Make it possible to use the binder API with an arbitrary service (#309)

This is useful if you want to connect to "dispdrv" for example.
This commit is contained in:
Thomas Guillemard 2019-07-18 19:12:03 +02:00 committed by fincs
parent c73b8ceeb9
commit 3f6cf66243
3 changed files with 19 additions and 16 deletions

View File

@ -1,22 +1,24 @@
#pragma once #pragma once
#include "../types.h" #include "../types.h"
#include "../kernel/event.h" #include "../kernel/event.h"
#include "../services/sm.h"
#define BINDER_FIRST_CALL_TRANSACTION 0x1 #define BINDER_FIRST_CALL_TRANSACTION 0x1
typedef struct { typedef struct {
bool created : 1; bool created : 1;
bool initialized : 1; bool initialized : 1;
bool has_transact_auto : 1; bool has_transact_auto : 1;
s32 id; s32 id;
size_t ipc_buffer_size; size_t ipc_buffer_size;
Service* relay;
} Binder; } Binder;
// Note: binderClose will not close the session_handle provided to binderCreate. // Note: binderClose will not close the session_handle provided to binderCreate.
void binderCreate(Binder* b, s32 id); void binderCreate(Binder* b, s32 id);
void binderClose(Binder* b); void binderClose(Binder* b);
Result binderInitSession(Binder* b); Result binderInitSession(Binder* b, Service* relay);
Result binderTransactParcel( Result binderTransactParcel(
Binder* b, u32 code, Binder* b, u32 code,

View File

@ -3,12 +3,11 @@
#include "result.h" #include "result.h"
#include "kernel/ipc.h" #include "kernel/ipc.h"
#include "runtime/hosversion.h" #include "runtime/hosversion.h"
#include "services/vi.h"
#include "display/binder.h" #include "display/binder.h"
static Result _binderIpcDispatch(void) static Result _binderIpcDispatch(Binder* b)
{ {
return serviceIpcDispatch(viGetSession_IHOSBinderDriverRelay()); return serviceIpcDispatch(b->relay);
} }
void binderCreate(Binder* b, s32 id) void binderCreate(Binder* b, s32 id)
@ -18,7 +17,7 @@ void binderCreate(Binder* b, s32 id)
b->id = id; b->id = id;
} }
Result binderInitSession(Binder* b) Result binderInitSession(Binder* b, Service* relay)
{ {
Result rc = 0; Result rc = 0;
@ -28,6 +27,8 @@ Result binderInitSession(Binder* b)
if (b->initialized) if (b->initialized)
return MAKERESULT(Module_Libnx, LibnxError_AlreadyInitialized); return MAKERESULT(Module_Libnx, LibnxError_AlreadyInitialized);
b->relay = relay;
rc = binderIncreaseWeakRef(b); rc = binderIncreaseWeakRef(b);
if (R_FAILED(rc)) if (R_FAILED(rc))
return rc; return rc;
@ -40,7 +41,7 @@ Result binderInitSession(Binder* b)
b->initialized = true; b->initialized = true;
rc = ipcQueryPointerBufferSize(viGetSession_IHOSBinderDriverRelay()->handle, &b->ipc_buffer_size); rc = ipcQueryPointerBufferSize(b->relay->handle, &b->ipc_buffer_size);
if (R_FAILED(rc)) { if (R_FAILED(rc)) {
binderClose(b); binderClose(b);
return rc; return rc;
@ -99,7 +100,7 @@ static Result _binderTransactParcel(
raw->code = code; raw->code = code;
raw->flags = flags; raw->flags = flags;
Result rc = _binderIpcDispatch(); Result rc = _binderIpcDispatch(b);
if (R_SUCCEEDED(rc)) { if (R_SUCCEEDED(rc)) {
IpcParsedCommand r; IpcParsedCommand r;
@ -146,7 +147,7 @@ static Result _binderTransactParcelAuto(
raw->code = code; raw->code = code;
raw->flags = flags; raw->flags = flags;
Result rc = _binderIpcDispatch(); Result rc = _binderIpcDispatch(b);
if (R_SUCCEEDED(rc)) { if (R_SUCCEEDED(rc)) {
IpcParsedCommand r; IpcParsedCommand r;
@ -228,7 +229,7 @@ Result binderAdjustRefcount(Binder* b, s32 addval, s32 type)
raw->addval = addval; raw->addval = addval;
raw->type = type; raw->type = type;
Result rc = _binderIpcDispatch(); Result rc = _binderIpcDispatch(b);
if (R_SUCCEEDED(rc)) { if (R_SUCCEEDED(rc)) {
IpcParsedCommand r; IpcParsedCommand r;
@ -267,7 +268,7 @@ Result binderGetNativeHandle(Binder* b, u32 inval, Event *event_out)
raw->session_id = b->id; raw->session_id = b->id;
raw->inval = inval; raw->inval = inval;
Result rc = _binderIpcDispatch(); Result rc = _binderIpcDispatch(b);
if (R_SUCCEEDED(rc)) { if (R_SUCCEEDED(rc)) {
IpcParsedCommand r; IpcParsedCommand r;

View File

@ -60,7 +60,7 @@ Result nwindowCreate(NWindow* nw, s32 binder_id, bool producer_controlled_by_app
nw->producer_controlled_by_app = producer_controlled_by_app; nw->producer_controlled_by_app = producer_controlled_by_app;
binderCreate(&nw->bq, binder_id); binderCreate(&nw->bq, binder_id);
rc = binderInitSession(&nw->bq); rc = binderInitSession(&nw->bq, viGetSession_IHOSBinderDriverRelay());
if (R_SUCCEEDED(rc)) if (R_SUCCEEDED(rc))
binderGetNativeHandle(&nw->bq, 0x0f, &nw->event); binderGetNativeHandle(&nw->bq, 0x0f, &nw->event);