memory: Write no access pages to the savefile.

This commit is contained in:
Dr. Chat 2015-12-06 18:02:59 -06:00 committed by Ben Vanik
parent 20fb20d7f6
commit 5ef21d3714
1 changed files with 26 additions and 25 deletions

View File

@ -560,10 +560,16 @@ bool BaseHeap::Save(ByteStream* stream) {
} }
// TODO: Write compressed // TODO: Write compressed
if (page.state & kMemoryAllocationCommit && if (page.state & kMemoryAllocationCommit) {
page.current_protect & kMemoryProtectRead) { void* addr = membase_ + heap_base_ + i * page_size_;
stream->Write((void*)(membase_ + heap_base_ + i * page_size_),
page_size_); memory::PageAccess old_access;
memory::Protect(addr, page_size_, memory::PageAccess::kReadWrite,
&old_access);
stream->Write(addr, page_size_);
memory::Protect(addr, page_size_, old_access, nullptr);
} }
} }
@ -579,37 +585,32 @@ bool BaseHeap::Restore(ByteStream* stream) {
continue; continue;
} }
memory::AllocationType alloc_type;
memory::PageAccess page_access = memory::PageAccess::kNoAccess; memory::PageAccess page_access = memory::PageAccess::kNoAccess;
if ((page.state & (kMemoryAllocationReserve | kMemoryAllocationCommit)) == if (page.current_protect == (kMemoryProtectRead | kMemoryProtectWrite)) {
3) {
alloc_type = memory::AllocationType::kReserveCommit;
} else if (page.state & kMemoryAllocationCommit) {
alloc_type = memory::AllocationType::kCommit;
} else if (page.state & kMemoryAllocationReserve) {
alloc_type = memory::AllocationType::kReserve;
}
if ((page.current_protect & (kMemoryProtectRead | kMemoryProtectWrite)) ==
3) {
page_access = memory::PageAccess::kReadWrite; page_access = memory::PageAccess::kReadWrite;
} else if (page.current_protect & kMemoryProtectRead) { } else if (page.current_protect & kMemoryProtectRead) {
page_access = memory::PageAccess::kReadOnly; page_access = memory::PageAccess::kReadOnly;
} }
// Blah allocate on page granularity for now // Commit the memory if it isn't already. We do not need to reserve any
if ((uint32_t)alloc_type & (uint32_t)memory::AllocationType::kCommit) { // memory, as the mapping has already taken care of that.
if (page.state & kMemoryAllocationCommit) {
xe::memory::AllocFixed(membase_ + heap_base_ + i * page_size_, page_size_, xe::memory::AllocFixed(membase_ + heap_base_ + i * page_size_, page_size_,
alloc_type, page_access); memory::AllocationType::kCommit,
memory::PageAccess::kReadWrite);
} }
if (page.state & kMemoryAllocationCommit && // Now read into memory. We'll set R/W protection first, then set the
page.current_protect & kMemoryProtectRead) { // protection back to its previous state.
if (!xe::memory::Protect(membase_ + heap_base_ + i * page_size_, // TODO: Read compressed
page_size_, page_access, nullptr)) { if (page.state & kMemoryAllocationCommit) {
assert_always(); void* addr = membase_ + heap_base_ + i * page_size_;
} xe::memory::Protect(addr, page_size_, memory::PageAccess::kReadWrite,
nullptr);
stream->Read((void*)(membase_ + heap_base_ + i * page_size_), page_size_); stream->Read(addr, page_size_);
xe::memory::Protect(addr, page_size_, page_access, nullptr);
} }
} }