loader: attribute guest faults to modules and print a backtrace #836
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
GPU
GUI
help wanted
question
Shaders
Video
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/KytyPS5--KytyPS5!836
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/836/head"
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?
@theantipopau on GitHub · 2026-09-25 20:43 UTC · original
theantipopau:guest-fault-backtrace→main· +664 −2 · 5 files · 5 commits · closed without mergingProblem
An unhandled guest exception prints the faulting thread, the register file, 96 bytes around the
faulting pc and a raw word dump of the top of the stack, but it never says which module the
faulting address belongs to. Game-compatibility issues quote this log verbatim, so triage starts
with guessing which of the game's modules a
0x9000...code address lives in.libC.cppalready does the right thing for guestabort(): it annotates every stack word thatresolves to a loaded module with
module+offsetand prints aRuntimeLinker::StackTracebacktrace.The fault reporter is the one crash path that does not.
Astro Bot (PPSA21564) is a live example. #835 reports a read of
0xffffffffffffffffatpc=0x9000006a1on theSceSndzAudioOutMainthread, and the log cannot attribute that addressto any module, so the report cannot be acted on as it stands.
Changes
fault pc: 0x... module+0xoffsetline before the register dump.backtrace:section, walked with the existingWalkGuestStackthe same way guestabort()does it.stack:dump: any word that resolves to a loaded module now carriesmodule+0xoffset. Words that do not resolve still print their raw value, so the report losesno information it had before.
RuntimeLinker::Current(), a non-constructing accessor for the live linker.RuntimeLinker::TryFindProgramByAddr(), the segment walk used by the reporter.Loader::FormatGuestFrame(), themodule+0xoffsetrendering.The last two exist because the reporter has to stay safe to run from an exception handler:
Common::Singleton<RuntimeLinker>::Instance()constructs on first use, so calling it from thereporter would allocate a linker inside the handler if the fault happens before the game is
linked. Allocating there can fault again and wedge the reporting thread.
Current()returns thepointer the constructor already publishes, and
nullptrwhen nothing is linked yet.TryFindProgramByAddr()takes the linker mutex withTryLockinstead of blocking. A guest faultcan land on a thread that already owns the mutex, e.g. during a concurrent load or unload, and a
blocking lock would hang the crash report. When the lock is contended it returns
nullptrandthe report degrades to
module=<unknown>, which is better than a hang. It also skips programswhose
Elf64is not loaded yet rather than dereferencing it, and never raises, so it cannotrecurse into its own handler.
Testing
Windows, clang-cl + Ninja, Release:
virtual_memory_allocation_tests: all cases passed, including the newGuestFaultFrameAttributioncase. It checks the exact rendering, the zero-offset andmaximum-offset ends of the range, the null and empty module name, and the offset clamp for an
address below the module base.
kyty_emulator: clean build and link.This is build and unit test evidence only. It was not verified against a real game, and the local
driver cannot run the production rasterization tests
(
VK_EXT_attachment_feedback_loop_dynamic_stateis missing), so the new report lines have not beenobserved in a live crash log yet.
Risk
Low, and diagnostics only. The report is already fatal and already exits, so the only behaviour
change is what it prints before it does. Nothing is added to the non-fault path, and no decode,
load, or memory behaviour changes. The two new accessors are additive;
FindProgramByAddrandSingleton<>are left untouched for existing callers.Next
#835 is a good first exercise of the new output: the next reporter of that crash should get the
module name for the faulting pc and a backtrace through the audio thread, instead of a bare address.
@coderabbitai[bot] on GitHub · 2026-09-25 20:50 UTC · original · edited 2026-09-26 03:16 UTC
Navigate logical layers of code changes, visualize relationships, and explore their blast radius.
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
Review profile: CHILL
Plan: Advanced
Run ID:
fa2def9b-105c-43db-b5c6-2593b2cbf005📥 Commits
Reviewing files that changed from the base of the PR and between
1cd7a72cb4and484c0dc41a.📒 Files selected for processing (1)
src/loader/x64InstructionDecoder.cpp🚧 Files skipped from review as they are similar to previous changes (1)
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
📝 Walkthrough
Walkthrough
The fault report decodes the instruction at a readable fault PC using captured guest registers. It reports the instruction text and length, memory access type, and effective address when available, while retaining the code-byte dump. The runtime linker returns copied module metadata for address and stack-word attribution. Its current-instance pointer now uses atomic operations. A report gate coordinates fault reporting with linker teardown. Tests cover instruction decoding, address resolution, memory access classification, and incomplete input.
Priority: ⬇️ Low
Change: Feature
Merge Risk: ⚪ Minimal · up to
484c0The inspected fault-report paths do not show a merge-blocking issue; the change is ready for normal checks.
Security Architecture Review
Security architecture risk: 🔵 Low · up to
1cd7aCrash reports gain useful fault details, but module attribution may allocate memory while handling a fault and holding locks. That creates a limited risk that a guest-triggered failure prevents orderly reporting or shutdown. No broader privilege or service-boundary change is established.
Retained concerns
Security review details
Security Blast Radius
Security Findings and Attack Paths
Trust Boundaries and Controls
Resilience and Maintainability Implications
Hardening Proposals
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Comment
@coderabbitai helpto get the list of available commands.@coderabbitai[bot] on GitHub · 2026-09-25 20:50 UTC · original · edited 2026-09-26 01:36 UTC
On
src/loader/runtimeLinker.cppline 1242 (outdated):🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy lift
Synchronize access to the current linker.
A worker thread can enter
KytyExceptionHandler()while the main thread destroysRuntimeLinker. The handler readss_currentthroughCurrent(), while the constructor and destructor write that plain pointer. This is a data race, and a loaded pointer does not keep the linker alive during reporting. Synchronize publication and teardown with fault reporting; an atomic pointer alone does not solve the lifetime race.Also applies to: 1246-1246, 1250-1251
✅ Addressed in commits
ce8132ctoda13cfc@coderabbitai[bot] on GitHub · 2026-09-25 20:50 UTC · original · edited 2026-09-26 01:36 UTC
On
src/loader/runtimeLinker.cppline 1596 (outdated):🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy lift
Keep the program alive through report formatting.
TryFindProgramByAddr()releasesm_mutexbefore it returnsfound. If another thread callsUnloadProgram(), that thread can delete the returnedProgrambeforeReportGuestAddress()or the stack dump reads its name andbase_vaddr. Return a diagnostic snapshot made under the lock, or hold a lifetime guard through formatting. Based on learnings, readers of objects referenced by a mutable collection must use the mutex that protects deletion.Source: Learnings
✅ Addressed in commits
ce8132ctoda13cfc@coderabbitai[bot] on GitHub · 2026-09-25 20:50 UTC · original · reviewed
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
Review profile: CHILL
Plan: Advanced
Run ID:
cc86d522-00ae-46fb-8523-3f96dfd42e19📥 Commits
Reviewing files that changed from the base of the PR and between
497166009candd875ddd9f9.📒 Files selected for processing (3)
src/loader/runtimeLinker.cppsrc/loader/runtimeLinker.htests/VirtualMemoryAllocationTests.cppIncluded review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.
@theantipopau on GitHub · 2026-09-26 01:30 UTC · original
On
src/loader/runtimeLinker.cppline 1596 (outdated):Fixed in
da13cfc7—TryFindProgramByAddris nowTryDescribeProgramByAddrand returns a value instead of a pointer:The segment walk is unchanged, but the module name and base are copied into the result while
m_mutexis still held, and the lock is released only after the copy. Both call sites (ReportGuestAddressand the stack annotation) then format from the snapshot, so noProgram*escapes the lock andUnloadProgramcan no longer free it underneath the report.GetProgramModuleNamereads onlydynamic_info->so_nameandfile_nameand takes no lock, so calling it underTryLockis safe and does not nest.@theantipopau on GitHub · 2026-09-26 01:30 UTC · original
On
src/loader/runtimeLinker.cppline 1242 (outdated):Partly fixed in
da13cfc7, and I want to be precise about the part that is not.s_currentis nowstd::atomic<RuntimeLinker*>: the constructor stores, the destructor storesnullptrbeforeClear(), andCurrent()loads. That removes the data race on the pointer itself, which is real UB and was introduced by adding a cross-thread reader in the fault reporter.What is not fixed is the lifetime half of your point, and you are right that the atomic alone does not address it. A reporter that has already loaded a non-null pointer can still race with
~RuntimeLinkertearing down state. Closing that properly needs either a refcount that the reporter pins, or deferring teardown until in-flight reports drain — both are a much larger change than this PR, and blocking in a destructor on a thread that may be the one taking the fault is its own hazard.I would rather not pretend the atomic settles this. Suggesting it as a follow-up rather than half-implementing a lifetime scheme here, unless you would rather I attempt the pin-or-defer version in this PR.
The store order in the destructor is deliberate:
s_current.store(nullptr)happens beforeClear(), so any report that starts once teardown begins seesnullptrrather than a half-destroyed linker. That narrows the window to reports already in flight; it does not close it.@ -0,0 +208,4 @@}result.effective_address = address;}} break;@coderabbitai[bot] on GitHub · 2026-09-26 01:36 UTC · original · edited 2026-09-26 03:15 UTC
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Classify memory access from hidden operands too.
The loop visits only
operand_count_visibleoperands. Zydis marks implicit memory operands as hidden. Examples are[rdi]/[rsi]formovs/stos/cmps/scasand the stack slot forpush/call. The common fault sites below therefore reportreads_memory == writes_memory == falseand no effective address:rep movsborrep stosq.pushorcall.The header states that these fields are true "when the instruction actually touches memory". The report then says the instruction does not access memory, which is wrong. Keep the text rendering limited to visible operands. Run the access-classification pass over all
instruction.operand_countoperands.operandsalready holdsZYDIS_MAX_OPERAND_COUNTentries, so the extra pass allocates nothing.♻️ Proposed change
✅ Addressed in commit
484c0dc@coderabbitai[bot] on GitHub · 2026-09-26 01:36 UTC · original · edited 2026-09-26 03:17 UTC
On
src/loader/x64InstructionDecoder.cppline 189 (outdated):🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Fix the "unresolved" labeling rule.
resolvedrequiresIsGeneralPurposeRegister(operand.mem.base).ZYDIS_REGISTER_NONEis not a general purpose register. The rule is wrong in two ways:[0x1000],moffsand[rcx*8+disp],ResolveMemoryOperandcomputes the correct address. The text still showsunresolved.fs:/gs:operands: forfs:[rax]orgs:[0x28], the segment base is not included. The operand can still be labeled resolved, andeffective_addressrecords the wrong address.Treat a missing base or index as resolved. Mark FS/GS-segment operands unresolved, and do not report their
effective_addressas the fault address.🐛 Proposed fix
📝 Committable suggestion
✅ Addressed in commit
484c0dc@coderabbitai[bot] on GitHub · 2026-09-26 01:36 UTC · original · reviewed
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
Review profile: CHILL
Plan: Advanced
Run ID:
f1c27df5-6f38-42d2-9713-c822fbbb508a📥 Commits
Reviewing files that changed from the base of the PR and between
d875ddd9f9andda13cfc77e.📒 Files selected for processing (5)
src/loader/runtimeLinker.cppsrc/loader/runtimeLinker.hsrc/loader/x64InstructionDecoder.cppsrc/loader/x64InstructionDecoder.htests/VirtualMemoryAllocationTests.cpp🚧 Files skipped from review as they are similar to previous changes (1)
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
@coderabbitai[bot] on GitHub · 2026-09-26 01:36 UTC · original
On
src/loader/runtimeLinker.cppline 1596 (outdated):🧩 Analysis chain
🏁 Script executed:
Length of output: 9557
@theantipopau, thanks for the shell results. They verify thatTryDescribeProgramByAddr()copies the module name and base address whilem_mutexis held. Both report paths use the returned snapshot, so the reportedProgram*lifetime issue is fixed. My earlier statement that repository verification was unavailable was incorrect.✅ Review thread resolved.
You are interacting with an AI system.
@coderabbitai[bot] on GitHub · 2026-09-26 01:37 UTC · original
On
src/loader/runtimeLinker.cppline 1242 (outdated):@theantipopau, thanks for the precise distinction. The atomics_currentremoves the data race on the pointer. StoringnullptrbeforeClear()prevents later loads from obtaining the linker, but it does not protect a reporter that already loaded the pointer.I would leave the lifetime concern open rather than ask for a partial pin-or-defer scheme in this PR. A follow-up should define how in-flight reporters finish before linker teardown without making the fault handler wait on a lock. Would you like me to open a GitHub issue for that work?
✏️ Learnings added
You are interacting with an AI system.
@theantipopau on GitHub · 2026-09-26 02:00 UTC · original
On
src/loader/runtimeLinker.cppline 1242 (outdated):Closed in
1cd7a72c, with a report gate rather than a pin or deferred teardown.s_currentbeing atomic was never the hard part; the hard part is that a report must not be holding a pointer to a linker whose state is being freed. So publication and teardown are now gated together:The reporter takes it with
TryLockfor the whole attribution pass, and the destructor takes it with a real lock before clearing the pointer:That gives the ordering the atomic alone could not: once the destructor's gate section completes, no report can obtain a non-null pointer, and any report that already had one has finished, because it held the gate for its entire use of the linker.
Clear()then runs with no reader.Two details worth calling out:
TryLock, notLock, in the reporter. A fault must never block. Losing the race against teardown costs only the module names and falls back to the samemodule=<unknown>output a busy linker already produces, which is why the existingTryDescribeProgramByAddris already written to degrade that way.s_currentis tested before the gate is touched, and re-read under it. Testing first means a fault that arrives before this translation unit is dynamically initialised never touches an unconstructedCommon::Mutex. Re-reading under the gate is what makes the pairing airtight: if the destructor cleared the pointer between the first read and the lock, the re-read returns null and attribution is skipped rather than reading a linker mid-destruction.Verified:
kyty_emulatorbuilds andvirtual_memory_allocation_testspasses, includingGuestFaultFrameAttributionandGuestFaultInstructionDecoding.One thing I did not do: add a unit test. The existing tests deliberately cover only the pure parts of this path (
FormatGuestFrame) without loading a program, and a deterministic test for this race needs a realRuntimeLinkerbeing constructed and destroyed on the main thread while a worker reads — which is not something the current test harness can host. So this is verified by construction and review rather than by a targeted test, and I would rather say that than add a test that only appears to cover it.@coderabbitai[bot] on GitHub · 2026-09-26 02:14 UTC · original
On
src/loader/runtimeLinker.cppline 1242 (outdated):🧩 Analysis chain
🏁 Script executed:
Length of output: 1051
🏁 Script executed:
Length of output: 1744
@theantipopau, thanks for the verification details.Common::Mutex::TryLock()uses a non-blocking platform call, andLock()waits for the gate. In1cd7a72, the reporter re-readss_currentafter taking the gate and holds it throughout linker attribution. The destructor clearss_currentunder the same gate beforeClear(). This addresses the reported lifetime race. I agree that the existing tests do not directly exercise this race.🧠 Learnings used
✅ Review thread resolved.
You are interacting with an AI system.
@theantipopau on GitHub · 2026-09-26 03:15 UTC · original
On
src/loader/x64InstructionDecoder.cppline 189 (outdated):Fixed in
484c0dc4.resolvednow requires only that any present base/index be a general-purpose register —ZYDIS_REGISTER_NONEfor either no longer forces "unresolved", so[0x1000],moffsand index-only operands like[rcx*8+disp]now print without the label.For fs:/gs: I went with the conservative half of your second point rather than reporting an address:
GuestX64Registerscarries no segment bases, so there is nothing to resolve against, and a seg:[offset] value is not a linear address. Those operands are markedunresolvedand, because the consumer at runtimeLinker.cpp:791 printsfault addr from insnwheneverreads_memory || writes_memory, theresolvedflag now also gates the access flags — so fs:/gs: accesses never report their segment-relative offset aseffective_address.Rebuilt
kyty_emulator+virtual_memory_allocation_tests; the suite includingGuestFaultInstructionDecodingpasses (after the usual 13824 MB reservation retry).@coderabbitai[bot] on GitHub · 2026-09-26 03:17 UTC · original
On
src/loader/x64InstructionDecoder.cppline 189 (outdated):🧩 Analysis chain
🏁 Script executed:
Length of output: 19417
@theantipopau, I can verify the fix now. Commit484c0dcallows absent base and index registers, marks FS/GS operands unresolved, and prevents those operands from setting the memory-access flags that triggerfault addr from insn. This addresses the finding. Thanks for the test results.✏️ Learnings added
✅ Review thread resolved.
You are interacting with an AI system.
@Nmzik on GitHub · 2026-09-27 11:57 UTC · original
This is unnecessary private debug code. Let’s keep it out of the main repository
@theantipopau on GitHub · 2026-09-27 13:04 UTC · original
Understood, thanks for taking the time to look. Dropping it.
For the record on what was in there, in case it is useful: the branch was the
guest-fault report path in
src/loader/runtimeLinker.cpp— a faulting-addressbacktrace with a
Loader::SymbolDatabaselookup, plus a decoder change so amissing base/index is reported as
resolvedandfs:/gs:segment-relativeaddresses are not printed as the fault address. None of the reporting should
have been in
mainin that form, and I have not opened a replacement.One narrow question, so I do not re-propose something you have already ruled
out: is the decoder half on its own (marking a missing base/index as
resolved, and leavingfs:/gs:asunresolved) a correctness fix youwould take, or is that report text as a whole considered debug-only? I will
leave it alone either way.
Pull request closed