void critical_error(const char* msg, cell tagged) { print_string("You have triggered a bug in Factor. Please report.\n"); print_string("critical_error: "); print_string(msg); print_string(": "); print_cell_hex(tagged); nl(); factorbug(); }
void factor_vm::start_factor(vm_parameters *p) { if(p->fep) factorbug(); nest_stacks(); c_to_factor_toplevel(special_objects[OBJ_STARTUP_QUOT]); unnest_stacks(); }
void factorvm::start_factor(vm_parameters *p) { if(p->fep) factorbug(); nest_stacks(); c_to_factor_toplevel(userenv[BOOT_ENV]); unnest_stacks(); }
void factor_vm::start_standalone_factor(int argc, vm_char** argv) { vm_parameters p; p.init_from_args(argc, argv); init_factor(&p); pass_args_to_factor(argc, argv); if (p.fep) factorbug(); c_to_factor_toplevel(special_objects[OBJ_STARTUP_QUOT]); }
/* Allocates memory */ void factor_vm::general_error(vm_error_type error, cell arg1_, cell arg2_) { data_root<object> arg1(arg1_, this); data_root<object> arg2(arg2_, this); faulting_p = true; /* If we had an underflow or overflow, data or retain stack pointers might be out of bounds, so fix them before allocating anything */ ctx->fix_stacks(); /* If error was thrown during heap scan, we re-enable the GC */ gc_off = false; /* If the error handler is set, we rewind any C stack frames and pass the error to user-space. */ if (!current_gc && to_boolean(special_objects[ERROR_HANDLER_QUOT])) { #ifdef FACTOR_DEBUG /* Doing a GC here triggers all kinds of funny errors */ primitive_compact_gc(); #endif /* Now its safe to allocate and GC */ cell error_object = allot_array_4(tag_fixnum(KERNEL_ERROR), tag_fixnum(error), arg1.value(), arg2.value()); ctx->push(error_object); /* Clear the data roots since arg1 and arg2's destructors won't be called. */ data_roots.clear(); /* The unwind-native-frames subprimitive will clear faulting_p if it was successfully reached. */ unwind_native_frames(special_objects[ERROR_HANDLER_QUOT], ctx->callstack_top); } /* Error was thrown in early startup before error handler is set, so just crash. */ else { std::cout << "You have triggered a bug in Factor. Please report.\n"; std::cout << "error: " << error << std::endl; std::cout << "arg 1: "; print_obj(std::cout, arg1.value()); std::cout << std::endl; std::cout << "arg 2: "; print_obj(std::cout, arg2.value()); std::cout << std::endl; factorbug(); abort(); } }
void throw_error(cell error, stack_frame *callstack_top) { /* If the error handler is set, we rewind any C stack frames and pass the error to user-space. */ if(userenv[BREAK_ENV] != F) { /* If error was thrown during heap scan, we re-enable the GC */ gc_off = false; /* Reset local roots */ gc_locals = gc_locals_region->start - sizeof(cell); gc_bignums = gc_bignums_region->start - sizeof(cell); /* If we had an underflow or overflow, stack pointers might be out of bounds */ fix_stacks(); dpush(error); /* Errors thrown from C code pass NULL for this parameter. Errors thrown from Factor code, or signal handlers, pass the actual stack pointer at the time, since the saved pointer is not necessarily up to date at that point. */ if(callstack_top) { callstack_top = fix_callstack_top(callstack_top, stack_chain->callstack_bottom); } else callstack_top = stack_chain->callstack_top; throw_impl(userenv[BREAK_ENV],callstack_top); } /* Error was thrown in early startup before error handler is set, just crash. */ else { print_string("You have triggered a bug in Factor. Please report.\n"); print_string("early_error: "); print_obj(error); nl(); factorbug(); } }
void factor_vm::throw_error(cell error, stack_frame *callstack_top) { /* If the error handler is set, we rewind any C stack frames and pass the error to user-space. */ if(!current_gc && to_boolean(special_objects[OBJ_BREAK])) { /* If error was thrown during heap scan, we re-enable the GC */ gc_off = false; /* Reset local roots */ data_roots.clear(); bignum_roots.clear(); code_roots.clear(); /* If we had an underflow or overflow, stack pointers might be out of bounds */ fix_stacks(); dpush(error); /* Errors thrown from C code pass NULL for this parameter. Errors thrown from Factor code, or signal handlers, pass the actual stack pointer at the time, since the saved pointer is not necessarily up to date at that point. */ if(callstack_top) callstack_top = fix_callstack_top(callstack_top,ctx->callstack_bottom); else callstack_top = ctx->callstack_top; throw_impl(special_objects[OBJ_BREAK],callstack_top,this); } /* Error was thrown in early startup before error handler is set, just crash. */ else { std::cout << "You have triggered a bug in Factor. Please report.\n"; std::cout << "early_error: "; print_obj(error); std::cout << std::endl; factorbug(); } }
void init_factor_from_args(F_CHAR *image, int argc, F_CHAR **argv, bool embedded) { F_PARAMETERS p; default_parameters(&p); if(image) p.image = image; CELL i; posix_argc = argc; posix_argv = safe_malloc(argc * sizeof(F_CHAR*)); posix_argv[0] = safe_strdup(argv[0]); for(i = 1; i < argc; i++) { posix_argv[i] = safe_strdup(argv[i]); if(factor_arg(argv[i],STR_FORMAT("-datastack=%d"),&p.ds_size)); else if(factor_arg(argv[i],STR_FORMAT("-retainstack=%d"),&p.rs_size)); else if(factor_arg(argv[i],STR_FORMAT("-generations=%d"),&p.gen_count)); else if(factor_arg(argv[i],STR_FORMAT("-young=%d"),&p.young_size)); else if(factor_arg(argv[i],STR_FORMAT("-aging=%d"),&p.aging_size)); else if(factor_arg(argv[i],STR_FORMAT("-tenured=%d"),&p.tenured_size)); else if(factor_arg(argv[i],STR_FORMAT("-codeheap=%d"),&p.code_size)); else if(STRCMP(argv[i],STR_FORMAT("-securegc")) == 0) p.secure_gc = true; else if(STRCMP(argv[i],STR_FORMAT("-fep")) == 0) p.fep = true; else if(STRNCMP(argv[i],STR_FORMAT("-i="),3) == 0) p.image = argv[i] + 3; else if(STRCMP(argv[i],STR_FORMAT("-console")) == 0) p.console = true; else if(STRCMP(argv[i],STR_FORMAT("-no-stack-traces")) == 0) p.stack_traces = false; } init_factor(&p); nest_stacks(); F_ARRAY *args = allot_array(ARRAY_TYPE,argc,F); for(i = 1; i < argc; i++) { REGISTER_UNTAGGED(args); CELL arg = tag_object(from_native_string(argv[i])); UNREGISTER_UNTAGGED(args); set_array_nth(args,i,arg); } userenv[ARGS_ENV] = tag_object(args); const F_CHAR *executable_path = vm_executable_path(); if(!executable_path) executable_path = argv[0]; userenv[EXECUTABLE_ENV] = tag_object(from_native_string(executable_path)); userenv[EMBEDDED_ENV] = (embedded ? T : F); if(p.fep) factorbug(); c_to_factor_toplevel(userenv[BOOT_ENV]); unnest_stacks(); for(i = 0; i < argc; i++) free(posix_argv[i]); free(posix_argv); }