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>
13 /*For each probe you need to allocate a kprobe structure*/
14 static struct kprobe kp
;
16 /*kprobe pre_handler: called just before the probed instruction is executed*/
17 int handler_pre(struct kprobe
*p
, struct pt_regs
*regs
)
19 //printk("pre_handler: p->addr=0x%p, eip=%lx, eflags=0x%lx\n",
20 // p->addr, regs->eip, regs->eflags);
25 /*kprobe post_handler: called after the probed instruction is executed*/
26 void handler_post(struct kprobe
*p
, struct pt_regs
*regs
, unsigned long flags
)
28 //printk("post_handler: p->addr=0x%p, eflags=0x%lx\n",
29 // p->addr, regs->eflags);
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.
36 int handler_fault(struct kprobe
*p
, struct pt_regs
*regs
, int trapnr
)
38 //printk("fault_handler: p->addr=0x%p, trap #%dn",
40 /* Return 0 because we don't handle the fault. */
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("ltt_relay_reserve_slot");
51 /* register the kprobe now */
53 printk("Couldn't find %s to plant kprobe\n", "ltt_relay_reserve_slot");
56 if ((ret
= register_kprobe(&kp
) < 0)) {
57 printk("register_kprobe failed, returned %d\n", ret
);
60 printk("kprobe registered\n");
64 void cleanup_module(void)
66 unregister_kprobe(&kp
);
67 printk("kprobe unregistered\n");
70 MODULE_LICENSE("GPL");
71 MODULE_AUTHOR("Mathieu Desnoyers");
72 MODULE_DESCRIPTION("Linux Trace Toolkit Test");
This page took 0.0296 seconds and 4 git commands to generate.