Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* Rewritten and vastly simplified by Rusty Russell for in-kernel |
| 2 | * module loader: |
| 3 | * Copyright 2002 Rusty Russell <rusty@rustcorp.com.au> IBM Corporation |
| 4 | */ |
| 5 | #ifndef _LINUX_KALLSYMS_H |
| 6 | #define _LINUX_KALLSYMS_H |
| 7 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | |
| 9 | #define KSYM_NAME_LEN 127 |
Robert Peterson | 42e3808 | 2007-04-30 15:09:48 -0700 | [diff] [blame] | 10 | #define KSYM_SYMBOL_LEN (sizeof("%s+%#lx/%#lx [%s]") + KSYM_NAME_LEN + \ |
| 11 | 2*(BITS_PER_LONG*3/10) + MODULE_NAME_LEN + 1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | |
| 13 | #ifdef CONFIG_KALLSYMS |
| 14 | /* Lookup the address for a symbol. Returns 0 if not found. */ |
| 15 | unsigned long kallsyms_lookup_name(const char *name); |
| 16 | |
Franck Bui-Huu | ffc5089 | 2006-10-03 01:13:48 -0700 | [diff] [blame] | 17 | extern int kallsyms_lookup_size_offset(unsigned long addr, |
| 18 | unsigned long *symbolsize, |
| 19 | unsigned long *offset); |
| 20 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | /* Lookup an address. modname is set to NULL if it's in the kernel. */ |
| 22 | const char *kallsyms_lookup(unsigned long addr, |
| 23 | unsigned long *symbolsize, |
| 24 | unsigned long *offset, |
| 25 | char **modname, char *namebuf); |
| 26 | |
Robert Peterson | 42e3808 | 2007-04-30 15:09:48 -0700 | [diff] [blame] | 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. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | extern void __print_symbol(const char *fmt, unsigned long address); |
| 32 | |
Alexey Dobriyan | 9d65cb4 | 2007-05-08 00:28:43 -0700 | [diff] [blame^] | 33 | int lookup_symbol_name(unsigned long addr, char *symname); |
| 34 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | #else /* !CONFIG_KALLSYMS */ |
| 36 | |
| 37 | static inline unsigned long kallsyms_lookup_name(const char *name) |
| 38 | { |
| 39 | return 0; |
| 40 | } |
| 41 | |
Franck Bui-Huu | ffc5089 | 2006-10-03 01:13:48 -0700 | [diff] [blame] | 42 | static inline int kallsyms_lookup_size_offset(unsigned long addr, |
| 43 | unsigned long *symbolsize, |
| 44 | unsigned long *offset) |
| 45 | { |
| 46 | return 0; |
| 47 | } |
| 48 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | static inline const char *kallsyms_lookup(unsigned long addr, |
| 50 | unsigned long *symbolsize, |
| 51 | unsigned long *offset, |
| 52 | char **modname, char *namebuf) |
| 53 | { |
| 54 | return NULL; |
| 55 | } |
| 56 | |
Robert Peterson | 42e3808 | 2007-04-30 15:09:48 -0700 | [diff] [blame] | 57 | static inline int sprint_symbol(char *buffer, unsigned long addr) |
| 58 | { |
| 59 | *buffer = '\0'; |
| 60 | return 0; |
| 61 | } |
| 62 | |
Alexey Dobriyan | 9d65cb4 | 2007-05-08 00:28:43 -0700 | [diff] [blame^] | 63 | static inline int lookup_symbol_name(unsigned long addr, char *symname) |
| 64 | { |
| 65 | return -ERANGE; |
| 66 | } |
| 67 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | /* Stupid that this does nothing, but I didn't create this mess. */ |
| 69 | #define __print_symbol(fmt, addr) |
| 70 | #endif /*CONFIG_KALLSYMS*/ |
| 71 | |
| 72 | /* This macro allows us to keep printk typechecking */ |
| 73 | static void __check_printsym_format(const char *fmt, ...) |
| 74 | __attribute__((format(printf,1,2))); |
| 75 | static inline void __check_printsym_format(const char *fmt, ...) |
| 76 | { |
| 77 | } |
| 78 | /* ia64 and ppc64 use function descriptors, which contain the real address */ |
| 79 | #if defined(CONFIG_IA64) || defined(CONFIG_PPC64) |
| 80 | #define print_fn_descriptor_symbol(fmt, addr) \ |
| 81 | do { \ |
| 82 | unsigned long *__faddr = (unsigned long*) addr; \ |
| 83 | print_symbol(fmt, __faddr[0]); \ |
| 84 | } while (0) |
| 85 | #else |
| 86 | #define print_fn_descriptor_symbol(fmt, addr) print_symbol(fmt, addr) |
| 87 | #endif |
| 88 | |
Heiko Carstens | b02454f | 2006-07-03 00:24:06 -0700 | [diff] [blame] | 89 | static inline void print_symbol(const char *fmt, unsigned long addr) |
| 90 | { |
| 91 | __check_printsym_format(fmt, ""); |
| 92 | __print_symbol(fmt, (unsigned long) |
| 93 | __builtin_extract_return_addr((void *)addr)); |
| 94 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | |
Heiko Carstens | 8d8fdf5 | 2006-07-03 00:24:25 -0700 | [diff] [blame] | 96 | #ifndef CONFIG_64BIT |
| 97 | #define print_ip_sym(ip) \ |
| 98 | do { \ |
| 99 | printk("[<%08lx>]", ip); \ |
| 100 | print_symbol(" %s\n", ip); \ |
| 101 | } while(0) |
| 102 | #else |
| 103 | #define print_ip_sym(ip) \ |
| 104 | do { \ |
| 105 | printk("[<%016lx>]", ip); \ |
| 106 | print_symbol(" %s\n", ip); \ |
| 107 | } while(0) |
| 108 | #endif |
| 109 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | #endif /*_LINUX_KALLSYMS_H*/ |