From a2bc0443f2beb113c95cee2b09577a87cf3a022c Mon Sep 17 00:00:00 2001 From: "Dr. Chat" Date: Mon, 7 Sep 2015 21:23:24 -0500 Subject: [PATCH] Quick-kill the MMIO handler if the fault address is above the mapping range. --- src/xenia/cpu/mmio_handler.cc | 9 ++++++--- src/xenia/cpu/mmio_handler.h | 4 +++- src/xenia/memory.cc | 4 ++-- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/xenia/cpu/mmio_handler.cc b/src/xenia/cpu/mmio_handler.cc index 5b704cf4d..0074eb595 100644 --- a/src/xenia/cpu/mmio_handler.cc +++ b/src/xenia/cpu/mmio_handler.cc @@ -25,7 +25,8 @@ std::unique_ptr CreateMMIOHandler(uint8_t* virtual_membase, uint8_t* physical_membase); std::unique_ptr MMIOHandler::Install(uint8_t* virtual_membase, - uint8_t* physical_membase) { + uint8_t* physical_membase, + uint8_t* memory_end) { // There can be only one handler at a time. assert_null(global_handler_); if (global_handler_) { @@ -40,6 +41,7 @@ std::unique_ptr MMIOHandler::Install(uint8_t* virtual_membase, return nullptr; } + handler->memory_end_ = memory_end; global_handler_ = handler.get(); return handler; } @@ -364,8 +366,9 @@ bool TryDecodeMov(const uint8_t* p, DecodedMov* mov) { bool MMIOHandler::HandleAccessFault(void* thread_state, uint64_t fault_address) { - if (fault_address < uint64_t(virtual_membase_)) { - // Quick kill anything below our mapping base. + if (fault_address < uint64_t(virtual_membase_) || + fault_address > uint64_t(memory_end_)) { + // Quick kill anything outside our mapping. return false; } diff --git a/src/xenia/cpu/mmio_handler.h b/src/xenia/cpu/mmio_handler.h index c8517fbb0..2d5b3fdde 100644 --- a/src/xenia/cpu/mmio_handler.h +++ b/src/xenia/cpu/mmio_handler.h @@ -42,7 +42,8 @@ class MMIOHandler { virtual ~MMIOHandler(); static std::unique_ptr Install(uint8_t* virtual_membase, - uint8_t* physical_membase); + uint8_t* physical_membase, + uint8_t* membase_end); static MMIOHandler* global_handler() { return global_handler_; } bool RegisterRange(uint32_t virtual_address, uint32_t mask, uint32_t size, @@ -86,6 +87,7 @@ class MMIOHandler { uint8_t* virtual_membase_; uint8_t* physical_membase_; + uint8_t* memory_end_; std::vector mapped_ranges_; diff --git a/src/xenia/memory.cc b/src/xenia/memory.cc index 7904a61ca..7485ece77 100644 --- a/src/xenia/memory.cc +++ b/src/xenia/memory.cc @@ -184,8 +184,8 @@ int Memory::Initialize() { kMemoryProtectRead | kMemoryProtectWrite); // Add handlers for MMIO. - mmio_handler_ = - cpu::MMIOHandler::Install(virtual_membase_, physical_membase_); + mmio_handler_ = cpu::MMIOHandler::Install(virtual_membase_, physical_membase_, + physical_membase_ + 0x1FFFFFFF); if (!mmio_handler_) { XELOGE("Unable to install MMIO handlers"); assert_always();