From eca2b453ae91d9f47add11f5858186f8fe376db9 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Wed, 15 Apr 2020 20:07:20 -0700 Subject: [PATCH] pgl: update with client C++ bindings --- .../stratosphere/pgl/pgl_shell_api.hpp | 5 +- .../include/stratosphere/pgl/pgl_types.hpp | 2 +- .../source/pgl/pgl_remote_event_observer.hpp | 45 ++++++++++ .../source/pgl/pgl_shell_api.cpp | 89 +++++++++++++++++++ stratosphere/creport/source/creport_main.cpp | 4 +- 5 files changed, 140 insertions(+), 5 deletions(-) create mode 100644 libraries/libstratosphere/source/pgl/pgl_remote_event_observer.hpp create mode 100644 libraries/libstratosphere/source/pgl/pgl_shell_api.cpp diff --git a/libraries/libstratosphere/include/stratosphere/pgl/pgl_shell_api.hpp b/libraries/libstratosphere/include/stratosphere/pgl/pgl_shell_api.hpp index 04fab11b3..7dbe28d08 100644 --- a/libraries/libstratosphere/include/stratosphere/pgl/pgl_shell_api.hpp +++ b/libraries/libstratosphere/include/stratosphere/pgl/pgl_shell_api.hpp @@ -24,12 +24,13 @@ namespace ams::pgl { Result Initialize(); void Finalize(); - Result LaunchProgram(const ncm::ProgramLocation &loc, u32 process_flags, u8 pgl_flags); + Result LaunchProgram(os::ProcessId *out, const ncm::ProgramLocation &loc, u32 process_flags, u8 pgl_flags); Result TerminateProcess(os::ProcessId process_id); - Result LaunchProgramFromHost(const char *content_path, u32 process_flags); + Result LaunchProgramFromHost(os::ProcessId *out, const char *content_path, u32 process_flags); Result GetHostContentMetaInfo(pgl::ContentMetaInfo *out, const char *content_path); Result GetApplicationProcessId(os::ProcessId *out); Result BoostSystemMemoryResourceLimit(u64 size); + Result IsProcessTracked(bool *out, os::ProcessId process_id); Result EnableApplicationCrashReport(bool enabled); Result IsApplicationCrashReportEnabled(bool *out); Result EnableApplicationAllThreadDumpOnCrash(bool enabled); diff --git a/libraries/libstratosphere/include/stratosphere/pgl/pgl_types.hpp b/libraries/libstratosphere/include/stratosphere/pgl/pgl_types.hpp index eb4f1c687..e2fa9ce42 100644 --- a/libraries/libstratosphere/include/stratosphere/pgl/pgl_types.hpp +++ b/libraries/libstratosphere/include/stratosphere/pgl/pgl_types.hpp @@ -31,7 +31,7 @@ namespace ams::pgl { enum class SnapShotDumpType : u32 { None = 0, Auto = 1, - Full = 1, + Full = 2, }; /* TODO: Is this really nn::ncm::ContentInfo? */ diff --git a/libraries/libstratosphere/source/pgl/pgl_remote_event_observer.hpp b/libraries/libstratosphere/source/pgl/pgl_remote_event_observer.hpp new file mode 100644 index 000000000..c7cf0d844 --- /dev/null +++ b/libraries/libstratosphere/source/pgl/pgl_remote_event_observer.hpp @@ -0,0 +1,45 @@ +/* + * 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 { + + class RemoteEventObserver final : public pgl::sf::IEventObserver { + NON_COPYABLE(RemoteEventObserver); + NON_MOVEABLE(RemoteEventObserver); + private: + ::PglEventObserver observer; + public: + constexpr RemoteEventObserver(const ::PglEventObserver &o) : observer(o) { /* ... */ } + virtual ~RemoteEventObserver() override { + ::pglEventObserverClose(std::addressof(this->observer)); + } + + virtual Result GetProcessEventHandle(ams::sf::OutCopyHandle out) override { + ::Event ev; + R_TRY(::pglEventObserverGetProcessEvent(std::addressof(this->observer), std::addressof(ev))); + out.SetValue(ev.revent); + return ResultSuccess(); + } + + virtual Result GetProcessEventInfo(ams::sf::Out out) override { + static_assert(sizeof(*out.GetPointer()) == sizeof(::PmProcessEventInfo)); + return ::pglEventObserverGetProcessEventInfo(std::addressof(this->observer), reinterpret_cast<::PmProcessEventInfo *>(out.GetPointer())); + } + }; + +} \ No newline at end of file diff --git a/libraries/libstratosphere/source/pgl/pgl_shell_api.cpp b/libraries/libstratosphere/source/pgl/pgl_shell_api.cpp new file mode 100644 index 000000000..cbed6bbb3 --- /dev/null +++ b/libraries/libstratosphere/source/pgl/pgl_shell_api.cpp @@ -0,0 +1,89 @@ +/* + * 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 . + */ +#include +#include "pgl_remote_event_observer.hpp" + +namespace ams::pgl { + + Result Initialize() { + return ::pglInitialize(); + } + + void Finalize() { + return pglExit(); + } + + Result LaunchProgram(os::ProcessId *out, const ncm::ProgramLocation &loc, u32 process_flags, u8 pgl_flags) { + static_assert(sizeof(*out) == sizeof(u64)); + static_assert(sizeof(loc) == sizeof(::NcmProgramLocation)); + return ::pglLaunchProgram(reinterpret_cast(out), reinterpret_cast(std::addressof(loc)), process_flags, pgl_flags); + } + + Result TerminateProcess(os::ProcessId process_id) { + return ::pglTerminateProcess(static_cast(process_id)); + } + + Result LaunchProgramFromHost(os::ProcessId *out, const char *content_path, u32 process_flags) { + static_assert(sizeof(*out) == sizeof(u64)); + return ::pglLaunchProgramFromHost(reinterpret_cast(out), content_path, process_flags); + } + + Result GetHostContentMetaInfo(pgl::ContentMetaInfo *out, const char *content_path) { + static_assert(sizeof(*out) == sizeof(::PglContentMetaInfo)); + return ::pglGetHostContentMetaInfo(reinterpret_cast<::PglContentMetaInfo *>(out), content_path); + } + + Result GetApplicationProcessId(os::ProcessId *out) { + static_assert(sizeof(*out) == sizeof(u64)); + return ::pglGetApplicationProcessId(reinterpret_cast(out)); + } + + Result BoostSystemMemoryResourceLimit(u64 size) { + return ::pglBoostSystemMemoryResourceLimit(size); + } + + Result IsProcessTracked(bool *out, os::ProcessId process_id) { + return ::pglIsProcessTracked(out, static_cast(process_id)); + } + + Result EnableApplicationCrashReport(bool enabled) { + return ::pglEnableApplicationCrashReport(enabled); + } + + Result IsApplicationCrashReportEnabled(bool *out) { + return ::pglIsApplicationCrashReportEnabled(out); + } + + Result EnableApplicationAllThreadDumpOnCrash(bool enabled) { + return ::pglEnableApplicationAllThreadDumpOnCrash(enabled); + } + + Result TriggerSnapShotDumper(const char *arg, SnapShotDumpType dump_type) { + return ::pglTriggerSnapShotDumper(arg, static_cast<::PglSnapShotDumpType>(dump_type)); + } + + Result GetEventObserver(pgl::EventObserver *out) { + ::PglEventObserver obs; + R_TRY(::pglGetEventObserver(std::addressof(obs))); + + auto remote_observer = std::make_shared(obs); + AMS_ABORT_UNLESS(remote_observer != nullptr); + + *out = pgl::EventObserver(remote_observer); + return ResultSuccess(); + } + +} \ No newline at end of file diff --git a/stratosphere/creport/source/creport_main.cpp b/stratosphere/creport/source/creport_main.cpp index af8e8f84e..b7fd6e445 100644 --- a/stratosphere/creport/source/creport_main.cpp +++ b/stratosphere/creport/source/creport_main.cpp @@ -110,9 +110,9 @@ int main(int argc, char **argv) { /* Try to terminate the process. */ if (hos::GetVersion() >= hos::Version_10_0_0) { /* On 10.0.0+, use pgl to terminate. */ - sm::ScopedServiceHolder pgl_holder; + sm::ScopedServiceHolder pgl_holder; if (pgl_holder) { - pglTerminateProcess(static_cast(crashed_pid)); + pgl::TerminateProcess(crashed_pid); } } else { /* On < 10.0.0, use ns:dev to terminate. */