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_
18 * This is a workaround for some slightly silly Linux/GNU Libc
19 * behaviour: glibc defines sigset_t to support 1024 signals, which is
20 * more than the kernel. This is usually not a problem, but becomes
21 * one when we want to save a signal mask from a ucontext, and restore
22 * it later into another ucontext: the ucontext is allocated on the
23 * stack by the kernel, so copying a libc-sized sigset_t into it will
24 * overflow and cause other data on the stack to be corrupted */
25 /* FIXME: do not rely on NSIG being a multiple of 8 */
26 #define REAL_SIGSET_SIZE_BYTES ((NSIG/8))
29 sigcopyset(sigset_t *new, sigset_t *old)
31 memcpy(new, old, REAL_SIGSET_SIZE_BYTES);
34 /* maximum signal nesting depth
36 * Note: In CMU CL, this was 4096, but there was no explanation given,
37 * and it's hard to see why we'd need that many nested interrupts, so
38 * I've scaled it back (to 256) to see what happens. -- WHN 20000730
40 * Nothing happened, so let's creep it back a bit further -- dan 20030411 */
41 #define MAX_INTERRUPTS 32
43 union interrupt_handler {
45 void (*c)(int, siginfo_t*, void*);
48 struct interrupt_data {
49 void (*interrupt_low_level_handlers[NSIG]) (int, siginfo_t*, void*) ;
50 union interrupt_handler interrupt_handlers[NSIG];
52 /* signal information for pending signal. pending_signal=0 when there
53 * is no pending signal. */
54 void (*pending_handler) (int, siginfo_t*, void*) ;
56 siginfo_t pending_info;
57 sigset_t pending_mask;
61 extern void interrupt_init();
62 extern void fake_foreign_function_call(os_context_t* context);
63 extern void undo_fake_foreign_function_call(os_context_t* context);
64 extern void arrange_return_to_lisp_function(os_context_t *, lispobj);
65 extern void interrupt_handle_now(int, siginfo_t*, void*);
66 extern void interrupt_handle_pending(os_context_t*);
67 extern void interrupt_internal_error(int, siginfo_t*, os_context_t*,
69 extern boolean handle_guard_page_triggered(os_context_t *,void *);
70 extern boolean interrupt_maybe_gc(int, siginfo_t*, void*);
71 extern boolean interrupt_maybe_gc_int(int, siginfo_t *, void *);
72 extern boolean maybe_defer_handler(void *handler, struct interrupt_data *data,
73 int signal, siginfo_t *info,
74 os_context_t *context);
75 #if defined LISP_FEATURE_GENCGC
76 /* assembly language stub that executes trap_PendingInterrupt */
77 extern void do_pending_interrupt(void);
80 #ifdef LISP_FEATURE_SB_THREAD
81 extern void interrupt_thread_handler(int, siginfo_t*, void*);
82 extern void sig_stop_for_gc_handler(int, siginfo_t*, void*);
84 extern void undoably_install_low_level_interrupt_handler (int signal,
89 extern unsigned long install_handler(int signal,
90 void handler(int, siginfo_t*, void*));
92 extern union interrupt_handler interrupt_handlers[NSIG];
94 /* Set all blockable signals into *s. */
95 void sigaddset_blockable(sigset_t *s);
97 /* The void* casting here avoids having to mess with the various types
98 * of function argument lists possible for signal handlers:
99 * SA_SIGACTION handlers have one signature, and the default old-style
100 * signal(..) handlers have another, and attempting to represent them
101 * "cleanly" with union types is in fact a mess. */
102 #define ARE_SAME_HANDLER(x, y) ((void*)(x) == (void*)(y))