kallsyms.h 3.3 KB

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