Run a virtual iPhone on an Apple Silicon Mac.
Swift
Clarify camera session reference naming and consolidate notes
James Jackson9b6b74d01160
diff --git a/.github/workflows/build.yml b/.github/workflows/build.ymlindex 3189a604..ebed63d8 100644--- a/.github/workflows/build.yml+++ b/.github/workflows/build.yml@@ -75,4 +75,4 @@ jobs:make -C VPhoneGuestComponents test-vcam-prewarmmake -C VPhoneGuestComponents test-vcam-drive-gatemake -C VPhoneGuestComponents test-camfix-geometry- make -C VPhoneGuestComponents test-camfix-session-lifetime+ make -C VPhoneGuestComponents test-camfix-session-referencediff --git a/Research/0_binary_patch_comparison.md b/Research/0_binary_patch_comparison.mdindex 5b8bb7f2..7dbe884f 100644--- a/Research/0_binary_patch_comparison.md+++ b/Research/0_binary_patch_comparison.md@@ -5,7 +5,7 @@> weak-table insertion. It skips sessions already in deallocation.> No firmware patch or preset changes. A small camera app reproduces the> original abort on iOS 27.0.1 (24A446). See-> [reproduction and crash stack](Guest/camera_session_teardown.md).+> [reproduction and crash stack](Guest/virtual_camera_transport.md#session-registration-during-teardown-2026-10-29).> **Apple TV RootHide bootstrap and environment hooks (2026-10-26).** No new> declaration or instruction patch. An arm64e Apple TV now admitsdiff --git a/Research/Guest/Evidence/camfix_session_teardown_crash.txt b/Research/Guest/Evidence/camfix_session_teardown_crash.txtdeleted file mode 100644index 22c1ba74..00000000--- a/Research/Guest/Evidence/camfix_session_teardown_crash.txt+++ /dev/null@@ -1,27 +0,0 @@-SessionProbe crash excerpt-Libraries: stock vPhone 2.13.4 camera libraries-Guest: iOS 27.0.1 (24A446)-Exception: EXC_CRASH (SIGABRT)-Termination namespace: OBJC--Crashed thread:- 0 libsystem_kernel.dylib __abort_with_payload + 8- 1 libsystem_kernel.dylib abort_with_payload_wrapper_internal + 104- 2 libsystem_kernel.dylib abort_with_reason + 32- 3 libobjc.A.dylib _objc_fatalv(unsigned long long, unsigned long long, char const*, char*) + 116- 4 libobjc.A.dylib _objc_fatal(char const*, ...) + 32- 5 libobjc.A.dylib weak_register_no_lock + 396- 6 libobjc.A.dylib objc_storeWeak + 468- 7 Foundation -[NSConcreteHashTable addObject:] + 96- 8 libcamfix.dylib cfx_track_vcam_session + 128- 9 libcamfix.dylib cfx_session_isRunning_hook + 76-10 AVFCapture -[AVCaptureInput setSession:] + 64-11 AVFCapture -[AVCaptureDeviceInput setSession:] + 272-12 AVFCapture -[AVCaptureSession _removeInput:] + 232-13 AVFCapture -[AVCaptureSession removeInput:] + 344-14 AVFCapture -[AVCaptureSession dealloc] + 308-15 Foundation _NSKVOPerformWithDeallocatingObservable + 180-16 Foundation NSKVODeallocate + 184-17 libobjc.A.dylib AutoreleasePoolPage::releaseUntil(objc_object**) + 204-18 libobjc.A.dylib objc_autoreleasePoolPop + 244-19 SessionProbe RunCameraSessionProbe + 440diff --git a/Research/Guest/camera_session_teardown.md b/Research/Guest/camera_session_teardown.mddeleted file mode 100644index f62fbda5..00000000--- a/Research/Guest/camera_session_teardown.md+++ /dev/null@@ -1,81 +0,0 @@-# Camera session teardown crash--The virtual-camera `isRunning` hook adds a weak reference to a session during deallocation.-Objective-C rejects the reference and aborts the app.-AVFoundation reaches the hook through `AVCaptureInput setSession:` while it removes the session inputs.--The getter must keep tracking live sessions.-Some camera clients skip `startRunning` because the getter already returns `YES`.-Removing tracking from the getter can stop frame delivery for those clients.--`cfx_live_session` uses `objc_storeWeakOrNil` to skip objects already in deallocation.-Its strong weak-load keeps live sessions alive through table insertion.-The tracking argument uses `__unsafe_unretained` so ARC does not retain a dying session on entry.--## Reproduction--Build the small camera app:--```sh-make -C VPhoneGuestComponents build-camfix-session-reproducer-```--Install `.build/siblings/camera-session-reproducer/SessionProbe.ipa` in an iOS guest.-Run `org.example.vphone.SessionProbe`.-The app automatically creates and releases 100 sessions with the virtual-camera input and a video data output.-It adds a KVO observer for `running` on alternate cycles.-It does not start capture.--The original library aborts during session deallocation.-The patched library completes all cycles.-The app shows the result and writes `Documents/result.txt` in its data container.--## Crash stack with the original 2.13.4 library--The [crash log excerpt](Evidence/camfix_session_teardown_crash.txt) includes the abort frames and library names.--```text-Exception: EXC_CRASH (SIGABRT)-Termination namespace: OBJC--weak_register_no_lock + 396-objc_storeWeak + 468--[NSConcreteHashTable addObject:] + 96-cfx_track_vcam_session + 128-cfx_session_isRunning_hook + 76--[AVCaptureInput setSession:] + 64--[AVCaptureDeviceInput setSession:] + 272--[AVCaptureSession _removeInput:] + 232--[AVCaptureSession removeInput:] + 344--[AVCaptureSession dealloc] + 308-_NSKVOPerformWithDeallocatingObservable + 180-NSKVODeallocate + 184-AutoreleasePoolPage::releaseUntil(objc_object**) + 204-objc_autoreleasePoolPop + 244-RunCameraSessionProbe + 440-```--## Results on iOS 27.0.1 (24A446)--- The original 2.13.4 libcamfix crashed twice with the same test app.-- A repeat with both stock 2.13.4 camera libraries produced the same crash.-- The clean-branch libcamfix with stock libvcamcaptured completed 100 release cycles.-- With that pair, Camera.app showed the host test pattern and saved photos and an 8.32-second movie.-- The movie contained 1280x720 H.264 video. All 251 decoded frames had distinct hashes.-- Camera.app also saved a photo after a cold reopening. No Camera.app crash reports appeared.--Camera.app was a regression check. The small test app reproduced the crash.-The final comparison used stock libvcamcaptured in both runs.-Only libcamfix changed. No local 1080p format changes were present.-These results cover one firmware pairing.--The full `VPhone` Debug build and bundle admission passed with Xcode 27.2.-The bundled libcamfix hash matched the clean-branch library used in the final guest run.-The camera geometry, data plane, prewarm, drive gate, loader links, and session lifetime tests passed.--The host regression test covers nil, live sessions, and deallocation.-It also checks that weak tracking does not retain a session after its owner releases it.--```sh-make -C VPhoneGuestComponents test-camfix-session-lifetime-```diff --git a/Research/Guest/virtual_camera_transport.md b/Research/Guest/virtual_camera_transport.mdindex e6ef6643..eecb9a66 100644--- a/Research/Guest/virtual_camera_transport.md+++ b/Research/Guest/virtual_camera_transport.md@@ -329,3 +329,29 @@ No Camera, cameracaptured or assetsd crash reports on either. Not done: themovie is landscape with no rotation metadata, like the photos; pause/resume,slo-mo, time-lapse and cinematic modes; `-startRecordingMovieWithSettings:`(the moment-capture movie path), which Camera.app did not call here.++## Session registration during teardown (2026-10-29)++AVFoundation calls the virtual-camera `isRunning` getter while removing inputs+in `AVCaptureSession dealloc`. Registering that dying session in the weak table+aborts in `objc_storeWeak` → `weak_register_no_lock`.++Keep tracking in the getter: some clients skip `startRunning` when it returns+`YES`. `cfx_load_live_session` uses `objc_storeWeakOrNil` and an ARC weak load to+skip dying sessions and hold live ones through insertion. Its argument remains+`__unsafe_unretained` so entry does not retain an object already in deallocation.++Reproduce with `make -C VPhoneGuestComponents build-camfix-session-reproducer`.+Install `.build/siblings/camera-session-reproducer/SessionProbe.ipa` and run+`org.example.vphone.SessionProbe`. It creates and releases 100 camera sessions,+observing `running` on alternate cycles, without starting capture.++On iOS 27.0.1 (24A446), the stock 2.13.4 camera libraries abort; changing only+libcamfix completes all 100 cycles. Camera.app also saved photos and an 8.32 s+1280×720 H.264 movie with 251 distinct decoded frames, then reopened and saved+another photo without a crash report. These checks cover one firmware pairing.+The VPhone Debug build and bundle admission passed with Xcode 27.2.++`make -C VPhoneGuestComponents test-camfix-session-reference` checks nil, live+and deallocating sessions, plus release after weak-table insertion. CI runs it+with the other guest-component tests.diff --git a/VPhoneGuestComponents/CamFix/Session/CamFixSessionLifetime.h b/VPhoneGuestComponents/CamFix/Session/CamFixSessionReference.hsimilarity index 86%rename from VPhoneGuestComponents/CamFix/Session/CamFixSessionLifetime.hrename to VPhoneGuestComponents/CamFix/Session/CamFixSessionReference.hindex fe40699d..60fe5856 100644--- a/VPhoneGuestComponents/CamFix/Session/CamFixSessionLifetime.h+++ b/VPhoneGuestComponents/CamFix/Session/CamFixSessionReference.h@@ -6,7 +6,7 @@extern id cfx_storeWeakOrNil(id __weak *location, id value)__asm("_objc_storeWeakOrNil");-static inline id cfx_live_session(id __unsafe_unretained session) {+static inline id cfx_load_live_session(id __unsafe_unretained session) {__weak id candidate = nil;cfx_storeWeakOrNil(&candidate, session);return candidate;diff --git a/VPhoneGuestComponents/CamFix/Session/CamFixVideoDelivery.m b/VPhoneGuestComponents/CamFix/Session/CamFixVideoDelivery.mindex eb184149..53c09efb 100644--- a/VPhoneGuestComponents/CamFix/Session/CamFixVideoDelivery.m+++ b/VPhoneGuestComponents/CamFix/Session/CamFixVideoDelivery.m@@ -3,7 +3,7 @@#import "CamFixPrivate.h"#include "CamFixFrameGeometry.h"-#include "CamFixSessionLifetime.h"+#include "CamFixSessionReference.h"// MARK: - client-side video delivery for vcam sessions//@@ -23,7 +23,7 @@ static _Atomic int cfx_video_deliver_logged = 0;// Also arms the 30 Hz pump: a session with a data output and no preview// layer would otherwise never start it.void cfx_track_vcam_session(id __unsafe_unretained candidate) {- id session = cfx_live_session(candidate);+ id session = cfx_load_live_session(candidate);if (!session) return;BOOL added = NO;pthread_mutex_lock(&cfx_vcam_sessions_lock);diff --git a/VPhoneGuestComponents/Makefile b/VPhoneGuestComponents/Makefileindex 434c77fd..34f6dcd7 100644--- a/VPhoneGuestComponents/Makefile+++ b/VPhoneGuestComponents/Makefile@@ -575,13 +575,13 @@ test-vcam-drive-gate:@$(OUT)/VCamDriveGateTests# Host proof harness for camera-session weak registration during teardown.-.PHONY: test-camfix-session-lifetime-test-camfix-session-lifetime:+.PHONY: test-camfix-session-reference+test-camfix-session-reference:@mkdir -p $(OUT)xcrun --sdk macosx clang -fobjc-arc -O1 -Wall -Wextra -Werror \-ICamFix/Session -framework Foundation \- -o $(OUT)/CamFixSessionLifetimeTests Tests/CamFixSessionLifetimeTests.m- @$(OUT)/CamFixSessionLifetimeTests+ -o $(OUT)/CamFixSessionReferenceTests Tests/CamFixSessionReferenceTests.m+ @$(OUT)/CamFixSessionReferenceTests.PHONY: build-camfix-session-reproducerbuild-camfix-session-reproducer:diff --git a/VPhoneGuestComponents/Tests/CamFixSessionLifetimeTests.m b/VPhoneGuestComponents/Tests/CamFixSessionReferenceTests.msimilarity index 74%rename from VPhoneGuestComponents/Tests/CamFixSessionLifetimeTests.mrename to VPhoneGuestComponents/Tests/CamFixSessionReferenceTests.mindex 3327fa21..c342b5f7 100644--- a/VPhoneGuestComponents/Tests/CamFixSessionLifetimeTests.m+++ b/VPhoneGuestComponents/Tests/CamFixSessionReferenceTests.m@@ -1,4 +1,4 @@-#import "CamFixSessionLifetime.h"+#import "CamFixSessionReference.h"#include <assert.h>static BOOL checkedDealloc;@@ -8,18 +8,18 @@ static NSHashTable *sessions;@implementation SessionProbe- (void)dealloc {// Mirrors isRunning -> tracking during AVCaptureSession teardown.- assert(cfx_live_session(self) == nil);+ assert(cfx_load_live_session(self) == nil);checkedDealloc = YES;}@endint main(void) {@autoreleasepool {- assert(cfx_live_session(nil) == nil);+ assert(cfx_load_live_session(nil) == nil);sessions = [NSHashTable weakObjectsHashTable];@autoreleasepool {SessionProbe *session = [SessionProbe new];- id live = cfx_live_session(session);+ id live = cfx_load_live_session(session);assert(live == session);[sessions addObject:live];assert([sessions containsObject:session]);@@ -28,5 +28,5 @@ int main(void) {assert(checkedDealloc);assert(sessions.allObjects.count == 0);}- puts("CamFix session lifetime: passed");+ puts("CamFix session reference: passed");}