mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2025-06-01 07:18:22 -04:00
pm: update for libstratosphere refactor
This commit is contained in:
parent
9a8c70ed68
commit
887b4e0275
17 changed files with 229 additions and 526 deletions
|
@ -20,172 +20,88 @@
|
|||
#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) {
|
||||
Result rc = 0xF601;
|
||||
if (kernelAbove500()) {
|
||||
switch ((DmntCmd_5X)cmd_id) {
|
||||
case Dmnt_Cmd_5X_GetDebugProcessIds:
|
||||
rc = WrapIpcCommandImpl<&DebugMonitorService::get_debug_process_ids>(this, r, out_c, pointer_buffer, pointer_buffer_size);
|
||||
break;
|
||||
case Dmnt_Cmd_5X_LaunchDebugProcess:
|
||||
rc = WrapIpcCommandImpl<&DebugMonitorService::launch_debug_process>(this, r, out_c, pointer_buffer, pointer_buffer_size);
|
||||
break;
|
||||
case Dmnt_Cmd_5X_GetTitleProcessId:
|
||||
rc = WrapIpcCommandImpl<&DebugMonitorService::get_title_process_id>(this, r, out_c, pointer_buffer, pointer_buffer_size);
|
||||
break;
|
||||
case Dmnt_Cmd_5X_EnableDebugForTitleId:
|
||||
rc = WrapIpcCommandImpl<&DebugMonitorService::enable_debug_for_tid>(this, r, out_c, pointer_buffer, pointer_buffer_size);
|
||||
break;
|
||||
case Dmnt_Cmd_5X_GetApplicationProcessId:
|
||||
rc = WrapIpcCommandImpl<&DebugMonitorService::get_application_process_id>(this, r, out_c, pointer_buffer, pointer_buffer_size);
|
||||
break;
|
||||
case Dmnt_Cmd_5X_EnableDebugForApplication:
|
||||
rc = WrapIpcCommandImpl<&DebugMonitorService::enable_debug_for_application>(this, r, out_c, pointer_buffer, pointer_buffer_size);
|
||||
break;
|
||||
case Dmnt_Cmd_6X_DisableDebug:
|
||||
if (kernelAbove600()) {
|
||||
rc = WrapIpcCommandImpl<&DebugMonitorService::disable_debug>(this, r, out_c, pointer_buffer, pointer_buffer_size);
|
||||
}
|
||||
break;
|
||||
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;
|
||||
}
|
||||
} else {
|
||||
switch ((DmntCmd)cmd_id) {
|
||||
case Dmnt_Cmd_GetUnknownStub:
|
||||
rc = WrapIpcCommandImpl<&DebugMonitorService::get_unknown_stub>(this, r, out_c, pointer_buffer, pointer_buffer_size);
|
||||
break;
|
||||
case Dmnt_Cmd_GetDebugProcessIds:
|
||||
rc = WrapIpcCommandImpl<&DebugMonitorService::get_debug_process_ids>(this, r, out_c, pointer_buffer, pointer_buffer_size);
|
||||
break;
|
||||
case Dmnt_Cmd_LaunchDebugProcess:
|
||||
rc = WrapIpcCommandImpl<&DebugMonitorService::launch_debug_process>(this, r, out_c, pointer_buffer, pointer_buffer_size);
|
||||
break;
|
||||
case Dmnt_Cmd_GetTitleProcessId:
|
||||
rc = WrapIpcCommandImpl<&DebugMonitorService::get_title_process_id>(this, r, out_c, pointer_buffer, pointer_buffer_size);
|
||||
break;
|
||||
case Dmnt_Cmd_EnableDebugForTitleId:
|
||||
rc = WrapIpcCommandImpl<&DebugMonitorService::enable_debug_for_tid>(this, r, out_c, pointer_buffer, pointer_buffer_size);
|
||||
break;
|
||||
case Dmnt_Cmd_GetApplicationProcessId:
|
||||
rc = WrapIpcCommandImpl<&DebugMonitorService::get_application_process_id>(this, r, out_c, pointer_buffer, pointer_buffer_size);
|
||||
break;
|
||||
case Dmnt_Cmd_EnableDebugForApplication:
|
||||
rc = WrapIpcCommandImpl<&DebugMonitorService::enable_debug_for_application>(this, r, out_c, pointer_buffer, pointer_buffer_size);
|
||||
break;
|
||||
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;
|
||||
}
|
||||
|
||||
Result DebugMonitorService::GetUnknownStub(Out<u32> count, OutBuffer<u8> out_buf, u64 in_unk) {
|
||||
/* This command seems stubbed. */
|
||||
if (out_buf.num_elements >> 31) {
|
||||
return 0xC0F;
|
||||
}
|
||||
return rc;
|
||||
count.SetValue(0);
|
||||
return 0x0;
|
||||
}
|
||||
|
||||
Result DebugMonitorService::handle_deferred() {
|
||||
/* This service is never deferrable. */
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
std::tuple<Result, u32> DebugMonitorService::get_unknown_stub(u64 unknown, OutBuffer<u8> out_unknown) {
|
||||
/* This command seem stubbed on retail. */
|
||||
if (out_unknown.num_elements >> 31) {
|
||||
return {0xC0F, 0};
|
||||
}
|
||||
return {0x0, 0};
|
||||
}
|
||||
|
||||
std::tuple<Result, u32> DebugMonitorService::get_debug_process_ids(OutBuffer<u64> out_pids) {
|
||||
u32 num_out = 0;
|
||||
Result rc;
|
||||
Result DebugMonitorService::GetDebugProcessIds(Out<u32> count, OutBuffer<u64> out_pids) {
|
||||
if (out_pids.num_elements >> 31) {
|
||||
return {0xC0F, 0};
|
||||
return 0xC0F;
|
||||
}
|
||||
rc = Registration::GetDebugProcessIds(out_pids.buffer, out_pids.num_elements, &num_out);
|
||||
return {rc, num_out};
|
||||
return Registration::GetDebugProcessIds(out_pids.buffer, out_pids.num_elements, count.GetPointer());
|
||||
}
|
||||
|
||||
std::tuple<Result> DebugMonitorService::launch_debug_process(u64 pid) {
|
||||
return {Registration::LaunchDebugProcess(pid)};
|
||||
Result DebugMonitorService::LaunchDebugProcess(u64 pid) {
|
||||
return Registration::LaunchDebugProcess(pid);
|
||||
}
|
||||
|
||||
std::tuple<Result, u64> DebugMonitorService::get_title_process_id(u64 tid) {
|
||||
Result DebugMonitorService::GetTitleProcessId(Out<u64> pid, u64 tid) {
|
||||
auto auto_lock = Registration::GetProcessListUniqueLock();
|
||||
|
||||
std::shared_ptr<Registration::Process> proc = Registration::GetProcessByTitleId(tid);
|
||||
if (proc != nullptr) {
|
||||
return {0, proc->pid};
|
||||
} else {
|
||||
return {0x20F, 0};
|
||||
pid.SetValue(proc->pid);
|
||||
return 0;
|
||||
}
|
||||
return 0x20F;
|
||||
}
|
||||
|
||||
std::tuple<Result, CopiedHandle> DebugMonitorService::enable_debug_for_tid(u64 tid) {
|
||||
Handle h = 0;
|
||||
Result rc = Registration::EnableDebugForTitleId(tid, &h);
|
||||
return {rc, h};
|
||||
Result DebugMonitorService::EnableDebugForTitleId(Out<CopiedHandle> event, u64 tid) {
|
||||
return Registration::EnableDebugForTitleId(tid, event.GetHandlePointer());
|
||||
}
|
||||
|
||||
std::tuple<Result, u64> DebugMonitorService::get_application_process_id() {
|
||||
Result DebugMonitorService::GetApplicationProcessId(Out<u64> pid) {
|
||||
auto auto_lock = Registration::GetProcessListUniqueLock();
|
||||
|
||||
std::shared_ptr<Registration::Process> app_proc;
|
||||
if (Registration::HasApplicationProcess(&app_proc)) {
|
||||
return {0, app_proc->pid};
|
||||
pid.SetValue(app_proc->pid);
|
||||
return 0x0;
|
||||
}
|
||||
return {0x20F, 0};
|
||||
return 0x20F;
|
||||
}
|
||||
|
||||
std::tuple<Result, CopiedHandle> DebugMonitorService::enable_debug_for_application() {
|
||||
Handle h = 0;
|
||||
Result rc = Registration::EnableDebugForApplication(&h);
|
||||
return {rc, h};
|
||||
Result DebugMonitorService::EnableDebugForApplication(Out<CopiedHandle> event) {
|
||||
return Registration::EnableDebugForApplication(event.GetHandlePointer());
|
||||
}
|
||||
|
||||
|
||||
std::tuple<Result> DebugMonitorService::disable_debug(u32 which) {
|
||||
return {Registration::DisableDebug(which)};
|
||||
Result DebugMonitorService::DisableDebug(u32 which) {
|
||||
return Registration::DisableDebug(which);
|
||||
}
|
||||
|
||||
std::tuple<Result, CopiedHandle> DebugMonitorService::get_process_handle(u64 pid) {
|
||||
std::shared_ptr<Registration::Process> proc = Registration::GetProcess(pid);
|
||||
if(proc == NULL) {
|
||||
return {0x20F, 0};
|
||||
Result DebugMonitorService::AtmosphereGetProcessHandle(Out<CopiedHandle> proc_hand, u64 pid) {
|
||||
auto proc = Registration::GetProcess(pid);
|
||||
if(proc != nullptr) {
|
||||
proc_hand.SetValue(proc->handle);
|
||||
return 0;
|
||||
}
|
||||
return {0, proc->handle};
|
||||
return 0x20F;
|
||||
}
|
||||
|
||||
std::tuple<Result, u64, u64> DebugMonitorService::get_current_limit_info(u32 category, u32 resource) {
|
||||
Result DebugMonitorService::AtmosphereGetCurrentLimitInfo(Out<u64> cur_val, Out<u64> lim_val, u32 category, u32 resource) {
|
||||
Result rc;
|
||||
if(category > ResourceLimitUtils::ResourceLimitCategory::ResourceLimitCategory_Applet) {
|
||||
return {0xf001, 0, 0};
|
||||
return 0xF001;
|
||||
}
|
||||
|
||||
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};
|
||||
rc = svcGetResourceLimitCurrentValue(cur_val.GetPointer(), limit_h, (LimitableResource) resource);
|
||||
if(R_FAILED(rc)) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
r = svcGetResourceLimitLimitValue(&limit_value, limit_h, (LimitableResource) resource);
|
||||
if(R_FAILED(r)) {
|
||||
return {r, 0, 0};
|
||||
rc = svcGetResourceLimitLimitValue(lim_val.GetPointer(), limit_h, (LimitableResource) resource);
|
||||
if(R_FAILED(rc)) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
return {0, current_value, limit_value};
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue