Use serviceIpcPrepareHeader/serviceIpcParse with binder to support using domains.

This commit is contained in:
yellows8 2019-08-27 18:32:53 -04:00
parent 4177031ebe
commit 3999ec147e
No known key found for this signature in database
GPG Key ID: 0AF90DA3F1E60E43

View File

@ -5,11 +5,21 @@
#include "runtime/hosversion.h" #include "runtime/hosversion.h"
#include "display/binder.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) static Result _binderIpcDispatch(Binder* b)
{ {
return serviceIpcDispatch(b->relay); 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) void binderCreate(Binder* b, s32 id)
{ {
memset(b, 0, sizeof(Binder)); memset(b, 0, sizeof(Binder));
@ -93,7 +103,7 @@ static Result _binderTransactParcel(
ipcAddSendBuffer(&c, parcel_data, parcel_data_size, 0); ipcAddSendBuffer(&c, parcel_data, parcel_data_size, 0);
ipcAddRecvBuffer(&c, parcel_reply, parcel_reply_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->magic = SFCI_MAGIC;
raw->cmd_id = 0; raw->cmd_id = 0;
raw->session_id = b->id; raw->session_id = b->id;
@ -104,12 +114,13 @@ static Result _binderTransactParcel(
if (R_SUCCEEDED(rc)) { if (R_SUCCEEDED(rc)) {
IpcParsedCommand r; IpcParsedCommand r;
ipcParse(&r);
struct { struct {
u64 magic; u64 magic;
u64 result; u64 result;
} *resp = r.Raw; } *resp;
_binderIpcParse(b, &r, sizeof(*resp));
resp = r.Raw;
rc = resp->result; rc = resp->result;
} }
@ -140,7 +151,7 @@ static Result _binderTransactParcelAuto(
ipcAddSendSmart(&c, b->ipc_buffer_size, parcel_data, parcel_data_size, 0); ipcAddSendSmart(&c, b->ipc_buffer_size, parcel_data, parcel_data_size, 0);
ipcAddRecvSmart(&c, b->ipc_buffer_size, parcel_reply, parcel_reply_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->magic = SFCI_MAGIC;
raw->cmd_id = 3; raw->cmd_id = 3;
raw->session_id = b->id; raw->session_id = b->id;
@ -151,12 +162,13 @@ static Result _binderTransactParcelAuto(
if (R_SUCCEEDED(rc)) { if (R_SUCCEEDED(rc)) {
IpcParsedCommand r; IpcParsedCommand r;
ipcParse(&r);
struct { struct {
u64 magic; u64 magic;
u64 result; u64 result;
} *resp = r.Raw; } *resp;
_binderIpcParse(b, &r, sizeof(*resp));
resp = r.Raw;
rc = resp->result; rc = resp->result;
} }
@ -222,7 +234,7 @@ Result binderAdjustRefcount(Binder* b, s32 addval, s32 type)
s32 type; s32 type;
} *raw; } *raw;
raw = ipcPrepareHeader(&c, sizeof(*raw)); raw = _binderIpcPrepareHeader(b, &c, sizeof(*raw));
raw->magic = SFCI_MAGIC; raw->magic = SFCI_MAGIC;
raw->cmd_id = 1; raw->cmd_id = 1;
raw->session_id = b->id; raw->session_id = b->id;
@ -233,12 +245,13 @@ Result binderAdjustRefcount(Binder* b, s32 addval, s32 type)
if (R_SUCCEEDED(rc)) { if (R_SUCCEEDED(rc)) {
IpcParsedCommand r; IpcParsedCommand r;
ipcParse(&r);
struct { struct {
u64 magic; u64 magic;
u64 result; u64 result;
} *resp = r.Raw; } *resp;
_binderIpcParse(b, &r, sizeof(*resp));
resp = r.Raw;
rc = resp->result; rc = resp->result;
} }
@ -261,7 +274,7 @@ Result binderGetNativeHandle(Binder* b, u32 inval, Event *event_out)
u32 inval; u32 inval;
} *raw; } *raw;
raw = ipcPrepareHeader(&c, sizeof(*raw)); raw = _binderIpcPrepareHeader(b, &c, sizeof(*raw));
raw->magic = SFCI_MAGIC; raw->magic = SFCI_MAGIC;
raw->cmd_id = 2; raw->cmd_id = 2;
@ -272,13 +285,14 @@ Result binderGetNativeHandle(Binder* b, u32 inval, Event *event_out)
if (R_SUCCEEDED(rc)) { if (R_SUCCEEDED(rc)) {
IpcParsedCommand r; IpcParsedCommand r;
ipcParse(&r);
struct { struct {
u64 magic; u64 magic;
u64 result; u64 result;
} *resp = r.Raw; } *resp = r.Raw;
_binderIpcParse(b, &r, sizeof(*resp));
resp = r.Raw;
rc = resp->result; rc = resp->result;
if (R_SUCCEEDED(rc)) { if (R_SUCCEEDED(rc)) {