From 2805aa2c24f28ea664658d274789a1644fe16f9b Mon Sep 17 00:00:00 2001 From: Gabor Melis Date: Mon, 29 Aug 2005 14:30:45 +0000 Subject: [PATCH] 0.9.4.14: * bug fix: interrupt handlers are now per-process to match pthread semantics, RUN-PROGRAM and SB-SPROF do not die with 'no handler for signal XX in interrupt_handle_now(..)' anymore --- NEWS | 3 +++ src/runtime/cheneygc.c | 6 ++---- src/runtime/gencgc.c | 13 +++++-------- src/runtime/interrupt.c | 40 +++++++++++++++------------------------- src/runtime/interrupt.h | 5 ++--- src/runtime/purify.c | 5 ++--- src/runtime/thread.c | 9 +-------- tests/threads.impure.lisp | 11 ++++++----- version.lisp-expr | 2 +- 9 files changed, 37 insertions(+), 57 deletions(-) diff --git a/NEWS b/NEWS index a6c58f8..44e11b1 100644 --- a/NEWS +++ b/NEWS @@ -19,6 +19,9 @@ changes in sbcl-0.9.5 relative to sbcl-0.9.4: Hannu Koivisto) ** bug fix: binding specials is thread safe (thanks to Hannu Koivisto) + ** bug fix: interrupt handlers are now per-process, RUN-PROGRAM + and SB-SPROF do not die with 'no handler for signal XX in + interrupt_handle_now(..)' anymore * fixed some bugs revealed by Paul Dietz' test suite: ** ENSURE-GENERIC-FUNCTION should take a method class object for the :method-class keyword argument. diff --git a/src/runtime/cheneygc.c b/src/runtime/cheneygc.c index 6679f11..3fa1aa7 100644 --- a/src/runtime/cheneygc.c +++ b/src/runtime/cheneygc.c @@ -124,8 +124,6 @@ collect_garbage(unsigned ignore) unsigned long control_stack_size, binding_stack_size; sigset_t tmp, old; struct thread *th=arch_os_get_current_thread(); - struct interrupt_data *data=th->interrupt_data; - #ifdef PRINTNOISE printf("[Collecting garbage ... \n"); @@ -177,8 +175,8 @@ collect_garbage(unsigned ignore) printf("Scavenging interrupt handlers (%d bytes) ...\n", (int)sizeof(interrupt_handlers)); #endif - scavenge((lispobj *) data->interrupt_handlers, - sizeof(data->interrupt_handlers) / sizeof(lispobj)); + scavenge((lispobj *) interrupt_handlers, + sizeof(interrupt_handlers) / sizeof(lispobj)); /* _size quantities are in units of sizeof(lispobj) - i.e. 4 */ control_stack_size = diff --git a/src/runtime/gencgc.c b/src/runtime/gencgc.c index ea715e3..c2dd4ba 100644 --- a/src/runtime/gencgc.c +++ b/src/runtime/gencgc.c @@ -3622,14 +3622,11 @@ garbage_collect_generation(int generation, int raise) /* Scavenge the Lisp functions of the interrupt handlers, taking * care to avoid SIG_DFL and SIG_IGN. */ - for_each_thread(th) { - struct interrupt_data *data=th->interrupt_data; - for (i = 0; i < NSIG; i++) { - union interrupt_handler handler = data->interrupt_handlers[i]; - if (!ARE_SAME_HANDLER(handler.c, SIG_IGN) && - !ARE_SAME_HANDLER(handler.c, SIG_DFL)) { - scavenge((lispobj *)(data->interrupt_handlers + i), 1); - } + for (i = 0; i < NSIG; i++) { + union interrupt_handler handler = interrupt_handlers[i]; + if (!ARE_SAME_HANDLER(handler.c, SIG_IGN) && + !ARE_SAME_HANDLER(handler.c, SIG_DFL)) { + scavenge((lispobj *)(interrupt_handlers + i), 1); } } /* Scavenge the function list for INTERRUPT-THREAD. */ diff --git a/src/runtime/interrupt.c b/src/runtime/interrupt.c index d822ceb..648850f 100644 --- a/src/runtime/interrupt.c +++ b/src/runtime/interrupt.c @@ -143,7 +143,8 @@ inline static void check_interrupts_enabled_or_lose(os_context_t *context) * becomes 'yes'.) */ boolean internal_errors_enabled = 0; -struct interrupt_data * global_interrupt_data; +static void (*interrupt_low_level_handlers[NSIG]) (int, siginfo_t*, void*); +union interrupt_handler interrupt_handlers[NSIG]; /* At the toplevel repl we routinely call this function. The signal * mask ought to be clear anyway most of the time, but may be non-zero @@ -416,7 +417,6 @@ void interrupt_handle_now(int signal, siginfo_t *info, void *void_context) { os_context_t *context = (os_context_t*)void_context; - struct thread *thread=arch_os_get_current_thread(); #if !defined(LISP_FEATURE_X86) && !defined(LISP_FEATURE_X86_64) boolean were_in_lisp; #endif @@ -431,7 +431,7 @@ interrupt_handle_now(int signal, siginfo_t *info, void *void_context) delivered we appear to have a null FPU control word. */ os_restore_fp_control(context); #endif - handler = thread->interrupt_data->interrupt_handlers[signal]; + handler = interrupt_handlers[signal]; if (ARE_SAME_HANDLER(handler.c, SIG_IGN)) { return; @@ -467,7 +467,10 @@ interrupt_handle_now(int signal, siginfo_t *info, void *void_context) * because we're not in pseudoatomic and allocation shouldn't * be interrupted. In which case it's no longer an issue as * all our allocation from C now goes through a PA wrapper, - * but still, doesn't hurt */ + * but still, doesn't hurt. + * + * Yeah, but non-gencgc platforms that don't really wrap + * allocation in PA. MG - 2005-08-29 */ lispobj info_sap,context_sap = alloc_sap(context); info_sap = alloc_sap(info); @@ -618,16 +621,13 @@ static void low_level_interrupt_handle_now(int signal, siginfo_t *info, void *void_context) { os_context_t *context = (os_context_t*)void_context; - struct thread *thread=arch_os_get_current_thread(); - struct interrupt_data *data=thread->interrupt_data; #ifdef LISP_FEATURE_LINUX os_restore_fp_control(context); #endif check_blockables_blocked_or_lose(); check_interrupts_enabled_or_lose(context); - (*data->interrupt_low_level_handlers[signal]) - (signal, info, void_context); + interrupt_low_level_handlers[signal](signal, info, void_context); #ifdef LISP_FEATURE_DARWIN /* Work around G5 bug */ DARWIN_FIX_CONTEXT(context); @@ -1051,10 +1051,6 @@ undoably_install_low_level_interrupt_handler (int signal, void*)) { struct sigaction sa; - struct thread *th=arch_os_get_current_thread(); - /* It may be before the initial thread is started. */ - struct interrupt_data *data= - th ? th->interrupt_data : global_interrupt_data; if (0 > signal || signal >= NSIG) { lose("bad signal number %d", signal); @@ -1078,7 +1074,7 @@ undoably_install_low_level_interrupt_handler (int signal, #endif sigaction(signal, &sa, NULL); - data->interrupt_low_level_handlers[signal] = + interrupt_low_level_handlers[signal] = (ARE_SAME_HANDLER(handler, SIG_DFL) ? 0 : handler); } @@ -1089,10 +1085,6 @@ install_handler(int signal, void handler(int, siginfo_t*, void*)) struct sigaction sa; sigset_t old, new; union interrupt_handler oldhandler; - struct thread *th=arch_os_get_current_thread(); - /* It may be before the initial thread is started. */ - struct interrupt_data *data= - th ? th->interrupt_data : global_interrupt_data; FSHOW((stderr, "/entering POSIX install_handler(%d, ..)\n", signal)); @@ -1100,9 +1092,9 @@ install_handler(int signal, void handler(int, siginfo_t*, void*)) sigaddset(&new, signal); thread_sigmask(SIG_BLOCK, &new, &old); - FSHOW((stderr, "/data->interrupt_low_level_handlers[signal]=%x\n", - (unsigned int)data->interrupt_low_level_handlers[signal])); - if (data->interrupt_low_level_handlers[signal]==0) { + FSHOW((stderr, "/interrupt_low_level_handlers[signal]=%x\n", + (unsigned int)interrupt_low_level_handlers[signal])); + if (interrupt_low_level_handlers[signal]==0) { if (ARE_SAME_HANDLER(handler, SIG_DFL) || ARE_SAME_HANDLER(handler, SIG_IGN)) { sa.sa_sigaction = handler; @@ -1118,8 +1110,8 @@ install_handler(int signal, void handler(int, siginfo_t*, void*)) sigaction(signal, &sa, NULL); } - oldhandler = data->interrupt_handlers[signal]; - data->interrupt_handlers[signal].c = handler; + oldhandler = interrupt_handlers[signal]; + interrupt_handlers[signal].c = handler; thread_sigmask(SIG_SETMASK, &old, 0); @@ -1138,11 +1130,9 @@ interrupt_init() sigaddset_deferrable(&deferrable_sigset); sigaddset_blockable(&blockable_sigset); - global_interrupt_data=calloc(sizeof(struct interrupt_data), 1); - /* Set up high level handler information. */ for (i = 0; i < NSIG; i++) { - global_interrupt_data->interrupt_handlers[i].c = + interrupt_handlers[i].c = /* (The cast here blasts away the distinction between * SA_SIGACTION-style three-argument handlers and * signal(..)-style one-argument handlers, which is OK diff --git a/src/runtime/interrupt.h b/src/runtime/interrupt.h index 0b6fb7b..ec78999 100644 --- a/src/runtime/interrupt.h +++ b/src/runtime/interrupt.h @@ -45,10 +45,9 @@ union interrupt_handler { void (*c)(int, siginfo_t*, void*); }; -struct interrupt_data { - void (*interrupt_low_level_handlers[NSIG]) (int, siginfo_t*, void*) ; - union interrupt_handler interrupt_handlers[NSIG]; +extern union interrupt_handler interrupt_handlers[NSIG]; +struct interrupt_data { /* signal information for pending signal. pending_signal=0 when there * is no pending signal. */ void (*pending_handler) (int, siginfo_t*, void*) ; diff --git a/src/runtime/purify.c b/src/runtime/purify.c index ca850dd..eaa602e 100644 --- a/src/runtime/purify.c +++ b/src/runtime/purify.c @@ -1491,9 +1491,8 @@ purify(lispobj static_roots, lispobj read_only_roots) printf(" handlers"); fflush(stdout); #endif - pscav((lispobj *) all_threads->interrupt_data->interrupt_handlers, - sizeof(all_threads->interrupt_data->interrupt_handlers) - / sizeof(lispobj), + pscav((lispobj *) interrupt_handlers, + sizeof(interrupt_handlers) / sizeof(lispobj), 0); #ifdef PRINTNOISE diff --git a/src/runtime/thread.c b/src/runtime/thread.c index 0377562..ab0db08 100644 --- a/src/runtime/thread.c +++ b/src/runtime/thread.c @@ -262,14 +262,7 @@ create_thread_struct(lispobj initial_function) { free_thread_struct(th); return 0; } - if(all_threads) - memcpy(th->interrupt_data, - arch_os_get_current_thread()->interrupt_data, - sizeof (struct interrupt_data)); - else - memcpy(th->interrupt_data,global_interrupt_data, - sizeof (struct interrupt_data)); - + th->interrupt_data->pending_handler = 0; th->no_tls_value_marker=initial_function; return th; } diff --git a/tests/threads.impure.lisp b/tests/threads.impure.lisp index 9cb1675..3e1c97c 100644 --- a/tests/threads.impure.lisp +++ b/tests/threads.impure.lisp @@ -417,6 +417,12 @@ (assert (null (symbol-value-in-thread 'sb-thread:*current-thread* thread)))) +;; interrupt handlers are per-thread with pthreads, make sure the +;; handler installed in one thread is global +(sb-thread:make-thread + (lambda () + (sb-ext:run-program "sleep" '("1") :search t :wait nil))) + #| ;; a cll post from eric marsden | (defun crash () | (setq *debugger-hook* @@ -429,8 +435,3 @@ | (mp:make-process #'roomy) | (mp:make-process #'roomy))) |# - -;; give the other thread time to die before we leave, otherwise the -;; overall exit status is 0, not 104 -(sleep 2) - diff --git a/version.lisp-expr b/version.lisp-expr index 4537eef..416f0bd 100644 --- a/version.lisp-expr +++ b/version.lisp-expr @@ -17,4 +17,4 @@ ;;; checkins which aren't released. (And occasionally for internal ;;; versions, especially for internal versions off the main CVS ;;; branch, it gets hairier, e.g. "0.pre7.14.flaky4.13".) -"0.9.4.13" +"0.9.4.14" -- 1.7.10.4