Skip to content

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

C

Debug: steps of linux64_el0_exception (dbg[15]) and a kprintf per EL0 exception

Heyang Zhou6fce44f86a46
diff --git a/xnu-ko/xnu_main.c b/xnu-ko/xnu_main.c
index ef0fe36..aa05527 100644
--- a/xnu-ko/xnu_main.c
+++ b/xnu-ko/xnu_main.c
@@ -469,8 +469,8 @@ static int monitor_fn(void *arg)
while (*h) *p++ = *h++;
p = put_dec(p, xnu_dbg[10]);
{
- static const char *const k[] = { " esr=0x", " far=0x", " pc=0x", " bad_esr=0x", " bad_elr=0x" };
- for (int j = 0; j < 5; j++) {
+ static const char *const k[] = { " esr=0x", " far=0x", " pc=0x", " bad_esr=0x", " bad_elr=0x", " step=0x" };
+ for (int j = 0; j < 6; j++) {
for (h = k[j]; *h; h++) *p++ = *h;
for (int i = 44; i >= 0; i -= 4) *p++ = "0123456789abcdef"[(xnu_dbg[11 + j] >> i) & 15];
}
diff --git a/xnu-patches/0001-linux64-stage-hook.patch b/xnu-patches/0001-linux64-stage-hook.patch
index 3e0ba20..74fbfc1 100644
--- a/xnu-patches/0001-linux64-stage-hook.patch
+++ b/xnu-patches/0001-linux64-stage-hook.patch
@@ -1764,10 +1764,10 @@ index d211433..dc247da 100644
// No need for atomic - These are per CPU and interrupts are disabled
diff --git a/osfmk/arm64/sleh.c b/osfmk/arm64/sleh.c
-index d8f1b19..4fef008 100644
+index d8f1b19..3baaa28 100644
--- a/osfmk/arm64/sleh.c
+++ b/osfmk/arm64/sleh.c
-@@ -3646,3 +3646,111 @@ sleh_panic_lockdown_should_initiate_el1_sp0_sync(uint64_t esr, uint64_t elr,
+@@ -3646,3 +3646,116 @@ sleh_panic_lockdown_should_initiate_el1_sp0_sync(uint64_t esr, uint64_t elr,
}
__SECURITY_STACK_DISALLOWED_POP
#endif /* CONFIG_SPTM */
@@ -1868,15 +1868,20 @@ index d8f1b19..4fef008 100644
+ linux64_dbg[11] = f->esr;
+ linux64_dbg[12] = f->far;
+ linux64_dbg[13] = f->pc;
++ linux64_dbg[15] = 1;
++ kprintf("linux64: EL0 exception esr 0x%llx far 0x%llx pc 0x%llx x16 %lld\n", f->esr, f->far, f->pc, f->x[16]);
+ for (unsigned i = 0; i < 29; i++) {
+ set_saved_state_reg(ss, i, f->x[i]);
+ }
++ linux64_dbg[15] = 2;
+ set_saved_state_fp(ss, f->x[29]);
+ set_saved_state_lr(ss, f->x[30]);
+ set_saved_state_sp(ss, f->sp);
+ set_saved_state_pc(ss, f->pc);
+ set_saved_state_cpsr(ss, (uint32_t)f->cpsr);
++ linux64_dbg[15] = 3;
+ sleh_synchronous(thread->machine.contextData, f->esr, (vm_offset_t)f->far, false);
++ linux64_dbg[15] = 4;
+ thread_exception_return();
+}
diff --git a/osfmk/arm64/status.c b/osfmk/arm64/status.c