6 XNU Startup sequence is driven by the `<kern/startup.h>` module.
8 The startup sequence is made of individual subsystems (the `STARTUP_SUB_*`
9 values of the `startup_subsystem_id_t` type) that get initialized in sequence.
11 A subsystem can use ranks to order the various initializers that make up its
12 initialization sequence. Usage of ranks is custom to each subsystem and must be
13 documented in this file.
15 The subsystem module will basically run hooks in that order:
18 for (subsystem 0 -> N) {
20 // run in no particular order for a given rank in the given subsystem
21 init(subsystem, rank);
26 ### Extending the startup sequence
28 When extending the startup sequence:
30 1. add a new value to the `startup_subsystem_id_t` enum in the right order
31 2. document what services this phase provides, and how it uses ranks in this
35 When hooking with a given subsystem, consult this documentation to use the
36 proper rank for your callback.
38 If a new rank needs to be used, update this documentation in the proper section.
40 ---------------------------------------------------------------------------------
43 `STARTUP_SUB_TUNABLES`
44 ----------------------
48 Initializes various globals that alter the behavior of the kernel, lookup
49 tables, ... Available hooks are:
51 - `TUNABLES`: parses a boot arg into a global that will become read-only at
53 - `TUNABLE_WRITEABLE`: same as `TUNABLE` but the global will not be locked down.
57 - Rank 1: `TUNABLE`, `TUNABLE_WRITEABLE`
58 - Middle: globals that require complex initialization (e.g. SFI classes).
61 `STARTUP_SUB_LOCKS_EARLY`
62 -------------------------
66 Initializes early locks that do not require any memory allocations to be
67 initialized. Available hooks are:
69 - `LCK_GRP_DECLARE*`: automatically initialized lock groups,
70 - `LCK_GRP_ATTR_DECLARE`: automatically initialized lock group attributes,
71 - `LCK_ATTR_DECLARE`: automatically initialized lock attributes,
72 - `LCK_SPIN_DECLARE*`: automatically initialized spinlocks,
73 - `LCK_RW_DECLARE`: automatically initialized reader/writer lock,
74 - `LCK_MTX_EARLY_DECLARE*`: automatically initialized mutexes, with statically
75 allocated buffers for statistics/tracing,
76 - `SIMPLE_LOCK_DECLARE*`: automatically initialized simple locks.
80 - Rank 1: Initializes the module (`lck_mod_init`),
81 - Rank 2: `LCK_GRP_ATTR_DECLARE`, `LCK_ATTR_DECLARE`,
82 - Rank 3: `LCK_GRP_DECLARE*`
83 - Rank 4: `LCK_SPIN_DECLARE*`, `LCK_MTX_EARLY_DECLARE*`,
84 `LCK_RW_DECLARE`, `SIMPLE_LOCK_DECLARE*`.
92 Initializes the kprintf subsystem.
96 - Rank 1: calls the module initializer (`PE_init_kprintf`).
99 `STARTUP_SUB_PMAP_STEAL`
100 ------------------------
104 Allows for subsystems to steal early memory.
111 `STARTUP_SUB_VM_KERNEL`
112 -----------------------
116 Denotes that the early kernel VM is initialized.
128 Denotes that `kernel_memory_allocate` is now usable.
135 `STARTUP_SUB_KMEM_ALLOC`
136 ------------------------
140 Denotes that `kmem_alloc` is now usable.
152 Initializes the zone allocator.
154 - `ZONE_DECLARE`, `ZONE_INIT`: automatically initialized permanent zones.
155 - `ZONE_VIEW_DEFINE`, `KALLOC_HEAP_DEFINE`: zone and kalloc heap views.
160 - Rank 1: `zone_init`: setup the zone subsystem, this allows for the already
161 created VM/pmap zones to become dynamic.
163 - Rank 2: `vm_page_module_init`: create the "vm pages" zone.
164 The `vm_page_zone` must be created prior to `kalloc_init`; that routine can
165 trigger `zalloc()`s (for e.g. mutex statistic structure initialization).
167 The `vm_page_zone` must exist to satisfy fictitious page allocations
168 (which are used for guard pages by the guard mode zone allocator).
170 - Rank 3: Initialize kalloc.
172 - Rank 4: Enable zone caching (uses kalloc)
174 - Middle: for any initialization that only requires kalloc/zalloc
175 runs `ZONE_DECLARE` and `ZONE_INIT`.
177 - Last: zone and kalloc heaps (`ZONE_VIEW_DEFINE`, `KALLOC_HEAP_DEFINE`).
185 Initializes the percpu subsystem.
189 Rank 1: allocates the percpu memory, `percpu_foreach_base` and `percpu_foreach`
198 Initializes kernel locks that might require allocations (due to statistics and
199 tracing features). Available hooks are:
201 - `LCK_MTX_DECLARE`: automatically initialized mutex,
206 - Rank 1: `LCK_MTX_DECLARE`.
209 `STARTUP_SUB_CODESIGNING`
210 -------------------------
214 Initializes the codesigning subsystem.
218 - Rank 1: calls the module initializer (`cs_init`).
226 Initializes the `os_log` facilities.
230 - Rank 1: Calls the module initializer (`oslog_init`).
233 `STARTUP_SUB_MACH_IPC`
238 Initializes the Mach IPC subsystem.
242 - Rank 1: Initializes IPC submodule globals (ipc tables, voucher hashes, ...)
243 - Rank last: Final IPC initialization.
246 `STARTUP_SUB_EARLY_BOOT`
247 ------------------------
251 Denotes that subsystems that expect to operate with
252 interrupts or preemption enabled may begin enforcement.
259 `STARTUP_SUB_LOCKDOWN`
260 ----------------------
264 Denotes that the kernel is locking down, this phase should never be hooked.
265 When the kernel locks down:
267 - data marked `__startup_data` and code marked `__startup_func` is unmapped,
268 - data marked `__security_const_late` or `SECURITY_READ_ONLY_LATE` becomes