Fixes #72570.
Still need to delete workarounds that make things public in corelib but maybe this diff is large enough already?
We were gradually getting less and less from reflection blocking:
* We stopped blocking things outside corelib (.NET Native blocked all of BCL; we don't).
* We trim reflection metadata and that allows us to have method bodies without metadata.
With this, we should be able to get type definition-level reflection metadata for any MethodTable there is in the system.
This is a ~30 kB size regression for BasicMinimalApis. It is pretty much a wash for Hello World, because all the BCL cruft to handle reflection blocked types costs as much as the benefit of blocking.
<ItemGroup Condition="'$(TestNativeAot)' == 'true'">
<RdXmlFile Include="$(MSBuildThisFileDirectory)default.rd.xml" />
- <!-- Tests are doing private reflection. -->
- <IlcArg Include="--nometadatablocking" />
-
<!-- xunit calls MakeGenericType to check if something is IEquatable -->
<IlcArg Include="--feature:System.Reflection.IsTypeConstructionEagerlyValidated=false" />
</ItemGroup>
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-/*
- Providing a definition for __BlockAllReflectionAttribute in an assembly is a signal to the .NET Native toolchain
- to remove the metadata for all APIs. This both reduces size and disables all reflection on those
- APIs in libraries that include this.
-*/
-
-using System;
-
-namespace System.Runtime.CompilerServices
-{
- [AttributeUsage(AttributeTargets.All)]
- internal class __BlockAllReflectionAttribute : Attribute { }
-}
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-/*
- Providing a definition for __BlockReflectionAttribute in an assembly is a signal to the .NET Native toolchain
- to remove the metadata for all non-public APIs. This both reduces size and disables private reflection on those
- APIs in libraries that include this.
-*/
-
-using System;
-
-namespace System.Runtime.CompilerServices
-{
- [AttributeUsage(AttributeTargets.All)]
- internal class __BlockReflectionAttribute : Attribute { }
-}
</Suppression>
<Suppression>
<DiagnosticId>CP0001</DiagnosticId>
- <Target>T:System.Runtime.CompilerServices.ReflectionBlockedAttribute</Target>
- </Suppression>
- <Suppression>
- <DiagnosticId>CP0001</DiagnosticId>
<Target>T:System.Runtime.CompilerServices.StaticClassConstructionContext</Target>
</Suppression>
<Suppression>
namespace Internal.DeveloperExperience
{
- [System.Runtime.CompilerServices.ReflectionBlocked]
public class DeveloperExperience
{
/// <summary>
namespace Internal.Reflection.Augments
{
- [System.Runtime.CompilerServices.ReflectionBlocked]
public static class ReflectionAugments
{
//
// This class is implemented by Internal.Reflection.Core.dll and provides the actual implementation
// of Type.GetTypeInfo() and Assembly.Load().
//
- [System.Runtime.CompilerServices.ReflectionBlocked]
public abstract class ReflectionCoreCallbacks
{
public abstract Assembly Load(AssemblyName refName, bool throwOnFileNotFound);
{
// Auto StructLayout used to suppress warning that order of fields is not guaranteed in partial structs
[StructLayout(LayoutKind.Auto)]
- [ReflectionBlocked]
[CLSCompliant(false)]
public partial struct AssemblyBindResult
{
//
// If the binder cannot locate an assembly, it must return null and set "exception" to an exception object.
//
- [ReflectionBlocked]
[CLSCompliant(false)]
public abstract class AssemblyBinder
{
//
// This singleton class acts as an entrypoint from System.Private.Reflection.Execution to System.Private.Reflection.Core.
//
- [ReflectionBlocked]
[CLSCompliant(false)]
public sealed class ExecutionDomain
{
// This group of methods jointly service the Type.GetTypeFromHandle() path. The caller
// is responsible for analyzing the RuntimeTypeHandle to figure out which flavor to call.
//=======================================================================================
- public Type GetNamedTypeForHandle(RuntimeTypeHandle typeHandle, bool isGenericTypeDefinition)
+ public Type GetNamedTypeForHandle(RuntimeTypeHandle typeHandle)
{
- QTypeDefinition qTypeDefinition;
-
- if (ExecutionEnvironment.TryGetMetadataForNamedType(typeHandle, out qTypeDefinition))
- {
+ QTypeDefinition qTypeDefinition = ExecutionEnvironment.GetMetadataForNamedType(typeHandle);
#if ECMA_METADATA_SUPPORT
- if (qTypeDefinition.IsNativeFormatMetadataBased)
-#endif
- {
- return qTypeDefinition.NativeFormatHandle.GetNamedType(qTypeDefinition.NativeFormatReader, typeHandle);
- }
-#if ECMA_METADATA_SUPPORT
- else
- {
- return System.Reflection.Runtime.TypeInfos.EcmaFormat.EcmaFormatRuntimeNamedTypeInfo.GetRuntimeNamedTypeInfo(qTypeDefinition.EcmaFormatReader,
- qTypeDefinition.EcmaFormatHandle,
- typeHandle);
- }
+ if (qTypeDefinition.IsNativeFormatMetadataBased)
#endif
+ {
+ return qTypeDefinition.NativeFormatHandle.GetNamedType(qTypeDefinition.NativeFormatReader, typeHandle);
}
+#if ECMA_METADATA_SUPPORT
else
{
- Debug.Assert(ExecutionEnvironment.IsReflectionBlocked(typeHandle) || RuntimeAugments.MightBeUnconstructedType(typeHandle));
- return RuntimeBlockedTypeInfo.GetRuntimeBlockedTypeInfo(typeHandle, isGenericTypeDefinition);
+ return System.Reflection.Runtime.TypeInfos.EcmaFormat.EcmaFormatRuntimeNamedTypeInfo.GetRuntimeNamedTypeInfo(qTypeDefinition.EcmaFormatReader,
+ qTypeDefinition.EcmaFormatHandle,
+ typeHandle);
}
+#endif
}
public Type GetArrayTypeForHandle(RuntimeTypeHandle typeHandle)
RuntimeTypeHandle[] genericTypeArgumentHandles;
genericTypeDefinitionHandle = RuntimeAugments.GetGenericInstantiation(typeHandle, out genericTypeArgumentHandles);
- // Reflection blocked constructed generic types simply pretend to not be generic
- // This is reasonable, as the behavior of reflection blocked types is supposed
- // to be that they expose the minimal information about a type that is necessary
- // for users of Object.GetType to move from that type to a type that isn't
- // reflection blocked. By not revealing that reflection blocked types are generic
- // we are making it appear as if implementation detail types exposed to user code
- // are all non-generic, which is theoretically possible, and by doing so
- // we avoid (in all known circumstances) the very complicated case of representing
- // the interfaces, base types, and generic parameter types of reflection blocked
- // generic type definitions.
- if (ExecutionEnvironment.IsReflectionBlocked(genericTypeDefinitionHandle))
- {
- return RuntimeBlockedTypeInfo.GetRuntimeBlockedTypeInfo(typeHandle, isGenericTypeDefinition: false);
- }
-
RuntimeTypeInfo genericTypeDefinition = genericTypeDefinitionHandle.GetTypeForRuntimeTypeHandle();
int count = genericTypeArgumentHandles.Length;
RuntimeTypeInfo[] genericTypeArguments = new RuntimeTypeInfo[count];
return runtimeType.InternalTypeHandleIfAvailable;
}
- public bool SupportsReflection(Type type)
- {
- if (type is not RuntimeType)
- return false;
-
- if (ExecutionEnvironment.IsReflectionBlocked(type.TypeHandle))
- {
- // The type is an internal framework type and is blocked from reflection
- return false;
- }
-
- RuntimeTypeInfo runtimeType = type.CastToRuntimeTypeInfo();
- if (runtimeType.InternalFullNameOfAssembly == Internal.Runtime.Augments.RuntimeAugments.HiddenScopeAssemblyName)
- {
- // The type is an internal framework type but is reflectable for internal class library use
- // where we make the type appear in a hidden assembly
- return false;
- }
-
- return true;
- }
-
public static bool IsPrimitiveType(Type type)
=> type == typeof(bool) || type == typeof(char)
|| type == typeof(sbyte) || type == typeof(byte)
// This class abstracts the underlying Redhawk (or whatever execution engine) runtime and exposes the services
// that I.R.Core.Execution needs.
//
- [ReflectionBlocked]
[CLSCompliant(false)]
public abstract class ExecutionEnvironment
{
public abstract IEnumerable<RuntimeTypeHandle> TryGetImplementedInterfaces(RuntimeTypeHandle typeHandle);
public abstract void VerifyInterfaceIsImplemented(RuntimeTypeHandle typeHandle, RuntimeTypeHandle ifaceHandle);
public abstract void GetInterfaceMap(Type instanceType, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.NonPublicMethods)] Type interfaceType, out MethodInfo[] interfaceMethods, out MethodInfo[] targetMethods);
- public abstract bool IsReflectionBlocked(RuntimeTypeHandle typeHandle);
public abstract string GetLastResortString(RuntimeTypeHandle typeHandle);
//==============================================================================================
// Reflection Mapping Tables
//==============================================================================================
- public abstract bool TryGetMetadataForNamedType(RuntimeTypeHandle runtimeTypeHandle, out QTypeDefinition qTypeDefinition);
+ public abstract QTypeDefinition GetMetadataForNamedType(RuntimeTypeHandle runtimeTypeHandle);
public abstract bool TryGetNamedTypeForMetadata(QTypeDefinition qTypeDefinition, out RuntimeTypeHandle runtimeTypeHandle);
- public abstract bool TryGetTypeReferenceForNamedType(RuntimeTypeHandle runtimeTypeHandle, out MetadataReader metadataReader, out TypeReferenceHandle typeRefHandle);
- public abstract bool TryGetNamedTypeForTypeReference(MetadataReader metadataReader, TypeReferenceHandle typeRefHandle, out RuntimeTypeHandle runtimeTypeHandle);
-
public abstract bool TryGetArrayTypeForElementType(RuntimeTypeHandle elementTypeHandle, out RuntimeTypeHandle arrayTypeHandle);
public abstract bool TryGetArrayTypeElementType(RuntimeTypeHandle arrayTypeHandle, out RuntimeTypeHandle elementTypeHandle);
//
// This class abstracts the underlying Redhawk (or whatever execution engine) runtime that sets and gets fields.
//
- [ReflectionBlocked]
[CLSCompliant(false)]
public abstract class FieldAccessor
{
// This class polymorphically implements the MethodBase.Invoke() api and its close cousins. MethodInvokers are designed to be built once and cached
// for maximum Invoke() throughput.
//
- [ReflectionBlocked]
public abstract class MethodInvoker
{
protected MethodInvoker() { }
namespace Internal.Reflection.Core.Execution
{
- [ReflectionBlocked]
[CLSCompliant(false)]
public static class ReflectionCoreExecution
{
if (eeType.IsDefType)
{
- if (eeType.IsGenericTypeDefinition)
- {
- return callbacks.GetNamedTypeForHandle(runtimeTypeHandle, isGenericTypeDefinition: true);
- }
- else if (eeType.IsGeneric)
+ if (eeType.IsGeneric)
{
return callbacks.GetConstructedGenericTypeForHandle(runtimeTypeHandle);
}
else
{
- return callbacks.GetNamedTypeForHandle(runtimeTypeHandle, isGenericTypeDefinition: false);
+ return callbacks.GetNamedTypeForHandle(runtimeTypeHandle);
}
}
else if (eeType.IsArray)
namespace Internal.Reflection.Core
{
- [ReflectionBlocked]
[CLSCompliant(false)]
public abstract class ReflectionDomainSetup
{
namespace Internal.Runtime.Augments
{
[CLSCompliant(false)]
- [System.Runtime.CompilerServices.ReflectionBlocked]
public abstract class ReflectionExecutionDomainCallbacks
{
public abstract IntPtr TryGetStaticClassConstructionContext(RuntimeTypeHandle runtimeTypeHandle);
- public abstract bool IsReflectionBlocked(RuntimeTypeHandle typeHandle);
-
//=======================================================================================
// This group of methods jointly service the Type.GetTypeFromHandle() path. The caller
// is responsible for analyzing the RuntimeTypeHandle to figure out which flavor to call.
//=======================================================================================
- public abstract Type GetNamedTypeForHandle(RuntimeTypeHandle typeHandle, bool isGenericTypeDefinition);
+ public abstract Type GetNamedTypeForHandle(RuntimeTypeHandle typeHandle);
public abstract Type GetArrayTypeForHandle(RuntimeTypeHandle typeHandle);
public abstract Type GetMdArrayTypeForHandle(RuntimeTypeHandle typeHandle, int rank);
public abstract Type GetPointerTypeForHandle(RuntimeTypeHandle typeHandle);
public abstract Assembly GetAssemblyForHandle(RuntimeTypeHandle typeHandle);
public abstract RuntimeTypeHandle GetTypeHandleIfAvailable(Type type);
- public abstract bool SupportsReflection(Type type);
public abstract MethodInfo GetDelegateMethod(Delegate del);
using BinderBundle = System.Reflection.BinderBundle;
using Pointer = System.Reflection.Pointer;
- [ReflectionBlocked]
public static class RuntimeAugments
{
/// <summary>
}
//
- // Returns the name of a virtual assembly we dump types private class library-Reflectable ty[es for internal class library use.
- // The assembly binder visible to apps will never reveal this assembly.
- //
- // Note that this is not versionable as it is exposed as a const (and needs to be a const so we can used as a custom attribute argument - which
- // is the other reason this string is not versionable.)
- //
- public const string HiddenScopeAssemblyName = "HiddenScope, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";
-
- //
// This implements the "IsAssignableFrom()" api for runtime-created types. By policy, we let the underlying runtime decide assignability.
//
public static bool IsAssignableFrom(RuntimeTypeHandle dstType, RuntimeTypeHandle srcType)
{
EETypePtr ifcEEType = eeType.Interfaces[i];
RuntimeTypeHandle ifcrth = new RuntimeTypeHandle(ifcEEType);
- if (Callbacks.IsReflectionBlocked(ifcrth))
- continue;
-
implementedInterfaces.Add(ifcrth);
}
return implementedInterfaces.ToArray();
/// Internal.Runtime.Augments.RuntimeAugments.InitializeStackTraceMetadataSupport(StackTraceMetadataCallbacks callbacks);
///
/// </summary>
- [System.Runtime.CompilerServices.ReflectionBlocked]
[CLSCompliant(false)]
public abstract class StackTraceMetadataCallbacks
{
namespace Internal.Runtime.Augments
{
[CLSCompliant(false)]
- [System.Runtime.CompilerServices.ReflectionBlocked]
public abstract class TypeLoaderCallbacks
{
public abstract TypeManagerHandle GetModuleForMetadataReader(MetadataReader reader);
namespace Internal.Runtime.CompilerServices
{
- [System.Runtime.CompilerServices.ReflectionBlocked]
public static class FunctionPointerOps
{
#if TARGET_WASM
namespace Internal.Runtime.CompilerServices
{
- [System.Runtime.CompilerServices.ReflectionBlocked]
public struct GenericMethodDescriptor
{
public readonly IntPtr MethodFunctionPointer;
// so that repeated allocation of the same resolver will not leak.
// 3) Use the ResolveMethod function to do the virtual lookup. This function takes advantage of
// a lockless cache so the resolution is very fast for repeated lookups.
- [ReflectionBlocked]
public struct OpenMethodResolver : IEquatable<OpenMethodResolver>
{
// Lazy initialized to point to the type loader method when the first `GVMResolve` resolver is created
<Compile Include="System\Runtime\CompilerServices\ForceLazyDictionaryAttribute.cs" />
<Compile Include="System\Runtime\CompilerServices\EagerStaticClassConstructionAttribute.cs" />
<Compile Include="System\Runtime\CompilerServices\ForceDictionaryLookupsAttribute.cs" />
- <Compile Include="System\Runtime\CompilerServices\ReflectionBlockedAttribute.cs" />
<Compile Include="System\Runtime\CompilerServices\RuntimeFeature.NativeAot.cs" />
<Compile Include="System\Runtime\CompilerServices\StaticClassConstructionContext.cs" />
<Compile Include="System\Runtime\ExceptionIDs.cs" />
<Compile Include="$(CompilerCommonPath)\Internal\LowLevelLinq\LowLevelEnumerable.ToArray.cs">
<Link>Internal\LowLevelLinq\LowLevelEnumerable.ToArray.cs</Link>
</Compile>
- <Compile Include="$(AotCommonPath)\System\Runtime\CompilerServices\__BlockReflectionAttribute.cs">
- <Link>System\Runtime\CompilerServices\__BlockReflectionAttribute.cs</Link>
- </Compile>
<Compile Include="$(AotCommonPath)\System\Runtime\CompilerServices\DeveloperExperienceState.cs">
<Link>System\Runtime\CompilerServices\DeveloperExperienceState.cs</Link>
</Compile>
<Compile Include="System\Reflection\Runtime\FieldInfos\NativeFormat\NativeFormatRuntimeFieldInfo.cs" />
<Compile Include="System\Reflection\Runtime\FieldInfos\RuntimeFieldInfo.cs" />
<Compile Include="System\Reflection\Runtime\General\Assignability.cs" />
- <Compile Include="System\Reflection\Runtime\General\BlockedRuntimeTypeNameGenerator.cs" />
<Compile Include="System\Reflection\Runtime\General\Dispensers.NativeFormat.cs" />
<Compile Include="System\Reflection\Runtime\General\Helpers.NativeFormat.cs" />
<Compile Include="System\Reflection\Runtime\General\ReflectionCoreCallbacksImplementation.cs" />
<Compile Include="System\Reflection\Runtime\TypeInfos\RuntimeHasElementTypeInfo.UnificationKey.cs" />
<Compile Include="System\Reflection\Runtime\TypeInfos\RuntimeNamedTypeInfo.cs" />
<Compile Include="System\Reflection\Runtime\TypeInfos\RuntimePointerTypeInfo.cs" />
- <Compile Include="System\Reflection\Runtime\TypeInfos\RuntimeBlockedTypeInfo.cs" />
<Compile Include="System\Reflection\Runtime\TypeInfos\RuntimeTypeDefinitionTypeInfo.cs" />
<Compile Include="System\Reflection\Runtime\TypeInfos\RuntimeTypeInfo.cs" />
<Compile Include="System\Reflection\Runtime\TypeInfos\RuntimeTypeInfo.GetMember.cs" />
/// <summary>
/// Annotations used by debugger
/// </summary>
- [System.Runtime.CompilerServices.ReflectionBlocked]
public static class DebugAnnotations
{
/// <summary>
namespace System.Diagnostics
{
- [System.Runtime.CompilerServices.ReflectionBlocked]
[AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Constructor, Inherited = false)]
public sealed class DebuggerGuidedStepThroughAttribute : Attribute
{
namespace System.Reflection
{
- [System.Runtime.CompilerServices.ReflectionBlocked]
public static class AssemblyRuntimeNameHelpers
{
//
// to manage.)
//
// This is not an api type but needs to be public as both Reflection.Core and System.Private.Corelib accesses it.
- [System.Runtime.CompilerServices.ReflectionBlocked]
public sealed class BinderBundle
{
public BinderBundle(Binder binder, CultureInfo culture)
namespace System.Reflection
{
// caches information required for efficient argument validation and type coercion for reflection Invoke.
- [ReflectionBlocked]
public class DynamicInvokeInfo
{
// Public state
namespace System.Reflection
{
- [ReflectionBlocked]
public abstract class EnumInfo
{
private protected EnumInfo(Type underlyingType, string[] names, bool isFlags)
internal bool HasFlagsAttribute { get; }
}
- [ReflectionBlocked]
public sealed class EnumInfo<TStorage> : EnumInfo
where TStorage : struct, INumber<TStorage>
{
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-using System;
-using System.Text;
-using System.Diagnostics;
-using System.Collections.Concurrent;
-
-namespace System.Reflection.Runtime.General
-{
- //
- // This class dispenses randomized strings (that serve as both the fake name and fake assembly container) for
- // reflection-blocked types.
- //
- // The names are randomized to prevent apps from hard-wiring dependencies on them or attempting to serialize them
- // across app execution.
- //
- internal static class BlockedRuntimeTypeNameGenerator
- {
- public static string GetNameForBlockedRuntimeType(RuntimeTypeHandle typeHandle)
- {
- string name = s_blockedNameTable.GetOrAdd(new RuntimeTypeHandleKey(typeHandle));
- return name;
- }
-
- private sealed class BlockedRuntimeTypeNameTable : ConcurrentUnifier<RuntimeTypeHandleKey, string>
- {
- protected sealed override string Factory(RuntimeTypeHandleKey key)
- {
- uint count = s_counter++;
- return $"$BlockedFromReflection_{count}_{Guid.NewGuid().ToString().Substring(0, 8)}";
- }
-
- private static uint s_counter;
- }
-
- private static readonly BlockedRuntimeTypeNameTable s_blockedNameTable = new BlockedRuntimeTypeNameTable();
- }
-}
//
// Collect various metadata reading tasks for better chunking...
//
- [ReflectionBlocked]
[CLSCompliant(false)]
public static class NativeFormatMetadataReaderExtensions
{
namespace System.Reflection.Runtime.General
{
- [ReflectionBlocked]
[CLSCompliant(false)]
public static partial class MetadataReaderExtensions
{
namespace Internal.Reflection.Core
{
- [ReflectionBlocked]
[CLSCompliant(false)]
public struct QScopeDefinition : IEquatable<QScopeDefinition>
{
namespace System.Reflection.Runtime.General
{
- [ReflectionBlocked]
[CLSCompliant(false)]
public struct QHandle : IEquatable<QHandle>
{
private readonly Handle _handle;
}
- [ReflectionBlocked]
[CLSCompliant(false)]
public partial struct QMethodDefinition
{
private readonly int _handle;
}
- [ReflectionBlocked]
[CLSCompliant(false)]
public partial struct QTypeDefinition
{
}
- [ReflectionBlocked]
[CLSCompliant(false)]
public partial struct QTypeDefRefOrSpec
{
private readonly int _handle;
}
- [ReflectionBlocked]
[CLSCompliant(false)]
public struct QGenericParameter : IEquatable<QGenericParameter>
{
namespace System.Reflection.Runtime.General
{
- [ReflectionBlocked]
[CLSCompliant(false)]
public partial struct QSignatureTypeHandle
{
Justification = "Resolves type references within metadata. We ensure metadata is consistent.")]
private static RuntimeTypeInfo? TryResolveTypeReference(this TypeReferenceHandle typeReferenceHandle, MetadataReader reader, ref Exception? exception)
{
- RuntimeTypeHandle resolvedRuntimeTypeHandle;
- if (ReflectionCoreExecution.ExecutionEnvironment.TryGetNamedTypeForTypeReference(reader, typeReferenceHandle, out resolvedRuntimeTypeHandle))
- return resolvedRuntimeTypeHandle.GetTypeForRuntimeTypeHandle();
-
TypeReference typeReference = typeReferenceHandle.GetTypeReference(reader);
string name = typeReference.TypeName.GetString(reader);
Handle parent = typeReference.ParentNamespaceOrType;
namespace System.Reflection.Runtime.TypeInfos
{
//-----------------------------------------------------------------------------------------------------------
- // TypeInfos that represent type definitions (i.e. Foo or Foo<>) or constructed generic types (Foo<int>)
- // that can never be reflection-enabled due to the framework Reflection block.
- //-----------------------------------------------------------------------------------------------------------
- internal sealed partial class RuntimeBlockedTypeInfo
- {
- internal static RuntimeBlockedTypeInfo GetRuntimeBlockedTypeInfo(RuntimeTypeHandle typeHandle, bool isGenericTypeDefinition)
- {
- RuntimeBlockedTypeInfo type;
- if (isGenericTypeDefinition)
- type = GenericBlockedTypeTable.Table.GetOrAdd(new RuntimeTypeHandleKey(typeHandle));
- else
- type = BlockedTypeTable.Table.GetOrAdd(new RuntimeTypeHandleKey(typeHandle));
- type.EstablishDebugName();
- return type;
- }
-
- private sealed class BlockedTypeTable : ConcurrentUnifierW<RuntimeTypeHandleKey, RuntimeBlockedTypeInfo>
- {
- protected sealed override RuntimeBlockedTypeInfo Factory(RuntimeTypeHandleKey key)
- {
- return new RuntimeBlockedTypeInfo(key.TypeHandle, isGenericTypeDefinition: false);
- }
-
- public static readonly BlockedTypeTable Table = new BlockedTypeTable();
- }
-
- private sealed class GenericBlockedTypeTable : ConcurrentUnifierW<RuntimeTypeHandleKey, RuntimeBlockedTypeInfo>
- {
- protected sealed override RuntimeBlockedTypeInfo Factory(RuntimeTypeHandleKey key)
- {
- return new RuntimeBlockedTypeInfo(key.TypeHandle, isGenericTypeDefinition: true);
- }
-
- public static readonly GenericBlockedTypeTable Table = new GenericBlockedTypeTable();
- }
- }
-
- //-----------------------------------------------------------------------------------------------------------
// TypeInfos for Sz and multi-dim Array types.
//-----------------------------------------------------------------------------------------------------------
internal sealed partial class RuntimeArrayTypeInfo : RuntimeHasElementTypeInfo
if (genericTypeDefinitionHandle.IsNull())
return default(RuntimeTypeHandle);
- if (ReflectionCoreExecution.ExecutionEnvironment.IsReflectionBlocked(genericTypeDefinitionHandle))
- return default(RuntimeTypeHandle);
-
int count = genericTypeArguments.Length;
RuntimeTypeHandle[] genericTypeArgumentHandles = new RuntimeTypeHandle[count];
for (int i = 0; i < count; i++)
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-using System;
-using System.Reflection;
-using System.Diagnostics;
-using System.Collections.Generic;
-using System.Reflection.Runtime.General;
-using System.Reflection.Runtime.TypeInfos;
-using System.Reflection.Runtime.Assemblies;
-using System.Reflection.Runtime.CustomAttributes;
-
-using Internal.LowLevelLinq;
-using Internal.Reflection.Core.Execution;
-
-using CharSet = System.Runtime.InteropServices.CharSet;
-using LayoutKind = System.Runtime.InteropServices.LayoutKind;
-using StructLayoutAttribute = System.Runtime.InteropServices.StructLayoutAttribute;
-
-namespace System.Reflection.Runtime.TypeInfos
-{
- //
- // TypeInfos that represent type definitions (i.e. Foo or Foo<>) or constructed generic types (Foo<int>)
- // that can never be reflection-enabled due to the framework Reflection block.
- //
- // These types differ from NoMetadata TypeInfos in that properties that inquire about members,
- // custom attributes or interfaces return an empty list rather than throwing a missing metadata exception.
- //
- // Since these represent "internal framework types", the app cannot prove we are lying.
- //
- internal sealed partial class RuntimeBlockedTypeInfo : RuntimeTypeDefinitionTypeInfo
- {
- private RuntimeBlockedTypeInfo(RuntimeTypeHandle typeHandle, bool isGenericTypeDefinition)
- {
- _typeHandle = typeHandle;
- _isGenericTypeDefinition = isGenericTypeDefinition;
- }
-
- public sealed override Assembly Assembly
- {
- get
- {
- return typeof(object).Assembly;
- }
- }
-
- public sealed override bool ContainsGenericParameters
- {
- get
- {
- return _isGenericTypeDefinition;
- }
- }
-
- public sealed override IEnumerable<CustomAttributeData> CustomAttributes
- {
- get
- {
- return Array.Empty<CustomAttributeData>();
- }
- }
-
- public sealed override bool IsByRefLike
- {
- get
- {
- return Internal.Runtime.Augments.RuntimeAugments.IsByRefLike(_typeHandle);
- }
- }
-
- public sealed override string FullName
- {
- get
- {
- return GeneratedName;
- }
- }
-
- public sealed override Guid GUID
- {
- get
- {
- throw ReflectionCoreExecution.ExecutionDomain.CreateMissingMetadataException(this);
- }
- }
-
-#if DEBUG
- public sealed override bool HasSameMetadataDefinitionAs(MemberInfo other) => base.HasSameMetadataDefinitionAs(other);
-#endif
-
- public sealed override bool IsGenericTypeDefinition
- {
- get
- {
- return _isGenericTypeDefinition;
- }
- }
-
- public sealed override string Namespace
- {
- get
- {
- return null; // Reflection-blocked framework types report themselves as existing in the "root" namespace.
- }
- }
-
- public sealed override StructLayoutAttribute StructLayoutAttribute
- {
- get
- {
- return new StructLayoutAttribute(LayoutKind.Auto)
- {
- CharSet = CharSet.Ansi,
- Pack = 8,
- Size = 0,
- };
- }
- }
-
- public sealed override string ToString()
- {
- return _typeHandle.LastResortString();
- }
-
- public sealed override int MetadataToken
- {
- get
- {
- throw new InvalidOperationException(SR.NoMetadataTokenAvailable);
- }
- }
-
- protected sealed override TypeAttributes GetAttributeFlagsImpl()
- {
- return TypeAttributes.Class | TypeAttributes.NotPublic;
- }
-
- protected sealed override int InternalGetHashCode()
- {
- return _typeHandle.GetHashCode();
- }
-
- //
- // Returns the anchoring typedef that declares the members that this type wants returned by the Declared*** properties.
- // The Declared*** properties will project the anchoring typedef's members by overriding their DeclaringType property with "this"
- // and substituting the value of this.TypeContext into any generic parameters.
- //
- // Default implementation returns null which causes the Declared*** properties to return no members.
- //
- // Note that this does not apply to DeclaredNestedTypes. Nested types and their containers have completely separate generic instantiation environments
- // (despite what C# might lead you to think.) Constructed generic types return the exact same same nested types that its generic type definition does
- // - i.e. their DeclaringTypes refer back to the generic type definition, not the constructed generic type.)
- //
- // Note also that we cannot use this anchoring concept for base types because of generic parameters. Generic parameters return
- // baseclass and interfaces based on its constraints.
- //
- internal sealed override RuntimeNamedTypeInfo AnchoringTypeDefinitionForDeclaredMembers
- {
- get
- {
- return null; // this causes the type to report having no members.
- }
- }
-
- internal sealed override RuntimeTypeInfo[] RuntimeGenericTypeParameters
- {
- get
- {
- throw ReflectionCoreExecution.ExecutionDomain.CreateMissingMetadataException(this);
- }
- }
-
- internal sealed override Type InternalDeclaringType
- {
- get
- {
- return null;
- }
- }
-
- public sealed override string Name
- {
- get
- {
- return GeneratedName;
- }
- }
-
- internal sealed override string InternalFullNameOfAssembly
- {
- get
- {
- return GeneratedName;
- }
- }
-
- internal sealed override RuntimeTypeHandle InternalTypeHandleIfAvailable
- {
- get
- {
- return _typeHandle;
- }
- }
-
- //
- // Returns the base type as a typeDef, Ref, or Spec. Default behavior is to QTypeDefRefOrSpec.Null, which causes BaseType to return null.
- //
- internal sealed override QTypeDefRefOrSpec TypeRefDefOrSpecForBaseType
- {
- get
- {
- throw ReflectionCoreExecution.ExecutionDomain.CreateMissingMetadataException(this);
- }
- }
-
- //
- // Returns the *directly implemented* interfaces as typedefs, specs or refs. ImplementedInterfaces will take care of the transitive closure and
- // insertion of the TypeContext.
- //
- internal sealed override QTypeDefRefOrSpec[] TypeRefDefOrSpecsForDirectlyImplementedInterfaces
- {
- get
- {
- throw ReflectionCoreExecution.ExecutionDomain.CreateMissingMetadataException(this);
- }
- }
-
- //
- // Returns the generic parameter substitutions to use when enumerating declared members, base class and implemented interfaces.
- //
- internal sealed override TypeContext TypeContext
- {
- get
- {
- throw ReflectionCoreExecution.ExecutionDomain.CreateMissingMetadataException(this);
- }
- }
-
- private string GeneratedName
- {
- get
- {
- return _lazyGeneratedName ??= BlockedRuntimeTypeNameGenerator.GetNameForBlockedRuntimeType(_typeHandle);
- }
- }
-
- private readonly RuntimeTypeHandle _typeHandle;
- private readonly bool _isGenericTypeDefinition;
- private volatile string _lazyGeneratedName;
- }
-}
{
get
{
- RuntimeTypeHandle typeHandle = InternalTypeHandleIfAvailable;
- if ((!typeHandle.IsNull()) && ReflectionCoreExecution.ExecutionEnvironment.IsReflectionBlocked(typeHandle))
- return null;
return GenericTypeDefinitionTypeInfo.InternalDeclaringType;
}
}
return GenericTypeDefinitionTypeInfo.CoreGetDeclaredNestedTypes(optionalNameFilter);
}
}
-
- internal sealed partial class RuntimeBlockedTypeInfo
- {
- internal sealed override IEnumerable<Type> CoreGetDeclaredNestedTypes(NameFilter optionalNameFilter)
- {
- return Array.Empty<Type>();
- }
- }
}
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-namespace System.Runtime.CompilerServices
-{
- // When applied to a type this custom attribute cause the type to be treated as reflection blocked.
- [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Delegate | AttributeTargets.Enum | AttributeTargets.Interface, Inherited = false, AllowMultiple = false)]
- public class ReflectionBlockedAttribute : Attribute
- {
- }
-}
// The .NET Foundation licenses this file to you under the MIT license.
using Internal.Reflection.Augments;
+using Internal.Reflection.Core.Execution;
using Internal.Runtime;
using Internal.Runtime.Augments;
using System.Diagnostics.CodeAnalysis;
throw new NotSupportedException(SR.NotSupported_ByRefLike);
}
+ Debug.Assert(MethodTable.Of<object>()->NumVtableSlots > 0);
+ if (mt->NumVtableSlots == 0)
+ {
+ // This is a type without a vtable or GCDesc. We must not allow creating an instance of it
+ throw ReflectionCoreExecution.ExecutionDomain.CreateMissingMetadataException(type);
+ }
+ // Paranoid check: not-meant-for-GC-heap types should be reliably identifiable by empty vtable.
+ Debug.Assert(!mt->ContainsGCPointers || RuntimeImports.RhGetGCDescSize(new EETypePtr(mt)) != 0);
+
if (mt->IsNullable)
{
mt = mt->NullableType;
/// in order to be accessible from System.Private.Interop.dll.
/// </summary>
[CLSCompliant(false)]
- [ReflectionBlocked]
public static class InteropExtensions
{
internal static bool MightBeBlittable(this EETypePtr eeType)
// E.g., the class and methods are marked internal assuming that only the base class library needs them
// but if a class library wants to factor differently (such as putting the GCHandle methods in an
// optional library, those methods can be moved to a different file/namespace/dll
- [ReflectionBlocked]
public static partial class RuntimeImports
{
private const string RuntimeLibrary = "*";
namespace System.Runtime
{
- [ReflectionBlocked]
public static class TypeLoaderExports
{
public static unsafe void ActivatorCreateInstanceAny(ref object ptrToData, IntPtr pEETypePtr)
}
}
- [ReflectionBlocked]
public delegate IntPtr RuntimeObjectFactory(IntPtr context, IntPtr signature, object contextObject, ref IntPtr auxResult);
internal static unsafe class RawCalliHelper
}
}
- [ReflectionBlocked]
public class RuntimeExceptionHelpers
{
//------------------------------------------------------------------------------------------------------------
namespace System.Threading
{
- [System.Runtime.CompilerServices.ReflectionBlocked]
public sealed class Condition
{
internal class Waiter
namespace System.Threading
{
- [ReflectionBlocked]
public sealed class Lock : IDisposable
{
//
namespace System.Threading
{
- [ReflectionBlocked]
public struct LockHolder : IDisposable
{
private Lock _lock;
public override Exception GetExceptionForHR(int hr) => throw new NotImplementedException();
public override Type GetMdArrayTypeForHandle(RuntimeTypeHandle typeHandle, int rank) => RuntimeTypeInfo.GetRuntimeTypeInfo(typeHandle);
public override MethodBase GetMethodBaseFromStartAddressIfAvailable(IntPtr methodStartAddress) => null;
- public override Type GetNamedTypeForHandle(RuntimeTypeHandle typeHandle, bool isGenericTypeDefinition) => RuntimeTypeInfo.GetRuntimeTypeInfo(typeHandle);
+ public override Type GetNamedTypeForHandle(RuntimeTypeHandle typeHandle) => RuntimeTypeInfo.GetRuntimeTypeInfo(typeHandle);
public override Type GetPointerTypeForHandle(RuntimeTypeHandle typeHandle) => RuntimeTypeInfo.GetRuntimeTypeInfo(typeHandle);
public override Type GetFunctionPointerTypeForHandle(RuntimeTypeHandle typeHandle) => RuntimeTypeInfo.GetRuntimeTypeInfo(typeHandle);
public override RuntimeTypeHandle GetTypeHandleIfAvailable(Type type) => type.TypeHandle;
- public override bool IsReflectionBlocked(RuntimeTypeHandle typeHandle) => false;
- public override bool SupportsReflection(Type type) => false;
public override IntPtr TryGetStaticClassConstructionContext(RuntimeTypeHandle runtimeTypeHandle) => throw new NotSupportedException(SR.Reflection_Disabled);
}
}
/// runtimeTypeHandle is a typedef (not a constructed type such as an array or generic instance.)
/// </summary>
/// <param name="runtimeTypeHandle">Runtime handle of the type in question</param>
- /// <param name="qTypeDefinition">TypeDef handle for the type</param>
- public sealed override unsafe bool TryGetMetadataForNamedType(RuntimeTypeHandle runtimeTypeHandle, out QTypeDefinition qTypeDefinition)
+ public sealed override QTypeDefinition GetMetadataForNamedType(RuntimeTypeHandle runtimeTypeHandle)
{
Debug.Assert(!RuntimeAugments.IsGenericType(runtimeTypeHandle));
- return TypeLoaderEnvironment.Instance.TryGetMetadataForNamedType(runtimeTypeHandle, out qTypeDefinition);
- }
-
- //
- // Return true for a TypeDef if the policy has decided this type is blocked from reflection.
- //
- // Preconditions:
- // runtimeTypeHandle is a typedef or a generic type instance (not a constructed type such as an array)
- //
- public sealed override unsafe bool IsReflectionBlocked(RuntimeTypeHandle runtimeTypeHandle)
- {
- // For generic types, use the generic type definition
- runtimeTypeHandle = GetTypeDefinition(runtimeTypeHandle);
- var moduleHandle = RuntimeAugments.GetModuleFromTypeHandle(runtimeTypeHandle);
-
- //make sure the module is actually NativeFormatModuleInfo, if the module
- //doesnt have reflection enabled it wont be a NativeFormatModuleInfo
- if (!(ModuleList.Instance.TryGetModuleInfoByHandle(moduleHandle, out ModuleInfo untypedModuleInfo) && (untypedModuleInfo is NativeFormatModuleInfo module)))
- {
- return true;
- }
-
- NativeReader blockedReflectionReader = GetNativeReaderForBlob(module, ReflectionMapBlob.BlockReflectionTypeMap);
- NativeParser blockedReflectionParser = new NativeParser(blockedReflectionReader, 0);
- NativeHashtable blockedReflectionHashtable = new NativeHashtable(blockedReflectionParser);
- ExternalReferencesTable externalReferences = default(ExternalReferencesTable);
- externalReferences.InitializeCommonFixupsTable(module);
-
- int hashcode = runtimeTypeHandle.GetHashCode();
- var lookup = blockedReflectionHashtable.Lookup(hashcode);
- NativeParser entryParser;
- while (!(entryParser = lookup.GetNext()).IsNull)
+ if (!TypeLoaderEnvironment.Instance.TryGetMetadataForNamedType(runtimeTypeHandle, out QTypeDefinition qTypeDefinition))
{
- RuntimeTypeHandle entryType = externalReferences.GetRuntimeTypeHandleFromIndex(entryParser.GetUnsigned());
- if (!entryType.Equals(runtimeTypeHandle))
- continue;
-
- // Entry found, must be blocked
- return true;
+ // This should be unreachable unless there's a compiler bug
+ throw new InvalidOperationException();
}
- // Entry not found, must not be blocked
- return false;
+ return qTypeDefinition;
}
/// <summary>
return TypeLoaderEnvironment.Instance.TryGetNamedTypeForMetadata(qTypeDefinition, out runtimeTypeHandle);
}
- /// <summary>
- /// Return the metadata handle for a TypeRef if this type was referenced indirectly by other type that pay-for-play has denoted as browsable
- /// (for example, as part of a method signature.)
- ///
- /// This is only used in "debug" builds to provide better missing metadata diagnostics.
- ///
- /// Preconditions:
- /// runtimeTypeHandle is a typedef (not a constructed type such as an array or generic instance.)
- /// </summary>
- /// <param name="runtimeTypeHandle">MethodTable of the type in question</param>
- /// <param name="metadataReader">Metadata reader for the type</param>
- /// <param name="typeRefHandle">Located TypeRef handle</param>
- public sealed override unsafe bool TryGetTypeReferenceForNamedType(RuntimeTypeHandle runtimeTypeHandle, out MetadataReader metadataReader, out TypeReferenceHandle typeRefHandle)
- {
- return TypeLoaderEnvironment.TryGetTypeReferenceForNamedType(runtimeTypeHandle, out metadataReader, out typeRefHandle);
- }
-
- /// <summary>
- /// Return the RuntimeTypeHandle for the named type referenced by another type that pay-for-play denotes as browsable (for example,
- /// in a member signature.) Typically, the type itself is *not* browsable (or it would have appeared in the TypeDef table.)
- ///
- /// This is used to ensure that we can produce a Type object if requested and that it match up with the analogous
- /// Type obtained via typeof().
- ///
- ///
- /// Preconditions:
- /// metadataReader + typeRefHandle - a valid metadata reader + typeReferenceHandle where "metadataReader" is one
- /// of the metadata readers returned by ExecutionEnvironment.MetadataReaders.
- ///
- /// Note: Although this method has a "bool" return value like the other mapping table accessors, the pay-for-play design
- /// guarantees that any type that has a metadata TypeReference to it also has a RuntimeTypeHandle underneath.
- /// </summary>
- /// <param name="metadataReader">Metadata reader for module containing the type reference</param>
- /// <param name="typeRefHandle">TypeRef handle to look up</param>
- /// <param name="runtimeTypeHandle">Resolved MethodTable for the type reference</param>
- public sealed override unsafe bool TryGetNamedTypeForTypeReference(MetadataReader metadataReader, TypeReferenceHandle typeRefHandle, out RuntimeTypeHandle runtimeTypeHandle)
- {
- return TypeLoaderEnvironment.TryGetNamedTypeForTypeReference(metadataReader, typeRefHandle, out runtimeTypeHandle);
- }
-
//
// Given a RuntimeTypeHandle for any type E, return a RuntimeTypeHandle for type E[], if the pay for play policy denotes E[] as browsable. This is used to
// implement Array.CreateInstance().
if ((entryFlags & InvokeTableFlags.HasMetadataHandle) != 0)
{
RuntimeTypeHandle declaringTypeHandleDefinition = GetTypeDefinition(declaringTypeHandle);
- QTypeDefinition qTypeDefinition;
- if (!TryGetMetadataForNamedType(declaringTypeHandleDefinition, out qTypeDefinition))
- {
- RuntimeExceptionHelpers.FailFast("Unable to resolve named type to having a metadata reader");
- }
+ QTypeDefinition qTypeDefinition = GetMetadataForNamedType(declaringTypeHandleDefinition);
MethodHandle nativeFormatMethodHandle =
(((int)HandleType.Method << 24) | (int)entryMethodHandleOrNameAndSigRaw).AsMethodHandle();
if (!TypeLoaderEnvironment.Instance.TryGetRuntimeFieldHandleComponents(runtimeFieldHandle, out declaringTypeHandle, out fieldName))
return false;
- QTypeDefinition qTypeDefinition;
RuntimeTypeHandle metadataLookupTypeHandle = GetTypeDefinition(declaringTypeHandle);
- if (!TryGetMetadataForNamedType(metadataLookupTypeHandle, out qTypeDefinition))
- return false;
+ QTypeDefinition qTypeDefinition = GetMetadataForNamedType(metadataLookupTypeHandle);
// TODO! Handle ecma style types
MetadataReader reader = qTypeDefinition.NativeFormatReader;
typeDefHandle = RuntimeAugments.GetGenericDefinition(typeHandle);
}
- // If the type is reflection blocked, we pretend there are no enum values defined
- if (ReflectionExecution.ExecutionEnvironment.IsReflectionBlocked(typeDefHandle))
- {
- names = Array.Empty<string>();
- values = Array.Empty<object>();
- isFlags = false;
- return;
- }
-
- QTypeDefinition qTypeDefinition;
- if (!ReflectionExecution.ExecutionEnvironment.TryGetMetadataForNamedType(typeDefHandle, out qTypeDefinition))
- {
- throw ReflectionCoreExecution.ExecutionDomain.CreateMissingMetadataException(Type.GetTypeFromHandle(typeDefHandle));
- }
+ QTypeDefinition qTypeDefinition = ReflectionExecution.ExecutionEnvironment.GetMetadataForNamedType(typeDefHandle);
if (qTypeDefinition.IsNativeFormatMetadataBased)
{
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-using global::System;
-using global::System.Text;
-using global::System.Collections.Generic;
-
-using global::Internal.Metadata.NativeFormat;
-
-using global::Internal.Runtime.Augments;
-
-using System.Reflection.Runtime.General;
-
-namespace Internal.Reflection.Execution.PayForPlayExperience
-{
- internal static partial class DiagnosticMappingTables
- {
- // Get the diagnostic name string for a type.
- // Returns true if the function is successful.
- // runtimeTypeHandle represents the type to get a name for
- // diagnosticName is the name that is returned
- public static bool TryGetDiagnosticStringForNamedType(RuntimeTypeHandle runtimeTypeHandle, out string diagnosticName)
- {
- diagnosticName = null;
- ExecutionEnvironmentImplementation executionEnvironment = ReflectionExecution.ExecutionEnvironment;
-
- MetadataReader reader;
- TypeReferenceHandle typeReferenceHandle;
- if (executionEnvironment.TryGetTypeReferenceForNamedType(runtimeTypeHandle, out reader, out typeReferenceHandle))
- {
- diagnosticName = GetTypeFullNameFromTypeRef(typeReferenceHandle, reader);
- return true;
- }
-
- QTypeDefinition qTypeDefinition;
- if (executionEnvironment.TryGetMetadataForNamedType(runtimeTypeHandle, out qTypeDefinition))
- {
- TryGetFullNameFromTypeDefEcma(qTypeDefinition, ref diagnosticName);
- if (diagnosticName != null)
- return true;
-
- if (qTypeDefinition.IsNativeFormatMetadataBased)
- {
- TypeDefinitionHandle typeDefinitionHandle = qTypeDefinition.NativeFormatHandle;
- diagnosticName = GetTypeFullNameFromTypeDef(typeDefinitionHandle, qTypeDefinition.NativeFormatReader);
- return true;
- }
- }
- return false;
- }
-
- static partial void TryGetFullNameFromTypeDefEcma(QTypeDefinition qTypeDefinition, ref string result);
-
- private static string GetTypeFullNameFromTypeRef(TypeReferenceHandle typeReferenceHandle, MetadataReader reader)
- {
- TypeReference typeReference = typeReferenceHandle.GetTypeReference(reader);
- string s = typeReference.TypeName.GetString(reader);
- Handle parentHandle = typeReference.ParentNamespaceOrType;
- HandleType parentHandleType = parentHandle.HandleType;
- if (parentHandleType == HandleType.TypeReference)
- {
- string containingTypeName = GetTypeFullNameFromTypeRef(parentHandle.ToTypeReferenceHandle(reader), reader);
- s = containingTypeName + "+" + s;
- }
- else if (parentHandleType == HandleType.NamespaceReference)
- {
- NamespaceReferenceHandle namespaceReferenceHandle = parentHandle.ToNamespaceReferenceHandle(reader);
- for (;;)
- {
- NamespaceReference namespaceReference = namespaceReferenceHandle.GetNamespaceReference(reader);
- string namespacePart = namespaceReference.Name.GetStringOrNull(reader);
- if (namespacePart == null)
- break; // Reached the root namespace.
- s = namespacePart + "." + s;
- if (namespaceReference.ParentScopeOrNamespace.HandleType != HandleType.NamespaceReference)
- break; // Should have reached the root namespace first but this helper is for ToString() - better to
- // return partial information than crash.
- namespaceReferenceHandle = namespaceReference.ParentScopeOrNamespace.ToNamespaceReferenceHandle(reader);
- }
- }
- else
- {
- // If we got here, the metadata is illegal but this helper is for ToString() - better to
- // return something partial than throw.
- }
- return s;
- }
-
- private static string GetTypeFullNameFromTypeDef(TypeDefinitionHandle typeDefinitionHandle, MetadataReader reader)
- {
- string s;
-
- TypeDefinition typeDefinition = typeDefinitionHandle.GetTypeDefinition(reader);
- s = typeDefinition.Name.GetString(reader);
-
- TypeDefinitionHandle enclosingTypeDefHandle = typeDefinition.EnclosingType;
- if (!enclosingTypeDefHandle.IsNull(reader))
- {
- string containingTypeName = GetTypeFullNameFromTypeDef(enclosingTypeDefHandle, reader);
- s = containingTypeName + "+" + s;
- }
- else
- {
- NamespaceDefinitionHandle namespaceHandle = typeDefinition.NamespaceDefinition;
- for (;;)
- {
- NamespaceDefinition namespaceDefinition = namespaceHandle.GetNamespaceDefinition(reader);
- string namespacePart = namespaceDefinition.Name.GetStringOrNull(reader);
- if (namespacePart == null)
- break; // Reached the root namespace.
- s = namespacePart + "." + s;
- if (namespaceDefinition.ParentScopeOrNamespace.HandleType != HandleType.NamespaceDefinition)
- break; // Should have reached the root namespace first but this helper is for ToString() - better to
- // return partial information than crash.
- namespaceHandle = namespaceDefinition.ParentScopeOrNamespace.ToNamespaceDefinitionHandle(reader);
- }
- }
- return s;
- }
- }
-}
{
return type.Name;
}
- else if (hasRuntimeTypeHandle)
- {
- string s;
- if (!DiagnosticMappingTables.TryGetDiagnosticStringForNamedType(runtimeTypeHandle, out s))
- return null;
-
- return s;
- }
else
{
return type.FullName;
if (!qMethodDefinition.IsNativeFormatMetadataBased)
return false;
- if (!ExecutionEnvironment.TryGetMetadataForNamedType(declaringTypeHandle, out QTypeDefinition qTypeDefinition))
- return false;
+ QTypeDefinition qTypeDefinition = ExecutionEnvironment.GetMetadataForNamedType(declaringTypeHandle);
Debug.Assert(qTypeDefinition.IsNativeFormatMetadataBased);
Debug.Assert(qTypeDefinition.NativeFormatReader == qMethodDefinition.NativeFormatReader);
_executionEnvironment = executionEnvironment;
}
- public sealed override bool IsReflectionBlocked(RuntimeTypeHandle typeHandle)
- {
- return _executionEnvironment.IsReflectionBlocked(typeHandle);
- }
-
//=======================================================================================
// This group of methods jointly service the Type.GetTypeFromHandle() path. The caller
// is responsible for analyzing the RuntimeTypeHandle to figure out which flavor to call.
//=======================================================================================
- public sealed override Type GetNamedTypeForHandle(RuntimeTypeHandle typeHandle, bool isGenericTypeDefinition)
+ public sealed override Type GetNamedTypeForHandle(RuntimeTypeHandle typeHandle)
{
- return _executionDomain.GetNamedTypeForHandle(typeHandle, isGenericTypeDefinition);
+ return _executionDomain.GetNamedTypeForHandle(typeHandle);
}
public sealed override Type GetArrayTypeForHandle(RuntimeTypeHandle typeHandle)
return _executionDomain.GetTypeHandleIfAvailable(type);
}
- public sealed override bool SupportsReflection(Type type)
- {
- return _executionDomain.SupportsReflection(type);
- }
-
public sealed override MethodInfo GetDelegateMethod(Delegate del)
{
return DelegateMethodInfoRetriever.GetDelegateMethodInfo(del);
<Compile Include="Internal\Reflection\Execution\MethodInvokers\InstanceMethodInvoker.cs" />
<Compile Include="Internal\Reflection\Execution\MethodInvokers\StaticMethodInvoker.cs" />
<Compile Include="Internal\Reflection\Execution\MethodInvokers\VirtualMethodInvoker.cs" />
- <Compile Include="Internal\Reflection\Execution\PayForPlayExperience\DiagnosticMappingTables.cs" />
<Compile Include="Internal\Reflection\Execution\PayForPlayExperience\MissingMetadataExceptionCreator.cs" />
<Compile Include="Internal\Reflection\Extensions\NonPortable\DelegateMethodInfoRetriever.cs" />
<Compile Include="Internal\Runtime\CompilerHelpers\LibraryInitializer.cs" />
</ItemGroup>
<ItemGroup>
- <Compile Include="$(CompilerCommonPath)\Internal\Runtime\MetadataBlob.cs" >
+ <Compile Include="$(CompilerCommonPath)\Internal\Runtime\MetadataBlob.cs">
<Link>Internal\Runtime\MetadataBlob.cs</Link>
</Compile>
- <Compile Include="$(CommonPath)\System\NotImplemented.cs" >
+ <Compile Include="$(CommonPath)\System\NotImplemented.cs">
<Link>System\NotImplemented.cs</Link>
</Compile>
<Compile Include="$(LibrariesProjectRoot)\System.Private.CoreLib\src\System\SR.cs" />
- <Compile Include="$(AotCommonPath)\System\Collections\Generic\LowLevelList.cs" >
+ <Compile Include="$(AotCommonPath)\System\Collections\Generic\LowLevelList.cs">
<Link>System\Collections\Generic\LowLevelList.cs</Link>
</Compile>
- <Compile Include="$(AotCommonPath)\System\Collections\Generic\LowLevelDictionary.cs" >
+ <Compile Include="$(AotCommonPath)\System\Collections\Generic\LowLevelDictionary.cs">
<Link>System\Collections\Generic\LowLevelDictionary.cs</Link>
</Compile>
- <Compile Include="$(CompilerCommonPath)\Internal\LowLevelLinq\LowLevelEnumerable.cs" >
+ <Compile Include="$(CompilerCommonPath)\Internal\LowLevelLinq\LowLevelEnumerable.cs">
<Link>Internal\LowLevelLinq\LowLevelEnumerable.cs</Link>
</Compile>
- <Compile Include="$(CompilerCommonPath)\Internal\LowLevelLinq\LowLevelEnumerable.ToArray.cs" >
+ <Compile Include="$(CompilerCommonPath)\Internal\LowLevelLinq\LowLevelEnumerable.ToArray.cs">
<Link>Internal\LowLevelLinq\LowLevelEnumerable.ToArray.cs</Link>
</Compile>
- <Compile Include="$(LibrariesProjectRoot)\System.Private.CoreLib\src\System\Collections\HashHelpers.cs" >
+ <Compile Include="$(LibrariesProjectRoot)\System.Private.CoreLib\src\System\Collections\HashHelpers.cs">
<Link>System\Collections\HashHelpers.cs</Link>
</Compile>
- <Compile Include="$(AotCommonPath)\System\Collections\Generic\Empty.cs" >
+ <Compile Include="$(AotCommonPath)\System\Collections\Generic\Empty.cs">
<Link>System\Collections\Generic\Empty.cs</Link>
</Compile>
- <Compile Include="$(AotCommonPath)\System\Runtime\CompilerServices\__BlockAllReflectionAttribute.cs">
- <Link>System\Runtime\CompilerServices\__BlockAllReflectionAttribute.cs</Link>
- </Compile>
</ItemGroup>
</Project>
<Compile Include="$(CompilerCommonPath)\Internal\Runtime\MetadataBlob.cs">
<Link>Internal\Runtime\MetadataBlob.cs</Link>
</Compile>
- <Compile Include="$(AotCommonPath)\System\Runtime\CompilerServices\__BlockAllReflectionAttribute.cs">
- <Link>System\Runtime\CompilerServices\__BlockAllReflectionAttribute.cs</Link>
- </Compile>
</ItemGroup>
</Project>
public static string LowLevelToString(this RuntimeTypeHandle rtth)
{
- TypeReferenceHandle typeRefHandle;
QTypeDefinition qTypeDefinition;
MetadataReader reader;
return typeDefHandle.GetFullName(reader);
}
- // Try to get the name from diagnostic metadata
- if (TypeLoaderEnvironment.TryGetTypeReferenceForNamedType(rtth, out reader, out typeRefHandle))
- {
- return typeRefHandle.GetFullName(reader);
- }
-
// Fallback implementation when no metadata available
return LowLevelToStringRawEETypeAddress(rtth);
}
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-
-using global::System;
-using global::System.Reflection;
-using global::Internal.Metadata.NativeFormat;
-
-using Debug = System.Diagnostics.Debug;
-using AssemblyFlags = Internal.Metadata.NativeFormat.AssemblyFlags;
-
-namespace Internal.Runtime.TypeLoader
-{
- public static class MetadataReaderHelpers
- {
- public static bool CompareTypeReferenceAcrossModules(TypeReferenceHandle tr1, MetadataReader mr1, TypeReferenceHandle tr2, MetadataReader mr2)
- {
- TypeReference trData1 = mr1.GetTypeReference(tr1);
- TypeReference trData2 = mr2.GetTypeReference(tr2);
- if (!trData1.TypeName.StringEquals(trData2.TypeName.GetConstantStringValue(mr2).Value, mr1))
- return false;
-
- if (trData1.ParentNamespaceOrType.HandleType != trData2.ParentNamespaceOrType.HandleType)
- return false;
-
- if (trData1.ParentNamespaceOrType.HandleType == HandleType.TypeReference)
- return CompareTypeReferenceAcrossModules(trData1.ParentNamespaceOrType.ToTypeReferenceHandle(mr1), mr1, trData2.ParentNamespaceOrType.ToTypeReferenceHandle(mr2), mr2);
-
- return CompareNamespaceReferenceAcrossModules(trData1.ParentNamespaceOrType.ToNamespaceReferenceHandle(mr1), mr1, trData2.ParentNamespaceOrType.ToNamespaceReferenceHandle(mr2), mr2);
- }
-
- public static bool CompareNamespaceReferenceAcrossModules(NamespaceReferenceHandle nr1, MetadataReader mr1, NamespaceReferenceHandle nr2, MetadataReader mr2)
- {
- NamespaceReference nrData1 = mr1.GetNamespaceReference(nr1);
- NamespaceReference nrData2 = mr2.GetNamespaceReference(nr2);
-
- if (nrData1.Name.IsNull(mr1) != nrData2.Name.IsNull(mr2))
- return false;
-
- if (!nrData1.Name.IsNull(mr1))
- {
- if (!nrData1.Name.StringEquals(nrData2.Name.GetConstantStringValue(mr2).Value, mr1))
- return false;
- }
-
- if (nrData1.ParentScopeOrNamespace.HandleType != nrData1.ParentScopeOrNamespace.HandleType)
- return false;
-
- if (nrData1.ParentScopeOrNamespace.HandleType == HandleType.NamespaceReference)
- return CompareNamespaceReferenceAcrossModules(nrData1.ParentScopeOrNamespace.ToNamespaceReferenceHandle(mr1), mr1, nrData2.ParentScopeOrNamespace.ToNamespaceReferenceHandle(mr2), mr2);
-
- return CompareScopeReferenceAcrossModules(nrData1.ParentScopeOrNamespace.ToScopeReferenceHandle(mr1), mr1, nrData2.ParentScopeOrNamespace.ToScopeReferenceHandle(mr2), mr2);
- }
-
- public static bool CompareScopeReferenceAcrossModules(ScopeReferenceHandle sr1, MetadataReader mr1, ScopeReferenceHandle sr2, MetadataReader mr2)
- {
- ScopeReference srData1 = mr1.GetScopeReference(sr1);
- ScopeReference srData2 = mr2.GetScopeReference(sr2);
- if (!srData1.Name.StringEquals(srData2.Name.GetConstantStringValue(mr2).Value, mr1))
- return false;
-
- if (!srData1.Culture.StringEquals(srData2.Culture.GetConstantStringValue(mr2).Value, mr1))
- return false;
-
- if (srData1.MajorVersion != srData2.MajorVersion)
- return false;
-
- if (srData1.MinorVersion != srData2.MinorVersion)
- return false;
-
- if (srData1.RevisionNumber != srData2.RevisionNumber)
- return false;
-
- if (srData1.BuildNumber != srData2.BuildNumber)
- return false;
-
- return true;
- }
-
- public static bool CompareTypeReferenceToDefinition(TypeReferenceHandle tr1, MetadataReader mr1, TypeDefinitionHandle td2, MetadataReader mr2)
- {
- // TODO! The correct implementation here is probably to call into the assembly binder, but that's not available due to layering.
- // For now, just implement comparison, which will be equivalent in all cases until we support loading multiple copies of the same assembly
-
- TypeReference trData1 = mr1.GetTypeReference(tr1);
- TypeDefinition tdData2 = mr2.GetTypeDefinition(td2);
-
- if (!trData1.TypeName.StringEquals(tdData2.Name.GetConstantStringValue(mr2).Value, mr1))
- return false;
-
- switch (trData1.ParentNamespaceOrType.HandleType)
- {
- case HandleType.TypeReference:
- if (tdData2.EnclosingType.IsNull(mr2))
- return false;
-
- return CompareTypeReferenceToDefinition(trData1.ParentNamespaceOrType.ToTypeReferenceHandle(mr1), mr1, tdData2.EnclosingType, mr2);
-
- case HandleType.NamespaceReference:
- return CompareNamespaceReferenceToDefinition(trData1.ParentNamespaceOrType.ToNamespaceReferenceHandle(mr1), mr1, tdData2.NamespaceDefinition, mr2);
-
- default:
- Debug.Assert(false);
- throw new BadImageFormatException();
- }
- }
-
- public static bool CompareNamespaceReferenceToDefinition(NamespaceReferenceHandle nr1, MetadataReader mr1, NamespaceDefinitionHandle nd2, MetadataReader mr2)
- {
- NamespaceReference nrData1 = mr1.GetNamespaceReference(nr1);
- NamespaceDefinition ndData2 = mr2.GetNamespaceDefinition(nd2);
-
- if (nrData1.Name.IsNull(mr1) != ndData2.Name.IsNull(mr2))
- return false;
-
- if (!nrData1.Name.IsNull(mr1))
- {
- if (!nrData1.Name.StringEquals(ndData2.Name.GetConstantStringValue(mr2).Value, mr1))
- return false;
- }
-
- switch (nrData1.ParentScopeOrNamespace.HandleType)
- {
- case HandleType.NamespaceReference:
- if (ndData2.ParentScopeOrNamespace.HandleType != HandleType.NamespaceDefinition)
- return false;
- return CompareNamespaceReferenceToDefinition(nrData1.ParentScopeOrNamespace.ToNamespaceReferenceHandle(mr1), mr1, ndData2.ParentScopeOrNamespace.ToNamespaceDefinitionHandle(mr2), mr2);
-
- case HandleType.ScopeReference:
- if (ndData2.ParentScopeOrNamespace.HandleType != HandleType.ScopeDefinition)
- return false;
-
- return CompareScopeReferenceToDefinition(nrData1.ParentScopeOrNamespace.ToScopeReferenceHandle(mr1), mr1, ndData2.ParentScopeOrNamespace.ToScopeDefinitionHandle(mr2), mr2);
-
- default:
- Debug.Assert(false);
- throw new BadImageFormatException();
- }
- }
-
- public static bool CompareScopeReferenceToDefinition(ScopeReferenceHandle sr1, MetadataReader mr1, ScopeDefinitionHandle sd2, MetadataReader mr2)
- {
- ScopeReference srData1 = mr1.GetScopeReference(sr1);
- ScopeDefinition sdData2 = mr2.GetScopeDefinition(sd2);
- if (!srData1.Name.StringEquals(sdData2.Name.GetConstantStringValue(mr2).Value, mr1))
- return false;
-
- if (!srData1.Culture.StringEquals(sdData2.Culture.GetConstantStringValue(mr2).Value, mr1))
- return false;
-
- if (srData1.MajorVersion != sdData2.MajorVersion)
- return false;
-
- if (srData1.MinorVersion != sdData2.MinorVersion)
- return false;
-
- if (srData1.RevisionNumber != sdData2.RevisionNumber)
- return false;
-
- if (srData1.BuildNumber != sdData2.BuildNumber)
- return false;
-
- return true;
- }
-
- }
-}
}
/// <summary>
- /// Return the metadata handle for a TypeRef if this type was referenced indirectly by other type that pay-for-play has denoted as browsable
- /// (for example, as part of a method signature.)
- ///
- /// This is only used in "debug" builds to provide better diagnostics when metadata is missing.
- ///
- /// Preconditions:
- /// runtimeTypeHandle is a typedef (not a constructed type such as an array or generic instance.)
- /// </summary>
- /// <param name="runtimeTypeHandle">MethodTable of the type in question</param>
- /// <param name="metadataReader">Metadata reader for the type</param>
- /// <param name="typeRefHandle">Located TypeRef handle</param>
- public static unsafe bool TryGetTypeReferenceForNamedType(RuntimeTypeHandle runtimeTypeHandle, out MetadataReader metadataReader, out TypeReferenceHandle typeRefHandle)
- {
- int hashCode = runtimeTypeHandle.GetHashCode();
-
- // Iterate over all modules, starting with the module that defines the MethodTable
- foreach (NativeFormatModuleInfo module in ModuleList.EnumerateModules(RuntimeAugments.GetModuleFromTypeHandle(runtimeTypeHandle)))
- {
- NativeReader typeMapReader;
- if (TryGetNativeReaderForBlob(module, ReflectionMapBlob.TypeMap, out typeMapReader))
- {
- NativeParser typeMapParser = new NativeParser(typeMapReader, 0);
- NativeHashtable typeHashtable = new NativeHashtable(typeMapParser);
-
- ExternalReferencesTable externalReferences = default(ExternalReferencesTable);
- externalReferences.InitializeCommonFixupsTable(module);
-
- var lookup = typeHashtable.Lookup(hashCode);
- NativeParser entryParser;
- while (!(entryParser = lookup.GetNext()).IsNull)
- {
- RuntimeTypeHandle foundType = externalReferences.GetRuntimeTypeHandleFromIndex(entryParser.GetUnsigned());
- if (foundType.Equals(runtimeTypeHandle))
- {
- Handle entryMetadataHandle = entryParser.GetUnsigned().AsHandle();
- if (entryMetadataHandle.HandleType == HandleType.TypeReference)
- {
- metadataReader = module.MetadataReader;
- typeRefHandle = entryMetadataHandle.ToTypeReferenceHandle(metadataReader);
- return true;
- }
- }
- }
- }
- }
-
- metadataReader = null;
- typeRefHandle = default(TypeReferenceHandle);
-
- return false;
- }
-
- /// <summary>
- /// Return the RuntimeTypeHandle for the named type referenced by another type that pay-for-play denotes as browsable (for example,
- /// in a member signature.) This will only find the typehandle if it is not defined in the current module, and is primarily used
- /// to find non-browsable types.
- ///
- /// This is used to ensure that we can produce a Type object if requested and that it match up with the analogous
- /// Type obtained via typeof().
- ///
- ///
- /// Preconditions:
- /// metadataReader + typeRefHandle - a valid metadata reader + typeReferenceHandle where "metadataReader" is one
- /// of the metadata readers returned by ExecutionEnvironment.MetadataReaders.
- ///
- /// Note: Although this method has a "bool" return value like the other mapping table accessors, the pay-for-play design
- /// guarantees that any type that has a metadata TypeReference to it also has a RuntimeTypeHandle underneath.
- /// </summary>
- /// <param name="metadataReader">Metadata reader for module containing the type reference</param>
- /// <param name="typeRefHandle">TypeRef handle to look up</param>
- /// <param name="runtimeTypeHandle">Resolved MethodTable for the type reference</param>
- /// <param name="searchAllModules">Search all modules</param>
- public static unsafe bool TryGetNamedTypeForTypeReference(MetadataReader metadataReader, TypeReferenceHandle typeRefHandle, out RuntimeTypeHandle runtimeTypeHandle, bool searchAllModules = false)
- {
- int hashCode = typeRefHandle.ComputeHashCode(metadataReader);
- NativeFormatModuleInfo typeRefModule = ModuleList.Instance.GetModuleInfoForMetadataReader(metadataReader);
- return TryGetNamedTypeForTypeReference_Inner(metadataReader, typeRefModule, typeRefHandle, hashCode, typeRefModule, out runtimeTypeHandle);
- }
-
- /// <summary>
- /// Return the RuntimeTypeHandle for the named type referenced by another type that pay-for-play denotes as browsable (for example,
- /// in a member signature.) This lookup will attempt to resolve to an MethodTable in any module to cover situations where the type
- /// does not have a TypeDefinition (non-browsable type) as well as cases where it does.
- ///
- /// Preconditions:
- /// metadataReader + typeRefHandle - a valid metadata reader + typeReferenceHandle where "metadataReader" is one
- /// of the metadata readers returned by ExecutionEnvironment.MetadataReaders.
- ///
- /// Note: Although this method has a "bool" return value like the other mapping table accessors, the pay-for-play design
- /// guarantees that any type that has a metadata TypeReference to it also has a RuntimeTypeHandle underneath.
- /// </summary>
- /// <param name="metadataReader">Metadata reader for module containing the type reference</param>
- /// <param name="typeRefHandle">TypeRef handle to look up</param>
- /// <param name="runtimeTypeHandle">Resolved MethodTable for the type reference</param>
- public static unsafe bool TryResolveNamedTypeForTypeReference(MetadataReader metadataReader, TypeReferenceHandle typeRefHandle, out RuntimeTypeHandle runtimeTypeHandle)
- {
- int hashCode = typeRefHandle.ComputeHashCode(metadataReader);
- NativeFormatModuleInfo typeRefModule = ModuleList.Instance.GetModuleInfoForMetadataReader(metadataReader);
- runtimeTypeHandle = default(RuntimeTypeHandle);
-
- foreach (NativeFormatModuleInfo module in ModuleList.EnumerateModules(typeRefModule.Handle))
- {
- if (TryGetNamedTypeForTypeReference_Inner(metadataReader, typeRefModule, typeRefHandle, hashCode, module, out runtimeTypeHandle))
- return true;
- }
-
- return false;
- }
-
- private static unsafe bool TryGetNamedTypeForTypeReference_Inner(MetadataReader metadataReader,
- NativeFormatModuleInfo typeRefModule,
- TypeReferenceHandle typeRefHandle,
- int hashCode,
- NativeFormatModuleInfo module,
- out RuntimeTypeHandle runtimeTypeHandle)
- {
- Debug.Assert(typeRefModule == ModuleList.Instance.GetModuleInfoForMetadataReader(metadataReader));
-
- NativeReader typeMapReader;
- if (TryGetNativeReaderForBlob(module, ReflectionMapBlob.TypeMap, out typeMapReader))
- {
- NativeParser typeMapParser = new NativeParser(typeMapReader, 0);
- NativeHashtable typeHashtable = new NativeHashtable(typeMapParser);
-
- ExternalReferencesTable externalReferences = default(ExternalReferencesTable);
- externalReferences.InitializeCommonFixupsTable(module);
-
- var lookup = typeHashtable.Lookup(hashCode);
- NativeParser entryParser;
- while (!(entryParser = lookup.GetNext()).IsNull)
- {
- var foundTypeIndex = entryParser.GetUnsigned();
- var handle = entryParser.GetUnsigned().AsHandle();
-
- if (module == typeRefModule)
- {
- if (handle.Equals(typeRefHandle))
- {
- runtimeTypeHandle = externalReferences.GetRuntimeTypeHandleFromIndex(foundTypeIndex);
- return true;
- }
- }
- else if (handle.HandleType == HandleType.TypeReference)
- {
- MetadataReader mrFoundHandle = module.MetadataReader;
- // We found a type reference handle in another module.. see if it matches
- if (MetadataReaderHelpers.CompareTypeReferenceAcrossModules(typeRefHandle, metadataReader, handle.ToTypeReferenceHandle(mrFoundHandle), mrFoundHandle))
- {
- runtimeTypeHandle = externalReferences.GetRuntimeTypeHandleFromIndex(foundTypeIndex);
- return true;
- }
- }
- else if (handle.HandleType == HandleType.TypeDefinition)
- {
- // We found a type definition handle in another module. See if it matches
- MetadataReader mrFoundHandle = module.MetadataReader;
- // We found a type definition handle in another module.. see if it matches
- if (MetadataReaderHelpers.CompareTypeReferenceToDefinition(typeRefHandle, metadataReader, handle.ToTypeDefinitionHandle(mrFoundHandle), mrFoundHandle))
- {
- runtimeTypeHandle = externalReferences.GetRuntimeTypeHandleFromIndex(foundTypeIndex);
- return true;
- }
- }
- }
- }
-
- runtimeTypeHandle = default(RuntimeTypeHandle);
- return false;
- }
-
- /// <summary>
/// Given a RuntimeTypeHandle for any non-dynamic type E, return a RuntimeTypeHandle for type E[]
/// if the pay for play policy denotes E[] as browsable. This is used to implement Array.CreateInstance().
/// This is not equivalent to calling TryGetMultiDimTypeForElementType() with a rank of 1!
}
}
- // If not found in the invoke map, try the default constructor map
- NativeReader defaultCtorMapReader;
- if (TryGetNativeReaderForBlob(mappingTableModule, ReflectionMapBlob.DefaultConstructorMap, out defaultCtorMapReader))
- {
- NativeParser defaultCtorMapParser = new NativeParser(defaultCtorMapReader, 0);
- NativeHashtable defaultCtorHashtable = new NativeHashtable(defaultCtorMapParser);
-
- ExternalReferencesTable externalReferencesForDefaultCtorMap = default(ExternalReferencesTable);
- externalReferencesForDefaultCtorMap.InitializeCommonFixupsTable(mappingTableModule);
- var lookup = defaultCtorHashtable.Lookup(canonHelper.LookupHashCode);
- NativeParser defaultCtorParser;
- while (!(defaultCtorParser = lookup.GetNext()).IsNull)
- {
- RuntimeTypeHandle entryType = externalReferencesForDefaultCtorMap.GetRuntimeTypeHandleFromIndex(defaultCtorParser.GetUnsigned());
- if (!canonHelper.IsCanonicallyEquivalent(entryType))
- continue;
-
- return externalReferencesForDefaultCtorMap.GetFunctionPointerFromIndex(defaultCtorParser.GetUnsigned());
- }
- }
return IntPtr.Zero;
}
}
break;
- case HandleType.TypeReference:
- if (!TypeLoaderEnvironment.TryResolveNamedTypeForTypeReference(
- _metadataReader, typeHandle.ToTypeReferenceHandle(_metadataReader), out type2))
- {
- return false;
- }
- break;
-
default:
return false;
}
Debug.Assert(!genericDefinitionHandle.IsNull());
#if DEBUG
- TypeReferenceHandle typeRefHandle;
QTypeDefinition qTypeDefinition;
- MetadataReader reader;
string enclosingDummy;
typeDefHandle.GetFullName(qTypeDefinition.NativeFormatReader, out name, out enclosingDummy, out nsName);
assemblyName = typeDefHandle.GetContainingModuleName(qTypeDefinition.NativeFormatReader);
}
- // Try to get the name from diagnostic metadata
- else if (TypeLoaderEnvironment.TryGetTypeReferenceForNamedType(genericDefinitionHandle, out reader, out typeRefHandle))
- {
- typeRefHandle.GetFullName(reader, out name, out enclosingDummy, out nsName);
- assemblyName = typeRefHandle.GetContainingModuleName(reader);
- }
else
#endif
{
<Compile Include="Internal\Runtime\TypeLoader\LockFreeObjectInterner.cs" />
<Compile Include="Internal\Runtime\TypeLoader\LowLevelStringConverter.cs" />
<Compile Include="Internal\Runtime\TypeLoader\MetadataNameExtensions.cs" />
- <Compile Include="Internal\Runtime\TypeLoader\MetadataReaderHelpers.cs" />
<Compile Include="Internal\Runtime\TypeLoader\ModuleList.cs" />
<Compile Include="Internal\Runtime\TypeLoader\NativeLayoutInfoLoadContext.cs" />
<Compile Include="Internal\Runtime\TypeLoader\NativeLayoutInterfacesAlgorithm.cs" />
<Compile Include="Internal\TypeSystem\ThrowHelper.cs" />
<Compile Include="Internal\TypeSystem\TypeDesc.Runtime.cs" />
<Compile Include="Internal\TypeSystem\TypeSystemContext.Runtime.cs" />
- <Compile Include="$(AotCommonPath)\System\Runtime\CompilerServices\__BlockAllReflectionAttribute.cs">
- <Link>System\Runtime\CompilerServices\__BlockAllReflectionAttribute.cs</Link>
- </Compile>
</ItemGroup>
<ItemGroup Condition="'$(Configuration)'=='Debug'">
<Compile Include="$(CompilerCommonPath)\TypeSystem\Common\TypeDesc.ToString.cs">
InterfaceGenericVirtualMethodTableNode,
GenericMethodsTemplateMap,
GenericTypesTemplateMap,
- BlockReflectionTypeMapNode,
StaticsInfoHashtableNode,
ReflectionVirtualInvokeMapNode,
ArrayOfEmbeddedPointersNode,
- DefaultConstructorMapNode,
ExternalReferencesTableNode,
StackTraceEmbeddedMetadataNode,
StackTraceMethodMappingNode,
_writer.WriteLine("#if SYSTEM_PRIVATE_CORELIB");
WriteScopeAttribute("[CLSCompliant(false)]");
- WriteScopeAttribute("[ReflectionBlocked]");
_writer.WriteLine("#endif");
}
}
[Flags]
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public enum AssemblyFlags : uint
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public enum AssemblyHashAlgorithm : uint
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public enum GenericParameterKind : byte
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public enum NamedArgumentMemberKind : byte
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public enum SignatureCallingConvention : byte
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public enum HandleType : byte
{
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct ArraySignature
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct ArraySignatureHandle
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct ByReferenceSignature
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct ByReferenceSignatureHandle
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct ConstantBooleanArray
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct ConstantBooleanArrayHandle
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct ConstantBooleanValue
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct ConstantBooleanValueHandle
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct ConstantBoxedEnumValue
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct ConstantBoxedEnumValueHandle
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct ConstantByteArray
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct ConstantByteArrayHandle
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct ConstantByteValue
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct ConstantByteValueHandle
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct ConstantCharArray
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct ConstantCharArrayHandle
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct ConstantCharValue
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct ConstantCharValueHandle
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct ConstantDoubleArray
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct ConstantDoubleArrayHandle
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct ConstantDoubleValue
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct ConstantDoubleValueHandle
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct ConstantEnumArray
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct ConstantEnumArrayHandle
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct ConstantHandleArray
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct ConstantHandleArrayHandle
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct ConstantInt16Array
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct ConstantInt16ArrayHandle
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct ConstantInt16Value
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct ConstantInt16ValueHandle
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct ConstantInt32Array
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct ConstantInt32ArrayHandle
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct ConstantInt32Value
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct ConstantInt32ValueHandle
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct ConstantInt64Array
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct ConstantInt64ArrayHandle
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct ConstantInt64Value
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct ConstantInt64ValueHandle
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct ConstantReferenceValue
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct ConstantReferenceValueHandle
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct ConstantSByteArray
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct ConstantSByteArrayHandle
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct ConstantSByteValue
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct ConstantSByteValueHandle
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct ConstantSingleArray
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct ConstantSingleArrayHandle
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct ConstantSingleValue
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct ConstantSingleValueHandle
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct ConstantStringArray
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct ConstantStringArrayHandle
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct ConstantStringValue
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct ConstantStringValueHandle
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct ConstantUInt16Array
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct ConstantUInt16ArrayHandle
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct ConstantUInt16Value
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct ConstantUInt16ValueHandle
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct ConstantUInt32Array
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct ConstantUInt32ArrayHandle
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct ConstantUInt32Value
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct ConstantUInt32ValueHandle
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct ConstantUInt64Array
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct ConstantUInt64ArrayHandle
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct ConstantUInt64Value
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct ConstantUInt64ValueHandle
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct CustomAttribute
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct CustomAttributeHandle
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct Event
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct EventHandle
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct Field
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct FieldHandle
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct FieldSignature
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct FieldSignatureHandle
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct FunctionPointerSignature
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct FunctionPointerSignatureHandle
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct GenericParameter
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct GenericParameterHandle
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct MemberReference
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct MemberReferenceHandle
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct Method
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct MethodHandle
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct MethodInstantiation
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct MethodInstantiationHandle
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct MethodSemantics
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct MethodSemanticsHandle
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct MethodSignature
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct MethodSignatureHandle
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct MethodTypeVariableSignature
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct MethodTypeVariableSignatureHandle
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct ModifiedType
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct ModifiedTypeHandle
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct NamedArgument
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct NamedArgumentHandle
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct NamespaceDefinition
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct NamespaceDefinitionHandle
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct NamespaceReference
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct NamespaceReferenceHandle
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct Parameter
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct ParameterHandle
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct PointerSignature
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct PointerSignatureHandle
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct Property
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct PropertyHandle
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct PropertySignature
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct PropertySignatureHandle
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct QualifiedField
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct QualifiedFieldHandle
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct QualifiedMethod
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct QualifiedMethodHandle
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct SZArraySignature
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct SZArraySignatureHandle
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct ScopeDefinition
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct ScopeDefinitionHandle
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct ScopeReference
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct ScopeReferenceHandle
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct TypeDefinition
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct TypeDefinitionHandle
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct TypeForwarder
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct TypeForwarderHandle
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct TypeInstantiationSignature
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct TypeInstantiationSignatureHandle
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct TypeReference
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct TypeReferenceHandle
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct TypeSpecification
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct TypeSpecificationHandle
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct TypeVariableSignature
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct TypeVariableSignatureHandle
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct NamedArgumentHandleCollection
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public struct Enumerator
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct MethodSemanticsHandleCollection
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public struct Enumerator
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct CustomAttributeHandleCollection
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public struct Enumerator
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct ParameterHandleCollection
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public struct Enumerator
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct GenericParameterHandleCollection
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public struct Enumerator
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct TypeDefinitionHandleCollection
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public struct Enumerator
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct TypeForwarderHandleCollection
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public struct Enumerator
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct NamespaceDefinitionHandleCollection
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public struct Enumerator
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct MethodHandleCollection
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public struct Enumerator
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct FieldHandleCollection
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public struct Enumerator
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct PropertyHandleCollection
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public struct Enumerator
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct EventHandleCollection
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public struct Enumerator
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct ScopeDefinitionHandleCollection
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public struct Enumerator
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct BooleanCollection
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public struct Enumerator
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct CharCollection
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public struct Enumerator
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct ByteCollection
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public struct Enumerator
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct SByteCollection
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public struct Enumerator
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct Int16Collection
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public struct Enumerator
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct UInt16Collection
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public struct Enumerator
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct Int32Collection
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public struct Enumerator
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct UInt32Collection
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public struct Enumerator
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct Int64Collection
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public struct Enumerator
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct UInt64Collection
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public struct Enumerator
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct SingleCollection
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public struct Enumerator
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct DoubleCollection
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public struct Enumerator
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct Handle
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial struct HandleCollection
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public struct Enumerator
{
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public partial class MetadataReader
{
{
// This Enum matches CorMethodSemanticsAttr defined in CorHdr.h
[Flags]
-#if SYSTEM_PRIVATE_CORELIB
- [ReflectionBlocked]
-#endif
public enum MethodSemanticsAttributes
{
Setter = 0x0001,
// This Enum matches CorPInvokeMap defined in CorHdr.h
[Flags]
-#if SYSTEM_PRIVATE_CORELIB
- [ReflectionBlocked]
-#endif
public enum PInvokeAttributes
{
NoMangle = 0x0001,
#if SYSTEM_PRIVATE_CORELIB
[CLSCompliant(false)]
- [ReflectionBlocked]
#endif
public static class NativeFormatReaderExtensions
{
ArrayMap = 2,
PointerTypeMap = 3,
FunctionPointerTypeMap = 4,
- BlockReflectionTypeMap = 5,
+ // unused = 5,
InvokeMap = 6,
VirtualInvokeMap = 7,
CommonFixupsTable = 8,
ByRefTypeMap = 11,
// unused = 12,
EmbeddedMetadata = 13,
- DefaultConstructorMap = 14,
+ // Unused = 14,
UnboxingAndInstantiatingStubMap = 15,
StructMarshallingStubMap = 16,
DelegateMarshallingStubMap = 17,
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-using Internal.TypeSystem;
-using Internal.TypeSystem.Ecma;
-
-using Debug = System.Diagnostics.Debug;
-using TypeAttributes = System.Reflection.TypeAttributes;
-using MethodAttributes = System.Reflection.MethodAttributes;
-using FieldAttributes = System.Reflection.FieldAttributes;
-
-namespace ILCompiler
-{
- /// <summary>
- /// Represents a metadata policy that blocks implementations details.
- /// </summary>
- public sealed class BlockedInternalsBlockingPolicy : MetadataBlockingPolicy
- {
- private enum ModuleBlockingMode
- {
- None,
- BlockedInternals,
- FullyBlocked,
- }
-
- private sealed class ModuleBlockingState
- {
- public ModuleDesc Module { get; }
- public ModuleBlockingMode BlockingMode { get; }
- public ModuleBlockingState(ModuleDesc module, ModuleBlockingMode mode)
- {
- Module = module;
- BlockingMode = mode;
- }
- }
-
- private sealed class BlockedModulesHashtable : LockFreeReaderHashtable<ModuleDesc, ModuleBlockingState>
- {
- protected override int GetKeyHashCode(ModuleDesc key) => key.GetHashCode();
- protected override int GetValueHashCode(ModuleBlockingState value) => value.Module.GetHashCode();
- protected override bool CompareKeyToValue(ModuleDesc key, ModuleBlockingState value) => ReferenceEquals(key, value.Module);
- protected override bool CompareValueToValue(ModuleBlockingState value1, ModuleBlockingState value2) => ReferenceEquals(value1.Module, value2.Module);
- protected override ModuleBlockingState CreateValueFromKey(ModuleDesc module)
- {
- ModuleBlockingMode blockingMode = ModuleBlockingMode.None;
-
- if (module.GetType("System.Runtime.CompilerServices", "__BlockAllReflectionAttribute", throwIfNotFound: false) != null)
- {
- blockingMode = ModuleBlockingMode.FullyBlocked;
- }
- else if (module.GetType("System.Runtime.CompilerServices", "__BlockReflectionAttribute", throwIfNotFound: false) != null)
- {
- blockingMode = ModuleBlockingMode.BlockedInternals;
- }
-
- return new ModuleBlockingState(module, blockingMode);
- }
- }
- private BlockedModulesHashtable _blockedModules = new BlockedModulesHashtable();
-
- private sealed class BlockingState
- {
- public EcmaType Type { get; }
- public bool IsBlocked { get; }
- public BlockingState(EcmaType type, bool isBlocked)
- {
- Type = type;
- IsBlocked = isBlocked;
- }
- }
-
- private sealed class BlockedTypeHashtable : LockFreeReaderHashtable<EcmaType, BlockingState>
- {
- private readonly BlockedModulesHashtable _blockedModules;
-
- public BlockedTypeHashtable(BlockedModulesHashtable blockedModules)
- {
- _blockedModules = blockedModules;
- }
-
- protected override int GetKeyHashCode(EcmaType key) => key.GetHashCode();
- protected override int GetValueHashCode(BlockingState value) => value.Type.GetHashCode();
- protected override bool CompareKeyToValue(EcmaType key, BlockingState value) => ReferenceEquals(key, value.Type);
- protected override bool CompareValueToValue(BlockingState value1, BlockingState value2) => ReferenceEquals(value1.Type, value2.Type);
- protected override BlockingState CreateValueFromKey(EcmaType type)
- {
- ModuleBlockingMode moduleBlockingMode = _blockedModules.GetOrCreateValue(type.EcmaModule).BlockingMode;
- bool isBlocked = ComputeIsBlocked(type, moduleBlockingMode);
- return new BlockingState(type, isBlocked);
- }
-
- private bool ComputeIsBlocked(EcmaType type, ModuleBlockingMode blockingMode)
- {
- // If the type is explicitly blocked, it's always blocked.
- if (type.HasCustomAttribute("System.Runtime.CompilerServices", "ReflectionBlockedAttribute"))
- return true;
-
- // If no blocking is applied to the module, the type is not blocked
- if (blockingMode == ModuleBlockingMode.None)
- return false;
-
- // <Module> type always gets metadata
- if (type.IsModuleType)
- return false;
-
- // The various SR types used in Resource Manager always get metadata
- if ((type.Name == "Strings" || type.Name == "SR") &&
- type.Namespace.Contains(type.Module.Assembly.GetName().Name))
- return false;
-
- // Event sources are not blocked
- if (type.HasCustomAttribute("System.Diagnostics.Tracing", "EventSourceAttribute"))
- return false;
-
- // We block everything else if the module is blocked
- if (blockingMode == ModuleBlockingMode.FullyBlocked)
- return true;
-
- DefType containingType = type.ContainingType;
- var typeDefinition = type.MetadataReader.GetTypeDefinition(type.Handle);
-
- if (containingType == null)
- {
- if ((typeDefinition.Attributes & TypeAttributes.Public) == 0)
- {
- return true;
- }
- }
- else
- {
- if ((typeDefinition.Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.NestedPublic)
- {
- return ComputeIsBlocked((EcmaType)containingType, blockingMode);
- }
- else
- {
- return true;
- }
- }
-
- return false;
- }
- }
- private BlockedTypeHashtable _blockedTypes;
-
- private MetadataType ArrayOfTType { get; }
-
- public BlockedInternalsBlockingPolicy(TypeSystemContext context)
- {
- _blockedTypes = new BlockedTypeHashtable(_blockedModules);
-
- ArrayOfTType = context.SystemModule.GetType("System", "Array`1", throwIfNotFound: false);
- }
-
- public override bool IsBlocked(MetadataType type)
- {
- Debug.Assert(type.IsTypeDefinition);
-
- var ecmaType = type as EcmaType;
- if (ecmaType == null)
- return true;
-
- return _blockedTypes.GetOrCreateValue(ecmaType).IsBlocked;
- }
-
- public override bool IsBlocked(MethodDesc method)
- {
- Debug.Assert(method.IsTypicalMethodDefinition);
-
- var ecmaMethod = method as EcmaMethod;
- if (ecmaMethod == null)
- return true;
-
- ModuleBlockingMode moduleBlockingMode = _blockedModules.GetOrCreateValue(ecmaMethod.Module).BlockingMode;
- if (moduleBlockingMode == ModuleBlockingMode.None)
- return false;
- else if (moduleBlockingMode == ModuleBlockingMode.FullyBlocked)
- return true;
-
- // We are blocking internal implementation details
- Debug.Assert(moduleBlockingMode == ModuleBlockingMode.BlockedInternals);
-
- var owningType = (EcmaType)ecmaMethod.OwningType;
- if (_blockedTypes.GetOrCreateValue(owningType).IsBlocked)
- return true;
-
- MethodAttributes accessibility = ecmaMethod.Attributes & MethodAttributes.Public;
- if (accessibility != MethodAttributes.Family
- && accessibility != MethodAttributes.FamORAssem
- && accessibility != MethodAttributes.Public)
- {
- return true;
- }
-
- // Methods on Array`1<T> are implementation details that implement the generic interfaces on
- // arrays. They should not generate metadata or be reflection invokable.
- // We could get rid of this special casing two ways:
- // * Make these method stop being regular EcmaMethods with Array<T> as their owning type, or
- // * Make these methods implement the interfaces explicitly (they would become private and naturally blocked)
- if (ecmaMethod.OwningType == ArrayOfTType)
- return true;
-
- return false;
- }
-
- public override bool IsBlocked(FieldDesc field)
- {
- Debug.Assert(field.IsTypicalFieldDefinition);
-
- var ecmaField = field as EcmaField;
- if (ecmaField == null)
- return true;
-
- ModuleBlockingMode moduleBlockingMode = _blockedModules.GetOrCreateValue(ecmaField.Module).BlockingMode;
- if (moduleBlockingMode == ModuleBlockingMode.None)
- return false;
- else if (moduleBlockingMode == ModuleBlockingMode.FullyBlocked)
- return true;
-
- // We are blocking internal implementation details
- Debug.Assert(moduleBlockingMode == ModuleBlockingMode.BlockedInternals);
-
- var owningType = (EcmaType)ecmaField.OwningType;
- if (_blockedTypes.GetOrCreateValue(owningType).IsBlocked)
- return true;
-
- FieldAttributes accessibility = ecmaField.Attributes & FieldAttributes.FieldAccessMask;
- return accessibility != FieldAttributes.Family
- && accessibility != FieldAttributes.FamORAssem
- && accessibility != FieldAttributes.Public;
- }
- }
-}
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-using System;
-
-using Internal.TypeSystem;
-using Internal.NativeFormat;
-using Internal.Text;
-
-namespace ILCompiler.DependencyAnalysis
-{
- /// <summary>
- /// Represents a hashtable of all type blocked from reflection.
- /// </summary>
- public sealed class BlockReflectionTypeMapNode : ObjectNode, ISymbolDefinitionNode
- {
- private ObjectAndOffsetSymbolNode _endSymbol;
- private ExternalReferencesTableNode _externalReferences;
-
- public BlockReflectionTypeMapNode(ExternalReferencesTableNode externalReferences)
- {
- _endSymbol = new ObjectAndOffsetSymbolNode(this, 0, "__block_reflection_type_map_End", true);
- _externalReferences = externalReferences;
- }
-
- public ISymbolDefinitionNode EndSymbol => _endSymbol;
-
- public void AppendMangledName(NameMangler nameMangler, Utf8StringBuilder sb)
- {
- sb.Append(nameMangler.CompilationUnitPrefix).Append("__block_reflection_type_map");
- }
- public int Offset => 0;
- public override bool IsShareable => false;
-
- public override ObjectNodeSection GetSection(NodeFactory factory) => _externalReferences.GetSection(factory);
-
- public override bool StaticDependenciesAreComputed => true;
-
- protected override string GetName(NodeFactory factory) => this.GetMangledName(factory.NameMangler);
-
- public override ObjectData GetData(NodeFactory factory, bool relocsOnly = false)
- {
- // This node does not trigger generation of other nodes.
- if (relocsOnly)
- return new ObjectData(Array.Empty<byte>(), Array.Empty<Relocation>(), 1, new ISymbolDefinitionNode[] { this });
-
- var writer = new NativeWriter();
- var reflectionBlockTypeMapHashTable = new VertexHashtable();
-
- Section hashTableSection = writer.NewSection();
- hashTableSection.Place(reflectionBlockTypeMapHashTable);
-
- foreach (var type in factory.MetadataManager.GetTypesWithEETypes())
- {
- if (!type.IsTypeDefinition)
- continue;
-
- var mdType = type as MetadataType;
- if (mdType == null)
- continue;
-
- if (!factory.MetadataManager.IsReflectionBlocked(mdType))
- continue;
-
- if (!factory.CompilationModuleGroup.ContainsType(mdType))
- continue;
-
- // Go with a necessary type symbol. It will be upgraded to a constructed one if a constructed was emitted.
- IEETypeNode typeSymbol = factory.NecessaryTypeSymbol(type);
-
- Vertex vertex = writer.GetUnsignedConstant(_externalReferences.GetIndex(typeSymbol));
-
- int hashCode = typeSymbol.Type.GetHashCode();
- reflectionBlockTypeMapHashTable.Append((uint)hashCode, hashTableSection.Place(vertex));
- }
-
- byte[] hashTableBytes = writer.Save();
-
- _endSymbol.SetSymbolOffset(hashTableBytes.Length);
-
- return new ObjectData(hashTableBytes, Array.Empty<Relocation>(), 1, new ISymbolDefinitionNode[] { this, _endSymbol });
- }
-
- protected internal override int Phase => (int)ObjectNodePhase.Ordered;
- public override int ClassCode => (int)ObjectNodeOrder.BlockReflectionTypeMapNode;
- }
-}
AddDependenciesForUniversalGVMSupport(factory, _type, ref dependencyList);
}
- // Keep track of the default constructor map dependency for this type if it has a default constructor
- // We only do this for reflection blocked types because dataflow analysis is responsible for
- // generating default constructors for Activator.CreateInstance in other cases.
- MethodDesc defaultCtor = closestDefType.GetDefaultConstructor();
- if (defaultCtor != null && factory.MetadataManager.IsReflectionBlocked(defaultCtor))
- {
- dependencyList.Add(new DependencyListEntry(
- factory.CanonicalEntrypoint(defaultCtor),
- "DefaultConstructorNode"));
- }
-
return dependencyList;
}
// relocs to nodes we emit.
dependencyList.Add(factory.NecessaryTypeSymbol(_type), "NecessaryType for constructed type");
- if(_type is MetadataType mdType)
- ModuleUseBasedDependencyAlgorithm.AddDependenciesDueToModuleUse(ref dependencyList, factory, mdType.Module);
-
DefType closestDefType = _type.GetClosestDefType();
if (_type.IsArray)
}
}
- // Ask the metadata manager if we have any dependencies due to the presence of the EEType.
- factory.MetadataManager.GetDependenciesDueToEETypePresence(ref dependencyList, factory, _type);
-
factory.InteropStubManager.AddInterestingInteropConstructedTypeDependencies(ref dependencyList, factory, _type);
- // Keep track of the default constructor map dependency for this type if it has a default constructor
- // We only do this for reflection blocked types because dataflow analysis is responsible for
- // generating default constructors for Activator.CreateInstance in other cases.
- MethodDesc defaultCtor = closestDefType.GetDefaultConstructor();
- if (defaultCtor != null && factory.MetadataManager.IsReflectionBlocked(defaultCtor))
- {
- dependencyList.Add(new DependencyListEntry(
- factory.CanonicalEntrypoint(defaultCtor),
- "DefaultConstructorNode"));
- }
-
return dependencyList;
}
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-using System;
-
-using Internal.Text;
-using Internal.TypeSystem;
-using Internal.NativeFormat;
-
-namespace ILCompiler.DependencyAnalysis
-{
- /// <summary>
- /// DefaultConstructorMap blob, containing information on default constructor entrypoints of all types used
- /// by lazy generic instantiations.
- /// </summary>
- internal sealed class DefaultConstructorMapNode : ObjectNode, ISymbolDefinitionNode
- {
- private ObjectAndOffsetSymbolNode _endSymbol;
- private ExternalReferencesTableNode _externalReferences;
-
- public DefaultConstructorMapNode(ExternalReferencesTableNode externalReferences)
- {
- _endSymbol = new ObjectAndOffsetSymbolNode(this, 0, "__DefaultConstructor_Map_End", true);
- _externalReferences = externalReferences;
- }
-
- public ISymbolNode EndSymbol => _endSymbol;
-
- public void AppendMangledName(NameMangler nameMangler, Utf8StringBuilder sb)
- {
- sb.Append(nameMangler.CompilationUnitPrefix).Append("__DefaultConstructor_Map");
- }
-
- public int Offset => 0;
- public override bool IsShareable => false;
- public override ObjectNodeSection GetSection(NodeFactory factory) => _externalReferences.GetSection(factory);
- public override bool ShouldSkipEmittingObjectNode(NodeFactory factory) => false;
- public override bool StaticDependenciesAreComputed => true;
-
- protected internal override int Phase => (int)ObjectNodePhase.Ordered;
- public override int ClassCode => (int)ObjectNodeOrder.DefaultConstructorMapNode;
-
- protected override string GetName(NodeFactory factory) => this.GetMangledName(factory.NameMangler);
-
- public override ObjectData GetData(NodeFactory factory, bool relocsOnly = false)
- {
- // This node does not trigger generation of other nodes.
- if (relocsOnly)
- return new ObjectData(Array.Empty<byte>(), Array.Empty<Relocation>(), 1, new ISymbolDefinitionNode[] { this });
-
- var writer = new NativeWriter();
- var defaultConstructorHashtable = new VertexHashtable();
-
- Section defaultConstructorHashtableSection = writer.NewSection();
- defaultConstructorHashtableSection.Place(defaultConstructorHashtable);
-
- foreach (var type in factory.MetadataManager.GetTypesWithConstructedEETypes())
- {
- MethodDesc defaultCtor = type.GetDefaultConstructor();
- if (defaultCtor == null)
- continue;
-
- // We only place default constructors of reflection-blocked types in this table.
- // At runtime, the type loader will search both this table and the invoke map
- // for default constructor info. If the ctor is reflectable, we would have
- // expected dataflow analysis to ensure there's a reflectable method for it.
- // If we don't find a reflectable method for the ctor of a non-blocked type
- // there would have to be a dataflow analysis warning.
- if (!factory.MetadataManager.IsReflectionBlocked(defaultCtor))
- continue;
-
- defaultCtor = defaultCtor.GetCanonMethodTarget(CanonicalFormKind.Specific);
-
- ISymbolNode typeNode = factory.NecessaryTypeSymbol(type);
- ISymbolNode defaultCtorNode = factory.MethodEntrypoint(defaultCtor, false);
-
- Vertex vertex = writer.GetTuple(
- writer.GetUnsignedConstant(_externalReferences.GetIndex(typeNode)),
- writer.GetUnsignedConstant(_externalReferences.GetIndex(defaultCtorNode)));
-
- int hashCode = type.GetHashCode();
- defaultConstructorHashtable.Append((uint)hashCode, defaultConstructorHashtableSection.Place(vertex));
- }
-
- byte[] hashTableBytes = writer.Save();
-
- _endSymbol.SetSymbolOffset(hashTableBytes.Length);
-
- return new ObjectData(hashTableBytes, Array.Empty<Relocation>(), 1, new ISymbolDefinitionNode[] { this, _endSymbol });
- }
- }
-}
}
}
- if (!ConstructedEETypeNode.CreationAllowed(_type))
- {
- // If necessary MethodTable is the highest load level for this type, ask the metadata manager
- // if we have any dependencies due to presence of the EEType.
- factory.MetadataManager.GetDependenciesDueToEETypePresence(ref dependencies, factory, _type);
+ // Ask the metadata manager
+ // if we have any dependencies due to presence of the EEType.
+ factory.MetadataManager.GetDependenciesDueToEETypePresence(ref dependencies, factory, _type);
- // If necessary MethodTable is the highest load level, consider this a module use
- if(_type is MetadataType mdType)
- ModuleUseBasedDependencyAlgorithm.AddDependenciesDueToModuleUse(ref dependencies, factory, mdType.Module);
- }
+ if (_type is MetadataType mdType)
+ ModuleUseBasedDependencyAlgorithm.AddDependenciesDueToModuleUse(ref dependencies, factory, mdType.Module);
if (_type.IsFunctionPointer)
FunctionPointerMapNode.GetHashtableDependencies(ref dependencies, factory, (FunctionPointerType)_type);
var transformed = MetadataTransform.Run(policy, GetCompilationModulesWithMetadata());
MetadataTransform transform = transformed.Transform;
- // TODO: DeveloperExperienceMode: Use transformed.Transform.HandleType() to generate
- // TypeReference records for _typeDefinitionsGenerated that don't have metadata.
- // (To be used in MissingMetadataException messages)
-
// Generate metadata blob
var writer = new MetadataWriter();
writer.ScopeDefinitions.AddRange(transformed.Scopes);
var genericTypesTemplatesMapNode = new GenericTypesTemplateMap(commonFixupsTableNode);
header.Add(BlobIdToReadyToRunSection(ReflectionMapBlob.TypeTemplateMap), genericTypesTemplatesMapNode, genericTypesTemplatesMapNode, genericTypesTemplatesMapNode.EndSymbol);
- var blockReflectionTypeMapNode = new BlockReflectionTypeMapNode(commonFixupsTableNode);
- header.Add(BlobIdToReadyToRunSection(ReflectionMapBlob.BlockReflectionTypeMap), blockReflectionTypeMapNode, blockReflectionTypeMapNode, blockReflectionTypeMapNode.EndSymbol);
-
var staticsInfoHashtableNode = new StaticsInfoHashtableNode(nativeReferencesTableNode, nativeStaticsTableNode);
header.Add(BlobIdToReadyToRunSection(ReflectionMapBlob.StaticsInfoHashtable), staticsInfoHashtableNode, staticsInfoHashtableNode, staticsInfoHashtableNode.EndSymbol);
var virtualInvokeMapNode = new ReflectionVirtualInvokeMapNode(commonFixupsTableNode);
header.Add(BlobIdToReadyToRunSection(ReflectionMapBlob.VirtualInvokeMap), virtualInvokeMapNode, virtualInvokeMapNode, virtualInvokeMapNode.EndSymbol);
- var defaultConstructorMapNode = new DefaultConstructorMapNode(commonFixupsTableNode);
- header.Add(BlobIdToReadyToRunSection(ReflectionMapBlob.DefaultConstructorMap), defaultConstructorMapNode, defaultConstructorMapNode, defaultConstructorMapNode.EndSymbol);
-
var stackTraceMethodMappingNode = new StackTraceMethodMappingNode();
header.Add(BlobIdToReadyToRunSection(ReflectionMapBlob.BlobIdStackTraceMethodRvaToTokenMapping), stackTraceMethodMappingNode, stackTraceMethodMappingNode, stackTraceMethodMappingNode.EndSymbol);
private IEnumerable<TypeDesc> GetTypesWithRuntimeMapping()
{
// All constructed types that are not blocked get runtime mapping
- foreach (var constructedType in GetTypesWithConstructedEETypes())
+ foreach (var constructedType in GetTypesWithEETypes())
{
if (!IsReflectionBlocked(constructedType))
yield return constructedType;
}
-
- // All necessary types for which this is the highest load level that are not blocked
- // get runtime mapping.
- foreach (var necessaryType in GetTypesWithEETypes())
- {
- if (!ConstructedEETypeNode.CreationAllowed(necessaryType) &&
- !IsReflectionBlocked(necessaryType))
- yield return necessaryType;
- }
}
public override void GetDependenciesDueToAccess(ref DependencyList dependencies, NodeFactory factory, MethodIL methodIL, FieldDesc writtenField)
<Compile Include="Compiler\AnalysisBasedInteropStubManager.cs" />
<Compile Include="Compiler\AnalysisBasedMetadataManager.cs" />
- <Compile Include="Compiler\BlockedInternalsBlockingPolicy.cs" />
<Compile Include="Compiler\BodySubstitution.cs" />
<Compile Include="Compiler\BodySubstitutionParser.cs" />
<Compile Include="Compiler\DependencyAnalysis\ByRefTypeMapNode.cs" />
<Compile Include="Compiler\DependencyAnalysis\EmbeddedTrimmingDescriptorNode.cs" />
<Compile Include="Compiler\DependencyAnalysis\DataflowAnalyzedMethodNode.cs" />
<Compile Include="Compiler\DependencyAnalysis\DataflowAnalyzedTypeDefinitionNode.cs" />
- <Compile Include="Compiler\DependencyAnalysis\DefaultConstructorMapNode.cs" />
<Compile Include="Compiler\DependencyAnalysis\DelegateMarshallingDataNode.cs" />
<Compile Include="Compiler\DependencyAnalysis\DynamicDependencyAttributesOnEntityNode.cs" />
<Compile Include="Compiler\DependencyAnalysis\ExternSymbolsImportedNodeProvider.cs" />
<Compile Include="Compiler\DescriptorMarker.cs" />
<Compile Include="Compiler\DependencyAnalysis\ArrayOfEmbeddedDataNode.cs" />
<Compile Include="Compiler\DependencyAnalysis\ArrayMapNode.cs" />
- <Compile Include="Compiler\DependencyAnalysis\BlockReflectionTypeMapNode.cs" />
<Compile Include="Compiler\DependencyAnalysis\CallingConventionConverterKey.cs" />
<Compile Include="Compiler\DependencyAnalysis\CodeBasedDependencyAlgorithm.cs" />
<Compile Include="Compiler\DependencyAnalysis\DelegateMarshallingStubMapNode.cs" />
new(new[] { "--mstat" }, "Generate an mstat file");
public Option<string> MetadataLogFileName { get; } =
new(new[] { "--metadatalog" }, "Generate a metadata log file");
- public Option<bool> NoMetadataBlocking { get; } =
- new(new[] { "--nometadatablocking" }, "Ignore metadata blocking for internal implementation details");
public Option<bool> CompleteTypesMetadata { get; } =
new(new[] { "--completetypemetadata" }, "Generate complete metadata for types");
public Option<string> ReflectionData { get; } =
AddOption(MapFileName);
AddOption(MstatFileName);
AddOption(MetadataLogFileName);
- AddOption(NoMetadataBlocking);
AddOption(CompleteTypesMetadata);
AddOption(ReflectionData);
AddOption(ScanReflection);
UsageBasedMetadataGenerationOptions metadataGenerationOptions = default;
if (supportsReflection)
{
- mdBlockingPolicy = Get(_command.NoMetadataBlocking) ?
- new NoMetadataBlockingPolicy() : new BlockedInternalsBlockingPolicy(typeSystemContext);
+ mdBlockingPolicy = new NoMetadataBlockingPolicy();
resBlockingPolicy = new ManifestResourceBlockingPolicy(logger, featureSwitches);
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.bytes);
}
- return string.Create(bytes.Length, (encoding: this, bytes), static (chars, args) =>
+ string result = string.FastAllocateString(bytes.Length);
+ fixed (byte* pBytes = bytes)
+ fixed (char* pChars = result)
{
- Debug.Assert(chars.Length == args.bytes.Length);
-
- fixed (byte* pBytes = args.bytes)
- fixed (char* pChars = chars)
- {
- args.encoding.GetCharsCommon(pBytes, args.bytes.Length, pChars, chars.Length);
- }
- });
+ GetCharsCommon(pBytes, bytes.Length, pChars, result.Length);
+ }
+ return result;
}
public override unsafe string GetString(byte[] bytes, int index, int count)
ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.bytes, ExceptionResource.ArgumentOutOfRange_IndexCountBuffer);
}
- return string.Create(count, (encoding: this, bytes, index), static (chars, args) =>
+ string result = string.FastAllocateString(count);
+ fixed (byte* pBytes = bytes)
+ fixed (char* pChars = result)
{
- fixed (byte* pBytes = args.bytes)
- fixed (char* pChars = chars)
- {
- args.encoding.GetCharsCommon(pBytes + args.index, chars.Length, pChars, chars.Length);
- }
- });
+ GetCharsCommon(pBytes + index, count, pChars, count);
+ }
+ return result;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
Console.WriteLine(s_type == typeof(Never));
#if !DEBUG
- ThrowIfPresent(typeof(TestTypeEquals), nameof(Never));
+ ThrowIfPresentWithUsableMethodTable(typeof(TestTypeEquals), nameof(Never));
#endif
}
}
// We only expect to be able to get rid of it when optimizing
#if !DEBUG
- ThrowIfPresent(typeof(TestBranchesInGenericCodeRemoval), nameof(Unused));
+ ThrowIfPresentWithUsableMethodTable(typeof(TestBranchesInGenericCodeRemoval), nameof(Unused));
#endif
ThrowIfNotPresent(typeof(TestBranchesInGenericCodeRemoval), nameof(Used));
}
}
+ private static void ThrowIfPresentWithUsableMethodTable(Type testType, string typeName)
+ {
+ Type t = GetTypeSecretly(testType, typeName);
+ if (t == null)
+ return;
+
+ try
+ {
+ RuntimeHelpers.GetUninitializedObject(t);
+
+ // Should have thrown NotSupported above.
+ throw new Exception();
+ }
+ catch (NotSupportedException) { }
+ }
+
private static void ThrowIfNotPresent(Type testType, string typeName)
{
if (GetTypeSecretly(testType, typeName) == null)