VirtualBox

Changeset 15917 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Jan 13, 2009 2:45:18 PM (16 years ago)
Author:
vboxsync
Message:

NetFlt/win: concurency issue fix

Location:
trunk/src/VBox/HostDrivers/VBoxNetFlt
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostDrivers/VBoxNetFlt/VBoxNetFlt.c

    r15893 r15917  
    611611 * Destroy a device that has been disconnected from the switch.
    612612 *
     613 * @return true iff the instance is destroyed, false otherwise
    613614 * @param   pThis               The instance to be destroyed. This is
    614615 *                              no longer valid when this function returns.
    615616 */
    616 static void vboxNetFltDestroyInstance(PVBOXNETFLTINS pThis)
     617static bool vboxNetFltCheckDestroyInstance(PVBOXNETFLTINS pThis)
    617618{
    618619    PVBOXNETFLTGLOBALS pGlobals = pThis->pGlobals;
    619620    int rc;
    620     LogFlow(("vboxNetFltDestroyInstance: pThis=%p (%s)\n", pThis, pThis->szName));
     621    uint32_t cRefs = ASMAtomicUoReadU32((uint32_t volatile *)&pThis->cRefs);
     622    LogFlow(("vboxNetFltCheckDestroyInstance: pThis=%p (%s)\n", pThis, pThis->szName));
    621623
    622624    /*
     
    640642     */
    641643    rc = RTSemFastMutexRequest(pGlobals->hFastMtx); AssertRC(rc);
    642     vboxNetFltSetState(pThis, kVBoxNetFltInsState_Disconnecting);
     644    if(cRefs != 0)
     645    {
     646        Assert(cRefs < UINT32_MAX / 2);
     647        RTSemFastMutexRelease(pGlobals->hFastMtx);
     648        return false;
     649    }
     650    vboxNetFltSetState(pThis, kVBoxNetFltInsState_Destroying);
    643651    RTSemFastMutexRelease(pGlobals->hFastMtx);
    644652
     
    658666    pThis->hSpinlock = NIL_RTSPINLOCK;
    659667    RTMemFree(pThis);
     668    return true;
    660669}
    661670
     
    707716    cRefs = ASMAtomicDecU32(&pThis->cRefs);
    708717    if (!cRefs)
    709         vboxNetFltDestroyInstance(pThis);
     718        vboxNetFltCheckDestroyInstance(pThis);
    710719    else
    711720        Assert(cRefs < UINT32_MAX / 2);
     
    961970DECLHIDDEN(int) vboxNetFltSearchCreateInstance(PVBOXNETFLTGLOBALS pGlobals, const char *pszName, PVBOXNETFLTINS *ppInstance, void * pContext)
    962971{
     972    PINTNETTRUNKIFPORT pIfPort;
    963973    int rc;
    964974
     
    967977
    968978    *ppInstance = vboxNetFltFindInstanceLocked(pGlobals, pszName);
    969     if(!(*ppInstance))
    970     {
    971         PINTNETTRUNKIFPORT pIfPort;
    972 
    973         RTSemFastMutexRelease(pGlobals->hFastMtx);
    974 
    975         rc = vboxNetFltNewInstance(pGlobals, pszName, NULL, &pIfPort, pContext);
    976         if(RT_SUCCESS(rc))
    977             *ppInstance =  IFPORT_2_VBOXNETFLTINS(pIfPort);
    978         else
    979             *ppInstance = NULL;
    980     }
     979    if(*ppInstance)
     980    {
     981        VBOXNETFTLINSSTATE enmState = vboxNetFltGetState(*ppInstance);
     982        if(enmState != kVBoxNetFltInsState_Destroying && enmState != kVBoxNetFltInsState_Destroyed)
     983        {
     984            vboxNetFltRetain(*ppInstance, false);
     985            RTSemFastMutexRelease(pGlobals->hFastMtx);
     986            return VINF_ALREADY_INITIALIZED;
     987        }
     988
     989        /*wait for the instance to be removed from the list */
     990
     991        *ppInstance = NULL;
     992
     993        do
     994        {
     995            RTSemFastMutexRelease(pGlobals->hFastMtx);
     996
     997            RTSemEventWait(pGlobals->hTimerEvent, 2);
     998
     999            rc = RTSemFastMutexRequest(pGlobals->hFastMtx);
     1000            AssertRCReturn(rc, rc);
     1001        } while(vboxNetFltFindInstanceLocked(pGlobals, pszName));
     1002    }
     1003
     1004    RTSemFastMutexRelease(pGlobals->hFastMtx);
     1005
     1006    rc = vboxNetFltNewInstance(pGlobals, pszName, NULL, &pIfPort, pContext);
     1007    if(RT_SUCCESS(rc))
     1008        *ppInstance =  IFPORT_2_VBOXNETFLTINS(pIfPort);
    9811009    else
    982     {
    983         RTSemFastMutexRelease(pGlobals->hFastMtx);
    984         rc = VINF_ALREADY_INITIALIZED;
    985     }
    986 
    987 
     1010        *ppInstance = NULL;
    9881011
    9891012    return rc;
     
    11861209    RTSemFastMutexDestroy(pGlobals->hFastMtx);
    11871210    pGlobals->hFastMtx = NIL_RTSEMFASTMUTEX;
     1211
     1212#ifdef VBOXNETFLT_STATIC_CONFIG
     1213    RTSemEventDestroy(pGlobals->hTimerEvent);
     1214    pGlobals->hTimerEvent = NIL_RTSEMEVENT;
     1215#endif
     1216
    11881217}
    11891218
     
    12221251    if (RT_SUCCESS(rc))
    12231252    {
    1224         pGlobals->pInstanceHead = NULL;
    1225 
    1226         pGlobals->TrunkFactory.pfnRelease = vboxNetFltFactoryRelease;
    1227         pGlobals->TrunkFactory.pfnCreateAndConnect = vboxNetFltFactoryCreateAndConnect;
    1228 
    1229         strcpy(pGlobals->SupDrvFactory.szName, "VBoxNetFlt");
    1230         pGlobals->SupDrvFactory.pfnQueryFactoryInterface = vboxNetFltQueryFactoryInterface;
     1253#ifdef VBOXNETFLT_STATIC_CONFIG
     1254        rc = RTSemEventCreate(&pGlobals->hTimerEvent);
     1255        if (RT_SUCCESS(rc))
     1256        {
     1257#endif
     1258            pGlobals->pInstanceHead = NULL;
     1259
     1260            pGlobals->TrunkFactory.pfnRelease = vboxNetFltFactoryRelease;
     1261            pGlobals->TrunkFactory.pfnCreateAndConnect = vboxNetFltFactoryCreateAndConnect;
     1262
     1263            strcpy(pGlobals->SupDrvFactory.szName, "VBoxNetFlt");
     1264            pGlobals->SupDrvFactory.pfnQueryFactoryInterface = vboxNetFltQueryFactoryInterface;
     1265
     1266            return rc;
     1267#ifdef VBOXNETFLT_STATIC_CONFIG
     1268        }
     1269        RTSemFastMutexDestroy(pGlobals->hFastMtx);
     1270#endif
    12311271    }
    12321272
  • trunk/src/VBox/HostDrivers/VBoxNetFlt/VBoxNetFltInternal.h

    r15893 r15917  
    6868     * Partly for reasons of deadlock avoidance again. */
    6969    kVBoxNetFltInsState_Disconnecting,
     70    /** Destroying the instance
     71     * Partly for reasons of deadlock avoidance again. */
     72    kVBoxNetFltInsState_Destroying,
    7073    /** The instance has been disconnected from both the host and the internal network. */
    7174    kVBoxNetFltInsState_Destroyed,
     
    248251    /** The number of current factory references. */
    249252    int32_t volatile cFactoryRefs;
    250 
     253#ifdef VBOXNETFLT_STATIC_CONFIG
     254    /* wait timer event */
     255    RTSEMEVENT hTimerEvent;
     256#endif
    251257    /** The SUPDRV IDC handle (opaque struct). */
    252258    SUPDRVIDCHANDLE SupDrvIDC;
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