1 | /** @file
|
---|
2 | * IPRT - Common C and C++ definitions.
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2006-2007 Sun Microsystems, Inc.
|
---|
7 | *
|
---|
8 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
9 | * available from http://www.virtualbox.org. This file is free software;
|
---|
10 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
11 | * General Public License (GPL) as published by the Free Software
|
---|
12 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
13 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
14 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
15 | *
|
---|
16 | * The contents of this file may alternatively be used under the terms
|
---|
17 | * of the Common Development and Distribution License Version 1.0
|
---|
18 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
19 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
20 | * CDDL are applicable instead of those of the GPL.
|
---|
21 | *
|
---|
22 | * You may elect to license modified versions of this file under the
|
---|
23 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
24 | *
|
---|
25 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
26 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
27 | * additional information or have any questions.
|
---|
28 | */
|
---|
29 |
|
---|
30 | #ifndef ___iprt_cdefs_h
|
---|
31 | #define ___iprt_cdefs_h
|
---|
32 |
|
---|
33 |
|
---|
34 | /** @defgroup grp_rt_cdefs IPRT Common Definitions and Macros
|
---|
35 | * @{
|
---|
36 | */
|
---|
37 |
|
---|
38 | /*
|
---|
39 | * Include sys/cdefs.h if present, if not define the stuff we need.
|
---|
40 | */
|
---|
41 | #ifdef HAVE_SYS_CDEFS_H
|
---|
42 | # if defined(RT_ARCH_LINUX) && defined(__KERNEL__)
|
---|
43 | # error "oops"
|
---|
44 | # endif
|
---|
45 | # include <sys/cdefs.h>
|
---|
46 | #else
|
---|
47 |
|
---|
48 | /** @def __BEGIN_DECLS
|
---|
49 | * Used to start a block of function declarations which are shared
|
---|
50 | * between C and C++ program.
|
---|
51 | */
|
---|
52 |
|
---|
53 | /** @def __END_DECLS
|
---|
54 | * Used to end a block of function declarations which are shared
|
---|
55 | * between C and C++ program.
|
---|
56 | */
|
---|
57 |
|
---|
58 | #if defined(__cplusplus)
|
---|
59 | # define __BEGIN_DECLS extern "C" {
|
---|
60 | # define __END_DECLS }
|
---|
61 | #else
|
---|
62 | # define __BEGIN_DECLS
|
---|
63 | # define __END_DECLS
|
---|
64 | #endif
|
---|
65 |
|
---|
66 | #endif
|
---|
67 |
|
---|
68 |
|
---|
69 | /*
|
---|
70 | * Shut up DOXYGEN warnings and guide it properly thru the code.
|
---|
71 | */
|
---|
72 | #ifdef DOXYGEN_RUNNING
|
---|
73 | #define __AMD64__
|
---|
74 | #define __X86__
|
---|
75 | #define RT_ARCH_AMD64
|
---|
76 | #define RT_ARCH_X86
|
---|
77 | #define IN_RING0
|
---|
78 | #define IN_RING3
|
---|
79 | #define IN_GC
|
---|
80 | #define IN_RT_GC
|
---|
81 | #define IN_RT_R0
|
---|
82 | #define IN_RT_R3
|
---|
83 | #define IN_RT_STATIC
|
---|
84 | #define RT_STRICT
|
---|
85 | #define Breakpoint
|
---|
86 | #define RT_NO_DEPRECATED_MACROS
|
---|
87 | #endif /* DOXYGEN_RUNNING */
|
---|
88 |
|
---|
89 | /** @def RT_ARCH_X86
|
---|
90 | * Indicates that we're compiling for the X86 architecture.
|
---|
91 | */
|
---|
92 |
|
---|
93 | /** @def RT_ARCH_AMD64
|
---|
94 | * Indicates that we're compiling for the AMD64 architecture.
|
---|
95 | */
|
---|
96 | #if !defined(RT_ARCH_X86) && !defined(RT_ARCH_AMD64)
|
---|
97 | # if defined(__amd64__) || defined(__x86_64__) || defined(_M_X64) || defined(__AMD64__)
|
---|
98 | # define RT_ARCH_AMD64
|
---|
99 | # elif defined(__i386__) || defined(_M_IX86) || defined(__X86__)
|
---|
100 | # define RT_ARCH_X86
|
---|
101 | # else /* PORTME: append test for new archs. */
|
---|
102 | # error "Check what predefined stuff your compiler uses to indicate architecture."
|
---|
103 | # endif
|
---|
104 | #elif defined(RT_ARCH_X86) && defined(RT_ARCH_AMD64) /* PORTME: append new archs. */
|
---|
105 | # error "Both RT_ARCH_X86 and RT_ARCH_AMD64 cannot be defined at the same time!"
|
---|
106 | #endif
|
---|
107 |
|
---|
108 |
|
---|
109 | /** @def __X86__
|
---|
110 | * Indicates that we're compiling for the X86 architecture.
|
---|
111 | * @deprecated
|
---|
112 | */
|
---|
113 |
|
---|
114 | /** @def __AMD64__
|
---|
115 | * Indicates that we're compiling for the AMD64 architecture.
|
---|
116 | * @deprecated
|
---|
117 | */
|
---|
118 | #if !defined(__X86__) && !defined(__AMD64__)
|
---|
119 | # if defined(RT_ARCH_AMD64)
|
---|
120 | # define __AMD64__
|
---|
121 | # elif defined(RT_ARCH_X86)
|
---|
122 | # define __X86__
|
---|
123 | # else
|
---|
124 | # error "Check what predefined stuff your compiler uses to indicate architecture."
|
---|
125 | # endif
|
---|
126 | #elif defined(__X86__) && defined(__AMD64__)
|
---|
127 | # error "Both __X86__ and __AMD64__ cannot be defined at the same time!"
|
---|
128 | #elif defined(__X86__) && !defined(RT_ARCH_X86)
|
---|
129 | # error "Both __X86__ without RT_ARCH_X86!"
|
---|
130 | #elif defined(__AMD64__) && !defined(RT_ARCH_AMD64)
|
---|
131 | # error "Both __AMD64__ without RT_ARCH_AMD64!"
|
---|
132 | #endif
|
---|
133 |
|
---|
134 | /** @def IN_RING0
|
---|
135 | * Used to indicate that we're compiling code which is running
|
---|
136 | * in Ring-0 Host Context.
|
---|
137 | */
|
---|
138 |
|
---|
139 | /** @def IN_RING3
|
---|
140 | * Used to indicate that we're compiling code which is running
|
---|
141 | * in Ring-3 Host Context.
|
---|
142 | */
|
---|
143 |
|
---|
144 | /** @def IN_GC
|
---|
145 | * Used to indicate that we're compiling code which is running
|
---|
146 | * in Guest Context (implies R0).
|
---|
147 | */
|
---|
148 | #if !defined(IN_RING3) && !defined(IN_RING0) && !defined(IN_GC)
|
---|
149 | # error "You must defined which context the compiled code should run in; IN_RING3, IN_RING0 or IN_GC"
|
---|
150 | #endif
|
---|
151 | #if (defined(IN_RING3) && (defined(IN_RING0) || defined(IN_GC)) ) \
|
---|
152 | || (defined(IN_RING0) && (defined(IN_RING3) || defined(IN_GC)) ) \
|
---|
153 | || (defined(IN_GC) && (defined(IN_RING3) || defined(IN_RING0)) )
|
---|
154 | # error "Only one of the IN_RING3, IN_RING0, IN_GC defines should be defined."
|
---|
155 | #endif
|
---|
156 |
|
---|
157 |
|
---|
158 | /** @def ARCH_BITS
|
---|
159 | * Defines the bit count of the current context.
|
---|
160 | */
|
---|
161 | #if !defined(ARCH_BITS) || defined(DOXYGEN_RUNNING)
|
---|
162 | # if defined(RT_ARCH_AMD64)
|
---|
163 | # define ARCH_BITS 64
|
---|
164 | # else
|
---|
165 | # define ARCH_BITS 32
|
---|
166 | # endif
|
---|
167 | #endif
|
---|
168 |
|
---|
169 | /** @def HC_ARCH_BITS
|
---|
170 | * Defines the host architecture bit count.
|
---|
171 | */
|
---|
172 | #if !defined(HC_ARCH_BITS) || defined(DOXYGEN_RUNNING)
|
---|
173 | # ifndef IN_GC
|
---|
174 | # define HC_ARCH_BITS ARCH_BITS
|
---|
175 | # else
|
---|
176 | # define HC_ARCH_BITS 32
|
---|
177 | # endif
|
---|
178 | #endif
|
---|
179 |
|
---|
180 | /** @def GC_ARCH_BITS
|
---|
181 | * Defines the guest architecture bit count.
|
---|
182 | */
|
---|
183 | #if !defined(GC_ARCH_BITS) && !defined(DOXYGEN_RUNNING)
|
---|
184 | # ifdef VBOX_WITH_64_BITS_GUESTS
|
---|
185 | # define GC_ARCH_BITS 64
|
---|
186 | # else
|
---|
187 | # define GC_ARCH_BITS 32
|
---|
188 | # endif
|
---|
189 | #endif
|
---|
190 |
|
---|
191 | /** @def R3_ARCH_BITS
|
---|
192 | * Defines the host ring-3 architecture bit count.
|
---|
193 | */
|
---|
194 | #if !defined(R3_ARCH_BITS) || defined(DOXYGEN_RUNNING)
|
---|
195 | # ifdef IN_RING3
|
---|
196 | # define R3_ARCH_BITS ARCH_BITS
|
---|
197 | # else
|
---|
198 | # define R3_ARCH_BITS HC_ARCH_BITS
|
---|
199 | # endif
|
---|
200 | #endif
|
---|
201 |
|
---|
202 | /** @def R0_ARCH_BITS
|
---|
203 | * Defines the host ring-0 architecture bit count.
|
---|
204 | */
|
---|
205 | #if !defined(R0_ARCH_BITS) || defined(DOXYGEN_RUNNING)
|
---|
206 | # ifdef IN_RING0
|
---|
207 | # define R0_ARCH_BITS ARCH_BITS
|
---|
208 | # else
|
---|
209 | # define R0_ARCH_BITS HC_ARCH_BITS
|
---|
210 | # endif
|
---|
211 | #endif
|
---|
212 |
|
---|
213 | /** @def GC_ARCH_BITS
|
---|
214 | * Defines the guest architecture bit count.
|
---|
215 | */
|
---|
216 | #if !defined(GC_ARCH_BITS) || defined(DOXYGEN_RUNNING)
|
---|
217 | # ifdef IN_GC
|
---|
218 | # define GC_ARCH_BITS ARCH_BITS
|
---|
219 | # else
|
---|
220 | # define GC_ARCH_BITS 32
|
---|
221 | # endif
|
---|
222 | #endif
|
---|
223 |
|
---|
224 |
|
---|
225 | /** @def CTXTYPE
|
---|
226 | * Declare a type differently in GC, R3 and R0.
|
---|
227 | *
|
---|
228 | * @param GCType The GC type.
|
---|
229 | * @param R3Type The R3 type.
|
---|
230 | * @param R0Type The R0 type.
|
---|
231 | * @remark For pointers used only in one context use RCPTRTYPE(), R3R0PTRTYPE(), R3PTRTYPE() or R0PTRTYPE().
|
---|
232 | */
|
---|
233 | #ifdef IN_GC
|
---|
234 | # define CTXTYPE(GCType, R3Type, R0Type) GCType
|
---|
235 | #elif defined(IN_RING3)
|
---|
236 | # define CTXTYPE(GCType, R3Type, R0Type) R3Type
|
---|
237 | #else
|
---|
238 | # define CTXTYPE(GCType, R3Type, R0Type) R0Type
|
---|
239 | #endif
|
---|
240 |
|
---|
241 | /** @def RCPTRTYPE
|
---|
242 | * Declare a pointer which is used in the raw mode context but appears in structure(s) used by
|
---|
243 | * both HC and RC. The main purpose is to make sure structures have the same
|
---|
244 | * size when built for different architectures.
|
---|
245 | *
|
---|
246 | * @param RCType The RC type.
|
---|
247 | */
|
---|
248 | #define RCPTRTYPE(RCType) CTXTYPE(RCType, RTRCPTR, RTRCPTR)
|
---|
249 |
|
---|
250 | /** @def R3R0PTRTYPE
|
---|
251 | * Declare a pointer which is used in HC, is explicitely valid in ring 3 and 0,
|
---|
252 | * but appears in structure(s) used by both HC and GC. The main purpose is to
|
---|
253 | * make sure structures have the same size when built for different architectures.
|
---|
254 | *
|
---|
255 | * @param R3R0Type The R3R0 type.
|
---|
256 | * @remarks This used to be called HCPTRTYPE.
|
---|
257 | */
|
---|
258 | #define R3R0PTRTYPE(R3R0Type) CTXTYPE(RTHCPTR, R3R0Type, R3R0Type)
|
---|
259 |
|
---|
260 | /** @def R3PTRTYPE
|
---|
261 | * Declare a pointer which is used in R3 but appears in structure(s) used by
|
---|
262 | * both HC and GC. The main purpose is to make sure structures have the same
|
---|
263 | * size when built for different architectures.
|
---|
264 | *
|
---|
265 | * @param R3Type The R3 type.
|
---|
266 | */
|
---|
267 | #define R3PTRTYPE(R3Type) CTXTYPE(RTHCUINTPTR, R3Type, RTHCUINTPTR)
|
---|
268 |
|
---|
269 | /** @def R0PTRTYPE
|
---|
270 | * Declare a pointer which is used in R0 but appears in structure(s) used by
|
---|
271 | * both HC and GC. The main purpose is to make sure structures have the same
|
---|
272 | * size when built for different architectures.
|
---|
273 | *
|
---|
274 | * @param R0Type The R0 type.
|
---|
275 | */
|
---|
276 | #define R0PTRTYPE(R0Type) CTXTYPE(RTHCUINTPTR, RTHCUINTPTR, R0Type)
|
---|
277 |
|
---|
278 | /** @def CTXSUFF
|
---|
279 | * Adds the suffix of the current context to the passed in
|
---|
280 | * identifier name. The suffix is HC or GC.
|
---|
281 | *
|
---|
282 | * This is macro should only be used in shared code to avoid a forrest of ifdefs.
|
---|
283 | * @param var Identifier name.
|
---|
284 | * @deprecated Use CTX_SUFF. Do NOT use this for new code.
|
---|
285 | */
|
---|
286 | /** @def OTHERCTXSUFF
|
---|
287 | * Adds the suffix of the other context to the passed in
|
---|
288 | * identifier name. The suffix is HC or GC.
|
---|
289 | *
|
---|
290 | * This is macro should only be used in shared code to avoid a forrest of ifdefs.
|
---|
291 | * @param var Identifier name.
|
---|
292 | * @deprecated Use CTX_SUFF. Do NOT use this for new code.
|
---|
293 | */
|
---|
294 | #ifdef IN_GC
|
---|
295 | # define CTXSUFF(var) var##GC
|
---|
296 | # define OTHERCTXSUFF(var) var##HC
|
---|
297 | #else
|
---|
298 | # define CTXSUFF(var) var##HC
|
---|
299 | # define OTHERCTXSUFF(var) var##GC
|
---|
300 | #endif
|
---|
301 |
|
---|
302 | /** @def CTXALLSUFF
|
---|
303 | * Adds the suffix of the current context to the passed in
|
---|
304 | * identifier name. The suffix is R3, R0 or GC.
|
---|
305 | *
|
---|
306 | * This is macro should only be used in shared code to avoid a forrest of ifdefs.
|
---|
307 | * @param var Identifier name.
|
---|
308 | * @deprecated Use CTX_SUFF. Do NOT use this for new code.
|
---|
309 | */
|
---|
310 | #ifdef IN_GC
|
---|
311 | # define CTXALLSUFF(var) var##GC
|
---|
312 | #elif defined(IN_RING0)
|
---|
313 | # define CTXALLSUFF(var) var##R0
|
---|
314 | #else
|
---|
315 | # define CTXALLSUFF(var) var##R3
|
---|
316 | #endif
|
---|
317 |
|
---|
318 | /** @def CTX_SUFF
|
---|
319 | * Adds the suffix of the current context to the passed in
|
---|
320 | * identifier name. The suffix is R3, R0 or RC.
|
---|
321 | *
|
---|
322 | * This is macro should only be used in shared code to avoid a forrest of ifdefs.
|
---|
323 | * @param var Identifier name.
|
---|
324 | *
|
---|
325 | * @remark This will replace CTXALLSUFF and CTXSUFF before long.
|
---|
326 | */
|
---|
327 | #ifdef IN_GC
|
---|
328 | # define CTX_SUFF(var) var##RC
|
---|
329 | #elif defined(IN_RING0)
|
---|
330 | # define CTX_SUFF(var) var##R0
|
---|
331 | #else
|
---|
332 | # define CTX_SUFF(var) var##R3
|
---|
333 | #endif
|
---|
334 |
|
---|
335 | /** @def CTX_SUFF_Z
|
---|
336 | * Adds the suffix of the current context to the passed in
|
---|
337 | * identifier name, combining RC and R0 into RZ.
|
---|
338 | * The suffix thus is R3 or RZ.
|
---|
339 | *
|
---|
340 | * This is macro should only be used in shared code to avoid a forrest of ifdefs.
|
---|
341 | * @param var Identifier name.
|
---|
342 | *
|
---|
343 | * @remark This will replace CTXALLSUFF and CTXSUFF before long.
|
---|
344 | */
|
---|
345 | #ifdef IN_RING3
|
---|
346 | # define CTX_SUFF_Z(var) var##R3
|
---|
347 | #else
|
---|
348 | # define CTX_SUFF_Z(var) var##RZ
|
---|
349 | #endif
|
---|
350 |
|
---|
351 |
|
---|
352 | /** @def CTXMID
|
---|
353 | * Adds the current context as a middle name of an identifier name
|
---|
354 | * The middle name is HC or GC.
|
---|
355 | *
|
---|
356 | * This is macro should only be used in shared code to avoid a forrest of ifdefs.
|
---|
357 | * @param first First name.
|
---|
358 | * @param last Surname.
|
---|
359 | */
|
---|
360 | /** @def OTHERCTXMID
|
---|
361 | * Adds the other context as a middle name of an identifier name
|
---|
362 | * The middle name is HC or GC.
|
---|
363 | *
|
---|
364 | * This is macro should only be used in shared code to avoid a forrest of ifdefs.
|
---|
365 | * @param first First name.
|
---|
366 | * @param last Surname.
|
---|
367 | * @deprecated use CTX_MID or CTX_MID_Z
|
---|
368 | */
|
---|
369 | #ifdef IN_GC
|
---|
370 | # define CTXMID(first, last) first##GC##last
|
---|
371 | # define OTHERCTXMID(first, last) first##HC##last
|
---|
372 | #else
|
---|
373 | # define CTXMID(first, last) first##HC##last
|
---|
374 | # define OTHERCTXMID(first, last) first##GC##last
|
---|
375 | #endif
|
---|
376 |
|
---|
377 | /** @def CTXALLMID
|
---|
378 | * Adds the current context as a middle name of an identifier name.
|
---|
379 | * The middle name is R3, R0 or GC.
|
---|
380 | *
|
---|
381 | * This is macro should only be used in shared code to avoid a forrest of ifdefs.
|
---|
382 | * @param first First name.
|
---|
383 | * @param last Surname.
|
---|
384 | * @deprecated use CTX_MID or CTX_MID_Z
|
---|
385 | */
|
---|
386 | #ifdef IN_GC
|
---|
387 | # define CTXALLMID(first, last) first##GC##last
|
---|
388 | #elif defined(IN_RING0)
|
---|
389 | # define CTXALLMID(first, last) first##R0##last
|
---|
390 | #else
|
---|
391 | # define CTXALLMID(first, last) first##R3##last
|
---|
392 | #endif
|
---|
393 |
|
---|
394 | /** @def CTX_MID
|
---|
395 | * Adds the current context as a middle name of an identifier name.
|
---|
396 | * The middle name is R3, R0 or RC.
|
---|
397 | *
|
---|
398 | * This is macro should only be used in shared code to avoid a forrest of ifdefs.
|
---|
399 | * @param first First name.
|
---|
400 | * @param last Surname.
|
---|
401 | */
|
---|
402 | #ifdef IN_GC
|
---|
403 | # define CTX_MID(first, last) first##RC##last
|
---|
404 | #elif defined(IN_RING0)
|
---|
405 | # define CTX_MID(first, last) first##R0##last
|
---|
406 | #else
|
---|
407 | # define CTX_MID(first, last) first##R3##last
|
---|
408 | #endif
|
---|
409 |
|
---|
410 | /** @def CTX_MID_Z
|
---|
411 | * Adds the current context as a middle name of an identifier name, combining RC
|
---|
412 | * and R0 into RZ.
|
---|
413 | * The middle name thus is either R3 or RZ.
|
---|
414 | *
|
---|
415 | * This is macro should only be used in shared code to avoid a forrest of ifdefs.
|
---|
416 | * @param first First name.
|
---|
417 | * @param last Surname.
|
---|
418 | */
|
---|
419 | #ifdef IN_RING3
|
---|
420 | # define CTX_MID_Z(first, last) first##R3##last
|
---|
421 | #else
|
---|
422 | # define CTX_MID_Z(first, last) first##RZ##last
|
---|
423 | #endif
|
---|
424 |
|
---|
425 |
|
---|
426 | /** @def R3STRING
|
---|
427 | * A macro which in GC and R0 will return a dummy string while in R3 it will return
|
---|
428 | * the parameter.
|
---|
429 | *
|
---|
430 | * This is typically used to wrap description strings in structures shared
|
---|
431 | * between R3, R0 and/or GC. The intention is to avoid the \#ifdef IN_RING3 mess.
|
---|
432 | *
|
---|
433 | * @param pR3String The R3 string. Only referenced in R3.
|
---|
434 | * @see R0STRING and GCSTRING
|
---|
435 | */
|
---|
436 | #ifdef IN_RING3
|
---|
437 | # define R3STRING(pR3String) (pR3String)
|
---|
438 | #else
|
---|
439 | # define R3STRING(pR3String) ("<R3_STRING>")
|
---|
440 | #endif
|
---|
441 |
|
---|
442 | /** @def R0STRING
|
---|
443 | * A macro which in GC and R3 will return a dummy string while in R0 it will return
|
---|
444 | * the parameter.
|
---|
445 | *
|
---|
446 | * This is typically used to wrap description strings in structures shared
|
---|
447 | * between R3, R0 and/or GC. The intention is to avoid the \#ifdef IN_RING0 mess.
|
---|
448 | *
|
---|
449 | * @param pR0String The R0 string. Only referenced in R0.
|
---|
450 | * @see R3STRING and GCSTRING
|
---|
451 | */
|
---|
452 | #ifdef IN_RING0
|
---|
453 | # define R0STRING(pR0String) (pR0String)
|
---|
454 | #else
|
---|
455 | # define R0STRING(pR0String) ("<R0_STRING>")
|
---|
456 | #endif
|
---|
457 |
|
---|
458 | /** @def RCSTRING
|
---|
459 | * A macro which in R3 and R0 will return a dummy string while in RC it will return
|
---|
460 | * the parameter.
|
---|
461 | *
|
---|
462 | * This is typically used to wrap description strings in structures shared
|
---|
463 | * between R3, R0 and/or RC. The intention is to avoid the \#ifdef IN_RC mess.
|
---|
464 | *
|
---|
465 | * @param pR0String The RC string. Only referenced in RC.
|
---|
466 | * @see R3STRING, R0STRING
|
---|
467 | */
|
---|
468 | #ifdef IN_GC
|
---|
469 | # define RCSTRING(pRCString) (pRCString)
|
---|
470 | #else
|
---|
471 | # define RCSTRING(pRCString) ("<RC_STRING>")
|
---|
472 | #endif
|
---|
473 |
|
---|
474 |
|
---|
475 | /** @def RTCALL
|
---|
476 | * The standard calling convention for the Runtime interfaces.
|
---|
477 | */
|
---|
478 | #ifdef _MSC_VER
|
---|
479 | # define RTCALL __cdecl
|
---|
480 | #elif defined(__GNUC__) && defined(IN_RING0) && !(defined(RT_OS_OS2) || defined(RT_ARCH_AMD64)) /* the latter is kernel/gcc */
|
---|
481 | # define RTCALL __attribute__((cdecl,regparm(0)))
|
---|
482 | #else
|
---|
483 | # define RTCALL
|
---|
484 | #endif
|
---|
485 |
|
---|
486 | /** @def RT_NO_THROW
|
---|
487 | * How to express that a function doesn't throw C++ exceptions
|
---|
488 | * and the compiler can thus save itself the bother of trying
|
---|
489 | * to catch any of them. Put this between the closing parenthesis
|
---|
490 | * and the semicolon in function prototypes (and implementation if C++).
|
---|
491 | */
|
---|
492 | #if defined(__cplusplus) \
|
---|
493 | && ( (defined(_MSC_VER) && defined(_CPPUNWIND)) \
|
---|
494 | || (defined(__GNUC__) && defined(__EXCEPTIONS)))
|
---|
495 | # define RT_NO_THROW throw()
|
---|
496 | #else
|
---|
497 | # define RT_NO_THROW
|
---|
498 | #endif
|
---|
499 |
|
---|
500 | /** @def DECLEXPORT
|
---|
501 | * How to declare an exported function.
|
---|
502 | * @param type The return type of the function declaration.
|
---|
503 | */
|
---|
504 | #if defined(_MSC_VER) || defined(RT_OS_OS2)
|
---|
505 | # define DECLEXPORT(type) __declspec(dllexport) type
|
---|
506 | #elif defined(RT_USE_VISIBILITY_DEFAULT)
|
---|
507 | # define DECLEXPORT(type) __attribute__((visibility("default"))) type
|
---|
508 | #else
|
---|
509 | # define DECLEXPORT(type) type
|
---|
510 | #endif
|
---|
511 |
|
---|
512 | /** @def DECLIMPORT
|
---|
513 | * How to declare an imported function.
|
---|
514 | * @param type The return type of the function declaration.
|
---|
515 | */
|
---|
516 | #if defined(_MSC_VER) || (defined(RT_OS_OS2) && !defined(__IBMC__) && !defined(__IBMCPP__))
|
---|
517 | # define DECLIMPORT(type) __declspec(dllimport) type
|
---|
518 | #else
|
---|
519 | # define DECLIMPORT(type) type
|
---|
520 | #endif
|
---|
521 |
|
---|
522 | /** @def DECLHIDDEN
|
---|
523 | * How to declare a non-exported function or variable.
|
---|
524 | * @param type The return type of the function or the data type of the variable.
|
---|
525 | */
|
---|
526 | #if defined(RT_OS_OS2) || defined(RT_OS_WINDOWS) || !defined(RT_USE_VISIBILITY_HIDDEN)
|
---|
527 | # define DECLHIDDEN(type) type
|
---|
528 | #else
|
---|
529 | # define DECLHIDDEN(type) __attribute__((visibility("hidden"))) type
|
---|
530 | #endif
|
---|
531 |
|
---|
532 | /** @def DECLASM
|
---|
533 | * How to declare an internal assembly function.
|
---|
534 | * @param type The return type of the function declaration.
|
---|
535 | */
|
---|
536 | #ifdef __cplusplus
|
---|
537 | # ifdef _MSC_VER
|
---|
538 | # define DECLASM(type) extern "C" type __cdecl
|
---|
539 | # else
|
---|
540 | # define DECLASM(type) extern "C" type
|
---|
541 | # endif
|
---|
542 | #else
|
---|
543 | # ifdef _MSC_VER
|
---|
544 | # define DECLASM(type) type __cdecl
|
---|
545 | # else
|
---|
546 | # define DECLASM(type) type
|
---|
547 | # endif
|
---|
548 | #endif
|
---|
549 |
|
---|
550 | /** @def DECLASMTYPE
|
---|
551 | * How to declare an internal assembly function type.
|
---|
552 | * @param type The return type of the function.
|
---|
553 | */
|
---|
554 | #ifdef _MSC_VER
|
---|
555 | # define DECLASMTYPE(type) type __cdecl
|
---|
556 | #else
|
---|
557 | # define DECLASMTYPE(type) type
|
---|
558 | #endif
|
---|
559 |
|
---|
560 | /** @def DECLNORETURN
|
---|
561 | * How to declare a function which does not return.
|
---|
562 | * @note: This macro can be combined with other macros, for example
|
---|
563 | * @code
|
---|
564 | * EMR3DECL(DECLNORETURN(void)) foo(void);
|
---|
565 | * @endcode
|
---|
566 | */
|
---|
567 | #ifdef _MSC_VER
|
---|
568 | # define DECLNORETURN(type) __declspec(noreturn) type
|
---|
569 | #elif defined(__GNUC__)
|
---|
570 | # define DECLNORETURN(type) __attribute__((noreturn)) type
|
---|
571 | #else
|
---|
572 | # define DECLNORETURN(type) type
|
---|
573 | #endif
|
---|
574 |
|
---|
575 | /** @def DECLCALLBACK
|
---|
576 | * How to declare an call back function type.
|
---|
577 | * @param type The return type of the function declaration.
|
---|
578 | */
|
---|
579 | #define DECLCALLBACK(type) type RTCALL
|
---|
580 |
|
---|
581 | /** @def DECLCALLBACKPTR
|
---|
582 | * How to declare an call back function pointer.
|
---|
583 | * @param type The return type of the function declaration.
|
---|
584 | * @param name The name of the variable member.
|
---|
585 | */
|
---|
586 | #define DECLCALLBACKPTR(type, name) type (RTCALL * name)
|
---|
587 |
|
---|
588 | /** @def DECLCALLBACKMEMBER
|
---|
589 | * How to declare an call back function pointer member.
|
---|
590 | * @param type The return type of the function declaration.
|
---|
591 | * @param name The name of the struct/union/class member.
|
---|
592 | */
|
---|
593 | #define DECLCALLBACKMEMBER(type, name) type (RTCALL * name)
|
---|
594 |
|
---|
595 | /** @def DECLR3CALLBACKMEMBER
|
---|
596 | * How to declare an call back function pointer member - R3 Ptr.
|
---|
597 | * @param type The return type of the function declaration.
|
---|
598 | * @param name The name of the struct/union/class member.
|
---|
599 | * @param args The argument list enclosed in parentheses.
|
---|
600 | */
|
---|
601 | #ifdef IN_RING3
|
---|
602 | # define DECLR3CALLBACKMEMBER(type, name, args) type (RTCALL * name) args
|
---|
603 | #else
|
---|
604 | # define DECLR3CALLBACKMEMBER(type, name, args) RTR3PTR name
|
---|
605 | #endif
|
---|
606 |
|
---|
607 | /** @def DECLRCCALLBACKMEMBER
|
---|
608 | * How to declare an call back function pointer member - RC Ptr.
|
---|
609 | * @param type The return type of the function declaration.
|
---|
610 | * @param name The name of the struct/union/class member.
|
---|
611 | * @param args The argument list enclosed in parentheses.
|
---|
612 | */
|
---|
613 | #ifdef IN_GC
|
---|
614 | # define DECLRCCALLBACKMEMBER(type, name, args) type (RTCALL * name) args
|
---|
615 | #else
|
---|
616 | # define DECLRCCALLBACKMEMBER(type, name, args) RTRCPTR name
|
---|
617 | #endif
|
---|
618 |
|
---|
619 | /** @def DECLR0CALLBACKMEMBER
|
---|
620 | * How to declare an call back function pointer member - R0 Ptr.
|
---|
621 | * @param type The return type of the function declaration.
|
---|
622 | * @param name The name of the struct/union/class member.
|
---|
623 | * @param args The argument list enclosed in parentheses.
|
---|
624 | */
|
---|
625 | #ifdef IN_RING0
|
---|
626 | # define DECLR0CALLBACKMEMBER(type, name, args) type (RTCALL * name) args
|
---|
627 | #else
|
---|
628 | # define DECLR0CALLBACKMEMBER(type, name, args) RTR0PTR name
|
---|
629 | #endif
|
---|
630 |
|
---|
631 | /** @def DECLINLINE
|
---|
632 | * How to declare a function as inline.
|
---|
633 | * @param type The return type of the function declaration.
|
---|
634 | * @remarks Don't use this macro on C++ methods.
|
---|
635 | */
|
---|
636 | #ifdef __GNUC__
|
---|
637 | # define DECLINLINE(type) static __inline__ type
|
---|
638 | #elif defined(__cplusplus)
|
---|
639 | # define DECLINLINE(type) inline type
|
---|
640 | #elif defined(_MSC_VER)
|
---|
641 | # define DECLINLINE(type) _inline type
|
---|
642 | #elif defined(__IBMC__)
|
---|
643 | # define DECLINLINE(type) _Inline type
|
---|
644 | #else
|
---|
645 | # define DECLINLINE(type) inline type
|
---|
646 | #endif
|
---|
647 |
|
---|
648 |
|
---|
649 | /** @def IN_RT_STATIC
|
---|
650 | * Used to inidicate whether we're linking against a static IPRT
|
---|
651 | * or not. The IPRT symbols will be declared as hidden (if
|
---|
652 | * supported). Note that this define has no effect without setting
|
---|
653 | * IN_RT_R0, IN_RT_R3 or IN_RT_GC indicators are set first.
|
---|
654 | */
|
---|
655 |
|
---|
656 | /** @def IN_RT_R0
|
---|
657 | * Used to indicate whether we're inside the same link module as
|
---|
658 | * the HC Ring-0 Runtime Library.
|
---|
659 | */
|
---|
660 | /** @def RTR0DECL(type)
|
---|
661 | * Runtime Library HC Ring-0 export or import declaration.
|
---|
662 | * @param type The return type of the function declaration.
|
---|
663 | */
|
---|
664 | #ifdef IN_RT_R0
|
---|
665 | # ifdef IN_RT_STATIC
|
---|
666 | # define RTR0DECL(type) DECLHIDDEN(type) RTCALL
|
---|
667 | # else
|
---|
668 | # define RTR0DECL(type) DECLEXPORT(type) RTCALL
|
---|
669 | # endif
|
---|
670 | #else
|
---|
671 | # define RTR0DECL(type) DECLIMPORT(type) RTCALL
|
---|
672 | #endif
|
---|
673 |
|
---|
674 | /** @def IN_RT_R3
|
---|
675 | * Used to indicate whether we're inside the same link module as
|
---|
676 | * the HC Ring-3 Runtime Library.
|
---|
677 | */
|
---|
678 | /** @def RTR3DECL(type)
|
---|
679 | * Runtime Library HC Ring-3 export or import declaration.
|
---|
680 | * @param type The return type of the function declaration.
|
---|
681 | */
|
---|
682 | #ifdef IN_RT_R3
|
---|
683 | # ifdef IN_RT_STATIC
|
---|
684 | # define RTR3DECL(type) DECLHIDDEN(type) RTCALL
|
---|
685 | # else
|
---|
686 | # define RTR3DECL(type) DECLEXPORT(type) RTCALL
|
---|
687 | # endif
|
---|
688 | #else
|
---|
689 | # define RTR3DECL(type) DECLIMPORT(type) RTCALL
|
---|
690 | #endif
|
---|
691 |
|
---|
692 | /** @def IN_RT_GC
|
---|
693 | * Used to indicate whether we're inside the same link module as
|
---|
694 | * the GC Runtime Library.
|
---|
695 | */
|
---|
696 | /** @def RTGCDECL(type)
|
---|
697 | * Runtime Library HC Ring-3 export or import declaration.
|
---|
698 | * @param type The return type of the function declaration.
|
---|
699 | */
|
---|
700 | #ifdef IN_RT_GC
|
---|
701 | # ifdef IN_RT_STATIC
|
---|
702 | # define RTGCDECL(type) DECLHIDDEN(type) RTCALL
|
---|
703 | # else
|
---|
704 | # define RTGCDECL(type) DECLEXPORT(type) RTCALL
|
---|
705 | # endif
|
---|
706 | #else
|
---|
707 | # define RTGCDECL(type) DECLIMPORT(type) RTCALL
|
---|
708 | #endif
|
---|
709 |
|
---|
710 | /** @def RTDECL(type)
|
---|
711 | * Runtime Library export or import declaration.
|
---|
712 | * Functions declared using this macro exists in all contexts.
|
---|
713 | * @param type The return type of the function declaration.
|
---|
714 | */
|
---|
715 | #if defined(IN_RT_R3) || defined(IN_RT_GC) || defined(IN_RT_R0)
|
---|
716 | # ifdef IN_RT_STATIC
|
---|
717 | # define RTDECL(type) DECLHIDDEN(type) RTCALL
|
---|
718 | # else
|
---|
719 | # define RTDECL(type) DECLEXPORT(type) RTCALL
|
---|
720 | # endif
|
---|
721 | #else
|
---|
722 | # define RTDECL(type) DECLIMPORT(type) RTCALL
|
---|
723 | #endif
|
---|
724 |
|
---|
725 | /** @def RTDATADECL(type)
|
---|
726 | * Runtime Library export or import declaration.
|
---|
727 | * Data declared using this macro exists in all contexts.
|
---|
728 | * @param type The return type of the function declaration.
|
---|
729 | */
|
---|
730 | #if defined(IN_RT_R3) || defined(IN_RT_GC) || defined(IN_RT_R0)
|
---|
731 | # ifdef IN_RT_STATIC
|
---|
732 | # define RTDATADECL(type) DECLHIDDEN(type)
|
---|
733 | # else
|
---|
734 | # define RTDATADECL(type) DECLEXPORT(type)
|
---|
735 | # endif
|
---|
736 | #else
|
---|
737 | # define RTDATADECL(type) DECLIMPORT(type)
|
---|
738 | #endif
|
---|
739 |
|
---|
740 |
|
---|
741 | /** @def RT_NOCRT
|
---|
742 | * Symbol name wrapper for the No-CRT bits.
|
---|
743 | *
|
---|
744 | * In order to coexist in the same process as other CRTs, we need to
|
---|
745 | * decorate the symbols such that they don't conflict the ones in the
|
---|
746 | * other CRTs. The result of such conflicts / duplicate symbols can
|
---|
747 | * confuse the dynamic loader on unix like systems.
|
---|
748 | *
|
---|
749 | * Define RT_WITHOUT_NOCRT_WRAPPERS to drop the wrapping.
|
---|
750 | * Define RT_WITHOUT_NOCRT_WRAPPER_ALIASES to drop the aliases to the
|
---|
751 | * wrapped names.
|
---|
752 | */
|
---|
753 | /** @def RT_NOCRT_STR
|
---|
754 | * Same as RT_NOCRT only it'll return a double quoted string of the result.
|
---|
755 | */
|
---|
756 | #ifndef RT_WITHOUT_NOCRT_WRAPPERS
|
---|
757 | # define RT_NOCRT(name) nocrt_ ## name
|
---|
758 | # define RT_NOCRT_STR(name) "nocrt_" # name
|
---|
759 | #else
|
---|
760 | # define RT_NOCRT(name) name
|
---|
761 | # define RT_NOCRT_STR(name) #name
|
---|
762 | #endif
|
---|
763 |
|
---|
764 |
|
---|
765 |
|
---|
766 | /** @def RT_LIKELY
|
---|
767 | * Give the compiler a hint that an expression is very likely to hold true.
|
---|
768 | *
|
---|
769 | * Some compilers support explicit branch prediction so that the CPU backend
|
---|
770 | * can hint the processor and also so that code blocks can be reordered such
|
---|
771 | * that the predicted path sees a more linear flow, thus improving cache
|
---|
772 | * behaviour, etc.
|
---|
773 | *
|
---|
774 | * IPRT provides the macros RT_LIKELY() and RT_UNLIKELY() as a way to utilize
|
---|
775 | * this compiler feature when present.
|
---|
776 | *
|
---|
777 | * A few notes about the usage:
|
---|
778 | *
|
---|
779 | * - Generally, use RT_UNLIKELY() with error condition checks (unless you
|
---|
780 | * have some _strong_ reason to do otherwise, in which case document it),
|
---|
781 | * and/or RT_LIKELY() with success condition checks, assuming you want
|
---|
782 | * to optimize for the success path.
|
---|
783 | *
|
---|
784 | * - Other than that, if you don't know the likelihood of a test succeeding
|
---|
785 | * from empirical or other 'hard' evidence, don't make predictions unless
|
---|
786 | * you happen to be a Dirk Gently.
|
---|
787 | *
|
---|
788 | * - These macros are meant to be used in places that get executed a lot. It
|
---|
789 | * is wasteful to make predictions in code that is executed seldomly (e.g.
|
---|
790 | * at subsystem initialization time) as the basic block reording that this
|
---|
791 | * affecs can often generate larger code.
|
---|
792 | *
|
---|
793 | * - Note that RT_SUCCESS() and RT_FAILURE() already makes use of RT_LIKELY()
|
---|
794 | * and RT_UNLIKELY(). Should you wish for prediction free status checks,
|
---|
795 | * use the RT_SUCCESS_NP() and RT_FAILURE_NP() macros instead.
|
---|
796 | *
|
---|
797 | *
|
---|
798 | * @returns the boolean result of the expression.
|
---|
799 | * @param expr The expression that's very likely to be true.
|
---|
800 | * @see RT_UNLIKELY
|
---|
801 | */
|
---|
802 | /** @def RT_UNLIKELY
|
---|
803 | * Give the compiler a hint that an expression is highly unlikely hold true.
|
---|
804 | *
|
---|
805 | * See the usage instructions give in the RT_LIKELY() docs.
|
---|
806 | *
|
---|
807 | * @returns the boolean result of the expression.
|
---|
808 | * @param expr The expression that's very unlikely to be true.
|
---|
809 | * @see RT_LIKELY
|
---|
810 | */
|
---|
811 | #if defined(__GNUC__)
|
---|
812 | # if __GNUC__ >= 3
|
---|
813 | # define RT_LIKELY(expr) __builtin_expect(!!(expr), 1)
|
---|
814 | # define RT_UNLIKELY(expr) __builtin_expect(!!(expr), 0)
|
---|
815 | # else
|
---|
816 | # define RT_LIKELY(expr) (expr)
|
---|
817 | # define RT_UNLIKELY(expr) (expr)
|
---|
818 | # endif
|
---|
819 | #else
|
---|
820 | # define RT_LIKELY(expr) (expr)
|
---|
821 | # define RT_UNLIKELY(expr) (expr)
|
---|
822 | #endif
|
---|
823 |
|
---|
824 |
|
---|
825 | /** @def RT_BIT
|
---|
826 | * Make a bitmask for one integer sized bit.
|
---|
827 | * @param bit Bit number.
|
---|
828 | */
|
---|
829 | #define RT_BIT(bit) (1U << (bit))
|
---|
830 |
|
---|
831 | /** @def RT_BIT_32
|
---|
832 | * Make a 32-bit bitmask for one bit.
|
---|
833 | * @param bit Bit number.
|
---|
834 | */
|
---|
835 | #define RT_BIT_32(bit) (UINT32_C(1) << (bit))
|
---|
836 |
|
---|
837 | /** @def RT_BIT_64
|
---|
838 | * Make a 64-bit bitmask for one bit.
|
---|
839 | * @param bit Bit number.
|
---|
840 | */
|
---|
841 | #define RT_BIT_64(bit) (UINT64_C(1) << (bit))
|
---|
842 |
|
---|
843 | /** @def RT_ALIGN
|
---|
844 | * Align macro.
|
---|
845 | * @param u Value to align.
|
---|
846 | * @param uAlignment The alignment. Power of two!
|
---|
847 | *
|
---|
848 | * @remark Be extremely careful when using this macro with type which sizeof != sizeof int.
|
---|
849 | * When possible use any of the other RT_ALIGN_* macros. And when that's not
|
---|
850 | * possible, make 101% sure that uAlignment is specified with a right sized type.
|
---|
851 | *
|
---|
852 | * Specifying an unsigned 32-bit alignment constant with a 64-bit value will give
|
---|
853 | * you a 32-bit return value!
|
---|
854 | *
|
---|
855 | * In short: Don't use this macro. Use RT_ALIGN_T() instead.
|
---|
856 | */
|
---|
857 | #define RT_ALIGN(u, uAlignment) ( ((u) + ((uAlignment) - 1)) & ~((uAlignment) - 1) )
|
---|
858 |
|
---|
859 | /** @def RT_ALIGN_T
|
---|
860 | * Align macro.
|
---|
861 | * @param u Value to align.
|
---|
862 | * @param uAlignment The alignment. Power of two!
|
---|
863 | * @param type Integer type to use while aligning.
|
---|
864 | * @remark This macro is the prefered alignment macro, it doesn't have any of the pitfalls RT_ALIGN has.
|
---|
865 | */
|
---|
866 | #define RT_ALIGN_T(u, uAlignment, type) ( ((type)(u) + ((uAlignment) - 1)) & ~(type)((uAlignment) - 1) )
|
---|
867 |
|
---|
868 | /** @def RT_ALIGN_32
|
---|
869 | * Align macro for a 32-bit value.
|
---|
870 | * @param u32 Value to align.
|
---|
871 | * @param uAlignment The alignment. Power of two!
|
---|
872 | */
|
---|
873 | #define RT_ALIGN_32(u32, uAlignment) RT_ALIGN_T(u32, uAlignment, uint32_t)
|
---|
874 |
|
---|
875 | /** @def RT_ALIGN_64
|
---|
876 | * Align macro for a 64-bit value.
|
---|
877 | * @param u64 Value to align.
|
---|
878 | * @param uAlignment The alignment. Power of two!
|
---|
879 | */
|
---|
880 | #define RT_ALIGN_64(u64, uAlignment) RT_ALIGN_T(u64, uAlignment, uint64_t)
|
---|
881 |
|
---|
882 | /** @def RT_ALIGN_Z
|
---|
883 | * Align macro for size_t.
|
---|
884 | * @param cb Value to align.
|
---|
885 | * @param uAlignment The alignment. Power of two!
|
---|
886 | */
|
---|
887 | #define RT_ALIGN_Z(cb, uAlignment) RT_ALIGN_T(cb, uAlignment, size_t)
|
---|
888 |
|
---|
889 | /** @def RT_ALIGN_P
|
---|
890 | * Align macro for pointers.
|
---|
891 | * @param pv Value to align.
|
---|
892 | * @param uAlignment The alignment. Power of two!
|
---|
893 | */
|
---|
894 | #define RT_ALIGN_P(pv, uAlignment) RT_ALIGN_PT(pv, uAlignment, void *)
|
---|
895 |
|
---|
896 | /** @def RT_ALIGN_PT
|
---|
897 | * Align macro for pointers with type cast.
|
---|
898 | * @param u Value to align.
|
---|
899 | * @param uAlignment The alignment. Power of two!
|
---|
900 | * @param CastType The type to cast the result to.
|
---|
901 | */
|
---|
902 | #define RT_ALIGN_PT(u, uAlignment, CastType) ((CastType)RT_ALIGN_T(u, uAlignment, uintptr_t))
|
---|
903 |
|
---|
904 | /** @def RT_ALIGN_R3PT
|
---|
905 | * Align macro for ring-3 pointers with type cast.
|
---|
906 | * @param u Value to align.
|
---|
907 | * @param uAlignment The alignment. Power of two!
|
---|
908 | * @param CastType The type to cast the result to.
|
---|
909 | */
|
---|
910 | #define RT_ALIGN_R3PT(u, uAlignment, CastType) ((CastType)RT_ALIGN_T(u, uAlignment, RTR3UINTPTR))
|
---|
911 |
|
---|
912 | /** @def RT_ALIGN_R0PT
|
---|
913 | * Align macro for ring-0 pointers with type cast.
|
---|
914 | * @param u Value to align.
|
---|
915 | * @param uAlignment The alignment. Power of two!
|
---|
916 | * @param CastType The type to cast the result to.
|
---|
917 | */
|
---|
918 | #define RT_ALIGN_R0PT(u, uAlignment, CastType) ((CastType)RT_ALIGN_T(u, uAlignment, RTR0UINTPTR))
|
---|
919 |
|
---|
920 | /** @def RT_ALIGN_GCPT
|
---|
921 | * Align macro for GC pointers with type cast.
|
---|
922 | * @param u Value to align.
|
---|
923 | * @param uAlignment The alignment. Power of two!
|
---|
924 | * @param CastType The type to cast the result to.
|
---|
925 | */
|
---|
926 | #define RT_ALIGN_GCPT(u, uAlignment, CastType) ((CastType)RT_ALIGN_T(u, uAlignment, RTGCUINTPTR))
|
---|
927 |
|
---|
928 |
|
---|
929 | /** @def RT_OFFSETOF
|
---|
930 | * Our own special offsetof() variant, returns a signed result.
|
---|
931 | *
|
---|
932 | * This differs from the usual offsetof() in that it's not relying on builtin
|
---|
933 | * compiler stuff and thus can use variables in arrays the structure may
|
---|
934 | * contain. If in this usful to determin the sizes of structures ending
|
---|
935 | * with a variable length field.
|
---|
936 | *
|
---|
937 | * @returns offset into the structure of the specified member. signed.
|
---|
938 | * @param type Structure type.
|
---|
939 | * @param member Member.
|
---|
940 | */
|
---|
941 | #define RT_OFFSETOF(type, member) ( (int)(uintptr_t)&( ((type *)(void *)0)->member) )
|
---|
942 |
|
---|
943 | /** @def RT_UOFFSETOF
|
---|
944 | * Our own special offsetof() variant, returns an unsigned result.
|
---|
945 | *
|
---|
946 | * This differs from the usual offsetof() in that it's not relying on builtin
|
---|
947 | * compiler stuff and thus can use variables in arrays the structure may
|
---|
948 | * contain. If in this usful to determin the sizes of structures ending
|
---|
949 | * with a variable length field.
|
---|
950 | *
|
---|
951 | * @returns offset into the structure of the specified member. unsigned.
|
---|
952 | * @param type Structure type.
|
---|
953 | * @param member Member.
|
---|
954 | */
|
---|
955 | #define RT_UOFFSETOF(type, member) ( (uintptr_t)&( ((type *)(void *)0)->member) )
|
---|
956 |
|
---|
957 | /** @def RT_SIZEOFMEMB
|
---|
958 | * Get the size of a structure member.
|
---|
959 | *
|
---|
960 | * @returns size of the structure member.
|
---|
961 | * @param type Structure type.
|
---|
962 | * @param member Member.
|
---|
963 | */
|
---|
964 | #define RT_SIZEOFMEMB(type, member) ( sizeof(((type *)(void *)0)->member) )
|
---|
965 |
|
---|
966 | /** @def RT_ELEMENTS
|
---|
967 | * Calcs the number of elements in an array.
|
---|
968 | * @returns Element count.
|
---|
969 | * @param aArray Array in question.
|
---|
970 | */
|
---|
971 | #define RT_ELEMENTS(aArray) ( sizeof(aArray) / sizeof((aArray)[0]) )
|
---|
972 |
|
---|
973 | #ifdef RT_OS_OS2
|
---|
974 | /* Undefine RT_MAX since there is an unfortunate clash with the max
|
---|
975 | resource type define in os2.h. */
|
---|
976 | # undef RT_MAX
|
---|
977 | #endif
|
---|
978 |
|
---|
979 | /** @def RT_MAX
|
---|
980 | * Finds the maximum value.
|
---|
981 | * @returns The higher of the two.
|
---|
982 | * @param Value1 Value 1
|
---|
983 | * @param Value2 Value 2
|
---|
984 | */
|
---|
985 | #define RT_MAX(Value1, Value2) ((Value1) >= (Value2) ? (Value1) : (Value2))
|
---|
986 |
|
---|
987 | /** @def RT_MIN
|
---|
988 | * Finds the minimum value.
|
---|
989 | * @returns The lower of the two.
|
---|
990 | * @param Value1 Value 1
|
---|
991 | * @param Value2 Value 2
|
---|
992 | */
|
---|
993 | #define RT_MIN(Value1, Value2) ((Value1) <= (Value2) ? (Value1) : (Value2))
|
---|
994 |
|
---|
995 | /** @def RT_ABS
|
---|
996 | * Get the absolute (non-negative) value.
|
---|
997 | * @returns The absolute value of Value.
|
---|
998 | * @param Value The value.
|
---|
999 | */
|
---|
1000 | #define RT_ABS(Value) ((Value) >= 0 ? (Value) : -(Value))
|
---|
1001 |
|
---|
1002 | /** @def RT_LOWORD
|
---|
1003 | * Gets the low word (=uint16_t) of something. */
|
---|
1004 | #define RT_LOWORD(a) ((a) & 0xffff)
|
---|
1005 |
|
---|
1006 | /** @def RT_HIWORD
|
---|
1007 | * Gets the high word (=uint16_t) of a 32 bit something. */
|
---|
1008 | #define RT_HIWORD(a) ((a) >> 16)
|
---|
1009 |
|
---|
1010 | /** @def RT_LOBYTE
|
---|
1011 | * Gets the low byte of something. */
|
---|
1012 | #define RT_LOBYTE(a) ((a) & 0xff)
|
---|
1013 |
|
---|
1014 | /** @def RT_HIBYTE
|
---|
1015 | * Gets the low byte of a 16 bit something. */
|
---|
1016 | #define RT_HIBYTE(a) ((a) >> 8)
|
---|
1017 |
|
---|
1018 | /** @def RT_BYTE1
|
---|
1019 | * Gets first byte of something. */
|
---|
1020 | #define RT_BYTE1(a) ((a) & 0xff)
|
---|
1021 |
|
---|
1022 | /** @def RT_BYTE2
|
---|
1023 | * Gets second byte of something. */
|
---|
1024 | #define RT_BYTE2(a) (((a) >> 8) & 0xff)
|
---|
1025 |
|
---|
1026 | /** @def RT_BYTE3
|
---|
1027 | * Gets second byte of something. */
|
---|
1028 | #define RT_BYTE3(a) (((a) >> 16) & 0xff)
|
---|
1029 |
|
---|
1030 | /** @def RT_BYTE4
|
---|
1031 | * Gets fourth byte of something. */
|
---|
1032 | #define RT_BYTE4(a) (((a) >> 24) & 0xff)
|
---|
1033 |
|
---|
1034 |
|
---|
1035 | /** @def RT_MAKE_U64
|
---|
1036 | * Constructs a uint64_t value from two uint32_t values.
|
---|
1037 | */
|
---|
1038 | #define RT_MAKE_U64(Lo, Hi) ( (uint64_t)((uint32_t)(Hi)) << 32 | (uint32_t)(Lo) )
|
---|
1039 |
|
---|
1040 | /** @def RT_MAKE_U64_FROM_U16
|
---|
1041 | * Constructs a uint64_t value from four uint16_t values.
|
---|
1042 | */
|
---|
1043 | #define RT_MAKE_U64_FROM_U16(w0, w1, w2, w3) \
|
---|
1044 | ( (uint64_t)((uint16_t)(w3)) << 48 \
|
---|
1045 | | (uint64_t)((uint16_t)(w2)) << 32 \
|
---|
1046 | | (uint32_t)((uint16_t)(w1)) << 16 \
|
---|
1047 | | (uint16_t)(w0) )
|
---|
1048 |
|
---|
1049 | /** @def RT_MAKE_U64_FROM_U8
|
---|
1050 | * Constructs a uint64_t value from eight uint8_t values.
|
---|
1051 | */
|
---|
1052 | #define RT_MAKE_U64_FROM_U8(b0, b1, b2, b3, b4, b5, b6, b7) \
|
---|
1053 | ( (uint64_t)((uint8_t)(b7)) << 56 \
|
---|
1054 | | (uint64_t)((uint8_t)(b6)) << 48 \
|
---|
1055 | | (uint64_t)((uint8_t)(b5)) << 40 \
|
---|
1056 | | (uint64_t)((uint8_t)(b4)) << 32 \
|
---|
1057 | | (uint32_t)((uint8_t)(b3)) << 24 \
|
---|
1058 | | (uint32_t)((uint8_t)(b2)) << 16 \
|
---|
1059 | | (uint16_t)((uint8_t)(b1)) << 8 \
|
---|
1060 | | (uint8_t)(b0) )
|
---|
1061 |
|
---|
1062 | /** @def RT_MAKE_U32
|
---|
1063 | * Constructs a uint32_t value from two uint16_t values.
|
---|
1064 | */
|
---|
1065 | #define RT_MAKE_U32(Lo, Hi) ( (uint32_t)((uint16_t)(Hi)) << 16 | (uint16_t)(Lo) )
|
---|
1066 |
|
---|
1067 | /** @def RT_MAKE_U32_FROM_U8
|
---|
1068 | * Constructs a uint32_t value from four uint8_t values.
|
---|
1069 | */
|
---|
1070 | #define RT_MAKE_U32_FROM_U8(b0, b1, b2, b3) \
|
---|
1071 | ( (uint32_t)((uint8_t)(b3)) << 24 \
|
---|
1072 | | (uint32_t)((uint8_t)(b2)) << 16 \
|
---|
1073 | | (uint16_t)((uint8_t)(b1)) << 8 \
|
---|
1074 | | (uint8_t)(b0) )
|
---|
1075 |
|
---|
1076 | /** @def RT_MAKE_U16
|
---|
1077 | * Constructs a uint32_t value from two uint16_t values.
|
---|
1078 | */
|
---|
1079 | #define RT_MAKE_U16(Lo, Hi) ( (uint16_t)((uint8_t)(Hi)) << 8 | (uint8_t)(Lo) )
|
---|
1080 |
|
---|
1081 |
|
---|
1082 | /** @def RT_BSWAP_U64
|
---|
1083 | * Reverses the byte order of an uint64_t value. */
|
---|
1084 | #if 0
|
---|
1085 | # define RT_BSWAP_U64(u64) RT_BSWAP_U64_C(u64)
|
---|
1086 | #elif defined(__GNUC__)
|
---|
1087 | /** @todo use __builtin_constant_p? */
|
---|
1088 | # define RT_BSWAP_U64(u64) ASMByteSwapU64(u64)
|
---|
1089 | #else
|
---|
1090 | # define RT_BSWAP_U64(u64) ASMByteSwapU64(u64)
|
---|
1091 | #endif
|
---|
1092 |
|
---|
1093 | /** @def RT_BSWAP_U32
|
---|
1094 | * Reverses the byte order of an uint32_t value. */
|
---|
1095 | #if 0
|
---|
1096 | # define RT_BSWAP_U32(u32) RT_BSWAP_U32_C(u32)
|
---|
1097 | #elif defined(__GNUC__)
|
---|
1098 | /** @todo use __builtin_constant_p? */
|
---|
1099 | # define RT_BSWAP_U32(u32) ASMByteSwapU32(u32)
|
---|
1100 | #else
|
---|
1101 | # define RT_BSWAP_U32(u32) ASMByteSwapU32(u32)
|
---|
1102 | #endif
|
---|
1103 |
|
---|
1104 | /** @def RT_BSWAP_U16
|
---|
1105 | * Reverses the byte order of an uint16_t value. */
|
---|
1106 | #if 0
|
---|
1107 | # define RT_BSWAP_U16(u16) RT_BSWAP_U16_C(u16)
|
---|
1108 | #elif defined(__GNUC__)
|
---|
1109 | /** @todo use __builtin_constant_p? */
|
---|
1110 | # define RT_BSWAP_U16(u16) ASMByteSwapU16(u16)
|
---|
1111 | #else
|
---|
1112 | # define RT_BSWAP_U16(u16) ASMByteSwapU16(u16)
|
---|
1113 | #endif
|
---|
1114 |
|
---|
1115 |
|
---|
1116 | /** @def RT_BSWAP_U64_C
|
---|
1117 | * Reverses the byte order of an uint64_t constant. */
|
---|
1118 | #define RT_BSWAP_U64_C(u64) RT_MAKE_U64(RT_BSWAP_U32_C((u64) >> 32), RT_BSWAP_U32_C((u64) & 0xffffffff))
|
---|
1119 |
|
---|
1120 | /** @def RT_BSWAP_U32_C
|
---|
1121 | * Reverses the byte order of an uint32_t constant. */
|
---|
1122 | #define RT_BSWAP_U32_C(u32) (RT_BYTE4(u32) | (RT_BYTE3(u32) << 8) | (RT_BYTE2(u32) << 16) | (RT_BYTE1(u32) << 24))
|
---|
1123 |
|
---|
1124 | /** @def RT_BSWAP_U16_C
|
---|
1125 | * Reverses the byte order of an uint16_t constant. */
|
---|
1126 | #define RT_BSWAP_U16_C(u16) (RT_HIBYTE(u16) | (RT_LOBYTE(u16) << 8))
|
---|
1127 |
|
---|
1128 |
|
---|
1129 | /** @def RT_H2LE_U64
|
---|
1130 | * Converts an uint64_t value from host to little endian byte order. */
|
---|
1131 | #ifdef RT_BIG_ENDIAN
|
---|
1132 | # define RT_H2LE_U64(u64) RT_BSWAP_U64(u64)
|
---|
1133 | #else
|
---|
1134 | # define RT_H2LE_U64(u64) (u64)
|
---|
1135 | #endif
|
---|
1136 |
|
---|
1137 | /** @def RT_H2LE_U64_C
|
---|
1138 | * Converts an uint64_t constant from host to little endian byte order. */
|
---|
1139 | #ifdef RT_BIG_ENDIAN
|
---|
1140 | # define RT_H2LE_U64_C(u64) RT_BSWAP_U64_C(u64)
|
---|
1141 | #else
|
---|
1142 | # define RT_H2LE_U64_C(u64) (u64)
|
---|
1143 | #endif
|
---|
1144 |
|
---|
1145 | /** @def RT_H2LE_U32
|
---|
1146 | * Converts an uint32_t value from host to little endian byte order. */
|
---|
1147 | #ifdef RT_BIG_ENDIAN
|
---|
1148 | # define RT_H2LE_U32(u32) RT_BSWAP_U32(u32)
|
---|
1149 | #else
|
---|
1150 | # define RT_H2LE_U32(u32) (u32)
|
---|
1151 | #endif
|
---|
1152 |
|
---|
1153 | /** @def RT_H2LE_U32_C
|
---|
1154 | * Converts an uint32_t constant from host to little endian byte order. */
|
---|
1155 | #ifdef RT_BIG_ENDIAN
|
---|
1156 | # define RT_H2LE_U32_C(u32) RT_BSWAP_U32_C(u32)
|
---|
1157 | #else
|
---|
1158 | # define RT_H2LE_U32_C(u32) (u32)
|
---|
1159 | #endif
|
---|
1160 |
|
---|
1161 | /** @def RT_H2LE_U16
|
---|
1162 | * Converts an uint16_t value from host to little endian byte order. */
|
---|
1163 | #ifdef RT_BIG_ENDIAN
|
---|
1164 | # define RT_H2LE_U16(u16) RT_BSWAP_U16(u16)
|
---|
1165 | #else
|
---|
1166 | # define RT_H2LE_U16(u16) (u16)
|
---|
1167 | #endif
|
---|
1168 |
|
---|
1169 | /** @def RT_H2LE_U16_C
|
---|
1170 | * Converts an uint16_t constant from host to little endian byte order. */
|
---|
1171 | #ifdef RT_BIG_ENDIAN
|
---|
1172 | # define RT_H2LE_U16_C(u16) RT_BSWAP_U16_C(u16)
|
---|
1173 | #else
|
---|
1174 | # define RT_H2LE_U16_C(u16) (u16)
|
---|
1175 | #endif
|
---|
1176 |
|
---|
1177 |
|
---|
1178 | /** @def RT_LE2H_U64
|
---|
1179 | * Converts an uint64_t value from little endian to host byte order. */
|
---|
1180 | #ifdef RT_BIG_ENDIAN
|
---|
1181 | # define RT_LE2H_U64(u64) RT_BSWAP_U64(u64)
|
---|
1182 | #else
|
---|
1183 | # define RT_LE2H_U64(u64) (u64)
|
---|
1184 | #endif
|
---|
1185 |
|
---|
1186 | /** @def RT_LE2H_U64_C
|
---|
1187 | * Converts an uint64_t constant from little endian to host byte order. */
|
---|
1188 | #ifdef RT_BIG_ENDIAN
|
---|
1189 | # define RT_LE2H_U64_C(u64) RT_BSWAP_U64_C(u64)
|
---|
1190 | #else
|
---|
1191 | # define RT_LE2H_U64_C(u64) (u64)
|
---|
1192 | #endif
|
---|
1193 |
|
---|
1194 | /** @def RT_LE2H_U32
|
---|
1195 | * Converts an uint32_t value from little endian to host byte order. */
|
---|
1196 | #ifdef RT_BIG_ENDIAN
|
---|
1197 | # define RT_LE2H_U32(u32) RT_BSWAP_U32(u32)
|
---|
1198 | #else
|
---|
1199 | # define RT_LE2H_U32(u32) (u32)
|
---|
1200 | #endif
|
---|
1201 |
|
---|
1202 | /** @def RT_LE2H_U32_C
|
---|
1203 | * Converts an uint32_t constant from little endian to host byte order. */
|
---|
1204 | #ifdef RT_BIG_ENDIAN
|
---|
1205 | # define RT_LE2H_U32_C(u32) RT_BSWAP_U32_C(u32)
|
---|
1206 | #else
|
---|
1207 | # define RT_LE2H_U32_C(u32) (u32)
|
---|
1208 | #endif
|
---|
1209 |
|
---|
1210 | /** @def RT_LE2H_U16
|
---|
1211 | * Converts an uint16_t value from little endian to host byte order. */
|
---|
1212 | #ifdef RT_BIG_ENDIAN
|
---|
1213 | # define RT_LE2H_U16(u16) RT_BSWAP_U16(u16)
|
---|
1214 | #else
|
---|
1215 | # define RT_LE2H_U16(u16) (u16)
|
---|
1216 | #endif
|
---|
1217 |
|
---|
1218 | /** @def RT_LE2H_U16_C
|
---|
1219 | * Converts an uint16_t constant from little endian to host byte order. */
|
---|
1220 | #ifdef RT_BIG_ENDIAN
|
---|
1221 | # define RT_LE2H_U16_C(u16) RT_BSWAP_U16_C(u16)
|
---|
1222 | #else
|
---|
1223 | # define RT_LE2H_U16_C(u16) (u16)
|
---|
1224 | #endif
|
---|
1225 |
|
---|
1226 |
|
---|
1227 | /** @def RT_H2BE_U64
|
---|
1228 | * Converts an uint64_t value from host to big endian byte order. */
|
---|
1229 | #ifdef RT_BIG_ENDIAN
|
---|
1230 | # define RT_H2BE_U64(u64) (u64)
|
---|
1231 | #else
|
---|
1232 | # define RT_H2BE_U64(u64) RT_BSWAP_U64(u64)
|
---|
1233 | #endif
|
---|
1234 |
|
---|
1235 | /** @def RT_H2BE_U64_C
|
---|
1236 | * Converts an uint64_t constant from host to big endian byte order. */
|
---|
1237 | #ifdef RT_BIG_ENDIAN
|
---|
1238 | # define RT_H2BE_U64_C(u64) (u64)
|
---|
1239 | #else
|
---|
1240 | # define RT_H2BE_U64_C(u64) RT_BSWAP_U64_C(u64)
|
---|
1241 | #endif
|
---|
1242 |
|
---|
1243 | /** @def RT_H2BE_U32
|
---|
1244 | * Converts an uint32_t value from host to big endian byte order. */
|
---|
1245 | #ifdef RT_BIG_ENDIAN
|
---|
1246 | # define RT_H2BE_U32(u32) (u32)
|
---|
1247 | #else
|
---|
1248 | # define RT_H2BE_U32(u32) RT_BSWAP_U32(u32)
|
---|
1249 | #endif
|
---|
1250 |
|
---|
1251 | /** @def RT_H2BE_U32_C
|
---|
1252 | * Converts an uint32_t constant from host to big endian byte order. */
|
---|
1253 | #ifdef RT_BIG_ENDIAN
|
---|
1254 | # define RT_H2BE_U32_C(u32) (u32)
|
---|
1255 | #else
|
---|
1256 | # define RT_H2BE_U32_C(u32) RT_BSWAP_U32_C(u32)
|
---|
1257 | #endif
|
---|
1258 |
|
---|
1259 | /** @def RT_H2BE_U16
|
---|
1260 | * Converts an uint16_t value from host to big endian byte order. */
|
---|
1261 | #ifdef RT_BIG_ENDIAN
|
---|
1262 | # define RT_H2BE_U16(u16) (u16)
|
---|
1263 | #else
|
---|
1264 | # define RT_H2BE_U16(u16) RT_BSWAP_U16(u16)
|
---|
1265 | #endif
|
---|
1266 |
|
---|
1267 | /** @def RT_H2BE_U16_C
|
---|
1268 | * Converts an uint16_t constant from host to big endian byte order. */
|
---|
1269 | #ifdef RT_BIG_ENDIAN
|
---|
1270 | # define RT_H2BE_U16_C(u16) (u16)
|
---|
1271 | #else
|
---|
1272 | # define RT_H2BE_U16_C(u16) RT_BSWAP_U16_C(u16)
|
---|
1273 | #endif
|
---|
1274 |
|
---|
1275 | /** @def RT_BE2H_U64
|
---|
1276 | * Converts an uint64_t value from big endian to host byte order. */
|
---|
1277 | #ifdef RT_BIG_ENDIAN
|
---|
1278 | # define RT_BE2H_U64(u64) (u64)
|
---|
1279 | #else
|
---|
1280 | # define RT_BE2H_U64(u64) RT_BSWAP_U64(u64)
|
---|
1281 | #endif
|
---|
1282 |
|
---|
1283 | /** @def RT_BE2H_U64
|
---|
1284 | * Converts an uint64_t constant from big endian to host byte order. */
|
---|
1285 | #ifdef RT_BIG_ENDIAN
|
---|
1286 | # define RT_BE2H_U64_C(u64) (u64)
|
---|
1287 | #else
|
---|
1288 | # define RT_BE2H_U64_C(u64) RT_BSWAP_U64_C(u64)
|
---|
1289 | #endif
|
---|
1290 |
|
---|
1291 | /** @def RT_BE2H_U32
|
---|
1292 | * Converts an uint32_t value from big endian to host byte order. */
|
---|
1293 | #ifdef RT_BIG_ENDIAN
|
---|
1294 | # define RT_BE2H_U32(u32) (u32)
|
---|
1295 | #else
|
---|
1296 | # define RT_BE2H_U32(u32) RT_BSWAP_U32(u32)
|
---|
1297 | #endif
|
---|
1298 |
|
---|
1299 | /** @def RT_BE2H_U32_C
|
---|
1300 | * Converts an uint32_t value from big endian to host byte order. */
|
---|
1301 | #ifdef RT_BIG_ENDIAN
|
---|
1302 | # define RT_BE2H_U32_C(u32) (u32)
|
---|
1303 | #else
|
---|
1304 | # define RT_BE2H_U32_C(u32) RT_BSWAP_U32_C(u32)
|
---|
1305 | #endif
|
---|
1306 |
|
---|
1307 | /** @def RT_BE2H_U16
|
---|
1308 | * Converts an uint16_t value from big endian to host byte order. */
|
---|
1309 | #ifdef RT_BIG_ENDIAN
|
---|
1310 | # define RT_BE2H_U16(u16) (u16)
|
---|
1311 | #else
|
---|
1312 | # define RT_BE2H_U16(u16) RT_BSWAP_U16(u16)
|
---|
1313 | #endif
|
---|
1314 |
|
---|
1315 | /** @def RT_BE2H_U16_C
|
---|
1316 | * Converts an uint16_t constant from big endian to host byte order. */
|
---|
1317 | #ifdef RT_BIG_ENDIAN
|
---|
1318 | # define RT_BE2H_U16_C(u16) (u16)
|
---|
1319 | #else
|
---|
1320 | # define RT_BE2H_U16_C(u16) RT_BSWAP_U16_C(u16)
|
---|
1321 | #endif
|
---|
1322 |
|
---|
1323 |
|
---|
1324 | /** @def RT_H2N_U64
|
---|
1325 | * Converts an uint64_t value from host to network byte order. */
|
---|
1326 | #define RT_H2N_U64(u64) RT_H2BE_U64(u64)
|
---|
1327 |
|
---|
1328 | /** @def RT_H2N_U64_C
|
---|
1329 | * Converts an uint64_t constant from host to network byte order. */
|
---|
1330 | #define RT_H2N_U64_C(u64) RT_H2BE_U64_C(u64)
|
---|
1331 |
|
---|
1332 | /** @def RT_H2N_U32
|
---|
1333 | * Converts an uint32_t value from host to network byte order. */
|
---|
1334 | #define RT_H2N_U32(u32) RT_H2BE_U32(u32)
|
---|
1335 |
|
---|
1336 | /** @def RT_H2N_U32_C
|
---|
1337 | * Converts an uint32_t constant from host to network byte order. */
|
---|
1338 | #define RT_H2N_U32_C(u32) RT_H2BE_U32_C(u32)
|
---|
1339 |
|
---|
1340 | /** @def RT_H2N_U16
|
---|
1341 | * Converts an uint16_t value from host to network byte order. */
|
---|
1342 | #define RT_H2N_U16(u16) RT_H2BE_U16(u16)
|
---|
1343 |
|
---|
1344 | /** @def RT_H2N_U16_C
|
---|
1345 | * Converts an uint16_t constant from host to network byte order. */
|
---|
1346 | #define RT_H2N_U16_C(u16) RT_H2BE_U16_C(u16)
|
---|
1347 |
|
---|
1348 | /** @def RT_N2H_U64
|
---|
1349 | * Converts an uint64_t value from network to host byte order. */
|
---|
1350 | #define RT_N2H_U64(u64) RT_BE2H_U64(u64)
|
---|
1351 |
|
---|
1352 | /** @def RT_N2H_U64_C
|
---|
1353 | * Converts an uint64_t constant from network to host byte order. */
|
---|
1354 | #define RT_N2H_U64_C(u64) RT_BE2H_U64_C(u64)
|
---|
1355 |
|
---|
1356 | /** @def RT_N2H_U32
|
---|
1357 | * Converts an uint32_t value from network to host byte order. */
|
---|
1358 | #define RT_N2H_U32(u32) RT_BE2H_U32(u32)
|
---|
1359 |
|
---|
1360 | /** @def RT_N2H_U32_C
|
---|
1361 | * Converts an uint32_t constant from network to host byte order. */
|
---|
1362 | #define RT_N2H_U32_C(u32) RT_BE2H_U32_C(u32)
|
---|
1363 |
|
---|
1364 | /** @def RT_N2H_U16
|
---|
1365 | * Converts an uint16_t value from network to host byte order. */
|
---|
1366 | #define RT_N2H_U16(u16) RT_BE2H_U16(u16)
|
---|
1367 |
|
---|
1368 | /** @def RT_N2H_U16_C
|
---|
1369 | * Converts an uint16_t value from network to host byte order. */
|
---|
1370 | #define RT_N2H_U16_C(u16) RT_BE2H_U16_C(u16)
|
---|
1371 |
|
---|
1372 |
|
---|
1373 | /** @def RT_NO_DEPRECATED_MACROS
|
---|
1374 | * Define RT_NO_DEPRECATED_MACROS to not define deprecated macros.
|
---|
1375 | */
|
---|
1376 | #ifndef RT_NO_DEPRECATED_MACROS
|
---|
1377 | /** @copydoc RT_ELEMENTS
|
---|
1378 | * @deprecated use RT_ELEMENTS. */
|
---|
1379 | # define ELEMENTS(aArray) RT_ELEMENTS(aArray)
|
---|
1380 | #endif
|
---|
1381 |
|
---|
1382 |
|
---|
1383 | /*
|
---|
1384 | * The BSD sys/param.h + machine/param.h file is a major source of
|
---|
1385 | * namespace pollution. Kill off some of the worse ones unless we're
|
---|
1386 | * compiling kernel code.
|
---|
1387 | */
|
---|
1388 | #if defined(RT_OS_DARWIN) \
|
---|
1389 | && !defined(KERNEL) \
|
---|
1390 | && !defined(RT_NO_BSD_PARAM_H_UNDEFING) \
|
---|
1391 | && ( defined(_SYS_PARAM_H_) || defined(_I386_PARAM_H_) )
|
---|
1392 | /* sys/param.h: */
|
---|
1393 | # undef PSWP
|
---|
1394 | # undef PVM
|
---|
1395 | # undef PINOD
|
---|
1396 | # undef PRIBO
|
---|
1397 | # undef PVFS
|
---|
1398 | # undef PZERO
|
---|
1399 | # undef PSOCK
|
---|
1400 | # undef PWAIT
|
---|
1401 | # undef PLOCK
|
---|
1402 | # undef PPAUSE
|
---|
1403 | # undef PUSER
|
---|
1404 | # undef PRIMASK
|
---|
1405 | # undef MINBUCKET
|
---|
1406 | # undef MAXALLOCSAVE
|
---|
1407 | # undef FSHIFT
|
---|
1408 | # undef FSCALE
|
---|
1409 |
|
---|
1410 | /* i386/machine.h: */
|
---|
1411 | # undef ALIGN
|
---|
1412 | # undef ALIGNBYTES
|
---|
1413 | # undef DELAY
|
---|
1414 | # undef STATUS_WORD
|
---|
1415 | # undef USERMODE
|
---|
1416 | # undef BASEPRI
|
---|
1417 | # undef MSIZE
|
---|
1418 | # undef CLSIZE
|
---|
1419 | # undef CLSIZELOG2
|
---|
1420 | #endif
|
---|
1421 |
|
---|
1422 |
|
---|
1423 | /** @def NULL
|
---|
1424 | * NULL pointer.
|
---|
1425 | */
|
---|
1426 | #ifndef NULL
|
---|
1427 | # ifdef __cplusplus
|
---|
1428 | # define NULL 0
|
---|
1429 | # else
|
---|
1430 | # define NULL ((void*)0)
|
---|
1431 | # endif
|
---|
1432 | #endif
|
---|
1433 |
|
---|
1434 | /** @def NIL_OFFSET
|
---|
1435 | * NIL offset.
|
---|
1436 | * Whenever we use offsets instead of pointers to save space and relocation effort
|
---|
1437 | * NIL_OFFSET shall be used as the equivalent to NULL.
|
---|
1438 | */
|
---|
1439 | #define NIL_OFFSET (~0U)
|
---|
1440 |
|
---|
1441 | /** @def NOREF
|
---|
1442 | * Keeps the compiler from bitching about an unused parameters.
|
---|
1443 | */
|
---|
1444 | #define NOREF(var) (void)(var)
|
---|
1445 |
|
---|
1446 | /** @def Breakpoint
|
---|
1447 | * Emit a debug breakpoint instruction.
|
---|
1448 | *
|
---|
1449 | * Use this for instrumenting a debugging session only!
|
---|
1450 | * No comitted code shall use Breakpoint().
|
---|
1451 | */
|
---|
1452 | #ifdef __GNUC__
|
---|
1453 | # define Breakpoint() __asm__ __volatile__("int $3\n\t")
|
---|
1454 | #endif
|
---|
1455 | #ifdef _MSC_VER
|
---|
1456 | # define Breakpoint() __asm int 3
|
---|
1457 | #endif
|
---|
1458 | #if defined(__IBMC__) || defined(__IBMCPP__)
|
---|
1459 | # define Breakpoint() __interrupt(3)
|
---|
1460 | #endif
|
---|
1461 | #ifndef Breakpoint
|
---|
1462 | # error "This compiler is not supported!"
|
---|
1463 | #endif
|
---|
1464 |
|
---|
1465 |
|
---|
1466 | /** Size Constants
|
---|
1467 | * (Of course, these are binary computer terms, not SI.)
|
---|
1468 | * @{
|
---|
1469 | */
|
---|
1470 | /** 1 K (Kilo) (1 024). */
|
---|
1471 | #define _1K 0x00000400
|
---|
1472 | /** 4 K (Kilo) (4 096). */
|
---|
1473 | #define _4K 0x00001000
|
---|
1474 | /** 32 K (Kilo) (32 678). */
|
---|
1475 | #define _32K 0x00008000
|
---|
1476 | /** 64 K (Kilo) (65 536). */
|
---|
1477 | #define _64K 0x00010000
|
---|
1478 | /** 128 K (Kilo) (131 072). */
|
---|
1479 | #define _128K 0x00020000
|
---|
1480 | /** 256 K (Kilo) (262 144). */
|
---|
1481 | #define _256K 0x00040000
|
---|
1482 | /** 512 K (Kilo) (524 288). */
|
---|
1483 | #define _512K 0x00080000
|
---|
1484 | /** 1 M (Mega) (1 048 576). */
|
---|
1485 | #define _1M 0x00100000
|
---|
1486 | /** 2 M (Mega) (2 097 152). */
|
---|
1487 | #define _2M 0x00200000
|
---|
1488 | /** 4 M (Mega) (4 194 304). */
|
---|
1489 | #define _4M 0x00400000
|
---|
1490 | /** 1 G (Giga) (1 073 741 824). */
|
---|
1491 | #define _1G 0x40000000
|
---|
1492 | /** 2 G (Giga) (2 147 483 648). (32-bit) */
|
---|
1493 | #define _2G32 0x80000000U
|
---|
1494 | /** 2 G (Giga) (2 147 483 648). (64-bit) */
|
---|
1495 | #define _2G 0x0000000080000000LL
|
---|
1496 | /** 4 G (Giga) (4 294 967 296). */
|
---|
1497 | #define _4G 0x0000000100000000LL
|
---|
1498 | /** 1 T (Tera) (1 099 511 627 776). */
|
---|
1499 | #define _1T 0x0000010000000000LL
|
---|
1500 | /** 1 P (Peta) (1 125 899 906 842 624). */
|
---|
1501 | #define _1P 0x0004000000000000LL
|
---|
1502 | /** 1 E (Exa) (1 152 921 504 606 846 976). */
|
---|
1503 | #define _1E 0x1000000000000000LL
|
---|
1504 | /** 2 E (Exa) (2 305 843 009 213 693 952). */
|
---|
1505 | #define _2E 0x2000000000000000ULL
|
---|
1506 | /** @} */
|
---|
1507 |
|
---|
1508 | /** @def VALID_PTR
|
---|
1509 | * Pointer validation macro.
|
---|
1510 | * @param ptr
|
---|
1511 | */
|
---|
1512 | #if defined(RT_ARCH_AMD64)
|
---|
1513 | # ifdef IN_RING3
|
---|
1514 | # if defined(RT_OS_DARWIN) /* first 4GB is reserved for legacy kernel. */
|
---|
1515 | # define VALID_PTR(ptr) ( (uintptr_t)(ptr) >= _4G \
|
---|
1516 | && !((uintptr_t)(ptr) & 0xffff800000000000ULL) )
|
---|
1517 | # elif defined(RT_OS_SOLARIS) /* The kernel only used the top 2TB, but keep it simple. */
|
---|
1518 | # define VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x1000U >= 0x2000U \
|
---|
1519 | && ( ((uintptr_t)(ptr) & 0xffff800000000000ULL) == 0xffff800000000000ULL \
|
---|
1520 | || ((uintptr_t)(ptr) & 0xffff800000000000ULL) == 0) )
|
---|
1521 | # else
|
---|
1522 | # define VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x1000U >= 0x2000U \
|
---|
1523 | && !((uintptr_t)(ptr) & 0xffff800000000000ULL) )
|
---|
1524 | # endif
|
---|
1525 | # else /* !IN_RING3 */
|
---|
1526 | # define VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x1000U >= 0x2000U \
|
---|
1527 | && ( ((uintptr_t)(ptr) & 0xffff800000000000ULL) == 0xffff800000000000ULL \
|
---|
1528 | || ((uintptr_t)(ptr) & 0xffff800000000000ULL) == 0) )
|
---|
1529 | # endif /* !IN_RING3 */
|
---|
1530 | #elif defined(RT_ARCH_X86)
|
---|
1531 | # define VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x1000U >= 0x2000U )
|
---|
1532 | #else
|
---|
1533 | # error "Architecture identifier missing / not implemented."
|
---|
1534 | #endif
|
---|
1535 |
|
---|
1536 |
|
---|
1537 | /** @def VALID_PHYS32
|
---|
1538 | * 32 bits physical address validation macro.
|
---|
1539 | * @param Phys The RTGCPHYS address.
|
---|
1540 | */
|
---|
1541 | #define VALID_PHYS32(Phys) ( (uint64_t)(Phys) < (uint64_t)_4G )
|
---|
1542 |
|
---|
1543 | /** @def N_
|
---|
1544 | * The \#define N_ is used mark a string for translation. This is usable in
|
---|
1545 | * any part of the code, as it is only used by the tools that create message
|
---|
1546 | * catalogs. This macro is a no-op as far as the compiler and code generation
|
---|
1547 | * is concerned.
|
---|
1548 | *
|
---|
1549 | * If you want to both mark a string for translation and translate it, use _.
|
---|
1550 | */
|
---|
1551 | #define N_(s) (s)
|
---|
1552 |
|
---|
1553 | /** @def _
|
---|
1554 | * The \#define _ is used mark a string for translation and to translate it in
|
---|
1555 | * one step.
|
---|
1556 | *
|
---|
1557 | * If you want to only mark a string for translation, use N_.
|
---|
1558 | */
|
---|
1559 | #define _(s) gettext(s)
|
---|
1560 |
|
---|
1561 |
|
---|
1562 | /** @def __PRETTY_FUNCTION__
|
---|
1563 | * With GNU C we'd like to use the builtin __PRETTY_FUNCTION__, so define that for the other compilers.
|
---|
1564 | */
|
---|
1565 | #if !defined(__GNUC__) && !defined(__PRETTY_FUNCTION__)
|
---|
1566 | # define __PRETTY_FUNCTION__ __FUNCTION__
|
---|
1567 | #endif
|
---|
1568 |
|
---|
1569 |
|
---|
1570 | /** @def RT_STRICT
|
---|
1571 | * The \#define RT_STRICT controls whether or not assertions and other runtime checks
|
---|
1572 | * should be compiled in or not.
|
---|
1573 | *
|
---|
1574 | * If you want assertions which are not a subject to compile time options use
|
---|
1575 | * the AssertRelease*() flavors.
|
---|
1576 | */
|
---|
1577 | #if !defined(RT_STRICT) && defined(DEBUG)
|
---|
1578 | # define RT_STRICT
|
---|
1579 | #endif
|
---|
1580 |
|
---|
1581 | /** Source position. */
|
---|
1582 | #define RT_SRC_POS __FILE__, __LINE__, __PRETTY_FUNCTION__
|
---|
1583 |
|
---|
1584 | /** Source position declaration. */
|
---|
1585 | #define RT_SRC_POS_DECL const char *pszFile, unsigned iLine, const char *pszFunction
|
---|
1586 |
|
---|
1587 | /** Source position arguments. */
|
---|
1588 | #define RT_SRC_POS_ARGS pszFile, iLine, pszFunction
|
---|
1589 |
|
---|
1590 | /** @} */
|
---|
1591 |
|
---|
1592 |
|
---|
1593 | /** @defgroup grp_rt_cdefs_cpp Special Macros for C++
|
---|
1594 | * @ingroup grp_rt_cdefs
|
---|
1595 | * @{
|
---|
1596 | */
|
---|
1597 |
|
---|
1598 | #ifdef __cplusplus
|
---|
1599 |
|
---|
1600 | /** @def DECLEXPORT_CLASS
|
---|
1601 | * How to declare an exported class. Place this macro after the 'class'
|
---|
1602 | * keyword in the declaration of every class you want to export.
|
---|
1603 | *
|
---|
1604 | * @note It is necessary to use this macro even for inner classes declared
|
---|
1605 | * inside the already exported classes. This is a GCC specific requirement,
|
---|
1606 | * but it seems not to harm other compilers.
|
---|
1607 | */
|
---|
1608 | #if defined(_MSC_VER) || defined(RT_OS_OS2)
|
---|
1609 | # define DECLEXPORT_CLASS __declspec(dllexport)
|
---|
1610 | #elif defined(RT_USE_VISIBILITY_DEFAULT)
|
---|
1611 | # define DECLEXPORT_CLASS __attribute__((visibility("default")))
|
---|
1612 | #else
|
---|
1613 | # define DECLEXPORT_CLASS
|
---|
1614 | #endif
|
---|
1615 |
|
---|
1616 | /** @def DECLIMPORT_CLASS
|
---|
1617 | * How to declare an imported class Place this macro after the 'class'
|
---|
1618 | * keyword in the declaration of every class you want to export.
|
---|
1619 | *
|
---|
1620 | * @note It is necessary to use this macro even for inner classes declared
|
---|
1621 | * inside the already exported classes. This is a GCC specific requirement,
|
---|
1622 | * but it seems not to harm other compilers.
|
---|
1623 | */
|
---|
1624 | #if defined(_MSC_VER) || (defined(RT_OS_OS2) && !defined(__IBMC__) && !defined(__IBMCPP__))
|
---|
1625 | # define DECLIMPORT_CLASS __declspec(dllimport)
|
---|
1626 | #elif defined(RT_USE_VISIBILITY_DEFAULT)
|
---|
1627 | # define DECLIMPORT_CLASS __attribute__((visibility("default")))
|
---|
1628 | #else
|
---|
1629 | # define DECLIMPORT_CLASS
|
---|
1630 | #endif
|
---|
1631 |
|
---|
1632 | /** @def WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP
|
---|
1633 | * Macro to work around error C2593 of the not-so-smart MSVC 7.x ambiguity
|
---|
1634 | * resolver. The following snippet clearly demonstrates the code causing this
|
---|
1635 | * error:
|
---|
1636 | * @code
|
---|
1637 | * class A
|
---|
1638 | * {
|
---|
1639 | * public:
|
---|
1640 | * operator bool() const { return false; }
|
---|
1641 | * operator int*() const { return NULL; }
|
---|
1642 | * };
|
---|
1643 | * int main()
|
---|
1644 | * {
|
---|
1645 | * A a;
|
---|
1646 | * if (!a);
|
---|
1647 | * if (a && 0);
|
---|
1648 | * return 0;
|
---|
1649 | * }
|
---|
1650 | * @endcode
|
---|
1651 | * The code itself seems pretty valid to me and GCC thinks the same.
|
---|
1652 | *
|
---|
1653 | * This macro fixes the compiler error by explicitly overloading implicit
|
---|
1654 | * global operators !, && and || that take the given class instance as one of
|
---|
1655 | * their arguments.
|
---|
1656 | *
|
---|
1657 | * The best is to use this macro right after the class declaration.
|
---|
1658 | *
|
---|
1659 | * @note The macro expands to nothing for compilers other than MSVC.
|
---|
1660 | *
|
---|
1661 | * @param Cls Class to apply the workaround to
|
---|
1662 | */
|
---|
1663 | #if defined(_MSC_VER)
|
---|
1664 | # define WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP(Cls) \
|
---|
1665 | inline bool operator! (const Cls &that) { return !bool (that); } \
|
---|
1666 | inline bool operator&& (const Cls &that, bool b) { return bool (that) && b; } \
|
---|
1667 | inline bool operator|| (const Cls &that, bool b) { return bool (that) || b; } \
|
---|
1668 | inline bool operator&& (bool b, const Cls &that) { return b && bool (that); } \
|
---|
1669 | inline bool operator|| (bool b, const Cls &that) { return b || bool (that); }
|
---|
1670 | #else
|
---|
1671 | # define WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP(Cls)
|
---|
1672 | #endif
|
---|
1673 |
|
---|
1674 | /** @def WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP_TPL
|
---|
1675 | * Version of WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP for template classes.
|
---|
1676 | *
|
---|
1677 | * @param Tpl Name of the template class to apply the workaround to
|
---|
1678 | * @param ArgsDecl arguments of the template, as declared in |<>| after the
|
---|
1679 | * |template| keyword, including |<>|
|
---|
1680 | * @param Args arguments of the template, as specified in |<>| after the
|
---|
1681 | * template class name when using the, including |<>|
|
---|
1682 | *
|
---|
1683 | * Example:
|
---|
1684 | * @code
|
---|
1685 | * // template class declaration
|
---|
1686 | * template <class C>
|
---|
1687 | * class Foo { ... };
|
---|
1688 | * // applied workaround
|
---|
1689 | * WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP_TPL (Foo, <class C>, <C>)
|
---|
1690 | * @endcode
|
---|
1691 | */
|
---|
1692 | #if defined(_MSC_VER)
|
---|
1693 | # define WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP_TPL(Tpl, ArgsDecl, Args) \
|
---|
1694 | template ArgsDecl \
|
---|
1695 | inline bool operator! (const Tpl Args &that) { return !bool (that); } \
|
---|
1696 | template ArgsDecl \
|
---|
1697 | inline bool operator&& (const Tpl Args &that, bool b) { return bool (that) && b; } \
|
---|
1698 | template ArgsDecl \
|
---|
1699 | inline bool operator|| (const Tpl Args &that, bool b) { return bool (that) || b; } \
|
---|
1700 | template ArgsDecl \
|
---|
1701 | inline bool operator&& (bool b, const Tpl Args &that) { return b && bool (that); } \
|
---|
1702 | template ArgsDecl \
|
---|
1703 | inline bool operator|| (bool b, const Tpl Args &that) { return b || bool (that); }
|
---|
1704 | #else
|
---|
1705 | # define WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP_TPL(Tpl, ArgsDecl, Args)
|
---|
1706 | #endif
|
---|
1707 |
|
---|
1708 |
|
---|
1709 | /** @def DECLARE_CLS_COPY_CTOR_ASSIGN_NOOP
|
---|
1710 | * Declares the copy constructor and the assignment operation as inlined no-ops
|
---|
1711 | * (non-existent functions) for the given class. Use this macro inside the
|
---|
1712 | * private section if you want to effectively disable these operations for your
|
---|
1713 | * class.
|
---|
1714 | *
|
---|
1715 | * @param Cls class name to declare for
|
---|
1716 | */
|
---|
1717 |
|
---|
1718 | #define DECLARE_CLS_COPY_CTOR_ASSIGN_NOOP(Cls) \
|
---|
1719 | inline Cls (const Cls &); \
|
---|
1720 | inline Cls &operator= (const Cls &);
|
---|
1721 |
|
---|
1722 |
|
---|
1723 | /** @def DECLARE_CLS_NEW_DELETE_NOOP
|
---|
1724 | * Declares the new and delete operations as no-ops (non-existent functions)
|
---|
1725 | * for the given class. Use this macro inside the private section if you want
|
---|
1726 | * to effectively limit creating class instances on the stack only.
|
---|
1727 | *
|
---|
1728 | * @note The destructor of the given class must not be virtual, otherwise a
|
---|
1729 | * compile time error will occur. Note that this is not a drawback: having
|
---|
1730 | * the virtual destructor for a stack-based class is absolutely useless
|
---|
1731 | * (the real class of the stack-based instance is always known to the compiler
|
---|
1732 | * at compile time, so it will always call the correct destructor).
|
---|
1733 | *
|
---|
1734 | * @param Cls class name to declare for
|
---|
1735 | */
|
---|
1736 | #define DECLARE_CLS_NEW_DELETE_NOOP(Cls) \
|
---|
1737 | inline static void *operator new (size_t); \
|
---|
1738 | inline static void operator delete (void *);
|
---|
1739 |
|
---|
1740 | #endif /* defined(__cplusplus) */
|
---|
1741 |
|
---|
1742 | /** @} */
|
---|
1743 |
|
---|
1744 | #endif
|
---|
1745 |
|
---|