2 * Dynamic loading of modules into the kernel.
4 * Rewritten by Richard Henderson <rth@tamu.edu> Dec 1996
7 #ifndef _LINUX_MODULE_H
8 #define _LINUX_MODULE_H
10 #include <linux/config.h>
11 #include <linux/spinlock.h>
12 #include <linux/list.h>
15 # define _set_ver(sym) sym
18 #else /* ! __GENKSYMS__ */
19 # if !defined(MODVERSIONS) && defined(EXPORT_SYMTAB)
20 # define _set_ver(sym) sym
21 # include <linux/modversions.h>
23 #endif /* __GENKSYMS__ */
25 #include <asm/atomic.h>
27 /* Don't need to bring in all of uaccess.h just for this decl. */
28 struct exception_table_entry;
30 /* Used by get_kernel_syms, which is obsolete. */
34 char name[60]; /* should have been 64-sizeof(long); oh well */
45 struct module *dep; /* "parent" pointer */
46 struct module *ref; /* "child" pointer */
47 struct module_ref *next_ref;
51 struct module_persist;
55 unsigned long size_of_struct; /* == sizeof(module) */
64 } uc; /* Needs to keep its size - so says rth */
66 unsigned long flags; /* AUTOCLEAN et al */
71 struct module_symbol *syms;
72 struct module_ref *deps;
73 struct module_ref *refs;
75 void (*cleanup)(void);
76 const struct exception_table_entry *ex_table_start;
77 const struct exception_table_entry *ex_table_end;
81 /* Members past this point are extensions to the basic
82 module support and are optional. Use mod_member_present()
84 const struct module_persist *persist_start;
85 const struct module_persist *persist_end;
86 int (*can_unload)(void);
87 int runsize; /* In modutils, not currently used */
88 const char *kallsyms_start; /* All symbols for kernel debugging */
89 const char *kallsyms_end;
90 const char *archdata_start; /* arch specific data for module */
91 const char *archdata_end;
92 const char *kernel_data; /* Reserved for kernel internal use */
103 /* Bits of module.flags. */
105 #define MOD_UNINITIALIZED 0
106 #define MOD_RUNNING 1
107 #define MOD_DELETED 2
108 #define MOD_AUTOCLEAN 4
109 #define MOD_VISITED 8
110 #define MOD_USED_ONCE 16
111 #define MOD_JUST_FREED 32
112 #define MOD_INITIALIZING 64
114 /* Values for query_module's which. */
122 /* Can the module be queried? */
123 #define MOD_CAN_QUERY(mod) (((mod)->flags & (MOD_RUNNING | MOD_INITIALIZING)) && !((mod)->flags & MOD_DELETED))
125 /* When struct module is extended, we must test whether the new member
126 is present in the header received from insmod before we can use it.
127 This function returns true if the member is present. */
129 #define mod_member_present(mod,member) \
130 ((unsigned long)(&((struct module *)0L)->member + 1) \
131 <= (mod)->size_of_struct)
134 * Ditto for archdata. Assumes mod->archdata_start and mod->archdata_end
135 * are validated elsewhere.
137 #define mod_archdata_member_present(mod, type, member) \
138 (((unsigned long)(&((type *)0L)->member) + \
139 sizeof(((type *)0L)->member)) <= \
140 ((mod)->archdata_end - (mod)->archdata_start))
143 /* Check if an address p with number of entries n is within the body of module m */
144 #define mod_bound(p, n, m) ((unsigned long)(p) >= ((unsigned long)(m) + ((m)->size_of_struct)) && \
145 (unsigned long)((p)+(n)) <= (unsigned long)(m) + (m)->size)
147 /* Backwards compatibility definition. */
149 #define GET_USE_COUNT(module) (atomic_read(&(module)->uc.usecount))
151 /* Poke the use count of a module. */
153 #define __MOD_INC_USE_COUNT(mod) \
154 (atomic_inc(&(mod)->uc.usecount), (mod)->flags |= MOD_VISITED|MOD_USED_ONCE)
155 #define __MOD_DEC_USE_COUNT(mod) \
156 (atomic_dec(&(mod)->uc.usecount), (mod)->flags |= MOD_VISITED)
157 #define __MOD_IN_USE(mod) \
158 (mod_member_present((mod), can_unload) && (mod)->can_unload \
159 ? (mod)->can_unload() : atomic_read(&(mod)->uc.usecount))
161 /* Indirect stringification. */
163 #define __MODULE_STRING_1(x) #x
164 #define __MODULE_STRING(x) __MODULE_STRING_1(x)
166 /* Generic inter module communication.
168 * NOTE: This interface is intended for small amounts of data that are
169 * passed between two objects and either or both of the objects
170 * might be compiled as modules. Do not over use this interface.
172 * If more than two objects need to communicate then you probably
173 * need a specific interface instead of abusing this generic
174 * interface. If both objects are *always* built into the kernel
175 * then a global extern variable is good enough, you do not need
178 * Keith Owens <kaos@ocs.com.au> 28 Oct 2000.
182 #define HAVE_INTER_MODULE
183 extern void inter_module_register(const char *, struct module *, const void *);
184 extern void inter_module_unregister(const char *);
185 extern const void *inter_module_get(const char *);
186 extern const void *inter_module_get_request(const char *, const char *);
187 extern void inter_module_put(const char *);
189 struct inter_module_entry {
190 struct list_head list;
192 struct module *owner;
193 const void *userdata;
196 extern int try_inc_mod_count(struct module *mod);
197 #endif /* __KERNEL__ */
199 #if defined(MODULE) && !defined(__GENKSYMS__)
201 /* Embedded module documentation macros. */
203 /* For documentation purposes only. */
205 #define MODULE_AUTHOR(name) \
206 const char __module_author[] __attribute__((section(".modinfo"))) = \
209 #define MODULE_DESCRIPTION(desc) \
210 const char __module_description[] __attribute__((section(".modinfo"))) = \
213 /* Could potentially be used by kmod... */
215 #define MODULE_SUPPORTED_DEVICE(dev) \
216 const char __module_device[] __attribute__((section(".modinfo"))) = \
219 /* Used to verify parameters given to the module. The TYPE arg should
220 be a string in the following format:
221 [min[-max]]{b,h,i,l,s}
222 The MIN and MAX specifiers delimit the length of the array. If MAX
223 is omitted, it defaults to MIN; if both are omitted, the default is 1.
224 The final character is a type specifier:
232 #define MODULE_PARM(var,type) \
233 const char __module_parm_##var[] \
234 __attribute__((section(".modinfo"))) = \
235 "parm_" __MODULE_STRING(var) "=" type
237 #define MODULE_PARM_DESC(var,desc) \
238 const char __module_parm_desc_##var[] \
239 __attribute__((section(".modinfo"))) = \
240 "parm_desc_" __MODULE_STRING(var) "=" desc
243 * MODULE_DEVICE_TABLE exports information about devices
244 * currently supported by this module. A device type, such as PCI,
245 * is a C-like identifier passed as the first arg to this macro.
246 * The second macro arg is the variable containing the device
247 * information being made public.
249 * The following is a list of known device types (arg 1),
250 * and the C types which are to be passed as arg 2.
251 * pci - struct pci_device_id - List of PCI ids supported by this module
252 * isapnp - struct isapnp_device_id - List of ISA PnP ids supported by this module
253 * usb - struct usb_device_id - List of USB ids supported by this module
255 #define MODULE_GENERIC_TABLE(gtype,name) \
256 static const unsigned long __module_##gtype##_size \
257 __attribute__ ((unused)) = sizeof(struct gtype##_id); \
258 static const struct gtype##_id * __module_##gtype##_table \
259 __attribute__ ((unused)) = name
262 * The following license idents are currently accepted as indicating free
265 * "GPL" [GNU Public License v2 or later]
266 * "GPL v2" [GNU Public License v2]
267 * "GPL and additional rights" [GNU Public License v2 rights and more]
268 * "Dual BSD/GPL" [GNU Public License v2 or BSD license choice]
269 * "Dual MPL/GPL" [GNU Public License v2 or Mozilla license choice]
271 * The following other idents are available
273 * "Proprietary" [Non free products]
275 * There are dual licensed components, but when running with Linux it is the
276 * GPL that is relevant so this is a non issue. Similarly LGPL linked with GPL
277 * is a GPL combined work.
279 * This exists for several reasons
280 * 1. So modinfo can show license info for users wanting to vet their setup
282 * 2. So the community can ignore bug reports including proprietary modules
283 * 3. So vendors can do likewise based on their own policies
286 #define MODULE_LICENSE(license) \
287 static const char __module_license[] __attribute__((section(".modinfo"))) = \
290 /* Define the module variable, and usage macros. */
291 extern struct module __this_module;
293 #define THIS_MODULE (&__this_module)
294 #define MOD_INC_USE_COUNT __MOD_INC_USE_COUNT(THIS_MODULE)
295 #define MOD_DEC_USE_COUNT __MOD_DEC_USE_COUNT(THIS_MODULE)
296 #define MOD_IN_USE __MOD_IN_USE(THIS_MODULE)
298 #include <linux/version.h>
299 static const char __module_kernel_version[] __attribute__((section(".modinfo"))) =
300 "kernel_version=" UTS_RELEASE;
302 static const char __module_using_checksums[] __attribute__((section(".modinfo"))) =
308 #define MODULE_AUTHOR(name)
309 #define MODULE_LICENSE(license)
310 #define MODULE_DESCRIPTION(desc)
311 #define MODULE_SUPPORTED_DEVICE(name)
312 #define MODULE_PARM(var,type)
313 #define MODULE_PARM_DESC(var,desc)
315 /* Create a dummy reference to the table to suppress gcc unused warnings. Put
316 * the reference in the .data.exit section which is discarded when code is built
317 * in, so the reference does not bloat the running kernel. Note: cannot be
318 * const, other exit data may be writable.
320 #define MODULE_GENERIC_TABLE(gtype,name) \
321 static const struct gtype##_id * __module_##gtype##_table \
322 __attribute__ ((unused, __section__(".data.exit"))) = name
326 #define THIS_MODULE NULL
327 #define MOD_INC_USE_COUNT do { } while (0)
328 #define MOD_DEC_USE_COUNT do { } while (0)
331 extern struct module *module_list;
333 #endif /* !__GENKSYMS__ */
337 #define MODULE_DEVICE_TABLE(type,name) \
338 MODULE_GENERIC_TABLE(type##_device,name)
340 /* Export a symbol either from the kernel or a module.
342 In the kernel, the symbol is added to the kernel's global symbol table.
344 In a module, it controls which variables are exported. If no
345 variables are explicitly exported, the action is controled by the
346 insmod -[xX] flags. Otherwise, only the variables listed are exported.
347 This obviates the need for the old register_symtab() function. */
349 #if defined(__GENKSYMS__)
351 /* We want the EXPORT_SYMBOL tag left intact for recognition. */
353 #elif !defined(AUTOCONF_INCLUDED)
355 #define __EXPORT_SYMBOL(sym,str) error config_must_be_included_before_module
356 #define EXPORT_SYMBOL(var) error config_must_be_included_before_module
357 #define EXPORT_SYMBOL_NOVERS(var) error config_must_be_included_before_module
358 #define EXPORT_SYMBOL_GPL(var) error config_must_be_included_before_module
360 #elif !defined(CONFIG_MODULES)
362 #define __EXPORT_SYMBOL(sym,str)
363 #define EXPORT_SYMBOL(var)
364 #define EXPORT_SYMBOL_NOVERS(var)
365 #define EXPORT_SYMBOL_GPL(var)
367 #elif !defined(EXPORT_SYMTAB)
369 #define __EXPORT_SYMBOL(sym,str) error this_object_must_be_defined_as_export_objs_in_the_Makefile
370 #define EXPORT_SYMBOL(var) error this_object_must_be_defined_as_export_objs_in_the_Makefile
371 #define EXPORT_SYMBOL_NOVERS(var) error this_object_must_be_defined_as_export_objs_in_the_Makefile
372 #define EXPORT_SYMBOL_GPL(var) error this_object_must_be_defined_as_export_objs_in_the_Makefile
376 #define __EXPORT_SYMBOL(sym, str) \
377 const char __kstrtab_##sym[] \
378 __attribute__((section(".kstrtab"))) = str; \
379 const struct module_symbol __ksymtab_##sym \
380 __attribute__((section("__ksymtab"))) = \
381 { (unsigned long)&sym, __kstrtab_##sym }
383 #define __EXPORT_SYMBOL_GPL(sym, str) \
384 const char __kstrtab_##sym[] \
385 __attribute__((section(".kstrtab"))) = "GPLONLY_" str; \
386 const struct module_symbol __ksymtab_##sym \
387 __attribute__((section("__ksymtab"))) = \
388 { (unsigned long)&sym, __kstrtab_##sym }
390 #if defined(MODVERSIONS) || !defined(CONFIG_MODVERSIONS)
391 #define EXPORT_SYMBOL(var) __EXPORT_SYMBOL(var, __MODULE_STRING(var))
392 #define EXPORT_SYMBOL_GPL(var) __EXPORT_SYMBOL_GPL(var, __MODULE_STRING(var))
394 #define EXPORT_SYMBOL(var) __EXPORT_SYMBOL(var, __MODULE_STRING(__VERSIONED_SYMBOL(var)))
395 #define EXPORT_SYMBOL_GPL(var) __EXPORT_SYMBOL(var, __MODULE_STRING(__VERSIONED_SYMBOL(var)))
398 #define EXPORT_SYMBOL_NOVERS(var) __EXPORT_SYMBOL(var, __MODULE_STRING(var))
400 #endif /* __GENKSYMS__ */
403 /* Force a module to export no symbols. */
404 #define EXPORT_NO_SYMBOLS __asm__(".section __ksymtab\n.previous")
406 #define EXPORT_NO_SYMBOLS
409 #ifdef CONFIG_MODULES
410 #define SET_MODULE_OWNER(some_struct) do { (some_struct)->owner = THIS_MODULE; } while (0)
412 #define SET_MODULE_OWNER(some_struct) do { } while (0)
415 #endif /* _LINUX_MODULE_H */