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);
96 void factor_vm::set_memory_protection_error(cell fault_addr, cell fault_pc) {
97 // Called from the OS-specific top halves of the signal handlers to
98 // make sure it's safe to dispatch to memory_signal_handler_impl.
100 fa_diddly_atal_error();
101 if (faulting_p && !code->safepoint_p(fault_addr))
102 fatal_error("Double fault", fault_addr);
104 fatal_error("Memory protection fault during low-level debugger", fault_addr);
105 else if (atomic::load(¤t_gc_p))
106 fatal_error("Memory protection fault during gc", fault_addr);
107 signal_fault_addr = fault_addr;
108 signal_fault_pc = fault_pc;
112 void factor_vm::divide_by_zero_error() {
113 general_error(ERROR_DIVIDE_BY_ZERO, false_object, false_object);
117 void memory_signal_handler_impl() {
118 factor_vm* vm = current_vm();
119 if (vm->code->safepoint_p(vm->signal_fault_addr)) {
120 vm->handle_safepoint(vm->signal_fault_pc);
123 vm_error_type type = vm->ctx->address_to_error(vm->signal_fault_addr);
124 cell number = vm->from_unsigned_cell(vm->signal_fault_addr);
125 vm->general_error(type, number, false_object);
127 if (!vm->signal_resumable) {
128 // In theory we should only get here if the callstack overflowed during a
130 vm->general_error(ERROR_CALLSTACK_OVERFLOW, false_object, false_object);
135 void synchronous_signal_handler_impl() {
136 factor_vm* vm = current_vm();
137 vm->general_error(ERROR_SIGNAL,
138 vm->from_unsigned_cell(vm->signal_number),
143 void fp_signal_handler_impl() {
144 factor_vm* vm = current_vm();
146 // Clear pending exceptions to avoid getting stuck in a loop
147 vm->set_fpu_state(vm->get_fpu_state());
149 vm->general_error(ERROR_FP_TRAP,
150 tag_fixnum(vm->signal_fpu_status),