1 // SPDX-License-Identifier: GPL-2.0-only
3 // Copyright 2024 Arm Limited
5 // Give ourselves GCS write 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)
18 #define GCSPR_EL0 S3_3_C2_C5_1
24 .type \name, @function
30 // Print a single character x0 to stdout
35 mov x0, #1 // STDOUT_FILENO
46 // Print a NUL-terminated string starting at address x0 to stdout
57 1: mov w0, #1 // STDOUT_FILENO
65 // Utility macro to print a literal string
68 .pushsection .rodata.str1.1, "aMS", @progbits, 1
69 .L__puts_literal\@: .string "\string"
72 ldr x0, =.L__puts_literal\@
79 mov x0, PR_SET_SHADOW_STACK_STATUS
80 mov x1, PR_SHADOW_STACK_ENABLE | PR_SHADOW_STACK_WRITE
88 puts "Failed to enable GCS with write permission\n"
94 .inst 0xd91f1c01 // GCSSTR x1, x0