Adding GetHandleEnum and GetHandleEnumForTypes cDAC APIs#124760
Adding GetHandleEnum and GetHandleEnumForTypes cDAC APIs#124760rcj1 wants to merge 20 commits intodotnet:mainfrom
Conversation
|
Tagging subscribers to this area: @steveisok, @tommcdon, @dotnet/dotnet-diag |
There was a problem hiding this comment.
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 |
...ative/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/HandleTableMap.cs
Outdated
Show resolved
Hide resolved
...ve/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/HandleTableBucket.cs
Outdated
Show resolved
Hide resolved
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/HandleTable.cs
Outdated
Show resolved
Hide resolved
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/SOSDacImpl.cs
Outdated
Show resolved
Hide resolved
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/GC/GC_1.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: Copilot <[email protected]>
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/SOSDacImpl.cs
Show resolved
Hide resolved
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/GC/GC_1.cs
Show resolved
Hide resolved
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/GC/GC_1.cs
Outdated
Show resolved
Hide resolved
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/GC/GC_1.cs
Show resolved
Hide resolved
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/SOSDacImpl.cs
Show resolved
Hide resolved
Co-authored-by: Copilot <[email protected]>
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/GC/GC_1.cs
Show resolved
Hide resolved
...ative/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/ComCallWrapper.cs
Outdated
Show resolved
Hide resolved
...ve/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/GC/GCFactory.cs
Show resolved
Hide resolved
...managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/SimpleComCallWrapper.cs
Outdated
Show resolved
Hide resolved
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/TableSegment.cs
Outdated
Show resolved
Hide resolved
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/GC/GC_1.cs
Show resolved
Hide resolved
Co-authored-by: Copilot <[email protected]>
...ve/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/GC/GCFactory.cs
Show resolved
Hide resolved
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/GC/GC_1.cs
Show resolved
Hide resolved
docs/design/datacontracts/GC.md
Outdated
| List<HandleData> IGC.GetHandles(uint[] types) | ||
| { | ||
| List<HandleData> handles = new(); | ||
| TargetPointer handleTableMap = target.ReadGlobalPointer("HandleTableMap"); | ||
| // for each handleTableMap in the linked list |
There was a problem hiding this comment.
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*.
...ative/managed/cdac/Microsoft.Diagnostics.DataContractReader.Abstractions/ContractRegistry.cs
Show resolved
Hide resolved
src/native/managed/cdac/tests/DumpTests/WorkstationGCDumpTests.cs
Outdated
Show resolved
Hide resolved
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/GC/GC_1.cs
Outdated
Show resolved
Hide resolved
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/GC/GC_1.cs
Show resolved
Hide resolved
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader/CachingContractRegistry.cs
Show resolved
Hide resolved
| (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}"), |
There was a problem hiding this comment.
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.
Co-authored-by: Copilot <[email protected]>
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/GC/GC_1.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
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
...tive/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/BuiltInCOM.cs
Show resolved
Hide resolved
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/GC/GC_1.cs
Outdated
Show resolved
Hide resolved
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/GC/GC_1.cs
Show resolved
Hide resolved
...ative/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/HandleTableMap.cs
Show resolved
Hide resolved
Co-authored-by: Copilot <[email protected]>
Fixes #124689