1bf49d9ddSMasahiro Yamada /* SPDX-License-Identifier: GPL-2.0-only */ 21da177e4SLinus Torvalds /* 31da177e4SLinus Torvalds * Dynamic loading of modules into the kernel. 41da177e4SLinus Torvalds * 51da177e4SLinus Torvalds * Rewritten by Richard Henderson <[email protected]> Dec 1996 61da177e4SLinus Torvalds * Rewritten again by Rusty Russell, 2002 71da177e4SLinus Torvalds */ 8bf49d9ddSMasahiro Yamada 9bf49d9ddSMasahiro Yamada #ifndef _LINUX_MODULE_H 10bf49d9ddSMasahiro Yamada #define _LINUX_MODULE_H 11bf49d9ddSMasahiro Yamada 121da177e4SLinus Torvalds #include <linux/list.h> 131da177e4SLinus Torvalds #include <linux/stat.h> 141da177e4SLinus Torvalds #include <linux/compiler.h> 151da177e4SLinus Torvalds #include <linux/cache.h> 161da177e4SLinus Torvalds #include <linux/kmod.h> 170fd972a7SPaul Gortmaker #include <linux/init.h> 181da177e4SLinus Torvalds #include <linux/elf.h> 191da177e4SLinus Torvalds #include <linux/stringify.h> 201da177e4SLinus Torvalds #include <linux/kobject.h> 211da177e4SLinus Torvalds #include <linux/moduleparam.h> 22b2e285fcSSteven Rostedt (Red Hat) #include <linux/jump_label.h> 23f5016932SPaul Gortmaker #include <linux/export.h> 2493c2e105SPeter Zijlstra #include <linux/rbtree_latch.h> 25663faf9fSMasami Hiramatsu #include <linux/error-injection.h> 269c0be3f6SMathieu Desnoyers #include <linux/tracepoint-defs.h> 27fe15b50cSPaul E. McKenney #include <linux/srcu.h> 289183c3f9SJosh Poimboeuf #include <linux/static_call_types.h> 29*cf68fffbSSami Tolvanen #include <linux/cfi.h> 301da177e4SLinus Torvalds 31e1783a24SChristoph Lameter #include <linux/percpu.h> 321da177e4SLinus Torvalds #include <asm/module.h> 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; 670801a007SJohan Hovold }; 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; } \ 132*cf68fffbSSami Tolvanen int init_module(void) __copy(initfn) \ 133*cf68fffbSSami Tolvanen __attribute__((alias(#initfn))); \ 134*cf68fffbSSami Tolvanen __CFI_ADDRESSABLE(init_module, __initdata); 1350fd972a7SPaul Gortmaker 1360fd972a7SPaul Gortmaker /* This is only required if you want to be unloadable. */ 1370fd972a7SPaul Gortmaker #define module_exit(exitfn) \ 1381f318a8bSArnd Bergmann static inline exitcall_t __maybe_unused __exittest(void) \ 1390fd972a7SPaul Gortmaker { return exitfn; } \ 140*cf68fffbSSami Tolvanen void cleanup_module(void) __copy(exitfn) \ 141*cf68fffbSSami Tolvanen __attribute__((alias(#exitfn))); \ 142*cf68fffbSSami Tolvanen __CFI_ADDRESSABLE(cleanup_module, __exitdata); 1430fd972a7SPaul Gortmaker 1440fd972a7SPaul Gortmaker #endif 1450fd972a7SPaul Gortmaker 1460fd972a7SPaul Gortmaker /* This means "can be init if no module support, otherwise module load 1470fd972a7SPaul Gortmaker may call it." */ 1480fd972a7SPaul Gortmaker #ifdef CONFIG_MODULES 1490fd972a7SPaul Gortmaker #define __init_or_module 1500fd972a7SPaul Gortmaker #define __initdata_or_module 1510fd972a7SPaul Gortmaker #define __initconst_or_module 1520fd972a7SPaul Gortmaker #define __INIT_OR_MODULE .text 1530fd972a7SPaul Gortmaker #define __INITDATA_OR_MODULE .data 1540fd972a7SPaul Gortmaker #define __INITRODATA_OR_MODULE .section ".rodata","a",%progbits 1550fd972a7SPaul Gortmaker #else 1560fd972a7SPaul Gortmaker #define __init_or_module __init 1570fd972a7SPaul Gortmaker #define __initdata_or_module __initdata 1580fd972a7SPaul Gortmaker #define __initconst_or_module __initconst 1590fd972a7SPaul Gortmaker #define __INIT_OR_MODULE __INIT 1600fd972a7SPaul Gortmaker #define __INITDATA_OR_MODULE __INITDATA 1610fd972a7SPaul Gortmaker #define __INITRODATA_OR_MODULE __INITRODATA 1620fd972a7SPaul Gortmaker #endif /*CONFIG_MODULES*/ 1630fd972a7SPaul Gortmaker 1641da177e4SLinus Torvalds /* Generic info of form tag = "info" */ 1651da177e4SLinus Torvalds #define MODULE_INFO(tag, info) __MODULE_INFO(tag, tag, info) 1661da177e4SLinus Torvalds 1671da177e4SLinus Torvalds /* For userspace: you can also call me... */ 1681da177e4SLinus Torvalds #define MODULE_ALIAS(_alias) MODULE_INFO(alias, _alias) 1691da177e4SLinus Torvalds 1707cb14ba7SAndreas Robinson /* Soft module dependencies. See man modprobe.d for details. 1717cb14ba7SAndreas Robinson * Example: MODULE_SOFTDEP("pre: module-foo module-bar post: module-baz") 1727cb14ba7SAndreas Robinson */ 1737cb14ba7SAndreas Robinson #define MODULE_SOFTDEP(_softdep) MODULE_INFO(softdep, _softdep) 1747cb14ba7SAndreas Robinson 1751da177e4SLinus Torvalds /* 1768b41fc44SMasahiro Yamada * MODULE_FILE is used for generating modules.builtin 1778b41fc44SMasahiro Yamada * So, make it no-op when this is being built as a module 1788b41fc44SMasahiro Yamada */ 1798b41fc44SMasahiro Yamada #ifdef MODULE 1808b41fc44SMasahiro Yamada #define MODULE_FILE 1818b41fc44SMasahiro Yamada #else 1828b41fc44SMasahiro Yamada #define MODULE_FILE MODULE_INFO(file, KBUILD_MODFILE); 1838b41fc44SMasahiro Yamada #endif 1848b41fc44SMasahiro Yamada 1858b41fc44SMasahiro Yamada /* 1861da177e4SLinus Torvalds * The following license idents are currently accepted as indicating free 1871da177e4SLinus Torvalds * software modules 1881da177e4SLinus Torvalds * 189bf7fbeeaSThomas Gleixner * "GPL" [GNU Public License v2] 1901da177e4SLinus Torvalds * "GPL v2" [GNU Public License v2] 1911da177e4SLinus Torvalds * "GPL and additional rights" [GNU Public License v2 rights and more] 1921da177e4SLinus Torvalds * "Dual BSD/GPL" [GNU Public License v2 1931da177e4SLinus Torvalds * or BSD license choice] 1948d27e908SXose Vazquez Perez * "Dual MIT/GPL" [GNU Public License v2 1958d27e908SXose Vazquez Perez * or MIT license choice] 1961da177e4SLinus Torvalds * "Dual MPL/GPL" [GNU Public License v2 1971da177e4SLinus Torvalds * or Mozilla license choice] 1981da177e4SLinus Torvalds * 1991da177e4SLinus Torvalds * The following other idents are available 2001da177e4SLinus Torvalds * 2011da177e4SLinus Torvalds * "Proprietary" [Non free products] 2021da177e4SLinus Torvalds * 203bf7fbeeaSThomas Gleixner * Both "GPL v2" and "GPL" (the latter also in dual licensed strings) are 204bf7fbeeaSThomas Gleixner * merely stating that the module is licensed under the GPL v2, but are not 205bf7fbeeaSThomas Gleixner * telling whether "GPL v2 only" or "GPL v2 or later". The reason why there 206bf7fbeeaSThomas Gleixner * are two variants is a historic and failed attempt to convey more 207bf7fbeeaSThomas Gleixner * information in the MODULE_LICENSE string. For module loading the 208bf7fbeeaSThomas Gleixner * "only/or later" distinction is completely irrelevant and does neither 209bf7fbeeaSThomas Gleixner * replace the proper license identifiers in the corresponding source file 210bf7fbeeaSThomas Gleixner * nor amends them in any way. The sole purpose is to make the 211bf7fbeeaSThomas Gleixner * 'Proprietary' flagging work and to refuse to bind symbols which are 212bf7fbeeaSThomas Gleixner * exported with EXPORT_SYMBOL_GPL when a non free module is loaded. 213bf7fbeeaSThomas Gleixner * 214bf7fbeeaSThomas Gleixner * In the same way "BSD" is not a clear license information. It merely 215bf7fbeeaSThomas Gleixner * states, that the module is licensed under one of the compatible BSD 216bf7fbeeaSThomas Gleixner * license variants. The detailed and correct license information is again 217bf7fbeeaSThomas Gleixner * to be found in the corresponding source files. 218bf7fbeeaSThomas Gleixner * 2191da177e4SLinus Torvalds * There are dual licensed components, but when running with Linux it is the 2201da177e4SLinus Torvalds * GPL that is relevant so this is a non issue. Similarly LGPL linked with GPL 2211da177e4SLinus Torvalds * is a GPL combined work. 2221da177e4SLinus Torvalds * 2231da177e4SLinus Torvalds * This exists for several reasons 2241da177e4SLinus Torvalds * 1. So modinfo can show license info for users wanting to vet their setup 2251da177e4SLinus Torvalds * is free 2261da177e4SLinus Torvalds * 2. So the community can ignore bug reports including proprietary modules 2271da177e4SLinus Torvalds * 3. So vendors can do likewise based on their own policies 2281da177e4SLinus Torvalds */ 2298b41fc44SMasahiro Yamada #define MODULE_LICENSE(_license) MODULE_FILE MODULE_INFO(license, _license) 2301da177e4SLinus Torvalds 2311d7015caSJohannes Berg /* 2321d7015caSJohannes Berg * Author(s), use "Name <email>" or just "Name", for multiple 2331d7015caSJohannes Berg * authors use multiple MODULE_AUTHOR() statements/lines. 2341d7015caSJohannes Berg */ 2351da177e4SLinus Torvalds #define MODULE_AUTHOR(_author) MODULE_INFO(author, _author) 2361da177e4SLinus Torvalds 2371da177e4SLinus Torvalds /* What your module does. */ 2381da177e4SLinus Torvalds #define MODULE_DESCRIPTION(_description) MODULE_INFO(description, _description) 2391da177e4SLinus Torvalds 240cff26a51SRusty Russell #ifdef MODULE 241cff26a51SRusty Russell /* Creates an alias so file2alias.c can find device table. */ 2421da177e4SLinus Torvalds #define MODULE_DEVICE_TABLE(type, name) \ 2430bf8bf50SMatthias Kaehlcke extern typeof(name) __mod_##type##__##name##_device_table \ 244cff26a51SRusty Russell __attribute__ ((unused, alias(__stringify(name)))) 245cff26a51SRusty Russell #else /* !MODULE */ 246cff26a51SRusty Russell #define MODULE_DEVICE_TABLE(type, name) 247cff26a51SRusty Russell #endif 2481da177e4SLinus Torvalds 2491da177e4SLinus Torvalds /* Version of form [<epoch>:]<version>[-<extra-version>]. 250e865d06bSSeunghun Lee * Or for CVS/RCS ID version, everything but the number is stripped. 251e865d06bSSeunghun Lee * <epoch>: A (small) unsigned integer which allows you to start versions 252e865d06bSSeunghun Lee * anew. If not mentioned, it's zero. eg. "2:1.0" is after 253e865d06bSSeunghun Lee * "1:2.0". 2541da177e4SLinus Torvalds 255e865d06bSSeunghun Lee * <version>: The <version> may contain only alphanumerics and the 256e865d06bSSeunghun Lee * character `.'. Ordered by numeric sort for numeric parts, 257e865d06bSSeunghun Lee * ascii sort for ascii parts (as per RPM or DEB algorithm). 258e865d06bSSeunghun Lee 259e865d06bSSeunghun Lee * <extraversion>: Like <version>, but inserted for local 260e865d06bSSeunghun Lee * customizations, eg "rh3" or "rusty1". 261e865d06bSSeunghun Lee 262e865d06bSSeunghun Lee * Using this automatically adds a checksum of the .c files and the 263e865d06bSSeunghun Lee * local headers in "srcversion". 2641da177e4SLinus Torvalds */ 265e94965edSDmitry Torokhov 2663b90a5b2SRusty Russell #if defined(MODULE) || !defined(CONFIG_SYSFS) 2671da177e4SLinus Torvalds #define MODULE_VERSION(_version) MODULE_INFO(version, _version) 268e94965edSDmitry Torokhov #else 269e94965edSDmitry Torokhov #define MODULE_VERSION(_version) \ 270898490c0SAlexey Gladkov MODULE_INFO(version, _version); \ 271b112082cSJohan Hovold static struct module_version_attribute __modver_attr \ 272b112082cSJohan Hovold __used __section("__modver") \ 273b112082cSJohan Hovold __aligned(__alignof__(struct module_version_attribute)) \ 274b112082cSJohan Hovold = { \ 275e94965edSDmitry Torokhov .mattr = { \ 276e94965edSDmitry Torokhov .attr = { \ 277e94965edSDmitry Torokhov .name = "version", \ 278e94965edSDmitry Torokhov .mode = S_IRUGO, \ 279e94965edSDmitry Torokhov }, \ 280e94965edSDmitry Torokhov .show = __modver_version_show, \ 281e94965edSDmitry Torokhov }, \ 282e94965edSDmitry Torokhov .module_name = KBUILD_MODNAME, \ 283e94965edSDmitry Torokhov .version = _version, \ 2842d26c716SJohan Hovold } 285e94965edSDmitry Torokhov #endif 2861da177e4SLinus Torvalds 287187afbedSJon Masters /* Optional firmware file (or files) needed by the module 288187afbedSJon Masters * format is simply firmware file name. Multiple firmware 289187afbedSJon Masters * files require multiple MODULE_FIRMWARE() specifiers */ 290187afbedSJon Masters #define MODULE_FIRMWARE(_firmware) MODULE_INFO(firmware, _firmware) 291187afbedSJon Masters 2923e4d890aSLinus Torvalds #define MODULE_IMPORT_NS(ns) MODULE_INFO(import_ns, #ns) 2933e4d890aSLinus Torvalds 2941da177e4SLinus Torvalds struct notifier_block; 2951da177e4SLinus Torvalds 2961da177e4SLinus Torvalds #ifdef CONFIG_MODULES 2971da177e4SLinus Torvalds 2985ed10910SDave Young extern int modules_disabled; /* for sysctl */ 2991da177e4SLinus Torvalds /* Get/put a kernel symbol (calls must be symmetric) */ 3001da177e4SLinus Torvalds void *__symbol_get(const char *symbol); 3011da177e4SLinus Torvalds void *__symbol_get_gpl(const char *symbol); 302996302c5SMasahiro Yamada #define symbol_get(x) ((typeof(&x))(__symbol_get(__stringify(x)))) 3031da177e4SLinus Torvalds 304c8e21cedSRusty Russell /* modules using other modules: kdb wants to see this. */ 305c8e21cedSRusty Russell struct module_use { 306c8e21cedSRusty Russell struct list_head source_list; 307c8e21cedSRusty Russell struct list_head target_list; 308c8e21cedSRusty Russell struct module *source, *target; 309c8e21cedSRusty Russell }; 310c8e21cedSRusty Russell 3110d21b0e3SRusty Russell enum module_state { 3120d21b0e3SRusty Russell MODULE_STATE_LIVE, /* Normal state. */ 3130d21b0e3SRusty Russell MODULE_STATE_COMING, /* Full formed, running module_init. */ 3140d21b0e3SRusty Russell MODULE_STATE_GOING, /* Going away. */ 3150d21b0e3SRusty Russell MODULE_STATE_UNFORMED, /* Still setting it up. */ 3161da177e4SLinus Torvalds }; 3171da177e4SLinus Torvalds 31893c2e105SPeter Zijlstra struct mod_tree_node { 31993c2e105SPeter Zijlstra struct module *mod; 32093c2e105SPeter Zijlstra struct latch_tree_node node; 32193c2e105SPeter Zijlstra }; 32293c2e105SPeter Zijlstra 3237523e4dcSRusty Russell struct module_layout { 3247523e4dcSRusty Russell /* The actual code + data. */ 3257523e4dcSRusty Russell void *base; 3267523e4dcSRusty Russell /* Total size. */ 3277523e4dcSRusty Russell unsigned int size; 3287523e4dcSRusty Russell /* The size of the executable code. */ 3297523e4dcSRusty Russell unsigned int text_size; 3307523e4dcSRusty Russell /* Size of RO section of the module (text+rodata) */ 3317523e4dcSRusty Russell unsigned int ro_size; 332444d13ffSJessica Yu /* Size of RO after init section */ 333444d13ffSJessica Yu unsigned int ro_after_init_size; 3347523e4dcSRusty Russell 3357523e4dcSRusty Russell #ifdef CONFIG_MODULES_TREE_LOOKUP 3367523e4dcSRusty Russell struct mod_tree_node mtn; 3377523e4dcSRusty Russell #endif 3387523e4dcSRusty Russell }; 3397523e4dcSRusty Russell 3407523e4dcSRusty Russell #ifdef CONFIG_MODULES_TREE_LOOKUP 3417523e4dcSRusty Russell /* Only touch one cacheline for common rbtree-for-core-layout case. */ 3427523e4dcSRusty Russell #define __module_layout_align ____cacheline_aligned 3437523e4dcSRusty Russell #else 3447523e4dcSRusty Russell #define __module_layout_align 3457523e4dcSRusty Russell #endif 3467523e4dcSRusty Russell 3478244062eSRusty Russell struct mod_kallsyms { 3488244062eSRusty Russell Elf_Sym *symtab; 3498244062eSRusty Russell unsigned int num_symtab; 3508244062eSRusty Russell char *strtab; 3511c7651f4SEugene Loh char *typetab; 3528244062eSRusty Russell }; 3538244062eSRusty Russell 3541ce15ef4SJessica Yu #ifdef CONFIG_LIVEPATCH 3551ce15ef4SJessica Yu struct klp_modinfo { 3561ce15ef4SJessica Yu Elf_Ehdr hdr; 3571ce15ef4SJessica Yu Elf_Shdr *sechdrs; 3581ce15ef4SJessica Yu char *secstrings; 3591ce15ef4SJessica Yu unsigned int symndx; 3601ce15ef4SJessica Yu }; 3611ce15ef4SJessica Yu #endif 3621ce15ef4SJessica Yu 363e865d06bSSeunghun Lee struct module { 3641da177e4SLinus Torvalds enum module_state state; 3651da177e4SLinus Torvalds 3661da177e4SLinus Torvalds /* Member of list of modules */ 3671da177e4SLinus Torvalds struct list_head list; 3681da177e4SLinus Torvalds 3691da177e4SLinus Torvalds /* Unique handle for this module */ 3701da177e4SLinus Torvalds char name[MODULE_NAME_LEN]; 3711da177e4SLinus Torvalds 3721da177e4SLinus Torvalds /* Sysfs stuff. */ 3731da177e4SLinus Torvalds struct module_kobject mkobj; 37403e88ae1SGreg Kroah-Hartman struct module_attribute *modinfo_attrs; 375c988d2b2SMatt Domsch const char *version; 376c988d2b2SMatt Domsch const char *srcversion; 377270a6c4cSKay Sievers struct kobject *holders_dir; 3781da177e4SLinus Torvalds 3791da177e4SLinus Torvalds /* Exported symbols */ 3801da177e4SLinus Torvalds const struct kernel_symbol *syms; 38171810db2SArd Biesheuvel const s32 *crcs; 382af540689SRichard Kennedy unsigned int num_syms; 3831da177e4SLinus Torvalds 384*cf68fffbSSami Tolvanen #ifdef CONFIG_CFI_CLANG 385*cf68fffbSSami Tolvanen cfi_check_fn cfi_check; 386*cf68fffbSSami Tolvanen #endif 387*cf68fffbSSami Tolvanen 388e180a6b7SRusty Russell /* Kernel parameters. */ 389cf2fde7bSRusty Russell #ifdef CONFIG_SYSFS 390b51d23e4SDan Streetman struct mutex param_lock; 391cf2fde7bSRusty Russell #endif 392e180a6b7SRusty Russell struct kernel_param *kp; 393e180a6b7SRusty Russell unsigned int num_kp; 394e180a6b7SRusty Russell 3951da177e4SLinus Torvalds /* GPL-only exported symbols. */ 3961da177e4SLinus Torvalds unsigned int num_gpl_syms; 397af540689SRichard Kennedy const struct kernel_symbol *gpl_syms; 39871810db2SArd Biesheuvel const s32 *gpl_crcs; 399262e6ae7SChristoph Hellwig bool using_gplonly_symbols; 4001da177e4SLinus Torvalds 401106a4ee2SRusty Russell #ifdef CONFIG_MODULE_SIG 402106a4ee2SRusty Russell /* Signature was verified. */ 403106a4ee2SRusty Russell bool sig_ok; 404106a4ee2SRusty Russell #endif 405106a4ee2SRusty Russell 406f2411da7SLuis R. Rodriguez bool async_probe_requested; 407f2411da7SLuis R. Rodriguez 4081da177e4SLinus Torvalds /* Exception table */ 4091da177e4SLinus Torvalds unsigned int num_exentries; 4105e458cc0SRusty Russell struct exception_table_entry *extable; 4111da177e4SLinus Torvalds 4121da177e4SLinus Torvalds /* Startup function. */ 4131da177e4SLinus Torvalds int (*init)(void); 4141da177e4SLinus Torvalds 4157523e4dcSRusty Russell /* Core layout: rbtree is accessed frequently, so keep together. */ 4167523e4dcSRusty Russell struct module_layout core_layout __module_layout_align; 4177523e4dcSRusty Russell struct module_layout init_layout; 41884e1c6bbSmatthieu castet 4191da177e4SLinus Torvalds /* Arch-specific module values */ 4201da177e4SLinus Torvalds struct mod_arch_specific arch; 4211da177e4SLinus Torvalds 4227fd8329bSPetr Mladek unsigned long taints; /* same bits as kernel:taint_flags */ 4232bc2d61aSRandy Dunlap 4247664c5a1SJeremy Fitzhardinge #ifdef CONFIG_GENERIC_BUG 4257664c5a1SJeremy Fitzhardinge /* Support for BUG */ 426af540689SRichard Kennedy unsigned num_bugs; 4277664c5a1SJeremy Fitzhardinge struct list_head bug_list; 4287664c5a1SJeremy Fitzhardinge struct bug_entry *bug_table; 4291da177e4SLinus Torvalds #endif 4301da177e4SLinus Torvalds 4311da177e4SLinus Torvalds #ifdef CONFIG_KALLSYMS 4328244062eSRusty Russell /* Protected by RCU and/or module_mutex: use rcu_dereference() */ 4336080d608SMadhuparna Bhowmik struct mod_kallsyms __rcu *kallsyms; 4348244062eSRusty Russell struct mod_kallsyms core_kallsyms; 4351da177e4SLinus Torvalds 4361da177e4SLinus Torvalds /* Section attributes */ 4371da177e4SLinus Torvalds struct module_sect_attrs *sect_attrs; 4386d760133SRoland McGrath 4396d760133SRoland McGrath /* Notes attributes */ 4406d760133SRoland McGrath struct module_notes_attrs *notes_attrs; 4411da177e4SLinus Torvalds #endif 4421da177e4SLinus Torvalds 443a288bd65SRichard Kennedy /* The command line arguments (may be mangled). People like 444a288bd65SRichard Kennedy keeping pointers to this stuff */ 445a288bd65SRichard Kennedy char *args; 446a288bd65SRichard Kennedy 447259354deSTejun Heo #ifdef CONFIG_SMP 4481da177e4SLinus Torvalds /* Per-cpu data. */ 449259354deSTejun Heo void __percpu *percpu; 450259354deSTejun Heo unsigned int percpu_size; 451259354deSTejun Heo #endif 45266e9b071SThomas Gleixner void *noinstr_text_start; 45366e9b071SThomas Gleixner unsigned int noinstr_text_size; 4541da177e4SLinus Torvalds 45597e1c18eSMathieu Desnoyers #ifdef CONFIG_TRACEPOINTS 45697e1c18eSMathieu Desnoyers unsigned int num_tracepoints; 4579c0be3f6SMathieu Desnoyers tracepoint_ptr_t *tracepoints_ptrs; 45897e1c18eSMathieu Desnoyers #endif 459fe15b50cSPaul E. McKenney #ifdef CONFIG_TREE_SRCU 460fe15b50cSPaul E. McKenney unsigned int num_srcu_structs; 461fe15b50cSPaul E. McKenney struct srcu_struct **srcu_struct_ptrs; 462fe15b50cSPaul E. McKenney #endif 463a38d1107SMatt Mullins #ifdef CONFIG_BPF_EVENTS 464a38d1107SMatt Mullins unsigned int num_bpf_raw_events; 465a38d1107SMatt Mullins struct bpf_raw_event_map *bpf_raw_events; 466a38d1107SMatt Mullins #endif 46736e68442SAndrii Nakryiko #ifdef CONFIG_DEBUG_INFO_BTF_MODULES 46836e68442SAndrii Nakryiko unsigned int btf_data_size; 46936e68442SAndrii Nakryiko void *btf_data; 47036e68442SAndrii Nakryiko #endif 471e9666d10SMasahiro Yamada #ifdef CONFIG_JUMP_LABEL 472bf5438fcSJason Baron struct jump_entry *jump_entries; 473bf5438fcSJason Baron unsigned int num_jump_entries; 474bf5438fcSJason Baron #endif 475769b0441SFrederic Weisbecker #ifdef CONFIG_TRACING 4761ba28e02SLai Jiangshan unsigned int num_trace_bprintk_fmt; 477a288bd65SRichard Kennedy const char **trace_bprintk_fmt_start; 4781ba28e02SLai Jiangshan #endif 4796d723736SSteven Rostedt #ifdef CONFIG_EVENT_TRACING 4802425bcb9SSteven Rostedt (Red Hat) struct trace_event_call **trace_events; 4816d723736SSteven Rostedt unsigned int num_trace_events; 48299be647cSJeremy Linton struct trace_eval_map **trace_evals; 48399be647cSJeremy Linton unsigned int num_trace_evals; 4846d723736SSteven Rostedt #endif 48593eb677dSSteven Rostedt #ifdef CONFIG_FTRACE_MCOUNT_RECORD 48693eb677dSSteven Rostedt unsigned int num_ftrace_callsites; 487a288bd65SRichard Kennedy unsigned long *ftrace_callsites; 48893eb677dSSteven Rostedt #endif 4891e6769b0SMasami Hiramatsu #ifdef CONFIG_KPROBES 4901e6769b0SMasami Hiramatsu void *kprobes_text_start; 4911e6769b0SMasami Hiramatsu unsigned int kprobes_text_size; 49216db6264SMasami Hiramatsu unsigned long *kprobe_blacklist; 49316db6264SMasami Hiramatsu unsigned int num_kprobe_blacklist; 4941e6769b0SMasami Hiramatsu #endif 4959183c3f9SJosh Poimboeuf #ifdef CONFIG_HAVE_STATIC_CALL_INLINE 4969183c3f9SJosh Poimboeuf int num_static_call_sites; 4979183c3f9SJosh Poimboeuf struct static_call_site *static_call_sites; 4989183c3f9SJosh Poimboeuf #endif 4991ba28e02SLai Jiangshan 5008cb2c2dcSPetr Mladek #ifdef CONFIG_LIVEPATCH 5011ce15ef4SJessica Yu bool klp; /* Is this a livepatch module? */ 5028cb2c2dcSPetr Mladek bool klp_alive; 5031ce15ef4SJessica Yu 5041ce15ef4SJessica Yu /* Elf information */ 5051ce15ef4SJessica Yu struct klp_modinfo *klp_info; 5068cb2c2dcSPetr Mladek #endif 5078cb2c2dcSPetr Mladek 508af540689SRichard Kennedy #ifdef CONFIG_MODULE_UNLOAD 509af540689SRichard Kennedy /* What modules depend on me? */ 5102c02dfe7SLinus Torvalds struct list_head source_list; 5112c02dfe7SLinus Torvalds /* What modules do I depend on? */ 5122c02dfe7SLinus Torvalds struct list_head target_list; 513af540689SRichard Kennedy 514af540689SRichard Kennedy /* Destruction function. */ 515af540689SRichard Kennedy void (*exit)(void); 516af540689SRichard Kennedy 5172f35c41fSMasami Hiramatsu atomic_t refcnt; 518af540689SRichard Kennedy #endif 519b99b87f7SPeter Oberparleiter 520b99b87f7SPeter Oberparleiter #ifdef CONFIG_CONSTRUCTORS 521b99b87f7SPeter Oberparleiter /* Constructor functions. */ 522b99b87f7SPeter Oberparleiter ctor_fn_t *ctors; 523b99b87f7SPeter Oberparleiter unsigned int num_ctors; 524b99b87f7SPeter Oberparleiter #endif 52592ace999SJosef Bacik 526540adea3SMasami Hiramatsu #ifdef CONFIG_FUNCTION_ERROR_INJECTION 527663faf9fSMasami Hiramatsu struct error_injection_entry *ei_funcs; 528540adea3SMasami Hiramatsu unsigned int num_ei_funcs; 52992ace999SJosef Bacik #endif 5303859a271SKees Cook } ____cacheline_aligned __randomize_layout; 531e61a1c1cSRoman Zippel #ifndef MODULE_ARCH_INIT 532e61a1c1cSRoman Zippel #define MODULE_ARCH_INIT {} 533e61a1c1cSRoman Zippel #endif 5341da177e4SLinus Torvalds 53593d77e7fSVincent Whitchurch #ifndef HAVE_ARCH_KALLSYMS_SYMBOL_VALUE 53693d77e7fSVincent Whitchurch static inline unsigned long kallsyms_symbol_value(const Elf_Sym *sym) 53793d77e7fSVincent Whitchurch { 53893d77e7fSVincent Whitchurch return sym->st_value; 53993d77e7fSVincent Whitchurch } 54093d77e7fSVincent Whitchurch #endif 54193d77e7fSVincent Whitchurch 5421da177e4SLinus Torvalds /* FIXME: It'd be nice to isolate modules during init, too, so they 5431da177e4SLinus Torvalds aren't used before they (may) fail. But presently too much code 5441da177e4SLinus Torvalds (IDE & SCSI) require entry into the module during init.*/ 545171d864eSYaowei Bai static inline bool module_is_live(struct module *mod) 5461da177e4SLinus Torvalds { 5471da177e4SLinus Torvalds return mod->state != MODULE_STATE_GOING; 5481da177e4SLinus Torvalds } 5491da177e4SLinus Torvalds 5501da177e4SLinus Torvalds struct module *__module_text_address(unsigned long addr); 551e610499eSRusty Russell struct module *__module_address(unsigned long addr); 552e610499eSRusty Russell bool is_module_address(unsigned long addr); 553383776faSThomas Gleixner bool __is_module_percpu_address(unsigned long addr, unsigned long *can_addr); 55410fad5e4STejun Heo bool is_module_percpu_address(unsigned long addr); 555e610499eSRusty Russell bool is_module_text_address(unsigned long addr); 5561da177e4SLinus Torvalds 55776681c8fSPetr Mladek static inline bool within_module_core(unsigned long addr, 55876681c8fSPetr Mladek const struct module *mod) 559a06f6211SMasami Hiramatsu { 5607523e4dcSRusty Russell return (unsigned long)mod->core_layout.base <= addr && 5617523e4dcSRusty Russell addr < (unsigned long)mod->core_layout.base + mod->core_layout.size; 562a06f6211SMasami Hiramatsu } 563a06f6211SMasami Hiramatsu 56476681c8fSPetr Mladek static inline bool within_module_init(unsigned long addr, 56576681c8fSPetr Mladek const struct module *mod) 566a06f6211SMasami Hiramatsu { 5677523e4dcSRusty Russell return (unsigned long)mod->init_layout.base <= addr && 5687523e4dcSRusty Russell addr < (unsigned long)mod->init_layout.base + mod->init_layout.size; 569a06f6211SMasami Hiramatsu } 570a06f6211SMasami Hiramatsu 57176681c8fSPetr Mladek static inline bool within_module(unsigned long addr, const struct module *mod) 5729b20a352SPetr Mladek { 5739b20a352SPetr Mladek return within_module_init(addr, mod) || within_module_core(addr, mod); 5749b20a352SPetr Mladek } 5759b20a352SPetr Mladek 576a0060505SChristoph Hellwig /* Search for module by name: must be in a RCU-sched critical section. */ 577c6b37801STim Abbott struct module *find_module(const char *name); 578c6b37801STim Abbott 579ea07890aSAlexey Dobriyan /* Returns 0 and fills in value, defined and namebuf, or -ERANGE if 5801da177e4SLinus Torvalds symnum out of range. */ 581ea07890aSAlexey Dobriyan int module_get_kallsym(unsigned int symnum, unsigned long *value, char *type, 582ea07890aSAlexey Dobriyan char *name, char *module_name, int *exported); 5831da177e4SLinus Torvalds 5841da177e4SLinus Torvalds /* Look for this name: can be of form module:name. */ 5851da177e4SLinus Torvalds unsigned long module_kallsyms_lookup_name(const char *name); 5861da177e4SLinus Torvalds 587bf262dceSJiri Kosina extern void __noreturn __module_put_and_exit(struct module *mod, 588bf262dceSJiri Kosina long code); 58974e22facSJoe Perches #define module_put_and_exit(code) __module_put_and_exit(THIS_MODULE, code) 5901da177e4SLinus Torvalds 5911da177e4SLinus Torvalds #ifdef CONFIG_MODULE_UNLOAD 592d5db139aSRusty Russell int module_refcount(struct module *mod); 5931da177e4SLinus Torvalds void __symbol_put(const char *symbol); 594996302c5SMasahiro Yamada #define symbol_put(x) __symbol_put(__stringify(x)) 5951da177e4SLinus Torvalds void symbol_put_addr(void *addr); 5961da177e4SLinus Torvalds 5971da177e4SLinus Torvalds /* Sometimes we know we already have a refcount, and it's easier not 5981da177e4SLinus Torvalds to handle the error case (which only happens with rmmod --wait). */ 599d53799beSSteven Rostedt extern void __module_get(struct module *module); 6001da177e4SLinus Torvalds 601d53799beSSteven Rostedt /* This is the Right Way to get a module: if it fails, it's being removed, 602d53799beSSteven Rostedt * so pretend it's not there. */ 603d53799beSSteven Rostedt extern bool try_module_get(struct module *module); 6041da177e4SLinus Torvalds 605f6a57033SAl Viro extern void module_put(struct module *module); 6061da177e4SLinus Torvalds 6071da177e4SLinus Torvalds #else /*!CONFIG_MODULE_UNLOAD*/ 6088ba4fcdfSGao Feng static inline bool try_module_get(struct module *module) 6091da177e4SLinus Torvalds { 6101da177e4SLinus Torvalds return !module || module_is_live(module); 6111da177e4SLinus Torvalds } 6121da177e4SLinus Torvalds static inline void module_put(struct module *module) 6131da177e4SLinus Torvalds { 6141da177e4SLinus Torvalds } 6151da177e4SLinus Torvalds static inline void __module_get(struct module *module) 6161da177e4SLinus Torvalds { 6171da177e4SLinus Torvalds } 6181da177e4SLinus Torvalds #define symbol_put(x) do { } while (0) 6191da177e4SLinus Torvalds #define symbol_put_addr(p) do { } while (0) 6201da177e4SLinus Torvalds 6211da177e4SLinus Torvalds #endif /* CONFIG_MODULE_UNLOAD */ 6221da177e4SLinus Torvalds 6231da177e4SLinus Torvalds /* This is a #define so the string doesn't get put in every .o file */ 6241da177e4SLinus Torvalds #define module_name(mod) \ 6251da177e4SLinus Torvalds ({ \ 6261da177e4SLinus Torvalds struct module *__mod = (mod); \ 6271da177e4SLinus Torvalds __mod ? __mod->name : "kernel"; \ 6281da177e4SLinus Torvalds }) 6291da177e4SLinus Torvalds 630b865ea64SSergey Senozhatsky /* Dereference module function descriptor */ 631b865ea64SSergey Senozhatsky void *dereference_module_function_descriptor(struct module *mod, void *ptr); 632b865ea64SSergey Senozhatsky 6336dd06c9fSRusty Russell /* For kallsyms to ask for address resolution. namebuf should be at 6346dd06c9fSRusty Russell * least KSYM_NAME_LEN long: a pointer to namebuf is returned if 6356dd06c9fSRusty Russell * found, otherwise NULL. */ 63692dfc9dcSAndrew Morton const char *module_address_lookup(unsigned long addr, 6371da177e4SLinus Torvalds unsigned long *symbolsize, 6381da177e4SLinus Torvalds unsigned long *offset, 6396dd06c9fSRusty Russell char **modname, 6406dd06c9fSRusty Russell char *namebuf); 6419d65cb4aSAlexey Dobriyan int lookup_module_symbol_name(unsigned long addr, char *symname); 642a5c43daeSAlexey Dobriyan int lookup_module_symbol_attrs(unsigned long addr, unsigned long *size, unsigned long *offset, char *modname, char *name); 6431da177e4SLinus Torvalds 6441da177e4SLinus Torvalds int register_module_notifier(struct notifier_block *nb); 6451da177e4SLinus Torvalds int unregister_module_notifier(struct notifier_block *nb); 6461da177e4SLinus Torvalds 6471da177e4SLinus Torvalds extern void print_modules(void); 6481da177e4SLinus Torvalds 64980c6e146SDmitry Torokhov static inline bool module_requested_async_probing(struct module *module) 65080c6e146SDmitry Torokhov { 65180c6e146SDmitry Torokhov return module && module->async_probe_requested; 65280c6e146SDmitry Torokhov } 65380c6e146SDmitry Torokhov 6541ce15ef4SJessica Yu #ifdef CONFIG_LIVEPATCH 6551ce15ef4SJessica Yu static inline bool is_livepatch_module(struct module *mod) 6561ce15ef4SJessica Yu { 6571ce15ef4SJessica Yu return mod->klp; 6581ce15ef4SJessica Yu } 6591ce15ef4SJessica Yu #else /* !CONFIG_LIVEPATCH */ 6601ce15ef4SJessica Yu static inline bool is_livepatch_module(struct module *mod) 6611ce15ef4SJessica Yu { 6621ce15ef4SJessica Yu return false; 6631ce15ef4SJessica Yu } 6641ce15ef4SJessica Yu #endif /* CONFIG_LIVEPATCH */ 6651ce15ef4SJessica Yu 666fda784e5SBruno E. O. Meneguele bool is_module_sig_enforced(void); 6678db5da0bSMimi Zohar void set_module_sig_enforced(void); 668fda784e5SBruno E. O. Meneguele 6691da177e4SLinus Torvalds #else /* !CONFIG_MODULES... */ 6701da177e4SLinus Torvalds 671e610499eSRusty Russell static inline struct module *__module_address(unsigned long addr) 672e610499eSRusty Russell { 673e610499eSRusty Russell return NULL; 674e610499eSRusty Russell } 675e610499eSRusty Russell 6761da177e4SLinus Torvalds static inline struct module *__module_text_address(unsigned long addr) 6771da177e4SLinus Torvalds { 6781da177e4SLinus Torvalds return NULL; 6791da177e4SLinus Torvalds } 6801da177e4SLinus Torvalds 681e610499eSRusty Russell static inline bool is_module_address(unsigned long addr) 6824d435f9dSIngo Molnar { 683e610499eSRusty Russell return false; 684e610499eSRusty Russell } 685e610499eSRusty Russell 686d5e50dafSRandy Dunlap static inline bool is_module_percpu_address(unsigned long addr) 687d5e50dafSRandy Dunlap { 688d5e50dafSRandy Dunlap return false; 689d5e50dafSRandy Dunlap } 690d5e50dafSRandy Dunlap 691383776faSThomas Gleixner static inline bool __is_module_percpu_address(unsigned long addr, unsigned long *can_addr) 692383776faSThomas Gleixner { 693383776faSThomas Gleixner return false; 694383776faSThomas Gleixner } 695383776faSThomas Gleixner 696e610499eSRusty Russell static inline bool is_module_text_address(unsigned long addr) 697e610499eSRusty Russell { 698e610499eSRusty Russell return false; 6994d435f9dSIngo Molnar } 7004d435f9dSIngo Molnar 701007ec26cSDavid Howells static inline bool within_module_core(unsigned long addr, 702007ec26cSDavid Howells const struct module *mod) 703007ec26cSDavid Howells { 704007ec26cSDavid Howells return false; 705007ec26cSDavid Howells } 706007ec26cSDavid Howells 707dadec066STri Vo static inline bool within_module_init(unsigned long addr, 708dadec066STri Vo const struct module *mod) 709dadec066STri Vo { 710dadec066STri Vo return false; 711dadec066STri Vo } 712dadec066STri Vo 713dadec066STri Vo static inline bool within_module(unsigned long addr, const struct module *mod) 714dadec066STri Vo { 715dadec066STri Vo return false; 716dadec066STri Vo } 717dadec066STri Vo 7181da177e4SLinus Torvalds /* Get/put a kernel symbol (calls should be symmetric) */ 71913150bc5SArd Biesheuvel #define symbol_get(x) ({ extern typeof(x) x __attribute__((weak,visibility("hidden"))); &(x); }) 7201da177e4SLinus Torvalds #define symbol_put(x) do { } while (0) 7211da177e4SLinus Torvalds #define symbol_put_addr(x) do { } while (0) 7221da177e4SLinus Torvalds 7231da177e4SLinus Torvalds static inline void __module_get(struct module *module) 7241da177e4SLinus Torvalds { 7251da177e4SLinus Torvalds } 7261da177e4SLinus Torvalds 7278ba4fcdfSGao Feng static inline bool try_module_get(struct module *module) 7281da177e4SLinus Torvalds { 7298ba4fcdfSGao Feng return true; 7301da177e4SLinus Torvalds } 7311da177e4SLinus Torvalds 7321da177e4SLinus Torvalds static inline void module_put(struct module *module) 7331da177e4SLinus Torvalds { 7341da177e4SLinus Torvalds } 7351da177e4SLinus Torvalds 7361da177e4SLinus Torvalds #define module_name(mod) "kernel" 7371da177e4SLinus Torvalds 7381da177e4SLinus Torvalds /* For kallsyms to ask for address resolution. NULL means not found. */ 73992dfc9dcSAndrew Morton static inline const char *module_address_lookup(unsigned long addr, 7401da177e4SLinus Torvalds unsigned long *symbolsize, 7411da177e4SLinus Torvalds unsigned long *offset, 7426dd06c9fSRusty Russell char **modname, 7436dd06c9fSRusty Russell char *namebuf) 7441da177e4SLinus Torvalds { 7451da177e4SLinus Torvalds return NULL; 7461da177e4SLinus Torvalds } 7471da177e4SLinus Torvalds 7489d65cb4aSAlexey Dobriyan static inline int lookup_module_symbol_name(unsigned long addr, char *symname) 7499d65cb4aSAlexey Dobriyan { 7509d65cb4aSAlexey Dobriyan return -ERANGE; 7519d65cb4aSAlexey Dobriyan } 7529d65cb4aSAlexey Dobriyan 753a5c43daeSAlexey Dobriyan static inline int lookup_module_symbol_attrs(unsigned long addr, unsigned long *size, unsigned long *offset, char *modname, char *name) 754a5c43daeSAlexey Dobriyan { 755a5c43daeSAlexey Dobriyan return -ERANGE; 756a5c43daeSAlexey Dobriyan } 757a5c43daeSAlexey Dobriyan 758ea07890aSAlexey Dobriyan static inline int module_get_kallsym(unsigned int symnum, unsigned long *value, 759ea07890aSAlexey Dobriyan char *type, char *name, 760ea07890aSAlexey Dobriyan char *module_name, int *exported) 7611da177e4SLinus Torvalds { 762ea07890aSAlexey Dobriyan return -ERANGE; 7631da177e4SLinus Torvalds } 7641da177e4SLinus Torvalds 7651da177e4SLinus Torvalds static inline unsigned long module_kallsyms_lookup_name(const char *name) 7661da177e4SLinus Torvalds { 7671da177e4SLinus Torvalds return 0; 7681da177e4SLinus Torvalds } 7691da177e4SLinus Torvalds 7701da177e4SLinus Torvalds static inline int register_module_notifier(struct notifier_block *nb) 7711da177e4SLinus Torvalds { 7721da177e4SLinus Torvalds /* no events will happen anyway, so this can always succeed */ 7731da177e4SLinus Torvalds return 0; 7741da177e4SLinus Torvalds } 7751da177e4SLinus Torvalds 7761da177e4SLinus Torvalds static inline int unregister_module_notifier(struct notifier_block *nb) 7771da177e4SLinus Torvalds { 7781da177e4SLinus Torvalds return 0; 7791da177e4SLinus Torvalds } 7801da177e4SLinus Torvalds 7811da177e4SLinus Torvalds #define module_put_and_exit(code) do_exit(code) 7821da177e4SLinus Torvalds 7831da177e4SLinus Torvalds static inline void print_modules(void) 7841da177e4SLinus Torvalds { 7851da177e4SLinus Torvalds } 78680c6e146SDmitry Torokhov 78780c6e146SDmitry Torokhov static inline bool module_requested_async_probing(struct module *module) 78880c6e146SDmitry Torokhov { 78980c6e146SDmitry Torokhov return false; 79080c6e146SDmitry Torokhov } 79180c6e146SDmitry Torokhov 792fda784e5SBruno E. O. Meneguele static inline bool is_module_sig_enforced(void) 793fda784e5SBruno E. O. Meneguele { 794fda784e5SBruno E. O. Meneguele return false; 795fda784e5SBruno E. O. Meneguele } 796fda784e5SBruno E. O. Meneguele 7978db5da0bSMimi Zohar static inline void set_module_sig_enforced(void) 7988db5da0bSMimi Zohar { 7998db5da0bSMimi Zohar } 8008db5da0bSMimi Zohar 801b865ea64SSergey Senozhatsky /* Dereference module function descriptor */ 802b865ea64SSergey Senozhatsky static inline 803b865ea64SSergey Senozhatsky void *dereference_module_function_descriptor(struct module *mod, void *ptr) 804b865ea64SSergey Senozhatsky { 805b865ea64SSergey Senozhatsky return ptr; 806b865ea64SSergey Senozhatsky } 807b865ea64SSergey Senozhatsky 808ef665c1aSRandy Dunlap #endif /* CONFIG_MODULES */ 809ef665c1aSRandy Dunlap 810ef665c1aSRandy Dunlap #ifdef CONFIG_SYSFS 8117405c1e1SGreg Kroah-Hartman extern struct kset *module_kset; 8127405c1e1SGreg Kroah-Hartman extern struct kobj_type module_ktype; 8137405c1e1SGreg Kroah-Hartman extern int module_sysfs_initialized; 814ef665c1aSRandy Dunlap #endif /* CONFIG_SYSFS */ 815ef665c1aSRandy Dunlap 8161da177e4SLinus Torvalds #define symbol_request(x) try_then_request_module(symbol_get(x), "symbol:" #x) 8171da177e4SLinus Torvalds 8181da177e4SLinus Torvalds /* BELOW HERE ALL THESE ARE OBSOLETE AND WILL VANISH */ 8191da177e4SLinus Torvalds 8201da177e4SLinus Torvalds #define __MODULE_STRING(x) __stringify(x) 8211da177e4SLinus Torvalds 8220d9c25ddSAndrew Morton #ifdef CONFIG_GENERIC_BUG 8235336377dSLinus Torvalds void module_bug_finalize(const Elf_Ehdr *, const Elf_Shdr *, 8240d9c25ddSAndrew Morton struct module *); 8250d9c25ddSAndrew Morton void module_bug_cleanup(struct module *); 8260d9c25ddSAndrew Morton 8270d9c25ddSAndrew Morton #else /* !CONFIG_GENERIC_BUG */ 8280d9c25ddSAndrew Morton 8295336377dSLinus Torvalds static inline void module_bug_finalize(const Elf_Ehdr *hdr, 8300d9c25ddSAndrew Morton const Elf_Shdr *sechdrs, 8310d9c25ddSAndrew Morton struct module *mod) 8320d9c25ddSAndrew Morton { 8330d9c25ddSAndrew Morton } 8340d9c25ddSAndrew Morton static inline void module_bug_cleanup(struct module *mod) {} 8350d9c25ddSAndrew Morton #endif /* CONFIG_GENERIC_BUG */ 8360d9c25ddSAndrew Morton 837e4f35891SWANG Chao #ifdef CONFIG_RETPOLINE 838caf7501aSAndi Kleen extern bool retpoline_module_ok(bool has_retpoline); 839caf7501aSAndi Kleen #else 840caf7501aSAndi Kleen static inline bool retpoline_module_ok(bool has_retpoline) 841caf7501aSAndi Kleen { 842caf7501aSAndi Kleen return true; 843caf7501aSAndi Kleen } 844caf7501aSAndi Kleen #endif 845caf7501aSAndi Kleen 84659afdc7bSHerbert Xu #ifdef CONFIG_MODULE_SIG 84759afdc7bSHerbert Xu static inline bool module_sig_ok(struct module *module) 84859afdc7bSHerbert Xu { 84959afdc7bSHerbert Xu return module->sig_ok; 85059afdc7bSHerbert Xu } 85159afdc7bSHerbert Xu #else /* !CONFIG_MODULE_SIG */ 85259afdc7bSHerbert Xu static inline bool module_sig_ok(struct module *module) 85359afdc7bSHerbert Xu { 85459afdc7bSHerbert Xu return true; 85559afdc7bSHerbert Xu } 85659afdc7bSHerbert Xu #endif /* CONFIG_MODULE_SIG */ 85759afdc7bSHerbert Xu 8583e355205SChristoph Hellwig int module_kallsyms_on_each_symbol(int (*fn)(void *, const char *, 8593e355205SChristoph Hellwig struct module *, unsigned long), 8603e355205SChristoph Hellwig void *data); 8613e355205SChristoph Hellwig 8621da177e4SLinus Torvalds #endif /* _LINUX_MODULE_H */ 863