# obj-m += test-instrument-size-big.o
# obj-m += test-printk-effect.o
endif
- obj-m += test-cmpxchg.o
- obj-m += test-cmpxchg-nolock.o
- obj-m += test-spinlock.o
- obj-m += test-inc.o
- obj-m += test-inc-nolock.o
- obj-m += test-kmalloc.o
- obj-m += test-irqdis.o
+# obj-m += test-cmpxchg.o
+# obj-m += test-cmpxchg-nolock.o
+# obj-m += test-spinlock.o
+# obj-m += test-inc.o
+# obj-m += test-inc-nolock.o
+# obj-m += test-kmalloc.o
+# obj-m += test-irqdis.o
+# obj-m += test-int3.o
+ obj-m += test-kprobes.o
else
KERNELDIR ?= /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
--- /dev/null
+/* test-kprobes.c
+ *
+ * kprobe timing test.
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/kprobes.h>
+#include <linux/kallsyms.h>
+#include <linux/sched.h>
+
+
+/*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("ltt_relay_reserve_slot");
+ /* register the kprobe now */
+ if (!kp.addr) {
+ printk("Couldn't find %s to plant kprobe\n", "ltt_relay_reserve_slot");
+ 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");
+