gpt4 book ai didi

windows - 为什么 malloc 会覆盖 RSP 和 RSP+8?

转载 作者:可可西里 更新时间:2023-11-01 09:47:00 25 4
gpt4 key购买 nike

您可以阅读有关 64 位调用约定的信息 here . x64 函数应该自行清理,但是,当我从 .asm 调用 malloc 时,它会覆盖 RSP 和 RSP+8 处的值。这似乎是非常错误的。有什么建议吗?

public TestMalloc

extern malloc : near

.CODE

align 8
TestMalloc proc
mov rcx, 100h
000000018000BDB8 48 C7 C1 00 01 00 00 mov rcx,100h

call malloc
000000018000BDBF E8 CC AC 06 00 call malloc (180076A90h)

ret
000000018000BDC4 C3 ret
000000018000BDC5 66 66 90 xchg ax,ax
TestMalloc endp

END

最佳答案

对于 x64 调用约定,即使参数在寄存器中传递,调用者也需要在堆栈上为它们节省空间:

Note that space is always allocated for the register parameters, even if the parameters themselves are never homed to the stack; a callee is guaranteed that space has been allocated for all its parameters. Home addresses are required for the register arguments so a contiguous area is available in case the called function needs to take the address of the argument list (va_list) or an individual argument.

http://msdn.microsoft.com/en-us/library/ew5tede7.aspx

关于windows - 为什么 malloc 会覆盖 RSP 和 RSP+8?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/387145/

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