diff --git a/nx/include/switch/display/binder.h b/nx/include/switch/display/binder.h index dfa6fb49e..aa8cefc7d 100644 --- a/nx/include/switch/display/binder.h +++ b/nx/include/switch/display/binder.h @@ -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, diff --git a/nx/source/display/binder.c b/nx/source/display/binder.c index 2b94defff..6d180dec4 100644 --- a/nx/source/display/binder.c +++ b/nx/source/display/binder.c @@ -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; diff --git a/nx/source/display/native_window.c b/nx/source/display/native_window.c index 6bca01923..78a722094 100644 --- a/nx/source/display/native_window.c +++ b/nx/source/display/native_window.c @@ -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);