home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / lxapi32.zip / Include / Linux / init.h < prev    next >
C/C++ Source or Header  |  2002-04-26  |  3KB  |  125 lines

  1. /* $Id: init.h,v 1.2 2002/04/26 23:09:06 smilcke Exp $ */
  2.  
  3. #ifndef _LINUX_INIT_H
  4. #define _LINUX_INIT_H
  5.  
  6. /* These macros are used to mark some functions or 
  7.  * initialized data (doesn't apply to uninitialized data)
  8.  * as `initialization' functions. The kernel can take this
  9.  * as hint that the function is used only during the initialization
  10.  * phase and free up used memory resources after
  11.  *
  12.  * Usage:
  13.  * For functions:
  14.  * 
  15.  * You should add __init immediately before the function name, like:
  16.  *
  17.  * static void __init initme(int x, int y)
  18.  * {
  19.  *    extern int z; z = x * y;
  20.  * }
  21.  *
  22.  * If the function has a prototype somewhere, you can also add
  23.  * __init between closing brace of the prototype and semicolon:
  24.  *
  25.  * extern int initialize_foobar_device(int, int, int) __init;
  26.  *
  27.  * For initialized data:
  28.  * You should insert __initdata between the variable name and equal
  29.  * sign followed by value, e.g.:
  30.  *
  31.  * static int init_variable __initdata = 0;
  32.  * static char linux_logo[] __initdata = { 0x32, 0x36, ... };
  33.  *
  34.  * For initialized data not at file scope, i.e. within a function,
  35.  * you should use __initlocaldata instead, due to a bug in GCC 2.7.
  36.  */
  37.  
  38. #ifndef MODULE
  39.  
  40. #ifndef __ASSEMBLY__
  41.  
  42. /*
  43.  * Used for initialization calls..
  44.  */
  45. typedef int (*initcall_t)(void);
  46.  
  47. extern initcall_t __initcall_start, __initcall_end;
  48.  
  49. #define __initcall(fn)                                \
  50.     static initcall_t __initcall_##fn __init_call = fn
  51.  
  52. /*
  53.  * Used for kernel command line parameter setup
  54.  */
  55. struct kernel_param {
  56.     const char *str;
  57.     int (*setup_func)(char *);
  58. };
  59.  
  60. extern struct kernel_param __setup_start, __setup_end;
  61.  
  62. #define __setup(str, fn)                                \
  63.     static char __setup_str_##fn[] __initdata = str;                \
  64.     static struct kernel_param __setup_##fn __initsetup = { __setup_str_##fn, fn }
  65.  
  66. #endif /* __ASSEMBLY__ */
  67.  
  68. /*
  69.  * Mark functions and data as being only used at initialization
  70.  * or exit time.
  71.  */
  72. #define __init
  73. #define __exit
  74. #define __initdata
  75. #define __exitdata
  76. #define __initsetup
  77. #define __init_call
  78. #define __devinitdata
  79. #define __devinit
  80. #define __devexit
  81.  
  82. /* For assembly routines */
  83. #define __INIT
  84. #define __FINIT
  85. #define __INITDATA
  86.  
  87. #define module_init(x)    __initcall(x);
  88. #define module_exit(x)    /* nothing */
  89.  
  90. #else
  91.  
  92. #define __init
  93. #define __exit
  94. #define __initdata
  95. #define __exitdata
  96. #define __initcall
  97. /* For assembly routines */
  98. #define __INIT
  99. #define __FINIT
  100. #define __INITDATA
  101. #define __devinitdata
  102. #define __devinit
  103. #define __devexit
  104.  
  105. /* Not sure what version aliases were introduced in, but certainly in 2.95.  */
  106. #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95)
  107. #define module_init(x)    int init_module(void) __attribute__((alias(#x)));
  108. #define module_exit(x)    void cleanup_module(void) __attribute__((alias(#x)));
  109. #else
  110. #define module_init(x)    int init_module(void) { return x(); }
  111. #define module_exit(x)    void cleanup_module(void) { x(); }
  112. #endif
  113.  
  114. #define __setup(str,func) /* nothing */
  115.  
  116. #endif
  117.  
  118. #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8)
  119. #define __initlocaldata  __initdata
  120. #else
  121. #define __initlocaldata
  122. #endif
  123.  
  124. #endif /* _LINUX_INIT_H */
  125.