summaryrefslogtreecommitdiff
path: root/ZAPD/CrashHandler.cpp
diff options
context:
space:
mode:
authorlouist103 <louist103@gmail.com>2022-10-25 11:59:52 -0400
committerlouist103 <louist103@gmail.com>2022-10-25 11:59:52 -0400
commitd79e0fbfab492dc22fa0fa8fecaa2bdba77d6b4f (patch)
tree77b328fcc1e5b7a860655b98c5cba473cdbdd5f1 /ZAPD/CrashHandler.cpp
parent78fdac56498f674eba2692e075d415a12cb4a31f (diff)
Cleanup crash handler.
Diffstat (limited to 'ZAPD/CrashHandler.cpp')
-rw-r--r--ZAPD/CrashHandler.cpp40
1 files changed, 40 insertions, 0 deletions
diff --git a/ZAPD/CrashHandler.cpp b/ZAPD/CrashHandler.cpp
index 3a45260..b1b4a47 100644
--- a/ZAPD/CrashHandler.cpp
+++ b/ZAPD/CrashHandler.cpp
@@ -1,6 +1,32 @@
#include "CrashHandler.h"
#include "Utils/StringHelper.h"
+#if __has_include(<unistd.h>)
+#define HAS_POSIX 1
+#else
+#define HAS_POSIX 0
+#endif
+
+#include <array>
+#include <cstdio>
+#include <cstdlib>
+#include <ctime>
+
+#if HAS_POSIX == 1
+#include <csignal>
+#include <cxxabi.h> // for __cxa_demangle
+#include <dlfcn.h> // for dladdr
+#include <execinfo.h>
+#include <unistd.h>
+#elif defined(_MSC_VER)
+#include <Windows.h>
+#include <DbgHelp.h>
+
+#include <inttypes.h>
+
+#pragma comment(lib, "Dbghelp.lib")
+#endif
+
// Feel free to add more crash messages.
static std::array<const char* const, 14> crashEasterEgg = {
@@ -164,5 +190,19 @@ LONG seh_filter(_EXCEPTION_POINTERS* ex)
printStack(ex->ContextRecord);
return EXCEPTION_EXECUTE_HANDLER;
}
+#endif
+void CrashHandler_Init()
+{
+#if HAS_POSIX == 1
+ signal(SIGSEGV, ErrorHandler);
+ signal(SIGABRT, ErrorHandler);
+#elif defined(_MSC_VER)
+ SetUnhandledExceptionFilter(seh_filter);
+#else
+ HANDLE_WARNING(WarningType::Always,
+ "tried to set error handler, but this ZAPD build lacks support for one", "");
#endif
+}
+
+