Atmosphere/stratosphere/pm/source/pm_debug_monitor.cpp

109 lines
3.6 KiB
C++
Raw Normal View History

/*
2019-04-08 04:00:49 +02:00
* 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 <http://www.gnu.org/licenses/>.
*/
#include <switch.h>
#include <stratosphere.hpp>
#include "pm_registration.hpp"
#include "pm_resource_limits.hpp"
#include "pm_debug_monitor.hpp"
Result DebugMonitorService::GetUnknownStub(Out<u32> count, OutBuffer<u8> out_buf, u64 in_unk) {
/* This command seems stubbed. */
if (out_buf.num_elements >> 31) {
return ResultPmInvalidSize;
}
count.SetValue(0);
2019-03-29 06:39:39 +01:00
return ResultSuccess;
}
Result DebugMonitorService::GetDebugProcessIds(Out<u32> count, OutBuffer<u64> 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<u64> pid, u64 tid) {
std::scoped_lock<ProcessList &> lk(Registration::GetProcessList());
std::shared_ptr<Registration::Process> proc = Registration::GetProcessByTitleId(tid);
if (proc != nullptr) {
pid.SetValue(proc->pid);
2019-03-29 06:39:39 +01:00
return ResultSuccess;
}
return ResultPmProcessNotFound;
}
Result DebugMonitorService::EnableDebugForTitleId(Out<CopiedHandle> event, u64 tid) {
return Registration::EnableDebugForTitleId(tid, event.GetHandlePointer());
}
Result DebugMonitorService::GetApplicationProcessId(Out<u64> pid) {
std::scoped_lock<ProcessList &> lk(Registration::GetProcessList());
std::shared_ptr<Registration::Process> app_proc;
if (Registration::HasApplicationProcess(&app_proc)) {
pid.SetValue(app_proc->pid);
2019-03-29 06:39:39 +01:00
return ResultSuccess;
}
return ResultPmProcessNotFound;
}
Result DebugMonitorService::EnableDebugForApplication(Out<CopiedHandle> event) {
return Registration::EnableDebugForApplication(event.GetHandlePointer());
}
2018-09-09 08:47:15 +02:00
Result DebugMonitorService::DisableDebug(u32 which) {
return Registration::DisableDebug(which);
2018-09-09 08:47:15 +02:00
}
Result DebugMonitorService::AtmosphereGetProcessInfo(Out<CopiedHandle> proc_hand, Out<Registration::TidSid> tid_sid, u64 pid) {
auto proc = Registration::GetProcess(pid);
if (proc != nullptr) {
proc_hand.SetValue(proc->handle);
tid_sid.SetValue(proc->tid_sid);
2019-03-29 06:39:39 +01:00
return ResultSuccess;
}
return ResultPmProcessNotFound;
}
Result DebugMonitorService::AtmosphereGetCurrentLimitInfo(Out<u64> cur_val, Out<u64> lim_val, u32 category, u32 resource) {
Result rc;
if(category > ResourceLimitUtils::ResourceLimitCategory::ResourceLimitCategory_Applet) {
return ResultKernelInvalidEnumValue;
}
Handle limit_h = ResourceLimitUtils::GetResourceLimitHandleByCategory((ResourceLimitUtils::ResourceLimitCategory) category);
rc = svcGetResourceLimitCurrentValue(cur_val.GetPointer(), limit_h, (LimitableResource) resource);
if(R_FAILED(rc)) {
return rc;
}
rc = svcGetResourceLimitLimitValue(lim_val.GetPointer(), limit_h, (LimitableResource) resource);
if(R_FAILED(rc)) {
return rc;
}
2019-03-29 06:39:39 +01:00
return ResultSuccess;
}