Check haddocking works when validating
[ghc-hetmet.git] / rts / seh_excn.c
1 #include "seh_excn.h"
2
3 /*
4  * Exception / signal handlers.
5  */
6 #if defined(__MINGW32__)
7 jmp_buf seh_unwind_to;
8 unsigned long seh_excn_code; /* variable used to communicate what kind of exception we've caught;nice. */
9
10 EXCEPTION_DISPOSITION
11 catchDivZero(struct _EXCEPTION_RECORD* rec,
12          void* arg1 __attribute__((unused)),
13          struct _CONTEXT* ctxt __attribute__((unused)),
14          void* arg2 __attribute__((unused)))
15 {
16      if ((rec->ExceptionFlags & EH_UNWINDING) != 0) {
17      // When the system unwinds the SEH stack after having handled an excn,
18      // return immediately.
19          return ExceptionContinueSearch;
20      }
21      switch (rec->ExceptionCode) {
22      case EXCEPTION_FLT_DIVIDE_BY_ZERO:
23      case EXCEPTION_INT_DIVIDE_BY_ZERO:
24      seh_excn_code = 0;
25      longjmp(seh_unwind_to, rec->ExceptionCode);
26      return ExceptionContinueExecution;
27      case EXCEPTION_STACK_OVERFLOW:
28      seh_excn_code = 1;
29      longjmp(seh_unwind_to, rec->ExceptionCode);
30      return ExceptionContinueExecution;
31      case EXCEPTION_ACCESS_VIOLATION:
32      seh_excn_code = 2;
33      longjmp(seh_unwind_to, rec->ExceptionCode);
34      return ExceptionContinueExecution;
35      longjmp(seh_unwind_to, rec->ExceptionCode);
36      return ExceptionContinueExecution;
37      default: ;
38      }
39      return ExceptionContinueSearch;
40 }
41 #endif
42