From c45088d1cda2d0bcb6a7fb35f8c2d826728ed730 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Fri, 4 Dec 2020 18:20:56 -0800 Subject: [PATCH] kern: add support for InfoType_FreeThreadCount --- libraries/libmesosphere/source/svc/kern_svc_info.cpp | 10 ++++++++++ .../include/vapours/svc/svc_types_common.hpp | 1 + 2 files changed, 11 insertions(+) diff --git a/libraries/libmesosphere/source/svc/kern_svc_info.cpp b/libraries/libmesosphere/source/svc/kern_svc_info.cpp index adab13b27..fda723182 100644 --- a/libraries/libmesosphere/source/svc/kern_svc_info.cpp +++ b/libraries/libmesosphere/source/svc/kern_svc_info.cpp @@ -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(); } } diff --git a/libraries/libvapours/include/vapours/svc/svc_types_common.hpp b/libraries/libvapours/include/vapours/svc/svc_types_common.hpp index 26bf251ec..0630fc017 100644 --- a/libraries/libvapours/include/vapours/svc/svc_types_common.hpp +++ b/libraries/libvapours/include/vapours/svc/svc_types_common.hpp @@ -156,6 +156,7 @@ namespace ams::svc { InfoType_TotalNonSystemMemorySize = 21, InfoType_UsedNonSystemMemorySize = 22, InfoType_IsApplication = 23, + InfoType_FreeThreadCount = 24, InfoType_MesosphereMeta = 65000,