-
Notifications
You must be signed in to change notification settings - Fork 5.4k
[cDAC] RuntimeSignatureDecoder and centralized Signature contract (2/5) #127636
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
Open
max-charlamb
wants to merge
13
commits into
dotnet:main
Choose a base branch
from
max-charlamb:cdac-stackrefs-pr2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
6083571
WIP: RuntimeSignatureDecoder, centralized SignatureDecoder contract
c468dde
Align RuntimeSignatureDecoder with SRM and move GC decoding to StackWalk
112b4be
Address review feedback: split interface, drop dead code, require Met…
d5e314a
Capture Target in providers; document signature-based GC scanning
bfaf8af
Address PR review: handle StoredSigMethodDesc; cache GcSignatureTypeP…
d70e706
Resolve VAR/MVAR via instantiation; normalize enums to underlying pri…
ba37f41
Address PR review: visibility, dead state, doc fixes
b8179d0
Rename SignatureDecoder contract to Signature
e8f72c1
Address review feedback: data-first Signature.md + cross-ref tag
08ee9d5
address feedback
b696caf
remove all references to number of internal types
9872130
Handle array class contexts in GcSignatureTypeProvider
4eaf8ee
Use EcmaMetadataUtils for method token constants in GcScanner
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| # Contract Signature | ||
|
|
||
| This contract describes the format of method, field, and local-variable signatures stored in target memory. Signatures use the ECMA-335 §II.23.2 format with CoreCLR-internal element types added by the runtime. | ||
|
|
||
| ## Internal element types | ||
|
|
||
| The runtime extends the standard ECMA-335 element type encoding with values that may appear in signatures stored in target memory: | ||
|
|
||
| | Encoding | Value | Layout following the tag | | ||
| | --- | --- | --- | | ||
| | `ELEMENT_TYPE_INTERNAL` | `0x21` | a target-sized pointer to a runtime `TypeHandle` | | ||
| | `ELEMENT_TYPE_CMOD_INTERNAL` | `0x22` | one byte (`1` = required, `0` = optional), then a target-sized pointer to a runtime `TypeHandle` | | ||
|
|
||
| These tags are used in signatures generated internally by the runtime that are not persisted to a managed image. They are defined alongside the standard ECMA-335 element types in `src/coreclr/inc/corhdr.h`. Their literal values are part of this contract -- changing them is a breaking change. | ||
|
|
||
| ## APIs of contract | ||
|
|
||
| ```csharp | ||
| TypeHandle DecodeFieldSignature(BlobHandle blobHandle, ModuleHandle moduleHandle, TypeHandle ctx); | ||
| ``` | ||
|
|
||
| ## Version 1 | ||
|
|
||
| Data descriptors used: | ||
| | Data Descriptor Name | Field | Meaning | | ||
| | --- | --- | --- | | ||
| | _none_ | | | | ||
|
|
||
| Global variables used: | ||
| | Global Name | Type | Purpose | | ||
| | --- | --- | --- | | ||
| | _none_ | | | | ||
|
|
||
| Contracts used: | ||
| | Contract Name | | ||
| | --- | | ||
| | RuntimeTypeSystem | | ||
| | Loader | | ||
| | EcmaMetadata | | ||
|
|
||
| Constants: | ||
| | Constant Name | Meaning | Value | | ||
| | --- | --- | --- | | ||
| | `ELEMENT_TYPE_INTERNAL` | runtime-internal element type tag for an internal `TypeHandle` | `0x21` | | ||
| | `ELEMENT_TYPE_CMOD_INTERNAL` | runtime-internal element type tag for an internal modified type | `0x22` | | ||
|
|
||
| Decoding a signature follows the ECMA-335 §II.23.2 grammar. For all standard element types, decoding behaves identically to `System.Reflection.Metadata.SignatureDecoder<TType, TGenericContext>`. When the decoder encounters one of the runtime-internal tags above, it reads the target-sized pointer (and optional `required` byte for `ELEMENT_TYPE_CMOD_INTERNAL`) from the signature blob and resolves it to a runtime `TypeHandle`. | ||
|
|
||
| The decoder is implemented as `RuntimeSignatureDecoder<TType, TGenericContext>` -- a clone of SRM's `SignatureDecoder<TType, TGenericContext>` with added support for the runtime-internal element types. The clone takes an additional `Target` so internal-type pointers can be sized for the target architecture. Provider implementations implement `IRuntimeSignatureTypeProvider<TType, TGenericContext>` -- a superset of `System.Reflection.Metadata.ISignatureTypeProvider<TType, TGenericContext>` -- adding methods for the runtime-internal element types: | ||
|
|
||
| ```csharp | ||
| TType GetInternalType(TargetPointer typeHandlePointer); | ||
| TType GetInternalModifiedType(TargetPointer typeHandlePointer, TType unmodifiedType, bool isRequired); | ||
| ``` | ||
|
|
||
| The contract's provider resolves these pointers through `RuntimeTypeSystem.GetTypeHandle`. Standard ECMA-335 element types resolve through `RuntimeTypeSystem.GetPrimitiveType` and `RuntimeTypeSystem.GetConstructedType`. Generic type parameters (`VAR`) and generic method parameters (`MVAR`) resolve via `RuntimeTypeSystem.GetInstantiation` and `RuntimeTypeSystem.GetGenericMethodInstantiation` respectively, using a `TypeHandle` (for generic types) or `MethodDescHandle` (for generic methods) generic context. `GetTypeFromDefinition` and `GetTypeFromReference` resolve tokens via the module's `TypeDefToMethodTableMap` / `TypeRefToMethodTableMap`; cross-module references and `GetTypeFromSpecification` are not currently implemented. | ||
|
|
||
| ```csharp | ||
| TypeHandle ISignature.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); | ||
| RuntimeSignatureDecoder<TypeHandle, TypeHandle> decoder = new(provider, _target, mdReader, ctx); | ||
| return decoder.DecodeFieldSignature(ref blobReader); | ||
| } | ||
| ``` | ||
|
|
||
| ### Other consumers | ||
|
|
||
| `RuntimeSignatureDecoder` is shared infrastructure within the cDAC. Other contracts construct their own decoder and provider directly when they need to decode method or local signatures rather than going through this contract. For example, the [StackWalk](./StackWalk.md) contract uses `RuntimeSignatureDecoder<GcTypeKind, GcSignatureContext>` with a GC-specific provider to classify method parameters during signature-based GC reference scanning. |
This file was deleted.
Oops, something went wrong.
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
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
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
33 changes: 33 additions & 0 deletions
33
...nostics.DataContractReader.Contracts/Contracts/Signature/IRuntimeSignatureTypeProvider.cs
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,33 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System.Reflection.Metadata; | ||
|
|
||
| namespace Microsoft.Diagnostics.DataContractReader.SignatureHelpers; | ||
|
|
||
| /// <summary> | ||
| /// Superset of SRM's <see cref="ISignatureTypeProvider{TType, TGenericContext}"/> | ||
| /// that adds support for runtime-internal type codes | ||
| /// (<c>ELEMENT_TYPE_INTERNAL</c> 0x21 and <c>ELEMENT_TYPE_CMOD_INTERNAL</c> 0x22). | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// Providers implementing this interface automatically satisfy SRM's | ||
| /// <see cref="ISignatureTypeProvider{TType, TGenericContext}"/> and can be used | ||
| /// with both SRM's <c>SignatureDecoder</c> and our | ||
| /// <see cref="RuntimeSignatureDecoder{TType, TGenericContext}"/>. | ||
| /// </remarks> | ||
| public interface IRuntimeSignatureTypeProvider<TType, TGenericContext> | ||
|
|
||
| : ISignatureTypeProvider<TType, TGenericContext> | ||
| { | ||
| /// <summary> | ||
| /// Classify an <c>ELEMENT_TYPE_INTERNAL</c> (0x21) type by resolving the | ||
| /// embedded TypeHandle pointer via the target's runtime type system. | ||
| /// </summary> | ||
| TType GetInternalType(TargetPointer typeHandlePointer); | ||
|
|
||
| /// <summary> | ||
| /// Classify an <c>ELEMENT_TYPE_CMOD_INTERNAL</c> (0x22) custom modifier by | ||
| /// resolving the embedded TypeHandle pointer via the target's runtime type system. | ||
| /// </summary> | ||
| TType GetInternalModifiedType(TargetPointer typeHandlePointer, TType unmodifiedType, bool isRequired); | ||
| } | ||
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.