Run a virtual iPhone on an Apple Silicon Mac.
Swift
Show the display of an iOS 18 guest on standard
Maximilian Paß70aea5df8b8d
diff --git a/VPhoneDaemon/Daemon/GuestCoreAnimationCompression.swift b/VPhoneDaemon/Daemon/GuestCoreAnimationCompression.swiftnew file mode 100644index 00000000..2d847249--- /dev/null+++ b/VPhoneDaemon/Daemon/GuestCoreAnimationCompression.swift@@ -0,0 +1,48 @@+import Darwin+import Foundation+import IcliKit++/// Turns off CoreAnimation's surface compression on an iOS 18 guest.+///+/// iOS 18's AppleParavirtIOSurface maps only address format 0 and rejects the+/// compressed surfaces CoreAnimation asks for ("invalid address format (3)"):+/// backboardd's framebuffer allocation fails at boot, it retries forever, and+/// the screen stays black. Three keys in the any-user global domain turn the+/// compression and the deep framebuffer off.+///+/// The Minimal preset writes them into the restore image+/// (`filesystem-boot-ios18_surface_compression`). Every other preset restores+/// the system as shipped and customises the System volume afterwards, and the+/// preferences live on the Data volume, which the host cannot mount (see+/// ``GuestMobileGestaltCache``). So vphoned sets them here, and restarts the+/// backboardd that started without them; a guest that has them already is left+/// alone, so this happens once, on the first boot.+enum GuestCoreAnimationCompression {+ static let keys = ["CAEnableIOSurfaceCompression", "CAEnableFramebufferCompression", "CAEnableDeepFramebuffer"]+ private static let backboardd = "/usr/libexec/backboardd"++ static func applyOnStartup() {+ guard ProcessInfo.processInfo.operatingSystemVersion.majorVersion == 18 else { return }+ let app = kCFPreferencesAnyApplication, user = kCFPreferencesAnyUser, host = kCFPreferencesAnyHost+ let missing = keys.filter {+ (CFPreferencesCopyValue($0 as CFString, app, user, host) as? Bool) != false+ }+ guard !missing.isEmpty else { return }+ let values = Dictionary(uniqueKeysWithValues: keys.map { ($0, false) }) as CFDictionary+ CFPreferencesSetMultiple(values, nil, app, user, host)+ guard CFPreferencesSynchronize(app, user, host) else {+ NSLog("vphoned: CoreAnimation compression: cannot write the global preferences")+ return+ }+ let rows = (try? listProcesses(filter: "backboardd"))?["processes"] as? [[String: Any]] ?? []+ guard let pid = rows.first(where: { $0["executable"] as? String == backboardd })?["pid"] as? Int else {+ NSLog("vphoned: CoreAnimation compression: turned off (%@); backboardd not running yet", missing.joined(separator: ", "))+ return+ }+ guard kill(pid_t(pid), SIGKILL) == 0 else {+ NSLog("vphoned: CoreAnimation compression: kill(%d): %@", pid, String(cString: strerror(errno)))+ return+ }+ NSLog("vphoned: CoreAnimation compression: turned off (%@), restarted backboardd %d", missing.joined(separator: ", "), pid)+ }+}diff --git a/VPhoneDaemon/Daemon/main.swift b/VPhoneDaemon/Daemon/main.swiftindex 5a2e5e6d..094a1eec 100644--- a/VPhoneDaemon/Daemon/main.swift+++ b/VPhoneDaemon/Daemon/main.swift@@ -23,6 +23,8 @@ guard vp_native_watch_proxy() == 0 else { exit(1) }GuestLockScreenIdle.startOnStartup()// Before the server, so `/v1/health` reports a drop from its first answer.GuestMobileGestaltCache.dropIfStaleOnStartup()+// An iOS 18 screen stays black until backboardd runs without surface compression.+GuestCoreAnimationCompression.applyOnStartup()// Before audiomxd is asked for sound again; see the type for what it cannot cover.GuestVirtualAudioProduct.storeOnStartup()// After SpringBoard has had time to come up, so the inner panel's layoutdiff --git a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwareGuestDisplayPatchSet.swift b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwareGuestDisplayPatchSet.swiftindex 25742dc1..6889734a 100644--- a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwareGuestDisplayPatchSet.swift+++ b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwareGuestDisplayPatchSet.swift@@ -3,7 +3,10 @@// IOMFB talks to a framebuffer that does not exist on a research board. Which// patch is needed depends on the userland: a 27 base routes the swap through the// kernel, while 26.0 and 18.x only need the swap-end structure resized. The two-// are mutually exclusive by version, so one set covers both.+// are mutually exclusive by version, so one set covers both. The resize is for a+// 26.x kernel: an 18.x userland on its own release's research board kernel+// submits the structure that kernel expects, and the resized one fails+// (`swap_end returned error e00002c2`, a black screen).import Foundationimport VPhonePatchKit@@ -27,10 +30,11 @@ public enum FirmwareGuestDisplayPatchSet {VPhonePatchDeclaration(identifier: "dyld-boot-iomfb_swapend",title: "IOMFB swap-end size",- summary: "Resizes the swap-end structure a 26.0, 18.x or experimental 17.7 userland submits.",+ summary: "Resizes the swap-end structure a 26.0, 18.x or experimental 17.7 userland submits to a 26.x kernel.",target: .dyldSharedCache,applicability: VPhonePatchApplicability(iOSBase: .oneOf([.release(major: 26, minor: 0), .major(18), .major(17)]),+ cloudOS: .atLeast(major: 26, minor: 0),),bootEssential: true,),