kallsyms.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. #define KSYM_NAME_LEN 127
  8. #ifdef CONFIG_KALLSYMS
  9. /* Lookup the address for a symbol. Returns 0 if not found. */
  10. unsigned long kallsyms_lookup_name(const char *name);
  11. /* Lookup an address. modname is set to NULL if it's in the kernel. */
  12. const char *kallsyms_lookup(unsigned long addr,
  13. unsigned long *symbolsize,
  14. unsigned long *offset,
  15. char **modname, char *namebuf);
  16. /* Replace "%s" in format with address, if found */
  17. extern void __print_symbol(const char *fmt, unsigned long address);
  18. #else /* !CONFIG_KALLSYMS */
  19. static inline unsigned long kallsyms_lookup_name(const char *name)
  20. {
  21. return 0;
  22. }
  23. static inline const char *kallsyms_lookup(unsigned long addr,
  24. unsigned long *symbolsize,
  25. unsigned long *offset,
  26. char **modname, char *namebuf)
  27. {
  28. return NULL;
  29. }
  30. /* Stupid that this does nothing, but I didn't create this mess. */
  31. #define __print_symbol(fmt, addr)
  32. #endif /*CONFIG_KALLSYMS*/
  33. /* This macro allows us to keep printk typechecking */
  34. static void __check_printsym_format(const char *fmt, ...)
  35. __attribute__((format(printf,1,2)));
  36. static inline void __check_printsym_format(const char *fmt, ...)
  37. {
  38. }
  39. /* ia64 and ppc64 use function descriptors, which contain the real address */
  40. #if defined(CONFIG_IA64) || defined(CONFIG_PPC64)
  41. #define print_fn_descriptor_symbol(fmt, addr) \
  42. do { \
  43. unsigned long *__faddr = (unsigned long*) addr; \
  44. print_symbol(fmt, __faddr[0]); \
  45. } while (0)
  46. #else
  47. #define print_fn_descriptor_symbol(fmt, addr) print_symbol(fmt, addr)
  48. #endif
  49. static inline void print_symbol(const char *fmt, unsigned long addr)
  50. {
  51. __check_printsym_format(fmt, "");
  52. __print_symbol(fmt, (unsigned long)
  53. __builtin_extract_return_addr((void *)addr));
  54. }
  55. #ifndef CONFIG_64BIT
  56. #define print_ip_sym(ip) \
  57. do { \
  58. printk("[<%08lx>]", ip); \
  59. print_symbol(" %s\n", ip); \
  60. } while(0)
  61. #else
  62. #define print_ip_sym(ip) \
  63. do { \
  64. printk("[<%016lx>]", ip); \
  65. print_symbol(" %s\n", ip); \
  66. } while(0)
  67. #endif
  68. #endif /*_LINUX_KALLSYMS_H*/