2 * interrupt-handling magic
6 * This software is part of the SBCL system. See the README file for
9 * This software is derived from the CMU CL system, which was
10 * written at Carnegie Mellon University and released into the
11 * public domain. The software is in the public domain and is
12 * provided with absolutely no warranty. See the COPYING and CREDITS
13 * files for more information.
17 /* As far as I can tell, what's going on here is:
19 * In the case of most signals, when Lisp asks us to handle the
20 * signal, the outermost handler (the one actually passed to UNIX) is
21 * either interrupt_handle_now(..) or maybe_now_maybe_later(..).
22 * In that case, the Lisp-level handler is stored in interrupt_handlers[..]
23 * and interrupt_low_level_handlers[..] is cleared.
25 * However, some signals need special handling, e.g.
27 * o the SIGSEGV (for e.g. Linux) or SIGBUS (for e.g. FreeBSD) used by the
28 * garbage collector to detect violations of write protection,
29 * because some cases of such signals (e.g. GC-related violations of
30 * write protection) are handled at C level and never passed on to
31 * Lisp. For such signals, we still store any Lisp-level handler
32 * in interrupt_handlers[..], but for the outermost handle we use
33 * the value from interrupt_low_level_handlers[..], instead of the
34 * ordinary interrupt_handle_now(..) or interrupt_handle_later(..).
36 * o the SIGTRAP (Linux/Alpha) which Lisp code uses to handle breakpoints,
37 * pseudo-atomic sections, and some classes of error (e.g. "function
38 * not defined"). This never goes anywhere near the Lisp handlers at all.
39 * See runtime/alpha-arch.c and code/signal.lisp
41 * - WHN 20000728, dan 20010128 */
53 #include "interrupt.h"
62 #include "genesis/fdefn.h"
63 #include "genesis/simple-fun.h"
65 void run_deferred_handler(struct interrupt_data *data, void *v_context) ;
66 static void store_signal_data_for_later (struct interrupt_data *data,
67 void *handler, int signal,
69 os_context_t *context);
70 boolean interrupt_maybe_gc_int(int signal, siginfo_t *info, void *v_context);
72 extern lispobj all_threads_lock;
73 extern volatile int countdown_to_gc;
76 * This is a workaround for some slightly silly Linux/GNU Libc
77 * behaviour: glibc defines sigset_t to support 1024 signals, which is
78 * more than the kernel. This is usually not a problem, but becomes
79 * one when we want to save a signal mask from a ucontext, and restore
80 * it later into another ucontext: the ucontext is allocated on the
81 * stack by the kernel, so copying a libc-sized sigset_t into it will
82 * overflow and cause other data on the stack to be corrupted */
84 #define REAL_SIGSET_SIZE_BYTES ((NSIG/8))
86 void sigaddset_blockable(sigset_t *s)
90 sigaddset(s, SIGQUIT);
91 sigaddset(s, SIGPIPE);
92 sigaddset(s, SIGALRM);
95 sigaddset(s, SIGTSTP);
96 sigaddset(s, SIGCHLD);
98 sigaddset(s, SIGXCPU);
99 sigaddset(s, SIGXFSZ);
100 sigaddset(s, SIGVTALRM);
101 sigaddset(s, SIGPROF);
102 sigaddset(s, SIGWINCH);
103 sigaddset(s, SIGUSR1);
104 sigaddset(s, SIGUSR2);
105 #ifdef LISP_FEATURE_SB_THREAD
106 sigaddset(s, SIG_STOP_FOR_GC);
107 sigaddset(s, SIG_INTERRUPT_THREAD);
111 /* When we catch an internal error, should we pass it back to Lisp to
112 * be handled in a high-level way? (Early in cold init, the answer is
113 * 'no', because Lisp is still too brain-dead to handle anything.
114 * After sufficient initialization has been completed, the answer
116 boolean internal_errors_enabled = 0;
118 struct interrupt_data * global_interrupt_data;
122 * utility routines used by various signal handlers
126 build_fake_control_stack_frames(struct thread *th,os_context_t *context)
128 #ifndef LISP_FEATURE_X86
132 /* Build a fake stack frame or frames */
134 current_control_frame_pointer =
135 (lispobj *)(*os_context_register_addr(context, reg_CSP));
136 if ((lispobj *)(*os_context_register_addr(context, reg_CFP))
137 == current_control_frame_pointer) {
138 /* There is a small window during call where the callee's
139 * frame isn't built yet. */
140 if (lowtag_of(*os_context_register_addr(context, reg_CODE))
141 == FUN_POINTER_LOWTAG) {
142 /* We have called, but not built the new frame, so
143 * build it for them. */
144 current_control_frame_pointer[0] =
145 *os_context_register_addr(context, reg_OCFP);
146 current_control_frame_pointer[1] =
147 *os_context_register_addr(context, reg_LRA);
148 current_control_frame_pointer += 8;
149 /* Build our frame on top of it. */
150 oldcont = (lispobj)(*os_context_register_addr(context, reg_CFP));
153 /* We haven't yet called, build our frame as if the
154 * partial frame wasn't there. */
155 oldcont = (lispobj)(*os_context_register_addr(context, reg_OCFP));
158 /* We can't tell whether we are still in the caller if it had to
159 * allocate a stack frame due to stack arguments. */
160 /* This observation provoked some past CMUCL maintainer to ask
161 * "Can anything strange happen during return?" */
164 oldcont = (lispobj)(*os_context_register_addr(context, reg_CFP));
167 current_control_stack_pointer = current_control_frame_pointer + 8;
169 current_control_frame_pointer[0] = oldcont;
170 current_control_frame_pointer[1] = NIL;
171 current_control_frame_pointer[2] =
172 (lispobj)(*os_context_register_addr(context, reg_CODE));
177 fake_foreign_function_call(os_context_t *context)
180 struct thread *thread=arch_os_get_current_thread();
182 /* Get current Lisp state from context. */
184 dynamic_space_free_pointer =
185 (lispobj *)(*os_context_register_addr(context, reg_ALLOC));
187 if ((long)dynamic_space_free_pointer & 1) {
188 lose("dead in fake_foreign_function_call, context = %x", context);
193 current_binding_stack_pointer =
194 (lispobj *)(*os_context_register_addr(context, reg_BSP));
197 build_fake_control_stack_frames(thread,context);
199 /* Do dynamic binding of the active interrupt context index
200 * and save the context in the context array. */
202 fixnum_value(SymbolValue(FREE_INTERRUPT_CONTEXT_INDEX,thread));
204 if (context_index >= MAX_INTERRUPTS) {
205 lose("maximum interrupt nesting depth (%d) exceeded", MAX_INTERRUPTS);
208 bind_variable(FREE_INTERRUPT_CONTEXT_INDEX,
209 make_fixnum(context_index + 1),thread);
211 thread->interrupt_contexts[context_index] = context;
213 /* no longer in Lisp now */
214 foreign_function_call_active = 1;
217 /* blocks all blockable signals. If you are calling from a signal handler,
218 * the usual signal mask will be restored from the context when the handler
219 * finishes. Otherwise, be careful */
222 undo_fake_foreign_function_call(os_context_t *context)
224 struct thread *thread=arch_os_get_current_thread();
225 /* Block all blockable signals. */
228 sigaddset_blockable(&block);
229 sigprocmask(SIG_BLOCK, &block, 0);
231 /* going back into Lisp */
232 foreign_function_call_active = 0;
234 /* Undo dynamic binding of FREE_INTERRUPT_CONTEXT_INDEX */
238 /* Put the dynamic space free pointer back into the context. */
239 *os_context_register_addr(context, reg_ALLOC) =
240 (unsigned long) dynamic_space_free_pointer;
244 /* a handler for the signal caused by execution of a trap opcode
245 * signalling an internal error */
247 interrupt_internal_error(int signal, siginfo_t *info, os_context_t *context,
250 lispobj context_sap = 0;
252 fake_foreign_function_call(context);
254 /* Allocate the SAP object while the interrupts are still
256 if (internal_errors_enabled) {
257 context_sap = alloc_sap(context);
260 sigprocmask(SIG_SETMASK, os_context_sigmask_addr(context), 0);
262 if (internal_errors_enabled) {
263 SHOW("in interrupt_internal_error");
265 /* Display some rudimentary debugging information about the
266 * error, so that even if the Lisp error handler gets badly
267 * confused, we have a chance to determine what's going on. */
268 describe_internal_error(context);
270 funcall2(SymbolFunction(INTERNAL_ERROR), context_sap,
271 continuable ? T : NIL);
273 describe_internal_error(context);
274 /* There's no good way to recover from an internal error
275 * before the Lisp error handling mechanism is set up. */
276 lose("internal error too early in init, can't recover");
278 undo_fake_foreign_function_call(context); /* blocks signals again */
280 arch_skip_instruction(context);
285 interrupt_handle_pending(os_context_t *context)
287 struct thread *thread;
288 struct interrupt_data *data;
290 thread=arch_os_get_current_thread();
291 data=thread->interrupt_data;
292 /* FIXME I'm not altogether sure this is appropriate if we're
293 * here as the result of a pseudo-atomic */
294 SetSymbolValue(INTERRUPT_PENDING, NIL,thread);
296 /* restore the saved signal mask from the original signal (the
297 * one that interrupted us during the critical section) into the
298 * os_context for the signal we're currently in the handler for.
299 * This should ensure that when we return from the handler the
300 * blocked signals are unblocked */
302 memcpy(os_context_sigmask_addr(context), &data->pending_mask,
303 REAL_SIGSET_SIZE_BYTES);
305 sigemptyset(&data->pending_mask);
306 /* This will break on sparc linux: the deferred handler really wants
307 * to be called with a void_context */
308 run_deferred_handler(data,(void *)context);
312 * the two main signal handlers:
313 * interrupt_handle_now(..)
314 * maybe_now_maybe_later(..)
316 * to which we have added interrupt_handle_now_handler(..). Why?
317 * Well, mostly because the SPARC/Linux platform doesn't quite do
318 * signals the way we want them done. The third argument in the
319 * handler isn't filled in by the kernel properly, so we fix it up
320 * ourselves in the arch_os_get_context(..) function; however, we only
321 * want to do this when we first hit the handler, and not when
322 * interrupt_handle_now(..) is being called from some other handler
323 * (when the fixup will already have been done). -- CSR, 2002-07-23
327 interrupt_handle_now(int signal, siginfo_t *info, void *void_context)
329 os_context_t *context = (os_context_t*)void_context;
330 struct thread *thread=arch_os_get_current_thread();
331 #ifndef LISP_FEATURE_X86
332 boolean were_in_lisp;
334 union interrupt_handler handler;
336 #ifdef LISP_FEATURE_LINUX
337 /* Under Linux on some architectures, we appear to have to restore
338 the FPU control word from the context, as after the signal is
339 delivered we appear to have a null FPU control word. */
340 os_restore_fp_control(context);
342 handler = thread->interrupt_data->interrupt_handlers[signal];
344 if (ARE_SAME_HANDLER(handler.c, SIG_IGN)) {
348 #ifndef LISP_FEATURE_X86
349 were_in_lisp = !foreign_function_call_active;
353 fake_foreign_function_call(context);
358 "/entering interrupt_handle_now(%d, info, context)\n",
362 if (ARE_SAME_HANDLER(handler.c, SIG_DFL)) {
364 /* This can happen if someone tries to ignore or default one
365 * of the signals we need for runtime support, and the runtime
366 * support decides to pass on it. */
367 lose("no handler for signal %d in interrupt_handle_now(..)", signal);
369 } else if (lowtag_of(handler.lisp) == FUN_POINTER_LOWTAG) {
370 /* Once we've decided what to do about contexts in a
371 * return-elsewhere world (the original context will no longer
372 * be available; should we copy it or was nobody using it anyway?)
373 * then we should convert this to return-elsewhere */
375 /* CMUCL comment said "Allocate the SAPs while the interrupts
376 * are still disabled.". I (dan, 2003.08.21) assume this is
377 * because we're not in pseudoatomic and allocation shouldn't
378 * be interrupted. In which case it's no longer an issue as
379 * all our allocation from C now goes through a PA wrapper,
380 * but still, doesn't hurt */
382 lispobj info_sap,context_sap = alloc_sap(context);
383 info_sap = alloc_sap(info);
384 /* Allow signals again. */
385 sigprocmask(SIG_SETMASK, os_context_sigmask_addr(context), 0);
388 SHOW("calling Lisp-level handler");
391 funcall3(handler.lisp,
398 SHOW("calling C-level handler");
401 /* Allow signals again. */
402 sigprocmask(SIG_SETMASK, os_context_sigmask_addr(context), 0);
404 (*handler.c)(signal, info, void_context);
407 #ifndef LISP_FEATURE_X86
411 undo_fake_foreign_function_call(context); /* block signals again */
416 "/returning from interrupt_handle_now(%d, info, context)\n",
421 /* This is called at the end of a critical section if the indications
422 * are that some signal was deferred during the section. Note that as
423 * far as C or the kernel is concerned we dealt with the signal
424 * already; we're just doing the Lisp-level processing now that we
428 run_deferred_handler(struct interrupt_data *data, void *v_context) {
429 (*(data->pending_handler))
430 (data->pending_signal,&(data->pending_info), v_context);
431 data->pending_handler=0;
435 maybe_defer_handler(void *handler, struct interrupt_data *data,
436 int signal, siginfo_t *info, os_context_t *context)
438 struct thread *thread=arch_os_get_current_thread();
439 if (SymbolValue(INTERRUPTS_ENABLED,thread) == NIL) {
440 store_signal_data_for_later(data,handler,signal,info,context);
441 SetSymbolValue(INTERRUPT_PENDING, T,thread);
444 /* a slightly confusing test. arch_pseudo_atomic_atomic() doesn't
445 * actually use its argument for anything on x86, so this branch
446 * may succeed even when context is null (gencgc alloc()) */
448 #ifndef LISP_FEATURE_X86
449 (!foreign_function_call_active) &&
451 arch_pseudo_atomic_atomic(context)) {
452 store_signal_data_for_later(data,handler,signal,info,context);
453 arch_set_pseudo_atomic_interrupted(context);
459 store_signal_data_for_later (struct interrupt_data *data, void *handler,
461 siginfo_t *info, os_context_t *context)
463 data->pending_handler = handler;
464 data->pending_signal = signal;
466 memcpy(&(data->pending_info), info, sizeof(siginfo_t));
468 /* the signal mask in the context (from before we were
469 * interrupted) is copied to be restored when
470 * run_deferred_handler happens. Then the usually-blocked
471 * signals are added to the mask in the context so that we are
472 * running with blocked signals when the handler returns */
473 sigemptyset(&(data->pending_mask));
474 memcpy(&(data->pending_mask),
475 os_context_sigmask_addr(context),
476 REAL_SIGSET_SIZE_BYTES);
477 sigaddset_blockable(os_context_sigmask_addr(context));
479 /* this is also called from gencgc alloc(), in which case
480 * there has been no signal and is therefore no context. */
483 sigaddset_blockable(&new);
484 sigprocmask(SIG_BLOCK,&new,&(data->pending_mask));
490 maybe_now_maybe_later(int signal, siginfo_t *info, void *void_context)
492 os_context_t *context = arch_os_get_context(&void_context);
493 struct thread *thread=arch_os_get_current_thread();
494 struct interrupt_data *data=thread->interrupt_data;
495 #ifdef LISP_FEATURE_LINUX
496 os_restore_fp_control(context);
498 if(maybe_defer_handler(interrupt_handle_now,data,
499 signal,info,context))
501 interrupt_handle_now(signal, info, context);
505 sig_stop_for_gc_handler(int signal, siginfo_t *info, void *void_context)
507 os_context_t *context = arch_os_get_context(&void_context);
508 struct thread *thread=arch_os_get_current_thread();
509 struct interrupt_data *data=thread->interrupt_data;
512 if(maybe_defer_handler(sig_stop_for_gc_handler,data,
513 signal,info,context)){
516 /* need the context stored so it can have registers scavenged */
517 fake_foreign_function_call(context);
519 get_spinlock(&all_threads_lock,thread->pid);
521 release_spinlock(&all_threads_lock);
522 kill(thread->pid,SIGSTOP);
524 undo_fake_foreign_function_call(context);
528 interrupt_handle_now_handler(int signal, siginfo_t *info, void *void_context)
530 os_context_t *context = arch_os_get_context(&void_context);
531 interrupt_handle_now(signal, info, context);
535 * stuff to detect and handle hitting the GC trigger
538 #ifndef LISP_FEATURE_GENCGC
539 /* since GENCGC has its own way to record trigger */
541 gc_trigger_hit(int signal, siginfo_t *info, os_context_t *context)
543 if (current_auto_gc_trigger == NULL)
546 void *badaddr=arch_get_bad_addr(signal,info,context);
547 return (badaddr >= (void *)current_auto_gc_trigger &&
548 badaddr <((void *)current_dynamic_space + DYNAMIC_SPACE_SIZE));
553 /* manipulate the signal context and stack such that when the handler
554 * returns, it will call function instead of whatever it was doing
558 extern lispobj call_into_lisp(lispobj fun, lispobj *args, int nargs);
559 extern void post_signal_tramp(void);
560 void arrange_return_to_lisp_function(os_context_t *context, lispobj function)
562 void * fun=native_pointer(function);
563 char *code = &(((struct simple_fun *) fun)->code);
565 /* Build a stack frame showing `interrupted' so that the
566 * user's backtrace makes (as much) sense (as usual) */
567 #ifdef LISP_FEATURE_X86
568 /* Suppose the existence of some function that saved all
569 * registers, called call_into_lisp, then restored GP registers and
570 * returned. We shortcut this: fake the stack that call_into_lisp
571 * would see, then arrange to have it called directly. post_signal_tramp
572 * is the second half of this function
574 u32 *sp=(u32 *)*os_context_register_addr(context,reg_ESP);
576 *(sp-14) = post_signal_tramp; /* return address for call_into_lisp */
577 *(sp-13) = function; /* args for call_into_lisp : function*/
578 *(sp-12) = 0; /* arg array */
579 *(sp-11) = 0; /* no. args */
580 /* this order matches that used in POPAD */
581 *(sp-10)=*os_context_register_addr(context,reg_EDI);
582 *(sp-9)=*os_context_register_addr(context,reg_ESI);
583 /* this gets overwritten again before it's used, anyway */
584 *(sp-8)=*os_context_register_addr(context,reg_EBP);
585 *(sp-7)=0 ; /* POPAD doesn't set ESP, but expects a gap for it anyway */
586 *(sp-6)=*os_context_register_addr(context,reg_EBX);
588 *(sp-5)=*os_context_register_addr(context,reg_EDX);
589 *(sp-4)=*os_context_register_addr(context,reg_ECX);
590 *(sp-3)=*os_context_register_addr(context,reg_EAX);
591 *(sp-2)=*os_context_register_addr(context,reg_EBP);
592 *(sp-1)=*os_context_pc_addr(context);
595 struct thread *th=arch_os_get_current_thread();
596 build_fake_control_stack_frames(th,context);
599 #ifdef LISP_FEATURE_X86
600 *os_context_pc_addr(context) = call_into_lisp;
601 *os_context_register_addr(context,reg_ECX) = 0;
602 *os_context_register_addr(context,reg_EBP) = sp-2;
603 *os_context_register_addr(context,reg_ESP) = sp-14;
605 /* this much of the calling convention is common to all
607 *os_context_pc_addr(context) = code;
608 *os_context_register_addr(context,reg_NARGS) = 0;
609 *os_context_register_addr(context,reg_LIP) = code;
610 *os_context_register_addr(context,reg_CFP) =
611 current_control_frame_pointer;
613 #ifdef ARCH_HAS_NPC_REGISTER
614 *os_context_npc_addr(context) =
615 4 + *os_context_pc_addr(context);
617 #ifdef LISP_FEATURE_SPARC
618 *os_context_register_addr(context,reg_CODE) =
619 fun + FUN_POINTER_LOWTAG;
623 #ifdef LISP_FEATURE_SB_THREAD
624 void handle_rt_signal(int num, siginfo_t *info, void *v_context)
626 os_context_t *context = (os_context_t*)arch_os_get_context(&v_context);
627 struct thread *th=arch_os_get_current_thread();
628 struct interrupt_data *data=
629 th ? th->interrupt_data : global_interrupt_data;
630 if(maybe_defer_handler(handle_rt_signal,data,num,info,context)){
633 arrange_return_to_lisp_function(context,info->si_value.sival_int);
637 boolean handle_control_stack_guard_triggered(os_context_t *context,void *addr){
638 struct thread *th=arch_os_get_current_thread();
639 /* note the os_context hackery here. When the signal handler returns,
640 * it won't go back to what it was doing ... */
641 if(addr>=(void *)CONTROL_STACK_GUARD_PAGE(th) &&
642 addr<(void *)(CONTROL_STACK_GUARD_PAGE(th)+os_vm_page_size)) {
643 /* we hit the end of the control stack. disable protection
644 * temporarily so the error handler has some headroom */
645 protect_control_stack_guard_page(th->pid,0L);
647 arrange_return_to_lisp_function
648 (context, SymbolFunction(CONTROL_STACK_EXHAUSTED_ERROR));
654 #ifndef LISP_FEATURE_GENCGC
655 /* This function gets called from the SIGSEGV (for e.g. Linux or
656 * OpenBSD) or SIGBUS (for e.g. FreeBSD) handler. Here we check
657 * whether the signal was due to treading on the mprotect()ed zone -
658 * and if so, arrange for a GC to happen. */
659 extern unsigned long bytes_consed_between_gcs; /* gc-common.c */
662 interrupt_maybe_gc(int signal, siginfo_t *info, void *void_context)
664 os_context_t *context=(os_context_t *) void_context;
665 struct thread *th=arch_os_get_current_thread();
666 struct interrupt_data *data=
667 th ? th->interrupt_data : global_interrupt_data;
669 if(!foreign_function_call_active && gc_trigger_hit(signal, info, context)){
670 clear_auto_gc_trigger();
671 if(!maybe_defer_handler
672 (interrupt_maybe_gc_int,data,signal,info,void_context))
673 interrupt_maybe_gc_int(signal,info,void_context);
681 /* this is also used by gencgc, in alloc() */
683 interrupt_maybe_gc_int(int signal, siginfo_t *info, void *void_context)
686 os_context_t *context=(os_context_t *) void_context;
687 fake_foreign_function_call(context);
688 /* SUB-GC may return without GCing if *GC-INHIBIT* is set, in
689 * which case we will be running with no gc trigger barrier
690 * thing for a while. But it shouldn't be long until the end
691 * of WITHOUT-GCING. */
694 sigaddset_blockable(&new);
695 /* enable signals before calling into Lisp */
696 sigprocmask(SIG_UNBLOCK,&new,0);
697 funcall0(SymbolFunction(SUB_GC));
698 undo_fake_foreign_function_call(context);
704 * noise to install handlers
708 undoably_install_low_level_interrupt_handler (int signal,
714 struct thread *th=arch_os_get_current_thread();
715 struct interrupt_data *data=
716 th ? th->interrupt_data : global_interrupt_data;
718 if (0 > signal || signal >= NSIG) {
719 lose("bad signal number %d", signal);
722 sa.sa_sigaction = handler;
723 sigemptyset(&sa.sa_mask);
724 sigaddset_blockable(&sa.sa_mask);
725 sa.sa_flags = SA_SIGINFO | SA_RESTART;
726 #ifdef LISP_FEATURE_C_STACK_IS_CONTROL_STACK
727 if((signal==SIG_MEMORY_FAULT)
728 #ifdef SIG_INTERRUPT_THREAD
729 || (signal==SIG_INTERRUPT_THREAD)
732 sa.sa_flags|= SA_ONSTACK;
735 sigaction(signal, &sa, NULL);
736 data->interrupt_low_level_handlers[signal] =
737 (ARE_SAME_HANDLER(handler, SIG_DFL) ? 0 : handler);
740 /* This is called from Lisp. */
742 install_handler(int signal, void handler(int, siginfo_t*, void*))
746 union interrupt_handler oldhandler;
747 struct thread *th=arch_os_get_current_thread();
748 struct interrupt_data *data=
749 th ? th->interrupt_data : global_interrupt_data;
751 FSHOW((stderr, "/entering POSIX install_handler(%d, ..)\n", signal));
754 sigaddset(&new, signal);
755 sigprocmask(SIG_BLOCK, &new, &old);
758 sigaddset_blockable(&new);
760 FSHOW((stderr, "/interrupt_low_level_handlers[signal]=%d\n",
761 interrupt_low_level_handlers[signal]));
762 if (data->interrupt_low_level_handlers[signal]==0) {
763 if (ARE_SAME_HANDLER(handler, SIG_DFL) ||
764 ARE_SAME_HANDLER(handler, SIG_IGN)) {
765 sa.sa_sigaction = handler;
766 } else if (sigismember(&new, signal)) {
767 sa.sa_sigaction = maybe_now_maybe_later;
769 sa.sa_sigaction = interrupt_handle_now_handler;
772 sigemptyset(&sa.sa_mask);
773 sigaddset_blockable(&sa.sa_mask);
774 sa.sa_flags = SA_SIGINFO | SA_RESTART;
775 sigaction(signal, &sa, NULL);
778 oldhandler = data->interrupt_handlers[signal];
779 data->interrupt_handlers[signal].c = handler;
781 sigprocmask(SIG_SETMASK, &old, 0);
783 FSHOW((stderr, "/leaving POSIX install_handler(%d, ..)\n", signal));
785 return (unsigned long)oldhandler.lisp;
792 SHOW("entering interrupt_init()");
793 global_interrupt_data=calloc(sizeof(struct interrupt_data), 1);
795 /* Set up high level handler information. */
796 for (i = 0; i < NSIG; i++) {
797 global_interrupt_data->interrupt_handlers[i].c =
798 /* (The cast here blasts away the distinction between
799 * SA_SIGACTION-style three-argument handlers and
800 * signal(..)-style one-argument handlers, which is OK
801 * because it works to call the 1-argument form where the
802 * 3-argument form is expected.) */
803 (void (*)(int, siginfo_t*, void*))SIG_DFL;
806 SHOW("returning from interrupt_init()");