diff --git a/nx/include/switch/services/hiddbg.h b/nx/include/switch/services/hiddbg.h index 2863f1cb..c429e394 100644 --- a/nx/include/switch/services/hiddbg.h +++ b/nx/include/switch/services/hiddbg.h @@ -182,8 +182,8 @@ Result hiddbgAttachHdlsWorkBuffer(void); /// Exit Hdls, must be called at some point prior to hiddbgExit. Only available with [7.0.0+]. Result hiddbgReleaseHdlsWorkBuffer(void); -/// Gets the Tmem pointer. Use only after calling hiddbgAttachHdlsWorkBuffer() -TransferMemory *hiddbgGetWorkBufferTransferMemoryAddress(); +/// Checks if the given HdlsHandle is still attached, where the result is written to isAttached. Only available with [7.0.0+]. +Result hiddbgIsHdlsVirtualDeviceAttached(u64 HdlsHandle, bool *isAttached); /// Gets state for \ref HiddbgHdlsNpadAssignment. Only available with [7.0.0+]. Result hiddbgDumpHdlsNpadAssignmentState(HiddbgHdlsNpadAssignment *state); diff --git a/nx/source/services/hiddbg.c b/nx/source/services/hiddbg.c index 408c038e..1c9ce114 100644 --- a/nx/source/services/hiddbg.c +++ b/nx/source/services/hiddbg.c @@ -392,9 +392,48 @@ Result hiddbgReleaseHdlsWorkBuffer(void) { return rc; } -TransferMemory *hiddbgGetWorkBufferTransferMemoryAddress() +Result hiddbgIsHdlsVirtualDeviceAttached(u64 HdlsHandle, bool *isAttached) { - return &g_hiddbgHdlsTmem; + Result rc = 0; + + if (hosversionBefore(7, 0, 0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + if (!g_hiddbgHdlsInitialized) + return MAKERESULT(Module_Libnx, LibnxError_NotInitialized); + + rc = _hiddbgCmdNoIO(327); + if (R_FAILED(rc)) + return rc; + if (isAttached) + { + *isAttached = false; + if (hosversionBefore(9, 0, 0)) + { + HiddbgHdlsStateListV7 *stateList = (HiddbgHdlsStateListV7 *)(g_hiddbgHdlsTmem.src_addr); + for (s32 i = 0; i < stateList->total_entries; i++) + { + if (stateList->entries[i].HdlsHandle == HdlsHandle) + { + *isAttached = true; + break; + } + } + } + else + { + HiddbgHdlsStateList *stateList = (HiddbgHdlsStateList *)(g_hiddbgHdlsTmem.src_addr); + for (s32 i = 0; i < stateList->total_entries; i++) + { + if (stateList->entries[i].HdlsHandle == HdlsHandle) + { + *isAttached = true; + break; + } + } + } + } + return rc; } Result hiddbgDumpHdlsNpadAssignmentState(HiddbgHdlsNpadAssignment *state) {