/** * @brief Creates a new virtual machine host * * allocates all the memory needed in the heap * * @returns pointer to a newly allocated VMHost * <b>Examples (from test suite):</b> * @snippet spec/vmhost_spec.h testVMHostCreate */ VMHost * _v_new() { SemTable *sem = _sem_new(); base_contexts(sem); base_defs(sem); Receptor *r = _r_new(sem,SYS_RECEPTOR); VMHost *v = __v_init(r,sem); r = _r_new(sem,COMPOSITORY); _v_new_receptor(v,v->r,COMPOSITORY,r); r = _r_new(sem,DEV_COMPOSITORY); _v_new_receptor(v,v->r,DEV_COMPOSITORY,r); r = _r_new(sem,TEST_RECEPTOR); _v_new_receptor(v,v->r,TEST_RECEPTOR,r); _r_defineClockReceptor(sem); return v; }
/** * bootstrap the ceptr system * * starts up the vmhost and wakes up receptors that should be running in it. * * @TODO check the compository to verify our version of the vmhost * */ void _a_boot(char *dir_path) { // check if the storage directory exists struct stat st = {0}; if (stat(dir_path, &st) == -1) { // if no directory we are firing up an initial instance, so // create directory mkdir(dir_path,0700); // instantiate a VMHost object G_vm = _v_new(); // create the basic receptors that all VMHosts have _v_instantiate_builtins(G_vm); } else { char fn[1000]; void *buffer; // unserialize the semtable base tree SemTable *sem = _sem_new(); T *t = __a_unserializet(dir_path,SEM_FN); sem->stores[0].definitions = t; // restore definitions to the correct store slots T *paths = __a_unserializet(dir_path,PATHS_FN); int i = 0; int c = _t_children(paths); for(i=1;i<=c;i++) { T *p = _t_child(paths,i); if (semeq(RECEPTOR_PATH,_t_symbol(p))) { T *x = _t_get(t,(int *)_t_surface(p)); sem->stores[i-1].definitions = x; } } _t_free(paths); sem->contexts = c+1; // unserialize all of the vmhost's instantiated receptors and other instances __a_vmfn(fn,dir_path); buffer = readFile(fn,0); Receptor *r = _r_unserialize(sem,buffer); G_vm = __v_init(r,sem); free(buffer); // unserialize other vmhost state data S *s; __a_vm_state_fn(fn,dir_path); s = readFile(fn,0); H h = _m_unserialize(s); free(s); H hars; hars.m=h.m; hars.a = _m_child(h,1); // first child is ACTIVE_RECEPTORS H har; har.m=h.m; int j = _m_children(hars); for (i=1;i<=j;i++) { har.a = _m_child(hars,i); if(!semeq(_m_symbol(har),RECEPTOR_XADDR)) raise_error("expecting RECEPTOR_XADDR!"); _v_activate(G_vm,*(Xaddr *)_m_surface(har)); } _m_free(h); } G_vm->dir = dir_path; // _a_check_vm_host_version_on_the_compository(); _v_start_vmhost(G_vm); }