x86-64 上的红色区域到底在哪里?

Where exactly is the red zone on x86-64?

来自Wikipedia

In computing, a red zone is a fixed-size area in a function's stack frame beyond the return address which is not preserved by that function. The callee function may use the red zone for storing local variables without the extra overhead of modifying the stack pointer. This region of memory is not to be modified by interrupt/exception/signal handlers. The x86-64 ABI used by System V mandates a 128-byte red zone, which begins directly after the return address and includes the function's arguments. The OpenRISC toolchain assumes a 128-byte red zone.

来自the System V x86-64 ABI

The 128-byte area beyond the location pointed to by %rsp is considered to be reserved and shall not be modified by signal or interrupt handlers. Therefore, functions may use this area for temporary data that is not needed across function calls. In particular, leaf functions may use this area for their entire stack frame, rather than adjusting the stack pointer in the prologue and epilogue. This area is known as the red zone.

Given these two quotes, is the red zone above the stacked return address or below the stacked return address?

红色区域是rsp正下方的128个字节,即rsp - 128rsp - 1

Since this red zone is relative to RSP, does it move downward with each push and does it move upward with each pop?

是的。

关于 红区 的维基百科文章是错误的,因此产生了歧义。

我在 2017 年 4 月修改了这篇文章来解决这个问题。截至该更新,Wikipedia article 为:

In computing, a red zone is a fixed-size area in a function's stack frame beyond the current stack pointer which is not preserved by that function. The callee function may use the red zone for storing local variables without the extra overhead of modifying the stack pointer. This region of memory is not to be modified by interrupt/exception/signal handlers. The x86-64 ABI used by System V mandates a 128-byte red zone, which begins directly under the current value of the stack pointer. The OpenRISC toolchain assumes a 128-byte red zone

这使维基百科文章更符合 64 位系统 V ABI 定义。解决了上面的歧义,关于问题:

Since this red zone is relative to RSP, does it move downward with each push and does it move upward with each pop?

红区 始终是 RSP 下方的 128 个字节。随着 RSP 的变化(通过 PUSH/POP/MOV 等),Red Zone[=27= 的位置也会发生变化].