Changeset 79311 in vbox for trunk/src/VBox/HostDrivers
- Timestamp:
- Jun 24, 2019 2:42:58 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostDrivers/VBoxUSB/win/mon/VBoxUsbMon.cpp
r76553 r79311 86 86 } VBOXUSBHUB_PNPHOOK_COMPLETION, *PVBOXUSBHUB_PNPHOOK_COMPLETION; 87 87 88 /*89 * Comment out VBOX_USB3PORT definition to disable hooking to multiple drivers (#6509)90 */91 #define VBOX_USB3PORT92 93 #ifdef VBOX_USB3PORT94 88 #define VBOXUSBMON_MAXDRIVERS 5 95 89 typedef struct VBOXUSB_PNPDRIVER … … 99 93 PDRIVER_DISPATCH pfnHookStub; 100 94 } VBOXUSB_PNPDRIVER, *PVBOXUSB_PNPDRIVER; 101 #endif /* !VBOX_USB3PORT */102 95 103 96 typedef struct VBOXUSBMONGLOBALS 104 97 { 105 98 PDEVICE_OBJECT pDevObj; 106 #ifdef VBOX_USB3PORT107 99 VBOXUSB_PNPDRIVER pDrivers[VBOXUSBMON_MAXDRIVERS]; 108 #else /* !VBOX_USB3PORT */109 VBOXUSBHUB_PNPHOOK UsbHubPnPHook;110 #endif /* !VBOX_USB3PORT */111 100 KEVENT OpenSynchEvent; 112 101 IO_REMOVE_LOCK RmLock; … … 556 545 { 557 546 NTSTATUS Status = STATUS_UNSUCCESSFUL; 558 #ifndef VBOX_USB3PORT559 UNICODE_STRING szStandardHubName;560 PDRIVER_OBJECT pDrvObj = NULL;561 szStandardHubName.Length = 0;562 szStandardHubName.MaximumLength = 0;563 szStandardHubName.Buffer = 0;564 RtlInitUnicodeString(&szStandardHubName, L"\\Driver\\usbhub");565 UNICODE_STRING szStandardHubPdoNamePrefix;566 szStandardHubPdoNamePrefix.Length = 0;567 szStandardHubPdoNamePrefix.MaximumLength = 0;568 szStandardHubPdoNamePrefix.Buffer = 0;569 RtlInitUnicodeString(&szStandardHubPdoNamePrefix, L"\\Device\\USBPDO-");570 571 for (int i = 0; i < 16; i++)572 {573 WCHAR szwHubName[32] = {0};574 char szHubName[32] = {0};575 ANSI_STRING AnsiName;576 UNICODE_STRING UnicodeName;577 PDEVICE_OBJECT pHubDevObj;578 PFILE_OBJECT pHubFileObj;579 580 sprintf(szHubName, "\\Device\\USBPDO-%d", i);581 582 RtlInitAnsiString(&AnsiName, szHubName);583 584 UnicodeName.Length = 0;585 UnicodeName.MaximumLength = sizeof (szwHubName);586 UnicodeName.Buffer = szwHubName;587 588 RtlInitAnsiString(&AnsiName, szHubName);589 Status = RtlAnsiStringToUnicodeString(&UnicodeName, &AnsiName, FALSE);590 if (Status == STATUS_SUCCESS)591 {592 Status = IoGetDeviceObjectPointer(&UnicodeName, FILE_READ_DATA, &pHubFileObj, &pHubDevObj);593 if (Status == STATUS_SUCCESS)594 {595 LOG(("IoGetDeviceObjectPointer for \\Device\\USBPDO-%d returned %p %p", i, pHubDevObj, pHubFileObj));596 597 VBOXUSBOBJDRVOBJSEARCHER Data = {0};598 Data.pDrvName = &szStandardHubName;599 Data.pPdoNamePrefix = &szStandardHubPdoNamePrefix;600 Data.fFlags = fFlags;601 602 vboxUsbObjDevStackWalk(pHubDevObj, vboxUsbObjDevObjSearcherWalker, &Data);603 if (Data.pDevObj)604 {605 LOG(("found hub dev obj (0x%p)", Data.pDevObj));606 if (!pfnWalker(pHubFileObj, pHubDevObj, Data.pDevObj, pvWalker))607 {608 LOG(("the walker said to stop"));609 ObDereferenceObject(Data.pDevObj);610 ObDereferenceObject(pHubFileObj);611 break;612 }613 614 LOG(("going forward.."));615 ObDereferenceObject(Data.pDevObj);616 }617 else618 {619 LOG(("no hub driver obj found"));620 ASSERT_WARN(!Data.pDevObj, ("non-null dev obj poiter returned (0x%p)", Data.pDevObj));621 }622 623 /* this will dereference both file and dev obj */624 ObDereferenceObject(pHubFileObj);625 }626 else627 {628 LOG(("IoGetDeviceObjectPointer returned Status (0x%x) for (\\Device\\USBPDO-%d)", Status, i));629 }630 }631 else632 {633 WARN(("RtlAnsiStringToUnicodeString failed, Status (0x%x) for Ansu name (\\Device\\USBPDO-%d)", Status, i));634 }635 }636 #else /* VBOX_USB3PORT */637 547 RT_NOREF1(fFlags); 638 548 PWSTR szwHubList; … … 673 583 ExFreePool(szwHubList); 674 584 } 675 #endif /* VBOX_USB3PORT */676 585 } 677 586 … … 1083 992 NTSTATUS tmpStatus = pIrp->IoStatus.Status; 1084 993 #endif 1085 #ifdef VBOX_USB3PORT1086 994 PVBOXUSBHOOK_ENTRY pHook = pRequest->pHook; 1087 #else /* !VBOX_USB3PORT */1088 PVBOXUSBHOOK_ENTRY pHook = &g_VBoxUsbMonGlobals.UsbHubPnPHook.Hook;1089 #endif /* !VBOX_USB3PORT */1090 995 NTSTATUS Status = VBoxUsbHookRequestComplete(pHook, pDevObj, pIrp, pRequest); 1091 996 VBoxUsbMonMemFree(pRequest); … … 1106 1011 * @param pIrp Request packet. 1107 1012 */ 1108 #ifdef VBOX_USB3PORT1109 1013 static NTSTATUS vboxUsbMonPnPHook(IN PVBOXUSBHOOK_ENTRY pHook, IN PDEVICE_OBJECT pDevObj, IN PIRP pIrp) 1110 #else /* !VBOX_USB3PORT */ 1111 NTSTATUS _stdcall VBoxUsbMonPnPHook(IN PDEVICE_OBJECT pDevObj, IN PIRP pIrp) 1112 #endif /* !VBOX_USB3PORT */ 1113 { 1114 #ifndef VBOX_USB3PORT 1115 PVBOXUSBHOOK_ENTRY pHook = &g_VBoxUsbMonGlobals.UsbHubPnPHook.Hook; 1116 #endif /* !VBOX_USB3PORT */ 1014 { 1117 1015 LOG(("==>PnP: Mn(%s), PDO(0x%p), IRP(0x%p), Status(0x%x)", vboxUsbDbgStrPnPMn(IoGetCurrentIrpStackLocation(pIrp)->MinorFunction), pDevObj, pIrp, pIrp->IoStatus.Status)); 1118 1016 … … 1149 1047 } 1150 1048 1151 #ifdef VBOX_USB3PORT1152 1049 /** 1153 1050 * Device PnP hook stubs. … … 1276 1173 return STATUS_SUCCESS; 1277 1174 } 1278 #endif /* VBOX_USB3PORT */1279 1175 1280 1176 static NTSTATUS vboxUsbMonHookCheckInit() … … 1286 1182 return STATUS_SUCCESS; 1287 1183 } 1288 #ifdef VBOX_USB3PORT1289 1184 return vboxUsbMonInstallAllHooks(); 1290 #else /* !VBOX_USB3PORT */1291 PDRIVER_OBJECT pDrvObj = vboxUsbMonHookFindHubDrvObj();1292 if (pDrvObj)1293 {1294 VBoxUsbHookInit(&g_VBoxUsbMonGlobals.UsbHubPnPHook.Hook, pDrvObj, IRP_MJ_PNP, VBoxUsbMonPnPHook);1295 fIsHookInited = true;1296 LOG(("SUCCESS"));1297 return STATUS_SUCCESS;1298 }1299 WARN(("hub drv obj not found, fail"));1300 return STATUS_UNSUCCESSFUL;1301 #endif /* !VBOX_USB3PORT */1302 1185 } 1303 1186 1304 1187 static NTSTATUS vboxUsbMonHookInstall() 1305 1188 { 1306 #ifdef VBOX_USB3PORT1307 1189 /* Nothing to do here as we have already installed all hooks in vboxUsbMonHookCheckInit(). */ 1308 1190 return STATUS_SUCCESS; 1309 #else /* !VBOX_USB3PORT */ 1191 } 1192 1193 static NTSTATUS vboxUsbMonHookUninstall() 1194 { 1310 1195 #ifdef VBOXUSBMON_DBG_NO_PNPHOOK 1311 1196 return STATUS_SUCCESS; 1312 1197 #else 1313 if (g_VBoxUsbMonGlobals.UsbHubPnPHook.fUninitFailed)1314 {1315 WARN(("trying to hook usbhub pnp after the unhook failed, do nothing & pretend success"));1316 return STATUS_SUCCESS;1317 }1318 return VBoxUsbHookInstall(&g_VBoxUsbMonGlobals.UsbHubPnPHook.Hook);1319 #endif1320 #endif /* !VBOX_USB3PORT */1321 }1322 1323 static NTSTATUS vboxUsbMonHookUninstall()1324 {1325 #ifdef VBOXUSBMON_DBG_NO_PNPHOOK1326 return STATUS_SUCCESS;1327 #else1328 #ifdef VBOX_USB3PORT1329 1198 NTSTATUS Status = STATUS_SUCCESS; 1330 1199 for (int i = 0; i < VBOXUSBMON_MAXDRIVERS; i++) … … 1354 1223 } 1355 1224 } 1356 #else /* !VBOX_USB3PORT */1357 NTSTATUS Status = VBoxUsbHookUninstall(&g_VBoxUsbMonGlobals.UsbHubPnPHook.Hook);1358 if (!NT_SUCCESS(Status))1359 {1360 AssertMsgFailed(("usbhub pnp unhook failed, setting the fUninitFailed flag, the current value of fUninitFailed (%d)", g_VBoxUsbMonGlobals.UsbHubPnPHook.fUninitFailed));1361 g_VBoxUsbMonGlobals.UsbHubPnPHook.fUninitFailed = true;1362 }1363 #endif /* !VBOX_USB3PORT */1364 1225 return Status; 1365 1226 #endif … … 1940 1801 1941 1802 memset (&g_VBoxUsbMonGlobals, 0, sizeof (g_VBoxUsbMonGlobals)); 1942 #ifdef VBOX_USB3PORT 1803 1943 1804 VBOX_PNPHOOKSTUB_INIT(0); 1944 1805 VBOX_PNPHOOKSTUB_INIT(1); … … 1947 1808 VBOX_PNPHOOKSTUB_INIT(4); 1948 1809 AssertCompile(VBOXUSBMON_MAXDRIVERS == 5); 1949 #endif /* VBOX_USB3PORT */ 1810 1950 1811 KeInitializeEvent(&g_VBoxUsbMonGlobals.OpenSynchEvent, SynchronizationEvent, TRUE /* signaled */); 1951 1812 IoInitializeRemoveLock(&g_VBoxUsbMonGlobals.RmLock, VBOXUSBMON_MEMTAG, 1, 100);
Note:
See TracChangeset
for help on using the changeset viewer.