Commit | Line | Data |
---|---|---|
1da177e4 LT |
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 | */ | |
1da177e4 LT |
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/elf.h> | |
15 | #include <linux/stringify.h> | |
16 | #include <linux/kobject.h> | |
17 | #include <linux/moduleparam.h> | |
97e1c18e | 18 | #include <linux/tracepoint.h> |
1da177e4 | 19 | |
e1783a24 | 20 | #include <linux/percpu.h> |
1da177e4 LT |
21 | #include <asm/module.h> |
22 | ||
7ead8b83 LZ |
23 | #include <trace/events/module.h> |
24 | ||
1da177e4 LT |
25 | /* Not Yet Implemented */ |
26 | #define MODULE_SUPPORTED_DEVICE(name) | |
27 | ||
9e1b9b80 AJ |
28 | /* Some toolchains use a `_' prefix for all user symbols. */ |
29 | #ifdef CONFIG_SYMBOL_PREFIX | |
30 | #define MODULE_SYMBOL_PREFIX CONFIG_SYMBOL_PREFIX | |
31 | #else | |
1da177e4 LT |
32 | #define MODULE_SYMBOL_PREFIX "" |
33 | #endif | |
34 | ||
730b69d2 | 35 | #define MODULE_NAME_LEN MAX_PARAM_PREFIX_LEN |
1da177e4 LT |
36 | |
37 | struct kernel_symbol | |
38 | { | |
39 | unsigned long value; | |
40 | const char *name; | |
41 | }; | |
42 | ||
43 | struct modversion_info | |
44 | { | |
45 | unsigned long crc; | |
46 | char name[MODULE_NAME_LEN]; | |
47 | }; | |
48 | ||
49 | struct module; | |
50 | ||
51 | struct module_attribute { | |
52 | struct attribute attr; | |
53 | ssize_t (*show)(struct module_attribute *, struct module *, char *); | |
54 | ssize_t (*store)(struct module_attribute *, struct module *, | |
55 | const char *, size_t count); | |
c988d2b2 MD |
56 | void (*setup)(struct module *, const char *); |
57 | int (*test)(struct module *); | |
58 | void (*free)(struct module *); | |
1da177e4 LT |
59 | }; |
60 | ||
e94965ed DT |
61 | struct module_version_attribute { |
62 | struct module_attribute mattr; | |
63 | const char *module_name; | |
64 | const char *version; | |
98562ad8 | 65 | } __attribute__ ((__aligned__(sizeof(void *)))); |
e94965ed | 66 | |
9b73a584 DT |
67 | extern ssize_t __modver_version_show(struct module_attribute *, |
68 | struct module *, char *); | |
69 | ||
1da177e4 LT |
70 | struct module_kobject |
71 | { | |
72 | struct kobject kobj; | |
73 | struct module *mod; | |
f30c53a8 | 74 | struct kobject *drivers_dir; |
9b473de8 | 75 | struct module_param_attrs *mp; |
1da177e4 LT |
76 | }; |
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 | /* Archs provide a method of finding the correct exception table. */ | |
83 | struct exception_table_entry; | |
84 | ||
85 | const struct exception_table_entry * | |
86 | search_extable(const struct exception_table_entry *first, | |
87 | const struct exception_table_entry *last, | |
88 | unsigned long value); | |
89 | void sort_extable(struct exception_table_entry *start, | |
90 | struct exception_table_entry *finish); | |
91 | void sort_main_extable(void); | |
ad6561df | 92 | void trim_init_extable(struct module *m); |
1da177e4 | 93 | |
1da177e4 LT |
94 | #ifdef MODULE |
95 | #define MODULE_GENERIC_TABLE(gtype,name) \ | |
96 | extern const struct gtype##_id __mod_##gtype##_table \ | |
97 | __attribute__ ((unused, alias(__stringify(name)))) | |
98 | ||
99 | extern struct module __this_module; | |
100 | #define THIS_MODULE (&__this_module) | |
101 | #else /* !MODULE */ | |
102 | #define MODULE_GENERIC_TABLE(gtype,name) | |
103 | #define THIS_MODULE ((struct module *)0) | |
104 | #endif | |
105 | ||
106 | /* Generic info of form tag = "info" */ | |
107 | #define MODULE_INFO(tag, info) __MODULE_INFO(tag, tag, info) | |
108 | ||
109 | /* For userspace: you can also call me... */ | |
110 | #define MODULE_ALIAS(_alias) MODULE_INFO(alias, _alias) | |
111 | ||
112 | /* | |
113 | * The following license idents are currently accepted as indicating free | |
114 | * software modules | |
115 | * | |
116 | * "GPL" [GNU Public License v2 or later] | |
117 | * "GPL v2" [GNU Public License v2] | |
118 | * "GPL and additional rights" [GNU Public License v2 rights and more] | |
119 | * "Dual BSD/GPL" [GNU Public License v2 | |
120 | * or BSD license choice] | |
8d27e908 XVP |
121 | * "Dual MIT/GPL" [GNU Public License v2 |
122 | * or MIT license choice] | |
1da177e4 LT |
123 | * "Dual MPL/GPL" [GNU Public License v2 |
124 | * or Mozilla license choice] | |
125 | * | |
126 | * The following other idents are available | |
127 | * | |
128 | * "Proprietary" [Non free products] | |
129 | * | |
130 | * There are dual licensed components, but when running with Linux it is the | |
131 | * GPL that is relevant so this is a non issue. Similarly LGPL linked with GPL | |
132 | * is a GPL combined work. | |
133 | * | |
134 | * This exists for several reasons | |
135 | * 1. So modinfo can show license info for users wanting to vet their setup | |
136 | * is free | |
137 | * 2. So the community can ignore bug reports including proprietary modules | |
138 | * 3. So vendors can do likewise based on their own policies | |
139 | */ | |
140 | #define MODULE_LICENSE(_license) MODULE_INFO(license, _license) | |
141 | ||
1d7015ca JB |
142 | /* |
143 | * Author(s), use "Name <email>" or just "Name", for multiple | |
144 | * authors use multiple MODULE_AUTHOR() statements/lines. | |
145 | */ | |
1da177e4 LT |
146 | #define MODULE_AUTHOR(_author) MODULE_INFO(author, _author) |
147 | ||
148 | /* What your module does. */ | |
149 | #define MODULE_DESCRIPTION(_description) MODULE_INFO(description, _description) | |
150 | ||
151 | /* One for each parameter, describing how to use it. Some files do | |
152 | multiple of these per line, so can't just use MODULE_INFO. */ | |
153 | #define MODULE_PARM_DESC(_parm, desc) \ | |
154 | __MODULE_INFO(parm, _parm, #_parm ":" desc) | |
155 | ||
156 | #define MODULE_DEVICE_TABLE(type,name) \ | |
157 | MODULE_GENERIC_TABLE(type##_device,name) | |
158 | ||
159 | /* Version of form [<epoch>:]<version>[-<extra-version>]. | |
160 | Or for CVS/RCS ID version, everything but the number is stripped. | |
161 | <epoch>: A (small) unsigned integer which allows you to start versions | |
162 | anew. If not mentioned, it's zero. eg. "2:1.0" is after | |
163 | "1:2.0". | |
164 | <version>: The <version> may contain only alphanumerics and the | |
165 | character `.'. Ordered by numeric sort for numeric parts, | |
166 | ascii sort for ascii parts (as per RPM or DEB algorithm). | |
167 | <extraversion>: Like <version>, but inserted for local | |
168 | customizations, eg "rh3" or "rusty1". | |
169 | ||
170 | Using this automatically adds a checksum of the .c files and the | |
171 | local headers in "srcversion". | |
172 | */ | |
e94965ed | 173 | |
3b90a5b2 | 174 | #if defined(MODULE) || !defined(CONFIG_SYSFS) |
1da177e4 | 175 | #define MODULE_VERSION(_version) MODULE_INFO(version, _version) |
e94965ed DT |
176 | #else |
177 | #define MODULE_VERSION(_version) \ | |
b4bc8428 | 178 | static struct module_version_attribute ___modver_attr = { \ |
e94965ed DT |
179 | .mattr = { \ |
180 | .attr = { \ | |
181 | .name = "version", \ | |
182 | .mode = S_IRUGO, \ | |
183 | }, \ | |
184 | .show = __modver_version_show, \ | |
185 | }, \ | |
186 | .module_name = KBUILD_MODNAME, \ | |
187 | .version = _version, \ | |
b4bc8428 DT |
188 | }; \ |
189 | static const struct module_version_attribute \ | |
190 | __used __attribute__ ((__section__ ("__modver"))) \ | |
191 | * __moduleparam_const __modver_attr = &___modver_attr | |
e94965ed | 192 | #endif |
1da177e4 | 193 | |
187afbed JM |
194 | /* Optional firmware file (or files) needed by the module |
195 | * format is simply firmware file name. Multiple firmware | |
196 | * files require multiple MODULE_FIRMWARE() specifiers */ | |
197 | #define MODULE_FIRMWARE(_firmware) MODULE_INFO(firmware, _firmware) | |
198 | ||
1da177e4 LT |
199 | /* Given an address, look for it in the exception tables */ |
200 | const struct exception_table_entry *search_exception_tables(unsigned long add); | |
201 | ||
202 | struct notifier_block; | |
203 | ||
204 | #ifdef CONFIG_MODULES | |
205 | ||
5ed10910 | 206 | extern int modules_disabled; /* for sysctl */ |
1da177e4 LT |
207 | /* Get/put a kernel symbol (calls must be symmetric) */ |
208 | void *__symbol_get(const char *symbol); | |
209 | void *__symbol_get_gpl(const char *symbol); | |
210 | #define symbol_get(x) ((typeof(&x))(__symbol_get(MODULE_SYMBOL_PREFIX #x))) | |
211 | ||
c8e21ced RR |
212 | /* modules using other modules: kdb wants to see this. */ |
213 | struct module_use { | |
214 | struct list_head source_list; | |
215 | struct list_head target_list; | |
216 | struct module *source, *target; | |
217 | }; | |
218 | ||
1da177e4 LT |
219 | #ifndef __GENKSYMS__ |
220 | #ifdef CONFIG_MODVERSIONS | |
221 | /* Mark the CRC weak since genksyms apparently decides not to | |
222 | * generate a checksums for some symbols */ | |
223 | #define __CRC_SYMBOL(sym, sec) \ | |
224 | extern void *__crc_##sym __attribute__((weak)); \ | |
225 | static const unsigned long __kcrctab_##sym \ | |
3ff6eecc | 226 | __used \ |
f02e8a65 | 227 | __attribute__((section("___kcrctab" sec "+" #sym), unused)) \ |
1da177e4 LT |
228 | = (unsigned long) &__crc_##sym; |
229 | #else | |
230 | #define __CRC_SYMBOL(sym, sec) | |
231 | #endif | |
232 | ||
233 | /* For every exported symbol, place a struct in the __ksymtab section */ | |
234 | #define __EXPORT_SYMBOL(sym, sec) \ | |
a1a8feed | 235 | extern typeof(sym) sym; \ |
1da177e4 LT |
236 | __CRC_SYMBOL(sym, sec) \ |
237 | static const char __kstrtab_##sym[] \ | |
ea01e798 | 238 | __attribute__((section("__ksymtab_strings"), aligned(1))) \ |
1da177e4 LT |
239 | = MODULE_SYMBOL_PREFIX #sym; \ |
240 | static const struct kernel_symbol __ksymtab_##sym \ | |
3ff6eecc | 241 | __used \ |
f02e8a65 | 242 | __attribute__((section("___ksymtab" sec "+" #sym), unused)) \ |
1da177e4 LT |
243 | = { (unsigned long)&sym, __kstrtab_##sym } |
244 | ||
245 | #define EXPORT_SYMBOL(sym) \ | |
246 | __EXPORT_SYMBOL(sym, "") | |
247 | ||
248 | #define EXPORT_SYMBOL_GPL(sym) \ | |
249 | __EXPORT_SYMBOL(sym, "_gpl") | |
250 | ||
9f28bb7e GKH |
251 | #define EXPORT_SYMBOL_GPL_FUTURE(sym) \ |
252 | __EXPORT_SYMBOL(sym, "_gpl_future") | |
253 | ||
f71d20e9 AV |
254 | |
255 | #ifdef CONFIG_UNUSED_SYMBOLS | |
256 | #define EXPORT_UNUSED_SYMBOL(sym) __EXPORT_SYMBOL(sym, "_unused") | |
257 | #define EXPORT_UNUSED_SYMBOL_GPL(sym) __EXPORT_SYMBOL(sym, "_unused_gpl") | |
258 | #else | |
259 | #define EXPORT_UNUSED_SYMBOL(sym) | |
260 | #define EXPORT_UNUSED_SYMBOL_GPL(sym) | |
261 | #endif | |
262 | ||
1da177e4 LT |
263 | #endif |
264 | ||
1da177e4 LT |
265 | enum module_state |
266 | { | |
267 | MODULE_STATE_LIVE, | |
268 | MODULE_STATE_COMING, | |
269 | MODULE_STATE_GOING, | |
270 | }; | |
271 | ||
1da177e4 LT |
272 | struct module |
273 | { | |
274 | enum module_state state; | |
275 | ||
276 | /* Member of list of modules */ | |
277 | struct list_head list; | |
278 | ||
279 | /* Unique handle for this module */ | |
280 | char name[MODULE_NAME_LEN]; | |
281 | ||
282 | /* Sysfs stuff. */ | |
283 | struct module_kobject mkobj; | |
03e88ae1 | 284 | struct module_attribute *modinfo_attrs; |
c988d2b2 MD |
285 | const char *version; |
286 | const char *srcversion; | |
270a6c4c | 287 | struct kobject *holders_dir; |
1da177e4 LT |
288 | |
289 | /* Exported symbols */ | |
290 | const struct kernel_symbol *syms; | |
1da177e4 | 291 | const unsigned long *crcs; |
af540689 | 292 | unsigned int num_syms; |
1da177e4 | 293 | |
e180a6b7 RR |
294 | /* Kernel parameters. */ |
295 | struct kernel_param *kp; | |
296 | unsigned int num_kp; | |
297 | ||
1da177e4 | 298 | /* GPL-only exported symbols. */ |
1da177e4 | 299 | unsigned int num_gpl_syms; |
af540689 | 300 | const struct kernel_symbol *gpl_syms; |
1da177e4 LT |
301 | const unsigned long *gpl_crcs; |
302 | ||
f7f5b675 | 303 | #ifdef CONFIG_UNUSED_SYMBOLS |
f71d20e9 AV |
304 | /* unused exported symbols. */ |
305 | const struct kernel_symbol *unused_syms; | |
f71d20e9 | 306 | const unsigned long *unused_crcs; |
af540689 RK |
307 | unsigned int num_unused_syms; |
308 | ||
f71d20e9 | 309 | /* GPL-only, unused exported symbols. */ |
f71d20e9 | 310 | unsigned int num_unused_gpl_syms; |
af540689 | 311 | const struct kernel_symbol *unused_gpl_syms; |
f71d20e9 | 312 | const unsigned long *unused_gpl_crcs; |
f7f5b675 | 313 | #endif |
f71d20e9 | 314 | |
9f28bb7e GKH |
315 | /* symbols that will be GPL-only in the near future. */ |
316 | const struct kernel_symbol *gpl_future_syms; | |
9f28bb7e | 317 | const unsigned long *gpl_future_crcs; |
af540689 | 318 | unsigned int num_gpl_future_syms; |
9f28bb7e | 319 | |
1da177e4 LT |
320 | /* Exception table */ |
321 | unsigned int num_exentries; | |
5e458cc0 | 322 | struct exception_table_entry *extable; |
1da177e4 LT |
323 | |
324 | /* Startup function. */ | |
325 | int (*init)(void); | |
326 | ||
327 | /* If this is non-NULL, vfree after init() returns */ | |
328 | void *module_init; | |
329 | ||
330 | /* Here is the actual code + data, vfree'd on unload. */ | |
331 | void *module_core; | |
332 | ||
333 | /* Here are the sizes of the init and core sections */ | |
2f0f2a33 | 334 | unsigned int init_size, core_size; |
1da177e4 LT |
335 | |
336 | /* The size of the executable code in each section. */ | |
2f0f2a33 | 337 | unsigned int init_text_size, core_text_size; |
1da177e4 | 338 | |
84e1c6bb | 339 | /* Size of RO sections of the module (text+rodata) */ |
340 | unsigned int init_ro_size, core_ro_size; | |
341 | ||
1da177e4 LT |
342 | /* Arch-specific module values */ |
343 | struct mod_arch_specific arch; | |
344 | ||
2bc2d61a RD |
345 | unsigned int taints; /* same bits as kernel:tainted */ |
346 | ||
7664c5a1 JF |
347 | #ifdef CONFIG_GENERIC_BUG |
348 | /* Support for BUG */ | |
af540689 | 349 | unsigned num_bugs; |
7664c5a1 JF |
350 | struct list_head bug_list; |
351 | struct bug_entry *bug_table; | |
1da177e4 LT |
352 | #endif |
353 | ||
354 | #ifdef CONFIG_KALLSYMS | |
4a496226 JB |
355 | /* |
356 | * We keep the symbol and string tables for kallsyms. | |
357 | * The core_* fields below are temporary, loader-only (they | |
358 | * could really be discarded after module init). | |
359 | */ | |
360 | Elf_Sym *symtab, *core_symtab; | |
361 | unsigned int num_symtab, core_num_syms; | |
554bdfe5 | 362 | char *strtab, *core_strtab; |
1da177e4 LT |
363 | |
364 | /* Section attributes */ | |
365 | struct module_sect_attrs *sect_attrs; | |
6d760133 RM |
366 | |
367 | /* Notes attributes */ | |
368 | struct module_notes_attrs *notes_attrs; | |
1da177e4 LT |
369 | #endif |
370 | ||
a288bd65 RK |
371 | /* The command line arguments (may be mangled). People like |
372 | keeping pointers to this stuff */ | |
373 | char *args; | |
374 | ||
259354de | 375 | #ifdef CONFIG_SMP |
1da177e4 | 376 | /* Per-cpu data. */ |
259354de TH |
377 | void __percpu *percpu; |
378 | unsigned int percpu_size; | |
379 | #endif | |
1da177e4 | 380 | |
97e1c18e | 381 | #ifdef CONFIG_TRACEPOINTS |
97e1c18e | 382 | unsigned int num_tracepoints; |
a288bd65 | 383 | struct tracepoint * const *tracepoints_ptrs; |
97e1c18e | 384 | #endif |
bf5438fc JB |
385 | #ifdef HAVE_JUMP_LABEL |
386 | struct jump_entry *jump_entries; | |
387 | unsigned int num_jump_entries; | |
388 | #endif | |
769b0441 | 389 | #ifdef CONFIG_TRACING |
1ba28e02 | 390 | unsigned int num_trace_bprintk_fmt; |
a288bd65 | 391 | const char **trace_bprintk_fmt_start; |
1ba28e02 | 392 | #endif |
6d723736 | 393 | #ifdef CONFIG_EVENT_TRACING |
e4a9ea5e | 394 | struct ftrace_event_call **trace_events; |
6d723736 SR |
395 | unsigned int num_trace_events; |
396 | #endif | |
93eb677d | 397 | #ifdef CONFIG_FTRACE_MCOUNT_RECORD |
93eb677d | 398 | unsigned int num_ftrace_callsites; |
a288bd65 | 399 | unsigned long *ftrace_callsites; |
93eb677d | 400 | #endif |
1ba28e02 | 401 | |
af540689 RK |
402 | #ifdef CONFIG_MODULE_UNLOAD |
403 | /* What modules depend on me? */ | |
2c02dfe7 LT |
404 | struct list_head source_list; |
405 | /* What modules do I depend on? */ | |
406 | struct list_head target_list; | |
af540689 RK |
407 | |
408 | /* Who is waiting for us to be unloaded */ | |
409 | struct task_struct *waiter; | |
410 | ||
411 | /* Destruction function. */ | |
412 | void (*exit)(void); | |
413 | ||
e1783a24 | 414 | struct module_ref { |
5fbfb18d NP |
415 | unsigned int incs; |
416 | unsigned int decs; | |
43cf38eb | 417 | } __percpu *refptr; |
af540689 | 418 | #endif |
b99b87f7 PO |
419 | |
420 | #ifdef CONFIG_CONSTRUCTORS | |
421 | /* Constructor functions. */ | |
422 | ctor_fn_t *ctors; | |
423 | unsigned int num_ctors; | |
424 | #endif | |
1da177e4 | 425 | }; |
e61a1c1c RZ |
426 | #ifndef MODULE_ARCH_INIT |
427 | #define MODULE_ARCH_INIT {} | |
428 | #endif | |
1da177e4 | 429 | |
c6b37801 TA |
430 | extern struct mutex module_mutex; |
431 | ||
1da177e4 LT |
432 | /* FIXME: It'd be nice to isolate modules during init, too, so they |
433 | aren't used before they (may) fail. But presently too much code | |
434 | (IDE & SCSI) require entry into the module during init.*/ | |
435 | static inline int module_is_live(struct module *mod) | |
436 | { | |
437 | return mod->state != MODULE_STATE_GOING; | |
438 | } | |
439 | ||
1da177e4 | 440 | struct module *__module_text_address(unsigned long addr); |
e610499e RR |
441 | struct module *__module_address(unsigned long addr); |
442 | bool is_module_address(unsigned long addr); | |
10fad5e4 | 443 | bool is_module_percpu_address(unsigned long addr); |
e610499e | 444 | bool is_module_text_address(unsigned long addr); |
1da177e4 | 445 | |
a06f6211 MH |
446 | static inline int within_module_core(unsigned long addr, struct module *mod) |
447 | { | |
448 | return (unsigned long)mod->module_core <= addr && | |
449 | addr < (unsigned long)mod->module_core + mod->core_size; | |
450 | } | |
451 | ||
452 | static inline int within_module_init(unsigned long addr, struct module *mod) | |
453 | { | |
454 | return (unsigned long)mod->module_init <= addr && | |
455 | addr < (unsigned long)mod->module_init + mod->init_size; | |
456 | } | |
457 | ||
c6b37801 TA |
458 | /* Search for module by name: must hold module_mutex. */ |
459 | struct module *find_module(const char *name); | |
460 | ||
461 | struct symsearch { | |
462 | const struct kernel_symbol *start, *stop; | |
463 | const unsigned long *crcs; | |
464 | enum { | |
465 | NOT_GPL_ONLY, | |
466 | GPL_ONLY, | |
467 | WILL_BE_GPL_ONLY, | |
468 | } licence; | |
469 | bool unused; | |
470 | }; | |
471 | ||
472 | /* Search for an exported symbol by name. */ | |
473 | const struct kernel_symbol *find_symbol(const char *name, | |
474 | struct module **owner, | |
475 | const unsigned long **crc, | |
476 | bool gplok, | |
477 | bool warn); | |
478 | ||
479 | /* Walk the exported symbol table */ | |
de4d8d53 RR |
480 | bool each_symbol_section(bool (*fn)(const struct symsearch *arr, |
481 | struct module *owner, | |
482 | void *data), void *data); | |
c6b37801 | 483 | |
ea07890a | 484 | /* Returns 0 and fills in value, defined and namebuf, or -ERANGE if |
1da177e4 | 485 | symnum out of range. */ |
ea07890a AD |
486 | int module_get_kallsym(unsigned int symnum, unsigned long *value, char *type, |
487 | char *name, char *module_name, int *exported); | |
1da177e4 LT |
488 | |
489 | /* Look for this name: can be of form module:name. */ | |
490 | unsigned long module_kallsyms_lookup_name(const char *name); | |
491 | ||
75a66614 AK |
492 | int module_kallsyms_on_each_symbol(int (*fn)(void *, const char *, |
493 | struct module *, unsigned long), | |
494 | void *data); | |
495 | ||
1da177e4 LT |
496 | extern void __module_put_and_exit(struct module *mod, long code) |
497 | __attribute__((noreturn)); | |
498 | #define module_put_and_exit(code) __module_put_and_exit(THIS_MODULE, code); | |
499 | ||
500 | #ifdef CONFIG_MODULE_UNLOAD | |
501 | unsigned int module_refcount(struct module *mod); | |
502 | void __symbol_put(const char *symbol); | |
503 | #define symbol_put(x) __symbol_put(MODULE_SYMBOL_PREFIX #x) | |
504 | void symbol_put_addr(void *addr); | |
505 | ||
506 | /* Sometimes we know we already have a refcount, and it's easier not | |
507 | to handle the error case (which only happens with rmmod --wait). */ | |
508 | static inline void __module_get(struct module *module) | |
509 | { | |
510 | if (module) { | |
e1783a24 | 511 | preempt_disable(); |
5fbfb18d | 512 | __this_cpu_inc(module->refptr->incs); |
ae832d1e | 513 | trace_module_get(module, _THIS_IP_); |
e1783a24 | 514 | preempt_enable(); |
1da177e4 LT |
515 | } |
516 | } | |
517 | ||
518 | static inline int try_module_get(struct module *module) | |
519 | { | |
520 | int ret = 1; | |
521 | ||
522 | if (module) { | |
e1783a24 CL |
523 | preempt_disable(); |
524 | ||
7ead8b83 | 525 | if (likely(module_is_live(module))) { |
5fbfb18d | 526 | __this_cpu_inc(module->refptr->incs); |
ae832d1e | 527 | trace_module_get(module, _THIS_IP_); |
5fbfb18d | 528 | } else |
1da177e4 | 529 | ret = 0; |
e1783a24 CL |
530 | |
531 | preempt_enable(); | |
1da177e4 LT |
532 | } |
533 | return ret; | |
534 | } | |
535 | ||
f6a57033 | 536 | extern void module_put(struct module *module); |
1da177e4 LT |
537 | |
538 | #else /*!CONFIG_MODULE_UNLOAD*/ | |
539 | static inline int try_module_get(struct module *module) | |
540 | { | |
541 | return !module || module_is_live(module); | |
542 | } | |
543 | static inline void module_put(struct module *module) | |
544 | { | |
545 | } | |
546 | static inline void __module_get(struct module *module) | |
547 | { | |
548 | } | |
549 | #define symbol_put(x) do { } while(0) | |
550 | #define symbol_put_addr(p) do { } while(0) | |
551 | ||
552 | #endif /* CONFIG_MODULE_UNLOAD */ | |
dfd62d1d | 553 | int ref_module(struct module *a, struct module *b); |
1da177e4 LT |
554 | |
555 | /* This is a #define so the string doesn't get put in every .o file */ | |
556 | #define module_name(mod) \ | |
557 | ({ \ | |
558 | struct module *__mod = (mod); \ | |
559 | __mod ? __mod->name : "kernel"; \ | |
560 | }) | |
561 | ||
6dd06c9f RR |
562 | /* For kallsyms to ask for address resolution. namebuf should be at |
563 | * least KSYM_NAME_LEN long: a pointer to namebuf is returned if | |
564 | * found, otherwise NULL. */ | |
92dfc9dc | 565 | const char *module_address_lookup(unsigned long addr, |
6dd06c9f RR |
566 | unsigned long *symbolsize, |
567 | unsigned long *offset, | |
568 | char **modname, | |
569 | char *namebuf); | |
9d65cb4a | 570 | int lookup_module_symbol_name(unsigned long addr, char *symname); |
a5c43dae | 571 | int lookup_module_symbol_attrs(unsigned long addr, unsigned long *size, unsigned long *offset, char *modname, char *name); |
1da177e4 LT |
572 | |
573 | /* For extable.c to search modules' exception tables. */ | |
574 | const struct exception_table_entry *search_module_extables(unsigned long addr); | |
575 | ||
576 | int register_module_notifier(struct notifier_block * nb); | |
577 | int unregister_module_notifier(struct notifier_block * nb); | |
578 | ||
579 | extern void print_modules(void); | |
580 | ||
97e1c18e MD |
581 | extern void module_update_tracepoints(void); |
582 | extern int module_get_iter_tracepoints(struct tracepoint_iter *iter); | |
583 | ||
1da177e4 LT |
584 | #else /* !CONFIG_MODULES... */ |
585 | #define EXPORT_SYMBOL(sym) | |
586 | #define EXPORT_SYMBOL_GPL(sym) | |
9f28bb7e | 587 | #define EXPORT_SYMBOL_GPL_FUTURE(sym) |
f71d20e9 AV |
588 | #define EXPORT_UNUSED_SYMBOL(sym) |
589 | #define EXPORT_UNUSED_SYMBOL_GPL(sym) | |
1da177e4 LT |
590 | |
591 | /* Given an address, look for it in the exception tables. */ | |
592 | static inline const struct exception_table_entry * | |
593 | search_module_extables(unsigned long addr) | |
594 | { | |
595 | return NULL; | |
596 | } | |
597 | ||
e610499e RR |
598 | static inline struct module *__module_address(unsigned long addr) |
599 | { | |
600 | return NULL; | |
601 | } | |
602 | ||
1da177e4 LT |
603 | static inline struct module *__module_text_address(unsigned long addr) |
604 | { | |
605 | return NULL; | |
606 | } | |
607 | ||
e610499e RR |
608 | static inline bool is_module_address(unsigned long addr) |
609 | { | |
610 | return false; | |
611 | } | |
612 | ||
d5e50daf RD |
613 | static inline bool is_module_percpu_address(unsigned long addr) |
614 | { | |
615 | return false; | |
616 | } | |
617 | ||
e610499e | 618 | static inline bool is_module_text_address(unsigned long addr) |
4d435f9d | 619 | { |
e610499e | 620 | return false; |
4d435f9d IM |
621 | } |
622 | ||
1da177e4 LT |
623 | /* Get/put a kernel symbol (calls should be symmetric) */ |
624 | #define symbol_get(x) ({ extern typeof(x) x __attribute__((weak)); &(x); }) | |
625 | #define symbol_put(x) do { } while(0) | |
626 | #define symbol_put_addr(x) do { } while(0) | |
627 | ||
628 | static inline void __module_get(struct module *module) | |
629 | { | |
630 | } | |
631 | ||
632 | static inline int try_module_get(struct module *module) | |
633 | { | |
634 | return 1; | |
635 | } | |
636 | ||
637 | static inline void module_put(struct module *module) | |
638 | { | |
639 | } | |
640 | ||
641 | #define module_name(mod) "kernel" | |
642 | ||
1da177e4 | 643 | /* For kallsyms to ask for address resolution. NULL means not found. */ |
92dfc9dc | 644 | static inline const char *module_address_lookup(unsigned long addr, |
6dd06c9f RR |
645 | unsigned long *symbolsize, |
646 | unsigned long *offset, | |
647 | char **modname, | |
648 | char *namebuf) | |
1da177e4 LT |
649 | { |
650 | return NULL; | |
651 | } | |
652 | ||
9d65cb4a AD |
653 | static inline int lookup_module_symbol_name(unsigned long addr, char *symname) |
654 | { | |
655 | return -ERANGE; | |
656 | } | |
657 | ||
a5c43dae AD |
658 | static inline int lookup_module_symbol_attrs(unsigned long addr, unsigned long *size, unsigned long *offset, char *modname, char *name) |
659 | { | |
660 | return -ERANGE; | |
661 | } | |
662 | ||
ea07890a AD |
663 | static inline int module_get_kallsym(unsigned int symnum, unsigned long *value, |
664 | char *type, char *name, | |
665 | char *module_name, int *exported) | |
1da177e4 | 666 | { |
ea07890a | 667 | return -ERANGE; |
1da177e4 LT |
668 | } |
669 | ||
670 | static inline unsigned long module_kallsyms_lookup_name(const char *name) | |
671 | { | |
672 | return 0; | |
673 | } | |
674 | ||
75a66614 AK |
675 | static inline int module_kallsyms_on_each_symbol(int (*fn)(void *, const char *, |
676 | struct module *, | |
677 | unsigned long), | |
678 | void *data) | |
679 | { | |
680 | return 0; | |
681 | } | |
682 | ||
1da177e4 LT |
683 | static inline int register_module_notifier(struct notifier_block * nb) |
684 | { | |
685 | /* no events will happen anyway, so this can always succeed */ | |
686 | return 0; | |
687 | } | |
688 | ||
689 | static inline int unregister_module_notifier(struct notifier_block * nb) | |
690 | { | |
691 | return 0; | |
692 | } | |
693 | ||
694 | #define module_put_and_exit(code) do_exit(code) | |
695 | ||
696 | static inline void print_modules(void) | |
697 | { | |
698 | } | |
699 | ||
97e1c18e MD |
700 | static inline void module_update_tracepoints(void) |
701 | { | |
702 | } | |
703 | ||
704 | static inline int module_get_iter_tracepoints(struct tracepoint_iter *iter) | |
705 | { | |
706 | return 0; | |
707 | } | |
ef665c1a RD |
708 | #endif /* CONFIG_MODULES */ |
709 | ||
ef665c1a | 710 | #ifdef CONFIG_SYSFS |
7405c1e1 GKH |
711 | extern struct kset *module_kset; |
712 | extern struct kobj_type module_ktype; | |
713 | extern int module_sysfs_initialized; | |
ef665c1a RD |
714 | #endif /* CONFIG_SYSFS */ |
715 | ||
1da177e4 LT |
716 | #define symbol_request(x) try_then_request_module(symbol_get(x), "symbol:" #x) |
717 | ||
718 | /* BELOW HERE ALL THESE ARE OBSOLETE AND WILL VANISH */ | |
719 | ||
1da177e4 LT |
720 | #define __MODULE_STRING(x) __stringify(x) |
721 | ||
84e1c6bb | 722 | #ifdef CONFIG_DEBUG_SET_MODULE_RONX |
723 | extern void set_all_modules_text_rw(void); | |
724 | extern void set_all_modules_text_ro(void); | |
725 | #else | |
726 | static inline void set_all_modules_text_rw(void) { } | |
727 | static inline void set_all_modules_text_ro(void) { } | |
728 | #endif | |
0d9c25dd AM |
729 | |
730 | #ifdef CONFIG_GENERIC_BUG | |
5336377d | 731 | void module_bug_finalize(const Elf_Ehdr *, const Elf_Shdr *, |
0d9c25dd AM |
732 | struct module *); |
733 | void module_bug_cleanup(struct module *); | |
734 | ||
735 | #else /* !CONFIG_GENERIC_BUG */ | |
736 | ||
5336377d | 737 | static inline void module_bug_finalize(const Elf_Ehdr *hdr, |
0d9c25dd AM |
738 | const Elf_Shdr *sechdrs, |
739 | struct module *mod) | |
740 | { | |
0d9c25dd AM |
741 | } |
742 | static inline void module_bug_cleanup(struct module *mod) {} | |
743 | #endif /* CONFIG_GENERIC_BUG */ | |
744 | ||
1da177e4 | 745 | #endif /* _LINUX_MODULE_H */ |