Utility predicates for packing: UNBOUNDED-SC-P and UNBOUNDED-TN-P
[sbcl.git] / src / runtime / x86-64-arch.c
index 0612ce9..573dc7e 100644 (file)
 #define BREAKPOINT_WIDTH 2
 #endif
 
-unsigned long fast_random_state = 1;
-
 void arch_init(void)
 {}
 
+#ifndef _WIN64
 os_vm_address_t
 arch_get_bad_addr(int sig, siginfo_t *code, os_context_t *context)
 {
     return (os_vm_address_t)code->si_addr;
 }
+#endif
 
 \f
 /*
@@ -76,6 +76,8 @@ context_eflags_addr(os_context_t *context)
     return &context->sc_rflags;
 #elif defined __NetBSD__
     return CONTEXT_ADDR_FROM_STEM(RFLAGS);
+#elif defined _WIN64
+    return (os_context_register_t*)&context->win32_context->EFlags;
 #else
 #error unsupported OS
 #endif
@@ -110,6 +112,10 @@ void arch_skip_instruction(os_context_t *context)
         case trap_FunEndBreakpoint: /* not tested */
             break;
 
+#ifdef LISP_FEATURE_SB_SAFEPOINT
+        case trap_GlobalSafepoint:
+        case trap_CspSafepoint:
+#endif
         case trap_PendingInterrupt:
         case trap_Halt:
         case trap_SingleStepAround:
@@ -233,7 +239,7 @@ arch_handle_fun_end_breakpoint(os_context_t *context)
 {
     *os_context_pc_addr(context) -= BREAKPOINT_WIDTH;
     *os_context_pc_addr(context) =
-        (unsigned long)handle_fun_end_breakpoint(context);
+        (uword_t)handle_fun_end_breakpoint(context);
 }
 
 void
@@ -247,36 +253,43 @@ arch_handle_single_step_trap(os_context_t *context, int trap)
 
 \f
 void
-sigtrap_handler(int signal, siginfo_t *info, os_context_t *context)
+restore_breakpoint_from_single_step(os_context_t * context)
 {
-    unsigned int trap;
-
-    if (single_stepping) {
 #ifdef CANNOT_GET_TO_SINGLE_STEP_FLAG
-        /* Un-install single step helper instructions. */
-        *(single_stepping-3) = single_step_save1;
-        *(single_stepping-2) = single_step_save2;
-        *(single_stepping-1) = single_step_save3;
+    /* Un-install single step helper instructions. */
+    *(single_stepping-3) = single_step_save1;
+    *(single_stepping-2) = single_step_save2;
+    *(single_stepping-1) = single_step_save3;
 #else
-        *context_eflags_addr(context) ^= 0x100;
+    *context_eflags_addr(context) &= ~0x100;
 #endif
-        /* Re-install the breakpoint if possible. */
-        if (((char *)*os_context_pc_addr(context) >
-             (char *)single_stepping) &&
-            ((char *)*os_context_pc_addr(context) <=
-             (char *)single_stepping + BREAKPOINT_WIDTH)) {
-            fprintf(stderr, "warning: couldn't reinstall breakpoint\n");
-        } else {
-            arch_install_breakpoint(single_stepping);
-        }
+    /* Re-install the breakpoint if possible. */
+    if (((char *)*os_context_pc_addr(context) >
+         (char *)single_stepping) &&
+        ((char *)*os_context_pc_addr(context) <=
+         (char *)single_stepping + BREAKPOINT_WIDTH)) {
+        fprintf(stderr, "warning: couldn't reinstall breakpoint\n");
+    } else {
+        arch_install_breakpoint(single_stepping);
+    }
 
-        single_stepping = NULL;
+    single_stepping = NULL;
+    return;
+}
+
+void
+sigtrap_handler(int signal, siginfo_t *info, os_context_t *context)
+{
+    unsigned int trap;
+
+    if (single_stepping) {
+        restore_breakpoint_from_single_step(context);
         return;
     }
 
     /* This is just for info in case the monitor wants to print an
      * approximation. */
-    current_control_stack_pointer =
+    access_control_stack_pointer(arch_os_get_current_thread()) =
         (lispobj *)*os_context_sp_addr(context);
 
     /* On entry %eip points just after the INT3 byte and aims at the
@@ -368,12 +381,12 @@ arch_install_interrupt_handlers()
      * OS I haven't tested on?) and we have to go back to the old CMU
      * CL way, I hope there will at least be a comment to explain
      * why.. -- WHN 2001-06-07 */
-#if !defined(LISP_FEATURE_MACH_EXCEPTION_HANDLER)
+#if !defined(LISP_FEATURE_MACH_EXCEPTION_HANDLER) && !defined(LISP_FEATURE_WIN32)
     undoably_install_low_level_interrupt_handler(SIGILL , sigill_handler);
     undoably_install_low_level_interrupt_handler(SIGTRAP, sigtrap_handler);
 #endif
 
-#ifdef X86_64_SIGFPE_FIXUP
+#if defined(X86_64_SIGFPE_FIXUP) && !defined(LISP_FEATURE_WIN32)
     undoably_install_low_level_interrupt_handler(SIGFPE, sigfpe_handler);
 #endif
 
@@ -388,7 +401,7 @@ arch_install_interrupt_handlers()
 void
 arch_write_linkage_table_jmp(char * reloc, void * fun)
 {
-    unsigned long addr = (unsigned long) fun;
+    uword_t addr = (uword_t) fun;
     int i;
 
     *reloc++ = 0xFF; /* Opcode for near jump to absolute reg/mem64. */
@@ -410,7 +423,7 @@ arch_write_linkage_table_jmp(char * reloc, void * fun)
 void
 arch_write_linkage_table_ref(void * reloc, void * data)
 {
-    *(unsigned long *)reloc = (unsigned long)data;
+    *(uword_t *)reloc = (uword_t)data;
 }
 
 #endif