0.9.13.22:
[sbcl.git] / src / runtime / interrupt.h
1 /*
2  * This software is part of the SBCL system. See the README file for
3  * more information.
4  *
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.
10  */
11
12 #if !defined(_INCLUDE_INTERRUPT_H_)
13 #define _INCLUDE_INTERRUPT_H_
14
15 #include <signal.h>
16 #include <string.h>
17
18 /*
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))
28
29 extern void check_blockables_blocked_or_lose();
30
31 static inline void
32 sigcopyset(sigset_t *new, sigset_t *old)
33 {
34     memcpy(new, old, REAL_SIGSET_SIZE_BYTES);
35 }
36
37 /* maximum signal nesting depth
38  *
39  * Note: In CMU CL, this was 4096, but there was no explanation given,
40  * and it's hard to see why we'd need that many nested interrupts, so
41  * I've scaled it back (to 256) to see what happens. -- WHN 20000730
42
43  * Nothing happened, so let's creep it back a bit further -- dan 20030411 */
44 #define MAX_INTERRUPTS 32
45
46 union interrupt_handler {
47     lispobj lisp;
48     void (*c)(int, siginfo_t*, void*);
49 };
50
51 extern union interrupt_handler interrupt_handlers[NSIG];
52
53 struct interrupt_data {
54     /* signal information for pending signal.  pending_signal=0 when there
55      * is no pending signal. */
56     void (*pending_handler) (int, siginfo_t*, void*) ;
57     int pending_signal;
58     siginfo_t pending_info;
59     sigset_t pending_mask;
60 };
61
62
63 extern void interrupt_init();
64 extern void fake_foreign_function_call(os_context_t* context);
65 extern void undo_fake_foreign_function_call(os_context_t* context);
66 extern void arrange_return_to_lisp_function(os_context_t *, lispobj);
67 extern void interrupt_handle_now(int, siginfo_t*, void*);
68 extern void interrupt_handle_pending(os_context_t*);
69 extern void interrupt_internal_error(int, siginfo_t*, os_context_t*,
70                                      boolean continuable);
71 extern boolean handle_guard_page_triggered(os_context_t *,os_vm_address_t);
72 extern boolean interrupt_maybe_gc(int, siginfo_t*, void*);
73 extern boolean interrupt_maybe_gc_int(int, siginfo_t *, void *);
74 extern boolean maybe_defer_handler(void *handler, struct interrupt_data *data,
75                                    int signal, siginfo_t *info,
76                                    os_context_t *context);
77 #if defined LISP_FEATURE_GENCGC
78 /* assembly language stub that executes trap_PendingInterrupt */
79 extern void do_pending_interrupt(void);
80 #endif
81
82 #ifdef LISP_FEATURE_SB_THREAD
83 extern void interrupt_thread_handler(int, siginfo_t*, void*);
84 extern void sig_stop_for_gc_handler(int, siginfo_t*, void*);
85 #endif
86 extern void undoably_install_low_level_interrupt_handler (int signal,
87                                                           void
88                                                           handler(int,
89                                                                   siginfo_t*,
90                                                                   void*));
91 extern unsigned long install_handler(int signal,
92                                      void handler(int, siginfo_t*, void*));
93
94 extern union interrupt_handler interrupt_handlers[NSIG];
95
96 /* Set all deferrable signals into *s. */
97 extern void sigaddset_deferrable(sigset_t *s);
98 /* Set all blockable signals into *s. */
99 extern void sigaddset_blockable(sigset_t *s);
100
101 extern void block_blockable_signals();
102
103 /* The void* casting here avoids having to mess with the various types
104  * of function argument lists possible for signal handlers:
105  * SA_SIGACTION handlers have one signature, and the default old-style
106  * signal(..) handlers have another, and attempting to represent them
107  * "cleanly" with union types is in fact a mess. */
108 #define ARE_SAME_HANDLER(x, y) ((void*)(x) == (void*)(y))
109
110 #endif