Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/pmladek...
[linux-2.6-block.git] / include / linux / kallsyms.h
index bd118a6c60cbf8c5dd28478239e44550d899b57c..d79d1e7486bdf78d291d92ed785a9845a59ceb5e 100644 (file)
@@ -9,6 +9,10 @@
 #include <linux/errno.h>
 #include <linux/kernel.h>
 #include <linux/stddef.h>
+#include <linux/mm.h>
+#include <linux/module.h>
+
+#include <asm/sections.h>
 
 #define KSYM_NAME_LEN 128
 #define KSYM_SYMBOL_LEN (sizeof("%s+%#lx/%#lx [%s]") + (KSYM_NAME_LEN - 1) + \
 
 struct module;
 
+static inline int is_kernel_inittext(unsigned long addr)
+{
+       if (addr >= (unsigned long)_sinittext
+           && addr <= (unsigned long)_einittext)
+               return 1;
+       return 0;
+}
+
+static inline int is_kernel_text(unsigned long addr)
+{
+       if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
+           arch_is_kernel_text(addr))
+               return 1;
+       return in_gate_area_no_mm(addr);
+}
+
+static inline int is_kernel(unsigned long addr)
+{
+       if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
+               return 1;
+       return in_gate_area_no_mm(addr);
+}
+
+static inline int is_ksym_addr(unsigned long addr)
+{
+       if (IS_ENABLED(CONFIG_KALLSYMS_ALL))
+               return is_kernel(addr);
+
+       return is_kernel_text(addr) || is_kernel_inittext(addr);
+}
+
+static inline void *dereference_symbol_descriptor(void *ptr)
+{
+#ifdef HAVE_DEREFERENCE_FUNCTION_DESCRIPTOR
+       struct module *mod;
+
+       ptr = dereference_kernel_function_descriptor(ptr);
+       if (is_ksym_addr((unsigned long)ptr))
+               return ptr;
+
+       preempt_disable();
+       mod = __module_address((unsigned long)ptr);
+       preempt_enable();
+
+       if (mod)
+               ptr = dereference_module_function_descriptor(mod, ptr);
+#endif
+       return ptr;
+}
+
 #ifdef CONFIG_KALLSYMS
 /* Lookup the address for a symbol. Returns 0 if not found. */
 unsigned long kallsyms_lookup_name(const char *name);
@@ -40,9 +94,6 @@ extern int sprint_symbol(char *buffer, unsigned long address);
 extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
 extern int sprint_backtrace(char *buffer, unsigned long address);
 
-/* Look up a kernel symbol and print it to the kernel messages. */
-extern void __print_symbol(const char *fmt, unsigned long address);
-
 int lookup_symbol_name(unsigned long addr, char *symname);
 int lookup_symbol_attrs(unsigned long addr, unsigned long *size, unsigned long *offset, char *modname, char *name);
 
@@ -112,23 +163,8 @@ static inline int kallsyms_show_value(void)
        return false;
 }
 
-/* Stupid that this does nothing, but I didn't create this mess. */
-#define __print_symbol(fmt, addr)
 #endif /*CONFIG_KALLSYMS*/
 
-/* This macro allows us to keep printk typechecking */
-static __printf(1, 2)
-void __check_printsym_format(const char *fmt, ...)
-{
-}
-
-static inline void print_symbol(const char *fmt, unsigned long addr)
-{
-       __check_printsym_format(fmt, "");
-       __print_symbol(fmt, (unsigned long)
-                      __builtin_extract_return_addr((void *)addr));
-}
-
 static inline void print_ip_sym(unsigned long ip)
 {
        printk("[<%p>] %pS\n", (void *) ip, (void *) ip);