mirror of
https://github.com/ubiquitarianism/leonida.git
synced 2026-11-27 00:45:53 +01:00
[PR #994] [CLOSED] runtime: opt-in unhandled-exception log with module+RVA and stack (RT-CRASH-STACK) #1030
Labels
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
starred/leonida#1030
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
📋 Pull Request Information
Original PR: https://github.com/ubiquitarianism/leonida/pull/994
Author: @roanh47
Created: 11/24/2026
Status: ❌ Closed
Base:
main← Head:pr/crash-stack📝 Commits (2)
a8b754aruntime: opt-in unhandled-exception log with code, module+RVA, thread and stack (RT-CRASH-STACK)6fa4c87runtime: keep the crash log handler lock-free and cover held-lock faults (RT-CRASH-STACK)📊 Changes
12 files changed (+1030 additions, -15 deletions)
View changed files
📝
docs/boot.md(+6 -0)📝
runtime/CMakeLists.txt(+13 -0)📝
runtime/README.md(+31 -0)➕
runtime/shims/crash_log.h(+316 -0)➕
runtime/shims/module_ranges.h(+153 -0)📝
runtime/shims/registry.cpp(+5 -0)📝
runtime/shims/shims.h(+5 -0)➕
runtime/shims/stack_walk.h(+53 -0)📝
runtime/shims/startup_trace.h(+5 -14)📝
runtime/src/main.cpp(+4 -0)📝
runtime/src/pe_loader.cpp(+8 -1)➕
runtime/test/crash_log_test.cpp(+431 -0)📄 Description
Claimed in the coordination issue as: RT-CRASH-STACK
Claim: https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7137294269
Why
The startup trace already records
module+0xRVAand a 16-frame stack for every exception, but only with--trace, and it records every first-chance exception too, so the one that ended the run can be buried among handled ones. Without--tracethere is no module or RVA at all for the current post-CLZERO0xC0000005.This adds an opt-in log for exactly the exception that ended the process: it needs no
--trace, writes its own file, and adds the faulting context (rip/rsp/rbp) plus the raw faulting address next tomodule+0xRVA. Termination and the exit code are untouched.What
LEONIDA_CRASH_LOG(unset or0: off):LEONIDA_CRASH_LOG=<file>writes the block to that file and stderr.LEONIDA_CRASH_LOG=1(oron/true) uses the overlay'sleonida-crash.log, so it never writes into the package.runtime/shims/crash_log.hinstalls aSetUnhandledExceptionFilterhandler, so only an exception nothing handled is logged (not the ones a shim's__tryor acatchdeals with). It returns the previous filter's answer (EXCEPTION_CONTINUE_SEARCHwhen there was none), so the process still ends with the same exception code; a filter installed before the log still runs.The handler is lock-free by design, because a fault can happen with the shim registry's lookup lock or the Loader's range lock already held and the log must not turn a crash into a hang:
runtime/shims/module_ranges.his a table of image base/end ranges, published by the Loader as it maps and byinstall()for the host modules seen then. Readers use a per-slot seqlock over atomics and fixed name buffers: no mutex, noshims::module_offset, no Loader call.WriteFileon handles opened at install, so it takes no CRT/stdio lock and allocates nothing;A sample from the mapped-image test:
runtime/shims/stack_walk.hholds the frame walkstartup_trace.halready had; the trace uses it too, so the two diagnostics agree onmodule+0xRVAfor mapped images andhost:name.dll+0xRVAfor host modules.Known limitation: host DLLs loaded after
install()(the game'sLoadLibrary, the Vulkan loader) have no entry and their frames print as raw addresses. Mapped images are always current because the Loader republishes its ranges on every map. A second concurrent Loader would replace the first one's table; gta6rt has one.Docs:
runtime/README.md, "Unhandled-exception log:LEONIDA_CRASH_LOG";docs/boot.mdpoints to it for the post-CLZERO0xC0000005.Test
runtime/test/crash_log_test.cpp(CTestcrash_log; synthetic, no game files, no GPU):0,1and a path, plusclose();0xC0000005;crash_image.bin+0x1220, the game's shape of address;LEONIDA_CRASH_LOG, so the file cannot be opened: the block still reaches stderr and the exit code is unchanged;shims::with_module_lookup_lock_for_test, a new test seam). The old handler would deadlock inmodule_offsethere; this one completes, logs the module+RVA and ends with0xC0000005;0xC0000005and writes nothing.pe_loader_fuzz(the Loader now publishes ranges on each map) passed in 41.11 s.crash_log_testitself reports 46 checks, 0 failed.Built with MSVC 19.44 (VS 2022 BuildTools), RelWithDebInfo, Ninja. No Vulkan SDK in this build, so the Vulkan D3D12 device was left out; nothing here touches it. Tested on Windows 10.0.26300, Intel Core i7-10700F. No GPU or driver path is involved in this change.
AI-assisted (DeepSeek v4.1 Flash 1017).
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.