[release/10.0] Fix EH - throw from catch in UnmanagedCallersOnly - #131467
Merged
JulieLeeMSFT merged 2 commits intoJul 28, 2026
Merged
Conversation
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
temporarily deployed
to
copilot-pat-pool
July 28, 2026 13:52 — with
GitHub Actions
Inactive
janvorli
temporarily deployed
to
copilot-pat-pool
July 28, 2026 13:53 — with
GitHub Actions
Inactive
|
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. |
Contributor
|
Tagging subscribers to this area: @agocke |
Contributor
There was a problem hiding this comment.
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 acatch.
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()
{
jkotas
approved these changes
Jul 28, 2026
jkotas
self-requested a review
July 28, 2026 14:04
AaronRobinsonMSFT
approved these changes
Jul 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
UnmanagedCallersOnlyon Windows. When such exception escapes the catch, it is not detected as going into CallEHFunclet, but it is thought to be escaping theUnmanagedCallersOnlymethod 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
Testing
Directed repro from the customer, regular coreclr / libraries tests.
Risk
Low. The change just fixes a condition that was incorrect for UnmanagedCallersOnly case.