/* * FIXME: to make this predictable (avoid memory allocation in the * must-be-predictable case, we should really cos_vect_add_id when we * first find out about the possibility of the thread making any * invocations. */ static struct blocked_thds *bt_get(unsigned short int tid) { struct blocked_thds *bt; bt = cos_vect_lookup(&bthds, tid); if (NULL == bt) { bt = malloc(sizeof(struct blocked_thds)); if (NULL == bt) return NULL; INIT_LIST(bt, next, prev); bt->thd_id = tid; if (tid != cos_vect_add_id(&bthds, bt, tid)) return NULL; } return bt; }
static int add_thd_map(unsigned short int ucid, rb_meta_t *rbm) { struct thd_map *tm; tm = malloc(sizeof(struct thd_map)); if (NULL == tm) return -1; tm->uc_rb = rbm; if (0 > cos_vect_add_id(&tmap, tm, ucid)) { free(tm); return -1; } return 0; }
/* * FIXME: to make this predictable (avoid memory allocation in the * must-be-predictable case, we should really cos_vect_add_id when we * first find out about the possibility of the thread making any * invocations. */ static struct thread_event *__te_get(unsigned short int tid, cos_vect_t *v) { struct thread_event *te; te = cos_vect_lookup(v, tid); if (NULL == te) { te = malloc(sizeof(struct thread_event)); if (NULL == te) return NULL; memset(te, 0, sizeof(struct thread_event)); te->thread_id = tid; INIT_LIST(te, next, prev); if (tid != cos_vect_add_id(v, te, tid)) return NULL; } return te; }
static int __valloc_init(spdid_t spdid) { int ret = -1; struct spd_vas_tracker *trac; struct spd_vas_occupied *occ; struct cos_component_information *ci; unsigned long page_off; void *hp; if (cos_vect_lookup(&spd_vect, spdid)) goto success; trac = malloc(sizeof(struct spd_vas_tracker)); if (!trac) goto done; occ = alloc_page(); if (!occ) goto err_free1; ci = cos_get_vas_page(); if (cinfo_map(cos_spd_id(), (vaddr_t)ci, spdid)) goto err_free2; hp = (void*)ci->cos_heap_ptr; // printc("valloc init heap_ptr: %x\n", (unsigned int) hp); trac->spdid = spdid; trac->ci = ci; trac->map = occ; trac->extents[0].start = (void*)round_to_pgd_page(hp); trac->extents[0].end = (void*)round_up_to_pgd_page(hp); page_off = ((unsigned long)hp - (unsigned long)round_to_pgd_page(hp))/PAGE_SIZE; bitmap_set_contig(&occ->pgd_occupied[0], page_off, (PGD_SIZE/PAGE_SIZE)-page_off, 1); cos_vect_add_id(&spd_vect, trac, spdid); assert(cos_vect_lookup(&spd_vect, spdid)); success: // printc("valloc init success\n"); ret = 0; done: return ret; err_free2: cos_release_vas_page(ci); free_page(occ); err_free1: free(trac); goto done; }
static void boot_symb_process(struct cobj_header *h, spdid_t spdid, vaddr_t heap_val, char *mem, vaddr_t d_addr, vaddr_t symb_addr) { if (round_to_page(symb_addr) == d_addr) { struct cos_component_information *ci; ci = (struct cos_component_information*)(mem + ((PAGE_SIZE-1) & symb_addr)); // ci->cos_heap_alloc_extent = ci->cos_heap_ptr; // ci->cos_heap_allocated = heap_val; if (!ci->cos_heap_ptr) ci->cos_heap_ptr = heap_val; ci->cos_this_spd_id = spdid; /* save the address of this page for later retrieval * (e.g. to manipulate the stack pointer) */ if (!cos_vect_lookup(&spd_info_addresses, spdid)) { boot_spd_set_symbs(h, spdid, ci); cos_vect_add_id(&spd_info_addresses, (void*)round_to_page(ci), spdid); } } }
static int __valloc_init(spdid_t spdid) { int ret = -1; struct spd_vas_tracker *trac; struct spd_vas_occupied *occ; unsigned long page_off; void *hp; if (cos_vect_lookup(&spd_vect, spdid)) goto success; trac = malloc(sizeof(struct spd_vas_tracker)); if (!trac) goto done; occ = alloc_page(); if (!occ) goto err_free1; hp = cinfo_get_heap_pointer(cos_spd_id(), spdid); if (!hp) goto err_free2; trac->spdid = spdid; trac->map = occ; trac->extents[0].start = (void*)round_to_pgd_page(hp); trac->extents[0].end = (void*)round_up_to_pgd_page(hp); trac->extents[0].map = occ; page_off = ((unsigned long)hp - (unsigned long)round_to_pgd_page(hp))/PAGE_SIZE; bitmap_set_contig(&occ->pgd_occupied[0], page_off, (PGD_SIZE/PAGE_SIZE)-page_off, 1); bitmap_set_contig(&occ->pgd_occupied[0], 0, page_off, 0); cos_vect_add_id(&spd_vect, trac, spdid); assert(cos_vect_lookup(&spd_vect, spdid)); success: ret = 0; done: return ret; err_free2: free_page(occ); err_free1: free(trac); goto done; }