VirtualBox

Changeset 79311 in vbox for trunk/src/VBox/HostDrivers


Ignore:
Timestamp:
Jun 24, 2019 2:42:58 PM (6 years ago)
Author:
vboxsync
Message:

USBMon (bugref:6509) Drop obsolete single-hook code.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostDrivers/VBoxUSB/win/mon/VBoxUsbMon.cpp

    r76553 r79311  
    8686} VBOXUSBHUB_PNPHOOK_COMPLETION, *PVBOXUSBHUB_PNPHOOK_COMPLETION;
    8787
    88 /*
    89  * Comment out VBOX_USB3PORT definition to disable hooking to multiple drivers (#6509)
    90  */
    91 #define VBOX_USB3PORT
    92 
    93 #ifdef VBOX_USB3PORT
    9488#define VBOXUSBMON_MAXDRIVERS 5
    9589typedef struct VBOXUSB_PNPDRIVER
     
    9993    PDRIVER_DISPATCH   pfnHookStub;
    10094} VBOXUSB_PNPDRIVER, *PVBOXUSB_PNPDRIVER;
    101 #endif /* !VBOX_USB3PORT */
    10295
    10396typedef struct VBOXUSBMONGLOBALS
    10497{
    10598    PDEVICE_OBJECT pDevObj;
    106 #ifdef VBOX_USB3PORT
    10799    VBOXUSB_PNPDRIVER pDrivers[VBOXUSBMON_MAXDRIVERS];
    108 #else /* !VBOX_USB3PORT */
    109     VBOXUSBHUB_PNPHOOK UsbHubPnPHook;
    110 #endif /* !VBOX_USB3PORT */
    111100    KEVENT OpenSynchEvent;
    112101    IO_REMOVE_LOCK RmLock;
     
    556545{
    557546    NTSTATUS Status = STATUS_UNSUCCESSFUL;
    558 #ifndef VBOX_USB3PORT
    559     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                 else
    618                 {
    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             else
    627             {
    628                 LOG(("IoGetDeviceObjectPointer returned Status (0x%x) for (\\Device\\USBPDO-%d)", Status, i));
    629             }
    630         }
    631         else
    632         {
    633             WARN(("RtlAnsiStringToUnicodeString failed, Status (0x%x) for Ansu name (\\Device\\USBPDO-%d)", Status, i));
    634         }
    635     }
    636 #else /* VBOX_USB3PORT */
    637547    RT_NOREF1(fFlags);
    638548    PWSTR szwHubList;
     
    673583        ExFreePool(szwHubList);
    674584    }
    675 #endif /* VBOX_USB3PORT */
    676585}
    677586
     
    1083992    NTSTATUS tmpStatus = pIrp->IoStatus.Status;
    1084993#endif
    1085 #ifdef VBOX_USB3PORT
    1086994    PVBOXUSBHOOK_ENTRY pHook = pRequest->pHook;
    1087 #else /* !VBOX_USB3PORT */
    1088     PVBOXUSBHOOK_ENTRY pHook = &g_VBoxUsbMonGlobals.UsbHubPnPHook.Hook;
    1089 #endif /* !VBOX_USB3PORT */
    1090995    NTSTATUS Status = VBoxUsbHookRequestComplete(pHook, pDevObj, pIrp, pRequest);
    1091996    VBoxUsbMonMemFree(pRequest);
     
    11061011 * @param   pIrp         Request packet.
    11071012 */
    1108 #ifdef VBOX_USB3PORT
    11091013static 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{
    11171015    LOG(("==>PnP: Mn(%s), PDO(0x%p), IRP(0x%p), Status(0x%x)", vboxUsbDbgStrPnPMn(IoGetCurrentIrpStackLocation(pIrp)->MinorFunction), pDevObj, pIrp, pIrp->IoStatus.Status));
    11181016
     
    11491047}
    11501048
    1151 #ifdef VBOX_USB3PORT
    11521049/**
    11531050 * Device PnP hook stubs.
     
    12761173    return STATUS_SUCCESS;
    12771174}
    1278 #endif /* VBOX_USB3PORT */
    12791175
    12801176static NTSTATUS vboxUsbMonHookCheckInit()
     
    12861182        return STATUS_SUCCESS;
    12871183    }
    1288 #ifdef VBOX_USB3PORT
    12891184    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 */
    13021185}
    13031186
    13041187static NTSTATUS vboxUsbMonHookInstall()
    13051188{
    1306 #ifdef VBOX_USB3PORT
    13071189    /* Nothing to do here as we have already installed all hooks in vboxUsbMonHookCheckInit(). */
    13081190    return STATUS_SUCCESS;
    1309 #else /* !VBOX_USB3PORT */
     1191}
     1192
     1193static NTSTATUS vboxUsbMonHookUninstall()
     1194{
    13101195#ifdef VBOXUSBMON_DBG_NO_PNPHOOK
    13111196    return STATUS_SUCCESS;
    13121197#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 #endif
    1320 #endif /* !VBOX_USB3PORT */
    1321 }
    1322 
    1323 static NTSTATUS vboxUsbMonHookUninstall()
    1324 {
    1325 #ifdef VBOXUSBMON_DBG_NO_PNPHOOK
    1326     return STATUS_SUCCESS;
    1327 #else
    1328 #ifdef VBOX_USB3PORT
    13291198    NTSTATUS Status = STATUS_SUCCESS;
    13301199    for (int i = 0; i < VBOXUSBMON_MAXDRIVERS; i++)
     
    13541223        }
    13551224    }
    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 */
    13641225    return Status;
    13651226#endif
     
    19401801
    19411802    memset (&g_VBoxUsbMonGlobals, 0, sizeof (g_VBoxUsbMonGlobals));
    1942 #ifdef VBOX_USB3PORT
     1803
    19431804    VBOX_PNPHOOKSTUB_INIT(0);
    19441805    VBOX_PNPHOOKSTUB_INIT(1);
     
    19471808    VBOX_PNPHOOKSTUB_INIT(4);
    19481809    AssertCompile(VBOXUSBMON_MAXDRIVERS == 5);
    1949 #endif /* VBOX_USB3PORT */
     1810
    19501811    KeInitializeEvent(&g_VBoxUsbMonGlobals.OpenSynchEvent, SynchronizationEvent, TRUE /* signaled */);
    19511812    IoInitializeRemoveLock(&g_VBoxUsbMonGlobals.RmLock, VBOXUSBMON_MEMTAG, 1, 100);
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette