Example #1
0
File: mesh.c Project: clazaro/sfepy
int32 conn_alloc(MeshConnectivity *conn, uint32 num, uint32 n_incident)
{
  int32 ret = RET_OK;

  if ((conn->num > 0) && (conn->n_incident > 0)) {
    conn_free(conn);
  }

  if (num > 0) {
    conn->num = num;
    conn->offsets = alloc_mem(uint32, num + 1);
    ERR_CheckGo(ret);
  }

  if (n_incident > 0) {
    conn->n_incident = n_incident;
    conn->indices = alloc_mem(uint32, n_incident);
    ERR_CheckGo(ret);
  } else if (num == 0) { // Empty connectivity.
    conn->n_incident = n_incident;
    conn->indices = 0;
  }

 end_label:
  if (ERR_Chk) {
    conn_free(conn);
  }

  return(ret);
}
Example #2
0
void
cylinder (double x0, double y0, double z0, double size, double diameter, double alpha, 
	  double betha, int arcs, int circles)
{
	int num_points;
	double *cylinder_3D_points, *left_points, *right_points;
	CYLINDER cylinder;
	
	num_points = arcs*circles;
	cylinder_3D_points = (double *) alloc_mem (3 * num_points * sizeof (double));
	left_points = (double *) alloc_mem (2 * num_points * sizeof (double));
	right_points = (double *) alloc_mem (2 * num_points * sizeof (double));

	cylinder.x = x0;
	cylinder.y = y0;
	cylinder.z = z0;
	cylinder.size = size;
	cylinder.diameter = diameter;
	cylinder.alpha = alpha;
	cylinder.betha = betha;

	compute_3D_cylinder (&cylinder, cylinder_3D_points, arcs, circles, cylinder.size, 180);
	
	CameraProjectionRight(num_points, left_points, cylinder_3D_points, LEFT_CAMERA);
	CameraProjectionRight(num_points, right_points, cylinder_3D_points, RIGHT_CAMERA);

	
//	overwrite_points (num_points, left_points, right_points);

	project_cylinder_2D_points_into_disparity_map (num_points, left_points, right_points);
 
	free (right_points);
	free (left_points);
	free (cylinder_3D_points);
}
Example #3
0
Character *new_char()
{
    Character *ch = (Character *) alloc_mem(1, sizeof(Character));
    ch->flags = new_flag();
    ch->affectedBy = new_flag();
    ch->next = 0;
    ch->next_in_area = 0;
    ch->name = str_empty;
    ch->position = POS_STANDING;
    ch->sex = SEX_NEUTRAL;
    ch->description = str_empty;
    ch->hit = ch->maxHit = 100;
    ch->mana = ch->maxMana = 100;
    ch->move = ch->maxMove = 100;
    ch->writelnf = writef_line_to_char;
    ch->writef = writef_to_char;
    ch->writeln = write_line_to_char;
    ch->write = write_to_char;
    ch->page = page_to_char;
    ch->title = title_to_char;
    ch->titlef = titlef_to_char;
    ch->classes = alloc_mem(1, sizeof(int));
    ch->classes[0] = -1;
    ch->size = SIZE_AVERAGE;

    for (int i = 0; i < MAX_DAM; i++) {
        ch->resists[i] = 100;
    }
    return ch;
}
Example #4
0
static item_t* fill_get_response_header(char *key ,intptr_t bytes){
  char *s=(char *)alloc_mem(pool,20);
  sprintf(s,"%ld",bytes);
  intptr_t first_length=strlen(first_get_response);
  intptr_t key_length=strlen(key);
  intptr_t middle_length=strlen(middle);
  intptr_t s_length=strlen(s);
  intptr_t command_end_length=strlen(command_end);
  intptr_t length=first_length+key_length+middle_length+s_length+command_end_length;
  char *c=(char *)alloc_mem(pool,length);
  memset(c,0,length);
  intptr_t index=0;
  memcpy(c,first_get_response,first_length);
  index+=first_length;
  memcpy(c+index,key,key_length);
  index+=key_length;
  memcpy(c+index,middle,middle_length);
  index+=middle_length;
  memcpy(c+index,s,s_length);
  index+=s_length;
  memcpy(c+index,command_end,command_end_length);
  index+=command_end_length;
  
  free_mem(s);
  item_t *i=init_item();
  i->data=c;
  i->c_size=length;
  return i;
}
Example #5
0
// intiailize (alloc mem, check/set firstrun bytes)
u8 init_flash() {
#if 1
#else
  u32 i;

  print_dbg("\r\n init flash... ");

  // allocate bfin loader buf
  ////////////////////
  /////////// TESTING
#if 0
  bfinLdrData = alloc_mem(BFIN_LDR_MAX_BYTES);
#else
  bfinLdrData = alloc_mem(BFIN_LDR_MAX_BYTES * 4);
#endif
  for(i=0; i<BFIN_LDR_MAX_BYTES; i++) { bfinLdrData[i] = 0; }

  if(flash_nvram_data.firstRun != FIRSTRUN_MAGIC) {
    // set size=0 so we won't attempt unitialized bfin load on next start
    bfinLdrSize = 0;
    flashc_memset32((void*)&(flash_nvram_data.ldrSize), 0x00000000, 4, true);
    // do this only after succesful app launch
    //    flashc_memset32((void*)&(flash_nvram_data.firstRun), FIRSTRUN_MAGIC, 4, true);
    return 1;
  } else { 
    // firstrun already happened
    return 0;
  }
#endif
}
Example #6
0
File: is.c Project: 8l/insieme
void alloc_key_buff( void )
{
    INT_TYPE i;
    int      num_procs;


#ifdef _OPENMP
    num_procs = omp_get_max_threads();
#else
    num_procs = 1;
#endif

#ifdef USE_BUCKETS
    bucket_size = (INT_TYPE **)alloc_mem(sizeof(INT_TYPE *) * num_procs);

    for (i = 0; i < num_procs; i++) {
        bucket_size[i] = (INT_TYPE *)alloc_mem(sizeof(INT_TYPE) * NUM_BUCKETS);
    }

    #pragma omp parallel for
    for( i=0; i<NUM_KEYS; i++ )
        key_buff2[i] = 0;

#else /*USE_BUCKETS*/

    key_buff1_aptr = (INT_TYPE **)alloc_mem(sizeof(INT_TYPE *) * num_procs);

    key_buff1_aptr[0] = key_buff1;
    for (i = 1; i < num_procs; i++) {
        key_buff1_aptr[i] = (INT_TYPE *)alloc_mem(sizeof(INT_TYPE) * MAX_KEY);
    }

#endif /*USE_BUCKETS*/
}
Example #7
0
void test_alloc(int testcase, int lite)
{
	if (lite)
		alloc_mem(TESTMEM + MB, testcase);
	else
		while(1)
			if (alloc_mem(LENGTH, testcase))
				return;
}
Example #8
0
File: send.c Project: verias/SRMud
/*
 * Page to one char, new colour version, by Lope.
 */
void page_to_char( const char *txt, CHAR_DATA *ch )
{
    const	char	*point;
    		char	*point2;
    		char	buf[ MAX_STRING_LENGTH * 4 ];
		int	skip = 0;

#if defined(macintosh)
		send_to_char( txt, ch );
#else
    buf[0] = '\0';
    point2 = buf;
    if( txt && ch->desc )
	{
	    if( IS_SET( ch->act, PLR_COLOUR ) )
	    {
		for( point = txt ; *point ; point++ )
	        {
		    if( *point == '{' )
		    {
			point++;
			skip = colour( *point, ch, point2 );
			while( skip-- > 0 )
			    ++point2;
			continue;
		    }
		    *point2 = *point;
		    *++point2 = '\0';
		}			
		*point2 = '\0';
		ch->desc->showstr_head  = alloc_mem( strlen( buf ) + 1 );
		strcpy( ch->desc->showstr_head, buf );
		ch->desc->showstr_point = ch->desc->showstr_head;
		show_string( ch->desc, "" );
	    }
	    else
	    {
		for( point = txt ; *point ; point++ )
	        {
		    if( *point == '{' )
		    {
			point++;
			continue;
		    }
		    *point2 = *point;
		    *++point2 = '\0';
		}
		*point2 = '\0';
		ch->desc->showstr_head  = alloc_mem( strlen_color( buf ) + 1 );
		strcpy( ch->desc->showstr_head, buf );
		ch->desc->showstr_point = ch->desc->showstr_head;
		show_string( ch->desc, "" );
	    }
	}
#endif
    return;
}
Example #9
0
static void write_null(connection_t *conn,char *key){
  intptr_t length=strlen(data_end);
  char *s=(char *)alloc_mem(pool,length);
  memcpy(s,data_end,length);
  item_t *i=(item_t *)alloc_mem(pool,length);
  i->data=s;
  i->c_size=length;
  push(conn->wc->w_queue,i);
}
Example #10
0
static status_t
cx23882_buffers_alloc(cx23882_device *device)
{
	device->dma_buf1_area = alloc_mem(&device->dma_buf1_virt, &device->dma_buf1_phys, DMA_BUFFER_SIZE, B_READ_AREA, "cx23882 dma buf 1");
	device->dma_buf2_area = alloc_mem(&device->dma_buf2_virt, &device->dma_buf2_phys, DMA_BUFFER_SIZE, B_READ_AREA, "cx23882 dma buf 2");
	if (device->dma_buf1_area < B_OK || device->dma_buf2_area < B_OK) {
		cx23882_buffers_free(device);
		return B_NO_MEMORY;
	}
	return B_OK;
}
LMS::LMS (                       //constructor
inT32 size                       //samplesize
):samplesize (size) {
  samplecount = 0;
  a = 0;
  m = 0.0f;
  c = 0.0f;
  samples = (FCOORD *) alloc_mem (size * sizeof (FCOORD));
  errors = (float *) alloc_mem (size * sizeof (float));
  line_error = 0.0f;
  fitted = FALSE;
}
Example #12
0
QSPLINE & QSPLINE::operator= (   //assignment
const QSPLINE & source) {
  if (xcoords != NULL)
    free_mem(xcoords);
  if (quadratics != NULL)
    free_mem(quadratics);

  segments = source.segments;
  xcoords = (inT32 *) alloc_mem ((segments + 1) * sizeof (inT32));
  quadratics = (QUAD_COEFFS *) alloc_mem (segments * sizeof (QUAD_COEFFS));
  memmove (xcoords, source.xcoords, (segments + 1) * sizeof (inT32));
  memmove (quadratics, source.quadratics, segments * sizeof (QUAD_COEFFS));
  return *this;
}
Example #13
0
static intptr_t process_set_body(connection_t *conn){ 
    //check一下当前buffer数据的剩余多少
  buffer_t *b=conn->rbuf;
  intptr_t count=b->limit-b->current;
  if(count==0){
    return AGAIN;
  }
    //开始存储set数据
  read_context_t *rc=conn->rc;
  char *key=rc->key->data;
  queue_t *q=(queue_t *)get(key,hash);
  if(q==NULL){

    //初始化队列,加入hash中
    q=init_queue();
    char *q_name=(char *)alloc_mem(pool,strlen(key));
    strcpy(q_name,key);
    put(q_name,q,hash);

    //开始统计这个队列
    start_queue_stat(q_name);
  }  
  intptr_t fill=0;
  intptr_t result=AGAIN;
  item_t *i=init_item();
  i->size=rc->last_bytes-2;
    //如果当前buffer的数据包含了所有的set数据包括最后的/r/n
  if(count>=rc->last_bytes){
    fill=rc->last_bytes;
    i->end=1;
    result=OK;
    write_set_response(conn);

    //加入队列数据统计
    increase_queue_stat(key,i->size);
  }else{
      //如果buffer不够了那么先把这部分数据copy出来,放入一个item中
    fill=count;
    rc->last_bytes-=fill;
  }
  char *c=(char *)alloc_mem(pool,fill);
  memset(c,0,fill);
  memcpy(c,b->data+b->current,fill);
  i->data=c;
  i->c_size=fill;
  push(q,i);
  add_set_sync_data(key,i);
  b->current+=fill;
  return result;
}
Example #14
0
void QSPLINE::extrapolate(                  //linear extrapolation
                          double gradient,  //gradient to use
                          int xmin,         //new left edge
                          int xmax          //new right edge
                         ) {
  register int segment;          /*current segment of spline */
  int dest_segment;              //dest index
  int *xstarts;                  //new boundaries
  QUAD_COEFFS *quads;            //new ones
  int increment;                 //in size

  increment = xmin < xcoords[0] ? 1 : 0;
  if (xmax > xcoords[segments])
    increment++;
  if (increment == 0)
    return;
  xstarts = (int *) alloc_mem ((segments + 1 + increment) * sizeof (int));
  quads =
    (QUAD_COEFFS *) alloc_mem ((segments + increment) * sizeof (QUAD_COEFFS));
  if (xmin < xcoords[0]) {
    xstarts[0] = xmin;
    quads[0].a = 0;
    quads[0].b = gradient;
    quads[0].c = y (xcoords[0]) - quads[0].b * xcoords[0];
    dest_segment = 1;
  }
  else
    dest_segment = 0;
  for (segment = 0; segment < segments; segment++) {
    xstarts[dest_segment] = xcoords[segment];
    quads[dest_segment] = quadratics[segment];
    dest_segment++;
  }
  xstarts[dest_segment] = xcoords[segment];
  if (xmax > xcoords[segments]) {
    quads[dest_segment].a = 0;
    quads[dest_segment].b = gradient;
    quads[dest_segment].c = y (xcoords[segments])
      - quads[dest_segment].b * xcoords[segments];
    dest_segment++;
    xstarts[dest_segment] = xmax + 1;
  }
  segments = dest_segment;
  free_mem(xcoords);
  free_mem(quadratics);
  xcoords = (inT32 *) xstarts;
  quadratics = quads;
}
Example #15
0
/*************************************************************************
 * PIXROW::PIXROW()
 *
 * Constructor for a specified size PIXROW from a blob
 *************************************************************************/
PIXROW::PIXROW(INT16 pos, INT16 count, PBLOB *blob) { 
  OUTLINE_LIST *outline_list;
  OUTLINE_IT outline_it;
  POLYPT_LIST *pts_list;
  POLYPT_IT pts_it;
  INT16 i;
  FCOORD pt;
  FCOORD vec;
  float y_coord;
  INT16 x_coord;

  row_offset = pos;
  row_count = count;
  min = (INT16 *) alloc_mem (count * sizeof (INT16));
  max = (INT16 *) alloc_mem (count * sizeof (INT16));
  outline_list = blob->out_list ();
  outline_it.set_to_list (outline_list);

  for (i = 0; i < count; i++) {
    min[i] = MAX_INT16 - 1;
    max[i] = -MAX_INT16 + 1;
    y_coord = row_offset + i + 0.5;
    for (outline_it.mark_cycle_pt ();
    !outline_it.cycled_list (); outline_it.forward ()) {
      pts_list = outline_it.data ()->polypts ();
      pts_it.set_to_list (pts_list);
      for (pts_it.mark_cycle_pt ();
      !pts_it.cycled_list (); pts_it.forward ()) {
        pt = pts_it.data ()->pos;
        vec = pts_it.data ()->vec;
        if ((vec.y () != 0) &&
          (((pt.y () <= y_coord) && (pt.y () + vec.y () >= y_coord))
          || ((pt.y () >= y_coord)
        && (pt.y () + vec.y () <= y_coord)))) {
          /* The segment crosses y_coord so find x-point and check for min/max. */
          x_coord = (INT16) floor ((y_coord -
            pt.y ()) * vec.x () / vec.y () +
            pt.x () + 0.5);
          if (x_coord < min[i])
            min[i] = x_coord;
          x_coord--;             //to get pix to left of line
          if (x_coord > max[i])
            max[i] = x_coord;
        }
      }
    }
  }
}
Example #16
0
////复制父进程的地址空间
static int copy_mem(int pid,struct task_struct *p)
{
    struct descriptor *dp = &proc_table[pid].ldts[INDEX_LDT_C];
    int text_base = get_base(dp);
    int text_limit = get_limit(dp);
    int text_size = (text_limit + 1) * ((dp->limit_high_attr2 * 0x80)?4096:1);

    dp = &proc_table[pid].ldts[INDEX_LDT_D]; 
    int data_base =  get_base(dp);
    int data_limit= get_limit(dp);
    int data_size = (text_limit + 1) * ((dp->limit_high_attr2 * 0x80)?4096:1);

    assert((text_base == data_base)  && 
            (text_limit == data_limit) &&
            (text_size == data_size)
          );

    int child_base = alloc_mem(p->pid,text_size);

    //	printk("child_base = %d\t text_base = %d\t text_size = %d\n",child_base,text_base,text_size);
    //	memcpy((void *)child_base,(void *)(text_base),text_size);

    //	printk("child_base = %d\t text_base = %d\t text_size = %d\n",child_base,text_base,text_size);
    phys_copy((char *)child_base,(char *)(text_base),text_size);
    return child_base;
}
Example #17
0
int _brk(void *addr)
{
	vir_bytes target = roundup((vir_bytes)addr, VM_PAGE_SIZE), v;
	extern char _end;
	extern char *_brksize;
	static vir_bytes prevbrk = (vir_bytes) &_end;
	struct vmproc *vmprocess = &vmproc[VM_PROC_NR];

	for(v = roundup(prevbrk, VM_PAGE_SIZE); v < target;
		v += VM_PAGE_SIZE) {
		phys_bytes mem, newpage = alloc_mem(1, 0);
		if(newpage == NO_MEM) return -1;
		mem = CLICK2ABS(newpage);
		if(pt_writemap(vmprocess, &vmprocess->vm_pt,
			v, mem, VM_PAGE_SIZE,
			  ARCH_VM_PTE_PRESENT
			| ARCH_VM_PTE_USER
			| ARCH_VM_PTE_RW
#if defined(__arm__)
			| ARM_VM_PTE_WB
#endif
			, 0) != OK) {
			free_mem(newpage, 1);
			return -1;
		}
		prevbrk = v + VM_PAGE_SIZE;
	}

        _brksize = (char *) addr;

        if(sys_vmctl(SELF, VMCTL_FLUSHTLB, 0) != OK)
        	panic("flushtlb failed");

	return 0;
}
Example #18
0
// initialize network at pre-allocated memory
void net_init(void) {
  u32 i;
  net = (ctlnet_t*)alloc_mem(sizeof(ctlnet_t));

  for(i=0; i<NET_OP_POOL_SIZE; i++) {
    net->opPoolMem[i] = 0x00;
  }

  net->opPool = (void*)&(net->opPoolMem);
  net->opPoolOffset = 0;
  net->numOps = 0;
  net->numIns = 0;
  net->numOuts = 0;
  net->numParams = 0;

  // unassign all I/O nodes
  for(i=0; i<NET_INS_MAX; i++) {
    net_init_inode(i);
  }
  for(i=0; i<NET_OUTS_MAX; i++) {
    net_init_onode(i);
  }

  print_dbg("\r\n initialized ctlnet, byte count: ");
  print_dbg_hex(sizeof(ctlnet_t));
  add_sys_ops();
  // ???
  netActive = 1;
}
Example #19
0
void c_rt_lib0init_advanced(int catch_signals, char * (*die_f)(), char * (*logs_f)()) {
	_global_const_offset_ = sizeof(NlInt);
	if (sizeof(NlFloat) > _global_const_offset_)
		_global_const_offset_ = sizeof(NlFloat);
	if (sizeof(NlString) > _global_const_offset_)
		_global_const_offset_ = sizeof(NlString);
	_false = c_rt_lib0ov_mk_none(c_rt_lib0string_new("FALSE"));
	_true = c_rt_lib0ov_mk_none(c_rt_lib0string_new("TRUE"));
	_array = c_rt_lib0array_new_alloc();
	_hash = c_rt_lib0hash_new_alloc();
	_int_0 = c_rt_lib0int_new(-1);
	((NlInt *)_int_0)->i = 0;
	_int_1 = c_rt_lib0int_new(-1);
	((NlInt *)_int_1)->i = 1;
	char *t = (char*)alloc_mem(sizeof(char));
	t[0] = '\0';
	_empty_str = c_rt_lib0string_new_alloc(t,0,1);
	___global_const_init();
	if (catch_signals) {
		c_rt_lib_priv_register_signal_handler(SIGSEGV);
	}

	die_additional_info = die_f;
	logs_dir_f = logs_f;
}
Example #20
0
C_OUTLINE::C_OUTLINE (
//constructor
CRACKEDGE * startpt,             //outline to convert
ICOORD bot_left,                 //bounding box
ICOORD top_right, inT16 length   //length of loop
):box (bot_left, top_right), start (startpt->pos), offsets(NULL) {
  inT16 stepindex;               //index to step
  CRACKEDGE *edgept;             //current point

  stepcount = length;            //no of steps
  if (length == 0) {
    steps = NULL;
    return;
  }
                                 //get memory
  steps = (uinT8 *) alloc_mem (step_mem());
  memset(steps, 0, step_mem());
  edgept = startpt;

  for (stepindex = 0; stepindex < length; stepindex++) {
                                 //set compact step
    set_step (stepindex, edgept->stepdir);
    edgept = edgept->next;
  }
}
Example #21
0
/* Inutilizzata */
BUFFER *new_buf_size(int size)
{
    BUFFER *buffer;

    if (buf_free == NULL)
        buffer = alloc_perm(sizeof(*buffer));
    else
    {
        buffer = buf_free;
        buf_free = buf_free->next;
    }

    buffer->next        = NULL;
    buffer->state       = BUFFER_SAFE;
    buffer->size        = get_size(size);
    if (buffer->size == -1)
    {
        bug("new_buf: buffer size %d too large.",size);
        exit(1);
    }
    buffer->string      = alloc_mem(buffer->size);
    buffer->string[0]   = '\0';
    VALIDATE(buffer);

    return buffer;
}
Example #22
0
void make_input_image_class_cnae (INPUT_DESC *input, int w, int h)
{
	char message[256];

	input->tfw = nearest_power_of_2 (w);
	input->tfh = nearest_power_of_2 (h);

	input->ww = w;
	input->wh = h;

	switch(TYPE_SHOW)
	{
		case SHOW_FRAME:
			input->vpw = input->neuron_layer->dimentions.x;
			input->vph = input->neuron_layer->dimentions.y;
			break;
		case SHOW_WINDOW:
			input->vph = h;
			input->vpw = w;
			break;
		default:
			sprintf(message,"%d. It can be SHOW_FRAME or SHOW_WINDOW.",TYPE_SHOW);
			Erro ("Invalid Type Show ", message, " Error in update_input_image.");
			return;
	}
	
	input->vpxo = 0;
	input->vpyo = h - input->vph;

	if(input->image == NULL)
		input->image = (GLubyte *) alloc_mem (input->tfw * input->tfh * 3 * sizeof (GLubyte));
}
Example #23
0
void SimpleGrayImage::resize(int wid, int hig)
{
	assert ((wid > 0) && (hig > 0));
	w = wid;
	h = hig;
	alloc_mem(wid, hig);
}
Example #24
0
int SwitchPortCPU::outputPacket(PriPacket& pkg) {

	if( pkg.getSourcePort() == CPU_Port_Sn ) {
		return -1;
	}
	uint16 RxLen = 0;
	uint8* RxData = pkg.getStdStream(&RxLen);
	if( RxLen < 30 || RxData == 0 ) {
        std::cout << "SwitchPortCPU send error: len " << (int)RxLen << std::endl;
        return -1;
	}
#ifdef EZ_DEBUG
	trace->sendOnePkg();
#endif
	tsk_lock();
    OS_FRAME* frame = alloc_mem (RxLen | 0x80000000);
    tsk_unlock();
	if (frame != NULL) {
		memcpy( &frame->data[0], RxData, RxLen);
		put_in_queue(frame);
		os_evt_set(0x0001, t_tcpTask);
		return 1;
	}
	else {
	    std::cout << "SwitchPortCPU::outputPacket() alloc_mem(" << (int)RxLen << ") error" << std::endl;
	}
	return -1;
}
Example #25
0
bool add_buf(BUFFER *buffer, char *string) {
	int len;
	char *oldstr;
	int oldsize;

	oldstr = buffer->string;
	oldsize = buffer->size;

	if (buffer->state == BUFFER_OVERFLOW)
		return FALSE;

	len = strlen(buffer->string) + strlen(string) + 1;

	while (len >= buffer->size) {
		buffer->size = get_size(buffer->size + 1);
		{
			if (buffer->size == -1) {
				buffer->size = oldsize;
				buffer->state = BUFFER_OVERFLOW;
				bug("Add_buf: buffer overflow past size %d", buffer->size);
				return FALSE;
			}
		}
	}

	if (buffer->size != oldsize) {
		buffer->string = alloc_mem(buffer->size);
		strcpy(buffer->string, oldstr);
		free_mem(oldstr, oldsize);
	}

	strcat(buffer->string, string);
	return TRUE;
}
Example #26
0
DESCRIPTOR_DATA *new_descriptor(void)
{
    static DESCRIPTOR_DATA d_zero;
    DESCRIPTOR_DATA *d;

    if (descriptor_free == NULL)
	d = alloc_perm(sizeof(*d));
    else
    {
	d = descriptor_free;
	descriptor_free = descriptor_free->next;
    }
	
    *d = d_zero;
    VALIDATE(d);
    
    d->connected	= CON_GET_NAME;
    d->showstr_head	= NULL;
    d->showstr_point = NULL;
    d->outsize	= 2000;
    d->outtop	= 0;
    d->pEdit		= NULL;			/* OLC */
    d->pString	= NULL;			/* OLC */
    d->editor	= 0;			/* OLC */
    d->outbuf	= alloc_mem( d->outsize );
    
    return d;
}
Example #27
0
static void child_alloc(int testcase, int lite, int threads)
{
	int i;
	pthread_t *th;

	if (lite) {
		int ret = alloc_mem(TESTMEM + MB, testcase);
		exit(ret);
	}

	th = malloc(sizeof(pthread_t) * threads);
	if (!th) {
		tst_resm(TINFO | TERRNO, "malloc");
		goto out;
	}

	for (i = 0; i < threads; i++) {
		TEST(pthread_create(&th[i], NULL, child_alloc_thread,
			(void *)((long)testcase)));
		if (TEST_RETURN) {
			tst_resm(TINFO | TRERRNO, "pthread_create");
			goto out;
		}
	}

	/* wait for one of threads to exit whole process */
	while (1)
		sleep(1);
out:
	exit(1);
}
Example #28
0
static int
reservedqueue_addslot(struct reserved_pages *rq)
{
	phys_bytes cl, cl_addr;
	void *vir;
	struct reserved_pageslot *rps;

	sanitycheck_rq(rq);

	if((cl = alloc_mem(rq->npages, rq->allocflags)) == NO_MEM)
		return ENOMEM;

	cl_addr = CLICK2ABS(cl);

	vir = NULL;

	if(rq->mappedin) {
		if(!(vir = vm_mappages(cl_addr, rq->npages))) {
			free_mem(cl, rq->npages);
			printf("reservedqueue_addslot: vm_mappages failed\n");
			return ENOMEM;
		}
	}

	rps = &rq->slots[rq->n_available];

	reservedqueue_fillslot(rq, rps, cl_addr, vir);

	return OK;
}
int _runprocess(resources computer_resources, node_t *queue) {
  pid_t pid = 0;
  int keep_process = 0;
  process handler = queue->proc;
  printf("%d\n",handler.Mbytes);
  while(queue != NULL) {
    if (keep_process == 0) {
      handler = pop(&queue);
      keep_process = 0;
    }
    if (alloc_mem(computer_resources, handler.Mbytes) != -1) {
      pid  = fork();
      if (pid == -1) {
        return -1;
      } else if (pid == 0) {
        execlp("./process", NULL);
        exit(0);
      } else {
        sleep(handler.processor_time);
        kill(pid, SIGTSTP);
        waitpid(pid, 0, 0);
      }
    } else {
      sleep(1);
      keep_process = 1;
    }
  }
  return EXIT_SUCCESS;
}
Example #30
0
static int
add_page( struct cache *c ) {
  int new_page_index;
  char **new_pages;
  char *new_page;

  new_pages = realloc_mem( c->pages, sizeof( char * ) * ( c->page_count + 1 ) );
  if( !new_pages ) {
    return -1;
  }

  new_page = alloc_mem( c->page_size );
  if( !new_page ) {
    return -1;
  }

  new_page_index = c->page_count;
  c->page_count++;

  c->pages = new_pages;
  c->pages[new_page_index] = new_page;
  init_page( c, new_page_index );

  return new_page_index;
}