export.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #ifndef _LINUX_EXPORT_H
  2. #define _LINUX_EXPORT_H
  3. /*
  4. * Export symbols from the kernel to modules. Forked from module.h
  5. * to reduce the amount of pointless cruft we feed to gcc when only
  6. * exporting a simple symbol or two.
  7. *
  8. * Try not to add #includes here. It slows compilation and makes kernel
  9. * hackers place grumpy comments in header files.
  10. */
  11. /* Some toolchains use a `_' prefix for all user symbols. */
  12. #ifdef CONFIG_HAVE_UNDERSCORE_SYMBOL_PREFIX
  13. #define __VMLINUX_SYMBOL(x) _##x
  14. #define __VMLINUX_SYMBOL_STR(x) "_" #x
  15. #else
  16. #define __VMLINUX_SYMBOL(x) x
  17. #define __VMLINUX_SYMBOL_STR(x) #x
  18. #endif
  19. /* Indirect, so macros are expanded before pasting. */
  20. #define VMLINUX_SYMBOL(x) __VMLINUX_SYMBOL(x)
  21. #define VMLINUX_SYMBOL_STR(x) __VMLINUX_SYMBOL_STR(x)
  22. #ifndef __ASSEMBLY__
  23. struct kernel_symbol
  24. {
  25. unsigned long value;
  26. const char *name;
  27. };
  28. #ifdef MODULE
  29. extern struct module __this_module;
  30. #define THIS_MODULE (&__this_module)
  31. #else
  32. #define THIS_MODULE ((struct module *)0)
  33. #endif
  34. #ifdef CONFIG_MODULES
  35. #ifndef __GENKSYMS__
  36. #ifdef CONFIG_MODVERSIONS
  37. /* Mark the CRC weak since genksyms apparently decides not to
  38. * generate a checksums for some symbols */
  39. #define __CRC_SYMBOL(sym, sec) \
  40. extern __visible void *__crc_##sym __attribute__((weak)); \
  41. static const unsigned long __kcrctab_##sym \
  42. __used \
  43. __attribute__((section("___kcrctab" sec "+" #sym), unused)) \
  44. = (unsigned long) &__crc_##sym;
  45. #else
  46. #define __CRC_SYMBOL(sym, sec)
  47. #endif
  48. /* For every exported symbol, place a struct in the __ksymtab section */
  49. #define __EXPORT_SYMBOL(sym, sec) \
  50. extern typeof(sym) sym; \
  51. __CRC_SYMBOL(sym, sec) \
  52. static const char __kstrtab_##sym[] \
  53. __attribute__((section("__ksymtab_strings"), aligned(1))) \
  54. = VMLINUX_SYMBOL_STR(sym); \
  55. extern const struct kernel_symbol __ksymtab_##sym; \
  56. __visible const struct kernel_symbol __ksymtab_##sym \
  57. __used \
  58. __attribute__((section("___ksymtab" sec "+" #sym), unused)) \
  59. = { (unsigned long)&sym, __kstrtab_##sym }
  60. #define EXPORT_SYMBOL(sym) \
  61. __EXPORT_SYMBOL(sym, "")
  62. #define EXPORT_SYMBOL_GPL(sym) \
  63. __EXPORT_SYMBOL(sym, "_gpl")
  64. #define EXPORT_SYMBOL_GPL_FUTURE(sym) \
  65. __EXPORT_SYMBOL(sym, "_gpl_future")
  66. #ifdef CONFIG_UNUSED_SYMBOLS
  67. #define EXPORT_UNUSED_SYMBOL(sym) __EXPORT_SYMBOL(sym, "_unused")
  68. #define EXPORT_UNUSED_SYMBOL_GPL(sym) __EXPORT_SYMBOL(sym, "_unused_gpl")
  69. #else
  70. #define EXPORT_UNUSED_SYMBOL(sym)
  71. #define EXPORT_UNUSED_SYMBOL_GPL(sym)
  72. #endif
  73. #endif /* __GENKSYMS__ */
  74. #else /* !CONFIG_MODULES... */
  75. #define EXPORT_SYMBOL(sym)
  76. #define EXPORT_SYMBOL_GPL(sym)
  77. #define EXPORT_SYMBOL_GPL_FUTURE(sym)
  78. #define EXPORT_UNUSED_SYMBOL(sym)
  79. #define EXPORT_UNUSED_SYMBOL_GPL(sym)
  80. #endif /* CONFIG_MODULES */
  81. #endif /* !__ASSEMBLY__ */
  82. #endif /* _LINUX_EXPORT_H */