blob: 11dd93e4258027cac8968074a5725aeafc7ae814 [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
Anders Kaseorg75a66612008-12-05 19:03:58 -050017struct module;
18
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#ifdef CONFIG_KALLSYMS
20/* Lookup the address for a symbol. Returns 0 if not found. */
21unsigned long kallsyms_lookup_name(const char *name);
22
Anders Kaseorg75a66612008-12-05 19:03:58 -050023/* Call a function on each kallsyms symbol in the core kernel */
24int kallsyms_on_each_symbol(int (*fn)(void *, const char *, struct module *,
25 unsigned long),
26 void *data);
27
Franck Bui-Huuffc50892006-10-03 01:13:48 -070028extern int kallsyms_lookup_size_offset(unsigned long addr,
29 unsigned long *symbolsize,
30 unsigned long *offset);
31
Linus Torvalds1da177e2005-04-16 15:20:36 -070032/* Lookup an address. modname is set to NULL if it's in the kernel. */
33const char *kallsyms_lookup(unsigned long addr,
34 unsigned long *symbolsize,
35 unsigned long *offset,
36 char **modname, char *namebuf);
37
Robert Peterson42e38082007-04-30 15:09:48 -070038/* Look up a kernel symbol and return it in a text buffer. */
39extern int sprint_symbol(char *buffer, unsigned long address);
Stephen Boyd4796dd22012-05-29 15:07:33 -070040extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
Namhyung Kim0f77a8d2011-03-24 11:42:29 +090041extern int sprint_backtrace(char *buffer, unsigned long address);
Robert Peterson42e38082007-04-30 15:09:48 -070042
43/* Look up a kernel symbol and print it to the kernel messages. */
Linus Torvalds1da177e2005-04-16 15:20:36 -070044extern void __print_symbol(const char *fmt, unsigned long address);
45
Alexey Dobriyan9d65cb42007-05-08 00:28:43 -070046int lookup_symbol_name(unsigned long addr, char *symname);
Alexey Dobriyana5c43da2007-05-08 00:28:47 -070047int lookup_symbol_attrs(unsigned long addr, unsigned long *size, unsigned long *offset, char *modname, char *name);
Alexey Dobriyan9d65cb42007-05-08 00:28:43 -070048
Linus Torvalds1da177e2005-04-16 15:20:36 -070049#else /* !CONFIG_KALLSYMS */
50
51static inline unsigned long kallsyms_lookup_name(const char *name)
52{
53 return 0;
54}
55
Anders Kaseorg75a66612008-12-05 19:03:58 -050056static inline int kallsyms_on_each_symbol(int (*fn)(void *, const char *,
57 struct module *,
58 unsigned long),
59 void *data)
60{
61 return 0;
62}
63
Franck Bui-Huuffc50892006-10-03 01:13:48 -070064static inline int kallsyms_lookup_size_offset(unsigned long addr,
65 unsigned long *symbolsize,
66 unsigned long *offset)
67{
68 return 0;
69}
70
Linus Torvalds1da177e2005-04-16 15:20:36 -070071static inline const char *kallsyms_lookup(unsigned long addr,
72 unsigned long *symbolsize,
73 unsigned long *offset,
74 char **modname, char *namebuf)
75{
76 return NULL;
77}
78
Robert Peterson42e38082007-04-30 15:09:48 -070079static inline int sprint_symbol(char *buffer, unsigned long addr)
80{
81 *buffer = '\0';
82 return 0;
83}
84
Stephen Boyd4796dd22012-05-29 15:07:33 -070085static inline int sprint_symbol_no_offset(char *buffer, unsigned long addr)
86{
87 *buffer = '\0';
88 return 0;
89}
90
Namhyung Kim0f77a8d2011-03-24 11:42:29 +090091static inline int sprint_backtrace(char *buffer, unsigned long addr)
92{
93 *buffer = '\0';
94 return 0;
95}
96
Alexey Dobriyan9d65cb42007-05-08 00:28:43 -070097static inline int lookup_symbol_name(unsigned long addr, char *symname)
98{
99 return -ERANGE;
100}
101
Alexey Dobriyana5c43da2007-05-08 00:28:47 -0700102static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, unsigned long *offset, char *modname, char *name)
103{
104 return -ERANGE;
105}
106
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107/* Stupid that this does nothing, but I didn't create this mess. */
108#define __print_symbol(fmt, addr)
109#endif /*CONFIG_KALLSYMS*/
110
111/* This macro allows us to keep printk typechecking */
Joe Perchesb9075fa2011-10-31 17:11:33 -0700112static __printf(1, 2)
113void __check_printsym_format(const char *fmt, ...)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114{
115}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116
Heiko Carstensb02454f2006-07-03 00:24:06 -0700117static inline void print_symbol(const char *fmt, unsigned long addr)
118{
119 __check_printsym_format(fmt, "");
120 __print_symbol(fmt, (unsigned long)
121 __builtin_extract_return_addr((void *)addr));
122}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123
Vegard Nossum2711b792008-07-25 01:45:56 -0700124static inline void print_ip_sym(unsigned long ip)
125{
Vegard Nossum3f1712ba2008-07-29 22:33:32 -0700126 printk("[<%p>] %pS\n", (void *) ip, (void *) ip);
Vegard Nossum2711b792008-07-25 01:45:56 -0700127}
Heiko Carstens8d8fdf52006-07-03 00:24:25 -0700128
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129#endif /*_LINUX_KALLSYMS_H*/