Is there a programmatic way to check stack corruption

后端 未结 8 1046
北海茫月
北海茫月 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条回答
  •  眼角桃花
    2021-02-08 22:11

    Checkout these similar questions: handling stack overflows in embedded systems and how can I visualise the memory sram usage of an avr program.

    Personally I would use the Memory Management Unit of your Processor it it has one. It can do memory checking for you with minimal software overhead.

    Set up a memory area in the MMU that will be used for the stack. It should be bordered by two memory areas where the MMU does not allow access. When your application is running you will receive a exception/interrupt as soon as you overflow the stack.

    Because you get a exception at the moment the error occur you know exactly where in your application the stack went bad. You can look at the call stack to see exactly how you got to where you are. This makes it a lot easier to find your problem than trying to figure out what is wrong by detecting your problem long after it happened.

    A MMU can also detect zero pointer accesses if you disallow memory access to the bottom part of your ram.

    If you have the source of the RTOS you can build MMU protection of the stack and heap into it.

提交回复
热议问题