internal _IOCompletionCallback(IOCompletionCallback ioCompletionCallback, ref StackCrawlMark stackMark)
 {
     _ioCompletionCallback = ioCompletionCallback;
     // clone the exection context
     _executionContext = ExecutionContext.Capture(ref stackMark);
     ExecutionContext.ClearSyncContext(_executionContext);
 }
 public ResourceSet GrovelForResourceSet(CultureInfo culture, Dictionary<string, ResourceSet> localResourceSets, bool tryParents, bool createIfNotExists, ref StackCrawlMark stackMark)
 {
     string file = null;
     ResourceSet set = null;
     ResourceSet set2;
     try
     {
         new FileIOPermission(PermissionState.Unrestricted).Assert();
         string resourceFileName = this._mediator.GetResourceFileName(culture);
         file = this.FindResourceFile(culture, resourceFileName);
         if (file == null)
         {
             if (tryParents && culture.HasInvariantCultureName)
             {
                 throw new MissingManifestResourceException(Environment.GetResourceString("MissingManifestResource_NoNeutralDisk") + Environment.NewLine + "baseName: " + this._mediator.BaseNameField + "  locationInfo: " + ((this._mediator.LocationInfo == null) ? "<null>" : this._mediator.LocationInfo.FullName) + "  fileName: " + this._mediator.GetResourceFileName(culture));
             }
         }
         else
         {
             set = this.CreateResourceSet(file);
         }
         set2 = set;
     }
     finally
     {
         CodeAccessPermission.RevertAssert();
     }
     return set2;
 }
Beispiel #3
0
        internal static Type GetType(
            string typeName,
            Func<AssemblyName, Assembly> assemblyResolver,
            Func<Assembly, string, bool, Type> typeResolver,
            bool throwOnError,
            bool ignoreCase,
            ref StackCrawlMark stackMark)
        {
            if (typeName == null)
                throw new ArgumentNullException("typeName");
            if (typeName.Length > 0 && typeName[0] == '\0')
                throw new ArgumentException(Environment.GetResourceString("Format_StringZeroLength"));
            Contract.EndContractBlock();

            Type ret = null;

            SafeTypeNameParserHandle handle = CreateTypeNameParser(typeName, throwOnError);

            if (handle != null)
            {
                // If we get here the typeName must have been successfully parsed.
                // Let's construct the Type object.
                using (TypeNameParser parser = new TypeNameParser(handle))
                {
                    ret = parser.ConstructType(assemblyResolver, typeResolver, throwOnError, ignoreCase, ref stackMark);
                }
            }

            return ret;
        }
 internal static ExecutionContext Capture(ref StackCrawlMark stackMark)
 {
     if (IsFlowSuppressed())
     {
         return null;
     }
     ExecutionContext executionContextNoCreate = System.Threading.Thread.CurrentThread.GetExecutionContextNoCreate();
     ExecutionContext context2 = new ExecutionContext {
         isNewCapture = true,
         SecurityContext = System.Security.SecurityContext.Capture(executionContextNoCreate, ref stackMark)
     };
     if (context2.SecurityContext != null)
     {
         context2.SecurityContext.ExecutionContext = context2;
     }
     context2._hostExecutionContext = HostExecutionContextManager.CaptureHostExecutionContext();
     if (executionContextNoCreate != null)
     {
         context2._syncContext = (executionContextNoCreate._syncContext == null) ? null : executionContextNoCreate._syncContext.CreateCopy();
         if (executionContextNoCreate._logicalCallContext != null)
         {
             System.Runtime.Remoting.Messaging.LogicalCallContext logicalCallContext = executionContextNoCreate.LogicalCallContext;
             context2.LogicalCallContext = (System.Runtime.Remoting.Messaging.LogicalCallContext) logicalCallContext.Clone();
         }
     }
     return context2;
 }
Beispiel #5
0
 internal _IOCompletionCallback(IOCompletionCallback ioCompletionCallback, ref StackCrawlMark stackMark)
 {
     _ioCompletionCallback = ioCompletionCallback;
     // clone the exection context
     _executionContext = ExecutionContext.Capture(
         ref stackMark, 
         ExecutionContext.CaptureOptions.IgnoreSyncCtx | ExecutionContext.CaptureOptions.OptimizeDefaultCase);
 }
 private unsafe Type ConstructType(Func<AssemblyName, Assembly> assemblyResolver, Func<Assembly, string, bool, Type> typeResolver, bool throwOnError, bool ignoreCase, ref StackCrawlMark stackMark)
 {
     Assembly assembly = null;
     int[] numArray2;
     string assemblyName = this.GetAssemblyName();
     if (assemblyName.Length > 0)
     {
         assembly = ResolveAssembly(assemblyName, assemblyResolver, throwOnError, ref stackMark);
         if (assembly == null)
         {
             return null;
         }
     }
     string[] names = this.GetNames();
     if (names == null)
     {
         if (throwOnError)
         {
             throw new TypeLoadException(Environment.GetResourceString("Arg_TypeLoadNullStr"));
         }
         return null;
     }
     Type typeStart = ResolveType(assembly, names, typeResolver, throwOnError, ignoreCase, ref stackMark);
     if (typeStart == null)
     {
         return null;
     }
     SafeTypeNameParserHandle[] typeArguments = this.GetTypeArguments();
     Type[] genericArgs = null;
     if (typeArguments != null)
     {
         genericArgs = new Type[typeArguments.Length];
         for (int i = 0; i < typeArguments.Length; i++)
         {
             using (TypeNameParser parser = new TypeNameParser(typeArguments[i]))
             {
                 genericArgs[i] = parser.ConstructType(assemblyResolver, typeResolver, throwOnError, ignoreCase, ref stackMark);
             }
             if (genericArgs[i] == null)
             {
                 return null;
             }
         }
     }
     int[] modifiers = this.GetModifiers();
     if (((numArray2 = modifiers) == null) || (numArray2.Length == 0))
     {
         numRef = null;
         goto Label_00EE;
     }
     fixed (int* numRef = numArray2)
     {
         IntPtr ptr;
     Label_00EE:
         ptr = new IntPtr((void*) numRef);
         return RuntimeTypeHandle.GetTypeHelper(typeStart, genericArgs, ptr, (modifiers == null) ? 0 : modifiers.Length);
     }
 }
 internal _ThreadPoolWaitCallback(WaitCallback waitCallback, object state, bool compressStack, ref StackCrawlMark stackMark)
 {
     this._waitCallback = waitCallback;
     this._state = state;
     if (compressStack && !ExecutionContext.IsFlowSuppressed())
     {
         this._executionContext = ExecutionContext.Capture(ref stackMark, ExecutionContext.CaptureOptions.OptimizeDefaultCase | ExecutionContext.CaptureOptions.IgnoreSyncCtx);
     }
 }
 internal _TimerCallback(TimerCallback timerCallback, object state, ref StackCrawlMark stackMark)
 {
     this._timerCallback = timerCallback;
     this._state = state;
     if (!ExecutionContext.IsFlowSuppressed())
     {
         this._executionContext = ExecutionContext.Capture(ref stackMark, ExecutionContext.CaptureOptions.OptimizeDefaultCase | ExecutionContext.CaptureOptions.IgnoreSyncCtx);
     }
 }
 internal QueueUserWorkItemCallback(WaitCallback waitCallback, object stateObj, bool compressStack, ref StackCrawlMark stackMark)
 {
     this.callback = waitCallback;
     this.state = stateObj;
     if (compressStack && !ExecutionContext.IsFlowSuppressed())
     {
         this.context = ExecutionContext.Capture(ref stackMark, ExecutionContext.CaptureOptions.OptimizeDefaultCase | ExecutionContext.CaptureOptions.IgnoreSyncCtx);
     }
 }
 internal _ThreadPoolWaitOrTimerCallback(WaitOrTimerCallback waitOrTimerCallback, object state, bool compressStack, ref StackCrawlMark stackMark)
 {
     this._waitOrTimerCallback = waitOrTimerCallback;
     this._state = state;
     if (compressStack && !ExecutionContext.IsFlowSuppressed())
     {
         this._executionContext = ExecutionContext.Capture(ref stackMark);
         ExecutionContext.ClearSyncContext(this._executionContext);
     }
 }
Beispiel #11
0
 internal _TimerCallback(TimerCallback timerCallback, Object state, ref StackCrawlMark stackMark)
 {
     _timerCallback = timerCallback;
     _state = state;
     if (!ExecutionContext.IsFlowSuppressed())
     {
         _executionContext = ExecutionContext.Capture(ref stackMark);
         ExecutionContext.ClearSyncContext(_executionContext);
     }
 }
Beispiel #12
0
		internal static Type GetType(
            string typeName,
            Func<AssemblyName, Assembly> assemblyResolver,
            Func<Assembly, string, bool, Type> typeResolver,
            bool throwOnError,
            bool ignoreCase,
            ref StackCrawlMark stackMark)
		{
			TypeSpec spec = TypeSpec.Parse (typeName);
			return spec.Resolve (assemblyResolver, typeResolver, throwOnError, ignoreCase);
		}
Beispiel #13
0
 internal void AddTimer(TimerCallback callback, object state, uint dueTime, uint period, ref StackCrawlMark stackMark)
 {
     if (callback == null)
     {
         throw new ArgumentNullException("TimerCallback");
     }
     _TimerCallback callback2 = new _TimerCallback(callback, state, ref stackMark);
     state = callback2;
     this.AddTimerNative(state, dueTime, period, ref stackMark);
     this.timerDeleted = 0;
 }
		private unsafe Type ConstructType(Func<AssemblyName, Assembly> assemblyResolver, Func<Assembly, string, bool, Type> typeResolver, bool throwOnError, bool ignoreCase, ref StackCrawlMark stackMark)
		{
			Assembly assembly = null;
			string assemblyName = this.GetAssemblyName();
			if (assemblyName.Length > 0)
			{
				assembly = TypeNameParser.ResolveAssembly(assemblyName, assemblyResolver, throwOnError, ref stackMark);
				if (assembly == null)
				{
					return null;
				}
			}
			string[] names = this.GetNames();
			if (names == null)
			{
				if (throwOnError)
				{
					throw new TypeLoadException(Environment.GetResourceString("Arg_TypeLoadNullStr"));
				}
				return null;
			}
			else
			{
				Type type = TypeNameParser.ResolveType(assembly, names, typeResolver, throwOnError, ignoreCase, ref stackMark);
				if (type == null)
				{
					return null;
				}
				SafeTypeNameParserHandle[] typeArguments = this.GetTypeArguments();
				Type[] array = null;
				if (typeArguments != null)
				{
					array = new Type[typeArguments.Length];
					for (int i = 0; i < typeArguments.Length; i++)
					{
						using (TypeNameParser typeNameParser = new TypeNameParser(typeArguments[i]))
						{
							array[i] = typeNameParser.ConstructType(assemblyResolver, typeResolver, throwOnError, ignoreCase, ref stackMark);
						}
						if (array[i] == null)
						{
							return null;
						}
					}
				}
				int[] modifiers = this.GetModifiers();
				fixed (int* ptr = modifiers)
				{
					IntPtr pModifiers = new IntPtr((void*)ptr);
					return RuntimeTypeHandle.GetTypeHelper(type, array, pModifiers, (modifiers == null) ? 0 : modifiers.Length);
				}
			}
		}
		internal Object CreateInstanceSlow(bool publicOnly, bool skipCheckThis, bool fillCache, ref StackCrawlMark stackMark)
		{
			bool bNeedSecurityCheck = true;
			bool bCanBeCached = false;
			bool bSecurityCheckOff = false;

			if (!skipCheckThis)
				CreateInstanceCheckThis();

			if (!fillCache)
				bSecurityCheckOff = true;

			return CreateInstanceMono (!publicOnly);
		}
        internal ModuleBuilder DefineDynamicModuleInternal(
            String      name,
            bool        emitSymbolInfo,         // specify if emit symbol info or not
            ref StackCrawlMark stackMark)
        {
            BCLDebug.Log("DYNIL","## DYNIL LOGGING: AssemblyBuilder.DefineDynamicModule( " + name + " )");
            
            BCLDebug.Assert(m_assemblyData != null, "m_assemblyData is null in DefineDynamicModuleInternal");

            if (name == null)
                throw new ArgumentNullException("name");
            if (name.Length == 0)
                throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), "name");
           if (name[0] == '\0')
                throw new ArgumentException(Environment.GetResourceString("Argument_InvalidName"), "name");
             
            m_assemblyData.CheckNameConflict(name);
    
            // create the dynamic module
            ModuleBuilder   dynModule = nDefineDynamicModule(this, emitSymbolInfo, name, ref stackMark);
            ISymbolWriter   writer = null;

            if (emitSymbolInfo)
            {
                // create the default SymWriter
                Assembly assem = LoadISymWrapper();
                Type symWriter = assem.GetType("System.Diagnostics.SymbolStore.SymWriter", true, false);
                if (symWriter != null && !symWriter.IsVisible) 
                    symWriter = null;

                if (symWriter == null)
                {
                    // cannot find SymWriter
                    throw new ExecutionEngineException(String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString(ResId.MissingType), "SymWriter")); 
                }
                try {
                    (new PermissionSet(PermissionState.Unrestricted)).Assert();
                    writer = (ISymbolWriter) Activator.CreateInstance(symWriter);
                }
                finally {
                    CodeAccessPermission.RevertAssert();
                }
            }

            dynModule.Init(name, null, writer);
            m_assemblyData.AddModule(dynModule);
            return dynModule;
        }
 internal static void Assert(PermissionSet permSet, ref StackCrawlMark stackMark)
 {
     FrameSecurityDescriptor descriptor = CodeAccessSecurityEngine.CheckNReturnSO(CodeAccessSecurityEngine.AssertPermissionToken, CodeAccessSecurityEngine.AssertPermission, ref stackMark, 1);
     if (descriptor == null)
     {
         Environment.FailFast(Environment.GetResourceString("ExecutionEngine_MissingSecurityDescriptor"));
     }
     else
     {
         if (descriptor.HasImperativeAsserts())
         {
             throw new SecurityException(Environment.GetResourceString("Security_MustRevertOverride"));
         }
         descriptor.SetAssert(permSet);
     }
 }
 internal static void AssertAllPossible(ref StackCrawlMark stackMark)
 {
     FrameSecurityDescriptor securityObjectForFrame = GetSecurityObjectForFrame(ref stackMark, true);
     if (securityObjectForFrame == null)
     {
         Environment.FailFast(Environment.GetResourceString("ExecutionEngine_MissingSecurityDescriptor"));
     }
     else
     {
         if (securityObjectForFrame.GetAssertAllPossible())
         {
             throw new SecurityException(Environment.GetResourceString("Security_MustRevertOverride"));
         }
         securityObjectForFrame.SetAssertAllPossible();
     }
 }
        [System.Security.SecuritySafeCritical]  // auto-generated
        public ResourceSet GrovelForResourceSet(CultureInfo culture, Dictionary<String, ResourceSet> localResourceSets, bool tryParents, bool createIfNotExists, ref StackCrawlMark stackMark) 
        {
            Contract.Assert(culture != null, "culture shouldn't be null; check caller");

            String fileName = null;
            ResourceSet rs = null;

            // Don't use Assembly manifest, but grovel on disk for a file.
            try
            {
#if !DISABLE_CAS_USE
                new System.Security.Permissions.FileIOPermission(System.Security.Permissions.PermissionState.Unrestricted).Assert();
#endif

                // Create new ResourceSet, if a file exists on disk for it.
                String tempFileName = _mediator.GetResourceFileName(culture);
                fileName = FindResourceFile(culture, tempFileName);
                if (fileName == null)
                {
                    if (tryParents)
                    {
                        // If we've hit top of the Culture tree, return.
                        if (culture.HasInvariantCultureName)
                        {
                            // We really don't think this should happen - we always
                            // expect the neutral locale's resources to be present.
                            throw new MissingManifestResourceException(Environment.GetResourceString("MissingManifestResource_NoNeutralDisk") + Environment.NewLine + "baseName: " + _mediator.BaseNameField + "  locationInfo: " + (_mediator.LocationInfo == null ? "<null>" : _mediator.LocationInfo.FullName) + "  fileName: " + _mediator.GetResourceFileName(culture));
                        }
                    }
                }
                else
                {
                    rs = CreateResourceSet(fileName);
                }
                return rs;
            }
            finally
            {
#if !DISABLE_CAS_USE
                System.Security.CodeAccessPermission.RevertAssert();
#endif
            }
        }
 internal static void Deny(PermissionSet permSet, ref StackCrawlMark stackMark)
 {
     if (!AppDomain.CurrentDomain.IsLegacyCasPolicyEnabled)
     {
         throw new NotSupportedException(Environment.GetResourceString("NotSupported_CasDeny"));
     }
     FrameSecurityDescriptor securityObjectForFrame = GetSecurityObjectForFrame(ref stackMark, true);
     if (securityObjectForFrame == null)
     {
         Environment.FailFast(Environment.GetResourceString("ExecutionEngine_MissingSecurityDescriptor"));
     }
     else
     {
         if (securityObjectForFrame.HasImperativeDenials())
         {
             throw new SecurityException(Environment.GetResourceString("Security_MustRevertOverride"));
         }
         securityObjectForFrame.SetDeny(permSet);
     }
 }
		internal static Type GetType(string typeName, Func<AssemblyName, Assembly> assemblyResolver, Func<Assembly, string, bool, Type> typeResolver, bool throwOnError, bool ignoreCase, ref StackCrawlMark stackMark)
		{
			if (typeName == null)
			{
				throw new ArgumentNullException("typeName");
			}
			if (typeName.Length > 0 && typeName[0] == '\0')
			{
				throw new ArgumentException(Environment.GetResourceString("Format_StringZeroLength"));
			}
			Type result = null;
			SafeTypeNameParserHandle safeTypeNameParserHandle = TypeNameParser.CreateTypeNameParser(typeName, throwOnError);
			if (safeTypeNameParserHandle != null)
			{
				using (TypeNameParser typeNameParser = new TypeNameParser(safeTypeNameParserHandle))
				{
					result = typeNameParser.ConstructType(assemblyResolver, typeResolver, throwOnError, ignoreCase, ref stackMark);
				}
			}
			return result;
		}
 internal static ExecutionContext Capture(ref StackCrawlMark stackMark, CaptureOptions options)
 {
     if (IsFlowSuppressed())
     {
         return null;
     }
     bool flag = CaptureOptions.None != (options & CaptureOptions.IgnoreSyncCtx);
     bool flag2 = CaptureOptions.None != (options & CaptureOptions.OptimizeDefaultCase);
     ExecutionContext executionContextNoCreate = System.Threading.Thread.CurrentThread.GetExecutionContextNoCreate();
     System.Security.SecurityContext context2 = System.Security.SecurityContext.Capture(executionContextNoCreate, ref stackMark);
     System.Threading.HostExecutionContext context3 = HostExecutionContextManager.CaptureHostExecutionContext();
     System.Threading.SynchronizationContext context4 = null;
     if ((executionContextNoCreate != null) && !flag)
     {
         context4 = (executionContextNoCreate._syncContext == null) ? null : executionContextNoCreate._syncContext.CreateCopy();
     }
     System.Runtime.Remoting.Messaging.LogicalCallContext context5 = null;
     if (((executionContextNoCreate != null) && (executionContextNoCreate._logicalCallContext != null)) && executionContextNoCreate.LogicalCallContext.HasInfo)
     {
         context5 = (System.Runtime.Remoting.Messaging.LogicalCallContext) executionContextNoCreate.LogicalCallContext.Clone();
     }
     if (((flag2 && (context2 == null)) && ((context3 == null) && (context4 == null))) && ((context5 == null) || !context5.HasInfo))
     {
         return s_dummyDefaultEC;
     }
     ExecutionContext context6 = new ExecutionContext {
         SecurityContext = context2
     };
     if (context6.SecurityContext != null)
     {
         context6.SecurityContext.ExecutionContext = context6;
     }
     context6._hostExecutionContext = context3;
     context6._syncContext = context4;
     context6.LogicalCallContext = context5;
     context6.isNewCapture = true;
     return context6;
 }
Beispiel #23
0
 private extern void AddTimerNative(Object state,
                                    UInt32 dueTime,
                                    UInt32 period,
                                    ref StackCrawlMark stackMark
                                    );
Beispiel #24
0
        [System.Security.SecurityCritical]  // auto-generated
        static internal ExecutionContext Capture(ref StackCrawlMark stackMark, CaptureOptions options)
        {
            ExecutionContext.Reader ecCurrent = Thread.CurrentThread.GetExecutionContextReader();

            // check to see if Flow is suppressed
            if (ecCurrent.IsFlowSuppressed)
            {
                return(null);
            }

            //
            // Attempt to capture context.  There may be nothing to capture...
            //

#if FEATURE_IMPERSONATION || FEATURE_COMPRESSEDSTACK
            // capture the security context
            SecurityContext secCtxNew = SecurityContext.Capture(ecCurrent, ref stackMark);
#endif // #if FEATURE_IMPERSONATION || FEATURE_COMPRESSEDSTACK
#if FEATURE_CAS_POLICY
            // capture the host execution context
            HostExecutionContext hostCtxNew = HostExecutionContextManager.CaptureHostExecutionContext();
#endif // FEATURE_CAS_POLICY

#if FEATURE_SYNCHRONIZATIONCONTEXT
            SynchronizationContext syncCtxNew = null;
#endif
            LogicalCallContext logCtxNew = null;

            if (!ecCurrent.IsNull)
            {
#if FEATURE_SYNCHRONIZATIONCONTEXT
                // capture the [....] context
                if (0 == (options & CaptureOptions.IgnoreSyncCtx))
                {
                    syncCtxNew = (ecCurrent.SynchronizationContext == null) ? null : ecCurrent.SynchronizationContext.CreateCopy();
                }
#endif // #if FEATURE_SYNCHRONIZATIONCONTEXT

                // copy over the Logical Call Context
                if (ecCurrent.LogicalCallContext.HasInfo)
                {
                    logCtxNew = ecCurrent.LogicalCallContext.Clone();
                }
            }

            //
            // If we didn't get anything but defaults, and we're allowed to return the
            // dummy default EC, don't bother allocating a new context.
            //
            if (0 != (options & CaptureOptions.OptimizeDefaultCase) &&
#if FEATURE_IMPERSONATION || FEATURE_COMPRESSEDSTACK
                secCtxNew == null &&
#endif
#if FEATURE_CAS_POLICY
                hostCtxNew == null &&
#endif // FEATURE_CAS_POLICY
#if FEATURE_SYNCHRONIZATIONCONTEXT
                syncCtxNew == null &&
#endif // #if FEATURE_SYNCHRONIZATIONCONTEXT
                (logCtxNew == null || !logCtxNew.HasInfo))
            {
                return(s_dummyDefaultEC);
            }

            //
            // Allocate the new context, and fill it in.
            //
            ExecutionContext ecNew = new ExecutionContext();
#if FEATURE_IMPERSONATION || FEATURE_COMPRESSEDSTACK
            ecNew.SecurityContext = secCtxNew;
            if (ecNew.SecurityContext != null)
            {
                ecNew.SecurityContext.ExecutionContext = ecNew;
            }
#endif
#if FEATURE_CAS_POLICY
            ecNew._hostExecutionContext = hostCtxNew;
#endif // FEATURE_CAS_POLICY
#if FEATURE_SYNCHRONIZATIONCONTEXT
            ecNew._syncContext = syncCtxNew;
#endif // #if FEATURE_SYNCHRONIZATIONCONTEXT
            ecNew.LogicalCallContext = logCtxNew;
            ecNew.isNewCapture       = true;

            return(ecNew);
        }
Beispiel #25
0
        [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable
        public new void Start()
        {
            StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;

            Start(ref stackMark);
        }
Beispiel #26
0
        [HandleProcessCorruptedStateExceptions]             //
#endif // FEATURE_CORRUPTING_EXCEPTIONS
        internal static ExecutionContextSwitcher SetExecutionContext(ExecutionContext executionContext, bool preserveSyncCtx)
        {
#if FEATURE_IMPERSONATION || FEATURE_COMPRESSEDSTACK
            StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
#endif // #if FEATURE_IMPERSONATION || FEATURE_COMPRESSEDSTACK

            Contract.Assert(executionContext != null);
            Contract.Assert(executionContext != s_dummyDefaultEC);

            // Set up the switcher object to return;
            ExecutionContextSwitcher ecsw = new ExecutionContextSwitcher();

            Thread currentThread            = Thread.CurrentThread;
            ExecutionContext.Reader outerEC = currentThread.GetExecutionContextReader();

            ecsw.thread  = currentThread;
            ecsw.outerEC = outerEC;
            ecsw.outerECBelongsToScope = currentThread.ExecutionContextBelongsToCurrentScope;

            if (preserveSyncCtx)
            {
                executionContext.SynchronizationContext = outerEC.SynchronizationContext;
            }
            executionContext.SynchronizationContextNoFlow = outerEC.SynchronizationContextNoFlow;

            currentThread.SetExecutionContext(executionContext, belongsToCurrentScope: true);

            RuntimeHelpers.PrepareConstrainedRegions();
            try
            {
#if FEATURE_IMPERSONATION || FEATURE_COMPRESSEDSTACK
                //set the security context
                SecurityContext sc = executionContext.SecurityContext;
                if (sc != null)
                {
                    // non-null SC: needs to be set
                    SecurityContext.Reader prevSeC = outerEC.SecurityContext;
                    ecsw.scsw = SecurityContext.SetSecurityContext(sc, prevSeC, false, ref stackMark);
                }
                else if (!SecurityContext.CurrentlyInDefaultFTSecurityContext(ecsw.outerEC))
                {
                    // null incoming SC, but we're currently not in FT: use static FTSC to set
                    SecurityContext.Reader prevSeC = outerEC.SecurityContext;
                    ecsw.scsw = SecurityContext.SetSecurityContext(SecurityContext.FullTrustSecurityContext, prevSeC, false, ref stackMark);
                }
#endif // #if FEATURE_IMPERSONATION || FEATURE_COMPRESSEDSTACK
#if FEATURE_CAS_POLICY
                // set the Host Context
                HostExecutionContext hostContext = executionContext.HostExecutionContext;
                if (hostContext != null)
                {
                    ecsw.hecsw = HostExecutionContextManager.SetHostExecutionContextInternal(hostContext);
                }
#endif // FEATURE_CAS_POLICY
            }
            catch
            {
                ecsw.UndoNoThrow();
                throw;
            }
            return(ecsw);
        }
Beispiel #27
0
 internal static extern DeserializationTracker GetThreadDeserializationTracker(ref StackCrawlMark stackMark);
Beispiel #28
0
        public static ExecutionContext Capture()
        {
            StackCrawlMark lookForMyCaller = StackCrawlMark.LookForMyCaller;

            return(Capture(ref lookForMyCaller, CaptureOptions.None));
        }
Beispiel #29
0
        internal static RuntimeAssembly InternalLoadAssemblyName(AssemblyName assemblyRef, ref StackCrawlMark stackMark, AssemblyLoadContext?assemblyLoadContext = null)
        {
#if FEATURE_APPX
            if (ApplicationModel.IsUap)
            {
                if (assemblyRef.CodeBase != null)
                {
                    throw new NotSupportedException(SR.Format(SR.NotSupported_AppX, "Assembly.LoadFrom"));
                }
            }
#endif

            assemblyRef = (AssemblyName)assemblyRef.Clone();
            if (assemblyRef.ProcessorArchitecture != ProcessorArchitecture.None)
            {
                // PA does not have a semantics for by-name binds for execution
                assemblyRef.ProcessorArchitecture = ProcessorArchitecture.None;
            }

            string?codeBase = VerifyCodeBase(assemblyRef.CodeBase);

            return(nLoad(assemblyRef, codeBase, null, ref stackMark, true, assemblyLoadContext));
        }
Beispiel #30
0
 private static extern IRuntimeMethodInfo _GetCurrentMethod(ref StackCrawlMark stackMark);
        internal static Delegate CreateDelegateInternal(RuntimeType rtType, RuntimeMethodInfo rtMethod, Object firstArgument, DelegateBindingFlags flags, ref StackCrawlMark stackMark)
        {
            Contract.Assert((flags & DelegateBindingFlags.SkipSecurityChecks) == 0);

#if FEATURE_APPX
            bool nonW8PMethod = (rtMethod.InvocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_NON_W8P_FX_API) != 0;
            bool nonW8PType = (rtType.InvocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_NON_W8P_FX_API) != 0;
            if (nonW8PMethod || nonW8PType)
            {
                RuntimeAssembly caller = RuntimeAssembly.GetExecutingAssembly(ref stackMark);
                if (caller != null && !caller.IsSafeForReflection())
                    throw new InvalidOperationException(
                        Environment.GetResourceString("InvalidOperation_APIInvalidForCurrentContext",
                                                      nonW8PMethod ? rtMethod.FullName : rtType.FullName));
            }
#endif

            return UnsafeCreateDelegate(rtType, rtMethod, firstArgument, flags);
        }
Beispiel #32
0
        [System.Security.SecuritySafeCritical]  // auto-generated
        internal static RuntimeType GetTypeByName(string name, bool throwOnError, bool ignoreCase, bool reflectionOnly, ref StackCrawlMark stackMark,
                                                  IntPtr pPrivHostBinder,
                                                  bool loadTypeFromPartialName)
        {
            if (name == null || name.Length == 0)
            {
                if (throwOnError)
                    throw new TypeLoadException(Environment.GetResourceString("Arg_TypeLoadNullStr"));

                return null;
            }

            RuntimeType type = null;

            Object keepAlive = null;
            GetTypeByName(name, throwOnError, ignoreCase, reflectionOnly,
                JitHelpers.GetStackCrawlMarkHandle(ref stackMark),
                pPrivHostBinder,
                loadTypeFromPartialName, JitHelpers.GetObjectHandleOnStack(ref type), JitHelpers.GetObjectHandleOnStack(ref keepAlive));
            GC.KeepAlive(keepAlive);

            return type;
        }
Beispiel #33
0
 [System.Security.SecuritySafeCritical]  // auto-generated
 internal static RuntimeType GetCallerType(ref StackCrawlMark stackMark)
 {
     RuntimeType type = null;
     GetCallerType(JitHelpers.GetStackCrawlMarkHandle(ref stackMark), JitHelpers.GetObjectHandleOnStack(ref type));
     return type;
 }
Beispiel #34
0
        internal TimerQueueTimer(TimerCallback timerCallback, object state, uint dueTime, uint period, ref StackCrawlMark stackMark)
        {
            m_timerCallback = timerCallback;
            m_state         = state;
            m_dueTime       = Timeout.UnsignedInfinite;
            m_period        = Timeout.UnsignedInfinite;

            if (!ExecutionContext.IsFlowSuppressed())
            {
                m_executionContext = ExecutionContext.Capture(
                    ref stackMark,
                    ExecutionContext.CaptureOptions.IgnoreSyncCtx | ExecutionContext.CaptureOptions.OptimizeDefaultCase);
            }

            //
            // After the following statement, the timer may fire.  No more manipulation of timer state outside of
            // the lock is permitted beyond this point!
            //
            if (dueTime != Timeout.UnsignedInfinite)
            {
                Change(dueTime, period);
            }
        }
 private extern void StartInternal(IPrincipal principal, ref StackCrawlMark stackMark);
Beispiel #36
0
 internal QueueUserWorkItemCallback(WaitCallback waitCallback, object stateObj, bool compressStack, ref StackCrawlMark stackMark)
 {
     this.callback = waitCallback;
     this.state    = stateObj;
     if (!compressStack || ExecutionContext.IsFlowSuppressed())
     {
         return;
     }
     this.context = ExecutionContext.Capture(ref stackMark, ExecutionContext.CaptureOptions.IgnoreSyncCtx | ExecutionContext.CaptureOptions.OptimizeDefaultCase);
 }
        public void Start()
        {
            StackCrawlMark lookForMyCaller = StackCrawlMark.LookForMyCaller;

            this.Start(ref lookForMyCaller);
        }
Beispiel #38
0
 private extern void StartInternal(ref StackCrawlMark stackMark);
Beispiel #39
0
        [System.Security.DynamicSecurityMethod] // Methods containing StackCrawlMark local var has to be marked DynamicSecurityMethod
        public override Stream GetManifestResourceStream(String name)
        {
            StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;

            return(GetManifestResourceStream(name, ref stackMark, false));
        }
 internal TimerQueueTimer(TimerCallback timerCallback, object state, uint dueTime, uint period, ref StackCrawlMark stackMark)
 {
     this.m_timerCallback = timerCallback;
     this.m_state         = state;
     this.m_dueTime       = uint.MaxValue;
     this.m_period        = uint.MaxValue;
     if (!ExecutionContext.IsFlowSuppressed())
     {
         this.m_executionContext = ExecutionContext.Capture(ref stackMark, ExecutionContext.CaptureOptions.IgnoreSyncCtx | ExecutionContext.CaptureOptions.OptimizeDefaultCase);
     }
     if (dueTime != 4294967295U)
     {
         this.Change(dueTime, period);
     }
 }
Beispiel #41
0
 internal static RuntimeAssembly InternalLoad(AssemblyName assemblyName, ref StackCrawlMark stackMark, AssemblyLoadContext?assemblyLoadContext = null)
 => InternalLoad(assemblyName, requestingAssembly: null, ref stackMark, throwOnFileNotFound: true, assemblyLoadContext);
Beispiel #42
0
 private static extern RuntimeAssembly nLoad(AssemblyName fileName,
                                             string?codeBase,
                                             RuntimeAssembly?assemblyContext,
                                             ref StackCrawlMark stackMark,
                                             bool throwOnFileNotFound,
                                             AssemblyLoadContext?assemblyLoadContext = null);
 internal static RuntimeAssembly InternalLoad(string assemblyName, ref StackCrawlMark stackMark, AssemblyLoadContext?assemblyLoadContext = null)
 => InternalLoad(new AssemblyName(assemblyName), ref stackMark, assemblyLoadContext);
Beispiel #44
0
 [System.Security.SecuritySafeCritical]  // auto-generated
 internal static IRuntimeMethodInfo GetCurrentMethod(ref StackCrawlMark stackMark)
 {
     return _GetCurrentMethod(ref stackMark);
 }
 private static extern RuntimeAssembly nLoad(AssemblyName fileName,
                                             string codeBase,
                                             RuntimeAssembly assemblyContext,
                                             ref StackCrawlMark stackMark,
                                             bool throwOnFileNotFound,
                                             IntPtr ptrLoadContextBinder);
Beispiel #46
0
 // Wrapper function to reduce the need for ifdefs.
 internal static RuntimeType GetTypeByName(string name, bool throwOnError, bool ignoreCase, bool reflectionOnly, ref StackCrawlMark stackMark, bool loadTypeFromPartialName)
 {
     return GetTypeByName(name, throwOnError, ignoreCase, reflectionOnly, ref stackMark, IntPtr.Zero, loadTypeFromPartialName);
 }
Beispiel #47
0
 // Wrapper function to wrap the typical use of InternalLoad.
 internal static RuntimeAssembly InternalLoad(string assemblyString,
                                              ref StackCrawlMark stackMark)
 {
     return(InternalLoad(assemblyString, ref stackMark, IntPtr.Zero));
 }
Beispiel #48
0
 internal static Type GetTypeByName(string name, ref StackCrawlMark stackMark)
 {
     return GetTypeByName(name, false, false, false, ref stackMark, false);
 }
Beispiel #49
0
        internal static RuntimeAssembly InternalLoad(string assemblyString, ref StackCrawlMark stackMark, AssemblyLoadContext?assemblyLoadContext = null)
        {
            AssemblyName an = new AssemblyName(assemblyString);

            return(InternalLoadAssemblyName(an, ref stackMark, assemblyLoadContext));
        }
Beispiel #50
0
        private ResourceSet InternalGetResourceSet(CultureInfo requestedCulture, bool createIfNotExists, bool tryParents, ref StackCrawlMark stackMark)
        {
            Dictionary<String, ResourceSet> localResourceSets = _resourceSets;
            ResourceSet rs = null;
            CultureInfo foundCulture = null;
            lock (localResourceSets) {
                if (localResourceSets.TryGetValue(requestedCulture.Name, out rs)) {
#if !FEATURE_CORECLR
                    if (FrameworkEventSource.IsInitialized) {
                        FrameworkEventSource.Log.ResourceManagerFoundResourceSetInCache(BaseNameField, MainAssembly, requestedCulture.Name);
                    }
#endif
                    return rs;
                }
            }

            ResourceFallbackManager mgr = new ResourceFallbackManager(requestedCulture, _neutralResourcesCulture, tryParents);

            foreach (CultureInfo currentCultureInfo in mgr)
            {
#if !FEATURE_CORECLR
                if (FrameworkEventSource.IsInitialized)
                {
                    FrameworkEventSource.Log.ResourceManagerLookingForResourceSet(BaseNameField, MainAssembly, currentCultureInfo.Name);
                }
#endif
                lock(localResourceSets) {
                    if (localResourceSets.TryGetValue(currentCultureInfo.Name, out rs)) {
#if !FEATURE_CORECLR
                        if (FrameworkEventSource.IsInitialized)
                        {
                            FrameworkEventSource.Log.ResourceManagerFoundResourceSetInCache(BaseNameField, MainAssembly, currentCultureInfo.Name);
                        }
#endif
                        // we need to update the cache if we fellback
                        if(requestedCulture != currentCultureInfo) foundCulture = currentCultureInfo;
                        break;
                    }
                }

                // InternalGetResourceSet will never be threadsafe.  However, it must
                // be protected against reentrancy from the SAME THREAD.  (ie, calling
                // GetSatelliteAssembly may send some window messages or trigger the
                // Assembly load event, which could fail then call back into the 
                // ResourceManager).  It's happened.

                rs = resourceGroveler.GrovelForResourceSet(currentCultureInfo, localResourceSets, 
                                                           tryParents, createIfNotExists, ref stackMark);

                // found a ResourceSet; we're done
                if (rs != null)
                {
                    foundCulture = currentCultureInfo;
                    break;
                }

            }

            if (rs != null && foundCulture != null)
            {
                // add entries to the cache for the cultures we have gone through

                // currentCultureInfo now refers to the culture that had resources.
                // update cultures starting from requested culture up to the culture
                // that had resources.
                foreach (CultureInfo updateCultureInfo in mgr)
                {
                    AddResourceSet(localResourceSets, updateCultureInfo.Name, ref rs);

                    // stop when we've added current or reached invariant (top of chain)
                    if (updateCultureInfo == foundCulture)
                    {
                        break;
                    }
                } 
            }

            return rs;
        }
Beispiel #51
0
        internal static RuntimeAssembly InternalLoadAssemblyName(AssemblyName assemblyRef, ref StackCrawlMark stackMark, AssemblyLoadContext?assemblyLoadContext = null)
        {
            assemblyRef = (AssemblyName)assemblyRef.Clone();
            if (assemblyRef.ProcessorArchitecture != ProcessorArchitecture.None)
            {
                // PA does not have a semantics for by-name binds for execution
                assemblyRef.ProcessorArchitecture = ProcessorArchitecture.None;
            }

            string?codeBase = VerifyCodeBase(assemblyRef.CodeBase);

            return(nLoad(assemblyRef, codeBase, null, ref stackMark, true, assemblyLoadContext));
        }