blob: 0a777c5216b1a2916795c4b58dae2d513c01c822 [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/* How and when do we show kallsyms values? */
18extern int kallsyms_show_value(void);
19#ifndef CONFIG_64BIT
20# define KALLSYM_FMT "%08lx"
21#else
22# define KALLSYM_FMT "%016lx"
23#endif
24
Anders Kaseorg75a66612008-12-05 19:03:58 -050025struct module;
26
Linus Torvalds1da177e2005-04-16 15:20:36 -070027#ifdef CONFIG_KALLSYMS
28/* Lookup the address for a symbol. Returns 0 if not found. */
29unsigned long kallsyms_lookup_name(const char *name);
30
Anders Kaseorg75a66612008-12-05 19:03:58 -050031/* Call a function on each kallsyms symbol in the core kernel */
32int kallsyms_on_each_symbol(int (*fn)(void *, const char *, struct module *,
33 unsigned long),
34 void *data);
35
Franck Bui-Huuffc50892006-10-03 01:13:48 -070036extern int kallsyms_lookup_size_offset(unsigned long addr,
37 unsigned long *symbolsize,
38 unsigned long *offset);
39
Linus Torvalds1da177e2005-04-16 15:20:36 -070040/* Lookup an address. modname is set to NULL if it's in the kernel. */
41const char *kallsyms_lookup(unsigned long addr,
42 unsigned long *symbolsize,
43 unsigned long *offset,
44 char **modname, char *namebuf);
45
Robert Peterson42e38082007-04-30 15:09:48 -070046/* Look up a kernel symbol and return it in a text buffer. */
47extern int sprint_symbol(char *buffer, unsigned long address);
Stephen Boyd4796dd22012-05-29 15:07:33 -070048extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
Namhyung Kim0f77a8d2011-03-24 11:42:29 +090049extern int sprint_backtrace(char *buffer, unsigned long address);
Robert Peterson42e38082007-04-30 15:09:48 -070050
51/* Look up a kernel symbol and print it to the kernel messages. */
Linus Torvalds1da177e2005-04-16 15:20:36 -070052extern void __print_symbol(const char *fmt, unsigned long address);
53
Alexey Dobriyan9d65cb42007-05-08 00:28:43 -070054int lookup_symbol_name(unsigned long addr, char *symname);
Alexey Dobriyana5c43da2007-05-08 00:28:47 -070055int lookup_symbol_attrs(unsigned long addr, unsigned long *size, unsigned long *offset, char *modname, char *name);
Alexey Dobriyan9d65cb42007-05-08 00:28:43 -070056
Linus Torvalds1da177e2005-04-16 15:20:36 -070057#else /* !CONFIG_KALLSYMS */
58
59static inline unsigned long kallsyms_lookup_name(const char *name)
60{
61 return 0;
62}
63
Anders Kaseorg75a66612008-12-05 19:03:58 -050064static inline int kallsyms_on_each_symbol(int (*fn)(void *, const char *,
65 struct module *,
66 unsigned long),
67 void *data)
68{
69 return 0;
70}
71
Franck Bui-Huuffc50892006-10-03 01:13:48 -070072static inline int kallsyms_lookup_size_offset(unsigned long addr,
73 unsigned long *symbolsize,
74 unsigned long *offset)
75{
76 return 0;
77}
78
Linus Torvalds1da177e2005-04-16 15:20:36 -070079static inline const char *kallsyms_lookup(unsigned long addr,
80 unsigned long *symbolsize,
81 unsigned long *offset,
82 char **modname, char *namebuf)
83{
84 return NULL;
85}
86
Robert Peterson42e38082007-04-30 15:09:48 -070087static inline int sprint_symbol(char *buffer, unsigned long addr)
88{
89 *buffer = '\0';
90 return 0;
91}
92
Stephen Boyd4796dd22012-05-29 15:07:33 -070093static inline int sprint_symbol_no_offset(char *buffer, unsigned long addr)
94{
95 *buffer = '\0';
96 return 0;
97}
98
Namhyung Kim0f77a8d2011-03-24 11:42:29 +090099static inline int sprint_backtrace(char *buffer, unsigned long addr)
100{
101 *buffer = '\0';
102 return 0;
103}
104
Alexey Dobriyan9d65cb42007-05-08 00:28:43 -0700105static inline int lookup_symbol_name(unsigned long addr, char *symname)
106{
107 return -ERANGE;
108}
109
Alexey Dobriyana5c43da2007-05-08 00:28:47 -0700110static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, unsigned long *offset, char *modname, char *name)
111{
112 return -ERANGE;
113}
114
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115/* Stupid that this does nothing, but I didn't create this mess. */
116#define __print_symbol(fmt, addr)
117#endif /*CONFIG_KALLSYMS*/
118
119/* This macro allows us to keep printk typechecking */
Joe Perchesb9075fa2011-10-31 17:11:33 -0700120static __printf(1, 2)
121void __check_printsym_format(const char *fmt, ...)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122{
123}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124
Heiko Carstensb02454f2006-07-03 00:24:06 -0700125static inline void print_symbol(const char *fmt, unsigned long addr)
126{
127 __check_printsym_format(fmt, "");
128 __print_symbol(fmt, (unsigned long)
129 __builtin_extract_return_addr((void *)addr));
130}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131
Vegard Nossum2711b792008-07-25 01:45:56 -0700132static inline void print_ip_sym(unsigned long ip)
133{
Vegard Nossum3f1712b2008-07-29 22:33:32 -0700134 printk("[<%p>] %pS\n", (void *) ip, (void *) ip);
Vegard Nossum2711b792008-07-25 01:45:56 -0700135}
Heiko Carstens8d8fdf52006-07-03 00:24:25 -0700136
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137#endif /*_LINUX_KALLSYMS_H*/