JitArm64_BackPatch: Correct usage of an invalidated iterator after a std::map erase() call in HandleFastmemFault()

Given the iterator gets invalidated within the erase() call, just keep a
temporary around to store the pointer address.
This commit is contained in:
Lioncash 2018-05-30 10:39:24 -04:00
parent 4fb2d580d8
commit bffcaf3218
1 changed files with 8 additions and 4 deletions

View File

@ -3,6 +3,7 @@
// Refer to the license.txt file included.
#include <cinttypes>
#include <cstddef>
#include <string>
#include "Common/BitSet.h"
@ -306,21 +307,24 @@ bool JitArm64::HandleFastmemFault(uintptr_t access_address, SContext* ctx)
if (slow_handler_iter == m_fault_to_handler.end())
return false;
const u8* fault_location = slow_handler_iter->first;
const u32 fastmem_area_length = slow_handler_iter->second.length;
// no overlapping fastmem area found
if ((const u8*)ctx->CTX_PC - slow_handler_iter->first > slow_handler_iter->second.length)
if ((const u8*)ctx->CTX_PC - fault_location > fastmem_area_length)
return false;
ARM64XEmitter emitter((u8*)slow_handler_iter->first);
ARM64XEmitter emitter((u8*)fault_location);
emitter.BL(slow_handler_iter->second.slowmem_code);
u32 num_insts_max = slow_handler_iter->second.length / 4 - 1;
const u32 num_insts_max = fastmem_area_length / 4 - 1;
for (u32 i = 0; i < num_insts_max; ++i)
emitter.HINT(HINT_NOP);
m_fault_to_handler.erase(slow_handler_iter);
emitter.FlushIcache();
ctx->CTX_PC = (u64)slow_handler_iter->first;
ctx->CTX_PC = reinterpret_cast<std::uintptr_t>(fault_location);
return true;
}