Heap and Stack collision check for arm target
S, Pitchumani
Pitchumani.S@atmel.com
Mon Aug 26 10:52:00 GMT 2013
Hi,
For arm target, stack overrun is checked using sp register. Stack
pointer register (sp) will hold the active stack position. If we
have fixed size stack, this check may not detect the stack overrun.
Also, allowing memory allocation till active stack position may
cause stack overrunning into heap, more often.
Stack position to be checked for overrun can be defined by user
through linker script (like 'end'). If may help user to define
fixed size stack. Is this change recommended?
Regards,
Pitchumani
--- a/newlib/libc/sys/arm/syscalls.c
+++ b/newlib/libc/sys/arm/syscalls.c
@@ -50,10 +50,6 @@ static int get_errno _PARAMS ((void));
static int remap_handle _PARAMS ((int));
static int findslot _PARAMS ((int));
-/* Register name faking - works in collusion with the linker. */
-register char * stack_ptr asm ("sp");
-
-
/* following is copied from libc/stdio/local.h to check std streams */
extern void _EXFUN(__sinit,(struct _reent *));
#define CHECK_INIT(ptr) \
@@ -457,6 +453,8 @@ _sbrk (int incr)
extern char end asm ("end"); /* Defined by the linker. */
static char * heap_end;
char * prev_heap_end;
+ extern char stack_end;
+ char * stack_ptr = &stack_end;
if (heap_end == NULL)
heap_end = & end;
More information about the Newlib
mailing list