blob: 708f337d780be3ee4c628fe0422e3a6752d0fb33 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/* Rewritten and vastly simplified by Rusty Russell for in-kernel
3 * module loader:
4 * Copyright 2002 Rusty Russell <rusty@rustcorp.com.au> IBM Corporation
5 */
6#ifndef _LINUX_KALLSYMS_H
7#define _LINUX_KALLSYMS_H
8
Adrian Bunk40e48ee2007-07-07 00:54:09 +02009#include <linux/errno.h>
Vegard Nossum2711b792008-07-25 01:45:56 -070010#include <linux/kernel.h>
Kamalesh Babulal5a759832007-11-05 14:50:55 -080011#include <linux/stddef.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070012
Tejun Heo9281ace2007-07-17 04:03:51 -070013#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)
Linus Torvalds1da177e2005-04-16 15:20:36 -070016
Linus Torvalds516fb7f2017-11-12 18:44:23 -080017#ifndef CONFIG_64BIT
18# define KALLSYM_FMT "%08lx"
19#else
20# define KALLSYM_FMT "%016lx"
21#endif
22
Anders Kaseorg75a66612008-12-05 19:03:58 -050023struct module;
24
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#ifdef CONFIG_KALLSYMS
26/* Lookup the address for a symbol. Returns 0 if not found. */
27unsigned long kallsyms_lookup_name(const char *name);
28
Anders Kaseorg75a66612008-12-05 19:03:58 -050029/* Call a function on each kallsyms symbol in the core kernel */
30int kallsyms_on_each_symbol(int (*fn)(void *, const char *, struct module *,
31 unsigned long),
32 void *data);
33
Franck Bui-Huuffc50892006-10-03 01:13:48 -070034extern int kallsyms_lookup_size_offset(unsigned long addr,
35 unsigned long *symbolsize,
36 unsigned long *offset);
37
Linus Torvalds1da177e2005-04-16 15:20:36 -070038/* Lookup an address. modname is set to NULL if it's in the kernel. */
39const char *kallsyms_lookup(unsigned long addr,
40 unsigned long *symbolsize,
41 unsigned long *offset,
42 char **modname, char *namebuf);
43
Robert Peterson42e38082007-04-30 15:09:48 -070044/* Look up a kernel symbol and return it in a text buffer. */
45extern int sprint_symbol(char *buffer, unsigned long address);
Stephen Boyd4796dd22012-05-29 15:07:33 -070046extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
Namhyung Kim0f77a8d2011-03-24 11:42:29 +090047extern int sprint_backtrace(char *buffer, unsigned long address);
Robert Peterson42e38082007-04-30 15:09:48 -070048
49/* Look up a kernel symbol and print it to the kernel messages. */
Linus Torvalds1da177e2005-04-16 15:20:36 -070050extern void __print_symbol(const char *fmt, unsigned long address);
51
Alexey Dobriyan9d65cb42007-05-08 00:28:43 -070052int lookup_symbol_name(unsigned long addr, char *symname);
Alexey Dobriyana5c43da2007-05-08 00:28:47 -070053int lookup_symbol_attrs(unsigned long addr, unsigned long *size, unsigned long *offset, char *modname, char *name);
Alexey Dobriyan9d65cb42007-05-08 00:28:43 -070054
Arnd Bergmanne4a8ca32017-11-13 17:51:00 +010055/* How and when do we show kallsyms values? */
56extern int kallsyms_show_value(void);
57
Linus Torvalds1da177e2005-04-16 15:20:36 -070058#else /* !CONFIG_KALLSYMS */
59
60static inline unsigned long kallsyms_lookup_name(const char *name)
61{
62 return 0;
63}
64
Anders Kaseorg75a66612008-12-05 19:03:58 -050065static 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
Franck Bui-Huuffc50892006-10-03 01:13:48 -070073static inline int kallsyms_lookup_size_offset(unsigned long addr,
74 unsigned long *symbolsize,
75 unsigned long *offset)
76{
77 return 0;
78}
79
Linus Torvalds1da177e2005-04-16 15:20:36 -070080static 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
Robert Peterson42e38082007-04-30 15:09:48 -070088static inline int sprint_symbol(char *buffer, unsigned long addr)
89{
90 *buffer = '\0';
91 return 0;
92}
93
Stephen Boyd4796dd22012-05-29 15:07:33 -070094static inline int sprint_symbol_no_offset(char *buffer, unsigned long addr)
95{
96 *buffer = '\0';
97 return 0;
98}
99
Namhyung Kim0f77a8d2011-03-24 11:42:29 +0900100static inline int sprint_backtrace(char *buffer, unsigned long addr)
101{
102 *buffer = '\0';
103 return 0;
104}
105
Alexey Dobriyan9d65cb42007-05-08 00:28:43 -0700106static inline int lookup_symbol_name(unsigned long addr, char *symname)
107{
108 return -ERANGE;
109}
110
Alexey Dobriyana5c43da2007-05-08 00:28:47 -0700111static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, unsigned long *offset, char *modname, char *name)
112{
113 return -ERANGE;
114}
115
Arnd Bergmanne4a8ca32017-11-13 17:51:00 +0100116static inline int kallsyms_show_value(void)
117{
118 return false;
119}
120
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121/* 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 */
Joe Perchesb9075fa2011-10-31 17:11:33 -0700126static __printf(1, 2)
127void __check_printsym_format(const char *fmt, ...)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128{
129}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130
Heiko Carstensb02454f2006-07-03 00:24:06 -0700131static 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}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137
Vegard Nossum2711b792008-07-25 01:45:56 -0700138static inline void print_ip_sym(unsigned long ip)
139{
Vegard Nossum3f1712ba2008-07-29 22:33:32 -0700140 printk("[<%p>] %pS\n", (void *) ip, (void *) ip);
Vegard Nossum2711b792008-07-25 01:45:56 -0700141}
Heiko Carstens8d8fdf52006-07-03 00:24:25 -0700142
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143#endif /*_LINUX_KALLSYMS_H*/