internal static CompressedStack GetCompressedStack(ref StackCrawlMark stackMark)
        {
            CompressedStack cs;
            CompressedStack innerCS = null;

            if (CodeAccessSecurityEngine.QuickCheckForAllDemands())
            {
                cs = new CompressedStack(null);
            }
            else if (CodeAccessSecurityEngine.AllDomainsHomogeneousWithNoStackModifiers())
            {
                cs       = new CompressedStack(null);
                cs.m_pls = PermissionListSet.CreateCompressedState_HG();
            }
            else
            {
                // regular stackwalking case
                cs = new CompressedStack(GetDelayedCompressedStack(ref stackMark));
                if (cs.CompressedStackHandle != null && IsImmediateCompletionCandidate(cs.CompressedStackHandle, out innerCS))
                {
                    cs.CompleteConstruction(innerCS);
                    DestroyDCSList(cs.CompressedStackHandle);
                }
            }
            return(cs);
        }
        [System.Security.SecurityCritical]  // auto-generated
        internal static CompressedStack GetCompressedStack(ref StackCrawlMark stackMark)
        {
            CompressedStack cs;
            CompressedStack innerCS = null;

            if (CodeAccessSecurityEngine.QuickCheckForAllDemands())
            {
                cs = new CompressedStack(null);
                cs.CanSkipEvaluation = true;
            }
            else if (CodeAccessSecurityEngine.AllDomainsHomogeneousWithNoStackModifiers())
            {
                // if all AppDomains on the stack are homogeneous, we don't need to walk the stack
                // however, we do need to capture the AppDomain stack.
                cs       = new CompressedStack(GetDelayedCompressedStack(ref stackMark, false));
                cs.m_pls = PermissionListSet.CreateCompressedState_HG();
            }
            else
            {
                // regular stackwalking case
                // We want this to complete without ThreadAborts - if we're in a multiple AD callstack and an intermediate AD gets unloaded,
                // preventing TAs here prevents a race condition where a SafeCompressedStackHandle is created to a DCS belonging to an AD that's
                // gone away
                cs = new CompressedStack(null);
                RuntimeHelpers.PrepareConstrainedRegions();
                try
                {
                    // Empty try block to ensure no ThreadAborts in the finally block
                }
                finally
                {
                    cs.CompressedStackHandle = GetDelayedCompressedStack(ref stackMark, true);
                    if (cs.CompressedStackHandle != null && IsImmediateCompletionCandidate(cs.CompressedStackHandle, out innerCS))
                    {
                        try
                        {
                            cs.CompleteConstruction(innerCS);
                        }
                        finally
                        {
                            DestroyDCSList(cs.CompressedStackHandle);
                        }
                    }
                }
            }
            return(cs);
        }
        internal static CompressedStack GetCompressedStack(ref StackCrawlMark stackMark)
        {
            CompressedStack innerCS = (CompressedStack)null;
            CompressedStack compressedStack;

            if (CodeAccessSecurityEngine.QuickCheckForAllDemands())
            {
                compressedStack = new CompressedStack((SafeCompressedStackHandle)null);
                compressedStack.CanSkipEvaluation = true;
            }
            else if (CodeAccessSecurityEngine.AllDomainsHomogeneousWithNoStackModifiers())
            {
                compressedStack       = new CompressedStack(CompressedStack.GetDelayedCompressedStack(ref stackMark, false));
                compressedStack.m_pls = PermissionListSet.CreateCompressedState_HG();
            }
            else
            {
                compressedStack = new CompressedStack((SafeCompressedStackHandle)null);
                RuntimeHelpers.PrepareConstrainedRegions();
                try
                {
                }
                finally
                {
                    compressedStack.CompressedStackHandle = CompressedStack.GetDelayedCompressedStack(ref stackMark, true);
                    if (compressedStack.CompressedStackHandle != null)
                    {
                        if (CompressedStack.IsImmediateCompletionCandidate(compressedStack.CompressedStackHandle, out innerCS))
                        {
                            try
                            {
                                compressedStack.CompleteConstruction(innerCS);
                            }
                            finally
                            {
                                CompressedStack.DestroyDCSList(compressedStack.CompressedStackHandle);
                            }
                        }
                    }
                }
            }
            return(compressedStack);
        }
Beispiel #4
0
        internal static CompressedStack GetCompressedStack(ref StackCrawlMark stackMark)
        {
            CompressedStack innerCS = null;

            if (CodeAccessSecurityEngine.QuickCheckForAllDemands())
            {
                return(new CompressedStack(null)
                {
                    CanSkipEvaluation = true
                });
            }
            if (CodeAccessSecurityEngine.AllDomainsHomogeneousWithNoStackModifiers())
            {
                return(new CompressedStack(GetDelayedCompressedStack(ref stackMark, false))
                {
                    m_pls = PermissionListSet.CreateCompressedState_HG()
                });
            }
            CompressedStack stack = new CompressedStack(null);

            RuntimeHelpers.PrepareConstrainedRegions();
            try
            {
            }
            finally
            {
                stack.CompressedStackHandle = GetDelayedCompressedStack(ref stackMark, true);
                if ((stack.CompressedStackHandle != null) && IsImmediateCompletionCandidate(stack.CompressedStackHandle, out innerCS))
                {
                    try
                    {
                        stack.CompleteConstruction(innerCS);
                    }
                    finally
                    {
                        DestroyDCSList(stack.CompressedStackHandle);
                    }
                }
            }
            return(stack);
        }
        // public(internal) interface begins... 
        // Creation functions 
        static internal PermissionListSet CreateCompressedState(CompressedStack cs, CompressedStack innerCS)
        { 
            // function that completes the construction of the compressed stack if not done so already (bottom half for demand evaluation)

            bool bHaltConstruction = false;
            if (cs.CompressedStackHandle == null) 
                return null; //  FT case or Security off
 
            PermissionListSet pls = new PermissionListSet(); 
            PermissionSetTriple currentTriple = new PermissionSetTriple();
            int numDomains = CompressedStack.GetDCSCount(cs.CompressedStackHandle); 
            for (int i=numDomains-1; (i >= 0 && !bHaltConstruction) ; i--)
            {
                DomainCompressedStack dcs = CompressedStack.GetDomainCompressedStack(cs.CompressedStackHandle, i);
                if (dcs == null) 
                    continue; // we hit a FT Domain
                if (dcs.PLS == null) 
                { 
                    // We failed on some DCS
                    throw new SecurityException(String.Format(CultureInfo.InvariantCulture, Environment.GetResourceString("Security_Generic"))); 
                }
                pls.UpdateZoneAndOrigin(dcs.PLS);
                pls.Update(currentTriple, dcs.PLS);
                bHaltConstruction = dcs.ConstructionHalted; 
            }
            if (!bHaltConstruction) 
            { 
                PermissionListSet tmp_pls = null;
                // Construction did not halt. 
                if (innerCS != null)
                {
                    innerCS.CompleteConstruction(null);
                    tmp_pls = innerCS.PLS; 
                }
                pls.Terminate(currentTriple, tmp_pls); 
            } 
            else
            { 
                pls.Terminate(currentTriple);
            }

            return pls; 
        }
Beispiel #6
0
 [System.Security.SecurityCritical]  // auto-generated
 internal static CompressedStack GetCompressedStack(ref StackCrawlMark stackMark)
 {
     CompressedStack cs;
     CompressedStack innerCS = null;
     if (CodeAccessSecurityEngine.QuickCheckForAllDemands())
     {
         cs = new CompressedStack(null);
         cs.CanSkipEvaluation = true;
     }
     else if (CodeAccessSecurityEngine.AllDomainsHomogeneousWithNoStackModifiers())
     {
         // if all AppDomains on the stack are homogeneous, we don't need to walk the stack
         // however, we do need to capture the AppDomain stack.
         cs = new CompressedStack(GetDelayedCompressedStack(ref stackMark, false));
         cs.m_pls = PermissionListSet.CreateCompressedState_HG();
     }
     else
     {
         // regular stackwalking case
         // We want this to complete without ThreadAborts - if we're in a multiple AD callstack and an intermediate AD gets unloaded,
         // preventing TAs here prevents a race condition where a SafeCompressedStackHandle is created to a DCS belonging to an AD that's 
         // gone away
         cs = new CompressedStack(null);
         RuntimeHelpers.PrepareConstrainedRegions();
         try
         {
             // Empty try block to ensure no ThreadAborts in the finally block
         }
         finally
         {
             
             cs.CompressedStackHandle = GetDelayedCompressedStack(ref stackMark, true);
             if (cs.CompressedStackHandle != null && IsImmediateCompletionCandidate(cs.CompressedStackHandle, out innerCS))
             {
                 try
                 {
                     cs.CompleteConstruction(innerCS);
                 }
                 finally
                 {
                     DestroyDCSList(cs.CompressedStackHandle);
                 }
             }
         }
     }
     return cs;
 }
Beispiel #7
0
 internal static CompressedStack GetCompressedStack(ref StackCrawlMark stackMark)
 {
     CompressedStack innerCS = null;
     if (CodeAccessSecurityEngine.QuickCheckForAllDemands())
     {
         return new CompressedStack(null) { CanSkipEvaluation = true };
     }
     if (CodeAccessSecurityEngine.AllDomainsHomogeneousWithNoStackModifiers())
     {
         return new CompressedStack(GetDelayedCompressedStack(ref stackMark, false)) { m_pls = PermissionListSet.CreateCompressedState_HG() };
     }
     CompressedStack stack = new CompressedStack(null);
     RuntimeHelpers.PrepareConstrainedRegions();
     try
     {
     }
     finally
     {
         stack.CompressedStackHandle = GetDelayedCompressedStack(ref stackMark, true);
         if ((stack.CompressedStackHandle != null) && IsImmediateCompletionCandidate(stack.CompressedStackHandle, out innerCS))
         {
             try
             {
                 stack.CompleteConstruction(innerCS);
             }
             finally
             {
                 DestroyDCSList(stack.CompressedStackHandle);
             }
         }
     }
     return stack;
 }
 internal static PermissionListSet CreateCompressedState(CompressedStack cs, CompressedStack innerCS)
 {
     bool constructionHalted = false;
     if (cs.CompressedStackHandle == null)
     {
         return null;
     }
     PermissionListSet set = new PermissionListSet();
     PermissionSetTriple currentTriple = new PermissionSetTriple();
     for (int i = CompressedStack.GetDCSCount(cs.CompressedStackHandle) - 1; (i >= 0) && !constructionHalted; i--)
     {
         DomainCompressedStack domainCompressedStack = CompressedStack.GetDomainCompressedStack(cs.CompressedStackHandle, i);
         if (domainCompressedStack != null)
         {
             if (domainCompressedStack.PLS == null)
             {
                 throw new SecurityException(string.Format(CultureInfo.InvariantCulture, Environment.GetResourceString("Security_Generic"), new object[0]));
             }
             set.UpdateZoneAndOrigin(domainCompressedStack.PLS);
             set.Update(currentTriple, domainCompressedStack.PLS);
             constructionHalted = domainCompressedStack.ConstructionHalted;
         }
     }
     if (!constructionHalted)
     {
         PermissionListSet pls = null;
         if (innerCS != null)
         {
             innerCS.CompleteConstruction(null);
             pls = innerCS.PLS;
         }
         set.Terminate(currentTriple, pls);
         return set;
     }
     set.Terminate(currentTriple);
     return set;
 }
 internal static CompressedStack GetCompressedStack(ref StackCrawlMark stackMark)
 {
     CompressedStack cs;
     CompressedStack innerCS = null;
     if (CodeAccessSecurityEngine.QuickCheckForAllDemands())
     {
         cs = new CompressedStack(null);
     }
     else if (CodeAccessSecurityEngine.AllDomainsHomogeneousWithNoStackModifiers())
     {
         cs = new CompressedStack(null);
         cs.m_pls = PermissionListSet.CreateCompressedState_HG();
     }
     else
     {
         // regular stackwalking case
         cs = new CompressedStack(GetDelayedCompressedStack( ref stackMark ));
         if (cs.CompressedStackHandle != null && IsImmediateCompletionCandidate(cs.CompressedStackHandle, out innerCS))
         {
             cs.CompleteConstruction(innerCS);
             DestroyDCSList(cs.CompressedStackHandle);
         }
     }
     return cs;
 }