1 /*
2 * Check decoding of sigpending syscall.
3 *
4 * Copyright (c) 2016-2018 Dmitry V. Levin <ldv@strace.io>
5 * Copyright (c) 2017-2021 The strace developers.
6 * All rights reserved.
7 *
8 * SPDX-License-Identifier: GPL-2.0-or-later
9 */
10
11 #include "tests.h"
12 #include "scno.h"
13
14 #ifdef __NR_sigpending
15
16 # include <signal.h>
17 # include <stdint.h>
18 # include <stdio.h>
19 # include <string.h>
20 # include <unistd.h>
21
22 static const char *errstr;
23
24 static long
25 k_sigpending(const kernel_ulong_t set)
26 {
27 const long rc = syscall(__NR_sigpending, set);
28 errstr = sprintrc(rc);
29 return rc;
30 }
31
32 int
33 main(void)
34 {
35 TAIL_ALLOC_OBJECT_CONST_PTR(kernel_ulong_t, k_set);
36 TAIL_ALLOC_OBJECT_CONST_PTR(sigset_t, libc_set);
37
38 sigemptyset(libc_set);
39 if (sigprocmask(SIG_SETMASK, libc_set, NULL))
40 perror_msg_and_fail("sigprocmask");
41
42 if (k_sigpending((uintptr_t) libc_set))
43 perror_msg_and_skip("sigpending");
44 else
45 puts("sigpending([]) = 0");
46
47 k_sigpending((uintptr_t) k_set);
48 puts("sigpending([]) = 0");
49
50 k_sigpending((uintptr_t) (k_set + 1));
51 printf("sigpending(%p) = -1 EFAULT (%m)\n", k_set + 1);
52
53 uintptr_t efault = sizeof(*k_set) / 2 + (uintptr_t) k_set;
54 k_sigpending(efault);
55 printf("sigpending(%#jx) = -1 EFAULT (%m)\n", (uintmax_t) efault);
56
57 sigaddset(libc_set, SIGHUP);
58 if (sigprocmask(SIG_SETMASK, libc_set, NULL))
59 perror_msg_and_fail("sigprocmask");
60 raise(SIGHUP);
61
62 k_sigpending((uintptr_t) k_set);
63 puts("sigpending([HUP]) = 0");
64
65 sigaddset(libc_set, SIGINT);
66 if (sigprocmask(SIG_SETMASK, libc_set, NULL))
67 perror_msg_and_fail("sigprocmask");
68 raise(SIGINT);
69
70 k_sigpending((uintptr_t) k_set);
71 puts("sigpending([HUP INT]) = 0");
72
73 if (F8ILL_KULONG_SUPPORTED) {
74 k_sigpending(f8ill_ptr_to_kulong(k_set));
75 printf("sigpending(%#jx) = %s\n",
76 (uintmax_t) f8ill_ptr_to_kulong(k_set), errstr);
77 }
78
79 puts("+++ exited with 0 +++");
80 return 0;
81 }
82
83 #else
84
85 SKIP_MAIN_UNDEFINED("__NR_sigpending")
86
87 #endif