This is the mail archive of the
newlib@sourceware.org
mailing list for the newlib project.
Heap and Stack collision check for arm target
- From: "S, Pitchumani" <Pitchumani dot S at atmel dot com>
- To: "newlib at sourceware dot org" <newlib at sourceware dot org>
- Date: Mon, 26 Aug 2013 10:52:00 +0000
- Subject: Heap and Stack collision check for arm target
- Authentication-results: sourceware.org; auth=none
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;