Wed Apr 22 09:23:21 2020 UTC ()
For NO_KERNEL_RCSIDS, strip __RCSID() also for src/common/*.


(rin)
diff -r1.153 -r1.154 src/sys/sys/cdefs.h

cvs diff -r1.153 -r1.154 src/sys/sys/cdefs.h (switch to unified diff)

--- src/sys/sys/cdefs.h 2020/04/17 14:59:23 1.153
+++ src/sys/sys/cdefs.h 2020/04/22 09:23:21 1.154
@@ -1,717 +1,717 @@ @@ -1,717 +1,717 @@
1/* $NetBSD: cdefs.h,v 1.153 2020/04/17 14:59:23 joerg Exp $ */ 1/* $NetBSD: cdefs.h,v 1.154 2020/04/22 09:23:21 rin Exp $ */
2 2
3/* * Copyright (c) 1991, 1993 3/* * Copyright (c) 1991, 1993
4 * The Regents of the University of California. All rights reserved. 4 * The Regents of the University of California. All rights reserved.
5 * 5 *
6 * This code is derived from software contributed to Berkeley by 6 * This code is derived from software contributed to Berkeley by
7 * Berkeley Software Design, Inc. 7 * Berkeley Software Design, Inc.
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions 10 * modification, are permitted provided that the following conditions
11 * are met: 11 * are met:
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright 14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the 15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution. 16 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of the University nor the names of its contributors 17 * 3. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software 18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission. 19 * without specific prior written permission.
20 * 20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE. 31 * SUCH DAMAGE.
32 * 32 *
33 * @(#)cdefs.h 8.8 (Berkeley) 1/9/95 33 * @(#)cdefs.h 8.8 (Berkeley) 1/9/95
34 */ 34 */
35 35
36#ifndef _SYS_CDEFS_H_ 36#ifndef _SYS_CDEFS_H_
37#define _SYS_CDEFS_H_ 37#define _SYS_CDEFS_H_
38 38
39#ifdef _KERNEL_OPT 39#ifdef _KERNEL_OPT
40#include "opt_diagnostic.h" 40#include "opt_diagnostic.h"
41#endif 41#endif
42 42
43/* 43/*
44 * Macro to test if we're using a GNU C compiler of a specific vintage 44 * Macro to test if we're using a GNU C compiler of a specific vintage
45 * or later, for e.g. features that appeared in a particular version 45 * or later, for e.g. features that appeared in a particular version
46 * of GNU C. Usage: 46 * of GNU C. Usage:
47 * 47 *
48 * #if __GNUC_PREREQ__(major, minor) 48 * #if __GNUC_PREREQ__(major, minor)
49 * ...cool feature... 49 * ...cool feature...
50 * #else 50 * #else
51 * ...delete feature... 51 * ...delete feature...
52 * #endif 52 * #endif
53 */ 53 */
54#ifdef __GNUC__ 54#ifdef __GNUC__
55#define __GNUC_PREREQ__(x, y) \ 55#define __GNUC_PREREQ__(x, y) \
56 ((__GNUC__ == (x) && __GNUC_MINOR__ >= (y)) || \ 56 ((__GNUC__ == (x) && __GNUC_MINOR__ >= (y)) || \
57 (__GNUC__ > (x))) 57 (__GNUC__ > (x)))
58#else 58#else
59#define __GNUC_PREREQ__(x, y) 0 59#define __GNUC_PREREQ__(x, y) 0
60#endif 60#endif
61 61
62/* 62/*
63 * Macros to test Clang/LLVM features. 63 * Macros to test Clang/LLVM features.
64 * Usage: 64 * Usage:
65 * 65 *
66 * #if __has_feature(safe_stack) 66 * #if __has_feature(safe_stack)
67 * ...SafeStack specific code... 67 * ...SafeStack specific code...
68 * #else 68 * #else
69 * ..regular code... 69 * ..regular code...
70 * #endif 70 * #endif
71 */ 71 */
72#ifndef __has_feature 72#ifndef __has_feature
73#define __has_feature(x) 0 73#define __has_feature(x) 0
74#endif 74#endif
75 75
76#ifndef __has_extension 76#ifndef __has_extension
77#define __has_extension __has_feature /* Compat with pre-3.0 Clang */ 77#define __has_extension __has_feature /* Compat with pre-3.0 Clang */
78#endif 78#endif
79 79
80#include <machine/cdefs.h> 80#include <machine/cdefs.h>
81#ifdef __ELF__ 81#ifdef __ELF__
82#include <sys/cdefs_elf.h> 82#include <sys/cdefs_elf.h>
83#else 83#else
84#include <sys/cdefs_aout.h> 84#include <sys/cdefs_aout.h>
85#endif 85#endif
86 86
87#ifdef __GNUC__ 87#ifdef __GNUC__
88#define __strict_weak_alias(alias,sym) \ 88#define __strict_weak_alias(alias,sym) \
89 __unused static __typeof__(alias) *__weak_alias_##alias = &sym; \ 89 __unused static __typeof__(alias) *__weak_alias_##alias = &sym; \
90 __weak_alias(alias,sym) 90 __weak_alias(alias,sym)
91#else 91#else
92#define __strict_weak_alias(alias,sym) __weak_alias(alias,sym) 92#define __strict_weak_alias(alias,sym) __weak_alias(alias,sym)
93#endif 93#endif
94 94
95/* 95/*
96 * Optional marker for size-optimised MD calling convention. 96 * Optional marker for size-optimised MD calling convention.
97 */ 97 */
98#ifndef __compactcall 98#ifndef __compactcall
99#define __compactcall 99#define __compactcall
100#endif 100#endif
101 101
102/* 102/*
103 * The __CONCAT macro is used to concatenate parts of symbol names, e.g. 103 * The __CONCAT macro is used to concatenate parts of symbol names, e.g.
104 * with "#define OLD(foo) __CONCAT(old,foo)", OLD(foo) produces oldfoo. 104 * with "#define OLD(foo) __CONCAT(old,foo)", OLD(foo) produces oldfoo.
105 * The __CONCAT macro is a bit tricky -- make sure you don't put spaces 105 * The __CONCAT macro is a bit tricky -- make sure you don't put spaces
106 * in between its arguments. __CONCAT can also concatenate double-quoted 106 * in between its arguments. __CONCAT can also concatenate double-quoted
107 * strings produced by the __STRING macro, but this only works with ANSI C. 107 * strings produced by the __STRING macro, but this only works with ANSI C.
108 */ 108 */
109 109
110#define ___STRING(x) __STRING(x) 110#define ___STRING(x) __STRING(x)
111#define ___CONCAT(x,y) __CONCAT(x,y) 111#define ___CONCAT(x,y) __CONCAT(x,y)
112 112
113#if __STDC__ || defined(__cplusplus) 113#if __STDC__ || defined(__cplusplus)
114#define __P(protos) protos /* full-blown ANSI C */ 114#define __P(protos) protos /* full-blown ANSI C */
115#define __CONCAT(x,y) x ## y 115#define __CONCAT(x,y) x ## y
116#define __STRING(x) #x 116#define __STRING(x) #x
117 117
118#define __const const /* define reserved names to standard */ 118#define __const const /* define reserved names to standard */
119#define __signed signed 119#define __signed signed
120#define __volatile volatile 120#define __volatile volatile
121#if defined(__cplusplus) || defined(__PCC__) 121#if defined(__cplusplus) || defined(__PCC__)
122#define __inline inline /* convert to C++/C99 keyword */ 122#define __inline inline /* convert to C++/C99 keyword */
123#else 123#else
124#if !defined(__GNUC__) && !defined(__lint__) 124#if !defined(__GNUC__) && !defined(__lint__)
125#define __inline /* delete GCC keyword */ 125#define __inline /* delete GCC keyword */
126#endif /* !__GNUC__ && !__lint__ */ 126#endif /* !__GNUC__ && !__lint__ */
127#endif /* !__cplusplus */ 127#endif /* !__cplusplus */
128 128
129#else /* !(__STDC__ || __cplusplus) */ 129#else /* !(__STDC__ || __cplusplus) */
130#define __P(protos) () /* traditional C preprocessor */ 130#define __P(protos) () /* traditional C preprocessor */
131#define __CONCAT(x,y) x/**/y 131#define __CONCAT(x,y) x/**/y
132#define __STRING(x) "x" 132#define __STRING(x) "x"
133 133
134#ifndef __GNUC__ 134#ifndef __GNUC__
135#define __const /* delete pseudo-ANSI C keywords */ 135#define __const /* delete pseudo-ANSI C keywords */
136#define __inline 136#define __inline
137#define __signed 137#define __signed
138#define __volatile 138#define __volatile
139#endif /* !__GNUC__ */ 139#endif /* !__GNUC__ */
140 140
141/* 141/*
142 * In non-ANSI C environments, new programs will want ANSI-only C keywords 142 * In non-ANSI C environments, new programs will want ANSI-only C keywords
143 * deleted from the program and old programs will want them left alone. 143 * deleted from the program and old programs will want them left alone.
144 * Programs using the ANSI C keywords const, inline etc. as normal 144 * Programs using the ANSI C keywords const, inline etc. as normal
145 * identifiers should define -DNO_ANSI_KEYWORDS. 145 * identifiers should define -DNO_ANSI_KEYWORDS.
146 */ 146 */
147#ifndef NO_ANSI_KEYWORDS 147#ifndef NO_ANSI_KEYWORDS
148#define const __const /* convert ANSI C keywords */ 148#define const __const /* convert ANSI C keywords */
149#define inline __inline 149#define inline __inline
150#define signed __signed 150#define signed __signed
151#define volatile __volatile 151#define volatile __volatile
152#endif /* !NO_ANSI_KEYWORDS */ 152#endif /* !NO_ANSI_KEYWORDS */
153#endif /* !(__STDC__ || __cplusplus) */ 153#endif /* !(__STDC__ || __cplusplus) */
154 154
155/* 155/*
156 * Used for internal auditing of the NetBSD source tree. 156 * Used for internal auditing of the NetBSD source tree.
157 */ 157 */
158#ifdef __AUDIT__ 158#ifdef __AUDIT__
159#define __aconst __const 159#define __aconst __const
160#else 160#else
161#define __aconst 161#define __aconst
162#endif 162#endif
163 163
164/* 164/*
165 * Compile Time Assertion. 165 * Compile Time Assertion.
166 */ 166 */
167#ifdef __COUNTER__ 167#ifdef __COUNTER__
168#define __CTASSERT(x) __CTASSERT0(x, __ctassert, __COUNTER__) 168#define __CTASSERT(x) __CTASSERT0(x, __ctassert, __COUNTER__)
169#else 169#else
170#define __CTASSERT(x) __CTASSERT99(x, __INCLUDE_LEVEL__, __LINE__) 170#define __CTASSERT(x) __CTASSERT99(x, __INCLUDE_LEVEL__, __LINE__)
171#define __CTASSERT99(x, a, b) __CTASSERT0(x, __CONCAT(__ctassert,a), \ 171#define __CTASSERT99(x, a, b) __CTASSERT0(x, __CONCAT(__ctassert,a), \
172 __CONCAT(_,b)) 172 __CONCAT(_,b))
173#endif 173#endif
174#define __CTASSERT0(x, y, z) __CTASSERT1(x, y, z) 174#define __CTASSERT0(x, y, z) __CTASSERT1(x, y, z)
175#define __CTASSERT1(x, y, z) \ 175#define __CTASSERT1(x, y, z) \
176 struct y ## z ## _struct { \ 176 struct y ## z ## _struct { \
177 unsigned int y ## z : /*CONSTCOND*/(x) ? 1 : -1; \ 177 unsigned int y ## z : /*CONSTCOND*/(x) ? 1 : -1; \
178 } 178 }
179 179
180/* 180/*
181 * The following macro is used to remove const cast-away warnings 181 * The following macro is used to remove const cast-away warnings
182 * from gcc -Wcast-qual; it should be used with caution because it 182 * from gcc -Wcast-qual; it should be used with caution because it
183 * can hide valid errors; in particular most valid uses are in 183 * can hide valid errors; in particular most valid uses are in
184 * situations where the API requires it, not to cast away string 184 * situations where the API requires it, not to cast away string
185 * constants. We don't use *intptr_t on purpose here and we are 185 * constants. We don't use *intptr_t on purpose here and we are
186 * explicit about unsigned long so that we don't have additional 186 * explicit about unsigned long so that we don't have additional
187 * dependencies. 187 * dependencies.
188 */ 188 */
189#define __UNCONST(a) ((void *)(unsigned long)(const void *)(a)) 189#define __UNCONST(a) ((void *)(unsigned long)(const void *)(a))
190 190
191/* 191/*
192 * The following macro is used to remove the volatile cast-away warnings 192 * The following macro is used to remove the volatile cast-away warnings
193 * from gcc -Wcast-qual; as above it should be used with caution 193 * from gcc -Wcast-qual; as above it should be used with caution
194 * because it can hide valid errors or warnings. Valid uses include 194 * because it can hide valid errors or warnings. Valid uses include
195 * making it possible to pass a volatile pointer to memset(). 195 * making it possible to pass a volatile pointer to memset().
196 * For the same reasons as above, we use unsigned long and not intptr_t. 196 * For the same reasons as above, we use unsigned long and not intptr_t.
197 */ 197 */
198#define __UNVOLATILE(a) ((void *)(unsigned long)(volatile void *)(a)) 198#define __UNVOLATILE(a) ((void *)(unsigned long)(volatile void *)(a))
199 199
200/* 200/*
201 * The following macro is used to remove the the function type cast warnings 201 * The following macro is used to remove the the function type cast warnings
202 * from gcc -Wcast-function-type and as above should be used with caution. 202 * from gcc -Wcast-function-type and as above should be used with caution.
203 */ 203 */
204#define __FPTRCAST(t, f) ((t)(void *)(f)) 204#define __FPTRCAST(t, f) ((t)(void *)(f))
205 205
206/* 206/*
207 * GCC2 provides __extension__ to suppress warnings for various GNU C 207 * GCC2 provides __extension__ to suppress warnings for various GNU C
208 * language extensions under "-ansi -pedantic". 208 * language extensions under "-ansi -pedantic".
209 */ 209 */
210#if !__GNUC_PREREQ__(2, 0) 210#if !__GNUC_PREREQ__(2, 0)
211#define __extension__ /* delete __extension__ if non-gcc or gcc1 */ 211#define __extension__ /* delete __extension__ if non-gcc or gcc1 */
212#endif 212#endif
213 213
214/* 214/*
215 * GCC1 and some versions of GCC2 declare dead (non-returning) and 215 * GCC1 and some versions of GCC2 declare dead (non-returning) and
216 * pure (no side effects) functions using "volatile" and "const"; 216 * pure (no side effects) functions using "volatile" and "const";
217 * unfortunately, these then cause warnings under "-ansi -pedantic". 217 * unfortunately, these then cause warnings under "-ansi -pedantic".
218 * GCC2 uses a new, peculiar __attribute__((attrs)) style. All of 218 * GCC2 uses a new, peculiar __attribute__((attrs)) style. All of
219 * these work for GNU C++ (modulo a slight glitch in the C++ grammar 219 * these work for GNU C++ (modulo a slight glitch in the C++ grammar
220 * in the distribution version of 2.5.5). 220 * in the distribution version of 2.5.5).
221 * 221 *
222 * GCC defines a pure function as depending only on its arguments and 222 * GCC defines a pure function as depending only on its arguments and
223 * global variables. Typical examples are strlen and sqrt. 223 * global variables. Typical examples are strlen and sqrt.
224 * 224 *
225 * GCC defines a const function as depending only on its arguments. 225 * GCC defines a const function as depending only on its arguments.
226 * Therefore calling a const function again with identical arguments 226 * Therefore calling a const function again with identical arguments
227 * will always produce the same result. 227 * will always produce the same result.
228 * 228 *
229 * Rounding modes for floating point operations are considered global 229 * Rounding modes for floating point operations are considered global
230 * variables and prevent sqrt from being a const function. 230 * variables and prevent sqrt from being a const function.
231 * 231 *
232 * Calls to const functions can be optimised away and moved around 232 * Calls to const functions can be optimised away and moved around
233 * without limitations. 233 * without limitations.
234 */ 234 */
235#if !__GNUC_PREREQ__(2, 0) && !defined(__lint__) 235#if !__GNUC_PREREQ__(2, 0) && !defined(__lint__)
236#define __attribute__(x) 236#define __attribute__(x)
237#endif 237#endif
238 238
239#if __GNUC_PREREQ__(2, 5) || defined(__lint__) 239#if __GNUC_PREREQ__(2, 5) || defined(__lint__)
240#define __dead __attribute__((__noreturn__)) 240#define __dead __attribute__((__noreturn__))
241#elif defined(__GNUC__) 241#elif defined(__GNUC__)
242#define __dead __volatile 242#define __dead __volatile
243#else 243#else
244#define __dead 244#define __dead
245#endif 245#endif
246 246
247#if __GNUC_PREREQ__(2, 96) || defined(__lint__) 247#if __GNUC_PREREQ__(2, 96) || defined(__lint__)
248#define __pure __attribute__((__pure__)) 248#define __pure __attribute__((__pure__))
249#elif defined(__GNUC__) 249#elif defined(__GNUC__)
250#define __pure __const 250#define __pure __const
251#else 251#else
252#define __pure 252#define __pure
253#endif 253#endif
254 254
255#if __GNUC_PREREQ__(2, 5) || defined(__lint__) 255#if __GNUC_PREREQ__(2, 5) || defined(__lint__)
256#define __constfunc __attribute__((__const__)) 256#define __constfunc __attribute__((__const__))
257#else 257#else
258#define __constfunc 258#define __constfunc
259#endif 259#endif
260 260
261#if __GNUC_PREREQ__(3, 0) || defined(__lint__) 261#if __GNUC_PREREQ__(3, 0) || defined(__lint__)
262#define __noinline __attribute__((__noinline__)) 262#define __noinline __attribute__((__noinline__))
263#else 263#else
264#define __noinline /* nothing */ 264#define __noinline /* nothing */
265#endif 265#endif
266 266
267#if __GNUC_PREREQ__(3, 0) || defined(__lint__) 267#if __GNUC_PREREQ__(3, 0) || defined(__lint__)
268#define __always_inline __attribute__((__always_inline__)) 268#define __always_inline __attribute__((__always_inline__))
269#else 269#else
270#define __always_inline /* nothing */ 270#define __always_inline /* nothing */
271#endif 271#endif
272 272
273#if __GNUC_PREREQ__(4, 1) || defined(__lint__) 273#if __GNUC_PREREQ__(4, 1) || defined(__lint__)
274#define __returns_twice __attribute__((__returns_twice__)) 274#define __returns_twice __attribute__((__returns_twice__))
275#else 275#else
276#define __returns_twice /* nothing */ 276#define __returns_twice /* nothing */
277#endif 277#endif
278 278
279#if __GNUC_PREREQ__(4, 5) || defined(__lint__) 279#if __GNUC_PREREQ__(4, 5) || defined(__lint__)
280#define __noclone __attribute__((__noclone__)) 280#define __noclone __attribute__((__noclone__))
281#else 281#else
282#define __noclone /* nothing */ 282#define __noclone /* nothing */
283#endif 283#endif
284 284
285/* 285/*
286 * __unused: Note that item or function might be unused. 286 * __unused: Note that item or function might be unused.
287 */ 287 */
288#if __GNUC_PREREQ__(2, 7) || defined(__lint__) 288#if __GNUC_PREREQ__(2, 7) || defined(__lint__)
289#define __unused __attribute__((__unused__)) 289#define __unused __attribute__((__unused__))
290#else 290#else
291#define __unused /* delete */ 291#define __unused /* delete */
292#endif 292#endif
293 293
294/* 294/*
295 * __used: Note that item is needed, even if it appears to be unused. 295 * __used: Note that item is needed, even if it appears to be unused.
296 */ 296 */
297#if __GNUC_PREREQ__(3, 1) || defined(__lint__) 297#if __GNUC_PREREQ__(3, 1) || defined(__lint__)
298#define __used __attribute__((__used__)) 298#define __used __attribute__((__used__))
299#else 299#else
300#define __used __unused 300#define __used __unused
301#endif 301#endif
302 302
303/* 303/*
304 * __diagused: Note that item is used in diagnostic code, but may be 304 * __diagused: Note that item is used in diagnostic code, but may be
305 * unused in non-diagnostic code. 305 * unused in non-diagnostic code.
306 */ 306 */
307#if (defined(_KERNEL) && defined(DIAGNOSTIC)) \ 307#if (defined(_KERNEL) && defined(DIAGNOSTIC)) \
308 || (!defined(_KERNEL) && !defined(NDEBUG)) 308 || (!defined(_KERNEL) && !defined(NDEBUG))
309#define __diagused /* empty */ 309#define __diagused /* empty */
310#else 310#else
311#define __diagused __unused 311#define __diagused __unused
312#endif 312#endif
313 313
314/* 314/*
315 * __debugused: Note that item is used in debug code, but may be 315 * __debugused: Note that item is used in debug code, but may be
316 * unused in non-debug code. 316 * unused in non-debug code.
317 */ 317 */
318#if defined(DEBUG) 318#if defined(DEBUG)
319#define __debugused /* empty */ 319#define __debugused /* empty */
320#else 320#else
321#define __debugused __unused 321#define __debugused __unused
322#endif 322#endif
323 323
324#if __GNUC_PREREQ__(3, 1) || defined(__lint__) 324#if __GNUC_PREREQ__(3, 1) || defined(__lint__)
325#define __noprofile __attribute__((__no_instrument_function__)) 325#define __noprofile __attribute__((__no_instrument_function__))
326#else 326#else
327#define __noprofile /* nothing */ 327#define __noprofile /* nothing */
328#endif 328#endif
329 329
330#if __GNUC_PREREQ__(4, 6) || defined(__clang__) || defined(__lint__) 330#if __GNUC_PREREQ__(4, 6) || defined(__clang__) || defined(__lint__)
331#define __unreachable() __builtin_unreachable() 331#define __unreachable() __builtin_unreachable()
332#else 332#else
333#define __unreachable() do {} while (/*CONSTCOND*/0) 333#define __unreachable() do {} while (/*CONSTCOND*/0)
334#endif 334#endif
335 335
336#if defined(_KERNEL) || defined(_RUMPKERNEL) 336#if defined(_KERNEL) || defined(_RUMPKERNEL)
337#if defined(__clang__) && __has_feature(address_sanitizer) 337#if defined(__clang__) && __has_feature(address_sanitizer)
338#define __noasan __attribute__((no_sanitize("kernel-address", "address"))) 338#define __noasan __attribute__((no_sanitize("kernel-address", "address")))
339#elif __GNUC_PREREQ__(4, 9) && defined(__SANITIZE_ADDRESS__) 339#elif __GNUC_PREREQ__(4, 9) && defined(__SANITIZE_ADDRESS__)
340#define __noasan __attribute__((no_sanitize_address)) 340#define __noasan __attribute__((no_sanitize_address))
341#else 341#else
342#define __noasan /* nothing */ 342#define __noasan /* nothing */
343#endif 343#endif
344 344
345#if defined(__clang__) && __has_feature(thread_sanitizer) 345#if defined(__clang__) && __has_feature(thread_sanitizer)
346#define __nocsan __attribute__((no_sanitize("thread"))) 346#define __nocsan __attribute__((no_sanitize("thread")))
347#elif __GNUC_PREREQ__(4, 9) && defined(__SANITIZE_THREAD__) 347#elif __GNUC_PREREQ__(4, 9) && defined(__SANITIZE_THREAD__)
348#define __nocsan __attribute__((no_sanitize_thread)) 348#define __nocsan __attribute__((no_sanitize_thread))
349#else 349#else
350#define __nocsan /* nothing */ 350#define __nocsan /* nothing */
351#endif 351#endif
352 352
353#if defined(__clang__) && __has_feature(memory_sanitizer) 353#if defined(__clang__) && __has_feature(memory_sanitizer)
354#define __nomsan __attribute__((no_sanitize("kernel-memory", "memory"))) 354#define __nomsan __attribute__((no_sanitize("kernel-memory", "memory")))
355#else 355#else
356#define __nomsan /* nothing */ 356#define __nomsan /* nothing */
357#endif 357#endif
358 358
359#if defined(__clang__) && __has_feature(undefined_behavior_sanitizer) 359#if defined(__clang__) && __has_feature(undefined_behavior_sanitizer)
360#define __noubsan __attribute__((no_sanitize("undefined"))) 360#define __noubsan __attribute__((no_sanitize("undefined")))
361#elif __GNUC_PREREQ__(4, 9) && defined(__SANITIZE_UNDEFINED__) 361#elif __GNUC_PREREQ__(4, 9) && defined(__SANITIZE_UNDEFINED__)
362#define __noubsan __attribute__((no_sanitize_undefined)) 362#define __noubsan __attribute__((no_sanitize_undefined))
363#else 363#else
364#define __noubsan /* nothing */ 364#define __noubsan /* nothing */
365#endif 365#endif
366#endif 366#endif
367 367
368#if defined(__COVERITY__) || \ 368#if defined(__COVERITY__) || \
369 __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__) ||\ 369 __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__) ||\
370 __has_feature(leak_sanitizer) || defined(__SANITIZE_LEAK__) 370 __has_feature(leak_sanitizer) || defined(__SANITIZE_LEAK__)
371#define __NO_LEAKS 371#define __NO_LEAKS
372#endif 372#endif
373 373
374/* 374/*
375 * To be used when an empty body is required like: 375 * To be used when an empty body is required like:
376 * 376 *
377 * #ifdef DEBUG 377 * #ifdef DEBUG
378 * # define dprintf(a) printf(a) 378 * # define dprintf(a) printf(a)
379 * #else 379 * #else
380 * # define dprintf(a) __nothing 380 * # define dprintf(a) __nothing
381 * #endif 381 * #endif
382 * 382 *
383 * We use ((void)0) instead of do {} while (0) so that it 383 * We use ((void)0) instead of do {} while (0) so that it
384 * works on , expressions. 384 * works on , expressions.
385 */ 385 */
386#define __nothing (/*LINTED*/(void)0) 386#define __nothing (/*LINTED*/(void)0)
387 387
388#if defined(__cplusplus) 388#if defined(__cplusplus)
389#define __BEGIN_EXTERN_C extern "C" { 389#define __BEGIN_EXTERN_C extern "C" {
390#define __END_EXTERN_C } 390#define __END_EXTERN_C }
391#define __static_cast(x,y) static_cast<x>(y) 391#define __static_cast(x,y) static_cast<x>(y)
392#else 392#else
393#define __BEGIN_EXTERN_C 393#define __BEGIN_EXTERN_C
394#define __END_EXTERN_C 394#define __END_EXTERN_C
395#define __static_cast(x,y) (x)y 395#define __static_cast(x,y) (x)y
396#endif 396#endif
397 397
398#if __GNUC_PREREQ__(4, 0) || defined(__lint__) 398#if __GNUC_PREREQ__(4, 0) || defined(__lint__)
399# define __dso_public __attribute__((__visibility__("default"))) 399# define __dso_public __attribute__((__visibility__("default")))
400# define __dso_hidden __attribute__((__visibility__("hidden"))) 400# define __dso_hidden __attribute__((__visibility__("hidden")))
401# define __BEGIN_PUBLIC_DECLS \ 401# define __BEGIN_PUBLIC_DECLS \
402 _Pragma("GCC visibility push(default)") __BEGIN_EXTERN_C 402 _Pragma("GCC visibility push(default)") __BEGIN_EXTERN_C
403# define __END_PUBLIC_DECLS __END_EXTERN_C _Pragma("GCC visibility pop") 403# define __END_PUBLIC_DECLS __END_EXTERN_C _Pragma("GCC visibility pop")
404# define __BEGIN_HIDDEN_DECLS \ 404# define __BEGIN_HIDDEN_DECLS \
405 _Pragma("GCC visibility push(hidden)") __BEGIN_EXTERN_C 405 _Pragma("GCC visibility push(hidden)") __BEGIN_EXTERN_C
406# define __END_HIDDEN_DECLS __END_EXTERN_C _Pragma("GCC visibility pop") 406# define __END_HIDDEN_DECLS __END_EXTERN_C _Pragma("GCC visibility pop")
407#else 407#else
408# define __dso_public 408# define __dso_public
409# define __dso_hidden 409# define __dso_hidden
410# define __BEGIN_PUBLIC_DECLS __BEGIN_EXTERN_C 410# define __BEGIN_PUBLIC_DECLS __BEGIN_EXTERN_C
411# define __END_PUBLIC_DECLS __END_EXTERN_C 411# define __END_PUBLIC_DECLS __END_EXTERN_C
412# define __BEGIN_HIDDEN_DECLS __BEGIN_EXTERN_C 412# define __BEGIN_HIDDEN_DECLS __BEGIN_EXTERN_C
413# define __END_HIDDEN_DECLS __END_EXTERN_C 413# define __END_HIDDEN_DECLS __END_EXTERN_C
414#endif 414#endif
415#if __GNUC_PREREQ__(4, 2) || defined(__lint__) 415#if __GNUC_PREREQ__(4, 2) || defined(__lint__)
416# define __dso_protected __attribute__((__visibility__("protected"))) 416# define __dso_protected __attribute__((__visibility__("protected")))
417#else 417#else
418# define __dso_protected 418# define __dso_protected
419#endif 419#endif
420 420
421#define __BEGIN_DECLS __BEGIN_PUBLIC_DECLS 421#define __BEGIN_DECLS __BEGIN_PUBLIC_DECLS
422#define __END_DECLS __END_PUBLIC_DECLS 422#define __END_DECLS __END_PUBLIC_DECLS
423 423
424/* 424/*
425 * Non-static C99 inline functions are optional bodies. They don't 425 * Non-static C99 inline functions are optional bodies. They don't
426 * create global symbols if not used, but can be replaced if desirable. 426 * create global symbols if not used, but can be replaced if desirable.
427 * This differs from the behavior of GCC before version 4.3. The nearest 427 * This differs from the behavior of GCC before version 4.3. The nearest
428 * equivalent for older GCC is `extern inline'. For newer GCC, use the 428 * equivalent for older GCC is `extern inline'. For newer GCC, use the
429 * gnu_inline attribute additionally to get the old behavior. 429 * gnu_inline attribute additionally to get the old behavior.
430 * 430 *
431 * For C99 compilers other than GCC, the C99 behavior is expected. 431 * For C99 compilers other than GCC, the C99 behavior is expected.
432 */ 432 */
433#if defined(__GNUC__) && defined(__GNUC_STDC_INLINE__) 433#if defined(__GNUC__) && defined(__GNUC_STDC_INLINE__)
434#define __c99inline extern __attribute__((__gnu_inline__)) __inline 434#define __c99inline extern __attribute__((__gnu_inline__)) __inline
435#elif defined(__GNUC__) 435#elif defined(__GNUC__)
436#define __c99inline extern __inline 436#define __c99inline extern __inline
437#elif defined(__STDC_VERSION__) || defined(__lint__) 437#elif defined(__STDC_VERSION__) || defined(__lint__)
438#define __c99inline __inline 438#define __c99inline __inline
439#endif 439#endif
440 440
441#if defined(__lint__) 441#if defined(__lint__)
442#define __thread /* delete */ 442#define __thread /* delete */
443#define __packed __packed 443#define __packed __packed
444#define __aligned(x) /* delete */ 444#define __aligned(x) /* delete */
445#define __section(x) /* delete */ 445#define __section(x) /* delete */
446#elif __GNUC_PREREQ__(2, 7) || defined(__PCC__) || defined(__lint__) 446#elif __GNUC_PREREQ__(2, 7) || defined(__PCC__) || defined(__lint__)
447#define __packed __attribute__((__packed__)) 447#define __packed __attribute__((__packed__))
448#define __aligned(x) __attribute__((__aligned__(x))) 448#define __aligned(x) __attribute__((__aligned__(x)))
449#define __section(x) __attribute__((__section__(x))) 449#define __section(x) __attribute__((__section__(x)))
450#elif defined(_MSC_VER) 450#elif defined(_MSC_VER)
451#define __packed /* ignore */ 451#define __packed /* ignore */
452#else 452#else
453#define __packed error: no __packed for this compiler 453#define __packed error: no __packed for this compiler
454#define __aligned(x) error: no __aligned for this compiler 454#define __aligned(x) error: no __aligned for this compiler
455#define __section(x) error: no __section for this compiler 455#define __section(x) error: no __section for this compiler
456#endif 456#endif
457 457
458/* 458/*
459 * C99 defines the restrict type qualifier keyword, which was made available 459 * C99 defines the restrict type qualifier keyword, which was made available
460 * in GCC 2.92. 460 * in GCC 2.92.
461 */ 461 */
462#if defined(__lint__) 462#if defined(__lint__)
463#define __restrict /* delete __restrict when not supported */ 463#define __restrict /* delete __restrict when not supported */
464#elif __STDC_VERSION__ >= 199901L 464#elif __STDC_VERSION__ >= 199901L
465#define __restrict restrict 465#define __restrict restrict
466#elif __GNUC_PREREQ__(2, 92) || defined(__lint__) 466#elif __GNUC_PREREQ__(2, 92) || defined(__lint__)
467#define __restrict __restrict__ 467#define __restrict __restrict__
468#else 468#else
469#define __restrict /* delete __restrict when not supported */ 469#define __restrict /* delete __restrict when not supported */
470#endif 470#endif
471 471
472/* 472/*
473 * C99 and C++11 define __func__ predefined identifier, which was made 473 * C99 and C++11 define __func__ predefined identifier, which was made
474 * available in GCC 2.95. 474 * available in GCC 2.95.
475 */ 475 */
476#if !(__STDC_VERSION__ >= 199901L) && !(__cplusplus - 0 >= 201103L) 476#if !(__STDC_VERSION__ >= 199901L) && !(__cplusplus - 0 >= 201103L)
477#if __GNUC_PREREQ__(2, 4) || defined(__lint__) 477#if __GNUC_PREREQ__(2, 4) || defined(__lint__)
478#define __func__ __FUNCTION__ 478#define __func__ __FUNCTION__
479#else 479#else
480#define __func__ "" 480#define __func__ ""
481#endif 481#endif
482#endif /* !(__STDC_VERSION__ >= 199901L) && !(__cplusplus - 0 >= 201103L) */ 482#endif /* !(__STDC_VERSION__ >= 199901L) && !(__cplusplus - 0 >= 201103L) */
483 483
484#if defined(_KERNEL) 484#if defined(_KERNEL) && defined(NO_KERNEL_RCSIDS)
485#if defined(NO_KERNEL_RCSIDS) 485#undef __KERNEL_RCSID
486#undef __KERNEL_RCSID 486#define __KERNEL_RCSID(_n, _s) /* nothing */
487#define __KERNEL_RCSID(_n, _s) /* nothing */ 487#undef __RCSID
488#endif /* NO_KERNEL_RCSIDS */ 488#define __RCSID(_s) /* nothing */
489#endif /* _KERNEL */ 489#endif
490 490
491#if !defined(_STANDALONE) && !defined(_KERNEL) 491#if !defined(_STANDALONE) && !defined(_KERNEL)
492#if defined(__GNUC__) || defined(__PCC__) 492#if defined(__GNUC__) || defined(__PCC__)
493#define __RENAME(x) ___RENAME(x) 493#define __RENAME(x) ___RENAME(x)
494#elif defined(__lint__) 494#elif defined(__lint__)
495#define __RENAME(x) __symbolrename(x) 495#define __RENAME(x) __symbolrename(x)
496#else 496#else
497#error "No function renaming possible" 497#error "No function renaming possible"
498#endif /* __GNUC__ */ 498#endif /* __GNUC__ */
499#else /* _STANDALONE || _KERNEL */ 499#else /* _STANDALONE || _KERNEL */
500#define __RENAME(x) no renaming in kernel/standalone environment 500#define __RENAME(x) no renaming in kernel/standalone environment
501#endif 501#endif
502 502
503/* 503/*
504 * A barrier to stop the optimizer from moving code or assume live 504 * A barrier to stop the optimizer from moving code or assume live
505 * register values. This is gcc specific, the version is more or less 505 * register values. This is gcc specific, the version is more or less
506 * arbitrary, might work with older compilers. 506 * arbitrary, might work with older compilers.
507 */ 507 */
508#if __GNUC_PREREQ__(2, 95) || defined(__lint__) 508#if __GNUC_PREREQ__(2, 95) || defined(__lint__)
509#define __insn_barrier() __asm __volatile("":::"memory") 509#define __insn_barrier() __asm __volatile("":::"memory")
510#else 510#else
511#define __insn_barrier() /* */ 511#define __insn_barrier() /* */
512#endif 512#endif
513 513
514/* 514/*
515 * GNU C version 2.96 adds explicit branch prediction so that 515 * GNU C version 2.96 adds explicit branch prediction so that
516 * the CPU back-end can hint the processor and also so that 516 * the CPU back-end can hint the processor and also so that
517 * code blocks can be reordered such that the predicted path 517 * code blocks can be reordered such that the predicted path
518 * sees a more linear flow, thus improving cache behavior, etc. 518 * sees a more linear flow, thus improving cache behavior, etc.
519 * 519 *
520 * The following two macros provide us with a way to use this 520 * The following two macros provide us with a way to use this
521 * compiler feature. Use __predict_true() if you expect the expression 521 * compiler feature. Use __predict_true() if you expect the expression
522 * to evaluate to true, and __predict_false() if you expect the 522 * to evaluate to true, and __predict_false() if you expect the
523 * expression to evaluate to false. 523 * expression to evaluate to false.
524 * 524 *
525 * A few notes about usage: 525 * A few notes about usage:
526 * 526 *
527 * * Generally, __predict_false() error condition checks (unless 527 * * Generally, __predict_false() error condition checks (unless
528 * you have some _strong_ reason to do otherwise, in which case 528 * you have some _strong_ reason to do otherwise, in which case
529 * document it), and/or __predict_true() `no-error' condition 529 * document it), and/or __predict_true() `no-error' condition
530 * checks, assuming you want to optimize for the no-error case. 530 * checks, assuming you want to optimize for the no-error case.
531 * 531 *
532 * * Other than that, if you don't know the likelihood of a test 532 * * Other than that, if you don't know the likelihood of a test
533 * succeeding from empirical or other `hard' evidence, don't 533 * succeeding from empirical or other `hard' evidence, don't
534 * make predictions. 534 * make predictions.
535 * 535 *
536 * * These are meant to be used in places that are run `a lot'. 536 * * These are meant to be used in places that are run `a lot'.
537 * It is wasteful to make predictions in code that is run 537 * It is wasteful to make predictions in code that is run
538 * seldomly (e.g. at subsystem initialization time) as the 538 * seldomly (e.g. at subsystem initialization time) as the
539 * basic block reordering that this affects can often generate 539 * basic block reordering that this affects can often generate
540 * larger code. 540 * larger code.
541 */ 541 */
542#if __GNUC_PREREQ__(2, 96) || defined(__lint__) 542#if __GNUC_PREREQ__(2, 96) || defined(__lint__)
543#define __predict_true(exp) __builtin_expect((exp) != 0, 1) 543#define __predict_true(exp) __builtin_expect((exp) != 0, 1)
544#define __predict_false(exp) __builtin_expect((exp) != 0, 0) 544#define __predict_false(exp) __builtin_expect((exp) != 0, 0)
545#else 545#else
546#define __predict_true(exp) (exp) 546#define __predict_true(exp) (exp)
547#define __predict_false(exp) (exp) 547#define __predict_false(exp) (exp)
548#endif 548#endif
549 549
550/* 550/*
551 * Compiler-dependent macros to declare that functions take printf-like 551 * Compiler-dependent macros to declare that functions take printf-like
552 * or scanf-like arguments. They are null except for versions of gcc 552 * or scanf-like arguments. They are null except for versions of gcc
553 * that are known to support the features properly (old versions of gcc-2 553 * that are known to support the features properly (old versions of gcc-2
554 * didn't permit keeping the keywords out of the application namespace). 554 * didn't permit keeping the keywords out of the application namespace).
555 */ 555 */
556#if __GNUC_PREREQ__(2, 7) || defined(__lint__) 556#if __GNUC_PREREQ__(2, 7) || defined(__lint__)
557#define __printflike(fmtarg, firstvararg) \ 557#define __printflike(fmtarg, firstvararg) \
558 __attribute__((__format__ (__printf__, fmtarg, firstvararg))) 558 __attribute__((__format__ (__printf__, fmtarg, firstvararg)))
559#ifndef __syslog_attribute__ 559#ifndef __syslog_attribute__
560#define __syslog__ __printf__ 560#define __syslog__ __printf__
561#endif 561#endif
562#define __sysloglike(fmtarg, firstvararg) \ 562#define __sysloglike(fmtarg, firstvararg) \
563 __attribute__((__format__ (__syslog__, fmtarg, firstvararg))) 563 __attribute__((__format__ (__syslog__, fmtarg, firstvararg)))
564#define __scanflike(fmtarg, firstvararg) \ 564#define __scanflike(fmtarg, firstvararg) \
565 __attribute__((__format__ (__scanf__, fmtarg, firstvararg))) 565 __attribute__((__format__ (__scanf__, fmtarg, firstvararg)))
566#define __format_arg(fmtarg) __attribute__((__format_arg__ (fmtarg))) 566#define __format_arg(fmtarg) __attribute__((__format_arg__ (fmtarg)))
567#else 567#else
568#define __printflike(fmtarg, firstvararg) /* nothing */ 568#define __printflike(fmtarg, firstvararg) /* nothing */
569#define __scanflike(fmtarg, firstvararg) /* nothing */ 569#define __scanflike(fmtarg, firstvararg) /* nothing */
570#define __sysloglike(fmtarg, firstvararg) /* nothing */ 570#define __sysloglike(fmtarg, firstvararg) /* nothing */
571#define __format_arg(fmtarg) /* nothing */ 571#define __format_arg(fmtarg) /* nothing */
572#endif 572#endif
573 573
574/* 574/*
575 * Macros for manipulating "link sets". Link sets are arrays of pointers 575 * Macros for manipulating "link sets". Link sets are arrays of pointers
576 * to objects, which are gathered up by the linker. 576 * to objects, which are gathered up by the linker.
577 * 577 *
578 * Object format-specific code has provided us with the following macros: 578 * Object format-specific code has provided us with the following macros:
579 * 579 *
580 * __link_set_add_text(set, sym) 580 * __link_set_add_text(set, sym)
581 * Add a reference to the .text symbol `sym' to `set'. 581 * Add a reference to the .text symbol `sym' to `set'.
582 * 582 *
583 * __link_set_add_rodata(set, sym) 583 * __link_set_add_rodata(set, sym)
584 * Add a reference to the .rodata symbol `sym' to `set'. 584 * Add a reference to the .rodata symbol `sym' to `set'.
585 * 585 *
586 * __link_set_add_data(set, sym) 586 * __link_set_add_data(set, sym)
587 * Add a reference to the .data symbol `sym' to `set'. 587 * Add a reference to the .data symbol `sym' to `set'.
588 * 588 *
589 * __link_set_add_bss(set, sym) 589 * __link_set_add_bss(set, sym)
590 * Add a reference to the .bss symbol `sym' to `set'. 590 * Add a reference to the .bss symbol `sym' to `set'.
591 * 591 *
592 * __link_set_decl(set, ptype) 592 * __link_set_decl(set, ptype)
593 * Provide an extern declaration of the set `set', which 593 * Provide an extern declaration of the set `set', which
594 * contains an array of pointers to type `ptype'. This 594 * contains an array of pointers to type `ptype'. This
595 * macro must be used by any code which wishes to reference 595 * macro must be used by any code which wishes to reference
596 * the elements of a link set. 596 * the elements of a link set.
597 * 597 *
598 * __link_set_start(set) 598 * __link_set_start(set)
599 * This points to the first slot in the link set. 599 * This points to the first slot in the link set.
600 * 600 *
601 * __link_set_end(set) 601 * __link_set_end(set)
602 * This points to the (non-existent) slot after the last 602 * This points to the (non-existent) slot after the last
603 * entry in the link set. 603 * entry in the link set.
604 * 604 *
605 * __link_set_count(set) 605 * __link_set_count(set)
606 * Count the number of entries in link set `set'. 606 * Count the number of entries in link set `set'.
607 * 607 *
608 * In addition, we provide the following macros for accessing link sets: 608 * In addition, we provide the following macros for accessing link sets:
609 * 609 *
610 * __link_set_foreach(pvar, set) 610 * __link_set_foreach(pvar, set)
611 * Iterate over the link set `set'. Because a link set is 611 * Iterate over the link set `set'. Because a link set is
612 * an array of pointers, pvar must be declared as "type **pvar", 612 * an array of pointers, pvar must be declared as "type **pvar",
613 * and the actual entry accessed as "*pvar". 613 * and the actual entry accessed as "*pvar".
614 * 614 *
615 * __link_set_entry(set, idx) 615 * __link_set_entry(set, idx)
616 * Access the link set entry at index `idx' from set `set'. 616 * Access the link set entry at index `idx' from set `set'.
617 */ 617 */
618#define __link_set_foreach(pvar, set) \ 618#define __link_set_foreach(pvar, set) \
619 for (pvar = __link_set_start(set); pvar < __link_set_end(set); pvar++) 619 for (pvar = __link_set_start(set); pvar < __link_set_end(set); pvar++)
620 620
621#define __link_set_entry(set, idx) (__link_set_start(set)[idx]) 621#define __link_set_entry(set, idx) (__link_set_start(set)[idx])
622 622
623/* 623/*
624 * Return the natural alignment in bytes for the given type 624 * Return the natural alignment in bytes for the given type
625 */ 625 */
626#if __GNUC_PREREQ__(4, 1) || defined(__lint__) 626#if __GNUC_PREREQ__(4, 1) || defined(__lint__)
627#define __alignof(__t) __alignof__(__t) 627#define __alignof(__t) __alignof__(__t)
628#else 628#else
629#define __alignof(__t) (sizeof(struct { char __x; __t __y; }) - sizeof(__t)) 629#define __alignof(__t) (sizeof(struct { char __x; __t __y; }) - sizeof(__t))
630#endif 630#endif
631 631
632/* 632/*
633 * Return the number of elements in a statically-allocated array, 633 * Return the number of elements in a statically-allocated array,
634 * __x. 634 * __x.
635 */ 635 */
636#define __arraycount(__x) (sizeof(__x) / sizeof(__x[0])) 636#define __arraycount(__x) (sizeof(__x) / sizeof(__x[0]))
637 637
638#ifndef __ASSEMBLER__ 638#ifndef __ASSEMBLER__
639/* __BIT(n): nth bit, where __BIT(0) == 0x1. */ 639/* __BIT(n): nth bit, where __BIT(0) == 0x1. */
640#define __BIT(__n) \ 640#define __BIT(__n) \
641 (((uintmax_t)(__n) >= NBBY * sizeof(uintmax_t)) ? 0 : \ 641 (((uintmax_t)(__n) >= NBBY * sizeof(uintmax_t)) ? 0 : \
642 ((uintmax_t)1 << (uintmax_t)((__n) & (NBBY * sizeof(uintmax_t) - 1)))) 642 ((uintmax_t)1 << (uintmax_t)((__n) & (NBBY * sizeof(uintmax_t) - 1))))
643 643
644/* Macros for min/max. */ 644/* Macros for min/max. */
645#define __MIN(a,b) ((/*CONSTCOND*/(a)<=(b))?(a):(b)) 645#define __MIN(a,b) ((/*CONSTCOND*/(a)<=(b))?(a):(b))
646#define __MAX(a,b) ((/*CONSTCOND*/(a)>(b))?(a):(b)) 646#define __MAX(a,b) ((/*CONSTCOND*/(a)>(b))?(a):(b))
647 647
648/* __BITS(m, n): bits m through n, m < n. */ 648/* __BITS(m, n): bits m through n, m < n. */
649#define __BITS(__m, __n) \ 649#define __BITS(__m, __n) \
650 ((__BIT(__MAX((__m), (__n)) + 1) - 1) ^ (__BIT(__MIN((__m), (__n))) - 1)) 650 ((__BIT(__MAX((__m), (__n)) + 1) - 1) ^ (__BIT(__MIN((__m), (__n))) - 1))
651#endif /* !__ASSEMBLER__ */ 651#endif /* !__ASSEMBLER__ */
652 652
653/* find least significant bit that is set */ 653/* find least significant bit that is set */
654#define __LOWEST_SET_BIT(__mask) ((((__mask) - 1) & (__mask)) ^ (__mask)) 654#define __LOWEST_SET_BIT(__mask) ((((__mask) - 1) & (__mask)) ^ (__mask))
655 655
656#define __PRIuBIT PRIuMAX 656#define __PRIuBIT PRIuMAX
657#define __PRIuBITS __PRIuBIT 657#define __PRIuBITS __PRIuBIT
658 658
659#define __PRIxBIT PRIxMAX 659#define __PRIxBIT PRIxMAX
660#define __PRIxBITS __PRIxBIT 660#define __PRIxBITS __PRIxBIT
661 661
662#define __SHIFTOUT(__x, __mask) (((__x) & (__mask)) / __LOWEST_SET_BIT(__mask)) 662#define __SHIFTOUT(__x, __mask) (((__x) & (__mask)) / __LOWEST_SET_BIT(__mask))
663#define __SHIFTIN(__x, __mask) ((__x) * __LOWEST_SET_BIT(__mask)) 663#define __SHIFTIN(__x, __mask) ((__x) * __LOWEST_SET_BIT(__mask))
664#define __SHIFTOUT_MASK(__mask) __SHIFTOUT((__mask), (__mask)) 664#define __SHIFTOUT_MASK(__mask) __SHIFTOUT((__mask), (__mask))
665 665
666/* 666/*
667 * Only to be used in other headers that are included from both c or c++ 667 * Only to be used in other headers that are included from both c or c++
668 * NOT to be used in code. 668 * NOT to be used in code.
669 */ 669 */
670#ifdef __cplusplus 670#ifdef __cplusplus
671#define __CAST(__dt, __st) static_cast<__dt>(__st) 671#define __CAST(__dt, __st) static_cast<__dt>(__st)
672#else 672#else
673#define __CAST(__dt, __st) ((__dt)(__st)) 673#define __CAST(__dt, __st) ((__dt)(__st))
674#endif 674#endif
675 675
676#define __CASTV(__dt, __st) __CAST(__dt, __CAST(void *, __st)) 676#define __CASTV(__dt, __st) __CAST(__dt, __CAST(void *, __st))
677#define __CASTCV(__dt, __st) __CAST(__dt, __CAST(const void *, __st)) 677#define __CASTCV(__dt, __st) __CAST(__dt, __CAST(const void *, __st))
678 678
679#define __USE(a) (/*LINTED*/(void)(a)) 679#define __USE(a) (/*LINTED*/(void)(a))
680 680
681#define __type_mask(t) (/*LINTED*/sizeof(t) < sizeof(intmax_t) ? \ 681#define __type_mask(t) (/*LINTED*/sizeof(t) < sizeof(intmax_t) ? \
682 (~((1ULL << (sizeof(t) * NBBY)) - 1)) : 0ULL) 682 (~((1ULL << (sizeof(t) * NBBY)) - 1)) : 0ULL)
683 683
684#ifndef __ASSEMBLER__ 684#ifndef __ASSEMBLER__
685static __inline long long __zeroll(void) { return 0; } 685static __inline long long __zeroll(void) { return 0; }
686static __inline unsigned long long __zeroull(void) { return 0; } 686static __inline unsigned long long __zeroull(void) { return 0; }
687#else 687#else
688#define __zeroll() (0LL) 688#define __zeroll() (0LL)
689#define __zeroull() (0ULL) 689#define __zeroull() (0ULL)
690#endif 690#endif
691 691
692#define __negative_p(x) (!((x) > 0) && ((x) != 0)) 692#define __negative_p(x) (!((x) > 0) && ((x) != 0))
693 693
694#define __type_min_s(t) ((t)((1ULL << (sizeof(t) * NBBY - 1)))) 694#define __type_min_s(t) ((t)((1ULL << (sizeof(t) * NBBY - 1))))
695#define __type_max_s(t) ((t)~((1ULL << (sizeof(t) * NBBY - 1)))) 695#define __type_max_s(t) ((t)~((1ULL << (sizeof(t) * NBBY - 1))))
696#define __type_min_u(t) ((t)0ULL) 696#define __type_min_u(t) ((t)0ULL)
697#define __type_max_u(t) ((t)~0ULL) 697#define __type_max_u(t) ((t)~0ULL)
698#define __type_is_signed(t) (/*LINTED*/__type_min_s(t) + (t)1 < (t)1) 698#define __type_is_signed(t) (/*LINTED*/__type_min_s(t) + (t)1 < (t)1)
699#define __type_min(t) (__type_is_signed(t) ? __type_min_s(t) : __type_min_u(t)) 699#define __type_min(t) (__type_is_signed(t) ? __type_min_s(t) : __type_min_u(t))
700#define __type_max(t) (__type_is_signed(t) ? __type_max_s(t) : __type_max_u(t)) 700#define __type_max(t) (__type_is_signed(t) ? __type_max_s(t) : __type_max_u(t))
701 701
702 702
703#define __type_fit_u(t, a) (/*LINTED*/!__negative_p(a) && \ 703#define __type_fit_u(t, a) (/*LINTED*/!__negative_p(a) && \
704 (uintmax_t)((a) + __zeroull()) <= (uintmax_t)__type_max_u(t)) 704 (uintmax_t)((a) + __zeroull()) <= (uintmax_t)__type_max_u(t))
705 705
706#define __type_fit_s(t, a) (/*LINTED*/__negative_p(a) ? \ 706#define __type_fit_s(t, a) (/*LINTED*/__negative_p(a) ? \
707 ((intmax_t)((a) + __zeroll()) >= (intmax_t)__type_min_s(t)) : \ 707 ((intmax_t)((a) + __zeroll()) >= (intmax_t)__type_min_s(t)) : \
708 ((intmax_t)((a) + __zeroll()) >= (intmax_t)0 && \ 708 ((intmax_t)((a) + __zeroll()) >= (intmax_t)0 && \
709 (intmax_t)((a) + __zeroll()) <= (intmax_t)__type_max_s(t))) 709 (intmax_t)((a) + __zeroll()) <= (intmax_t)__type_max_s(t)))
710 710
711/* 711/*
712 * return true if value 'a' fits in type 't' 712 * return true if value 'a' fits in type 't'
713 */ 713 */
714#define __type_fit(t, a) (__type_is_signed(t) ? \ 714#define __type_fit(t, a) (__type_is_signed(t) ? \
715 __type_fit_s(t, a) : __type_fit_u(t, a)) 715 __type_fit_s(t, a) : __type_fit_u(t, a))
716 716
717#endif /* !_SYS_CDEFS_H_ */ 717#endif /* !_SYS_CDEFS_H_ */