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