儲存庫 vbox 的更動 17095
- 時間撮記:
- 2009-2-24 下午08:08:20 (16 年 以前)
- 位置:
- trunk/src/VBox
- 檔案:
-
- 修改 4 筆資料
圖例:
- 未更動
- 新增
- 刪除
-
trunk/src/VBox/HostDrivers/VBoxNetAdp/VBoxNetAdp.c
r17025 r17095 79 79 80 80 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 */ 90 DECLINLINE(VBOXNETADPSTATE) vboxNetAdpGetState(PVBOXNETADP pThis) 91 { 92 return (VBOXNETADPSTATE)ASMAtomicUoReadU32((uint32_t volatile *)&pThis->enmState); 93 } 94 95 81 96 /** 82 97 * Sets the enmState member atomically. … … 89 104 DECLINLINE(void) vboxNetAdpSetState(PVBOXNETADP pThis, VBOXNETADPSTATE enmNewState) 90 105 { 106 Log(("vboxNetAdpSetState: pThis=%p, state change: %d -> %d.\n", pThis, vboxNetAdpGetState(pThis), enmNewState)); 91 107 ASMAtomicWriteU32((uint32_t volatile *)&pThis->enmState, enmNewState); 92 108 } 93 109 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 */ 118 DECLINLINE(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. 97 132 * 98 133 * Used for all reads. … … 101 136 * @param pThis The instance. 102 137 */ 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 } 138 DECLINLINE(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 */ 158 DECLINLINE(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 134 177 135 178 … … 143 186 PVBOXNETADP pThis = &pGlobals->aAdapters[i]; 144 187 RTSpinlockAcquire(pThis->hSpinlock, &Tmp); 145 if (vboxNetAdp IsValid(pThis)188 if (vboxNetAdpGetState(pThis) 146 189 && !strcmp(pThis->szName, pszName)) 147 190 { … … 180 223 */ 181 224 cRefs = ASMAtomicDecU32(&pThis->cRefs); 182 /* if (!cRefs) */ 183 /* vboxNetAdpCheckDestroyInstance(pThis); */ 184 /* else */ 185 Assert(cRefs < UINT32_MAX / 2); 225 Assert(cRefs < UINT32_MAX / 2); 186 226 } 187 227 … … 201 241 Assert(pThis->MyPort.u32Version == INTNETTRUNKIFPORT_VERSION); 202 242 Assert(pThis->MyPort.u32VersionEnd == INTNETTRUNKIFPORT_VERSION); 203 Assert( pThis->enmState == kVBoxNetAdpState_Connected);243 Assert(vboxNetAdpGetState(pThis) >= kVBoxNetAdpState_Connected); 204 244 AssertPtr(pThis->pGlobals); 205 245 Assert(pThis->hEventIdle != NIL_RTSEMEVENT); … … 260 300 Assert(pThis->MyPort.u32Version == INTNETTRUNKIFPORT_VERSION); 261 301 Assert(pThis->MyPort.u32VersionEnd == INTNETTRUNKIFPORT_VERSION); 262 Assert( pThis->enmState == kVBoxNetAdpState_Connected);302 Assert(vboxNetAdpGetState(pThis) >= kVBoxNetAdpState_Connected); 263 303 AssertPtr(pThis->pGlobals); 264 304 Assert(pThis->hEventIdle != NIL_RTSEMEVENT); … … 284 324 Assert(pThis->MyPort.u32Version == INTNETTRUNKIFPORT_VERSION); 285 325 RTSpinlockAcquire(pThis->hSpinlock, &Tmp); 286 if ( pThis->enmState== kVBoxNetAdpState_Active)326 if (vboxNetAdpGetState(pThis) == kVBoxNetAdpState_Active) 287 327 { 288 328 fCanReceive = true; … … 308 348 AssertPtr(pThis); 309 349 AssertPtr(pSG); 350 AssertPtr(pThis->pSwitchPort); 310 351 Assert(pThis->MyPort.u32Version == INTNETTRUNKIFPORT_VERSION); 311 352 pThis->pSwitchPort->pfnRecv(pThis->pSwitchPort, pSG, INTNETTRUNKDIR_HOST); … … 368 409 */ 369 410 RTSpinlockAcquire(pThis->hSpinlock, &Tmp); 370 if ( pThis->enmState!= kVBoxNetAdpState_Active)411 if (vboxNetAdpGetState(pThis) != kVBoxNetAdpState_Active) 371 412 { 372 413 RTSpinlockRelease(pThis->hSpinlock, &Tmp); … … 398 439 AssertPtr(pThis); 399 440 Assert(pThis->MyPort.u32Version == INTNETTRUNKIFPORT_VERSION); 400 Assert(vboxNetAdpGetState (pThis) == kVBoxNetAdpState_Connected);441 Assert(vboxNetAdpGetStateWithLock(pThis) == kVBoxNetAdpState_Connected); 401 442 402 443 /* … … 419 460 AssertPtr(pThis); 420 461 Assert(pThis->MyPort.u32Version == INTNETTRUNKIFPORT_VERSION); 421 Assert(vboxNetAdpGetState (pThis) == kVBoxNetAdpState_Connected);462 Assert(vboxNetAdpGetStateWithLock(pThis) == kVBoxNetAdpState_Connected); 422 463 423 464 /* … … 440 481 AssertPtr(pThis); 441 482 Assert(pThis->MyPort.u32Version == INTNETTRUNKIFPORT_VERSION); 442 Assert(vboxNetAdpGetState (pThis) == kVBoxNetAdpState_Connected);483 Assert(vboxNetAdpGetStateWithLock(pThis) == kVBoxNetAdpState_Active); 443 484 444 485 /* … … 454 495 NETADP_DECL_CALLBACK(int) vboxNetAdpPortWaitForIdle(PINTNETTRUNKIFPORT pIfPort, uint32_t cMillies) 455 496 { 497 int rc; 456 498 PVBOXNETADP pThis = IFPORT_2_VBOXNETADP(pIfPort); 457 int rc;458 499 459 500 /* … … 462 503 AssertPtr(pThis); 463 504 Assert(pThis->MyPort.u32Version == INTNETTRUNKIFPORT_VERSION); 464 AssertReturn(vboxNetAdpGetState (pThis) == kVBoxNetAdpState_Connected, VERR_INVALID_STATE);505 AssertReturn(vboxNetAdpGetStateWithLock(pThis) >= kVBoxNetAdpState_Connected, VERR_INVALID_STATE); 465 506 466 507 /* … … 495 536 Assert(pThis->MyPort.u32Version == INTNETTRUNKIFPORT_VERSION); 496 537 538 Log(("vboxNetAdpPortSetActive: pThis=%p, fActive=%d, state before: %d.\n", pThis, fActive, vboxNetAdpGetState(pThis))); 497 539 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 } 511 552 } 512 553 RTSpinlockRelease(pThis->hSpinlock, &Tmp); 554 Log(("vboxNetAdpPortSetActive: state after: %d.\n", vboxNetAdpGetState(pThis))); 513 555 return fPreviouslyActive; 514 556 } … … 533 575 Assert(pThis->hSpinlock != NIL_RTSPINLOCK); 534 576 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); 536 583 Assert(!pThis->cBusy); 537 538 /*539 * Disconnect and release it.540 */541 RTSpinlockAcquire(pThis->hSpinlock, &Tmp);542 584 vboxNetAdpSetState(pThis, kVBoxNetAdpState_Transitional); 543 585 RTSpinlockRelease(pThis->hSpinlock, &Tmp); … … 573 615 } 574 616 617 618 int 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 648 int 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 } 575 671 576 672 /** … … 594 690 * Validate state. 595 691 */ 596 //Assert(!pThis->fActive);597 692 Assert(!pThis->cBusy); 598 Assert(vboxNetAdpGetState (pThis) == kVBoxNetAdpState_Transitional);693 Assert(vboxNetAdpGetStateWithLock(pThis) == kVBoxNetAdpState_Transitional); 599 694 600 695 /* … … 611 706 pThis->pSwitchPort = NULL; 612 707 613 //Assert(!pThis->fActive);614 708 return rc; 615 709 } … … 634 728 if (pThis) 635 729 { 636 RTSPINLOCKTMP Tmp = RTSPINLOCKTMP_INITIALIZER; 637 RTSpinlockAcquire(pThis->hSpinlock, &Tmp); 638 if (pThis->enmState == kVBoxNetAdpState_Available) 730 if (vboxNetAdpCheckAndSetState(pThis, kVBoxNetAdpState_Available, kVBoxNetAdpState_Transitional)) 639 731 { 640 pThis->enmState = kVBoxNetAdpState_Transitional; 641 RTSpinlockRelease(pThis->hSpinlock, &Tmp); 732 vboxNetAdpRetain(pThis); 642 733 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); 648 735 } 649 736 else 650 737 rc = VERR_INTNET_FLT_IF_BUSY; 651 RTSpinlockRelease(pThis->hSpinlock, &Tmp);652 738 } 653 739 else … … 723 809 for (i = 0; i < RT_ELEMENTS(pGlobals->aAdapters); i++) 724 810 { 725 RTSPINLOCKTMP Tmp = RTSPINLOCKTMP_INITIALIZER;726 811 PVBOXNETADP pThis = &pGlobals->aAdapters[i]; 727 RTSpinlockAcquire(pThis->hSpinlock, &Tmp); 728 if (vboxNetAdpIsConnected(&pGlobals->aAdapters[i])) 812 if (vboxNetAdpGetStateWithLock(&pGlobals->aAdapters[i]) >= kVBoxNetAdpState_Connected) 729 813 { 730 RTSpinlockRelease(pThis->hSpinlock, &Tmp);731 814 fRc = false; 732 815 break; /* We already know the answer. */ 733 816 } 734 RTSpinlockRelease(pThis->hSpinlock, &Tmp);735 817 } 736 818 return fRc && ASMAtomicUoReadS32((int32_t volatile *)&pGlobals->cFactoryRefs) <= 0; … … 777 859 } 778 860 861 static 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 904 static 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 779 921 /** 780 922 * performs "base" globals deinitialization … … 789 931 DECLHIDDEN(void) vboxNetAdpDeleteGlobalsBase(PVBOXNETADPGLOBALS pGlobals) 790 932 { 933 int i; 791 934 /* 792 935 * Release resources. 793 936 */ 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 794 941 RTSemFastMutexDestroy(pGlobals->hFastMtx); 795 942 pGlobals->hFastMtx = NIL_RTSEMFASTMUTEX; … … 818 965 return rc; 819 966 } 967 820 968 821 969 /** … … 840 988 for (i = 0; i < (int)RT_ELEMENTS(pGlobals->aAdapters); i++) 841 989 { 842 rc = RTSpinlockCreate(&pGlobals->aAdapters[i].hSpinlock);990 rc = vboxNetAdpSlotCreate(pGlobals, i, &pGlobals->aAdapters[i]); 843 991 if (RT_FAILURE(rc)) 844 992 { 845 993 /* Clean up. */ 846 994 while (--i >= 0) 847 RTSpinlockDestroy(pGlobals->aAdapters[i].hSpinlock);995 vboxNetAdpSlotDestroy(&pGlobals->aAdapters[i]); 848 996 Log(("vboxNetAdpInitGlobalsBase: Failed to create fast mutex (rc=%Rrc).\n", rc)); 849 997 RTSemFastMutexDestroy(pGlobals->hFastMtx); … … 854 1002 pGlobals->TrunkFactory.pfnCreateAndConnect = vboxNetAdpFactoryCreateAndConnect; 855 1003 856 strcpy(pGlobals->SupDrvFactory.szName, "VBoxNet Tap");1004 strcpy(pGlobals->SupDrvFactory.szName, "VBoxNetAdp"); 857 1005 pGlobals->SupDrvFactory.pfnQueryFactoryInterface = vboxNetAdpQueryFactoryInterface; 858 1006 } … … 882 1030 if (RT_SUCCESS(rc)) 883 1031 { 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)); 884 1037 Log(("VBoxNetAdp: pSession=%p\n", SUPR0IdcGetSession(&pGlobals->SupDrvIDC))); 885 1038 return rc; … … 923 1076 return rc; 924 1077 } 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 36 36 #define VBOXNETADP_MAX_INSTANCES 8 37 37 #define VBOXNETADP_NAME "vboxnet" 38 #define VBOXNETADP_MAX_NAME_LEN 32 38 39 #define VBOXNETADP_MTU 1500 39 40 #if defined(RT_OS_DARWIN) … … 142 143 } u; 143 144 /** The interface name. */ 144 char szName[ 1];145 char szName[VBOXNETADP_MAX_NAME_LEN]; 145 146 }; 146 147 typedef struct VBoxNetAdapter VBOXNETADP; … … 270 271 271 272 /** 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 */ 280 DECLHIDDEN(int) vboxNetAdpOsInit(PVBOXNETADP pThis); 281 282 /** 272 283 * Counter part to vboxNetAdpOsCreate(). 273 284 * -
trunk/src/VBox/HostDrivers/VBoxNetAdp/darwin/VBoxNetAdp-darwin.cpp
r16976 r17095 40 40 #include <iprt/semaphore.h> 41 41 #include <iprt/spinlock.h> 42 #include <iprt/string.h> 42 43 #include <iprt/uuid.h> 43 44 … … 120 121 DECLINLINE(ifnet_t) vboxNetAdpDarwinRetainIfNet(PVBOXNETADP pThis) 121 122 { 122 RTSPINLOCKTMP Tmp = RTSPINLOCKTMP_INITIALIZER;123 123 ifnet_t pIfNet = NULL; 124 124 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); 129 126 130 127 return pIfNet; … … 599 596 memcpy(LLADDR(&mac), pMACAddress->au8, mac.sdl_alen); 600 597 598 RTStrPrintf(pThis->szName, VBOXNETADP_MAX_NAME_LEN, "%s%d", VBOXNETADP_NAME, pThis->uUnit); 601 599 vboxNetAdpDarwinComposeUUID(pThis, &uuid); 602 600 Params.uniqueid = uuid.au8; … … 682 680 } 683 681 682 int 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 684 694 /** 685 695 * Start the kernel module. -
trunk/src/VBox/Runtime/VBox/log-vbox.cpp
r16195 r17095 418 418 # endif 419 419 # 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"); 421 421 RTLogFlags(pLogger, "enabled unbuffered"); 422 422 pLogger->fDestFlags |= RTLOGDEST_DEBUGGER | RTLOGDEST_STDOUT;
注意:
瀏覽 TracChangeset
來幫助您使用更動檢視器