summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Lioncash2018-11-26 19:14:29 -0500
committerGravatar Lioncash2018-11-26 21:23:11 -0500
commiteb5596044dfb3ee862ca239f9cb08eb4b9b3903f (patch)
tree6407a55837956cbf6f3c7cac114bceea903d4203 /src
parentsvc: Implement svcGetResourceLimitLimitValue() (diff)
downloadyuzu-eb5596044dfb3ee862ca239f9cb08eb4b9b3903f.tar.gz
yuzu-eb5596044dfb3ee862ca239f9cb08eb4b9b3903f.tar.xz
yuzu-eb5596044dfb3ee862ca239f9cb08eb4b9b3903f.zip
svc: Implement svcGetResourceLimitCurrentValue()
This kernel service function is essentially the exact same as svcGetResourceLimitLimitValue(), with the only difference being that it retrieves the current value for a given resource category using the provided resource limit handle, rather than retrieving the limiting value of that resource limit instance. Given these are exactly the same and only differ on returned values, we can extract the existing code for svcGetResourceLimitLimitValue() to handle both values.
Diffstat (limited to 'src')
-rw-r--r--src/core/hle/kernel/svc.cpp65
1 files changed, 49 insertions, 16 deletions
diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp
index 5e604411b..9d1b000b5 100644
--- a/src/core/hle/kernel/svc.cpp
+++ b/src/core/hle/kernel/svc.cpp
@@ -105,6 +105,38 @@ ResultCode MapUnmapMemorySanityChecks(const VMManager& vm_manager, VAddr dst_add
105 105
106 return RESULT_SUCCESS; 106 return RESULT_SUCCESS;
107} 107}
108
109enum class ResourceLimitValueType {
110 CurrentValue,
111 LimitValue,
112};
113
114ResultVal<s64> RetrieveResourceLimitValue(Handle resource_limit, u32 resource_type,
115 ResourceLimitValueType value_type) {
116 const auto type = static_cast<ResourceType>(resource_type);
117 if (!IsValidResourceType(type)) {
118 LOG_ERROR(Kernel_SVC, "Invalid resource limit type: '{}'", resource_type);
119 return ERR_INVALID_ENUM_VALUE;
120 }
121
122 const auto& kernel = Core::System::GetInstance().Kernel();
123 const auto* const current_process = kernel.CurrentProcess();
124 ASSERT(current_process != nullptr);
125
126 const auto resource_limit_object =
127 current_process->GetHandleTable().Get<ResourceLimit>(resource_limit);
128 if (!resource_limit_object) {
129 LOG_ERROR(Kernel_SVC, "Handle to non-existent resource limit instance used. Handle={:08X}",
130 resource_limit);
131 return ERR_INVALID_HANDLE;
132 }
133
134 if (value_type == ResourceLimitValueType::CurrentValue) {
135 return MakeResult(resource_limit_object->GetCurrentResourceValue(type));
136 }
137
138 return MakeResult(resource_limit_object->GetMaxResourceValue(type));
139}
108} // Anonymous namespace 140} // Anonymous namespace
109 141
110/// Set the process heap to a given Size. It can both extend and shrink the heap. 142/// Set the process heap to a given Size. It can both extend and shrink the heap.
@@ -1368,26 +1400,27 @@ static ResultCode GetResourceLimitLimitValue(u64* out_value, Handle resource_lim
1368 u32 resource_type) { 1400 u32 resource_type) {
1369 LOG_DEBUG(Kernel_SVC, "called. Handle={:08X}, Resource type={}", resource_limit, resource_type); 1401 LOG_DEBUG(Kernel_SVC, "called. Handle={:08X}, Resource type={}", resource_limit, resource_type);
1370 1402
1371 const auto type = static_cast<ResourceType>(resource_type); 1403 const auto limit_value = RetrieveResourceLimitValue(resource_limit, resource_type,
1372 if (!IsValidResourceType(type)) { 1404 ResourceLimitValueType::LimitValue);
1373 LOG_ERROR(Kernel_SVC, "Invalid resource limit type: '{}'.", resource_type); 1405 if (limit_value.Failed()) {
1374 return ERR_INVALID_ENUM_VALUE; 1406 return limit_value.Code();
1375 } 1407 }
1376 1408
1377 const auto& kernel = Core::System::GetInstance().Kernel(); 1409 *out_value = static_cast<u64>(*limit_value);
1378 const auto* const current_process = kernel.CurrentProcess(); 1410 return RESULT_SUCCESS;
1379 ASSERT(current_process != nullptr); 1411}
1380 1412
1381 const auto resource_limit_object = 1413static ResultCode GetResourceLimitCurrentValue(u64* out_value, Handle resource_limit,
1382 current_process->GetHandleTable().Get<ResourceLimit>(resource_limit); 1414 u32 resource_type) {
1383 if (!resource_limit_object) { 1415 LOG_DEBUG(Kernel_SVC, "called. Handle={:08X}, Resource type={}", resource_limit, resource_type);
1384 LOG_ERROR(Kernel_SVC, "Handle to non-existent resource limit instance used. Handle={:08X}", 1416
1385 resource_limit); 1417 const auto current_value = RetrieveResourceLimitValue(resource_limit, resource_type,
1386 return ERR_INVALID_HANDLE; 1418 ResourceLimitValueType::CurrentValue);
1419 if (current_value.Failed()) {
1420 return current_value.Code();
1387 } 1421 }
1388 1422
1389 const s64 limit_value = resource_limit_object->GetMaxResourceValue(type); 1423 *out_value = static_cast<u64>(*current_value);
1390 *out_value = static_cast<u64>(limit_value);
1391 return RESULT_SUCCESS; 1424 return RESULT_SUCCESS;
1392} 1425}
1393 1426
@@ -1451,7 +1484,7 @@ static const FunctionDef SVC_Table[] = {
1451 {0x2E, nullptr, "GetFutureThreadInfo"}, 1484 {0x2E, nullptr, "GetFutureThreadInfo"},
1452 {0x2F, nullptr, "GetLastThreadInfo"}, 1485 {0x2F, nullptr, "GetLastThreadInfo"},
1453 {0x30, SvcWrap<GetResourceLimitLimitValue>, "GetResourceLimitLimitValue"}, 1486 {0x30, SvcWrap<GetResourceLimitLimitValue>, "GetResourceLimitLimitValue"},
1454 {0x31, nullptr, "GetResourceLimitCurrentValue"}, 1487 {0x31, SvcWrap<GetResourceLimitCurrentValue>, "GetResourceLimitCurrentValue"},
1455 {0x32, SvcWrap<SetThreadActivity>, "SetThreadActivity"}, 1488 {0x32, SvcWrap<SetThreadActivity>, "SetThreadActivity"},
1456 {0x33, SvcWrap<GetThreadContext>, "GetThreadContext"}, 1489 {0x33, SvcWrap<GetThreadContext>, "GetThreadContext"},
1457 {0x34, SvcWrap<WaitForAddress>, "WaitForAddress"}, 1490 {0x34, SvcWrap<WaitForAddress>, "WaitForAddress"},