Changed to actually work. (On modern Linux systems the old version just

crashes. On old Linux systems it apparently only worked by accident.)
This commit is contained in:
dtrg 2010-08-06 17:06:31 +00:00
parent 293f34fa9b
commit a0c67da261

View file

@ -9,23 +9,27 @@
#define OUT_OF_MEMORY (void*)(-1) /* sbrk returns this on failure */ #define OUT_OF_MEMORY (void*)(-1) /* sbrk returns this on failure */
extern char _end[1]; static char* current = NULL;
static char* current = _end;
void* sbrk(intptr_t increment) void* sbrk(intptr_t increment)
{ {
char* old; char* old;
char* new; char* new;
char* actual;
if (!current)
current = (char*) _syscall(__NR_brk, 0, 0, 0);
if (increment == 0) if (increment == 0)
return current; return current;
old = current; old = current;
new = old + increment; new = old + increment;
if (brk(new) < 0)
actual = (char*) _syscall(__NR_brk, (quad) new, 0, 0);
if (actual < new)
return OUT_OF_MEMORY; return OUT_OF_MEMORY;
current = new; current = actual;
return old; return old;
} }