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

linux/init.h

Go to the documentation of this file.
00001 #ifndef _LINUX_INIT_H
00002 #define _LINUX_INIT_H
00003 
00004 /* These macros are used to mark some functions or 
00005  * initialized data (doesn't apply to uninitialized data)
00006  * as `initialization' functions. The kernel can take this
00007  * as hint that the function is used only during the initialization
00008  * phase and free up used memory resources after
00009  *
00010  * Usage:
00011  * For functions:
00012  * 
00013  * You should add __init immediately before the function name, like:
00014  *
00015  * static void __init initme(int x, int y)
00016  * {
00017  *    extern int z; z = x * y;
00018  * }
00019  *
00020  * Deprecated: you can surround the whole function declaration 
00021  * just before function body into __initfunc() macro, like:
00022  *
00023  * __initfunc (static void initme(int x, int y))
00024  * {
00025  *    extern int z; z = x * y;
00026  * }
00027  *
00028  * If the function has a prototype somewhere, you can also add
00029  * __init between closing brace of the prototype and semicolon:
00030  *
00031  * extern int initialize_foobar_device(int, int, int) __init;
00032  *
00033  * For initialized data:
00034  * You should insert __initdata between the variable name and equal
00035  * sign followed by value, e.g.:
00036  *
00037  * static int init_variable __initdata = 0;
00038  * static char linux_logo[] __initdata = { 0x32, 0x36, ... };
00039  *
00040  * For initialized data not at file scope, i.e. within a function,
00041  * you should use __initlocaldata instead, due to a bug in GCC 2.7.
00042  */
00043 
00044 /*
00045  * Disable the __initfunc macros if a file that is a part of a
00046  * module attempts to use them. We do not want to interfere
00047  * with module linking.
00048  */
00049 
00050 #ifndef MODULE
00051 #include <asm/init.h>
00052 #else
00053 #define __init
00054 #define __initdata
00055 #define __initfunc(__arginit) __arginit
00056 /* For assembly routines */
00057 #define __INIT
00058 #define __FINIT
00059 #define __INITDATA
00060 #endif
00061 
00062 #if (__GNUC__ > 2) || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8)
00063 #define __initlocaldata  __initdata
00064 #else
00065 #define __initlocaldata
00066 #endif
00067 
00068 
00069 #ifndef __ASSEMBLY__
00070 
00071 /*
00072  * Used for kernel command line parameter setup
00073  */
00074 struct new_kernel_param {
00075         const char *str;
00076         int (*setup_func)(char *);
00077 };
00078 
00079 extern struct new_kernel_param __setup_start, __setup_end;
00080 
00081 #define __setup(str, fn)                                                                \
00082         static char __setup_str_##fn[] __initdata = str;                                \
00083         static struct new_kernel_param __setup_##fn __initsetup = { __setup_str_##fn, fn }
00084 
00085 #define __initsetup     __attribute__ ((unused,__section__ (".setup.init")))
00086 
00087 
00088 /*
00089  * Used for initialization calls..
00090  */
00091 typedef int (*initcall_t)(void);
00092 typedef void (*exitcall_t)(void);
00093 
00094 #define __init_call     __attribute__ ((unused,__section__ (".initcall.init")))
00095 #define __exit_call     __attribute__ ((unused,__section__ (".exitcall.exit")))
00096 
00097 extern initcall_t __initcall_start, __initcall_end;
00098 
00099 #define __initcall(fn)                                                          \
00100         static initcall_t __initcall_##fn __init_call = fn
00101 #define __exitcall(fn)                                                          \
00102         static exitcall_t __exitcall_##fn __exit_call = fn
00103 
00104 #ifdef MODULE
00105 /* Not sure what version aliases were introduced in, but certainly in 2.91.66.  */
00106 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 91)
00107 /* These macros create a dummy inline: gcc 2.9x does not count alias
00108  as usage, hence the `unused function' warning when __init functions
00109  are declared static. We use the dummy __*_module_inline functions
00110  both to kill the warning and check the type of the init/cleanup
00111  function. */
00112 typedef int (*__init_module_func_t)(void);
00113 typedef void (*__cleanup_module_func_t)(void);
00114 #define module_init(x) \
00115         int init_module(void) __attribute__((alias(#x))); \
00116         extern inline __init_module_func_t __init_module_inline(void) \
00117         { return x; }
00118 #define module_exit(x) \
00119         void cleanup_module(void) __attribute__((alias(#x))); \
00120         extern inline __cleanup_module_func_t __cleanup_module_inline(void) \
00121         { return x; }
00122 #else
00123 #define module_init(x)  int init_module(void) { return x(); }
00124 #define module_exit(x)  void cleanup_module(void) { x(); }
00125 #endif
00126 
00127 #else 
00128 #define module_init(x)  __initcall(x);
00129 #define module_exit(x)  __exitcall(x);
00130 #endif
00131 
00132 #endif /* __ASSEMBLY __ */
00133 #endif