...
 
......@@ -92,6 +92,8 @@ deserialize :: !DeserializationSettings !SerializedGraph !String !*World -> *(!M
| DV_StackOverflow
//* The interpreter had not enough stack to evaluate the expression.
//* NB: on Windows, not all stack overflows can be caught.
| DV_FloatingPointException
//* A floating point exception occurred, e.g. due to division by 0.
| DV_Halt
//* The ABC instruction `halt` was encountered.
| DV_IllegalInstruction
......
......@@ -1196,6 +1196,7 @@ BC_WORD copy_interpreter_to_host_n(void *__dummy_0, void *__dummy_1,
if (interpret_ie(ie, &bootstrap, with_error_reporting) != 0) {
EPRINTF("Failed to interpret\n");
__interpret__copy__node__asm_redirect_node=interpret_error-1;
ie->asp=old_asp;
return 0;
}
......
......@@ -274,11 +274,21 @@ static void handle_segv(int sig, siginfo_t *info, void *context) {
}
return;
}
interpret_error=&e__ABC_PInterpreter__dDV__StackOverflow;
# endif
EPRINTF("Segmentation fault in interpreter\n");
if (sig==SIGFPE) {
# ifdef LINK_CLEAN_RUNTIME
interpret_error=&e__ABC_PInterpreter__dDV__FloatingPointException;
# endif
EPRINTF("Floating point exception during interpretation\n");
} else {
# ifdef LINK_CLEAN_RUNTIME
siglongjmp(segfault_restore_points->restore_point, SIGSEGV);
interpret_error=&e__ABC_PInterpreter__dDV__StackOverflow;
# endif
EPRINTF("Segmentation fault during interpretation\n");
}
# ifdef LINK_CLEAN_RUNTIME
siglongjmp(segfault_restore_points->restore_point, sig);
# else
exit(1);
# endif
......@@ -294,7 +304,7 @@ static LONG WINAPI handle_segv(struct _EXCEPTION_POINTERS *exception) {
}
#endif
void install_interpreter_segv_handler(void) {
static void install_signal_handlers(void) {
#ifdef POSIX
stack_t signal_stack;
signal_stack.ss_sp=safe_malloc(SIGSTKSZ);
......@@ -315,6 +325,8 @@ void install_interpreter_segv_handler(void) {
# endif
) == -1)
perror("sigaction");
if (sigaction(SIGFPE, &segv_handler, NULL) == -1)
perror("sigaction");
#elif defined(WINDOWS)
SetUnhandledExceptionFilter(&handle_segv);
#else
......@@ -331,7 +343,7 @@ int ensure_interpreter_init(void) {
if (interpreter_initialized)
return 1;
install_interpreter_segv_handler();
install_signal_handlers();
prepare_static_nodes();
#ifdef LINK_CLEAN_RUNTIME
......
......@@ -48,6 +48,7 @@ struct interpretation_environment {
extern void *e__ABC_PInterpreter__dDV__ParseError;
extern void *e__ABC_PInterpreter__dDV__HeapFull;
extern void *e__ABC_PInterpreter__dDV__StackOverflow;
extern void *e__ABC_PInterpreter__dDV__FloatingPointException;
extern void *e__ABC_PInterpreter__dDV__Halt;
extern void *e__ABC_PInterpreter__dDV__IllegalInstruction;
extern void *e__ABC_PInterpreter__dDV__FileIOAttempted;
......