**************************************************************************/
#include <windows.h>
+#include <assert.h>
+#include <signal.h>
#include <string.h>
#include <stdio.h>
va_end(ap);
OutputDebugStringA(buf);
+
+ /*
+ * Also write the message to stderr, when a debugger is not present (to
+ * avoid duplicate messages in command line debuggers).
+ */
+#if _WIN32_WINNT > 0x0400
if (!IsDebuggerPresent()) {
fflush(stdout);
fputs(buf, stderr);
fflush(stderr);
}
+#endif
}
long long GetTime(void)
{
static LARGE_INTEGER frequency;
LARGE_INTEGER counter;
- if(!frequency.QuadPart)
+ if (!frequency.QuadPart)
QueryPerformanceFrequency(&frequency);
QueryPerformanceCounter(&counter);
return counter.QuadPart*1000000LL/frequency.QuadPart;
#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
+ResetExceptionCallback(void)
+{
+ gCallback = NULL;
+}
+
+
} /* namespace OS */