diff --git a/libraries/libstratosphere/include/stratosphere.hpp b/libraries/libstratosphere/include/stratosphere.hpp index 31c66bad1..8aa4b363a 100644 --- a/libraries/libstratosphere/include/stratosphere.hpp +++ b/libraries/libstratosphere/include/stratosphere.hpp @@ -51,6 +51,7 @@ #include #include #include +#include #include #include #include diff --git a/libraries/libstratosphere/include/stratosphere/pgl.hpp b/libraries/libstratosphere/include/stratosphere/pgl.hpp new file mode 100644 index 000000000..3d2ffeb81 --- /dev/null +++ b/libraries/libstratosphere/include/stratosphere/pgl.hpp @@ -0,0 +1,21 @@ +/* + * 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 +#include +#include diff --git a/libraries/libstratosphere/include/stratosphere/pgl/pgl_event_observer.hpp b/libraries/libstratosphere/include/stratosphere/pgl/pgl_event_observer.hpp new file mode 100644 index 000000000..48d16b9fb --- /dev/null +++ b/libraries/libstratosphere/include/stratosphere/pgl/pgl_event_observer.hpp @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2019-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 +#include +#include +#include + +namespace ams::pgl { + + class EventObserver { + NON_COPYABLE(EventObserver); + private: + std::shared_ptr interface; + public: + EventObserver() { /* ... */ } + explicit EventObserver(std::shared_ptr intf) : interface(std::move(intf)) { /* ... */ } + + EventObserver(EventObserver &&rhs) { + this->interface = std::move(rhs.interface); + } + + EventObserver &operator=(EventObserver &&rhs) { + EventObserver(std::move(rhs)).Swap(*this); + return *this; + } + + void Swap(EventObserver &rhs) { + std::swap(this->interface, rhs.interface); + } + public: + Result GetSystemEvent(os::SystemEventType *out) { + ams::sf::CopyHandle handle; + R_TRY(this->interface->GetProcessEventHandle(std::addressof(handle))); + os::AttachSystemEvent(out, handle.GetValue(), true, svc::InvalidHandle, false, os::EventClearMode_AutoClear); + return ResultSuccess(); + } + + Result GetProcessEventInfo(pm::ProcessEventInfo *out) { + return this->interface->GetProcessEventInfo(out); + } + }; + +} diff --git a/libraries/libstratosphere/include/stratosphere/pgl/pgl_shell_api.hpp b/libraries/libstratosphere/include/stratosphere/pgl/pgl_shell_api.hpp new file mode 100644 index 000000000..04fab11b3 --- /dev/null +++ b/libraries/libstratosphere/include/stratosphere/pgl/pgl_shell_api.hpp @@ -0,0 +1,40 @@ +/* + * 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 +#include +#include + +namespace ams::pgl { + + Result Initialize(); + void Finalize(); + + Result LaunchProgram(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 GetHostContentMetaInfo(pgl::ContentMetaInfo *out, const char *content_path); + Result GetApplicationProcessId(os::ProcessId *out); + Result BoostSystemMemoryResourceLimit(u64 size); + Result EnableApplicationCrashReport(bool enabled); + Result IsApplicationCrashReportEnabled(bool *out); + Result EnableApplicationAllThreadDumpOnCrash(bool enabled); + Result TriggerSnapShotDumper(const char *arg, SnapShotDumpType dump_type); + + Result GetEventObserver(pgl::EventObserver *out); + +} diff --git a/libraries/libstratosphere/include/stratosphere/pgl/pgl_types.hpp b/libraries/libstratosphere/include/stratosphere/pgl/pgl_types.hpp new file mode 100644 index 000000000..eb4f1c687 --- /dev/null +++ b/libraries/libstratosphere/include/stratosphere/pgl/pgl_types.hpp @@ -0,0 +1,56 @@ +/* + * 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 +#include +#include +#include + +namespace ams::pgl { + + enum LaunchFlags : u8 { + LaunchFlags_EnableDetailedCrashReport = (1 << 0), + LaunchFlags_EnableCrashReportScreenShotForProduction = (1 << 1), + LaunchFlags_EnableCrashReportScreenShotForDevelop = (1 << 2), + }; + + enum class SnapShotDumpType : u32 { + None = 0, + Auto = 1, + Full = 1, + }; + + /* TODO: Is this really nn::ncm::ContentInfo? */ + struct ContentMetaInfo { + u64 id; + u32 version; + ncm::ContentType content_type; + u8 id_offset; + u8 reserved_0E[2]; + + static constexpr ContentMetaInfo Make(u64 id, u32 version, ncm::ContentType content_type, u8 id_offset) { + return { + .id = id, + .version = version, + .content_type = content_type, + .id_offset = id_offset, + }; + } + }; + static_assert(sizeof(ContentMetaInfo) == 0x10 && std::is_pod::value); + +} diff --git a/libraries/libstratosphere/include/stratosphere/pgl/sf/pgl_sf_i_event_observer.hpp b/libraries/libstratosphere/include/stratosphere/pgl/sf/pgl_sf_i_event_observer.hpp new file mode 100644 index 000000000..d3e147e9c --- /dev/null +++ b/libraries/libstratosphere/include/stratosphere/pgl/sf/pgl_sf_i_event_observer.hpp @@ -0,0 +1,42 @@ +/* + * 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 +#include +#include +#include + +namespace ams::pgl::sf { + + class IEventObserver : public ams::sf::IServiceObject { + protected: + enum class CommandId { + GetProcessEventHandle = 0, + GetProcessEventInfo = 1, + }; + public: + /* Actual commands. */ + virtual Result GetProcessEventHandle(ams::sf::OutCopyHandle out) = 0; + virtual Result GetProcessEventInfo(ams::sf::Out out) = 0; + public: + DEFINE_SERVICE_DISPATCH_TABLE { + MAKE_SERVICE_COMMAND_META(GetProcessEventHandle), + MAKE_SERVICE_COMMAND_META(GetProcessEventInfo), + }; + }; + +} \ No newline at end of file diff --git a/libraries/libstratosphere/include/stratosphere/pm/pm_types.hpp b/libraries/libstratosphere/include/stratosphere/pm/pm_types.hpp index a4521758b..70bf622b3 100644 --- a/libraries/libstratosphere/include/stratosphere/pm/pm_types.hpp +++ b/libraries/libstratosphere/include/stratosphere/pm/pm_types.hpp @@ -34,6 +34,45 @@ namespace ams::pm { using LimitableResource = ::LimitableResource; + enum class ProcessEvent { + None = 0, + Exited = 1, + Started = 2, + Exception = 3, + DebugRunning = 4, + DebugBreak = 5, + }; + + enum class ProcessEventDeprecated { + None = 0, + Exception = 1, + Exited = 2, + DebugRunning = 3, + DebugBreak = 4, + Started = 5, + }; + + inline u32 GetProcessEventValue(ProcessEvent event) { + if (hos::GetVersion() >= hos::Version_5_0_0) { + return static_cast(event); + } + switch (event) { + case ProcessEvent::None: + return static_cast(ProcessEventDeprecated::None); + case ProcessEvent::Exited: + return static_cast(ProcessEventDeprecated::Exited); + case ProcessEvent::Started: + return static_cast(ProcessEventDeprecated::Started); + case ProcessEvent::Exception: + return static_cast(ProcessEventDeprecated::Exception); + case ProcessEvent::DebugRunning: + return static_cast(ProcessEventDeprecated::DebugRunning); + case ProcessEvent::DebugBreak: + return static_cast(ProcessEventDeprecated::DebugBreak); + AMS_UNREACHABLE_DEFAULT_CASE(); + } + } + struct ProcessEventInfo { u32 event; os::ProcessId process_id; diff --git a/stratosphere/pm/source/impl/pm_process_manager.cpp b/stratosphere/pm/source/impl/pm_process_manager.cpp index 30ad8ce23..21a80595f 100644 --- a/stratosphere/pm/source/impl/pm_process_manager.cpp +++ b/stratosphere/pm/source/impl/pm_process_manager.cpp @@ -91,45 +91,6 @@ namespace ams::pm::impl { #undef GET_FLAG_MASK - enum class ProcessEvent { - None = 0, - Exited = 1, - Started = 2, - Exception = 3, - DebugRunning = 4, - DebugBreak = 5, - }; - - enum class ProcessEventDeprecated { - None = 0, - Exception = 1, - Exited = 2, - DebugRunning = 3, - DebugBreak = 4, - Started = 5, - }; - - inline u32 GetProcessEventValue(ProcessEvent event) { - if (hos::GetVersion() >= hos::Version_5_0_0) { - return static_cast(event); - } - switch (event) { - case ProcessEvent::None: - return static_cast(ProcessEventDeprecated::None); - case ProcessEvent::Exited: - return static_cast(ProcessEventDeprecated::Exited); - case ProcessEvent::Started: - return static_cast(ProcessEventDeprecated::Started); - case ProcessEvent::Exception: - return static_cast(ProcessEventDeprecated::Exception); - case ProcessEvent::DebugRunning: - return static_cast(ProcessEventDeprecated::DebugRunning); - case ProcessEvent::DebugBreak: - return static_cast(ProcessEventDeprecated::DebugBreak); - AMS_UNREACHABLE_DEFAULT_CASE(); - } - } - template class ProcessInfoAllocator { NON_COPYABLE(ProcessInfoAllocator);