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>
13 # define _set_ver(sym) sym
16 #else /* ! __GENKSYMS__ */
17 # if !defined(MODVERSIONS) && defined(EXPORT_SYMTAB)
18 # define _set_ver(sym) sym
19 # include <linux/modversions.h>
21 #endif /* __GENKSYMS__ */
23 #include <asm/atomic.h>
25 /* Don't need to bring in all of uaccess.h just for this decl. */
26 struct exception_table_entry
;
28 /* Used by get_kernel_syms, which is obsolete. */
32 char name
[60]; /* should have been 64-sizeof(long); oh well */
43 struct module
*dep
; /* "parent" pointer */
44 struct module
*ref
; /* "child" pointer */
45 struct module_ref
*next_ref
;
49 struct module_persist
;
53 unsigned long size_of_struct
; /* == sizeof(module) */
62 } uc
; /* Needs to keep its size - so says rth */
64 unsigned long flags
; /* AUTOCLEAN et al */
69 struct module_symbol
*syms
;
70 struct module_ref
*deps
;
71 struct module_ref
*refs
;
73 void (*cleanup
)(void);
74 const struct exception_table_entry
*ex_table_start
;
75 const struct exception_table_entry
*ex_table_end
;
79 /* Members past this point are extensions to the basic
80 module support and are optional. Use mod_opt_member()
82 const struct module_persist
*persist_start
;
83 const struct module_persist
*persist_end
;
84 int (*can_unload
)(void);
95 /* Bits of module.flags. */
97 #define MOD_UNINITIALIZED 0
100 #define MOD_AUTOCLEAN 4
101 #define MOD_VISITED 8
102 #define MOD_USED_ONCE 16
103 #define MOD_JUST_FREED 32
105 /* Values for query_module's which. */
113 /* When struct module is extended, we must test whether the new member
114 is present in the header received from insmod before we can use it.
115 This function returns true if the member is present. */
117 #define mod_member_present(mod,member) \
118 ((unsigned long)(&((struct module *)0L)->member + 1) \
119 <= (mod)->size_of_struct)
121 /* Backwards compatibility definition. */
123 #define GET_USE_COUNT(module) (atomic_read(&(module)->uc.usecount))
125 /* Poke the use count of a module. */
127 #define __MOD_INC_USE_COUNT(mod) \
128 (atomic_inc(&(mod)->uc.usecount), (mod)->flags |= MOD_VISITED|MOD_USED_ONCE)
129 #define __MOD_DEC_USE_COUNT(mod) \
130 (atomic_dec(&(mod)->uc.usecount), (mod)->flags |= MOD_VISITED)
131 #define __MOD_IN_USE(mod) \
132 (mod_member_present((mod), can_unload) && (mod)->can_unload \
133 ? (mod)->can_unload() : atomic_read(&(mod)->uc.usecount))
135 /* Indirect stringification. */
137 #define __MODULE_STRING_1(x) #x
138 #define __MODULE_STRING(x) __MODULE_STRING_1(x)
140 /* Find a symbol exported by the kernel or another module */
141 extern unsigned long get_module_symbol(char *, char *);
143 #if defined(MODULE) && !defined(__GENKSYMS__)
145 /* Embedded module documentation macros. */
147 /* For documentation purposes only. */
149 #define MODULE_AUTHOR(name) \
150 const char __module_author[] __attribute__((section(".modinfo"))) = \
153 #define MODULE_DESCRIPTION(desc) \
154 const char __module_description[] __attribute__((section(".modinfo"))) = \
157 /* Could potentially be used by kmod... */
159 #define MODULE_SUPPORTED_DEVICE(dev) \
160 const char __module_device[] __attribute__((section(".modinfo"))) = \
163 /* Used to verify parameters given to the module. The TYPE arg should
164 be a string in the following format:
165 [min[-max]]{b,h,i,l,s}
166 The MIN and MAX specifiers delimit the length of the array. If MAX
167 is omitted, it defaults to MIN; if both are omitted, the default is 1.
168 The final character is a type specifier:
176 #define MODULE_PARM(var,type) \
177 const char __module_parm_##var[] \
178 __attribute__((section(".modinfo"))) = \
179 "parm_" __MODULE_STRING(var) "=" type
181 #define MODULE_PARM_DESC(var,desc) \
182 const char __module_parm_desc_##var[] \
183 __attribute__((section(".modinfo"))) = \
184 "parm_desc_" __MODULE_STRING(var) "=" desc
186 /* The attributes of a section are set the first time the section is
187 seen; we want .modinfo to not be allocated. */
189 __asm__(".section .modinfo\n\t.previous");
191 /* Define the module variable, and usage macros. */
192 extern struct module __this_module
;
194 #define THIS_MODULE (&__this_module)
195 #define MOD_INC_USE_COUNT __MOD_INC_USE_COUNT(THIS_MODULE)
196 #define MOD_DEC_USE_COUNT __MOD_DEC_USE_COUNT(THIS_MODULE)
197 #define MOD_IN_USE __MOD_IN_USE(THIS_MODULE)
199 #ifndef __NO_VERSION__
200 #include <linux/version.h>
201 const char __module_kernel_version
[] __attribute__((section(".modinfo"))) =
202 "kernel_version=" UTS_RELEASE
;
204 const char __module_using_checksums
[] __attribute__((section(".modinfo"))) =
211 #define MODULE_AUTHOR(name)
212 #define MODULE_DESCRIPTION(desc)
213 #define MODULE_SUPPORTED_DEVICE(name)
214 #define MODULE_PARM(var,type)
215 #define MODULE_PARM_DESC(var,desc)
219 #define THIS_MODULE NULL
220 #define MOD_INC_USE_COUNT do { } while (0)
221 #define MOD_DEC_USE_COUNT do { } while (0)
224 extern struct module
*module_list
;
226 #endif /* !__GENKSYMS__ */
230 /* Export a symbol either from the kernel or a module.
232 In the kernel, the symbol is added to the kernel's global symbol table.
234 In a module, it controls which variables are exported. If no
235 variables are explicitly exported, the action is controled by the
236 insmod -[xX] flags. Otherwise, only the variables listed are exported.
237 This obviates the need for the old register_symtab() function. */
239 #if defined(__GENKSYMS__)
241 /* We want the EXPORT_SYMBOL tag left intact for recognition. */
243 #elif !defined(AUTOCONF_INCLUDED)
245 #define __EXPORT_SYMBOL(sym,str) error config_must_be_included_before_module
246 #define EXPORT_SYMBOL(var) error config_must_be_included_before_module
247 #define EXPORT_SYMBOL_NOVERS(var) error config_must_be_included_before_module
249 #elif !defined(CONFIG_MODULES)
251 #define __EXPORT_SYMBOL(sym,str)
252 #define EXPORT_SYMBOL(var)
253 #define EXPORT_SYMBOL_NOVERS(var)
255 #elif !defined(EXPORT_SYMTAB)
257 /* If things weren't set up in the Makefiles to get EXPORT_SYMTAB defined,
258 then they weren't set up to run genksyms properly so MODVERSIONS breaks. */
259 #define __EXPORT_SYMBOL(sym,str) error EXPORT_SYMTAB_not_defined
260 #define EXPORT_SYMBOL(var) error EXPORT_SYMTAB_not_defined
261 #define EXPORT_SYMBOL_NOVERS(var) error EXPORT_SYMTAB_not_defined
265 #define __EXPORT_SYMBOL(sym, str) \
266 const char __kstrtab_##sym[] \
267 __attribute__((section(".kstrtab"))) = str; \
268 const struct module_symbol __ksymtab_##sym \
269 __attribute__((section("__ksymtab"))) = \
270 { (unsigned long)&sym, __kstrtab_##sym }
272 #if defined(MODVERSIONS) || !defined(CONFIG_MODVERSIONS)
273 #define EXPORT_SYMBOL(var) __EXPORT_SYMBOL(var, __MODULE_STRING(var))
275 #define EXPORT_SYMBOL(var) __EXPORT_SYMBOL(var, __MODULE_STRING(__VERSIONED_SYMBOL(var)))
278 #define EXPORT_SYMBOL_NOVERS(var) __EXPORT_SYMBOL(var, __MODULE_STRING(var))
280 #endif /* __GENKSYMS__ */
283 /* Force a module to export no symbols. */
284 #define EXPORT_NO_SYMBOLS __asm__(".section __ksymtab\n.previous")
286 #define EXPORT_NO_SYMBOLS
289 #endif /* _LINUX_MODULE_H */