Skip to content

Fix ProfileEnter when called on a foreign thread - #119327

Merged
janvorli merged 2 commits into
dotnet:mainfrom
janvorli:fix-profile-enter-for-unmanaged-callers-only
Sep 4, 2025
Merged

janvorli merged 2 commits into
dotnet:mainfrom
janvorli:fix-profile-enter-for-unmanaged-callers-only

Conversation

@janvorli

@janvorli janvorli commented Sep 3, 2025

Copy link
Copy Markdown
Member

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

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 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
Copy Markdown
Contributor

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

@noahfalk noahfalk 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.

thanks @janvorli!

@janvorli
janvorli merged commit 655ec8a into dotnet:main Sep 4, 2025
@janvorli

janvorli commented Sep 4, 2025

Copy link
Copy Markdown
Member Author

/backport to release/10.0

@github-actions

github-actions Bot commented Sep 4, 2025

Copy link
Copy Markdown
Contributor

@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.

4 participants