summaryrefslogtreecommitdiff
path: root/os/src
diff options
context:
space:
mode:
authorNicolas "Pixel" Noble <pixel@nobis-crew.org>2011-01-24 23:50:09 +0100
committerNicolas "Pixel" Noble <pixel@nobis-crew.org>2011-01-24 23:50:09 +0100
commit0066036fc69e887b7f048aa48af61e0ead8daf90 (patch)
tree6e9a686389c13a012d3d869df660f3f112ce0a4e /os/src
parent175b7cdd07bf2266b278de829dbf105b19a198c0 (diff)
Sanitizing sbrk with stack stuff.
Diffstat (limited to 'os/src')
-rw-r--r--os/src/sbrk.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/os/src/sbrk.c b/os/src/sbrk.c
index 221c809..4208b2e 100644
--- a/os/src/sbrk.c
+++ b/os/src/sbrk.c
@@ -8,13 +8,15 @@
// Mostly stolen from mbed-freertos
-extern unsigned int __heap_start, __heap_end;
+extern uintptr_t __heap_start, __heap_end;
+extern uintptr_t __stack_start __attribute__((weak));
/* Low-level bulk RAM allocator -- used by Newlib's Malloc */
void *heap_end = NULL;
PRIVILEGED_FUNCTION void *_sbrk_r(struct _reent *ptr, ptrdiff_t incr)
{
void *prev_heap_end, *next_heap_end, *ret;
+ void *stack_min = (void *)(__stack_start ? __stack_start : __heap_end);
taskENTER_CRITICAL();
{
@@ -27,10 +29,10 @@ PRIVILEGED_FUNCTION void *_sbrk_r(struct _reent *ptr, ptrdiff_t incr)
prev_heap_end = heap_end;
/* Align to always be on 8-byte boundaries */
- next_heap_end = (void *)((((unsigned int)heap_end + incr) + 7) & ~7);
+ next_heap_end = (void *)((((uintptr_t)heap_end + incr) + 7) & ~7);
/* Check if this allocation would exceed the end of the ram - would probably get into the stack first however */
- if (next_heap_end > (void *)&__heap_end)
+ if (next_heap_end > stack_min)
{
ptr->_errno = ENOMEM;
ret = NULL;