“ret"指令的访问冲突 [英] Access violation on 'ret' instruction
问题描述
我有这个函数,它主要由内联汇编组成.
I've got this function, which consists mostly of inline asm.
long *toarrayl(int members, ...){
__asm{
push esp
mov eax, members
imul eax, 4
push eax
call malloc
mov edx, eax
mov edi, eax
xor ecx, ecx
xor esi, esi
loopx:
cmp ecx, members
je done
mov esi, 4
imul esi, ecx
add esi, ebp
mov eax, [esi+0xC]
mov [edi], eax
inc ecx
add edi, 4
jmp loopx
done:
mov eax, edx
pop esp
ret
}
}
在运行时,我在返回指令中遇到访问冲突.
And upon running, I get an access violation on the return instruction.
我使用的是 VC++ 6,有时可能意味着指向上面的行,因此可能在pop esp"上.如果你能帮助我,那就太好了.谢谢,iDomo.
I'm using VC++ 6, and it can sometimes mean to point at the line above, so possible on 'pop esp'. If you could help me out, it'd be great. Thanks, iDomo.
推荐答案
您未能正确管理堆栈指针.特别是,您对 malloc
的调用会使堆栈不平衡,并且您的 pop esp
最终将错误的值弹出到 esp
中.因此,当您尝试从无效堆栈(CPU 无法读取返回地址)ret
时会发生访问冲突.目前还不清楚你为什么要推送和弹出 esp
;什么也做不了.
You are failing to manage the stack pointer correctly. In particular, your call to malloc
unbalances the stack, and your pop esp
ends up popping the wrong value into esp
. The access violation therefore occurs when you try to ret
from an invalid stack (the CPU cannot read the return address). It's unclear why you are pushing and popping esp
; that accomplishes nothing.
这篇关于“ret"指令的访问冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!