Skip to content

Run a virtual iPhone on an Apple Silicon Mac.

Swift

Bundle vphoned's Swift Span runtime for older iOS guests

Phineas Guodcbf94944f5a
diff --git a/Research/0_binary_patch_comparison.md b/Research/0_binary_patch_comparison.md
index 41b8dedb..19156be9 100644
--- a/Research/0_binary_patch_comparison.md
+++ b/Research/0_binary_patch_comparison.md
@@ -1,5 +1,18 @@
# Patch Comparison: Regular / Development / Jailbreak / Experimental
+> **vphoned on iOS 18 (2026-10-23):** the daemon strongly imports Span types
+> from `@rpath/libswiftCompatibilitySpan.dylib`, but the guest payload omitted
+> the back-deployment library. The bundle now carries the signed iPhoneOS
+> library, and the existing vphoned installation steps (both restore-image
+> injection and full/environment-only CFW install) copy it to
+> `/usr/lib/vphone/libswiftCompatibilitySpan.dylib`. The iOS daemon gains that
+> fallback rpath after `/usr/lib/swift`, preserving the system implementation
+> on iOS 26+. The restore-image trust-cache scan includes the added file.
+> Bundle admission checks its signature/platform and the daemon's search path.
+> No new patch, preset, instruction replacement, or version change is needed;
+> TV/watch daemon payloads are unchanged. This fixes a confirmed missing
+> dependency; an iOS 18 guest boot still needs runtime validation.
+
> **iPhone Duo bring-up (2026-10-23, first boot fails):**
> `iPhone19,4` / V68AP, iOS 27.1 (24A94425), is registered with one outer
> display and paired with cloudOS 26.4 (23E5207q). Its device tree reports
diff --git a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/CryptexFilesystem/CryptexFilesystemPatcherGuestPayload.swift b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/CryptexFilesystem/CryptexFilesystemPatcherGuestPayload.swift
index 0bb7eb12..42c5ba51 100644
--- a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/CryptexFilesystem/CryptexFilesystemPatcherGuestPayload.swift
+++ b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/CryptexFilesystem/CryptexFilesystemPatcherGuestPayload.swift
@@ -69,6 +69,13 @@ extension CryptexFilesystemPatcher {
defer { try? FileManager.default.removeItem(at: vphonedBin) }
let confined = try VPhoneConfinedDirectory.pin(absolutePath: targetMount)
+ if guestFamily == .iPhone || guestFamily == .iPad {
+ // Included in createTrustcache's scan of the finished filesystem.
+ _ = try confined.directory("usr/lib/vphone", create: true)
+ try confined.replaceFile("usr/lib/vphone/libswiftCompatibilitySpan.dylib",
+ fromFileAt: VPhoneGuestBinaries.resolve("libswiftCompatibilitySpan.dylib"),
+ mode: 0o755, owner: (0, 0))
+ }
try confined.replaceFile("usr/bin/vphoned", fromFileAt: vphonedBin, mode: 0o755, owner: (0, 0))
}
diff --git a/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneCustomFirmwareInstaller.swift b/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneCustomFirmwareInstaller.swift
index 7e490943..a51034ef 100644
--- a/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneCustomFirmwareInstaller.swift
+++ b/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneCustomFirmwareInstaller.swift
@@ -2321,6 +2321,14 @@ struct VPhoneCustomFirmwareInstaller {
let vphoned = try VPhoneGuestBinaries.resolve(VPhoneResources.vphonedName(for: guestDevice.family))
let staged = work.file("vphoned")
try fm.copyItem(at: vphoned, to: staged)
+ if guestDevice.family == .iPhone || guestDevice.family == .iPad {
+ // Install on both full and environment-only updates, before the
+ // daemon that needs it. The payload is already signed in the bundle.
+ _ = try system.directory("usr/lib/vphone", create: true)
+ try system.replaceFile("usr/lib/vphone/libswiftCompatibilitySpan.dylib",
+ fromFileAt: VPhoneGuestBinaries.resolve("libswiftCompatibilitySpan.dylib"),
+ mode: 0o755, owner: Self.guestOwner)
+ }
try system.replaceFile("usr/bin/vphoned", fromFileAt: staged, mode: 0o755, owner: Self.guestOwner)
let daemon = resources.guestResources.appendingPathComponent("vphoned.plist")
try system.replaceFile(
diff --git a/VPhoneExecutable/VPhoneVirtualization/Build/StageBundle.sh b/VPhoneExecutable/VPhoneVirtualization/Build/StageBundle.sh
index 7792c2d1..babb00c9 100755
--- a/VPhoneExecutable/VPhoneVirtualization/Build/StageBundle.sh
+++ b/VPhoneExecutable/VPhoneVirtualization/Build/StageBundle.sh
@@ -73,6 +73,15 @@ daemon_sdk="$(/usr/bin/otool -l "$guest/vphoned" | /usr/bin/awk '/LC_BUILD_VERSI
/usr/bin/xcrun vtool -set-build-version tvos 15.0 "$daemon_sdk" -replace -output "$guest/vphoned-tvos" "$guest/vphoned"
# The same for watch guests: watchOS 8 is iOS 15's release.
/usr/bin/xcrun vtool -set-build-version watchos 8.0 "$daemon_sdk" -replace -output "$guest/vphoned-watchos" "$guest/vphoned"
+# iOS before 26 needs Span's back-deployment library. Keep /usr/lib/swift
+# first so newer guests use their system implementation; only the iOS daemon
+# gets this private fallback. TV/watch payloads above remain unchanged.
+guest_compatibility_library="$(/usr/bin/xcrun swift-stdlib-tool --print \
+ --scan-executable "$guest/vphoned" --platform iphoneos | \
+ /usr/bin/grep '/libswiftCompatibilitySpan.dylib$')"
+/bin/cp "$guest_compatibility_library" "$guest/libswiftCompatibilitySpan.dylib"
+/usr/bin/install_name_tool -add_rpath /usr/lib/vphone "$guest/vphoned"
+/usr/bin/codesign --force --sign - "$guest/libswiftCompatibilitySpan.dylib"
/bin/cp "$root/VPhoneDaemon/Configuration/vphoned.plist" "$guest/vphoned.plist"
/bin/cp "$guest_products/launchhook/launchdhook-vphone.dylib" "$guest/launchdhook-vphone.dylib"
/bin/cp "$guest_products/systemhook/SystemHook-vphone.dylib" "$guest/SystemHook-vphone.dylib"
diff --git a/VPhoneExecutable/VPhoneVirtualization/Build/ValidateBundle.sh b/VPhoneExecutable/VPhoneVirtualization/Build/ValidateBundle.sh
index cd894067..a6d23563 100755
--- a/VPhoneExecutable/VPhoneVirtualization/Build/ValidateBundle.sh
+++ b/VPhoneExecutable/VPhoneVirtualization/Build/ValidateBundle.sh
@@ -144,11 +144,27 @@ if /usr/bin/grep -q 'AVPSEPBooter-' "$resources/OpenSEP/OpenSEP.bin"; then
exit 1
fi
-for name in vphoned vphoned-tvos vphoned-watchos launchdhook-vphone.dylib SystemHook-vphone.dylib libcamfix.dylib \
+for name in vphoned vphoned-tvos vphoned-watchos libswiftCompatibilitySpan.dylib launchdhook-vphone.dylib SystemHook-vphone.dylib libcamfix.dylib \
libvcamcaptured.dylib libmisfix.dylib libhapticsfix.dylib libbatteryhealthfix.dylib libdevicehubfix.dylib libdevicename.dylib \
libprefsfix.dylib libsigninfix.dylib libvphonegyro.dylib libvphoneaccelerometer.dylib libvphoneattitude.dylib libAppleParavirtCompilerPluginIOGPUFamily.dylib; do
require_signed_macho "$guest/$name"
done
+# iOS 18 must be able to resolve the compatibility library without Xcode.
+# /usr/lib/swift remains first for guests whose standard library has Span.
+daemon_rpaths="$(/usr/bin/otool -l "$guest/vphoned" | /usr/bin/awk '
+ $2 == "LC_RPATH" { rpath = 1; next }
+ rpath && $1 == "path" { print $2; rpath = 0 }
+')"
+[[ "${daemon_rpaths%%$'\n'*}" == /usr/lib/swift &&
+ "$daemon_rpaths" == *$'\n/usr/lib/vphone' ]] || {
+ print -u2 "vphoned must search system Swift libraries before its bundled fallback"
+ exit 1
+}
+/usr/bin/otool -L "$guest/vphoned" | /usr/bin/awk 'NR > 1 {print $1}' |
+ /usr/bin/grep -Fx '@rpath/libswiftCompatibilitySpan.dylib' >/dev/null || {
+ print -u2 "vphoned does not use the bundled Span compatibility library"
+ exit 1
+ }
for name in vphoned.plist libcamfix.plist libvcamcaptured.plist libmisfix.plist; do
[[ -f "$guest/$name" ]] || { print -u2 "Missing guest configuration: $name"; exit 1; }
done