Skip to content

Run a virtual iPhone on an Apple Silicon Mac.

Swift

Give iOS 18 guests on a cloudOS 26.1 kernel a Metal device

Jacky24fd20d72a32
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index 210e8efa..47e73405 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -72,6 +72,7 @@ jobs:
run: |
make -C VPhoneGuestComponents test-mach-ports-compat
make -C VPhoneGuestComponents test-ios16-surface
+ make -C VPhoneGuestComponents test-ios18-gpu
make -C VPhoneGuestComponents test-ios16-lab-policy
make -C VPhoneGuestComponents test-loader-links
make -C VPhoneGuestComponents test-vcam-dataplane
diff --git a/Research/0_binary_patch_comparison.md b/Research/0_binary_patch_comparison.md
index 16303104..4c769871 100644
--- a/Research/0_binary_patch_comparison.md
+++ b/Research/0_binary_patch_comparison.md
@@ -1801,6 +1801,7 @@ do NOT execute these).
| 34 | Remove four point-size reflection guards that suppress valid `GL_POINTS` submissions — **iOS 26.6 / cloudOS 26.4** | AppleMetalGLRenderer's direct and primitive-buffer draw paths, guest dyld shared cache | **Submit points despite missing PV pipeline usage flags.** `dyld-cfw-gles_point_draw` replaces only the four bit-7 `TBZ` guards with NOPs, preserving other gates and the native shader/rasterizer. Semantic discovery and transactional DSC undo; cloned-cache apply/repeat/revert restores all 85 files exactly. Process-local diagnostics restore point footprints but expose a separate coordinate Y-flip transport gap. Development-build guest validation passes all 21 point cases on the restored old default cache and a warm repeat; see "Native GLES follow-up (2026-11-02)". | Y | Y | Y |
| 35 | Derive the paravirtual driver compiler cache identity from the installed plugin — **iOS 26.6 / cloudOS 26.4** | AppleParavirtGPUMetalIOGPUFamily | **Invalidate shader output after plugin updates.** `system-paravirt_gpu-cfw-compiler_cache` replaces only two eight-byte SHA-256 seed inputs with a 96-bit plugin content identity. Changes compose with the other driver patches on its pristine backup. Requires row 36 when cross-boot reuse is enabled; installer verifies it actually applied before refreshing the plugin. Private APFS clone and fatal identity-failure handling prevent inconsistent publication. Development-build guest validation rejects stale default-cache shaders and passes all 21 point cases. | Y | Y | Y |
| 36 | Retain cache-key validation when cross-boot reuse is enabled — **iOS 26.6 / cloudOS 26.4** | libCoreFSCache in the guest dyld shared cache | **Reject stale compiler output while retaining warm caches across boots.** The original `FS_CACHE_REUSE_ON_REBOOT=1` skips both the key and boot checks. `dyld-cfw-metal_cache_reuse_key` routes only that path through the key comparison; the no-reuse path remains intact. Development-build guest validation passes all 21 point cases on the restored old default cache and a warm repeat; actual-cache apply/repeat/undo restores all 85 files. | Y | Y | Y |
+| 37 | No Apple binary change: SystemHook detours IOKit's `IOServiceOpen`/`IOServiceClose`/`IOConnectCallMethod`/`IOConnectCallAsyncMethod` while `/usr/lib/vphone-ios18-gpu` exists, and `fw prepare` stages the iOS release's own cloudOS GPU driver — **iOS 18.6 / cloudOS 26.1** | none (`VPhoneGuestComponents/SystemHook/VPhoneIOS18GPU.c`; driver from cloudOS 18.6; marker written by `cfw install` only over that driver) | **An iOS 18 guest gets a Metal device.** The 26.1 driver does not load on iOS 18, and the 18.6 one is refused by the 26.1 kernel: IOGPU device method 6 is gone and 7–255 moved down by one, the resource-create reply gained 8 bytes at 0x18, and AppleParavirtGPU method 265 grew from 0x10c to 0x118. The transport renumbers and repacks for IOGPU device connections only. `system-systemhook-cfw-ios18_gpu_transport`; see "iOS 18 GPU transport (2026-11-05)" and `Research/Guest/ios18_gpu_transport.md` | Y | Y | Y |
### Swift port status — the eight DSC patchers (2026-09-23)
@@ -6820,3 +6821,28 @@ developer mode `enabled`, and LLDB attached to configd through the re-signed
debugserver, evaluated `(int)getpid()` and read 16 bytes at its pc. The watch
guest needed more than 2048 MB: at 2048 MB a stock LLB, with or without the
feature, stops the VM after `iLLB decompressed`; at 8192 MB both boot.
+
+## iOS 18 GPU transport (2026-11-05)
+
+Row 37. An iPhone17,3 iOS 18.6.2 guest on the cloudOS 26.1 kernel had no Metal
+device, because `fw prepare` staged the cloudOS's paravirtual driver and iOS 18
+cannot load a 26.x one. `system-systemhook-cfw-ios18_gpu_transport` is selected by
+`standard` for iOS 18.6 on cloudOS 26.1 only. TV, HomePod and HomeView presets
+exclude it, a VM with no plan does not get it, and opt-in cannot widen the gate.
+
+**Reveal.** Trace each user-client call from a guest test process with the
+prototype detours; diff every `bl _IOConnectCall*` site of IOGPU.framework in the
+22G100 and 23B85 caches by caller symbol (`w1` selector, scalar and struct
+counts); sweep accepted struct sizes of each AppleParavirtGPU method against the
+26.1 kernel from a guest test binary. The full table and the steps for another
+pairing are in `Research/Guest/ios18_gpu_transport.md`.
+
+**Change.** No Apple binary is modified. `fw prepare` stages the driver from the
+iOS release's own cloudOS (18.6, 22G86), cached in `~/.vphone/gpu-drivers` and
+otherwise recovered by the usual temporary restore. SystemHook detours four IOKit
+entry points with MISFixDetour, only while the marker exists, and translates IOGPU
+device-client calls only. `cfw install` writes the marker only when the installed
+driver's `DTPlatformVersion` is the iOS release; switching the patch off removes
+it. Rules are unit-tested by `make test-ios18-gpu`.
+
+**Validation.** See `Research/Guest/ios18_gpu_transport.md`, "Verified".
diff --git a/Research/Guest/ios18_gpu_transport.md b/Research/Guest/ios18_gpu_transport.md
new file mode 100644
index 00000000..436de9b4
--- /dev/null
+++ b/Research/Guest/ios18_gpu_transport.md
@@ -0,0 +1,119 @@
+# iOS 18 GPU transport on a cloudOS 26.1 kernel
+
+iPhone17,3 iOS 18.6.2 (22G100) boots the cloudOS 26.1 (23B85) vphone600
+kernel, with PR #822 aiming the EXC_GUARD patch. Before this change the guest had
+no Metal device: wallpaper black, Settings rows without icons, app status bars
+clipped, vphoned screenshots black, and SBRendererService aborting in
+`-[NUDevice_iOS _newRendererWithCIContextOptions:]` (`NUDevice.GPU`,
+`deviceNotCapable`). Everything drew in software.
+
+`system-systemhook-cfw-ios18_gpu_transport` fixes this in two parts.
+
+## Why there was no device
+
+`fw prepare` stages the paravirtual Metal driver of the paired cloudOS, because
+`VPhonePCCGPUDriver.validateBundle` requires its `DTPlatformVersion` to match the
+cloudOS release. An iOS 18 base therefore got the 26.1 driver (v63.2.2, built for
+26.1). dyld refuses it on iOS 18:
+`Symbol not found: _OBJC_IVAR_$_IOGPUMetalHeap._device` (IOGPU.framework), so
+`MTLCreateSystemDefaultDevice()` returns nil.
+
+The driver from cloudOS 18.6 (22G86, v40.5.10) loads. Its device is then refused
+by the 26.1 kernel, because iOS 18's IOGPU.framework and that driver call user
+clients that changed between the two releases.
+
+## The kernel ABI that moved
+
+Found by tracing each IOKit user-client call in a test process, then diffing all
+~50 `IOConnectCall*` sites of IOGPU.framework in the 18.6.2 and 26.1 shared caches
+(selector immediate, scalar and struct counts, struct sizes):
+
+| iOS 18 call | cloudOS 26.1 | Translation |
+| --- | --- | --- |
+| IOGPU device method 6 (`IOGPUDeviceCreateWithAPIProperty`: a 16-byte API name, result ignored) | removed | answered locally with success |
+| IOGPU device methods 7–255 (7 = command queue create, 9 = resource create, … 0x37) | one lower (6, 8, … 0x36) | selector − 1 |
+| Resource create reply: 0x50-byte header + driver tail | 8 bytes inserted at 0x18 | ask for 8 more, drop `[0x18, 0x20)` |
+| AppleParavirtGPU method 265 (`-[AppleParavirtDevice setupDeviceInfo]`), 0x10c-byte reply | 0x118 bytes, refused with 0xe00002c2 when asked for 0x10c | ask for 0x118, keep `[0, 0xd8)` and `[0xdc, 0x110)` |
+
+Request layouts did not change: the command queue create struct is 0x408 bytes on
+both, and resource create input passes through (variable size, at least 88 bytes).
+Paravirt methods 257, 259 and 260 are unchanged. Only the device user client
+(type `1 | (api << 16)`) is renumbered. IOGPU's other client types and every other
+user client in the process are not.
+
+## How the fix works
+
+- **Driver.** With the patch selected, `fw prepare` stages the driver of the iOS
+ release's own cloudOS (`VPhoneFirmwareCatalog.iOS18CloudOS(forVersion:)`, the
+ research-board table: cloudOS 18.6 for 18.6.x). It reuses
+ `~/.vphone/gpu-drivers/<version>_<build>` when an earlier machine cached it, and
+ otherwise recovers it from that cloudOS with the usual temporary restore. The
+ project's compiler plugin is merged as before. iOS 18's `MTLCompilerService`
+ accepts plugins only under `/System/Library/Extensions/` or
+ `/System/Library/PrivateFrameworks/` (`validPathPrefixes`), so the driver has to
+ be in the System volume, and the plugin (minos 26.1) loads there.
+- **Transport.** SystemHook (`SystemHook/VPhoneIOS18GPU.c`) detours IOKit's
+ `IOServiceOpen`, `IOServiceClose`, `IOConnectCallMethod` and
+ `IOConnectCallAsyncMethod` with MISFixDetour, which rewrites the callee, so calls
+ from inside the shared cache are translated too. An interpose or
+ `DYLD_INSERT_LIBRARIES` does not reach those. It records connections opened as
+ IOGPU device clients and applies the table above to them only. The rules are in
+ `SystemHook/VPhoneIOS18GPUTransport.c`, checked by `make test-ios18-gpu`.
+ `IOServiceOpen` is detoured last, so connections are recorded only once both
+ call paths translate.
+- **Gate.** The declaration applies to iOS 18.6 on cloudOS 26.1, the pair that was
+ measured. `cfw install` writes `/usr/lib/vphone-ios18-gpu` only when the
+ installed driver's `DTPlatformVersion` is the iOS release. A machine prepared
+ before this change, which still has the 26.1 driver, gets no marker and a note
+ to run `fw prepare` again. Switching the patch off removes the marker.
+
+## Retargeting to another pairing
+
+Do not widen the gate without repeating the measurement:
+
+1. Extract IOGPU.framework from both shared caches
+ (`ipsw dyld extract … IOGPU`), disassemble with symbols, and list each
+ `bl _IOConnectCall*` with the selector in `w1` and the size arguments.
+2. Pair the sites by caller symbol. Any change other than the shift above needs
+ a new rule.
+3. For the driver, probe each paravirt method's accepted struct sizes against the
+ target kernel from a guest test binary (size sweep; refusals are 0xe00002c2).
+4. Repeat the guest checks below.
+
+## Verified
+
+Test process on `exc822-1862` (iPhone17,3 18.6.2 over cloudOS 26.1, bundle
+2.15.2-local, 2026-11-04), with the 18.6 driver and the prototype of this
+transport: `MTLCreateSystemDefaultDevice` returned "Apple Paravirtual device GPU".
+Blit fill 4096/4096, render-pass clear read back 4096/4096, IOSurface render
+target and shared event (signaled 7), shader compile through `MTLCompilerService`,
+and a compute pipeline whose dispatch read back 1024/1024. No IOKit call returned
+an error.
+
+System-wide on the same machine (2026-11-05), bundle built from this change plus
+PR #822, driver staged as `fw prepare` now stages it, then `cfw install`:
+
+- `cfw install` wrote `/usr/lib/vphone-ios18-gpu` over the 18.6 driver.
+- IORegistry: paravirt device clients held by backboardd, SpringBoard,
+ runningboardd, Preferences, iconservicesagent, cameracaptured, mediaanalysisd
+ and the poster and widget extensions.
+- Lock screen wallpaper with the depth clock, home screen widgets and dock
+ material, Settings with an unclipped status bar, and the vector map in Maps
+ (a sandboxed app) all render. SpringBoard and backboardd kept their pids
+ across the session. No panic in four boots.
+- A probe in the `temporary-sandbox` profile, with SystemHook loaded inside the
+ sandbox, reads the marker and gets a device.
+
+Open:
+
+- `com.apple.MapKit.SnapshotService` aborted once in each of the first two boots,
+ about 9 s after SpringBoard started, in `-[AppleParavirtDevice setupCompiler]`
+ (`compilerTargetInfo.shaderVersionMajor >= 2`). That field comes from the
+ device-info reply, so that call was not translated there. It did not recur in
+ the next two boots and could not be started on demand. The cause is unknown.
+- cameracaptured aborted once at boot in `MPSLibrary::MPSKey_Compile`
+ (`MTLReportFailure`) while prewarming inference. That is a shader compile
+ failure under a working device, not seen again.
+- Settings row icons stay blank, as before this change. Not a stale cache:
+ with the icon cache moved aside, Settings wrote no new entries. Not yet
+ explained.
diff --git a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwareGuestSystemPatchSet.swift b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwareGuestSystemPatchSet.swift
index 119609d6..05fd7d62 100644
--- a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwareGuestSystemPatchSet.swift
+++ b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwareGuestSystemPatchSet.swift
@@ -45,6 +45,8 @@ public enum FirmwareGuestSystemPatchSet {
public static let metalCacheReuseMarker = "/usr/lib/vphone-metal-cache-reuse"
public static let glesUpperLeft = "system-systemhook-cfw-gles_upper_left"
public static let glesUpperLeftMarker = "/usr/lib/vphone-gles-upper-left"
+ public static let ios18GPUTransport = "system-systemhook-cfw-ios18_gpu_transport"
+ public static let ios18GPUTransportMarker = "/usr/lib/vphone-ios18-gpu"
public static let metalVertexIDFormat = "dyld-cfw-metal_vertex_id_format"
public static let glesPrimitiveRestart = "dyld-cfw-gles_primitive_restart"
public static let glesPointDraw = "dyld-cfw-gles_point_draw"
@@ -604,6 +606,22 @@ public enum FirmwareGuestSystemPatchSet {
cloudOS: .release(major: 26, minor: 4),
),
),
+ VPhonePatchDeclaration(
+ identifier: ios18GPUTransport,
+ title: "iOS 18 GPU transport",
+ summary: """
+ Gives an iOS 18 guest on a cloudOS 26.1 kernel a Metal device. `fw prepare` stages \
+ the paravirtual GPU driver of the iOS release's own cloudOS, and SystemHook \
+ translates the IOGPU and driver calls the 26.1 kernel renumbered or widened. \
+ Without it the guest has no GPU and draws its UI in software. Restart after changing; \
+ switching it on or off also needs a new `fw prepare` for the matching driver.
+ """,
+ target: .guestFile(path: ios18GPUTransportMarker),
+ applicability: VPhonePatchApplicability(
+ iOSBase: .release(major: 18, minor: 6),
+ cloudOS: .release(major: 26, minor: 1),
+ ),
+ ),
// MARK: Guest Payload
diff --git a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwarePatchSetCatalog.swift b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwarePatchSetCatalog.swift
index e5b17aa5..409daba5 100644
--- a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwarePatchSetCatalog.swift
+++ b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwarePatchSetCatalog.swift
@@ -295,6 +295,7 @@ public enum FirmwarePatchSetCatalog {
"system-paravirt_gpu-cfw-primitive_restart",
FirmwareGuestSystemPatchSet.paravirtGPUCompilerCache,
FirmwareGuestSystemPatchSet.glesUpperLeft,
+ FirmwareGuestSystemPatchSet.ios18GPUTransport,
"system-systemhook-cfw-metal_cache_reuse",
"system-systemversion-cfw-build_version",
"system-virtiosound-cfw-hal_plugin",
diff --git a/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/PatchSets/FirmwarePatchSetCatalogTests.swift b/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/PatchSets/FirmwarePatchSetCatalogTests.swift
index 9c9ffac1..aba8cd10 100644
--- a/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/PatchSets/FirmwarePatchSetCatalogTests.swift
+++ b/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/PatchSets/FirmwarePatchSetCatalogTests.swift
@@ -622,6 +622,30 @@ struct FirmwarePatchSetCatalogTests {
}
}
+ @Test
+ func `The iOS 18 GPU transport follows the measured OS pair`() throws {
+ let patch = FirmwareGuestSystemPatchSet.ios18GPUTransport
+ for base in ["18.1", "18.5", "18.6", "18.6.2", "18.7.2", "26.1", "unknown"] {
+ for cloud in ["18.6", "26.1", "26.4", "unknown"] {
+ let plan = try VPhonePatchPlan.resolve(
+ preset: FirmwarePatchSetCatalog.standardPreset,
+ patchSets: FirmwarePatchSetCatalog.bundled,
+ iOSBase: VPhoneVersion(base), cloudOS: VPhoneVersion(cloud),
+ )
+ let supported = (base == "18.6" || base == "18.6.2") && cloud == "26.1"
+ #expect(plan.isEnabled(patch) == supported, "\(base)/\(cloud)")
+ }
+ }
+ for preset in [FirmwarePatchSetCatalog.tvOSPreset, FirmwarePatchSetCatalog.tvOS4KPreset,
+ FirmwarePatchSetCatalog.homePodMiniPreset, FirmwarePatchSetCatalog.homeViewPreset] {
+ let plan = try VPhonePatchPlan.resolve(
+ preset: preset, patchSets: FirmwarePatchSetCatalog.bundled,
+ iOSBase: VPhoneVersion("18.6.2"), cloudOS: VPhoneVersion("26.1"),
+ )
+ #expect(!plan.isEnabled(patch), "\(preset.identifier)")
+ }
+ }
+
@Test
func `Standard names the GLES renderer on every base while tvOS stays off`() throws {
let patch = FirmwarePatchSetCatalog.paravirtGLESPatch
diff --git a/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneCustomFirmwareInstaller.swift b/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneCustomFirmwareInstaller.swift
index f06079c3..d58e477b 100644
--- a/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneCustomFirmwareInstaller.swift
+++ b/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneCustomFirmwareInstaller.swift
@@ -1363,6 +1363,7 @@ struct VPhoneCustomFirmwareInstaller {
&& identifier != FirmwareGuestSystemPatchSet.ios16Touchscreen
&& identifier != FirmwareGuestSystemPatchSet.ios16KeybaglessUI
&& identifier != FirmwareGuestSystemPatchSet.glesUpperLeft
+ && identifier != FirmwareGuestSystemPatchSet.ios18GPUTransport
&& identifier != FirmwareGuestSystemPatchSet.paravirtGPUCompilerCache
}
guard plan.isEnabled(identifier) else {
@@ -2496,6 +2497,30 @@ struct VPhoneCustomFirmwareInstaller {
}
}
+ // The transport only makes sense over the iOS release's own driver,
+ // which `fw prepare` stages when this patch is selected. A machine
+ // prepared before that still has the cloudOS one, which iOS 18 cannot
+ // load at all, so translating for it would change nothing.
+ let gpuTransportPatch = FirmwareGuestSystemPatchSet.ios18GPUTransport
+ let gpuTransportMarker = String(FirmwareGuestSystemPatchSet.ios18GPUTransportMarker.dropFirst())
+ isolate([gpuTransportPatch]) {
+ if on(gpuTransportPatch) {
+ let info = try PropertyListSerialization.propertyList(
+ from: system.readData("\(gpuBundle)/Info.plist"), format: nil,
+ ) as? [String: Any]
+ let driver = info?["DTPlatformVersion"] as? String ?? "unknown"
+ guard VPhonePCCGPUDriver.release(driver) == VPhonePCCGPUDriver.release(version) else {
+ try system.removeItem(gpuTransportMarker)
+ print(" [!] \(gpuTransportPatch): the installed GPU driver is for \(driver), not \(version); run fw prepare again to stage the iOS \(VPhonePCCGPUDriver.release(version)) driver")
+ return
+ }
+ try system.writeFile(gpuTransportMarker, contents: Data("1\n".utf8), mode: 0o644, owner: Self.guestOwner)
+ live.insert(gpuTransportPatch)
+ } else {
+ try system.removeItem(gpuTransportMarker)
+ }
+ }
+
if !failures.isEmpty {
print("[!] \(failures.count) guest patch(es) failed and were left in their prior state: \(Set(failures).sorted().joined(separator: ", "))")
if strict {
diff --git a/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneFirmwarePreparer.swift b/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneFirmwarePreparer.swift
index fd7824cf..d7552d9c 100644
--- a/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneFirmwarePreparer.swift
+++ b/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneFirmwarePreparer.swift
@@ -194,12 +194,23 @@ enum VPhoneFirmwarePreparer {
plan.isEnabled("system-extensions-boot-gpu_bundle") || plan.isEnabled(FirmwareRestoreImagePatchSet.gpuDriver)
{
let cachedDriver = cachedGPUDriver(for: cloud)
+ // iOS 18 cannot load a 26.x cloudOS driver. With its transport
+ // selected it takes the driver of its own release's cloudOS.
+ let ownReleaseDriver = plan.isEnabled(FirmwareGuestSystemPatchSet.ios18GPUTransport)
if let gpuDriverBundle {
print("[*] Staging GPU driver from local bundle...")
try VPhonePCCGPUDriver.stage(
from: gpuDriverBundle,
into: phoneTree,
- expectedPlatformVersion: cloud.version,
+ expectedPlatformVersion: ownReleaseDriver ? VPhonePCCGPUDriver.release(phone.version) : cloud.version,
+ )
+ } else if ownReleaseDriver {
+ try stageIOS18GPUDriver(
+ forVersion: phone.version,
+ into: phoneTree,
+ staging: staging,
+ ipswCacheDirectory: ipswCacheDirectory,
+ downloadConnections: downloadConnections,
)
} else if (try? VPhonePCCGPUDriver.stage(
from: cachedDriver,
@@ -440,6 +451,52 @@ enum VPhoneFirmwarePreparer {
.appendingPathComponent(VPhonePCCGPUDriver.name, isDirectory: true)
}
+ /// The driver of an iOS 18 release's own cloudOS, for its GPU transport:
+ /// cached by an earlier machine, or recovered from that cloudOS the same
+ /// way as a paired cloudOS's driver and cached for the next one.
+ static func stageIOS18GPUDriver(
+ forVersion version: String,
+ into phoneTree: URL,
+ staging: URL,
+ ipswCacheDirectory: URL,
+ downloadConnections: Int,
+ cacheDirectory: URL = VPhoneResources.gpuDriverCacheDirectory(),
+ ) throws {
+ let fm = FileManager.default
+ let release = VPhonePCCGPUDriver.release(version)
+ // Cached per cloudOS build, as `<version>_<build>`.
+ let builds = ((try? fm.contentsOfDirectory(atPath: cacheDirectory.path)) ?? [])
+ .filter { VPhonePCCGPUDriver.release(String($0.prefix { $0 != "_" })) == release }
+ .sorted()
+ for build in builds.reversed() {
+ let driver = cacheDirectory
+ .appendingPathComponent(build, isDirectory: true)
+ .appendingPathComponent(VPhonePCCGPUDriver.name, isDirectory: true)
+ if (try? VPhonePCCGPUDriver.stage(from: driver, into: phoneTree, expectedPlatformVersion: release)) != nil {
+ print("[+] iOS \(release) GPU driver reused from cloudOS \(build) cache")
+ return
+ }
+ }
+ guard let option = VPhoneFirmwareCatalog.iOS18CloudOS(forVersion: version) else {
+ throw ValidationError("No known cloudOS \(release) supplies a GPU driver iOS \(version) can load. Pass one with --gpu-driver-bundle, or block \(FirmwareGuestSystemPatchSet.ios18GPUTransport).")
+ }
+ print("[*] Resolving \(option.name) for the iOS \(release) GPU driver...")
+ let archive = try resolve(
+ option.url, in: ipswCacheDirectory, connections: downloadConnections, label: "downloading \(option.name)",
+ )
+ let tree = staging.appendingPathComponent("cloudOS-\(release)", isDirectory: true)
+ try fm.createDirectory(at: tree, withIntermediateDirectories: false)
+ try VPhoneArchiveExtractor.extract(archive.file, into: tree, options: .intoHostDirectory)
+ print("[*] Restoring \(option.name) in a temporary vphone VM to extract its GPU driver...")
+ try VPhonePCCGPURecovery.stage(cloudOSDirectory: tree, into: phoneTree, expectedPlatformVersion: archive.version)
+ let cached = cachedGPUDriver(for: archive, in: cacheDirectory)
+ do {
+ try storeGPUDriver(VPhonePCCGPUDriver.stagedBundle(in: phoneTree), at: cached)
+ } catch {
+ fputs("warning: could not cache the GPU driver at \(cached.path): \(error.localizedDescription)\n", stderr)
+ }
+ }
+
/// Copies into a private directory, then renames it into place, so a
/// concurrent prepare never sees half a bundle. If another prepare stores
/// the same build in between, its copy is kept.
diff --git a/VPhoneExecutable/VPhoneVirtualization/Resources/patches_presets/homepod-mini.plist b/VPhoneExecutable/VPhoneVirtualization/Resources/patches_presets/homepod-mini.plist
index 1a45eac0..1bcfdd9d 100644
--- a/VPhoneExecutable/VPhoneVirtualization/Resources/patches_presets/homepod-mini.plist
+++ b/VPhoneExecutable/VPhoneVirtualization/Resources/patches_presets/homepod-mini.plist
@@ -150,6 +150,7 @@
<string>system-paravirt_gpu-cfw-primitive_restart</string>
<string>system-paravirt_gpu-cfw-compiler_cache</string>
<string>system-systemhook-cfw-gles_upper_left</string>
+ <string>system-systemhook-cfw-ios18_gpu_transport</string>
<string>system-systemhook-cfw-metal_cache_reuse</string>
<string>system-systemversion-cfw-build_version</string>
<string>system-virtualaudio-cfw-microphone_graph_chains</string>
diff --git a/VPhoneExecutable/VPhoneVirtualization/Resources/patches_presets/homeview.plist b/VPhoneExecutable/VPhoneVirtualization/Resources/patches_presets/homeview.plist
index b434e78a..9f635ea0 100644
--- a/VPhoneExecutable/VPhoneVirtualization/Resources/patches_presets/homeview.plist
+++ b/VPhoneExecutable/VPhoneVirtualization/Resources/patches_presets/homeview.plist
@@ -157,6 +157,7 @@
<string>system-springboard-cfw-fold_display</string>
<string>system-springboard-cfw-fold_guard</string>
<string>system-systemhook-cfw-gles_upper_left</string>
+ <string>system-systemhook-cfw-ios18_gpu_transport</string>
<string>system-systemhook-cfw-metal_cache_reuse</string>
<string>system-systemversion-cfw-build_version</string>
<string>system-tv-exp-legacy_setup</string>
diff --git a/VPhoneExecutable/VPhoneVirtualization/Resources/patches_presets/tvos-4k.plist b/VPhoneExecutable/VPhoneVirtualization/Resources/patches_presets/tvos-4k.plist
index dfb194d2..7d9c0dad 100644
--- a/VPhoneExecutable/VPhoneVirtualization/Resources/patches_presets/tvos-4k.plist
+++ b/VPhoneExecutable/VPhoneVirtualization/Resources/patches_presets/tvos-4k.plist
@@ -156,6 +156,7 @@
<string>system-paravirt_gpu-cfw-primitive_restart</string>
<string>system-paravirt_gpu-cfw-compiler_cache</string>
<string>system-systemhook-cfw-gles_upper_left</string>
+ <string>system-systemhook-cfw-ios18_gpu_transport</string>
<string>system-systemhook-cfw-metal_cache_reuse</string>
<string>system-systemversion-cfw-build_version</string>
<string>system-virtiosound-cfw-hal_plugin</string>
diff --git a/VPhoneExecutable/VPhoneVirtualization/Resources/patches_presets/tvos.plist b/VPhoneExecutable/VPhoneVirtualization/Resources/patches_presets/tvos.plist
index e53a71d9..273c68ee 100644
--- a/VPhoneExecutable/VPhoneVirtualization/Resources/patches_presets/tvos.plist
+++ b/VPhoneExecutable/VPhoneVirtualization/Resources/patches_presets/tvos.plist
@@ -160,6 +160,7 @@
<string>system-paravirt_gpu-cfw-primitive_restart</string>
<string>system-paravirt_gpu-cfw-compiler_cache</string>
<string>system-systemhook-cfw-gles_upper_left</string>
+ <string>system-systemhook-cfw-ios18_gpu_transport</string>
<string>system-systemhook-cfw-metal_cache_reuse</string>
<string>system-systemversion-cfw-build_version</string>
<string>system-virtiosound-cfw-hal_plugin</string>
diff --git a/VPhoneGuestComponents/Makefile b/VPhoneGuestComponents/Makefile
index 43f7f065..f8bbb7c3 100644
--- a/VPhoneGuestComponents/Makefile
+++ b/VPhoneGuestComponents/Makefile
@@ -43,8 +43,8 @@ LAUNCHHOOK := $(STAGE)/launchhook/launchdhook-vphone.dylib
LAUNCHHOOK_SOURCES := $(wildcard LaunchHook/*.c) Shared/RootHideLoaderLinks.c Shared/VPhoneX1Spawn.c Shared/VPhoneMachPortsCompat.c
LAUNCHHOOK_INCLUDES := $(wildcard LaunchHook/*.h LaunchHook/*.inc Shared/*.h)
SYSTEMHOOK := $(STAGE)/systemhook/SystemHook-vphone.dylib
-SYSTEMHOOK_SOURCES := $(wildcard SystemHook/*.c) $(wildcard FlutterRemapFix/*.c) Shared/RootHideLoaderLinks.c Shared/VPhoneX1Spawn.c Shared/VPhoneMachPortsCompat.c LaunchHook/VPhoneMachMessage.c
-SYSTEMHOOK_INCLUDES := $(wildcard SystemHook/*.h SystemHook/*.inc FlutterRemapFix/*.h Shared/*.h)
+SYSTEMHOOK_SOURCES := $(wildcard SystemHook/*.c) $(wildcard FlutterRemapFix/*.c) Shared/RootHideLoaderLinks.c Shared/VPhoneX1Spawn.c Shared/VPhoneMachPortsCompat.c LaunchHook/VPhoneMachMessage.c MISFix/MISFixDetour.c
+SYSTEMHOOK_INCLUDES := $(wildcard SystemHook/*.h SystemHook/*.inc FlutterRemapFix/*.h Shared/*.h) MISFix/MISFixDetour.h MISFix/MISFixConditionalBranch.h MISFix/MISFixConfig.h
# libmis is not a framework and has no header; the iPhoneOS SDK does ship
# libmis.tbd, so the interposed symbols bind two-level like any other import
# rather than through flat dynamic lookup.
@@ -723,6 +723,13 @@ test-ios16-surface:
-o $(OUT)/IOS16SurfaceReplyTest Tests/IOS16SurfaceReplyTest.c SystemHook/VPhoneIOS16SurfaceReply.c
@$(OUT)/IOS16SurfaceReplyTest
+.PHONY: test-ios18-gpu
+test-ios18-gpu:
+ @mkdir -p $(OUT)
+ xcrun --sdk macosx clang -Wall -Wextra -Werror -fsanitize=address,undefined -ISystemHook \
+ -o $(OUT)/IOS18GPUTransportTest Tests/IOS18GPUTransportTest.c SystemHook/VPhoneIOS18GPUTransport.c
+ @$(OUT)/IOS18GPUTransportTest
+
.PHONY: test-mach-ports-compat
test-mach-ports-compat: $(MACHPORTS_STAMP)
@mkdir -p ../.build/machports-test
diff --git a/VPhoneGuestComponents/README.md b/VPhoneGuestComponents/README.md
index 54d4186d..f5fa786e 100644
--- a/VPhoneGuestComponents/README.md
+++ b/VPhoneGuestComponents/README.md
@@ -133,6 +133,15 @@ which iOS ships no driver for. audiomxd loads it when the kernel publishes
frames are served, on the host. See `Research/Guest/virtio_sound.md` and
`Research/Guest/virtio_sound_microphone.md`.
+`system-systemhook-cfw-ios18_gpu_transport` links the iOS 18 GPU transport into
+SystemHook. While `/usr/lib/vphone-ios18-gpu` exists it detours IOKit's service
+open and close and its two call entry points with MISFixDetour, and translates the
+calls of IOGPU device clients only: method 6 is answered locally, 7 to 255 move
+down by one, and the resource-create and paravirtual device-info replies are
+repacked to iOS 18's layout. `cfw install` writes the marker only for iOS 18.6
+on cloudOS 26.1, over the iOS release's own driver. `make test-ios18-gpu` checks
+the rules. See `Research/Guest/ios18_gpu_transport.md`.
+
`FlutterRemapFix` is linked into SystemHook for early handling of a specific
Flutter AOT callback remap permission mismatch. It checks canonical same-bundle
images, native parameters and actual permissions before making a private copy
diff --git a/VPhoneGuestComponents/SystemHook/SystemHook-vphone.c b/VPhoneGuestComponents/SystemHook/SystemHook-vphone.c
index e30901b8..201ccb5f 100644
--- a/VPhoneGuestComponents/SystemHook/SystemHook-vphone.c
+++ b/VPhoneGuestComponents/SystemHook/SystemHook-vphone.c
@@ -19,6 +19,7 @@
static int vpInXPCProxy;
static int vpInBootstrap;
extern void vpInstallSurfaceAdapter(void);
+extern void vpInstallIOS18GPUTransport(void);
static int vpIsBootstrapPath(const char *path, const char *root) {
if (path && strncmp(path, "/var/jb/", 8) == 0)
@@ -224,6 +225,7 @@ static void vpLoadLibrary(const char *kind, const char *library) {
// xpcproxy needs this bridge because launchd only spawns the proxy, not its target.
__attribute__((constructor)) static void vpLogProcess(void) {
vpInstallSurfaceAdapter();
+ vpInstallIOS18GPUTransport();
// Request cross-boot reuse at constructor entry: libCoreFSCache normally
// invalidates Metal caches when the boot session changes. Preserve an
// explicit environment setting. See Research/Guest/gpu_acceleration.md.
diff --git a/VPhoneGuestComponents/SystemHook/VPhoneIOS18GPU.c b/VPhoneGuestComponents/SystemHook/VPhoneIOS18GPU.c
new file mode 100644
index 00000000..2c7735d6
--- /dev/null
+++ b/VPhoneGuestComponents/SystemHook/VPhoneIOS18GPU.c
@@ -0,0 +1,169 @@
+#include "VPhoneIOS18GPUTransport.h"
+#include "../MISFix/MISFixDetour.h"
+#include <IOKit/IOKitLib.h>
+#include <dlfcn.h>
+#include <fcntl.h>
+#include <os/lock.h>
+#include <stdatomic.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+// iOS 18's GPU userland on a cloudOS 26.1 kernel. `cfw install` writes the
+// marker only for that pairing, with the iOS 18 paravirtual driver installed.
+// The calls come from IOGPU.framework inside the shared cache and from the
+// driver bundle, so IOKit's entry points are detoured rather than interposed;
+// see MISFix/MISFixDetour.h.
+#define VP_IOS18_GPU_MARKER "/usr/lib/vphone-ios18-gpu"
+
+// MISFixDetour reports each install through these. SystemHook is in every
+// process, so its success line is dropped; failures are reported below.
+void MISFixNote(const char *format, ...) { (void)format; }
+const char *MISFixCallerImage(const void *address) { (void)address; return "?"; }
+
+// MARK: - Device connections
+
+// Only IOGPU device clients are translated: every other user client in the
+// process, including IOGPU's other client types, keeps its selectors.
+enum { VP_DEVICE_SLOTS = 32 };
+static io_connect_t vpDevices[VP_DEVICE_SLOTS];
+static atomic_int vpDeviceCount;
+static os_unfair_lock vpDeviceLock = OS_UNFAIR_LOCK_INIT;
+
+// A closed name can come back from another IOServiceOpen, which always
+// replaces whatever this table remembered about it.
+static void vpForgetLocked(io_connect_t connection) {
+ for (int index = 0; index < VP_DEVICE_SLOTS; index++) {
+ if (vpDevices[index] != connection) continue;
+ vpDevices[index] = MACH_PORT_NULL;
+ atomic_fetch_sub(&vpDeviceCount, 1);
+ }
+}
+
+static bool vpIsDevice(io_connect_t connection) {
+ if (connection == MACH_PORT_NULL || atomic_load_explicit(&vpDeviceCount, memory_order_relaxed) == 0) return false;
+ bool found = false;
+ os_unfair_lock_lock(&vpDeviceLock);
+ for (int index = 0; index < VP_DEVICE_SLOTS && !found; index++) found = vpDevices[index] == connection;
+ os_unfair_lock_unlock(&vpDeviceLock);
+ return found;
+}
+
+static void vpNoteFirstDevice(void) {
+ static atomic_bool noted;
+ if (atomic_exchange(&noted, true)) return;
+ int fd = open("/var/mobile/Library/Caches/vphone-systemhook.log", O_WRONLY | O_APPEND | O_CLOEXEC);
+ if (fd < 0) return;
+ dprintf(fd, "pid=%d ios18-gpu=%s device opened\n", getpid(), getprogname());
+ close(fd);
+}
+
+// MARK: - IOKit detours
+
+static kern_return_t (*vpServiceOpen)(io_service_t, task_port_t, uint32_t, io_connect_t *);
+static kern_return_t vpServiceOpenHook(io_service_t service, task_port_t task, uint32_t type, io_connect_t *connection) {
+ kern_return_t result = vpServiceOpen(service, task, type, connection);
+ if (result != KERN_SUCCESS || !connection) return result;
+ bool device = (type & 0xffff) == VP_IOS18_GPU_DEVICE_CLIENT && IOObjectConformsTo(service, "IOGPU");
+ bool added = false;
+ os_unfair_lock_lock(&vpDeviceLock);
+ vpForgetLocked(*connection);
+ for (int index = 0; device && index < VP_DEVICE_SLOTS && !added; index++) {
+ if (vpDevices[index] != MACH_PORT_NULL) continue;
+ vpDevices[index] = *connection;
+ atomic_fetch_add(&vpDeviceCount, 1);
+ added = true;
+ }
+ os_unfair_lock_unlock(&vpDeviceLock);
+ if (added) vpNoteFirstDevice();
+ // Untranslated, this client would call the wrong methods.
+ if (device && !added) {
+ IOServiceClose(*connection);
+ *connection = MACH_PORT_NULL;
+ return kIOReturnNoResources;
+ }
+ return result;
+}
+
+static kern_return_t (*vpServiceClose)(io_connect_t);
+static kern_return_t vpServiceCloseHook(io_connect_t connection) {
+ os_unfair_lock_lock(&vpDeviceLock);
+ vpForgetLocked(connection);
+ os_unfair_lock_unlock(&vpDeviceLock);
+ return vpServiceClose(connection);
+}
+
+static kern_return_t (*vpCallMethod)(mach_port_t, uint32_t, const uint64_t *, uint32_t, const void *, size_t,
+ uint64_t *, uint32_t *, void *, size_t *);
+static kern_return_t vpCallMethodHook(mach_port_t connection, uint32_t selector,
+ const uint64_t *input, uint32_t inputCount, const void *inputStruct, size_t inputStructSize,
+ uint64_t *output, uint32_t *outputCount, void *outputStruct, size_t *outputStructSize) {
+ if (!vpIsDevice(connection))
+ return vpCallMethod(connection, selector, input, inputCount, inputStruct, inputStructSize,
+ output, outputCount, outputStruct, outputStructSize);
+ uint32_t modern;
+ VPIOS18GPUSelectorAction action = vpIOS18GPUSelector(selector, &modern);
+ if (action == VPIOS18GPUAnswerLocally) return KERN_SUCCESS;
+
+ if (selector == VP_IOS18_GPU_RESOURCE_CREATE && outputStruct && outputStructSize &&
+ *outputStructSize >= VP_IOS18_GPU_RESOURCE_HEADER) {
+ size_t legacySize = *outputStructSize, size = legacySize + VP_IOS18_GPU_RESOURCE_GROWTH;
+ uint8_t *reply = calloc(1, size);
+ if (!reply) return kIOReturnNoMemory;
+ kern_return_t result = vpCallMethod(connection, modern, input, inputCount, inputStruct, inputStructSize,
+ output, outputCount, reply, &size);
+ if (result == KERN_SUCCESS && !vpIOS18GPUResourceReply(outputStruct, legacySize, reply, size))
+ result = kIOReturnBadArgument;
+ free(reply);
+ if (result == KERN_SUCCESS) *outputStructSize = legacySize;
+ return result;
+ }
+ if (selector == VP_IOS18_GPU_DEVICE_INFO && outputStruct && outputStructSize &&
+ *outputStructSize == VP_IOS18_GPU_DEVICE_INFO_LEGACY) {
+ uint8_t reply[VP_IOS18_GPU_DEVICE_INFO_MODERN] = {0};
+ size_t size = sizeof(reply);
+ kern_return_t result = vpCallMethod(connection, modern, input, inputCount, inputStruct, inputStructSize,
+ output, outputCount, reply, &size);
+ if (result != KERN_SUCCESS) return result;
+ if (size != sizeof(reply)) return kIOReturnBadArgument;
+ vpIOS18GPUDeviceInfoReply(outputStruct, reply);
+ *outputStructSize = VP_IOS18_GPU_DEVICE_INFO_LEGACY;
+ return KERN_SUCCESS;
+ }
+ return vpCallMethod(connection, modern, input, inputCount, inputStruct, inputStructSize,
+ output, outputCount, outputStruct, outputStructSize);
+}
+
+static kern_return_t (*vpCallAsyncMethod)(mach_port_t, uint32_t, mach_port_t, uint64_t *, uint32_t,
+ const uint64_t *, uint32_t, const void *, size_t, uint64_t *, uint32_t *, void *, size_t *);
+static kern_return_t vpCallAsyncMethodHook(mach_port_t connection, uint32_t selector, mach_port_t wake,
+ uint64_t *reference, uint32_t referenceCount, const uint64_t *input, uint32_t inputCount,
+ const void *inputStruct, size_t inputStructSize, uint64_t *output, uint32_t *outputCount,
+ void *outputStruct, size_t *outputStructSize) {
+ uint32_t modern = selector;
+ if (vpIsDevice(connection) && vpIOS18GPUSelector(selector, &modern) == VPIOS18GPUAnswerLocally)
+ return KERN_SUCCESS;
+ return vpCallAsyncMethod(connection, modern, wake, reference, referenceCount, input, inputCount,
+ inputStruct, inputStructSize, output, outputCount, outputStruct, outputStructSize);
+}
+
+// MARK: - Install
+
+void vpInstallIOS18GPUTransport(void) {
+ if (getpid() == 1 || !strcmp(getprogname(), "xpcproxy") || access(VP_IOS18_GPU_MARKER, F_OK) != 0) return;
+ // Device connections are only recorded once IOServiceOpen is detoured,
+ // which happens last: until both call paths translate, none is.
+ MISFixDetourResult call = MISFixDetour("IOConnectCallMethod", (void *)&IOConnectCallMethod,
+ (void *)vpCallMethodHook, (void **)&vpCallMethod);
+ MISFixDetourResult async = call ? call : MISFixDetour("IOConnectCallAsyncMethod",
+ (void *)&IOConnectCallAsyncMethod, (void *)vpCallAsyncMethodHook, (void **)&vpCallAsyncMethod);
+ MISFixDetourResult closing = async ? async : MISFixDetour("IOServiceClose", (void *)&IOServiceClose,
+ (void *)vpServiceCloseHook, (void **)&vpServiceClose);
+ MISFixDetourResult open = async ? async : MISFixDetour("IOServiceOpen", (void *)&IOServiceOpen,
+ (void *)vpServiceOpenHook, (void **)&vpServiceOpen);
+ if (call || async || closing || open)
+ fprintf(stderr, "[ios18-gpu] %s transport: call=%s async=%s close=%s open=%s\n", getprogname(),
+ MISFixDetourDescribe(call), MISFixDetourDescribe(async), MISFixDetourDescribe(closing),
+ MISFixDetourDescribe(open));
+}
diff --git a/VPhoneGuestComponents/SystemHook/VPhoneIOS18GPUTransport.c b/VPhoneGuestComponents/SystemHook/VPhoneIOS18GPUTransport.c
new file mode 100644
index 00000000..46815236
--- /dev/null
+++ b/VPhoneGuestComponents/SystemHook/VPhoneIOS18GPUTransport.c
@@ -0,0 +1,24 @@
+#include "VPhoneIOS18GPUTransport.h"
+#include <string.h>
+
+VPIOS18GPUSelectorAction vpIOS18GPUSelector(uint32_t legacy, uint32_t *modern) {
+ *modern = legacy;
+ if (legacy == 6) return VPIOS18GPUAnswerLocally;
+ if (legacy < 7 || legacy > 255) return VPIOS18GPUForward;
+ *modern = legacy - 1;
+ return VPIOS18GPURenumbered;
+}
+
+bool vpIOS18GPUResourceReply(uint8_t *legacy, size_t legacySize, const uint8_t *modern, size_t modernSize) {
+ if (legacySize < VP_IOS18_GPU_RESOURCE_HEADER || modernSize != legacySize + VP_IOS18_GPU_RESOURCE_GROWTH)
+ return false;
+ memcpy(legacy, modern, 0x18);
+ memcpy(legacy + 0x18, modern + 0x18 + VP_IOS18_GPU_RESOURCE_GROWTH, legacySize - 0x18);
+ return true;
+}
+
+void vpIOS18GPUDeviceInfoReply(uint8_t legacy[VP_IOS18_GPU_DEVICE_INFO_LEGACY],
+ const uint8_t modern[VP_IOS18_GPU_DEVICE_INFO_MODERN]) {
+ memcpy(legacy, modern, 0xd8);
+ memcpy(legacy + 0xd8, modern + 0xdc, 0x34);
+}
diff --git a/VPhoneGuestComponents/SystemHook/VPhoneIOS18GPUTransport.h b/VPhoneGuestComponents/SystemHook/VPhoneIOS18GPUTransport.h
new file mode 100644
index 00000000..ba565055
--- /dev/null
+++ b/VPhoneGuestComponents/SystemHook/VPhoneIOS18GPUTransport.h
@@ -0,0 +1,42 @@
+#pragma once
+#include <stdbool.h>
+#include <stddef.h>
+#include <stdint.h>
+
+// iOS 18's IOGPU.framework and paravirtual Metal driver against cloudOS
+// 26.1's IOGPUFamily and AppleParavirtGPU user clients. Measured by diffing
+// every IOConnectCall site of the 18.6.2 (22G100) and 26.1 (23B85) IOGPU
+// builds; see Research/Guest/ios18_gpu_transport.md.
+
+// The device user client, opened as `1 | (api << 16)`.
+enum { VP_IOS18_GPU_DEVICE_CLIENT = 1 };
+
+typedef enum {
+ VPIOS18GPUForward, // call the kernel with the selector as given
+ VPIOS18GPURenumbered, // call the kernel with the returned selector
+ VPIOS18GPUAnswerLocally, // 26.1 has no such method; report success
+} VPIOS18GPUSelectorAction;
+
+// 26.1 removed method 6 (the client's API name, whose result IOGPU ignores)
+// and moved methods 7..255 down by one. Driver methods from 256 are unchanged.
+VPIOS18GPUSelectorAction vpIOS18GPUSelector(uint32_t legacy, uint32_t *modern);
+
+// iOS 18's resource-create method (9, 8 on 26.1). Its reply gained eight
+// bytes at 0x18; the 0x50-byte header and the driver's tail are otherwise
+// unchanged.
+enum {
+ VP_IOS18_GPU_RESOURCE_CREATE = 9,
+ VP_IOS18_GPU_RESOURCE_HEADER = 0x50,
+ VP_IOS18_GPU_RESOURCE_GROWTH = 8,
+};
+bool vpIOS18GPUResourceReply(uint8_t *legacy, size_t legacySize, const uint8_t *modern, size_t modernSize);
+
+// AppleParavirtGPU's device-info method. Each of its two blocks gained fields
+// at its end: 0xd8 -> 0xdc and 0x34 -> 0x3c.
+enum {
+ VP_IOS18_GPU_DEVICE_INFO = 265,
+ VP_IOS18_GPU_DEVICE_INFO_LEGACY = 0x10c,
+ VP_IOS18_GPU_DEVICE_INFO_MODERN = 0x118,
+};
+void vpIOS18GPUDeviceInfoReply(uint8_t legacy[VP_IOS18_GPU_DEVICE_INFO_LEGACY],
+ const uint8_t modern[VP_IOS18_GPU_DEVICE_INFO_MODERN]);
diff --git a/VPhoneGuestComponents/Tests/IOS18GPUTransportTest.c b/VPhoneGuestComponents/Tests/IOS18GPUTransportTest.c
new file mode 100644
index 00000000..60365016
--- /dev/null
+++ b/VPhoneGuestComponents/Tests/IOS18GPUTransportTest.c
@@ -0,0 +1,40 @@
+#include "VPhoneIOS18GPUTransport.h"
+#include <assert.h>
+#include <stdio.h>
+#include <string.h>
+
+int main(void) {
+ uint32_t modern;
+ // Below the removed method, and the driver's own methods, pass through.
+ for (uint32_t selector = 0; selector < 6; selector++) {
+ assert(vpIOS18GPUSelector(selector, &modern) == VPIOS18GPUForward && modern == selector);
+ }
+ assert(vpIOS18GPUSelector(6, &modern) == VPIOS18GPUAnswerLocally);
+ // Command queue create, resource create and the last base method measured.
+ assert(vpIOS18GPUSelector(7, &modern) == VPIOS18GPURenumbered && modern == 6);
+ assert(vpIOS18GPUSelector(9, &modern) == VPIOS18GPURenumbered && modern == 8);
+ assert(vpIOS18GPUSelector(0x37, &modern) == VPIOS18GPURenumbered && modern == 0x36);
+ assert(vpIOS18GPUSelector(255, &modern) == VPIOS18GPURenumbered && modern == 254);
+ for (uint32_t selector = 256; selector < 270; selector++) {
+ assert(vpIOS18GPUSelector(selector, &modern) == VPIOS18GPUForward && modern == selector);
+ }
+
+ // The new eight bytes at 0x18 are dropped; both sides of them are kept.
+ uint8_t wide[0x60], narrow[0x58];
+ for (size_t index = 0; index < sizeof(wide); index++) wide[index] = (uint8_t)index;
+ memset(narrow, 0xEE, sizeof(narrow));
+ assert(vpIOS18GPUResourceReply(narrow, sizeof(narrow), wide, sizeof(wide)));
+ for (size_t index = 0; index < 0x18; index++) assert(narrow[index] == index);
+ for (size_t index = 0x18; index < sizeof(narrow); index++) assert(narrow[index] == index + 8);
+ assert(!vpIOS18GPUResourceReply(narrow, sizeof(narrow), wide, sizeof(wide) - 1));
+ assert(!vpIOS18GPUResourceReply(narrow, 0x4F, wide, 0x4F + 8));
+
+ uint8_t info[VP_IOS18_GPU_DEVICE_INFO_MODERN], legacy[VP_IOS18_GPU_DEVICE_INFO_LEGACY];
+ for (size_t index = 0; index < sizeof(info); index++) info[index] = (uint8_t)(index * 7);
+ vpIOS18GPUDeviceInfoReply(legacy, info);
+ for (size_t index = 0; index < 0xd8; index++) assert(legacy[index] == info[index]);
+ for (size_t index = 0; index < 0x34; index++) assert(legacy[0xd8 + index] == info[0xdc + index]);
+
+ puts("IOS18GPUTransportTest: ok");
+ return 0;
+}
diff --git a/VPhoneKit/VPhoneCoreKit/Firmware/VPhoneFirmwareCatalog.swift b/VPhoneKit/VPhoneCoreKit/Firmware/VPhoneFirmwareCatalog.swift
index e195fcd9..f230428f 100644
--- a/VPhoneKit/VPhoneCoreKit/Firmware/VPhoneFirmwareCatalog.swift
+++ b/VPhoneKit/VPhoneCoreKit/Firmware/VPhoneFirmwareCatalog.swift
@@ -559,6 +559,15 @@ public enum VPhoneFirmwareCatalog {
.init(name: "cloudOS 18.7.2 (22H43)", url: "https://updates.cdn-apple.com/private-cloud-compute/d425a03c76f1ddb92a65a27d56e80beffe399605018d4d268f5ef8889d0ec9e7")),
]
+ /// The cloudOS of an iOS 18 release's own major and minor version. Its
+ /// paravirtual GPU driver is the one that release's userland can load.
+ public static func iOS18CloudOS(forVersion version: String) -> VPhoneCloudOSOption? {
+ let release = version.split(separator: ".").prefix(2).joined(separator: ".")
+ return iOS18ResearchBoardReleases.first {
+ $0.version.split(separator: ".").prefix(2).joined(separator: ".") == release
+ }?.cloudOS
+ }
+
/// Full OTAs of devices without an IPSW, oldest first. Each has a
/// `tvReleases` entry of its `baseVersion` for its `restoreBase`. The keys
/// are from AppleDB or the device's Pallas response.
diff --git a/VPhoneKit/VPhoneCoreKit/Firmware/VPhonePCCGPUDriver.swift b/VPhoneKit/VPhoneCoreKit/Firmware/VPhonePCCGPUDriver.swift
index f9b2f9f3..7a62ba97 100644
--- a/VPhoneKit/VPhoneCoreKit/Firmware/VPhonePCCGPUDriver.swift
+++ b/VPhoneKit/VPhoneCoreKit/Firmware/VPhonePCCGPUDriver.swift
@@ -42,6 +42,12 @@ public enum VPhonePCCGPUDriver {
print("[+] GPU driver staged: \(destination.path)")
}
+ /// A point release's driver names the SDK it was built with: cloudOS
+ /// 18.7.2 ships one that says 18.7. Compare major and minor only.
+ public static func release(_ version: String) -> String {
+ version.split(separator: ".").prefix(2).joined(separator: ".")
+ }
+
static func validateBundle(at source: URL, expectedPlatformVersion: String) throws {
let fm = FileManager.default
var isDirectory: ObjCBool = false
@@ -64,11 +70,6 @@ public enum VPhonePCCGPUDriver {
"com.apple.driver.AppleParavirtGPUMetalIOGPUFamily"
else { throw Error.invalidBundle(source) }
let actual = properties["DTPlatformVersion"] as? String ?? "unknown"
- // A point release's driver names the SDK it was built with: cloudOS
- // 18.7.2 ships one that says 18.7.
- func release(_ version: String) -> String {
- version.split(separator: ".").prefix(2).joined(separator: ".")
- }
guard release(actual) == release(expectedPlatformVersion) else {
throw Error.wrongPlatformVersion(
source,
diff --git a/VPhoneKit/VPhoneCoreKitTests/Firmware/FirmwareCatalogReportTests.swift b/VPhoneKit/VPhoneCoreKitTests/Firmware/FirmwareCatalogReportTests.swift
index 15eefe3e..6358f1f9 100644
--- a/VPhoneKit/VPhoneCoreKitTests/Firmware/FirmwareCatalogReportTests.swift
+++ b/VPhoneKit/VPhoneCoreKitTests/Firmware/FirmwareCatalogReportTests.swift
@@ -308,6 +308,14 @@ struct FirmwareCatalogReportTests {
#expect(VPhoneFirmwareCatalog.recommendedCloudOS(forDevice: "AppleTV5,3", version: "26.1", url: "").url == VPhoneFirmwareCatalog.cloud264)
}
+ @Test func `an iOS 18 release takes the GPU driver of its own release's cloudOS`() {
+ #expect(VPhoneFirmwareCatalog.iOS18CloudOS(forVersion: "18.6.2")?.name == "cloudOS 18.6 (22G86)")
+ #expect(VPhoneFirmwareCatalog.iOS18CloudOS(forVersion: "18.6")?.name == "cloudOS 18.6 (22G86)")
+ #expect(VPhoneFirmwareCatalog.iOS18CloudOS(forVersion: "18.7.2")?.name.hasPrefix("cloudOS 18.7") == true)
+ #expect(VPhoneFirmwareCatalog.iOS18CloudOS(forVersion: "18.4") == nil)
+ #expect(VPhoneFirmwareCatalog.iOS18CloudOS(forVersion: "26.1") == nil)
+ }
+
@Test func `round trips JSON`() throws {
let report = VPhoneFirmwareCatalog.report
let back = try JSONDecoder().decode(VPhoneFirmwareCatalogReport.self, from: JSONEncoder().encode(report))