A
download appdomainstack.h
Language: C++
Copyright: (c) 2006 Microsoft Corporation. All rights reserved.
LOC: 190
Project Info
Shared Source Common Language Infrastructure(sscli20)
Server: Shared Source Common Language Infrastructure
Type: filesystem
...sscli20\sscli20\clr\src\vm\
   appdomain.cpp
   appdomain.hpp
   appdomain.inl
   appdomainhelper.cpp
   appdomainhelper.h
   appdomainnative.cpp
   appdomainnative.hpp
   appdomainstack.cpp
   appdomainstack.h
   appdomainstack.inl
   argslot.h
   array.cpp
   array.h
   assembly.cpp
   assembly.hpp
   assemblyname.cpp
   assemblyname.hpp
   assemblynative.cpp
   assemblynative.hpp
   assemblysink.cpp
   assemblysink.h
   assemblyspec.cpp
   assemblyspec.hpp
   binder.cpp
   binder.h
   cachelinealloc.cpp
   cachelinealloc.h
   ceeload.cpp
   ceeload.h
   ceeload.inl
   ceemain.cpp
   ceemain.h
   certificatecache.cpp
   certificatecache.h
   cgensys.h
   class.cpp
   class.h
   class.inl
   classloadlevel.h
   classnames.h
   clrex.cpp
   clrex.h
   clsload.cpp
   clsload.hpp
   clsload.inl
   codeman.cpp
   codeman.h
   codeman.inl
   comarrayhelpers.cpp
   comarrayhelpers.h
   comarrayinfo.cpp
   comarrayinfo.h
   comcallablewrapper.cpp
   comcallablewrapper.h
   comcurrency.cpp
   comcurrency.h
   comdatetime.cpp
   comdatetime.h
   comdecimal.cpp
   comdecimal.h
   comdelegate.cpp
   comdelegate.h
   comdynamic.cpp
   comdynamic.h
   comisolatedstorage.cpp
   comisolatedstorage.h
   commemoryfailpoint.cpp
   commemoryfailpoint.h
   commethodrental.cpp
   commethodrental.h
   commodule.cpp
   commodule.h
   common.cpp
   common.h
   comnumber.cpp
   comnumber.h
   comobject.cpp
   comobject.h
   comreflectioncache.hpp
   comreflectioncommon.cpp
   comreflectioncommon.h
   comstreams.cpp
   comstreams.h
   comstring.cpp
   comstring.h
   comstringbuffer.cpp
   comstringbuffer.h
   comstringcommon.h
   comsynchronizable.cpp
   comsynchronizable.h
   comsystem.cpp
   comsystem.h
   comthreadpool.cpp
   comthreadpool.h
   comutilnative.cpp
   comutilnative.h
   comvarargs.cpp
   comvarargs.h
   comvariant.cpp
   comvariant.h
   comwaithandle.cpp
   comwaithandle.h
   confighelper.cpp
   confighelper.h
   ...inedexecutionregion.cpp
   ...rainedexecutionregion.h
   context.h
   contexts.cpp
   contractimpl.cpp
   contractimpl.h
   corhost.cpp
   crossdomaincalls.cpp
   crossdomaincalls.h
   crst.cpp
   crst.h
   cryptapis.h
   ctxtcall.h
   customattribute.cpp
   customattribute.h
   custommarshalerinfo.cpp
   custommarshalerinfo.h
   dbginterface.h
   debugdebugger.cpp
   debugdebugger.h
   debughelp.cpp
   debuginfostore.cpp
   debuginfostore.h
   decodemd.cpp
   decodemd.h
   delegateinfo.h
   dllimport.cpp
   dllimport.h
   dllimportcallback.cpp
   dllimportcallback.h
   domainfile.cpp
   domainfile.h
   domainfile.inl
   dynamicmethod.cpp
   dynamicmethod.h
   ecall.cpp
   ecall.h
   ecmakey.h
   eecallconv.h
   eeconfig.cpp
   eeconfig.h
   eeconfigfactory.cpp
   eeconfigfactory.h
   eecontract.cpp
   eecontract.h
   eecontract.inl
   eedbginterface.h
   eedbginterfaceimpl.cpp
   eedbginterfaceimpl.h
   eedbginterfaceimpl.inl
   eehash.cpp
   eehash.h
   eemessagebox.cpp
   eemessagebox.h
   eepolicy.cpp
   eepolicy.h
   eeprofinterfaces.h
   eeprofinterfaces.inl
   ...rofinterfacewrapper.inl
   eetwain.cpp
   encee.h
   eventstore.cpp
   eventstore.hpp
   excep.cpp
   excep.h
   exceptmacros.h
   exinfo.cpp
   exinfo.h
   exstate.cpp
   exstate.h
   exstatecommon.h
   fcall.cpp
   fcall.h
   field.cpp
   field.h
   fieldmarshaler.cpp
   fieldmarshaler.h
   fjit_eetwain.cpp
   fjit_eetwain.h
   fptrstubs.cpp
   fptrstubs.h
   frames.cpp
   frames.h
   fusionbind.cpp
   fusioninit.cpp
   fusionsink.cpp
   fusionwrap.cpp
   fusionwrap.h
   gc.h
   gccommon.cpp
   gcdecode.cpp
   gcdesc.h
   gcee.cpp
   gceesvr.cpp
   gceewks.cpp
   gchost.cpp
   gcimpl.h
   gcscan.cpp
   gcscan.h
   gcsmp.cpp
   gcsmppriv.h
   gcsvr.cpp
   gcwks.cpp
   genericdict.cpp
   genericdict.h
   generics.cpp
   generics.h
   genmeth.cpp
   gmheap.cpp
   gmheap.hpp
   gms.h
   h2inc.pl
   handletable.cpp
   handletable.h
   handletable.inl
   handletablecache.cpp
   handletablecore.cpp
   handletablepriv.h
   handletablescan.cpp
   hash.cpp
   hash.h
   hostexecutioncontext.cpp
   hostexecutioncontext.h
   hosting.cpp
   hosting.h
   ibclogger.h
   ildump.h
   ilmarshalers.cpp
   ilmarshalers.h
   ilstubcache.cpp
   ilstubcache.h
   ilstubresolver.cpp
   ilstubresolver.h
   instmethhash.cpp
   instmethhash.h
   interopconverter.cpp
   interopconverter.h
   interoputil.cpp
   interoputil.h
   ...lidoverlappedwrappers.h
   invokeutil.cpp
   invokeutil.h
   jithelpers.cpp
   jitinterface.cpp
   jitinterface.h
   jitinterfacegen.cpp
   list.cpp
   list.h
   listlock.cpp
   listlock.h
   listlock.inl
   makefile.inc
   managedmdimport.cpp
   managedmdimport.hpp
   marshaler.h
   marshalnative.cpp
   marshalnative.h
   mdaassistants.h
   mdaassistantsptr.h
   memberload.cpp
   memberload.h
   message.cpp
   message.h
   metasig.h
   method.cpp
   method.hpp
   method.inl
   methodimpl.cpp
   methodimpl.h
   methoditer.cpp
   methoditer.h
   methodtable.cpp
   methodtable.h
   methodtable.inl
   ml.cpp
   ml.h
   mlcache.cpp
   mlcache.h
   mlgen.cpp
   mlgen.h
   mlinfo.cpp
   mlinfo.h
   mlopdef.h
   mscorlib.h
   mtypes.h
   namespace.h
   nativeoverlapped.cpp
   nativeoverlapped.h
   newcompressedstack.cpp
   newcompressedstack.h
   nsenums.h
   object.cpp
   object.h
   object.inl
   objectclone.cpp
   objectclone.h
   objecthandle.cpp
   objecthandle.h
   objectlist.cpp
   objectlist.h
   olevariant.cpp
   olevariant.h
   pefile.cpp
   pefile.h
   pefile.inl
   peimage.cpp
   peimage.h
   peimage.inl
   peimagelayout.cpp
   peimagelayout.h
   peimagelayout.inl
   pendingload.cpp
   pendingload.h
   precode.cpp
   precode.h
   prestub.cpp
   proftoeeinterfaceimpl.cpp
   proftoeeinterfaceimpl.h
   reflectclasswriter.cpp
   reflectclasswriter.h
   reflectioninvocation.cpp
   reflectioninvocation.h
   remoting.cpp
   remoting.h
   rexcep.h
   runtimeexceptionkind.h
   runtimehandles.cpp
   runtimehandles.h
   rwlock.cpp
   rwlock.h
   safehandle.cpp
   security.h
   security.inl
   securityattributes.cpp
   securityattributes.h
   securityconfig.cpp
   securityconfig.h
   securitydeclarative.cpp
   securitydeclarative.h
   securitydescriptor.cpp
   securitydescriptor.h
   ...descriptorappdomain.cpp
   ...tydescriptorappdomain.h
   ...ydescriptorassembly.cpp
   ...itydescriptorassembly.h
   securityhostprotection.cpp
   securityhostprotection.h
   securityimperative.cpp
   securityimperative.h
   securitymeta.cpp
   securitymeta.h
   securitypolicy.cpp
   securitypolicy.h
   securitystackwalk.cpp
   securitystackwalk.h
   ...transparentassembly.cpp
   ...tytransparentassembly.h
   sigformat.cpp
   sigformat.h
   siginfo.cpp
   siginfo.hpp
   simplerwlock.cpp
   simplerwlock.hpp
   sourceline.cpp
   sourceline.h
   sources.dac
   sources.inc
   specialstatics.h
   spinlock.cpp
   spinlock.h
   stackbuildersink.cpp
   stackbuildersink.h
   stackcompressor.cpp
   stackcompressor.h
   stackingallocator.cpp
   stackingallocator.h
   stackprobe.h
   stackprobe.inl
   stackwalk.cpp
   stackwalk.h
   stackwalktypes.h
   stringliteralmap.cpp
   stringliteralmap.h
   strongname.cpp
   stubgen.h
   stublink.cpp
   stublink.h
   stublink.inl
   stubmgr.cpp
   stubmgr.h
   syncblk.cpp
   syncblk.h
   syncblk.inl
   syncclean.cpp
   syncclean.hpp
   synch.cpp
   synch.h
   ...zationcontextnative.cpp
   ...nizationcontextnative.h
   testhookmgr.cpp
   testhookmgr.h
   thekey.h
   threads.cpp
   threads.h
   threads.inl
   tokeniter.cpp
   tokeniter.hpp
   typectxt.cpp
   typectxt.h
   typedesc.cpp
   typedesc.h
   typedesc.inl
   typehandle.cpp
   typehandle.h
   typehandle.inl
   typehash.cpp
   typehash.h
   typekey.h
   typeparse.cpp
   typeparse.h
   typestring.cpp
   typestring.h
   umthunkhash.cpp
   umthunkhash.h
   util.cpp
   util.hpp
   validator.cpp
   vars.cpp
   vars.hpp
   verifier.cpp
   verifier.hpp
   veropcodes.hpp
   vertable.h
   virtualcallstub.cpp
   virtualcallstub.h
   vmholder.h
   win32threadpool.cpp
   win32threadpool.h
   wrappers.h

// ==++==
//
//   
//    Copyright (c) 2006 Microsoft Corporation.  All rights reserved.
//   
//    The use and distribution terms for this software are contained in the file
//    named license.txt, which can be found in the root of this distribution.
//    By using this software in any fashion, you are agreeing to be bound by the
//    terms of this license.
//   
//    You must not remove this notice, or any other, from this software.
//   
//
// ==--==
// Appdomainstack.h -
//
//

#ifndef __appdomainstack_h__
#define __appdomainstack_h__

#include "vars.hpp"
#include "util.hpp"


// Stack of AppDomains executing on the current thread. Used in security optimization to avoid stackwalks
#define ADSTACK_BLOCK_SIZE        16
#define INVALID_APPDOMAIN_ID ((DWORD)-1)
#define CURRENT_APPDOMAIN_ID ((ADID)(DWORD)0)
#define __GetADID(index)   ((index)<ADSTACK_BLOCK_SIZE?m_pStack[(index)].m_domainID:m_pExtraStack[((index)-ADSTACK_BLOCK_SIZE)].m_domainID)
#define __GetEntryPtr(index) ((index)<ADSTACK_BLOCK_SIZE?&(m_pStack[(index)]):&(m_pExtraStack[((index)-ADSTACK_BLOCK_SIZE)]))

struct AppDomainStackEntry
{
    ADID  m_domainID;
    DWORD m_dwOverridesCount;
    DWORD m_dwAsserts;
    DWORD m_dwPreviousThreadWideSpecialFlags;

    FORCEINLINE bool operator==(const AppDomainStackEntry& entry) const
    {
        return (m_domainID == entry.m_domainID &&
                m_dwOverridesCount == entry.m_dwOverridesCount &&
                m_dwAsserts == entry.m_dwAsserts);
    }
    FORCEINLINE bool operator!=(const AppDomainStackEntry& entry) const
    {
        return (m_domainID != entry.m_domainID ||
                m_dwOverridesCount != entry.m_dwOverridesCount ||
                m_dwAsserts != entry.m_dwAsserts);

    }
    BOOL IsFullyTrustedWithNoStackModifiers(void);
    BOOL IsHomogeneousWithNoStackModifiers(void);
    BOOL HasFlagsOrFullyTrustedWithNoStackModifiers(DWORD flags);
#ifndef DACCESS_COMPILE    
    void UpdateHomogeneousPLS(OBJECTREF* homogeneousPLS);
#endif
};

class AppDomainStack
{
public:
    AppDomainStack() : m_numEntries(0), m_pExtraStack(NULL), m_ExtraStackSize(0), m_dwOverridesCount(0), m_dwAsserts(0), m_dwThreadWideSpecialFlags(0xFFFFFFFF)
    {
        WRAPPER_CONTRACT;
        FillEntries(m_pStack, ADSTACK_BLOCK_SIZE);
    }

    AppDomainStack(const AppDomainStack& stack):m_numEntries(0), m_pExtraStack(NULL), m_ExtraStackSize(0), m_dwOverridesCount(0), m_dwAsserts(0)
    {
        CONTRACTL {
            THROWS;
            GC_NOTRIGGER;
            MODE_ANY;
        }
        CONTRACTL_END;

        m_dwThreadWideSpecialFlags = stack.m_dwThreadWideSpecialFlags;
        m_numEntries = stack.m_numEntries;
        m_dwOverridesCount = stack.m_dwOverridesCount;
        m_dwAsserts = stack.m_dwAsserts;
        LOG((LF_APPDOMAIN, LL_INFO100, "copy ctor: m_dwAsserts:%d stack.m_dwAsserts:%d\n",m_dwAsserts, stack.m_dwAsserts));
        memcpy(m_pStack, stack.m_pStack, sizeof( AppDomainStackEntry) * ADSTACK_BLOCK_SIZE);
        // If there is anything stored in the extra allocated space, copy that over
        if (m_numEntries > ADSTACK_BLOCK_SIZE)
        {
            // #blocks to allocate = ceil(numDomains/blocksize) - 1 = ceil ((numdomains - blocksize)/blocksize) = numdomains/blocksize
            DWORD numBlocks = m_numEntries/ADSTACK_BLOCK_SIZE; 
            m_ExtraStackSize = numBlocks*ADSTACK_BLOCK_SIZE;
            m_pExtraStack = new AppDomainStackEntry[m_ExtraStackSize];
            memcpy(m_pExtraStack, stack.m_pExtraStack, sizeof(AppDomainStackEntry)*(m_numEntries-ADSTACK_BLOCK_SIZE));
            FillEntries((m_pExtraStack+m_numEntries-ADSTACK_BLOCK_SIZE), (m_ExtraStackSize -(m_numEntries-ADSTACK_BLOCK_SIZE)));
        }
    }

    ~AppDomainStack()
    {
        CONTRACTL
        {
          MODE_ANY;
          GC_NOTRIGGER;
          NOTHROW;
        } CONTRACTL_END;
        if (m_pExtraStack != NULL)
            delete[] m_pExtraStack;
        m_pExtraStack = NULL;
        m_ExtraStackSize = 0;
    }

    bool operator!= (const AppDomainStack& stack) const
    {
        return !(*this == stack);
    }

    bool operator== (const AppDomainStack& stack) const
    {
        LEAF_CONTRACT;
        if (this == &stack) // degenerate case: comparing with self
            return true;
        if (this->m_numEntries != stack.m_numEntries || 
            this->m_dwAsserts != stack.m_dwAsserts || 
            this->m_dwOverridesCount != stack.m_dwOverridesCount)
            return false;
        for (unsigned i =0; i < stack.m_numEntries; i++)
        {
            if (i < ADSTACK_BLOCK_SIZE)
            {
                if (this->m_pStack[i] != stack.m_pStack[i])
                    return false;
            }
            else
            {
                if (this->m_pExtraStack[i-ADSTACK_BLOCK_SIZE] != stack.m_pExtraStack[i-ADSTACK_BLOCK_SIZE])
                    return false;
            }
        }
        return true;
    }
    inline AppDomainStack& operator =(const AppDomainStack& stack)
    {
        CONTRACTL {
            THROWS;
            GC_NOTRIGGER;
            MODE_ANY;
        }
        CONTRACTL_END;

        // Degenerate case (assigning x = x)
        if (this == &stack)
            return *this;

        m_dwThreadWideSpecialFlags = stack.m_dwThreadWideSpecialFlags;
        m_numEntries = stack.m_numEntries;
        m_dwOverridesCount = stack.m_dwOverridesCount;
        m_dwAsserts = stack.m_dwAsserts;
        LOG((LF_APPDOMAIN, LL_INFO100, "= operator : m_dwAsserts:%d stack.m_dwAsserts:%d\n",m_dwAsserts, stack.m_dwAsserts));
        memcpy(m_pStack, stack.m_pStack, sizeof( AppDomainStackEntry) * ADSTACK_BLOCK_SIZE);
        // If there is anything stored in the extra allocated space, copy that over
        if (m_numEntries > ADSTACK_BLOCK_SIZE)
        {
            // #blocks to allocate = ceil(numDomains/blocksize) - 1 = ceil ((numdomains - blocksize)/blocksize) = numdomains/blocksize
            DWORD numBlocks = m_numEntries/ADSTACK_BLOCK_SIZE; 
            if (m_ExtraStackSize < numBlocks*ADSTACK_BLOCK_SIZE)
            {
                // free ptr if it exists
                if (m_pExtraStack != NULL)
                    delete[] m_pExtraStack;
                m_pExtraStack = NULL;

                m_ExtraStackSize = numBlocks*ADSTACK_BLOCK_SIZE;
                m_pExtraStack = new AppDomainStackEntry[m_ExtraStackSize];
            }

            memset(m_pExtraStack, 0xFF, sizeof(ADID) * numBlocks);
            memcpy(m_pExtraStack, stack.m_pExtraStack, sizeof(AppDomainStackEntry)*(m_numEntries-ADSTACK_BLOCK_SIZE));
            FillEntries((m_pExtraStack+m_numEntries-ADSTACK_BLOCK_SIZE), (m_ExtraStackSize -(m_numEntries-ADSTACK_BLOCK_SIZE)));
        }
    
        return *this;
    }

    inline void PushDomain(ADID pDomain);
    inline ADID PopDomain();

    inline void InitDomainIteration(DWORD *pIndex) const;
    // Gets the next AD on the stack
    inline ADID GetNextDomainOnStack(DWORD *pIndex, DWORD *pOverrides, DWORD *pAsserts) const;
    inline AppDomainStackEntry* GetNextDomainEntryOnStack(DWORD *pIndex);
    inline AppDomainStackEntry* GetCurrentDomainEntryOnStack(DWORD pIndex);
    // Updates the asserts/overrides on the next AD on the stack
    inline void UpdateDomainOnStack(DWORD pIndex, DWORD asserts, DWORD overrides);
    inline DWORD   GetNumDomains() const;
    inline void ClearDomainStack();
    inline DWORD GetThreadWideSpecialFlag() const;
    inline DWORD IncrementOverridesCount();
    inline DWORD DecrementOverridesCount();
    inline DWORD GetOverridesCount();
    inline DWORD GetInnerAppDomainOverridesCount();
    inline DWORD IncrementAssertCount();
    inline DWORD DecrementAssertCount();
    inline DWORD GetAssertCount();
    inline DWORD GetInnerAppDomainAssertCount();
    bool IsDefaultSecurityInfo() const;
    BOOL AllDomainsHomogeneousWithNoStackModifiers();

private:
    inline void AddMoreDomains(void);
    inline AppDomainStackEntry* ReadTopOfStack();
    void UpdateStackFromEntries();
    static void AppDomainStack::FillEntries(AppDomainStackEntry ptr[], DWORD size)
    {
        CONTRACTL 
        {
            MODE_ANY;
            GC_NOTRIGGER;
            NOTHROW;
        }CONTRACTL_END;
        _ASSERTE(ptr != NULL);
        DWORD i;
        const AppDomainStackEntry tmp_entry = {ADID(INVALID_APPDOMAIN_ID), 0, 0};
        for(i=0;i<size;i++)
            ptr[i]=tmp_entry;
    }

#ifdef _DEBUG
    inline void LogADStackUpdate(void);
    void CheckOverridesAssertCounts(); // Debug only code to check that assert count/overrides count are always in sync across adstack
#endif

    DWORD       m_numEntries;
    AppDomainStackEntry m_pStack[ADSTACK_BLOCK_SIZE];
    AppDomainStackEntry *m_pExtraStack;
    DWORD       m_ExtraStackSize;
    DWORD m_dwOverridesCount; // across all entries
    DWORD m_dwAsserts; // across all entries
    DWORD       m_dwThreadWideSpecialFlags; // this flag records the last evaluated thread wide security state
};
#endif

About Koders | Resources | Downloads | Support | Black Duck | Terms of Service | DMCA | Privacy Policy | Contact Us