/** * add an mtree into an existing tree * * @param[in] parent handle to the parent to be added to * @param[in] h handle to the tree to add in * @returns handle of newly added (sub) tree * * this function is destructive in that the task is accomplished by copying * the values from the tree at h, and then freeing it. * */ H _m_add(H parent,H h) { L *pl,*l; H r; int x = _m_children(parent)+1; int i,levels = h.m->levels; H p = parent; Mindex d = parent.a.i; for (i=0;i<levels;i++) { __m_new_init(p,&r,&pl); l = _GET_LEVEL(h,i); N *np = __m_add_nodes(r,pl,l->nodes); N *n = &l->nP[0]; Mindex j = l->nodes; while (j--) { *np = *n; if (np->parenti == NULL_ADDR) np->parenti = 0; np->parenti += d; np++; n++; } d = pl->nodes-l->nodes; p.a.l++; } r.a = _m_child(parent,x); __m_free(h,0); //free h but not it's surfaces which were copied into the parent return r; }
/** * 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); }