1 #ifndef _LINUX_MODULE_H
2 #define _LINUX_MODULE_H
9 #include <linux/list.h>
10 #include <linux/stat.h>
11 #include <linux/compiler.h>
14 #include <linux/elf.h>
19 #include <linux/export.h>
22 #include <asm/module.h>
25 #define MODULE_SIG_STRING "~Module signature appended~\n"
28 #define MODULE_SUPPORTED_DEVICE(name)
30 #define MODULE_NAME_LEN MAX_PARAM_PREFIX_LEN
52 const char *,
size_t count);
86 #define MODULE_GENERIC_TABLE(gtype,name) \
87 extern const struct gtype##_id __mod_##gtype##_table \
88 __attribute__ ((unused, alias(__stringify(name))))
91 #define MODULE_GENERIC_TABLE(gtype,name)
95 #define MODULE_INFO(tag, info) __MODULE_INFO(tag, tag, info)
98 #define MODULE_ALIAS(_alias) MODULE_INFO(alias, _alias)
128 #define MODULE_LICENSE(_license) MODULE_INFO(license, _license)
134 #define MODULE_AUTHOR(_author) MODULE_INFO(author, _author)
137 #define MODULE_DESCRIPTION(_description) MODULE_INFO(description, _description)
139 #define MODULE_DEVICE_TABLE(type,name) \
140 MODULE_GENERIC_TABLE(type##_device,name)
157 #if defined(MODULE) || !defined(CONFIG_SYSFS)
158 #define MODULE_VERSION(_version) MODULE_INFO(version, _version)
160 #define MODULE_VERSION(_version) \
161 static struct module_version_attribute ___modver_attr = { \
167 .show = __modver_version_show, \
169 .module_name = KBUILD_MODNAME, \
170 .version = _version, \
172 static const struct module_version_attribute \
173 __used __attribute__ ((__section__ ("__modver"))) \
174 * __moduleparam_const __modver_attr = &___modver_attr
180 #define MODULE_FIRMWARE(_firmware) MODULE_INFO(firmware, _firmware)
187 #ifdef CONFIG_MODULES
192 void *__symbol_get_gpl(
const char *
symbol);
193 #define symbol_get(x) ((typeof(&x))(__symbol_get(MODULE_SYMBOL_PREFIX #x)))
225 enum module_state
state;
242 const unsigned long *crcs;
243 unsigned int num_syms;
250 unsigned int num_gpl_syms;
252 const unsigned long *gpl_crcs;
254 #ifdef CONFIG_UNUSED_SYMBOLS
257 const unsigned long *unused_crcs;
258 unsigned int num_unused_syms;
261 unsigned int num_unused_gpl_syms;
263 const unsigned long *unused_gpl_crcs;
266 #ifdef CONFIG_MODULE_SIG
273 const unsigned long *gpl_future_crcs;
274 unsigned int num_gpl_future_syms;
277 unsigned int num_exentries;
293 unsigned int init_text_size, core_text_size;
296 unsigned int init_ro_size, core_ro_size;
303 #ifdef CONFIG_GENERIC_BUG
307 struct bug_entry *bug_table;
310 #ifdef CONFIG_KALLSYMS
317 unsigned int num_symtab, core_num_syms;
318 char *strtab, *core_strtab;
321 struct module_sect_attrs *sect_attrs;
324 struct module_notes_attrs *notes_attrs;
334 unsigned int percpu_size;
337 #ifdef CONFIG_TRACEPOINTS
338 unsigned int num_tracepoints;
341 #ifdef HAVE_JUMP_LABEL
343 unsigned int num_jump_entries;
345 #ifdef CONFIG_TRACING
346 unsigned int num_trace_bprintk_fmt;
347 const char **trace_bprintk_fmt_start;
349 #ifdef CONFIG_EVENT_TRACING
351 unsigned int num_trace_events;
353 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
354 unsigned int num_ftrace_callsites;
355 unsigned long *ftrace_callsites;
358 #ifdef CONFIG_MODULE_UNLOAD
373 #ifdef CONFIG_CONSTRUCTORS
376 unsigned int num_ctors;
379 #ifndef MODULE_ARCH_INIT
380 #define MODULE_ARCH_INIT {}
383 extern struct mutex module_mutex;
388 static inline int module_is_live(
struct module *
mod)
390 return mod->state != MODULE_STATE_GOING;
399 static inline int within_module_core(
unsigned long addr,
struct module *
mod)
401 return (
unsigned long)mod->module_core <= addr &&
402 addr < (
unsigned long)mod->module_core + mod->core_size;
405 static inline int within_module_init(
unsigned long addr,
struct module *mod)
407 return (
unsigned long)mod->module_init <= addr &&
408 addr < (
unsigned long)mod->module_init + mod->init_size;
416 const unsigned long *crcs;
428 const unsigned long **
crc,
435 void *
data),
void *data);
439 int module_get_kallsym(
unsigned int symnum,
unsigned long *
value,
char *
type,
443 unsigned long module_kallsyms_lookup_name(
const char *
name);
445 int module_kallsyms_on_each_symbol(
int (*
fn)(
void *,
const char *,
446 struct module *,
unsigned long),
451 #define module_put_and_exit(code) __module_put_and_exit(THIS_MODULE, code);
453 #ifdef CONFIG_MODULE_UNLOAD
454 unsigned long module_refcount(
struct module *mod);
455 void __symbol_put(
const char *
symbol);
456 #define symbol_put(x) __symbol_put(MODULE_SYMBOL_PREFIX #x)
470 static inline int try_module_get(struct module *module)
480 #define symbol_put(x) do { } while(0)
481 #define symbol_put_addr(p) do { } while(0)
487 #define module_name(mod) \
489 struct module *__mod = (mod); \
490 __mod ? __mod->name : "kernel"; \
496 const char *module_address_lookup(
unsigned long addr,
497 unsigned long *symbolsize,
501 int lookup_module_symbol_name(
unsigned long addr,
char *symname);
502 int lookup_module_symbol_attrs(
unsigned long addr,
unsigned long *
size,
unsigned long *
offset,
char *
modname,
char *
name);
547 #define symbol_get(x) ({ extern typeof(x) x __attribute__((weak)); &(x); })
548 #define symbol_put(x) do { } while(0)
549 #define symbol_put_addr(x) do { } while(0)
564 #define module_name(mod) "kernel"
567 static inline const char *module_address_lookup(
unsigned long addr,
568 unsigned long *symbolsize,
576 static inline int lookup_module_symbol_name(
unsigned long addr,
char *symname)
581 static inline int lookup_module_symbol_attrs(
unsigned long addr,
unsigned long *
size,
unsigned long *
offset,
char *
modname,
char *
name)
586 static inline int module_get_kallsym(
unsigned int symnum,
unsigned long *
value,
593 static inline unsigned long module_kallsyms_lookup_name(
const char *
name)
598 static inline int module_kallsyms_on_each_symbol(
int (*
fn)(
void *,
const char *,
617 #define module_put_and_exit(code) do_exit(code)
625 extern struct kset *module_kset;
627 extern int module_sysfs_initialized;
630 #define symbol_request(x) try_then_request_module(symbol_get(x), "symbol:" #x)
634 #define __MODULE_STRING(x) __stringify(x)
636 #ifdef CONFIG_DEBUG_SET_MODULE_RONX
637 extern void set_all_modules_text_rw(
void);
638 extern void set_all_modules_text_ro(
void);
640 static inline void set_all_modules_text_rw(
void) { }
641 static inline void set_all_modules_text_ro(
void) { }
644 #ifdef CONFIG_GENERIC_BUG
647 void module_bug_cleanup(
struct module *);
651 static inline void module_bug_finalize(
const Elf_Ehdr *
hdr,
656 static inline void module_bug_cleanup(
struct module *mod) {}