1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Rewritten and vastly simplified by Rusty Russell for in-kernel
4 * Copyright 2002 Rusty Russell <rusty@rustcorp.com.au> IBM Corporation
6 #ifndef _LINUX_KALLSYMS_H
7 #define _LINUX_KALLSYMS_H
9 #include <linux/errno.h>
10 #include <linux/kernel.h>
11 #include <linux/stddef.h>
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)
19 #ifdef CONFIG_KALLSYMS
20 /* Lookup the address for a symbol. Returns 0 if not found. */
21 unsigned long kallsyms_lookup_name(const char *name);
23 /* Call a function on each kallsyms symbol in the core kernel */
24 int kallsyms_on_each_symbol(int (*fn)(void *, const char *, struct module *,
28 extern int kallsyms_lookup_size_offset(unsigned long addr,
29 unsigned long *symbolsize,
30 unsigned long *offset);
32 /* Lookup an address. modname is set to NULL if it's in the kernel. */
33 const char *kallsyms_lookup(unsigned long addr,
34 unsigned long *symbolsize,
35 unsigned long *offset,
36 char **modname, char *namebuf);
38 /* Look up a kernel symbol and return it in a text buffer. */
39 extern int sprint_symbol(char *buffer, unsigned long address);
40 extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
41 extern int sprint_backtrace(char *buffer, unsigned long address);
43 /* Look up a kernel symbol and print it to the kernel messages. */
44 extern void __print_symbol(const char *fmt, unsigned long address);
46 int lookup_symbol_name(unsigned long addr, char *symname);
47 int lookup_symbol_attrs(unsigned long addr, unsigned long *size, unsigned long *offset, char *modname, char *name);
49 #else /* !CONFIG_KALLSYMS */
51 static inline unsigned long kallsyms_lookup_name(const char *name)
56 static inline int kallsyms_on_each_symbol(int (*fn)(void *, const char *,
64 static inline int kallsyms_lookup_size_offset(unsigned long addr,
65 unsigned long *symbolsize,
66 unsigned long *offset)
71 static inline const char *kallsyms_lookup(unsigned long addr,
72 unsigned long *symbolsize,
73 unsigned long *offset,
74 char **modname, char *namebuf)
79 static inline int sprint_symbol(char *buffer, unsigned long addr)
85 static inline int sprint_symbol_no_offset(char *buffer, unsigned long addr)
91 static inline int sprint_backtrace(char *buffer, unsigned long addr)
97 static inline int lookup_symbol_name(unsigned long addr, char *symname)
102 static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, unsigned long *offset, char *modname, char *name)
107 /* Stupid that this does nothing, but I didn't create this mess. */
108 #define __print_symbol(fmt, addr)
109 #endif /*CONFIG_KALLSYMS*/
111 /* This macro allows us to keep printk typechecking */
112 static __printf(1, 2)
113 void __check_printsym_format(const char *fmt, ...)
117 static inline void print_symbol(const char *fmt, unsigned long addr)
119 __check_printsym_format(fmt, "");
120 __print_symbol(fmt, (unsigned long)
121 __builtin_extract_return_addr((void *)addr));
124 static inline void print_ip_sym(unsigned long ip)
126 printk("[<%p>] %pS\n", (void *) ip, (void *) ip);
129 #endif /*_LINUX_KALLSYMS_H*/