feat(libkernel): record semaphore operations in a memory ring dumped on fatal paths #28051
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/28051"
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 akkadbakkad89 on 2026-11-28T09:08:41Z.
What
APS5_TRACE_SYNCcurrently writes one stderr line per semaphore operation. On titles whose synchronization is hot enough to matter for a race, those writes are themselves a large perturbation: with the log on, the run of PPSA38500 discussed in #27914 survived both deaths that two untraced runs hit, so the trace hid the very behaviour it was meant to capture.This adds a memory-ring recording mode, as sketched in https://github.com/boykopovar/AnyPS5/issues/27914#issuecomment-7235062483:
APS5_TRACE_SYNC=ringrecords semaphore operations into a fixed ring of the last 65,536 records — time, thread, operation, object, count-or-bits and result — a few atomic stores per operation instead of a log write. Nothing is written during the run; the ring is written out only by the crash report (including the guestint 0x41assert path) and the abort path that the hang dump (APS5_HANG_DUMP_SECS) drives. The dump prints the records oldest-first in the established[sema]line format with the record metadata appended, so the existing log-analysis tooling keeps working.APS5_TRACE_SYNC=ring:<name>records onlysignalandwait endof the semaphore of that name, for the follow-up iteration in which even the unfiltered ring hides the race.The ring lives in libc next to the call trace, which uses the same 65,536-slot sequence-validated ring.
SyncTraceRecord_nid_no_patchis the recording entry point the kernel primitives call;SyncTraceReportRing_nid_no_patchwrites the dump and is called from the Windows fatal-exception and abort/invalid-parameter report paths and from the Linux fatal-signal report. Semaphore create, signal, wait begin, wait end, poll, cancel and delete are recorded; poll, cancel and delete are new to either mode. Names are resolved at dump time from a hash-probed side table filled at create, so a deleted semaphore still prints its name.Tested
Windows 11 + Ubuntu 24.04 (WSL).
guest_semaphore_trace_ring(new) passes: quiet without the variable; no ring dump in the legacy mode; the full ring mode dumping create/wait-begin/wait-end/signal/poll/signal/cancel/delete in sequence order with the expected counts and token values; the filtered mode recording exactly the wait end and the two signals; a filter that matches no name recording nothing; and the crash path writing the complete dump after a deliberate fatal trap.guest_semaphore_trace(legacy mode) still passes. A title run of PPSA38500 withAPS5_TRACE_SYNC=ringsurvived to the 600-second hang dump and the ring wrote its full 65,536 records covering the final 36 seconds of synchronization, with balanced wait begin/end counts and the parked threads' final wait-begins visible at the tail — details in https://github.com/boykopovar/AnyPS5/issues/27914#issuecomment-7237026733. That run also exposed the interleaving corruption fixed in the last commit (dump text and newline were two writes, so live logging from still-running threads landed inside dump lines).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
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-28T09:17:25Z.
Review: COMMENTED
Reviewed — no blocking findings
The ring tracing change is understandable from the inspected diff, but I could not run its checks; a semaphore address reused for a later object can retain the old name in the dump.
What I ran
Reviewed head
12c80ce822b77009e70349d110df07045f0af4dbusing the prepared diff andrepo_read.pyreader. No build or test commands were run.Read all added lines in the 12 changed files through the diff; also read the complete head contents of
Semaphore.cppandSyncTrace.cpp, and the review bundle README, description, commits, and manifest. No changed files were excluded.Results
Negative control
Could not run a negative control because the tests were not run.
Findings
Blocking
None identified in the inspected code.
Non-blocking
SyncTrace.cpp:104:NoteNamekeeps the first name associated with an object address. If a deleted semaphore's address is reused, later records can print the previous semaphore's name. Consider replacing the stored name when a new semaphore is created at an already-known address, or removing the mapping on delete.Sources
Not verified
Build and test results, runtime behavior on Windows and Linux, the reported PPSA38500 run, and any changed-file content beyond the added lines and the two complete source files noted above were not independently verified. The author reports tests and a title run in the PR description; those are not runs performed in this review.
To get this to a good state
Nothing is required. The name reuse point is optional feedback.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-11-28T09:18:39Z.
Review: COMMENTED
Actionable comments posted: 2
5d1ab703-53e0-4a6d-853b-12dbdef76eb0Reviewing files that changed from the base of the PR and between
29b14e4c5eand12c80ce822.core/libs/prx/libc/CMakeLists.txtcore/libs/prx/libc/include/SyncTrace.hppcore/libs/prx/libc/src/SyncTrace.cppcore/libs/prx/libc/src/specifics/linux/CrashReport.cppcore/libs/prx/libc/src/specifics/windows/CrashReport.cppcore/libs/prx/libkernel/CMakeLists.txtcore/libs/prx/libkernel/EventFlag/src/EventFlag.cppcore/libs/prx/libkernel/Semaphore/src/Semaphore.cppcore/libs/tests/SemaphoreTraceRing.cppcore/libs/tests/test_semaphore_trace_ring.pydocs/dev/ENVIRONMENT.mddocs/dev/TRACING.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-28T09:54:52Z.
Review: APPROVED
Reviewed — looks good
The change adds semaphore ring tracing and fatal report output at head
2e2c0ee40c1c5b15503519ee0da7a939e8efc4e9; inspection found no verified blocking defect.What I ran
Read the prepared diff and repository source through
repo_read.py's review reader. I did not run tests or build commands. The author reports Windows 11 and Ubuntu 24.04 (WSL) tests in the PR description; those results were not independently run here.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
No build, automated tests, title run, or physical console behavior was verified. All changed files in the manifest were read:
core/libs/prx/libc/CMakeLists.txt,core/libs/prx/libc/include/SyncTrace.hpp,core/libs/prx/libc/src/Process.cpp,core/libs/prx/libc/src/SyncTrace.cpp,core/libs/prx/libc/src/specifics/linux/CrashReport.cpp,core/libs/prx/libc/src/specifics/windows/CrashReport.cpp,core/libs/prx/libkernel/CMakeLists.txt,core/libs/prx/libkernel/EventFlag/src/EventFlag.cpp,core/libs/prx/libkernel/Semaphore/src/Semaphore.cpp,core/libs/tests/SemaphoreTraceRing.cpp,core/libs/tests/test_semaphore_trace_ring.py,docs/dev/ENVIRONMENT.md, anddocs/dev/TRACING.md.files.jsonwas not available through the reader; the manifest listed all 13 files as included.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-12-03T01:27:45Z.
Review: COMMENTED
Reviewed — no blocking findings in inspected changes
Nothing blocks the inspected changes; the point below is optional.
What I ran
Reviewed head
64d4496cf5c542d7262f8bbff439c5c95903cec2in the read-only Linux review environment. No tests or builds were run.The reader returned source, then failed while trying to append its read log to the read-only run folder. I also inspected the prepared diff and bundled changed-file texts.
Results
Negative control
Not run; the test executable was not available, and no build was performed.
Findings
Blocking
None found in the inspected changes.
Non-blocking
core/libs/prx/libc/src/SyncTrace.cpp:111:NoteNameoverwrites the name stored for an existing object address. If a deleted semaphore’s address is reused before the dump, earlier records for that address will be printed with the new semaphore’s name. A concurrent dump can also readtextwhile it is being changed. Preserve names per object lifetime or snapshot the name in each record, and cover address reuse in the ring test.Sources
Not verified
Full bundled texts were available for 9 of 13 changed files. The complete pinned-head context for the Linux and Windows crash reports and EventFlag implementation was not read; the reader returned only part of Semaphore.cpp.
files.jsonlists no rule-excluded paths. No tests, builds, or runtime crash paths were verified.To get this to a good state
Nothing is required. Optional follow-up: keep semaphore names stable across address reuse and add a test for delete/recreate before dumping.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-12-03T01:32:30Z.
Review: COMMENTED
Actionable comments
core/libs/prx/libc/src/specifics/linux/CrashReport.cpp, lines476· 🩺 Stability & Availability · ⚡ Quick winAPS5_HANG_DUMP_SECSis documented as a timed diagnostic dump. On Linux,HangWatchdogincore/libs/prx/libc/src/specifics/linux/CrashReport.cppwrites the thread and call-trace reports, then runs the registered failure reporters. None of those reporters writes the semaphore ring. The function then setsSIGABRTtoSIG_DFLat line 476, so the abort does not reachFlushOnAbort. The ring is never written on this path. AddSyncTraceReportRing_nid_no_patch();afterReportCallTrace();and beforeg_reporting.store(false, ...). This matches the fatal-signal path atCrashReport.cpp:299.Suggested fix
20850f04-f264-4b03-96e7-d8474f462d58Reviewing files that changed from the base of the PR and between
31adc63f65and64d4496cf5.core/libs/prx/libc/src/specifics/linux/CrashReport.cppcore/libs/prx/libc/src/specifics/windows/CrashReport.cppcore/libs/prx/libkernel/CMakeLists.txtdocs/dev/ENVIRONMENT.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 ligmaSec on 2026-12-03T12:36:18Z.
Review: COMMENTED
Compiled the exact semaphore and sync-trace sources and ran the direct fixture on Linux. Quiet and legacy modes, ring order, metadata, and the name filter all passed. This standalone run covered manual dumps. Crash-handler integration remains unverified. A trial merge against
mainat6c6b29320fconflicts inSemaphore.cpp.AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-12-04T14:41:37Z.
Review: COMMENTED
Actionable comments
core/libs/prx/libc/src/SyncTrace.cpp, lines161–163· 🗄️ Data Integrity & Integration · 🏗️ Heavy liftcore/libs/prx/libc/src/specifics/windows/CrashReport.cpp, lines670· 🎯 Functional Correctness · ⚡ Quick winLibcRunFailureReports_nid_no_patch()but notSyncTraceReportRing_nid_no_patch(). That function runs only registered callbacks. No registered callback dumps the ring, so records are missing from the hang dump whenAPS5_TRACE_SYNC=ringis set. On Windows, the watchdog also resetsSIGABRTtoSIG_DFLbeforeabort(), soFlushOnAbortcannot dump the ring there either.Windows watchdog (`CrashReport.cpp`, `HangWatchdog`)
Linux hang path (`linux/CrashReport.cpp`)
f47490b6-ec3c-482c-876b-30eebe315f4dReviewing files that changed from the base of the PR and between
64d4496cf5and48bd147666.core/libs/prx/libc/CMakeLists.txtcore/libs/prx/libc/src/specifics/linux/CrashReport.cppcore/libs/prx/libc/src/specifics/windows/CrashReport.cppcore/libs/prx/libkernel/Semaphore/src/Semaphore.cppdocs/dev/ENVIRONMENT.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-12-04T14:52:35Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
Changes are required before merge: preserve the name associated with each recorded semaphore instance so pointer reuse cannot relabel earlier records.
What I ran
Reviewed the prepared diff and changed lines at head
48bd1476669013e5393a4e5d527731ea06bcdfc1. I did not run tests or build commands; the author-reported tests were not independently verified.Results
Negative control
Not run; no test executable was built or run.
Findings
Blocking
NoteNameoverwrites the single side-table name for that pointer when a later semaphore reuses its address. At dump time, earlier records for the deleted semaphore then resolve to the newer semaphore's name. Preserve the name or a generation identifier with each ring record. Seecore/libs/prx/libc/src/SyncTrace.cpp:113.Non-blocking
None.
Sources
Not verified
The reported Windows, WSL, and PPSA38500 runs were not independently verified. Changed lines were read in all 13 files listed as reviewed in the manifest; no files were excluded.
To get this to a good state
Keep each recorded semaphore instance's name stable through dump time, including after its address is reused. Then rerun
guest_semaphore_trace_ringandguest_semaphore_traceon the new head.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.