From 71fce1a170fc87bdf94461b725cb732e5572e2e7 Mon Sep 17 00:00:00 2001 From: patchzyy <64382339+patchzyy@users.noreply.github.com> Date: Thu, 22 Oct 2026 21:21:47 +0200 Subject: [PATCH] dump kamek overlay on crash (#335) --- runtime/include/system_bridge.h | 3 ++- runtime/src/system_bridge.cpp | 27 +++++++++++++++++---------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/runtime/include/system_bridge.h b/runtime/include/system_bridge.h index a2d4cf6..1c2ab8e 100644 --- a/runtime/include/system_bridge.h +++ b/runtime/include/system_bridge.h @@ -84,7 +84,8 @@ public: // Crash-path helpers shared by the centralized reporter in main.cpp. // DumpCrashHeuristics prints plain-language "likely cause" hints derived // from the register state; WriteGuestMemorySnapshot writes MEM1 to - // `mem1Path` and MEM2 to `mem1Path + ".mem2"`, logging outcomes to `os`. + // `mem1Path`, MEM2 to `mem1Path + ".mem2"` and the Kamek overlay to + // `mem1Path + ".kamek"`, logging outcomes to `os`. static void DumpCrashHeuristics(std::ostream& os, const struct CpuContext* cpu, const uint32_t* missingGuestTarget); static void WriteGuestMemorySnapshot(std::ostream& os, const std::filesystem::path& mem1Path); diff --git a/runtime/src/system_bridge.cpp b/runtime/src/system_bridge.cpp index 18ca7c6..99f2abd 100644 --- a/runtime/src/system_bridge.cpp +++ b/runtime/src/system_bridge.cpp @@ -413,14 +413,18 @@ void SystemBridge::Initialize() { } void SystemBridge::WriteGuestMemorySnapshot(std::ostream& os, const std::filesystem::path& mem1Path) { + auto writeRegion = [&](const char* label, uint32_t base, uint32_t size, + const std::filesystem::path& path) { + std::ofstream dump(path, std::ios::binary | std::ios::trunc); + dump.write(reinterpret_cast(Memory::GetPointer(base, size)), size); + os << "[runtime] " << label << " snapshot written to " << RuntimeConfigFile::PathToUtf8(path) + << (dump.good() ? "" : " (write failed)") << std::endl; + }; + constexpr uint32_t kMem1Base = 0x80000000u; constexpr uint32_t kMem1Size = 0x01800000u; if (Memory::Contains(kMem1Base, kMem1Size)) { - std::ofstream dump(mem1Path, std::ios::binary | std::ios::trunc); - dump.write(reinterpret_cast(Memory::GetPointer(kMem1Base, kMem1Size)), - kMem1Size); - os << "[runtime] MEM1 snapshot written to " << RuntimeConfigFile::PathToUtf8(mem1Path) - << (dump.good() ? "" : " (write failed)") << std::endl; + writeRegion("MEM1", kMem1Base, kMem1Size, mem1Path); } constexpr uint32_t kMem2Base = 0x90000000u; for (uint32_t mem2Size : {0x08000000u, 0x04000000u}) { @@ -429,13 +433,16 @@ void SystemBridge::WriteGuestMemorySnapshot(std::ostream& os, const std::filesys } std::filesystem::path mem2Path = mem1Path; mem2Path += ".mem2"; - std::ofstream dump(mem2Path, std::ios::binary | std::ios::trunc); - dump.write(reinterpret_cast(Memory::GetPointer(kMem2Base, mem2Size)), - mem2Size); - os << "[runtime] MEM2 snapshot written to " << RuntimeConfigFile::PathToUtf8(mem2Path) - << (dump.good() ? "" : " (write failed)") << std::endl; + writeRegion("MEM2", kMem2Base, mem2Size, mem2Path); break; } + constexpr uint32_t kKamekBase = 0x81800000u; + constexpr uint32_t kKamekSize = 0x00200000u; + if (Memory::Contains(kKamekBase, kKamekSize)) { + std::filesystem::path kamekPath = mem1Path; + kamekPath += ".kamek"; + writeRegion("Kamek overlay", kKamekBase, kKamekSize, kamekPath); + } } void SystemBridge::DumpCrashHeuristics(std::ostream& os, const CpuContext* cpu,