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