1 // SPDX-License-Identifier: GPL-2.0-only
3 // Copyright 2024 Arm Limited
5 // Give ourselves GCS push permissions then use them
7 #include <asm/unistd.h>
9 /* Shadow Stack/Guarded Control Stack interface */
10 #define PR_GET_SHADOW_STACK_STATUS 74
11 #define PR_SET_SHADOW_STACK_STATUS 75
12 #define PR_LOCK_SHADOW_STACK_STATUS 76
14 # define PR_SHADOW_STACK_ENABLE (1UL << 0)
15 # define PR_SHADOW_STACK_WRITE (1UL << 1)
16 # define PR_SHADOW_STACK_PUSH (1UL << 2)
22 .type \name, @function
28 // Print a single character x0 to stdout
33 mov x0, #1 // STDOUT_FILENO
44 // Print a NUL-terminated string starting at address x0 to stdout
55 1: mov w0, #1 // STDOUT_FILENO
63 // Utility macro to print a literal string
66 .pushsection .rodata.str1.1, "aMS", @progbits, 1
67 .L__puts_literal\@: .string "\string"
70 ldr x0, =.L__puts_literal\@
77 mov x0, PR_SET_SHADOW_STACK_STATUS
78 mov x1, PR_SHADOW_STACK_ENABLE | PR_SHADOW_STACK_PUSH
86 puts "Failed to enable GCS with push permission\n"
90 sys #3, c7, c7, #0, x0 // GCSPUSHM
91 sysl x0, #3, c7, c7, #1 // GCSPOPM