1 /***********************************************************************/
5 /* Xavier Leroy and Damien Doligez, INRIA Rocquencourt */
7 /* Copyright 2007 Institut National de Recherche en Informatique et */
8 /* en Automatique. All rights reserved. This file is distributed */
9 /* under the terms of the GNU Library General Public License, with */
10 /* the special exception on linking described in file ../LICENSE. */
12 /***********************************************************************/
14 /* $Id: signals_byt.c 7904 2007-02-23 09:29:45Z xleroy $ */
16 /* Signal handling, code specific to the bytecode interpreter */
23 #include "signals_machdep.h"
30 typedef void (*sighandler)(int sig);
31 extern sighandler caml_win32_signal(int sig, sighandler action);
32 #define signal(sig,act) caml_win32_signal(sig,act)
35 CAMLexport int volatile caml_something_to_do = 0;
36 CAMLexport void (* volatile caml_async_action_hook)(void) = NULL;
38 void caml_process_event(void)
40 void (*async_action)(void);
42 if (caml_force_major_slice) caml_minor_collection ();
43 /* FIXME should be [caml_check_urgent_gc] */
44 caml_process_pending_signals();
45 async_action = caml_async_action_hook;
46 if (async_action != NULL) {
47 caml_async_action_hook = NULL;
52 static void handle_signal(int signal_number)
54 #if !defined(POSIX_SIGNALS) && !defined(BSD_SIGNALS)
55 signal(signal_number, handle_signal);
57 if (signal_number < 0 || signal_number >= NSIG) return;
58 if (caml_try_leave_blocking_section_hook()) {
59 caml_execute_signal(signal_number, 1);
60 caml_enter_blocking_section_hook();
62 caml_record_signal(signal_number);
66 int caml_set_signal_action(int signo, int action)
68 void (*act)(int signo), (*oldact)(int signo);
70 struct sigaction sigact, oldsigact;
74 case 0: act = SIG_DFL; break;
75 case 1: act = SIG_IGN; break;
76 default: act = handle_signal; break;
80 sigact.sa_handler = act;
81 sigemptyset(&sigact.sa_mask);
83 if (sigaction(signo, &sigact, &oldsigact) == -1) return -1;
84 oldact = oldsigact.sa_handler;
86 oldact = signal(signo, act);
87 if (oldact == SIG_ERR) return -1;
89 if (oldact == handle_signal)
91 else if (oldact == SIG_IGN)