blob: 9f0ddc808a829e36f277408f4f35ead49b336157 [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 Desnoyers97e1c182008-07-18 12:16:16 -040018#include <linux/tracepoint.h>
Paul Gortmakerf5016932011-05-23 14:11:39 -040019#include <linux/export.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020
Christoph Lametere1783a22010-01-05 15:34:50 +090021#include <linux/percpu.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
Rusty Russell730b69d2008-10-22 10:00:22 -050029#define MODULE_NAME_LEN MAX_PARAM_PREFIX_LEN
Linus Torvalds1da177e2005-04-16 15:20:36 -070030
Linus Torvalds1da177e2005-04-16 15:20:36 -070031struct modversion_info
32{
33 unsigned long crc;
34 char name[MODULE_NAME_LEN];
35};
36
37struct module;
38
Kay Sievers4befb022011-07-24 22:06:04 +093039struct module_kobject {
40 struct kobject kobj;
41 struct module *mod;
42 struct kobject *drivers_dir;
43 struct module_param_attrs *mp;
44};
45
Linus Torvalds1da177e2005-04-16 15:20:36 -070046struct module_attribute {
Kay Sievers4befb022011-07-24 22:06:04 +093047 struct attribute attr;
48 ssize_t (*show)(struct module_attribute *, struct module_kobject *,
49 char *);
50 ssize_t (*store)(struct module_attribute *, struct module_kobject *,
Linus Torvalds1da177e2005-04-16 15:20:36 -070051 const char *, size_t count);
Matt Domschc988d2b2005-06-23 22:05:15 -070052 void (*setup)(struct module *, const char *);
53 int (*test)(struct module *);
54 void (*free)(struct module *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070055};
56
Dmitry Torokhove94965e2010-12-15 14:00:19 -080057struct module_version_attribute {
58 struct module_attribute mattr;
59 const char *module_name;
60 const char *version;
Dmitry Torokhov98562ad2011-02-04 13:30:10 -080061} __attribute__ ((__aligned__(sizeof(void *))));
Dmitry Torokhove94965e2010-12-15 14:00:19 -080062
Dmitry Torokhov9b73a582011-02-07 16:02:27 -080063extern ssize_t __modver_version_show(struct module_attribute *,
Kay Sievers4befb022011-07-24 22:06:04 +093064 struct module_kobject *, char *);
Dmitry Torokhov9b73a582011-02-07 16:02:27 -080065
Kay Sievers88bfa322011-07-24 22:06:04 +093066extern struct module_attribute module_uevent;
Linus Torvalds1da177e2005-04-16 15:20:36 -070067
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
Linus Torvalds1da177e2005-04-16 15:20:36 -070089#else /* !MODULE */
90#define MODULE_GENERIC_TABLE(gtype,name)
Linus Torvalds1da177e2005-04-16 15:20:36 -070091#endif
92
93/* Generic info of form tag = "info" */
94#define MODULE_INFO(tag, info) __MODULE_INFO(tag, tag, info)
95
96/* For userspace: you can also call me... */
97#define MODULE_ALIAS(_alias) MODULE_INFO(alias, _alias)
98
99/*
100 * The following license idents are currently accepted as indicating free
101 * software modules
102 *
103 * "GPL" [GNU Public License v2 or later]
104 * "GPL v2" [GNU Public License v2]
105 * "GPL and additional rights" [GNU Public License v2 rights and more]
106 * "Dual BSD/GPL" [GNU Public License v2
107 * or BSD license choice]
Xose Vazquez Perez8d27e902006-06-23 02:05:13 -0700108 * "Dual MIT/GPL" [GNU Public License v2
109 * or MIT license choice]
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 * "Dual MPL/GPL" [GNU Public License v2
111 * or Mozilla license choice]
112 *
113 * The following other idents are available
114 *
115 * "Proprietary" [Non free products]
116 *
117 * There are dual licensed components, but when running with Linux it is the
118 * GPL that is relevant so this is a non issue. Similarly LGPL linked with GPL
119 * is a GPL combined work.
120 *
121 * This exists for several reasons
122 * 1. So modinfo can show license info for users wanting to vet their setup
123 * is free
124 * 2. So the community can ignore bug reports including proprietary modules
125 * 3. So vendors can do likewise based on their own policies
126 */
127#define MODULE_LICENSE(_license) MODULE_INFO(license, _license)
128
Johannes Berg1d7015c2009-09-25 00:32:58 -0600129/*
130 * Author(s), use "Name <email>" or just "Name", for multiple
131 * authors use multiple MODULE_AUTHOR() statements/lines.
132 */
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*/
Dmitry Torokhove94965e2010-12-15 14:00:19 -0800160
Rusty Russell3b90a5b2011-01-24 14:32:51 -0600161#if defined(MODULE) || !defined(CONFIG_SYSFS)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162#define MODULE_VERSION(_version) MODULE_INFO(version, _version)
Dmitry Torokhove94965e2010-12-15 14:00:19 -0800163#else
164#define MODULE_VERSION(_version) \
Dmitry Torokhovb4bc84282011-02-07 16:02:25 -0800165 static struct module_version_attribute ___modver_attr = { \
Dmitry Torokhove94965e2010-12-15 14:00:19 -0800166 .mattr = { \
167 .attr = { \
168 .name = "version", \
169 .mode = S_IRUGO, \
170 }, \
171 .show = __modver_version_show, \
172 }, \
173 .module_name = KBUILD_MODNAME, \
174 .version = _version, \
Dmitry Torokhovb4bc84282011-02-07 16:02:25 -0800175 }; \
176 static const struct module_version_attribute \
177 __used __attribute__ ((__section__ ("__modver"))) \
178 * __moduleparam_const __modver_attr = &___modver_attr
Dmitry Torokhove94965e2010-12-15 14:00:19 -0800179#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180
Jon Masters187afbe2006-08-28 17:08:21 -0500181/* Optional firmware file (or files) needed by the module
182 * format is simply firmware file name. Multiple firmware
183 * files require multiple MODULE_FIRMWARE() specifiers */
184#define MODULE_FIRMWARE(_firmware) MODULE_INFO(firmware, _firmware)
185
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186/* Given an address, look for it in the exception tables */
187const struct exception_table_entry *search_exception_tables(unsigned long add);
188
189struct notifier_block;
190
191#ifdef CONFIG_MODULES
192
Dave Young5ed10912010-03-10 15:24:06 -0800193extern int modules_disabled; /* for sysctl */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194/* Get/put a kernel symbol (calls must be symmetric) */
195void *__symbol_get(const char *symbol);
196void *__symbol_get_gpl(const char *symbol);
197#define symbol_get(x) ((typeof(&x))(__symbol_get(MODULE_SYMBOL_PREFIX #x)))
198
Rusty Russellc8e21ce2010-06-05 11:17:35 -0600199/* modules using other modules: kdb wants to see this. */
200struct module_use {
201 struct list_head source_list;
202 struct list_head target_list;
203 struct module *source, *target;
204};
205
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206enum module_state
207{
208 MODULE_STATE_LIVE,
209 MODULE_STATE_COMING,
210 MODULE_STATE_GOING,
211};
212
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213struct module
214{
215 enum module_state state;
216
217 /* Member of list of modules */
218 struct list_head list;
219
220 /* Unique handle for this module */
221 char name[MODULE_NAME_LEN];
222
223 /* Sysfs stuff. */
224 struct module_kobject mkobj;
Greg Kroah-Hartman03e88ae12006-02-16 13:50:23 -0800225 struct module_attribute *modinfo_attrs;
Matt Domschc988d2b2005-06-23 22:05:15 -0700226 const char *version;
227 const char *srcversion;
Kay Sievers270a6c42007-01-18 13:26:15 +0100228 struct kobject *holders_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229
230 /* Exported symbols */
231 const struct kernel_symbol *syms;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 const unsigned long *crcs;
Richard Kennedyaf540682008-07-22 19:24:26 -0500233 unsigned int num_syms;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234
Rusty Russelle180a6b2009-03-31 13:05:29 -0600235 /* Kernel parameters. */
236 struct kernel_param *kp;
237 unsigned int num_kp;
238
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239 /* GPL-only exported symbols. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 unsigned int num_gpl_syms;
Richard Kennedyaf540682008-07-22 19:24:26 -0500241 const struct kernel_symbol *gpl_syms;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 const unsigned long *gpl_crcs;
243
Denys Vlasenkof7f5b672008-07-22 19:24:26 -0500244#ifdef CONFIG_UNUSED_SYMBOLS
Arjan van de Venf71d20e2006-06-28 04:26:45 -0700245 /* unused exported symbols. */
246 const struct kernel_symbol *unused_syms;
Arjan van de Venf71d20e2006-06-28 04:26:45 -0700247 const unsigned long *unused_crcs;
Richard Kennedyaf540682008-07-22 19:24:26 -0500248 unsigned int num_unused_syms;
249
Arjan van de Venf71d20e2006-06-28 04:26:45 -0700250 /* GPL-only, unused exported symbols. */
Arjan van de Venf71d20e2006-06-28 04:26:45 -0700251 unsigned int num_unused_gpl_syms;
Richard Kennedyaf540682008-07-22 19:24:26 -0500252 const struct kernel_symbol *unused_gpl_syms;
Arjan van de Venf71d20e2006-06-28 04:26:45 -0700253 const unsigned long *unused_gpl_crcs;
Denys Vlasenkof7f5b672008-07-22 19:24:26 -0500254#endif
Arjan van de Venf71d20e2006-06-28 04:26:45 -0700255
Greg Kroah-Hartman9f28bb72006-03-20 13:17:13 -0800256 /* symbols that will be GPL-only in the near future. */
257 const struct kernel_symbol *gpl_future_syms;
Greg Kroah-Hartman9f28bb72006-03-20 13:17:13 -0800258 const unsigned long *gpl_future_crcs;
Richard Kennedyaf540682008-07-22 19:24:26 -0500259 unsigned int num_gpl_future_syms;
Greg Kroah-Hartman9f28bb72006-03-20 13:17:13 -0800260
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261 /* Exception table */
262 unsigned int num_exentries;
Rusty Russell5e458cc2008-10-22 10:00:13 -0500263 struct exception_table_entry *extable;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264
265 /* Startup function. */
266 int (*init)(void);
267
268 /* If this is non-NULL, vfree after init() returns */
269 void *module_init;
270
271 /* Here is the actual code + data, vfree'd on unload. */
272 void *module_core;
273
274 /* Here are the sizes of the init and core sections */
Denys Vlasenko2f0f2a32008-07-22 19:24:27 -0500275 unsigned int init_size, core_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276
277 /* The size of the executable code in each section. */
Denys Vlasenko2f0f2a32008-07-22 19:24:27 -0500278 unsigned int init_text_size, core_text_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279
matthieu castet84e1c6b2010-11-16 22:35:16 +0100280 /* Size of RO sections of the module (text+rodata) */
281 unsigned int init_ro_size, core_ro_size;
282
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 /* Arch-specific module values */
284 struct mod_arch_specific arch;
285
Randy Dunlap2bc2d612006-10-02 02:17:02 -0700286 unsigned int taints; /* same bits as kernel:tainted */
287
Jeremy Fitzhardinge7664c5a2006-12-08 02:36:19 -0800288#ifdef CONFIG_GENERIC_BUG
289 /* Support for BUG */
Richard Kennedyaf540682008-07-22 19:24:26 -0500290 unsigned num_bugs;
Jeremy Fitzhardinge7664c5a2006-12-08 02:36:19 -0800291 struct list_head bug_list;
292 struct bug_entry *bug_table;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293#endif
294
295#ifdef CONFIG_KALLSYMS
Jan Beulich4a496222009-07-06 14:50:42 +0100296 /*
297 * We keep the symbol and string tables for kallsyms.
298 * The core_* fields below are temporary, loader-only (they
299 * could really be discarded after module init).
300 */
301 Elf_Sym *symtab, *core_symtab;
302 unsigned int num_symtab, core_num_syms;
Jan Beulich554bdfe2009-07-06 14:51:44 +0100303 char *strtab, *core_strtab;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304
305 /* Section attributes */
306 struct module_sect_attrs *sect_attrs;
Roland McGrath6d760132007-10-16 23:26:40 -0700307
308 /* Notes attributes */
309 struct module_notes_attrs *notes_attrs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310#endif
311
Richard Kennedya288bd62011-05-19 16:55:25 -0600312 /* The command line arguments (may be mangled). People like
313 keeping pointers to this stuff */
314 char *args;
315
Tejun Heo259354d2010-03-10 18:56:10 +0900316#ifdef CONFIG_SMP
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 /* Per-cpu data. */
Tejun Heo259354d2010-03-10 18:56:10 +0900318 void __percpu *percpu;
319 unsigned int percpu_size;
320#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321
Mathieu Desnoyers97e1c182008-07-18 12:16:16 -0400322#ifdef CONFIG_TRACEPOINTS
Mathieu Desnoyers97e1c182008-07-18 12:16:16 -0400323 unsigned int num_tracepoints;
Richard Kennedya288bd62011-05-19 16:55:25 -0600324 struct tracepoint * const *tracepoints_ptrs;
Mathieu Desnoyers97e1c182008-07-18 12:16:16 -0400325#endif
Jason Baronbf5438fc2010-09-17 11:09:00 -0400326#ifdef HAVE_JUMP_LABEL
327 struct jump_entry *jump_entries;
328 unsigned int num_jump_entries;
329#endif
Frederic Weisbecker769b0442009-03-06 17:21:49 +0100330#ifdef CONFIG_TRACING
Lai Jiangshan1ba28e02009-03-06 17:21:48 +0100331 unsigned int num_trace_bprintk_fmt;
Richard Kennedya288bd62011-05-19 16:55:25 -0600332 const char **trace_bprintk_fmt_start;
Lai Jiangshan1ba28e02009-03-06 17:21:48 +0100333#endif
Steven Rostedt6d723732009-04-10 14:53:50 -0400334#ifdef CONFIG_EVENT_TRACING
Steven Rostedte4a9ea52011-01-27 09:15:30 -0500335 struct ftrace_event_call **trace_events;
Steven Rostedt6d723732009-04-10 14:53:50 -0400336 unsigned int num_trace_events;
337#endif
Steven Rostedt93eb6772009-04-15 13:24:06 -0400338#ifdef CONFIG_FTRACE_MCOUNT_RECORD
Steven Rostedt93eb6772009-04-15 13:24:06 -0400339 unsigned int num_ftrace_callsites;
Richard Kennedya288bd62011-05-19 16:55:25 -0600340 unsigned long *ftrace_callsites;
Steven Rostedt93eb6772009-04-15 13:24:06 -0400341#endif
Lai Jiangshan1ba28e02009-03-06 17:21:48 +0100342
Richard Kennedyaf540682008-07-22 19:24:26 -0500343#ifdef CONFIG_MODULE_UNLOAD
344 /* What modules depend on me? */
Linus Torvalds2c02dfe2010-05-31 12:19:37 -0700345 struct list_head source_list;
346 /* What modules do I depend on? */
347 struct list_head target_list;
Richard Kennedyaf540682008-07-22 19:24:26 -0500348
349 /* Who is waiting for us to be unloaded */
350 struct task_struct *waiter;
351
352 /* Destruction function. */
353 void (*exit)(void);
354
Christoph Lametere1783a22010-01-05 15:34:50 +0900355 struct module_ref {
Nick Piggin5fbfb182010-04-01 19:09:40 +1100356 unsigned int incs;
357 unsigned int decs;
Tejun Heo43cf38e2010-02-02 14:38:57 +0900358 } __percpu *refptr;
Richard Kennedyaf540682008-07-22 19:24:26 -0500359#endif
Peter Oberparleiterb99b87f2009-06-17 16:28:03 -0700360
361#ifdef CONFIG_CONSTRUCTORS
362 /* Constructor functions. */
363 ctor_fn_t *ctors;
364 unsigned int num_ctors;
365#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366};
Roman Zippele61a1c12007-05-09 02:35:15 -0700367#ifndef MODULE_ARCH_INIT
368#define MODULE_ARCH_INIT {}
369#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370
Tim Abbottc6b37802008-12-05 19:03:59 -0500371extern struct mutex module_mutex;
372
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373/* FIXME: It'd be nice to isolate modules during init, too, so they
374 aren't used before they (may) fail. But presently too much code
375 (IDE & SCSI) require entry into the module during init.*/
376static inline int module_is_live(struct module *mod)
377{
378 return mod->state != MODULE_STATE_GOING;
379}
380
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381struct module *__module_text_address(unsigned long addr);
Rusty Russelle6104992009-03-31 13:05:31 -0600382struct module *__module_address(unsigned long addr);
383bool is_module_address(unsigned long addr);
Tejun Heo10fad5e2010-03-10 18:57:54 +0900384bool is_module_percpu_address(unsigned long addr);
Rusty Russelle6104992009-03-31 13:05:31 -0600385bool is_module_text_address(unsigned long addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386
Masami Hiramatsua06f6212009-01-06 14:41:49 -0800387static inline int within_module_core(unsigned long addr, struct module *mod)
388{
389 return (unsigned long)mod->module_core <= addr &&
390 addr < (unsigned long)mod->module_core + mod->core_size;
391}
392
393static inline int within_module_init(unsigned long addr, struct module *mod)
394{
395 return (unsigned long)mod->module_init <= addr &&
396 addr < (unsigned long)mod->module_init + mod->init_size;
397}
398
Tim Abbottc6b37802008-12-05 19:03:59 -0500399/* Search for module by name: must hold module_mutex. */
400struct module *find_module(const char *name);
401
402struct symsearch {
403 const struct kernel_symbol *start, *stop;
404 const unsigned long *crcs;
405 enum {
406 NOT_GPL_ONLY,
407 GPL_ONLY,
408 WILL_BE_GPL_ONLY,
409 } licence;
410 bool unused;
411};
412
413/* Search for an exported symbol by name. */
414const struct kernel_symbol *find_symbol(const char *name,
415 struct module **owner,
416 const unsigned long **crc,
417 bool gplok,
418 bool warn);
419
420/* Walk the exported symbol table */
Rusty Russellde4d8d52011-04-19 21:49:58 +0200421bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
422 struct module *owner,
423 void *data), void *data);
Tim Abbottc6b37802008-12-05 19:03:59 -0500424
Alexey Dobriyanea078902007-05-08 00:28:39 -0700425/* Returns 0 and fills in value, defined and namebuf, or -ERANGE if
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 symnum out of range. */
Alexey Dobriyanea078902007-05-08 00:28:39 -0700427int module_get_kallsym(unsigned int symnum, unsigned long *value, char *type,
428 char *name, char *module_name, int *exported);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429
430/* Look for this name: can be of form module:name. */
431unsigned long module_kallsyms_lookup_name(const char *name);
432
Anders Kaseorg75a66612008-12-05 19:03:58 -0500433int module_kallsyms_on_each_symbol(int (*fn)(void *, const char *,
434 struct module *, unsigned long),
435 void *data);
436
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437extern void __module_put_and_exit(struct module *mod, long code)
438 __attribute__((noreturn));
439#define module_put_and_exit(code) __module_put_and_exit(THIS_MODULE, code);
440
441#ifdef CONFIG_MODULE_UNLOAD
442unsigned int module_refcount(struct module *mod);
443void __symbol_put(const char *symbol);
444#define symbol_put(x) __symbol_put(MODULE_SYMBOL_PREFIX #x)
445void symbol_put_addr(void *addr);
446
447/* Sometimes we know we already have a refcount, and it's easier not
448 to handle the error case (which only happens with rmmod --wait). */
449static inline void __module_get(struct module *module)
450{
451 if (module) {
Christoph Lametere1783a22010-01-05 15:34:50 +0900452 preempt_disable();
Nick Piggin5fbfb182010-04-01 19:09:40 +1100453 __this_cpu_inc(module->refptr->incs);
Li Zefanae832d12010-03-24 10:57:43 +0800454 trace_module_get(module, _THIS_IP_);
Christoph Lametere1783a22010-01-05 15:34:50 +0900455 preempt_enable();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 }
457}
458
459static inline int try_module_get(struct module *module)
460{
461 int ret = 1;
462
463 if (module) {
Christoph Lametere1783a22010-01-05 15:34:50 +0900464 preempt_disable();
465
Li Zefan7ead8b82009-08-17 16:56:28 +0800466 if (likely(module_is_live(module))) {
Nick Piggin5fbfb182010-04-01 19:09:40 +1100467 __this_cpu_inc(module->refptr->incs);
Li Zefanae832d12010-03-24 10:57:43 +0800468 trace_module_get(module, _THIS_IP_);
Nick Piggin5fbfb182010-04-01 19:09:40 +1100469 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 ret = 0;
Christoph Lametere1783a22010-01-05 15:34:50 +0900471
472 preempt_enable();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 }
474 return ret;
475}
476
Al Virof6a57032006-10-18 01:47:25 -0400477extern void module_put(struct module *module);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478
479#else /*!CONFIG_MODULE_UNLOAD*/
480static inline int try_module_get(struct module *module)
481{
482 return !module || module_is_live(module);
483}
484static inline void module_put(struct module *module)
485{
486}
487static inline void __module_get(struct module *module)
488{
489}
490#define symbol_put(x) do { } while(0)
491#define symbol_put_addr(p) do { } while(0)
492
493#endif /* CONFIG_MODULE_UNLOAD */
Anders Kaseorgdfd62d12010-11-24 15:21:10 -0600494int ref_module(struct module *a, struct module *b);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495
496/* This is a #define so the string doesn't get put in every .o file */
497#define module_name(mod) \
498({ \
499 struct module *__mod = (mod); \
500 __mod ? __mod->name : "kernel"; \
501})
502
Rusty Russell6dd06c92008-01-29 17:13:22 -0500503/* For kallsyms to ask for address resolution. namebuf should be at
504 * least KSYM_NAME_LEN long: a pointer to namebuf is returned if
505 * found, otherwise NULL. */
Andrew Morton92dfc9d2008-02-08 04:18:43 -0800506const char *module_address_lookup(unsigned long addr,
Rusty Russell6dd06c92008-01-29 17:13:22 -0500507 unsigned long *symbolsize,
508 unsigned long *offset,
509 char **modname,
510 char *namebuf);
Alexey Dobriyan9d65cb42007-05-08 00:28:43 -0700511int lookup_module_symbol_name(unsigned long addr, char *symname);
Alexey Dobriyana5c43da2007-05-08 00:28:47 -0700512int lookup_module_symbol_attrs(unsigned long addr, unsigned long *size, unsigned long *offset, char *modname, char *name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513
514/* For extable.c to search modules' exception tables. */
515const struct exception_table_entry *search_module_extables(unsigned long addr);
516
517int register_module_notifier(struct notifier_block * nb);
518int unregister_module_notifier(struct notifier_block * nb);
519
520extern void print_modules(void);
521
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522#else /* !CONFIG_MODULES... */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523
524/* Given an address, look for it in the exception tables. */
525static inline const struct exception_table_entry *
526search_module_extables(unsigned long addr)
527{
528 return NULL;
529}
530
Rusty Russelle6104992009-03-31 13:05:31 -0600531static inline struct module *__module_address(unsigned long addr)
532{
533 return NULL;
534}
535
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536static inline struct module *__module_text_address(unsigned long addr)
537{
538 return NULL;
539}
540
Rusty Russelle6104992009-03-31 13:05:31 -0600541static inline bool is_module_address(unsigned long addr)
Ingo Molnar4d435f92006-07-03 00:24:24 -0700542{
Rusty Russelle6104992009-03-31 13:05:31 -0600543 return false;
544}
545
Randy Dunlapd5e50da2010-03-31 11:33:42 +0900546static inline bool is_module_percpu_address(unsigned long addr)
547{
548 return false;
549}
550
Rusty Russelle6104992009-03-31 13:05:31 -0600551static inline bool is_module_text_address(unsigned long addr)
552{
553 return false;
Ingo Molnar4d435f92006-07-03 00:24:24 -0700554}
555
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556/* Get/put a kernel symbol (calls should be symmetric) */
557#define symbol_get(x) ({ extern typeof(x) x __attribute__((weak)); &(x); })
558#define symbol_put(x) do { } while(0)
559#define symbol_put_addr(x) do { } while(0)
560
561static inline void __module_get(struct module *module)
562{
563}
564
565static inline int try_module_get(struct module *module)
566{
567 return 1;
568}
569
570static inline void module_put(struct module *module)
571{
572}
573
574#define module_name(mod) "kernel"
575
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576/* For kallsyms to ask for address resolution. NULL means not found. */
Andrew Morton92dfc9d2008-02-08 04:18:43 -0800577static inline const char *module_address_lookup(unsigned long addr,
Rusty Russell6dd06c92008-01-29 17:13:22 -0500578 unsigned long *symbolsize,
579 unsigned long *offset,
580 char **modname,
581 char *namebuf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582{
583 return NULL;
584}
585
Alexey Dobriyan9d65cb42007-05-08 00:28:43 -0700586static inline int lookup_module_symbol_name(unsigned long addr, char *symname)
587{
588 return -ERANGE;
589}
590
Alexey Dobriyana5c43da2007-05-08 00:28:47 -0700591static inline int lookup_module_symbol_attrs(unsigned long addr, unsigned long *size, unsigned long *offset, char *modname, char *name)
592{
593 return -ERANGE;
594}
595
Alexey Dobriyanea078902007-05-08 00:28:39 -0700596static inline int module_get_kallsym(unsigned int symnum, unsigned long *value,
597 char *type, char *name,
598 char *module_name, int *exported)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599{
Alexey Dobriyanea078902007-05-08 00:28:39 -0700600 return -ERANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601}
602
603static inline unsigned long module_kallsyms_lookup_name(const char *name)
604{
605 return 0;
606}
607
Anders Kaseorg75a66612008-12-05 19:03:58 -0500608static inline int module_kallsyms_on_each_symbol(int (*fn)(void *, const char *,
609 struct module *,
610 unsigned long),
611 void *data)
612{
613 return 0;
614}
615
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616static inline int register_module_notifier(struct notifier_block * nb)
617{
618 /* no events will happen anyway, so this can always succeed */
619 return 0;
620}
621
622static inline int unregister_module_notifier(struct notifier_block * nb)
623{
624 return 0;
625}
626
627#define module_put_and_exit(code) do_exit(code)
628
629static inline void print_modules(void)
630{
631}
Randy Dunlapef665c12007-02-13 15:19:06 -0800632#endif /* CONFIG_MODULES */
633
Randy Dunlapef665c12007-02-13 15:19:06 -0800634#ifdef CONFIG_SYSFS
Greg Kroah-Hartman7405c1e2007-11-01 10:39:50 -0700635extern struct kset *module_kset;
636extern struct kobj_type module_ktype;
637extern int module_sysfs_initialized;
Randy Dunlapef665c12007-02-13 15:19:06 -0800638#endif /* CONFIG_SYSFS */
639
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640#define symbol_request(x) try_then_request_module(symbol_get(x), "symbol:" #x)
641
642/* BELOW HERE ALL THESE ARE OBSOLETE AND WILL VANISH */
643
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644#define __MODULE_STRING(x) __stringify(x)
645
matthieu castet84e1c6b2010-11-16 22:35:16 +0100646#ifdef CONFIG_DEBUG_SET_MODULE_RONX
647extern void set_all_modules_text_rw(void);
648extern void set_all_modules_text_ro(void);
649#else
650static inline void set_all_modules_text_rw(void) { }
651static inline void set_all_modules_text_ro(void) { }
652#endif
Andrew Morton0d9c25d2009-06-16 15:33:37 -0700653
654#ifdef CONFIG_GENERIC_BUG
Linus Torvalds53363772010-10-05 11:29:27 -0700655void module_bug_finalize(const Elf_Ehdr *, const Elf_Shdr *,
Andrew Morton0d9c25d2009-06-16 15:33:37 -0700656 struct module *);
657void module_bug_cleanup(struct module *);
658
659#else /* !CONFIG_GENERIC_BUG */
660
Linus Torvalds53363772010-10-05 11:29:27 -0700661static inline void module_bug_finalize(const Elf_Ehdr *hdr,
Andrew Morton0d9c25d2009-06-16 15:33:37 -0700662 const Elf_Shdr *sechdrs,
663 struct module *mod)
664{
Andrew Morton0d9c25d2009-06-16 15:33:37 -0700665}
666static inline void module_bug_cleanup(struct module *mod) {}
667#endif /* CONFIG_GENERIC_BUG */
668
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669#endif /* _LINUX_MODULE_H */