Example #1
0
    bool InitDbgHelp()
    {
        static vmpi_spin_lock_t lock;
        static bool inited = false;

        // We must hold the lock for the entire initialization process:
        //  - if we set inited to true and Release the lock then other
        //    threads may forge ahead without initialization having occured
        //  - if we leave it false and Release then other threads
        //    may try to perform initialization as well.
        MMGC_LOCK(lock);
        if(!inited) {
#ifndef UNDER_CE
            if(!g_DbgHelpDll.m_SymInitialize ||
                !(*g_DbgHelpDll.m_SymInitialize)(GetCurrentProcess(), NULL, true)) {
                    LPVOID lpMsgBuf;
                    if(FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
                        NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
                        (LPTSTR) &lpMsgBuf, 0, NULL ))
                    {
                        GCAssertMsg(false, "See lpMsgBuf");
                        LocalFree(lpMsgBuf);
                    }
                    return false;
            }
#endif // ifn UNDER_CE
            inited = true;
        }
        return true;
    }
Example #2
0
 void FixedMalloc::AddToLargeObjectTracker(const void* item)
 {
     if (!m_heap->config.checkFixedMemory())
         return;
     
     LargeObject* lo = (LargeObject*)Alloc(sizeof(LargeObject));
     lo->item = item;
     MMGC_LOCK(m_largeObjectLock);
     lo->next = largeObjects;
     largeObjects = lo;
 }
Example #3
0
 void FixedMalloc::RemoveFromLargeObjectTracker(const void* item)
 {
     if (!m_heap->config.checkFixedMemory())
         return;
     
     void *loToFree=NULL;
     {
         MMGC_LOCK(m_largeObjectLock);
         LargeObject *lo, *prev;
         for ( prev=NULL, lo=largeObjects ; lo != NULL ; prev=lo, lo=lo->next ) {
             if (lo->item == item) {
                 if (prev != NULL)
                     prev->next = lo->next;
                 else
                     largeObjects = lo->next;
                 loToFree = lo;
                 break;
             }
         }
     }
     if(loToFree)
         Free(loToFree);
 }
Example #4
0
    void FixedMalloc::GetUsageInfo(size_t& totalAskSize, size_t& totalAllocated)
    {
        totalAskSize = 0;
        totalAllocated = 0;
        for (int i=0; i<kNumSizeClasses; i++) {
            size_t allocated = 0;
            size_t ask = 0;
            m_allocs[i].GetUsageInfo(ask, allocated);
            totalAskSize += ask;
            totalAllocated += allocated;
        }

#ifdef MMGC_MEMORY_PROFILER
        {
            MMGC_LOCK(m_largeAllocInfoLock);
            totalAskSize += totalAskSizeLargeAllocs;
        }
#endif

        // Not entirely accurate, assumes large allocations using all of
        // the last block (large ask size not stored).
        totalAllocated += (GetNumLargeBlocks() * GCHeap::kBlockSize);
    }
Example #5
0
    void FixedMalloc::EnsureFixedMallocMemory(const void* item)
    {
        // For a discussion of this flag, see bugzilla 564878.
        if (!m_heap->config.checkFixedMemory())
            return;
        
        for (int i=0; i<kNumSizeClasses; i++)
            if (m_allocs[i].QueryOwnsObject(item))
                return;

#ifdef AVMPLUS_SAMPLER
        if (m_heap->SafeSize(GetRealPointer(item)) != (size_t)-1)
            return;
#else
        {
            MMGC_LOCK(m_largeObjectLock);
            for ( LargeObject* lo=largeObjects; lo != NULL ; lo=lo->next)
                if (lo->item == item)
                    return;
        }
#endif

        GCAssertMsg(false, "Trying to delete an object with FixedMalloc::Free that was not allocated with FixedMalloc::Alloc");
    }