X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=os_win32.cpp;h=587503c41553fa7cd013cf5ad28862fa34f938a7;hb=b5f2ee344ef2914ca141608107c571ec0c28c6a6;hp=90ce8d3a74a41a5a660cc71547d27898d0d834e1;hpb=00e0021870c9bbba51376aa32554183e1c7859ba;p=apitrace diff --git a/os_win32.cpp b/os_win32.cpp index 90ce8d3..587503c 100644 --- a/os_win32.cpp +++ b/os_win32.cpp @@ -24,6 +24,7 @@ **************************************************************************/ #include +#include #include #include #include @@ -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; }