Skip to content

Commit

Permalink
Free the alternate signal stack when thread / process stops, continued
Browse files Browse the repository at this point in the history
Make sure caml_terminate_signals is called if caml_raise goes straight
to caml_fatal_uncaught_exception.

Refactoring: add dummy definitions of caml_init_signals and
caml_terminate_signals to the bytecode runtime system, so that no
caml_stop_stack_overflow_detection.
  • Loading branch information
xavierleroy committed Nov 29, 2021
1 parent 908bd21 commit bb56709
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
2 changes: 0 additions & 2 deletions runtime/caml/signals.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,8 @@ value caml_process_pending_actions_with_root_exn (value extra_root);
int caml_set_signal_action(int signo, int action);
CAMLextern int caml_setup_stack_overflow_detection(void);
CAMLextern int caml_stop_stack_overflow_detection(void);
#ifdef NATIVE_CODE
CAMLextern void caml_init_signals(void);
CAMLextern void caml_terminate_signals(void);
#endif
CAMLextern void (*caml_enter_blocking_section_hook)(void);
CAMLextern void (*caml_leave_blocking_section_hook)(void);
#ifdef POSIX_SIGNALS
Expand Down
6 changes: 5 additions & 1 deletion runtime/fail_nat.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "caml/stack.h"
#include "caml/roots.h"
#include "caml/callback.h"
#include "caml/signals.h"

/* The globals holding predefined exceptions */

Expand Down Expand Up @@ -70,7 +71,10 @@ void caml_raise(value v)
if (Is_exception_result(v))
v = Extract_exception(v);

if (Caml_state->exception_pointer == NULL) caml_fatal_uncaught_exception(v);
if (Caml_state->exception_pointer == NULL) {
caml_terminate_signals();
caml_fatal_uncaught_exception(v);
}

while (Caml_state->local_roots != NULL &&
(char *) Caml_state->local_roots < Caml_state->exception_pointer) {
Expand Down
2 changes: 2 additions & 0 deletions runtime/signals_byt.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,5 @@ int caml_set_signal_action(int signo, int action)

CAMLexport int caml_setup_stack_overflow_detection(void) { return 0; }
CAMLexport int caml_stop_stack_overflow_detection(void) { return 0; }
CAMLexport void caml_init_signals(void) { }
CAMLexport void caml_terminate_signals(void) { }
2 changes: 0 additions & 2 deletions runtime/sys.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,7 @@ CAMLexport void caml_do_exit(int retcode)
#ifdef _WIN32
caml_restore_win32_terminal();
#endif
#ifdef NATIVE_CODE
caml_terminate_signals();
#endif
#ifdef NAKED_POINTERS_CHECKER
if (retcode == 0 && caml_naked_pointers_detected) {
fprintf (stderr, "\nOut-of-heap pointers were detected by the runtime.\n"
Expand Down

0 comments on commit bb56709

Please sign in to comment.