2 * Check decoding of prctl PR_GET_TID_ADDRESS operation.
4 * Copyright (c) 2016 Eugene Syromyatnikov <evgsyr@gmail.com>
5 * Copyright (c) 2016-2018 The strace developers.
8 * SPDX-License-Identifier: GPL-2.0-or-later
12 #include <asm/unistd.h>
13 #include <linux/prctl.h>
15 #if defined __NR_prctl && defined __NR_set_tid_address && \
16 defined PR_GET_TID_ADDRESS
18 # include <inttypes.h>
23 sprintaddr(kernel_ulong_t addr)
25 static char buf[sizeof("0x") + sizeof(addr) * 2];
28 snprintf(buf, sizeof(buf), "%#llx", (unsigned long long) addr);
39 static const kernel_ulong_t bogus_addr =
40 (kernel_ulong_t) 0xfffffffffffffffdULL;
42 /* Note that kernel puts kernel-sized pointer even on x32 */
43 TAIL_ALLOC_OBJECT_CONST_PTR(kernel_ulong_t, ptr);
47 *ptr = (kernel_ulong_t) 0xbadc0dedda7a1057ULL;
49 rc = syscall(__NR_prctl, PR_GET_TID_ADDRESS, NULL);
50 printf("prctl(PR_GET_TID_ADDRESS, NULL) = %s\n", sprintrc(rc));
52 rc = syscall(__NR_prctl, PR_GET_TID_ADDRESS, bogus_addr);
53 printf("prctl(PR_GET_TID_ADDRESS, %#llx) = %s\n",
54 (unsigned long long) bogus_addr, sprintrc(rc));
56 rc = syscall(__NR_prctl, PR_GET_TID_ADDRESS, ptr);
58 printf("prctl(PR_GET_TID_ADDRESS, %p) = %s\n",
61 printf("prctl(PR_GET_TID_ADDRESS, [%s]) = %s\n",
62 sprintaddr(*ptr), sprintrc(rc));
65 set_ok = syscall(__NR_set_tid_address, bogus_addr);
67 rc = syscall(__NR_prctl, PR_GET_TID_ADDRESS, ptr);
69 printf("prctl(PR_GET_TID_ADDRESS, %p) = %s\n",
72 printf("prctl(PR_GET_TID_ADDRESS, [%s]) = %s\n",
73 sprintaddr(set_ok ? bogus_addr : *ptr), sprintrc(rc));
76 puts("+++ exited with 0 +++");
82 SKIP_MAIN_UNDEFINED("__NR_prctl && __NR_set_tid_address && PR_GET_TID_ADDRESS")