diff options
| -rw-r--r-- | include/linux/kallsyms.h | 13 | ||||
| -rw-r--r-- | kernel/kallsyms.c | 23 |
2 files changed, 27 insertions, 9 deletions
diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h index 1cebcbc28b47..3e3b92dabe3b 100644 --- a/include/linux/kallsyms.h +++ b/include/linux/kallsyms.h | |||
| @@ -7,6 +7,8 @@ | |||
| 7 | 7 | ||
| 8 | 8 | ||
| 9 | #define KSYM_NAME_LEN 127 | 9 | #define KSYM_NAME_LEN 127 |
| 10 | #define KSYM_SYMBOL_LEN (sizeof("%s+%#lx/%#lx [%s]") + KSYM_NAME_LEN + \ | ||
| 11 | 2*(BITS_PER_LONG*3/10) + MODULE_NAME_LEN + 1) | ||
| 10 | 12 | ||
| 11 | #ifdef CONFIG_KALLSYMS | 13 | #ifdef CONFIG_KALLSYMS |
| 12 | /* Lookup the address for a symbol. Returns 0 if not found. */ | 14 | /* Lookup the address for a symbol. Returns 0 if not found. */ |
| @@ -22,7 +24,10 @@ const char *kallsyms_lookup(unsigned long addr, | |||
| 22 | unsigned long *offset, | 24 | unsigned long *offset, |
| 23 | char **modname, char *namebuf); | 25 | char **modname, char *namebuf); |
| 24 | 26 | ||
| 25 | /* Replace "%s" in format with address, if found */ | 27 | /* Look up a kernel symbol and return it in a text buffer. */ |
| 28 | extern int sprint_symbol(char *buffer, unsigned long address); | ||
| 29 | |||
| 30 | /* Look up a kernel symbol and print it to the kernel messages. */ | ||
| 26 | extern void __print_symbol(const char *fmt, unsigned long address); | 31 | extern void __print_symbol(const char *fmt, unsigned long address); |
| 27 | 32 | ||
| 28 | #else /* !CONFIG_KALLSYMS */ | 33 | #else /* !CONFIG_KALLSYMS */ |
| @@ -47,6 +52,12 @@ static inline const char *kallsyms_lookup(unsigned long addr, | |||
| 47 | return NULL; | 52 | return NULL; |
| 48 | } | 53 | } |
| 49 | 54 | ||
| 55 | static inline int sprint_symbol(char *buffer, unsigned long addr) | ||
| 56 | { | ||
| 57 | *buffer = '\0'; | ||
| 58 | return 0; | ||
| 59 | } | ||
| 60 | |||
| 50 | /* Stupid that this does nothing, but I didn't create this mess. */ | 61 | /* Stupid that this does nothing, but I didn't create this mess. */ |
| 51 | #define __print_symbol(fmt, addr) | 62 | #define __print_symbol(fmt, addr) |
| 52 | #endif /*CONFIG_KALLSYMS*/ | 63 | #endif /*CONFIG_KALLSYMS*/ |
diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c index 6f294ff4f9ee..5a0de8409739 100644 --- a/kernel/kallsyms.c +++ b/kernel/kallsyms.c | |||
| @@ -267,27 +267,33 @@ const char *kallsyms_lookup(unsigned long addr, | |||
| 267 | return NULL; | 267 | return NULL; |
| 268 | } | 268 | } |
| 269 | 269 | ||
| 270 | /* Replace "%s" in format with address, or returns -errno. */ | 270 | /* Look up a kernel symbol and return it in a text buffer. */ |
| 271 | void __print_symbol(const char *fmt, unsigned long address) | 271 | int sprint_symbol(char *buffer, unsigned long address) |
| 272 | { | 272 | { |
| 273 | char *modname; | 273 | char *modname; |
| 274 | const char *name; | 274 | const char *name; |
| 275 | unsigned long offset, size; | 275 | unsigned long offset, size; |
| 276 | char namebuf[KSYM_NAME_LEN+1]; | 276 | char namebuf[KSYM_NAME_LEN+1]; |
| 277 | char buffer[sizeof("%s+%#lx/%#lx [%s]") + KSYM_NAME_LEN + | ||
| 278 | 2*(BITS_PER_LONG*3/10) + MODULE_NAME_LEN + 1]; | ||
| 279 | 277 | ||
| 280 | name = kallsyms_lookup(address, &size, &offset, &modname, namebuf); | 278 | name = kallsyms_lookup(address, &size, &offset, &modname, namebuf); |
| 281 | |||
| 282 | if (!name) | 279 | if (!name) |
| 283 | sprintf(buffer, "0x%lx", address); | 280 | return sprintf(buffer, "0x%lx", address); |
| 284 | else { | 281 | else { |
| 285 | if (modname) | 282 | if (modname) |
| 286 | sprintf(buffer, "%s+%#lx/%#lx [%s]", name, offset, | 283 | return sprintf(buffer, "%s+%#lx/%#lx [%s]", name, offset, |
| 287 | size, modname); | 284 | size, modname); |
| 288 | else | 285 | else |
| 289 | sprintf(buffer, "%s+%#lx/%#lx", name, offset, size); | 286 | return sprintf(buffer, "%s+%#lx/%#lx", name, offset, size); |
| 290 | } | 287 | } |
| 288 | } | ||
| 289 | |||
| 290 | /* Look up a kernel symbol and print it to the kernel messages. */ | ||
| 291 | void __print_symbol(const char *fmt, unsigned long address) | ||
| 292 | { | ||
| 293 | char buffer[KSYM_SYMBOL_LEN]; | ||
| 294 | |||
| 295 | sprint_symbol(buffer, address); | ||
| 296 | |||
| 291 | printk(fmt, buffer); | 297 | printk(fmt, buffer); |
| 292 | } | 298 | } |
| 293 | 299 | ||
| @@ -452,3 +458,4 @@ static int __init kallsyms_init(void) | |||
| 452 | __initcall(kallsyms_init); | 458 | __initcall(kallsyms_init); |
| 453 | 459 | ||
| 454 | EXPORT_SYMBOL(__print_symbol); | 460 | EXPORT_SYMBOL(__print_symbol); |
| 461 | EXPORT_SYMBOL_GPL(sprint_symbol); | ||
