blob: f3fe34391d8e2664f2d1bef0140b184f879b8e32 [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
16#ifdef CONFIG_KALLSYMS
17/* Lookup the address for a symbol. Returns 0 if not found. */
18unsigned long kallsyms_lookup_name(const char *name);
19
Franck Bui-Huuffc50892006-10-03 01:13:48 -070020extern int kallsyms_lookup_size_offset(unsigned long addr,
21 unsigned long *symbolsize,
22 unsigned long *offset);
23
Linus Torvalds1da177e2005-04-16 15:20:36 -070024/* Lookup an address. modname is set to NULL if it's in the kernel. */
25const char *kallsyms_lookup(unsigned long addr,
26 unsigned long *symbolsize,
27 unsigned long *offset,
28 char **modname, char *namebuf);
29
Robert Peterson42e38082007-04-30 15:09:48 -070030/* Look up a kernel symbol and return it in a text buffer. */
31extern int sprint_symbol(char *buffer, unsigned long address);
32
33/* Look up a kernel symbol and print it to the kernel messages. */
Linus Torvalds1da177e2005-04-16 15:20:36 -070034extern void __print_symbol(const char *fmt, unsigned long address);
35
Alexey Dobriyan9d65cb42007-05-08 00:28:43 -070036int lookup_symbol_name(unsigned long addr, char *symname);
Alexey Dobriyana5c43da2007-05-08 00:28:47 -070037int lookup_symbol_attrs(unsigned long addr, unsigned long *size, unsigned long *offset, char *modname, char *name);
Alexey Dobriyan9d65cb42007-05-08 00:28:43 -070038
Linus Torvalds1da177e2005-04-16 15:20:36 -070039#else /* !CONFIG_KALLSYMS */
40
41static inline unsigned long kallsyms_lookup_name(const char *name)
42{
43 return 0;
44}
45
Franck Bui-Huuffc50892006-10-03 01:13:48 -070046static inline int kallsyms_lookup_size_offset(unsigned long addr,
47 unsigned long *symbolsize,
48 unsigned long *offset)
49{
50 return 0;
51}
52
Linus Torvalds1da177e2005-04-16 15:20:36 -070053static inline const char *kallsyms_lookup(unsigned long addr,
54 unsigned long *symbolsize,
55 unsigned long *offset,
56 char **modname, char *namebuf)
57{
58 return NULL;
59}
60
Robert Peterson42e38082007-04-30 15:09:48 -070061static inline int sprint_symbol(char *buffer, unsigned long addr)
62{
63 *buffer = '\0';
64 return 0;
65}
66
Alexey Dobriyan9d65cb42007-05-08 00:28:43 -070067static inline int lookup_symbol_name(unsigned long addr, char *symname)
68{
69 return -ERANGE;
70}
71
Alexey Dobriyana5c43da2007-05-08 00:28:47 -070072static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, unsigned long *offset, char *modname, char *name)
73{
74 return -ERANGE;
75}
76
Linus Torvalds1da177e2005-04-16 15:20:36 -070077/* Stupid that this does nothing, but I didn't create this mess. */
78#define __print_symbol(fmt, addr)
79#endif /*CONFIG_KALLSYMS*/
80
81/* This macro allows us to keep printk typechecking */
82static void __check_printsym_format(const char *fmt, ...)
83__attribute__((format(printf,1,2)));
84static inline void __check_printsym_format(const char *fmt, ...)
85{
86}
Linus Torvalds1da177e2005-04-16 15:20:36 -070087
Heiko Carstensb02454f2006-07-03 00:24:06 -070088static inline void print_symbol(const char *fmt, unsigned long addr)
89{
90 __check_printsym_format(fmt, "");
91 __print_symbol(fmt, (unsigned long)
92 __builtin_extract_return_addr((void *)addr));
93}
Linus Torvalds1da177e2005-04-16 15:20:36 -070094
Linus Torvaldsa442ac52008-05-15 17:50:37 -070095/*
Bjorn Helgaasc80cfb02008-10-15 22:01:35 -070096 * Pretty-print a function pointer. This function is deprecated.
97 * Please use the "%pF" vsprintf format instead.
Linus Torvaldsa442ac52008-05-15 17:50:37 -070098 */
Bjorn Helgaasc80cfb02008-10-15 22:01:35 -070099static inline void __deprecated print_fn_descriptor_symbol(const char *fmt, void *addr)
Linus Torvaldsa442ac52008-05-15 17:50:37 -0700100{
101#if defined(CONFIG_IA64) || defined(CONFIG_PPC64)
102 addr = *(void **)addr;
103#endif
104 print_symbol(fmt, (unsigned long)addr);
105}
106
Vegard Nossum2711b792008-07-25 01:45:56 -0700107static inline void print_ip_sym(unsigned long ip)
108{
Vegard Nossum3f1712b2008-07-29 22:33:32 -0700109 printk("[<%p>] %pS\n", (void *) ip, (void *) ip);
Vegard Nossum2711b792008-07-25 01:45:56 -0700110}
Heiko Carstens8d8fdf52006-07-03 00:24:25 -0700111
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112#endif /*_LINUX_KALLSYMS_H*/