fix(videoout): leave a host thread that cannot unwind shutdown #12113

Closed
wanderingbug wants to merge 1 commit from upstream-pr/12113 into main
wanderingbug commented 2026-10-27 21:25:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by wanderingbug on 2026-10-27T21:25:14Z.


What

ProcessShutdown thrown on a host thread whose root is thread_start never reaches the catch in Driver::run or the presenter loop. On the confirmed hang, the sync-flip worker was inside FlipRequest::GpuReady, waiting on vblank with cfg->mutex held. A later join, or a frame dump that locks that mutex or the GPU mutex, never returns.

On a thread_start miss the host thread sets hostShutdownAbandoned, logs, and pauses. It does not call _Unwind_ForcedUnwind or pthread_exit. Exit frames are copied while the config mutex is already held. Shutdown dumps that snapshot without taking the config mutex or the GPU mutex, then ends the process before joining the abandoned thread. A guest-frame miss that is not thread_start still runs shutdown and _Exit. LibcTerminate keeps the existing 8 second exit drain and skips the end flush once the flag is set.

Upstream main already includes #11048 (MainThreadMacOs.cpp and OnMainThread in libSceVideoOut) and #7814. This PR sits on that presenter. Open PRs #11447 and #11554 cover macOS compile and Vulkan loader fixes in Lifecycle.cpp and VulkanDevice.cpp, and those hunks are left out of this diff.

Tested

Linux, gcc 13, Release, against upstream main e0cd1259a9. Rebuilt libc, libSceVideoOut, and libSceAgcDriver. Passed exception_runtime, exception_personality, exception_c_cleanup, and video_out_output_mode_policy. python3 tools/check_conventions.py --base upstream/main passed.

Square frame dump and clean exit were confirmed on the combined reference f91b74b1c, Apple M1 Max, macOS 27, Rosetta 2, MoltenVK 1.4.2.

Checklist

  • Based on current main (e0cd1259a9). Open PRs #11447 and #11554 edit Lifecycle.cpp and VulkanDevice.cpp for macOS compile and loader fixes; they do not implement this abandoned-thread exit.
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: Apple M1 Max, MoltenVK 1.4.2, macOS 27 (on combined reference f91b74b1c)
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5041360332 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12113). Originally posted by [wanderingbug](https://github.com/wanderingbug) on 2026-10-27T21:25:14Z. --- ### What `ProcessShutdown` thrown on a host thread whose root is `thread_start` never reaches the catch in `Driver::run` or the presenter loop. On the confirmed hang, the sync-flip worker was inside `FlipRequest::GpuReady`, waiting on vblank with `cfg->mutex` held. A later join, or a frame dump that locks that mutex or the GPU mutex, never returns. On a `thread_start` miss the host thread sets `hostShutdownAbandoned`, logs, and pauses. It does not call `_Unwind_ForcedUnwind` or `pthread_exit`. Exit frames are copied while the config mutex is already held. Shutdown dumps that snapshot without taking the config mutex or the GPU mutex, then ends the process before joining the abandoned thread. A guest-frame miss that is not `thread_start` still runs shutdown and `_Exit`. `LibcTerminate` keeps the existing 8 second exit drain and skips the end flush once the flag is set. Upstream main already includes #11048 (`MainThreadMacOs.cpp` and `OnMainThread` in libSceVideoOut) and #7814. This PR sits on that presenter. Open PRs #11447 and #11554 cover macOS compile and Vulkan loader fixes in `Lifecycle.cpp` and `VulkanDevice.cpp`, and those hunks are left out of this diff. ### Tested Linux, gcc 13, Release, against upstream main e0cd1259a95e6dfaf97f8f73e74410bbc5d8d199. Rebuilt libc, libSceVideoOut, and libSceAgcDriver. Passed exception_runtime, exception_personality, exception_c_cleanup, and video_out_output_mode_policy. `python3 tools/check_conventions.py --base upstream/main` passed. Square frame dump and clean exit were confirmed on the combined reference f91b74b1c, Apple M1 Max, macOS 27, Rosetta 2, MoltenVK 1.4.2. ### Checklist - [x] Based on current `main` (e0cd1259a95e6dfaf97f8f73e74410bbc5d8d199). Open PRs #11447 and #11554 edit Lifecycle.cpp and VulkanDevice.cpp for macOS compile and loader fixes; they do not implement this abandoned-thread exit. - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except technical debt - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's technical debt file - [x] No notes, investigation .md files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: Apple M1 Max, MoltenVK 1.4.2, macOS 27 (on combined reference f91b74b1c) - [x] AI-assisted: yes

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!12113
No description provided.