diff --git a/nx/include/switch/sf/service.h b/nx/include/switch/sf/service.h index ce3a0135..625fbba1 100644 --- a/nx/include/switch/sf/service.h +++ b/nx/include/switch/sf/service.h @@ -166,6 +166,11 @@ NX_CONSTEXPR void serviceCreateDomainSubservice(Service* s, Service* parent, u32 */ NX_INLINE void serviceClose(Service* s) { +#if defined(NX_SERVICE_ASSUME_NON_DOMAIN) + if (s->object_id) + __builtin_unreachable(); +#endif + if (s->own_handle || s->object_id) { cmifMakeCloseRequest(armGetTls(), s->own_handle ? 0 : s->object_id); svcSendSyncRequest(s->session); @@ -182,6 +187,11 @@ NX_INLINE void serviceClose(Service* s) */ NX_INLINE Result serviceClone(Service* s, Service* out_s) { +#if defined(NX_SERVICE_ASSUME_NON_DOMAIN) + if (s->object_id) + __builtin_unreachable(); +#endif + out_s->session = 0; out_s->own_handle = 1; out_s->object_id = s->object_id; @@ -197,6 +207,11 @@ NX_INLINE Result serviceClone(Service* s, Service* out_s) */ NX_INLINE Result serviceCloneEx(Service* s, u32 tag, Service* out_s) { +#if defined(NX_SERVICE_ASSUME_NON_DOMAIN) + if (s->object_id) + __builtin_unreachable(); +#endif + out_s->session = 0; out_s->own_handle = 1; out_s->object_id = s->object_id; @@ -211,9 +226,6 @@ NX_INLINE Result serviceCloneEx(Service* s, u32 tag, Service* out_s) */ NX_INLINE Result serviceConvertToDomain(Service* s) { - if (s->object_id) - return 0; // Nothing to do - if (!s->own_handle) { // For overridden services, create a clone first. @@ -298,6 +310,11 @@ NX_INLINE void* serviceMakeRequest( u32 num_objects, const Service* const* objects, u32 num_handles, const Handle* handles ) { +#if defined(NX_SERVICE_ASSUME_NON_DOMAIN) + if (s->object_id) + __builtin_unreachable(); +#endif + CmifRequestFormat fmt = {}; fmt.object_id = s->object_id; fmt.request_id = request_id; @@ -358,6 +375,11 @@ NX_INLINE Result serviceParseResponse( u32 num_out_objects, Service* out_objects, const SfOutHandleAttrs out_handle_attrs, Handle* out_handles ) { +#if defined(NX_SERVICE_ASSUME_NON_DOMAIN) + if (s->object_id) + __builtin_unreachable(); +#endif + CmifResponse res = {}; bool is_domain = s->object_id != 0; Result rc = cmifParseResponse(&res, armGetTls(), is_domain, out_size); diff --git a/nx/source/services/fatal.c b/nx/source/services/fatal.c index 2b8cf163..e4d8ccc7 100644 --- a/nx/source/services/fatal.c +++ b/nx/source/services/fatal.c @@ -1,4 +1,5 @@ // Copyright 2017 plutoo +#define NX_SERVICE_ASSUME_NON_DOMAIN #include "types.h" #include "result.h" #include "kernel/detect.h" @@ -38,6 +39,7 @@ static void _fatalImpl(u32 cmd_id, Result err, FatalType type, FatalContext *ctx .buffers = { { ctx, sizeof(*ctx) } }, .in_send_pid = true, ); + serviceClose(&s); } switch (type) { diff --git a/nx/source/services/nv.c b/nx/source/services/nv.c index 2c671816..f3240bff 100644 --- a/nx/source/services/nv.c +++ b/nx/source/services/nv.c @@ -1,3 +1,4 @@ +#define NX_SERVICE_ASSUME_NON_DOMAIN #include #include "types.h" #include "result.h" diff --git a/nx/source/services/sm.c b/nx/source/services/sm.c index 63f03c3d..daa329b0 100644 --- a/nx/source/services/sm.c +++ b/nx/source/services/sm.c @@ -1,4 +1,5 @@ // Copyright 2017 plutoo +#define NX_SERVICE_ASSUME_NON_DOMAIN #include "types.h" #include "result.h" #include "arm/atomics.h"