From 3999ec147e25239ba77a034ee16543e35d6daeaa Mon Sep 17 00:00:00 2001 From: yellows8 Date: Tue, 27 Aug 2019 18:32:53 -0400 Subject: [PATCH] Use serviceIpcPrepareHeader/serviceIpcParse with binder to support using domains. --- nx/source/display/binder.c | 44 +++++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/nx/source/display/binder.c b/nx/source/display/binder.c index 6d180dec..f757dde8 100644 --- a/nx/source/display/binder.c +++ b/nx/source/display/binder.c @@ -5,11 +5,21 @@ #include "runtime/hosversion.h" #include "display/binder.h" +static void* _binderIpcPrepareHeader(Binder* b, IpcCommand* cmd, size_t sizeof_raw) +{ + return serviceIpcPrepareHeader(b->relay, cmd, sizeof_raw); +} + static Result _binderIpcDispatch(Binder* b) { return serviceIpcDispatch(b->relay); } +static Result _binderIpcParse(Binder* b, IpcParsedCommand* r, size_t sizeof_raw) +{ + return serviceIpcParse(b->relay, r, sizeof_raw); +} + void binderCreate(Binder* b, s32 id) { memset(b, 0, sizeof(Binder)); @@ -93,7 +103,7 @@ static Result _binderTransactParcel( ipcAddSendBuffer(&c, parcel_data, parcel_data_size, 0); ipcAddRecvBuffer(&c, parcel_reply, parcel_reply_size, 0); - raw = ipcPrepareHeader(&c, sizeof(*raw)); + raw = _binderIpcPrepareHeader(b, &c, sizeof(*raw)); raw->magic = SFCI_MAGIC; raw->cmd_id = 0; raw->session_id = b->id; @@ -104,12 +114,13 @@ static Result _binderTransactParcel( if (R_SUCCEEDED(rc)) { IpcParsedCommand r; - ipcParse(&r); - struct { u64 magic; u64 result; - } *resp = r.Raw; + } *resp; + + _binderIpcParse(b, &r, sizeof(*resp)); + resp = r.Raw; rc = resp->result; } @@ -140,7 +151,7 @@ static Result _binderTransactParcelAuto( ipcAddSendSmart(&c, b->ipc_buffer_size, parcel_data, parcel_data_size, 0); ipcAddRecvSmart(&c, b->ipc_buffer_size, parcel_reply, parcel_reply_size, 0); - raw = ipcPrepareHeader(&c, sizeof(*raw)); + raw = _binderIpcPrepareHeader(b, &c, sizeof(*raw)); raw->magic = SFCI_MAGIC; raw->cmd_id = 3; raw->session_id = b->id; @@ -151,12 +162,13 @@ static Result _binderTransactParcelAuto( if (R_SUCCEEDED(rc)) { IpcParsedCommand r; - ipcParse(&r); - struct { u64 magic; u64 result; - } *resp = r.Raw; + } *resp; + + _binderIpcParse(b, &r, sizeof(*resp)); + resp = r.Raw; rc = resp->result; } @@ -222,7 +234,7 @@ Result binderAdjustRefcount(Binder* b, s32 addval, s32 type) s32 type; } *raw; - raw = ipcPrepareHeader(&c, sizeof(*raw)); + raw = _binderIpcPrepareHeader(b, &c, sizeof(*raw)); raw->magic = SFCI_MAGIC; raw->cmd_id = 1; raw->session_id = b->id; @@ -233,12 +245,13 @@ Result binderAdjustRefcount(Binder* b, s32 addval, s32 type) if (R_SUCCEEDED(rc)) { IpcParsedCommand r; - ipcParse(&r); - struct { u64 magic; u64 result; - } *resp = r.Raw; + } *resp; + + _binderIpcParse(b, &r, sizeof(*resp)); + resp = r.Raw; rc = resp->result; } @@ -261,7 +274,7 @@ Result binderGetNativeHandle(Binder* b, u32 inval, Event *event_out) u32 inval; } *raw; - raw = ipcPrepareHeader(&c, sizeof(*raw)); + raw = _binderIpcPrepareHeader(b, &c, sizeof(*raw)); raw->magic = SFCI_MAGIC; raw->cmd_id = 2; @@ -272,13 +285,14 @@ Result binderGetNativeHandle(Binder* b, u32 inval, Event *event_out) if (R_SUCCEEDED(rc)) { IpcParsedCommand r; - ipcParse(&r); - struct { u64 magic; u64 result; } *resp = r.Raw; + _binderIpcParse(b, &r, sizeof(*resp)); + resp = r.Raw; + rc = resp->result; if (R_SUCCEEDED(rc)) {