Ejemplo n.º 1
0
void table_insert(table *arr, int index, const void *val) {
	if (arr->m_len == arr->m_cap) {
		int newcap;
		if (arr->m_cap == 0) {
			newcap = 8;
		} else {
			newcap = arr->m_cap * 2;
		}
		
		arr->m_data = realloc(arr->m_data, arr->m_elemSize * newcap);
		if (! arr->m_data) {
			debug_print("Not enough memory to append.\r\n");
			sys_abort();
		}
		memset(((unsigned char*)arr->m_data) + arr->m_cap*arr->m_elemSize, 0, newcap - arr->m_cap);
		arr->m_cap = newcap;
	}
	
	if (index == arr->m_len) {
		table_append(arr, val);
		return;
	}
	
	unsigned char *arrbytes = (unsigned char*) arr->m_data;
	unsigned char *target = arrbytes + arr->m_elemSize * index;
	unsigned char *next = target + arr->m_elemSize;
	memmove(next, target, (arr->m_len - index) * arr->m_elemSize);
	memmove(target, val, arr->m_elemSize);
}
Ejemplo n.º 2
0
int
st_vprintf (const char *format, va_list ap)
{
  int written;
  char buffer[ST_VPRINTF_SIZE];

#ifdef HAVE_VSNPRINTF
  written = vsnprintf(buffer, ST_VPRINTF_SIZE, format, ap);
#else
  written = vsprintf(buffer, format, ap);

  if (written >= ST_VPRINTF_SIZE - 1)
    {
      /* The error message was longer than our buffer.  Ouch.  Because
	 we may have messed up things badly, report the error and
	 quit.  */
#define ERROR_MESSAGE "Internal error: buffer overrun in st_vprintf()\n"
      write (STDERR_FILENO, buffer, ST_VPRINTF_SIZE - 1);
      write (STDERR_FILENO, ERROR_MESSAGE, strlen(ERROR_MESSAGE));
      sys_abort ();
#undef ERROR_MESSAGE

    }
#endif

  written = write (STDERR_FILENO, buffer, written);
  return written;
}
Ejemplo n.º 3
0
void table_put(table *arr, int index, const void *val) {
	if (index >= arr->m_len) {
		debug_print("Array index out of bounds.\n");
		sys_abort();
	}
	memmove(((unsigned char*) arr->m_data) + index * arr->m_elemSize, val, arr->m_elemSize);
}
Ejemplo n.º 4
0
void* table_ind(table *arr, int index) {
	if (index >= arr->m_len) {
		debug_print("Array index out of bounds.\n");
		sys_abort();
	}
	return ((unsigned char*) arr->m_data) + index * arr->m_elemSize;
}
Ejemplo n.º 5
0
const char *
gfc_itoa (GFC_INTEGER_LARGEST n, char *buffer, size_t len)
{
  int negative;
  char *p;
  GFC_UINTEGER_LARGEST t;

  if (len < GFC_ITOA_BUF_SIZE)
    sys_abort ();

  if (n == 0)
    return "0";

  negative = 0;
  t = n;
  if (n < 0)
    {
      negative = 1;
      t = -n; /*must use unsigned to protect from overflow*/
    }

  p = buffer + GFC_ITOA_BUF_SIZE - 1;
  *p = '\0';

  while (t != 0)
    {
      *--p = '0' + (t % 10);
      t /= 10;
    }

  if (negative)
    *--p = '-';
  return p;
}
Ejemplo n.º 6
0
table* table_new(size_t elemSize, int startingSize, int startingCapacity) {
	if (startingSize > startingCapacity) {
		debug_print("Array size > cap.\n");
		sys_abort();
	}
	
	table* arr = (table*) malloc(sizeof(table));
	if (! arr) {
		debug_print("Out of memory.\n");
		sys_abort();
	}
	arr->m_elemSize = elemSize;
	arr->m_len = startingSize;
	arr->m_cap = startingCapacity;
	arr->m_data = calloc(startingCapacity, elemSize);
	return arr;
}
Ejemplo n.º 7
0
void menu_set_value(menu *pMenu, const char *fmt, ...) {
	char* cText = (char*) malloc(512);
	if (! cText) {
		debug_print("Out of memory.\n");
		sys_abort();
	}
	va_list vArgs;
	va_start(vArgs, fmt);
	vsnprintf(cText, 512, fmt, vArgs);
	va_end(vArgs);
	
	table_put(pMenu->m_aValues, pMenu->m_aValues->m_len-1, &cText);
}
Ejemplo n.º 8
0
void menu_add_entry(menu *pMenu, const char *fmt, ...) {
	char* cText = (char*) malloc(512);
	if (! cText) {
		debug_print("Out of memory.\n");
		sys_abort();
	}
	va_list vArgs;
	va_start(vArgs, fmt);
	vsnprintf(cText, 512, fmt, vArgs);
	va_end(vArgs);
	
	table_append(pMenu->m_aEntries, &cText);
	cText = nullptr;
	table_append(pMenu->m_aValues, &cText);
	Uint32 textcol = COLOR_MENU_TEXT;
	table_append(pMenu->m_aColors, &textcol);	
}
Ejemplo n.º 9
0
// offerChoice()
// 	offerChoice blocks (yields to the C code) until the user makes a choice, returning
// 	the 1-based index of the chosen option.
int _lua_offerchoice(lua_State *L) {
	_talk_state *st = (_talk_state*) lua_touserdata(L, lua_upvalueindex(1));
	int ctx, status;
	if (st->m_iState == _STOPPED) {
		return luaL_error(L, "conversation is already stopped");
	}
	
	status = lua_getctx(L, &ctx);
	if (status == LUA_YIELD) {
		return 1;  // choice should be pushed on the stack before resuming
	}
	
	if (status != LUA_OK) { sys_abort(); }

	menu_auto_resize(st->m_pChoices);
	st->m_iState = _WAIT_CHOICE;
	st->m_pThread = L;
	return lua_yieldk(L, 0, 0, _lua_offerchoice);
}
Ejemplo n.º 10
0
static void up_handler(state_t s, event_t e, unmarsh_t abv) {
    endpt_id_t origin ;
    unmarsh_endpt_id(abv, &origin) ;
    if (s->partition) {
	sys_abort() ;
    } else {
	etime_t delay ;
	if (!distrib(s, &delay)) {
	    up_free(e, abv) ;
	} else {
	    etime_t when = time_add(alarm_gettime(s->alarm), delay) ;
	    item_t item = record_create(item_t, item) ;
	    /*eprintf("type=%s\n", event_type_to_string(event_type(e))) ;*/
	    item->type = DROP_UP ;
	    item->u.up.event = e ;
	    item->u.up.abv = abv ;
	    priq_add(s->priq, when, item) ;
	    dnnm(s, event_timer_time(when)) ;
	}
    }
}
Ejemplo n.º 11
0
void table_append(table *arr, const void *val) {
	if (arr->m_len == arr->m_cap) {
		int newcap;
		if (arr->m_cap == 0) {
			newcap = 8;
		} else {
			newcap = arr->m_cap * 2;
		}
		
		arr->m_data = realloc(arr->m_data, arr->m_elemSize * newcap);
		if (! arr->m_data) {
			debug_print("Not enough memory to append.\n");
			sys_abort();
		}
		memset(((unsigned char*)arr->m_data) + arr->m_cap*arr->m_elemSize, 0, newcap - arr->m_cap);
		arr->m_cap = newcap;
	}
	
	memmove(((unsigned char*)arr->m_data) + arr->m_len*arr->m_elemSize, val, arr->m_elemSize);
	arr->m_len++;
}
Ejemplo n.º 12
0
void alarm_disable(alarm_handle_t handle) {
    sys_abort() ;
}
Ejemplo n.º 13
0
void PREFIX(abort) (void)
{
    sys_abort ();
}
Ejemplo n.º 14
0
Archivo: inet.c Proyecto: 54niyu/minix
void abort()
{
	sys_abort(RBT_PANIC);
}
Ejemplo n.º 15
0
static void dump(state_t s) {
    sys_abort() ;
}
Ejemplo n.º 16
0
static void upnm_handler(state_t s, event_t e) {
    switch(event_type(e)) {
    case EVENT_FAIL:
	assert(bool_array_super(event_failures(e), s->failed, s->vs->nmembers)) ;
	bool_array_copy_into(s->failed, event_failures(e), s->vs->nmembers) ;
	upnm(s, e) ;
	break ;
	
    case EVENT_INIT:
	dnnm(s, event_timer_time(time_zero())) ;
	upnm(s, e) ;
	break ;

    case EVENT_TIMER: {
	etime_t time = event_time(e) ;
	item_t item ;
	while (priq_get_upto(s->priq, time, NULL, (void**)&item)) {
	    s->acct_delivered ++ ;
	    switch(item->type) {
	    case DROP_UP: {
		rank_t origin = event_peer(item->u.up.event) ;
		if (origin >= 0 &&
		    array_get(s->failed, origin)) {
		    up_free(item->u.up.event, item->u.up.abv) ;
		} else {
		    up(s, item->u.up.event, item->u.up.abv) ;
		}
	    } break ;

	    case DROP_UPNM:
		upnm(s, item->u.upnm.event) ;
		break ;

	    OTHERWISE_ABORT() ;
	    }
	    record_free(item) ;
	}

	if (time_ge(time, s->next_sweep)) {
	    if (!time_is_zero(s->next_sweep) &&
		sys_random(5) == 1) {
		rank_t i ;
		bool_array_t suspects = bool_array_create_init(s->vs->nmembers, FALSE) ;

		for(i=0;i<s->vs->nmembers;i++) {
		    if (i == s->ls->rank) {
			continue ;
		    }
		    if (sys_random(4) == 0) {
			array_set(suspects, i, TRUE) ;
		    }
		}
		if (bool_array_exists(suspects, s->vs->nmembers)) {
		    dnnm(s, event_suspect_reason_create(suspects, name)) ;
		} else {
		    array_free(suspects) ;
		}
	    }

#if 0
	    /* Suspicions are randomly generated every 0-8 seconds.
	     */
	    s->next_sweep = time_add(time, time_of_usecs(sys_random(1<<23/*8M*/))) ;
#else
	    s->next_sweep = time_add(time, time_of_usecs(sys_random(1<<20/*1M*/))) ;
#endif
	    dnnm(s, event_timer_time(s->next_sweep)) ; /* request next sweep */
	}
	upnm(s, e) ;
    } break ; 
	
    case EVENT_GOSSIP_EXT: {
	/*endpt_id_t origin = NULL ;*/
	etime_t delay ;
/*
	let origin =
      	getExtender (function
	  | HealGos(_,(_,endpt),_,_) -> Some (Some endpt)
	  | SwitchGos(_,(_,endpt),_) -> Some (Some endpt)
	  | _ -> None
        ) None ev 
      in
*/
	if (1 /*!origin*/) {
	    upnm(s, e) ;
	} else if (s->partition) {
	    sys_abort() ;
	} else if (!distrib(s, &delay)) {
	    event_free(e) ;
	} else {
	    /* Deliver after a certain delay....
	     */
	    etime_t when = time_add(alarm_gettime(s->alarm), delay) ;
	    item_t item = record_create(item_t, item) ;
	    item->type = DROP_UPNM ;
	    item->u.upnm.event = e ;
	    priq_add(s->priq, when, item) ;
	    dnnm(s, event_timer_time(when)) ;
	}
    } break ;

    case EVENT_ACCOUNT:
	log(("delivered=%d dropped=%d", s->acct_delivered, s->acct_dropped)) ;
	upnm(s, e) ;
	break ;

    EVENT_DUMP_HANDLE() ;

    default:
	upnm(s, e) ;
	break ;
    }
}