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 branch 'main' into services

vcvkk243d649e11ee
diff --cc userland/build.sh
index f2b6c92,b5950cb..e3d272e
--- a/userland/build.sh
+++ b/userland/build.sh
@@@ -233,17 -250,39 +261,45 @@@ if [ -d $IOS/rootfs/usr/lib ]; the
case $f in mobile/*) owner=501 ;; *) owner=0 ;; esac
printf 'f\t644\t%s\t%s\t/private/var/%s\t/var/%s\n' $owner $owner "$f" "$f"
done >> root/etc/var.skel
+ # mobile's own temporary directory, $HOME/tmp, which iOS's template does not have: an application of
+ # mobile's without a data container of its own keeps its temporary files there -- Sileo, registered from
+ # the prefix with the root on the flash, downloads every package and index there, and without it each
+ # download ended in "No such file or directory"
+ printf 'd\t700\t501\t501\t/private/var/mobile/tmp\n' >> root/etc/var.skel
+ # A key of ours for root, when there is one: ssh/authorized_keys, never in the repository (like
+ # fw-*). dropbear from the package manager's prefix reads it and lets us in over the phone's
+ # Wi-Fi, which saves rebuilding an image for every question one wants to ask a running iOS. It
+ # refuses a key whose directory anyone but its owner may write, hence the 700.
+ if [ -f ../ssh/authorized_keys ]; then
+ mkdir -p root/var/root/.ssh
+ printf 'd\t700\t0\t0\t/private/var/root/.ssh\n' >> root/etc/var.skel
+ # the key that lets us in, and the host's own key beside it: made here and not on the
+ # phone, because ssh-keygen asks who uid 0 is and gets "No user exists for uid 0" --
+ # it asks through libiosexec, which reads a database the bootstrap does not ship (see
+ # init.c, where it is now built at every boot); the key is made here all the same,
+ # since nothing should depend on the order of those two
+ for k in authorized_keys ssh_host_ed25519_key ssh_host_ed25519_key.pub; do
+ [ -f ../ssh/$k ] || continue
+ cp ../ssh/$k root/var/root/.ssh/$k
+ printf 'f\t600\t0\t0\t/private/var/root/.ssh/%s\t/var/root/.ssh/%s\n' $k $k >> root/etc/var.skel
+ done
+ fi
cp ${RC:-rc.launchd} root/etc/rc
cp ${RC_JOBS:-rc.jobs} root/etc/rc.jobs
+ # QUIET=1: launchd's own standard error goes nowhere (src/init.c). It says a few thousand
+ # lines about its own business in the first minutes and pushes everything else out of the
+ # kernel's log; the daemons keep their own standard error on the console all the same.
+ rm -f root/etc/quiet
+ [ -n "$QUIET" ] && : > root/etc/quiet
- # the jobs the iOS launchd will see (/System/Library/LaunchDaemons is a symlink to this directory)
+ # the jobs the iOS launchd will see (/System/Library/LaunchDaemons is a symlink to this directory).
+ # With FLASHBOOT=1 the root will be Apple's whole volume on the flash, not the part of it that fits in
+ # the system image, so mkjobs.py judges "is this daemon's program there" by the listing of the volume
+ # and not by what select-system.py extracted here (--root-volume; seven jobs turn on the difference,
+ # fairplayd among them).
cp com.redwood.demo.plist com.redwood.wifi.plist root/LaunchDaemons/
- [ -n "$IOS_JOBS" ] && OSLOG=${OSLOG-com.apple.backboardd} ./mkjobs.py ${REST:+--rest} $IOS/rootfs root/LaunchDaemons $IOS_JOBS
+ VOLUME=""
+ [ -n "$FLASHBOOT" ] && [ -f $IOS/rootfs.slt ] && VOLUME="--root-volume $IOS/rootfs.slt"
+ [ -n "$IOS_JOBS" ] && OSLOG=${OSLOG-com.apple.backboardd} ./mkjobs.py ${REST:+--rest} $VOLUME $IOS/rootfs root/LaunchDaemons $IOS_JOBS
fi
# firmware of the phone's own hardware, where somebody has pulled it from the phone's Android into ../fw-gpu
# (it is the vendor's and never in the repository): the kernel's GPU bring-up, bsd/dev/redwood_adreno.c, finds it in fw/
diff --cc userland/mkjobs.py
index 6b590a9,8b82fb9..73ce071
--- a/userland/mkjobs.py
+++ b/userland/mkjobs.py
@@@ -40,144 -26,12 +40,150 @@@ import o
import plistlib
import sys
-# substrings of labels. (nsurlsessiond is not among them either, for all that it belongs to the same
-# family of Apple's own services: it is the daemon that carries out background URLSession downloads,
+# Substrings of labels -- and two things to know before adding to this list or believing anything in it.
+#
+# A daemon here may be misbehaving BECAUSE OF ANOTHER ENTRY, so the tuple cannot be judged one line at a
+# time. cloudd was the proof: it looked like a daemon that cost the home screen, on the phone as well as in
+# QEMU, until it turned out to be retrying com.apple.nsurlsessiond thousands of times because nsurlsessiond
+# was itself denied. With that one word gone, cloudd stops spinning and the home screen comes back. Anything
+# written below about a daemon was measured against whatever else was denied at the time, which may no longer
+# be what is denied now -- when a note here was written before a word came out, retest before trusting it.
+#
+# And measure against a control from the same afternoon. Every stalled run of mine happened to be later than
+# every good one, and another session's QEMU was running on the same machine, so the obvious reading was that
+# the machine was loaded rather than that the daemons did it. It was not: one good run sat squarely between
+# two stalled ones. A time-ordered pattern is not a cause; put a control next to the thing you changed.
+#
+# (nsurlsessiond is not among them either, taken out in the sileo2 copy: it is the
+# daemon that carries out background URLSession downloads, and without it an application's download never
+# starts and never fails -- Sileo sits on "Queued" for ever. It matters here for a second reason, below:
+# cloudd spins on it when it is missing.
+# 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.
+# apsd is not among them either: it was left out from the first day without ever being tried, and it is the
+# service the rest of the system misses most -- near a third of every "failed lookup" line in the run logs is
+# one of 22 daemons asking for com.apple.apsd, and the whole account stack asks before it will do anything.
+# It needs no hardware we have not got, and it serves its clients whether or not it reaches a push courier,
+# which it never will: the courier wants a device identity rooted in the Secure Enclave this phone has not
+# got (apsd -> mobileactivationd, "Device is probably unactivated"), so the push itself stays out of reach.)
+# CommCenter stays, and this is what it cost to find out. Shipping both of its plists is the stock
+# arrangement -- they carry the same label and launchd picks by the device tree, so with no "baseband" node
+# it takes com.apple.CommCenter-noncellular, the variant iOS has for a device with no modem -- and it does
+# pick it. It then gets a long way: it answers com.apple.commcenter.xpc and .coretelephony.xpc (85 and 18
+# failed lookups in a session become none), serves geod its policy, loads the network-extension
+# configurations. And then it dies, every time, on one of two IOKit drivers of the cellular path that this
+# kernel has not got, and each has its own signal. With CommCenter's own log on, the split is clean over
+# 20 crashes: 11 SIGSEGV every one of them right after "Could not find AppleIPAppender service" (matched
+# by name; user client ApplePDPHelperInterface -- PDP contexts, traffic-class flows, dedicated bearers),
+# and 9 SIGABRT every one of them right after "Unable to communicate with AppleBaseband driver"
+# (com.apple.driver.AppleBasebandPCI). That answers the obvious question before anyone spends a week on
+# it: stubbing AppleIPAppender alone would remove the SIGSEGV half and leave the SIGABRT half, so it is
+# not enough on its own -- and AppleBasebandPCI is an Apple modem on PCIe, which this phone has not got.
+# It respawns and does it again: 18 crashes in a seven-minute session where the same image without it has
+# none. The boot is not held up -- it reaches the same 118 processes against 119 -- so the trade is 103
+# failed lookups a session against a process dying every fifteen seconds for ever, which is a bad one.
+# Stubbing the first driver is the kind of work RedwoodBattery already is, but the second is an Apple
+# baseband on PCIe, and this phone's modem is on the SoC and speaks QMI to a Qualcomm subsystem -- so what
+# is behind the driver is missing too, not just the driver.
+# cloudd and appstored are IN, and getting there was the most instructive thing in this file.
+# They looked like daemons that cost the home screen: with them the boot reached 76-78 processes against
+# 119 and not one widget or poster started, and on the phone it was worse still -- 42 processes against
+# 128, no home screen, the scenario's applications never opening. The cause was neither of them. cloudd
+# was retrying com.apple.nsurlsessiond without ever stopping -- 2351 times in that phone session -- because
+# nsurlsessiond was itself in this tuple. With nsurlsessiond shipped, the phone run with both of them in
+# reaches 130 processes and 20 widget and poster processes with no crash, against the baseline's 128 and 19:
+# better than the image without them. Zero nsurlsessiond retries.
+# What each one is actually shown to do, which is less than "it works":
+# appstored -- confirmed. It spawns, and com.apple.appstored.xpc.request, the one service the App Store
+# could not find when it was opened by hand, is answered: 0 failed lookups against 1.
+# cloudd -- the harm is gone, the use is not shown. In that phone session nothing asked for it at all
+# (0 requestor lines against 2352 when it was spinning), so all that is proved is that shipping it no
+# longer costs the boot. In QEMU it does start and behaves: 0 retries, 100 processes, 12 widgets.
+# Taking 'cloudd' out of the tuple also lets com.apple.itunescloudd through, which has never been asked
+# for in any session measured here.
+# The App Store: itunesstored and installcoordinationd are in, and this is exactly how far it gets.
+# appstored asks for both the moment the store is opened, and with them it runs clean -- 135 processes,
+# 17 widget and poster processes, no crash. The App Store opens and shows its own LOADING spinner and
+# stays there. It is NOT the FairPlay wall and NOT a sign-in: the store stack never opens a TCP
+# connection at all (trustd, mDNSResponder, geod, nsurlsessiond all do; appstored, itunesstored and
+# AppStore do not), so it stops before the network. appstored says why, in one line:
+# [bag] AMSBagActiveAccountProvider: The local account doesn't have a storefront.
+# localAccount = <ACAccount type = iTunesStore | username = local | storefront = (null)>
+# [bag] AMSBagNetworkDataSource: Could not fetch initial cached storefront
+# [Bag] Error creating snapshot of bag: Timed out while waiting for snapshot bag to load
+# CAUTION, this paragraph's conclusion was wrong and is left here only so the mistake is not repeated.
+# There IS a third route to a storefront and it is the one a SIM-less, never-signed-in iPhone uses: the
+# bag server sets it over HTTP. AppleMediaServices holds "X-Set-Apple-Store-Front" and the line
+# "Attempting to load the bag again because the response had a x-set-apple-store-front header", plus
+# https://bag.itunes.apple.com/bag.xml; AMS fetches the bag with no storefront, the server picks one from
+# the request's address, and AMSBagDataSource _setStorefrontFromURLResponse:bagData: writes it onto the
+# local account. "The local account doesn't have a storefront" is a fallback message, not a wall, and
+# there is no activation gate anywhere in the store stack.
+# AND THE MEASUREMENT UNDER IT CANNOT CARRY A NEGATIVE AT ALL, which is the lesson worth keeping:
+# /dev/console on the phone DROPS LINES, and every "it never appears in the log" above rests on that
+# channel. In the same run the scenario's steps demonstrably ran -- init echoed the command line, the
+# step after them printed -- and net_test's own output for resolve, reach and two fetches is simply
+# absent, while launchd's "Last log repeated 2312 times" of failed lookups fills the window. So the
+# store's missing bag strings are not evidence that no bag was fetched; they are evidence of nothing.
+# What the console did carry, and what is therefore true, is the opposite of what was written here:
+# THE PHONE'S NETWORK WORKS. en0 is 192.168.9.243, mDNSResponder resolves over TCP to 192.168.9.1:53
+# (four queries, answers of 159, 842, 200 and 107 bytes), and trustd, geod, maild, gamed, cloudd,
+# StocksWidget and nsurlsessiond all open TLS to Apple and Akamai (17.248.214.x, 17.253.39.x,
+# 2.16.56.93, 23.11.40.157, 95.100.176.233). "net_test: en0: flags 0x8802" was read 0.1 s into user
+# space, before configd had configured it: com.redwood.wifi does that by itself with wifi=1, so a
+# scenario must not ask for DHCP again -- only "waitaddr en0 60".
+# The storefront question is therefore OPEN, and the next measurement has to be made over a channel
+# that does not drop: ssh to the phone (rc.jobs.ssh) and fetch the bag by hand.
+# What is true below is only that these two services are the ones appstored cannot find:
+# com.apple.commcenter.coretelephony.xpc -- the SIM's country, through CommCenter, which crash-loops
+# here (see above);
+# com.apple.mobileactivationd -- the activation record's region. That binary carries RegionCode,
+# RegionInfo and subscriberCountryCodeDidChange:, and it is rooted in a Secure Enclave this phone
+# has not got.
+# (Still worth knowing, and unaffected: the setup assistant is not the missing piece, since this port refuses it
+# (src/inject_sb.c forces -[SBSetupManager _setSetupRequiredReason:] to 0) -- it is not. We already ship
+# com.apple.purplebuddy.plist with SetupDone = True, MobileGestalt already answers RegionInfo = LL/A, and
+# a region is not a storefront. AMS has no country-to-storefront path to feed either: every countryCode
+# selector in AppleMediaServices derives the country FROM the bag (_countryCodeFromBag:), and the bag
+# cannot be fetched without a storefront -- AMSBagNetworkTask takes one as an argument. AMSDefaults holds
+# storefrontSuffixes, not a storefront. So there is no file that can be shipped to fake this: it needs
+# CommCenter working or an account signed in, and signing in is not a decision to be taken here.
+# The one stall that looked like a second cause was the same cause. ALLOW="syncdefaultsd appstored" lost the
+# home screen too (77 processes, no widgets) with no retry storm at all, which seemed to rule nsurlsessiond
+# out -- but that run was built before nsurlsessiond came out of this tuple. Built again with it there, the
+# same pair reaches 112 processes and 15 widget and poster processes, PosterBoard among them. So every stall
+# measured in this group traces to the one missing daemon, and nothing here needs a second explanation.
+# The thing that nearly hid it: the storm is cloudd's alone. syncdefaultsd and appstored do not spin on
+# nsurlsessiond -- they simply wait on something that waits on it -- so "no retry storm" was not evidence of
+# a different cause. Absence of the symptom is not absence of the illness.
+# syncdefaultsd (com.apple.kvsd) is out on its own merits. It serves cloudkeychainproxy3 its store, then
+# aborts inside changeTokenForStoreWithConfiguration:reply: with
+# *** Terminating app due to uncaught exception 'NSInvalidArgumentException',
+# reason: '*** -[NSURL initFileURLWithPath:isDirectory:]: nil string parameter'
+# -- it is building a file URL for a directory it was given as nil. The likely one is the SyncedPreferences
+# directory it asks for by name ("uncontainerizedSyncedPreferencesDirectoryURL"). Two candidates were
+# followed and both are ruled out, so nobody need follow them again.
+# Not a missing directory of mobile's. build.sh can make an empty one with a d line in var.skel, as it
+# does for /var/root/.ssh; with /private/var/mobile/Library/SyncedPreferences created at boot,
+# syncdefaultsd aborts in the same place with the same exception.
+# Not a container lookup either. Running with containermanagerd's own log on, syncdefaultsd never asks
+# it anything: every request in the session comes from lsd. So _container_create_or_lookup_path is
+# not where the nil is born.
+# What it looks like instead: the URL is per bundle, and it comes back nil for whichever bundle the
+# migration pass happens to reach. syncdefaultsd walks 686 of them ("Checking for plist URLs from bundle:
+# ..."), and the one it dies after is a different bundle every run -- com.apple.PaperBoard.LegacyPoster in
+# one, com.apple.exchangesyncexpress.framework.EASOAuthService in another -- so it is not one bad bundle.
+# It also aborts on the cloudkeychainproxy3 store registration with no bundle in hand at all. Whatever
+# supplies a bundle's SyncedPreferences path is empty here, for bundles at large; that is not two lines of
+# var.skel, and guessing directories is the wrong tool for it.
+# bird and duetexpertd were shipped as well and nothing ever asked for them in a bare boot (no spawn, no
+# lookup), so they are still untested rather than known good; they need a session with applications.
++# (nsurlsessiond is not among them either, for all that it belongs to the same family of Apple's own
++# services: it is the daemon that carries out background URLSession downloads,
+ # and without it an application's download never starts and never fails -- Sileo sits on "Queued"
+ # for ever, see «Sileo» in README.md.)
+ # (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',