2 * Check decoding of sigpending syscall.
4 * Copyright (c) 2016-2017 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 <asm/unistd.h>
33 #ifdef __NR_sigpending
41 static const char *errstr;
44 k_sigpending(const kernel_ulong_t set)
46 const long rc = syscall(__NR_sigpending, set);
47 errstr = sprintrc(rc);
54 TAIL_ALLOC_OBJECT_CONST_PTR(kernel_ulong_t, k_set);
55 TAIL_ALLOC_OBJECT_CONST_PTR(sigset_t, libc_set);
57 sigemptyset(libc_set);
58 if (sigprocmask(SIG_SETMASK, libc_set, NULL))
59 perror_msg_and_fail("sigprocmask");
61 if (k_sigpending((uintptr_t) libc_set))
62 perror_msg_and_skip("sigpending");
64 puts("sigpending([]) = 0");
66 k_sigpending((uintptr_t) k_set);
67 puts("sigpending([]) = 0");
69 k_sigpending((uintptr_t) (k_set + 1));
70 printf("sigpending(%p) = -1 EFAULT (%m)\n", k_set + 1);
72 uintptr_t efault = sizeof(*k_set) / 2 + (uintptr_t) k_set;
74 printf("sigpending(%#jx) = -1 EFAULT (%m)\n", (uintmax_t) efault);
76 sigaddset(libc_set, SIGHUP);
77 if (sigprocmask(SIG_SETMASK, libc_set, NULL))
78 perror_msg_and_fail("sigprocmask");
81 k_sigpending((uintptr_t) k_set);
82 puts("sigpending([HUP]) = 0");
84 sigaddset(libc_set, SIGINT);
85 if (sigprocmask(SIG_SETMASK, libc_set, NULL))
86 perror_msg_and_fail("sigprocmask");
89 k_sigpending((uintptr_t) k_set);
90 puts("sigpending([HUP INT]) = 0");
92 if (F8ILL_KULONG_SUPPORTED) {
93 k_sigpending(f8ill_ptr_to_kulong(k_set));
94 printf("sigpending(%#jx) = %s\n",
95 (uintmax_t) f8ill_ptr_to_kulong(k_set), errstr);
98 puts("+++ exited with 0 +++");
104 SKIP_MAIN_UNDEFINED("__NR_sigpending")