]> granicus.if.org Git - strace/blob - tests/s390_runtime_instr.c
strace: terminate itself if interrupted by a signal
[strace] / tests / s390_runtime_instr.c
1 /*
2  * Check decoding of s390_runtime_instr syscall.
3  *
4  * Copyright (c) 2018 The strace developers.
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 #if defined __NR_s390_runtime_instr
14
15 # include <errno.h>
16 # include <signal.h>
17 # include <stdio.h>
18 # include <unistd.h>
19
20 int
21 main(void)
22 {
23         static struct {
24                 kernel_ulong_t cmd;
25                 const char * cmd_str;
26         } cmd_args[] = {
27                 { 0, "0 /* S390_RUNTIME_INSTR_??? */" },
28                 { 4, "4 /* S390_RUNTIME_INSTR_??? */" },
29                 { (kernel_ulong_t) 0xdeafbeefdeadc0deULL,
30                         "-559038242 /* S390_RUNTIME_INSTR_??? */" },
31                 { 2, "S390_RUNTIME_INSTR_STOP"  },
32         };
33
34         static struct {
35                 kernel_ulong_t sig;
36                 const char * sig_str;
37         } start_sig_args[] = {
38                 { 0, "0" },
39                 { (kernel_ulong_t) 0xfacefeedac0ffeedULL, NULL },
40                 { ARG_STR(SIGALRM) },
41                 { 33, "SIGRT_1" },
42                 { 63, "SIGRT_31" },
43         };
44
45         unsigned int i;
46         long rc;
47
48         for (i = 0; i < ARRAY_SIZE(cmd_args); i++) {
49                 rc = syscall(__NR_s390_runtime_instr, cmd_args[i].cmd, 0xdead);
50                 printf("s390_runtime_instr(%s) = %s\n",
51                        cmd_args[i].cmd_str, sprintrc(rc));
52         }
53
54         for (i = 0; i < ARRAY_SIZE(start_sig_args); i++) {
55                 long saved_errno;
56
57                 rc = syscall(__NR_s390_runtime_instr, 1, start_sig_args[i].sig);
58                 saved_errno = errno;
59                 printf("s390_runtime_instr(S390_RUNTIME_INSTR_START, ");
60
61                 if (start_sig_args[i].sig_str)
62                         printf("%s", start_sig_args[i].sig_str);
63                 else
64                         printf("%d", (int) start_sig_args[i].sig);
65
66                 errno = saved_errno;
67                 printf(") = %s\n", sprintrc(rc));
68         }
69
70         puts("+++ exited with 0 +++");
71         return 0;
72 }
73
74 #else
75
76 SKIP_MAIN_UNDEFINED("__NR_s390_runtime_instr")
77
78 #endif