fix(libSceNpCommon): refuse to terminate a callout context from its own callout #11601
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/11601"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by x-labb on 2026-10-26T22:24:11Z.
What
sceNpCalloutTermCtxcalled from a callout of the same context could not join the worker thread (the self-join returnsEDEADLK), destroyed the context's mutex and condition anyway, and returned. If the caller then released the context, the worker locked the destroyed mutex after the callout returned and the host crashed with0xC0000005.The call now throws when the calling thread is the context's worker. What the console does here is unknown, so the gap is recorded in the library's technical debt. Terminating a context from any other thread is unchanged.
Tested
Windows 11 x64, WinLibs GCC 15.2.0 r7 (x86_64-ucrt-posix-seh), Release.
guest_np_common_runtimefails without the change (the newTestCalloutSelfTerminationaborts) and passes with it.ctest -R guest_np_common: 4/4 passed on each of 5 consecutive runs.python tools/check_conventions.py --base origin/main: passed.No retail title or homebrew was run. Linux and macOS were not tested.
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-26T23:12:47Z.
Review: CHANGES_REQUESTED
Reviewed head
c6705fd7636aff25d97840144e35e1a2f3d1f68fand issue #11567.[P1] Do not let the new exception escape the callout worker.
CalloutThreadinvokeshead->handler(head->arg)without a catch boundary. If a real callback callssceNpCalloutTermCtxand does not itself catchstd::runtime_error, this guard throws out of the worker entry point and invokesstd::terminate; the host still terminates instead of reaching a safe state.TestCalloutSelfTerminationcatches the exception inside its callback, so it does not exercise the uncaught case that ordinary callers will hit.Please make this path safe for an uncaught call from a callback (for example, refuse teardown without throwing and leave the context initialized for later external termination, or add an explicit worker exception policy that preserves process safety). Add a test where the callback calls
sceNpCalloutTermCtxwithout catching and confirm the process remains alive, the worker returns to its loop, and external teardown succeeds. The existing external-thread termination path should remain covered.The issue demonstrates that returning from self-termination and freeing the context causes a later use-after-free; this guard correctly detects that call site, but the exception currently converts it into a process-wide termination. Hosted conventions, intake and labels pass; no build/test run is reported in hosted status. The author reports Windows CTest passes with the callback catching the exception; I did not rerun locally.
Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-27T01:07:01Z.
Review: COMMENTED
Linux run of the current head, since the description says Linux and macOS were not tested.
Machine: Linux x86_64, i7-8700 (6 cores / 12 threads, AVX2), Ubuntu 26.04, GCC 15.2, Release,
BUILD_TESTING=ON. Headc6705fd76merged ontomaincb45ae2dd.guest_np_common*tests pass;guest_np_common_runtime100 of 100 runs.Runtime.cppfrommainand the test kept,guest_np_common_runtimeaborts withterminating a context from its own callout is refused. On Linux,main's self-join does not hang: it returns and the context is torn down from inside its own callout, as #11567 describes.Runtime.cppand the callback'stry/catchremoved, Linux ends the same way.[libc] unhandled exception 'St13runtime_error', thenterminatewith the new message, exit 134. So an uncaught call terminates the process on Linux too.Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-29T07:51:01Z.
Review: APPROVED
Review — approved
I withdraw my earlier P1 finding. The repository README explicitly requires unsupported or unexpected states to throw
std::runtime_error, print the reason, and terminate the process. This guard follows that policy and records the console behavior as unknown; requiring the callback to survive an uncaught exception would contradict the documented fail-fast rule.What I checked
c6705fd7636aff25d97840144e35e1a2f3d1f68f.main10bec5c322eb581b3e959e6c7e18bcf09e068e96: the merge preview is clean. Its only production-file delta in this PR's touched paths removes an unrelated include; the other overlapping changes are test additions and debt-document reformatting.git diff --checkandtools/check_conventions.pypass against currentmain.Test evidence
Not verified
No console/title behavior was measured. The current-main Linux product CI is not reported as having run for this head.
The implementation is consistent with the repository's explicit fail-fast policy, so I approve this change at the reviewed head.