convert from svn repository: remove tags directory
[lttv.git] / trunk / tests / kernel / test-kprobes2.c
CommitLineData
d9cae1b0 1/* test-kprobes.c
2 *
3 * kprobe timing test.
4 */
5
6#include <linux/kernel.h>
7#include <linux/module.h>
8#include <linux/kprobes.h>
9#include <linux/kallsyms.h>
10#include <linux/sched.h>
11
12
13/*For each probe you need to allocate a kprobe structure*/
14static struct kprobe kp;
15
16/*kprobe pre_handler: called just before the probed instruction is executed*/
17int handler_pre(struct kprobe *p, struct pt_regs *regs)
18{
19 //printk("pre_handler: p->addr=0x%p, eip=%lx, eflags=0x%lx\n",
20 // p->addr, regs->eip, regs->eflags);
21 //dump_stack();
22 return 0;
23}
24
25/*kprobe post_handler: called after the probed instruction is executed*/
26void handler_post(struct kprobe *p, struct pt_regs *regs, unsigned long flags)
27{
28 //printk("post_handler: p->addr=0x%p, eflags=0x%lx\n",
29 // p->addr, regs->eflags);
30}
31
32/* fault_handler: this is called if an exception is generated for any
33 * instruction within the pre- or post-handler, or when Kprobes
34 * single-steps the probed instruction.
35 */
36int handler_fault(struct kprobe *p, struct pt_regs *regs, int trapnr)
37{
38 //printk("fault_handler: p->addr=0x%p, trap #%dn",
39 // p->addr, trapnr);
40 /* Return 0 because we don't handle the fault. */
41 return 0;
42}
43
44int init_module(void)
45{
46 int ret;
47 kp.pre_handler = handler_pre;
48 kp.post_handler = handler_post;
49 kp.fault_handler = handler_fault;
50 //kp.addr = (kprobe_opcode_t*) kallsyms_lookup_name("do_fork");
51 kp.addr = (void*)0xf886b000;
52 /* register the kprobe now */
53 if (!kp.addr) {
54 printk("Couldn't find %s to plant kprobe\n", "do_fork");
55 return -1;
56 }
57 if ((ret = register_kprobe(&kp) < 0)) {
58 printk("register_kprobe failed, returned %d\n", ret);
59 return -1;
60 }
61 printk("kprobe registered\n");
62 return 0;
63}
64
65void cleanup_module(void)
66{
67 unregister_kprobe(&kp);
68 printk("kprobe unregistered\n");
69}
70
71MODULE_LICENSE("GPL");
72MODULE_AUTHOR("Mathieu Desnoyers");
73MODULE_DESCRIPTION("Linux Trace Toolkit Test");
74
This page took 0.028836 seconds and 4 git commands to generate.