11da177e4SLinus Torvalds #ifndef _LINUX_MODULE_H 21da177e4SLinus Torvalds #define _LINUX_MODULE_H 31da177e4SLinus Torvalds /* 41da177e4SLinus Torvalds * Dynamic loading of modules into the kernel. 51da177e4SLinus Torvalds * 61da177e4SLinus Torvalds * Rewritten by Richard Henderson <[email protected]> Dec 1996 71da177e4SLinus Torvalds * Rewritten again by Rusty Russell, 2002 81da177e4SLinus Torvalds */ 91da177e4SLinus Torvalds #include <linux/list.h> 101da177e4SLinus Torvalds #include <linux/stat.h> 111da177e4SLinus Torvalds #include <linux/compiler.h> 121da177e4SLinus Torvalds #include <linux/cache.h> 131da177e4SLinus Torvalds #include <linux/kmod.h> 140fd972a7SPaul Gortmaker #include <linux/init.h> 151da177e4SLinus Torvalds #include <linux/elf.h> 161da177e4SLinus Torvalds #include <linux/stringify.h> 171da177e4SLinus Torvalds #include <linux/kobject.h> 181da177e4SLinus Torvalds #include <linux/moduleparam.h> 19b2e285fcSSteven Rostedt (Red Hat) #include <linux/jump_label.h> 20f5016932SPaul Gortmaker #include <linux/export.h> 2193c2e105SPeter Zijlstra #include <linux/rbtree_latch.h> 22663faf9fSMasami Hiramatsu #include <linux/error-injection.h> 239c0be3f6SMathieu Desnoyers #include <linux/tracepoint-defs.h> 241da177e4SLinus Torvalds 25e1783a24SChristoph Lameter #include <linux/percpu.h> 261da177e4SLinus Torvalds #include <asm/module.h> 271da177e4SLinus Torvalds 28106a4ee2SRusty Russell /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */ 29106a4ee2SRusty Russell #define MODULE_SIG_STRING "~Module signature appended~\n" 30106a4ee2SRusty Russell 311da177e4SLinus Torvalds /* Not Yet Implemented */ 321da177e4SLinus Torvalds #define MODULE_SUPPORTED_DEVICE(name) 331da177e4SLinus Torvalds 34730b69d2SRusty Russell #define MODULE_NAME_LEN MAX_PARAM_PREFIX_LEN 351da177e4SLinus Torvalds 36e865d06bSSeunghun Lee struct modversion_info { 371da177e4SLinus Torvalds unsigned long crc; 381da177e4SLinus Torvalds char name[MODULE_NAME_LEN]; 391da177e4SLinus Torvalds }; 401da177e4SLinus Torvalds 411da177e4SLinus Torvalds struct module; 420ef76537SPaul Gortmaker struct exception_table_entry; 431da177e4SLinus Torvalds 444befb026SKay Sievers struct module_kobject { 454befb026SKay Sievers struct kobject kobj; 464befb026SKay Sievers struct module *mod; 474befb026SKay Sievers struct kobject *drivers_dir; 484befb026SKay Sievers struct module_param_attrs *mp; 49942e4431SLi Zhong struct completion *kobj_completion; 503859a271SKees Cook } __randomize_layout; 514befb026SKay Sievers 521da177e4SLinus Torvalds struct module_attribute { 531da177e4SLinus Torvalds struct attribute attr; 544befb026SKay Sievers ssize_t (*show)(struct module_attribute *, struct module_kobject *, 554befb026SKay Sievers char *); 564befb026SKay Sievers ssize_t (*store)(struct module_attribute *, struct module_kobject *, 571da177e4SLinus Torvalds const char *, size_t count); 58c988d2b2SMatt Domsch void (*setup)(struct module *, const char *); 59c988d2b2SMatt Domsch int (*test)(struct module *); 60c988d2b2SMatt Domsch void (*free)(struct module *); 611da177e4SLinus Torvalds }; 621da177e4SLinus Torvalds 63e94965edSDmitry Torokhov struct module_version_attribute { 64e94965edSDmitry Torokhov struct module_attribute mattr; 65e94965edSDmitry Torokhov const char *module_name; 66e94965edSDmitry Torokhov const char *version; 6798562ad8SDmitry Torokhov } __attribute__ ((__aligned__(sizeof(void *)))); 68e94965edSDmitry Torokhov 699b73a584SDmitry Torokhov extern ssize_t __modver_version_show(struct module_attribute *, 704befb026SKay Sievers struct module_kobject *, char *); 719b73a584SDmitry Torokhov 7288bfa324SKay Sievers extern struct module_attribute module_uevent; 731da177e4SLinus Torvalds 741da177e4SLinus Torvalds /* These are either module local, or the kernel's dummy ones. */ 751da177e4SLinus Torvalds extern int init_module(void); 761da177e4SLinus Torvalds extern void cleanup_module(void); 771da177e4SLinus Torvalds 780fd972a7SPaul Gortmaker #ifndef MODULE 790fd972a7SPaul Gortmaker /** 800fd972a7SPaul Gortmaker * module_init() - driver initialization entry point 810fd972a7SPaul Gortmaker * @x: function to be run at kernel boot time or module insertion 820fd972a7SPaul Gortmaker * 830fd972a7SPaul Gortmaker * module_init() will either be called during do_initcalls() (if 840fd972a7SPaul Gortmaker * builtin) or at module insertion time (if a module). There can only 850fd972a7SPaul Gortmaker * be one per module. 860fd972a7SPaul Gortmaker */ 870fd972a7SPaul Gortmaker #define module_init(x) __initcall(x); 880fd972a7SPaul Gortmaker 890fd972a7SPaul Gortmaker /** 900fd972a7SPaul Gortmaker * module_exit() - driver exit entry point 910fd972a7SPaul Gortmaker * @x: function to be run when driver is removed 920fd972a7SPaul Gortmaker * 930fd972a7SPaul Gortmaker * module_exit() will wrap the driver clean-up code 940fd972a7SPaul Gortmaker * with cleanup_module() when used with rmmod when 950fd972a7SPaul Gortmaker * the driver is a module. If the driver is statically 960fd972a7SPaul Gortmaker * compiled into the kernel, module_exit() has no effect. 970fd972a7SPaul Gortmaker * There can only be one per module. 980fd972a7SPaul Gortmaker */ 990fd972a7SPaul Gortmaker #define module_exit(x) __exitcall(x); 1000fd972a7SPaul Gortmaker 1010fd972a7SPaul Gortmaker #else /* MODULE */ 1020fd972a7SPaul Gortmaker 1030fd972a7SPaul Gortmaker /* 1040fd972a7SPaul Gortmaker * In most cases loadable modules do not need custom 1050fd972a7SPaul Gortmaker * initcall levels. There are still some valid cases where 1060fd972a7SPaul Gortmaker * a driver may be needed early if built in, and does not 1070fd972a7SPaul Gortmaker * matter when built as a loadable module. Like bus 1080fd972a7SPaul Gortmaker * snooping debug drivers. 1090fd972a7SPaul Gortmaker */ 1100fd972a7SPaul Gortmaker #define early_initcall(fn) module_init(fn) 1110fd972a7SPaul Gortmaker #define core_initcall(fn) module_init(fn) 1120fd972a7SPaul Gortmaker #define core_initcall_sync(fn) module_init(fn) 1130fd972a7SPaul Gortmaker #define postcore_initcall(fn) module_init(fn) 1140fd972a7SPaul Gortmaker #define postcore_initcall_sync(fn) module_init(fn) 1150fd972a7SPaul Gortmaker #define arch_initcall(fn) module_init(fn) 1160fd972a7SPaul Gortmaker #define subsys_initcall(fn) module_init(fn) 1170fd972a7SPaul Gortmaker #define subsys_initcall_sync(fn) module_init(fn) 1180fd972a7SPaul Gortmaker #define fs_initcall(fn) module_init(fn) 1190fd972a7SPaul Gortmaker #define fs_initcall_sync(fn) module_init(fn) 1200fd972a7SPaul Gortmaker #define rootfs_initcall(fn) module_init(fn) 1210fd972a7SPaul Gortmaker #define device_initcall(fn) module_init(fn) 1220fd972a7SPaul Gortmaker #define device_initcall_sync(fn) module_init(fn) 1230fd972a7SPaul Gortmaker #define late_initcall(fn) module_init(fn) 1240fd972a7SPaul Gortmaker #define late_initcall_sync(fn) module_init(fn) 1250fd972a7SPaul Gortmaker 1260fd972a7SPaul Gortmaker #define console_initcall(fn) module_init(fn) 1270fd972a7SPaul Gortmaker 1280fd972a7SPaul Gortmaker /* Each module must use one module_init(). */ 1290fd972a7SPaul Gortmaker #define module_init(initfn) \ 1301f318a8bSArnd Bergmann static inline initcall_t __maybe_unused __inittest(void) \ 1310fd972a7SPaul Gortmaker { return initfn; } \ 1320fd972a7SPaul Gortmaker int init_module(void) __attribute__((alias(#initfn))); 1330fd972a7SPaul Gortmaker 1340fd972a7SPaul Gortmaker /* This is only required if you want to be unloadable. */ 1350fd972a7SPaul Gortmaker #define module_exit(exitfn) \ 1361f318a8bSArnd Bergmann static inline exitcall_t __maybe_unused __exittest(void) \ 1370fd972a7SPaul Gortmaker { return exitfn; } \ 1380fd972a7SPaul Gortmaker void cleanup_module(void) __attribute__((alias(#exitfn))); 1390fd972a7SPaul Gortmaker 1400fd972a7SPaul Gortmaker #endif 1410fd972a7SPaul Gortmaker 1420fd972a7SPaul Gortmaker /* This means "can be init if no module support, otherwise module load 1430fd972a7SPaul Gortmaker may call it." */ 1440fd972a7SPaul Gortmaker #ifdef CONFIG_MODULES 1450fd972a7SPaul Gortmaker #define __init_or_module 1460fd972a7SPaul Gortmaker #define __initdata_or_module 1470fd972a7SPaul Gortmaker #define __initconst_or_module 1480fd972a7SPaul Gortmaker #define __INIT_OR_MODULE .text 1490fd972a7SPaul Gortmaker #define __INITDATA_OR_MODULE .data 1500fd972a7SPaul Gortmaker #define __INITRODATA_OR_MODULE .section ".rodata","a",%progbits 1510fd972a7SPaul Gortmaker #else 1520fd972a7SPaul Gortmaker #define __init_or_module __init 1530fd972a7SPaul Gortmaker #define __initdata_or_module __initdata 1540fd972a7SPaul Gortmaker #define __initconst_or_module __initconst 1550fd972a7SPaul Gortmaker #define __INIT_OR_MODULE __INIT 1560fd972a7SPaul Gortmaker #define __INITDATA_OR_MODULE __INITDATA 1570fd972a7SPaul Gortmaker #define __INITRODATA_OR_MODULE __INITRODATA 1580fd972a7SPaul Gortmaker #endif /*CONFIG_MODULES*/ 1590fd972a7SPaul Gortmaker 1601da177e4SLinus Torvalds /* Generic info of form tag = "info" */ 1611da177e4SLinus Torvalds #define MODULE_INFO(tag, info) __MODULE_INFO(tag, tag, info) 1621da177e4SLinus Torvalds 1631da177e4SLinus Torvalds /* For userspace: you can also call me... */ 1641da177e4SLinus Torvalds #define MODULE_ALIAS(_alias) MODULE_INFO(alias, _alias) 1651da177e4SLinus Torvalds 1667cb14ba7SAndreas Robinson /* Soft module dependencies. See man modprobe.d for details. 1677cb14ba7SAndreas Robinson * Example: MODULE_SOFTDEP("pre: module-foo module-bar post: module-baz") 1687cb14ba7SAndreas Robinson */ 1697cb14ba7SAndreas Robinson #define MODULE_SOFTDEP(_softdep) MODULE_INFO(softdep, _softdep) 1707cb14ba7SAndreas Robinson 1711da177e4SLinus Torvalds /* 1721da177e4SLinus Torvalds * The following license idents are currently accepted as indicating free 1731da177e4SLinus Torvalds * software modules 1741da177e4SLinus Torvalds * 175*bf7fbeeaSThomas Gleixner * "GPL" [GNU Public License v2] 1761da177e4SLinus Torvalds * "GPL v2" [GNU Public License v2] 1771da177e4SLinus Torvalds * "GPL and additional rights" [GNU Public License v2 rights and more] 1781da177e4SLinus Torvalds * "Dual BSD/GPL" [GNU Public License v2 1791da177e4SLinus Torvalds * or BSD license choice] 1808d27e908SXose Vazquez Perez * "Dual MIT/GPL" [GNU Public License v2 1818d27e908SXose Vazquez Perez * or MIT license choice] 1821da177e4SLinus Torvalds * "Dual MPL/GPL" [GNU Public License v2 1831da177e4SLinus Torvalds * or Mozilla license choice] 1841da177e4SLinus Torvalds * 1851da177e4SLinus Torvalds * The following other idents are available 1861da177e4SLinus Torvalds * 1871da177e4SLinus Torvalds * "Proprietary" [Non free products] 1881da177e4SLinus Torvalds * 189*bf7fbeeaSThomas Gleixner * Both "GPL v2" and "GPL" (the latter also in dual licensed strings) are 190*bf7fbeeaSThomas Gleixner * merely stating that the module is licensed under the GPL v2, but are not 191*bf7fbeeaSThomas Gleixner * telling whether "GPL v2 only" or "GPL v2 or later". The reason why there 192*bf7fbeeaSThomas Gleixner * are two variants is a historic and failed attempt to convey more 193*bf7fbeeaSThomas Gleixner * information in the MODULE_LICENSE string. For module loading the 194*bf7fbeeaSThomas Gleixner * "only/or later" distinction is completely irrelevant and does neither 195*bf7fbeeaSThomas Gleixner * replace the proper license identifiers in the corresponding source file 196*bf7fbeeaSThomas Gleixner * nor amends them in any way. The sole purpose is to make the 197*bf7fbeeaSThomas Gleixner * 'Proprietary' flagging work and to refuse to bind symbols which are 198*bf7fbeeaSThomas Gleixner * exported with EXPORT_SYMBOL_GPL when a non free module is loaded. 199*bf7fbeeaSThomas Gleixner * 200*bf7fbeeaSThomas Gleixner * In the same way "BSD" is not a clear license information. It merely 201*bf7fbeeaSThomas Gleixner * states, that the module is licensed under one of the compatible BSD 202*bf7fbeeaSThomas Gleixner * license variants. The detailed and correct license information is again 203*bf7fbeeaSThomas Gleixner * to be found in the corresponding source files. 204*bf7fbeeaSThomas Gleixner * 2051da177e4SLinus Torvalds * There are dual licensed components, but when running with Linux it is the 2061da177e4SLinus Torvalds * GPL that is relevant so this is a non issue. Similarly LGPL linked with GPL 2071da177e4SLinus Torvalds * is a GPL combined work. 2081da177e4SLinus Torvalds * 2091da177e4SLinus Torvalds * This exists for several reasons 2101da177e4SLinus Torvalds * 1. So modinfo can show license info for users wanting to vet their setup 2111da177e4SLinus Torvalds * is free 2121da177e4SLinus Torvalds * 2. So the community can ignore bug reports including proprietary modules 2131da177e4SLinus Torvalds * 3. So vendors can do likewise based on their own policies 2141da177e4SLinus Torvalds */ 2151da177e4SLinus Torvalds #define MODULE_LICENSE(_license) MODULE_INFO(license, _license) 2161da177e4SLinus Torvalds 2171d7015caSJohannes Berg /* 2181d7015caSJohannes Berg * Author(s), use "Name <email>" or just "Name", for multiple 2191d7015caSJohannes Berg * authors use multiple MODULE_AUTHOR() statements/lines. 2201d7015caSJohannes Berg */ 2211da177e4SLinus Torvalds #define MODULE_AUTHOR(_author) MODULE_INFO(author, _author) 2221da177e4SLinus Torvalds 2231da177e4SLinus Torvalds /* What your module does. */ 2241da177e4SLinus Torvalds #define MODULE_DESCRIPTION(_description) MODULE_INFO(description, _description) 2251da177e4SLinus Torvalds 226cff26a51SRusty Russell #ifdef MODULE 227cff26a51SRusty Russell /* Creates an alias so file2alias.c can find device table. */ 2281da177e4SLinus Torvalds #define MODULE_DEVICE_TABLE(type, name) \ 2290bf8bf50SMatthias Kaehlcke extern typeof(name) __mod_##type##__##name##_device_table \ 230cff26a51SRusty Russell __attribute__ ((unused, alias(__stringify(name)))) 231cff26a51SRusty Russell #else /* !MODULE */ 232cff26a51SRusty Russell #define MODULE_DEVICE_TABLE(type, name) 233cff26a51SRusty Russell #endif 2341da177e4SLinus Torvalds 2351da177e4SLinus Torvalds /* Version of form [<epoch>:]<version>[-<extra-version>]. 236e865d06bSSeunghun Lee * Or for CVS/RCS ID version, everything but the number is stripped. 237e865d06bSSeunghun Lee * <epoch>: A (small) unsigned integer which allows you to start versions 238e865d06bSSeunghun Lee * anew. If not mentioned, it's zero. eg. "2:1.0" is after 239e865d06bSSeunghun Lee * "1:2.0". 2401da177e4SLinus Torvalds 241e865d06bSSeunghun Lee * <version>: The <version> may contain only alphanumerics and the 242e865d06bSSeunghun Lee * character `.'. Ordered by numeric sort for numeric parts, 243e865d06bSSeunghun Lee * ascii sort for ascii parts (as per RPM or DEB algorithm). 244e865d06bSSeunghun Lee 245e865d06bSSeunghun Lee * <extraversion>: Like <version>, but inserted for local 246e865d06bSSeunghun Lee * customizations, eg "rh3" or "rusty1". 247e865d06bSSeunghun Lee 248e865d06bSSeunghun Lee * Using this automatically adds a checksum of the .c files and the 249e865d06bSSeunghun Lee * local headers in "srcversion". 2501da177e4SLinus Torvalds */ 251e94965edSDmitry Torokhov 2523b90a5b2SRusty Russell #if defined(MODULE) || !defined(CONFIG_SYSFS) 2531da177e4SLinus Torvalds #define MODULE_VERSION(_version) MODULE_INFO(version, _version) 254e94965edSDmitry Torokhov #else 255e94965edSDmitry Torokhov #define MODULE_VERSION(_version) \ 256b4bc8428SDmitry Torokhov static struct module_version_attribute ___modver_attr = { \ 257e94965edSDmitry Torokhov .mattr = { \ 258e94965edSDmitry Torokhov .attr = { \ 259e94965edSDmitry Torokhov .name = "version", \ 260e94965edSDmitry Torokhov .mode = S_IRUGO, \ 261e94965edSDmitry Torokhov }, \ 262e94965edSDmitry Torokhov .show = __modver_version_show, \ 263e94965edSDmitry Torokhov }, \ 264e94965edSDmitry Torokhov .module_name = KBUILD_MODNAME, \ 265e94965edSDmitry Torokhov .version = _version, \ 266b4bc8428SDmitry Torokhov }; \ 267b4bc8428SDmitry Torokhov static const struct module_version_attribute \ 268b4bc8428SDmitry Torokhov __used __attribute__ ((__section__ ("__modver"))) \ 269b4bc8428SDmitry Torokhov * __moduleparam_const __modver_attr = &___modver_attr 270e94965edSDmitry Torokhov #endif 2711da177e4SLinus Torvalds 272187afbedSJon Masters /* Optional firmware file (or files) needed by the module 273187afbedSJon Masters * format is simply firmware file name. Multiple firmware 274187afbedSJon Masters * files require multiple MODULE_FIRMWARE() specifiers */ 275187afbedSJon Masters #define MODULE_FIRMWARE(_firmware) MODULE_INFO(firmware, _firmware) 276187afbedSJon Masters 2771da177e4SLinus Torvalds struct notifier_block; 2781da177e4SLinus Torvalds 2791da177e4SLinus Torvalds #ifdef CONFIG_MODULES 2801da177e4SLinus Torvalds 2815ed10910SDave Young extern int modules_disabled; /* for sysctl */ 2821da177e4SLinus Torvalds /* Get/put a kernel symbol (calls must be symmetric) */ 2831da177e4SLinus Torvalds void *__symbol_get(const char *symbol); 2841da177e4SLinus Torvalds void *__symbol_get_gpl(const char *symbol); 285996302c5SMasahiro Yamada #define symbol_get(x) ((typeof(&x))(__symbol_get(__stringify(x)))) 2861da177e4SLinus Torvalds 287c8e21cedSRusty Russell /* modules using other modules: kdb wants to see this. */ 288c8e21cedSRusty Russell struct module_use { 289c8e21cedSRusty Russell struct list_head source_list; 290c8e21cedSRusty Russell struct list_head target_list; 291c8e21cedSRusty Russell struct module *source, *target; 292c8e21cedSRusty Russell }; 293c8e21cedSRusty Russell 2940d21b0e3SRusty Russell enum module_state { 2950d21b0e3SRusty Russell MODULE_STATE_LIVE, /* Normal state. */ 2960d21b0e3SRusty Russell MODULE_STATE_COMING, /* Full formed, running module_init. */ 2970d21b0e3SRusty Russell MODULE_STATE_GOING, /* Going away. */ 2980d21b0e3SRusty Russell MODULE_STATE_UNFORMED, /* Still setting it up. */ 2991da177e4SLinus Torvalds }; 3001da177e4SLinus Torvalds 30193c2e105SPeter Zijlstra struct mod_tree_node { 30293c2e105SPeter Zijlstra struct module *mod; 30393c2e105SPeter Zijlstra struct latch_tree_node node; 30493c2e105SPeter Zijlstra }; 30593c2e105SPeter Zijlstra 3067523e4dcSRusty Russell struct module_layout { 3077523e4dcSRusty Russell /* The actual code + data. */ 3087523e4dcSRusty Russell void *base; 3097523e4dcSRusty Russell /* Total size. */ 3107523e4dcSRusty Russell unsigned int size; 3117523e4dcSRusty Russell /* The size of the executable code. */ 3127523e4dcSRusty Russell unsigned int text_size; 3137523e4dcSRusty Russell /* Size of RO section of the module (text+rodata) */ 3147523e4dcSRusty Russell unsigned int ro_size; 315444d13ffSJessica Yu /* Size of RO after init section */ 316444d13ffSJessica Yu unsigned int ro_after_init_size; 3177523e4dcSRusty Russell 3187523e4dcSRusty Russell #ifdef CONFIG_MODULES_TREE_LOOKUP 3197523e4dcSRusty Russell struct mod_tree_node mtn; 3207523e4dcSRusty Russell #endif 3217523e4dcSRusty Russell }; 3227523e4dcSRusty Russell 3237523e4dcSRusty Russell #ifdef CONFIG_MODULES_TREE_LOOKUP 3247523e4dcSRusty Russell /* Only touch one cacheline for common rbtree-for-core-layout case. */ 3257523e4dcSRusty Russell #define __module_layout_align ____cacheline_aligned 3267523e4dcSRusty Russell #else 3277523e4dcSRusty Russell #define __module_layout_align 3287523e4dcSRusty Russell #endif 3297523e4dcSRusty Russell 3308244062eSRusty Russell struct mod_kallsyms { 3318244062eSRusty Russell Elf_Sym *symtab; 3328244062eSRusty Russell unsigned int num_symtab; 3338244062eSRusty Russell char *strtab; 3348244062eSRusty Russell }; 3358244062eSRusty Russell 3361ce15ef4SJessica Yu #ifdef CONFIG_LIVEPATCH 3371ce15ef4SJessica Yu struct klp_modinfo { 3381ce15ef4SJessica Yu Elf_Ehdr hdr; 3391ce15ef4SJessica Yu Elf_Shdr *sechdrs; 3401ce15ef4SJessica Yu char *secstrings; 3411ce15ef4SJessica Yu unsigned int symndx; 3421ce15ef4SJessica Yu }; 3431ce15ef4SJessica Yu #endif 3441ce15ef4SJessica Yu 345e865d06bSSeunghun Lee struct module { 3461da177e4SLinus Torvalds enum module_state state; 3471da177e4SLinus Torvalds 3481da177e4SLinus Torvalds /* Member of list of modules */ 3491da177e4SLinus Torvalds struct list_head list; 3501da177e4SLinus Torvalds 3511da177e4SLinus Torvalds /* Unique handle for this module */ 3521da177e4SLinus Torvalds char name[MODULE_NAME_LEN]; 3531da177e4SLinus Torvalds 3541da177e4SLinus Torvalds /* Sysfs stuff. */ 3551da177e4SLinus Torvalds struct module_kobject mkobj; 35603e88ae1SGreg Kroah-Hartman struct module_attribute *modinfo_attrs; 357c988d2b2SMatt Domsch const char *version; 358c988d2b2SMatt Domsch const char *srcversion; 359270a6c4cSKay Sievers struct kobject *holders_dir; 3601da177e4SLinus Torvalds 3611da177e4SLinus Torvalds /* Exported symbols */ 3621da177e4SLinus Torvalds const struct kernel_symbol *syms; 36371810db2SArd Biesheuvel const s32 *crcs; 364af540689SRichard Kennedy unsigned int num_syms; 3651da177e4SLinus Torvalds 366e180a6b7SRusty Russell /* Kernel parameters. */ 367cf2fde7bSRusty Russell #ifdef CONFIG_SYSFS 368b51d23e4SDan Streetman struct mutex param_lock; 369cf2fde7bSRusty Russell #endif 370e180a6b7SRusty Russell struct kernel_param *kp; 371e180a6b7SRusty Russell unsigned int num_kp; 372e180a6b7SRusty Russell 3731da177e4SLinus Torvalds /* GPL-only exported symbols. */ 3741da177e4SLinus Torvalds unsigned int num_gpl_syms; 375af540689SRichard Kennedy const struct kernel_symbol *gpl_syms; 37671810db2SArd Biesheuvel const s32 *gpl_crcs; 3771da177e4SLinus Torvalds 378f7f5b675SDenys Vlasenko #ifdef CONFIG_UNUSED_SYMBOLS 379f71d20e9SArjan van de Ven /* unused exported symbols. */ 380f71d20e9SArjan van de Ven const struct kernel_symbol *unused_syms; 38171810db2SArd Biesheuvel const s32 *unused_crcs; 382af540689SRichard Kennedy unsigned int num_unused_syms; 383af540689SRichard Kennedy 384f71d20e9SArjan van de Ven /* GPL-only, unused exported symbols. */ 385f71d20e9SArjan van de Ven unsigned int num_unused_gpl_syms; 386af540689SRichard Kennedy const struct kernel_symbol *unused_gpl_syms; 38771810db2SArd Biesheuvel const s32 *unused_gpl_crcs; 388f7f5b675SDenys Vlasenko #endif 389f71d20e9SArjan van de Ven 390106a4ee2SRusty Russell #ifdef CONFIG_MODULE_SIG 391106a4ee2SRusty Russell /* Signature was verified. */ 392106a4ee2SRusty Russell bool sig_ok; 393106a4ee2SRusty Russell #endif 394106a4ee2SRusty Russell 395f2411da7SLuis R. Rodriguez bool async_probe_requested; 396f2411da7SLuis R. Rodriguez 3979f28bb7eSGreg Kroah-Hartman /* symbols that will be GPL-only in the near future. */ 3989f28bb7eSGreg Kroah-Hartman const struct kernel_symbol *gpl_future_syms; 39971810db2SArd Biesheuvel const s32 *gpl_future_crcs; 400af540689SRichard Kennedy unsigned int num_gpl_future_syms; 4019f28bb7eSGreg Kroah-Hartman 4021da177e4SLinus Torvalds /* Exception table */ 4031da177e4SLinus Torvalds unsigned int num_exentries; 4045e458cc0SRusty Russell struct exception_table_entry *extable; 4051da177e4SLinus Torvalds 4061da177e4SLinus Torvalds /* Startup function. */ 4071da177e4SLinus Torvalds int (*init)(void); 4081da177e4SLinus Torvalds 4097523e4dcSRusty Russell /* Core layout: rbtree is accessed frequently, so keep together. */ 4107523e4dcSRusty Russell struct module_layout core_layout __module_layout_align; 4117523e4dcSRusty Russell struct module_layout init_layout; 41284e1c6bbSmatthieu castet 4131da177e4SLinus Torvalds /* Arch-specific module values */ 4141da177e4SLinus Torvalds struct mod_arch_specific arch; 4151da177e4SLinus Torvalds 4167fd8329bSPetr Mladek unsigned long taints; /* same bits as kernel:taint_flags */ 4172bc2d61aSRandy Dunlap 4187664c5a1SJeremy Fitzhardinge #ifdef CONFIG_GENERIC_BUG 4197664c5a1SJeremy Fitzhardinge /* Support for BUG */ 420af540689SRichard Kennedy unsigned num_bugs; 4217664c5a1SJeremy Fitzhardinge struct list_head bug_list; 4227664c5a1SJeremy Fitzhardinge struct bug_entry *bug_table; 4231da177e4SLinus Torvalds #endif 4241da177e4SLinus Torvalds 4251da177e4SLinus Torvalds #ifdef CONFIG_KALLSYMS 4268244062eSRusty Russell /* Protected by RCU and/or module_mutex: use rcu_dereference() */ 4278244062eSRusty Russell struct mod_kallsyms *kallsyms; 4288244062eSRusty Russell struct mod_kallsyms core_kallsyms; 4291da177e4SLinus Torvalds 4301da177e4SLinus Torvalds /* Section attributes */ 4311da177e4SLinus Torvalds struct module_sect_attrs *sect_attrs; 4326d760133SRoland McGrath 4336d760133SRoland McGrath /* Notes attributes */ 4346d760133SRoland McGrath struct module_notes_attrs *notes_attrs; 4351da177e4SLinus Torvalds #endif 4361da177e4SLinus Torvalds 437a288bd65SRichard Kennedy /* The command line arguments (may be mangled). People like 438a288bd65SRichard Kennedy keeping pointers to this stuff */ 439a288bd65SRichard Kennedy char *args; 440a288bd65SRichard Kennedy 441259354deSTejun Heo #ifdef CONFIG_SMP 4421da177e4SLinus Torvalds /* Per-cpu data. */ 443259354deSTejun Heo void __percpu *percpu; 444259354deSTejun Heo unsigned int percpu_size; 445259354deSTejun Heo #endif 4461da177e4SLinus Torvalds 44797e1c18eSMathieu Desnoyers #ifdef CONFIG_TRACEPOINTS 44897e1c18eSMathieu Desnoyers unsigned int num_tracepoints; 4499c0be3f6SMathieu Desnoyers tracepoint_ptr_t *tracepoints_ptrs; 45097e1c18eSMathieu Desnoyers #endif 451a38d1107SMatt Mullins #ifdef CONFIG_BPF_EVENTS 452a38d1107SMatt Mullins unsigned int num_bpf_raw_events; 453a38d1107SMatt Mullins struct bpf_raw_event_map *bpf_raw_events; 454a38d1107SMatt Mullins #endif 455e9666d10SMasahiro Yamada #ifdef CONFIG_JUMP_LABEL 456bf5438fcSJason Baron struct jump_entry *jump_entries; 457bf5438fcSJason Baron unsigned int num_jump_entries; 458bf5438fcSJason Baron #endif 459769b0441SFrederic Weisbecker #ifdef CONFIG_TRACING 4601ba28e02SLai Jiangshan unsigned int num_trace_bprintk_fmt; 461a288bd65SRichard Kennedy const char **trace_bprintk_fmt_start; 4621ba28e02SLai Jiangshan #endif 4636d723736SSteven Rostedt #ifdef CONFIG_EVENT_TRACING 4642425bcb9SSteven Rostedt (Red Hat) struct trace_event_call **trace_events; 4656d723736SSteven Rostedt unsigned int num_trace_events; 46699be647cSJeremy Linton struct trace_eval_map **trace_evals; 46799be647cSJeremy Linton unsigned int num_trace_evals; 4686d723736SSteven Rostedt #endif 46993eb677dSSteven Rostedt #ifdef CONFIG_FTRACE_MCOUNT_RECORD 47093eb677dSSteven Rostedt unsigned int num_ftrace_callsites; 471a288bd65SRichard Kennedy unsigned long *ftrace_callsites; 47293eb677dSSteven Rostedt #endif 4731ba28e02SLai Jiangshan 4748cb2c2dcSPetr Mladek #ifdef CONFIG_LIVEPATCH 4751ce15ef4SJessica Yu bool klp; /* Is this a livepatch module? */ 4768cb2c2dcSPetr Mladek bool klp_alive; 4771ce15ef4SJessica Yu 4781ce15ef4SJessica Yu /* Elf information */ 4791ce15ef4SJessica Yu struct klp_modinfo *klp_info; 4808cb2c2dcSPetr Mladek #endif 4818cb2c2dcSPetr Mladek 482af540689SRichard Kennedy #ifdef CONFIG_MODULE_UNLOAD 483af540689SRichard Kennedy /* What modules depend on me? */ 4842c02dfe7SLinus Torvalds struct list_head source_list; 4852c02dfe7SLinus Torvalds /* What modules do I depend on? */ 4862c02dfe7SLinus Torvalds struct list_head target_list; 487af540689SRichard Kennedy 488af540689SRichard Kennedy /* Destruction function. */ 489af540689SRichard Kennedy void (*exit)(void); 490af540689SRichard Kennedy 4912f35c41fSMasami Hiramatsu atomic_t refcnt; 492af540689SRichard Kennedy #endif 493b99b87f7SPeter Oberparleiter 494b99b87f7SPeter Oberparleiter #ifdef CONFIG_CONSTRUCTORS 495b99b87f7SPeter Oberparleiter /* Constructor functions. */ 496b99b87f7SPeter Oberparleiter ctor_fn_t *ctors; 497b99b87f7SPeter Oberparleiter unsigned int num_ctors; 498b99b87f7SPeter Oberparleiter #endif 49992ace999SJosef Bacik 500540adea3SMasami Hiramatsu #ifdef CONFIG_FUNCTION_ERROR_INJECTION 501663faf9fSMasami Hiramatsu struct error_injection_entry *ei_funcs; 502540adea3SMasami Hiramatsu unsigned int num_ei_funcs; 50392ace999SJosef Bacik #endif 5043859a271SKees Cook } ____cacheline_aligned __randomize_layout; 505e61a1c1cSRoman Zippel #ifndef MODULE_ARCH_INIT 506e61a1c1cSRoman Zippel #define MODULE_ARCH_INIT {} 507e61a1c1cSRoman Zippel #endif 5081da177e4SLinus Torvalds 50993d77e7fSVincent Whitchurch #ifndef HAVE_ARCH_KALLSYMS_SYMBOL_VALUE 51093d77e7fSVincent Whitchurch static inline unsigned long kallsyms_symbol_value(const Elf_Sym *sym) 51193d77e7fSVincent Whitchurch { 51293d77e7fSVincent Whitchurch return sym->st_value; 51393d77e7fSVincent Whitchurch } 51493d77e7fSVincent Whitchurch #endif 51593d77e7fSVincent Whitchurch 516c6b37801STim Abbott extern struct mutex module_mutex; 517c6b37801STim Abbott 5181da177e4SLinus Torvalds /* FIXME: It'd be nice to isolate modules during init, too, so they 5191da177e4SLinus Torvalds aren't used before they (may) fail. But presently too much code 5201da177e4SLinus Torvalds (IDE & SCSI) require entry into the module during init.*/ 521171d864eSYaowei Bai static inline bool module_is_live(struct module *mod) 5221da177e4SLinus Torvalds { 5231da177e4SLinus Torvalds return mod->state != MODULE_STATE_GOING; 5241da177e4SLinus Torvalds } 5251da177e4SLinus Torvalds 5261da177e4SLinus Torvalds struct module *__module_text_address(unsigned long addr); 527e610499eSRusty Russell struct module *__module_address(unsigned long addr); 528e610499eSRusty Russell bool is_module_address(unsigned long addr); 529383776faSThomas Gleixner bool __is_module_percpu_address(unsigned long addr, unsigned long *can_addr); 53010fad5e4STejun Heo bool is_module_percpu_address(unsigned long addr); 531e610499eSRusty Russell bool is_module_text_address(unsigned long addr); 5321da177e4SLinus Torvalds 53376681c8fSPetr Mladek static inline bool within_module_core(unsigned long addr, 53476681c8fSPetr Mladek const struct module *mod) 535a06f6211SMasami Hiramatsu { 5367523e4dcSRusty Russell return (unsigned long)mod->core_layout.base <= addr && 5377523e4dcSRusty Russell addr < (unsigned long)mod->core_layout.base + mod->core_layout.size; 538a06f6211SMasami Hiramatsu } 539a06f6211SMasami Hiramatsu 54076681c8fSPetr Mladek static inline bool within_module_init(unsigned long addr, 54176681c8fSPetr Mladek const struct module *mod) 542a06f6211SMasami Hiramatsu { 5437523e4dcSRusty Russell return (unsigned long)mod->init_layout.base <= addr && 5447523e4dcSRusty Russell addr < (unsigned long)mod->init_layout.base + mod->init_layout.size; 545a06f6211SMasami Hiramatsu } 546a06f6211SMasami Hiramatsu 54776681c8fSPetr Mladek static inline bool within_module(unsigned long addr, const struct module *mod) 5489b20a352SPetr Mladek { 5499b20a352SPetr Mladek return within_module_init(addr, mod) || within_module_core(addr, mod); 5509b20a352SPetr Mladek } 5519b20a352SPetr Mladek 552c6b37801STim Abbott /* Search for module by name: must hold module_mutex. */ 553c6b37801STim Abbott struct module *find_module(const char *name); 554c6b37801STim Abbott 555c6b37801STim Abbott struct symsearch { 556c6b37801STim Abbott const struct kernel_symbol *start, *stop; 55771810db2SArd Biesheuvel const s32 *crcs; 558c6b37801STim Abbott enum { 559c6b37801STim Abbott NOT_GPL_ONLY, 560c6b37801STim Abbott GPL_ONLY, 561c6b37801STim Abbott WILL_BE_GPL_ONLY, 562c6b37801STim Abbott } licence; 563c6b37801STim Abbott bool unused; 564c6b37801STim Abbott }; 565c6b37801STim Abbott 5660be964beSPeter Zijlstra /* 5670be964beSPeter Zijlstra * Search for an exported symbol by name. 5680be964beSPeter Zijlstra * 5690be964beSPeter Zijlstra * Must be called with module_mutex held or preemption disabled. 5700be964beSPeter Zijlstra */ 571c6b37801STim Abbott const struct kernel_symbol *find_symbol(const char *name, 572c6b37801STim Abbott struct module **owner, 57371810db2SArd Biesheuvel const s32 **crc, 574c6b37801STim Abbott bool gplok, 575c6b37801STim Abbott bool warn); 576c6b37801STim Abbott 5770be964beSPeter Zijlstra /* 5780be964beSPeter Zijlstra * Walk the exported symbol table 5790be964beSPeter Zijlstra * 5800be964beSPeter Zijlstra * Must be called with module_mutex held or preemption disabled. 5810be964beSPeter Zijlstra */ 582de4d8d53SRusty Russell bool each_symbol_section(bool (*fn)(const struct symsearch *arr, 583de4d8d53SRusty Russell struct module *owner, 584de4d8d53SRusty Russell void *data), void *data); 585c6b37801STim Abbott 586ea07890aSAlexey Dobriyan /* Returns 0 and fills in value, defined and namebuf, or -ERANGE if 5871da177e4SLinus Torvalds symnum out of range. */ 588ea07890aSAlexey Dobriyan int module_get_kallsym(unsigned int symnum, unsigned long *value, char *type, 589ea07890aSAlexey Dobriyan char *name, char *module_name, int *exported); 5901da177e4SLinus Torvalds 5911da177e4SLinus Torvalds /* Look for this name: can be of form module:name. */ 5921da177e4SLinus Torvalds unsigned long module_kallsyms_lookup_name(const char *name); 5931da177e4SLinus Torvalds 59475a66614SAnders Kaseorg int module_kallsyms_on_each_symbol(int (*fn)(void *, const char *, 59575a66614SAnders Kaseorg struct module *, unsigned long), 59675a66614SAnders Kaseorg void *data); 59775a66614SAnders Kaseorg 598bf262dceSJiri Kosina extern void __noreturn __module_put_and_exit(struct module *mod, 599bf262dceSJiri Kosina long code); 60074e22facSJoe Perches #define module_put_and_exit(code) __module_put_and_exit(THIS_MODULE, code) 6011da177e4SLinus Torvalds 6021da177e4SLinus Torvalds #ifdef CONFIG_MODULE_UNLOAD 603d5db139aSRusty Russell int module_refcount(struct module *mod); 6041da177e4SLinus Torvalds void __symbol_put(const char *symbol); 605996302c5SMasahiro Yamada #define symbol_put(x) __symbol_put(__stringify(x)) 6061da177e4SLinus Torvalds void symbol_put_addr(void *addr); 6071da177e4SLinus Torvalds 6081da177e4SLinus Torvalds /* Sometimes we know we already have a refcount, and it's easier not 6091da177e4SLinus Torvalds to handle the error case (which only happens with rmmod --wait). */ 610d53799beSSteven Rostedt extern void __module_get(struct module *module); 6111da177e4SLinus Torvalds 612d53799beSSteven Rostedt /* This is the Right Way to get a module: if it fails, it's being removed, 613d53799beSSteven Rostedt * so pretend it's not there. */ 614d53799beSSteven Rostedt extern bool try_module_get(struct module *module); 6151da177e4SLinus Torvalds 616f6a57033SAl Viro extern void module_put(struct module *module); 6171da177e4SLinus Torvalds 6181da177e4SLinus Torvalds #else /*!CONFIG_MODULE_UNLOAD*/ 6198ba4fcdfSGao Feng static inline bool try_module_get(struct module *module) 6201da177e4SLinus Torvalds { 6211da177e4SLinus Torvalds return !module || module_is_live(module); 6221da177e4SLinus Torvalds } 6231da177e4SLinus Torvalds static inline void module_put(struct module *module) 6241da177e4SLinus Torvalds { 6251da177e4SLinus Torvalds } 6261da177e4SLinus Torvalds static inline void __module_get(struct module *module) 6271da177e4SLinus Torvalds { 6281da177e4SLinus Torvalds } 6291da177e4SLinus Torvalds #define symbol_put(x) do { } while (0) 6301da177e4SLinus Torvalds #define symbol_put_addr(p) do { } while (0) 6311da177e4SLinus Torvalds 6321da177e4SLinus Torvalds #endif /* CONFIG_MODULE_UNLOAD */ 633dfd62d1dSAnders Kaseorg int ref_module(struct module *a, struct module *b); 6341da177e4SLinus Torvalds 6351da177e4SLinus Torvalds /* This is a #define so the string doesn't get put in every .o file */ 6361da177e4SLinus Torvalds #define module_name(mod) \ 6371da177e4SLinus Torvalds ({ \ 6381da177e4SLinus Torvalds struct module *__mod = (mod); \ 6391da177e4SLinus Torvalds __mod ? __mod->name : "kernel"; \ 6401da177e4SLinus Torvalds }) 6411da177e4SLinus Torvalds 642b865ea64SSergey Senozhatsky /* Dereference module function descriptor */ 643b865ea64SSergey Senozhatsky void *dereference_module_function_descriptor(struct module *mod, void *ptr); 644b865ea64SSergey Senozhatsky 6456dd06c9fSRusty Russell /* For kallsyms to ask for address resolution. namebuf should be at 6466dd06c9fSRusty Russell * least KSYM_NAME_LEN long: a pointer to namebuf is returned if 6476dd06c9fSRusty Russell * found, otherwise NULL. */ 64892dfc9dcSAndrew Morton const char *module_address_lookup(unsigned long addr, 6491da177e4SLinus Torvalds unsigned long *symbolsize, 6501da177e4SLinus Torvalds unsigned long *offset, 6516dd06c9fSRusty Russell char **modname, 6526dd06c9fSRusty Russell char *namebuf); 6539d65cb4aSAlexey Dobriyan int lookup_module_symbol_name(unsigned long addr, char *symname); 654a5c43daeSAlexey Dobriyan int lookup_module_symbol_attrs(unsigned long addr, unsigned long *size, unsigned long *offset, char *modname, char *name); 6551da177e4SLinus Torvalds 6561da177e4SLinus Torvalds int register_module_notifier(struct notifier_block *nb); 6571da177e4SLinus Torvalds int unregister_module_notifier(struct notifier_block *nb); 6581da177e4SLinus Torvalds 6591da177e4SLinus Torvalds extern void print_modules(void); 6601da177e4SLinus Torvalds 66180c6e146SDmitry Torokhov static inline bool module_requested_async_probing(struct module *module) 66280c6e146SDmitry Torokhov { 66380c6e146SDmitry Torokhov return module && module->async_probe_requested; 66480c6e146SDmitry Torokhov } 66580c6e146SDmitry Torokhov 6661ce15ef4SJessica Yu #ifdef CONFIG_LIVEPATCH 6671ce15ef4SJessica Yu static inline bool is_livepatch_module(struct module *mod) 6681ce15ef4SJessica Yu { 6691ce15ef4SJessica Yu return mod->klp; 6701ce15ef4SJessica Yu } 6711ce15ef4SJessica Yu #else /* !CONFIG_LIVEPATCH */ 6721ce15ef4SJessica Yu static inline bool is_livepatch_module(struct module *mod) 6731ce15ef4SJessica Yu { 6741ce15ef4SJessica Yu return false; 6751ce15ef4SJessica Yu } 6761ce15ef4SJessica Yu #endif /* CONFIG_LIVEPATCH */ 6771ce15ef4SJessica Yu 678fda784e5SBruno E. O. Meneguele bool is_module_sig_enforced(void); 679fda784e5SBruno E. O. Meneguele 6801da177e4SLinus Torvalds #else /* !CONFIG_MODULES... */ 6811da177e4SLinus Torvalds 682e610499eSRusty Russell static inline struct module *__module_address(unsigned long addr) 683e610499eSRusty Russell { 684e610499eSRusty Russell return NULL; 685e610499eSRusty Russell } 686e610499eSRusty Russell 6871da177e4SLinus Torvalds static inline struct module *__module_text_address(unsigned long addr) 6881da177e4SLinus Torvalds { 6891da177e4SLinus Torvalds return NULL; 6901da177e4SLinus Torvalds } 6911da177e4SLinus Torvalds 692e610499eSRusty Russell static inline bool is_module_address(unsigned long addr) 6934d435f9dSIngo Molnar { 694e610499eSRusty Russell return false; 695e610499eSRusty Russell } 696e610499eSRusty Russell 697d5e50dafSRandy Dunlap static inline bool is_module_percpu_address(unsigned long addr) 698d5e50dafSRandy Dunlap { 699d5e50dafSRandy Dunlap return false; 700d5e50dafSRandy Dunlap } 701d5e50dafSRandy Dunlap 702383776faSThomas Gleixner static inline bool __is_module_percpu_address(unsigned long addr, unsigned long *can_addr) 703383776faSThomas Gleixner { 704383776faSThomas Gleixner return false; 705383776faSThomas Gleixner } 706383776faSThomas Gleixner 707e610499eSRusty Russell static inline bool is_module_text_address(unsigned long addr) 708e610499eSRusty Russell { 709e610499eSRusty Russell return false; 7104d435f9dSIngo Molnar } 7114d435f9dSIngo Molnar 7121da177e4SLinus Torvalds /* Get/put a kernel symbol (calls should be symmetric) */ 7131da177e4SLinus Torvalds #define symbol_get(x) ({ extern typeof(x) x __attribute__((weak)); &(x); }) 7141da177e4SLinus Torvalds #define symbol_put(x) do { } while (0) 7151da177e4SLinus Torvalds #define symbol_put_addr(x) do { } while (0) 7161da177e4SLinus Torvalds 7171da177e4SLinus Torvalds static inline void __module_get(struct module *module) 7181da177e4SLinus Torvalds { 7191da177e4SLinus Torvalds } 7201da177e4SLinus Torvalds 7218ba4fcdfSGao Feng static inline bool try_module_get(struct module *module) 7221da177e4SLinus Torvalds { 7238ba4fcdfSGao Feng return true; 7241da177e4SLinus Torvalds } 7251da177e4SLinus Torvalds 7261da177e4SLinus Torvalds static inline void module_put(struct module *module) 7271da177e4SLinus Torvalds { 7281da177e4SLinus Torvalds } 7291da177e4SLinus Torvalds 7301da177e4SLinus Torvalds #define module_name(mod) "kernel" 7311da177e4SLinus Torvalds 7321da177e4SLinus Torvalds /* For kallsyms to ask for address resolution. NULL means not found. */ 73392dfc9dcSAndrew Morton static inline const char *module_address_lookup(unsigned long addr, 7341da177e4SLinus Torvalds unsigned long *symbolsize, 7351da177e4SLinus Torvalds unsigned long *offset, 7366dd06c9fSRusty Russell char **modname, 7376dd06c9fSRusty Russell char *namebuf) 7381da177e4SLinus Torvalds { 7391da177e4SLinus Torvalds return NULL; 7401da177e4SLinus Torvalds } 7411da177e4SLinus Torvalds 7429d65cb4aSAlexey Dobriyan static inline int lookup_module_symbol_name(unsigned long addr, char *symname) 7439d65cb4aSAlexey Dobriyan { 7449d65cb4aSAlexey Dobriyan return -ERANGE; 7459d65cb4aSAlexey Dobriyan } 7469d65cb4aSAlexey Dobriyan 747a5c43daeSAlexey Dobriyan static inline int lookup_module_symbol_attrs(unsigned long addr, unsigned long *size, unsigned long *offset, char *modname, char *name) 748a5c43daeSAlexey Dobriyan { 749a5c43daeSAlexey Dobriyan return -ERANGE; 750a5c43daeSAlexey Dobriyan } 751a5c43daeSAlexey Dobriyan 752ea07890aSAlexey Dobriyan static inline int module_get_kallsym(unsigned int symnum, unsigned long *value, 753ea07890aSAlexey Dobriyan char *type, char *name, 754ea07890aSAlexey Dobriyan char *module_name, int *exported) 7551da177e4SLinus Torvalds { 756ea07890aSAlexey Dobriyan return -ERANGE; 7571da177e4SLinus Torvalds } 7581da177e4SLinus Torvalds 7591da177e4SLinus Torvalds static inline unsigned long module_kallsyms_lookup_name(const char *name) 7601da177e4SLinus Torvalds { 7611da177e4SLinus Torvalds return 0; 7621da177e4SLinus Torvalds } 7631da177e4SLinus Torvalds 76475a66614SAnders Kaseorg static inline int module_kallsyms_on_each_symbol(int (*fn)(void *, const char *, 76575a66614SAnders Kaseorg struct module *, 76675a66614SAnders Kaseorg unsigned long), 76775a66614SAnders Kaseorg void *data) 76875a66614SAnders Kaseorg { 76975a66614SAnders Kaseorg return 0; 77075a66614SAnders Kaseorg } 77175a66614SAnders Kaseorg 7721da177e4SLinus Torvalds static inline int register_module_notifier(struct notifier_block *nb) 7731da177e4SLinus Torvalds { 7741da177e4SLinus Torvalds /* no events will happen anyway, so this can always succeed */ 7751da177e4SLinus Torvalds return 0; 7761da177e4SLinus Torvalds } 7771da177e4SLinus Torvalds 7781da177e4SLinus Torvalds static inline int unregister_module_notifier(struct notifier_block *nb) 7791da177e4SLinus Torvalds { 7801da177e4SLinus Torvalds return 0; 7811da177e4SLinus Torvalds } 7821da177e4SLinus Torvalds 7831da177e4SLinus Torvalds #define module_put_and_exit(code) do_exit(code) 7841da177e4SLinus Torvalds 7851da177e4SLinus Torvalds static inline void print_modules(void) 7861da177e4SLinus Torvalds { 7871da177e4SLinus Torvalds } 78880c6e146SDmitry Torokhov 78980c6e146SDmitry Torokhov static inline bool module_requested_async_probing(struct module *module) 79080c6e146SDmitry Torokhov { 79180c6e146SDmitry Torokhov return false; 79280c6e146SDmitry Torokhov } 79380c6e146SDmitry Torokhov 794fda784e5SBruno E. O. Meneguele static inline bool is_module_sig_enforced(void) 795fda784e5SBruno E. O. Meneguele { 796fda784e5SBruno E. O. Meneguele return false; 797fda784e5SBruno E. O. Meneguele } 798fda784e5SBruno E. O. Meneguele 799b865ea64SSergey Senozhatsky /* Dereference module function descriptor */ 800b865ea64SSergey Senozhatsky static inline 801b865ea64SSergey Senozhatsky void *dereference_module_function_descriptor(struct module *mod, void *ptr) 802b865ea64SSergey Senozhatsky { 803b865ea64SSergey Senozhatsky return ptr; 804b865ea64SSergey Senozhatsky } 805b865ea64SSergey Senozhatsky 806ef665c1aSRandy Dunlap #endif /* CONFIG_MODULES */ 807ef665c1aSRandy Dunlap 808ef665c1aSRandy Dunlap #ifdef CONFIG_SYSFS 8097405c1e1SGreg Kroah-Hartman extern struct kset *module_kset; 8107405c1e1SGreg Kroah-Hartman extern struct kobj_type module_ktype; 8117405c1e1SGreg Kroah-Hartman extern int module_sysfs_initialized; 812ef665c1aSRandy Dunlap #endif /* CONFIG_SYSFS */ 813ef665c1aSRandy Dunlap 8141da177e4SLinus Torvalds #define symbol_request(x) try_then_request_module(symbol_get(x), "symbol:" #x) 8151da177e4SLinus Torvalds 8161da177e4SLinus Torvalds /* BELOW HERE ALL THESE ARE OBSOLETE AND WILL VANISH */ 8171da177e4SLinus Torvalds 8181da177e4SLinus Torvalds #define __MODULE_STRING(x) __stringify(x) 8191da177e4SLinus Torvalds 8200f5bf6d0SLaura Abbott #ifdef CONFIG_STRICT_MODULE_RWX 82184e1c6bbSmatthieu castet extern void set_all_modules_text_rw(void); 82284e1c6bbSmatthieu castet extern void set_all_modules_text_ro(void); 823444d13ffSJessica Yu extern void module_enable_ro(const struct module *mod, bool after_init); 82485c898dbSRusty Russell extern void module_disable_ro(const struct module *mod); 82584e1c6bbSmatthieu castet #else 82684e1c6bbSmatthieu castet static inline void set_all_modules_text_rw(void) { } 82784e1c6bbSmatthieu castet static inline void set_all_modules_text_ro(void) { } 828444d13ffSJessica Yu static inline void module_enable_ro(const struct module *mod, bool after_init) { } 82985c898dbSRusty Russell static inline void module_disable_ro(const struct module *mod) { } 83084e1c6bbSmatthieu castet #endif 8310d9c25ddSAndrew Morton 8320d9c25ddSAndrew Morton #ifdef CONFIG_GENERIC_BUG 8335336377dSLinus Torvalds void module_bug_finalize(const Elf_Ehdr *, const Elf_Shdr *, 8340d9c25ddSAndrew Morton struct module *); 8350d9c25ddSAndrew Morton void module_bug_cleanup(struct module *); 8360d9c25ddSAndrew Morton 8370d9c25ddSAndrew Morton #else /* !CONFIG_GENERIC_BUG */ 8380d9c25ddSAndrew Morton 8395336377dSLinus Torvalds static inline void module_bug_finalize(const Elf_Ehdr *hdr, 8400d9c25ddSAndrew Morton const Elf_Shdr *sechdrs, 8410d9c25ddSAndrew Morton struct module *mod) 8420d9c25ddSAndrew Morton { 8430d9c25ddSAndrew Morton } 8440d9c25ddSAndrew Morton static inline void module_bug_cleanup(struct module *mod) {} 8450d9c25ddSAndrew Morton #endif /* CONFIG_GENERIC_BUG */ 8460d9c25ddSAndrew Morton 847caf7501aSAndi Kleen #ifdef RETPOLINE 848caf7501aSAndi Kleen extern bool retpoline_module_ok(bool has_retpoline); 849caf7501aSAndi Kleen #else 850caf7501aSAndi Kleen static inline bool retpoline_module_ok(bool has_retpoline) 851caf7501aSAndi Kleen { 852caf7501aSAndi Kleen return true; 853caf7501aSAndi Kleen } 854caf7501aSAndi Kleen #endif 855caf7501aSAndi Kleen 85659afdc7bSHerbert Xu #ifdef CONFIG_MODULE_SIG 85759afdc7bSHerbert Xu static inline bool module_sig_ok(struct module *module) 85859afdc7bSHerbert Xu { 85959afdc7bSHerbert Xu return module->sig_ok; 86059afdc7bSHerbert Xu } 86159afdc7bSHerbert Xu #else /* !CONFIG_MODULE_SIG */ 86259afdc7bSHerbert Xu static inline bool module_sig_ok(struct module *module) 86359afdc7bSHerbert Xu { 86459afdc7bSHerbert Xu return true; 86559afdc7bSHerbert Xu } 86659afdc7bSHerbert Xu #endif /* CONFIG_MODULE_SIG */ 86759afdc7bSHerbert Xu 8681da177e4SLinus Torvalds #endif /* _LINUX_MODULE_H */ 869