2 * Check decoding of prctl PR_GET_TSC/PR_SET_TSC operations.
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.
9 * SPDX-License-Identifier: GPL-2.0-or-later
13 #include <asm/unistd.h>
14 #include <linux/prctl.h>
16 #if defined __NR_prctl && defined PR_GET_TSC && defined PR_SET_TSC
24 static const kernel_ulong_t bogus_tsc =
25 (kernel_ulong_t) 0xdeadc0defacebeefULL;
27 TAIL_ALLOC_OBJECT_CONST_PTR(int, tsc);
30 rc = syscall(__NR_prctl, PR_SET_TSC, 0);
31 printf("prctl(PR_SET_TSC, 0 /* PR_TSC_??? */) = %s\n", sprintrc(rc));
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));
37 rc = syscall(__NR_prctl, PR_SET_TSC, PR_TSC_SIGSEGV);
38 printf("prctl(PR_SET_TSC, PR_TSC_SIGSEGV) = %s\n", sprintrc(rc));
40 rc = syscall(__NR_prctl, PR_GET_TSC, NULL);
41 printf("prctl(PR_GET_TSC, NULL) = %s\n", sprintrc(rc));
43 rc = syscall(__NR_prctl, PR_GET_TSC, tsc + 1);
44 printf("prctl(PR_GET_TSC, %p) = %s\n", tsc + 1, sprintrc(rc));
46 rc = syscall(__NR_prctl, PR_GET_TSC, tsc);
48 printf("prctl(PR_GET_TSC, %p) = %s\n", tsc, sprintrc(rc));
50 printf("prctl(PR_GET_TSC, [PR_TSC_SIGSEGV]) = %s\n",
53 puts("+++ exited with 0 +++");
59 SKIP_MAIN_UNDEFINED("__NR_prctl && PR_GET_TSC && PR_SET_TSC")