1 /* SPDX-License-Identifier: GPL-2.0-only */
2 #ifndef _LINUX_EXPORT_H
3 #define _LINUX_EXPORT_H
5 #include <linux/compiler.h>
6 #include <linux/linkage.h>
7 #include <linux/stringify.h>
10 * Export symbols from the kernel to modules. Forked from module.h
11 * to reduce the amount of pointless cruft we feed to gcc when only
12 * exporting a simple symbol or two.
14 * Try not to add #includes here. It slows compilation and makes kernel
15 * hackers place grumpy comments in header files.
19 * This comment block is used by fixdep. Please do not remove.
21 * When CONFIG_MODVERSIONS is changed from n to y, all source files having
22 * EXPORT_SYMBOL variants must be re-compiled because genksyms is run as a
23 * side effect of the *.o build rule.
28 extern struct module __this_module;
29 #define THIS_MODULE (&__this_module)
31 #define THIS_MODULE ((struct module *)0)
33 #endif /* __ASSEMBLY__ */
36 #define __EXPORT_SYMBOL_REF(sym) \
40 #define __EXPORT_SYMBOL_REF(sym) \
45 #define ___EXPORT_SYMBOL(sym, license, ns) \
46 .section ".export_symbol","a" ASM_NL \
47 __export_symbol_##sym: ASM_NL \
48 .asciz license ASM_NL \
50 __EXPORT_SYMBOL_REF(sym) ASM_NL \
53 #if defined(__DISABLE_EXPORTS)
56 * Allow symbol exports to be disabled completely so that C code may
57 * be reused in other execution contexts such as the UEFI stub or the
60 #define __EXPORT_SYMBOL(sym, license, ns)
62 #elif defined(__GENKSYMS__)
64 #define __EXPORT_SYMBOL(sym, license, ns) __GENKSYMS_EXPORT_SYMBOL(sym)
66 #elif defined(__ASSEMBLY__)
68 #define __EXPORT_SYMBOL(sym, license, ns) \
69 ___EXPORT_SYMBOL(sym, license, ns)
73 #define __EXPORT_SYMBOL(sym, license, ns) \
74 extern typeof(sym) sym; \
76 asm(__stringify(___EXPORT_SYMBOL(sym, license, ns)))
80 #ifdef DEFAULT_SYMBOL_NAMESPACE
81 #define _EXPORT_SYMBOL(sym, license) __EXPORT_SYMBOL(sym, license, __stringify(DEFAULT_SYMBOL_NAMESPACE))
83 #define _EXPORT_SYMBOL(sym, license) __EXPORT_SYMBOL(sym, license, "")
86 #define EXPORT_SYMBOL(sym) _EXPORT_SYMBOL(sym, "")
87 #define EXPORT_SYMBOL_GPL(sym) _EXPORT_SYMBOL(sym, "GPL")
88 #define EXPORT_SYMBOL_NS(sym, ns) __EXPORT_SYMBOL(sym, "", __stringify(ns))
89 #define EXPORT_SYMBOL_NS_GPL(sym, ns) __EXPORT_SYMBOL(sym, "GPL", __stringify(ns))
91 #endif /* _LINUX_EXPORT_H */