diff --git a/libraries/libstratosphere/include/stratosphere/ro.hpp b/libraries/libstratosphere/include/stratosphere/ro.hpp index a5972ab3a..d3a695220 100644 --- a/libraries/libstratosphere/include/stratosphere/ro.hpp +++ b/libraries/libstratosphere/include/stratosphere/ro.hpp @@ -16,4 +16,6 @@ #pragma once -#include "ro/ro_types.hpp" +#include +#include +#include diff --git a/libraries/libstratosphere/include/stratosphere/ro/impl/ro_debug_monitor_interface.hpp b/libraries/libstratosphere/include/stratosphere/ro/impl/ro_debug_monitor_interface.hpp new file mode 100644 index 000000000..40e703a8a --- /dev/null +++ b/libraries/libstratosphere/include/stratosphere/ro/impl/ro_debug_monitor_interface.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 +#include +#include + +namespace ams::ro::impl { + + #define AMS_RO_I_DEBUG_MONITOR_INTERFACE_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 0, Result, GetProcessModuleInfo, (sf::Out out_count, const sf::OutArray &out_infos, os::ProcessId process_id)) + + AMS_SF_DEFINE_INTERFACE(IDebugMonitorInterface, AMS_RO_I_DEBUG_MONITOR_INTERFACE_INTERFACE_INFO) + +} diff --git a/libraries/libstratosphere/include/stratosphere/ro/impl/ro_ro_interface.hpp b/libraries/libstratosphere/include/stratosphere/ro/impl/ro_ro_interface.hpp new file mode 100644 index 000000000..624d1e5d8 --- /dev/null +++ b/libraries/libstratosphere/include/stratosphere/ro/impl/ro_ro_interface.hpp @@ -0,0 +1,34 @@ +/* + * 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::ro::impl { + + #define AMS_RO_I_RO_INTERFACE_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 0, Result, MapManualLoadModuleMemory, (sf::Out out_load_address, const sf::ClientProcessId &client_pid, u64 nro_address, u64 nro_size, u64 bss_address, u64 bss_size)) \ + AMS_SF_METHOD_INFO(C, H, 1, Result, UnmapManualLoadModuleMemory, (const sf::ClientProcessId &client_pid, u64 nro_address)) \ + AMS_SF_METHOD_INFO(C, H, 2, Result, RegisterModuleInfo, (const sf::ClientProcessId &client_pid, u64 nrr_address, u64 nrr_size)) \ + AMS_SF_METHOD_INFO(C, H, 3, Result, UnregisterModuleInfo, (const sf::ClientProcessId &client_pid, u64 nrr_address)) \ + AMS_SF_METHOD_INFO(C, H, 4, Result, RegisterProcessHandle, (const sf::ClientProcessId &client_pid, sf::CopyHandle process_h)) \ + AMS_SF_METHOD_INFO(C, H, 10, Result, RegisterModuleInfoEx, (const sf::ClientProcessId &client_pid, u64 nrr_address, u64 nrr_size, sf::CopyHandle process_h), hos::Version_7_0_0) + + AMS_SF_DEFINE_INTERFACE(IRoInterface, AMS_RO_I_RO_INTERFACE_INTERFACE_INFO) + +} diff --git a/libraries/libstratosphere/include/stratosphere/sm.hpp b/libraries/libstratosphere/include/stratosphere/sm.hpp index d5c4456d1..98e3f83ac 100644 --- a/libraries/libstratosphere/include/stratosphere/sm.hpp +++ b/libraries/libstratosphere/include/stratosphere/sm.hpp @@ -16,9 +16,13 @@ #pragma once -#include "sm/sm_types.hpp" -#include "sm/sm_api.hpp" -#include "sm/sm_mitm_api.hpp" -#include "sm/sm_scoped_holder.hpp" +#include +#include +#include +#include -#include "sm/sm_manager_api.hpp" +#include + +#include +#include +#include diff --git a/libraries/libstratosphere/include/stratosphere/sm/impl/sm_debug_monitor_interface.hpp b/libraries/libstratosphere/include/stratosphere/sm/impl/sm_debug_monitor_interface.hpp new file mode 100644 index 000000000..af79293c8 --- /dev/null +++ b/libraries/libstratosphere/include/stratosphere/sm/impl/sm_debug_monitor_interface.hpp @@ -0,0 +1,31 @@ +/* + * 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::sm::impl { + + #define AMS_SM_I_DEBUG_MONITOR_INTERFACE_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 65000, Result, AtmosphereGetRecord, (sf::Out record, ServiceName service)) \ + AMS_SF_METHOD_INFO(C, H, 65001, void, AtmosphereListRecords, (const sf::OutArray &records, sf::Out out_count, u64 offset)) \ + AMS_SF_METHOD_INFO(C, H, 65002, void, AtmosphereGetRecordSize, (sf::Out record_size)) + + AMS_SF_DEFINE_INTERFACE(IDebugMonitorInterface, AMS_SM_I_DEBUG_MONITOR_INTERFACE_INTERFACE_INFO) + +} diff --git a/libraries/libstratosphere/include/stratosphere/sm/impl/sm_manager_interface.hpp b/libraries/libstratosphere/include/stratosphere/sm/impl/sm_manager_interface.hpp new file mode 100644 index 000000000..6037bafe0 --- /dev/null +++ b/libraries/libstratosphere/include/stratosphere/sm/impl/sm_manager_interface.hpp @@ -0,0 +1,33 @@ +/* + * 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::sm::impl { + + #define AMS_SM_I_MANAGER_INTERFACE_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 0, Result, RegisterProcess, (os::ProcessId process_id, const sf::InBuffer &acid_sac, const sf::InBuffer &aci_sac)) \ + AMS_SF_METHOD_INFO(C, H, 1, Result, UnregisterProcess, (os::ProcessId process_id)) \ + AMS_SF_METHOD_INFO(C, H, 65000, void, AtmosphereEndInitDefers, ()) \ + AMS_SF_METHOD_INFO(C, H, 65001, void, AtmosphereHasMitm, (sf::Out out, ServiceName service)) \ + AMS_SF_METHOD_INFO(C, H, 65002, Result, AtmosphereRegisterProcess, (os::ProcessId process_id, ncm::ProgramId program_id, cfg::OverrideStatus override_status, const sf::InBuffer &acid_sac, const sf::InBuffer &aci_sac)) + + AMS_SF_DEFINE_INTERFACE(IManagerInterface, AMS_SM_I_MANAGER_INTERFACE_INTERFACE_INFO) + +} diff --git a/libraries/libstratosphere/include/stratosphere/sm/impl/sm_user_interface.hpp b/libraries/libstratosphere/include/stratosphere/sm/impl/sm_user_interface.hpp new file mode 100644 index 000000000..843162857 --- /dev/null +++ b/libraries/libstratosphere/include/stratosphere/sm/impl/sm_user_interface.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::sm::impl { + + #define AMS_SM_I_USER_INTERFACE_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 0, Result, RegisterClient, (const sf::ClientProcessId &client_process_id)) \ + AMS_SF_METHOD_INFO(C, H, 1, Result, GetServiceHandle, (sf::OutMoveHandle out_h, ServiceName service)) \ + AMS_SF_METHOD_INFO(C, H, 2, Result, RegisterService, (sf::OutMoveHandle out_h, ServiceName service, u32 max_sessions, bool is_light)) \ + AMS_SF_METHOD_INFO(C, H, 3, Result, UnregisterService, (ServiceName service)) \ + AMS_SF_METHOD_INFO(C, H, 65000, Result, AtmosphereInstallMitm, (sf::OutMoveHandle srv_h, sf::OutMoveHandle qry_h, ServiceName service)) \ + AMS_SF_METHOD_INFO(C, H, 65001, Result, AtmosphereUninstallMitm, (ServiceName service)) \ + AMS_SF_METHOD_INFO(C, H, 65003, Result, AtmosphereAcknowledgeMitmSession, (sf::Out client_info, sf::OutMoveHandle fwd_h, ServiceName service)) \ + AMS_SF_METHOD_INFO(C, H, 65004, Result, AtmosphereHasMitm, (sf::Out out, ServiceName service)) \ + AMS_SF_METHOD_INFO(C, H, 65005, Result, AtmosphereWaitMitm, (ServiceName service)) \ + AMS_SF_METHOD_INFO(C, H, 65006, Result, AtmosphereDeclareFutureMitm, (ServiceName service)) \ + AMS_SF_METHOD_INFO(C, H, 65100, Result, AtmosphereHasService, (sf::Out out, ServiceName service)) \ + AMS_SF_METHOD_INFO(C, H, 65101, Result, AtmosphereWaitService, (ServiceName service)) + + AMS_SF_DEFINE_INTERFACE(IUserInterface, AMS_SM_I_USER_INTERFACE_INTERFACE_INFO) + +} diff --git a/stratosphere/ro/source/impl/ro_service_impl.cpp b/stratosphere/ro/source/impl/ro_service_impl.cpp index 3fde492fa..5568b0f43 100644 --- a/stratosphere/ro/source/impl/ro_service_impl.cpp +++ b/stratosphere/ro/source/impl/ro_service_impl.cpp @@ -413,7 +413,7 @@ namespace ams::ro::impl { } /* Service implementations. */ - Result LoadNrr(size_t context_id, Handle process_h, u64 nrr_address, u64 nrr_size, ModuleType expected_type, bool enforce_type) { + Result RegisterModuleInfo(size_t context_id, Handle process_h, u64 nrr_address, u64 nrr_size, ModuleType expected_type, bool enforce_type) { /* Get context. */ ProcessContext *context = GetContextById(context_id); AMS_ABORT_UNLESS(context != nullptr); @@ -454,7 +454,7 @@ namespace ams::ro::impl { return ResultSuccess(); } - Result UnloadNrr(size_t context_id, u64 nrr_address) { + Result UnregisterModuleInfo(size_t context_id, u64 nrr_address) { /* Get context. */ ProcessContext *context = GetContextById(context_id); AMS_ABORT_UNLESS(context != nullptr); @@ -476,7 +476,7 @@ namespace ams::ro::impl { return UnmapNrr(context->process_handle, nrr_backup.mapped_header, nrr_backup.nrr_heap_address, nrr_backup.nrr_heap_size, nrr_backup.mapped_code_address); } - Result LoadNro(u64 *out_address, size_t context_id, u64 nro_address, u64 nro_size, u64 bss_address, u64 bss_size) { + Result MapManualLoadModuleMemory(u64 *out_address, size_t context_id, u64 nro_address, u64 nro_size, u64 bss_address, u64 bss_size) { /* Get context. */ ProcessContext *context = GetContextById(context_id); AMS_ABORT_UNLESS(context != nullptr); @@ -522,7 +522,7 @@ namespace ams::ro::impl { return ResultSuccess(); } - Result UnloadNro(size_t context_id, u64 nro_address) { + Result UnmapManualLoadModuleMemory(size_t context_id, u64 nro_address) { /* Get context. */ ProcessContext *context = GetContextById(context_id); AMS_ABORT_UNLESS(context != nullptr); diff --git a/stratosphere/ro/source/impl/ro_service_impl.hpp b/stratosphere/ro/source/impl/ro_service_impl.hpp index 01ad09e67..a8f45456d 100644 --- a/stratosphere/ro/source/impl/ro_service_impl.hpp +++ b/stratosphere/ro/source/impl/ro_service_impl.hpp @@ -35,10 +35,10 @@ namespace ams::ro::impl { void UnregisterProcess(size_t context_id); /* Service implementations. */ - Result LoadNrr(size_t context_id, Handle process_h, u64 nrr_address, u64 nrr_size, ModuleType expected_type, bool enforce_type); - Result UnloadNrr(size_t context_id, u64 nrr_address); - Result LoadNro(u64 *out_address, size_t context_id, u64 nro_address, u64 nro_size, u64 bss_address, u64 bss_size); - Result UnloadNro(size_t context_id, u64 nro_address); + Result RegisterModuleInfo(size_t context_id, Handle process_h, u64 nrr_address, u64 nrr_size, ModuleType expected_type, bool enforce_type); + Result UnregisterModuleInfo(size_t context_id, u64 nrr_address); + Result MapManualLoadModuleMemory(u64 *out_address, size_t context_id, u64 nro_address, u64 nro_size, u64 bss_address, u64 bss_size); + Result UnmapManualLoadModuleMemory(size_t context_id, u64 nro_address); /* Debug service implementations. */ Result GetProcessModuleInfo(u32 *out_count, LoaderModuleInfo *out_infos, size_t max_out_count, os::ProcessId process_id); diff --git a/stratosphere/ro/source/ro_debug_monitor.cpp b/stratosphere/ro/source/ro_debug_monitor_service.cpp similarity index 96% rename from stratosphere/ro/source/ro_debug_monitor.cpp rename to stratosphere/ro/source/ro_debug_monitor_service.cpp index 2cb4aa8ee..21a105109 100644 --- a/stratosphere/ro/source/ro_debug_monitor.cpp +++ b/stratosphere/ro/source/ro_debug_monitor_service.cpp @@ -14,7 +14,7 @@ * along with this program. If not, see . */ #include -#include "ro_debug_monitor.hpp" +#include "ro_debug_monitor_service.hpp" #include "impl/ro_service_impl.hpp" namespace ams::ro { diff --git a/stratosphere/ro/source/ro_debug_monitor.hpp b/stratosphere/ro/source/ro_debug_monitor_service.hpp similarity index 71% rename from stratosphere/ro/source/ro_debug_monitor.hpp rename to stratosphere/ro/source/ro_debug_monitor_service.hpp index f86eb00d6..58b634e43 100644 --- a/stratosphere/ro/source/ro_debug_monitor.hpp +++ b/stratosphere/ro/source/ro_debug_monitor_service.hpp @@ -18,18 +18,10 @@ namespace ams::ro { - class DebugMonitorService final : public sf::IServiceObject { - protected: - enum class CommandId { - GetProcessModuleInfo = 0, - }; - private: - /* Actual commands. */ - Result GetProcessModuleInfo(sf::Out out_count, const sf::OutArray &out_infos, os::ProcessId process_id); + class DebugMonitorService final { public: - DEFINE_SERVICE_DISPATCH_TABLE { - MAKE_SERVICE_COMMAND_META(GetProcessModuleInfo), - }; + Result GetProcessModuleInfo(sf::Out out_count, const sf::OutArray &out_infos, os::ProcessId process_id); }; + static_assert(ro::impl::IsIDebugMonitorInterface); } diff --git a/stratosphere/ro/source/ro_main.cpp b/stratosphere/ro/source/ro_main.cpp index 2a0a8034c..f3de32bb9 100644 --- a/stratosphere/ro/source/ro_main.cpp +++ b/stratosphere/ro/source/ro_main.cpp @@ -14,8 +14,8 @@ * along with this program. If not, see . */ #include -#include "ro_debug_monitor.hpp" -#include "ro_service.hpp" +#include "ro_debug_monitor_service.hpp" +#include "ro_ro_service.hpp" extern "C" { extern u32 __start__; @@ -84,10 +84,6 @@ void __appExit(void) { setsysExit(); } -/* Helpers to create RO objects. */ -static constexpr auto MakeRoServiceForSelf = []() { return std::make_shared(ro::ModuleType::ForSelf); }; -static constexpr auto MakeRoServiceForOthers = []() { return std::make_shared(ro::ModuleType::ForOthers); }; - namespace { /* ldr:ro, ro:dmnt, ro:1. */ @@ -122,11 +118,11 @@ int main(int argc, char **argv) } /* Create services. */ - R_ABORT_UNLESS((g_server_manager.RegisterServer(DebugMonitorServiceName, DebugMonitorMaxSessions))); + R_ABORT_UNLESS((g_server_manager.RegisterServer(DebugMonitorServiceName, DebugMonitorMaxSessions))); - R_ABORT_UNLESS((g_server_manager.RegisterServer(ForSelfServiceName, ForSelfMaxSessions))); + R_ABORT_UNLESS((g_server_manager.RegisterServer(ForSelfServiceName, ForSelfMaxSessions))); if (hos::GetVersion() >= hos::Version_7_0_0) { - R_ABORT_UNLESS((g_server_manager.RegisterServer(ForOthersServiceName, ForOthersMaxSessions))); + R_ABORT_UNLESS((g_server_manager.RegisterServer(ForOthersServiceName, ForOthersMaxSessions))); } /* Loop forever, servicing our services. */ diff --git a/stratosphere/ro/source/ro_ro_service.cpp b/stratosphere/ro/source/ro_ro_service.cpp new file mode 100644 index 000000000..47eb27b02 --- /dev/null +++ b/stratosphere/ro/source/ro_ro_service.cpp @@ -0,0 +1,67 @@ +/* + * 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 "ro_ro_service.hpp" +#include "impl/ro_service_impl.hpp" + +namespace ams::ro { + + void SetDevelopmentHardware(bool is_development_hardware) { + impl::SetDevelopmentHardware(is_development_hardware); + } + + void SetDevelopmentFunctionEnabled(bool is_development_function_enabled) { + impl::SetDevelopmentFunctionEnabled(is_development_function_enabled); + } + + RoService::RoService(ModuleType t) : context_id(impl::InvalidContextId), type(t) { + /* ... */ + } + + RoService::~RoService() { + impl::UnregisterProcess(this->context_id); + } + + Result RoService::MapManualLoadModuleMemory(sf::Out load_address, const sf::ClientProcessId &client_pid, u64 nro_address, u64 nro_size, u64 bss_address, u64 bss_size) { + R_TRY(impl::ValidateProcess(this->context_id, client_pid.GetValue())); + return impl::MapManualLoadModuleMemory(load_address.GetPointer(), this->context_id, nro_address, nro_size, bss_address, bss_size); + } + + Result RoService::UnmapManualLoadModuleMemory(const sf::ClientProcessId &client_pid, u64 nro_address) { + R_TRY(impl::ValidateProcess(this->context_id, client_pid.GetValue())); + return impl::UnmapManualLoadModuleMemory(this->context_id, nro_address); + } + + Result RoService::RegisterModuleInfo(const sf::ClientProcessId &client_pid, u64 nrr_address, u64 nrr_size) { + R_TRY(impl::ValidateProcess(this->context_id, client_pid.GetValue())); + return impl::RegisterModuleInfo(this->context_id, svc::InvalidHandle, nrr_address, nrr_size, ModuleType::ForSelf, true); + } + + Result RoService::UnregisterModuleInfo(const sf::ClientProcessId &client_pid, u64 nrr_address) { + R_TRY(impl::ValidateProcess(this->context_id, client_pid.GetValue())); + return impl::UnregisterModuleInfo(this->context_id, nrr_address); + } + + Result RoService::RegisterProcessHandle(const sf::ClientProcessId &client_pid, sf::CopyHandle process_h) { + return impl::RegisterProcess(std::addressof(this->context_id), process_h.GetValue(), client_pid.GetValue()); + } + + Result RoService::RegisterModuleInfoEx(const sf::ClientProcessId &client_pid, u64 nrr_address, u64 nrr_size, sf::CopyHandle process_h) { + R_TRY(impl::ValidateProcess(this->context_id, client_pid.GetValue())); + return impl::RegisterModuleInfo(this->context_id, process_h.GetValue(), nrr_address, nrr_size, this->type, this->type == ModuleType::ForOthers); + } + +} diff --git a/stratosphere/ro/source/ro_ro_service.hpp b/stratosphere/ro/source/ro_ro_service.hpp new file mode 100644 index 000000000..c3dd6d15b --- /dev/null +++ b/stratosphere/ro/source/ro_ro_service.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 + +namespace ams::ro { + + /* Access utilities. */ + void SetDevelopmentHardware(bool is_development_hardware); + void SetDevelopmentFunctionEnabled(bool is_development_function_enabled); + + class RoService { + private: + size_t context_id; + ModuleType type; + protected: + explicit RoService(ModuleType t); + public: + virtual ~RoService(); + public: + /* Actual commands. */ + Result MapManualLoadModuleMemory(sf::Out out_load_address, const sf::ClientProcessId &client_pid, u64 nro_address, u64 nro_size, u64 bss_address, u64 bss_size); + Result UnmapManualLoadModuleMemory(const sf::ClientProcessId &client_pid, u64 nro_address); + Result RegisterModuleInfo(const sf::ClientProcessId &client_pid, u64 nrr_address, u64 nrr_size); + Result UnregisterModuleInfo(const sf::ClientProcessId &client_pid, u64 nrr_address); + Result RegisterProcessHandle(const sf::ClientProcessId &client_pid, sf::CopyHandle process_h); + Result RegisterModuleInfoEx(const sf::ClientProcessId &client_pid, u64 nrr_address, u64 nrr_size, sf::CopyHandle process_h); + }; + static_assert(ro::impl::IsIRoInterface); + + class RoServiceForSelf final : public RoService { + public: + RoServiceForSelf() : RoService(ro::ModuleType::ForSelf) { /* ... */ } + }; + + /* TODO: This is really JitPlugin... */ + class RoServiceForOthers final : public RoService { + public: + RoServiceForOthers() : RoService(ro::ModuleType::ForOthers) { /* ... */ } + }; + +} diff --git a/stratosphere/ro/source/ro_service.cpp b/stratosphere/ro/source/ro_service.cpp deleted file mode 100644 index 96d38519f..000000000 --- a/stratosphere/ro/source/ro_service.cpp +++ /dev/null @@ -1,67 +0,0 @@ -/* - * 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 "ro_service.hpp" -#include "impl/ro_service_impl.hpp" - -namespace ams::ro { - - void SetDevelopmentHardware(bool is_development_hardware) { - impl::SetDevelopmentHardware(is_development_hardware); - } - - void SetDevelopmentFunctionEnabled(bool is_development_function_enabled) { - impl::SetDevelopmentFunctionEnabled(is_development_function_enabled); - } - - Service::Service(ModuleType t) : context_id(impl::InvalidContextId), type(t) { - /* ... */ - } - - Service::~Service() { - impl::UnregisterProcess(this->context_id); - } - - Result Service::LoadNro(sf::Out load_address, const sf::ClientProcessId &client_pid, u64 nro_address, u64 nro_size, u64 bss_address, u64 bss_size) { - R_TRY(impl::ValidateProcess(this->context_id, client_pid.GetValue())); - return impl::LoadNro(load_address.GetPointer(), this->context_id, nro_address, nro_size, bss_address, bss_size); - } - - Result Service::UnloadNro(const sf::ClientProcessId &client_pid, u64 nro_address) { - R_TRY(impl::ValidateProcess(this->context_id, client_pid.GetValue())); - return impl::UnloadNro(this->context_id, nro_address); - } - - Result Service::LoadNrr(const sf::ClientProcessId &client_pid, u64 nrr_address, u64 nrr_size) { - R_TRY(impl::ValidateProcess(this->context_id, client_pid.GetValue())); - return impl::LoadNrr(this->context_id, INVALID_HANDLE, nrr_address, nrr_size, ModuleType::ForSelf, true); - } - - Result Service::UnloadNrr(const sf::ClientProcessId &client_pid, u64 nrr_address) { - R_TRY(impl::ValidateProcess(this->context_id, client_pid.GetValue())); - return impl::UnloadNrr(this->context_id, nrr_address); - } - - Result Service::Initialize(const sf::ClientProcessId &client_pid, sf::CopyHandle process_h) { - return impl::RegisterProcess(&this->context_id, process_h.GetValue(), client_pid.GetValue()); - } - - Result Service::LoadNrrEx(const sf::ClientProcessId &client_pid, u64 nrr_address, u64 nrr_size, sf::CopyHandle process_h) { - R_TRY(impl::ValidateProcess(this->context_id, client_pid.GetValue())); - return impl::LoadNrr(this->context_id, process_h.GetValue(), nrr_address, nrr_size, this->type, this->type == ModuleType::ForOthers); - } - -} diff --git a/stratosphere/ro/source/ro_service.hpp b/stratosphere/ro/source/ro_service.hpp deleted file mode 100644 index 6cc943ef9..000000000 --- a/stratosphere/ro/source/ro_service.hpp +++ /dev/null @@ -1,62 +0,0 @@ -/* - * 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::ro { - - /* Access utilities. */ - void SetDevelopmentHardware(bool is_development_hardware); - void SetDevelopmentFunctionEnabled(bool is_development_function_enabled); - - class Service final : public sf::IServiceObject { - protected: - enum class CommandId { - LoadNro = 0, - UnloadNro = 1, - LoadNrr = 2, - UnloadNrr = 3, - Initialize = 4, - LoadNrrEx = 10, - }; - private: - size_t context_id; - ModuleType type; - public: - explicit Service(ModuleType t); - virtual ~Service(); - private: - /* Actual commands. */ - Result LoadNro(sf::Out out_load_address, const sf::ClientProcessId &client_pid, u64 nro_address, u64 nro_size, u64 bss_address, u64 bss_size); - Result UnloadNro(const sf::ClientProcessId &client_pid, u64 nro_address); - Result LoadNrr(const sf::ClientProcessId &client_pid, u64 nrr_address, u64 nrr_size); - Result UnloadNrr(const sf::ClientProcessId &client_pid, u64 nrr_address); - Result Initialize(const sf::ClientProcessId &client_pid, sf::CopyHandle process_h); - Result LoadNrrEx(const sf::ClientProcessId &client_pid, u64 nrr_address, u64 nrr_size, sf::CopyHandle process_h); - public: - DEFINE_SERVICE_DISPATCH_TABLE { - MAKE_SERVICE_COMMAND_META(LoadNro), - MAKE_SERVICE_COMMAND_META(UnloadNro), - MAKE_SERVICE_COMMAND_META(LoadNrr), - MAKE_SERVICE_COMMAND_META(UnloadNrr), - MAKE_SERVICE_COMMAND_META(Initialize), - MAKE_SERVICE_COMMAND_META(LoadNrrEx, hos::Version_7_0_0), - }; - - }; - -} diff --git a/stratosphere/sm/source/sm_dmnt_service.cpp b/stratosphere/sm/source/sm_debug_monitor_service.cpp similarity index 73% rename from stratosphere/sm/source/sm_dmnt_service.cpp rename to stratosphere/sm/source/sm_debug_monitor_service.cpp index 7ee32f363..4622bbb4d 100644 --- a/stratosphere/sm/source/sm_dmnt_service.cpp +++ b/stratosphere/sm/source/sm_debug_monitor_service.cpp @@ -14,20 +14,20 @@ * along with this program. If not, see . */ #include -#include "sm_dmnt_service.hpp" +#include "sm_debug_monitor_service.hpp" #include "impl/sm_service_manager.hpp" namespace ams::sm { - Result DmntService::AtmosphereGetRecord(sf::Out record, ServiceName service) { + Result DebugMonitorService::AtmosphereGetRecord(sf::Out record, ServiceName service) { return impl::GetServiceRecord(record.GetPointer(), service); } - void DmntService::AtmosphereListRecords(const sf::OutArray &records, sf::Out out_count, u64 offset) { + void DebugMonitorService::AtmosphereListRecords(const sf::OutArray &records, sf::Out out_count, u64 offset) { R_ABORT_UNLESS(impl::ListServiceRecords(records.GetPointer(), out_count.GetPointer(), offset, records.GetSize())); } - void DmntService::AtmosphereGetRecordSize(sf::Out record_size) { + void DebugMonitorService::AtmosphereGetRecordSize(sf::Out record_size) { record_size.SetValue(sizeof(ServiceRecord)); } diff --git a/stratosphere/sm/source/sm_debug_monitor_service.hpp b/stratosphere/sm/source/sm_debug_monitor_service.hpp new file mode 100644 index 000000000..9b405e769 --- /dev/null +++ b/stratosphere/sm/source/sm_debug_monitor_service.hpp @@ -0,0 +1,31 @@ +/* + * 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::sm { + + /* Service definition. */ + class DebugMonitorService final { + public: + Result AtmosphereGetRecord(sf::Out record, ServiceName service); + void AtmosphereListRecords(const sf::OutArray &records, sf::Out out_count, u64 offset); + void AtmosphereGetRecordSize(sf::Out record_size); + }; + static_assert(sm::impl::IsIDebugMonitorInterface); + +} diff --git a/stratosphere/sm/source/sm_dmnt_service.hpp b/stratosphere/sm/source/sm_dmnt_service.hpp deleted file mode 100644 index 08a1c2ac6..000000000 --- a/stratosphere/sm/source/sm_dmnt_service.hpp +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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::sm { - - /* Service definition. */ - class DmntService final : public sf::IServiceObject { - protected: - /* Command IDs. */ - enum class CommandId { - AtmosphereGetRecord = 65000, - AtmosphereListRecords = 65001, - AtmosphereGetRecordSize = 65002, - }; - private: - /* Actual commands. */ - virtual Result AtmosphereGetRecord(sf::Out record, ServiceName service); - virtual void AtmosphereListRecords(const sf::OutArray &records, sf::Out out_count, u64 offset); - virtual void AtmosphereGetRecordSize(sf::Out record_size); - public: - DEFINE_SERVICE_DISPATCH_TABLE { - MAKE_SERVICE_COMMAND_META(AtmosphereGetRecord), - MAKE_SERVICE_COMMAND_META(AtmosphereListRecords), - MAKE_SERVICE_COMMAND_META(AtmosphereGetRecordSize), - }; - }; - -} diff --git a/stratosphere/sm/source/sm_main.cpp b/stratosphere/sm/source/sm_main.cpp index eb2c56dfc..2916c8e51 100644 --- a/stratosphere/sm/source/sm_main.cpp +++ b/stratosphere/sm/source/sm_main.cpp @@ -16,7 +16,7 @@ #include #include "sm_user_service.hpp" #include "sm_manager_service.hpp" -#include "sm_dmnt_service.hpp" +#include "sm_debug_monitor_service.hpp" #include "impl/sm_service_manager.hpp" extern "C" { @@ -101,14 +101,14 @@ int main(int argc, char **argv) { Handle sm_h; R_ABORT_UNLESS(svcManageNamedPort(&sm_h, "sm:", 0x40)); - g_server_manager.RegisterServer(sm_h); + g_server_manager.RegisterServer(sm_h); } /* Create sm:m manually. */ { Handle smm_h; R_ABORT_UNLESS(sm::impl::RegisterServiceForSelf(&smm_h, sm::ServiceName::Encode("sm:m"), 1)); - g_server_manager.RegisterServer(smm_h); + g_server_manager.RegisterServer(smm_h); } /*===== ATMOSPHERE EXTENSION =====*/ @@ -116,7 +116,7 @@ int main(int argc, char **argv) { Handle smdmnt_h; R_ABORT_UNLESS(sm::impl::RegisterServiceForSelf(&smdmnt_h, sm::ServiceName::Encode("sm:dmnt"), 1)); - g_server_manager.RegisterServer(smdmnt_h); + g_server_manager.RegisterServer(smdmnt_h); } /*================================*/ diff --git a/stratosphere/sm/source/sm_manager_service.hpp b/stratosphere/sm/source/sm_manager_service.hpp index 05340baa4..1906c1824 100644 --- a/stratosphere/sm/source/sm_manager_service.hpp +++ b/stratosphere/sm/source/sm_manager_service.hpp @@ -19,33 +19,14 @@ namespace ams::sm { /* Service definition. */ - class ManagerService final : public sf::IServiceObject { - protected: - /* Command IDs. */ - enum class CommandId { - RegisterProcess = 0, - UnregisterProcess = 1, - - AtmosphereEndInitDefers = 65000, - AtmosphereHasMitm = 65001, - AtmosphereRegisterProcess = 65002, - }; - private: - /* Actual commands. */ - virtual Result RegisterProcess(os::ProcessId process_id, const sf::InBuffer &acid_sac, const sf::InBuffer &aci_sac); - virtual Result UnregisterProcess(os::ProcessId process_id); - virtual void AtmosphereEndInitDefers(); - virtual void AtmosphereHasMitm(sf::Out out, ServiceName service); - virtual Result AtmosphereRegisterProcess(os::ProcessId process_id, ncm::ProgramId program_id, cfg::OverrideStatus override_status, const sf::InBuffer &acid_sac, const sf::InBuffer &aci_sac); + class ManagerService final { public: - DEFINE_SERVICE_DISPATCH_TABLE { - MAKE_SERVICE_COMMAND_META(RegisterProcess), - MAKE_SERVICE_COMMAND_META(UnregisterProcess), - - MAKE_SERVICE_COMMAND_META(AtmosphereEndInitDefers), - MAKE_SERVICE_COMMAND_META(AtmosphereHasMitm), - MAKE_SERVICE_COMMAND_META(AtmosphereRegisterProcess), - }; + Result RegisterProcess(os::ProcessId process_id, const sf::InBuffer &acid_sac, const sf::InBuffer &aci_sac); + Result UnregisterProcess(os::ProcessId process_id); + void AtmosphereEndInitDefers(); + void AtmosphereHasMitm(sf::Out out, ServiceName service); + Result AtmosphereRegisterProcess(os::ProcessId process_id, ncm::ProgramId program_id, cfg::OverrideStatus override_status, const sf::InBuffer &acid_sac, const sf::InBuffer &aci_sac); }; + static_assert(sm::impl::IsIManagerInterface); } diff --git a/stratosphere/sm/source/sm_user_service.cpp b/stratosphere/sm/source/sm_user_service.cpp index f36c661e7..67143af19 100644 --- a/stratosphere/sm/source/sm_user_service.cpp +++ b/stratosphere/sm/source/sm_user_service.cpp @@ -19,20 +19,18 @@ namespace ams::sm { - Result UserService::Initialize(const sf::ClientProcessId &client_process_id) { + Result UserService::RegisterClient(const sf::ClientProcessId &client_process_id) { this->process_id = client_process_id.GetValue(); this->has_initialized = true; return ResultSuccess(); } Result UserService::EnsureInitialized() { - if (!this->has_initialized) { - return sm::ResultInvalidClient(); - } + R_UNLESS(this->has_initialized, sm::ResultInvalidClient()); return ResultSuccess(); } - Result UserService::GetService(sf::OutMoveHandle out_h, ServiceName service) { + Result UserService::GetServiceHandle(sf::OutMoveHandle out_h, ServiceName service) { R_TRY(this->EnsureInitialized()); return impl::GetServiceHandle(out_h.GetHandlePointer(), this->process_id, service); } diff --git a/stratosphere/sm/source/sm_user_service.hpp b/stratosphere/sm/source/sm_user_service.hpp index 341760f8f..bc2c02f3f 100644 --- a/stratosphere/sm/source/sm_user_service.hpp +++ b/stratosphere/sm/source/sm_user_service.hpp @@ -20,26 +20,7 @@ namespace ams::sm { /* Service definition. */ - class UserService final : public sf::IServiceObject { - protected: - /* Command IDs. */ - enum class CommandId { - Initialize = 0, - GetService = 1, - RegisterService = 2, - UnregisterService = 3, - - AtmosphereInstallMitm = 65000, - AtmosphereUninstallMitm = 65001, - /* Deprecated: AtmosphereAssociatePidTidForMitm = 65002 */ - AtmosphereAcknowledgeMitmSession = 65003, - AtmosphereHasMitm = 65004, - AtmosphereWaitMitm = 65005, - AtmosphereDeclareFutureMitm = 65006, - - AtmosphereHasService = 65100, - AtmosphereWaitService = 65101, - }; + class UserService final { private: os::ProcessId process_id = os::InvalidProcessId; bool has_initialized = false; @@ -47,38 +28,22 @@ namespace ams::sm { Result EnsureInitialized(); public: /* Official commands. */ - virtual Result Initialize(const sf::ClientProcessId &client_process_id); - virtual Result GetService(sf::OutMoveHandle out_h, ServiceName service); - virtual Result RegisterService(sf::OutMoveHandle out_h, ServiceName service, u32 max_sessions, bool is_light); - virtual Result UnregisterService(ServiceName service); + Result RegisterClient(const sf::ClientProcessId &client_process_id); + Result GetServiceHandle(sf::OutMoveHandle out_h, ServiceName service); + Result RegisterService(sf::OutMoveHandle out_h, ServiceName service, u32 max_sessions, bool is_light); + Result UnregisterService(ServiceName service); /* Atmosphere commands. */ - virtual Result AtmosphereInstallMitm(sf::OutMoveHandle srv_h, sf::OutMoveHandle qry_h, ServiceName service); - virtual Result AtmosphereUninstallMitm(ServiceName service); - virtual Result AtmosphereAcknowledgeMitmSession(sf::Out client_info, sf::OutMoveHandle fwd_h, ServiceName service); - virtual Result AtmosphereHasMitm(sf::Out out, ServiceName service); - virtual Result AtmosphereWaitMitm(ServiceName service); - virtual Result AtmosphereDeclareFutureMitm(ServiceName service); + Result AtmosphereInstallMitm(sf::OutMoveHandle srv_h, sf::OutMoveHandle qry_h, ServiceName service); + Result AtmosphereUninstallMitm(ServiceName service); + Result AtmosphereAcknowledgeMitmSession(sf::Out client_info, sf::OutMoveHandle fwd_h, ServiceName service); + Result AtmosphereHasMitm(sf::Out out, ServiceName service); + Result AtmosphereWaitMitm(ServiceName service); + Result AtmosphereDeclareFutureMitm(ServiceName service); - virtual Result AtmosphereHasService(sf::Out out, ServiceName service); - virtual Result AtmosphereWaitService(ServiceName service); - public: - DEFINE_SERVICE_DISPATCH_TABLE { - MAKE_SERVICE_COMMAND_META(Initialize), - MAKE_SERVICE_COMMAND_META(GetService), - MAKE_SERVICE_COMMAND_META(RegisterService), - MAKE_SERVICE_COMMAND_META(UnregisterService), - - MAKE_SERVICE_COMMAND_META(AtmosphereInstallMitm), - MAKE_SERVICE_COMMAND_META(AtmosphereUninstallMitm), - MAKE_SERVICE_COMMAND_META(AtmosphereAcknowledgeMitmSession), - MAKE_SERVICE_COMMAND_META(AtmosphereHasMitm), - MAKE_SERVICE_COMMAND_META(AtmosphereWaitMitm), - MAKE_SERVICE_COMMAND_META(AtmosphereDeclareFutureMitm), - - MAKE_SERVICE_COMMAND_META(AtmosphereHasService), - MAKE_SERVICE_COMMAND_META(AtmosphereWaitService), - }; + Result AtmosphereHasService(sf::Out out, ServiceName service); + Result AtmosphereWaitService(ServiceName service); }; + static_assert(sm::impl::IsIUserInterface); }