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 extern void get_current_sigmask(sigset_t
*sigset
);
20 /* Set all deferrable signals into *s. */
21 extern void sigaddset_deferrable(sigset_t
*s
);
22 /* Set all blockable signals into *s. */
23 extern void sigaddset_blockable(sigset_t
*s
);
24 /* Set all gc signals into *s. */
25 extern void sigaddset_gc(sigset_t
*s
);
27 extern sigset_t deferrable_sigset
;
28 extern sigset_t blockable_sigset
;
29 extern sigset_t gc_sigset
;
31 extern boolean
deferrables_blocked_p(sigset_t
*sigset
);
32 extern boolean
blockables_blocked_p(sigset_t
*sigset
);
33 extern boolean
gc_signals_blocked_p(sigset_t
*sigset
);
35 extern void check_deferrables_blocked_or_lose(sigset_t
*sigset
);
36 extern void check_blockables_blocked_or_lose(sigset_t
*sigset
);
37 extern void check_gc_signals_blocked_or_lose(sigset_t
*sigset
);
39 extern void check_deferrables_unblocked_or_lose(sigset_t
*sigset
);
40 extern void check_blockables_unblocked_or_lose(sigset_t
*sigset
);
41 extern void check_gc_signals_unblocked_or_lose(sigset_t
*sigset
);
43 extern void block_deferrable_signals(sigset_t
*where
, sigset_t
*old
);
44 extern void block_blockable_signals(sigset_t
*where
, sigset_t
*old
);
45 extern void block_gc_signals(sigset_t
*where
, sigset_t
*old
);
47 extern void unblock_deferrable_signals(sigset_t
*where
, sigset_t
*old
);
48 extern void unblock_blockable_signals(sigset_t
*where
, sigset_t
*old
);
49 extern void unblock_gc_signals(sigset_t
*where
, sigset_t
*old
);
51 extern void maybe_save_gc_mask_and_block_deferrables(sigset_t
*sigset
);
53 /* maximum signal nesting depth
55 * FIXME: In CMUCL this was 4096, and it was first scaled down to 256
56 * and then 32, until finally Stumpwm broke: it is possible to receive
57 * interrupts in sufficiently quick succession that handler nesting
58 * can become preposterous. Scaling this back up to 1024 is a bandaid:
59 * for a real fix we should consider the following things:
61 * We should almost certainly always use
62 * arrange_return_to_lisp_function, though it needs to be thought
63 * about arguments, and it needs to be able to pass a frobbable
64 * context to the callee...
66 * There are cases when nesting handlers is exactly what we want:
69 * There are cases when we probably want to drop duplicate signals
70 * on the floor if they arrive before the previous one has been handled.
73 * There are cases when we probably want to handle duplicate signals
74 * after the previous handler has returned, not before. Eg. SIGALARM.
78 /* No longer defined here, but in 'compiler/generic/parms.lisp' due to
79 requirement that Lisp skip this many words when assigning thread-local
81 // #define MAX_INTERRUPTS 1024
83 union interrupt_handler
{
85 void (*c
)(int, siginfo_t
*, os_context_t
*);
88 extern union interrupt_handler interrupt_handlers
[NSIG
];
90 struct interrupt_data
{
91 /* signal information for pending signal. pending_signal=0 when there
92 * is no pending signal. */
93 void (*pending_handler
) (int, siginfo_t
*, os_context_t
*) ;
95 siginfo_t pending_info
;
96 sigset_t pending_mask
;
97 /* Was pending mask saved for gc request? True if GC_PENDING or
98 * SIG_STOP_FOR_GC happened in a pseudo atomic with GC_INHIBIT NIL
99 * and with no pending handler. Both deferrable interrupt handlers
100 * and gc are careful not to clobber each other's pending_mask. */
101 boolean gc_blocked_deferrables
;
102 #ifdef GENCGC_IS_PRECISE
103 /* On PPC when consing wants to turn to alloc(), it does so via a
104 * trap. When alloc() wants to save the sigmask it consults
105 * allocation_trap_context. It does not look up the most recent
106 * context, because alloc() can be called from other places
108 os_context_t
*allocation_trap_context
;
112 typedef lispobj (*call_into_lisp_lookalike
)(
113 lispobj fun
, lispobj
*args
, int nargs
);
115 extern boolean
interrupt_handler_pending_p(void);
116 extern void interrupt_init(void);
117 extern void fake_foreign_function_call(os_context_t
* context
);
118 extern void undo_fake_foreign_function_call(os_context_t
* context
);
119 extern void arrange_return_to_c_function(
120 os_context_t
*, call_into_lisp_lookalike
, lispobj
);
121 extern void arrange_return_to_lisp_function(os_context_t
*, lispobj
);
122 extern void interrupt_handle_now(int, siginfo_t
*, os_context_t
*);
123 extern void interrupt_handle_pending(os_context_t
*);
124 extern void interrupt_internal_error(os_context_t
*, boolean continuable
);
125 extern boolean
handle_guard_page_triggered(os_context_t
*,os_vm_address_t
);
126 extern boolean
maybe_defer_handler(void *handler
, struct interrupt_data
*data
,
127 int signal
, siginfo_t
*info
,
128 os_context_t
*context
);
129 #if defined LISP_FEATURE_GENCGC
130 /* assembly language stub that executes trap_PendingInterrupt */
131 extern void do_pending_interrupt(void);
134 #ifdef LISP_FEATURE_SB_THREAD
135 extern void sig_stop_for_gc_handler(int, siginfo_t
*, os_context_t
*);
137 typedef void (*interrupt_handler_t
)(int, siginfo_t
*, os_context_t
*);
138 extern void undoably_install_low_level_interrupt_handler (
140 interrupt_handler_t handler
);
141 extern uword_t
install_handler(int signal
,
142 interrupt_handler_t handler
,
145 /* The void* casting here avoids having to mess with the various types
146 * of function argument lists possible for signal handlers:
147 * SA_SIGACTION handlers have one signature, and the default old-style
148 * signal(..) handlers have another, and attempting to represent them
149 * "cleanly" with union types is in fact a mess. */
150 #define ARE_SAME_HANDLER(x, y) ((void*)(x) == (void*)(y))
152 extern void handle_trap(os_context_t
*context
, int trap
);
154 #ifndef LISP_FEATURE_WIN32
155 extern void lisp_memory_fault_error(os_context_t
*context
,
156 os_vm_address_t addr
);
161 extern void lower_thread_control_stack_guard_page(struct thread
*th
);
162 extern void reset_thread_control_stack_guard_page(struct thread
*th
);
164 #if defined(LISP_FEATURE_SB_SAFEPOINT) && !defined(LISP_FEATURE_WIN32)
165 # ifdef LISP_FEATURE_SB_THRUPTION
166 void thruption_handler(int signal
, siginfo_t
*info
, os_context_t
*context
);