Interpreter: don't spin forever on a memory access that's set to be ignored

The alignment checks added in d8edeb7649 return out of the instruction handler
without advancing PC, so with IgnoreBadMemAccess - which is the default, and
which makes Core_MemoryException log and return - the run loop comes straight
back to the same instruction and never gets past it. cpu/crash/crash_read_u32
under -i logged the same SIGSEGV 585096 times in 30 seconds before being killed;
the JIT runs it to completion.

Continue instead, the way Memory::Read_U32 did before those checks existed and
the way the JIT's safe-memory path still does: loads produce zero, stores are
dropped, PC advances. When the exception is set to break rather than ignore,
Core_Break has already stopped the core by the time we get here, so nothing
changes for that case.

lv.q/sv.q are left alone - they already fall through and do the access.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SfY7iFJEjmRXf1XGrTs4MF
This commit is contained in:
Henrik RydgårdandClaude Opus 5 committed 2026-08-27 16:43:43 +02:00
1 parent 3fa67f22ed
commit 484898385f
2 files changed
+32 -24

No files matched your search

+25 -18
View File
@@ -420,9 +420,10 @@ namespace MIPSInt {
if (rt != 0) {
if (!Memory::IsValid4AlignedAddress(addr)) {
Core_MemoryException(addr, 4, PC, MemoryExceptionType::READ_WORD, "ll");
return;
R(rt) = 0;
} else {
R(rt) = Memory::ReadUnchecked_U32(addr);
}
R(rt) = Memory::ReadUnchecked_U32(addr);
}
mips->llBit = 1;
break;
@@ -430,9 +431,9 @@ namespace MIPSInt {
if (mips->llBit) {
if (!Memory::IsValid4AlignedAddress(addr)) {
Core_MemoryException(addr, 4, PC, MemoryExceptionType::WRITE_WORD, "sc");
return;
} else {
Memory::WriteUnchecked_U32(R(rt), addr);
}
Memory::WriteUnchecked_U32(R(rt), addr);
if (rt != 0) {
R(rt) = 1;
}
@@ -501,7 +502,8 @@ namespace MIPSInt {
break;
}
Core_MemoryException(addr, 1, PC, MemoryExceptionType::READ_WORD, "lb");
return;
R(rt) = 0;
break;
}
R(rt) = SignExtend8ToU32(Memory::ReadUnchecked_U8(addr));
break; //lb
@@ -513,7 +515,8 @@ namespace MIPSInt {
break;
}
Core_MemoryException(addr, 2, PC, MemoryExceptionType::READ_WORD, "lh");
return;
R(rt) = 0;
break;
}
R(rt) = SignExtend16ToU32(Memory::ReadUnchecked_U16(addr));
break; //lh
@@ -525,7 +528,8 @@ namespace MIPSInt {
break;
}
Core_MemoryException(addr, 4, PC, MemoryExceptionType::READ_WORD, "lw");
return;
R(rt) = 0;
break;
}
R(rt) = Memory::ReadUnchecked_U32(addr);
break; //lw
@@ -537,7 +541,8 @@ namespace MIPSInt {
break;
}
Core_MemoryException(addr, 1, PC, MemoryExceptionType::READ_WORD, "lbu");
return;
R(rt) = 0;
break;
}
R(rt) = Memory::ReadUnchecked_U8(addr);
break; //lbu
@@ -549,7 +554,8 @@ namespace MIPSInt {
break;
}
Core_MemoryException(addr, 2, PC, MemoryExceptionType::READ_WORD, "lhu");
return;
R(rt) = 0;
break;
}
R(rt) = Memory::ReadUnchecked_U16(addr);
break; //lhu
@@ -561,7 +567,7 @@ namespace MIPSInt {
break;
}
Core_MemoryException(addr, 1, PC, MemoryExceptionType::WRITE_WORD, "sb");
return;
break;
}
Memory::WriteUnchecked_U8(R(rt), addr);
break; //sb
@@ -573,7 +579,7 @@ namespace MIPSInt {
break;
}
Core_MemoryException(addr, 2, PC, MemoryExceptionType::WRITE_WORD, "sh");
return;
break;
}
Memory::WriteUnchecked_U16(R(rt), addr);
break; //sh
@@ -585,7 +591,7 @@ namespace MIPSInt {
break;
}
Core_MemoryException(addr, 4, PC, MemoryExceptionType::WRITE_WORD, "sw");
return;
break;
}
Memory::WriteUnchecked_U32(R(rt), addr);
break; //sw
@@ -597,7 +603,7 @@ namespace MIPSInt {
// Not checking for alignment here - the actual read will be aligned.
if (!Memory::IsValidAddress(addr)) {
Core_MemoryException(addr, 4, PC, MemoryExceptionType::READ_WORD, "lwl");
return;
break;
}
u32 shift = (addr & 3) * 8;
u32 mem = Memory::ReadUnchecked_U32(addr & 0xfffffffc);
@@ -611,7 +617,7 @@ namespace MIPSInt {
// Not checking for alignment here - the actual read will be aligned.
if (!Memory::IsValidAddress(addr)) {
Core_MemoryException(addr, 4, PC, MemoryExceptionType::READ_WORD, "lwr");
return;
break;
}
u32 shift = (addr & 3) * 8;
u32 mem = Memory::ReadUnchecked_U32(addr & 0xfffffffc);
@@ -626,7 +632,7 @@ namespace MIPSInt {
// Not checking for alignment here - the actual read/write will be aligned.
if (!Memory::IsValidAddress(addr)) {
Core_MemoryException(addr, 4, PC, MemoryExceptionType::WRITE_WORD, "swl");
return;
break;
}
u32 shift = (addr & 3) * 8;
u32 mem = Memory::ReadUnchecked_U32(addr & 0xfffffffc);
@@ -640,7 +646,7 @@ namespace MIPSInt {
// Not checking for alignment here - the actual read/write will be aligned.
if (!Memory::IsValidAddress(addr)) {
Core_MemoryException(addr, 4, PC, MemoryExceptionType::WRITE_WORD, "swr");
return;
break;
}
u32 shift = (addr & 3) << 3;
u32 mem = Memory::ReadUnchecked_U32(addr & 0xfffffffc);
@@ -666,14 +672,15 @@ namespace MIPSInt {
case 49:
if (!Memory::IsValid4AlignedAddress(addr)) {
Core_MemoryException(addr, 4, PC, MemoryExceptionType::READ_WORD, "lwc1");
return;
FI(ft) = 0;
break;
}
FI(ft) = Memory::ReadUnchecked_U32(addr);
break; //lwc1
case 57:
if (!Memory::IsValid4AlignedAddress(addr)) {
Core_MemoryException(addr, 4, PC, MemoryExceptionType::WRITE_WORD, "swc1");
return;
break;
}
Memory::WriteUnchecked_U32(FI(ft), addr);
break; //swc1
+7 -6
View File
@@ -219,7 +219,7 @@ namespace MIPSInt
if ((op & 2) == 0) {
if (!Memory::IsValid4AlignedAddress(addr)) {
Core_MemoryException(addr, 16, PC, MemoryExceptionType::READ_WORD, "lvl.q");
return;
break;
}
// It's an LVL
for (int i = 0; i < offset + 1; i++) {
@@ -228,7 +228,7 @@ namespace MIPSInt
} else {
if (!Memory::IsValid4AlignedAddress(addr)) {
Core_MemoryException(addr, 16, PC, MemoryExceptionType::READ_WORD, "lvr.q");
return;
break;
}
// It's an LVR
for (int i = 0; i < (3 - offset) + 1; i++) {
@@ -268,7 +268,7 @@ namespace MIPSInt
if ((op & 2) == 0) {
if (!Memory::IsValid4AlignedAddress(addr)) {
Core_MemoryException(addr, 16, PC, MemoryExceptionType::WRITE_WORD, "svl.q");
return;
break;
}
// It's an SVL
for (int i = 0; i < offset + 1; i++)
@@ -278,7 +278,7 @@ namespace MIPSInt
} else {
if (!Memory::IsValid4AlignedAddress(addr)) {
Core_MemoryException(addr, 16, PC, MemoryExceptionType::WRITE_WORD, "svr.q");
return;
break;
}
// It's an SVR
for (int i = 0; i < (3 - offset) + 1; i++) {
@@ -1757,14 +1757,15 @@ namespace MIPSInt
case 50: //lv.s
if (!Memory::IsValid4AlignedAddress(addr)) {
Core_MemoryException(addr, 4, PC, MemoryExceptionType::READ_WORD, "lv.s");
return;
VI(vt) = 0;
break;
}
VI(vt) = Memory::ReadUnchecked_U32(addr);
break;
case 58: //sv.s
if (!Memory::IsValid4AlignedAddress(addr)) {
Core_MemoryException(addr, 4, PC, MemoryExceptionType::WRITE_WORD, "sv.s");
return;
break;
}
Memory::WriteUnchecked_U32(VI(vt), addr);
break;