fix(libkernel): hold sceKernelRaiseException on a thread that blocks the signal #27801
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/27801"
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 Jazeupoi on 2026-11-27T12:38:44Z.
What
sceKernelRaiseExceptionredirected the target thread at once, even when that thread blocked the signal. FreeBSD'stdsendsignalleaves a signal sent to one thread pending while that thread blocks it, anddocs/dev/debt/libkernel.mdlisted the gap ("does not consult the target thread's signal mask").The raise now checks the target thread's blocked mask. If the signal is blocked, it is recorded on that thread and delivered there, once, when the thread unblocks it through
sigprocmask,_sigprocmask,pthread_sigmaskor the temporary mask ofsigsuspend, which then returnsEINTR, or when a signal handler whose mask holds the signal returns. After recording, the sender checks the mask again, so a raise that races with an unblock is either taken by the unblocking thread or delivered at once, not lost. Two raises made while the signal is blocked deliver once, as a pending signal does.The two functions
Exception.cppandSignals.cppshare are declared in a new small header,System/include/RaiseHold.hpp, not inApi.hpp. The new testguest_raise_blocked_maskblocksSIGUSR1on a worker, raises at it, checks for 200 ms that the handler did not run, unblocks, and checks that the handler ran once on the worker. It then does the same with two raises, raises at the unblocked worker, and finally checks thatsigsuspendwith an empty set delivers a raise held before it. Last, a second worker that never changes its mask runs aSIGUSR2handler whose mask holdsSIGUSR1; a raise during that handler runs on the worker once the handler returns. The debt entry is replaced through a fragment.Tested
Windows 11 26300, Ryzen 5 3400G, WinLibs GCC 15.2.0 UCRT, Release, on
main6b74d9d67b:guest_raise_blocked_mask: 200/200.Exception.cppandSignals.cppfrommainand the test kept, it aborts on its first check (0xc0000409): the handler runs on the worker while it blocksSIGUSR1. With the change restored, it passes 20/20.guest_siginfo_fault50/50,guest_signals10/10,guest_signal_handler_mask10/10,guest_mutex_raise_exception10/10,guest_raise_short_sleep10/10,guest_raise_exception3/3.e0d0bd8eac(the target rechecks its mask before running the handler): Windows: all 28 signal and raise tests pass;guest_raise_blocked_mask200/200;guest_raise_in_host_code,guest_raise_in_system_call,guest_raise_nested_sleep,guest_raise_short_sleep,guest_raise_leaves_host_code,guest_signal_handler_maskandguest_signals50/50 each. Linux (WSL2, GCC 13): the 19 registered there pass;guest_raise_blocked_mask200/200;guest_signal_handler_mask,guest_signalsandguest_raise_released_thread50/50.89b71b72ab(a handler's hold delivers a held raise when it ends): the results in the comment below.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)Summary by CodeRabbit
sigsuspend. Multiple raises while blocked are delivered once, andsigsuspendreturnsEINTRwhen the pending signal is delivered.sigsuspend.Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-11-27T12:48:19Z.
Review: COMMENTED
Actionable comments posted: 1
d716b0d4-e467-4209-a53a-49e80178bf08Reviewing files that changed from the base of the PR and between
c8d13657c7and95ac41c8af.core/libs/prx/libkernel/CMakeLists.txtcore/libs/prx/libkernel/System/include/RaiseHold.hppcore/libs/prx/libkernel/System/src/Exception.cppcore/libs/prx/libkernel/System/src/Signals.cppcore/libs/tests/GuestRaiseBlockedMask.cppdocs/dev/debt/changes/fix-libkernel-raise-blocked-mask.mdIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-27T13:08:52Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the inspected implementation and reported test evidence support merging.
What I ran
Reviewed head
95ac41c8af4ec0e25ff6b8720a86949af2dfee37using the prepared diff and pinned repository reader. No tests or builds were run during this review. The author reports Windows and WSL2 test runs in the PR description; those results were not independently verified.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
The added test source and debt fragment were excluded by the prepared review rules. No build, test, CI, macOS, or physical-console behavior was independently verified. The review artifacts read were
review/description.md,review/commits.md,review/manifest.json, andreview/diff.patch. All files listed as reviewed in the manifest were read:core/libs/prx/libkernel/CMakeLists.txt,core/libs/prx/libkernel/System/include/RaiseHold.hpp,core/libs/prx/libkernel/System/src/Exception.cpp, andcore/libs/prx/libkernel/System/src/Signals.cpp.files.jsonwas not available through the reader.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-11-27T13:19:30Z.
Review: COMMENTED
Actionable comments posted: 1
84839020-dd7c-459d-a82a-dbb538d257b1Reviewing files that changed from the base of the PR and between
95ac41c8afandb264f07952.core/libs/prx/libkernel/System/src/Exception.cppcore/libs/prx/libkernel/System/src/Signals.cppcore/libs/prx/libkernel/tests/cmake/guest_raise_blocked_mask_tests.cmakecore/libs/tests/GuestRaiseBlockedMask.cppdocs/dev/debt/changes/fix-libkernel-raise-blocked-mask.mdIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-11-27T13:38:21Z.
Review: COMMENTED
Independent native Linux x86-64 check at
b264f079521384963d5a46ac718c6dc227eee81a. The registeredguest_raise_blocked_mask,guest_signals,guest_signal_handler_mask,guest_raise_exception, andguest_raise_released_threadCTests all passed.The exact
guest_raise_blocked_maskfixture also passed 30 consecutive runs. Each run exercised holding a blocked raise, coalescing two held raises into one delivery, and delivering a held raise throughsigsuspendon the target thread.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-27T14:01:42Z.
Review: COMMENTED
Reviewed — comments
The change’s core implementation is readable, but the added guest test and test registration were excluded from the supplied diff, and I could not run checks.
What I ran
Reviewed head
b264f079521384963d5a46ac718c6dc227eee81a; no commands or tests were run. Readreview/description.md,review/commits.md,review/manifest.json,review/diff.patch,RaiseHold.hpp,Exception.cpp, andSignals.cpp. The supplied review folder listing showed three changed files, all included; the description identifies the test, test registration, and debt fragment as excluded by rule.Results
Findings
Blocking
None.
Non-blocking
COMMENTverdict reflects incomplete validation: the added guest test and its registration were excluded from this review, and no checks were run. Consider reviewing those files and running the reported tests before relying on the PR’s test claims.Not verified
The behavior and coverage in
core/libs/prx/libkernel/tests/cmake/guest_raise_blocked_mask_tests.cmake,core/libs/tests/GuestRaiseBlockedMask.cpp, anddocs/dev/debt/changes/fix-libkernel-raise-blocked-mask.mdwere not reviewed because those files were excluded by rule. Reported Windows and Linux test results are author-provided; they were not run in this review. macOS and physical-console behavior were not verified.To get this to a good state
Nothing is required. Optional: review the excluded test and registration, and run the claimed tests on the reviewed head.
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-27T16:47:39Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
b264f07952:tools/check_conventions.pypassed.guest_raise_blocked_mask_testsbuilt cleanly.guest_raise_blocked_mask):core/libs/prx/libkernel/System/src/Exception.cpp,core/libs/prx/libkernel/System/src/Signals.cppreverted tomainand the new tests kept, the suite fails: Restoring the change makes it pass again.Looks Good To Me
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-27T17:13:52Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change based on the source reviewed; the reported test runs were not independently verified.
What I ran
Reviewed head
e0d0bd8eacf5cbf9b6d596eb2831acb122aaa608. No tests or build commands were run. Readdescription.md,commits.md,manifest.json, anddiff.patch; read the full changed filesRaiseHold.hpp,Exception.cpp, andSignals.cppfrom the prepared bundle, plus targeted signal registration and mask code. The prepared bundle did not providefiles.json.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
Build and test results, runtime behavior on Windows, Linux, and macOS, and physical-console behavior were not verified independently. The excluded test and debt-fragment files listed in
description.mdwere not read.files.jsonwas unavailable, so the reviewed-file list could not be compared against itsreviewedentries.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-11-27T17:17:19Z.
Review: COMMENTED
Actionable comments posted: 1
014d88dc-12dd-4db1-b99f-811a985ec5e7Reviewing files that changed from the base of the PR and between
b264f07952ande0d0bd8eac.core/libs/prx/libkernel/System/include/RaiseHold.hppcore/libs/prx/libkernel/System/src/Exception.cppcore/libs/prx/libkernel/System/src/Signals.cppdocs/dev/debt/changes/fix-libkernel-raise-blocked-mask.mdIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-11-27T23:37:30Z.
Review: COMMENTED
Actionable comments posted: 1
5cbe9a40-37cf-450a-bf9b-d85b5c9b8430Reviewing files that changed from the base of the PR and between
e0d0bd8eacand9b3f7b7e33.docs/dev/debt/changes/fix-libkernel-raise-blocked-mask.mdIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-28T12:14:08Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
Changes are required before merge: deliver a held raise on the target thread when it unblocks the signal, including when the target was never registered through a signal-mask change.
What I ran
10199f454df5fabe653d187850c62b7b122a3456against the prepared diff.RaiseHold.hpp,Exception.cpp, andSignals.cpp, plus the relevant signal-thread registration, mask-change, delivery, and raise functions. The prepared bundle excluded the three files listed indescription.mdby rule.repo_read.pywas unavailable as a command in this environment.Results
Findings
Blocking
RegisterSignalThreadis called fromChangeBlockedMaskandsigsuspend, but not when a thread starts or whenCurrentSignals()initializes.HoldRaisedExceptionlooks up the target by thread ID and treats a missing entry as unblocked. Thus a thread that blocksSIGUSR1before ever calling the mask APIs, for example by inheriting a blocked host mask, has noThreadSignalsentry; the raise falls through to immediate delivery instead of being held. Register each thread’s signal state before it can receive a directed raise, or ensure the raise path can obtain the target’s mask state. Evidence:Signals.cpp:913-915andSignals.cpp:150-157; changed call siteException.cpp:1521.Non-blocking
None.
Not verified
To get this to a good state
SignalThreadbeforesceKernelRaiseExceptionchecks their mask, then add or update coverage for a target whose signal mask is already blocked before registration would otherwise occur. Re-run the claimed platform test suites on the new head.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-28T21:28:34Z.
Review: COMMENTED
Reviewed — no blocking findings
The inspected implementation follows the described pending-raise flow, but tests and several changed-file sections were not reviewed, so a formal approval is not justified.
What I ran
Head:
89b71b72ab69b3d1f6ad0e78921911a94891fe62. No commands or tests were run. I readdescription.md,commits.md,manifest.json, anddiff.patch, then targeted ranges ofException.cppandSignals.cppthroughrepo_read.py.Results
Findings
Blocking
None in the inspected code.
Non-blocking
None.
Not verified
The full text of
Exception.cppandSignals.cppwas not read; inspection was limited to relevant ranges. The test source and CMake registration, plus the debt documentation fragment, were excluded by rule. No tests were run, and author-reported results were not independently verified. The review folder’sfiles.jsonwas unavailable; the excluded-file list was read fromdescription.md.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T09:04:23Z.
Review: COMMENTED
The Linux
guest_raise_blocked_maskCTest passed against the patched kernel and reported five delivered raises. The fixture checks pending delivery after unblocking, coalescing of repeated blocked raises, delivery aftersigsuspend, and the handler-mask case. The delivered callbacks also verify the target thread.AI-assisted: yes.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.