Skip to content

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

C

xnulinux-boot.sh stop: wait up to 2 min for every XNU CPU to see the stop (a VM shutdown found one in a long host call)

Heyang Zhou094c401cfc29
diff --git a/scripts/install-service.sh b/scripts/install-service.sh
index 9452547..0e57f1d 100755
--- a/scripts/install-service.sh
+++ b/scripts/install-service.sh
@@ -31,7 +31,7 @@ WorkingDirectory=$P
ExecStart=$P/scripts/xnulinux-boot.sh --wait
ExecStop=$P/scripts/xnulinux-boot.sh stop
TimeoutStartSec=infinity
-TimeoutStopSec=60
+TimeoutStopSec=180
Restart=on-failure
RestartSec=10
StartLimitIntervalSec=600
diff --git a/scripts/xnulinux-boot.sh b/scripts/xnulinux-boot.sh
index 1f8e3e6..556a7c0 100755
--- a/scripts/xnulinux-boot.sh
+++ b/scripts/xnulinux-boot.sh
@@ -20,8 +20,10 @@ if [ "${1:-}" = stop ]; then # end the running hosted system (its disk synced fi
lsmod | grep -q '^xnu ' || { echo "no hosted system is running"; exit 0; }
printf 'sync\n' >> "${CONSOLE_IN:-/var/tmp/console-in}"; sleep 3
echo 1 | sudo tee /sys/module/xnu/parameters/stop_run >/dev/null
- for _ in $(seq 1 50); do pgrep -x insmod >/dev/null || break; sleep 0.2; done
- sudo rmmod xnu && echo "hosted system stopped"
+ # every XNU CPU sees the stop at its next host call; one in a long one (disk I/O while the VM shuts down) takes a while
+ for _ in $(seq 1 600); do pgrep -f "insmod xnu-ko/xnu.ko" >/dev/null || break; sleep 0.2; done
+ if lsmod | grep -q '^xnu '; then sudo rmmod xnu; fi
+ echo "hosted system stopped"
exit
fi
WAIT=0; [ "${1:-}" = --wait ] && WAIT=1