Repository navigation
Fix cDAC big-RVA field offset detection to mask packed type bits - #130501
Merged
max-charlamb merged 1 commit intoJul 10, 2026
Merged
max-charlamb merged 1 commit into
max-charlamb merged 1 commit into
Conversation
FieldDesc::DWord2 packs the 27-bit field offset in its low bits and the 5-bit field type in its high bits. GetFieldDescOffset compared the full DWord2 against the FIELD_OFFSET_BIG_RVA sentinel, but the sentinel is a 27-bit offset value, so for any real field (which always has a non-zero type in the high bits) the comparison never matched. As a result big-RVA fields were never resolved from metadata and callers saw the sentinel value returned as the offset. Mask off the type bits before comparing, matching the native runtime, which compares the m_dwOffset bitfield directly (FieldDesc::GetOffset in src/coreclr/vm/field.h). This also mirrors the sibling IsFieldDescEnCNew, which already masks with OffsetMask before comparing its sentinel. Adds unit tests for the big-RVA and normal offset paths, plus a MockFieldDesc helper in the RuntimeTypeSystem mock. The big-RVA test fails without the fix (the sentinel leaks out as the offset). Co-authored-by: Copilot <[email protected]>
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes cDAC IRuntimeTypeSystem.GetFieldDescOffset big-RVA detection by masking out the packed field-type bits in FieldDesc.DWord2 before comparing against the FIELD_OFFSET_BIG_RVA sentinel, enabling correct fallback to metadata RVA resolution.
Changes:
- Mask
FieldDesc.DWord2withFieldDescFlags2.OffsetMaskbefore comparing againstConstants.Globals.FieldOffsetBigRVA, and reuse the masked value for the return path. - Extend cDAC unit-test mocks with a
MockFieldDesclayout and anAddFieldDeschelper for creating packedFieldDescinstances. - Add unit tests covering both the non-big-RVA masked-offset behavior and big-RVA metadata RVA resolution.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/RuntimeTypeSystem_1.cs | Fixes big-RVA detection by comparing the masked 27-bit offset rather than the full packed DWord2. |
| src/native/managed/cdac/tests/UnitTests/MockDescriptors/MockDescriptors.RuntimeTypeSystem.cs | Adds a FieldDesc mock layout and helper allocation routine used by new tests. |
| src/native/managed/cdac/tests/UnitTests/MethodTableTests.cs | Adds unit tests that validate masked offsets for normal fields and metadata-based RVA resolution for big-RVA fields. |
Contributor
|
Tagging subscribers to this area: @steveisok, @tommcdon, @dotnet/dotnet-diag |
max-charlamb
marked this pull request as draft
July 10, 2026 16:57
max-charlamb
marked this pull request as ready for review
July 10, 2026 16:59
hoyosjs
approved these changes
Jul 10, 2026
max-charlamb
enabled auto-merge (squash)
July 10, 2026 18:11
Member
Author
|
/ba-g osx infra timeout |
max-charlamb
pushed a commit
to max-charlamb/runtime
that referenced
this pull request
Jul 10, 2026
Merging main brought in the big-RVA offset fix (dotnet#130501), whose unit tests call the two-arg GetFieldDescOffset(ptr, FieldDefinition?) overload that this PR removed in favor of the single-arg GetFieldDescOffset(ptr) (which resolves the FieldDefinition internally). Update the tests to the new API: - Non-big-RVA test: call GetFieldDescOffset(ptr) and assert the masked offset. - Big-RVA test: assert the sentinel is detected after masking the type bits -- with no enclosing MethodTable/metadata wired, the detected big-RVA path finds no FieldDefinition and throws InvalidOperationException. This still fails against the pre-fix comparison (which never detects the sentinel), so it remains a valid regression guard, without pulling Loader/EcmaMetadata mocks into the RuntimeTypeSystem-only test harness. Removes the now-unused metadata-building helper and its usings. Co-authored-by: Copilot <[email protected]>
max-charlamb
added a commit
that referenced
this pull request
Jul 10, 2026
…leData changes (#130531) ## Summary Small docs-only follow-up aligning the cDAC data-contract documentation with two recently merged changes that updated the contract implementations but not their docs. ### 1. `RuntimeTypeSystem.md` -- big-RVA offset masking (follow-up to #130501) #130501 fixed big-RVA field-offset detection by masking the packed type bits before comparing `FieldDesc::DWord2` against the `FIELD_OFFSET_BIG_RVA` sentinel, but left the `GetFieldDescOffset` pseudocode showing the old unmasked comparison. Updated the pseudocode to mask the offset out of the packed `DWord2` (27-bit offset + 5-bit type) before the sentinel check, matching the shipped implementation and native `FieldDesc::GetOffset`. ### 2. `GC.md` -- `JupiterRefCount` removal (follow-up to #130448) #130448 removed the vestigial `JupiterRefCount` field from the cDAC `HandleData` contract, but left the `CreateHandleData` pseudocode setting it. Removed the stale `handleData.JupiterRefCount = 0;` assignment. (The COM ABI struct still exposes the field and reports `0`, unchanged.) Docs-only change. --------- Co-authored-by: Max Charlamb <[email protected]> Co-authored-by: Copilot <[email protected]>
max-charlamb
pushed a commit
to max-charlamb/runtime
that referenced
this pull request
Jul 13, 2026
Merging main brought in the big-RVA offset fix (dotnet#130501), whose unit tests call the two-arg GetFieldDescOffset(ptr, FieldDefinition?) overload that this PR removed in favor of the single-arg GetFieldDescOffset(ptr) (which resolves the FieldDefinition internally). Update the tests to the new API: - Non-big-RVA test: call GetFieldDescOffset(ptr) and assert the masked offset. - Big-RVA test: assert the sentinel is detected after masking the type bits -- with no enclosing MethodTable/metadata wired, the detected big-RVA path finds no FieldDefinition and throws InvalidOperationException. This still fails against the pre-fix comparison (which never detects the sentinel), so it remains a valid regression guard, without pulling Loader/EcmaMetadata mocks into the RuntimeTypeSystem-only test harness. Removes the now-unused metadata-building helper and its usings. Co-authored-by: Copilot <[email protected]>
eiriktsarpalis
pushed a commit
that referenced
this pull request
Jul 15, 2026
…0501) ## Summary Fixes a bug in the cDAC's `RuntimeTypeSystem` contract where big-RVA field offsets were never resolved from metadata. `FieldDesc::DWord2` packs the **27-bit field offset** in its low bits and the **5-bit field type** in its high bits (`m_dwOffset : 27` / `m_type : 5`, see `src/coreclr/vm/field.h`). `GetFieldDescOffset` compared the **full `DWord2`** against the `FIELD_OFFSET_BIG_RVA` sentinel: ```csharp if (fieldDesc.DWord2 == _target.ReadGlobal<uint>(Constants.Globals.FieldOffsetBigRVA)) ``` But the sentinel is a 27-bit offset value (`FIELD_OFFSET_MAX - 5`). Every real field has a non-zero type in the high 5 bits, so `DWord2` can never equal the 27-bit sentinel. The big-RVA branch was therefore dead, and callers received the sentinel value back as the field offset instead of the RVA read from metadata. ## Fix Mask off the type bits before comparing, matching the native runtime, which compares the `m_dwOffset` bitfield directly (`FieldDesc::GetOffset`): ```csharp uint offset = fieldDesc.DWord2 & (uint)FieldDescFlags2.OffsetMask; if (offset == _target.ReadGlobal<uint>(Constants.Globals.FieldOffsetBigRVA)) ``` This also mirrors the sibling `IsFieldDescEnCNew`, which already masks with `OffsetMask` before comparing its sentinel — good evidence this was a simple oversight in `GetFieldDescOffset`. ## Testing - Added `MethodTableTests.GetFieldDescOffset_BigRVA_ResolvesFromMetadata` and `GetFieldDescOffset_NonBigRVA_ReturnsMaskedOffset`, plus a `MockFieldDesc` helper in the RuntimeTypeSystem mock. - Verified the big-RVA test **fails without the fix** (returns `0x07FFFFFA`, the leaked sentinel) and **passes with it** (returns the RVA `0x1234`). - Full `MethodTableTests` suite (136 tests) passes. **Note on dump tests:** a real big-RVA field requires an RVA static whose offset exceeds `FIELD_OFFSET_MAX` (~128 MB), which isn't reproducible in a debuggee/dump test, so this is validated via unit tests instead. > [!NOTE] > This PR was created with GitHub Copilot. Co-authored-by: Max Charlamb <[email protected]> Co-authored-by: Copilot <[email protected]>
eiriktsarpalis
pushed a commit
that referenced
this pull request
Jul 15, 2026
…leData changes (#130531) ## Summary Small docs-only follow-up aligning the cDAC data-contract documentation with two recently merged changes that updated the contract implementations but not their docs. ### 1. `RuntimeTypeSystem.md` -- big-RVA offset masking (follow-up to #130501) #130501 fixed big-RVA field-offset detection by masking the packed type bits before comparing `FieldDesc::DWord2` against the `FIELD_OFFSET_BIG_RVA` sentinel, but left the `GetFieldDescOffset` pseudocode showing the old unmasked comparison. Updated the pseudocode to mask the offset out of the packed `DWord2` (27-bit offset + 5-bit type) before the sentinel check, matching the shipped implementation and native `FieldDesc::GetOffset`. ### 2. `GC.md` -- `JupiterRefCount` removal (follow-up to #130448) #130448 removed the vestigial `JupiterRefCount` field from the cDAC `HandleData` contract, but left the `CreateHandleData` pseudocode setting it. Removed the stale `handleData.JupiterRefCount = 0;` assignment. (The COM ABI struct still exposes the field and reports `0`, unchanged.) Docs-only change. --------- Co-authored-by: Max Charlamb <[email protected]> Co-authored-by: Copilot <[email protected]>
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
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Summary
Fixes a bug in the cDAC's
RuntimeTypeSystemcontract where big-RVA field offsets were never resolved from metadata.FieldDesc::DWord2packs the 27-bit field offset in its low bits and the 5-bit field type in its high bits (m_dwOffset : 27/m_type : 5, seesrc/coreclr/vm/field.h).GetFieldDescOffsetcompared the fullDWord2against theFIELD_OFFSET_BIG_RVAsentinel:But the sentinel is a 27-bit offset value (
FIELD_OFFSET_MAX - 5). Every real field has a non-zero type in the high 5 bits, soDWord2can never equal the 27-bit sentinel. The big-RVA branch was therefore dead, and callers received the sentinel value back as the field offset instead of the RVA read from metadata.Fix
Mask off the type bits before comparing, matching the native runtime, which compares the
m_dwOffsetbitfield directly (FieldDesc::GetOffset):This also mirrors the sibling
IsFieldDescEnCNew, which already masks withOffsetMaskbefore comparing its sentinel — good evidence this was a simple oversight inGetFieldDescOffset.Testing
MethodTableTests.GetFieldDescOffset_BigRVA_ResolvesFromMetadataandGetFieldDescOffset_NonBigRVA_ReturnsMaskedOffset, plus aMockFieldDeschelper in the RuntimeTypeSystem mock.0x07FFFFFA, the leaked sentinel) and passes with it (returns the RVA0x1234).MethodTableTestssuite (136 tests) passes.Note on dump tests: a real big-RVA field requires an RVA static whose offset exceeds
FIELD_OFFSET_MAX(~128 MB), which isn't reproducible in a debuggee/dump test, so this is validated via unit tests instead.Note
This PR was created with GitHub Copilot.