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