Skip to content

Commit

Permalink
Fix segfault when DMAing past the end of cart ROM.
Browse files Browse the repository at this point in the history
When a game triggers a DMA from the cart ROM area to RDRAM, part or all of the
DMA'd area is not covered by the currently-loaded ROM, cen64 treats it as a
series of reads from open-bus. A bug in the code that handles this case was
causing segfaults.
Hat-tip to cen64 user Grim who provided a test rom that triggered this bug. His
test ROM was less than (1 MB + 4 KB) in size, which was causing the initial 1MB
DMA to trigger this bug.
  • Loading branch information
jkbenaim committed May 24, 2018
1 parent 6215202 commit 72c778c
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion pi/controller.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ static int pi_dma_write(struct pi_controller *pi) {
for (i = (pi->regs[PI_CART_ADDR_REG] + pi->rom_size + 3) & ~0x3;
i < pi->regs[PI_CART_ADDR_REG] + length; i += 4) {
uint32_t word = (i >> 16) | (i & 0xFFFF0000);
memcpy(pi->bus->ri->ram + dest + i, &word, sizeof(word));
memcpy(pi->bus->ri->ram + dest, &word, sizeof(word));
}

length = pi->rom_size - source;
Expand Down

0 comments on commit 72c778c

Please sign in to comment.