Skip to content

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

C

fki_log_alert: an XNU panic and a silent XNU CPU reach the console even when it is quiet

Heyang Zhouafbaba7c07ca
diff --git a/fki-ko/fki.h b/fki-ko/fki.h
index 3d6e657..20f403e 100644
--- a/fki-ko/fki.h
+++ b/fki-ko/fki.h
@@ -39,6 +39,7 @@ extern "C" {
#endif
int fki_version(void);
void fki_log(const char *s, unsigned long len);
+void fki_log_alert(const char *s, unsigned long len); /* KERN_ALERT: on the console even when it is quiet */
int fki_region_alloc(unsigned long size, struct fki_region *r);
void fki_region_free(struct fki_region *r);
/* A named blob from the firmware search path. */
diff --git a/fki-ko/fki_mod.c b/fki-ko/fki_mod.c
index 08788b5..b53aad7 100644
--- a/fki-ko/fki_mod.c
+++ b/fki-ko/fki_mod.c
@@ -51,6 +51,12 @@ void fki_log(const char *s, unsigned long len)
pr_info("fki: %.*s\n", (int)len, s);
}
EXPORT_SYMBOL(fki_log);
+/* what an operator must see even with the console quiet (an XNU panic, a CPU gone silent): KERN_ALERT */
+void fki_log_alert(const char *s, unsigned long len)
+{
+ pr_alert("fki: %.*s\n", (int)len, s);
+}
+EXPORT_SYMBOL(fki_log_alert);
/*
diff --git a/xnu-ko/xnu_main.c b/xnu-ko/xnu_main.c
index 627fa73..0c62269 100644
--- a/xnu-ko/xnu_main.c
+++ b/xnu-ko/xnu_main.c
@@ -138,6 +138,7 @@ static void *in_file; static fki_u64 in_off;
struct xnu_world xnu_W;
static void logs(const char *s) { fki_log(s, x_strlen(s)); }
+static void logs_alert(const char *s) { fki_log_alert(s, x_strlen(s)); }
static void logkv(const char *k, u64_t v)
{
char buf[96]; char *p = buf;
@@ -641,8 +642,8 @@ static long xnu_hook_body(unsigned long call, unsigned long a1, unsigned long a2
char m[500]; const char *f = (const char *)a1; unsigned i = 0;
while (f && f[i] && i < sizeof(m) - 1) { m[i] = f[i]; i++; }
m[i] = 0;
- logs("xnu: XNU panic:");
- logs(m);
+ logs_alert("xnu: XNU panic:");
+ logs_alert(m);
logkv("xnu: panic caller", a2);
{ /* the frame-pointer chain from here through XNU's frames (the hook runs on XNU's stack); return addresses
* with their pointer-authentication bits replaced by the kernel's all-ones top */
@@ -998,6 +999,14 @@ static int monitor_fn(void *arg)
if (++still[c] == 1) {
struct xnu_world *w = xnu_worlds[s];
unsigned long fp = w->xnu_regs[10];
+ {
+ char ab[160]; char *q = ab;
+ put_str(&q, "xnu: XNU CPU "); q = put_dec(q, (unsigned long)c);
+ put_str(&q, " made no host call for 2 s (its Linux CPU held, interrupts masked); last call ");
+ q = put_dec(q, last_call_slot[s]); put_str(&q, in_call_slot[s] ? " (inside it)" : " (back in XNU)");
+ *q = 0;
+ logs_alert(ab);
+ }
logkv("xnu: XNU CPU silent for 2 s (no host call), cpu", (u64_t)c);
logkv("xnu: its last host call", last_call_slot[s]);
logkv("xnu: still inside it (1) or back in XNU (0)", in_call_slot[s]);