At 13:10 10/31/2002 -0600, Ward, Garry wrote:
push something to the stack, decrement the address, and if you've gone negative, you've gone too far?
Sure, and the same is true of upwards-growing stacks (only in the other direction, natch). The issue isn't accidental stack overflow.
The difference is in the impact of storage overlays - if your stack grows down, the memory above the current stack frame is your caller's. If your stack grows up, the memory above it is your callee's. Now imagine storing 1000 bytes into a 10-byte buffer on the stack (the classic shellcode-insertion hack). In the grows-down case, you overlay some active memory including possibly the savearea containing the register's you're going to reload when you hit the "return" statement. In the grows-up case, you overlay some inactive memory.
sorry, PC assembler is a long time past, but I vaguely remember the argument being made that top down stacking was easier to manage.
That's true on platforms that actually have stacks (sometimes). The 8080 and it's descendants do, and Intel chose to grow them downwards. It's a design issue, just like little-endian-ness, and IMHO just as wrong. :-) S/390 doesn't have a general-purpose hardware stack, so it's a matter of implementation preference. Ross Patterson
