簡體   English   中英

如何獲得指令長度

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM