2000-02-18 03:39:52 +08:00
|
|
|
#include <_ansi.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include "sys/syscall.h"
|
|
|
|
|
|
|
|
caddr_t
|
|
|
|
_sbrk (int incr)
|
|
|
|
{
|
2011-05-27 18:46:48 +08:00
|
|
|
extern char heap_start; /* Defined by the linker script. */
|
|
|
|
static char * heap_end = NULL;
|
|
|
|
char * prev_heap_end;
|
|
|
|
char * sp = (char *) & sp;
|
|
|
|
|
|
|
|
if (heap_end == NULL)
|
|
|
|
heap_end = & heap_start;
|
2000-02-18 03:39:52 +08:00
|
|
|
|
|
|
|
prev_heap_end = heap_end;
|
2011-05-27 18:46:48 +08:00
|
|
|
|
2000-02-18 03:39:52 +08:00
|
|
|
if (heap_end + incr > sp)
|
|
|
|
{
|
2011-05-27 18:46:48 +08:00
|
|
|
#define MESSAGE "Heap and stack collision\n"
|
|
|
|
_write (1, MESSAGE, sizeof MESSAGE);
|
2000-02-18 03:39:52 +08:00
|
|
|
abort ();
|
|
|
|
}
|
2011-05-27 18:46:48 +08:00
|
|
|
|
2000-02-18 03:39:52 +08:00
|
|
|
heap_end += incr;
|
2011-05-27 18:46:48 +08:00
|
|
|
|
2000-02-18 03:39:52 +08:00
|
|
|
return (caddr_t) prev_heap_end;
|
|
|
|
}
|