diff --git a/src/xenia/memory.cc b/src/xenia/memory.cc index f5c178be9..fa24da118 100644 --- a/src/xenia/memory.cc +++ b/src/xenia/memory.cc @@ -553,9 +553,9 @@ uint32_t Memory::SystemHeapAlloc(uint32_t size, uint32_t alignment, bool is_physical = !!(system_heap_flags & kSystemHeapPhysical); auto heap = LookupHeapByType(is_physical, 4096); uint32_t address; - if (!heap->Alloc(size, alignment, - kMemoryAllocationReserve | kMemoryAllocationCommit, - kMemoryProtectRead | kMemoryProtectWrite, false, &address)) { + if (!heap->AllocSystemHeap( + size, alignment, kMemoryAllocationReserve | kMemoryAllocationCommit, + kMemoryProtectRead | kMemoryProtectWrite, false, &address)) { return 0; } Zero(address, size); @@ -1059,6 +1059,24 @@ bool BaseHeap::AllocRange(uint32_t low_address, uint32_t high_address, return true; } +bool BaseHeap::AllocSystemHeap(uint32_t size, uint32_t alignment, + uint32_t allocation_type, uint32_t protect, + bool top_down, uint32_t* out_address) { + *out_address = 0; + size = xe::round_up(size, page_size_); + alignment = xe::round_up(alignment, page_size_); + + uint32_t low_address = heap_base_; + if (heap_type_ == xe::HeapType::kGuestVirtual) { + // Both virtual heaps are same size, so we can assume that we substract + // constant value. + low_address = heap_base_ + heap_size_ - 0x10000000; + } + uint32_t high_address = heap_base_ + (heap_size_ - 1); + return AllocRange(low_address, high_address, size, alignment, allocation_type, + protect, top_down, out_address); +} + bool BaseHeap::Decommit(uint32_t address, uint32_t size) { uint32_t page_count = get_page_count(size, page_size_); uint32_t start_page_number = (address - heap_base_) / page_size_;