Reapply bugfix to sbrk() which got dropped during the move from linx386/libsys
to liblinux. Set errno correctly.
This commit is contained in:
parent
c18a82ec40
commit
fc1b3672a3
2 changed files with 21 additions and 10 deletions
|
@ -5,9 +5,13 @@
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <errno.h>
|
||||||
#include "libsys.h"
|
#include "libsys.h"
|
||||||
|
|
||||||
int brk(void* end)
|
int brk(void* end)
|
||||||
{
|
{
|
||||||
return _syscall(__NR_brk, (quad) end, 0, 0);
|
int e = _syscall(__NR_brk, (quad) end, 0, 0);
|
||||||
|
if (e == -1)
|
||||||
|
errno = ENOMEM;
|
||||||
|
return e;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,32 +1,39 @@
|
||||||
/* $Source: /cvsroot/tack/Ack/plat/linux386/libsys/sbrk.c,v $
|
/* $Source$
|
||||||
* $State: Exp $
|
* $State$
|
||||||
* $Revision: 1.1 $
|
* $Revision$
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <errno.h>
|
||||||
#include "libsys.h"
|
#include "libsys.h"
|
||||||
|
|
||||||
#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)
|
||||||
|
{
|
||||||
|
errno = ENOMEM;
|
||||||
return OUT_OF_MEMORY;
|
return OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
current = new;
|
current = actual;
|
||||||
return old;
|
return old;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue