[Kernel/Memory] Do not clear range if it was previously commited

This commit is contained in:
Gliniak 2020-12-06 13:45:14 +01:00 committed by Rick Gibbed
parent 010f0aa517
commit 9ccdbb2153
1 changed files with 7 additions and 1 deletions

View File

@ -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);
}