compiler.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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 volatile void __user *);
  17. extern void __chk_io_ptr(const volatile 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. # include <linux/compiler-gcc4.h>
  37. #elif __GNUC__ == 3 && __GNUC_MINOR__ >= 2
  38. # include <linux/compiler-gcc3.h>
  39. #else
  40. # error Sorry, your compiler is too old/not recognized.
  41. #endif
  42. /* Intel compiler defines __GNUC__. So we will overwrite implementations
  43. * coming from above header files here
  44. */
  45. #ifdef __INTEL_COMPILER
  46. # include <linux/compiler-intel.h>
  47. #endif
  48. /*
  49. * Generic compiler-dependent macros required for kernel
  50. * build go below this comment. Actual compiler/compiler version
  51. * specific implementations come from the above header files
  52. */
  53. #define likely(x) __builtin_expect(!!(x), 1)
  54. #define unlikely(x) __builtin_expect(!!(x), 0)
  55. /* Optimization barrier */
  56. #ifndef barrier
  57. # define barrier() __memory_barrier()
  58. #endif
  59. #ifndef RELOC_HIDE
  60. # define RELOC_HIDE(ptr, off) \
  61. ({ unsigned long __ptr; \
  62. __ptr = (unsigned long) (ptr); \
  63. (typeof(ptr)) (__ptr + (off)); })
  64. #endif
  65. #endif /* __KERNEL__ */
  66. #endif /* __ASSEMBLY__ */
  67. #ifdef __KERNEL__
  68. /*
  69. * Allow us to mark functions as 'deprecated' and have gcc emit a nice
  70. * warning for each use, in hopes of speeding the functions removal.
  71. * Usage is:
  72. * int __deprecated foo(void)
  73. */
  74. #ifndef __deprecated
  75. # define __deprecated /* unimplemented */
  76. #endif
  77. #ifdef MODULE
  78. #define __deprecated_for_modules __deprecated
  79. #else
  80. #define __deprecated_for_modules
  81. #endif
  82. #ifndef __must_check
  83. #define __must_check
  84. #endif
  85. #ifndef CONFIG_ENABLE_MUST_CHECK
  86. #undef __must_check
  87. #define __must_check
  88. #endif
  89. #ifndef CONFIG_ENABLE_WARN_DEPRECATED
  90. #undef __deprecated
  91. #undef __deprecated_for_modules
  92. #define __deprecated
  93. #define __deprecated_for_modules
  94. #endif
  95. /*
  96. * Allow us to avoid 'defined but not used' warnings on functions and data,
  97. * as well as force them to be emitted to the assembly file.
  98. *
  99. * As of gcc 3.4, static functions that are not marked with attribute((used))
  100. * may be elided from the assembly file. As of gcc 3.4, static data not so
  101. * marked will not be elided, but this may change in a future gcc version.
  102. *
  103. * NOTE: Because distributions shipped with a backported unit-at-a-time
  104. * compiler in gcc 3.3, we must define __used to be __attribute__((used))
  105. * for gcc >=3.3 instead of 3.4.
  106. *
  107. * In prior versions of gcc, such functions and data would be emitted, but
  108. * would be warned about except with attribute((unused)).
  109. *
  110. * Mark functions that are referenced only in inline assembly as __used so
  111. * the code is emitted even though it appears to be unreferenced.
  112. */
  113. #ifndef __used
  114. # define __used /* unimplemented */
  115. #endif
  116. #ifndef __maybe_unused
  117. # define __maybe_unused /* unimplemented */
  118. #endif
  119. #ifndef noinline
  120. #define noinline
  121. #endif
  122. /*
  123. * Rather then using noinline to prevent stack consumption, use
  124. * noinline_for_stack instead. For documentaiton reasons.
  125. */
  126. #define noinline_for_stack noinline
  127. #ifndef __always_inline
  128. #define __always_inline inline
  129. #endif
  130. #endif /* __KERNEL__ */
  131. /*
  132. * From the GCC manual:
  133. *
  134. * Many functions do not examine any values except their arguments,
  135. * and have no effects except the return value. Basically this is
  136. * just slightly more strict class than the `pure' attribute above,
  137. * since function is not allowed to read global memory.
  138. *
  139. * Note that a function that has pointer arguments and examines the
  140. * data pointed to must _not_ be declared `const'. Likewise, a
  141. * function that calls a non-`const' function usually must not be
  142. * `const'. It does not make sense for a `const' function to return
  143. * `void'.
  144. */
  145. #ifndef __attribute_const__
  146. # define __attribute_const__ /* unimplemented */
  147. #endif
  148. /*
  149. * Tell gcc if a function is cold. The compiler will assume any path
  150. * directly leading to the call is unlikely.
  151. */
  152. #ifndef __cold
  153. #define __cold
  154. #endif
  155. /* Simple shorthand for a section definition */
  156. #ifndef __section
  157. # define __section(S) __attribute__ ((__section__(#S)))
  158. #endif
  159. /*
  160. * Prevent the compiler from merging or refetching accesses. The compiler
  161. * is also forbidden from reordering successive instances of ACCESS_ONCE(),
  162. * but only when the compiler is aware of some particular ordering. One way
  163. * to make the compiler aware of ordering is to put the two invocations of
  164. * ACCESS_ONCE() in different C statements.
  165. *
  166. * This macro does absolutely -nothing- to prevent the CPU from reordering,
  167. * merging, or refetching absolutely anything at any time. Its main intended
  168. * use is to mediate communication between process-level code and irq/NMI
  169. * handlers, all running on the same CPU.
  170. */
  171. #define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
  172. #endif /* __LINUX_COMPILER_H */