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