linux/include/linux/kallsyms.h
<<
>>
Prefs
   1/* 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
   8#include <linux/errno.h>
   9#include <linux/kernel.h>
  10#include <linux/stddef.h>
  11
  12#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)
  15
  16struct module;
  17
  18#ifdef CONFIG_KALLSYMS
  19/* Lookup the address for a symbol. Returns 0 if not found. */
  20unsigned long kallsyms_lookup_name(const char *name);
  21
  22/* Call a function on each kallsyms symbol in the core kernel */
  23int kallsyms_on_each_symbol(int (*fn)(void *, const char *, struct module *,
  24                                      unsigned long),
  25                            void *data);
  26
  27extern int kallsyms_lookup_size_offset(unsigned long addr,
  28                                  unsigned long *symbolsize,
  29                                  unsigned long *offset);
  30
  31/* Lookup an address.  modname is set to NULL if it's in the kernel. */
  32const char *kallsyms_lookup(unsigned long addr,
  33                            unsigned long *symbolsize,
  34                            unsigned long *offset,
  35                            char **modname, char *namebuf);
  36
  37/* Look up a kernel symbol and return it in a text buffer. */
  38extern int sprint_symbol(char *buffer, unsigned long address);
  39extern int sprint_backtrace(char *buffer, unsigned long address);
  40
  41/* Look up a kernel symbol and print it to the kernel messages. */
  42extern void __print_symbol(const char *fmt, unsigned long address);
  43
  44int lookup_symbol_name(unsigned long addr, char *symname);
  45int lookup_symbol_attrs(unsigned long addr, unsigned long *size, unsigned long *offset, char *modname, char *name);
  46
  47#else /* !CONFIG_KALLSYMS */
  48
  49static inline unsigned long kallsyms_lookup_name(const char *name)
  50{
  51        return 0;
  52}
  53
  54static inline int kallsyms_on_each_symbol(int (*fn)(void *, const char *,
  55                                                    struct module *,
  56                                                    unsigned long),
  57                                          void *data)
  58{
  59        return 0;
  60}
  61
  62static inline int kallsyms_lookup_size_offset(unsigned long addr,
  63                                              unsigned long *symbolsize,
  64                                              unsigned long *offset)
  65{
  66        return 0;
  67}
  68
  69static inline const char *kallsyms_lookup(unsigned long addr,
  70                                          unsigned long *symbolsize,
  71                                          unsigned long *offset,
  72                                          char **modname, char *namebuf)
  73{
  74        return NULL;
  75}
  76
  77static inline int sprint_symbol(char *buffer, unsigned long addr)
  78{
  79        *buffer = '\0';
  80        return 0;
  81}
  82
  83static inline int sprint_backtrace(char *buffer, unsigned long addr)
  84{
  85        *buffer = '\0';
  86        return 0;
  87}
  88
  89static inline int lookup_symbol_name(unsigned long addr, char *symname)
  90{
  91        return -ERANGE;
  92}
  93
  94static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, unsigned long *offset, char *modname, char *name)
  95{
  96        return -ERANGE;
  97}
  98
  99/* Stupid that this does nothing, but I didn't create this mess. */
 100#define __print_symbol(fmt, addr)
 101#endif /*CONFIG_KALLSYMS*/
 102
 103/* This macro allows us to keep printk typechecking */
 104static __printf(1, 2)
 105void __check_printsym_format(const char *fmt, ...)
 106{
 107}
 108
 109static inline void print_symbol(const char *fmt, unsigned long addr)
 110{
 111        __check_printsym_format(fmt, "");
 112        __print_symbol(fmt, (unsigned long)
 113                       __builtin_extract_return_addr((void *)addr));
 114}
 115
 116static inline void print_ip_sym(unsigned long ip)
 117{
 118        printk("[<%p>] %pS\n", (void *) ip, (void *) ip);
 119}
 120
 121#endif /*_LINUX_KALLSYMS_H*/
 122