2 * Check decoding of sgetmask and ssetmask syscalls.
4 * Copyright (c) 2017 Dmitry V. Levin <ldv@altlinux.org>
7 * SPDX-License-Identifier: GPL-2.0-or-later
11 #include <asm/unistd.h>
13 #if defined __NR_sgetmask && defined __NR_ssetmask
25 return syscall(__NR_sgetmask);
29 k_ssetmask(const kernel_ulong_t arg)
31 return syscall(__NR_ssetmask, arg);
39 unsigned long old_mask;
44 * Block, reset, and raise SIGUSR1.
45 * If a subsequent ssetmask call fails to set the proper mask,
46 * the process will be terminated by SIGUSR1.
48 sigemptyset(&uset.libc_mask);
49 sigaddset(&uset.libc_mask, SIGUSR1);
50 if (sigprocmask(SIG_SETMASK, &uset.libc_mask, NULL))
51 perror_msg_and_fail("sigprocmask");
52 if (signal(SIGUSR1, SIG_DFL) == SIG_ERR)
53 perror_msg_and_fail("signal");
56 sigaddset(&uset.libc_mask, SIGUSR2);
57 rc = k_ssetmask((kernel_ulong_t) 0xfacefeed00000000ULL | uset.old_mask);
59 printf("ssetmask([USR1 USR2]) = %s\n", sprintrc(rc));
61 printf("ssetmask([USR1 USR2]) = %#lx (old mask [USR1])\n", rc);
63 * Use a regular sigprocmask call to check the value
64 * returned by the ssetmask call being tested.
66 if (sigprocmask(SIG_SETMASK, NULL, &uget.libc_mask))
67 perror_msg_and_fail("sigprocmask");
68 if (uset.old_mask != uget.old_mask)
69 error_msg_and_fail("sigprocmask returned %#lx"
71 uget.old_mask, uset.old_mask);
76 printf("sgetmask() = %s\n", sprintrc(rc));
78 printf("sgetmask() = %#lx (mask [USR1 USR2])\n", rc);
79 if (uget.old_mask != (unsigned long) rc)
80 error_msg_and_fail("sigprocmask returned %#lx",
83 if (sizeof(long) > 4) {
84 sigaddset(&uset.libc_mask, 32 + 27);
85 if (sigprocmask(SIG_SETMASK, &uset.libc_mask, NULL))
86 perror_msg_and_fail("sigprocmask");
88 printf("sgetmask() = %#lx"
89 " (mask [USR1 USR2 RT_27])\n", rc);
90 if (uset.old_mask != (unsigned long) rc)
91 error_msg_and_fail("sigprocmask set %#lx",
96 puts("+++ exited with 0 +++");
102 SKIP_MAIN_UNDEFINED("__NR_sgetmask && __NR_ssetmask")