VirtualBox

Ignore:
Timestamp:
Sep 18, 2019 10:08:33 AM (6 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
133450
Message:

USB/win: Removed unused VBOX_USB_USE_DEVICE_NOTIFICATION code from userland and support driver (SUPUSBFLT_IOCTL_SET_NOTIFY_EVENT). See bugref:9518

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  
    5151#include <usbdi.h>
    5252#include <hidsdi.h>
     53#include <Dbt.h>
    5354
    5455/* Defined in Windows 8 DDK (through usbdi.h) but we use Windows 7 DDK to build. */
    5556#define UsbSuperSpeed   3
    56 
    57 #define VBOX_USB_USE_DEVICE_NOTIFICATION
    58 
    59 #ifdef VBOX_USB_USE_DEVICE_NOTIFICATION
    60 # include <Dbt.h>
    61 #endif
    6257
    6358#ifdef VBOX_WITH_NEW_USB_ENUM
     
    8883    HANDLE hNotifyEvent;
    8984    HANDLE hInterruptEvent;
    90 #ifdef VBOX_USB_USE_DEVICE_NOTIFICATION
    9185    HANDLE hThread;
    9286    HWND   hWnd;
    9387    HANDLE hTimerQueue;
    9488    HANDLE hTimer;
    95 #endif
    9689} VBOXUSBGLOBALSTATE, *PVBOXUSBGLOBALSTATE;
    9790
     
    525518    {
    526519        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));
    528521#ifdef VBOX_WITH_ANNOYING_USB_ASSERTIONS
    529522        AssertFailed();
     
    562555        {
    563556            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));
    565558#ifdef VBOX_WITH_ANNOYING_USB_ASSERTIONS
    566559            AssertFailed();
     
    810803    if (!lpszName)
    811804    {
    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));
    813806        lpszName = &nameEmptyBuf;
    814807        fFreeNameBuf = false;
     
    10431036    if (cr != CR_SUCCESS)
    10441037    {
    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()));
    10461039        return NULL;
    10471040    }
     
    10561049    if (cr != CR_SUCCESS)
    10571050    {
    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()));
    10591052        RTMemFree(InstanceID);
    10601053        return NULL;
     
    10901083    if (HubDevice == INVALID_HANDLE_VALUE)
    10911084    {
    1092         LogRelFunc(("Failed to open hub `%s', dwErr(%d)\n", lpcszHubFile, GetLastError()));
     1085        LogRelFunc(("Failed to open hub `%s' (dwErr=%d)\n", lpcszHubFile, GetLastError()));
    10931086        return VERR_FILE_NOT_FOUND;
    10941087    }
     
    13891382    *pcDevs = 0;
    13901383
     1384    LogRelFunc(("Starting USB device enumeration\n"));
    13911385    int rc = usbLibDevGetDevices(ppDevs, pcDevs);
    13921386    AssertRC(rc);
     
    14041398        }
    14051399
     1400        LogRelFunc(("Found %u USB devices, %u captured\n", *pcDevs, cDevInfos));
    14061401        return VINF_SUCCESS;
    14071402    }
     
    15481543}
    15491544
    1550 
    1551 #ifdef VBOX_USB_USE_DEVICE_NOTIFICATION
    15521545
    15531546static VOID CALLBACK usbLibTimerCallback(__in PVOID lpParameter, __in BOOLEAN TimerOrWaitFired)
     
    16811674}
    16821675
    1683 #endif /* VBOX_USB_USE_DEVICE_NOTIFICATION */
    16841676
    16851677/**
     
    17021694    g_VBoxUsbGlobal.hNotifyEvent = CreateEvent(NULL,  /* LPSECURITY_ATTRIBUTES lpEventAttributes */
    17031695                                               FALSE, /* BOOL bManualReset */
    1704 #ifndef VBOX_USB_USE_DEVICE_NOTIFICATION
    1705                                                TRUE,  /* BOOL bInitialState */
    1706 #else
    17071696                                               FALSE, /* set to false since it will be initially used for notification thread startup sync */
    1708 #endif
    17091697                                               NULL   /* LPCTSTR lpName */);
    17101698    if (g_VBoxUsbGlobal.hNotifyEvent)
     
    17421730                    {
    17431731                        DWORD dwErr = GetLastError();
    1744                         LogRelFunc(("CreateFile failed dwErr(%d)\n", dwErr));
     1732                        LogRelFunc(("CreateFile failed (dwErr=%d) for `%s'\n", dwErr, USBMON_DEVICE_NAME));
    17451733                        rc = VERR_FILE_NOT_FOUND;
    17461734                    }
     
    17721760                        )
    17731761                    {
    1774 #ifndef VBOX_USB_USE_DEVICE_NOTIFICATION
    1775                         /*
    1776                          * Tell the monitor driver which event object to use
    1777                          * 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                         else
    1799                         {
    1800                             DWORD dwErr = GetLastError();
    1801                             AssertMsgFailed(("SetEvent Ioctl failed, dwErr (%d)\n", dwErr));
    1802                             rc = VERR_VERSION_MISMATCH;
    1803                         }
    1804 #else
    18051762                        /*
    18061763                         * We can not use USB Mon for reliable device add/remove tracking
     
    18451802                                BOOL fRc = CloseHandle(g_VBoxUsbGlobal.hThread); NOREF(fRc);
    18461803                                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));
    18481805                                g_VBoxUsbGlobal.hThread = INVALID_HANDLE_VALUE;
    18491806                            }
     
    18611818                        {
    18621819                            DWORD dwErr = GetLastError(); NOREF(dwErr);
    1863                             AssertMsgFailed(("CreateTimerQueue failed dwErr(%d)\n", dwErr));
     1820                            AssertMsgFailed(("CreateTimerQueue failed (dwErr=%d)\n", dwErr));
    18641821                        }
    1865 #endif
    18661822                    }
    18671823                    else
     
    18781834                {
    18791835                    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();
    18811838                    rc = VERR_VERSION_MISMATCH;
    18821839                }
     
    19001857        {
    19011858            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));
    19031860            rc = VERR_GENERAL_FAILURE;
    19041861        }
     
    19101867    {
    19111868        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));
    19131870        rc = VERR_GENERAL_FAILURE;
    19141871    }
     
    19371894
    19381895    BOOL fRc;
    1939 #ifdef VBOX_USB_USE_DEVICE_NOTIFICATION
    19401896    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()));
    19421898
    19431899    if (g_VBoxUsbGlobal.hThread != NULL)
     
    19461902        Assert(dwResult == WAIT_OBJECT_0); NOREF(dwResult);
    19471903        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()));
    19491905    }
    19501906
     
    19531909        fRc = DeleteTimerQueueTimer(g_VBoxUsbGlobal.hTimerQueue, g_VBoxUsbGlobal.hTimer,
    19541910                                    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()));
    19561912    }
    19571913
     
    19601916        fRc = DeleteTimerQueueEx(g_VBoxUsbGlobal.hTimerQueue,
    19611917                                 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    }
    19651920
    19661921    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()));
    19681923    g_VBoxUsbGlobal.hMonitor = INVALID_HANDLE_VALUE;
    19691924
     
    19731928
    19741929    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()));
    19761931    g_VBoxUsbGlobal.hNotifyEvent = NULL;
    19771932
  • TabularUnified trunk/src/VBox/HostDrivers/VBoxUSB/win/mon/VBoxUsbFlt.cpp

    r80441 r80877  
    677677}
    678678
    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 
    697679static bool vboxUsbFltDevCheckReplugLocked(PVBOXUSBFLT_DEVICE pDevice, PVBOXUSBFLTCTX pContext)
    698680{
     
    10381020
    10391021    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     else
    1050         LOG(("no change event"));
    10511022    RemoveEntryList(&pContext->ListEntry);
    10521023
     
    12101181}
    12111182
    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 
    12421183static USBDEVICESTATE vboxUsbDevGetUserState(PVBOXUSBFLTCTX pContext, PVBOXUSBFLT_DEVICE pDevice)
    12431184{
     
    13991340}
    14001341
    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 
    14101342BOOLEAN VBoxUsbFltPdoIsFiltered(PDEVICE_OBJECT pPdo)
    14111343{
     
    14341366        enmOldState = pDevice->enmState;
    14351367        pDevice->enmState = VBOXUSBFLT_DEVSTATE_REMOVED;
    1436         if (enmOldState != VBOXUSBFLT_DEVSTATE_REPLUGGING)
    1437         {
    1438             vboxUsbFltSignalChangeLocked();
    1439         }
    1440         else
    1441         {
    1442             /* the device *should* reappear, do signlling on re-appear only
    1443              * to avoid extra signaling. still there might be a situation
    1444              * when the device will not re-appear if it gets physically removed
    1445              * before it re-appears
    1446              * @todo: set a timer callback to do a notification from it */
    1447         }
    14481368    }
    14491369    VBOXUSBFLT_LOCK_RELEASE();
     
    14711391        LOG(("The proxy notified proxy start for the captured device 0x%x", pDevice));
    14721392        vboxUsbFltDevRetain(pDevice);
    1473         vboxUsbFltSignalChangeLocked();
    14741393    }
    14751394    else
     
    15011420        LOG(("The proxy notified proxy stop for the captured device 0x%x, current state %d", pDevice, pDevice->enmState));
    15021421        pDevice->enmState = VBOXUSBFLT_DEVSTATE_CAPTURING;
    1503         vboxUsbFltSignalChangeLocked();
    15041422    }
    15051423    else
  • TabularUnified trunk/src/VBox/HostDrivers/VBoxUSB/win/mon/VBoxUsbFlt.h

    r76568 r80877  
    3939{
    4040    LIST_ENTRY ListEntry;
    41     PKEVENT pChangeEvent;
    42     RTPROCESS Process;
     41    RTPROCESS Process;          // Purely informational, no function?
    4342    uint32_t cActiveFilters;
    44     BOOLEAN bRemoved;
     43    BOOLEAN bRemoved;           // For debugging only?
    4544} VBOXUSBFLTCTX, *PVBOXUSBFLTCTX;
    4645
     
    5150int VBoxUsbFltAdd(PVBOXUSBFLTCTX pContext, PUSBFILTER pFilter, uintptr_t *pId);
    5251int VBoxUsbFltRemove(PVBOXUSBFLTCTX pContext, uintptr_t uId);
    53 NTSTATUS VBoxUsbFltSetNotifyEvent(PVBOXUSBFLTCTX pContext, HANDLE hEvent);
    5452NTSTATUS VBoxUsbFltFilterCheck(PVBOXUSBFLTCTX pContext);
    5553
     
    6159
    6260NTSTATUS VBoxUsbFltPdoAdd(PDEVICE_OBJECT pPdo, BOOLEAN *pbFiltered);
    63 NTSTATUS VBoxUsbFltPdoAddCompleted(PDEVICE_OBJECT pPdo);
    6461NTSTATUS VBoxUsbFltPdoRemove(PDEVICE_OBJECT pPdo);
    6562BOOLEAN VBoxUsbFltPdoIsFiltered(PDEVICE_OBJECT pPdo);
  • TabularUnified trunk/src/VBox/HostDrivers/VBoxUSB/win/mon/VBoxUsbMon.cpp

    r80436 r80877  
    633633        case IRP_MN_QUERY_RESOURCE_REQUIREMENTS:
    634634        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. */
    644636
    645637        default:
     
    11051097}
    11061098
    1107 static int VBoxUsbMonSetNotifyEvent(PVBOXUSBMONCTX pContext, HANDLE hEvent)
    1108 {
    1109     int rc = VBoxUsbFltSetNotifyEvent(&pContext->FltCtx, hEvent);
    1110     return rc;
    1111 }
    1112 
    11131099static int VBoxUsbMonFltAdd(PVBOXUSBMONCTX pContext, PUSBFILTER pFilter, uintptr_t *pId)
    11141100{
     
    12561242                WARN(("VBoxUsbMonGetDevice fail 0x%x", Status));
    12571243            }
    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));
    12751244            break;
    12761245        }
Note: See TracChangeset for help on using the changeset viewer.

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