Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception handler - catch bad memory accesses by the JIT #11795

Merged
merged 17 commits into from
Jul 14, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 8 additions & 11 deletions Core/MemMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ bool HandleFault(uintptr_t hostAddress, void *ctx) {
const uint8_t *codePtr = (uint8_t *)(context->CTX_PC);

// TODO: Check that codePtr is within the current JIT space.
bool inJitSpace = MIPSComp::jit->CodeInRange(codePtr);
bool inJitSpace = MIPSComp::jit && MIPSComp::jit->CodeInRange(codePtr);
if (!inJitSpace) {
// This is a crash in non-jitted code. Not something we want to handle here, ignore.
return false;
Expand Down Expand Up @@ -533,19 +533,16 @@ bool HandleFault(uintptr_t hostAddress, void *ctx) {
// It was a read. Fill the destination register with 0.
// TODO
}
// Move on to the next instruction.
// Move on to the next instruction. Note that handling bad accesses like this is pretty slow.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could set a flag to rebuild jit with slow memory, either for this block or all blocks. Might be faster overall.

-[Unknown]

context->CTX_PC += info.instructionSize;
// Fall through to logging.
g_numReportedBadAccesses++;
if (g_numReportedBadAccesses < 100) {
ERROR_LOG(MEMMAP, "Bad memory access detected and ignored: %08x (%p)", guestAddress, (void *)hostAddress);
}
} else {
// Jump to a crash handler that will exit the game.
// Redirect execution to a crash handler that will exit the game.
context->CTX_PC = (uintptr_t)MIPSComp::jit->GetCrashHandler();
ERROR_LOG(SYSTEM, "Bad memory access detected! %08x (%p) Stopping emulation.", guestAddress, (void *)hostAddress);
return true;
}

g_numReportedBadAccesses++;
if (g_numReportedBadAccesses < 100) {
ERROR_LOG(SYSTEM, "Bad memory access detected and ignored: %08x (%p)", guestAddress, (void *)hostAddress);
ERROR_LOG(MEMMAP, "Bad memory access detected! %08x (%p) Stopping emulation.", guestAddress, (void *)hostAddress);
}
return true;
}
Expand Down