XNU as a loadable kernel module inside Linux (macOS personality for arm64 Linux)
C
XNU printf goes to the host too (os_log/console paths block this early)
Heyang Zhoubc86ecf44941
diff --git a/xnu-patches/0001-linux64-stage-hook.patch b/xnu-patches/0001-linux64-stage-hook.patchindex e938e9e..e5ab957 100644--- a/xnu-patches/0001-linux64-stage-hook.patch+++ b/xnu-patches/0001-linux64-stage-hook.patch@@ -1150,6 +1150,36 @@ index 0eae1f6..9a4e240 100644#if defined(__x86_64__) && (DEVELOPMENT || DEBUG)read_lbr();#endif+diff --git a/osfmk/kern/printf.c b/osfmk/kern/printf.c+index 2fc6931..19e5838 100644+--- a/osfmk/kern/printf.c++++ b/osfmk/kern/printf.c+@@ -876,6 +876,25 @@ __printflike(1, 0)+ static int+ vprintf_internal(const char *fmt, va_list ap_in, void *caller)+ {++ {++ /* LINUX64 (xnulinux): hosted XNU prints through the host (dmesg), like kprintf. */++ extern uintptr_t linux64_hook;++ if (linux64_hook && fmt) {++ char buf[256];++ va_list ap;++ va_copy(ap, ap_in);++ vsnprintf(buf, sizeof(buf), fmt, ap);++ va_end(ap);++ register unsigned long x0 __asm__("x0") = 998;++ register unsigned long x1 __asm__("x1") = (unsigned long)buf;++ register unsigned long x2 __asm__("x2") = 0;++ __asm__ volatile ("blr %3" : "+r"(x0), "+r"(x1), "+r"(x2) : "r"(linux64_hook)++ : "x3", "x4", "x5", "x6", "x7", "x8", "x9", "x10", "x11", "x12", "x13",++ "x14", "x15", "x16", "x17", "x30", "cc", "memory");++ (void)caller;++ return 0;++ }++ }+ if (fmt) {+ struct console_printbuf_state info_data;+diff --git a/pexpert/arm/pe_init.c b/pexpert/arm/pe_init.cindex b7134a6..e7d1c99 100644--- a/pexpert/arm/pe_init.c