summaryrefslogtreecommitdiffstats
path: root/src/core
diff options
context:
space:
mode:
authorLioncash <mathew1800@gmail.com>2019-03-24 21:30:45 +0100
committerLioncash <mathew1800@gmail.com>2019-03-24 22:08:30 +0100
commit1e92ba27855a40d928265debfdf2478248e40eaf (patch)
tree75d964749fc4374ed41fa6685d0ffff7b9c05ec4 /src/core
parentkernel/vm_manager: Rename HeapAllocate to SetHeapSize (diff)
downloadyuzu-1e92ba27855a40d928265debfdf2478248e40eaf.tar
yuzu-1e92ba27855a40d928265debfdf2478248e40eaf.tar.gz
yuzu-1e92ba27855a40d928265debfdf2478248e40eaf.tar.bz2
yuzu-1e92ba27855a40d928265debfdf2478248e40eaf.tar.lz
yuzu-1e92ba27855a40d928265debfdf2478248e40eaf.tar.xz
yuzu-1e92ba27855a40d928265debfdf2478248e40eaf.tar.zst
yuzu-1e92ba27855a40d928265debfdf2478248e40eaf.zip
Diffstat (limited to 'src/core')
-rw-r--r--src/core/hle/kernel/vm_manager.cpp34
-rw-r--r--src/core/hle/kernel/vm_manager.h36
2 files changed, 46 insertions, 24 deletions
diff --git a/src/core/hle/kernel/vm_manager.cpp b/src/core/hle/kernel/vm_manager.cpp
index 523fe63e9..ec0a480ce 100644
--- a/src/core/hle/kernel/vm_manager.cpp
+++ b/src/core/hle/kernel/vm_manager.cpp
@@ -274,14 +274,23 @@ ResultVal<VAddr> VMManager::SetHeapSize(u64 size) {
UnmapRange(heap_region_base, GetCurrentHeapSize());
}
- // If necessary, expand backing vector to cover new heap extents.
- if (size > GetCurrentHeapSize()) {
- const u64 alloc_size = size - GetCurrentHeapSize();
+ // If necessary, expand backing vector to cover new heap extents in
+ // the case of allocating. Otherwise, shrink the backing memory,
+ // if a smaller heap has been requested.
+ const u64 old_heap_size = GetCurrentHeapSize();
+ if (size > old_heap_size) {
+ const u64 alloc_size = size - old_heap_size;
heap_memory->insert(heap_memory->end(), alloc_size, 0);
- heap_end = heap_region_base + size;
+ RefreshMemoryBlockMappings(heap_memory.get());
+ } else if (size < old_heap_size) {
+ heap_memory->resize(size);
+ heap_memory->shrink_to_fit();
+
RefreshMemoryBlockMappings(heap_memory.get());
}
+
+ heap_end = heap_region_base + size;
ASSERT(GetCurrentHeapSize() == heap_memory->size());
const auto mapping_result =
@@ -293,23 +302,6 @@ ResultVal<VAddr> VMManager::SetHeapSize(u64 size) {
return MakeResult<VAddr>(heap_region_base);
}
-ResultCode VMManager::HeapFree(VAddr target, u64 size) {
- if (!IsWithinHeapRegion(target, size)) {
- return ERR_INVALID_ADDRESS;
- }
-
- if (size == 0) {
- return RESULT_SUCCESS;
- }
-
- const ResultCode result = UnmapRange(target, size);
- if (result.IsError()) {
- return result;
- }
-
- return RESULT_SUCCESS;
-}
-
MemoryInfo VMManager::QueryMemory(VAddr address) const {
const auto vma = FindVMA(address);
MemoryInfo memory_info{};
diff --git a/src/core/hle/kernel/vm_manager.h b/src/core/hle/kernel/vm_manager.h
index cab748364..6f484b7bf 100644
--- a/src/core/hle/kernel/vm_manager.h
+++ b/src/core/hle/kernel/vm_manager.h
@@ -380,11 +380,41 @@ public:
/// Changes the permissions of a range of addresses, splitting VMAs as necessary.
ResultCode ReprotectRange(VAddr target, u64 size, VMAPermission new_perms);
- ResultVal<VAddr> SetHeapSize(u64 size);
- ResultCode HeapFree(VAddr target, u64 size);
-
ResultCode MirrorMemory(VAddr dst_addr, VAddr src_addr, u64 size, MemoryState state);
+ /// Attempts to allocate a heap with the given size.
+ ///
+ /// @param size The size of the heap to allocate in bytes.
+ ///
+ /// @note If a heap is currently allocated, and this is called
+ /// with a size that is equal to the size of the current heap,
+ /// then this function will do nothing and return the current
+ /// heap's starting address, as there's no need to perform
+ /// any additional heap allocation work.
+ ///
+ /// @note If a heap is currently allocated, and this is called
+ /// with a size less than the current heap's size, then
+ /// this function will attempt to shrink the heap.
+ ///
+ /// @note If a heap is currently allocated, and this is called
+ /// with a size larger than the current heap's size, then
+ /// this function will attempt to extend the size of the heap.
+ ///
+ /// @returns A result indicating either success or failure.
+ /// <p>
+ /// If successful, this function will return a result
+ /// containing the starting address to the allocated heap.
+ /// <p>
+ /// If unsuccessful, this function will return a result
+ /// containing an error code.
+ ///
+ /// @pre The given size must lie within the allowable heap
+ /// memory region managed by this VMManager instance.
+ /// Failure to abide by this will result in ERR_OUT_OF_MEMORY
+ /// being returned as the result.
+ ///
+ ResultVal<VAddr> SetHeapSize(u64 size);
+
/// Queries the memory manager for information about the given address.
///
/// @param address The address to query the memory manager about for information.