From b3f8bee89e3fa5713ff391e0172b8e1d4b92be25 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Thu, 12 Dec 2013 22:47:27 -0800 Subject: First cut at signal handling support. * Makefile (OBJS-y): Include signal.o if have_posix_sigs is "y". * configure (have_posix_sigs): New variable, set by detecting POSIX signal stuff. * dep.mk: Regenerated. * arith.c, debug.c, eval.c, filter.c, hash.c, match.c, parser.y, parser.l, rand.c, regex.c, syslog.c, txr.c, utf8.c: Include new signal.h header, now required by unwind, and the system header. * eval.c (exit_wrap): New function. (eval_init): New functions registered as intrinsics: exit_wrap, set_sig_handler, get_sig_handler, sig_check. * gc.c (release): Unused functions removed. * gc.h (release): Declaration removed. * lib.c (init): Call sig_init. * stream.c (set_putc, se_getc, se_fflush): New static functions. (stdio_put_char_callback, stdio_get_char_callback, stdio_put_byte, stdio_flush, stdio_get_byte): Use new functions to enable signals when blocked on I/O. (tail_strategy): Allow signals across sleep. (pipev_close): Allow signals across waitpid. (se_pclose): New static function. (pipe_close): Use new function to enable signals across pclose. * unwind.c (uw_unwind_to_exit_point): use extended_longjmp instead of longjmp. * unwind.h (struct uw_block, struct uw_catch): jb member changes from jmp_buf to extended_jmp_buf. (uw_block_begin, uw_simple_catch_begin, uw_catch_begin): Use extended_setjmp instead of setjmp. * signal.c: New file. * signal.h: New file. --- lib.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'lib.c') diff --git a/lib.c b/lib.c index 16e5d08e..245c864f 100644 --- a/lib.c +++ b/lib.c @@ -36,7 +36,9 @@ #include #include #include +#include #include +#include #include "config.h" #ifdef HAVE_GETENVIRONMENTSTRINGS #define NOMINMAX @@ -47,6 +49,7 @@ #include "arith.h" #include "rand.h" #include "hash.h" +#include "signal.h" #include "unwind.h" #include "stream.h" #include "utf8.h" @@ -1082,6 +1085,9 @@ static mem_t *malloc_low_bound, *malloc_high_bound; mem_t *chk_malloc(size_t size) { mem_t *ptr = (mem_t *) malloc(size); + + assert (!async_sig_enabled); + if (size && ptr == 0) ptr = (mem_t *) oom_realloc(0, size); if (ptr < malloc_low_bound) @@ -1094,6 +1100,9 @@ mem_t *chk_malloc(size_t size) mem_t *chk_calloc(size_t n, size_t size) { mem_t *ptr = (mem_t *) calloc(n, size); + + assert (!async_sig_enabled); + if (size && ptr == 0) { ptr = (mem_t *) oom_realloc(0, size); memset(ptr, 0, n * size); @@ -1108,6 +1117,9 @@ mem_t *chk_calloc(size_t n, size_t size) mem_t *chk_realloc(mem_t *old, size_t size) { mem_t *newptr = (mem_t *) realloc(old, size); + + assert (!async_sig_enabled); + if (size != 0 && newptr == 0) newptr = oom_realloc(old, size); if (newptr < malloc_low_bound) @@ -1126,6 +1138,7 @@ wchar_t *chk_strdup(const wchar_t *str) { size_t nchar = wcslen(str) + 1; wchar_t *copy = (wchar_t *) chk_malloc(nchar * sizeof *copy); + assert (!async_sig_enabled); wmemcpy(copy, str, nchar); return copy; } @@ -5188,6 +5201,9 @@ void init(const wchar_t *pn, mem_t *(*oom)(mem_t *, size_t), oom_realloc = oom; gc_init(stack_bottom); +#if HAVE_POSIX_SIGS + sig_init(); +#endif obj_init(); arith_init(); rand_init(); -- cgit v1.2.3