fix(libkernel): keep the native signal handler out of the allocator and the pending lock #22307
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/22307"
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 Kal0s-design on 2026-11-17T11:30:08Z.
What
A host signal that arrives for a guest-blocked signal can deadlock the thread it lands on, and with it every later sender and waiter.
Dispatchruns as the host signal handler. For a signal the guest has blocked it calledMarkPending, which locks the pending mutex and inserts into astd::deque. Neither is safe in a signal handler:mallocorfree, the insertion re-enters the allocator and the thread never returns from it.In both cases the pending mutex stays held or contended, so every later
kill,sigwaitandsigpendingon the process queues behind it.The fix keeps the handler to operations that are safe there:
MarkPending: there the CRT calls the handler fromraise, on the raising thread and outside any interrupted code.guest_blocked_signal_allocatoris the regression test (POSIX hosts). 64 threads blockSIGTERMand loop onmalloc/freewhile the main thread sends each of them the host signal four times; the test fails if a worker never leaves the allocator.#19463 also changes
Signals.cpp(ktimer delivery). It does not touch the handler path, but the two will need a rebase against each other.Tested
Head
ea6760b516onmain9b7afdd507. Themaincolumn ismainwith only the new test added.Linux 6.18, GCC 16.1, Release.
guest_blocked_signal_allocator, 30 runs per build:mainsignal-unsafe call inside of a signalinMarkPendingandCurrentSignalsUnder ASan the test passes on
mainas well: ASan's allocator does not deadlock on re-entry, so those builds do not show the defect.The 18 tests of the signal, itimer, ktimer and pselect set, one run each:
mainmainfailsguest_signals,guest_broken_pipe,guest_signal_handler_maskand the new test. With this changeguest_broken_pipeandguest_signal_handler_maskpass, and thesignal-unsafe callreports are gone.guest_signalsstill fails under TSan with a lock-order inversion inDiscardPendingIfIgnored. That is a separate defect, present onmain, and not addressed here.Windows, WinLibs GCC 15, Release: the 16 tests of the same set that exist on Windows pass in 3 of 3 runs. The handler path is unchanged there.
tools/check_conventions.pypasses.Not tested: macOS, and no title was run.
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)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-17T11:37:22Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
ea6760b516:tools/check_conventions.pypassed.guest_blocked_signal_allocator_testsbuilt cleanly.guest_blocked_signal_allocator):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
Pull request closed