-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Implement UnhandledException hook for finalizer scenario in Mono. #118563
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
Conversation
There was a problem hiding this 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 implements the UnhandledException hook for finalizer scenarios in Mono runtime, building on previous work in shared corelib code. The implementation ensures that unhandled exceptions in finalizers are properly handled through the global exception handler mechanism.
Key changes:
- Introduces a new
GuardedFinalizemethod that wraps finalizer calls with exception handling - Updates Mono's finalizer execution path to use the guarded version instead of direct finalizer calls
- Enables previously excluded UnhandledException tests for Mono (with some exceptions)
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/tests/issues.targets | Enables UnhandledException tests for Mono, excluding only specific problematic test cases |
| src/mono/mono/mini/aot-compiler.c | Updates AOT compilation to use GuardedFinalize instead of Finalize for runtime-invoke |
| src/mono/mono/metadata/gc.c | Modifies finalizer execution to call GuardedFinalize and updates method resolution |
| src/mono/System.Private.CoreLib/src/System/Object.Mono.cs | Implements GuardedFinalize method with exception handling using UnsafeAccessor |
| src/mono/System.Private.CoreLib/src/ILLink/ILLink.Descriptors.xml | Preserves GuardedFinalize method from IL linking removal |
|
I think this is ready for a review. There are some failures on ios/tvos, but I cannot tell if these are caused by the change. |
|
This keeps failing on ios/tvos. I am out of ideas why. @lambdageek - could you take a look? |
|
@VSadov I can't really see anything in the CI logs, but probably something needs to tell Mono's AOT compiler to compile |
|
Let me run it locally to try to get better diagnostics/ stack trace. |
|
I am getting the following error on iOS arm64 device: |
I think I am precompiling the wrapper. We had the same pattern before, just the wrapper was for The wrapper for |
|
Making Virtual |
|
LLVMFULLAOT fails in The rest is passing now, including the newly enabled tests for |
|
/ba-g LLVMFULLAOT failure in Regression_2 is unrelated. Happens without this change as well (see: NOOP change in #118642) |
|
Thanks for reviewing! |
|
/backport to release/10.0-rc1 |
|
Started backporting to release/10.0-rc1: https://github.com/dotnet/runtime/actions/runs/17064173533 |
A follow-up for #109806
Most of the implementation is in the shared corelib code and works for Mono, but finalization scenario needs special handling as that part is not shared.