diff --git a/nx/include/switch/result.h b/nx/include/switch/result.h index e55f25c5..c0d47a07 100644 --- a/nx/include/switch/result.h +++ b/nx/include/switch/result.h @@ -123,6 +123,7 @@ enum { LibnxError_NvinfoFailedToInitialize, LibnxError_NvbufFailedToInitialize, LibnxError_LibAppletBadExit, + LibnxError_InvalidCmifOutHeader, }; /// libnx binder error codes diff --git a/nx/include/switch/sf/cmif.h b/nx/include/switch/sf/cmif.h index c38c2e23..4924c4c0 100644 --- a/nx/include/switch/sf/cmif.h +++ b/nx/include/switch/sf/cmif.h @@ -264,8 +264,7 @@ NX_CONSTEXPR Result cmifParseResponse(CmifResponse* res, void* base, bool is_dom CmifOutHeader* hdr = NULL; u32* objects = NULL; - if (is_domain) - { + if (is_domain) { CmifDomainOutHeader* domain_hdr = (CmifDomainOutHeader*)start; hdr = (CmifOutHeader*)(domain_hdr+1); objects = (u32*)((u8*)hdr + sizeof(CmifOutHeader) + size); @@ -274,7 +273,7 @@ NX_CONSTEXPR Result cmifParseResponse(CmifResponse* res, void* base, bool is_dom hdr = (CmifOutHeader*)start; if (hdr->magic != CMIF_OUT_HEADER_MAGIC) - return MAKERESULT(Module_Libnx, LibnxError_BadInput); // todo: proper result code + return MAKERESULT(Module_Libnx, LibnxError_InvalidCmifOutHeader); if (R_FAILED(hdr->result)) return hdr->result; @@ -307,8 +306,7 @@ NX_INLINE Result cmifConvertCurrentObjectToDomain(Handle h, u32* out_object_id) { cmifMakeControlRequest(armGetTls(), 0, 0); Result rc = svcSendSyncRequest(h); - if (R_SUCCEEDED(rc)) - { + if (R_SUCCEEDED(rc)) { CmifResponse resp = {}; rc = cmifParseResponse(&resp, armGetTls(), false, sizeof(u32)); if (R_SUCCEEDED(rc) && out_object_id) @@ -322,8 +320,7 @@ NX_INLINE Result cmifCopyFromCurrentDomain(Handle h, u32 object_id, Handle* out_ void* raw = cmifMakeControlRequest(armGetTls(), 1, sizeof(u32)); *(u32*)raw = object_id; Result rc = svcSendSyncRequest(h); - if (R_SUCCEEDED(rc)) - { + if (R_SUCCEEDED(rc)) { CmifResponse resp = {}; rc = cmifParseResponse(&resp, armGetTls(), false, 0); if (R_SUCCEEDED(rc) && out_h) @@ -336,8 +333,7 @@ NX_INLINE Result cmifCloneCurrentObject(Handle h, Handle* out_h) { cmifMakeControlRequest(armGetTls(), 2, 0); Result rc = svcSendSyncRequest(h); - if (R_SUCCEEDED(rc)) - { + if (R_SUCCEEDED(rc)) { CmifResponse resp = {}; rc = cmifParseResponse(&resp, armGetTls(), false, 0); if (R_SUCCEEDED(rc) && out_h) @@ -350,8 +346,7 @@ NX_INLINE Result cmifQueryPointerBufferSize(Handle h, u16* out_size) { cmifMakeControlRequest(armGetTls(), 3, 0); Result rc = svcSendSyncRequest(h); - if (R_SUCCEEDED(rc)) - { + if (R_SUCCEEDED(rc)) { CmifResponse resp = {}; rc = cmifParseResponse(&resp, armGetTls(), false, sizeof(u16)); if (R_SUCCEEDED(rc) && out_size) @@ -365,8 +360,7 @@ NX_INLINE Result cmifCloneCurrentObjectEx(Handle h, u32 tag, Handle* out_h) void* raw = cmifMakeControlRequest(armGetTls(), 4, sizeof(u32)); *(u32*)raw = tag; Result rc = svcSendSyncRequest(h); - if (R_SUCCEEDED(rc)) - { + if (R_SUCCEEDED(rc)) { CmifResponse resp = {}; rc = cmifParseResponse(&resp, armGetTls(), false, 0); if (R_SUCCEEDED(rc) && out_h) diff --git a/nx/include/switch/sf/service.h b/nx/include/switch/sf/service.h index f7cf0c8a..2e94b063 100644 --- a/nx/include/switch/sf/service.h +++ b/nx/include/switch/sf/service.h @@ -10,16 +10,14 @@ #include "cmif.h" /// Service object structure -typedef struct Service -{ +typedef struct Service { Handle session; u32 own_handle; u32 object_id; u16 pointer_buffer_size; } Service; -enum -{ +enum { SfBufferAttr_In = BIT(0), SfBufferAttr_Out = BIT(1), SfBufferAttr_HipcMapAlias = BIT(2), @@ -41,8 +39,7 @@ typedef struct SfBufferAttrs { u32 attr7; } SfBufferAttrs; -typedef struct SfBuffer -{ +typedef struct SfBuffer { const void* ptr; size_t size; } SfBuffer; @@ -53,8 +50,7 @@ typedef enum SfOutHandleAttr { SfOutHandleAttr_HipcMove = 2, } SfOutHandleAttr; -typedef struct SfOutHandleAttrs -{ +typedef struct SfOutHandleAttrs { SfOutHandleAttr attr0; SfOutHandleAttr attr1; SfOutHandleAttr attr2; @@ -65,8 +61,7 @@ typedef struct SfOutHandleAttrs SfOutHandleAttr attr7; } SfOutHandleAttrs; -typedef struct SfDispatchParams -{ +typedef struct SfDispatchParams { Handle target_session; u32 context; @@ -227,8 +222,7 @@ NX_INLINE Result serviceCloneEx(Service* s, u32 tag, Service* out_s) */ NX_INLINE Result serviceConvertToDomain(Service* s) { - if (!s->own_handle) - { + if (!s->own_handle) { // For overridden services, create a clone first. Result rc = cmifCloneCurrentObjectEx(s->session, 0, &s->session); if (R_FAILED(rc)) @@ -358,8 +352,7 @@ NX_INLINE void* serviceMakeRequest( NX_CONSTEXPR void _serviceResponseGetHandle(CmifResponse* res, SfOutHandleAttr type, Handle* out) { - switch (type) - { + switch (type) { default: case SfOutHandleAttr_None: break; @@ -391,8 +384,7 @@ NX_INLINE Result serviceParseResponse( if (out_size) *out_data = res.data; - for (u32 i = 0; i < num_out_objects; i ++) - { + for (u32 i = 0; i < num_out_objects; i ++) { if (is_domain) serviceCreateDomainSubservice(&out_objects[i], s, cmifResponseGetObject(&res)); else // Output objects are marshalled as move handles at the beginning of the list. @@ -428,8 +420,7 @@ NX_INLINE Result serviceDispatchImpl( __builtin_memcpy(in, in_data, in_data_size); Result rc = svcSendSyncRequest(disp.target_session == INVALID_HANDLE ? s->session : disp.target_session); - if (R_SUCCEEDED(rc)) - { + if (R_SUCCEEDED(rc)) { void* out = NULL; rc = serviceParseResponse(s, out_data_size, &out, diff --git a/nx/source/services/service_guard.h b/nx/source/services/service_guard.h index 03c68e9b..4f4620b4 100644 --- a/nx/source/services/service_guard.h +++ b/nx/source/services/service_guard.h @@ -5,8 +5,7 @@ #include "sf/service.h" #include "services/sm.h" -typedef struct ServiceGuard -{ +typedef struct ServiceGuard { Mutex mutex; u32 refCount; } ServiceGuard; @@ -19,8 +18,7 @@ NX_INLINE bool serviceGuardBeginInit(ServiceGuard* g) NX_INLINE Result serviceGuardEndInit(ServiceGuard* g, Result rc, void (*cleanupFunc)(void)) { - if (R_FAILED(rc)) - { + if (R_FAILED(rc)) { cleanupFunc(); --g->refCount; } diff --git a/nx/source/services/sm.c b/nx/source/services/sm.c index 3a0eac43..19b05da6 100644 --- a/nx/source/services/sm.c +++ b/nx/source/services/sm.c @@ -29,13 +29,9 @@ void smAddOverrideHandle(u64 name, Handle handle) Handle smGetServiceOverride(u64 name) { - size_t i; - - for (i=0; iown_handle = own_handle; }