kallsyms.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
  32. extern int sprint_backtrace(char *buffer, unsigned long address);
  33. /* Look up a kernel symbol and print it to the kernel messages. */
  34. extern void __print_symbol(const char *fmt, unsigned long address);
  35. int lookup_symbol_name(unsigned long addr, char *symname);
  36. int lookup_symbol_attrs(unsigned long addr, unsigned long *size, unsigned long *offset, char *modname, char *name);
  37. #else /* !CONFIG_KALLSYMS */
  38. static inline unsigned long kallsyms_lookup_name(const char *name)
  39. {
  40. return 0;
  41. }
  42. static inline int kallsyms_on_each_symbol(int (*fn)(void *, const char *,
  43. struct module *,
  44. unsigned long),
  45. void *data)
  46. {
  47. return 0;
  48. }
  49. static inline int kallsyms_lookup_size_offset(unsigned long addr,
  50. unsigned long *symbolsize,
  51. unsigned long *offset)
  52. {
  53. return 0;
  54. }
  55. static inline const char *kallsyms_lookup(unsigned long addr,
  56. unsigned long *symbolsize,
  57. unsigned long *offset,
  58. char **modname, char *namebuf)
  59. {
  60. return NULL;
  61. }
  62. static inline int sprint_symbol(char *buffer, unsigned long addr)
  63. {
  64. *buffer = '\0';
  65. return 0;
  66. }
  67. static inline int sprint_symbol_no_offset(char *buffer, unsigned long addr)
  68. {
  69. *buffer = '\0';
  70. return 0;
  71. }
  72. static inline int sprint_backtrace(char *buffer, unsigned long addr)
  73. {
  74. *buffer = '\0';
  75. return 0;
  76. }
  77. static inline int lookup_symbol_name(unsigned long addr, char *symname)
  78. {
  79. return -ERANGE;
  80. }
  81. static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, unsigned long *offset, char *modname, char *name)
  82. {
  83. return -ERANGE;
  84. }
  85. /* Stupid that this does nothing, but I didn't create this mess. */
  86. #define __print_symbol(fmt, addr)
  87. #endif /*CONFIG_KALLSYMS*/
  88. /* This macro allows us to keep printk typechecking */
  89. static __printf(1, 2)
  90. void __check_printsym_format(const char *fmt, ...)
  91. {
  92. }
  93. static inline void print_symbol(const char *fmt, unsigned long addr)
  94. {
  95. __check_printsym_format(fmt, "");
  96. __print_symbol(fmt, (unsigned long)
  97. __builtin_extract_return_addr((void *)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*/