]> git.ipfire.org Git - people/arne_f/kernel.git/blame - include/linux/kallsyms.h
License cleanup: add SPDX GPL-2.0 license identifier to files with no license
[people/arne_f/kernel.git] / include / linux / kallsyms.h
CommitLineData
b2441318 1/* SPDX-License-Identifier: GPL-2.0 */
1da177e4
LT
2/* 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
40e48eed 9#include <linux/errno.h>
2711b793 10#include <linux/kernel.h>
5a75983e 11#include <linux/stddef.h>
1da177e4 12
9281acea
TH
13#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)
1da177e4 16
75a66614
AK
17struct module;
18
1da177e4
LT
19#ifdef CONFIG_KALLSYMS
20/* Lookup the address for a symbol. Returns 0 if not found. */
21unsigned long kallsyms_lookup_name(const char *name);
22
75a66614
AK
23/* 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
ffc50891
FBH
28extern int kallsyms_lookup_size_offset(unsigned long addr,
29 unsigned long *symbolsize,
30 unsigned long *offset);
31
1da177e4
LT
32/* 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
42e38083
RP
38/* Look up a kernel symbol and return it in a text buffer. */
39extern int sprint_symbol(char *buffer, unsigned long address);
4796dd20 40extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
0f77a8d3 41extern int sprint_backtrace(char *buffer, unsigned long address);
42e38083
RP
42
43/* Look up a kernel symbol and print it to the kernel messages. */
1da177e4
LT
44extern void __print_symbol(const char *fmt, unsigned long address);
45
9d65cb4a 46int lookup_symbol_name(unsigned long addr, char *symname);
a5c43dae 47int lookup_symbol_attrs(unsigned long addr, unsigned long *size, unsigned long *offset, char *modname, char *name);
9d65cb4a 48
1da177e4
LT
49#else /* !CONFIG_KALLSYMS */
50
51static inline unsigned long kallsyms_lookup_name(const char *name)
52{
53 return 0;
54}
55
75a66614
AK
56static 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
ffc50891
FBH
64static inline int kallsyms_lookup_size_offset(unsigned long addr,
65 unsigned long *symbolsize,
66 unsigned long *offset)
67{
68 return 0;
69}
70
1da177e4
LT
71static 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
42e38083
RP
79static inline int sprint_symbol(char *buffer, unsigned long addr)
80{
81 *buffer = '\0';
82 return 0;
83}
84
4796dd20
SB
85static inline int sprint_symbol_no_offset(char *buffer, unsigned long addr)
86{
87 *buffer = '\0';
88 return 0;
89}
90
0f77a8d3
NK
91static inline int sprint_backtrace(char *buffer, unsigned long addr)
92{
93 *buffer = '\0';
94 return 0;
95}
96
9d65cb4a
AD
97static inline int lookup_symbol_name(unsigned long addr, char *symname)
98{
99 return -ERANGE;
100}
101
a5c43dae
AD
102static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, unsigned long *offset, char *modname, char *name)
103{
104 return -ERANGE;
105}
106
1da177e4
LT
107/* 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 */
b9075fa9
JP
112static __printf(1, 2)
113void __check_printsym_format(const char *fmt, ...)
1da177e4
LT
114{
115}
1da177e4 116
b02454f4
HC
117static 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}
1da177e4 123
2711b793
VN
124static inline void print_ip_sym(unsigned long ip)
125{
3f1712ba 126 printk("[<%p>] %pS\n", (void *) ip, (void *) ip);
2711b793 127}
8d8fdf5c 128
1da177e4 129#endif /*_LINUX_KALLSYMS_H*/