From 61ba39a23786a7ae9694705af1d146c00a319144 Mon Sep 17 00:00:00 2001 From: "Nicolas \"Pixel\" Noble" Date: Sat, 5 Feb 2011 04:35:27 +0100 Subject: Getting rid of newlib, starting to implement a libc. Highly experimental, highly untested. --- os/src/sbrk.c | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) (limited to 'os/src/sbrk.c') diff --git a/os/src/sbrk.c b/os/src/sbrk.c index 53efe1e..fcb6b7a 100644 --- a/os/src/sbrk.c +++ b/os/src/sbrk.c @@ -9,27 +9,15 @@ #include "osdebug.h" -// Mostly stolen from mbed-freertos - extern uintptr_t __heap_start; extern uintptr_t __stack_start; -/* Low-level bulk RAM allocator -- used by Newlib's Malloc */ -static void *heap_end = (void *) &__heap_start; - -static xSemaphoreHandle sbrk_sem = NULL; - -__attribute__((constructor)) static void sbrk_init() { - sbrk_sem = xSemaphoreCreateMutex(); -} +static void * heap_end = (void *) &__heap_start; -void *_sbrk_r(struct _reent *ptr, ptrdiff_t incr) { +void * sbrk(ptrdiff_t incr) { void *prev_heap_end, *next_heap_end, *ret; void *stack_min = (void *) &__stack_start; - if (sbrk_sem) - xSemaphoreTake(sbrk_sem, portMAX_DELAY); - prev_heap_end = heap_end; /* Align to always be on 8-byte boundaries */ @@ -37,15 +25,12 @@ void *_sbrk_r(struct _reent *ptr, ptrdiff_t incr) { /* Check if this allocation would exceed the end of the ram - would probably get into the stack first however */ if (next_heap_end > stack_min) { - ptr->_errno = ENOMEM; + _impure_ptr->_errno = ENOMEM; ret = NULL; } else { heap_end = next_heap_end; ret = (void *)prev_heap_end; } - if (sbrk_sem) - xSemaphoreGive(sbrk_sem); - return ret; } -- cgit v1.2.3