#include #include #include #ifndef PR_SET_SHADOW_STACK_STATUS #define PR_SET_SHADOW_STACK_STATUS 75 #define PR_SHADOW_STACK_ENABLE (1UL << 0) #endif /* We need to use a macro to call prctl because after GCS is enabled, it's not possible to return from the function which enabled it. This is because the return address of the calling function isn't on the GCS. */ #define my_syscall2(num, arg1, arg2) \ ({ \ register long _num __asm__("x8") = (num); \ register long _arg1 __asm__("x0") = (long)(arg1); \ register long _arg2 __asm__("x1") = (long)(arg2); \ register long _arg3 __asm__("x2") = 0; \ register long _arg4 __asm__("x3") = 0; \ register long _arg5 __asm__("x4") = 0; \ \ asm volatile ("svc #0\n" \ : "=r"(_arg1) \ : "r"(_arg1), "r"(_arg2), "r"(_arg3), "r"(_arg4), \ "r"(_arg5), "r"(_num) \ : "memory", "cc"); \ _arg1; \ }) int main (void) { int ret; ret = my_syscall2 (__NR_prctl, PR_SET_SHADOW_STACK_STATUS, PR_SHADOW_STACK_ENABLE); /* Don't return from main to avoid segmentation fault. */ exit (ret); }