VirtualBox

Ignore:
Timestamp:
May 31, 2012 4:48:33 PM (13 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
78291
Message:

Main/HostUSBDevice(all platforms)+USBProxyService: redo USB locking, fixes major regression, added lots of assertions to catch locking flaws early, whitespace cleanup
Main/Machine: small USB locking fix to be consistent with the remaining code
Main/Host+glue/AutoLock: replace USB list lock by host lock, small numbering cleanup
Main/Console: redo USB locking, do less in USB callbacks/EMT (addresses long standing todo items), eliminate unsafe iterator parameters

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/src-server/os2/USBProxyServiceOs2.cpp

    r31892 r41528  
    55
    66/*
    7  * Copyright (C) 2006-2010 Oracle Corporation
     7 * Copyright (C) 2005-2012 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    3838 * Initialize data members.
    3939 */
    40 USBProxyServiceOs2::USBProxyServiceOs2 (Host *aHost)
    41     : USBProxyService (aHost), mhev (NULLHANDLE), mhmod (NULLHANDLE),
    42     mpfnUsbRegisterChangeNotification (NULL), mpfnUsbDeregisterNotification (NULL),
    43     mpfnUsbQueryNumberDevices (NULL), mpfnUsbQueryDeviceReport (NULL)
     40USBProxyServiceOs2::USBProxyServiceOs2(Host *aHost)
     41    : USBProxyService(aHost), mhev(NULLHANDLE), mhmod(NULLHANDLE),
     42    mpfnUsbRegisterChangeNotification(NULL), mpfnUsbDeregisterNotification(NULL),
     43    mpfnUsbQueryNumberDevices(NULL), mpfnUsbQueryDeviceReport(NULL)
    4444{
    4545    LogFlowThisFunc(("aHost=%p\n", aHost));
     
    4848     * Try initialize the usbcalls stuff.
    4949     */
    50     int rc = DosCreateEventSem (NULL, &mhev, 0, FALSE);
    51     rc = RTErrConvertFromOS2 (rc);
     50    int rc = DosCreateEventSem(NULL, &mhev, 0, FALSE);
     51    rc = RTErrConvertFromOS2(rc);
    5252    if (RT_SUCCESS(rc))
    5353    {
    54         rc = DosLoadModule (NULL, 0, (PCSZ)"usbcalls", &mhmod);
    55         rc = RTErrConvertFromOS2 (rc);
     54        rc = DosLoadModule(NULL, 0, (PCSZ)"usbcalls", &mhmod);
     55        rc = RTErrConvertFromOS2(rc);
    5656        if (RT_SUCCESS(rc))
    5757        {
    58             if (    (rc = DosQueryProcAddr (mhmod, 0, (PCSZ)"UsbQueryNumberDevices",            (PPFN)&mpfnUsbQueryNumberDevices))          == NO_ERROR
    59                 &&  (rc = DosQueryProcAddr (mhmod, 0, (PCSZ)"UsbQueryDeviceReport",             (PPFN)&mpfnUsbQueryDeviceReport))           == NO_ERROR
    60                 &&  (rc = DosQueryProcAddr (mhmod, 0, (PCSZ)"UsbRegisterChangeNotification",    (PPFN)&mpfnUsbRegisterChangeNotification))  == NO_ERROR
    61                 &&  (rc = DosQueryProcAddr (mhmod, 0, (PCSZ)"UsbDeregisterNotification",        (PPFN)&mpfnUsbDeregisterNotification))      == NO_ERROR
     58            if (    (rc = DosQueryProcAddr(mhmod, 0, (PCSZ)"UsbQueryNumberDevices",         (PPFN)&mpfnUsbQueryNumberDevices))          == NO_ERROR
     59                &&  (rc = DosQueryProcAddr(mhmod, 0, (PCSZ)"UsbQueryDeviceReport",          (PPFN)&mpfnUsbQueryDeviceReport))           == NO_ERROR
     60                &&  (rc = DosQueryProcAddr(mhmod, 0, (PCSZ)"UsbRegisterChangeNotification", (PPFN)&mpfnUsbRegisterChangeNotification))  == NO_ERROR
     61                &&  (rc = DosQueryProcAddr(mhmod, 0, (PCSZ)"UsbDeregisterNotification",     (PPFN)&mpfnUsbDeregisterNotification))      == NO_ERROR
    6262               )
    6363            {
    64                 rc = mpfnUsbRegisterChangeNotification (&mNotifyId, mhev, mhev);
     64                rc = mpfnUsbRegisterChangeNotification(&mNotifyId, mhev, mhev);
    6565                if (!rc)
    6666                {
     
    7777                }
    7878
    79                 LogRel (("USBProxyServiceOs2: failed to register change notification, rc=%d\n", rc));
     79                LogRel(("USBProxyServiceOs2: failed to register change notification, rc=%d\n", rc));
    8080            }
    8181            else
    82                 LogRel (("USBProxyServiceOs2: failed to load usbcalls\n"));
    83 
    84             DosFreeModule (mhmod);
     82                LogRel(("USBProxyServiceOs2: failed to load usbcalls\n"));
     83
     84            DosFreeModule(mhmod);
    8585        }
    8686        else
    87             LogRel (("USBProxyServiceOs2: failed to load usbcalls, rc=%d\n", rc));
     87            LogRel(("USBProxyServiceOs2: failed to load usbcalls, rc=%d\n", rc));
    8888        mhmod = NULLHANDLE;
    8989    }
     
    115115    {
    116116        if (mpfnUsbDeregisterNotification)
    117             mpfnUsbDeregisterNotification (mNotifyId);
     117            mpfnUsbDeregisterNotification(mNotifyId);
    118118
    119119        mpfnUsbRegisterChangeNotification = NULL;
     
    122122        mpfnUsbQueryDeviceReport = NULL;
    123123
    124         DosFreeModule (mhmod);
     124        DosFreeModule(mhmod);
    125125        mhmod = NULLHANDLE;
    126126    }
     
    128128
    129129
    130 int USBProxyServiceOs2::captureDevice (HostUSBDevice *aDevice)
    131 {
    132     Log (("USBProxyServiceOs2::captureDevice: %p\n", aDevice));
     130int USBProxyServiceOs2::captureDevice(HostUSBDevice *aDevice)
     131{
    133132    AssertReturn(aDevice, VERR_GENERAL_FAILURE);
    134     AssertReturn(aDevice->isWriteLockOnCurrentThread(), VERR_GENERAL_FAILURE);
     133    AssertReturn(!aDevice->isWriteLockOnCurrentThread(), VERR_GENERAL_FAILURE);
     134
     135    AutoReadLock devLock(aDevice COMMA_LOCKVAL_SRC_POS);
     136    LogFlowThisFunc(("aDevice=%s\n", aDevice->getName().c_str()));
    135137
    136138    /*
     
    138140     */
    139141    Assert(aDevice->isStatePending());
     142    devLock.release();
    140143    interruptWait();
    141144
     
    144147
    145148
    146 int USBProxyServiceOs2::releaseDevice (HostUSBDevice *aDevice)
    147 {
    148     Log (("USBProxyServiceOs2::releaseDevice: %p\n", aDevice));
     149int USBProxyServiceOs2::releaseDevice(HostUSBDevice *aDevice)
     150{
    149151    AssertReturn(aDevice, VERR_GENERAL_FAILURE);
    150     AssertReturn(aDevice->isWriteLockOnCurrentThread(), VERR_GENERAL_FAILURE);
     152    AssertReturn(!aDevice->isWriteLockOnCurrentThread(), VERR_GENERAL_FAILURE);
     153
     154    AutoReadLock devLock(aDevice COMMA_LOCKVAL_SRC_POS);
     155    LogFlowThisFunc(("aDevice=%s\n", aDevice->getName().c_str()));
    151156
    152157    /*
     
    154159     */
    155160    Assert(aDevice->isStatePending());
     161    devLock.release();
    156162    interruptWait();
    157163
     
    162168bool USBProxyServiceOs2::updateDeviceState(HostUSBDevice *aDevice, PUSBDEVICE aUSBDevice, bool *aRunFilters, SessionMachine **aIgnoreMachine)
    163169{
     170    AssertReturn(aDevice, false);
     171    AssertReturn(!aDevice->isWriteLockOnCurrentThread(), false);
    164172    return updateDeviceStateFake(aDevice, aUSBDevice, aRunFilters, aIgnoreMachine);
    165173}
     
    174182
    175183
    176 int USBProxyServiceOs2::interruptWait (void)
    177 {
    178     int rc = DosPostEventSem (mhev);
     184int USBProxyServiceOs2::interruptWait(void)
     185{
     186    int rc = DosPostEventSem(mhev);
    179187    return rc == NO_ERROR || rc == ERROR_ALREADY_POSTED
    180188         ? VINF_SUCCESS
    181          : RTErrConvertFromOS2 (rc);
     189         : RTErrConvertFromOS2(rc);
    182190}
    183191
    184192#include <stdio.h>
    185193
    186 PUSBDEVICE USBProxyServiceOs2::getDevices (void)
     194PUSBDEVICE USBProxyServiceOs2::getDevices(void)
    187195{
    188196    /*
     
    190198     */
    191199    ULONG cDevices = 0;
    192     int rc = mpfnUsbQueryNumberDevices ((PULONG)&cDevices); /* Thanks to com/xpcom, PULONG and ULONG * aren't the same. */
     200    int rc = mpfnUsbQueryNumberDevices((PULONG)&cDevices); /* Thanks to com/xpcom, PULONG and ULONG * aren't the same. */
    193201    if (rc)
    194202        return NULL;
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