/* uprobe_example.c, modified to try to register the same probe 3 times */ #include #include #include #include /* * Usage: insmod wenji3x.ko pid= vaddr=
[verbose=0] * where identifies the probed process and
is the virtual * address of the probed instruction. * * insmod should report success (0) for the first registration attempt * and failure (-16 = EBUSY) for the second and third attempts. The * probe should work. */ static int pid = 0; module_param(pid, int, 0); MODULE_PARM_DESC(pid, "pid"); static int verbose = 1; module_param(verbose, int, 0); MODULE_PARM_DESC(verbose, "verbose"); static long vaddr = 0; module_param(vaddr, long, 0); MODULE_PARM_DESC(vaddr, "vaddr"); static int nhits; static struct uprobe usp; static void uprobe_handler(struct uprobe *u, struct pt_regs *regs) { nhits++; if (verbose) printk(KERN_INFO "Hit #%d on probepoint at %#lx\n", nhits, u->vaddr); } int __init init_module(void) { int ret, try, success = 0; usp.pid = pid; usp.vaddr = vaddr; usp.handler = uprobe_handler; printk(KERN_INFO "Registering uprobe on pid %d, vaddr %#lx\n", usp.pid, usp.vaddr); for (try = 1; try <= 3; try++) { ret = register_uprobe(&usp); printk(KERN_ERR "Try #%d: register_uprobe() returned %d\n", try, ret); if (ret == 0) success++; } return (success ? 0 : ret); } void __exit cleanup_module(void) { printk(KERN_INFO "Unregistering uprobe on pid %d, vaddr %#lx\n", usp.pid, usp.vaddr); printk(KERN_INFO "Probepoint was hit %d times\n", nhits); unregister_uprobe(&usp); } MODULE_LICENSE("GPL");