1 /* libc/sys/linux/sys/cdefs.h - Helper macros for K&R vs. ANSI C compat. */
3 /* Written 2000 by Werner Almesberger */
6 * SPDX-License-Identifier: BSD-3-Clause
8 * Copyright (c) 1991, 1993
9 * The Regents of the University of California. All rights reserved.
11 * This code is derived from software contributed to Berkeley by
12 * Berkeley Software Design, Inc.
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
17 * 1. Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer.
19 * 2. Redistributions in binary form must reproduce the above copyright
20 * notice, this list of conditions and the following disclaimer in the
21 * documentation and/or other materials provided with the distribution.
22 * 3. Neither the name of the University nor the names of its contributors
23 * may be used to endorse or promote products derived from this software
24 * without specific prior written permission.
26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 * @(#)cdefs.h 8.8 (Berkeley) 1/9/95
45 #include <machine/_default_types.h>
46 #include <sys/features.h>
49 #define __PMT(args) args
54 # define __ASMNAME(cname) __XSTRING (__USER_LABEL_PREFIX__) cname
57 #define __ptr_t void *
58 #define __long_double_t long double
60 #define __attribute_malloc__
61 #define __attribute_pure__
62 #define __attribute_format_strfmon__(a,b)
65 #ifndef __BOUNDED_POINTERS__
66 # define __bounded /* nothing */
67 # define __unbounded /* nothing */
68 # define __ptrvalue /* nothing */
72 * Testing against Clang-specific extensions.
74 #ifndef __has_attribute
75 #define __has_attribute(x) 0
77 #ifndef __has_extension
78 #define __has_extension __has_feature
81 #define __has_feature(x) 0
84 #define __has_include(x) 0
87 #define __has_builtin(x) 0
90 #if defined(__cplusplus)
91 #define __BEGIN_DECLS extern "C" {
99 * This code has been put in place to help reduce the addition of
100 * compiler specific defines in FreeBSD code. It helps to aid in
101 * having a compiler-agnostic source tree.
104 #if defined(__GNUC__)
107 #define __GNUCLIKE_ASM 3
108 #define __GNUCLIKE_MATH_BUILTIN_CONSTANTS
110 #define __GNUCLIKE_ASM 2
112 #define __GNUCLIKE___TYPEOF 1
113 #define __GNUCLIKE___SECTION 1
115 #define __GNUCLIKE_CTOR_SECTION_HANDLING 1
117 #define __GNUCLIKE_BUILTIN_CONSTANT_P 1
119 #if (__GNUC_MINOR__ > 95 || __GNUC__ >= 3)
120 #define __GNUCLIKE_BUILTIN_VARARGS 1
121 #define __GNUCLIKE_BUILTIN_STDARG 1
122 #define __GNUCLIKE_BUILTIN_VAALIST 1
125 #define __GNUC_VA_LIST_COMPATIBILITY 1
128 * Compiler memory barriers, specific to gcc and clang.
130 #define __compiler_membar() __asm __volatile(" " : : : "memory")
132 #define __GNUCLIKE_BUILTIN_NEXT_ARG 1
133 #define __GNUCLIKE_MATH_BUILTIN_RELOPS
135 #define __GNUCLIKE_BUILTIN_MEMCPY 1
137 /* XXX: if __GNUC__ >= 2: not tested everywhere originally, where replaced */
138 #define __CC_SUPPORTS_INLINE 1
139 #define __CC_SUPPORTS___INLINE 1
140 #define __CC_SUPPORTS___INLINE__ 1
142 #define __CC_SUPPORTS___FUNC__ 1
143 #define __CC_SUPPORTS_WARNING 1
145 #define __CC_SUPPORTS_VARADIC_XXX 1 /* see varargs.h */
147 #define __CC_SUPPORTS_DYNAMIC_ARRAY_INIT 1
149 #endif /* __GNUC__ */
152 * The __CONCAT macro is used to concatenate parts of symbol names, e.g.
153 * with "#define OLD(foo) __CONCAT(old,foo)", OLD(foo) produces oldfoo.
154 * The __CONCAT macro is a bit tricky to use if it must work in non-ANSI
155 * mode -- there must be no spaces between its arguments, and for nested
156 * __CONCAT's, all the __CONCAT's must be at the left. __CONCAT can also
157 * concatenate double-quoted strings produced by the __STRING macro, but
158 * this only works with ANSI C.
160 * __XSTRING is like __STRING, but it expands any macros in its argument
161 * first. It is only available with ANSI C.
163 #if defined(__STDC__) || defined(__cplusplus)
164 #define __P(protos) protos /* full-blown ANSI C */
165 #define __CONCAT1(x,y) x ## y
166 #define __CONCAT(x,y) __CONCAT1(x,y)
167 #define __STRING(x) #x /* stringify without expanding x */
168 #define __XSTRING(x) __STRING(x) /* expand x, then stringify */
170 #define __const const /* define reserved names to standard */
171 #define __signed signed
172 #define __volatile volatile
173 #if defined(__cplusplus)
174 #define __inline inline /* convert to C++ keyword */
176 #if !(defined(__CC_SUPPORTS___INLINE))
177 #define __inline /* delete GCC keyword */
178 #endif /* ! __CC_SUPPORTS___INLINE */
179 #endif /* !__cplusplus */
181 #else /* !(__STDC__ || __cplusplus) */
182 #define __P(protos) () /* traditional C preprocessor */
183 #define __CONCAT(x,y) x/**/y
184 #define __STRING(x) "x"
186 #if !defined(__CC_SUPPORTS___INLINE)
187 #define __const /* delete pseudo-ANSI C keywords */
192 * In non-ANSI C environments, new programs will want ANSI-only C keywords
193 * deleted from the program and old programs will want them left alone.
194 * When using a compiler other than gcc, programs using the ANSI C keywords
195 * const, inline etc. as normal identifiers should define -DNO_ANSI_KEYWORDS.
196 * When using "gcc -traditional", we assume that this is the intent; if
197 * __GNUC__ is defined but __STDC__ is not, we leave the new keywords alone.
199 #ifndef NO_ANSI_KEYWORDS
200 #define const /* delete ANSI C keywords */
204 #endif /* !NO_ANSI_KEYWORDS */
205 #endif /* !__CC_SUPPORTS___INLINE */
206 #endif /* !(__STDC__ || __cplusplus) */
209 * Compiler-dependent macros to help declare dead (non-returning) and
210 * pure (no side effects) functions, and unused variables. They are
211 * null except for versions of gcc that are known to support the features
212 * properly (old versions of gcc-2 supported the dead and pure features
213 * in a different (wrong) way). If we do not provide an implementation
214 * for a given compiler, let the compile fail if it is told to use
215 * a feature that we cannot live without.
217 #define __weak_symbol __attribute__((__weak__))
218 #if !__GNUC_PREREQ__(2, 5)
223 #if __GNUC__ == 2 && __GNUC_MINOR__ >= 5 && __GNUC_MINOR__ < 7
224 #define __dead2 __attribute__((__noreturn__))
225 #define __pure2 __attribute__((__const__))
227 /* XXX Find out what to do for __packed, __aligned and __section */
229 #if __GNUC_PREREQ__(2, 7)
230 #define __dead2 __attribute__((__noreturn__))
231 #define __pure2 __attribute__((__const__))
232 #define __unused __attribute__((__unused__))
233 #define __used __attribute__((__used__))
234 #define __packed __attribute__((__packed__))
235 #define __aligned(x) __attribute__((__aligned__(x)))
236 #define __section(x) __attribute__((__section__(x)))
238 #if __GNUC_PREREQ__(4, 3) || __has_attribute(__alloc_size__)
239 #define __alloc_size(x) __attribute__((__alloc_size__(x)))
240 #define __alloc_size2(n, x) __attribute__((__alloc_size__(n, x)))
242 #define __alloc_size(x)
243 #define __alloc_size2(n, x)
245 #if __GNUC_PREREQ__(4, 9) || __has_attribute(__alloc_align__)
246 #define __alloc_align(x) __attribute__((__alloc_align__(x)))
248 #define __alloc_align(x)
251 #if !__GNUC_PREREQ__(2, 95)
252 #define __alignof(x) __offsetof(struct { char __a; x __b; }, __b)
256 * Keywords added in C11.
259 #if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 201112L
261 #if !__has_extension(c_alignas)
262 #if (defined(__cplusplus) && __cplusplus >= 201103L) || \
263 __has_extension(cxx_alignas)
264 #define _Alignas(x) alignas(x)
266 /* XXX: Only emulates _Alignas(constant-expression); not _Alignas(type-name). */
267 #define _Alignas(x) __aligned(x)
271 #if defined(__cplusplus) && __cplusplus >= 201103L
272 #define _Alignof(x) alignof(x)
274 #define _Alignof(x) __alignof(x)
277 #if !defined(__cplusplus) && !__has_extension(c_atomic) && \
278 !__has_extension(cxx_atomic) && !__GNUC_PREREQ__(4, 7)
280 * No native support for _Atomic(). Place object in structure to prevent
281 * most forms of direct non-atomic access.
283 #define _Atomic(T) struct { T volatile __val; }
286 #if defined(__cplusplus) && __cplusplus >= 201103L
287 #define _Noreturn [[noreturn]]
289 #define _Noreturn __dead2
292 #if !__has_extension(c_static_assert)
293 #if (defined(__cplusplus) && __cplusplus >= 201103L) || \
294 __has_extension(cxx_static_assert)
295 #define _Static_assert(x, y) static_assert(x, y)
296 #elif __GNUC_PREREQ__(4,6) && !defined(__cplusplus)
297 /* Nothing, gcc 4.6 and higher has _Static_assert built-in */
298 #elif defined(__COUNTER__)
299 #define _Static_assert(x, y) __Static_assert(x, __COUNTER__)
300 #define __Static_assert(x, y) ___Static_assert(x, y)
301 #define ___Static_assert(x, y) typedef char __assert_ ## y[(x) ? 1 : -1] \
304 #define _Static_assert(x, y) struct __hack
308 #if !__has_extension(c_thread_local)
310 * XXX: Some compilers (Clang 3.3, GCC 4.7) falsely announce C++11 mode
311 * without actually supporting the thread_local keyword. Don't check for
312 * the presence of C++11 when defining _Thread_local.
314 #if /* (defined(__cplusplus) && __cplusplus >= 201103L) || */ \
315 __has_extension(cxx_thread_local)
316 #define _Thread_local thread_local
318 #define _Thread_local __thread
322 #endif /* __STDC_VERSION__ || __STDC_VERSION__ < 201112L */
325 * Emulation of C11 _Generic(). Unlike the previously defined C11
326 * keywords, it is not possible to implement this using exactly the same
327 * syntax. Therefore implement something similar under the name
328 * __generic(). Unlike _Generic(), this macro can only distinguish
329 * between a single type, so it requires nested invocations to
330 * distinguish multiple cases.
332 * Note that the comma operator is used to force expr to decay in
333 * order to match _Generic().
336 #if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) || \
337 __has_extension(c_generic_selections)
338 #define __generic(expr, t, yes, no) \
339 _Generic(expr, t: yes, default: no)
340 #elif __GNUC_PREREQ__(3, 1) && !defined(__cplusplus)
341 #define __generic(expr, t, yes, no) \
342 __builtin_choose_expr( \
343 __builtin_types_compatible_p(__typeof((0, (expr))), t), yes, no)
347 * C99 Static array indices in function parameter declarations. Syntax such as:
348 * void bar(int myArray[static 10]);
349 * is allowed in C99 but not in C++. Define __min_size appropriately so
350 * headers using it can be compiled in either language. Use like this:
351 * void bar(int myArray[__min_size(10)]);
353 #if !defined(__cplusplus) && \
354 (defined(__clang__) || __GNUC_PREREQ__(4, 6)) && \
355 (!defined(__STDC_VERSION__) || (__STDC_VERSION__ >= 199901))
356 #define __min_size(x) static (x)
358 #define __min_size(x) (x)
361 #if __GNUC_PREREQ__(2, 96)
362 #define __malloc_like __attribute__((__malloc__))
363 #define __pure __attribute__((__pure__))
365 #define __malloc_like
369 #if __GNUC_PREREQ__(3, 1)
370 #define __always_inline __inline__ __attribute__((__always_inline__))
372 #define __always_inline
375 #if __GNUC_PREREQ__(3, 1)
376 #define __noinline __attribute__ ((__noinline__))
381 #if __GNUC_PREREQ__(3, 3)
382 #define __nonnull(x) __attribute__((__nonnull__ x))
383 #define __nonnull_all __attribute__((__nonnull__))
386 #define __nonnull_all
389 #if __GNUC_PREREQ__(3, 4)
390 #define __fastcall __attribute__((__fastcall__))
391 #define __result_use_check __attribute__((__warn_unused_result__))
394 #define __result_use_check
397 #if __GNUC_PREREQ__(4, 1)
398 #define __returns_twice __attribute__((__returns_twice__))
400 #define __returns_twice
403 #if __GNUC_PREREQ__(4, 6) || __has_builtin(__builtin_unreachable)
404 #define __unreachable() __builtin_unreachable()
406 #define __unreachable() ((void)0)
409 /* XXX: should use `#if __STDC_VERSION__ < 199901'. */
410 #if !__GNUC_PREREQ__(2, 7)
411 #define __func__ NULL
415 * We use `__restrict' as a way to define the `restrict' type qualifier
416 * without disturbing older software that is unaware of C99 keywords.
417 * GCC also provides `__restrict' as an extension to support C99-style
418 * restricted pointers in other language modes.
420 #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901
421 #define __restrict restrict
422 #elif !__GNUC_PREREQ__(2, 95)
427 * Additionally, we allow to use `__restrict_arr' for declaring arrays as
428 * non-overlapping per C99. That's supported since gcc 3.1, but it's not
431 #if defined(__cplusplus) || !__GNUC_PREREQ__(3, 1)
432 #define __restrict_arr
433 #elif defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L
434 #define __restrict_arr restrict
436 #define __restrict_arr
440 * GNU C version 2.96 adds explicit branch prediction so that
441 * the CPU back-end can hint the processor and also so that
442 * code blocks can be reordered such that the predicted path
443 * sees a more linear flow, thus improving cache behavior, etc.
445 * The following two macros provide us with a way to utilize this
446 * compiler feature. Use __predict_true() if you expect the expression
447 * to evaluate to true, and __predict_false() if you expect the
448 * expression to evaluate to false.
450 * A few notes about usage:
452 * * Generally, __predict_false() error condition checks (unless
453 * you have some _strong_ reason to do otherwise, in which case
454 * document it), and/or __predict_true() `no-error' condition
455 * checks, assuming you want to optimize for the no-error case.
457 * * Other than that, if you don't know the likelihood of a test
458 * succeeding from empirical or other `hard' evidence, don't
461 * * These are meant to be used in places that are run `a lot'.
462 * It is wasteful to make predictions in code that is run
463 * seldomly (e.g. at subsystem initialization time) as the
464 * basic block reordering that this affects can often generate
467 #if __GNUC_PREREQ__(2, 96)
468 #define __predict_true(exp) __builtin_expect((exp), 1)
469 #define __predict_false(exp) __builtin_expect((exp), 0)
471 #define __predict_true(exp) (exp)
472 #define __predict_false(exp) (exp)
475 #if __GNUC_PREREQ__(4, 0)
476 #define __null_sentinel __attribute__((__sentinel__))
477 #define __exported __attribute__((__visibility__("default")))
478 /* Only default visibility is supported on PE/COFF targets. */
480 #define __hidden __attribute__((__visibility__("hidden")))
485 #define __null_sentinel
490 #define __offsetof(type, field) offsetof(type, field)
491 #define __rangeof(type, start, end) \
492 (__offsetof(type, end) - __offsetof(type, start))
495 * Given the pointer x to the member m of the struct s, return
496 * a pointer to the containing structure. When using GCC, we first
497 * assign pointer x to a local variable, to check that its type is
498 * compatible with member m.
500 #if __GNUC_PREREQ__(3, 1)
501 #define __containerof(x, s, m) ({ \
502 const volatile __typeof(((s *)0)->m) *__x = (x); \
503 __DEQUALIFY(s *, (const volatile char *)__x - __offsetof(s, m));\
506 #define __containerof(x, s, m) \
507 __DEQUALIFY(s *, (const volatile char *)(x) - __offsetof(s, m))
511 * Compiler-dependent macros to declare that functions take printf-like
512 * or scanf-like arguments. They are null except for versions of gcc
513 * that are known to support the features properly (old versions of gcc-2
514 * didn't permit keeping the keywords out of the application namespace).
516 #if !__GNUC_PREREQ__(2, 7)
517 #define __printflike(fmtarg, firstvararg)
518 #define __scanflike(fmtarg, firstvararg)
519 #define __format_arg(fmtarg)
520 #define __strfmonlike(fmtarg, firstvararg)
521 #define __strftimelike(fmtarg, firstvararg)
523 #define __printflike(fmtarg, firstvararg) \
524 __attribute__((__format__ (__printf__, fmtarg, firstvararg)))
525 #define __scanflike(fmtarg, firstvararg) \
526 __attribute__((__format__ (__scanf__, fmtarg, firstvararg)))
527 #define __format_arg(fmtarg) __attribute__((__format_arg__ (fmtarg)))
528 #define __strfmonlike(fmtarg, firstvararg) \
529 __attribute__((__format__ (__strfmon__, fmtarg, firstvararg)))
530 #define __strftimelike(fmtarg, firstvararg) \
531 __attribute__((__format__ (__strftime__, fmtarg, firstvararg)))
534 /* Compiler-dependent macros that rely on FreeBSD-specific extensions. */
535 #if defined(__FreeBSD_cc_version) && __FreeBSD_cc_version >= 300001 && \
537 #define __printf0like(fmtarg, firstvararg) \
538 __attribute__((__format__ (__printf0__, fmtarg, firstvararg)))
540 #define __printf0like(fmtarg, firstvararg)
543 #if defined(__GNUC__)
544 #define __strong_reference(sym,aliassym) \
545 extern __typeof (sym) aliassym __attribute__ ((__alias__ (#sym)))
548 #define __weak_reference(sym,alias) \
549 __asm__(".weak " #alias); \
550 __asm__(".equ " #alias ", " #sym)
551 #define __warn_references(sym,msg) \
552 __asm__(".section .gnu.warning." #sym); \
553 __asm__(".asciz \"" msg "\""); \
555 #define __sym_compat(sym,impl,verid) \
556 __asm__(".symver " #impl ", " #sym "@" #verid)
557 #define __sym_default(sym,impl,verid) \
558 __asm__(".symver " #impl ", " #sym "@@" #verid)
560 #define __weak_reference(sym,alias) \
561 __asm__(".weak alias"); \
562 __asm__(".equ alias, sym")
563 #define __warn_references(sym,msg) \
564 __asm__(".section .gnu.warning.sym"); \
565 __asm__(".asciz \"msg\""); \
567 #define __sym_compat(sym,impl,verid) \
568 __asm__(".symver impl, sym@verid")
569 #define __sym_default(impl,sym,verid) \
570 __asm__(".symver impl, sym@@verid")
571 #endif /* __STDC__ */
574 #define __weak_reference(sym,alias) \
575 __asm__(".stabs \"_" #alias "\",11,0,0,0"); \
576 __asm__(".stabs \"_" #sym "\",1,0,0,0")
577 #define __warn_references(sym,msg) \
578 __asm__(".stabs \"" msg "\",30,0,0,0"); \
579 __asm__(".stabs \"_" #sym "\",1,0,0,0")
581 #define __weak_reference(sym,alias) \
582 __asm__(".stabs \"_/**/alias\",11,0,0,0"); \
583 __asm__(".stabs \"_/**/sym\",1,0,0,0")
584 #define __warn_references(sym,msg) \
585 __asm__(".stabs msg,30,0,0,0"); \
586 __asm__(".stabs \"_/**/sym\",1,0,0,0")
587 #endif /* __STDC__ */
589 #endif /* __GNUC__ */
592 #define __FBSDID(s) struct __hack
596 #define __RCSID(s) struct __hack
599 #ifndef __RCSID_SOURCE
600 #define __RCSID_SOURCE(s) struct __hack
604 #define __SCCSID(s) struct __hack
608 #define __COPYRIGHT(s) struct __hack
612 #define __DECONST(type, var) ((type)(__uintptr_t)(const void *)(var))
616 #define __DEVOLATILE(type, var) ((type)(__uintptr_t)(volatile void *)(var))
620 #define __DEQUALIFY(type, var) ((type)(__uintptr_t)(const volatile void *)(var))
624 * Nullability qualifiers: currently only supported by Clang.
626 #if !(defined(__clang__) && __has_feature(nullability))
629 #define _Null_unspecified
630 #define __NULLABILITY_PRAGMA_PUSH
631 #define __NULLABILITY_PRAGMA_POP
633 #define __NULLABILITY_PRAGMA_PUSH _Pragma("clang diagnostic push") \
634 _Pragma("clang diagnostic ignored \"-Wnullability-completeness\"")
635 #define __NULLABILITY_PRAGMA_POP _Pragma("clang diagnostic pop")
639 * Type Safety Checking
641 * Clang provides additional attributes to enable checking type safety
642 * properties that cannot be enforced by the C type system.
645 #if __has_attribute(__argument_with_type_tag__) && \
646 __has_attribute(__type_tag_for_datatype__)
647 #define __arg_type_tag(arg_kind, arg_idx, type_tag_idx) \
648 __attribute__((__argument_with_type_tag__(arg_kind, arg_idx, type_tag_idx)))
649 #define __datatype_type_tag(kind, type) \
650 __attribute__((__type_tag_for_datatype__(kind, type)))
652 #define __arg_type_tag(arg_kind, arg_idx, type_tag_idx)
653 #define __datatype_type_tag(kind, type)
659 * Clang provides support for doing basic thread-safety tests at
660 * compile-time, by marking which locks will/should be held when
661 * entering/leaving a functions.
663 * Furthermore, it is also possible to annotate variables and structure
664 * members to enforce that they are only accessed when certain locks are
668 #if __has_extension(c_thread_safety_attributes)
669 #define __lock_annotate(x) __attribute__((x))
671 #define __lock_annotate(x)
674 /* Structure implements a lock. */
675 /* FIXME: Use __lockable__, etc. to avoid colliding with user namespace macros,
676 * once clang is fixed: https://bugs.llvm.org/show_bug.cgi?id=34319 */
677 #define __lockable __lock_annotate(lockable)
679 /* Function acquires an exclusive or shared lock. */
680 #define __locks_exclusive(...) \
681 __lock_annotate(exclusive_lock_function(__VA_ARGS__))
682 #define __locks_shared(...) \
683 __lock_annotate(shared_lock_function(__VA_ARGS__))
685 /* Function attempts to acquire an exclusive or shared lock. */
686 #define __trylocks_exclusive(...) \
687 __lock_annotate(exclusive_trylock_function(__VA_ARGS__))
688 #define __trylocks_shared(...) \
689 __lock_annotate(shared_trylock_function(__VA_ARGS__))
691 /* Function releases a lock. */
692 #define __unlocks(...) __lock_annotate(unlock_function(__VA_ARGS__))
694 /* Function asserts that an exclusive or shared lock is held. */
695 #define __asserts_exclusive(...) \
696 __lock_annotate(assert_exclusive_lock(__VA_ARGS__))
697 #define __asserts_shared(...) \
698 __lock_annotate(assert_shared_lock(__VA_ARGS__))
700 /* Function requires that an exclusive or shared lock is or is not held. */
701 #define __requires_exclusive(...) \
702 __lock_annotate(exclusive_locks_required(__VA_ARGS__))
703 #define __requires_shared(...) \
704 __lock_annotate(shared_locks_required(__VA_ARGS__))
705 #define __requires_unlocked(...) \
706 __lock_annotate(locks_excluded(__VA_ARGS__))
708 /* Function should not be analyzed. */
709 #define __no_lock_analysis __lock_annotate(no_thread_safety_analysis)
712 * Function or variable should not be sanitized, e.g., by AddressSanitizer.
713 * GCC has the nosanitize attribute, but as a function attribute only, and
714 * warns on use as a variable attribute.
716 #if __has_attribute(no_sanitize) && defined(__clang__)
718 #define __nosanitizeaddress __attribute__((no_sanitize("kernel-address")))
719 #define __nosanitizememory __attribute__((no_sanitize("kernel-memory")))
721 #define __nosanitizeaddress __attribute__((no_sanitize("address")))
722 #define __nosanitizememory __attribute__((no_sanitize("memory")))
724 #define __nosanitizethread __attribute__((no_sanitize("thread")))
726 #define __nosanitizeaddress
727 #define __nosanitizememory
728 #define __nosanitizethread
731 /* Guard variables and structure members by lock. */
732 #define __guarded_by(x) __lock_annotate(guarded_by(x))
733 #define __pt_guarded_by(x) __lock_annotate(pt_guarded_by(x))
735 /* Alignment builtins for better type checking and improved code generation. */
736 /* Provide fallback versions for other compilers (GCC/Clang < 10): */
737 #if !__has_builtin(__builtin_is_aligned)
738 #define __builtin_is_aligned(x, align) \
739 (((__uintptr_t)x & ((align) - 1)) == 0)
741 #if !__has_builtin(__builtin_align_up)
742 #define __builtin_align_up(x, align) \
743 ((__typeof__(x))(((__uintptr_t)(x)+((align)-1))&(~((align)-1))))
745 #if !__has_builtin(__builtin_align_down)
746 #define __builtin_align_down(x, align) \
747 ((__typeof__(x))((x)&(~((align)-1))))
750 #define __align_up(x, y) __builtin_align_up(x, y)
751 #define __align_down(x, y) __builtin_align_down(x, y)
752 #define __is_aligned(x, y) __builtin_is_aligned(x, y)
754 #endif /* !_SYS_CDEFS_H_ */