0001
0002 #ifndef _LINUX_INIT_H
0003 #define _LINUX_INIT_H
0004
0005 #include <linux/compiler.h>
0006 #include <linux/types.h>
0007
0008
0009 #if defined(__noretpoline) && !defined(MODULE)
0010 #define __noinitretpoline __noretpoline
0011 #else
0012 #define __noinitretpoline
0013 #endif
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050 #define __init __section(".init.text") __cold __latent_entropy __noinitretpoline __nocfi
0051 #define __initdata __section(".init.data")
0052 #define __initconst __section(".init.rodata")
0053 #define __exitdata __section(".exit.data")
0054 #define __exit_call __used __section(".exitcall.exit")
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073 #define __ref __section(".ref.text") noinline
0074 #define __refdata __section(".ref.data")
0075 #define __refconst __section(".ref.rodata")
0076
0077 #ifdef MODULE
0078 #define __exitused
0079 #else
0080 #define __exitused __used
0081 #endif
0082
0083 #define __exit __section(".exit.text") __exitused __cold notrace
0084
0085
0086 #define __meminit __section(".meminit.text") __cold notrace \
0087 __latent_entropy
0088 #define __meminitdata __section(".meminit.data")
0089 #define __meminitconst __section(".meminit.rodata")
0090 #define __memexit __section(".memexit.text") __exitused __cold notrace
0091 #define __memexitdata __section(".memexit.data")
0092 #define __memexitconst __section(".memexit.rodata")
0093
0094
0095 #define __HEAD .section ".head.text","ax"
0096 #define __INIT .section ".init.text","ax"
0097 #define __FINIT .previous
0098
0099 #define __INITDATA .section ".init.data","aw",%progbits
0100 #define __INITRODATA .section ".init.rodata","a",%progbits
0101 #define __FINITDATA .previous
0102
0103 #define __MEMINIT .section ".meminit.text", "ax"
0104 #define __MEMINITDATA .section ".meminit.data", "aw"
0105 #define __MEMINITRODATA .section ".meminit.rodata", "a"
0106
0107
0108 #define __REF .section ".ref.text", "ax"
0109 #define __REFDATA .section ".ref.data", "aw"
0110 #define __REFCONST .section ".ref.rodata", "a"
0111
0112 #ifndef __ASSEMBLY__
0113
0114
0115
0116 typedef int (*initcall_t)(void);
0117 typedef void (*exitcall_t)(void);
0118
0119 #ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS
0120 typedef int initcall_entry_t;
0121
0122 static inline initcall_t initcall_from_entry(initcall_entry_t *entry)
0123 {
0124 return offset_to_ptr(entry);
0125 }
0126 #else
0127 typedef initcall_t initcall_entry_t;
0128
0129 static inline initcall_t initcall_from_entry(initcall_entry_t *entry)
0130 {
0131 return *entry;
0132 }
0133 #endif
0134
0135 extern initcall_entry_t __con_initcall_start[], __con_initcall_end[];
0136
0137
0138 typedef void (*ctor_fn_t)(void);
0139
0140 struct file_system_type;
0141
0142
0143 extern int do_one_initcall(initcall_t fn);
0144 extern char __initdata boot_command_line[];
0145 extern char *saved_command_line;
0146 extern unsigned int reset_devices;
0147
0148
0149 void setup_arch(char **);
0150 void prepare_namespace(void);
0151 void __init init_rootfs(void);
0152 extern struct file_system_type rootfs_fs_type;
0153
0154 #if defined(CONFIG_STRICT_KERNEL_RWX) || defined(CONFIG_STRICT_MODULE_RWX)
0155 extern bool rodata_enabled;
0156 #endif
0157 #ifdef CONFIG_STRICT_KERNEL_RWX
0158 void mark_rodata_ro(void);
0159 #endif
0160
0161 extern void (*late_time_init)(void);
0162
0163 extern bool initcall_debug;
0164
0165 #endif
0166
0167 #ifndef MODULE
0168
0169 #ifndef __ASSEMBLY__
0170
0171
0172
0173
0174
0175
0176
0177
0178
0179
0180
0181
0182
0183
0184
0185
0186
0187
0188 #define __initcall_id(fn) \
0189 __PASTE(__KBUILD_MODNAME, \
0190 __PASTE(__, \
0191 __PASTE(__COUNTER__, \
0192 __PASTE(_, \
0193 __PASTE(__LINE__, \
0194 __PASTE(_, fn))))))
0195
0196
0197 #define __initcall_name(prefix, __iid, id) \
0198 __PASTE(__, \
0199 __PASTE(prefix, \
0200 __PASTE(__, \
0201 __PASTE(__iid, id))))
0202
0203 #ifdef CONFIG_LTO_CLANG
0204
0205
0206
0207
0208
0209
0210 #define __initcall_section(__sec, __iid) \
0211 #__sec ".init.." #__iid
0212
0213
0214
0215
0216
0217
0218
0219 #define __initcall_stub(fn, __iid, id) \
0220 __initcall_name(initstub, __iid, id)
0221
0222 #define __define_initcall_stub(__stub, fn) \
0223 int __init __cficanonical __stub(void); \
0224 int __init __cficanonical __stub(void) \
0225 { \
0226 return fn(); \
0227 } \
0228 __ADDRESSABLE(__stub)
0229 #else
0230 #define __initcall_section(__sec, __iid) \
0231 #__sec ".init"
0232
0233 #define __initcall_stub(fn, __iid, id) fn
0234
0235 #define __define_initcall_stub(__stub, fn) \
0236 __ADDRESSABLE(fn)
0237 #endif
0238
0239 #ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS
0240 #define ____define_initcall(fn, __stub, __name, __sec) \
0241 __define_initcall_stub(__stub, fn) \
0242 asm(".section \"" __sec "\", \"a\" \n" \
0243 __stringify(__name) ": \n" \
0244 ".long " __stringify(__stub) " - . \n" \
0245 ".previous \n"); \
0246 static_assert(__same_type(initcall_t, &fn));
0247 #else
0248 #define ____define_initcall(fn, __unused, __name, __sec) \
0249 static initcall_t __name __used \
0250 __attribute__((__section__(__sec))) = fn;
0251 #endif
0252
0253 #define __unique_initcall(fn, id, __sec, __iid) \
0254 ____define_initcall(fn, \
0255 __initcall_stub(fn, __iid, id), \
0256 __initcall_name(initcall, __iid, id), \
0257 __initcall_section(__sec, __iid))
0258
0259 #define ___define_initcall(fn, id, __sec) \
0260 __unique_initcall(fn, id, __sec, __initcall_id(fn))
0261
0262 #define __define_initcall(fn, id) ___define_initcall(fn, id, .initcall##id)
0263
0264
0265
0266
0267
0268
0269 #define early_initcall(fn) __define_initcall(fn, early)
0270
0271
0272
0273
0274
0275
0276
0277
0278 #define pure_initcall(fn) __define_initcall(fn, 0)
0279
0280 #define core_initcall(fn) __define_initcall(fn, 1)
0281 #define core_initcall_sync(fn) __define_initcall(fn, 1s)
0282 #define postcore_initcall(fn) __define_initcall(fn, 2)
0283 #define postcore_initcall_sync(fn) __define_initcall(fn, 2s)
0284 #define arch_initcall(fn) __define_initcall(fn, 3)
0285 #define arch_initcall_sync(fn) __define_initcall(fn, 3s)
0286 #define subsys_initcall(fn) __define_initcall(fn, 4)
0287 #define subsys_initcall_sync(fn) __define_initcall(fn, 4s)
0288 #define fs_initcall(fn) __define_initcall(fn, 5)
0289 #define fs_initcall_sync(fn) __define_initcall(fn, 5s)
0290 #define rootfs_initcall(fn) __define_initcall(fn, rootfs)
0291 #define device_initcall(fn) __define_initcall(fn, 6)
0292 #define device_initcall_sync(fn) __define_initcall(fn, 6s)
0293 #define late_initcall(fn) __define_initcall(fn, 7)
0294 #define late_initcall_sync(fn) __define_initcall(fn, 7s)
0295
0296 #define __initcall(fn) device_initcall(fn)
0297
0298 #define __exitcall(fn) \
0299 static exitcall_t __exitcall_##fn __exit_call = fn
0300
0301 #define console_initcall(fn) ___define_initcall(fn, con, .con_initcall)
0302
0303 struct obs_kernel_param {
0304 const char *str;
0305 int (*setup_func)(char *);
0306 int early;
0307 };
0308
0309
0310
0311
0312
0313
0314
0315 #define __setup_param(str, unique_id, fn, early) \
0316 static const char __setup_str_##unique_id[] __initconst \
0317 __aligned(1) = str; \
0318 static struct obs_kernel_param __setup_##unique_id \
0319 __used __section(".init.setup") \
0320 __aligned(__alignof__(struct obs_kernel_param)) \
0321 = { __setup_str_##unique_id, fn, early }
0322
0323
0324
0325
0326
0327
0328 #define __setup(str, fn) \
0329 __setup_param(str, fn, fn, 0)
0330
0331
0332
0333
0334
0335
0336
0337 #define early_param(str, fn) \
0338 __setup_param(str, fn, fn, 1)
0339
0340 #define early_param_on_off(str_on, str_off, var, config) \
0341 \
0342 int var = IS_ENABLED(config); \
0343 \
0344 static int __init parse_##var##_on(char *arg) \
0345 { \
0346 var = 1; \
0347 return 0; \
0348 } \
0349 early_param(str_on, parse_##var##_on); \
0350 \
0351 static int __init parse_##var##_off(char *arg) \
0352 { \
0353 var = 0; \
0354 return 0; \
0355 } \
0356 early_param(str_off, parse_##var##_off)
0357
0358
0359 void __init parse_early_param(void);
0360 void __init parse_early_options(char *cmdline);
0361 #endif
0362
0363 #else
0364
0365 #define __setup_param(str, unique_id, fn)
0366 #define __setup(str, func)
0367 #endif
0368
0369
0370 #define __nosavedata __section(".data..nosave")
0371
0372 #ifdef MODULE
0373 #define __exit_p(x) x
0374 #else
0375 #define __exit_p(x) NULL
0376 #endif
0377
0378 #endif