diff options
Diffstat (limited to 'include/linux/module.h')
-rw-r--r-- | include/linux/module.h | 145 |
1 files changed, 55 insertions, 90 deletions
diff --git a/include/linux/module.h b/include/linux/module.h index 482efc865acf..0bb0f7464ff0 100644 --- a/include/linux/module.h +++ b/include/linux/module.h @@ -15,6 +15,7 @@ #include <linux/stringify.h> #include <linux/kobject.h> #include <linux/moduleparam.h> +#include <linux/mod_export.h> #include <linux/tracepoint.h> #include <asm/local.h> @@ -25,19 +26,8 @@ /* Not Yet Implemented */ #define MODULE_SUPPORTED_DEVICE(name) -/* some toolchains uses a `_' prefix for all user symbols */ -#ifndef MODULE_SYMBOL_PREFIX -#define MODULE_SYMBOL_PREFIX "" -#endif - #define MODULE_NAME_LEN MAX_PARAM_PREFIX_LEN -struct kernel_symbol -{ - unsigned long value; - const char *name; -}; - struct modversion_info { unsigned long crc; @@ -178,51 +168,61 @@ void *__symbol_get(const char *symbol); void *__symbol_get_gpl(const char *symbol); #define symbol_get(x) ((typeof(&x))(__symbol_get(MODULE_SYMBOL_PREFIX #x))) -#ifndef __GENKSYMS__ -#ifdef CONFIG_MODVERSIONS -/* Mark the CRC weak since genksyms apparently decides not to - * generate a checksums for some symbols */ -#define __CRC_SYMBOL(sym, sec) \ - extern void *__crc_##sym __attribute__((weak)); \ - static const unsigned long __kcrctab_##sym \ - __used \ - __attribute__((section("__kcrctab" sec), unused)) \ - = (unsigned long) &__crc_##sym; -#else -#define __CRC_SYMBOL(sym, sec) -#endif +#ifdef CONFIG_UNUSED_SYMBOLS +enum export_type { + /* GPL-only exported symbols. */ + __EXPORT_FLAG_GPL_ONLY = 0x1, -/* For every exported symbol, place a struct in the __ksymtab section */ -#define __EXPORT_SYMBOL(sym, sec) \ - extern typeof(sym) sym; \ - __CRC_SYMBOL(sym, sec) \ - static const char __kstrtab_##sym[] \ - __attribute__((section("__ksymtab_strings"), aligned(1))) \ - = MODULE_SYMBOL_PREFIX #sym; \ - static const struct kernel_symbol __ksymtab_##sym \ - __used \ - __attribute__((section("__ksymtab" sec), unused)) \ - = { (unsigned long)&sym, __kstrtab_##sym } + /* unused exported symbols. */ + __EXPORT_FLAG_UNUSED = 0x2, -#define EXPORT_SYMBOL(sym) \ - __EXPORT_SYMBOL(sym, "") + /* exports that will be GPL-only in the near future. */ + __EXPORT_FLAG_GPL_FUTURE = 0x4, -#define EXPORT_SYMBOL_GPL(sym) \ - __EXPORT_SYMBOL(sym, "_gpl") + EXPORT_TYPE_PLAIN = 0x0, + EXPORT_TYPE_GPL = 0x1, + EXPORT_TYPE_UNUSED = 0x2, + EXPORT_TYPE_UNUSED_GPL = 0x3, + EXPORT_TYPE_GPL_FUTURE = 0x4, -#define EXPORT_SYMBOL_GPL_FUTURE(sym) \ - __EXPORT_SYMBOL(sym, "_gpl_future") + EXPORT_TYPE_MAX +}; +#else /* !CONFIG_UNUSED_EXPORTS */ +enum export_type { + __EXPORT_FLAG_UNUSED = 0x0, + __EXPORT_FLAG_GPL_ONLY = 0x1, + __EXPORT_FLAG_GPL_FUTURE = 0x2, -#ifdef CONFIG_UNUSED_SYMBOLS -#define EXPORT_UNUSED_SYMBOL(sym) __EXPORT_SYMBOL(sym, "_unused") -#define EXPORT_UNUSED_SYMBOL_GPL(sym) __EXPORT_SYMBOL(sym, "_unused_gpl") -#else -#define EXPORT_UNUSED_SYMBOL(sym) -#define EXPORT_UNUSED_SYMBOL_GPL(sym) + EXPORT_TYPE_PLAIN = 0x0, + EXPORT_TYPE_GPL = 0x1, + EXPORT_TYPE_GPL_FUTURE = 0x2, + EXPORT_TYPE_MAX +}; #endif +static inline bool export_is_gpl_only(enum export_type type) +{ + return (type & __EXPORT_FLAG_GPL_ONLY); +} + +static inline bool export_is_unused(enum export_type type) +{ + return (type & __EXPORT_FLAG_UNUSED); +} + +static inline bool export_is_gpl_future(enum export_type type) +{ + return (type & __EXPORT_FLAG_GPL_FUTURE); +} + +struct ksymtab { + const struct kernel_symbol *syms; +#ifdef CONFIG_MODVERSIONS + const unsigned long *crcs; #endif + unsigned int num_syms; +}; enum module_state { @@ -249,36 +249,12 @@ struct module struct kobject *holders_dir; /* Exported symbols */ - const struct kernel_symbol *syms; - const unsigned long *crcs; - unsigned int num_syms; + struct ksymtab syms[EXPORT_TYPE_MAX]; /* Kernel parameters. */ struct kernel_param *kp; unsigned int num_kp; - /* GPL-only exported symbols. */ - unsigned int num_gpl_syms; - const struct kernel_symbol *gpl_syms; - const unsigned long *gpl_crcs; - -#ifdef CONFIG_UNUSED_SYMBOLS - /* unused exported symbols. */ - const struct kernel_symbol *unused_syms; - const unsigned long *unused_crcs; - unsigned int num_unused_syms; - - /* GPL-only, unused exported symbols. */ - unsigned int num_unused_gpl_syms; - const struct kernel_symbol *unused_gpl_syms; - const unsigned long *unused_gpl_crcs; -#endif - - /* symbols that will be GPL-only in the near future. */ - const struct kernel_symbol *gpl_future_syms; - const unsigned long *gpl_future_crcs; - unsigned int num_gpl_future_syms; - /* Exception table */ unsigned int num_exentries; struct exception_table_entry *extable; @@ -408,17 +384,6 @@ static inline int within_module_init(unsigned long addr, struct module *mod) /* Search for module by name: must hold module_mutex. */ struct module *find_module(const char *name); -struct symsearch { - const struct kernel_symbol *start, *stop; - const unsigned long *crcs; - enum { - NOT_GPL_ONLY, - GPL_ONLY, - WILL_BE_GPL_ONLY, - } licence; - bool unused; -}; - /* Search for an exported symbol by name. */ const struct kernel_symbol *find_symbol(const char *name, struct module **owner, @@ -426,9 +391,14 @@ const struct kernel_symbol *find_symbol(const char *name, bool gplok, bool warn); +typedef bool each_symbol_fn_t (enum export_type type, + const struct kernel_symbol *sym, + const unsigned long *crc, + struct module *owner, + void *data); + /* Walk the exported symbol table */ -bool each_symbol(bool (*fn)(const struct symsearch *arr, struct module *owner, - unsigned int symnum, void *data), void *data); +bool each_symbol(each_symbol_fn_t *fn, void *data); /* Returns 0 and fills in value, defined and namebuf, or -ERANGE if symnum out of range. */ @@ -541,11 +511,6 @@ extern void module_update_tracepoints(void); extern int module_get_iter_tracepoints(struct tracepoint_iter *iter); #else /* !CONFIG_MODULES... */ -#define EXPORT_SYMBOL(sym) -#define EXPORT_SYMBOL_GPL(sym) -#define EXPORT_SYMBOL_GPL_FUTURE(sym) -#define EXPORT_UNUSED_SYMBOL(sym) -#define EXPORT_UNUSED_SYMBOL_GPL(sym) /* Given an address, look for it in the exception tables. */ static inline const struct exception_table_entry * |