I am working with a multithreaded embedded application. Each thread is allocated stack sizes based on its functionality. Recently we found that one of the thread corrupted the s
Do you have the kernel source? The last time I wrote a kernel, I added (as an option) stack checking in the kernel itself.
Whenever a context switch was going to occur, the kernel would check 2 stacks:
(1) The task being swapped out -->if the task blew its stack while it was running, let's know right now.
(2) The destination (target) task --> before we jump into the new task, let's make sure some wild code didn't clobber its stack. If its stack is corrupted, don't even switch into the task, we're screwed.
Theoretically the stacks of all tasks could be checked, but the above comments provide the rationale for why I checked these 2 stacks (configurable).
In addition to this, application code can monitor tasks (incl. the interrupt stack if you have one) in the idle loop, the tick ISR, etc...