XNU as a loadable kernel module inside Linux (macOS personality for arm64 Linux)
C
fsck.hfsplus the system disk before each boot and before editing it (a hosted XNU never unmounts its rw root; a dirty volume failed to mount)
Heyang Zhouf3c37b14df9d
diff --git a/scripts/vm-m2-kbisect.sh b/scripts/vm-m2-kbisect.shindex 27c4984..474cd24 100755--- a/scripts/vm-m2-kbisect.sh+++ b/scripts/vm-m2-kbisect.sh@@ -6,6 +6,8 @@ make -s -C /lib/modules/$(uname -r)/build M=$PWD/xnu-ko clean >/dev/null 2>&1make -s -C /lib/modules/$(uname -r)/build M=$PWD/xnu-ko KBUILD_EXTRA_SYMBOLS=$PWD/fki-ko/Module.symvers modules >/dev/null 2>&1sudo dmesg -n ${CONLEVEL:-8}sudo rmmod xnu 2>/dev/null; sudo rmmod fki 2>/dev/null; sudo insmod fki-ko/fki.ko+# a hosted XNU never unmounts its read-write root: check the host disk before each boot+[ -n "$HOSTDISK" ] && sudo fsck.hfsplus -fy "$HOSTDISK" 2>&1 | tail -1for K in "$@"; dosudo dmesg -Cecho ">>> kmax=$K"; syncdiff --git a/scripts/vm-sysdisk-init.sh b/scripts/vm-sysdisk-init.shindex 2cc1fa7..882b935 100755--- a/scripts/vm-sysdisk-init.sh+++ b/scripts/vm-sysdisk-init.sh@@ -7,6 +7,7 @@ for f in start:init hello:hello; do$TC/target-clang -target arm64-apple-macos14.0 -c ${f%%:*}.s -o ${f%%:*}.o$TC/target-clang -target arm64-apple-macos14.0 -nostdlib -static -e _start -Wl,-adhoc_codesign ${f%%:*}.o -o ${f##*:} 2>&1 | grep -v "directory not found" || truedone-sudo mkdir -p /mnt/sys; sudo mount -o loop -t hfsplus $IMG /mnt/sys+sudo fsck.hfsplus -fy $IMG 2>&1 | tail -1+sudo mkdir -p /mnt/sys; sudo mount -o loop,rw -t hfsplus $IMG /mnt/syssudo cp init /mnt/sys/sbin/launchd; sudo cp hello /mnt/sys/sbin/hello; sudo chmod 755 /mnt/sys/sbin/launchd /mnt/sys/sbin/hellols -la /mnt/sys/sbin /mnt/sys/private/var/select; sudo umount /mnt/sysdiff --git a/scripts/vm-sysdisk-launchd.sh b/scripts/vm-sysdisk-launchd.shindex abb1cd1..0229d29 100755--- a/scripts/vm-sysdisk-launchd.sh+++ b/scripts/vm-sysdisk-launchd.sh@@ -3,7 +3,8 @@# local) at /sbin/launchd of the system disk; MODE=test puts the test init back.set -euo pipefailIMG=${IMG:-/var/tmp/sys.img}-sudo mkdir -p /mnt/sys; sudo mount -o loop -t hfsplus $IMG /mnt/sys+sudo fsck.hfsplus -fy $IMG 2>&1 | tail -1+sudo mkdir -p /mnt/sys; sudo mount -o loop,rw -t hfsplus $IMG /mnt/sysif [ "${MODE:-launchd}" = launchd ]; thensudo tar xf /var/tmp/launchd.tar -C /mnt/sys --warning=no-unknown-keywordsudo mkdir -p /mnt/sys/private/var/db /mnt/sys/private/var/run /mnt/sys/private/var/log /mnt/sys/private/etc /mnt/sys/Library