----- Ursprüngliche Nachricht ----- Von: Radu Rendec Gesendet am: 24 Aug 2011 22:27:32
> I'm trying to implement a simple stack checking mechanism in an MSP430 > multi-task environment (task scheduling/switching is subject to a custom > "OS"). > Each task has its own stack space, but since there's a single address > space and the memory is small, tasks can easily overflow their stack and > corrupt "foreign" data. > The best idea I came up with for checking the overflow is adding some > explicit checking code at the beginning of each function - actually at > the end of the preamble, when SP is already lowered to reserve space for > local variables. I had a similar problem but came up with a completely different solution. When my (preemptive) multitasker creates a new thread, it reserves some organizational space as well as the stack for the new thread. The orignaizational data is a linked list for all the threads and begins with a guard code. The new stack space immediately follows and ends with anothe rguard code. When I switch threads, I check the guard codes. If they have been touched, there is something wrong and the affected thread is killed and then a 'thread stack error interrupt' is called for debugging purposes. This way, maybe I don't know when exactly this happened, but it doesn't lower overall performance and safely detects any stack corruption. The code overhead is low too, as the checking is done on a central place that is already called on a task switch. And there's no way to recover from such a situation anyway. And it doesn't need patching the compiler :) JMGross ------------------------------------------------------------------------------ EMC VNX: the world's simplest storage, starting under $10K The only unified storage solution that offers unified management Up to 160% more powerful than alternatives and 25% more efficient. Guaranteed. http://p.sf.net/sfu/emc-vnx-dev2dev _______________________________________________ Mspgcc-users mailing list Mspgcc-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mspgcc-users