diff --git a/src/xenia/kernel/xboxkrnl/xboxkrnl_memory.cc b/src/xenia/kernel/xboxkrnl/xboxkrnl_memory.cc index de672b227..25d6b0347 100644 --- a/src/xenia/kernel/xboxkrnl/xboxkrnl_memory.cc +++ b/src/xenia/kernel/xboxkrnl/xboxkrnl_memory.cc @@ -136,6 +136,8 @@ dword_result_t NtAllocateVirtualMemory(lpdword_t base_addr_ptr, uint32_t protect = FromXdkProtectFlags(protect_bits); uint32_t address = 0; BaseHeap* heap; + HeapAllocationInfo prev_alloc_info = {}; + bool was_commited = false; if (adjusted_base != 0) { heap = kernel_memory()->LookupHeap(adjusted_base); @@ -143,6 +145,8 @@ dword_result_t NtAllocateVirtualMemory(lpdword_t base_addr_ptr, // Specified the wrong page size for the wrong heap. return X_STATUS_ACCESS_DENIED; } + was_commited = heap->QueryRegionInfo(adjusted_base, &prev_alloc_info) && + (prev_alloc_info.state & kMemoryAllocationCommit) != 0; if (heap->AllocFixed(adjusted_base, adjusted_size, page_size, allocation_type, protect)) { @@ -166,7 +170,9 @@ dword_result_t NtAllocateVirtualMemory(lpdword_t base_addr_ptr, heap->Protect(address, adjusted_size, kMemoryProtectRead | kMemoryProtectWrite); } - kernel_memory()->Zero(address, adjusted_size); + if (!was_commited) { + kernel_memory()->Zero(address, adjusted_size); + } if (!(protect & kMemoryProtectWrite)) { heap->Protect(address, adjusted_size, protect); }