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