[Kernel] Fix MmAllocatePhysicalMemoryEx range base

This commit is contained in:
Triang3l 2019-08-24 19:23:31 +03:00
parent 7e6bf8022f
commit a422166123
1 changed files with 13 additions and 2 deletions

View File

@ -330,9 +330,20 @@ dword_result_t MmAllocatePhysicalMemoryEx(dword_t flags, dword_t region_size,
uint32_t allocation_type = kMemoryAllocationReserve | kMemoryAllocationCommit;
uint32_t protect = FromXdkProtectFlags(protect_bits);
bool top_down = true;
auto heap = kernel_memory()->LookupHeapByType(true, page_size);
auto heap = static_cast<PhysicalHeap*>(
kernel_memory()->LookupHeapByType(true, page_size));
// min_addr_range/max_addr_range are bounds in physical memory, not virtual.
uint32_t heap_base = heap->heap_base();
uint32_t heap_physical_address_offset = heap->GetPhysicalAddress(heap_base);
uint32_t heap_min_addr =
xe::sat_sub(min_addr_range.value(), heap_physical_address_offset);
uint32_t heap_max_addr =
xe::sat_sub(max_addr_range.value(), heap_physical_address_offset);
uint32_t heap_size = heap->heap_size();
heap_min_addr = heap_base + std::min(heap_min_addr, heap_size);
heap_max_addr = heap_base + std::min(heap_max_addr, heap_size);
uint32_t base_address;
if (!heap->AllocRange(min_addr_range, max_addr_range, adjusted_size,
if (!heap->AllocRange(heap_min_addr, heap_max_addr, adjusted_size,
adjusted_alignment, allocation_type, protect, top_down,
&base_address)) {
// Failed - assume no memory available.