Ejemplo n.º 1
0
void v_aalloc_noop(out_ctx *octx, unsigned sz, unsigned align, const char *why)
{
	(void)why;

	align_sz(&sz, align);

	octx->stack_n_alloc += sz;
	v_set_cur_stack_sz(octx, octx->cur_stack_sz + sz);
}
Ejemplo n.º 2
0
const out_val *out_aalloc(
		out_ctx *octx, unsigned sz, unsigned align, type *in_ty)
{
	type *ty = type_ptr_to(in_ty
		? in_ty : type_nav_btype(cc1_type_nav, type_nchar));

	align_sz(&sz, align);

	/* packing takes care of everything */
	pack_next(&octx->cur_stack_sz, NULL, sz, align);

	v_set_cur_stack_sz(octx, octx->cur_stack_sz);

	return v_new_bp3_below(octx, NULL, ty, octx->cur_stack_sz);
}
Ejemplo n.º 3
0
/**
   Get the offset of the halloc structure before a data block
*/
static halloc_t *halloc_from_data( void *data )
{
	return (halloc_t *)(((char *)data) - align_sz(sizeof( halloc_t ) ));
}
Ejemplo n.º 4
0
void *halloc( void *context, size_t size )
{	
	halloc_t *me, *parent;
	if( context )
	{
		char *res;
		char *aligned;
		
#ifdef HALLOC_DEBUG
			
		if( !child_count )
		{
			pid = getpid();
			atexit( &halloc_report );
		}
		 
		child_count++;
		child_size += size;
#endif	
		parent = halloc_from_data( context );

		/*
		  Align memory address 
		*/
		aligned = align_ptr( parent->scratch );

		parent->scratch_free -= (aligned-parent->scratch);

		if( parent->scratch_free < 0 )
			parent->scratch_free=0;
		
		parent->scratch = aligned;

		if( size <= parent->scratch_free )
		{
			res = parent->scratch;
			parent->scratch_free -= size;
			parent->scratch = ((char *)parent->scratch)+size;
		}
		else
		{

#ifdef HALLOC_DEBUG
			alloc_count++;
#endif	
		
			if( parent->scratch_free < HALLOC_SCRAP_SIZE )
			{
#ifdef HALLOC_DEBUG
				alloc_spill += parent->scratch_free;
#endif
				res = calloc( 1, size + HALLOC_BLOCK_SIZE );
				if( !res )
					DIE_MEM();
				parent->scratch = (char *)res + size;
				parent->scratch_free = HALLOC_BLOCK_SIZE;
			}
			else
			{
				res = calloc( 1, size );
				if( !res )
					DIE_MEM();
			}
			al_push_func( &parent->children, &late_free );
			al_push( &parent->children, res );
			
		}
		return res;
	
	}
	else
	{
		me = (halloc_t *)calloc( 1, align_sz(sizeof(halloc_t)) + align_sz(size) + HALLOC_BLOCK_SIZE );
		
		if( !me )
			DIE_MEM();
#ifdef HALLOC_DEBUG
		parent_count++;
#endif		
		me->scratch = ((char *)me) + align_sz(sizeof(halloc_t)) + align_sz(size);
		me->scratch_free = HALLOC_BLOCK_SIZE;
		
		al_init( &me->children );
		return ((char *)me) + align_sz(sizeof(halloc_t));
	}
}