2 #include "include/internal/wine/msvcrt.h"
3 #include "include/internal/wine/cppexcept.h"
5 typedef void (*sighandler_t
)(int);
6 static sighandler_t sighandlers
[NSIG
] = { SIG_DFL
};
8 /* The exception codes are actually NTSTATUS values */
13 } float_exception_map
[] = {
14 { EXCEPTION_FLT_DENORMAL_OPERAND
, _FPE_DENORMAL
},
15 { EXCEPTION_FLT_DIVIDE_BY_ZERO
, _FPE_ZERODIVIDE
},
16 { EXCEPTION_FLT_INEXACT_RESULT
, _FPE_INEXACT
},
17 { EXCEPTION_FLT_INVALID_OPERATION
, _FPE_INVALID
},
18 { EXCEPTION_FLT_OVERFLOW
, _FPE_OVERFLOW
},
19 { EXCEPTION_FLT_STACK_CHECK
, _FPE_STACKOVERFLOW
},
20 { EXCEPTION_FLT_UNDERFLOW
, _FPE_UNDERFLOW
},
27 _XcptFilter(DWORD ExceptionCode
,
28 struct _EXCEPTION_POINTERS
* except
)
30 LONG ret
= EXCEPTION_CONTINUE_SEARCH
;
33 if (!except
|| !except
->ExceptionRecord
)
34 return EXCEPTION_CONTINUE_SEARCH
;
36 switch (except
->ExceptionRecord
->ExceptionCode
)
38 case EXCEPTION_ACCESS_VIOLATION
:
39 if ((handler
= sighandlers
[SIGSEGV
]) != SIG_DFL
)
41 if (handler
!= SIG_IGN
)
43 sighandlers
[SIGSEGV
] = SIG_DFL
;
46 ret
= EXCEPTION_CONTINUE_EXECUTION
;
50 * the FPE signal handler takes as a second argument the type of
51 * floating point exception.
53 case EXCEPTION_FLT_DENORMAL_OPERAND
:
54 case EXCEPTION_FLT_DIVIDE_BY_ZERO
:
55 case EXCEPTION_FLT_INEXACT_RESULT
:
56 case EXCEPTION_FLT_INVALID_OPERATION
:
57 case EXCEPTION_FLT_OVERFLOW
:
58 case EXCEPTION_FLT_STACK_CHECK
:
59 case EXCEPTION_FLT_UNDERFLOW
:
60 if ((handler
= sighandlers
[SIGFPE
]) != SIG_DFL
)
62 if (handler
!= SIG_IGN
)
64 int i
, float_signal
= _FPE_INVALID
;
66 sighandlers
[SIGFPE
] = SIG_DFL
;
67 for (i
= 0; i
< sizeof(float_exception_map
) /
68 sizeof(float_exception_map
[0]); i
++)
70 if (float_exception_map
[i
].status
==
71 except
->ExceptionRecord
->ExceptionCode
)
73 float_signal
= float_exception_map
[i
].signal
;
77 ((float_handler
)handler
)(SIGFPE
, float_signal
);
79 ret
= EXCEPTION_CONTINUE_EXECUTION
;
82 case EXCEPTION_ILLEGAL_INSTRUCTION
:
83 if ((handler
= sighandlers
[SIGILL
]) != SIG_DFL
)
85 if (handler
!= SIG_IGN
)
87 sighandlers
[SIGILL
] = SIG_DFL
;
90 ret
= EXCEPTION_CONTINUE_EXECUTION
;
97 int CDECL
__CppXcptFilter(NTSTATUS ex
, PEXCEPTION_POINTERS ptr
)
99 /* only filter c++ exceptions */
100 if (ex
!= CXX_EXCEPTION
) return EXCEPTION_CONTINUE_SEARCH
;
101 return _XcptFilter( ex
, ptr
);