Trying to do MMIO protects on allocation granularity.

This commit is contained in:
Ben Vanik 2015-05-18 20:47:26 -07:00
parent 92f5fe3b88
commit 8bfc43bb0d
2 changed files with 18 additions and 10 deletions

View File

@ -12,6 +12,7 @@
#include "xenia/base/assert.h"
#include "xenia/base/byte_order.h"
#include "xenia/base/math.h"
#include "xenia/base/memory.h"
namespace BE {
#include <beaengine/BeaEngine.h>
@ -90,6 +91,12 @@ uintptr_t MMIOHandler::AddPhysicalWriteWatch(uint32_t guest_address,
uint32_t base_address = guest_address;
assert_true(base_address < 0x1FFFFFFF);
// Can only protect sizes matching system page size.
// This means we need to round up, which will cause spurious access
// violations and invalidations.
// TODO(benvanik): only invalidate if actually within the region?
length = xe::round_up(length, xe::page_size());
// Add to table. The slot reservation may evict a previous watch, which
// could include our target, so we do it first.
auto entry = new WriteWatchEntry();
@ -106,8 +113,6 @@ uintptr_t MMIOHandler::AddPhysicalWriteWatch(uint32_t guest_address,
DWORD old_protect;
VirtualProtect(physical_membase_ + entry->address, entry->length,
PAGE_READONLY, &old_protect);
VirtualProtect(virtual_membase_ + entry->address, entry->length,
PAGE_READONLY, &old_protect);
VirtualProtect(virtual_membase_ + 0xA0000000 + entry->address, entry->length,
PAGE_READONLY, &old_protect);
VirtualProtect(virtual_membase_ + 0xC0000000 + entry->address, entry->length,
@ -122,8 +127,6 @@ void MMIOHandler::ClearWriteWatch(WriteWatchEntry* entry) {
DWORD old_protect;
VirtualProtect(physical_membase_ + entry->address, entry->length,
PAGE_READWRITE, &old_protect);
VirtualProtect(virtual_membase_ + entry->address, entry->length,
PAGE_READWRITE, &old_protect);
VirtualProtect(virtual_membase_ + 0xA0000000 + entry->address, entry->length,
PAGE_READWRITE, &old_protect);
VirtualProtect(virtual_membase_ + 0xC0000000 + entry->address, entry->length,

View File

@ -804,13 +804,18 @@ bool BaseHeap::Release(uint32_t base_address, uint32_t* out_region_size) {
PLOGE("BaseHeap::Release failed due to host VirtualFree failure");
return false;
}*/
// Instead, we just protect it.
// Instead, we just protect it, if we can.
if (page_size_ == xe::page_size() ||
((base_page_entry.region_page_count * page_size_) % xe::page_size() ==
0) &&
((base_page_number * page_size_) % xe::page_size() == 0)) {
DWORD old_protect;
if (!VirtualProtect(membase_ + heap_base_ + base_page_number * page_size_,
base_page_entry.region_page_count * page_size_,
PAGE_NOACCESS, &old_protect)) {
XELOGW("BaseHeap::Release failed due to host VirtualProtect failure");
}
}
// Perform table change.
uint32_t end_page_number =