1.0.25.33: protect against recursive gcs
[sbcl.git] / src / runtime / sparc-arch.c
index f941eae..f32c06d 100644 (file)
@@ -52,7 +52,7 @@ os_vm_address_t arch_get_bad_addr(int sig, siginfo_t *code, os_context_t *contex
     if ((pc < READ_ONLY_SPACE_START ||
          pc >= READ_ONLY_SPACE_START+READ_ONLY_SPACE_SIZE) &&
         (pc < current_dynamic_space ||
-         pc >= current_dynamic_space + DYNAMIC_SPACE_SIZE)) {
+         pc >= current_dynamic_space + dynamic_space_size)) {
       return NULL;
     }
 
@@ -86,8 +86,12 @@ os_vm_address_t arch_get_bad_addr(int sig, siginfo_t *code, os_context_t *contex
 
 void arch_skip_instruction(os_context_t *context)
 {
-    ((char *) *os_context_pc_addr(context)) = ((char *) *os_context_npc_addr(context));
-    ((char *) *os_context_npc_addr(context)) += 4;
+    *os_context_pc_addr(context) = *os_context_npc_addr(context);
+    /* Note that we're doing integer arithmetic here, not pointer. So
+     * the value that the return value of os_context_npc_addr() points
+     * to will be incremented by 4, not 16.
+     */
+    *os_context_npc_addr(context) += 4;
 }
 
 unsigned char *arch_internal_error_arguments(os_context_t *context)
@@ -97,7 +101,18 @@ unsigned char *arch_internal_error_arguments(os_context_t *context)
 
 boolean arch_pseudo_atomic_atomic(os_context_t *context)
 {
-    return ((*os_context_register_addr(context,reg_ALLOC)) & 4);
+    /* FIXME: this foreign_function_call_active test is dubious at
+     * best. If a foreign call is made in a pseudo atomic section
+     * (?) or more likely a pseudo atomic section is in a foreign
+     * call then an interrupt is executed immediately. Maybe it
+     * has to do with C code not maintaining pseudo atomic
+     * properly. MG - 2005-08-10
+     *
+     * The foreign_function_call_active used to live at each call-site
+     * to arch_pseudo_atomic_atomic, but this seems clearer.
+     * --NS 2007-05-15 */
+    return (!foreign_function_call_active)
+        && ((*os_context_register_addr(context,reg_ALLOC)) & 4);
 }
 
 void arch_set_pseudo_atomic_interrupted(os_context_t *context)
@@ -105,6 +120,11 @@ void arch_set_pseudo_atomic_interrupted(os_context_t *context)
     *os_context_register_addr(context,reg_ALLOC) |=  1;
 }
 
+void arch_clear_pseudo_atomic_interrupted(os_context_t *context)
+{
+    *os_context_register_addr(context,reg_ALLOC) &= ~1;
+}
+
 unsigned int arch_install_breakpoint(void *pc)
 {
     unsigned int *ptr = (unsigned int *)pc;
@@ -198,6 +218,39 @@ static int pseudo_atomic_trap_p(os_context_t *context)
     return result;
 }
 
+void
+arch_handle_breakpoint(os_context_t *context)
+{
+    handle_breakpoint(context);
+}
+
+void
+arch_handle_fun_end_breakpoint(os_context_t *context)
+{
+    *os_context_pc_addr(context) = (int) handle_fun_end_breakpoint(context);
+    *os_context_npc_addr(context) = *os_context_pc_addr(context) + 4;
+}
+
+void
+arch_handle_after_breakpoint(os_context_t *context)
+{
+    *skipped_break_addr = trap_Breakpoint;
+    os_flush_icache(skipped_break_addr, sizeof(unsigned int));
+    skipped_break_addr = NULL;
+    *(unsigned long *) os_context_pc_addr(context) = displaced_after_inst;
+    /* context->sigmask = orig_sigmask; */
+    os_flush_icache((os_vm_address_t) os_context_pc_addr(context), sizeof(unsigned int));
+}
+
+void
+arch_handle_single_step_trap(os_context_t *context, int trap)
+{
+    unsigned int code = *((u32 *)(*os_context_pc_addr(context)));
+    int register_offset = code >> 5 & 0x1f;
+    handle_single_step_trap(context, trap, register_offset);
+    arch_skip_instruction(context);
+}
+
 static void sigill_handler(int signal, siginfo_t *siginfo, void *void_context)
 {
     os_context_t *context = arch_os_get_context(&void_context);
@@ -216,45 +269,8 @@ static void sigill_handler(int signal, siginfo_t *siginfo, void *void_context)
         unsigned int* pc = (unsigned int*) siginfo->si_addr;
 
         inst = *pc;
-        trap = inst & 0x3fffff;
-
-        switch (trap) {
-        case trap_PendingInterrupt:
-            arch_skip_instruction(context);
-            interrupt_handle_pending(context);
-            break;
-
-        case trap_Halt:
-            fake_foreign_function_call(context);
-            lose("%%primitive halt called; the party is over.\n");
-
-        case trap_Error:
-        case trap_Cerror:
-            interrupt_internal_error(signal, siginfo, context, trap == trap_Cerror);
-            break;
-
-        case trap_Breakpoint:
-            handle_breakpoint(signal, siginfo, context);
-            break;
-
-        case trap_FunEndBreakpoint:
-            *os_context_pc_addr(context) = (int) handle_fun_end_breakpoint(signal, siginfo, context);
-            *os_context_npc_addr(context) = *os_context_pc_addr(context) + 4;
-            break;
-
-        case trap_AfterBreakpoint:
-            *skipped_break_addr = trap_Breakpoint;
-            os_flush_icache(skipped_break_addr, sizeof(unsigned int));
-            skipped_break_addr = NULL;
-            *(unsigned long *) os_context_pc_addr(context) = displaced_after_inst;
-            /* context->sigmask = orig_sigmask; */
-            os_flush_icache((os_vm_address_t) os_context_pc_addr(context), sizeof(unsigned int));
-            break;
-
-        default:
-            interrupt_handle_now(signal, siginfo, context);
-            break;
-        }
+        trap = inst & 0x1f;
+        handle_trap(context,trap);
     }
     else if ((siginfo->si_code) == ILL_ILLTRP
 #ifdef LISP_FEATURE_LINUX
@@ -266,12 +282,12 @@ static void sigill_handler(int signal, siginfo_t *siginfo, void *void_context)
                to fixup up alloc-tn to remove the interrupted flag,
                skip over the trap instruction, and then handle the
                pending interrupt(s). */
-            *os_context_register_addr(context, reg_ALLOC) &= ~7;
+            arch_clear_pseudo_atomic_interrupted(context);
             arch_skip_instruction(context);
             interrupt_handle_pending(context);
         }
         else {
-            interrupt_internal_error(signal, siginfo, context, 0);
+            interrupt_internal_error(context, 0);
         }
     }
     else {
@@ -314,6 +330,8 @@ static void sigemt_handler(int signal, siginfo_t *siginfo, void *void_context)
             result = op1 - op2;
         else
             result = op1 + op2;
+        /* KLUDGE: this & ~7 is a little bit magical but basically
+           clears pseudo_atomic bits if any */
         *os_context_register_addr(context, reg_ALLOC) = result & ~7;
         arch_skip_instruction(context);
         interrupt_handle_pending(context);
@@ -322,7 +340,7 @@ static void sigemt_handler(int signal, siginfo_t *siginfo, void *void_context)
 
     if ((op1 & 3) != 0) {
         /* The first arg wan't a fixnum. */
-        interrupt_internal_error(signal, siginfo, context, 0);
+        interrupt_internal_error(context, 0);
         return;
     }
 
@@ -338,7 +356,7 @@ static void sigemt_handler(int signal, siginfo_t *siginfo, void *void_context)
 
     if ((op2 & 3) != 0) {
         /* The second arg wan't a fixnum. */
-        interrupt_internal_error(signal, siginfo, context, 0);
+        interrupt_internal_error(context, 0);
         return;
     }
 
@@ -369,48 +387,6 @@ void arch_install_interrupt_handlers()
 }
 
 \f
-extern lispobj call_into_lisp(lispobj fun, lispobj *args, int nargs);
-
-lispobj funcall0(lispobj function)
-{
-    lispobj *args = current_control_stack_pointer;
-
-    return call_into_lisp(function, args, 0);
-}
-
-lispobj funcall1(lispobj function, lispobj arg0)
-{
-    lispobj *args = current_control_stack_pointer;
-
-    current_control_stack_pointer += 1;
-    args[0] = arg0;
-
-    return call_into_lisp(function, args, 1);
-}
-
-lispobj funcall2(lispobj function, lispobj arg0, lispobj arg1)
-{
-    lispobj *args = current_control_stack_pointer;
-
-    current_control_stack_pointer += 2;
-    args[0] = arg0;
-    args[1] = arg1;
-
-    return call_into_lisp(function, args, 2);
-}
-
-lispobj funcall3(lispobj function, lispobj arg0, lispobj arg1, lispobj arg2)
-{
-    lispobj *args = current_control_stack_pointer;
-
-    current_control_stack_pointer += 3;
-    args[0] = arg0;
-    args[1] = arg1;
-    args[2] = arg2;
-
-    return call_into_lisp(function, args, 3);
-}
-
 #ifdef LISP_FEATURE_LINKAGE_TABLE
 
 /* This a naive port from CMUCL/sparc, which was mostly stolen from the