Skip to content

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

C

idle_max

Heyang Zhou1e75004e5e2b
diff --git a/scripts/vm-m2-kbisect.sh b/scripts/vm-m2-kbisect.sh
index 60c44a2..517b1e8 100755
--- a/scripts/vm-m2-kbisect.sh
+++ b/scripts/vm-m2-kbisect.sh
@@ -8,7 +8,7 @@ sudo rmmod xnu 2>/dev/null; sudo rmmod fki 2>/dev/null; sudo insmod fki-ko/fki.k
for K in "$@"; do
sudo dmesg -C
echo ">>> kmax=$K"; sync
- sudo insmod xnu-ko/xnu.ko mode=3 stop=899 kmax=$K ram_mb=${RAM_MB:-128}
+ sudo insmod xnu-ko/xnu.ko mode=3 stop=899 kmax=$K idle_max=${IDLE_MAX:-200} ram_mb=${RAM_MB:-128}
sudo dmesg | grep -a "xnu\]\|XNU stage 4\|budget\|panic\|run ended" | tail -${SHOW:-4}
sudo rmmod xnu
done
diff --git a/xnu-ko/xnu_main.c b/xnu-ko/xnu_main.c
index 4b26bfa..c5a491c 100644
--- a/xnu-ko/xnu_main.c
+++ b/xnu-ko/xnu_main.c
@@ -26,6 +26,8 @@ module_param(ram_mb, int, 0444);
static int kmax; /* end the run after this many XNU kprintf lines (0: no limit) */
module_param(kmax, int, 0444);
static int kcount;
+static int idle_max = 200; /* end the run after this many XNU idle rounds (0: never) */
+module_param(idle_max, int, 0444);
static struct xnu_image img;
static struct fki_region l2page;
@@ -159,7 +161,7 @@ long xnu_hook(unsigned long stage, unsigned long a1, unsigned long a2)
static unsigned long idles;
if ((++idles & (idles - 1)) == 0) logkv("xnu: XNU idle, count", idles);
fki_idle_until(a1, 20000000ULL); /* at most 20 ms per round */
- return (long)stop == 810 && idles >= (unsigned long)(kmax ? kmax : 1);
+ return idle_max && idles >= (unsigned long)idle_max;
}
if (stage == 999) {
char m[200]; const char *f = (const char *)a1; unsigned i = 0;