export.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. #if defined(__KERNEL__) && !defined(__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), used)) \
  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. static const struct kernel_symbol __ksymtab_##sym \
  56. __used \
  57. __attribute__((section("___ksymtab" sec "+" #sym), used)) \
  58. = { (unsigned long)&sym, __kstrtab_##sym }
  59. #if defined(__KSYM_DEPS__)
  60. /*
  61. * For fine grained build dependencies, we want to tell the build system
  62. * about each possible exported symbol even if they're not actually exported.
  63. * We use a string pattern that is unlikely to be valid code that the build
  64. * system filters out from the preprocessor output (see ksym_dep_filter
  65. * in scripts/Kbuild.include).
  66. */
  67. #define __EXPORT_SYMBOL(sym, sec) === __KSYM_##sym ===
  68. #elif defined(CONFIG_TRIM_UNUSED_KSYMS)
  69. #include <generated/autoksyms.h>
  70. #define __EXPORT_SYMBOL(sym, sec) \
  71. __cond_export_sym(sym, sec, __is_defined(__KSYM_##sym))
  72. #define __cond_export_sym(sym, sec, conf) \
  73. ___cond_export_sym(sym, sec, conf)
  74. #define ___cond_export_sym(sym, sec, enabled) \
  75. __cond_export_sym_##enabled(sym, sec)
  76. #define __cond_export_sym_1(sym, sec) ___EXPORT_SYMBOL(sym, sec)
  77. #define __cond_export_sym_0(sym, sec) /* nothing */
  78. #else
  79. #define __EXPORT_SYMBOL ___EXPORT_SYMBOL
  80. #endif
  81. #define EXPORT_SYMBOL(sym) \
  82. __EXPORT_SYMBOL(sym, "")
  83. #define EXPORT_SYMBOL_GPL(sym) \
  84. __EXPORT_SYMBOL(sym, "_gpl")
  85. #define EXPORT_SYMBOL_GPL_FUTURE(sym) \
  86. __EXPORT_SYMBOL(sym, "_gpl_future")
  87. #ifdef CONFIG_UNUSED_SYMBOLS
  88. #define EXPORT_UNUSED_SYMBOL(sym) __EXPORT_SYMBOL(sym, "_unused")
  89. #define EXPORT_UNUSED_SYMBOL_GPL(sym) __EXPORT_SYMBOL(sym, "_unused_gpl")
  90. #else
  91. #define EXPORT_UNUSED_SYMBOL(sym)
  92. #define EXPORT_UNUSED_SYMBOL_GPL(sym)
  93. #endif
  94. #endif /* __GENKSYMS__ */
  95. #else /* !CONFIG_MODULES... */
  96. #define EXPORT_SYMBOL(sym)
  97. #define EXPORT_SYMBOL_GPL(sym)
  98. #define EXPORT_SYMBOL_GPL_FUTURE(sym)
  99. #define EXPORT_UNUSED_SYMBOL(sym)
  100. #define EXPORT_UNUSED_SYMBOL_GPL(sym)
  101. #endif /* CONFIG_MODULES */
  102. #endif /* !__ASSEMBLY__ */
  103. #endif /* _LINUX_EXPORT_H */