1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
/*
* Check decoding of tkill syscall.
*
* Copyright (c) 2020 Dmitry V. Levin <ldv@altlinux.org>
* All rights reserved.
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "tests.h"
#include "scno.h"
#ifdef __NR_tkill
# include <signal.h>
# include <stdio.h>
# include <unistd.h>
static const char *errstr;
static long
k_tkill(const unsigned int tid, const unsigned int sig)
{
const kernel_ulong_t fill = (kernel_ulong_t) 0xdefaced00000000ULL;
const kernel_ulong_t bad = (kernel_ulong_t) 0xbadc0dedbadc0dedULL;
const kernel_ulong_t arg1 = fill | tid;
const kernel_ulong_t arg2 = fill | sig;
const long rc = syscall(__NR_tkill, arg1, arg2, bad, bad, bad, bad);
errstr = sprintrc(rc);
return rc;
}
int
main(void)
{
const int pid = getpid();
const int bad_pid = -1;
const int bad_sig = 0xface;
k_tkill(pid, 0);
printf("tkill(%d, 0) = %s\n", pid, errstr);
k_tkill(pid, SIGCONT);
printf("tkill(%d, SIGCONT) = %s\n", pid, errstr);
k_tkill(bad_pid, bad_sig);
printf("tkill(%d, %d) = %s\n", bad_pid, bad_sig, errstr);
k_tkill(bad_pid, -bad_sig);
printf("tkill(%d, %d) = %s\n", bad_pid, -bad_sig, errstr);
puts("+++ exited with 0 +++");
return 0;
}
#else
SKIP_MAIN_UNDEFINED("__NR_tkill")
#endif
|