Fix heap allocation when used with RTOS

Remove the code which checks the heap against the stack to determine
if there is space left.  Using the stack pointer as a limit causes
problems when used with an RTOS since the stack pointer depends
on the current thread which can use a user-allocated stack residing
anywhere in memory.
Russ Butler 2016-04-07 18:09:55 -05:00 committed by Russ Butler
parent 98a8c49f00
commit 6b4dfeb1ab
2 changed files with 1 additions and 7 deletions

View File

@ -461,9 +461,7 @@ extern "C" void __iar_argc_argv() {
// Linker defined symbol used by _sbrk to indicate where heap should start.
extern "C" int __end__;
#if defined(TARGET_CORTEX_A)
extern "C" uint32_t __HeapLimit;
#endif
// Turn off the errno macro and use actual global variable instead.
#undef errno
@ -486,11 +484,7 @@ extern "C" caddr_t _sbrk(int incr) {
unsigned char* prev_heap = heap;
unsigned char* new_heap = heap + incr;
#if defined(TARGET_CORTEX_A)
if (new_heap >= (unsigned char*)&__HeapLimit) { /* __HeapLimit is end of heap section */
#else
if (new_heap >= (unsigned char*)__current_sp()) {
#endif
errno = ENOMEM;
return (caddr_t)-1;
}

View File

@ -64,7 +64,7 @@ __StackTop:
#ifdef __HEAP_SIZE
.equ Heap_Size, __HEAP_SIZE
#else
.equ Heap_Size, 0x400
.equ Heap_Size, 0x20000
#endif
.globl __HeapBase
.globl __HeapLimit