XNU as a loadable kernel module inside Linux (macOS personality for arm64 Linux)
C
PureDarwin from the fork AFK-surf/PureDarwin (#27)
CommaBotcf3399e90d72
diff --git a/docs/free-kc.md b/docs/free-kc.mdindex 09a76d9..4c2a4df 100644--- a/docs/free-kc.md+++ b/docs/free-kc.md@@ -4,7 +4,11 @@The kernel collection `scripts/vm-xnu-rebuild.sh` links is the source-built XNU and xnulinux's own kexts, plus Apple'skexts from a macOS kernelcache (APFS, AMFI, IOKit families...). `scripts/free-kc/build.sh` links one with none ofApple's kexts. That collection boots [PureDarwin](https://github.com/PureDarwin/PureDarwin)'s arm64 userland (its own-dyld, libSystem, launchd, zsh and toybox) to its console shell.+dyld, libSystem, launchd, zsh and toybox) to its console shell. xnulinux takes PureDarwin from its fork+[AFK-surf/PureDarwin](https://github.com/AFK-surf/PureDarwin), which has what this kernel needs of the userland:+`posix_spawnattr_init` zeroes the attributes (otherwise launchd's children come up with the resource limits `malloc` left+in them, a file descriptor hard limit of a few, and are killed when they pass it), and ICU's libraries are signed after+their install names change (otherwise their first page fails validation in every process that maps them).## What is in it@@ -35,8 +39,10 @@ kernel has; and a kext's load tag.## Using it-1. `scripts/puredarwin-root.sh IMAGE root.tar.gz` (Linux) unpacks the root of a PureDarwin arm64 image, for example- `nix build github:PureDarwin/PureDarwin#image-arm64-virt-minimal`.+1. `scripts/puredarwin-root.sh IMAGE root.tar.gz` (Linux) unpacks the root of a PureDarwin arm64 image:+ `nix build 'git+https://github.com/AFK-surf/PureDarwin?submodules=1&rev=b3b4b2812fdd1c5c251dc3089b5a1a9e00d29970#image-arm64-virt-minimal'` (PureDarwin's+ binary cache, https://hydra.lab004.dev, has its toolchain and what the fork did not change; the images there are+ upstream's).2. `scripts/mk-puredarwin-disk.sh root.tar.gz pd.img > pd.conf` (Mac) makes the HFS+ disk and prints its UUIDs.3. In the VM, after `scripts/vm-xnu-rebuild.sh`: `scripts/free-kc/build.sh`, which writes `/lib/firmware/xnu/kc-free.bin`.4. Boot it: `MAC_CONF=pd.conf DISK=pd.img IMAGE=xnu/kc-free.bin TRUSTCACHE= GPU=off scripts/xnulinux-boot.sh`. The consolediff --git a/scripts/free-kc/build.sh b/scripts/free-kc/build.shindex 34bf106..e8d1112 100755--- a/scripts/free-kc/build.sh+++ b/scripts/free-kc/build.sh@@ -13,7 +13,7 @@set -euo pipefailPOC=$(cd "$(dirname "$0")/../.." && pwd)DVM=${DVM:-$HOME/w/dvm}; W=${FREE_KC_WORK:-$HOME/w/free-kc}; OUT=${OUT:-/lib/firmware/xnu/kc-free.bin}-PD_URL=https://github.com/PureDarwin/PureDarwin PD_REV=0c1990c803c13b68cad4df3f6dc34ba4306fc789+PD_URL=https://github.com/AFK-surf/PureDarwin PD_REV=b3b4b2812fdd1c5c251dc3089b5a1a9e00d29970MBEDTLS_URL=https://github.com/Mbed-TLS/mbedtls MBEDTLS_REV=$(sed -n 's/^MBEDTLS_REV=//p' $POC/kexts/free/corecrypto/mbedtls.rev)export DVM NETINC=${NETINC:-$POC/build/netinc}K="python3 $POC/scripts/free-kc/kcc.py --macos"; O=$W/obj; S=$W/src; F=$POC/kexts/freediff --git a/scripts/puredarwin-root.sh b/scripts/puredarwin-root.shindex 833a6ae..b6f261e 100755--- a/scripts/puredarwin-root.sh+++ b/scripts/puredarwin-root.sh@@ -1,7 +1,7 @@#!/bin/bash# SPDX-License-Identifier: GPL-2.0-only-# On a Linux host: PureDarwin's arm64 root file system as a tarball, from one of its disk images (Nix: .#image-arm64-virt-minimal,-# or the release puredarwin-arm64-virt-minimal-*.img.zst from hydra.lab004.dev). The image's root is the GPT partition+# On a Linux host: PureDarwin's arm64 root file system as a tarball, from one of its disk images (Nix: .#image-arm64-virt-minimal+# of the fork AFK-surf/PureDarwin, docs/free-kc.md; hydra.lab004.dev's release images are upstream's, without its fixes). The image's root is the GPT partition# "Darwin ext4 Root"; owners and modes are kept.# puredarwin-root.sh IMAGE OUT.tar.gzset -euo pipefail