]> gitweb.factorcode.org Git - factor.git/blobdiff - vm/errors.cpp
webapps.wiki: adding search bar
[factor.git] / vm / errors.cpp
index 8a223371499f3e8bfe76a657af85e8a2de548583..74ba10056c095bb1476e0e5aeaa37de025f8ff1d 100644 (file)
@@ -19,7 +19,10 @@ void fatal_error(const char* msg, cell tagged) {
   std::cout << "fatal_error: " << msg;
   std::cout << ": " << (void*)tagged;
   std::cout << std::endl << std::endl;
-  current_vm()->dump_memory_layout(std::cout);
+  factor_vm* vm = current_vm();
+  if (vm->data) {
+    vm->dump_memory_layout(std::cout);
+  }
   abort();
 }
 
@@ -31,7 +34,7 @@ void critical_error(const char* msg, cell tagged) {
   current_vm()->factorbug();
 }
 
-/* Allocates memory */
+// Allocates memory
 void factor_vm::general_error(vm_error_type error, cell arg1_, cell arg2_) {
 
   data_root<object> arg1(arg1_, this);
@@ -39,38 +42,38 @@ 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, so fix them before allocating
-     anything */
+  // 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 */
+  // If error was thrown during heap scan, we re-enable the GC
   gc_off = false;
 
-  /* If the error handler is set, we rewind any C stack frames and
-     pass the error to user-space. */
+  // If the error handler is set, we rewind any C stack frames and
+  // pass the error to user-space.
   if (!current_gc && to_boolean(special_objects[ERROR_HANDLER_QUOT])) {
 #ifdef FACTOR_DEBUG
-    /* Doing a GC here triggers all kinds of funny errors */
+    // Doing a GC here triggers all kinds of funny errors
     primitive_compact_gc();
 #endif
 
-    /* Now its safe to allocate and GC */
+    // Now its safe to allocate and GC
     cell error_object =
-        allot_array_4(special_objects[OBJ_ERROR], tag_fixnum(error),
+        allot_array_4(tag_fixnum(KERNEL_ERROR), tag_fixnum(error),
                       arg1.value(), arg2.value());
     ctx->push(error_object);
 
-    /* Clear the data roots since arg1 and arg2's destructors won't be
-       called. */
+    // Clear the data roots since arg1 and arg2's destructors won't be
+    // called.
     data_roots.clear();
 
-    /* The unwind-native-frames subprimitive will clear faulting_p
-       if it was successfully reached. */
+    // The unwind-native-frames subprimitive will clear faulting_p
+    // if it was successfully reached.
     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. */
+  } // Error was thrown in early startup before error handler is set, so just
+    // crash.
   else {
     std::cout << "You have triggered a bug in Factor. Please report.\n";
     std::cout << "error: " << error << std::endl;
@@ -85,78 +88,66 @@ void factor_vm::general_error(vm_error_type error, cell arg1_, cell arg2_) {
   }
 }
 
-/* Allocates memory */
+// Allocates memory
 void factor_vm::type_error(cell type, cell tagged) {
   general_error(ERROR_TYPE, tag_fixnum(type), tagged);
 }
 
-/* Allocates memory */
-void factor_vm::not_implemented_error() {
-  general_error(ERROR_NOT_IMPLEMENTED, false_object, false_object);
-}
-
-void factor_vm::verify_memory_protection_error(cell addr) {
-  /* Called from the OS-specific top halves of the signal handlers to
-     make sure it's safe to dispatch to memory_signal_handler_impl. */
+void factor_vm::set_memory_protection_error(cell fault_addr, cell fault_pc) {
+  // Called from the OS-specific top halves of the signal handlers to
+  // make sure it's safe to dispatch to memory_signal_handler_impl.
   if (fatal_erroring_p)
     fa_diddly_atal_error();
-  if (faulting_p && !code->safepoint_p(addr))
-    fatal_error("Double fault", addr);
+  if (faulting_p && !code->safepoint_p(fault_addr))
+    fatal_error("Double fault", fault_addr);
   else if (fep_p)
-    fatal_error("Memory protection fault during low-level debugger", addr);
+    fatal_error("Memory protection fault during low-level debugger", fault_addr);
   else if (atomic::load(&current_gc_p))
-    fatal_error("Memory protection fault during gc", addr);
+    fatal_error("Memory protection fault during gc", fault_addr);
+  signal_fault_addr = fault_addr;
+  signal_fault_pc = fault_pc;
 }
 
-/* Allocates memory */
+// Allocates memory
 void factor_vm::divide_by_zero_error() {
   general_error(ERROR_DIVIDE_BY_ZERO, false_object, false_object);
 }
 
-/* For testing purposes */
-/* Allocates memory */
-void factor_vm::primitive_unimplemented() { not_implemented_error(); }
-
-/* Allocates memory */
-void factor_vm::memory_signal_handler_impl() {
-  if (code->safepoint_p(signal_fault_addr)) {
-    safepoint.handle_safepoint(this, signal_fault_pc);
+// Allocates memory
+void memory_signal_handler_impl() {
+  factor_vm* vm = current_vm();
+  if (vm->code->safepoint_p(vm->signal_fault_addr)) {
+    vm->handle_safepoint(vm->signal_fault_pc);
   }
   else {
-    vm_error_type type = ctx->address_to_error(signal_fault_addr);
-    cell number = from_unsigned_cell(signal_fault_addr);
-    general_error(type, number, false_object);
+    vm_error_type type = vm->ctx->address_to_error(vm->signal_fault_addr);
+    cell number = vm->from_unsigned_cell(vm->signal_fault_addr);
+    vm->general_error(type, number, false_object);
   }
-  if (!signal_resumable) {
-    /* In theory we should only get here if the callstack overflowed during a
-       safepoint */
-    general_error(ERROR_CALLSTACK_OVERFLOW, false_object, false_object);
+  if (!vm->signal_resumable) {
+    // In theory we should only get here if the callstack overflowed during a
+    // safepoint
+    vm->general_error(ERROR_CALLSTACK_OVERFLOW, false_object, false_object);
   }
 }
 
-/* Allocates memory */
-void memory_signal_handler_impl() {
-  current_vm()->memory_signal_handler_impl();
-}
-
-/* Allocates memory */
-void factor_vm::synchronous_signal_handler_impl() {
-  general_error(ERROR_SIGNAL, from_unsigned_cell(signal_number), false_object);
-}
-
-/* Allocates memory */
+// Allocates memory
 void synchronous_signal_handler_impl() {
-  current_vm()->synchronous_signal_handler_impl();
+  factor_vm* vm = current_vm();
+  vm->general_error(ERROR_SIGNAL,
+                    vm->from_unsigned_cell(vm->signal_number),
+                    false_object);
 }
 
-/* Allocates memory (fp_trap_error())*/
-void factor_vm::fp_signal_handler_impl() {
-  /* Clear pending exceptions to avoid getting stuck in a loop */
-  set_fpu_state(get_fpu_state());
+// Allocates memory
+void fp_signal_handler_impl() {
+  factor_vm* vm = current_vm();
 
-  general_error(ERROR_FP_TRAP, tag_fixnum(signal_fpu_status), false_object);
-}
+  // Clear pending exceptions to avoid getting stuck in a loop
+  vm->set_fpu_state(vm->get_fpu_state());
 
-/* Allocates memory */
-void fp_signal_handler_impl() { current_vm()->fp_signal_handler_impl(); }
+  vm->general_error(ERROR_FP_TRAP,
+                    tag_fixnum(vm->signal_fpu_status),
+                    false_object);
+}
 }