2 * Check decoding of sigprocmask syscall.
4 * Copyright (c) 2016-2017 Dmitry V. Levin <ldv@altlinux.org>
7 * SPDX-License-Identifier: GPL-2.0-or-later
11 #include <asm/unistd.h>
13 #ifdef __NR_sigprocmask
21 static const char *errstr;
24 k_sigprocmask(const kernel_ulong_t how, const kernel_ulong_t new_set,
25 const kernel_ulong_t old_set)
27 const long rc = syscall(__NR_sigprocmask, how, new_set, old_set);
28 errstr = sprintrc(rc);
35 static const kernel_ulong_t sig_block =
36 (kernel_ulong_t) 0xfacefeed00000000ULL | SIG_BLOCK;
37 static const kernel_ulong_t sig_unblock =
38 (kernel_ulong_t) 0xfacefeed00000000ULL | SIG_UNBLOCK;
39 static const kernel_ulong_t sig_setmask =
40 (kernel_ulong_t) 0xfacefeed00000000ULL | SIG_SETMASK;
42 if (k_sigprocmask(sig_setmask, 0, 0))
43 perror_msg_and_skip("sigprocmask");
44 puts("sigprocmask(SIG_SETMASK, NULL, NULL) = 0");
46 TAIL_ALLOC_OBJECT_CONST_PTR(kernel_ulong_t, new_set);
47 TAIL_ALLOC_OBJECT_CONST_PTR(kernel_ulong_t, old_set);
48 TAIL_ALLOC_OBJECT_CONST_PTR(sigset_t, libc_set);
50 memset(new_set, 0, sizeof(*new_set));
51 k_sigprocmask(sig_setmask, (uintptr_t) new_set, 0);
52 printf("sigprocmask(SIG_SETMASK, [], NULL) = %s\n", errstr);
54 k_sigprocmask(sig_unblock,
55 (uintptr_t) (new_set - 1), (uintptr_t) old_set);
56 puts("sigprocmask(SIG_UNBLOCK, ~[], []) = 0");
58 if (F8ILL_KULONG_SUPPORTED) {
59 k_sigprocmask(sig_unblock, f8ill_ptr_to_kulong(new_set), 0);
60 printf("sigprocmask(SIG_UNBLOCK, %#jx, NULL) = %s\n",
61 (uintmax_t) f8ill_ptr_to_kulong(new_set), errstr);
63 k_sigprocmask(sig_unblock, 0, f8ill_ptr_to_kulong(old_set));
64 printf("sigprocmask(SIG_UNBLOCK, NULL, %#jx) = %s\n",
65 (uintmax_t) f8ill_ptr_to_kulong(old_set), errstr);
68 sigemptyset(libc_set);
69 sigaddset(libc_set, SIGHUP);
70 memcpy(new_set, libc_set, sizeof(*new_set));
72 k_sigprocmask(sig_block, (uintptr_t) new_set, (uintptr_t) old_set);
73 puts("sigprocmask(SIG_BLOCK, [HUP], []) = 0");
75 memset(libc_set, -1, sizeof(*libc_set));
76 sigdelset(libc_set, SIGHUP);
77 memcpy(new_set, libc_set, sizeof(*new_set));
79 k_sigprocmask(sig_unblock, (uintptr_t) new_set, (uintptr_t) old_set);
80 puts("sigprocmask(SIG_UNBLOCK, ~[HUP], [HUP]) = 0");
82 sigdelset(libc_set, SIGKILL);
83 memcpy(new_set, libc_set, sizeof(*new_set));
85 k_sigprocmask(sig_unblock, (uintptr_t) new_set, (uintptr_t) old_set);
86 puts("sigprocmask(SIG_UNBLOCK, ~[HUP KILL], [HUP]) = 0");
88 sigemptyset(libc_set);
89 sigaddset(libc_set, SIGHUP);
90 sigaddset(libc_set, SIGINT);
91 sigaddset(libc_set, SIGQUIT);
92 sigaddset(libc_set, SIGALRM);
93 sigaddset(libc_set, SIGTERM);
94 memcpy(new_set, libc_set, sizeof(*new_set));
96 k_sigprocmask(sig_block, (uintptr_t) new_set, (uintptr_t) old_set);
97 printf("sigprocmask(SIG_BLOCK, %s, [HUP]) = 0\n",
98 "[HUP INT QUIT ALRM TERM]");
100 k_sigprocmask(sig_setmask, 0, (uintptr_t) old_set);
101 printf("sigprocmask(SIG_SETMASK, NULL, %s) = 0\n",
102 "[HUP INT QUIT ALRM TERM]");
104 k_sigprocmask(sig_setmask, (uintptr_t) (new_set + 1), 0);
105 printf("sigprocmask(SIG_SETMASK, %p, NULL) = %s\n",
106 new_set + 1, errstr);
108 k_sigprocmask(sig_setmask,
109 (uintptr_t) new_set, (uintptr_t) (old_set + 1));
110 printf("sigprocmask(SIG_SETMASK, %s, %p) = %s\n",
111 "[HUP INT QUIT ALRM TERM]", old_set + 1, errstr);
113 uintptr_t efault = sizeof(*new_set) / 2 + (uintptr_t) new_set;
115 k_sigprocmask(sig_setmask, efault, 0);
116 printf("sigprocmask(SIG_SETMASK, %#jx, NULL) = %s\n",
117 (uintmax_t) efault, errstr);
119 k_sigprocmask(sig_setmask, 0, efault);
120 printf("sigprocmask(SIG_SETMASK, NULL, %#jx) = %s\n",
121 (uintmax_t) efault, errstr);
123 puts("+++ exited with 0 +++");
129 SKIP_MAIN_UNDEFINED("__NR_sigprocmask")