aboutsummaryrefslogtreecommitdiffstats
path: root/arch
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@lst.de>2007-05-08 03:34:14 -0400
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2007-05-08 14:15:19 -0400
commit4c4308cb93450989846ac49faeb6dab943e7657e (patch)
treec06092cae6f95a243cdd758d07491cf5fa24a1dd /arch
parent6f716acd5fa20ae6a35ab29ae37fa9189e839ed5 (diff)
kprobes: kretprobes simplifications
- consolidate duplicate code in all arch_prepare_kretprobe instances into common code - replace various odd helpers that use hlist_for_each_entry to get the first elemenet of a list with either a hlist_for_each_entry_save or an opencoded access to the first element in the caller - inline add_rp_inst into it's only remaining caller - use kretprobe_inst_table_head instead of opencoding it Signed-off-by: Christoph Hellwig <hch@lst.de> Cc: Prasanna S Panchamukhi <prasanna@in.ibm.com> Acked-by: Ananth N Mavinakayanahalli <ananth@in.ibm.com> Cc: Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'arch')
-rw-r--r--arch/i386/kernel/kprobes.c17
-rw-r--r--arch/ia64/kernel/kprobes.c18
-rw-r--r--arch/powerpc/kernel/kprobes.c19
-rw-r--r--arch/s390/kernel/kprobes.c18
-rw-r--r--arch/x86_64/kernel/kprobes.c17
5 files changed, 21 insertions, 68 deletions
diff --git a/arch/i386/kernel/kprobes.c b/arch/i386/kernel/kprobes.c
index 3fbef288c376..b6a9d64c2251 100644
--- a/arch/i386/kernel/kprobes.c
+++ b/arch/i386/kernel/kprobes.c
@@ -226,24 +226,15 @@ static void __kprobes prepare_singlestep(struct kprobe *p, struct pt_regs *regs)
226} 226}
227 227
228/* Called with kretprobe_lock held */ 228/* Called with kretprobe_lock held */
229void __kprobes arch_prepare_kretprobe(struct kretprobe *rp, 229void __kprobes arch_prepare_kretprobe(struct kretprobe_instance *ri,
230 struct pt_regs *regs) 230 struct pt_regs *regs)
231{ 231{
232 unsigned long *sara = (unsigned long *)&regs->esp; 232 unsigned long *sara = (unsigned long *)&regs->esp;
233 233
234 struct kretprobe_instance *ri; 234 ri->ret_addr = (kprobe_opcode_t *) *sara;
235 235
236 if ((ri = get_free_rp_inst(rp)) != NULL) { 236 /* Replace the return addr with trampoline addr */
237 ri->rp = rp; 237 *sara = (unsigned long) &kretprobe_trampoline;
238 ri->task = current;
239 ri->ret_addr = (kprobe_opcode_t *) *sara;
240
241 /* Replace the return addr with trampoline addr */
242 *sara = (unsigned long) &kretprobe_trampoline;
243 add_rp_inst(ri);
244 } else {
245 rp->nmissed++;
246 }
247} 238}
248 239
249/* 240/*
diff --git a/arch/ia64/kernel/kprobes.c b/arch/ia64/kernel/kprobes.c
index 353689edebd5..0b72f0f94192 100644
--- a/arch/ia64/kernel/kprobes.c
+++ b/arch/ia64/kernel/kprobes.c
@@ -465,23 +465,13 @@ int __kprobes trampoline_probe_handler(struct kprobe *p, struct pt_regs *regs)
465} 465}
466 466
467/* Called with kretprobe_lock held */ 467/* Called with kretprobe_lock held */
468void __kprobes arch_prepare_kretprobe(struct kretprobe *rp, 468void __kprobes arch_prepare_kretprobe(struct kretprobe_instance *ri,
469 struct pt_regs *regs) 469 struct pt_regs *regs)
470{ 470{
471 struct kretprobe_instance *ri; 471 ri->ret_addr = (kprobe_opcode_t *)regs->b0;
472 472
473 if ((ri = get_free_rp_inst(rp)) != NULL) { 473 /* Replace the return addr with trampoline addr */
474 ri->rp = rp; 474 regs->b0 = ((struct fnptr *)kretprobe_trampoline)->ip;
475 ri->task = current;
476 ri->ret_addr = (kprobe_opcode_t *)regs->b0;
477
478 /* Replace the return addr with trampoline addr */
479 regs->b0 = ((struct fnptr *)kretprobe_trampoline)->ip;
480
481 add_rp_inst(ri);
482 } else {
483 rp->nmissed++;
484 }
485} 475}
486 476
487int __kprobes arch_prepare_kprobe(struct kprobe *p) 477int __kprobes arch_prepare_kprobe(struct kprobe *p)
diff --git a/arch/powerpc/kernel/kprobes.c b/arch/powerpc/kernel/kprobes.c
index 3d54ad7dd1f9..aed58e1cb91f 100644
--- a/arch/powerpc/kernel/kprobes.c
+++ b/arch/powerpc/kernel/kprobes.c
@@ -126,22 +126,13 @@ static void __kprobes set_current_kprobe(struct kprobe *p, struct pt_regs *regs,
126} 126}
127 127
128/* Called with kretprobe_lock held */ 128/* Called with kretprobe_lock held */
129void __kprobes arch_prepare_kretprobe(struct kretprobe *rp, 129void __kprobes arch_prepare_kretprobe(struct kretprobe_instance *ri,
130 struct pt_regs *regs) 130 struct pt_regs *regs)
131{ 131{
132 struct kretprobe_instance *ri; 132 ri->ret_addr = (kprobe_opcode_t *)regs->link;
133 133
134 if ((ri = get_free_rp_inst(rp)) != NULL) { 134 /* Replace the return addr with trampoline addr */
135 ri->rp = rp; 135 regs->link = (unsigned long)kretprobe_trampoline;
136 ri->task = current;
137 ri->ret_addr = (kprobe_opcode_t *)regs->link;
138
139 /* Replace the return addr with trampoline addr */
140 regs->link = (unsigned long)kretprobe_trampoline;
141 add_rp_inst(ri);
142 } else {
143 rp->nmissed++;
144 }
145} 136}
146 137
147static int __kprobes kprobe_handler(struct pt_regs *regs) 138static int __kprobes kprobe_handler(struct pt_regs *regs)
diff --git a/arch/s390/kernel/kprobes.c b/arch/s390/kernel/kprobes.c
index 8516a94d8163..9d0f0d09d473 100644
--- a/arch/s390/kernel/kprobes.c
+++ b/arch/s390/kernel/kprobes.c
@@ -271,23 +271,13 @@ static void __kprobes set_current_kprobe(struct kprobe *p, struct pt_regs *regs,
271} 271}
272 272
273/* Called with kretprobe_lock held */ 273/* Called with kretprobe_lock held */
274void __kprobes arch_prepare_kretprobe(struct kretprobe *rp, 274void __kprobes arch_prepare_kretprobe(struct kretprobe_instance *ri,
275 struct pt_regs *regs) 275 struct pt_regs *regs)
276{ 276{
277 struct kretprobe_instance *ri; 277 ri->ret_addr = (kprobe_opcode_t *) regs->gprs[14];
278 278
279 if ((ri = get_free_rp_inst(rp)) != NULL) { 279 /* Replace the return addr with trampoline addr */
280 ri->rp = rp; 280 regs->gprs[14] = (unsigned long)&kretprobe_trampoline;
281 ri->task = current;
282 ri->ret_addr = (kprobe_opcode_t *) regs->gprs[14];
283
284 /* Replace the return addr with trampoline addr */
285 regs->gprs[14] = (unsigned long)&kretprobe_trampoline;
286
287 add_rp_inst(ri);
288 } else {
289 rp->nmissed++;
290 }
291} 281}
292 282
293static int __kprobes kprobe_handler(struct pt_regs *regs) 283static int __kprobes kprobe_handler(struct pt_regs *regs)
diff --git a/arch/x86_64/kernel/kprobes.c b/arch/x86_64/kernel/kprobes.c
index 5841ba5f479b..f995bea6e2c1 100644
--- a/arch/x86_64/kernel/kprobes.c
+++ b/arch/x86_64/kernel/kprobes.c
@@ -266,23 +266,14 @@ static void __kprobes prepare_singlestep(struct kprobe *p, struct pt_regs *regs)
266} 266}
267 267
268/* Called with kretprobe_lock held */ 268/* Called with kretprobe_lock held */
269void __kprobes arch_prepare_kretprobe(struct kretprobe *rp, 269void __kprobes arch_prepare_kretprobe(struct kretprobe_instance *ri,
270 struct pt_regs *regs) 270 struct pt_regs *regs)
271{ 271{
272 unsigned long *sara = (unsigned long *)regs->rsp; 272 unsigned long *sara = (unsigned long *)regs->rsp;
273 struct kretprobe_instance *ri;
274 273
275 if ((ri = get_free_rp_inst(rp)) != NULL) { 274 ri->ret_addr = (kprobe_opcode_t *) *sara;
276 ri->rp = rp; 275 /* Replace the return addr with trampoline addr */
277 ri->task = current; 276 *sara = (unsigned long) &kretprobe_trampoline;
278 ri->ret_addr = (kprobe_opcode_t *) *sara;
279
280 /* Replace the return addr with trampoline addr */
281 *sara = (unsigned long) &kretprobe_trampoline;
282 add_rp_inst(ri);
283 } else {
284 rp->nmissed++;
285 }
286} 277}
287 278
288int __kprobes kprobe_handler(struct pt_regs *regs) 279int __kprobes kprobe_handler(struct pt_regs *regs)