Exemplo n.º 1
0
void buffer_init (TBuffer *buf, size_t sz, lua_State *L, TFreeList *fl) {
  void *ud;
  lua_Alloc lalloc = lua_getallocf(L, &ud);
  buf->arr = (char*) lalloc (ud, NULL, 0, sz);
  if (!buf->arr) {
    freelist_free (fl);
    luaL_error (L, "malloc failed");
  }
  buf->size = sz;
  buf->top = 0;
  buf->L = L;
  buf->freelist = fl;
  freelist_add (fl, buf);
}
Exemplo n.º 2
0
static int
stkmgr_stack_find_home(struct cos_stk_item *csi, struct spd_stk_info *prev)
{
	struct spd_stk_info *dest;

	assert(EMPTY_LIST(csi, next, prev));
	dest = stkmgr_find_spd_requiring_stk();
	if (!dest) {
		freelist_add(csi);
	} else {
		assert(SPD_HAS_BLK_THD(dest));
		stkmgr_stk_add_to_spd(csi, dest);
		spd_freelist_add(dest->spdid, csi);
		spd_wake_threads(dest->spdid);
	}
	return 0;
}
Exemplo n.º 3
0
uint32_t parse_codepoint( char const *s ) {
  assert( s );

  if ( s[0] && !s[1] )                  // assume single-char ASCII
    return (uint32_t)s[0];

  char const *const s0 = s;
  if ( (s[0] == 'U' || s[0] == 'u') && s[1] == '+' ) {
    // convert [uU]+NNNN to 0xNNNN so strtoull() will grok it
    char *const t = freelist_add( check_strdup( s ) );
    s = memcpy( t, "0x", 2 );
  }
  uint64_t const codepoint = parse_ull( s );
  if ( codepoint_is_valid( codepoint ) )
    return (uint32_t)codepoint;         
  PMESSAGE_EXIT( USAGE,
    "\"%s\": invalid Unicode code-point for -%c\n",
    s0, 'U'
  );
}
Exemplo n.º 4
0
/**
 * cos_init
 */
void 
cos_init(void *arg){
	int i;
	struct cos_stk_item *stk_item;

	DOUT("<stkmgr>: STACK in cos_init\n");
   
	memset(spd_stk_info_list, 0, sizeof(struct spd_stk_info) * MAX_NUM_SPDS);
    
	for(i = 0; i < MAX_NUM_SPDS; i++){
		spd_stk_info_list[i].spdid = i;    
		INIT_LIST(&spd_stk_info_list[i].stk_list, next, prev);
		INIT_LIST(&spd_stk_info_list[i].bthd_list, next, prev);
	}

	// Initialize our free stack list
	for(i = 0; i < MAX_NUM_STACKS; i++){
        
		// put stk list is some known state
		stk_item = &(all_stk_list[i]);
		stk_item->stk  = NULL;
		INIT_LIST(stk_item, next, prev);
        
		// allocate a page
		stk_item->hptr = alloc_page();
		if (stk_item->hptr == NULL){
			DOUT("<stk_mgr>: ERROR, could not allocate stack\n"); 
		} else {
			// figure out or location of the top of the stack
			stk_item->stk = (struct cos_stk *)D_COS_STK_ADDR((char *)stk_item->hptr);
			freelist_add(stk_item);
		}
	}
	stacks_allocated = 0;

	// Map all of the spds we can into this component
	for (i = 0 ; i < MAX_NUM_SPDS ; i++) {
		spdid_t spdid;
		void *hp;

		hp = cos_get_vas_page();
		spdid = cinfo_get_spdid(i);
		if (!spdid) break;

		if(cinfo_map(cos_spd_id(), (vaddr_t)hp, spdid)){
			DOUT("Could not map cinfo page for %d\n", spdid);
			BUG();
		}
		spd_stk_info_list[spdid].ci = hp; 
        
		DOUT("mapped -- id: %ld, hp:%x, sp:%x\n",
		     spd_stk_info_list[spdid].ci->cos_this_spd_id, 
		     (unsigned int)spd_stk_info_list[spdid].ci->cos_heap_ptr,
		     (unsigned int)spd_stk_info_list[spdid].ci->cos_stacks.freelists[0].freelist);
    
		stacks_target += DEFAULT_TARGET_ALLOC;
		spd_stk_info_list[spdid].num_allocated = 0;
		spd_stk_info_list[spdid].num_desired = DEFAULT_TARGET_ALLOC;
	}

	LOCK_INIT();
	
	DOUT("Done mapping components information pages!\n");
	DOUT("<stkmgr>: init finished\n");
	return;
}