Skip to content

Fix ReferenceTrackerHost fixed-address storage#129669

Open
Copilot wants to merge 3 commits into
mainfrom
copilot/fix-fixed-address-value-type-issue
Open

Fix ReferenceTrackerHost fixed-address storage#129669
Copilot wants to merge 3 commits into
mainfrom
copilot/fix-fixed-address-value-type-issue

Conversation

Copilot AI commented Jun 21, 2026

Copy link
Copy Markdown
Contributor

ReferenceTrackerHost stored s_globalHostServices as an IntPtr annotated with [FixedAddressValueType], but that attribute does not apply to primitive value types. This change avoids relying on that unsupported combination while keeping the COM host object layout unchanged.

  • What changed

    • Replaced s_globalHostServices from IntPtr with a small wrapper value type that contains the vtable pointer.
    • Kept [FixedAddressValueType] on s_globalHostServices, but now applied to a non-primitive value type where the runtime honors it.
  • Why this is safer

    • Removes the dependency on FixedAddressValueType behavior for IntPtr.
    • Preserves the existing native shape expected by SetReferenceTrackerHost: a pointer to a single-field object whose first field is the vtable pointer.
  • Shape

    [FixedAddressValueType]
    private static readonly unsafe ReferenceTrackerHostObject s_globalHostServices =
        new((IReferenceTrackerHostVftbl*)Unsafe.AsPointer(in HostServices.Vftbl));
    
    private readonly unsafe struct ReferenceTrackerHostObject
    {
        public readonly IReferenceTrackerHostVftbl* Vftbl;
    }

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @dotnet/interop-contrib
See info in area-owners.md if you want to be subscribed.

Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot June 21, 2026 14:10
Copilot AI changed the title [WIP] Fix FixedAddressValueType handling in CoreCLR implementation Fix ReferenceTrackerHost fixed-address storage Jun 21, 2026
Copilot AI requested a review from jkotas June 21, 2026 14:15

@jkotas jkotas left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot June 21, 2026 15:18

Copilot AI commented Jun 21, 2026

Copy link
Copy Markdown
Contributor Author

@copilot

Addressed in 721b060.

Note

This comment was created by GitHub Copilot.

Copilot AI requested a review from jkotas June 21, 2026 15:20
@jkotas jkotas marked this pull request as ready for review June 21, 2026 15:35

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

This PR adjusts how ReferenceTrackerHost stores the global COM host “this” pointer so that the fixed-address storage is applied to a non-primitive value type while preserving the native layout expected by IReferenceTrackerManager.SetReferenceTrackerHost.

Changes:

  • Replaced the fixed-address static IntPtr used as the host object with a single-field value-type instance holding the vtable pointer.
  • Updated SetReferenceTrackerHost to pass the address of that fixed instance to the native SetReferenceTrackerHost call.

@hamarb123

Copy link
Copy Markdown
Contributor

(Btw, you can also just use ValueTuple<IntPtr> - would give a smaller diff of +2/-2)

@jkotas

jkotas commented Jun 22, 2026

Copy link
Copy Markdown
Member

ValueTuple has large set of dependencies. It comes with code bloat risk. Avoiding it saves you from having to worry about it in code that's likely included in minimal apps that we track naot binary sizes for.

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.

5 participants