2 * This file is part of rt_sigtimedwait strace test.
4 * Copyright (c) 2016 Dmitry V. Levin <ldv@altlinux.org>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #include <sys/syscall.h>
33 #ifdef __NR_rt_sigtimedwait
44 k_sigtimedwait(const sigset_t *const set, siginfo_t *const info,
45 const struct timespec *const timeout, const unsigned long size)
47 return syscall(__NR_rt_sigtimedwait, set, info, timeout, size);
51 iterate(const char *const text, const void *set,
52 const struct timespec *const timeout, unsigned int size)
55 assert(k_sigtimedwait(set, NULL, timeout, size) == -1);
57 tprintf("rt_sigtimedwait(%s, NULL, {%jd, %jd}, %u)"
58 " = -1 EAGAIN (%m)\n", text,
59 (intmax_t) timeout->tv_sec,
60 (intmax_t) timeout->tv_nsec,
63 if (size < sizeof(long))
64 tprintf("rt_sigtimedwait(%p, NULL, {%jd, %jd}"
65 ", %u) = -1 EINVAL (%m)\n",
66 set, (intmax_t) timeout->tv_sec,
67 (intmax_t) timeout->tv_nsec, size);
69 tprintf("rt_sigtimedwait(%s, NULL, {%jd, %jd}"
70 ", %u) = -1 EINVAL (%m)\n",
71 text, (intmax_t) timeout->tv_sec,
72 (intmax_t) timeout->tv_nsec, size);
86 siginfo_t *const info = tail_alloc(sizeof(*info));
87 struct timespec *const timeout = tail_alloc(sizeof(*timeout));
89 timeout->tv_nsec = 42;
91 const unsigned int big_size = 1024 / 8;
92 void *k_set = tail_alloc(big_size);
93 memset(k_set, 0, big_size);
95 unsigned int set_size = big_size;
96 for (; set_size; set_size >>= 1, k_set += set_size) {
97 assert(k_sigtimedwait(k_set, NULL, timeout, set_size) == -1);
100 tprintf("rt_sigtimedwait(%p, NULL, {%jd, %jd}, %u)"
101 " = -1 EINVAL (%m)\n",
102 k_set, (intmax_t) timeout->tv_sec,
103 (intmax_t) timeout->tv_nsec, set_size);
106 perror_msg_and_fail("rt_sigtimedwait");
107 tprintf("rt_sigtimedwait([], NULL, {%jd, %jd}, %u) = -1 EAGAIN (%m)\n",
108 (intmax_t) timeout->tv_sec, (intmax_t) timeout->tv_nsec,
111 sigset_t *const libc_set = tail_alloc(sizeof(sigset_t));
112 sigemptyset(libc_set);
113 sigaddset(libc_set, SIGHUP);
114 memcpy(k_set, libc_set, set_size);
116 assert(k_sigtimedwait(k_set, info, timeout, set_size) == -1);
117 assert(EAGAIN == errno);
118 tprintf("rt_sigtimedwait([HUP], %p, {%jd, %jd}, %u) = -1 EAGAIN (%m)\n",
119 info, (intmax_t) timeout->tv_sec,
120 (intmax_t) timeout->tv_nsec, set_size);
122 sigaddset(libc_set, SIGINT);
123 memcpy(k_set, libc_set, set_size);
125 assert(k_sigtimedwait(k_set, info, timeout, set_size) == -1);
126 assert(EAGAIN == errno);
127 tprintf("rt_sigtimedwait([HUP INT], %p, {%jd, %jd}, %u)"
128 " = -1 EAGAIN (%m)\n",
129 info, (intmax_t) timeout->tv_sec,
130 (intmax_t) timeout->tv_nsec, set_size);
132 sigaddset(libc_set, SIGQUIT);
133 sigaddset(libc_set, SIGALRM);
134 sigaddset(libc_set, SIGTERM);
135 memcpy(k_set, libc_set, set_size);
137 assert(k_sigtimedwait(k_set, info, timeout, set_size) == -1);
138 assert(EAGAIN == errno);
139 tprintf("rt_sigtimedwait(%s, %p, {%jd, %jd}, %u) = -1 EAGAIN (%m)\n",
140 "[HUP INT QUIT ALRM TERM]",
141 info, (intmax_t) timeout->tv_sec,
142 (intmax_t) timeout->tv_nsec, set_size);
144 memset(k_set - set_size, -1, set_size);
145 assert(k_sigtimedwait(k_set - set_size, info, timeout, set_size) == -1);
146 assert(EAGAIN == errno);
147 tprintf("rt_sigtimedwait(~[], %p, {%jd, %jd}, %u) = -1 EAGAIN (%m)\n",
148 info, (intmax_t) timeout->tv_sec,
149 (intmax_t) timeout->tv_nsec, set_size);
151 if (sigprocmask(SIG_SETMASK, libc_set, NULL))
152 perror_msg_and_fail("sigprocmask");
154 assert(k_sigtimedwait(k_set - set_size, info, NULL, set_size << 1) == -1);
155 tprintf("rt_sigtimedwait(%p, %p, NULL, %u) = -1 EINVAL (%m)\n",
156 k_set - set_size, info, set_size << 1);
158 iterate("~[]", k_set - set_size, timeout, set_size >> 1);
162 assert(k_sigtimedwait(k_set, info, timeout, set_size) == SIGALRM);
163 tprintf("rt_sigtimedwait(%s, {si_signo=%s, si_code=SI_TKILL"
164 ", si_pid=%d, si_uid=%d}, {%jd, %jd}, %u) = %d (%s)\n",
165 "[HUP INT QUIT ALRM TERM]", "SIGALRM", getpid(), getuid(),
166 (intmax_t) timeout->tv_sec, (intmax_t) timeout->tv_nsec,
167 set_size, SIGALRM, "SIGALRM");
170 assert(k_sigtimedwait(k_set, NULL, NULL, set_size) == SIGALRM);
171 tprintf("rt_sigtimedwait(%s, NULL, NULL, %u) = %d (%s)\n",
172 "[HUP INT QUIT ALRM TERM]", set_size, SIGALRM, "SIGALRM");
174 tprintf("+++ exited with 0 +++\n");
180 SKIP_MAIN_UNDEFINED("__NR_rt_sigtimedwait")