From 586cab617270346c39ecfb340127e0b8edb863d3 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 24 Mar 2019 15:24:52 -0400 Subject: kernel/vm_manager: Tidy up heap allocation code Another holdover from citra that can be tossed out is the notion of the heap needing to be allocated in different addresses. On the switch, the base address of the heap will always be managed by the memory allocator in the kernel, so this doesn't need to be specified in the function's interface itself. The heap on the switch is always allocated with read/write permissions, so we don't need to add specifying the memory permissions as part of the heap allocation itself either. This also corrects the error code returned from within the function. If the size of the heap is larger than the entire heap region, then the kernel will report an out of memory condition. --- src/core/hle/kernel/svc.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'src/core/hle/kernel/svc.cpp') diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp index a6a17efe7..59bc8d9f8 100644 --- a/src/core/hle/kernel/svc.cpp +++ b/src/core/hle/kernel/svc.cpp @@ -174,10 +174,8 @@ static ResultCode SetHeapSize(VAddr* heap_addr, u64 heap_size) { return ERR_INVALID_SIZE; } - auto& vm_manager = Core::CurrentProcess()->VMManager(); - const VAddr heap_base = vm_manager.GetHeapRegionBaseAddress(); - const auto alloc_result = - vm_manager.HeapAllocate(heap_base, heap_size, VMAPermission::ReadWrite); + auto& vm_manager = Core::System::GetInstance().Kernel().CurrentProcess()->VMManager(); + const auto alloc_result = vm_manager.HeapAllocate(heap_size); if (alloc_result.Failed()) { return alloc_result.Code(); -- cgit v1.2.3 From 52980df1aa796bb1eba3e5fec921eab1df961e51 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 24 Mar 2019 15:56:07 -0400 Subject: kernel/vm_manager: Remove unnecessary heap_used data member This isn't required anymore, as all the kernel ever queries is the size of the current heap, not the total usage of it. --- src/core/hle/kernel/svc.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/core/hle/kernel/svc.cpp') diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp index 59bc8d9f8..f689f745f 100644 --- a/src/core/hle/kernel/svc.cpp +++ b/src/core/hle/kernel/svc.cpp @@ -806,7 +806,7 @@ static ResultCode GetInfo(u64* result, u64 info_id, u64 handle, u64 info_sub_id) return RESULT_SUCCESS; case GetInfoType::TotalHeapUsage: - *result = process->VMManager().GetTotalHeapUsage(); + *result = process->VMManager().GetCurrentHeapSize(); return RESULT_SUCCESS; case GetInfoType::IsVirtualAddressMemoryEnabled: -- cgit v1.2.3 From 99a163478be9ca285280ee59aa7800903b8571c2 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 24 Mar 2019 16:28:04 -0400 Subject: kernel/vm_manager: Rename HeapAllocate to SetHeapSize Makes it more obvious that this function is intending to stand in for the actual supervisor call itself, and not acting as a general heap allocation function. Also the following change will merge the freeing behavior of HeapFree into this function, so leaving it as HeapAllocate would be misleading. --- src/core/hle/kernel/svc.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/core/hle/kernel/svc.cpp') diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp index f689f745f..6a8960c8d 100644 --- a/src/core/hle/kernel/svc.cpp +++ b/src/core/hle/kernel/svc.cpp @@ -175,8 +175,7 @@ static ResultCode SetHeapSize(VAddr* heap_addr, u64 heap_size) { } auto& vm_manager = Core::System::GetInstance().Kernel().CurrentProcess()->VMManager(); - const auto alloc_result = vm_manager.HeapAllocate(heap_size); - + const auto alloc_result = vm_manager.SetHeapSize(heap_size); if (alloc_result.Failed()) { return alloc_result.Code(); } -- cgit v1.2.3