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