Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where exactly is the red zone on x86-64?

From 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.

From 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?

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

like image 757
Sep Roland Avatar asked Jun 26 '16 19:06

Sep Roland


People also ask

Where is return address stored in stack?

The function return address is placed on the stack by the x86 CALL instruction, which stores the current value of the EIP register. Then, the frame pointer that is the previous value of the EBP register is placed on the stack.

What is in a stack frame?

Techopedia Explains Stack Frame A stack frame is comprised of: Local variables. Saved copies of registers modified by subprograms that could need restoration. Argument parameters. Return address.

What is stack frame in assembly?

Understanding Frame Pointers Each function has local memory associated with it to hold incoming parameters, local variables, and (in some cases) temporary variables. This region of memory is called a stack frame and is allocated on the process' stack.


1 Answers

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

The red zone is the 128 bytes just below rsp, i.e. rsp - 128 to rsp - 1.

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

Yes.

like image 62
fuz Avatar answered Sep 30 '22 21:09

fuz