blob: f8f92d015efe7ceb5fbd8eabc7e747887eae7344 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#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 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07009#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>
Mathieu Desnoyers8256e472007-10-18 23:41:06 -070018#include <linux/marker.h>
Mathieu Desnoyers97e1c182008-07-18 12:16:16 -040019#include <linux/tracepoint.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020
Li Zefan7ead8b82009-08-17 16:56:28 +080021#include <asm/local.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include <asm/module.h>
23
Li Zefan7ead8b82009-08-17 16:56:28 +080024#include <trace/events/module.h>
25
Linus Torvalds1da177e2005-04-16 15:20:36 -070026/* Not Yet Implemented */
27#define MODULE_SUPPORTED_DEVICE(name)
28
Adrian Bunkf606ddf2008-07-23 21:28:50 -070029/* some toolchains uses a `_' prefix for all user symbols */
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#ifndef MODULE_SYMBOL_PREFIX
31#define MODULE_SYMBOL_PREFIX ""
32#endif
33
Rusty Russell730b69d2008-10-22 10:00:22 -050034#define MODULE_NAME_LEN MAX_PARAM_PREFIX_LEN
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
36struct kernel_symbol
37{
38 unsigned long value;
39 const char *name;
40};
41
42struct modversion_info
43{
44 unsigned long crc;
45 char name[MODULE_NAME_LEN];
46};
47
48struct module;
49
50struct module_attribute {
51 struct attribute attr;
52 ssize_t (*show)(struct module_attribute *, struct module *, char *);
53 ssize_t (*store)(struct module_attribute *, struct module *,
54 const char *, size_t count);
Matt Domschc988d2b2005-06-23 22:05:15 -070055 void (*setup)(struct module *, const char *);
56 int (*test)(struct module *);
57 void (*free)(struct module *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070058};
59
60struct module_kobject
61{
62 struct kobject kobj;
63 struct module *mod;
Kay Sieversf30c53a2007-01-15 20:22:02 +010064 struct kobject *drivers_dir;
Rusty Russell9b473de2008-10-22 10:00:22 -050065 struct module_param_attrs *mp;
Linus Torvalds1da177e2005-04-16 15:20:36 -070066};
67
68/* These are either module local, or the kernel's dummy ones. */
69extern int init_module(void);
70extern void cleanup_module(void);
71
72/* Archs provide a method of finding the correct exception table. */
73struct exception_table_entry;
74
75const struct exception_table_entry *
76search_extable(const struct exception_table_entry *first,
77 const struct exception_table_entry *last,
78 unsigned long value);
79void sort_extable(struct exception_table_entry *start,
80 struct exception_table_entry *finish);
81void sort_main_extable(void);
Rusty Russellad6561d2009-06-12 21:47:03 -060082void trim_init_extable(struct module *m);
Linus Torvalds1da177e2005-04-16 15:20:36 -070083
Linus Torvalds1da177e2005-04-16 15:20:36 -070084#ifdef MODULE
85#define MODULE_GENERIC_TABLE(gtype,name) \
86extern const struct gtype##_id __mod_##gtype##_table \
87 __attribute__ ((unused, alias(__stringify(name))))
88
89extern struct module __this_module;
90#define THIS_MODULE (&__this_module)
91#else /* !MODULE */
92#define MODULE_GENERIC_TABLE(gtype,name)
93#define THIS_MODULE ((struct module *)0)
94#endif
95
96/* Generic info of form tag = "info" */
97#define MODULE_INFO(tag, info) __MODULE_INFO(tag, tag, info)
98
99/* For userspace: you can also call me... */
100#define MODULE_ALIAS(_alias) MODULE_INFO(alias, _alias)
101
102/*
103 * The following license idents are currently accepted as indicating free
104 * software modules
105 *
106 * "GPL" [GNU Public License v2 or later]
107 * "GPL v2" [GNU Public License v2]
108 * "GPL and additional rights" [GNU Public License v2 rights and more]
109 * "Dual BSD/GPL" [GNU Public License v2
110 * or BSD license choice]
Xose Vazquez Perez8d27e902006-06-23 02:05:13 -0700111 * "Dual MIT/GPL" [GNU Public License v2
112 * or MIT license choice]
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 * "Dual MPL/GPL" [GNU Public License v2
114 * or Mozilla license choice]
115 *
116 * The following other idents are available
117 *
118 * "Proprietary" [Non free products]
119 *
120 * There are dual licensed components, but when running with Linux it is the
121 * GPL that is relevant so this is a non issue. Similarly LGPL linked with GPL
122 * is a GPL combined work.
123 *
124 * This exists for several reasons
125 * 1. So modinfo can show license info for users wanting to vet their setup
126 * is free
127 * 2. So the community can ignore bug reports including proprietary modules
128 * 3. So vendors can do likewise based on their own policies
129 */
130#define MODULE_LICENSE(_license) MODULE_INFO(license, _license)
131
Rene Herman108f39a2007-05-10 22:22:50 -0700132/* Author, ideally of form NAME[, NAME]*[ and NAME] */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133#define MODULE_AUTHOR(_author) MODULE_INFO(author, _author)
134
135/* What your module does. */
136#define MODULE_DESCRIPTION(_description) MODULE_INFO(description, _description)
137
138/* One for each parameter, describing how to use it. Some files do
139 multiple of these per line, so can't just use MODULE_INFO. */
140#define MODULE_PARM_DESC(_parm, desc) \
141 __MODULE_INFO(parm, _parm, #_parm ":" desc)
142
143#define MODULE_DEVICE_TABLE(type,name) \
144 MODULE_GENERIC_TABLE(type##_device,name)
145
146/* Version of form [<epoch>:]<version>[-<extra-version>].
147 Or for CVS/RCS ID version, everything but the number is stripped.
148 <epoch>: A (small) unsigned integer which allows you to start versions
149 anew. If not mentioned, it's zero. eg. "2:1.0" is after
150 "1:2.0".
151 <version>: The <version> may contain only alphanumerics and the
152 character `.'. Ordered by numeric sort for numeric parts,
153 ascii sort for ascii parts (as per RPM or DEB algorithm).
154 <extraversion>: Like <version>, but inserted for local
155 customizations, eg "rh3" or "rusty1".
156
157 Using this automatically adds a checksum of the .c files and the
158 local headers in "srcversion".
159*/
160#define MODULE_VERSION(_version) MODULE_INFO(version, _version)
161
Jon Masters187afbe2006-08-28 17:08:21 -0500162/* Optional firmware file (or files) needed by the module
163 * format is simply firmware file name. Multiple firmware
164 * files require multiple MODULE_FIRMWARE() specifiers */
165#define MODULE_FIRMWARE(_firmware) MODULE_INFO(firmware, _firmware)
166
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167/* Given an address, look for it in the exception tables */
168const struct exception_table_entry *search_exception_tables(unsigned long add);
169
170struct notifier_block;
171
172#ifdef CONFIG_MODULES
173
174/* Get/put a kernel symbol (calls must be symmetric) */
175void *__symbol_get(const char *symbol);
176void *__symbol_get_gpl(const char *symbol);
177#define symbol_get(x) ((typeof(&x))(__symbol_get(MODULE_SYMBOL_PREFIX #x)))
178
179#ifndef __GENKSYMS__
180#ifdef CONFIG_MODVERSIONS
181/* Mark the CRC weak since genksyms apparently decides not to
182 * generate a checksums for some symbols */
183#define __CRC_SYMBOL(sym, sec) \
184 extern void *__crc_##sym __attribute__((weak)); \
185 static const unsigned long __kcrctab_##sym \
Adrian Bunk3ff6eec2008-01-24 22:16:20 +0100186 __used \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187 __attribute__((section("__kcrctab" sec), unused)) \
188 = (unsigned long) &__crc_##sym;
189#else
190#define __CRC_SYMBOL(sym, sec)
191#endif
192
193/* For every exported symbol, place a struct in the __ksymtab section */
194#define __EXPORT_SYMBOL(sym, sec) \
Patrick McHardya1a8fee2006-03-23 22:07:34 -0800195 extern typeof(sym) sym; \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196 __CRC_SYMBOL(sym, sec) \
197 static const char __kstrtab_##sym[] \
Rusty Russellea01e792008-03-13 09:02:17 +0000198 __attribute__((section("__ksymtab_strings"), aligned(1))) \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 = MODULE_SYMBOL_PREFIX #sym; \
200 static const struct kernel_symbol __ksymtab_##sym \
Adrian Bunk3ff6eec2008-01-24 22:16:20 +0100201 __used \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 __attribute__((section("__ksymtab" sec), unused)) \
203 = { (unsigned long)&sym, __kstrtab_##sym }
204
205#define EXPORT_SYMBOL(sym) \
206 __EXPORT_SYMBOL(sym, "")
207
208#define EXPORT_SYMBOL_GPL(sym) \
209 __EXPORT_SYMBOL(sym, "_gpl")
210
Greg Kroah-Hartman9f28bb72006-03-20 13:17:13 -0800211#define EXPORT_SYMBOL_GPL_FUTURE(sym) \
212 __EXPORT_SYMBOL(sym, "_gpl_future")
213
Arjan van de Venf71d20e2006-06-28 04:26:45 -0700214
215#ifdef CONFIG_UNUSED_SYMBOLS
216#define EXPORT_UNUSED_SYMBOL(sym) __EXPORT_SYMBOL(sym, "_unused")
217#define EXPORT_UNUSED_SYMBOL_GPL(sym) __EXPORT_SYMBOL(sym, "_unused_gpl")
218#else
219#define EXPORT_UNUSED_SYMBOL(sym)
220#define EXPORT_UNUSED_SYMBOL_GPL(sym)
221#endif
222
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223#endif
224
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225enum module_state
226{
227 MODULE_STATE_LIVE,
228 MODULE_STATE_COMING,
229 MODULE_STATE_GOING,
230};
231
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232struct module
233{
234 enum module_state state;
235
236 /* Member of list of modules */
237 struct list_head list;
238
239 /* Unique handle for this module */
240 char name[MODULE_NAME_LEN];
241
242 /* Sysfs stuff. */
243 struct module_kobject mkobj;
Greg Kroah-Hartman03e88ae12006-02-16 13:50:23 -0800244 struct module_attribute *modinfo_attrs;
Matt Domschc988d2b2005-06-23 22:05:15 -0700245 const char *version;
246 const char *srcversion;
Kay Sievers270a6c42007-01-18 13:26:15 +0100247 struct kobject *holders_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248
249 /* Exported symbols */
250 const struct kernel_symbol *syms;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251 const unsigned long *crcs;
Richard Kennedyaf540682008-07-22 19:24:26 -0500252 unsigned int num_syms;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253
Rusty Russelle180a6b2009-03-31 13:05:29 -0600254 /* Kernel parameters. */
255 struct kernel_param *kp;
256 unsigned int num_kp;
257
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 /* GPL-only exported symbols. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 unsigned int num_gpl_syms;
Richard Kennedyaf540682008-07-22 19:24:26 -0500260 const struct kernel_symbol *gpl_syms;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261 const unsigned long *gpl_crcs;
262
Denys Vlasenkof7f5b672008-07-22 19:24:26 -0500263#ifdef CONFIG_UNUSED_SYMBOLS
Arjan van de Venf71d20e2006-06-28 04:26:45 -0700264 /* unused exported symbols. */
265 const struct kernel_symbol *unused_syms;
Arjan van de Venf71d20e2006-06-28 04:26:45 -0700266 const unsigned long *unused_crcs;
Richard Kennedyaf540682008-07-22 19:24:26 -0500267 unsigned int num_unused_syms;
268
Arjan van de Venf71d20e2006-06-28 04:26:45 -0700269 /* GPL-only, unused exported symbols. */
Arjan van de Venf71d20e2006-06-28 04:26:45 -0700270 unsigned int num_unused_gpl_syms;
Richard Kennedyaf540682008-07-22 19:24:26 -0500271 const struct kernel_symbol *unused_gpl_syms;
Arjan van de Venf71d20e2006-06-28 04:26:45 -0700272 const unsigned long *unused_gpl_crcs;
Denys Vlasenkof7f5b672008-07-22 19:24:26 -0500273#endif
Arjan van de Venf71d20e2006-06-28 04:26:45 -0700274
Greg Kroah-Hartman9f28bb72006-03-20 13:17:13 -0800275 /* symbols that will be GPL-only in the near future. */
276 const struct kernel_symbol *gpl_future_syms;
Greg Kroah-Hartman9f28bb72006-03-20 13:17:13 -0800277 const unsigned long *gpl_future_crcs;
Richard Kennedyaf540682008-07-22 19:24:26 -0500278 unsigned int num_gpl_future_syms;
Greg Kroah-Hartman9f28bb72006-03-20 13:17:13 -0800279
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 /* Exception table */
281 unsigned int num_exentries;
Rusty Russell5e458cc2008-10-22 10:00:13 -0500282 struct exception_table_entry *extable;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283
284 /* Startup function. */
285 int (*init)(void);
286
287 /* If this is non-NULL, vfree after init() returns */
288 void *module_init;
289
290 /* Here is the actual code + data, vfree'd on unload. */
291 void *module_core;
292
293 /* Here are the sizes of the init and core sections */
Denys Vlasenko2f0f2a32008-07-22 19:24:27 -0500294 unsigned int init_size, core_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295
296 /* The size of the executable code in each section. */
Denys Vlasenko2f0f2a32008-07-22 19:24:27 -0500297 unsigned int init_text_size, core_text_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298
299 /* Arch-specific module values */
300 struct mod_arch_specific arch;
301
Randy Dunlap2bc2d612006-10-02 02:17:02 -0700302 unsigned int taints; /* same bits as kernel:tainted */
303
Jeremy Fitzhardinge7664c5a2006-12-08 02:36:19 -0800304#ifdef CONFIG_GENERIC_BUG
305 /* Support for BUG */
Richard Kennedyaf540682008-07-22 19:24:26 -0500306 unsigned num_bugs;
Jeremy Fitzhardinge7664c5a2006-12-08 02:36:19 -0800307 struct list_head bug_list;
308 struct bug_entry *bug_table;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309#endif
310
311#ifdef CONFIG_KALLSYMS
312 /* We keep the symbol and string tables for kallsyms. */
313 Elf_Sym *symtab;
Denys Vlasenko2f0f2a32008-07-22 19:24:27 -0500314 unsigned int num_symtab;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 char *strtab;
316
317 /* Section attributes */
318 struct module_sect_attrs *sect_attrs;
Roland McGrath6d760132007-10-16 23:26:40 -0700319
320 /* Notes attributes */
321 struct module_notes_attrs *notes_attrs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322#endif
323
324 /* Per-cpu data. */
325 void *percpu;
326
327 /* The command line arguments (may be mangled). People like
328 keeping pointers to this stuff */
329 char *args;
Mathieu Desnoyers8256e472007-10-18 23:41:06 -0700330#ifdef CONFIG_MARKERS
331 struct marker *markers;
332 unsigned int num_markers;
333#endif
Mathieu Desnoyers97e1c182008-07-18 12:16:16 -0400334#ifdef CONFIG_TRACEPOINTS
335 struct tracepoint *tracepoints;
336 unsigned int num_tracepoints;
337#endif
Richard Kennedyaf540682008-07-22 19:24:26 -0500338
Frederic Weisbecker769b0442009-03-06 17:21:49 +0100339#ifdef CONFIG_TRACING
Lai Jiangshan1ba28e02009-03-06 17:21:48 +0100340 const char **trace_bprintk_fmt_start;
341 unsigned int num_trace_bprintk_fmt;
342#endif
Steven Rostedt6d723732009-04-10 14:53:50 -0400343#ifdef CONFIG_EVENT_TRACING
344 struct ftrace_event_call *trace_events;
345 unsigned int num_trace_events;
346#endif
Steven Rostedt93eb6772009-04-15 13:24:06 -0400347#ifdef CONFIG_FTRACE_MCOUNT_RECORD
348 unsigned long *ftrace_callsites;
349 unsigned int num_ftrace_callsites;
350#endif
Lai Jiangshan1ba28e02009-03-06 17:21:48 +0100351
Richard Kennedyaf540682008-07-22 19:24:26 -0500352#ifdef CONFIG_MODULE_UNLOAD
353 /* What modules depend on me? */
354 struct list_head modules_which_use_me;
355
356 /* Who is waiting for us to be unloaded */
357 struct task_struct *waiter;
358
359 /* Destruction function. */
360 void (*exit)(void);
361
Eric Dumazet720eba32009-02-03 13:31:36 +1030362#ifdef CONFIG_SMP
363 char *refptr;
364#else
365 local_t ref;
366#endif
Richard Kennedyaf540682008-07-22 19:24:26 -0500367#endif
Peter Oberparleiterb99b87f2009-06-17 16:28:03 -0700368
369#ifdef CONFIG_CONSTRUCTORS
370 /* Constructor functions. */
371 ctor_fn_t *ctors;
372 unsigned int num_ctors;
373#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374};
Roman Zippele61a1c12007-05-09 02:35:15 -0700375#ifndef MODULE_ARCH_INIT
376#define MODULE_ARCH_INIT {}
377#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378
Tim Abbottc6b37802008-12-05 19:03:59 -0500379extern struct mutex module_mutex;
380
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381/* FIXME: It'd be nice to isolate modules during init, too, so they
382 aren't used before they (may) fail. But presently too much code
383 (IDE & SCSI) require entry into the module during init.*/
384static inline int module_is_live(struct module *mod)
385{
386 return mod->state != MODULE_STATE_GOING;
387}
388
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389struct module *__module_text_address(unsigned long addr);
Rusty Russelle6104992009-03-31 13:05:31 -0600390struct module *__module_address(unsigned long addr);
391bool is_module_address(unsigned long addr);
392bool is_module_text_address(unsigned long addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393
Masami Hiramatsua06f6212009-01-06 14:41:49 -0800394static inline int within_module_core(unsigned long addr, struct module *mod)
395{
396 return (unsigned long)mod->module_core <= addr &&
397 addr < (unsigned long)mod->module_core + mod->core_size;
398}
399
400static inline int within_module_init(unsigned long addr, struct module *mod)
401{
402 return (unsigned long)mod->module_init <= addr &&
403 addr < (unsigned long)mod->module_init + mod->init_size;
404}
405
Tim Abbottc6b37802008-12-05 19:03:59 -0500406/* Search for module by name: must hold module_mutex. */
407struct module *find_module(const char *name);
408
409struct symsearch {
410 const struct kernel_symbol *start, *stop;
411 const unsigned long *crcs;
412 enum {
413 NOT_GPL_ONLY,
414 GPL_ONLY,
415 WILL_BE_GPL_ONLY,
416 } licence;
417 bool unused;
418};
419
420/* Search for an exported symbol by name. */
421const struct kernel_symbol *find_symbol(const char *name,
422 struct module **owner,
423 const unsigned long **crc,
424 bool gplok,
425 bool warn);
426
427/* Walk the exported symbol table */
428bool each_symbol(bool (*fn)(const struct symsearch *arr, struct module *owner,
429 unsigned int symnum, void *data), void *data);
430
Alexey Dobriyanea078902007-05-08 00:28:39 -0700431/* Returns 0 and fills in value, defined and namebuf, or -ERANGE if
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 symnum out of range. */
Alexey Dobriyanea078902007-05-08 00:28:39 -0700433int module_get_kallsym(unsigned int symnum, unsigned long *value, char *type,
434 char *name, char *module_name, int *exported);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435
436/* Look for this name: can be of form module:name. */
437unsigned long module_kallsyms_lookup_name(const char *name);
438
Anders Kaseorg75a66612008-12-05 19:03:58 -0500439int module_kallsyms_on_each_symbol(int (*fn)(void *, const char *,
440 struct module *, unsigned long),
441 void *data);
442
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443extern void __module_put_and_exit(struct module *mod, long code)
444 __attribute__((noreturn));
445#define module_put_and_exit(code) __module_put_and_exit(THIS_MODULE, code);
446
447#ifdef CONFIG_MODULE_UNLOAD
448unsigned int module_refcount(struct module *mod);
449void __symbol_put(const char *symbol);
450#define symbol_put(x) __symbol_put(MODULE_SYMBOL_PREFIX #x)
451void symbol_put_addr(void *addr);
452
Eric Dumazet720eba32009-02-03 13:31:36 +1030453static inline local_t *__module_ref_addr(struct module *mod, int cpu)
454{
455#ifdef CONFIG_SMP
456 return (local_t *) (mod->refptr + per_cpu_offset(cpu));
457#else
458 return &mod->ref;
459#endif
460}
461
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462/* Sometimes we know we already have a refcount, and it's easier not
463 to handle the error case (which only happens with rmmod --wait). */
464static inline void __module_get(struct module *module)
465{
466 if (module) {
Li Zefan7ead8b82009-08-17 16:56:28 +0800467 unsigned int cpu = get_cpu();
468 local_inc(__module_ref_addr(module, cpu));
469 trace_module_get(module, _THIS_IP_,
470 local_read(__module_ref_addr(module, cpu)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 put_cpu();
472 }
473}
474
475static inline int try_module_get(struct module *module)
476{
477 int ret = 1;
478
479 if (module) {
480 unsigned int cpu = get_cpu();
Li Zefan7ead8b82009-08-17 16:56:28 +0800481 if (likely(module_is_live(module))) {
Eric Dumazet720eba32009-02-03 13:31:36 +1030482 local_inc(__module_ref_addr(module, cpu));
Li Zefan7ead8b82009-08-17 16:56:28 +0800483 trace_module_get(module, _THIS_IP_,
484 local_read(__module_ref_addr(module, cpu)));
485 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 else
487 ret = 0;
488 put_cpu();
489 }
490 return ret;
491}
492
Al Virof6a57032006-10-18 01:47:25 -0400493extern void module_put(struct module *module);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494
495#else /*!CONFIG_MODULE_UNLOAD*/
496static inline int try_module_get(struct module *module)
497{
498 return !module || module_is_live(module);
499}
500static inline void module_put(struct module *module)
501{
502}
503static inline void __module_get(struct module *module)
504{
505}
506#define symbol_put(x) do { } while(0)
507#define symbol_put_addr(p) do { } while(0)
508
509#endif /* CONFIG_MODULE_UNLOAD */
Tim Abbottc6b37802008-12-05 19:03:59 -0500510int use_module(struct module *a, struct module *b);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511
512/* This is a #define so the string doesn't get put in every .o file */
513#define module_name(mod) \
514({ \
515 struct module *__mod = (mod); \
516 __mod ? __mod->name : "kernel"; \
517})
518
Rusty Russell6dd06c92008-01-29 17:13:22 -0500519/* For kallsyms to ask for address resolution. namebuf should be at
520 * least KSYM_NAME_LEN long: a pointer to namebuf is returned if
521 * found, otherwise NULL. */
Andrew Morton92dfc9d2008-02-08 04:18:43 -0800522const char *module_address_lookup(unsigned long addr,
Rusty Russell6dd06c92008-01-29 17:13:22 -0500523 unsigned long *symbolsize,
524 unsigned long *offset,
525 char **modname,
526 char *namebuf);
Alexey Dobriyan9d65cb42007-05-08 00:28:43 -0700527int lookup_module_symbol_name(unsigned long addr, char *symname);
Alexey Dobriyana5c43da2007-05-08 00:28:47 -0700528int lookup_module_symbol_attrs(unsigned long addr, unsigned long *size, unsigned long *offset, char *modname, char *name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529
530/* For extable.c to search modules' exception tables. */
531const struct exception_table_entry *search_module_extables(unsigned long addr);
532
533int register_module_notifier(struct notifier_block * nb);
534int unregister_module_notifier(struct notifier_block * nb);
535
536extern void print_modules(void);
537
Mathieu Desnoyersfb40bd72008-02-13 15:03:37 -0800538extern void module_update_markers(void);
Mathieu Desnoyers8256e472007-10-18 23:41:06 -0700539
Mathieu Desnoyers97e1c182008-07-18 12:16:16 -0400540extern void module_update_tracepoints(void);
541extern int module_get_iter_tracepoints(struct tracepoint_iter *iter);
542
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543#else /* !CONFIG_MODULES... */
544#define EXPORT_SYMBOL(sym)
545#define EXPORT_SYMBOL_GPL(sym)
Greg Kroah-Hartman9f28bb72006-03-20 13:17:13 -0800546#define EXPORT_SYMBOL_GPL_FUTURE(sym)
Arjan van de Venf71d20e2006-06-28 04:26:45 -0700547#define EXPORT_UNUSED_SYMBOL(sym)
548#define EXPORT_UNUSED_SYMBOL_GPL(sym)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549
550/* Given an address, look for it in the exception tables. */
551static inline const struct exception_table_entry *
552search_module_extables(unsigned long addr)
553{
554 return NULL;
555}
556
Rusty Russelle6104992009-03-31 13:05:31 -0600557static inline struct module *__module_address(unsigned long addr)
558{
559 return NULL;
560}
561
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562static inline struct module *__module_text_address(unsigned long addr)
563{
564 return NULL;
565}
566
Rusty Russelle6104992009-03-31 13:05:31 -0600567static inline bool is_module_address(unsigned long addr)
Ingo Molnar4d435f92006-07-03 00:24:24 -0700568{
Rusty Russelle6104992009-03-31 13:05:31 -0600569 return false;
570}
571
572static inline bool is_module_text_address(unsigned long addr)
573{
574 return false;
Ingo Molnar4d435f92006-07-03 00:24:24 -0700575}
576
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577/* Get/put a kernel symbol (calls should be symmetric) */
578#define symbol_get(x) ({ extern typeof(x) x __attribute__((weak)); &(x); })
579#define symbol_put(x) do { } while(0)
580#define symbol_put_addr(x) do { } while(0)
581
582static inline void __module_get(struct module *module)
583{
584}
585
586static inline int try_module_get(struct module *module)
587{
588 return 1;
589}
590
591static inline void module_put(struct module *module)
592{
593}
594
595#define module_name(mod) "kernel"
596
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597/* For kallsyms to ask for address resolution. NULL means not found. */
Andrew Morton92dfc9d2008-02-08 04:18:43 -0800598static inline const char *module_address_lookup(unsigned long addr,
Rusty Russell6dd06c92008-01-29 17:13:22 -0500599 unsigned long *symbolsize,
600 unsigned long *offset,
601 char **modname,
602 char *namebuf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603{
604 return NULL;
605}
606
Alexey Dobriyan9d65cb42007-05-08 00:28:43 -0700607static inline int lookup_module_symbol_name(unsigned long addr, char *symname)
608{
609 return -ERANGE;
610}
611
Alexey Dobriyana5c43da2007-05-08 00:28:47 -0700612static inline int lookup_module_symbol_attrs(unsigned long addr, unsigned long *size, unsigned long *offset, char *modname, char *name)
613{
614 return -ERANGE;
615}
616
Alexey Dobriyanea078902007-05-08 00:28:39 -0700617static inline int module_get_kallsym(unsigned int symnum, unsigned long *value,
618 char *type, char *name,
619 char *module_name, int *exported)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620{
Alexey Dobriyanea078902007-05-08 00:28:39 -0700621 return -ERANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622}
623
624static inline unsigned long module_kallsyms_lookup_name(const char *name)
625{
626 return 0;
627}
628
Anders Kaseorg75a66612008-12-05 19:03:58 -0500629static inline int module_kallsyms_on_each_symbol(int (*fn)(void *, const char *,
630 struct module *,
631 unsigned long),
632 void *data)
633{
634 return 0;
635}
636
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637static inline int register_module_notifier(struct notifier_block * nb)
638{
639 /* no events will happen anyway, so this can always succeed */
640 return 0;
641}
642
643static inline int unregister_module_notifier(struct notifier_block * nb)
644{
645 return 0;
646}
647
648#define module_put_and_exit(code) do_exit(code)
649
650static inline void print_modules(void)
651{
652}
653
Adrian Bunk1387d0d2008-02-14 19:31:20 -0800654static inline void module_update_markers(void)
Mathieu Desnoyers8256e472007-10-18 23:41:06 -0700655{
656}
657
Mathieu Desnoyers97e1c182008-07-18 12:16:16 -0400658static inline void module_update_tracepoints(void)
659{
660}
661
662static inline int module_get_iter_tracepoints(struct tracepoint_iter *iter)
663{
664 return 0;
665}
666
Randy Dunlapef665c12007-02-13 15:19:06 -0800667#endif /* CONFIG_MODULES */
668
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669struct device_driver;
Randy Dunlapef665c12007-02-13 15:19:06 -0800670#ifdef CONFIG_SYSFS
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671struct module;
672
Greg Kroah-Hartman7405c1e2007-11-01 10:39:50 -0700673extern struct kset *module_kset;
674extern struct kobj_type module_ktype;
675extern int module_sysfs_initialized;
Randy Dunlapef665c12007-02-13 15:19:06 -0800676
677int mod_sysfs_init(struct module *mod);
678int mod_sysfs_setup(struct module *mod,
679 struct kernel_param *kparam,
680 unsigned int num_params);
681int module_add_modinfo_attrs(struct module *mod);
682void module_remove_modinfo_attrs(struct module *mod);
683
684#else /* !CONFIG_SYSFS */
685
686static inline int mod_sysfs_init(struct module *mod)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687{
Randy Dunlapef665c12007-02-13 15:19:06 -0800688 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689}
690
Randy Dunlapef665c12007-02-13 15:19:06 -0800691static inline int mod_sysfs_setup(struct module *mod,
692 struct kernel_param *kparam,
693 unsigned int num_params)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694{
Randy Dunlapef665c12007-02-13 15:19:06 -0800695 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696}
697
Randy Dunlapef665c12007-02-13 15:19:06 -0800698static inline int module_add_modinfo_attrs(struct module *mod)
699{
700 return 0;
701}
702
703static inline void module_remove_modinfo_attrs(struct module *mod)
704{ }
705
706#endif /* CONFIG_SYSFS */
707
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708#define symbol_request(x) try_then_request_module(symbol_get(x), "symbol:" #x)
709
710/* BELOW HERE ALL THESE ARE OBSOLETE AND WILL VANISH */
711
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712#define __MODULE_STRING(x) __stringify(x)
713
Andrew Morton0d9c25d2009-06-16 15:33:37 -0700714
715#ifdef CONFIG_GENERIC_BUG
716int module_bug_finalize(const Elf_Ehdr *, const Elf_Shdr *,
717 struct module *);
718void module_bug_cleanup(struct module *);
719
720#else /* !CONFIG_GENERIC_BUG */
721
722static inline int module_bug_finalize(const Elf_Ehdr *hdr,
723 const Elf_Shdr *sechdrs,
724 struct module *mod)
725{
726 return 0;
727}
728static inline void module_bug_cleanup(struct module *mod) {}
729#endif /* CONFIG_GENERIC_BUG */
730
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731#endif /* _LINUX_MODULE_H */