Skip to content

[release/10.0] Fix EH - throw from catch in UnmanagedCallersOnly - #131467

Merged
JulieLeeMSFT merged 2 commits into
dotnet:release/10.0from
janvorli:port-fix-throw-from-catch-unmanagedcallersonly
Jul 28, 2026
Merged

[release/10.0] Fix EH - throw from catch in UnmanagedCallersOnly#131467
JulieLeeMSFT merged 2 commits into
dotnet:release/10.0from
janvorli:port-fix-throw-from-catch-unmanagedcallersonly

Conversation

@janvorli

@janvorli janvorli commented Jul 28, 2026

Copy link
Copy Markdown
Member

Backport of #131163 to release/10.0

Customer Impact

There is an issue when an exception is thrown from catch in a method marked as UnmanagedCallersOnly on Windows. When such exception escapes the catch, it is not detected as going into CallEHFunclet, but it is thought to be escaping the UnmanagedCallersOnly method itself, thus going through a reverse pinvoke transition. That results in an incorrect handling of that exception. We don't detect the unwind is colliding with previous exception and we end up calling the same catch again. This results in an infinite loop and a stack overflow after a while.

Regression

  • Yes - in .NET 9 when new exception handling was enabled by default
  • No

Testing

Directed repro from the customer, regular coreclr / libraries tests.

Risk

Low. The change just fixes a condition that was incorrect for UnmanagedCallersOnly case.

Backport of dotnet#131163

There is an issue when an exception is thrown from catch in a method
marked as `UnmanagedCallersOnly` on Windows. When such exception escapes
the catch, it is not detected as going into CallEHFunclet, but it is
thought to be escaping the `UnmanagedCallersOnly` method itself, thus
going through a reverse pinvoke transition. That results in an incorrect
handling of that exception. We don't detect the unwind is colliding with
previous exception and we end up calling the same catch again. This
results in an infinite loop and a stack overflow after a while.
@janvorli janvorli added this to the 10.0.x milestone Jul 28, 2026
@janvorli
janvorli requested a review from jkotas July 28, 2026 13:52
@janvorli janvorli self-assigned this Jul 28, 2026
@janvorli janvorli added the Servicing-consider Issue for next servicing release review label Jul 28, 2026
Copilot AI review requested due to automatic review settings July 28, 2026 13:52
@janvorli
janvorli temporarily deployed to copilot-pat-pool July 28, 2026 13:52 — with GitHub Actions Inactive
@janvorli
janvorli temporarily deployed to copilot-pat-pool July 28, 2026 13:53 — with GitHub Actions Inactive
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
13 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @agocke
See info in area-owners.md if you want to be subscribed.

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

Backport to release/10.0 addressing incorrect unwind classification when an exception escapes a catch inside an [UnmanagedCallersOnly] callback on Windows (leading to re-entering the same catch and eventual stack overflow). The PR adjusts reverse-P/Invoke detection during funclet unwinds and adds regression coverage in the exception interop tests.

Changes:

  • Update CoreCLR EH stack-walk logic to ignore the parent method’s reverse-P/Invoke GC info when unwinding a funclet.
  • Add new [UnmanagedCallersOnly] callbacks and corresponding regression tests for throwing native/managed exceptions from inside a catch.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/tests/baseservices/exceptions/exceptioninterop/ExceptionInterop.cs Adds new UnmanagedCallersOnly callbacks and intended regression tests for throw-from-catch scenarios (Windows-only).
src/coreclr/vm/exceptionhandling.cpp Adjusts reverse-P/Invoke propagation detection when unwinding from funclets to avoid misclassifying EH transitions.
Comments suppressed due to low confidence (1)

src/tests/baseservices/exceptions/exceptioninterop/ExceptionInterop.cs:284

  • This method looks like a new test, but it is missing a [Fact] attribute, so it won't be discovered/executed by the test runner.
    [PlatformSpecific(TestPlatforms.Windows)]
    [SkipOnMono("Exception interop not supported on Mono.")]
    public static void ThrowManagedExceptionFromCatchInUnmanagedCallersOnlyCallback()
    {

Comment thread src/coreclr/vm/exceptionhandling.cpp
@jkotas
jkotas self-requested a review July 28, 2026 14:04
Copilot AI review requested due to automatic review settings July 28, 2026 15:09

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

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

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

LGTM.

@rbhanda rbhanda modified the milestones: 10.0.x, 10.0.12 Jul 28, 2026
@rbhanda rbhanda added Servicing-approved Approved for servicing release and removed Servicing-consider Issue for next servicing release review labels Jul 28, 2026
@JulieLeeMSFT
JulieLeeMSFT merged commit 6e620d7 into dotnet:release/10.0 Jul 28, 2026
114 of 115 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-VM-coreclr Servicing-approved Approved for servicing release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants