x64 程序集中的“阴影空间"是什么? [英] What is the 'shadow space' in x64 assembly?

查看:18
本文介绍了x64 程序集中的“阴影空间"是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找到了很多关于这个影子空间的话题,但我都找不到答案,所以我的问题是:

I found plenty of topics about this shadow space, but I couldn't find the answer in none of them, so my question is:

在进入过程之前,我需要从堆栈指针中减去多少字节?

How much exactly bytes I need to subtract from the stack pointer, before entering to a procedure?

在减去阴影空间"之前,我应该将过程参数压入堆栈吗?

And should I push the procedure parameters to the stack before subtracting the "shadow space"?

我已经反汇编了我的代码,但我找不到逻辑.

I've disassembled my code, but I couldn't find the logic.

推荐答案

阴影空间(有时也称为溢出空间家庭空间) 位于被调用函数拥有的返回地址上方 32 个字节(并且可以用作暂存空间),低于堆栈参数(如果有).调用者必须在运行 call 指令之前为其被调用者的影子空间保留空间.

The Shadow space (also sometimes called Spill space or Home space) is 32 bytes above the return address which the called function owns (and can use as scratch space), below stack args if any. The caller has to reserve space for their callee's shadow space before running a call instruction.

它旨在使调试 x64 更容易.

It is meant to be used to make debugging x64 easier.

回忆一下 前 4 个参数在寄存器中传递.如果您闯入调试器并检查线程的调用堆栈,您将看不到任何传递给函数的参数.存储在寄存器中的值是暂时的,在调用堆栈向上移动时无法重建.

Recall that the first 4 parameters are passed in registers. If you break into the debugger and inspect the call stack for a thread, you won't be able to see any parameters passed to functions. The values stored in registers are transient and cannot be reconstructed when moving up the call stack.

这是主空间发挥作用的地方:编译器可以使用它在堆栈上留下寄存器值的副本,以便以后在调试器中进行检查.这通常发生在未优化的构建中.但是,当启用优化时,编译器通常会将 Home 空间 视为可供临时使用.堆栈上没有任何副本,调试故障转储变成了一场噩梦.

This is where the Home space comes into play: It can be used by compilers to leave a copy of the register values on the stack for later inspection in the debugger. This usually happens for unoptimized builds. When optimizations are enabled, however, compilers generally treat the Home space as available for scratch use. No copies are left on the stack, and debugging a crash dump turns into a nightmare.

调试挑战优化的 x64 代码提供了有关该问题的深入信息.

Challenges of Debugging Optimized x64 Code offers in-depth information on the issue.

这篇关于x64 程序集中的“阴影空间"是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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