x86-64 上的红色区域究竟在哪里? [英] Where exactly is the red zone on x86-64?

查看:30
本文介绍了x86-64 上的红色区域究竟在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

来自维基百科:

<块引用>

在计算中,红色区域是函数堆栈帧中超出返回地址的固定大小区域,该区域未由该函数保留.被调用函数可以使用红色区域来存储局部变量,而无需修改堆栈指针的额外开销.这个内存区域不会被中断/异常/信号处理程序修改.System V 使用的 x86-64 ABI 要求有一个 128 字节的红色区域,该区域直接在返回地址之后开始并包含函数的参数.OpenRISC 工具链假定一个 128 字节的红色区域.

来自 System V x86-64 ABI:

<块引用>

超出 %rsp 所指位置的 128 字节区域 被认为是保留,不得被信号或中断处理程序修改.因此,函数可以将此区域用于跨函数调用不需要的临时数据.特别是,叶子函数可以将这个区域用于它们的整个堆栈帧,而不是在序言和结尾调整堆栈指针.这个区域被称为红色区域.

  • 鉴于这两个引号,红色区域 上方是堆叠返回地址还是下方堆叠返回地址?p>

  • 由于这个红色区域是相对于RSP的,它是否随着每个push向下移动,它是否随着每个push向上移动?pop?

解决方案

鉴于这两个引号,红色区域是堆叠返回地址上方还是堆叠返回地址下方?

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

<块引用>

由于这个红色区域是相对于 RSP 而言的,它是在每次推动时向下移动,还是在每次弹出时向上移动?

是的.

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?

解决方案

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.

这篇关于x86-64 上的红色区域究竟在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆