2 #include "internal/wine/msvcrt.h"
3 #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(NTSTATUS 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
)
65 int float_signal
= _FPE_INVALID
;
67 sighandlers
[SIGFPE
] = SIG_DFL
;
68 for (i
= 0; i
< sizeof(float_exception_map
) /
69 sizeof(float_exception_map
[0]); i
++)
71 if (float_exception_map
[i
].status
==
72 except
->ExceptionRecord
->ExceptionCode
)
74 float_signal
= float_exception_map
[i
].signal
;
78 ((float_handler
)handler
)(SIGFPE
, float_signal
);
80 ret
= EXCEPTION_CONTINUE_EXECUTION
;
83 case EXCEPTION_ILLEGAL_INSTRUCTION
:
84 case EXCEPTION_PRIV_INSTRUCTION
:
85 if ((handler
= sighandlers
[SIGILL
]) != SIG_DFL
)
87 if (handler
!= SIG_IGN
)
89 sighandlers
[SIGILL
] = SIG_DFL
;
92 ret
= EXCEPTION_CONTINUE_EXECUTION
;