fix(libkernel): leave other threads' signal masks alone when a thread exits through scePthreadExit #12897
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/12897"
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 AdnanKhan-ak47 on 2026-10-29T13:45:24Z.
What
On macOS, a thread that exits through
scePthreadExitchanges the signal mask of the other threads, so every thread created after it blocksSIGUSR1,SIGSEGV,SIGBUSand most other signals.guest_pthread_create_suspendedfails because of it ("the handler did not run on the thread once it was resumed").scePthreadExitleaves the thread bylongjmping to thesetjmp(exitJump)inThreadEntry(Pthread/src/Thread.cpp).setjmpsaves andlongjmprestores the signal mask throughsigprocmask. The buffer is filled while the thread still has the all-blocked mask thatscePthreadCreatesets aroundpthread_create, so every exit re-applies that mask.sigprocmaskcall also changed the mask the main thread reads back. In the test the main thread then reads0xfffefeff, andscePthreadCreatecopies it into every later thread. The raisedSIGUSR1stays pending forever, and theSIGSEGV/SIGBUShandlers the write watch installs stop seeing faults on those threads.setjmp/longjmpdo not save the mask, so Linux was not affected.The pair becomes
_setjmp/_longjmp, the POSIX variants that leave the mask alone. The exit path only unwinds the thread's frames. The block is already#ifndef _WIN32, so the change is 2 lines with no new#ifdef. Diagnosis and the macOS run are in #1.#9938 moves this
setjmpintoRunGuestThreadbut keeps it, so the bug remains with it. Whichever lands second has a two-line rebase.Tested
macOS. Apple M4, macOS 27.2, Apple clang 21.0.0, x86-64 Release under Rosetta 2, Vulkan SDK 1.4.363.0.
mainf88c86bf6cplus the macOS PR set thatlibkernelneeds to build (#10552, #11249, #11447, #10669, #12076, #7631, #7804, #11554, #11437, #4630),BUILD_TESTING=ON.guest_pthread_create_suspendedfails every run without the change, and passes 20/20 with it.ctest -j8(2818 tests) with and without it: the only differences areguest_pthread_create_suspended, now passing, and oneagc_driver_image_tabletimeout that also passes alone without the change. Nothing new fails.Linux. Arch Linux x86-64 (Ryzen 7 3700X, GCC 16.2.1), Release, this branch
33afa6a464onmainedf6804cf5: the 121 thread, signal and exception tests (ctest -R "pthread|thread|signal|exception|setjmp") pass, as they do onmainf88c86bf6c. glibc'ssetjmpdoes not save the signal mask, so_setjmp/_longjmpbehave the same there and nothing changes on Linux.tools/check_conventions.py --base origin/mainpasses.tools/pr_overlap.pylists 10 open PRs touchingThread.cpp; only #9938 changes these lines, and #12682 merges cleanly with this branch.Merge order with #9938 (agreed with @BorchBe99 in https://github.com/boykopovar/AnyPS5/pull/9938#issuecomment-6510541480, who added this PR to #9938's
Depends on): this PR first, then #9938.AdnanKhan-ak47:update/9938-with-12897(a52db41d53) is #9938's head36a6b5c6c7with this PR merged in. The one conflict is #9938's moved nativesetjmp(exitJump)inRunGuestThread, which becomes_setjmp; the_longjmpinscePthreadExitmerges cleanly. On POSIX hosts both #9938's native-stack and caller-stack threads go throughRunGuestThread, so that one line covers both; Windows uses the guest jump buffer, which only touches libkernel's emulated mask. On macOS (the PR set from #1 plus that branch),guest_pthread_create_suspendedpasses 20/20, andguest_pthread_cancelandguest_pthread_cancel_recoverypass. With both lines put back tosetjmp/std::longjmp,guest_pthread_create_suspendedfails.guest_pthread_provided_stackis built only on Windows and Linux, and the Linux run of that branch is still to do. If #9938 lands first instead, I rebase this PR onto it with the same one-line change.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)Depends onImported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-29T13:52:29Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
The implementation matches the reported Darwin signal-mask issue, but the branch conflicts with open PR #9938 in
Thread.cppand the required landing order is not declared.What I ran
33afa6a4648f9e7860413b1116f1aa6e61828486against currentmainb0465557fdf9daa302392cbd2e2d799fc59bbf79.5eb8668f646198730dee2c612618f989145deec3.36a6b5c6c730c24a2024cd3f43a3ad2b46523adf: conflicts incore/libs/prx/libkernel/Pthread/src/Thread.cpp.Results
5eb8668f646198730dee2c612618f989145deec3Thread.cpp; tree623d540a7e73f182c77884c37408ef70a3f217a4Unedited command output
Negative control
Not applicable: the blocker is unresolved branch integration order, not a behavioral assertion.
Findings
Blocking
The PR body says #9938 also changes this
setjmppath and that whichever lands second needs a rebase, but the checklist saysDepends on: none. Both PRs are open, and a current pairwise merge preview conflicts inThread.cpp. CONTRIBUTING.md requires the authors to agree which one lands first and record the dependency/order. Please coordinate with #9938's author and update the checklist to reflect the agreed sequence. If #9938 lands first, rerun the signal-mask regression on the rebased head; if this PR lands first, ask #9938's author to preserve the_setjmp/_longjmpchange and rerun the caller-stack tests.Non-blocking
The two-line change is consistent with the stated macOS
setjmpsignal-mask issue; the author reports a 20/20 macOS regression run and Linux thread tests. Those are author-reported results, not runs performed here.Sources
b0465557fdf9daa302392cbd2e2d799fc59bbf79Not verified
I did not run the focused C++ test or build locally. Hosted checks were pending. The macOS and Linux test results above are reported by the author; I did not independently reproduce them.
To get this to a good state
Agree with #9938's author on an order, record it in the dependency checklist, and rerun the affected focused tests on the resulting head. I will repeat the merge and convention checks on that head.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-30T05:02:11Z.
Review: APPROVED
Reviewed — looks good
The only blocker from my prior review is resolved: both PRs record the agreed order, with this change landing before #9938.
What I ran
Reviewed head
33afa6a4648f9e7860413b1116f1aa6e61828486against currentmainbase8c8b9986204d5b1cbb23847b363df00ae832ec9c; the merge preview is clean (50e73eb9f815669bed87123283a32f3526e55d59). No changes toThread.cpplanded on currentmainbetween the previously tested base422f96b3a92e797c5f69c136c4a394c8da672556and this base. Environment: Linux; no compiler invoked.Results
50e73eb9f815669bed87123283a32f3526e55d59.git diff --checkThread.cpp.#12897underDepends on. The reported pre-integrated #9938 branch preserves_setjmpand resolves its moved call site.Raw local command output
git merge-tree --write-tree ...:git diff --check ...: no output (exit status 0).python tools/check_conventions.py ...:git diff --quiet ...: no output (exit status 0; no changes in the listed source path).Negative control
setjmp/std::longjmpmakesguest_pthread_create_suspendedfail; I did not independently run this mutation.Findings
Blocking
None found.
Non-blocking
The macOS/Linux test runs and the #9938 integration-branch tests are author-reported, not runs I performed. #9938's caller-stack Linux run remains pending according to the author; that follow-up belongs to #9938.
Sources
_setjmpcall is in the reviewed PR head, and_longjmpis at the exit site.Not verified
To get this to a good state
No further action is needed on #12897 before the agreed merge order. I will rerun the merge, diff, and conventions checks if its head changes.