0.8.0.54:
[sbcl.git] / src / runtime / purify.c
index e061156..642dea9 100644 (file)
 #include <sys/types.h>
 #include <stdlib.h>
 #include <strings.h>
+#if (defined(LISP_FEATURE_SB_THREAD) && defined(LISP_FEATURE_LINUX))
 #include <sys/ptrace.h>
 #include <linux/user.h>
+#endif
 #include <errno.h>
 
 #include "runtime.h"
@@ -43,6 +45,7 @@
  */
 static lispobj *dynamic_space_free_pointer;
 #endif
+extern unsigned long bytes_consed_between_gcs;
 
 #define gc_abort() \
   lose("GC invariant lost, file \"%s\", line %d", __FILE__, __LINE__)
@@ -130,17 +133,11 @@ dynamic_pointer_p(lispobj ptr)
 
 static unsigned pointer_filter_verbose = 0;
 
-/* FIXME: This is substantially the same code as in gencgc.c. (There
- * are some differences, at least (1) the gencgc.c code needs to worry
- * about return addresses on the stack pinning code objects, (2) the
- * gencgc.c code needs to worry about the GC maybe happening in an
- * interrupt service routine when the main thread of control was
- * interrupted just as it had allocated memory and before it
- * initialized it, while PURIFY needn't worry about that, and (3) the
- * gencgc.c code has mutated more under maintenance since the fork
- * from CMU CL than the code here has.) The two versions should be
- * made to explicitly share common code, instead of just two different
- * cut-and-pasted versions. */
+/* FIXME: This is substantially the same code as
+ * possibly_valid_dynamic_space_pointer in gencgc.c.  The only
+ * relevant difference seems to be that the gencgc code also checks
+ * for raw pointers into Code objects */
+
 static int
 valid_dynamic_space_pointer(lispobj *pointer, lispobj *start_addr)
 {
@@ -1061,7 +1058,7 @@ pscav_code(struct code*code)
         gc_assert(!dynamic_pointer_p(func));
 
 #ifdef __i386__
-       /* Temporarly convert the self pointer to a real function
+       /* Temporarily convert the self pointer to a real function
         * pointer. */
        ((struct simple_fun *)native_pointer(func))->self
            -= FUN_RAW_ADDR_OFFSET;
@@ -1339,11 +1336,12 @@ purify(lispobj static_roots, lispobj read_only_roots)
     fflush(stdout);
 #endif
 
+#if (defined(LISP_FEATURE_GENCGC) && defined(LISP_FEATURE_X86))
 #if 0
-    /* can't do this unless the threads in question are suspended with
-     * ptrace
+    /* This is what we should do, but can't unless the threads in
+     * question are suspended with ptrace.  That's right, purify is not
+     * threadsafe
      */
-#if (defined(LISP_FEATURE_GENCGC) && defined(LISP_FEATURE_X86))
     for_each_thread(thread) {
        void **ptr;
        struct user_regs_struct regs;
@@ -1352,16 +1350,13 @@ purify(lispobj static_roots, lispobj read_only_roots)
            lose("PTRACE_GETREGS");
        }
        setup_i386_stack_scav(regs.ebp,
-                             ((void *)thread->control_stack_start)
-                             +THREAD_CONTROL_STACK_SIZE);
+                             ((void *)thread->control_stack_end));
     }
-#endif
-#endif
+#endif /* 0 */
+    /* stopgap until we can set things up as in preceding comment */
     setup_i386_stack_scav(((&static_roots)-2),
-                         ((void *)all_threads->control_stack_start)
-                         +THREAD_CONTROL_STACK_SIZE);
-
-
+                         ((void *)all_threads->control_stack_end));
+#endif
 
     pscav(&static_roots, 1, 0);
     pscav(&read_only_roots, 1, 1);
@@ -1380,8 +1375,9 @@ purify(lispobj static_roots, lispobj read_only_roots)
     fflush(stdout);
 #endif
 #ifndef __i386__
-    pscav((lispobj *)CONTROL_STACK_START,
-         current_control_stack_pointer - (lispobj *)CONTROL_STACK_START,
+    pscav((lispobj *)all_threads->control_stack_start,
+         current_control_stack_pointer - 
+         all_threads->control_stack_start,
          0);
 #else
 #ifdef LISP_FEATURE_GENCGC
@@ -1394,8 +1390,9 @@ purify(lispobj static_roots, lispobj read_only_roots)
     fflush(stdout);
 #endif
 #if !defined(__i386__)
-    pscav( (lispobj *)BINDING_STACK_START,
-         (lispobj *)current_binding_stack_pointer - (lispobj *)BINDING_STACK_START,
+    pscav( (lispobj *)all_threads->binding_stack_start,
+         (lispobj *)current_binding_stack_pointer -
+          all_threads->binding_stack_start,
          0);
 #else
     for_each_thread(thread) {
@@ -1474,10 +1471,9 @@ purify(lispobj static_roots, lispobj read_only_roots)
      * calling SCRUB-CONTROL-STACK - this zeros the stack on the x86. */
 #ifndef __i386__
     os_zero((os_vm_address_t) current_control_stack_pointer,
-            (os_vm_size_t) (CONTROL_STACK_SIZE -
-                            ((current_control_stack_pointer -
-                             (lispobj *)CONTROL_STACK_START) *
-                             sizeof(lispobj))));
+            (os_vm_size_t)
+           ((all_threads->control_stack_end -
+             current_control_stack_pointer) * sizeof(lispobj)));
 #endif
 
     /* It helps to update the heap free pointers so that free_heap can
@@ -1487,6 +1483,7 @@ purify(lispobj static_roots, lispobj read_only_roots)
 
 #if !defined(__i386__)
     dynamic_space_free_pointer = current_dynamic_space;
+    set_auto_gc_trigger(bytes_consed_between_gcs);
 #else
 #if defined LISP_FEATURE_GENCGC
     gc_free_heap();
@@ -1499,6 +1496,5 @@ purify(lispobj static_roots, lispobj read_only_roots)
     printf(" done]\n");
     fflush(stdout);
 #endif
-
     return 0;
 }