[Kernel/Memory] Do not clear range if it was previously commited
This commit is contained in:
parent
010f0aa517
commit
9ccdbb2153
|
@ -136,6 +136,8 @@ dword_result_t NtAllocateVirtualMemory(lpdword_t base_addr_ptr,
|
||||||
uint32_t protect = FromXdkProtectFlags(protect_bits);
|
uint32_t protect = FromXdkProtectFlags(protect_bits);
|
||||||
uint32_t address = 0;
|
uint32_t address = 0;
|
||||||
BaseHeap* heap;
|
BaseHeap* heap;
|
||||||
|
HeapAllocationInfo prev_alloc_info = {};
|
||||||
|
bool was_commited = false;
|
||||||
|
|
||||||
if (adjusted_base != 0) {
|
if (adjusted_base != 0) {
|
||||||
heap = kernel_memory()->LookupHeap(adjusted_base);
|
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.
|
// Specified the wrong page size for the wrong heap.
|
||||||
return X_STATUS_ACCESS_DENIED;
|
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,
|
if (heap->AllocFixed(adjusted_base, adjusted_size, page_size,
|
||||||
allocation_type, protect)) {
|
allocation_type, protect)) {
|
||||||
|
@ -166,7 +170,9 @@ dword_result_t NtAllocateVirtualMemory(lpdword_t base_addr_ptr,
|
||||||
heap->Protect(address, adjusted_size,
|
heap->Protect(address, adjusted_size,
|
||||||
kMemoryProtectRead | kMemoryProtectWrite);
|
kMemoryProtectRead | kMemoryProtectWrite);
|
||||||
}
|
}
|
||||||
kernel_memory()->Zero(address, adjusted_size);
|
if (!was_commited) {
|
||||||
|
kernel_memory()->Zero(address, adjusted_size);
|
||||||
|
}
|
||||||
if (!(protect & kMemoryProtectWrite)) {
|
if (!(protect & kMemoryProtectWrite)) {
|
||||||
heap->Protect(address, adjusted_size, protect);
|
heap->Protect(address, adjusted_size, protect);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue