1
2
3
4
5
6
7#ifndef _LINUX_MODULE_H
8#define _LINUX_MODULE_H
9
10#include <linux/config.h>
11#include <linux/spinlock.h>
12#include <linux/list.h>
13
14#ifdef __GENKSYMS__
15# define _set_ver(sym) sym
16# undef MODVERSIONS
17# define MODVERSIONS
18#else
19# if !defined(MODVERSIONS) && defined(EXPORT_SYMTAB)
20# define _set_ver(sym) sym
21# include <linux/modversions.h>
22# endif
23#endif
24
25#include <asm/atomic.h>
26
27
28struct exception_table_entry;
29
30
31struct kernel_sym
32{
33 unsigned long value;
34 char name[60];
35};
36
37struct module_symbol
38{
39 unsigned long value;
40 const char *name;
41};
42
43struct module_ref
44{
45 struct module *dep;
46 struct module *ref;
47 struct module_ref *next_ref;
48};
49
50
51struct module_persist;
52
53struct module
54{
55 unsigned long size_of_struct;
56 struct module *next;
57 const char *name;
58 unsigned long size;
59
60 union
61 {
62 atomic_t usecount;
63 long pad;
64 } uc;
65
66 unsigned long flags;
67
68 unsigned nsyms;
69 unsigned ndeps;
70
71 struct module_symbol *syms;
72 struct module_ref *deps;
73 struct module_ref *refs;
74 int (*init)(void);
75 void (*cleanup)(void);
76 const struct exception_table_entry *ex_table_start;
77 const struct exception_table_entry *ex_table_end;
78#ifdef __alpha__
79 unsigned long gp;
80#endif
81
82
83
84 const struct module_persist *persist_start;
85 const struct module_persist *persist_end;
86 int (*can_unload)(void);
87 int runsize;
88 const char *kallsyms_start;
89 const char *kallsyms_end;
90 const char *archdata_start;
91 const char *archdata_end;
92 const char *kernel_data;
93};
94
95struct module_info
96{
97 unsigned long addr;
98 unsigned long size;
99 unsigned long flags;
100 long usecount;
101};
102
103
104
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
113
114
115
116#define QM_MODULES 1
117#define QM_DEPS 2
118#define QM_REFS 3
119#define QM_SYMBOLS 4
120#define QM_INFO 5
121
122
123#define MOD_CAN_QUERY(mod) (((mod)->flags & (MOD_RUNNING | MOD_INITIALIZING)) && !((mod)->flags & MOD_DELETED))
124
125
126
127
128
129#define mod_member_present(mod,member) \
130 ((unsigned long)(&((struct module *)0L)->member + 1) \
131 <= (mod)->size_of_struct)
132
133
134
135
136
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))
141
142
143
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)
146
147
148
149#define GET_USE_COUNT(module) (atomic_read(&(module)->uc.usecount))
150
151
152
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))
160
161
162
163#define __MODULE_STRING_1(x) #x
164#define __MODULE_STRING(x) __MODULE_STRING_1(x)
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181#ifdef __KERNEL__
182#define HAVE_INTER_MODULE
183extern void inter_module_register(const char *, struct module *, const void *);
184extern void inter_module_unregister(const char *);
185extern const void *inter_module_get(const char *);
186extern const void *inter_module_get_request(const char *, const char *);
187extern void inter_module_put(const char *);
188
189struct inter_module_entry {
190 struct list_head list;
191 const char *im_name;
192 struct module *owner;
193 const void *userdata;
194};
195
196extern int try_inc_mod_count(struct module *mod);
197#endif
198
199#if defined(MODULE) && !defined(__GENKSYMS__)
200
201
202
203
204
205#define MODULE_AUTHOR(name) \
206const char __module_author[] __attribute__((section(".modinfo"))) = \
207"author=" name
208
209#define MODULE_DESCRIPTION(desc) \
210const char __module_description[] __attribute__((section(".modinfo"))) = \
211"description=" desc
212
213
214
215#define MODULE_SUPPORTED_DEVICE(dev) \
216const char __module_device[] __attribute__((section(".modinfo"))) = \
217"device=" dev
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232#define MODULE_PARM(var,type) \
233const char __module_parm_##var[] \
234__attribute__((section(".modinfo"))) = \
235"parm_" __MODULE_STRING(var) "=" type
236
237#define MODULE_PARM_DESC(var,desc) \
238const char __module_parm_desc_##var[] \
239__attribute__((section(".modinfo"))) = \
240"parm_desc_" __MODULE_STRING(var) "=" desc
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255#define MODULE_GENERIC_TABLE(gtype,name) \
256static const unsigned long __module_##gtype##_size \
257 __attribute__ ((unused)) = sizeof(struct gtype##_id); \
258static const struct gtype##_id * __module_##gtype##_table \
259 __attribute__ ((unused)) = name
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285#define MODULE_LICENSE(license) \
286static const char __module_license[] __attribute__((section(".modinfo"))) = \
287"license=" license
288
289
290extern struct module __this_module;
291
292#define THIS_MODULE (&__this_module)
293#define MOD_INC_USE_COUNT __MOD_INC_USE_COUNT(THIS_MODULE)
294#define MOD_DEC_USE_COUNT __MOD_DEC_USE_COUNT(THIS_MODULE)
295#define MOD_IN_USE __MOD_IN_USE(THIS_MODULE)
296
297#include <linux/version.h>
298static const char __module_kernel_version[] __attribute__((section(".modinfo"))) =
299"kernel_version=" UTS_RELEASE;
300#ifdef MODVERSIONS
301static const char __module_using_checksums[] __attribute__((section(".modinfo"))) =
302"using_checksums=1";
303#endif
304
305#else
306
307#define MODULE_AUTHOR(name)
308#define MODULE_LICENSE(license)
309#define MODULE_DESCRIPTION(desc)
310#define MODULE_SUPPORTED_DEVICE(name)
311#define MODULE_PARM(var,type)
312#define MODULE_PARM_DESC(var,desc)
313
314
315
316
317
318
319#define MODULE_GENERIC_TABLE(gtype,name) \
320static const struct gtype##_id * __module_##gtype##_table \
321 __attribute__ ((unused, __section__(".data.exit"))) = name
322
323#ifndef __GENKSYMS__
324
325#define THIS_MODULE NULL
326#define MOD_INC_USE_COUNT do { } while (0)
327#define MOD_DEC_USE_COUNT do { } while (0)
328#define MOD_IN_USE 1
329
330extern struct module *module_list;
331
332#endif
333
334#endif
335
336#define MODULE_DEVICE_TABLE(type,name) \
337 MODULE_GENERIC_TABLE(type##_device,name)
338
339
340
341
342
343
344
345
346
347
348#if defined(__GENKSYMS__)
349
350
351
352#elif !defined(AUTOCONF_INCLUDED)
353
354#define __EXPORT_SYMBOL(sym,str) error config_must_be_included_before_module
355#define EXPORT_SYMBOL(var) error config_must_be_included_before_module
356#define EXPORT_SYMBOL_NOVERS(var) error config_must_be_included_before_module
357#define EXPORT_SYMBOL_GPL(var) error config_must_be_included_before_module
358
359#elif !defined(CONFIG_MODULES)
360
361#define __EXPORT_SYMBOL(sym,str)
362#define EXPORT_SYMBOL(var)
363#define EXPORT_SYMBOL_NOVERS(var)
364#define EXPORT_SYMBOL_GPL(var)
365
366#elif !defined(EXPORT_SYMTAB)
367
368#define __EXPORT_SYMBOL(sym,str) error this_object_must_be_defined_as_export_objs_in_the_Makefile
369#define EXPORT_SYMBOL(var) error this_object_must_be_defined_as_export_objs_in_the_Makefile
370#define EXPORT_SYMBOL_NOVERS(var) error this_object_must_be_defined_as_export_objs_in_the_Makefile
371#define EXPORT_SYMBOL_GPL(var) error this_object_must_be_defined_as_export_objs_in_the_Makefile
372
373#else
374
375#define __EXPORT_SYMBOL(sym, str) \
376const char __kstrtab_##sym[] \
377__attribute__((section(".kstrtab"))) = str; \
378const struct module_symbol __ksymtab_##sym \
379__attribute__((section("__ksymtab"))) = \
380{ (unsigned long)&sym, __kstrtab_##sym }
381
382#define __EXPORT_SYMBOL_GPL(sym, str) \
383const char __kstrtab_##sym[] \
384__attribute__((section(".kstrtab"))) = "GPLONLY_" str; \
385const struct module_symbol __ksymtab_##sym \
386__attribute__((section("__ksymtab"))) = \
387{ (unsigned long)&sym, __kstrtab_##sym }
388
389#if defined(MODVERSIONS) || !defined(CONFIG_MODVERSIONS)
390#define EXPORT_SYMBOL(var) __EXPORT_SYMBOL(var, __MODULE_STRING(var))
391#define EXPORT_SYMBOL_GPL(var) __EXPORT_SYMBOL_GPL(var, __MODULE_STRING(var))
392#else
393#define EXPORT_SYMBOL(var) __EXPORT_SYMBOL(var, __MODULE_STRING(__VERSIONED_SYMBOL(var)))
394#define EXPORT_SYMBOL_GPL(var) __EXPORT_SYMBOL(var, __MODULE_STRING(__VERSIONED_SYMBOL(var)))
395#endif
396
397#define EXPORT_SYMBOL_NOVERS(var) __EXPORT_SYMBOL(var, __MODULE_STRING(var))
398
399#endif
400
401#ifdef MODULE
402
403#define EXPORT_NO_SYMBOLS __asm__(".section __ksymtab\n.previous")
404#else
405#define EXPORT_NO_SYMBOLS
406#endif
407
408#ifdef CONFIG_MODULES
409#define SET_MODULE_OWNER(some_struct) do { (some_struct)->owner = THIS_MODULE; } while (0)
410#else
411#define SET_MODULE_OWNER(some_struct) do { } while (0)
412#endif
413
414#endif
415