init.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. #ifndef _LINUX_UML_INIT_H
  2. #define _LINUX_UML_INIT_H
  3. /* These macros are used to mark some functions or
  4. * initialized data (doesn't apply to uninitialized data)
  5. * as `initialization' functions. The kernel can take this
  6. * as hint that the function is used only during the initialization
  7. * phase and free up used memory resources after
  8. *
  9. * Usage:
  10. * For functions:
  11. *
  12. * You should add __init immediately before the function name, like:
  13. *
  14. * static void __init initme(int x, int y)
  15. * {
  16. * extern int z; z = x * y;
  17. * }
  18. *
  19. * If the function has a prototype somewhere, you can also add
  20. * __init between closing brace of the prototype and semicolon:
  21. *
  22. * extern int initialize_foobar_device(int, int, int) __init;
  23. *
  24. * For initialized data:
  25. * You should insert __initdata between the variable name and equal
  26. * sign followed by value, e.g.:
  27. *
  28. * static int init_variable __initdata = 0;
  29. * static char linux_logo[] __initdata = { 0x32, 0x36, ... };
  30. *
  31. * Don't forget to initialize data not at file scope, i.e. within a function,
  32. * as gcc otherwise puts the data into the bss section and not into the init
  33. * section.
  34. *
  35. * Also note, that this data cannot be "const".
  36. */
  37. #ifndef _LINUX_INIT_H
  38. typedef int (*initcall_t)(void);
  39. typedef void (*exitcall_t)(void);
  40. /* These are for everybody (although not all archs will actually
  41. discard it in modules) */
  42. #define __init __attribute__ ((__section__ (".init.text")))
  43. #define __initdata __attribute__ ((__section__ (".init.data")))
  44. #define __exitdata __attribute__ ((__section__(".exit.data")))
  45. #define __exit_call __attribute_used__ __attribute__ ((__section__ (".exitcall.exit")))
  46. #ifdef MODULE
  47. #define __exit __attribute__ ((__section__(".exit.text")))
  48. #else
  49. #define __exit __attribute_used__ __attribute__ ((__section__(".exit.text")))
  50. #endif
  51. #endif
  52. #ifndef MODULE
  53. struct uml_param {
  54. const char *str;
  55. int (*setup_func)(char *, int *);
  56. };
  57. extern initcall_t __uml_initcall_start, __uml_initcall_end;
  58. extern initcall_t __uml_postsetup_start, __uml_postsetup_end;
  59. extern const char *__uml_help_start, *__uml_help_end;
  60. #endif
  61. #define __uml_initcall(fn) \
  62. static initcall_t __uml_initcall_##fn __uml_init_call = fn
  63. #define __uml_exitcall(fn) \
  64. static exitcall_t __uml_exitcall_##fn __uml_exit_call = fn
  65. extern struct uml_param __uml_setup_start, __uml_setup_end;
  66. #define __uml_postsetup(fn) \
  67. static initcall_t __uml_postsetup_##fn __uml_postsetup_call = fn
  68. #define __non_empty_string(dummyname,string) \
  69. struct __uml_non_empty_string_struct_##dummyname \
  70. { \
  71. char _string[sizeof(string)-2]; \
  72. }
  73. #ifndef MODULE
  74. #define __uml_setup(str, fn, help...) \
  75. __non_empty_string(fn ##_setup, str); \
  76. __uml_help(fn, help); \
  77. static char __uml_setup_str_##fn[] __initdata = str; \
  78. static struct uml_param __uml_setup_##fn __uml_init_setup = { __uml_setup_str_##fn, fn }
  79. #else
  80. #define __uml_setup(str, fn, help...) \
  81. #endif
  82. #define __uml_help(fn, help...) \
  83. __non_empty_string(fn ##__help, help); \
  84. static char __uml_help_str_##fn[] __initdata = help; \
  85. static const char *__uml_help_##fn __uml_setup_help = __uml_help_str_##fn
  86. /*
  87. * Mark functions and data as being only used at initialization
  88. * or exit time.
  89. */
  90. #define __uml_init_setup __attribute_used__ __attribute__ ((__section__ (".uml.setup.init")))
  91. #define __uml_setup_help __attribute_used__ __attribute__ ((__section__ (".uml.help.init")))
  92. #define __uml_init_call __attribute_used__ __attribute__ ((__section__ (".uml.initcall.init")))
  93. #define __uml_postsetup_call __attribute_used__ __attribute__ ((__section__ (".uml.postsetup.init")))
  94. #define __uml_exit_call __attribute_used__ __attribute__ ((__section__ (".uml.exitcall.exit")))
  95. #ifndef __KERNEL__
  96. #define __define_initcall(level,fn) \
  97. static initcall_t __initcall_##fn __attribute_used__ \
  98. __attribute__((__section__(".initcall" level ".init"))) = fn
  99. /* Userspace initcalls shouldn't depend on anything in the kernel, so we'll
  100. * make them run first.
  101. */
  102. #define __initcall(fn) __define_initcall("1", fn)
  103. #define __exitcall(fn) static exitcall_t __exitcall_##fn __exit_call = fn
  104. #define __init_call __attribute__ ((unused,__section__ (".initcall.init")))
  105. #endif
  106. #endif /* _LINUX_UML_INIT_H */
  107. /*
  108. * Overrides for Emacs so that we follow Linus's tabbing style.
  109. * Emacs will notice this stuff at the end of the file and automatically
  110. * adjust the settings for this buffer only. This must remain at the end
  111. * of the file.
  112. * ---------------------------------------------------------------------------
  113. * Local variables:
  114. * c-file-style: "linux"
  115. * End:
  116. */