Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef _LINUX_UML_INIT_H
0003 #define _LINUX_UML_INIT_H
0004 
0005 /* These macros are used to mark some functions or
0006  * initialized data (doesn't apply to uninitialized data)
0007  * as `initialization' functions. The kernel can take this
0008  * as hint that the function is used only during the initialization
0009  * phase and free up used memory resources after
0010  *
0011  * Usage:
0012  * For functions:
0013  *
0014  * You should add __init immediately before the function name, like:
0015  *
0016  * static void __init initme(int x, int y)
0017  * {
0018  *    extern int z; z = x * y;
0019  * }
0020  *
0021  * If the function has a prototype somewhere, you can also add
0022  * __init between closing brace of the prototype and semicolon:
0023  *
0024  * extern int initialize_foobar_device(int, int, int) __init;
0025  *
0026  * For initialized data:
0027  * You should insert __initdata between the variable name and equal
0028  * sign followed by value, e.g.:
0029  *
0030  * static int init_variable __initdata = 0;
0031  * static const char linux_logo[] __initconst = { 0x32, 0x36, ... };
0032  *
0033  * Don't forget to initialize data not at file scope, i.e. within a function,
0034  * as gcc otherwise puts the data into the bss section and not into the init
0035  * section.
0036  *
0037  * Also note, that this data cannot be "const".
0038  */
0039 
0040 #ifndef _LINUX_INIT_H
0041 typedef int (*initcall_t)(void);
0042 typedef void (*exitcall_t)(void);
0043 
0044 #include <linux/compiler_types.h>
0045 
0046 /* These are for everybody (although not all archs will actually
0047    discard it in modules) */
0048 #define __init      __section(".init.text")
0049 #define __initdata  __section(".init.data")
0050 #define __exitdata  __section(".exit.data")
0051 #define __exit_call __used __section(".exitcall.exit")
0052 
0053 #ifdef MODULE
0054 #define __exit      __section(".exit.text")
0055 #else
0056 #define __exit      __used __section(".exit.text")
0057 #endif
0058 
0059 #endif
0060 
0061 #ifndef MODULE
0062 struct uml_param {
0063         const char *str;
0064         int (*setup_func)(char *, int *);
0065 };
0066 
0067 extern initcall_t __uml_postsetup_start, __uml_postsetup_end;
0068 extern const char *__uml_help_start, *__uml_help_end;
0069 #endif
0070 
0071 #define __uml_exitcall(fn)                      \
0072     static exitcall_t __uml_exitcall_##fn __uml_exit_call = fn
0073 
0074 extern struct uml_param __uml_setup_start, __uml_setup_end;
0075 
0076 #define __uml_postsetup(fn)                     \
0077     static initcall_t __uml_postsetup_##fn __uml_postsetup_call = fn
0078 
0079 #define __non_empty_string(dummyname,string)                \
0080     struct __uml_non_empty_string_struct_##dummyname        \
0081     {                               \
0082         char _string[sizeof(string)-2];             \
0083     }
0084 
0085 #ifndef MODULE
0086 #define __uml_setup(str, fn, help...)                   \
0087     __non_empty_string(fn ##_setup, str);               \
0088     __uml_help(fn, help);                       \
0089     static char __uml_setup_str_##fn[] __initdata = str;        \
0090     static struct uml_param __uml_setup_##fn __uml_init_setup = { __uml_setup_str_##fn, fn }
0091 #else
0092 #define __uml_setup(str, fn, help...)                   \
0093 
0094 #endif
0095 
0096 #define __uml_help(fn, help...)                     \
0097     __non_empty_string(fn ##__help, help);              \
0098     static char __uml_help_str_##fn[] __initdata = help;        \
0099     static const char *__uml_help_##fn __uml_setup_help = __uml_help_str_##fn
0100 
0101 /*
0102  * Mark functions and data as being only used at initialization
0103  * or exit time.
0104  */
0105 #define __uml_init_setup    __used __section(".uml.setup.init")
0106 #define __uml_setup_help    __used __section(".uml.help.init")
0107 #define __uml_postsetup_call    __used __section(".uml.postsetup.init")
0108 #define __uml_exit_call     __used __section(".uml.exitcall.exit")
0109 
0110 #ifdef __UM_HOST__
0111 
0112 #define __define_initcall(level,fn) \
0113     static initcall_t __initcall_##fn __used \
0114     __attribute__((__section__(".initcall" level ".init"))) = fn
0115 
0116 /* Userspace initcalls shouldn't depend on anything in the kernel, so we'll
0117  * make them run first.
0118  */
0119 #define __initcall(fn) __define_initcall("1", fn)
0120 
0121 #define __exitcall(fn) static exitcall_t __exitcall_##fn __exit_call = fn
0122 
0123 #define __init_call __used __section(".initcall.init")
0124 
0125 #endif
0126 
0127 #endif /* _LINUX_UML_INIT_H */