From fdd1ccf87a5fe3c554180a2cb35563a8c1dcd4d8 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 --- libstratosphere/source/sm/sm_ams.c | 9 +++++++++ libstratosphere/source/sm/sm_utils.hpp | 5 ++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/libstratosphere/source/sm/sm_ams.c b/libstratosphere/source/sm/sm_ams.c index 1ceb23f8..520a3133 100644 --- a/libstratosphere/source/sm/sm_ams.c +++ b/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/libstratosphere/source/sm/sm_utils.hpp b/libstratosphere/source/sm/sm_utils.hpp index d3b4b153..5c0ae6c7 100644 --- a/libstratosphere/source/sm/sm_utils.hpp +++ b/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(); }