1 /*
2 * Check decoding of prctl PR_GET_UNALIGN/PR_SET_UNALIGN operations.
3 *
4 * Copyright (c) 2021 The strace developers.
5 * All rights reserved.
6 *
7 * SPDX-License-Identifier: GPL-2.0-or-later
8 */
9
10 #include "tests.h"
11 #include "scno.h"
12 #include <stdio.h>
13 #include <unistd.h>
14 #include <linux/prctl.h>
15
16 int
17 main(void)
18 {
19 TAIL_ALLOC_OBJECT_CONST_PTR(unsigned int, unalign);
20 long rc;
21
22 prctl_marker();
23
24 rc = syscall(__NR_prctl, PR_SET_UNALIGN, PR_UNALIGN_NOPRINT | PR_UNALIGN_SIGBUS);
25 printf("prctl(PR_SET_UNALIGN, PR_UNALIGN_NOPRINT|PR_UNALIGN_SIGBUS) = %s\n",
26 sprintrc(rc));
27
28 rc = syscall(__NR_prctl, PR_SET_UNALIGN, 0xff00);
29 printf("prctl(PR_SET_UNALIGN, %#llx /* PR_UNALIGN_??? */) = %s\n",
30 (unsigned long long) 0xff00, sprintrc(rc));
31
32 rc = syscall(__NR_prctl, PR_SET_UNALIGN, PR_UNALIGN_SIGBUS);
33 printf("prctl(PR_SET_UNALIGN, PR_UNALIGN_SIGBUS) = %s\n", sprintrc(rc));
34
35 rc = syscall(__NR_prctl, PR_GET_UNALIGN, unalign + 1);
36 printf("prctl(PR_GET_UNALIGN, %p) = %s\n", unalign + 1, sprintrc(rc));
37
38 rc = syscall(__NR_prctl, PR_GET_UNALIGN, NULL);
39 printf("prctl(PR_GET_UNALIGN, NULL) = %s\n", sprintrc(rc));
40
41 rc = syscall(__NR_prctl, PR_GET_UNALIGN, unalign);
42 if (rc)
43 printf("prctl(PR_GET_UNALIGN, %p) = %s\n", unalign, sprintrc(rc));
44 else
45 printf("prctl(PR_GET_UNALIGN, [PR_UNALIGN_SIGBUS]) = %s\n",
46 sprintrc(rc));
47
48 puts("+++ exited with 0 +++");
49 return 0;
50 }