Skip to content

[cDAC] Add custom marshallers for COM interface parameters#125132

Merged
max-charlamb merged 2 commits intodotnet:mainfrom
max-charlamb:dev/maxcharlamb/runtime-cdac-interface-marshalling
Mar 6, 2026
Merged

[cDAC] Add custom marshallers for COM interface parameters#125132
max-charlamb merged 2 commits intodotnet:mainfrom
max-charlamb:dev/maxcharlamb/runtime-cdac-interface-marshalling

Conversation

@max-charlamb
Copy link
Member

@max-charlamb max-charlamb commented Mar 3, 2026

No description provided.

@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 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 new Marshalling/ subfolder; ClrDataAddress.cs moved there as well.
  • All COM interface declarations in ISOSDacInterface.cs and IXCLRData.cs migrated from void*/void**/out IFoo? to the new typed wrappers.
  • Implementations updated in SOSDacImpl, ClrDataFrame, ClrDataModule, ClrDataTask, ClrDataStackWalk, and ClrDataMethodInstance, with ThrowIfNull()/IsNull null-safety guards added to match native E_POINTER/E_INVALIDARG behavior.

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

max-charlamb

This comment was marked as outdated.

max-charlamb

This comment was marked as outdated.

Copilot AI review requested due to automatic review settings March 3, 2026 18:05
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 11 out of 12 changed files in this pull request and generated 5 comments.

max-charlamb

This comment was marked as outdated.

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

max-charlamb

This comment was marked as outdated.

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

Copy link
Member

@jkoritzinsky jkoritzinsky left a comment

Choose a reason for hiding this comment

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

LGTM

Copilot AI review requested due to automatic review settings March 5, 2026 16:36
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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@max-charlamb max-charlamb marked this pull request as ready for review March 5, 2026 17:07
Copilot AI review requested due to automatic review settings March 5, 2026 17:07
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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@max-charlamb max-charlamb reopened this Mar 5, 2026
Copilot AI review requested due to automatic review settings March 5, 2026 21:42
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 10 out of 11 changed files in this pull request and generated no new comments.

Copilot AI review requested due to automatic review settings March 5, 2026 22:36
@max-charlamb max-charlamb force-pushed the dev/maxcharlamb/runtime-cdac-interface-marshalling branch from 61ac4b0 to f57d8a7 Compare March 5, 2026 22:36
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 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.UnmanagedToManagedIn and MarshalMode.ManagedToUnmanagedIn modes. For an output parameter in [GeneratedComInterface]-decorated interfaces, the source generator requires MarshalMode.UnmanagedToManagedIn for the receiver (managed implementation called by native code) but may also need MarshalMode.ManagedToUnmanagedOut or MarshalMode.Default for certain call directions. More specifically, ManagedToUnmanagedIn is for passing a value from managed into native — but this parameter is an output from the callee's perspective. Using ManagedToUnmanagedIn when passing a DacComNullableByRef<T> to a legacy native call (as done in SOSDacImpl.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.

Max Charlamb and others added 2 commits March 6, 2026 10:56
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>
Copilot AI review requested due to automatic review settings March 6, 2026 16:01
@max-charlamb max-charlamb force-pushed the dev/maxcharlamb/runtime-cdac-interface-marshalling branch from 5e77fcc to 08ff1af Compare March 6, 2026 16:01
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 12 out of 13 changed files in this pull request and generated 2 comments.

@max-charlamb
Copy link
Member Author

max-charlamb commented Mar 6, 2026

/ba-g "cDAC only change and cDAC tests pass"

@max-charlamb max-charlamb enabled auto-merge (squash) March 6, 2026 17:50
@max-charlamb max-charlamb merged commit 6bf2076 into dotnet:main Mar 6, 2026
52 of 56 checks passed
@max-charlamb max-charlamb deleted the dev/maxcharlamb/runtime-cdac-interface-marshalling branch March 6, 2026 17:52
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.

4 participants