diff options
| author | 2018-11-26 19:51:09 -0500 | |
|---|---|---|
| committer | 2018-11-26 21:23:15 -0500 | |
| commit | 5905162e364abe8312cd95dd04555aaefcfc2293 (patch) | |
| tree | 6b2b4fe4bbfa474e9210fe97f057df443c56d541 /src/core/hle/kernel/svc.cpp | |
| parent | svc: Implement svcGetResourceLimitCurrentValue() (diff) | |
| download | yuzu-5905162e364abe8312cd95dd04555aaefcfc2293.tar.gz yuzu-5905162e364abe8312cd95dd04555aaefcfc2293.tar.xz yuzu-5905162e364abe8312cd95dd04555aaefcfc2293.zip | |
svc: Implement svcSetResourceLimitLimitValue()
The opposite of the getter functions, this function sets the limit value
for a particular ResourceLimit resource category, with the restriction
that the new limit value must be equal to or greater than the current
resource value. If this is violated, then ERR_INVALID_STATE is returned.
e.g.
Assume:
current[Events] = 10;
limit[Events] = 20;
a call to this service function lowering the limit value to 10 would be
fine, however, attempting to lower it to 9 in this case would cause an
invalid state error.
Diffstat (limited to 'src/core/hle/kernel/svc.cpp')
| -rw-r--r-- | src/core/hle/kernel/svc.cpp | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp index 9d1b000b5..1f19d5576 100644 --- a/src/core/hle/kernel/svc.cpp +++ b/src/core/hle/kernel/svc.cpp | |||
| @@ -1424,6 +1424,41 @@ static ResultCode GetResourceLimitCurrentValue(u64* out_value, Handle resource_l | |||
| 1424 | return RESULT_SUCCESS; | 1424 | return RESULT_SUCCESS; |
| 1425 | } | 1425 | } |
| 1426 | 1426 | ||
| 1427 | static ResultCode SetResourceLimitLimitValue(Handle resource_limit, u32 resource_type, u64 value) { | ||
| 1428 | LOG_DEBUG(Kernel_SVC, "called. Handle={:08X}, Resource type={}, Value={}", resource_limit, | ||
| 1429 | resource_type, value); | ||
| 1430 | |||
| 1431 | const auto type = static_cast<ResourceType>(resource_type); | ||
| 1432 | if (!IsValidResourceType(type)) { | ||
| 1433 | LOG_ERROR(Kernel_SVC, "Invalid resource limit type: '{}'", resource_type); | ||
| 1434 | return ERR_INVALID_ENUM_VALUE; | ||
| 1435 | } | ||
| 1436 | |||
| 1437 | auto& kernel = Core::System::GetInstance().Kernel(); | ||
| 1438 | auto* const current_process = kernel.CurrentProcess(); | ||
| 1439 | ASSERT(current_process != nullptr); | ||
| 1440 | |||
| 1441 | auto resource_limit_object = | ||
| 1442 | current_process->GetHandleTable().Get<ResourceLimit>(resource_limit); | ||
| 1443 | if (!resource_limit_object) { | ||
| 1444 | LOG_ERROR(Kernel_SVC, "Handle to non-existent resource limit instance used. Handle={:08X}", | ||
| 1445 | resource_limit); | ||
| 1446 | return ERR_INVALID_HANDLE; | ||
| 1447 | } | ||
| 1448 | |||
| 1449 | const auto set_result = resource_limit_object->SetLimitValue(type, static_cast<s64>(value)); | ||
| 1450 | if (set_result.IsError()) { | ||
| 1451 | LOG_ERROR( | ||
| 1452 | Kernel_SVC, | ||
| 1453 | "Attempted to lower resource limit ({}) for category '{}' below its current value ({})", | ||
| 1454 | resource_limit_object->GetMaxResourceValue(type), resource_type, | ||
| 1455 | resource_limit_object->GetCurrentResourceValue(type)); | ||
| 1456 | return set_result; | ||
| 1457 | } | ||
| 1458 | |||
| 1459 | return RESULT_SUCCESS; | ||
| 1460 | } | ||
| 1461 | |||
| 1427 | namespace { | 1462 | namespace { |
| 1428 | struct FunctionDef { | 1463 | struct FunctionDef { |
| 1429 | using Func = void(); | 1464 | using Func = void(); |
| @@ -1561,7 +1596,7 @@ static const FunctionDef SVC_Table[] = { | |||
| 1561 | {0x7B, nullptr, "TerminateProcess"}, | 1596 | {0x7B, nullptr, "TerminateProcess"}, |
| 1562 | {0x7C, SvcWrap<GetProcessInfo>, "GetProcessInfo"}, | 1597 | {0x7C, SvcWrap<GetProcessInfo>, "GetProcessInfo"}, |
| 1563 | {0x7D, SvcWrap<CreateResourceLimit>, "CreateResourceLimit"}, | 1598 | {0x7D, SvcWrap<CreateResourceLimit>, "CreateResourceLimit"}, |
| 1564 | {0x7E, nullptr, "SetResourceLimitLimitValue"}, | 1599 | {0x7E, SvcWrap<SetResourceLimitLimitValue>, "SetResourceLimitLimitValue"}, |
| 1565 | {0x7F, nullptr, "CallSecureMonitor"}, | 1600 | {0x7F, nullptr, "CallSecureMonitor"}, |
| 1566 | }; | 1601 | }; |
| 1567 | 1602 | ||