mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2024-11-05 19:51:45 +00:00
pm: add AtmosphereGetCurrentLimitInfo command to pm:dmnt
This commit is contained in:
parent
ca0e41e8a0
commit
2d6aba7a70
4 changed files with 41 additions and 2 deletions
|
@ -17,6 +17,7 @@
|
|||
#include <switch.h>
|
||||
#include <stratosphere.hpp>
|
||||
#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<Result, CopiedHandle> DebugMonitorService::get_process_handle(u64 pid
|
|||
}
|
||||
return {0, proc->handle};
|
||||
}
|
||||
|
||||
std::tuple<Result, u64, u64> 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};
|
||||
}
|
||||
|
|
|
@ -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<Result, CopiedHandle> get_process_handle(u64 pid);
|
||||
std::tuple<Result, u64, u64> get_current_limit_info(u32 category, u32 resource);
|
||||
};
|
||||
|
|
|
@ -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]) {
|
||||
|
|
|
@ -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);
|
||||
};
|
Loading…
Reference in a new issue