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

Merge sileo2 into main: SSH on the phone, the switcher's purple cards, the fault reporter

vcvkk7ae311642a4e
diff --cc README.md
index 8738dcd,598da75..0a38225
--- a/README.md
+++ b/README.md
@@@ -33,9 -33,10 +33,11 @@@
| Кнопки: на телефоне настоящие — питание (боковая кнопка iPhone) и громкость; в QEMU — клавишами | Зарядка под нашим ядром (телефон только разряжается) |
| Большое ядро на 2,4 ГГц, загрузка до экрана блокировки ~20 с (телефон) | |
| Safari: открывает страницы (на телефоне — через его Wi-Fi), его службы — из криптекса App, как на iPhone (см. «Только APFS, как на iPhone») | |
-| Снимки экрана и запись экрана с телефона | Сохранение данных: /private/var в памяти, каждая загрузка — «новое устройство» |
+| Снимки экрана и запись экрана с телефона | |
+| Сохранение данных: то, что iOS записала в `/private/var`, переживает перезагрузку телефона — архивом в разделе `darwin` (`var_store=1 ufs_write=1`, см. «Том данных между загрузками») | |
| Звук iOS в QEMU (см. ниже; с громкостью; «Сейчас играет» — с оговоркой) | Динамики и микрофоны самого телефона: под нашим ядром они молчат |
+ | Камера телефона в самой Camera.app: предпросмотр с задней камеры, ровный и живой (`cam=5`, см. «Камера») | Снимок по кнопке затвора: запрос сходит на нет внутри mediaserverd |
+ | Sileo и префикс Procursus — dpkg и apt, установка пакетов из сети (`tools/mk-jb.sh`, см. «Sileo») | |
Это стенд для исследования, а не прошивка: сеанс длится заданное число секунд, потом ядро возвращается в загрузчик
и отдаёт журнал.
diff --cc userland/src/init.c
index 45ee283,c6a7f27..d5edfed
--- a/userland/src/init.c
+++ b/userland/src/init.c
@@@ -643,44 -845,89 +845,125 @@@ mount_writable(void
}
printf(" %d directories, %d files\n", made, files);
check(ok && made > 50, "create the directories of the data volume");
+
+ /*
+ * and the package manager's prefix, when the image was built with one (tools/mk-jb.sh): /jb of
+ * the system image in RAM, or, with the iOS volume on the flash as the root, /private/preboot/jb
+ * -- the boot volume, where a rootless jailbreak on an iPhone keeps its Procursus too
+ * (/var/jb leads into /private/preboot there)
+ */
+ jb = stat("/jb", &st) == 0 && (st.st_mode & S_IFMT) == S_IFDIR ? "/jb" :
+ stat("/private/preboot/jb", &st) == 0 && (st.st_mode & S_IFMT) == S_IFDIR ? "/private/preboot/jb" : NULL;
+ if (ok && jb != NULL) {
+ const char *to = "/private/var/jb";
+ int dirs = 0, entries = 0, grafted, users = 0;
+
+ /*
+ * With the root on the flash, the prefix's writable copy goes into a memory filesystem of its own
+ * on the boot volume's jb-rw, as procursus, and /var/jb is a link to it: where /var/jb leads on
+ * an iPhone with a rootless jailbreak, into /private/preboot. LaunchServices registers an
+ * application from there, and from /private/var not at all -- everything a package put in
+ * /var/jb/Applications was "Unable to register", with nothing on the files even looked at.
+ */
+ if (strcmp(jb, "/private/preboot/jb") == 0 && stat("/private/preboot/jb-rw", &st) == 0) {
+ if (mount("ramfs", "/private/preboot/jb-rw", 0, NULL) == 0 &&
+ symlink("/private/preboot/jb-rw/procursus", "/private/var/jb") == 0) {
+ to = "/private/preboot/jb-rw/procursus";
+ } else {
+ printf(" the prefix on /private/preboot/jb-rw: %s\n", strerror(errno));
+ }
+ }
+ grafted = graft_tree(jb, to, 1, &dirs, &entries);
+
+ /*
+ * All of it belongs to root, as it does on a phone, but for the user's corner of it: an
+ * application of the prefix runs as mobile and keeps its data there (Sileo's database).
+ */
+ static const char *const mobiles[] = { "/private/var/jb/var/mobile", "/private/var/jb/var/mobile/Library",
+ "/private/var/jb/var/mobile/Library/Caches",
+ "/private/var/jb/var/mobile/Library/Preferences",
+ "/private/var/jb/var/mobile/Documents",
+ /*
+ * Sileo keeps the indexes of its repositories apart from
+ * apt's own (it runs apt with -oDir::State::lists=
+ * sileolists/), and it is mobile who writes them.
+ */
+ "/private/var/jb/var/lib/apt/sileolists",
+ "/private/var/jb/var/lib/apt/sileolists/partial" };
+
+ for (unsigned i = 0; i < sizeof(mobiles) / sizeof(mobiles[0]); i++) {
+ mkdir(mobiles[i], 0755);
+ grafted = chown(mobiles[i], 501, 501) == 0 && grafted;
+ }
+ grafted = own_tree("/private/var/jb/var/mobile", 501) && grafted;
+ /*
+ * The prefix's own user database. Its programs do not ask iOS who a user is: they are
+ * built against libiosexec, which carries an ie_getpwnam of its own and reads
+ * /var/jb/etc/pwd.db -- a Berkeley database that pwd_mkdb makes from master.passwd and
+ * that the bootstrap does not ship, only the text it is made from. Without it every
+ * program of the prefix answers "no such user": an sshd from here refused every login
+ * with "Invalid user root" while iOS's own /bin/ps resolved users perfectly -- and the
+ * asymmetry is exactly this, not anything about iOS's own database or the launchd domain
+ * its server sits in, because a program of the prefix never asks iOS at all. The
+ * writable copy of the prefix is new at every boot, so the database is made at every
+ * boot; it takes milliseconds.
+ */
+ if (stat("/private/var/jb/usr/sbin/pwd_mkdb", &st) == 0) {
+ char *argv[] = { "/var/jb/usr/sbin/pwd_mkdb", "-p", "/var/jb/etc/master.passwd", NULL };
+ char *envp[] = { "PATH=/var/jb/usr/sbin:/var/jb/usr/bin:/usr/bin:/bin", NULL };
+ int status = 0;
+ pid_t pid = fork();
+
+ if (pid == 0) {
+ execve(argv[0], argv, envp);
+ _exit(127);
+ }
+ if (pid > 0 && wait4(pid, &status, 0, NULL) == pid && WIFEXITED(status) && WEXITSTATUS(status) == 0) {
+ users = 1;
+ }
+ }
+ printf(" /var/jb from %s, in %s: %d directories, %d files and links%s\n", jb, to, dirs, entries,
+ users ? ", users resolvable" : "");
+ check(grafted, "graft the package manager's prefix onto the data volume");
+ }
}
+/*
+ * What the last boot left in /private/var, back out of the phone's flash (var_store=1): the
+ * memory filesystem is empty at every boot, so everything iOS writes -- the home screen's layout,
+ * the applications' own data, the snapshots and the baked wallpaper -- would otherwise be new
+ * again every time. userland/src/var_store.c keeps a copy in the partition darwin, past the iOS
+ * volume and the cryptexes, and puts it back here, over the skeleton: a name the skeleton has and
+ * the store has too comes out as the store has it. A store that is not there or does not check
+ * out leaves what the skeleton made, and the boot goes on either way -- so a bad store cannot
+ * keep the phone from starting.
+ */
+static void
+restore_var(void)
+{
+ const char *wanted = boot_arg("var_store");
+ char *argv[3];
+ int status = 0;
+ pid_t pid;
+
+ if (wanted == NULL || strcmp(wanted, "1") != 0) {
+ return;
+ }
+ printf("\n-- the data volume of the last boot --\n");
+ argv[0] = (char *)in_image("/bin/var_store");
+ argv[1] = (char *)"load";
+ argv[2] = NULL;
+ pid = fork();
+ if (pid == 0) {
+ execve(argv[0], argv, environ);
+ printf(" %s: %s\n", argv[0], strerror(errno));
+ _exit(127);
+ }
+ if (pid < 0 || wait4(pid, &status, 0, NULL) != pid || !WIFEXITED(status)) {
+ printf(" var_store did not run\n");
+ }
+}
+
static int
count_entries(const char *path)
{