public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
To: Liuyongan <liuyongan@huawei.com>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Qianhuibin <qianhuibin@huawei.com>
Subject: Re: kprobe pre_handler change return IP
Date: Sun, 20 Oct 2013 01:00:18 +0900	[thread overview]
Message-ID: <5262AC92.3060606@hitachi.com> (raw)
In-Reply-To: <E4ABEE53CC34664FA3F0BD8AEAF50A1941474DB1@szxeml511-mbs.china.huawei.com>

(2013/10/17 21:57), Liuyongan wrote:
> I use kprobe to probe a function suppose: 
>           int is_winter(int num) { ... }
>           int replace_is_winter(int num) { ...} 
> I want to replace is_winter() with replace_is_winter(), so when we call is_winter, replace_is_winter will be called.
>                                                                                                                   
> so:  
>    int my_pre_handler(struct kprobe *p, struct pt_regs *regs)
>    { 
>         regs->ip = (unsigned long)&replace_is_winter;
>         return 1;
>    } 
> 
> and echo 0 > /proc/sys/debug/kprobes-optimization so that jump instruction will not be used.
> 
> I got a exception in fault_handler, and trap number is 14.
> 
>    fault_handler: p->addr = 0xffffffffa08e201a, ip = ffffffff8021c59d, trap #14n
> 
> Anyone here can help me ?

If you want to replace something with kprobes, the pre_handler must clean current_kprobe up.
Actually the same thing has been done in setup_detour_execution(). So, what you need to do is

>    int my_pre_handler(struct kprobe *p, struct pt_regs *regs)
>    {
>         regs->ip = (unsigned long)&replace_is_winter;

          reset_current_kprobe();
          preempt_enable_no_resched();

>         return 1;
>    }

Happy hacking! ;)


Thank you,

-- 
Masami HIRAMATSU
IT Management Research Dept. Linux Technology Center
Hitachi, Ltd., Yokohama Research Laboratory
E-mail: masami.hiramatsu.pt@hitachi.com



  reply	other threads:[~2013-10-19 16:00 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-17 12:57 kprobe pre_handler change return IP Liuyongan
2013-10-19 16:00 ` Masami Hiramatsu [this message]
2013-10-21  6:15   ` Liuyongan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5262AC92.3060606@hitachi.com \
    --to=masami.hiramatsu.pt@hitachi.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=liuyongan@huawei.com \
    --cc=qianhuibin@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox