From d9cae1b0f2fce2c0aabf6cdaaa7d45e4c480932d Mon Sep 17 00:00:00 2001 From: compudj Date: Thu, 8 May 2008 09:39:23 +0000 Subject: [PATCH] update rcu git-svn-id: http://ltt.polymtl.ca/svn@2903 04897980-b3bd-0310-b5e0-8ef037075253 --- tests/kernel/test-kprobes2.c | 74 ++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 tests/kernel/test-kprobes2.c diff --git a/tests/kernel/test-kprobes2.c b/tests/kernel/test-kprobes2.c new file mode 100644 index 00000000..164ec32d --- /dev/null +++ b/tests/kernel/test-kprobes2.c @@ -0,0 +1,74 @@ +/* test-kprobes.c + * + * kprobe timing test. + */ + +#include +#include +#include +#include +#include + + +/*For each probe you need to allocate a kprobe structure*/ +static struct kprobe kp; + +/*kprobe pre_handler: called just before the probed instruction is executed*/ +int handler_pre(struct kprobe *p, struct pt_regs *regs) +{ + //printk("pre_handler: p->addr=0x%p, eip=%lx, eflags=0x%lx\n", + // p->addr, regs->eip, regs->eflags); + //dump_stack(); + return 0; +} + +/*kprobe post_handler: called after the probed instruction is executed*/ +void handler_post(struct kprobe *p, struct pt_regs *regs, unsigned long flags) +{ + //printk("post_handler: p->addr=0x%p, eflags=0x%lx\n", + // p->addr, regs->eflags); +} + +/* fault_handler: this is called if an exception is generated for any + * instruction within the pre- or post-handler, or when Kprobes + * single-steps the probed instruction. + */ +int handler_fault(struct kprobe *p, struct pt_regs *regs, int trapnr) +{ + //printk("fault_handler: p->addr=0x%p, trap #%dn", + // p->addr, trapnr); + /* Return 0 because we don't handle the fault. */ + return 0; +} + +int init_module(void) +{ + int ret; + kp.pre_handler = handler_pre; + kp.post_handler = handler_post; + kp.fault_handler = handler_fault; + //kp.addr = (kprobe_opcode_t*) kallsyms_lookup_name("do_fork"); + kp.addr = (void*)0xf886b000; + /* register the kprobe now */ + if (!kp.addr) { + printk("Couldn't find %s to plant kprobe\n", "do_fork"); + return -1; + } + if ((ret = register_kprobe(&kp) < 0)) { + printk("register_kprobe failed, returned %d\n", ret); + return -1; + } + printk("kprobe registered\n"); + return 0; +} + +void cleanup_module(void) +{ + unregister_kprobe(&kp); + printk("kprobe unregistered\n"); +} + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Mathieu Desnoyers"); +MODULE_DESCRIPTION("Linux Trace Toolkit Test"); + -- 2.34.1