为什么我不能救RIP的价值? [英] Why can't I save the value of rip?
本文介绍了为什么我不能救RIP的价值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
的#include< stdint.h>
uint64_t中撕裂;
诠释的main()
{
ASM(
MOVQ %% RIP,%0 \\ n:= M(RIP)
); 睡眠(10);
}
当我编译
CC -m64 rip.c -o RIP
/tmp/ccwNbZi1.s:汇编的消息:
/tmp/ccwNbZi1.s:12:错误:后缀或操作数`MOVQ无效
使:*** [RIP]错误1
解决方案
您无法读取(E | R)IP
,因为没有86(/ 64)指令直接读取它。
读,它是使与呼叫
指令调用的唯一方法。这将节省堆栈上的返回地址和一个可以读
更新:在64位模式下,可以利用 RIP
-relative寻址,所以 LEA RAX,[ RIP]
会给你本身 EAX
的地址。另一种解决方法是 MOV RAX,$
组装。
#include <stdint.h>
uint64_t rip;
int main()
{
asm(
"movq %%rip, %0\n" : "=m" (rip)
);
sleep(10);
}
When I compile I get
cc -m64 rip.c -o rip
/tmp/ccwNbZi1.s: Assembler messages:
/tmp/ccwNbZi1.s:12: Error: suffix or operands invalid for `movq'
make: *** [rip] Error 1
解决方案
You can't read (E|R)IP
because there's no x86(/64) instruction to read it directly.
The only way to "read" it is to make a call with the CALL
instruction. It will save the return address on the stack and that one you can read.
UPDATE: In 64-bit mode you can exploit the RIP
-relative addressing, so LEA RAX, [RIP]
will give you the address of itself in EAX
. Yet another workaround is MOV RAX, $
in assembly.
这篇关于为什么我不能救RIP的价值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文