Questions tagged [red-zone]

The red zone is stack space that's safe from asynchronous modification even though it's not reserved the normal way. Some ABIs (notably the x86-64 SysV ABI) provide one.

The red zone is a fixed-length area of stack space that's safe from asynchronous modification (by signals or interrupts) even though it's outside the reserved part of the stack. (e.g. the first 128 bytes below rsp in the SysV ABI for x86-64, where the stack grows down. See the tag wiki.)

It can be used as a temporary scratch area for the function, in order to avoid having to spend 2 instructions to decrement and increment the stack pointer. The red zone is not preserved across function calls, so it's best used for leaf functions, or in a function tail.

Compiler options can disable use of the red zone for compiler-generated code. For example, Linux kernel code is compiled with -mno-red-zone because it's very difficult if not impossible for x86 interrupt handlers to respect the standard 128B red-zone, unlike signal handlers respecting the user-space stack's red-zone.

The location and implementation of the red zone differs by platform (operating system) .

Resources

51 questions
0
votes
0 answers

Different ways how gcc allocate memory for stack

How does gcc decides how much memory allocate for stack and why does it not decrement %rsp anymore when I remove printf() (or any function call) from my main? 1. I noticed when I played around with a code sample: https://godbolt.org/z/fQqkNE that…
miran80
  • 945
  • 7
  • 22
0
votes
0 answers

Using the Frame pointer instead of the Stack pointer in x86_64

Compiling a simple C code into assembly using GCC will have the following output: ... 13 xorl %eax, %eax 14 movl $0, -4(%rbp) 15 movl $5, -8(%rbp) 16 movl $6, -12(%rbp) 17 movl -8(%rbp),…
Josh
  • 43
  • 1
  • 4
0
votes
2 answers

What is the actual size of stack red zone?

In the x86-64 System V ABI it is specified that the space behind the $rsp - 128 is the so-called red zone which is not touched by any signal handlers. On my machine $ ulimit -s 8192 I expected there is only 2 pages in the stack. So I wrote the…
St.Antario
  • 26,175
  • 41
  • 130
  • 318
0
votes
1 answer

Setting up local stack according to x86-64 calling convention on linux

I am doing some extended assembly optimization on gnu C code running on 64 bit linux. I wanted to print debugging messages from within the assembly code and that's how I came accross the following. I am hoping someone can explain what I am supposed…
Ivan
  • 409
  • 4
  • 17
0
votes
2 answers

Grails: invalid access of stack red zone

I am running a Grails 2.0.4 app on OS X (10.7.4). The app starts without any trouble, but when I try to access the home page in a browser, I get stack red zone errors: Invalid access of stack red zone 0x1139b10c0 rip=0x112e50b70 Bus error: 10 and…
Ben Klein
  • 1,719
  • 3
  • 18
  • 41
-1
votes
1 answer

Value of rbp changing after jumping into a new function

I have the following assembly program: .globl main main: push %rbp mov %rsp, %rbp movb $8, -1(%rbp) movw $30, -4(%rbp) mov -1(%rbp), %rax add -4(%rbp), %rax call func pop %rbp ret func: push %rbp mov…
samuelbrody1249
  • 4,379
  • 1
  • 15
  • 58
1 2 3
4