// On CoreCLR, the host is in charge of determining whether the process is AppX or not.
void SetIsAppXProcess(bool);
- inline bool IsAppXNGen()
- {
- WRAPPER_NO_CONTRACT;
- return false;
- }
-
#ifdef DACCESS_COMPILE
bool DacIsAppXProcess();
#endif // DACCESS_COMPILE
#ifdef FEATURE_RANDOMIZED_STRING_HASHING
RETAIL_CONFIG_DWORD_INFO(EXTERNAL_UseRandomizedStringHashAlgorithm, W("UseRandomizedStringHashAlgorithm"), 0, "Flag to use a string hashing algorithm who's behavior differs between AppDomains")
#endif // FEATURE_RANDOMIZED_STRING_HASHING
-#ifdef FEATURE_APPX
-RETAIL_CONFIG_DWORD_INFO(INTERNAL_Windows8ProfileAPICheckFlag, W("Windows8ProfileAPICheckFlag"), 0, "Windows 8 Profile API check behavior (non-W8P framework APIs cannot be accessed through Reflection and RefEmit). 0: normal (only check in non-dev-mode APPX). 1: always check. 2: never check.");
-#endif
//
// Conditional breakpoints
APPX_FLAGS_APPX_MODEL = 0x02,
APPX_FLAGS_APPX_DESIGN_MODE = 0x04,
- APPX_FLAGS_APPX_NGEN = 0x08,
APPX_FLAGS_APPX_MASK = APPX_FLAGS_APPX_MODEL |
- APPX_FLAGS_APPX_DESIGN_MODE |
- APPX_FLAGS_APPX_NGEN,
-
- APPX_FLAGS_API_CHECK = 0x10,
+ APPX_FLAGS_APPX_DESIGN_MODE,
}
private static APPX_FLAGS Flags
return s_flags;
}
}
-
- internal static bool ProfileAPICheck
- {
- get
- {
- return (Flags & APPX_FLAGS.APPX_FLAGS_API_CHECK) != 0;
- }
- }
-
- internal static bool IsAppXNGen
- {
- get
- {
- return (Flags & APPX_FLAGS.APPX_FLAGS_APPX_NGEN) != 0;
- }
- }
#endif // FEATURE_APPX
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
{
Debug.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);
}
return null;
}
- // If running within a compilation process (mscorsvw.exe, for example), it is illegal to
- // load any non-mscorlib assembly for execution. Since WindowsRuntimeResourceManager lives
- // in System.Runtime.WindowsRuntime, caller will need to fall back to default Win32 value,
- // which should be fine because we should only ever need to access FX resources during NGEN.
- // FX resources are always loaded from satellite assemblies - even in AppX processes (see the
- // comments in code:System.Resources.ResourceManager.SetAppXConfiguration for more details).
- if (AppDomain.IsAppXNGen)
- {
- return null;
- }
-
CultureInfo toReturn = null;
try
internal static bool SetCultureInfoForUserPreferredLanguageInAppX(CultureInfo ci)
{
- // If running within a compilation process (mscorsvw.exe, for example), it is illegal to
- // load any non-mscorlib assembly for execution. Since WindowsRuntimeResourceManager lives
- // in System.Runtime.WindowsRuntime, caller will need to fall back to default Win32 value,
- // which should be fine because we should only ever need to access FX resources during NGEN.
- // FX resources are always loaded from satellite assemblies - even in AppX processes (see the
- // comments in code:System.Resources.ResourceManager.SetAppXConfiguration for more details).
- if (AppDomain.IsAppXNGen)
- {
- return false;
- }
-
if (s_WindowsRuntimeResourceManager == null)
{
s_WindowsRuntimeResourceManager = ResourceManager.GetWinRTResourceManager();
ASSEMBLY_FLAGS_UNKNOWN = 0x00000000,
ASSEMBLY_FLAGS_INITIALIZED = 0x01000000,
ASSEMBLY_FLAGS_FRAMEWORK = 0x02000000,
- ASSEMBLY_FLAGS_SAFE_REFLECTION = 0x04000000,
ASSEMBLY_FLAGS_TOKEN_MASK = 0x00FFFFFF,
}
#endif // FEATURE_APPX
#endregion
#if FEATURE_APPX
- internal int InvocableAttributeCtorToken
- {
- get
- {
- int token = (int)(Flags & ASSEMBLY_FLAGS.ASSEMBLY_FLAGS_TOKEN_MASK);
-
- return token | (int)MetadataTokenType.MethodDef;
- }
- }
-
private ASSEMBLY_FLAGS Flags
{
get
if ((m_flags & ASSEMBLY_FLAGS.ASSEMBLY_FLAGS_INITIALIZED) == 0)
{
ASSEMBLY_FLAGS flags = ASSEMBLY_FLAGS.ASSEMBLY_FLAGS_UNKNOWN
- | ASSEMBLY_FLAGS.ASSEMBLY_FLAGS_FRAMEWORK | ASSEMBLY_FLAGS.ASSEMBLY_FLAGS_SAFE_REFLECTION;
+ | ASSEMBLY_FLAGS.ASSEMBLY_FLAGS_FRAMEWORK;
m_flags = flags | ASSEMBLY_FLAGS.ASSEMBLY_FLAGS_INITIALIZED;
}
ASSEMBLY_FLAGS flags = Flags;
return (flags & ASSEMBLY_FLAGS.ASSEMBLY_FLAGS_FRAMEWORK) != 0;
}
-
- // Returns true if we want to allow this assembly to invoke non-W8P
- // framework APIs through reflection.
- internal bool IsSafeForReflection()
- {
- ASSEMBLY_FLAGS flags = Flags;
- return (flags & ASSEMBLY_FLAGS.ASSEMBLY_FLAGS_SAFE_REFLECTION) != 0;
- }
#endif
[MethodImplAttribute(MethodImplOptions.InternalCall)]
private volatile Signature m_signature;
private INVOCATION_FLAGS m_invocationFlags;
-#if FEATURE_APPX
- private bool IsNonW8PFrameworkAPI()
- {
- if (DeclaringType.IsArray && IsPublic && !IsStatic)
- return false;
-
- RuntimeAssembly rtAssembly = GetRuntimeAssembly();
- if (rtAssembly.IsFrameworkAssembly())
- {
- int ctorToken = rtAssembly.InvocableAttributeCtorToken;
- if (System.Reflection.MetadataToken.IsNullToken(ctorToken) ||
- !CustomAttribute.IsAttributeDefined(GetRuntimeModule(), MetadataToken, ctorToken))
- return true;
- }
-
- if (GetRuntimeType().IsNonW8PFrameworkAPI())
- return true;
-
- return false;
- }
-#endif // FEATURE_APPX
-
internal INVOCATION_FLAGS InvocationFlags
{
get
invocationFlags |= INVOCATION_FLAGS.INVOCATION_FLAGS_IS_DELEGATE_CTOR;
}
-#if FEATURE_APPX
- if (AppDomain.ProfileAPICheck && IsNonW8PFrameworkAPI())
- invocationFlags |= INVOCATION_FLAGS.INVOCATION_FLAGS_NON_W8P_FX_API;
-#endif // FEATURE_APPX
-
m_invocationFlags = invocationFlags | INVOCATION_FLAGS.INVOCATION_FLAGS_INITIALIZED;
}
// 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)
{
// For unverifiable code, we require the caller to be critical.
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
-
// get the signature
Signature sig = Signature;
private bool m_fManifestModuleUsedAsDefinedModule;
internal const string MANIFEST_MODULE_NAME = "RefEmit_InMemoryManifestModule";
-#if FEATURE_APPX
- private bool m_profileAPICheck;
-#endif
-
internal ModuleBuilder GetModuleBuilder(InternalModuleBuilder module)
{
Contract.Requires(module != null);
{
return InternalAssembly.GetNativeHandle();
}
-
-#if FEATURE_APPX
- internal bool ProfileAPICheck
- {
- get
- {
- return m_profileAPICheck;
- }
- }
-#endif
#endregion
#region Constructor
name.Name,
access,
dir);
-#if FEATURE_APPX
- if (AppDomain.ProfileAPICheck)
- {
- RuntimeAssembly creator = RuntimeAssembly.GetExecutingAssembly(ref stackMark);
- if (creator != null && !creator.IsFrameworkAssembly())
- m_profileAPICheck = true;
- }
-#endif
+
// Make sure that ManifestModule is properly initialized
// We need to do this before setting any CustomAttribute
InitManifestModule();
new DynamicResolver(this));
}
-#if FEATURE_APPX
- private bool ProfileAPICheck
- {
- get
- {
- return ((DynamicMethod)m_methodBuilder).ProfileAPICheck;
- }
- }
-#endif // FEATURE_APPX
-
// *** ILGenerator api ***
public override LocalBuilder DeclareLocal(Type localType, bool pinned)
if (rtType == null)
throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeType"));
-#if FEATURE_APPX
- if (ProfileAPICheck && (rtType.InvocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_NON_W8P_FX_API) != 0)
- throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_APIInvalidForCurrentContext", rtType.FullName));
-#endif
-
localBuilder = new LocalBuilder(m_localCount, localType, m_methodBuilder);
// add the localType to local signature
m_localSignature.AddArgument(localType, pinned);
#region GetTokenFor helpers
private int GetTokenFor(RuntimeType rtType)
{
-#if FEATURE_APPX
- if (ProfileAPICheck && (rtType.InvocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_NON_W8P_FX_API) != 0)
- throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_APIInvalidForCurrentContext", rtType.FullName));
-#endif
-
return m_scope.GetTokenFor(rtType.TypeHandle);
}
private int GetTokenFor(RuntimeFieldInfo runtimeField)
{
-#if FEATURE_APPX
- if (ProfileAPICheck)
- {
- RtFieldInfo rtField = runtimeField as RtFieldInfo;
- if (rtField != null && (rtField.InvocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_NON_W8P_FX_API) != 0)
- throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_APIInvalidForCurrentContext", rtField.FullName));
- }
-#endif
-
return m_scope.GetTokenFor(runtimeField.FieldHandle);
}
private int GetTokenFor(RuntimeFieldInfo runtimeField, RuntimeType rtType)
{
-#if FEATURE_APPX
- if (ProfileAPICheck)
- {
- RtFieldInfo rtField = runtimeField as RtFieldInfo;
- if (rtField != null && (rtField.InvocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_NON_W8P_FX_API) != 0)
- throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_APIInvalidForCurrentContext", rtField.FullName));
-
- if ((rtType.InvocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_NON_W8P_FX_API) != 0)
- throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_APIInvalidForCurrentContext", rtType.FullName));
- }
-#endif
-
return m_scope.GetTokenFor(runtimeField.FieldHandle, rtType.TypeHandle);
}
private int GetTokenFor(RuntimeConstructorInfo rtMeth)
{
-#if FEATURE_APPX
- if (ProfileAPICheck && (rtMeth.InvocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_NON_W8P_FX_API) != 0)
- throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_APIInvalidForCurrentContext", rtMeth.FullName));
-#endif
-
return m_scope.GetTokenFor(rtMeth.MethodHandle);
}
private int GetTokenFor(RuntimeConstructorInfo rtMeth, RuntimeType rtType)
{
-#if FEATURE_APPX
- if (ProfileAPICheck)
- {
- if ((rtMeth.InvocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_NON_W8P_FX_API) != 0)
- throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_APIInvalidForCurrentContext", rtMeth.FullName));
-
- if ((rtType.InvocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_NON_W8P_FX_API) != 0)
- throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_APIInvalidForCurrentContext", rtType.FullName));
- }
-#endif
-
return m_scope.GetTokenFor(rtMeth.MethodHandle, rtType.TypeHandle);
}
private int GetTokenFor(RuntimeMethodInfo rtMeth)
{
-#if FEATURE_APPX
- if (ProfileAPICheck && (rtMeth.InvocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_NON_W8P_FX_API) != 0)
- throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_APIInvalidForCurrentContext", rtMeth.FullName));
-#endif
-
return m_scope.GetTokenFor(rtMeth.MethodHandle);
}
private int GetTokenFor(RuntimeMethodInfo rtMeth, RuntimeType rtType)
{
-#if FEATURE_APPX
- if (ProfileAPICheck)
- {
- if ((rtMeth.InvocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_NON_W8P_FX_API) != 0)
- throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_APIInvalidForCurrentContext", rtMeth.FullName));
-
- if ((rtType.InvocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_NON_W8P_FX_API) != 0)
- throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_APIInvalidForCurrentContext", rtType.FullName));
- }
-#endif
-
return m_scope.GetTokenFor(rtMeth.MethodHandle, rtType.TypeHandle);
}
private int GetTokenForVarArgMethod(RuntimeMethodInfo rtMeth, SignatureHelper sig)
{
-#if FEATURE_APPX
- if (ProfileAPICheck && (rtMeth.InvocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_NON_W8P_FX_API) != 0)
- throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_APIInvalidForCurrentContext", rtMeth.FullName));
-#endif
VarArgMethod varArgMeth = new VarArgMethod(rtMeth, sig);
return m_scope.GetTokenFor(varArgMeth);
}
// assigned by the DynamicResolver ctor
internal DynamicResolver m_resolver;
- // Always false unless we are in an immersive (non dev mode) process.
-#if FEATURE_APPX
- private bool m_profileAPICheck;
-
- private RuntimeAssembly m_creatorAssembly;
-#endif
-
internal bool m_restrictedSkipVisibility;
// The context when the method was created. We use this to do the RestrictedMemberAccess checks.
// These checks are done when the method is compiled. This can happen at an arbitrary time,
private DynamicMethod() { }
- [System.Security.DynamicSecurityMethod] // Methods containing StackCrawlMark local var has to be marked DynamicSecurityMethod
public DynamicMethod(string name,
Type returnType,
Type[] parameterTypes)
{
- StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
-
Init(name,
MethodAttributes.Public | MethodAttributes.Static,
CallingConventions.Standard,
null, // owner
null, // m
false, // skipVisibility
- true,
- ref stackMark); // transparentMethod
+ true);
}
- [System.Security.DynamicSecurityMethod] // Methods containing StackCrawlMark local var has to be marked DynamicSecurityMethod
public DynamicMethod(string name,
Type returnType,
Type[] parameterTypes,
bool restrictedSkipVisibility)
{
- StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
-
Init(name,
MethodAttributes.Public | MethodAttributes.Static,
CallingConventions.Standard,
null, // owner
null, // m
restrictedSkipVisibility,
- true,
- ref stackMark); // transparentMethod
+ true);
}
- [System.Security.DynamicSecurityMethod] // Methods containing StackCrawlMark local var has to be marked DynamicSecurityMethod
public DynamicMethod(string name,
Type returnType,
Type[] parameterTypes,
Module m)
{
- StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
- PerformSecurityCheck(m, ref stackMark, false);
+ if (m == null)
+ throw new ArgumentNullException(nameof(m));
+
Init(name,
MethodAttributes.Public | MethodAttributes.Static,
CallingConventions.Standard,
null, // owner
m, // m
false, // skipVisibility
- false,
- ref stackMark); // transparentMethod
+ false);
}
- [System.Security.DynamicSecurityMethod] // Methods containing StackCrawlMark local var has to be marked DynamicSecurityMethod
public DynamicMethod(string name,
Type returnType,
Type[] parameterTypes,
Module m,
bool skipVisibility)
{
- StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
- PerformSecurityCheck(m, ref stackMark, skipVisibility);
+ if (m == null)
+ throw new ArgumentNullException(nameof(m));
+
Init(name,
MethodAttributes.Public | MethodAttributes.Static,
CallingConventions.Standard,
null, // owner
m, // m
skipVisibility,
- false,
- ref stackMark); // transparentMethod
+ false);
}
- [System.Security.DynamicSecurityMethod] // Methods containing StackCrawlMark local var has to be marked DynamicSecurityMethod
public DynamicMethod(string name,
MethodAttributes attributes,
CallingConventions callingConvention,
Module m,
bool skipVisibility)
{
- StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
- PerformSecurityCheck(m, ref stackMark, skipVisibility);
+ if (m == null)
+ throw new ArgumentNullException(nameof(m));
+
Init(name,
attributes,
callingConvention,
null, // owner
m, // m
skipVisibility,
- false,
- ref stackMark); // transparentMethod
+ false);
}
- [System.Security.DynamicSecurityMethod] // Methods containing StackCrawlMark local var has to be marked DynamicSecurityMethod
public DynamicMethod(string name,
Type returnType,
Type[] parameterTypes,
Type owner)
{
- StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
- PerformSecurityCheck(owner, ref stackMark, false);
+ if (owner == null)
+ throw new ArgumentNullException(nameof(owner));
+
Init(name,
MethodAttributes.Public | MethodAttributes.Static,
CallingConventions.Standard,
owner, // owner
null, // m
false, // skipVisibility
- false,
- ref stackMark); // transparentMethod
+ false);
}
- [System.Security.DynamicSecurityMethod] // Methods containing StackCrawlMark local var has to be marked DynamicSecurityMethod
public DynamicMethod(string name,
Type returnType,
Type[] parameterTypes,
Type owner,
bool skipVisibility)
{
- StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
- PerformSecurityCheck(owner, ref stackMark, skipVisibility);
+ if (owner == null)
+ throw new ArgumentNullException(nameof(owner));
+
Init(name,
MethodAttributes.Public | MethodAttributes.Static,
CallingConventions.Standard,
owner, // owner
null, // m
skipVisibility,
- false,
- ref stackMark); // transparentMethod
+ false);
}
- [System.Security.DynamicSecurityMethod] // Methods containing StackCrawlMark local var has to be marked DynamicSecurityMethod
public DynamicMethod(string name,
MethodAttributes attributes,
CallingConventions callingConvention,
Type owner,
bool skipVisibility)
{
- StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
- PerformSecurityCheck(owner, ref stackMark, skipVisibility);
+ if (owner == null)
+ throw new ArgumentNullException(nameof(owner));
+
Init(name,
attributes,
callingConvention,
owner, // owner
null, // m
skipVisibility,
- false,
- ref stackMark); // transparentMethod
+ false);
}
// helpers for intialization
Type owner,
Module m,
bool skipVisibility,
- bool transparentMethod,
- ref StackCrawlMark stackMark)
+ bool transparentMethod)
{
DynamicMethod.CheckConsistency(attributes, callingConvention);
}
else
{
- Debug.Assert(m != null || owner != null, "PerformSecurityCheck should ensure that either m or owner is set");
+ Debug.Assert(m != null || owner != null, "Constructor should ensure that either m or owner is set");
Debug.Assert(m == null || !m.Equals(s_anonymouslyHostedDynamicMethodsModule), "The user cannot explicitly use this assembly");
Debug.Assert(m == null || owner == null, "m and owner cannot both be set");
if (name == null)
throw new ArgumentNullException(nameof(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);
}
- private void PerformSecurityCheck(Module m, ref StackCrawlMark stackMark, bool skipVisibility)
- {
- if (m == null)
- throw new ArgumentNullException(nameof(m));
- Contract.EndContractBlock();
- }
-
- private void PerformSecurityCheck(Type owner, ref StackCrawlMark stackMark, bool skipVisibility)
- {
- if (owner == null)
- throw new ArgumentNullException(nameof(owner));
- }
-
//
// Delegate and method creation
//
return d;
}
-#if FEATURE_APPX
- internal bool ProfileAPICheck
- {
- get
- {
- return m_profileAPICheck;
- }
-
- [FriendAccessAllowed]
- set
- {
- m_profileAPICheck = value;
- }
- }
-#endif
-
// This is guaranteed to return a valid handle
internal unsafe RuntimeMethodHandle GetMethodDescriptor()
{
{
Debug.Assert(method != null);
-#if FEATURE_APPX
- if (ContainingAssemblyBuilder.ProfileAPICheck)
- {
- if ((method.InvocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_NON_W8P_FX_API) != 0)
- throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_APIInvalidForCurrentContext", method.FullName));
- }
-#endif
-
return GetMemberRefOfMethodInfo(GetNativeHandle(), tr, method);
}
{
Debug.Assert(method != null);
-#if FEATURE_APPX
- if (ContainingAssemblyBuilder.ProfileAPICheck)
- {
- if ((method.InvocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_NON_W8P_FX_API) != 0)
- throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_APIInvalidForCurrentContext", method.FullName));
- }
-#endif
-
return GetMemberRefOfMethodInfo(GetNativeHandle(), tr, method);
}
{
Debug.Assert(runtimeField != null);
-#if FEATURE_APPX
- if (ContainingAssemblyBuilder.ProfileAPICheck)
- {
- RtFieldInfo rtField = runtimeField as RtFieldInfo;
- if (rtField != null && (rtField.InvocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_NON_W8P_FX_API) != 0)
- throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_APIInvalidForCurrentContext", rtField.FullName));
- }
-#endif
-
return GetMemberRefOfFieldInfo(GetNativeHandle(), tkType, declaringType, runtimeField.MetadataToken);
}
Debug.Assert(!type.IsByRef, "Must not be ByRef.");
Debug.Assert(!type.IsGenericType || type.IsGenericTypeDefinition, "Must not have generic arguments.");
-#if FEATURE_APPX
- if (ContainingAssemblyBuilder.ProfileAPICheck)
- {
- RuntimeType rtType = type as RuntimeType;
- if (rtType != null && (rtType.InvocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_NON_W8P_FX_API) != 0)
- {
- throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_APIInvalidForCurrentContext", rtType.FullName));
- }
- }
-#endif
-
return GetTypeRef(GetNativeHandle(), typeName, GetRuntimeModuleFromModule(refedModule).GetNativeHandle(), strRefedModuleFileName, tkResolution);
}
private RuntimeType m_fieldType;
private INVOCATION_FLAGS m_invocationFlags;
-#if FEATURE_APPX
- private bool IsNonW8PFrameworkAPI()
- {
- if (GetRuntimeType().IsNonW8PFrameworkAPI())
- return true;
-
- // Allow "value__"
- if (m_declaringType.IsEnum)
- return false;
-
- RuntimeAssembly rtAssembly = GetRuntimeAssembly();
- if (rtAssembly.IsFrameworkAssembly())
- {
- int ctorToken = rtAssembly.InvocableAttributeCtorToken;
- if (System.Reflection.MetadataToken.IsNullToken(ctorToken) ||
- !CustomAttribute.IsAttributeDefined(GetRuntimeModule(), MetadataToken, ctorToken))
- return true;
- }
-
- return false;
- }
-#endif
-
internal INVOCATION_FLAGS InvocationFlags
{
get
invocationFlags |= INVOCATION_FLAGS.INVOCATION_FLAGS_FIELD_SPECIAL_CAST;
}
-#if FEATURE_APPX
- if (AppDomain.ProfileAPICheck && IsNonW8PFrameworkAPI())
- invocationFlags |= INVOCATION_FLAGS.INVOCATION_FLAGS_NON_W8P_FX_API;
-#endif // FEATURE_APPX
-
// must be last to avoid threading problems
m_invocationFlags = invocationFlags | INVOCATION_FLAGS.INVOCATION_FLAGS_INITIALIZED;
}
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
CheckConsistency(obj);
-#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
-
RuntimeType fieldType = (RuntimeType)FieldType;
if ((invocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_NEED_SECURITY) != 0)
PerformVisibilityCheckOnField(m_fieldHandle, obj, m_declaringType, m_fieldAttributes, (uint)(m_invocationFlags & ~INVOCATION_FLAGS.INVOCATION_FLAGS_SPECIAL_FIELD));
// method
INVOCATION_FLAGS_IS_CTOR = 0x00000010,
INVOCATION_FLAGS_RISKY_METHOD = 0x00000020,
- INVOCATION_FLAGS_NON_W8P_FX_API = 0x00000040,
+ /* unused 0x00000040 */
INVOCATION_FLAGS_IS_DELEGATE_CTOR = 0x00000080,
INVOCATION_FLAGS_CONTAINS_STACK_POINTERS = 0x00000100,
// field
private object m_keepalive;
private INVOCATION_FLAGS m_invocationFlags;
-#if FEATURE_APPX
- private bool IsNonW8PFrameworkAPI()
- {
- if (m_declaringType.IsArray && IsPublic && !IsStatic)
- return false;
-
- RuntimeAssembly rtAssembly = GetRuntimeAssembly();
- if (rtAssembly.IsFrameworkAssembly())
- {
- int ctorToken = rtAssembly.InvocableAttributeCtorToken;
- if (System.Reflection.MetadataToken.IsNullToken(ctorToken) ||
- !CustomAttribute.IsAttributeDefined(GetRuntimeModule(), MetadataToken, ctorToken))
- return true;
- }
-
- if (GetRuntimeType().IsNonW8PFrameworkAPI())
- return true;
-
- if (IsGenericMethod && !IsGenericMethodDefinition)
- {
- foreach (Type t in GetGenericArguments())
- {
- if (((RuntimeType)t).IsNonW8PFrameworkAPI())
- return true;
- }
- }
-
- return false;
- }
-#endif
-
internal INVOCATION_FLAGS InvocationFlags
{
get
}
}
-#if FEATURE_APPX
- if (AppDomain.ProfileAPICheck && IsNonW8PFrameworkAPI())
- invocationFlags |= INVOCATION_FLAGS.INVOCATION_FLAGS_NON_W8P_FX_API;
-#endif // FEATURE_APPX
-
m_invocationFlags = invocationFlags | INVOCATION_FLAGS.INVOCATION_FLAGS_INITIALIZED;
}
{
object[] arguments = InvokeArgumentsCheck(obj, invokeAttr, binder, parameters, culture);
- #region Security Check
- INVOCATION_FLAGS invocationFlags = InvocationFlags;
-
-#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
- #endregion
-
return UnsafeInvokeInternal(obj, parameters, arguments);
}
{
// Cannot load the WindowsRuntimeResourceManager when in a compilation process, since it
// lives in System.Runtime.WindowsRuntime and only mscorlib may be loaded for execution.
- if (AppDomain.IsAppXModel() && !AppDomain.IsAppXNGen)
+ if (AppDomain.IsAppXModel())
{
s_IsAppXModel = true;
private IntPtr m_cache;
internal IntPtr m_handle;
-#if FEATURE_APPX
- private INVOCATION_FLAGS m_invocationFlags;
-
- internal bool IsNonW8PFrameworkAPI()
- {
- if (IsGenericParameter)
- return false;
-
- if (HasElementType)
- return ((RuntimeType)GetElementType()).IsNonW8PFrameworkAPI();
-
- if (IsSimpleTypeNonW8PFrameworkAPI())
- return true;
-
- if (IsGenericType && !IsGenericTypeDefinition)
- {
- foreach (Type t in GetGenericArguments())
- {
- if (((RuntimeType)t).IsNonW8PFrameworkAPI())
- return true;
- }
- }
-
- return false;
- }
-
- private bool IsSimpleTypeNonW8PFrameworkAPI()
- {
- RuntimeAssembly rtAssembly = GetRuntimeAssembly();
- if (rtAssembly.IsFrameworkAssembly())
- {
- int ctorToken = rtAssembly.InvocableAttributeCtorToken;
- if (System.Reflection.MetadataToken.IsNullToken(ctorToken) ||
- !CustomAttribute.IsAttributeDefined(GetRuntimeModule(), MetadataToken, ctorToken))
- return true;
- }
-
- return false;
- }
-
- internal INVOCATION_FLAGS InvocationFlags
- {
- get
- {
- if ((m_invocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_INITIALIZED) == 0)
- {
- INVOCATION_FLAGS invocationFlags = INVOCATION_FLAGS.INVOCATION_FLAGS_UNKNOWN;
-
- if (AppDomain.ProfileAPICheck && IsNonW8PFrameworkAPI())
- invocationFlags |= INVOCATION_FLAGS.INVOCATION_FLAGS_NON_W8P_FX_API;
-
- m_invocationFlags = invocationFlags | INVOCATION_FLAGS.INVOCATION_FLAGS_INITIALIZED;
- }
-
- return m_invocationFlags;
- }
- }
-#endif // FEATURE_APPX
-
internal static readonly RuntimeType ValueType = (RuntimeType)typeof(System.ValueType);
internal static readonly RuntimeType EnumType = (RuntimeType)typeof(System.Enum);
RuntimeMethodHandleInternal runtime_ctor = default(RuntimeMethodHandleInternal);
bool bNeedSecurityCheck = true;
bool bCanBeCached = false;
- bool bSecurityCheckOff = false;
+ bool bSecurityCheckOff;
if (!skipCheckThis)
CreateInstanceCheckThis();
- if (!fillCache)
- bSecurityCheckOff = true;
-
-#if FEATURE_APPX
- INVOCATION_FLAGS invocationFlags = InvocationFlags;
- 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", this.FullName));
-
- // Allow it because the caller is framework code, but don't cache the result
- // because we need to do the stack walk every time this type is instantiated.
- bSecurityCheckOff = false;
- bCanBeCached = false;
- }
-#endif
bSecurityCheckOff = true; // CoreCLR does not use security at all.
Object instance = RuntimeTypeHandle.CreateInstance(this, publicOnly, bSecurityCheckOff, ref bCanBeCached, ref runtime_ctor, ref bNeedSecurityCheck);
_ASSERTE(!g_pEnumClass->IsValueType());
// Load System.RuntimeType
- // We need to load this after ValueType and Enum because RuntimeType now
- // contains an enum field (m_invocationFlags). Otherwise INVOCATION_FLAGS
- // would be treated as a reference type and clr!SigPointer::GetTypeHandleThrowing
- // throws an exception.
g_pRuntimeTypeClass = MscorlibBinder::GetClass(CLASS__CLASS);
_ASSERTE(g_pRuntimeTypeClass->IsFullyLoaded());
APPX_FLAGS_APPX_MODEL = 0x02,
APPX_FLAGS_APPX_DESIGN_MODE = 0x04,
- APPX_FLAGS_APPX_NGEN = 0x08,
APPX_FLAGS_APPX_MASK = APPX_FLAGS_APPX_MODEL |
- APPX_FLAGS_APPX_DESIGN_MODE |
- APPX_FLAGS_APPX_NGEN,
-
- APPX_FLAGS_API_CHECK = 0x10,
+ APPX_FLAGS_APPX_DESIGN_MODE,
};
// static
if (AppX::IsAppXDesignMode())
flags |= APPX_FLAGS_APPX_DESIGN_MODE;
- else
- flags |= APPX_FLAGS_API_CHECK;
-
- if (AppX::IsAppXNGen())
- flags |= APPX_FLAGS_APPX_NGEN;
- }
-
- //
- // 0: normal (only check in non-dev-mode APPX)
- // 1: always check
- // 2: never check
- //
- switch (g_pConfig->GetWindows8ProfileAPICheckFlag())
- {
- case 1:
- flags |= APPX_FLAGS_API_CHECK;
- break;
- case 2:
- flags &= ~APPX_FLAGS_API_CHECK;
- break;
- default:
- break;
}
END_QCALL;
dwSleepOnExit = CLRConfig::GetConfigValue(CLRConfig::UNSUPPORTED_SleepOnExit);
-#ifdef FEATURE_APPX
- dwWindows8ProfileAPICheckFlag = CLRConfig::GetConfigValue(CLRConfig::INTERNAL_Windows8ProfileAPICheckFlag);
-#endif
-
return hr;
}
public:
DWORD GetSleepOnExit()
{ return dwSleepOnExit; }
-
-#if FEATURE_APPX
-private:
- DWORD dwWindows8ProfileAPICheckFlag;
-
-public:
- DWORD GetWindows8ProfileAPICheckFlag() { return dwWindows8ProfileAPICheckFlag; }
-#endif
};
DEFINE_FIELD_U(m_cache, ReflectClassBaseObject, m_cache)
DEFINE_FIELD_U(m_handle, ReflectClassBaseObject, m_typeHandle)
DEFINE_FIELD_U(m_keepalive, ReflectClassBaseObject, m_keepalive)
-#ifdef FEATURE_APPX
-DEFINE_FIELD_U(m_invocationFlags, ReflectClassBaseObject, m_invocationFlags)
-#endif
DEFINE_CLASS(CLASS, System, RuntimeType)
DEFINE_FIELD(CLASS, TYPEHANDLE, m_handle)
DEFINE_METHOD(CLASS, GET_PROPERTIES, GetProperties, IM_BindingFlags_RetArrPropertyInfo)
OBJECTREF m_keepalive;
OBJECTREF m_cache;
TypeHandle m_typeHandle;
-#ifdef FEATURE_APPX
- UINT32 m_invocationFlags;
-#endif
#ifdef _DEBUG
void TypeCheck()