This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Heap and Stack collision check for arm target


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;


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]