example_allocators/bump_allocator/bump_alloc.c
char *bump_alloc(int len)
{
	char *chunk = buffer + count;
	size_t rounded_len; /* for CHERI alignment */
	size_t new_count;	/* for buffer overflow check */

	/* ensure we can represent the capability accurately,
	 * see p30 of CHERI C/C++ Prog Guide (June 2020)
	 * www.cl.cam.ac.uk/techreports/UCAM-CL-TR-947
	 */
	chunk = __builtin_align_up(chunk, ~cheri_representable_alignment_mask(len) + 1);
	rounded_len = cheri_representable_length(len);

	new_count = (chunk + rounded_len) - buffer;
	if (new_count > max)
	{
		/* out of bounds - don't allocate anything */
		chunk = 0;
	}
	else
	{
		/* restrict capability range before returning ptr */
		chunk = cheri_bounds_set_exact(chunk, rounded_len);

		/* update bytes allocated count */
		count = new_count;
	}

	return chunk;
}
/*
 * allocate len bytes with bump pointer allocator
 * this is our simplistic `malloc` function
 */
allocate len bytes with bump pointer allocator
this is our simplistic `malloc` function
allocate len bytes with bump pointer allocator this is our simplistic ` malloc ` function
char *bump_alloc(int len)
{
	char *chunk = buffer + count;
	size_t rounded_len; 
	size_t new_count;	
	chunk = __builtin_align_up(chunk, ~cheri_representable_alignment_mask(len) + 1);
	rounded_len = cheri_representable_length(len);
	new_count = (chunk + rounded_len) - buffer;
	if (new_count > max)
	{
		chunk = 0;
	}
	else
	{
		chunk = cheri_bounds_set_exact(chunk, rounded_len);
		count = new_count;
	}
	return chunk;
}
char * bump_alloc ( int len ) { char * chunk = buffer + count ; size_t rounded_len ; size_t new_count ; chunk = __builtin_align_up ( chunk , ~ cheri_representable_alignment_mask ( len ) + 1 ) ; rounded_len = cheri_representable_length ( len ) ; new_count = ( chunk + rounded_len ) - buffer ; if ( new_count > max ) { chunk = 0 ; } else { chunk = cheri_bounds_set_exact ( chunk , rounded_len ) ; count = new_count ; } return chunk ; }
allocate len bytes with bump pointer allocator
 this is our simplistic `malloc` function
allocate len bytes with bump pointer allocator this is our simplistic ` malloc ` function
/* for CHERI alignment */ /* for buffer overflow check */ /* ensure we can represent the capability accurately,
	 * see p30 of CHERI C/C++ Prog Guide (June 2020)
	 * www.cl.cam.ac.uk/techreports/UCAM-CL-TR-947
	 */ /* out of bounds - don't allocate anything */ /* restrict capability range before returning ptr */ /* update bytes allocated count */