Skip to content

Apple's open-source XNU kernel on Android phones: its own loader and drivers, Metal on the Adreno. Runs from RAM; a reboot gives the phone back to Android.

C

The keychain works, and a HackiOS pane in Settings

vcvkk5948df6262ff
diff --git a/prebuilt/SHA256SUMS b/prebuilt/SHA256SUMS
index e06707b..0830402 100644
--- a/prebuilt/SHA256SUMS
+++ b/prebuilt/SHA256SUMS
@@ -1,6 +1,6 @@
-Built 2026-10-14 21:30 from this tree.
+Built 2026-10-14 22:41 from this tree.
-fa8df870cfe5dc82fe0e1d9c9d85111c37ccd044ad8f3623daebcf1e2105c46b prebuilt/mach.development.bcm2837
+93d4fb49d14501253f5d9f55ab2c94633fb0bb94b367b97c833f97e18f786c49 prebuilt/mach.development.bcm2837
1332a598d2dec00a1d8e930044e4f00a12ad44c6e5e50eecf4b7fe7fae803bf2 prebuilt/loader.efi
d2a35a4a1d6658ffb3696914f727661b52c9333de8a3af8a31642b8023ce03ac prebuilt/userland/child
1a413befd511384052e1962c1394adce20f718e1f2657ce63ab09828ebc4bd1b prebuilt/userland/cpu_test
diff --git a/prebuilt/mach.development.bcm2837 b/prebuilt/mach.development.bcm2837
index ecc38f4..797d875 100755
Binary files a/prebuilt/mach.development.bcm2837 and b/prebuilt/mach.development.bcm2837 differ
diff --git a/xnu/files/bsd/dev/redwood_adreno.c b/xnu/files/bsd/dev/redwood_adreno.c
index 4d0a997..3ee1f18 100644
--- a/xnu/files/bsd/dev/redwood_adreno.c
+++ b/xnu/files/bsd/dev/redwood_adreno.c
@@ -99,6 +99,7 @@
#include <pexpert/pexpert.h>
#include <sys/redwood_input.h>
#include <sys/stat.h>
+#include <sys/sysctl.h>
#include <sys/systm.h>
#include <vm/vm_kern.h>
@@ -2311,6 +2312,9 @@ static struct block gpu = { "gpu", 0x03d00000, 0x40000 };
#define GMU_CORE_GRANTED (1u << 31) /* of gmu2host_intr_info */
static uint32_t core_khz; /* the 3D core's speed, as asked of the GMU */
+SYSCTL_DECL(_kern_redwood);
+SYSCTL_UINT(_kern_redwood, OID_AUTO, gpu_khz, CTLFLAG_RD | CTLFLAG_LOCKED, &core_khz, 0,
+ "the GPU's 3D core speed as asked of its GMU, in kHz (0: the GPU is not on)");
/*
* What the vendor's driver sends at this point (a6xx_hfi_start; Linux the same with fewer
diff --git a/xnu/files/bsd/dev/redwood_buttons.c b/xnu/files/bsd/dev/redwood_buttons.c
index 4ba54f4..4b9b69b 100644
--- a/xnu/files/bsd/dev/redwood_buttons.c
+++ b/xnu/files/bsd/dev/redwood_buttons.c
@@ -48,6 +48,7 @@
#include <mach/mach_types.h>
#include <pexpert/pexpert.h>
#include <sys/redwood_input.h>
+#include <sys/sysctl.h>
#include <sys/systm.h>
extern vm_offset_t ml_io_map(vm_offset_t phys_addr, vm_size_t size);
@@ -508,6 +509,11 @@ out:
thread_terminate(current_thread());
}
+static int buttons_on;
+SYSCTL_DECL(_kern_redwood);
+SYSCTL_INT(_kern_redwood, OID_AUTO, buttons, CTLFLAG_RD | CTLFLAG_LOCKED, &buttons_on, 0,
+ "1 if the power and volume keys' driver runs");
+
void
redwood_buttons_init(void)
{
@@ -532,6 +538,7 @@ redwood_buttons_init(void)
}
if (kernel_thread_start(buttons_thread, (void *)(uintptr_t)steps, &thread) == KERN_SUCCESS) {
thread_deallocate(thread);
+ buttons_on = 1;
}
}
diff --git a/xnu/files/bsd/dev/redwood_cpufreq.c b/xnu/files/bsd/dev/redwood_cpufreq.c
index 9d345de..0f90817 100644
--- a/xnu/files/bsd/dev/redwood_cpufreq.c
+++ b/xnu/files/bsd/dev/redwood_cpufreq.c
@@ -17,6 +17,7 @@
#include <machine/machine_routines.h>
#include <pexpert/pexpert.h>
#include <sys/redwood_input.h>
+#include <sys/sysctl.h>
#include <sys/systm.h>
extern vm_offset_t ml_io_map(vm_offset_t phys_addr, vm_size_t size);
@@ -53,6 +54,12 @@ domain_of(uint32_t phys_id)
return core < 4 ? 0 : core < 7 ? 1 : 2;
}
+/* the speed the group of the boot processor was raised to, for whoever asks (Settings' HackiOS pane): kHz, 0 when not */
+static int cpufreq_khz;
+SYSCTL_DECL(_kern_redwood);
+SYSCTL_INT(_kern_redwood, OID_AUTO, cpu_khz, CTLFLAG_RD | CTLFLAG_LOCKED, &cpufreq_khz, 0,
+ "the speed cpufreq=1 set the fastest group of processors to, in kHz (0: left as the boot loader left it)");
+
static void
raise_domain(uint32_t domain, uint32_t cores)
{
@@ -75,6 +82,9 @@ raise_domain(uint32_t domain, uint32_t cores)
delay_for_interval(20, NSEC_PER_MSEC);
printf("cpufreq: group %u (%u of our cores): row %u -> %u of the frequency table, %u MHz\n", domain, cores, was, top,
top_khz / 1000);
+ if ((int)top_khz > cpufreq_khz) {
+ cpufreq_khz = (int)top_khz;
+ }
}
void
diff --git a/xnu/files/bsd/dev/redwood_input.c b/xnu/files/bsd/dev/redwood_input.c
index 8ac7a2a..93c475a 100644
--- a/xnu/files/bsd/dev/redwood_input.c
+++ b/xnu/files/bsd/dev/redwood_input.c
@@ -10,6 +10,7 @@
#include <sys/errno.h>
#include <sys/proc.h>
#include <sys/redwood_input.h>
+#include <sys/sysctl.h>
#include <sys/systm.h>
#include <sys/uio.h>
@@ -34,13 +35,52 @@ static thread_call_t exit_call;
static uint32_t fingers_down; /* one bit for each finger a driver says is down */
static void
-exit_hold_elapsed(__unused thread_call_param_t p0, __unused thread_call_param_t p1)
+exit_hold_elapsed(thread_call_param_t p0, __unused thread_call_param_t p1)
{
- printf("\n--- %d fingers held on the screen for %d ms: back to the loader ---\n", EXIT_FINGERS, EXIT_HOLD_MS);
+ if (p0 != NULL) {
+ printf("\n--- asked for by %s: back to the loader ---\n", (const char *)p0);
+ } else {
+ printf("\n--- %d fingers held on the screen for %d ms: back to the loader ---\n", EXIT_FINGERS, EXIT_HOLD_MS);
+ }
redwood_adreno_stop();
loader_return();
}
+/*
+ * The same way out, asked for by a program (Settings' HackiOS pane: "Return to the loader", behind
+ * a confirmation): writing 1 to kern.redwood.leave. Anybody may, as anybody may hold five fingers
+ * on the screen.
+ */
+static int
+sysctl_leave(__unused struct sysctl_oid *oidp, __unused void *arg1, __unused int arg2, struct sysctl_req *req)
+{
+ static char who[32];
+ static thread_call_t leave_call;
+ int value = 0, error;
+
+ error = sysctl_handle_int(oidp, &value, 0, req);
+ if (error != 0 || req->newptr == USER_ADDR_NULL || value != 1) {
+ return error;
+ }
+ proc_selfname(who, sizeof(who));
+ if (leave_call == NULL) {
+ leave_call = thread_call_allocate(exit_hold_elapsed, who);
+ }
+ if (leave_call == NULL) {
+ return ENOMEM;
+ }
+ {
+ uint64_t deadline;
+
+ clock_interval_to_deadline(300, NSEC_PER_MSEC, &deadline); /* (the answer gets out first) */
+ thread_call_enter_delayed(leave_call, deadline);
+ }
+ return 0;
+}
+SYSCTL_DECL(_kern_redwood);
+SYSCTL_PROC(_kern_redwood, OID_AUTO, leave, CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_ANYBODY | CTLFLAG_LOCKED, NULL, 0, sysctl_leave,
+ "I", "write 1: end the run, back to the loader (as five fingers held on the screen)");
+
/* With touch_lock held. */
static void
count_fingers(uint32_t type, uint32_t finger)
diff --git a/xnu/files/bsd/dev/redwood_sta.c b/xnu/files/bsd/dev/redwood_sta.c
index f4e0490..f4bbbc1 100644
--- a/xnu/files/bsd/dev/redwood_sta.c
+++ b/xnu/files/bsd/dev/redwood_sta.c
@@ -26,6 +26,7 @@
#include <sys/errno.h>
#include <sys/redwood_input.h>
#include <sys/redwood_sta.h>
+#include <sys/sysctl.h>
#include <sys/systm.h>
extern void thread_set_thread_name(thread_t thread, const char *name);
@@ -369,3 +370,47 @@ redwood_sta_address(uint8_t *address)
}
return ops != NULL;
}
+
+/* For whoever asks (Settings' HackiOS pane): "none" (no radio), "off" (turned off), "on", "joining", "joined". */
+static int
+sysctl_wifi(__unused struct sysctl_oid *oidp, __unused void *arg1, __unused int arg2, struct sysctl_req *req)
+{
+ struct redwood_sta_state *state = kalloc_data(sizeof(*state), Z_WAITOK | Z_ZERO);
+ const char *text = "none";
+ int error;
+
+ if (state == NULL) {
+ return ENOMEM;
+ }
+ if (redwood_sta_present()) {
+ redwood_sta_state(state);
+ text = !redwood_sta_powered() ? "off" : state->phase == REDWOOD_STA_JOINED ? "joined" : state->phase ==
+ REDWOOD_STA_JOINING ? "joining" : "on";
+ }
+ kfree_data(state, sizeof(*state));
+ error = SYSCTL_OUT(req, text, strlen(text) + 1);
+ return error;
+}
+SYSCTL_DECL(_kern_redwood);
+SYSCTL_PROC(_kern_redwood, OID_AUTO, wifi, CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_LOCKED, NULL, 0, sysctl_wifi, "A",
+ "the phone's radio: none, off, on, joining, joined");
+
+/* ... and how strongly the network joined is heard: dBm, 0 when none is joined */
+static int
+sysctl_wifi_rssi(__unused struct sysctl_oid *oidp, __unused void *arg1, __unused int arg2, struct sysctl_req *req)
+{
+ struct redwood_sta_state *state = kalloc_data(sizeof(*state), Z_WAITOK | Z_ZERO);
+ int rssi = 0;
+
+ if (state == NULL) {
+ return ENOMEM;
+ }
+ if (redwood_sta_present()) {
+ redwood_sta_state(state);
+ rssi = state->phase == REDWOOD_STA_JOINED ? state->bss.rssi : 0;
+ }
+ kfree_data(state, sizeof(*state));
+ return SYSCTL_OUT(req, &rssi, sizeof(rssi));
+}
+SYSCTL_PROC(_kern_redwood, OID_AUTO, wifi_rssi, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_LOCKED, NULL, 0, sysctl_wifi_rssi, "I",
+ "how strongly the network joined is heard, dBm (0: none joined)");
diff --git a/xnu/files/iokit/Kernel/MiniAppleKeyStore.cpp b/xnu/files/iokit/Kernel/MiniAppleKeyStore.cpp
index 13be44b..f0e367a 100644
--- a/xnu/files/iokit/Kernel/MiniAppleKeyStore.cpp
+++ b/xnu/files/iokit/Kernel/MiniAppleKeyStore.cpp
@@ -4,8 +4,13 @@
* and libaks.
*
* It describes one fixed situation: a device that has no passcode -- never locked, unlocked
- * since boot. Nothing is encrypted here and no keys exist; requests that would need them
- * (wrapping keys for the keychain, creating or loading bags) are refused, logged once.
+ * since boot. No keys exist here. The keychain (securityd) gives every item a key of its own and
+ * has it wrapped by the key of the item's protection class (kAKSWrapKey) before it stores it, and
+ * unwrapped (kAKSUnwrapKey) to read the item: that is answered, so that the keychain works -- but
+ * with nothing secret to wrap with, the "wrapping" is a reversible transformation and protects
+ * nothing (and the keychain lives in /private/var, in memory, and is gone at the next start).
+ * Requests that would need real keys or bags otherwise (creating or loading bags, keys kept in the
+ * key store) are refused, logged once.
*
* The protocol was worked out from the user-space side of iOS 16.5: selectors, and the
* DER-encoded answers ("SET of SEQUENCE { UTF8String key, INTEGER value }").
@@ -26,6 +31,8 @@ enum {
kAKSGetLockState = 0x07, /* in: handle; out: state flags */
kAKSLockDevice = 0x08,
kAKSUnlockDevice = 0x09,
+ kAKSWrapKey = 0x0a, /* in: handle, class; a key; out: the class, the key wrapped */
+ kAKSUnwrapKey = 0x0b, /* in: handle, class; a wrapped key; out: the key */
kAKSUnlockBag = 0x0c,
kAKSGetSystem = 0x0e, /* out: the handle of the system keybag */
kAKSGetDeviceState = 0x11, /* in: handle; out: DER */
@@ -158,6 +165,21 @@ AppleKeyStoreUserClient::registerNotificationPort(mach_port_t port, UInt32 type,
return kIOReturnSuccess;
}
+/*
+ * kAKSWrapKey and kAKSUnwrapKey. A wrapped key is 8 bytes longer than the key, as with AES key
+ * wrap (RFC 3394), which is what callers size their buffers for: a mark, the class, and the key
+ * mixed with a fixed pattern. Not encryption: there is no secret here to encrypt with.
+ */
+static const uint8_t kWrapMark[4] = { 'H', 'K', 'w', 'r' };
+
+static void
+wrapMix(uint8_t * bytes, size_t length)
+{
+ for (size_t i = 0; i < length; i++) {
+ bytes[i] ^= (uint8_t)(0x5a + 37 * i);
+ }
+}
+
/* A structure answer; a big buffer on the other side arrives as a memory descriptor. */
IOReturn
AppleKeyStoreUserClient::answer(IOExternalMethodArguments * args, const uint8_t * bytes, size_t length)
@@ -236,6 +258,38 @@ AppleKeyStoreUserClient::externalMethod(uint32_t selector, IOExternalMethodArgum
gAKSNotifyState = true;
return kIOReturnSuccess;
+ case kAKSWrapKey: {
+ uint8_t wrapped[8 + 64];
+ size_t length = args->structureInputSize;
+
+ if (args->structureInput == NULL || length == 0 || length > 64 || args->scalarInputCount < 2) {
+ return kIOReturnBadArgument;
+ }
+ memcpy(wrapped, kWrapMark, sizeof(kWrapMark));
+ wrapped[4] = (uint8_t)args->scalarInput[1];
+ wrapped[5] = wrapped[6] = wrapped[7] = 0;
+ memcpy(wrapped + 8, args->structureInput, length);
+ wrapMix(wrapped + 8, length);
+ if (args->scalarOutputCount >= 1) {
+ out[0] = args->scalarInput[1];
+ args->scalarOutputCount = 1;
+ }
+ return answer(args, wrapped, 8 + length);
+ }
+
+ case kAKSUnwrapKey: {
+ uint8_t key[64];
+ const uint8_t * wrapped = (const uint8_t *)args->structureInput;
+ size_t length = args->structureInputSize;
+
+ if (wrapped == NULL || length <= 8 || length > 8 + sizeof(key) || memcmp(wrapped, kWrapMark, sizeof(kWrapMark)) != 0) {
+ return kIOReturnBadArgument;
+ }
+ memcpy(key, wrapped + 8, length - 8);
+ wrapMix(key, length - 8);
+ return answer(args, key, length - 8);
+ }
+
case kAKSNotifyStateIsSet:
if (args->scalarOutputCount < 1) {
return kIOReturnBadArgument;