kallsyms.h 3.3 KB

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