-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Implement ExceptionHandling.SetFatalErrorHandler
#129543
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
Open
AaronRobinsonMSFT
wants to merge
56
commits into
dotnet:main
Choose a base branch
from
AaronRobinsonMSFT:set-fatal-error-handler
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
56 commits
Select commit
Hold shift + click to select a range
180c0b1
Implement SetFatalErrorHandler for NativeAOT
AaronRobinsonMSFT fc2fd84
Implement SetFatalErrorHandler for CoreCLR
AaronRobinsonMSFT 9e102dd
Apply suggestions from code review
AaronRobinsonMSFT 0da0fa6
Use _exit() for SkipDefaultHandler on Unix
AaronRobinsonMSFT 01fe291
Add using declaration for Process in test
AaronRobinsonMSFT fd85bf0
Simplify test process launch with Process.RunAndCaptureText
AaronRobinsonMSFT 1c4d60c
Address PR feedback: use _Exit, fix IsCrashExitCode, suppress warning
AaronRobinsonMSFT e27a586
Fix handler invocation on Windows and exclude Mono
AaronRobinsonMSFT e6eec0a
Address PR feedback: UTF-8 crash log, exit code checks, truncation fix
AaronRobinsonMSFT 6965928
Merge remote-tracking branch 'upstream/main' into set-fatal-error-han…
AaronRobinsonMSFT 6249ab4
Replace managed test handlers with native C++ library
AaronRobinsonMSFT 05e0539
Potential fix for pull request finding
AaronRobinsonMSFT d48a54e
Move crash log writer abstraction into eepolicy.cpp
AaronRobinsonMSFT 88d4857
Fix HandleFatalStackOverflow: invoke handler after stack trace
AaronRobinsonMSFT 6b1848b
Remove unused SystemNative__Exit entrypoint
AaronRobinsonMSFT 58f269d
Address PR review feedback
AaronRobinsonMSFT 8a47f90
Populate FatalErrorInfo with native exception pointers on Unix
AaronRobinsonMSFT 9f69d40
Move fatal error handler to C++ static with QCall registration
AaronRobinsonMSFT a9d2d1c
Simplify InvokeFatalErrorHandler to direct call
AaronRobinsonMSFT 3b40c8c
Address PR feedback: fix QCall return type, PAL decorators, remove de…
AaronRobinsonMSFT d798770
Route stack trace through CrashInfoWriter for callback support
AaronRobinsonMSFT 83a87c4
Surface native exception info/context to the fatal error handler on m…
AaronRobinsonMSFT 56ce69a
Refactor fatal error property storage into common core + platform module
AaronRobinsonMSFT 790b319
Fix duplicate crash log and stack-overflow header in fatal error path
AaronRobinsonMSFT a65444a
Store hardware-exception records per-fault to survive nested faults
AaronRobinsonMSFT ad36176
Align hardware-exception records within the per-fault buffer
AaronRobinsonMSFT 9ab5194
Use InlineArray16 for crash log fragment storage
AaronRobinsonMSFT 5ec609f
Address PR review feedback
AaronRobinsonMSFT baa5e41
Clarify comment on FatalErrorPropertyGetter regarding ownership of data
AaronRobinsonMSFT 9a074eb
Address PR review feedback
AaronRobinsonMSFT 2abb2df
Merge remote-tracking branch 'upstream/main' into set-fatal-error-han…
AaronRobinsonMSFT a3ce5f0
Address PR review feedback
AaronRobinsonMSFT 01e4dc1
Stage 1: surface fault IP to fatal error handler (managed path)
AaronRobinsonMSFT 323a39f
Stage 2: route genuinely-unmanaged fatal faults to the fatal error ha…
AaronRobinsonMSFT 9e1739e
Stage 2: route genuinely-unmanaged fatal faults to the fatal error ha…
AaronRobinsonMSFT 401175a
WIP
AaronRobinsonMSFT f28cd9f
Merge branch 'main' into set-fatal-error-handler
AaronRobinsonMSFT e011455
Address review feedback: synchronize native fatal handler pointer, po…
AaronRobinsonMSFT 3b16843
Enhance comments in fatal error handling to clarify encoder behavior …
AaronRobinsonMSFT 1a608d4
Refactor crash log handling to use a single managed string, improving…
AaronRobinsonMSFT f72811e
Serialize concurrent fatal error handling to ensure only the first fa…
AaronRobinsonMSFT 7960de5
Merge remote-tracking branch 'upstream/main' into set-fatal-error-han…
AaronRobinsonMSFT 2fa3051
Install fatal error handling header
AaronRobinsonMSFT cd46bf2
Make C compliant
AaronRobinsonMSFT 5871c68
Handle native fatal exceptions in CoreCLR
AaronRobinsonMSFT 46a4925
Invoke fatal error handler for SIGABRT
AaronRobinsonMSFT 0b0e3ad
Merge upstream/main into set-fatal-error-handler
AaronRobinsonMSFT 2fba4fa
Split TerminateProcess interop declarations
AaronRobinsonMSFT df78676
Refactor fatal error handling: remove previous unhandled exception fi…
AaronRobinsonMSFT b67696a
Reserve fatal error handler return values
AaronRobinsonMSFT 5bd6d69
Invoke NativeAOT fatal handlers from native code
AaronRobinsonMSFT 72669ae
Cover CoreCLR native utility threads in the fatal error handler
AaronRobinsonMSFT b6190a6
Ensure process termination in InvokeFatalErrorHandler on spurious wakeup
AaronRobinsonMSFT ec3ae8e
Update README.md for clarity and formatting improvements
AaronRobinsonMSFT 0a99673
Merge remote-tracking branch 'upstream/main' into set-fatal-error-han…
AaronRobinsonMSFT cbd3c88
Bad merge.
AaronRobinsonMSFT File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
16 changes: 16 additions & 0 deletions
16
.../System.Private.CoreLib/src/System/Runtime/ExceptionServices/ExceptionHandling.CoreCLR.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System.Runtime.CompilerServices; | ||
| using System.Runtime.InteropServices; | ||
|
|
||
| namespace System.Runtime.ExceptionServices | ||
| { | ||
| public static partial class ExceptionHandling | ||
| { | ||
| [LibraryImport(RuntimeHelpers.QCall, EntryPoint = "ExceptionHandling_TrySetFatalErrorHandler")] | ||
| [SuppressGCTransition] | ||
| [return: MarshalAs(UnmanagedType.U1)] | ||
| private static partial bool TrySetFatalErrorHandler(IntPtr handler); | ||
| } | ||
| } |
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
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
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
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
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
24 changes: 24 additions & 0 deletions
24
...ystem.Private.CoreLib/src/System/Runtime/ExceptionServices/ExceptionHandling.NativeAot.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System.Threading; | ||
|
|
||
| namespace System.Runtime.ExceptionServices | ||
| { | ||
| public static partial class ExceptionHandling | ||
| { | ||
| internal static IntPtr s_fatalErrorHandler; | ||
|
|
||
| private static unsafe bool TrySetFatalErrorHandler(IntPtr handler) | ||
| { | ||
| if (Interlocked.CompareExchange(ref s_fatalErrorHandler, handler, IntPtr.Zero) != IntPtr.Zero) | ||
| return false; | ||
|
|
||
| // Register the user callback with the native runtime so genuinely-unmanaged | ||
| // fatal exceptions can invoke it without transitioning into managed code. | ||
| RuntimeImports.RhpRegisterFatalErrorHandler((void*)handler); | ||
|
|
||
| return true; | ||
| } | ||
| } | ||
| } |
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
Oops, something went wrong.
Oops, something went wrong.
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.
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.
What is the default fatal handling going to do in this case - is the process just going to exit?
It means that the user callback on the first thread may be terminated by the process exit before it gets a chance to do much.
(I am not sure what to do about this.)
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.
@jkotas Yes. In this case, the loser drives process exit. After
RhpInvokeFatalErrorHandlerForNativeExceptionreturns on the losing thread:Windows -
RhpVectoredExceptionHandlerreturnsEXCEPTION_CONTINUE_SEARCHorRaiseFailFastExceptionif the fault IP is inside the runtime module -> unhandled termination.Non-Windows -
SIGSEGVHandlerchains to the previous/default signal action -> termination.So if that races the owner thread still running the user callback, the callback can be truncated by process exit.
But this only happens in one case and I'm not sure how common it is. A concurrent exception where the losing thread is in cooperative mode. Non-cooperative / unattached threads already
PalSleep(INFINITE)inWaitForFatalErrorHandlerIfGcSafeand never reach the terminating path, so the owner would complete normally.I think we've got two options right now.