“ 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
。因此,当您尝试从无效堆栈中进行 ret
的访问时,将发生访问冲突(CPU无法读取返回地址)。目前尚不清楚为什么要推动并弹出 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屋!