compiler.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. #ifndef __LINUX_COMPILER_H
  2. #define __LINUX_COMPILER_H
  3. #ifndef __ASSEMBLY__
  4. #ifdef __CHECKER__
  5. # define __user __attribute__((noderef, address_space(1)))
  6. # define __kernel /* default address space */
  7. # define __safe __attribute__((safe))
  8. # define __force __attribute__((force))
  9. # define __nocast __attribute__((nocast))
  10. # define __iomem __attribute__((noderef, address_space(2)))
  11. # define __acquires(x) __attribute__((context(x,0,1)))
  12. # define __releases(x) __attribute__((context(x,1,0)))
  13. # define __acquire(x) __context__(x,1)
  14. # define __release(x) __context__(x,-1)
  15. # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
  16. extern void __chk_user_ptr(const void __user *);
  17. extern void __chk_io_ptr(const void __iomem *);
  18. #else
  19. # define __user
  20. # define __kernel
  21. # define __safe
  22. # define __force
  23. # define __nocast
  24. # define __iomem
  25. # define __chk_user_ptr(x) (void)0
  26. # define __chk_io_ptr(x) (void)0
  27. # define __builtin_warning(x, y...) (1)
  28. # define __acquires(x)
  29. # define __releases(x)
  30. # define __acquire(x) (void)0
  31. # define __release(x) (void)0
  32. # define __cond_lock(x,c) (c)
  33. #endif
  34. #ifdef __KERNEL__
  35. #if __GNUC__ > 4
  36. #error no compiler-gcc.h file for this gcc version
  37. #elif __GNUC__ == 4
  38. # include <linux/compiler-gcc4.h>
  39. #elif __GNUC__ == 3 && __GNUC_MINOR__ >= 2
  40. # include <linux/compiler-gcc3.h>
  41. #else
  42. # error Sorry, your compiler is too old/not recognized.
  43. #endif
  44. /* Intel compiler defines __GNUC__. So we will overwrite implementations
  45. * coming from above header files here
  46. */
  47. #ifdef __INTEL_COMPILER
  48. # include <linux/compiler-intel.h>
  49. #endif
  50. /*
  51. * Generic compiler-dependent macros required for kernel
  52. * build go below this comment. Actual compiler/compiler version
  53. * specific implementations come from the above header files
  54. */
  55. #define likely(x) __builtin_expect(!!(x), 1)
  56. #define unlikely(x) __builtin_expect(!!(x), 0)
  57. /* Optimization barrier */
  58. #ifndef barrier
  59. # define barrier() __memory_barrier()
  60. #endif
  61. #ifndef RELOC_HIDE
  62. # define RELOC_HIDE(ptr, off) \
  63. ({ unsigned long __ptr; \
  64. __ptr = (unsigned long) (ptr); \
  65. (typeof(ptr)) (__ptr + (off)); })
  66. #endif
  67. #endif /* __KERNEL__ */
  68. #endif /* __ASSEMBLY__ */
  69. #ifdef __KERNEL__
  70. /*
  71. * Allow us to mark functions as 'deprecated' and have gcc emit a nice
  72. * warning for each use, in hopes of speeding the functions removal.
  73. * Usage is:
  74. * int __deprecated foo(void)
  75. */
  76. #ifndef __deprecated
  77. # define __deprecated /* unimplemented */
  78. #endif
  79. #ifdef MODULE
  80. #define __deprecated_for_modules __deprecated
  81. #else
  82. #define __deprecated_for_modules
  83. #endif
  84. #ifndef __must_check
  85. #define __must_check
  86. #endif
  87. #ifndef CONFIG_ENABLE_MUST_CHECK
  88. #undef __must_check
  89. #define __must_check
  90. #endif
  91. /*
  92. * Allow us to avoid 'defined but not used' warnings on functions and data,
  93. * as well as force them to be emitted to the assembly file.
  94. *
  95. * As of gcc 3.3, static functions that are not marked with attribute((used))
  96. * may be elided from the assembly file. As of gcc 3.3, static data not so
  97. * marked will not be elided, but this may change in a future gcc version.
  98. *
  99. * In prior versions of gcc, such functions and data would be emitted, but
  100. * would be warned about except with attribute((unused)).
  101. */
  102. #ifndef __attribute_used__
  103. # define __attribute_used__ /* unimplemented */
  104. #endif
  105. /*
  106. * From the GCC manual:
  107. *
  108. * Many functions have no effects except the return value and their
  109. * return value depends only on the parameters and/or global
  110. * variables. Such a function can be subject to common subexpression
  111. * elimination and loop optimization just as an arithmetic operator
  112. * would be.
  113. * [...]
  114. */
  115. #ifndef __attribute_pure__
  116. # define __attribute_pure__ /* unimplemented */
  117. #endif
  118. #ifndef noinline
  119. #define noinline
  120. #endif
  121. #ifndef __always_inline
  122. #define __always_inline inline
  123. #endif
  124. #endif /* __KERNEL__ */
  125. /*
  126. * From the GCC manual:
  127. *
  128. * Many functions do not examine any values except their arguments,
  129. * and have no effects except the return value. Basically this is
  130. * just slightly more strict class than the `pure' attribute above,
  131. * since function is not allowed to read global memory.
  132. *
  133. * Note that a function that has pointer arguments and examines the
  134. * data pointed to must _not_ be declared `const'. Likewise, a
  135. * function that calls a non-`const' function usually must not be
  136. * `const'. It does not make sense for a `const' function to return
  137. * `void'.
  138. */
  139. #ifndef __attribute_const__
  140. # define __attribute_const__ /* unimplemented */
  141. #endif
  142. #endif /* __LINUX_COMPILER_H */