From 51868dfbe58a868029f1ad7fb4ebc0327c6cc724 Mon Sep 17 00:00:00 2001 From: Moriz82 <72836413+Moriz82@users.noreply.github.com> Date: Tue, 24 Nov 2026 12:20:41 -0600 Subject: [PATCH] runtime: report the memory region for a traced access violation (RT-STARTUP-TRACE) An access violation in the startup trace gives the address and operation but does not identify the allocation or its page protection. When startup tracing is enabled, query the memory region at the fault address. Include its state, protection, type and allocation bounds when the query succeeds. The exception handler continues its usual search. Cross-built gta6rt and startup_trace_test. With the new assertion, 1 of 27 checks failed on the base. All 27 passed with the change under Wine. AI-assisted (Codex and Claude Code agents). Co-authored-by: Plaaasma <47513553+Plaaasma@users.noreply.github.com> Co-Authored-By: Claude Fable 5.2 --- runtime/shims/startup_trace.h | 8 ++++++++ runtime/test/startup_trace_test.cpp | 2 ++ 2 files changed, 10 insertions(+) diff --git a/runtime/shims/startup_trace.h b/runtime/shims/startup_trace.h index 7b47d993ae..bf3939292d 100644 --- a/runtime/shims/startup_trace.h +++ b/runtime/shims/startup_trace.h @@ -18,6 +18,7 @@ // same handler records their text without a shim. // // The file can quote whatever the game prints: it stays on the player's machine (AGENTS.md, "No game data"). +// A successful query adds the memory region containing the address of an access violation. #pragma once #include @@ -181,6 +182,13 @@ inline void log_exception(const EXCEPTION_POINTERS& info) { const auto op = r.ExceptionInformation[0]; f += ",\"access\":" + quote(op == 0 ? "read" : op == 1 ? "write" : "execute") + ",\"address\":" + quote(hex(r.ExceptionInformation[1])); + // The faulting page's region: committed or not, its protection, private or a mapped view. + MEMORY_BASIC_INFORMATION m{}; + if (VirtualQuery(reinterpret_cast(r.ExceptionInformation[1]), &m, sizeof(m))) + f += ",\"region\":{\"base\":" + quote(hex(reinterpret_cast(m.BaseAddress))) + + ",\"allocation_base\":" + quote(hex(reinterpret_cast(m.AllocationBase))) + + ",\"size\":" + quote(hex(m.RegionSize)) + ",\"state\":" + quote(hex(m.State)) + + ",\"protect\":" + quote(hex(m.Protect)) + ",\"type\":" + quote(hex(m.Type)) + "}"; } if (r.ExceptionCode == kCppException) f += ",\"cpp\":true"; if (info.ContextRecord) f += ",\"stack\":" + stack_from(*info.ContextRecord); diff --git a/runtime/test/startup_trace_test.cpp b/runtime/test/startup_trace_test.cpp index 336f957eb4..170ea39d55 100644 --- a/runtime/test/startup_trace_test.cpp +++ b/runtime/test/startup_trace_test.cpp @@ -272,6 +272,8 @@ void test_trace(const fs::path& dir) { check(has(e, "\"code\":\"0xc0000005\""), "exception code"); check(has(e, "\"at\":" + mod + hex_rva(kFaultRva) + "\""), "exception address is module+RVA"); check(has(e, "\"access\":\"read\"") && has(e, "\"address\":\"0x0\""), "access kind and faulting address"); + check(has(e, "\"region\":{\"base\":\"0x0\"") && has(e, "\"state\":\"0x10000\""), + "the faulting page's region (address 0 is free memory)"); check(has(e, "\"stack\":[" + mod.substr(0) + hex_rva(kFaultRva)), "stack starts at the faulting instruction"); check(find_line(lines, "exit") == &lines.back(), "exit comes last");