/* * Copyright (c) 2018-2019 Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include #include #include "pm_registration.hpp" #include "pm_resource_limits.hpp" #include "pm_debug_monitor.hpp" Result DebugMonitorService::GetUnknownStub(Out count, OutBuffer out_buf, u64 in_unk) { /* This command seems stubbed. */ if (out_buf.num_elements >> 31) { return ResultPmInvalidSize; } count.SetValue(0); return ResultSuccess; } Result DebugMonitorService::GetDebugProcessIds(Out count, OutBuffer out_pids) { if (out_pids.num_elements >> 31) { return ResultPmInvalidSize; } return Registration::GetDebugProcessIds(out_pids.buffer, out_pids.num_elements, count.GetPointer()); } Result DebugMonitorService::LaunchDebugProcess(u64 pid) { return Registration::LaunchDebugProcess(pid); } Result DebugMonitorService::GetTitleProcessId(Out pid, u64 tid) { std::scoped_lock lk(Registration::GetProcessList()); std::shared_ptr proc = Registration::GetProcessByTitleId(tid); if (proc != nullptr) { pid.SetValue(proc->pid); return ResultSuccess; } return ResultPmProcessNotFound; } Result DebugMonitorService::EnableDebugForTitleId(Out event, u64 tid) { return Registration::EnableDebugForTitleId(tid, event.GetHandlePointer()); } Result DebugMonitorService::GetApplicationProcessId(Out pid) { std::scoped_lock lk(Registration::GetProcessList()); std::shared_ptr app_proc; if (Registration::HasApplicationProcess(&app_proc)) { pid.SetValue(app_proc->pid); return ResultSuccess; } return ResultPmProcessNotFound; } Result DebugMonitorService::EnableDebugForApplication(Out event) { return Registration::EnableDebugForApplication(event.GetHandlePointer()); } Result DebugMonitorService::DisableDebug(u32 which) { return Registration::DisableDebug(which); } Result DebugMonitorService::AtmosphereGetProcessInfo(Out proc_hand, Out tid_sid, u64 pid) { auto proc = Registration::GetProcess(pid); if (proc != nullptr) { proc_hand.SetValue(proc->handle); tid_sid.SetValue(proc->tid_sid); return ResultSuccess; } return ResultPmProcessNotFound; } Result DebugMonitorService::AtmosphereGetCurrentLimitInfo(Out cur_val, Out lim_val, u32 category, u32 resource) { if(category > ResourceLimitUtils::ResourceLimitCategory::ResourceLimitCategory_Applet) { return ResultKernelInvalidEnumValue; } Handle limit_h = ResourceLimitUtils::GetResourceLimitHandleByCategory((ResourceLimitUtils::ResourceLimitCategory) category); R_TRY(svcGetResourceLimitCurrentValue(cur_val.GetPointer(), limit_h, (LimitableResource) resource)); R_TRY(svcGetResourceLimitLimitValue(lim_val.GetPointer(), limit_h, (LimitableResource) resource)); return ResultSuccess; }