1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* Rewritten and vastly simplified by Rusty Russell for in-kernel 3 * module loader: 4 * Copyright 2002 Rusty Russell <[email protected]> IBM Corporation 5 */ 6 #ifndef _LINUX_KALLSYMS_H 7 #define _LINUX_KALLSYMS_H 8 9 #include <linux/errno.h> 10 #include <linux/kernel.h> 11 #include <linux/stddef.h> 12 13 #define KSYM_NAME_LEN 128 14 #define KSYM_SYMBOL_LEN (sizeof("%s+%#lx/%#lx [%s]") + (KSYM_NAME_LEN - 1) + \ 15 2*(BITS_PER_LONG*3/10) + (MODULE_NAME_LEN - 1) + 1) 16 17 #ifndef CONFIG_64BIT 18 # define KALLSYM_FMT "%08lx" 19 #else 20 # define KALLSYM_FMT "%016lx" 21 #endif 22 23 struct module; 24 25 #ifdef CONFIG_KALLSYMS 26 /* Lookup the address for a symbol. Returns 0 if not found. */ 27 unsigned long kallsyms_lookup_name(const char *name); 28 29 /* Call a function on each kallsyms symbol in the core kernel */ 30 int kallsyms_on_each_symbol(int (*fn)(void *, const char *, struct module *, 31 unsigned long), 32 void *data); 33 34 extern int kallsyms_lookup_size_offset(unsigned long addr, 35 unsigned long *symbolsize, 36 unsigned long *offset); 37 38 /* Lookup an address. modname is set to NULL if it's in the kernel. */ 39 const char *kallsyms_lookup(unsigned long addr, 40 unsigned long *symbolsize, 41 unsigned long *offset, 42 char **modname, char *namebuf); 43 44 /* Look up a kernel symbol and return it in a text buffer. */ 45 extern int sprint_symbol(char *buffer, unsigned long address); 46 extern int sprint_symbol_no_offset(char *buffer, unsigned long address); 47 extern int sprint_backtrace(char *buffer, unsigned long address); 48 49 /* Look up a kernel symbol and print it to the kernel messages. */ 50 extern void __print_symbol(const char *fmt, unsigned long address); 51 52 int lookup_symbol_name(unsigned long addr, char *symname); 53 int lookup_symbol_attrs(unsigned long addr, unsigned long *size, unsigned long *offset, char *modname, char *name); 54 55 /* How and when do we show kallsyms values? */ 56 extern int kallsyms_show_value(void); 57 58 #else /* !CONFIG_KALLSYMS */ 59 60 static inline unsigned long kallsyms_lookup_name(const char *name) 61 { 62 return 0; 63 } 64 65 static inline int kallsyms_on_each_symbol(int (*fn)(void *, const char *, 66 struct module *, 67 unsigned long), 68 void *data) 69 { 70 return 0; 71 } 72 73 static inline int kallsyms_lookup_size_offset(unsigned long addr, 74 unsigned long *symbolsize, 75 unsigned long *offset) 76 { 77 return 0; 78 } 79 80 static inline const char *kallsyms_lookup(unsigned long addr, 81 unsigned long *symbolsize, 82 unsigned long *offset, 83 char **modname, char *namebuf) 84 { 85 return NULL; 86 } 87 88 static inline int sprint_symbol(char *buffer, unsigned long addr) 89 { 90 *buffer = '\0'; 91 return 0; 92 } 93 94 static inline int sprint_symbol_no_offset(char *buffer, unsigned long addr) 95 { 96 *buffer = '\0'; 97 return 0; 98 } 99 100 static inline int sprint_backtrace(char *buffer, unsigned long addr) 101 { 102 *buffer = '\0'; 103 return 0; 104 } 105 106 static inline int lookup_symbol_name(unsigned long addr, char *symname) 107 { 108 return -ERANGE; 109 } 110 111 static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, unsigned long *offset, char *modname, char *name) 112 { 113 return -ERANGE; 114 } 115 116 static inline int kallsyms_show_value(void) 117 { 118 return false; 119 } 120 121 /* Stupid that this does nothing, but I didn't create this mess. */ 122 #define __print_symbol(fmt, addr) 123 #endif /*CONFIG_KALLSYMS*/ 124 125 /* This macro allows us to keep printk typechecking */ 126 static __printf(1, 2) 127 void __check_printsym_format(const char *fmt, ...) 128 { 129 } 130 131 static inline void print_symbol(const char *fmt, unsigned long addr) 132 { 133 __check_printsym_format(fmt, ""); 134 __print_symbol(fmt, (unsigned long) 135 __builtin_extract_return_addr((void *)addr)); 136 } 137 138 static inline void print_ip_sym(unsigned long ip) 139 { 140 printk("[<%p>] %pS\n", (void *) ip, (void *) ip); 141 } 142 143 #endif /*_LINUX_KALLSYMS_H*/ 144