indicogniBuild a VMM

Contents

Chapter 23 · Part X

macOS guests, the high road: Virtualization.framework

Needs a Mac ~3 h
24 of 26

Course progress: chapter 23 is 24 of the 26 chapters written so far (numbering starts at 00)

Warm-up: three questions from earlier chapters

Answer each one in your head or on paper before you open its answer. They change on each visit.

  1. From chapter 13: Loading kernels: arm64 Image, initramfs and ELF

    The eight bytes at offset 0x10 of an Image header are 00 00 2a 02 00 00 00 00, and text_offset is 0. Where does the kernel's memory start and end in our plan?

    Show answer

    The field is image_size, little-endian: 0x022a0000. The kernel starts at the 2 MiB-aligned base 0x4020_0000 plus text_offset 0, so it owns 0x4020_0000..0x424a_0000 (start plus image_size, end exclusive).

  2. From chapter 10: The Device Tree: the VMM's promise to the guest

    A node's parent says #address-cells = <2> and #size-cells = <1>. The node's reg describes two ranges. How many bytes long is the reg property?

    Show answer

    Each range is 2 + 1 = 3 cells, and a cell is 4 bytes, so one range is 12 bytes and two ranges are 24. The counts come from the parent, not from the node itself.

  3. From chapter 01: Where our VMM sits: Hypervisor.framework and a hand-written FFI

    Your doctor prints hv_vm_create: HV_BUSY (0xfae94002). What is the most likely cause in your own code?

    Show answer

    A VM already exists in this process: Hypervisor.framework allows one per process. Usually an earlier Vm is still alive, or was dropped without Drop calling hv_vm_destroy.

Concepts you'll need

Chapters before this one: chapter 14, Booting Linux to a shell.

  • Core, taught here: Virtualization.framework (VZ) as a machine Apple defines and you configure; VZLinuxBootLoader; where a VZ guest runs (an XPC service with private entitlements); the two entitlements compared; for macOS guests, restore images, the Mac platform identity, VZMacOSBootLoader and Apple-specific devices; the inventory of what a low-level VMM must provide.
  • Core, from earlier: a guest as a host process, and paravirtual devices (chapter 00); VZ's place in the macOS stack and the hypervisor entitlement (chapter 01); exception levels (chapter 02); the memory map (chapter 05); memory-mapped I/O, MMIO (chapter 07); the PL011, ttyAMA0 and the output filter (chapter 09); the device tree (chapter 10); the Generic Interrupt Controller, GIC (chapter 12); the loader and test initramfs (chapter 13); booting Linux to a shell (chapter 14).
  • Primers (read first): codesign-entitlements, including its optional sections on restricted entitlements and the hardened runtime.
  • Primers (review): tty-termios (escape sequences, and its section on why bytes from a guest are dangerous); linux-boot-sequence (kernel modules); uefi (only the name, for one table row).
  • Pointers: Apple's Virtualization documentation and software development kit (SDK) headers; Apple's licence for macOS virtual machines (cited, not interpreted); Swift; PCI Express; XPC services.
  • Forward definitions: virtio and its virtio-mmio transport (chapter 15), and virtio-console with its Linux name hvc0, and virtio-rng (chapter 17); virtio-blk, virtio's disk (chapter 18); AVPBooter, Apple's boot ROM for virtual Macs, and ParavirtualizedGraphics (chapter 24). Each is defined where it first appears.

In chapter 14 your virtual machine monitor (VMM) booted Alpine's kernel with the command line console=ttyAMA0 earlycon=pl011,0x09000000 macvmm.test=boot, and the test initramfs printed macvmm-initramfs: ready. Now give the same kernel file, the same initramfs file and that command line minus its earlycon= word to a different VMM: the one Apple ships inside macOS, Virtualization.framework. The earlycon= word goes because it names an address on our machine, the PL011 at 0x0900_0000, which means nothing on a machine whose map you have not seen. Same Mac, same CPU, the same files. What appears on your terminal?

Predict The kernel and the initramfs are byte for byte what your VMM booted in chapter 14, and the command line is console=ttyAMA0 macvmm.test=boot, chapter 14's without the early console. Under Virtualization.framework, will you see (a) the same boot log ending in macvmm-initramfs: ready, (b) a kernel panic, or (c) something else? If you think the command line needs a change, which change, and why?

Write your answer under ## Predict in your journal now, before you read on. The section "Same kernel, another machine" runs it.

Every row of the problem ledger is closed (this chapter needs only chapter 14's), so this chapter sits beyond it. It makes explicit what the ledger left implicit: a machine is its whole contract of devices and firmware, and a kernel that boots on one meets a different contract on the next. Plan about 3 hours at your Mac. There is no Rust to write: you read and run a small tool, and write two short documents.

Objectives: by the end you can

  • Explain, with an example from your own runs, what Virtualization.framework (VZ) supplies that Hypervisor.framework (HVF) does not: a complete machine with Apple's memory map, devices and boot loader, and, for macOS guests, restore images, the Mac platform identity, VZMacOSBootLoader and paravirtual graphics.
  • Build and run the provided Swift tool tools/vz-mac/, signed with exactly com.apple.security.virtualization; boot our Linux test initramfs under VZ, and predict, then explain from the output, which console it prints on.
  • Compare the two programs' entitlements with codesign, find with ps which process runs a VZ guest, and state whose code a hostile guest attacks in each case.
  • Inventory what a low-level VMM must provide to boot macOS, marking each piece documented or undocumented; chapter 24 starts from it.

Before you start. From the repository root, run scripts/learner start 23 to copy this chapter's journal to learner/journal/23.md. You also need Xcode, for the swift command (swift --version should print a version), and the kernel and initramfs from chapter 13 in .cache/macvmm/. If swift complains about the Xcode licence, open Xcode once and accept it there; no sudo is needed.

Configured, not built

Chapter 01 placed two Apple frameworks side by side. With HVF you build the machine, as every Part so far did. With VZ you describe the machine, and Apple builds and runs it: a boot loader, a platform, a CPU count, a memory size and a list of devices.

The tool in this chapter, vz-mac, is a small Swift program, because VZ has no C interface to call from Rust; you read and run it, not write it.

Aside

Swift is Apple's language for its own frameworks; VZ is an Objective-C and Swift interface. If a line puzzles you, see The Swift Programming Language: let is Rust's let, var is let mut, and throws marks a function that can fail, like a Result. Apple's reference for every class below is the Virtualization documentation.

Here is the whole machine definition for a Linux guest, from tools/vz-mac/Sources/vz-mac/LinuxBoot.swift:

tools/vz-mac/Sources/vz-mac/LinuxBoot.swiftlines 136-157
/// The whole machine definition for a Linux guest under VZ. Everything else (memory map,/// interrupt controller, device tree, boot protocol, device models) is Apple's.func makeLinuxConfiguration(_ r: LinuxRequest, console: VZSerialPortAttachment)    -> VZVirtualMachineConfiguration{    let bootLoader = VZLinuxBootLoader(kernelURL: URL(fileURLWithPath: r.kernel))    bootLoader.initialRamdiskURL = URL(fileURLWithPath: r.initrd)    bootLoader.commandLine = r.cmdline    // One virtio-console port: the guest's `hvc0`.    let serial = VZVirtioConsoleDeviceSerialPortConfiguration()    serial.attachment = console    let config = VZVirtualMachineConfiguration()    config.platform = VZGenericPlatformConfiguration()    config.bootLoader = bootLoader    config.cpuCount = r.cpus    config.memorySize = r.memory    config.serialPorts = [serial]    config.entropyDevices = [VZVirtioEntropyDeviceConfiguration()]  // virtio-rng, as in chapter 17    return config}

VZLinuxBootLoader takes a kernel, an initramfs and a command line: chapter 13's loader and boot plan, and chapter 10's device tree, in three lines, because VZ writes its own device tree and places everything itself. VZGenericPlatformConfiguration is Apple's generic 64-bit Arm machine, with its memory map, interrupt controller and timer. The serialPorts line gives one serial port, a VZVirtioConsoleDeviceSerialPortConfiguration; there is no PL011 class to choose instead, and the next section's run shows what that means. The entropyDevices line adds a random-number source.

Your VMM, and the chapter that built itThe line in VZ's configuration
guest RAM and the region table (04, 05)config.memorySize
virtual CPUs (vCPUs), the exit loop, power calls (06 to 08)config.cpuCount
the PL011 (09)config.serialPorts: a serial port of another kind (next section)
the device tree (10)generated inside VZ, never shown to you
the GIC and the timer (11, 12)inside VZGenericPlatformConfiguration
the loader and the boot plan (13)VZLinuxBootLoader

Every job on the left still exists under VZ. Apple's code does it, and you cannot read it.

Building and signing the tool

tools/vz-mac/run.sh does for vz-mac what the signing runner does for macvmm: it runs swift build, copies the binary to target/vz-mac/signed/vz-mac, signs the copy ad hoc with tools/vz-mac/vz-mac.entitlements, reads the signature back, and only then runs it. It also signs with the hardened runtime (codesign -o runtime), which among other things makes macOS ignore the DYLD_* environment variables that could inject code into the process.

Build and sign without running anything, sign macvmm in place, then compare the two signatures:

Shell
tools/vz-mac/run.sh --print-pathscripts/sign.sh target/debug/macvmmcodesign -d --entitlements - target/vz-mac/signed/vz-maccodesign -d --entitlements - target/debug/macvmm

The first run.sh compiles vz-mac (a minute or so; build lines go to standard error), then, with --print-path, prints where the signed copy is, target/vz-mac/signed/vz-mac under your repository, and runs nothing. The second line matters because cargo run signs a private copy under target/run-bin/, so target/debug/macvmm carries only the linker's signature until you sign it in place.

TerminalReal output
codesign -d --entitlements - target/vz-mac/signed/vz-macexit: 0--- stdout ---[Dict]	[Key] com.apple.security.virtualization	[Value]		[Bool] true--- stderr ---Executable=<repo>/target/vz-mac/signed/vz-mac
captured: real output, Apple M5 Pro, macOS 27.2.1, commit dad6c99, 2026-11-20
  • The binary run.sh built and signed (tools/vz-mac/run.sh --print-path prints this path).
course/captures/23-codesign-vz.txt
TerminalReal output
codesign -d --entitlements - target/debug/macvmmexit: 0--- stdout ---[Dict]	[Key] com.apple.security.hypervisor	[Value]		[Bool] true--- stderr ---Executable=<repo>/target/debug/macvmm
captured: real output, Apple M5 Pro, macOS 27.2.1, commit dad6c99, 2026-11-20
  • Signed in place first with scripts/sign.sh target/debug/macvmm (cargo run signs a private copy instead, which you cannot easily point codesign at).
course/captures/23-codesign-macvmm.txt

Two programs, one self-granted entitlement each. com.apple.security.hypervisor lets macvmm create a virtual machine (VM) and run vCPUs itself; com.apple.security.virtualization lets vz-mac ask VZ for a whole machine. In separate programs, a bug in one cannot borrow the other's right.

Same kernel, another machine

Time for your Predict. Run chapter 14's command line, minus the earlycon= word:

Shell
tools/vz-mac/run.sh linux --kernel .cache/macvmm/Image-virt --initrd .cache/macvmm/initramfs-test.img --cmdline "console=ttyAMA0 macvmm.test=boot"
TerminalReal output
tools/vz-mac/run.sh linux --kernel .cache/macvmm/Image-virt --initrd .cache/macvmm/initramfs-test.img --cmdline "console=ttyAMA0 macvmm.test=boot"exit: 0--- stderr ---Building for production...[1 / 1]Build complete! (0.33 sec)VZ guest state: startingVZ guest state: runningVZ guest state: stopped (guest)vz-mac: guest powered off (exit 0)
captured: real output, Apple M5 Pro, macOS 27.2.1, commit dad6c99, 2026-11-20
  • The reference tool, unmodified, given chapter 14's command line without its earlycon= word, which names the PL011 address on our machine; VZ has no PL011 there. run.sh builds and signs vz-mac first; its build lines are on stderr.
course/captures/23-vz-ttyama0.txt

We checked this on a real Mac: (c). Not one byte on standard output, yet VZ guest state: stopped (guest) and exit 0: the guest powered itself off, and the only code in this initramfs that does so is /init, after it prints macvmm-initramfs: ready. So the kernel booted, /init ran and printed, and nobody heard.

ttyAMA0 is the name Linux gives a PL011, and this machine has no PL011. Its one serial port, the VZVirtioConsoleDeviceSerialPortConfiguration from the configuration, is a virtio-console. Virtio is the standard family of devices designed for virtual machines, which share memory with the VMM instead of trapping on every register (chapter 15 builds its transport), and virtio-console is its serial port; Linux calls the first one hvc0 (chapter 17 adds one to your VMM). The random-number source was virtio-rng, virtio's random-number device (also chapter 17).

When the command line names a console, Linux enables only a console of that name. The virtio-console registered but was never switched on, so /init's bytes went nowhere. Now name the console this machine has:

TerminalReal output
tools/vz-mac/run.sh linux --kernel .cache/macvmm/Image-virt --initrd .cache/macvmm/initramfs-test.img --cmdline "console=hvc0 macvmm.test=boot"exit: 0--- stdout ---[    0.044643] hv_vmbus: registering driver hyperv_keyboard[    0.044843] rtc-pl031 20050000.pl031: registered as rtc0[    0.044888] rtc-pl031 20050000.pl031: setting system clock to 2026-11-20T09:12:00 UTC (1795165920)[    0.045042] NET: Registered PF_INET6 protocol family[    0.046628] Segment Routing with IPv6[    0.046678] In-situ OAM (IOAM) with IPv6[    0.050367] registered taskstats version 1[    0.050510] Loading compiled-in X.509 certificates[    0.088238] Freeing initrd memory: 9204K[    0.091070] Loaded X.509 cert 'alpinelinux.org: Alpine Linux kernel key: 87fa969a47f3e2a6aa35859eb932a17c95abcd82'[    0.091832] Demotion targets for Node 0: null[    0.091959] Key type .fscrypt registered[    0.091990] Key type fscrypt-provisioning registered[    0.093376] clk: Disabling unused clocks[    0.093410] PM: genpd: Disabling unused power domains[    0.093840] Freeing unused kernel memory: 2048K[    0.093895] Run /init as init processmacvmm-initramfs: ready 6.18.60-0-virt--- stderr ---Building for production...Build complete! (0.15 sec)VZ guest state: startingVZ guest state: runningVZ guest state: stopped (guest)vz-mac: guest powered off (exit 0)
captured: real output, Apple M5 Pro, macOS 27.2.1, commit dad6c99, 2026-11-20
  • The reference tool, unmodified. run.sh builds and signs vz-mac first; its build lines are on stderr.
course/captures/23-vz-linux.txt

The marker line: the same files boot to the end, so the first run did not panic either. Two lines deserve a second look:

  • rtc-pl031 20050000.pl031. Chapter 14's run said rtc-pl031 9010000.pl031: the same real-time clock (RTC) design, at another address. Same kernel, different machine.
  • The first line: 44 milliseconds in, not 0.000000. Chapter 14 had an early boot console, earlycon, printing from the kernel's first line; this machine has none.

So when did hvc0 start printing? Ask the guest, in the test initramfs's shell case, which stops at a / # prompt:

Shell
tools/vz-mac/run.sh linux --kernel .cache/macvmm/Image-virt --initrd .cache/macvmm/initramfs-test.img --cmdline "console=hvc0 macvmm.test=shell"

At the prompt, type dmesg | grep -i -e console -e virtio, then poweroff -f:

TerminalReal output
tools/vz-mac/run.sh linux --kernel .cache/macvmm/Image-virt --initrd .cache/macvmm/initramfs-test.img --cmdline "console=hvc0 macvmm.test=shell"exit: 0--- stdout ---[    0.068223] hv_vmbus: registering driver hyperv_keyboard[    0.069149] rtc-pl031 20050000.pl031: registered as rtc0[    0.069204] rtc-pl031 20050000.pl031: setting system clock to 2026-11-20T10:15:33 UTC (1795169733)[    0.069551] NET: Registered PF_INET6 protocol family[    0.070095] Segment Routing with IPv6[    0.070276] In-situ OAM (IOAM) with IPv6[    0.074155] registered taskstats version 1[    0.075462] Loading compiled-in X.509 certificates[    0.127501] Freeing initrd memory: 9204K[    0.131197] Loaded X.509 cert 'alpinelinux.org: Alpine Linux kernel key: 87fa969a47f3e2a6aa35859eb932a17c95abcd82'[    0.134628] Demotion targets for Node 0: null[    0.135149] Key type .fscrypt registered[    0.135360] Key type fscrypt-provisioning registered[    0.137531] clk: Disabling unused clocks[    0.137739] PM: genpd: Disabling unused power domains[    0.138056] Freeing unused kernel memory: 2048K[    0.138446] Run /init as init processmacvmm-initramfs: ready 6.18.60-0-virt/ # ^[[6ndmesg | grep -i -e console -e virtio[    0.000000] Kernel command line: console=hvc0 macvmm.test=shell[    0.003404] Console: colour dummy device 80x25[    0.058483] virtio-pci 0000:00:05.0: enabling device (0000 -> 0002)[    0.061198] virtio-pci 0000:00:06.0: enabling device (0000 -> 0002)[    0.067685] printk: legacy console [hvc0] enabled/ # poweroff -f--- stderr ---Building for production...Build complete! (0.20 sec)VZ guest state: startingVZ guest state: runningVZ guest state: stopped (guest)vz-mac: guest powered off (exit 0)
captured: real output, Apple M5 Pro, macOS 27.2.1, commit dad6c99, 2026-11-20
  • Typed at the / # prompt (piped in by the capture after 6 s): dmesg | grep -i -e console -e virtio; poweroff -f. It asks the guest when each console was enabled.
course/captures/23-vz-console-dmesg.txt

(Times vary a little from run to run.) The kernel enabled hvc0 only after finding the virtio devices. The earlier lines are still in the log buffer, since dmesg reads them back, but hvc0 did not replay them. ttyAMA0 did: in the macvmm shell run in the next section, with no early console, printk: console [ttyAMA0] enabled comes about 4 milliseconds in, yet the log on your terminal starts at 0.000000. We have not checked why hvc0 skipped it.

The misconception this retires is "the same PL011". The kernel is identical; the machine is not, and the command line is part of their contract.

From the repository root, this chapter's cargo run lines run the reference VMM. To use yours, run them inside learner/ with ../.cache/macvmm/. Two options, --console and --serial none, arrive in chapter 17; if you came straight from chapter 14, use the reference.

Try it

Run the mirror image on a VMM of ours: macvmm with console=hvc0 and no --console option (the option that adds a virtio-console), so it has no virtio-console. Predict before you look.

TerminalReal output
cargo run -q -p macvmm -- run --kernel .cache/macvmm/Image-virt --initrd .cache/macvmm/initramfs-test.img --mem 512M --cmdline "console=hvc0 macvmm.test=boot" --timeout 30exit: 0
captured: real output, Apple M5 Pro, macOS 27.2.1, commit dad6c99, 2026-11-20
  • The reference, unmodified, with no --console option (so no virtio-console device); run as scripts/sign-and-run.sh target/debug/macvmm, the runner cargo run uses.
course/captures/23-macvmm-hvc0.txt

Silence again, exit 0, for the same reason in reverse. Now add a virtio-console on standard output with --console stdio. Only one of --serial (where the PL011's output goes, chapter 09) and --console may own standard output, and --serial takes it by default, so send the PL011 nowhere with --serial none:

TerminalReal output
cargo run -q -p macvmm -- run --kernel .cache/macvmm/Image-virt --initrd .cache/macvmm/initramfs-test.img --mem 512M --serial none --console stdio --cmdline "console=hvc0 macvmm.test=boot" --timeout 30exit: 0
captured: real output, Apple M5 Pro, macOS 27.2.1, commit dad6c99, 2026-11-20
  • The reference, unmodified, now with a virtio-console on standard output (--console stdio) and the PL011 sent nowhere (--serial none), because only one of the two may be stdio.
course/captures/23-macvmm-hvc0-console.txt

Still silent, and this time the device is there. In Alpine's kernel the virtio-mmio transport, the code that finds virtio devices at fixed addresses as our VMM places them (chapter 15), is a loadable module (scripts/initramfs/init notes this; the linux-boot-sequence primer explains modules). The boot case never loads it, so no driver finds the console. Under VZ the console sits on a different bus, PCI Express (next section), whose driver is built in.

One more variant, for the spec hunt at the end: a VZ boot whose command line names no console at all.

TerminalReal output
tools/vz-mac/run.sh linux --kernel .cache/macvmm/Image-virt --initrd .cache/macvmm/initramfs-test.img --cmdline "macvmm.test=boot"exit: 0--- stderr ---Building for production...[1 / 3]Build complete! (3.43 sec)VZ guest state: startingVZ guest state: runningVZ guest state: stopped (guest)vz-mac: guest powered off (exit 0)
captured: real output, Apple M5 Pro, macOS 27.2.1, commit dad6c99, 2026-11-20
  • The reference tool, unmodified; the command line names no console at all.
course/captures/23-vz-noconsole.txt

Silent again, exit 0. The spec hunt asks which console Linux picks when you name none.

Looking inside Apple's machine

VZ never shows its device tree, but the guest can describe what it found. Boot the shell case again under VZ, and then under a VMM of ours:

Shell
tools/vz-mac/run.sh linux --kernel .cache/macvmm/Image-virt --initrd .cache/macvmm/initramfs-test.img --cmdline "console=hvc0 macvmm.test=shell"cargo run -q -p macvmm -- run --kernel .cache/macvmm/Image-virt --initrd .cache/macvmm/initramfs-test.img --mem 512M --cmdline "console=ttyAMA0 macvmm.test=shell" --timeout 300

At each / # prompt, type the same lines. The for loop prints every Peripheral Component Interconnect (PCI) device the kernel found, with its vendor and device IDs:

cat /proc/consolesdmesg | head -n 3cat /proc/iomemfor d in /sys/bus/pci/devices/*; do echo $d $(cat $d/vendor $d/device); donepoweroff -f

Leave with poweroff -f. Ctrl-C also works under vz-mac, which then exits 130; under macvmm, Ctrl-C goes to the guest, and Ctrl-A then x quits (chapter 09). The captures piped these lines in; if macvmm stops with exit 5 while you type, its --timeout ran out, so raise it. First VZ:

TerminalReal output
tools/vz-mac/run.sh linux --kernel .cache/macvmm/Image-virt --initrd .cache/macvmm/initramfs-test.img --cmdline "console=hvc0 macvmm.test=shell"exit: 0--- stdout ---[    0.049452] hv_vmbus: registering driver hyperv_keyboard[    0.049612] rtc-pl031 20050000.pl031: registered as rtc0[    0.049646] rtc-pl031 20050000.pl031: setting system clock to 2026-11-20T09:12:36 UTC (1795165956)[    0.049813] NET: Registered PF_INET6 protocol family[    0.051186] Segment Routing with IPv6[    0.051217] In-situ OAM (IOAM) with IPv6[    0.053410] registered taskstats version 1[    0.053486] Loading compiled-in X.509 certificates[    0.094109] Freeing initrd memory: 9204K[    0.097203] Loaded X.509 cert 'alpinelinux.org: Alpine Linux kernel key: 87fa969a47f3e2a6aa35859eb932a17c95abcd82'[    0.097987] Demotion targets for Node 0: null[    0.098251] Key type .fscrypt registered[    0.098284] Key type fscrypt-provisioning registered[    0.099973] clk: Disabling unused clocks[    0.100005] PM: genpd: Disabling unused power domains[    0.100201] Freeing unused kernel memory: 2048K[    0.100266] Run /init as init processmacvmm-initramfs: ready 6.18.60-0-virt/ # ^[[6ncat /proc/consoleshvc0                 -W- (EC  p  )  229:0/ # dmesg | head -n 3[    0.000000] Booting Linux on physical CPU 0x0000000000 [0x610f0000][    0.000000] Linux version 6.18.60-0-virt (buildozer@build-3-24-aarch64) (cc (Alpine 15.2.0) 15.2.0, GNU ld (GNU Binutils) 2.45.1) #1-Alpine SMP PREEMPT_DYNAMIC 2026-11-01 07:26:31[    0.000000] efi: UEFI not found./ # cat /proc/iomem10000000-1000ffff : GICD10010000-1004ffff : GICR20050000-20050fff : pl031  20050000-20050fff : rtc-pl03120060000-20060fff : pl06140000000-4fffffff : PCI ECAM50000000-6ffdffff : pci  50000000-5000007f : 0000:00:05.0  50000080-500000bf : 0000:00:06.070000000-8fffffff : System RAM  70000000-7157ffff : Kernel code  71580000-7177ffff : reserved  71780000-7229ffff : Kernel data  722a0000-72b9dfff : reserved  72c00000-72c00fff : reserved  8f2f7000-8fbfffff : reserved  8fc27000-8fc27fff : reserved  8fc28000-8fca7fff : reserved  8fca8000-8fcf0fff : reserved  8fcf1000-8fd03fff : reserved  8fd04000-8fd06fff : reserved  8fd07000-8fffffff : reserved100000000-4ffffffff : pci  100000000-10000ffff : 0000:00:05.0    100000000-10000ffff : virtio-pci-modern  100010000-100017fff : 0000:00:06.0    100010000-100017fff : virtio-pci-modern/ # for d in /sys/bus/pci/devices/*; do echo $d $(cat $d/vendor $d/device); done/sys/bus/pci/devices/0000:00:00.0 0x106b 0x1a05/sys/bus/pci/devices/0000:00:05.0 0x1af4 0x1043/sys/bus/pci/devices/0000:00:06.0 0x1af4 0x1044/ # poweroff -f--- stderr ---Building for production...Build complete! (0.17 sec)VZ guest state: startingVZ guest state: runningVZ guest state: stopped (guest)vz-mac: guest powered off (exit 0)
captured: real output, Apple M5 Pro, macOS 27.2.1, commit dad6c99, 2026-11-20
  • Typed at the / # prompt (piped in by the capture after 5 s): cat /proc/consoles; dmesg | head -n 3; cat /proc/iomem; the for loop over /sys/bus/pci/devices that prints each vendor and device ID; poweroff -f.
  • Only the lines from macvmm-initramfs: ready on matter; the kernel log before it is the same as the boot run.
course/captures/23-vz-shell.txt

Then your VMM:

TerminalReal output
cargo run -q -p macvmm -- run --kernel .cache/macvmm/Image-virt --initrd .cache/macvmm/initramfs-test.img --mem 512M --cmdline "console=ttyAMA0 macvmm.test=shell" --timeout 300exit: 0--- stdout ---[    0.000000] Booting Linux on physical CPU 0x0000000000 [0x610f0000][    0.000000] Linux version 6.18.60-0-virt (buildozer@build-3-24-aarch64) (cc (Alpine 15.2.0) 15.2.0, GNU ld (GNU Binutils) 2.45.1) #1-Alpine SMP PREEMPT_DYNAMIC 2026-11-01 07:26:31[    0.000000] random: crng init done[    0.000000] Machine model: macvmm-virt[    0.000000] efi: UEFI not found.[    0.000000] OF: reserved mem: Reserved memory: No reserved-memory node in the DT[    0.000000] NUMA: Faking a node at [mem 0x0000000040000000-0x000000005fffffff][    0.000000] NODE_DATA(0) allocated [mem 0x5fd03780-0x5fd05c3f][    0.000000] Zone ranges:[    0.000000]   DMA      [mem 0x0000000040000000-0x000000005fffffff][    0.000000]   DMA32    empty[    0.000000]   Normal   empty[    0.000000] Movable zone start for each node[    0.000000] Early memory node ranges[    0.000000]   node   0: [mem 0x0000000040000000-0x000000005fffffff][    0.000000] Initmem setup node 0 [mem 0x0000000040000000-0x000000005fffffff][    0.000000] psci: probing for conduit method from DT.[    0.000000] psci: PSCIv1.1 detected in firmware.[    0.000000] psci: Using standard PSCI v0.2 function IDs[    0.000000] psci: Trusted OS migration not required[    0.000000] psci: SMC Calling Convention v1.1[    0.000000] percpu: Embedded 34 pages/cpu s99608 r8192 d31464 u139264[    0.000000] Detected PIPT I-cache on CPU0[    0.000000] CPU features: detected: Address authentication (IMP DEF algorithm)[    0.000000] CPU features: detected: GICv3 CPU interface[    0.000000] CPU features: detected: Spectre-v4[    0.000000] CPU features: detected: Spectre-BHB[    0.000000] alternatives: applying boot alternatives[    0.000000] Kernel command line: console=ttyAMA0 macvmm.test=shell[    0.000000] printk: log buffer data + meta data: 131072 + 458752 = 589824 bytes[    0.000000] Dentry cache hash table entries: 65536 (order: 7, 524288 bytes, linear)[    0.000000] Inode-cache hash table entries: 32768 (order: 6, 262144 bytes, linear)[    0.000000] software IO TLB: SWIOTLB bounce buffer size adjusted to 0MB[    0.000000] software IO TLB: area num 1.[    0.000000] software IO TLB: mapped [mem 0x000000005f380000-0x000000005f400000] (0MB)[    0.000000] Fallback order for Node 0: 0 [    0.000000] Built 1 zonelists, mobility grouping on.  Total pages: 131072[    0.000000] Policy zone: DMA[    0.000000] mem auto-init: stack:all(zero), heap alloc:on, heap free:off[    0.000000] SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=1, Nodes=1[    0.000000] Dynamic Preempt: none[    0.000000] rcu: Preemptible hierarchical RCU implementation.[    0.000000] rcu: 	RCU restricting CPUs from NR_CPUS=4096 to nr_cpu_ids=1.[    0.000000] 	Trampoline variant of Tasks RCU enabled.[    0.000000] 	Tracing variant of Tasks RCU enabled.[    0.000000] rcu: RCU calculated value of scheduler-enlistment delay is 100 jiffies.[    0.000000] rcu: Adjusting geometry for rcu_fanout_leaf=16, nr_cpu_ids=1[    0.000000] RCU Tasks: Setting shift to 0 and lim to 1 rcu_task_cb_adjust=1 rcu_task_cpu_ids=1.[    0.000000] RCU Tasks Trace: Setting shift to 0 and lim to 1 rcu_task_cb_adjust=1 rcu_task_cpu_ids=1.[    0.000000] NR_IRQS: 64, nr_irqs: 64, preallocated irqs: 0[    0.000000] GICv3: 988 SPIs implemented[    0.000000] GICv3: 0 Extended SPIs implemented[    0.000000] Root IRQ handler: gic_handle_irq[    0.000000] GICv3: GICv3 features: 16 PPIs, RSS[    0.000000] GICv3: GICD_CTLR.DS=1, SCR_EL3.FIQ=0[    0.000000] GICv3: CPU0: found redistributor 0 region 0:0x00000000080a0000[    0.000000] rcu: srcu_init: Setting srcu_struct sizes based on contention.[    0.000000] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 1911260446275000 ns[    0.000000] arch_timer: cp15 timer running at 24.00MHz (virt).[    0.000000] clocksource: arch_sys_counter: mask: 0xffffffffffffff max_cycles: 0x588fe9dc0, max_idle_ns: 440795202592 ns[    0.000000] sched_clock: 56 bits at 24MHz, resolution 41ns, wraps every 4398046511097ns[    0.000201] kfence: initialized - using 2097152 bytes for 255 objects at 0x(____ptrval____)-0x(____ptrval____)[    0.000247] Console: colour dummy device 80x25[    0.000266] Calibrating delay loop (skipped), value calculated using timer frequency.. 48.00 BogoMIPS (lpj=24000)[    0.000267] pid_max: default: 32768 minimum: 301[    0.000288] LSM: initializing lsm=lockdown,capability,landlock,yama[    0.000353] landlock: Up and running.[    0.000353] Yama: becoming mindful.[    0.000384] Mount-cache hash table entries: 1024 (order: 1, 8192 bytes, linear)[    0.000385] Mountpoint-cache hash table entries: 1024 (order: 1, 8192 bytes, linear)[    0.000826] rcu: Hierarchical SRCU implementation.[    0.000827] rcu: 	Max phase no-delay instances is 400.[    0.001311] EFI services will not be available.[    0.001330] smp: Bringing up secondary CPUs ...[    0.001333] smp: Brought up 1 node, 1 CPU[    0.001334] SMP: Total of 1 processors activated.[    0.001334] CPU: All CPU(s) started at EL1[    0.001341] CPU features: detected: Branch Target Identification[    0.001344] CPU features: detected: ARMv8.4 Translation Table Level[    0.001344] CPU features: detected: Data cache clean to the PoU not required for I/D coherence[    0.001345] CPU features: detected: Common not Private translations[    0.001345] CPU features: detected: CRC32 instructions[    0.001345] CPU features: detected: Data independent timing control (DIT)[    0.001345] CPU features: detected: E0PD[    0.001346] CPU features: detected: Enhanced Privileged Access Never[    0.001346] CPU features: detected: Generic authentication (IMP DEF algorithm)[    0.001347] CPU features: detected: RCpc load-acquire (LDAPR)[    0.001348] CPU features: detected: LSE atomic instructions[    0.001348] CPU features: detected: Privileged Access Never[    0.001348] CPU features: detected: RAS Extension Support[    0.001349] CPU features: detected: Speculation barrier (SB)[    0.001349] CPU features: detected: TLB range maintenance instructions[    0.001350] CPU features: detected: Scalable Matrix Extension[    0.001350] CPU features: detected: SME2[    0.001391] alternatives: applying system-wide alternatives[    0.002309] SME: minimum available vector length 64 bytes per vector[    0.002310] SME: maximum available vector length 64 bytes per vector[    0.002310] SME: default vector length 64 bytes per vector[    0.002351] Memory: 464096K/524288K available (13312K kernel code, 1994K rwdata, 8460K rodata, 2048K init, 9282K bss, 57716K reserved, 0K cma-reserved)[    0.002452] devtmpfs: initialized[    0.002662] posixtimers hash table entries: 512 (order: 1, 8192 bytes, linear)[    0.002667] futex hash table entries: 256 (16384 bytes on 1 NUMA nodes, total 16 KiB, linear).[    0.002677] 23904 pages in range for non-PLT usage[    0.002677] 515424 pages in range for PLT usage[    0.002698] pinctrl core: initialized pinctrl subsystem[    0.002748] DMI not present or invalid.[    0.003815] NET: Registered PF_NETLINK/PF_ROUTE protocol family[    0.003889] DMA: preallocated 128 KiB GFP_KERNEL pool for atomic allocations[    0.003911] DMA: preallocated 128 KiB GFP_KERNEL|GFP_DMA pool for atomic allocations[    0.003933] DMA: preallocated 128 KiB GFP_KERNEL|GFP_DMA32 pool for atomic allocations[    0.003967] audit: initializing netlink subsys (disabled)[    0.004042] thermal_sys: Registered thermal governor 'step_wise'[    0.004048] audit: type=2000 audit(0.003:1): state=initialized audit_enabled=0 res=1[    0.004050] cpuidle: using governor ladder[    0.004052] cpuidle: using governor menu[    0.004062] hw-breakpoint: found 6 breakpoint and 4 watchpoint registers.[    0.004065] ASID allocator initialised with 65536 entries[    0.004081] Serial: AMBA PL011 UART driver[    0.004236] 9000000.pl011: ttyAMA0 at MMIO 0x9000000 (irq = 13, base_baud = 0) is a PL011 rev1[    0.004262] printk: console [ttyAMA0] enabled[    0.049311] HugeTLB: registered 1.00 GiB page size, pre-allocated 0 pages[    0.049313] HugeTLB: 0 KiB vmemmap can be freed for a 1.00 GiB page[    0.049313] HugeTLB: registered 32.0 MiB page size, pre-allocated 0 pages[    0.049314] HugeTLB: 0 KiB vmemmap can be freed for a 32.0 MiB page[    0.049314] HugeTLB: registered 2.00 MiB page size, pre-allocated 0 pages[    0.049314] HugeTLB: 0 KiB vmemmap can be freed for a 2.00 MiB page[    0.049315] HugeTLB: registered 64.0 KiB page size, pre-allocated 0 pages[    0.049315] HugeTLB: 0 KiB vmemmap can be freed for a 64.0 KiB page[    0.049505] ACPI: Interpreter disabled.[    0.049512] iommu: Default domain type: Translated[    0.049513] iommu: DMA domain TLB invalidation policy: lazy mode[    0.052048] clocksource: Switched to clocksource arch_sys_counter[    0.059241] VFS: Disk quotas dquot_6.6.0[    0.059248] VFS: Dquot-cache hash table entries: 512 (order 0, 4096 bytes)[    0.059577] pnp: PnP ACPI: disabled[    0.060904] NET: Registered PF_INET protocol family[    0.060928] IP idents hash table entries: 8192 (order: 4, 65536 bytes, linear)[    0.066377] tcp_listen_portaddr_hash hash table entries: 256 (order: 0, 4096 bytes, linear)[    0.066383] Table-perturb hash table entries: 65536 (order: 6, 262144 bytes, linear)[    0.066387] TCP established hash table entries: 4096 (order: 3, 32768 bytes, linear)[    0.066392] TCP bind hash table entries: 4096 (order: 5, 131072 bytes, linear)[    0.066397] TCP: Hash tables configured (established 4096 bind 4096)[    0.066423] MPTCP token hash table entries: 512 (order: 2, 12288 bytes, linear)[    0.066429] UDP hash table entries: 256 (order: 2, 16384 bytes, linear)[    0.066431] UDP-Lite hash table entries: 256 (order: 2, 16384 bytes, linear)[    0.066448] NET: Registered PF_UNIX/PF_LOCAL protocol family[    0.066454] NET: Registered PF_XDP protocol family[    0.066458] PCI: CLS 0 bytes, default 64[    0.066540] Unpacking initramfs...[    0.071248] kvm [1]: HYP mode not available[    0.071413] Initialise system trusted keyrings[    0.072305] workingset: timestamp_bits=44 max_order=17 bucket_order=0[    0.079794] Key type asymmetric registered[    0.079797] Asymmetric key parser 'x509' registered[    0.079834] Block layer SCSI generic (bsg) driver version 0.4 loaded (major 248)[    0.089781] io scheduler mq-deadline registered[    0.089785] io scheduler kyber registered[    0.089799] io scheduler bfq registered[    0.090135] Serial: 8250/16550 driver, 4 ports, IRQ sharing enabled[    0.090578] hv_vmbus: registering driver hyperv_keyboard[    0.090712] rtc-pl031 9010000.pl031: registered as rtc0[    0.090719] rtc-pl031 9010000.pl031: setting system clock to 2026-11-20T10:15:44 UTC (1795169744)[    0.090806] NET: Registered PF_INET6 protocol family[    0.093832] Segment Routing with IPv6[    0.093836] In-situ OAM (IOAM) with IPv6[    0.096136] registered taskstats version 1[    0.096203] Loading compiled-in X.509 certificates[    0.153029] Freeing initrd memory: 9204K[    0.156597] Loaded X.509 cert 'alpinelinux.org: Alpine Linux kernel key: 87fa969a47f3e2a6aa35859eb932a17c95abcd82'[    0.158655] Demotion targets for Node 0: null[    0.158696] Key type .fscrypt registered[    0.158696] Key type fscrypt-provisioning registered[    0.161146] clk: Disabling unused clocks[    0.161150] PM: genpd: Disabling unused power domains[    0.161381] Freeing unused kernel memory: 2048K[    0.161398] Run /init as init processmacvmm-initramfs: ready 6.18.60-0-virt/ # cat /proc/consolesttyAMA0              -W- (EC Np a)  204:64/ # dmesg | head -n 3[    0.000000] Booting Linux on physical CPU 0x0000000000 [0x610f0000][    0.000000] Linux version 6.18.60-0-virt (buildozer@build-3-24-aarch64) (cc (Alpine 15.2.0) 15.2.0, GNU ld (GNU Binutils) 2.45.1) #1-Alpine SMP PREEMPT_DYNAMIC 2026-11-01 07:26:31[    0.000000] random: crng init done/ # cat /proc/iomem08000000-0800ffff : GICD080a0000-080bffff : GICR09000000-09000fff : pl011@9000000  09000000-09000fff : 9000000.pl011 pl011@900000009010000-09010fff : pl031@9010000  09010000-09010fff : rtc-pl03140000000-5fffffff : System RAM  40000000-40000fff : reserved  40200000-4177ffff : Kernel code  41780000-4197ffff : reserved  41980000-4249ffff : Kernel data  42600000-42efdfff : reserved  5f337000-5fbfffff : reserved  5fc0b000-5fccbfff : reserved  5fccc000-5fcf2fff : reserved  5fcf3000-5fd05fff : reserved  5fd06000-5fd07fff : reserved  5fd08000-5fffffff : reserved/ # for d in /sys/bus/pci/devices/*; do echo $d $(cat $d/vendor $d/device); donecat: can't open '/sys/bus/pci/devices/*/vendor': No such file or directorycat: can't open '/sys/bus/pci/devices/*/device': No such file or directory/sys/bus/pci/devices/*/ # poweroff -f[    4.553231] reboot: Power down
captured: real output, Apple M5 Pro, macOS 27.2.1, commit dad6c99, 2026-11-20
  • Typed at the / # prompt (piped in by the capture after 5 s): cat /proc/consoles; dmesg | head -n 3; cat /proc/iomem; the for loop over /sys/bus/pci/devices that prints each vendor and device ID; poweroff -f. The same lines as the VZ run.
  • Run as scripts/sign-and-run.sh target/debug/macvmm, the runner cargo run uses.
course/captures/23-macvmm-shell.txt

Where our VMM puts devices at fixed addresses, VZ puts its virtio devices on PCI Express (PCIe), the bus ordinary computers use for expansion cards. The operating system finds each device by reading its vendor and device IDs from a configuration space (Linux PCI documentation); the PCI ECAM range in VZ's /proc/iomem is that space, laid out by the Enhanced Configuration Access Mechanism (ECAM).

Under VZ the loop printed three devices. Vendor 0x106b is Apple: the host bridge, the device that connects the CPU to the PCI bus. Vendor 0x1af4 is the ID the virtio specification assigns to virtio devices (it is Red Hat's), and a modern virtio device's ID is 0x1040 plus its virtio type: 0x1043 is type 3, the console, and 0x1044 is type 4, the virtio-rng. Under our VMM the pattern matched no file, so cat complained about the literal *.

Put side by side:

our VMMVZ's generic platform
console (/proc/consoles)ttyAMA0, the PL011hvc0, a virtio-console
interrupt controllerGICD, the GIC's distributor, at 0x0800_0000GICD at 0x1000_0000
RAMfrom 0x4000_0000from 0x7000_0000
RTCPL031 at 0x0901_0000PL031 at 0x2005_0000
other devicesnone on a busa PCI host bridge, two virtio devices on PCI, and a PL061 (a general-purpose input/output controller)
firmwarenone, the VMM enters the kernelnone: efi: UEFI not found.
CPU ID in the first log line0x610f00000x610f0000

The kernel copes because, as chapter 10 showed, it reads the machine from the device tree each VMM hands it. UEFI is the Unified Extensible Firmware Interface, the standard firmware the uefi primer describes; neither machine runs one here.

The last row is the interesting sameness. It is the main ID register (MIDR), which names the CPU's maker and model.

A guest does not read the chip's own MIDR: HVF's header hv_vcpu_types.h lists HV_SYS_REG_MIDR_EL1 among the registers a VMM may set, and macvmm never sets it, so 0x610f0000 is HVF's default. The Arm Architecture Reference Manual's description of MIDR_EL1 gives the fields: bits [31:24] are the implementer, [23:20] the variant, [19:16] the architecture (0xF), [15:4] the part number and [3:0] the revision. So 0x610f0000 is implementer 0x61 (Apple) with part number 0, while Apple's real cores carry non-zero part numbers (Linux's arch/arm64/include/asm/cputype.h lists them).

Seeing HVF's default under VZ hints that VZ runs on HVF too; only a hint, since VZ could choose the same value. The next section has stronger evidence.

Who runs the guest?

Under macvmm, the guest's vCPUs are threads of your own process (chapter 00). Look for vz-mac's guest the same way: start the shell boot again and, while it waits at its prompt, run this in a second terminal:

Shell
ps -axo pid,ppid,comm | grep -i -e virtualization -e vz-mac

Your process IDs will differ:

TerminalReal output
ps -axo pid,ppid,comm | grep -i -e virtualization -e vz-macexit: 0--- stdout ---77330 77328 target/vz-mac/signed/vz-mac77333     1 /System/Library/Frameworks/Virtualization.framework/Versions/A/XPCServices/com.apple.Virtualization.VirtualMachine.xpc/Contents/MacOS/com.apple.Virtualization.VirtualMachine
captured: real output, Apple M5 Pro, macOS 27.2.1, commit dad6c99, 2026-11-20
  • Run in a second terminal while tools/vz-mac/run.sh linux ... --cmdline "console=hvc0 macvmm.test=shell" waited at its / # prompt. Process IDs differ on every run.
course/captures/23-ps-xpc.txt

Two processes: vz-mac, and Apple's com.apple.Virtualization.VirtualMachine, whose parent is process 1, launchd, which starts macOS services. Other VM apps add one each; yours goes away when vz-mac stops.

It is an XPC service: a helper program macOS starts on an app's behalf and talks to by messages (XPC documentation). vz-mac sent it a configuration; the service builds the machine, runs the vCPUs and emulates the devices. vz-mac never sees a VM exit, and VZ has no interface that would show one. What may that service do? Read its signature:

TerminalReal output
codesign -d --entitlements - /System/Library/Frameworks/Virtualization.framework/Versions/A/XPCServices/com.apple.Virtualization.VirtualMachine.xpc | grep -F '[Key]'exit: 0--- stdout ---	[Key] adi-client	[Key] com.apple.ane.iokit-user-access	[Key] com.apple.aned.private.adapterWeight.allow	[Key] com.apple.aned.private.allow	[Key] com.apple.developer.kernel.increased-memory-limit	[Key] com.apple.private.AppleVirtualPlatformIdentity	[Key] com.apple.private.FairPlayIOKitUserClient.Virtual.access	[Key] com.apple.private.PCIPassthrough.access	[Key] com.apple.private.amber.client	[Key] com.apple.private.ane.mappingMutableWeightsBuffer.allow	[Key] com.apple.private.ane.privileged-vm-client	[Key] com.apple.private.apfs.no-padding	[Key] com.apple.private.biometrickit.allow-match	[Key] com.apple.private.debug-usb.access	[Key] com.apple.private.fpsd.client	[Key] com.apple.private.ggdsw.GPUProcessProtectedContent	[Key] com.apple.private.hypervisor	[Key] com.apple.private.proreshw	[Key] com.apple.private.security.message-filter	[Key] com.apple.private.system-keychain	[Key] com.apple.private.tcc.check-allow-on-responsible-process	[Key] com.apple.private.vfs.open-by-id	[Key] com.apple.private.virtualization	[Key] com.apple.private.virtualization.linux-gpu-support	[Key] com.apple.private.virtualization.plugin-loader	[Key] com.apple.private.xpc.domain-extension	[Key] com.apple.security.hardened-process	[Key] com.apple.security.hardened-process.checked-allocations	[Key] com.apple.security.hardened-process.no-guard-objects	[Key] com.apple.security.hypervisor	[Key] com.apple.security.private.Virtualization.VzDevicesMonitor.register	[Key] com.apple.usb.hostcontrollerinterface	[Key] com.apple.vm.networking	[Key] keychain-access-groups	[Key] lskdd-client
captured: real output, Apple M5 Pro, macOS 27.2.1, commit dad6c99, 2026-11-20
  • Read-only: prints the entitlements in the signature of Apple's own helper; nothing is changed.
course/captures/23-codesign-xpc.txt

About three dozen keys on our Mac (macOS 27.2.1); your list may differ. Among them is com.apple.security.hypervisor, the one macvmm holds: the service may use Hypervisor.framework, and with the CPU ID above that is good evidence it does. Many others are com.apple.private.* keys, including com.apple.private.hypervisor. These are restricted entitlements: macOS honours them only in code Apple has vouched for, never in an ad-hoc signature (the primer shows macOS killing such a program at launch).

In chapter 02's exception levels: guest kernels run at EL1; macvmm, vz-mac and Apple's service at EL0; the macOS kernel's hypervisor part at EL2. A guest reaches its devices by memory-mapped I/O (MMIO, chapter 07), loads and stores that trap to the VMM, and by virtio traffic in shared memory. Who parses what the guest sends:

  guest kernel, EL1 (untrusted)     guest kernel, EL1 (untrusted)     | sends MMIO and                  | sends virtio traffic     | virtio traffic                  | over PCI; writes console bytes - - | - - - - - - trust boundary - - -| - - - - - - - - - - - - - - - - - -     v                                 v  macvmm, EL0, our process          VirtualMachine service, EL0      vz-mac, EL0,  parses guest traffic:             Apple's process              <-- our process    devices, exit loop              parses guest traffic:            sends a  also holds:                         devices, exit loop             configuration    device tree, loader             also holds:                      (XPC)     |                                device tree, loader     |                                 | console bytes ------------> filters them,     |                                 |                             prints them     | runs vCPUs                      | runs vCPUs     v                                 v  [ macOS kernel, EL2 part (chapter 02): one kernel under both columns     ]

The machine moved out of your process. Notice who now parses the guest's device traffic, and the one stream that still reaches vz-mac.

Security

Under macvmm, a hostile guest attacks our device code, in a process with one entitlement; you can read, test and patch every line. Under VZ, it attacks Apple's device code, in a process with about three dozen entitlements, many restricted; Apple audits and patches it, and you can do neither. A trade, not a ranking.

vz-mac's own surface: the console

vz-mac copies the guest's console bytes to your terminal, and some escape sequences make a terminal answer: ESC [ 6 n asks for the cursor position, and the terminal types its reply into its own input. vz-mac forwards what you type to the guest, so while it runs the reply goes to the guest; after it exits, your shell reads it (the tty-termios primer has worse examples). The VZ shell capture shows the guest's shell sending that query, which reached your terminal as the harmless text ^[[6n. (macvmm's default filter from chapter 09 drops queries silently, so its capture shows nothing there.) This filter, like chapter 09's in its strict mode, did that:

tools/vz-mac/Sources/vz-mac/Console.swiftlines 51-82
private mutating func feedByte(_ b: UInt8, into out: inout [UInt8]) {    if expected != 0 {        if b & 0xC0 == 0x80 {            pending.append(b)            if pending.count == expected { completeSequence(into: &out) }            return        }        // A lead or ASCII byte cut the sequence short: replace it, then handle `b` afresh.        out += Self.replacement        pending.removeAll(keepingCapacity: true)        expected = 0    }    switch b {    case 0x20...0x7E, 0x0A, 0x0D, 0x09, 0x08:        out.append(b)    case 0x00...0x1F:        out += [UInt8(ascii: "^"), b + 0x40]  // ESC -> ^[, BEL -> ^G, NUL -> ^@    case 0x7F:        out += Array("^?".utf8)    case 0x80...0x9F:        out += Array(String(format: "\\x%02x", b).utf8)  // raw 8-bit C1, e.g. CSI 0x9b    case 0xC2...0xDF:        start(b, length: 2)    case 0xE0...0xEF:        start(b, length: 3)    case 0xF0...0xF4:        start(b, length: 4)    default:  // 0xA0...0xBF stray continuation, 0xC0, 0xC1, 0xF5...0xFF never valid        out += Self.replacement    }}

Three parts carry the defence for single bytes:

  • case 0x00...0x1F: every control byte but newline, carriage return, tab and backspace prints in caret notation, ^ then the byte plus 0x40. ESC (0x1b) becomes ^[, so no escape sequence can start.
  • case 0x80...0x9F: these are the 8-bit C1 controls. Some terminals treat 0x9b alone as the start of a sequence (CSI, the Control Sequence Introducer, the same as ESC [), so a raw one is printed as the text \x9b.
  • The expected != 0 branch: bytes 0xC2 to 0xF4 start a multi-byte UTF-8 character, continued by bytes 0x80 to 0xBF. A character cut short becomes the replacement character, U+FFFD. A continuation byte with no lead takes the arms below: 0x80 to 0x9F print as \x.., and 0xA0 to 0xBF fall to default, U+FFFD.

A complete character is checked again, since a C1 control can be spelled in UTF-8: C2 9B is U+009B, CSI again.

tools/vz-mac/Sources/vz-mac/Console.swiftlines 92-110
private mutating func completeSequence(into out: inout [UInt8]) {    var cp: UInt32    switch expected {    case 2: cp = UInt32(pending[0] & 0x1F)    case 3: cp = UInt32(pending[0] & 0x0F)    default: cp = UInt32(pending[0] & 0x07)    }    for c in pending.dropFirst() { cp = (cp << 6) | UInt32(c & 0x3F) }    let minimum: UInt32 = expected == 2 ? 0x80 : (expected == 3 ? 0x800 : 0x1_0000)    if cp < minimum || cp > 0x10_FFFF || (0xD800...0xDFFF).contains(cp) {        out += Self.replacement  // overlong, out of range, or a surrogate    } else if (0x80...0x9F).contains(cp) {        out += Array(String(format: "\\u{%x}", cp).utf8)  // UTF-8-encoded C1    } else {        out += pending    }    pending.removeAll(keepingCapacity: true)    expected = 0}

An overlong form (more bytes than the character needs), a value past U+10FFFF or a surrogate becomes U+FFFD; U+0080 to U+009F print as \u{..}; anything else passes unchanged.

Good place to stop. Sitting B needs your Mac and about 1.5 hours (more if you install macOS).

The high road to macOS

Why use VZ at all? For Linux, mostly you would not; your own VMM shows you everything. For a macOS guest, VZ is the only supported way. A macOS virtual machine starts from a restore image, Apple's installation file for macOS (ending in .ipsw), a VZMacOSRestoreImage to VZ; VZMacOSInstaller installs it onto a disk image. Ask VZ which restore image this Mac supports; it asks Apple's servers but downloads nothing:

Shell
tools/vz-mac/run.sh install --bundle .cache/macvmm/macos-vm --latest --dry-run
TerminalReal output
tools/vz-mac/run.sh install --bundle .cache/macvmm/macos-vm --latest --dry-runexit: 0--- stderr ---Building for production...Build complete! (0.15 sec)vz-mac: latest supported restore image: macOS 27.2.1 build "26B131" at "https://updates.cdn-apple.com/2026FallFCS/c202a724-db7e-4d56-917b-110aa0226507/UniversalMac_27.2.1_26B131_Restore.ipsw"vz-mac: requirements: at least 2 CPUs and 4096 MiBvz-mac: dry run: nothing downloaded, no bundle created
captured: real output, Apple M5 Pro, macOS 27.2.1, commit dad6c99, 2026-11-20
  • The reference tool, unmodified. VZ asks Apple's servers which restore image this Mac supports; nothing is downloaded and no bundle is created.
course/captures/23-install-dry-run.txt

A macOS guest also has an identity. vz-mac keeps it in a bundle, a directory holding the disk image, the auxiliary storage, the hardware model and the machine identifier, and builds the platform from the last three:

tools/vz-mac/Sources/vz-mac/Bundle.swiftlines 84-97
func makeMacConfiguration(    hardwareModel: VZMacHardwareModel, machineIdentifier: VZMacMachineIdentifier,    auxiliaryStorage: VZMacAuxiliaryStorage, disk: URL, cpus: Int, memory: UInt64) throws(VZMacError) -> VZVirtualMachineConfiguration {    let platform = VZMacPlatformConfiguration()    platform.hardwareModel = hardwareModel    platform.machineIdentifier = machineIdentifier    platform.auxiliaryStorage = auxiliaryStorage    let config = VZVirtualMachineConfiguration()    config.platform = platform    config.bootLoader = VZMacOSBootLoader()    config.cpuCount = cpus    config.memorySize = memory
  • The hardware model: an opaque value naming the kind of virtual Mac the restore image was installed for.
  • The machine identifier: an opaque value that gives this one VM its identity.
  • The auxiliary storage: a file holding data the boot loader and the guest need, such as boot settings, laid out by the installer.

The SDK that ships with Xcode keeps VZ's headers in $(xcrun --show-sdk-path)/System/Library/Frameworks/Virtualization.framework/Headers/. There, VZMacPlatformConfiguration.h says that when a VM is loaded again, all three "must be restored to their original values". And VZMacOSBootLoader takes no kernel at all: it runs AVPBooter, Apple's boot ROM for virtual Macs, which loads and checks macOS's own boot files from the disk (chapter 24 runs it under your VMM). The devices complete the machine:

tools/vz-mac/Sources/vz-mac/Bundle.swiftlines 101-122
    // The main disk must be the first storage device (VZVirtualMachineConfiguration.h).    let attachment: VZDiskImageStorageDeviceAttachment    do {        attachment = try VZDiskImageStorageDeviceAttachment(url: disk, readOnly: false)    } catch {        throw .failure("cannot attach \(debugQuoted(disk.path)): \(describe(error))")    }    config.storageDevices = [VZVirtioBlockDeviceConfiguration(attachment: attachment)]    // Apple-specific devices: ParavirtualizedGraphics, a Mac keyboard and trackpad. They are    // what a low-level VMM would have to reimplement (docs/macos/inventory.md). No network    // device by default: the tool needs none, and NAT would add a surface for no lesson.    let graphics = VZMacGraphicsDeviceConfiguration()    graphics.displays = [        VZMacGraphicsDisplayConfiguration(widthInPixels: 1920, heightInPixels: 1200, pixelsPerInch: 80)    ]    config.graphicsDevices = [graphics]    config.keyboards = [VZMacKeyboardConfiguration()]    config.pointingDevices = [VZMacTrackpadConfiguration()]    config.entropyDevices = [VZVirtioEntropyDeviceConfiguration()]    return config}

The disk is a standard virtio-blk device, virtio's disk (chapter 18). The display, keyboard and trackpad are VZMac* classes: Apple-specific. The display is paravirtual graphics, a device designed for VMs. Its host half is ParavirtualizedGraphics, a public macOS framework, but the protocol the guest speaks to it is not documented (chapter 24).

Installing is optional, and big. Ask Apple's server how big the restore image above is, without downloading it (-I sends a HEAD request, which returns only the headers):

Shell
curl -sSI https://updates.cdn-apple.com/2026FallFCS/c202a724-db7e-4d56-917b-110aa0226507/UniversalMac_27.2.1_26B131_Restore.ipsw | grep -i '^content-length'

Use the URL your dry run printed; it changes with each release.

TerminalReal output
curl -sSI https://updates.cdn-apple.com/2026FallFCS/c202a724-db7e-4d56-917b-110aa0226507/UniversalMac_27.2.1_26B131_Restore.ipsw | grep -i '^content-length'exit: 0--- stdout ---Content-Length: 25595954706
captured: real output, Apple M5 Pro, macOS 27.2.1, commit dad6c99, 2026-11-20
  • A HEAD request: asks Apple's server for the size of the restore image the dry run named, and downloads nothing.
course/captures/23-ipsw-size.txt

About 26 GB. The disk image can grow to 64 GB, and the tool's README expects 20 to 40 minutes. If you have the space and time:

Shell
tools/vz-mac/run.sh install --bundle .cache/macvmm/macos-vm --latesttools/vz-mac/run.sh boot --bundle .cache/macvmm/macos-vm --seconds 60

The tool is written to print VZ guest state: running and, after the virtual power button, VZ guest state: stopped (requested). We did not install macOS, so there is no capture of a macOS boot here. running proves only that VZ started the machine: the reference's docs/macos/status.md records it even for a bundle with no macOS installed.

Aside

Apple's software licence agreement for macOS addresses macOS in virtual machines; the reference's docs/research/macos-guest.md cites section 2B(iii). Read the version for your macOS at apple.com/legal/sla; this course links it and does not interpret it. VZ enforces a limit of its own: its header VZError.h defines VZErrorVirtualMachineLimitExceeded, for when starting a VM "would exceed the system's limit on the number of simultaneously running virtual machines".

Breaking it on purpose

Deliberate breakage 1: run vz-mac without its entitlement. Copy the signed tool to a scratch directory and re-sign the copy with the hardened runtime and no entitlement (-i keeps the identifier vz-mac; with no entitlements file, the copy carries none):

Shell
mkdir -p target/scratchcp target/vz-mac/signed/vz-mac target/scratch/codesign -s - -f -o runtime -i vz-mac target/scratch/vz-mactarget/scratch/vz-mac linux --kernel .cache/macvmm/Image-virt --initrd .cache/macvmm/initramfs-test.img --cmdline "console=hvc0 macvmm.test=boot"

Chapter 01's macvmm got HV_DENIED from hv_vm_create. Predict: does VZ fail at the same moment, earlier, or later?

TerminalReal output
target/scratch/vz-mac linux --kernel .cache/macvmm/Image-virt --initrd .cache/macvmm/initramfs-test.img --cmdline "console=hvc0 macvmm.test=boot"exit: 1--- stderr ---vz-mac: configuration rejected by Virtualization.framework: "Invalid virtual machine configuration. The process doesn’t have the “com.apple.security.virtualization” entitlement. [VZErrorDomain 2]"
captured: real output, Apple M5 Pro, macOS 27.2.1, commit dad6c99, 2026-11-20
  • Deliberate breakage: a copy of target/vz-mac/signed/vz-mac in target/scratch/, re-signed with codesign -s - -f -o runtime -i vz-mac target/scratch/vz-mac, that is, with the hardened runtime and no entitlement; the tool itself is unchanged.
course/captures/23-no-entitlement.txt

Earlier, and by name. vz-mac calls the configuration's validate() before starting the machine, and VZ refused there; vz-mac exits 1. What you saw: a clean, named refusal at run time. The misconception it exposes: "Apple's service holds all the rights, so my program needs none"; the framework checks your signature before it asks the service for anything. The tool that finds it: the error text and codesign -d --entitlements -.

A weekend's work?

A common thought: "VZ is a wrapper around Hypervisor.framework; we could rewrite it in a weekend." Your runs say otherwise. Here are the device classes VZ offers, from the SDK headers:

TerminalReal output
ls "$(xcrun --show-sdk-path)/System/Library/Frameworks/Virtualization.framework/Headers" | grep -E 'Device(Specific)?Configuration|Keyboard|Trackpad|Pointing'exit: 0--- stdout ---VZAudioDeviceConfiguration.hVZConsoleDeviceConfiguration.hVZCustomVirtioDeviceConfiguration.hVZCustomVirtioDeviceConfigurationDelegate.hVZDirectorySharingDeviceConfiguration.hVZEntropyDeviceConfiguration.hVZGraphicsDeviceConfiguration.hVZKeyboardConfiguration.hVZMacGraphicsDeviceConfiguration.hVZMacKeyboardConfiguration.hVZMacTrackpadConfiguration.hVZMemoryBalloonDeviceConfiguration.hVZNetworkDeviceConfiguration.hVZNVMExpressControllerDeviceConfiguration.hVZPointingDeviceConfiguration.hVZSocketDeviceConfiguration.hVZStorageDeviceConfiguration.hVZUSBDeviceConfiguration.hVZUSBKeyboardConfiguration.hVZUSBMassStorageDeviceConfiguration.hVZUSBPassthroughDeviceConfiguration.hVZUSBScreenCoordinatePointingDeviceConfiguration.hVZVirtioBlockDeviceConfiguration.hVZVirtioConsoleDeviceConfiguration.hVZVirtioDeviceSpecificConfiguration.hVZVirtioEntropyDeviceConfiguration.hVZVirtioFileSystemDeviceConfiguration.hVZVirtioGraphicsDeviceConfiguration.hVZVirtioNetworkDeviceConfiguration.hVZVirtioSocketDeviceConfiguration.hVZVirtioSoundDeviceConfiguration.hVZVirtioTraditionalMemoryBalloonDeviceConfiguration.h
captured: real output, Apple M5 Pro, macOS 27.2.1, commit dad6c99, 2026-11-20
  • Read-only: the file names of the Virtualization.framework headers in the Xcode SDK on this Mac.
course/captures/23-vz-headers.txt

They fall into three groups:

  • Standard virtio: the VZVirtio* classes, documented in a public specification.
  • Other public standards: the Universal Serial Bus (USB) keyboard, pointing device and mass storage (VZUSB*), and the NVM Express (NVMe) disk controller; anyone can read their specifications.
  • Apple-specific: the VZMac* graphics, keyboard and trackpad, and the Mac platform identity behind them.

"Apple implemented it" and "Apple defined it" are different questions; only the second leaves a low-level VMM with no specification. Under the configuration sits a whole machine, generated privately: a memory map, PCIe, a GIC, a device tree, and for macOS a boot ROM, an identity tied to Apple's installer and an undocumented graphics protocol. The misconception, corrected: VZ supplies a complete machine, firmware and devices, much of it undocumented.

Production note

Low-level macOS guests do exist: QEMU's vmapple machine boots macOS on Hypervisor.framework by loading Apple's boot ROM from the host's Virtualization.framework and reimplementing Apple's devices from observation. Chapter 24 follows that road, as an investigation, not a promise.

Your turn

  1. Run tools/vz-mac/test.sh until it ends in VZ TESTS OK; the checkpoint below shows its five steps.
  2. In your journal, write a comparison table of VZ and your VMM in your own words, six rows at least: who defines the devices, the console, the memory map, who runs the exit loop, the entitlement, what a hostile guest attacks.
  3. Write your inventory in a file of your own, such as learner/docs/macos/inventory.md: one row per piece a low-level VMM must provide to boot macOS, with the VZ class or file that supplies it today, what you would build, and "documented" or "undocumented". Start from this chapter's three (the Mac platform identity, the boot ROM, the graphics device), add what the headers showed, then compare with the reference's docs/macos/inventory.md.

Checkpoint

Back at the repository root, run:

Checkpoint

Needs a Mac

Run this from the repository root:

scripts/checkpoint.sh 23

You should see, as the last line:

CHECKPOINT 23 PASS

The checkpoint runs vz-mac's acceptance test, tools/vz-mac/test.sh, then checks that every journal heading has an answer:

TerminalReal output
scripts/checkpoint.sh 23exit: 0--- stdout ---[INFO] contract tests   none for this chapter[PASS] runs on your Mac vz-acceptance: 10/10 serial markers, exit 0 in 8.55s[INFO] journal          not checked (not a learner tree)CHECKPOINT 23 PASS
captured: real output, Apple M5 Pro, macOS 27.2.1, commit dad6c99, 2026-11-20
  • The chapter's checkpoint against the reference: it runs tools/vz-mac/test.sh from the repository root, then would check your journal.
  • The journal line reports "not a learner tree" here; in your own learner/ workspace it checks your journal.
course/captures/23-checkpoint.txt

The test's five steps, as the checkpoint ran them:

TerminalReal output
tools/vz-mac/test.shexit: 0--- stdout ---== 1. swift test (host-only)Test run with 72 tests in 16 suites passed after 0.131 seconds.PASS swift_test== 2. vz_entitlements_exactbinary: <repo>/target/vz-mac/signed/vz-macentitlement: com.apple.security.virtualizationCodeDirectory v=20500 size=935 flags=0x10002(adhoc,runtime) hashes=19+7 location=embeddedPASS vz_entitlements_exact== 3. vz_breaks_without_entitlementvz-mac: configuration rejected by Virtualization.framework: "Invalid virtual machine configuration. The process doesn’t have the “com.apple.security.virtualization” entitlement. [VZErrorDomain 2]"PASS vz_breaks_without_entitlement (exit 1)== 4. vz_linux_dry_runvz-mac: configuration valid: linux, 2 vCPUs, 512 MiB, console hvc0PASS vz_linux_dry_run== 5. vz_linux_bootmacvmm-initramfs: ready 6.18.60-0-virt\rVZ guest state: startingVZ guest state: runningVZ guest state: stopped (guest)vz-mac: guest powered off (exit 0)PASS vz_linux_boot (exit 0, 0s)VZ TESTS OK--- stderr ---Building for production...Build complete! (0.15 sec)
captured: run "vz-acceptance" of checkpoint 23, captured from the reference on real hardwarecourse/captures/23-vz-acceptance.txt

Step 1 is 72 host-only tests (argument parsing, hostile inputs); step 2 checks vz-mac's signature and macvmm's entitlements file; steps 3 and 5 repeat this chapter's runs (no entitlement, the Linux boot); step 4 validates the Linux configuration without booting (--dry-run).

What now works:

  • you can run a VZ guest from the same kernel and initramfs as your VMM, and say why its console is hvc0;
  • you can show, with ps and codesign, that a VZ guest runs in Apple's service, which holds restricted entitlements you cannot get;
  • you have a comparison table and an inventory of what a macOS guest needs.

No Rust changed; chapter 24 starts from the reference at the end of chapter 23.

What's next

Chapter 24 takes the low road: a VMM of ours loads Apple's boot ROM in place from the host's Virtualization.framework, runs it on a second board, and records every access to a device it lacks. Your inventory is its map; its honest answer may be "not yet".

Open question

From your inventory, which three pieces will be hardest for a low-level VMM to provide, and is each one hard because it is complex or because it is undocumented?

Spec hunt

  • The SDK header VZMacPlatformConfiguration.h, the discussion above the class: what must be restored when a saved VM is loaded again, and what should differ between two VMs created from the same configuration?
  • The virtio 1.2 specification, section 4.1.2 "PCI Device Discovery", with the device ID table in chapter 5: why is the console 0x1043, and what PCI device ID would a virtio-blk disk have?
  • Linux Documentation/admin-guide/serial-console.rst: what does the kernel use as its console when the command line names none? Our VZ run with no console= word was silent, not printed on hvc0; which console registered first (look for the Console: line in course/captures/23-macvmm-shell.txt, a log with no early console), and why did it win?
Progress is stored only in this browser.