提交 1cabd2f8 编写于 作者: N Naveen N. Rao 提交者: Michael Ellerman

powerpc/kprobes: Factor out code to emulate instruction into a helper

Factor out code to emulate instruction into a try_to_emulate()
helper function. This makes no functional changes.
Acked-by: NAnanth N Mavinakayanahalli <ananth@linux.vnet.ibm.com>
Signed-off-by: NNaveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
Signed-off-by: NMichael Ellerman <mpe@ellerman.id.au>
上级 a64e3f35
...@@ -207,6 +207,35 @@ void __kprobes arch_prepare_kretprobe(struct kretprobe_instance *ri, ...@@ -207,6 +207,35 @@ void __kprobes arch_prepare_kretprobe(struct kretprobe_instance *ri,
regs->link = (unsigned long)kretprobe_trampoline; regs->link = (unsigned long)kretprobe_trampoline;
} }
int __kprobes try_to_emulate(struct kprobe *p, struct pt_regs *regs)
{
int ret;
unsigned int insn = *p->ainsn.insn;
/* regs->nip is also adjusted if emulate_step returns 1 */
ret = emulate_step(regs, insn);
if (ret > 0) {
/*
* Once this instruction has been boosted
* successfully, set the boostable flag
*/
if (unlikely(p->ainsn.boostable == 0))
p->ainsn.boostable = 1;
} else if (ret < 0) {
/*
* We don't allow kprobes on mtmsr(d)/rfi(d), etc.
* So, we should never get here... but, its still
* good to catch them, just in case...
*/
printk("Can't step on instruction %x\n", insn);
BUG();
} else if (ret == 0)
/* This instruction can't be boosted */
p->ainsn.boostable = -1;
return ret;
}
int __kprobes kprobe_handler(struct pt_regs *regs) int __kprobes kprobe_handler(struct pt_regs *regs)
{ {
struct kprobe *p; struct kprobe *p;
...@@ -302,18 +331,9 @@ int __kprobes kprobe_handler(struct pt_regs *regs) ...@@ -302,18 +331,9 @@ int __kprobes kprobe_handler(struct pt_regs *regs)
ss_probe: ss_probe:
if (p->ainsn.boostable >= 0) { if (p->ainsn.boostable >= 0) {
unsigned int insn = *p->ainsn.insn; ret = try_to_emulate(p, regs);
/* regs->nip is also adjusted if emulate_step returns 1 */
ret = emulate_step(regs, insn);
if (ret > 0) { if (ret > 0) {
/*
* Once this instruction has been boosted
* successfully, set the boostable flag
*/
if (unlikely(p->ainsn.boostable == 0))
p->ainsn.boostable = 1;
if (p->post_handler) if (p->post_handler)
p->post_handler(p, regs, 0); p->post_handler(p, regs, 0);
...@@ -321,17 +341,7 @@ int __kprobes kprobe_handler(struct pt_regs *regs) ...@@ -321,17 +341,7 @@ int __kprobes kprobe_handler(struct pt_regs *regs)
reset_current_kprobe(); reset_current_kprobe();
preempt_enable_no_resched(); preempt_enable_no_resched();
return 1; return 1;
} else if (ret < 0) { }
/*
* We don't allow kprobes on mtmsr(d)/rfi(d), etc.
* So, we should never get here... but, its still
* good to catch them, just in case...
*/
printk("Can't step on instruction %x\n", insn);
BUG();
} else if (ret == 0)
/* This instruction can't be boosted */
p->ainsn.boostable = -1;
} }
prepare_singlestep(p, regs); prepare_singlestep(p, regs);
kcb->kprobe_status = KPROBE_HIT_SS; kcb->kprobe_status = KPROBE_HIT_SS;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册