diff --git a/stratosphere/pm/source/pm_debug_monitor.cpp b/stratosphere/pm/source/pm_debug_monitor.cpp index 95362c1ea..8555fc8dd 100644 --- a/stratosphere/pm/source/pm_debug_monitor.cpp +++ b/stratosphere/pm/source/pm_debug_monitor.cpp @@ -17,6 +17,7 @@ #include #include #include "pm_registration.hpp" +#include "pm_resource_limits.hpp" #include "pm_debug_monitor.hpp" Result DebugMonitorService::dispatch(IpcParsedCommand &r, IpcCommand &out_c, u64 cmd_id, u8 *pointer_buffer, size_t pointer_buffer_size) { @@ -49,6 +50,9 @@ Result DebugMonitorService::dispatch(IpcParsedCommand &r, IpcCommand &out_c, u64 case Dmnt_Cmd_5X_AtmosphereGetProcessHandle: rc = WrapIpcCommandImpl<&DebugMonitorService::get_process_handle>(this, r, out_c, pointer_buffer, pointer_buffer_size); break; + case Dmnt_Cmd_5X_AtmosphereGetCurrentLimitInfo: + rc = WrapIpcCommandImpl<&DebugMonitorService::get_current_limit_info>(this, r, out_c, pointer_buffer, pointer_buffer_size); + break; default: break; } @@ -78,6 +82,9 @@ Result DebugMonitorService::dispatch(IpcParsedCommand &r, IpcCommand &out_c, u64 case Dmnt_Cmd_AtmosphereGetProcessHandle: rc = WrapIpcCommandImpl<&DebugMonitorService::get_process_handle>(this, r, out_c, pointer_buffer, pointer_buffer_size); break; + case Dmnt_Cmd_AtmosphereGetCurrentLimitInfo: + rc = WrapIpcCommandImpl<&DebugMonitorService::get_current_limit_info>(this, r, out_c, pointer_buffer, pointer_buffer_size); + break; default: break; } @@ -158,3 +165,27 @@ std::tuple DebugMonitorService::get_process_handle(u64 pid } return {0, proc->handle}; } + +std::tuple DebugMonitorService::get_current_limit_info(u32 category, u32 resource) { + if(category > ResourceLimitUtils::ResourceLimitCategory::ResourceLimitCategory_Applet) { + return {0xf001, 0, 0}; + } + + Handle limit_h = ResourceLimitUtils::GetResourceLimitHandleByCategory((ResourceLimitUtils::ResourceLimitCategory) category); + + uint64_t current_value, limit_value; + + Result r; + + r = svcGetResourceLimitCurrentValue(¤t_value, limit_h, (LimitableResource) resource); + if(R_FAILED(r)) { + return {r, 0, 0}; + } + + r = svcGetResourceLimitLimitValue(&limit_value, limit_h, (LimitableResource) resource); + if(R_FAILED(r)) { + return {r, 0, 0}; + } + + return {0, current_value, limit_value}; +} diff --git a/stratosphere/pm/source/pm_debug_monitor.hpp b/stratosphere/pm/source/pm_debug_monitor.hpp index ee6c66b12..24c2d7839 100644 --- a/stratosphere/pm/source/pm_debug_monitor.hpp +++ b/stratosphere/pm/source/pm_debug_monitor.hpp @@ -29,7 +29,8 @@ enum DmntCmd { Dmnt_Cmd_GetApplicationProcessId = 5, Dmnt_Cmd_EnableDebugForApplication = 6, - Dmnt_Cmd_AtmosphereGetProcessHandle = 65000 + Dmnt_Cmd_AtmosphereGetProcessHandle = 65000, + Dmnt_Cmd_AtmosphereGetCurrentLimitInfo = 65001, }; enum DmntCmd_5X { @@ -42,7 +43,8 @@ enum DmntCmd_5X { Dmnt_Cmd_6X_DisableDebug = 6, - Dmnt_Cmd_5X_AtmosphereGetProcessHandle = 65000 + Dmnt_Cmd_5X_AtmosphereGetProcessHandle = 65000, + Dmnt_Cmd_5X_AtmosphereGetCurrentLimitInfo = 65001, }; class DebugMonitorService final : public IServiceObject { @@ -67,4 +69,5 @@ class DebugMonitorService final : public IServiceObject { /* Atmosphere commands. */ std::tuple get_process_handle(u64 pid); + std::tuple get_current_limit_info(u32 category, u32 resource); }; diff --git a/stratosphere/pm/source/pm_resource_limits.cpp b/stratosphere/pm/source/pm_resource_limits.cpp index 97c699221..e0d729075 100644 --- a/stratosphere/pm/source/pm_resource_limits.cpp +++ b/stratosphere/pm/source/pm_resource_limits.cpp @@ -224,6 +224,10 @@ Handle ResourceLimitUtils::GetResourceLimitHandle(u16 application_type) { } } +Handle ResourceLimitUtils::GetResourceLimitHandleByCategory(ResourceLimitCategory category) { + return g_resource_limit_handles[category]; +} + Result ResourceLimitUtils::BoostSystemMemoryResourceLimit(u64 boost_size) { Result rc = 0; if (boost_size > g_memory_resource_limits[g_memory_limit_type][ResourceLimitCategory_Application]) { diff --git a/stratosphere/pm/source/pm_resource_limits.hpp b/stratosphere/pm/source/pm_resource_limits.hpp index 36d46fcd0..c06706e02 100644 --- a/stratosphere/pm/source/pm_resource_limits.hpp +++ b/stratosphere/pm/source/pm_resource_limits.hpp @@ -28,5 +28,6 @@ class ResourceLimitUtils { static void InitializeLimits(); static void EnsureApplicationResourcesAvailable(); static Handle GetResourceLimitHandle(u16 application_type); + static Handle GetResourceLimitHandleByCategory(ResourceLimitCategory category); static Result BoostSystemMemoryResourceLimit(u64 boost_size); }; \ No newline at end of file