Skip to content

Run a virtual iPhone on an Apple Silicon Mac.

Swift

Duo: let DeviceHub follow the fold

Jacky792e0e39e1c5
diff --git a/Research/0_binary_patch_comparison.md b/Research/0_binary_patch_comparison.md
index 664aca98..a6506fb6 100644
--- a/Research/0_binary_patch_comparison.md
+++ b/Research/0_binary_patch_comparison.md
@@ -1602,7 +1602,7 @@ do NOT execute these).
| 23 | No binary change: `libvcamcaptured.dylib`, which SystemHook already loads into `cameracaptured`, rewrites the `bl PrewarmThreadSafeSBPs` in `__FigCapturePreloadShadersInternal_block_invoke_2` to `nop` in the daemon's own memory. This runs from the dylib's constructor and only when the paravirtual Metal driver is installed — **all bases** | none (guest dylib `VPhoneGuestComponents/VCamCaptured/Prewarm/`, installed at `/usr/lib/libvcamcaptured.dylib`) | **Stop `cameracaptured` crashing at every boot, and the SpringBoard freeze that follows.** At launch the daemon preloads its shaders. `PrewarmThreadSafeSBPs` runs each video processor's `-prewarm`, and NRFV3's reaches `-[ToneMappingCurves initWithWithContext:]`, which fills textures made from a shared `MTLHeap` with `-replaceRegion:…`. The cloudOS 26.4 `AppleParavirtGPUMetalIOGPUFamily` never sets `_dimension` (a texture's CPU layout) in `-initWithHeap:resource:offset:length:descriptor:`, and `-replaceRegion:` loads it unchecked, so the daemon faults with `KERN_INVALID_ADDRESS` at `0xc` (measured on `iPad16,1 26.6.2 (23G90)`, `standard`: launchd at `successive crashes = 6`). While the daemon crash-loops, SpringBoard's main thread blocked in a synchronous XPC to it as soon as an app started recording. The daemon does have a Metal device, so `kernel-exp-paravirt_user_clients` does not help. Prewarming is only an optimisation, and nothing waits on that function: no return value, no global, no signal. The rest of the preload (processor flags, data migration, and the deferred shader cache copy, whose semaphore deferred processing waits on) is kept. The call site is found from the exported `FigCapturePreloadShaders`: its `b` to the internal function, that function's one `adrp/add/pacia x16` block invoke, then the block's one `ldr x0, [xN, #0x20]; bl` into CMCapture's `__text`. That gives `0x1aeb2fd68` on 23G90 and `0x1b0759d10` on 24A435. Any mismatch leaves the prewarm in place and logs the step that failed. Host test: `make -C VPhoneGuestComponents test-vcam-prewarm`. Validation: `vcamcaptured.log` has `gpu prewarm: … skipped`, no new `cameracaptured` crash report, and `successive crashes = 0`. See `Research/Guest/gpu_acceleration.md` ("Heap Textures Have No CPU Layout"). | Y | Y | Y |
| 24 | No binary change: both spawn hooks insert `libbatteryhealthfix.dylib` into `Settings` (`/Applications/Preferences.app/Preferences`) beside SystemHook, where it interposes `IOPSCopyPowerSourcesInfo`, `IOPSCopyPowerSourcesByType`, `IOPSCopyPowerSourcesByTypePrecise`, `notify_register_check` / `notify_get_state` / `notify_cancel` and `MGGetBoolAnswer` — **all bases** | none (new guest dylib `VPhoneGuestComponents/BatteryHealthFix/libbatteryhealthfix.c`, installed at `/usr/lib/libbatteryhealthfix.dylib`) | **Stop Settings → Battery → Battery Health & Charging loading forever.** The VM's battery is Virtualization.framework's synthetic power source (charge and connectivity only), and the health half of a real battery's description comes from AppleSmartBattery, which no VM has. Measured on `iPhone17,3 27.0 (24A435)`: powerd's internal battery description has one `BatteryPacks` entry holding only `PackID`, `Cycle count` and `Transport Type`, no `Battery Service State`/`Flags` or `Maximum Capacity Percent` anywhere, and `com.apple.thermalmonitor.ageAwareMitigationState` stays 0. `-[BatteryHealthUIController specifiers]` asks `-[BatteryHealthUIInformation batteryDataUnavailable]`, which answers YES while `+getManagementState` is 0, while no pack parses (`-[BatteryHealthUIPackInformation initWithPowerSourceInformation:]` drops a pack without service flags and state), or while the overall genuine status is -1 — and it is -1 because `MGGetBoolAnswer("D6/BMDrlb8V3WSiqL8gL+w")` (HasBatteryModuleAuth, `+[PLGestaltUtilities hasBatteryModuleAuth]`) answers 1 on the guest, sending `+genuineBatteryStatusForPackIndex:` to an `AppleBatteryAuth`/`AppleAuthCPRelay` service that does not exist. The controller then shows its global spinner and re-asks on a timer. iPadOS 26.6.2 (23G90) has the same gate in `+[BatteryUIResourceClass batteryDataUnavailable]`, reading the flat keys of `IOPSCopyPowerSourcesByType`'s array, the same notify name and the same MobileGestalt key. The hook answers as a new battery without battery authentication: each internal-battery description is copied with `Battery Service State` 0, `Battery Service Flags` 0, `Maximum Capacity Percent` 100 and `Cycle count` 0 at the top level, and each of powerd's packs (or one new pack) completed with a `BatteryHealth` dictionary of the same three numbers plus `Date of manufacture`/`Date of first use` (the birth time of `/private/var/mobile`, i.e. the restore); keys already present are never replaced, and a description that already has them is passed through. A mitigation state of 0 on a token registered for the age-aware name reads as 2 ("supporting normal peak performance"). HasBatteryModuleAuth reads as no only while `IOServiceGetMatchingService("AppleBatteryAuth")` finds nothing. Interposing reaches the callers because `BatteryUsageUI.bundle` is a standalone Mach-O bound through dyld's interposing table (cache-to-cache calls are not; see `MISFix/MISFixSignature.c`), and inserting it — rather than SystemHook `dlopen`ing it like row 21 — is what puts the table in place before the bundle loads. `vpInsertedLibraryFor` in `Shared/InjectionEnvironment.h` picks it or libmisfix for a path; the two target sets do not overlap. Ships with `system-launchdaemons-boot-environment`; existing guests get it from the vphoned environment update on their next start with the new bundle (offline `cfw update-environment` only replaces libraries a VM already has). launchd starts Settings itself, so it is the launchd hook that inserts it: a guest updated only by that online sync needs one more reboot before launchd runs the new hook, which the update already reports as `reboot_required`; an offline environment update replaces the hook before boot. **Validated (2026-10-04, `bhtest-iphone`, `iPhone17,3 27.0 (24A435)` + cloudOS 26.4):** before, the page showed only the spinner and the two charging switches; after, Maximum Capacity 100%, Peak Performance Capability "Your battery is currently supporting normal peak performance", the two switches, no spinner; the hook's log shows all three answers taken once per process. Re-checked on the final bundle after a reboot of the same guest, with the launchd hook logging `inserted+batteryhealthfix` for each Settings launch. **iPad16,1 26.6.2 (23G90), `bhtest-ipad`, created with the new bundle:** the hook is inserted and stays inert, and Settings runs without a crash; that iPad has no Battery Health page at all, because `-[BatteryUIController setUpBatteryHealthGroup]` offers the row only on an iPhone or, through `+[PLBatteryUIBackendModel shouldShowModifiedHealthController]`, on an iPad that supports the fixed charge limit with the `PerfPowerServices/battery_health_details` feature on — the model decides, as on hardware. The 26.x gate inside the page is from static analysis; no 26.x iPhone image was at hand to run it. | Y | Y | Y |
| 25 | No binary change: `libvcamcaptured.dylib` stops every other thread in `cameracaptured` (`task_threads` + `thread_suspend`, self excluded, one patcher at a time) around each `vcc_patch_word` / `vcc_patch_two_nops` text rewrite — **all bases** | none (guest dylib `VPhoneGuestComponents/VCamCaptured/Image/VCamCodePatch.m`, installed at `/usr/lib/libvcamcaptured.dylib`) | **Stop the hook's own runtime patching from crashing `cameracaptured`, which froze the whole VM when the camera was opened.** The hook rewrites CMCapture shared-cache `__text` through `vm_protect(RW|COPY)` → write → `vm_protect(RX)`; for the whole flip the 16K page carries no execute permission, and the pages it touches (the `-12783` error-code sites, the master-clock gate, the prewarm call) are live XPC server code. Two crash reports caught a thread fetching an instruction in a page mid-flip while the patching thread was in `vcc_patch_word` on the same boot: `ipad-mini-01` `cameracaptured-2026-10-03-045638.ips` died in `__FigFlashlightGetClassID_block_invoke` on `com.apple.coremedia.flashlight(34)-messages`, and `ipad-pro-13` `cameracaptured-2026-10-04-225558.ips` died in `captureSourceServer_handleRegisterNotificationForProprietaryDefaultChangesMessage` on `com.apple.coremedia.capturesource(523)-messages` — the register-for-source-changes XPC that camera enumeration itself sends. Both are `EXC_BAD_ACCESS (SIGBUS)`, `KERN_PROTECTION_FAILURE` on an instruction fetch, in a region snapshotted `r-x/rwx`, `SM=COW` (the rwx max-protection is the flip's fingerprint). The card: with row 23 removing the boot crash, any later `cameracaptured` restart (jetsam, another crash) while a camera client reconnects sends its first XPCs straight into the +3 s reinstall window; one SIGBUS → launchd throttles → every AVCapture client, SpringBoard's main thread included, blocks forever in a synchronous XPC — the "VM 卡死" report of 2026-10-05. The stopped section is exactly two `vm_protect` calls, the word write and `sys_icache_invalidate`: no locks, no allocation, no logging, so a frozen thread holding any userspace lock cannot deadlock the patcher; every `vcc_log` moved after the resume, and a mutex serialises patchers (constructor prewarm patch vs the +3 s install block). All five runtime text-patching call sites (`vcc_scan_and_patch` ×2, the prewarm NOP, the session-hook pair, the source-installation NOPs) funnel through the two fixed functions. Validation: kill-and-relaunch stress with Camera.app auto-reconnecting (the same collision that produced both crashes) produces no new `cameracaptured` crash report, and the boot log's `patch_word OK` lines are unchanged. See `Research/Guest/virtual_camera_transport.md` ("The patch race that froze the whole VM"). | Y | Y | Y |
-| 26 | No binary change: both spawn hooks insert `libdevicehubfix.dylib` into `cryptexd`, the DDI's `dtremotedisplayd` and `dtdeviceinfod`, and `avconferenced`. In `cryptexd` it interposes `fcntl` and reports an `EPERM` from `F_SETPROTECTIONCLASS` as `ENOTSUP`; in `dtremotedisplayd` it interposes `MediaStreamSupportedFeatures.current` (answers `0x8c`) and `CurrentDevice.isCustomerRestricted` (answers false) from the DDI's `CoreDeviceUtilities`; in `dtdeviceinfod` it interposes `MGCopyAnswer` and fills a missing `FramebufferIdentifier` for `phone11` chrome; in `avconferenced` it replaces `VCPSideCarMetal`'s two band reads through the Objective-C runtime and runs one synchronous scaler transform before the first read of each frame — **all bases** | none (new guest dylib `VPhoneGuestComponents/DeviceHubFix/libdevicehubfix.c`, installed at `/usr/lib/libdevicehubfix.dylib`) | **Let Xcode 27's DeviceHub show the guest's screen.** On iOS 27 `cryptexd` stages each DDI asset with `open(O_RDWR)` + `fcntl(F_SETPROTECTIONCLASS, 4)` and accepts only `ENOTSUP` as a failure; a guest answers `EPERM` (`set protection class: [1: Operation not permitted]`, `staging failed`), so CoreDevice shows the device as "connected (no DDI)" for good. With the DDI mounted, DeviceHub asks `dtremotedisplayd` for its media stream features and gets 0 from CoreDeviceUtilities' policy: `isCustomerRestricted` (`isProductionFused && !hasInternalOSBuild && hasInternalDDI == false`) refuses every pre-27.0 device, and remote control is limited to iPhone, Apple Watch and Apple TV, which refuses every iPad. `0x8c` is what a Mac host reports for itself (mirrored primary display 0x4, system audio 0x8, display information 0x80). The 27.x iPhone guest reports `phone11` chrome with no `FramebufferIdentifier`, so DeviceHub drew the screen over the bezel corners; the hook answers only that missing key with Xcode's matching mask `4E5532ED-1470-47D1-BDF4-7AA90C26957A` from `/Library/Developer/DeviceKit/chrome_map.plist`. Interposing reaches all of them because `cryptexd`, `dtremotedisplayd`, `dtdeviceinfod` and `CoreDeviceUtilities` are standalone images; the two Swift symbols are weak flat-namespace imports, resolving to nothing outside `dtremotedisplayd`. On 27.x the view also needs row 11's conditional dispatch, or the capture display stays black. A stream that splits each frame into four bands (`tilesPerFrame` 4) deadlocked the host GPU within 16–35 s of screen activity: `VCPSideCarMetal` reads every frame once per band while the paravirtual scaler's write of that frame can still be unregistered on the host, and a band read that registers the first of the frame's two planes before the write and the second after it waits on the write, which waits on it (`Timeout in timestamp wait`, the guest loses its GPU). Waiting for one synchronous transform puts the band reads behind the frame's write. `VideoProcessing` is in the shared cache, so this part is a method replacement, not an interpose. Ships with `system-launchdaemons-boot-environment`; an existing guest gets it from the environment update. Details: `Research/Guest/devicehub_screen_viewing.md`. **Validated (2026-10-06/07):** `iPad16,1 26.6.2 (23G90)`: DeviceHub receives `supportedFeatures: 140`, `MediaStreamStart` succeeds and the view shows the live home screen. `iPhone17,3 27.0.1 (24A446)`: the DDI mounts (`F_SETPROTECTIONCLASS EPERM, reported as ENOTSUP`), and with row 11's conditional dispatch DeviceHub shows the home screen and Settings live, clipped inside the chrome (`Found FramebufferMaskIdentifier from displayInfo`). **Band reads validated (2026-10-07/08, `iPhone17,3 27.0.1 (24A446)`):** a four-band stream with screen activity deadlocked after 18 s without the barrier and ran 60, 180 and 300 s with it without a GPU error; in the host trace of the 180 s run no IOSurface access waited, and every band read of 6258 frames registered after the frame's write was released, a median 0.76 ms after it. Open: latency that grows over a long session and occasional stalls after a cold start, both upstream of the Mac receiver. | Y | Y | Y |
+| 26 | No binary change: both spawn hooks insert `libdevicehubfix.dylib` into `cryptexd`, the DDI's `dtremotedisplayd` and `dtdeviceinfod`, and `avconferenced`. In `cryptexd` it interposes `fcntl` and reports an `EPERM` from `F_SETPROTECTIONCLASS` as `ENOTSUP`; in `dtremotedisplayd` it interposes `MediaStreamSupportedFeatures.current` (answers `0x8c`) and `CurrentDevice.isCustomerRestricted` (answers false) from the DDI's `CoreDeviceUtilities`; in `dtdeviceinfod` it interposes `MGCopyAnswer` and fills a missing `FramebufferIdentifier` for `phone11` chrome, and stands in for CoreMotion's `CMAngleManager` and `CMDeviceStateManager` (the foldable hinge and pose DeviceHub draws from); in `avconferenced` it replaces `VCPSideCarMetal`'s two band reads through the Objective-C runtime and runs one synchronous scaler transform before the first read of each frame — **all bases** | none (new guest dylib `VPhoneGuestComponents/DeviceHubFix/libdevicehubfix.c`, installed at `/usr/lib/libdevicehubfix.dylib`) | **Let Xcode 27's DeviceHub show the guest's screen.** On iOS 27 `cryptexd` stages each DDI asset with `open(O_RDWR)` + `fcntl(F_SETPROTECTIONCLASS, 4)` and accepts only `ENOTSUP` as a failure; a guest answers `EPERM` (`set protection class: [1: Operation not permitted]`, `staging failed`), so CoreDevice shows the device as "connected (no DDI)" for good. With the DDI mounted, DeviceHub asks `dtremotedisplayd` for its media stream features and gets 0 from CoreDeviceUtilities' policy: `isCustomerRestricted` (`isProductionFused && !hasInternalOSBuild && hasInternalDDI == false`) refuses every pre-27.0 device, and remote control is limited to iPhone, Apple Watch and Apple TV, which refuses every iPad. `0x8c` is what a Mac host reports for itself (mirrored primary display 0x4, system audio 0x8, display information 0x80). The 27.x iPhone guest reports `phone11` chrome with no `FramebufferIdentifier`, so DeviceHub drew the screen over the bezel corners; the hook answers only that missing key with Xcode's matching mask `4E5532ED-1470-47D1-BDF4-7AA90C26957A` from `/Library/Developer/DeviceKit/chrome_map.plist`. Interposing reaches all of them because `cryptexd`, `dtremotedisplayd`, `dtdeviceinfod` and `CoreDeviceUtilities` are standalone images; the two Swift symbols are weak flat-namespace imports, resolving to nothing outside `dtremotedisplayd`. On 27.x the view also needs row 11's conditional dispatch, or the capture display stays black. A stream that splits each frame into four bands (`tilesPerFrame` 4) deadlocked the host GPU within 16–35 s of screen activity: `VCPSideCarMetal` reads every frame once per band while the paravirtual scaler's write of that frame can still be unregistered on the host, and a band read that registers the first of the frame's two planes before the write and the second after it waits on the write, which waits on it (`Timeout in timestamp wait`, the guest loses its GPU). Waiting for one synchronous transform puts the band reads behind the frame's write. `VideoProcessing` is in the shared cache, so this part is a method replacement, not an interpose. Ships with `system-launchdaemons-boot-environment`; an existing guest gets it from the environment update. Details: `Research/Guest/devicehub_screen_viewing.md`. **Validated (2026-10-06/07):** `iPad16,1 26.6.2 (23G90)`: DeviceHub receives `supportedFeatures: 140`, `MediaStreamStart` succeeds and the view shows the live home screen. `iPhone17,3 27.0.1 (24A446)`: the DDI mounts (`F_SETPROTECTIONCLASS EPERM, reported as ENOTSUP`), and with row 11's conditional dispatch DeviceHub shows the home screen and Settings live, clipped inside the chrome (`Found FramebufferMaskIdentifier from displayInfo`). **Band reads validated (2026-10-07/08, `iPhone17,3 27.0.1 (24A446)`):** a four-band stream with screen activity deadlocked after 18 s without the barrier and ran 60, 180 and 300 s with it without a GPU error; in the host trace of the 180 s run no IOSurface access waited, and every band read of 6258 frames registered after the frame's write was released, a median 0.76 ms after it. Open: latency that grows over a long session and occasional stalls after a cold start, both upstream of the Mac receiver. | Y | Y | Y |
| 27 | No binary change: both spawn hooks insert `libdevicename.dylib` into `configd` and `lockdownd` (after `libmisfix.dylib`, the first process to take two inserted libraries). In `configd` it interposes `SCDynamicStoreSetMultiple` and `SCDynamicStoreSetValue` and pins `Setup:/System`'s `ComputerName`; in `lockdownd` it interposes `SCPreferencesSetComputerName`, `SCPreferencesSetHostName` and `SCPreferencesSetLocalHostName` and refuses every rename with `kSCStatusAccessError`. Inert unless `/var/db/vphone/devicename.plist` holds a valid `DeviceName` — **all bases** | none (new guest dylib `VPhoneGuestComponents/DeviceName/libdevicename.c`, installed at `/usr/lib/libdevicename.dylib`; vphoned `device.name.get`/`device.name.set`) | **Pin the guest's device name to the VM's name.** The name is `System/System/ComputerName` in `preferences.plist`; configd's PreferencesMonitor (`updateConfiguration`, 24A435 `0x100062098`) flattens it into `Setup:/System` with one `SCDynamicStoreSetMultiple`, and every reader (`SCDynamicStoreCopyComputerName` in lockdownd's `copy_device_name`, MobileGestalt `UserAssignedDeviceName`, `UIDevice.name`) reads the store. The hook rewrites that publication, not the preferences read: the monitor's model-change path (`sub_10006155c`) writes the `kSCPrefSystem` value it reads back to disk, and the publication route leaves `preferences.plist` with the guest's own name. A publication that leaves `Setup:/System` out as unchanged gets the store's value pinned; one that removes it gets the pinned name instead. `vphone-vm` sends the VM's name to vphoned's `device.name.set` after every connect; vphoned writes the file (one rename, 0644) and applies the preferences unchanged, so configd publishes again and the new pin, or the guest's own name when the file is removed, is live within a second. The file outlives a reboot, so configd's first publication at boot carries it. The library re-reads the file when its inode, size or mtime change. lockdownd's `set_device_name` (`0x1000073b0`) is the only caller of the three setters; it logs their failure and still commits, and the `SetValue DeviceName` handler ignores the result, so a host rename reports success and the name stays. The pinned name itself is refused too: lockdownd runs `set_device_name(copy_device_name())` whenever it starts, and a lockdownd restarted after configd published would otherwise write the pinned name and derived host names into `preferences.plist` (seen once). An NVRAM variable was the first channel and never reached the guest: iBoot keeps only the variables it knows (even `vphone-vm`'s `boot-args` write is replaced). Interposing works because both daemons are standalone images. Ships with `system-launchdaemons-boot-environment` and the environment update; takes effect at the next boot. Verified on iOS 27.0 (24A435) on 2026-10-07: pin at boot and live, host rename refused, `vm rename` followed, preferences untouched. CoreDevice (`devicectl`, DeviceHub) reads the name when the device appears and can lag one boot after a rename. Details: `Research/Guest/device_name_pinning.md`. | Y | Y | Y |
| 28 | `cbz`/`cbnz` -> `b` at the four compact-command choices in `-[PGSerializerRenderCommandEncoder drawIndexedPrimitives:…]` (`0x140b0`, `0x1421c`, `0x143b4`, `0x143c4` in 23E5207q) — **cloudOS 26.4** | `AppleParavirtGPUMetalIOGPUFamily` (`/System/Library/Extensions/AppleParavirtGPUMetalIOGPUFamily.bundle`) | **Heap index buffer fix.** The compact command stores `parentResourceOffset + indexBufferOffset` in 16 bits but is chosen by testing `indexBufferOffset` alone, so an index buffer 64 KiB or more into an `MTLHeap` is read from the wrong address and meshes (Unity games) draw with another mesh's indices. Every indexed draw takes the 64-bit command instead. `system-paravirt_gpu-cfw-heap_index_offset`; see "Heap index buffers reach the host whole (2026-10-14)" and `Research/Guest/gpu_acceleration.md` | Y | Y | Y |
| 29 | No binary change: SystemHook calls `setenv("FS_CACHE_REUSE_ON_REBOOT", "1", 0)` first thing in its constructor, in every process it is inserted into, while `/usr/lib/vphone-metal-cache-reuse` exists — **all bases** | none (`VPhoneGuestComponents/SystemHook/SystemHook-vphone.c`; marker written by `cfw install` / `cfw update-environment`) | **Keep the guest's Metal shader caches across a reboot.** `libCoreFSCache` stamps each cache with `kern.bootsessionuuid` and resets it at the next boot unless the variable is set; on the paravirtual GPU CoreAnimation's precompiled pipelines are disabled, so backboardd rebuilt every pipeline after every boot. `system-systemhook-cfw-metal_cache_reuse`; see "Guest Metal caches survive a reboot (2026-10-19)" | Y | Y | Y |
@@ -5673,3 +5673,5 @@ The host VM view now derives its input geometry from the active Duo viewport (`a
> **Duo display: two displays only (2026-10-29):** `system-springboard-cfw-fold_display` (now titled "Foldable inner display") keeps only the two-display path, and it is always on for iPhone19,4: `libvphonefolddisplay.dylib` checks `hw.machine` in backboardd and SpringBoard instead of the `vphone-duo-inner-display` marker. backboardd: the 2853x2007 `CAWindowServerVirtualDisplay` added from `-[CAWindowServer _detectDisplays]` (server-ready fallback), tagged `unknown`; `DeviceSurfaceType` 1 for the primary and 2 for the inner display through `-[CAWindowServerDisplay extendedProperties]`; `BKHIDDirectTouchEventProcessor` digitizer routing and the 270° position turn while the inner display is lit. SpringBoard: the CADisplay type/pointScale/isExternal adapter with the FrontBoard classification scope, `mainLike` in the inner identity's XPC encoding, the inner screen's idiom, the shared scanout (`-[CADisplayStateControl transitionToDisplayState:withCompletion:]`), the compositor, the content mode resolver hand-over (the resolver is now recorded by a pass-through `-[SBFDisplayContentModeResolver _startResolvingContentModeOfDisplay:]`), and the per-screen `STUIStatusBarGetVisualProviderClassForScreen` detour. Removed hooks: the Main configuration transformer, monitor and identity observers, `SBWindowScene surfaceType`/`sbhScreenType`, `SBWindow _shouldResizeWithScene`, the scene geometry callback, the clock and time-item adapters, the scene status policy, the Main status lookup and status profile factories, `SBHScreenTypeFor*`, `_os_feature_enabled_impl` (`TraitsArbiterWallpaperTokyoDrift`), `PF_IS_PAD_DEVICE`, `_SBWallpaperSecureWindow setHidden:`, the quick-action glyph subclass, the `UIWindow` target-window fallback, the `SBSDeviceDeterminedConfiguration`/`CSProminentLayoutController` loggers, and every `com.vphone.display.*` notification. `libvphoneposterprobe.dylib` (the poster orientation follower) is no longer built, staged, listed in the guest environment, or loaded by SystemHook. Details in `Research/Guest/iphone_duo_bringup.md`.
> **Duo display: flicker, capture and rotation (2026-10-29):** in `system-springboard-cfw-fold_display`, the compositor is now a layer at the top of Main's `UIRootSceneWindow` (points) instead of a display-level `CAContext` (pixels), its hosts sync from a main run loop observer before Core Animation's commit and change only when a value changes, and its per-frame damage alternates two clear colors. New SpringBoard hook: `+[CMMagicPoseManager orientationForMagicPose:deviceSurface:]` answers with `+[CMDeviceStateEvent propertyAForConfigType:propertyA:propertyB:propertyC:]` directly, because the guest has no `CMMagicPoseManager` shared manager and every panel read ambiguous, so neither panel rotated. vphoned's `display.rotation` on a foldable sets the pose orientation for the lit panel. Details in `Research/Guest/iphone_duo_bringup.md`.
+
+> **Duo: folds through SpringBoard, and DeviceHub follows them (2026-10-29 night, PR Lakr233/vphone-cli#774):** no binary change. vphoned's `display.posture` `position` asks SpringBoard to fold itself through `SBSDisplayToolService` (entitlement `com.apple.springboard.sbdisplay.service`) and then sets only the virtual hinge (`Research/vphoned_http_api.md`, "Device pose"). In `system-springboard-cfw-fold_display`, `libvphonefolddisplay.dylib` (1) re-reads the shared panel's owner on `-[SpringBoard displayContentModeCoordinator:handleSwapTransitionFromPrimaryWindowScene:toPrimaryWindowScene:withContinuationLockProvider:]` as well, because a continuous close swaps the primary content as it finishes and the panel kept showing the (black) inner display for 3 s; and (2) in backboardd keeps every clone on the panel: `-[CAWindowServerDisplay addClone:options:]` on the inner render display attaches the clone to display 1 instead, and `removeClone:` removes a clone from its real `cloneMaster` (CoreAnimation aborts otherwise). backboardd moves a mirror (DeviceHub's capture display, AirPlay, recording) to the display with the primary content, so open it carried the inner display upright, while DeviceHub draws an open Duo's stream as the inner panel's native portrait framebuffer and turned it a quarter more; the panel is that framebuffer. Row 26's `libdevicehubfix` gains a `CMDeviceStateManager` stand-in in dtdeviceinfod (`VPCMAngleManager.m`: `isAvailable`, `startUpdatesToQueue:withHandler:`, `stopUpdates`, real `CMDeviceStateEvent`s with A device orientation 1, B the hinge state from `VPhoneHingeLatest`, C 0, delivered at start and on change): Xcode 27.1's DeviceHub (CoreDevicePop plugins) draws a foldable from CoreDevice's device motion state (`streamdevicemotionstate`), which a guest's CoreMotion could not answer ("Pose monitoring failed … 1001"), so the device was always drawn closed. **Validated on iPhone19,4 27.1 (24A94425):** closed shows the folded device with the cover screen, open the opened device with the inner screen upright and filling the panel, following live folds; the VM window is unchanged. **Open:** at book DeviceHub draws the cover (it names the inner panel only from DisplayInfo's `active` integrated display, and reporting the inner display as integrated makes DeviceHub want a per-display stream the guest cannot supply); DeviceHub's own pose controls (vendor-defined HID) are not wired to the guest.
diff --git a/Research/Guest/devicehub_screen_viewing.md b/Research/Guest/devicehub_screen_viewing.md
index 0887c6e1..ed8511ae 100644
--- a/Research/Guest/devicehub_screen_viewing.md
+++ b/Research/Guest/devicehub_screen_viewing.md
@@ -15,7 +15,8 @@ Measured with Xcode 27.0 (27A266a) and CoreDevice 642.16 on macOS 27.0.1,
against `iPad16,1` 26.6.2 (23G90) and 27.0.1 (24A446) and `iPhone17,3` 26.6.2
and 27.0.1 guests over cloudOS 26.4, 2026-10-06 and 2026-10-07.
-Status: the live view works on iPadOS 26, iOS 26 and iOS 27; iPadOS 27 refuses
+Status: the live view works on iPadOS 26, iOS 26 and iOS 27 (an iPhone Duo
+follows its fold, see [iPhone Duo: the fold](#iphone-duo-the-fold)); iPadOS 27 refuses
pairing and is untested. Known issue: under load (several VMs streaming, or the
Mac busy restoring or downloading) the view can stall for seconds or fall
seconds behind and stay there until the stream restarts. A single stream on a
@@ -543,6 +544,51 @@ when the two interleave a real frame can land 1–28 ms behind an idle one and
is dropped. The offsets do not accumulate, so this costs single frames, not
seconds.
+## iPhone Duo: the fold
+
+Measured 2026-10-29 with Xcode 27.1 against `iPhone19,4` 27.1 (24A94425).
+
+Xcode 27.1 draws a foldable as a 3D V68 model
+(`DeviceKit.framework/PlugIns/CoreDevicePopDeviceKitExtension.devicekitplugin`,
+log subsystem `com.apple.dt.coredevicepop`, with the host CoreDevice plugin
+`CoreDevicePopCoreDeviceExtension.coredeviceplugin`). It picks the fold and
+the lit panel from the device's pose, which is CoreDevice's device motion
+state stream (`com.apple.coredevice.action.streamdevicemotionstate`). The
+DDI's `dtdeviceinfod` (`DeviceMotionStateManager`) answers it from
+CoreMotion's `CMDeviceStateManager`, reading each `CMDeviceStateEvent`'s
+`propertyA` (device orientation), `propertyB` (hinge state 1 closed, 2
+partially open, 3 open flat) and `propertyC`. On a guest the manager is
+unavailable, DeviceHub logs `Pose monitoring failed … Code=1001` every second,
+and draws the device closed whatever the hinge angle stream says.
+
+`libdevicehubfix` answers it in `dtdeviceinfod` (`VPCMAngleManager.m`, beside
+the hinge angle stand-in): `isAvailable` follows the hinge provider, and
+updates are real `CMDeviceStateEvent`s built from the provider's newest
+sample, sent at start and on every change. With it DeviceHub draws the folded
+device on the cover and the opened device on the inner panel, and follows
+live folds.
+
+The stream is the mirrored primary display (display ID 1) for both panels.
+DeviceHub draws it on the inner panel as that panel's native framebuffer,
+portrait and mounted a quarter turn. backboardd moves every clone to the
+display holding the primary content, which open is the guest's landscape
+inner render display, rotated upright; DeviceHub turned that a quarter more
+(sideways and pillarboxed). FoldDisplay keeps clones on the panel instead
+(`FoldDisplayBackboard.m`), which open shows the inner display turned a
+quarter, exactly the native framebuffer DeviceHub expects.
+
+Not done:
+
+- At book (100°) DeviceHub draws the cover. It takes the lit panel at that
+ angle from DisplayInfo's `active` integrated display, and the inner render
+ display is `virtual`. Reporting it as integrated gives DeviceHub the
+ evidence, but DeviceHub then wants a stream for that display ID, which
+ needs feature `0x100` and a capture path the mirror patch does not cover
+ (tried: the picture comes out small and centred).
+- DeviceHub's own pose controls (a hinge slider and closed / book / open
+ presets, which appear once an integrated inner display is reported) send
+ vendor-defined HID reports; nothing in the guest acts on them.
+
## Other open items
- iPadOS 27 refuses pairing (see Validation), so DeviceHub is untested there.
diff --git a/Research/Guest/iphone_duo_bringup.md b/Research/Guest/iphone_duo_bringup.md
index 88d02de1..97e672be 100644
--- a/Research/Guest/iphone_duo_bringup.md
+++ b/Research/Guest/iphone_duo_bringup.md
@@ -4834,6 +4834,13 @@ test VM (iPhone19,4 27.1, 24A94425) with the two-display path:
- Folding from the lock screen or sleep lights the arriving panel's lock
screen, which sleeps again after the lock screen's short idle time (about
7 s), as on hardware.
+- DeviceHub (Xcode 27.1) draws a Duo guest as a 3D V68 model from CoreDevice's
+ device motion state, which needed a `CMDeviceStateManager` stand-in in
+ `dtdeviceinfod`, and draws the open stream as the inner panel's native
+ portrait framebuffer, which needed every mirror clone kept on the panel
+ (backboardd moved it to the landscape inner render display). Closed and
+ open now look right there; book does not. Details:
+ `Research/Guest/devicehub_screen_viewing.md`, "iPhone Duo: the fold".
## 2026-10-29 night: the inner display at 120 Hz
diff --git a/VPhoneGuestComponents/DeviceHubFix/VPCMAngleManager.m b/VPhoneGuestComponents/DeviceHubFix/VPCMAngleManager.m
index b2890495..3158bcc6 100644
--- a/VPhoneGuestComponents/DeviceHubFix/VPCMAngleManager.m
+++ b/VPhoneGuestComponents/DeviceHubFix/VPCMAngleManager.m
@@ -1,4 +1,6 @@
-// VPCMAngleManager.m — the hinge-angle manager stand-in for dtdeviceinfod.
+// VPCMAngleManager.m — the hinge-angle manager stand-in for dtdeviceinfod,
+// and beside it the device state manager stand-in (see "The device state
+// stand-in" below).
//
// CoreDevice's hinge-angle stream (DeviceHub) ends, on the device, in the
// DDI's dtdeviceinfod: CMAngleManager_Bridge resolves CoreMotion's
@@ -317,12 +319,152 @@ static void vpSwizzledSetAngleUpdateInterval(id self, SEL selector, double inter
vpArmTimer(session);
}
+// MARK: - The device state stand-in
+//
+// DeviceHub (Xcode 27.1's CoreDevicePop plugin) draws a foldable from its
+// device pose: which panel is active, the hinge state, the orientation and
+// the tabletop pose. Without it the model stays closed on the cover whatever
+// the hinge angle says. The pose is CoreDevice's device motion state stream,
+// which dtdeviceinfod's DeviceMotionStateManager answers from CoreMotion's
+// CMDeviceStateManager (isAvailable, startUpdatesToQueue:withHandler:,
+// stopUpdates), reading each CMDeviceStateEvent's propertyA, propertyB and
+// propertyC. Those are SpringBoard's magic pose: A the device orientation, B
+// the hinge state (1 closed, 2 partially open, 3 open flat, as
+// +propertyAForConfigType:… partitions them), C the tabletop pose. A guest's
+// CoreMotion reads them from a hardware HID device it skips on a VM, so the
+// manager answers unavailable. Here it answers from the provider's newest
+// sample instead, like the angle stand-in, with real CMDeviceStateEvents,
+// delivered once at start and then on every change.
+
+static IMP vpOriginalStateIsAvailableIMP;
+
+typedef struct {
+ long long orientation, hinge, tabletop;
+} VPDeviceState;
+
+static VPDeviceState vpDeviceStateFromSample(NSDictionary *latest) {
+ long long hinge = [latest[@"state"] longLongValue];
+ // The provider's state follows SpringBoard's table; open (4) is open
+ // flat to CoreMotion, which has no wider state.
+ return (VPDeviceState){1, MIN(MAX(hinge, 0), 3), 0};
+}
+
+static id vpDeviceStateEvent(VPDeviceState state) {
+ Class event = objc_getClass("CMDeviceStateEvent");
+ SEL init = sel_registerName(
+ "initWithDeviceStatePropertyAType:deviceStatePropertyBType:deviceStatePropertyCType:timestamp:continuousTimestamp:");
+ if (![event instancesRespondToSelector:init])
+ return nil;
+ NSTimeInterval now = NSProcessInfo.processInfo.systemUptime;
+ return ((id (*)(id, SEL, long long, long long, long long, double, double))objc_msgSend)(
+ [event alloc], init, state.orientation, state.hinge, state.tabletop, now, now);
+}
+
+@interface VPDeviceStateSession : NSObject
+@property (nonatomic, strong) id deliveryQueue;
+@property (nonatomic, copy) void (^handler)(id event, NSError *error);
+@property (nonatomic, strong) dispatch_source_t timer;
+@property (nonatomic) VPDeviceState delivered;
+@property (nonatomic) BOOL hasDelivered;
+@end
+
+@implementation VPDeviceStateSession
+- (void)dealloc {
+ if (_timer)
+ dispatch_source_cancel(_timer);
+}
+@end
+
+static char vpStateSessionKey;
+
+static void vpDeliverDeviceState(VPDeviceStateSession *session) {
+ NSDictionary *latest = vpLatestSample();
+ if (!session.handler || !latest)
+ return;
+ VPDeviceState state = vpDeviceStateFromSample(latest);
+ VPDeviceState last = session.delivered;
+ if (session.hasDelivered && state.orientation == last.orientation && state.hinge == last.hinge &&
+ state.tabletop == last.tabletop)
+ return;
+ id event = vpDeviceStateEvent(state);
+ if (!event)
+ return;
+ session.delivered = state;
+ session.hasDelivered = YES;
+ vpMotionLog(@"device state: hinge %lld orientation %lld tabletop %lld", state.hinge, state.orientation,
+ state.tabletop);
+ void (^handler)(id, NSError *) = session.handler;
+ id queue = session.deliveryQueue;
+ if ([queue isKindOfClass:[NSOperationQueue class]])
+ [(NSOperationQueue *)queue addOperationWithBlock:^{ handler(event, nil); }];
+ else if (queue)
+ dispatch_async((dispatch_queue_t)queue, ^{ handler(event, nil); });
+ else
+ handler(event, nil);
+}
+
+static BOOL vpSwizzledStateIsAvailable(id self, SEL selector) {
+ if (vpProviderIsRunning())
+ return YES;
+ return ((BOOL (*)(id, SEL))vpOriginalStateIsAvailableIMP)(self, selector);
+}
+
+static void vpSwizzledStartStateUpdates(id self, SEL selector, id queue, id handler) {
+ VPDeviceStateSession *session = objc_getAssociatedObject(self, &vpStateSessionKey);
+ if (!session) {
+ session = [VPDeviceStateSession new];
+ objc_setAssociatedObject(self, &vpStateSessionKey, session, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
+ }
+ if (session.timer)
+ dispatch_source_cancel(session.timer);
+ session.deliveryQueue = queue;
+ session.handler = handler;
+ session.hasDelivered = NO;
+ dispatch_source_t timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, vpTimerQueue());
+ dispatch_source_set_timer(timer, DISPATCH_TIME_NOW, 100 * NSEC_PER_MSEC, 10 * NSEC_PER_MSEC);
+ __weak VPDeviceStateSession *weakSession = session;
+ dispatch_source_set_event_handler(timer, ^{
+ @autoreleasepool {
+ VPDeviceStateSession *alive = weakSession;
+ if (alive)
+ vpDeliverDeviceState(alive);
+ }
+ });
+ dispatch_resume(timer);
+ session.timer = timer;
+}
+
+static void vpSwizzledStopStateUpdates(id self, SEL selector) {
+ VPDeviceStateSession *session = objc_getAssociatedObject(self, &vpStateSessionKey);
+ session.handler = nil;
+ if (session.timer) {
+ dispatch_source_cancel(session.timer);
+ session.timer = nil;
+ }
+}
+
+static void vpInstallDeviceStateManagerStandIn(void) {
+ Class manager = objc_getClass("CMDeviceStateManager");
+ Method available = class_getClassMethod(manager, sel_registerName("isAvailable"));
+ Method start = class_getInstanceMethod(manager, sel_registerName("startUpdatesToQueue:withHandler:"));
+ Method stop = class_getInstanceMethod(manager, sel_registerName("stopUpdates"));
+ if (!available || !start || !stop || !vpDeviceStateEvent((VPDeviceState){1, 1, 0})) {
+ vpMotionLog(@"device state: CMDeviceStateManager surface not found, CoreDevice deviceMotionState stays off");
+ return;
+ }
+ vpOriginalStateIsAvailableIMP = method_setImplementation(available, (IMP)vpSwizzledStateIsAvailable);
+ method_setImplementation(start, (IMP)vpSwizzledStartStateUpdates);
+ method_setImplementation(stop, (IMP)vpSwizzledStopStateUpdates);
+ vpMotionLog(@"device state: stand-in installed");
+}
+
// MARK: - Install
__attribute__((constructor)) static void vpInstallAngleManagerStandIn(void) {
if (strcmp(getprogname(), "dtdeviceinfod") != 0)
return;
dlopen("/System/Library/Frameworks/CoreMotion.framework/CoreMotion", RTLD_LAZY | RTLD_LOCAL);
+ vpInstallDeviceStateManagerStandIn();
Class manager = objc_getClass("CMAngleManager");
if (!manager) {
vpMotionLog(@"hinge manager: CMAngleManager not found, CoreDevice hingeAngle stays off");
diff --git a/VPhoneGuestComponents/FoldDisplay/FoldDisplayBackboard.m b/VPhoneGuestComponents/FoldDisplay/FoldDisplayBackboard.m
index 564aea42..45fadd44 100644
--- a/VPhoneGuestComponents/FoldDisplay/FoldDisplayBackboard.m
+++ b/VPhoneGuestComponents/FoldDisplay/FoldDisplayBackboard.m
@@ -290,9 +290,62 @@ static void vpInstallInnerDigitizer(void) {
vpInstallInnerDigitizerTurn(processor);
}
+// MARK: - mirroring
+
+// A mirror of the screen (Xcode's DeviceHub stream, AirPlay, recording) is a
+// clone of a display, and backboardd moves it to whichever display holds the
+// primary content: open, the inner render display. A clone is rotated upright
+// by its master's orientation, so it carried the inner display upright and
+// letterboxed. DeviceHub draws an open Duo's stream on the inner panel as
+// that panel's native framebuffer, portrait and mounted a quarter turn
+// (2007x2853 at 270 degrees), and turned the upright picture a quarter more.
+// The panel itself (LCD) is that framebuffer: open, SpringBoard shows the
+// inner display on it turned a quarter (FoldDisplayPanel.m). So every clone
+// stays on the panel, as the VM window shows it. A clone is removed from the
+// master that really holds it: CoreAnimation aborts on removing a clone from
+// a display it is not cloned from.
+static IMP vpOriginalAddClone, vpOriginalRemoveClone;
+
+static id vpPanelDisplay(void) {
+ id server = ((id (*)(id, SEL))objc_msgSend)(objc_getClass("CAWindowServer"), sel_registerName("serverIfRunning"));
+ for (id display in [server valueForKey:@"displays"] ?: @[])
+ if ([[display valueForKey:@"displayId"] unsignedIntValue] == 1) return display;
+ return nil;
+}
+
+static void vpPanelAddClone(id self, SEL selector, id clone, id options) {
+ id panel = self == vpInnerRenderDisplay ? vpPanelDisplay() : nil;
+ if (panel && clone != panel) {
+ vpFoldDisplayLog([NSString stringWithFormat:@"inner display: %@ mirrors the panel instead", [clone valueForKey:@"name"]]);
+ self = panel;
+ }
+ ((void (*)(id, SEL, id, id))vpOriginalAddClone)(self, selector, clone, options);
+}
+
+static void vpPanelRemoveClone(id self, SEL selector, id clone) {
+ id master = [clone valueForKey:@"cloneMaster"];
+ if (!master) return;
+ ((void (*)(id, SEL, id))vpOriginalRemoveClone)(master, selector, clone);
+}
+
+static void vpInstallPanelMirroring(void) {
+ Class display = objc_getClass("CAWindowServerDisplay");
+ Method add = class_getInstanceMethod(display, sel_registerName("addClone:options:"));
+ Method remove = class_getInstanceMethod(display, sel_registerName("removeClone:"));
+ if (!add || !remove || strcmp(method_getTypeEncoding(add), "v32@0:8@16@24") != 0 ||
+ strcmp(method_getTypeEncoding(remove), "v24@0:8@16") != 0 ||
+ ![display instancesRespondToSelector:sel_registerName("cloneMaster")]) {
+ vpFoldDisplayLog(@"inner display: clone ABI unavailable, mirrors follow the inner display");
+ return;
+ }
+ vpOriginalAddClone = method_setImplementation(add, (IMP)vpPanelAddClone);
+ vpOriginalRemoveClone = method_setImplementation(remove, (IMP)vpPanelRemoveClone);
+}
+
// MARK: - installation
void vpInstallInnerRenderDisplay(void) {
+ vpInstallPanelMirroring();
vpInstallInnerDigitizer();
Method extended = class_getInstanceMethod(objc_getClass("CAWindowServerDisplay"), sel_registerName("extendedProperties"));
if (extended && strcmp(method_getTypeEncoding(extended), "@16@0:8") == 0)
diff --git a/VPhoneGuestComponents/Makefile b/VPhoneGuestComponents/Makefile
index fcaabe12..92089ec6 100644
--- a/VPhoneGuestComponents/Makefile
+++ b/VPhoneGuestComponents/Makefile
@@ -63,8 +63,9 @@ BATTERYHEALTHFIX_INCLUDES := $(wildcard BatteryHealthFix/*.h)
# the image is mounted only after the host enables developer services. The two
# interposed Swift getters are weak flat-namespace imports. CoreVideo, IOSurface
# and libobjc are for the avconferenced band reads it waits on the scaler for;
-# Foundation and the ObjC runtime are for the CMAngleManager stand-in
-# (VPCMAngleManager.m) dtdeviceinfod answers the hinge stream from.
+# Foundation and the ObjC runtime are for the CMAngleManager and
+# CMDeviceStateManager stand-ins (VPCMAngleManager.m) dtdeviceinfod answers
+# the hinge and device motion state streams from.
DEVICEHUBFIX := $(STAGE)/devicehubfix/libdevicehubfix.dylib
DEVICEHUBFIX_SOURCES := $(sort $(wildcard DeviceHubFix/*.c) $(wildcard DeviceHubFix/*.m))
DEVICEHUBFIX_INCLUDES := $(wildcard DeviceHubFix/*.h)