kern: add support for InfoType_FreeThreadCount

This commit is contained in:
Michael Scire 2020-12-04 18:20:56 -08:00
parent 7336dc2b7a
commit c45088d1cd
2 changed files with 11 additions and 0 deletions

View File

@ -59,6 +59,7 @@ namespace ams::kern::svc {
case ams::svc::InfoType_TotalNonSystemMemorySize:
case ams::svc::InfoType_UsedNonSystemMemorySize:
case ams::svc::InfoType_IsApplication:
case ams::svc::InfoType_FreeThreadCount:
{
/* These info types don't support non-zero subtypes. */
R_UNLESS(info_subtype == 0, svc::ResultInvalidCombination());
@ -125,6 +126,15 @@ namespace ams::kern::svc {
case ams::svc::InfoType_IsApplication:
*out = process->IsApplication();
break;
case ams::svc::InfoType_FreeThreadCount:
if (KResourceLimit *resource_limit = process->GetResourceLimit(); resource_limit != nullptr) {
const auto current_value = resource_limit->GetCurrentValue(ams::svc::LimitableResource_ThreadCountMax);
const auto limit_value = resource_limit->GetLimitValue(ams::svc::LimitableResource_ThreadCountMax);
*out = limit_value - current_value;
} else {
*out = 0;
}
break;
MESOSPHERE_UNREACHABLE_DEFAULT_CASE();
}
}

View File

@ -156,6 +156,7 @@ namespace ams::svc {
InfoType_TotalNonSystemMemorySize = 21,
InfoType_UsedNonSystemMemorySize = 22,
InfoType_IsApplication = 23,
InfoType_FreeThreadCount = 24,
InfoType_MesosphereMeta = 65000,