Example #1
0
void CordbAppDomain::AddToTypeList(CordbBase *pObject)
{
    INTERNAL_API_ENTRY(this);
    _ASSERTE(pObject != NULL);
    RSLockHolder lockHolder(GetProcess()->GetProcessLock());
    this->m_TypeNeuterList.Add(GetProcess(), pObject);
}
Example #2
0
    void _RegisterConcRTEventTracing()
    {
#if defined(_ONECORE) || defined(_KERNELX)
        g_pEtw = NULL;
#else
        // Initialize ETW dynamically, and only once, to avoid a static dependency on Advapi32.dll.
        _StaticLock::_Scoped_lock lockHolder(Etw::s_lock);

        if (g_pEtw == NULL)
        {
            g_pEtw = _concrt_new Etw();

            static TRACE_GUID_REGISTRATION eventGuidRegistration[] = {
                { &Concurrency::ConcRTEventGuid, NULL },
                { &Concurrency::SchedulerEventGuid, NULL },
                { &Concurrency::ScheduleGroupEventGuid, NULL },
                { &Concurrency::ContextEventGuid, NULL },
                { &Concurrency::ChoreEventGuid, NULL },
                { &Concurrency::LockEventGuid, NULL },
                { &Concurrency::ResourceManagerEventGuid, NULL }
            };

            ULONG eventGuidCount = sizeof eventGuidRegistration / sizeof eventGuidRegistration[0];

            g_pEtw->RegisterGuids(Concurrency::details::ControlCallback, &ConcRT_ProviderGuid, eventGuidCount, eventGuidRegistration, &g_ConcRTPRoviderHandle);
        }
#endif // defined(_ONECORE) || defined(_KERNELX)
    }
Example #3
0
void CordbAppDomain::PrepopulateAssembliesOrThrow()
{
    INTERNAL_API_ENTRY(GetProcess());

    RSLockHolder lockHolder(GetProcess()->GetProcessLock());

    if (!GetProcess()->IsDacInitialized())
    {
        return;
    }

    // DD-primitive  that invokes a callback.   
    GetProcess()->GetDAC()->EnumerateAssembliesInAppDomain(
        this->m_vmAppDomain,
        CordbAppDomain::AssemblyEnumerationCallback,
        this); // user data
}
Example #4
0
// Gets a CordbModule that has the given metadata interface
//
// Arguments:
//     pIMetaData - metadata interface
//
// Returns:
//     CordbModule whose associated metadata matches the metadata interface provided here
//     Throws on error. Returns non-null
//
CordbModule * CordbAppDomain::GetModuleFromMetaDataInterface(IUnknown *pIMetaData)
{
    HRESULT hr = S_OK;
        
    RSExtSmartPtr<IMetaDataImport> pImport;
    RSLockHolder lockHolder(GetProcess()->GetProcessLock());  // need for module enumeration      

    // Grab the interface we need...
    hr = pIMetaData->QueryInterface(IID_IMetaDataImport, (void**)&pImport);
    if (FAILED(hr))
    {
        ThrowHR(E_INVALIDARG);
    }

    // Get the mvid of the given module.
    GUID matchMVID;
    hr = pImport->GetScopeProps(NULL, 0, 0, &matchMVID);
    IfFailThrow(hr);

    CordbModule* pModule;
    HASHFIND findmodule;

    PrepopulateModules();

    for (pModule =  m_modules.FindFirst(&findmodule);
         pModule != NULL;
         pModule =  m_modules.FindNext(&findmodule))
    {
        IMetaDataImport * pImportCurrent = pModule->GetMetaDataImporter(); // throws
        _ASSERTE(pImportCurrent != NULL);
        
        // Get the mvid of this module
        GUID MVID;
        hr = pImportCurrent->GetScopeProps(NULL, 0, 0, &MVID);
        IfFailThrow(hr);

        if (MVID == matchMVID)
        {
            return pModule;
        }        
    }

    ThrowHR(E_INVALIDARG);
}
    bool AuthzManagerExternalStateMongos::tryAcquireAuthzUpdateLock(const StringData& why) {
        boost::lock_guard<boost::mutex> lkLocal(_distLockGuard);
        if (_authzDataUpdateLock.get()) {
            return false;
        }

        // Temporarily put into an auto_ptr just in case there is an exception thrown during
        // lock acquisition.
        std::auto_ptr<ScopedDistributedLock> lockHolder(new ScopedDistributedLock(
                configServer.getConnectionString(), "authorizationData"));
        lockHolder->setLockMessage(why.toString());

        std::string errmsg;
        if (!lockHolder->acquire(_authzUpdateLockAcquisitionTimeoutMillis, &errmsg)) {
            warning() <<
                    "Error while attempting to acquire distributed lock for user modification: " <<
                    errmsg << endl;
            return false;
        }
        _authzDataUpdateLock.reset(lockHolder.release());
        return true;
    }
HeapTimer::HeapTimer(VM* vm)
    : m_vm(vm)
{
    RefPtr<JSLock> lockProtector(&m_vm->apiLock());
    m_timer.initialize("[JSC] HeapTimer",
        [this, lockProtector] {
            auto& apiLock = *lockProtector;
            apiLock.lock();

            VM* vm = apiLock.vm();
            if (!vm) {
                apiLock.unlock();
                return;
            }

            {
                JSLockHolder lockHolder(vm);
                doWork();
            }

            apiLock.unlock();
        });
}
Example #7
0
BOOL PAL_VirtualUnwindOutOfProc(CONTEXT *context, 
                                KNONVOLATILE_CONTEXT_POINTERS *contextPointers, 
                                DWORD pid, 
                                ReadMemoryWordCallback readMemCallback)
{
    // This function can be executed only by one thread at a time. 
    // The reason for this is that we need to pass context and read mem function to libunwind callbacks
    // but "arg" is already used by the pointer returned from _UPT_create(). 
    // So we resort to using global variables and a lock.
    struct Lock 
    {
        CRITICAL_SECTION cs;
        Lock()
        {        
            // ctor of a static variable is a thread-safe way to initialize critical section exactly once (clang,gcc)
            InitializeCriticalSection(&cs);
        }
    };
    struct LockHolder
    {
        CRITICAL_SECTION *cs;
        LockHolder(CRITICAL_SECTION *cs)
        {
            this->cs = cs;
            EnterCriticalSection(cs);
        }

        ~LockHolder()
        {
            LeaveCriticalSection(cs);
            cs = NULL;
        }
    };    
    static Lock lock;
    LockHolder lockHolder(&lock.cs);

    int st;
    unw_context_t unwContext;
    unw_cursor_t cursor;
    unw_addr_space_t addrSpace = 0;
    void *libunwindUptPtr = NULL;
    BOOL result = FALSE;

    LibunwindCallbacksInfo.Context = context;
    LibunwindCallbacksInfo.readMemCallback = readMemCallback;
    WinContextToUnwindContext(context, &unwContext);
    addrSpace = unw_create_addr_space(&unwind_accessors, 0);
    libunwindUptPtr = _UPT_create(pid);
    st = unw_init_remote(&cursor, addrSpace, libunwindUptPtr);
    if (st < 0)
    {
        result = FALSE;
        goto Exit;
    }

    st = unw_step(&cursor);
    if (st < 0)
    {
        result = FALSE;
        goto Exit;
    }

    UnwindContextToWinContext(&cursor, context);

    if (contextPointers != NULL)
    {
        GetContextPointers(&cursor, &unwContext, contextPointers);
    }
    result = TRUE;

Exit:
    if (libunwindUptPtr != nullptr) 
    {
        _UPT_destroy(libunwindUptPtr);
    }
    if (addrSpace != 0) 
    {
        unw_destroy_addr_space(addrSpace);
    }    
    return result;
}
size_t ExecutableAllocator::committedByteCount()
{
    SpinLockHolder lockHolder(&spinlock);
    return committedBytesCount;
}