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