Debian Codegraph @

sysdeps/unix/sysv/linux/aarch64/tst-gcs-lock.c

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
•1 /* AArch64 test for GCS locking.
2 Copyright (C) 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 "tst-gcs-helper.h"
20
21 #include <linux/prctl.h>
22 #include <sys/prctl.h>
23 #include <errno.h>
24
25 static int
26 do_test (void)
27 {
28 /* Check if GCS could possible by enabled. */
29 if (!(getauxval (AT_HWCAP) & HWCAP_GCS))
30 FAIL_UNSUPPORTED ("kernel or CPU does not support GCS");
31
32 TEST_VERIFY (__check_gcs_status ());
33
34 /* Try disabling GCS. */
35 int res = prctl (PR_SET_SHADOW_STACK_STATUS, 0, 0, 0, 0);
36 if (res)
37 {
38 TEST_COMPARE (errno, EBUSY);
39 #ifdef GCS_SHOULD_UNLOCK
40 FAIL_EXIT1 ("GCS was not unlocked (was supposed to): %m");
41 #else
42 TEST_VERIFY (__check_gcs_status ());
43 #endif
44 }
45 else
46 {
47 #ifdef GCS_SHOULD_UNLOCK
48 TEST_VERIFY (!__check_gcs_status ());
49 puts ("GCS unlocked successfully");
50 #else
51 FAIL_EXIT1 ("GCS was unlocked (was not supposed to)");
52 #endif
53 }
54
55 return 0;
56 }
57
58 #include <support/test-driver.c>