2 * This software is part of the SBCL system. See the README file for
5 * This software is derived from the CMU CL system, which was
6 * written at Carnegie Mellon University and released into the
7 * public domain. The software is in the public domain and is
8 * provided with absolutely no warranty. See the COPYING and CREDITS
9 * files for more information.
12 #if !defined(_INCLUDE_INTERRUPT_H_)
13 #define _INCLUDE_INTERRUPT_H_
19 * This is a workaround for some slightly silly Linux/GNU Libc
20 * behaviour: glibc defines sigset_t to support 1024 signals, which is
21 * more than the kernel. This is usually not a problem, but becomes
22 * one when we want to save a signal mask from a ucontext, and restore
23 * it later into another ucontext: the ucontext is allocated on the
24 * stack by the kernel, so copying a libc-sized sigset_t into it will
25 * overflow and cause other data on the stack to be corrupted */
26 /* FIXME: do not rely on NSIG being a multiple of 8 */
27 #define REAL_SIGSET_SIZE_BYTES ((NSIG/8))
29 extern sigset_t deferrable_sigset;
30 extern sigset_t blockable_sigset;
32 extern void check_blockables_blocked_or_lose(void);
33 extern void check_gc_signals_unblocked_or_lose(void);
34 extern void unblock_gc_signals(void);
37 sigcopyset(sigset_t *new, sigset_t *old)
39 memcpy(new, old, REAL_SIGSET_SIZE_BYTES);
42 /* maximum signal nesting depth
44 * FIXME: In CMUCL this was 4096, and it was first scaled down to 256
45 * and then 32, until finally Stumpwm broke: it is possible to receive
46 * interrupts in sufficiently quick succession that handler nesting
47 * can become preposterous. Scaling this back up to 1024 is a bandaid:
48 * for a real fix we should consider the following things:
50 * We should almost certainly always use
51 * arrange_return_to_lisp_function, though it needs to be thought
52 * about arguments, and it needs to be able to pass a frobbable
53 * context to the callee...
55 * There are cases when nesting handlers is exactly what we want:
58 * There are cases when we probably want to drop duplicate signals
59 * on the floor if they arrive before the previous one has been handled.
62 * There are cases when we probably want to handle duplicate signals
63 * after the previous handler has returned, not before. Eg. SIGALARM.
67 #define MAX_INTERRUPTS 1024
69 union interrupt_handler {
71 void (*c)(int, siginfo_t*, void*);
74 extern union interrupt_handler interrupt_handlers[NSIG];
76 struct interrupt_data {
77 /* signal information for pending signal. pending_signal=0 when there
78 * is no pending signal. */
79 void (*pending_handler) (int, siginfo_t*, void*) ;
81 siginfo_t pending_info;
82 sigset_t pending_mask;
86 extern void interrupt_init(void);
87 extern void fake_foreign_function_call(os_context_t* context);
88 extern void undo_fake_foreign_function_call(os_context_t* context);
89 extern void arrange_return_to_lisp_function(os_context_t *, lispobj);
90 extern void interrupt_handle_now(int, siginfo_t*, os_context_t*);
91 extern void interrupt_handle_pending(os_context_t*);
92 extern void interrupt_internal_error(os_context_t*, boolean continuable);
93 extern boolean handle_guard_page_triggered(os_context_t *,os_vm_address_t);
94 extern boolean maybe_defer_handler(void *handler, struct interrupt_data *data,
95 int signal, siginfo_t *info,
96 os_context_t *context);
97 #if defined LISP_FEATURE_GENCGC
98 /* assembly language stub that executes trap_PendingInterrupt */
99 extern void do_pending_interrupt(void);
102 #ifdef LISP_FEATURE_SB_THREAD
103 extern void interrupt_thread_handler(int, siginfo_t*, void*);
104 extern void sig_stop_for_gc_handler(int, siginfo_t*, void*);
106 typedef void (*interrupt_handler_t)(int, siginfo_t *, void *);
107 extern void undoably_install_low_level_interrupt_handler (
109 interrupt_handler_t handler);
110 extern unsigned long install_handler(int signal,
111 interrupt_handler_t handler);
113 extern union interrupt_handler interrupt_handlers[NSIG];
115 /* Set all deferrable signals into *s. */
116 extern void sigaddset_deferrable(sigset_t *s);
117 /* Set all blockable signals into *s. */
118 extern void sigaddset_blockable(sigset_t *s);
120 extern void block_blockable_signals(void);
122 /* The void* casting here avoids having to mess with the various types
123 * of function argument lists possible for signal handlers:
124 * SA_SIGACTION handlers have one signature, and the default old-style
125 * signal(..) handlers have another, and attempting to represent them
126 * "cleanly" with union types is in fact a mess. */
127 #define ARE_SAME_HANDLER(x, y) ((void*)(x) == (void*)(y))
129 extern void handle_trap(os_context_t *context, int trap);
131 #ifndef LISP_FEATURE_WIN32
132 extern void lisp_memory_fault_error(os_context_t *context,
133 os_vm_address_t addr);