On Nov 13, 2007 12:09 AM, Abhishek Sagar <[EMAIL PROTECTED]> wrote: > Whoops...sry for the repeated email..emailer trouble.
Expecting this one to makes it to the list. Summary again: This patch introduces a provision to specify a user-defined callback to run at function entry to complement the return handler in kretprobes. Currently, whenever a kretprobe is registered, a user can specify a callback (return-handler) to be run each time the target function returns. This is also not guaranteed and is limited by the number of concurrently pending return instances of the target function in the current process's context. This patch will now allow registration of another user defined handler which is guaranteed to run each time the current return instance is allocated and the return handler is set-up. Conversely, if the entry-handler returns an error, it'll cause the current return instance to be dropped and the return handler will also not run. The purpose is to provide flexibility to do certain kinds of function level profiling using kretprobes. By being able to register function entry and return handlers, kretprobes will now be able to reduce an extra probe registration (and associated race) for scenarios where an entry handler is required to capture the function call/entry event along with the corresponding function exit event. Hope these simple changes would suffice; all suggestions/corrections are welcome. Signed-off-by: Abhishek Sagar <[EMAIL PROTECTED]> --- diff -X /home/sagara/kprobes/dontdiff -upNr linux-2.6.24-rc2/include/linux/kprobes.h linux-2.6.24-rc2_kp/include/linux/kprobes.h --- linux-2.6.24-rc2/include/linux/kprobes.h 2007-11-07 03:27:46.000000000 +0530 +++ linux-2.6.24-rc2_kp/include/linux/kprobes.h 2007-11-13 16:04:35.000000000 +0530 @@ -152,6 +152,7 @@ static inline int arch_trampoline_kprobe struct kretprobe { struct kprobe kp; kretprobe_handler_t handler; + kretprobe_handler_t entry_handler; int maxactive; int nmissed; struct hlist_head free_instances; diff -X /home/sagara/kprobes/dontdiff -upNr linux-2.6.24-rc2/kernel/kprobes.c linux-2.6.24-rc2_kp/kernel/kprobes.c --- linux-2.6.24-rc2/kernel/kprobes.c 2007-11-07 03:27:46.000000000 +0530 +++ linux-2.6.24-rc2_kp/kernel/kprobes.c 2007-11-13 16:04:17.000000000 +0530 @@ -694,12 +694,22 @@ static int __kprobes pre_handler_kretpro spin_lock_irqsave(&kretprobe_lock, flags); if (!hlist_empty(&rp->free_instances)) { struct kretprobe_instance *ri; + struct pt_regs copy; ri = hlist_entry(rp->free_instances.first, struct kretprobe_instance, uflist); ri->rp = rp; ri->task = current; - arch_prepare_kretprobe(ri, regs); + + if (rp->entry_handler) { + copy = *regs; + arch_prepare_kretprobe(ri, ©); + if (rp->entry_handler(ri, ©)) + goto out; /* skip current kretprobe instance */ + *regs = copy; + } else { + arch_prepare_kretprobe(ri, regs); + } /* XXX(hch): why is there no hlist_move_head? */ hlist_del(&ri->uflist); @@ -707,6 +717,7 @@ static int __kprobes pre_handler_kretpro hlist_add_head(&ri->hlist, kretprobe_inst_table_head(ri->task)); } else rp->nmissed++; +out: spin_unlock_irqrestore(&kretprobe_lock, flags); return 0; } - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/