Skip to content

Commit

Permalink
Make it possible to use the binder API with an arbitrary service (#309)
Browse files Browse the repository at this point in the history
This is useful if you want to connect to "dispdrv" for example.
  • Loading branch information
Thomas Guillemard authored and fincs committed Jul 18, 2019
1 parent c73b8ce commit 3f6cf66
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
14 changes: 8 additions & 6 deletions nx/include/switch/display/binder.h
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
#pragma once
#include "../types.h"
#include "../kernel/event.h"
#include "../services/sm.h"

#define BINDER_FIRST_CALL_TRANSACTION 0x1

typedef struct {
bool created : 1;
bool initialized : 1;
bool has_transact_auto : 1;
s32 id;
size_t ipc_buffer_size;
bool created : 1;
bool initialized : 1;
bool has_transact_auto : 1;
s32 id;
size_t ipc_buffer_size;
Service* relay;
} Binder;

// Note: binderClose will not close the session_handle provided to binderCreate.
void binderCreate(Binder* b, s32 id);
void binderClose(Binder* b);

Result binderInitSession(Binder* b);
Result binderInitSession(Binder* b, Service* relay);

Result binderTransactParcel(
Binder* b, u32 code,
Expand Down
19 changes: 10 additions & 9 deletions nx/source/display/binder.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
#include "result.h"
#include "kernel/ipc.h"
#include "runtime/hosversion.h"
#include "services/vi.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)
Expand All @@ -18,7 +17,7 @@ void binderCreate(Binder* b, s32 id)
b->id = id;
}

Result binderInitSession(Binder* b)
Result binderInitSession(Binder* b, Service* relay)
{
Result rc = 0;

Expand All @@ -28,6 +27,8 @@ Result binderInitSession(Binder* b)
if (b->initialized)
return MAKERESULT(Module_Libnx, LibnxError_AlreadyInitialized);

b->relay = relay;

rc = binderIncreaseWeakRef(b);
if (R_FAILED(rc))
return rc;
Expand All @@ -40,7 +41,7 @@ Result binderInitSession(Binder* b)

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)) {
binderClose(b);
return rc;
Expand Down Expand Up @@ -99,7 +100,7 @@ static Result _binderTransactParcel(
raw->code = code;
raw->flags = flags;

Result rc = _binderIpcDispatch();
Result rc = _binderIpcDispatch(b);

if (R_SUCCEEDED(rc)) {
IpcParsedCommand r;
Expand Down Expand Up @@ -146,7 +147,7 @@ static Result _binderTransactParcelAuto(
raw->code = code;
raw->flags = flags;

Result rc = _binderIpcDispatch();
Result rc = _binderIpcDispatch(b);

if (R_SUCCEEDED(rc)) {
IpcParsedCommand r;
Expand Down Expand Up @@ -228,7 +229,7 @@ Result binderAdjustRefcount(Binder* b, s32 addval, s32 type)
raw->addval = addval;
raw->type = type;

Result rc = _binderIpcDispatch();
Result rc = _binderIpcDispatch(b);

if (R_SUCCEEDED(rc)) {
IpcParsedCommand r;
Expand Down Expand Up @@ -267,7 +268,7 @@ Result binderGetNativeHandle(Binder* b, u32 inval, Event *event_out)
raw->session_id = b->id;
raw->inval = inval;

Result rc = _binderIpcDispatch();
Result rc = _binderIpcDispatch(b);

if (R_SUCCEEDED(rc)) {
IpcParsedCommand r;
Expand Down
2 changes: 1 addition & 1 deletion nx/source/display/native_window.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

binderCreate(&nw->bq, binder_id);
rc = binderInitSession(&nw->bq);
rc = binderInitSession(&nw->bq, viGetSession_IHOSBinderDriverRelay());

if (R_SUCCEEDED(rc))
binderGetNativeHandle(&nw->bq, 0x0f, &nw->event);
Expand Down

0 comments on commit 3f6cf66

Please sign in to comment.