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)
32 /* Reset local roots before allocating anything */
37 /* If we had an underflow or overflow, data or retain stack
38 pointers might be out of bounds, so fix them before allocating
42 /* If error was thrown during heap scan, we re-enable the GC */
45 /* If the error handler is set, we rewind any C stack frames and
46 pass the error to user-space. */
47 if(!current_gc && to_boolean(special_objects[ERROR_HANDLER_QUOT]))
50 /* Doing a GC here triggers all kinds of funny errors */
51 primitive_compact_gc();
54 /* Now its safe to allocate and GC */
55 cell error_object = allot_array_4(special_objects[OBJ_ERROR],
56 tag_fixnum(error),arg1,arg2);
58 ctx->push(error_object);
60 unwind_native_frames(special_objects[ERROR_HANDLER_QUOT],
63 /* Error was thrown in early startup before error handler is set, just
67 std::cout << "You have triggered a bug in Factor. Please report.\n";
68 std::cout << "error: " << error << std::endl;
69 std::cout << "arg 1: "; print_obj(arg1); std::cout << std::endl;
70 std::cout << "arg 2: "; print_obj(arg2); std::cout << std::endl;
75 void factor_vm::type_error(cell type, cell tagged)
77 general_error(ERROR_TYPE,tag_fixnum(type),tagged);
80 void factor_vm::not_implemented_error()
82 general_error(ERROR_NOT_IMPLEMENTED,false_object,false_object);
85 void factor_vm::memory_protection_error(cell addr)
87 if(code->safepoint_p(addr))
89 else if(ctx->datastack_seg->underflow_p(addr))
90 general_error(ERROR_DATASTACK_UNDERFLOW,false_object,false_object);
91 else if(ctx->datastack_seg->overflow_p(addr))
92 general_error(ERROR_DATASTACK_OVERFLOW,false_object,false_object);
93 else if(ctx->retainstack_seg->underflow_p(addr))
94 general_error(ERROR_RETAINSTACK_UNDERFLOW,false_object,false_object);
95 else if(ctx->retainstack_seg->overflow_p(addr))
96 general_error(ERROR_RETAINSTACK_OVERFLOW,false_object,false_object);
97 else if(ctx->callstack_seg->underflow_p(addr))
98 general_error(ERROR_CALLSTACK_OVERFLOW,false_object,false_object);
99 else if(ctx->callstack_seg->overflow_p(addr))
100 general_error(ERROR_CALLSTACK_UNDERFLOW,false_object,false_object);
101 else if(ctx->callstack_seg->canary_p(addr))
102 fatal_error("Call stack overflow in your call stack overflow", addr);
104 general_error(ERROR_MEMORY,from_unsigned_cell(addr),false_object);
107 void factor_vm::signal_error(cell signal)
109 general_error(ERROR_SIGNAL,from_unsigned_cell(signal),false_object);
112 void factor_vm::divide_by_zero_error()
114 general_error(ERROR_DIVIDE_BY_ZERO,false_object,false_object);
117 void factor_vm::fp_trap_error(unsigned int fpu_status)
119 general_error(ERROR_FP_TRAP,tag_fixnum(fpu_status),false_object);
122 /* For testing purposes */
123 void factor_vm::primitive_unimplemented()
125 not_implemented_error();
128 void factor_vm::memory_signal_handler_impl()
130 memory_protection_error(signal_fault_addr);
133 void memory_signal_handler_impl()
135 current_vm()->memory_signal_handler_impl();
138 void factor_vm::synchronous_signal_handler_impl()
140 signal_error(signal_number);
143 void synchronous_signal_handler_impl()
145 current_vm()->synchronous_signal_handler_impl();
148 void factor_vm::fp_signal_handler_impl()
150 /* Clear pending exceptions to avoid getting stuck in a loop */
151 set_fpu_state(get_fpu_state());
153 fp_trap_error(signal_fpu_status);
156 void fp_signal_handler_impl()
158 current_vm()->fp_signal_handler_impl();
161 void factor_vm::enqueue_safepoint_fep()
164 fatal_error("Low-level debugger interrupted", 0);
165 safepoint_fep = true;
166 code->guard_safepoint();
169 void factor_vm::enqueue_safepoint_signal(cell signal)
171 sigaddset(&safepoint_signals, signal);
172 code->guard_safepoint();
175 void factor_vm::enqueue_safepoint_sample()
178 fatal_error("Received sampling signal while not sampling!", 0);
179 ++safepoint_sample_count;
182 void factor_vm::handle_safepoint()
184 if (signal_from_leaf)
185 std::cout << "XXX SIGNALED FROM LEAF\n";
187 code->unguard_safepoint();
189 std::cout << "Interrupted\n";
191 safepoint_fep = false;
194 // XXX handle sample count
195 // XXX handle queued signals