[MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable static public void GetZoneAndOrigin(out ArrayList zone, out ArrayList origin) { StackCrawlMark mark = StackCrawlMark.LookForMyCaller; CodeAccessSecurityEngine.GetZoneAndOrigin(ref mark, out zone, out origin); }
public override Object GetValue(Object obj) { StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; return(InternalGetValue(obj, ref stackMark)); }
private static extern MethodBase nativeGetCurrentMethod(ref StackCrawlMark stackMark);
private static extern Assembly nCreateDynamicAssembly(AssemblyName name, ref StackCrawlMark stackMark, AssemblyBuilderAccess access);
[System.Security.SecurityCritical] // auto-generated internal static void Assert(CodeAccessPermission cap, ref StackCrawlMark stackMark) { }
internal static extern void SpecialDemand(PermissionType whatPermission, ref StackCrawlMark stackMark);
public ResourceSet GrovelForResourceSet(CultureInfo culture, Dictionary <String, ResourceSet> localResourceSets, bool tryParents, bool createIfNotExists, ref StackCrawlMark stackMark) { Debug.Assert(culture != null, "culture shouldn't be null; check caller"); Debug.Assert(localResourceSets != null, "localResourceSets shouldn't be null; check caller"); ResourceSet rs = null; Stream stream = null; RuntimeAssembly satellite = null; // 1. Fixups for ultimate fallbacks CultureInfo lookForCulture = UltimateFallbackFixup(culture); // 2. Look for satellite assembly or main assembly, as appropriate if (lookForCulture.HasInvariantCultureName && _mediator.FallbackLoc == UltimateResourceFallbackLocation.MainAssembly) { // don't bother looking in satellites in this case satellite = _mediator.MainAssembly; } #if RESOURCE_SATELLITE_CONFIG // If our config file says the satellite isn't here, don't ask for it. else if (!lookForCulture.HasInvariantCultureName && !_mediator.TryLookingForSatellite(lookForCulture)) { satellite = null; } #endif else { satellite = GetSatelliteAssembly(lookForCulture, ref stackMark); if (satellite == null) { bool raiseException = (culture.HasInvariantCultureName && (_mediator.FallbackLoc == UltimateResourceFallbackLocation.Satellite)); // didn't find satellite, give error if necessary if (raiseException) { HandleSatelliteMissing(); } } } // get resource file name we'll search for. Note, be careful if you're moving this statement // around because lookForCulture may be modified from originally requested culture above. String fileName = _mediator.GetResourceFileName(lookForCulture); // 3. If we identified an assembly to search; look in manifest resource stream for resource file if (satellite != null) { // Handle case in here where someone added a callback for assembly load events. // While no other threads have called into GetResourceSet, our own thread can! // At that point, we could already have an RS in our hash table, and we don't // want to add it twice. lock (localResourceSets) { localResourceSets.TryGetValue(culture.Name, out rs); } stream = GetManifestResourceStream(satellite, fileName, ref stackMark); } // 4a. Found a stream; create a ResourceSet if possible if (createIfNotExists && stream != null && rs == null) { rs = CreateResourceSet(stream, satellite); } else if (stream == null && tryParents) { // 4b. Didn't find stream; give error if necessary bool raiseException = culture.HasInvariantCultureName; if (raiseException) { HandleResourceStreamMissing(fileName); } } return(rs); }
[System.Security.SecurityCritical] // auto-generated internal static void Check(PermissionSet permSet, ref StackCrawlMark stackMark) { }
public override void SetValue(Object obj, Object value, BindingFlags invokeAttr, Binder binder, CultureInfo culture) { StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; InternalSetValue(obj, value, invokeAttr, binder, culture, ref stackMark); }
private Stream GetManifestResourceStream(RuntimeAssembly satellite, String fileName, ref StackCrawlMark stackMark) { Debug.Assert(satellite != null, "satellite shouldn't be null; check caller"); Debug.Assert(fileName != null, "fileName shouldn't be null; check caller"); // If we're looking in the main assembly AND if the main assembly was the person who // created the ResourceManager, skip a security check for private manifest resources. bool canSkipSecurityCheck = (_mediator.MainAssembly == satellite) && (_mediator.CallingAssembly == _mediator.MainAssembly); Stream stream = satellite.GetManifestResourceStream(_mediator.LocationInfo, fileName, canSkipSecurityCheck, ref stackMark); if (stream == null) { stream = CaseInsensitiveManifestResourceStreamLookup(satellite, fileName); } return(stream); }
internal void InternalSetValue(Object obj, Object value, BindingFlags invokeAttr, Binder binder, CultureInfo culture, ref StackCrawlMark stackMark) { INVOCATION_FLAGS invocationFlags = InvocationFlags; RuntimeType declaringType = DeclaringType as RuntimeType; if ((invocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_NO_INVOKE) != 0) { if (declaringType != null && declaringType.ContainsGenericParameters) { throw new InvalidOperationException(SR.Arg_UnboundGenField); } if ((declaringType == null && Module.Assembly.ReflectionOnly) || declaringType is ReflectionOnlyType) { throw new InvalidOperationException(SR.Arg_ReflectionOnlyField); } throw new FieldAccessException(); } CheckConsistency(obj); RuntimeType fieldType = (RuntimeType)FieldType; value = fieldType.CheckValue(value, binder, culture, invokeAttr); bool domainInitialized = false; if (declaringType == null) { RuntimeFieldHandle.SetValue(this, obj, value, fieldType, m_fieldAttributes, null, ref domainInitialized); } else { domainInitialized = declaringType.DomainInitialized; RuntimeFieldHandle.SetValue(this, obj, value, fieldType, m_fieldAttributes, declaringType, ref domainInitialized); declaringType.DomainInitialized = domainInitialized; } }
internal static void Check(CodeAccessPermission cap, ref StackCrawlMark stackMark) { Check(cap, ref stackMark, false); }
private static extern void Check(Object demand, ref StackCrawlMark stackMark, bool isPermSet);
private static extern void GetZoneAndOriginInternal(ArrayList zoneList, ArrayList originList, ref StackCrawlMark stackMark);
extern static Assembly InternalLoadFile(IntPtr nativeAssemblyLoadContext, string assemblyFile, ref StackCrawlMark stackMark);
public ResourceSet GrovelForResourceSet(CultureInfo culture, Dictionary <string, ResourceSet> localResourceSets, bool tryParents, bool createIfNotExists, ref StackCrawlMark stackMark) { ResourceSet resourceSet = null; ResourceSet result; try { new FileIOPermission(PermissionState.Unrestricted).Assert(); string resourceFileName = this._mediator.GetResourceFileName(culture); string text = this.FindResourceFile(culture, resourceFileName); if (text == null) { if (tryParents && culture.HasInvariantCultureName) { throw new MissingManifestResourceException(string.Concat(new string[] { 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 { resourceSet = this.CreateResourceSet(text); } result = resourceSet; } finally { CodeAccessPermission.RevertAssert(); } return(result); }
[System.Security.SecurityCritical] // auto-generated private unsafe void Init(String name, MethodAttributes attributes, CallingConventions callingConvention, Type returnType, Type[] signature, Type owner, Module m, bool skipVisibility, bool transparentMethod, ref StackCrawlMark stackMark) { DynamicMethod.CheckConsistency(attributes, callingConvention); // check and store the signature if (signature != null) { m_parameterTypes = new RuntimeType[signature.Length]; for (int i = 0; i < signature.Length; i++) { if (signature[i] == null) { throw new ArgumentException(Environment.GetResourceString("Arg_InvalidTypeInSignature")); } m_parameterTypes[i] = signature[i].UnderlyingSystemType as RuntimeType; if (m_parameterTypes[i] == null || !(m_parameterTypes[i] is RuntimeType) || m_parameterTypes[i] == (RuntimeType)typeof(void)) { throw new ArgumentException(Environment.GetResourceString("Arg_InvalidTypeInSignature")); } } } else { m_parameterTypes = Array.Empty <RuntimeType>(); } // check and store the return value m_returnType = (returnType == null) ? (RuntimeType)typeof(void) : returnType.UnderlyingSystemType as RuntimeType; if ((m_returnType == null) || !(m_returnType is RuntimeType) || m_returnType.IsByRef) { throw new NotSupportedException(Environment.GetResourceString("Arg_InvalidTypeInRetType")); } if (transparentMethod) { Contract.Assert(owner == null && m == null, "owner and m cannot be set for transparent methods"); m_module = GetDynamicMethodsModule(); if (skipVisibility) { m_restrictedSkipVisibility = true; } #if FEATURE_COMPRESSEDSTACK m_creationContext = CompressedStack.Capture(); #endif // FEATURE_COMPRESSEDSTACK } else { Contract.Assert(m != null || owner != null, "PerformSecurityCheck should ensure that either m or owner is set"); Contract.Assert(m == null || !m.Equals(s_anonymouslyHostedDynamicMethodsModule), "The user cannot explicitly use this assembly"); Contract.Assert(m == null || owner == null, "m and owner cannot both be set"); if (m != null) { m_module = m.ModuleHandle.GetRuntimeModule(); // this returns the underlying module for all RuntimeModule and ModuleBuilder objects. } else { RuntimeType rtOwner = null; if (owner != null) { rtOwner = owner.UnderlyingSystemType as RuntimeType; } if (rtOwner != null) { if (rtOwner.HasElementType || rtOwner.ContainsGenericParameters || rtOwner.IsGenericParameter || rtOwner.IsInterface) { throw new ArgumentException(Environment.GetResourceString("Argument_InvalidTypeForDynamicMethod")); } m_typeOwner = rtOwner; m_module = rtOwner.GetRuntimeModule(); } } m_skipVisibility = skipVisibility; } // initialize remaining fields m_ilGenerator = null; m_fInitLocals = true; m_methodHandle = null; if (name == null) { throw new ArgumentNullException("name"); } #if FEATURE_APPX if (AppDomain.ProfileAPICheck) { if (m_creatorAssembly == null) { m_creatorAssembly = RuntimeAssembly.GetExecutingAssembly(ref stackMark); } if (m_creatorAssembly != null && !m_creatorAssembly.IsFrameworkAssembly()) { m_profileAPICheck = true; } } #endif // FEATURE_APPX m_dynMethod = new RTDynamicMethod(this, name, attributes, callingConvention); }
internal static extern FrameSecurityDescriptor CheckNReturnSO(PermissionToken permToken, CodeAccessPermission demand, ref StackCrawlMark stackMark, int create);
[MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable public override Object Invoke( Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) { INVOCATION_FLAGS invocationFlags = InvocationFlags; if ((invocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_NO_INVOKE) != 0) { ThrowNoInvokeException(); } // check basic method consistency. This call will throw if there are problems in the target/method relationship CheckConsistency(obj); #if FEATURE_APPX if ((invocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_NON_W8P_FX_API) != 0) { StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; RuntimeAssembly caller = RuntimeAssembly.GetExecutingAssembly(ref stackMark); if (caller != null && !caller.IsSafeForReflection()) { throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_APIInvalidForCurrentContext", FullName)); } } #endif if (obj != null) { #if FEATURE_CORECLR // For unverifiable code, we require the caller to be critical. // Adding the INVOCATION_FLAGS_NEED_SECURITY flag makes that check happen invocationFlags |= INVOCATION_FLAGS.INVOCATION_FLAGS_NEED_SECURITY; #else // FEATURE_CORECLR new SecurityPermission(SecurityPermissionFlag.SkipVerification).Demand(); #endif // FEATURE_CORECLR } if ((invocationFlags & (INVOCATION_FLAGS.INVOCATION_FLAGS_RISKY_METHOD | INVOCATION_FLAGS.INVOCATION_FLAGS_NEED_SECURITY)) != 0) { #if !FEATURE_CORECLR if ((invocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_RISKY_METHOD) != 0) { CodeAccessPermission.Demand(PermissionType.ReflectionMemberAccess); } if ((invocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_NEED_SECURITY) != 0) #endif // !FEATURE_CORECLR RuntimeMethodHandle.PerformSecurityCheck(obj, this, m_declaringType, (uint)m_invocationFlags); } Signature sig = Signature; // get the signature int formalCount = sig.Arguments.Length; int actualCount = (parameters != null) ? parameters.Length : 0; if (formalCount != actualCount) { throw new TargetParameterCountException(Environment.GetResourceString("Arg_ParmCnt")); } // if we are here we passed all the previous checks. Time to look at the arguments if (actualCount > 0) { Object[] arguments = CheckArguments(parameters, binder, invokeAttr, culture, sig); Object retValue = RuntimeMethodHandle.InvokeMethod(obj, arguments, sig, false); // copy out. This should be made only if ByRef are present. for (int index = 0; index < arguments.Length; index++) { parameters[index] = arguments[index]; } return(retValue); } return(RuntimeMethodHandle.InvokeMethod(obj, null, sig, false)); }
[System.Security.SecurityCritical] // auto-generated internal static void PermitOnly(CodeAccessPermission cap, ref StackCrawlMark stackMark) { }
[MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable public override Object Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) { INVOCATION_FLAGS invocationFlags = InvocationFlags; // get the declaring TypeHandle early for consistent exceptions in IntrospectionOnly context RuntimeTypeHandle declaringTypeHandle = m_declaringType.TypeHandle; if ((invocationFlags & (INVOCATION_FLAGS.INVOCATION_FLAGS_NO_INVOKE | INVOCATION_FLAGS.INVOCATION_FLAGS_CONTAINS_STACK_POINTERS | INVOCATION_FLAGS.INVOCATION_FLAGS_NO_CTOR_INVOKE)) != 0) { ThrowNoInvokeException(); } #if FEATURE_APPX if ((invocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_NON_W8P_FX_API) != 0) { StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; RuntimeAssembly caller = RuntimeAssembly.GetExecutingAssembly(ref stackMark); if (caller != null && !caller.IsSafeForReflection()) { throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_APIInvalidForCurrentContext", FullName)); } } #endif if ((invocationFlags & (INVOCATION_FLAGS.INVOCATION_FLAGS_RISKY_METHOD | INVOCATION_FLAGS.INVOCATION_FLAGS_NEED_SECURITY | INVOCATION_FLAGS.INVOCATION_FLAGS_IS_DELEGATE_CTOR)) != 0) { #if !FEATURE_CORECLR if ((invocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_RISKY_METHOD) != 0) { CodeAccessPermission.Demand(PermissionType.ReflectionMemberAccess); } if ((invocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_NEED_SECURITY) != 0) #endif // !FEATURE_CORECLR RuntimeMethodHandle.PerformSecurityCheck(null, this, m_declaringType, (uint)(m_invocationFlags | INVOCATION_FLAGS.INVOCATION_FLAGS_CONSTRUCTOR_INVOKE)); #if !FEATURE_CORECLR if ((invocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_IS_DELEGATE_CTOR) != 0) { new SecurityPermission(SecurityPermissionFlag.UnmanagedCode).Demand(); } #endif // !FEATURE_CORECLR } // get the signature Signature sig = Signature; int formalCount = sig.Arguments.Length; int actualCount = (parameters != null) ? parameters.Length : 0; if (formalCount != actualCount) { throw new TargetParameterCountException(Environment.GetResourceString("Arg_ParmCnt")); } // We don't need to explicitly invoke the class constructor here, // JIT/NGen will insert the call to .cctor in the instance ctor. // if we are here we passed all the previous checks. Time to look at the arguments if (actualCount > 0) { Object[] arguments = CheckArguments(parameters, binder, invokeAttr, culture, sig); Object retValue = RuntimeMethodHandle.InvokeMethod(null, arguments, sig, true); // copy out. This should be made only if ByRef are present. for (int index = 0; index < arguments.Length; index++) { parameters[index] = arguments[index]; } return(retValue); } return(RuntimeMethodHandle.InvokeMethod(null, null, sig, true)); }
// Wraps StackCrawlMark into a handle. Used to pass StackCrawlMark to QCalls. // stackMark has to be a local variable on the stack. static internal StackCrawlMarkHandle GetStackCrawlMarkHandle(ref StackCrawlMark stackMark) { return(new StackCrawlMarkHandle(UnsafeCastToStackPointer(ref stackMark))); }
[MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable public void Assert() { StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; CodeAccessSecurityEngine.Assert(this, ref stackMark); }
[DynamicSecurityMethod] // Methods containing StackCrawlMark local var has to be marked DynamicSecurityMethod. public static AssemblyBuilder DefineDynamicAssembly(AssemblyName name, AssemblyBuilderAccess access) { StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; return(InternalDefineDynamicAssembly(name, access, ref stackMark, null)); }
[MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable public void PermitOnly() { StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; CodeAccessSecurityEngine.PermitOnly(this, ref stackMark); }
[MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable public static MethodBase GetCurrentMethod() { StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; return(RuntimeMethodInfo.InternalGetCurrentMethod(ref stackMark)); }
[MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable public static void RevertAll() { StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; SecurityRuntime.RevertAll(ref stackMark); }
internal void InternalSetValue(Object obj, Object value, BindingFlags invokeAttr, Binder binder, CultureInfo culture, ref StackCrawlMark stackMark) { INVOCATION_FLAGS invocationFlags = InvocationFlags; RuntimeType declaringType = DeclaringType as RuntimeType; if ((invocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_NO_INVOKE) != 0) { if (declaringType != null && declaringType.ContainsGenericParameters) { throw new InvalidOperationException(Environment.GetResourceString("Arg_UnboundGenField")); } if ((declaringType == null && Module.Assembly.ReflectionOnly) || declaringType is ReflectionOnlyType) { throw new InvalidOperationException(Environment.GetResourceString("Arg_ReflectionOnlyField")); } throw new FieldAccessException(); } CheckConsistency(obj); RuntimeType fieldType = (RuntimeType)FieldType; value = fieldType.CheckValue(value, binder, culture, invokeAttr); #region Security Check #if FEATURE_APPX if ((invocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_NON_W8P_FX_API) != 0) { RuntimeAssembly caller = RuntimeAssembly.GetExecutingAssembly(ref stackMark); if (caller != null && !caller.IsSafeForReflection()) { throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_APIInvalidForCurrentContext", FullName)); } } #endif if ((invocationFlags & (INVOCATION_FLAGS.INVOCATION_FLAGS_SPECIAL_FIELD | INVOCATION_FLAGS.INVOCATION_FLAGS_NEED_SECURITY)) != 0) { PerformVisibilityCheckOnField(m_fieldHandle, obj, m_declaringType, m_fieldAttributes, (uint)m_invocationFlags); } #endregion bool domainInitialized = false; if (declaringType == null) { RuntimeFieldHandle.SetValue(this, obj, value, fieldType, m_fieldAttributes, null, ref domainInitialized); } else { domainInitialized = declaringType.DomainInitialized; RuntimeFieldHandle.SetValue(this, obj, value, fieldType, m_fieldAttributes, declaringType, ref domainInitialized); declaringType.DomainInitialized = domainInitialized; } }
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)); }
internal static ExecutionContext Capture (ref StackCrawlMark stackMark, CaptureOptions options) { // For References sources compatibility only return null; }
internal static RuntimeAssembly InternalLoadAssemblyName(AssemblyName assemblyRef, ref StackCrawlMark stackMark, IntPtr ptrLoadContextBinder = default) { return((RuntimeAssembly)InternalLoad(assemblyRef.FullName, ref stackMark, ptrLoadContextBinder)); }