[英]gnu assembly RET instruction on x86-64 architecture FAIL
The below program causes an SEGMENTATION FAULT.下面的程序会导致 SEGMENTATION FAULT。 The RET
instruction don't recover RETURN ADDRESS TO SYSTEM. RET
指令不会恢复系统的返回地址。
Debugging session with gdb, I can read that the return address IS NOT on the stack.使用 gdb 调试会话,我可以读到返回地址不在堆栈中。 Before the first instruction pushq %rbp
the %rsp
stack pointer reference the 0x00000000 address that is not the return address and cause the SEGMENTATION DEFAULT.第一个指令之前pushq %rbp
的%rsp
堆栈指针引用00000000地址不是返回地址和事业分割DEFAULT。
On debug session when I set the breakpoint on _start label the first instruction to execute is not the Epilogue.... it is the Prologue.在调试会话中,当我在 _start 标签上设置断点时,要执行的第一条指令不是 Epilogue .... 它是 Prologue。
It is clear that the system calling operaion don't operate correctly with the stack pointer and don't save the return address.很明显,系统调用操作没有正确操作堆栈指针,也没有保存返回地址。
I had not this problem on a old 32 bits platform.我在旧的 32 位平台上没有这个问题。
¿Some idea? ¿一些想法? Thanks in advance.提前致谢。
gdb session: gdb 会话:
Reading symbols from /home/candido/tutoriales/as_tutorial/examples/basicos_64/nada/ret_fault...done.
(gdb) b _start
Breakpoint 1 at 0x40007c: file ret_fault.s, line 15.
(gdb) run
Starting program: /home/candido/tutoriales/as_tutorial/examples/basicos_64/nada/ret_fault
(gdb) x /x $rsp
0x7fffffffe068: 0x00000000
(gdb)
as source code:作为源代码:
### Simple Prologue Epilogue Module
### System call don't save the RETURN ADDRESS
### Assembling: as -gstabs -o ret_fault.o ret_fault.s
### Linking: ld -o ret_fault ret_fault.o
### Execution: ./ret_fault
### System warning: SEGMENTATION FAULT
### System platform: Linux lur 3.2.0-33-generic #52-Ubuntu SMP x86_64 GNU/Linux
.text
.globl _start
_start:
## Epilogue
pushq %rbp # save calling frame pointer
movq %rsp, %rbp # set called frame pointer
## Prologue
movl $0, %eax # set return value
popq %rbp # restore calling frame pointer
ret # return to system. Get return address from stack and load on RIP register.
.end
You can't use ret
to end a program.您不能使用ret
来结束程序。 You can use eg.你可以使用例如。 syscall
: syscall
:
movq $0x60, %rax
xorq %rdi, %rdi
syscall
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.