diff options
author | Abhishek Sagar <sagar.abhishek@gmail.com> | 2008-02-06 04:38:22 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2008-02-06 13:41:11 -0500 |
commit | f47cd9b553aaada602449204513b5a5b29cba263 (patch) | |
tree | 079ddd399b1aa00a8c413ef51f3b8681a19a6e7e /kernel | |
parent | 5beec4aa2ac261b0b4992fb41df40a7ab91e4fad (diff) |
kprobes: kretprobe user entry-handler
Provide support to add an optional user defined callback to be run at
function entry of a kretprobe'd function. Also modify the kprobe smoke
tests to include an entry-handler during the kretprobe sanity test.
Signed-off-by: Abhishek Sagar <sagar.abhishek@gmail.com>
Cc: Prasanna S Panchamukhi <prasanna@in.ibm.com>
Cc: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
Cc: Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com>
Acked-by: Jim Keniston <jkenisto@us.ibm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/kprobes.c | 9 | ||||
-rw-r--r-- | kernel/test_kprobes.c | 16 |
2 files changed, 22 insertions, 3 deletions
diff --git a/kernel/kprobes.c b/kernel/kprobes.c index d0493eafea3e..7a86e6432338 100644 --- a/kernel/kprobes.c +++ b/kernel/kprobes.c | |||
@@ -699,6 +699,12 @@ static int __kprobes pre_handler_kretprobe(struct kprobe *p, | |||
699 | struct kretprobe_instance, uflist); | 699 | struct kretprobe_instance, uflist); |
700 | ri->rp = rp; | 700 | ri->rp = rp; |
701 | ri->task = current; | 701 | ri->task = current; |
702 | |||
703 | if (rp->entry_handler && rp->entry_handler(ri, regs)) { | ||
704 | spin_unlock_irqrestore(&kretprobe_lock, flags); | ||
705 | return 0; | ||
706 | } | ||
707 | |||
702 | arch_prepare_kretprobe(ri, regs); | 708 | arch_prepare_kretprobe(ri, regs); |
703 | 709 | ||
704 | /* XXX(hch): why is there no hlist_move_head? */ | 710 | /* XXX(hch): why is there no hlist_move_head? */ |
@@ -745,7 +751,8 @@ int __kprobes register_kretprobe(struct kretprobe *rp) | |||
745 | INIT_HLIST_HEAD(&rp->used_instances); | 751 | INIT_HLIST_HEAD(&rp->used_instances); |
746 | INIT_HLIST_HEAD(&rp->free_instances); | 752 | INIT_HLIST_HEAD(&rp->free_instances); |
747 | for (i = 0; i < rp->maxactive; i++) { | 753 | for (i = 0; i < rp->maxactive; i++) { |
748 | inst = kmalloc(sizeof(struct kretprobe_instance), GFP_KERNEL); | 754 | inst = kmalloc(sizeof(struct kretprobe_instance) + |
755 | rp->data_size, GFP_KERNEL); | ||
749 | if (inst == NULL) { | 756 | if (inst == NULL) { |
750 | free_rp_inst(rp); | 757 | free_rp_inst(rp); |
751 | return -ENOMEM; | 758 | return -ENOMEM; |
diff --git a/kernel/test_kprobes.c b/kernel/test_kprobes.c index 88cdb109e13c..06b6395b45b2 100644 --- a/kernel/test_kprobes.c +++ b/kernel/test_kprobes.c | |||
@@ -135,6 +135,12 @@ static int test_jprobe(void) | |||
135 | #ifdef CONFIG_KRETPROBES | 135 | #ifdef CONFIG_KRETPROBES |
136 | static u32 krph_val; | 136 | static u32 krph_val; |
137 | 137 | ||
138 | static int entry_handler(struct kretprobe_instance *ri, struct pt_regs *regs) | ||
139 | { | ||
140 | krph_val = (rand1 / div_factor); | ||
141 | return 0; | ||
142 | } | ||
143 | |||
138 | static int return_handler(struct kretprobe_instance *ri, struct pt_regs *regs) | 144 | static int return_handler(struct kretprobe_instance *ri, struct pt_regs *regs) |
139 | { | 145 | { |
140 | unsigned long ret = regs_return_value(regs); | 146 | unsigned long ret = regs_return_value(regs); |
@@ -144,13 +150,19 @@ static int return_handler(struct kretprobe_instance *ri, struct pt_regs *regs) | |||
144 | printk(KERN_ERR "Kprobe smoke test failed: " | 150 | printk(KERN_ERR "Kprobe smoke test failed: " |
145 | "incorrect value in kretprobe handler\n"); | 151 | "incorrect value in kretprobe handler\n"); |
146 | } | 152 | } |
153 | if (krph_val == 0) { | ||
154 | handler_errors++; | ||
155 | printk(KERN_ERR "Kprobe smoke test failed: " | ||
156 | "call to kretprobe entry handler failed\n"); | ||
157 | } | ||
147 | 158 | ||
148 | krph_val = (rand1 / div_factor); | 159 | krph_val = rand1; |
149 | return 0; | 160 | return 0; |
150 | } | 161 | } |
151 | 162 | ||
152 | static struct kretprobe rp = { | 163 | static struct kretprobe rp = { |
153 | .handler = return_handler, | 164 | .handler = return_handler, |
165 | .entry_handler = entry_handler, | ||
154 | .kp.symbol_name = "kprobe_target" | 166 | .kp.symbol_name = "kprobe_target" |
155 | }; | 167 | }; |
156 | 168 | ||
@@ -167,7 +179,7 @@ static int test_kretprobe(void) | |||
167 | 179 | ||
168 | ret = kprobe_target(rand1); | 180 | ret = kprobe_target(rand1); |
169 | unregister_kretprobe(&rp); | 181 | unregister_kretprobe(&rp); |
170 | if (krph_val == 0) { | 182 | if (krph_val != rand1) { |
171 | printk(KERN_ERR "Kprobe smoke test failed: " | 183 | printk(KERN_ERR "Kprobe smoke test failed: " |
172 | "kretprobe handler not called\n"); | 184 | "kretprobe handler not called\n"); |
173 | handler_errors++; | 185 | handler_errors++; |