Are there any alive CPU architectures with two stacks today?

浪尽此生 提交于 2019-12-24 17:44:12

问题


Is it simpler to prevent buffer overflows explorations with two stacks in general? One stack for variables and passing arguments, the other for return addresses.

Or things like NX/XD-bits (on AMD/Intel x86) as non-executable stack do it better?


回答1:


Itanium has two stacks. I believe one is for storing local variables (like arrays and stuff), while the other is for return addresses. This way, you can't overwrite return addresses by overrunning a buffer.

https://blogs.msdn.microsoft.com/oldnewthing/20050421-28/?p=35833




回答2:


32-bit ARM

Other than loading the program counter from a full descending stack using r13 as the stack pointer being treated as a return for branch prediction purposes the instruction set is neutral as to the register used as the stack pointer or the direction of stack growth. In assembly language "push" and "pop" are just alternative names for load and store instructions.

Thumb, the 16-bit wide instruction set, has a preferred stack pointer but still other registers can be used equally well.

The catch is multiple stacks requires multiple push/pop instructions.

AVR

There are no instructions to add or subtract to the stack pointer, nor are there instructions to atomically set the stack pointer to a new value. Therefore creating a stack frame might involve:

  1. Load low byte of stack pointer.
  2. Load high byte of stack pointer.
  3. Perform a 16-bit subtraction.
  4. Save interrupt enable status.
  5. Disable interrupts.
  6. Store high byte of stack pointer.
  7. Store low byte of stack pointer.
  8. Restore interrupt enable status.

Failing to disable interrupts could result in 200 bytes of RAM being wasted which could result in stack overflow. (Some AVR models have 1024 bytes of RAM)

At least one C compiler uses a pair of general purpose registers as a data stack pointer which can be added to, or subtracted from atomically.



来源:https://stackoverflow.com/questions/34481141/are-there-any-alive-cpu-architectures-with-two-stacks-today

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!