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