2018-09-07 16:00:13 +01:00
|
|
|
/*
|
2019-04-08 03:00:49 +01:00
|
|
|
* Copyright (c) 2018-2019 Atmosphère-NX
|
2018-09-07 16:00:13 +01:00
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2018-05-07 11:45:44 +01:00
|
|
|
#include <switch.h>
|
2018-06-15 00:50:01 +01:00
|
|
|
#include <stratosphere.hpp>
|
2018-05-07 11:45:44 +01:00
|
|
|
#include "pm_registration.hpp"
|
2018-10-05 04:05:41 +01:00
|
|
|
#include "pm_resource_limits.hpp"
|
2018-05-07 11:45:44 +01:00
|
|
|
#include "pm_debug_monitor.hpp"
|
|
|
|
|
|
|
|
|
2018-10-30 00:29:35 +00:00
|
|
|
Result DebugMonitorService::GetUnknownStub(Out<u32> count, OutBuffer<u8> out_buf, u64 in_unk) {
|
|
|
|
/* This command seems stubbed. */
|
|
|
|
if (out_buf.num_elements >> 31) {
|
2019-03-28 22:16:36 +00:00
|
|
|
return ResultPmInvalidSize;
|
2018-05-07 11:45:44 +01:00
|
|
|
}
|
2018-10-30 00:29:35 +00:00
|
|
|
count.SetValue(0);
|
2019-03-29 05:39:39 +00:00
|
|
|
return ResultSuccess;
|
2018-05-07 11:45:44 +01:00
|
|
|
}
|
|
|
|
|
2018-10-30 00:29:35 +00:00
|
|
|
Result DebugMonitorService::GetDebugProcessIds(Out<u32> count, OutBuffer<u64> out_pids) {
|
2018-05-07 11:45:44 +01:00
|
|
|
if (out_pids.num_elements >> 31) {
|
2019-03-28 22:16:36 +00:00
|
|
|
return ResultPmInvalidSize;
|
2018-05-07 11:45:44 +01:00
|
|
|
}
|
2018-10-30 00:29:35 +00:00
|
|
|
return Registration::GetDebugProcessIds(out_pids.buffer, out_pids.num_elements, count.GetPointer());
|
2018-05-07 11:45:44 +01:00
|
|
|
}
|
|
|
|
|
2018-10-30 00:29:35 +00:00
|
|
|
Result DebugMonitorService::LaunchDebugProcess(u64 pid) {
|
|
|
|
return Registration::LaunchDebugProcess(pid);
|
2018-05-07 11:45:44 +01:00
|
|
|
}
|
|
|
|
|
2018-10-30 00:29:35 +00:00
|
|
|
Result DebugMonitorService::GetTitleProcessId(Out<u64> pid, u64 tid) {
|
2019-03-26 00:12:19 +00:00
|
|
|
std::scoped_lock<ProcessList &> lk(Registration::GetProcessList());
|
2018-05-07 11:45:44 +01:00
|
|
|
|
2018-06-15 07:47:07 +01:00
|
|
|
std::shared_ptr<Registration::Process> proc = Registration::GetProcessByTitleId(tid);
|
|
|
|
if (proc != nullptr) {
|
2018-10-30 00:29:35 +00:00
|
|
|
pid.SetValue(proc->pid);
|
2019-03-29 05:39:39 +00:00
|
|
|
return ResultSuccess;
|
2018-05-07 11:45:44 +01:00
|
|
|
}
|
2019-03-28 22:16:36 +00:00
|
|
|
return ResultPmProcessNotFound;
|
2018-05-07 11:45:44 +01:00
|
|
|
}
|
|
|
|
|
2018-10-30 00:29:35 +00:00
|
|
|
Result DebugMonitorService::EnableDebugForTitleId(Out<CopiedHandle> event, u64 tid) {
|
|
|
|
return Registration::EnableDebugForTitleId(tid, event.GetHandlePointer());
|
2018-05-07 11:45:44 +01:00
|
|
|
}
|
|
|
|
|
2018-10-30 00:29:35 +00:00
|
|
|
Result DebugMonitorService::GetApplicationProcessId(Out<u64> pid) {
|
2019-03-26 00:12:19 +00:00
|
|
|
std::scoped_lock<ProcessList &> lk(Registration::GetProcessList());
|
2018-05-07 11:45:44 +01:00
|
|
|
|
2018-06-15 07:47:07 +01:00
|
|
|
std::shared_ptr<Registration::Process> app_proc;
|
2018-05-07 11:45:44 +01:00
|
|
|
if (Registration::HasApplicationProcess(&app_proc)) {
|
2018-10-30 00:29:35 +00:00
|
|
|
pid.SetValue(app_proc->pid);
|
2019-03-29 05:39:39 +00:00
|
|
|
return ResultSuccess;
|
2018-05-07 11:45:44 +01:00
|
|
|
}
|
2019-03-28 22:16:36 +00:00
|
|
|
return ResultPmProcessNotFound;
|
2018-05-07 11:45:44 +01:00
|
|
|
}
|
|
|
|
|
2018-10-30 00:29:35 +00:00
|
|
|
Result DebugMonitorService::EnableDebugForApplication(Out<CopiedHandle> event) {
|
|
|
|
return Registration::EnableDebugForApplication(event.GetHandlePointer());
|
2018-05-07 11:45:44 +01:00
|
|
|
}
|
2018-06-08 07:32:45 +01:00
|
|
|
|
2018-09-09 07:47:15 +01:00
|
|
|
|
2018-10-30 00:29:35 +00:00
|
|
|
Result DebugMonitorService::DisableDebug(u32 which) {
|
|
|
|
return Registration::DisableDebug(which);
|
2018-09-09 07:47:15 +01:00
|
|
|
}
|
|
|
|
|
2019-03-04 14:55:37 +00:00
|
|
|
Result DebugMonitorService::AtmosphereGetProcessInfo(Out<CopiedHandle> proc_hand, Out<Registration::TidSid> tid_sid, u64 pid) {
|
2018-10-30 00:29:35 +00:00
|
|
|
auto proc = Registration::GetProcess(pid);
|
2019-03-04 14:55:37 +00:00
|
|
|
if (proc != nullptr) {
|
2018-10-30 00:29:35 +00:00
|
|
|
proc_hand.SetValue(proc->handle);
|
2019-03-04 14:55:37 +00:00
|
|
|
tid_sid.SetValue(proc->tid_sid);
|
2019-03-29 05:39:39 +00:00
|
|
|
return ResultSuccess;
|
2018-06-08 07:32:45 +01:00
|
|
|
}
|
2019-03-28 22:16:36 +00:00
|
|
|
return ResultPmProcessNotFound;
|
2018-06-08 07:32:45 +01:00
|
|
|
}
|
2018-10-05 04:05:41 +01:00
|
|
|
|
2018-10-30 00:29:35 +00:00
|
|
|
Result DebugMonitorService::AtmosphereGetCurrentLimitInfo(Out<u64> cur_val, Out<u64> lim_val, u32 category, u32 resource) {
|
|
|
|
Result rc;
|
2018-10-05 04:05:41 +01:00
|
|
|
if(category > ResourceLimitUtils::ResourceLimitCategory::ResourceLimitCategory_Applet) {
|
2019-03-28 23:57:18 +00:00
|
|
|
return ResultKernelInvalidEnumValue;
|
2018-10-05 04:05:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Handle limit_h = ResourceLimitUtils::GetResourceLimitHandleByCategory((ResourceLimitUtils::ResourceLimitCategory) category);
|
|
|
|
|
2018-10-30 00:29:35 +00:00
|
|
|
rc = svcGetResourceLimitCurrentValue(cur_val.GetPointer(), limit_h, (LimitableResource) resource);
|
|
|
|
if(R_FAILED(rc)) {
|
|
|
|
return rc;
|
2018-10-05 04:05:41 +01:00
|
|
|
}
|
|
|
|
|
2018-10-30 00:29:35 +00:00
|
|
|
rc = svcGetResourceLimitLimitValue(lim_val.GetPointer(), limit_h, (LimitableResource) resource);
|
|
|
|
if(R_FAILED(rc)) {
|
|
|
|
return rc;
|
2018-10-05 04:05:41 +01:00
|
|
|
}
|
|
|
|
|
2019-03-29 05:39:39 +00:00
|
|
|
return ResultSuccess;
|
2018-10-05 04:05:41 +01:00
|
|
|
}
|