From fb3b29516c3904d117f432784d05bff915150aae Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Mon, 6 Jul 2020 20:00:07 -0700 Subject: [PATCH] sf: convert loader to new format --- .../include/stratosphere/ldr.hpp | 3 + .../ldr/impl/ldr_debug_monitor_interface.hpp | 32 +++++ .../impl/ldr_process_manager_interface.hpp | 36 ++++++ .../ldr/impl/ldr_shell_interface.hpp | 32 +++++ .../loader/source/ldr_loader_service.hpp | 110 +++--------------- stratosphere/loader/source/ldr_main.cpp | 6 +- 6 files changed, 124 insertions(+), 95 deletions(-) create mode 100644 libraries/libstratosphere/include/stratosphere/ldr/impl/ldr_debug_monitor_interface.hpp create mode 100644 libraries/libstratosphere/include/stratosphere/ldr/impl/ldr_process_manager_interface.hpp create mode 100644 libraries/libstratosphere/include/stratosphere/ldr/impl/ldr_shell_interface.hpp diff --git a/libraries/libstratosphere/include/stratosphere/ldr.hpp b/libraries/libstratosphere/include/stratosphere/ldr.hpp index c278de699..20f40cbdd 100644 --- a/libraries/libstratosphere/include/stratosphere/ldr.hpp +++ b/libraries/libstratosphere/include/stratosphere/ldr.hpp @@ -19,3 +19,6 @@ #include #include #include +#include +#include +#include \ No newline at end of file diff --git a/libraries/libstratosphere/include/stratosphere/ldr/impl/ldr_debug_monitor_interface.hpp b/libraries/libstratosphere/include/stratosphere/ldr/impl/ldr_debug_monitor_interface.hpp new file mode 100644 index 000000000..328ae400c --- /dev/null +++ b/libraries/libstratosphere/include/stratosphere/ldr/impl/ldr_debug_monitor_interface.hpp @@ -0,0 +1,32 @@ +/* + * 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::ldr::impl { + + #define AMS_LDR_I_DEBUG_MONITOR_INTERFACE_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 0, Result, SetProgramArguments, (ncm::ProgramId program_id, const sf::InPointerBuffer &args, u32 args_size)) \ + AMS_SF_METHOD_INFO(C, H, 1, Result, FlushArguments, ()) \ + AMS_SF_METHOD_INFO(C, H, 2, Result, GetProcessModuleInfo, (sf::Out count, const sf::OutPointerArray &out, os::ProcessId process_id)) \ + AMS_SF_METHOD_INFO(C, H, 65000, void, AtmosphereHasLaunchedProgram, (sf::Out out, ncm::ProgramId program_id)) + + AMS_SF_DEFINE_INTERFACE(IDebugMonitorInterface, AMS_LDR_I_DEBUG_MONITOR_INTERFACE_INTERFACE_INFO) + +} diff --git a/libraries/libstratosphere/include/stratosphere/ldr/impl/ldr_process_manager_interface.hpp b/libraries/libstratosphere/include/stratosphere/ldr/impl/ldr_process_manager_interface.hpp new file mode 100644 index 000000000..946ef636c --- /dev/null +++ b/libraries/libstratosphere/include/stratosphere/ldr/impl/ldr_process_manager_interface.hpp @@ -0,0 +1,36 @@ +/* + * 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::ldr::impl { + + #define AMS_LDR_I_PROCESS_MANAGER_INTERFACE_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 0, Result, CreateProcess, (sf::OutMoveHandle proc_h, PinId id, u32 flags, sf::CopyHandle reslimit_h)) \ + AMS_SF_METHOD_INFO(C, H, 1, Result, GetProgramInfo, (sf::Out out_program_info, const ncm::ProgramLocation &loc)) \ + AMS_SF_METHOD_INFO(C, H, 2, Result, PinProgram, (sf::Out out_id, const ncm::ProgramLocation &loc)) \ + AMS_SF_METHOD_INFO(C, H, 3, Result, UnpinProgram, (PinId id)) \ + AMS_SF_METHOD_INFO(C, H, 4, Result, SetEnabledProgramVerification, (bool enabled), hos::Version_10_0_0) \ + AMS_SF_METHOD_INFO(C, H, 65000, void, AtmosphereHasLaunchedProgram, (sf::Out out, ncm::ProgramId program_id)) \ + AMS_SF_METHOD_INFO(C, H, 65001, Result, AtmosphereGetProgramInfo, (sf::Out out_program_info, sf::Out out_status, const ncm::ProgramLocation &loc)) \ + AMS_SF_METHOD_INFO(C, H, 65002, Result, AtmospherePinProgram, (sf::Out out_id, const ncm::ProgramLocation &loc, const cfg::OverrideStatus &override_status)) + + AMS_SF_DEFINE_INTERFACE(IProcessManagerInterface, AMS_LDR_I_PROCESS_MANAGER_INTERFACE_INTERFACE_INFO) + +} diff --git a/libraries/libstratosphere/include/stratosphere/ldr/impl/ldr_shell_interface.hpp b/libraries/libstratosphere/include/stratosphere/ldr/impl/ldr_shell_interface.hpp new file mode 100644 index 000000000..5e3e31188 --- /dev/null +++ b/libraries/libstratosphere/include/stratosphere/ldr/impl/ldr_shell_interface.hpp @@ -0,0 +1,32 @@ +/* + * 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::ldr::impl { + + #define AMS_LDR_I_SHELL_INTERFACE_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 0, Result, SetProgramArguments, (ncm::ProgramId program_id, const sf::InPointerBuffer &args, u32 args_size)) \ + AMS_SF_METHOD_INFO(C, H, 1, Result, FlushArguments, ()) \ + AMS_SF_METHOD_INFO(C, H, 65000, Result, AtmosphereRegisterExternalCode, (sf::OutMoveHandle out, ncm::ProgramId program_id)) \ + AMS_SF_METHOD_INFO(C, H, 65001, void, AtmosphereUnregisterExternalCode, (ncm::ProgramId program_id)) + + AMS_SF_DEFINE_INTERFACE(IShellInterface, AMS_LDR_I_SHELL_INTERFACE_INTERFACE_INFO) + +} diff --git a/stratosphere/loader/source/ldr_loader_service.hpp b/stratosphere/loader/source/ldr_loader_service.hpp index 2d5d5942a..289c384a7 100644 --- a/stratosphere/loader/source/ldr_loader_service.hpp +++ b/stratosphere/loader/source/ldr_loader_service.hpp @@ -18,101 +18,27 @@ namespace ams::ldr { - class LoaderService : public sf::IServiceObject { - protected: + class LoaderService final { + public: /* Official commands. */ - virtual Result CreateProcess(sf::OutMoveHandle proc_h, PinId id, u32 flags, sf::CopyHandle reslimit_h); - virtual Result GetProgramInfo(sf::Out out_program_info, const ncm::ProgramLocation &loc); - virtual Result PinProgram(sf::Out out_id, const ncm::ProgramLocation &loc); - virtual Result UnpinProgram(PinId id); - virtual Result SetProgramArguments(ncm::ProgramId program_id, const sf::InPointerBuffer &args, u32 args_size); - virtual Result FlushArguments(); - virtual Result GetProcessModuleInfo(sf::Out count, const sf::OutPointerArray &out, os::ProcessId process_id); - virtual Result SetEnabledProgramVerification(bool enabled); + Result CreateProcess(sf::OutMoveHandle proc_h, PinId id, u32 flags, sf::CopyHandle reslimit_h); + Result GetProgramInfo(sf::Out out_program_info, const ncm::ProgramLocation &loc); + Result PinProgram(sf::Out out_id, const ncm::ProgramLocation &loc); + Result UnpinProgram(PinId id); + Result SetProgramArguments(ncm::ProgramId program_id, const sf::InPointerBuffer &args, u32 args_size); + Result FlushArguments(); + Result GetProcessModuleInfo(sf::Out count, const sf::OutPointerArray &out, os::ProcessId process_id); + Result SetEnabledProgramVerification(bool enabled); /* Atmosphere commands. */ - virtual Result AtmosphereRegisterExternalCode(sf::OutMoveHandle out, ncm::ProgramId program_id); - virtual void AtmosphereUnregisterExternalCode(ncm::ProgramId program_id); - virtual void AtmosphereHasLaunchedProgram(sf::Out out, ncm::ProgramId program_id); - virtual Result AtmosphereGetProgramInfo(sf::Out out_program_info, sf::Out out_status, const ncm::ProgramLocation &loc); - virtual Result AtmospherePinProgram(sf::Out out_id, const ncm::ProgramLocation &loc, const cfg::OverrideStatus &override_status); + Result AtmosphereRegisterExternalCode(sf::OutMoveHandle out, ncm::ProgramId program_id); + void AtmosphereUnregisterExternalCode(ncm::ProgramId program_id); + void AtmosphereHasLaunchedProgram(sf::Out out, ncm::ProgramId program_id); + Result AtmosphereGetProgramInfo(sf::Out out_program_info, sf::Out out_status, const ncm::ProgramLocation &loc); + Result AtmospherePinProgram(sf::Out out_id, const ncm::ProgramLocation &loc, const cfg::OverrideStatus &override_status); }; - - namespace pm { - - class ProcessManagerInterface final : public LoaderService { - protected: - enum class CommandId { - CreateProcess = 0, - GetProgramInfo = 1, - PinProgram = 2, - UnpinProgram = 3, - SetEnabledProgramVerification = 4, - - AtmosphereHasLaunchedProgram = 65000, - AtmosphereGetProgramInfo = 65001, - AtmospherePinProgram = 65002, - }; - public: - DEFINE_SERVICE_DISPATCH_TABLE { - MAKE_SERVICE_COMMAND_META(CreateProcess), - MAKE_SERVICE_COMMAND_META(GetProgramInfo), - MAKE_SERVICE_COMMAND_META(PinProgram), - MAKE_SERVICE_COMMAND_META(UnpinProgram), - MAKE_SERVICE_COMMAND_META(SetEnabledProgramVerification, hos::Version_10_0_0), - - MAKE_SERVICE_COMMAND_META(AtmosphereHasLaunchedProgram), - MAKE_SERVICE_COMMAND_META(AtmosphereGetProgramInfo), - MAKE_SERVICE_COMMAND_META(AtmospherePinProgram), - }; - }; - - } - - namespace dmnt { - - class DebugMonitorInterface final : public LoaderService { - protected: - enum class CommandId { - SetProgramArguments = 0, - FlushArguments = 1, - GetProcessModuleInfo = 2, - - AtmosphereHasLaunchedProgram = 65000, - }; - public: - DEFINE_SERVICE_DISPATCH_TABLE { - MAKE_SERVICE_COMMAND_META(SetProgramArguments), - MAKE_SERVICE_COMMAND_META(FlushArguments), - MAKE_SERVICE_COMMAND_META(GetProcessModuleInfo), - - MAKE_SERVICE_COMMAND_META(AtmosphereHasLaunchedProgram), - }; - }; - - } - - namespace shell { - - class ShellInterface final : public LoaderService { - protected: - enum class CommandId { - SetProgramArguments = 0, - FlushArguments = 1, - - AtmosphereRegisterExternalCode = 65000, - AtmosphereUnregisterExternalCode = 65001, - }; - public: - DEFINE_SERVICE_DISPATCH_TABLE { - MAKE_SERVICE_COMMAND_META(SetProgramArguments), - MAKE_SERVICE_COMMAND_META(FlushArguments), - - MAKE_SERVICE_COMMAND_META(AtmosphereRegisterExternalCode), - MAKE_SERVICE_COMMAND_META(AtmosphereUnregisterExternalCode), - }; - }; - - } + static_assert(ams::ldr::impl::IsIProcessManagerInterface); + static_assert(ams::ldr::impl::IsIDebugMonitorInterface); + static_assert(ams::ldr::impl::IsIShellInterface); } diff --git a/stratosphere/loader/source/ldr_main.cpp b/stratosphere/loader/source/ldr_main.cpp index ace9cd4b2..73de30843 100644 --- a/stratosphere/loader/source/ldr_main.cpp +++ b/stratosphere/loader/source/ldr_main.cpp @@ -129,9 +129,9 @@ int main(int argc, char **argv) ldr::SetDevelopmentForAcidSignatureCheck(spl::IsDevelopment()); /* Add services to manager. */ - R_ABORT_UNLESS((g_server_manager.RegisterServer(ProcessManagerServiceName, ProcessManagerMaxSessions))); - R_ABORT_UNLESS((g_server_manager.RegisterServer(ShellServiceName, ShellMaxSessions))); - R_ABORT_UNLESS((g_server_manager.RegisterServer(DebugMonitorServiceName, DebugMonitorMaxSessions))); + R_ABORT_UNLESS((g_server_manager.RegisterServer(ProcessManagerServiceName, ProcessManagerMaxSessions))); + R_ABORT_UNLESS((g_server_manager.RegisterServer(ShellServiceName, ShellMaxSessions))); + R_ABORT_UNLESS((g_server_manager.RegisterServer(DebugMonitorServiceName, DebugMonitorMaxSessions))); /* Loop forever, servicing our services. */ g_server_manager.LoopProcess();