0001
0002
0003
0004
0005
0006
0007 #include <linux/kprobes.h>
0008 #include <linux/ptrace.h>
0009 #include <linux/hardirq.h>
0010 #include <linux/preempt.h>
0011 #include <linux/ftrace.h>
0012
0013 #include "common.h"
0014
0015
0016 void kprobe_ftrace_handler(unsigned long ip, unsigned long parent_ip,
0017 struct ftrace_ops *ops, struct ftrace_regs *fregs)
0018 {
0019 struct pt_regs *regs = ftrace_get_regs(fregs);
0020 struct kprobe *p;
0021 struct kprobe_ctlblk *kcb;
0022 int bit;
0023
0024 bit = ftrace_test_recursion_trylock(ip, parent_ip);
0025 if (bit < 0)
0026 return;
0027
0028 p = get_kprobe((kprobe_opcode_t *)ip);
0029 if (unlikely(!p) || kprobe_disabled(p))
0030 goto out;
0031
0032 kcb = get_kprobe_ctlblk();
0033 if (kprobe_running()) {
0034 kprobes_inc_nmissed_count(p);
0035 } else {
0036 unsigned long orig_ip = regs->ip;
0037
0038 regs->ip = ip + sizeof(kprobe_opcode_t);
0039
0040 __this_cpu_write(current_kprobe, p);
0041 kcb->kprobe_status = KPROBE_HIT_ACTIVE;
0042 if (!p->pre_handler || !p->pre_handler(p, regs)) {
0043
0044
0045
0046
0047 regs->ip = (unsigned long)p->addr + MCOUNT_INSN_SIZE;
0048 if (unlikely(p->post_handler)) {
0049 kcb->kprobe_status = KPROBE_HIT_SSDONE;
0050 p->post_handler(p, regs, 0);
0051 }
0052 regs->ip = orig_ip;
0053 }
0054
0055
0056
0057
0058 __this_cpu_write(current_kprobe, NULL);
0059 }
0060 out:
0061 ftrace_test_recursion_unlock(bit);
0062 }
0063 NOKPROBE_SYMBOL(kprobe_ftrace_handler);
0064
0065 int arch_prepare_kprobe_ftrace(struct kprobe *p)
0066 {
0067 p->ainsn.insn = NULL;
0068 p->ainsn.boostable = false;
0069 return 0;
0070 }