Skip to content

Fix ReferenceTrackerHost fixed-address storage - #129669

Merged
jkotas merged 3 commits into
mainfrom
copilot/fix-fixed-address-value-type-issue
Jun 23, 2026
Merged

Fix ReferenceTrackerHost fixed-address storage#129669
jkotas merged 3 commits into
mainfrom
copilot/fix-fixed-address-value-type-issue

Conversation

CopilotAI 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]privatestaticreadonlyunsafeReferenceTrackerHostObjects_globalHostServices=new((IReferenceTrackerHostVftbl*)Unsafe.AsPointer(inHostServices.Vftbl));privatereadonlyunsafestructReferenceTrackerHostObject{publicreadonlyIReferenceTrackerHostVftbl*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>
CopilotAI requested review from Copilot and removed request for CopilotJune 21, 2026 14:10
CopilotAI changed the title [WIP] Fix FixedAddressValueType handling in CoreCLR implementationFix ReferenceTrackerHost fixed-address storageJun 21, 2026
CopilotAI requested a review from jkotasJune 21, 2026 14:15

@jkotasjkotas 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>
CopilotAI requested review from Copilot and removed request for CopilotJune 21, 2026 15:18

CopilotAI commented Jun 21, 2026

Copy link
Copy Markdown
ContributorAuthor

@copilot

Addressed in 721b060.

Note

This comment was created by GitHub Copilot.

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

CopilotAI 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

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.

@jkotas
jkotas merged commit 6f79670 into mainJun 23, 2026
146 checks passed
@jkotas
jkotas deleted the copilot/fix-fixed-address-value-type-issue branch June 23, 2026 01:36
@dotnet-milestone-botdotnet-milestone-botBot added this to the 11.0-preview6 milestone Jun 24, 2026
eiriktsarpalis pushed a commit that referenced this pull request Jul 15, 2026
`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.
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>
@github-actionsgithub-actionsBot locked and limited conversation to collaborators Jul 24, 2026
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

@hamarb123@jkotas@AaronRobinsonMSFT