Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef _ASM_STATIC_CALL_H
0003 #define _ASM_STATIC_CALL_H
0004 
0005 #include <asm/text-patching.h>
0006 
0007 /*
0008  * For CONFIG_HAVE_STATIC_CALL_INLINE, this is a temporary trampoline which
0009  * uses the current value of the key->func pointer to do an indirect jump to
0010  * the function.  This trampoline is only used during boot, before the call
0011  * sites get patched by static_call_update().  The name of this trampoline has
0012  * a magical aspect: objtool uses it to find static call sites so it can create
0013  * the .static_call_sites section.
0014  *
0015  * For CONFIG_HAVE_STATIC_CALL, this is a permanent trampoline which
0016  * does a direct jump to the function.  The direct jump gets patched by
0017  * static_call_update().
0018  *
0019  * Having the trampoline in a special section forces GCC to emit a JMP.d32 when
0020  * it does tail-call optimization on the call; since you cannot compute the
0021  * relative displacement across sections.
0022  */
0023 
0024 /*
0025  * The trampoline is 8 bytes and of the general form:
0026  *
0027  *   jmp.d32 \func
0028  *   ud1 %esp, %ecx
0029  *
0030  * That trailing #UD provides both a speculation stop and serves as a unique
0031  * 3 byte signature identifying static call trampolines. Also see tramp_ud[]
0032  * and __static_call_fixup().
0033  */
0034 #define __ARCH_DEFINE_STATIC_CALL_TRAMP(name, insns)            \
0035     asm(".pushsection .static_call.text, \"ax\"     \n" \
0036         ".align 4                       \n" \
0037         ".globl " STATIC_CALL_TRAMP_STR(name) "     \n" \
0038         STATIC_CALL_TRAMP_STR(name) ":          \n" \
0039         ANNOTATE_NOENDBR                        \
0040         insns "                     \n" \
0041         ".byte 0x0f, 0xb9, 0xcc             \n" \
0042         ".type " STATIC_CALL_TRAMP_STR(name) ", @function   \n" \
0043         ".size " STATIC_CALL_TRAMP_STR(name) ", . - " STATIC_CALL_TRAMP_STR(name) " \n" \
0044         ".popsection                    \n")
0045 
0046 #define ARCH_DEFINE_STATIC_CALL_TRAMP(name, func)           \
0047     __ARCH_DEFINE_STATIC_CALL_TRAMP(name, ".byte 0xe9; .long " #func " - (. + 4)")
0048 
0049 #ifdef CONFIG_RETHUNK
0050 #define ARCH_DEFINE_STATIC_CALL_NULL_TRAMP(name)            \
0051     __ARCH_DEFINE_STATIC_CALL_TRAMP(name, "jmp __x86_return_thunk")
0052 #else
0053 #define ARCH_DEFINE_STATIC_CALL_NULL_TRAMP(name)            \
0054     __ARCH_DEFINE_STATIC_CALL_TRAMP(name, "ret; int3; nop; nop; nop")
0055 #endif
0056 
0057 #define ARCH_DEFINE_STATIC_CALL_RET0_TRAMP(name)            \
0058     ARCH_DEFINE_STATIC_CALL_TRAMP(name, __static_call_return0)
0059 
0060 #define ARCH_ADD_TRAMP_KEY(name)                    \
0061     asm(".pushsection .static_call_tramp_key, \"a\"     \n" \
0062         ".long " STATIC_CALL_TRAMP_STR(name) " - .      \n" \
0063         ".long " STATIC_CALL_KEY_STR(name) " - .        \n" \
0064         ".popsection                    \n")
0065 
0066 extern bool __static_call_fixup(void *tramp, u8 op, void *dest);
0067 
0068 #endif /* _ASM_STATIC_CALL_H */