diff --git a/src/xenia/kernel/xboxkrnl/xboxkrnl_memory.cc b/src/xenia/kernel/xboxkrnl/xboxkrnl_memory.cc index de594bf9a..d5e444441 100644 --- a/src/xenia/kernel/xboxkrnl/xboxkrnl_memory.cc +++ b/src/xenia/kernel/xboxkrnl/xboxkrnl_memory.cc @@ -140,6 +140,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); @@ -147,6 +149,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)) { @@ -171,7 +175,9 @@ dword_result_t NtAllocateVirtualMemory(lpdword_t base_addr_ptr, 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);