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 stock wallpaper: mediaserverd runs, and decodes its pictures
vcvkkac3f77e6839e
diff --git a/README.md b/README.mdindex 298b82e..2e83866 100644--- a/README.md+++ b/README.md@@ -21,8 +21,8 @@| Работает | Не работает ||---|---|-| Экран блокировки, разблокировка свайпом, домашний экран с полным набором значков (две страницы) | Звук, сеть (Wi-Fi/сотовая), Bluetooth, камера |-| Системные жесты: свайп снизу — «домой» и переключатель приложений, свайп от левого края — «назад», Пункт управления | Обои: от стандартных пока рисуется только градиент, без картинок |+| Экран блокировки, разблокировка свайпом, домашний экран с полным набором значков (две страницы), стандартные обои iOS 16 | Звук, сеть (Wi-Fi/сотовая), Bluetooth, камера |+| Системные жесты: свайп снизу — «домой» и переключатель приложений, свайп от левого края — «назад», Пункт управления | Часы экрана блокировки не того цвета: красные, а с `gpu=1` белые, но поверх обоев красная пелена || Запуск приложений: Настройки (вглубь), Часы, Календарь, Фото, Заметки и др.; расширения приложений (виджеты «Погода» и «Календарь» на домашнем экране рисуют своё содержимое — на телефоне; в QEMU им не хватает скорости) | Metal (приложения, рисующие через него сами); отрисовка самим Adreno есть, но пока опытная — см. «GPU» || Сенсорный экран телефона (Goodix GT9916), мультитач, пробуждение касанием | Без `cpus=N` работает одно ядро процессора || Несколько ядер процессора (`cpus=4`: четыре больших ядра телефона) | |@@ -273,8 +273,9 @@ fastboot boot ──► UEFI (Mu-Silicium, redwood) ──► xnuloader (EFI-п└─ ввод: /dev/redwood-touch ◄─ Goodix GT9916 (телефон) / virtio-input (QEMU)▼launchd iOS 16.5 → logd, notifyd, cfprefsd, runningboardd, backboardd, SpringBoard, приложения- └─ в backboardd и SpringBoard внедряются наши библиотеки (libredwood*.dylib):- виртуальные HID-службы (сенсор, кнопки) и подмена нескольких ObjC-методов+ └─ в backboardd, SpringBoard и mediaserverd внедряются наши библиотеки+ (libredwood*.dylib): виртуальные HID-службы (сенсор, кнопки) и подмена+ нескольких ObjC-методов```Userland не изменён ни в одном байте: всё, чего ему не хватает, либо делает ядро (замены драйверов), либо@@ -289,7 +290,7 @@ Userland не изменён ни в одном байте: всё, чего е| `xnu/` | наши правки XNU: патч, новые файлы, `apply.sh`/`export.sh` || `xnu-deps/` | всё для сборки XNU на Linux: `setup.sh`, обёртки инструментов, заглушки || `xnu-build.sh`, `xnu-env.sh` | сборка ядра |-| `userland/` | наш init, вставки (`src/inject.c` — backboardd, `src/inject_sb.c` — SpringBoard), тесты, сборка образов |+| `userland/` | наш init, вставки (`src/inject.c` — backboardd, `src/inject_sb.c` — SpringBoard, `src/inject_media.c` — mediaserverd), тесты, сборка образов || `ios165/` | добыча файлов iOS из IPSW и выбор того, что идёт в образ || `mkpackfs.py` | сборщик образов packfs (формат описан в `bsd/miscfs/packfs/packfs.h` ядра) || `qemu/` | запуск в QEMU, касания, снимки экрана, разбор стеков |diff --git a/tools/update-prebuilt.sh b/tools/update-prebuilt.shindex 089433b..2fe9ba4 100755--- a/tools/update-prebuilt.sh+++ b/tools/update-prebuilt.sh@@ -10,7 +10,7 @@ mkdir -p prebuilt/userland prebuilt/ueficp $K prebuilt/mach.development.bcm2837cp xnuloader/loader.efi prebuilt/loader.eficp userland/hello prebuilt/userland/-for f in init child stage0 hello_dyn svc_test surf_test rwtouch mg_test cpu_test libredwood.dylib libredwood-sb.dylib; do+for f in init child stage0 hello_dyn svc_test surf_test rwtouch mg_test cpu_test libredwood.dylib libredwood-sb.dylib libredwood-media.dylib; docp userland/obj/$f prebuilt/userland/doneif [ -f $MU/Build/redwoodPkg/RELEASE_CLANGPDB/FV/SILICIUM_UEFI.fd ]; thendiff --git a/userland/build.sh b/userland/build.shindex ce096c3..14d3b56 100755--- a/userland/build.sh+++ b/userland/build.sh@@ -12,7 +12,8 @@# OSLOG="..." labels of the jobs whose os_log output goes to the console ("all": every# one of JOBS; default: only the window server, which says little)# INJECT="..." the programs started with a library of ours, "LIBRARY NAME..." per line-# (default: src/inject.c in backboardd, src/inject_sb.c in SpringBoard);+# (default: src/inject.c in backboardd, src/inject_sb.c in SpringBoard,+# src/inject_media.c in mediaserverd);# init hands the list to the kernel (etc/inject.conf -> sysctl kern.exec_inject)# EXTRA="..." more programs for /redwood/bin (files on this machine): one-off# diagnostics, which a file given as RC_JOBS can then run@@ -59,9 +60,11 @@ IOS_JOBS=${JOBS-"com.apple.SpringBoard"}# The programs (file names) started with a library of ours inside them: "LIBRARY NAME..." per line-# (src/inject.c is libredwood.dylib, src/inject_sb.c is libredwood-sb.dylib).+# (src/inject.c is libredwood.dylib, src/inject_sb.c is libredwood-sb.dylib, src/inject_media.c is+# libredwood-media.dylib).INJECT=${INJECT-"/redwood/lib/libredwood.dylib backboardd containermanagerd containermanagerd_system-/redwood/lib/libredwood-sb.dylib SpringBoard"}+/redwood/lib/libredwood-sb.dylib SpringBoard+/redwood/lib/libredwood-media.dylib mediaserverd"}mkdir -p objif [ -z "$PREBUILT" ] && ! command -v ld64 >/dev/null; then PREBUILT=1; fi@@ -105,6 +108,8 @@ if [ -d $IOS/rootfs/usr/lib ]; then-o obj/libredwood.dylib src/inject.c$DYN -dynamiclib -install_name /redwood/lib/libredwood-sb.dylib -framework CoreFoundation -lobjc \-o obj/libredwood-sb.dylib src/inject_sb.c+ $DYN -dynamiclib -install_name /redwood/lib/libredwood-media.dylib -framework CoreFoundation -lobjc \+ -o obj/libredwood-media.dylib src/inject_media.cif [ -n "$GL" ]; then# the OpenGL ES library, and the table of functions that hands CoreAnimation's calls to it# (Mesa says beside the library what it was built from: one from other patches is built again)@@ -124,12 +129,16 @@ if [ -d $IOS/rootfs/usr/lib ]; thenfor f in $EXTRA; do cp "$f" root/bin/; donemkdir -p root/libcp obj/libredwood.dylib obj/libredwood-sb.dylib root/lib/+ [ -f obj/libredwood-media.dylib ] && cp obj/libredwood-media.dylib root/lib/ # (as with cpu_test)if [ -n "$GL" ]; thencp obj/libOSMesa.8.dylib root/lib/cp obj/gl_test root/bin/[ "$GL" = test ] || cp obj/libredwood-gl.dylib root/lib/fi- echo "$INJECT" > root/etc/inject.conf+ # a program is not started with a library that is not there: it would not start at all+ echo "$INJECT" | while read -r library names; do+ [ -z "$library" ] || [ ! -f "root/lib/${library#/redwood/lib/}" ] || echo "$library $names"+ done > root/etc/inject.confcp $IOS/var.skel root/etc/var.skel # the directories init creates in /private/var# time zones: the template's links go in a circle until the time zone daemon has run (/usr/share/zoneinfo# points back into /var); point them at the data that ships with the system, and use this machine's zonediff --git a/userland/mkjobs.py b/userland/mkjobs.pyindex 05d554c..4b98f02 100755--- a/userland/mkjobs.py+++ b/userland/mkjobs.py@@ -26,11 +26,12 @@ import osimport plistlibimport sys-# substrings of labels+# substrings of labels. (mediaserverd is not among them, for all that there is neither sound nor a camera:+# it is where VideoToolbox decodes for every other process, a HEIC picture included; see src/inject_media.c.)DENY = ('watchdog', 'CommCenter', 'wifi', 'WiFi', 'bluetooth', 'BTServer', 'locationd', 'softwareupdate','datamigrator', 'backupd', 'thermalmonitord', 'keybagd', 'nfcd', 'biometrickitd', 'pearld','obliterat', 'storage_mounter', 'com.apple.fud', 'sepd', 'seputil', 'camera', 'ReportCrash',- 'osanalytics', 'lockdown', 'mediaserverd', 'audio', 'jetsamproperties', 'mobileactivationd',+ 'osanalytics', 'lockdown', 'audio', 'jetsamproperties', 'mobileactivationd','installcoordinationd', 'purplebuddy', 'restore', 'usb', 'accessoryd','mobileassetd', 'nsurlsessiond', 'apsd', 'itunesstored', 'appstored', 'cloudd', 'bird',# these start, crash and are asked for again, over and overdiff --git a/userland/src/inject_media.c b/userland/src/inject_media.cnew file mode 100644index 0000000..43c4a63--- /dev/null+++ b/userland/src/inject_media.c@@ -0,0 +1,106 @@+/*+ * libredwood-media.dylib: code of ours inside mediaserverd (see inject.c for how it gets there).+ *+ * mediaserverd is the audio server, and also the camera's: the capture stack of CMCapture lives+ * in the same process. Soon after it starts, that stack "prewarms" the Core Image filters of the+ * portrait mode, for which Core Image wants an OpenGL ES context; there is no GPU, the context+ * has no functions behind it, and the daemon jumps to address 0 -- every time launchd restarts+ * it. Nobody is going to take a portrait here: the prewarming is skipped.+ *+ * What the daemon is wanted for meanwhile is neither sound nor the camera: it is where+ * VideoToolbox decodes for everybody else (the service com.apple.coremedia.decompressionsession),+ * and a HEIC picture is HEVC inside. Without the daemon ImageIO has "no way to decode a HEIC",+ * and the stock wallpaper of iOS 16, whose layers are four such pictures, is its gradient alone.+ * There is no hardware decoder here; VideoToolbox takes its software one (VCPHEVC.videocodec).+ *+ * CMCapture is not loaded yet when this library is: the method is replaced when its image+ * arrives.+ */+#include <CoreFoundation/CoreFoundation.h>+#include <mach-o/dyld.h>+#include <objc/runtime.h>+#include <stdarg.h>+#include <stdio.h>+#include <string.h>+#include <unistd.h>++static void+say(const char *format, ...)+{+ char line[256];+ va_list ap;+ int n;++ va_start(ap, format);+ n = vsnprintf(line, sizeof(line), format, ap);+ va_end(ap);+ if (n > (int)sizeof(line) - 1) {+ n = sizeof(line) - 1;+ }+ write(2, line, (size_t)n);+}++extern const void *_dyld_get_shared_cache_range(size_t *length);++#define CACHE_BASE 0x180000000UL /* where the cache was built to be, before the slide */++static uintptr_t slide;++/* +[BWCoreImageFilterRenderer prewarmPortraitFilterVersion:semanticStyleFilters:] */+static void+prewarm_portrait_filter(__unused id self, __unused SEL selector, __unused int version, __unused BOOL styles)+{+}++/*+ * The class methods replaced, each as soon as its class exists. `expected` is the unslid address+ * of the code in iOS 16.5 (20F66): a method that is not what it was is left alone.+ */+static struct replacement {+ const char *class_name, *selector;+ uintptr_t expected;+ IMP replacement;+ bool done;+} replacements[] = {+ { "BWCoreImageFilterRenderer", "prewarmPortraitFilterVersion:semanticStyleFilters:", 0x1a2115c0cUL,+ (IMP)prewarm_portrait_filter, false },+};++static void+image_added(__unused const struct mach_header *header, __unused intptr_t image_slide)+{+ for (size_t i = 0; i < sizeof(replacements) / sizeof(replacements[0]); i++) {+ struct replacement *r = &replacements[i];+ Class cls;+ Method method;+ IMP original;++ if (r->done || (cls = objc_getClass(r->class_name)) == NULL) {+ continue;+ }+ r->done = true;+ method = class_getClassMethod(cls, sel_registerName(r->selector));+ original = method ? method_getImplementation(method) : NULL;+ if (original == NULL || (uintptr_t)original != r->expected + slide) {+ say("redwood: +[%s %s]: found %#lx, expected %#lx; left alone\n", r->class_name, r->selector,+ original ? (uintptr_t)original - slide : 0, r->expected);+ continue;+ }+ method_setImplementation(method, r->replacement);+ say("redwood: mediaserverd: +[%s %s] replaced\n", r->class_name, r->selector);+ }+}++__attribute__((constructor))+static void+redwood_media_init(void)+{+ const char *name = getprogname();+ size_t length = 0;++ if (name == NULL || strcmp(name, "mediaserverd") != 0) {+ return;+ }+ slide = (uintptr_t)_dyld_get_shared_cache_range(&length) - CACHE_BASE;+ _dyld_register_func_for_add_image(image_added); /* also called for every image already there */+}