kallsyms.h 3.2 KB

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