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.shindex 9452547..0e57f1d 100755--- a/scripts/install-service.sh+++ b/scripts/install-service.sh@@ -31,7 +31,7 @@ WorkingDirectory=$PExecStart=$P/scripts/xnulinux-boot.sh --waitExecStop=$P/scripts/xnulinux-boot.sh stopTimeoutStartSec=infinity-TimeoutStopSec=60+TimeoutStopSec=180Restart=on-failureRestartSec=10StartLimitIntervalSec=600diff --git a/scripts/xnulinux-boot.sh b/scripts/xnulinux-boot.shindex 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 filsmod | grep -q '^xnu ' || { echo "no hosted system is running"; exit 0; }printf 'sync\n' >> "${CONSOLE_IN:-/var/tmp/console-in}"; sleep 3echo 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"exitfiWAIT=0; [ "${1:-}" = --wait ] && WAIT=1