]> granicus.if.org Git - strace/blob - tests/prctl-tsc.c
Update copyright headers
[strace] / tests / prctl-tsc.c
1 /*
2  * Check decoding of prctl PR_GET_TSC/PR_SET_TSC operations.
3  *
4  * Copyright (c) 2016 JingPiao Chen <chenjingpiao@foxmail.com>
5  * Copyright (c) 2016 Eugene Syromyatnikov <evgsyr@gmail.com>
6  * Copyright (c) 2016-2018 The strace developers.
7  * All rights reserved.
8  *
9  * SPDX-License-Identifier: GPL-2.0-or-later
10  */
11
12 #include "tests.h"
13 #include <asm/unistd.h>
14 #include <linux/prctl.h>
15
16 #if defined __NR_prctl && defined PR_GET_TSC && defined PR_SET_TSC
17
18 # include <stdio.h>
19 # include <unistd.h>
20
21 int
22 main(void)
23 {
24         static const kernel_ulong_t bogus_tsc =
25                 (kernel_ulong_t) 0xdeadc0defacebeefULL;
26
27         TAIL_ALLOC_OBJECT_CONST_PTR(int, tsc);
28         long rc;
29
30         rc = syscall(__NR_prctl, PR_SET_TSC, 0);
31         printf("prctl(PR_SET_TSC, 0 /* PR_TSC_??? */) = %s\n", sprintrc(rc));
32
33         rc = syscall(__NR_prctl, PR_SET_TSC, bogus_tsc);
34         printf("prctl(PR_SET_TSC, %#x /* PR_TSC_??? */) = %s\n",
35                (unsigned int) bogus_tsc, sprintrc(rc));
36
37         rc = syscall(__NR_prctl, PR_SET_TSC, PR_TSC_SIGSEGV);
38         printf("prctl(PR_SET_TSC, PR_TSC_SIGSEGV) = %s\n", sprintrc(rc));
39
40         rc = syscall(__NR_prctl, PR_GET_TSC, NULL);
41         printf("prctl(PR_GET_TSC, NULL) = %s\n", sprintrc(rc));
42
43         rc = syscall(__NR_prctl, PR_GET_TSC, tsc + 1);
44         printf("prctl(PR_GET_TSC, %p) = %s\n", tsc + 1, sprintrc(rc));
45
46         rc = syscall(__NR_prctl, PR_GET_TSC, tsc);
47         if (rc)
48                 printf("prctl(PR_GET_TSC, %p) = %s\n", tsc, sprintrc(rc));
49         else
50                 printf("prctl(PR_GET_TSC, [PR_TSC_SIGSEGV]) = %s\n",
51                        sprintrc(rc));
52
53         puts("+++ exited with 0 +++");
54         return 0;
55 }
56
57 #else
58
59 SKIP_MAIN_UNDEFINED("__NR_prctl && PR_GET_TSC && PR_SET_TSC")
60
61 #endif