aboutsummaryrefslogtreecommitdiff
path: root/libgloss
diff options
context:
space:
mode:
authorJeff Johnston <jjohnstn@redhat.com>2007-10-01 18:22:50 +0000
committerJeff Johnston <jjohnstn@redhat.com>2007-10-01 18:22:50 +0000
commiteae493d8a860ae720ade4ceabfb96b42859750d1 (patch)
treec9b2fa79c0f46cfdd800746d28a3eb9331e6048b /libgloss
parent571685454909cbe5af908b4a85a6fab6eb682216 (diff)
downloadnewlib-eae493d8a860ae720ade4ceabfb96b42859750d1.zip
newlib-eae493d8a860ae720ade4ceabfb96b42859750d1.tar.gz
newlib-eae493d8a860ae720ade4ceabfb96b42859750d1.tar.bz2
2007-10-01 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.
Diffstat (limited to 'libgloss')
-rw-r--r--libgloss/ChangeLog7
-rw-r--r--libgloss/spu/sbrk.c5
2 files changed, 10 insertions, 2 deletions
diff --git a/libgloss/ChangeLog b/libgloss/ChangeLog
index 4946812..b9fcadf 100644
--- a/libgloss/ChangeLog
+++ b/libgloss/ChangeLog
@@ -1,3 +1,10 @@
+2007-10-01 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.
+
2007-09-26 Patrick Mansfield <patmans@us.ibm.com>
* spu/sched_yield.c: New file (missed on 2007-09-21).
diff --git a/libgloss/spu/sbrk.c b/libgloss/spu/sbrk.c
index b0528c3..6f21b03 100644
--- a/libgloss/spu/sbrk.c
+++ b/libgloss/spu/sbrk.c
@@ -37,7 +37,6 @@ Author: Andreas Neukoetter (ti95neuk@de.ibm.com)
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;