blob: 12178d2c882be4461714df1c9147c5ae0852d4cc [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
Linus Torvalds1da177e2005-04-16 15:20:36 -07008
9#define KSYM_NAME_LEN 127
Robert Peterson42e38082007-04-30 15:09:48 -070010#define KSYM_SYMBOL_LEN (sizeof("%s+%#lx/%#lx [%s]") + KSYM_NAME_LEN + \
11 2*(BITS_PER_LONG*3/10) + MODULE_NAME_LEN + 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -070012
13#ifdef CONFIG_KALLSYMS
14/* Lookup the address for a symbol. Returns 0 if not found. */
15unsigned long kallsyms_lookup_name(const char *name);
16
Franck Bui-Huuffc50892006-10-03 01:13:48 -070017extern int kallsyms_lookup_size_offset(unsigned long addr,
18 unsigned long *symbolsize,
19 unsigned long *offset);
20
Linus Torvalds1da177e2005-04-16 15:20:36 -070021/* Lookup an address. modname is set to NULL if it's in the kernel. */
22const char *kallsyms_lookup(unsigned long addr,
23 unsigned long *symbolsize,
24 unsigned long *offset,
25 char **modname, char *namebuf);
26
Robert Peterson42e38082007-04-30 15:09:48 -070027/* Look up a kernel symbol and return it in a text buffer. */
28extern int sprint_symbol(char *buffer, unsigned long address);
29
30/* Look up a kernel symbol and print it to the kernel messages. */
Linus Torvalds1da177e2005-04-16 15:20:36 -070031extern void __print_symbol(const char *fmt, unsigned long address);
32
Alexey Dobriyan9d65cb42007-05-08 00:28:43 -070033int lookup_symbol_name(unsigned long addr, char *symname);
Alexey Dobriyana5c43da2007-05-08 00:28:47 -070034int lookup_symbol_attrs(unsigned long addr, unsigned long *size, unsigned long *offset, char *modname, char *name);
Alexey Dobriyan9d65cb42007-05-08 00:28:43 -070035
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#else /* !CONFIG_KALLSYMS */
37
38static inline unsigned long kallsyms_lookup_name(const char *name)
39{
40 return 0;
41}
42
Franck Bui-Huuffc50892006-10-03 01:13:48 -070043static inline int kallsyms_lookup_size_offset(unsigned long addr,
44 unsigned long *symbolsize,
45 unsigned long *offset)
46{
47 return 0;
48}
49
Linus Torvalds1da177e2005-04-16 15:20:36 -070050static inline const char *kallsyms_lookup(unsigned long addr,
51 unsigned long *symbolsize,
52 unsigned long *offset,
53 char **modname, char *namebuf)
54{
55 return NULL;
56}
57
Robert Peterson42e38082007-04-30 15:09:48 -070058static inline int sprint_symbol(char *buffer, unsigned long addr)
59{
60 *buffer = '\0';
61 return 0;
62}
63
Alexey Dobriyan9d65cb42007-05-08 00:28:43 -070064static inline int lookup_symbol_name(unsigned long addr, char *symname)
65{
66 return -ERANGE;
67}
68
Alexey Dobriyana5c43da2007-05-08 00:28:47 -070069static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, unsigned long *offset, char *modname, char *name)
70{
71 return -ERANGE;
72}
73
Linus Torvalds1da177e2005-04-16 15:20:36 -070074/* Stupid that this does nothing, but I didn't create this mess. */
75#define __print_symbol(fmt, addr)
76#endif /*CONFIG_KALLSYMS*/
77
78/* This macro allows us to keep printk typechecking */
79static void __check_printsym_format(const char *fmt, ...)
80__attribute__((format(printf,1,2)));
81static inline void __check_printsym_format(const char *fmt, ...)
82{
83}
84/* ia64 and ppc64 use function descriptors, which contain the real address */
85#if defined(CONFIG_IA64) || defined(CONFIG_PPC64)
86#define print_fn_descriptor_symbol(fmt, addr) \
87do { \
88 unsigned long *__faddr = (unsigned long*) addr; \
89 print_symbol(fmt, __faddr[0]); \
90} while (0)
91#else
92#define print_fn_descriptor_symbol(fmt, addr) print_symbol(fmt, addr)
93#endif
94
Heiko Carstensb02454f2006-07-03 00:24:06 -070095static inline void print_symbol(const char *fmt, unsigned long addr)
96{
97 __check_printsym_format(fmt, "");
98 __print_symbol(fmt, (unsigned long)
99 __builtin_extract_return_addr((void *)addr));
100}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101
Heiko Carstens8d8fdf52006-07-03 00:24:25 -0700102#ifndef CONFIG_64BIT
103#define print_ip_sym(ip) \
104do { \
105 printk("[<%08lx>]", ip); \
106 print_symbol(" %s\n", ip); \
107} while(0)
108#else
109#define print_ip_sym(ip) \
110do { \
111 printk("[<%016lx>]", ip); \
112 print_symbol(" %s\n", ip); \
113} while(0)
114#endif
115
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116#endif /*_LINUX_KALLSYMS_H*/