linux - Understanding ASM. Why does this work in Windows? -
me , couple of friends fiddling strange issue. encountered crash in our application inside of small assembler portion (used speed process). error caused fiddling stackpointer , not resetting @ end, looked this:
push ebp mov ebp, esp ; stuff here including sub , add on esp pop ebp
when correctly should written as:
push ebp mov ebp, esp ; stuff here including sub , add on esp mov esp,ebp pop ebp
now our mindbreak is: why work in windows? found error ported application linux, encountered crash. neither in windows or android (using ndk) encountered issues , never have found error. there stackpointer recovery? there protection against misusing stackpointer?
the ebp esp usage, called stack frame, , purpose allocate variables on stack, , afterward have quick way restore stack before ret
instruction. new versions of x86 cpu can compress these instructions using enter / leave instructions instead.
esp actual stack pointer used cpu when doing push/pop/call/ret. ebp user-manipulated base pointer, more or less compilers use stack-pointer local storage.
if mov esp, ebp
instruction missing, stack misbehave if esp != ebp when cpu reaches pop ebp
, then.
Comments
Post a Comment