GBA Memory: Soft-crash if jumping past the end of a ROM

This commit is contained in:
Jeffrey Pfau 2015-05-08 00:34:01 -07:00
parent 924efefc38
commit 3c844a9ae9
2 changed files with 18 additions and 11 deletions

View File

@ -53,6 +53,7 @@ Misc:
- GBA: Add status log level - GBA: Add status log level
- GBA Thread: Add functionality for running callbacks on the GBA thread - GBA Thread: Add functionality for running callbacks on the GBA thread
- Qt: Fast forward (held) option moved from Other to Emulation menu - Qt: Fast forward (held) option moved from Other to Emulation menu
- GBA Memory: Soft-crash if jumping past the end of a ROM
0.2.0: (2015-04-03) 0.2.0: (2015-04-03)
Features: Features:

View File

@ -231,6 +231,12 @@ static void GBASetActiveRegion(struct ARMCore* cpu, uint32_t address) {
} }
gba->lastJump = address; 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) {
return; return;
} }
@ -239,29 +245,29 @@ static void GBASetActiveRegion(struct ARMCore* cpu, uint32_t address) {
memory->biosPrefetch = cpu->prefetch[1]; memory->biosPrefetch = cpu->prefetch[1];
} }
memory->activeRegion = newRegion; memory->activeRegion = newRegion;
switch (address & ~OFFSET_MASK) { switch (newRegion) {
case BASE_BIOS: case REGION_BIOS:
cpu->memory.activeRegion = memory->bios; cpu->memory.activeRegion = memory->bios;
cpu->memory.activeMask = SIZE_BIOS - 1; cpu->memory.activeMask = SIZE_BIOS - 1;
break; break;
case BASE_WORKING_RAM: case REGION_WORKING_RAM:
cpu->memory.activeRegion = memory->wram; cpu->memory.activeRegion = memory->wram;
cpu->memory.activeMask = SIZE_WORKING_RAM - 1; cpu->memory.activeMask = SIZE_WORKING_RAM - 1;
break; break;
case BASE_WORKING_IRAM: case REGION_WORKING_IRAM:
cpu->memory.activeRegion = memory->iwram; cpu->memory.activeRegion = memory->iwram;
cpu->memory.activeMask = SIZE_WORKING_IRAM - 1; cpu->memory.activeMask = SIZE_WORKING_IRAM - 1;
break; break;
case BASE_VRAM: case REGION_VRAM:
cpu->memory.activeRegion = (uint32_t*) gba->video.renderer->vram; cpu->memory.activeRegion = (uint32_t*) gba->video.renderer->vram;
cpu->memory.activeMask = 0x0000FFFF; cpu->memory.activeMask = 0x0000FFFF;
break; break;
case BASE_CART0: case REGION_CART0:
case BASE_CART0_EX: case REGION_CART0_EX:
case BASE_CART1: case REGION_CART1:
case BASE_CART1_EX: case REGION_CART1_EX:
case BASE_CART2: case REGION_CART2:
case BASE_CART2_EX: case REGION_CART2_EX:
cpu->memory.activeRegion = memory->rom; cpu->memory.activeRegion = memory->rom;
cpu->memory.activeMask = SIZE_CART0 - 1; cpu->memory.activeMask = SIZE_CART0 - 1;
break; break;