all repos — mgba @ 37f5058de01345a6f0efbf5cb72c8d0c3643f12d

mGBA Game Boy Advance Emulator

GBA Memory: Fix jumping to invalid memory when switching from Thumb to ARM
Jeffrey Pfau jeffrey@endrift.com
Sat, 09 May 2015 17:07:26 -0700
commit

37f5058de01345a6f0efbf5cb72c8d0c3643f12d

parent

cb3f029d9e0d228fba883a10e100c38a0c5d924d

2 files changed, 7 insertions(+), 8 deletions(-)

jump to
M CHANGESCHANGES

@@ -52,6 +52,7 @@ - ARM7: Make illegal instruction decoding consistent between ARM and Thumb

- GBA BIOS: Initialize a variable that may be uninitialized in very rare cases - ARM7: Fix ARM multiply instructions when PC is a destination register - SDL: Fix potential build issues when Qt and SDL2 are in use + - GBA Memory: Fix jumping to invalid memory when switching from Thumb to ARM Misc: - Qt: Show multiplayer numbers in window title - Qt: Handle saving input settings better
M src/gba/memory.csrc/gba/memory.c

@@ -231,13 +231,7 @@ }

} gba->lastJump = address; - if (newRegion >= REGION_CART0 && (address & (SIZE_CART0 - 1)) >= memory->romSize) { - cpu->memory.activeRegion = _deadbeef; - cpu->memory.activeMask = 0; - GBALog(gba, GBA_LOG_FATAL, "Jumped past end of ROM"); - return; - } - if (newRegion == memory->activeRegion) { + if (newRegion == memory->activeRegion && (newRegion < REGION_CART0 || (address & (SIZE_CART0 - 1)) < memory->romSize)) { return; }

@@ -270,8 +264,12 @@ case REGION_CART2:

case REGION_CART2_EX: cpu->memory.activeRegion = memory->rom; cpu->memory.activeMask = SIZE_CART0 - 1; - break; + if ((address & (SIZE_CART0 - 1)) < memory->romSize) { + break; + } + // Fall through default: + memory->activeRegion = 0; cpu->memory.activeRegion = _deadbeef; cpu->memory.activeMask = 0; GBALog(gba, GBA_LOG_FATAL, "Jumped to invalid address");