summaryrefslogtreecommitdiff
path: root/rts/win32/seh_excn.c
blob: 4934a7def0e2f6ce9bb2563601155f72b7e86b5e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include "ghcconfig.h"
#include "seh_excn.h"

/*
 * Exception / signal handlers.
 */
#if defined(mingw32_HOST_OS)
#if defined(i386_HOST_ARCH)
jmp_buf seh_unwind_to;
unsigned long seh_excn_code; /* variable used to communicate what kind of exception we've caught;nice. */

EXCEPTION_DISPOSITION
catchDivZero(struct _EXCEPTION_RECORD* rec,
         void* arg1 __attribute__((unused)),
         struct _CONTEXT* ctxt __attribute__((unused)),
         void* arg2 __attribute__((unused)))
{
     if ((rec->ExceptionFlags & EH_UNWINDING) != 0) {
     // When the system unwinds the SEH stack after having handled an excn,
     // return immediately.
         return ExceptionContinueSearch;
     }
     switch (rec->ExceptionCode) {
     case EXCEPTION_FLT_DIVIDE_BY_ZERO:
     case EXCEPTION_INT_DIVIDE_BY_ZERO:
     seh_excn_code = 0;
     longjmp(seh_unwind_to, rec->ExceptionCode);
     return ExceptionContinueExecution;
     case EXCEPTION_STACK_OVERFLOW:
     seh_excn_code = 1;
     longjmp(seh_unwind_to, rec->ExceptionCode);
     return ExceptionContinueExecution;
     case EXCEPTION_ACCESS_VIOLATION:
     seh_excn_code = 2;
     longjmp(seh_unwind_to, rec->ExceptionCode);
     return ExceptionContinueExecution;
     longjmp(seh_unwind_to, rec->ExceptionCode);
     return ExceptionContinueExecution;
     default: ;
     }
     return ExceptionContinueSearch;
}
#endif
#endif


// Local Variables:
// mode: C
// fill-column: 80
// indent-tabs-mode: nil
// c-basic-offset: 4
// buffer-file-coding-system: utf-8-unix
// End: