feat(libkernel): run SA_SIGINFO handlers for SIGSEGV and SIGBUS host faults #26653
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/26653"
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-24T13:36:27Z.
What
A guest that installs its page-fault handler with
sigaction(SIGSEGV or SIGBUS, SA_SIGINFO)never had it called: the handler was recorded, and the fault ended the process as unhandled. This is how PCSX2's fastmem works (PageFaultHandler::Installincommon/Linux/LnxHostSys.cpp): the recompiled code reads guest memory through a reserved area, and the first access to an unmapped page faults. The handler reads the fault address andripfrom the context, patches the code to the slow path and returns.Host faults in guest code now reach that handler on Windows and Linux, through the same path that
sceKernelInstallExceptionHandlerhandlers use. This happens when no such handler is set for the signal (it keeps precedence) and the signal is not blocked. The handler gets:siginfo_t:si_codeSEGV_MAPERR/SEGV_ACCERRorBUS_ADRALN/BUS_OBJERR, the fault address insi_addr, and the trap number at offset 40;ucontext_t, withmc_trapno,mc_addrandmc_errfilled.On Windows the handler is reached through
HandleHostFault, the last step of libc'sReportCrash, after the arena recovery, the arena write and read handling, the write watch and the SSE4a emulation; read traps registered first in the vectored chain (#26643) are resolved before that. On Linux,DeliverFaultgives the write watch the fault first. When SIGSEGV or SIGBUS takes anSA_SIGINFOaction,sigactionleaves the host fault handler in place instead of resetting the host signal.Register changes are applied when the handler returns, and the handler runs under the mask,
SA_NODEFERandSA_RESETHANDrules of the othersigactionhandlers. macOS is unchanged, since the fault delivery path is not installed there. OtherSA_SIGINFOhandlers are still not called.guest_siginfo_fault(Windows and Linux) installs anSA_SIGINFO | SA_NODEFERhandler on SIGSEGV. It checks thesiginfo_tfields and themc_trapno,mc_addr,mc_errandripoffsets that PCSX2 reads, for a read of an unmapped address and a write to a read-only page. It also checks that execution resumes, once with registers the handler changed and once after it remaps the page. A debt fragment adds an entry for these handlers and points thesigactionentry to it.Tested
Windows 11, NVIDIA GeForce RTX 2060, driver 621.24, WinLibs GCC 15.2.0, Release. At head
51cd4a3973(onmain566e3c6da9),guest_siginfo_faultpasses 200 of 200 runs, andguest_signals,guest_signal_context,guest_signal_interrupt,guest_signal_handler_maskandguest_aio50 of 50 each. WithException.cppfrom before51cd4a3973,guest_siginfo_faultfails on Windows (the no-access page).Linux: WSL2 Ubuntu 24.04 (kernel 6.18) on the same machine, GCC 13.3, Release. At
51cd4a3973,guest_siginfo_faultpasses 200 of 200 runs, andguest_signals,guest_signal_context,guest_signal_interruptandguest_signal_handler_mask50 of 50 each. WithException.cppandSignals.cppfrom before21b843b88f,guest_siginfo_faultfails on Linux at thesi_codecheck of the untouched read-only page.PS5SX2 (PPSA99203) vk-285-321, "PS2 system menu" option, with its default
fastmemflag on. Before this change it stopped 3 of 3 times as the option started:FATAL: unhandled exception 0xc0000005 on thread 'CPU Thread', a read of0x3b0000000from the recompiled code (fastmem base0x300000000). With it, on the older local tree (00ede212a0) with this change applied, the option starts and ran for 8 minutes with no error, reaching its first screen. That run also bypassed three other stops locally, so it doesn't show the title working onmain:noautoprofflag file, for SIGPROF sent throughpthread_killto an SA_SIGINFO handler on another thread.ProsperoCraft (PPSA99874 01.000.288), on Windows on
maine8daa4b6c6with #27330 (which its JVM needs for its heap): its JVM installs its SIGSEGV and SIGBUS handlers withSA_SIGINFO. Without this change, 5 of 5 runs stopped withFATAL: unhandled exception 0xc0000005 on thread 'ProsperoCraft download'while the launcher downloaded files; with it, one run downloaded all 5209 files (576 MB) without a stop and another reached 231 of 575 MB before I ended it. Details in the comments.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
SA_SIGINFOhandlers can receive guest-code segmentation and bus faults on supported platforms, with fault details and execution context.Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-24T13:37:55Z.
Review: CHANGES_REQUESTED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
7054633331:tools/check_conventions.pypassed.guest_siginfo_fault_testsbuilt cleanly.guest_siginfo_fault):Requesting changes for the points above.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-25T14:04:11Z.
Review: COMMENTED
Reviewed — comments
The prepared review bundle and pinned repository source could not be read, so the change is not verified and no merge decision is justified.
What I ran
No reader commands ran: this session does not expose a shell or repository reader tool. The stated head is
14999dce09ea03da09c73e98f28d4bcb8bf4a8b6.Results
Findings
Blocking
None verified.
Non-blocking
No code findings; the review is incomplete.
Not verified
Could not read
description.md,commits.md,manifest.json,diff.patch,files.json, or any changed source files. No files were read, so the reviewed-file count is 0; the expected reviewed-file list could not be determined. Logic, security, performance, and test coverage are not verified.To get this to a good state
Nothing is required. Optional: make the reader available and rerun the full review against the pinned head.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-11-26T21:06:52Z.
Review: COMMENTED
Actionable comments posted: 4
54850cda-f864-4e7f-aee6-6a18fd97d8faReviewing files that changed from the base of the PR and between
566e3c6da9and07b671e558.core/libs/prx/libkernel/System/include/FaultSignals.hppcore/libs/prx/libkernel/System/src/Exception.cppcore/libs/prx/libkernel/System/src/Signals.cppcore/libs/prx/libkernel/tests/cmake/guest_siginfo_fault_tests.cmakecore/libs/tests/GuestSiginfoFault.cppdocs/dev/debt/changes/feat-libkernel-sa-siginfo-delivery.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-26T21:19:52Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
Changes are required before merge: the Windows fault path clears the siginfo marker before using it, so the new handler is invoked with a null function pointer.
What I ran
Reviewed head
07b671e558d344c024e4b9a29a7db2472c55dbd7using the prepareddiff.patch, manifest and repository readerrepo_read.py. I did not run tests or build commands.Results
Findings
Blocking
Exception.cpp:1042:FaultEntryclearspendingFault.siginfoand then passes that cleared field toDeliver. For a Windows SA_SIGINFO fault,pending.handleris null andsiginfois true, but this call passes false;CallHandlerthen calls the nullhandleratException.cpp:196. Preserve the copied pending flag in a local value before clearing the pending state, and pass that value toDeliver.Non-blocking
None.
Not verified
Tests and builds were not run. The review folder listed all six changed files as included, and I read the changed code in each:
FaultSignals.hpp,Exception.cpp,Signals.cpp,guest_siginfo_fault_tests.cmake,GuestSiginfoFault.cpp, andfeat-libkernel-sa-siginfo-delivery.md. No changed file was excluded.To get this to a good state
Fix the Windows pending-fault siginfo flag handling and rerun the relevant Windows fault-delivery tests.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-11-26T22:50:54Z.
Review: COMMENTED
dbb0f748-0d14-4611-898f-edf57478dc4fReviewing files that changed from the base of the PR and between
07b671e558and21b843b88f.core/libs/prx/libkernel/System/src/Exception.cppcore/libs/prx/libkernel/System/src/Signals.cppcore/libs/tests/GuestSiginfoFault.cppdocs/dev/debt/changes/feat-libkernel-sa-siginfo-delivery.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-26T22:59:59Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the checks and source reviewed support merging.
What I ran
Reviewed head
21b843b88f0eb8f0109334395eb17ae9a93379c5usingrepo_read.pyto inspect the prepared diff and targeted source ranges. No commands or tests were run.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
Tests and builds were not run; reported test results in the PR description were not independently verified. The full changed-file text was available for all six files listed in
manifest.jsonand was reviewed. No excluded changed files were listed in the manifest.files.jsonwas unavailable through the reader, so exclusion details beyond the prepared manifest are not verified.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-26T23:40:39Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the reviewed code supports merging.
What I ran
Reviewed head
51cd4a3973945859980db0660ba4a5f7fa1be07cusing the prepared description, commits, manifest, diff, andrepo_read.pyfor targeted source reads. No commands or tests were run. The author-reported test results were not independently verified.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
Did not run tests or verify behavior on Windows, Linux, macOS, or console hardware. The author's reported runs are recorded in the PR description and were not independently confirmed. Read all changed files listed as
reviewedinmanifest.json:FaultSignals.hpp,Exception.cpp,Signals.cpp,guest_siginfo_fault_tests.cmake,GuestSiginfoFault.cpp, andfeat-libkernel-sa-siginfo-delivery.md. No changed files were excluded.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-27T11:52:37Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
51cd4a3973:tools/check_conventions.pypassed.guest_siginfo_fault_testsbuilt cleanly.guest_siginfo_fault):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