Structured exception handling was not working as expected because the exception filtering function didn't return EXCEPTION_EXECUTE_HANDLER.
@@ -35,30 +35,26 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#if _WIN32 || __CYGWIN__
#include <windows.h>
-#include <setjmp.h>
-jmp_buf *exc_jmp_buf[YR_MAX_THREADS];
+// If compiling with Microsoft's compiler use structered exception handling.
+
+#ifdef _MSC_VER
+
+#include <excpt.h>
static LONG CALLBACK exception_handler(
PEXCEPTION_POINTERS ExceptionInfo)
{
- int tidx = yr_get_tidx();
-
switch(ExceptionInfo->ExceptionRecord->ExceptionCode)
{
case EXCEPTION_IN_PAGE_ERROR:
case EXCEPTION_ACCESS_VIOLATION:
- if (tidx != -1 && exc_jmp_buf[tidx] != NULL)
- longjmp(*exc_jmp_buf[tidx], 1);
+ return EXCEPTION_EXECUTE_HANDLER;
}
return EXCEPTION_CONTINUE_SEARCH;
}
-#ifdef _MSC_VER
-
-#include <excpt.h>
-
#define YR_TRYCATCH(_do_,_try_clause_,_catch_clause_) \
do \
{ \
@@ -75,6 +71,28 @@ static LONG CALLBACK exception_handler(
#else
+// If not compiling with Microsoft's compiler use vectored exception handling.
+
+#include <setjmp.h>
+
+jmp_buf *exc_jmp_buf[YR_MAX_THREADS];
+
+static LONG CALLBACK exception_handler(
+ PEXCEPTION_POINTERS ExceptionInfo)
+{
+ int tidx = yr_get_tidx();
+
+ switch(ExceptionInfo->ExceptionRecord->ExceptionCode)
+ {
+ case EXCEPTION_IN_PAGE_ERROR:
+ case EXCEPTION_ACCESS_VIOLATION:
+ if (tidx != -1 && exc_jmp_buf[tidx] != NULL)
+ longjmp(*exc_jmp_buf[tidx], 1);
+ }
+
+ return EXCEPTION_CONTINUE_SEARCH;
+}
+
#define YR_TRYCATCH(_do_,_try_clause_,_catch_clause_) \
do \
{ \
