export.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. __visible const struct kernel_symbol __ksymtab_##sym \
  56. __used \
  57. __attribute__((section("___ksymtab" sec "+" #sym), unused)) \
  58. = { (unsigned long)&sym, __kstrtab_##sym }
  59. #define EXPORT_SYMBOL(sym) \
  60. __EXPORT_SYMBOL(sym, "")
  61. #define EXPORT_SYMBOL_GPL(sym) \
  62. __EXPORT_SYMBOL(sym, "_gpl")
  63. #define EXPORT_SYMBOL_GPL_FUTURE(sym) \
  64. __EXPORT_SYMBOL(sym, "_gpl_future")
  65. #ifdef CONFIG_UNUSED_SYMBOLS
  66. #define EXPORT_UNUSED_SYMBOL(sym) __EXPORT_SYMBOL(sym, "_unused")
  67. #define EXPORT_UNUSED_SYMBOL_GPL(sym) __EXPORT_SYMBOL(sym, "_unused_gpl")
  68. #else
  69. #define EXPORT_UNUSED_SYMBOL(sym)
  70. #define EXPORT_UNUSED_SYMBOL_GPL(sym)
  71. #endif
  72. #endif /* __GENKSYMS__ */
  73. #else /* !CONFIG_MODULES... */
  74. #define EXPORT_SYMBOL(sym)
  75. #define EXPORT_SYMBOL_GPL(sym)
  76. #define EXPORT_SYMBOL_GPL_FUTURE(sym)
  77. #define EXPORT_UNUSED_SYMBOL(sym)
  78. #define EXPORT_UNUSED_SYMBOL_GPL(sym)
  79. #endif /* CONFIG_MODULES */
  80. #endif /* !__ASSEMBLY__ */
  81. #endif /* _LINUX_EXPORT_H */