Skip to content

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

C

XNU patch: a hosted root mounts read-write (no boot task remounts it; logd trapped on EROFS)

Heyang Zhou2f09507e957c
diff --git a/xnu-patches/0001-linux64-stage-hook.patch b/xnu-patches/0001-linux64-stage-hook.patch
index 64eb04e..7007fc4 100644
--- a/xnu-patches/0001-linux64-stage-hook.patch
+++ b/xnu-patches/0001-linux64-stage-hook.patch
@@ -336,6 +336,26 @@ index e5e58b5..6e6596d 100644
pthread_functions->pth_proc_hashinit(p);
}
+diff --git a/bsd/vfs/vfs_subr.c b/bsd/vfs/vfs_subr.c
+index 229d6a1..e610b22 100644
+--- a/bsd/vfs/vfs_subr.c
++++ b/bsd/vfs/vfs_subr.c
+@@ -1144,7 +1144,14 @@ vfs_rootmountalloc_internal(struct vfstable *vfsp, const char *devname)
+
+ mp->mnt_vtable = vfsp;
+ mp->mnt_op = vfsp->vfc_vfsops;
+- mp->mnt_flag = MNT_RDONLY | MNT_ROOTFS;
++ {
++ /*
++ * LINUX64 (xnulinux): a hosted root (the host-file disk) mounts read-write; nothing here runs the boot tasks
++ * that would remount it (logd traps on EROFS writing /private/var/db/diagnostics).
++ */
++ extern uintptr_t linux64_hook;
++ mp->mnt_flag = (linux64_hook ? 0 : MNT_RDONLY) | MNT_ROOTFS;
++ }
+ mp->mnt_vnodecovered = NULLVP;
+ //mp->mnt_stat.f_type = vfsp->vfc_typenum;
+ mp->mnt_flag |= vfsp->vfc_flags & MNT_VISFLAGMASK;
diff --git a/bsd/vm/vm_unix.c b/bsd/vm/vm_unix.c
index d8fd4af..815051f 100644
--- a/bsd/vm/vm_unix.c