fs: ensure that a minidump is created on crash

Summary:
After printing the exception backtrace, EdenFS terminates manually.
Unfortunately, this means that Windows can't detect that the process crashed as
it thinks it terminated correctly. In turn, this prevents minidumps from being
created which makes debugging the crash impossible.

Fixing this is no easy task as returning from the exception handler would
always trigger an infinite recursion of unwind somewhere in the CRT code. This
would produce a minidump, but it wouldn't be handy to use. The only solution I
found is to reset the exception handler and invoke one as by default, this
creates a minidump. After that, we can exit EdenFS in the same way as before,
being careful to not call `std::abort` or `std::terminate`.

Reviewed By: chadaustin

Differential Revision: D41362303

fbshipit-source-id: 42422db66a5f8033796ed8cb5b3ccf1a235f1da5
This commit is contained in:
Xavier Deguillard 2022-11-16 23:22:50 -08:00 committed by Facebook GitHub Bot
parent 625ca6f96d
commit 93ecf2126b

View File

@ -238,6 +238,11 @@ LONG WINAPI windowsExceptionFilter(LPEXCEPTION_POINTERS excep) {
size = backtrace(frames, kMaxFrames);
backtraceSymbols(frames, size, err);
// Call an exception that bypass all exception handlers. This will create a
// crash dump on disk by default.
SetUnhandledExceptionFilter(nullptr);
UnhandledExceptionFilter(excep);
// Terminate the process.
// msvcrt abort() ultimately calls exit(3), so we shortcut that.
// Ideally we'd just exit() or ExitProcess() and be done, but it