-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
flambda-backend: Fix segfault when signal handlers invoked in non-OCa…
…ml threads on runtime5 (#2154) * Cherry-pick 59029b9 (part of ocaml/ocaml PR11307) * Add a test, which would segfault before this PR
- Loading branch information
Showing
6 changed files
with
107 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
testsuite/tests/lib-threads/signal_handler_run_in_c_thread.ml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
(* TEST | ||
modules = "signal_handler_run_in_c_thread_stubs.c" | ||
* native | ||
** hassysthreads | ||
*) | ||
|
||
(* This doesn't actually need systhreads, but the requirement should | ||
ensure the C pthreads-using code will build. *) | ||
|
||
external c_stub : unit -> unit = "test_signal_handler_run_in_c_thread" | ||
|
||
let () = | ||
Sys.set_signal Sys.sigusr1 (Signal_handle (fun _ -> exit 0)); | ||
c_stub (); | ||
while true do | ||
(* Ensure pending actions are run, by forcing allocation *) | ||
ignore (Sys.opaque_identity (Random.int 42, Random.int 42)) | ||
done |
22 changes: 22 additions & 0 deletions
22
testsuite/tests/lib-threads/signal_handler_run_in_c_thread_stubs.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#include <pthread.h> | ||
#include <signal.h> | ||
#include <caml/mlvalues.h> | ||
|
||
static pthread_cond_t cond = PTHREAD_COND_INITIALIZER; | ||
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; | ||
|
||
static void* in_thread(void* unused) | ||
{ | ||
(void) pthread_cond_signal(&cond); | ||
/* Signal to be received in this thread by the OCaml signal handler */ | ||
while (1); | ||
} | ||
|
||
value test_signal_handler_run_in_c_thread(value unit) | ||
{ | ||
pthread_t thread; | ||
pthread_create(&thread, NULL, &in_thread, NULL); | ||
pthread_cond_wait(&cond, &mutex); | ||
pthread_kill(thread, SIGUSR1); | ||
return Val_unit; | ||
} |