CVS: examples/stackcheck main.c,1.3,1.4
Chris Liechti <[email protected]>
| Newsgroups | gmane.comp.hardware.texas-instruments.msp430.gcc.cvs |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvsroot/mspgcc/examples/stackcheck
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30907/examples/stackcheck
Modified Files:
main.c
Log Message:
use pointer instead of asm variable
Index: main.c
===================================================================
RCS file: /cvsroot/mspgcc/examples/stackcheck/main.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -w -d -r1.3 -r1.4
--- main.c 15 Nov 2004 15:22:06 -0000 1.3
+++ main.c 23 Nov 2004 16:52:24 -0000 1.4
@@ -6,28 +6,12 @@
#include "hardware.h"
/**
- * Address after the last used byte of the last segment in RAM (defined by
- * the linker)
- */
-extern void *__noinit_end;
-
-/**
- * Access to the stack pointer.
- */
-register void * __stackptr asm("r1");
-
-/**
* A constant that is unlikely to be a valid address/a value that occours
* in the code
*/
-#define STACK_GUARD_INIT 0xcf55
+#define STACK_GUARD_INIT 0x0c55
-/**
- * Place this variable after the end of the .no_init section, the last section
- * in the RAM. If the stack would grow too large, it wouldoverwrite this
- * variable.
- */
-extern short stackGuard asm("_end");
+extern unsigned short _end; ///<Last used byte of the last segment in RAM (defined by the linker)
/**
* Initilize the stack checking mechanisms.
@@ -36,14 +20,15 @@
*/
inline void stackProtectionInit(void)
{
- unsigned short *address = &stackGuard;
+ unsigned short *address = &_end;
+ register void * __stackptr asm("r1"); ///<Access to the stack pointer
+ //init stack guard
+ (*address++) = STACK_GUARD_INIT;
//fill free memory with a pattern for debug purpose (see max stack depth)
- for (; address < (unsigned short *)__stackptr; address++)
+ while (address < (unsigned short *)__stackptr)
{
- *address = 0x5aa5;
+ *address++ = 0x7a7a;
}
- //init stack guard
- stackGuard = STACK_GUARD_INIT;
}
/**
@@ -59,7 +44,8 @@
*/
void stackCheck(void)
{
- if (stackGuard != STACK_GUARD_INIT)
+ unsigned short *address = &_end;
+ if ((*address) != STACK_GUARD_INIT)
{
//fatal error: the stack guard was altered -> stack overflow
//~ log(LEVEL_FATAL, "Stack Overflow");
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://productguide.itmanagersjournal.com/