galileo: Implement _sbrk_r syscall
This patch implements the _sbrk_r() system call for Galileo platform. This system call is required by newlib's malloc() implementation. Next patch will introduce the initial support for stdio library which requires a working malloc() function for proper operation. We are not sure about the heap size we should use. Preliminary tests have shown that stdio library requests 1032 bytes heap. So, as an initial guess, a 2Kb heap size should be enough for now.
This commit is contained in:
parent
15f947fe40
commit
ee82304211
|
@ -31,6 +31,11 @@
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
|
#define HEAP_MAX_SIZE 2048
|
||||||
|
|
||||||
|
static char _heap[HEAP_MAX_SIZE];
|
||||||
|
static char *prog_break = _heap;
|
||||||
|
|
||||||
int
|
int
|
||||||
_close_r(struct _reent *ptr, int file)
|
_close_r(struct _reent *ptr, int file)
|
||||||
{
|
{
|
||||||
|
@ -81,9 +86,21 @@ _fstat_r(struct _reent *ptr, int file, struct stat *st)
|
||||||
caddr_t
|
caddr_t
|
||||||
_sbrk_r(struct _reent *ptr, int incr)
|
_sbrk_r(struct _reent *ptr, int incr)
|
||||||
{
|
{
|
||||||
/* Stubbed function */
|
char *prev_prog_break;
|
||||||
ptr->_errno = ENOTSUP;
|
|
||||||
return NULL;
|
/* If the new program break overruns the maximum heap address, we return
|
||||||
|
* "Out of Memory" error to the user.
|
||||||
|
*/
|
||||||
|
if(prog_break + incr > _heap + HEAP_MAX_SIZE) {
|
||||||
|
ptr->_errno = ENOMEM;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
prev_prog_break = prog_break;
|
||||||
|
|
||||||
|
prog_break += incr;
|
||||||
|
|
||||||
|
return prev_prog_break;
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
void
|
void
|
||||||
|
|
Loading…
Reference in a new issue