2 * Check decoding of sigprocmask syscall.
4 * Copyright (c) 2016-2018 Dmitry V. Levin <ldv@altlinux.org>
5 * Copyright (c) 2017-2019 The strace developers.
8 * SPDX-License-Identifier: GPL-2.0-or-later
14 #ifdef __NR_sigprocmask
22 static const char *errstr;
25 k_sigprocmask(const kernel_ulong_t how, const kernel_ulong_t new_set,
26 const kernel_ulong_t old_set)
28 const long rc = syscall(__NR_sigprocmask, how, new_set, old_set);
29 errstr = sprintrc(rc);
36 static const kernel_ulong_t sig_block =
37 (kernel_ulong_t) 0xfacefeed00000000ULL | SIG_BLOCK;
38 static const kernel_ulong_t sig_unblock =
39 (kernel_ulong_t) 0xfacefeed00000000ULL | SIG_UNBLOCK;
40 static const kernel_ulong_t sig_setmask =
41 (kernel_ulong_t) 0xfacefeed00000000ULL | SIG_SETMASK;
43 if (k_sigprocmask(sig_setmask, 0, 0))
44 perror_msg_and_skip("sigprocmask");
45 puts("sigprocmask(SIG_SETMASK, NULL, NULL) = 0");
47 TAIL_ALLOC_OBJECT_CONST_PTR(kernel_ulong_t, new_set);
48 TAIL_ALLOC_OBJECT_CONST_PTR(kernel_ulong_t, old_set);
49 TAIL_ALLOC_OBJECT_CONST_PTR(sigset_t, libc_set);
51 memset(new_set, 0, sizeof(*new_set));
52 k_sigprocmask(sig_setmask, (uintptr_t) new_set, 0);
53 printf("sigprocmask(SIG_SETMASK, [], NULL) = %s\n", errstr);
55 k_sigprocmask(sig_unblock,
56 (uintptr_t) (new_set - 1), (uintptr_t) old_set);
57 puts("sigprocmask(SIG_UNBLOCK, ~[], []) = 0");
59 if (F8ILL_KULONG_SUPPORTED) {
60 k_sigprocmask(sig_unblock, f8ill_ptr_to_kulong(new_set), 0);
61 printf("sigprocmask(SIG_UNBLOCK, %#jx, NULL) = %s\n",
62 (uintmax_t) f8ill_ptr_to_kulong(new_set), errstr);
64 k_sigprocmask(sig_unblock, 0, f8ill_ptr_to_kulong(old_set));
65 printf("sigprocmask(SIG_UNBLOCK, NULL, %#jx) = %s\n",
66 (uintmax_t) f8ill_ptr_to_kulong(old_set), errstr);
69 sigemptyset(libc_set);
70 sigaddset(libc_set, SIGHUP);
71 memcpy(new_set, libc_set, sizeof(*new_set));
73 k_sigprocmask(sig_block, (uintptr_t) new_set, (uintptr_t) old_set);
74 puts("sigprocmask(SIG_BLOCK, [HUP], []) = 0");
76 memset(libc_set, -1, sizeof(*libc_set));
77 sigdelset(libc_set, SIGHUP);
78 memcpy(new_set, libc_set, sizeof(*new_set));
80 k_sigprocmask(sig_unblock, (uintptr_t) new_set, (uintptr_t) old_set);
81 puts("sigprocmask(SIG_UNBLOCK, ~[HUP], [HUP]) = 0");
83 sigdelset(libc_set, SIGKILL);
84 memcpy(new_set, libc_set, sizeof(*new_set));
86 k_sigprocmask(sig_unblock, (uintptr_t) new_set, (uintptr_t) old_set);
87 puts("sigprocmask(SIG_UNBLOCK, ~[HUP KILL], [HUP]) = 0");
89 sigemptyset(libc_set);
90 sigaddset(libc_set, SIGHUP);
91 sigaddset(libc_set, SIGINT);
92 sigaddset(libc_set, SIGQUIT);
93 sigaddset(libc_set, SIGALRM);
94 sigaddset(libc_set, SIGTERM);
95 memcpy(new_set, libc_set, sizeof(*new_set));
97 k_sigprocmask(sig_block, (uintptr_t) new_set, (uintptr_t) old_set);
98 printf("sigprocmask(SIG_BLOCK, %s, [HUP]) = 0\n",
99 "[HUP INT QUIT ALRM TERM]");
101 k_sigprocmask(sig_setmask, 0, (uintptr_t) old_set);
102 printf("sigprocmask(SIG_SETMASK, NULL, %s) = 0\n",
103 "[HUP INT QUIT ALRM TERM]");
105 k_sigprocmask(sig_setmask, (uintptr_t) (new_set + 1), 0);
106 printf("sigprocmask(SIG_SETMASK, %p, NULL) = %s\n",
107 new_set + 1, errstr);
109 k_sigprocmask(sig_setmask,
110 (uintptr_t) new_set, (uintptr_t) (old_set + 1));
111 printf("sigprocmask(SIG_SETMASK, %s, %p) = %s\n",
112 "[HUP INT QUIT ALRM TERM]", old_set + 1, errstr);
114 uintptr_t efault = sizeof(*new_set) / 2 + (uintptr_t) new_set;
116 k_sigprocmask(sig_setmask, efault, 0);
117 printf("sigprocmask(SIG_SETMASK, %#jx, NULL) = %s\n",
118 (uintmax_t) efault, errstr);
120 k_sigprocmask(sig_setmask, 0, efault);
121 printf("sigprocmask(SIG_SETMASK, NULL, %#jx) = %s\n",
122 (uintmax_t) efault, errstr);
124 puts("+++ exited with 0 +++");
130 SKIP_MAIN_UNDEFINED("__NR_sigprocmask")