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