VirtualBox

Changeset 15505 in vbox for trunk


Ignore:
Timestamp:
Dec 15, 2008 2:36:30 PM (16 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
40984
Message:

SUPDrv,INTNet: Heads up! SupDrv version bumped. Added SUPR0ObjAddRefEx for dealing with the handle table callback which occurs while owning a spinlock. Normally SUPR0ObjAddRef[Ex] would always allocate a usage record, which means RTMemAlloc, but this is a bad idea when inside a spinlock. SUPR0ObjAddRefEx sports an additional parameter indicating whether it is allowed block or not.

Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/sup.h

    r15397 r15505  
    839839SUPR0DECL(void *) SUPR0ObjRegister(PSUPDRVSESSION pSession, SUPDRVOBJTYPE enmType, PFNSUPDRVDESTRUCTOR pfnDestructor, void *pvUser1, void *pvUser2);
    840840SUPR0DECL(int) SUPR0ObjAddRef(void *pvObj, PSUPDRVSESSION pSession);
     841SUPR0DECL(int) SUPR0ObjAddRefEx(void *pvObj, PSUPDRVSESSION pSession, bool fNoBlocking);
    841842SUPR0DECL(int) SUPR0ObjRelease(void *pvObj, PSUPDRVSESSION pSession);
    842843SUPR0DECL(int) SUPR0ObjVerifyAccess(void *pvObj, PSUPDRVSESSION pSession, const char *pszObjName);
  • trunk/src/VBox/Devices/Network/SrvIntNetR0.cpp

    r14695 r15505  
    537537DECLINLINE(int) intnetR0IfRetain(PINTNETIF pIf, PSUPDRVSESSION pSession)
    538538{
    539     int rc = SUPR0ObjAddRef(pIf->pvObj, pSession);
     539    int rc = SUPR0ObjAddRefEx(pIf->pvObj, pSession, true /* fNoBlocking */);
    540540    AssertRCReturn(rc, rc);
    541541    return VINF_SUCCESS;
     
    20012001        ||  cbPacket < cbIpHdr + RTNETUDP_MIN_LEN + RTNETBOOTP_DHCP_MIN_LEN) /* Min DHCP packet len */
    20022002        return;
    2003  
     2003
    20042004    size_t cbUdpPkt = cbPacket - cbIpHdr;
    20052005    PCRTNETUDP pUdpHdr = (PCRTNETUDP)((uintptr_t)pIpHdr + cbIpHdr);
  • trunk/src/VBox/Devices/Network/testcase/tstIntNetR0.cpp

    r14831 r15505  
    130130}
    131131
    132 INTNETR3DECL(int) SUPR0ObjAddRef(void *pvObj, PSUPDRVSESSION pSession)
     132INTNETR3DECL(int) SUPR0ObjAddRefEx(void *pvObj, PSUPDRVSESSION pSession, bool fNoBlocking)
    133133{
    134134    if (pSession != g_pSession)
     
    141141    ASMAtomicIncU32(&pRef->cRefs);
    142142    return VINF_SUCCESS;
     143}
     144
     145INTNETR3DECL(int) SUPR0ObjAddRef(void *pvObj, PSUPDRVSESSION pSession)
     146{
     147    return SUPR0ObjAddRefEx(pvObj, pSession, false);
    143148}
    144149
  • trunk/src/VBox/HostDrivers/Support/SUPDrv.c

    r15212 r15505  
    161161DECLASM(void *) UNWIND_WRAP(SUPR0ObjRegister)(PSUPDRVSESSION pSession, SUPDRVOBJTYPE enmType, PFNSUPDRVDESTRUCTOR pfnDestructor, void *pvUser1, void *pvUser2);
    162162DECLASM(int)    UNWIND_WRAP(SUPR0ObjAddRef)(void *pvObj, PSUPDRVSESSION pSession);
     163DECLASM(int)    UNWIND_WRAP(SUPR0ObjAddRefEx)(void *pvObj, PSUPDRVSESSION pSession, bool fNoPreempt);
    163164DECLASM(int)    UNWIND_WRAP(SUPR0ObjRelease)(void *pvObj, PSUPDRVSESSION pSession);
    164165DECLASM(int)    UNWIND_WRAP(SUPR0ObjVerifyAccess)(void *pvObj, PSUPDRVSESSION pSession, const char *pszObjName);
     
    296297    { "SUPR0ObjRegister",                       (void *)UNWIND_WRAP(SUPR0ObjRegister) },
    297298    { "SUPR0ObjAddRef",                         (void *)UNWIND_WRAP(SUPR0ObjAddRef) },
     299    { "SUPR0ObjAddRefEx",                       (void *)UNWIND_WRAP(SUPR0ObjAddRefEx) },
    298300    { "SUPR0ObjRelease",                        (void *)UNWIND_WRAP(SUPR0ObjRelease) },
    299301    { "SUPR0ObjVerifyAccess",                   (void *)UNWIND_WRAP(SUPR0ObjVerifyAccess) },
     
    17251727    /*
    17261728     * Allocate the usage record.
    1727      * (We keep freed usage records around to simplify SUPR0ObjAddRef().)
     1729     * (We keep freed usage records around to simplify SUPR0ObjAddRefEx().)
    17281730     */
    17291731    RTSpinlockAcquire(pDevExt->Spinlock, &SpinlockTmp);
     
    17791781SUPR0DECL(int) SUPR0ObjAddRef(void *pvObj, PSUPDRVSESSION pSession)
    17801782{
     1783    return SUPR0ObjAddRefEx(pvObj, pSession, false /* fNoBlocking */);
     1784}
     1785
     1786
     1787/**
     1788 * Increment the reference counter for the object associating the reference
     1789 * with the specified session.
     1790 *
     1791 * @returns IPRT status code.
     1792 * @retval  VERR_TRY_AGAIN if fNoBlocking was set and a new usage record
     1793 *          couldn't be allocated. (If you see this you're not doing the right
     1794 *          thing and it won't ever work reliably.)
     1795 *
     1796 * @param   pvObj           The identifier returned by SUPR0ObjRegister().
     1797 * @param   pSession        The session which is referencing the object.
     1798 * @param   fNoBlocking     Set if it's not OK to block. Never try to make the
     1799 *                          first reference to an object in a session with this
     1800 *                          argument set.
     1801 *
     1802 * @remarks The caller should not own any spinlocks and must carefully protect
     1803 *          itself against potential race with the destructor so freed memory
     1804 *          isn't accessed here.
     1805 */
     1806SUPR0DECL(int) SUPR0ObjAddRefEx(void *pvObj, PSUPDRVSESSION pSession, bool fNoBlocking)
     1807{
    17811808    RTSPINLOCKTMP   SpinlockTmp = RTSPINLOCKTMP_INITIALIZER;
    17821809    PSUPDRVDEVEXT   pDevExt     = pSession->pDevExt;
    17831810    PSUPDRVOBJ      pObj        = (PSUPDRVOBJ)pvObj;
     1811    int             rc          = VINF_SUCCESS;
    17841812    PSUPDRVUSAGE    pUsagePre;
    17851813    PSUPDRVUSAGE    pUsage;
     
    18071835
    18081836    /*
    1809      * Preallocate the usage record.
     1837     * Preallocate the usage record if we can.
    18101838     */
    18111839    pUsagePre = pDevExt->pUsageFree;
    18121840    if (pUsagePre)
    18131841        pDevExt->pUsageFree = pUsagePre->pNext;
    1814     else
     1842    else if (!fNoBlocking)
    18151843    {
    18161844        RTSpinlockRelease(pDevExt->Spinlock, &SpinlockTmp);
     
    18201848
    18211849        RTSpinlockAcquire(pDevExt->Spinlock, &SpinlockTmp);
     1850        if (RT_UNLIKELY(pObj->u32Magic != SUPDRVOBJ_MAGIC))
     1851        {
     1852            RTSpinlockRelease(pDevExt->Spinlock, &SpinlockTmp);
     1853
     1854            AssertMsgFailed(("pvObj=%p magic=%#x\n", pvObj, pObj->u32Magic));
     1855            return VERR_WRONG_ORDER;
     1856        }
    18221857    }
    18231858
     
    18381873    if (pUsage)
    18391874        pUsage->cUsage++;
    1840     else
     1875    else if (pUsagePre)
    18411876    {
    18421877        /* create a new session record. */
     
    18491884        pUsagePre = NULL;
    18501885    }
     1886    else
     1887    {
     1888        pObj->cUsage--;
     1889        rc = VERR_TRY_AGAIN;
     1890    }
    18511891
    18521892    /*
     
    18611901    RTSpinlockRelease(pDevExt->Spinlock, &SpinlockTmp);
    18621902
    1863     return VINF_SUCCESS;
     1903    return rc;
    18641904}
    18651905
     
    19722012}
    19732013
     2014
    19742015/**
    19752016 * Verifies that the current process can access the specified object.
  • trunk/src/VBox/HostDrivers/Support/SUPDrvIOC.h

    r14901 r15505  
    188188 *            and renaming the related IOCtls too.
    189189 */
    190 #define SUPDRV_IOC_VERSION                              0x000a0007
     190#define SUPDRV_IOC_VERSION                              0x000a0008
    191191
    192192/** SUP_IOCTL_COOKIE. */
  • trunk/src/VBox/HostDrivers/Support/SUPLib.cpp

    r15351 r15505  
    261261        CookieReq.u.In.u32ReqVersion = SUPDRV_IOC_VERSION;
    262262        const uint32_t MinVersion = (SUPDRV_IOC_VERSION & 0xffff0000) == 0x000a0000
    263                                   ? 0x000a0007
     263                                  ? 0x000a0008
    264264                                  :  SUPDRV_IOC_VERSION & 0xffff0000;
    265265        CookieReq.u.In.u32MinVersion = MinVersion;
     
    389389        { "SUPR0ObjRegister",                       0xefef0000 },
    390390        { "SUPR0ObjAddRef",                         0xefef0001 },
     391        { "SUPR0ObjAddRefEx",                       0xefef0001 },
    391392        { "SUPR0ObjRelease",                        0xefef0002 },
    392393        { "SUPR0ObjVerifyAccess",                   0xefef0003 },
  • trunk/src/VBox/HostDrivers/Support/SUPR0.def

    r14901 r15505  
    4141    SUPR0ObjRegister
    4242    SUPR0ObjAddRef
     43    SUPR0ObjAddRefEx
    4344    SUPR0ObjRelease
    4445    SUPR0ObjVerifyAccess
  • trunk/src/VBox/HostDrivers/Support/win/SUPDrvA-win.asm

    r14825 r15505  
    6060NtWrapDyn2DrvFunctionWith5Params       supdrvNtWrap, SUPR0ObjRegister
    6161NtWrapDyn2DrvFunctionWithAllRegParams  supdrvNtWrap, SUPR0ObjAddRef
     62NtWrapDyn2DrvFunctionWithAllRegParams  supdrvNtWrap, SUPR0ObjAddRefEx
    6263NtWrapDyn2DrvFunctionWithAllRegParams  supdrvNtWrap, SUPR0ObjRelease
    6364NtWrapDyn2DrvFunctionWithAllRegParams  supdrvNtWrap, SUPR0ObjVerifyAccess
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