GNU Linux-libre 5.4.241-gnu1
[releases.git] / include / linux / module.h
1 #ifndef _LINUX_MODULE_H
2 #define _LINUX_MODULE_H
3 /*
4  * Dynamic loading of modules into the kernel.
5  *
6  * Rewritten by Richard Henderson <rth@tamu.edu> Dec 1996
7  * Rewritten again by Rusty Russell, 2002
8  */
9 #include <linux/list.h>
10 #include <linux/stat.h>
11 #include <linux/compiler.h>
12 #include <linux/cache.h>
13 #include <linux/kmod.h>
14 #include <linux/init.h>
15 #include <linux/elf.h>
16 #include <linux/stringify.h>
17 #include <linux/kobject.h>
18 #include <linux/moduleparam.h>
19 #include <linux/jump_label.h>
20 #include <linux/export.h>
21 #include <linux/rbtree_latch.h>
22 #include <linux/error-injection.h>
23 #include <linux/tracepoint-defs.h>
24 #include <linux/srcu.h>
25
26 #include <linux/percpu.h>
27 #include <asm/module.h>
28
29 /* Not Yet Implemented */
30 #define MODULE_SUPPORTED_DEVICE(name)
31
32 #define MODULE_NAME_LEN MAX_PARAM_PREFIX_LEN
33
34 struct modversion_info {
35         unsigned long crc;
36         char name[MODULE_NAME_LEN];
37 };
38
39 struct module;
40 struct exception_table_entry;
41
42 struct module_kobject {
43         struct kobject kobj;
44         struct module *mod;
45         struct kobject *drivers_dir;
46         struct module_param_attrs *mp;
47         struct completion *kobj_completion;
48 } __randomize_layout;
49
50 struct module_attribute {
51         struct attribute attr;
52         ssize_t (*show)(struct module_attribute *, struct module_kobject *,
53                         char *);
54         ssize_t (*store)(struct module_attribute *, struct module_kobject *,
55                          const char *, size_t count);
56         void (*setup)(struct module *, const char *);
57         int (*test)(struct module *);
58         void (*free)(struct module *);
59 };
60
61 struct module_version_attribute {
62         struct module_attribute mattr;
63         const char *module_name;
64         const char *version;
65 } __attribute__ ((__aligned__(sizeof(void *))));
66
67 extern ssize_t __modver_version_show(struct module_attribute *,
68                                      struct module_kobject *, char *);
69
70 extern struct module_attribute module_uevent;
71
72 /* These are either module local, or the kernel's dummy ones. */
73 extern int init_module(void);
74 extern void cleanup_module(void);
75
76 #ifndef MODULE
77 /**
78  * module_init() - driver initialization entry point
79  * @x: function to be run at kernel boot time or module insertion
80  *
81  * module_init() will either be called during do_initcalls() (if
82  * builtin) or at module insertion time (if a module).  There can only
83  * be one per module.
84  */
85 #define module_init(x)  __initcall(x);
86
87 /**
88  * module_exit() - driver exit entry point
89  * @x: function to be run when driver is removed
90  *
91  * module_exit() will wrap the driver clean-up code
92  * with cleanup_module() when used with rmmod when
93  * the driver is a module.  If the driver is statically
94  * compiled into the kernel, module_exit() has no effect.
95  * There can only be one per module.
96  */
97 #define module_exit(x)  __exitcall(x);
98
99 #else /* MODULE */
100
101 /*
102  * In most cases loadable modules do not need custom
103  * initcall levels. There are still some valid cases where
104  * a driver may be needed early if built in, and does not
105  * matter when built as a loadable module. Like bus
106  * snooping debug drivers.
107  */
108 #define early_initcall(fn)              module_init(fn)
109 #define core_initcall(fn)               module_init(fn)
110 #define core_initcall_sync(fn)          module_init(fn)
111 #define postcore_initcall(fn)           module_init(fn)
112 #define postcore_initcall_sync(fn)      module_init(fn)
113 #define arch_initcall(fn)               module_init(fn)
114 #define subsys_initcall(fn)             module_init(fn)
115 #define subsys_initcall_sync(fn)        module_init(fn)
116 #define fs_initcall(fn)                 module_init(fn)
117 #define fs_initcall_sync(fn)            module_init(fn)
118 #define rootfs_initcall(fn)             module_init(fn)
119 #define device_initcall(fn)             module_init(fn)
120 #define device_initcall_sync(fn)        module_init(fn)
121 #define late_initcall(fn)               module_init(fn)
122 #define late_initcall_sync(fn)          module_init(fn)
123
124 #define console_initcall(fn)            module_init(fn)
125
126 /* Each module must use one module_init(). */
127 #define module_init(initfn)                                     \
128         static inline initcall_t __maybe_unused __inittest(void)                \
129         { return initfn; }                                      \
130         int init_module(void) __copy(initfn) __attribute__((alias(#initfn)));
131
132 /* This is only required if you want to be unloadable. */
133 #define module_exit(exitfn)                                     \
134         static inline exitcall_t __maybe_unused __exittest(void)                \
135         { return exitfn; }                                      \
136         void cleanup_module(void) __copy(exitfn) __attribute__((alias(#exitfn)));
137
138 #endif
139
140 /* This means "can be init if no module support, otherwise module load
141    may call it." */
142 #ifdef CONFIG_MODULES
143 #define __init_or_module
144 #define __initdata_or_module
145 #define __initconst_or_module
146 #define __INIT_OR_MODULE        .text
147 #define __INITDATA_OR_MODULE    .data
148 #define __INITRODATA_OR_MODULE  .section ".rodata","a",%progbits
149 #else
150 #define __init_or_module __init
151 #define __initdata_or_module __initdata
152 #define __initconst_or_module __initconst
153 #define __INIT_OR_MODULE __INIT
154 #define __INITDATA_OR_MODULE __INITDATA
155 #define __INITRODATA_OR_MODULE __INITRODATA
156 #endif /*CONFIG_MODULES*/
157
158 /* Generic info of form tag = "info" */
159 #define MODULE_INFO(tag, info) __MODULE_INFO(tag, tag, info)
160
161 /* For userspace: you can also call me... */
162 #define MODULE_ALIAS(_alias) MODULE_INFO(alias, _alias)
163
164 /* Soft module dependencies. See man modprobe.d for details.
165  * Example: MODULE_SOFTDEP("pre: module-foo module-bar post: module-baz")
166  */
167 #define MODULE_SOFTDEP(_softdep) MODULE_INFO(softdep, _softdep)
168
169 /*
170  * The following license idents are currently accepted as indicating free
171  * software modules
172  *
173  *      "GPL"                           [GNU Public License v2]
174  *      "GPL v2"                        [GNU Public License v2]
175  *      "GPL and additional rights"     [GNU Public License v2 rights and more]
176  *      "Dual BSD/GPL"                  [GNU Public License v2
177  *                                       or BSD license choice]
178  *      "Dual MIT/GPL"                  [GNU Public License v2
179  *                                       or MIT license choice]
180  *      "Dual MPL/GPL"                  [GNU Public License v2
181  *                                       or Mozilla license choice]
182  *
183  * The following other idents are available
184  *
185  *      "Proprietary"                   [Non free products]
186  *
187  * Both "GPL v2" and "GPL" (the latter also in dual licensed strings) are
188  * merely stating that the module is licensed under the GPL v2, but are not
189  * telling whether "GPL v2 only" or "GPL v2 or later". The reason why there
190  * are two variants is a historic and failed attempt to convey more
191  * information in the MODULE_LICENSE string. For module loading the
192  * "only/or later" distinction is completely irrelevant and does neither
193  * replace the proper license identifiers in the corresponding source file
194  * nor amends them in any way. The sole purpose is to make the
195  * 'Proprietary' flagging work and to refuse to bind symbols which are
196  * exported with EXPORT_SYMBOL_GPL when a non free module is loaded.
197  *
198  * In the same way "BSD" is not a clear license information. It merely
199  * states, that the module is licensed under one of the compatible BSD
200  * license variants. The detailed and correct license information is again
201  * to be found in the corresponding source files.
202  *
203  * There are dual licensed components, but when running with Linux it is the
204  * GPL that is relevant so this is a non issue. Similarly LGPL linked with GPL
205  * is a GPL combined work.
206  *
207  * This exists for several reasons
208  * 1.   So modinfo can show license info for users wanting to vet their setup
209  *      is free
210  * 2.   So the community can ignore bug reports including proprietary modules
211  * 3.   So vendors can do likewise based on their own policies
212  */
213 #define MODULE_LICENSE(_license) MODULE_INFO(license, _license)
214
215 /*
216  * Author(s), use "Name <email>" or just "Name", for multiple
217  * authors use multiple MODULE_AUTHOR() statements/lines.
218  */
219 #define MODULE_AUTHOR(_author) MODULE_INFO(author, _author)
220
221 /* What your module does. */
222 #define MODULE_DESCRIPTION(_description) MODULE_INFO(description, _description)
223
224 #ifdef MODULE
225 /* Creates an alias so file2alias.c can find device table. */
226 #define MODULE_DEVICE_TABLE(type, name)                                 \
227 extern typeof(name) __mod_##type##__##name##_device_table               \
228   __attribute__ ((unused, alias(__stringify(name))))
229 #else  /* !MODULE */
230 #define MODULE_DEVICE_TABLE(type, name)
231 #endif
232
233 /* Version of form [<epoch>:]<version>[-<extra-version>].
234  * Or for CVS/RCS ID version, everything but the number is stripped.
235  * <epoch>: A (small) unsigned integer which allows you to start versions
236  * anew. If not mentioned, it's zero.  eg. "2:1.0" is after
237  * "1:2.0".
238
239  * <version>: The <version> may contain only alphanumerics and the
240  * character `.'.  Ordered by numeric sort for numeric parts,
241  * ascii sort for ascii parts (as per RPM or DEB algorithm).
242
243  * <extraversion>: Like <version>, but inserted for local
244  * customizations, eg "rh3" or "rusty1".
245
246  * Using this automatically adds a checksum of the .c files and the
247  * local headers in "srcversion".
248  */
249
250 #if defined(MODULE) || !defined(CONFIG_SYSFS)
251 #define MODULE_VERSION(_version) MODULE_INFO(version, _version)
252 #else
253 #define MODULE_VERSION(_version)                                        \
254         MODULE_INFO(version, _version);                                 \
255         static struct module_version_attribute ___modver_attr = {       \
256                 .mattr  = {                                             \
257                         .attr   = {                                     \
258                                 .name   = "version",                    \
259                                 .mode   = S_IRUGO,                      \
260                         },                                              \
261                         .show   = __modver_version_show,                \
262                 },                                                      \
263                 .module_name    = KBUILD_MODNAME,                       \
264                 .version        = _version,                             \
265         };                                                              \
266         static const struct module_version_attribute                    \
267         __used __attribute__ ((__section__ ("__modver")))               \
268         * __moduleparam_const __modver_attr = &___modver_attr
269 #endif
270
271 /* Optional firmware file (or files) needed by the module
272  * format is simply firmware file name.  Multiple firmware
273  * files require multiple MODULE_FIRMWARE() specifiers */
274 #define MODULE_FIRMWARE(_firmware) MODULE_INFO(firmware, _firmware)
275
276 #define MODULE_IMPORT_NS(ns) MODULE_INFO(import_ns, #ns)
277
278 struct notifier_block;
279
280 #ifdef CONFIG_MODULES
281
282 extern int modules_disabled; /* for sysctl */
283 /* Get/put a kernel symbol (calls must be symmetric) */
284 void *__symbol_get(const char *symbol);
285 void *__symbol_get_gpl(const char *symbol);
286 #define symbol_get(x) ((typeof(&x))(__symbol_get(__stringify(x))))
287
288 /* modules using other modules: kdb wants to see this. */
289 struct module_use {
290         struct list_head source_list;
291         struct list_head target_list;
292         struct module *source, *target;
293 };
294
295 enum module_state {
296         MODULE_STATE_LIVE,      /* Normal state. */
297         MODULE_STATE_COMING,    /* Full formed, running module_init. */
298         MODULE_STATE_GOING,     /* Going away. */
299         MODULE_STATE_UNFORMED,  /* Still setting it up. */
300 };
301
302 struct mod_tree_node {
303         struct module *mod;
304         struct latch_tree_node node;
305 };
306
307 struct module_layout {
308         /* The actual code + data. */
309         void *base;
310         /* Total size. */
311         unsigned int size;
312         /* The size of the executable code.  */
313         unsigned int text_size;
314         /* Size of RO section of the module (text+rodata) */
315         unsigned int ro_size;
316         /* Size of RO after init section */
317         unsigned int ro_after_init_size;
318
319 #ifdef CONFIG_MODULES_TREE_LOOKUP
320         struct mod_tree_node mtn;
321 #endif
322 };
323
324 #ifdef CONFIG_MODULES_TREE_LOOKUP
325 /* Only touch one cacheline for common rbtree-for-core-layout case. */
326 #define __module_layout_align ____cacheline_aligned
327 #else
328 #define __module_layout_align
329 #endif
330
331 struct mod_kallsyms {
332         Elf_Sym *symtab;
333         unsigned int num_symtab;
334         char *strtab;
335         char *typetab;
336 };
337
338 #ifdef CONFIG_LIVEPATCH
339 struct klp_modinfo {
340         Elf_Ehdr hdr;
341         Elf_Shdr *sechdrs;
342         char *secstrings;
343         unsigned int symndx;
344 };
345 #endif
346
347 struct module {
348         enum module_state state;
349
350         /* Member of list of modules */
351         struct list_head list;
352
353         /* Unique handle for this module */
354         char name[MODULE_NAME_LEN];
355
356         /* Sysfs stuff. */
357         struct module_kobject mkobj;
358         struct module_attribute *modinfo_attrs;
359         const char *version;
360         const char *srcversion;
361         struct kobject *holders_dir;
362
363         /* Exported symbols */
364         const struct kernel_symbol *syms;
365         const s32 *crcs;
366         unsigned int num_syms;
367
368         /* Kernel parameters. */
369 #ifdef CONFIG_SYSFS
370         struct mutex param_lock;
371 #endif
372         struct kernel_param *kp;
373         unsigned int num_kp;
374
375         /* GPL-only exported symbols. */
376         unsigned int num_gpl_syms;
377         const struct kernel_symbol *gpl_syms;
378         const s32 *gpl_crcs;
379         bool using_gplonly_symbols;
380
381 #ifdef CONFIG_UNUSED_SYMBOLS
382         /* unused exported symbols. */
383         const struct kernel_symbol *unused_syms;
384         const s32 *unused_crcs;
385         unsigned int num_unused_syms;
386
387         /* GPL-only, unused exported symbols. */
388         unsigned int num_unused_gpl_syms;
389         const struct kernel_symbol *unused_gpl_syms;
390         const s32 *unused_gpl_crcs;
391 #endif
392
393 #ifdef CONFIG_MODULE_SIG
394         /* Signature was verified. */
395         bool sig_ok;
396 #endif
397
398         bool async_probe_requested;
399
400         /* symbols that will be GPL-only in the near future. */
401         const struct kernel_symbol *gpl_future_syms;
402         const s32 *gpl_future_crcs;
403         unsigned int num_gpl_future_syms;
404
405         /* Exception table */
406         unsigned int num_exentries;
407         struct exception_table_entry *extable;
408
409         /* Startup function. */
410         int (*init)(void);
411
412         /* Core layout: rbtree is accessed frequently, so keep together. */
413         struct module_layout core_layout __module_layout_align;
414         struct module_layout init_layout;
415
416         /* Arch-specific module values */
417         struct mod_arch_specific arch;
418
419         unsigned long taints;   /* same bits as kernel:taint_flags */
420
421 #ifdef CONFIG_GENERIC_BUG
422         /* Support for BUG */
423         unsigned num_bugs;
424         struct list_head bug_list;
425         struct bug_entry *bug_table;
426 #endif
427
428 #ifdef CONFIG_KALLSYMS
429         /* Protected by RCU and/or module_mutex: use rcu_dereference() */
430         struct mod_kallsyms *kallsyms;
431         struct mod_kallsyms core_kallsyms;
432
433         /* Section attributes */
434         struct module_sect_attrs *sect_attrs;
435
436         /* Notes attributes */
437         struct module_notes_attrs *notes_attrs;
438 #endif
439
440         /* The command line arguments (may be mangled).  People like
441            keeping pointers to this stuff */
442         char *args;
443
444 #ifdef CONFIG_SMP
445         /* Per-cpu data. */
446         void __percpu *percpu;
447         unsigned int percpu_size;
448 #endif
449
450 #ifdef CONFIG_TRACEPOINTS
451         unsigned int num_tracepoints;
452         tracepoint_ptr_t *tracepoints_ptrs;
453 #endif
454 #ifdef CONFIG_TREE_SRCU
455         unsigned int num_srcu_structs;
456         struct srcu_struct **srcu_struct_ptrs;
457 #endif
458 #ifdef CONFIG_BPF_EVENTS
459         unsigned int num_bpf_raw_events;
460         struct bpf_raw_event_map *bpf_raw_events;
461 #endif
462 #ifdef CONFIG_JUMP_LABEL
463         struct jump_entry *jump_entries;
464         unsigned int num_jump_entries;
465 #endif
466 #ifdef CONFIG_TRACING
467         unsigned int num_trace_bprintk_fmt;
468         const char **trace_bprintk_fmt_start;
469 #endif
470 #ifdef CONFIG_EVENT_TRACING
471         struct trace_event_call **trace_events;
472         unsigned int num_trace_events;
473         struct trace_eval_map **trace_evals;
474         unsigned int num_trace_evals;
475 #endif
476 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
477         unsigned int num_ftrace_callsites;
478         unsigned long *ftrace_callsites;
479 #endif
480
481 #ifdef CONFIG_LIVEPATCH
482         bool klp; /* Is this a livepatch module? */
483         bool klp_alive;
484
485         /* Elf information */
486         struct klp_modinfo *klp_info;
487 #endif
488
489 #ifdef CONFIG_MODULE_UNLOAD
490         /* What modules depend on me? */
491         struct list_head source_list;
492         /* What modules do I depend on? */
493         struct list_head target_list;
494
495         /* Destruction function. */
496         void (*exit)(void);
497
498         atomic_t refcnt;
499 #endif
500
501 #ifdef CONFIG_CONSTRUCTORS
502         /* Constructor functions. */
503         ctor_fn_t *ctors;
504         unsigned int num_ctors;
505 #endif
506
507 #ifdef CONFIG_FUNCTION_ERROR_INJECTION
508         struct error_injection_entry *ei_funcs;
509         unsigned int num_ei_funcs;
510 #endif
511 } ____cacheline_aligned __randomize_layout;
512 #ifndef MODULE_ARCH_INIT
513 #define MODULE_ARCH_INIT {}
514 #endif
515
516 #ifndef HAVE_ARCH_KALLSYMS_SYMBOL_VALUE
517 static inline unsigned long kallsyms_symbol_value(const Elf_Sym *sym)
518 {
519         return sym->st_value;
520 }
521 #endif
522
523 extern struct mutex module_mutex;
524
525 /* FIXME: It'd be nice to isolate modules during init, too, so they
526    aren't used before they (may) fail.  But presently too much code
527    (IDE & SCSI) require entry into the module during init.*/
528 static inline bool module_is_live(struct module *mod)
529 {
530         return mod->state != MODULE_STATE_GOING;
531 }
532
533 struct module *__module_text_address(unsigned long addr);
534 struct module *__module_address(unsigned long addr);
535 bool is_module_address(unsigned long addr);
536 bool __is_module_percpu_address(unsigned long addr, unsigned long *can_addr);
537 bool is_module_percpu_address(unsigned long addr);
538 bool is_module_text_address(unsigned long addr);
539
540 static inline bool within_module_core(unsigned long addr,
541                                       const struct module *mod)
542 {
543         return (unsigned long)mod->core_layout.base <= addr &&
544                addr < (unsigned long)mod->core_layout.base + mod->core_layout.size;
545 }
546
547 static inline bool within_module_init(unsigned long addr,
548                                       const struct module *mod)
549 {
550         return (unsigned long)mod->init_layout.base <= addr &&
551                addr < (unsigned long)mod->init_layout.base + mod->init_layout.size;
552 }
553
554 static inline bool within_module(unsigned long addr, const struct module *mod)
555 {
556         return within_module_init(addr, mod) || within_module_core(addr, mod);
557 }
558
559 /* Search for module by name: must hold module_mutex. */
560 struct module *find_module(const char *name);
561
562 struct symsearch {
563         const struct kernel_symbol *start, *stop;
564         const s32 *crcs;
565         enum mod_license {
566                 NOT_GPL_ONLY,
567                 GPL_ONLY,
568                 WILL_BE_GPL_ONLY,
569         } license;
570         bool unused;
571 };
572
573 /* Returns 0 and fills in value, defined and namebuf, or -ERANGE if
574    symnum out of range. */
575 int module_get_kallsym(unsigned int symnum, unsigned long *value, char *type,
576                         char *name, char *module_name, int *exported);
577
578 /* Look for this name: can be of form module:name. */
579 unsigned long module_kallsyms_lookup_name(const char *name);
580
581 int module_kallsyms_on_each_symbol(int (*fn)(void *, const char *,
582                                              struct module *, unsigned long),
583                                    void *data);
584
585 extern void __noreturn __module_put_and_exit(struct module *mod,
586                         long code);
587 #define module_put_and_exit(code) __module_put_and_exit(THIS_MODULE, code)
588
589 #ifdef CONFIG_MODULE_UNLOAD
590 int module_refcount(struct module *mod);
591 void __symbol_put(const char *symbol);
592 #define symbol_put(x) __symbol_put(__stringify(x))
593 void symbol_put_addr(void *addr);
594
595 /* Sometimes we know we already have a refcount, and it's easier not
596    to handle the error case (which only happens with rmmod --wait). */
597 extern void __module_get(struct module *module);
598
599 /* This is the Right Way to get a module: if it fails, it's being removed,
600  * so pretend it's not there. */
601 extern bool try_module_get(struct module *module);
602
603 extern void module_put(struct module *module);
604
605 #else /*!CONFIG_MODULE_UNLOAD*/
606 static inline bool try_module_get(struct module *module)
607 {
608         return !module || module_is_live(module);
609 }
610 static inline void module_put(struct module *module)
611 {
612 }
613 static inline void __module_get(struct module *module)
614 {
615 }
616 #define symbol_put(x) do { } while (0)
617 #define symbol_put_addr(p) do { } while (0)
618
619 #endif /* CONFIG_MODULE_UNLOAD */
620
621 /* This is a #define so the string doesn't get put in every .o file */
622 #define module_name(mod)                        \
623 ({                                              \
624         struct module *__mod = (mod);           \
625         __mod ? __mod->name : "kernel";         \
626 })
627
628 /* Dereference module function descriptor */
629 void *dereference_module_function_descriptor(struct module *mod, void *ptr);
630
631 /* For kallsyms to ask for address resolution.  namebuf should be at
632  * least KSYM_NAME_LEN long: a pointer to namebuf is returned if
633  * found, otherwise NULL. */
634 const char *module_address_lookup(unsigned long addr,
635                             unsigned long *symbolsize,
636                             unsigned long *offset,
637                             char **modname,
638                             char *namebuf);
639 int lookup_module_symbol_name(unsigned long addr, char *symname);
640 int lookup_module_symbol_attrs(unsigned long addr, unsigned long *size, unsigned long *offset, char *modname, char *name);
641
642 int register_module_notifier(struct notifier_block *nb);
643 int unregister_module_notifier(struct notifier_block *nb);
644
645 extern void print_modules(void);
646
647 static inline bool module_requested_async_probing(struct module *module)
648 {
649         return module && module->async_probe_requested;
650 }
651
652 #ifdef CONFIG_LIVEPATCH
653 static inline bool is_livepatch_module(struct module *mod)
654 {
655         return mod->klp;
656 }
657 #else /* !CONFIG_LIVEPATCH */
658 static inline bool is_livepatch_module(struct module *mod)
659 {
660         return false;
661 }
662 #endif /* CONFIG_LIVEPATCH */
663
664 bool is_module_sig_enforced(void);
665 void set_module_sig_enforced(void);
666
667 #else /* !CONFIG_MODULES... */
668
669 static inline struct module *__module_address(unsigned long addr)
670 {
671         return NULL;
672 }
673
674 static inline struct module *__module_text_address(unsigned long addr)
675 {
676         return NULL;
677 }
678
679 static inline bool is_module_address(unsigned long addr)
680 {
681         return false;
682 }
683
684 static inline bool is_module_percpu_address(unsigned long addr)
685 {
686         return false;
687 }
688
689 static inline bool __is_module_percpu_address(unsigned long addr, unsigned long *can_addr)
690 {
691         return false;
692 }
693
694 static inline bool is_module_text_address(unsigned long addr)
695 {
696         return false;
697 }
698
699 static inline bool within_module_core(unsigned long addr,
700                                       const struct module *mod)
701 {
702         return false;
703 }
704
705 static inline bool within_module_init(unsigned long addr,
706                                       const struct module *mod)
707 {
708         return false;
709 }
710
711 static inline bool within_module(unsigned long addr, const struct module *mod)
712 {
713         return false;
714 }
715
716 /* Get/put a kernel symbol (calls should be symmetric) */
717 #define symbol_get(x) ({ extern typeof(x) x __attribute__((weak)); &(x); })
718 #define symbol_put(x) do { } while (0)
719 #define symbol_put_addr(x) do { } while (0)
720
721 static inline void __module_get(struct module *module)
722 {
723 }
724
725 static inline bool try_module_get(struct module *module)
726 {
727         return true;
728 }
729
730 static inline void module_put(struct module *module)
731 {
732 }
733
734 #define module_name(mod) "kernel"
735
736 /* For kallsyms to ask for address resolution.  NULL means not found. */
737 static inline const char *module_address_lookup(unsigned long addr,
738                                           unsigned long *symbolsize,
739                                           unsigned long *offset,
740                                           char **modname,
741                                           char *namebuf)
742 {
743         return NULL;
744 }
745
746 static inline int lookup_module_symbol_name(unsigned long addr, char *symname)
747 {
748         return -ERANGE;
749 }
750
751 static inline int lookup_module_symbol_attrs(unsigned long addr, unsigned long *size, unsigned long *offset, char *modname, char *name)
752 {
753         return -ERANGE;
754 }
755
756 static inline int module_get_kallsym(unsigned int symnum, unsigned long *value,
757                                         char *type, char *name,
758                                         char *module_name, int *exported)
759 {
760         return -ERANGE;
761 }
762
763 static inline unsigned long module_kallsyms_lookup_name(const char *name)
764 {
765         return 0;
766 }
767
768 static inline int module_kallsyms_on_each_symbol(int (*fn)(void *, const char *,
769                                                            struct module *,
770                                                            unsigned long),
771                                                  void *data)
772 {
773         return 0;
774 }
775
776 static inline int register_module_notifier(struct notifier_block *nb)
777 {
778         /* no events will happen anyway, so this can always succeed */
779         return 0;
780 }
781
782 static inline int unregister_module_notifier(struct notifier_block *nb)
783 {
784         return 0;
785 }
786
787 #define module_put_and_exit(code) do_exit(code)
788
789 static inline void print_modules(void)
790 {
791 }
792
793 static inline bool module_requested_async_probing(struct module *module)
794 {
795         return false;
796 }
797
798 static inline bool is_module_sig_enforced(void)
799 {
800         return false;
801 }
802
803 static inline void set_module_sig_enforced(void)
804 {
805 }
806
807 /* Dereference module function descriptor */
808 static inline
809 void *dereference_module_function_descriptor(struct module *mod, void *ptr)
810 {
811         return ptr;
812 }
813
814 #endif /* CONFIG_MODULES */
815
816 #ifdef CONFIG_SYSFS
817 extern struct kset *module_kset;
818 extern struct kobj_type module_ktype;
819 extern int module_sysfs_initialized;
820 #endif /* CONFIG_SYSFS */
821
822 #define symbol_request(x) try_then_request_module(symbol_get(x), "symbol:" #x)
823
824 /* BELOW HERE ALL THESE ARE OBSOLETE AND WILL VANISH */
825
826 #define __MODULE_STRING(x) __stringify(x)
827
828 #ifdef CONFIG_STRICT_MODULE_RWX
829 extern void set_all_modules_text_rw(void);
830 extern void set_all_modules_text_ro(void);
831 extern void module_enable_ro(const struct module *mod, bool after_init);
832 extern void module_disable_ro(const struct module *mod);
833 #else
834 static inline void set_all_modules_text_rw(void) { }
835 static inline void set_all_modules_text_ro(void) { }
836 static inline void module_enable_ro(const struct module *mod, bool after_init) { }
837 static inline void module_disable_ro(const struct module *mod) { }
838 #endif
839
840 #ifdef CONFIG_GENERIC_BUG
841 void module_bug_finalize(const Elf_Ehdr *, const Elf_Shdr *,
842                          struct module *);
843 void module_bug_cleanup(struct module *);
844
845 #else   /* !CONFIG_GENERIC_BUG */
846
847 static inline void module_bug_finalize(const Elf_Ehdr *hdr,
848                                         const Elf_Shdr *sechdrs,
849                                         struct module *mod)
850 {
851 }
852 static inline void module_bug_cleanup(struct module *mod) {}
853 #endif  /* CONFIG_GENERIC_BUG */
854
855 #ifdef CONFIG_RETPOLINE
856 extern bool retpoline_module_ok(bool has_retpoline);
857 #else
858 static inline bool retpoline_module_ok(bool has_retpoline)
859 {
860         return true;
861 }
862 #endif
863
864 #ifdef CONFIG_MODULE_SIG
865 static inline bool module_sig_ok(struct module *module)
866 {
867         return module->sig_ok;
868 }
869 #else   /* !CONFIG_MODULE_SIG */
870 static inline bool module_sig_ok(struct module *module)
871 {
872         return true;
873 }
874 #endif  /* CONFIG_MODULE_SIG */
875
876 #endif /* _LINUX_MODULE_H */