blob: 6883e197acb9e939156c4934d9cc7150b1b107f5 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* Rewritten and vastly simplified by Rusty Russell for in-kernel
2 * module loader:
3 * Copyright 2002 Rusty Russell <rusty@rustcorp.com.au> IBM Corporation
4 */
5#ifndef _LINUX_KALLSYMS_H
6#define _LINUX_KALLSYMS_H
7
Adrian Bunk40e48ee2007-07-07 00:54:09 +02008#include <linux/errno.h>
Vegard Nossum2711b792008-07-25 01:45:56 -07009#include <linux/kernel.h>
Kamalesh Babulal5a759832007-11-05 14:50:55 -080010#include <linux/stddef.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070011
Tejun Heo9281ace2007-07-17 04:03:51 -070012#define KSYM_NAME_LEN 128
13#define KSYM_SYMBOL_LEN (sizeof("%s+%#lx/%#lx [%s]") + (KSYM_NAME_LEN - 1) + \
14 2*(BITS_PER_LONG*3/10) + (MODULE_NAME_LEN - 1) + 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -070015
Anders Kaseorg75a66612008-12-05 19:03:58 -050016struct module;
17
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#ifdef CONFIG_KALLSYMS
19/* Lookup the address for a symbol. Returns 0 if not found. */
20unsigned long kallsyms_lookup_name(const char *name);
21
Anders Kaseorg75a66612008-12-05 19:03:58 -050022/* Call a function on each kallsyms symbol in the core kernel */
23int kallsyms_on_each_symbol(int (*fn)(void *, const char *, struct module *,
24 unsigned long),
25 void *data);
26
Franck Bui-Huuffc50892006-10-03 01:13:48 -070027extern int kallsyms_lookup_size_offset(unsigned long addr,
28 unsigned long *symbolsize,
29 unsigned long *offset);
30
Linus Torvalds1da177e2005-04-16 15:20:36 -070031/* Lookup an address. modname is set to NULL if it's in the kernel. */
32const char *kallsyms_lookup(unsigned long addr,
33 unsigned long *symbolsize,
34 unsigned long *offset,
35 char **modname, char *namebuf);
36
Robert Peterson42e38082007-04-30 15:09:48 -070037/* Look up a kernel symbol and return it in a text buffer. */
38extern int sprint_symbol(char *buffer, unsigned long address);
Stephen Boyd4796dd22012-05-29 15:07:33 -070039extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
Namhyung Kim0f77a8d2011-03-24 11:42:29 +090040extern int sprint_backtrace(char *buffer, unsigned long address);
Robert Peterson42e38082007-04-30 15:09:48 -070041
42/* Look up a kernel symbol and print it to the kernel messages. */
Linus Torvalds1da177e2005-04-16 15:20:36 -070043extern void __print_symbol(const char *fmt, unsigned long address);
44
Alexey Dobriyan9d65cb42007-05-08 00:28:43 -070045int lookup_symbol_name(unsigned long addr, char *symname);
Alexey Dobriyana5c43da2007-05-08 00:28:47 -070046int lookup_symbol_attrs(unsigned long addr, unsigned long *size, unsigned long *offset, char *modname, char *name);
Alexey Dobriyan9d65cb42007-05-08 00:28:43 -070047
Linus Torvalds1da177e2005-04-16 15:20:36 -070048#else /* !CONFIG_KALLSYMS */
49
50static inline unsigned long kallsyms_lookup_name(const char *name)
51{
52 return 0;
53}
54
Anders Kaseorg75a66612008-12-05 19:03:58 -050055static inline int kallsyms_on_each_symbol(int (*fn)(void *, const char *,
56 struct module *,
57 unsigned long),
58 void *data)
59{
60 return 0;
61}
62
Franck Bui-Huuffc50892006-10-03 01:13:48 -070063static inline int kallsyms_lookup_size_offset(unsigned long addr,
64 unsigned long *symbolsize,
65 unsigned long *offset)
66{
67 return 0;
68}
69
Linus Torvalds1da177e2005-04-16 15:20:36 -070070static inline const char *kallsyms_lookup(unsigned long addr,
71 unsigned long *symbolsize,
72 unsigned long *offset,
73 char **modname, char *namebuf)
74{
75 return NULL;
76}
77
Robert Peterson42e38082007-04-30 15:09:48 -070078static inline int sprint_symbol(char *buffer, unsigned long addr)
79{
80 *buffer = '\0';
81 return 0;
82}
83
Stephen Boyd4796dd22012-05-29 15:07:33 -070084static inline int sprint_symbol_no_offset(char *buffer, unsigned long addr)
85{
86 *buffer = '\0';
87 return 0;
88}
89
Namhyung Kim0f77a8d2011-03-24 11:42:29 +090090static inline int sprint_backtrace(char *buffer, unsigned long addr)
91{
92 *buffer = '\0';
93 return 0;
94}
95
Alexey Dobriyan9d65cb42007-05-08 00:28:43 -070096static inline int lookup_symbol_name(unsigned long addr, char *symname)
97{
98 return -ERANGE;
99}
100
Alexey Dobriyana5c43da2007-05-08 00:28:47 -0700101static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, unsigned long *offset, char *modname, char *name)
102{
103 return -ERANGE;
104}
105
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106/* Stupid that this does nothing, but I didn't create this mess. */
107#define __print_symbol(fmt, addr)
108#endif /*CONFIG_KALLSYMS*/
109
110/* This macro allows us to keep printk typechecking */
Joe Perchesb9075fa2011-10-31 17:11:33 -0700111static __printf(1, 2)
112void __check_printsym_format(const char *fmt, ...)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113{
114}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115
Heiko Carstensb02454f2006-07-03 00:24:06 -0700116static inline void print_symbol(const char *fmt, unsigned long addr)
117{
118 __check_printsym_format(fmt, "");
119 __print_symbol(fmt, (unsigned long)
120 __builtin_extract_return_addr((void *)addr));
121}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122
Vegard Nossum2711b792008-07-25 01:45:56 -0700123static inline void print_ip_sym(unsigned long ip)
124{
Vegard Nossum3f1712b2008-07-29 22:33:32 -0700125 printk("[<%p>] %pS\n", (void *) ip, (void *) ip);
Vegard Nossum2711b792008-07-25 01:45:56 -0700126}
Heiko Carstens8d8fdf52006-07-03 00:24:25 -0700127
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128#endif /*_LINUX_KALLSYMS_H*/