diff options
author | Ananth N Mavinakayanahalli <ananth@in.ibm.com> | 2006-10-02 05:17:30 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@g5.osdl.org> | 2006-10-02 10:57:16 -0400 |
commit | 3a872d89baae821a0f6e2c1055d4b47650661137 (patch) | |
tree | 5ac6aa55e04960e02f25ff5079078f975957b1b3 /kernel/kprobes.c | |
parent | 782237a2418e2561a87c86a4832726931adce737 (diff) |
[PATCH] Kprobes: Make kprobe modules more portable
In an effort to make kprobe modules more portable, here is a patch that:
o Introduces the "symbol_name" field to struct kprobe.
The symbol->address resolution now happens in the kernel in an
architecture agnostic manner. 64-bit powerpc users no longer have
to specify the ".symbols"
o Introduces the "offset" field to struct kprobe to allow a user to
specify an offset into a symbol.
o The legacy mechanism of specifying the kprobe.addr is still supported.
However, if both the kprobe.addr and kprobe.symbol_name are specified,
probe registration fails with an -EINVAL.
o The symbol resolution code uses kallsyms_lookup_name(). So
CONFIG_KPROBES now depends on CONFIG_KALLSYMS
o Apparantly kprobe modules were the only legitimate out-of-tree user of
the kallsyms_lookup_name() EXPORT. Now that the symbol resolution
happens in-kernel, remove the EXPORT as suggested by Christoph Hellwig
o Modify tcp_probe.c that uses the kprobe interface so as to make it
work on multiple platforms (in its earlier form, the code wouldn't
work, say, on powerpc)
Signed-off-by: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
Signed-off-by: Prasanna S Panchamukhi <prasanna@in.ibm.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'kernel/kprobes.c')
-rw-r--r-- | kernel/kprobes.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/kernel/kprobes.c b/kernel/kprobes.c index 3f57dfdc8f92..f66b8e681b4d 100644 --- a/kernel/kprobes.c +++ b/kernel/kprobes.c | |||
@@ -37,6 +37,7 @@ | |||
37 | #include <linux/slab.h> | 37 | #include <linux/slab.h> |
38 | #include <linux/module.h> | 38 | #include <linux/module.h> |
39 | #include <linux/moduleloader.h> | 39 | #include <linux/moduleloader.h> |
40 | #include <linux/kallsyms.h> | ||
40 | #include <asm-generic/sections.h> | 41 | #include <asm-generic/sections.h> |
41 | #include <asm/cacheflush.h> | 42 | #include <asm/cacheflush.h> |
42 | #include <asm/errno.h> | 43 | #include <asm/errno.h> |
@@ -45,6 +46,16 @@ | |||
45 | #define KPROBE_HASH_BITS 6 | 46 | #define KPROBE_HASH_BITS 6 |
46 | #define KPROBE_TABLE_SIZE (1 << KPROBE_HASH_BITS) | 47 | #define KPROBE_TABLE_SIZE (1 << KPROBE_HASH_BITS) |
47 | 48 | ||
49 | |||
50 | /* | ||
51 | * Some oddball architectures like 64bit powerpc have function descriptors | ||
52 | * so this must be overridable. | ||
53 | */ | ||
54 | #ifndef kprobe_lookup_name | ||
55 | #define kprobe_lookup_name(name, addr) \ | ||
56 | addr = ((kprobe_opcode_t *)(kallsyms_lookup_name(name))) | ||
57 | #endif | ||
58 | |||
48 | static struct hlist_head kprobe_table[KPROBE_TABLE_SIZE]; | 59 | static struct hlist_head kprobe_table[KPROBE_TABLE_SIZE]; |
49 | static struct hlist_head kretprobe_inst_table[KPROBE_TABLE_SIZE]; | 60 | static struct hlist_head kretprobe_inst_table[KPROBE_TABLE_SIZE]; |
50 | static atomic_t kprobe_count; | 61 | static atomic_t kprobe_count; |
@@ -447,6 +458,21 @@ static int __kprobes __register_kprobe(struct kprobe *p, | |||
447 | struct kprobe *old_p; | 458 | struct kprobe *old_p; |
448 | struct module *probed_mod; | 459 | struct module *probed_mod; |
449 | 460 | ||
461 | /* | ||
462 | * If we have a symbol_name argument look it up, | ||
463 | * and add it to the address. That way the addr | ||
464 | * field can either be global or relative to a symbol. | ||
465 | */ | ||
466 | if (p->symbol_name) { | ||
467 | if (p->addr) | ||
468 | return -EINVAL; | ||
469 | kprobe_lookup_name(p->symbol_name, p->addr); | ||
470 | } | ||
471 | |||
472 | if (!p->addr) | ||
473 | return -EINVAL; | ||
474 | p->addr = (kprobe_opcode_t *)(((char *)p->addr)+ p->offset); | ||
475 | |||
450 | if ((!kernel_text_address((unsigned long) p->addr)) || | 476 | if ((!kernel_text_address((unsigned long) p->addr)) || |
451 | in_kprobes_functions((unsigned long) p->addr)) | 477 | in_kprobes_functions((unsigned long) p->addr)) |
452 | return -EINVAL; | 478 | return -EINVAL; |