Ejemplo n.º 1
0
int
qminheap_init(qminheap_t *heap, cmp_func_t cmp,
              set_func_t set, get_func_t get) {
  heap->data = qcalloc(QID_MAX * sizeof(void*)); 
  if (heap->data == NULL) {
    return -1;
  }
  heap->size = QID_MAX;
  heap->num  = 0;
  heap->cmp  = cmp;
  heap->set  = set;
  heap->get  = get;

  return 0;
}
Ejemplo n.º 2
0
qdict_t*
qdict_new(int hashsize) {
  int       i;
  qdict_t  *dict;

  dict = qcalloc(sizeof(qdict_t) + hashsize * sizeof(qlist_t));
  if (dict == NULL) {
    return NULL;
  }
  dict->hashsize = hashsize;
  dict->num = 0;
  for (i = 0; i < hashsize; ++i) {
    qlist_entry_init(&(dict->buckets[i]));
  }

  return dict;
}
Ejemplo n.º 3
0
qlog_t*
qlog_new() {
  /* seems freelist no effect, so alloc directly */
  return qcalloc(sizeof(qlog_t));

  qlog_t *log;

  qmutex_lock(&free_log_list_lock);
  log = (qlog_t*)qfreelist_new(&free_log_list);
  qmutex_unlock(&free_log_list_lock);
  if (log != NULL) {
    /* del it from freelist alloc list */
    qlist_del_init(&log->fentry);
  }

  return log;
}
Ejemplo n.º 4
0
qmsg_t*
qmsg_new(qid_t sender, qid_t recver, int size, int type) {
  qmsg_t *msg;

  msg = (qmsg_t*)qcalloc(size);
  if (msg == NULL) {
    qerror("alloc type %d msg error", type);
    return NULL;
  }
  qlist_entry_init(&(msg->entry));
  msg->sender   = sender;
  msg->recver   = recver;
  msg->type     = type;
  msg->size     = size;

  return msg;
}
Ejemplo n.º 5
0
static int
kqueue_init(qengine_t *engine) {
  qkqueue_t *kq;

  kq = qcalloc(sizeof(qkqueue_t));
  if (kq == NULL) {
    return QERROR;
  }

  kq->events = qalloc(sizeof(struct kevent) * engine->size);
  if (kq->events == NULL) {
    return QERROR;
  }
  kq->kqfd = kqueue();
  if (kq->kqfd == -1) {
    qfree(kq->events);
    qfree(kq);
    return QERROR;
  }
  engine->data = kq;

  return QOK;
}
Ejemplo n.º 6
0
int
qlogger_new(int thread_num, qthread_start_pt done) {
  qlog_init_free_list();
  logger = qcalloc(sizeof(qlogger_t));
  if (logger == NULL) {
    return QERROR;
  }

  if (pthread_key_create(&thread_log_key, log_key_destroy) < 0) {
    return QERROR;
  }

  logger->fd = -1;
  logger->log_size = 0;
  if (config.daemon) {
    qlogger_open_file();
  }
  logger->engine = qengine_new();
  if (logger->engine == NULL) {
    return QERROR;
  }
  qmailbox_init(&(logger->box), logger_msg_handler,
                logger->engine, logger);
  logger->box.done = logger_handle_msglist_done;

  logger->thread_num = thread_num;
  qlist_entry_init(&(logger->free_list));
  log_time_handler(NULL);
  qtimer_add(logger->engine, 1000, log_time_handler,
             NULL, 1000, NULL);
  logger->running = 0;
  logger->done = done;
  pthread_create(&logger->id, NULL,
                 logger_main, logger);

  return QOK;
}
Ejemplo n.º 7
0
static int
epoll_init(qengine_t *engine) {
  qepoll_t *epoll;

  epoll = qcalloc(sizeof(qepoll_t));
  if (epoll == NULL) {
    return QERROR;
  }
  epoll->events = qalloc(sizeof(struct epoll_event) * engine->size);
  if (epoll->events == NULL) {
    return QERROR;
  }

  epoll->fd = epoll_create(1024);
  if (epoll->fd == -1) {
    qfree(epoll->events);
    qfree(epoll);
    qerror("epoll_create error: %s", strerror(errno));
    return QERROR;
  }
  engine->data = epoll;

  return QOK;
}
Ejemplo n.º 8
0
int struct_init(ea_t addr, ea_t base, size_t size)
{
	char buf[1024];
	strace_t *st = strace;

	// skip if this alloc has already been identified
	while(st)
	{
		if(st->addr == addr)
			return 0;
		st = st->next;
	}

	if(!size && options.detect_size)
	{
		if((size = analyze_struct_size(addr)) < 0)
			if(options.verbose)
				msg("[idastruct] could not auto-detect structure size\n");
	}
	
	// failsafe -- if size wasn't detected, just ask for it
	if(!size)
	{
		if(!asklong((sval_t *)&size, "Structure size"))
		{
			if(options.verbose)
				msg("[idastruct] structure size unknown .. skipping\n");
			return -1;
		}
	}
	

	// check call history for action to take on this call
	if(allocator_call_hist(addr) != -1)
		return -1;

	// this call has not been traced or permanently skipped
	get_disasm(addr, buf, 1024);
	int ref = askbuttons_c(NULL, NULL, "Skip once", 0, 
		"Create structure reference at this call:\n\n%s        (%d bytes @ 0x%08x)",
		buf, size, base);

	// skip once 
	if(ref == -1)
		return -1;

	// save action for this call
	struct _alloc_hist *cur = (struct _alloc_hist *)qcalloc(1, sizeof(struct _alloc_hist));
	if(!cur)
	{
		msg("[idastruct] error: could not store allocator state\n");
		return -1;
	}
	cur->addr = addr;
	cur->cstruct = ref;

	// insert into history
	cur->next = alloc_hist;
	alloc_hist = cur;  

	// user decided to not trace structure
	if(ref == 0)
		return -1; 

	// create structure trace
	st = (strace_t *)qcalloc(1, sizeof(strace_t));
	if(!st)
	{
		msg("[idastruct] error: could not allocate memory\n");
		return -1;
	}

	st->addr = addr;
	st->size = size;
	st->base = base;
	st->sptr = struct_create(st->size);
	if(!st->sptr)
		return -1;

	if(options.verbose)
	{
		msg("[idastruct] structure initialized\n");
		msg("            code origin:    0x%08x\n", addr);
		msg("            structure base: 0x%08x\n", st->base);
		msg("            structure size: %d bytes\n", st->size);
	}

	// push struct trace
	st->next = strace; 
	strace = st; 	

	return 0;
}