Skip to content

Commit 5eb505a

Browse files
committed
EmuX86: Let invalid memory accesses trigger a warning rather than a fatal error
This seems to resolve most regressions we have had in recent history.
1 parent eb2381e commit 5eb505a

1 file changed

Lines changed: 7 additions & 19 deletions

File tree

src/devices/x86/EmuX86.cpp

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@ extern std::atomic_bool g_bEnableAllInterrupts;
5757

5858
static int field_pin = 0;
5959

60-
static thread_local bool g_tls_isEmuX86Managed;
61-
6260
uint32_t EmuX86_IORead(xbox::addr_xt addr, int size)
6361
{
6462
switch (addr) {
@@ -197,11 +195,8 @@ uint32_t EmuX86_Read(xbox::addr_xt addr, int size)
197195
return value;
198196
}
199197

200-
// EmuX86 is not suppose to do direct read to host memory and should be handle from
201-
// redirect from above statements. If it doesn't meet any requirement, then should be
202-
// handle as possible fatal crash instead of return corrupt value.
203-
g_tls_isEmuX86Managed = false;
204-
198+
// EmuX86 should not directly access host memory.
199+
EmuLog(LOG_LEVEL::WARNING, "EmuX86_Read(0x%08X, %d) [Unhandled]", addr, size);
205200
return 0;
206201
}
207202

@@ -223,10 +218,8 @@ void EmuX86_Write(xbox::addr_xt addr, uint32_t value, int size)
223218
return;
224219
}
225220

226-
// EmuX86 is not suppose to do direct write to host memory and should be handle from
227-
// redirect from above statements. If it doesn't meet any requirement, then should be
228-
// handle as possible fatal crash instead of set corrupt value.
229-
g_tls_isEmuX86Managed = false;
221+
// EmuX86 should not directly access host memory.
222+
EmuLog(LOG_LEVEL::WARNING, "EmuX86_Write(0x%08X, 0x%08X, %d) [Unhandled]", addr, value, size);
230223
}
231224

232225
int ContextRecordOffsetByRegisterType[/*_RegisterType*/R_DR7 + 1] = { 0 };
@@ -2928,7 +2921,6 @@ bool EmuX86_DecodeException(LPEXCEPTION_POINTERS e)
29282921
// However, if for any reason, an opcode operand cannot be read from or written to,
29292922
// that case may be logged, but it shouldn't fail the opcode handler.
29302923
_DInst info;
2931-
g_tls_isEmuX86Managed = true;
29322924
DWORD StartingEip = e->ContextRecord->Eip;
29332925
EmuLog(LOG_LEVEL::DEBUG, "Starting instruction emulation from 0x%08X", e->ContextRecord->Eip);
29342926

@@ -3294,15 +3286,11 @@ bool EmuX86_DecodeException(LPEXCEPTION_POINTERS e)
32943286
return true;
32953287
} // switch info.opcode
32963288

3297-
if (g_tls_isEmuX86Managed) {
3298-
e->ContextRecord->Eip += info.size;
3299-
}
3300-
else {
3301-
break;
3302-
}
3289+
3290+
e->ContextRecord->Eip += info.size;
33033291
} // while true
33043292

3305-
return g_tls_isEmuX86Managed;
3293+
return true;
33063294

33073295
opcode_error:
33083296
EmuLog(LOG_LEVEL::WARNING, "0x%08X: Error while handling instruction %s (%u)", e->ContextRecord->Eip, Distorm_OpcodeString(info.opcode), info.opcode);

0 commit comments

Comments
 (0)