From 9eb2ec8fa2df14f4c04f68bcd2c598aa4a7961e5 Mon Sep 17 00:00:00 2001 From: Mow <32942550+taxicat1@users.noreply.github.com> Date: Thu, 29 Jan 2026 05:20:19 -0500 Subject: [PATCH] Ignore ROM reads into null pointer destinations (#122) Fixes #121 DMA ROM reads ignore null pointer destinations, but if they are coerced to CPU reads they will data abort. With this commit, if the destination address is under 0x01000000 it will be considered invalid. --- arm9/source/patches/arm9/sdk2to4/CardiReadCardPatchAsm.s | 5 +++++ arm9/source/patches/arm9/sdk5/CardiReadRomWithCpuPatchAsm.s | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/arm9/source/patches/arm9/sdk2to4/CardiReadCardPatchAsm.s b/arm9/source/patches/arm9/sdk2to4/CardiReadCardPatchAsm.s index 7e3a04e..bec22d4 100644 --- a/arm9/source/patches/arm9/sdk2to4/CardiReadCardPatchAsm.s +++ b/arm9/source/patches/arm9/sdk2to4/CardiReadCardPatchAsm.s @@ -57,8 +57,13 @@ patch_cardireadcard_mov_r3_to_dst: str r3, [r6, #0x24] do_read: + lsrs r3, r1, #24 // if dst address is invalid (close to zero), ignore the read + beq ignore_read // this is intended to fix reads to null pointers that would be ignored if done with DMA + ldr r3, __patch_cardireadcard_sdread_asm_address blx r3 + +ignore_read: pop {r1,r2,r3,r4,r6,pc} .balign 4 diff --git a/arm9/source/patches/arm9/sdk5/CardiReadRomWithCpuPatchAsm.s b/arm9/source/patches/arm9/sdk5/CardiReadRomWithCpuPatchAsm.s index ea00ca6..6aa60a0 100644 --- a/arm9/source/patches/arm9/sdk5/CardiReadRomWithCpuPatchAsm.s +++ b/arm9/source/patches/arm9/sdk5/CardiReadRomWithCpuPatchAsm.s @@ -43,6 +43,9 @@ patch_cardireadromwithcpu_mov_left_to_read_to_r2: lsls r7, r2, #9 do_read: + lsrs r3, r1, #24 // if dst address is invalid (close to zero), ignore the read + beq ignore_read // this is intended to fix reads to null pointers that would be ignored if done with DMA + ldr r3, __patch_cardireadromwithcpu_sdread_asm_address blx r3 // arm @@ -53,6 +56,8 @@ do_read: // r7 = number of bytes read // r5 = number of bytes left to read // [sp + 0 + 4] = actual dst + +ignore_read: pop {pc} .balign 4