gpt4 book ai didi

assembly - 使用 esp 下面的堆栈是否安全?

转载 作者:行者123 更新时间:2023-12-04 22:38:37 26 4
gpt4 key购买 nike

我有一个从 c 程序调用的简单汇编函数,我必须使用需要内存操作数的指令( FIDIV )。

将值移动到 [esp - 2] 是否安全并在下一条指令中使用它,或者以这种方式使用堆栈永远不会安全?

我知道有很多解决方法,我真的不再需要这个了,所以现在只是好奇。

最佳答案

使用这样的偏移量肯定会在线程上的任何操作需要再次接触堆栈时将数据暴露给损坏。这可能发生在中断、APC、上下文切换、异常等期间。您要做的是实际在堆栈上保留空间并保存指向它的指针。

sub esp, 4        ; Allways move it 4 byte increments. x64 may need 8 bytes
mov eax, esp ; EAX points to your 4 byte buffer
add esp, 4 ; Restore allocation.

当然如果你只需要几个字节,push指令会快很多
push eax
mov eax, esp ; EAX points to a buffer properly alligned to system

关于assembly - 使用 esp 下面的堆栈是否安全?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/778690/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com