From 1118421fa600d7bd2ef1b8446c16cdba6ead13af Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Sat, 10 Apr 2021 17:59:54 -0700 Subject: [PATCH] strat: changes for sm tipc (boots 11.0.1, now) --- libraries/libstratosphere/source/sm/sm_ams.c | 42 +++++++++---------- libraries/libstratosphere/source/sm/sm_ams.h | 8 ++-- .../libstratosphere/source/sm/sm_mitm_api.cpp | 2 +- .../libstratosphere/source/sm/sm_utils.hpp | 2 +- libraries/libstratosphere/source/sm/smm_ams.c | 6 +-- stratosphere/ams_mitm/ams_mitm.json | 2 + stratosphere/boot/boot.json | 1 + stratosphere/loader/loader.json | 2 + stratosphere/ncm/ncm.json | 2 + stratosphere/pm/pm.json | 2 + stratosphere/sm/sm.json | 2 + stratosphere/spl/spl.json | 2 + 12 files changed, 42 insertions(+), 31 deletions(-) diff --git a/libraries/libstratosphere/source/sm/sm_ams.c b/libraries/libstratosphere/source/sm/sm_ams.c index 520a31337..407531892 100644 --- a/libraries/libstratosphere/source/sm/sm_ams.c +++ b/libraries/libstratosphere/source/sm/sm_ams.c @@ -19,18 +19,17 @@ static Result _smAtmosphereCmdHas(bool *out, SmServiceName name, u32 cmd_id) { u8 tmp; - Result rc = serviceDispatchInOut(smGetServiceSession(), cmd_id, name, tmp); + Result rc = tipcDispatchInOut(smGetServiceSessionTipc(), cmd_id, name, tmp); if (R_SUCCEEDED(rc) && out) *out = tmp & 1; return rc; } -static Result _smAtmosphereCmdInServiceNameNoOut(SmServiceName name, Service *srv, u32 cmd_id) { - return serviceDispatchIn(srv, cmd_id, name); +static Result _smAtmosphereCmdInServiceNameNoOut(SmServiceName name, TipcService *srv, u32 cmd_id) { + return tipcDispatchIn(srv, cmd_id, name); } -static Result _smAtmosphereDetachClient(Service *srv) { - u64 pid_placeholder = 0; - return serviceDispatchIn(srv, 4, pid_placeholder, .in_send_pid = true); +static Result _smAtmosphereDetachClient(TipcService *srv) { + return tipcDispatch(srv, 4, .in_send_pid = true); } Result smAtmosphereHasService(bool *out, SmServiceName name) { @@ -38,7 +37,7 @@ Result smAtmosphereHasService(bool *out, SmServiceName name) { } Result smAtmosphereWaitService(SmServiceName name) { - return _smAtmosphereCmdInServiceNameNoOut(name, smGetServiceSession(), 65101); + return _smAtmosphereCmdInServiceNameNoOut(name, smGetServiceSessionTipc(), 65101); } Result smAtmosphereHasMitm(bool *out, SmServiceName name) { @@ -46,10 +45,10 @@ Result smAtmosphereHasMitm(bool *out, SmServiceName name) { } Result smAtmosphereWaitMitm(SmServiceName name) { - return _smAtmosphereCmdInServiceNameNoOut(name, smGetServiceSession(), 65005); + return _smAtmosphereCmdInServiceNameNoOut(name, smGetServiceSessionTipc(), 65005); } -static Service g_smAtmosphereMitmSrv; +static TipcService g_smAtmosphereMitmSrv; NX_GENERATE_SERVICE_GUARD(smAtmosphereMitm); @@ -61,11 +60,11 @@ void _smAtmosphereMitmCleanup(void) { smAtmosphereCloseSession(&g_smAtmosphereMitmSrv); } -Service* smAtmosphereMitmGetServiceSession(void) { +TipcService* smAtmosphereMitmGetServiceSession(void) { return &g_smAtmosphereMitmSrv; } -Result smAtmosphereOpenSession(Service *out) { +Result smAtmosphereOpenSession(TipcService *out) { Handle sm_handle; Result rc = svcConnectToNamedPort(&sm_handle, "sm:"); while (R_VALUE(rc) == KERNELRESULT(NotFound)) { @@ -74,28 +73,27 @@ Result smAtmosphereOpenSession(Service *out) { } if (R_SUCCEEDED(rc)) { - serviceCreate(out, sm_handle); + tipcCreate(out, sm_handle); } if (R_SUCCEEDED(rc)) { - const u64 pid_placeholder = 0; - rc = serviceDispatchIn(out, 0, pid_placeholder, .in_send_pid = true); + rc = tipcDispatch(out, 0, .in_send_pid = true); } return rc; } -void smAtmosphereCloseSession(Service *srv) { +void smAtmosphereCloseSession(TipcService *srv) { Result rc = _smAtmosphereDetachClient(srv); if (R_FAILED(rc)) { svcBreak(BreakReason_Panic, (uintptr_t)&rc, sizeof(rc)); } - serviceClose(srv); + tipcClose(srv); } -Result smAtmosphereMitmInstall(Service *fwd_srv, Handle *handle_out, Handle *query_out, SmServiceName name) { +Result smAtmosphereMitmInstall(TipcService *fwd_srv, Handle *handle_out, Handle *query_out, SmServiceName name) { Handle tmp_handles[2]; - Result rc = serviceDispatchIn(fwd_srv, 65000, name, + Result rc = tipcDispatchIn(fwd_srv, 65000, name, .out_handle_attrs = { SfOutHandleAttr_HipcMove, SfOutHandleAttr_HipcMove }, .out_handles = tmp_handles, ); @@ -109,15 +107,15 @@ Result smAtmosphereMitmInstall(Service *fwd_srv, Handle *handle_out, Handle *que } Result smAtmosphereMitmUninstall(SmServiceName name) { - return _smAtmosphereCmdInServiceNameNoOut(name, smGetServiceSession(), 65001); + return _smAtmosphereCmdInServiceNameNoOut(name, smGetServiceSessionTipc(), 65001); } Result smAtmosphereMitmDeclareFuture(SmServiceName name) { - return _smAtmosphereCmdInServiceNameNoOut(name, smGetServiceSession(), 65006); + return _smAtmosphereCmdInServiceNameNoOut(name, smGetServiceSessionTipc(), 65006); } Result smAtmosphereMitmClearFuture(SmServiceName name) { - return _smAtmosphereCmdInServiceNameNoOut(name, smGetServiceSession(), 65007); + return _smAtmosphereCmdInServiceNameNoOut(name, smGetServiceSessionTipc(), 65007); } Result smAtmosphereMitmAcknowledgeSession(Service *srv_out, void *_out, SmServiceName name) { @@ -131,7 +129,7 @@ Result smAtmosphereMitmAcknowledgeSession(Service *srv_out, void *_out, SmServic Handle tmp_handle; - Result rc = serviceDispatchInOut(&g_smAtmosphereMitmSrv, 65003, name, *out, + Result rc = tipcDispatchInOut(&g_smAtmosphereMitmSrv, 65003, name, *out, .out_handle_attrs = { SfOutHandleAttr_HipcMove }, .out_handles = &tmp_handle, ); diff --git a/libraries/libstratosphere/source/sm/sm_ams.h b/libraries/libstratosphere/source/sm/sm_ams.h index 3a4885ccb..f53f98670 100644 --- a/libraries/libstratosphere/source/sm/sm_ams.h +++ b/libraries/libstratosphere/source/sm/sm_ams.h @@ -18,12 +18,12 @@ Result smAtmosphereWaitMitm(SmServiceName name); Result smAtmosphereMitmInitialize(void); void smAtmosphereMitmExit(void); -Service *smAtmosphereMitmGetServiceSession(); +TipcService *smAtmosphereMitmGetServiceSession(); -Result smAtmosphereOpenSession(Service *out); -void smAtmosphereCloseSession(Service *srv); +Result smAtmosphereOpenSession(TipcService *out); +void smAtmosphereCloseSession(TipcService *srv); -Result smAtmosphereMitmInstall(Service *fwd_srv, Handle *handle_out, Handle *query_out, SmServiceName name); +Result smAtmosphereMitmInstall(TipcService *fwd_srv, Handle *handle_out, Handle *query_out, SmServiceName name); Result smAtmosphereMitmUninstall(SmServiceName name); Result smAtmosphereMitmDeclareFuture(SmServiceName name); Result smAtmosphereMitmClearFuture(SmServiceName name); diff --git a/libraries/libstratosphere/source/sm/sm_mitm_api.cpp b/libraries/libstratosphere/source/sm/sm_mitm_api.cpp index 8e5c80023..cdf07e7ad 100644 --- a/libraries/libstratosphere/source/sm/sm_mitm_api.cpp +++ b/libraries/libstratosphere/source/sm/sm_mitm_api.cpp @@ -20,7 +20,7 @@ namespace ams::sm::mitm { /* Mitm API. */ Result InstallMitm(Handle *out_port, Handle *out_query, ServiceName name) { - return impl::DoWithPerThreadSession([&](Service *fwd) { + return impl::DoWithPerThreadSession([&](TipcService *fwd) { return smAtmosphereMitmInstall(fwd, out_port, out_query, impl::ConvertName(name)); }); } diff --git a/libraries/libstratosphere/source/sm/sm_utils.hpp b/libraries/libstratosphere/source/sm/sm_utils.hpp index 5c0ae6c7c..d869f9cd1 100644 --- a/libraries/libstratosphere/source/sm/sm_utils.hpp +++ b/libraries/libstratosphere/source/sm/sm_utils.hpp @@ -52,7 +52,7 @@ namespace ams::sm::impl { template Result DoWithPerThreadSession(F f) { - Service srv; + TipcService srv; { std::scoped_lock lk(GetPerThreadSessionMutex()); R_ABORT_UNLESS(smAtmosphereOpenSession(&srv)); diff --git a/libraries/libstratosphere/source/sm/smm_ams.c b/libraries/libstratosphere/source/sm/smm_ams.c index 9326d981f..1574776a2 100644 --- a/libraries/libstratosphere/source/sm/smm_ams.c +++ b/libraries/libstratosphere/source/sm/smm_ams.c @@ -16,7 +16,7 @@ #include "smm_ams.h" Result smManagerAtmosphereEndInitialDefers(void) { - return serviceDispatch(smManagerGetServiceSession(), 65000); + return tipcDispatch(smManagerTipcGetServiceSession(), 65000); } Result smManagerAtmosphereRegisterProcess(u64 pid, u64 tid, const CfgOverrideStatus *status, const void *acid_sac, size_t acid_sac_size, const void *aci_sac, size_t aci_sac_size) { @@ -25,7 +25,7 @@ Result smManagerAtmosphereRegisterProcess(u64 pid, u64 tid, const CfgOverrideSta u64 tid; CfgOverrideStatus status; } in = { pid, tid, *status }; - return serviceDispatchIn(smManagerGetServiceSession(), 65002, in, + return tipcDispatchIn(smManagerTipcGetServiceSession(), 65002, in, .buffer_attrs = { SfBufferAttr_In | SfBufferAttr_HipcMapAlias, SfBufferAttr_In | SfBufferAttr_HipcMapAlias, @@ -39,7 +39,7 @@ Result smManagerAtmosphereRegisterProcess(u64 pid, u64 tid, const CfgOverrideSta static Result _smManagerAtmosphereCmdHas(bool *out, SmServiceName name, u32 cmd_id) { u8 tmp; - Result rc = serviceDispatchInOut(smManagerGetServiceSession(), cmd_id, name, tmp); + Result rc = tipcDispatchInOut(smManagerTipcGetServiceSession(), cmd_id, name, tmp); if (R_SUCCEEDED(rc) && out) *out = tmp & 1; return rc; } diff --git a/stratosphere/ams_mitm/ams_mitm.json b/stratosphere/ams_mitm/ams_mitm.json index c78327d05..132eeee2c 100644 --- a/stratosphere/ams_mitm/ams_mitm.json +++ b/stratosphere/ams_mitm/ams_mitm.json @@ -5,6 +5,8 @@ "main_thread_priority": 43, "default_cpu_id": 3, "process_category": 1, + "use_secure_memory": true, + "immortal": true, "kernel_capabilities": [ { "type": "handle_table_size", diff --git a/stratosphere/boot/boot.json b/stratosphere/boot/boot.json index b8166d193..90375a00c 100644 --- a/stratosphere/boot/boot.json +++ b/stratosphere/boot/boot.json @@ -6,6 +6,7 @@ "default_cpu_id": 3, "process_category": 1, "use_secure_memory": false, + "immortal": false, "kernel_capabilities": [ { "type": "handle_table_size", diff --git a/stratosphere/loader/loader.json b/stratosphere/loader/loader.json index b79900517..8dc3e8bd6 100644 --- a/stratosphere/loader/loader.json +++ b/stratosphere/loader/loader.json @@ -5,6 +5,8 @@ "main_thread_priority": 49, "default_cpu_id": 3, "process_category": 1, + "use_secure_memory": true, + "immortal": true, "kernel_capabilities": [ { "type": "handle_table_size", diff --git a/stratosphere/ncm/ncm.json b/stratosphere/ncm/ncm.json index 5a3ac657b..b0b54bebf 100644 --- a/stratosphere/ncm/ncm.json +++ b/stratosphere/ncm/ncm.json @@ -5,6 +5,8 @@ "main_thread_priority": 49, "default_cpu_id": 3, "process_category": 1, + "use_secure_memory": true, + "immortal": true, "kernel_capabilities": [ { "type": "handle_table_size", diff --git a/stratosphere/pm/pm.json b/stratosphere/pm/pm.json index 4e4036c3a..b05421b33 100644 --- a/stratosphere/pm/pm.json +++ b/stratosphere/pm/pm.json @@ -5,6 +5,8 @@ "main_thread_priority": 49, "default_cpu_id": 3, "process_category": 1, + "use_secure_memory": true, + "immortal": true, "kernel_capabilities": [ { "type": "handle_table_size", diff --git a/stratosphere/sm/sm.json b/stratosphere/sm/sm.json index 0734e82b7..2d7356458 100644 --- a/stratosphere/sm/sm.json +++ b/stratosphere/sm/sm.json @@ -5,6 +5,8 @@ "main_thread_priority": 27, "default_cpu_id": 3, "process_category": 1, + "use_secure_memory": true, + "immortal": true, "kernel_capabilities": [ { "type": "handle_table_size", diff --git a/stratosphere/spl/spl.json b/stratosphere/spl/spl.json index 022b06cc1..43e6f7b07 100644 --- a/stratosphere/spl/spl.json +++ b/stratosphere/spl/spl.json @@ -5,6 +5,8 @@ "main_thread_priority": 27, "default_cpu_id": 3, "process_category": 1, + "use_secure_memory": true, + "immortal": true, "kernel_capabilities": [{ "type": "handle_table_size", "value": 128