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