From 3b2c2ba5a2de0e128ed5f2c49d4ab40249f247b7 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Tue, 19 Jan 2021 02:34:02 -0800 Subject: [PATCH] ams_mitm: update for new sf semantics --- .../fssrv_storage_interface_adapter.hpp | 4 +- .../sf/hipc/sf_hipc_server_manager.hpp | 18 ++++- .../sf/impl/sf_impl_autogen_impl_macros.hpp | 10 ++- .../source/ams/ams_environment.cpp | 8 --- .../fssrv/fssrv_storage_interface_adapter.cpp | 2 +- .../ams_mitm/source/amsmitm_debug.cpp | 57 ---------------- .../ams_mitm/source/amsmitm_debug.hpp | 23 ------- stratosphere/ams_mitm/source/amsmitm_main.cpp | 11 +++ .../source/amsmitm_module_management.cpp | 3 - .../source/bpc_mitm/bpc_ams_module.cpp | 4 +- .../source/bpc_mitm/bpc_ams_service.hpp | 18 ++--- .../source/bpc_mitm/bpc_mitm_service.hpp | 16 ++--- .../source/bpc_mitm/bpcmitm_module.cpp | 30 +++++++- .../source/fs_mitm/fs_mitm_service.cpp | 59 ++++++++-------- .../source/fs_mitm/fs_mitm_service.hpp | 42 ++++++------ .../ams_mitm/source/fs_mitm/fsmitm_module.cpp | 28 +++++++- .../source/hid_mitm/hid_mitm_service.cpp | 28 -------- .../source/hid_mitm/hid_mitm_service.hpp | 48 ------------- .../ams_mitm/source/hid_mitm/hid_shim.c | 27 -------- .../ams_mitm/source/hid_mitm/hid_shim.h | 19 ------ .../source/hid_mitm/hidmitm_module.cpp | 68 ------------------- .../source/hid_mitm/hidmitm_module.hpp | 24 ------- .../source/ns_mitm/ns_am_mitm_service.hpp | 18 ++--- .../source/ns_mitm/ns_web_mitm_service.cpp | 4 +- .../source/ns_mitm/ns_web_mitm_service.hpp | 30 ++++---- .../ams_mitm/source/ns_mitm/nsmitm_module.cpp | 36 ++++++++-- .../source/set_mitm/set_mitm_service.hpp | 18 ++--- .../source/set_mitm/setmitm_module.cpp | 34 ++++++++-- .../source/set_mitm/setsys_mitm_service.hpp | 22 +++--- .../source/set_mitm/settings_sd_kvs.cpp | 12 +--- .../source/sysupdater/sysupdater_module.cpp | 12 ++-- .../source/sysupdater/sysupdater_service.cpp | 10 +-- .../source/sysupdater/sysupdater_service.hpp | 30 ++++---- .../boot/source/boot_driver_management.cpp | 5 ++ .../boot/source/boot_driver_management.hpp | 1 + stratosphere/boot/source/boot_main.cpp | 3 + 36 files changed, 293 insertions(+), 489 deletions(-) delete mode 100644 stratosphere/ams_mitm/source/amsmitm_debug.cpp delete mode 100644 stratosphere/ams_mitm/source/amsmitm_debug.hpp delete mode 100644 stratosphere/ams_mitm/source/hid_mitm/hid_mitm_service.cpp delete mode 100644 stratosphere/ams_mitm/source/hid_mitm/hid_mitm_service.hpp delete mode 100644 stratosphere/ams_mitm/source/hid_mitm/hid_shim.c delete mode 100644 stratosphere/ams_mitm/source/hid_mitm/hid_shim.h delete mode 100644 stratosphere/ams_mitm/source/hid_mitm/hidmitm_module.cpp delete mode 100644 stratosphere/ams_mitm/source/hid_mitm/hidmitm_module.hpp diff --git a/libraries/libstratosphere/include/stratosphere/fssrv/interface_adapters/fssrv_storage_interface_adapter.hpp b/libraries/libstratosphere/include/stratosphere/fssrv/interface_adapters/fssrv_storage_interface_adapter.hpp index 7f442da3f..f3151543c 100644 --- a/libraries/libstratosphere/include/stratosphere/fssrv/interface_adapters/fssrv_storage_interface_adapter.hpp +++ b/libraries/libstratosphere/include/stratosphere/fssrv/interface_adapters/fssrv_storage_interface_adapter.hpp @@ -27,7 +27,7 @@ namespace ams::fs { namespace ams::fssrv::impl { - class StorageInterfaceAdapter final { + class StorageInterfaceAdapter { NON_COPYABLE(StorageInterfaceAdapter); private: /* TODO: Nintendo uses fssystem::AsynchronousAccessStorage here. */ @@ -39,7 +39,7 @@ namespace ams::fssrv::impl { public: StorageInterfaceAdapter(fs::IStorage *storage); StorageInterfaceAdapter(std::unique_ptr storage); - explicit StorageInterfaceAdapter(std::shared_ptr &&storage); + explicit StorageInterfaceAdapter(std::shared_ptr storage); /* TODO: Other constructors. */ ~StorageInterfaceAdapter(); diff --git a/libraries/libstratosphere/include/stratosphere/sf/hipc/sf_hipc_server_manager.hpp b/libraries/libstratosphere/include/stratosphere/sf/hipc/sf_hipc_server_manager.hpp index 7b2deea46..19986c90a 100644 --- a/libraries/libstratosphere/include/stratosphere/sf/hipc/sf_hipc_server_manager.hpp +++ b/libraries/libstratosphere/include/stratosphere/sf/hipc/sf_hipc_server_manager.hpp @@ -53,13 +53,24 @@ namespace ams::sf::hipc { friend class ServerManager; NON_COPYABLE(Server); NON_MOVEABLE(Server); - protected: + private: cmif::ServiceObjectHolder static_object; ::Handle port_handle; sm::ServiceName service_name; int index; bool service_managed; bool is_mitm_server; + public: + void AcknowledgeMitmSession(std::shared_ptr<::Service> *out_fsrv, sm::MitmProcessInfo *out_client_info) { + /* Check mitm server. */ + AMS_ABORT_UNLESS(this->is_mitm_server); + + /* Create forward service. */ + *out_fsrv = ServerSession::CreateForwardService(); + + /* Get client info. */ + R_ABORT_UNLESS(sm::mitm::AcknowledgeSession(out_fsrv->get(), out_client_info, this->service_name)); + } }; private: /* Management of waitables. */ @@ -172,6 +183,11 @@ namespace ams::sf::hipc { Result AcceptImpl(Server *server, SharedPointer p) { return ServerSessionManager::AcceptSession(server->port_handle, std::move(p)); } + + template + Result AcceptMitmImpl(Server *server, SharedPointer p, std::shared_ptr<::Service> forward_service) { + return ServerSessionManager::AcceptMitmSession(server->port_handle, std::move(p), std::move(forward_service)); + } public: ServerManagerBase(DomainEntryStorage *entry_storage, size_t entry_count) : ServerDomainSessionManager(entry_storage, entry_count), diff --git a/libraries/libstratosphere/include/stratosphere/sf/impl/sf_impl_autogen_impl_macros.hpp b/libraries/libstratosphere/include/stratosphere/sf/impl/sf_impl_autogen_impl_macros.hpp index 09c7da59b..dda9a3af4 100644 --- a/libraries/libstratosphere/include/stratosphere/sf/impl/sf_impl_autogen_impl_macros.hpp +++ b/libraries/libstratosphere/include/stratosphere/sf/impl/sf_impl_autogen_impl_macros.hpp @@ -25,10 +25,10 @@ namespace ams::sf::impl { return ImplGetter::GetImplPointer(static_cast(this))->NAME ARGNAMES; \ } - #define AMS_SF_DEFINE_INTERFACE(NAMESPACE, INTERFACE, CMD_MACRO) \ + #define AMS_SF_DEFINE_INTERFACE_WITH_DEFAULT_BASE(NAMESPACE, INTERFACE, BASE, CMD_MACRO) \ namespace NAMESPACE { \ \ - AMS_SF_DEFINE_INTERFACE_IMPL(::ams::sf::IServiceObject, INTERFACE, CMD_MACRO) \ + AMS_SF_DEFINE_INTERFACE_IMPL(BASE, INTERFACE, CMD_MACRO) \ \ } \ \ @@ -45,6 +45,12 @@ namespace ams::sf::impl { \ } + #define AMS_SF_DEFINE_INTERFACE(NAMESPACE, INTERFACE, CMD_MACRO) \ + AMS_SF_DEFINE_INTERFACE_WITH_DEFAULT_BASE(NAMESPACE, INTERFACE, ::ams::sf::IServiceObject, CMD_MACRO) + + #define AMS_SF_DEFINE_MITM_INTERFACE(NAMESPACE, INTERFACE, CMD_MACRO) \ + AMS_SF_DEFINE_INTERFACE_WITH_DEFAULT_BASE(NAMESPACE, INTERFACE, ::ams::sf::IMitmServiceObject, CMD_MACRO) + #define AMS_SF_DEFINE_INTERFACE_WITH_BASE(NAMESPACE, INTERFACE, BASE, CMD_MACRO) \ namespace NAMESPACE { \ \ diff --git a/libraries/libstratosphere/source/ams/ams_environment.cpp b/libraries/libstratosphere/source/ams/ams_environment.cpp index 674dcf0d2..e18a8019b 100644 --- a/libraries/libstratosphere/source/ams/ams_environment.cpp +++ b/libraries/libstratosphere/source/ams/ams_environment.cpp @@ -196,16 +196,8 @@ extern "C" { } -namespace { - - constinit ams::os::Mutex g_abort_lock(true); - -} - /* Custom abort handler, so that std::abort will trigger these. */ void abort() { - std::scoped_lock lk(g_abort_lock); - ams::AbortImpl(); __builtin_unreachable(); } diff --git a/libraries/libstratosphere/source/fssrv/fssrv_storage_interface_adapter.cpp b/libraries/libstratosphere/source/fssrv/fssrv_storage_interface_adapter.cpp index f36bf0267..384db7d1b 100644 --- a/libraries/libstratosphere/source/fssrv/fssrv_storage_interface_adapter.cpp +++ b/libraries/libstratosphere/source/fssrv/fssrv_storage_interface_adapter.cpp @@ -26,7 +26,7 @@ namespace ams::fssrv::impl { /* ... */ } - StorageInterfaceAdapter::StorageInterfaceAdapter(std::shared_ptr &&storage) : base_storage(std::move(storage)) { + StorageInterfaceAdapter::StorageInterfaceAdapter(std::shared_ptr storage) : base_storage(std::move(storage)) { /* ... */ } diff --git a/stratosphere/ams_mitm/source/amsmitm_debug.cpp b/stratosphere/ams_mitm/source/amsmitm_debug.cpp deleted file mode 100644 index e4725ac80..000000000 --- a/stratosphere/ams_mitm/source/amsmitm_debug.cpp +++ /dev/null @@ -1,57 +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 "amsmitm_debug.hpp" - -namespace ams::mitm { - - namespace { - - os::Mutex g_throw_lock(false); - bool g_threw; - Result g_throw_result; - - - void DebugThrowThreadFunc(void *arg); - - constexpr size_t DebugThrowThreadStackSize = 0x4000; - os::ThreadType g_debug_throw_thread; - - alignas(os::ThreadStackAlignment) u8 g_debug_throw_thread_stack[DebugThrowThreadStackSize]; - - void DebugThrowThreadFunc(void *arg) { - /* TODO: Better heuristic for fatal startup than sleep. */ - os::SleepThread(TimeSpan::FromSeconds(10)); - fatalThrow(g_throw_result.GetValue()); - } - - } - - void ThrowResultForDebug(Result res) { - std::scoped_lock lk(g_throw_lock); - - if (g_threw) { - return; - } - - g_throw_result = res; - g_threw = true; - R_ABORT_UNLESS(os::CreateThread(std::addressof(g_debug_throw_thread), DebugThrowThreadFunc, nullptr, g_debug_throw_thread_stack, sizeof(g_debug_throw_thread_stack), AMS_GET_SYSTEM_THREAD_PRIORITY(mitm, DebugThrowThread))); - os::SetThreadNamePointer(std::addressof(g_debug_throw_thread), AMS_GET_SYSTEM_THREAD_NAME(mitm, DebugThrowThread)); - os::StartThread(std::addressof(g_debug_throw_thread)); - } - -} diff --git a/stratosphere/ams_mitm/source/amsmitm_debug.hpp b/stratosphere/ams_mitm/source/amsmitm_debug.hpp deleted file mode 100644 index 6e51775f5..000000000 --- a/stratosphere/ams_mitm/source/amsmitm_debug.hpp +++ /dev/null @@ -1,23 +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::mitm { - - void ThrowResultForDebug(Result res); - -} diff --git a/stratosphere/ams_mitm/source/amsmitm_main.cpp b/stratosphere/ams_mitm/source/amsmitm_main.cpp index 7e9b57bc8..3b914a755 100644 --- a/stratosphere/ams_mitm/source/amsmitm_main.cpp +++ b/stratosphere/ams_mitm/source/amsmitm_main.cpp @@ -37,6 +37,9 @@ extern "C" { alignas(16) u8 __nx_exception_stack[ams::os::MemoryPageSize]; u64 __nx_exception_stack_size = sizeof(__nx_exception_stack); void __libnx_exception_handler(ThreadExceptionDump *ctx); + + void *__libnx_thread_alloc(size_t size); + void __libnx_thread_free(void *mem); } namespace ams { @@ -107,6 +110,14 @@ void __appExit(void) { fsExit(); } +void *__libnx_thread_alloc(size_t size) { + AMS_ABORT("__libnx_thread_alloc was called"); +} + +void __libnx_thread_free(void *mem) { + AMS_ABORT("__libnx_thread_free was called"); +} + int main(int argc, char **argv) { /* Launch all mitm modules in sequence. */ mitm::LaunchAllModules(); diff --git a/stratosphere/ams_mitm/source/amsmitm_module_management.cpp b/stratosphere/ams_mitm/source/amsmitm_module_management.cpp index 03a7d779d..1bd12f55f 100644 --- a/stratosphere/ams_mitm/source/amsmitm_module_management.cpp +++ b/stratosphere/ams_mitm/source/amsmitm_module_management.cpp @@ -22,7 +22,6 @@ #include "bpc_mitm/bpcmitm_module.hpp" #include "bpc_mitm/bpc_ams_module.hpp" #include "ns_mitm/nsmitm_module.hpp" -#include "hid_mitm/hidmitm_module.hpp" #include "sysupdater/sysupdater_module.hpp" namespace ams::mitm { @@ -35,7 +34,6 @@ namespace ams::mitm { ModuleId_BpcMitm, ModuleId_BpcAms, ModuleId_NsMitm, - ModuleId_HidMitm, ModuleId_Sysupdater, ModuleId_Count, @@ -68,7 +66,6 @@ namespace ams::mitm { GetModuleDefinition(), GetModuleDefinition(), GetModuleDefinition(), - GetModuleDefinition(), GetModuleDefinition(), }; diff --git a/stratosphere/ams_mitm/source/bpc_mitm/bpc_ams_module.cpp b/stratosphere/ams_mitm/source/bpc_mitm/bpc_ams_module.cpp index 06a45b876..a3c80b640 100644 --- a/stratosphere/ams_mitm/source/bpc_mitm/bpc_ams_module.cpp +++ b/stratosphere/ams_mitm/source/bpc_mitm/bpc_ams_module.cpp @@ -30,6 +30,8 @@ namespace ams::mitm::bpc_ams { using ServerOptions = sf::hipc::DefaultServerManagerOptions; sf::hipc::ServerManager g_server_manager; + constinit sf::UnmanagedServiceObject g_ams_service_object; + } void MitmModule::ThreadFunction(void *arg) { @@ -37,7 +39,7 @@ namespace ams::mitm::bpc_ams { { Handle bpcams_h; R_ABORT_UNLESS(svcManageNamedPort(&bpcams_h, AtmosphereServiceName.name, AtmosphereMaxSessions)); - g_server_manager.RegisterServer(bpcams_h); + g_server_manager.RegisterObjectForServer(g_ams_service_object.GetShared(), bpcams_h); } /* Loop forever, servicing our services. */ diff --git a/stratosphere/ams_mitm/source/bpc_mitm/bpc_ams_service.hpp b/stratosphere/ams_mitm/source/bpc_mitm/bpc_ams_service.hpp index 234b92c91..6cbc88247 100644 --- a/stratosphere/ams_mitm/source/bpc_mitm/bpc_ams_service.hpp +++ b/stratosphere/ams_mitm/source/bpc_mitm/bpc_ams_service.hpp @@ -16,19 +16,15 @@ #pragma once #include +#define AMS_BPC_MITM_ATMOSPHERE_INTERFACE_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 65000, void, RebootToFatalError, (const ams::FatalErrorContext &ctx), (ctx)) \ + AMS_SF_METHOD_INFO(C, H, 65001, void, SetRebootPayload, (const ams::sf::InBuffer &payload), (payload)) + +AMS_SF_DEFINE_INTERFACE(ams::mitm::bpc::impl, IAtmosphereInterface, AMS_BPC_MITM_ATMOSPHERE_INTERFACE_INTERFACE_INFO) + namespace ams::mitm::bpc { - namespace impl { - - #define AMS_BPC_MITM_ATMOSPHERE_INTERFACE_INTERFACE_INFO(C, H) \ - AMS_SF_METHOD_INFO(C, H, 65000, void, RebootToFatalError, (const ams::FatalErrorContext &ctx)) \ - AMS_SF_METHOD_INFO(C, H, 65001, void, SetRebootPayload, (const ams::sf::InBuffer &payload)) - - AMS_SF_DEFINE_INTERFACE(IAtmosphereInterface, AMS_BPC_MITM_ATMOSPHERE_INTERFACE_INTERFACE_INFO) - - } - - class AtmosphereService final { + class AtmosphereService { public: void RebootToFatalError(const ams::FatalErrorContext &ctx); void SetRebootPayload(const ams::sf::InBuffer &payload); diff --git a/stratosphere/ams_mitm/source/bpc_mitm/bpc_mitm_service.hpp b/stratosphere/ams_mitm/source/bpc_mitm/bpc_mitm_service.hpp index de88296f5..b15d2f56d 100644 --- a/stratosphere/ams_mitm/source/bpc_mitm/bpc_mitm_service.hpp +++ b/stratosphere/ams_mitm/source/bpc_mitm/bpc_mitm_service.hpp @@ -16,18 +16,14 @@ #pragma once #include +#define AMS_BPC_MITM_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 0, Result, ShutdownSystem, (), ()) \ + AMS_SF_METHOD_INFO(C, H, 1, Result, RebootSystem, (), ()) + +AMS_SF_DEFINE_MITM_INTERFACE(ams::mitm::bpc::impl, IBpcMitmInterface, AMS_BPC_MITM_INTERFACE_INFO) + namespace ams::mitm::bpc { - namespace impl { - - #define AMS_BPC_MITM_INTERFACE_INFO(C, H) \ - AMS_SF_METHOD_INFO(C, H, 0, Result, ShutdownSystem, ()) \ - AMS_SF_METHOD_INFO(C, H, 1, Result, RebootSystem, ()) - - AMS_SF_DEFINE_MITM_INTERFACE(IBpcMitmInterface, AMS_BPC_MITM_INTERFACE_INFO) - - } - class BpcMitmService : public sf::MitmServiceImplBase { public: using MitmServiceImplBase::MitmServiceImplBase; diff --git a/stratosphere/ams_mitm/source/bpc_mitm/bpcmitm_module.cpp b/stratosphere/ams_mitm/source/bpc_mitm/bpcmitm_module.cpp index 75f7afc0c..3a186f6b3 100644 --- a/stratosphere/ams_mitm/source/bpc_mitm/bpcmitm_module.cpp +++ b/stratosphere/ams_mitm/source/bpc_mitm/bpcmitm_module.cpp @@ -22,14 +22,37 @@ namespace ams::mitm::bpc { namespace { + enum PortIndex { + PortIndex_Mitm, + PortIndex_Count, + }; + constexpr sm::ServiceName MitmServiceName = sm::ServiceName::Encode("bpc"); constexpr sm::ServiceName DeprecatedMitmServiceName = sm::ServiceName::Encode("bpc:c"); constexpr size_t MitmServiceMaxSessions = 13; - constexpr size_t MaxServers = 1; constexpr size_t MaxSessions = MitmServiceMaxSessions; using ServerOptions = sf::hipc::DefaultServerManagerOptions; - sf::hipc::ServerManager g_server_manager; + + class ServerManager final : public sf::hipc::ServerManager { + private: + virtual Result OnNeedsToAccept(int port_index, Server *server) override; + }; + + ServerManager g_server_manager; + + Result ServerManager::OnNeedsToAccept(int port_index, Server *server) { + /* Acknowledge the mitm session. */ + std::shared_ptr<::Service> fsrv; + sm::MitmProcessInfo client_info; + server->AcknowledgeMitmSession(std::addressof(fsrv), std::addressof(client_info)); + + switch (port_index) { + case PortIndex_Mitm: + return this->AcceptMitmImpl(server, sf::CreateSharedObjectEmplaced(decltype(fsrv)(fsrv), client_info), fsrv); + AMS_UNREACHABLE_DEFAULT_CASE(); + } + } } @@ -44,7 +67,8 @@ namespace ams::mitm::bpc { /* Create bpc mitm. */ const sm::ServiceName service_name = (hos::GetVersion() >= hos::Version_2_0_0) ? MitmServiceName : DeprecatedMitmServiceName; - R_ABORT_UNLESS((g_server_manager.RegisterMitmServer(service_name))); + + R_ABORT_UNLESS((g_server_manager.RegisterMitmServer(PortIndex_Mitm, service_name))); /* Loop forever, servicing our services. */ g_server_manager.LoopProcess(); diff --git a/stratosphere/ams_mitm/source/fs_mitm/fs_mitm_service.cpp b/stratosphere/ams_mitm/source/fs_mitm/fs_mitm_service.cpp index 1a925a347..2c2fdeca3 100644 --- a/stratosphere/ams_mitm/source/fs_mitm/fs_mitm_service.cpp +++ b/stratosphere/ams_mitm/source/fs_mitm/fs_mitm_service.cpp @@ -35,7 +35,8 @@ namespace ams::mitm::fs { constinit os::SdkMutex g_data_storage_lock; constinit os::SdkMutex g_storage_cache_lock; - std::unordered_map> g_storage_cache; + + std::unordered_map> g_storage_cache; constinit os::SdkMutex g_boot0_detect_lock; constinit bool g_detected_boot0_kind = false; @@ -54,7 +55,7 @@ namespace ams::mitm::fs { return g_is_boot0_custom_public_key; } - std::shared_ptr GetStorageCacheEntry(ncm::ProgramId program_id) { + std::shared_ptr GetStorageCacheEntry(ncm::ProgramId program_id) { std::scoped_lock lk(g_storage_cache_lock); auto it = g_storage_cache.find(static_cast(program_id)); @@ -65,7 +66,7 @@ namespace ams::mitm::fs { return it->second.lock(); } - void SetStorageCacheEntry(ncm::ProgramId program_id, std::shared_ptr *new_intf) { + void SetStorageCacheEntry(ncm::ProgramId program_id, std::shared_ptr *new_intf) { std::scoped_lock lk(g_storage_cache_lock); auto it = g_storage_cache.find(static_cast(program_id)); @@ -88,15 +89,15 @@ namespace ams::mitm::fs { template constexpr ALWAYS_INLINE auto MakeSharedFileSystem(Arguments &&... args) { - return sf::MakeShared(std::forward(args)...); + return sf::CreateSharedObjectEmplaced(std::forward(args)...); } template constexpr ALWAYS_INLINE auto MakeSharedStorage(Arguments &&... args) { - return sf::MakeShared(std::forward(args)...); + return sf::CreateSharedObjectEmplaced(std::forward(args)...); } - Result OpenHblWebContentFileSystem(sf::Out> &out, ncm::ProgramId client_program_id, ncm::ProgramId program_id, FsFileSystemType filesystem_type) { + Result OpenHblWebContentFileSystem(sf::Out> &out, ncm::ProgramId client_program_id, ncm::ProgramId program_id, FsFileSystemType filesystem_type) { /* Verify eligibility. */ bool is_hbl; R_UNLESS(R_SUCCEEDED(pm::info::IsHblProgramId(&is_hbl, program_id)), sm::mitm::ResultShouldForwardToSession()); @@ -119,7 +120,7 @@ namespace ams::mitm::fs { return ResultSuccess(); } - Result OpenProgramSpecificWebContentFileSystem(sf::Out> &out, ncm::ProgramId client_program_id, ncm::ProgramId program_id, FsFileSystemType filesystem_type, Service *fwd, const fssrv::sf::Path *path, bool with_id) { + Result OpenProgramSpecificWebContentFileSystem(sf::Out> &out, ncm::ProgramId client_program_id, ncm::ProgramId program_id, FsFileSystemType filesystem_type, Service *fwd, const fssrv::sf::Path *path, bool with_id) { /* Directory must exist. */ { FsDir d; @@ -165,7 +166,7 @@ namespace ams::mitm::fs { return ResultSuccess(); } - Result OpenWebContentFileSystem(sf::Out> &out, ncm::ProgramId client_program_id, ncm::ProgramId program_id, FsFileSystemType filesystem_type, Service *fwd, const fssrv::sf::Path *path, bool with_id, bool try_program_specific) { + Result OpenWebContentFileSystem(sf::Out> &out, ncm::ProgramId client_program_id, ncm::ProgramId program_id, FsFileSystemType filesystem_type, Service *fwd, const fssrv::sf::Path *path, bool with_id, bool try_program_specific) { /* Check first that we're a web applet opening web content. */ R_UNLESS(ncm::IsWebAppletId(client_program_id), sm::mitm::ResultShouldForwardToSession()); R_UNLESS(filesystem_type == FsFileSystemType_ContentManual, sm::mitm::ResultShouldForwardToSession()); @@ -182,15 +183,15 @@ namespace ams::mitm::fs { } - Result FsMitmService::OpenFileSystemWithPatch(sf::Out> out, ncm::ProgramId program_id, u32 _filesystem_type) { + Result FsMitmService::OpenFileSystemWithPatch(sf::Out> out, ncm::ProgramId program_id, u32 _filesystem_type) { return OpenWebContentFileSystem(out, this->client_info.program_id, program_id, static_cast(_filesystem_type), this->forward_service.get(), nullptr, false, this->client_info.override_status.IsProgramSpecific()); } - Result FsMitmService::OpenFileSystemWithId(sf::Out> out, const fssrv::sf::Path &path, ncm::ProgramId program_id, u32 _filesystem_type) { + Result FsMitmService::OpenFileSystemWithId(sf::Out> out, const fssrv::sf::Path &path, ncm::ProgramId program_id, u32 _filesystem_type) { return OpenWebContentFileSystem(out, this->client_info.program_id, program_id, static_cast(_filesystem_type), this->forward_service.get(), std::addressof(path), true, this->client_info.override_status.IsProgramSpecific()); } - Result FsMitmService::OpenSdCardFileSystem(sf::Out> out) { + Result FsMitmService::OpenSdCardFileSystem(sf::Out> out) { /* We only care about redirecting this for NS/emummc. */ R_UNLESS(this->client_info.program_id == ncm::SystemProgramId::Ns, sm::mitm::ResultShouldForwardToSession()); R_UNLESS(emummc::IsActive(), sm::mitm::ResultShouldForwardToSession()); @@ -206,7 +207,7 @@ namespace ams::mitm::fs { return ResultSuccess(); } - Result FsMitmService::OpenSaveDataFileSystem(sf::Out> out, u8 _space_id, const fs::SaveDataAttribute &attribute) { + Result FsMitmService::OpenSaveDataFileSystem(sf::Out> out, u8 _space_id, const fs::SaveDataAttribute &attribute) { /* We only want to intercept saves for games, right now. */ const bool is_game_or_hbl = this->client_info.override_status.IsHbl() || ncm::IsApplicationId(this->client_info.program_id); R_UNLESS(is_game_or_hbl, sm::mitm::ResultShouldForwardToSession()); @@ -271,7 +272,7 @@ namespace ams::mitm::fs { return ResultSuccess(); } - Result FsMitmService::OpenBisStorage(sf::Out> out, u32 _bis_partition_id) { + Result FsMitmService::OpenBisStorage(sf::Out> out, u32 _bis_partition_id) { const ::FsBisPartitionId bis_partition_id = static_cast<::FsBisPartitionId>(_bis_partition_id); /* Try to open a storage for the partition. */ @@ -312,7 +313,7 @@ namespace ams::mitm::fs { return ResultSuccess(); } - Result FsMitmService::OpenDataStorageByCurrentProcess(sf::Out> out) { + Result FsMitmService::OpenDataStorageByCurrentProcess(sf::Out> out) { /* Only mitm if we should override contents for the current process. */ R_UNLESS(this->client_info.override_status.IsProgramSpecific(), sm::mitm::ResultShouldForwardToSession()); @@ -329,37 +330,37 @@ namespace ams::mitm::fs { /* Try to get a storage from the cache. */ { - std::shared_ptr cached_storage = GetStorageCacheEntry(this->client_info.program_id); + std::shared_ptr cached_storage = GetStorageCacheEntry(this->client_info.program_id); if (cached_storage != nullptr) { - out.SetValue(std::move(cached_storage), target_object_id); + out.SetValue(MakeSharedStorage(cached_storage), target_object_id); return ResultSuccess(); } } /* Make a new layered romfs, and cache to storage. */ { - std::shared_ptr new_storage_intf = nullptr; + std::shared_ptr new_storage = nullptr; /* Create the layered storage. */ FsFile data_file; if (R_SUCCEEDED(OpenAtmosphereSdFile(&data_file, this->client_info.program_id, "romfs.bin", OpenMode_Read))) { auto layered_storage = std::make_shared(std::make_unique(new RemoteStorage(data_storage)), std::make_unique(new FileStorage(new RemoteFile(data_file))), this->client_info.program_id); layered_storage->BeginInitialize(); - new_storage_intf = MakeSharedStorage(layered_storage); + new_storage = std::move(layered_storage); } else { auto layered_storage = std::make_shared(std::make_unique(new RemoteStorage(data_storage)), nullptr, this->client_info.program_id); layered_storage->BeginInitialize(); - new_storage_intf = MakeSharedStorage(layered_storage); + new_storage = std::move(layered_storage); } - SetStorageCacheEntry(this->client_info.program_id, &new_storage_intf); - out.SetValue(std::move(new_storage_intf), target_object_id); + SetStorageCacheEntry(this->client_info.program_id, &new_storage); + out.SetValue(MakeSharedStorage(new_storage), target_object_id); } return ResultSuccess(); } - Result FsMitmService::OpenDataStorageByDataId(sf::Out> out, ncm::DataId _data_id, u8 storage_id) { + Result FsMitmService::OpenDataStorageByDataId(sf::Out> out, ncm::DataId _data_id, u8 storage_id) { /* Only mitm if we should override contents for the current process. */ R_UNLESS(this->client_info.override_status.IsProgramSpecific(), sm::mitm::ResultShouldForwardToSession()); @@ -379,31 +380,31 @@ namespace ams::mitm::fs { /* Try to get a storage from the cache. */ { - std::shared_ptr cached_storage = GetStorageCacheEntry(data_id); + std::shared_ptr cached_storage = GetStorageCacheEntry(this->client_info.program_id); if (cached_storage != nullptr) { - out.SetValue(std::move(cached_storage), target_object_id); + out.SetValue(MakeSharedStorage(cached_storage), target_object_id); return ResultSuccess(); } } /* Make a new layered romfs, and cache to storage. */ { - std::shared_ptr new_storage_intf = nullptr; + std::shared_ptr new_storage = nullptr; /* Create the layered storage. */ FsFile data_file; if (R_SUCCEEDED(OpenAtmosphereSdFile(&data_file, data_id, "romfs.bin", OpenMode_Read))) { auto layered_storage = std::make_shared(std::make_unique(new RemoteStorage(data_storage)), std::make_unique(new FileStorage(new RemoteFile(data_file))), data_id); layered_storage->BeginInitialize(); - new_storage_intf = MakeSharedStorage(layered_storage); + new_storage = std::move(layered_storage); } else { auto layered_storage = std::make_shared(std::make_unique(new RemoteStorage(data_storage)), nullptr, data_id); layered_storage->BeginInitialize(); - new_storage_intf = MakeSharedStorage(layered_storage); + new_storage = std::move(layered_storage); } - SetStorageCacheEntry(data_id, &new_storage_intf); - out.SetValue(std::move(new_storage_intf), target_object_id); + SetStorageCacheEntry(this->client_info.program_id, &new_storage); + out.SetValue(MakeSharedStorage(new_storage), target_object_id); } return ResultSuccess(); diff --git a/stratosphere/ams_mitm/source/fs_mitm/fs_mitm_service.hpp b/stratosphere/ams_mitm/source/fs_mitm/fs_mitm_service.hpp index d674b197a..1593eebf9 100644 --- a/stratosphere/ams_mitm/source/fs_mitm/fs_mitm_service.hpp +++ b/stratosphere/ams_mitm/source/fs_mitm/fs_mitm_service.hpp @@ -13,28 +13,23 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - #pragma once #include #include +#define AMS_FS_MITM_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 7, Result, OpenFileSystemWithPatch, (sf::Out> out, ncm::ProgramId program_id, u32 _filesystem_type), (out, program_id, _filesystem_type), hos::Version_2_0_0) \ + AMS_SF_METHOD_INFO(C, H, 8, Result, OpenFileSystemWithId, (sf::Out> out, const fssrv::sf::Path &path, ncm::ProgramId program_id, u32 _filesystem_type), (out, path, program_id, _filesystem_type), hos::Version_2_0_0) \ + AMS_SF_METHOD_INFO(C, H, 18, Result, OpenSdCardFileSystem, (sf::Out> out), (out)) \ + AMS_SF_METHOD_INFO(C, H, 51, Result, OpenSaveDataFileSystem, (sf::Out> out, u8 space_id, const ams::fs::SaveDataAttribute &attribute), (out, space_id, attribute)) \ + AMS_SF_METHOD_INFO(C, H, 12, Result, OpenBisStorage, (sf::Out> out, u32 bis_partition_id), (out, bis_partition_id)) \ + AMS_SF_METHOD_INFO(C, H, 200, Result, OpenDataStorageByCurrentProcess, (sf::Out> out), (out)) \ + AMS_SF_METHOD_INFO(C, H, 202, Result, OpenDataStorageByDataId, (sf::Out> out, ncm::DataId data_id, u8 storage_id), (out, data_id, storage_id)) + +AMS_SF_DEFINE_MITM_INTERFACE(ams::mitm::fs, IFsMitmInterface, AMS_FS_MITM_INTERFACE_INFO) + namespace ams::mitm::fs { - namespace { - - #define AMS_FS_MITM_INTERFACE_INFO(C, H) \ - AMS_SF_METHOD_INFO(C, H, 7, Result, OpenFileSystemWithPatch, (sf::Out> out, ncm::ProgramId program_id, u32 _filesystem_type), hos::Version_2_0_0) \ - AMS_SF_METHOD_INFO(C, H, 8, Result, OpenFileSystemWithId, (sf::Out> out, const fssrv::sf::Path &path, ncm::ProgramId program_id, u32 _filesystem_type), hos::Version_2_0_0) \ - AMS_SF_METHOD_INFO(C, H, 18, Result, OpenSdCardFileSystem, (sf::Out> out)) \ - AMS_SF_METHOD_INFO(C, H, 51, Result, OpenSaveDataFileSystem, (sf::Out> out, u8 space_id, const ams::fs::SaveDataAttribute &attribute)) \ - AMS_SF_METHOD_INFO(C, H, 12, Result, OpenBisStorage, (sf::Out> out, u32 bis_partition_id)) \ - AMS_SF_METHOD_INFO(C, H, 200, Result, OpenDataStorageByCurrentProcess, (sf::Out> out)) \ - AMS_SF_METHOD_INFO(C, H, 202, Result, OpenDataStorageByDataId, (sf::Out> out, ncm::DataId data_id, u8 storage_id)) - - AMS_SF_DEFINE_MITM_INTERFACE(IFsMitmInterface, AMS_FS_MITM_INTERFACE_INFO) - - } - class FsMitmService : public sf::MitmServiceImplBase { public: using MitmServiceImplBase::MitmServiceImplBase; @@ -78,13 +73,14 @@ namespace ams::mitm::fs { } public: /* Overridden commands. */ - Result OpenFileSystemWithPatch(sf::Out> out, ncm::ProgramId program_id, u32 _filesystem_type); - Result OpenFileSystemWithId(sf::Out> out, const fssrv::sf::Path &path, ncm::ProgramId program_id, u32 _filesystem_type); - Result OpenSdCardFileSystem(sf::Out> out); - Result OpenSaveDataFileSystem(sf::Out> out, u8 space_id, const ams::fs::SaveDataAttribute &attribute); - Result OpenBisStorage(sf::Out> out, u32 bis_partition_id); - Result OpenDataStorageByCurrentProcess(sf::Out> out); - Result OpenDataStorageByDataId(sf::Out> out, ncm::DataId data_id, u8 storage_id); + Result OpenFileSystemWithPatch(sf::Out> out, ncm::ProgramId program_id, u32 _filesystem_type); + Result OpenFileSystemWithId(sf::Out> out, const fssrv::sf::Path &path, ncm::ProgramId program_id, u32 _filesystem_type); + Result OpenSdCardFileSystem(sf::Out> out); + Result OpenSaveDataFileSystem(sf::Out> out, u8 space_id, const ams::fs::SaveDataAttribute &attribute); + Result OpenBisStorage(sf::Out> out, u32 bis_partition_id); + Result OpenDataStorageByCurrentProcess(sf::Out> out); + Result OpenDataStorageByDataId(sf::Out> out, ncm::DataId data_id, u8 storage_id); }; + static_assert(IsIFsMitmInterface); } diff --git a/stratosphere/ams_mitm/source/fs_mitm/fsmitm_module.cpp b/stratosphere/ams_mitm/source/fs_mitm/fsmitm_module.cpp index ad0894d5c..cc9bc418b 100644 --- a/stratosphere/ams_mitm/source/fs_mitm/fsmitm_module.cpp +++ b/stratosphere/ams_mitm/source/fs_mitm/fsmitm_module.cpp @@ -21,6 +21,11 @@ namespace ams::mitm::fs { namespace { + enum PortIndex { + PortIndex_Mitm, + PortIndex_Count, + }; + constexpr sm::ServiceName MitmServiceName = sm::ServiceName::Encode("fsp-srv"); struct ServerOptions { @@ -29,10 +34,27 @@ namespace ams::mitm::fs { static constexpr size_t MaxDomainObjects = 0x4000; }; - constexpr size_t MaxServers = 1; constexpr size_t MaxSessions = 61; - sf::hipc::ServerManager g_server_manager; + class ServerManager final : public sf::hipc::ServerManager { + private: + virtual Result OnNeedsToAccept(int port_index, Server *server) override; + }; + + ServerManager g_server_manager; + + Result ServerManager::OnNeedsToAccept(int port_index, Server *server) { + /* Acknowledge the mitm session. */ + std::shared_ptr<::Service> fsrv; + sm::MitmProcessInfo client_info; + server->AcknowledgeMitmSession(std::addressof(fsrv), std::addressof(client_info)); + + switch (port_index) { + case PortIndex_Mitm: + return this->AcceptMitmImpl(server, sf::CreateSharedObjectEmplaced(decltype(fsrv)(fsrv), client_info), fsrv); + AMS_UNREACHABLE_DEFAULT_CASE(); + } + } constexpr size_t TotalThreads = 5; static_assert(TotalThreads >= 1, "TotalThreads"); @@ -78,7 +100,7 @@ namespace ams::mitm::fs { void MitmModule::ThreadFunction(void *arg) { /* Create fs mitm. */ - R_ABORT_UNLESS((g_server_manager.RegisterMitmServer(MitmServiceName))); + R_ABORT_UNLESS((g_server_manager.RegisterMitmServer(PortIndex_Mitm, MitmServiceName))); /* Process for the server. */ ProcessForServerOnAllThreads(); diff --git a/stratosphere/ams_mitm/source/hid_mitm/hid_mitm_service.cpp b/stratosphere/ams_mitm/source/hid_mitm/hid_mitm_service.cpp deleted file mode 100644 index f4d220749..000000000 --- a/stratosphere/ams_mitm/source/hid_mitm/hid_mitm_service.cpp +++ /dev/null @@ -1,28 +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 "hid_mitm_service.hpp" -#include "hid_shim.h" - -namespace ams::mitm::hid { - - Result HidMitmService::SetSupportedNpadStyleSet(const sf::ClientAppletResourceUserId &client_aruid, u32 style_set) { - /* This code applies only to hbl, guaranteed by the check in ShouldMitm. */ - style_set |= HidNpadStyleTag_NpadSystem | HidNpadStyleTag_NpadSystemExt; - return hidSetSupportedNpadStyleSetFwd(this->forward_service.get(), static_cast(this->client_info.process_id), static_cast(client_aruid.GetValue()), style_set); - } - -} diff --git a/stratosphere/ams_mitm/source/hid_mitm/hid_mitm_service.hpp b/stratosphere/ams_mitm/source/hid_mitm/hid_mitm_service.hpp deleted file mode 100644 index 53beaf305..000000000 --- a/stratosphere/ams_mitm/source/hid_mitm/hid_mitm_service.hpp +++ /dev/null @@ -1,48 +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::mitm::hid { - - namespace { - - #define AMS_HID_MITM_INTERFACE_INFO(C, H) \ - AMS_SF_METHOD_INFO(C, H, 100, Result, SetSupportedNpadStyleSet, (const sf::ClientAppletResourceUserId &client_aruid, u32 style_set)) - - AMS_SF_DEFINE_MITM_INTERFACE(IHidMitmInterface, AMS_HID_MITM_INTERFACE_INFO) - - } - - class HidMitmService : public sf::MitmServiceImplBase { - public: - using MitmServiceImplBase::MitmServiceImplBase; - public: - static bool ShouldMitm(const sm::MitmProcessInfo &client_info) { - /* TODO: Remove in Atmosphere 0.10.2. */ - /* We will mitm: - * - hbl, to help homebrew not need to be recompiled. - */ - return client_info.override_status.IsHbl(); - } - public: - /* Overridden commands. */ - Result SetSupportedNpadStyleSet(const sf::ClientAppletResourceUserId &client_aruid, u32 style_set); - }; - static_assert(IsIHidMitmInterface); - -} diff --git a/stratosphere/ams_mitm/source/hid_mitm/hid_shim.c b/stratosphere/ams_mitm/source/hid_mitm/hid_shim.c deleted file mode 100644 index 7652e937a..000000000 --- a/stratosphere/ams_mitm/source/hid_mitm/hid_shim.c +++ /dev/null @@ -1,27 +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 "hid_shim.h" -#include - -/* Command forwarders. */ -Result hidSetSupportedNpadStyleSetFwd(Service* s, u64 process_id, u64 aruid, u32 style_set) { - const struct { - u32 style_set; - u32 pad; - u64 aruid; - } in = { style_set, 0, aruid }; - return serviceMitmDispatchIn(s, 100, in, .in_send_pid = true, .override_pid = process_id); -} diff --git a/stratosphere/ams_mitm/source/hid_mitm/hid_shim.h b/stratosphere/ams_mitm/source/hid_mitm/hid_shim.h deleted file mode 100644 index 451981a50..000000000 --- a/stratosphere/ams_mitm/source/hid_mitm/hid_shim.h +++ /dev/null @@ -1,19 +0,0 @@ -/** - * @file hid_shim.h - * @brief Human Interface Devices Services (hid) IPC wrapper. - * @author SciresM - * @copyright libnx Authors - */ -#pragma once -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/* Command forwarders. */ -Result hidSetSupportedNpadStyleSetFwd(Service* s, u64 process_id, u64 aruid, u32 style_set); - -#ifdef __cplusplus -} -#endif \ No newline at end of file diff --git a/stratosphere/ams_mitm/source/hid_mitm/hidmitm_module.cpp b/stratosphere/ams_mitm/source/hid_mitm/hidmitm_module.cpp deleted file mode 100644 index 583095376..000000000 --- a/stratosphere/ams_mitm/source/hid_mitm/hidmitm_module.cpp +++ /dev/null @@ -1,68 +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 "../amsmitm_initialization.hpp" -#include "hidmitm_module.hpp" -#include "hid_mitm_service.hpp" - -namespace ams::mitm::hid { - - namespace { - - constexpr sm::ServiceName MitmServiceName = sm::ServiceName::Encode("hid"); - - struct ServerOptions { - static constexpr size_t PointerBufferSize = 0x200; - static constexpr size_t MaxDomains = 0; - static constexpr size_t MaxDomainObjects = 0; - }; - - constexpr size_t MaxServers = 1; - sf::hipc::ServerManager g_server_manager; - - bool ShouldMitmHidForCompability() { - u8 en = 0; - if (settings::fwdbg::GetSettingsItemValue(&en, sizeof(en), "atmosphere", "enable_deprecated_hid_mitm") == sizeof(en)) { - return (en != 0); - } - return false; - } - - } - - void MitmModule::ThreadFunction(void *arg) { - /* This is only necessary on 9.x+ */ - if (hos::GetVersion() < hos::Version_9_0_0) { - return; - } - - /* Wait until initialization is complete. */ - mitm::WaitInitialized(); - - /* hid mitm was a temporary solution for compatibility. */ - /* Unless we are configured to continue doing so, don't instantiate the mitm. */ - if (!ShouldMitmHidForCompability()) { - return; - } - - /* Create hid mitm. */ - R_ABORT_UNLESS((g_server_manager.RegisterMitmServer(MitmServiceName))); - - /* Loop forever, servicing our services. */ - g_server_manager.LoopProcess(); - } - -} diff --git a/stratosphere/ams_mitm/source/hid_mitm/hidmitm_module.hpp b/stratosphere/ams_mitm/source/hid_mitm/hidmitm_module.hpp deleted file mode 100644 index 025540e4a..000000000 --- a/stratosphere/ams_mitm/source/hid_mitm/hidmitm_module.hpp +++ /dev/null @@ -1,24 +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 -#include "../amsmitm_module.hpp" - -namespace ams::mitm::hid { - - DEFINE_MITM_MODULE_CLASS(0x8000, AMS_GET_SYSTEM_THREAD_PRIORITY(hid, IpcServer)); - -} diff --git a/stratosphere/ams_mitm/source/ns_mitm/ns_am_mitm_service.hpp b/stratosphere/ams_mitm/source/ns_mitm/ns_am_mitm_service.hpp index f84f3f6c0..f5dcf9906 100644 --- a/stratosphere/ams_mitm/source/ns_mitm/ns_am_mitm_service.hpp +++ b/stratosphere/ams_mitm/source/ns_mitm/ns_am_mitm_service.hpp @@ -16,19 +16,15 @@ #pragma once #include +#define AMS_NS_AM_MITM_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 21, Result, GetApplicationContentPath, (const sf::OutBuffer &out_path, ncm::ProgramId application_id, u8 content_type), (out_path, application_id, content_type)) \ + AMS_SF_METHOD_INFO(C, H, 23, Result, ResolveApplicationContentPath, (ncm::ProgramId application_id, u8 content_type), (application_id, content_type)) \ + AMS_SF_METHOD_INFO(C, H, 92, Result, GetRunningApplicationProgramId, (sf::Out out, ncm::ProgramId application_id), (out, application_id), hos::Version_6_0_0) + +AMS_SF_DEFINE_MITM_INTERFACE(ams::mitm::ns::impl, IAmMitmInterface, AMS_NS_AM_MITM_INTERFACE_INFO) + namespace ams::mitm::ns { - namespace impl { - - #define AMS_NS_AM_MITM_INTERFACE_INFO(C, H) \ - AMS_SF_METHOD_INFO(C, H, 21, Result, GetApplicationContentPath, (const sf::OutBuffer &out_path, ncm::ProgramId application_id, u8 content_type)) \ - AMS_SF_METHOD_INFO(C, H, 23, Result, ResolveApplicationContentPath, (ncm::ProgramId application_id, u8 content_type)) \ - AMS_SF_METHOD_INFO(C, H, 92, Result, GetRunningApplicationProgramId, (sf::Out out, ncm::ProgramId application_id), hos::Version_6_0_0) - - AMS_SF_DEFINE_MITM_INTERFACE(IAmMitmInterface, AMS_NS_AM_MITM_INTERFACE_INFO) - - } - class NsAmMitmService : public sf::MitmServiceImplBase { public: using MitmServiceImplBase::MitmServiceImplBase; diff --git a/stratosphere/ams_mitm/source/ns_mitm/ns_web_mitm_service.cpp b/stratosphere/ams_mitm/source/ns_mitm/ns_web_mitm_service.cpp index f364b5401..0db57f5de 100644 --- a/stratosphere/ams_mitm/source/ns_mitm/ns_web_mitm_service.cpp +++ b/stratosphere/ams_mitm/source/ns_mitm/ns_web_mitm_service.cpp @@ -37,13 +37,13 @@ namespace ams::mitm::ns { return nswebGetRunningApplicationProgramId(this->srv.get(), reinterpret_cast(out.GetPointer()), static_cast(application_id)); } - Result NsWebMitmService::GetDocumentInterface(sf::Out> out) { + Result NsWebMitmService::GetDocumentInterface(sf::Out> out) { /* Open a document interface. */ NsDocumentInterface doc; R_TRY(nsGetDocumentInterfaceFwd(this->forward_service.get(), &doc)); const sf::cmif::DomainObjectId target_object_id{serviceGetObjectId(&doc.s)}; - out.SetValue(sf::MakeShared(this->client_info, std::make_unique(doc)), target_object_id); + out.SetValue(sf::CreateSharedObjectEmplaced(this->client_info, std::make_unique(doc)), target_object_id); return ResultSuccess(); } diff --git a/stratosphere/ams_mitm/source/ns_mitm/ns_web_mitm_service.hpp b/stratosphere/ams_mitm/source/ns_mitm/ns_web_mitm_service.hpp index 8f7574ee8..026ab2bb4 100644 --- a/stratosphere/ams_mitm/source/ns_mitm/ns_web_mitm_service.hpp +++ b/stratosphere/ams_mitm/source/ns_mitm/ns_web_mitm_service.hpp @@ -18,24 +18,20 @@ #include "ns_shim.h" +#define AMS_NS_DOCUMENT_MITM_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 21, Result, GetApplicationContentPath, (const sf::OutBuffer &out_path, ncm::ProgramId application_id, u8 content_type), (out_path, application_id, content_type)) \ + AMS_SF_METHOD_INFO(C, H, 23, Result, ResolveApplicationContentPath, (ncm::ProgramId application_id, u8 content_type), (application_id, content_type)) \ + AMS_SF_METHOD_INFO(C, H, 92, Result, GetRunningApplicationProgramId, (sf::Out out, ncm::ProgramId application_id), (out, application_id), hos::Version_6_0_0) + +AMS_SF_DEFINE_INTERFACE(ams::mitm::ns::impl, IDocumentInterface, AMS_NS_DOCUMENT_MITM_INTERFACE_INFO) + +#define AMS_NS_WEB_MITM_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 7999, Result, GetDocumentInterface, (sf::Out> out), (out)) + +AMS_SF_DEFINE_MITM_INTERFACE(ams::mitm::ns::impl, IWebMitmInterface, AMS_NS_WEB_MITM_INTERFACE_INFO) + namespace ams::mitm::ns { - namespace impl { - - #define AMS_NS_DOCUMENT_MITM_INTERFACE_INFO(C, H) \ - AMS_SF_METHOD_INFO(C, H, 21, Result, GetApplicationContentPath, (const sf::OutBuffer &out_path, ncm::ProgramId application_id, u8 content_type)) \ - AMS_SF_METHOD_INFO(C, H, 23, Result, ResolveApplicationContentPath, (ncm::ProgramId application_id, u8 content_type)) \ - AMS_SF_METHOD_INFO(C, H, 92, Result, GetRunningApplicationProgramId, (sf::Out out, ncm::ProgramId application_id), hos::Version_6_0_0) - - AMS_SF_DEFINE_INTERFACE(IDocumentInterface, AMS_NS_DOCUMENT_MITM_INTERFACE_INFO) - - #define AMS_NS_WEB_MITM_INTERFACE_INFO(C, H) \ - AMS_SF_METHOD_INFO(C, H, 7999, Result, GetDocumentInterface, (sf::Out> out)) - - AMS_SF_DEFINE_MITM_INTERFACE(IWebMitmInterface, AMS_NS_WEB_MITM_INTERFACE_INFO) - - } - class NsDocumentService { private: sm::MitmProcessInfo client_info; @@ -65,7 +61,7 @@ namespace ams::mitm::ns { return ncm::IsWebAppletId(client_info.program_id); } public: - Result GetDocumentInterface(sf::Out> out); + Result GetDocumentInterface(sf::Out> out); }; static_assert(impl::IsIWebMitmInterface); diff --git a/stratosphere/ams_mitm/source/ns_mitm/nsmitm_module.cpp b/stratosphere/ams_mitm/source/ns_mitm/nsmitm_module.cpp index 4a7a708ac..95530b72c 100644 --- a/stratosphere/ams_mitm/source/ns_mitm/nsmitm_module.cpp +++ b/stratosphere/ams_mitm/source/ns_mitm/nsmitm_module.cpp @@ -23,13 +23,41 @@ namespace ams::mitm::ns { namespace { + enum PortIndex { + PortIndex_Mitm, + PortIndex_Count, + }; + constexpr sm::ServiceName NsAmMitmServiceName = sm::ServiceName::Encode("ns:am"); constexpr sm::ServiceName NsWebMitmServiceName = sm::ServiceName::Encode("ns:web"); - constexpr size_t MaxServers = 1; constexpr size_t MaxSessions = 5; using ServerOptions = sf::hipc::DefaultServerManagerOptions; - sf::hipc::ServerManager g_server_manager; + + class ServerManager final : public sf::hipc::ServerManager { + private: + virtual Result OnNeedsToAccept(int port_index, Server *server) override; + }; + + ServerManager g_server_manager; + + Result ServerManager::OnNeedsToAccept(int port_index, Server *server) { + /* Acknowledge the mitm session. */ + std::shared_ptr<::Service> fsrv; + sm::MitmProcessInfo client_info; + server->AcknowledgeMitmSession(std::addressof(fsrv), std::addressof(client_info)); + + switch (port_index) { + case PortIndex_Mitm: + if (hos::GetVersion() < hos::Version_3_0_0) { + return this->AcceptMitmImpl(server, sf::CreateSharedObjectEmplaced(decltype(fsrv)(fsrv), client_info), fsrv); + } else { + return this->AcceptMitmImpl(server, sf::CreateSharedObjectEmplaced(decltype(fsrv)(fsrv), client_info), fsrv); + } + + AMS_UNREACHABLE_DEFAULT_CASE(); + } + } } @@ -39,9 +67,9 @@ namespace ams::mitm::ns { /* Create mitm servers. */ if (hos::GetVersion() < hos::Version_3_0_0) { - R_ABORT_UNLESS((g_server_manager.RegisterMitmServer(NsAmMitmServiceName))); + R_ABORT_UNLESS((g_server_manager.RegisterMitmServer(PortIndex_Mitm, NsAmMitmServiceName))); } else { - R_ABORT_UNLESS((g_server_manager.RegisterMitmServer(NsWebMitmServiceName))); + R_ABORT_UNLESS((g_server_manager.RegisterMitmServer(PortIndex_Mitm, NsWebMitmServiceName))); } /* Loop forever, servicing our services. */ diff --git a/stratosphere/ams_mitm/source/set_mitm/set_mitm_service.hpp b/stratosphere/ams_mitm/source/set_mitm/set_mitm_service.hpp index a69bcaefd..c10161b11 100644 --- a/stratosphere/ams_mitm/source/set_mitm/set_mitm_service.hpp +++ b/stratosphere/ams_mitm/source/set_mitm/set_mitm_service.hpp @@ -16,21 +16,17 @@ #pragma once #include +#define AMS_SETTINGS_MITM_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 0, Result, GetLanguageCode, (sf::Out out), (out)) \ + AMS_SF_METHOD_INFO(C, H, 4, Result, GetRegionCode, (sf::Out out), (out)) + +AMS_SF_DEFINE_MITM_INTERFACE(ams::mitm::settings, ISetMitmInterface, AMS_SETTINGS_MITM_INTERFACE_INFO) + namespace ams::mitm::settings { - namespace { - - #define AMS_SETTINGS_MITM_INTERFACE_INFO(C, H) \ - AMS_SF_METHOD_INFO(C, H, 0, Result, GetLanguageCode, (sf::Out out)) \ - AMS_SF_METHOD_INFO(C, H, 4, Result, GetRegionCode, (sf::Out out)) - - AMS_SF_DEFINE_MITM_INTERFACE(ISetMitmInterface, AMS_SETTINGS_MITM_INTERFACE_INFO) - - } - class SetMitmService : public sf::MitmServiceImplBase { private: - os::Mutex lock{false}; + os::SdkMutex lock{}; cfg::OverrideLocale locale; bool got_locale = false; bool is_valid_language = false; diff --git a/stratosphere/ams_mitm/source/set_mitm/setmitm_module.cpp b/stratosphere/ams_mitm/source/set_mitm/setmitm_module.cpp index 787e285e8..b746f7fde 100644 --- a/stratosphere/ams_mitm/source/set_mitm/setmitm_module.cpp +++ b/stratosphere/ams_mitm/source/set_mitm/setmitm_module.cpp @@ -23,6 +23,12 @@ namespace ams::mitm::settings { namespace { + enum PortIndex { + PortIndex_SetMitm, + PortIndex_SetSysMitm, + PortIndex_Count, + }; + constexpr sm::ServiceName SetMitmServiceName = sm::ServiceName::Encode("set"); constexpr sm::ServiceName SetSysMitmServiceName = sm::ServiceName::Encode("set:sys"); @@ -32,9 +38,29 @@ namespace ams::mitm::settings { static constexpr size_t MaxDomainObjects = 0; }; - constexpr size_t MaxServers = 2; constexpr size_t MaxSessions = 60; - sf::hipc::ServerManager g_server_manager; + + class ServerManager final : public sf::hipc::ServerManager { + private: + virtual Result OnNeedsToAccept(int port_index, Server *server) override; + }; + + ServerManager g_server_manager; + + Result ServerManager::OnNeedsToAccept(int port_index, Server *server) { + /* Acknowledge the mitm session. */ + std::shared_ptr<::Service> fsrv; + sm::MitmProcessInfo client_info; + server->AcknowledgeMitmSession(std::addressof(fsrv), std::addressof(client_info)); + + switch (port_index) { + case PortIndex_SetMitm: + return this->AcceptMitmImpl(server, sf::CreateSharedObjectEmplaced(decltype(fsrv)(fsrv), client_info), fsrv); + case PortIndex_SetSysMitm: + return this->AcceptMitmImpl(server, sf::CreateSharedObjectEmplaced(decltype(fsrv)(fsrv), client_info), fsrv); + AMS_UNREACHABLE_DEFAULT_CASE(); + } + } } @@ -43,8 +69,8 @@ namespace ams::mitm::settings { mitm::WaitInitialized(); /* Create mitm servers. */ - R_ABORT_UNLESS((g_server_manager.RegisterMitmServer(SetMitmServiceName))); - R_ABORT_UNLESS((g_server_manager.RegisterMitmServer(SetSysMitmServiceName))); + R_ABORT_UNLESS((g_server_manager.RegisterMitmServer(PortIndex_SetMitm, SetMitmServiceName))); + R_ABORT_UNLESS((g_server_manager.RegisterMitmServer(PortIndex_SetSysMitm, SetSysMitmServiceName))); /* Loop forever, servicing our services. */ g_server_manager.LoopProcess(); diff --git a/stratosphere/ams_mitm/source/set_mitm/setsys_mitm_service.hpp b/stratosphere/ams_mitm/source/set_mitm/setsys_mitm_service.hpp index f91fbb183..b49a02fbc 100644 --- a/stratosphere/ams_mitm/source/set_mitm/setsys_mitm_service.hpp +++ b/stratosphere/ams_mitm/source/set_mitm/setsys_mitm_service.hpp @@ -16,21 +16,17 @@ #pragma once #include +#define AMS_SETTINGS_SYSTEM_MITM_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 3, Result, GetFirmwareVersion, (sf::Out out), (out)) \ + AMS_SF_METHOD_INFO(C, H, 4, Result, GetFirmwareVersion2, (sf::Out out), (out)) \ + AMS_SF_METHOD_INFO(C, H, 37, Result, GetSettingsItemValueSize, (sf::Out out_size, const ams::settings::fwdbg::SettingsName &name, const ams::settings::fwdbg::SettingsItemKey &key), (out_size, name, key)) \ + AMS_SF_METHOD_INFO(C, H, 38, Result, GetSettingsItemValue, (sf::Out out_size, const sf::OutBuffer &out, const ams::settings::fwdbg::SettingsName &name, const ams::settings::fwdbg::SettingsItemKey &key), (out_size, out, name, key)) \ + AMS_SF_METHOD_INFO(C, H, 62, Result, GetDebugModeFlag, (sf::Out out), (out)) + +AMS_SF_DEFINE_MITM_INTERFACE(ams::mitm::settings, ISetSysMitmInterface, AMS_SETTINGS_SYSTEM_MITM_INTERFACE_INFO) + namespace ams::mitm::settings { - namespace { - - #define AMS_SETTINGS_SYSTEM_MITM_INTERFACE_INFO(C, H) \ - AMS_SF_METHOD_INFO(C, H, 3, Result, GetFirmwareVersion, (sf::Out out)) \ - AMS_SF_METHOD_INFO(C, H, 4, Result, GetFirmwareVersion2, (sf::Out out)) \ - AMS_SF_METHOD_INFO(C, H, 37, Result, GetSettingsItemValueSize, (sf::Out out_size, const ams::settings::fwdbg::SettingsName &name, const ams::settings::fwdbg::SettingsItemKey &key)) \ - AMS_SF_METHOD_INFO(C, H, 38, Result, GetSettingsItemValue, (sf::Out out_size, const sf::OutBuffer &out, const ams::settings::fwdbg::SettingsName &name, const ams::settings::fwdbg::SettingsItemKey &key)) \ - AMS_SF_METHOD_INFO(C, H, 62, Result, GetDebugModeFlag, (sf::Out out)) - - AMS_SF_DEFINE_MITM_INTERFACE(ISetSysMitmInterface, AMS_SETTINGS_SYSTEM_MITM_INTERFACE_INFO) - - } - class SetSysMitmService : public sf::MitmServiceImplBase { public: using MitmServiceImplBase::MitmServiceImplBase; diff --git a/stratosphere/ams_mitm/source/set_mitm/settings_sd_kvs.cpp b/stratosphere/ams_mitm/source/set_mitm/settings_sd_kvs.cpp index 72228b2af..9e946c1ec 100644 --- a/stratosphere/ams_mitm/source/set_mitm/settings_sd_kvs.cpp +++ b/stratosphere/ams_mitm/source/set_mitm/settings_sd_kvs.cpp @@ -14,7 +14,6 @@ * along with this program. If not, see . */ #include -#include "../amsmitm_debug.hpp" #include "../amsmitm_fs_utils.hpp" #include "settings_sd_kvs.hpp" @@ -345,12 +344,6 @@ namespace ams::settings::fwdbg { /* If you do not know what you are doing, do not touch this yet. */ R_ABORT_UNLESS(ParseSettingsItemValue("atmosphere", "fsmitm_redirect_saves_to_sd", "u8!0x0")); - /* Controls whether to enable the deprecated hid mitm */ - /* to fix compatibility with old homebrew. */ - /* 0 = Do not enable, 1 = Enable. */ - /* Please note this setting may be removed in a future release of Atmosphere. */ - R_ABORT_UNLESS(ParseSettingsItemValue("atmosphere", "enable_deprecated_hid_mitm", "u8!0x0")); - /* Controls whether am sees system settings "DebugModeFlag" as */ /* enabled or disabled. */ /* 0 = Disabled (not debug mode), 1 = Enabled (debug mode) */ @@ -377,10 +370,7 @@ namespace ams::settings::fwdbg { LoadDefaultCustomSettings(); /* Parse custom settings off the SD card. */ - const Result parse_result = LoadSdCardKeyValueStore(); - if (R_FAILED(parse_result)) { - ams::mitm::ThrowResultForDebug(parse_result); - } + R_ABORT_UNLESS(LoadSdCardKeyValueStore()); /* Determine how many custom settings are present. */ for (size_t i = 0; i < util::size(g_entries); i++) { diff --git a/stratosphere/ams_mitm/source/sysupdater/sysupdater_module.cpp b/stratosphere/ams_mitm/source/sysupdater/sysupdater_module.cpp index 5ab7ff6e5..ce25b0312 100644 --- a/stratosphere/ams_mitm/source/sysupdater/sysupdater_module.cpp +++ b/stratosphere/ams_mitm/source/sysupdater/sysupdater_module.cpp @@ -23,10 +23,14 @@ namespace ams::mitm::sysupdater { namespace { + enum PortIndex { + PortIndex_Sysupdater, + PortIndex_Count, + }; + constexpr sm::ServiceName SystemUpdateServiceName = sm::ServiceName::Encode("ams:su"); constexpr size_t SystemUpdateMaxSessions = 1; - constexpr size_t MaxServers = 1; constexpr size_t MaxSessions = SystemUpdateMaxSessions + 3; struct ServerOptions { @@ -35,9 +39,9 @@ namespace ams::mitm::sysupdater { static constexpr size_t MaxDomainObjects = 0; }; - sf::hipc::ServerManager g_server_manager; + sf::hipc::ServerManager g_server_manager; - constinit sysupdater::SystemUpdateService g_system_update_service_object; + constinit sf::UnmanagedServiceObject g_system_update_service_object; } @@ -50,7 +54,7 @@ namespace ams::mitm::sysupdater { ON_SCOPE_EXIT { nim::FinalizeForNetworkInstallManager(); }; /* Register ams:su. */ - R_ABORT_UNLESS((g_server_manager.RegisterServer(SystemUpdateServiceName, SystemUpdateMaxSessions, sf::GetSharedPointerTo(g_system_update_service_object)))); + R_ABORT_UNLESS(g_server_manager.RegisterObjectForServer(g_system_update_service_object.GetShared(), SystemUpdateServiceName, SystemUpdateMaxSessions)); /* Loop forever, servicing our services. */ g_server_manager.LoopProcess(); diff --git a/stratosphere/ams_mitm/source/sysupdater/sysupdater_service.cpp b/stratosphere/ams_mitm/source/sysupdater/sysupdater_service.cpp index f312bba6b..03282d749 100644 --- a/stratosphere/ams_mitm/source/sysupdater/sysupdater_service.cpp +++ b/stratosphere/ams_mitm/source/sysupdater/sysupdater_service.cpp @@ -418,22 +418,22 @@ namespace ams::mitm::sysupdater { return this->SetupUpdateImpl(transfer_memory.GetValue(), transfer_memory_size, path, exfat, firmware_variation_id); } - Result SystemUpdateService::RequestPrepareUpdate(sf::OutCopyHandle out_event_handle, sf::Out> out_async) { + Result SystemUpdateService::RequestPrepareUpdate(sf::OutCopyHandle out_event_handle, sf::Out> out_async) { /* Ensure the update is setup but not prepared. */ R_UNLESS(this->setup_update, ns::ResultCardUpdateNotSetup()); R_UNLESS(!this->requested_update, ns::ResultPrepareCardUpdateAlreadyRequested()); /* Create the async result. */ - auto async_result = sf::MakeShared(std::addressof(*this->update_task)); + auto async_result = sf::CreateSharedObjectEmplaced(std::addressof(*this->update_task)); R_UNLESS(async_result != nullptr, ns::ResultOutOfMaxRunningTask()); /* Run the task. */ - R_TRY(async_result->GetImpl().Run()); + R_TRY(async_result.GetImpl().Run()); /* We prepared the task! */ this->requested_update = true; - out_event_handle.SetValue(async_result->GetImpl().GetEvent().GetReadableHandle()); - out_async.SetValue(std::move(async_result)); + out_event_handle.SetValue(async_result.GetImpl().GetEvent().GetReadableHandle()); + *out_async = std::move(async_result); return ResultSuccess(); } diff --git a/stratosphere/ams_mitm/source/sysupdater/sysupdater_service.hpp b/stratosphere/ams_mitm/source/sysupdater/sysupdater_service.hpp index f0d05b12c..cce63e1d6 100644 --- a/stratosphere/ams_mitm/source/sysupdater/sysupdater_service.hpp +++ b/stratosphere/ams_mitm/source/sysupdater/sysupdater_service.hpp @@ -38,25 +38,23 @@ namespace ams::mitm::sysupdater { s64 total_size; }; - namespace impl { +} - #define AMS_SYSUPDATER_SYSTEM_UPDATE_INTERFACE_INFO(C, H) \ - AMS_SF_METHOD_INFO(C, H, 0, Result, GetUpdateInformation, (sf::Out out, const ncm::Path &path)) \ - AMS_SF_METHOD_INFO(C, H, 1, Result, ValidateUpdate, (sf::Out out_validate_result, sf::Out out_validate_exfat_result, sf::Out out_validate_info, const ncm::Path &path)) \ - AMS_SF_METHOD_INFO(C, H, 2, Result, SetupUpdate, (sf::CopyHandle transfer_memory, u64 transfer_memory_size, const ncm::Path &path, bool exfat)) \ - AMS_SF_METHOD_INFO(C, H, 3, Result, SetupUpdateWithVariation, (sf::CopyHandle transfer_memory, u64 transfer_memory_size, const ncm::Path &path, bool exfat, ncm::FirmwareVariationId firmware_variation_id)) \ - AMS_SF_METHOD_INFO(C, H, 4, Result, RequestPrepareUpdate, (sf::OutCopyHandle out_event_handle, sf::Out> out_async)) \ - AMS_SF_METHOD_INFO(C, H, 5, Result, GetPrepareUpdateProgress, (sf::Out out)) \ - AMS_SF_METHOD_INFO(C, H, 6, Result, HasPreparedUpdate, (sf::Out out)) \ - AMS_SF_METHOD_INFO(C, H, 7, Result, ApplyPreparedUpdate, ()) +#define AMS_SYSUPDATER_SYSTEM_UPDATE_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 0, Result, GetUpdateInformation, (sf::Out out, const ncm::Path &path), (out, path)) \ + AMS_SF_METHOD_INFO(C, H, 1, Result, ValidateUpdate, (sf::Out out_validate_result, sf::Out out_validate_exfat_result, sf::Out out_validate_info, const ncm::Path &path), (out_validate_result, out_validate_exfat_result, out_validate_info, path)) \ + AMS_SF_METHOD_INFO(C, H, 2, Result, SetupUpdate, (sf::CopyHandle transfer_memory, u64 transfer_memory_size, const ncm::Path &path, bool exfat), (transfer_memory, transfer_memory_size, path, exfat)) \ + AMS_SF_METHOD_INFO(C, H, 3, Result, SetupUpdateWithVariation, (sf::CopyHandle transfer_memory, u64 transfer_memory_size, const ncm::Path &path, bool exfat, ncm::FirmwareVariationId firmware_variation_id), (transfer_memory, transfer_memory_size, path, exfat, firmware_variation_id)) \ + AMS_SF_METHOD_INFO(C, H, 4, Result, RequestPrepareUpdate, (sf::OutCopyHandle out_event_handle, sf::Out> out_async), (out_event_handle, out_async)) \ + AMS_SF_METHOD_INFO(C, H, 5, Result, GetPrepareUpdateProgress, (sf::Out out), (out)) \ + AMS_SF_METHOD_INFO(C, H, 6, Result, HasPreparedUpdate, (sf::Out out), (out)) \ + AMS_SF_METHOD_INFO(C, H, 7, Result, ApplyPreparedUpdate, (), ()) - AMS_SF_DEFINE_INTERFACE(ISystemUpdateInterface, AMS_SYSUPDATER_SYSTEM_UPDATE_INTERFACE_INFO) +AMS_SF_DEFINE_INTERFACE(ams::mitm::sysupdater::impl, ISystemUpdateInterface, AMS_SYSUPDATER_SYSTEM_UPDATE_INTERFACE_INFO) +namespace ams::mitm::sysupdater { - - } - - class SystemUpdateService final { + class SystemUpdateService { private: SystemUpdateApplyManager apply_manager; std::optional update_task; @@ -73,7 +71,7 @@ namespace ams::mitm::sysupdater { Result ValidateUpdate(sf::Out out_validate_result, sf::Out out_validate_exfat_result, sf::Out out_validate_info, const ncm::Path &path); Result SetupUpdate(sf::CopyHandle transfer_memory, u64 transfer_memory_size, const ncm::Path &path, bool exfat); Result SetupUpdateWithVariation(sf::CopyHandle transfer_memory, u64 transfer_memory_size, const ncm::Path &path, bool exfat, ncm::FirmwareVariationId firmware_variation_id); - Result RequestPrepareUpdate(sf::OutCopyHandle out_event_handle, sf::Out> out_async); + Result RequestPrepareUpdate(sf::OutCopyHandle out_event_handle, sf::Out> out_async); Result GetPrepareUpdateProgress(sf::Out out); Result HasPreparedUpdate(sf::Out out); Result ApplyPreparedUpdate(); diff --git a/stratosphere/boot/source/boot_driver_management.cpp b/stratosphere/boot/source/boot_driver_management.cpp index 1382c1fe7..2f5207335 100644 --- a/stratosphere/boot/source/boot_driver_management.cpp +++ b/stratosphere/boot/source/boot_driver_management.cpp @@ -49,6 +49,11 @@ namespace ams::boot { pwm::driver::Initialize(); } + void FinalizeGpioDriverLibrary() { + /* Finalize the gpio client library. */ + gpio::Finalize(); + } + void FinalizeI2cDriverLibrary() { /* Finalize the i2c driver library. */ i2c::driver::Finalize(); diff --git a/stratosphere/boot/source/boot_driver_management.hpp b/stratosphere/boot/source/boot_driver_management.hpp index aab6e5523..955466feb 100644 --- a/stratosphere/boot/source/boot_driver_management.hpp +++ b/stratosphere/boot/source/boot_driver_management.hpp @@ -19,6 +19,7 @@ namespace ams::boot { void InitializeGpioDriverLibrary(); void InitializeI2cDriverLibrary(); + void FinalizeGpioDriverLibrary(); void FinalizeI2cDriverLibrary(); diff --git a/stratosphere/boot/source/boot_main.cpp b/stratosphere/boot/source/boot_main.cpp index c8c238444..d7e6c3c87 100644 --- a/stratosphere/boot/source/boot_main.cpp +++ b/stratosphere/boot/source/boot_main.cpp @@ -253,6 +253,9 @@ int main(int argc, char **argv) /* Finalize the i2c server library. */ boot::FinalizeI2cDriverLibrary(); + /* Finalize the gpio server library. */ + boot::FinalizeGpioDriverLibrary(); + /* Tell PM to start boot2. */ R_ABORT_UNLESS(pmshellNotifyBootFinished());