sm: supercede ams extension via DetachClient

This commit is contained in:
Michael Scire 2021-01-27 14:36:15 -08:00
parent 4190281b2f
commit 4a82d9bf28
3 changed files with 15 additions and 15 deletions

View file

@ -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);
}

View file

@ -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();
}

View file

@ -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,19 +432,13 @@ 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();
}
}
}
}
/* Process management. */
Result RegisterProcess(os::ProcessId process_id, ncm::ProgramId program_id, cfg::OverrideStatus override_status, const void *acid_sac, size_t acid_sac_size, const void *aci_sac, size_t aci_sac_size) {