xref: /openbmc/linux/arch/arm64/include/asm/compiler.h (revision 6f2bde9b)
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 #define xpaclri(ptr)							\
12 ({									\
13 	register unsigned long __xpaclri_ptr asm("x30") = (ptr);	\
14 									\
15 	asm(								\
16 	ARM64_ASM_PREAMBLE						\
17 	"	hint	#7\n"						\
18 	: "+r" (__xpaclri_ptr));					\
19 									\
20 	__xpaclri_ptr;							\
21 })
22 
23 #ifdef CONFIG_ARM64_PTR_AUTH_KERNEL
24 #define ptrauth_strip_kernel_insn_pac(ptr)	xpaclri(ptr)
25 #else
26 #define ptrauth_strip_kernel_insn_pac(ptr)	(ptr)
27 #endif
28 
29 #ifdef CONFIG_ARM64_PTR_AUTH
30 #define ptrauth_strip_user_insn_pac(ptr)	xpaclri(ptr)
31 #else
32 #define ptrauth_strip_user_insn_pac(ptr)	(ptr)
33 #endif
34 
35 #if !defined(CONFIG_BUILTIN_RETURN_ADDRESS_STRIPS_PAC)
36 #define __builtin_return_address(val)					\
37 	(void *)(ptrauth_strip_kernel_insn_pac((unsigned long)__builtin_return_address(val)))
38 #endif
39 
40 #endif /* __ASM_COMPILER_H */
41