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