Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * Dynamic loading of modules into the kernel.
0004  *
0005  * Rewritten by Richard Henderson <rth@tamu.edu> Dec 1996
0006  * Rewritten again by Rusty Russell, 2002
0007  */
0008 
0009 #ifndef _LINUX_MODULE_H
0010 #define _LINUX_MODULE_H
0011 
0012 #include <linux/list.h>
0013 #include <linux/stat.h>
0014 #include <linux/buildid.h>
0015 #include <linux/compiler.h>
0016 #include <linux/cache.h>
0017 #include <linux/kmod.h>
0018 #include <linux/init.h>
0019 #include <linux/elf.h>
0020 #include <linux/stringify.h>
0021 #include <linux/kobject.h>
0022 #include <linux/moduleparam.h>
0023 #include <linux/jump_label.h>
0024 #include <linux/export.h>
0025 #include <linux/rbtree_latch.h>
0026 #include <linux/error-injection.h>
0027 #include <linux/tracepoint-defs.h>
0028 #include <linux/srcu.h>
0029 #include <linux/static_call_types.h>
0030 #include <linux/cfi.h>
0031 
0032 #include <linux/percpu.h>
0033 #include <asm/module.h>
0034 
0035 #define MODULE_NAME_LEN MAX_PARAM_PREFIX_LEN
0036 
0037 struct modversion_info {
0038     unsigned long crc;
0039     char name[MODULE_NAME_LEN];
0040 };
0041 
0042 struct module;
0043 struct exception_table_entry;
0044 
0045 struct module_kobject {
0046     struct kobject kobj;
0047     struct module *mod;
0048     struct kobject *drivers_dir;
0049     struct module_param_attrs *mp;
0050     struct completion *kobj_completion;
0051 } __randomize_layout;
0052 
0053 struct module_attribute {
0054     struct attribute attr;
0055     ssize_t (*show)(struct module_attribute *, struct module_kobject *,
0056             char *);
0057     ssize_t (*store)(struct module_attribute *, struct module_kobject *,
0058              const char *, size_t count);
0059     void (*setup)(struct module *, const char *);
0060     int (*test)(struct module *);
0061     void (*free)(struct module *);
0062 };
0063 
0064 struct module_version_attribute {
0065     struct module_attribute mattr;
0066     const char *module_name;
0067     const char *version;
0068 };
0069 
0070 extern ssize_t __modver_version_show(struct module_attribute *,
0071                      struct module_kobject *, char *);
0072 
0073 extern struct module_attribute module_uevent;
0074 
0075 /* These are either module local, or the kernel's dummy ones. */
0076 extern int init_module(void);
0077 extern void cleanup_module(void);
0078 
0079 #ifndef MODULE
0080 /**
0081  * module_init() - driver initialization entry point
0082  * @x: function to be run at kernel boot time or module insertion
0083  *
0084  * module_init() will either be called during do_initcalls() (if
0085  * builtin) or at module insertion time (if a module).  There can only
0086  * be one per module.
0087  */
0088 #define module_init(x)  __initcall(x);
0089 
0090 /**
0091  * module_exit() - driver exit entry point
0092  * @x: function to be run when driver is removed
0093  *
0094  * module_exit() will wrap the driver clean-up code
0095  * with cleanup_module() when used with rmmod when
0096  * the driver is a module.  If the driver is statically
0097  * compiled into the kernel, module_exit() has no effect.
0098  * There can only be one per module.
0099  */
0100 #define module_exit(x)  __exitcall(x);
0101 
0102 #else /* MODULE */
0103 
0104 /*
0105  * In most cases loadable modules do not need custom
0106  * initcall levels. There are still some valid cases where
0107  * a driver may be needed early if built in, and does not
0108  * matter when built as a loadable module. Like bus
0109  * snooping debug drivers.
0110  */
0111 #define early_initcall(fn)      module_init(fn)
0112 #define core_initcall(fn)       module_init(fn)
0113 #define core_initcall_sync(fn)      module_init(fn)
0114 #define postcore_initcall(fn)       module_init(fn)
0115 #define postcore_initcall_sync(fn)  module_init(fn)
0116 #define arch_initcall(fn)       module_init(fn)
0117 #define subsys_initcall(fn)     module_init(fn)
0118 #define subsys_initcall_sync(fn)    module_init(fn)
0119 #define fs_initcall(fn)         module_init(fn)
0120 #define fs_initcall_sync(fn)        module_init(fn)
0121 #define rootfs_initcall(fn)     module_init(fn)
0122 #define device_initcall(fn)     module_init(fn)
0123 #define device_initcall_sync(fn)    module_init(fn)
0124 #define late_initcall(fn)       module_init(fn)
0125 #define late_initcall_sync(fn)      module_init(fn)
0126 
0127 #define console_initcall(fn)        module_init(fn)
0128 
0129 /* Each module must use one module_init(). */
0130 #define module_init(initfn)                 \
0131     static inline initcall_t __maybe_unused __inittest(void)        \
0132     { return initfn; }                  \
0133     int init_module(void) __copy(initfn)            \
0134         __attribute__((alias(#initfn)));        \
0135     __CFI_ADDRESSABLE(init_module, __initdata);
0136 
0137 /* This is only required if you want to be unloadable. */
0138 #define module_exit(exitfn)                 \
0139     static inline exitcall_t __maybe_unused __exittest(void)        \
0140     { return exitfn; }                  \
0141     void cleanup_module(void) __copy(exitfn)        \
0142         __attribute__((alias(#exitfn)));        \
0143     __CFI_ADDRESSABLE(cleanup_module, __exitdata);
0144 
0145 #endif
0146 
0147 /* This means "can be init if no module support, otherwise module load
0148    may call it." */
0149 #ifdef CONFIG_MODULES
0150 #define __init_or_module
0151 #define __initdata_or_module
0152 #define __initconst_or_module
0153 #define __INIT_OR_MODULE    .text
0154 #define __INITDATA_OR_MODULE    .data
0155 #define __INITRODATA_OR_MODULE  .section ".rodata","a",%progbits
0156 #else
0157 #define __init_or_module __init
0158 #define __initdata_or_module __initdata
0159 #define __initconst_or_module __initconst
0160 #define __INIT_OR_MODULE __INIT
0161 #define __INITDATA_OR_MODULE __INITDATA
0162 #define __INITRODATA_OR_MODULE __INITRODATA
0163 #endif /*CONFIG_MODULES*/
0164 
0165 /* Generic info of form tag = "info" */
0166 #define MODULE_INFO(tag, info) __MODULE_INFO(tag, tag, info)
0167 
0168 /* For userspace: you can also call me... */
0169 #define MODULE_ALIAS(_alias) MODULE_INFO(alias, _alias)
0170 
0171 /* Soft module dependencies. See man modprobe.d for details.
0172  * Example: MODULE_SOFTDEP("pre: module-foo module-bar post: module-baz")
0173  */
0174 #define MODULE_SOFTDEP(_softdep) MODULE_INFO(softdep, _softdep)
0175 
0176 /*
0177  * MODULE_FILE is used for generating modules.builtin
0178  * So, make it no-op when this is being built as a module
0179  */
0180 #ifdef MODULE
0181 #define MODULE_FILE
0182 #else
0183 #define MODULE_FILE MODULE_INFO(file, KBUILD_MODFILE);
0184 #endif
0185 
0186 /*
0187  * The following license idents are currently accepted as indicating free
0188  * software modules
0189  *
0190  *  "GPL"               [GNU Public License v2]
0191  *  "GPL v2"            [GNU Public License v2]
0192  *  "GPL and additional rights" [GNU Public License v2 rights and more]
0193  *  "Dual BSD/GPL"          [GNU Public License v2
0194  *                   or BSD license choice]
0195  *  "Dual MIT/GPL"          [GNU Public License v2
0196  *                   or MIT license choice]
0197  *  "Dual MPL/GPL"          [GNU Public License v2
0198  *                   or Mozilla license choice]
0199  *
0200  * The following other idents are available
0201  *
0202  *  "Proprietary"           [Non free products]
0203  *
0204  * Both "GPL v2" and "GPL" (the latter also in dual licensed strings) are
0205  * merely stating that the module is licensed under the GPL v2, but are not
0206  * telling whether "GPL v2 only" or "GPL v2 or later". The reason why there
0207  * are two variants is a historic and failed attempt to convey more
0208  * information in the MODULE_LICENSE string. For module loading the
0209  * "only/or later" distinction is completely irrelevant and does neither
0210  * replace the proper license identifiers in the corresponding source file
0211  * nor amends them in any way. The sole purpose is to make the
0212  * 'Proprietary' flagging work and to refuse to bind symbols which are
0213  * exported with EXPORT_SYMBOL_GPL when a non free module is loaded.
0214  *
0215  * In the same way "BSD" is not a clear license information. It merely
0216  * states, that the module is licensed under one of the compatible BSD
0217  * license variants. The detailed and correct license information is again
0218  * to be found in the corresponding source files.
0219  *
0220  * There are dual licensed components, but when running with Linux it is the
0221  * GPL that is relevant so this is a non issue. Similarly LGPL linked with GPL
0222  * is a GPL combined work.
0223  *
0224  * This exists for several reasons
0225  * 1.   So modinfo can show license info for users wanting to vet their setup
0226  *  is free
0227  * 2.   So the community can ignore bug reports including proprietary modules
0228  * 3.   So vendors can do likewise based on their own policies
0229  */
0230 #define MODULE_LICENSE(_license) MODULE_FILE MODULE_INFO(license, _license)
0231 
0232 /*
0233  * Author(s), use "Name <email>" or just "Name", for multiple
0234  * authors use multiple MODULE_AUTHOR() statements/lines.
0235  */
0236 #define MODULE_AUTHOR(_author) MODULE_INFO(author, _author)
0237 
0238 /* What your module does. */
0239 #define MODULE_DESCRIPTION(_description) MODULE_INFO(description, _description)
0240 
0241 #ifdef MODULE
0242 /* Creates an alias so file2alias.c can find device table. */
0243 #define MODULE_DEVICE_TABLE(type, name)                 \
0244 extern typeof(name) __mod_##type##__##name##_device_table       \
0245   __attribute__ ((unused, alias(__stringify(name))))
0246 #else  /* !MODULE */
0247 #define MODULE_DEVICE_TABLE(type, name)
0248 #endif
0249 
0250 /* Version of form [<epoch>:]<version>[-<extra-version>].
0251  * Or for CVS/RCS ID version, everything but the number is stripped.
0252  * <epoch>: A (small) unsigned integer which allows you to start versions
0253  * anew. If not mentioned, it's zero.  eg. "2:1.0" is after
0254  * "1:2.0".
0255 
0256  * <version>: The <version> may contain only alphanumerics and the
0257  * character `.'.  Ordered by numeric sort for numeric parts,
0258  * ascii sort for ascii parts (as per RPM or DEB algorithm).
0259 
0260  * <extraversion>: Like <version>, but inserted for local
0261  * customizations, eg "rh3" or "rusty1".
0262 
0263  * Using this automatically adds a checksum of the .c files and the
0264  * local headers in "srcversion".
0265  */
0266 
0267 #if defined(MODULE) || !defined(CONFIG_SYSFS)
0268 #define MODULE_VERSION(_version) MODULE_INFO(version, _version)
0269 #else
0270 #define MODULE_VERSION(_version)                    \
0271     MODULE_INFO(version, _version);                 \
0272     static struct module_version_attribute __modver_attr        \
0273         __used __section("__modver")                \
0274         __aligned(__alignof__(struct module_version_attribute)) \
0275         = {                         \
0276             .mattr  = {                 \
0277                 .attr   = {             \
0278                     .name   = "version",        \
0279                     .mode   = S_IRUGO,      \
0280                 },                  \
0281                 .show   = __modver_version_show,    \
0282             },                      \
0283             .module_name    = KBUILD_MODNAME,       \
0284             .version    = _version,         \
0285         }
0286 #endif
0287 
0288 /* Optional firmware file (or files) needed by the module
0289  * format is simply firmware file name.  Multiple firmware
0290  * files require multiple MODULE_FIRMWARE() specifiers */
0291 #define MODULE_FIRMWARE(_firmware) MODULE_INFO(firmware, _firmware)
0292 
0293 #define MODULE_IMPORT_NS(ns)    MODULE_INFO(import_ns, __stringify(ns))
0294 
0295 struct notifier_block;
0296 
0297 #ifdef CONFIG_MODULES
0298 
0299 extern int modules_disabled; /* for sysctl */
0300 /* Get/put a kernel symbol (calls must be symmetric) */
0301 void *__symbol_get(const char *symbol);
0302 void *__symbol_get_gpl(const char *symbol);
0303 #define symbol_get(x) ((typeof(&x))(__symbol_get(__stringify(x))))
0304 
0305 /* modules using other modules: kdb wants to see this. */
0306 struct module_use {
0307     struct list_head source_list;
0308     struct list_head target_list;
0309     struct module *source, *target;
0310 };
0311 
0312 enum module_state {
0313     MODULE_STATE_LIVE,  /* Normal state. */
0314     MODULE_STATE_COMING,    /* Full formed, running module_init. */
0315     MODULE_STATE_GOING, /* Going away. */
0316     MODULE_STATE_UNFORMED,  /* Still setting it up. */
0317 };
0318 
0319 struct mod_tree_node {
0320     struct module *mod;
0321     struct latch_tree_node node;
0322 };
0323 
0324 struct module_layout {
0325     /* The actual code + data. */
0326     void *base;
0327     /* Total size. */
0328     unsigned int size;
0329     /* The size of the executable code.  */
0330     unsigned int text_size;
0331     /* Size of RO section of the module (text+rodata) */
0332     unsigned int ro_size;
0333     /* Size of RO after init section */
0334     unsigned int ro_after_init_size;
0335 
0336 #ifdef CONFIG_MODULES_TREE_LOOKUP
0337     struct mod_tree_node mtn;
0338 #endif
0339 };
0340 
0341 #ifdef CONFIG_MODULES_TREE_LOOKUP
0342 /* Only touch one cacheline for common rbtree-for-core-layout case. */
0343 #define __module_layout_align ____cacheline_aligned
0344 #else
0345 #define __module_layout_align
0346 #endif
0347 
0348 struct mod_kallsyms {
0349     Elf_Sym *symtab;
0350     unsigned int num_symtab;
0351     char *strtab;
0352     char *typetab;
0353 };
0354 
0355 #ifdef CONFIG_LIVEPATCH
0356 struct klp_modinfo {
0357     Elf_Ehdr hdr;
0358     Elf_Shdr *sechdrs;
0359     char *secstrings;
0360     unsigned int symndx;
0361 };
0362 #endif
0363 
0364 struct module {
0365     enum module_state state;
0366 
0367     /* Member of list of modules */
0368     struct list_head list;
0369 
0370     /* Unique handle for this module */
0371     char name[MODULE_NAME_LEN];
0372 
0373 #ifdef CONFIG_STACKTRACE_BUILD_ID
0374     /* Module build ID */
0375     unsigned char build_id[BUILD_ID_SIZE_MAX];
0376 #endif
0377 
0378     /* Sysfs stuff. */
0379     struct module_kobject mkobj;
0380     struct module_attribute *modinfo_attrs;
0381     const char *version;
0382     const char *srcversion;
0383     struct kobject *holders_dir;
0384 
0385     /* Exported symbols */
0386     const struct kernel_symbol *syms;
0387     const s32 *crcs;
0388     unsigned int num_syms;
0389 
0390 #ifdef CONFIG_CFI_CLANG
0391     cfi_check_fn cfi_check;
0392 #endif
0393 
0394     /* Kernel parameters. */
0395 #ifdef CONFIG_SYSFS
0396     struct mutex param_lock;
0397 #endif
0398     struct kernel_param *kp;
0399     unsigned int num_kp;
0400 
0401     /* GPL-only exported symbols. */
0402     unsigned int num_gpl_syms;
0403     const struct kernel_symbol *gpl_syms;
0404     const s32 *gpl_crcs;
0405     bool using_gplonly_symbols;
0406 
0407 #ifdef CONFIG_MODULE_SIG
0408     /* Signature was verified. */
0409     bool sig_ok;
0410 #endif
0411 
0412     bool async_probe_requested;
0413 
0414     /* Exception table */
0415     unsigned int num_exentries;
0416     struct exception_table_entry *extable;
0417 
0418     /* Startup function. */
0419     int (*init)(void);
0420 
0421     /* Core layout: rbtree is accessed frequently, so keep together. */
0422     struct module_layout core_layout __module_layout_align;
0423     struct module_layout init_layout;
0424 #ifdef CONFIG_ARCH_WANTS_MODULES_DATA_IN_VMALLOC
0425     struct module_layout data_layout;
0426 #endif
0427 
0428     /* Arch-specific module values */
0429     struct mod_arch_specific arch;
0430 
0431     unsigned long taints;   /* same bits as kernel:taint_flags */
0432 
0433 #ifdef CONFIG_GENERIC_BUG
0434     /* Support for BUG */
0435     unsigned num_bugs;
0436     struct list_head bug_list;
0437     struct bug_entry *bug_table;
0438 #endif
0439 
0440 #ifdef CONFIG_KALLSYMS
0441     /* Protected by RCU and/or module_mutex: use rcu_dereference() */
0442     struct mod_kallsyms __rcu *kallsyms;
0443     struct mod_kallsyms core_kallsyms;
0444 
0445     /* Section attributes */
0446     struct module_sect_attrs *sect_attrs;
0447 
0448     /* Notes attributes */
0449     struct module_notes_attrs *notes_attrs;
0450 #endif
0451 
0452     /* The command line arguments (may be mangled).  People like
0453        keeping pointers to this stuff */
0454     char *args;
0455 
0456 #ifdef CONFIG_SMP
0457     /* Per-cpu data. */
0458     void __percpu *percpu;
0459     unsigned int percpu_size;
0460 #endif
0461     void *noinstr_text_start;
0462     unsigned int noinstr_text_size;
0463 
0464 #ifdef CONFIG_TRACEPOINTS
0465     unsigned int num_tracepoints;
0466     tracepoint_ptr_t *tracepoints_ptrs;
0467 #endif
0468 #ifdef CONFIG_TREE_SRCU
0469     unsigned int num_srcu_structs;
0470     struct srcu_struct **srcu_struct_ptrs;
0471 #endif
0472 #ifdef CONFIG_BPF_EVENTS
0473     unsigned int num_bpf_raw_events;
0474     struct bpf_raw_event_map *bpf_raw_events;
0475 #endif
0476 #ifdef CONFIG_DEBUG_INFO_BTF_MODULES
0477     unsigned int btf_data_size;
0478     void *btf_data;
0479 #endif
0480 #ifdef CONFIG_JUMP_LABEL
0481     struct jump_entry *jump_entries;
0482     unsigned int num_jump_entries;
0483 #endif
0484 #ifdef CONFIG_TRACING
0485     unsigned int num_trace_bprintk_fmt;
0486     const char **trace_bprintk_fmt_start;
0487 #endif
0488 #ifdef CONFIG_EVENT_TRACING
0489     struct trace_event_call **trace_events;
0490     unsigned int num_trace_events;
0491     struct trace_eval_map **trace_evals;
0492     unsigned int num_trace_evals;
0493 #endif
0494 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
0495     unsigned int num_ftrace_callsites;
0496     unsigned long *ftrace_callsites;
0497 #endif
0498 #ifdef CONFIG_KPROBES
0499     void *kprobes_text_start;
0500     unsigned int kprobes_text_size;
0501     unsigned long *kprobe_blacklist;
0502     unsigned int num_kprobe_blacklist;
0503 #endif
0504 #ifdef CONFIG_HAVE_STATIC_CALL_INLINE
0505     int num_static_call_sites;
0506     struct static_call_site *static_call_sites;
0507 #endif
0508 #if IS_ENABLED(CONFIG_KUNIT)
0509     int num_kunit_suites;
0510     struct kunit_suite **kunit_suites;
0511 #endif
0512 
0513 
0514 #ifdef CONFIG_LIVEPATCH
0515     bool klp; /* Is this a livepatch module? */
0516     bool klp_alive;
0517 
0518     /* Elf information */
0519     struct klp_modinfo *klp_info;
0520 #endif
0521 
0522 #ifdef CONFIG_PRINTK_INDEX
0523     unsigned int printk_index_size;
0524     struct pi_entry **printk_index_start;
0525 #endif
0526 
0527 #ifdef CONFIG_MODULE_UNLOAD
0528     /* What modules depend on me? */
0529     struct list_head source_list;
0530     /* What modules do I depend on? */
0531     struct list_head target_list;
0532 
0533     /* Destruction function. */
0534     void (*exit)(void);
0535 
0536     atomic_t refcnt;
0537 #endif
0538 
0539 #ifdef CONFIG_CONSTRUCTORS
0540     /* Constructor functions. */
0541     ctor_fn_t *ctors;
0542     unsigned int num_ctors;
0543 #endif
0544 
0545 #ifdef CONFIG_FUNCTION_ERROR_INJECTION
0546     struct error_injection_entry *ei_funcs;
0547     unsigned int num_ei_funcs;
0548 #endif
0549 } ____cacheline_aligned __randomize_layout;
0550 #ifndef MODULE_ARCH_INIT
0551 #define MODULE_ARCH_INIT {}
0552 #endif
0553 
0554 #ifndef HAVE_ARCH_KALLSYMS_SYMBOL_VALUE
0555 static inline unsigned long kallsyms_symbol_value(const Elf_Sym *sym)
0556 {
0557     return sym->st_value;
0558 }
0559 #endif
0560 
0561 /* FIXME: It'd be nice to isolate modules during init, too, so they
0562    aren't used before they (may) fail.  But presently too much code
0563    (IDE & SCSI) require entry into the module during init.*/
0564 static inline bool module_is_live(struct module *mod)
0565 {
0566     return mod->state != MODULE_STATE_GOING;
0567 }
0568 
0569 struct module *__module_text_address(unsigned long addr);
0570 struct module *__module_address(unsigned long addr);
0571 bool is_module_address(unsigned long addr);
0572 bool __is_module_percpu_address(unsigned long addr, unsigned long *can_addr);
0573 bool is_module_percpu_address(unsigned long addr);
0574 bool is_module_text_address(unsigned long addr);
0575 
0576 static inline bool within_module_core(unsigned long addr,
0577                       const struct module *mod)
0578 {
0579 #ifdef CONFIG_ARCH_WANTS_MODULES_DATA_IN_VMALLOC
0580     if ((unsigned long)mod->data_layout.base <= addr &&
0581         addr < (unsigned long)mod->data_layout.base + mod->data_layout.size)
0582         return true;
0583 #endif
0584     return (unsigned long)mod->core_layout.base <= addr &&
0585            addr < (unsigned long)mod->core_layout.base + mod->core_layout.size;
0586 }
0587 
0588 static inline bool within_module_init(unsigned long addr,
0589                       const struct module *mod)
0590 {
0591     return (unsigned long)mod->init_layout.base <= addr &&
0592            addr < (unsigned long)mod->init_layout.base + mod->init_layout.size;
0593 }
0594 
0595 static inline bool within_module(unsigned long addr, const struct module *mod)
0596 {
0597     return within_module_init(addr, mod) || within_module_core(addr, mod);
0598 }
0599 
0600 /* Search for module by name: must be in a RCU-sched critical section. */
0601 struct module *find_module(const char *name);
0602 
0603 /* Returns 0 and fills in value, defined and namebuf, or -ERANGE if
0604    symnum out of range. */
0605 int module_get_kallsym(unsigned int symnum, unsigned long *value, char *type,
0606             char *name, char *module_name, int *exported);
0607 
0608 /* Look for this name: can be of form module:name. */
0609 unsigned long module_kallsyms_lookup_name(const char *name);
0610 
0611 extern void __noreturn __module_put_and_kthread_exit(struct module *mod,
0612             long code);
0613 #define module_put_and_kthread_exit(code) __module_put_and_kthread_exit(THIS_MODULE, code)
0614 
0615 #ifdef CONFIG_MODULE_UNLOAD
0616 int module_refcount(struct module *mod);
0617 void __symbol_put(const char *symbol);
0618 #define symbol_put(x) __symbol_put(__stringify(x))
0619 void symbol_put_addr(void *addr);
0620 
0621 /* Sometimes we know we already have a refcount, and it's easier not
0622    to handle the error case (which only happens with rmmod --wait). */
0623 extern void __module_get(struct module *module);
0624 
0625 /* This is the Right Way to get a module: if it fails, it's being removed,
0626  * so pretend it's not there. */
0627 extern bool try_module_get(struct module *module);
0628 
0629 extern void module_put(struct module *module);
0630 
0631 #else /*!CONFIG_MODULE_UNLOAD*/
0632 static inline bool try_module_get(struct module *module)
0633 {
0634     return !module || module_is_live(module);
0635 }
0636 static inline void module_put(struct module *module)
0637 {
0638 }
0639 static inline void __module_get(struct module *module)
0640 {
0641 }
0642 #define symbol_put(x) do { } while (0)
0643 #define symbol_put_addr(p) do { } while (0)
0644 
0645 #endif /* CONFIG_MODULE_UNLOAD */
0646 
0647 /* This is a #define so the string doesn't get put in every .o file */
0648 #define module_name(mod)            \
0649 ({                      \
0650     struct module *__mod = (mod);       \
0651     __mod ? __mod->name : "kernel";     \
0652 })
0653 
0654 /* Dereference module function descriptor */
0655 void *dereference_module_function_descriptor(struct module *mod, void *ptr);
0656 
0657 /* For kallsyms to ask for address resolution.  namebuf should be at
0658  * least KSYM_NAME_LEN long: a pointer to namebuf is returned if
0659  * found, otherwise NULL. */
0660 const char *module_address_lookup(unsigned long addr,
0661                 unsigned long *symbolsize,
0662                 unsigned long *offset,
0663                 char **modname, const unsigned char **modbuildid,
0664                 char *namebuf);
0665 int lookup_module_symbol_name(unsigned long addr, char *symname);
0666 int lookup_module_symbol_attrs(unsigned long addr, unsigned long *size, unsigned long *offset, char *modname, char *name);
0667 
0668 int register_module_notifier(struct notifier_block *nb);
0669 int unregister_module_notifier(struct notifier_block *nb);
0670 
0671 extern void print_modules(void);
0672 
0673 static inline bool module_requested_async_probing(struct module *module)
0674 {
0675     return module && module->async_probe_requested;
0676 }
0677 
0678 static inline bool is_livepatch_module(struct module *mod)
0679 {
0680 #ifdef CONFIG_LIVEPATCH
0681     return mod->klp;
0682 #else
0683     return false;
0684 #endif
0685 }
0686 
0687 void set_module_sig_enforced(void);
0688 
0689 #else /* !CONFIG_MODULES... */
0690 
0691 static inline struct module *__module_address(unsigned long addr)
0692 {
0693     return NULL;
0694 }
0695 
0696 static inline struct module *__module_text_address(unsigned long addr)
0697 {
0698     return NULL;
0699 }
0700 
0701 static inline bool is_module_address(unsigned long addr)
0702 {
0703     return false;
0704 }
0705 
0706 static inline bool is_module_percpu_address(unsigned long addr)
0707 {
0708     return false;
0709 }
0710 
0711 static inline bool __is_module_percpu_address(unsigned long addr, unsigned long *can_addr)
0712 {
0713     return false;
0714 }
0715 
0716 static inline bool is_module_text_address(unsigned long addr)
0717 {
0718     return false;
0719 }
0720 
0721 static inline bool within_module_core(unsigned long addr,
0722                       const struct module *mod)
0723 {
0724     return false;
0725 }
0726 
0727 static inline bool within_module_init(unsigned long addr,
0728                       const struct module *mod)
0729 {
0730     return false;
0731 }
0732 
0733 static inline bool within_module(unsigned long addr, const struct module *mod)
0734 {
0735     return false;
0736 }
0737 
0738 /* Get/put a kernel symbol (calls should be symmetric) */
0739 #define symbol_get(x) ({ extern typeof(x) x __attribute__((weak,visibility("hidden"))); &(x); })
0740 #define symbol_put(x) do { } while (0)
0741 #define symbol_put_addr(x) do { } while (0)
0742 
0743 static inline void __module_get(struct module *module)
0744 {
0745 }
0746 
0747 static inline bool try_module_get(struct module *module)
0748 {
0749     return true;
0750 }
0751 
0752 static inline void module_put(struct module *module)
0753 {
0754 }
0755 
0756 #define module_name(mod) "kernel"
0757 
0758 /* For kallsyms to ask for address resolution.  NULL means not found. */
0759 static inline const char *module_address_lookup(unsigned long addr,
0760                       unsigned long *symbolsize,
0761                       unsigned long *offset,
0762                       char **modname,
0763                       const unsigned char **modbuildid,
0764                       char *namebuf)
0765 {
0766     return NULL;
0767 }
0768 
0769 static inline int lookup_module_symbol_name(unsigned long addr, char *symname)
0770 {
0771     return -ERANGE;
0772 }
0773 
0774 static inline int lookup_module_symbol_attrs(unsigned long addr, unsigned long *size, unsigned long *offset, char *modname, char *name)
0775 {
0776     return -ERANGE;
0777 }
0778 
0779 static inline int module_get_kallsym(unsigned int symnum, unsigned long *value,
0780                     char *type, char *name,
0781                     char *module_name, int *exported)
0782 {
0783     return -ERANGE;
0784 }
0785 
0786 static inline unsigned long module_kallsyms_lookup_name(const char *name)
0787 {
0788     return 0;
0789 }
0790 
0791 static inline int register_module_notifier(struct notifier_block *nb)
0792 {
0793     /* no events will happen anyway, so this can always succeed */
0794     return 0;
0795 }
0796 
0797 static inline int unregister_module_notifier(struct notifier_block *nb)
0798 {
0799     return 0;
0800 }
0801 
0802 #define module_put_and_kthread_exit(code) kthread_exit(code)
0803 
0804 static inline void print_modules(void)
0805 {
0806 }
0807 
0808 static inline bool module_requested_async_probing(struct module *module)
0809 {
0810     return false;
0811 }
0812 
0813 
0814 static inline void set_module_sig_enforced(void)
0815 {
0816 }
0817 
0818 /* Dereference module function descriptor */
0819 static inline
0820 void *dereference_module_function_descriptor(struct module *mod, void *ptr)
0821 {
0822     return ptr;
0823 }
0824 
0825 #endif /* CONFIG_MODULES */
0826 
0827 #ifdef CONFIG_SYSFS
0828 extern struct kset *module_kset;
0829 extern struct kobj_type module_ktype;
0830 extern int module_sysfs_initialized;
0831 #endif /* CONFIG_SYSFS */
0832 
0833 #define symbol_request(x) try_then_request_module(symbol_get(x), "symbol:" #x)
0834 
0835 /* BELOW HERE ALL THESE ARE OBSOLETE AND WILL VANISH */
0836 
0837 #define __MODULE_STRING(x) __stringify(x)
0838 
0839 #ifdef CONFIG_GENERIC_BUG
0840 void module_bug_finalize(const Elf_Ehdr *, const Elf_Shdr *,
0841              struct module *);
0842 void module_bug_cleanup(struct module *);
0843 
0844 #else   /* !CONFIG_GENERIC_BUG */
0845 
0846 static inline void module_bug_finalize(const Elf_Ehdr *hdr,
0847                     const Elf_Shdr *sechdrs,
0848                     struct module *mod)
0849 {
0850 }
0851 static inline void module_bug_cleanup(struct module *mod) {}
0852 #endif  /* CONFIG_GENERIC_BUG */
0853 
0854 #ifdef CONFIG_RETPOLINE
0855 extern bool retpoline_module_ok(bool has_retpoline);
0856 #else
0857 static inline bool retpoline_module_ok(bool has_retpoline)
0858 {
0859     return true;
0860 }
0861 #endif
0862 
0863 #ifdef CONFIG_MODULE_SIG
0864 bool is_module_sig_enforced(void);
0865 
0866 static inline bool module_sig_ok(struct module *module)
0867 {
0868     return module->sig_ok;
0869 }
0870 #else   /* !CONFIG_MODULE_SIG */
0871 static inline bool is_module_sig_enforced(void)
0872 {
0873     return false;
0874 }
0875 
0876 static inline bool module_sig_ok(struct module *module)
0877 {
0878     return true;
0879 }
0880 #endif  /* CONFIG_MODULE_SIG */
0881 
0882 int module_kallsyms_on_each_symbol(int (*fn)(void *, const char *,
0883                          struct module *, unsigned long),
0884                    void *data);
0885 
0886 #endif /* _LINUX_MODULE_H */