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