summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGliniak <Gliniak93@gmail.com>2020-11-29 12:03:17 +0100
committerRick Gibbed <rick@gibbed.us>2020-12-05 14:18:03 -0600
commitff5c5f01e0e31abee675be7e48c11c20642a40fb (patch)
treeb3b2b9c9fc1daad1dce11394ee15c4bfde2a6dff
parent1513dd235bfe3a944c621e09e98a94bfbb0ab5a3 (diff)
[Kernel] Zeroing out pages without write protect flag
-rw-r--r--src/xenia/kernel/xboxkrnl/xboxkrnl_memory.cc13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/xenia/kernel/xboxkrnl/xboxkrnl_memory.cc b/src/xenia/kernel/xboxkrnl/xboxkrnl_memory.cc
index bcb88123c..de672b227 100644
--- a/src/xenia/kernel/xboxkrnl/xboxkrnl_memory.cc
+++ b/src/xenia/kernel/xboxkrnl/xboxkrnl_memory.cc
@@ -135,8 +135,10 @@ dword_result_t NtAllocateVirtualMemory(lpdword_t base_addr_ptr,
}
uint32_t protect = FromXdkProtectFlags(protect_bits);
uint32_t address = 0;
+ BaseHeap* heap;
+
if (adjusted_base != 0) {
- auto heap = kernel_memory()->LookupHeap(adjusted_base);
+ heap = kernel_memory()->LookupHeap(adjusted_base);
if (heap->page_size() != page_size) {
// Specified the wrong page size for the wrong heap.
return X_STATUS_ACCESS_DENIED;
@@ -148,7 +150,7 @@ dword_result_t NtAllocateVirtualMemory(lpdword_t base_addr_ptr,
}
} else {
bool top_down = !!(alloc_type & X_MEM_TOP_DOWN);
- auto heap = kernel_memory()->LookupHeapByType(false, page_size);
+ heap = kernel_memory()->LookupHeapByType(false, page_size);
heap->Alloc(adjusted_size, page_size, allocation_type, protect, top_down,
&address);
}
@@ -160,7 +162,14 @@ dword_result_t NtAllocateVirtualMemory(lpdword_t base_addr_ptr,
// Zero memory, if needed.
if (address && !(alloc_type & X_MEM_NOZERO)) {
if (alloc_type & X_MEM_COMMIT) {
+ if (!(protect & kMemoryProtectWrite)) {
+ heap->Protect(address, adjusted_size,
+ kMemoryProtectRead | kMemoryProtectWrite);
+ }
kernel_memory()->Zero(address, adjusted_size);
+ if (!(protect & kMemoryProtectWrite)) {
+ heap->Protect(address, adjusted_size, protect);
+ }
}
}