Skip to content

Fix contract violations for OLE scenario.#114609

Merged
AaronRobinsonMSFT merged 6 commits intodotnet:mainfrom
AaronRobinsonMSFT:runtime_114372
Apr 16, 2025
Merged

Fix contract violations for OLE scenario.#114609
AaronRobinsonMSFT merged 6 commits intodotnet:mainfrom
AaronRobinsonMSFT:runtime_114372

Conversation

@AaronRobinsonMSFT
Copy link
Copy Markdown
Member

Rework the logic so the FCall doesn't do any
allocations and defers any non-fast scenario
to the slow path.

Fixes #114372

Rework the logic so the FCall doesn't do any
allocations and defers any non-fast scenario
to the slow path.
@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.

@AaronRobinsonMSFT AaronRobinsonMSFT marked this pull request as ready for review April 14, 2025 16:24
Copilot AI review requested due to automatic review settings April 14, 2025 16:24
Copy link
Copy Markdown
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 reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

src/coreclr/vm/stubhelpers.cpp:194

  • [nitpick] Consider adding a clarifying comment that explains TryGetOleTlsData only retrieves existing TLS data without creating it, to differentiate it clearly from GetOrCreateOleTlsData.
FORCEINLINE static SOleTlsData* TryGetOleTlsData()

Copy link
Copy Markdown
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 reviewed 2 out of 2 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (2)

src/coreclr/vm/stubhelpers.cpp:232

  • The removal of the FP state clearing call in the slow path diverges from the previous behavior where FP state was cleared for VB6 compatibility. Verify that this change is intentional and that it does not introduce issues in scenarios requiring FP state clearing.
GetCOMIPFromRCW_ClearFP();

src/coreclr/vm/olecontexthelpers.cpp:37

  • Switching the contract mode from MODE_ANY (with ENTRY_POINT) to MODE_COOPERATIVE may affect call sites that previously relied on a more flexible mode. Confirm that this change is appropriate for all scenarios where SetupOleContext is used.
MODE_COOPERATIVE;

@AaronRobinsonMSFT
Copy link
Copy Markdown
Member Author

/cc @jkoritzinsky

@AaronRobinsonMSFT AaronRobinsonMSFT merged commit e7baf91 into dotnet:main Apr 16, 2025
93 of 95 checks passed
@AaronRobinsonMSFT AaronRobinsonMSFT deleted the runtime_114372 branch April 16, 2025 17:39
@github-actions github-actions bot locked and limited conversation to collaborators May 17, 2025
@AaronRobinsonMSFT
Copy link
Copy Markdown
Member Author

/backport to release/10.0

@github-actions github-actions bot unlocked this conversation Apr 10, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Started backporting to release/10.0 (link to workflow run)

AaronRobinsonMSFT added a commit that referenced this pull request Apr 10, 2026
Fixes #126619.

This was a regression introduced in
#114609

When `System.StubHelpers.GetCOMIPFromRCW()` misses the fast path on a
native-created thread, the slow path can create OLE TLS and still
resolve the COM interface pointer from the RCW cache. Those cache hits
are borrowed and should not be released by the stub cleanup path.

This change moves the `pfNeedsRelease` decision to the slow helper so it
can distinguish between:
- RCW cache hits after OLE TLS initialization
- freshly acquired interface pointers from
`ComObject::GetComIPFromRCWThrowing`

Testing:
- verified against the local repro from #126619

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions
Copy link
Copy Markdown
Contributor

@AaronRobinsonMSFT backporting to release/10.0 failed, the patch most likely resulted in conflicts. Please backport manually!

git am output
$ git am --3way --empty=keep --ignore-whitespace --keep-non-patch changes.patch

Applying: Fix contract violations for OLE scenario.
Using index info to reconstruct a base tree...
M	src/coreclr/vm/olecontexthelpers.cpp
M	src/coreclr/vm/stubhelpers.cpp
Falling back to patching base and 3-way merge...
Auto-merging src/coreclr/vm/stubhelpers.cpp
CONFLICT (content): Merge conflict in src/coreclr/vm/stubhelpers.cpp
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
Patch failed at 0001 Fix contract violations for OLE scenario.
Error: The process '/usr/bin/git' failed with exit code 128

Link to workflow output

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 10, 2026
Sign up for free to 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.

Contract violation in SetupOleContext

3 participants