-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Overriding the default behavior in case of fatal errors #116050
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
Closed
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
547c687
API defined
VSadov d5b741b
arg checks
VSadov 48a04ab
move the declaration
VSadov b967f3a
added simple test
VSadov ace0d9e
exclude the test on mono and NativeAOT
VSadov 73411e5
make simple test to pass
VSadov 4200d52
make GCC happy about char8_t
VSadov 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// | ||
|
||
enum FatalErrorHandlerResult : int32_t | ||
{ | ||
RunDefaultHandler = 0, | ||
SkipDefaultHandler = 1, | ||
}; | ||
|
||
#if defined(_MSC_VER) && defined(_M_IX86) | ||
#define DOTNET_CALLCONV __stdcall | ||
#else | ||
#define DOTNET_CALLCONV | ||
#endif | ||
|
||
struct FatalErrorInfo | ||
{ | ||
size_t size; // size of the FatalErrorInfo instance | ||
void* address; // code location correlated with the failure (i.e. location where FailFast was called) | ||
|
||
// exception/signal information, if available | ||
void* info; // Cast to PEXCEPTION_RECORD on Windows or siginfo_t* on non-Windows. | ||
void* context; // Cast to PCONTEXT on Windows or ucontext_t* on non-Windows. | ||
|
||
// An entry point for logging additional information about the crash. | ||
// As runtime finds information suitable for logging, it will invoke pfnLogAction and pass the information in logString. | ||
// The callback may be called multiple times. | ||
// Combined, the logString will contain the same parts as in the console output of the default crash handler. | ||
// The errorLog string will have UTF-8 encoding. | ||
void (DOTNET_CALLCONV *pfnGetFatalErrorLog)( | ||
FatalErrorInfo* errorData, | ||
void (DOTNET_CALLCONV *pfnLogAction)(char8_t* logString, void *userContext), | ||
void* userContext); | ||
|
||
// More information can be exposed for querying in the future by adding | ||
// entry points with similar pattern as in pfnGetFatalErrorLog | ||
}; |
32 changes: 32 additions & 0 deletions
32
src/tests/baseservices/exceptions/FatalErrorHandler/UnhandledException.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,32 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
using System; | ||
using System.Runtime.InteropServices; | ||
using System.Runtime.ExceptionServices; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using TestLibrary; | ||
using Xunit; | ||
|
||
unsafe public class UnhandledException | ||
{ | ||
[UnmanagedCallersOnly] | ||
static int Handler(int i, void* ptr) | ||
{ | ||
Environment.Exit(100); | ||
|
||
// unreachable | ||
return 42; | ||
} | ||
|
||
public static int Main() | ||
{ | ||
// set handler | ||
ExceptionHandling.SetFatalErrorHandler((delegate* unmanaged<int, void*, int>)&Handler); | ||
|
||
// throw | ||
Environment.FailFast("hello"); | ||
|
||
return 42; | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/tests/baseservices/exceptions/FatalErrorHandler/UnhandledException.csproj
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 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<!-- tests process-wide state --> | ||
<RequiresProcessIsolation>true</RequiresProcessIsolation> | ||
<!-- Test checks the behavior of Main --> | ||
<ReferenceXUnitWrapperGenerator>false</ReferenceXUnitWrapperGenerator> | ||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
<CLRTestPriority>0</CLRTestPriority> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Compile Include="UnhandledException.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="$(TestSourceDir)Common/CoreCLRTestLibrary/CoreCLRTestLibrary.csproj" /> | ||
</ItemGroup> | ||
</Project> |
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.
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.
I would move this next to
SetUnhandledExceptionHandler