1.0.25.23: more allocation checks
[sbcl.git] / src / runtime / interrupt.h
index 0b6fb7b..579eeb6 100644 (file)
@@ -13,6 +13,7 @@
 #define _INCLUDE_INTERRUPT_H_
 
 #include <signal.h>
+#include <string.h>
 
 /*
  * This is a workaround for some slightly silly Linux/GNU Libc
 /* FIXME: do not rely on NSIG being a multiple of 8 */
 #define REAL_SIGSET_SIZE_BYTES ((NSIG/8))
 
+extern sigset_t deferrable_sigset;
+extern sigset_t blockable_sigset;
+
+extern void check_deferrables_blocked_or_lose(void);
+extern void check_blockables_blocked_or_lose(void);
+extern void check_gc_signals_unblocked_or_lose(void);
+extern void unblock_gc_signals(void);
+
 static inline void
 sigcopyset(sigset_t *new, sigset_t *old)
 {
@@ -33,22 +42,39 @@ sigcopyset(sigset_t *new, sigset_t *old)
 
 /* maximum signal nesting depth
  *
- * Note: In CMU CL, this was 4096, but there was no explanation given,
- * and it's hard to see why we'd need that many nested interrupts, so
- * I've scaled it back (to 256) to see what happens. -- WHN 20000730
-
- * Nothing happened, so let's creep it back a bit further -- dan 20030411 */
-#define MAX_INTERRUPTS 32
+ * FIXME: In CMUCL this was 4096, and it was first scaled down to 256
+ * and then 32, until finally Stumpwm broke: it is possible to receive
+ * interrupts in sufficiently quick succession that handler nesting
+ * can become preposterous. Scaling this back up to 1024 is a bandaid:
+ * for a real fix we should consider the following things:
+ *
+ *   We should almost certainly always use
+ *   arrange_return_to_lisp_function, though it needs to be thought
+ *   about arguments, and it needs to be able to pass a frobbable
+ *   context to the callee...
+ *
+ *   There are cases when nesting handlers is exactly what we want:
+ *   eg. SIGINT.
+ *
+ *   There are cases when we probably want to drop duplicate signals
+ *   on the floor if they arrive before the previous one has been handled.
+ *   Eg. SIGPROF.
+ *
+ *   There are cases when we probably want to handle duplicate signals
+ *   after the previous handler has returned, not before. Eg. SIGALARM.
+ *
+ * -- NS 2007-01-29
+ */
+#define MAX_INTERRUPTS 1024
 
 union interrupt_handler {
     lispobj lisp;
     void (*c)(int, siginfo_t*, void*);
 };
 
-struct interrupt_data {
-    void (*interrupt_low_level_handlers[NSIG]) (int, siginfo_t*, void*) ;
-    union interrupt_handler interrupt_handlers[NSIG];
+extern union interrupt_handler interrupt_handlers[NSIG];
 
+struct interrupt_data {
     /* signal information for pending signal.  pending_signal=0 when there
      * is no pending signal. */
     void (*pending_handler) (int, siginfo_t*, void*) ;
@@ -58,17 +84,14 @@ struct interrupt_data {
 };
 
 
-extern void interrupt_init();
+extern void interrupt_init(void);
 extern void fake_foreign_function_call(os_context_t* context);
 extern void undo_fake_foreign_function_call(os_context_t* context);
 extern void arrange_return_to_lisp_function(os_context_t *, lispobj);
-extern void interrupt_handle_now(int, siginfo_t*, void*);
+extern void interrupt_handle_now(int, siginfo_t*, os_context_t*);
 extern void interrupt_handle_pending(os_context_t*);
-extern void interrupt_internal_error(int, siginfo_t*, os_context_t*,
-                                     boolean continuable);
+extern void interrupt_internal_error(os_context_t*, boolean continuable);
 extern boolean handle_guard_page_triggered(os_context_t *,os_vm_address_t);
-extern boolean interrupt_maybe_gc(int, siginfo_t*, void*);
-extern boolean interrupt_maybe_gc_int(int, siginfo_t *, void *);
 extern boolean maybe_defer_handler(void *handler, struct interrupt_data *data,
                                    int signal, siginfo_t *info,
                                    os_context_t *context);
@@ -81,22 +104,21 @@ extern void do_pending_interrupt(void);
 extern void interrupt_thread_handler(int, siginfo_t*, void*);
 extern void sig_stop_for_gc_handler(int, siginfo_t*, void*);
 #endif
-extern void undoably_install_low_level_interrupt_handler (int signal,
-                                                          void
-                                                          handler(int,
-                                                                  siginfo_t*,
-                                                                  void*));
+typedef void (*interrupt_handler_t)(int, siginfo_t *, void *);
+extern void undoably_install_low_level_interrupt_handler (
+                        int signal,
+                        interrupt_handler_t handler);
 extern unsigned long install_handler(int signal,
-                                     void handler(int, siginfo_t*, void*));
+                                     interrupt_handler_t handler);
 
 extern union interrupt_handler interrupt_handlers[NSIG];
 
 /* Set all deferrable signals into *s. */
-void sigaddset_deferrable(sigset_t *s);
+extern void sigaddset_deferrable(sigset_t *s);
 /* Set all blockable signals into *s. */
-void sigaddset_blockable(sigset_t *s);
+extern void sigaddset_blockable(sigset_t *s);
 
-extern void block_blockable_signals();
+extern void block_blockable_signals(void);
 
 /* The void* casting here avoids having to mess with the various types
  * of function argument lists possible for signal handlers:
@@ -105,4 +127,11 @@ extern void block_blockable_signals();
  * "cleanly" with union types is in fact a mess. */
 #define ARE_SAME_HANDLER(x, y) ((void*)(x) == (void*)(y))
 
+extern void handle_trap(os_context_t *context, int trap);
+
+#ifndef LISP_FEATURE_WIN32
+extern void lisp_memory_fault_error(os_context_t *context,
+                                    os_vm_address_t addr);
+#endif
+
 #endif