]>
git.proxmox.com Git - mirror_ubuntu-impish-kernel.git/blob - arch/riscv/kernel/probes/ftrace.c
e6372490aa0baf276bf1f46da6933f7dafc45dfc
1 // SPDX-License-Identifier: GPL-2.0
3 #include <linux/kprobes.h>
5 /* Ftrace callback handler for kprobes -- called under preepmt disabed */
6 void kprobe_ftrace_handler(unsigned long ip
, unsigned long parent_ip
,
7 struct ftrace_ops
*ops
, struct ftrace_regs
*regs
)
10 struct kprobe_ctlblk
*kcb
;
12 p
= get_kprobe((kprobe_opcode_t
*)ip
);
13 if (unlikely(!p
) || kprobe_disabled(p
))
16 kcb
= get_kprobe_ctlblk();
17 if (kprobe_running()) {
18 kprobes_inc_nmissed_count(p
);
20 unsigned long orig_ip
= instruction_pointer(&(regs
->regs
));
22 instruction_pointer_set(&(regs
->regs
), ip
);
24 __this_cpu_write(current_kprobe
, p
);
25 kcb
->kprobe_status
= KPROBE_HIT_ACTIVE
;
26 if (!p
->pre_handler
|| !p
->pre_handler(p
, &(regs
->regs
))) {
28 * Emulate singlestep (and also recover regs->pc)
29 * as if there is a nop
31 instruction_pointer_set(&(regs
->regs
),
32 (unsigned long)p
->addr
+ MCOUNT_INSN_SIZE
);
33 if (unlikely(p
->post_handler
)) {
34 kcb
->kprobe_status
= KPROBE_HIT_SSDONE
;
35 p
->post_handler(p
, &(regs
->regs
), 0);
37 instruction_pointer_set(&(regs
->regs
), orig_ip
);
41 * If pre_handler returns !0, it changes regs->pc. We have to
42 * skip emulating post_handler.
44 __this_cpu_write(current_kprobe
, NULL
);
47 NOKPROBE_SYMBOL(kprobe_ftrace_handler
);
49 int arch_prepare_kprobe_ftrace(struct kprobe
*p
)
51 p
->ainsn
.api
.insn
= NULL
;