blob: 23996ad147e7a212159bfd7a01cdbf074f7be792 [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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019
Christoph Lametere1783a22010-01-05 15:34:50 +090020#include <linux/percpu.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <asm/module.h>
22
Li Zefan7ead8b82009-08-17 16:56:28 +080023#include <trace/events/module.h>
24
Linus Torvalds1da177e2005-04-16 15:20:36 -070025/* Not Yet Implemented */
26#define MODULE_SUPPORTED_DEVICE(name)
27
Alan Jenkins9e1b9b82009-11-07 21:03:54 +000028/* Some toolchains use a `_' prefix for all user symbols. */
29#ifdef CONFIG_SYMBOL_PREFIX
30#define MODULE_SYMBOL_PREFIX CONFIG_SYMBOL_PREFIX
31#else
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#define MODULE_SYMBOL_PREFIX ""
33#endif
34
Rusty Russell730b69d2008-10-22 10:00:22 -050035#define MODULE_NAME_LEN MAX_PARAM_PREFIX_LEN
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
37struct kernel_symbol
38{
39 unsigned long value;
40 const char *name;
41};
42
43struct modversion_info
44{
45 unsigned long crc;
46 char name[MODULE_NAME_LEN];
47};
48
49struct module;
50
51struct 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);
Matt Domschc988d2b2005-06-23 22:05:15 -070056 void (*setup)(struct module *, const char *);
57 int (*test)(struct module *);
58 void (*free)(struct module *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070059};
60
Dmitry Torokhove94965e2010-12-15 14:00:19 -080061struct module_version_attribute {
62 struct module_attribute mattr;
63 const char *module_name;
64 const char *version;
Dmitry Torokhov98562ad2011-02-04 13:30:10 -080065} __attribute__ ((__aligned__(sizeof(void *))));
Dmitry Torokhove94965e2010-12-15 14:00:19 -080066
Dmitry Torokhov9b73a582011-02-07 16:02:27 -080067extern ssize_t __modver_version_show(struct module_attribute *,
68 struct module *, char *);
69
Linus Torvalds1da177e2005-04-16 15:20:36 -070070struct module_kobject
71{
72 struct kobject kobj;
73 struct module *mod;
Kay Sieversf30c53a2007-01-15 20:22:02 +010074 struct kobject *drivers_dir;
Rusty Russell9b473de2008-10-22 10:00:22 -050075 struct module_param_attrs *mp;
Linus Torvalds1da177e2005-04-16 15:20:36 -070076};
77
78/* These are either module local, or the kernel's dummy ones. */
79extern int init_module(void);
80extern void cleanup_module(void);
81
82/* Archs provide a method of finding the correct exception table. */
83struct exception_table_entry;
84
85const struct exception_table_entry *
86search_extable(const struct exception_table_entry *first,
87 const struct exception_table_entry *last,
88 unsigned long value);
89void sort_extable(struct exception_table_entry *start,
90 struct exception_table_entry *finish);
91void sort_main_extable(void);
Rusty Russellad6561d2009-06-12 21:47:03 -060092void trim_init_extable(struct module *m);
Linus Torvalds1da177e2005-04-16 15:20:36 -070093
Linus Torvalds1da177e2005-04-16 15:20:36 -070094#ifdef MODULE
95#define MODULE_GENERIC_TABLE(gtype,name) \
96extern const struct gtype##_id __mod_##gtype##_table \
97 __attribute__ ((unused, alias(__stringify(name))))
98
99extern 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]
Xose Vazquez Perez8d27e902006-06-23 02:05:13 -0700121 * "Dual MIT/GPL" [GNU Public License v2
122 * or MIT license choice]
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 * "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
Johannes Berg1d7015c2009-09-25 00:32:58 -0600142/*
143 * Author(s), use "Name <email>" or just "Name", for multiple
144 * authors use multiple MODULE_AUTHOR() statements/lines.
145 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146#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*/
Dmitry Torokhove94965e2010-12-15 14:00:19 -0800173
Rusty Russell3b90a5b2011-01-24 14:32:51 -0600174#if defined(MODULE) || !defined(CONFIG_SYSFS)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175#define MODULE_VERSION(_version) MODULE_INFO(version, _version)
Dmitry Torokhove94965e2010-12-15 14:00:19 -0800176#else
177#define MODULE_VERSION(_version) \
Dmitry Torokhovb4bc84282011-02-07 16:02:25 -0800178 static struct module_version_attribute ___modver_attr = { \
Dmitry Torokhove94965e2010-12-15 14:00:19 -0800179 .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, \
Dmitry Torokhovb4bc84282011-02-07 16:02:25 -0800188 }; \
189 static const struct module_version_attribute \
190 __used __attribute__ ((__section__ ("__modver"))) \
191 * __moduleparam_const __modver_attr = &___modver_attr
Dmitry Torokhove94965e2010-12-15 14:00:19 -0800192#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193
Jon Masters187afbe2006-08-28 17:08:21 -0500194/* 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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199/* Given an address, look for it in the exception tables */
200const struct exception_table_entry *search_exception_tables(unsigned long add);
201
202struct notifier_block;
203
204#ifdef CONFIG_MODULES
205
Dave Young5ed10912010-03-10 15:24:06 -0800206extern int modules_disabled; /* for sysctl */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207/* Get/put a kernel symbol (calls must be symmetric) */
208void *__symbol_get(const char *symbol);
209void *__symbol_get_gpl(const char *symbol);
210#define symbol_get(x) ((typeof(&x))(__symbol_get(MODULE_SYMBOL_PREFIX #x)))
211
Rusty Russellc8e21ce2010-06-05 11:17:35 -0600212/* modules using other modules: kdb wants to see this. */
213struct module_use {
214 struct list_head source_list;
215 struct list_head target_list;
216 struct module *source, *target;
217};
218
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219#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 \
Adrian Bunk3ff6eec2008-01-24 22:16:20 +0100226 __used \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 __attribute__((section("__kcrctab" sec), unused)) \
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) \
Patrick McHardya1a8fee2006-03-23 22:07:34 -0800235 extern typeof(sym) sym; \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 __CRC_SYMBOL(sym, sec) \
237 static const char __kstrtab_##sym[] \
Rusty Russellea01e792008-03-13 09:02:17 +0000238 __attribute__((section("__ksymtab_strings"), aligned(1))) \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239 = MODULE_SYMBOL_PREFIX #sym; \
240 static const struct kernel_symbol __ksymtab_##sym \
Adrian Bunk3ff6eec2008-01-24 22:16:20 +0100241 __used \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 __attribute__((section("__ksymtab" sec), unused)) \
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
Greg Kroah-Hartman9f28bb72006-03-20 13:17:13 -0800251#define EXPORT_SYMBOL_GPL_FUTURE(sym) \
252 __EXPORT_SYMBOL(sym, "_gpl_future")
253
Arjan van de Venf71d20e2006-06-28 04:26:45 -0700254
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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263#endif
264
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265enum module_state
266{
267 MODULE_STATE_LIVE,
268 MODULE_STATE_COMING,
269 MODULE_STATE_GOING,
270};
271
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272struct 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;
Greg Kroah-Hartman03e88ae2006-02-16 13:50:23 -0800284 struct module_attribute *modinfo_attrs;
Matt Domschc988d2b2005-06-23 22:05:15 -0700285 const char *version;
286 const char *srcversion;
Kay Sievers270a6c42007-01-18 13:26:15 +0100287 struct kobject *holders_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288
289 /* Exported symbols */
290 const struct kernel_symbol *syms;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 const unsigned long *crcs;
Richard Kennedyaf540682008-07-22 19:24:26 -0500292 unsigned int num_syms;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293
Rusty Russelle180a6b2009-03-31 13:05:29 -0600294 /* Kernel parameters. */
295 struct kernel_param *kp;
296 unsigned int num_kp;
297
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 /* GPL-only exported symbols. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 unsigned int num_gpl_syms;
Richard Kennedyaf540682008-07-22 19:24:26 -0500300 const struct kernel_symbol *gpl_syms;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 const unsigned long *gpl_crcs;
302
Denys Vlasenkof7f5b672008-07-22 19:24:26 -0500303#ifdef CONFIG_UNUSED_SYMBOLS
Arjan van de Venf71d20e2006-06-28 04:26:45 -0700304 /* unused exported symbols. */
305 const struct kernel_symbol *unused_syms;
Arjan van de Venf71d20e2006-06-28 04:26:45 -0700306 const unsigned long *unused_crcs;
Richard Kennedyaf540682008-07-22 19:24:26 -0500307 unsigned int num_unused_syms;
308
Arjan van de Venf71d20e2006-06-28 04:26:45 -0700309 /* GPL-only, unused exported symbols. */
Arjan van de Venf71d20e2006-06-28 04:26:45 -0700310 unsigned int num_unused_gpl_syms;
Richard Kennedyaf540682008-07-22 19:24:26 -0500311 const struct kernel_symbol *unused_gpl_syms;
Arjan van de Venf71d20e2006-06-28 04:26:45 -0700312 const unsigned long *unused_gpl_crcs;
Denys Vlasenkof7f5b672008-07-22 19:24:26 -0500313#endif
Arjan van de Venf71d20e2006-06-28 04:26:45 -0700314
Greg Kroah-Hartman9f28bb72006-03-20 13:17:13 -0800315 /* symbols that will be GPL-only in the near future. */
316 const struct kernel_symbol *gpl_future_syms;
Greg Kroah-Hartman9f28bb72006-03-20 13:17:13 -0800317 const unsigned long *gpl_future_crcs;
Richard Kennedyaf540682008-07-22 19:24:26 -0500318 unsigned int num_gpl_future_syms;
Greg Kroah-Hartman9f28bb72006-03-20 13:17:13 -0800319
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 /* Exception table */
321 unsigned int num_exentries;
Rusty Russell5e458cc2008-10-22 10:00:13 -0500322 struct exception_table_entry *extable;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323
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 */
Denys Vlasenko2f0f2a32008-07-22 19:24:27 -0500334 unsigned int init_size, core_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335
336 /* The size of the executable code in each section. */
Denys Vlasenko2f0f2a32008-07-22 19:24:27 -0500337 unsigned int init_text_size, core_text_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338
matthieu castet84e1c6b2010-11-16 22:35:16 +0100339 /* Size of RO sections of the module (text+rodata) */
340 unsigned int init_ro_size, core_ro_size;
341
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 /* Arch-specific module values */
343 struct mod_arch_specific arch;
344
Randy Dunlap2bc2d612006-10-02 02:17:02 -0700345 unsigned int taints; /* same bits as kernel:tainted */
346
Jeremy Fitzhardinge7664c5a2006-12-08 02:36:19 -0800347#ifdef CONFIG_GENERIC_BUG
348 /* Support for BUG */
Richard Kennedyaf540682008-07-22 19:24:26 -0500349 unsigned num_bugs;
Jeremy Fitzhardinge7664c5a2006-12-08 02:36:19 -0800350 struct list_head bug_list;
351 struct bug_entry *bug_table;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352#endif
353
354#ifdef CONFIG_KALLSYMS
Jan Beulich4a496222009-07-06 14:50:42 +0100355 /*
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;
Jan Beulich554bdfe2009-07-06 14:51:44 +0100362 char *strtab, *core_strtab;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363
364 /* Section attributes */
365 struct module_sect_attrs *sect_attrs;
Roland McGrath6d760132007-10-16 23:26:40 -0700366
367 /* Notes attributes */
368 struct module_notes_attrs *notes_attrs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369#endif
370
Tejun Heo259354d2010-03-10 18:56:10 +0900371#ifdef CONFIG_SMP
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 /* Per-cpu data. */
Tejun Heo259354d2010-03-10 18:56:10 +0900373 void __percpu *percpu;
374 unsigned int percpu_size;
375#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376
377 /* The command line arguments (may be mangled). People like
378 keeping pointers to this stuff */
379 char *args;
Mathieu Desnoyers97e1c182008-07-18 12:16:16 -0400380#ifdef CONFIG_TRACEPOINTS
Mathieu Desnoyers65498642011-01-26 17:26:22 -0500381 struct tracepoint * const *tracepoints_ptrs;
Mathieu Desnoyers97e1c182008-07-18 12:16:16 -0400382 unsigned int num_tracepoints;
383#endif
Jason Baronbf5438fc2010-09-17 11:09:00 -0400384#ifdef HAVE_JUMP_LABEL
385 struct jump_entry *jump_entries;
386 unsigned int num_jump_entries;
387#endif
Frederic Weisbecker769b0442009-03-06 17:21:49 +0100388#ifdef CONFIG_TRACING
Lai Jiangshan1ba28e02009-03-06 17:21:48 +0100389 const char **trace_bprintk_fmt_start;
390 unsigned int num_trace_bprintk_fmt;
391#endif
Steven Rostedt6d723732009-04-10 14:53:50 -0400392#ifdef CONFIG_EVENT_TRACING
Steven Rostedte4a9ea52011-01-27 09:15:30 -0500393 struct ftrace_event_call **trace_events;
Steven Rostedt6d723732009-04-10 14:53:50 -0400394 unsigned int num_trace_events;
395#endif
Steven Rostedt93eb6772009-04-15 13:24:06 -0400396#ifdef CONFIG_FTRACE_MCOUNT_RECORD
397 unsigned long *ftrace_callsites;
398 unsigned int num_ftrace_callsites;
399#endif
Lai Jiangshan1ba28e02009-03-06 17:21:48 +0100400
Richard Kennedyaf540682008-07-22 19:24:26 -0500401#ifdef CONFIG_MODULE_UNLOAD
402 /* What modules depend on me? */
Linus Torvalds2c02dfe2010-05-31 12:19:37 -0700403 struct list_head source_list;
404 /* What modules do I depend on? */
405 struct list_head target_list;
Richard Kennedyaf540682008-07-22 19:24:26 -0500406
407 /* Who is waiting for us to be unloaded */
408 struct task_struct *waiter;
409
410 /* Destruction function. */
411 void (*exit)(void);
412
Christoph Lametere1783a22010-01-05 15:34:50 +0900413 struct module_ref {
Nick Piggin5fbfb182010-04-01 19:09:40 +1100414 unsigned int incs;
415 unsigned int decs;
Tejun Heo43cf38e2010-02-02 14:38:57 +0900416 } __percpu *refptr;
Richard Kennedyaf540682008-07-22 19:24:26 -0500417#endif
Peter Oberparleiterb99b87f2009-06-17 16:28:03 -0700418
419#ifdef CONFIG_CONSTRUCTORS
420 /* Constructor functions. */
421 ctor_fn_t *ctors;
422 unsigned int num_ctors;
423#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424};
Roman Zippele61a1c12007-05-09 02:35:15 -0700425#ifndef MODULE_ARCH_INIT
426#define MODULE_ARCH_INIT {}
427#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428
Tim Abbottc6b37802008-12-05 19:03:59 -0500429extern struct mutex module_mutex;
430
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431/* FIXME: It'd be nice to isolate modules during init, too, so they
432 aren't used before they (may) fail. But presently too much code
433 (IDE & SCSI) require entry into the module during init.*/
434static inline int module_is_live(struct module *mod)
435{
436 return mod->state != MODULE_STATE_GOING;
437}
438
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439struct module *__module_text_address(unsigned long addr);
Rusty Russelle6104992009-03-31 13:05:31 -0600440struct module *__module_address(unsigned long addr);
441bool is_module_address(unsigned long addr);
Tejun Heo10fad5e2010-03-10 18:57:54 +0900442bool is_module_percpu_address(unsigned long addr);
Rusty Russelle6104992009-03-31 13:05:31 -0600443bool is_module_text_address(unsigned long addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444
Masami Hiramatsua06f6212009-01-06 14:41:49 -0800445static inline int within_module_core(unsigned long addr, struct module *mod)
446{
447 return (unsigned long)mod->module_core <= addr &&
448 addr < (unsigned long)mod->module_core + mod->core_size;
449}
450
451static inline int within_module_init(unsigned long addr, struct module *mod)
452{
453 return (unsigned long)mod->module_init <= addr &&
454 addr < (unsigned long)mod->module_init + mod->init_size;
455}
456
Tim Abbottc6b37802008-12-05 19:03:59 -0500457/* Search for module by name: must hold module_mutex. */
458struct module *find_module(const char *name);
459
460struct symsearch {
461 const struct kernel_symbol *start, *stop;
462 const unsigned long *crcs;
463 enum {
464 NOT_GPL_ONLY,
465 GPL_ONLY,
466 WILL_BE_GPL_ONLY,
467 } licence;
468 bool unused;
469};
470
471/* Search for an exported symbol by name. */
472const struct kernel_symbol *find_symbol(const char *name,
473 struct module **owner,
474 const unsigned long **crc,
475 bool gplok,
476 bool warn);
477
478/* Walk the exported symbol table */
479bool each_symbol(bool (*fn)(const struct symsearch *arr, struct module *owner,
480 unsigned int symnum, void *data), void *data);
481
Alexey Dobriyanea078902007-05-08 00:28:39 -0700482/* Returns 0 and fills in value, defined and namebuf, or -ERANGE if
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 symnum out of range. */
Alexey Dobriyanea078902007-05-08 00:28:39 -0700484int module_get_kallsym(unsigned int symnum, unsigned long *value, char *type,
485 char *name, char *module_name, int *exported);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486
487/* Look for this name: can be of form module:name. */
488unsigned long module_kallsyms_lookup_name(const char *name);
489
Anders Kaseorg75a66612008-12-05 19:03:58 -0500490int module_kallsyms_on_each_symbol(int (*fn)(void *, const char *,
491 struct module *, unsigned long),
492 void *data);
493
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494extern void __module_put_and_exit(struct module *mod, long code)
495 __attribute__((noreturn));
496#define module_put_and_exit(code) __module_put_and_exit(THIS_MODULE, code);
497
498#ifdef CONFIG_MODULE_UNLOAD
499unsigned int module_refcount(struct module *mod);
500void __symbol_put(const char *symbol);
501#define symbol_put(x) __symbol_put(MODULE_SYMBOL_PREFIX #x)
502void symbol_put_addr(void *addr);
503
504/* Sometimes we know we already have a refcount, and it's easier not
505 to handle the error case (which only happens with rmmod --wait). */
506static inline void __module_get(struct module *module)
507{
508 if (module) {
Christoph Lametere1783a22010-01-05 15:34:50 +0900509 preempt_disable();
Nick Piggin5fbfb182010-04-01 19:09:40 +1100510 __this_cpu_inc(module->refptr->incs);
Li Zefanae832d12010-03-24 10:57:43 +0800511 trace_module_get(module, _THIS_IP_);
Christoph Lametere1783a22010-01-05 15:34:50 +0900512 preempt_enable();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 }
514}
515
516static inline int try_module_get(struct module *module)
517{
518 int ret = 1;
519
520 if (module) {
Christoph Lametere1783a22010-01-05 15:34:50 +0900521 preempt_disable();
522
Li Zefan7ead8b82009-08-17 16:56:28 +0800523 if (likely(module_is_live(module))) {
Nick Piggin5fbfb182010-04-01 19:09:40 +1100524 __this_cpu_inc(module->refptr->incs);
Li Zefanae832d12010-03-24 10:57:43 +0800525 trace_module_get(module, _THIS_IP_);
Nick Piggin5fbfb182010-04-01 19:09:40 +1100526 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 ret = 0;
Christoph Lametere1783a22010-01-05 15:34:50 +0900528
529 preempt_enable();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 }
531 return ret;
532}
533
Al Virof6a57032006-10-18 01:47:25 -0400534extern void module_put(struct module *module);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535
536#else /*!CONFIG_MODULE_UNLOAD*/
537static inline int try_module_get(struct module *module)
538{
539 return !module || module_is_live(module);
540}
541static inline void module_put(struct module *module)
542{
543}
544static inline void __module_get(struct module *module)
545{
546}
547#define symbol_put(x) do { } while(0)
548#define symbol_put_addr(p) do { } while(0)
549
550#endif /* CONFIG_MODULE_UNLOAD */
Anders Kaseorgdfd62d12010-11-24 15:21:10 -0600551int ref_module(struct module *a, struct module *b);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552
553/* This is a #define so the string doesn't get put in every .o file */
554#define module_name(mod) \
555({ \
556 struct module *__mod = (mod); \
557 __mod ? __mod->name : "kernel"; \
558})
559
Rusty Russell6dd06c92008-01-29 17:13:22 -0500560/* For kallsyms to ask for address resolution. namebuf should be at
561 * least KSYM_NAME_LEN long: a pointer to namebuf is returned if
562 * found, otherwise NULL. */
Andrew Morton92dfc9d2008-02-08 04:18:43 -0800563const char *module_address_lookup(unsigned long addr,
Rusty Russell6dd06c92008-01-29 17:13:22 -0500564 unsigned long *symbolsize,
565 unsigned long *offset,
566 char **modname,
567 char *namebuf);
Alexey Dobriyan9d65cb42007-05-08 00:28:43 -0700568int lookup_module_symbol_name(unsigned long addr, char *symname);
Alexey Dobriyana5c43da2007-05-08 00:28:47 -0700569int lookup_module_symbol_attrs(unsigned long addr, unsigned long *size, unsigned long *offset, char *modname, char *name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570
571/* For extable.c to search modules' exception tables. */
572const struct exception_table_entry *search_module_extables(unsigned long addr);
573
574int register_module_notifier(struct notifier_block * nb);
575int unregister_module_notifier(struct notifier_block * nb);
576
577extern void print_modules(void);
578
Mathieu Desnoyers97e1c182008-07-18 12:16:16 -0400579extern void module_update_tracepoints(void);
580extern int module_get_iter_tracepoints(struct tracepoint_iter *iter);
581
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582#else /* !CONFIG_MODULES... */
583#define EXPORT_SYMBOL(sym)
584#define EXPORT_SYMBOL_GPL(sym)
Greg Kroah-Hartman9f28bb72006-03-20 13:17:13 -0800585#define EXPORT_SYMBOL_GPL_FUTURE(sym)
Arjan van de Venf71d20e2006-06-28 04:26:45 -0700586#define EXPORT_UNUSED_SYMBOL(sym)
587#define EXPORT_UNUSED_SYMBOL_GPL(sym)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588
589/* Given an address, look for it in the exception tables. */
590static inline const struct exception_table_entry *
591search_module_extables(unsigned long addr)
592{
593 return NULL;
594}
595
Rusty Russelle6104992009-03-31 13:05:31 -0600596static inline struct module *__module_address(unsigned long addr)
597{
598 return NULL;
599}
600
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601static inline struct module *__module_text_address(unsigned long addr)
602{
603 return NULL;
604}
605
Rusty Russelle6104992009-03-31 13:05:31 -0600606static inline bool is_module_address(unsigned long addr)
Ingo Molnar4d435f92006-07-03 00:24:24 -0700607{
Rusty Russelle6104992009-03-31 13:05:31 -0600608 return false;
609}
610
Randy Dunlapd5e50da2010-03-31 11:33:42 +0900611static inline bool is_module_percpu_address(unsigned long addr)
612{
613 return false;
614}
615
Rusty Russelle6104992009-03-31 13:05:31 -0600616static inline bool is_module_text_address(unsigned long addr)
617{
618 return false;
Ingo Molnar4d435f92006-07-03 00:24:24 -0700619}
620
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621/* Get/put a kernel symbol (calls should be symmetric) */
622#define symbol_get(x) ({ extern typeof(x) x __attribute__((weak)); &(x); })
623#define symbol_put(x) do { } while(0)
624#define symbol_put_addr(x) do { } while(0)
625
626static inline void __module_get(struct module *module)
627{
628}
629
630static inline int try_module_get(struct module *module)
631{
632 return 1;
633}
634
635static inline void module_put(struct module *module)
636{
637}
638
639#define module_name(mod) "kernel"
640
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641/* For kallsyms to ask for address resolution. NULL means not found. */
Andrew Morton92dfc9d2008-02-08 04:18:43 -0800642static inline const char *module_address_lookup(unsigned long addr,
Rusty Russell6dd06c92008-01-29 17:13:22 -0500643 unsigned long *symbolsize,
644 unsigned long *offset,
645 char **modname,
646 char *namebuf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647{
648 return NULL;
649}
650
Alexey Dobriyan9d65cb42007-05-08 00:28:43 -0700651static inline int lookup_module_symbol_name(unsigned long addr, char *symname)
652{
653 return -ERANGE;
654}
655
Alexey Dobriyana5c43da2007-05-08 00:28:47 -0700656static inline int lookup_module_symbol_attrs(unsigned long addr, unsigned long *size, unsigned long *offset, char *modname, char *name)
657{
658 return -ERANGE;
659}
660
Alexey Dobriyanea078902007-05-08 00:28:39 -0700661static inline int module_get_kallsym(unsigned int symnum, unsigned long *value,
662 char *type, char *name,
663 char *module_name, int *exported)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664{
Alexey Dobriyanea078902007-05-08 00:28:39 -0700665 return -ERANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666}
667
668static inline unsigned long module_kallsyms_lookup_name(const char *name)
669{
670 return 0;
671}
672
Anders Kaseorg75a66612008-12-05 19:03:58 -0500673static inline int module_kallsyms_on_each_symbol(int (*fn)(void *, const char *,
674 struct module *,
675 unsigned long),
676 void *data)
677{
678 return 0;
679}
680
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681static inline int register_module_notifier(struct notifier_block * nb)
682{
683 /* no events will happen anyway, so this can always succeed */
684 return 0;
685}
686
687static inline int unregister_module_notifier(struct notifier_block * nb)
688{
689 return 0;
690}
691
692#define module_put_and_exit(code) do_exit(code)
693
694static inline void print_modules(void)
695{
696}
697
Mathieu Desnoyers97e1c182008-07-18 12:16:16 -0400698static inline void module_update_tracepoints(void)
699{
700}
701
702static inline int module_get_iter_tracepoints(struct tracepoint_iter *iter)
703{
704 return 0;
705}
Randy Dunlapef665c12007-02-13 15:19:06 -0800706#endif /* CONFIG_MODULES */
707
Randy Dunlapef665c12007-02-13 15:19:06 -0800708#ifdef CONFIG_SYSFS
Greg Kroah-Hartman7405c1e2007-11-01 10:39:50 -0700709extern struct kset *module_kset;
710extern struct kobj_type module_ktype;
711extern int module_sysfs_initialized;
Randy Dunlapef665c12007-02-13 15:19:06 -0800712#endif /* CONFIG_SYSFS */
713
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714#define symbol_request(x) try_then_request_module(symbol_get(x), "symbol:" #x)
715
716/* BELOW HERE ALL THESE ARE OBSOLETE AND WILL VANISH */
717
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718#define __MODULE_STRING(x) __stringify(x)
719
matthieu castet84e1c6b2010-11-16 22:35:16 +0100720#ifdef CONFIG_DEBUG_SET_MODULE_RONX
721extern void set_all_modules_text_rw(void);
722extern void set_all_modules_text_ro(void);
723#else
724static inline void set_all_modules_text_rw(void) { }
725static inline void set_all_modules_text_ro(void) { }
726#endif
Andrew Morton0d9c25d2009-06-16 15:33:37 -0700727
728#ifdef CONFIG_GENERIC_BUG
Linus Torvalds53363772010-10-05 11:29:27 -0700729void module_bug_finalize(const Elf_Ehdr *, const Elf_Shdr *,
Andrew Morton0d9c25d2009-06-16 15:33:37 -0700730 struct module *);
731void module_bug_cleanup(struct module *);
732
733#else /* !CONFIG_GENERIC_BUG */
734
Linus Torvalds53363772010-10-05 11:29:27 -0700735static inline void module_bug_finalize(const Elf_Ehdr *hdr,
Andrew Morton0d9c25d2009-06-16 15:33:37 -0700736 const Elf_Shdr *sechdrs,
737 struct module *mod)
738{
Andrew Morton0d9c25d2009-06-16 15:33:37 -0700739}
740static inline void module_bug_cleanup(struct module *mod) {}
741#endif /* CONFIG_GENERIC_BUG */
742
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743#endif /* _LINUX_MODULE_H */