1 | /** @file
|
---|
2 | * innotek Portable Runtime - Common C and C++ definitions.
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2006-2007 innotek GmbH
|
---|
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 |
|
---|
26 | #ifndef ___iprt_cdefs_h
|
---|
27 | #define ___iprt_cdefs_h
|
---|
28 |
|
---|
29 |
|
---|
30 | /** @defgroup grp_rt_cdefs innotek Portable Runtime Common Definitions and Macros
|
---|
31 | * @{
|
---|
32 | */
|
---|
33 |
|
---|
34 | /*
|
---|
35 | * Include sys/cdefs.h if present, if not define the stuff we need.
|
---|
36 | */
|
---|
37 | #ifdef HAVE_SYS_CDEFS_H
|
---|
38 | # if defined(RT_ARCH_LINUX) && defined(__KERNEL__)
|
---|
39 | # error "oops"
|
---|
40 | # endif
|
---|
41 | # include <sys/cdefs.h>
|
---|
42 | #else
|
---|
43 |
|
---|
44 | /** @def __BEGIN_DECLS
|
---|
45 | * Used to start a block of function declarations which are shared
|
---|
46 | * between C and C++ program.
|
---|
47 | */
|
---|
48 |
|
---|
49 | /** @def __END_DECLS
|
---|
50 | * Used to end a block of function declarations which are shared
|
---|
51 | * between C and C++ program.
|
---|
52 | */
|
---|
53 |
|
---|
54 | #if defined(__cplusplus)
|
---|
55 | # define __BEGIN_DECLS extern "C" {
|
---|
56 | # define __END_DECLS }
|
---|
57 | #else
|
---|
58 | # define __BEGIN_DECLS
|
---|
59 | # define __END_DECLS
|
---|
60 | #endif
|
---|
61 |
|
---|
62 | #endif
|
---|
63 |
|
---|
64 |
|
---|
65 | /*
|
---|
66 | * Shut up DOXYGEN warnings and guide it properly thru the code.
|
---|
67 | */
|
---|
68 | #ifdef __DOXYGEN__
|
---|
69 | #define __AMD64__
|
---|
70 | #define __X86__
|
---|
71 | #define RT_ARCH_AMD64
|
---|
72 | #define RT_ARCH_X86
|
---|
73 | #define IN_RING0
|
---|
74 | #define IN_RING3
|
---|
75 | #define IN_GC
|
---|
76 | #define IN_RT_GC
|
---|
77 | #define IN_RT_R0
|
---|
78 | #define IN_RT_R3
|
---|
79 | #define RT_STRICT
|
---|
80 | #define Breakpoint
|
---|
81 | #define RT_NO_DEPRECATED_MACROS
|
---|
82 | #define ARCH_BITS
|
---|
83 | #define HC_ARCH_BITS
|
---|
84 | #define R3_ARCH_BITS
|
---|
85 | #define R0_ARCH_BITS
|
---|
86 | #define GC_ARCH_BITS
|
---|
87 | #endif /* __DOXYGEN__ */
|
---|
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 | #ifndef ARCH_BITS
|
---|
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 architechture bit count.
|
---|
171 | */
|
---|
172 | #ifndef HC_ARCH_BITS
|
---|
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 R3_ARCH_BITS
|
---|
181 | * Defines the host ring-3 architechture bit count.
|
---|
182 | */
|
---|
183 | #ifndef R3_ARCH_BITS
|
---|
184 | # ifdef IN_RING3
|
---|
185 | # define R3_ARCH_BITS ARCH_BITS
|
---|
186 | # else
|
---|
187 | # define R3_ARCH_BITS HC_ARCH_BITS
|
---|
188 | # endif
|
---|
189 | #endif
|
---|
190 |
|
---|
191 | /** @def R0_ARCH_BITS
|
---|
192 | * Defines the host ring-0 architechture bit count.
|
---|
193 | */
|
---|
194 | #ifndef R0_ARCH_BITS
|
---|
195 | # ifdef IN_RING0
|
---|
196 | # define R0_ARCH_BITS ARCH_BITS
|
---|
197 | # else
|
---|
198 | # define R0_ARCH_BITS HC_ARCH_BITS
|
---|
199 | # endif
|
---|
200 | #endif
|
---|
201 |
|
---|
202 | /** @def GC_ARCH_BITS
|
---|
203 | * Defines the guest architechture bit count.
|
---|
204 | */
|
---|
205 | #ifndef GC_ARCH_BITS
|
---|
206 | # ifdef IN_GC
|
---|
207 | # define GC_ARCH_BITS ARCH_BITS
|
---|
208 | # else
|
---|
209 | # define GC_ARCH_BITS 32
|
---|
210 | # endif
|
---|
211 | #endif
|
---|
212 |
|
---|
213 |
|
---|
214 | /** @def CTXTYPE
|
---|
215 | * Declare a type differently in GC, R3 and R0.
|
---|
216 | *
|
---|
217 | * @param GCType The GC type.
|
---|
218 | * @param R3Type The R3 type.
|
---|
219 | * @param R0Type The R0 type.
|
---|
220 | * @remark For pointers used only in one context use GCPTRTYPE(), R3R0PTRTYPE(), R3PTRTYPE() or R0PTRTYPE().
|
---|
221 | */
|
---|
222 | #ifdef IN_GC
|
---|
223 | # define CTXTYPE(GCType, R3Type, R0Type) GCType
|
---|
224 | #elif defined(IN_RING3)
|
---|
225 | # define CTXTYPE(GCType, R3Type, R0Type) R3Type
|
---|
226 | #else
|
---|
227 | # define CTXTYPE(GCType, R3Type, R0Type) R0Type
|
---|
228 | #endif
|
---|
229 |
|
---|
230 | /** @def GCTYPE
|
---|
231 | * Declare a type differently in GC and HC.
|
---|
232 | *
|
---|
233 | * @param GCType The GC type.
|
---|
234 | * @param HCType The HC type.
|
---|
235 | * @remark For pointers used only in one context use GCPTRTYPE(), R3R0PTRTYPE(), R3PTRTYPE() or R0PTRTYPE().
|
---|
236 | */
|
---|
237 | #define GCTYPE(GCType, HCType) CTXTYPE(GCType, HCType, HCType)
|
---|
238 |
|
---|
239 | /** @def GCPTRTYPE
|
---|
240 | * Declare a pointer which is used in GC but appears in structure(s) used by
|
---|
241 | * both HC and GC. The main purpose is to make sure structures have the same
|
---|
242 | * size when built for different architectures.
|
---|
243 | *
|
---|
244 | * @param GCType The GC type.
|
---|
245 | */
|
---|
246 | #define GCPTRTYPE(GCType) CTXTYPE(GCType, RTGCPTR, RTGCPTR)
|
---|
247 |
|
---|
248 | /** @def R3R0PTRTYPE
|
---|
249 | * Declare a pointer which is used in HC, is explicitely valid in ring 3 and 0,
|
---|
250 | * but appears in structure(s) used by both HC and GC. The main purpose is to
|
---|
251 | * make sure structures have the same size when built for different architectures.
|
---|
252 | *
|
---|
253 | * @param R3R0Type The R3R0 type.
|
---|
254 | * @remarks This used to be called HCPTRTYPE.
|
---|
255 | */
|
---|
256 | #define R3R0PTRTYPE(R3R0Type) CTXTYPE(RTHCPTR, R3R0Type, R3R0Type)
|
---|
257 |
|
---|
258 | /** @def R3PTRTYPE
|
---|
259 | * Declare a pointer which is used in R3 but appears in structure(s) used by
|
---|
260 | * both HC and GC. The main purpose is to make sure structures have the same
|
---|
261 | * size when built for different architectures.
|
---|
262 | *
|
---|
263 | * @param R3Type The R3 type.
|
---|
264 | */
|
---|
265 | #define R3PTRTYPE(R3Type) CTXTYPE(RTHCUINTPTR, R3Type, RTHCUINTPTR)
|
---|
266 |
|
---|
267 | /** @def R0PTRTYPE
|
---|
268 | * Declare a pointer which is used in R0 but appears in structure(s) used by
|
---|
269 | * both HC and GC. The main purpose is to make sure structures have the same
|
---|
270 | * size when built for different architectures.
|
---|
271 | *
|
---|
272 | * @param R0Type The R0 type.
|
---|
273 | */
|
---|
274 | #define R0PTRTYPE(R0Type) CTXTYPE(RTHCUINTPTR, RTHCUINTPTR, R0Type)
|
---|
275 |
|
---|
276 | /** @def CTXSUFF
|
---|
277 | * Adds the suffix of the current context to the passed in
|
---|
278 | * identifier name. The suffix is HC or GC.
|
---|
279 | *
|
---|
280 | * This is macro should only be used in shared code to avoid a forrest of ifdefs.
|
---|
281 | * @param var Identifier name.
|
---|
282 | */
|
---|
283 | /** @def OTHERCTXSUFF
|
---|
284 | * Adds the suffix of the other context to the passed in
|
---|
285 | * identifier name. The suffix is HC or GC.
|
---|
286 | *
|
---|
287 | * This is macro should only be used in shared code to avoid a forrest of ifdefs.
|
---|
288 | * @param var Identifier name.
|
---|
289 | */
|
---|
290 | #ifdef IN_GC
|
---|
291 | # define CTXSUFF(var) var##GC
|
---|
292 | # define OTHERCTXSUFF(var) var##HC
|
---|
293 | #else
|
---|
294 | # define CTXSUFF(var) var##HC
|
---|
295 | # define OTHERCTXSUFF(var) var##GC
|
---|
296 | #endif
|
---|
297 |
|
---|
298 | /** @def CTXALLSUFF
|
---|
299 | * Adds the suffix of the current context to the passed in
|
---|
300 | * identifier name. The suffix is R3, R0 or GC.
|
---|
301 | *
|
---|
302 | * This is macro should only be used in shared code to avoid a forrest of ifdefs.
|
---|
303 | * @param var Identifier name.
|
---|
304 | */
|
---|
305 | #ifdef IN_GC
|
---|
306 | # define CTXALLSUFF(var) var##GC
|
---|
307 | #elif defined(IN_RING0)
|
---|
308 | # define CTXALLSUFF(var) var##R0
|
---|
309 | #else
|
---|
310 | # define CTXALLSUFF(var) var##R3
|
---|
311 | #endif
|
---|
312 |
|
---|
313 | /** @def CTXMID
|
---|
314 | * Adds the current context as a middle name of an identifier name
|
---|
315 | * The middle name is HC or GC.
|
---|
316 | *
|
---|
317 | * This is macro should only be used in shared code to avoid a forrest of ifdefs.
|
---|
318 | * @param first First name.
|
---|
319 | * @param last Surname.
|
---|
320 | */
|
---|
321 | /** @def OTHERCTXMID
|
---|
322 | * Adds the other context as a middle name of an identifier name
|
---|
323 | * The middle name is HC or GC.
|
---|
324 | *
|
---|
325 | * This is macro should only be used in shared code to avoid a forrest of ifdefs.
|
---|
326 | * @param first First name.
|
---|
327 | * @param last Surname.
|
---|
328 | */
|
---|
329 | #ifdef IN_GC
|
---|
330 | # define CTXMID(first, last) first##GC##last
|
---|
331 | # define OTHERCTXMID(first, last) first##HC##last
|
---|
332 | #else
|
---|
333 | # define CTXMID(first, last) first##HC##last
|
---|
334 | # define OTHERCTXMID(first, last) first##GC##last
|
---|
335 | #endif
|
---|
336 |
|
---|
337 | /** @def CTXALLMID
|
---|
338 | * Adds the current context as a middle name of an identifier name
|
---|
339 | * The middle name is R3, R0 or GC.
|
---|
340 | *
|
---|
341 | * This is macro should only be used in shared code to avoid a forrest of ifdefs.
|
---|
342 | * @param first First name.
|
---|
343 | * @param last Surname.
|
---|
344 | */
|
---|
345 | #ifdef IN_GC
|
---|
346 | # define CTXALLMID(first, last) first##GC##last
|
---|
347 | #elif defined(IN_RING0)
|
---|
348 | # define CTXALLMID(first, last) first##R0##last
|
---|
349 | #else
|
---|
350 | # define CTXALLMID(first, last) first##R3##last
|
---|
351 | #endif
|
---|
352 |
|
---|
353 |
|
---|
354 | /** @def R3STRING
|
---|
355 | * A macro which in GC and R0 will return a dummy string while in R3 it will return
|
---|
356 | * the parameter.
|
---|
357 | *
|
---|
358 | * This is typically used to wrap description strings in structures shared
|
---|
359 | * between R3, R0 and/or GC. The intention is to avoid the \#ifdef IN_RING3 mess.
|
---|
360 | *
|
---|
361 | * @param pR3String The R3 string. Only referenced in R3.
|
---|
362 | * @see R0STRING and GCSTRING
|
---|
363 | */
|
---|
364 | #ifdef IN_RING3
|
---|
365 | # define R3STRING(pR3String) (pR3String)
|
---|
366 | #else
|
---|
367 | # define R3STRING(pR3String) ("<R3_STRING>")
|
---|
368 | #endif
|
---|
369 |
|
---|
370 | /** @def R0STRING
|
---|
371 | * A macro which in GC and R3 will return a dummy string while in R0 it will return
|
---|
372 | * the parameter.
|
---|
373 | *
|
---|
374 | * This is typically used to wrap description strings in structures shared
|
---|
375 | * between R3, R0 and/or GC. The intention is to avoid the \#ifdef IN_RING0 mess.
|
---|
376 | *
|
---|
377 | * @param pR0String The R0 string. Only referenced in R0.
|
---|
378 | * @see R3STRING and GCSTRING
|
---|
379 | */
|
---|
380 | #ifdef IN_RING0
|
---|
381 | # define R0STRING(pR0String) (pR0String)
|
---|
382 | #else
|
---|
383 | # define R0STRING(pR0String) ("<R0_STRING>")
|
---|
384 | #endif
|
---|
385 |
|
---|
386 | /** @def GCSTRING
|
---|
387 | * A macro which in R3 and R0 will return a dummy string while in GC it will return
|
---|
388 | * the parameter.
|
---|
389 | *
|
---|
390 | * This is typically used to wrap description strings in structures shared
|
---|
391 | * between R3, R0 and/or GC. The intention is to avoid the \#ifdef IN_GC mess.
|
---|
392 | *
|
---|
393 | * @param pR0String The GC string. Only referenced in GC.
|
---|
394 | * @see R3STRING, R0STRING
|
---|
395 | */
|
---|
396 | #ifdef IN_GC
|
---|
397 | # define GCSTRING(pR0String) (pGCString)
|
---|
398 | #else
|
---|
399 | # define GCSTRING(pR0String) ("<GC_STRING>")
|
---|
400 | #endif
|
---|
401 |
|
---|
402 | /** @def HCSTRING
|
---|
403 | * Macro which in GC will return a dummy string while in HC will return
|
---|
404 | * the parameter.
|
---|
405 | *
|
---|
406 | * This is typically used to wrap description strings in structures shared
|
---|
407 | * between HC and GC. The intention is to avoid the \#ifdef IN_GC kludge.
|
---|
408 | *
|
---|
409 | * @param pHCString The HC string. Only referenced in HC.
|
---|
410 | * @deprecated Use R3STRING or R0STRING instead.
|
---|
411 | */
|
---|
412 | #ifdef IN_GC
|
---|
413 | # define HCSTRING(pHCString) ("<HC_STRING>")
|
---|
414 | #else
|
---|
415 | # define HCSTRING(pHCString) (pHCString)
|
---|
416 | #endif
|
---|
417 |
|
---|
418 |
|
---|
419 | /** @def RTCALL
|
---|
420 | * The standard calling convention for the Runtime interfaces.
|
---|
421 | */
|
---|
422 | #ifdef _MSC_VER
|
---|
423 | # define RTCALL __cdecl
|
---|
424 | #elif defined(__GNUC__) && defined(IN_RING0) && !(defined(RT_OS_OS2) || defined(RT_ARCH_AMD64)) /* the latter is kernel/gcc */
|
---|
425 | # define RTCALL __attribute__((cdecl,regparm(0)))
|
---|
426 | #else
|
---|
427 | # define RTCALL
|
---|
428 | #endif
|
---|
429 |
|
---|
430 | /** @def DECLEXPORT
|
---|
431 | * How to declare an exported function.
|
---|
432 | * @param type The return type of the function declaration.
|
---|
433 | */
|
---|
434 | #if defined(_MSC_VER) || defined(RT_OS_OS2)
|
---|
435 | # define DECLEXPORT(type) __declspec(dllexport) type
|
---|
436 | #else
|
---|
437 | # ifdef VBOX_HAVE_VISIBILITY_HIDDEN
|
---|
438 | # define DECLEXPORT(type) __attribute__((visibility("default"))) type
|
---|
439 | # else
|
---|
440 | # define DECLEXPORT(type) type
|
---|
441 | # endif
|
---|
442 | #endif
|
---|
443 |
|
---|
444 | /** @def DECLIMPORT
|
---|
445 | * How to declare an imported function.
|
---|
446 | * @param type The return type of the function declaration.
|
---|
447 | */
|
---|
448 | #if defined(_MSC_VER) || (defined(RT_OS_OS2) && !defined(__IBMC__) && !defined(__IBMCPP__))
|
---|
449 | # define DECLIMPORT(type) __declspec(dllimport) type
|
---|
450 | #else
|
---|
451 | # define DECLIMPORT(type) type
|
---|
452 | #endif
|
---|
453 |
|
---|
454 | /** @def DECLASM
|
---|
455 | * How to declare an internal assembly function.
|
---|
456 | * @param type The return type of the function declaration.
|
---|
457 | */
|
---|
458 | #ifdef __cplusplus
|
---|
459 | # ifdef _MSC_VER
|
---|
460 | # define DECLASM(type) extern "C" type __cdecl
|
---|
461 | # else
|
---|
462 | # define DECLASM(type) extern "C" type
|
---|
463 | # endif
|
---|
464 | #else
|
---|
465 | # ifdef _MSC_VER
|
---|
466 | # define DECLASM(type) type __cdecl
|
---|
467 | # else
|
---|
468 | # define DECLASM(type) type
|
---|
469 | # endif
|
---|
470 | #endif
|
---|
471 |
|
---|
472 | /** @def DECLASMTYPE
|
---|
473 | * How to declare an internal assembly function type.
|
---|
474 | * @param type The return type of the function.
|
---|
475 | */
|
---|
476 | #ifdef _MSC_VER
|
---|
477 | # define DECLASMTYPE(type) type __cdecl
|
---|
478 | #else
|
---|
479 | # define DECLASMTYPE(type) type
|
---|
480 | #endif
|
---|
481 |
|
---|
482 | /** @def DECLCALLBACK
|
---|
483 | * How to declare an call back function type.
|
---|
484 | * @param type The return type of the function declaration.
|
---|
485 | */
|
---|
486 | #define DECLCALLBACK(type) type RTCALL
|
---|
487 |
|
---|
488 | /** @def DECLCALLBACKPTR
|
---|
489 | * How to declare an call back function pointer.
|
---|
490 | * @param type The return type of the function declaration.
|
---|
491 | * @param name The name of the variable member.
|
---|
492 | */
|
---|
493 | #define DECLCALLBACKPTR(type, name) type (RTCALL * name)
|
---|
494 |
|
---|
495 | /** @def DECLCALLBACKMEMBER
|
---|
496 | * How to declare an call back function pointer member.
|
---|
497 | * @param type The return type of the function declaration.
|
---|
498 | * @param name The name of the struct/union/class member.
|
---|
499 | */
|
---|
500 | #define DECLCALLBACKMEMBER(type, name) type (RTCALL * name)
|
---|
501 |
|
---|
502 | /** @def DECLR3CALLBACKMEMBER
|
---|
503 | * How to declare an call back function pointer member - R3 Ptr.
|
---|
504 | * @param type The return type of the function declaration.
|
---|
505 | * @param name The name of the struct/union/class member.
|
---|
506 | * @param args The argument list enclosed in parentheses.
|
---|
507 | */
|
---|
508 | #ifdef IN_RING3
|
---|
509 | # define DECLR3CALLBACKMEMBER(type, name, args) type (RTCALL * name) args
|
---|
510 | #else
|
---|
511 | # define DECLR3CALLBACKMEMBER(type, name, args) RTR3PTR name
|
---|
512 | #endif
|
---|
513 |
|
---|
514 | /** @def DECLGCCALLBACKMEMBER
|
---|
515 | * How to declare an call back function pointer member - GC Ptr.
|
---|
516 | * @param type The return type of the function declaration.
|
---|
517 | * @param name The name of the struct/union/class member.
|
---|
518 | * @param args The argument list enclosed in parentheses.
|
---|
519 | */
|
---|
520 | #ifdef IN_GC
|
---|
521 | # define DECLGCCALLBACKMEMBER(type, name, args) type (RTCALL * name) args
|
---|
522 | #else
|
---|
523 | # define DECLGCCALLBACKMEMBER(type, name, args) RTGCPTR name
|
---|
524 | #endif
|
---|
525 |
|
---|
526 | /** @def DECLR0CALLBACKMEMBER
|
---|
527 | * How to declare an call back function pointer member - R0 Ptr.
|
---|
528 | * @param type The return type of the function declaration.
|
---|
529 | * @param name The name of the struct/union/class member.
|
---|
530 | * @param args The argument list enclosed in parentheses.
|
---|
531 | */
|
---|
532 | #ifdef IN_RING0
|
---|
533 | # define DECLR0CALLBACKMEMBER(type, name, args) type (RTCALL * name) args
|
---|
534 | #else
|
---|
535 | # define DECLR0CALLBACKMEMBER(type, name, args) RTR0PTR name
|
---|
536 | #endif
|
---|
537 |
|
---|
538 | /** @def DECLINLINE
|
---|
539 | * How to declare a function as inline.
|
---|
540 | * @param type The return type of the function declaration.
|
---|
541 | * @remarks Don't use this macro on C++ methods.
|
---|
542 | */
|
---|
543 | #ifdef __GNUC__
|
---|
544 | # define DECLINLINE(type) static __inline__ type
|
---|
545 | #elif defined(__cplusplus)
|
---|
546 | # define DECLINLINE(type) inline type
|
---|
547 | #elif defined(_MSC_VER)
|
---|
548 | # define DECLINLINE(type) _inline type
|
---|
549 | #elif defined(__IBMC__)
|
---|
550 | # define DECLINLINE(type) _Inline type
|
---|
551 | #else
|
---|
552 | # define DECLINLINE(type) inline type
|
---|
553 | #endif
|
---|
554 |
|
---|
555 |
|
---|
556 | /** @def IN_RT_R0
|
---|
557 | * Used to indicate whether we're inside the same link module as
|
---|
558 | * the HC Ring-0 Runtime Library.
|
---|
559 | */
|
---|
560 | /** @def RTR0DECL(type)
|
---|
561 | * Runtime Library HC Ring-0 export or import declaration.
|
---|
562 | * @param type The return type of the function declaration.
|
---|
563 | */
|
---|
564 | #ifdef IN_RT_R0
|
---|
565 | # define RTR0DECL(type) DECLEXPORT(type) RTCALL
|
---|
566 | #else
|
---|
567 | # define RTR0DECL(type) DECLIMPORT(type) RTCALL
|
---|
568 | #endif
|
---|
569 |
|
---|
570 | /** @def IN_RT_R3
|
---|
571 | * Used to indicate whether we're inside the same link module as
|
---|
572 | * the HC Ring-3 Runtime Library.
|
---|
573 | */
|
---|
574 | /** @def RTR3DECL(type)
|
---|
575 | * Runtime Library HC Ring-3 export or import declaration.
|
---|
576 | * @param type The return type of the function declaration.
|
---|
577 | */
|
---|
578 | #ifdef IN_RT_R3
|
---|
579 | # define RTR3DECL(type) DECLEXPORT(type) RTCALL
|
---|
580 | #else
|
---|
581 | # define RTR3DECL(type) DECLIMPORT(type) RTCALL
|
---|
582 | #endif
|
---|
583 |
|
---|
584 | /** @def IN_RT_GC
|
---|
585 | * Used to indicate whether we're inside the same link module as
|
---|
586 | * the GC Runtime Library.
|
---|
587 | */
|
---|
588 | /** @def RTGCDECL(type)
|
---|
589 | * Runtime Library HC Ring-3 export or import declaration.
|
---|
590 | * @param type The return type of the function declaration.
|
---|
591 | */
|
---|
592 | #ifdef IN_RT_GC
|
---|
593 | # define RTGCDECL(type) DECLEXPORT(type) RTCALL
|
---|
594 | #else
|
---|
595 | # define RTGCDECL(type) DECLIMPORT(type) RTCALL
|
---|
596 | #endif
|
---|
597 |
|
---|
598 | /** @def RTDECL(type)
|
---|
599 | * Runtime Library export or import declaration.
|
---|
600 | * Functions declared using this macro exists in all contexts.
|
---|
601 | * @param type The return type of the function declaration.
|
---|
602 | */
|
---|
603 | #if defined(IN_RT_R3) || defined(IN_RT_GC) || defined(IN_RT_R0)
|
---|
604 | # define RTDECL(type) DECLEXPORT(type) RTCALL
|
---|
605 | #else
|
---|
606 | # define RTDECL(type) DECLIMPORT(type) RTCALL
|
---|
607 | #endif
|
---|
608 |
|
---|
609 | /** @def RTDATADECL(type)
|
---|
610 | * Runtime Library export or import declaration.
|
---|
611 | * Data declared using this macro exists in all contexts.
|
---|
612 | * @param type The return type of the function declaration.
|
---|
613 | */
|
---|
614 | #if defined(IN_RT_R3) || defined(IN_RT_GC) || defined(IN_RT_R0)
|
---|
615 | # define RTDATADECL(type) DECLEXPORT(type)
|
---|
616 | #else
|
---|
617 | # define RTDATADECL(type) DECLIMPORT(type)
|
---|
618 | #endif
|
---|
619 |
|
---|
620 |
|
---|
621 | /** @def RT_NOCRT
|
---|
622 | * Symbol name wrapper for the No-CRT bits.
|
---|
623 | *
|
---|
624 | * In order to coexist in the same process as other CRTs, we need to
|
---|
625 | * decorate the symbols such that they don't conflict the ones in the
|
---|
626 | * other CRTs. The result of such conflicts / duplicate symbols can
|
---|
627 | * confuse the dynamic loader on unix like systems.
|
---|
628 | *
|
---|
629 | * Define RT_WITHOUT_NOCRT_WRAPPERS to drop the wrapping.
|
---|
630 | */
|
---|
631 | /** @def RT_NOCRT_STR
|
---|
632 | * Same as RT_NOCRT only it'll return a double quoted string of the result.
|
---|
633 | */
|
---|
634 | #ifndef RT_WITHOUT_NOCRT_WRAPPERS
|
---|
635 | # define RT_NOCRT(name) nocrt_ ## name
|
---|
636 | # define RT_NOCRT_STR(name) "nocrt_" # name
|
---|
637 | #else
|
---|
638 | # define RT_NOCRT(name) name
|
---|
639 | # define RT_NOCRT_STR(name) #name
|
---|
640 | #endif
|
---|
641 |
|
---|
642 |
|
---|
643 |
|
---|
644 | /** @def RT_LIKELY
|
---|
645 | * Give the compiler a hint that an expression is very likely to hold true.
|
---|
646 | *
|
---|
647 | * Some compilers support explicit branch prediction so that the CPU backend
|
---|
648 | * can hint the processor and also so that code blocks can be reordered such
|
---|
649 | * that the predicted path sees a more linear flow, thus improving cache
|
---|
650 | * behaviour, etc.
|
---|
651 | *
|
---|
652 | * IPRT provides the macros RT_LIKELY() and RT_UNLIKELY() as a way to utilize
|
---|
653 | * this compiler feature when present.
|
---|
654 | *
|
---|
655 | * A few notes about the usage:
|
---|
656 | *
|
---|
657 | * - Generally, use RT_UNLIKELY() with error condition checks (unless you
|
---|
658 | * have some _strong_ reason to do otherwise, in which case document it),
|
---|
659 | * and/or RT_LIKELY() with success condition checks, assuming you want
|
---|
660 | * to optimize for the success path.
|
---|
661 | *
|
---|
662 | * - Other than that, if you don't know the likelihood of a test succeeding
|
---|
663 | * from empirical or other 'hard' evidence, don't make predictions unless
|
---|
664 | * you happen to be a Dirk Gently.
|
---|
665 | *
|
---|
666 | * - These macros are meant to be used in places that get executed a lot. It
|
---|
667 | * is wasteful to make predictions in code that is executed seldomly (e.g.
|
---|
668 | * at subsystem initialization time) as the basic block reording that this
|
---|
669 | * affecs can often generate larger code.
|
---|
670 | *
|
---|
671 | * - Note that RT_SUCCESS() and RT_FAILURE() already makes use of RT_LIKELY()
|
---|
672 | * and RT_UNLIKELY(). Should you wish for prediction free status checks,
|
---|
673 | * use the RT_SUCCESS_NP() and RT_FAILURE_NP() macros instead.
|
---|
674 | *
|
---|
675 | *
|
---|
676 | * @returns the boolean result of the expression.
|
---|
677 | * @param expr The expression that's very likely to be true.
|
---|
678 | * @see RT_UNLIKELY
|
---|
679 | */
|
---|
680 | /** @def RT_UNLIKELY
|
---|
681 | * Give the compiler a hint that an expression is highly unlikely hold true.
|
---|
682 | *
|
---|
683 | * See the usage instructions give in the RT_LIKELY() docs.
|
---|
684 | *
|
---|
685 | * @returns the boolean result of the expression.
|
---|
686 | * @param expr The expression that's very unlikely to be true.
|
---|
687 | * @see RT_LIKELY
|
---|
688 | */
|
---|
689 | #if defined(__GNUC__)
|
---|
690 | # if __GNUC__ >= 3
|
---|
691 | # define RT_LIKELY(expr) __builtin_expect(!!(expr), 1)
|
---|
692 | # define RT_UNLIKELY(expr) __builtin_expect(!!(expr), 0)
|
---|
693 | # else
|
---|
694 | # define RT_LIKELY(expr) (expr)
|
---|
695 | # define RT_UNLIKELY(expr) (expr)
|
---|
696 | # endif
|
---|
697 | #else
|
---|
698 | # define RT_LIKELY(expr) (expr)
|
---|
699 | # define RT_UNLIKELY(expr) (expr)
|
---|
700 | #endif
|
---|
701 |
|
---|
702 |
|
---|
703 | /** @def RT_BIT
|
---|
704 | * Make a bitmask for one integer sized bit.
|
---|
705 | * @param bit Bit number.
|
---|
706 | */
|
---|
707 | #define RT_BIT(bit) (1U << (bit))
|
---|
708 |
|
---|
709 | /** @def RT_BIT_32
|
---|
710 | * Make a 32-bit bitmask for one bit.
|
---|
711 | * @param bit Bit number.
|
---|
712 | */
|
---|
713 | #define RT_BIT_32(bit) (UINT32_C(1) << (bit))
|
---|
714 |
|
---|
715 | /** @def RT_BIT_64
|
---|
716 | * Make a 64-bit bitmask for one bit.
|
---|
717 | * @param bit Bit number.
|
---|
718 | */
|
---|
719 | #define RT_BIT_64(bit) (UINT64_C(1) << (bit))
|
---|
720 |
|
---|
721 | /** @def RT_ALIGN
|
---|
722 | * Align macro.
|
---|
723 | * @param u Value to align.
|
---|
724 | * @param uAlignment The alignment. Power of two!
|
---|
725 | *
|
---|
726 | * @remark Be extremely careful when using this macro with type which sizeof != sizeof int.
|
---|
727 | * When possible use any of the other RT_ALIGN_* macros. And when that's not
|
---|
728 | * possible, make 101% sure that uAlignment is specified with a right sized type.
|
---|
729 | *
|
---|
730 | * Specifying an unsigned 32-bit alignment constant with a 64-bit value will give
|
---|
731 | * you a 32-bit return value!
|
---|
732 | *
|
---|
733 | * In short: Don't use this macro. Use RT_ALIGN_T() instead.
|
---|
734 | */
|
---|
735 | #define RT_ALIGN(u, uAlignment) ( ((u) + ((uAlignment) - 1)) & ~((uAlignment) - 1) )
|
---|
736 |
|
---|
737 | /** @def RT_ALIGN_T
|
---|
738 | * Align macro.
|
---|
739 | * @param u Value to align.
|
---|
740 | * @param uAlignment The alignment. Power of two!
|
---|
741 | * @param type Integer type to use while aligning.
|
---|
742 | * @remark This macro is the prefered alignment macro, it doesn't have any of the pitfalls RT_ALIGN has.
|
---|
743 | */
|
---|
744 | #define RT_ALIGN_T(u, uAlignment, type) ( ((type)(u) + ((uAlignment) - 1)) & ~(type)((uAlignment) - 1) )
|
---|
745 |
|
---|
746 | /** @def RT_ALIGN_32
|
---|
747 | * Align macro for a 32-bit value.
|
---|
748 | * @param u32 Value to align.
|
---|
749 | * @param uAlignment The alignment. Power of two!
|
---|
750 | */
|
---|
751 | #define RT_ALIGN_32(u32, uAlignment) RT_ALIGN_T(u32, uAlignment, uint32_t)
|
---|
752 |
|
---|
753 | /** @def RT_ALIGN_64
|
---|
754 | * Align macro for a 64-bit value.
|
---|
755 | * @param u64 Value to align.
|
---|
756 | * @param uAlignment The alignment. Power of two!
|
---|
757 | */
|
---|
758 | #define RT_ALIGN_64(u64, uAlignment) RT_ALIGN_T(u64, uAlignment, uint64_t)
|
---|
759 |
|
---|
760 | /** @def RT_ALIGN_Z
|
---|
761 | * Align macro for size_t.
|
---|
762 | * @param cb Value to align.
|
---|
763 | * @param uAlignment The alignment. Power of two!
|
---|
764 | */
|
---|
765 | #define RT_ALIGN_Z(cb, uAlignment) RT_ALIGN_T(cb, uAlignment, size_t)
|
---|
766 |
|
---|
767 | /** @def RT_ALIGN_P
|
---|
768 | * Align macro for pointers.
|
---|
769 | * @param pv Value to align.
|
---|
770 | * @param uAlignment The alignment. Power of two!
|
---|
771 | */
|
---|
772 | #define RT_ALIGN_P(pv, uAlignment) RT_ALIGN_PT(pv, uAlignment, void *)
|
---|
773 |
|
---|
774 | /** @def RT_ALIGN_PT
|
---|
775 | * Align macro for pointers with type cast.
|
---|
776 | * @param u Value to align.
|
---|
777 | * @param uAlignment The alignment. Power of two!
|
---|
778 | * @param CastType The type to cast the result to.
|
---|
779 | */
|
---|
780 | #define RT_ALIGN_PT(u, uAlignment, CastType) ((CastType)RT_ALIGN_T(u, uAlignment, uintptr_t))
|
---|
781 |
|
---|
782 | /** @def RT_ALIGN_R3PT
|
---|
783 | * Align macro for ring-3 pointers with type cast.
|
---|
784 | * @param u Value to align.
|
---|
785 | * @param uAlignment The alignment. Power of two!
|
---|
786 | * @param CastType The type to cast the result to.
|
---|
787 | */
|
---|
788 | #define RT_ALIGN_R3PT(u, uAlignment, CastType) ((CastType)RT_ALIGN_T(u, uAlignment, RTR3UINTPTR))
|
---|
789 |
|
---|
790 | /** @def RT_ALIGN_R0PT
|
---|
791 | * Align macro for ring-0 pointers with type cast.
|
---|
792 | * @param u Value to align.
|
---|
793 | * @param uAlignment The alignment. Power of two!
|
---|
794 | * @param CastType The type to cast the result to.
|
---|
795 | */
|
---|
796 | #define RT_ALIGN_R0PT(u, uAlignment, CastType) ((CastType)RT_ALIGN_T(u, uAlignment, RTR0UINTPTR))
|
---|
797 |
|
---|
798 | /** @def RT_ALIGN_GCPT
|
---|
799 | * Align macro for GC pointers with type cast.
|
---|
800 | * @param u Value to align.
|
---|
801 | * @param uAlignment The alignment. Power of two!
|
---|
802 | * @param CastType The type to cast the result to.
|
---|
803 | */
|
---|
804 | #define RT_ALIGN_GCPT(u, uAlignment, CastType) ((CastType)RT_ALIGN_T(u, uAlignment, RTGCUINTPTR))
|
---|
805 |
|
---|
806 |
|
---|
807 | /** @def RT_OFFSETOF
|
---|
808 | * Our own special offsetof() variant, returns a signed result.
|
---|
809 | *
|
---|
810 | * This differs from the usual offsetof() in that it's not relying on builtin
|
---|
811 | * compiler stuff and thus can use variables in arrays the structure may
|
---|
812 | * contain. If in this usful to determin the sizes of structures ending
|
---|
813 | * with a variable length field.
|
---|
814 | *
|
---|
815 | * @returns offset into the structure of the specified member. signed.
|
---|
816 | * @param type Structure type.
|
---|
817 | * @param member Member.
|
---|
818 | */
|
---|
819 | #define RT_OFFSETOF(type, member) ( (int)(uintptr_t)&( ((type *)(void *)0)->member) )
|
---|
820 |
|
---|
821 | /** @def RT_UOFFSETOF
|
---|
822 | * Our own special offsetof() variant, returns an unsigned result.
|
---|
823 | *
|
---|
824 | * This differs from the usual offsetof() in that it's not relying on builtin
|
---|
825 | * compiler stuff and thus can use variables in arrays the structure may
|
---|
826 | * contain. If in this usful to determin the sizes of structures ending
|
---|
827 | * with a variable length field.
|
---|
828 | *
|
---|
829 | * @returns offset into the structure of the specified member. unsigned.
|
---|
830 | * @param type Structure type.
|
---|
831 | * @param member Member.
|
---|
832 | */
|
---|
833 | #define RT_UOFFSETOF(type, member) ( (uintptr_t)&( ((type *)(void *)0)->member) )
|
---|
834 |
|
---|
835 | /** @def RT_SIZEOFMEMB
|
---|
836 | * Get the size of a structure member.
|
---|
837 | *
|
---|
838 | * @returns size of the structure member.
|
---|
839 | * @param type Structure type.
|
---|
840 | * @param member Member.
|
---|
841 | */
|
---|
842 | #define RT_SIZEOFMEMB(type, member) ( sizeof(((type *)(void *)0)->member) )
|
---|
843 |
|
---|
844 | /** @def RT_ELEMENTS
|
---|
845 | * Calcs the number of elements in an array.
|
---|
846 | * @returns Element count.
|
---|
847 | * @param aArray Array in question.
|
---|
848 | */
|
---|
849 | #define RT_ELEMENTS(aArray) ( sizeof(aArray) / sizeof((aArray)[0]) )
|
---|
850 |
|
---|
851 | #ifdef RT_OS_OS2
|
---|
852 | /* Undefine RT_MAX since there is an unfortunate clash with the max
|
---|
853 | resource type define in os2.h. */
|
---|
854 | # undef RT_MAX
|
---|
855 | #endif
|
---|
856 |
|
---|
857 | /** @def RT_MAX
|
---|
858 | * Finds the maximum value.
|
---|
859 | * @returns The higher of the two.
|
---|
860 | * @param Value1 Value 1
|
---|
861 | * @param Value2 Value 2
|
---|
862 | */
|
---|
863 | #define RT_MAX(Value1, Value2) ((Value1) >= (Value2) ? (Value1) : (Value2))
|
---|
864 |
|
---|
865 | /** @def RT_MIN
|
---|
866 | * Finds the minimum value.
|
---|
867 | * @returns The lower of the two.
|
---|
868 | * @param Value1 Value 1
|
---|
869 | * @param Value2 Value 2
|
---|
870 | */
|
---|
871 | #define RT_MIN(Value1, Value2) ((Value1) <= (Value2) ? (Value1) : (Value2))
|
---|
872 |
|
---|
873 | /** @def RT_ABS
|
---|
874 | * Get the absolute (non-negative) value.
|
---|
875 | * @returns The absolute value of Value.
|
---|
876 | * @param Value The value.
|
---|
877 | */
|
---|
878 | #define RT_ABS(Value) ((Value) >= 0 ? (Value) : -(Value))
|
---|
879 |
|
---|
880 | /** @def RT_LOWORD
|
---|
881 | * Gets the low word (=uint16_t) of something. */
|
---|
882 | #define RT_LOWORD(a) ((a) & 0xffff)
|
---|
883 |
|
---|
884 | /** @def RT_HIWORD
|
---|
885 | * Gets the high word (=uint16_t) of a 32 bit something. */
|
---|
886 | #define RT_HIWORD(a) ((a) >> 16)
|
---|
887 |
|
---|
888 | /** @def RT_LOBYTE
|
---|
889 | * Gets the low byte of something. */
|
---|
890 | #define RT_LOBYTE(a) ((a) & 0xff)
|
---|
891 |
|
---|
892 | /** @def RT_HIBYTE
|
---|
893 | * Gets the low byte of a 16 bit something. */
|
---|
894 | #define RT_HIBYTE(a) ((a) >> 8)
|
---|
895 |
|
---|
896 | /** @def RT_BYTE1
|
---|
897 | * Gets first byte of something. */
|
---|
898 | #define RT_BYTE1(a) ((a) & 0xff)
|
---|
899 |
|
---|
900 | /** @def RT_BYTE2
|
---|
901 | * Gets second byte of something. */
|
---|
902 | #define RT_BYTE2(a) (((a) >> 8) & 0xff)
|
---|
903 |
|
---|
904 | /** @def RT_BYTE3
|
---|
905 | * Gets second byte of something. */
|
---|
906 | #define RT_BYTE3(a) (((a) >> 16) & 0xff)
|
---|
907 |
|
---|
908 | /** @def RT_BYTE4
|
---|
909 | * Gets fourth byte of something. */
|
---|
910 | #define RT_BYTE4(a) (((a) >> 24) & 0xff)
|
---|
911 |
|
---|
912 |
|
---|
913 | /** @def RT_MAKE_U64
|
---|
914 | * Constructs a uint64_t value from two uint32_t values.
|
---|
915 | */
|
---|
916 | #define RT_MAKE_U64(Lo, Hi) ( (uint64_t)((uint32_t)(Hi)) << 32 | (uint32_t)(Lo) )
|
---|
917 |
|
---|
918 | /** @def RT_MAKE_U64_FROM_U16
|
---|
919 | * Constructs a uint64_t value from four uint16_t values.
|
---|
920 | */
|
---|
921 | #define RT_MAKE_U64_FROM_U16(w0, w1, w2, w3) \
|
---|
922 | ( (uint64_t)((uint16_t)(w3)) << 48 \
|
---|
923 | | (uint64_t)((uint16_t)(w2)) << 32 \
|
---|
924 | | (uint32_t)((uint16_t)(w1)) << 16 \
|
---|
925 | | (uint16_t)(w0) )
|
---|
926 |
|
---|
927 | /** @def RT_MAKE_U64_FROM_U8
|
---|
928 | * Constructs a uint64_t value from eight uint8_t values.
|
---|
929 | */
|
---|
930 | #define RT_MAKE_U64_FROM_U8(b0, b1, b2, b3, b4, b5, b6, b7) \
|
---|
931 | ( (uint64_t)((uint8_t)(b7)) << 56 \
|
---|
932 | | (uint64_t)((uint8_t)(b6)) << 48 \
|
---|
933 | | (uint64_t)((uint8_t)(b5)) << 40 \
|
---|
934 | | (uint64_t)((uint8_t)(b4)) << 32 \
|
---|
935 | | (uint32_t)((uint8_t)(b3)) << 24 \
|
---|
936 | | (uint32_t)((uint8_t)(b2)) << 16 \
|
---|
937 | | (uint16_t)((uint8_t)(b1)) << 8 \
|
---|
938 | | (uint8_t)(b0) )
|
---|
939 |
|
---|
940 | /** @def RT_MAKE_U32
|
---|
941 | * Constructs a uint32_t value from two uint16_t values.
|
---|
942 | */
|
---|
943 | #define RT_MAKE_U32(Lo, Hi) ( (uint32_t)((uint16_t)(Hi)) << 16 | (uint16_t)(Lo) )
|
---|
944 |
|
---|
945 | /** @def RT_MAKE_U32_FROM_U8
|
---|
946 | * Constructs a uint32_t value from four uint8_t values.
|
---|
947 | */
|
---|
948 | #define RT_MAKE_U32_FROM_U8(b0, b1, b2, b3) \
|
---|
949 | ( (uint32_t)((uint8_t)(b3)) << 24 \
|
---|
950 | | (uint32_t)((uint8_t)(b2)) << 16 \
|
---|
951 | | (uint16_t)((uint8_t)(b1)) << 8 \
|
---|
952 | | (uint8_t)(b0) )
|
---|
953 | /** @todo remove this after uses in VUSBUrb.cpp has been corrected. */
|
---|
954 | #define MAKE_U32_FROM_U8(b0,b1,b2,b3) RT_MAKE_U32_FROM_U8(b0,b1,b2,b3)
|
---|
955 |
|
---|
956 | /** @def RT_MAKE_U16
|
---|
957 | * Constructs a uint32_t value from two uint16_t values.
|
---|
958 | */
|
---|
959 | #define RT_MAKE_U16(Lo, Hi) ( (uint16_t)((uint8_t)(Hi)) << 8 | (uint8_t)(Lo) )
|
---|
960 |
|
---|
961 |
|
---|
962 | /** @def RT_H2LE_U64
|
---|
963 | * Converts uint64_t value from host to little endian byte order. */
|
---|
964 | #define RT_H2LE_U64(u64) (u64)
|
---|
965 |
|
---|
966 | /** @def RT_H2LE_U32
|
---|
967 | * Converts uint32_t value from host to little endian byte order. */
|
---|
968 | #define RT_H2LE_U32(u32) (u32)
|
---|
969 |
|
---|
970 | /** @def RT_H2LE_U16
|
---|
971 | * Converts uint16_t value from host to little endian byte order. */
|
---|
972 | #define RT_H2LE_U16(u16) (u16)
|
---|
973 |
|
---|
974 | /** @def RT_LE2H_U64
|
---|
975 | * Converts uint64_t value from little endian to host byte order. */
|
---|
976 | #define RT_LE2H_U64(u64) (u64)
|
---|
977 |
|
---|
978 | /** @def RT_LE2H_U32
|
---|
979 | * Converts uint32_t value from little endian to host byte order. */
|
---|
980 | #define RT_LE2H_U32(u32) (u32)
|
---|
981 |
|
---|
982 | /** @def RT_LE2H_U16
|
---|
983 | * Converts uint16_t value from little endian to host byte order. */
|
---|
984 | #define RT_LE2H_U16(u16) (u16)
|
---|
985 |
|
---|
986 |
|
---|
987 | /** @def RT_H2BE_U64
|
---|
988 | * Converts uint64_t value from host to big endian byte order. */
|
---|
989 | #define RT_H2BE_U64(u64) RT_MAKE_U64_FROM_U32(RT_H2BE_U32((u64) >> 32), RT_H2BE_U32((u64) & 0xffffffff))
|
---|
990 |
|
---|
991 | /** @def RT_H2BE_U32
|
---|
992 | * Converts uint32_t value from host to big endian byte order. */
|
---|
993 | #define RT_H2BE_U32(u32) (RT_BYTE4(u32) | (RT_BYTE3(u32) << 8) | (RT_BYTE2(u32) << 16) | (RT_BYTE1(u32) << 24))
|
---|
994 |
|
---|
995 | /** @def RT_H2BE_U16
|
---|
996 | * Converts uint16_t value from host to big endian byte order. */
|
---|
997 | #define RT_H2BE_U16(u16) (RT_HIBYTE(u16) | (RT_LOBYTE(u16) << 8))
|
---|
998 |
|
---|
999 | /** @def RT_BE2H_U64
|
---|
1000 | * Converts uint64_t value from big endian to host byte order. */
|
---|
1001 | #define RT_BE2H_U64(u64) RT_MAKE_U64_FROM_U32(RT_H2BE_U32((u64) >> 32), RT_H2BE_U32((u64) & 0xffffffff))
|
---|
1002 |
|
---|
1003 | /** @def RT_BE2H_U32
|
---|
1004 | * Converts uint32_t value from big endian to host byte order. */
|
---|
1005 | #define RT_BE2H_U32(u32) (RT_BYTE4(u32) | (RT_BYTE3(u32) << 8) | (RT_BYTE2(u32) << 16) | (RT_BYTE1(u32) << 24))
|
---|
1006 |
|
---|
1007 | /** @def RT_BE2H_U16
|
---|
1008 | * Converts uint16_t value from big endian to host byte order. */
|
---|
1009 | #define RT_BE2H_U16(u16) (RT_HIBYTE(u16) | (RT_LOBYTE(u16) << 8))
|
---|
1010 |
|
---|
1011 |
|
---|
1012 | /** @def RT_H2N_U32
|
---|
1013 | * Converts uint32_t value from host to network byte order. */
|
---|
1014 | #define RT_H2N_U32(u32) RT_H2BE_U32(u32)
|
---|
1015 |
|
---|
1016 | /** @def RT_H2N_U16
|
---|
1017 | * Converts uint16_t value from host to network byte order. */
|
---|
1018 | #define RT_H2N_U16(u16) RT_H2BE_U16(u16)
|
---|
1019 |
|
---|
1020 | /** @def RT_N2H_U32
|
---|
1021 | * Converts uint32_t value from network to host byte order. */
|
---|
1022 | #define RT_N2H_U32(u32) RT_BE2H_U32(u32)
|
---|
1023 |
|
---|
1024 | /** @def RT_N2H_U16
|
---|
1025 | * Converts uint16_t value from network to host byte order. */
|
---|
1026 | #define RT_N2H_U16(u16) RT_BE2H_U16(u16)
|
---|
1027 |
|
---|
1028 |
|
---|
1029 | /** @def RT_NO_DEPRECATED_MACROS
|
---|
1030 | * Define RT_NO_DEPRECATED_MACROS to not define deprecated macros.
|
---|
1031 | */
|
---|
1032 | #ifndef RT_NO_DEPRECATED_MACROS
|
---|
1033 | /** @copydoc RT_ELEMENTS
|
---|
1034 | * @deprecated use RT_ELEMENTS. */
|
---|
1035 | # define ELEMENTS(aArray) RT_ELEMENTS(aArray)
|
---|
1036 | #endif
|
---|
1037 |
|
---|
1038 |
|
---|
1039 | /*
|
---|
1040 | * The BSD sys/param.h + machine/param.h file is a major source of
|
---|
1041 | * namespace pollution. Kill off some of the worse ones unless we're
|
---|
1042 | * compiling kernel code.
|
---|
1043 | */
|
---|
1044 | #if defined(RT_OS_DARWIN) \
|
---|
1045 | && !defined(KERNEL) \
|
---|
1046 | && !defined(RT_NO_BSD_PARAM_H_UNDEFING) \
|
---|
1047 | && ( defined(_SYS_PARAM_H_) || defined(_I386_PARAM_H_) )
|
---|
1048 | /* sys/param.h: */
|
---|
1049 | # undef PSWP
|
---|
1050 | # undef PVM
|
---|
1051 | # undef PINOD
|
---|
1052 | # undef PRIBO
|
---|
1053 | # undef PVFS
|
---|
1054 | # undef PZERO
|
---|
1055 | # undef PSOCK
|
---|
1056 | # undef PWAIT
|
---|
1057 | # undef PLOCK
|
---|
1058 | # undef PPAUSE
|
---|
1059 | # undef PUSER
|
---|
1060 | # undef PRIMASK
|
---|
1061 | # undef MINBUCKET
|
---|
1062 | # undef MAXALLOCSAVE
|
---|
1063 | # undef FSHIFT
|
---|
1064 | # undef FSCALE
|
---|
1065 |
|
---|
1066 | /* i386/machine.h: */
|
---|
1067 | # undef ALIGN
|
---|
1068 | # undef ALIGNBYTES
|
---|
1069 | # undef DELAY
|
---|
1070 | # undef STATUS_WORD
|
---|
1071 | # undef USERMODE
|
---|
1072 | # undef BASEPRI
|
---|
1073 | # undef MSIZE
|
---|
1074 | # undef CLSIZE
|
---|
1075 | # undef CLSIZELOG2
|
---|
1076 | #endif
|
---|
1077 |
|
---|
1078 |
|
---|
1079 | /** @def NULL
|
---|
1080 | * NULL pointer.
|
---|
1081 | */
|
---|
1082 | #ifndef NULL
|
---|
1083 | # ifdef __cplusplus
|
---|
1084 | # define NULL 0
|
---|
1085 | # else
|
---|
1086 | # define NULL ((void*)0)
|
---|
1087 | # endif
|
---|
1088 | #endif
|
---|
1089 |
|
---|
1090 | /** @def NIL_OFFSET
|
---|
1091 | * NIL offset.
|
---|
1092 | * Whenever we use offsets instead of pointers to save space and relocation effort
|
---|
1093 | * NIL_OFFSET shall be used as the equivalent to NULL.
|
---|
1094 | */
|
---|
1095 | #define NIL_OFFSET (~0U)
|
---|
1096 |
|
---|
1097 | /** @def NOREF
|
---|
1098 | * Keeps the compiler from bitching about an unused parameters.
|
---|
1099 | */
|
---|
1100 | #define NOREF(var) (void)(var)
|
---|
1101 |
|
---|
1102 | /** @def Breakpoint
|
---|
1103 | * Emit a debug breakpoint instruction.
|
---|
1104 | *
|
---|
1105 | * Use this for instrumenting a debugging session only!
|
---|
1106 | * No comitted code shall use Breakpoint().
|
---|
1107 | */
|
---|
1108 | #ifdef __GNUC__
|
---|
1109 | # define Breakpoint() __asm__ __volatile__("int $3\n\t")
|
---|
1110 | #endif
|
---|
1111 | #ifdef _MSC_VER
|
---|
1112 | # define Breakpoint() __asm int 3
|
---|
1113 | #endif
|
---|
1114 | #if defined(__IBMC__) || defined(__IBMCPP__)
|
---|
1115 | # define Breakpoint() __interrupt(3)
|
---|
1116 | #endif
|
---|
1117 | #ifndef Breakpoint
|
---|
1118 | # error "This compiler is not supported!"
|
---|
1119 | #endif
|
---|
1120 |
|
---|
1121 |
|
---|
1122 | /** Size Constants
|
---|
1123 | * (Of course, these are binary computer terms, not SI.)
|
---|
1124 | * @{
|
---|
1125 | */
|
---|
1126 | /** 1 K (Kilo) (1 024). */
|
---|
1127 | #define _1K 0x00000400
|
---|
1128 | /** 4 K (Kilo) (4 096). */
|
---|
1129 | #define _4K 0x00001000
|
---|
1130 | /** 32 K (Kilo) (32 678). */
|
---|
1131 | #define _32K 0x00008000
|
---|
1132 | /** 64 K (Kilo) (65 536). */
|
---|
1133 | #define _64K 0x00010000
|
---|
1134 | /** 128 K (Kilo) (131 072). */
|
---|
1135 | #define _128K 0x00020000
|
---|
1136 | /** 256 K (Kilo) (262 144). */
|
---|
1137 | #define _256K 0x00040000
|
---|
1138 | /** 512 K (Kilo) (524 288). */
|
---|
1139 | #define _512K 0x00080000
|
---|
1140 | /** 1 M (Mega) (1 048 576). */
|
---|
1141 | #define _1M 0x00100000
|
---|
1142 | /** 2 M (Mega) (2 097 152). */
|
---|
1143 | #define _2M 0x00200000
|
---|
1144 | /** 4 M (Mega) (4 194 304). */
|
---|
1145 | #define _4M 0x00400000
|
---|
1146 | /** 1 G (Giga) (1 073 741 824). */
|
---|
1147 | #define _1G 0x40000000
|
---|
1148 | /** 2 G (Giga) (2 147 483 648). (32-bit) */
|
---|
1149 | #define _2G32 0x80000000U
|
---|
1150 | /** 2 G (Giga) (2 147 483 648). (64-bit) */
|
---|
1151 | #define _2G 0x0000000080000000LL
|
---|
1152 | /** 4 G (Giga) (4 294 967 296). */
|
---|
1153 | #define _4G 0x0000000100000000LL
|
---|
1154 | /** 1 T (Tera) (1 099 511 627 776). */
|
---|
1155 | #define _1T 0x0000010000000000LL
|
---|
1156 | /** 1 P (Peta) (1 125 899 906 842 624). */
|
---|
1157 | #define _1P 0x0004000000000000LL
|
---|
1158 | /** 1 E (Exa) (1 152 921 504 606 846 976). */
|
---|
1159 | #define _1E 0x1000000000000000LL
|
---|
1160 | /** 2 E (Exa) (2 305 843 009 213 693 952). */
|
---|
1161 | #define _2E 0x2000000000000000ULL
|
---|
1162 | /** @} */
|
---|
1163 |
|
---|
1164 | /** @def VALID_PTR
|
---|
1165 | * Pointer validation macro.
|
---|
1166 | * @param ptr
|
---|
1167 | */
|
---|
1168 | #if defined(RT_ARCH_AMD64)
|
---|
1169 | # ifdef IN_RING3
|
---|
1170 | # if defined(RT_OS_DARWIN) /* first 4GB is reserved for legacy kernel. */
|
---|
1171 | # define VALID_PTR(ptr) ( (uintptr_t)(ptr) >= _4G \
|
---|
1172 | && !((uintptr_t)(ptr) & 0xffff800000000000ULL) )
|
---|
1173 | # elif defined(RT_OS_SOLARIS) /* The kernel only used the top 2TB, but keep it simple. */
|
---|
1174 | # define VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x1000U >= 0x2000U \
|
---|
1175 | && ( ((uintptr_t)(ptr) & 0xffff800000000000ULL) == 0xffff800000000000ULL \
|
---|
1176 | || ((uintptr_t)(ptr) & 0xffff800000000000ULL) == 0) )
|
---|
1177 | # else
|
---|
1178 | # define VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x1000U >= 0x2000U \
|
---|
1179 | && !((uintptr_t)(ptr) & 0xffff800000000000ULL) )
|
---|
1180 | # endif
|
---|
1181 | # else /* !IN_RING3 */
|
---|
1182 | # define VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x1000U >= 0x2000U \
|
---|
1183 | && ( ((uintptr_t)(ptr) & 0xffff800000000000ULL) == 0xffff800000000000ULL \
|
---|
1184 | || ((uintptr_t)(ptr) & 0xffff800000000000ULL) == 0) )
|
---|
1185 | # endif /* !IN_RING3 */
|
---|
1186 | #elif defined(RT_ARCH_X86)
|
---|
1187 | # define VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x1000U >= 0x2000U )
|
---|
1188 | #else
|
---|
1189 | # error "Architecture identifier missing / not implemented."
|
---|
1190 | #endif
|
---|
1191 |
|
---|
1192 |
|
---|
1193 | /** @def N_
|
---|
1194 | * The \#define N_ is used mark a string for translation. This is usable in
|
---|
1195 | * any part of the code, as it is only used by the tools that create message
|
---|
1196 | * catalogs. This macro is a no-op as far as the compiler and code generation
|
---|
1197 | * is concerned.
|
---|
1198 | *
|
---|
1199 | * If you want to both mark a string for translation and translate it, use _.
|
---|
1200 | */
|
---|
1201 | #define N_(s) (s)
|
---|
1202 |
|
---|
1203 | /** @def _
|
---|
1204 | * The \#define _ is used mark a string for translation and to translate it in
|
---|
1205 | * one step.
|
---|
1206 | *
|
---|
1207 | * If you want to only mark a string for translation, use N_.
|
---|
1208 | */
|
---|
1209 | #define _(s) gettext(s)
|
---|
1210 |
|
---|
1211 |
|
---|
1212 | /** @def __PRETTY_FUNCTION__
|
---|
1213 | * With GNU C we'd like to use the builtin __PRETTY_FUNCTION__, so define that for the other compilers.
|
---|
1214 | */
|
---|
1215 | #if !defined(__GNUC__) && !defined(__PRETTY_FUNCTION__)
|
---|
1216 | # define __PRETTY_FUNCTION__ __FUNCTION__
|
---|
1217 | #endif
|
---|
1218 |
|
---|
1219 |
|
---|
1220 | /** @def RT_STRICT
|
---|
1221 | * The \#define RT_STRICT controls whether or not assertions and other runtime checks
|
---|
1222 | * should be compiled in or not.
|
---|
1223 | *
|
---|
1224 | * If you want assertions which are not a subject to compile time options use
|
---|
1225 | * the AssertRelease*() flavors.
|
---|
1226 | */
|
---|
1227 | #if !defined(RT_STRICT) && defined(DEBUG)
|
---|
1228 | # define RT_STRICT
|
---|
1229 | #endif
|
---|
1230 |
|
---|
1231 | /** Source position. */
|
---|
1232 | #define RT_SRC_POS __FILE__, __LINE__, __PRETTY_FUNCTION__
|
---|
1233 |
|
---|
1234 | /** Source position declaration. */
|
---|
1235 | #define RT_SRC_POS_DECL const char *pszFile, unsigned iLine, const char *pszFunction
|
---|
1236 |
|
---|
1237 | /** Source position arguments. */
|
---|
1238 | #define RT_SRC_POS_ARGS pszFile, iLine, pszFunction
|
---|
1239 |
|
---|
1240 | /** @} */
|
---|
1241 |
|
---|
1242 |
|
---|
1243 | /** @defgroup grp_rt_cdefs_cpp Special Macros for C++
|
---|
1244 | * @ingroup grp_rt_cdefs
|
---|
1245 | * @{
|
---|
1246 | */
|
---|
1247 |
|
---|
1248 | #ifdef __cplusplus
|
---|
1249 |
|
---|
1250 | /** @def DECLEXPORT_CLASS
|
---|
1251 | * How to declare an exported class. Place this macro after the 'class'
|
---|
1252 | * keyword in the declaration of every class you want to export.
|
---|
1253 | *
|
---|
1254 | * @note It is necessary to use this macro even for inner classes declared
|
---|
1255 | * inside the already exported classes. This is a GCC specific requirement,
|
---|
1256 | * but it seems not to harm other compilers.
|
---|
1257 | */
|
---|
1258 | #if defined(_MSC_VER) || defined(RT_OS_OS2)
|
---|
1259 | # define DECLEXPORT_CLASS __declspec(dllexport)
|
---|
1260 | #else
|
---|
1261 | # ifdef VBOX_HAVE_VISIBILITY_HIDDEN
|
---|
1262 | # define DECLEXPORT_CLASS __attribute__((visibility("default")))
|
---|
1263 | # else
|
---|
1264 | # define DECLEXPORT_CLASS
|
---|
1265 | # endif
|
---|
1266 | #endif
|
---|
1267 |
|
---|
1268 | /** @def DECLIMPORT_CLASS
|
---|
1269 | * How to declare an imported class Place this macro after the 'class'
|
---|
1270 | * keyword in the declaration of every class you want to export.
|
---|
1271 | *
|
---|
1272 | * @note It is necessary to use this macro even for inner classes declared
|
---|
1273 | * inside the already exported classes. This is a GCC specific requirement,
|
---|
1274 | * but it seems not to harm other compilers.
|
---|
1275 | */
|
---|
1276 | #if defined(_MSC_VER) || (defined(RT_OS_OS2) && !defined(__IBMC__) && !defined(__IBMCPP__))
|
---|
1277 | # define DECLIMPORT_CLASS __declspec(dllimport)
|
---|
1278 | #else
|
---|
1279 | # ifdef VBOX_HAVE_VISIBILITY_HIDDEN
|
---|
1280 | # define DECLIMPORT_CLASS __attribute__((visibility("default")))
|
---|
1281 | # else
|
---|
1282 | # define DECLIMPORT_CLASS
|
---|
1283 | # endif
|
---|
1284 | #endif
|
---|
1285 |
|
---|
1286 | /** @def WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP
|
---|
1287 | * Macro to work around error C2593 of the not-so-smart MSVC 7.x ambiguity
|
---|
1288 | * resolver. The following snippet clearly demonstrates the code causing this
|
---|
1289 | * error:
|
---|
1290 | * @code
|
---|
1291 | * class A
|
---|
1292 | * {
|
---|
1293 | * public:
|
---|
1294 | * operator bool() const { return false; }
|
---|
1295 | * operator int*() const { return NULL; }
|
---|
1296 | * };
|
---|
1297 | * int main()
|
---|
1298 | * {
|
---|
1299 | * A a;
|
---|
1300 | * if (!a);
|
---|
1301 | * if (a && 0);
|
---|
1302 | * return 0;
|
---|
1303 | * }
|
---|
1304 | * @endcode
|
---|
1305 | * The code itself seems pretty valid to me and GCC thinks the same.
|
---|
1306 | *
|
---|
1307 | * This macro fixes the compiler error by explicitly overloading implicit
|
---|
1308 | * global operators !, && and || that take the given class instance as one of
|
---|
1309 | * their arguments.
|
---|
1310 | *
|
---|
1311 | * The best is to use this macro right after the class declaration.
|
---|
1312 | *
|
---|
1313 | * @note The macro expands to nothing for compilers other than MSVC.
|
---|
1314 | *
|
---|
1315 | * @param Cls Class to apply the workaround to
|
---|
1316 | */
|
---|
1317 | #if defined(_MSC_VER)
|
---|
1318 | # define WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP(Cls) \
|
---|
1319 | inline bool operator! (const Cls &that) { return !bool (that); } \
|
---|
1320 | inline bool operator&& (const Cls &that, bool b) { return bool (that) && b; } \
|
---|
1321 | inline bool operator|| (const Cls &that, bool b) { return bool (that) || b; } \
|
---|
1322 | inline bool operator&& (bool b, const Cls &that) { return b && bool (that); } \
|
---|
1323 | inline bool operator|| (bool b, const Cls &that) { return b || bool (that); }
|
---|
1324 | #else
|
---|
1325 | # define WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP(Cls)
|
---|
1326 | #endif
|
---|
1327 |
|
---|
1328 | /** @def WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP_TPL
|
---|
1329 | * Version of WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP for template classes.
|
---|
1330 | *
|
---|
1331 | * @param Tpl Name of the template class to apply the workaround to
|
---|
1332 | * @param ArgsDecl arguments of the template, as declared in |<>| after the
|
---|
1333 | * |template| keyword, including |<>|
|
---|
1334 | * @param Args arguments of the template, as specified in |<>| after the
|
---|
1335 | * template class name when using the, including |<>|
|
---|
1336 | *
|
---|
1337 | * Example:
|
---|
1338 | * @code
|
---|
1339 | * // template class declaration
|
---|
1340 | * template <class C>
|
---|
1341 | * class Foo { ... };
|
---|
1342 | * // applied workaround
|
---|
1343 | * WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP_TPL (Foo, <class C>, <C>)
|
---|
1344 | * @endcode
|
---|
1345 | */
|
---|
1346 | #if defined(_MSC_VER)
|
---|
1347 | # define WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP_TPL(Tpl, ArgsDecl, Args) \
|
---|
1348 | template ArgsDecl \
|
---|
1349 | inline bool operator! (const Tpl Args &that) { return !bool (that); } \
|
---|
1350 | template ArgsDecl \
|
---|
1351 | inline bool operator&& (const Tpl Args &that, bool b) { return bool (that) && b; } \
|
---|
1352 | template ArgsDecl \
|
---|
1353 | inline bool operator|| (const Tpl Args &that, bool b) { return bool (that) || b; } \
|
---|
1354 | template ArgsDecl \
|
---|
1355 | inline bool operator&& (bool b, const Tpl Args &that) { return b && bool (that); } \
|
---|
1356 | template ArgsDecl \
|
---|
1357 | inline bool operator|| (bool b, const Tpl Args &that) { return b || bool (that); }
|
---|
1358 | #else
|
---|
1359 | # define WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP_TPL(Tpl, ArgsDecl, Args)
|
---|
1360 | #endif
|
---|
1361 |
|
---|
1362 |
|
---|
1363 | /** @def DECLARE_CLS_COPY_CTOR_ASSIGN_NOOP
|
---|
1364 | * Declares the copy constructor and the assignment operation as inlined no-ops
|
---|
1365 | * (non-existent functions) for the given class. Use this macro inside the
|
---|
1366 | * private section if you want to effectively disable these operations for your
|
---|
1367 | * class.
|
---|
1368 | *
|
---|
1369 | * @param Cls class name to declare for
|
---|
1370 | */
|
---|
1371 |
|
---|
1372 | #define DECLARE_CLS_COPY_CTOR_ASSIGN_NOOP(Cls) \
|
---|
1373 | inline Cls (const Cls &); \
|
---|
1374 | inline Cls &operator= (const Cls &);
|
---|
1375 |
|
---|
1376 |
|
---|
1377 | /** @def DECLARE_CLS_NEW_DELETE_NOOP
|
---|
1378 | * Declares the new and delete operations as no-ops (non-existent functions)
|
---|
1379 | * for the given class. Use this macro inside the private section if you want
|
---|
1380 | * to effectively limit creating class instances on the stack only.
|
---|
1381 | *
|
---|
1382 | * @note The destructor of the given class must not be virtual, otherwise a
|
---|
1383 | * compile time error will occur. Note that this is not a drawback: having
|
---|
1384 | * the virtual destructor for a stack-based class is absolutely useless
|
---|
1385 | * (the real class of the stack-based instance is always known to the compiler
|
---|
1386 | * at compile time, so it will always call the correct destructor).
|
---|
1387 | *
|
---|
1388 | * @param Cls class name to declare for
|
---|
1389 | */
|
---|
1390 | #define DECLARE_CLS_NEW_DELETE_NOOP(Cls) \
|
---|
1391 | inline static void *operator new (size_t); \
|
---|
1392 | inline static void operator delete (void *);
|
---|
1393 |
|
---|
1394 | #endif /* defined(__cplusplus) */
|
---|
1395 |
|
---|
1396 | /** @} */
|
---|
1397 |
|
---|
1398 | #endif
|
---|
1399 |
|
---|