]> granicus.if.org Git - strace/blob - tests/prctl-no-args.c
Update copyright headers
[strace] / tests / prctl-no-args.c
1 /*
2  * Check decoding of prctl operations without arguments and return code parsing:
3  * PR_GET_KEEPCAPS, PR_GET_SECCOMP, PR_GET_TIMERSLACK, PR_GET_TIMING,
4  * PR_TASK_PERF_EVENTS_DISABLE, and PR_TASK_PERF_EVENTS_ENABLE.
5  *
6  * Copyright (c) 2016 Eugene Syromyatnikov <evgsyr@gmail.com>
7  * Copyright (c) 2016-2018 The strace developers.
8  * All rights reserved.
9  *
10  * SPDX-License-Identifier: GPL-2.0-or-later
11  */
12
13 #include "tests.h"
14 #include <asm/unistd.h>
15
16 #if defined __NR_prctl
17
18 # include <stdio.h>
19 # include <unistd.h>
20 # include <linux/prctl.h>
21
22 int
23 main(void)
24 {
25         static const kernel_ulong_t bogus_op_bits =
26                 (kernel_ulong_t) 0xbadc0ded00000000ULL;
27         static const kernel_ulong_t bogus_arg =
28                 (kernel_ulong_t) 0xfacefeeddeadbeefULL;
29         static const struct {
30                 kernel_ulong_t val;
31                 const char *str;
32         } options[] = {
33                 {  7, "PR_GET_KEEPCAPS" },
34                 { 13, "PR_GET_TIMING" },
35                 { 21, "PR_GET_SECCOMP" },
36                 { 30, "PR_GET_TIMERSLACK" },
37                 { 31, "PR_TASK_PERF_EVENTS_DISABLE" },
38                 { 32, "PR_TASK_PERF_EVENTS_ENABLE" },
39         };
40
41         TAIL_ALLOC_OBJECT_CONST_PTR(unsigned int, ptr);
42         unsigned int i;
43
44         for (i = 0; i < ARRAY_SIZE(options); i++) {
45                 long rc = syscall(__NR_prctl, options[i].val | bogus_op_bits,
46                                   bogus_arg);
47                 printf("prctl(%s) = %s\n", options[i].str, sprintrc(rc));
48         }
49
50         puts("+++ exited with 0 +++");
51         return 0;
52 }
53
54 #else
55
56 SKIP_MAIN_UNDEFINED("__NR_prctl")
57
58 #endif