5 bool factor_vm::fatal_erroring_p;
7 static inline void fa_diddly_atal_error() {
8 printf("fatal_error in fatal_error!\n");
13 void fatal_error(const char* msg, cell tagged) {
14 if (factor_vm::fatal_erroring_p)
15 fa_diddly_atal_error();
17 factor_vm::fatal_erroring_p = true;
19 std::cout << "fatal_error: " << msg;
20 std::cout << ": " << (void*)tagged;
21 std::cout << std::endl << std::endl;
22 factor_vm* vm = current_vm();
24 vm->dump_memory_layout(std::cout);
29 void critical_error(const char* msg, cell tagged) {
30 std::cout << "You have triggered a bug in Factor. Please report.\n";
31 std::cout << "critical_error: " << msg;
32 std::cout << ": " << std::hex << tagged << std::dec;
33 std::cout << std::endl;
34 current_vm()->factorbug();
38 void factor_vm::general_error(vm_error_type error, cell arg1_, cell arg2_) {
40 data_root<object> arg1(arg1_, this);
41 data_root<object> arg2(arg2_, this);
45 // If we had an underflow or overflow, data or retain stack
46 // pointers might be out of bounds, so fix them before allocating
50 // If error was thrown during heap scan, we re-enable the GC
53 // If the error handler is set, we rewind any C stack frames and
54 // pass the error to user-space.
55 if (!current_gc && to_boolean(special_objects[ERROR_HANDLER_QUOT])) {
57 // Doing a GC here triggers all kinds of funny errors
58 primitive_compact_gc();
61 // Now its safe to allocate and GC
63 allot_array_4(tag_fixnum(KERNEL_ERROR), tag_fixnum(error),
64 arg1.value(), arg2.value());
65 ctx->push(error_object);
67 // Clear the data roots since arg1 and arg2's destructors won't be
71 // The unwind-native-frames subprimitive will clear faulting_p
72 // if it was successfully reached.
73 unwind_native_frames(special_objects[ERROR_HANDLER_QUOT],
75 } // Error was thrown in early startup before error handler is set, so just
78 std::cout << "You have triggered a bug in Factor. Please report.\n";
79 std::cout << "error: " << error << std::endl;
80 std::cout << "arg 1: ";
81 print_obj(std::cout, arg1.value());
82 std::cout << std::endl;
83 std::cout << "arg 2: ";
84 print_obj(std::cout, arg2.value());
85 std::cout << std::endl;
92 void factor_vm::type_error(cell type, cell tagged) {
93 general_error(ERROR_TYPE, tag_fixnum(type), tagged);
97 void factor_vm::not_implemented_error() {
98 general_error(ERROR_NOT_IMPLEMENTED, false_object, false_object);
101 void factor_vm::set_memory_protection_error(cell fault_addr, cell fault_pc) {
102 // Called from the OS-specific top halves of the signal handlers to
103 // make sure it's safe to dispatch to memory_signal_handler_impl.
104 if (fatal_erroring_p)
105 fa_diddly_atal_error();
106 if (faulting_p && !code->safepoint_p(fault_addr))
107 fatal_error("Double fault", fault_addr);
109 fatal_error("Memory protection fault during low-level debugger", fault_addr);
110 else if (atomic::load(¤t_gc_p))
111 fatal_error("Memory protection fault during gc", fault_addr);
112 signal_fault_addr = fault_addr;
113 signal_fault_pc = fault_pc;
117 void factor_vm::divide_by_zero_error() {
118 general_error(ERROR_DIVIDE_BY_ZERO, false_object, false_object);
121 // For testing purposes
123 void factor_vm::primitive_unimplemented() { not_implemented_error(); }
126 void memory_signal_handler_impl() {
127 factor_vm* vm = current_vm();
128 if (vm->code->safepoint_p(vm->signal_fault_addr)) {
129 vm->handle_safepoint(vm->signal_fault_pc);
132 vm_error_type type = vm->ctx->address_to_error(vm->signal_fault_addr);
133 cell number = vm->from_unsigned_cell(vm->signal_fault_addr);
134 vm->general_error(type, number, false_object);
136 if (!vm->signal_resumable) {
137 // In theory we should only get here if the callstack overflowed during a
139 vm->general_error(ERROR_CALLSTACK_OVERFLOW, false_object, false_object);
144 void synchronous_signal_handler_impl() {
145 factor_vm* vm = current_vm();
146 vm->general_error(ERROR_SIGNAL,
147 vm->from_unsigned_cell(vm->signal_number),
152 void fp_signal_handler_impl() {
153 factor_vm* vm = current_vm();
155 // Clear pending exceptions to avoid getting stuck in a loop
156 vm->set_fpu_state(vm->get_fpu_state());
158 vm->general_error(ERROR_FP_TRAP,
159 tag_fixnum(vm->signal_fpu_status),