Skip to content

x86/funclets: Handle longjmp #115932

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 24, 2025
Merged

Conversation

filipnavara
Copy link
Member

@filipnavara filipnavara commented May 23, 2025

Implement basic support for unwinding longjmp across managed frames to match x64 and old EH behavior.

Like other Windows platforms we get our exception handler called with STATUS_LONGJMP exception. However, unlike 64-bit platforms we don't get the original jmp_buf and return value in the ExceptionInformation parameters. In order to handle the longjmp we need to return back from the ProcessCLRException call which is currently not done anywhere else.

The solution is a bit of an abuse. We create our own setjmp trampoline from ProcessCLRException and use that to return from last CallCatchFunclet at the end of DispatchEx. In order not to interfere with C++ unwinding we need to extract the setjmp into its own function with no C++ destructors on the frame.

Also fix #115701 by calling GCX_PREEMP_NO_DTOR in PropagateLongJmpThroughNativeFrames while I am at it.

Contributes to #113985

@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label May 23, 2025
@filipnavara
Copy link
Member Author

The alternative solution would be to just detect STATUS_LONGJMP and fail fast on the spot with a meaningful message but since I already got far enough with a viable workaround I thought we could just do that.

Copy link
Member

@janvorli janvorli left a comment

Choose a reason for hiding this comment

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

LGTM, thank you!

Co-authored-by: Jan Kotas <jkotas@microsoft.com>
@jkotas
Copy link
Member

jkotas commented May 24, 2025

/ba-g unrelated timeouts

@jkotas jkotas merged commit cf53694 into dotnet:main May 24, 2025
92 of 95 checks passed
@filipnavara filipnavara deleted the longjmp_x86_funclets branch June 5, 2025 06:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-ExceptionHandling-coreclr community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Missing GCX_PREEMP_NO_DTOR in PropagateLongJmpThroughNativeFrames
3 participants