]>
git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blob - include/linux/static_call_types.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _STATIC_CALL_TYPES_H
3 #define _STATIC_CALL_TYPES_H
5 #include <linux/types.h>
6 #include <linux/stringify.h>
7 #include <linux/compiler.h>
9 #define STATIC_CALL_KEY_PREFIX __SCK__
10 #define STATIC_CALL_KEY_PREFIX_STR __stringify(STATIC_CALL_KEY_PREFIX)
11 #define STATIC_CALL_KEY_PREFIX_LEN (sizeof(STATIC_CALL_KEY_PREFIX_STR) - 1)
12 #define STATIC_CALL_KEY(name) __PASTE(STATIC_CALL_KEY_PREFIX, name)
13 #define STATIC_CALL_KEY_STR(name) __stringify(STATIC_CALL_KEY(name))
15 #define STATIC_CALL_TRAMP_PREFIX __SCT__
16 #define STATIC_CALL_TRAMP_PREFIX_STR __stringify(STATIC_CALL_TRAMP_PREFIX)
17 #define STATIC_CALL_TRAMP_PREFIX_LEN (sizeof(STATIC_CALL_TRAMP_PREFIX_STR) - 1)
18 #define STATIC_CALL_TRAMP(name) __PASTE(STATIC_CALL_TRAMP_PREFIX, name)
19 #define STATIC_CALL_TRAMP_STR(name) __stringify(STATIC_CALL_TRAMP(name))
22 * Flags in the low bits of static_call_site::key.
24 #define STATIC_CALL_SITE_TAIL 1UL /* tail call */
25 #define STATIC_CALL_SITE_INIT 2UL /* init section */
26 #define STATIC_CALL_SITE_FLAGS 3UL
29 * The static call site table needs to be created by external tooling (objtool
30 * or a compiler plugin).
32 struct static_call_site
{
37 #define DECLARE_STATIC_CALL(name, func) \
38 extern struct static_call_key STATIC_CALL_KEY(name); \
39 extern typeof(func) STATIC_CALL_TRAMP(name);
41 #ifdef CONFIG_HAVE_STATIC_CALL
43 #define __raw_static_call(name) (&STATIC_CALL_TRAMP(name))
45 #ifdef CONFIG_HAVE_STATIC_CALL_INLINE
48 * __ADDRESSABLE() is used to ensure the key symbol doesn't get stripped from
49 * the symbol table so that objtool can reference it when it generates the
50 * .static_call_sites section.
52 #define __STATIC_CALL_ADDRESSABLE(name) \
53 __ADDRESSABLE(STATIC_CALL_KEY(name))
55 #define __static_call(name) \
57 __STATIC_CALL_ADDRESSABLE(name); \
58 __raw_static_call(name); \
61 #else /* !CONFIG_HAVE_STATIC_CALL_INLINE */
63 #define __STATIC_CALL_ADDRESSABLE(name)
64 #define __static_call(name) __raw_static_call(name)
66 #endif /* CONFIG_HAVE_STATIC_CALL_INLINE */
69 #define __STATIC_CALL_MOD_ADDRESSABLE(name)
70 #define static_call_mod(name) __raw_static_call(name)
72 #define __STATIC_CALL_MOD_ADDRESSABLE(name) __STATIC_CALL_ADDRESSABLE(name)
73 #define static_call_mod(name) __static_call(name)
76 #define static_call(name) __static_call(name)
80 #define static_call(name) \
81 ((typeof(STATIC_CALL_TRAMP(name))*)(STATIC_CALL_KEY(name).func))
83 #endif /* CONFIG_HAVE_STATIC_CALL */
85 #endif /* _STATIC_CALL_TYPES_H */