Skip to content

XNU as a loadable kernel module inside Linux (macOS personality for arm64 Linux)

C

README: M3 status (shell, launchd as PID 1, hosted stand-ins)

Heyang Zhou720aa086fa78
diff --git a/README.md b/README.md
index ec12c3b..ae6962e 100644
--- a/README.md
+++ b/README.md
@@ -22,7 +22,7 @@ The two sides are kept apart by license and only meet at the FKI (foreign kernel
- **M2b (done, 2026-11-20).** XNU runs at its own link address on physically contiguous memory with real PAs. `arm_vm_init` builds its kernel page tables, `xnu.ko` installs XNU's 48 kernel L1 entries into Linux's top-level L1 (the free `L1[384..495]` of `L0[511]`), and the hardware walks XNU's own tables. `pmap_bootstrap` runs, and XNU prints `kprintf initialized` to dmesg. Then (M2c, 2026-11-20) `machine_startup` → `kernel_bootstrap` runs to the end: zalloc/kalloc, scheduler, Mach IPC, tasks and threads; `load_context` switches to `kernel_bootstrap_thread`, which creates the idle thread, starts the scheduler, thread calls, clock service, kdp and sysctl, and reaches `PE_init_iokit`. Next: IOKit (`PE_init_iokit`), then timers/IPIs on FKI and real kthreads.
- **M2c (done, 2026-11-20).** The bare kernel runs `kernel_bootstrap_thread` through IOKit to `bsd_init` (VFS, mbufs, MAC, audit, aio), with a cooperative timer (XNU idles into the host, which delivers its timer), a virtual interrupt flag (hardware IRQs stay masked on XNU stacks), host-reported `assert`s and panics, and stand-ins for what the kexts would register.
- **M2e (done, 2026-11-20).** `xnu.ko` loads a fileset kernel collection: our kernel plus 53 of Apple's macOS 27.2 kexts (vma2 kernelcache, linked with macOS-DroidVM's `kc-build27.py`; Apple's binaries stay local). XNU applies the collection's chained fixups and signs it itself. Kernel page faults on XNU addresses are forwarded by FKI (`fki_fault_register`) to XNU's `vm_fault`; a fault nothing resolves ends the run cleanly instead of taking the host down. Apple's corecrypto (FIPS POST passes), AppleImage4, AMFI and Sandbox initialize; the ADT carries the `/chosen` a bootloader would pass (boot manifest hash, AP identity, NVRAM, SIP) and `/options`. `bsd_init` runs through networking and Skywalk to `IOFindBSDRoot`, waiting for a root device. Next: a root device (an FKI block endpoint or a RAM disk), NativeAES and AKS for AppleImage4 and AMFI, then `launchd` (M3).
-- **M3 (in progress, 2026-11-20).** User space runs under the hosted XNU. EL0 entry and exit go through a LINUX64 path (`linux64_el0_run`, `linux64_el0_vectors`, `linux64_el0_exception` into XNU's own `sleh_synchronous`) that keeps Linux's x18 (shadow call stack), the user's NEON/FP state and XNU's ASIDs (TCR.A1 off in XNU's world); upcalls keep the user TLS registers Linux's scheduler would clobber, and unresolved faults inside copyin/copyout take XNU's copyio recovery. The root can be a host file (`hostdisk=`: FKI `fki_file_open/rw`, XNU `memdev` in host mode). Done so far: static test binaries (`tools/init`) through `open`/`write` on `/dev/console`, `fork`, `execve`, `wait4`, signals; then Apple's own `/bin/echo` from macOS, dynamically linked: dyld maps the 7 GB dyld shared cache system wide from an HFS+ image on the Linux host and echo prints through libSystem (Apple's binaries stay local, never in this repo). Next: `/bin/sh`, then a real `launchd`.
+- **M3 (in progress, 2026-11-20).** User space runs under the hosted XNU. EL0 entry and exit go through a LINUX64 path (`linux64_el0_run`, `linux64_el0_vectors`, `linux64_el0_exception` into XNU's own `sleh_synchronous`) that keeps Linux's x18 (shadow call stack), the user's NEON/FP state and XNU's ASIDs (TCR.A1 off in XNU's world); upcalls keep the user TLS registers Linux's scheduler would clobber, and unresolved faults inside copyin/copyout take XNU's copyio recovery. The root can be a host file (`hostdisk=`: FKI `fki_file_open/rw`, XNU `memdev` in host mode). Done so far: static test binaries (`tools/init`) through `open`/`write` on `/dev/console`, `fork`, `execve`, `wait4`, signals; then Apple's own `/bin/echo` from macOS, dynamically linked: dyld maps the 7 GB dyld shared cache system wide from an HFS+ image on the Linux host and echo prints through libSystem (Apple's binaries stay local, never in this repo). Then Apple's `/bin/sh` (bash: builtins, fork/exec of `uname` and `ls`), and macOS's own `launchd` as PID 1: libignition, the boot tasks, LaunchDaemons import and xpcproxy spawns. What launchd needs from hardware that is not there is stood in for inside the hosted XNU: AppleKeyStore's `AKSKernelServices` table (the three entries AMFI calls, PAC-signed with their type discriminators), the SEP `scrd` endpoint, an `IOAESAccelerator` whose AES entry copies (AppleImage4's nonce store). FKI moves Linux-running upcalls (idle, host file I/O) to a Linux-shaped stack and catches the foreign kernel's non-abort exceptions (die()), so XNU problems end the run instead of the host. EL0 tracing: boot-arg `linux64_trace=1`.
Debugging: the VM console is captured on the host (`scripts/serial-pty.py`), a monitor thread on another CPU prints XNU's counters every 2 s, and XNU dumps its threads with their saved frames after 20000 idle rounds.