XNU as a loadable kernel module inside Linux (macOS personality for arm64 Linux)
C
Hosted macOS is online at boot: LaunchDaemon xnulinux.network runs /Library/xnulinux/net-up.sh (en0 192.168.77.2/24, default route and DNS through Linux's xnu0, set with scutil since configd only manages IOKit-backed interfaces)
Heyang Zhou065c7ca8445b
diff --git a/scripts/vm-sysdisk-launchd.sh b/scripts/vm-sysdisk-launchd.shindex 0bac18d..c599d8d 100755--- a/scripts/vm-sysdisk-launchd.sh+++ b/scripts/vm-sysdisk-launchd.sh@@ -86,6 +86,14 @@ GP</dict></plist>PL+ # en0 (XNU's link to the host's xnu0): address, route and DNS at boot (tools/hosted/net-up.sh)+ sudo mkdir -p /mnt/sys/Library/xnulinux+ sudo install -m 755 ~/w/poc/tools/hosted/net-up.sh /mnt/sys/Library/xnulinux/net-up.sh+ sudo python3 - <<'PY'+import plistlib+plistlib.dump({"Label": "xnulinux.network", "RunAtLoad": True, "ProgramArguments": ["/bin/sh", "/Library/xnulinux/net-up.sh"]},+ open("/mnt/sys/System/Library/LaunchDaemons/xnulinux.network.plist", "wb"))+PY# xcodebuild test needs the per-user agent com.apple.testmanagerd, which macOS limits to Aqua/LoginWindow sessions;# the headless system has none: a copy limited to Background sessions, bootstrapped into root's user domain at boot.if [ -e /mnt/sys/System/Library/LaunchAgents/com.apple.testmanagerd.plist ]; thendiff --git a/tools/hosted/net-up.sh b/tools/hosted/net-up.shnew file mode 100644index 0000000..ac92efd--- /dev/null+++ b/tools/hosted/net-up.sh@@ -0,0 +1,25 @@+#!/bin/sh+# In the hosted macOS, at boot (launchd job xnulinux.network): en0 is XNU's link to the host's xnu0 (bsd/net/if_linux64.c).+# configd's IPConfiguration does not manage it (no IOKit interface behind it), so configure it here: address, default+# route, and the DNS/IPv4 state mDNSResponder resolves through (it does not read /etc/resolv.conf).+ADDR=192.168.77.2 GW=192.168.77.1 DNS=192.168.77.1+for i in $(seq 1 60); do ifconfig en0 >/dev/null 2>&1 && scutil -r $GW >/dev/null 2>&1 && break; sleep 1; done+ifconfig en0 inet $ADDR netmask 255.255.255.0 up+route -n delete default >/dev/null 2>&1; route -n add default $GW+scutil <<EOS+d.init+d.add ServerAddresses * $DNS+set State:/Network/Service/xnulinux/DNS+d.init+d.add Router $GW+d.add Addresses * $ADDR+d.add SubnetMasks * 255.255.255.0+d.add InterfaceName en0+set State:/Network/Service/xnulinux/IPv4+d.init+d.add PrimaryService xnulinux+d.add PrimaryInterface en0+d.add Router $GW+set State:/Network/Global/IPv4+EOS+echo "xnulinux: en0 $ADDR via $GW, DNS $DNS" > /dev/console