kallsyms.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. #include <linux/errno.h>
  8. #define KSYM_NAME_LEN 128
  9. #define KSYM_SYMBOL_LEN (sizeof("%s+%#lx/%#lx [%s]") + (KSYM_NAME_LEN - 1) + \
  10. 2*(BITS_PER_LONG*3/10) + (MODULE_NAME_LEN - 1) + 1)
  11. #ifdef CONFIG_KALLSYMS
  12. /* Lookup the address for a symbol. Returns 0 if not found. */
  13. unsigned long kallsyms_lookup_name(const char *name);
  14. extern int kallsyms_lookup_size_offset(unsigned long addr,
  15. unsigned long *symbolsize,
  16. unsigned long *offset);
  17. /* Lookup an address. modname is set to NULL if it's in the kernel. */
  18. const char *kallsyms_lookup(unsigned long addr,
  19. unsigned long *symbolsize,
  20. unsigned long *offset,
  21. char **modname, char *namebuf);
  22. /* Look up a kernel symbol and return it in a text buffer. */
  23. extern int sprint_symbol(char *buffer, unsigned long address);
  24. /* Look up a kernel symbol and print it to the kernel messages. */
  25. extern void __print_symbol(const char *fmt, unsigned long address);
  26. int lookup_symbol_name(unsigned long addr, char *symname);
  27. int lookup_symbol_attrs(unsigned long addr, unsigned long *size, unsigned long *offset, char *modname, char *name);
  28. #else /* !CONFIG_KALLSYMS */
  29. static inline unsigned long kallsyms_lookup_name(const char *name)
  30. {
  31. return 0;
  32. }
  33. static inline int kallsyms_lookup_size_offset(unsigned long addr,
  34. unsigned long *symbolsize,
  35. unsigned long *offset)
  36. {
  37. return 0;
  38. }
  39. static inline const char *kallsyms_lookup(unsigned long addr,
  40. unsigned long *symbolsize,
  41. unsigned long *offset,
  42. char **modname, char *namebuf)
  43. {
  44. return NULL;
  45. }
  46. static inline int sprint_symbol(char *buffer, unsigned long addr)
  47. {
  48. *buffer = '\0';
  49. return 0;
  50. }
  51. static inline int lookup_symbol_name(unsigned long addr, char *symname)
  52. {
  53. return -ERANGE;
  54. }
  55. static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, unsigned long *offset, char *modname, char *name)
  56. {
  57. return -ERANGE;
  58. }
  59. /* Stupid that this does nothing, but I didn't create this mess. */
  60. #define __print_symbol(fmt, addr)
  61. #endif /*CONFIG_KALLSYMS*/
  62. /* This macro allows us to keep printk typechecking */
  63. static void __check_printsym_format(const char *fmt, ...)
  64. __attribute__((format(printf,1,2)));
  65. static inline void __check_printsym_format(const char *fmt, ...)
  66. {
  67. }
  68. /* ia64 and ppc64 use function descriptors, which contain the real address */
  69. #if defined(CONFIG_IA64) || defined(CONFIG_PPC64)
  70. #define print_fn_descriptor_symbol(fmt, addr) \
  71. do { \
  72. unsigned long *__faddr = (unsigned long*) addr; \
  73. print_symbol(fmt, __faddr[0]); \
  74. } while (0)
  75. #else
  76. #define print_fn_descriptor_symbol(fmt, addr) print_symbol(fmt, addr)
  77. #endif
  78. static inline void print_symbol(const char *fmt, unsigned long addr)
  79. {
  80. __check_printsym_format(fmt, "");
  81. __print_symbol(fmt, (unsigned long)
  82. __builtin_extract_return_addr((void *)addr));
  83. }
  84. #ifndef CONFIG_64BIT
  85. #define print_ip_sym(ip) \
  86. do { \
  87. printk("[<%08lx>]", ip); \
  88. print_symbol(" %s\n", ip); \
  89. } while(0)
  90. #else
  91. #define print_ip_sym(ip) \
  92. do { \
  93. printk("[<%016lx>]", ip); \
  94. print_symbol(" %s\n", ip); \
  95. } while(0)
  96. #endif
  97. #endif /*_LINUX_KALLSYMS_H*/