6 void fatal_error(const char *msg, cell tagged)
8 std::cout << "fatal_error: " << msg;
9 std::cout << ": " << std::hex << tagged << std::dec;
10 std::cout << std::endl;
14 void critical_error(const char *msg, cell tagged)
16 std::cout << "You have triggered a bug in Factor. Please report.\n";
17 std::cout << "critical_error: " << msg;
18 std::cout << ": " << std::hex << tagged << std::dec;
19 std::cout << std::endl;
20 current_vm()->factorbug();
25 std::cout << "Out of memory\n\n";
26 current_vm()->dump_generations();
30 void factor_vm::general_error(vm_error_type error, cell arg1, cell arg2)
34 /* Reset local roots before allocating anything */
39 /* If we had an underflow or overflow, data or retain stack
40 pointers might be out of bounds, so fix them before allocating
44 /* If error was thrown during heap scan, we re-enable the GC */
47 /* If the error handler is set, we rewind any C stack frames and
48 pass the error to user-space. */
49 if(!current_gc && to_boolean(special_objects[ERROR_HANDLER_QUOT]))
52 /* Doing a GC here triggers all kinds of funny errors */
53 primitive_compact_gc();
56 /* Now its safe to allocate and GC */
57 cell error_object = allot_array_4(special_objects[OBJ_ERROR],
58 tag_fixnum(error),arg1,arg2);
60 ctx->push(error_object);
63 unwind_native_frames(special_objects[ERROR_HANDLER_QUOT],
66 /* Error was thrown in early startup before error handler is set, just
70 std::cout << "You have triggered a bug in Factor. Please report.\n";
71 std::cout << "error: " << error << std::endl;
72 std::cout << "arg 1: "; print_obj(arg1); std::cout << std::endl;
73 std::cout << "arg 2: "; print_obj(arg2); std::cout << std::endl;
79 void factor_vm::type_error(cell type, cell tagged)
81 general_error(ERROR_TYPE,tag_fixnum(type),tagged);
84 void factor_vm::not_implemented_error()
86 general_error(ERROR_NOT_IMPLEMENTED,false_object,false_object);
89 void factor_vm::memory_protection_error(cell addr)
91 if(code->safepoint_p(addr))
92 safepoint.handle_safepoint(this);
94 fatal_error("Double fault", 0);
95 else if(ctx->datastack_seg->underflow_p(addr))
96 general_error(ERROR_DATASTACK_UNDERFLOW,false_object,false_object);
97 else if(ctx->datastack_seg->overflow_p(addr))
98 general_error(ERROR_DATASTACK_OVERFLOW,false_object,false_object);
99 else if(ctx->retainstack_seg->underflow_p(addr))
100 general_error(ERROR_RETAINSTACK_UNDERFLOW,false_object,false_object);
101 else if(ctx->retainstack_seg->overflow_p(addr))
102 general_error(ERROR_RETAINSTACK_OVERFLOW,false_object,false_object);
103 else if(ctx->callstack_seg->underflow_p(addr))
104 general_error(ERROR_CALLSTACK_OVERFLOW,false_object,false_object);
105 else if(ctx->callstack_seg->overflow_p(addr))
106 general_error(ERROR_CALLSTACK_UNDERFLOW,false_object,false_object);
108 general_error(ERROR_MEMORY,from_unsigned_cell(addr),false_object);
111 void factor_vm::signal_error(cell signal)
113 general_error(ERROR_SIGNAL,from_unsigned_cell(signal),false_object);
116 void factor_vm::divide_by_zero_error()
118 general_error(ERROR_DIVIDE_BY_ZERO,false_object,false_object);
121 void factor_vm::fp_trap_error(unsigned int fpu_status)
123 general_error(ERROR_FP_TRAP,tag_fixnum(fpu_status),false_object);
126 /* For testing purposes */
127 void factor_vm::primitive_unimplemented()
129 not_implemented_error();
132 void factor_vm::memory_signal_handler_impl()
134 memory_protection_error(signal_fault_addr);
135 if (!signal_resumable)
137 /* In theory we should only get here if the callstack overflowed during a
139 general_error(ERROR_CALLSTACK_OVERFLOW,false_object,false_object);
143 void memory_signal_handler_impl()
145 current_vm()->memory_signal_handler_impl();
148 void factor_vm::synchronous_signal_handler_impl()
150 signal_error(signal_number);
153 void synchronous_signal_handler_impl()
155 current_vm()->synchronous_signal_handler_impl();
158 void factor_vm::fp_signal_handler_impl()
160 /* Clear pending exceptions to avoid getting stuck in a loop */
161 set_fpu_state(get_fpu_state());
163 fp_trap_error(signal_fpu_status);
166 void fp_signal_handler_impl()
168 current_vm()->fp_signal_handler_impl();