blob: 1c30087a2d8134e60696a04665ad39c4b01bc7c5 [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
Kay Sievers4befb022011-07-24 22:06:04 +093051struct module_kobject {
52 struct kobject kobj;
53 struct module *mod;
54 struct kobject *drivers_dir;
55 struct module_param_attrs *mp;
56};
57
Linus Torvalds1da177e2005-04-16 15:20:36 -070058struct module_attribute {
Kay Sievers4befb022011-07-24 22:06:04 +093059 struct attribute attr;
60 ssize_t (*show)(struct module_attribute *, struct module_kobject *,
61 char *);
62 ssize_t (*store)(struct module_attribute *, struct module_kobject *,
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 const char *, size_t count);
Matt Domschc988d2b2005-06-23 22:05:15 -070064 void (*setup)(struct module *, const char *);
65 int (*test)(struct module *);
66 void (*free)(struct module *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070067};
68
Dmitry Torokhove94965e2010-12-15 14:00:19 -080069struct module_version_attribute {
70 struct module_attribute mattr;
71 const char *module_name;
72 const char *version;
Dmitry Torokhov98562ad2011-02-04 13:30:10 -080073} __attribute__ ((__aligned__(sizeof(void *))));
Dmitry Torokhove94965e2010-12-15 14:00:19 -080074
Dmitry Torokhov9b73a582011-02-07 16:02:27 -080075extern ssize_t __modver_version_show(struct module_attribute *,
Kay Sievers4befb022011-07-24 22:06:04 +093076 struct module_kobject *, char *);
Dmitry Torokhov9b73a582011-02-07 16:02:27 -080077
Kay Sievers88bfa322011-07-24 22:06:04 +093078extern struct module_attribute module_uevent;
Linus Torvalds1da177e2005-04-16 15:20:36 -070079
80/* These are either module local, or the kernel's dummy ones. */
81extern int init_module(void);
82extern void cleanup_module(void);
83
84/* Archs provide a method of finding the correct exception table. */
85struct exception_table_entry;
86
87const struct exception_table_entry *
88search_extable(const struct exception_table_entry *first,
89 const struct exception_table_entry *last,
90 unsigned long value);
91void sort_extable(struct exception_table_entry *start,
92 struct exception_table_entry *finish);
93void sort_main_extable(void);
Rusty Russellad6561d2009-06-12 21:47:03 -060094void trim_init_extable(struct module *m);
Linus Torvalds1da177e2005-04-16 15:20:36 -070095
Linus Torvalds1da177e2005-04-16 15:20:36 -070096#ifdef MODULE
97#define MODULE_GENERIC_TABLE(gtype,name) \
98extern const struct gtype##_id __mod_##gtype##_table \
99 __attribute__ ((unused, alias(__stringify(name))))
100
101extern struct module __this_module;
102#define THIS_MODULE (&__this_module)
103#else /* !MODULE */
104#define MODULE_GENERIC_TABLE(gtype,name)
105#define THIS_MODULE ((struct module *)0)
106#endif
107
108/* Generic info of form tag = "info" */
109#define MODULE_INFO(tag, info) __MODULE_INFO(tag, tag, info)
110
111/* For userspace: you can also call me... */
112#define MODULE_ALIAS(_alias) MODULE_INFO(alias, _alias)
113
114/*
115 * The following license idents are currently accepted as indicating free
116 * software modules
117 *
118 * "GPL" [GNU Public License v2 or later]
119 * "GPL v2" [GNU Public License v2]
120 * "GPL and additional rights" [GNU Public License v2 rights and more]
121 * "Dual BSD/GPL" [GNU Public License v2
122 * or BSD license choice]
Xose Vazquez Perez8d27e902006-06-23 02:05:13 -0700123 * "Dual MIT/GPL" [GNU Public License v2
124 * or MIT license choice]
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 * "Dual MPL/GPL" [GNU Public License v2
126 * or Mozilla license choice]
127 *
128 * The following other idents are available
129 *
130 * "Proprietary" [Non free products]
131 *
132 * There are dual licensed components, but when running with Linux it is the
133 * GPL that is relevant so this is a non issue. Similarly LGPL linked with GPL
134 * is a GPL combined work.
135 *
136 * This exists for several reasons
137 * 1. So modinfo can show license info for users wanting to vet their setup
138 * is free
139 * 2. So the community can ignore bug reports including proprietary modules
140 * 3. So vendors can do likewise based on their own policies
141 */
142#define MODULE_LICENSE(_license) MODULE_INFO(license, _license)
143
Johannes Berg1d7015c2009-09-25 00:32:58 -0600144/*
145 * Author(s), use "Name <email>" or just "Name", for multiple
146 * authors use multiple MODULE_AUTHOR() statements/lines.
147 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148#define MODULE_AUTHOR(_author) MODULE_INFO(author, _author)
149
150/* What your module does. */
151#define MODULE_DESCRIPTION(_description) MODULE_INFO(description, _description)
152
153/* One for each parameter, describing how to use it. Some files do
154 multiple of these per line, so can't just use MODULE_INFO. */
155#define MODULE_PARM_DESC(_parm, desc) \
156 __MODULE_INFO(parm, _parm, #_parm ":" desc)
157
158#define MODULE_DEVICE_TABLE(type,name) \
159 MODULE_GENERIC_TABLE(type##_device,name)
160
161/* Version of form [<epoch>:]<version>[-<extra-version>].
162 Or for CVS/RCS ID version, everything but the number is stripped.
163 <epoch>: A (small) unsigned integer which allows you to start versions
164 anew. If not mentioned, it's zero. eg. "2:1.0" is after
165 "1:2.0".
166 <version>: The <version> may contain only alphanumerics and the
167 character `.'. Ordered by numeric sort for numeric parts,
168 ascii sort for ascii parts (as per RPM or DEB algorithm).
169 <extraversion>: Like <version>, but inserted for local
170 customizations, eg "rh3" or "rusty1".
171
172 Using this automatically adds a checksum of the .c files and the
173 local headers in "srcversion".
174*/
Dmitry Torokhove94965e2010-12-15 14:00:19 -0800175
Rusty Russell3b90a5b2011-01-24 14:32:51 -0600176#if defined(MODULE) || !defined(CONFIG_SYSFS)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177#define MODULE_VERSION(_version) MODULE_INFO(version, _version)
Dmitry Torokhove94965e2010-12-15 14:00:19 -0800178#else
179#define MODULE_VERSION(_version) \
Dmitry Torokhovb4bc84282011-02-07 16:02:25 -0800180 static struct module_version_attribute ___modver_attr = { \
Dmitry Torokhove94965e2010-12-15 14:00:19 -0800181 .mattr = { \
182 .attr = { \
183 .name = "version", \
184 .mode = S_IRUGO, \
185 }, \
186 .show = __modver_version_show, \
187 }, \
188 .module_name = KBUILD_MODNAME, \
189 .version = _version, \
Dmitry Torokhovb4bc84282011-02-07 16:02:25 -0800190 }; \
191 static const struct module_version_attribute \
192 __used __attribute__ ((__section__ ("__modver"))) \
193 * __moduleparam_const __modver_attr = &___modver_attr
Dmitry Torokhove94965e2010-12-15 14:00:19 -0800194#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195
Jon Masters187afbe2006-08-28 17:08:21 -0500196/* Optional firmware file (or files) needed by the module
197 * format is simply firmware file name. Multiple firmware
198 * files require multiple MODULE_FIRMWARE() specifiers */
199#define MODULE_FIRMWARE(_firmware) MODULE_INFO(firmware, _firmware)
200
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201/* Given an address, look for it in the exception tables */
202const struct exception_table_entry *search_exception_tables(unsigned long add);
203
204struct notifier_block;
205
206#ifdef CONFIG_MODULES
207
Dave Young5ed10912010-03-10 15:24:06 -0800208extern int modules_disabled; /* for sysctl */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209/* Get/put a kernel symbol (calls must be symmetric) */
210void *__symbol_get(const char *symbol);
211void *__symbol_get_gpl(const char *symbol);
212#define symbol_get(x) ((typeof(&x))(__symbol_get(MODULE_SYMBOL_PREFIX #x)))
213
Rusty Russellc8e21ce2010-06-05 11:17:35 -0600214/* modules using other modules: kdb wants to see this. */
215struct module_use {
216 struct list_head source_list;
217 struct list_head target_list;
218 struct module *source, *target;
219};
220
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221#ifndef __GENKSYMS__
222#ifdef CONFIG_MODVERSIONS
223/* Mark the CRC weak since genksyms apparently decides not to
224 * generate a checksums for some symbols */
225#define __CRC_SYMBOL(sym, sec) \
226 extern void *__crc_##sym __attribute__((weak)); \
227 static const unsigned long __kcrctab_##sym \
Adrian Bunk3ff6eec2008-01-24 22:16:20 +0100228 __used \
Alessio Igor Boganif02e8a62011-04-14 14:59:39 +0200229 __attribute__((section("___kcrctab" sec "+" #sym), unused)) \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 = (unsigned long) &__crc_##sym;
231#else
232#define __CRC_SYMBOL(sym, sec)
233#endif
234
235/* For every exported symbol, place a struct in the __ksymtab section */
236#define __EXPORT_SYMBOL(sym, sec) \
Patrick McHardya1a8fee2006-03-23 22:07:34 -0800237 extern typeof(sym) sym; \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 __CRC_SYMBOL(sym, sec) \
239 static const char __kstrtab_##sym[] \
Rusty Russellea01e792008-03-13 09:02:17 +0000240 __attribute__((section("__ksymtab_strings"), aligned(1))) \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 = MODULE_SYMBOL_PREFIX #sym; \
242 static const struct kernel_symbol __ksymtab_##sym \
Adrian Bunk3ff6eec2008-01-24 22:16:20 +0100243 __used \
Alessio Igor Boganif02e8a62011-04-14 14:59:39 +0200244 __attribute__((section("___ksymtab" sec "+" #sym), unused)) \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245 = { (unsigned long)&sym, __kstrtab_##sym }
246
247#define EXPORT_SYMBOL(sym) \
248 __EXPORT_SYMBOL(sym, "")
249
250#define EXPORT_SYMBOL_GPL(sym) \
251 __EXPORT_SYMBOL(sym, "_gpl")
252
Greg Kroah-Hartman9f28bb72006-03-20 13:17:13 -0800253#define EXPORT_SYMBOL_GPL_FUTURE(sym) \
254 __EXPORT_SYMBOL(sym, "_gpl_future")
255
Arjan van de Venf71d20e2006-06-28 04:26:45 -0700256
257#ifdef CONFIG_UNUSED_SYMBOLS
258#define EXPORT_UNUSED_SYMBOL(sym) __EXPORT_SYMBOL(sym, "_unused")
259#define EXPORT_UNUSED_SYMBOL_GPL(sym) __EXPORT_SYMBOL(sym, "_unused_gpl")
260#else
261#define EXPORT_UNUSED_SYMBOL(sym)
262#define EXPORT_UNUSED_SYMBOL_GPL(sym)
263#endif
264
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265#endif
266
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267enum module_state
268{
269 MODULE_STATE_LIVE,
270 MODULE_STATE_COMING,
271 MODULE_STATE_GOING,
272};
273
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274struct module
275{
276 enum module_state state;
277
278 /* Member of list of modules */
279 struct list_head list;
280
281 /* Unique handle for this module */
282 char name[MODULE_NAME_LEN];
283
284 /* Sysfs stuff. */
285 struct module_kobject mkobj;
Greg Kroah-Hartman03e88ae12006-02-16 13:50:23 -0800286 struct module_attribute *modinfo_attrs;
Matt Domschc988d2b2005-06-23 22:05:15 -0700287 const char *version;
288 const char *srcversion;
Kay Sievers270a6c42007-01-18 13:26:15 +0100289 struct kobject *holders_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290
291 /* Exported symbols */
292 const struct kernel_symbol *syms;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293 const unsigned long *crcs;
Richard Kennedyaf540682008-07-22 19:24:26 -0500294 unsigned int num_syms;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295
Rusty Russelle180a6b2009-03-31 13:05:29 -0600296 /* Kernel parameters. */
297 struct kernel_param *kp;
298 unsigned int num_kp;
299
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 /* GPL-only exported symbols. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 unsigned int num_gpl_syms;
Richard Kennedyaf540682008-07-22 19:24:26 -0500302 const struct kernel_symbol *gpl_syms;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303 const unsigned long *gpl_crcs;
304
Denys Vlasenkof7f5b672008-07-22 19:24:26 -0500305#ifdef CONFIG_UNUSED_SYMBOLS
Arjan van de Venf71d20e2006-06-28 04:26:45 -0700306 /* unused exported symbols. */
307 const struct kernel_symbol *unused_syms;
Arjan van de Venf71d20e2006-06-28 04:26:45 -0700308 const unsigned long *unused_crcs;
Richard Kennedyaf540682008-07-22 19:24:26 -0500309 unsigned int num_unused_syms;
310
Arjan van de Venf71d20e2006-06-28 04:26:45 -0700311 /* GPL-only, unused exported symbols. */
Arjan van de Venf71d20e2006-06-28 04:26:45 -0700312 unsigned int num_unused_gpl_syms;
Richard Kennedyaf540682008-07-22 19:24:26 -0500313 const struct kernel_symbol *unused_gpl_syms;
Arjan van de Venf71d20e2006-06-28 04:26:45 -0700314 const unsigned long *unused_gpl_crcs;
Denys Vlasenkof7f5b672008-07-22 19:24:26 -0500315#endif
Arjan van de Venf71d20e2006-06-28 04:26:45 -0700316
Greg Kroah-Hartman9f28bb72006-03-20 13:17:13 -0800317 /* symbols that will be GPL-only in the near future. */
318 const struct kernel_symbol *gpl_future_syms;
Greg Kroah-Hartman9f28bb72006-03-20 13:17:13 -0800319 const unsigned long *gpl_future_crcs;
Richard Kennedyaf540682008-07-22 19:24:26 -0500320 unsigned int num_gpl_future_syms;
Greg Kroah-Hartman9f28bb72006-03-20 13:17:13 -0800321
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 /* Exception table */
323 unsigned int num_exentries;
Rusty Russell5e458cc2008-10-22 10:00:13 -0500324 struct exception_table_entry *extable;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325
326 /* Startup function. */
327 int (*init)(void);
328
329 /* If this is non-NULL, vfree after init() returns */
330 void *module_init;
331
332 /* Here is the actual code + data, vfree'd on unload. */
333 void *module_core;
334
335 /* Here are the sizes of the init and core sections */
Denys Vlasenko2f0f2a32008-07-22 19:24:27 -0500336 unsigned int init_size, core_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337
338 /* The size of the executable code in each section. */
Denys Vlasenko2f0f2a32008-07-22 19:24:27 -0500339 unsigned int init_text_size, core_text_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340
matthieu castet84e1c6b2010-11-16 22:35:16 +0100341 /* Size of RO sections of the module (text+rodata) */
342 unsigned int init_ro_size, core_ro_size;
343
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 /* Arch-specific module values */
345 struct mod_arch_specific arch;
346
Randy Dunlap2bc2d612006-10-02 02:17:02 -0700347 unsigned int taints; /* same bits as kernel:tainted */
348
Jeremy Fitzhardinge7664c5a2006-12-08 02:36:19 -0800349#ifdef CONFIG_GENERIC_BUG
350 /* Support for BUG */
Richard Kennedyaf540682008-07-22 19:24:26 -0500351 unsigned num_bugs;
Jeremy Fitzhardinge7664c5a2006-12-08 02:36:19 -0800352 struct list_head bug_list;
353 struct bug_entry *bug_table;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354#endif
355
356#ifdef CONFIG_KALLSYMS
Jan Beulich4a496222009-07-06 14:50:42 +0100357 /*
358 * We keep the symbol and string tables for kallsyms.
359 * The core_* fields below are temporary, loader-only (they
360 * could really be discarded after module init).
361 */
362 Elf_Sym *symtab, *core_symtab;
363 unsigned int num_symtab, core_num_syms;
Jan Beulich554bdfe2009-07-06 14:51:44 +0100364 char *strtab, *core_strtab;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365
366 /* Section attributes */
367 struct module_sect_attrs *sect_attrs;
Roland McGrath6d760132007-10-16 23:26:40 -0700368
369 /* Notes attributes */
370 struct module_notes_attrs *notes_attrs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371#endif
372
Richard Kennedya288bd62011-05-19 16:55:25 -0600373 /* The command line arguments (may be mangled). People like
374 keeping pointers to this stuff */
375 char *args;
376
Tejun Heo259354d2010-03-10 18:56:10 +0900377#ifdef CONFIG_SMP
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 /* Per-cpu data. */
Tejun Heo259354d2010-03-10 18:56:10 +0900379 void __percpu *percpu;
380 unsigned int percpu_size;
381#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382
Mathieu Desnoyers97e1c182008-07-18 12:16:16 -0400383#ifdef CONFIG_TRACEPOINTS
Mathieu Desnoyers97e1c182008-07-18 12:16:16 -0400384 unsigned int num_tracepoints;
Richard Kennedya288bd62011-05-19 16:55:25 -0600385 struct tracepoint * const *tracepoints_ptrs;
Mathieu Desnoyers97e1c182008-07-18 12:16:16 -0400386#endif
Jason Baronbf5438fc2010-09-17 11:09:00 -0400387#ifdef HAVE_JUMP_LABEL
388 struct jump_entry *jump_entries;
389 unsigned int num_jump_entries;
390#endif
Frederic Weisbecker769b0442009-03-06 17:21:49 +0100391#ifdef CONFIG_TRACING
Lai Jiangshan1ba28e02009-03-06 17:21:48 +0100392 unsigned int num_trace_bprintk_fmt;
Richard Kennedya288bd62011-05-19 16:55:25 -0600393 const char **trace_bprintk_fmt_start;
Lai Jiangshan1ba28e02009-03-06 17:21:48 +0100394#endif
Steven Rostedt6d723732009-04-10 14:53:50 -0400395#ifdef CONFIG_EVENT_TRACING
Steven Rostedte4a9ea52011-01-27 09:15:30 -0500396 struct ftrace_event_call **trace_events;
Steven Rostedt6d723732009-04-10 14:53:50 -0400397 unsigned int num_trace_events;
398#endif
Steven Rostedt93eb6772009-04-15 13:24:06 -0400399#ifdef CONFIG_FTRACE_MCOUNT_RECORD
Steven Rostedt93eb6772009-04-15 13:24:06 -0400400 unsigned int num_ftrace_callsites;
Richard Kennedya288bd62011-05-19 16:55:25 -0600401 unsigned long *ftrace_callsites;
Steven Rostedt93eb6772009-04-15 13:24:06 -0400402#endif
Lai Jiangshan1ba28e02009-03-06 17:21:48 +0100403
Richard Kennedyaf540682008-07-22 19:24:26 -0500404#ifdef CONFIG_MODULE_UNLOAD
405 /* What modules depend on me? */
Linus Torvalds2c02dfe2010-05-31 12:19:37 -0700406 struct list_head source_list;
407 /* What modules do I depend on? */
408 struct list_head target_list;
Richard Kennedyaf540682008-07-22 19:24:26 -0500409
410 /* Who is waiting for us to be unloaded */
411 struct task_struct *waiter;
412
413 /* Destruction function. */
414 void (*exit)(void);
415
Christoph Lametere1783a22010-01-05 15:34:50 +0900416 struct module_ref {
Nick Piggin5fbfb182010-04-01 19:09:40 +1100417 unsigned int incs;
418 unsigned int decs;
Tejun Heo43cf38e2010-02-02 14:38:57 +0900419 } __percpu *refptr;
Richard Kennedyaf540682008-07-22 19:24:26 -0500420#endif
Peter Oberparleiterb99b87f2009-06-17 16:28:03 -0700421
422#ifdef CONFIG_CONSTRUCTORS
423 /* Constructor functions. */
424 ctor_fn_t *ctors;
425 unsigned int num_ctors;
426#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427};
Roman Zippele61a1c12007-05-09 02:35:15 -0700428#ifndef MODULE_ARCH_INIT
429#define MODULE_ARCH_INIT {}
430#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431
Tim Abbottc6b37802008-12-05 19:03:59 -0500432extern struct mutex module_mutex;
433
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434/* FIXME: It'd be nice to isolate modules during init, too, so they
435 aren't used before they (may) fail. But presently too much code
436 (IDE & SCSI) require entry into the module during init.*/
437static inline int module_is_live(struct module *mod)
438{
439 return mod->state != MODULE_STATE_GOING;
440}
441
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442struct module *__module_text_address(unsigned long addr);
Rusty Russelle6104992009-03-31 13:05:31 -0600443struct module *__module_address(unsigned long addr);
444bool is_module_address(unsigned long addr);
Tejun Heo10fad5e2010-03-10 18:57:54 +0900445bool is_module_percpu_address(unsigned long addr);
Rusty Russelle6104992009-03-31 13:05:31 -0600446bool is_module_text_address(unsigned long addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447
Masami Hiramatsua06f6212009-01-06 14:41:49 -0800448static inline int within_module_core(unsigned long addr, struct module *mod)
449{
450 return (unsigned long)mod->module_core <= addr &&
451 addr < (unsigned long)mod->module_core + mod->core_size;
452}
453
454static inline int within_module_init(unsigned long addr, struct module *mod)
455{
456 return (unsigned long)mod->module_init <= addr &&
457 addr < (unsigned long)mod->module_init + mod->init_size;
458}
459
Tim Abbottc6b37802008-12-05 19:03:59 -0500460/* Search for module by name: must hold module_mutex. */
461struct module *find_module(const char *name);
462
463struct symsearch {
464 const struct kernel_symbol *start, *stop;
465 const unsigned long *crcs;
466 enum {
467 NOT_GPL_ONLY,
468 GPL_ONLY,
469 WILL_BE_GPL_ONLY,
470 } licence;
471 bool unused;
472};
473
474/* Search for an exported symbol by name. */
475const struct kernel_symbol *find_symbol(const char *name,
476 struct module **owner,
477 const unsigned long **crc,
478 bool gplok,
479 bool warn);
480
481/* Walk the exported symbol table */
Rusty Russellde4d8d52011-04-19 21:49:58 +0200482bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
483 struct module *owner,
484 void *data), void *data);
Tim Abbottc6b37802008-12-05 19:03:59 -0500485
Alexey Dobriyanea078902007-05-08 00:28:39 -0700486/* Returns 0 and fills in value, defined and namebuf, or -ERANGE if
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 symnum out of range. */
Alexey Dobriyanea078902007-05-08 00:28:39 -0700488int module_get_kallsym(unsigned int symnum, unsigned long *value, char *type,
489 char *name, char *module_name, int *exported);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490
491/* Look for this name: can be of form module:name. */
492unsigned long module_kallsyms_lookup_name(const char *name);
493
Anders Kaseorg75a66612008-12-05 19:03:58 -0500494int module_kallsyms_on_each_symbol(int (*fn)(void *, const char *,
495 struct module *, unsigned long),
496 void *data);
497
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498extern void __module_put_and_exit(struct module *mod, long code)
499 __attribute__((noreturn));
500#define module_put_and_exit(code) __module_put_and_exit(THIS_MODULE, code);
501
502#ifdef CONFIG_MODULE_UNLOAD
503unsigned int module_refcount(struct module *mod);
504void __symbol_put(const char *symbol);
505#define symbol_put(x) __symbol_put(MODULE_SYMBOL_PREFIX #x)
506void symbol_put_addr(void *addr);
507
508/* Sometimes we know we already have a refcount, and it's easier not
509 to handle the error case (which only happens with rmmod --wait). */
510static inline void __module_get(struct module *module)
511{
512 if (module) {
Christoph Lametere1783a22010-01-05 15:34:50 +0900513 preempt_disable();
Nick Piggin5fbfb182010-04-01 19:09:40 +1100514 __this_cpu_inc(module->refptr->incs);
Li Zefanae832d12010-03-24 10:57:43 +0800515 trace_module_get(module, _THIS_IP_);
Christoph Lametere1783a22010-01-05 15:34:50 +0900516 preempt_enable();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 }
518}
519
520static inline int try_module_get(struct module *module)
521{
522 int ret = 1;
523
524 if (module) {
Christoph Lametere1783a22010-01-05 15:34:50 +0900525 preempt_disable();
526
Li Zefan7ead8b82009-08-17 16:56:28 +0800527 if (likely(module_is_live(module))) {
Nick Piggin5fbfb182010-04-01 19:09:40 +1100528 __this_cpu_inc(module->refptr->incs);
Li Zefanae832d12010-03-24 10:57:43 +0800529 trace_module_get(module, _THIS_IP_);
Nick Piggin5fbfb182010-04-01 19:09:40 +1100530 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 ret = 0;
Christoph Lametere1783a22010-01-05 15:34:50 +0900532
533 preempt_enable();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 }
535 return ret;
536}
537
Al Virof6a57032006-10-18 01:47:25 -0400538extern void module_put(struct module *module);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539
540#else /*!CONFIG_MODULE_UNLOAD*/
541static inline int try_module_get(struct module *module)
542{
543 return !module || module_is_live(module);
544}
545static inline void module_put(struct module *module)
546{
547}
548static inline void __module_get(struct module *module)
549{
550}
551#define symbol_put(x) do { } while(0)
552#define symbol_put_addr(p) do { } while(0)
553
554#endif /* CONFIG_MODULE_UNLOAD */
Anders Kaseorgdfd62d12010-11-24 15:21:10 -0600555int ref_module(struct module *a, struct module *b);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556
557/* This is a #define so the string doesn't get put in every .o file */
558#define module_name(mod) \
559({ \
560 struct module *__mod = (mod); \
561 __mod ? __mod->name : "kernel"; \
562})
563
Rusty Russell6dd06c92008-01-29 17:13:22 -0500564/* For kallsyms to ask for address resolution. namebuf should be at
565 * least KSYM_NAME_LEN long: a pointer to namebuf is returned if
566 * found, otherwise NULL. */
Andrew Morton92dfc9d2008-02-08 04:18:43 -0800567const char *module_address_lookup(unsigned long addr,
Rusty Russell6dd06c92008-01-29 17:13:22 -0500568 unsigned long *symbolsize,
569 unsigned long *offset,
570 char **modname,
571 char *namebuf);
Alexey Dobriyan9d65cb42007-05-08 00:28:43 -0700572int lookup_module_symbol_name(unsigned long addr, char *symname);
Alexey Dobriyana5c43da2007-05-08 00:28:47 -0700573int lookup_module_symbol_attrs(unsigned long addr, unsigned long *size, unsigned long *offset, char *modname, char *name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574
575/* For extable.c to search modules' exception tables. */
576const struct exception_table_entry *search_module_extables(unsigned long addr);
577
578int register_module_notifier(struct notifier_block * nb);
579int unregister_module_notifier(struct notifier_block * nb);
580
581extern void print_modules(void);
582
Mathieu Desnoyers97e1c182008-07-18 12:16:16 -0400583extern void module_update_tracepoints(void);
584extern int module_get_iter_tracepoints(struct tracepoint_iter *iter);
585
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586#else /* !CONFIG_MODULES... */
587#define EXPORT_SYMBOL(sym)
588#define EXPORT_SYMBOL_GPL(sym)
Greg Kroah-Hartman9f28bb72006-03-20 13:17:13 -0800589#define EXPORT_SYMBOL_GPL_FUTURE(sym)
Arjan van de Venf71d20e2006-06-28 04:26:45 -0700590#define EXPORT_UNUSED_SYMBOL(sym)
591#define EXPORT_UNUSED_SYMBOL_GPL(sym)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592
593/* Given an address, look for it in the exception tables. */
594static inline const struct exception_table_entry *
595search_module_extables(unsigned long addr)
596{
597 return NULL;
598}
599
Rusty Russelle6104992009-03-31 13:05:31 -0600600static inline struct module *__module_address(unsigned long addr)
601{
602 return NULL;
603}
604
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605static inline struct module *__module_text_address(unsigned long addr)
606{
607 return NULL;
608}
609
Rusty Russelle6104992009-03-31 13:05:31 -0600610static inline bool is_module_address(unsigned long addr)
Ingo Molnar4d435f92006-07-03 00:24:24 -0700611{
Rusty Russelle6104992009-03-31 13:05:31 -0600612 return false;
613}
614
Randy Dunlapd5e50da2010-03-31 11:33:42 +0900615static inline bool is_module_percpu_address(unsigned long addr)
616{
617 return false;
618}
619
Rusty Russelle6104992009-03-31 13:05:31 -0600620static inline bool is_module_text_address(unsigned long addr)
621{
622 return false;
Ingo Molnar4d435f92006-07-03 00:24:24 -0700623}
624
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625/* Get/put a kernel symbol (calls should be symmetric) */
626#define symbol_get(x) ({ extern typeof(x) x __attribute__((weak)); &(x); })
627#define symbol_put(x) do { } while(0)
628#define symbol_put_addr(x) do { } while(0)
629
630static inline void __module_get(struct module *module)
631{
632}
633
634static inline int try_module_get(struct module *module)
635{
636 return 1;
637}
638
639static inline void module_put(struct module *module)
640{
641}
642
643#define module_name(mod) "kernel"
644
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645/* For kallsyms to ask for address resolution. NULL means not found. */
Andrew Morton92dfc9d2008-02-08 04:18:43 -0800646static inline const char *module_address_lookup(unsigned long addr,
Rusty Russell6dd06c92008-01-29 17:13:22 -0500647 unsigned long *symbolsize,
648 unsigned long *offset,
649 char **modname,
650 char *namebuf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651{
652 return NULL;
653}
654
Alexey Dobriyan9d65cb42007-05-08 00:28:43 -0700655static inline int lookup_module_symbol_name(unsigned long addr, char *symname)
656{
657 return -ERANGE;
658}
659
Alexey Dobriyana5c43da2007-05-08 00:28:47 -0700660static inline int lookup_module_symbol_attrs(unsigned long addr, unsigned long *size, unsigned long *offset, char *modname, char *name)
661{
662 return -ERANGE;
663}
664
Alexey Dobriyanea078902007-05-08 00:28:39 -0700665static inline int module_get_kallsym(unsigned int symnum, unsigned long *value,
666 char *type, char *name,
667 char *module_name, int *exported)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668{
Alexey Dobriyanea078902007-05-08 00:28:39 -0700669 return -ERANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670}
671
672static inline unsigned long module_kallsyms_lookup_name(const char *name)
673{
674 return 0;
675}
676
Anders Kaseorg75a66612008-12-05 19:03:58 -0500677static inline int module_kallsyms_on_each_symbol(int (*fn)(void *, const char *,
678 struct module *,
679 unsigned long),
680 void *data)
681{
682 return 0;
683}
684
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685static inline int register_module_notifier(struct notifier_block * nb)
686{
687 /* no events will happen anyway, so this can always succeed */
688 return 0;
689}
690
691static inline int unregister_module_notifier(struct notifier_block * nb)
692{
693 return 0;
694}
695
696#define module_put_and_exit(code) do_exit(code)
697
698static inline void print_modules(void)
699{
700}
701
Mathieu Desnoyers97e1c182008-07-18 12:16:16 -0400702static inline void module_update_tracepoints(void)
703{
704}
705
706static inline int module_get_iter_tracepoints(struct tracepoint_iter *iter)
707{
708 return 0;
709}
Randy Dunlapef665c12007-02-13 15:19:06 -0800710#endif /* CONFIG_MODULES */
711
Randy Dunlapef665c12007-02-13 15:19:06 -0800712#ifdef CONFIG_SYSFS
Greg Kroah-Hartman7405c1e2007-11-01 10:39:50 -0700713extern struct kset *module_kset;
714extern struct kobj_type module_ktype;
715extern int module_sysfs_initialized;
Randy Dunlapef665c12007-02-13 15:19:06 -0800716#endif /* CONFIG_SYSFS */
717
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718#define symbol_request(x) try_then_request_module(symbol_get(x), "symbol:" #x)
719
720/* BELOW HERE ALL THESE ARE OBSOLETE AND WILL VANISH */
721
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722#define __MODULE_STRING(x) __stringify(x)
723
matthieu castet84e1c6b2010-11-16 22:35:16 +0100724#ifdef CONFIG_DEBUG_SET_MODULE_RONX
725extern void set_all_modules_text_rw(void);
726extern void set_all_modules_text_ro(void);
727#else
728static inline void set_all_modules_text_rw(void) { }
729static inline void set_all_modules_text_ro(void) { }
730#endif
Andrew Morton0d9c25d2009-06-16 15:33:37 -0700731
732#ifdef CONFIG_GENERIC_BUG
Linus Torvalds53363772010-10-05 11:29:27 -0700733void module_bug_finalize(const Elf_Ehdr *, const Elf_Shdr *,
Andrew Morton0d9c25d2009-06-16 15:33:37 -0700734 struct module *);
735void module_bug_cleanup(struct module *);
736
737#else /* !CONFIG_GENERIC_BUG */
738
Linus Torvalds53363772010-10-05 11:29:27 -0700739static inline void module_bug_finalize(const Elf_Ehdr *hdr,
Andrew Morton0d9c25d2009-06-16 15:33:37 -0700740 const Elf_Shdr *sechdrs,
741 struct module *mod)
742{
Andrew Morton0d9c25d2009-06-16 15:33:37 -0700743}
744static inline void module_bug_cleanup(struct module *mod) {}
745#endif /* CONFIG_GENERIC_BUG */
746
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747#endif /* _LINUX_MODULE_H */