Adding posix signal handling.
This commit is contained in:
@ -12,10 +12,28 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifdef HAS_SIGNALS
|
||||
#include <setjmp.h>
|
||||
#include <signal.h>
|
||||
#endif
|
||||
|
||||
#define JMPW goto **(void **) w
|
||||
#define NEXT w = *ip++; JMPW
|
||||
#define ADDROF(x) (&& OP_ ## x)
|
||||
|
||||
#ifdef HAS_SIGNALS
|
||||
static __thread jmp_buf g_forth_fault;
|
||||
static __thread int g_forth_signal;
|
||||
|
||||
static void forth_signal_handler(int sig) {
|
||||
g_forth_signal = sig;
|
||||
sigset_t ss;
|
||||
sigemptyset(&ss);
|
||||
sigprocmask(SIG_SETMASK, &ss, 0);
|
||||
longjmp(g_forth_fault, 1);
|
||||
}
|
||||
#endif
|
||||
|
||||
static cell_t *forth_run(cell_t *init_rp) {
|
||||
static const BUILTIN_WORD builtins[] = {
|
||||
#define Z(flags, name, op, code) \
|
||||
@ -32,11 +50,30 @@ static cell_t *forth_run(cell_t *init_rp) {
|
||||
if (!init_rp) {
|
||||
g_sys->DOCREATE_OP = ADDROF(DOCREATE);
|
||||
g_sys->builtins = builtins;
|
||||
#ifdef HAS_SIGNALS
|
||||
struct sigaction sa;
|
||||
memset(&sa, 0, sizeof(sa));
|
||||
sa.sa_handler = forth_signal_handler;
|
||||
sigaction(SIGSEGV, &sa, 0);
|
||||
sigaction(SIGBUS, &sa, 0);
|
||||
sigaction(SIGINT, &sa, 0);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
register cell_t *ip, *rp, *sp, tos, w;
|
||||
register float *fp, ft;
|
||||
rp = init_rp; UNPARK; NEXT;
|
||||
rp = init_rp; UNPARK;
|
||||
#ifdef HAS_SIGNALS
|
||||
if (setjmp(g_forth_fault)) {
|
||||
rp = *g_sys->throw_handler;
|
||||
*g_sys->throw_handler = (cell_t *) *rp--;
|
||||
sp = (cell_t *) *rp--;
|
||||
fp = (float *) *rp--;
|
||||
--sp;
|
||||
tos = -g_forth_signal;
|
||||
}
|
||||
#endif
|
||||
NEXT;
|
||||
#define Z(flags, name, op, code) OP_ ## op: { code; } NEXT;
|
||||
PLATFORM_OPCODE_LIST
|
||||
TIER2_OPCODE_LIST
|
||||
|
||||
Reference in New Issue
Block a user