Skip to content

[cDAC] DacDbi code-version node APIs for ReJIT/SOS - #126980

Merged
rcj1 merged 8 commits into
mainfrom
copilot/implement-dacdbi-cs-apis
May 3, 2026
Merged

rcj1 merged 8 commits into
mainfrom
copilot/implement-dacdbi-cs-apis

Conversation

Copilot AI commented Apr 16, 2026 •

Copy link
Copy Markdown
Contributor

Description

Implements the cDAC DacDbiImpl APIs GetActiveRejitILCodeVersionNode, GetNativeCodeVersionNode, and GetILCodeVersionNode using existing CodeVersions and ReJIT contracts.

Copilot AI review requested due to automatic review settings April 16, 2026 00:39
Copilot AI removed the request for review from Copilot April 16, 2026 00:39
@rcj1 rcj1 changed the title Implement cDAC DacDbi code-version node APIs for ReJIT/SOS parity [cDAC] DacDbi code-version node APIs for ReJIT/SOS Apr 16, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @steveisok, @tommcdon, @dotnet/dotnet-diag
See info in area-owners.md if you want to be subscribed.

@rcj1
rcj1 marked this pull request as ready for review April 16, 2026 06:16
Copilot AI review requested due to automatic review settings April 16, 2026 06:16

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Implements cDAC equivalents of legacy DAC DBI code-version node lookup APIs used by SOS/ICorDebug, mapping through existing CodeVersions and ReJIT contracts while preserving HRESULT-style behavior.

Changes:

  • Implemented GetActiveRejitILCodeVersionNode by resolving (Module, mdMethodDef) → MethodDesc and returning the explicit active ReJIT IL node (or 0).
  • Implemented GetNativeCodeVersionNode by matching (MethodDesc, codeStartAddress) against contract-enumerated native code versions and returning an explicit native node (or 0 for synthetic/absent).
  • Implemented GetILCodeVersionNode by mapping an explicit native node → explicit IL node (or 0 for default/synthetic), with DEBUG cross-validation against legacy DAC.

@rcj1
rcj1 marked this pull request as draft April 16, 2026 06:33
@rcj1 rcj1 added the NO-MERGE The PR is not ready for merge yet (see discussion for detailed reasons) label Apr 16, 2026
@rcj1
rcj1 force-pushed the copilot/implement-dacdbi-cs-apis branch from 419ac0e to bb2c01d Compare April 17, 2026 23:05
@rcj1 rcj1 removed the NO-MERGE The PR is not ready for merge yet (see discussion for detailed reasons) label Apr 17, 2026
@rcj1
rcj1 marked this pull request as ready for review April 17, 2026 23:14
@github-actions

This comment has been minimized.

Copilot AI review requested due to automatic review settings April 27, 2026 18:10

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

Copilot AI review requested due to automatic review settings April 27, 2026 18:18

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.

Copilot AI review requested due to automatic review settings May 1, 2026 22:39

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

@github-actions

github-actions Bot commented May 1, 2026

Copy link
Copy Markdown
Contributor

🤖 Copilot Code Review — PR #126980

Note

This review was generated by GitHub Copilot.

Holistic Assessment

Motivation: This PR implements three DacDbi code version node APIs (GetActiveRejitILCodeVersionNode, GetNativeCodeVersionNode, GetILCodeVersionNode) in the cDAC, replacing legacy fallback stubs. This is part of the ongoing cDAC migration and enables no-fallback testing for these methods. The motivation is clear and justified.

Approach: The implementation follows the established DacDbiImpl pattern (try/catch with HResult, DEBUG-mode legacy validation). The Loader_1.cs change converts ArgumentOutOfRangeException.ThrowIfZero(rid) into a graceful return of null, which is needed because the new caller expects non-throwing behavior for missing entries.

Summary: ⚠️ Needs Human Review. The implementation is well-structured and follows existing patterns, but there is one notable behavioral concern regarding the GetNativeCodeVersionNode implementation that warrants human verification.


Detailed Findings

⚠️ Correctness — GetNativeCodeVersionNode ignores vmMethod parameter

The native DAC implementation (dacdbiimpl.cpp:7664) uses vmMethod to get the CodeVersionManager and calls GetNativeCodeVersion(pMD, codeStartAddress), which searches code versions specifically for that MethodDesc at the given address. The cDAC implementation ignores vmMethod entirely and calls codeVersions.GetNativeCodeVersionForIP(codeAddress), which looks up the code version by IP alone.

In practice these may produce the same result because GetNativeCodeVersionForIP does a range lookup and the IP should uniquely identify a native code version. However, the native DAC approach is more precise — it scopes the search to the specific MethodDesc. If GetNativeCodeVersionForIP can ever resolve to a different method's code version for an ambiguous address, this would be a behavioral difference. The DEBUG validation block should catch this, but a human reviewer familiar with the code versioning system should confirm this is semantically equivalent.

✅ Correctness — GetActiveRejitILCodeVersionNode logic matches native DAC

The implementation correctly:

  • Validates the token is a MethodDef token
  • Resolves the MethodDesc via the lookup map
  • Gets the active IL code version and checks IsValid, IsExplicit, and RejitState.Active

This mirrors the native DAC logic of checking !IsNull(), !IsDefaultVersion(), and GetRejitState() == kStateActive.

✅ Correctness — GetILCodeVersionNode logic matches native DAC

The implementation correctly creates an explicit NativeCodeVersionHandle from the input pointer and retrieves the associated ILCodeVersion, writing the node address only if the version is explicit (not default). This matches the native DAC's IsDefaultVersion() check.

⚠️ Behavioral Change — GetModuleLookupMapElement no longer throws on rid==0

The change to Loader_1.cs converts a throwing behavior (ArgumentOutOfRangeException.ThrowIfZero(rid)) into a graceful return of TargetPointer.Null. All existing callers appear to handle null returns appropriately (they check for TargetPointer.Null before proceeding), so this should be safe. However, this is a contract-level behavioral change — callers that previously relied on the exception for invalid tokens will now get a silent null. A human reviewer should confirm this is the intended semantic for the ILoader contract.

💡 Suggestion — Unnecessary local variable initialization

In GetActiveRejitILCodeVersionNode, methodDesc is declared and initialized to TargetPointer.Null on line 1217, then unconditionally reassigned on line 1221. The initial assignment is redundant — declare it after the token type check instead.

✅ Pattern Consistency — DEBUG validation blocks

All three methods correctly follow the established DEBUG validation pattern: call the legacy implementation with local variables, validate HResult consistency, and assert result equality. This is consistent with surrounding methods like GetDefinesBitField and GetMDStructuresVersion.

Generated by Code Review for issue #126980 · ◷

@rcj1
rcj1 merged commit ebcaacc into main May 3, 2026
58 of 60 checks passed
@rcj1
rcj1 deleted the copilot/implement-dacdbi-cs-apis branch May 3, 2026 06:18
@github-actions github-actions Bot locked and limited conversation to collaborators Jun 2, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants