[PATCH] SPU use current stack pointer to limit sbrk() heap allocation
Jeff Johnston
jjohnstn@redhat.com
Mon Oct 1 18:43:00 GMT 2007
Patch applied.
-- Jeff J.
Patrick Mansfield wrote:
> libgloss ChangeLog:
>
> 2007-09-17 Patrick Mansfield <patmans@us.ibm.com>
>
> * spu/sbrk.c: Use the current stack pointer value rather than the
> maximum available memory to determine the amount of heap space
> left. Without this change calling sbrk() can allocate space that
> is currently in use on the stack.
>
> Index: src/libgloss/spu/sbrk.c
> ===================================================================
> --- src.orig/libgloss/spu/sbrk.c
> +++ src/libgloss/spu/sbrk.c
> @@ -37,7 +37,6 @@ Author: Andreas Neukoetter (ti95neuk@de.
> extern int errno;
>
> extern caddr_t _end;
> -#define RAMSIZE 262144
> #define STACKSIZE 4096
>
> void *
> @@ -47,6 +46,7 @@ sbrk (ptrdiff_t increment)
> caddr_t base;
> vector unsigned int sp_reg, sp_delta;
> vector unsigned int *sp_ptr;
> + caddr_t sps;
>
> /* The stack pointer register. */
> volatile register vector unsigned int sp_r1 __asm__("1");
> @@ -54,7 +54,8 @@ sbrk (ptrdiff_t increment)
> if (heap_ptr == NULL)
> heap_ptr = (caddr_t) & _end;
>
> - if (((RAMSIZE - STACKSIZE) - (int) heap_ptr) >= increment)
> + sps = (caddr_t) spu_extract (sp_r1, 0);
> + if (((int) sps - STACKSIZE - (int) heap_ptr) >= increment)
> {
> base = heap_ptr;
> heap_ptr += increment;
More information about the Newlib
mailing list