6 bool factor_vm::fatal_erroring_p;
8 static inline void fa_diddly_atal_error()
10 printf("fatal_error in fatal_error!\n");
15 void fatal_error(const char *msg, cell tagged)
17 if (factor_vm::fatal_erroring_p)
18 fa_diddly_atal_error();
20 factor_vm::fatal_erroring_p = true;
22 std::cout << "fatal_error: " << msg;
23 std::cout << ": " << (void*)tagged;
24 std::cout << std::endl;
28 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();
39 std::cout << "Out of memory\n\n";
40 current_vm()->dump_generations();
44 void factor_vm::general_error(vm_error_type error, cell arg1_, cell arg2_)
48 /* Reset local roots before allocating anything */
53 data_root<object> arg1(arg1_,this);
54 data_root<object> arg2(arg2_,this);
56 /* If we had an underflow or overflow, data or retain stack
57 pointers might be out of bounds, so fix them before allocating
61 /* If error was thrown during heap scan, we re-enable the GC */
64 /* If the error handler is set, we rewind any C stack frames and
65 pass the error to user-space. */
66 if(!current_gc && to_boolean(special_objects[ERROR_HANDLER_QUOT]))
69 /* Doing a GC here triggers all kinds of funny errors */
70 primitive_compact_gc();
73 /* Now its safe to allocate and GC */
74 cell error_object = allot_array_4(special_objects[OBJ_ERROR],
75 tag_fixnum(error),arg1.value(),arg2.value());
77 ctx->push(error_object);
79 /* The unwind-native-frames subprimitive will clear faulting_p
80 if it was successfully reached. */
81 unwind_native_frames(special_objects[ERROR_HANDLER_QUOT],
84 /* Error was thrown in early startup before error handler is set, so just
88 std::cout << "You have triggered a bug in Factor. Please report.\n";
89 std::cout << "error: " << error << std::endl;
90 std::cout << "arg 1: "; print_obj(arg1.value()); std::cout << std::endl;
91 std::cout << "arg 2: "; print_obj(arg2.value()); std::cout << std::endl;
97 void factor_vm::type_error(cell type, cell tagged)
99 general_error(ERROR_TYPE,tag_fixnum(type),tagged);
102 void factor_vm::not_implemented_error()
104 general_error(ERROR_NOT_IMPLEMENTED,false_object,false_object);
107 void factor_vm::verify_memory_protection_error(cell addr)
109 /* Called from the OS-specific top halves of the signal handlers to
110 make sure it's safe to dispatch to memory_protection_error */
112 fa_diddly_atal_error();
113 if(faulting_p && !code->safepoint_p(addr))
114 fatal_error("Double fault", addr);
116 fatal_error("Memory protection fault during low-level debugger", addr);
117 else if(atomic::load(¤t_gc_p))
118 fatal_error("Memory protection fault during gc", addr);
121 void factor_vm::memory_protection_error(cell pc, cell addr)
123 if(code->safepoint_p(addr))
124 safepoint.handle_safepoint(this, pc);
125 else if(ctx->datastack_seg->underflow_p(addr))
126 general_error(ERROR_DATASTACK_UNDERFLOW,false_object,false_object);
127 else if(ctx->datastack_seg->overflow_p(addr))
128 general_error(ERROR_DATASTACK_OVERFLOW,false_object,false_object);
129 else if(ctx->retainstack_seg->underflow_p(addr))
130 general_error(ERROR_RETAINSTACK_UNDERFLOW,false_object,false_object);
131 else if(ctx->retainstack_seg->overflow_p(addr))
132 general_error(ERROR_RETAINSTACK_OVERFLOW,false_object,false_object);
133 else if(ctx->callstack_seg->underflow_p(addr))
134 general_error(ERROR_CALLSTACK_OVERFLOW,false_object,false_object);
135 else if(ctx->callstack_seg->overflow_p(addr))
136 general_error(ERROR_CALLSTACK_UNDERFLOW,false_object,false_object);
138 general_error(ERROR_MEMORY,from_unsigned_cell(addr),false_object);
141 void factor_vm::signal_error(cell signal)
143 general_error(ERROR_SIGNAL,from_unsigned_cell(signal),false_object);
146 void factor_vm::divide_by_zero_error()
148 general_error(ERROR_DIVIDE_BY_ZERO,false_object,false_object);
151 void factor_vm::fp_trap_error(unsigned int fpu_status)
153 general_error(ERROR_FP_TRAP,tag_fixnum(fpu_status),false_object);
156 /* For testing purposes */
157 void factor_vm::primitive_unimplemented()
159 not_implemented_error();
162 void factor_vm::memory_signal_handler_impl()
164 memory_protection_error(signal_fault_pc, signal_fault_addr);
165 if (!signal_resumable)
167 /* In theory we should only get here if the callstack overflowed during a
169 general_error(ERROR_CALLSTACK_OVERFLOW,false_object,false_object);
173 void memory_signal_handler_impl()
175 current_vm()->memory_signal_handler_impl();
178 void factor_vm::synchronous_signal_handler_impl()
180 signal_error(signal_number);
183 void synchronous_signal_handler_impl()
185 current_vm()->synchronous_signal_handler_impl();
188 void factor_vm::fp_signal_handler_impl()
190 /* Clear pending exceptions to avoid getting stuck in a loop */
191 set_fpu_state(get_fpu_state());
193 fp_trap_error(signal_fpu_status);
196 void fp_signal_handler_impl()
198 current_vm()->fp_signal_handler_impl();