GNU Linux-libre 4.19.304-gnu1
[releases.git] / include / linux / compiler_types.h
1 #ifndef __LINUX_COMPILER_TYPES_H
2 #define __LINUX_COMPILER_TYPES_H
3
4 #ifndef __ASSEMBLY__
5
6 #ifdef __CHECKER__
7 # define __user         __attribute__((noderef, address_space(1)))
8 # define __kernel       __attribute__((address_space(0)))
9 # define __safe         __attribute__((safe))
10 # define __force        __attribute__((force))
11 # define __nocast       __attribute__((nocast))
12 # define __iomem        __attribute__((noderef, address_space(2)))
13 # define __must_hold(x) __attribute__((context(x,1,1)))
14 # define __acquires(x)  __attribute__((context(x,0,1)))
15 # define __releases(x)  __attribute__((context(x,1,0)))
16 # define __acquire(x)   __context__(x,1)
17 # define __release(x)   __context__(x,-1)
18 # define __cond_lock(x,c)       ((c) ? ({ __acquire(x); 1; }) : 0)
19 # define __percpu       __attribute__((noderef, address_space(3)))
20 # define __rcu          __attribute__((noderef, address_space(4)))
21 # define __private      __attribute__((noderef))
22 extern void __chk_user_ptr(const volatile void __user *);
23 extern void __chk_io_ptr(const volatile void __iomem *);
24 # define ACCESS_PRIVATE(p, member) (*((typeof((p)->member) __force *) &(p)->member))
25 #else /* __CHECKER__ */
26 # ifdef STRUCTLEAK_PLUGIN
27 #  define __user __attribute__((user))
28 # else
29 #  define __user
30 # endif
31 # define __kernel
32 # define __safe
33 # define __force
34 # define __nocast
35 # define __iomem
36 # define __chk_user_ptr(x) (void)0
37 # define __chk_io_ptr(x) (void)0
38 # define __builtin_warning(x, y...) (1)
39 # define __must_hold(x)
40 # define __acquires(x)
41 # define __releases(x)
42 # define __acquire(x) (void)0
43 # define __release(x) (void)0
44 # define __cond_lock(x,c) (c)
45 # define __percpu
46 # define __rcu
47 # define __private
48 # define ACCESS_PRIVATE(p, member) ((p)->member)
49 #endif /* __CHECKER__ */
50
51 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
52 #define ___PASTE(a,b) a##b
53 #define __PASTE(a,b) ___PASTE(a,b)
54
55 #ifdef __KERNEL__
56
57 /* Compiler specific macros. */
58 #ifdef __clang__
59 #include <linux/compiler-clang.h>
60 #elif defined(__INTEL_COMPILER)
61 #include <linux/compiler-intel.h>
62 #elif defined(__GNUC__)
63 /* The above compilers also define __GNUC__, so order is important here. */
64 #include <linux/compiler-gcc.h>
65 #else
66 #error "Unknown compiler"
67 #endif
68
69 /*
70  * Some architectures need to provide custom definitions of macros provided
71  * by linux/compiler-*.h, and can do so using asm/compiler.h. We include that
72  * conditionally rather than using an asm-generic wrapper in order to avoid
73  * build failures if any C compilation, which will include this file via an
74  * -include argument in c_flags, occurs prior to the asm-generic wrappers being
75  * generated.
76  */
77 #ifdef CONFIG_HAVE_ARCH_COMPILER_H
78 #include <asm/compiler.h>
79 #endif
80
81 /*
82  * Generic compiler-independent macros required for kernel
83  * build go below this comment. Actual compiler/compiler version
84  * specific implementations come from the above header files
85  */
86
87 struct ftrace_branch_data {
88         const char *func;
89         const char *file;
90         unsigned line;
91         union {
92                 struct {
93                         unsigned long correct;
94                         unsigned long incorrect;
95                 };
96                 struct {
97                         unsigned long miss;
98                         unsigned long hit;
99                 };
100                 unsigned long miss_hit[2];
101         };
102 };
103
104 struct ftrace_likely_data {
105         struct ftrace_branch_data       data;
106         unsigned long                   constant;
107 };
108
109 /* Don't. Just don't. */
110 #define __deprecated
111 #define __deprecated_for_modules
112
113 #endif /* __KERNEL__ */
114
115 #endif /* __ASSEMBLY__ */
116
117 /*
118  * The below symbols may be defined for one or more, but not ALL, of the above
119  * compilers. We don't consider that to be an error, so set them to nothing.
120  * For example, some of them are for compiler specific plugins.
121  */
122 #ifndef __designated_init
123 # define __designated_init
124 #endif
125
126 #ifndef __latent_entropy
127 # define __latent_entropy
128 #endif
129
130 #ifndef __randomize_layout
131 # define __randomize_layout __designated_init
132 #endif
133
134 #ifndef __no_randomize_layout
135 # define __no_randomize_layout
136 #endif
137
138 #ifndef randomized_struct_fields_start
139 # define randomized_struct_fields_start
140 # define randomized_struct_fields_end
141 #endif
142
143 #ifndef __visible
144 #define __visible
145 #endif
146
147 /*
148  * Assume alignment of return value.
149  */
150 #ifndef __assume_aligned
151 #define __assume_aligned(a, ...)
152 #endif
153
154 #ifndef asm_volatile_goto
155 #define asm_volatile_goto(x...) asm goto(x)
156 #endif
157
158 /* Are two types/vars the same type (ignoring qualifiers)? */
159 #define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b))
160
161 /* Is this type a native word size -- useful for atomic operations */
162 #define __native_word(t) \
163         (sizeof(t) == sizeof(char) || sizeof(t) == sizeof(short) || \
164          sizeof(t) == sizeof(int) || sizeof(t) == sizeof(long))
165
166 #ifndef __attribute_const__
167 #define __attribute_const__     __attribute__((__const__))
168 #endif
169
170 #ifndef __noclone
171 #define __noclone
172 #endif
173
174 /* Helpers for emitting diagnostics in pragmas. */
175 #ifndef __diag
176 #define __diag(string)
177 #endif
178
179 #ifndef __diag_GCC
180 #define __diag_GCC(version, severity, string)
181 #endif
182
183 #ifndef __copy
184 # define __copy(symbol)
185 #endif
186
187 #define __diag_push()   __diag(push)
188 #define __diag_pop()    __diag(pop)
189
190 #define __diag_ignore(compiler, version, option, comment) \
191         __diag_ ## compiler(version, ignore, option)
192 #define __diag_warn(compiler, version, option, comment) \
193         __diag_ ## compiler(version, warn, option)
194 #define __diag_error(compiler, version, option, comment) \
195         __diag_ ## compiler(version, error, option)
196
197 /*
198  * From the GCC manual:
199  *
200  * Many functions have no effects except the return value and their
201  * return value depends only on the parameters and/or global
202  * variables.  Such a function can be subject to common subexpression
203  * elimination and loop optimization just as an arithmetic operator
204  * would be.
205  * [...]
206  */
207 #define __pure                  __attribute__((pure))
208 #define __aligned(x)            __attribute__((aligned(x)))
209 #define __aligned_largest       __attribute__((aligned))
210 #define __printf(a, b)          __attribute__((format(printf, a, b)))
211 #define __scanf(a, b)           __attribute__((format(scanf, a, b)))
212 #define __maybe_unused          __attribute__((unused))
213 #define __always_unused         __attribute__((unused))
214 #define __mode(x)               __attribute__((mode(x)))
215 #define __malloc                __attribute__((__malloc__))
216 #define __used                  __attribute__((__used__))
217 #define __noreturn              __attribute__((noreturn))
218 #define __packed                __attribute__((packed))
219 #define __weak                  __attribute__((weak))
220 #define __alias(symbol)         __attribute__((alias(#symbol)))
221 #define __cold                  __attribute__((cold))
222 #define __section(S)            __attribute__((__section__(#S)))
223
224
225 #ifdef CONFIG_ENABLE_MUST_CHECK
226 #define __must_check            __attribute__((warn_unused_result))
227 #else
228 #define __must_check
229 #endif
230
231 #if defined(CC_USING_HOTPATCH) && !defined(__CHECKER__)
232 #define notrace                 __attribute__((hotpatch(0, 0)))
233 #else
234 #define notrace                 __attribute__((no_instrument_function))
235 #endif
236
237 #if defined(__KERNEL__) && !defined(__ASSEMBLY__)
238 /* Section for code which can't be instrumented at all */
239 #define noinstr                                                         \
240         noinline notrace __attribute((__section__(".noinstr.text")))
241 #endif
242
243 /*
244  * it doesn't make sense on ARM (currently the only user of __naked)
245  * to trace naked functions because then mcount is called without
246  * stack and frame pointer being set up and there is no chance to
247  * restore the lr register to the value before mcount was called.
248  */
249 #define __naked                 __attribute__((naked)) notrace
250
251 #define __compiler_offsetof(a, b)       __builtin_offsetof(a, b)
252
253 /*
254  * Feature detection for gnu_inline (gnu89 extern inline semantics). Either
255  * __GNUC_STDC_INLINE__ is defined (not using gnu89 extern inline semantics,
256  * and we opt in to the gnu89 semantics), or __GNUC_STDC_INLINE__ is not
257  * defined so the gnu89 semantics are the default.
258  */
259 #ifdef __GNUC_STDC_INLINE__
260 # define __gnu_inline   __attribute__((gnu_inline))
261 #else
262 # define __gnu_inline
263 #endif
264
265 /*
266  * Force always-inline if the user requests it so via the .config.
267  * GCC does not warn about unused static inline functions for
268  * -Wunused-function.  This turns out to avoid the need for complex #ifdef
269  * directives.  Suppress the warning in clang as well by using "unused"
270  * function attribute, which is redundant but not harmful for gcc.
271  * Prefer gnu_inline, so that extern inline functions do not emit an
272  * externally visible function. This makes extern inline behave as per gnu89
273  * semantics rather than c99. This prevents multiple symbol definition errors
274  * of extern inline functions at link time.
275  * A lot of inline functions can cause havoc with function tracing.
276  */
277 #if !defined(CONFIG_ARCH_SUPPORTS_OPTIMIZED_INLINING) || \
278         !defined(CONFIG_OPTIMIZE_INLINING)
279 #define inline \
280         inline __attribute__((always_inline, unused)) notrace __gnu_inline
281 #else
282 #define inline inline   __attribute__((unused)) notrace __gnu_inline
283 #endif
284
285 #define __inline__ inline
286 #define __inline inline
287 #define noinline        __attribute__((noinline))
288
289 #ifndef __always_inline
290 #define __always_inline inline __attribute__((always_inline))
291 #endif
292
293 /*
294  * Rather then using noinline to prevent stack consumption, use
295  * noinline_for_stack instead.  For documentation reasons.
296  */
297 #define noinline_for_stack noinline
298
299 #endif /* __LINUX_COMPILER_TYPES_H */