Fix a crash on invalid memory accesses

This commit is contained in:
Luke Usher 2018-09-15 16:19:50 +01:00
parent 1102133475
commit b8889b6857
1 changed files with 42 additions and 27 deletions

View File

@ -118,35 +118,46 @@ void EmuX86_IOWrite(xbaddr addr, uint32_t value, int size)
// //
uint32_t EmuX86_Mem_Read(xbaddr addr, int size) uint32_t EmuX86_Mem_Read(xbaddr addr, int size)
{ {
switch (size) { __try {
case sizeof(uint32_t) :
return *(uint32_t*)addr; switch (size) {
case sizeof(uint16_t) : case sizeof(uint32_t) :
return *(uint16_t*)addr; return *(uint32_t*)addr;
case sizeof(uint8_t) : case sizeof(uint16_t) :
return *(uint8_t*)addr; return *(uint16_t*)addr;
default: case sizeof(uint8_t) :
// UNREACHABLE(size); return *(uint8_t*)addr;
return 0; default:
// UNREACHABLE(size);
return 0;
}
}
__except (true) {
EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "EmuX86_Mem_Read Failed (0x%08X, %d)", addr, size);
} }
} }
void EmuX86_Mem_Write(xbaddr addr, uint32_t value, int size) void EmuX86_Mem_Write(xbaddr addr, uint32_t value, int size)
{ {
switch (size) { __try {
case sizeof(uint32_t) : switch (size) {
*(uint32_t*)addr = (uint32_t)value; case sizeof(uint32_t) :
break; *(uint32_t*)addr = (uint32_t)value;
case sizeof(uint16_t) : break;
*(uint16_t*)addr = (uint16_t)value; case sizeof(uint16_t) :
break; *(uint16_t*)addr = (uint16_t)value;
case sizeof(uint8_t) : break;
*(uint8_t*)addr = (uint8_t)value; case sizeof(uint8_t) :
break; *(uint8_t*)addr = (uint8_t)value;
default: break;
// UNREACHABLE(size); default:
return; // UNREACHABLE(size);
return;
}
}
__except (true) {
EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "EmuX86_Mem_Write Failed (0x%08X, 0x%08X, %d)", addr, value, size);
} }
} }
@ -1179,8 +1190,12 @@ bool EmuX86_DecodeException(LPEXCEPTION_POINTERS e)
continue; continue;
} }
break; break;
case I_RET: case I_CALL: case I_RET:
// RET always signifies the end of a code block // RET and CALL always signify the end of a code block
return true;
case I_PUSH: case I_POP:
// TODO: Implement these instructions
// currently stubbed to prevent firing the unimplemented instruction handler
return true; return true;
case I_ADD: case I_ADD:
if (EmuX86_Opcode_ADD(e, info)) break; if (EmuX86_Opcode_ADD(e, info)) break;