diff options
author | Lioncash <mathew1800@gmail.com> | 2019-03-24 20:24:52 +0100 |
---|---|---|
committer | Lioncash <mathew1800@gmail.com> | 2019-03-24 21:17:31 +0100 |
commit | 586cab617270346c39ecfb340127e0b8edb863d3 (patch) | |
tree | 47daaae2ad06629fc4c636746cc39b6818441425 /src/core/hle/kernel/vm_manager.cpp | |
parent | Merge pull request #2221 from DarkLordZach/firmware-version (diff) | |
download | yuzu-586cab617270346c39ecfb340127e0b8edb863d3.tar yuzu-586cab617270346c39ecfb340127e0b8edb863d3.tar.gz yuzu-586cab617270346c39ecfb340127e0b8edb863d3.tar.bz2 yuzu-586cab617270346c39ecfb340127e0b8edb863d3.tar.lz yuzu-586cab617270346c39ecfb340127e0b8edb863d3.tar.xz yuzu-586cab617270346c39ecfb340127e0b8edb863d3.tar.zst yuzu-586cab617270346c39ecfb340127e0b8edb863d3.zip |
Diffstat (limited to '')
-rw-r--r-- | src/core/hle/kernel/vm_manager.cpp | 42 |
1 files changed, 22 insertions, 20 deletions
diff --git a/src/core/hle/kernel/vm_manager.cpp b/src/core/hle/kernel/vm_manager.cpp index 22bf55ce7..9848a8ac6 100644 --- a/src/core/hle/kernel/vm_manager.cpp +++ b/src/core/hle/kernel/vm_manager.cpp @@ -256,39 +256,37 @@ ResultCode VMManager::ReprotectRange(VAddr target, u64 size, VMAPermission new_p return RESULT_SUCCESS; } -ResultVal<VAddr> VMManager::HeapAllocate(VAddr target, u64 size, VMAPermission perms) { - if (!IsWithinHeapRegion(target, size)) { - return ERR_INVALID_ADDRESS; +ResultVal<VAddr> VMManager::HeapAllocate(u64 size) { + if (size > GetHeapRegionSize()) { + return ERR_OUT_OF_MEMORY; } if (heap_memory == nullptr) { // Initialize heap - heap_memory = std::make_shared<std::vector<u8>>(); - heap_start = heap_end = target; + heap_memory = std::make_shared<std::vector<u8>>(size); + heap_end = heap_region_base + size; } else { - UnmapRange(heap_start, heap_end - heap_start); + UnmapRange(heap_region_base, GetCurrentHeapSize()); } // If necessary, expand backing vector to cover new heap extents. - if (target < heap_start) { - heap_memory->insert(begin(*heap_memory), heap_start - target, 0); - heap_start = target; - RefreshMemoryBlockMappings(heap_memory.get()); - } - if (target + size > heap_end) { - heap_memory->insert(end(*heap_memory), (target + size) - heap_end, 0); - heap_end = target + size; + if (size > GetCurrentHeapSize()) { + const u64 alloc_size = size - GetCurrentHeapSize(); + + heap_memory->insert(heap_memory->end(), alloc_size, 0); + heap_end = heap_region_base + size; RefreshMemoryBlockMappings(heap_memory.get()); } - ASSERT(heap_end - heap_start == heap_memory->size()); + ASSERT(GetCurrentHeapSize() == heap_memory->size()); - CASCADE_RESULT(auto vma, MapMemoryBlock(target, heap_memory, target - heap_start, size, - MemoryState::Heap)); - Reprotect(vma, perms); + const auto mapping_result = + MapMemoryBlock(heap_region_base, heap_memory, 0, size, MemoryState::Heap); + if (mapping_result.Failed()) { + return mapping_result.Code(); + } heap_used = size; - - return MakeResult<VAddr>(heap_end - size); + return MakeResult<VAddr>(heap_region_base); } ResultCode VMManager::HeapFree(VAddr target, u64 size) { @@ -778,6 +776,10 @@ u64 VMManager::GetHeapRegionSize() const { return heap_region_end - heap_region_base; } +u64 VMManager::GetCurrentHeapSize() const { + return heap_end - heap_region_base; +} + bool VMManager::IsWithinHeapRegion(VAddr address, u64 size) const { return IsInsideAddressRange(address, size, GetHeapRegionBaseAddress(), GetHeapRegionEndAddress()); |