third_party/virtualbox/src/VBox/VMM/VMMR3/MMHeap.cpp
/**
 * Allocate and initialize a heap structure and it's associated substructures.
 *
 * @returns VBox status code.
 * @param   pUVM    Pointer to the user mode VM structure.
 * @param   ppHeap  Where to store the heap pointer.
 */
Allocate and initialize a heap structure and it's associated substructures.
@returns VBox status code.
@param   pUVM    Pointer to the user mode VM structure.
@param   ppHeap  Where to store the heap pointer.
Allocate and initialize a heap structure and it ' s associated substructures . @returns VBox status code . @param pUVM Pointer to the user mode VM structure . @param ppHeap Where to store the heap pointer .
int mmR3HeapCreateU(PUVM pUVM, PMMHEAP *ppHeap)
{
    PMMHEAP pHeap = (PMMHEAP)RTMemAllocZ(sizeof(MMHEAP) + sizeof(MMHEAPSTAT));
    if (pHeap)
    {
        int rc = RTCritSectInit(&pHeap->Lock);
        if (RT_SUCCESS(rc))
        {
            pHeap->pUVM = pUVM;
            pHeap->Stat.pHeap = pHeap;
#ifdef MMR3HEAP_WITH_STATISTICS
            PMMHEAPSTAT pStat = &pHeap->Stat;
            STAMR3RegisterU(pUVM, &pStat->cAllocations,   STAMTYPE_U64, STAMVISIBILITY_ALWAYS, "/MM/R3Heap/cAllocations",     STAMUNIT_CALLS, "Number or MMR3HeapAlloc() calls.");
            STAMR3RegisterU(pUVM, &pStat->cReallocations, STAMTYPE_U64, STAMVISIBILITY_ALWAYS, "/MM/R3Heap/cReallocations",   STAMUNIT_CALLS, "Number of MMR3HeapRealloc() calls.");
            STAMR3RegisterU(pUVM, &pStat->cFrees,         STAMTYPE_U64, STAMVISIBILITY_ALWAYS, "/MM/R3Heap/cFrees",           STAMUNIT_CALLS, "Number of MMR3HeapFree() calls.");
            STAMR3RegisterU(pUVM, &pStat->cFailures,      STAMTYPE_U64, STAMVISIBILITY_ALWAYS, "/MM/R3Heap/cFailures",        STAMUNIT_COUNT, "Number of failures.");
            STAMR3RegisterU(pUVM, &pStat->cbCurAllocated, sizeof(pStat->cbCurAllocated) == sizeof(uint32_t) ? STAMTYPE_U32 : STAMTYPE_U64,
                                                                        STAMVISIBILITY_ALWAYS, "/MM/R3Heap/cbCurAllocated",   STAMUNIT_BYTES, "Number of bytes currently allocated.");
            STAMR3RegisterU(pUVM, &pStat->cbAllocated,    STAMTYPE_U64, STAMVISIBILITY_ALWAYS, "/MM/R3Heap/cbAllocated",      STAMUNIT_BYTES, "Total number of bytes allocated.");
            STAMR3RegisterU(pUVM, &pStat->cbFreed,        STAMTYPE_U64, STAMVISIBILITY_ALWAYS, "/MM/R3Heap/cbFreed",          STAMUNIT_BYTES, "Total number of bytes freed.");
#endif
            *ppHeap = pHeap;
            return VINF_SUCCESS;
        }
        AssertRC(rc);
        RTMemFree(pHeap);
    }
    AssertMsgFailed(("failed to allocate heap structure\n"));
    return VERR_NO_MEMORY;
}
int mmR3HeapCreateU ( PUVM pUVM , PMMHEAP * ppHeap ) { PMMHEAP pHeap = ( PMMHEAP ) RTMemAllocZ ( sizeof ( MMHEAP ) + sizeof ( MMHEAPSTAT ) ) ; if ( pHeap ) { int rc = RTCritSectInit ( & pHeap -> Lock ) ; if ( RT_SUCCESS ( rc ) ) { pHeap -> pUVM = pUVM ; pHeap -> Stat . pHeap = pHeap ; #ifdef MMR3HEAP_WITH_STATISTICS PMMHEAPSTAT pStat = & pHeap -> Stat ; STAMR3RegisterU ( pUVM , & pStat -> cAllocations , STAMTYPE_U64 , STAMVISIBILITY_ALWAYS , " " , STAMUNIT_CALLS , " " ) ; STAMR3RegisterU ( pUVM , & pStat -> cReallocations , STAMTYPE_U64 , STAMVISIBILITY_ALWAYS , " " , STAMUNIT_CALLS , " " ) ; STAMR3RegisterU ( pUVM , & pStat -> cFrees , STAMTYPE_U64 , STAMVISIBILITY_ALWAYS , " " , STAMUNIT_CALLS , " " ) ; STAMR3RegisterU ( pUVM , & pStat -> cFailures , STAMTYPE_U64 , STAMVISIBILITY_ALWAYS , " " , STAMUNIT_COUNT , " " ) ; STAMR3RegisterU ( pUVM , & pStat -> cbCurAllocated , sizeof ( pStat -> cbCurAllocated ) == sizeof ( uint32_t ) ? STAMTYPE_U32 : STAMTYPE_U64 , STAMVISIBILITY_ALWAYS , " " , STAMUNIT_BYTES , " " ) ; STAMR3RegisterU ( pUVM , & pStat -> cbAllocated , STAMTYPE_U64 , STAMVISIBILITY_ALWAYS , " " , STAMUNIT_BYTES , " " ) ; STAMR3RegisterU ( pUVM , & pStat -> cbFreed , STAMTYPE_U64 , STAMVISIBILITY_ALWAYS , " " , STAMUNIT_BYTES , " " ) ; #endif * ppHeap = pHeap ; return VINF_SUCCESS ; } AssertRC ( rc ) ; RTMemFree ( pHeap ) ; } AssertMsgFailed ( ( " \n " ) ) ; return VERR_NO_MEMORY ; }
Allocate and initialize a heap structure and it's associated substructures.
Allocate and initialize a heap structure and it ' s associated substructures .
/*
             * Initialize the global stat record.
             */