diff options
Diffstat (limited to 'dev-lang/ocaml/files/ocaml-4.10.2-glibc-2.34.patch')
-rw-r--r-- | dev-lang/ocaml/files/ocaml-4.10.2-glibc-2.34.patch | 239 |
1 files changed, 0 insertions, 239 deletions
diff --git a/dev-lang/ocaml/files/ocaml-4.10.2-glibc-2.34.patch b/dev-lang/ocaml/files/ocaml-4.10.2-glibc-2.34.patch deleted file mode 100644 index 4c157ddd90b8..000000000000 --- a/dev-lang/ocaml/files/ocaml-4.10.2-glibc-2.34.patch +++ /dev/null @@ -1,239 +0,0 @@ -https://github.com/ocaml/ocaml/commit/4b4c643d1d5d28738f6d900cd902851ed9dc5364 -https://bugs.gentoo.org/804498 - -From 4b4c643d1d5d28738f6d900cd902851ed9dc5364 Mon Sep 17 00:00:00 2001 -From: Xavier Leroy <xavierleroy@users.noreply.github.com> -Date: Fri, 5 Mar 2021 19:14:07 +0100 -Subject: [PATCH] Dynamically allocate the alternate signal stack - -In Glibc 2.34 and later, SIGSTKSZ may not be a compile-time constant. -It is no longer possible to statically allocate the alternate signal -stack for the main thread, as we've been doing for the last 25 years. - -This commit implements dynamic allocation of the alternate signal stack -even for the main thread. It reuses the code already in place to allocate -the alternate signal stack for other threads. - -The alternate signal stack is freed when the main OCaml code / an OCaml thread -stops. - -(partial back-port of PR#10266 and PR#10726) ---- a/otherlibs/systhreads/st_stubs.c -+++ b/otherlibs/systhreads/st_stubs.c -@@ -140,6 +140,7 @@ static st_retcode caml_threadstatus_wait (value); - #ifdef NATIVE_CODE - extern struct longjmp_buffer caml_termination_jmpbuf; - extern void (*caml_termination_hook)(void); -+extern int caml_stop_stack_overflow_detection(void); - #endif - - /* Hook for scanning the stacks of the other threads */ -@@ -576,6 +577,7 @@ static ST_THREAD_FUNCTION caml_thread_start(void * arg) - caml_thread_stop(); - #ifdef NATIVE_CODE - } -+ caml_stop_stack_overflow_detection(); - #endif - /* The thread now stops running */ - return 0; ---- a/runtime/fail_nat.c -+++ b/runtime/fail_nat.c -@@ -32,6 +32,8 @@ - #include "caml/roots.h" - #include "caml/callback.h" - -+extern void caml_terminate_signals(void); -+ - /* The globals holding predefined exceptions */ - - typedef value caml_generated_constant[1]; -@@ -62,7 +64,10 @@ CAMLno_asan - void caml_raise(value v) - { - Unlock_exn(); -- 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) { ---- a/runtime/signals_nat.c -+++ b/runtime/signals_nat.c -@@ -191,8 +191,6 @@ DECLARE_SIGNAL_HANDLER(trap_handler) - #error "CONTEXT_SP is required if HAS_STACK_OVERFLOW_DETECTION is defined" - #endif - --static char sig_alt_stack[SIGSTKSZ]; -- - /* Code compiled with ocamlopt never accesses more than - EXTRA_STACK bytes below the stack pointer. */ - #define EXTRA_STACK 256 -@@ -254,6 +252,10 @@ DECLARE_SIGNAL_HANDLER(segv_handler) - - /* Initialization of signal stuff */ - -+#ifdef HAS_STACK_OVERFLOW_DETECTION -+static int setup_stack_overflow_detection(void); -+#endif -+ - void caml_init_signals(void) - { - /* Bound-check trap handling */ -@@ -278,28 +280,91 @@ void caml_init_signals(void) - #endif - - #ifdef HAS_STACK_OVERFLOW_DETECTION -- { -- stack_t stk; -+ if (setup_stack_overflow_detection() != -1) { - struct sigaction act; -- stk.ss_sp = sig_alt_stack; -- stk.ss_size = SIGSTKSZ; -- stk.ss_flags = 0; - SET_SIGACT(act, segv_handler); - act.sa_flags |= SA_ONSTACK | SA_NODEFER; - sigemptyset(&act.sa_mask); -- if (sigaltstack(&stk, NULL) == 0) { sigaction(SIGSEGV, &act, NULL); } -+ sigaction(SIGSEGV, &act, NULL); - } - #endif - } - --void caml_setup_stack_overflow_detection(void) -+/* Termination of signal stuff */ -+ -+#if defined(TARGET_power) || defined(TARGET_s390x) \ -+ || defined(HAS_STACK_OVERFLOW_DETECTION) -+static void set_signal_default(int signum) -+{ -+ struct sigaction act; -+ sigemptyset(&act.sa_mask); -+ act.sa_handler = SIG_DFL; -+ act.sa_flags = 0; -+ sigaction(signum, &act, NULL); -+} -+#endif -+ -+int caml_stop_stack_overflow_detection(void); -+ -+void caml_terminate_signals(void) - { -+#if defined(TARGET_power) -+ set_signal_default(SIGTRAP); -+#endif -+ -+#if defined(TARGET_s390x) -+ set_signal_default(SIGFPE); -+#endif -+ - #ifdef HAS_STACK_OVERFLOW_DETECTION -+ set_signal_default(SIGSEGV); -+ caml_stop_stack_overflow_detection(); -+#endif -+} -+ -+/* Allocate and select an alternate stack for handling signals, -+ especially SIGSEGV signals. -+ Each thread needs its own alternate stack. -+ The alternate stack used to be statically-allocated for the main thread, -+ but this is incompatible with Glibc 2.34 and newer, where SIGSTKSZ -+ may not be a compile-time constant (issue #10250). */ -+ -+#ifdef HAS_STACK_OVERFLOW_DETECTION -+static int setup_stack_overflow_detection(void) -+{ - stack_t stk; - stk.ss_sp = malloc(SIGSTKSZ); -+ if (stk.ss_sp == NULL) return -1; - stk.ss_size = SIGSTKSZ; - stk.ss_flags = 0; -- if (stk.ss_sp) -- sigaltstack(&stk, NULL); -+ if (sigaltstack(&stk, NULL) == -1) { -+ free(stk.ss_sp); -+ return -1; -+ } -+ /* Success (or stack overflow detection not available) */ -+ return 0; -+} -+#endif -+ -+CAMLexport void caml_setup_stack_overflow_detection(void) -+{ -+#ifdef HAS_STACK_OVERFLOW_DETECTION -+ setup_stack_overflow_detection(); -+#endif -+} -+ -+CAMLexport int caml_stop_stack_overflow_detection(void) -+{ -+#ifdef HAS_STACK_OVERFLOW_DETECTION -+ stack_t oldstk, stk; -+ stk.ss_flags = SS_DISABLE; -+ if (sigaltstack(&stk, &oldstk) == -1) return -1; -+ /* If caml_setup_stack_overflow_detection failed, we are not using -+ an alternate signal stack. SS_DISABLE will be set in oldstk, -+ and there is nothing to free in this case. */ -+ if (! (oldstk.ss_flags & SS_DISABLE)) free(oldstk.ss_sp); -+ return 0; -+#else -+ return 0; - #endif - } ---- a/runtime/startup_nat.c -+++ b/runtime/startup_nat.c -@@ -93,6 +93,7 @@ void (*caml_termination_hook)(void *) = NULL; - extern value caml_start_program (caml_domain_state*); - extern void caml_init_ieee_floats (void); - extern void caml_init_signals (void); -+extern void caml_terminate_signals(void); - #ifdef _WIN32 - extern void caml_win32_overflow_detection (void); - #endif -@@ -107,6 +108,7 @@ extern void caml_install_invalid_parameter_handler(); - value caml_startup_common(char_os **argv, int pooling) - { - char_os * exe_name, * proc_self_exe; -+ value res; - char tos; - - /* Initialize the domain */ -@@ -156,10 +158,13 @@ value caml_startup_common(char_os **argv, int pooling) - exe_name = caml_search_exe_in_path(exe_name); - caml_sys_init(exe_name, argv); - if (sigsetjmp(caml_termination_jmpbuf.buf, 0)) { -+ caml_terminate_signals(); - if (caml_termination_hook != NULL) caml_termination_hook(NULL); - return Val_unit; - } -- return caml_start_program(Caml_state); -+ res = caml_start_program(Caml_state); -+ caml_terminate_signals(); -+ return res; - } - - value caml_startup_exn(char_os **argv) ---- a/runtime/sys.c -+++ b/runtime/sys.c -@@ -112,6 +112,8 @@ static void caml_sys_check_path(value name) - } - } - -+extern void caml_terminate_signals(void); -+ - CAMLprim value caml_sys_exit(value retcode_v) - { - int retcode = Int_val(retcode_v); -@@ -156,6 +158,9 @@ CAMLprim value caml_sys_exit(value retcode_v) - caml_shutdown(); - #ifdef _WIN32 - caml_restore_win32_terminal(); -+#endif -+#ifdef NATIVE_CODE -+ caml_terminate_signals(); - #endif - exit(retcode); - } - |