From 2be4d995f25e631461b41cd4f02ae233c1175a11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Mon, 10 Aug 2026 11:23:23 +0200 Subject: [PATCH] More Read_U32 cleanup --- GPU/Debugger/Record.cpp | 7 ++++++- GPU/GPUCommon.cpp | 7 ++++++- UI/ImDebugger/ImDisasmView.cpp | 16 ++++++++-------- UI/ImDebugger/ImStructViewer.cpp | 4 ++++ 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/GPU/Debugger/Record.cpp b/GPU/Debugger/Record.cpp index ba85a5c2da..9d92296a28 100644 --- a/GPU/Debugger/Record.cpp +++ b/GPU/Debugger/Record.cpp @@ -628,8 +628,13 @@ void Recorder::NotifyCommand(u32 pc) { return; } + if (!Memory::IsValid4AlignedAddress(pc)) { + ERROR_LOG(Log::G3D, "Bad pc in Recorder: %08x", pc); + return; + } + CheckEdramTrans(); - const u32 op = Memory::Read_U32(pc); + const u32 op = Memory::ReadUnchecked_U32(pc); const GECommand cmd = GECommand(op >> 24); switch (cmd) { diff --git a/GPU/GPUCommon.cpp b/GPU/GPUCommon.cpp index f4e4f0992c..43b6819292 100644 --- a/GPU/GPUCommon.cpp +++ b/GPU/GPUCommon.cpp @@ -1576,7 +1576,12 @@ int GPUCommon::GetCurrentPrim(GEPrimitiveType *prim, GECommand *outCmd) const { DisplayList list; u32 cmdWord; if (GetCurrentDisplayList(list)) { - cmdWord = Memory::Read_U32(list.pc); + if (Memory::IsValid4AlignedAddress(list.pc)) { + cmdWord = Memory::ReadUnchecked_U32(list.pc); + } else { + // We are screwed. + return 0; + } } else { // Current prim value. cmdWord = gstate.cmdmem[GE_CMD_PRIM]; diff --git a/UI/ImDebugger/ImDisasmView.cpp b/UI/ImDebugger/ImDisasmView.cpp index a72461953a..b2384761eb 100644 --- a/UI/ImDebugger/ImDisasmView.cpp +++ b/UI/ImDebugger/ImDisasmView.cpp @@ -896,21 +896,21 @@ void ImDisasmView::updateStatusBarText() { } if (line.info.isDataAccess) { - if (!Memory::IsValidAddress(line.info.dataAddress)) { - snprintf(text, sizeof(text), "Invalid address %08X", line.info.dataAddress); + if (!Memory::IsValidRange(line.info.dataAddress, line.info.dataSize)) { + snprintf(text, sizeof(text), "Invalid address range %08X (size %d)", line.info.dataAddress, line.info.dataSize); } else { bool isFloat = MIPSGetInfo(line.info.encodedOpcode) & (IS_FPU | IS_VFPU); switch (line.info.dataSize) { case 1: - snprintf(text, sizeof(text), "[%08X] = %02X", line.info.dataAddress, Memory::Read_U8(line.info.dataAddress)); + snprintf(text, sizeof(text), "[%08X] = %02X", line.info.dataAddress, Memory::ReadUnchecked_U8(line.info.dataAddress)); break; case 2: - snprintf(text, sizeof(text), "[%08X] = %04X", line.info.dataAddress, Memory::Read_U16(line.info.dataAddress)); + snprintf(text, sizeof(text), "[%08X] = %04X", line.info.dataAddress, Memory::ReadUnchecked_U16(line.info.dataAddress)); break; case 4: { - u32 dataInt = Memory::Read_U32(line.info.dataAddress); - u32 dataFloat = Memory::Read_Float(line.info.dataAddress); + u32 dataInt = Memory::ReadUnchecked_U32(line.info.dataAddress); + u32 dataFloat = Memory::ReadUnchecked_Float(line.info.dataAddress); std::string dataString; if (isFloat) dataString = StringFromFormat("%08X / %f", dataInt, dataFloat); @@ -930,8 +930,8 @@ void ImDisasmView::updateStatusBarText() { uint32_t dataInt[4]; float dataFloat[4]; for (int i = 0; i < 4; ++i) { - dataInt[i] = Memory::Read_U32(line.info.dataAddress + i * 4); - dataFloat[i] = Memory::Read_Float(line.info.dataAddress + i * 4); + dataInt[i] = Memory::ReadUnchecked_U32(line.info.dataAddress + i * 4); + dataFloat[i] = Memory::ReadUnchecked_Float(line.info.dataAddress + i * 4); } std::string dataIntString = StringFromFormat("%08X,%08X,%08X,%08X", dataInt[0], dataInt[1], dataInt[2], dataInt[3]); std::string dataFloatString = StringFromFormat("%f,%f,%f,%f", dataFloat[0], dataFloat[1], dataFloat[2], dataFloat[3]); diff --git a/UI/ImDebugger/ImStructViewer.cpp b/UI/ImDebugger/ImStructViewer.cpp index 9cb88e92fb..e45d1a1085 100644 --- a/UI/ImDebugger/ImStructViewer.cpp +++ b/UI/ImDebugger/ImStructViewer.cpp @@ -635,6 +635,10 @@ void ImStructViewer::DrawType( } const u32 address = base + offset; + if (!Memory::IsValidAddress(address)) { + // Bad! + return; + } ImGui::PushID(static_cast(address)); ImGui::PushID(watchId); // We push watch id too as it's possible to have multiple watches on the same address