diff --git a/nx/include/switch/display/binder.h b/nx/include/switch/display/binder.h index a8ad8689..dfa6fb49 100644 --- a/nx/include/switch/display/binder.h +++ b/nx/include/switch/display/binder.h @@ -24,6 +24,8 @@ Result binderTransactParcel( void* parcel_reply, size_t parcel_reply_size, u32 flags); +Result binderConvertErrorCode(s32 code); + Result binderAdjustRefcount(Binder* b, s32 addval, s32 type); Result binderGetNativeHandle(Binder* b, u32 unk0, Event *event_out); diff --git a/nx/include/switch/result.h b/nx/include/switch/result.h index bf849a05..a2b569f5 100644 --- a/nx/include/switch/result.h +++ b/nx/include/switch/result.h @@ -23,6 +23,7 @@ enum { Module_Kernel=1, Module_Libnx=345, + Module_LibnxBinder=347, Module_LibnxNvidia=348, }; @@ -80,6 +81,27 @@ enum { LibnxError_NvbufFailedToInitialize, }; +/// libnx binder error codes +enum { + LibnxBinderError_Unknown=1, + LibnxBinderError_NoMemory, + LibnxBinderError_InvalidOperation, + LibnxBinderError_BadValue, + LibnxBinderError_BadType, + LibnxBinderError_NameNotFound, + LibnxBinderError_PermissionDenied, + LibnxBinderError_NoInit, + LibnxBinderError_AlreadyExists, + LibnxBinderError_DeadObject, + LibnxBinderError_FailedTransaction, + LibnxBinderError_BadIndex, + LibnxBinderError_NotEnoughData, + LibnxBinderError_WouldBlock, + LibnxBinderError_TimedOut, + LibnxBinderError_UnknownTransaction, + LibnxBinderError_FdsNotAllowed, +}; + /// libnx nvidia error codes enum { LibnxNvidiaError_Unknown=1, diff --git a/nx/source/display/binder.c b/nx/source/display/binder.c index c72ba95b..6ee7e26d 100644 --- a/nx/source/display/binder.c +++ b/nx/source/display/binder.c @@ -179,6 +179,32 @@ Result binderTransactParcel( return rc; } +Result binderConvertErrorCode(s32 code) +{ + if (code >= 0) + return 0; + + switch (-code) { + case 1: return MAKERESULT(Module_LibnxBinder, LibnxBinderError_PermissionDenied); + case 2: return MAKERESULT(Module_LibnxBinder, LibnxBinderError_NameNotFound); + case 11: return MAKERESULT(Module_LibnxBinder, LibnxBinderError_WouldBlock); + case 12: return MAKERESULT(Module_LibnxBinder, LibnxBinderError_NoMemory); + case 17: return MAKERESULT(Module_LibnxBinder, LibnxBinderError_AlreadyExists); + case 19: return MAKERESULT(Module_LibnxBinder, LibnxBinderError_NoInit); + case 22: return MAKERESULT(Module_LibnxBinder, LibnxBinderError_BadValue); + case 32: return MAKERESULT(Module_LibnxBinder, LibnxBinderError_DeadObject); + case 38: return MAKERESULT(Module_LibnxBinder, LibnxBinderError_InvalidOperation); + case 61: return MAKERESULT(Module_LibnxBinder, LibnxBinderError_NotEnoughData); + case 74: return MAKERESULT(Module_LibnxBinder, LibnxBinderError_UnknownTransaction); + case 75: return MAKERESULT(Module_LibnxBinder, LibnxBinderError_BadIndex); + case 110: return MAKERESULT(Module_LibnxBinder, LibnxBinderError_TimedOut); + case -(INT32_MIN+7): return MAKERESULT(Module_LibnxBinder, LibnxBinderError_FdsNotAllowed); + case -(INT32_MIN+2): return MAKERESULT(Module_LibnxBinder, LibnxBinderError_FailedTransaction); + case -(INT32_MIN+1): return MAKERESULT(Module_LibnxBinder, LibnxBinderError_BadType); + default: return MAKERESULT(Module_LibnxBinder, LibnxBinderError_Unknown); + } +} + Result binderAdjustRefcount(Binder* b, s32 addval, s32 type) { if (!b->created)