1 /* SPDX-License-Identifier: GPL-2.0 */ 1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* Rewritten and vastly simplified by Rusty Ru 2 /* Rewritten and vastly simplified by Rusty Russell for in-kernel 3 * module loader: 3 * module loader: 4 * Copyright 2002 Rusty Russell <rusty@rustc 4 * Copyright 2002 Rusty Russell <rusty@rustcorp.com.au> IBM Corporation 5 */ 5 */ 6 #ifndef _LINUX_KALLSYMS_H 6 #ifndef _LINUX_KALLSYMS_H 7 #define _LINUX_KALLSYMS_H 7 #define _LINUX_KALLSYMS_H 8 8 9 #include <linux/errno.h> 9 #include <linux/errno.h> 10 #include <linux/buildid.h> << 11 #include <linux/kernel.h> 10 #include <linux/kernel.h> 12 #include <linux/stddef.h> 11 #include <linux/stddef.h> 13 #include <linux/mm.h> 12 #include <linux/mm.h> 14 #include <linux/module.h> 13 #include <linux/module.h> 15 14 16 #include <asm/sections.h> 15 #include <asm/sections.h> 17 16 18 #define KSYM_NAME_LEN 512 !! 17 #define KSYM_NAME_LEN 128 19 #define KSYM_SYMBOL_LEN (sizeof("%s+%#lx/%#lx !! 18 #define KSYM_SYMBOL_LEN (sizeof("%s+%#lx/%#lx [%s]") + (KSYM_NAME_LEN - 1) + \ 20 (KSYM_NAME_LEN - 1) + !! 19 2*(BITS_PER_LONG*3/10) + (MODULE_NAME_LEN - 1) + 1) 21 2*(BITS_PER_LONG*3/10) << 22 (BUILD_ID_SIZE_MAX * 2 << 23 20 24 struct cred; 21 struct cred; 25 struct module; 22 struct module; 26 23 >> 24 static inline int is_kernel_inittext(unsigned long addr) >> 25 { >> 26 if (addr >= (unsigned long)_sinittext >> 27 && addr <= (unsigned long)_einittext) >> 28 return 1; >> 29 return 0; >> 30 } >> 31 27 static inline int is_kernel_text(unsigned long 32 static inline int is_kernel_text(unsigned long addr) 28 { 33 { 29 if (__is_kernel_text(addr)) !! 34 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) || >> 35 arch_is_kernel_text(addr)) 30 return 1; 36 return 1; 31 return in_gate_area_no_mm(addr); 37 return in_gate_area_no_mm(addr); 32 } 38 } 33 39 34 static inline int is_kernel(unsigned long addr 40 static inline int is_kernel(unsigned long addr) 35 { 41 { 36 if (__is_kernel(addr)) !! 42 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end) 37 return 1; 43 return 1; 38 return in_gate_area_no_mm(addr); 44 return in_gate_area_no_mm(addr); 39 } 45 } 40 46 41 static inline int is_ksym_addr(unsigned long a 47 static inline int is_ksym_addr(unsigned long addr) 42 { 48 { 43 if (IS_ENABLED(CONFIG_KALLSYMS_ALL)) 49 if (IS_ENABLED(CONFIG_KALLSYMS_ALL)) 44 return is_kernel(addr); 50 return is_kernel(addr); 45 51 46 return is_kernel_text(addr) || is_kern 52 return is_kernel_text(addr) || is_kernel_inittext(addr); 47 } 53 } 48 54 49 static inline void *dereference_symbol_descrip 55 static inline void *dereference_symbol_descriptor(void *ptr) 50 { 56 { 51 #ifdef CONFIG_HAVE_FUNCTION_DESCRIPTORS !! 57 #ifdef HAVE_DEREFERENCE_FUNCTION_DESCRIPTOR 52 struct module *mod; 58 struct module *mod; 53 59 54 ptr = dereference_kernel_function_desc 60 ptr = dereference_kernel_function_descriptor(ptr); 55 if (is_ksym_addr((unsigned long)ptr)) 61 if (is_ksym_addr((unsigned long)ptr)) 56 return ptr; 62 return ptr; 57 63 58 preempt_disable(); 64 preempt_disable(); 59 mod = __module_address((unsigned long) 65 mod = __module_address((unsigned long)ptr); 60 preempt_enable(); 66 preempt_enable(); 61 67 62 if (mod) 68 if (mod) 63 ptr = dereference_module_funct 69 ptr = dereference_module_function_descriptor(mod, ptr); 64 #endif 70 #endif 65 return ptr; 71 return ptr; 66 } 72 } 67 73 68 /* How and when do we show kallsyms values? */ !! 74 int kallsyms_on_each_symbol(int (*fn)(void *, const char *, struct module *, 69 extern bool kallsyms_show_value(const struct c !! 75 unsigned long), 70 << 71 #ifdef CONFIG_KALLSYMS << 72 unsigned long kallsyms_sym_address(int idx); << 73 int kallsyms_on_each_symbol(int (*fn)(void *, << 74 void *data); 76 void *data); 75 int kallsyms_on_each_match_symbol(int (*fn)(vo << 76 const char * << 77 77 >> 78 #ifdef CONFIG_KALLSYMS 78 /* Lookup the address for a symbol. Returns 0 79 /* Lookup the address for a symbol. Returns 0 if not found. */ 79 unsigned long kallsyms_lookup_name(const char 80 unsigned long kallsyms_lookup_name(const char *name); 80 81 81 extern int kallsyms_lookup_size_offset(unsigne 82 extern int kallsyms_lookup_size_offset(unsigned long addr, 82 unsigned lon 83 unsigned long *symbolsize, 83 unsigned lon 84 unsigned long *offset); 84 85 85 /* Lookup an address. modname is set to NULL 86 /* Lookup an address. modname is set to NULL if it's in the kernel. */ 86 const char *kallsyms_lookup(unsigned long addr 87 const char *kallsyms_lookup(unsigned long addr, 87 unsigned long *sym 88 unsigned long *symbolsize, 88 unsigned long *off 89 unsigned long *offset, 89 char **modname, ch 90 char **modname, char *namebuf); 90 91 91 /* Look up a kernel symbol and return it in a 92 /* Look up a kernel symbol and return it in a text buffer. */ 92 extern int sprint_symbol(char *buffer, unsigne 93 extern int sprint_symbol(char *buffer, unsigned long address); 93 extern int sprint_symbol_build_id(char *buffer << 94 extern int sprint_symbol_no_offset(char *buffe 94 extern int sprint_symbol_no_offset(char *buffer, unsigned long address); 95 extern int sprint_backtrace(char *buffer, unsi 95 extern int sprint_backtrace(char *buffer, unsigned long address); 96 extern int sprint_backtrace_build_id(char *buf << 97 96 98 int lookup_symbol_name(unsigned long addr, cha 97 int lookup_symbol_name(unsigned long addr, char *symname); >> 98 int lookup_symbol_attrs(unsigned long addr, unsigned long *size, unsigned long *offset, char *modname, char *name); >> 99 >> 100 /* How and when do we show kallsyms values? */ >> 101 extern bool kallsyms_show_value(const struct cred *cred); 99 102 100 #else /* !CONFIG_KALLSYMS */ 103 #else /* !CONFIG_KALLSYMS */ 101 104 102 static inline unsigned long kallsyms_lookup_na 105 static inline unsigned long kallsyms_lookup_name(const char *name) 103 { 106 { 104 return 0; 107 return 0; 105 } 108 } 106 109 107 static inline int kallsyms_lookup_size_offset( 110 static inline int kallsyms_lookup_size_offset(unsigned long addr, 108 111 unsigned long *symbolsize, 109 112 unsigned long *offset) 110 { 113 { 111 return 0; 114 return 0; 112 } 115 } 113 116 114 static inline const char *kallsyms_lookup(unsi 117 static inline const char *kallsyms_lookup(unsigned long addr, 115 unsi 118 unsigned long *symbolsize, 116 unsi 119 unsigned long *offset, 117 char 120 char **modname, char *namebuf) 118 { 121 { 119 return NULL; 122 return NULL; 120 } 123 } 121 124 122 static inline int sprint_symbol(char *buffer, 125 static inline int sprint_symbol(char *buffer, unsigned long addr) 123 { 126 { 124 *buffer = '\0'; 127 *buffer = '\0'; 125 return 0; 128 return 0; 126 } 129 } 127 130 128 static inline int sprint_symbol_build_id(char << 129 { << 130 *buffer = '\0'; << 131 return 0; << 132 } << 133 << 134 static inline int sprint_symbol_no_offset(char 131 static inline int sprint_symbol_no_offset(char *buffer, unsigned long addr) 135 { 132 { 136 *buffer = '\0'; 133 *buffer = '\0'; 137 return 0; 134 return 0; 138 } 135 } 139 136 140 static inline int sprint_backtrace(char *buffe 137 static inline int sprint_backtrace(char *buffer, unsigned long addr) 141 { 138 { 142 *buffer = '\0'; 139 *buffer = '\0'; 143 return 0; 140 return 0; 144 } 141 } 145 142 146 static inline int sprint_backtrace_build_id(ch << 147 { << 148 *buffer = '\0'; << 149 return 0; << 150 } << 151 << 152 static inline int lookup_symbol_name(unsigned 143 static inline int lookup_symbol_name(unsigned long addr, char *symname) 153 { 144 { 154 return -ERANGE; 145 return -ERANGE; 155 } 146 } 156 147 157 static inline int kallsyms_on_each_symbol(int !! 148 static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, unsigned long *offset, char *modname, char *name) 158 void << 159 { 149 { 160 return -EOPNOTSUPP; !! 150 return -ERANGE; 161 } 151 } 162 152 163 static inline int kallsyms_on_each_match_symbo !! 153 static inline bool kallsyms_show_value(const struct cred *cred) 164 << 165 { 154 { 166 return -EOPNOTSUPP; !! 155 return false; 167 } 156 } >> 157 168 #endif /*CONFIG_KALLSYMS*/ 158 #endif /*CONFIG_KALLSYMS*/ 169 159 170 static inline void print_ip_sym(const char *lo 160 static inline void print_ip_sym(const char *loglvl, unsigned long ip) 171 { 161 { 172 printk("%s[<%px>] %pS\n", loglvl, (voi 162 printk("%s[<%px>] %pS\n", loglvl, (void *) ip, (void *) ip); 173 } 163 } 174 164 175 #endif /*_LINUX_KALLSYMS_H*/ 165 #endif /*_LINUX_KALLSYMS_H*/ 176 166
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.