init.h 3.9 KB

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