![](/img/trans.png)
[英]How to determine if an instruction is long or short at the event of an exception? (Vairable Length Instructions)
[英]How to get instruction length
这是segv时继续的代码,我不明白“6字节”,为什么是6?
static void sigaction_segv(int signal, siginfo_t *si, void *arg) {
ucontext_t *ctx = (ucontext_t *) arg;
/* We are on linux x86, the returning IP is stored in RIP (64bit) or EIP (32bit).
In this example, the length of the offending instruction is 6 bytes.
So we skip the offender ! */
#if __WORDSIZE == 64
printf("Caught SIGSEGV, addr %p, RIP 0x%lx\n", si->si_addr, ctx->uc_mcontext.gregs[REG_RIP]);
ctx->uc_mcontext.gregs[REG_RIP] += 6;
#else
printf("Caught SIGSEGV, addr %p, EIP 0x%x\n", si->si_addr, ctx->uc_mcontext.gregs[REG_EIP]);
ctx->uc_mcontext.gregs[REG_EIP] += 6;
#endif
}
完整代码在这里
*(int *) NULL = 0;
将编译为(清除 rax 后):
c7 00 00 00 00 00 ' movl $0x0,(%rax)
所以这是 6 个字节的机器码。 使用 objdump 查看代码的程序集。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.