From 878d2aeb0e8b5d3d2bb58cf9bcfbce414eb3e9e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Mon, 27 Jul 2026 23:28:23 +0200 Subject: [PATCH] Fix a bunch of possible crashes due to our VRAM check thinking that VRAM in kernel space is valid (but nothing is mapped there, unless you use masked memory) --- Core/MemMap.h | 6 ++++-- Core/MemMapFunctions.cpp | 8 ++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/Core/MemMap.h b/Core/MemMap.h index 6e9fa3b51b..1a058490f7 100644 --- a/Core/MemMap.h +++ b/Core/MemMap.h @@ -262,11 +262,13 @@ const T* GetTypedPointerRange(const u32 address, const u32 size) { } bool IsRAMAddress(const u32 address); + +// Note that VRAM is not mirrored up into kernel space. So we use BF800000 instead of 3F800000 to check for VRAM addresses. inline bool IsVRAMAddress(const u32 address) { - return ((address & 0x3F800000) == 0x04000000); + return ((address & 0xBF800000) == 0x04000000); } inline bool IsDepthTexVRAMAddress(const u32 address) { - return ((address & 0x3FE00000) == 0x04200000) || ((address & 0x3FE00000) == 0x04600000); + return ((address & 0xBFE00000) == 0x04200000) || ((address & 0xBFE00000) == 0x04600000); } // 0x08000000 -> 0x08800000 diff --git a/Core/MemMapFunctions.cpp b/Core/MemMapFunctions.cpp index 6f39b1b006..f8a57f3f70 100644 --- a/Core/MemMapFunctions.cpp +++ b/Core/MemMapFunctions.cpp @@ -29,7 +29,7 @@ namespace Memory { u8 *GetPointerWrite(const u32 address) { if ((address & 0x3E000000) == 0x08000000 || // RAM - (address & 0x3F800000) == 0x04000000 || // VRAM + (address & 0xBF800000) == 0x04000000 || // VRAM (address & 0xBFFFC000) == 0x00010000 || // Scratchpad ((address & 0x3F000000) >= 0x08000000 && (address & 0x3F000000) < 0x08000000 + g_MemorySize)) { // More RAM (remasters, etc.) return GetPointerWriteUnchecked(address); @@ -42,7 +42,7 @@ u8 *GetPointerWrite(const u32 address) { const u8 *GetPointer(const u32 address) { if ((address & 0x3E000000) == 0x08000000 || // RAM - (address & 0x3F800000) == 0x04000000 || // VRAM + (address & 0xBF800000) == 0x04000000 || // VRAM (address & 0xBFFFC000) == 0x00010000 || // Scratchpad ((address & 0x3F000000) >= 0x08000000 && (address & 0x3F000000) < 0x08000000 + g_MemorySize)) { // More RAM (remasters, etc.) return GetPointerUnchecked(address); @@ -88,7 +88,7 @@ const u8 *GetPointerRange(const u32 address, const u32 size) { template inline void ReadFromHardware(T &var, const u32 address) { if ((address & 0x3E000000) == 0x08000000 || // RAM - (address & 0x3F800000) == 0x04000000 || // VRAM + (address & 0xBF800000) == 0x04000000 || // VRAM (address & 0xBFFFC000) == 0x00010000 || // Scratchpad ((address & 0x3F000000) >= 0x08000000 && (address & 0x3F000000) < 0x08000000 + g_MemorySize)) { // More RAM (remasters, etc.) var = *((const T*)GetPointerUnchecked(address)); @@ -101,7 +101,7 @@ inline void ReadFromHardware(T &var, const u32 address) { template inline void WriteToHardware(u32 address, const T data) { if ((address & 0x3E000000) == 0x08000000 || // RAM - (address & 0x3F800000) == 0x04000000 || // VRAM + (address & 0xBF800000) == 0x04000000 || // VRAM (address & 0xBFFFC000) == 0x00010000 || // Scratchpad ((address & 0x3F000000) >= 0x08000000 && (address & 0x3F000000) < 0x08000000 + g_MemorySize)) { // More RAM (remasters, etc.) *(T*)GetPointerUnchecked(address) = data;