summaryrefslogtreecommitdiffstats
path: root/signal.c
Commit message (Collapse)AuthorAgeFilesLines
* Update copyright notices from 2014 to 2015.Kaz Kylheku2015-02-011-1/+1
| | | | | | | | | | | * arith.c, arith.h, combi.c, combi.h, debug.c, debug.h, eval.c, eval.h, filter.c, filter.h, gc.c, gc.h, hash.c, hash.h, lib.c, lib.h, match.c, match.h, parser.h, rand.c, rand.h, regex.c, regex.h, signal.c, signal.h, stream.c, stream.h, sysif.c, sysif.h, syslog.c, syslog.h, txr.c, txr.h, unwind.c, unwind.h, utf8.c, utf8.h: Update. * LICENSE, METALICENSE: Likewise.
* * Makefile: Removing trailing spaces.Kaz Kylheku2014-10-241-1/+1
| | | | | | | | | | (GREP_CHECK): New macro. (enforce): Rewritten using GREP_CHECK, with new checks. * arith.c, combi.c, debug.c, eval.c, filter.c, gc.c, hash.c, lib.c, * lib.h, match.c, parser.l, parser.y, rand.c, regex.c, signal.c, * signal.h, stream.c, syslog.c, txr.c, unwind.c, utf8.c: Remove trailing spaces.
* Converting cast expressions to macros that are retargettedKaz Kylheku2014-10-171-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | to C++ style casts when compiling as C++. * lib.h (strip_qual, convert, coerce): New casting macros. (TAG_MASK, tag, type, wli_noex, auto_str, static_str, litptr, num_fast, chr, lit_noex, nil, nao): Use cast macros. * arith.c (mul, isqrt_fixnum, bit): Use cast macros. * configure (INT_PTR_MAX): Define using cast macro. * debug.c (debug_init): Use cast macro. * eval.c (do_eval, expand_macro, reg_op, reg_mac, eval_init): Use cast macros. * filter.c (filter_init): Use cast macro. * gc.c (more, mark_obj, in_heap, mark, sweep_one, unmark): Use cast macros. * hash.c (hash_double, equal_hash, eql_hash, hash_equal_op, hash_hash_op, hash_print_op, hash_mark, make_hash, make_similar_hash, copy_hash, gethash_c, gethash, gethash_f, gethash_n, remhash, hash_count, get_hash_userdata, set_hash_userdata, hash_iter_destroy, hash_iter_mark, hash_begin, hash_uni, hash_diff, hash_isec): Use cast macros. * lib.c (code2type, chk_malloc, chk_malloc_gc_more, chk_calloc, chk_realloc, chk_strdup, num, c_num, string, mkstring, mkustring, upcase_str, downcase_str, string_extend, sub_str, cat_str, trim_str, c_chr, vector, vec_set_length, copy_vec, sub_vec, cat_vec, cobj_print_op, obj_init): Likewise. * match.c (do_match_line, hv_trampoline, match_files, dir_tables_init): Likewise. * parser.l (grammar): Likewise. * parser.y (parse): Likewise. * rand.c (make_state, make_random_state, random_fixnum, random): Likewise. * regex.c (CHAR_SET_L2_LO, CHAR_SET_L2_HI, CHAR_SET_L1_LO, CHAR_SET_L1_HI, CHAR_SET_L0_LO, CHAR_SET_L0_HI, L0_full, L0_fill_range, L1_full, L1_fill_range, L1_contains, L1_free, L2_full, L2_fill_range, L2_contains, L2_free, L3_fill_range, L3_contains, L3_free, char_set_create, char_set_cobj_destroy, nfa_state_accept, nfa_state_empty, nfa_state_single, nfa_state_wild, nfa_state_set,
* Purge stray occurrences of "void *" from code base.Kaz Kylheku2014-10-171-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * lib.c (cobj_print_op): In the format call, cast the C pointer to val, since the ~p conversion now takes a val rather than void *. (cptr_equal_op, obj_print, obj_pprint): Remove cast to void *, since obj now already has the type that ~p expects. * lib.h (struct any): Use mem_t * instead of void *. * parser.h (yyscan_t): Repeat the definition from inside the Flex-generated lex.yy.c. (yylex_init, yylex_destroy, yyget_extra, yyset_extra): Re-declare using yyscan_t typedef in place of void *. * parser.l (yyget_column, yyerrprepf): Re-declare using yyscan_t. (grammar): Use yyg in place of yyscanner in calls to yyerrprepf. * parser.y (yylex, %lex-param): Use yyscan_t instead of void *. (parse): Use yyscan_t for local variable. * signal.c (stack): Change type from void * to mem_t *. * stream.c (vformat): Conversion specifier p extracts val instead of void *. (run): Use casts that only remove const, not all the way to void *. * txr.1: Documented p conversion specifier of format. * Makefile (OBJS-y): Initialize with := to make sure it is a simple variable, and not a macro. (SRCS): New variable, listing source files. (enforce): New rule for enforcing coding conventions. Currently checks for void * occurrences.
* * signal.c (interrupt_count): New global variable.Kaz Kylheku2014-08-021-1/+5
| | | | | | | (sig_handler): Increment and decrement interrupt count. If the interrupt count is already positive, treat that as if async signals were not enabled: do not invoke handlers.
* * configure (have_sys_time): New variable.Kaz Kylheku2014-08-011-0/+51
| | | | | | | | | | | | | | Added check for setitimer/getitimer which also checks for <sys/time.h>. * signal.c (sig_init): Register itimer-real, itimer-virtual, itimer-prof variables and getitimer and setitimer functions. (tv_to_usec): New static function. (getitimer_wrap, setitimer_wrap): New functions. * signal.h (getitimer_wrap, setitimer_wrap): Declared. * txr.1: Documented itimers.
* * signal.c (set_sig_handler): Don't use SA_ONSTACKKaz Kylheku2014-08-011-2/+3
| | | | | | | | except for signals for which we use alt stack. * signal.h (sig_save_enable): Do sig_check before enabling async signals. This caused the !async_sig_enabled assertion to trip inside make_obj.
* * signal.c (sig_hup, sig_int, sig_quit, sig_ill, sig_trap, sig_abrt,Kaz Kylheku2014-08-011-7/+0
| | | | | | | | | | sig_bus, sig_fpe, sig_kill, sig_usr1, sig_segv, sig_usr2, sig_pipe, sig_alrm, sig_term, sig_chld, sig_cont, sig_stop, sig_tstp, sig_ttin, sig_ttou, sig_urg, sig_xcpu, sig_xfsz, sigtalrm, sig_prof, sig_poll, sig_sys, sig_winch, sig_iot, sig_stkflt, sig_io, sig_lost, sig_pwr): Remove unused global variables variables. * signal.h: Remove declarations thereof.
* * eval.c (getpid_wrap, getppid_wrap): New static functions.Kaz Kylheku2014-07-301-0/+7
| | | | | | | | | (eval_init): Registered getpid and getppid intrinsics. * signal.c (kill_wrap): New static function. (sig-init): Registered kill intrinsic function. * txr.1: Documented getpid, gettpid and kill.
* * Makefile, arith.c, arith.h, combi.c, combi.h, configure, debug.c,Kaz Kylheku2014-07-231-16/+16
| | | | | | | | debug.h, eval.c, eval.h, filter.c, filter.h, gc.c, gc.h, hash.c, hash.h, lib.c, lib.h, match.c, match.h, parser.h, parser.l, parser.y, rand.c, rand.h, regex.c, regex.h, signal.c, signal.h, stream.c, stream.h, syslog.c, syslog.h, txr.c, txr.h, unwind.c, unwind.h, utf8.c, utf8.h: Synchronize license header with LICENSE.
* * signal.c (set_sig_handler): Set up and tear down alternateKaz Kylheku2014-07-201-2/+2
| | | | | | | | stack for SIGBUS also, not only for SIGSEGV. On Linux, when stack growth collides with another memory mapping, it triggers a SIGBUS not SIGSEGV, which occurs when the process limit on stack size is exceeded. In either situation, we need an alternative stack.
* * eval.c, gc.c, rand.c, regex.c, signal.c: Remove inclusion of unneededKaz Kylheku2014-04-131-2/+0
| | | | headers.
* On platforms with sigaltstack, TXR programs can now catch theKaz Kylheku2014-03-131-0/+77
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | segmentation fault that occurs when running out of stack space, and escape by throwing an exception. Also, bugfix: save and restore the gc enable/disable state. Without this, if we are ever running cod in a gc disabled state and it jumps out, gc stays disabled. * configure: added check for sigaltstack. * gc.h (gc_enabled): Declaration added for existing variable. * signal.c (is_cpu_exception): New static function. (sig_handler): For cpu_exception type signals that pertain to the execution of some instruction, turn on async_sig_enabled, so that the signal is not deferred. Otherwise we will just return without calling the user-defined handler, restart the instruction and get into a loop. Also, disable gc around the handler just in case. One issue is that we might be on an alternate stack, which gc won't like. (setup_alt_stack, teardown_alt_stack): New static functions. (set_sig_handler): If we have sigaltstack, and are asked to set up a SEGV handler, then set it up on the alternate stack. * signal.h (extended_jmp_buf): Adding new member, gc. (extended_setjmp, extended_longjmp): use gc member to save and restore the gc_enable state across setjmp and longjmp.
* Change in the design of how special variables work, to fix the brokenKaz Kylheku2014-02-281-34/+40
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | re-binding. C code now has to go through the dynamic environment lookup to access things like *random-state*, or *stdout*. As part of this, I'm moving some intrinsic variable and function initializations out of eval.c and into their respective modules. Macros are are used to make global variables look like ordinary C variables. This is very similar to the errno trick in POSIX threads implementations. * eval.c (looup_var, lookup_var_l): Restructured to eliminate silly goto, the cobjp handling is gone. (reg_fun, reg_var): Internal function becomes external. reg_var registers a simple cons cell binding now, without any C pointer tricks to real C global variables. (c_var_mark): Static function removed. (c_var_ops): Static struct removed. (eval_init): Numerous initializations for streams, syslog, rand, signals and others moved to their respective modules. The new symbol variables user_package_s, keyword_package_s and system_package_s are interned here, and the variables are created in a special way. * eval.h (reg_var, reg_fun): Declared. * gc.c (prot1): Added assert that the loc pointer isn't null. This happened, and blew up during garbage collection. * lib.c (system_package, keyword_package, user_package): Variables removed these become macros. (system_package_var, keyword_package_var, user_package_var): New global variables. (system_package_s, keyword_package_s, user_package_s): New symbol globals. (get_user_package, get_system_package, get_keyword_package): New functions. (obj_init): Protect new variables. Initialization order of modules tweaked: the modules sig_init, stream_init, and rand_init are moved after eval_init because they register variables. * lib.h (keyword_package, system_pckage, user_package): Variables turned into macros. (system_package_var, keyword_package_var, user_package_var): Declared. (system_package_s, keyword_package_s, user_package_s): Declared. (get_user_package, get_system_package, get_keyword_package): Declared. * rand.c (struct random_state): Renamed to struct rand_state to avoid clash with new random_state macro. (random_state): Global variable removed. (random_state_s): New symbol global. (make_state, rand32, make_random_state, random_fixnum, random): Follow rename of struct random_state.
* Mac OSX Upkeep.Kaz Kylheku2014-01-131-0/+2
| | | | | | | | | * configure: (need_svid_source, need_bsd_source): Variables removed. (need_darwin_c_source): New variable. Detect Apple environment and add -D_DARWIN_C_SOURCE, which is needed to reveal some functions in headers. * signal.c (sig_init): Wrap #ifdefs around SIGPOLL; it is not defined on Darwin.
* Merry C++mas!Kaz Kylheku2013-12-251-8/+9
| | | | | | | * configure: Avoid using "new" as identifier in signals test case. * signal.c (set_sig_handler): Fix warning about { 0 } initializer. (sig_mask): Avoid using "new" as identifier.
* Fixing a bug and performance issue.Kaz Kylheku2013-12-201-2/+51
| | | | | | | | | | | | | | | | | | | | | Problem: we are using sigsetjmp but with a jmp_buf structure; it requires sigjmp_buf! Performance issue: sigsetjmp is a dog which makes system calls. Solution: let's roll our own cached version of sigprocmask which only calls the real sigprocmask when the mask changes. Then our extended_setjmp will just use regular setjmp, plus our own custom signal saving and restoring based on the cached version. * signal.c (sig_blocked_cache): New variable. (set_sig_handler): Use our sig_mask instead of sigprocmask. (mem_set_bits, mem_clr_bits): New static functions. (sig_mask): New function. * signal.h (extended_jmp_buf): New member, blocked. (extended_setjmp): save blocked signals by peeking into sig_blocked_cache, and restore using sig_mask. (sig_blocked_cache, sig_mask): Declared.
* * signal.c (sig_handler): Pass two arguments to signalKaz Kylheku2013-12-131-2/+3
| | | | | | | | | | | | | handler rather than 1. The new argument is the value t, telling the handler that it's asynchronously invoked in a real signal context. If the signal handler returns true, then mark it deferred so that it can re-trigger in a synchronous context. (sig_check): Pass nil as a the second argument to signal handlers, indicating that they are synchronously called, not in a signal handler context. * txr.1: Added documentation.
* * signal.c (set_sig_handler): Disable signals around thisKaz Kylheku2013-12-131-0/+6
| | | | | function because it manipulates the mask of deferred signals which can also be manipulated by an async signal.
* * signal.c (set_sig_handler): Clear the deferred flagKaz Kylheku2013-12-131-0/+4
| | | | | | for a signal that is being set to ignored or default. * txr.1: Documented signals.
* * eval.c (eval_init): Registered vars for signal numbers.Kaz Kylheku2013-12-121-0/+54
| | | | | | | | | | | | * signal.c (sig_hup, sig_int, sig_quit, sig_ill, sig_trap, sig_abrt, sig_bus, val sig_fpe, sig_kill, sig_usr1, sig_segv, sig_usr2, sig_pipe, sig_alrm, val sig_term, sig_chld, sig_cont, sig_stop, sig_tstp, sig_ttin, val sig_ttou, sig_urg, sig_xcpu, sig_xfsz, sigtalrm, sig_prof, val sig_poll, sig_sys, sig_winch, sig_iot, sig_stkflt, sig_io, sig_lost, sig_pwr): New variables. (sig_init): New variables initialized. * signal.h: New variables declared.
* First cut at signal handling support.Kaz Kylheku2013-12-121-0/+135
* 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 <signal.h> 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.