1 /*
2 * Check decoding of tgkill syscall.
3 *
4 * Copyright (c) 2020-2021 Dmitry V. Levin <ldv@strace.io>
5 * All rights reserved.
6 *
7 * SPDX-License-Identifier: GPL-2.0-or-later
8 */
9
10 #include "tests.h"
11 #include "scno.h"
12 #include "pidns.h"
13
14 #include <signal.h>
15 #include <stdio.h>
16 #include <unistd.h>
17
18 static const char *errstr;
19
20 static long
21 k_tgkill(const unsigned int tgid,
22 const unsigned int tid,
23 const unsigned int sig)
24 {
25 const kernel_ulong_t fill = (kernel_ulong_t) 0xdefaced00000000ULL;
26 const kernel_ulong_t bad = (kernel_ulong_t) 0xbadc0dedbadc0dedULL;
27 const kernel_ulong_t arg1 = fill | tgid;
28 const kernel_ulong_t arg2 = fill | tid;
29 const kernel_ulong_t arg3 = fill | sig;
30 const long rc = syscall(__NR_tgkill, arg1, arg2, arg3, bad, bad, bad);
31 errstr = sprintrc(rc);
32 return rc;
33 }
34
35 int
36 main(void)
37 {
38 PIDNS_TEST_INIT;
39
40 const int pid = getpid();
41 const char *pid_str = pidns_pid2str(PT_TGID);
42 const int tid = syscall(__NR_gettid);
43 const char *tid_str = pidns_pid2str(PT_TID);
44 const int bad_pid = -1;
45 const int bad_sig = 0xface;
46
47 k_tgkill(pid, tid, 0);
48 pidns_print_leader();
49 printf("tgkill(%d%s, %d%s, 0) = %s\n",
50 pid, pid_str, tid, tid_str, errstr);
51
52 k_tgkill(pid, bad_pid, 0);
53 pidns_print_leader();
54 printf("tgkill(%d%s, %d, 0) = %s\n",
55 pid, pid_str, bad_pid, errstr);
56
57 k_tgkill(bad_pid, tid, 0);
58 pidns_print_leader();
59 printf("tgkill(%d, %d%s, 0) = %s\n",
60 bad_pid, tid, tid_str, errstr);
61
62 k_tgkill(pid, tid, SIGCONT);
63 pidns_print_leader();
64 printf("tgkill(%d%s, %d%s, SIGCONT) = %s\n",
65 pid, pid_str, tid, tid_str, errstr);
66
67 k_tgkill(pid, tid, bad_sig);
68 pidns_print_leader();
69 printf("tgkill(%d%s, %d%s, %d) = %s\n",
70 pid, pid_str, tid, tid_str, bad_sig, errstr);
71
72 k_tgkill(pid, tid, -bad_sig);
73 pidns_print_leader();
74 printf("tgkill(%d%s, %d%s, %d) = %s\n",
75 pid, pid_str, tid, tid_str, -bad_sig, errstr);
76
77 pidns_print_leader();
78 puts("+++ exited with 0 +++");
79 return 0;
80 }