summaryrefslogtreecommitdiff
path: root/src/core/hle
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/hle')
-rw-r--r--src/core/hle/kernel/process.cpp14
-rw-r--r--src/core/hle/kernel/process.h23
-rw-r--r--src/core/hle/kernel/svc.cpp32
-rw-r--r--src/core/hle/kernel/vm_manager.cpp5
-rw-r--r--src/core/hle/kernel/vm_manager.h4
5 files changed, 42 insertions, 36 deletions
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 {
129 return vm_manager.GetTotalPhysicalMemoryAvailable(); 129 return vm_manager.GetTotalPhysicalMemoryAvailable();
130} 130}
131 131
132u64 Process::GetTotalPhysicalMemoryAvailableWithoutMmHeap() const { 132u64 Process::GetTotalPhysicalMemoryAvailableWithoutSystemResource() const {
133 // TODO: Subtract the personal heap size from this when the 133 return GetTotalPhysicalMemoryAvailable() - GetSystemResourceSize();
134 // personal heap is implemented.
135 return GetTotalPhysicalMemoryAvailable();
136} 134}
137 135
138u64 Process::GetTotalPhysicalMemoryUsed() const { 136u64 Process::GetTotalPhysicalMemoryUsed() const {
139 return vm_manager.GetCurrentHeapSize() + main_thread_stack_size + code_memory_size; 137 return vm_manager.GetCurrentHeapSize() + main_thread_stack_size + code_memory_size + GetSystemResourceUsage();
140} 138}
141 139
142u64 Process::GetTotalPhysicalMemoryUsedWithoutMmHeap() const { 140u64 Process::GetTotalPhysicalMemoryUsedWithoutSystemResource() const {
143 // TODO: Subtract the personal heap size from this when the 141 return GetTotalPhysicalMemoryUsed() - GetSystemResourceUsage();
144 // personal heap is implemented.
145 return GetTotalPhysicalMemoryUsed();
146} 142}
147 143
148void Process::RegisterThread(const Thread* thread) { 144void 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:
173 return system_resource_size; 173 return system_resource_size;
174 } 174 }
175 175
176 /// Gets the amount of secure memory currently in use for memory management.
177 u32 GetSystemResourceUsage() const {
178 // On hardware, this returns the amount of system resource memory that has
179 // been used by the kernel. This is problematic for Yuzu to emulate, because
180 // system resource memory is used for page tables -- and yuzu doesn't really
181 // have a way to calculate how much memory is required for page tables for
182 // the current process at any given time.
183 // TODO: Is this even worth implementing? Games may retrieve this value via
184 // an SDK function that gets used + available system resource size for debug
185 // or diagnostic purposes. However, it seems unlikely that a game would make
186 // decisions based on how much system memory is dedicated to its page tables.
187 // Is returning a value other than zero wise?
188 return 0;
189 }
190
176 /// Whether this process is an AArch64 or AArch32 process. 191 /// Whether this process is an AArch64 or AArch32 process.
177 bool Is64BitProcess() const { 192 bool Is64BitProcess() const {
178 return is_64bit_process; 193 return is_64bit_process;
@@ -197,15 +212,15 @@ public:
197 u64 GetTotalPhysicalMemoryAvailable() const; 212 u64 GetTotalPhysicalMemoryAvailable() const;
198 213
199 /// Retrieves the total physical memory available to this process in bytes, 214 /// Retrieves the total physical memory available to this process in bytes,
200 /// without the size of the personal heap added to it. 215 /// without the size of the personal system resource heap added to it.
201 u64 GetTotalPhysicalMemoryAvailableWithoutMmHeap() const; 216 u64 GetTotalPhysicalMemoryAvailableWithoutSystemResource() const;
202 217
203 /// Retrieves the total physical memory used by this process in bytes. 218 /// Retrieves the total physical memory used by this process in bytes.
204 u64 GetTotalPhysicalMemoryUsed() const; 219 u64 GetTotalPhysicalMemoryUsed() const;
205 220
206 /// Retrieves the total physical memory used by this process in bytes, 221 /// Retrieves the total physical memory used by this process in bytes,
207 /// without the size of the personal heap added to it. 222 /// without the size of the personal system resource heap added to it.
208 u64 GetTotalPhysicalMemoryUsedWithoutMmHeap() const; 223 u64 GetTotalPhysicalMemoryUsedWithoutSystemResource() const;
209 224
210 /// Gets the list of all threads created with this process as their owner. 225 /// Gets the list of all threads created with this process as their owner.
211 const std::list<const Thread*>& GetThreadList() const { 226 const std::list<const Thread*>& 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
737 // 5.0.0+ 737 // 5.0.0+
738 UserExceptionContextAddr = 20, 738 UserExceptionContextAddr = 20,
739 // 6.0.0+ 739 // 6.0.0+
740 TotalPhysicalMemoryAvailableWithoutMmHeap = 21, 740 TotalPhysicalMemoryAvailableWithoutSystemResource = 21,
741 TotalPhysicalMemoryUsedWithoutMmHeap = 22, 741 TotalPhysicalMemoryUsedWithoutSystemResource = 22,
742 }; 742 };
743 743
744 const auto info_id_type = static_cast<GetInfoType>(info_id); 744 const auto info_id_type = static_cast<GetInfoType>(info_id);
@@ -760,8 +760,8 @@ static ResultCode GetInfo(Core::System& system, u64* result, u64 info_id, u64 ha
760 case GetInfoType::SystemResourceUsage: 760 case GetInfoType::SystemResourceUsage:
761 case GetInfoType::TitleId: 761 case GetInfoType::TitleId:
762 case GetInfoType::UserExceptionContextAddr: 762 case GetInfoType::UserExceptionContextAddr:
763 case GetInfoType::TotalPhysicalMemoryAvailableWithoutMmHeap: 763 case GetInfoType::TotalPhysicalMemoryAvailableWithoutSystemResource:
764 case GetInfoType::TotalPhysicalMemoryUsedWithoutMmHeap: { 764 case GetInfoType::TotalPhysicalMemoryUsedWithoutSystemResource: {
765 if (info_sub_id != 0) { 765 if (info_sub_id != 0) {
766 return ERR_INVALID_ENUM_VALUE; 766 return ERR_INVALID_ENUM_VALUE;
767 } 767 }
@@ -827,17 +827,9 @@ static ResultCode GetInfo(Core::System& system, u64* result, u64 info_id, u64 ha
827 return RESULT_SUCCESS; 827 return RESULT_SUCCESS;
828 828
829 case GetInfoType::SystemResourceUsage: 829 case GetInfoType::SystemResourceUsage:
830 // On hardware, this returns the amount of system resource memory that has
831 // been used by the kernel. This is problematic for Yuzu to emulate, because
832 // system resource memory is used for page tables -- and yuzu doesn't really
833 // have a way to calculate how much memory is required for page tables for
834 // the current process at any given time.
835 // TODO: Is this even worth implementing? No game should ever use it, since
836 // the amount of remaining page table space should never be relevant except
837 // for diagnostics. Is returning a value other than zero wise?
838 LOG_WARNING(Kernel_SVC, 830 LOG_WARNING(Kernel_SVC,
839 "(STUBBED) Attempted to query system resource usage, returned 0"); 831 "(STUBBED) Attempted to query system resource usage");
840 *result = 0; 832 *result = process->GetSystemResourceUsage();
841 return RESULT_SUCCESS; 833 return RESULT_SUCCESS;
842 834
843 case GetInfoType::TitleId: 835 case GetInfoType::TitleId:
@@ -850,12 +842,12 @@ static ResultCode GetInfo(Core::System& system, u64* result, u64 info_id, u64 ha
850 *result = 0; 842 *result = 0;
851 return RESULT_SUCCESS; 843 return RESULT_SUCCESS;
852 844
853 case GetInfoType::TotalPhysicalMemoryAvailableWithoutMmHeap: 845 case GetInfoType::TotalPhysicalMemoryAvailableWithoutSystemResource:
854 *result = process->GetTotalPhysicalMemoryAvailable(); 846 *result = process->GetTotalPhysicalMemoryAvailableWithoutSystemResource();
855 return RESULT_SUCCESS; 847 return RESULT_SUCCESS;
856 848
857 case GetInfoType::TotalPhysicalMemoryUsedWithoutMmHeap: 849 case GetInfoType::TotalPhysicalMemoryUsedWithoutSystemResource:
858 *result = process->GetTotalPhysicalMemoryUsedWithoutMmHeap(); 850 *result = process->GetTotalPhysicalMemoryUsedWithoutSystemResource();
859 return RESULT_SUCCESS; 851 return RESULT_SUCCESS;
860 852
861 default: 853 default:
@@ -984,7 +976,7 @@ static ResultCode MapPhysicalMemory(Core::System& system, VAddr addr, u64 size)
984 return ERR_INVALID_MEMORY_RANGE; 976 return ERR_INVALID_MEMORY_RANGE;
985 } 977 }
986 978
987 auto* const current_process = Core::CurrentProcess(); 979 Process* const current_process = system.Kernel().CurrentProcess();
988 auto& vm_manager = current_process->VMManager(); 980 auto& vm_manager = current_process->VMManager();
989 981
990 if (current_process->GetSystemResourceSize() == 0) { 982 if (current_process->GetSystemResourceSize() == 0) {
@@ -1024,7 +1016,7 @@ static ResultCode UnmapPhysicalMemory(Core::System& system, VAddr addr, u64 size
1024 return ERR_INVALID_MEMORY_RANGE; 1016 return ERR_INVALID_MEMORY_RANGE;
1025 } 1017 }
1026 1018
1027 auto* const current_process = Core::CurrentProcess(); 1019 Process* const current_process = system.Kernel().CurrentProcess();
1028 auto& vm_manager = current_process->VMManager(); 1020 auto& vm_manager = current_process->VMManager();
1029 1021
1030 if (current_process->GetSystemResourceSize() == 0) { 1022 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) {
349 } 349 }
350 350
351 // Check that we can map the memory we want. 351 // Check that we can map the memory we want.
352 const auto res_limit = Core::CurrentProcess()->GetResourceLimit(); 352 const auto res_limit = system.CurrentProcess()->GetResourceLimit();
353 const u64 physmem_remaining = res_limit->GetMaxResourceValue(ResourceType::PhysicalMemory) - 353 const u64 physmem_remaining = res_limit->GetMaxResourceValue(ResourceType::PhysicalMemory) -
354 res_limit->GetCurrentResourceValue(ResourceType::PhysicalMemory); 354 res_limit->GetCurrentResourceValue(ResourceType::PhysicalMemory);
355 if (physmem_remaining < (size - mapped_size)) { 355 if (physmem_remaining < (size - mapped_size)) {
@@ -558,6 +558,9 @@ ResultCode VMManager::UnmapPhysicalMemory(VAddr target, u64 size) {
558 } 558 }
559 } 559 }
560 560
561 // Update mapped amount
562 physical_memory_mapped -= mapped_size;
563
561 return RESULT_SUCCESS; 564 return RESULT_SUCCESS;
562} 565}
563 566
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:
458 /// 458 ///
459 /// @note The destination address must lie within the Map region. 459 /// @note The destination address must lie within the Map region.
460 /// 460 ///
461 /// @note This function requires SystemResourceSize is non-zero, 461 /// @note This function requires that SystemResourceSize be non-zero,
462 /// however, this is just because if it were not then the 462 /// however, this is just because if it were not then the
463 /// resulting page tables could be exploited on hardware by 463 /// resulting page tables could be exploited on hardware by
464 /// a malicious program. SystemResource usage does not need 464 /// a malicious program. SystemResource usage does not need
@@ -472,7 +472,7 @@ public:
472 /// 472 ///
473 /// @note The destination address must lie within the Map region. 473 /// @note The destination address must lie within the Map region.
474 /// 474 ///
475 /// @note This function requires SystemResourceSize is non-zero, 475 /// @note This function requires that SystemResourceSize be non-zero,
476 /// however, this is just because if it were not then the 476 /// however, this is just because if it were not then the
477 /// resulting page tables could be exploited on hardware by 477 /// resulting page tables could be exploited on hardware by
478 /// a malicious program. SystemResource usage does not need 478 /// a malicious program. SystemResource usage does not need