2018-09-07 15:00:13 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018 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/>.
|
|
|
|
*/
|
|
|
|
|
2018-05-05 00:25:26 +00:00
|
|
|
#include <switch.h>
|
2018-06-14 23:50:01 +00:00
|
|
|
#include <stratosphere.hpp>
|
2018-05-05 00:25:26 +00:00
|
|
|
#include "pm_registration.hpp"
|
2018-05-07 09:50:33 +00:00
|
|
|
#include "pm_resource_limits.hpp"
|
2018-05-05 00:25:26 +00:00
|
|
|
#include "pm_shell.hpp"
|
2018-07-27 09:23:53 +00:00
|
|
|
#include "pm_boot2.hpp"
|
2018-05-05 00:25:26 +00:00
|
|
|
|
|
|
|
static bool g_has_boot_finished = false;
|
|
|
|
|
2018-10-30 13:29:30 +00:00
|
|
|
Result ShellService::LaunchProcess(Out<u64> pid, Registration::TidSid tid_sid, u32 launch_flags) {
|
2018-10-30 00:29:35 +00:00
|
|
|
return Registration::LaunchProcessByTidSid(tid_sid, launch_flags, pid.GetPointer());
|
2018-05-05 00:25:26 +00:00
|
|
|
}
|
|
|
|
|
2018-10-30 00:29:35 +00:00
|
|
|
Result ShellService::TerminateProcessId(u64 pid) {
|
2018-07-02 14:10:57 +00:00
|
|
|
auto auto_lock = Registration::GetProcessListUniqueLock();
|
2018-05-05 01:56:59 +00:00
|
|
|
|
2018-10-30 00:29:35 +00:00
|
|
|
auto proc = Registration::GetProcess(pid);
|
|
|
|
if (proc != nullptr) {
|
|
|
|
return svcTerminateProcess(proc->handle);
|
2018-05-05 01:56:59 +00:00
|
|
|
} else {
|
2018-10-30 00:29:35 +00:00
|
|
|
return 0x20F;
|
2018-05-05 01:56:59 +00:00
|
|
|
}
|
2018-05-05 00:25:26 +00:00
|
|
|
}
|
|
|
|
|
2018-10-30 00:29:35 +00:00
|
|
|
Result ShellService::TerminateTitleId(u64 tid) {
|
2018-07-02 14:10:57 +00:00
|
|
|
auto auto_lock = Registration::GetProcessListUniqueLock();
|
2018-05-05 01:56:59 +00:00
|
|
|
|
2018-10-30 00:29:35 +00:00
|
|
|
auto proc = Registration::GetProcessByTitleId(tid);
|
2018-05-05 01:56:59 +00:00
|
|
|
if (proc != NULL) {
|
2018-10-30 00:29:35 +00:00
|
|
|
return svcTerminateProcess(proc->handle);
|
2018-05-05 01:56:59 +00:00
|
|
|
} else {
|
2018-10-30 00:29:35 +00:00
|
|
|
return 0x20F;
|
2018-05-05 01:56:59 +00:00
|
|
|
}
|
2018-05-05 00:25:26 +00:00
|
|
|
}
|
|
|
|
|
2018-10-30 00:29:35 +00:00
|
|
|
void ShellService::GetProcessWaitEvent(Out<CopiedHandle> event) {
|
|
|
|
event.SetValue(Registration::GetProcessEventHandle());
|
2018-05-05 00:25:26 +00:00
|
|
|
}
|
|
|
|
|
2018-10-30 00:29:35 +00:00
|
|
|
void ShellService::GetProcessEventType(Out<u64> type, Out<u64> pid) {
|
|
|
|
Registration::GetProcessEventType(pid.GetPointer(), type.GetPointer());
|
2018-05-05 00:25:26 +00:00
|
|
|
}
|
|
|
|
|
2018-10-30 00:29:35 +00:00
|
|
|
Result ShellService::FinalizeExitedProcess(u64 pid) {
|
2018-07-02 14:10:57 +00:00
|
|
|
auto auto_lock = Registration::GetProcessListUniqueLock();
|
2018-05-05 01:56:59 +00:00
|
|
|
|
2018-10-30 00:29:35 +00:00
|
|
|
auto proc = Registration::GetProcess(pid);
|
2018-05-05 01:56:59 +00:00
|
|
|
if (proc == NULL) {
|
2018-10-30 00:29:35 +00:00
|
|
|
return 0x20F;
|
2018-05-05 01:56:59 +00:00
|
|
|
} else if (proc->state != ProcessState_Exited) {
|
2018-10-30 00:29:35 +00:00
|
|
|
return 0x60F;
|
2018-05-05 01:56:59 +00:00
|
|
|
} else {
|
|
|
|
Registration::FinalizeExitedProcess(proc);
|
2018-10-30 00:29:35 +00:00
|
|
|
return 0x0;
|
2018-05-05 01:56:59 +00:00
|
|
|
}
|
2018-05-05 00:25:26 +00:00
|
|
|
}
|
|
|
|
|
2018-10-30 00:29:35 +00:00
|
|
|
Result ShellService::ClearProcessNotificationFlag(u64 pid) {
|
2018-07-02 14:10:57 +00:00
|
|
|
auto auto_lock = Registration::GetProcessListUniqueLock();
|
2018-05-05 01:56:59 +00:00
|
|
|
|
2018-10-30 00:29:35 +00:00
|
|
|
auto proc = Registration::GetProcess(pid);
|
2018-05-05 01:56:59 +00:00
|
|
|
if (proc != NULL) {
|
2018-07-27 08:56:24 +00:00
|
|
|
proc->flags &= ~PROCESSFLAGS_CRASHED;
|
2018-10-30 00:29:35 +00:00
|
|
|
return 0x0;
|
2018-05-05 01:56:59 +00:00
|
|
|
} else {
|
2018-10-30 00:29:35 +00:00
|
|
|
return 0x20F;
|
2018-05-05 01:56:59 +00:00
|
|
|
}
|
2018-05-05 00:25:26 +00:00
|
|
|
}
|
|
|
|
|
2018-10-30 00:29:35 +00:00
|
|
|
void ShellService::NotifyBootFinished() {
|
2018-05-05 00:25:26 +00:00
|
|
|
if (!g_has_boot_finished) {
|
|
|
|
g_has_boot_finished = true;
|
2018-07-27 09:23:53 +00:00
|
|
|
EmbeddedBoot2::Main();
|
2018-05-05 00:25:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-30 00:29:35 +00:00
|
|
|
Result ShellService::GetApplicationProcessId(Out<u64> pid) {
|
2018-07-02 14:10:57 +00:00
|
|
|
auto auto_lock = Registration::GetProcessListUniqueLock();
|
2018-05-05 01:56:59 +00:00
|
|
|
|
2018-06-15 06:47:07 +00:00
|
|
|
std::shared_ptr<Registration::Process> app_proc;
|
2018-05-05 01:56:59 +00:00
|
|
|
if (Registration::HasApplicationProcess(&app_proc)) {
|
2018-10-30 00:29:35 +00:00
|
|
|
pid.SetValue(app_proc->pid);
|
|
|
|
return 0;
|
2018-05-05 01:56:59 +00:00
|
|
|
}
|
2018-10-30 00:29:35 +00:00
|
|
|
return 0x20F;
|
2018-05-05 00:25:26 +00:00
|
|
|
}
|
|
|
|
|
2018-10-30 00:29:35 +00:00
|
|
|
Result ShellService::BoostSystemMemoryResourceLimit(u64 sysmem_size) {
|
|
|
|
return ResourceLimitUtils::BoostSystemMemoryResourceLimit(sysmem_size);
|
2018-05-05 00:25:26 +00:00
|
|
|
}
|