Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions runtime/shims/startup_trace.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <windows.h>
Expand Down Expand Up @@ -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<const void*>(r.ExceptionInformation[1]), &m, sizeof(m)))
f += ",\"region\":{\"base\":" + quote(hex(reinterpret_cast<uint64_t>(m.BaseAddress))) +
",\"allocation_base\":" + quote(hex(reinterpret_cast<uint64_t>(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);
Expand Down
2 changes: 2 additions & 0 deletions runtime/test/startup_trace_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Loading