CDECL 中的程序集清理堆栈导致崩溃
Assembly cleaning up stack in CDECL causes crash
Function CallFunc(Address: PtrUInt; Arg: Array of PtrUInt; isCDecl: Boolean = True): PtrUInt;
{$ASMMODE INTEL}
begin
if (isCDecl) then
asm
mov ecx, 3 //loop 3 times.
mov edx, Arg
@@start:
dec ecx
push dword ptr[edx + ecx * 4] //push 3 pointers onto the stack.
jnz @@start
call [Address]
//Do cleanup
mov ecx, 3
@@end:
dec ecx
pop dword ptr[edx + ecx * 4] //pop each pointer off the stack.
jnz @@end
mov @Result, eax
end;
end;
但是,我在清理时遇到了段错误。如果我不从堆栈中弹出参数,它就不会出现段错误。
在这种情况下,我是否需要将参数从堆栈中弹出或保留它是否安全?
我试过 "ret 12" 但也失败了。
从调用 [Address] 返回后,您的 edx 包含垃圾,所以谁知道您进入了什么。
你不需要弹出任何内存。只需弹出 edx 3 次。
Function CallFunc(Address: PtrUInt; Arg: Array of PtrUInt; isCDecl: Boolean = True): PtrUInt;
{$ASMMODE INTEL}
begin
if (isCDecl) then
asm
mov ecx, 3 //loop 3 times.
mov edx, Arg
@@start:
dec ecx
push dword ptr[edx + ecx * 4] //push 3 pointers onto the stack.
jnz @@start
call [Address]
//Do cleanup
mov ecx, 3
@@end:
dec ecx
pop dword ptr[edx + ecx * 4] //pop each pointer off the stack.
jnz @@end
mov @Result, eax
end;
end;
但是,我在清理时遇到了段错误。如果我不从堆栈中弹出参数,它就不会出现段错误。
在这种情况下,我是否需要将参数从堆栈中弹出或保留它是否安全?
我试过 "ret 12" 但也失败了。
从调用 [Address] 返回后,您的 edx 包含垃圾,所以谁知道您进入了什么。
你不需要弹出任何内存。只需弹出 edx 3 次。