2 * This file is part of rt_sigprocmask strace test.
4 * Copyright (c) 2016 Dmitry V. Levin <ldv@altlinux.org>
5 * Copyright (c) 2016-2017 The strace developers.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #include <asm/unistd.h>
34 #ifdef __NR_rt_sigprocmask
43 k_sigprocmask(const unsigned long how, void *const new_set,
44 void *const old_set, const unsigned long size)
46 return syscall(__NR_rt_sigprocmask, how, new_set, old_set, size);
50 iterate(const char *const text, void *set, void *old, unsigned int size)
53 if (k_sigprocmask(SIG_UNBLOCK, set, old, size)) {
54 if (size < sizeof(long))
55 tprintf("rt_sigprocmask(SIG_UNBLOCK"
56 ", %p, %p, %u) = -1 EINVAL (%m)\n",
59 tprintf("rt_sigprocmask(SIG_UNBLOCK"
60 ", %s, %p, %u) = -1 EINVAL (%m)\n",
63 tprintf("rt_sigprocmask(SIG_UNBLOCK, %s, [], %u)"
64 " = 0\n", text, size);
79 const unsigned int big_size = 1024 / 8;
80 unsigned int set_size;
82 for (set_size = big_size; set_size; set_size >>= 1) {
83 if (!k_sigprocmask(SIG_SETMASK, NULL, NULL, set_size))
85 tprintf("rt_sigprocmask(SIG_SETMASK, NULL, NULL, %u)"
86 " = -1 EINVAL (%m)\n", set_size);
89 perror_msg_and_fail("rt_sigprocmask");
90 tprintf("rt_sigprocmask(SIG_SETMASK, NULL, NULL, %u) = 0\n",
93 void *const k_set = tail_alloc(set_size);
94 void *const old_set = tail_alloc(set_size);
95 TAIL_ALLOC_OBJECT_CONST_PTR(sigset_t, libc_set);
97 memset(k_set, 0, set_size);
98 if (k_sigprocmask(SIG_SETMASK, k_set, NULL, set_size))
99 perror_msg_and_fail("rt_sigprocmask");
100 tprintf("rt_sigprocmask(SIG_SETMASK, [], NULL, %u) = 0\n", set_size);
102 if (k_sigprocmask(SIG_UNBLOCK, k_set - set_size, old_set, set_size))
103 perror_msg_and_fail("rt_sigprocmask");
104 tprintf("rt_sigprocmask(SIG_UNBLOCK, ~[], [], %u) = 0\n", set_size);
106 assert(k_sigprocmask(SIG_SETMASK, k_set - set_size,
107 old_set, set_size << 1) == -1);
108 tprintf("rt_sigprocmask(SIG_SETMASK, %p, %p, %u) = -1 EINVAL (%m)\n",
109 k_set - set_size, old_set, set_size << 1);
111 iterate("~[]", k_set - set_size, old_set, set_size >> 1);
113 sigemptyset(libc_set);
114 sigaddset(libc_set, SIGHUP);
115 memcpy(k_set, libc_set, set_size);
117 if (k_sigprocmask(SIG_BLOCK, k_set, old_set, set_size))
118 perror_msg_and_fail("rt_sigprocmask");
119 tprintf("rt_sigprocmask(SIG_BLOCK, [HUP], [], %u) = 0\n", set_size);
121 memset(libc_set, -1, sizeof(sigset_t));
122 sigdelset(libc_set, SIGHUP);
123 memcpy(k_set, libc_set, set_size);
125 if (k_sigprocmask(SIG_UNBLOCK, k_set, old_set, set_size))
126 perror_msg_and_fail("rt_sigprocmask");
127 tprintf("rt_sigprocmask(SIG_UNBLOCK, ~[HUP], [HUP], %u) = 0\n",
130 sigdelset(libc_set, SIGKILL);
131 memcpy(k_set, libc_set, set_size);
133 if (k_sigprocmask(SIG_UNBLOCK, k_set, old_set, set_size))
134 perror_msg_and_fail("rt_sigprocmask");
135 tprintf("rt_sigprocmask(SIG_UNBLOCK, ~[HUP KILL], [HUP], %u) = 0\n",
138 sigemptyset(libc_set);
139 sigaddset(libc_set, SIGHUP);
140 sigaddset(libc_set, SIGINT);
141 sigaddset(libc_set, SIGQUIT);
142 sigaddset(libc_set, SIGALRM);
143 sigaddset(libc_set, SIGTERM);
144 memcpy(k_set, libc_set, set_size);
146 if (k_sigprocmask(SIG_BLOCK, k_set, old_set, set_size))
147 perror_msg_and_fail("rt_sigprocmask");
148 tprintf("rt_sigprocmask(SIG_BLOCK, %s, [HUP], %u) = 0\n",
149 "[HUP INT QUIT ALRM TERM]", set_size);
151 if (k_sigprocmask(SIG_SETMASK, NULL, old_set, set_size))
152 perror_msg_and_fail("rt_sigprocmask");
153 tprintf("rt_sigprocmask(SIG_SETMASK, NULL, %s, %u) = 0\n",
154 "[HUP INT QUIT ALRM TERM]", set_size);
156 assert(k_sigprocmask(SIG_SETMASK, k_set + (set_size >> 1), NULL,
158 tprintf("rt_sigprocmask(SIG_SETMASK, %p, NULL, %u) = -1 EFAULT (%m)\n",
159 k_set + (set_size >> 1), set_size);
161 assert(k_sigprocmask(SIG_SETMASK, k_set, old_set + (set_size >> 1),
163 tprintf("rt_sigprocmask(SIG_SETMASK, %s, %p, %u) = -1 EFAULT (%m)\n",
164 "[HUP INT QUIT ALRM TERM]",
165 old_set + (set_size >> 1), set_size);
167 tprintf("+++ exited with 0 +++\n");
173 SKIP_MAIN_UNDEFINED("__NR_rt_sigprocmask")