]> gitweb.factorcode.org Git - factor.git/commitdiff
Revert "VM: always clear the data and retainstack in general_error because they might...
authorJohn Benediktsson <mrjbq7@gmail.com>
Thu, 4 Dec 2014 19:45:13 +0000 (11:45 -0800)
committerJohn Benediktsson <mrjbq7@gmail.com>
Thu, 4 Dec 2014 19:46:28 +0000 (11:46 -0800)
This reverts commit 378f2080251cae3b52fe28e466438af25b5004a4.

vm/contexts.cpp
vm/contexts.hpp
vm/errors.cpp

index dfab8d53ff30bce47a383cc595e0ac235d2f9696..41133e0839cf2254549a82825b98a65bc11077f5 100644 (file)
@@ -39,6 +39,16 @@ void context::reset() {
   reset_context_objects();
 }
 
+void context::fix_stacks() {
+  if (datastack + sizeof(cell) < datastack_seg->start ||
+      datastack + stack_reserved >= datastack_seg->end)
+    reset_datastack();
+
+  if (retainstack + sizeof(cell) < retainstack_seg->start ||
+      retainstack + stack_reserved >= retainstack_seg->end)
+    reset_retainstack();
+}
+
 context::~context() {
   delete datastack_seg;
   delete retainstack_seg;
index 45c0c5c236b4e686366e57380842d8fc5cf6860c..62d6f26833b318536a67f5c2bf36019ac4ec4be5 100644 (file)
@@ -47,6 +47,7 @@ struct context {
   void reset_callstack();
   void reset_context_objects();
   void reset();
+  void fix_stacks();
   void scrub_stacks(gc_info* info, cell index);
 
   cell peek() { return *(cell*)datastack; }
index 4360961f2fccd25d6dd0d61f48b20346882317a2..0e27d9938aefc8d01e1df68d41b75d15c46edcf2 100644 (file)
@@ -44,19 +44,17 @@ void factor_vm::general_error(vm_error_type error, cell arg1_, cell arg2_) {
 
   faulting_p = true;
 
-  /* If we had an underflow or overflow, data or retain stack pointers
-     might be out of bounds, or some of their slots might be
-     uninitialized, so reset them before allocating anything. */
-  ctx->reset_datastack();
-  ctx->reset_retainstack();
+  /* If we had an underflow or overflow, data or retain stack
+     pointers might be out of bounds, so fix them before allocating
+     anything */
+  ctx->fix_stacks();
 
   /* If error was thrown during heap scan, we re-enable the GC */
   gc_off = false;
 
-  cell error_handler = special_objects[ERROR_HANDLER_QUOT];
   /* If the error handler is set, we rewind any C stack frames and
      pass the error to user-space. */
-  if (!current_gc && to_boolean(error_handler)) {
+  if (!current_gc && to_boolean(special_objects[ERROR_HANDLER_QUOT])) {
 #ifdef FACTOR_DEBUG
     /* Doing a GC here triggers all kinds of funny errors */
     primitive_compact_gc();
@@ -74,7 +72,8 @@ void factor_vm::general_error(vm_error_type error, cell arg1_, cell arg2_) {
 
     /* The unwind-native-frames subprimitive will clear faulting_p
        if it was successfully reached. */
-    unwind_native_frames(error_handler, ctx->callstack_top);
+    unwind_native_frames(special_objects[ERROR_HANDLER_QUOT],
+                         ctx->callstack_top);
   } /* Error was thrown in early startup before error handler is set, so just
        crash. */
   else {