#include "ikarus.h" #include #include #include #include #include #include #include #include #include void register_handlers(); void register_alt_stack(); ikpcb* the_pcb; /* get_option takes pointers to argc and argv and looks for the first option matching opt. If one exists, it removes it from the argv list, updates argc, and returns a pointer to the option value. returns null if option is not found. */ char* get_option(char* opt, int argc, char** argv){ int i; for(i=1; i 0){ char* s = argv[i]; int n = strlen(s); ikp str = ik_alloc(pcb, align(n+disp_string_data+1)); ref(str, disp_string_length) = fix(n); strcpy((char*)str+disp_string_data, s); ikp p = ik_alloc(pcb, pair_size); ref(p, disp_car) = str + string_tag; ref(p, disp_cdr) = arg_list; arg_list = p+pair_tag; i--; } pcb->arg_list = arg_list; } register_handlers(); register_alt_stack(); ik_fasl_load(pcb, boot_file); /* fprintf(stderr, "collect time: %d.%03d utime, %d.%03d stime (%d collections)\n", pcb->collect_utime.tv_sec, pcb->collect_utime.tv_usec/1000, pcb->collect_stime.tv_sec, pcb->collect_stime.tv_usec/1000, pcb->collection_id ); */ ik_delete_pcb(pcb); return 0; } #if 0 #include struct sigaction { union { void (*__sa_handler)(int); void (*__sa_sigaction)(int, struct __siginfo *, void *); } __sigaction_u; /* signal handler */ int sa_flags; /* see signal options below */ sigset_t sa_mask; /* signal mask to apply */ }; #define sa_handler __sigaction_u.__sa_handler #define sa_sigaction __sigaction_u.__sa_sigaction int sigaction(int sig, const struct sigaction * restrict act, struct sigaction * restrict oact); #endif void handler(int signo, struct __siginfo* info, ucontext_t* uap){ the_pcb->engine_counter = 1; the_pcb->interrupted = 1; } void register_handlers(){ struct sigaction sa; sa.sa_sigaction = (void(*)(int,struct __siginfo*,void*)) handler; sa.sa_flags = SA_SIGINFO | SA_ONSTACK; sa.sa_mask = 0; int err = sigaction(SIGINT, &sa, 0); if(err){ fprintf(stderr, "Sigaction Failed: %s\n", strerror(errno)); exit(-1); } } #if 0 SYNOPSIS #include #include struct sigaltstack { char *ss_sp; int ss_size; int ss_flags; }; int sigaltstack(const struct sigaltstack *ss, struct sigaltstack *oss); #endif void register_alt_stack(){ char* stk = ik_mmap(SIGSTKSZ); if(stk == 0){ fprintf(stderr, "Cannot maloc an alt stack\n"); exit(-1); } struct sigaltstack sa; sa.ss_sp = stk; sa.ss_size = SIGSTKSZ; sa.ss_flags = 0; int err = sigaltstack(&sa, 0); if(err){ fprintf(stderr, "Cannot set alt stack: %s\n", strerror(errno)); exit(-1); } }