From 81b11020908e6ca6b0a8a881046fef0f23c80aaa Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 9 Jun 2019 18:08:37 -0400 Subject: [PATCH 1/3] kernel/svc: Remove duplicate enum entry in svcGetInfo() --- src/core/hle/kernel/svc.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp index 5a5851f66..1f8b0d92b 100644 --- a/src/core/hle/kernel/svc.cpp +++ b/src/core/hle/kernel/svc.cpp @@ -716,7 +716,7 @@ static ResultCode GetInfo(Core::System& system, u64* result, u64 info_id, u64 ha RegisterResourceLimit = 9, IdleTickCount = 10, RandomEntropy = 11, - PerformanceCounter = 0xF0000002, + ThreadTickCount = 0xF0000002, // 2.0.0+ ASLRRegionBaseAddr = 12, ASLRRegionSize = 13, @@ -730,7 +730,6 @@ static ResultCode GetInfo(Core::System& system, u64* result, u64 info_id, u64 ha PrivilegedProcessId = 19, // 5.0.0+ UserExceptionContextAddr = 20, - ThreadTickCount = 0xF0000002, }; const auto info_id_type = static_cast(info_id); From c1a8f684df76afc9d1b450da97e504b8d9d65a97 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 9 Jun 2019 18:12:02 -0400 Subject: [PATCH 2/3] kernel/svc: Amend naming for TotalMemoryUsage in svcGetInfo() Disambiguates and makes the name a little more consistent with TotalPhysicalMemoryUsed. --- src/core/hle/kernel/svc.cpp | 8 ++++---- src/core/hle/kernel/vm_manager.cpp | 2 +- src/core/hle/kernel/vm_manager.h | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp index 1f8b0d92b..377a9bf48 100644 --- a/src/core/hle/kernel/svc.cpp +++ b/src/core/hle/kernel/svc.cpp @@ -710,7 +710,7 @@ static ResultCode GetInfo(Core::System& system, u64* result, u64 info_id, u64 ha MapRegionSize = 3, HeapRegionBaseAddr = 4, HeapRegionSize = 5, - TotalMemoryUsage = 6, + TotalPhysicalMemoryAvailable = 6, TotalPhysicalMemoryUsed = 7, IsCurrentProcessBeingDebugged = 8, RegisterResourceLimit = 9, @@ -745,7 +745,7 @@ static ResultCode GetInfo(Core::System& system, u64* result, u64 info_id, u64 ha case GetInfoType::ASLRRegionSize: case GetInfoType::NewMapRegionBaseAddr: case GetInfoType::NewMapRegionSize: - case GetInfoType::TotalMemoryUsage: + case GetInfoType::TotalPhysicalMemoryAvailable: case GetInfoType::TotalPhysicalMemoryUsed: case GetInfoType::IsVirtualAddressMemoryEnabled: case GetInfoType::PersonalMmHeapUsage: @@ -803,8 +803,8 @@ static ResultCode GetInfo(Core::System& system, u64* result, u64 info_id, u64 ha *result = process->VMManager().GetNewMapRegionSize(); return RESULT_SUCCESS; - case GetInfoType::TotalMemoryUsage: - *result = process->VMManager().GetTotalMemoryUsage(); + case GetInfoType::TotalPhysicalMemoryAvailable: + *result = process->VMManager().GetTotalPhysicalMemoryAvailable(); return RESULT_SUCCESS; case GetInfoType::TotalPhysicalMemoryUsed: diff --git a/src/core/hle/kernel/vm_manager.cpp b/src/core/hle/kernel/vm_manager.cpp index 48b13cfdd..6d6980aba 100644 --- a/src/core/hle/kernel/vm_manager.cpp +++ b/src/core/hle/kernel/vm_manager.cpp @@ -758,7 +758,7 @@ VMManager::CheckResults VMManager::CheckRangeState(VAddr address, u64 size, Memo std::make_tuple(initial_state, initial_permissions, initial_attributes & ~ignore_mask)); } -u64 VMManager::GetTotalMemoryUsage() const { +u64 VMManager::GetTotalPhysicalMemoryAvailable() const { LOG_WARNING(Kernel, "(STUBBED) called"); return 0xF8000000; } diff --git a/src/core/hle/kernel/vm_manager.h b/src/core/hle/kernel/vm_manager.h index ec84d9a70..dfbf7a894 100644 --- a/src/core/hle/kernel/vm_manager.h +++ b/src/core/hle/kernel/vm_manager.h @@ -499,7 +499,7 @@ public: void LogLayout() const; /// Gets the total memory usage, used by svcGetInfo - u64 GetTotalMemoryUsage() const; + u64 GetTotalPhysicalMemoryAvailable() const; /// Gets the address space base address VAddr GetAddressSpaceBaseAddress() const; From 3f87664d8fac06b024b0a59adfdfe570ab6195e5 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 9 Jun 2019 18:20:20 -0400 Subject: [PATCH 3/3] kernel/svc: Implement TotalMemoryUsedWithoutMmHeap/TotalMemoryAvailableWithoutMmHeap Given we don't currently implement the personal heap yet, the existing memory querying functions are essentially doing what the memory querying types introduced in 6.0.0 do. So, we can build the necessary machinery over the top of those and just use them as part of info types. --- src/core/hle/kernel/process.cpp | 16 ++++++++++++++++ src/core/hle/kernel/process.h | 11 +++++++++++ src/core/hle/kernel/svc.cpp | 17 +++++++++++++++-- 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/src/core/hle/kernel/process.cpp b/src/core/hle/kernel/process.cpp index 0775a89fb..63a3707b2 100644 --- a/src/core/hle/kernel/process.cpp +++ b/src/core/hle/kernel/process.cpp @@ -72,10 +72,26 @@ SharedPtr Process::GetResourceLimit() const { return resource_limit; } +u64 Process::GetTotalPhysicalMemoryAvailable() const { + return vm_manager.GetTotalPhysicalMemoryAvailable(); +} + +u64 Process::GetTotalPhysicalMemoryAvailableWithoutMmHeap() const { + // TODO: Subtract the personal heap size from this when the + // personal heap is implemented. + return GetTotalPhysicalMemoryAvailable(); +} + u64 Process::GetTotalPhysicalMemoryUsed() const { return vm_manager.GetCurrentHeapSize() + main_thread_stack_size + code_memory_size; } +u64 Process::GetTotalPhysicalMemoryUsedWithoutMmHeap() const { + // TODO: Subtract the personal heap size from this when the + // personal heap is implemented. + return GetTotalPhysicalMemoryUsed(); +} + void Process::RegisterThread(const Thread* thread) { thread_list.push_back(thread); } diff --git a/src/core/hle/kernel/process.h b/src/core/hle/kernel/process.h index f027fafa3..9c20eb7f8 100644 --- a/src/core/hle/kernel/process.h +++ b/src/core/hle/kernel/process.h @@ -186,9 +186,20 @@ public: return random_entropy.at(index); } + /// Retrieves the total physical memory available to this process in bytes. + u64 GetTotalPhysicalMemoryAvailable() const; + + /// Retrieves the total physical memory available to this process in bytes, + /// without the size of the personal heap added to it. + u64 GetTotalPhysicalMemoryAvailableWithoutMmHeap() const; + /// Retrieves the total physical memory used by this process in bytes. u64 GetTotalPhysicalMemoryUsed() const; + /// Retrieves the total physical memory used by this process in bytes, + /// without the size of the personal heap added to it. + u64 GetTotalPhysicalMemoryUsedWithoutMmHeap() const; + /// Gets the list of all threads created with this process as their owner. const std::list& GetThreadList() const { return thread_list; diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp index 377a9bf48..f9c606bc5 100644 --- a/src/core/hle/kernel/svc.cpp +++ b/src/core/hle/kernel/svc.cpp @@ -730,6 +730,9 @@ static ResultCode GetInfo(Core::System& system, u64* result, u64 info_id, u64 ha PrivilegedProcessId = 19, // 5.0.0+ UserExceptionContextAddr = 20, + // 6.0.0+ + TotalPhysicalMemoryAvailableWithoutMmHeap = 21, + TotalPhysicalMemoryUsedWithoutMmHeap = 22, }; const auto info_id_type = static_cast(info_id); @@ -750,7 +753,9 @@ static ResultCode GetInfo(Core::System& system, u64* result, u64 info_id, u64 ha case GetInfoType::IsVirtualAddressMemoryEnabled: case GetInfoType::PersonalMmHeapUsage: case GetInfoType::TitleId: - case GetInfoType::UserExceptionContextAddr: { + case GetInfoType::UserExceptionContextAddr: + case GetInfoType::TotalPhysicalMemoryAvailableWithoutMmHeap: + case GetInfoType::TotalPhysicalMemoryUsedWithoutMmHeap: { if (info_sub_id != 0) { return ERR_INVALID_ENUM_VALUE; } @@ -804,7 +809,7 @@ static ResultCode GetInfo(Core::System& system, u64* result, u64 info_id, u64 ha return RESULT_SUCCESS; case GetInfoType::TotalPhysicalMemoryAvailable: - *result = process->VMManager().GetTotalPhysicalMemoryAvailable(); + *result = process->GetTotalPhysicalMemoryAvailable(); return RESULT_SUCCESS; case GetInfoType::TotalPhysicalMemoryUsed: @@ -825,6 +830,14 @@ static ResultCode GetInfo(Core::System& system, u64* result, u64 info_id, u64 ha *result = 0; return RESULT_SUCCESS; + case GetInfoType::TotalPhysicalMemoryAvailableWithoutMmHeap: + *result = process->GetTotalPhysicalMemoryAvailable(); + return RESULT_SUCCESS; + + case GetInfoType::TotalPhysicalMemoryUsedWithoutMmHeap: + *result = process->GetTotalPhysicalMemoryUsedWithoutMmHeap(); + return RESULT_SUCCESS; + default: break; }