diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Abstractions/CdacAttributes.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Abstractions/CdacAttributes.cs index 96f9c4be01aaa7..56fc9bb58a1fe0 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Abstractions/CdacAttributes.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Abstractions/CdacAttributes.cs @@ -31,8 +31,8 @@ public CdacTypeAttribute(params string[] names) public string[] Names { get; } /// - /// When true, the generator emits a TypeHandle(Target) - /// accessor that resolves the runtime TypeHandle by trying each + /// When true, the generator emits a ITypeHandle(Target) + /// accessor that resolves the runtime ITypeHandle by trying each /// candidate name against IManagedTypeSource. /// public bool HasTypeHandle { get; set; } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Abstractions/Contracts/IManagedTypeSource.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Abstractions/Contracts/IManagedTypeSource.cs index 97154a6cbe0669..f81568d517512a 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Abstractions/Contracts/IManagedTypeSource.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Abstractions/Contracts/IManagedTypeSource.cs @@ -16,8 +16,8 @@ public interface IManagedTypeSource : IContract bool TryGetTypeInfo(string fullyQualifiedName, out Target.TypeInfo info) => throw new NotImplementedException(); Target.TypeInfo GetTypeInfo(string fullyQualifiedName) => throw new NotImplementedException(); - bool TryGetTypeHandle(string fullyQualifiedName, out TypeHandle typeHandle) => throw new NotImplementedException(); - TypeHandle GetTypeHandle(string fullyQualifiedName) => throw new NotImplementedException(); + bool TryGetTypeHandle(string fullyQualifiedName, out ITypeHandle typeHandle) => throw new NotImplementedException(); + ITypeHandle GetTypeHandle(string fullyQualifiedName) => throw new NotImplementedException(); bool TryGetStaticFieldAddress(string fullyQualifiedName, string fieldName, out TargetPointer address) => throw new NotImplementedException(); TargetPointer GetStaticFieldAddress(string fullyQualifiedName, string fieldName) => throw new NotImplementedException(); diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Abstractions/Contracts/IRuntimeMutableTypeSystem.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Abstractions/Contracts/IRuntimeMutableTypeSystem.cs index cecb94c10aeb81..2c77cbeeab8ffd 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Abstractions/Contracts/IRuntimeMutableTypeSystem.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Abstractions/Contracts/IRuntimeMutableTypeSystem.cs @@ -9,7 +9,7 @@ namespace Microsoft.Diagnostics.DataContractReader.Contracts; public interface IRuntimeMutableTypeSystem : IContract { static string IContract.Name { get; } = nameof(RuntimeMutableTypeSystem); - IEnumerable EnumerateAddedFieldDescs(TypeHandle typeHandle, bool staticFields) => throw new NotImplementedException(); + IEnumerable EnumerateAddedFieldDescs(ITypeHandle typeHandle, bool staticFields) => throw new NotImplementedException(); bool IsFieldDescEnCNew(TargetPointer fieldDescPointer) => throw new NotImplementedException(); bool DoesEnCFieldDescNeedFixup(TargetPointer encFieldDescPointer) => throw new NotImplementedException(); TargetPointer GetEnCStaticFieldDataAddress(TargetPointer encFieldDescPointer) => throw new NotImplementedException(); diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Abstractions/Contracts/IRuntimeTypeSystem.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Abstractions/Contracts/IRuntimeTypeSystem.cs index 14e6386a0ad644..dcc9bc30a89e6f 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Abstractions/Contracts/IRuntimeTypeSystem.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Abstractions/Contracts/IRuntimeTypeSystem.cs @@ -8,18 +8,32 @@ namespace Microsoft.Diagnostics.DataContractReader.Contracts; -// an opaque handle to a type handle. See IMetadata.GetMethodTableData -public readonly struct TypeHandle +/// +/// An opaque handle to a runtime type. May represent a loaded type (backed by a +/// target-process MethodTable or TypeDesc address) or a synthetic type fabricated +/// by the reader for unloaded constructed types. +/// +public interface ITypeHandle : IEquatable { - // TODO-Layering: These members should be accessible only to contract implementations. - public TypeHandle(TargetPointer address) - { - Address = address; - } - - public TargetPointer Address { get; } + TargetPointer Address { get; } + bool IsNull { get; } + bool IsSynthetic { get; } + static ITypeHandle Null { get; } = NullTypeHandle.Instance; +} - public bool IsNull => Address == 0; +/// +/// Singleton ITypeHandle representing the absence of a type. +/// +public sealed class NullTypeHandle : ITypeHandle +{ + public static readonly NullTypeHandle Instance = new(); + private NullTypeHandle() { } + public TargetPointer Address => TargetPointer.Null; + public bool IsNull => true; + public bool IsSynthetic => false; + public bool Equals(ITypeHandle? other) => other is not null && other.IsNull && !other.IsSynthetic; + public override bool Equals(object? obj) => obj is ITypeHandle th && Equals(th); + public override int GetHashCode() => 0; } public enum CorElementType @@ -115,108 +129,110 @@ public interface IRuntimeTypeSystem : IContract static string IContract.Name => nameof(RuntimeTypeSystem); #region TypeHandle inspection APIs - TypeHandle GetTypeHandle(TargetPointer address) => throw new NotImplementedException(); - TargetPointer GetModule(TypeHandle typeHandle) => throw new NotImplementedException(); - TargetPointer GetLoaderModule(TypeHandle typeHandle) => throw new NotImplementedException(); + ITypeHandle GetTypeHandle(TargetPointer address) => throw new NotImplementedException(); + TargetPointer GetModule(ITypeHandle typeHandle) => throw new NotImplementedException(); + TargetPointer GetLoaderModule(ITypeHandle typeHandle) => throw new NotImplementedException(); // A canonical method table is either the MethodTable itself, or in the case of a generic instantiation, it is the // MethodTable of the prototypical instance. - TargetPointer GetCanonicalMethodTable(TypeHandle typeHandle) => throw new NotImplementedException(); + TargetPointer GetCanonicalMethodTable(ITypeHandle typeHandle) => throw new NotImplementedException(); // Returns the EEClass pointer for this MethodTable. For non-canonical MTs, follows the tagged pointer // to the canonical MT and returns its EEClass. - TargetPointer GetClassPointer(TypeHandle typeHandle) => throw new NotImplementedException(); + TargetPointer GetClassPointer(ITypeHandle typeHandle) => throw new NotImplementedException(); // True if this MethodTable is the canonical MethodTable (i.e., EEClassOrCanonMT points directly to the EEClass) - bool IsCanonicalMethodTable(TypeHandle typeHandle) => throw new NotImplementedException(); - TargetPointer GetParentMethodTable(TypeHandle typeHandle) => throw new NotImplementedException(); + bool IsCanonicalMethodTable(ITypeHandle typeHandle) => throw new NotImplementedException(); + TargetPointer GetParentMethodTable(ITypeHandle typeHandle) => throw new NotImplementedException(); - TargetPointer GetMethodDescForSlot(TypeHandle methodTable, ushort slot) => throw new NotImplementedException(); - IEnumerable GetIntroducedMethodDescs(TypeHandle methodTable) => throw new NotImplementedException(); - TargetCodePointer GetSlot(TypeHandle typeHandle, uint slot) => throw new NotImplementedException(); + TargetPointer GetMethodDescForSlot(ITypeHandle methodTable, ushort slot) => throw new NotImplementedException(); + IEnumerable GetIntroducedMethodDescs(ITypeHandle methodTable) => throw new NotImplementedException(); + TargetCodePointer GetSlot(ITypeHandle typeHandle, uint slot) => throw new NotImplementedException(); - uint GetBaseSize(TypeHandle typeHandle) => throw new NotImplementedException(); - uint GetNumInstanceFieldBytes(TypeHandle typeHandle) => throw new NotImplementedException(); + uint GetBaseSize(ITypeHandle typeHandle) => throw new NotImplementedException(); + uint GetNumInstanceFieldBytes(ITypeHandle typeHandle) => throw new NotImplementedException(); // The component size is only available for strings and arrays. It is the size of the element type of the array, or the size of an ECMA 335 character (2 bytes) - uint GetComponentSize(TypeHandle typeHandle) => throw new NotImplementedException(); + uint GetComponentSize(ITypeHandle typeHandle) => throw new NotImplementedException(); // True if the MethodTable is the sentinel value associated with unallocated space in the managed heap - bool IsFreeObjectMethodTable(TypeHandle typeHandle) => throw new NotImplementedException(); + bool IsFreeObjectMethodTable(ITypeHandle typeHandle) => throw new NotImplementedException(); // True if the MethodTable is the System.Object MethodTable (g_pObjectClass) - bool IsObject(TypeHandle typeHandle) => throw new NotImplementedException(); - bool IsString(TypeHandle typeHandle) => throw new NotImplementedException(); + bool IsObject(ITypeHandle typeHandle) => throw new NotImplementedException(); + bool IsString(ITypeHandle typeHandle) => throw new NotImplementedException(); // True if the CorElementType represents a GC-collectable object reference. bool IsCorElementTypeObjRef(CorElementType elementType) => throw new NotImplementedException(); // Returns the address of one of the runtime's well-known singleton MethodTables, // or TargetPointer.Null if the runtime has not yet initialized that global. TargetPointer GetWellKnownMethodTable(WellKnownMethodTable kind) => throw new NotImplementedException(); + bool IsObjRef(ITypeHandle typeHandle) => throw new NotImplementedException(); // True if the MethodTable represents a type that contains managed references - bool ContainsGCPointers(TypeHandle typeHandle) => throw new NotImplementedException(); + bool ContainsGCPointers(ITypeHandle typeHandle) => throw new NotImplementedException(); // True if the type requires 8-byte alignment on platforms that don't 8-byte align by default (FEATURE_64BIT_ALIGNMENT) - bool RequiresAlign8(TypeHandle typeHandle) => throw new NotImplementedException(); + bool RequiresAlign8(ITypeHandle typeHandle) => throw new NotImplementedException(); // True if the MethodTable represents a continuation subtype that has no metadata of its own - bool IsContinuationWithoutMetadata(TypeHandle typeHandle) => throw new NotImplementedException(); + bool IsContinuationWithoutMetadata(ITypeHandle typeHandle) => throw new NotImplementedException(); /// /// Enumerates GC pointer runs from the CGCDesc stored before the method table. /// Returns (offset, size) pairs normalized to actual byte lengths. /// See RuntimeTypeSystem.md for the full GCDesc format documentation. /// - IEnumerable<(uint Offset, uint Size)> GetGCDescSeries(TypeHandle typeHandle, uint numComponents = 0) => throw new NotImplementedException(); - bool IsDynamicStatics(TypeHandle typeHandle) => throw new NotImplementedException(); - ushort GetNumInterfaces(TypeHandle typeHandle) => throw new NotImplementedException(); + IEnumerable<(uint Offset, uint Size)> GetGCDescSeries(ITypeHandle typeHandle, uint numComponents = 0) => throw new NotImplementedException(); + bool IsDynamicStatics(ITypeHandle typeHandle) => throw new NotImplementedException(); + ushort GetNumInterfaces(ITypeHandle typeHandle) => throw new NotImplementedException(); // Returns an ECMA-335 TypeDef table token for this type, or for its generic type definition if it is a generic instantiation - uint GetTypeDefToken(TypeHandle typeHandle) => throw new NotImplementedException(); - ushort GetNumVtableSlots(TypeHandle typeHandle) => throw new NotImplementedException(); - ushort GetNumMethods(TypeHandle typeHandle) => throw new NotImplementedException(); + uint GetTypeDefToken(ITypeHandle typeHandle) => throw new NotImplementedException(); + ushort GetNumVtableSlots(ITypeHandle typeHandle) => throw new NotImplementedException(); + ushort GetNumMethods(ITypeHandle typeHandle) => throw new NotImplementedException(); // Returns the ECMA 335 TypeDef table Flags value (a bitmask of TypeAttributes) for this type, // or for its generic type definition if it is a generic instantiation - uint GetTypeDefTypeAttributes(TypeHandle typeHandle) => throw new NotImplementedException(); - ushort GetNumInstanceFields(TypeHandle typeHandle) => throw new NotImplementedException(); - ushort GetNumStaticFields(TypeHandle typeHandle) => throw new NotImplementedException(); - ushort GetNumThreadStaticFields(TypeHandle typeHandle) => throw new NotImplementedException(); - IEnumerable GetFieldDescList(TypeHandle typeHandle) => throw new NotImplementedException(); + uint GetTypeDefTypeAttributes(ITypeHandle typeHandle) => throw new NotImplementedException(); + ushort GetNumInstanceFields(ITypeHandle typeHandle) => throw new NotImplementedException(); + ushort GetNumStaticFields(ITypeHandle typeHandle) => throw new NotImplementedException(); + ushort GetNumThreadStaticFields(ITypeHandle typeHandle) => throw new NotImplementedException(); + IEnumerable GetFieldDescList(ITypeHandle typeHandle) => throw new NotImplementedException(); // True if the MethodTable represents a type tracked as an Objective-C reference type with a finalizer - bool IsTrackedReferenceWithFinalizer(TypeHandle typeHandle) => throw new NotImplementedException(); - TargetPointer GetGCStaticsBasePointer(TypeHandle typeHandle) => throw new NotImplementedException(); - TargetPointer GetNonGCStaticsBasePointer(TypeHandle typeHandle) => throw new NotImplementedException(); - TargetPointer GetGCThreadStaticsBasePointer(TypeHandle typeHandle, TargetPointer threadPtr) => throw new NotImplementedException(); - TargetPointer GetNonGCThreadStaticsBasePointer(TypeHandle typeHandle, TargetPointer threadPtr) => throw new NotImplementedException(); + bool IsTrackedReferenceWithFinalizer(ITypeHandle typeHandle) => throw new NotImplementedException(); + TargetPointer GetGCStaticsBasePointer(ITypeHandle typeHandle) => throw new NotImplementedException(); + TargetPointer GetNonGCStaticsBasePointer(ITypeHandle typeHandle) => throw new NotImplementedException(); + TargetPointer GetGCThreadStaticsBasePointer(ITypeHandle typeHandle, TargetPointer threadPtr) => throw new NotImplementedException(); + TargetPointer GetNonGCThreadStaticsBasePointer(ITypeHandle typeHandle, TargetPointer threadPtr) => throw new NotImplementedException(); - ReadOnlySpan GetInstantiation(TypeHandle typeHandle) => throw new NotImplementedException(); - public bool IsClassInited(TypeHandle typeHandle) => throw new NotImplementedException(); - public bool IsInitError(TypeHandle typeHandle) => throw new NotImplementedException(); - bool IsGenericTypeDefinition(TypeHandle typeHandle) => throw new NotImplementedException(); - bool ContainsGenericVariables(TypeHandle typeHandle) => throw new NotImplementedException(); - bool IsCollectible(TypeHandle typeHandle) => throw new NotImplementedException(); + ITypeHandle[] GetInstantiation(ITypeHandle typeHandle) => throw new NotImplementedException(); + public bool IsClassInited(ITypeHandle typeHandle) => throw new NotImplementedException(); + public bool IsInitError(ITypeHandle typeHandle) => throw new NotImplementedException(); + bool IsGenericTypeDefinition(ITypeHandle typeHandle) => throw new NotImplementedException(); + bool ContainsGenericVariables(ITypeHandle typeHandle) => throw new NotImplementedException(); + bool IsCollectible(ITypeHandle typeHandle) => throw new NotImplementedException(); - bool HasTypeParam(TypeHandle typeHandle) => throw new NotImplementedException(); + bool HasTypeParam(ITypeHandle typeHandle) => throw new NotImplementedException(); // Element type of the type. NOTE: this drops the CorElementType.GenericInst, and CorElementType.String is returned as CorElementType.Class. // If this returns CorElementType.ValueType it may be a normal valuetype or a "NATIVE" valuetype used to represent an interop view on a structure // HasTypeParam will return true for cases where this is the interop view - CorElementType GetSignatureCorElementType(TypeHandle typeHandle) => throw new NotImplementedException(); - bool IsValueType(TypeHandle typeHandle) => throw new NotImplementedException(); + CorElementType GetSignatureCorElementType(ITypeHandle typeHandle) => throw new NotImplementedException(); + bool IsValueType(ITypeHandle typeHandle) => throw new NotImplementedException(); // Internal element type of the type. Unlike GetSignatureCorElementType, this returns the underlying primitive // type for enums (e.g. I4 for an enum with int underlying type) and for PrimitiveValueType categories. // For arrays, reference types, and TypeDescs, behaves identically to GetSignatureCorElementType. - CorElementType GetInternalCorElementType(TypeHandle typeHandle) => throw new NotImplementedException(); + CorElementType GetInternalCorElementType(ITypeHandle typeHandle) => throw new NotImplementedException(); // return true if the TypeHandle represents an enum type. - bool IsEnum(TypeHandle typeHandle) => throw new NotImplementedException(); + bool IsEnum(ITypeHandle typeHandle) => throw new NotImplementedException(); // return true if the TypeHandle represents a delegate type (i.e., its parent is System.MulticastDelegate) - bool IsDelegate(TypeHandle typeHandle) => throw new NotImplementedException(); + bool IsDelegate(ITypeHandle typeHandle) => throw new NotImplementedException(); // return true if the TypeHandle represents an array, and set the rank to either 0 (if the type is not an array), or the rank number if it is. - bool IsArray(TypeHandle typeHandle, out uint rank) => throw new NotImplementedException(); - TypeHandle GetTypeParam(TypeHandle typeHandle) => throw new NotImplementedException(); - TypeHandle GetConstructedType(TypeHandle typeHandle, CorElementType corElementType, int rank, ImmutableArray typeArguments, SignatureCallingConvention callConv = SignatureCallingConvention.Default) => throw new NotImplementedException(); - TypeHandle GetPrimitiveType(CorElementType typeCode) => throw new NotImplementedException(); - bool IsGenericVariable(TypeHandle typeHandle, out TargetPointer module, out uint token) => throw new NotImplementedException(); - bool IsFunctionPointer(TypeHandle typeHandle, out ReadOnlySpan retAndArgTypes, out SignatureCallingConvention callConv) => throw new NotImplementedException(); - bool IsPointer(TypeHandle typeHandle) => throw new NotImplementedException(); - bool IsTypeDesc(TypeHandle typeHandle) => throw new NotImplementedException(); + bool IsArray(ITypeHandle typeHandle, out uint rank) => throw new NotImplementedException(); + ITypeHandle GetTypeParam(ITypeHandle typeHandle) => throw new NotImplementedException(); + ITypeHandle GetConstructedType(ITypeHandle typeHandle, CorElementType corElementType, int rank, ImmutableArray typeArguments, SignatureCallingConvention callConv = SignatureCallingConvention.Default) => throw new NotImplementedException(); + ITypeHandle GetPrimitiveType(CorElementType typeCode) => throw new NotImplementedException(); + bool IsGenericVariable(ITypeHandle typeHandle, out TargetPointer module, out uint token) => throw new NotImplementedException(); + bool IsFunctionPointer(ITypeHandle typeHandle, out ITypeHandle[] retAndArgTypes, out SignatureCallingConvention callConv) => throw new NotImplementedException(); + bool IsPointer(ITypeHandle typeHandle) => throw new NotImplementedException(); + bool IsTypeDesc(ITypeHandle typeHandle) => throw new NotImplementedException(); + bool IsSynthetic(ITypeHandle typeHandle) => typeHandle.IsSynthetic; TypedByRefInfo GetTypedByRefInfo(TargetPointer typedByRef) => throw new NotImplementedException(); // Returns null if the TypeHandle is not a class/struct/generic variable #endregion TypeHandle inspection APIs @@ -227,7 +243,7 @@ public interface IRuntimeTypeSystem : IContract // Return true for an uninstantiated generic method bool IsGenericMethodDefinition(MethodDescHandle methodDesc) => throw new NotImplementedException(); - ReadOnlySpan GetGenericMethodInstantiation(MethodDescHandle methodDesc) => throw new NotImplementedException(); + ITypeHandle[] GetGenericMethodInstantiation(MethodDescHandle methodDesc) => throw new NotImplementedException(); GenericContextLoc GetGenericContextLoc(MethodDescHandle methodDescHandle) => throw new NotImplementedException(); @@ -295,7 +311,7 @@ public interface IRuntimeTypeSystem : IContract bool IsFieldDescRVA(TargetPointer fieldDescPointer) => throw new NotImplementedException(); CorElementType GetFieldDescType(TargetPointer fieldDescPointer) => throw new NotImplementedException(); uint GetFieldDescOffset(TargetPointer fieldDescPointer, FieldDefinition? fieldDef) => throw new NotImplementedException(); - TargetPointer GetFieldDescByName(TypeHandle typeHandle, string fieldName) => throw new NotImplementedException(); + TargetPointer GetFieldDescByName(ITypeHandle typeHandle, string fieldName) => throw new NotImplementedException(); TargetPointer GetFieldDescStaticAddress(TargetPointer fieldDescPointer, bool unboxValueTypes = true) => throw new NotImplementedException(); TargetPointer GetFieldDescThreadStaticAddress(TargetPointer fieldDescPointer, TargetPointer thread, bool unboxValueTypes = true) => throw new NotImplementedException(); #endregion FieldDesc inspection APIs diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Abstractions/Contracts/ISignature.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Abstractions/Contracts/ISignature.cs index e32b595f5f4b32..f07ed2b07ad8c9 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Abstractions/Contracts/ISignature.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Abstractions/Contracts/ISignature.cs @@ -9,7 +9,7 @@ namespace Microsoft.Diagnostics.DataContractReader.Contracts; public interface ISignature : IContract { static string IContract.Name { get; } = nameof(Signature); - TypeHandle DecodeFieldSignature(BlobHandle blobHandle, ModuleHandle moduleHandle, TypeHandle ctx) => throw new NotImplementedException(); + ITypeHandle DecodeFieldSignature(BlobHandle blobHandle, ModuleHandle moduleHandle, ITypeHandle ctx) => throw new NotImplementedException(); TargetPointer GetVarArgArgsBase(TargetPointer vaSigCookieAddr) => throw new NotImplementedException(); void GetVarArgSignature(TargetPointer vaSigCookieAddr, out TargetPointer signatureAddress, out uint signatureLength) => throw new NotImplementedException(); } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/CodeVersions_1.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/CodeVersions_1.cs index 633369d4f18bd8..ca99c4d33f3e1a 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/CodeVersions_1.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/CodeVersions_1.cs @@ -154,7 +154,7 @@ bool ICodeVersions.CodeVersionManagerSupportsMethod(TargetPointer methodDescAddr if (rts.IsCollectibleMethod(md)) return false; TargetPointer mtAddr = rts.GetMethodTable(md); - TypeHandle mt = rts.GetTypeHandle(mtAddr); + ITypeHandle mt = rts.GetTypeHandle(mtAddr); TargetPointer modAddr = rts.GetModule(mt); ILoader loader = _target.Contracts.Loader; ModuleHandle mod = loader.GetModuleHandleFromModulePtr(modAddr); @@ -342,7 +342,7 @@ private void GetModuleAndMethodDesc(TargetPointer methodDesc, out TargetPointer IRuntimeTypeSystem rts = _target.Contracts.RuntimeTypeSystem; MethodDescHandle md = rts.GetMethodDescHandle(methodDesc); TargetPointer mtAddr = rts.GetMethodTable(md); - TypeHandle typeHandle = rts.GetTypeHandle(mtAddr); + ITypeHandle typeHandle = rts.GetTypeHandle(mtAddr); module = rts.GetModule(typeHandle); methodDefToken = rts.GetMethodToken(md); } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/ComWrappers_1.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/ComWrappers_1.cs index 843d96a31f4792..937ee347a0d132 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/ComWrappers_1.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/ComWrappers_1.cs @@ -144,7 +144,7 @@ public List GetMOWs(TargetPointer obj, out bool hasMOWTable) public bool IsComWrappersRCW(TargetPointer rcw) { TargetPointer mt = _target.Contracts.Object.GetMethodTableAddress(rcw); - return mt == Data.NativeObjectWrapper.TypeHandle(_target).Address; + return mt == Data.NativeObjectWrapper.ITypeHandle(_target).Address; } public TargetPointer GetComWrappersRCWForObject(TargetPointer obj) diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/ConditionalWeakTable_1.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/ConditionalWeakTable_1.cs index 90ecfdd452a60c..8c1931d72becea 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/ConditionalWeakTable_1.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/ConditionalWeakTable_1.cs @@ -34,7 +34,7 @@ bool IConditionalWeakTable.TryGetValue(TargetPointer conditionalWeakTable, Targe Data.Array entriesArray = _target.ProcessedData.GetOrAdd(container.Entries); TargetPointer entriesMT = _target.Contracts.Object.GetMethodTableAddress(container.Entries); - TypeHandle entriesTypeHandle = _target.Contracts.RuntimeTypeSystem.GetTypeHandle(entriesMT); + ITypeHandle entriesTypeHandle = _target.Contracts.RuntimeTypeSystem.GetTypeHandle(entriesMT); uint entrySize = _target.Contracts.RuntimeTypeSystem.GetComponentSize(entriesTypeHandle); while (entriesIndex != -1) diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/Exception_1.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/Exception_1.cs index 217f185ecb0b80..771b06e02967d4 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/Exception_1.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/Exception_1.cs @@ -63,7 +63,7 @@ IEnumerable IException.GetExceptionStackFrames(TargetPo TargetPointer mt = objectContract.GetMethodTableAddress(stackTraceObj); if (mt == TargetPointer.Null) throw new InvalidOperationException($"Stack trace object 0x{stackTraceObj.Value:x} has no MethodTable."); - TypeHandle stackTraceHandle = rtsContract.GetTypeHandle(mt); + ITypeHandle stackTraceHandle = rtsContract.GetTypeHandle(mt); TargetPointer i1ArrayAddr; if (rtsContract.ContainsGCPointers(stackTraceHandle)) diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/ExecutionManager/ExecutionManagerCore.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/ExecutionManager/ExecutionManagerCore.cs index 0cba73ce8bbcf7..c3845042ae1c72 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/ExecutionManager/ExecutionManagerCore.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/ExecutionManager/ExecutionManagerCore.cs @@ -538,7 +538,7 @@ List IExecutionManager.GetExceptionClauses(CodeBlockHandle IRuntimeTypeSystem rts = _target.Contracts.RuntimeTypeSystem; MethodDescHandle mdHandle = rts.GetMethodDescHandle(methodDescPtr); TargetPointer mtPtr = rts.GetMethodTable(mdHandle); - TypeHandle th = rts.GetTypeHandle(mtPtr); + ITypeHandle th = rts.GetTypeHandle(mtPtr); TargetPointer handleModuleAddr = rts.GetModule(th); List exceptionClauses = new List(); diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/ManagedTypeSource_1.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/ManagedTypeSource_1.cs index a2987a89297a8f..6a4ccba7b41763 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/ManagedTypeSource_1.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/ManagedTypeSource_1.cs @@ -14,7 +14,7 @@ internal sealed class ManagedTypeSource_1 : IManagedTypeSource { private readonly Target _target; private readonly Dictionary _typeInfoCache = new(); - private readonly Dictionary _typeHandleCache = new(); + private readonly Dictionary _typeHandleCache = new(); private readonly Dictionary<(string Fqn, string FieldName), TargetPointer> _fieldDescCache = new(); private bool _inSearch; @@ -81,22 +81,26 @@ public bool TryGetTypeInfo(string fullyQualifiedName, out Target.TypeInfo info) } } - public TypeHandle GetTypeHandle(string fullyQualifiedName) + public ITypeHandle GetTypeHandle(string fullyQualifiedName) { - if (!TryGetTypeHandle(fullyQualifiedName, out TypeHandle typeHandle)) + if (!TryGetTypeHandle(fullyQualifiedName, out ITypeHandle typeHandle)) throw new InvalidOperationException($"Managed type '{fullyQualifiedName}' is not resolvable through {nameof(ManagedTypeSource_1)}."); return typeHandle; } - public bool TryGetTypeHandle(string fullyQualifiedName, out TypeHandle typeHandle) + public bool TryGetTypeHandle(string fullyQualifiedName, out ITypeHandle typeHandle) { - if (_typeHandleCache.TryGetValue(fullyQualifiedName, out typeHandle)) + if (_typeHandleCache.TryGetValue(fullyQualifiedName, out var cached)) + { + typeHandle = cached; return !typeHandle.IsNull; + } if (!TryResolveType(fullyQualifiedName, out typeHandle, out _, out _)) { - _typeHandleCache[fullyQualifiedName] = new TypeHandle(TargetPointer.Null); + typeHandle = ITypeHandle.Null; + _typeHandleCache[fullyQualifiedName] = ITypeHandle.Null; return false; } @@ -128,7 +132,7 @@ public bool TryGetStaticFieldAddress(string fullyQualifiedName, string fieldName // Gate on the statics base being allocated for the enclosing class so callers cannot // dereference a small offset-from-zero when the class has not been initialized. TargetPointer enclosingMT = rts.GetMTOfEnclosingClass(fieldDescAddr); - TypeHandle ctx = rts.GetTypeHandle(enclosingMT); + ITypeHandle ctx = rts.GetTypeHandle(enclosingMT); CorElementType type = rts.GetFieldDescType(fieldDescAddr); bool isGC = type is CorElementType.Class or CorElementType.ValueType; TargetPointer @base = isGC ? rts.GetGCStaticsBasePointer(ctx) : rts.GetNonGCStaticsBasePointer(ctx); @@ -163,7 +167,7 @@ public bool TryGetThreadStaticFieldAddress(string fullyQualifiedName, string fie // cannot dereference a small offset-from-zero when this thread has not initialized // thread-static storage for the type. TargetPointer enclosingMT = rts.GetMTOfEnclosingClass(fieldDescAddr); - TypeHandle ctx = rts.GetTypeHandle(enclosingMT); + ITypeHandle ctx = rts.GetTypeHandle(enclosingMT); CorElementType type = rts.GetFieldDescType(fieldDescAddr); bool isGC = type is CorElementType.Class or CorElementType.ValueType; TargetPointer @base = isGC @@ -182,7 +186,7 @@ private bool TryGetFieldDesc(string fullyQualifiedName, string fieldName, out Ta if (_fieldDescCache.TryGetValue(key, out fieldDescAddr)) return fieldDescAddr != TargetPointer.Null; - if (!TryResolveType(fullyQualifiedName, out TypeHandle th, out _, out _)) + if (!TryResolveType(fullyQualifiedName, out ITypeHandle th, out _, out _)) { fieldDescAddr = TargetPointer.Null; _fieldDescCache[key] = TargetPointer.Null; @@ -198,7 +202,7 @@ private bool TryBuildTypeInfo(string managedFqName, out Target.TypeInfo info) { info = default; - if (!TryResolveType(managedFqName, out TypeHandle th, out MetadataReader? mdReader, out TypeDefinition typeDef)) + if (!TryResolveType(managedFqName, out ITypeHandle th, out MetadataReader? mdReader, out TypeDefinition typeDef)) return false; IRuntimeTypeSystem rts = _target.Contracts.RuntimeTypeSystem; @@ -246,9 +250,9 @@ private bool TryBuildTypeInfo(string managedFqName, out Target.TypeInfo info) return true; } - private bool TryResolveType(string managedFqName, out TypeHandle th, [NotNullWhen(true)] out MetadataReader? mdReader, out TypeDefinition typeDef) + private bool TryResolveType(string managedFqName, out ITypeHandle th, [NotNullWhen(true)] out MetadataReader? mdReader, out TypeDefinition typeDef) { - th = new TypeHandle(TargetPointer.Null); + th = ITypeHandle.Null; typeDef = default; ILoader loader = _target.Contracts.Loader; @@ -264,7 +268,7 @@ private bool TryResolveType(string managedFqName, out TypeHandle th, [NotNullWhe if (!TryFindTypeDefinition(moduleHandle, managedFqName, out mdReader, out TypeDefinitionHandle typeDefHandle)) return false; - // Look up the runtime TypeHandle via the module's TypeDef → MethodTable map. + // Look up the runtime ITypeHandle via the module's TypeDef → MethodTable map. int token = MetadataTokens.GetToken((EntityHandle)typeDefHandle); TargetPointer typeDefToMethodTable = loader.GetLookupTables(moduleHandle).TypeDefToMethodTable; TargetPointer typeHandlePtr = loader.GetModuleLookupMapElement(typeDefToMethodTable, (uint)token, out _); diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/Object_1.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/Object_1.cs index 0d56541dbb049c..191ac3a92300d4 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/Object_1.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/Object_1.cs @@ -72,7 +72,7 @@ public TargetPointer GetArrayData(TargetPointer address, out uint count, out Tar if (mt == TargetPointer.Null) throw new ArgumentException("Address represents a set-free object"); Contracts.IRuntimeTypeSystem typeSystemContract = _target.Contracts.RuntimeTypeSystem; - TypeHandle typeHandle = typeSystemContract.GetTypeHandle(mt); + ITypeHandle typeHandle = typeSystemContract.GetTypeHandle(mt); uint rank; if (!typeSystemContract.IsArray(typeHandle, out rank)) throw new ArgumentException("Address does not represent an array object", nameof(address)); @@ -207,7 +207,7 @@ public ulong GetSize(TargetPointer address) if (mt == TargetPointer.Null) throw new ArgumentException("Address represents a free object"); Contracts.IRuntimeTypeSystem typeSystemContract = _target.Contracts.RuntimeTypeSystem; - TypeHandle typeHandle = typeSystemContract.GetTypeHandle(mt); + ITypeHandle typeHandle = typeSystemContract.GetTypeHandle(mt); ulong size = typeSystemContract.GetBaseSize(typeHandle); uint componentSize = typeSystemContract.GetComponentSize(typeHandle); diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/RuntimeMutableTypeSystem_1.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/RuntimeMutableTypeSystem_1.cs index c58e5ef4a58b59..b997b35d46c390 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/RuntimeMutableTypeSystem_1.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/RuntimeMutableTypeSystem_1.cs @@ -26,7 +26,7 @@ bool IRuntimeMutableTypeSystem.IsFieldDescEnCNew(TargetPointer fieldDescPointer) return offset == _target.ReadGlobal(Constants.Globals.FieldOffsetNewEnc); } - IEnumerable IRuntimeMutableTypeSystem.EnumerateAddedFieldDescs(TypeHandle typeHandle, bool staticFields) + IEnumerable IRuntimeMutableTypeSystem.EnumerateAddedFieldDescs(ITypeHandle typeHandle, bool staticFields) { // Only MethodTable type handles can have EnC-added fields. TypeDescs (TypeVar, FnPtr, etc.) cannot. if (!typeHandle.IsMethodTable()) diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/RuntimeTypeSystem/TypeHandleImplementations.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/RuntimeTypeSystem/TypeHandleImplementations.cs new file mode 100644 index 00000000000000..3acd01fb8229cf --- /dev/null +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/RuntimeTypeSystem/TypeHandleImplementations.cs @@ -0,0 +1,71 @@ +// 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.Collections.Generic; + +namespace Microsoft.Diagnostics.DataContractReader.Contracts; + +/// +/// An ITypeHandle backed by a real target-process address (MethodTable* or TypeDesc*). +/// +public readonly struct TargetTypeHandle : ITypeHandle, IEquatable +{ + public TargetTypeHandle(TargetPointer address) + { + Address = address; + } + + public TargetPointer Address { get; } + public bool IsNull => Address == 0; + public bool IsSynthetic => false; + + public bool Equals(ITypeHandle? other) + { + if (other is null) return false; + if (other is TargetTypeHandle t) return Address == t.Address; + // A zero-address TargetTypeHandle is equivalent to a NullTypeHandle + if (IsNull && other.IsNull && !other.IsSynthetic) return true; + return false; + } + public bool Equals(TargetTypeHandle other) => Address == other.Address; + public override bool Equals(object? obj) + => obj is ITypeHandle th && Equals(th); + public override int GetHashCode() => Address.GetHashCode(); +} + +/// +/// A reader-fabricated ITypeHandle for an unloaded constructed type +/// (Ptr, Byref, SzArray, or Array). Has no backing target memory. +/// +internal sealed class SyntheticTypeHandle : ITypeHandle, IEquatable +{ + public SyntheticTypeHandle(CorElementType kind, ITypeHandle element, int rank = 0) + { + Kind = kind; + Element = element; + Rank = rank; + } + + /// The outermost CorElementType (Ptr, Byref, SzArray, or Array). + public CorElementType Kind { get; } + + /// The element (referent) ITypeHandle. May itself be synthetic. + public ITypeHandle Element { get; } + + /// Array rank (meaningful only for Array; SzArray is always 1). + public int Rank { get; } + + public TargetPointer Address => TargetPointer.Null; + public bool IsNull => false; + public bool IsSynthetic => true; + + public bool Equals(ITypeHandle? other) => other is SyntheticTypeHandle s && Equals(s); + public bool Equals(SyntheticTypeHandle? other) + => other is not null + && Kind == other.Kind + && Rank == other.Rank + && EqualityComparer.Default.Equals(Element, other.Element); + public override bool Equals(object? obj) => obj is ITypeHandle th && Equals(th); + public override int GetHashCode() => HashCode.Combine((int)Kind, Rank, Element?.GetHashCode() ?? 0); +} diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/RuntimeTypeSystem_1.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/RuntimeTypeSystem_1.cs index 41e2413a41df8b..07a4ade9ebd025 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/RuntimeTypeSystem_1.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/RuntimeTypeSystem_1.cs @@ -30,7 +30,7 @@ internal partial struct RuntimeTypeSystem_1 : IRuntimeTypeSystem // If we need to invalidate our view of memory, we should clear this dictionary. private readonly Dictionary _methodTables = new(); private readonly Dictionary _methodDescs = new(); - private readonly Dictionary _typeHandles = new(); + private readonly Dictionary _typeHandles = new(); public void Flush(FlushScope scope) { @@ -72,7 +72,7 @@ internal MethodTable(Data.MethodTable data) private readonly struct TypeKey : IEquatable { - public TypeKey(TypeHandle typeHandle, CorElementType elementType, int rank, ImmutableArray typeArgs, SignatureCallingConvention callConv = SignatureCallingConvention.Default) + public TypeKey(ITypeHandle typeHandle, CorElementType elementType, int rank, ImmutableArray typeArgs, SignatureCallingConvention callConv = SignatureCallingConvention.Default) { TypeHandle = typeHandle; ElementType = elementType; @@ -80,10 +80,10 @@ public TypeKey(TypeHandle typeHandle, CorElementType elementType, int rank, Immu TypeArgs = typeArgs; CallConv = callConv; } - public TypeHandle TypeHandle { get; } + public ITypeHandle TypeHandle { get; } public CorElementType ElementType { get; } public int Rank { get; } - public ImmutableArray TypeArgs { get; } + public ImmutableArray TypeArgs { get; } public SignatureCallingConvention CallConv { get; } public bool Equals(TypeKey other) @@ -103,7 +103,7 @@ public bool Equals(TypeKey other) public override int GetHashCode() { int hash = HashCode.Combine(TypeHandle.GetHashCode(), (int)ElementType, Rank, (int)CallConv); - foreach (TypeHandle th in TypeArgs) + foreach (ITypeHandle th in TypeArgs) { hash = HashCode.Combine(hash, th.GetHashCode()); } @@ -111,7 +111,7 @@ public override int GetHashCode() } } - // Low order bits of TypeHandle address. + // Low order bits of ITypeHandle address. // If the low bits contain a 2, then it is a TypeDesc [Flags] internal enum TypeHandleBits @@ -351,11 +351,11 @@ private InstantiatedMethodDesc(Target target, TargetPointer methodDescPointer) TargetPointer perInstInfo = _desc.PerInstInfo; if ((perInstInfo == TargetPointer.Null) || (numGenericArgs == 0)) { - Instantiation = System.Array.Empty(); + Instantiation = System.Array.Empty(); } else { - Instantiation = new TypeHandle[numGenericArgs]; + Instantiation = new ITypeHandle[numGenericArgs]; for (int i = 0; i < numGenericArgs; i++) { Instantiation[i] = rts.GetTypeHandle(target.ReadPointer(perInstInfo + (ulong)target.PointerSize * (ulong)i)); @@ -368,7 +368,7 @@ private InstantiatedMethodDesc(Target target, TargetPointer methodDescPointer) internal bool IsGenericMethodDefinition => HasFlags(InstantiatedMethodDescFlags2.KindMask, InstantiatedMethodDescFlags2.GenericMethodDefinition); internal bool HasPerInstInfo => _desc.PerInstInfo != TargetPointer.Null; internal bool HasMethodInstantiation => IsGenericMethodDefinition || HasPerInstInfo; - public TypeHandle[] Instantiation { get; } + public ITypeHandle[] Instantiation { get; } } private sealed class DynamicMethodDesc : IData @@ -462,7 +462,7 @@ internal TargetPointer ContinuationSingletonEEClassPointer internal ulong MethodDescAlignment => _methodDescAlignment; - public TypeHandle GetTypeHandle(TargetPointer typeHandlePointer) + public ITypeHandle GetTypeHandle(TargetPointer typeHandlePointer) { TypeHandleBits addressLowBits = (TypeHandleBits)((ulong)typeHandlePointer & ((ulong)_target.PointerSize - 1)); @@ -474,14 +474,14 @@ public TypeHandle GetTypeHandle(TargetPointer typeHandlePointer) // if we already validated this address, return a handle if (_methodTables.ContainsKey(typeHandlePointer)) { - return new TypeHandle(typeHandlePointer); + return new TargetTypeHandle(typeHandlePointer); } // Check for a TypeDesc if (addressLowBits == TypeHandleBits.TypeDesc) { // This is a TypeDesc - return new TypeHandle(typeHandlePointer); + return new TargetTypeHandle(typeHandlePointer); } TargetPointer methodTablePointer = typeHandlePointer; @@ -492,7 +492,7 @@ public TypeHandle GetTypeHandle(TargetPointer typeHandlePointer) // we already cached the data, we must have validated the address, create the representation struct for our use MethodTable trustedMethodTable = new MethodTable(methodTableData); _ = _methodTables.TryAdd(methodTablePointer, trustedMethodTable); - return new TypeHandle(methodTablePointer); + return new TargetTypeHandle(methodTablePointer); } // If it's the free object method table, we trust it to be valid @@ -501,7 +501,7 @@ public TypeHandle GetTypeHandle(TargetPointer typeHandlePointer) Data.MethodTable freeObjectMethodTableData = _target.ProcessedData.GetOrAdd(methodTablePointer); MethodTable trustedMethodTable = new MethodTable(freeObjectMethodTableData); _ = _methodTables.TryAdd(methodTablePointer, trustedMethodTable); - return new TypeHandle(methodTablePointer); + return new TargetTypeHandle(methodTablePointer); } // Otherwse, get ready to validate @@ -513,10 +513,13 @@ public TypeHandle GetTypeHandle(TargetPointer typeHandlePointer) Data.MethodTable trustedMethodTableData = _target.ProcessedData.GetOrAdd(methodTablePointer); MethodTable trustedMethodTableF = new MethodTable(trustedMethodTableData); _ = _methodTables.TryAdd(methodTablePointer, trustedMethodTableF); - return new TypeHandle(methodTablePointer); + return new TargetTypeHandle(methodTablePointer); } - public TargetPointer GetModule(TypeHandle typeHandle) + public TargetPointer GetModule(ITypeHandle typeHandle) { + if (typeHandle is SyntheticTypeHandle synthetic) + return GetModule(synthetic.Element); + if (typeHandle.IsMethodTable()) { return _methodTables[typeHandle.Address].Module; @@ -542,17 +545,17 @@ public TargetPointer GetModule(TypeHandle typeHandle) return TargetPointer.Null; } } - public TargetPointer GetCanonicalMethodTable(TypeHandle typeHandle) => !typeHandle.IsMethodTable() ? TargetPointer.Null : GetClassData(typeHandle).MethodTable; - public bool IsCanonicalMethodTable(TypeHandle typeHandle) => typeHandle.IsMethodTable() && _methodTables[typeHandle.Address].IsCanonMT; - public TargetPointer GetParentMethodTable(TypeHandle typeHandle) => !typeHandle.IsMethodTable() ? TargetPointer.Null : _methodTables[typeHandle.Address].ParentMethodTable; + public TargetPointer GetCanonicalMethodTable(ITypeHandle typeHandle) => !typeHandle.IsMethodTable() ? TargetPointer.Null : GetClassData(typeHandle).MethodTable; + public bool IsCanonicalMethodTable(ITypeHandle typeHandle) => typeHandle.IsMethodTable() && _methodTables[typeHandle.Address].IsCanonMT; + public TargetPointer GetParentMethodTable(ITypeHandle typeHandle) => !typeHandle.IsMethodTable() ? TargetPointer.Null : _methodTables[typeHandle.Address].ParentMethodTable; - public uint GetBaseSize(TypeHandle typeHandle) => !typeHandle.IsMethodTable() ? (uint)0 : _methodTables[typeHandle.Address].Flags.BaseSize; + public uint GetBaseSize(ITypeHandle typeHandle) => !typeHandle.IsMethodTable() ? (uint)0 : _methodTables[typeHandle.Address].Flags.BaseSize; - public uint GetNumInstanceFieldBytes(TypeHandle typeHandle) => !typeHandle.IsMethodTable() ? (uint)0 : _methodTables[typeHandle.Address].Flags.BaseSize - GetClassData(typeHandle).BaseSizePadding; + public uint GetNumInstanceFieldBytes(ITypeHandle typeHandle) => !typeHandle.IsMethodTable() ? (uint)0 : _methodTables[typeHandle.Address].Flags.BaseSize - GetClassData(typeHandle).BaseSizePadding; - public uint GetComponentSize(TypeHandle typeHandle) => !typeHandle.IsMethodTable() ? (uint)0 : _methodTables[typeHandle.Address].Flags.ComponentSize; + public uint GetComponentSize(ITypeHandle typeHandle) => !typeHandle.IsMethodTable() ? (uint)0 : _methodTables[typeHandle.Address].Flags.ComponentSize; - public TargetPointer GetClassPointer(TypeHandle typeHandle) + public TargetPointer GetClassPointer(ITypeHandle typeHandle) { if (!typeHandle.IsMethodTable()) return TargetPointer.Null; @@ -563,7 +566,7 @@ public TargetPointer GetClassPointer(TypeHandle typeHandle) return methodTable.EEClassOrCanonMT; case MethodTableFlags_1.EEClassOrCanonMTBits.CanonMT: TargetPointer canonMTPtr = MethodTableFlags_1.UntagEEClassOrCanonMT(methodTable.EEClassOrCanonMT); - TypeHandle canonMTHandle = GetTypeHandle(canonMTPtr); + ITypeHandle canonMTHandle = GetTypeHandle(canonMTPtr); MethodTable canonMT = _methodTables[canonMTHandle.Address]; return canonMT.EEClassOrCanonMT; // canonical method table EEClassOrCanonMT is always EEClass default: @@ -572,18 +575,18 @@ public TargetPointer GetClassPointer(TypeHandle typeHandle) } // only called on validated method tables, so we don't need to re-validate the EEClass - private Data.EEClass GetClassData(TypeHandle typeHandle) + private Data.EEClass GetClassData(ITypeHandle typeHandle) { TargetPointer clsPtr = GetClassPointer(typeHandle); return _target.ProcessedData.GetOrAdd(clsPtr); } - public bool IsFreeObjectMethodTable(TypeHandle typeHandle) => FreeObjectMethodTablePointer == typeHandle.Address; + public bool IsFreeObjectMethodTable(ITypeHandle typeHandle) => FreeObjectMethodTablePointer == typeHandle.Address; - public bool IsObject(TypeHandle typeHandle) => ObjectMethodTablePointer != TargetPointer.Null && ObjectMethodTablePointer == typeHandle.Address; + public bool IsObject(ITypeHandle typeHandle) => ObjectMethodTablePointer != TargetPointer.Null && ObjectMethodTablePointer == typeHandle.Address; - public bool IsString(TypeHandle typeHandle) => !typeHandle.IsMethodTable() ? false : _methodTables[typeHandle.Address].Flags.IsString; + public bool IsString(ITypeHandle typeHandle) => !typeHandle.IsMethodTable() ? false : _methodTables[typeHandle.Address].Flags.IsString; public bool IsCorElementTypeObjRef(CorElementType elementType) => elementType is CorElementType.Class @@ -612,15 +615,21 @@ public TargetPointer GetWellKnownMethodTable(WellKnownMethodTable kind) return value; } - public bool ContainsGCPointers(TypeHandle typeHandle) => !typeHandle.IsMethodTable() ? false : _methodTables[typeHandle.Address].Flags.ContainsGCPointers; - public bool RequiresAlign8(TypeHandle typeHandle) => !typeHandle.IsMethodTable() ? false : _methodTables[typeHandle.Address].Flags.RequiresAlign8; - public bool IsContinuationWithoutMetadata(TypeHandle typeHandle) => typeHandle.IsMethodTable() + public bool IsObjRef(ITypeHandle typeHandle) + { + CorElementType elementType = GetSignatureCorElementType(typeHandle); + // Keep this aligned with CorTypeInfo::IsObjRef semantics for signature element types. + return elementType is CorElementType.Class or CorElementType.Array or CorElementType.SzArray; + } + public bool ContainsGCPointers(ITypeHandle typeHandle) => !typeHandle.IsMethodTable() ? false : _methodTables[typeHandle.Address].Flags.ContainsGCPointers; + public bool RequiresAlign8(ITypeHandle typeHandle) => !typeHandle.IsMethodTable() ? false : _methodTables[typeHandle.Address].Flags.RequiresAlign8; + public bool IsContinuationWithoutMetadata(ITypeHandle typeHandle) => typeHandle.IsMethodTable() && ContinuationMethodTablePointer != TargetPointer.Null && _methodTables[typeHandle.Address].ParentMethodTable == ContinuationMethodTablePointer && ContinuationSingletonEEClassPointer != TargetPointer.Null && GetClassPointer(typeHandle) == ContinuationSingletonEEClassPointer; - IEnumerable<(uint Offset, uint Size)> IRuntimeTypeSystem.GetGCDescSeries(TypeHandle typeHandle, uint numComponents) + IEnumerable<(uint Offset, uint Size)> IRuntimeTypeSystem.GetGCDescSeries(ITypeHandle typeHandle, uint numComponents) { if (!typeHandle.IsMethodTable()) yield break; @@ -694,17 +703,17 @@ public bool IsContinuationWithoutMetadata(TypeHandle typeHandle) => typeHandle.I } } - public bool IsDynamicStatics(TypeHandle typeHandle) => !typeHandle.IsMethodTable() ? false : _methodTables[typeHandle.Address].Flags.IsDynamicStatics; - public ushort GetNumInterfaces(TypeHandle typeHandle) => !typeHandle.IsMethodTable() ? (ushort)0 : _methodTables[typeHandle.Address].NumInterfaces; + public bool IsDynamicStatics(ITypeHandle typeHandle) => !typeHandle.IsMethodTable() ? false : _methodTables[typeHandle.Address].Flags.IsDynamicStatics; + public ushort GetNumInterfaces(ITypeHandle typeHandle) => !typeHandle.IsMethodTable() ? (ushort)0 : _methodTables[typeHandle.Address].NumInterfaces; - public uint GetTypeDefToken(TypeHandle typeHandle) + public uint GetTypeDefToken(ITypeHandle typeHandle) { if (!typeHandle.IsMethodTable()) return 0; MethodTable methodTable = _methodTables[typeHandle.Address]; return (uint)(methodTable.Flags.GetTypeDefRid() | ((int)TableIndex.TypeDef << 24)); } - public ushort GetNumVtableSlots(TypeHandle typeHandle) + public ushort GetNumVtableSlots(ITypeHandle typeHandle) { if (!typeHandle.IsMethodTable()) return 0; @@ -712,12 +721,12 @@ public ushort GetNumVtableSlots(TypeHandle typeHandle) ushort numNonVirtualSlots = methodTable.IsCanonMT ? GetClassData(typeHandle).NumNonVirtualSlots : (ushort)0; return checked((ushort)(methodTable.NumVirtuals + numNonVirtualSlots)); } - public ushort GetNumMethods(TypeHandle typeHandle) => !typeHandle.IsMethodTable() ? (ushort)0 : GetClassData(typeHandle).NumMethods; - public uint GetTypeDefTypeAttributes(TypeHandle typeHandle) => !typeHandle.IsMethodTable() ? (uint)0 : GetClassData(typeHandle).CorTypeAttr; - public ushort GetNumInstanceFields(TypeHandle typeHandle) => !typeHandle.IsMethodTable() ? (ushort)0 : GetClassData(typeHandle).NumInstanceFields; - public ushort GetNumStaticFields(TypeHandle typeHandle) => !typeHandle.IsMethodTable() ? (ushort)0 : GetClassData(typeHandle).NumStaticFields; - public ushort GetNumThreadStaticFields(TypeHandle typeHandle) => !typeHandle.IsMethodTable() ? (ushort)0 : GetClassData(typeHandle).NumThreadStaticFields; - public IEnumerable GetFieldDescList(TypeHandle typeHandle) + public ushort GetNumMethods(ITypeHandle typeHandle) => !typeHandle.IsMethodTable() ? (ushort)0 : GetClassData(typeHandle).NumMethods; + public uint GetTypeDefTypeAttributes(ITypeHandle typeHandle) => !typeHandle.IsMethodTable() ? (uint)0 : GetClassData(typeHandle).CorTypeAttr; + public ushort GetNumInstanceFields(ITypeHandle typeHandle) => !typeHandle.IsMethodTable() ? (ushort)0 : GetClassData(typeHandle).NumInstanceFields; + public ushort GetNumStaticFields(ITypeHandle typeHandle) => !typeHandle.IsMethodTable() ? (ushort)0 : GetClassData(typeHandle).NumStaticFields; + public ushort GetNumThreadStaticFields(ITypeHandle typeHandle) => !typeHandle.IsMethodTable() ? (ushort)0 : GetClassData(typeHandle).NumThreadStaticFields; + public IEnumerable GetFieldDescList(ITypeHandle typeHandle) { if (!typeHandle.IsMethodTable()) yield break; @@ -729,7 +738,7 @@ public IEnumerable GetFieldDescList(TypeHandle typeHandle) TargetPointer parentMT = GetParentMethodTable(typeHandle); if (parentMT != TargetPointer.Null) { - TypeHandle parentHandle = GetTypeHandle(parentMT); + ITypeHandle parentHandle = GetTypeHandle(parentMT); numInstanceFields -= GetNumInstanceFields(parentHandle); } int totalFields = numInstanceFields + GetNumStaticFields(typeHandle); @@ -738,8 +747,8 @@ public IEnumerable GetFieldDescList(TypeHandle typeHandle) yield return fieldDescListPtr + (ulong)i * fieldDescSize; } } - public bool IsTrackedReferenceWithFinalizer(TypeHandle typeHandle) => typeHandle.IsMethodTable() && _methodTables[typeHandle.Address].Flags.IsTrackedReferenceWithFinalizer; - private TargetPointer GetDynamicStaticsInfo(TypeHandle typeHandle) + public bool IsTrackedReferenceWithFinalizer(ITypeHandle typeHandle) => typeHandle.IsMethodTable() && _methodTables[typeHandle.Address].Flags.IsTrackedReferenceWithFinalizer; + private TargetPointer GetDynamicStaticsInfo(ITypeHandle typeHandle) { if (!typeHandle.IsMethodTable()) return default; @@ -752,7 +761,7 @@ private TargetPointer GetDynamicStaticsInfo(TypeHandle typeHandle) return dynamicStaticsInfoAddr; } - private Data.ThreadStaticsInfo GetThreadStaticsInfo(TypeHandle typeHandle) + private Data.ThreadStaticsInfo GetThreadStaticsInfo(ITypeHandle typeHandle) { MethodTable methodTable = _methodTables[typeHandle.Address]; TargetPointer threadStaticsInfoSize = _target.GetTypeInfo(DataType.ThreadStaticsInfo).Size!.Value; @@ -761,7 +770,7 @@ private Data.ThreadStaticsInfo GetThreadStaticsInfo(TypeHandle typeHandle) return threadStaticsInfo; } - public TargetPointer GetGCThreadStaticsBasePointer(TypeHandle typeHandle, TargetPointer threadPtr) + public TargetPointer GetGCThreadStaticsBasePointer(ITypeHandle typeHandle, TargetPointer threadPtr) { if (!typeHandle.IsMethodTable()) return TargetPointer.Null; @@ -770,7 +779,7 @@ public TargetPointer GetGCThreadStaticsBasePointer(TypeHandle typeHandle, Target return threadContract.GetThreadLocalStaticBase(threadPtr, tlsIndexPtr); } - public TargetPointer GetNonGCThreadStaticsBasePointer(TypeHandle typeHandle, TargetPointer threadPtr) + public TargetPointer GetNonGCThreadStaticsBasePointer(ITypeHandle typeHandle, TargetPointer threadPtr) { if (!typeHandle.IsMethodTable()) return TargetPointer.Null; @@ -779,7 +788,7 @@ public TargetPointer GetNonGCThreadStaticsBasePointer(TypeHandle typeHandle, Tar return threadContract.GetThreadLocalStaticBase(threadPtr, tlsIndexPtr); } - public TargetPointer GetGCStaticsBasePointer(TypeHandle typeHandle) + public TargetPointer GetGCStaticsBasePointer(ITypeHandle typeHandle) { TargetPointer dynamicStaticsInfoAddr = GetDynamicStaticsInfo(typeHandle); if (dynamicStaticsInfoAddr == TargetPointer.Null) @@ -788,7 +797,7 @@ public TargetPointer GetGCStaticsBasePointer(TypeHandle typeHandle) return dynamicStaticsInfo.GCStatics; } - public TargetPointer GetNonGCStaticsBasePointer(TypeHandle typeHandle) + public TargetPointer GetNonGCStaticsBasePointer(ITypeHandle typeHandle) { TargetPointer dynamicStaticsInfoAddr = GetDynamicStaticsInfo(typeHandle); if (dynamicStaticsInfoAddr == TargetPointer.Null) @@ -797,19 +806,19 @@ public TargetPointer GetNonGCStaticsBasePointer(TypeHandle typeHandle) return dynamicStaticsInfo.NonGCStatics; } - public ReadOnlySpan GetInstantiation(TypeHandle typeHandle) + public ITypeHandle[] GetInstantiation(ITypeHandle typeHandle) { if (!typeHandle.IsMethodTable()) - return default; + return global::System.Array.Empty(); MethodTable methodTable = _methodTables[typeHandle.Address]; if (!methodTable.Flags.HasInstantiation) - return default; + return global::System.Array.Empty(); return _target.ProcessedData.GetOrAdd(typeHandle.Address).TypeHandles; } - public bool IsClassInited(TypeHandle typeHandle) + public bool IsClassInited(ITypeHandle typeHandle) { if (!typeHandle.IsMethodTable()) return false; @@ -818,7 +827,7 @@ public bool IsClassInited(TypeHandle typeHandle) return (auxiliaryData.Flags & (uint)MethodTableAuxiliaryFlags.Initialized) != 0; } - public bool IsInitError(TypeHandle typeHandle) + public bool IsInitError(ITypeHandle typeHandle) { if (!typeHandle.IsMethodTable()) return false; @@ -831,7 +840,7 @@ private sealed class TypeInstantiation : IData { public static TypeInstantiation Create(Target target, TargetPointer address) => new TypeInstantiation(target, address); - public TypeHandle[] TypeHandles { get; } + public ITypeHandle[] TypeHandles { get; } private TypeInstantiation(Target target, TargetPointer typePointer) { RuntimeTypeSystem_1 rts = (RuntimeTypeSystem_1)target.Contracts.RuntimeTypeSystem; @@ -847,7 +856,7 @@ private TypeInstantiation(Target target, TargetPointer typePointer) TargetPointer dictionaryPointer = target.ReadPointer(perInstInfo + (ulong)target.PointerSize * (ulong)(genericsDictInfo.NumDicts - 1)); int numberOfGenericArgs = genericsDictInfo.NumTypeArgs; - TypeHandles = new TypeHandle[numberOfGenericArgs]; + TypeHandles = new ITypeHandle[numberOfGenericArgs]; for (int i = 0; i < numberOfGenericArgs; i++) { TypeHandles[i] = rts.GetTypeHandle(target.ReadPointer(dictionaryPointer + (ulong)target.PointerSize * (ulong)i)); @@ -855,9 +864,12 @@ private TypeInstantiation(Target target, TargetPointer typePointer) } } - public bool IsGenericTypeDefinition(TypeHandle typeHandle) => !typeHandle.IsMethodTable() ? false : _methodTables[typeHandle.Address].Flags.IsGenericTypeDefinition; - public bool ContainsGenericVariables(TypeHandle typeHandle) + public bool IsGenericTypeDefinition(ITypeHandle typeHandle) => !typeHandle.IsMethodTable() ? false : _methodTables[typeHandle.Address].Flags.IsGenericTypeDefinition; + public bool ContainsGenericVariables(ITypeHandle typeHandle) { + if (typeHandle is SyntheticTypeHandle) + return ContainsGenericVariables(GetRootTypeParam(typeHandle)); + if (typeHandle.IsTypeDesc()) { CorElementType type = GetSignatureCorElementType(typeHandle); @@ -871,8 +883,8 @@ public bool ContainsGenericVariables(TypeHandle typeHandle) else if (type == CorElementType.FnPtr) { - _ = IsFunctionPointer(typeHandle, out ReadOnlySpan signatureTypeArgs, out _); - foreach (TypeHandle sigTypeArg in signatureTypeArgs) + _ = IsFunctionPointer(typeHandle, out ITypeHandle[] signatureTypeArgs, out _); + foreach (ITypeHandle sigTypeArg in signatureTypeArgs) { if (ContainsGenericVariables(sigTypeArg)) return true; @@ -884,9 +896,12 @@ public bool ContainsGenericVariables(TypeHandle typeHandle) return _methodTables[typeHandle.Address].Flags.ContainsGenericVariables; } - public bool IsCollectible(TypeHandle typeHandle) => !typeHandle.IsMethodTable() ? false : _methodTables[typeHandle.Address].Flags.IsCollectible; - public bool HasTypeParam(TypeHandle typeHandle) + public bool IsCollectible(ITypeHandle typeHandle) => !typeHandle.IsMethodTable() ? false : _methodTables[typeHandle.Address].Flags.IsCollectible; + public bool HasTypeParam(ITypeHandle typeHandle) { + if (typeHandle is SyntheticTypeHandle) + return true; + if (typeHandle.IsMethodTable()) { MethodTable methodTable = _methodTables[typeHandle.Address]; @@ -907,8 +922,11 @@ public bool HasTypeParam(TypeHandle typeHandle) return false; } - public CorElementType GetSignatureCorElementType(TypeHandle typeHandle) + public CorElementType GetSignatureCorElementType(ITypeHandle typeHandle) { + if (typeHandle is SyntheticTypeHandle synthetic) + return synthetic.Kind; + if (typeHandle.IsMethodTable()) { MethodTable methodTable = _methodTables[typeHandle.Address]; @@ -938,7 +956,7 @@ public CorElementType GetSignatureCorElementType(TypeHandle typeHandle) return default; } - public CorElementType GetInternalCorElementType(TypeHandle typeHandle) + public CorElementType GetInternalCorElementType(ITypeHandle typeHandle) { CorElementType sigType = GetSignatureCorElementType(typeHandle); if (sigType == CorElementType.ValueType && typeHandle.IsMethodTable()) @@ -951,7 +969,7 @@ public CorElementType GetInternalCorElementType(TypeHandle typeHandle) return sigType; } - public bool IsValueType(TypeHandle typeHandle) + public bool IsValueType(ITypeHandle typeHandle) { if (typeHandle.IsMethodTable()) { @@ -967,7 +985,7 @@ public bool IsValueType(TypeHandle typeHandle) return false; } - public bool IsEnum(TypeHandle typeHandle) + public bool IsEnum(ITypeHandle typeHandle) { // Enums have Category_Primitive in their MethodTable flags and their // InternalCorElementType is a primitive type (I1, U1, I2, U2, I4, U4, I8, U8), @@ -979,7 +997,7 @@ public bool IsEnum(TypeHandle typeHandle) return methodTable.Flags.GetFlag(MethodTableFlags_1.WFLAGS_HIGH.Category_Mask) == MethodTableFlags_1.WFLAGS_HIGH.Category_Primitive; } - public bool IsDelegate(TypeHandle typeHandle) + public bool IsDelegate(ITypeHandle typeHandle) { if (!typeHandle.IsMethodTable()) return false; @@ -988,9 +1006,25 @@ public bool IsDelegate(TypeHandle typeHandle) return parentMT == _multicastDelegateMethodTablePointer; } - // return true if the TypeHandle represents an array, and set the rank to either 0 (if the type is not an array), or the rank number if it is. - public bool IsArray(TypeHandle typeHandle, out uint rank) + // return true if the ITypeHandle represents an array, and set the rank to either 0 (if the type is not an array), or the rank number if it is. + public bool IsArray(ITypeHandle typeHandle, out uint rank) { + if (typeHandle is SyntheticTypeHandle synthetic) + { + if (synthetic.Kind == CorElementType.SzArray) + { + rank = 1; + return true; + } + if (synthetic.Kind == CorElementType.Array) + { + rank = (uint)synthetic.Rank; + return true; + } + rank = 0; + return false; + } + if (typeHandle.IsMethodTable()) { MethodTable methodTable = _methodTables[typeHandle.Address]; @@ -1014,8 +1048,11 @@ public bool IsArray(TypeHandle typeHandle, out uint rank) return false; } - public TypeHandle GetTypeParam(TypeHandle typeHandle) + public ITypeHandle GetTypeParam(ITypeHandle typeHandle) { + if (typeHandle is SyntheticTypeHandle synthetic) + return synthetic.Element; + if (typeHandle.IsMethodTable()) { MethodTable methodTable = _methodTables[typeHandle.Address]; @@ -1040,9 +1077,9 @@ public TypeHandle GetTypeParam(TypeHandle typeHandle) throw new ArgumentException(nameof(typeHandle)); } - private TypeHandle GetRootTypeParam(TypeHandle typeHandle) + private ITypeHandle GetRootTypeParam(ITypeHandle typeHandle) { - TypeHandle current = typeHandle; + ITypeHandle current = typeHandle; while (HasTypeParam(current)) { current = GetTypeParam(current); @@ -1050,9 +1087,9 @@ private TypeHandle GetRootTypeParam(TypeHandle typeHandle) return current; } - private bool GenericInstantiationMatch(TypeHandle genericType, TypeHandle potentialMatch, ImmutableArray typeArguments) + private bool GenericInstantiationMatch(ITypeHandle genericType, ITypeHandle potentialMatch, ImmutableArray typeArguments) { - ReadOnlySpan instantiation = GetInstantiation(potentialMatch); + ITypeHandle[] instantiation = GetInstantiation(potentialMatch); if (instantiation.Length != typeArguments.Length) return false; @@ -1070,7 +1107,7 @@ private bool GenericInstantiationMatch(TypeHandle genericType, TypeHandle potent return true; } - private bool ArrayPtrMatch(TypeHandle elementType, CorElementType corElementType, int rank, TypeHandle potentialMatch) + private bool ArrayPtrMatch(ITypeHandle elementType, CorElementType corElementType, int rank, ITypeHandle potentialMatch) { IsArray(potentialMatch, out uint typeHandleRank); return GetSignatureCorElementType(potentialMatch) == corElementType && @@ -1080,9 +1117,9 @@ private bool ArrayPtrMatch(TypeHandle elementType, CorElementType corElementType } - private bool FnPtrMatch(TypeHandle candidate, ImmutableArray retAndArgTypes, SignatureCallingConvention callConv) + private bool FnPtrMatch(ITypeHandle candidate, ImmutableArray retAndArgTypes, SignatureCallingConvention callConv) { - if (!IsFunctionPointer(candidate, out ReadOnlySpan candidateRetAndArgs, out SignatureCallingConvention candidateCallConv)) + if (!IsFunctionPointer(candidate, out ITypeHandle[] candidateRetAndArgs, out SignatureCallingConvention candidateCallConv)) return false; if (candidateCallConv != callConv) return false; @@ -1096,9 +1133,9 @@ private bool FnPtrMatch(TypeHandle candidate, ImmutableArray retAndA return true; } - private bool IsLoaded(TypeHandle typeHandle) + private bool IsLoaded(ITypeHandle typeHandle) { - if (typeHandle.Address == TargetPointer.Null) + if (typeHandle.IsNull || typeHandle.IsSynthetic) return false; if (typeHandle.IsTypeDesc()) { @@ -1111,11 +1148,11 @@ private bool IsLoaded(TypeHandle typeHandle) return (auxData.Flags & (uint)MethodTableAuxiliaryFlags.IsNotFullyLoaded) == 0; // IsUnloaded } - TypeHandle IRuntimeTypeSystem.GetConstructedType(TypeHandle typeHandle, CorElementType corElementType, int rank, ImmutableArray typeArguments, SignatureCallingConvention callConv) + ITypeHandle IRuntimeTypeSystem.GetConstructedType(ITypeHandle typeHandle, CorElementType corElementType, int rank, ImmutableArray typeArguments, SignatureCallingConvention callConv) { - if (typeHandle.Address == TargetPointer.Null && corElementType != CorElementType.FnPtr) - return new TypeHandle(TargetPointer.Null); - if (_typeHandles.TryGetValue(new TypeKey(typeHandle, corElementType, rank, typeArguments, callConv), out TypeHandle existing)) + if (typeHandle.IsNull && corElementType != CorElementType.FnPtr) + return ITypeHandle.Null; + if (_typeHandles.TryGetValue(new TypeKey(typeHandle, corElementType, rank, typeArguments, callConv), out ITypeHandle? existing) && existing is not null) return existing; ILoader loaderContract = _target.Contracts.Loader; TargetPointer loaderModule; @@ -1125,7 +1162,7 @@ TypeHandle IRuntimeTypeSystem.GetConstructedType(TypeHandle typeHandle, CorEleme loaderModule = GetLoaderModule(typeHandle); ModuleHandle moduleHandle = loaderContract.GetModuleHandleFromModulePtr(loaderModule); - TypeHandle potentialMatch; + ITypeHandle potentialMatch; foreach (TargetPointer ptr in loaderContract.GetAvailableTypeParams(moduleHandle)) { potentialMatch = GetTypeHandle(ptr); @@ -1151,14 +1188,23 @@ TypeHandle IRuntimeTypeSystem.GetConstructedType(TypeHandle typeHandle, CorEleme return potentialMatch; } } - return new TypeHandle(TargetPointer.Null); + // No loaded match found. For Ptr/Byref/SzArray/Array, synthesize a handle + // so signature-decoding contracts can treat unloaded constructed types uniformly. + if (corElementType is CorElementType.Ptr or CorElementType.Byref or CorElementType.SzArray or CorElementType.Array) + { + var synthetic = new SyntheticTypeHandle(corElementType, typeHandle, rank); + _ = _typeHandles.TryAdd(new TypeKey(typeHandle, corElementType, rank, typeArguments, callConv), synthetic); + return synthetic; + } + + return ITypeHandle.Null; } // Mirrors the native algorithm // ClassLoader::ComputeLoaderModuleForFunctionPointer: the loader module is the collectible // ret/arg type's loader module with the largest LoaderAllocator creation number, or CoreLib's // loader module if none of the ret/arg types are collectible. - private TargetPointer FindFnPtrLoaderModule(ImmutableArray retAndArgTypes) + private TargetPointer FindFnPtrLoaderModule(ImmutableArray retAndArgTypes) { ILoader loaderContract = _target.Contracts.Loader; @@ -1166,9 +1212,9 @@ private TargetPointer FindFnPtrLoaderModule(ImmutableArray retAndArg ulong latestFoundNumber = 0; bool anyCollectible = false; - foreach (TypeHandle arg in retAndArgTypes) + foreach (ITypeHandle arg in retAndArgTypes) { - if (arg.Address == TargetPointer.Null) + if (arg.IsNull) continue; TargetPointer argModulePtr = GetLoaderModule(arg); @@ -1202,7 +1248,7 @@ private TargetPointer FindFnPtrLoaderModule(ImmutableArray retAndArg return loaderModulePtr; } - TypeHandle IRuntimeTypeSystem.GetPrimitiveType(CorElementType typeCode) + ITypeHandle IRuntimeTypeSystem.GetPrimitiveType(CorElementType typeCode) { TargetPointer coreLib = _target.ReadGlobalPointer(Constants.Globals.CoreLib); CoreLibBinder coreLibData = _target.ProcessedData.GetOrAdd(coreLib); @@ -1210,7 +1256,7 @@ TypeHandle IRuntimeTypeSystem.GetPrimitiveType(CorElementType typeCode) return GetTypeHandle(typeHandlePtr); } - public bool IsGenericVariable(TypeHandle typeHandle, out TargetPointer module, out uint token) + public bool IsGenericVariable(ITypeHandle typeHandle, out TargetPointer module, out uint token) { module = TargetPointer.Null; token = 0; @@ -1232,9 +1278,9 @@ public bool IsGenericVariable(TypeHandle typeHandle, out TargetPointer module, o return false; } - public bool IsFunctionPointer(TypeHandle typeHandle, out ReadOnlySpan retAndArgTypes, out SignatureCallingConvention callConv) + public bool IsFunctionPointer(ITypeHandle typeHandle, out ITypeHandle[] retAndArgTypes, out SignatureCallingConvention callConv) { - retAndArgTypes = default; + retAndArgTypes = global::System.Array.Empty(); callConv = default; if (!typeHandle.IsTypeDesc()) @@ -1251,8 +1297,11 @@ public bool IsFunctionPointer(TypeHandle typeHandle, out ReadOnlySpan typeHandle.IsTypeDesc(); + public bool IsTypeDesc(ITypeHandle typeHandle) => typeHandle.IsTypeDesc(); public TypedByRefInfo GetTypedByRefInfo(TargetPointer typedByRef) { @@ -1269,8 +1318,11 @@ public TypedByRefInfo GetTypedByRefInfo(TargetPointer typedByRef) return new TypedByRefInfo(typedByRefData.Data, typedByRefData.Type); } - public TargetPointer GetLoaderModule(TypeHandle typeHandle) + public TargetPointer GetLoaderModule(ITypeHandle typeHandle) { + if (typeHandle is SyntheticTypeHandle synthetic) + return GetLoaderModule(synthetic.Element); + if (typeHandle.IsTypeDesc()) { // TypeDesc::GetLoaderModule @@ -1299,7 +1351,7 @@ private sealed class FunctionPointerRetAndArgs : IData new FunctionPointerRetAndArgs(target, address); - public TypeHandle[] TypeHandles { get; } + public ITypeHandle[] TypeHandles { get; } private FunctionPointerRetAndArgs(Target target, TargetPointer typePointer) { RuntimeTypeSystem_1 rts = (RuntimeTypeSystem_1)target.Contracts.RuntimeTypeSystem; @@ -1308,7 +1360,7 @@ private FunctionPointerRetAndArgs(Target target, TargetPointer typePointer) TargetPointer retAndArgs = fnPtrTypeDesc.RetAndArgTypes; int numberOfRetAndArgTypes = checked((int)fnPtrTypeDesc.NumArgs + 1); - TypeHandles = new TypeHandle[numberOfRetAndArgTypes]; + TypeHandles = new ITypeHandle[numberOfRetAndArgTypes]; for (int i = 0; i < numberOfRetAndArgTypes; i++) { TypeHandles[i] = rts.GetTypeHandle(target.ReadPointer(retAndArgs + (ulong)target.PointerSize * (ulong)i)); @@ -1380,12 +1432,12 @@ public bool IsGenericMethodDefinition(MethodDescHandle methodDescHandle) return AsInstantiatedMethodDesc(methodDesc).IsGenericMethodDefinition; } - public ReadOnlySpan GetGenericMethodInstantiation(MethodDescHandle methodDescHandle) + public ITypeHandle[] GetGenericMethodInstantiation(MethodDescHandle methodDescHandle) { MethodDesc methodDesc = _methodDescs[methodDescHandle.Address]; if (methodDesc.Classification != MethodClassification.Instantiated) - return default; + return global::System.Array.Empty(); return AsInstantiatedMethodDesc(methodDesc).Instantiation; } @@ -1620,7 +1672,7 @@ private VtableIndirections GetVTableIndirections(TargetPointer methodTableAddres return new VtableIndirections(_target, methodTableAddress + typeInfo.Size!.Value); } - private TargetPointer GetAddressOfSlot(TypeHandle typeHandle, uint slotNum) + private TargetPointer GetAddressOfSlot(ITypeHandle typeHandle, uint slotNum) { if (!typeHandle.IsMethodTable()) throw new InvalidOperationException($"nameof{typeHandle} is not a MethodTable"); @@ -1681,7 +1733,7 @@ private TargetPointer GetLoaderModule(MethodDesc md) else { TargetPointer mtAddr = GetMethodTable(new MethodDescHandle(md.Address)); - TypeHandle mt = GetTypeHandle(mtAddr); + ITypeHandle mt = GetTypeHandle(mtAddr); return GetLoaderModule(mt); } } @@ -1740,7 +1792,7 @@ bool IRuntimeTypeSystem.HasNativeCodeSlot(MethodDescHandle methodDesc) } // Based on MethodTable::IntroducedMethodIterator - private IEnumerable GetIntroducedMethods(TypeHandle typeHandle) + private IEnumerable GetIntroducedMethods(ITypeHandle typeHandle) { Debug.Assert(typeHandle.IsMethodTable()); @@ -1766,12 +1818,12 @@ private IEnumerable GetIntroducedMethods(TypeHandle typeHandle } } - IEnumerable IRuntimeTypeSystem.GetIntroducedMethodDescs(TypeHandle typeHandle) + IEnumerable IRuntimeTypeSystem.GetIntroducedMethodDescs(ITypeHandle typeHandle) { if (!typeHandle.IsMethodTable()) yield break; - TypeHandle canonMT = GetTypeHandle(GetCanonicalMethodTable(typeHandle)); + ITypeHandle canonMT = GetTypeHandle(GetCanonicalMethodTable(typeHandle)); foreach (MethodDescHandle mdh in GetIntroducedMethods(canonMT)) { yield return mdh.Address; @@ -1780,13 +1832,13 @@ IEnumerable IRuntimeTypeSystem.GetIntroducedMethodDescs(TypeHandl // Uses GetMethodDescForVtableSlot if slot is less than the number of vtable slots // otherwise looks for the slot in the introduced methods - TargetPointer IRuntimeTypeSystem.GetMethodDescForSlot(TypeHandle typeHandle, ushort slot) + TargetPointer IRuntimeTypeSystem.GetMethodDescForSlot(ITypeHandle typeHandle, ushort slot) { if (!typeHandle.IsMethodTable()) // TypeDesc do not contain any slots. return TargetPointer.Null; - TypeHandle canonMT = GetTypeHandle(GetCanonicalMethodTable(typeHandle)); + ITypeHandle canonMT = GetTypeHandle(GetCanonicalMethodTable(typeHandle)); if (slot < GetNumVtableSlots(canonMT)) { return GetMethodDescForVtableSlot(canonMT, slot); @@ -1805,7 +1857,7 @@ TargetPointer IRuntimeTypeSystem.GetMethodDescForSlot(TypeHandle typeHandle, ush } } - private TargetPointer GetMethodDescForVtableSlot(TypeHandle typeHandle, ushort slot) + private TargetPointer GetMethodDescForVtableSlot(ITypeHandle typeHandle, ushort slot) { // based on MethodTable::GetMethodDescForSlot_NoThrow if (!typeHandle.IsMethodTable()) @@ -1813,7 +1865,7 @@ private TargetPointer GetMethodDescForVtableSlot(TypeHandle typeHandle, ushort s throw new ArgumentException(nameof(slot), "Slot number is greater than the number of slots"); TargetPointer cannonMTPTr = GetCanonicalMethodTable(typeHandle); - TypeHandle canonMT = GetTypeHandle(cannonMTPTr); + ITypeHandle canonMT = GetTypeHandle(cannonMTPTr); if (slot >= GetNumVtableSlots(canonMT)) throw new ArgumentException(nameof(slot), "Slot number is greater than the number of slots"); @@ -1826,7 +1878,7 @@ private TargetPointer GetMethodDescForVtableSlot(TypeHandle typeHandle, ushort s while (lookupMTPtr != TargetPointer.Null) { // if pCode is null, we iterate through the method descs in the MT. - TypeHandle lookupMT = GetTypeHandle(lookupMTPtr); + ITypeHandle lookupMT = GetTypeHandle(lookupMTPtr); foreach (MethodDescHandle mdh in GetIntroducedMethods(lookupMT)) { MethodDesc md = _methodDescs[mdh.Address]; @@ -1862,7 +1914,7 @@ private readonly TargetPointer GetMethodDescForEntrypoint(TargetCodePointer pCod } } - TargetCodePointer IRuntimeTypeSystem.GetSlot(TypeHandle typeHandle, uint slot) + TargetCodePointer IRuntimeTypeSystem.GetSlot(ITypeHandle typeHandle, uint slot) { // based on MethodTable::GetSlot(uint slotNumber) @@ -1924,7 +1976,7 @@ private TargetCodePointer GetMethodEntryPointIfExists(MethodDesc md) } TargetPointer methodTablePointer = md.MethodTable; - TypeHandle typeHandle = GetTypeHandle(methodTablePointer); + ITypeHandle typeHandle = GetTypeHandle(methodTablePointer); Debug.Assert(_methodTables[typeHandle.Address].IsCanonMT); TargetPointer addrOfSlot = GetAddressOfSlot(typeHandle, md.Slot); return _target.ReadCodePointer(addrOfSlot); @@ -2012,7 +2064,7 @@ public TargetPointer GetAddressOfMethodTableSlot(TargetPointer methodTablePointe // for the benefit of MethodValidation private TargetPointer GetAddressOfMethodTableSlot(TargetPointer methodTablePointer, uint slot) { - TypeHandle typeHandle = GetTypeHandle(methodTablePointer); + ITypeHandle typeHandle = GetTypeHandle(methodTablePointer); Debug.Assert(_methodTables[typeHandle.Address].IsCanonMT); TargetPointer addrOfSlot = GetAddressOfSlot(typeHandle, slot); return addrOfSlot; @@ -2020,7 +2072,7 @@ private TargetPointer GetAddressOfMethodTableSlot(TargetPointer methodTablePoint private bool SlotIsVtableSlot(TargetPointer methodTablePointer, uint slot) { - TypeHandle typeHandle = GetTypeHandle(methodTablePointer); + ITypeHandle typeHandle = GetTypeHandle(methodTablePointer); return slot < GetNumVtableSlots(typeHandle); } TargetPointer IRuntimeTypeSystem.GetMTOfEnclosingClass(TargetPointer fieldDescPointer) @@ -2072,7 +2124,7 @@ uint IRuntimeTypeSystem.GetFieldDescOffset(TargetPointer fieldDescPointer, Field return fieldDesc.DWord2 & (uint)FieldDescFlags2.OffsetMask; } - TargetPointer IRuntimeTypeSystem.GetFieldDescByName(TypeHandle typeHandle, string fieldName) + TargetPointer IRuntimeTypeSystem.GetFieldDescByName(ITypeHandle typeHandle, string fieldName) { if (!typeHandle.IsMethodTable()) return TargetPointer.Null; @@ -2130,7 +2182,7 @@ private TargetPointer GetStaticAddressHandle(TargetPointer @base, uint offset, b private TargetPointer GetFieldDescStaticOrThreadStaticAddress(TargetPointer fieldDescPointer, TargetPointer? thread = null, bool unboxValueTypes = true) { TargetPointer enclosingMT = ((IRuntimeTypeSystem)this).GetMTOfEnclosingClass(fieldDescPointer); - TypeHandle ctx = GetTypeHandle(enclosingMT); + ITypeHandle ctx = GetTypeHandle(enclosingMT); TargetPointer modulePtr = GetModule(ctx); ILoader loader = _target.Contracts.Loader; ModuleHandle moduleHandle = loader.GetModuleHandleFromModulePtr(modulePtr); diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/Signature/IRuntimeSignatureTypeProvider.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/Signature/IRuntimeSignatureTypeProvider.cs index a8d9b15251dd40..722247e1f4fe1e 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/Signature/IRuntimeSignatureTypeProvider.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/Signature/IRuntimeSignatureTypeProvider.cs @@ -21,13 +21,13 @@ public interface IRuntimeSignatureTypeProvider { /// /// Classify an ELEMENT_TYPE_INTERNAL (0x21) type by resolving the - /// embedded TypeHandle pointer via the target's runtime type system. + /// embedded ITypeHandle pointer via the target's runtime type system. /// TType GetInternalType(TargetPointer typeHandlePointer); /// /// Classify an ELEMENT_TYPE_CMOD_INTERNAL (0x22) custom modifier by - /// resolving the embedded TypeHandle pointer via the target's runtime type system. + /// resolving the embedded ITypeHandle pointer via the target's runtime type system. /// TType GetInternalModifiedType(TargetPointer typeHandlePointer, TType unmodifiedType, bool isRequired); } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/Signature/SignatureTypeProvider.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/Signature/SignatureTypeProvider.cs index c6cb2bfb47fbd5..813c9466bbd3d9 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/Signature/SignatureTypeProvider.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/Signature/SignatureTypeProvider.cs @@ -10,7 +10,7 @@ namespace Microsoft.Diagnostics.DataContractReader.SignatureHelpers; -public class SignatureTypeProvider : IRuntimeSignatureTypeProvider +public class SignatureTypeProvider : IRuntimeSignatureTypeProvider { private readonly Target _target; private readonly Contracts.ModuleHandle _moduleHandle; @@ -25,19 +25,19 @@ public SignatureTypeProvider(Target target, Contracts.ModuleHandle moduleHandle) _runtimeTypeSystem = target.Contracts.RuntimeTypeSystem; } - public TypeHandle GetArrayType(TypeHandle elementType, ArrayShape shape) + public ITypeHandle GetArrayType(ITypeHandle elementType, ArrayShape shape) => _runtimeTypeSystem.GetConstructedType(elementType, CorElementType.Array, shape.Rank, []); - public TypeHandle GetByReferenceType(TypeHandle elementType) + public ITypeHandle GetByReferenceType(ITypeHandle elementType) => _runtimeTypeSystem.GetConstructedType(elementType, CorElementType.Byref, 0, []); - public TypeHandle GetFunctionPointerType(MethodSignature signature) + public ITypeHandle GetFunctionPointerType(MethodSignature signature) => GetPrimitiveType(PrimitiveTypeCode.IntPtr); - public TypeHandle GetGenericInstantiation(TypeHandle genericType, ImmutableArray typeArguments) + public ITypeHandle GetGenericInstantiation(ITypeHandle genericType, ImmutableArray typeArguments) => _runtimeTypeSystem.GetConstructedType(genericType, CorElementType.GenericInst, 0, typeArguments); - public TypeHandle GetGenericMethodParameter(T context, int index) + public ITypeHandle GetGenericMethodParameter(T context, int index) { if (typeof(T) == typeof(MethodDescHandle)) { @@ -46,55 +46,55 @@ public TypeHandle GetGenericMethodParameter(T context, int index) } throw new NotSupportedException(); } - public TypeHandle GetGenericTypeParameter(T context, int index) + public ITypeHandle GetGenericTypeParameter(T context, int index) { - TypeHandle typeContext; - if (typeof(T) == typeof(TypeHandle)) + ITypeHandle typeContext; + if (typeof(T) == typeof(ITypeHandle)) { - typeContext = (TypeHandle)(object)context!; + typeContext = (ITypeHandle)(object)context!; return _runtimeTypeSystem.GetInstantiation(typeContext)[index]; } throw new NotImplementedException(); } - public TypeHandle GetModifiedType(TypeHandle modifier, TypeHandle unmodifiedType, bool isRequired) + public ITypeHandle GetModifiedType(ITypeHandle modifier, ITypeHandle unmodifiedType, bool isRequired) => unmodifiedType; - public TypeHandle GetPinnedType(TypeHandle elementType) + public ITypeHandle GetPinnedType(ITypeHandle elementType) => elementType; - public TypeHandle GetPointerType(TypeHandle elementType) + public ITypeHandle GetPointerType(ITypeHandle elementType) => _runtimeTypeSystem.GetConstructedType(elementType, CorElementType.Ptr, 0, []); - public TypeHandle GetPrimitiveType(PrimitiveTypeCode typeCode) + public ITypeHandle GetPrimitiveType(PrimitiveTypeCode typeCode) => _runtimeTypeSystem.GetPrimitiveType((CorElementType)typeCode); - public TypeHandle GetSZArrayType(TypeHandle elementType) + public ITypeHandle GetSZArrayType(ITypeHandle elementType) => _runtimeTypeSystem.GetConstructedType(elementType, CorElementType.SzArray, 1, []); - public TypeHandle GetTypeFromDefinition(MetadataReader reader, TypeDefinitionHandle handle, byte rawTypeKind) + public ITypeHandle GetTypeFromDefinition(MetadataReader reader, TypeDefinitionHandle handle, byte rawTypeKind) { int token = MetadataTokens.GetToken((EntityHandle)handle); TargetPointer typeDefToMethodTable = _loader.GetLookupTables(_moduleHandle).TypeDefToMethodTable; TargetPointer typeHandlePtr = _loader.GetModuleLookupMapElement(typeDefToMethodTable, (uint)token, out _); - return typeHandlePtr == TargetPointer.Null ? new TypeHandle(TargetPointer.Null) : _runtimeTypeSystem.GetTypeHandle(typeHandlePtr); + return typeHandlePtr == TargetPointer.Null ? ITypeHandle.Null : _runtimeTypeSystem.GetTypeHandle(typeHandlePtr); } - public TypeHandle GetTypeFromReference(MetadataReader reader, TypeReferenceHandle handle, byte rawTypeKind) + public ITypeHandle GetTypeFromReference(MetadataReader reader, TypeReferenceHandle handle, byte rawTypeKind) { int token = MetadataTokens.GetToken((EntityHandle)handle); TargetPointer typeRefToMethodTable = _loader.GetLookupTables(_moduleHandle).TypeRefToMethodTable; TargetPointer typeHandlePtr = _loader.GetModuleLookupMapElement(typeRefToMethodTable, (uint)token, out _); - return typeHandlePtr == TargetPointer.Null ? new TypeHandle(TargetPointer.Null) : _runtimeTypeSystem.GetTypeHandle(typeHandlePtr); + return typeHandlePtr == TargetPointer.Null ? ITypeHandle.Null : _runtimeTypeSystem.GetTypeHandle(typeHandlePtr); } - public TypeHandle GetTypeFromSpecification(MetadataReader reader, T context, TypeSpecificationHandle handle, byte rawTypeKind) + public ITypeHandle GetTypeFromSpecification(MetadataReader reader, T context, TypeSpecificationHandle handle, byte rawTypeKind) => throw new NotImplementedException(); - public TypeHandle GetInternalType(TargetPointer typeHandlePointer) + public ITypeHandle GetInternalType(TargetPointer typeHandlePointer) => typeHandlePointer == TargetPointer.Null - ? new TypeHandle(TargetPointer.Null) + ? ITypeHandle.Null : _runtimeTypeSystem.GetTypeHandle(typeHandlePointer); - public TypeHandle GetInternalModifiedType(TargetPointer typeHandlePointer, TypeHandle unmodifiedType, bool isRequired) + public ITypeHandle GetInternalModifiedType(TargetPointer typeHandlePointer, ITypeHandle unmodifiedType, bool isRequired) => unmodifiedType; } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/Signature/Signature_1.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/Signature/Signature_1.cs index ee7cf0485ee0e8..1bb1626266fd7a 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/Signature/Signature_1.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/Signature/Signature_1.cs @@ -18,7 +18,7 @@ namespace Microsoft.Diagnostics.DataContractReader.Contracts; internal sealed class Signature_1 : ISignature { private readonly Target _target; - private readonly Dictionary> _thProviders = []; + private readonly Dictionary> _thProviders = []; internal Signature_1(Target target) { @@ -30,25 +30,25 @@ public void Flush(FlushScope scope) _thProviders.Clear(); } - private SignatureTypeProvider GetTypeHandleProvider(ModuleHandle moduleHandle) + private SignatureTypeProvider GetTypeHandleProvider(ModuleHandle moduleHandle) { - if (_thProviders.TryGetValue(moduleHandle, out SignatureTypeProvider? thProvider)) + if (_thProviders.TryGetValue(moduleHandle, out SignatureTypeProvider? thProvider)) { return thProvider; } - SignatureTypeProvider newProvider = new(_target, moduleHandle); + SignatureTypeProvider newProvider = new(_target, moduleHandle); _thProviders[moduleHandle] = newProvider; return newProvider; } - TypeHandle ISignature.DecodeFieldSignature(BlobHandle blobHandle, ModuleHandle moduleHandle, TypeHandle ctx) + ITypeHandle ISignature.DecodeFieldSignature(BlobHandle blobHandle, ModuleHandle moduleHandle, ITypeHandle ctx) { - SignatureTypeProvider provider = GetTypeHandleProvider(moduleHandle); + SignatureTypeProvider provider = GetTypeHandleProvider(moduleHandle); MetadataReader mdReader = _target.Contracts.EcmaMetadata.GetMetadata(moduleHandle)!; BlobReader blobReader = mdReader.GetBlobReader(blobHandle); - RuntimeSignatureDecoder decoder = new(provider, _target, mdReader, ctx); + RuntimeSignatureDecoder decoder = new(provider, _target, mdReader, ctx); return decoder.DecodeFieldSignature(ref blobReader); } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/StackWalk/FrameHandling/FrameHelpers.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/StackWalk/FrameHandling/FrameHelpers.cs index e04cdd7149993e..51d9a24b7bf647 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/StackWalk/FrameHandling/FrameHelpers.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/StackWalk/FrameHandling/FrameHelpers.cs @@ -116,7 +116,7 @@ public TargetPointer GetMethodDescPtr(TargetPointer framePtr) else if (stubDispatchFrame.RepresentativeMTPtr != TargetPointer.Null) { IRuntimeTypeSystem rtsContract = _target.Contracts.RuntimeTypeSystem; - TypeHandle mtHandle = rtsContract.GetTypeHandle(stubDispatchFrame.RepresentativeMTPtr); + ITypeHandle mtHandle = rtsContract.GetTypeHandle(stubDispatchFrame.RepresentativeMTPtr); return rtsContract.GetMethodDescForSlot(mtHandle, (ushort)stubDispatchFrame.RepresentativeSlot); } else diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/StackWalk/GC/GcSignatureTypeProvider.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/StackWalk/GC/GcSignatureTypeProvider.cs index 8852f733df6a97..ed9cad1d11850b 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/StackWalk/GC/GcSignatureTypeProvider.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/StackWalk/GC/GcSignatureTypeProvider.cs @@ -28,10 +28,10 @@ internal enum GcTypeKind /// /// Generic context used to resolve ELEMENT_TYPE_VAR and ELEMENT_TYPE_MVAR /// while decoding a method signature for GC scanning. is the -/// owning type's (used for VAR), and +/// owning type's (used for VAR), and /// is the owning method's (used for MVAR). /// -internal readonly record struct GcSignatureContext(TypeHandle ClassContext, MethodDescHandle MethodContext); +internal readonly record struct GcSignatureContext(ITypeHandle ClassContext, MethodDescHandle MethodContext); /// /// Classifies signature types for GC scanning purposes. @@ -87,7 +87,7 @@ public GcTypeKind GetGenericMethodParameter(GcSignatureContext genericContext, i { try { - ReadOnlySpan instantiation = _target.Contracts.RuntimeTypeSystem.GetGenericMethodInstantiation(genericContext.MethodContext); + ITypeHandle[] instantiation = _target.Contracts.RuntimeTypeSystem.GetGenericMethodInstantiation(genericContext.MethodContext); if ((uint)index >= (uint)instantiation.Length) return GcTypeKind.Ref; return ClassifyTypeHandle(instantiation[index]); @@ -103,7 +103,7 @@ public GcTypeKind GetGenericTypeParameter(GcSignatureContext genericContext, int try { IRuntimeTypeSystem rts = _target.Contracts.RuntimeTypeSystem; - TypeHandle classCtx = genericContext.ClassContext; + ITypeHandle classCtx = genericContext.ClassContext; if (rts.IsArray(classCtx, out _)) { @@ -117,7 +117,7 @@ public GcTypeKind GetGenericTypeParameter(GcSignatureContext genericContext, int return ClassifyTypeHandle(rts.GetTypeParam(classCtx)); } - ReadOnlySpan instantiation = rts.GetInstantiation(classCtx); + ITypeHandle[] instantiation = rts.GetInstantiation(classCtx); if ((uint)index >= (uint)instantiation.Length) return GcTypeKind.Ref; return ClassifyTypeHandle(instantiation[index]); @@ -150,7 +150,7 @@ public GcTypeKind GetInternalType(TargetPointer typeHandlePointer) /// /// Resolve a TypeDef/TypeRef token via the module's lookup tables and classify the - /// resulting . Falls back to a -based + /// resulting . Falls back to a -based /// classification when the type has not been loaded. /// private GcTypeKind ClassifyTokenLookup(TargetPointer lookupTable, int token, byte rawTypeKind) @@ -170,14 +170,14 @@ private GcTypeKind ClassifyTokenLookup(TargetPointer lookupTable, int token, byt } /// - /// Classify a resolved . Mirrors native + /// Classify a resolved . Mirrors native /// SigPointer::PeekElemTypeNormalized + gElementTypeInfo[etype].m_gc: /// enums collapse to their underlying primitive () so /// they are skipped during stack scanning, matching native behavior. /// - private GcTypeKind ClassifyTypeHandle(TypeHandle typeHandle) + private GcTypeKind ClassifyTypeHandle(ITypeHandle typeHandle) { - if (typeHandle.Address == TargetPointer.Null) + if (typeHandle.IsNull) return GcTypeKind.Ref; IRuntimeTypeSystem rts = _target.Contracts.RuntimeTypeSystem; diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/RuntimeTypeSystemHelpers/ExtensionMethods.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/RuntimeTypeSystemHelpers/ExtensionMethods.cs index 2dd9a6dde7e947..2ceafa34213cd6 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/RuntimeTypeSystemHelpers/ExtensionMethods.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/RuntimeTypeSystemHelpers/ExtensionMethods.cs @@ -7,17 +7,17 @@ namespace Microsoft.Diagnostics.DataContractReader.RuntimeTypeSystemHelpers; internal static class ExtensionMethods { - public static bool IsTypeDesc(this TypeHandle type) + public static bool IsTypeDesc(this ITypeHandle type) { return type.Address != 0 && ((ulong)type.Address & (ulong)RuntimeTypeSystem_1.TypeHandleBits.ValidMask) == (ulong)RuntimeTypeSystem_1.TypeHandleBits.TypeDesc; } - public static bool IsMethodTable(this TypeHandle type) + public static bool IsMethodTable(this ITypeHandle type) { return type.Address != 0 && ((ulong)type.Address & (ulong)RuntimeTypeSystem_1.TypeHandleBits.ValidMask) == (ulong)RuntimeTypeSystem_1.TypeHandleBits.MethodTable; } - public static TargetPointer TypeDescAddress(this TypeHandle type) + public static TargetPointer TypeDescAddress(this ITypeHandle type) { if (!type.IsTypeDesc()) return 0; diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/ClrDataFrame.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/ClrDataFrame.cs index 4e127457b5aae8..588890ea8109cb 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/ClrDataFrame.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/ClrDataFrame.cs @@ -410,7 +410,7 @@ private void GetMethodInfo(out MethodDescHandle mdh, out MetadataReader mdReader IRuntimeTypeSystem rts = _target.Contracts.RuntimeTypeSystem; mdh = rts.GetMethodDescHandle(methodDescPtr); TargetPointer mtAddr = rts.GetMethodTable(mdh); - TypeHandle typeHandle = rts.GetTypeHandle(mtAddr); + ITypeHandle typeHandle = rts.GetTypeHandle(mtAddr); TargetPointer modulePtr = rts.GetModule(typeHandle); ILoader loader = _target.Contracts.Loader; moduleHandle = loader.GetModuleHandleFromModulePtr(modulePtr); @@ -745,7 +745,7 @@ public FlagSignatureTypeProvider(Target target, Contracts.ModuleHandle moduleHan try { IRuntimeTypeSystem rts = _target.Contracts.RuntimeTypeSystem; - ReadOnlySpan methodInst = rts.GetGenericMethodInstantiation(mdh); + ITypeHandle[] methodInst = rts.GetGenericMethodInstantiation(mdh); return ResolveGenericParam(rts, methodInst[index]); } catch (System.Exception) { return ((uint)ClrDataValueFlag.DEFAULT, -1); } @@ -757,14 +757,14 @@ public FlagSignatureTypeProvider(Target target, Contracts.ModuleHandle moduleHan { IRuntimeTypeSystem rts = _target.Contracts.RuntimeTypeSystem; TargetPointer mtAddr = rts.GetMethodTable(mdh); - TypeHandle declaringType = rts.GetTypeHandle(mtAddr); - ReadOnlySpan typeInst = rts.GetInstantiation(declaringType); + ITypeHandle declaringType = rts.GetTypeHandle(mtAddr); + ITypeHandle[] typeInst = rts.GetInstantiation(declaringType); return ResolveGenericParam(rts, typeInst[index]); } catch (System.Exception) { return ((uint)ClrDataValueFlag.DEFAULT, -1); } } - private static (uint Flags, int Size) ResolveGenericParam(IRuntimeTypeSystem rts, TypeHandle resolvedType) + private static (uint Flags, int Size) ResolveGenericParam(IRuntimeTypeSystem rts, ITypeHandle resolvedType) { CorElementType elementType = rts.GetSignatureCorElementType(resolvedType); (uint flags, int size) = MapCorElementTypeToFlags(elementType); diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/ClrDataMethodDefinition.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/ClrDataMethodDefinition.cs index 0fe4e2641d91b0..7fcdbbbdfb65c9 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/ClrDataMethodDefinition.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/ClrDataMethodDefinition.cs @@ -45,9 +45,9 @@ private static bool HasClassInstantiation(Target target, MethodDescHandle md) { IRuntimeTypeSystem rts = target.Contracts.RuntimeTypeSystem; TargetPointer mtAddr = rts.GetMethodTable(md); - TypeHandle mt = rts.GetTypeHandle(mtAddr); + ITypeHandle mt = rts.GetTypeHandle(mtAddr); - return !rts.GetInstantiation(mt).IsEmpty; + return rts.GetInstantiation(mt).Length > 0; } private static bool HasMethodInstantiation(Target target, MethodDescHandle md) @@ -56,7 +56,7 @@ private static bool HasMethodInstantiation(Target target, MethodDescHandle md) if (rts.IsGenericMethodDefinition(md)) return true; - return !rts.GetGenericMethodInstantiation(md).IsEmpty; + return rts.GetGenericMethodInstantiation(md).Length > 0; } private static bool HasClassOrMethodInstantiation(Target target, MethodDescHandle md) diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/ClrDataMethodInstance.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/ClrDataMethodInstance.cs index 96bb383b43659c..534d1585027de8 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/ClrDataMethodInstance.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/ClrDataMethodInstance.cs @@ -63,7 +63,7 @@ int IXCLRDataMethodInstance.GetTokenAndScope(uint* token, DacComNullableByRef fpCallback, nint pUserData, List? cdacFields) @@ -2379,7 +2379,7 @@ private static void EmitFieldData( TargetPointer enclosingMT = rts.GetMTOfEnclosingClass(fdPtr); if (enclosingMT != TargetPointer.Null) { - TypeHandle enclosingTh = rts.GetTypeHandle(enclosingMT); + ITypeHandle enclosingTh = rts.GetTypeHandle(enclosingMT); isCollectibleStatic = rts.IsCollectible(enclosingTh); } } @@ -2479,7 +2479,7 @@ public int TypeHandleToExpandedTypeInfo(AreValueTypesBoxed boxed, ulong vmTypeHa try { IRuntimeTypeSystem rts = _target.Contracts.RuntimeTypeSystem; - TypeHandle th = rts.GetTypeHandle(new TargetPointer(vmTypeHandle)); + ITypeHandle th = rts.GetTypeHandle(new TargetPointer(vmTypeHandle)); TypeHandleToExpandedTypeInfoImpl(rts, boxed, th, pTypeInfo); } catch (System.Exception ex) @@ -2508,7 +2508,7 @@ public int GetObjectExpandedTypeInfo(AreValueTypesBoxed boxed, ulong addr, Debug { IRuntimeTypeSystem rts = _target.Contracts.RuntimeTypeSystem; TargetPointer mtAddr = _target.Contracts.Object.GetMethodTableAddress(new TargetPointer(addr)); - TypeHandle th = rts.GetTypeHandle(mtAddr); + ITypeHandle th = rts.GetTypeHandle(mtAddr); TypeHandleToExpandedTypeInfoImpl(rts, boxed, th, pTypeInfo); } catch (System.Exception ex) @@ -2632,10 +2632,10 @@ public int GetApproxTypeHandle(TypeInfoList* pTypeData, ulong* pRetVal) TargetPointer canonMtPtr = rts.GetWellKnownMethodTable(WellKnownMethodTable.Canon); if (canonMtPtr == TargetPointer.Null) throw Marshal.GetExceptionForHR(CorDbgHResults.CORDBG_E_CLASS_NOT_LOADED)!; - TypeHandle canonTh = rts.GetTypeHandle(canonMtPtr); + ITypeHandle canonTh = rts.GetTypeHandle(canonMtPtr); TypeDataWalk walk = new TypeDataWalk(_target, rts, canonTh, pTypeData->m_pList, (uint)pTypeData->m_nEntries); - TypeHandle th = walk.ReadLoadedTypeHandle(); + ITypeHandle th = walk.ReadLoadedTypeHandle(); if (th.IsNull) throw Marshal.GetExceptionForHR(CorDbgHResults.CORDBG_E_CLASS_NOT_LOADED)!; *pRetVal = th.Address.Value; @@ -2667,7 +2667,7 @@ public int GetExactTypeHandle(DebuggerIPCE_ExpandedTypeData* pTypeData, ArgInfoL try { IRuntimeTypeSystem rts = _target.Contracts.RuntimeTypeSystem; - TypeHandle th = default; + ITypeHandle th = ITypeHandle.Null; CorElementType et = (CorElementType)ReadLittleEndian(pTypeData->elementType); switch (et) { @@ -2711,10 +2711,10 @@ public int GetExactTypeHandle(DebuggerIPCE_ExpandedTypeData* pTypeData, ArgInfoL return hr; } - private TypeHandle BasicTypeInfoToTypeHandle(IRuntimeTypeSystem rts, DebuggerIPCE_BasicTypeData* pData) + private ITypeHandle BasicTypeInfoToTypeHandle(IRuntimeTypeSystem rts, DebuggerIPCE_BasicTypeData* pData) { CorElementType et = (CorElementType)ReadLittleEndian(pData->elementType); - TypeHandle th; + ITypeHandle th; switch (et) { case CorElementType.Array: @@ -2740,7 +2740,7 @@ private TypeHandle BasicTypeInfoToTypeHandle(IRuntimeTypeSystem rts, DebuggerIPC return th; } - private TypeHandle GetClassOrValueTypeHandle(IRuntimeTypeSystem rts, DebuggerIPCE_BasicTypeData* pData) + private ITypeHandle GetClassOrValueTypeHandle(IRuntimeTypeSystem rts, DebuggerIPCE_BasicTypeData* pData) { ulong vmTh = ReadLittleEndian(pData->vmTypeHandle); if (vmTh != 0) @@ -2748,55 +2748,77 @@ private TypeHandle GetClassOrValueTypeHandle(IRuntimeTypeSystem rts, DebuggerIPC ulong vmAssembly = ReadLittleEndian(pData->vmAssembly); uint metadataToken = ReadLittleEndian(pData->metadataToken); - return LookupTypeDefOrRefInAssembly(vmAssembly, metadataToken); + return LookupTypeDefOrRefInAssembly(rts, vmAssembly, metadataToken); } - private TypeHandle GetExactArrayTypeHandle(IRuntimeTypeSystem rts, DebuggerIPCE_ExpandedTypeData* pTopLevel, ArgInfoList* pArgInfo) + private ITypeHandle LookupTypeDefOrRefInAssembly(IRuntimeTypeSystem rts, ulong vmAssembly, uint metadataToken) + { + Contracts.ILoader loader = _target.Contracts.Loader; + Contracts.ModuleHandle moduleHandle = loader.GetModuleHandleFromAssemblyPtr(new TargetPointer(vmAssembly)); + Contracts.ModuleLookupTables lookupTables = loader.GetLookupTables(moduleHandle); + TargetPointer mt; + switch ((EcmaMetadataUtils.TokenType)(metadataToken & EcmaMetadataUtils.TokenTypeMask)) + { + case EcmaMetadataUtils.TokenType.mdtTypeDef: + mt = loader.GetModuleLookupMapElement(lookupTables.TypeDefToMethodTable, metadataToken, out _); + break; + case EcmaMetadataUtils.TokenType.mdtTypeRef: + mt = loader.GetModuleLookupMapElement(lookupTables.TypeRefToMethodTable, metadataToken, out _); + break; + default: + throw Marshal.GetExceptionForHR(CorDbgHResults.CORDBG_E_CLASS_NOT_LOADED)!; + } + if (mt == TargetPointer.Null) + throw Marshal.GetExceptionForHR(CorDbgHResults.CORDBG_E_CLASS_NOT_LOADED)!; + return rts.GetTypeHandle(mt); + } + + private ITypeHandle GetExactArrayTypeHandle(IRuntimeTypeSystem rts, DebuggerIPCE_ExpandedTypeData* pTopLevel, ArgInfoList* pArgInfo) { if (pArgInfo->m_nEntries != 1) throw new ArgumentException($"Array type with arg count: {pArgInfo->m_nEntries}"); - TypeHandle elementType = BasicTypeInfoToTypeHandle(rts, &pArgInfo->m_pList[0]); + ITypeHandle elementType = BasicTypeInfoToTypeHandle(rts, &pArgInfo->m_pList[0]); CorElementType et = (CorElementType)ReadLittleEndian(pTopLevel->elementType); int rank = (int)ReadLittleEndian(pTopLevel->ArrayTypeData_arrayRank); - return rts.GetConstructedType(elementType, et, rank, ImmutableArray.Empty); + return rts.GetConstructedType(elementType, et, rank, ImmutableArray.Empty); } - private TypeHandle GetExactPtrOrByRefTypeHandle(IRuntimeTypeSystem rts, DebuggerIPCE_ExpandedTypeData* pTopLevel, ArgInfoList* pArgInfo) + private ITypeHandle GetExactPtrOrByRefTypeHandle(IRuntimeTypeSystem rts, DebuggerIPCE_ExpandedTypeData* pTopLevel, ArgInfoList* pArgInfo) { if (pArgInfo->m_nEntries != 1) throw new ArgumentException($"Pointer or byref type with arg count: {pArgInfo->m_nEntries}"); - TypeHandle referent = BasicTypeInfoToTypeHandle(rts, &pArgInfo->m_pList[0]); + ITypeHandle referent = BasicTypeInfoToTypeHandle(rts, &pArgInfo->m_pList[0]); CorElementType et = (CorElementType)ReadLittleEndian(pTopLevel->elementType); - return rts.GetConstructedType(referent, et, 0, ImmutableArray.Empty); + return rts.GetConstructedType(referent, et, 0, ImmutableArray.Empty); } - private TypeHandle GetExactClassTypeHandle(IRuntimeTypeSystem rts, DebuggerIPCE_ExpandedTypeData* pTopLevel, ArgInfoList* pArgInfo) + private ITypeHandle GetExactClassTypeHandle(IRuntimeTypeSystem rts, DebuggerIPCE_ExpandedTypeData* pTopLevel, ArgInfoList* pArgInfo) { ulong vmAssembly = ReadLittleEndian(pTopLevel->ClassTypeData_vmAssembly); uint metadataToken = ReadLittleEndian(pTopLevel->ClassTypeData_metadataToken); - TypeHandle typeConstructor = LookupTypeDefOrRefInAssembly(vmAssembly, metadataToken); + ITypeHandle typeConstructor = LookupTypeDefOrRefInAssembly(rts, vmAssembly, metadataToken); int argCount = pArgInfo->m_nEntries; if (argCount == 0) return typeConstructor; - ImmutableArray.Builder builder = ImmutableArray.CreateBuilder(argCount); + ImmutableArray.Builder builder = ImmutableArray.CreateBuilder(argCount); for (int i = 0; i < argCount; i++) builder.Add(BasicTypeInfoToTypeHandle(rts, &pArgInfo->m_pList[i])); return rts.GetConstructedType(typeConstructor, CorElementType.GenericInst, 0, builder.MoveToImmutable()); } - private TypeHandle GetExactFnPtrTypeHandle(IRuntimeTypeSystem rts, ArgInfoList* pArgInfo) + private ITypeHandle GetExactFnPtrTypeHandle(IRuntimeTypeSystem rts, ArgInfoList* pArgInfo) { int argCount = pArgInfo->m_nEntries; - ImmutableArray.Builder builder = ImmutableArray.CreateBuilder(argCount); + ImmutableArray.Builder builder = ImmutableArray.CreateBuilder(argCount); for (int i = 0; i < argCount; i++) builder.Add(BasicTypeInfoToTypeHandle(rts, &pArgInfo->m_pList[i])); // Non-default calling conventions are not supported. // Currently passes callConv=0 to match native DAC. - return rts.GetConstructedType(default, CorElementType.FnPtr, 0, builder.MoveToImmutable()); + return rts.GetConstructedType(ITypeHandle.Null, CorElementType.FnPtr, 0, builder.MoveToImmutable()); } public int EnumerateMethodDescParams(ulong vmMethodDesc, ulong genericsToken, uint* pcGenericClassTypeParams, @@ -2819,13 +2841,13 @@ public int EnumerateMethodDescParams(ulong vmMethodDesc, ulong genericsToken, ui *pcGenericClassTypeParams = 0; IRuntimeTypeSystem rts = _target.Contracts.RuntimeTypeSystem; Contracts.MethodDescHandle pRepMethod = rts.GetMethodDescHandle(vmMethodDesc); - TypeHandle thRepMt = rts.GetTypeHandle(rts.GetMethodTable(pRepMethod)); + ITypeHandle thRepMt = rts.GetTypeHandle(rts.GetMethodTable(pRepMethod)); // Try to resolve exact instantiations using the generics token. Fall back // to canonical when the token is unavailable, the method isn't shared, or any // resolution step fails (analogous to native's SanityCheck path). Contracts.MethodDescHandle pSpecificMethod = pRepMethod; - TypeHandle thSpecificClass = thRepMt; + ITypeHandle thSpecificClass = thRepMt; bool isExact = false; GenericContextLoc ctxLoc = rts.GetGenericContextLoc(pRepMethod); @@ -2854,8 +2876,8 @@ public int EnumerateMethodDescParams(ulong vmMethodDesc, ulong genericsToken, ui { // AcquiresInstMethodTableFromThis: token is some MethodTable*; it may be a // subclass, so walk the parent chain to find the exact declaring class. - TypeHandle thFromThis = rts.GetTypeHandle(new TargetPointer(genericsToken)); - TypeHandle thMatch = GetMethodTableMatchingParentClass(rts, thFromThis, thRepMt); + ITypeHandle thFromThis = rts.GetTypeHandle(new TargetPointer(genericsToken)); + ITypeHandle thMatch = GetMethodTableMatchingParentClass(rts, thFromThis, thRepMt); if (!thMatch.IsNull) { thSpecificClass = thMatch; @@ -2878,19 +2900,19 @@ public int EnumerateMethodDescParams(ulong vmMethodDesc, ulong genericsToken, ui // Project the specific class onto the method's declaring class to get the class instantiation. TargetPointer specMethodMtPtr = rts.GetMethodTable(pSpecificMethod); - TypeHandle thSpecMethodMt = rts.GetTypeHandle(specMethodMtPtr); - TypeHandle thMatchingParent = GetMethodTableMatchingParentClass(rts, thSpecificClass, thSpecMethodMt); - ReadOnlySpan classInst = thMatchingParent.IsNull - ? ReadOnlySpan.Empty + ITypeHandle thSpecMethodMt = rts.GetTypeHandle(specMethodMtPtr); + ITypeHandle thMatchingParent = GetMethodTableMatchingParentClass(rts, thSpecificClass, thSpecMethodMt); + ITypeHandle[] classInst = thMatchingParent.IsNull + ? Array.Empty() : rts.GetInstantiation(thMatchingParent); - ReadOnlySpan methodInst = rts.GetGenericMethodInstantiation(pSpecificMethod); + ITypeHandle[] methodInst = rts.GetGenericMethodInstantiation(pSpecificMethod); cClassParams = (uint)classInst.Length; *pcGenericClassTypeParams = cClassParams; - // Resolve the System.__Canon TypeHandle for per-parameter fallback. + // Resolve the System.__Canon ITypeHandle for per-parameter fallback. TargetPointer canonMtPtr = rts.GetWellKnownMethodTable(WellKnownMethodTable.Canon); - TypeHandle thCanon = rts.GetTypeHandle(canonMtPtr); + ITypeHandle thCanon = rts.GetTypeHandle(canonMtPtr); DebuggerIPCE_ExpandedTypeData entry; for (int i = 0; i < classInst.Length; i++) @@ -3106,15 +3128,15 @@ public int GetEnCHangingFieldInfo(EnCHangingFieldInfo* pEnCFieldInfo, FieldData* return hr; } - internal TypeHandle LookupTypeDefOrRefInAssembly(ulong vmAssembly, uint metadataToken) + internal ITypeHandle LookupTypeDefOrRefInAssembly(ulong vmAssembly, uint metadataToken) { - TypeHandle th = TryLookupTypeDefOrRefInAssembly(vmAssembly, metadataToken); + ITypeHandle th = TryLookupTypeDefOrRefInAssembly(vmAssembly, metadataToken); if (th.IsNull) throw Marshal.GetExceptionForHR(CorDbgHResults.CORDBG_E_CLASS_NOT_LOADED)!; return th; } - internal TypeHandle TryLookupTypeDefOrRefInAssembly(ulong vmAssembly, uint metadataToken) + internal ITypeHandle TryLookupTypeDefOrRefInAssembly(ulong vmAssembly, uint metadataToken) { ILoader loader = _target.Contracts.Loader; IRuntimeTypeSystem rts = _target.Contracts.RuntimeTypeSystem; @@ -3130,10 +3152,10 @@ internal TypeHandle TryLookupTypeDefOrRefInAssembly(ulong vmAssembly, uint metad mt = loader.GetModuleLookupMapElement(lookupTables.TypeRefToMethodTable, metadataToken, out _); break; default: - return default; + return ITypeHandle.Null; } if (mt == TargetPointer.Null) - return default; + return ITypeHandle.Null; return rts.GetTypeHandle(mt); } @@ -3150,8 +3172,8 @@ public int EnumerateTypeHandleParams(ulong vmTypeHandle, throw new ArgumentNullException(nameof(fpCallback)); IRuntimeTypeSystem rts = _target.Contracts.RuntimeTypeSystem; - TypeHandle typeHandle = rts.GetTypeHandle(new TargetPointer(vmTypeHandle)); - ReadOnlySpan instantiation = rts.GetInstantiation(typeHandle); + ITypeHandle typeHandle = rts.GetTypeHandle(new TargetPointer(vmTypeHandle)); + ITypeHandle[] instantiation = rts.GetInstantiation(typeHandle); DebuggerIPCE_ExpandedTypeData entry; for (int i = 0; i < instantiation.Length; i++) @@ -3227,7 +3249,7 @@ public int GetSimpleType(int simpleType, uint* pMetadataToken, ulong* pVmModule) try { Contracts.IRuntimeTypeSystem rts = _target.Contracts.RuntimeTypeSystem; - Contracts.TypeHandle typeHandle = rts.GetPrimitiveType((CorElementType)simpleType); + Contracts.ITypeHandle typeHandle = rts.GetPrimitiveType((CorElementType)simpleType); if (typeHandle.IsNull) { @@ -3283,7 +3305,7 @@ public int IsExceptionObject(ulong vmObject, Interop.BOOL* pResult) break; } - TypeHandle typeHandle = rts.GetTypeHandle(parentMT); + ITypeHandle typeHandle = rts.GetTypeHandle(parentMT); parentMT = rts.GetParentMethodTable(typeHandle); } } @@ -3469,7 +3491,7 @@ public int GetTypedByRefInfo(ulong pTypedByRef, ulong* pObjRef, DebuggerIPCE_Bas { IRuntimeTypeSystem rts = _target.Contracts.RuntimeTypeSystem; TypedByRefInfo info = rts.GetTypedByRefInfo(pTypedByRef); - TypeHandle th = rts.GetTypeHandle(info.TypeHandle); + ITypeHandle th = rts.GetTypeHandle(info.TypeHandle); FillBasicTypeInfo(rts, th, out DebuggerIPCE_BasicTypeData typeData); *pTypedByRefType = typeData; *pObjRef = info.Data.Value; @@ -3507,7 +3529,7 @@ public int GetStringData(ulong objectAddress, uint* pLength, uint* pOffsetToStri { IRuntimeTypeSystem rts = _target.Contracts.RuntimeTypeSystem; TargetPointer mtAddr = _target.Contracts.Object.GetMethodTableAddress(objectAddress); - TypeHandle th = rts.GetTypeHandle(mtAddr); + ITypeHandle th = rts.GetTypeHandle(mtAddr); if (!rts.IsString(th)) { throw Marshal.GetExceptionForHR(CorDbgHResults.CORDBG_E_TARGET_INCONSISTENT)!; @@ -3546,7 +3568,7 @@ public int GetArrayData(ulong objectAddress, Interop.BOOL* pIsValidArray, DacDbi IObject objectContract = _target.Contracts.Object; IRuntimeTypeSystem rts = _target.Contracts.RuntimeTypeSystem; TargetPointer mt = objectContract.GetMethodTableAddress(objectAddress); - TypeHandle th = rts.GetTypeHandle(mt); + ITypeHandle th = rts.GetTypeHandle(mt); if (rts.IsArray(th, out uint rank)) { TargetPointer dataStart = objectContract.GetArrayData(objectAddress, out uint numComponents, out TargetPointer boundsStart, out TargetPointer lowerBounds); @@ -3609,7 +3631,7 @@ public int GetBasicObjectInfo(ulong objectAddress, Interop.BOOL* pIsValidRef, ui *pObjTypeData = default; IRuntimeTypeSystem rts = _target.Contracts.RuntimeTypeSystem; // verify the object reference is readable and has a valid MethodTable - TypeHandle th = default; + ITypeHandle th = ITypeHandle.Null; try { TargetPointer mt = _target.Contracts.Object.GetMethodTableAddress(objectAddress); @@ -4151,7 +4173,7 @@ public int IsValidObject(ulong obj, Interop.BOOL* pResult) { IRuntimeTypeSystem rts = _target.Contracts.RuntimeTypeSystem; TargetPointer mt = _target.Contracts.Object.GetMethodTableAddress(new TargetPointer(obj)); - TypeHandle th = rts.GetTypeHandle(mt); + ITypeHandle th = rts.GetTypeHandle(mt); TargetPointer canonMT = rts.GetCanonicalMethodTable(th); if (mt == canonMT) @@ -4161,7 +4183,7 @@ public int IsValidObject(ulong obj, Interop.BOOL* pResult) else if (!rts.IsCanonicalMethodTable(th) || rts.IsContinuationWithoutMetadata(th)) { TargetPointer cls = rts.GetClassPointer(th); - TypeHandle canonTh = rts.GetTypeHandle(canonMT); + ITypeHandle canonTh = rts.GetTypeHandle(canonMT); TargetPointer canonCls = rts.GetClassPointer(canonTh); if (canonCls == cls) isValid = Interop.BOOL.TRUE; @@ -4275,7 +4297,7 @@ public int GetObjectFields(ulong id, uint celt, COR_FIELD* layout, uint* pceltFe throw Marshal.GetExceptionForHR(CorDbgHResults.CORDBG_E_CLASS_NOT_LOADED)!; IRuntimeTypeSystem rts = _target.Contracts.RuntimeTypeSystem; - TypeHandle typeHandle = rts.GetTypeHandle(new TargetPointer(id)); + ITypeHandle typeHandle = rts.GetTypeHandle(new TargetPointer(id)); if (rts.IsTypeDesc(typeHandle)) throw new ArgumentException("TypeDescs are not supported", nameof(id)); @@ -4287,7 +4309,7 @@ public int GetObjectFields(ulong id, uint celt, COR_FIELD* layout, uint* pceltFe TargetPointer parentMT = rts.GetParentMethodTable(typeHandle); if (parentMT != TargetPointer.Null) { - TypeHandle parentHandle = rts.GetTypeHandle(parentMT); + ITypeHandle parentHandle = rts.GetTypeHandle(parentMT); cFields -= rts.GetNumInstanceFields(parentHandle); } @@ -4328,7 +4350,7 @@ public int GetObjectFields(ulong id, uint celt, COR_FIELD* layout, uint* pceltFe // Resolve metadata for this field's enclosing class (for offset lookup and // signature decoding context). TargetPointer enclosingMT = rts.GetMTOfEnclosingClass(fieldDescPtr); - TypeHandle enclosingTypeHandle = rts.GetTypeHandle(enclosingMT); + ITypeHandle enclosingTypeHandle = rts.GetTypeHandle(enclosingMT); TargetPointer enclosingModulePtr = rts.GetModule(enclosingTypeHandle); Contracts.ModuleHandle enclosingModuleHandle = _target.Contracts.Loader.GetModuleHandleFromModulePtr(enclosingModulePtr); MetadataReader enclosingMdReader = ecmaMetadataContract.GetMetadata(enclosingModuleHandle)!; @@ -4340,10 +4362,10 @@ public int GetObjectFields(ulong id, uint celt, COR_FIELD* layout, uint* pceltFe // Resolve the field's type. If we cannot decode the signature (e.g. corrupt // metadata or a type that cannot be loaded), zero out the type id and // fieldType, matching native DAC behavior when LookupFieldTypeHandle returns - // a null TypeHandle. + // a null ITypeHandle. try { - TypeHandle fieldTypeHandle = signature.DecodeFieldSignature(fieldDef.Signature, enclosingModuleHandle, enclosingTypeHandle); + ITypeHandle fieldTypeHandle = signature.DecodeFieldSignature(fieldDef.Signature, enclosingModuleHandle, enclosingTypeHandle); if (fieldTypeHandle.IsNull) { corField->id = default; @@ -4361,7 +4383,7 @@ public int GetObjectFields(ulong id, uint celt, COR_FIELD* layout, uint* pceltFe else { // - Pointer/FnPtr typedescs report ELEMENT_TYPE_U's MethodTable. - TypeHandle mtHandle = (signatureType == CorElementType.Ptr || signatureType == CorElementType.FnPtr) + ITypeHandle mtHandle = (signatureType == CorElementType.Ptr || signatureType == CorElementType.FnPtr) ? rts.GetPrimitiveType(CorElementType.U) : fieldTypeHandle; @@ -4372,7 +4394,7 @@ public int GetObjectFields(ulong id, uint celt, COR_FIELD* layout, uint* pceltFe } catch (System.Exception) { - // Field type could not be resolved - mirror native's null-TypeHandle path. + // Field type could not be resolved - mirror native's null-ITypeHandle path. corField->id = default; corField->fieldType = 0; } @@ -4426,7 +4448,7 @@ public int GetTypeLayout(ulong id, COR_TYPE_LAYOUT* pLayout) throw Marshal.GetExceptionForHR(CorDbgHResults.CORDBG_E_CLASS_NOT_LOADED)!; IRuntimeTypeSystem rts = _target.Contracts.RuntimeTypeSystem; - TypeHandle typeHandle = rts.GetTypeHandle(new TargetPointer((ulong)id)); + ITypeHandle typeHandle = rts.GetTypeHandle(new TargetPointer((ulong)id)); TargetPointer parentMT = rts.GetParentMethodTable(typeHandle); pLayout->parentID.token1 = parentMT.Value; @@ -4435,7 +4457,7 @@ public int GetTypeLayout(ulong id, COR_TYPE_LAYOUT* pLayout) ushort numInstanceFields = rts.GetNumInstanceFields(typeHandle); if (parentMT != TargetPointer.Null) { - TypeHandle parentHandle = rts.GetTypeHandle(parentMT); + ITypeHandle parentHandle = rts.GetTypeHandle(parentMT); numInstanceFields -= rts.GetNumInstanceFields(parentHandle); } pLayout->numFields = numInstanceFields; @@ -4482,12 +4504,12 @@ public int GetArrayLayout(ulong id, COR_ARRAY_LAYOUT* pLayout) if (id == 0) throw Marshal.GetExceptionForHR(CorDbgHResults.CORDBG_E_CLASS_NOT_LOADED)!; IRuntimeTypeSystem rts = _target.Contracts.RuntimeTypeSystem; - TypeHandle arrayOrStringTypeHandle = rts.GetTypeHandle(new TargetPointer(id)); + ITypeHandle arrayOrStringTypeHandle = rts.GetTypeHandle(new TargetPointer(id)); uint pointerSize = (uint)_target.PointerSize; if (rts.IsString(arrayOrStringTypeHandle)) { - TypeHandle charTypeHandle = rts.GetPrimitiveType(CorElementType.Char); + ITypeHandle charTypeHandle = rts.GetPrimitiveType(CorElementType.Char); pLayout->componentID.token1 = charTypeHandle.Address.Value; pLayout->componentID.token2 = 0; pLayout->componentType = CorElementType.Char; @@ -4503,7 +4525,7 @@ public int GetArrayLayout(ulong id, COR_ARRAY_LAYOUT* pLayout) if (!rts.IsArray(arrayOrStringTypeHandle, out uint rank)) throw Marshal.GetExceptionForHR(HResults.E_INVALIDARG)!; - TypeHandle componentTypeHandle = rts.GetTypeParam(arrayOrStringTypeHandle); + ITypeHandle componentTypeHandle = rts.GetTypeParam(arrayOrStringTypeHandle); CorElementType componentType = rts.IsString(componentTypeHandle) ? CorElementType.String : rts.GetInternalCorElementType(componentTypeHandle); pLayout->componentID.token1 = componentTypeHandle.Address.Value; pLayout->componentID.token2 = 0; @@ -4964,7 +4986,7 @@ public int GetDelegateFunctionData(ulong delegateObject, ulong* ppFunctionAssemb *pMethodDef = rts.GetMethodToken(mdHandle); TargetPointer mtPtr = rts.GetMethodTable(mdHandle); - TypeHandle typeHandle = rts.GetTypeHandle(mtPtr); + ITypeHandle typeHandle = rts.GetTypeHandle(mtPtr); TargetPointer modulePtr = rts.GetModule(typeHandle); Contracts.ModuleHandle moduleHandle = _target.Contracts.Loader.GetModuleHandleFromModulePtr(modulePtr); *ppFunctionAssembly = _target.Contracts.Loader.GetAssembly(moduleHandle).Value; @@ -5029,7 +5051,7 @@ private bool IsDelegateHelper(ulong vmObject) { TargetPointer mt = _target.Contracts.Object.GetMethodTableAddress(vmObject); IRuntimeTypeSystem rts = _target.Contracts.RuntimeTypeSystem; - TypeHandle typeHandle = rts.GetTypeHandle(mt); + ITypeHandle typeHandle = rts.GetTypeHandle(mt); return rts.IsDelegate(typeHandle); } @@ -5314,7 +5336,7 @@ public int GetGenericArgTokenIndex(ulong vmMethod, uint* pIndex) } // Fills a DebuggerIPCE_ExpandedTypeData entry for a single type parameter, falling back to System.__Canon on failure. - private void FillExpandedTypeDataWithCanonFallback(IRuntimeTypeSystem rts, TypeHandle typeHandle, TypeHandle thCanon, DebuggerIPCE_ExpandedTypeData* pTypeInfo) + private void FillExpandedTypeDataWithCanonFallback(IRuntimeTypeSystem rts, ITypeHandle typeHandle, ITypeHandle thCanon, DebuggerIPCE_ExpandedTypeData* pTypeInfo) { try { @@ -5328,7 +5350,7 @@ private void FillExpandedTypeDataWithCanonFallback(IRuntimeTypeSystem rts, TypeH // True if `a` and `b` share the same non-zero TypeDef RID and Module. // Mirrors native MethodTable::HasSameTypeDefAs. - private static bool HasSameTypeDefAs(IRuntimeTypeSystem rts, TypeHandle a, TypeHandle b) + private static bool HasSameTypeDefAs(IRuntimeTypeSystem rts, ITypeHandle a, ITypeHandle b) { if (a.Address == b.Address) return true; @@ -5342,9 +5364,9 @@ private static bool HasSameTypeDefAs(IRuntimeTypeSystem rts, TypeHandle a, TypeH // Walks the parent chain of `start` and returns the first MethodTable whose TypeDef matches `parent`, // or default if no match is found. The walk is bounded by a hard iteration cap to defend against // cycles observed in corrupt dumps. Mirrors native MethodTable::GetMethodTableMatchingParentClass. - private static TypeHandle GetMethodTableMatchingParentClass(IRuntimeTypeSystem rts, TypeHandle start, TypeHandle parent) + private static ITypeHandle GetMethodTableMatchingParentClass(IRuntimeTypeSystem rts, ITypeHandle start, ITypeHandle parent) { - TypeHandle current = start; + ITypeHandle current = start; TargetPointer prev = TargetPointer.Null; for (int i = 0; i < 1000 && !current.IsNull; i++) { @@ -5356,11 +5378,11 @@ private static TypeHandle GetMethodTableMatchingParentClass(IRuntimeTypeSystem r prev = current.Address; current = rts.GetTypeHandle(next); } - return default; + return ITypeHandle.Null; } // Shared core implementation for TypeHandleToExpandedTypeInfo and GetObjectExpandedTypeInfo. - private void TypeHandleToExpandedTypeInfoImpl(IRuntimeTypeSystem rts, AreValueTypesBoxed boxed, TypeHandle typeHandle, DebuggerIPCE_ExpandedTypeData* pTypeInfo) + private void TypeHandleToExpandedTypeInfoImpl(IRuntimeTypeSystem rts, AreValueTypesBoxed boxed, ITypeHandle typeHandle, DebuggerIPCE_ExpandedTypeData* pTypeInfo) { *pTypeInfo = default; CorElementType elementType = GetElementType(rts, typeHandle); @@ -5407,7 +5429,7 @@ private void TypeHandleToExpandedTypeInfoImpl(IRuntimeTypeSystem rts, AreValueTy // Determines the CorElementType for a type handle, mapping System.Object and System.String // to their specific element types (the runtime's GetSignatureCorElementType returns E_T_CLASS // for both Object and String). - private static CorElementType GetElementType(IRuntimeTypeSystem rts, TypeHandle typeHandle) + private static CorElementType GetElementType(IRuntimeTypeSystem rts, ITypeHandle typeHandle) { if (typeHandle.IsNull) return CorElementType.Void; @@ -5421,9 +5443,9 @@ private static CorElementType GetElementType(IRuntimeTypeSystem rts, TypeHandle return rts.GetSignatureCorElementType(typeHandle); } - // Mirrors native TypeHandle::UpCastTypeIfNeeded — for continuation types, returns the + // Mirrors native ITypeHandle::UpCastTypeIfNeeded — for continuation types, returns the // parent (continuation base) type handle instead. - private static TypeHandle UpCastTypeIfNeeded(IRuntimeTypeSystem rts, TypeHandle typeHandle) + private static ITypeHandle UpCastTypeIfNeeded(IRuntimeTypeSystem rts, ITypeHandle typeHandle) { if (rts.IsContinuationWithoutMetadata(typeHandle)) { @@ -5436,17 +5458,17 @@ private static TypeHandle UpCastTypeIfNeeded(IRuntimeTypeSystem rts, TypeHandle // Fills ArrayTypeData for E_T_ARRAY and E_T_SZARRAY. // Mirrors native DacDbiInterfaceImpl::GetArrayTypeInfo. - private void FillArrayTypeInfo(IRuntimeTypeSystem rts, TypeHandle typeHandle, DebuggerIPCE_ExpandedTypeData* pTypeInfo) + private void FillArrayTypeInfo(IRuntimeTypeSystem rts, ITypeHandle typeHandle, DebuggerIPCE_ExpandedTypeData* pTypeInfo) { Debug.Assert(rts.IsArray(typeHandle, out _)); rts.IsArray(typeHandle, out uint rank); WriteLittleEndian(ref pTypeInfo->ArrayTypeData_arrayRank, rank); - TypeHandle elemTypeHandle = rts.GetTypeParam(typeHandle); + ITypeHandle elemTypeHandle = rts.GetTypeParam(typeHandle); FillBasicTypeInfo(rts, elemTypeHandle, out pTypeInfo->ArrayTypeData_arrayTypeArg); } // Fills UnaryTypeData for E_T_PTR and E_T_BYREF (or ClassTypeData if AllBoxed). - private void FillPtrTypeInfo(IRuntimeTypeSystem rts, AreValueTypesBoxed boxed, TypeHandle typeHandle, DebuggerIPCE_ExpandedTypeData* pTypeInfo) + private void FillPtrTypeInfo(IRuntimeTypeSystem rts, AreValueTypesBoxed boxed, ITypeHandle typeHandle, DebuggerIPCE_ExpandedTypeData* pTypeInfo) { if (boxed == AreValueTypesBoxed.AllBoxed) { @@ -5454,13 +5476,13 @@ private void FillPtrTypeInfo(IRuntimeTypeSystem rts, AreValueTypesBoxed boxed, T } else { - TypeHandle paramTypeHandle = rts.GetTypeParam(typeHandle); + ITypeHandle paramTypeHandle = rts.GetTypeParam(typeHandle); FillBasicTypeInfo(rts, paramTypeHandle, out pTypeInfo->UnaryTypeData_unaryTypeArg); } } // Fills ClassTypeData for E_T_CLASS and E_T_VALUETYPE. - private void FillClassTypeInfo(IRuntimeTypeSystem rts, TypeHandle typeHandle, DebuggerIPCE_ExpandedTypeData* pTypeInfo) + private void FillClassTypeInfo(IRuntimeTypeSystem rts, ITypeHandle typeHandle, DebuggerIPCE_ExpandedTypeData* pTypeInfo) { typeHandle = UpCastTypeIfNeeded(rts, typeHandle); @@ -5468,7 +5490,7 @@ private void FillClassTypeInfo(IRuntimeTypeSystem rts, TypeHandle typeHandle, De Contracts.ILoader loader = _target.Contracts.Loader; Contracts.ModuleHandle moduleHandle = loader.GetModuleHandleFromModulePtr(modulePtr); - ReadOnlySpan instantiation = rts.GetInstantiation(typeHandle); + ITypeHandle[] instantiation = rts.GetInstantiation(typeHandle); if (instantiation.Length > 0) { // Generic instantiation — set the type handle so the debugger can fetch type arguments @@ -5483,7 +5505,7 @@ private void FillClassTypeInfo(IRuntimeTypeSystem rts, TypeHandle typeHandle, De } // Fills NaryTypeData for E_T_FNPTR (or ClassTypeData if AllBoxed). - private void FillFnPtrTypeInfo(IRuntimeTypeSystem rts, AreValueTypesBoxed boxed, TypeHandle typeHandle, DebuggerIPCE_ExpandedTypeData* pTypeInfo) + private void FillFnPtrTypeInfo(IRuntimeTypeSystem rts, AreValueTypesBoxed boxed, ITypeHandle typeHandle, DebuggerIPCE_ExpandedTypeData* pTypeInfo) { if (boxed == AreValueTypesBoxed.AllBoxed) { @@ -5497,8 +5519,8 @@ private void FillFnPtrTypeInfo(IRuntimeTypeSystem rts, AreValueTypesBoxed boxed, // Fills a DebuggerIPCE_BasicTypeData for a type handle — used for array element types // and ptr/byref referent types. Exposed as internal so tests can build the ArgInfoList - // needed to round-trip a TypeHandle through GetExactTypeHandle. - internal void FillBasicTypeInfo(IRuntimeTypeSystem rts, TypeHandle typeHandle, out DebuggerIPCE_BasicTypeData typeInfo) + // needed to round-trip a ITypeHandle through GetExactTypeHandle. + internal void FillBasicTypeInfo(IRuntimeTypeSystem rts, ITypeHandle typeHandle, out DebuggerIPCE_BasicTypeData typeInfo) { typeInfo = default; CorElementType elementType = GetElementType(rts, typeHandle); @@ -5524,7 +5546,7 @@ internal void FillBasicTypeInfo(IRuntimeTypeSystem rts, TypeHandle typeHandle, o Contracts.ILoader loader = _target.Contracts.Loader; Contracts.ModuleHandle moduleHandle = loader.GetModuleHandleFromModulePtr(modulePtr); - ReadOnlySpan instantiation = rts.GetInstantiation(typeHandle); + ITypeHandle[] instantiation = rts.GetInstantiation(typeHandle); if (instantiation.Length > 0) { WriteLittleEndian(ref typeInfo.vmTypeHandle, typeHandle.Address.Value); diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/Dbi/Helpers/HeapWalk.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/Dbi/Helpers/HeapWalk.cs index 3c039ee0148fb4..43650bc4d8d605 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/Dbi/Helpers/HeapWalk.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/Dbi/Helpers/HeapWalk.cs @@ -124,7 +124,7 @@ private bool TryGetObjectSize(TargetPointer objAddr, TargetPointer mt, out ulong size = 0; try { - TypeHandle handle = _rts.GetTypeHandle(mt); + ITypeHandle handle = _rts.GetTypeHandle(mt); ulong baseSize = _rts.GetBaseSize(handle); uint componentSize = _rts.GetComponentSize(handle); uint numComponentsOffset = 0; diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/Dbi/IDacDbiInterface.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/Dbi/IDacDbiInterface.cs index 5cd7ef6fcde607..f7c723cf2b8bbc 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/Dbi/IDacDbiInterface.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/Dbi/IDacDbiInterface.cs @@ -278,7 +278,7 @@ public struct DebuggerIPCE_BasicTypeData [FieldOffset(0)] public int elementType; // Portable [FieldOffset(4)] public uint metadataToken; // Portable [FieldOffset(8)] public ulong vmAssembly; // VMPTR_Assembly (Portable) - [FieldOffset(16)] public ulong vmTypeHandle; // VMPTR_TypeHandle (Portable) + [FieldOffset(16)] public ulong vmTypeHandle; // VMPTR_ITypeHandle (Portable) } [StructLayout(LayoutKind.Sequential)] @@ -301,7 +301,7 @@ public struct DebuggerIPCE_ExpandedTypeData // ClassTypeData (used for E_T_CLASS, E_T_VALUETYPE) [FieldOffset(8)] public uint ClassTypeData_metadataToken; // Portable [FieldOffset(16)] public ulong ClassTypeData_vmAssembly; // VMPTR_Assembly - [FieldOffset(24)] public ulong ClassTypeData_typeHandle; // VMPTR_TypeHandle + [FieldOffset(24)] public ulong ClassTypeData_typeHandle; // VMPTR_ITypeHandle // UnaryTypeData (used for E_T_PTR, E_T_BYREF) — overlaps union at offset 8 [FieldOffset(8)] public DebuggerIPCE_BasicTypeData UnaryTypeData_unaryTypeArg; @@ -311,7 +311,7 @@ public struct DebuggerIPCE_ExpandedTypeData [FieldOffset(32)] public uint ArrayTypeData_arrayRank; // Portable // NaryTypeData (used for E_T_FNPTR) — overlaps union at offset 8 - [FieldOffset(8)] public ulong NaryTypeData_typeHandle; // VMPTR_TypeHandle + [FieldOffset(8)] public ulong NaryTypeData_typeHandle; // VMPTR_ITypeHandle } [StructLayout(LayoutKind.Sequential)] diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/Dbi/TypeDataWalk.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/Dbi/TypeDataWalk.cs index 706073acec0a2c..410b629413e748 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/Dbi/TypeDataWalk.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/Dbi/TypeDataWalk.cs @@ -11,7 +11,7 @@ namespace Microsoft.Diagnostics.DataContractReader.Legacy; // Port of native DacDbiInterfaceImpl::TypeDataWalk // // Walks the flattened DebuggerIPCE_TypeArgData[] tree that the right side built in -// CordbType::GatherTypeData and produces a TypeHandle for the loaded representation +// CordbType::GatherTypeData and produces a ITypeHandle for the loaded representation // (exact, or canonical when generic code-sharing collapses reference type-args to // System.__Canon and value type-args to their canonical form). // @@ -19,11 +19,11 @@ internal unsafe ref struct TypeDataWalk { private readonly Target _target; private readonly IRuntimeTypeSystem _rts; - private readonly TypeHandle _canonTh; + private readonly ITypeHandle _canonTh; private DebuggerIPCE_TypeArgData* _pCurrent; private uint _remaining; - public TypeDataWalk(Target target, IRuntimeTypeSystem rts, TypeHandle canonTh, DebuggerIPCE_TypeArgData* pData, uint nData) + public TypeDataWalk(Target target, IRuntimeTypeSystem rts, ITypeHandle canonTh, DebuggerIPCE_TypeArgData* pData, uint nData) { _target = target; _rts = rts; @@ -55,11 +55,11 @@ private void Skip() } } - public TypeHandle ReadLoadedTypeHandle() + public ITypeHandle ReadLoadedTypeHandle() { DebuggerIPCE_TypeArgData* p = ReadOne(); if (p == null) - return default; + return ITypeHandle.Null; CorElementType et = (CorElementType)DacDbiImpl.ReadLittleEndian(p->data.elementType); switch (et) @@ -89,11 +89,11 @@ public TypeHandle ReadLoadedTypeHandle() } // Read a single type argument in canonicalization-aware fashion. - private TypeHandle ReadLoadedTypeArg() + private ITypeHandle ReadLoadedTypeArg() { DebuggerIPCE_TypeArgData* p = ReadOne(); if (p == null) - return default; + return ITypeHandle.Null; CorElementType et = (CorElementType)DacDbiImpl.ReadLittleEndian(p->data.elementType); switch (et) @@ -114,59 +114,59 @@ private TypeHandle ReadLoadedTypeArg() } // Read an instantiation and ask the runtime-type-system for the loaded handle. - private TypeHandle ReadLoadedInstantiation(ulong vmAssembly, uint metadataToken, uint nTypeArgs) + private ITypeHandle ReadLoadedInstantiation(ulong vmAssembly, uint metadataToken, uint nTypeArgs) { - TypeHandle typeDef = TryLookupTypeDefOrRefInAssembly(vmAssembly, metadataToken); + ITypeHandle typeDef = TryLookupTypeDefOrRefInAssembly(vmAssembly, metadataToken); if (typeDef.IsNull) - return default; + return ITypeHandle.Null; if (nTypeArgs == 0) return typeDef; - ImmutableArray.Builder builder = ImmutableArray.CreateBuilder((int)nTypeArgs); + ImmutableArray.Builder builder = ImmutableArray.CreateBuilder((int)nTypeArgs); bool allOK = true; for (uint i = 0; i < nTypeArgs; i++) { - TypeHandle th = ReadLoadedTypeArg(); + ITypeHandle th = ReadLoadedTypeArg(); allOK &= !th.IsNull; builder.Add(th); } if (!allOK) - return default; + return ITypeHandle.Null; return _rts.GetConstructedType(typeDef, CorElementType.GenericInst, 0, builder.MoveToImmutable()); } - private TypeHandle ArrayTypeArg(DebuggerIPCE_TypeArgData* pInfo) + private ITypeHandle ArrayTypeArg(DebuggerIPCE_TypeArgData* pInfo) { - TypeHandle elem = ReadLoadedTypeArg(); + ITypeHandle elem = ReadLoadedTypeArg(); if (elem.IsNull) - return default; + return ITypeHandle.Null; CorElementType et = (CorElementType)DacDbiImpl.ReadLittleEndian(pInfo->data.elementType); int rank = (int)DacDbiImpl.ReadLittleEndian(pInfo->data.ArrayTypeData_arrayRank); - return _rts.GetConstructedType(elem, et, rank, ImmutableArray.Empty); + return _rts.GetConstructedType(elem, et, rank, ImmutableArray.Empty); } - private TypeHandle PtrOrByRefTypeArg(DebuggerIPCE_TypeArgData* pInfo) + private ITypeHandle PtrOrByRefTypeArg(DebuggerIPCE_TypeArgData* pInfo) { - TypeHandle referent = ReadLoadedTypeArg(); + ITypeHandle referent = ReadLoadedTypeArg(); if (referent.IsNull) - return default; + return ITypeHandle.Null; CorElementType et = (CorElementType)DacDbiImpl.ReadLittleEndian(pInfo->data.elementType); - return _rts.GetConstructedType(referent, et, 0, ImmutableArray.Empty); + return _rts.GetConstructedType(referent, et, 0, ImmutableArray.Empty); } // A generic reference type collapses to System.__Canon // (and its type arguments are skipped); a value-type instantiation is recursively // resolved. - private TypeHandle ClassTypeArg(DebuggerIPCE_TypeArgData* pInfo) + private ITypeHandle ClassTypeArg(DebuggerIPCE_TypeArgData* pInfo) { ulong vmAssembly = DacDbiImpl.ReadLittleEndian(pInfo->data.ClassTypeData_vmAssembly); uint metadataToken = DacDbiImpl.ReadLittleEndian(pInfo->data.ClassTypeData_metadataToken); uint numTypeArgs = DacDbiImpl.ReadLittleEndian(pInfo->numTypeArgs); CorElementType et = (CorElementType)DacDbiImpl.ReadLittleEndian(pInfo->data.elementType); - TypeHandle typeDef = TryLookupTypeDefOrRefInAssembly(vmAssembly, metadataToken); + ITypeHandle typeDef = TryLookupTypeDefOrRefInAssembly(vmAssembly, metadataToken); if ((!typeDef.IsNull && _rts.IsValueType(typeDef)) || et == CorElementType.ValueType) { @@ -180,25 +180,25 @@ private TypeHandle ClassTypeArg(DebuggerIPCE_TypeArgData* pInfo) } } - private TypeHandle FnPtrTypeArg(DebuggerIPCE_TypeArgData* pInfo) + private ITypeHandle FnPtrTypeArg(DebuggerIPCE_TypeArgData* pInfo) { uint numTypeArgs = DacDbiImpl.ReadLittleEndian(pInfo->numTypeArgs); - ImmutableArray.Builder builder = ImmutableArray.CreateBuilder((int)numTypeArgs); + ImmutableArray.Builder builder = ImmutableArray.CreateBuilder((int)numTypeArgs); bool allOK = true; for (uint i = 0; i < numTypeArgs; i++) { - TypeHandle th = ReadLoadedTypeArg(); + ITypeHandle th = ReadLoadedTypeArg(); allOK &= !th.IsNull; builder.Add(th); } if (!allOK) - return default; + return ITypeHandle.Null; // Non-default calling conventions are not supported (matches the exact-handle path). - return _rts.GetConstructedType(default, CorElementType.FnPtr, 0, builder.MoveToImmutable()); + return _rts.GetConstructedType(ITypeHandle.Null, CorElementType.FnPtr, 0, builder.MoveToImmutable()); } - private TypeHandle ObjRefOrPrimitiveTypeArg(DebuggerIPCE_TypeArgData* pInfo, CorElementType elementType) + private ITypeHandle ObjRefOrPrimitiveTypeArg(DebuggerIPCE_TypeArgData* pInfo, CorElementType elementType) { // Skip any children: they are part of a reference-typed argument that canonicalizes to __Canon. uint numTypeArgs = DacDbiImpl.ReadLittleEndian(pInfo->numTypeArgs); @@ -210,7 +210,7 @@ private TypeHandle ObjRefOrPrimitiveTypeArg(DebuggerIPCE_TypeArgData* pInfo, Cor return _rts.GetPrimitiveType(elementType); } - private TypeHandle TryLookupTypeDefOrRefInAssembly(ulong vmAssembly, uint metadataToken) + private ITypeHandle TryLookupTypeDefOrRefInAssembly(ulong vmAssembly, uint metadataToken) { ILoader loader = _target.Contracts.Loader; IRuntimeTypeSystem rts = _target.Contracts.RuntimeTypeSystem; @@ -226,10 +226,10 @@ private TypeHandle TryLookupTypeDefOrRefInAssembly(ulong vmAssembly, uint metada mt = loader.GetModuleLookupMapElement(lookupTables.TypeRefToMethodTable, metadataToken, out _); break; default: - return default; + return ITypeHandle.Null; } if (mt == TargetPointer.Null) - return default; + return ITypeHandle.Null; return rts.GetTypeHandle(mt); } } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/SOSDacImpl.IXCLRDataProcess.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/SOSDacImpl.IXCLRDataProcess.cs index 2caee9ff9583b3..e5fecafd14ab23 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/SOSDacImpl.IXCLRDataProcess.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/SOSDacImpl.IXCLRDataProcess.cs @@ -300,7 +300,7 @@ private IEnumerable IterateMethodInstantiations(Contracts.Modu } } - private IEnumerable IterateTypeParams(Contracts.ModuleHandle moduleHandle) + private IEnumerable IterateTypeParams(Contracts.ModuleHandle moduleHandle) { IEnumerable typeParams = _loader.GetAvailableTypeParams(moduleHandle); @@ -347,7 +347,7 @@ 4. Generic method on Generic type (There are N generic defining methods where N } TargetPointer mtAddr = _rts.GetMethodTable(mainMD); - TypeHandle mainMT = _rts.GetTypeHandle(mtAddr); + ITypeHandle mainMT = _rts.GetTypeHandle(mtAddr); TargetPointer mainModule = _rts.GetModule(mainMT); uint mainMTToken = _rts.GetTypeDefToken(mainMT); uint mainMDToken = _rts.GetMethodToken(mainMD); @@ -361,7 +361,7 @@ 4. Generic method on Generic type (There are N generic defining methods where N { foreach (MethodDescHandle methodDesc in IterateMethodInstantiations(moduleHandle)) { - TypeHandle methodTypeHandle = _rts.GetTypeHandle(_rts.GetMethodTable(methodDesc)); + ITypeHandle methodTypeHandle = _rts.GetTypeHandle(_rts.GetMethodTable(methodDesc)); if (mainModule != _rts.GetModule(methodTypeHandle)) continue; if (mainMDToken != _rts.GetMethodToken(methodDesc)) continue; @@ -384,7 +384,7 @@ 4. Generic method on Generic type (There are N generic defining methods where N { if (HasClassInstantiation(mainMD)) { - foreach (Contracts.TypeHandle typeParam in IterateTypeParams(moduleHandle)) + foreach (Contracts.ITypeHandle typeParam in IterateTypeParams(moduleHandle)) { uint typeParamToken = _rts.GetTypeDefToken(typeParam); @@ -398,7 +398,7 @@ 4. Generic method on Generic type (There are N generic defining methods where N if (mainModule != _rts.GetModule(typeParam)) continue; TargetPointer cmt = _rts.GetCanonicalMethodTable(typeParam); - TypeHandle cmtHandle = _rts.GetTypeHandle(cmt); + ITypeHandle cmtHandle = _rts.GetTypeHandle(cmt); TargetPointer methodDescAddr = _rts.GetMethodDescForSlot(cmtHandle, slotNum); if (methodDescAddr == TargetPointer.Null) continue; @@ -427,8 +427,8 @@ private bool HasClassInstantiation(MethodDescHandle md) IRuntimeTypeSystem rts = _target.Contracts.RuntimeTypeSystem; TargetPointer mtAddr = rts.GetMethodTable(md); - TypeHandle mt = rts.GetTypeHandle(mtAddr); - return !rts.GetInstantiation(mt).IsEmpty; + ITypeHandle mt = rts.GetTypeHandle(mtAddr); + return rts.GetInstantiation(mt).Length > 0; } private bool HasMethodInstantiation(MethodDescHandle md) @@ -436,7 +436,7 @@ private bool HasMethodInstantiation(MethodDescHandle md) IRuntimeTypeSystem rts = _target.Contracts.RuntimeTypeSystem; if (rts.IsGenericMethodDefinition(md)) return true; - return !rts.GetGenericMethodInstantiation(md).IsEmpty; + return rts.GetGenericMethodInstantiation(md).Length > 0; } } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/SOSDacImpl.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/SOSDacImpl.cs index 2112c9574ceade..610d7a3d2f4be5 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/SOSDacImpl.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/SOSDacImpl.cs @@ -1069,7 +1069,7 @@ int ISOSDacInterface.GetFieldDescData(ClrDataAddress fieldDesc, DacpFieldDescDat FieldDefinitionHandle fieldHandle = (FieldDefinitionHandle)MetadataTokens.Handle((int)token); TargetPointer enclosingMT = rtsContract.GetMTOfEnclosingClass(fieldDescTargetPtr); - TypeHandle ctx = rtsContract.GetTypeHandle(enclosingMT); + ITypeHandle ctx = rtsContract.GetTypeHandle(enclosingMT); TargetPointer modulePtr = rtsContract.GetModule(ctx); Contracts.ModuleHandle moduleHandle = _target.Contracts.Loader.GetModuleHandleFromModulePtr(modulePtr); MetadataReader mdReader = ecmaMetadataContract.GetMetadata(moduleHandle)!; @@ -1077,12 +1077,12 @@ int ISOSDacInterface.GetFieldDescData(ClrDataAddress fieldDesc, DacpFieldDescDat try { // try to completely decode the signature - TypeHandle foundTypeHandle = signatureContract.DecodeFieldSignature(fieldDef.Signature, moduleHandle, ctx); + ITypeHandle foundTypeHandle = signatureContract.DecodeFieldSignature(fieldDef.Signature, moduleHandle, ctx); // get the MT of the type // This is an implementation detail of the DAC that we replicate here to get method tables for non-MT types // that we can return to SOS for pretty-printing. - // In the future we may want to return a TypeHandle instead of a MethodTable, and modify SOS to do more complete pretty-printing. + // In the future we may want to return a ITypeHandle instead of a MethodTable, and modify SOS to do more complete pretty-printing. // DAC equivalent: src/coreclr/vm/typehandle.inl TypeHandle::GetMethodTable if (rtsContract.IsFunctionPointer(foundTypeHandle, out _, out _) || rtsContract.IsPointer(foundTypeHandle)) data->MTOfType = rtsContract.GetPrimitiveType(CorElementType.U).Address.ToClrDataAddress(_target); @@ -1094,7 +1094,7 @@ int ISOSDacInterface.GetFieldDescData(ClrDataAddress fieldDesc, DacpFieldDescDat try { // value typedescs - TypeHandle paramTypeHandle = rtsContract.GetTypeParam(foundTypeHandle); + ITypeHandle paramTypeHandle = rtsContract.GetTypeParam(foundTypeHandle); data->MTOfType = paramTypeHandle.Address.ToClrDataAddress(_target); } catch (ArgumentException) @@ -2312,7 +2312,7 @@ int ISOSDacInterface.GetMethodDescData(ClrDataAddress addr, ClrDataAddress ip, D data->MethodDescPtr = addr; TargetPointer methodTableAddr = rtsContract.GetMethodTable(methodDescHandle); data->MethodTablePtr = methodTableAddr.ToClrDataAddress(_target); - TypeHandle typeHandle = rtsContract.GetTypeHandle(methodTableAddr); + ITypeHandle typeHandle = rtsContract.GetTypeHandle(methodTableAddr); data->ModulePtr = rtsContract.GetModule(typeHandle).ToClrDataAddress(_target); // If rejit info is appropriate, get the following: @@ -2788,7 +2788,7 @@ int ISOSDacInterface.GetMethodTableData(ClrDataAddress mt, DacpMethodTableData* if (mt == 0 || data == null) throw new ArgumentException(); Contracts.IRuntimeTypeSystem contract = _target.Contracts.RuntimeTypeSystem; - Contracts.TypeHandle methodTable = contract.GetTypeHandle(mt.ToTargetPointer(_target)); + Contracts.ITypeHandle methodTable = contract.GetTypeHandle(mt.ToTargetPointer(_target)); DacpMethodTableData result = default; result.baseSize = contract.GetBaseSize(methodTable); @@ -2861,7 +2861,7 @@ int ISOSDacInterface.GetMethodTableFieldData(ClrDataAddress mt, DacpMethodTableF TargetPointer mtAddress = mt.ToTargetPointer(_target); Contracts.IRuntimeTypeSystem rtsContract = _target.Contracts.RuntimeTypeSystem; - TypeHandle typeHandle = rtsContract.GetTypeHandle(mtAddress); + ITypeHandle typeHandle = rtsContract.GetTypeHandle(mtAddress); data->FirstField = rtsContract.GetFieldDescList(typeHandle).FirstOrDefault().ToClrDataAddress(_target); data->wNumInstanceFields = rtsContract.GetNumInstanceFields(typeHandle); data->wNumStaticFields = rtsContract.GetNumStaticFields(typeHandle); @@ -2901,7 +2901,7 @@ int ISOSDacInterface.GetMethodTableForEEClass(ClrDataAddress eeClassReallyCanonM if (eeClassReallyCanonMT == 0 || value == null) throw new ArgumentException(); Contracts.IRuntimeTypeSystem contract = _target.Contracts.RuntimeTypeSystem; - Contracts.TypeHandle methodTableHandle = contract.GetTypeHandle(eeClassReallyCanonMT.ToTargetPointer(_target)); + Contracts.ITypeHandle methodTableHandle = contract.GetTypeHandle(eeClassReallyCanonMT.ToTargetPointer(_target)); *value = methodTableHandle.Address.ToClrDataAddress(_target); } catch (global::System.Exception ex) @@ -2931,7 +2931,7 @@ int ISOSDacInterface.GetMethodTableName(ClrDataAddress mt, uint count, char* mtN throw new ArgumentException(); Contracts.IRuntimeTypeSystem typeSystemContract = _target.Contracts.RuntimeTypeSystem; Contracts.ILoader loader = _target.Contracts.Loader; - Contracts.TypeHandle methodTableHandle = typeSystemContract.GetTypeHandle(mt.ToTargetPointer(_target, overrideCheck: true)); + Contracts.ITypeHandle methodTableHandle = typeSystemContract.GetTypeHandle(mt.ToTargetPointer(_target, overrideCheck: true)); if (typeSystemContract.IsFreeObjectMethodTable(methodTableHandle)) { OutputBufferHelpers.CopyStringToBuffer(mtName, count, pNeeded, "Free"); @@ -3003,7 +3003,7 @@ int ISOSDacInterface.GetMethodTableSlot(ClrDataAddress mt, uint slot, ClrDataAdd throw new ArgumentException(); TargetPointer methodTable = mt.ToTargetPointer(_target); - TypeHandle methodTableHandle = rts.GetTypeHandle(methodTable); // validate MT + ITypeHandle methodTableHandle = rts.GetTypeHandle(methodTable); // validate MT ushort vtableSlots = rts.GetNumVtableSlots(methodTableHandle); @@ -3246,7 +3246,7 @@ int ISOSDacInterface.GetObjectClassName(ClrDataAddress obj, uint count, char* cl Contracts.ILoader loader = _target.Contracts.Loader; TargetPointer mt = objectContract.GetMethodTableAddress(obj.ToTargetPointer(_target)); - Contracts.TypeHandle typeHandle = rts.GetTypeHandle(mt); + Contracts.ITypeHandle typeHandle = rts.GetTypeHandle(mt); TargetPointer modulePointer = rts.GetModule(typeHandle); if (modulePointer == TargetPointer.Null) @@ -3318,7 +3318,7 @@ int ISOSDacInterface.GetObjectData(ClrDataAddress objAddr, DacpObjectData* data) TargetPointer objPtr = objAddr.ToTargetPointer(_target); TargetPointer mt = objectContract.GetMethodTableAddress(objPtr); - TypeHandle handle = runtimeTypeSystemContract.GetTypeHandle(mt); + ITypeHandle handle = runtimeTypeSystemContract.GetTypeHandle(mt); data->MethodTable = mt.ToClrDataAddress(_target); data->Size = runtimeTypeSystemContract.GetBaseSize(handle); @@ -3360,7 +3360,7 @@ int ISOSDacInterface.GetObjectData(ClrDataAddress objAddr, DacpObjectData* data) data->Size += numComponents * data->dwComponentSize; // Get the type of the array elements - TypeHandle element = runtimeTypeSystemContract.GetTypeParam(handle); + ITypeHandle element = runtimeTypeSystemContract.GetTypeParam(handle); data->ElementTypeHandle = element.Address.Value; data->ElementType = (uint)runtimeTypeSystemContract.GetSignatureCorElementType(element); @@ -5414,7 +5414,7 @@ int ISOSDacInterface6.GetMethodTableCollectibleData(ClrDataAddress mt, DacpMetho Contracts.IRuntimeTypeSystem rtsContract = _target.Contracts.RuntimeTypeSystem; ILoader loaderContract = _target.Contracts.Loader; - Contracts.TypeHandle typeHandle = rtsContract.GetTypeHandle(mt.ToTargetPointer(_target)); + Contracts.ITypeHandle typeHandle = rtsContract.GetTypeHandle(mt.ToTargetPointer(_target)); bool isCollectible = rtsContract.IsCollectible(typeHandle); if (isCollectible) @@ -5568,7 +5568,7 @@ int ISOSDacInterface7.GetProfilerModifiedILInformation(ClrDataAddress methodDesc // getting the module handle and the token from the method desc MethodDescHandle mdh = rts.GetMethodDescHandle(methodDescPtr); TargetPointer mt = rts.GetMethodTable(mdh); - TypeHandle typeHandle = rts.GetTypeHandle(mt); + ITypeHandle typeHandle = rts.GetTypeHandle(mt); TargetPointer modulePtr = rts.GetModule(typeHandle); uint token = rts.GetMethodToken(mdh); Contracts.ModuleHandle moduleHandle = loader.GetModuleHandleFromModulePtr(modulePtr); @@ -5629,7 +5629,7 @@ int ISOSDacInterface7.GetMethodsWithProfilerModifiedIL(ClrDataAddress mod, ClrDa { if (*pcMethodDescs >= cMethodDescs) break; - TypeHandle typeHandle = rts.GetTypeHandle(ptr); + ITypeHandle typeHandle = rts.GetTypeHandle(ptr); foreach (TargetPointer md in rts.GetIntroducedMethodDescs(typeHandle)) { MethodDescHandle mdh = rts.GetMethodDescHandle(md); @@ -5988,7 +5988,7 @@ int ISOSDacInterface8.GetAssemblyLoadContext(ClrDataAddress methodTable, ClrData Contracts.IRuntimeTypeSystem rtsContract = _target.Contracts.RuntimeTypeSystem; Contracts.ILoader loaderContract = _target.Contracts.Loader; - Contracts.TypeHandle methodTableHandle = rtsContract.GetTypeHandle(methodTable.ToTargetPointer(_target)); + Contracts.ITypeHandle methodTableHandle = rtsContract.GetTypeHandle(methodTable.ToTargetPointer(_target)); Contracts.ModuleHandle moduleHandle = loaderContract.GetModuleHandleFromModulePtr(rtsContract.GetModule(methodTableHandle)); TargetPointer alc = loaderContract.GetAssemblyLoadContext(moduleHandle); *assemblyLoadContext = alc.ToClrDataAddress(_target); @@ -6274,7 +6274,7 @@ int ISOSDacInterface11.IsTrackedType(ClrDataAddress objAddr, Interop.BOOL* isTra throw new ArgumentException(); Contracts.IRuntimeTypeSystem rtsContract = _target.Contracts.RuntimeTypeSystem; - TypeHandle mtHandle = rtsContract.GetTypeHandle(mt); + ITypeHandle mtHandle = rtsContract.GetTypeHandle(mt); if (rtsContract.IsTrackedReferenceWithFinalizer(mtHandle)) *isTrackedType = Interop.BOOL.TRUE; @@ -6716,7 +6716,7 @@ int ISOSDacInterface14.GetStaticBaseAddress(ClrDataAddress methodTable, ClrDataA throw new ArgumentException(); Contracts.IRuntimeTypeSystem rtsContract = _target.Contracts.RuntimeTypeSystem; - Contracts.TypeHandle typeHandle = rtsContract.GetTypeHandle(methodTable.ToTargetPointer(_target)); + Contracts.ITypeHandle typeHandle = rtsContract.GetTypeHandle(methodTable.ToTargetPointer(_target)); if (GCStaticsAddress != null) *GCStaticsAddress = rtsContract.GetGCStaticsBasePointer(typeHandle).ToClrDataAddress(_target); if (nonGCStaticsAddress != null) @@ -6757,7 +6757,7 @@ int ISOSDacInterface14.GetThreadStaticBaseAddress(ClrDataAddress methodTable, Cl Contracts.IRuntimeTypeSystem rtsContract = _target.Contracts.RuntimeTypeSystem; TargetPointer methodTablePtr = methodTable.ToTargetPointer(_target); TargetPointer threadPtr = thread.ToTargetPointer(_target); - Contracts.TypeHandle typeHandle = rtsContract.GetTypeHandle(methodTablePtr); + Contracts.ITypeHandle typeHandle = rtsContract.GetTypeHandle(methodTablePtr); ushort numThreadStaticFields = rtsContract.GetNumThreadStaticFields(typeHandle); if (numThreadStaticFields == 0) { @@ -6810,7 +6810,7 @@ int ISOSDacInterface14.GetMethodTableInitializationFlags(ClrDataAddress methodTa throw new NullReferenceException(); Contracts.IRuntimeTypeSystem rtsContract = _target.Contracts.RuntimeTypeSystem; - Contracts.TypeHandle methodTableHandle = rtsContract.GetTypeHandle(methodTable.ToTargetPointer(_target)); + Contracts.ITypeHandle methodTableHandle = rtsContract.GetTypeHandle(methodTable.ToTargetPointer(_target)); *initializationStatus = (MethodTableInitializationFlags)0; if (rtsContract.IsClassInited(methodTableHandle)) *initializationStatus = MethodTableInitializationFlags.MethodTableInitialized; @@ -6844,14 +6844,14 @@ internal sealed unsafe partial class SOSMethodEnum : ISOSMethodEnum { private readonly Target _target; private readonly IRuntimeTypeSystem _rts; - private readonly TypeHandle _methodTable; + private readonly ITypeHandle _methodTable; private readonly ISOSMethodEnum? _legacyMethodEnum; private uint _iteratorIndex; private List _methods = []; - public SOSMethodEnum(Target target, TypeHandle methodTable, ISOSMethodEnum? legacyMethodEnum) + public SOSMethodEnum(Target target, ITypeHandle methodTable, ISOSMethodEnum? legacyMethodEnum) { _target = target; _rts = _target.Contracts.RuntimeTypeSystem; @@ -6887,7 +6887,7 @@ private void PopulateMethods() TargetPointer mtAddr = _rts.GetMethodTable(mdh); methodData.DefiningMethodTable = mtAddr.ToClrDataAddress(_target); - TypeHandle typeHandle = _rts.GetTypeHandle(mtAddr); + ITypeHandle typeHandle = _rts.GetTypeHandle(mtAddr); methodData.DefiningModule = _rts.GetModule(typeHandle).ToClrDataAddress(_target); methodData.Token = _rts.GetMethodToken(mdh); } @@ -6911,7 +6911,7 @@ private void PopulateMethods() TargetPointer mtAddr = _rts.GetMethodTable(mdh); methodData.DefiningMethodTable = mtAddr.ToClrDataAddress(_target); - TypeHandle typeHandle = _rts.GetTypeHandle(mtAddr); + ITypeHandle typeHandle = _rts.GetTypeHandle(mtAddr); methodData.DefiningModule = _rts.GetModule(typeHandle).ToClrDataAddress(_target); methodData.Token = _rts.GetMethodToken(mdh); @@ -7030,7 +7030,7 @@ int ISOSDacInterface15.GetMethodTableSlotEnumerator(ClrDataAddress mt, DacComNul throw new ArgumentException(); IRuntimeTypeSystem rts = _target.Contracts.RuntimeTypeSystem; - TypeHandle methodTableHandle = rts.GetTypeHandle(mt.ToTargetPointer(_target)); + ITypeHandle methodTableHandle = rts.GetTypeHandle(mt.ToTargetPointer(_target)); ISOSMethodEnum? legacyMethodEnum = null; #if DEBUG diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/SigFormat.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/SigFormat.cs index 6e41501fab87f7..efb6b0ff347bd5 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/SigFormat.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/SigFormat.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using System; @@ -18,8 +18,8 @@ public static unsafe void AppendSigFormat(Target target, string? memberName, string? className, string? namespaceName, - ReadOnlySpan typeInstantiation, - ReadOnlySpan methodInstantiation, + ITypeHandle[] typeInstantiation, + ITypeHandle[] methodInstantiation, bool CStringParmsOnly) { fixed (byte* pSignature = signature) @@ -36,8 +36,8 @@ public static void AppendSigFormat(Target target, string? memberName, string? className, string? namespaceName, - ReadOnlySpan typeInstantiation, - ReadOnlySpan methodInstantiation, + ITypeHandle[] typeInstantiation, + ITypeHandle[] methodInstantiation, bool CStringParmsOnly) { SignatureHeader header = signature.ReadSignatureHeader(); @@ -95,8 +95,8 @@ public static void AppendSigFormat(Target target, private static unsafe void AddTypeString(Target target, StringBuilder stringBuilder, ref BlobReader signature, - ReadOnlySpan typeInstantiation, - ReadOnlySpan methodInstantiation, + ITypeHandle[] typeInstantiation, + ITypeHandle[] methodInstantiation, MetadataReader? metadata) { string _namespace; @@ -157,7 +157,7 @@ private static unsafe void AddTypeString(Target target, case CorElementType.Internal: TargetPointer typeHandlePointer = target.ReadPointerFromSpan(signature.ReadBytes(target.PointerSize)); IRuntimeTypeSystem runtimeTypeSystem = target.Contracts.RuntimeTypeSystem; - TypeHandle th = runtimeTypeSystem.GetTypeHandle(typeHandlePointer); + ITypeHandle th = runtimeTypeSystem.GetTypeHandle(typeHandlePointer); switch (runtimeTypeSystem.GetSignatureCorElementType(th)) { case CorElementType.FnPtr: @@ -308,7 +308,7 @@ private static unsafe void AddTypeString(Target target, } } - private static void AddType(Target target, StringBuilder stringBuilder, TypeHandle typeHandle) + private static void AddType(Target target, StringBuilder stringBuilder, ITypeHandle typeHandle) { IRuntimeTypeSystem runtimeTypeSystem = target.Contracts.RuntimeTypeSystem; @@ -358,7 +358,7 @@ private static void AddType(Target target, StringBuilder stringBuilder, TypeHand } stringBuilder.Append(name); - ReadOnlySpan instantiation = runtimeTypeSystem.GetInstantiation(typeHandle); + ITypeHandle[] instantiation = runtimeTypeSystem.GetInstantiation(typeHandle); if (instantiation.Length > 0) { stringBuilder.Append('<'); @@ -414,7 +414,7 @@ private static void AddType(Target target, StringBuilder stringBuilder, TypeHand return; case CorElementType.FnPtr: - runtimeTypeSystem.IsFunctionPointer(typeHandle, out ReadOnlySpan retAndArgTypes, out SignatureCallingConvention callConv); + runtimeTypeSystem.IsFunctionPointer(typeHandle, out ITypeHandle[] retAndArgTypes, out SignatureCallingConvention callConv); SignatureHeader header = new SignatureHeader((byte)callConv); AddType(target, stringBuilder, retAndArgTypes[0]); stringBuilder.Append(" ("); diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/TypeNameBuilder.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/TypeNameBuilder.cs index 4372ca366ad388..8800ee0ff4b8f2 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/TypeNameBuilder.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/TypeNameBuilder.cs @@ -59,15 +59,15 @@ private TypeNameBuilder(StringBuilder typeString, Target target, TypeNameFormat public static void AppendMethodInternal(Target target, StringBuilder stringBuilder, Contracts.MethodDescHandle method, TypeNameFormat format) { - AppendMethodImpl(target, stringBuilder, method, default, format); + AppendMethodImpl(target, stringBuilder, method, Array.Empty(), format); } - public static void AppendMethodImpl(Target target, StringBuilder stringBuilder, Contracts.MethodDescHandle method, ReadOnlySpan typeInstantiation, TypeNameFormat format) + public static void AppendMethodImpl(Target target, StringBuilder stringBuilder, Contracts.MethodDescHandle method, ITypeHandle[] typeInstantiation, TypeNameFormat format) { IRuntimeTypeSystem runtimeTypeSystem = target.Contracts.RuntimeTypeSystem; ILoader loader = target.Contracts.Loader; string methodName; - TypeHandle th = default; + ITypeHandle th = ITypeHandle.Null; Contracts.ModuleHandle module = default; bool isNoMetadataMethod = runtimeTypeSystem.IsNoMetadataMethod(method, out methodName); @@ -126,7 +126,7 @@ public static void AppendMethodImpl(Target target, StringBuilder stringBuilder, stringBuilder.Append(reader.GetString(methodDef.Name)); } - ReadOnlySpan genericMethodInstantiation = runtimeTypeSystem.GetGenericMethodInstantiation(method); + ITypeHandle[] genericMethodInstantiation = runtimeTypeSystem.GetGenericMethodInstantiation(method); if (genericMethodInstantiation.Length > 0 && !runtimeTypeSystem.IsGenericMethodDefinition(method)) { AppendInst(target, stringBuilder, genericMethodInstantiation, format); @@ -146,11 +146,11 @@ public static void AppendMethodImpl(Target target, StringBuilder stringBuilder, } } - ReadOnlySpan typeInstantiationSigFormat = default; + ITypeHandle[] typeInstantiationSigFormat = Array.Empty(); if (!th.IsNull) { typeInstantiationSigFormat = runtimeTypeSystem.GetInstantiation(th); - if (typeInstantiationSigFormat.IsEmpty && runtimeTypeSystem.IsArray(th, out _)) + if (typeInstantiationSigFormat.Length == 0 && runtimeTypeSystem.IsArray(th, out _)) { // For arrays, fill in the instantiation with the element type handle // See MethodTable::GetArrayInstantiation for coreclr equivalent @@ -162,9 +162,9 @@ public static void AppendMethodImpl(Target target, StringBuilder stringBuilder, } } - public static TypeHandle GetExactOwningType(IRuntimeTypeSystem runtimeTypeSystem, TypeHandle possiblyDerivedType, MethodDescHandle method) + public static ITypeHandle GetExactOwningType(IRuntimeTypeSystem runtimeTypeSystem, ITypeHandle possiblyDerivedType, MethodDescHandle method) { - TypeHandle approxOwner = runtimeTypeSystem.GetTypeHandle(runtimeTypeSystem.GetMethodTable(method)); + ITypeHandle approxOwner = runtimeTypeSystem.GetTypeHandle(runtimeTypeSystem.GetMethodTable(method)); uint typeDefTokenOfOwner = runtimeTypeSystem.GetTypeDefToken(approxOwner); TargetPointer moduleOfOwner = runtimeTypeSystem.GetModule(approxOwner); @@ -188,18 +188,18 @@ public static TypeHandle GetExactOwningType(IRuntimeTypeSystem runtimeTypeSystem } while (true); } - public static void AppendType(Target target, StringBuilder stringBuilder, Contracts.TypeHandle typeHandle, TypeNameFormat format) + public static void AppendType(Target target, StringBuilder stringBuilder, Contracts.ITypeHandle typeHandle, TypeNameFormat format) { - AppendType(target, stringBuilder, typeHandle, default, format); + AppendType(target, stringBuilder, typeHandle, Array.Empty(), format); } - public static void AppendType(Target target, StringBuilder stringBuilder, Contracts.TypeHandle typeHandle, ReadOnlySpan typeInstantiation, TypeNameFormat format) + public static void AppendType(Target target, StringBuilder stringBuilder, Contracts.ITypeHandle typeHandle, ITypeHandle[] typeInstantiation, TypeNameFormat format) { TypeNameBuilder builder = new(stringBuilder, target, format); AppendTypeCore(ref builder, typeHandle, typeInstantiation, format); } - private static void AppendTypeCore(ref TypeNameBuilder tnb, Contracts.TypeHandle typeHandle, ReadOnlySpan instantiation, TypeNameFormat format) + private static void AppendTypeCore(ref TypeNameBuilder tnb, Contracts.ITypeHandle typeHandle, Contracts.ITypeHandle[] instantiation, TypeNameFormat format) { bool toString = format.HasFlag(TypeNameFormat.FormatNamespace) && !format.HasFlag(TypeNameFormat.FormatFullInst) && !format.HasFlag(TypeNameFormat.FormatAssembly); @@ -216,13 +216,13 @@ private static void AppendTypeCore(ref TypeNameBuilder tnb, Contracts.TypeHandle if (elemType != Contracts.CorElementType.ValueType) { typeSystemContract.IsArray(typeHandle, out uint rank); - AppendTypeCore(ref tnb, typeSystemContract.GetTypeParam(typeHandle), default(ReadOnlySpan), (TypeNameFormat)(format & ~TypeNameFormat.FormatAssembly)); + AppendTypeCore(ref tnb, typeSystemContract.GetTypeParam(typeHandle), Array.Empty(), (TypeNameFormat)(format & ~TypeNameFormat.FormatAssembly)); AppendParamTypeQualifier(ref tnb, elemType, rank); } else { tnb.TypeString.Append("VALUETYPE"); - AppendTypeCore(ref tnb, typeSystemContract.GetTypeParam(typeHandle), Array.Empty(), format & ~TypeNameFormat.FormatAssembly); + AppendTypeCore(ref tnb, typeSystemContract.GetTypeParam(typeHandle), Array.Empty(), format & ~TypeNameFormat.FormatAssembly); } } else if (typeSystemContract.IsGenericVariable(typeHandle, out TargetPointer modulePointer, out uint genericParamToken)) @@ -245,7 +245,7 @@ private static void AppendTypeCore(ref TypeNameBuilder tnb, Contracts.TypeHandle tnb.AddName(reader.GetString(genericParam.Name)); format &= ~TypeNameFormat.FormatAssembly; } - else if (typeSystemContract.IsFunctionPointer(typeHandle, out ReadOnlySpan retAndArgTypes, out SignatureCallingConvention callConv)) + else if (typeSystemContract.IsFunctionPointer(typeHandle, out ITypeHandle[] retAndArgTypes, out SignatureCallingConvention callConv)) { if (format.HasFlag(TypeNameFormat.FormatNamespace)) { @@ -303,7 +303,7 @@ private static void AppendTypeCore(ref TypeNameBuilder tnb, Contracts.TypeHandle if (format.HasFlag(TypeNameFormat.FormatNamespace) || format.HasFlag(TypeNameFormat.FormatAssembly)) { - ReadOnlySpan instantiationSpan = typeSystemContract.GetInstantiation(typeHandle); + ITypeHandle[] instantiationSpan = typeSystemContract.GetInstantiation(typeHandle); if ((instantiationSpan.Length > 0) && (!typeSystemContract.IsGenericTypeDefinition(typeHandle) || toString)) { @@ -333,25 +333,25 @@ private static void AppendTypeCore(ref TypeNameBuilder tnb, Contracts.TypeHandle // Append a square-bracket-enclosed, comma-separated list of n type parameters in inst to the string s // and enclose each parameter in square brackets to disambiguate the commas // The following flags in the FormatFlags argument are significant: FormatNamespace FormatFullInst FormatAssembly FormatNoVersion - private static void AppendInst(Target target, StringBuilder stringBuilder, ReadOnlySpan inst, TypeNameFormat format) + private static void AppendInst(Target target, StringBuilder stringBuilder, ITypeHandle[] inst, TypeNameFormat format) { TypeNameBuilder tnb = new(stringBuilder, target, format, initialStateIsName: true); AppendInst(ref tnb, inst, format); } - private static void AppendInst(ref TypeNameBuilder tnb, ReadOnlySpan inst, TypeNameFormat format) + private static void AppendInst(ref TypeNameBuilder tnb, ITypeHandle[] inst, TypeNameFormat format) { tnb.OpenGenericArguments(); - foreach (TypeHandle arg in inst) + foreach (ITypeHandle arg in inst) { tnb.OpenGenericArgument(); if (format.HasFlag(TypeNameFormat.FormatFullInst) && !tnb.Target.Contracts.RuntimeTypeSystem.IsGenericVariable(arg, out _, out _)) { - AppendTypeCore(ref tnb, arg, default, format | TypeNameFormat.FormatNamespace | TypeNameFormat.FormatAssembly); + AppendTypeCore(ref tnb, arg, Array.Empty(), format | TypeNameFormat.FormatNamespace | TypeNameFormat.FormatAssembly); } else { - AppendTypeCore(ref tnb, arg, default, format & (TypeNameFormat.FormatNamespace | TypeNameFormat.FormatAngleBrackets)); + AppendTypeCore(ref tnb, arg, Array.Empty(), format & (TypeNameFormat.FormatNamespace | TypeNameFormat.FormatAngleBrackets)); } tnb.CloseGenericArgument(); } @@ -510,7 +510,7 @@ private void AddAssemblySpec(string? assemblySpec) /// Only GC descriptor series whose startoffset is at or above the continuation data /// payload (i.e., after the fixed CORINFO_Continuation header fields) are included. /// - private static void AppendContinuationName(ref TypeNameBuilder tnb, IRuntimeTypeSystem typeSystemContract, TypeHandle typeHandle) + private static void AppendContinuationName(ref TypeNameBuilder tnb, IRuntimeTypeSystem typeSystemContract, ITypeHandle typeHandle) { uint baseSize = typeSystemContract.GetBaseSize(typeHandle); uint continuationDataOffset = tnb.Target.GetTypeInfo(DataType.ContinuationObject).Size!.Value; diff --git a/src/native/managed/cdac/gen/CdacGenerator.cs b/src/native/managed/cdac/gen/CdacGenerator.cs index 2375b2fdb60d05..a93ddd5a835d96 100644 --- a/src/native/managed/cdac/gen/CdacGenerator.cs +++ b/src/native/managed/cdac/gen/CdacGenerator.cs @@ -11,7 +11,7 @@ namespace Microsoft.Diagnostics.DataContractReader.DataGenerator; /// /// Source generator for cdac classes. Emits the /// boilerplate IData<T>.Create factory, managed-type -/// TypeHandle accessors, and static-field accessors from +/// ITypeHandle accessors, and static-field accessors from /// declarative attributes. /// /// diff --git a/src/native/managed/cdac/gen/Emitter.cs b/src/native/managed/cdac/gen/Emitter.cs index 162d75d2ddcce4..3d3e054d901310 100644 --- a/src/native/managed/cdac/gen/Emitter.cs +++ b/src/native/managed/cdac/gen/Emitter.cs @@ -12,10 +12,10 @@ internal static class Emitter // Generated files declare a file-scoped namespace inside // Microsoft.Diagnostics.DataContractReader.* so these short names resolve // via parent-namespace lookup. The using directives below cover - // TypeHandle (in ...Contracts) explicitly. + // ITypeHandle (in ...Contracts) explicitly. private const string Target = "Target"; private const string TargetPointer = "TargetPointer"; - private const string TypeHandleType = "TypeHandle"; + private const string ITypeHandleType = "ITypeHandle"; private const string IDataInterface = "IData"; private const string RootNamespace = "Microsoft.Diagnostics.DataContractReader"; @@ -51,7 +51,7 @@ public static string Emit(CdacTypeModel model) sb.AppendLine($"partial class {model.ClassName}"); sb.AppendLine("{"); - // Emit a static _typeNames array for LayoutSet.Resolve and TypeHandle resolution. + // Emit a static _typeNames array for LayoutSet.Resolve and ITypeHandle resolution. if (model.Names.Count > 0) { string namesLiteral = NamesArrayLiteral(model.Names); @@ -59,10 +59,10 @@ public static string Emit(CdacTypeModel model) sb.AppendLine(); } - // The class advertises a managed identity (TypeHandle) when HasTypeHandle is set. + // The class advertises a managed identity (ITypeHandle) when HasTypeHandle is set. if (model.HasTypeHandle) { - sb.AppendLine($" public static {TypeHandleType} TypeHandle({Target} target)"); + sb.AppendLine($" public static {ITypeHandleType} ITypeHandle({Target} target)"); sb.AppendLine($" => TypeNameResolver.GetTypeHandle(target, _typeNames);"); sb.AppendLine(); } diff --git a/src/native/managed/cdac/gen/TypeNameResolverSource.cs b/src/native/managed/cdac/gen/TypeNameResolverSource.cs index 8d6a7f777eb5af..ff4ecb39206db6 100644 --- a/src/native/managed/cdac/gen/TypeNameResolverSource.cs +++ b/src/native/managed/cdac/gen/TypeNameResolverSource.cs @@ -6,7 +6,7 @@ namespace Microsoft.Diagnostics.DataContractReader.DataGenerator; /// /// Source for the TypeNameResolver helper emitted into each consuming /// assembly via RegisterSourceOutput (gated by CompilationProvider to -/// avoid duplicate symbols). Resolves TypeHandle, static field addresses, and +/// avoid duplicate symbols). Resolves ITypeHandle, static field addresses, and /// thread-static field addresses across a cascade of candidate type names. /// internal static class TypeNameResolverSource @@ -26,15 +26,15 @@ namespace Microsoft.Diagnostics.DataContractReader.Generated; internal static class TypeNameResolver { - public static TypeHandle GetTypeHandle(Target target, string[] names) + public static ITypeHandle GetTypeHandle(Target target, string[] names) { foreach (string name in names) { - if (target.Contracts.ManagedTypeSource.TryGetTypeHandle(name, out TypeHandle th)) + if (target.Contracts.ManagedTypeSource.TryGetTypeHandle(name, out ITypeHandle th)) return th; } throw new InvalidOperationException( - $"No managed type resolved for TypeHandle (names=[{string.Join(",", names)}])."); + $"No managed type resolved for ITypeHandle (names=[{string.Join(",", names)}])."); } public static TargetPointer GetStaticFieldAddress(Target target, string[] names, string fieldName) diff --git a/src/native/managed/cdac/tests/DumpTests/AsyncContinuationDumpTests.cs b/src/native/managed/cdac/tests/DumpTests/AsyncContinuationDumpTests.cs index 14731f6418bf92..33e13d8d052ffc 100644 --- a/src/native/managed/cdac/tests/DumpTests/AsyncContinuationDumpTests.cs +++ b/src/native/managed/cdac/tests/DumpTests/AsyncContinuationDumpTests.cs @@ -44,7 +44,7 @@ public void ContinuationBaseClass_IsNotContinuation(TestConfiguration config) TargetPointer continuationMT = Target.ReadPointer(continuationMTGlobal); Assert.NotEqual(TargetPointer.Null, continuationMT); - TypeHandle handle = rts.GetTypeHandle(continuationMT); + ITypeHandle handle = rts.GetTypeHandle(continuationMT); Assert.False(rts.IsContinuationWithoutMetadata(handle)); } @@ -58,7 +58,7 @@ public void ObjectMethodTable_IsNotContinuation(TestConfiguration config) TargetPointer objectMTGlobal = Target.ReadGlobalPointer("ObjectMethodTable"); TargetPointer objectMT = Target.ReadPointer(objectMTGlobal); - TypeHandle objectHandle = rts.GetTypeHandle(objectMT); + ITypeHandle objectHandle = rts.GetTypeHandle(objectMT); Assert.False(rts.IsContinuationWithoutMetadata(objectHandle)); } @@ -111,7 +111,7 @@ public void ThreadLocalContinuation_IsContinuation(TestConfiguration config) // 4. Verify the object's MethodTable is a continuation subtype via the cDAC. TargetPointer objMT = Target.Contracts.Object.GetMethodTableAddress( new TargetPointer(continuationAddress)); - TypeHandle handle = rts.GetTypeHandle(objMT); + ITypeHandle handle = rts.GetTypeHandle(objMT); Assert.True(rts.IsContinuationWithoutMetadata(handle)); } } diff --git a/src/native/managed/cdac/tests/DumpTests/CCWDumpTests.cs b/src/native/managed/cdac/tests/DumpTests/CCWDumpTests.cs index bfa5069716f41a..c11036738231ee 100644 --- a/src/native/managed/cdac/tests/DumpTests/CCWDumpTests.cs +++ b/src/native/managed/cdac/tests/DumpTests/CCWDumpTests.cs @@ -94,10 +94,10 @@ public void CCW_InterfaceMethodTablesAreReadable(TestConfiguration config) if (iface.MethodTable == TargetPointer.Null) continue; - // Verify the MethodTable is readable by resolving it to a TypeHandle. - TypeHandle typeHandle = rts.GetTypeHandle(iface.MethodTable); + // Verify the MethodTable is readable by resolving it to a ITypeHandle. + ITypeHandle typeHandle = rts.GetTypeHandle(iface.MethodTable); Assert.False(typeHandle.IsNull, - $"Expected non-null TypeHandle for MethodTable 0x{iface.MethodTable:X} in CCW 0x{ccwPtr:X}"); + $"Expected non-null ITypeHandle for MethodTable 0x{iface.MethodTable:X} in CCW 0x{ccwPtr:X}"); Assert.True(rts.GetBaseSize(typeHandle) > 0, $"Expected positive base size for MethodTable 0x{iface.MethodTable:X} in CCW 0x{ccwPtr:X}"); } diff --git a/src/native/managed/cdac/tests/DumpTests/DacDbi/DacDbiApproxTypeHandleDumpTests.cs b/src/native/managed/cdac/tests/DumpTests/DacDbi/DacDbiApproxTypeHandleDumpTests.cs index 2c9d3c570f4d68..1d76fd8f62a561 100644 --- a/src/native/managed/cdac/tests/DumpTests/DacDbi/DacDbiApproxTypeHandleDumpTests.cs +++ b/src/native/managed/cdac/tests/DumpTests/DacDbi/DacDbiApproxTypeHandleDumpTests.cs @@ -51,7 +51,7 @@ public unsafe void RoundTrip_AllReachableHandleObjects_MatchApproxMethodTable(Te IRuntimeTypeSystem rts = Target.Contracts.RuntimeTypeSystem; TargetPointer canonMtPtr = Target.ReadPointer(Target.ReadGlobalPointer(Constants.Globals.CanonMethodTable)); - TypeHandle canonTh = rts.GetTypeHandle(canonMtPtr); + ITypeHandle canonTh = rts.GetTypeHandle(canonMtPtr); HandleType[] handleKinds = [ @@ -81,14 +81,14 @@ public unsafe void RoundTrip_AllReachableHandleObjects_MatchApproxMethodTable(Te /// and assert the resulting vmTypeHandle equals the expected canonicalized /// MethodTable for the object's type. /// - private unsafe void AssertRoundTrip(DacDbiImpl dbi, IRuntimeTypeSystem rts, TypeHandle canonTh, ulong objAddr) + private unsafe void AssertRoundTrip(DacDbiImpl dbi, IRuntimeTypeSystem rts, ITypeHandle canonTh, ulong objAddr) { TargetPointer expectedMT = Target.Contracts.Object.GetMethodTableAddress(new TargetPointer(objAddr)); - TypeHandle expectedTh = rts.GetTypeHandle(expectedMT); + ITypeHandle expectedTh = rts.GetTypeHandle(expectedMT); // Build the expected canonicalized handle from the exact type. Mirrors the rules // applied by TypeDataWalk on the cDAC side. - TypeHandle expectedApproxTh = ApproxTopLevel(dbi, rts, canonTh, expectedTh); + ITypeHandle expectedApproxTh = ApproxTopLevel(dbi, rts, canonTh, expectedTh); if (expectedApproxTh.IsNull) return; // If the approximation rules collapse this type to null, skip the round-trip assertion. @@ -121,7 +121,7 @@ private unsafe void AssertRoundTrip(DacDbiImpl dbi, IRuntimeTypeSystem rts, Type // anything else -> 0 // ---------------------------------------------------------------------------------------- - private static int CountTypeNodes(IRuntimeTypeSystem rts, TypeHandle th) + private static int CountTypeNodes(IRuntimeTypeSystem rts, ITypeHandle th) { CorElementType et = GetElementType(rts, th); switch (et) @@ -136,7 +136,7 @@ private static int CountTypeNodes(IRuntimeTypeSystem rts, TypeHandle th) case CorElementType.ValueType: { int total = 1; - foreach (TypeHandle arg in rts.GetInstantiation(th)) + foreach (ITypeHandle arg in rts.GetInstantiation(th)) total += CountTypeNodes(rts, arg); return total; } @@ -146,7 +146,7 @@ private static int CountTypeNodes(IRuntimeTypeSystem rts, TypeHandle th) } } - private static unsafe void FillTypeNodes(DacDbiImpl dbi, IRuntimeTypeSystem rts, TypeHandle th, DebuggerIPCE_TypeArgData* nodes, ref int idx) + private static unsafe void FillTypeNodes(DacDbiImpl dbi, IRuntimeTypeSystem rts, ITypeHandle th, DebuggerIPCE_TypeArgData* nodes, ref int idx) { int self = idx++; DebuggerIPCE_TypeArgData* pSelf = &nodes[self]; @@ -170,7 +170,7 @@ private static unsafe void FillTypeNodes(DacDbiImpl dbi, IRuntimeTypeSystem rts, case CorElementType.Class: case CorElementType.ValueType: { - ReadOnlySpan inst = rts.GetInstantiation(th); + ReadOnlySpan inst = rts.GetInstantiation(th); uint numTypeArgs = (uint)inst.Length; pSelf->numTypeArgs = BitConverter.IsLittleEndian ? numTypeArgs : System.Buffers.Binary.BinaryPrimitives.ReverseEndianness(numTypeArgs); for (int i = 0; i < inst.Length; i++) @@ -193,7 +193,7 @@ private static unsafe void FillTypeNodes(DacDbiImpl dbi, IRuntimeTypeSystem rts, // ApproxTypeArg. Array / Ptr / Byref preserve the outer shape; the inner type goes through // ApproxTypeArg. Anything else collapses to the primitive type for its element type // (e.g. System.Object, System.String, primitives). - private TypeHandle ApproxTopLevel(DacDbiImpl dbi, IRuntimeTypeSystem rts, TypeHandle canonTh, TypeHandle th) + private ITypeHandle ApproxTopLevel(DacDbiImpl dbi, IRuntimeTypeSystem rts, ITypeHandle canonTh, ITypeHandle th) { CorElementType et = GetElementType(rts, th); switch (et) @@ -201,16 +201,16 @@ private TypeHandle ApproxTopLevel(DacDbiImpl dbi, IRuntimeTypeSystem rts, TypeHa case CorElementType.Array: case CorElementType.SzArray: { - TypeHandle elem = ApproxTypeArg(dbi, rts, canonTh, rts.GetTypeParam(th)); + ITypeHandle elem = ApproxTypeArg(dbi, rts, canonTh, rts.GetTypeParam(th)); rts.IsArray(th, out uint rank); - return rts.GetConstructedType(elem, et, (int)rank, ImmutableArray.Empty); + return rts.GetConstructedType(elem, et, (int)rank, ImmutableArray.Empty); } case CorElementType.Ptr: case CorElementType.Byref: { - TypeHandle referent = ApproxTypeArg(dbi, rts, canonTh, rts.GetTypeParam(th)); - return rts.GetConstructedType(referent, et, 0, ImmutableArray.Empty); + ITypeHandle referent = ApproxTypeArg(dbi, rts, canonTh, rts.GetTypeParam(th)); + return rts.GetConstructedType(referent, et, 0, ImmutableArray.Empty); } case CorElementType.Class: @@ -224,16 +224,16 @@ private TypeHandle ApproxTopLevel(DacDbiImpl dbi, IRuntimeTypeSystem rts, TypeHa // Arg context: Class collapses to __Canon (its children skipped); ValueType is recursively // approximated; Ptr preserves shape; obj-ref primitives (Class/Object/String/SzArray/Array) - // collapse to __Canon; primitives map to their primitive TypeHandle. - private TypeHandle ApproxTypeArg(DacDbiImpl dbi, IRuntimeTypeSystem rts, TypeHandle canonTh, TypeHandle th) + // collapse to __Canon; primitives map to their primitive ITypeHandle. + private ITypeHandle ApproxTypeArg(DacDbiImpl dbi, IRuntimeTypeSystem rts, ITypeHandle canonTh, ITypeHandle th) { CorElementType et = GetElementType(rts, th); switch (et) { case CorElementType.Ptr: { - TypeHandle referent = ApproxTypeArg(dbi, rts, canonTh, rts.GetTypeParam(th)); - return rts.GetConstructedType(referent, et, 0, ImmutableArray.Empty); + ITypeHandle referent = ApproxTypeArg(dbi, rts, canonTh, rts.GetTypeParam(th)); + return rts.GetConstructedType(referent, et, 0, ImmutableArray.Empty); } case CorElementType.Class: @@ -255,7 +255,7 @@ private TypeHandle ApproxTypeArg(DacDbiImpl dbi, IRuntimeTypeSystem rts, TypeHan // Non-generic types return early — the production walker takes the // nTypeArgs == 0 branch and returns the typeDef directly, which equals the type's // own MT for a non-generic type. - private TypeHandle InstantiationApprox(DacDbiImpl dbi, IRuntimeTypeSystem rts, TypeHandle canonTh, TypeHandle th) + private ITypeHandle InstantiationApprox(DacDbiImpl dbi, IRuntimeTypeSystem rts, ITypeHandle canonTh, ITypeHandle th) { // Mirror DacDbiImpl.FillClassTypeInfo: upcast continuation-without-metadata types to // their parent before resolving module / typeDef token. Otherwise the synthesized token @@ -268,7 +268,7 @@ private TypeHandle InstantiationApprox(DacDbiImpl dbi, IRuntimeTypeSystem rts, T th = rts.GetTypeHandle(parentMT); } - ReadOnlySpan inst = rts.GetInstantiation(th); + ReadOnlySpan inst = rts.GetInstantiation(th); if (inst.Length == 0) return th; @@ -280,16 +280,16 @@ private TypeHandle InstantiationApprox(DacDbiImpl dbi, IRuntimeTypeSystem rts, T ulong vmAssembly = loader.GetAssembly(moduleHandle).Value; uint metadataToken = rts.GetTypeDefToken(th); - TypeHandle typeDef = dbi.TryLookupTypeDefOrRefInAssembly(vmAssembly, metadataToken); + ITypeHandle typeDef = dbi.TryLookupTypeDefOrRefInAssembly(vmAssembly, metadataToken); if (typeDef.IsNull) - return default; + return ITypeHandle.Null; - ImmutableArray.Builder builder = ImmutableArray.CreateBuilder(inst.Length); + ImmutableArray.Builder builder = ImmutableArray.CreateBuilder(inst.Length); for (int i = 0; i < inst.Length; i++) { - TypeHandle approxArg = ApproxTypeArg(dbi, rts, canonTh, inst[i]); + ITypeHandle approxArg = ApproxTypeArg(dbi, rts, canonTh, inst[i]); if (approxArg.IsNull) - return default; + return ITypeHandle.Null; builder.Add(approxArg); } @@ -298,7 +298,7 @@ private TypeHandle InstantiationApprox(DacDbiImpl dbi, IRuntimeTypeSystem rts, T // Same element-type mapping DacDbiImpl uses (System.String -> E_T_STRING, System.Object -> // E_T_OBJECT, else GetSignatureCorElementType). - private static CorElementType GetElementType(IRuntimeTypeSystem rts, TypeHandle th) + private static CorElementType GetElementType(IRuntimeTypeSystem rts, ITypeHandle th) { if (th.IsNull) return CorElementType.Void; diff --git a/src/native/managed/cdac/tests/DumpTests/DacDbi/DacDbiExactTypeHandleDumpTests.cs b/src/native/managed/cdac/tests/DumpTests/DacDbi/DacDbiExactTypeHandleDumpTests.cs index ee1e39bf5e03eb..a73dd297169fa9 100644 --- a/src/native/managed/cdac/tests/DumpTests/DacDbi/DacDbiExactTypeHandleDumpTests.cs +++ b/src/native/managed/cdac/tests/DumpTests/DacDbi/DacDbiExactTypeHandleDumpTests.cs @@ -74,7 +74,7 @@ private unsafe void AssertRoundTrip(DacDbiImpl dbi, ulong objAddr) IRuntimeTypeSystem rts = Target.Contracts.RuntimeTypeSystem; TargetPointer expectedMT = Target.Contracts.Object.GetMethodTableAddress(new TargetPointer(objAddr)); - TypeHandle expectedTh = rts.GetTypeHandle(expectedMT); + ITypeHandle expectedTh = rts.GetTypeHandle(expectedMT); DebuggerIPCE_ExpandedTypeData expanded; int hr = dbi.GetObjectExpandedTypeInfo(AreValueTypesBoxed.NoValueTypeBoxing, objAddr, &expanded); @@ -99,7 +99,7 @@ private unsafe void AssertRoundTrip(DacDbiImpl dbi, ulong objAddr) } } - private static DebuggerIPCE_BasicTypeData[] BuildArgInfoList(DacDbiImpl dbi, IRuntimeTypeSystem rts, TypeHandle typeHandle) + private static DebuggerIPCE_BasicTypeData[] BuildArgInfoList(DacDbiImpl dbi, IRuntimeTypeSystem rts, ITypeHandle typeHandle) { if (rts.IsArray(typeHandle, out _)) { @@ -108,7 +108,7 @@ private static DebuggerIPCE_BasicTypeData[] BuildArgInfoList(DacDbiImpl dbi, IRu return one; } - ReadOnlySpan instantiation = rts.GetInstantiation(typeHandle); + ITypeHandle[] instantiation = rts.GetInstantiation(typeHandle); if (instantiation.Length == 0) return Array.Empty(); diff --git a/src/native/managed/cdac/tests/DumpTests/DacDbi/DacDbiLoaderDumpTests.cs b/src/native/managed/cdac/tests/DumpTests/DacDbi/DacDbiLoaderDumpTests.cs index 5f4313d4d1d8f2..1dfce0799bb9e4 100644 --- a/src/native/managed/cdac/tests/DumpTests/DacDbi/DacDbiLoaderDumpTests.cs +++ b/src/native/managed/cdac/tests/DumpTests/DacDbi/DacDbiLoaderDumpTests.cs @@ -141,7 +141,7 @@ public unsafe void GetTypeHandle_ReturnsMethodTableForTypeDef(TestConfiguration // Get the well-known System.Object MethodTable TargetPointer objectMTGlobal = Target.ReadGlobalPointer("ObjectMethodTable"); TargetPointer objectMT = Target.ReadPointer(objectMTGlobal); - TypeHandle objectHandle = rts.GetTypeHandle(objectMT); + ITypeHandle objectHandle = rts.GetTypeHandle(objectMT); // Get its TypeDef token and module pointer uint token = rts.GetTypeDefToken(objectHandle); diff --git a/src/native/managed/cdac/tests/DumpTests/DacDbi/DacDbiObjectDumpTests.cs b/src/native/managed/cdac/tests/DumpTests/DacDbi/DacDbiObjectDumpTests.cs index 03f529402b927e..6145d1b2aaf0b3 100644 --- a/src/native/managed/cdac/tests/DumpTests/DacDbi/DacDbiObjectDumpTests.cs +++ b/src/native/managed/cdac/tests/DumpTests/DacDbi/DacDbiObjectDumpTests.cs @@ -57,7 +57,7 @@ public unsafe void GetTypeLayout_Object_CrossValidatesContract(TestConfiguration DacDbiImpl dbi = CreateDacDbi(); TargetPointer objectMT = Target.ReadPointer(Target.ReadGlobalPointer("ObjectMethodTable")); - TypeHandle objectHandle = Target.Contracts.RuntimeTypeSystem.GetTypeHandle(objectMT); + ITypeHandle objectHandle = Target.Contracts.RuntimeTypeSystem.GetTypeHandle(objectMT); COR_TYPE_LAYOUT layout; int hr = dbi.GetTypeLayout(objectMT.Value, &layout); @@ -79,8 +79,8 @@ public unsafe void GetArrayLayout_ObjectArray_CrossValidatesContract(TestConfigu IRuntimeTypeSystem rts = Target.Contracts.RuntimeTypeSystem; TargetPointer arrayMT = Target.ReadPointer(Target.ReadGlobalPointer("ObjectArrayMethodTable")); - TypeHandle arrayHandle = rts.GetTypeHandle(arrayMT); - TypeHandle componentHandle = rts.GetTypeParam(arrayHandle); + ITypeHandle arrayHandle = rts.GetTypeHandle(arrayMT); + ITypeHandle componentHandle = rts.GetTypeParam(arrayHandle); Assert.True(rts.IsArray(arrayHandle, out uint rank)); COR_ARRAY_LAYOUT layout; @@ -213,7 +213,7 @@ public unsafe void GetObjectFields_NullLayout_QueriesIntroducedFieldCount(TestCo IRuntimeTypeSystem rts = Target.Contracts.RuntimeTypeSystem; TargetPointer stringMT = Target.ReadPointer(Target.ReadGlobalPointer("StringMethodTable")); - TypeHandle stringHandle = rts.GetTypeHandle(stringMT); + ITypeHandle stringHandle = rts.GetTypeHandle(stringMT); uint expectedCount = GetIntroducedInstanceFieldCount(rts, stringHandle); uint fetched = 0; @@ -231,7 +231,7 @@ public unsafe void GetObjectFields_String_CrossValidatesContract(TestConfigurati IRuntimeTypeSystem rts = Target.Contracts.RuntimeTypeSystem; TargetPointer stringMT = Target.ReadPointer(Target.ReadGlobalPointer("StringMethodTable")); - TypeHandle stringHandle = rts.GetTypeHandle(stringMT); + ITypeHandle stringHandle = rts.GetTypeHandle(stringMT); uint cFields = GetIntroducedInstanceFieldCount(rts, stringHandle); Assert.True(cFields >= 1, $"Expected System.String to have at least one introduced instance field, got {cFields}"); @@ -262,13 +262,13 @@ public unsafe void GetObjectFields_String_CrossValidatesContract(TestConfigurati } } - private static uint GetIntroducedInstanceFieldCount(IRuntimeTypeSystem rts, TypeHandle handle) + private static uint GetIntroducedInstanceFieldCount(IRuntimeTypeSystem rts, ITypeHandle handle) { uint count = rts.GetNumInstanceFields(handle); TargetPointer parentMT = rts.GetParentMethodTable(handle); if (parentMT != TargetPointer.Null) { - TypeHandle parentHandle = rts.GetTypeHandle(parentMT); + ITypeHandle parentHandle = rts.GetTypeHandle(parentMT); count -= rts.GetNumInstanceFields(parentHandle); } return count; diff --git a/src/native/managed/cdac/tests/DumpTests/IXCLRDataMethodDefinitionDumpTests.cs b/src/native/managed/cdac/tests/DumpTests/IXCLRDataMethodDefinitionDumpTests.cs index d352cb87f19c8a..236bb3ecde4b04 100644 --- a/src/native/managed/cdac/tests/DumpTests/IXCLRDataMethodDefinitionDumpTests.cs +++ b/src/native/managed/cdac/tests/DumpTests/IXCLRDataMethodDefinitionDumpTests.cs @@ -233,7 +233,7 @@ private IXCLRDataMethodDefinition GetGenericMethodDefinition() TargetPointer systemAssembly = loader.GetSystemAssembly(); Contracts.ModuleHandle coreLibModule = loader.GetModuleHandleFromAssemblyPtr(systemAssembly); - TypeHandle listTypeDef = Target.Contracts.ManagedTypeSource.GetTypeHandle( + ITypeHandle listTypeDef = Target.Contracts.ManagedTypeSource.GetTypeHandle( "System.Collections.Generic.List`1"); Assert.True(listTypeDef.Address != 0, "Could not find List<> type definition in CoreLib"); diff --git a/src/native/managed/cdac/tests/DumpTests/IXCLRDataValueDumpTests.cs b/src/native/managed/cdac/tests/DumpTests/IXCLRDataValueDumpTests.cs index ae75899ea40618..1ca092dd50e103 100644 --- a/src/native/managed/cdac/tests/DumpTests/IXCLRDataValueDumpTests.cs +++ b/src/native/managed/cdac/tests/DumpTests/IXCLRDataValueDumpTests.cs @@ -242,7 +242,7 @@ public void GetFlags_ReturnsExpectedFlags(TestConfiguration config) // --- GenericInst and ByRef --- // GenericInstAndByRefVars(List listArg, KeyValuePair kvpArg, ref int refArg) - // Native DAC passes ByRef TypeHandle directly to GetTypeFieldValueFlags which + // Native DAC passes ByRef ITypeHandle directly to GetTypeFieldValueFlags which // returns DEFAULT (ELEMENT_TYPE_BYREF is not IsObjRef, not primitive, etc.). var genericInstArgs = GetArgumentValues("GenericInstAndByRefVars"); AssertEach(genericInstArgs, new Dictionary> diff --git a/src/native/managed/cdac/tests/DumpTests/ObjectiveCMarshalDumpTests.cs b/src/native/managed/cdac/tests/DumpTests/ObjectiveCMarshalDumpTests.cs index e237b3bb344ebc..b5aefff43f0fb3 100644 --- a/src/native/managed/cdac/tests/DumpTests/ObjectiveCMarshalDumpTests.cs +++ b/src/native/managed/cdac/tests/DumpTests/ObjectiveCMarshalDumpTests.cs @@ -40,7 +40,7 @@ private List FindTrackedObjects() if (mt == TargetPointer.Null) continue; - TypeHandle typeHandle = rtsContract.GetTypeHandle(mt); + ITypeHandle typeHandle = rtsContract.GetTypeHandle(mt); if (rtsContract.IsTrackedReferenceWithFinalizer(typeHandle)) results.Add(objectAddress); } diff --git a/src/native/managed/cdac/tests/DumpTests/RuntimeTypeSystemDumpTests.cs b/src/native/managed/cdac/tests/DumpTests/RuntimeTypeSystemDumpTests.cs index 9960f1b6469eea..f01c9da1a06d08 100644 --- a/src/native/managed/cdac/tests/DumpTests/RuntimeTypeSystemDumpTests.cs +++ b/src/native/managed/cdac/tests/DumpTests/RuntimeTypeSystemDumpTests.cs @@ -48,7 +48,7 @@ public void RuntimeTypeSystem_ObjectMethodTableIsValid(TestConfiguration config) TargetPointer objectMT = Target.ReadPointer(objectMTGlobal); Assert.NotEqual(TargetPointer.Null, objectMT); - TypeHandle handle = rts.GetTypeHandle(objectMT); + ITypeHandle handle = rts.GetTypeHandle(objectMT); Assert.False(rts.IsFreeObjectMethodTable(handle)); Assert.True(rts.IsObject(handle)); } @@ -65,7 +65,7 @@ public void RuntimeTypeSystem_FreeObjectMethodTableIsValid(TestConfiguration con TargetPointer freeObjMT = Target.ReadPointer(freeObjMTGlobal); Assert.NotEqual(TargetPointer.Null, freeObjMT); - TypeHandle handle = rts.GetTypeHandle(freeObjMT); + ITypeHandle handle = rts.GetTypeHandle(freeObjMT); Assert.True(rts.IsFreeObjectMethodTable(handle)); Assert.False(rts.IsObject(handle)); } @@ -82,7 +82,7 @@ public void RuntimeTypeSystem_StringMethodTableIsString(TestConfiguration config TargetPointer stringMT = Target.ReadPointer(stringMTGlobal); Assert.NotEqual(TargetPointer.Null, stringMT); - TypeHandle handle = rts.GetTypeHandle(stringMT); + ITypeHandle handle = rts.GetTypeHandle(stringMT); Assert.True(rts.IsString(handle)); Assert.False(rts.IsObject(handle)); } @@ -96,7 +96,7 @@ public void RuntimeTypeSystem_ObjectMethodTableHasParent(TestConfiguration confi TargetPointer objectMTGlobal = Target.ReadGlobalPointer("ObjectMethodTable"); TargetPointer objectMT = Target.ReadPointer(objectMTGlobal); - TypeHandle objectHandle = rts.GetTypeHandle(objectMT); + ITypeHandle objectHandle = rts.GetTypeHandle(objectMT); // System.Object has no parent TargetPointer parent = rts.GetParentMethodTable(objectHandle); @@ -115,7 +115,7 @@ public void RuntimeTypeSystem_StringHasObjectParent(TestConfiguration config) TargetPointer stringMTGlobal = Target.ReadGlobalPointer("StringMethodTable"); TargetPointer stringMT = Target.ReadPointer(stringMTGlobal); - TypeHandle stringHandle = rts.GetTypeHandle(stringMT); + ITypeHandle stringHandle = rts.GetTypeHandle(stringMT); // System.String's parent should be System.Object TargetPointer parent = rts.GetParentMethodTable(stringHandle); @@ -131,7 +131,7 @@ public void RuntimeTypeSystem_ObjectMethodTableHasReasonableBaseSize(TestConfigu TargetPointer objectMTGlobal = Target.ReadGlobalPointer("ObjectMethodTable"); TargetPointer objectMT = Target.ReadPointer(objectMTGlobal); - TypeHandle handle = rts.GetTypeHandle(objectMT); + ITypeHandle handle = rts.GetTypeHandle(objectMT); uint baseSize = rts.GetBaseSize(handle); Assert.True(baseSize > 0 && baseSize < 1024, @@ -147,7 +147,7 @@ public void RuntimeTypeSystem_StringHasNonZeroComponentSize(TestConfiguration co TargetPointer stringMTGlobal = Target.ReadGlobalPointer("StringMethodTable"); TargetPointer stringMT = Target.ReadPointer(stringMTGlobal); - TypeHandle handle = rts.GetTypeHandle(stringMT); + ITypeHandle handle = rts.GetTypeHandle(stringMT); // String has a component size (char size = 2) uint componentSize = rts.GetComponentSize(handle); @@ -163,7 +163,7 @@ public void RuntimeTypeSystem_ObjectMethodTableContainsNoGCPointers(TestConfigur TargetPointer objectMTGlobal = Target.ReadGlobalPointer("ObjectMethodTable"); TargetPointer objectMT = Target.ReadPointer(objectMTGlobal); - TypeHandle handle = rts.GetTypeHandle(objectMT); + ITypeHandle handle = rts.GetTypeHandle(objectMT); // System.Object has no GC-tracked fields Assert.False(rts.ContainsGCPointers(handle)); @@ -178,7 +178,7 @@ public void RuntimeTypeSystem_ObjectMethodTableHasValidToken(TestConfiguration c TargetPointer objectMTGlobal = Target.ReadGlobalPointer("ObjectMethodTable"); TargetPointer objectMT = Target.ReadPointer(objectMTGlobal); - TypeHandle handle = rts.GetTypeHandle(objectMT); + ITypeHandle handle = rts.GetTypeHandle(objectMT); uint token = rts.GetTypeDefToken(handle); // TypeDef tokens have the form 0x02xxxxxx @@ -194,7 +194,7 @@ public void RuntimeTypeSystem_ObjectMethodTableHasMethods(TestConfiguration conf TargetPointer objectMTGlobal = Target.ReadGlobalPointer("ObjectMethodTable"); TargetPointer objectMT = Target.ReadPointer(objectMTGlobal); - TypeHandle handle = rts.GetTypeHandle(objectMT); + ITypeHandle handle = rts.GetTypeHandle(objectMT); ushort numMethods = rts.GetNumMethods(handle); // System.Object has ToString, Equals, GetHashCode, Finalize, etc. @@ -210,7 +210,7 @@ public void RuntimeTypeSystem_StringIsNotGenericTypeDefinition(TestConfiguration TargetPointer stringMTGlobal = Target.ReadGlobalPointer("StringMethodTable"); TargetPointer stringMT = Target.ReadPointer(stringMTGlobal); - TypeHandle handle = rts.GetTypeHandle(stringMT); + ITypeHandle handle = rts.GetTypeHandle(stringMT); Assert.False(rts.IsGenericTypeDefinition(handle)); } @@ -224,7 +224,7 @@ public void RuntimeTypeSystem_StringCorElementTypeIsClass(TestConfiguration conf TargetPointer stringMTGlobal = Target.ReadGlobalPointer("StringMethodTable"); TargetPointer stringMT = Target.ReadPointer(stringMTGlobal); - TypeHandle handle = rts.GetTypeHandle(stringMT); + ITypeHandle handle = rts.GetTypeHandle(stringMT); // GetSignatureCorElementType returns the MethodTable's stored CorElementType, // which is Class for System.String (not CorElementType.String) @@ -243,11 +243,11 @@ public void RuntimeTypeSystem_IsCorElementTypeObjRef_AreConsistent(TestConfigura TargetPointer stringMT = Target.ReadPointer(Target.ReadGlobalPointer("StringMethodTable")); TargetPointer objectArrayMT = Target.ReadPointer(Target.ReadGlobalPointer("ObjectArrayMethodTable")); - TypeHandle objectHandle = rts.GetTypeHandle(objectMT); - TypeHandle stringHandle = rts.GetTypeHandle(stringMT); - TypeHandle objectArrayHandle = rts.GetTypeHandle(objectArrayMT); + ITypeHandle objectHandle = rts.GetTypeHandle(objectMT); + ITypeHandle stringHandle = rts.GetTypeHandle(stringMT); + ITypeHandle objectArrayHandle = rts.GetTypeHandle(objectArrayMT); - TypeHandle intPtrHandle = Target.Contracts.ManagedTypeSource.GetTypeHandle("System.IntPtr"); + ITypeHandle intPtrHandle = Target.Contracts.ManagedTypeSource.GetTypeHandle("System.IntPtr"); Assert.True(rts.IsCorElementTypeObjRef(rts.GetInternalCorElementType(objectHandle))); Assert.True(rts.IsCorElementTypeObjRef(rts.GetInternalCorElementType(stringHandle))); @@ -264,7 +264,7 @@ public void RuntimeTypeSystem_ObjectMethodTableHasIntroducedMethods(TestConfigur TargetPointer objectMTGlobal = Target.ReadGlobalPointer("ObjectMethodTable"); TargetPointer objectMT = Target.ReadPointer(objectMTGlobal); - TypeHandle handle = rts.GetTypeHandle(objectMT); + ITypeHandle handle = rts.GetTypeHandle(objectMT); IEnumerable methodDescs = rts.GetIntroducedMethodDescs(handle); List methods = methodDescs.ToList(); @@ -291,7 +291,7 @@ public void RuntimeTypeSystem_ObjectMethodTableHasLoadedModule(TestConfiguration TargetPointer objectMTGlobal = Target.ReadGlobalPointer("ObjectMethodTable"); TargetPointer objectMT = Target.ReadPointer(objectMTGlobal); - TypeHandle handle = rts.GetTypeHandle(objectMT); + ITypeHandle handle = rts.GetTypeHandle(objectMT); TargetPointer modulePointer = rts.GetModule(handle); Assert.NotEqual(TargetPointer.Null, modulePointer); @@ -311,7 +311,7 @@ public void RuntimeTypeSystem_StringMethodTableHasLoadedModule(TestConfiguration TargetPointer stringMTGlobal = Target.ReadGlobalPointer("StringMethodTable"); TargetPointer stringMT = Target.ReadPointer(stringMTGlobal); - TypeHandle handle = rts.GetTypeHandle(stringMT); + ITypeHandle handle = rts.GetTypeHandle(stringMT); TargetPointer modulePointer = rts.GetModule(handle); Assert.NotEqual(TargetPointer.Null, modulePointer); @@ -333,7 +333,7 @@ public void RuntimeTypeSystem_ConcreteTypesDoNotContainGenericVariables(TestConf { TargetPointer mtGlobal = Target.ReadGlobalPointer(globalName); TargetPointer mt = Target.ReadPointer(mtGlobal); - TypeHandle handle = rts.GetTypeHandle(mt); + ITypeHandle handle = rts.GetTypeHandle(mt); Assert.False(rts.ContainsGenericVariables(handle), $"{globalName} should not contain generic variables"); } @@ -356,12 +356,12 @@ public void RuntimeTypeSystem_IsValueType(TestConfiguration config) Assert.False(rts.IsValueType(rts.GetTypeHandle(stringMT))); // Int32 is a value type (TruePrimitive category) - TypeHandle int32Type = Target.Contracts.ManagedTypeSource.GetTypeHandle("System.Int32"); + ITypeHandle int32Type = Target.Contracts.ManagedTypeSource.GetTypeHandle("System.Int32"); Assert.True(int32Type.Address != 0, "Could not find Int32 type in CoreLib"); Assert.True(rts.IsValueType(int32Type)); // Nullable<> is a value type (Category_Nullable) — loaded because Container.Value is int? - TypeHandle nullableType = Target.Contracts.ManagedTypeSource.GetTypeHandle("System.Nullable`1"); + ITypeHandle nullableType = Target.Contracts.ManagedTypeSource.GetTypeHandle("System.Nullable`1"); Assert.True(nullableType.Address != 0, "Could not find Nullable<> type in CoreLib"); Assert.True(rts.IsValueType(nullableType)); } @@ -376,7 +376,7 @@ public void RuntimeTypeSystem_GenericTypeDefinitionContainsGenericVariables(Test // Look up the generic type definition List<> in System.Private.CoreLib. // The debuggee instantiates List, so the runtime has loaded // both the closed List MT and the open List type definition MT. - TypeHandle listTypeDef = Target.Contracts.ManagedTypeSource.GetTypeHandle( + ITypeHandle listTypeDef = Target.Contracts.ManagedTypeSource.GetTypeHandle( "System.Collections.Generic.List`1"); Assert.True(listTypeDef.Address != 0, "Could not find List<> type definition in CoreLib"); diff --git a/src/native/managed/cdac/tests/UnitTests/CodeVersionsTests.cs b/src/native/managed/cdac/tests/UnitTests/CodeVersionsTests.cs index 0758ea776d196a..742662c4266d4d 100644 --- a/src/native/managed/cdac/tests/UnitTests/CodeVersionsTests.cs +++ b/src/native/managed/cdac/tests/UnitTests/CodeVersionsTests.cs @@ -115,7 +115,7 @@ public static void AddMethodDesc(this Mock mock, CodeVersion public static void AddMethodTable(this Mock mock, MockCodeVersions builder, CodeVersionsMockMethodTable methodTable) { - TypeHandle handle = new TypeHandle(methodTable.Address); + ITypeHandle handle = new TargetTypeHandle(methodTable.Address); mock.Setup(r => r.GetTypeHandle(methodTable.Address)).Returns(address => { // this is not quite accurate on 32 bit architectures, but it's good enough for testing diff --git a/src/native/managed/cdac/tests/UnitTests/DacDbiImplTests.cs b/src/native/managed/cdac/tests/UnitTests/DacDbiImplTests.cs index 0d2e46764d1c6b..01af6e49583646 100644 --- a/src/native/managed/cdac/tests/UnitTests/DacDbiImplTests.cs +++ b/src/native/managed/cdac/tests/UnitTests/DacDbiImplTests.cs @@ -321,8 +321,8 @@ public void IsExceptionObject(MockTarget.Architecture arch, int inheritanceDepth mockRts.Setup(r => r.GetWellKnownMethodTable(WellKnownMethodTable.Exception)).Returns(exceptionMT); if (intermediateMTs.Length == 0 && !isException) { - mockRts.Setup(r => r.GetTypeHandle(objectMT)).Returns(new TypeHandle(objectMT)); - mockRts.Setup(r => r.GetParentMethodTable(new TypeHandle(objectMT))).Returns(TargetPointer.Null); + mockRts.Setup(r => r.GetTypeHandle(objectMT)).Returns(new TargetTypeHandle(objectMT)); + mockRts.Setup(r => r.GetParentMethodTable(new TargetTypeHandle(objectMT))).Returns(TargetPointer.Null); } for (int i = 0; i < intermediateMTs.Length; i++) { @@ -331,8 +331,8 @@ public void IsExceptionObject(MockTarget.Architecture arch, int inheritanceDepth ? intermediateMTs[i + 1] : isException ? exceptionMT : TargetPointer.Null; - mockRts.Setup(r => r.GetTypeHandle(current)).Returns(new TypeHandle(current)); - mockRts.Setup(r => r.GetParentMethodTable(new TypeHandle(current))).Returns(parent); + mockRts.Setup(r => r.GetTypeHandle(current)).Returns(new TargetTypeHandle(current)); + mockRts.Setup(r => r.GetParentMethodTable(new TargetTypeHandle(current))).Returns(parent); } var (dacDbi, _) = CreateDacDbiWithExceptionMT(arch, mockObject, mockRts); diff --git a/src/native/managed/cdac/tests/UnitTests/ExceptionTests.cs b/src/native/managed/cdac/tests/UnitTests/ExceptionTests.cs index 3f4e527eb91fee..a05f5f556251a4 100644 --- a/src/native/managed/cdac/tests/UnitTests/ExceptionTests.cs +++ b/src/native/managed/cdac/tests/UnitTests/ExceptionTests.cs @@ -199,14 +199,14 @@ private static IException CreateContract(MockTarget.Architecture arch, StackTrac Name = "CombinedPtrArray", }); - TypeHandle combinedHandle = new(CombinedArrayMTAddr); + ITypeHandle combinedHandle = new TargetTypeHandle(CombinedArrayMTAddr); objectMock.Setup(o => o.GetMethodTableAddress(CombinedArrayAddr)).Returns(CombinedArrayMTAddr); rtsMock.Setup(r => r.GetTypeHandle(CombinedArrayMTAddr)).Returns(combinedHandle); rtsMock.Setup(r => r.ContainsGCPointers(combinedHandle)).Returns(true); } else { - TypeHandle i1Handle = new(StackTraceMTAddr); + ITypeHandle i1Handle = new TargetTypeHandle(StackTraceMTAddr); objectMock.Setup(o => o.GetMethodTableAddress(StackTraceObjectAddr)).Returns(StackTraceMTAddr); rtsMock.Setup(r => r.GetTypeHandle(StackTraceMTAddr)).Returns(i1Handle); rtsMock.Setup(r => r.ContainsGCPointers(i1Handle)).Returns(false); diff --git a/src/native/managed/cdac/tests/UnitTests/MethodDescTests.cs b/src/native/managed/cdac/tests/UnitTests/MethodDescTests.cs index e16b21181b980f..b8197106910749 100644 --- a/src/native/managed/cdac/tests/UnitTests/MethodDescTests.cs +++ b/src/native/managed/cdac/tests/UnitTests/MethodDescTests.cs @@ -295,7 +295,7 @@ public void IsGenericMethodDefinition(MockTarget.Architecture arch) MethodDescHandle handle = rts.GetMethodDescHandle(genericMethodDef); Assert.NotEqual(TargetPointer.Null, handle.Address); Assert.True(rts.IsGenericMethodDefinition(handle)); - ReadOnlySpan instantiation = rts.GetGenericMethodInstantiation(handle); + ITypeHandle[] instantiation = rts.GetGenericMethodInstantiation(handle); Assert.Equal(0, instantiation.Length); } @@ -303,7 +303,7 @@ public void IsGenericMethodDefinition(MockTarget.Architecture arch) MethodDescHandle handle = rts.GetMethodDescHandle(genericWithInst); Assert.NotEqual(TargetPointer.Null, handle.Address); Assert.True(rts.IsGenericMethodDefinition(handle)); - ReadOnlySpan instantiation = rts.GetGenericMethodInstantiation(handle); + ITypeHandle[] instantiation = rts.GetGenericMethodInstantiation(handle); Assert.Equal(typeArgsRawAddrs.Length, instantiation.Length); for (int i = 0; i < typeArgsRawAddrs.Length; i++) { diff --git a/src/native/managed/cdac/tests/UnitTests/MethodTableTests.cs b/src/native/managed/cdac/tests/UnitTests/MethodTableTests.cs index 17f2901ed05c9c..b474bc202cc046 100644 --- a/src/native/managed/cdac/tests/UnitTests/MethodTableTests.cs +++ b/src/native/managed/cdac/tests/UnitTests/MethodTableTests.cs @@ -77,7 +77,7 @@ public void HasRuntimeTypeSystemContract(MockTarget.Architecture arch) builder => freeObjectMethodTableAddress = builder.FreeObjectMethodTableAddress); IRuntimeTypeSystem contract = target.Contracts.RuntimeTypeSystem; - Contracts.TypeHandle handle = contract.GetTypeHandle(freeObjectMethodTableAddress); + Contracts.ITypeHandle handle = contract.GetTypeHandle(freeObjectMethodTableAddress); Assert.NotEqual(TargetPointer.Null, handle.Address); Assert.True(contract.IsFreeObjectMethodTable(handle)); Assert.False(contract.IsObject(handle)); @@ -93,7 +93,7 @@ public void ValidateSystemObjectMethodTable(MockTarget.Architecture arch) rtsBuilder => systemObjectMethodTablePtr = rtsBuilder.SystemObjectMethodTable.Address); IRuntimeTypeSystem contract = target.Contracts.RuntimeTypeSystem; - Contracts.TypeHandle systemObjectTypeHandle = contract.GetTypeHandle(systemObjectMethodTablePtr); + Contracts.ITypeHandle systemObjectTypeHandle = contract.GetTypeHandle(systemObjectMethodTablePtr); Assert.Equal(systemObjectMethodTablePtr.Value, systemObjectTypeHandle.Address.Value); Assert.False(contract.IsFreeObjectMethodTable(systemObjectTypeHandle)); Assert.True(contract.IsObject(systemObjectTypeHandle)); @@ -133,7 +133,7 @@ public void ValidateSystemStringMethodTable(MockTarget.Architecture arch) }); IRuntimeTypeSystem contract = target.Contracts.RuntimeTypeSystem; - Contracts.TypeHandle systemStringTypeHandle = contract.GetTypeHandle(systemStringMethodTablePtr); + Contracts.ITypeHandle systemStringTypeHandle = contract.GetTypeHandle(systemStringMethodTablePtr); Assert.Equal(systemStringMethodTablePtr.Value, systemStringTypeHandle.Address.Value); Assert.False(contract.IsFreeObjectMethodTable(systemStringTypeHandle)); Assert.True(contract.IsString(systemStringTypeHandle)); @@ -243,7 +243,7 @@ public void ValidateGenericInstMethodTable(MockTarget.Architecture arch) }); IRuntimeTypeSystem contract = target.Contracts.RuntimeTypeSystem; - Contracts.TypeHandle genericInstanceTypeHandle = contract.GetTypeHandle(genericInstanceMethodTablePtr); + Contracts.ITypeHandle genericInstanceTypeHandle = contract.GetTypeHandle(genericInstanceMethodTablePtr); Assert.Equal(genericInstanceMethodTablePtr.Value, genericInstanceTypeHandle.Address.Value); Assert.False(contract.IsFreeObjectMethodTable(genericInstanceTypeHandle)); Assert.False(contract.IsString(genericInstanceTypeHandle)); @@ -299,7 +299,7 @@ public void ValidateArrayInstMethodTable(MockTarget.Architecture arch) }); IRuntimeTypeSystem contract = target.Contracts.RuntimeTypeSystem; - Contracts.TypeHandle arrayInstanceTypeHandle = contract.GetTypeHandle(arrayInstanceMethodTablePtr); + Contracts.ITypeHandle arrayInstanceTypeHandle = contract.GetTypeHandle(arrayInstanceMethodTablePtr); Assert.Equal(arrayInstanceMethodTablePtr.Value, arrayInstanceTypeHandle.Address.Value); Assert.False(contract.IsFreeObjectMethodTable(arrayInstanceTypeHandle)); Assert.False(contract.IsString(arrayInstanceTypeHandle)); @@ -362,7 +362,7 @@ public void IsContinuationWithoutMetadata_ReturnsTrueForContinuationType(MockTar }); IRuntimeTypeSystem contract = target.Contracts.RuntimeTypeSystem; - Contracts.TypeHandle continuationTypeHandle = contract.GetTypeHandle(continuationInstanceMethodTablePtr); + Contracts.ITypeHandle continuationTypeHandle = contract.GetTypeHandle(continuationInstanceMethodTablePtr); Assert.True(contract.IsContinuationWithoutMetadata(continuationTypeHandle)); Assert.False(contract.IsFreeObjectMethodTable(continuationTypeHandle)); Assert.False(contract.IsString(continuationTypeHandle)); @@ -461,11 +461,11 @@ public void ValidateMultidimArrayRank(MockTarget.Architecture arch) }); IRuntimeTypeSystem contract = target.Contracts.RuntimeTypeSystem; - Contracts.TypeHandle rank4Handle = contract.GetTypeHandle(rank4MethodTablePtr); + Contracts.ITypeHandle rank4Handle = contract.GetTypeHandle(rank4MethodTablePtr); Assert.True(contract.IsArray(rank4Handle, out uint rank4)); Assert.Equal(4u, rank4); - Contracts.TypeHandle rank1Handle = contract.GetTypeHandle(rank1MultiDimMethodTablePtr); + Contracts.ITypeHandle rank1Handle = contract.GetTypeHandle(rank1MultiDimMethodTablePtr); Assert.True(contract.IsArray(rank1Handle, out uint rank1)); Assert.Equal(1u, rank1); } @@ -495,10 +495,10 @@ public void IsContinuationWithoutMetadata_ReturnsFalseWhenGlobalIsNull(MockTarge }); IRuntimeTypeSystem contract = target.Contracts.RuntimeTypeSystem; - Contracts.TypeHandle objectTypeHandle = contract.GetTypeHandle(systemObjectMethodTablePtr); + Contracts.ITypeHandle objectTypeHandle = contract.GetTypeHandle(systemObjectMethodTablePtr); Assert.False(contract.IsContinuationWithoutMetadata(objectTypeHandle)); - Contracts.TypeHandle childTypeHandle = contract.GetTypeHandle(childMethodTablePtr); + Contracts.ITypeHandle childTypeHandle = contract.GetTypeHandle(childMethodTablePtr); Assert.False(contract.IsContinuationWithoutMetadata(childTypeHandle)); } @@ -532,7 +532,7 @@ public void ValidateContinuationMethodTablePointer(MockTarget.Architecture arch) }); IRuntimeTypeSystem contract = target.Contracts.RuntimeTypeSystem; - Contracts.TypeHandle continuationTypeHandle = contract.GetTypeHandle(continuationInstanceMethodTablePtr); + Contracts.ITypeHandle continuationTypeHandle = contract.GetTypeHandle(continuationInstanceMethodTablePtr); Assert.Equal(continuationInstanceMethodTablePtr.Value, continuationTypeHandle.Address.Value); Assert.True(contract.IsContinuationWithoutMetadata(continuationTypeHandle)); } @@ -560,7 +560,7 @@ public void IsContinuationWithoutMetadata_ReturnsTrueForSingletonEEClass(MockTar }); IRuntimeTypeSystem contract = target.Contracts.RuntimeTypeSystem; - TypeHandle continuationTypeHandle = contract.GetTypeHandle(continuationInstanceMethodTablePtr); + ITypeHandle continuationTypeHandle = contract.GetTypeHandle(continuationInstanceMethodTablePtr); Assert.True(contract.IsContinuationWithoutMetadata(continuationTypeHandle)); } @@ -588,7 +588,7 @@ public void IsContinuationWithoutMetadata_ReturnsFalseForOwnEEClass(MockTarget.A }); IRuntimeTypeSystem contract = target.Contracts.RuntimeTypeSystem; - TypeHandle continuationTypeHandle = contract.GetTypeHandle(continuationInstanceMethodTablePtr); + ITypeHandle continuationTypeHandle = contract.GetTypeHandle(continuationInstanceMethodTablePtr); Assert.False(contract.IsContinuationWithoutMetadata(continuationTypeHandle)); } @@ -602,7 +602,7 @@ public void IsContinuationWithoutMetadata_ReturnsFalseForRegularType(MockTarget. rtsBuilder => systemObjectMethodTablePtr = rtsBuilder.SystemObjectMethodTable.Address); IRuntimeTypeSystem contract = target.Contracts.RuntimeTypeSystem; - TypeHandle objectTypeHandle = contract.GetTypeHandle(systemObjectMethodTablePtr); + ITypeHandle objectTypeHandle = contract.GetTypeHandle(systemObjectMethodTablePtr); Assert.False(contract.IsContinuationWithoutMetadata(objectTypeHandle)); } @@ -641,10 +641,10 @@ public void IsCanonicalMethodTable_ReturnsTrueForCanonicalAndFalseForNonCanonica IRuntimeTypeSystem contract = target.Contracts.RuntimeTypeSystem; - TypeHandle canonTh = contract.GetTypeHandle(canonicalMethodTablePtr); + ITypeHandle canonTh = contract.GetTypeHandle(canonicalMethodTablePtr); Assert.True(contract.IsCanonicalMethodTable(canonTh)); - TypeHandle nonCanonTh = contract.GetTypeHandle(nonCanonicalMethodTablePtr); + ITypeHandle nonCanonTh = contract.GetTypeHandle(nonCanonicalMethodTablePtr); Assert.False(contract.IsCanonicalMethodTable(nonCanonTh)); // Both canonical and non-canonical MTs should resolve to the same EEClass @@ -846,7 +846,7 @@ public void RequiresAlign8(MockTarget.Architecture arch, bool flagSet) }); IRuntimeTypeSystem contract = target.Contracts.RuntimeTypeSystem; - Contracts.TypeHandle typeHandle = contract.GetTypeHandle(methodTablePtr); + Contracts.ITypeHandle typeHandle = contract.GetTypeHandle(methodTablePtr); Assert.Equal(flagSet, contract.RequiresAlign8(typeHandle)); } @@ -865,7 +865,7 @@ public void GetGCDescSeriesReturnsEmptyForNonMethodTable(MockTarget.Architecture }); IRuntimeTypeSystem contract = target.Contracts.RuntimeTypeSystem; - Contracts.TypeHandle typeDescHandle = contract.GetTypeHandle(typeDescAddress); + Contracts.ITypeHandle typeDescHandle = contract.GetTypeHandle(typeDescAddress); Assert.Empty(contract.GetGCDescSeries(typeDescHandle)); } @@ -891,7 +891,7 @@ public void GetGCDescSeriesReturnsEmptyWhenNoGCPointers(MockTarget.Architecture }); IRuntimeTypeSystem contract = target.Contracts.RuntimeTypeSystem; - Contracts.TypeHandle typeHandle = contract.GetTypeHandle(mtPtr); + Contracts.ITypeHandle typeHandle = contract.GetTypeHandle(mtPtr); Assert.False(contract.ContainsGCPointers(typeHandle)); Assert.Empty(contract.GetGCDescSeries(typeHandle)); } @@ -938,7 +938,7 @@ public void GetGCDescSeriesReturnsSingleSeries(MockTarget.Architecture arch) }); IRuntimeTypeSystem contract = target.Contracts.RuntimeTypeSystem; - Contracts.TypeHandle typeHandle = contract.GetTypeHandle(mtPtr); + Contracts.ITypeHandle typeHandle = contract.GetTypeHandle(mtPtr); Assert.True(contract.ContainsGCPointers(typeHandle)); (uint Offset, uint Size)[] series = contract.GetGCDescSeries(typeHandle).ToArray(); @@ -993,7 +993,7 @@ public void GetGCDescSeriesReturnsMultipleSeriesInOrder(MockTarget.Architecture }); IRuntimeTypeSystem contract = target.Contracts.RuntimeTypeSystem; - Contracts.TypeHandle typeHandle = contract.GetTypeHandle(mtPtr); + Contracts.ITypeHandle typeHandle = contract.GetTypeHandle(mtPtr); (uint Offset, uint Size)[] series = contract.GetGCDescSeries(typeHandle).ToArray(); Assert.Equal(expectedSeries.Length, series.Length); @@ -1049,7 +1049,7 @@ public void GetGCDescSeriesReturnsSingleValueClassSeries(MockTarget.Architecture }); IRuntimeTypeSystem contract = target.Contracts.RuntimeTypeSystem; - Contracts.TypeHandle typeHandle = contract.GetTypeHandle(mtPtr); + Contracts.ITypeHandle typeHandle = contract.GetTypeHandle(mtPtr); Assert.True(contract.ContainsGCPointers(typeHandle)); // Pass numComponents=1 because value-class GCDesc iterates one element per component. @@ -1108,7 +1108,7 @@ public void GetGCDescSeriesReturnsMultipleValueClassSeries(MockTarget.Architectu }); IRuntimeTypeSystem contract = target.Contracts.RuntimeTypeSystem; - Contracts.TypeHandle typeHandle = contract.GetTypeHandle(mtPtr); + Contracts.ITypeHandle typeHandle = contract.GetTypeHandle(mtPtr); // Pass numComponents=1 because value-class GCDesc iterates one element per component. (uint Offset, uint Size)[] series = contract.GetGCDescSeries(typeHandle, 1).ToArray(); @@ -1169,7 +1169,7 @@ public void GetGCDescSeriesRegularSeriesWithArrayNumComponents(MockTarget.Archit }); IRuntimeTypeSystem contract = target.Contracts.RuntimeTypeSystem; - Contracts.TypeHandle typeHandle = contract.GetTypeHandle(mtPtr); + Contracts.ITypeHandle typeHandle = contract.GetTypeHandle(mtPtr); Assert.True(contract.ContainsGCPointers(typeHandle)); uint pointerSz = (uint)target.PointerSize; @@ -1227,7 +1227,7 @@ public void GetGCDescSeriesValueClassRepeatingWithArrayNumComponents(MockTarget. }); IRuntimeTypeSystem contract = target.Contracts.RuntimeTypeSystem; - Contracts.TypeHandle typeHandle = contract.GetTypeHandle(mtPtr); + Contracts.ITypeHandle typeHandle = contract.GetTypeHandle(mtPtr); Assert.True(contract.ContainsGCPointers(typeHandle)); uint elemSize = 2 * (uint)target.PointerSize; uint startOff = 3u * (uint)target.PointerSize; diff --git a/src/native/managed/cdac/tests/UnitTests/ObjectTests.cs b/src/native/managed/cdac/tests/UnitTests/ObjectTests.cs index 8e5d367eebdabd..d721f9b4fb7c30 100644 --- a/src/native/managed/cdac/tests/UnitTests/ObjectTests.cs +++ b/src/native/managed/cdac/tests/UnitTests/ObjectTests.cs @@ -295,7 +295,7 @@ public void GetObjectClassName_UnloadedModule(MockTarget.Architecture arch) }, builder => { var mockRts = new Mock(); - TypeHandle handle = new TypeHandle(TestMethodTableAddress); + ITypeHandle handle = new TargetTypeHandle(TestMethodTableAddress); mockRts.Setup(r => r.GetTypeHandle(TestMethodTableAddress)).Returns(handle); mockRts.Setup(r => r.GetModule(handle)).Returns(TargetPointer.Null); @@ -343,7 +343,7 @@ public void GetObjectClassName_NullBufferReturnsNeededSize(MockTarget.Architectu }, builder => { var mockRts = new Mock(); - TypeHandle handle = new TypeHandle(TestMethodTableAddress); + ITypeHandle handle = new TargetTypeHandle(TestMethodTableAddress); mockRts.Setup(r => r.GetTypeHandle(TestMethodTableAddress)).Returns(handle); mockRts.Setup(r => r.GetModule(handle)).Returns(TargetPointer.Null); diff --git a/src/native/managed/cdac/tests/UnitTests/RuntimeMutableTypeSystemTests.cs b/src/native/managed/cdac/tests/UnitTests/RuntimeMutableTypeSystemTests.cs index 5134255237294d..9058be1b6d3b9c 100644 --- a/src/native/managed/cdac/tests/UnitTests/RuntimeMutableTypeSystemTests.cs +++ b/src/native/managed/cdac/tests/UnitTests/RuntimeMutableTypeSystemTests.cs @@ -45,8 +45,8 @@ private static (Mock Rts, Mock Loader) CreateMocks( ModuleFlags flags) { var rts = new Mock(); - rts.Setup(r => r.GetTypeHandle(mtPtr)).Returns(new TypeHandle(mtPtr)); - rts.Setup(r => r.GetModule(It.Is(th => th.Address == mtPtr))).Returns(modulePtr); + rts.Setup(r => r.GetTypeHandle(mtPtr)).Returns(new TargetTypeHandle(mtPtr)); + rts.Setup(r => r.GetModule(It.Is(th => th.Address == mtPtr))).Returns(modulePtr); var loader = new Mock(); Contracts.ModuleHandle moduleHandle = new Contracts.ModuleHandle(modulePtr); @@ -72,7 +72,7 @@ public void TypeDescHandle_ReturnsEmpty(MockTarget.Architecture arch) IRuntimeMutableTypeSystem contract = target.Contracts.RuntimeMutableTypeSystem; Assert.NotNull(contract); - TypeHandle th = target.Contracts.RuntimeTypeSystem.GetTypeHandle(tdPtr); + ITypeHandle th = target.Contracts.RuntimeTypeSystem.GetTypeHandle(tdPtr); Assert.Empty(contract.EnumerateAddedFieldDescs(th, staticFields: false)); Assert.Empty(contract.EnumerateAddedFieldDescs(th, staticFields: true)); } @@ -92,7 +92,7 @@ public void EnCNotEnabled_ReturnsEmpty(MockTarget.Architecture arch) TestPlaceholderTarget target = CreateTarget(arch, builder, rts, loader); IRuntimeMutableTypeSystem contract = target.Contracts.RuntimeMutableTypeSystem; - TypeHandle th = target.Contracts.RuntimeTypeSystem.GetTypeHandle(mtPtr); + ITypeHandle th = target.Contracts.RuntimeTypeSystem.GetTypeHandle(mtPtr); Assert.Empty(contract.EnumerateAddedFieldDescs(th, staticFields: false)); Assert.Empty(contract.EnumerateAddedFieldDescs(th, staticFields: true)); } @@ -112,7 +112,7 @@ public void NoMatchingClassData_ReturnsEmpty(MockTarget.Architecture arch) TestPlaceholderTarget target = CreateTarget(arch, builder, rts, loader); IRuntimeMutableTypeSystem contract = target.Contracts.RuntimeMutableTypeSystem; - TypeHandle th = target.Contracts.RuntimeTypeSystem.GetTypeHandle(otherMt); + ITypeHandle th = target.Contracts.RuntimeTypeSystem.GetTypeHandle(otherMt); Assert.Empty(contract.EnumerateAddedFieldDescs(th, staticFields: false)); Assert.Empty(contract.EnumerateAddedFieldDescs(th, staticFields: true)); } @@ -129,7 +129,7 @@ public void EmptyClassList_ReturnsEmpty(MockTarget.Architecture arch) TestPlaceholderTarget target = CreateTarget(arch, builder, rts, loader); IRuntimeMutableTypeSystem contract = target.Contracts.RuntimeMutableTypeSystem; - TypeHandle th = target.Contracts.RuntimeTypeSystem.GetTypeHandle(mtPtr); + ITypeHandle th = target.Contracts.RuntimeTypeSystem.GetTypeHandle(mtPtr); Assert.Empty(contract.EnumerateAddedFieldDescs(th, staticFields: false)); Assert.Empty(contract.EnumerateAddedFieldDescs(th, staticFields: true)); } @@ -149,7 +149,7 @@ public void InstanceFields_ReturnedInOrder(MockTarget.Architecture arch) TestPlaceholderTarget target = CreateTarget(arch, builder, rts, loader); IRuntimeMutableTypeSystem contract = target.Contracts.RuntimeMutableTypeSystem; - TypeHandle th = target.Contracts.RuntimeTypeSystem.GetTypeHandle(mtPtr); + ITypeHandle th = target.Contracts.RuntimeTypeSystem.GetTypeHandle(mtPtr); // FieldDesc is the address of the FieldDesc subfield within each element. ulong fieldDescOffset = (ulong)builder.AddedFieldElementLayout.GetField("FieldDesc").Offset; @@ -174,7 +174,7 @@ public void StaticFields_ReturnedInOrder(MockTarget.Architecture arch) TestPlaceholderTarget target = CreateTarget(arch, builder, rts, loader); IRuntimeMutableTypeSystem contract = target.Contracts.RuntimeMutableTypeSystem; - TypeHandle th = target.Contracts.RuntimeTypeSystem.GetTypeHandle(mtPtr); + ITypeHandle th = target.Contracts.RuntimeTypeSystem.GetTypeHandle(mtPtr); ulong fieldDescOffset = (ulong)builder.AddedFieldElementLayout.GetField("FieldDesc").Offset; ulong[] expected = staticElems.Select(e => e.Address + fieldDescOffset).ToArray(); @@ -199,7 +199,7 @@ public void InstanceAndStaticFields_ReturnedSeparately(MockTarget.Architecture a TestPlaceholderTarget target = CreateTarget(arch, builder, rts, loader); IRuntimeMutableTypeSystem contract = target.Contracts.RuntimeMutableTypeSystem; - TypeHandle th = target.Contracts.RuntimeTypeSystem.GetTypeHandle(mtPtr); + ITypeHandle th = target.Contracts.RuntimeTypeSystem.GetTypeHandle(mtPtr); ulong fieldDescOffset = (ulong)builder.AddedFieldElementLayout.GetField("FieldDesc").Offset; Assert.Equal( @@ -227,7 +227,7 @@ public void SecondEntryMatches(MockTarget.Architecture arch) TestPlaceholderTarget target = CreateTarget(arch, builder, rts, loader); IRuntimeMutableTypeSystem contract = target.Contracts.RuntimeMutableTypeSystem; - TypeHandle th = target.Contracts.RuntimeTypeSystem.GetTypeHandle(mtPtr); + ITypeHandle th = target.Contracts.RuntimeTypeSystem.GetTypeHandle(mtPtr); ulong fieldDescOffset = (ulong)builder.AddedFieldElementLayout.GetField("FieldDesc").Offset; ulong[] expected = instanceElems.Select(e => e.Address + fieldDescOffset).ToArray(); diff --git a/src/native/managed/cdac/tests/UnitTests/SOSDacInterface5Tests.cs b/src/native/managed/cdac/tests/UnitTests/SOSDacInterface5Tests.cs index 1da74f6d4d2a19..5e5c6bc79f385d 100644 --- a/src/native/managed/cdac/tests/UnitTests/SOSDacInterface5Tests.cs +++ b/src/native/managed/cdac/tests/UnitTests/SOSDacInterface5Tests.cs @@ -40,7 +40,7 @@ private static ISOSDacInterface5 CreateDac5( ILCodeVersionHandle ilCodeVersion = ILCodeVersionHandle.CreateSynthetic(s_moduleAddr, 0x06000001); MethodDescHandle methodDescHandle = new MethodDescHandle(s_methodDescAddr); - TypeHandle typeHandle = new TypeHandle(s_methodTableAddr); + ITypeHandle typeHandle = new TargetTypeHandle(s_methodTableAddr); Contracts.ModuleHandle moduleHandle = new Contracts.ModuleHandle(s_moduleAddr); mockCodeVersions diff --git a/src/native/managed/cdac/tests/UnitTests/TypeDescTests.cs b/src/native/managed/cdac/tests/UnitTests/TypeDescTests.cs index a93d3d9263a34c..7f269d27e6b380 100644 --- a/src/native/managed/cdac/tests/UnitTests/TypeDescTests.cs +++ b/src/native/managed/cdac/tests/UnitTests/TypeDescTests.cs @@ -47,21 +47,21 @@ public void GetModule(MockTarget.Architecture arch) { // Type var type IRuntimeTypeSystem rts = target.Contracts.RuntimeTypeSystem; - TypeHandle handle = rts.GetTypeHandle(GetTypeDescHandlePointer(varType)); + ITypeHandle handle = rts.GetTypeHandle(GetTypeDescHandlePointer(varType)); TargetPointer actualModule = rts.GetModule(handle); Assert.Equal(module, actualModule); } { // Param type - pointing at var type IRuntimeTypeSystem rts = target.Contracts.RuntimeTypeSystem; - TypeHandle handle = rts.GetTypeHandle(GetTypeDescHandlePointer(paramType)); + ITypeHandle handle = rts.GetTypeHandle(GetTypeDescHandlePointer(paramType)); TargetPointer actualModule = rts.GetModule(handle); Assert.Equal(module, actualModule); } { // Function pointer - always null IRuntimeTypeSystem rts = target.Contracts.RuntimeTypeSystem; - TypeHandle handle = rts.GetTypeHandle(GetTypeDescHandlePointer(funcPtr)); + ITypeHandle handle = rts.GetTypeHandle(GetTypeDescHandlePointer(funcPtr)); TargetPointer actualModule = rts.GetModule(handle); Assert.Equal(TargetPointer.Null, actualModule); } @@ -98,24 +98,24 @@ public void GetTypeParam(MockTarget.Architecture arch) { IRuntimeTypeSystem rts = target.Contracts.RuntimeTypeSystem; - TypeHandle handle = rts.GetTypeHandle(GetTypeDescHandlePointer(paramType)); + ITypeHandle handle = rts.GetTypeHandle(GetTypeDescHandlePointer(paramType)); bool res = rts.HasTypeParam(handle); Assert.True(res); - TypeHandle typeParam = rts.GetTypeParam(handle); + ITypeHandle typeParam = rts.GetTypeParam(handle); Assert.Equal(typePointerHandle, typeParam.Address); Assert.Equal(typePointerRawAddr, typeParam.TypeDescAddress()); } { // Function pointer IRuntimeTypeSystem rts = target.Contracts.RuntimeTypeSystem; - TypeHandle handle = rts.GetTypeHandle(GetTypeDescHandlePointer(funcPtr)); + ITypeHandle handle = rts.GetTypeHandle(GetTypeDescHandlePointer(funcPtr)); bool res = rts.HasTypeParam(handle); Assert.False(res); } { // Type var type IRuntimeTypeSystem rts = target.Contracts.RuntimeTypeSystem; - TypeHandle handle = rts.GetTypeHandle(GetTypeDescHandlePointer(varType)); + ITypeHandle handle = rts.GetTypeHandle(GetTypeDescHandlePointer(varType)); bool res = rts.HasTypeParam(handle); Assert.False(res); } @@ -160,8 +160,8 @@ public void IsFunctionPointer(MockTarget.Architecture arch) { // Function pointer IRuntimeTypeSystem rts = target.Contracts.RuntimeTypeSystem; - TypeHandle handle = rts.GetTypeHandle(GetTypeDescHandlePointer(funcPtr)); - bool res = rts.IsFunctionPointer(handle, out ReadOnlySpan actualRetAndArgTypes, out SignatureCallingConvention actualCallConv); + ITypeHandle handle = rts.GetTypeHandle(GetTypeDescHandlePointer(funcPtr)); + bool res = rts.IsFunctionPointer(handle, out ITypeHandle[] actualRetAndArgTypes, out SignatureCallingConvention actualCallConv); Assert.True(res); Assert.Equal(callConv, (byte)actualCallConv); Assert.Equal(retAndArgTypesHandle.Length, actualRetAndArgTypes.Length); @@ -174,14 +174,14 @@ public void IsFunctionPointer(MockTarget.Architecture arch) { // Param type IRuntimeTypeSystem rts = target.Contracts.RuntimeTypeSystem; - TypeHandle handle = rts.GetTypeHandle(GetTypeDescHandlePointer(paramType)); + ITypeHandle handle = rts.GetTypeHandle(GetTypeDescHandlePointer(paramType)); bool res = rts.IsFunctionPointer(handle, out _, out _); Assert.False(res); } { // Type var type IRuntimeTypeSystem rts = target.Contracts.RuntimeTypeSystem; - TypeHandle handle = rts.GetTypeHandle(GetTypeDescHandlePointer(varType)); + ITypeHandle handle = rts.GetTypeHandle(GetTypeDescHandlePointer(varType)); bool res = rts.IsFunctionPointer(handle, out _, out _); Assert.False(res); } @@ -227,7 +227,7 @@ public void IsGenericVariable(MockTarget.Architecture arch) { // Var IRuntimeTypeSystem rts = target.Contracts.RuntimeTypeSystem; - TypeHandle handle = rts.GetTypeHandle(GetTypeDescHandlePointer(varType)); + ITypeHandle handle = rts.GetTypeHandle(GetTypeDescHandlePointer(varType)); bool res = rts.IsGenericVariable(handle, out TargetPointer actualModule, out uint actualToken); Assert.True(res); Assert.Equal(module, actualModule); @@ -236,7 +236,7 @@ public void IsGenericVariable(MockTarget.Architecture arch) { // MVar IRuntimeTypeSystem rts = target.Contracts.RuntimeTypeSystem; - TypeHandle handle = rts.GetTypeHandle(GetTypeDescHandlePointer(mvarType)); + ITypeHandle handle = rts.GetTypeHandle(GetTypeDescHandlePointer(mvarType)); bool res = rts.IsGenericVariable(handle, out TargetPointer actualModule, out uint actualToken); Assert.True(res); Assert.Equal(module, actualModule); @@ -245,14 +245,14 @@ public void IsGenericVariable(MockTarget.Architecture arch) { // Function pointer IRuntimeTypeSystem rts = target.Contracts.RuntimeTypeSystem; - TypeHandle handle = rts.GetTypeHandle(GetTypeDescHandlePointer(funcPtr)); + ITypeHandle handle = rts.GetTypeHandle(GetTypeDescHandlePointer(funcPtr)); bool res = rts.IsGenericVariable(handle, out _, out _); Assert.False(res); } { // Param type IRuntimeTypeSystem rts = target.Contracts.RuntimeTypeSystem; - TypeHandle handle = rts.GetTypeHandle(GetTypeDescHandlePointer(paramType)); + ITypeHandle handle = rts.GetTypeHandle(GetTypeDescHandlePointer(paramType)); bool res = rts.IsGenericVariable(handle, out _, out _); Assert.False(res); }