forked from ocaml-flambda/flambda-backend
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsignals_byt.c
87 lines (77 loc) · 2.82 KB
/
signals_byt.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/**************************************************************************/
/* */
/* OCaml */
/* */
/* Xavier Leroy and Damien Doligez, INRIA Rocquencourt */
/* */
/* Copyright 2007 Institut National de Recherche en Informatique et */
/* en Automatique. */
/* */
/* All rights reserved. This file is distributed under the terms of */
/* the GNU Lesser General Public License version 2.1, with the */
/* special exception on linking described in the file LICENSE. */
/* */
/**************************************************************************/
#define CAML_INTERNALS
/* Signal handling, code specific to the bytecode interpreter */
#include <signal.h>
#include <errno.h>
#include "caml/config.h"
#include "caml/memory.h"
#include "caml/fail.h"
#include "caml/finalise.h"
#include "caml/osdeps.h"
#include "caml/signals.h"
#include "caml/signals_machdep.h"
#ifndef NSIG
#define NSIG 64
#endif
#ifdef _WIN32
typedef void (*sighandler)(int sig);
extern sighandler caml_win32_signal(int sig, sighandler action);
#define signal(sig,act) caml_win32_signal(sig,act)
#endif
static void handle_signal(int signal_number)
{
int saved_errno;
/* Save the value of errno (PR#5982). */
saved_errno = errno;
#if !defined(POSIX_SIGNALS) && !defined(BSD_SIGNALS)
signal(signal_number, handle_signal);
#endif
if (signal_number < 0 || signal_number >= NSIG) return;
caml_record_signal(signal_number);
errno = saved_errno;
}
int caml_set_signal_action(int signo, int action)
{
void (*act)(int signo), (*oldact)(int signo);
#ifdef POSIX_SIGNALS
struct sigaction sigact, oldsigact;
#endif
switch (action) {
case 0: act = SIG_DFL; break;
case 1: act = SIG_IGN; break;
default: act = handle_signal; break;
}
#ifdef POSIX_SIGNALS
sigact.sa_handler = act;
sigemptyset(&sigact.sa_mask);
sigact.sa_flags = 0;
if (sigaction(signo, &sigact, &oldsigact) == -1) return -1;
oldact = oldsigact.sa_handler;
#else
oldact = signal(signo, act);
if (oldact == SIG_ERR) return -1;
#endif
if (oldact == handle_signal)
return 2;
else if (oldact == SIG_IGN)
return 1;
else
return 0;
}
CAMLexport void * caml_setup_stack_overflow_detection(void) { return NULL; }
CAMLexport int caml_stop_stack_overflow_detection(void * p) { return 0; }
CAMLexport void caml_init_signals(void) { }
CAMLexport void caml_terminate_signals(void) { }