xref: /linux-6.15/include/linux/module.h (revision cbc0425d)
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 <[email protected]> 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 struct notifier_block;
277 
278 #ifdef CONFIG_MODULES
279 
280 extern int modules_disabled; /* for sysctl */
281 /* Get/put a kernel symbol (calls must be symmetric) */
282 void *__symbol_get(const char *symbol);
283 void *__symbol_get_gpl(const char *symbol);
284 #define symbol_get(x) ((typeof(&x))(__symbol_get(__stringify(x))))
285 
286 /* modules using other modules: kdb wants to see this. */
287 struct module_use {
288 	struct list_head source_list;
289 	struct list_head target_list;
290 	struct module *source, *target;
291 };
292 
293 enum module_state {
294 	MODULE_STATE_LIVE,	/* Normal state. */
295 	MODULE_STATE_COMING,	/* Full formed, running module_init. */
296 	MODULE_STATE_GOING,	/* Going away. */
297 	MODULE_STATE_UNFORMED,	/* Still setting it up. */
298 };
299 
300 struct mod_tree_node {
301 	struct module *mod;
302 	struct latch_tree_node node;
303 };
304 
305 struct module_layout {
306 	/* The actual code + data. */
307 	void *base;
308 	/* Total size. */
309 	unsigned int size;
310 	/* The size of the executable code.  */
311 	unsigned int text_size;
312 	/* Size of RO section of the module (text+rodata) */
313 	unsigned int ro_size;
314 	/* Size of RO after init section */
315 	unsigned int ro_after_init_size;
316 
317 #ifdef CONFIG_MODULES_TREE_LOOKUP
318 	struct mod_tree_node mtn;
319 #endif
320 };
321 
322 #ifdef CONFIG_MODULES_TREE_LOOKUP
323 /* Only touch one cacheline for common rbtree-for-core-layout case. */
324 #define __module_layout_align ____cacheline_aligned
325 #else
326 #define __module_layout_align
327 #endif
328 
329 struct mod_kallsyms {
330 	Elf_Sym *symtab;
331 	unsigned int num_symtab;
332 	char *strtab;
333 	char *typetab;
334 };
335 
336 #ifdef CONFIG_LIVEPATCH
337 struct klp_modinfo {
338 	Elf_Ehdr hdr;
339 	Elf_Shdr *sechdrs;
340 	char *secstrings;
341 	unsigned int symndx;
342 };
343 #endif
344 
345 struct module {
346 	enum module_state state;
347 
348 	/* Member of list of modules */
349 	struct list_head list;
350 
351 	/* Unique handle for this module */
352 	char name[MODULE_NAME_LEN];
353 
354 	/* Sysfs stuff. */
355 	struct module_kobject mkobj;
356 	struct module_attribute *modinfo_attrs;
357 	const char *version;
358 	const char *srcversion;
359 	struct kobject *holders_dir;
360 
361 	/* Exported symbols */
362 	const struct kernel_symbol *syms;
363 	const s32 *crcs;
364 	unsigned int num_syms;
365 
366 	/* Kernel parameters. */
367 #ifdef CONFIG_SYSFS
368 	struct mutex param_lock;
369 #endif
370 	struct kernel_param *kp;
371 	unsigned int num_kp;
372 
373 	/* GPL-only exported symbols. */
374 	unsigned int num_gpl_syms;
375 	const struct kernel_symbol *gpl_syms;
376 	const s32 *gpl_crcs;
377 
378 #ifdef CONFIG_UNUSED_SYMBOLS
379 	/* unused exported symbols. */
380 	const struct kernel_symbol *unused_syms;
381 	const s32 *unused_crcs;
382 	unsigned int num_unused_syms;
383 
384 	/* GPL-only, unused exported symbols. */
385 	unsigned int num_unused_gpl_syms;
386 	const struct kernel_symbol *unused_gpl_syms;
387 	const s32 *unused_gpl_crcs;
388 #endif
389 
390 #ifdef CONFIG_MODULE_SIG
391 	/* Signature was verified. */
392 	bool sig_ok;
393 #endif
394 
395 	bool async_probe_requested;
396 
397 	/* symbols that will be GPL-only in the near future. */
398 	const struct kernel_symbol *gpl_future_syms;
399 	const s32 *gpl_future_crcs;
400 	unsigned int num_gpl_future_syms;
401 
402 	/* Exception table */
403 	unsigned int num_exentries;
404 	struct exception_table_entry *extable;
405 
406 	/* Startup function. */
407 	int (*init)(void);
408 
409 	/* Core layout: rbtree is accessed frequently, so keep together. */
410 	struct module_layout core_layout __module_layout_align;
411 	struct module_layout init_layout;
412 
413 	/* Arch-specific module values */
414 	struct mod_arch_specific arch;
415 
416 	unsigned long taints;	/* same bits as kernel:taint_flags */
417 
418 #ifdef CONFIG_GENERIC_BUG
419 	/* Support for BUG */
420 	unsigned num_bugs;
421 	struct list_head bug_list;
422 	struct bug_entry *bug_table;
423 #endif
424 
425 #ifdef CONFIG_KALLSYMS
426 	/* Protected by RCU and/or module_mutex: use rcu_dereference() */
427 	struct mod_kallsyms *kallsyms;
428 	struct mod_kallsyms core_kallsyms;
429 
430 	/* Section attributes */
431 	struct module_sect_attrs *sect_attrs;
432 
433 	/* Notes attributes */
434 	struct module_notes_attrs *notes_attrs;
435 #endif
436 
437 	/* The command line arguments (may be mangled).  People like
438 	   keeping pointers to this stuff */
439 	char *args;
440 
441 #ifdef CONFIG_SMP
442 	/* Per-cpu data. */
443 	void __percpu *percpu;
444 	unsigned int percpu_size;
445 #endif
446 
447 #ifdef CONFIG_TRACEPOINTS
448 	unsigned int num_tracepoints;
449 	tracepoint_ptr_t *tracepoints_ptrs;
450 #endif
451 #ifdef CONFIG_TREE_SRCU
452 	unsigned int num_srcu_structs;
453 	struct srcu_struct **srcu_struct_ptrs;
454 #endif
455 #ifdef CONFIG_BPF_EVENTS
456 	unsigned int num_bpf_raw_events;
457 	struct bpf_raw_event_map *bpf_raw_events;
458 #endif
459 #ifdef CONFIG_JUMP_LABEL
460 	struct jump_entry *jump_entries;
461 	unsigned int num_jump_entries;
462 #endif
463 #ifdef CONFIG_TRACING
464 	unsigned int num_trace_bprintk_fmt;
465 	const char **trace_bprintk_fmt_start;
466 #endif
467 #ifdef CONFIG_EVENT_TRACING
468 	struct trace_event_call **trace_events;
469 	unsigned int num_trace_events;
470 	struct trace_eval_map **trace_evals;
471 	unsigned int num_trace_evals;
472 #endif
473 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
474 	unsigned int num_ftrace_callsites;
475 	unsigned long *ftrace_callsites;
476 #endif
477 
478 #ifdef CONFIG_LIVEPATCH
479 	bool klp; /* Is this a livepatch module? */
480 	bool klp_alive;
481 
482 	/* Elf information */
483 	struct klp_modinfo *klp_info;
484 #endif
485 
486 #ifdef CONFIG_MODULE_UNLOAD
487 	/* What modules depend on me? */
488 	struct list_head source_list;
489 	/* What modules do I depend on? */
490 	struct list_head target_list;
491 
492 	/* Destruction function. */
493 	void (*exit)(void);
494 
495 	atomic_t refcnt;
496 #endif
497 
498 #ifdef CONFIG_CONSTRUCTORS
499 	/* Constructor functions. */
500 	ctor_fn_t *ctors;
501 	unsigned int num_ctors;
502 #endif
503 
504 #ifdef CONFIG_FUNCTION_ERROR_INJECTION
505 	struct error_injection_entry *ei_funcs;
506 	unsigned int num_ei_funcs;
507 #endif
508 } ____cacheline_aligned __randomize_layout;
509 #ifndef MODULE_ARCH_INIT
510 #define MODULE_ARCH_INIT {}
511 #endif
512 
513 #ifndef HAVE_ARCH_KALLSYMS_SYMBOL_VALUE
514 static inline unsigned long kallsyms_symbol_value(const Elf_Sym *sym)
515 {
516 	return sym->st_value;
517 }
518 #endif
519 
520 extern struct mutex module_mutex;
521 
522 /* FIXME: It'd be nice to isolate modules during init, too, so they
523    aren't used before they (may) fail.  But presently too much code
524    (IDE & SCSI) require entry into the module during init.*/
525 static inline bool module_is_live(struct module *mod)
526 {
527 	return mod->state != MODULE_STATE_GOING;
528 }
529 
530 struct module *__module_text_address(unsigned long addr);
531 struct module *__module_address(unsigned long addr);
532 bool is_module_address(unsigned long addr);
533 bool __is_module_percpu_address(unsigned long addr, unsigned long *can_addr);
534 bool is_module_percpu_address(unsigned long addr);
535 bool is_module_text_address(unsigned long addr);
536 
537 static inline bool within_module_core(unsigned long addr,
538 				      const struct module *mod)
539 {
540 	return (unsigned long)mod->core_layout.base <= addr &&
541 	       addr < (unsigned long)mod->core_layout.base + mod->core_layout.size;
542 }
543 
544 static inline bool within_module_init(unsigned long addr,
545 				      const struct module *mod)
546 {
547 	return (unsigned long)mod->init_layout.base <= addr &&
548 	       addr < (unsigned long)mod->init_layout.base + mod->init_layout.size;
549 }
550 
551 static inline bool within_module(unsigned long addr, const struct module *mod)
552 {
553 	return within_module_init(addr, mod) || within_module_core(addr, mod);
554 }
555 
556 /* Search for module by name: must hold module_mutex. */
557 struct module *find_module(const char *name);
558 
559 struct symsearch {
560 	const struct kernel_symbol *start, *stop;
561 	const s32 *crcs;
562 	enum {
563 		NOT_GPL_ONLY,
564 		GPL_ONLY,
565 		WILL_BE_GPL_ONLY,
566 	} licence;
567 	bool unused;
568 };
569 
570 /*
571  * Search for an exported symbol by name.
572  *
573  * Must be called with module_mutex held or preemption disabled.
574  */
575 const struct kernel_symbol *find_symbol(const char *name,
576 					struct module **owner,
577 					const s32 **crc,
578 					bool gplok,
579 					bool warn);
580 
581 /*
582  * Walk the exported symbol table
583  *
584  * Must be called with module_mutex held or preemption disabled.
585  */
586 bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
587 				    struct module *owner,
588 				    void *data), void *data);
589 
590 /* Returns 0 and fills in value, defined and namebuf, or -ERANGE if
591    symnum out of range. */
592 int module_get_kallsym(unsigned int symnum, unsigned long *value, char *type,
593 			char *name, char *module_name, int *exported);
594 
595 /* Look for this name: can be of form module:name. */
596 unsigned long module_kallsyms_lookup_name(const char *name);
597 
598 int module_kallsyms_on_each_symbol(int (*fn)(void *, const char *,
599 					     struct module *, unsigned long),
600 				   void *data);
601 
602 extern void __noreturn __module_put_and_exit(struct module *mod,
603 			long code);
604 #define module_put_and_exit(code) __module_put_and_exit(THIS_MODULE, code)
605 
606 #ifdef CONFIG_MODULE_UNLOAD
607 int module_refcount(struct module *mod);
608 void __symbol_put(const char *symbol);
609 #define symbol_put(x) __symbol_put(__stringify(x))
610 void symbol_put_addr(void *addr);
611 
612 /* Sometimes we know we already have a refcount, and it's easier not
613    to handle the error case (which only happens with rmmod --wait). */
614 extern void __module_get(struct module *module);
615 
616 /* This is the Right Way to get a module: if it fails, it's being removed,
617  * so pretend it's not there. */
618 extern bool try_module_get(struct module *module);
619 
620 extern void module_put(struct module *module);
621 
622 #else /*!CONFIG_MODULE_UNLOAD*/
623 static inline bool try_module_get(struct module *module)
624 {
625 	return !module || module_is_live(module);
626 }
627 static inline void module_put(struct module *module)
628 {
629 }
630 static inline void __module_get(struct module *module)
631 {
632 }
633 #define symbol_put(x) do { } while (0)
634 #define symbol_put_addr(p) do { } while (0)
635 
636 #endif /* CONFIG_MODULE_UNLOAD */
637 int ref_module(struct module *a, struct module *b);
638 
639 /* This is a #define so the string doesn't get put in every .o file */
640 #define module_name(mod)			\
641 ({						\
642 	struct module *__mod = (mod);		\
643 	__mod ? __mod->name : "kernel";		\
644 })
645 
646 /* Dereference module function descriptor */
647 void *dereference_module_function_descriptor(struct module *mod, void *ptr);
648 
649 /* For kallsyms to ask for address resolution.  namebuf should be at
650  * least KSYM_NAME_LEN long: a pointer to namebuf is returned if
651  * found, otherwise NULL. */
652 const char *module_address_lookup(unsigned long addr,
653 			    unsigned long *symbolsize,
654 			    unsigned long *offset,
655 			    char **modname,
656 			    char *namebuf);
657 int lookup_module_symbol_name(unsigned long addr, char *symname);
658 int lookup_module_symbol_attrs(unsigned long addr, unsigned long *size, unsigned long *offset, char *modname, char *name);
659 
660 int register_module_notifier(struct notifier_block *nb);
661 int unregister_module_notifier(struct notifier_block *nb);
662 
663 extern void print_modules(void);
664 
665 static inline bool module_requested_async_probing(struct module *module)
666 {
667 	return module && module->async_probe_requested;
668 }
669 
670 #ifdef CONFIG_LIVEPATCH
671 static inline bool is_livepatch_module(struct module *mod)
672 {
673 	return mod->klp;
674 }
675 #else /* !CONFIG_LIVEPATCH */
676 static inline bool is_livepatch_module(struct module *mod)
677 {
678 	return false;
679 }
680 #endif /* CONFIG_LIVEPATCH */
681 
682 bool is_module_sig_enforced(void);
683 void set_module_sig_enforced(void);
684 
685 #else /* !CONFIG_MODULES... */
686 
687 static inline struct module *__module_address(unsigned long addr)
688 {
689 	return NULL;
690 }
691 
692 static inline struct module *__module_text_address(unsigned long addr)
693 {
694 	return NULL;
695 }
696 
697 static inline bool is_module_address(unsigned long addr)
698 {
699 	return false;
700 }
701 
702 static inline bool is_module_percpu_address(unsigned long addr)
703 {
704 	return false;
705 }
706 
707 static inline bool __is_module_percpu_address(unsigned long addr, unsigned long *can_addr)
708 {
709 	return false;
710 }
711 
712 static inline bool is_module_text_address(unsigned long addr)
713 {
714 	return false;
715 }
716 
717 static inline bool within_module_core(unsigned long addr,
718 				      const struct module *mod)
719 {
720 	return false;
721 }
722 
723 static inline bool within_module_init(unsigned long addr,
724 				      const struct module *mod)
725 {
726 	return false;
727 }
728 
729 static inline bool within_module(unsigned long addr, const struct module *mod)
730 {
731 	return false;
732 }
733 
734 /* Get/put a kernel symbol (calls should be symmetric) */
735 #define symbol_get(x) ({ extern typeof(x) x __attribute__((weak)); &(x); })
736 #define symbol_put(x) do { } while (0)
737 #define symbol_put_addr(x) do { } while (0)
738 
739 static inline void __module_get(struct module *module)
740 {
741 }
742 
743 static inline bool try_module_get(struct module *module)
744 {
745 	return true;
746 }
747 
748 static inline void module_put(struct module *module)
749 {
750 }
751 
752 #define module_name(mod) "kernel"
753 
754 /* For kallsyms to ask for address resolution.  NULL means not found. */
755 static inline const char *module_address_lookup(unsigned long addr,
756 					  unsigned long *symbolsize,
757 					  unsigned long *offset,
758 					  char **modname,
759 					  char *namebuf)
760 {
761 	return NULL;
762 }
763 
764 static inline int lookup_module_symbol_name(unsigned long addr, char *symname)
765 {
766 	return -ERANGE;
767 }
768 
769 static inline int lookup_module_symbol_attrs(unsigned long addr, unsigned long *size, unsigned long *offset, char *modname, char *name)
770 {
771 	return -ERANGE;
772 }
773 
774 static inline int module_get_kallsym(unsigned int symnum, unsigned long *value,
775 					char *type, char *name,
776 					char *module_name, int *exported)
777 {
778 	return -ERANGE;
779 }
780 
781 static inline unsigned long module_kallsyms_lookup_name(const char *name)
782 {
783 	return 0;
784 }
785 
786 static inline int module_kallsyms_on_each_symbol(int (*fn)(void *, const char *,
787 							   struct module *,
788 							   unsigned long),
789 						 void *data)
790 {
791 	return 0;
792 }
793 
794 static inline int register_module_notifier(struct notifier_block *nb)
795 {
796 	/* no events will happen anyway, so this can always succeed */
797 	return 0;
798 }
799 
800 static inline int unregister_module_notifier(struct notifier_block *nb)
801 {
802 	return 0;
803 }
804 
805 #define module_put_and_exit(code) do_exit(code)
806 
807 static inline void print_modules(void)
808 {
809 }
810 
811 static inline bool module_requested_async_probing(struct module *module)
812 {
813 	return false;
814 }
815 
816 static inline bool is_module_sig_enforced(void)
817 {
818 	return false;
819 }
820 
821 static inline void set_module_sig_enforced(void)
822 {
823 }
824 
825 /* Dereference module function descriptor */
826 static inline
827 void *dereference_module_function_descriptor(struct module *mod, void *ptr)
828 {
829 	return ptr;
830 }
831 
832 #endif /* CONFIG_MODULES */
833 
834 #ifdef CONFIG_SYSFS
835 extern struct kset *module_kset;
836 extern struct kobj_type module_ktype;
837 extern int module_sysfs_initialized;
838 #endif /* CONFIG_SYSFS */
839 
840 #define symbol_request(x) try_then_request_module(symbol_get(x), "symbol:" #x)
841 
842 /* BELOW HERE ALL THESE ARE OBSOLETE AND WILL VANISH */
843 
844 #define __MODULE_STRING(x) __stringify(x)
845 
846 #ifdef CONFIG_STRICT_MODULE_RWX
847 extern void set_all_modules_text_rw(void);
848 extern void set_all_modules_text_ro(void);
849 extern void module_enable_ro(const struct module *mod, bool after_init);
850 extern void module_disable_ro(const struct module *mod);
851 #else
852 static inline void set_all_modules_text_rw(void) { }
853 static inline void set_all_modules_text_ro(void) { }
854 static inline void module_enable_ro(const struct module *mod, bool after_init) { }
855 static inline void module_disable_ro(const struct module *mod) { }
856 #endif
857 
858 #ifdef CONFIG_GENERIC_BUG
859 void module_bug_finalize(const Elf_Ehdr *, const Elf_Shdr *,
860 			 struct module *);
861 void module_bug_cleanup(struct module *);
862 
863 #else	/* !CONFIG_GENERIC_BUG */
864 
865 static inline void module_bug_finalize(const Elf_Ehdr *hdr,
866 					const Elf_Shdr *sechdrs,
867 					struct module *mod)
868 {
869 }
870 static inline void module_bug_cleanup(struct module *mod) {}
871 #endif	/* CONFIG_GENERIC_BUG */
872 
873 #ifdef CONFIG_RETPOLINE
874 extern bool retpoline_module_ok(bool has_retpoline);
875 #else
876 static inline bool retpoline_module_ok(bool has_retpoline)
877 {
878 	return true;
879 }
880 #endif
881 
882 #ifdef CONFIG_MODULE_SIG
883 static inline bool module_sig_ok(struct module *module)
884 {
885 	return module->sig_ok;
886 }
887 #else	/* !CONFIG_MODULE_SIG */
888 static inline bool module_sig_ok(struct module *module)
889 {
890 	return true;
891 }
892 #endif	/* CONFIG_MODULE_SIG */
893 
894 #endif /* _LINUX_MODULE_H */
895