[cDAC] Add custom marshallers for COM interface parameters#125132
Conversation
|
Tagging subscribers to this area: @steveisok, @tommcdon, @dotnet/dotnet-diag |
There was a problem hiding this comment.
Pull request overview
This PR introduces DacComInterfaceIn<T> and DacComInterfaceOut<T> custom marshaller types to replace raw void*/void** and typed out IFoo? patterns for COM interface parameters in the cDAC legacy COM interface definitions. This improves type safety while correctly handling null COM interface pointers that the [GeneratedComInterface] source generator cannot natively accommodate.
Changes:
- New
DacComInterfaceIn<T>,DacComInterfaceOut<T>wrapper types and their[CustomMarshaller]implementations in a newMarshalling/subfolder;ClrDataAddress.csmoved there as well. - All COM interface declarations in
ISOSDacInterface.csandIXCLRData.csmigrated fromvoid*/void**/out IFoo?to the new typed wrappers. - Implementations updated in
SOSDacImpl,ClrDataFrame,ClrDataModule,ClrDataTask,ClrDataStackWalk, andClrDataMethodInstance, withThrowIfNull()/IsNullnull-safety guards added to match nativeE_POINTER/E_INVALIDARGbehavior.
Reviewed changes
Copilot reviewed 11 out of 12 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
Marshalling/DacComInterfaceOut.cs |
New DacComInterfaceOut<T> wrapper and marshaller for output COM interface parameters |
Marshalling/DacComInterfaceIn.cs |
New DacComInterfaceIn<T> wrapper and marshaller for input COM interface parameters |
Marshalling/ClrDataAddress.cs |
ClrDataAddress type moved to Marshalling/ subfolder; no logic change |
ISOSDacInterface.cs |
Updated all COM interface parameter types + added ISOSStackRefEnum/ISOSMemoryEnum interface declarations |
IXCLRData.cs |
Updated all COM interface parameter types across all IXCLRData* interfaces |
SOSDacImpl.cs |
Updated implementations for GetHandleEnum, GetHandleEnumForTypes, GetHandleEnumForGC, GetModule, GetStackReferences, ISOSDacInterface13 passthrough methods, GetMethodTableSlotEnumerator |
SOSDacImpl.IXCLRDataProcess.cs |
Updated IXCLRDataProcess implementations with new typed parameters and try-catch wrapping |
ClrDataTask.cs |
Updated IXCLRDataTask implementations |
ClrDataStackWalk.cs |
Updated GetFrame implementation |
ClrDataModule.cs |
Updated IXCLRDataModule implementations |
ClrDataFrame.cs |
Updated IXCLRDataFrame implementations |
ClrDataMethodInstance.cs |
Updated IXCLRDataMethodInstance implementations, cleaned up COM interop code |
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/ISOSDacInterface.cs
Show resolved
Hide resolved
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/ClrDataTask.cs
Outdated
Show resolved
Hide resolved
...native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/ClrDataMethodInstance.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.Legacy/SOSDacImpl.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.Legacy/SOSDacImpl.cs
Outdated
Show resolved
Hide resolved
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/SOSDacImpl.cs
Outdated
Show resolved
Hide resolved
.../managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/SOSDacImpl.IXCLRDataProcess.cs
Outdated
Show resolved
Hide resolved
...anaged/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/Marshalling/DacComInterfaceIn.cs
Outdated
Show resolved
Hide resolved
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/ClrDataStackWalk.cs
Outdated
Show resolved
Hide resolved
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/ClrDataFrame.cs
Outdated
Show resolved
Hide resolved
...naged/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/Marshalling/DacComInterfaceOut.cs
Outdated
Show resolved
Hide resolved
b01d788 to
ecb58d5
Compare
...naged/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/Marshalling/DacComInterfaceOut.cs
Outdated
Show resolved
Hide resolved
...naged/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/Marshalling/DacComInterfaceOut.cs
Outdated
Show resolved
Hide resolved
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/ISOSDacInterface.cs
Outdated
Show resolved
Hide resolved
.../managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/SOSDacImpl.IXCLRDataProcess.cs
Outdated
Show resolved
Hide resolved
...naged/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/Marshalling/DacComInterfaceOut.cs
Outdated
Show resolved
Hide resolved
...naged/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/Marshalling/DacComInterfaceOut.cs
Outdated
Show resolved
Hide resolved
61ac4b0 to
f57d8a7
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 12 out of 13 changed files in this pull request and generated 5 comments.
Comments suppressed due to low confidence (1)
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/Marshalling/DacComNullableByRef.cs:1
- The marshaller only registers
MarshalMode.UnmanagedToManagedInandMarshalMode.ManagedToUnmanagedInmodes. For an output parameter in[GeneratedComInterface]-decorated interfaces, the source generator requiresMarshalMode.UnmanagedToManagedInfor the receiver (managed implementation called by native code) but may also needMarshalMode.ManagedToUnmanagedOutorMarshalMode.Defaultfor certain call directions. More specifically,ManagedToUnmanagedInis for passing a value from managed into native — but this parameter is an output from the callee's perspective. UsingManagedToUnmanagedInwhen passing aDacComNullableByRef<T>to a legacy native call (as done inSOSDacImpl.cs) means the source generator is treating the wrapper as an input, not an output sink. Verify that the registered marshal modes produce the correct generated code for both call directions (native→managed and managed→native).
// Licensed to the .NET Foundation under one or more agreements.
...aged/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/Marshalling/DacComNullableByRef.cs
Show resolved
Hide resolved
...aged/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/Marshalling/DacComNullableByRef.cs
Show resolved
Hide resolved
...aged/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/Marshalling/DacComNullableByRef.cs
Show resolved
Hide resolved
...aged/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/Marshalling/DacComNullableByRef.cs
Outdated
Show resolved
Hide resolved
.../managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/SOSDacImpl.IXCLRDataProcess.cs
Outdated
Show resolved
Hide resolved
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/ClrDataModule.cs
Show resolved
Hide resolved
Replace raw void*/void** and out T? COM interface parameters with DacComNullableByRef<T> across the cDAC legacy layer: - Add DacComNullableByRef<T> with stateful custom marshallers for both UnmanagedToManaged and ManagedToUnmanaged directions. Setting Interface when IsNullRef is true throws NullReferenceException, mirroring the native behavior of writing through a null void**. - Convert all out T? COM interface output parameters in IXCLRData.cs and ISOSDacInterface.cs to DacComNullableByRef<T>. - Update all implementation files to match new signatures: pass-through methods become expression-bodied, cDAC implementations set .Interface directly (NRE on null ref) or guard with IsNullRef for optional params. - Fully define ISOSStackRefEnum and ISOSMemoryEnum interfaces with their Next methods, supporting structs (SOSStackRefData, SOSStackRefError, SOSMemoryRegion), enums (SOSStackSourceType), and ISOSStackRefErrorEnum. - Move ClrDataAddress.cs to the Marshalling folder. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
5e77fcc to
08ff1af
Compare
...aged/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/Marshalling/DacComNullableByRef.cs
Show resolved
Hide resolved
...aged/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/Marshalling/DacComNullableByRef.cs
Show resolved
Hide resolved
|
/ba-g "cDAC only change and cDAC tests pass" |
No description provided.