aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/kallsyms.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/kallsyms.h')
-rw-r--r--include/linux/kallsyms.h74
1 files changed, 55 insertions, 19 deletions
diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
index bd118a6c60cb..657a83b943f0 100644
--- a/include/linux/kallsyms.h
+++ b/include/linux/kallsyms.h
@@ -9,6 +9,10 @@
9#include <linux/errno.h> 9#include <linux/errno.h>
10#include <linux/kernel.h> 10#include <linux/kernel.h>
11#include <linux/stddef.h> 11#include <linux/stddef.h>
12#include <linux/mm.h>
13#include <linux/module.h>
14
15#include <asm/sections.h>
12 16
13#define KSYM_NAME_LEN 128 17#define KSYM_NAME_LEN 128
14#define KSYM_SYMBOL_LEN (sizeof("%s+%#lx/%#lx [%s]") + (KSYM_NAME_LEN - 1) + \ 18#define KSYM_SYMBOL_LEN (sizeof("%s+%#lx/%#lx [%s]") + (KSYM_NAME_LEN - 1) + \
@@ -16,6 +20,56 @@
16 20
17struct module; 21struct module;
18 22
23static inline int is_kernel_inittext(unsigned long addr)
24{
25 if (addr >= (unsigned long)_sinittext
26 && addr <= (unsigned long)_einittext)
27 return 1;
28 return 0;
29}
30
31static inline int is_kernel_text(unsigned long addr)
32{
33 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
34 arch_is_kernel_text(addr))
35 return 1;
36 return in_gate_area_no_mm(addr);
37}
38
39static inline int is_kernel(unsigned long addr)
40{
41 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
42 return 1;
43 return in_gate_area_no_mm(addr);
44}
45
46static inline int is_ksym_addr(unsigned long addr)
47{
48 if (IS_ENABLED(CONFIG_KALLSYMS_ALL))
49 return is_kernel(addr);
50
51 return is_kernel_text(addr) || is_kernel_inittext(addr);
52}
53
54static inline void *dereference_symbol_descriptor(void *ptr)
55{
56#ifdef HAVE_DEREFERENCE_FUNCTION_DESCRIPTOR
57 struct module *mod;
58
59 ptr = dereference_kernel_function_descriptor(ptr);
60 if (is_ksym_addr((unsigned long)ptr))
61 return ptr;
62
63 preempt_disable();
64 mod = __module_address((unsigned long)ptr);
65 preempt_enable();
66
67 if (mod)
68 ptr = dereference_module_function_descriptor(mod, ptr);
69#endif
70 return ptr;
71}
72
19#ifdef CONFIG_KALLSYMS 73#ifdef CONFIG_KALLSYMS
20/* Lookup the address for a symbol. Returns 0 if not found. */ 74/* Lookup the address for a symbol. Returns 0 if not found. */
21unsigned long kallsyms_lookup_name(const char *name); 75unsigned long kallsyms_lookup_name(const char *name);
@@ -40,9 +94,6 @@ extern int sprint_symbol(char *buffer, unsigned long address);
40extern int sprint_symbol_no_offset(char *buffer, unsigned long address); 94extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
41extern int sprint_backtrace(char *buffer, unsigned long address); 95extern int sprint_backtrace(char *buffer, unsigned long address);
42 96
43/* Look up a kernel symbol and print it to the kernel messages. */
44extern void __print_symbol(const char *fmt, unsigned long address);
45
46int lookup_symbol_name(unsigned long addr, char *symname); 97int lookup_symbol_name(unsigned long addr, char *symname);
47int lookup_symbol_attrs(unsigned long addr, unsigned long *size, unsigned long *offset, char *modname, char *name); 98int lookup_symbol_attrs(unsigned long addr, unsigned long *size, unsigned long *offset, char *modname, char *name);
48 99
@@ -112,26 +163,11 @@ static inline int kallsyms_show_value(void)
112 return false; 163 return false;
113} 164}
114 165
115/* Stupid that this does nothing, but I didn't create this mess. */
116#define __print_symbol(fmt, addr)
117#endif /*CONFIG_KALLSYMS*/ 166#endif /*CONFIG_KALLSYMS*/
118 167
119/* This macro allows us to keep printk typechecking */
120static __printf(1, 2)
121void __check_printsym_format(const char *fmt, ...)
122{
123}
124
125static inline void print_symbol(const char *fmt, unsigned long addr)
126{
127 __check_printsym_format(fmt, "");
128 __print_symbol(fmt, (unsigned long)
129 __builtin_extract_return_addr((void *)addr));
130}
131
132static inline void print_ip_sym(unsigned long ip) 168static inline void print_ip_sym(unsigned long ip)
133{ 169{
134 printk("[<%p>] %pS\n", (void *) ip, (void *) ip); 170 printk("[<%px>] %pS\n", (void *) ip, (void *) ip);
135} 171}
136 172
137#endif /*_LINUX_KALLSYMS_H*/ 173#endif /*_LINUX_KALLSYMS_H*/