VirtualBox

Changeset 19663 in vbox for trunk/src/VBox/VMM/VMMAll


Ignore:
Timestamp:
May 13, 2009 3:06:00 PM (16 years ago)
Author:
vboxsync
Message:

Protect the MM hypervisor heap with a critical section.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/VMMAll/MMAllHyper.cpp

    r18287 r19663  
    152152#endif
    153153
     154/**
     155 * Locks the hypervisor heap.
     156 * This might call back to Ring-3 in order to deal with lock contention in GC and R3.
     157 *
     158 * @param   pVM     The VM handle.
     159 */
     160VMMDECL(int) MMHyperLock(PVM pVM)
     161{
     162    PMMHYPERHEAP pHeap = pVM->mm.s.CTX_SUFF(pHyperHeap);
     163
     164#ifdef IN_RING3
     165    if (!PDMCritSectIsInitialized(&pHeap->Lock))
     166        return VINF_SUCCESS;     /* early init */
     167
     168    int rc = PDMCritSectEnter(&pHeap->Lock, VERR_INTERNAL_ERROR);
     169#else
     170    Assert(PDMCritSectIsInitialized(&pHeap->Lock));
     171    int rc = PDMCritSectEnter(&pHeap->Lock, VERR_GENERAL_FAILURE);
     172    if (rc == VERR_GENERAL_FAILURE)
     173    {
     174# ifdef IN_RC
     175        rc = VMMGCCallHost(pVM, VMMCALLHOST_MMHYPER_LOCK, 0);
     176# else
     177        rc = VMMR0CallHost(pVM, VMMCALLHOST_MMHYPER_LOCK, 0);
     178# endif
     179    }
     180#endif
     181    AssertRC(rc);
     182    return rc;
     183}
     184
     185
     186/**
     187 * Unlocks the hypervisor heap.
     188 *
     189 * @param   pVM     The VM handle.
     190 */
     191VMMDECL(void) MMHyperUnlock(PVM pVM)
     192{
     193    PMMHYPERHEAP pHeap = pVM->mm.s.CTX_SUFF(pHyperHeap);
     194
     195#ifdef IN_RING3
     196    if (!PDMCritSectIsInitialized(&pHeap->Lock))
     197        return;     /* early init */
     198#endif
     199    Assert(PDMCritSectIsInitialized(&pHeap->Lock));
     200    PDMCritSectLeave(&pHeap->Lock);
     201}
    154202
    155203/**
     
    166214 * @param   ppv         Where to store the address to the allocated
    167215 *                      memory.
    168  * @remark  This is assumed not to be used at times when serialization is required.
    169  */
    170 VMMDECL(int) MMHyperAlloc(PVM pVM, size_t cb, unsigned uAlignment, MMTAG enmTag, void **ppv)
     216 */
     217static int mmHyperAllocInternal(PVM pVM, size_t cb, unsigned uAlignment, MMTAG enmTag, void **ppv)
    171218{
    172219    AssertMsg(cb >= 8, ("Hey! Do you really mean to allocate less than 8 bytes?! cb=%d\n", cb));
     
    282329}
    283330
    284 
     331/**
     332 * Wrapper for mmHyperAllocInternal
     333 */
     334VMMDECL(int) MMHyperAlloc(PVM pVM, size_t cb, unsigned uAlignment, MMTAG enmTag, void **ppv)
     335{
     336    int rc;
     337
     338    rc = MMHyperLock(pVM);
     339    AssertRCReturn(rc, rc);
     340
     341    rc = mmHyperAllocInternal(pVM, cb, uAlignment, enmTag, ppv);
     342
     343    MMHyperUnlock(pVM);
     344    return rc;
     345}
    285346
    286347/**
     
    705766 * @remark  Try avoid free hyper memory.
    706767 */
    707 VMMDECL(int) MMHyperFree(PVM pVM, void *pv)
     768static int mmHyperFreeInternal(PVM pVM, void *pv)
    708769{
    709770    Log2(("MMHyperFree: pv=%p\n", pv));
     
    758819                    ("%p: u32Magic=%#x\n", pv, pHeap->u32Magic),
    759820                    VERR_INVALID_POINTER);
    760 Assert(pHeap == pVM->mm.s.CTX_SUFF(pHyperHeap));
     821    Assert(pHeap == pVM->mm.s.CTX_SUFF(pHyperHeap));
    761822
    762823    /* Some more verifications using additional info from pHeap. */
     
    844905#endif
    845906
     907    return rc;
     908}
     909
     910
     911/**
     912 * Wrapper for mmHyperFreeInternal
     913 */
     914VMMDECL(int) MMHyperFree(PVM pVM, void *pv)
     915{
     916    int rc;
     917
     918    rc = MMHyperLock(pVM);
     919    AssertRCReturn(rc, rc);
     920
     921    rc = mmHyperFreeInternal(pVM, pv);
     922
     923    MMHyperUnlock(pVM);
    846924    return rc;
    847925}
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