From 4a82d9bf28a4f4ba1198138eed0637ae61514df6 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Wed, 27 Jan 2021 14:36:15 -0800 Subject: [PATCH] sm: supercede ams extension via DetachClient --- libraries/libstratosphere/source/sm/sm_ams.c | 9 +++++++++ libraries/libstratosphere/source/sm/sm_utils.hpp | 5 ++++- .../sm/source/impl/sm_service_manager.cpp | 16 ++-------------- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/libraries/libstratosphere/source/sm/sm_ams.c b/libraries/libstratosphere/source/sm/sm_ams.c index 1ceb23f88..520a31337 100644 --- a/libraries/libstratosphere/source/sm/sm_ams.c +++ b/libraries/libstratosphere/source/sm/sm_ams.c @@ -28,6 +28,11 @@ static Result _smAtmosphereCmdInServiceNameNoOut(SmServiceName name, Service *sr return serviceDispatchIn(srv, cmd_id, name); } +static Result _smAtmosphereDetachClient(Service *srv) { + u64 pid_placeholder = 0; + return serviceDispatchIn(srv, 4, pid_placeholder, .in_send_pid = true); +} + Result smAtmosphereHasService(bool *out, SmServiceName name) { return _smAtmosphereCmdHas(out, name, 65100); } @@ -81,6 +86,10 @@ Result smAtmosphereOpenSession(Service *out) { } void smAtmosphereCloseSession(Service *srv) { + Result rc = _smAtmosphereDetachClient(srv); + if (R_FAILED(rc)) { + svcBreak(BreakReason_Panic, (uintptr_t)&rc, sizeof(rc)); + } serviceClose(srv); } diff --git a/libraries/libstratosphere/source/sm/sm_utils.hpp b/libraries/libstratosphere/source/sm/sm_utils.hpp index d3b4b153e..5c0ae6c7c 100644 --- a/libraries/libstratosphere/source/sm/sm_utils.hpp +++ b/libraries/libstratosphere/source/sm/sm_utils.hpp @@ -30,7 +30,10 @@ namespace ams::sm::impl { std::scoped_lock lk(GetUserSessionMutex()); { R_ABORT_UNLESS(smInitialize()); - ON_SCOPE_EXIT { smExit(); }; + ON_SCOPE_EXIT { + R_ABORT_UNLESS(smDetachClient()); + smExit(); + }; return f(); } diff --git a/stratosphere/sm/source/impl/sm_service_manager.cpp b/stratosphere/sm/source/impl/sm_service_manager.cpp index e830af32e..48e1de943 100644 --- a/stratosphere/sm/source/impl/sm_service_manager.cpp +++ b/stratosphere/sm/source/impl/sm_service_manager.cpp @@ -350,12 +350,6 @@ namespace ams::sm::impl { return service == InitiallyDeferredServiceName; } - bool ShouldCloseOnClientDisconnect(ServiceName service) { - /* jit sysmodule is closed and relaunched by am for each application which uses it. */ - constexpr auto JitU = ServiceName::Encode("jit:u"); - return service == JitU; - } - Result GetMitmServiceHandleImpl(Handle *out, ServiceInfo *service_info, const MitmProcessInfo &client_info) { /* Send command to query if we should mitm. */ bool should_mitm; @@ -438,16 +432,10 @@ namespace ams::sm::impl { return; } - /* NOTE: Nintendo unregisters all services a process hosted on client close. */ - /* We do not do this as an atmosphere extension, in order to reduce the number */ - /* of sessions open at any given time. */ - /* However, certain system behavior (jit) relies on this occurring. */ - /* As such, we will special case the system components which rely on the behavior. */ + /* Unregister all services a client hosts, on attached-client-close. */ for (size_t i = 0; i < ServiceCountMax; i++) { if (g_service_list[i].name != InvalidServiceName && g_service_list[i].owner_process_id == process_id) { - if (ShouldCloseOnClientDisconnect(g_service_list[i].name)) { - g_service_list[i].Free(); - } + g_service_list[i].Free(); } } }