VirtualBox

儲存庫 vbox 的更動 17095


忽略:
時間撮記:
2009-2-24 下午08:08:20 (16 年 以前)
作者:
vboxsync
訊息:

#2957: VBoxNetAdp: Fixes in generic and darwin parts. No traffic yet.

位置:
trunk/src/VBox
檔案:
修改 4 筆資料

圖例:

未更動
新增
刪除
  • trunk/src/VBox/HostDrivers/VBoxNetAdp/VBoxNetAdp.c

    r17025 r17095  
    7979
    8080
     81
     82/**
     83 * Gets the enmState member atomically.
     84 *
     85 * Used for all reads.
     86 *
     87 * @returns The enmState value.
     88 * @param   pThis           The instance.
     89 */
     90DECLINLINE(VBOXNETADPSTATE) vboxNetAdpGetState(PVBOXNETADP pThis)
     91{
     92    return (VBOXNETADPSTATE)ASMAtomicUoReadU32((uint32_t volatile *)&pThis->enmState);
     93}
     94
     95
    8196/**
    8297 * Sets the enmState member atomically.
     
    89104DECLINLINE(void) vboxNetAdpSetState(PVBOXNETADP pThis, VBOXNETADPSTATE enmNewState)
    90105{
     106    Log(("vboxNetAdpSetState: pThis=%p, state change: %d -> %d.\n", pThis, vboxNetAdpGetState(pThis), enmNewState));
    91107    ASMAtomicWriteU32((uint32_t volatile *)&pThis->enmState, enmNewState);
    92108}
    93109
    94 
    95 /**
    96  * Gets the enmState member atomically.
     110/**
     111 * Sets the enmState member atomically.
     112 *
     113 * Used for all updates.
     114 *
     115 * @param   pThis           The instance.
     116 * @param   enmNewState     The new value.
     117 */
     118DECLINLINE(void) vboxNetAdpSetStateWithLock(PVBOXNETADP pThis, VBOXNETADPSTATE enmNewState)
     119{
     120    VBOXNETADPSTATE enmState;
     121    RTSPINLOCKTMP Tmp = RTSPINLOCKTMP_INITIALIZER;
     122    Log(("vboxNetAdpSetStateWithLock: pThis=%p, state=%d.\n", pThis, enmState));
     123    RTSpinlockAcquire(pThis->hSpinlock, &Tmp);
     124    vboxNetAdpSetState(pThis, enmNewState);
     125    RTSpinlockRelease(pThis->hSpinlock, &Tmp);
     126}
     127
     128
     129
     130/**
     131 * Gets the enmState member with locking.
    97132 *
    98133 * Used for all reads.
     
    101136 * @param   pThis           The instance.
    102137 */
    103 DECLINLINE(VBOXNETADPSTATE) vboxNetAdpGetState(PVBOXNETADP pThis)
    104 {
    105     return (VBOXNETADPSTATE)ASMAtomicUoReadU32((uint32_t volatile *)&pThis->enmState);
    106 }
    107 
    108 
    109 DECLINLINE(bool) vboxNetAdpIsAvailable(PVBOXNETADP pAdp)
    110 {
    111     return pAdp->enmState == kVBoxNetAdpState_Available;
    112 }
    113 
    114 DECLINLINE(bool) vboxNetAdpIsConnected(PVBOXNETADP pAdp)
    115 {
    116     return pAdp->enmState >= kVBoxNetAdpState_Connected;
    117 }
    118 
    119 DECLINLINE(bool) vboxNetAdpIsVoid(PVBOXNETADP pAdp)
    120 {
    121     return pAdp->enmState == kVBoxNetAdpState_Invalid;
    122 }
    123 
    124 DECLINLINE(bool) vboxNetAdpIsValid(PVBOXNETADP pAdp)
    125 {
    126     return pAdp->enmState != kVBoxNetAdpState_Invalid
    127         && pAdp->enmState != kVBoxNetAdpState_Transitional;
    128 }
    129 
    130 DECLINLINE(bool) vboxNetAdpIsBusy(PVBOXNETADP pAdp)
    131 {
    132     return pAdp->enmState == kVBoxNetAdpState_Connected;
    133 }
     138DECLINLINE(VBOXNETADPSTATE) vboxNetAdpGetStateWithLock(PVBOXNETADP pThis)
     139{
     140    VBOXNETADPSTATE enmState;
     141    RTSPINLOCKTMP Tmp = RTSPINLOCKTMP_INITIALIZER;
     142    RTSpinlockAcquire(pThis->hSpinlock, &Tmp);
     143    enmState = vboxNetAdpGetState(pThis);
     144    RTSpinlockRelease(pThis->hSpinlock, &Tmp);
     145    Log(("vboxNetAdpGetStateWithLock: pThis=%p, state=%d.\n", pThis, enmState));
     146    return enmState;
     147}
     148
     149/**
     150 * Checks and sets the enmState member atomically.
     151 *
     152 * Used for all updates.
     153 *
     154 * @returns true if the state has been changed.
     155 * @param   pThis           The instance.
     156 * @param   enmNewState     The new value.
     157 */
     158DECLINLINE(bool) vboxNetAdpCheckAndSetState(PVBOXNETADP pThis, VBOXNETADPSTATE enmOldState, VBOXNETADPSTATE enmNewState)
     159{
     160    VBOXNETADPSTATE enmActualState;
     161    bool fRc = true; /* be optimistic */
     162    RTSPINLOCKTMP Tmp = RTSPINLOCKTMP_INITIALIZER;
     163    RTSpinlockAcquire(pThis->hSpinlock, &Tmp);
     164    enmActualState = vboxNetAdpGetState(pThis);
     165    if (enmActualState == enmOldState)
     166        vboxNetAdpSetState(pThis, enmNewState);
     167    else
     168        fRc = false;
     169    RTSpinlockRelease(pThis->hSpinlock, &Tmp);
     170    if (fRc)
     171        Log(("vboxNetAdpCheckAndSetState: pThis=%p, state changed: %d -> %d.\n", pThis, enmOldState, enmNewState));
     172    else
     173        Log(("vboxNetAdpCheckAndSetState: pThis=%p, no state change: %d != %d (expected).\n", pThis, enmActualState, enmOldState));
     174    return fRc;
     175}
     176
    134177
    135178
     
    143186        PVBOXNETADP pThis = &pGlobals->aAdapters[i];
    144187        RTSpinlockAcquire(pThis->hSpinlock, &Tmp);
    145         if (vboxNetAdpIsValid(pThis)
     188        if (vboxNetAdpGetState(pThis)
    146189            && !strcmp(pThis->szName, pszName))
    147190        {
     
    180223     */
    181224    cRefs = ASMAtomicDecU32(&pThis->cRefs);
    182 /*     if (!cRefs) */
    183 /*         vboxNetAdpCheckDestroyInstance(pThis); */
    184 /*     else */
    185         Assert(cRefs < UINT32_MAX / 2);
     225    Assert(cRefs < UINT32_MAX / 2);
    186226}
    187227
     
    201241    Assert(pThis->MyPort.u32Version == INTNETTRUNKIFPORT_VERSION);
    202242    Assert(pThis->MyPort.u32VersionEnd == INTNETTRUNKIFPORT_VERSION);
    203     Assert(pThis->enmState == kVBoxNetAdpState_Connected);
     243    Assert(vboxNetAdpGetState(pThis) >= kVBoxNetAdpState_Connected);
    204244    AssertPtr(pThis->pGlobals);
    205245    Assert(pThis->hEventIdle != NIL_RTSEMEVENT);
     
    260300    Assert(pThis->MyPort.u32Version == INTNETTRUNKIFPORT_VERSION);
    261301    Assert(pThis->MyPort.u32VersionEnd == INTNETTRUNKIFPORT_VERSION);
    262     Assert(pThis->enmState == kVBoxNetAdpState_Connected);
     302    Assert(vboxNetAdpGetState(pThis) >= kVBoxNetAdpState_Connected);
    263303    AssertPtr(pThis->pGlobals);
    264304    Assert(pThis->hEventIdle != NIL_RTSEMEVENT);
     
    284324    Assert(pThis->MyPort.u32Version == INTNETTRUNKIFPORT_VERSION);
    285325    RTSpinlockAcquire(pThis->hSpinlock, &Tmp);
    286     if (pThis->enmState == kVBoxNetAdpState_Active)
     326    if (vboxNetAdpGetState(pThis) == kVBoxNetAdpState_Active)
    287327    {
    288328        fCanReceive = true;
     
    308348    AssertPtr(pThis);
    309349    AssertPtr(pSG);
     350    AssertPtr(pThis->pSwitchPort);
    310351    Assert(pThis->MyPort.u32Version == INTNETTRUNKIFPORT_VERSION);
    311352    pThis->pSwitchPort->pfnRecv(pThis->pSwitchPort, pSG, INTNETTRUNKDIR_HOST);
     
    368409     */
    369410    RTSpinlockAcquire(pThis->hSpinlock, &Tmp);
    370     if (pThis->enmState != kVBoxNetAdpState_Active)
     411    if (vboxNetAdpGetState(pThis) != kVBoxNetAdpState_Active)
    371412    {
    372413        RTSpinlockRelease(pThis->hSpinlock, &Tmp);
     
    398439    AssertPtr(pThis);
    399440    Assert(pThis->MyPort.u32Version == INTNETTRUNKIFPORT_VERSION);
    400     Assert(vboxNetAdpGetState(pThis) == kVBoxNetAdpState_Connected);
     441    Assert(vboxNetAdpGetStateWithLock(pThis) == kVBoxNetAdpState_Connected);
    401442
    402443    /*
     
    419460    AssertPtr(pThis);
    420461    Assert(pThis->MyPort.u32Version == INTNETTRUNKIFPORT_VERSION);
    421     Assert(vboxNetAdpGetState(pThis) == kVBoxNetAdpState_Connected);
     462    Assert(vboxNetAdpGetStateWithLock(pThis) == kVBoxNetAdpState_Connected);
    422463
    423464    /*
     
    440481    AssertPtr(pThis);
    441482    Assert(pThis->MyPort.u32Version == INTNETTRUNKIFPORT_VERSION);
    442     Assert(vboxNetAdpGetState(pThis) == kVBoxNetAdpState_Connected);
     483    Assert(vboxNetAdpGetStateWithLock(pThis) == kVBoxNetAdpState_Active);
    443484
    444485    /*
     
    454495NETADP_DECL_CALLBACK(int) vboxNetAdpPortWaitForIdle(PINTNETTRUNKIFPORT pIfPort, uint32_t cMillies)
    455496{
     497    int rc;
    456498    PVBOXNETADP pThis = IFPORT_2_VBOXNETADP(pIfPort);
    457     int rc;
    458499
    459500    /*
     
    462503    AssertPtr(pThis);
    463504    Assert(pThis->MyPort.u32Version == INTNETTRUNKIFPORT_VERSION);
    464     AssertReturn(vboxNetAdpGetState(pThis) == kVBoxNetAdpState_Connected, VERR_INVALID_STATE);
     505    AssertReturn(vboxNetAdpGetStateWithLock(pThis) >= kVBoxNetAdpState_Connected, VERR_INVALID_STATE);
    465506
    466507    /*
     
    495536    Assert(pThis->MyPort.u32Version == INTNETTRUNKIFPORT_VERSION);
    496537
     538    Log(("vboxNetAdpPortSetActive: pThis=%p, fActive=%d, state before: %d.\n", pThis, fActive, vboxNetAdpGetState(pThis)));
    497539    RTSpinlockAcquire(pThis->hSpinlock, &Tmp);
    498     switch (vboxNetAdpGetState(pThis))
    499     {
    500         case kVBoxNetAdpState_Connected:
    501             fPreviouslyActive = false;
    502             pThis->enmState = kVBoxNetAdpState_Active;
    503             break;
    504         case kVBoxNetAdpState_Active:
    505             fPreviouslyActive = true;
    506             pThis->enmState = kVBoxNetAdpState_Connected;
    507             break;
    508         default:
    509             fPreviouslyActive = false;
    510             break;
     540    fPreviouslyActive = vboxNetAdpGetState(pThis) == kVBoxNetAdpState_Active;
     541    if (fPreviouslyActive != fActive)
     542    {
     543        switch (vboxNetAdpGetState(pThis))
     544        {
     545            case kVBoxNetAdpState_Connected:
     546                vboxNetAdpSetState(pThis, kVBoxNetAdpState_Active);
     547                break;
     548            case kVBoxNetAdpState_Active:
     549                vboxNetAdpSetState(pThis, kVBoxNetAdpState_Connected);
     550                break;
     551        }
    511552    }
    512553    RTSpinlockRelease(pThis->hSpinlock, &Tmp);
     554    Log(("vboxNetAdpPortSetActive: state after: %d.\n", vboxNetAdpGetState(pThis)));
    513555    return fPreviouslyActive;
    514556}
     
    533575    Assert(pThis->hSpinlock != NIL_RTSPINLOCK);
    534576
    535     Assert(pThis->enmState == kVBoxNetAdpState_Connected);
     577
     578    /*
     579     * Disconnect and release it.
     580     */
     581    RTSpinlockAcquire(pThis->hSpinlock, &Tmp);
     582    //Assert(vboxNetAdpGetState(pThis) == kVBoxNetAdpState_Connected);
    536583    Assert(!pThis->cBusy);
    537 
    538     /*
    539      * Disconnect and release it.
    540      */
    541     RTSpinlockAcquire(pThis->hSpinlock, &Tmp);
    542584    vboxNetAdpSetState(pThis, kVBoxNetAdpState_Transitional);
    543585    RTSpinlockRelease(pThis->hSpinlock, &Tmp);
     
    573615}
    574616
     617
     618int vboxNetAdpCreate (PINTNETTRUNKFACTORY pIfFactory, PVBOXNETADP *ppNew)
     619{
     620    int rc;
     621    unsigned i;
     622    PVBOXNETADPGLOBALS pGlobals = (PVBOXNETADPGLOBALS)((uint8_t *)pIfFactory - RT_OFFSETOF(VBOXNETADPGLOBALS, TrunkFactory));
     623
     624    for (i = 0; i < RT_ELEMENTS(pGlobals->aAdapters); i++)
     625    {
     626        RTSPINLOCKTMP Tmp = RTSPINLOCKTMP_INITIALIZER;
     627        PVBOXNETADP pThis = &pGlobals->aAdapters[i];
     628   
     629        if (vboxNetAdpCheckAndSetState(pThis, kVBoxNetAdpState_Invalid, kVBoxNetAdpState_Transitional))
     630        {
     631            /* Found an empty slot -- use it. */
     632            RTMAC Mac;
     633            Assert(ASMAtomicIncU32(&pThis->cRefs) == 1);
     634            vboxNetAdpComposeMACAddress(pThis, &Mac);
     635            rc = vboxNetAdpOsCreate(pThis, &Mac);
     636            *ppNew = pThis;
     637            RTSpinlockAcquire(pThis->hSpinlock, &Tmp);
     638            vboxNetAdpSetState(pThis, kVBoxNetAdpState_Available);
     639            RTSpinlockRelease(pThis->hSpinlock, &Tmp);
     640            return rc;
     641        }
     642    }
     643
     644    /* All slots in adapter array are busy. */
     645    return VERR_OUT_OF_RESOURCES;
     646}
     647
     648int vboxNetAdpDestroy (PVBOXNETADP pThis)
     649{
     650    int rc = VINF_SUCCESS;
     651    RTSPINLOCKTMP Tmp = RTSPINLOCKTMP_INITIALIZER;
     652   
     653    RTSpinlockAcquire(pThis->hSpinlock, &Tmp);
     654    if (vboxNetAdpGetState(pThis) != kVBoxNetAdpState_Available || pThis->cBusy)
     655    {
     656        RTSpinlockRelease(pThis->hSpinlock, &Tmp);
     657        return VERR_INTNET_FLT_IF_BUSY;
     658    }
     659    vboxNetAdpSetState(pThis, kVBoxNetAdpState_Transitional);
     660    RTSpinlockRelease(pThis->hSpinlock, &Tmp);
     661    vboxNetAdpRelease(pThis);
     662
     663    vboxNetAdpOsDestroy(pThis);
     664
     665    RTSpinlockAcquire(pThis->hSpinlock, &Tmp);
     666    vboxNetAdpSetState(pThis, kVBoxNetAdpState_Invalid);
     667    RTSpinlockRelease(pThis->hSpinlock, &Tmp);
     668
     669    return rc;
     670}
    575671
    576672/**
     
    594690     * Validate state.
    595691     */
    596     //Assert(!pThis->fActive);
    597692    Assert(!pThis->cBusy);
    598     Assert(vboxNetAdpGetState(pThis) == kVBoxNetAdpState_Transitional);
     693    Assert(vboxNetAdpGetStateWithLock(pThis) == kVBoxNetAdpState_Transitional);
    599694
    600695    /*
     
    611706        pThis->pSwitchPort = NULL;
    612707
    613     //Assert(!pThis->fActive);
    614708    return rc;
    615709}
     
    634728    if (pThis)
    635729    {
    636         RTSPINLOCKTMP Tmp = RTSPINLOCKTMP_INITIALIZER;
    637         RTSpinlockAcquire(pThis->hSpinlock, &Tmp);
    638         if (pThis->enmState == kVBoxNetAdpState_Available)
     730        if (vboxNetAdpCheckAndSetState(pThis, kVBoxNetAdpState_Available, kVBoxNetAdpState_Transitional))
    639731        {
    640             pThis->enmState = kVBoxNetAdpState_Transitional;
    641             RTSpinlockRelease(pThis->hSpinlock, &Tmp);
     732            vboxNetAdpRetain(pThis);
    642733            rc = vboxNetAdpConnectIt(pThis, pSwitchPort, ppIfPort);
    643             RTSpinlockAcquire(pThis->hSpinlock, &Tmp);
    644             if (RT_SUCCESS(rc))
    645                 pThis->enmState = kVBoxNetAdpState_Connected;
    646             else
    647                 pThis->enmState = kVBoxNetAdpState_Available;
     734            vboxNetAdpSetStateWithLock(pThis, RT_SUCCESS(rc) ? kVBoxNetAdpState_Connected : kVBoxNetAdpState_Available);
    648735        }
    649736        else
    650737            rc = VERR_INTNET_FLT_IF_BUSY;
    651         RTSpinlockRelease(pThis->hSpinlock, &Tmp);
    652738    }
    653739    else
     
    723809    for (i = 0; i < RT_ELEMENTS(pGlobals->aAdapters); i++)
    724810    {
    725         RTSPINLOCKTMP Tmp = RTSPINLOCKTMP_INITIALIZER;
    726811        PVBOXNETADP pThis = &pGlobals->aAdapters[i];
    727         RTSpinlockAcquire(pThis->hSpinlock, &Tmp);
    728         if (vboxNetAdpIsConnected(&pGlobals->aAdapters[i]))
     812        if (vboxNetAdpGetStateWithLock(&pGlobals->aAdapters[i]) >= kVBoxNetAdpState_Connected)
    729813        {
    730             RTSpinlockRelease(pThis->hSpinlock, &Tmp);
    731814            fRc = false;
    732815            break; /* We already know the answer. */
    733816        }
    734         RTSpinlockRelease(pThis->hSpinlock, &Tmp);
    735817    }
    736818    return fRc && ASMAtomicUoReadS32((int32_t volatile *)&pGlobals->cFactoryRefs) <= 0;
     
    777859}
    778860
     861static int vboxNetAdpSlotCreate(PVBOXNETADPGLOBALS pGlobals, unsigned uUnit, PVBOXNETADP pNew)
     862{
     863    int rc;
     864
     865    pNew->MyPort.u32Version             = INTNETTRUNKIFPORT_VERSION;
     866    pNew->MyPort.pfnRetain              = NETADP_CALLBACK(vboxNetAdpPortRetain);
     867    pNew->MyPort.pfnRelease             = NETADP_CALLBACK(vboxNetAdpPortRelease);
     868    pNew->MyPort.pfnDisconnectAndRelease= NETADP_CALLBACK(vboxNetAdpPortDisconnectAndRelease);
     869    pNew->MyPort.pfnSetActive           = NETADP_CALLBACK(vboxNetAdpPortSetActive);
     870    pNew->MyPort.pfnWaitForIdle         = NETADP_CALLBACK(vboxNetAdpPortWaitForIdle);
     871    pNew->MyPort.pfnGetMacAddress       = NETADP_CALLBACK(vboxNetAdpPortGetMacAddress);
     872    pNew->MyPort.pfnIsHostMac           = NETADP_CALLBACK(vboxNetAdpPortIsHostMac);
     873    pNew->MyPort.pfnIsPromiscuous       = NETADP_CALLBACK(vboxNetAdpPortIsPromiscuous);
     874    pNew->MyPort.pfnXmit                = NETADP_CALLBACK(vboxNetAdpPortXmit);
     875    pNew->MyPort.u32VersionEnd          = INTNETTRUNKIFPORT_VERSION;
     876    pNew->pSwitchPort                   = NULL;
     877    pNew->pGlobals                      = pGlobals;
     878    pNew->hSpinlock                     = NIL_RTSPINLOCK;
     879    pNew->enmState                      = kVBoxNetAdpState_Invalid;
     880    pNew->cRefs                         = 0;
     881    pNew->cBusy                         = 0;
     882    pNew->hEventIdle                    = NIL_RTSEMEVENT;
     883
     884    rc = RTSpinlockCreate(&pNew->hSpinlock);
     885    if (RT_SUCCESS(rc))
     886    {
     887        rc = RTSemEventCreate(&pNew->hEventIdle);
     888        if (RT_SUCCESS(rc))
     889        {
     890            rc = vboxNetAdpOsInit(pNew);
     891            if (RT_SUCCESS(rc))
     892            {
     893                return rc;
     894            }
     895            RTSemEventDestroy(pNew->hEventIdle);
     896            pNew->hEventIdle = NIL_RTSEMEVENT;
     897        }
     898        RTSpinlockDestroy(pNew->hSpinlock);
     899        pNew->hSpinlock = NIL_RTSPINLOCK;
     900    }
     901    return rc;
     902}
     903
     904static void vboxNetAdpSlotDestroy(PVBOXNETADP pThis)
     905{
     906    Assert(pThis->cRefs == 0);
     907    Assert(pThis->cBusy == 0);
     908    Assert(vboxNetAdpGetState(pThis) == kVBoxNetAdpState_Invalid);
     909    if (pThis->hEventIdle != NIL_RTSEMEVENT)
     910    {
     911        RTSemEventDestroy(pThis->hEventIdle);
     912        pThis->hEventIdle = NIL_RTSEMEVENT;
     913    }
     914    if (pThis->hSpinlock != NIL_RTSPINLOCK)
     915    {
     916        RTSpinlockDestroy(pThis->hSpinlock);
     917        pThis->hSpinlock = NIL_RTSPINLOCK;
     918    }
     919}
     920
    779921/**
    780922 * performs "base" globals deinitialization
     
    789931DECLHIDDEN(void) vboxNetAdpDeleteGlobalsBase(PVBOXNETADPGLOBALS pGlobals)
    790932{
     933    int i;
    791934    /*
    792935     * Release resources.
    793936     */
     937    for (i = 0; i < (int)RT_ELEMENTS(pGlobals->aAdapters); i++)
     938        if (RT_SUCCESS(vboxNetAdpDestroy(&pGlobals->aAdapters[i])))
     939            vboxNetAdpSlotDestroy(&pGlobals->aAdapters[i]);
     940
    794941    RTSemFastMutexDestroy(pGlobals->hFastMtx);
    795942    pGlobals->hFastMtx = NIL_RTSEMFASTMUTEX;
     
    818965    return rc;
    819966}
     967
    820968
    821969/**
     
    840988        for (i = 0; i < (int)RT_ELEMENTS(pGlobals->aAdapters); i++)
    841989        {
    842             rc = RTSpinlockCreate(&pGlobals->aAdapters[i].hSpinlock);
     990            rc = vboxNetAdpSlotCreate(pGlobals, i, &pGlobals->aAdapters[i]);
    843991            if (RT_FAILURE(rc))
    844992            {
    845993                /* Clean up. */
    846994                while (--i >= 0)
    847                     RTSpinlockDestroy(pGlobals->aAdapters[i].hSpinlock);
     995                    vboxNetAdpSlotDestroy(&pGlobals->aAdapters[i]);
    848996                Log(("vboxNetAdpInitGlobalsBase: Failed to create fast mutex (rc=%Rrc).\n", rc));
    849997                RTSemFastMutexDestroy(pGlobals->hFastMtx);
     
    8541002        pGlobals->TrunkFactory.pfnCreateAndConnect = vboxNetAdpFactoryCreateAndConnect;
    8551003
    856         strcpy(pGlobals->SupDrvFactory.szName, "VBoxNetTap");
     1004        strcpy(pGlobals->SupDrvFactory.szName, "VBoxNetAdp");
    8571005        pGlobals->SupDrvFactory.pfnQueryFactoryInterface = vboxNetAdpQueryFactoryInterface;
    8581006    }
     
    8821030        if (RT_SUCCESS(rc))
    8831031        {
     1032            /* @todo REMOVE ME! */
     1033            PVBOXNETADP pTmp;
     1034            rc = vboxNetAdpCreate(&pGlobals->TrunkFactory, &pTmp);
     1035            if (RT_FAILURE(rc))
     1036                Log(("Failed to create vboxnet0, rc=%Rrc.\n", rc));
    8841037            Log(("VBoxNetAdp: pSession=%p\n", SUPR0IdcGetSession(&pGlobals->SupDrvIDC)));
    8851038            return rc;
     
    9231076    return rc;
    9241077}
    925 
    926 //////
    927 
    928 int vboxNetAdpCreate (PINTNETTRUNKFACTORY pIfFactory, PVBOXNETADP *ppNew)
    929 {
    930     int rc;
    931     unsigned i;
    932     PVBOXNETADPGLOBALS pGlobals = (PVBOXNETADPGLOBALS)((uint8_t *)pIfFactory - RT_OFFSETOF(VBOXNETADPGLOBALS, TrunkFactory));
    933 
    934     for (i = 0; i < RT_ELEMENTS(pGlobals->aAdapters); i++)
    935     {
    936         RTSPINLOCKTMP Tmp = RTSPINLOCKTMP_INITIALIZER;
    937         PVBOXNETADP pThis = &pGlobals->aAdapters[i];
    938 
    939         RTSpinlockAcquire(pThis->hSpinlock, &Tmp);
    940         if (vboxNetAdpIsVoid(pThis))
    941         {
    942             RTMAC Mac;
    943 
    944             pThis->enmState = kVBoxNetAdpState_Transitional;
    945             RTSpinlockRelease(pThis->hSpinlock, &Tmp);
    946             /* Found an empty slot -- use it. */
    947             pThis->uUnit = i;
    948             vboxNetAdpComposeMACAddress(pThis, &Mac);
    949             rc = vboxNetAdpOsCreate(pThis, &Mac);
    950             *ppNew = pThis;
    951             RTSpinlockAcquire(pThis->hSpinlock, &Tmp);
    952             pThis->enmState = kVBoxNetAdpState_Available;
    953             RTSpinlockRelease(pThis->hSpinlock, &Tmp);
    954             return rc;
    955         }
    956         RTSpinlockRelease(pThis->hSpinlock, &Tmp);
    957     }
    958 
    959     /* All slots in adapter array are busy. */
    960     return VERR_OUT_OF_RESOURCES;
    961 }
    962 
    963 int vboxNetAdpDestroy (PVBOXNETADP pThis)
    964 {
    965     int rc;
    966     RTSPINLOCKTMP Tmp = RTSPINLOCKTMP_INITIALIZER;
    967 
    968     RTSpinlockAcquire(pThis->hSpinlock, &Tmp);
    969     if (pThis->enmState != kVBoxNetAdpState_Available || pThis->cBusy)
    970     {
    971         RTSpinlockRelease(pThis->hSpinlock, &Tmp);
    972         return VERR_INTNET_FLT_IF_BUSY;
    973     }
    974     pThis->enmState = kVBoxNetAdpState_Transitional;
    975     RTSpinlockRelease(pThis->hSpinlock, &Tmp);
    976 
    977     vboxNetAdpOsDestroy(pThis);
    978 
    979     RTSpinlockAcquire(pThis->hSpinlock, &Tmp);
    980     pThis->enmState = kVBoxNetAdpState_Invalid;
    981     RTSpinlockRelease(pThis->hSpinlock, &Tmp);
    982 
    983     return rc;
    984 }
  • trunk/src/VBox/HostDrivers/VBoxNetAdp/VBoxNetAdpInternal.h

    r16960 r17095  
    3636#define VBOXNETADP_MAX_INSTANCES   8
    3737#define VBOXNETADP_NAME            "vboxnet"
     38#define VBOXNETADP_MAX_NAME_LEN    32
    3839#define VBOXNETADP_MTU             1500
    3940#if defined(RT_OS_DARWIN)
     
    142143    } u;
    143144    /** The interface name. */
    144     char szName[1];
     145    char szName[VBOXNETADP_MAX_NAME_LEN];
    145146};
    146147typedef struct VBoxNetAdapter VBOXNETADP;
     
    270271
    271272/**
     273 * This is called to perform OS-specific structure initializations.
     274 *
     275 * @return  IPRT status code.
     276 * @param   pThis           The new instance.
     277 *
     278 * @remarks Owns no locks.
     279 */
     280DECLHIDDEN(int) vboxNetAdpOsInit(PVBOXNETADP pThis);
     281
     282/**
    272283 * Counter part to vboxNetAdpOsCreate().
    273284 *
  • trunk/src/VBox/HostDrivers/VBoxNetAdp/darwin/VBoxNetAdp-darwin.cpp

    r16976 r17095  
    4040#include <iprt/semaphore.h>
    4141#include <iprt/spinlock.h>
     42#include <iprt/string.h>
    4243#include <iprt/uuid.h>
    4344
     
    120121DECLINLINE(ifnet_t) vboxNetAdpDarwinRetainIfNet(PVBOXNETADP pThis)
    121122{
    122     RTSPINLOCKTMP Tmp = RTSPINLOCKTMP_INITIALIZER;
    123123    ifnet_t pIfNet = NULL;
    124124
    125     RTSpinlockAcquire(pThis->hSpinlock, &Tmp);
    126     if (pThis->enmState >= kVBoxNetAdpState_Connected)
    127         ifnet_reference(pThis->u.s.pIface);
    128     RTSpinlockRelease(pThis->hSpinlock, &Tmp);
     125    ifnet_reference(pThis->u.s.pIface);
    129126
    130127    return pIfNet;
     
    599596    memcpy(LLADDR(&mac), pMACAddress->au8, mac.sdl_alen);
    600597
     598    RTStrPrintf(pThis->szName, VBOXNETADP_MAX_NAME_LEN, "%s%d", VBOXNETADP_NAME, pThis->uUnit);
    601599    vboxNetAdpDarwinComposeUUID(pThis, &uuid);
    602600    Params.uniqueid = uuid.au8;
     
    682680}
    683681
     682int  vboxNetAdpOsInit(PVBOXNETADP pThis)
     683{
     684    /*
     685     * Init the darwin specific members.
     686     */
     687    pThis->u.s.pIface = NULL;
     688    pThis->u.s.hEvtDetached = NIL_RTSEMEVENT;
     689    memset(pThis->u.s.aAttachedFamilies, 0, sizeof(pThis->u.s.aAttachedFamilies));
     690
     691    return VINF_SUCCESS;
     692}
     693
    684694/**
    685695 * Start the kernel module.
  • trunk/src/VBox/Runtime/VBox/log-vbox.cpp

    r16195 r17095  
    418418# endif
    419419# if defined(DEBUG_aleksey)  /* Guest ring-0 as well */
    420         RTLogGroupSettings(pLogger, "+net_flt_drv.e.l.f+srv_intnet.e.l.f");
     420        RTLogGroupSettings(pLogger, "+net_tap_drv.e.l.f+net_flt_drv.e.l.f+srv_intnet.e.l.f");
    421421        RTLogFlags(pLogger, "enabled unbuffered");
    422422        pLogger->fDestFlags |= RTLOGDEST_DEBUGGER | RTLOGDEST_STDOUT;
注意: 瀏覽 TracChangeset 來幫助您使用更動檢視器

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