blob: 1cebcbc28b474d9f7af1d4061f0e30ba60347aa8 [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
10
11#ifdef CONFIG_KALLSYMS
12/* Lookup the address for a symbol. Returns 0 if not found. */
13unsigned long kallsyms_lookup_name(const char *name);
14
Franck Bui-Huuffc50892006-10-03 01:13:48 -070015extern int kallsyms_lookup_size_offset(unsigned long addr,
16 unsigned long *symbolsize,
17 unsigned long *offset);
18
Linus Torvalds1da177e2005-04-16 15:20:36 -070019/* Lookup an address. modname is set to NULL if it's in the kernel. */
20const char *kallsyms_lookup(unsigned long addr,
21 unsigned long *symbolsize,
22 unsigned long *offset,
23 char **modname, char *namebuf);
24
25/* Replace "%s" in format with address, if found */
26extern void __print_symbol(const char *fmt, unsigned long address);
27
28#else /* !CONFIG_KALLSYMS */
29
30static inline unsigned long kallsyms_lookup_name(const char *name)
31{
32 return 0;
33}
34
Franck Bui-Huuffc50892006-10-03 01:13:48 -070035static inline int kallsyms_lookup_size_offset(unsigned long addr,
36 unsigned long *symbolsize,
37 unsigned long *offset)
38{
39 return 0;
40}
41
Linus Torvalds1da177e2005-04-16 15:20:36 -070042static inline const char *kallsyms_lookup(unsigned long addr,
43 unsigned long *symbolsize,
44 unsigned long *offset,
45 char **modname, char *namebuf)
46{
47 return NULL;
48}
49
50/* Stupid that this does nothing, but I didn't create this mess. */
51#define __print_symbol(fmt, addr)
52#endif /*CONFIG_KALLSYMS*/
53
54/* This macro allows us to keep printk typechecking */
55static void __check_printsym_format(const char *fmt, ...)
56__attribute__((format(printf,1,2)));
57static inline void __check_printsym_format(const char *fmt, ...)
58{
59}
60/* ia64 and ppc64 use function descriptors, which contain the real address */
61#if defined(CONFIG_IA64) || defined(CONFIG_PPC64)
62#define print_fn_descriptor_symbol(fmt, addr) \
63do { \
64 unsigned long *__faddr = (unsigned long*) addr; \
65 print_symbol(fmt, __faddr[0]); \
66} while (0)
67#else
68#define print_fn_descriptor_symbol(fmt, addr) print_symbol(fmt, addr)
69#endif
70
Heiko Carstensb02454f2006-07-03 00:24:06 -070071static inline void print_symbol(const char *fmt, unsigned long addr)
72{
73 __check_printsym_format(fmt, "");
74 __print_symbol(fmt, (unsigned long)
75 __builtin_extract_return_addr((void *)addr));
76}
Linus Torvalds1da177e2005-04-16 15:20:36 -070077
Heiko Carstens8d8fdf52006-07-03 00:24:25 -070078#ifndef CONFIG_64BIT
79#define print_ip_sym(ip) \
80do { \
81 printk("[<%08lx>]", ip); \
82 print_symbol(" %s\n", ip); \
83} while(0)
84#else
85#define print_ip_sym(ip) \
86do { \
87 printk("[<%016lx>]", ip); \
88 print_symbol(" %s\n", ip); \
89} while(0)
90#endif
91
Linus Torvalds1da177e2005-04-16 15:20:36 -070092#endif /*_LINUX_KALLSYMS_H*/