Debian Codegraph @

sysdeps/unix/sysv/linux/x86_64/x32/tst-prctl-x32.c

raw symbols SCIP
1 /* Smoke test for prctl.
2 Copyright (C) 2021-2026 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
18
19 #include <stdint.h>
20 #include <sys/prctl.h>
21 #include <support/check.h>
22
23 /* On x32, when parameters are passed in 64-bit registers, only the lower
24 32 bits are used and the upper 32 bits must be cleared. */
25 typedef union
26 {
27 struct
28 {
29 union
30 {
31 const char *ptr;
32 int i1;
33 };
34 int i2;
35 } s;
36 long long ll;
37 } parameter_t;
38
39 static int
40 __attribute__ ((noipa))
41 do_prctl (int op, long long arg1, long long arg2, long long arg3,
42 long long arg4)
43 {
44 return prctl (op, arg1, arg2, arg3, arg4);
45 }
46
47 static int
48 do_test (void)
49 {
50 parameter_t name = { { { "thread name" }, -1 } };
51 parameter_t zero = { { { 0 }, -2 } };
52 TEST_COMPARE (do_prctl (PR_SET_NAME, name.ll, zero.ll, zero.ll,
53 zero.ll), 0);
54 char buffer[16] = { 0, };
55 name.s.ptr = buffer;
56 TEST_COMPARE (do_prctl (PR_GET_NAME, name.ll, zero.ll, zero.ll,
57 zero.ll), 0);
58 char expected[16] = "thread name";
59 TEST_COMPARE_BLOB (buffer, sizeof (buffer), expected, sizeof (expected));
60 return 0;
61 }
62
63 #include <support/test-driver.c>