Red zone (computing)

In computing, the red zone is a fixed-size area in a function's stack frame below (for a push-down stack) the current stack pointer that is reserved and safe to use. It is most commonly used in leaf functions (functions that don't call other functions) for allocating additional stack memory, without moving the stack pointer, which saves an instruction.

Whether a red zone is present depends on the calling convention. x86-64 systems that use the System V AMD64 ABI (including Linux and macOS) use a 128-byte red zone that begins directly under the current value of the stack pointer.[1][2] The OpenRISC toolchain assumes a 128-byte red zone.[3] Microsoft Windows does not have the concept of a red zone on x86.[4] In fact, the ABI explicitly states that the memory beyond the stack pointer is volatile and may be overwritten by debuggers or interrupt handlers.[5][6] However, Microsoft Windows has a red zone of 16 bytes on IA-64, 8 bytes on AArch32, and 16 bytes on AArch64.[6]

The red zone is safe from modification by interrupt/exception/signal handlers.

Notes and references

  1. Michael Matz; Jan Hubička; Andreas Jaeger; et al., eds. (2018-01-28). "System V Application Binary Interface: AMD64 Architecture Processor Supplement (With LP64 and ILP32 Programming Models) Version 1.0" (PDF). 1.0.
  2. "i386 and x86-64 Options - Using the GNU Compiler Collection (GCC)". Retrieved 2011-04-10.
  3. "OpenCores Wiki - OpenRISC GNU toolchain". Retrieved 2014-05-28.
  4. Fog, Agner (2021-01-31). Calling conventions for different C++ compilers and operating systems (PDF). Denmark. p. 20. Retrieved 2021-07-11.{{cite book}}: CS1 maint: location missing publisher (link)
  5. Bendersky, Eli (2011-09-06). "Stack frame layout on x86-64". Eli Bendersky's website. Retrieved 2021-07-11.
  6. Chen, Raymond (2019-01-11). "Why do we even need to define a red zone? Can't I just use my stack for anything?". The Old New Thing. Retrieved 2021-07-11.


This article is issued from Wikipedia. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.