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-2021 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 "scno.h"
14 #include <stdio.h>
15 #include <unistd.h>
16 #include <linux/prctl.h>
17
18 int
19 main(void)
20 {
21 static const kernel_ulong_t bogus_tsc =
22 (kernel_ulong_t) 0xdeadc0defacebeefULL;
23
24 TAIL_ALLOC_OBJECT_CONST_PTR(int, tsc);
25 long rc;
26
27 prctl_marker();
28
29 rc = syscall(__NR_prctl, PR_SET_TSC, 0);
30 printf("prctl(PR_SET_TSC, 0 /* PR_TSC_??? */) = %s\n", sprintrc(rc));
31
32 rc = syscall(__NR_prctl, PR_SET_TSC, bogus_tsc);
33 printf("prctl(PR_SET_TSC, %#x /* PR_TSC_??? */) = %s\n",
34 (unsigned int) bogus_tsc, sprintrc(rc));
35
36 rc = syscall(__NR_prctl, PR_SET_TSC, PR_TSC_SIGSEGV);
37 printf("prctl(PR_SET_TSC, PR_TSC_SIGSEGV) = %s\n", sprintrc(rc));
38
39 rc = syscall(__NR_prctl, PR_GET_TSC, NULL);
40 printf("prctl(PR_GET_TSC, NULL) = %s\n", sprintrc(rc));
41
42 rc = syscall(__NR_prctl, PR_GET_TSC, tsc + 1);
43 printf("prctl(PR_GET_TSC, %p) = %s\n", tsc + 1, sprintrc(rc));
44
45 rc = syscall(__NR_prctl, PR_GET_TSC, tsc);
46 if (rc)
47 printf("prctl(PR_GET_TSC, %p) = %s\n", tsc, sprintrc(rc));
48 else
49 printf("prctl(PR_GET_TSC, [PR_TSC_SIGSEGV]) = %s\n",
50 sprintrc(rc));
51
52 puts("+++ exited with 0 +++");
53 return 0;
54 }