blob: b00a95741d4115339db192cddf54a7ba1b977ab7 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef _LINUX_UML_INIT_H
2#define _LINUX_UML_INIT_H
3
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 char linux_logo[] __initdata = { 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
39#ifndef _LINUX_INIT_H
40typedef int (*initcall_t)(void);
41typedef void (*exitcall_t)(void);
42
Jeff Dike99c9f502008-02-04 22:30:34 -080043#ifndef __KERNEL__
44#ifndef __section
45# define __section(S) __attribute__ ((__section__(#S)))
46#endif
47
48#if __GNUC_MINOR__ >= 3
49# define __used __attribute__((__used__))
50#else
51# define __used __attribute__((__unused__))
52#endif
53
54#else
55#include <linux/compiler.h>
56#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070057/* These are for everybody (although not all archs will actually
58 discard it in modules) */
Adrian Bunk3ff6eec2008-01-24 22:16:20 +010059#define __init __section(.init.text)
60#define __initdata __section(.init.data)
61#define __exitdata __section(.exit.data)
62#define __exit_call __used __section(.exitcall.exit)
Linus Torvalds1da177e2005-04-16 15:20:36 -070063
64#ifdef MODULE
Adrian Bunk3ff6eec2008-01-24 22:16:20 +010065#define __exit __section(.exit.text)
Linus Torvalds1da177e2005-04-16 15:20:36 -070066#else
Adrian Bunk3ff6eec2008-01-24 22:16:20 +010067#define __exit __used __section(.exit.text)
Linus Torvalds1da177e2005-04-16 15:20:36 -070068#endif
69
70#endif
71
72#ifndef MODULE
73struct uml_param {
74 const char *str;
75 int (*setup_func)(char *, int *);
76};
77
78extern initcall_t __uml_initcall_start, __uml_initcall_end;
79extern initcall_t __uml_postsetup_start, __uml_postsetup_end;
80extern const char *__uml_help_start, *__uml_help_end;
81#endif
82
83#define __uml_initcall(fn) \
84 static initcall_t __uml_initcall_##fn __uml_init_call = fn
85
86#define __uml_exitcall(fn) \
87 static exitcall_t __uml_exitcall_##fn __uml_exit_call = fn
88
89extern struct uml_param __uml_setup_start, __uml_setup_end;
90
91#define __uml_postsetup(fn) \
92 static initcall_t __uml_postsetup_##fn __uml_postsetup_call = fn
93
94#define __non_empty_string(dummyname,string) \
95 struct __uml_non_empty_string_struct_##dummyname \
96 { \
97 char _string[sizeof(string)-2]; \
98 }
99
100#ifndef MODULE
101#define __uml_setup(str, fn, help...) \
102 __non_empty_string(fn ##_setup, str); \
103 __uml_help(fn, help); \
104 static char __uml_setup_str_##fn[] __initdata = str; \
105 static struct uml_param __uml_setup_##fn __uml_init_setup = { __uml_setup_str_##fn, fn }
106#else
107#define __uml_setup(str, fn, help...) \
108
109#endif
110
111#define __uml_help(fn, help...) \
112 __non_empty_string(fn ##__help, help); \
113 static char __uml_help_str_##fn[] __initdata = help; \
114 static const char *__uml_help_##fn __uml_setup_help = __uml_help_str_##fn
115
116/*
117 * Mark functions and data as being only used at initialization
118 * or exit time.
119 */
Adrian Bunk3ff6eec2008-01-24 22:16:20 +0100120#define __uml_init_setup __used __section(.uml.setup.init)
121#define __uml_setup_help __used __section(.uml.help.init)
122#define __uml_init_call __used __section(.uml.initcall.init)
123#define __uml_postsetup_call __used __section(.uml.postsetup.init)
124#define __uml_exit_call __used __section(.uml.exitcall.exit)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125
126#ifndef __KERNEL__
127
Jeff Dike75e55842005-09-03 15:57:45 -0700128#define __define_initcall(level,fn) \
Adrian Bunk3ff6eec2008-01-24 22:16:20 +0100129 static initcall_t __initcall_##fn __used \
Jeff Dike75e55842005-09-03 15:57:45 -0700130 __attribute__((__section__(".initcall" level ".init"))) = fn
131
132/* Userspace initcalls shouldn't depend on anything in the kernel, so we'll
133 * make them run first.
134 */
135#define __initcall(fn) __define_initcall("1", fn)
136
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137#define __exitcall(fn) static exitcall_t __exitcall_##fn __exit_call = fn
138
Adrian Bunk3ff6eec2008-01-24 22:16:20 +0100139#define __init_call __used __section(.initcall.init)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140
141#endif
142
143#endif /* _LINUX_UML_INIT_H */