mirror of
https://github.com/switchbrew/libnx.git
synced 2025-06-22 13:02:38 +02:00
Minor style fixes in new IPC code
This commit is contained in:
parent
5ab1219f40
commit
96fc7dd8cd
@ -123,6 +123,7 @@ enum {
|
|||||||
LibnxError_NvinfoFailedToInitialize,
|
LibnxError_NvinfoFailedToInitialize,
|
||||||
LibnxError_NvbufFailedToInitialize,
|
LibnxError_NvbufFailedToInitialize,
|
||||||
LibnxError_LibAppletBadExit,
|
LibnxError_LibAppletBadExit,
|
||||||
|
LibnxError_InvalidCmifOutHeader,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// libnx binder error codes
|
/// libnx binder error codes
|
||||||
|
@ -264,8 +264,7 @@ NX_CONSTEXPR Result cmifParseResponse(CmifResponse* res, void* base, bool is_dom
|
|||||||
|
|
||||||
CmifOutHeader* hdr = NULL;
|
CmifOutHeader* hdr = NULL;
|
||||||
u32* objects = NULL;
|
u32* objects = NULL;
|
||||||
if (is_domain)
|
if (is_domain) {
|
||||||
{
|
|
||||||
CmifDomainOutHeader* domain_hdr = (CmifDomainOutHeader*)start;
|
CmifDomainOutHeader* domain_hdr = (CmifDomainOutHeader*)start;
|
||||||
hdr = (CmifOutHeader*)(domain_hdr+1);
|
hdr = (CmifOutHeader*)(domain_hdr+1);
|
||||||
objects = (u32*)((u8*)hdr + sizeof(CmifOutHeader) + size);
|
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;
|
hdr = (CmifOutHeader*)start;
|
||||||
|
|
||||||
if (hdr->magic != CMIF_OUT_HEADER_MAGIC)
|
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))
|
if (R_FAILED(hdr->result))
|
||||||
return hdr->result;
|
return hdr->result;
|
||||||
|
|
||||||
@ -307,8 +306,7 @@ NX_INLINE Result cmifConvertCurrentObjectToDomain(Handle h, u32* out_object_id)
|
|||||||
{
|
{
|
||||||
cmifMakeControlRequest(armGetTls(), 0, 0);
|
cmifMakeControlRequest(armGetTls(), 0, 0);
|
||||||
Result rc = svcSendSyncRequest(h);
|
Result rc = svcSendSyncRequest(h);
|
||||||
if (R_SUCCEEDED(rc))
|
if (R_SUCCEEDED(rc)) {
|
||||||
{
|
|
||||||
CmifResponse resp = {};
|
CmifResponse resp = {};
|
||||||
rc = cmifParseResponse(&resp, armGetTls(), false, sizeof(u32));
|
rc = cmifParseResponse(&resp, armGetTls(), false, sizeof(u32));
|
||||||
if (R_SUCCEEDED(rc) && out_object_id)
|
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));
|
void* raw = cmifMakeControlRequest(armGetTls(), 1, sizeof(u32));
|
||||||
*(u32*)raw = object_id;
|
*(u32*)raw = object_id;
|
||||||
Result rc = svcSendSyncRequest(h);
|
Result rc = svcSendSyncRequest(h);
|
||||||
if (R_SUCCEEDED(rc))
|
if (R_SUCCEEDED(rc)) {
|
||||||
{
|
|
||||||
CmifResponse resp = {};
|
CmifResponse resp = {};
|
||||||
rc = cmifParseResponse(&resp, armGetTls(), false, 0);
|
rc = cmifParseResponse(&resp, armGetTls(), false, 0);
|
||||||
if (R_SUCCEEDED(rc) && out_h)
|
if (R_SUCCEEDED(rc) && out_h)
|
||||||
@ -336,8 +333,7 @@ NX_INLINE Result cmifCloneCurrentObject(Handle h, Handle* out_h)
|
|||||||
{
|
{
|
||||||
cmifMakeControlRequest(armGetTls(), 2, 0);
|
cmifMakeControlRequest(armGetTls(), 2, 0);
|
||||||
Result rc = svcSendSyncRequest(h);
|
Result rc = svcSendSyncRequest(h);
|
||||||
if (R_SUCCEEDED(rc))
|
if (R_SUCCEEDED(rc)) {
|
||||||
{
|
|
||||||
CmifResponse resp = {};
|
CmifResponse resp = {};
|
||||||
rc = cmifParseResponse(&resp, armGetTls(), false, 0);
|
rc = cmifParseResponse(&resp, armGetTls(), false, 0);
|
||||||
if (R_SUCCEEDED(rc) && out_h)
|
if (R_SUCCEEDED(rc) && out_h)
|
||||||
@ -350,8 +346,7 @@ NX_INLINE Result cmifQueryPointerBufferSize(Handle h, u16* out_size)
|
|||||||
{
|
{
|
||||||
cmifMakeControlRequest(armGetTls(), 3, 0);
|
cmifMakeControlRequest(armGetTls(), 3, 0);
|
||||||
Result rc = svcSendSyncRequest(h);
|
Result rc = svcSendSyncRequest(h);
|
||||||
if (R_SUCCEEDED(rc))
|
if (R_SUCCEEDED(rc)) {
|
||||||
{
|
|
||||||
CmifResponse resp = {};
|
CmifResponse resp = {};
|
||||||
rc = cmifParseResponse(&resp, armGetTls(), false, sizeof(u16));
|
rc = cmifParseResponse(&resp, armGetTls(), false, sizeof(u16));
|
||||||
if (R_SUCCEEDED(rc) && out_size)
|
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));
|
void* raw = cmifMakeControlRequest(armGetTls(), 4, sizeof(u32));
|
||||||
*(u32*)raw = tag;
|
*(u32*)raw = tag;
|
||||||
Result rc = svcSendSyncRequest(h);
|
Result rc = svcSendSyncRequest(h);
|
||||||
if (R_SUCCEEDED(rc))
|
if (R_SUCCEEDED(rc)) {
|
||||||
{
|
|
||||||
CmifResponse resp = {};
|
CmifResponse resp = {};
|
||||||
rc = cmifParseResponse(&resp, armGetTls(), false, 0);
|
rc = cmifParseResponse(&resp, armGetTls(), false, 0);
|
||||||
if (R_SUCCEEDED(rc) && out_h)
|
if (R_SUCCEEDED(rc) && out_h)
|
||||||
|
@ -10,16 +10,14 @@
|
|||||||
#include "cmif.h"
|
#include "cmif.h"
|
||||||
|
|
||||||
/// Service object structure
|
/// Service object structure
|
||||||
typedef struct Service
|
typedef struct Service {
|
||||||
{
|
|
||||||
Handle session;
|
Handle session;
|
||||||
u32 own_handle;
|
u32 own_handle;
|
||||||
u32 object_id;
|
u32 object_id;
|
||||||
u16 pointer_buffer_size;
|
u16 pointer_buffer_size;
|
||||||
} Service;
|
} Service;
|
||||||
|
|
||||||
enum
|
enum {
|
||||||
{
|
|
||||||
SfBufferAttr_In = BIT(0),
|
SfBufferAttr_In = BIT(0),
|
||||||
SfBufferAttr_Out = BIT(1),
|
SfBufferAttr_Out = BIT(1),
|
||||||
SfBufferAttr_HipcMapAlias = BIT(2),
|
SfBufferAttr_HipcMapAlias = BIT(2),
|
||||||
@ -41,8 +39,7 @@ typedef struct SfBufferAttrs {
|
|||||||
u32 attr7;
|
u32 attr7;
|
||||||
} SfBufferAttrs;
|
} SfBufferAttrs;
|
||||||
|
|
||||||
typedef struct SfBuffer
|
typedef struct SfBuffer {
|
||||||
{
|
|
||||||
const void* ptr;
|
const void* ptr;
|
||||||
size_t size;
|
size_t size;
|
||||||
} SfBuffer;
|
} SfBuffer;
|
||||||
@ -53,8 +50,7 @@ typedef enum SfOutHandleAttr {
|
|||||||
SfOutHandleAttr_HipcMove = 2,
|
SfOutHandleAttr_HipcMove = 2,
|
||||||
} SfOutHandleAttr;
|
} SfOutHandleAttr;
|
||||||
|
|
||||||
typedef struct SfOutHandleAttrs
|
typedef struct SfOutHandleAttrs {
|
||||||
{
|
|
||||||
SfOutHandleAttr attr0;
|
SfOutHandleAttr attr0;
|
||||||
SfOutHandleAttr attr1;
|
SfOutHandleAttr attr1;
|
||||||
SfOutHandleAttr attr2;
|
SfOutHandleAttr attr2;
|
||||||
@ -65,8 +61,7 @@ typedef struct SfOutHandleAttrs
|
|||||||
SfOutHandleAttr attr7;
|
SfOutHandleAttr attr7;
|
||||||
} SfOutHandleAttrs;
|
} SfOutHandleAttrs;
|
||||||
|
|
||||||
typedef struct SfDispatchParams
|
typedef struct SfDispatchParams {
|
||||||
{
|
|
||||||
Handle target_session;
|
Handle target_session;
|
||||||
u32 context;
|
u32 context;
|
||||||
|
|
||||||
@ -227,8 +222,7 @@ NX_INLINE Result serviceCloneEx(Service* s, u32 tag, Service* out_s)
|
|||||||
*/
|
*/
|
||||||
NX_INLINE Result serviceConvertToDomain(Service* s)
|
NX_INLINE Result serviceConvertToDomain(Service* s)
|
||||||
{
|
{
|
||||||
if (!s->own_handle)
|
if (!s->own_handle) {
|
||||||
{
|
|
||||||
// For overridden services, create a clone first.
|
// For overridden services, create a clone first.
|
||||||
Result rc = cmifCloneCurrentObjectEx(s->session, 0, &s->session);
|
Result rc = cmifCloneCurrentObjectEx(s->session, 0, &s->session);
|
||||||
if (R_FAILED(rc))
|
if (R_FAILED(rc))
|
||||||
@ -358,8 +352,7 @@ NX_INLINE void* serviceMakeRequest(
|
|||||||
|
|
||||||
NX_CONSTEXPR void _serviceResponseGetHandle(CmifResponse* res, SfOutHandleAttr type, Handle* out)
|
NX_CONSTEXPR void _serviceResponseGetHandle(CmifResponse* res, SfOutHandleAttr type, Handle* out)
|
||||||
{
|
{
|
||||||
switch (type)
|
switch (type) {
|
||||||
{
|
|
||||||
default:
|
default:
|
||||||
case SfOutHandleAttr_None:
|
case SfOutHandleAttr_None:
|
||||||
break;
|
break;
|
||||||
@ -391,8 +384,7 @@ NX_INLINE Result serviceParseResponse(
|
|||||||
if (out_size)
|
if (out_size)
|
||||||
*out_data = res.data;
|
*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)
|
if (is_domain)
|
||||||
serviceCreateDomainSubservice(&out_objects[i], s, cmifResponseGetObject(&res));
|
serviceCreateDomainSubservice(&out_objects[i], s, cmifResponseGetObject(&res));
|
||||||
else // Output objects are marshalled as move handles at the beginning of the list.
|
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);
|
__builtin_memcpy(in, in_data, in_data_size);
|
||||||
|
|
||||||
Result rc = svcSendSyncRequest(disp.target_session == INVALID_HANDLE ? s->session : disp.target_session);
|
Result rc = svcSendSyncRequest(disp.target_session == INVALID_HANDLE ? s->session : disp.target_session);
|
||||||
if (R_SUCCEEDED(rc))
|
if (R_SUCCEEDED(rc)) {
|
||||||
{
|
|
||||||
void* out = NULL;
|
void* out = NULL;
|
||||||
rc = serviceParseResponse(s,
|
rc = serviceParseResponse(s,
|
||||||
out_data_size, &out,
|
out_data_size, &out,
|
||||||
|
@ -5,8 +5,7 @@
|
|||||||
#include "sf/service.h"
|
#include "sf/service.h"
|
||||||
#include "services/sm.h"
|
#include "services/sm.h"
|
||||||
|
|
||||||
typedef struct ServiceGuard
|
typedef struct ServiceGuard {
|
||||||
{
|
|
||||||
Mutex mutex;
|
Mutex mutex;
|
||||||
u32 refCount;
|
u32 refCount;
|
||||||
} ServiceGuard;
|
} ServiceGuard;
|
||||||
@ -19,8 +18,7 @@ NX_INLINE bool serviceGuardBeginInit(ServiceGuard* g)
|
|||||||
|
|
||||||
NX_INLINE Result serviceGuardEndInit(ServiceGuard* g, Result rc, void (*cleanupFunc)(void))
|
NX_INLINE Result serviceGuardEndInit(ServiceGuard* g, Result rc, void (*cleanupFunc)(void))
|
||||||
{
|
{
|
||||||
if (R_FAILED(rc))
|
if (R_FAILED(rc)) {
|
||||||
{
|
|
||||||
cleanupFunc();
|
cleanupFunc();
|
||||||
--g->refCount;
|
--g->refCount;
|
||||||
}
|
}
|
||||||
|
@ -29,13 +29,9 @@ void smAddOverrideHandle(u64 name, Handle handle)
|
|||||||
|
|
||||||
Handle smGetServiceOverride(u64 name)
|
Handle smGetServiceOverride(u64 name)
|
||||||
{
|
{
|
||||||
size_t i;
|
for (size_t i = 0; i < g_smOverridesNum; i++)
|
||||||
|
|
||||||
for (i=0; i<g_smOverridesNum; i++)
|
|
||||||
{
|
|
||||||
if (g_smOverrides[i].name == name)
|
if (g_smOverrides[i].name == name)
|
||||||
return g_smOverrides[i].handle;
|
return g_smOverrides[i].handle;
|
||||||
}
|
|
||||||
|
|
||||||
return INVALID_HANDLE;
|
return INVALID_HANDLE;
|
||||||
}
|
}
|
||||||
@ -84,14 +80,12 @@ Result smGetService(Service* service_out, const char* name)
|
|||||||
bool own_handle = false;
|
bool own_handle = false;
|
||||||
Result rc = 0;
|
Result rc = 0;
|
||||||
|
|
||||||
if (handle == INVALID_HANDLE)
|
if (handle == INVALID_HANDLE) {
|
||||||
{
|
|
||||||
own_handle = true;
|
own_handle = true;
|
||||||
rc = smGetServiceOriginal(&handle, name_encoded);
|
rc = smGetServiceOriginal(&handle, name_encoded);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (R_SUCCEEDED(rc))
|
if (R_SUCCEEDED(rc)) {
|
||||||
{
|
|
||||||
serviceCreate(service_out, handle);
|
serviceCreate(service_out, handle);
|
||||||
service_out->own_handle = own_handle;
|
service_out->own_handle = own_handle;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user