diff options
author | Till Straumann <strauman@slac.stanford.edu> | 2011-05-18 05:26:53 +0000 |
---|---|---|
committer | Till Straumann <strauman@slac.stanford.edu> | 2011-05-18 05:26:53 +0000 |
commit | 4f599ed99fc0aa37bc4d100cf787880c1e1bb97a (patch) | |
tree | 56fa22232321006e3aa761e38495a786d0f3632d /c/src/lib/libbsp/powerpc/shared/startup/sbrk.c | |
parent | 2011-05-16 Yaakov Selkowitz <yselkowitz@users.sourceforge.net> (diff) | |
download | rtems-4f599ed99fc0aa37bc4d100cf787880c1e1bb97a.tar.bz2 |
2011-05-18 Till Straumann <strauman@slac.stanford.edu>
PR1797/bsps: Applied cleaned-up version of Kate's patch.
CONFIGURE_MALLOC_BSP_SUPPORTS_SBRK is now a 'bspopts.h'
setting and as such configurable.
Diffstat (limited to 'c/src/lib/libbsp/powerpc/shared/startup/sbrk.c')
-rw-r--r-- | c/src/lib/libbsp/powerpc/shared/startup/sbrk.c | 48 |
1 files changed, 21 insertions, 27 deletions
diff --git a/c/src/lib/libbsp/powerpc/shared/startup/sbrk.c b/c/src/lib/libbsp/powerpc/shared/startup/sbrk.c index 5d352132bd..dc6b49c6ef 100644 --- a/c/src/lib/libbsp/powerpc/shared/startup/sbrk.c +++ b/c/src/lib/libbsp/powerpc/shared/startup/sbrk.c @@ -70,8 +70,8 @@ #include <sys/types.h> #include <unistd.h> -static uint32_t remaining_start=0; -static uint32_t remaining_size=0; +static void * remaining_start=(void*)-1LL; +static uintptr_t remaining_size=0; /* App. may provide a value by defining the BSP_sbrk_policy * variable. @@ -81,16 +81,17 @@ static uint32_t remaining_size=0; * 0 -> limit memory effectively to 32M. * */ -extern uint32_t BSP_sbrk_policy __attribute__((weak)); +extern uintptr_t BSP_sbrk_policy __attribute__((weak)); -#define LIMIT_32M 0x02000000 +#define LIMIT_32M ((void*)0x02000000) -uintptr_t _bsp_sbrk_init( - uintptr_t heap_start, +uintptr_t bsp_sbrk_init( + void *heap_start, uintptr_t *heap_size_p ) { uintptr_t rval=0; + uintptr_t policy; remaining_start = heap_start; remaining_size = *heap_size_p; @@ -104,29 +105,22 @@ uintptr_t _bsp_sbrk_init( remaining_size = rval; } - if ( 0 != &BSP_sbrk_policy ) { - switch ( BSP_sbrk_policy ) { - case (uint32_t)(-1): - *heap_size_p += rval; - remaining_start = heap_start + *heap_size_p; - remaining_size = 0; - /* return a nonzero sbrk_amount because the libsupport code - * at some point divides by this number prior to trying an - * sbrk() which will fail. - */ - rval = 1; - break; + policy = (0 == &BSP_sbrk_policy ? (uintptr_t)(-1) : BSP_sbrk_policy); + switch ( policy ) { + case (uintptr_t)(-1): + *heap_size_p += rval; + remaining_start = heap_start + *heap_size_p; + remaining_size = 0; + break; case 0: - remaining_size = 0; - /* see above for why we return 1 */ - rval = 1; - break; + remaining_size = 0; + break; default: - if ( rval > BSP_sbrk_policy ) - rval = BSP_sbrk_policy; - break; + if ( rval > policy ) + rval = policy; + break; } } @@ -143,9 +137,9 @@ void *bsp_sbrk(ptrdiff_t incr) void *rval=(void*)-1; /* FIXME: BEWARE if size >2G */ - if (incr <= remaining_size) { + if ( remaining_start != (void*)-1LL && incr <= remaining_size) { remaining_size-=incr; - rval = (void*)remaining_start; + rval = remaining_start; remaining_start += incr; } else { errno = ENOMEM; |