Changeset 80877 in vbox for trunk/src/VBox/HostDrivers/VBoxUSB/win
- Timestamp:
- Sep 18, 2019 10:08:33 AM (6 years ago)
- svn:sync-xref-src-repo-rev:
- 133450
- Location:
- trunk/src/VBox/HostDrivers/VBoxUSB/win
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified trunk/src/VBox/HostDrivers/VBoxUSB/win/lib/VBoxUsbLib-win.cpp ¶
r80685 r80877 51 51 #include <usbdi.h> 52 52 #include <hidsdi.h> 53 #include <Dbt.h> 53 54 54 55 /* Defined in Windows 8 DDK (through usbdi.h) but we use Windows 7 DDK to build. */ 55 56 #define UsbSuperSpeed 3 56 57 #define VBOX_USB_USE_DEVICE_NOTIFICATION58 59 #ifdef VBOX_USB_USE_DEVICE_NOTIFICATION60 # include <Dbt.h>61 #endif62 57 63 58 #ifdef VBOX_WITH_NEW_USB_ENUM … … 88 83 HANDLE hNotifyEvent; 89 84 HANDLE hInterruptEvent; 90 #ifdef VBOX_USB_USE_DEVICE_NOTIFICATION91 85 HANDLE hThread; 92 86 HWND hWnd; 93 87 HANDLE hTimerQueue; 94 88 HANDLE hTimer; 95 #endif96 89 } VBOXUSBGLOBALSTATE, *PVBOXUSBGLOBALSTATE; 97 90 … … 525 518 { 526 519 DWORD dwErr = GetLastError(); 527 LogRelFunc((" DeviceIoControl 1 fail dwErr (%d) on hub %s port %d\n", dwErr, lpcszHubName, iPort));520 LogRelFunc(("IOCTL_USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION #1 failed (dwErr=%d) on hub %s port %d\n", dwErr, lpcszHubName, iPort)); 528 521 #ifdef VBOX_WITH_ANNOYING_USB_ASSERTIONS 529 522 AssertFailed(); … … 562 555 { 563 556 DWORD dwErr = GetLastError(); 564 LogRelFunc((" DeviceIoControl 2 fail dwErr (%d) on hub %s port %d\n", dwErr, lpcszHubName, iPort));557 LogRelFunc(("IOCTL_USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION #2 failed (dwErr=%d) on hub %s port %d\n", dwErr, lpcszHubName, iPort)); 565 558 #ifdef VBOX_WITH_ANNOYING_USB_ASSERTIONS 566 559 AssertFailed(); … … 810 803 if (!lpszName) 811 804 { 812 LogRelFunc((" warning: no DriverKey on hub %s port %d\n", lpcszHubName, iPort));805 LogRelFunc(("No DriverKey on hub %s port %d\n", lpcszHubName, iPort)); 813 806 lpszName = &nameEmptyBuf; 814 807 fFreeNameBuf = false; … … 1043 1036 if (cr != CR_SUCCESS) 1044 1037 { 1045 LogRelFunc(("Failed to get device ID size , error %ld\n", GetLastError()));1038 LogRelFunc(("Failed to get device ID size (DevInst=%X), error %ld\n", DevInst, GetLastError())); 1046 1039 return NULL; 1047 1040 } … … 1056 1049 if (cr != CR_SUCCESS) 1057 1050 { 1058 LogRelFunc(("Failed to get device ID , error %ld\n", GetLastError()));1051 LogRelFunc(("Failed to get device ID (DevInst=%X), error %ld\n", DevInst, GetLastError())); 1059 1052 RTMemFree(InstanceID); 1060 1053 return NULL; … … 1090 1083 if (HubDevice == INVALID_HANDLE_VALUE) 1091 1084 { 1092 LogRelFunc(("Failed to open hub `%s' , dwErr(%d)\n", lpcszHubFile, GetLastError()));1085 LogRelFunc(("Failed to open hub `%s' (dwErr=%d)\n", lpcszHubFile, GetLastError())); 1093 1086 return VERR_FILE_NOT_FOUND; 1094 1087 } … … 1389 1382 *pcDevs = 0; 1390 1383 1384 LogRelFunc(("Starting USB device enumeration\n")); 1391 1385 int rc = usbLibDevGetDevices(ppDevs, pcDevs); 1392 1386 AssertRC(rc); … … 1404 1398 } 1405 1399 1400 LogRelFunc(("Found %u USB devices, %u captured\n", *pcDevs, cDevInfos)); 1406 1401 return VINF_SUCCESS; 1407 1402 } … … 1548 1543 } 1549 1544 1550 1551 #ifdef VBOX_USB_USE_DEVICE_NOTIFICATION1552 1545 1553 1546 static VOID CALLBACK usbLibTimerCallback(__in PVOID lpParameter, __in BOOLEAN TimerOrWaitFired) … … 1681 1674 } 1682 1675 1683 #endif /* VBOX_USB_USE_DEVICE_NOTIFICATION */1684 1676 1685 1677 /** … … 1702 1694 g_VBoxUsbGlobal.hNotifyEvent = CreateEvent(NULL, /* LPSECURITY_ATTRIBUTES lpEventAttributes */ 1703 1695 FALSE, /* BOOL bManualReset */ 1704 #ifndef VBOX_USB_USE_DEVICE_NOTIFICATION1705 TRUE, /* BOOL bInitialState */1706 #else1707 1696 FALSE, /* set to false since it will be initially used for notification thread startup sync */ 1708 #endif1709 1697 NULL /* LPCTSTR lpName */); 1710 1698 if (g_VBoxUsbGlobal.hNotifyEvent) … … 1742 1730 { 1743 1731 DWORD dwErr = GetLastError(); 1744 LogRelFunc(("CreateFile failed dwErr(%d)\n", dwErr));1732 LogRelFunc(("CreateFile failed (dwErr=%d) for `%s'\n", dwErr, USBMON_DEVICE_NAME)); 1745 1733 rc = VERR_FILE_NOT_FOUND; 1746 1734 } … … 1772 1760 ) 1773 1761 { 1774 #ifndef VBOX_USB_USE_DEVICE_NOTIFICATION1775 /*1776 * Tell the monitor driver which event object to use1777 * for notifications.1778 */1779 USBSUP_SET_NOTIFY_EVENT SetEvent = {0};1780 Assert(g_VBoxUsbGlobal.hNotifyEvent);1781 SetEvent.u.hEvent = g_VBoxUsbGlobal.hNotifyEvent;1782 if (DeviceIoControl(g_VBoxUsbGlobal.hMonitor, SUPUSBFLT_IOCTL_SET_NOTIFY_EVENT,1783 &SetEvent, sizeof(SetEvent),1784 &SetEvent, sizeof(SetEvent),1785 &cbReturned, NULL))1786 {1787 rc = SetEvent.u.rc;1788 if (RT_SUCCESS(rc))1789 {1790 /*1791 * We're DONE!1792 */1793 return VINF_SUCCESS;1794 }1795 1796 AssertMsgFailed(("SetEvent failed, %Rrc (%d)\n", rc, rc));1797 }1798 else1799 {1800 DWORD dwErr = GetLastError();1801 AssertMsgFailed(("SetEvent Ioctl failed, dwErr (%d)\n", dwErr));1802 rc = VERR_VERSION_MISMATCH;1803 }1804 #else1805 1762 /* 1806 1763 * We can not use USB Mon for reliable device add/remove tracking … … 1845 1802 BOOL fRc = CloseHandle(g_VBoxUsbGlobal.hThread); NOREF(fRc); 1846 1803 DWORD dwErr = GetLastError(); NOREF(dwErr); 1847 AssertMsg(fRc, ("CloseHandle for hThread failed dwErr(%d)\n", dwErr));1804 AssertMsg(fRc, ("CloseHandle for hThread failed (dwErr=%d)\n", dwErr)); 1848 1805 g_VBoxUsbGlobal.hThread = INVALID_HANDLE_VALUE; 1849 1806 } … … 1861 1818 { 1862 1819 DWORD dwErr = GetLastError(); NOREF(dwErr); 1863 AssertMsgFailed(("CreateTimerQueue failed dwErr(%d)\n", dwErr));1820 AssertMsgFailed(("CreateTimerQueue failed (dwErr=%d)\n", dwErr)); 1864 1821 } 1865 #endif1866 1822 } 1867 1823 else … … 1878 1834 { 1879 1835 DWORD dwErr = GetLastError(); NOREF(dwErr); 1880 AssertMsgFailed(("DeviceIoControl failed dwErr(%d)\n", dwErr)); 1836 LogRelFunc(("SUPUSBFLT_IOCTL_GET_VERSION failed (dwErr=%d)\n", dwErr)); 1837 AssertFailed(); 1881 1838 rc = VERR_VERSION_MISMATCH; 1882 1839 } … … 1900 1857 { 1901 1858 DWORD dwErr = GetLastError(); NOREF(dwErr); 1902 AssertMsgFailed(("CreateEvent for InterruptEvent failed dwErr(%d)\n", dwErr));1859 AssertMsgFailed(("CreateEvent for InterruptEvent failed (dwErr=%d)\n", dwErr)); 1903 1860 rc = VERR_GENERAL_FAILURE; 1904 1861 } … … 1910 1867 { 1911 1868 DWORD dwErr = GetLastError(); NOREF(dwErr); 1912 AssertMsgFailed(("CreateEvent for NotifyEvent failed dwErr(%d)\n", dwErr));1869 AssertMsgFailed(("CreateEvent for NotifyEvent failed (dwErr=%d)\n", dwErr)); 1913 1870 rc = VERR_GENERAL_FAILURE; 1914 1871 } … … 1937 1894 1938 1895 BOOL fRc; 1939 #ifdef VBOX_USB_USE_DEVICE_NOTIFICATION1940 1896 fRc = PostMessage(g_VBoxUsbGlobal.hWnd, WM_CLOSE, 0, 0); 1941 AssertMsg(fRc, ("PostMessage for hWnd failed dwErr(%d)\n", GetLastError()));1897 AssertMsg(fRc, ("PostMessage for hWnd failed (dwErr=%d)\n", GetLastError())); 1942 1898 1943 1899 if (g_VBoxUsbGlobal.hThread != NULL) … … 1946 1902 Assert(dwResult == WAIT_OBJECT_0); NOREF(dwResult); 1947 1903 fRc = CloseHandle(g_VBoxUsbGlobal.hThread); 1948 AssertMsg(fRc, ("CloseHandle for hThread failed dwErr(%d)\n", GetLastError()));1904 AssertMsg(fRc, ("CloseHandle for hThread failed (dwErr=%d)\n", GetLastError())); 1949 1905 } 1950 1906 … … 1953 1909 fRc = DeleteTimerQueueTimer(g_VBoxUsbGlobal.hTimerQueue, g_VBoxUsbGlobal.hTimer, 1954 1910 INVALID_HANDLE_VALUE); /* <-- to block until the timer is completed */ 1955 AssertMsg(fRc, ("DeleteTimerQueueTimer failed dwErr(%d)\n", GetLastError()));1911 AssertMsg(fRc, ("DeleteTimerQueueTimer failed (dwErr=%d)\n", GetLastError())); 1956 1912 } 1957 1913 … … 1960 1916 fRc = DeleteTimerQueueEx(g_VBoxUsbGlobal.hTimerQueue, 1961 1917 INVALID_HANDLE_VALUE); /* <-- to block until all timers are completed */ 1962 AssertMsg(fRc, ("DeleteTimerQueueEx failed dwErr(%d)\n", GetLastError())); 1963 } 1964 #endif /* VBOX_USB_USE_DEVICE_NOTIFICATION */ 1918 AssertMsg(fRc, ("DeleteTimerQueueEx failed (dwErr=%d)\n", GetLastError())); 1919 } 1965 1920 1966 1921 fRc = CloseHandle(g_VBoxUsbGlobal.hMonitor); 1967 AssertMsg(fRc, ("CloseHandle for hMonitor failed dwErr(%d)\n", GetLastError()));1922 AssertMsg(fRc, ("CloseHandle for hMonitor failed (dwErr=%d)\n", GetLastError())); 1968 1923 g_VBoxUsbGlobal.hMonitor = INVALID_HANDLE_VALUE; 1969 1924 … … 1973 1928 1974 1929 fRc = CloseHandle(g_VBoxUsbGlobal.hNotifyEvent); 1975 AssertMsg(fRc, ("CloseHandle for hNotifyEvent failed dwErr(%d)\n", GetLastError()));1930 AssertMsg(fRc, ("CloseHandle for hNotifyEvent failed (dwErr=%d)\n", GetLastError())); 1976 1931 g_VBoxUsbGlobal.hNotifyEvent = NULL; 1977 1932 -
TabularUnified trunk/src/VBox/HostDrivers/VBoxUSB/win/mon/VBoxUsbFlt.cpp ¶
r80441 r80877 677 677 } 678 678 679 static void vboxUsbFltSignalChangeLocked()680 {681 for (PLIST_ENTRY pEntry = g_VBoxUsbFltGlobals.ContextList.Flink;682 pEntry != &g_VBoxUsbFltGlobals.ContextList;683 pEntry = pEntry->Flink)684 {685 PVBOXUSBFLTCTX pCtx = PVBOXUSBFLTCTX_FROM_LE(pEntry);686 /* the removed context can not be in a list */687 Assert(!pCtx->bRemoved);688 if (pCtx->pChangeEvent)689 {690 KeSetEvent(pCtx->pChangeEvent,691 0, /* increment*/692 FALSE /* wait */);693 }694 }695 }696 697 679 static bool vboxUsbFltDevCheckReplugLocked(PVBOXUSBFLT_DEVICE pDevice, PVBOXUSBFLTCTX pContext) 698 680 { … … 1038 1020 1039 1021 pContext->bRemoved = TRUE; 1040 if (pContext->pChangeEvent)1041 {1042 LOG(("seting & closing change event (0x%p)", pContext->pChangeEvent));1043 KeSetEvent(pContext->pChangeEvent,1044 0, /* increment*/1045 FALSE /* wait */);1046 ObDereferenceObject(pContext->pChangeEvent);1047 pContext->pChangeEvent = NULL;1048 }1049 else1050 LOG(("no change event"));1051 1022 RemoveEntryList(&pContext->ListEntry); 1052 1023 … … 1210 1181 } 1211 1182 1212 NTSTATUS VBoxUsbFltSetNotifyEvent(PVBOXUSBFLTCTX pContext, HANDLE hEvent)1213 {1214 NTSTATUS Status = STATUS_SUCCESS;1215 PKEVENT pEvent = NULL;1216 PKEVENT pOldEvent = NULL;1217 if (hEvent)1218 {1219 Status = ObReferenceObjectByHandle(hEvent,1220 EVENT_MODIFY_STATE,1221 *ExEventObjectType, UserMode,1222 (PVOID*)&pEvent,1223 NULL);1224 Assert(Status == STATUS_SUCCESS);1225 if (!NT_SUCCESS(Status))1226 return Status;1227 }1228 1229 VBOXUSBFLT_LOCK_ACQUIRE();1230 pOldEvent = pContext->pChangeEvent;1231 pContext->pChangeEvent = pEvent;1232 VBOXUSBFLT_LOCK_RELEASE();1233 1234 if (pOldEvent)1235 {1236 ObDereferenceObject(pOldEvent);1237 }1238 1239 return STATUS_SUCCESS;1240 }1241 1242 1183 static USBDEVICESTATE vboxUsbDevGetUserState(PVBOXUSBFLTCTX pContext, PVBOXUSBFLT_DEVICE pDevice) 1243 1184 { … … 1399 1340 } 1400 1341 1401 NTSTATUS VBoxUsbFltPdoAddCompleted(PDEVICE_OBJECT pPdo)1402 {1403 RT_NOREF1(pPdo);1404 VBOXUSBFLT_LOCK_ACQUIRE();1405 vboxUsbFltSignalChangeLocked();1406 VBOXUSBFLT_LOCK_RELEASE();1407 return STATUS_SUCCESS;1408 }1409 1410 1342 BOOLEAN VBoxUsbFltPdoIsFiltered(PDEVICE_OBJECT pPdo) 1411 1343 { … … 1434 1366 enmOldState = pDevice->enmState; 1435 1367 pDevice->enmState = VBOXUSBFLT_DEVSTATE_REMOVED; 1436 if (enmOldState != VBOXUSBFLT_DEVSTATE_REPLUGGING)1437 {1438 vboxUsbFltSignalChangeLocked();1439 }1440 else1441 {1442 /* the device *should* reappear, do signlling on re-appear only1443 * to avoid extra signaling. still there might be a situation1444 * when the device will not re-appear if it gets physically removed1445 * before it re-appears1446 * @todo: set a timer callback to do a notification from it */1447 }1448 1368 } 1449 1369 VBOXUSBFLT_LOCK_RELEASE(); … … 1471 1391 LOG(("The proxy notified proxy start for the captured device 0x%x", pDevice)); 1472 1392 vboxUsbFltDevRetain(pDevice); 1473 vboxUsbFltSignalChangeLocked();1474 1393 } 1475 1394 else … … 1501 1420 LOG(("The proxy notified proxy stop for the captured device 0x%x, current state %d", pDevice, pDevice->enmState)); 1502 1421 pDevice->enmState = VBOXUSBFLT_DEVSTATE_CAPTURING; 1503 vboxUsbFltSignalChangeLocked();1504 1422 } 1505 1423 else -
TabularUnified trunk/src/VBox/HostDrivers/VBoxUSB/win/mon/VBoxUsbFlt.h ¶
r76568 r80877 39 39 { 40 40 LIST_ENTRY ListEntry; 41 PKEVENT pChangeEvent; 42 RTPROCESS Process; 41 RTPROCESS Process; // Purely informational, no function? 43 42 uint32_t cActiveFilters; 44 BOOLEAN bRemoved; 43 BOOLEAN bRemoved; // For debugging only? 45 44 } VBOXUSBFLTCTX, *PVBOXUSBFLTCTX; 46 45 … … 51 50 int VBoxUsbFltAdd(PVBOXUSBFLTCTX pContext, PUSBFILTER pFilter, uintptr_t *pId); 52 51 int VBoxUsbFltRemove(PVBOXUSBFLTCTX pContext, uintptr_t uId); 53 NTSTATUS VBoxUsbFltSetNotifyEvent(PVBOXUSBFLTCTX pContext, HANDLE hEvent);54 52 NTSTATUS VBoxUsbFltFilterCheck(PVBOXUSBFLTCTX pContext); 55 53 … … 61 59 62 60 NTSTATUS VBoxUsbFltPdoAdd(PDEVICE_OBJECT pPdo, BOOLEAN *pbFiltered); 63 NTSTATUS VBoxUsbFltPdoAddCompleted(PDEVICE_OBJECT pPdo);64 61 NTSTATUS VBoxUsbFltPdoRemove(PDEVICE_OBJECT pPdo); 65 62 BOOLEAN VBoxUsbFltPdoIsFiltered(PDEVICE_OBJECT pPdo); -
TabularUnified trunk/src/VBox/HostDrivers/VBoxUSB/win/mon/VBoxUsbMon.cpp ¶
r80436 r80877 633 633 case IRP_MN_QUERY_RESOURCE_REQUIREMENTS: 634 634 case IRP_MN_QUERY_RESOURCES: 635 if (NT_SUCCESS(pIrp->IoStatus.Status) || pIrp->IoStatus.Status == STATUS_NOT_SUPPORTED) 636 { 637 VBoxUsbFltPdoAddCompleted(pRealDevObj); 638 } 639 else 640 { 641 AssertFailed(); 642 } 643 break; 635 /* There used to be code to support SUPUSBFLT_IOCTL_SET_NOTIFY_EVENT but it was not reliable. */ 644 636 645 637 default: … … 1105 1097 } 1106 1098 1107 static int VBoxUsbMonSetNotifyEvent(PVBOXUSBMONCTX pContext, HANDLE hEvent)1108 {1109 int rc = VBoxUsbFltSetNotifyEvent(&pContext->FltCtx, hEvent);1110 return rc;1111 }1112 1113 1099 static int VBoxUsbMonFltAdd(PVBOXUSBMONCTX pContext, PUSBFILTER pFilter, uintptr_t *pId) 1114 1100 { … … 1256 1242 WARN(("VBoxUsbMonGetDevice fail 0x%x", Status)); 1257 1243 } 1258 break;1259 }1260 1261 case SUPUSBFLT_IOCTL_SET_NOTIFY_EVENT:1262 {1263 PUSBSUP_SET_NOTIFY_EVENT pSne = (PUSBSUP_SET_NOTIFY_EVENT)pvBuffer;1264 if (!pvBuffer || cbInBuffer != sizeof (*pSne) || cbOutBuffer != sizeof (*pSne))1265 {1266 WARN(("SUPUSBFLT_IOCTL_SET_NOTIFY_EVENT: Invalid input/output sizes. cbIn=%d expected %d. cbOut=%d expected %d.",1267 cbInBuffer, sizeof (*pSne), cbOutBuffer, sizeof (*pSne)));1268 Status = STATUS_INVALID_PARAMETER;1269 break;1270 }1271 1272 pSne->u.rc = VBoxUsbMonSetNotifyEvent(pContext, pSne->u.hEvent);1273 Info = sizeof (*pSne);1274 ASSERT_WARN(Status == STATUS_SUCCESS, ("unexpected status, 0x%x", Status));1275 1244 break; 1276 1245 }
Note:
See TracChangeset
for help on using the changeset viewer.