diff --git a/asmrun/fail.c b/asmrun/fail.c index 6b3e2fa2b..2b4b0eba4 100644 --- a/asmrun/fail.c +++ b/asmrun/fail.c @@ -33,13 +33,9 @@ typedef char caml_generated_constant[256]; extern caml_generated_constant Out_of_memory, Sys_error, Failure, Invalid_argument, End_of_file, Division_by_zero, Not_found, Match_failure; -/* Exception raising */ +/* Resetting the signal mask when raising an exception from C */ -extern void raise_caml_exception (value bucket) Noreturn; - -char * caml_exception_pointer = NULL; - -void mlraise(value v) +static void default_reset_sigmask(void) { #ifdef POSIX_SIGNALS sigset_t mask; @@ -50,6 +46,19 @@ void mlraise(value v) sigsetmask(0); #endif #endif +} + +void (*caml_reset_sigmask)(void) = default_reset_sigmask; + +/* Exception raising */ + +extern void raise_caml_exception (value bucket) Noreturn; + +char * caml_exception_pointer = NULL; + +void mlraise(value v) +{ + (*caml_reset_sigmask)(); Unlock_exn(); if (caml_exception_pointer == NULL) fatal_uncaught_exception(v); diff --git a/byterun/fail.h b/byterun/fail.h index e72bb03bc..302b83a6b 100644 --- a/byterun/fail.h +++ b/byterun/fail.h @@ -59,4 +59,6 @@ void raise_not_found (void) Noreturn; void fatal_uncaught_exception (value) Noreturn; void init_exceptions (void); +extern void (*caml_reset_sigmask)(void); + #endif /* _fail_ */ diff --git a/otherlibs/systhreads/posix.c b/otherlibs/systhreads/posix.c index b53e7540c..b1df4a67a 100644 --- a/otherlibs/systhreads/posix.c +++ b/otherlibs/systhreads/posix.c @@ -225,6 +225,17 @@ static void caml_io_mutex_unlock_exn(void) if (chan != NULL) caml_io_mutex_unlock(chan); } +/* Hook for resetting signals in mlraise() (in native-code only) */ + +#ifdef NATIVE_CODE +static void caml_thread_reset_sigmask(void) +{ + sigset_t mask; + sigemptyset(&mask); + pthread_sigmask(SIG_SETMASK, &mask, NULL); +} +#endif + /* The "tick" thread fakes a SIGVTALRM signal at regular intervals. */ static void * caml_thread_tick(void * arg) @@ -301,6 +312,9 @@ value caml_thread_initialize(value unit) /* ML */ channel_mutex_lock = caml_io_mutex_lock; channel_mutex_unlock = caml_io_mutex_unlock; channel_mutex_unlock_exn = caml_io_mutex_unlock_exn; +#ifdef NATIVE_CODE + caml_reset_sigmask = caml_thread_reset_sigmask; +#endif /* Fork the tick thread */ pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);