Skip to content

Conversation

@janvorli
Copy link
Member

@janvorli janvorli commented Sep 3, 2025

When ProfileEnter is called on a foreign thread that the runtime has not seen yet, which can happen for UnmanagedCallersOnly marked methods, it crashes in the GCX_COOP_THREAD_EXISTS(GET_THREAD()); That was left in by accident in my change I've made a long time ago and should not be there.
This change removes that switch, we switch to cooperative mode later in the ProfileEnter and setup the thread for runtime before that.

Close #115617

When ProfileEnter is called on a foreign thread that the runtime has not
seen yet, which can happen for UnmanagedCallersOnly marked methods,
it crashes in the GCX_COOP_THREAD_EXISTS(GET_THREAD()); That was left in
by accident in my change I've made a long time ago and should not be
there.
This change removes that switch, we switch to cooperative mode later in
the ProfileEnter and setup the thread for runtime before that.

Close dotnet#115617
@janvorli janvorli added this to the 10.0.0 milestone Sep 3, 2025
@janvorli janvorli requested a review from jkotas September 3, 2025 17:04
@janvorli janvorli self-assigned this Sep 3, 2025
Copilot AI review requested due to automatic review settings September 3, 2025 17:04
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 fixes a crash that occurs when ProfileEnter is called on a foreign thread (one that the runtime hasn't seen before), which can happen with UnmanagedCallersOnly marked methods. The fix removes an erroneous thread mode switch that was causing the crash.

  • Removes the problematic GCX_COOP_THREAD_EXISTS(GET_THREAD()) call that crashes on foreign threads
  • Changes from HCIMPL2_RAW to HCIMPL2 macro usage to properly handle thread setup

@dotnet-policy-service
Copy link
Contributor

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

Copy link
Member

@noahfalk noahfalk left a comment

Choose a reason for hiding this comment

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

thanks @janvorli!

@janvorli janvorli merged commit 655ec8a into dotnet:main Sep 4, 2025
98 checks passed
@janvorli
Copy link
Member Author

janvorli commented Sep 4, 2025

/backport to release/10.0

@github-actions
Copy link
Contributor

github-actions bot commented Sep 4, 2025

Started backporting to release/10.0: https://github.com/dotnet/runtime/actions/runs/17461109329

@github-actions github-actions bot locked and limited conversation to collaborators Oct 5, 2025
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.

ProfileEnter crashes for UnmanagedCallersOnly methods invoked from foreign threads not registered with runtime yet.

3 participants