Main Page | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

module.h

Go to the documentation of this file.
00001 /*
00002  * Dynamic loading of modules into the kernel.
00003  *
00004  * Rewritten by Richard Henderson <rth@tamu.edu> Dec 1996
00005  */
00006 
00007 #ifndef _LINUX_MODULE_H
00008 #define _LINUX_MODULE_H
00009 
00010 #include <linux/config.h>
00011 
00012 #ifdef __GENKSYMS__
00013 #  define _set_ver(sym) sym
00014 #  undef  MODVERSIONS
00015 #  define MODVERSIONS
00016 #else /* ! __GENKSYMS__ */
00017 # if !defined(MODVERSIONS) && defined(EXPORT_SYMTAB)
00018 #   define _set_ver(sym) sym
00019 #   include <linux/modversions.h>
00020 # endif
00021 #endif /* __GENKSYMS__ */
00022 
00023 #include <asm/atomic.h>
00024 
00025 /* Don't need to bring in all of uaccess.h just for this decl.  */
00026 struct exception_table_entry;
00027 
00028 /* Used by get_kernel_syms, which is obsolete.  */
00029 struct kernel_sym
00030 {
00031         unsigned long value;
00032         char name[60];          /* should have been 64-sizeof(long); oh well */
00033 };
00034 
00035 struct module_symbol
00036 {
00037         unsigned long value;
00038         const char *name;
00039 };
00040 
00041 struct module_ref
00042 {
00043         struct module *dep;     /* "parent" pointer */
00044         struct module *ref;     /* "child" pointer */
00045         struct module_ref *next_ref;
00046 };
00047 
00048 /* TBD */
00049 struct module_persist;
00050 
00051 struct module
00052 {
00053         unsigned long size_of_struct;   /* == sizeof(module) */
00054         struct module *next;
00055         const char *name;
00056         unsigned long size;
00057 
00058         union
00059         {
00060                 atomic_t usecount;
00061                 long pad;
00062         } uc;                           /* Needs to keep its size - so says rth */
00063 
00064         unsigned long flags;            /* AUTOCLEAN et al */
00065 
00066         unsigned nsyms;
00067         unsigned ndeps;
00068 
00069         struct module_symbol *syms;
00070         struct module_ref *deps;
00071         struct module_ref *refs;
00072         int (*init)(void);
00073         void (*cleanup)(void);
00074         const struct exception_table_entry *ex_table_start;
00075         const struct exception_table_entry *ex_table_end;
00076 #ifdef __alpha__
00077         unsigned long gp;
00078 #endif
00079         /* Members past this point are extensions to the basic
00080            module support and are optional.  Use mod_opt_member()
00081            to examine them.  */
00082         const struct module_persist *persist_start;
00083         const struct module_persist *persist_end;
00084         int (*can_unload)(void);
00085 };
00086 
00087 struct module_info
00088 {
00089         unsigned long addr;
00090         unsigned long size;
00091         unsigned long flags;
00092         long usecount;
00093 };
00094 
00095 /* Bits of module.flags.  */
00096 
00097 #define MOD_UNINITIALIZED       0
00098 #define MOD_RUNNING             1
00099 #define MOD_DELETED             2
00100 #define MOD_AUTOCLEAN           4
00101 #define MOD_VISITED             8
00102 #define MOD_USED_ONCE           16
00103 #define MOD_JUST_FREED          32
00104 #define MOD_INITIALIZING        64
00105 
00106 /* Values for query_module's which.  */
00107 
00108 #define QM_MODULES      1
00109 #define QM_DEPS         2
00110 #define QM_REFS         3
00111 #define QM_SYMBOLS      4
00112 #define QM_INFO         5
00113 
00114 /* Can the module be queried? */
00115 #define MOD_CAN_QUERY(mod) (((mod)->flags & (MOD_RUNNING | MOD_INITIALIZING)) && !((mod)->flags & MOD_DELETED))
00116 
00117 /* When struct module is extended, we must test whether the new member
00118    is present in the header received from insmod before we can use it.  
00119    This function returns true if the member is present.  */
00120 
00121 #define mod_member_present(mod,member)                                  \
00122         ((unsigned long)(&((struct module *)0L)->member + 1)            \
00123          <= (mod)->size_of_struct)
00124 
00125 /* Backwards compatibility definition.  */
00126 
00127 #define GET_USE_COUNT(module)   (atomic_read(&(module)->uc.usecount))
00128 
00129 /* Poke the use count of a module.  */
00130 
00131 #define __MOD_INC_USE_COUNT(mod)                                        \
00132         (atomic_inc(&(mod)->uc.usecount), (mod)->flags |= MOD_VISITED|MOD_USED_ONCE)
00133 #define __MOD_DEC_USE_COUNT(mod)                                        \
00134         (atomic_dec(&(mod)->uc.usecount), (mod)->flags |= MOD_VISITED)
00135 #define __MOD_IN_USE(mod)                                               \
00136         (mod_member_present((mod), can_unload) && (mod)->can_unload     \
00137          ? (mod)->can_unload() : atomic_read(&(mod)->uc.usecount))
00138 
00139 extern int try_inc_mod_count(struct module *mod);
00140 /* Indirect stringification.  */
00141 
00142 #define __MODULE_STRING_1(x)    #x
00143 #define __MODULE_STRING(x)      __MODULE_STRING_1(x)
00144 
00145 /* Find a symbol exported by the kernel or another module */
00146 #ifndef CONFIG_MODULES
00147 static inline unsigned long get_module_symbol(char *A, char *B) { return 0; };
00148 #else
00149 extern unsigned long get_module_symbol(char *, char *);
00150 #endif
00151 #if defined(MODULE) && !defined(__GENKSYMS__)
00152 
00153 /* Embedded module documentation macros.  */
00154 
00155 /* For documentation purposes only.  */
00156 
00157 #define MODULE_AUTHOR(name)                                                \
00158 const char __module_author[] __attribute__((section(".modinfo"))) =        \
00159 "author=" name
00160 
00161 #define MODULE_DESCRIPTION(desc)                                           \
00162 const char __module_description[] __attribute__((section(".modinfo"))) =   \
00163 "description=" desc
00164 
00165 /* Could potentially be used by kmod...  */
00166 
00167 #define MODULE_SUPPORTED_DEVICE(dev)                                       \
00168 const char __module_device[] __attribute__((section(".modinfo"))) =        \
00169 "device=" dev
00170 
00171 /* Used to verify parameters given to the module.  The TYPE arg should
00172    be a string in the following format:
00173         [min[-max]]{b,h,i,l,s}
00174    The MIN and MAX specifiers delimit the length of the array.  If MAX
00175    is omitted, it defaults to MIN; if both are omitted, the default is 1.
00176    The final character is a type specifier:
00177         b       byte
00178         h       short
00179         i       int
00180         l       long
00181         s       string
00182 */
00183 
00184 /* Dummy macro for 2.2/2.4 compatibility */
00185 #define MODULE_LICENSE(var)
00186 
00187 #define MODULE_PARM(var,type)                   \
00188 const char __module_parm_##var[]                \
00189 __attribute__((section(".modinfo"))) =          \
00190 "parm_" __MODULE_STRING(var) "=" type
00191 
00192 #define MODULE_PARM_DESC(var,desc)              \
00193 const char __module_parm_desc_##var[]           \
00194 __attribute__((section(".modinfo"))) =          \
00195 "parm_desc_" __MODULE_STRING(var) "=" desc
00196 
00197 /* The attributes of a section are set the first time the section is
00198    seen; we want .modinfo to not be allocated.  */
00199 
00200 __asm__(".section .modinfo\n\t.previous");
00201 
00202 /* Define the module variable, and usage macros.  */
00203 extern struct module __this_module;
00204 
00205 #define THIS_MODULE             (&__this_module)
00206 #define MOD_INC_USE_COUNT       __MOD_INC_USE_COUNT(&__this_module)
00207 #define MOD_DEC_USE_COUNT       __MOD_DEC_USE_COUNT(&__this_module)
00208 #define MOD_IN_USE              __MOD_IN_USE(&__this_module)
00209 
00210 #ifndef __NO_VERSION__
00211 #include <linux/version.h>
00212 const char __module_kernel_version[] __attribute__((section(".modinfo"))) =
00213 "kernel_version=" UTS_RELEASE;
00214 #ifdef MODVERSIONS
00215 const char __module_using_checksums[] __attribute__((section(".modinfo"))) =
00216 "using_checksums=1";
00217 #endif
00218 #endif
00219 
00220 #else /* MODULE */
00221 
00222 #define MODULE_AUTHOR(name)
00223 #define MODULE_DESCRIPTION(desc)
00224 #define MODULE_SUPPORTED_DEVICE(name)
00225 #define MODULE_LICENSE(var)
00226 #define MODULE_PARM(var,type)
00227 #define MODULE_PARM_DESC(var,desc)
00228 #define THIS_MODULE             NULL
00229 
00230 #ifndef __GENKSYMS__
00231 
00232 #define MOD_INC_USE_COUNT       do { } while (0)
00233 #define MOD_DEC_USE_COUNT       do { } while (0)
00234 #define MOD_IN_USE              1
00235 
00236 extern struct module *module_list;
00237 
00238 #endif /* !__GENKSYMS__ */
00239 
00240 #endif /* MODULE */
00241 
00242 /* Export a symbol either from the kernel or a module.
00243 
00244    In the kernel, the symbol is added to the kernel's global symbol table.
00245 
00246    In a module, it controls which variables are exported.  If no
00247    variables are explicitly exported, the action is controled by the
00248    insmod -[xX] flags.  Otherwise, only the variables listed are exported.
00249    This obviates the need for the old register_symtab() function.  */
00250 
00251 #if defined(__GENKSYMS__)
00252 
00253 /* We want the EXPORT_SYMBOL tag left intact for recognition.  */
00254 
00255 #elif !defined(AUTOCONF_INCLUDED)
00256 
00257 #define __EXPORT_SYMBOL(sym,str)   error config_must_be_included_before_module
00258 #define EXPORT_SYMBOL(var)         error config_must_be_included_before_module
00259 #define EXPORT_SYMBOL_NOVERS(var)  error config_must_be_included_before_module
00260 
00261 #elif !defined(CONFIG_MODULES)
00262 
00263 #define __EXPORT_SYMBOL(sym,str)
00264 #define EXPORT_SYMBOL(var)
00265 #define EXPORT_SYMBOL_NOVERS(var)
00266 
00267 #elif !defined(EXPORT_SYMTAB)
00268 
00269 /* If things weren't set up in the Makefiles to get EXPORT_SYMTAB defined,
00270    then they weren't set up to run genksyms properly so MODVERSIONS breaks.  */
00271 #define __EXPORT_SYMBOL(sym,str)   error EXPORT_SYMTAB_not_defined
00272 #define EXPORT_SYMBOL(var)         error EXPORT_SYMTAB_not_defined
00273 #define EXPORT_SYMBOL_NOVERS(var)  error EXPORT_SYMTAB_not_defined
00274 
00275 #else
00276 
00277 #define __EXPORT_SYMBOL(sym, str)                       \
00278 const char __kstrtab_##sym[]                            \
00279 __attribute__((section(".kstrtab"))) = str;             \
00280 const struct module_symbol __ksymtab_##sym              \
00281 __attribute__((section("__ksymtab"))) =                 \
00282 { (unsigned long)&sym, __kstrtab_##sym }
00283 
00284 #if defined(MODVERSIONS) || !defined(CONFIG_MODVERSIONS)
00285 #define EXPORT_SYMBOL(var)  __EXPORT_SYMBOL(var, __MODULE_STRING(var))
00286 #else
00287 #define EXPORT_SYMBOL(var)  __EXPORT_SYMBOL(var, __MODULE_STRING(__VERSIONED_SYMBOL(var)))
00288 #endif
00289 
00290 #define EXPORT_SYMBOL_NOVERS(var)  __EXPORT_SYMBOL(var, __MODULE_STRING(var))
00291 
00292 #endif /* __GENKSYMS__ */
00293 
00294 #ifdef MODULE
00295 /* Force a module to export no symbols.  */
00296 #define EXPORT_NO_SYMBOLS  __asm__(".section __ksymtab\n.previous")
00297 #else
00298 #define EXPORT_NO_SYMBOLS
00299 #endif /* MODULE */
00300 
00301 #endif /* _LINUX_MODULE_H */