diff --git a/libraries/libstratosphere/include/stratosphere/pm/pm_shell_api.hpp b/libraries/libstratosphere/include/stratosphere/pm/pm_shell_api.hpp index a7a51247c..cba0e47c4 100644 --- a/libraries/libstratosphere/include/stratosphere/pm/pm_shell_api.hpp +++ b/libraries/libstratosphere/include/stratosphere/pm/pm_shell_api.hpp @@ -23,7 +23,9 @@ namespace ams::pm::shell { /* Shell API. */ - Result LaunchProgram(os::ProcessId *out_process_id, const ncm::ProgramLocation &loc, u32 launch_flags); + Result LaunchProgram(os::ProcessId *out, const ncm::ProgramLocation &loc, u32 launch_flags); Result TerminateProcess(os::ProcessId process_id); + Result GetApplicationProcessIdForShell(os::ProcessId *out); + Result BoostSystemMemoryResourceLimit(u64 size); } diff --git a/libraries/libstratosphere/source/pgl/srv/pgl_srv_shell.cpp b/libraries/libstratosphere/source/pgl/srv/pgl_srv_shell.cpp index eae40013a..46e3de9dc 100644 --- a/libraries/libstratosphere/source/pgl/srv/pgl_srv_shell.cpp +++ b/libraries/libstratosphere/source/pgl/srv/pgl_srv_shell.cpp @@ -73,6 +73,15 @@ namespace ams::pgl::srv { } } + std::optional GetRunningApplicationProcessId() { + os::ProcessId process_id; + if (R_SUCCEEDED(pm::shell::GetApplicationProcessIdForShell(std::addressof(process_id)))) { + return process_id; + } else { + return std::nullopt; + } + } + } void InitializeProcessControlTask() { @@ -108,7 +117,29 @@ namespace ams::pgl::srv { } Result TerminateProcess(os::ProcessId process_id) { + /* Ask PM to terminate the process. */ return pm::shell::TerminateProcess(process_id); } -} \ No newline at end of file + Result GetApplicationProcessId(os::ProcessId *out) { + /* Get the application process id. */ + auto application_process_id = GetRunningApplicationProcessId(); + R_UNLESS(application_process_id, pgl::ResultApplicationNotRunning()); + + /* Return the id. */ + *out = *application_process_id; + return ResultSuccess(); + } + + Result BoostSystemMemoryResourceLimit(u64 size) { + /* Ask PM to boost the limit. */ + return pm::shell::BoostSystemMemoryResourceLimit(size); + } + + bool IsProcessTracked(os::ProcessId process_id) { + /* Check whether a ProcessData exists for the process. */ + std::scoped_lock lk(g_process_data_mutex); + return FindProcessData(process_id) != nullptr; + } + +} diff --git a/libraries/libstratosphere/source/pgl/srv/pgl_srv_shell.hpp b/libraries/libstratosphere/source/pgl/srv/pgl_srv_shell.hpp index 4819e1425..8ecdde737 100644 --- a/libraries/libstratosphere/source/pgl/srv/pgl_srv_shell.hpp +++ b/libraries/libstratosphere/source/pgl/srv/pgl_srv_shell.hpp @@ -22,5 +22,8 @@ namespace ams::pgl::srv { Result LaunchProgram(os::ProcessId *out, const ncm::ProgramLocation &loc, u32 pm_flags, u8 pgl_flags); Result TerminateProcess(os::ProcessId process_id); + Result GetApplicationProcessId(os::ProcessId *out); + Result BoostSystemMemoryResourceLimit(u64 size); + bool IsProcessTracked(os::ProcessId process_id); } diff --git a/libraries/libstratosphere/source/pgl/srv/pgl_srv_shell_interface.cpp b/libraries/libstratosphere/source/pgl/srv/pgl_srv_shell_interface.cpp index e25dbb23b..a24d9882a 100644 --- a/libraries/libstratosphere/source/pgl/srv/pgl_srv_shell_interface.cpp +++ b/libraries/libstratosphere/source/pgl/srv/pgl_srv_shell_interface.cpp @@ -36,15 +36,16 @@ namespace ams::pgl::srv { } Result ShellInterface::GetApplicationProcessId(ams::sf::Out out) { - /* TODO */ + return pgl::srv::GetApplicationProcessId(out.GetPointer()); } Result ShellInterface::BoostSystemMemoryResourceLimit(u64 size) { - /* TODO */ + return pgl::srv::BoostSystemMemoryResourceLimit(size); } Result ShellInterface::IsProcessTracked(ams::sf::Out out, os::ProcessId process_id) { - /* TODO */ + out.SetValue(pgl::srv::IsProcessTracked(process_id)); + return ResultSuccess(); } Result ShellInterface::EnableApplicationCrashReport(bool enabled) { diff --git a/libraries/libstratosphere/source/pm/pm_shell_api.cpp b/libraries/libstratosphere/source/pm/pm_shell_api.cpp index 40a32a163..16a1adf2c 100644 --- a/libraries/libstratosphere/source/pm/pm_shell_api.cpp +++ b/libraries/libstratosphere/source/pm/pm_shell_api.cpp @@ -18,14 +18,23 @@ namespace ams::pm::shell { /* Shell API. */ - Result WEAK_SYMBOL LaunchProgram(os::ProcessId *out_process_id, const ncm::ProgramLocation &loc, u32 launch_flags) { + Result WEAK_SYMBOL LaunchProgram(os::ProcessId *out, const ncm::ProgramLocation &loc, u32 launch_flags) { static_assert(sizeof(ncm::ProgramLocation) == sizeof(NcmProgramLocation)); static_assert(alignof(ncm::ProgramLocation) == alignof(NcmProgramLocation)); - return pmshellLaunchProgram(launch_flags, reinterpret_cast(&loc), reinterpret_cast(out_process_id)); + return pmshellLaunchProgram(launch_flags, reinterpret_cast(&loc), reinterpret_cast(out)); } Result TerminateProcess(os::ProcessId process_id) { return ::pmshellTerminateProcess(static_cast(process_id)); } + Result GetApplicationProcessIdForShell(os::ProcessId *out) { + static_assert(sizeof(*out) == sizeof(u64)); + return ::pmshellGetApplicationProcessIdForShell(reinterpret_cast(out)); + } + + Result BoostSystemMemoryResourceLimit(u64 size) { + return ::pmshellBoostSystemMemoryResourceLimit(size); + } + } diff --git a/libraries/libvapours/include/vapours/results.hpp b/libraries/libvapours/include/vapours/results.hpp index 77c762b67..aed86ea51 100644 --- a/libraries/libvapours/include/vapours/results.hpp +++ b/libraries/libvapours/include/vapours/results.hpp @@ -38,6 +38,7 @@ #include #include #include +#include #include #include #include diff --git a/libraries/libvapours/include/vapours/results/pgl_results.hpp b/libraries/libvapours/include/vapours/results/pgl_results.hpp new file mode 100644 index 000000000..9bbfc5e02 --- /dev/null +++ b/libraries/libvapours/include/vapours/results/pgl_results.hpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2018-2020 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 . + */ + +#pragma once +#include + +namespace ams::pgl { + + R_DEFINE_NAMESPACE_RESULT_MODULE(228); + + R_DEFINE_ERROR_RESULT(ApplicationNotRunning, 3); + R_DEFINE_ERROR_RESULT(BufferNotEnough, 4); + R_DEFINE_ERROR_RESULT(ApplicationContentNotFound, 5); + R_DEFINE_ERROR_RESULT(ContentMetaNotFound, 4); + +}