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