]> granicus.if.org Git - strace/blob - tests/sigreturn.c
ae68cabff3ad95432275e31f92a8ac60514f1325
[strace] / tests / sigreturn.c
1 /*
2  * Copyright (c) 2015-2017 Dmitry V. Levin <ldv@altlinux.org>
3  * All rights reserved.
4  *
5  * SPDX-License-Identifier: GPL-2.0-or-later
6  */
7
8 #include "tests.h"
9 #include <asm/unistd.h>
10
11 #if defined __powerpc64__ \
12  || (defined __sparc__ && defined __arch64__)
13 /* Old sigreturn is defined but not implemented in the kernel. */
14 # undef __NR_sigreturn
15 #endif
16
17 #ifdef __NR_sigreturn
18
19 # include <signal.h>
20 # include <stdio.h>
21 # include <stdlib.h>
22
23 # ifdef ASM_SIGRTMIN
24 #  define RT_0 ASM_SIGRTMIN
25 # else
26 /* Linux kernel >= 3.18 defines SIGRTMIN to 32 on all architectures. */
27 #  define RT_0 32
28 # endif
29
30 static void
31 handler(int sig)
32 {
33 }
34
35 int
36 main(void)
37 {
38         static sigset_t set;
39         sigemptyset(&set);
40         sigaddset(&set, SIGINT);
41         sigaddset(&set, SIGUSR2);
42         sigaddset(&set, SIGCHLD);
43         sigaddset(&set, RT_0 +  3);
44         sigaddset(&set, RT_0 +  4);
45         sigaddset(&set, RT_0 +  5);
46         sigaddset(&set, RT_0 + 26);
47         sigaddset(&set, RT_0 + 27);
48         if (sigprocmask(SIG_SETMASK, &set, NULL))
49                 perror_msg_and_fail("sigprocmask");
50         sigemptyset(&set);
51
52         /* This should result to old sigreturn. */
53         if (signal(SIGUSR1, handler) == SIG_ERR)
54                 perror_msg_and_fail("sigaction");
55
56         if (raise(SIGUSR1))
57                 perror_msg_and_fail("raise");
58
59         static const char *const sigs =
60                 (SIGUSR2 < SIGCHLD) ? "INT USR2 CHLD" : "INT CHLD USR2";
61         static const char *const rt_sigs = "RT_3 RT_4 RT_5 RT_26 RT_27";
62         printf("sigreturn({mask=[%s %s]}) = 0\n", sigs, rt_sigs);
63
64         puts("+++ exited with 0 +++");
65         return 0;
66 }
67
68 #else
69
70 SKIP_MAIN_UNDEFINED("__NR_sigreturn")
71
72 #endif