chiark / gitweb /
[PATCH] added klibc version 0.82 (cvs tree) to the udev tree.
[elogind.git] / klibc / klibc / include / sys / module.h
1 /*
2  * sys/module.h
3  *
4  * This is a bastardized version of linux/module.h, since the latter
5  * doesn't have __KERNEL__ guards where it needs them...
6  */
7
8 #ifndef _SYS_MODULE_H
9 #define _SYS_MODULE_H
10
11 /*
12  * Dynamic loading of modules into the kernel.
13  *
14  * Rewritten by Richard Henderson <rth@tamu.edu> Dec 1996
15  */
16
17 #include <asm/atomic.h>
18
19 /* Don't need to bring in all of uaccess.h just for this decl.  */
20 struct exception_table_entry;
21
22 /* Used by get_kernel_syms, which is obsolete.  */
23 struct kernel_sym
24 {
25         unsigned long value;
26         char name[60];          /* should have been 64-sizeof(long); oh well */
27 };
28
29 struct module_symbol
30 {
31         unsigned long value;
32         const char *name;
33 };
34
35 struct module_ref
36 {
37         struct module *dep;     /* "parent" pointer */
38         struct module *ref;     /* "child" pointer */
39         struct module_ref *next_ref;
40 };
41
42 /* TBD */
43 struct module_persist;
44
45 struct module
46 {
47         unsigned long size_of_struct;   /* == sizeof(module) */
48         struct module *next;
49         const char *name;
50         unsigned long size;
51
52         union
53         {
54                 atomic_t usecount;
55                 long pad;
56         } uc;                           /* Needs to keep its size - so says rth */
57
58         unsigned long flags;            /* AUTOCLEAN et al */
59
60         unsigned nsyms;
61         unsigned ndeps;
62
63         struct module_symbol *syms;
64         struct module_ref *deps;
65         struct module_ref *refs;
66         int (*init)(void);
67         void (*cleanup)(void);
68         const struct exception_table_entry *ex_table_start;
69         const struct exception_table_entry *ex_table_end;
70 #ifdef __alpha__
71         unsigned long gp;
72 #endif
73         /* Members past this point are extensions to the basic
74            module support and are optional.  Use mod_member_present()
75            to examine them.  */
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 */
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 #define MOD_INITIALIZING        64
105
106 /* Values for query_module's which.  */
107
108 #define QM_MODULES      1
109 #define QM_DEPS         2
110 #define QM_REFS         3
111 #define QM_SYMBOLS      4
112 #define QM_INFO         5
113
114 /* Can the module be queried? */
115 #define MOD_CAN_QUERY(mod) (((mod)->flags & (MOD_RUNNING | MOD_INITIALIZING)) && !((mod)->flags & MOD_DELETED))
116
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.  */
120
121 #define mod_member_present(mod,member)                                  \
122         ((unsigned long)(&((struct module *)0L)->member + 1)            \
123          <= (mod)->size_of_struct)
124
125 /*
126  * Ditto for archdata.  Assumes mod->archdata_start and mod->archdata_end
127  * are validated elsewhere.
128  */
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))
133          
134
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)
138
139 /* Backwards compatibility definition.  */
140
141 #define GET_USE_COUNT(module)   (atomic_read(&(module)->uc.usecount))
142
143 /* Poke the use count of a module.  */
144
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))
152
153 /* Indirect stringification.  */
154
155 #define __MODULE_STRING_1(x)    #x
156 #define __MODULE_STRING(x)      __MODULE_STRING_1(x)
157
158 #endif /* _SYS_MODULE_H */