Quick-kill the MMIO handler if the fault address is above the mapping range.

This commit is contained in:
Dr. Chat 2015-09-07 21:23:24 -05:00
parent 3ac83b16c8
commit a2bc0443f2
3 changed files with 11 additions and 6 deletions

View File

@ -25,7 +25,8 @@ std::unique_ptr<MMIOHandler> CreateMMIOHandler(uint8_t* virtual_membase,
uint8_t* physical_membase); uint8_t* physical_membase);
std::unique_ptr<MMIOHandler> MMIOHandler::Install(uint8_t* virtual_membase, std::unique_ptr<MMIOHandler> 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. // There can be only one handler at a time.
assert_null(global_handler_); assert_null(global_handler_);
if (global_handler_) { if (global_handler_) {
@ -40,6 +41,7 @@ std::unique_ptr<MMIOHandler> MMIOHandler::Install(uint8_t* virtual_membase,
return nullptr; return nullptr;
} }
handler->memory_end_ = memory_end;
global_handler_ = handler.get(); global_handler_ = handler.get();
return handler; return handler;
} }
@ -364,8 +366,9 @@ bool TryDecodeMov(const uint8_t* p, DecodedMov* mov) {
bool MMIOHandler::HandleAccessFault(void* thread_state, bool MMIOHandler::HandleAccessFault(void* thread_state,
uint64_t fault_address) { uint64_t fault_address) {
if (fault_address < uint64_t(virtual_membase_)) { if (fault_address < uint64_t(virtual_membase_) ||
// Quick kill anything below our mapping base. fault_address > uint64_t(memory_end_)) {
// Quick kill anything outside our mapping.
return false; return false;
} }

View File

@ -42,7 +42,8 @@ class MMIOHandler {
virtual ~MMIOHandler(); virtual ~MMIOHandler();
static std::unique_ptr<MMIOHandler> Install(uint8_t* virtual_membase, static std::unique_ptr<MMIOHandler> Install(uint8_t* virtual_membase,
uint8_t* physical_membase); uint8_t* physical_membase,
uint8_t* membase_end);
static MMIOHandler* global_handler() { return global_handler_; } static MMIOHandler* global_handler() { return global_handler_; }
bool RegisterRange(uint32_t virtual_address, uint32_t mask, uint32_t size, bool RegisterRange(uint32_t virtual_address, uint32_t mask, uint32_t size,
@ -86,6 +87,7 @@ class MMIOHandler {
uint8_t* virtual_membase_; uint8_t* virtual_membase_;
uint8_t* physical_membase_; uint8_t* physical_membase_;
uint8_t* memory_end_;
std::vector<MMIORange> mapped_ranges_; std::vector<MMIORange> mapped_ranges_;

View File

@ -184,8 +184,8 @@ int Memory::Initialize() {
kMemoryProtectRead | kMemoryProtectWrite); kMemoryProtectRead | kMemoryProtectWrite);
// Add handlers for MMIO. // Add handlers for MMIO.
mmio_handler_ = mmio_handler_ = cpu::MMIOHandler::Install(virtual_membase_, physical_membase_,
cpu::MMIOHandler::Install(virtual_membase_, physical_membase_); physical_membase_ + 0x1FFFFFFF);
if (!mmio_handler_) { if (!mmio_handler_) {
XELOGE("Unable to install MMIO handlers"); XELOGE("Unable to install MMIO handlers");
assert_always(); assert_always();