Is there a programmatic way to check stack corruption

后端 未结 8 1047
北海茫月
北海茫月 2021-02-08 21:29

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

8条回答
  •  猫巷女王i
    2021-02-08 22:00

    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...

提交回复
热议问题