1 /*
2 * Dynamic loading of modules into the kernel.
3 *
4 * Rewritten by Richard Henderson <rth@tamu.edu> Dec 1996
5 */
6
7 #ifndef _LINUX_MODULE_H
8 #define _LINUX_MODULE_H
9
10 #include <linux/config.h>
11
12 #ifdef __GENKSYMS__
13 # define _set_ver(sym) sym
14 # undef MODVERSIONS
15 # define MODVERSIONS
16 #else /* ! __GENKSYMS__ */
17 # if !defined(MODVERSIONS) && defined(EXPORT_SYMTAB)
18 # define _set_ver(sym) sym
19 # include <linux/modversions.h>
20 # endif
21 #endif /* __GENKSYMS__ */
22
23 #include <asm/atomic.h>
24
25 /* Don't need to bring in all of uaccess.h just for this decl. */
26 struct exception_table_entry;
27
28 /* Used by get_kernel_syms, which is obsolete. */
29 struct kernel_sym
30 {
31 unsigned long value;
32 char name[60]; /* should have been 64-sizeof(long); oh well */
33 };
34
35 struct module_symbol
36 {
37 unsigned long value;
38 const char *name;
39 };
40
41 struct module_ref
42 {
43 struct module *dep; /* "parent" pointer */
44 struct module *ref; /* "child" pointer */
45 struct module_ref *next_ref;
46 };
47
48 /* TBD */
49 struct module_persist;
50
51 struct module
52 {
53 unsigned long size_of_struct; /* == sizeof(module) */
54 struct module *next;
55 const char *name;
56 unsigned long size;
57
58 union
59 {
60 atomic_t usecount;
61 long pad;
62 } uc; /* Needs to keep its size - so says rth */
63
64 unsigned long flags; /* AUTOCLEAN et al */
65
66 unsigned nsyms;
67 unsigned ndeps;
68
69 struct module_symbol *syms;
70 struct module_ref *deps;
71 struct module_ref *refs;
72 int (*init)(void);
73 void (*cleanup)(void);
74 const struct exception_table_entry *ex_table_start;
75 const struct exception_table_entry *ex_table_end;
76 #ifdef __alpha__
77 unsigned long gp;
78 #endif
79 /* Members past this point are extensions to the basic
80 module support and are optional. Use mod_opt_member()
81 to examine them. */
82 const struct module_persist *persist_start;
83 const struct module_persist *persist_end;
84 int (*can_unload)(void);
85 };
86
87 struct module_info
88 {
89 unsigned long addr;
90 unsigned long size;
91 unsigned long flags;
92 long usecount;
93 };
94
95 /* Bits of module.flags. */
96
97 #define MOD_UNINITIALIZED 0
98 #define MOD_RUNNING 1
99 #define MOD_DELETED 2
100 #define MOD_AUTOCLEAN 4
101 #define MOD_VISITED 8
102 #define MOD_USED_ONCE 16
103 #define MOD_JUST_FREED 32
104
105 /* Values for query_module's which. */
106
107 #define QM_MODULES 1
108 #define QM_DEPS 2
109 #define QM_REFS 3
110 #define QM_SYMBOLS 4
111 #define QM_INFO 5
112
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. */
116
117 #define mod_member_present(mod,member) \
118 ((unsigned long)(&((struct module *)0L)->member + 1) \
119 <= (mod)->size_of_struct)
120
121 /* Backwards compatibility definition. */
122
123 #define GET_USE_COUNT(module) (atomic_read(&(module)->uc.usecount))
124
125 /* Poke the use count of a module. */
126
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))
134
135 /* Indirect stringification. */
136
137 #define __MODULE_STRING_1(x) #x
138 #define __MODULE_STRING(x) __MODULE_STRING_1(x)
139
140 /* Find a symbol exported by the kernel or another module */
141 extern unsigned long get_module_symbol(char *, char *);
142
143 #if defined(MODULE) && !defined(__GENKSYMS__)
144
145 /* Embedded module documentation macros. */
146
147 /* For documentation purposes only. */
148
149 #define MODULE_AUTHOR(name) \
150 const char __module_author[] __attribute__((section(".modinfo"))) = \
151 "author=" name
152
153 #define MODULE_DESCRIPTION(desc) \
154 const char __module_description[] __attribute__((section(".modinfo"))) = \
155 "description=" desc
156
157 /* Could potentially be used by kmod... */
158
159 #define MODULE_SUPPORTED_DEVICE(dev) \
160 const char __module_device[] __attribute__((section(".modinfo"))) = \
161 "device=" dev
162
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:
169 b byte
170 h short
171 i int
172 l long
173 s string
174 */
175
176 #define MODULE_PARM(var,type) \
177 const char __module_parm_##var[] \
178 __attribute__((section(".modinfo"))) = \
179 "parm_" __MODULE_STRING(var) "=" type
180
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
185
186 /* The attributes of a section are set the first time the section is
187 seen; we want .modinfo to not be allocated. */
188
189 __asm__(".section .modinfo\n\t.previous");
190
191 /* Define the module variable, and usage macros. */
192 extern struct module __this_module;
193
194 #define MOD_INC_USE_COUNT __MOD_INC_USE_COUNT(&__this_module)
195 #define MOD_DEC_USE_COUNT __MOD_DEC_USE_COUNT(&__this_module)
196 #define MOD_IN_USE __MOD_IN_USE(&__this_module)
197
198 #ifndef __NO_VERSION__
199 #include <linux/version.h>
200 const char __module_kernel_version[] __attribute__((section(".modinfo"))) =
201 "kernel_version=" UTS_RELEASE;
202 #ifdef MODVERSIONS
203 const char __module_using_checksums[] __attribute__((section(".modinfo"))) =
204 "using_checksums=1";
205 #endif
206 #endif
207
208 #else /* MODULE */
209
210 #define MODULE_AUTHOR(name)
211 #define MODULE_DESCRIPTION(desc)
212 #define MODULE_SUPPORTED_DEVICE(name)
213 #define MODULE_PARM(var,type)
214 #define MODULE_PARM_DESC(var,desc)
215
216 #ifndef __GENKSYMS__
217
218 #define MOD_INC_USE_COUNT do { } while (0)
219 #define MOD_DEC_USE_COUNT do { } while (0)
220 #define MOD_IN_USE 1
221
222 extern struct module *module_list;
223
224 #endif /* !__GENKSYMS__ */
225
226 #endif /* MODULE */
227
228 /* Export a symbol either from the kernel or a module.
229
230 In the kernel, the symbol is added to the kernel's global symbol table.
231
232 In a module, it controls which variables are exported. If no
233 variables are explicitly exported, the action is controled by the
234 insmod -[xX] flags. Otherwise, only the variables listed are exported.
235 This obviates the need for the old register_symtab() function. */
236
237 #if defined(__GENKSYMS__)
238
239 /* We want the EXPORT_SYMBOL tag left intact for recognition. */
240
241 #elif !defined(AUTOCONF_INCLUDED)
242
243 #define __EXPORT_SYMBOL(sym,str) error config_must_be_included_before_module
244 #define EXPORT_SYMBOL(var) error config_must_be_included_before_module
245 #define EXPORT_SYMBOL_NOVERS(var) error config_must_be_included_before_module
246
247 #elif !defined(CONFIG_MODULES)
248
249 #define __EXPORT_SYMBOL(sym,str)
250 #define EXPORT_SYMBOL(var)
251 #define EXPORT_SYMBOL_NOVERS(var)
252
253 #elif !defined(EXPORT_SYMTAB)
254
255 /* If things weren't set up in the Makefiles to get EXPORT_SYMTAB defined,
256 then they weren't set up to run genksyms properly so MODVERSIONS breaks. */
257 #define __EXPORT_SYMBOL(sym,str) error EXPORT_SYMTAB_not_defined
258 #define EXPORT_SYMBOL(var) error EXPORT_SYMTAB_not_defined
259 #define EXPORT_SYMBOL_NOVERS(var) error EXPORT_SYMTAB_not_defined
260
261 #else
262
263 #define __EXPORT_SYMBOL(sym, str) \
264 const char __kstrtab_##sym[] \
265 __attribute__((section(".kstrtab"))) = str; \
266 const struct module_symbol __ksymtab_##sym \
267 __attribute__((section("__ksymtab"))) = \
268 { (unsigned long)&sym, __kstrtab_##sym }
269
270 #if defined(MODVERSIONS) || !defined(CONFIG_MODVERSIONS)
271 #define EXPORT_SYMBOL(var) __EXPORT_SYMBOL(var, __MODULE_STRING(var))
272 #else
273 #define EXPORT_SYMBOL(var) __EXPORT_SYMBOL(var, __MODULE_STRING(__VERSIONED_SYMBOL(var)))
274 #endif
275
276 #define EXPORT_SYMBOL_NOVERS(var) __EXPORT_SYMBOL(var, __MODULE_STRING(var))
277
278 #endif /* __GENKSYMS__ */
279
280 #ifdef MODULE
281 /* Force a module to export no symbols. */
282 #define EXPORT_NO_SYMBOLS __asm__(".section __ksymtab\n.previous")
283 #else
284 #define EXPORT_NO_SYMBOLS
285 #endif /* MODULE */
286
287 #endif /* _LINUX_MODULE_H */
288
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.