1.0.0.10:
[sbcl.git] / src / runtime / bsd-os.c
index 6372c42..0fda392 100644 (file)
@@ -23,6 +23,7 @@
 #include <sys/file.h>
 #include <unistd.h>
 #include <assert.h>
+#include <errno.h>
 #include "sbcl.h"
 #include "./signal.h"
 #include "os.h"
@@ -47,6 +48,7 @@ os_vm_size_t os_vm_page_size;
 #include <sys/resource.h>
 #include <sys/sysctl.h>
 #include <string.h>
+#include <sys/stat.h> /* For the stat-family wrappers. */
 
 static void netbsd_init();
 #endif /* __NetBSD__ */
@@ -58,10 +60,6 @@ static void netbsd_init();
 static void freebsd_init();
 #endif /* __FreeBSD__ */
 
-#if defined(LISP_FEATURE_DARWIN) && defined(LISP_FEATURE_X86)
-static void x86_darwin_init();
-#endif
-
 void
 os_init(char *argv[], char *envp[])
 {
@@ -73,9 +71,6 @@ os_init(char *argv[], char *envp[])
 #ifdef __FreeBSD__
     freebsd_init();
 #endif /* __FreeBSD__ */
-#if defined(LISP_FEATURE_DARWIN) && defined(LISP_FEATURE_X86)
-    x86_darwin_init();
-#endif
 }
 
 int *os_context_pc_addr(os_context_t *context)
@@ -174,7 +169,7 @@ is_valid_lisp_addr(os_vm_address_t addr)
     struct thread *th;
     if(in_range_p(addr, READ_ONLY_SPACE_START, READ_ONLY_SPACE_SIZE) ||
        in_range_p(addr, STATIC_SPACE_START   , STATIC_SPACE_SIZE) ||
-       in_range_p(addr, DYNAMIC_SPACE_START  , DYNAMIC_SPACE_SIZE))
+       in_range_p(addr, DYNAMIC_SPACE_START  , dynamic_space_size))
         return 1;
     for_each_thread(th) {
         if((th->control_stack_start <= addr) && (addr < th->control_stack_end))
@@ -201,13 +196,14 @@ memory_fault_handler(int signal, siginfo_t *siginfo, void *void_context)
     os_context_t *context = arch_os_get_context(&void_context);
     void *fault_addr = arch_get_bad_addr(signal, siginfo, context);
 
-#if defined(MEMORY_FAULT_DEBUG)
-    fprintf(stderr, "Memory fault at: %p, PC: %x\n", fault_addr, *os_context_pc_addr(context));
-#if defined(ARCH_HAS_STACK_POINTER)
-    fprintf(stderr, "Stack pointer: %x\n", *os_context_sp_addr(context));
-#endif
+#if defined(LISP_FEATURE_RESTORE_TLS_SEGMENT_REGISTER_FROM_CONTEXT)
+    FSHOW_SIGNAL((stderr, "/ TLS: restoring fs: %p in memory_fault_handler\n",
+                  *CONTEXT_ADDR_FROM_STEM(fs)));
+    os_restore_tls_segment_register(context);
 #endif
 
+    FSHOW((stderr, "Memory fault at: %p, PC: %x\n", fault_addr, *os_context_pc_addr(context)));
+
     if (!gencgc_handle_wp_violation(fault_addr))
         if(!handle_guard_page_triggered(context,fault_addr)) {
 #ifdef LISP_FEATURE_C_STACK_IS_CONTROL_STACK
@@ -234,10 +230,22 @@ os_install_interrupt_handlers(void)
     undoably_install_low_level_interrupt_handler(SIG_MEMORY_FAULT2,
                                                  memory_fault_handler);
 #endif
+
+#ifdef LISP_FEATURE_SB_THREAD
+    undoably_install_low_level_interrupt_handler(SIG_INTERRUPT_THREAD,
+                                                 interrupt_thread_handler);
+    undoably_install_low_level_interrupt_handler(SIG_STOP_FOR_GC,
+                                                 sig_stop_for_gc_handler);
+#ifdef SIG_RESUME_FROM_GC
+    undoably_install_low_level_interrupt_handler(SIG_RESUME_FROM_GC,
+                                                 sig_stop_for_gc_handler);
+#endif
+#endif
+
     SHOW("leaving os_install_interrupt_handlers()");
 }
 
-#else /* Currently Darwin only */
+#else /* Currently PPC/Darwin/Cheney only */
 
 static void
 sigsegv_handler(int signal, siginfo_t *info, void* void_context)
@@ -304,6 +312,25 @@ The system may fail to start.\n",
                  strerror(errno));
     }
 }
+
+/* The stat() routines in NetBSD's C library are compatibility
+   wrappers for some very old version of the stat buffer structure.
+   Programs must be processed by the C toolchain in order to get an
+   up-to-date definition of the stat() routine.  These wrappers are
+   used only in sb-posix, as of 2006-10-15. -- RMK */
+int _stat(const char *path, struct stat *sb) {
+  return (stat(path, sb));
+}
+
+int _lstat(const char *path, struct stat *sb) {
+  return (lstat(path, sb));
+}
+
+int _fstat(int fd, struct stat *sb) {
+  return (fstat(fd, sb));
+}
+
+
 #endif /* __NetBSD__ */
 
 #ifdef __FreeBSD__
@@ -328,43 +355,6 @@ static void freebsd_init()
 #endif /* LISP_FEATURE_X86 */
 }
 #endif /* __FreeBSD__ */
-\f
-/* threads */
-
-/* no threading in any *BSD variant on any CPU (yet? in sbcl-0.8.0 anyway) */
-#ifdef LISP_FEATURE_SB_THREAD
-#error "Define threading support functions"
-#else
-int arch_os_thread_init(struct thread *thread) {
-  stack_t sigstack;
-#ifdef LISP_FEATURE_C_STACK_IS_CONTROL_STACK
-    /* Signal handlers are run on the control stack, so if it is exhausted
-     * we had better use an alternate stack for whatever signal tells us
-     * we've exhausted it */
-    sigstack.ss_sp=((void *) thread)+dynamic_values_bytes;
-    sigstack.ss_flags=0;
-    sigstack.ss_size = 32*SIGSTKSZ;
-    sigaltstack(&sigstack,0);
-#endif
-    return 1;                  /* success */
-}
-int arch_os_thread_cleanup(struct thread *thread) {
-    return 1;                  /* success */
-}
-#endif
-
-#if defined(LISP_FEATURE_DARWIN) && defined(LISP_FEATURE_X86)
-static void x86_darwin_init()
-{
-    struct sigaltstack sigstack;
-    sigstack.ss_sp = os_allocate(32*SIGSTKSZ);
-    if (sigstack.ss_sp) {
-        sigstack.ss_flags=0;
-        sigstack.ss_size = 32*SIGSTKSZ;
-        sigaltstack(&sigstack,0);
-    }
-}
-#endif
 
 #ifdef LISP_FEATURE_DARWIN
 /* defined in ppc-darwin-os.c instead */