1

据我了解,在 x86 上,在用户指定的位置uprobe放置一条int3指令,并在遇到异常时处理该异常,kprobe在这方面有点类似。

我不明白的是,do_int3()执行处理程序如何告诉uprobe它何时被击中。相比之下, forkprobe有对kprobe_int3_handlerinside的调用do_int3,所以我的问题是,如何以及在哪里uprobe注册它的处理程序?

这是do_int3来自 x86 上的内核 5.7:

dotraplinkage void notrace do_int3(struct pt_regs *regs, long error_code)
{
    if (poke_int3_handler(regs))
        return;

    if (!user_mode(regs)) {
        rcu_nmi_enter();
        preempt_disable();
    }
    RCU_LOCKDEP_WARN(!rcu_is_watching(), "entry code didn't wake RCU");

#ifdef CONFIG_KGDB_LOW_LEVEL_TRAP
    if (kgdb_ll_trap(DIE_INT3, "int3", regs, error_code, X86_TRAP_BP,
                SIGTRAP) == NOTIFY_STOP)
        goto exit;
#endif /* CONFIG_KGDB_LOW_LEVEL_TRAP */

#ifdef CONFIG_KPROBES
    if (kprobe_int3_handler(regs))
        goto exit;
#endif

    if (notify_die(DIE_INT3, "int3", regs, error_code, X86_TRAP_BP,
            SIGTRAP) == NOTIFY_STOP)
        goto exit;

    cond_local_irq_enable(regs);
    do_trap(X86_TRAP_BP, SIGTRAP, "int3", regs, error_code, 0, NULL);
    cond_local_irq_disable(regs);

exit:
    if (!user_mode(regs)) {
        preempt_enable_no_resched();
        rcu_nmi_exit();
    }
}
4

0 回答 0