1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-19 11:02:59 +02:00

[Support] On Windows, ensure abort() can be catched several times in a row with CrashRecoveryContext

Before this patch, the CrashRecoveryContext would only catch the first abort(). Any further calls to abort() inside subsquent CrashRecoveryContexts would not be catched. This is because the Windows CRT removes the abort() handler before calling it.

This is part of https://reviews.llvm.org/D70378
This commit is contained in:
Alexandre Ganea 2020-09-22 18:22:01 -04:00
parent 0d7df5ad90
commit 6aabad1fd2
3 changed files with 17 additions and 3 deletions

View File

@ -44,11 +44,11 @@ class CrashRecoveryContextCleanup;
/// executed in any case, whether crash occurs or not. These actions may be used /// executed in any case, whether crash occurs or not. These actions may be used
/// to reclaim resources in the case of crash. /// to reclaim resources in the case of crash.
class CrashRecoveryContext { class CrashRecoveryContext {
void *Impl; void *Impl = nullptr;
CrashRecoveryContextCleanup *head; CrashRecoveryContextCleanup *head = nullptr;
public: public:
CrashRecoveryContext() : Impl(nullptr), head(nullptr) {} CrashRecoveryContext();
~CrashRecoveryContext(); ~CrashRecoveryContext();
/// Register cleanup handler, which is used when the recovery context is /// Register cleanup handler, which is used when the recovery context is

View File

@ -95,6 +95,13 @@ static void uninstallExceptionOrSignalHandlers();
CrashRecoveryContextCleanup::~CrashRecoveryContextCleanup() {} CrashRecoveryContextCleanup::~CrashRecoveryContextCleanup() {}
CrashRecoveryContext::CrashRecoveryContext() {
// On Windows, if abort() was previously triggered (and caught by a previous
// CrashRecoveryContext) the Windows CRT removes our installed signal handler,
// so we need to install it again.
sys::DisableSystemDialogsOnCrash();
}
CrashRecoveryContext::~CrashRecoveryContext() { CrashRecoveryContext::~CrashRecoveryContext() {
// Reclaim registered resources. // Reclaim registered resources.
CrashRecoveryContextCleanup *i = head; CrashRecoveryContextCleanup *i = head;

View File

@ -123,4 +123,11 @@ TEST(CrashRecoveryTest, CallOutputDebugString) {
EXPECT_TRUE(CrashRecoveryContext().RunSafely(outputString)); EXPECT_TRUE(CrashRecoveryContext().RunSafely(outputString));
} }
TEST(CrashRecoveryTest, Abort) {
llvm::CrashRecoveryContext::Enable();
auto A = []() { abort(); };
EXPECT_FALSE(CrashRecoveryContext().RunSafely(A));
// Test a second time to ensure we reinstall the abort signal handler.
EXPECT_FALSE(CrashRecoveryContext().RunSafely(A));
}
#endif #endif