3 ms·
Would it be considerably expensive to check in runtime that SP is in an expected range every time it gets moved? This'd work with multiple stacks, too.
by robryk 13y ago
Would it be considerably expensive to check in runtime that SP is in an expected range every time it gets moved? This'd work with multiple stacks, too.
- simias 13y agoWell assuming you run in virtual mode you could always leave the page/segment directly below the stack unmapped, this way if the stack overflows it'll trigger an exception by accessing invalid addresses.
- prutschman 13y agoThere is an enormous class of embedded devices not running on chips capable of address virtualization.
- ctz 13y agoYou don't need virtual memory, just memory protection. Many microprocessors and microcontrollers offer just an MPU, without the full fat of address translation machinery needed for an MMU.
- sitkack 13y agohttp://www.freertos.org/FreeRTOS-MPU-memory-protection-unit.html http://www.freertos.org/FreeRTOS-MPU-memory-protection-unit....
- robryk 13y agoUnless you move the stack pointer by more than a page (the stack in Linux grows automatically: IIRC any access to at most 64k below the stack pointer is considered to be an attempt to grow the stack, because the compiler may very well reorder a change in SP in a function's prelude and an access to the newly-allocated stack frame). Edit: I'm sorry, I was somewhat wrong. Accessing stack below SP is considered a bug, but x86 enter instruction can make it seem like such an access has taken place if it faults: http://lxr.free-electrons.com/source/arch/x86/mm/fault.c?v=3.2#L1136 http://lxr.free-electrons.com/source/arch/x86/mm/fault.c?v=3...
- astrobe_ 13y agoSome very small micro-controller didn't even had a readable stack pointer. The usual trick in this case is to fill the bottom of the stack space with a predefined, well chosen value(s) and to check that those values are still here.