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
systrace: print the policy and request of __mac_syscall, and the MIB of sysctl
vcvkke7675929f614
diff --git a/xnu/redwood.patch b/xnu/redwood.patchindex 417deb3..8f7dd87 100644--- a/xnu/redwood.patch+++ b/xnu/redwood.patch@@ -174,10 +174,10 @@ index fd7a94b20794..69eaceedd248 100644if (cc > 1) {console_write((char *)buf, cc);diff --git a/bsd/dev/arm/systemcalls.c b/bsd/dev/arm/systemcalls.c-index 7fd9be1a5f38..231a58c622db 100644+index 7fd9be1a5f38..0d035255b030 100644--- a/bsd/dev/arm/systemcalls.c+++ b/bsd/dev/arm/systemcalls.c-@@ -36,6 +36,58 @@+@@ -36,6 +36,92 @@#include <security/mac_framework.h>#endif@@ -207,6 +207,17 @@ index 7fd9be1a5f38..231a58c622db 100644+ SYS_getattrlistat, SYS_mkdirat, SYS_unlinkat,+ };+ char path[160] = "";++ /*++ * Two calls are worth more than their arguments' addresses, because what they ASK is the whole++ * of what they do. __mac_syscall carries the policy's name and the request number: this++ * kernel's AMFI stand-in answers only 0x5a and 0x60 and returns ENOPOLICY to anything else++ * (bsd/kern/kern_minimac.c), so a daemon refused there is refused in a way nothing in user++ * space can see -- and a library of ours cannot watch it either, since the call is made inside++ * libsystem and dyld interposing only stands between images. The name matters as much as the++ * number: the same call goes to Sandbox as well. And sysctl carries its MIB, which is the only++ * thing that says what was asked about.++ */++ char detail[112] = "";+ size_t done;++ if (systrace_level < 2 && (error == 0 || error == EJUSTRETURN || error == ERESTART)) {@@ -226,17 +237,40 @@ index 7fd9be1a5f38..231a58c622db 100644+ }+ }+ path[sizeof(path) - 1] = 0;-+ printf("systrace: %s[%d] %s(0x%llx, 0x%llx, 0x%llx, 0x%llx)%s%s%s = %d\n",++ if (syscode == SYS___mac_syscall) {++ char policy[32] = "";++++ (void)copyinstr((user_addr_t)uthread->uu_arg[0], policy, sizeof(policy), &done);++ policy[sizeof(policy) - 1] = 0;++ snprintf(detail, sizeof(detail), " policy \"%s\" request %lld", policy,++ (long long)uthread->uu_arg[1]);++ } else if (syscode == SYS_sysctl) {++ int mib[6];++ unsigned count = (unsigned)uthread->uu_arg[1];++++ if (count > 6) {++ count = 6;++ }++ if (count > 0 && copyin((user_addr_t)uthread->uu_arg[0], mib, count * sizeof(mib[0])) == 0) {++ size_t used = (size_t)snprintf(detail, sizeof(detail), " mib");++++ for (unsigned i = 0; i < count && used + 12 < sizeof(detail); i++) {++ used += (size_t)snprintf(detail + used, sizeof(detail) - used, " %d", mib[i]);++ }++ }++ }++ detail[sizeof(detail) - 1] = 0;++ printf("systrace: %s[%d] %s(0x%llx, 0x%llx, 0x%llx, 0x%llx)%s%s%s%s = %d\n",+ proc->p_comm, proc_getpid(proc), syscallnames[syscode],+ (unsigned long long)uthread->uu_arg[0], (unsigned long long)uthread->uu_arg[1],+ (unsigned long long)uthread->uu_arg[2], (unsigned long long)uthread->uu_arg[3],-+ path[0] ? " \"" : "", path, path[0] ? "\"" : "", error);++ path[0] ? " \"" : "", path, path[0] ? "\"" : "", detail, error);+}+#if CONFIG_DTRACEextern int32_t dtrace_systrace_syscall(struct proc *, void *, int *);extern void dtrace_systrace_syscall_return(unsigned short, int, int *);-@@ -181,6 +233,10 @@ unix_syscall(+@@ -181,6 +267,10 @@ unix_syscall(error = (*(callp->sy_call))(proc, &uthread->uu_arg[0], &(uthread->uu_rval[0]));AUDIT_SYSCALL_EXIT(code, proc, uthread, error);