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");