From 6a672d5e96038863066b5e3fbe7d7889976077b2 Mon Sep 17 00:00:00 2001 From: David Given Date: Sat, 25 May 2013 23:28:47 +0100 Subject: [PATCH] Heap allocations now works. --HG-- branch : dtrg-videocore --- plat/rpi/build.mk | 14 +++++++------- plat/rpi/libsys/brk.c | 20 ++++++++++---------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/plat/rpi/build.mk b/plat/rpi/build.mk index dffe59d9b..a522046f3 100644 --- a/plat/rpi/build.mk +++ b/plat/rpi/build.mk @@ -18,23 +18,23 @@ platform-headers := \ platform-libsys := \ _hol0.s \ + errno.s \ phys_to_user.s \ user_to_phys.s \ uart.s \ + creat.c \ + close.c \ + open.c \ + read.c \ write.c \ + isatty.c \ + brk.c \ ifeq (x,y) - errno.s \ _sys_rawread.s \ _sys_rawwrite.s \ - open.c \ - creat.c \ - close.c \ - read.c \ - brk.c \ getpid.c \ kill.c \ - isatty.c \ lseek.c \ time.c \ signal.c diff --git a/plat/rpi/libsys/brk.c b/plat/rpi/libsys/brk.c index cff32b9a9..2c44347d4 100644 --- a/plat/rpi/libsys/brk.c +++ b/plat/rpi/libsys/brk.c @@ -8,25 +8,25 @@ #include #include #include +#include #define OUT_OF_MEMORY (void*)(-1) /* sbrk returns this on failure */ -#define STACK_BUFFER 128 /* number of bytes to leave for stack */ +#define STACK_BUFFER 1024 /* number of bytes to leave for stack */ extern char _end[1]; static char* current = _end; +/* Top of heap: we assume that the block of memory the binary is loaded in + * is 256kB long. Because user pointers are always relative to the beginning + * of the block, this makes the end address easy to calculate. */ +static char* max = (char*) (256*1024); + 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)) + if ((newend >= (void*)max) || (newend < (void*)_end)) return -1; - - current = p; + + current = newend; return 0; } -- 2.34.1