1 /* SPDX-License-Identifier: GPL-2.0 */ 2 #ifndef __ASM_COMPILER_H 3 #define __ASM_COMPILER_H 4 5 #ifdef ARM64_ASM_ARCH 6 #define ARM64_ASM_PREAMBLE ".arch " ARM64_ASM_ARCH "\n" 7 #else 8 #define ARM64_ASM_PREAMBLE 9 #endif 10 11 /* 12 * The EL0/EL1 pointer bits used by a pointer authentication code. 13 * This is dependent on TBI0/TBI1 being enabled, or bits 63:56 would also apply. 14 */ 15 #define ptrauth_user_pac_mask() GENMASK_ULL(54, vabits_actual) 16 #define ptrauth_kernel_pac_mask() GENMASK_ULL(63, vabits_actual) 17 18 /* Valid for EL0 TTBR0 and EL1 TTBR1 instruction pointers */ 19 #define ptrauth_clear_pac(ptr) \ 20 ((ptr & BIT_ULL(55)) ? (ptr | ptrauth_kernel_pac_mask()) : \ 21 (ptr & ~ptrauth_user_pac_mask())) 22 23 #define __builtin_return_address(val) \ 24 (void *)(ptrauth_clear_pac((unsigned long)__builtin_return_address(val))) 25 26 #ifdef CONFIG_CFI_CLANG 27 /* 28 * With CONFIG_CFI_CLANG, the compiler replaces function address 29 * references with the address of the function's CFI jump table 30 * entry. The function_nocfi macro always returns the address of the 31 * actual function instead. 32 */ 33 #define function_nocfi(x) ({ \ 34 void *addr; \ 35 asm("adrp %0, " __stringify(x) "\n\t" \ 36 "add %0, %0, :lo12:" __stringify(x) \ 37 : "=r" (addr)); \ 38 addr; \ 39 }) 40 #endif 41 42 #endif /* __ASM_COMPILER_H */ 43