Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef _STATIC_CALL_TYPES_H
0003 #define _STATIC_CALL_TYPES_H
0004 
0005 #include <linux/types.h>
0006 #include <linux/stringify.h>
0007 #include <linux/compiler.h>
0008 
0009 #define STATIC_CALL_KEY_PREFIX      __SCK__
0010 #define STATIC_CALL_KEY_PREFIX_STR  __stringify(STATIC_CALL_KEY_PREFIX)
0011 #define STATIC_CALL_KEY_PREFIX_LEN  (sizeof(STATIC_CALL_KEY_PREFIX_STR) - 1)
0012 #define STATIC_CALL_KEY(name)       __PASTE(STATIC_CALL_KEY_PREFIX, name)
0013 #define STATIC_CALL_KEY_STR(name)   __stringify(STATIC_CALL_KEY(name))
0014 
0015 #define STATIC_CALL_TRAMP_PREFIX    __SCT__
0016 #define STATIC_CALL_TRAMP_PREFIX_STR    __stringify(STATIC_CALL_TRAMP_PREFIX)
0017 #define STATIC_CALL_TRAMP_PREFIX_LEN    (sizeof(STATIC_CALL_TRAMP_PREFIX_STR) - 1)
0018 #define STATIC_CALL_TRAMP(name)     __PASTE(STATIC_CALL_TRAMP_PREFIX, name)
0019 #define STATIC_CALL_TRAMP_STR(name) __stringify(STATIC_CALL_TRAMP(name))
0020 
0021 /*
0022  * Flags in the low bits of static_call_site::key.
0023  */
0024 #define STATIC_CALL_SITE_TAIL 1UL   /* tail call */
0025 #define STATIC_CALL_SITE_INIT 2UL   /* init section */
0026 #define STATIC_CALL_SITE_FLAGS 3UL
0027 
0028 /*
0029  * The static call site table needs to be created by external tooling (objtool
0030  * or a compiler plugin).
0031  */
0032 struct static_call_site {
0033     s32 addr;
0034     s32 key;
0035 };
0036 
0037 #define DECLARE_STATIC_CALL(name, func)                 \
0038     extern struct static_call_key STATIC_CALL_KEY(name);        \
0039     extern typeof(func) STATIC_CALL_TRAMP(name);
0040 
0041 #ifdef CONFIG_HAVE_STATIC_CALL
0042 
0043 #define __raw_static_call(name) (&STATIC_CALL_TRAMP(name))
0044 
0045 #ifdef CONFIG_HAVE_STATIC_CALL_INLINE
0046 
0047 /*
0048  * __ADDRESSABLE() is used to ensure the key symbol doesn't get stripped from
0049  * the symbol table so that objtool can reference it when it generates the
0050  * .static_call_sites section.
0051  */
0052 #define __STATIC_CALL_ADDRESSABLE(name) \
0053     __ADDRESSABLE(STATIC_CALL_KEY(name))
0054 
0055 #define __static_call(name)                     \
0056 ({                                  \
0057     __STATIC_CALL_ADDRESSABLE(name);                \
0058     __raw_static_call(name);                    \
0059 })
0060 
0061 struct static_call_key {
0062     void *func;
0063     union {
0064         /* bit 0: 0 = mods, 1 = sites */
0065         unsigned long type;
0066         struct static_call_mod *mods;
0067         struct static_call_site *sites;
0068     };
0069 };
0070 
0071 #else /* !CONFIG_HAVE_STATIC_CALL_INLINE */
0072 
0073 #define __STATIC_CALL_ADDRESSABLE(name)
0074 #define __static_call(name) __raw_static_call(name)
0075 
0076 struct static_call_key {
0077     void *func;
0078 };
0079 
0080 #endif /* CONFIG_HAVE_STATIC_CALL_INLINE */
0081 
0082 #ifdef MODULE
0083 #define __STATIC_CALL_MOD_ADDRESSABLE(name)
0084 #define static_call_mod(name)   __raw_static_call(name)
0085 #else
0086 #define __STATIC_CALL_MOD_ADDRESSABLE(name) __STATIC_CALL_ADDRESSABLE(name)
0087 #define static_call_mod(name)   __static_call(name)
0088 #endif
0089 
0090 #define static_call(name)   __static_call(name)
0091 
0092 #else
0093 
0094 struct static_call_key {
0095     void *func;
0096 };
0097 
0098 #define static_call(name)                       \
0099     ((typeof(STATIC_CALL_TRAMP(name))*)(STATIC_CALL_KEY(name).func))
0100 
0101 #endif /* CONFIG_HAVE_STATIC_CALL */
0102 
0103 #endif /* _STATIC_CALL_TYPES_H */