export.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. * If you feel the need to add #include <linux/foo.h> to this file
  9. * then you are doing something wrong and should go away silently.
  10. */
  11. /* Some toolchains use a `_' prefix for all user symbols. */
  12. #ifdef CONFIG_SYMBOL_PREFIX
  13. #define MODULE_SYMBOL_PREFIX CONFIG_SYMBOL_PREFIX
  14. #else
  15. #define MODULE_SYMBOL_PREFIX ""
  16. #endif
  17. struct kernel_symbol
  18. {
  19. unsigned long value;
  20. const char *name;
  21. };
  22. #ifdef MODULE
  23. extern struct module __this_module;
  24. #define THIS_MODULE (&__this_module)
  25. #else
  26. #define THIS_MODULE ((struct module *)0)
  27. #endif
  28. #ifdef CONFIG_MODULES
  29. #ifndef __GENKSYMS__
  30. #ifdef CONFIG_MODVERSIONS
  31. /* Mark the CRC weak since genksyms apparently decides not to
  32. * generate a checksums for some symbols */
  33. #define __CRC_SYMBOL(sym, sec) \
  34. extern void *__crc_##sym __attribute__((weak)); \
  35. static const unsigned long __kcrctab_##sym \
  36. __used \
  37. __attribute__((section("___kcrctab" sec "+" #sym), unused)) \
  38. = (unsigned long) &__crc_##sym;
  39. #else
  40. #define __CRC_SYMBOL(sym, sec)
  41. #endif
  42. /* For every exported symbol, place a struct in the __ksymtab section */
  43. #define __EXPORT_SYMBOL(sym, sec) \
  44. extern typeof(sym) sym; \
  45. __CRC_SYMBOL(sym, sec) \
  46. static const char __kstrtab_##sym[] \
  47. __attribute__((section("__ksymtab_strings"), aligned(1))) \
  48. = MODULE_SYMBOL_PREFIX #sym; \
  49. static const struct kernel_symbol __ksymtab_##sym \
  50. __used \
  51. __attribute__((section("___ksymtab" sec "+" #sym), unused)) \
  52. = { (unsigned long)&sym, __kstrtab_##sym }
  53. #define EXPORT_SYMBOL(sym) \
  54. __EXPORT_SYMBOL(sym, "")
  55. #define EXPORT_SYMBOL_GPL(sym) \
  56. __EXPORT_SYMBOL(sym, "_gpl")
  57. #define EXPORT_SYMBOL_GPL_FUTURE(sym) \
  58. __EXPORT_SYMBOL(sym, "_gpl_future")
  59. #ifdef CONFIG_UNUSED_SYMBOLS
  60. #define EXPORT_UNUSED_SYMBOL(sym) __EXPORT_SYMBOL(sym, "_unused")
  61. #define EXPORT_UNUSED_SYMBOL_GPL(sym) __EXPORT_SYMBOL(sym, "_unused_gpl")
  62. #else
  63. #define EXPORT_UNUSED_SYMBOL(sym)
  64. #define EXPORT_UNUSED_SYMBOL_GPL(sym)
  65. #endif
  66. #endif /* __GENKSYMS__ */
  67. #else /* !CONFIG_MODULES... */
  68. #define EXPORT_SYMBOL(sym)
  69. #define EXPORT_SYMBOL_GPL(sym)
  70. #define EXPORT_SYMBOL_GPL_FUTURE(sym)
  71. #define EXPORT_UNUSED_SYMBOL(sym)
  72. #define EXPORT_UNUSED_SYMBOL_GPL(sym)
  73. #endif /* CONFIG_MODULES */
  74. #endif /* _LINUX_EXPORT_H */