xnulinux: Two Kernels, One CPU
Apple's XNU runs as a loadable Linux module, swapping page tables, PAC keys, and registers on every world switch. No hypervisor required.
- Two production kernels share one CPU core by taking turns owning it, with a disciplined register and page-table handoff instead of a hypervisor boundary.
- The world switch swaps TTBR0, TCR_EL1, the full PAC key set, and the TLS registers, then flushes the entire TLB on every call between XNU and Linux.
- xnulinux is neither a VM nor a compatibility layer: it loads Apple's open-source XNU as xnu.ko and lets it drive the MMU and CPUs directly.
- The project reports a working macOS 27.2.1 desktop on arm64 Linux, but ships with documented stopgaps around security, memory layout, and GPU acceleration.
The World Switch
On every call between the two kernels, the CPU saves one world's registers, swaps its page tables, swaps its pointer authentication keys, swaps its thread-local pointers, flushes the entire translation lookaside buffer, and runs the other kernel. Then it reverses the whole sequence.
There is no hypervisor in that sentence. There is no guest boundary. There is a very disciplined handoff, written in hand-tuned assembly, executed on every core.
This is the world switch, and it is the most surprising thing in xnulinux. The project runs Apple's open-source XNU kernel as a loadable Linux module. XNU owns the CPU and the MMU while it runs. Linux owns them the rest of the time. Neither one is virtualized. They just take turns.
The README frames the goal plainly: "Run macOS userspace on Linux by loading the macOS kernel into it."
Run macOS userspace on Linux by loading the macOS kernel into it.
What xnulinux Actually Is
Apple publishes XNU's source. xnulinux builds it, patches it, and loads the result as xnu.ko into a stock arm64 Linux kernel. A second module, fki.ko, is the Foreign Kernel Interface. It gives hosted XNU the things a kernel normally expects from hardware: memory, timers, files, networking, and a path to the GPU.
The hosted XNU is not sandboxed. It drives the CPUs and the MMU directly, which is exactly why macOS and Linux processes can share the same cores without a hypervisor in between. The README reports booting a macOS 27.2.1 desktop on an Apple Silicon Linux VM and on a bare-metal NVIDIA DGX Spark. The repository snapshot shows 2,312 stars and 89 forks.
# Load the hosted macOS kernel into a stock arm64 Linux kernel
insmod xnu.ko cpus=4 ram_mb=8192 hostdisk=/dev/nvme0n1p3 \
fb_width=1920 fb_height=1080 fb_dump=/tmp/fb.raw
# Bring up the Foreign Kernel Interface that supplies
# memory, timers, files, networking, and GPU access
insmod fki.ko
Who Built It and Why
xnulinux lives in the AFK-surf organization, from AFK Inc. The repository's top contributor is losfair, with 262 commits. The announcement was blunt about what had been done.
We loaded XNU as a kernel module inside stock arm64 Linux and ran its code in kernel context. No VM, no compat layer, open source.
Then came the milestone post. Heyang Zhou, associated with the project announcement, put it simply.
We can now run full macOS GUI userspace on Linux.
The DGX Spark detail is the one that reframes the whole project. A DGX Spark is an arm64 Linux box with no Apple silicon inside it. The README reports running a macOS desktop on it, with screen sharing and SSH, using CPU rendering rather than a hardware GPU.
How Two Kernels Share One Core
The ledger for the whole arrangement is struct xnu_world. Each CPU gets one. It holds the callee-saved registers and stack pointer for both worlds, both sets of TLS registers, both page-table base registers, both PAC key sets, and Linux's shadow call stack pointer. The layout is fixed and enforced with _Static_assert checks on the exact byte offsets.
struct xnu_world {
u64 linux_regs[14]; /* x19-x30, SP */
u64 xnu_regs[13]; /* x19-x30, SP */
u64 linux_tpidr0, linux_tpidrro0;
u64 xnu_tpidr, xnu_tpidrro;
u64 linux_ttbr0, linux_tcr;
u64 xnu_ttbr0, xnu_tcr;
u64 linux_scs; /* x18, shadow call stack */
struct fki_pac_keys linux_keys;
struct fki_pac_keys xnu_keys;
};
The entry path is short and deliberate. Locate the save area for this CPU from its MPIDR affinity bits. Save Linux's callee-saved registers, stack pointer, and x18. Call fki_enter to disable IRQs and preemption and load XNU's PAC keys. Save and set the TLS registers. Mask all exceptions, including debug exceptions. Swap TTBR0 and TCR_EL1 to XNU's user pmap. Flush the TLB. Branch.
Three choices inside that path are worth naming.
- TPIDR_EL1 stays Linux's. XNU keeps its thread pointer in TPIDRRO_EL0, so a fault taken inside XNU still reaches Linux with a valid per-CPU base and becomes a normal oops instead of a mystery.
- x18 stays with the CPU. Under
CONFIG_SHADOW_CALL_STACK, x18 is Linux's shadow call stack pointer. XNU does not use it, so Linux functions that XNU calls push and pop on it in a balanced way. - PAC instructions are banned inside
world.S. The source comment is explicit: "No PAC instructions here: keys change under our feet." Any pointer authenticated across a key swap would fail, so the keys are only touched infki_pac_swapandfki_enter/fki_leave.
The full TLB flush is the expensive part. TO_XNU_MM and TO_LINUX_MM each end with tlbi vmalle1. The comment justifies it by noting that the two worlds' ASIDs are unrelated. Correct, and costly. It is probably a major contributor to the performance gap the project documents.
Faking an Apple SoC
XNU expects its hardware description from iBoot. There is no iBoot. So xnulinux builds the description itself.
adt.c synthesizes an Apple Device Tree, the same {u32 nProperties, u32 nChildren} structure XNU parses on real hardware. It is a synthetic description of a virtual Apple SoC, and its existence is one of the clearest statements of what the project has to fake. macho.c applies chained fixups and re-signs authenticated pointers inside XNU's key context, because those pointers must be signed with the keys XNU will later authenticate with.
A set of IOKit kexts give hosted macOS its devices: disk, display, input, Ethernet, DRM, and a Metal CPU device. The README credits some of these derived kexts to macOS-DroidVM. Together with the ADT and the Mach-O loader, they are what make this a faithful boot rather than a loader that merely runs code.
Not a VM
The distinction that matters is categorical, not visual. xnulinux is not a virtual machine, not a compatibility layer, and not a reimplementation. The boundary between the two kernels is a module boundary, and XNU is the real kernel, not a guest.
| Approach | What runs | Boundary | arm64 Linux host | Full macOS userspace |
|---|---|---|---|---|
| xnulinux | Apple's XNU kernel, loaded as xnu.ko plus fki.ko | Module boundary, no VM | Yes | Goal |
| Darling | Reimplemented macOS interfaces | Userspace layer | Yes | Partial |
| GNUstep | OpenStep/Cocoa API implementation | Userspace layer | Yes | No |
| Apple Virtualization.framework | macOS guest kernel behind a hypervisor | VM boundary | No, needs Apple hardware | Yes, isolated guest |
| QEMU/KVM | Guest operating system | VM boundary | Yes, host-dependent | Partial |
A Hacker News commenter drew the line cleanly against GNUstep: "The goal of GNUstep was/is to provide an open-source implementation of the OPENSTEP API. This is not what this project here is doing. It's taking the already open-source XNU kernel and gets it to run under Linux." That is the whole differentiator in one sentence.
The Fine Print
The project's own production document lists the stopgaps: a merged OS cryptex, patched AMFI, relaxed SIP, and slower memory access than a native VM. On performance, it reports Dock startup at 31 seconds for the hosted setup versus 49 seconds for a two-CPU Apple Virtualization VM on the same host. These are project-reported measurements.
- Security is relaxed by design. Patched AMFI and relaxed SIP are part of making an unmodified macOS userspace run outside Apple's trust chain.
- Memory is slower than a native VM. The full TLB flush on every world switch is the likely cause.
- You supply the macOS install. Apple binaries are not distributed in the repository.
- arm64 only. The project requires pointer authentication and 4K pages, which rules out x86_64 Linux hosts.
The licensing split is deliberate. xnu.ko is APSL-2.0, matching XNU itself. fki.ko and the Linux-side code are GPL-2.0-only. The README describes FKI as "a narrow, stable, semantic interface," and xnu.ko "only uses fki.h." Whether that boundary holds up legally is a question for a licensing expert, not this article.
Nice, I like this, though, it still needs Apple hardware. I think I would prefer if someone was to improve GNUstep instead.
That comment reflects the state of the project at announcement: the tested environments were an Apple Silicon Linux VM and a bare-metal DGX Spark, and those results do not establish broad hardware compatibility. The EULA questions raised in the same thread are community discussion, not legal conclusions.





