Esempio n. 1
0
void Kernel::copy_fields( Kernel & k_dst , unsigned i_dst ,
                          Kernel & k_src , unsigned i_src )
{
  static const char method[] = "phdmesh::Kernel::copy_fields" ;

  const std::vector<FieldBase*> & field_set =
    k_dst.mesh().mesh_meta_data().get_fields();

  unsigned char * const s = reinterpret_cast<unsigned char*>(k_src.m_entities);
  unsigned char * const d = reinterpret_cast<unsigned char*>(k_dst.m_entities);
  DataMap *       j = k_src.m_field_map ;
  DataMap *       i = k_dst.m_field_map ;
  DataMap * const e = i + field_set.size();

  for ( ; i != e ; ++i , ++j ) {

    if ( i->m_size ) {
      if ( j->m_size ) {
        if ( i->m_size == j->m_size ) {
          memory_copy( d + i->m_base + i->m_size * i_dst ,
                       s + j->m_base + j->m_size * i_src , i->m_size );
        }
        else {
          std::ostringstream msg ;
          msg << method ;
          msg << " FAILED WITH INCOMPATIBLE FIELD SIZES" ;
          throw std::runtime_error( msg.str() );
        }
      }
      else {
        memory_zero( d + i->m_base + i->m_size * i_dst , i->m_size );
      }
    }
  }
}
Esempio n. 2
0
listening_t * conn_listening_add(array_t *listening, pool_t *pool, 
    log_t *log, in_addr_t addr, in_port_t port, event_handler_pt handler,
    int rbuff_len, int sbuff_len)
{
    uchar_t             *address = NULL;
    listening_t        *ls = NULL;
    struct sockaddr_in *sin = NULL;

    if (!listening || !pool || !log ||  (port <= 0)) {
        return NULL;
    }
    //alloc sin addr
    sin = pool_alloc(pool, sizeof(struct sockaddr_in));
    if (!sin) {
        fast_log_error(log, FAST_LOG_ALERT, 0,
            "conn_listening_add: pooll alloc sockaddr failed");
        return NULL;
    }
    sin->sin_family = AF_INET;
    sin->sin_addr.s_addr = addr;
    sin->sin_port = htons(port);
    address = (uchar_t *)inet_ntoa(sin->sin_addr);
    //push listening socket
    ls = array_push(listening);
    if (!ls) {
        fast_log_error(log, FAST_LOG_ALERT, 0,
            "conn_listening_add: push listening socket failed!");
        return NULL;
    }
    memory_zero(ls, sizeof(listening_t));
    ls->addr_text.data = pool_calloc(pool,
        INET_ADDRSTRLEN - 1 + sizeof(":65535") - 1);
    if (!ls->addr_text.data) {
        fast_log_error(log, FAST_LOG_ALERT, 0,
            "conn_listening_add: pool alloc ls->addr text failed");
        return NULL;
    }
    ls->addr_text.len = string_xxsprintf(ls->addr_text.data,
        "%s:%d", address, port) - ls->addr_text.data;
    ls->fd = FAST_INVALID_FILE;
    ls->family = AF_INET;
    ls->type = SOCK_STREAM;
    ls->sockaddr = (struct sockaddr *) sin;
    ls->socklen = sizeof(struct sockaddr_in);
    //config from config file
    ls->backlog = CONN_DEFAULT_BACKLOG;
   	ls->rcvbuf = rbuff_len > CONN_DEFAULT_RCVBUF? rbuff_len: CONN_DEFAULT_RCVBUF;
    ls->sndbuf = sbuff_len > CONN_DEFAULT_SNDBUF? sbuff_len: CONN_DEFAULT_SNDBUF;
	
    //connection pool size
    ls->conn_psize = CONN_DEFAULT_POOL_SIZE;
    ls->log = log;
    ls->handler = handler;
    ls->open = 0;
    ls->linger = 1;

    return ls;
}
Esempio n. 3
0
void conn_set_default(conn_t *c, int s)
{
    event_t      *rev = NULL;
    event_t      *wev = NULL;
    uint32_t      instance;
    uint32_t      last_instance;

    c->fd = s;

    rev = c->read;
    wev = c->write;
    instance = rev->instance;
    last_instance = rev->last_instance;
    c->sent = 0;

    c->conn_data = NULL;
    c->next = NULL;
    c->error = 0;
    c->listening = NULL;
    c->next = NULL;
    c->sendfile = FAST_FALSE;
    c->sndlowat = 0;
    c->sockaddr = NULL;
    memory_zero(&c->addr_text, sizeof(string_t));
    c->socklen = 0;
    //set rev & wev->instance to !last->instance
    memory_zero(rev, sizeof(event_t));
    memory_zero(wev, sizeof(event_t));
    rev->instance = !instance;
    wev->instance = !instance;
    rev->last_instance = last_instance;
    
    rev->data = c;
    wev->data = c;
    wev->write = FAST_TRUE;

}
Esempio n. 4
0
void Kernel::zero_fields( Kernel & k_dst , unsigned i_dst )
{
  const std::vector<FieldBase*> & field_set =
    k_dst.mesh().mesh_meta_data().get_fields();

  unsigned char * const p = reinterpret_cast<unsigned char*>(k_dst.m_entities);
  const DataMap *       i = k_dst.m_field_map ;
  const DataMap * const e = i + field_set.size();

  for ( ; i != e ; ++i ) {
    if ( i->m_size ) {
      memory_zero( p + i->m_base + i->m_size * i_dst , i->m_size );
    }
  }
}
Esempio n. 5
0
int create_task(task_func program, size_t stack_size, struct task_info **task)
{
	PANIC_ON(program == NULL, "Program pointer cannot be NULL");
	PANIC_ON(stack_size == 0, "Cannot create task with stack size of 0.");
	
	*task = malloc(sizeof(struct task_info));
	
	if(!*task)
		return -1;
	
	uint8_t *stack = (uint8_t*)malloc(stack_size);
	uint8_t *stack_base = stack + stack_size;
	
	if(!stack) {
		free(*task);
		return -1;
	}
	
	memory_zero(stack, stack_size);
	
	(*task)->stack_ptr = stack;
	(*task)->stack_base = stack + stack_size;
	(*task)->current_sp = stack + stack_size;
	(*task)->program = program;
	
	stack_push(*task, 514); // EFLAGS (No idea what to put here, I inspected EFLAGS at some random location and found it had the value 514)
	stack_push(*task, 0x08); // code segment
	stack_push(*task, (uint32_t)program); // EIP
	stack_push(*task, 0x0); // edi
	stack_push(*task, 0x0); // esi
	stack_push(*task, 0x0); // ebx
	stack_push(*task, 0x0); // edx
	stack_push(*task, 0x0); // ecx
	stack_push(*task, 0x0); // eax
	
	char buf[92];
	uint32_t *ebp = (uint32_t*)(*task)->stack_base;
	uint32_t *esp = (uint32_t*)(*task)->current_sp;
	snprintf(buf, 92, "DEBUG: created new task with EBP: %d, ESP: %d\n", 2, ebp, esp);
	print(buf);
	
	return 0;
}