4 * This is a bastardized version of linux/module.h, since the latter
5 * doesn't have __KERNEL__ guards where it needs them...
12 * Dynamic loading of modules into the kernel.
14 * Rewritten by Richard Henderson <rth@tamu.edu> Dec 1996
17 #include <asm/atomic.h>
19 /* Don't need to bring in all of uaccess.h just for this decl. */
20 struct exception_table_entry;
22 /* Used by get_kernel_syms, which is obsolete. */
26 char name[60]; /* should have been 64-sizeof(long); oh well */
37 struct module *dep; /* "parent" pointer */
38 struct module *ref; /* "child" pointer */
39 struct module_ref *next_ref;
43 struct module_persist;
47 unsigned long size_of_struct; /* == sizeof(module) */
56 } uc; /* Needs to keep its size - so says rth */
58 unsigned long flags; /* AUTOCLEAN et al */
63 struct module_symbol *syms;
64 struct module_ref *deps;
65 struct module_ref *refs;
67 void (*cleanup)(void);
68 const struct exception_table_entry *ex_table_start;
69 const struct exception_table_entry *ex_table_end;
73 /* Members past this point are extensions to the basic
74 module support and are optional. Use mod_member_present()
76 const struct module_persist *persist_start;
77 const struct module_persist *persist_end;
78 int (*can_unload)(void);
79 int runsize; /* In modutils, not currently used */
80 const char *kallsyms_start; /* All symbols for kernel debugging */
81 const char *kallsyms_end;
82 const char *archdata_start; /* arch specific data for module */
83 const char *archdata_end;
84 const char *kernel_data; /* Reserved for kernel internal use */
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
104 #define MOD_INITIALIZING 64
106 /* Values for query_module's which. */
114 /* Can the module be queried? */
115 #define MOD_CAN_QUERY(mod) (((mod)->flags & (MOD_RUNNING | MOD_INITIALIZING)) && !((mod)->flags & MOD_DELETED))
117 /* When struct module is extended, we must test whether the new member
118 is present in the header received from insmod before we can use it.
119 This function returns true if the member is present. */
121 #define mod_member_present(mod,member) \
122 ((unsigned long)(&((struct module *)0L)->member + 1) \
123 <= (mod)->size_of_struct)
126 * Ditto for archdata. Assumes mod->archdata_start and mod->archdata_end
127 * are validated elsewhere.
129 #define mod_archdata_member_present(mod, type, member) \
130 (((unsigned long)(&((type *)0L)->member) + \
131 sizeof(((type *)0L)->member)) <= \
132 ((mod)->archdata_end - (mod)->archdata_start))
135 /* Check if an address p with number of entries n is within the body of module m */
136 #define mod_bound(p, n, m) ((unsigned long)(p) >= ((unsigned long)(m) + ((m)->size_of_struct)) && \
137 (unsigned long)((p)+(n)) <= (unsigned long)(m) + (m)->size)
139 /* Backwards compatibility definition. */
141 #define GET_USE_COUNT(module) (atomic_read(&(module)->uc.usecount))
143 /* Poke the use count of a module. */
145 #define __MOD_INC_USE_COUNT(mod) \
146 (atomic_inc(&(mod)->uc.usecount), (mod)->flags |= MOD_VISITED|MOD_USED_ONCE)
147 #define __MOD_DEC_USE_COUNT(mod) \
148 (atomic_dec(&(mod)->uc.usecount), (mod)->flags |= MOD_VISITED)
149 #define __MOD_IN_USE(mod) \
150 (mod_member_present((mod), can_unload) && (mod)->can_unload \
151 ? (mod)->can_unload() : atomic_read(&(mod)->uc.usecount))
153 /* Indirect stringification. */
155 #define __MODULE_STRING_1(x) #x
156 #define __MODULE_STRING(x) __MODULE_STRING_1(x)
158 #endif /* _SYS_MODULE_H */