kallsyms.h 3.5 KB

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