1
2#ifndef __LINUX_COMPILER_TYPES_H
3#define __LINUX_COMPILER_TYPES_H
4
5#ifndef __ASSEMBLY__
6
7#ifdef __CHECKER__
8# define __kernel __attribute__((address_space(0)))
9# define __user __attribute__((noderef, address_space(__user)))
10# define __safe __attribute__((safe))
11# define __force __attribute__((force))
12# define __nocast __attribute__((nocast))
13# define __iomem __attribute__((noderef, address_space(__iomem)))
14# define __must_hold(x) __attribute__((context(x,1,1)))
15# define __acquires(x) __attribute__((context(x,0,1)))
16# define __releases(x) __attribute__((context(x,1,0)))
17# define __acquire(x) __context__(x,1)
18# define __release(x) __context__(x,-1)
19# define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
20# define __percpu __attribute__((noderef, address_space(__percpu)))
21# define __rcu __attribute__((noderef, address_space(__rcu)))
22# define __private __attribute__((noderef))
23extern void __chk_user_ptr(const volatile void __user *);
24extern void __chk_io_ptr(const volatile void __iomem *);
25# define ACCESS_PRIVATE(p, member) (*((typeof((p)->member) __force *) &(p)->member))
26#else
27# ifdef STRUCTLEAK_PLUGIN
28# define __user __attribute__((user))
29# else
30# define __user
31# endif
32# define __kernel
33# define __safe
34# define __force
35# define __nocast
36# define __iomem
37# define __chk_user_ptr(x) (void)0
38# define __chk_io_ptr(x) (void)0
39# define __builtin_warning(x, y...) (1)
40# define __must_hold(x)
41# define __acquires(x)
42# define __releases(x)
43# define __acquire(x) (void)0
44# define __release(x) (void)0
45# define __cond_lock(x,c) (c)
46# define __percpu
47# define __rcu
48# define __private
49# define ACCESS_PRIVATE(p, member) ((p)->member)
50#endif
51
52
53#define ___PASTE(a,b) a##b
54#define __PASTE(a,b) ___PASTE(a,b)
55
56#ifdef __KERNEL__
57
58
59#include <linux/compiler_attributes.h>
60
61
62#ifdef __clang__
63#include <linux/compiler-clang.h>
64#elif defined(__INTEL_COMPILER)
65#include <linux/compiler-intel.h>
66#elif defined(__GNUC__)
67
68#include <linux/compiler-gcc.h>
69#else
70#error "Unknown compiler"
71#endif
72
73
74
75
76
77
78
79
80
81#ifdef CONFIG_HAVE_ARCH_COMPILER_H
82#include <asm/compiler.h>
83#endif
84
85struct ftrace_branch_data {
86 const char *func;
87 const char *file;
88 unsigned line;
89 union {
90 struct {
91 unsigned long correct;
92 unsigned long incorrect;
93 };
94 struct {
95 unsigned long miss;
96 unsigned long hit;
97 };
98 unsigned long miss_hit[2];
99 };
100};
101
102struct ftrace_likely_data {
103 struct ftrace_branch_data data;
104 unsigned long constant;
105};
106
107#ifdef CONFIG_ENABLE_MUST_CHECK
108#define __must_check __attribute__((__warn_unused_result__))
109#else
110#define __must_check
111#endif
112
113#if defined(CC_USING_HOTPATCH)
114#define notrace __attribute__((hotpatch(0, 0)))
115#elif defined(CC_USING_PATCHABLE_FUNCTION_ENTRY)
116#define notrace __attribute__((patchable_function_entry(0, 0)))
117#else
118#define notrace __attribute__((__no_instrument_function__))
119#endif
120
121
122
123
124
125
126
127#define __naked __attribute__((__naked__)) notrace
128
129#define __compiler_offsetof(a, b) __builtin_offsetof(a, b)
130
131
132
133
134
135
136
137
138#define inline inline __gnu_inline __inline_maybe_unused notrace
139
140
141
142
143
144
145
146
147
148
149
150#define __inline__ inline
151
152
153
154
155
156
157
158#ifdef KBUILD_EXTRA_WARN1
159#define __inline_maybe_unused
160#else
161#define __inline_maybe_unused __maybe_unused
162#endif
163
164
165
166
167
168#define noinline_for_stack noinline
169
170
171
172
173
174
175
176
177#ifdef __SANITIZE_ADDRESS__
178
179
180
181
182
183
184# define __no_kasan_or_inline __no_sanitize_address notrace __maybe_unused
185# define __no_sanitize_or_inline __no_kasan_or_inline
186#else
187# define __no_kasan_or_inline __always_inline
188#endif
189
190#define __no_kcsan __no_sanitize_thread
191#ifdef __SANITIZE_THREAD__
192# define __no_sanitize_or_inline __no_kcsan notrace __maybe_unused
193#endif
194
195#ifndef __no_sanitize_or_inline
196#define __no_sanitize_or_inline __always_inline
197#endif
198
199
200#define noinstr \
201 noinline notrace __attribute((__section__(".noinstr.text"))) \
202 __no_kcsan __no_sanitize_address
203
204#endif
205
206#endif
207
208
209
210
211
212
213#ifndef __latent_entropy
214# define __latent_entropy
215#endif
216
217#ifndef __randomize_layout
218# define __randomize_layout __designated_init
219#endif
220
221#ifndef __no_randomize_layout
222# define __no_randomize_layout
223#endif
224
225#ifndef randomized_struct_fields_start
226# define randomized_struct_fields_start
227# define randomized_struct_fields_end
228#endif
229
230#ifndef __noscs
231# define __noscs
232#endif
233
234#ifndef asm_volatile_goto
235#define asm_volatile_goto(x...) asm goto(x)
236#endif
237
238#ifdef CONFIG_CC_HAS_ASM_INLINE
239#define asm_inline asm __inline
240#else
241#define asm_inline asm
242#endif
243
244#ifndef __no_fgcse
245# define __no_fgcse
246#endif
247
248
249#define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b))
250
251
252
253
254
255
256
257
258
259#define __scalar_type_to_expr_cases(type) \
260 unsigned type: (unsigned type)0, \
261 signed type: (signed type)0
262
263#define __unqual_scalar_typeof(x) typeof( \
264 _Generic((x), \
265 char: (char)0, \
266 __scalar_type_to_expr_cases(char), \
267 __scalar_type_to_expr_cases(short), \
268 __scalar_type_to_expr_cases(int), \
269 __scalar_type_to_expr_cases(long), \
270 __scalar_type_to_expr_cases(long long), \
271 default: (x)))
272
273
274#define __native_word(t) \
275 (sizeof(t) == sizeof(char) || sizeof(t) == sizeof(short) || \
276 sizeof(t) == sizeof(int) || sizeof(t) == sizeof(long))
277
278
279#ifndef __diag
280#define __diag(string)
281#endif
282
283#ifndef __diag_GCC
284#define __diag_GCC(version, severity, string)
285#endif
286
287#define __diag_push() __diag(push)
288#define __diag_pop() __diag(pop)
289
290#define __diag_ignore(compiler, version, option, comment) \
291 __diag_ ## compiler(version, ignore, option)
292#define __diag_warn(compiler, version, option, comment) \
293 __diag_ ## compiler(version, warn, option)
294#define __diag_error(compiler, version, option, comment) \
295 __diag_ ## compiler(version, error, option)
296
297#endif
298