-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Signature parsing and GetFieldDescData cDAC API #119417
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 15 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
1b47b26
signature parsing and GetFieldDescData cDAC API
rcj1 61c3aae
Merge branch 'main' into Signature
rcj1 bbc99bc
Fix missing newline at end of contracts.jsonc
rcj1 14d4631
Update src/native/managed/cdac/mscordaccore_universal/Legacy/ISOSDacI…
rcj1 387207c
fix
rcj1 7917e1b
code review
rcj1 00c25b5
Update SignatureDecoder.md
rcj1 b1f541e
code review
rcj1 7efa776
Merge branch 'main' into Signature
rcj1 6b1dc39
fix bad merge
rcj1 f38a02a
fixing custom modifiers and not-founds
rcj1 b6a8e71
cache and renaming
rcj1 538ba6f
loadlevel
rcj1 c51cfbf
e
rcj1 fc947e0
Merge branch 'main' into Signature
rcj1 17c4634
Apply suggestions from code review
rcj1 434bfad
code review
rcj1 9023b01
Merge branch 'main' into Signature
rcj1 cfd962c
codereview
rcj1 6c326e1
merge
rcj1 13e30e1
small edits
rcj1 2cfa600
Update src/coreclr/vm/datadescriptor/datadescriptor.inc
rcj1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
# Contract SignatureDecoder | ||
|
||
This contract encapsulates signature decoding in the cDAC. | ||
rcj1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
## APIs of contract | ||
|
||
```csharp | ||
TypeHandle DecodeFieldSignature(BlobHandle blobHandle, ModuleHandle moduleHandle, TypeHandle ctx); | ||
``` | ||
|
||
## Version 1 | ||
|
||
In version 1 of the SignatureDecoder contract we take advantage of the System.Reflection.Metadata signature decoding. We implement a SignatureTypeProvider that inherits from System.Reflection.Metadata ISignatureTypeProvider. | ||
|
||
Data descriptors used: | ||
| Data Descriptor Name | Field | Meaning | | ||
| --- | --- | --- | | ||
| Module | TypeDefToMethodTableMap | Mapping table | | ||
| Module | TypeRefToMethodTableMap | Mapping table | | ||
|
||
Global variables used: | ||
| Global Name | Type | Purpose | | ||
| --- | --- | --- | | ||
| ObjectMethodTable | TargetPointer | pointer to the MT of `object` | | ||
| StringMethodTable | TargetPointer | pointer to the MT of `string` | | ||
|
||
Contracts used: | ||
| Contract Name | | ||
| --- | | ||
| RuntimeTypeSystem | | ||
| Loader | | ||
|
||
### SignatureTypeProvider | ||
```csharp | ||
using System.Reflection.Metadata; | ||
using System.Reflection.Metadata.Ecma335; | ||
|
||
public class SignatureTypeProvider<T> : ISignatureTypeProvider<TypeHandle, T> | ||
{ | ||
private readonly Target _target; | ||
private readonly DataContractReader.Contracts.ModuleHandle _moduleHandle; | ||
|
||
public SignatureTypeProvider(Target target, DataContractReader.Contracts.ModuleHandle moduleHandle) | ||
{ | ||
_target = target; | ||
_moduleHandle = moduleHandle; | ||
} | ||
public TypeHandle GetArrayType(TypeHandle elementType, ArrayShape shape) | ||
=> _target.Contracts.RuntimeTypeSystem.GetConstructedType(elementType, CorElementType.Array, shape.Rank, ImmutableArray<TypeHandle>.Empty); | ||
|
||
public TypeHandle GetByReferenceType(TypeHandle elementType) | ||
=> _target.Contracts.RuntimeTypeSystem.GetConstructedType(elementType, CorElementType.Byref, 0, ImmutableArray<TypeHandle>.Empty); | ||
|
||
public TypeHandle GetFunctionPointerType(MethodSignature<TypeHandle> signature) | ||
=> GetPrimitiveType(PrimitiveTypeCode.IntPtr); | ||
|
||
public TypeHandle GetGenericInstantiation(TypeHandle genericType, ImmutableArray<TypeHandle> typeArguments) | ||
=> _target.Contracts.RuntimeTypeSystem.GetConstructedType(genericType, CorElementType.GenericInst, 0, typeArguments); | ||
|
||
public TypeHandle GetGenericMethodParameter(T context, int index) | ||
{ | ||
if (typeof(T) == typeof(MethodDescHandle)) | ||
{ | ||
MethodDescHandle methodContext = (MethodDescHandle)(object)context!; | ||
return _target.Contracts.RuntimeTypeSystem.GetGenericMethodInstantiation(methodContext)[index]; | ||
} | ||
throw new NotSupportedException(); | ||
} | ||
public TypeHandle GetGenericTypeParameter(T context, int index) | ||
{ | ||
TypeHandle typeContext; | ||
if (typeof(T) == typeof(TypeHandle)) | ||
{ | ||
typeContext = (TypeHandle)(object)context!; | ||
return _target.Contracts.RuntimeTypeSystem.GetInstantiation(typeContext)[index]; | ||
} | ||
throw new NotImplementedException(); | ||
} | ||
public TypeHandle GetModifiedType(TypeHandle modifier, TypeHandle unmodifiedType, bool isRequired) | ||
=> unmodifiedType; | ||
|
||
public TypeHandle GetPinnedType(TypeHandle elementType) | ||
=> elementType; | ||
|
||
public TypeHandle GetPointerType(TypeHandle elementType) | ||
=> _target.Contracts.RuntimeTypeSystem.GetConstructedType(elementType, CorElementType.Ptr, 0, ImmutableArray<TypeHandle>.Empty); | ||
|
||
public TypeHandle GetPrimitiveType(PrimitiveTypeCode typeCode) | ||
=> _target.Contracts.RuntimeTypeSystem.GetPrimitiveType(typeCode); | ||
|
||
public TypeHandle GetSZArrayType(TypeHandle elementType) | ||
=> _target.Contracts.RuntimeTypeSystem.GetConstructedType(elementType, CorElementType.SzArray, 1, ImmutableArray<TypeHandle>.Empty); | ||
|
||
public TypeHandle GetTypeFromDefinition(MetadataReader reader, TypeDefinitionHandle handle, byte rawTypeKind) | ||
{ | ||
int token = MetadataTokens.GetToken((EntityHandle)handle); | ||
TargetPointer typeHandlePtr = _target.Contracts.Loader.GetModuleLookupMapElement(_target.ReadPointer(moduleHandle.Address + /* Module::TypeDefToMethodTableMap offset */, (uint)token, out _); | ||
return typeHandlePtr == TargetPointer.Null ? new TypeHandle(TargetPointer.Null) : _runtimeTypeSystem.GetTypeHandle(typeHandlePtr); | ||
} | ||
|
||
public TypeHandle GetTypeFromReference(MetadataReader reader, TypeReferenceHandle handle, byte rawTypeKind) | ||
{ | ||
int token = MetadataTokens.GetToken((EntityHandle)handle); | ||
TargetPointer typeHandlePtr = _target.Contracts.Loader.GetModuleLookupMapElement(_target.ReadPointer(moduleHandle.Address + /* Module::TypeRefToMethodTableMap offset */, (uint)token, out _); | ||
return typeHandlePtr == TargetPointer.Null ? new TypeHandle(TargetPointer.Null) : _runtimeTypeSystem.GetTypeHandle(typeHandlePtr); | ||
} | ||
|
||
public TypeHandle GetTypeFromSpecification(MetadataReader reader, T context, TypeSpecificationHandle handle, byte rawTypeKind) | ||
=> throw new NotImplementedException(); | ||
} | ||
|
||
``` | ||
rcj1 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
### APIs | ||
```csharp | ||
TypeHandle ISignatureDecoder.DecodeFieldSignature(BlobHandle blobHandle, ModuleHandle moduleHandle, TypeHandle ctx) | ||
{ | ||
SignatureTypeProvider<TypeHandle> provider = new(_target, moduleHandle); | ||
MetadataReader mdReader = _target.Contracts.EcmaMetadata.GetMetadata(moduleHandle)!; | ||
BlobReader blobReader = mdReader.GetBlobReader(blobHandle); | ||
SignatureDecoder<TypeHandle, TypeHandle> decoder = new(provider, mdReader, ctx); | ||
return decoder.DecodeFieldSignature(ref blobReader); | ||
} | ||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.