Skip to content

Adding GetHandleEnum and GetHandleEnumForTypes cDAC APIs#124760

Open
rcj1 wants to merge 20 commits intodotnet:mainfrom
rcj1:GetHandleEnum
Open

Adding GetHandleEnum and GetHandleEnumForTypes cDAC APIs#124760
rcj1 wants to merge 20 commits intodotnet:mainfrom
rcj1:GetHandleEnum

Conversation

@rcj1
Copy link
Contributor

@rcj1 rcj1 commented Feb 23, 2026

Fixes #124689

@dotnet-policy-service
Copy link
Contributor

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

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request implements the GetHandleEnum and GetHandleEnumForTypes cDAC APIs, enabling enumeration of GC handles through the contract-based data access interface. The implementation adds handle enumeration support that can operate independently of the legacy DAC while maintaining backward compatibility for validation in DEBUG builds.

Changes:

  • Implements SOSHandleEnum class that wraps handle data retrieval from the GC contract and provides COM enumeration semantics
  • Adds GC contract methods GetHandles and GetSupportedHandleTypes to retrieve handle information from handle table structures
  • Extends ComWrappers contract with GetRefCount and IsHandleWeak methods to support refcounted handle interrogation

Reviewed changes

Copilot reviewed 22 out of 22 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
SOSDacImpl.cs Implements SOSHandleEnum class and GetHandleEnum/GetHandleEnumForTypes interface methods with legacy DAC comparison in DEBUG builds
ISOSDacInterface.cs Defines ISOSHandleEnum interface and SOSHandleData structure; updates GetHandleEnum/GetHandleEnumForTypes signatures to use typed interfaces instead of void pointers
GC_1.cs Implements GetHandles and GetSupportedHandleTypes methods that traverse handle table structures and populate handle data including COM refcount info
GCFactory.cs Updates GC_1 constructor to receive handle-related global constants
ComWrappers_1.cs Adds GetRefCount and IsHandleWeak methods to interrogate COM call wrapper properties
TableSegment.cs New data structure representing a segment of the handle table with handle block metadata
SimpleComCallWrapper.cs New data structure containing COM wrapper refcount and flags
HandleTableMap.cs New data structure representing the handle table map with bucket array
HandleTableBucket.cs New data structure representing a handle table bucket
HandleTable.cs New data structure representing a handle table with segment list
ComCallWrapper.cs New data structure representing a COM call wrapper with pointer to SimpleComCallWrapper
datadescriptor.inc (VM) Adds data descriptors for ComCallWrapper and SimpleComCallWrapper types; adds feature flags and ComRefcountMask global
datadescriptor.h (VM) Includes comcallablewrapper.h for cdac_data template specializations
comcallablewrapper.h Adds cdac_data friend declarations and template specializations for ComCallWrapper and SimpleComCallWrapper offset definitions
datadescriptor.inc (GC) Adds data descriptors for handle table structures and related globals
datadescriptor.h (GC) Includes handletablepriv.h for handle table structure definitions
Constants.cs Adds global constant names for feature flags, handle table configuration, and COM refcount mask
DataType.cs Adds enum values for new handle table and COM wrapper data types
IGC.cs Adds HandleData record struct and GetHandles/GetSupportedHandleTypes interface methods
IComWrappers.cs Adds GetRefCount and IsHandleWeak interface methods
GC.md Documents GetHandles and GetSupportedHandleTypes contract methods with implementation details
ComWrappers.md Documents GetRefCount and IsHandleWeak contract methods

Copilot AI review requested due to automatic review settings February 23, 2026 19:14
Copy link
Contributor

Copilot AI left a comment

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 22 out of 22 changed files in this pull request and generated 3 comments.

Copilot AI review requested due to automatic review settings February 23, 2026 19:27
Copy link
Contributor

Copilot AI left a comment

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 22 out of 22 changed files in this pull request and generated 7 comments.

Copilot AI review requested due to automatic review settings February 23, 2026 19:35
Copy link
Contributor

Copilot AI left a comment

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 22 out of 22 changed files in this pull request and generated 8 comments.

@rcj1 rcj1 marked this pull request as ready for review February 23, 2026 21:13
Copilot AI review requested due to automatic review settings February 24, 2026 22:15
Copy link
Contributor

Copilot AI left a comment

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 27 out of 27 changed files in this pull request and generated 11 comments.

Comment on lines 574 to 578
List<HandleData> IGC.GetHandles(uint[] types)
{
List<HandleData> handles = new();
TargetPointer handleTableMap = target.ReadGlobalPointer("HandleTableMap");
// for each handleTableMap in the linked list
Copy link

Copilot AI Feb 24, 2026

Choose a reason for hiding this comment

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

The GetHandles design snippet is out of sync with the implementation: the API was added as IGC.GetHandles(HandleType[] types), but the docs show uint[] types. Also HandleTableMap is a CDAC_GLOBAL_POINTER(&g_HandleTableMap), so the sample should dereference the global pointer once before treating it as a HandleTableMap*.

Copilot uses AI. Check for mistakes.
Comment on lines 379 to 383
(uint)HandleType_1.RefCounted => HandleType.RefCounted,
(uint)HandleType_1.Dependent => HandleType.Dependent,
(uint)HandleType_1.WeakInteriorPointer => HandleType.WeakInteriorPointer,
(uint)HandleType_1.CrossReference => HandleType.CrossReference,
_ => throw new InvalidOperationException($"Unknown handle type {type}"),
Copy link

Copilot AI Feb 24, 2026

Choose a reason for hiding this comment

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

GetHandleTypes throws for unrecognized handle type values. The native DAC typemask builder accepts arbitrary type values (< 32) and just results in “no handles” for unsupported types; throwing here can break forward-compat callers. Prefer ignoring unknown types (or filtering to known/supported ones) instead of throwing.

Copilot uses AI. Check for mistakes.
Copilot AI review requested due to automatic review settings February 24, 2026 22:41
Copy link
Contributor

Copilot AI left a comment

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 31 out of 31 changed files in this pull request and generated 3 comments.

Copilot AI review requested due to automatic review settings February 25, 2026 03:48
Copy link
Contributor

Copilot AI left a comment

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 33 out of 33 changed files in this pull request and generated 6 comments.

Comments suppressed due to low confidence (1)

src/coreclr/vm/datadescriptor/datadescriptor.inc:1204

  • CDAC_GLOBAL_CONTRACT(BuiltInCOM, 1) is currently unconditional, but the contract implementation and its data descriptors/globals are only valid when FEATURE_COMINTEROP is enabled. Consider guarding this contract registration with #if FEATURE_COMINTEROP (similar to ComWrappers) so targets that don't support built-in COM don't advertise a non-functional contract.

CDAC_GLOBAL_CONTRACT(BuiltInCOM, 1)
CDAC_GLOBAL_CONTRACT(CodeVersions, 1)
#ifdef FEATURE_COMWRAPPERS
CDAC_GLOBAL_CONTRACT(ComWrappers, 1)
#endif // FEATURE_COMWRAPPERS

Copilot AI review requested due to automatic review settings February 25, 2026 04:19
Copy link
Contributor

Copilot AI left a comment

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 33 out of 33 changed files in this pull request and generated 3 comments.

Copilot AI review requested due to automatic review settings February 25, 2026 04:40
Copy link
Contributor

Copilot AI left a comment

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 33 out of 33 changed files in this pull request and generated no new comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[cDAC] Implement ISOSDacInterface::GetHandleEnum

4 participants