0001
0002 #ifndef __LINUX_COMPILER_TYPES_H
0003 #define __LINUX_COMPILER_TYPES_H
0004
0005 #ifndef __ASSEMBLY__
0006
0007 #if defined(CONFIG_DEBUG_INFO_BTF) && defined(CONFIG_PAHOLE_HAS_BTF_TAG) && \
0008 __has_attribute(btf_type_tag)
0009 # define BTF_TYPE_TAG(value) __attribute__((btf_type_tag(#value)))
0010 #else
0011 # define BTF_TYPE_TAG(value)
0012 #endif
0013
0014
0015 #ifdef __CHECKER__
0016
0017 # define __kernel __attribute__((address_space(0)))
0018 # define __user __attribute__((noderef, address_space(__user)))
0019 # define __iomem __attribute__((noderef, address_space(__iomem)))
0020 # define __percpu __attribute__((noderef, address_space(__percpu)))
0021 # define __rcu __attribute__((noderef, address_space(__rcu)))
0022 static inline void __chk_user_ptr(const volatile void __user *ptr) { }
0023 static inline void __chk_io_ptr(const volatile void __iomem *ptr) { }
0024
0025 # define __must_hold(x) __attribute__((context(x,1,1)))
0026 # define __acquires(x) __attribute__((context(x,0,1)))
0027 # define __cond_acquires(x) __attribute__((context(x,0,-1)))
0028 # define __releases(x) __attribute__((context(x,1,0)))
0029 # define __acquire(x) __context__(x,1)
0030 # define __release(x) __context__(x,-1)
0031 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
0032
0033 # define __force __attribute__((force))
0034 # define __nocast __attribute__((nocast))
0035 # define __safe __attribute__((safe))
0036 # define __private __attribute__((noderef))
0037 # define ACCESS_PRIVATE(p, member) (*((typeof((p)->member) __force *) &(p)->member))
0038 #else
0039
0040 # define __kernel
0041 # ifdef STRUCTLEAK_PLUGIN
0042 # define __user __attribute__((user))
0043 # else
0044 # define __user BTF_TYPE_TAG(user)
0045 # endif
0046 # define __iomem
0047 # define __percpu BTF_TYPE_TAG(percpu)
0048 # define __rcu
0049 # define __chk_user_ptr(x) (void)0
0050 # define __chk_io_ptr(x) (void)0
0051
0052 # define __must_hold(x)
0053 # define __acquires(x)
0054 # define __cond_acquires(x)
0055 # define __releases(x)
0056 # define __acquire(x) (void)0
0057 # define __release(x) (void)0
0058 # define __cond_lock(x,c) (c)
0059
0060 # define __force
0061 # define __nocast
0062 # define __safe
0063 # define __private
0064 # define ACCESS_PRIVATE(p, member) ((p)->member)
0065 # define __builtin_warning(x, y...) (1)
0066 #endif
0067
0068
0069 #define ___PASTE(a,b) a##b
0070 #define __PASTE(a,b) ___PASTE(a,b)
0071
0072 #ifdef __KERNEL__
0073
0074
0075 #include <linux/compiler_attributes.h>
0076
0077
0078
0079
0080
0081
0082
0083
0084 #ifndef __has_builtin
0085 #define __has_builtin(x) (0)
0086 #endif
0087
0088
0089 #ifdef __clang__
0090 #include <linux/compiler-clang.h>
0091 #elif defined(__INTEL_COMPILER)
0092 #include <linux/compiler-intel.h>
0093 #elif defined(__GNUC__)
0094
0095 #include <linux/compiler-gcc.h>
0096 #else
0097 #error "Unknown compiler"
0098 #endif
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108 #ifdef CONFIG_HAVE_ARCH_COMPILER_H
0109 #include <asm/compiler.h>
0110 #endif
0111
0112 struct ftrace_branch_data {
0113 const char *func;
0114 const char *file;
0115 unsigned line;
0116 union {
0117 struct {
0118 unsigned long correct;
0119 unsigned long incorrect;
0120 };
0121 struct {
0122 unsigned long miss;
0123 unsigned long hit;
0124 };
0125 unsigned long miss_hit[2];
0126 };
0127 };
0128
0129 struct ftrace_likely_data {
0130 struct ftrace_branch_data data;
0131 unsigned long constant;
0132 };
0133
0134 #if defined(CC_USING_HOTPATCH)
0135 #define notrace __attribute__((hotpatch(0, 0)))
0136 #elif defined(CC_USING_PATCHABLE_FUNCTION_ENTRY)
0137 #define notrace __attribute__((patchable_function_entry(0, 0)))
0138 #else
0139 #define notrace __attribute__((__no_instrument_function__))
0140 #endif
0141
0142
0143
0144
0145
0146
0147
0148 #define __naked __attribute__((__naked__)) notrace
0149
0150
0151
0152
0153
0154
0155
0156
0157 #define inline inline __gnu_inline __inline_maybe_unused notrace
0158
0159
0160
0161
0162
0163
0164
0165
0166
0167
0168
0169 #define __inline__ inline
0170
0171
0172
0173
0174
0175
0176
0177 #ifdef KBUILD_EXTRA_WARN1
0178 #define __inline_maybe_unused
0179 #else
0180 #define __inline_maybe_unused __maybe_unused
0181 #endif
0182
0183
0184
0185
0186
0187 #define noinline_for_stack noinline
0188
0189
0190
0191
0192
0193
0194
0195
0196 #ifdef __SANITIZE_ADDRESS__
0197
0198
0199
0200
0201
0202
0203 # define __no_kasan_or_inline __no_sanitize_address notrace __maybe_unused
0204 # define __no_sanitize_or_inline __no_kasan_or_inline
0205 #else
0206 # define __no_kasan_or_inline __always_inline
0207 #endif
0208
0209 #ifdef __SANITIZE_THREAD__
0210
0211
0212
0213
0214
0215
0216
0217
0218
0219 # define __no_kcsan __no_sanitize_thread __disable_sanitizer_instrumentation
0220 # define __no_sanitize_or_inline __no_kcsan notrace __maybe_unused
0221 #else
0222 # define __no_kcsan
0223 #endif
0224
0225 #ifndef __no_sanitize_or_inline
0226 #define __no_sanitize_or_inline __always_inline
0227 #endif
0228
0229
0230 #define noinstr \
0231 noinline notrace __attribute((__section__(".noinstr.text"))) \
0232 __no_kcsan __no_sanitize_address __no_profile __no_sanitize_coverage
0233
0234 #endif
0235
0236 #endif
0237
0238
0239
0240
0241
0242
0243 #ifndef __latent_entropy
0244 # define __latent_entropy
0245 #endif
0246
0247 #if defined(RANDSTRUCT) && !defined(__CHECKER__)
0248 # define __randomize_layout __designated_init __attribute__((randomize_layout))
0249 # define __no_randomize_layout __attribute__((no_randomize_layout))
0250
0251 # define randomized_struct_fields_start struct {
0252 # define randomized_struct_fields_end } __randomize_layout;
0253 #else
0254 # define __randomize_layout __designated_init
0255 # define __no_randomize_layout
0256 # define randomized_struct_fields_start
0257 # define randomized_struct_fields_end
0258 #endif
0259
0260 #ifndef __noscs
0261 # define __noscs
0262 #endif
0263
0264 #ifndef __nocfi
0265 # define __nocfi
0266 #endif
0267
0268 #ifndef __cficanonical
0269 # define __cficanonical
0270 #endif
0271
0272
0273
0274
0275
0276
0277
0278 #ifdef __alloc_size__
0279 # define __alloc_size(x, ...) __alloc_size__(x, ## __VA_ARGS__) __malloc
0280 #else
0281 # define __alloc_size(x, ...) __malloc
0282 #endif
0283
0284 #ifndef asm_volatile_goto
0285 #define asm_volatile_goto(x...) asm goto(x)
0286 #endif
0287
0288 #ifdef CONFIG_CC_HAS_ASM_INLINE
0289 #define asm_inline asm __inline
0290 #else
0291 #define asm_inline asm
0292 #endif
0293
0294
0295 #define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b))
0296
0297
0298
0299
0300
0301
0302
0303
0304
0305 #define __scalar_type_to_expr_cases(type) \
0306 unsigned type: (unsigned type)0, \
0307 signed type: (signed type)0
0308
0309 #define __unqual_scalar_typeof(x) typeof( \
0310 _Generic((x), \
0311 char: (char)0, \
0312 __scalar_type_to_expr_cases(char), \
0313 __scalar_type_to_expr_cases(short), \
0314 __scalar_type_to_expr_cases(int), \
0315 __scalar_type_to_expr_cases(long), \
0316 __scalar_type_to_expr_cases(long long), \
0317 default: (x)))
0318
0319
0320 #define __native_word(t) \
0321 (sizeof(t) == sizeof(char) || sizeof(t) == sizeof(short) || \
0322 sizeof(t) == sizeof(int) || sizeof(t) == sizeof(long))
0323
0324 #ifdef __OPTIMIZE__
0325 # define __compiletime_assert(condition, msg, prefix, suffix) \
0326 do { \
0327
0328
0329
0330
0331 \
0332 __noreturn extern void prefix ## suffix(void) \
0333 __compiletime_error(msg); \
0334 if (!(condition)) \
0335 prefix ## suffix(); \
0336 } while (0)
0337 #else
0338 # define __compiletime_assert(condition, msg, prefix, suffix) do { } while (0)
0339 #endif
0340
0341 #define _compiletime_assert(condition, msg, prefix, suffix) \
0342 __compiletime_assert(condition, msg, prefix, suffix)
0343
0344
0345
0346
0347
0348
0349
0350
0351
0352
0353 #define compiletime_assert(condition, msg) \
0354 _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
0355
0356 #define compiletime_assert_atomic_type(t) \
0357 compiletime_assert(__native_word(t), \
0358 "Need native word sized stores/loads for atomicity.")
0359
0360
0361 #ifndef __diag
0362 #define __diag(string)
0363 #endif
0364
0365 #ifndef __diag_GCC
0366 #define __diag_GCC(version, severity, string)
0367 #endif
0368
0369 #define __diag_push() __diag(push)
0370 #define __diag_pop() __diag(pop)
0371
0372 #define __diag_ignore(compiler, version, option, comment) \
0373 __diag_ ## compiler(version, ignore, option)
0374 #define __diag_warn(compiler, version, option, comment) \
0375 __diag_ ## compiler(version, warn, option)
0376 #define __diag_error(compiler, version, option, comment) \
0377 __diag_ ## compiler(version, error, option)
0378
0379 #ifndef __diag_ignore_all
0380 #define __diag_ignore_all(option, comment)
0381 #endif
0382
0383 #endif