Esempio n. 1
0
//=============================================================================================
// Used to initialize the per-thread ClrDebugState. This is called once per thread (with
// possible exceptions for OOM scenarios.)
//
// No matter what, this function will not return NULL. If it can't do its job because of OOM reasons,
// it will return a pointer to &gBadClrDebugState which effectively disables contracts for
// this thread.
//=============================================================================================
ClrDebugState *CLRInitDebugState()
{
    // workaround!
    //
    // The existing Fls apis didn't provide the support we need and adding support cleanly is
    // messy because of the brittleness of IExecutionEngine.
    //
    // To understand this function, you need to know that the Fls routines have special semantics
    // for the TlsIdx_ClrDebugState slot:
    //
    //  - FlsSetValue will never throw. If it fails due to OOM on creation of the slot storage,
    //    it will silently bail. Thus, we must do a confirming FlsGetValue before we can conclude
    //    that the SetValue succeeded.
    //
    //  - FlsAssociateCallback will not complain about multiple sets of the callback.
    //
    //  - The mscorwks implemention of FlsAssociateCallback will ignore the passed in value
    //    and use the version of FreeClrDebugState compiled into mscorwks. This is needed to
    //    avoid dangling pointer races on shutdown.


    // This is our global "bad" debug state that thread use when they OOM on CLRInitDebugState.
    // We really only need to initialize it once but initializing each time is convenient
    // and has low perf impact.
    static ClrDebugState gBadClrDebugState;
    gBadClrDebugState.ViolationMaskSet( AllViolation );
    // SO_INFRASTRUCTURE_CODE() Macro to remove SO infrastructure code during build
    SO_INFRASTRUCTURE_CODE(gBadClrDebugState.BeginSOTolerant();)