VirtualBox

Ignore:
Timestamp:
Dec 8, 2008 11:04:31 AM (16 years ago)
Author:
vboxsync
Message:

Solaris/VBoxNetFlt: Thread protection while closing.

File:
1 edited

Legend:

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

    r14280 r15101  
    369369vboxnetflt_stream_t *g_VBoxNetFltSolarisStreams;
    370370
     371/** Global mutex protecting open/close. */
     372static RTSEMFASTMUTEX g_VBoxNetFltSolarisMtx = NIL_RTSEMFASTMUTEX;
     373
    371374/**
    372375 * g_VBoxNetFltInstance is the current PVBOXNETFLTINS to be associated with the stream being created
     
    410413        g_VBoxNetFltSolarisInstance = NULL;
    411414
    412         /*
    413          * Initialize the globals and connect to the support driver.
    414          *
    415          * This will call back vboxNetFltOsOpenSupDrv (and maybe vboxNetFltOsCloseSupDrv)
    416          * for establishing the connect to the support driver.
    417          */
    418         memset(&g_VBoxNetFltSolarisGlobals, 0, sizeof(g_VBoxNetFltSolarisGlobals));
    419         rc = vboxNetFltInitGlobals(&g_VBoxNetFltSolarisGlobals);
     415        int rc = RTSemFastMutexCreate(&g_VBoxNetFltSolarisMtx);
    420416        if (RT_SUCCESS(rc))
    421417        {
    422             rc = mod_install(&g_VBoxNetFltSolarisModLinkage);
    423             if (!rc)
    424                 return rc;
    425 
    426             LogRel((DEVICE_NAME ":mod_install failed. rc=%d\n", rc));
    427             vboxNetFltTryDeleteGlobals(&g_VBoxNetFltSolarisGlobals);
    428         }
    429         else
    430             LogRel((DEVICE_NAME ":failed to initialize globals.\n"));
     418            /*
     419             * Initialize the globals and connect to the support driver.
     420             *
     421             * This will call back vboxNetFltOsOpenSupDrv (and maybe vboxNetFltOsCloseSupDrv)
     422             * for establishing the connect to the support driver.
     423             */
     424            memset(&g_VBoxNetFltSolarisGlobals, 0, sizeof(g_VBoxNetFltSolarisGlobals));
     425            rc = vboxNetFltInitGlobals(&g_VBoxNetFltSolarisGlobals);
     426            if (RT_SUCCESS(rc))
     427            {
     428                rc = mod_install(&g_VBoxNetFltSolarisModLinkage);
     429                if (!rc)
     430                    return rc;
     431
     432                LogRel((DEVICE_NAME ":mod_install failed. rc=%d\n", rc));
     433                vboxNetFltTryDeleteGlobals(&g_VBoxNetFltSolarisGlobals);
     434            }
     435            else
     436                LogRel((DEVICE_NAME ":failed to initialize globals.\n"));
     437
     438            RTSemFastMutexDestroy(g_VBoxNetFltSolarisMtx);
     439            g_VBoxNetFltSolarisMtx = NIL_RTSEMFASTMUTEX;
     440        }
    431441
    432442        RTR0Term();
     
    453463        LogRel((DEVICE_NAME ":_fini - busy!\n"));
    454464        return EBUSY;
     465    }
     466
     467    if (g_VBoxNetFltSolarisMtx != NIL_RTSEMFASTMUTEX)
     468    {
     469        RTSemFastMutexDestroy(g_VBoxNetFltSolarisMtx);
     470        g_VBoxNetFltSolarisMtx = NIL_RTSEMFASTMUTEX;
    455471    }
    456472
     
    595611            fOpenMode, fStreamMode));
    596612
     613    int rc = RTSemFastMutexRequest(g_VBoxNetFltSolarisMtx);
     614    AssertRCReturn(rc, rc);
     615
    597616    /*
    598617     * Already open?
     
    601620    {
    602621        LogRel((DEVICE_NAME ":VBoxNetFltSolarisModOpen invalid open.\n"));
     622        RTSemFastMutexRelease(g_VBoxNetFltSolarisMtx);
    603623        return ENOENT;
    604624    }
     
    611631    {
    612632        LogRel((DEVICE_NAME ":VBoxNetFltSolarisModOpen failed to get VirtualBox instance.\n"));
     633        RTSemFastMutexRelease(g_VBoxNetFltSolarisMtx);
    613634        return ENOENT;
    614635    }
     
    620641    {
    621642        LogRel((DEVICE_NAME ":VBoxNetFltSolarisModOpen failed due to undefined VirtualBox open mode.\n"));
     643        RTSemFastMutexRelease(g_VBoxNetFltSolarisMtx);
    622644        return ENOENT;
    623645    }
     
    648670        {
    649671            LogRel((DEVICE_NAME ":VBoxNetFltSolarisModOpen failed to allocate promiscuous stream data.\n"));
     672            RTSemFastMutexRelease(g_VBoxNetFltSolarisMtx);
    650673            return ENOMEM;
    651674        }
     
    668691        {
    669692            LogRel((DEVICE_NAME ":VBoxNetFltSolarisModOpen failed to allocate stream data.\n"));
     693            RTSemFastMutexRelease(g_VBoxNetFltSolarisMtx);
    670694            return ENOMEM;
    671695        }
     
    701725    pStream->pNext = *ppPrevStream;
    702726    *ppPrevStream = pStream;
     727
     728    /*
     729     * Release global lock, & do not hold locks across putnext calls.
     730     */
     731    RTSemFastMutexRelease(g_VBoxNetFltSolarisMtx);
    703732
    704733    qprocson(pQueue);
     
    771800    LogFlow((DEVICE_NAME ":VBoxNetFltSolarisModClose pQueue=%p fOpenMode=%d\n", pQueue, fOpenMode));
    772801
     802    int rc = RTSemFastMutexRequest(g_VBoxNetFltSolarisMtx);
     803    AssertRCReturn(rc, rc);
     804
    773805    vboxnetflt_stream_t *pStream = NULL;
    774806    vboxnetflt_stream_t **ppPrevStream = NULL;
     
    782814        LogRel((DEVICE_NAME ":VBoxNetFltSolarisModClose failed to get stream.\n"));
    783815        vboxNetFltRelease(pStream->pThis, false /* fBusy */);
     816        RTSemFastMutexRelease(g_VBoxNetFltSolarisMtx);
    784817        return ENXIO;
    785818    }
     
    848881    NOREF(fOpenMode);
    849882    NOREF(pCred);
     883
     884    RTSemFastMutexRelease(g_VBoxNetFltSolarisMtx);
    850885
    851886    return 0;
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