VirtualBox

Changeset 10556 in vbox


Ignore:
Timestamp:
Jul 11, 2008 10:02:09 PM (17 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
33248
Message:

SUPR0ObjAddRef: Deal with destruction race in a predictable manner (return VERR_WRONG_ORDER). (The caller must make some effort too.)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostDrivers/Support/SUPDrv.c

    r10387 r10556  
    14821482 * @param   pvObj           The identifier returned by SUPR0ObjRegister().
    14831483 * @param   pSession        The session which is referencing the object.
     1484 *
     1485 * @remarks The caller should not own any spinlocks and must carefully protect
     1486 *          itself against potential race with the destructor so freed memory
     1487 *          isn't accessed here.
    14841488 */
    14851489SUPR0DECL(int) SUPR0ObjAddRef(void *pvObj, PSUPDRVSESSION pSession)
     
    14931497    /*
    14941498     * Validate the input.
     1499     * Be ready for the destruction race (someone might be stuck in the
     1500     * destructor waiting a lock we own).
    14951501     */
    14961502    AssertReturn(SUP_IS_SESSION_VALID(pSession), VERR_INVALID_PARAMETER);
    1497     AssertMsgReturn(VALID_PTR(pObj) && pObj->u32Magic == SUPDRVOBJ_MAGIC,
    1498                     ("Invalid pvObj=%p magic=%#x (exepcted %#x)\n", pvObj, pObj ? pObj->u32Magic : 0, SUPDRVOBJ_MAGIC),
     1503    AssertPtrReturn(pObj, VERR_INVALID_POINTER);
     1504    AssertMsgReturn(pObj->u32Magic == SUPDRVOBJ_MAGIC || pObj->u32Magic == SUPDRVOBJ_MAGIC + 1,
     1505                    ("Invalid pvObj=%p magic=%#x (expected %#x or %#x)\n", pvObj, pObj->u32Magic, SUPDRVOBJ_MAGIC, SUPDRVOBJ_MAGIC + 1),
    14991506                    VERR_INVALID_PARAMETER);
    15001507
     1508    RTSpinlockAcquire(pDevExt->Spinlock, &SpinlockTmp);
     1509
     1510    if (RT_UNLIKELY(pObj->u32Magic != SUPDRVOBJ_MAGIC))
     1511    {
     1512        AssertMsg(pObj->u32Magic == SUPDRVOBJ_MAGIC + 1, ("pvObj=%p magic=%#x\n", pvObj, pObj->u32Magic));
     1513
     1514        RTSpinlockRelease(pDevExt->Spinlock, &SpinlockTmp);
     1515        return VERR_WRONG_ORDER;
     1516    }
     1517
    15011518    /*
    15021519     * Preallocate the usage record.
    15031520     */
    1504     RTSpinlockAcquire(pDevExt->Spinlock, &SpinlockTmp);
    1505 
    15061521    pUsagePre = pDevExt->pUsageFree;
    15071522    if (pUsagePre)
     
    15131528        if (!pUsagePre)
    15141529            return VERR_NO_MEMORY;
     1530
    15151531        RTSpinlockAcquire(pDevExt->Spinlock, &SpinlockTmp);
    15161532    }
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