[e5072a]: src / c / unixint.d Maximize Restore History

Download this file

unixint.d    185 lines (160 with data), 3.6 kB

  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
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
/*
unixint.c -- Unix interrupt interface.
*/
/*
Copyright (c) 1984, Taiichi Yuasa and Masami Hagiya.
Copyright (c) 1990, Giuseppe Attardi.
Copyright (c) 2001, Juan Jose Garcia Ripoll.
ECL is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
See file '../Copyright' for full details.
*/
#include "ecl.h"
#include <signal.h>
#include <unistd.h>
/******************************* EXPORTS ******************************/
int interrupt_enable; /* console interupt enable */
int interrupt_flag; /* console interupt flag */
/******************************* ------- ******************************/
typedef void (*signalfn)(int);
#ifndef THREADS
#ifdef SIGALRM
static void
sigalrm(void)
{
if (interrupt_flag) {
interrupt_flag = FALSE;
terminal_interrupt(TRUE);
}
}
#endif
void
sigint(void)
{
if (!interrupt_enable || interrupt_flag) {
if (!interrupt_enable) {
fprintf(stdout, "\n;;;Interrupt delayed.\n"); fflush(stdout);
interrupt_flag = TRUE;
}
signal(SIGINT, (signalfn)sigint);
return;
}
if (symbol_value(@'si::*interrupt-enable*') == Cnil) {
SYM_VAL(@'si::*interrupt-enable*') = Ct;
signal(SIGINT, (signalfn)sigint);
return;
}
#ifdef SIGALRM
#ifdef __GO32__
if (interrupt_flag)
sigalrm();
#endif
interrupt_flag = TRUE;
signal(SIGALRM, (signalfn)sigalrm);
alarm(1);
#endif
signal(SIGINT, (signalfn)sigint);
}
#else /* THREADS */
extern int critical_level;
bool scheduler_interrupted = FALSE;
int scheduler_interruption = 0;
void
sigint()
{
#ifdef SYSV
signal(SIGINT, sigint);
#endif
if (critical_level > 0) {
scheduler_interrupted = TRUE;
scheduler_interruption = ERROR_INT;
return;
}
if (symbol_value(@'si::*interrupt-enable*') == Cnil) {
SYM_VAL(@'si::*interrupt-enable*') = Ct;
return;
}
terminal_interrupt(TRUE);
}
#endif /*THREADS */
static void
sigfpe(void)
{
signal(SIGFPE, (signalfn)sigfpe);
FEerror("Floating-point exception.", 0);
}
void
signal_catcher(int sig, int code, int scp)
{
char str[64];
if (!interrupt_enable) {
sprintf(str, "signal %d caught (during GC)", sig);
error(str);
}
else if (sig == SIGSEGV)
FEerror("Segmentation violation.~%\
Wrong type argument to a compiled function.", 0);
else {
printf("System error. Trying to recover ...\n");
fflush(stdout);
FEerror("Signal ~D caught.~%\
The internal memory may be broken.~%\
You should check the signal and exit from Lisp.", 1,
MAKE_FIXNUM(sig));
}
}
cl_object
si_catch_bad_signals()
{
signal(SIGILL, (signalfn)signal_catcher);
#ifndef GBC_BOEHM
signal(SIGBUS, (signalfn)signal_catcher);
#endif
signal(SIGSEGV, (signalfn)signal_catcher);
#ifdef SIGIOT
signal(SIGIOT, (signalfn)signal_catcher);
#endif
#ifdef SIGEMT
signal(SIGEMT, (signalfn)signal_catcher);
#endif
#ifdef SIGSYS
signal(SIGSYS, (signalfn)signal_catcher);
#endif
@(return Ct)
}
cl_object
si_uncatch_bad_signals()
{
signal(SIGILL, SIG_DFL);
#ifndef GBC_BOEHM
signal(SIGBUS, SIG_DFL);
#endif
signal(SIGSEGV, SIG_DFL);
#ifdef SIGIOT
signal(SIGIOT, SIG_DFL);
#endif
#ifdef SIGEMT
signal(SIGEMT, SIG_DFL);
#endif
#ifdef SIGSYS
signal(SIGSYS, SIG_DFL);
#endif
@(return Ct)
}
void
enable_interrupt(void)
{
interrupt_enable = TRUE;
signal(SIGFPE, (signalfn)sigfpe);
signal(SIGINT, (signalfn)sigint);
#ifdef __EMX__
signal(SIGBREAK, (signalfn)sigint);
#endif
}
void
init_interrupt(void)
{
SYM_VAL(@'SI::*INTERRUPT-ENABLE*') = Ct;
}