Skip to content

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

C

README: M2e done, M3 status (EL0 path, host-file root, Apple's /bin/echo through dyld and the shared cache)

Heyang Zhou0e6c4a51a36b
diff --git a/README.md b/README.md
index 42d414a..ec12c3b 100644
--- a/README.md
+++ b/README.md
@@ -21,7 +21,8 @@ The two sides are kept apart by license and only meet at the FKI (foreign kernel
- **M2a (done, 2026-11-20).** `arm_init` runs inside the module from `xnu.ko`'s boot args and ADT up to `arm_vm_init` (stage 199), with XNU's `kprintf` in dmesg. Next is M2b: a LINUX64 `arm_vm_init` and pmap on FKI.
- **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 (in progress, 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).
+- **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`.
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.