]> git.cworth.org Git - apitrace/blobdiff - os_win32.cpp
Make sure that the snappyfile doesn't try to read past the end of file.
[apitrace] / os_win32.cpp
index 90ce8d3a74a41a5a660cc71547d27898d0d834e1..587503c41553fa7cd013cf5ad28862fa34f938a7 100644 (file)
@@ -24,6 +24,7 @@
  **************************************************************************/
 
 #include <windows.h>
+#include <assert.h>
 #include <signal.h>
 #include <string.h>
 #include <stdio.h>
@@ -134,12 +135,40 @@ Abort(void)
 #endif
 }
 
+
+static LPTOP_LEVEL_EXCEPTION_FILTER prevExceptionFilter = NULL;
+static void (*gCallback)(void) = NULL;
+
+static LONG WINAPI UnhandledExceptionFilter(PEXCEPTION_POINTERS pExceptionInfo)
+{
+    if (gCallback) {
+        gCallback();
+    }
+
+       if (prevExceptionFilter) {
+               return prevExceptionFilter(pExceptionInfo);
+    } else {
+               return EXCEPTION_CONTINUE_SEARCH;
+    }
+}
+
+void
+SetExceptionCallback(void (*callback)(void))
+{
+    assert(!gCallback);
+
+    if (!gCallback) {
+        gCallback = callback;
+
+        assert(!prevExceptionFilter);
+        prevExceptionFilter = SetUnhandledExceptionFilter(UnhandledExceptionFilter);
+    }
+}
+
 void
-CatchInterrupts(void (*func)(int))
+ResetExceptionCallback(void)
 {
-    signal(SIGINT, func);
-    signal(SIGHUP, func);
-    signal(SIGTERM, func);
+    gCallback = NULL;
 }