[lkml]   [2007]   [Nov]   [13]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
    Patch in this message
    SubjectRe: [PATCH][RFC] kprobes: Add user entry-handler in kretprobes
    On Nov 13, 2007 12:09 AM, Abhishek Sagar <> 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 <>

    diff -X /home/sagara/kprobes/dontdiff -upNr
    --- 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, &copy);
    + if (rp->entry_handler(ri, &copy))
    + goto out; /* skip current kretprobe instance */
    + *regs = copy;
    + } else {
    + arch_prepare_kretprobe(ri, regs);
    + }

    /* XXX(hch): why is there no hlist_move_head? */
    @@ -707,6 +717,7 @@ static int __kprobes pre_handler_kretpro
    hlist_add_head(&ri->hlist, kretprobe_inst_table_head(ri->task));
    } else
    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
    More majordomo info at
    Please read the FAQ at
     \ /
      Last update: 2007-11-13 11:51    [W:0.023 / U:9.008 seconds]
    ©2003-2016 Jasper Spaans. hosted at Digital OceanAdvertise on this site