mirror of
https://github.com/switchbrew/libnx.git
synced 2025-06-21 12:32:40 +02:00
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:
parent
c73b8ceeb9
commit
3f6cf66243
@ -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,
|
||||
|
@ -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)
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
@ -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;
|
||||
@ -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;
|
||||
@ -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;
|
||||
@ -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;
|
||||
@ -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;
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user