mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-10-27 22:51:31 +00:00
04b8eb7a4c
dereference_symbol_descriptor() invokes appropriate ARCH specific function descriptor dereference callbacks: - dereference_kernel_function_descriptor() if the pointer is a kernel symbol; - dereference_module_function_descriptor() if the pointer is a module symbol. This is the last step needed to make '%pS/%ps' smart enough to handle function descriptor dereference on affected ARCHs and to retire '%pF/%pf'. To refresh it: Some architectures (ia64, ppc64, parisc64) use an indirect pointer for C function pointers - the function pointer points to a function descriptor and we need to dereference it to get the actual function pointer. Function descriptors live in .opd elf section and all affected ARCHs (ia64, ppc64, parisc64) handle it properly for kernel and modules. So we, technically, can decide if the dereference is needed by simply looking at the pointer: if it belongs to .opd section then we need to dereference it. The kernel and modules have their own .opd sections, obviously, that's why we need to split dereference_function_descriptor() and use separate kernel and module dereference arch callbacks. Link: http://lkml.kernel.org/r/20171206043649.GB15885@jagdpanzerIV Cc: Fenghua Yu <fenghua.yu@intel.com> Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org> Cc: Paul Mackerras <paulus@samba.org> Cc: Michael Ellerman <mpe@ellerman.id.au> Cc: James Bottomley <jejb@parisc-linux.org> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Jessica Yu <jeyu@kernel.org> Cc: Steven Rostedt <rostedt@goodmis.org> Cc: linux-ia64@vger.kernel.org Cc: linux-parisc@vger.kernel.org Cc: linuxppc-dev@lists.ozlabs.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com> Tested-by: Tony Luck <tony.luck@intel.com> #ia64 Tested-by: Santosh Sivaraj <santosh@fossix.org> #powerpc Tested-by: Helge Deller <deller@gmx.de> #parisc64 Signed-off-by: Petr Mladek <pmladek@suse.com>
197 lines
4.9 KiB
C
197 lines
4.9 KiB
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
/* Rewritten and vastly simplified by Rusty Russell for in-kernel
|
|
* module loader:
|
|
* Copyright 2002 Rusty Russell <rusty@rustcorp.com.au> IBM Corporation
|
|
*/
|
|
#ifndef _LINUX_KALLSYMS_H
|
|
#define _LINUX_KALLSYMS_H
|
|
|
|
#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) + \
|
|
2*(BITS_PER_LONG*3/10) + (MODULE_NAME_LEN - 1) + 1)
|
|
|
|
#ifndef CONFIG_64BIT
|
|
# define KALLSYM_FMT "%08lx"
|
|
#else
|
|
# define KALLSYM_FMT "%016lx"
|
|
#endif
|
|
|
|
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);
|
|
|
|
/* Call a function on each kallsyms symbol in the core kernel */
|
|
int kallsyms_on_each_symbol(int (*fn)(void *, const char *, struct module *,
|
|
unsigned long),
|
|
void *data);
|
|
|
|
extern int kallsyms_lookup_size_offset(unsigned long addr,
|
|
unsigned long *symbolsize,
|
|
unsigned long *offset);
|
|
|
|
/* Lookup an address. modname is set to NULL if it's in the kernel. */
|
|
const char *kallsyms_lookup(unsigned long addr,
|
|
unsigned long *symbolsize,
|
|
unsigned long *offset,
|
|
char **modname, char *namebuf);
|
|
|
|
/* Look up a kernel symbol and return it in a text buffer. */
|
|
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);
|
|
|
|
/* How and when do we show kallsyms values? */
|
|
extern int kallsyms_show_value(void);
|
|
|
|
#else /* !CONFIG_KALLSYMS */
|
|
|
|
static inline unsigned long kallsyms_lookup_name(const char *name)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
static inline int kallsyms_on_each_symbol(int (*fn)(void *, const char *,
|
|
struct module *,
|
|
unsigned long),
|
|
void *data)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
static inline int kallsyms_lookup_size_offset(unsigned long addr,
|
|
unsigned long *symbolsize,
|
|
unsigned long *offset)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
static inline const char *kallsyms_lookup(unsigned long addr,
|
|
unsigned long *symbolsize,
|
|
unsigned long *offset,
|
|
char **modname, char *namebuf)
|
|
{
|
|
return NULL;
|
|
}
|
|
|
|
static inline int sprint_symbol(char *buffer, unsigned long addr)
|
|
{
|
|
*buffer = '\0';
|
|
return 0;
|
|
}
|
|
|
|
static inline int sprint_symbol_no_offset(char *buffer, unsigned long addr)
|
|
{
|
|
*buffer = '\0';
|
|
return 0;
|
|
}
|
|
|
|
static inline int sprint_backtrace(char *buffer, unsigned long addr)
|
|
{
|
|
*buffer = '\0';
|
|
return 0;
|
|
}
|
|
|
|
static inline int lookup_symbol_name(unsigned long addr, char *symname)
|
|
{
|
|
return -ERANGE;
|
|
}
|
|
|
|
static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, unsigned long *offset, char *modname, char *name)
|
|
{
|
|
return -ERANGE;
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
#endif /*_LINUX_KALLSYMS_H*/
|