aboutsummaryrefslogtreecommitdiff
path: root/src/core/hle/kernel/vm_manager.cpp
diff options
context:
space:
mode:
authorLioncash <mathew1800@gmail.com>2019-03-24 16:30:45 -0400
committerLioncash <mathew1800@gmail.com>2019-03-24 17:08:30 -0400
commit4a886e14f961d16ffd965aeca446a814e82d4680 (patch)
tree75d964749fc4374ed41fa6685d0ffff7b9c05ec4 /src/core/hle/kernel/vm_manager.cpp
parent142364942d369afb12091461d06306c765a6edd6 (diff)
kernel/vm_manager: Handle shrinking of the heap size within SetHeapSize()
One behavior that we weren't handling properly in our heap allocation process was the ability for the heap to be shrunk down in size if a larger size was previously requested. This adds the basic behavior to do so and also gets rid of HeapFree, as it's no longer necessary now that we have allocations and deallocations going through the same API function. While we're at it, fully document the behavior that this function performs.
Diffstat (limited to 'src/core/hle/kernel/vm_manager.cpp')
-rw-r--r--src/core/hle/kernel/vm_manager.cpp34
1 files changed, 13 insertions, 21 deletions
diff --git a/src/core/hle/kernel/vm_manager.cpp b/src/core/hle/kernel/vm_manager.cpp
index 523fe63e93..ec0a480ce5 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{};