--HG-- branch : dtrg-videocore rename : mach/powerpc/as/.distr => mach/vc4/as/.distr rename : mach/powerpc/as/mach0.c => mach/vc4/as/mach0.c rename : mach/powerpc/as/mach1.c => mach/vc4/as/mach1.c rename : mach/powerpc/as/mach2.c => mach/vc4/as/mach2.c rename : mach/powerpc/as/mach3.c => mach/vc4/as/mach3.c rename : mach/powerpc/as/mach4.c => mach/vc4/as/mach4.c rename : mach/powerpc/as/mach5.c => mach/vc4/as/mach5.c rename : mach/i86/build.mk => mach/vc4/build.mk rename : mach/powerpc/libem/powerpc.h => mach/vc4/libem/videocore.h rename : mach/i86/libend/.distr => mach/vc4/libend/.distr rename : mach/i86/libend/edata.s => mach/vc4/libend/edata.s rename : mach/i86/libend/em_end.s => mach/vc4/libend/em_end.s rename : mach/i86/libend/end.s => mach/vc4/libend/end.s rename : mach/i86/libend/etext.s => mach/vc4/libend/etext.s rename : mach/powerpc/ncg/.distr => mach/vc4/ncg/.distr rename : mach/powerpc/ncg/mach.c => mach/vc4/ncg/mach.c rename : mach/powerpc/ncg/mach.h => mach/vc4/ncg/mach.h rename : mach/powerpc/ncg/table => mach/vc4/ncg/table rename : plat/pc86/descr => plat/rpi/descr
		
			
				
	
	
		
			45 lines
		
	
	
	
		
			909 B
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			45 lines
		
	
	
	
		
			909 B
		
	
	
	
		
			C
		
	
	
	
	
	
| /*
 | |
|  * Raspberry Pi support library for the ACK
 | |
|  * © 2013 David Given
 | |
|  * This file is redistributable under the terms of the 3-clause BSD license.
 | |
|  * See the file 'Copying' in the root of the distribution for the full text.
 | |
|  */
 | |
| 
 | |
| #include <stdlib.h>
 | |
| #include <errno.h>
 | |
| #include <unistd.h>
 | |
| 
 | |
| #define	OUT_OF_MEMORY (void*)(-1)	/* sbrk returns this on failure */
 | |
| #define STACK_BUFFER 128 /* number of bytes to leave for stack */
 | |
| 
 | |
| extern char _end[1];
 | |
| static char* current = _end;
 | |
| 
 | |
| int brk(void* newend)
 | |
| {
 | |
| 	/* This variable is used to figure out the current stack pointer,
 | |
| 	 * by taking its address. */
 | |
| 	char dummy;
 | |
| 	char* p = newend;
 | |
| 	
 | |
| 	if ((p > (&dummy - STACK_BUFFER)) ||
 | |
| 	    (p < _end))	
 | |
| 		return -1;
 | |
| 		
 | |
| 	current = p;
 | |
| 	return 0;
 | |
| }
 | |
| 
 | |
| void* sbrk(intptr_t increment)
 | |
| {
 | |
| 	char* old;
 | |
| 	
 | |
| 	if (increment == 0)
 | |
| 		return current;
 | |
| 		
 | |
| 	old = current;
 | |
| 	if (brk(old + increment) < 0)
 | |
| 		return OUT_OF_MEMORY;
 | |
| 		
 | |
| 	return old;
 | |
| }
 |