From 1689784c198f6a7f3c389d4cd5edeccc74c1d9f3 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Sun, 7 Jul 2019 11:48:11 -0700 Subject: address review commentary --- src/core/hle/kernel/process.cpp | 14 +++++--------- src/core/hle/kernel/process.h | 23 +++++++++++++++++++---- src/core/hle/kernel/svc.cpp | 32 ++++++++++++-------------------- src/core/hle/kernel/vm_manager.cpp | 5 ++++- src/core/hle/kernel/vm_manager.h | 4 ++-- 5 files changed, 42 insertions(+), 36 deletions(-) (limited to 'src') diff --git a/src/core/hle/kernel/process.cpp b/src/core/hle/kernel/process.cpp index 51245cbb4..b0690be34 100644 --- a/src/core/hle/kernel/process.cpp +++ b/src/core/hle/kernel/process.cpp @@ -129,20 +129,16 @@ 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::GetTotalPhysicalMemoryAvailableWithoutSystemResource() const { + return GetTotalPhysicalMemoryAvailable() - GetSystemResourceSize(); } u64 Process::GetTotalPhysicalMemoryUsed() const { - return vm_manager.GetCurrentHeapSize() + main_thread_stack_size + code_memory_size; + return vm_manager.GetCurrentHeapSize() + main_thread_stack_size + code_memory_size + GetSystemResourceUsage(); } -u64 Process::GetTotalPhysicalMemoryUsedWithoutMmHeap() const { - // TODO: Subtract the personal heap size from this when the - // personal heap is implemented. - return GetTotalPhysicalMemoryUsed(); +u64 Process::GetTotalPhysicalMemoryUsedWithoutSystemResource() const { + return GetTotalPhysicalMemoryUsed() - GetSystemResourceUsage(); } void Process::RegisterThread(const Thread* thread) { diff --git a/src/core/hle/kernel/process.h b/src/core/hle/kernel/process.h index b0e795577..3196014da 100644 --- a/src/core/hle/kernel/process.h +++ b/src/core/hle/kernel/process.h @@ -173,6 +173,21 @@ public: return system_resource_size; } + /// Gets the amount of secure memory currently in use for memory management. + u32 GetSystemResourceUsage() const { + // On hardware, this returns the amount of system resource memory that has + // been used by the kernel. This is problematic for Yuzu to emulate, because + // system resource memory is used for page tables -- and yuzu doesn't really + // have a way to calculate how much memory is required for page tables for + // the current process at any given time. + // TODO: Is this even worth implementing? Games may retrieve this value via + // an SDK function that gets used + available system resource size for debug + // or diagnostic purposes. However, it seems unlikely that a game would make + // decisions based on how much system memory is dedicated to its page tables. + // Is returning a value other than zero wise? + return 0; + } + /// Whether this process is an AArch64 or AArch32 process. bool Is64BitProcess() const { return is_64bit_process; @@ -197,15 +212,15 @@ public: 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; + /// without the size of the personal system resource heap added to it. + u64 GetTotalPhysicalMemoryAvailableWithoutSystemResource() 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; + /// without the size of the personal system resource heap added to it. + u64 GetTotalPhysicalMemoryUsedWithoutSystemResource() const; /// Gets the list of all threads created with this process as their owner. const std::list& GetThreadList() const { diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp index abb374892..85e4512f0 100644 --- a/src/core/hle/kernel/svc.cpp +++ b/src/core/hle/kernel/svc.cpp @@ -737,8 +737,8 @@ static ResultCode GetInfo(Core::System& system, u64* result, u64 info_id, u64 ha // 5.0.0+ UserExceptionContextAddr = 20, // 6.0.0+ - TotalPhysicalMemoryAvailableWithoutMmHeap = 21, - TotalPhysicalMemoryUsedWithoutMmHeap = 22, + TotalPhysicalMemoryAvailableWithoutSystemResource = 21, + TotalPhysicalMemoryUsedWithoutSystemResource = 22, }; const auto info_id_type = static_cast(info_id); @@ -760,8 +760,8 @@ static ResultCode GetInfo(Core::System& system, u64* result, u64 info_id, u64 ha case GetInfoType::SystemResourceUsage: case GetInfoType::TitleId: case GetInfoType::UserExceptionContextAddr: - case GetInfoType::TotalPhysicalMemoryAvailableWithoutMmHeap: - case GetInfoType::TotalPhysicalMemoryUsedWithoutMmHeap: { + case GetInfoType::TotalPhysicalMemoryAvailableWithoutSystemResource: + case GetInfoType::TotalPhysicalMemoryUsedWithoutSystemResource: { if (info_sub_id != 0) { return ERR_INVALID_ENUM_VALUE; } @@ -827,17 +827,9 @@ static ResultCode GetInfo(Core::System& system, u64* result, u64 info_id, u64 ha return RESULT_SUCCESS; case GetInfoType::SystemResourceUsage: - // On hardware, this returns the amount of system resource memory that has - // been used by the kernel. This is problematic for Yuzu to emulate, because - // system resource memory is used for page tables -- and yuzu doesn't really - // have a way to calculate how much memory is required for page tables for - // the current process at any given time. - // TODO: Is this even worth implementing? No game should ever use it, since - // the amount of remaining page table space should never be relevant except - // for diagnostics. Is returning a value other than zero wise? LOG_WARNING(Kernel_SVC, - "(STUBBED) Attempted to query system resource usage, returned 0"); - *result = 0; + "(STUBBED) Attempted to query system resource usage"); + *result = process->GetSystemResourceUsage(); return RESULT_SUCCESS; case GetInfoType::TitleId: @@ -850,12 +842,12 @@ static ResultCode GetInfo(Core::System& system, u64* result, u64 info_id, u64 ha *result = 0; return RESULT_SUCCESS; - case GetInfoType::TotalPhysicalMemoryAvailableWithoutMmHeap: - *result = process->GetTotalPhysicalMemoryAvailable(); + case GetInfoType::TotalPhysicalMemoryAvailableWithoutSystemResource: + *result = process->GetTotalPhysicalMemoryAvailableWithoutSystemResource(); return RESULT_SUCCESS; - case GetInfoType::TotalPhysicalMemoryUsedWithoutMmHeap: - *result = process->GetTotalPhysicalMemoryUsedWithoutMmHeap(); + case GetInfoType::TotalPhysicalMemoryUsedWithoutSystemResource: + *result = process->GetTotalPhysicalMemoryUsedWithoutSystemResource(); return RESULT_SUCCESS; default: @@ -984,7 +976,7 @@ static ResultCode MapPhysicalMemory(Core::System& system, VAddr addr, u64 size) return ERR_INVALID_MEMORY_RANGE; } - auto* const current_process = Core::CurrentProcess(); + Process* const current_process = system.Kernel().CurrentProcess(); auto& vm_manager = current_process->VMManager(); if (current_process->GetSystemResourceSize() == 0) { @@ -1024,7 +1016,7 @@ static ResultCode UnmapPhysicalMemory(Core::System& system, VAddr addr, u64 size return ERR_INVALID_MEMORY_RANGE; } - auto* const current_process = Core::CurrentProcess(); + Process* const current_process = system.Kernel().CurrentProcess(); auto& vm_manager = current_process->VMManager(); if (current_process->GetSystemResourceSize() == 0) { diff --git a/src/core/hle/kernel/vm_manager.cpp b/src/core/hle/kernel/vm_manager.cpp index 9385a8697..bda325e87 100644 --- a/src/core/hle/kernel/vm_manager.cpp +++ b/src/core/hle/kernel/vm_manager.cpp @@ -349,7 +349,7 @@ ResultCode VMManager::MapPhysicalMemory(VAddr target, u64 size) { } // Check that we can map the memory we want. - const auto res_limit = Core::CurrentProcess()->GetResourceLimit(); + const auto res_limit = system.CurrentProcess()->GetResourceLimit(); const u64 physmem_remaining = res_limit->GetMaxResourceValue(ResourceType::PhysicalMemory) - res_limit->GetCurrentResourceValue(ResourceType::PhysicalMemory); if (physmem_remaining < (size - mapped_size)) { @@ -558,6 +558,9 @@ ResultCode VMManager::UnmapPhysicalMemory(VAddr target, u64 size) { } } + // Update mapped amount + physical_memory_mapped -= mapped_size; + return RESULT_SUCCESS; } diff --git a/src/core/hle/kernel/vm_manager.h b/src/core/hle/kernel/vm_manager.h index 16f40ad00..8be03a6e4 100644 --- a/src/core/hle/kernel/vm_manager.h +++ b/src/core/hle/kernel/vm_manager.h @@ -458,7 +458,7 @@ public: /// /// @note The destination address must lie within the Map region. /// - /// @note This function requires SystemResourceSize is non-zero, + /// @note This function requires that SystemResourceSize be non-zero, /// however, this is just because if it were not then the /// resulting page tables could be exploited on hardware by /// a malicious program. SystemResource usage does not need @@ -472,7 +472,7 @@ public: /// /// @note The destination address must lie within the Map region. /// - /// @note This function requires SystemResourceSize is non-zero, + /// @note This function requires that SystemResourceSize be non-zero, /// however, this is just because if it were not then the /// resulting page tables could be exploited on hardware by /// a malicious program. SystemResource usage does not need -- cgit v1.2.3