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