aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnders Kaseorg <andersk@mit.edu>2008-12-05 19:03:58 -0500
committerRusty Russell <rusty@rustcorp.com.au>2009-03-30 22:35:32 -0400
commit75a66614db21007bcc8c37f9c5d5b922981387b9 (patch)
treed02c905a3aee02ec25ce38700f47d0fa57d2cbf7
parenta6e6abd575fcbe6572ebc7a70ad616406d206fa8 (diff)
Ksplice: Add functions for walking kallsyms symbols
Impact: New API kallsyms_lookup_name only returns the first match that it finds. Ksplice needs information about all symbols with a given name in order to correctly resolve local symbols. kallsyms_on_each_symbol provides a generic mechanism for iterating over the kallsyms table. Cc: Jeff Arnold <jbarnold@mit.edu> Cc: Tim Abbott <tabbott@mit.edu> Signed-off-by: Anders Kaseorg <andersk@mit.edu> Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
-rw-r--r--include/linux/kallsyms.h15
-rw-r--r--include/linux/module.h12
-rw-r--r--kernel/kallsyms.c19
-rw-r--r--kernel/module.c19
4 files changed, 65 insertions, 0 deletions
diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
index f3fe34391d8e..792274269f2b 100644
--- a/include/linux/kallsyms.h
+++ b/include/linux/kallsyms.h
@@ -13,10 +13,17 @@
13#define KSYM_SYMBOL_LEN (sizeof("%s+%#lx/%#lx [%s]") + (KSYM_NAME_LEN - 1) + \ 13#define KSYM_SYMBOL_LEN (sizeof("%s+%#lx/%#lx [%s]") + (KSYM_NAME_LEN - 1) + \
14 2*(BITS_PER_LONG*3/10) + (MODULE_NAME_LEN - 1) + 1) 14 2*(BITS_PER_LONG*3/10) + (MODULE_NAME_LEN - 1) + 1)
15 15
16struct module;
17
16#ifdef CONFIG_KALLSYMS 18#ifdef CONFIG_KALLSYMS
17/* Lookup the address for a symbol. Returns 0 if not found. */ 19/* Lookup the address for a symbol. Returns 0 if not found. */
18unsigned long kallsyms_lookup_name(const char *name); 20unsigned long kallsyms_lookup_name(const char *name);
19 21
22/* Call a function on each kallsyms symbol in the core kernel */
23int kallsyms_on_each_symbol(int (*fn)(void *, const char *, struct module *,
24 unsigned long),
25 void *data);
26
20extern int kallsyms_lookup_size_offset(unsigned long addr, 27extern int kallsyms_lookup_size_offset(unsigned long addr,
21 unsigned long *symbolsize, 28 unsigned long *symbolsize,
22 unsigned long *offset); 29 unsigned long *offset);
@@ -43,6 +50,14 @@ static inline unsigned long kallsyms_lookup_name(const char *name)
43 return 0; 50 return 0;
44} 51}
45 52
53static inline int kallsyms_on_each_symbol(int (*fn)(void *, const char *,
54 struct module *,
55 unsigned long),
56 void *data)
57{
58 return 0;
59}
60
46static inline int kallsyms_lookup_size_offset(unsigned long addr, 61static inline int kallsyms_lookup_size_offset(unsigned long addr,
47 unsigned long *symbolsize, 62 unsigned long *symbolsize,
48 unsigned long *offset) 63 unsigned long *offset)
diff --git a/include/linux/module.h b/include/linux/module.h
index 69761ce0dbf0..c3d3fc4ffb18 100644
--- a/include/linux/module.h
+++ b/include/linux/module.h
@@ -387,6 +387,10 @@ int module_get_kallsym(unsigned int symnum, unsigned long *value, char *type,
387/* Look for this name: can be of form module:name. */ 387/* Look for this name: can be of form module:name. */
388unsigned long module_kallsyms_lookup_name(const char *name); 388unsigned long module_kallsyms_lookup_name(const char *name);
389 389
390int module_kallsyms_on_each_symbol(int (*fn)(void *, const char *,
391 struct module *, unsigned long),
392 void *data);
393
390extern void __module_put_and_exit(struct module *mod, long code) 394extern void __module_put_and_exit(struct module *mod, long code)
391 __attribute__((noreturn)); 395 __attribute__((noreturn));
392#define module_put_and_exit(code) __module_put_and_exit(THIS_MODULE, code); 396#define module_put_and_exit(code) __module_put_and_exit(THIS_MODULE, code);
@@ -566,6 +570,14 @@ static inline unsigned long module_kallsyms_lookup_name(const char *name)
566 return 0; 570 return 0;
567} 571}
568 572
573static inline int module_kallsyms_on_each_symbol(int (*fn)(void *, const char *,
574 struct module *,
575 unsigned long),
576 void *data)
577{
578 return 0;
579}
580
569static inline int register_module_notifier(struct notifier_block * nb) 581static inline int register_module_notifier(struct notifier_block * nb)
570{ 582{
571 /* no events will happen anyway, so this can always succeed */ 583 /* no events will happen anyway, so this can always succeed */
diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
index 7b8b0f21a5b1..374faf9bfdc7 100644
--- a/kernel/kallsyms.c
+++ b/kernel/kallsyms.c
@@ -161,6 +161,25 @@ unsigned long kallsyms_lookup_name(const char *name)
161 return module_kallsyms_lookup_name(name); 161 return module_kallsyms_lookup_name(name);
162} 162}
163 163
164int kallsyms_on_each_symbol(int (*fn)(void *, const char *, struct module *,
165 unsigned long),
166 void *data)
167{
168 char namebuf[KSYM_NAME_LEN];
169 unsigned long i;
170 unsigned int off;
171 int ret;
172
173 for (i = 0, off = 0; i < kallsyms_num_syms; i++) {
174 off = kallsyms_expand_symbol(off, namebuf);
175 ret = fn(data, namebuf, NULL, kallsyms_addresses[i]);
176 if (ret != 0)
177 return ret;
178 }
179 return module_kallsyms_on_each_symbol(fn, data);
180}
181EXPORT_SYMBOL_GPL(kallsyms_on_each_symbol);
182
164static unsigned long get_symbol_pos(unsigned long addr, 183static unsigned long get_symbol_pos(unsigned long addr,
165 unsigned long *symbolsize, 184 unsigned long *symbolsize,
166 unsigned long *offset) 185 unsigned long *offset)
diff --git a/kernel/module.c b/kernel/module.c
index 8ddca629e079..dd4389be9152 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -2612,6 +2612,25 @@ unsigned long module_kallsyms_lookup_name(const char *name)
2612 preempt_enable(); 2612 preempt_enable();
2613 return ret; 2613 return ret;
2614} 2614}
2615
2616int module_kallsyms_on_each_symbol(int (*fn)(void *, const char *,
2617 struct module *, unsigned long),
2618 void *data)
2619{
2620 struct module *mod;
2621 unsigned int i;
2622 int ret;
2623
2624 list_for_each_entry(mod, &modules, list) {
2625 for (i = 0; i < mod->num_symtab; i++) {
2626 ret = fn(data, mod->strtab + mod->symtab[i].st_name,
2627 mod, mod->symtab[i].st_value);
2628 if (ret != 0)
2629 return ret;
2630 }
2631 }
2632 return 0;
2633}
2615#endif /* CONFIG_KALLSYMS */ 2634#endif /* CONFIG_KALLSYMS */
2616 2635
2617static char *module_flags(struct module *mod, char *buf) 2636static char *module_flags(struct module *mod, char *buf)