2 * win32-exception.c: Win32 SEH filter.
4 * (C) 2002 Ximian, Inc.
7 #include "win32-exception.h"
14 LONG CALLBACK seh_handler(EXCEPTION_POINTERS* ep);
16 static MonoW32ExceptionHandler fpe_handler;
17 static MonoW32ExceptionHandler ill_handler;
18 static MonoW32ExceptionHandler segv_handler;
20 static LPTOP_LEVEL_EXCEPTION_FILTER old_handler;
22 #define W32_SEH_COPY_CONTEXT \
23 sctx->eax = ctx->Eax;\
24 sctx->ebx = ctx->Ebx;\
25 sctx->ecx = ctx->Ecx;\
26 sctx->edx = ctx->Edx;\
27 sctx->ebp = ctx->Ebp;\
28 sctx->esp = ctx->Esp;\
29 sctx->esi = ctx->Esi;\
30 sctx->edi = ctx->Edi;\
33 #define W32_SEH_HANDLE_EX(_ex) \
34 if (_ex##_handler) _ex##_handler((int)sctx)
37 * Unhandled Exception Filter
38 * Top-level per-process exception handler.
40 LONG CALLBACK seh_handler(EXCEPTION_POINTERS* ep)
44 struct sigcontext* sctx;
47 res = EXCEPTION_CONTINUE_SEARCH;
49 er = ep->ExceptionRecord;
50 ctx = ep->ContextRecord;
51 sctx = g_malloc(sizeof(struct sigcontext));
54 switch (er->ExceptionCode) {
55 case EXCEPTION_ACCESS_VIOLATION:
56 W32_SEH_HANDLE_EX(segv);
58 case EXCEPTION_ILLEGAL_INSTRUCTION:
59 W32_SEH_HANDLE_EX(ill);
61 case EXCEPTION_INT_DIVIDE_BY_ZERO:
62 case EXCEPTION_INT_OVERFLOW:
63 case EXCEPTION_FLT_DIVIDE_BY_ZERO:
64 case EXCEPTION_FLT_OVERFLOW:
65 case EXCEPTION_FLT_UNDERFLOW:
66 case EXCEPTION_FLT_INEXACT_RESULT:
67 W32_SEH_HANDLE_EX(fpe);
78 old_handler = SetUnhandledExceptionFilter(seh_handler);
81 void win32_seh_cleanup()
83 if (old_handler) SetUnhandledExceptionFilter(old_handler);
86 void win32_seh_set_handler(int type, MonoW32ExceptionHandler handler)
90 fpe_handler = handler;
93 ill_handler = handler;
96 segv_handler = handler;
103 #endif /* PLATFORM_WIN32 */