VirtualBox

source: vbox/trunk/include/iprt/assert.h@ 18231

Last change on this file since 18231 was 18050, checked in by vboxsync, 16 years ago

Typos.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 70.9 KB
Line 
1/** @file
2 * IPRT - Assertions.
3 */
4
5/*
6 * Copyright (C) 2006-2007 Sun Microsystems, Inc.
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.virtualbox.org. This file is free software;
10 * you can redistribute it and/or modify it under the terms of the GNU
11 * General Public License (GPL) as published by the Free Software
12 * Foundation, in version 2 as it comes in the "COPYING" file of the
13 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
15 *
16 * The contents of this file may alternatively be used under the terms
17 * of the Common Development and Distribution License Version 1.0
18 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
19 * VirtualBox OSE distribution, in which case the provisions of the
20 * CDDL are applicable instead of those of the GPL.
21 *
22 * You may elect to license modified versions of this file under the
23 * terms and conditions of either the GPL or the CDDL or both.
24 *
25 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
26 * Clara, CA 95054 USA or visit http://www.sun.com if you need
27 * additional information or have any questions.
28 */
29
30#ifndef ___iprt_assert_h
31#define ___iprt_assert_h
32
33#include <iprt/cdefs.h>
34#include <iprt/types.h>
35#include <iprt/stdarg.h>
36
37/** @defgroup grp_rt_assert Assert - Assertions
38 * @ingroup grp_rt
39 *
40 * Assertions are generally used to check precoditions and other
41 * assumptions. Sometimes it is also used to catch odd errors or errors
42 * that one would like to inspect in the debugger. They should not be
43 * used for errors that happen frequently.
44 *
45 * IPRT provides a host of assertion macros, so many that it can be a bit
46 * overwhelming at first. Don't despair, there is a system (surprise).
47 *
48 * First there are four families of assertions:
49 * - Assert - The normal strict build only assertions.
50 * - AssertLogRel - Calls LogRel() in non-strict builds, otherwise like Assert.
51 * - AssertRelease - Triggers in all builds.
52 * - AssertFatal - Triggers in all builds and cannot be continued.
53 *
54 * Then there are variations wrt to argument list and behavior on failure:
55 * - Msg - Custom RTStrPrintf-like message with the assertion message.
56 * - Return - Return the specific rc on failure.
57 * - ReturnVoid - Return (void) on failure.
58 * - Break - Break (out of switch/loop) on failure.
59 * - Stmt - Execute the specified statment(s) on failure.
60 * - RC - Assert RT_SUCCESS.
61 * - RCSuccess - Assert VINF_SUCCESS.
62 *
63 * In additions there is a very special familiy AssertCompile that can be
64 * used for some limited compile checking. Like structure sizes and member
65 * alignment. This family doesn't have the same variations.
66 *
67 *
68 * @remarks As you might've noticed, the macros doesn't follow the
69 * coding guidelines wrt to macros supposedly being all uppercase
70 * and underscored. For various reasons they don't, and it nobody
71 * has complained yet. Wonder why... :-)
72 *
73 * @remarks Each project has its own specific guidelines on how to use
74 * assertions, so the above is just trying to give you the general idea
75 * from the IPRT point of view.
76 *
77 * @{
78 */
79
80__BEGIN_DECLS
81
82/**
83 * The 1st part of an assert message.
84 *
85 * @param pszExpr Expression. Can be NULL.
86 * @param uLine Location line number.
87 * @param pszFile Location file name.
88 * @param pszFunction Location function name.
89 */
90RTDECL(void) RTAssertMsg1(const char *pszExpr, unsigned uLine, const char *pszFile, const char *pszFunction);
91/**
92 * Weak version of RTAssertMsg1
93 *
94 * @copydoc RTAssertMsg1
95 * @todo rename to AssertMsg1Weak
96 */
97RTDECL(void) AssertMsg1(const char *pszExpr, unsigned uLine, const char *pszFile, const char *pszFunction);
98
99/**
100 * The 2nd (optional) part of an assert message.
101 *
102 * @param pszFormat Printf like format string.
103 * @param va Arguments to that string.
104 */
105RTDECL(void) RTAssertMsg2V(const char *pszFormat, va_list va);
106
107/**
108 * The 2nd (optional) part of an assert message.
109 *
110 * @param pszFormat Printf like format string.
111 * @param ... Arguments to that string.
112 */
113RTDECL(void) RTAssertMsg2(const char *pszFormat, ...);
114/** Weak version of RTAssertMsg2
115 * @copydoc RTAssertMsg2
116 * @todo rename to AssertMsg2Weak
117 */
118RTDECL(void) AssertMsg2(const char *pszFormat, ...);
119
120#ifdef IN_RING0
121/**
122 * Panics the system as the result of a fail assertion.
123 */
124RTR0DECL(void) RTR0AssertPanicSystem(void);
125#endif /* IN_RING0 */
126
127/**
128 * Overridable function that decides whether assertions executes the panic
129 * (breakpoint) or not.
130 *
131 * The generic implementation will return true.
132 *
133 * @returns true if the breakpoint should be hit, false if it should be ignored.
134 *
135 * @remark The RTDECL() makes this a bit difficult to override on Windows. So,
136 * you'll have ot use RTASSERT_HAVE_SHOULD_PANIC or
137 * RTASSERT_HAVE_SHOULD_PANIC_PRIVATE there to control the kind of
138 * prototype.
139 */
140#if !defined(RTASSERT_HAVE_SHOULD_PANIC) && !defined(RTASSERT_HAVE_SHOULD_PANIC_PRIVATE)
141RTDECL(bool) RTAssertShouldPanic(void);
142#elif defined(RTASSERT_HAVE_SHOULD_PANIC_PRIVATE)
143bool RTAssertShouldPanic(void);
144#else
145DECLEXPORT(bool) RTCALL RTAssertShouldPanic(void);
146#endif
147
148/** @name Globals for crash analysis
149 * @remarks This is the full potential set, it
150 * @{
151 */
152/** The last assert message, 1st part. */
153extern RTDATADECL(char) g_szRTAssertMsg1[1024];
154/** The last assert message, 2nd part. */
155extern RTDATADECL(char) g_szRTAssertMsg2[2048];
156/** The last assert message, expression. */
157extern RTDATADECL(const char * volatile) g_pszRTAssertExpr;
158/** The last assert message, file name. */
159extern RTDATADECL(const char * volatile) g_pszRTAssertFile;
160/** The last assert message, line number. */
161extern RTDATADECL(uint32_t volatile) g_u32RTAssertLine;
162/** The last assert message, function name. */
163extern RTDATADECL(const char * volatile) g_pszRTAssertFunction;
164/** @} */
165
166__END_DECLS
167
168/** @def RTAssertDebugBreak()
169 * Debugger breakpoint instruction.
170 *
171 * @remarks In the gnu world we add a nop instruction after the int3 to
172 * force gdb to remain at the int3 source line.
173 * @remarks The L4 kernel will try make sense of the breakpoint, thus the jmp.
174 * @remarks This macro does not depend on RT_STRICT.
175 */
176#ifdef __GNUC__
177# ifndef __L4ENV__
178# define RTAssertDebugBreak() do { __asm__ __volatile__ ("int3\n\tnop"); } while (0)
179# else
180# define RTAssertDebugBreak() do { __asm__ __volatile__ ("int3; jmp 1f; 1:"); } while (0)
181# endif
182#elif defined(_MSC_VER) || defined(DOXYGEN_RUNNING)
183# define RTAssertDebugBreak() do { __debugbreak(); } while (0)
184#else
185# error "Unknown compiler"
186#endif
187
188
189
190/** @name Compile time assertions.
191 *
192 * These assertions are used to check structure sizes, memember/size alignments
193 * and similar compile time expressions.
194 *
195 * @{
196 */
197
198/**
199 * RTASSERTTYPE is the type the AssertCompile() macro redefines.
200 * It has no other function and shouldn't be used.
201 * Visual C++ uses this.
202 */
203typedef int RTASSERTTYPE[1];
204
205/**
206 * RTASSERTVAR is the type the AssertCompile() macro redefines.
207 * It has no other function and shouldn't be used.
208 * GCC uses this.
209 */
210#ifdef __GNUC__
211__BEGIN_DECLS
212#endif
213extern int RTASSERTVAR[1];
214#ifdef __GNUC__
215__END_DECLS
216#endif
217
218/** @def AssertCompile
219 * Asserts that a compile-time expression is true. If it's not break the build.
220 * @param expr Expression which should be true.
221 */
222#ifdef __GNUC__
223# define AssertCompile(expr) extern int RTASSERTVAR[1] __attribute__((unused)), RTASSERTVAR[(expr) ? 1 : 0] __attribute__((unused))
224#else
225# define AssertCompile(expr) typedef int RTASSERTTYPE[(expr) ? 1 : 0]
226#endif
227
228/** @def AssertCompileSize
229 * Asserts a size at compile.
230 * @param type The type.
231 * @param size The expected type size.
232 */
233#define AssertCompileSize(type, size) \
234 AssertCompile(sizeof(type) == (size))
235
236/** @def AssertCompileSizeAlignment
237 * Asserts a size alignment at compile.
238 * @param type The type.
239 * @param align The size alignment to assert.
240 */
241#define AssertCompileSizeAlignment(type, align) \
242 AssertCompile(!(sizeof(type) & ((align) - 1)))
243
244/** @def AssertCompileMemberSize
245 * Asserts a member offset alignment at compile.
246 * @param type The type.
247 * @param member The member.
248 * @param size The member size to assert.
249 */
250#define AssertCompileMemberSize(type, member, size) \
251 AssertCompile(RT_SIZEOFMEMB(type, member) == (size))
252
253/** @def AssertCompileMemberSizeAlignment
254 * Asserts a member size alignment at compile.
255 * @param type The type.
256 * @param member The member.
257 * @param align The member size alignment to assert.
258 */
259#define AssertCompileMemberSizeAlignment(type, member, align) \
260 AssertCompile(!(RT_SIZEOFMEMB(type, member) & ((align) - 1)))
261
262/** @def AssertCompileMemberAlignment
263 * Asserts a member offset alignment at compile.
264 * @param type The type.
265 * @param member The member.
266 * @param align The member offset alignment to assert.
267 */
268#if defined(__GNUC__) && defined(__cplusplus)
269# if __GNUC__ >= 4
270# define AssertCompileMemberAlignment(type, member, align) \
271 AssertCompile(!(__builtin_offsetof(type, member) & ((align) - 1)))
272# else
273# define AssertCompileMemberAlignment(type, member, align) \
274 AssertCompile(!(RT_OFFSETOF(type, member) & ((align) - 1)))
275# endif
276#else
277# define AssertCompileMemberAlignment(type, member, align) \
278 AssertCompile(!(RT_OFFSETOF(type, member) & ((align) - 1)))
279#endif
280
281/** @def AssertCompileMemberOffset
282 * Asserts a offset of a structure member at compile.
283 * @param type The type.
284 * @param member The member.
285 * @param off The expected offset.
286 */
287#if defined(__GNUC__) && defined(__cplusplus)
288# if __GNUC__ >= 4
289# define AssertCompileMemberOffset(type, member, off) \
290 AssertCompile(__builtin_offsetof(type, member) == (off))
291# else
292# define AssertCompileMemberOffset(type, member, off) \
293 AssertCompile(RT_OFFSETOF(type, member) == (off))
294# endif
295#else
296# define AssertCompileMemberOffset(type, member, off) \
297 AssertCompile(RT_OFFSETOF(type, member) == (off))
298#endif
299
300/** @} */
301
302
303
304/** @name Assertions
305 *
306 * These assertions will only trigger when RT_STRICT is defined. When it is
307 * undefined they will all be noops and generate no code.
308 *
309 * @{
310 */
311
312/** @def RTAssertDoPanic
313 * Raises an assertion panic appropriate to the current context.
314 * @remarks This macro does not depend on RT_STRICT.
315 */
316#if defined(IN_RING0) \
317 && (defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS))
318# define RTAssertDoPanic() RTR0AssertPanicSystem()
319#else
320# define RTAssertDoPanic() RTAssertDebugBreak()
321#endif
322
323/** @def AssertBreakpoint()
324 * Assertion Breakpoint.
325 * @deprecated Use RTAssertPanic or RTAssertDebugBreak instead.
326 */
327#ifdef RT_STRICT
328# define AssertBreakpoint() RTAssertDebugBreak()
329#else
330# define AssertBreakpoint() do { } while (0)
331#endif
332
333/** @def rtAssertPanic()
334 * If RT_STRICT is defined this macro will invoke RTAssertDoPanic if
335 * RTAssertShouldPanic returns true. If RT_STRICT isn't defined it won't do any
336 * thing.
337 */
338#ifdef RT_STRICT
339# define RTAssertPanic() do { if (RTAssertShouldPanic()) RTAssertDoPanic(); } while (0)
340#else
341# define RTAssertPanic() do { } while (0)
342#endif
343
344/** @def Assert
345 * Assert that an expression is true. If false, hit breakpoint.
346 * @param expr Expression which should be true.
347 */
348#ifdef RT_STRICT
349# define Assert(expr) \
350 do { \
351 if (RT_UNLIKELY(!(expr))) \
352 { \
353 AssertMsg1(#expr, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
354 RTAssertPanic(); \
355 } \
356 } while (0)
357#else
358# define Assert(expr) do { } while (0)
359#endif
360
361
362/** @def AssertReturn
363 * Assert that an expression is true and returns if it isn't.
364 * In RT_STRICT mode it will hit a breakpoint before returning.
365 *
366 * @param expr Expression which should be true.
367 * @param rc What is to be presented to return.
368 */
369#ifdef RT_STRICT
370# define AssertReturn(expr, rc) \
371 do { \
372 if (RT_UNLIKELY(!(expr))) \
373 { \
374 AssertMsg1(#expr, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
375 RTAssertPanic(); \
376 return (rc); \
377 } \
378 } while (0)
379#else
380# define AssertReturn(expr, rc) \
381 do { \
382 if (RT_UNLIKELY(!(expr))) \
383 return (rc); \
384 } while (0)
385#endif
386
387/** @def AssertReturnStmt
388 * Assert that an expression is true, if it isn't execute the given statement
389 * and return rc.
390 *
391 * In RT_STRICT mode it will hit a breakpoint before executing the statment and
392 * returning.
393 *
394 * @param expr Expression which should be true.
395 * @param stmt Statement to execute before returning on failure.
396 * @param rc What is to be presented to return.
397 */
398#ifdef RT_STRICT
399# define AssertReturnStmt(expr, stmt, rc) \
400 do { \
401 if (RT_UNLIKELY(!(expr))) \
402 { \
403 AssertMsg1(#expr, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
404 RTAssertPanic(); \
405 stmt; \
406 return (rc); \
407 } \
408 } while (0)
409#else
410# define AssertReturnStmt(expr, stmt, rc) \
411 do { \
412 if (RT_UNLIKELY(!(expr))) \
413 { \
414 stmt; \
415 return (rc); \
416 } \
417 } while (0)
418#endif
419
420/** @def AssertReturnVoid
421 * Assert that an expression is true and returns if it isn't.
422 * In RT_STRICT mode it will hit a breakpoint before returning.
423 *
424 * @param expr Expression which should be true.
425 */
426#ifdef RT_STRICT
427# define AssertReturnVoid(expr) \
428 do { \
429 if (RT_UNLIKELY(!(expr))) \
430 { \
431 AssertMsg1(#expr, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
432 RTAssertPanic(); \
433 return; \
434 } \
435 } while (0)
436#else
437# define AssertReturnVoid(expr) \
438 do { \
439 if (RT_UNLIKELY(!(expr))) \
440 return; \
441 } while (0)
442#endif
443
444/** @def AssertReturnVoidStmt
445 * Assert that an expression is true, if it isn't execute the given statement
446 * and return.
447 *
448 * In RT_STRICT mode it will hit a breakpoint before returning.
449 *
450 * @param expr Expression which should be true.
451 * @param stmt Statement to execute before returning on failure.
452 */
453#ifdef RT_STRICT
454# define AssertReturnVoidStmt(expr, stmt) \
455 do { \
456 if (RT_UNLIKELY(!(expr))) \
457 { \
458 AssertMsg1(#expr, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
459 RTAssertPanic(); \
460 stmt; \
461 return; \
462 } \
463 } while (0)
464#else
465# define AssertReturnVoidStmt(expr, stmt) \
466 do { \
467 if (RT_UNLIKELY(!(expr))) \
468 { \
469 stmt; \
470 return; \
471 } \
472 } while (0)
473#endif
474
475
476/** @def AssertBreak
477 * Assert that an expression is true and breaks if it isn't.
478 * In RT_STRICT mode it will hit a breakpoint before returning.
479 *
480 * @param expr Expression which should be true.
481 */
482#ifdef RT_STRICT
483# define AssertBreak(expr) \
484 if (RT_UNLIKELY(!(expr))) \
485 { \
486 AssertMsg1(#expr, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
487 RTAssertPanic(); \
488 break; \
489 } else do {} while (0)
490#else
491# define AssertBreak(expr) \
492 if (RT_UNLIKELY(!(expr))) \
493 break; \
494 else do {} while (0)
495#endif
496
497/** @def AssertBreakStmt
498 * Assert that an expression is true and breaks if it isn't.
499 * In RT_STRICT mode it will hit a breakpoint before doing break.
500 *
501 * @param expr Expression which should be true.
502 * @param stmt Statement to execute before break in case of a failed assertion.
503 */
504#ifdef RT_STRICT
505# define AssertBreakStmt(expr, stmt) \
506 if (RT_UNLIKELY(!(expr))) { \
507 AssertMsg1(#expr, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
508 RTAssertPanic(); \
509 stmt; \
510 break; \
511 } else do {} while (0)
512#else
513# define AssertBreakStmt(expr, stmt) \
514 if (RT_UNLIKELY(!(expr))) { \
515 stmt; \
516 break; \
517 } else do {} while (0)
518#endif
519
520
521/** @def AssertMsg
522 * Assert that an expression is true. If it's not print message and hit breakpoint.
523 * @param expr Expression which should be true.
524 * @param a printf argument list (in parenthesis).
525 */
526#ifdef RT_STRICT
527# define AssertMsg(expr, a) \
528 do { \
529 if (RT_UNLIKELY(!(expr))) \
530 { \
531 AssertMsg1(#expr, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
532 AssertMsg2 a; \
533 RTAssertPanic(); \
534 } \
535 } while (0)
536#else
537# define AssertMsg(expr, a) do { } while (0)
538#endif
539
540/** @def AssertMsgReturn
541 * Assert that an expression is true and returns if it isn't.
542 * In RT_STRICT mode it will hit a breakpoint before returning.
543 *
544 * @param expr Expression which should be true.
545 * @param a printf argument list (in parenthesis).
546 * @param rc What is to be presented to return.
547 */
548#ifdef RT_STRICT
549# define AssertMsgReturn(expr, a, rc) \
550 do { \
551 if (RT_UNLIKELY(!(expr))) \
552 { \
553 AssertMsg1(#expr, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
554 AssertMsg2 a; \
555 RTAssertPanic(); \
556 return (rc); \
557 } \
558 } while (0)
559#else
560# define AssertMsgReturn(expr, a, rc) \
561 do { \
562 if (RT_UNLIKELY(!(expr))) \
563 return (rc); \
564 } while (0)
565#endif
566
567/** @def AssertMsgReturnStmt
568 * Assert that an expression is true, if it isn't execute the statement and
569 * return.
570 *
571 * In RT_STRICT mode it will hit a breakpoint before returning.
572 *
573 * @param expr Expression which should be true.
574 * @param a printf argument list (in parenthesis).
575 * @param stmt Statement to execute before break in case of a failed assertion.
576 * @param rc What is to be presented to return.
577 */
578#ifdef RT_STRICT
579# define AssertMsgReturnStmt(expr, a, stmt, rc) \
580 do { \
581 if (RT_UNLIKELY(!(expr))) \
582 { \
583 AssertMsg1(#expr, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
584 AssertMsg2 a; \
585 RTAssertPanic(); \
586 stmt; \
587 return (rc); \
588 } \
589 } while (0)
590#else
591# define AssertMsgReturnStmt(expr, a, stmt, rc) \
592 do { \
593 if (RT_UNLIKELY(!(expr))) \
594 { \
595 stmt; \
596 return (rc); \
597 } \
598 } while (0)
599#endif
600
601/** @def AssertMsgReturnVoid
602 * Assert that an expression is true and returns if it isn't.
603 * In RT_STRICT mode it will hit a breakpoint before returning.
604 *
605 * @param expr Expression which should be true.
606 * @param a printf argument list (in parenthesis).
607 */
608#ifdef RT_STRICT
609# define AssertMsgReturnVoid(expr, a) \
610 do { \
611 if (RT_UNLIKELY(!(expr))) \
612 { \
613 AssertMsg1(#expr, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
614 AssertMsg2 a; \
615 RTAssertPanic(); \
616 return; \
617 } \
618 } while (0)
619#else
620# define AssertMsgReturnVoid(expr, a) \
621 do { \
622 if (RT_UNLIKELY(!(expr))) \
623 return; \
624 } while (0)
625#endif
626
627/** @def AssertMsgReturnVoidStmt
628 * Assert that an expression is true, if it isn't execute the statement and
629 * return.
630 *
631 * In RT_STRICT mode it will hit a breakpoint before returning.
632 *
633 * @param expr Expression which should be true.
634 * @param a printf argument list (in parenthesis).
635 * @param stmt Statement to execute before break in case of a failed assertion.
636 */
637#ifdef RT_STRICT
638# define AssertMsgReturnVoidStmt(expr, a, stmt) \
639 do { \
640 if (RT_UNLIKELY(!(expr))) \
641 { \
642 AssertMsg1(#expr, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
643 AssertMsg2 a; \
644 RTAssertPanic(); \
645 stmt; \
646 return; \
647 } \
648 } while (0)
649#else
650# define AssertMsgReturnVoidStmt(expr, a, stmt) \
651 do { \
652 if (RT_UNLIKELY(!(expr))) \
653 { \
654 stmt; \
655 return; \
656 } \
657 } while (0)
658#endif
659
660
661/** @def AssertMsgBreak
662 * Assert that an expression is true and breaks if it isn't.
663 * In RT_STRICT mode it will hit a breakpoint before returning.
664 *
665 * @param expr Expression which should be true.
666 * @param a printf argument list (in parenthesis).
667 */
668#ifdef RT_STRICT
669# define AssertMsgBreak(expr, a) \
670 if (RT_UNLIKELY(!(expr))) \
671 { \
672 AssertMsg1(#expr, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
673 AssertMsg2 a; \
674 RTAssertPanic(); \
675 break; \
676 } else do {} while (0)
677#else
678# define AssertMsgBreak(expr, a) \
679 if (RT_UNLIKELY(!(expr))) \
680 break; \
681 else do {} while (0)
682#endif
683
684/** @def AssertMsgBreakStmt
685 * Assert that an expression is true and breaks if it isn't.
686 * In RT_STRICT mode it will hit a breakpoint before doing break.
687 *
688 * @param expr Expression which should be true.
689 * @param a printf argument list (in parenthesis).
690 * @param stmt Statement to execute before break in case of a failed assertion.
691 */
692#ifdef RT_STRICT
693# define AssertMsgBreakStmt(expr, a, stmt) \
694 if (RT_UNLIKELY(!(expr))) { \
695 AssertMsg1(#expr, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
696 AssertMsg2 a; \
697 RTAssertPanic(); \
698 stmt; \
699 break; \
700 } else do {} while (0)
701#else
702# define AssertMsgBreakStmt(expr, a, stmt) \
703 if (RT_UNLIKELY(!(expr))) { \
704 stmt; \
705 break; \
706 } else do {} while (0)
707#endif
708
709/** @def AssertFailed
710 * An assertion failed hit breakpoint.
711 */
712#ifdef RT_STRICT
713# define AssertFailed() \
714 do { \
715 AssertMsg1((const char *)0, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
716 RTAssertPanic(); \
717 } while (0)
718#else
719# define AssertFailed() do { } while (0)
720#endif
721
722/** @def AssertFailedReturn
723 * An assertion failed, hit breakpoint (RT_STRICT mode only) and return.
724 *
725 * @param rc The rc to return.
726 */
727#ifdef RT_STRICT
728# define AssertFailedReturn(rc) \
729 do { \
730 AssertMsg1((const char *)0, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
731 RTAssertPanic(); \
732 return (rc); \
733 } while (0)
734#else
735# define AssertFailedReturn(rc) \
736 do { \
737 return (rc); \
738 } while (0)
739#endif
740
741/** @def AssertFailedReturnStmt
742 * An assertion failed, hit breakpoint (RT_STRICT mode only), execute a
743 * statement and return a value.
744 *
745 * @param stmt The statement to execute before returning.
746 * @param rc The value to return.
747 */
748#ifdef RT_STRICT
749# define AssertFailedReturnStmt(stmt, rc) \
750 do { \
751 AssertMsg1((const char *)0, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
752 RTAssertPanic(); \
753 stmt; \
754 return (rc); \
755 } while (0)
756#else
757# define AssertFailedReturnStmt(stmt, rc) \
758 do { \
759 stmt; \
760 return (rc); \
761 } while (0)
762#endif
763
764/** @def AssertFailedReturnVoid
765 * An assertion failed, hit breakpoint (RT_STRICT mode only) and return.
766 */
767#ifdef RT_STRICT
768# define AssertFailedReturnVoid() \
769 do { \
770 AssertMsg1((const char *)0, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
771 RTAssertPanic(); \
772 return; \
773 } while (0)
774#else
775# define AssertFailedReturnVoid() \
776 do { \
777 return; \
778 } while (0)
779#endif
780
781/** @def AssertFailedReturnVoidStmt
782 * An assertion failed, hit breakpoint (RT_STRICT mode only), execute a
783 * statement and return.
784 *
785 * @param stmt The statement to execute before returning.
786 */
787#ifdef RT_STRICT
788# define AssertFailedReturnVoidStmt(stmt) \
789 do { \
790 AssertMsg1((const char *)0, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
791 RTAssertPanic(); \
792 stmt; \
793 return; \
794 } while (0)
795#else
796# define AssertFailedReturnVoidStmt(stmt) \
797 do { \
798 stmt; \
799 return; \
800 } while (0)
801#endif
802
803
804/** @def AssertFailedBreak
805 * An assertion failed, hit breakpoint (RT_STRICT mode only) and break.
806 */
807#ifdef RT_STRICT
808# define AssertFailedBreak() \
809 if (1) { \
810 AssertMsg1((const char *)0, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
811 RTAssertPanic(); \
812 break; \
813 } else do {} while (0)
814#else
815# define AssertFailedBreak() \
816 if (1) \
817 break; \
818 else do {} while (0)
819#endif
820
821/** @def AssertFailedBreakStmt
822 * An assertion failed, hit breakpoint (RT_STRICT mode only), execute
823 * the given statement and break.
824 *
825 * @param stmt Statement to execute before break.
826 */
827#ifdef RT_STRICT
828# define AssertFailedBreakStmt(stmt) \
829 if (1) { \
830 AssertMsg1((const char *)0, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
831 RTAssertPanic(); \
832 stmt; \
833 break; \
834 } else do {} while (0)
835#else
836# define AssertFailedBreakStmt(stmt) \
837 if (1) { \
838 stmt; \
839 break; \
840 } else do {} while (0)
841#endif
842
843
844/** @def AssertMsgFailed
845 * An assertion failed print a message and a hit breakpoint.
846 *
847 * @param a printf argument list (in parenthesis).
848 */
849#ifdef RT_STRICT
850# define AssertMsgFailed(a) \
851 do { \
852 AssertMsg1((const char *)0, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
853 AssertMsg2 a; \
854 RTAssertPanic(); \
855 } while (0)
856#else
857# define AssertMsgFailed(a) do { } while (0)
858#endif
859
860/** @def AssertMsgFailedReturn
861 * An assertion failed, hit breakpoint with message (RT_STRICT mode only) and return.
862 *
863 * @param a printf argument list (in parenthesis).
864 * @param rc What is to be presented to return.
865 */
866#ifdef RT_STRICT
867# define AssertMsgFailedReturn(a, rc) \
868 do { \
869 AssertMsg1((const char *)0, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
870 AssertMsg2 a; \
871 RTAssertPanic(); \
872 return (rc); \
873 } while (0)
874#else
875# define AssertMsgFailedReturn(a, rc) \
876 do { \
877 return (rc); \
878 } while (0)
879#endif
880
881/** @def AssertMsgFailedReturnVoid
882 * An assertion failed, hit breakpoint with message (RT_STRICT mode only) and return.
883 *
884 * @param a printf argument list (in parenthesis).
885 */
886#ifdef RT_STRICT
887# define AssertMsgFailedReturnVoid(a) \
888 do { \
889 AssertMsg1((const char *)0, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
890 AssertMsg2 a; \
891 RTAssertPanic(); \
892 return; \
893 } while (0)
894#else
895# define AssertMsgFailedReturnVoid(a) \
896 do { \
897 return; \
898 } while (0)
899#endif
900
901
902/** @def AssertMsgFailedBreak
903 * An assertion failed, hit breakpoint with message (RT_STRICT mode only) and break.
904 *
905 * @param a printf argument list (in parenthesis).
906 */
907#ifdef RT_STRICT
908# define AssertMsgFailedBreak(a) \
909 if (1) { \
910 AssertMsg1((const char *)0, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
911 AssertMsg2 a; \
912 RTAssertPanic(); \
913 break; \
914 } else do {} while (0)
915#else
916# define AssertMsgFailedBreak(a) \
917 if (1) \
918 break; \
919 else do {} while (0)
920#endif
921
922/** @def AssertMsgFailedBreakStmt
923 * An assertion failed, hit breakpoint (RT_STRICT mode only), execute
924 * the given statement and break.
925 *
926 * @param a printf argument list (in parenthesis).
927 * @param stmt Statement to execute before break.
928 */
929#ifdef RT_STRICT
930# define AssertMsgFailedBreakStmt(a, stmt) \
931 if (1) { \
932 AssertMsg1((const char *)0, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
933 AssertMsg2 a; \
934 RTAssertPanic(); \
935 stmt; \
936 break; \
937 } else do {} while (0)
938#else
939# define AssertMsgFailedBreakStmt(a, stmt) \
940 if (1) { \
941 stmt; \
942 break; \
943 } else do {} while (0)
944#endif
945
946/** @} */
947
948
949
950/** @name Release Log Assertions
951 *
952 * These assertions will work like normal strict assertion when RT_STRICT is
953 * defined and LogRel statements when RT_STRICT is undefined. Typically used for
954 * things which shouldn't go wrong, but when it does you'd like to know one way
955 * or ther other.
956 *
957 * @{
958 */
959
960/** @def RTAssertLogRelMsg1
961 * AssertMsg1 (strict builds) / LogRel wrapper (non-strict).
962 */
963#ifdef RT_STRICT
964# define RTAssertLogRelMsg1(pszExpr, iLine, pszFile, pszFunction) \
965 AssertMsg1(pszExpr, iLine, pszFile, pszFunction)
966#else
967# define RTAssertLogRelMsg1(pszExpr, iLine, pszFile, pszFunction) \
968 LogRel(("AssertLogRel %s(%d) %s: %s\n",\
969 (pszFile), (iLine), (pszFunction), (pszExpr) ))
970#endif
971
972/** @def RTAssertLogRelMsg2
973 * AssertMsg2 (strict builds) / LogRel wrapper (non-strict).
974 */
975#ifdef RT_STRICT
976# define RTAssertLogRelMsg2(a) AssertMsg2 a
977#else
978# define RTAssertLogRelMsg2(a) LogRel(a)
979#endif
980
981/** @def AssertLogRel
982 * Assert that an expression is true.
983 * Strict builds will hit a breakpoint, non-strict will only do LogRel.
984 *
985 * @param expr Expression which should be true.
986 */
987#define AssertLogRel(expr) \
988 do { \
989 if (RT_UNLIKELY(!(expr))) \
990 { \
991 RTAssertLogRelMsg1(#expr, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
992 RTAssertPanic(); \
993 } \
994 } while (0)
995
996/** @def AssertLogRelReturn
997 * Assert that an expression is true, return \a rc if it isn't.
998 * Strict builds will hit a breakpoint, non-strict will only do LogRel.
999 *
1000 * @param expr Expression which should be true.
1001 * @param rc What is to be presented to return.
1002 */
1003#define AssertLogRelReturn(expr, rc) \
1004 do { \
1005 if (RT_UNLIKELY(!(expr))) \
1006 { \
1007 RTAssertLogRelMsg1(#expr, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
1008 RTAssertPanic(); \
1009 return (rc); \
1010 } \
1011 } while (0)
1012
1013/** @def AssertLogRelReturnVoid
1014 * Assert that an expression is true, return void if it isn't.
1015 * Strict builds will hit a breakpoint, non-strict will only do LogRel.
1016 *
1017 * @param expr Expression which should be true.
1018 */
1019#define AssertLogRelReturnVoid(expr) \
1020 do { \
1021 if (RT_UNLIKELY(!(expr))) \
1022 { \
1023 RTAssertLogRelMsg1(#expr, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
1024 RTAssertPanic(); \
1025 return; \
1026 } \
1027 } while (0)
1028
1029/** @def AssertLogRelBreak
1030 * Assert that an expression is true, break if it isn't.
1031 * Strict builds will hit a breakpoint, non-strict will only do LogRel.
1032 *
1033 * @param expr Expression which should be true.
1034 */
1035#define AssertLogRelBreak(expr) \
1036 if (RT_UNLIKELY(!(expr))) \
1037 { \
1038 RTAssertLogRelMsg1(#expr, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
1039 RTAssertPanic(); \
1040 break; \
1041 } \
1042 else do {} while (0)
1043
1044/** @def AssertLogRelBreakStmt
1045 * Assert that an expression is true, execute \a stmt and break if it isn't.
1046 * Strict builds will hit a breakpoint, non-strict will only do LogRel.
1047 *
1048 * @param expr Expression which should be true.
1049 * @param stmt Statement to execute before break in case of a failed assertion.
1050 */
1051#define AssertLogRelBreakStmt(expr, stmt) \
1052 if (RT_UNLIKELY(!(expr))) \
1053 { \
1054 RTAssertLogRelMsg1(#expr, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
1055 RTAssertPanic(); \
1056 stmt; \
1057 break; \
1058 } else do {} while (0)
1059
1060/** @def AssertLogRelMsg
1061 * Assert that an expression is true.
1062 * Strict builds will hit a breakpoint, non-strict will only do LogRel.
1063 *
1064 * @param expr Expression which should be true.
1065 * @param a printf argument list (in parenthesis).
1066 */
1067#define AssertLogRelMsg(expr, a) \
1068 do { \
1069 if (RT_UNLIKELY(!(expr))) \
1070 { \
1071 RTAssertLogRelMsg1(#expr, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
1072 RTAssertLogRelMsg2(a); \
1073 RTAssertPanic(); \
1074 } \
1075 } while (0)
1076
1077/** @def AssertLogRelMsgReturn
1078 * Assert that an expression is true, return \a rc if it isn't.
1079 * Strict builds will hit a breakpoint, non-strict will only do LogRel.
1080 *
1081 * @param expr Expression which should be true.
1082 * @param a printf argument list (in parenthesis).
1083 * @param rc What is to be presented to return.
1084 */
1085#define AssertLogRelMsgReturn(expr, a, rc) \
1086 do { \
1087 if (RT_UNLIKELY(!(expr))) \
1088 { \
1089 RTAssertLogRelMsg1(#expr, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
1090 RTAssertLogRelMsg2(a); \
1091 RTAssertPanic(); \
1092 return (rc); \
1093 } \
1094 } while (0)
1095
1096/** @def AssertLogRelMsgReturnVoid
1097 * Assert that an expression is true, return (void) if it isn't.
1098 * Strict builds will hit a breakpoint, non-strict will only do LogRel.
1099 *
1100 * @param expr Expression which should be true.
1101 * @param a printf argument list (in parenthesis).
1102 */
1103#define AssertLogRelMsgReturnVoid(expr, a) \
1104 do { \
1105 if (RT_UNLIKELY(!(expr))) \
1106 { \
1107 RTAssertLogRelMsg1(#expr, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
1108 RTAssertLogRelMsg2(a); \
1109 RTAssertPanic(); \
1110 return; \
1111 } \
1112 } while (0)
1113
1114/** @def AssertLogRelMsgBreak
1115 * Assert that an expression is true, break if it isn't.
1116 * Strict builds will hit a breakpoint, non-strict will only do LogRel.
1117 *
1118 * @param expr Expression which should be true.
1119 * @param a printf argument list (in parenthesis).
1120 */
1121#define AssertLogRelMsgBreak(expr, a) \
1122 if (RT_UNLIKELY(!(expr))) \
1123 { \
1124 RTAssertLogRelMsg1(#expr, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
1125 RTAssertLogRelMsg2(a); \
1126 RTAssertPanic(); \
1127 break; \
1128 } \
1129 else do {} while (0)
1130
1131/** @def AssertLogRelMsgBreakStmt
1132 * Assert that an expression is true, execute \a stmt and break if it isn't.
1133 * Strict builds will hit a breakpoint, non-strict will only do LogRel.
1134 *
1135 * @param expr Expression which should be true.
1136 * @param a printf argument list (in parenthesis).
1137 * @param stmt Statement to execute before break in case of a failed assertion.
1138 */
1139#define AssertLogRelMsgBreakStmt(expr, a, stmt) \
1140 if (RT_UNLIKELY(!(expr))) \
1141 { \
1142 RTAssertLogRelMsg1(#expr, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
1143 RTAssertLogRelMsg2(a); \
1144 RTAssertPanic(); \
1145 stmt; \
1146 break; \
1147 } else do {} while (0)
1148
1149/** @def AssertLogRelFailed
1150 * An assertion failed.
1151 * Strict builds will hit a breakpoint, non-strict will only do LogRel.
1152 */
1153#define AssertLogRelFailed() \
1154 do { \
1155 RTAssertLogRelMsg1((const char *)0, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
1156 RTAssertPanic(); \
1157 } while (0)
1158
1159/** @def AssertLogRelFailedReturn
1160 * An assertion failed.
1161 * Strict builds will hit a breakpoint, non-strict will only do LogRel.
1162 *
1163 * @param rc What is to be presented to return.
1164 */
1165#define AssertLogRelFailedReturn(rc) \
1166 do { \
1167 RTAssertLogRelMsg1((const char *)0, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
1168 RTAssertPanic(); \
1169 return (rc); \
1170 } while (0)
1171
1172/** @def AssertLogRelFailedReturnVoid
1173 * An assertion failed, hit a breakpoint and return.
1174 * Strict builds will hit a breakpoint, non-strict will only do LogRel.
1175 */
1176#define AssertLogRelFailedReturnVoid() \
1177 do { \
1178 RTAssertLogRelMsg1((const char *)0, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
1179 RTAssertPanic(); \
1180 return; \
1181 } while (0)
1182
1183/** @def AssertLogRelFailedBreak
1184 * An assertion failed, break.
1185 * Strict builds will hit a breakpoint, non-strict will only do LogRel.
1186 */
1187#define AssertLogRelFailedBreak() \
1188 if (1) \
1189 { \
1190 RTAssertLogRelMsg1((const char *)0, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
1191 RTAssertPanic(); \
1192 break; \
1193 } else do {} while (0)
1194
1195/** @def AssertLogRelFailedBreakStmt
1196 * An assertion failed, execute \a stmt and break.
1197 * Strict builds will hit a breakpoint, non-strict will only do LogRel.
1198 *
1199 * @param stmt Statement to execute before break.
1200 */
1201#define AssertLogRelFailedBreakStmt(stmt) \
1202 if (1) \
1203 { \
1204 RTAssertLogRelMsg1((const char *)0, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
1205 RTAssertPanic(); \
1206 stmt; \
1207 break; \
1208 } else do {} while (0)
1209
1210/** @def AssertLogRelMsgFailed
1211 * An assertion failed.
1212 * Strict builds will hit a breakpoint, non-strict will only do LogRel.
1213 *
1214 * @param a printf argument list (in parenthesis).
1215 */
1216#define AssertLogRelMsgFailed(a) \
1217 do { \
1218 RTAssertLogRelMsg1((const char *)0, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
1219 RTAssertLogRelMsg2(a); \
1220 RTAssertPanic(); \
1221 } while (0)
1222
1223/** @def AssertLogRelMsgFailedReturn
1224 * An assertion failed, return \a rc.
1225 * Strict builds will hit a breakpoint, non-strict will only do LogRel.
1226 *
1227 * @param a printf argument list (in parenthesis).
1228 * @param rc What is to be presented to return.
1229 */
1230#define AssertLogRelMsgFailedReturn(a, rc) \
1231 do { \
1232 RTAssertLogRelMsg1((const char *)0, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
1233 RTAssertLogRelMsg2(a); \
1234 RTAssertPanic(); \
1235 return (rc); \
1236 } while (0)
1237
1238/** @def AssertLogRelMsgFailedReturnVoid
1239 * An assertion failed, return void.
1240 * Strict builds will hit a breakpoint, non-strict will only do LogRel.
1241 *
1242 * @param a printf argument list (in parenthesis).
1243 */
1244#define AssertLogRelMsgFailedReturnVoid(a) \
1245 do { \
1246 RTAssertLogRelMsg1((const char *)0, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
1247 RTAssertLogRelMsg2(a); \
1248 RTAssertPanic(); \
1249 return; \
1250 } while (0)
1251
1252/** @def AssertLogRelMsgFailedBreak
1253 * An assertion failed, break.
1254 * Strict builds will hit a breakpoint, non-strict will only do LogRel.
1255 *
1256 * @param a printf argument list (in parenthesis).
1257 */
1258#define AssertLogRelMsgFailedBreak(a) \
1259 if (1)\
1260 { \
1261 RTAssertLogRelMsg1((const char *)0, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
1262 RTAssertLogRelMsg2(a); \
1263 RTAssertPanic(); \
1264 break; \
1265 } else do {} while (0)
1266
1267/** @def AssertLogRelMsgFailedBreakStmt
1268 * An assertion failed, execute \a stmt and break.
1269 * Strict builds will hit a breakpoint, non-strict will only do LogRel.
1270 *
1271 * @param a printf argument list (in parenthesis).
1272 * @param stmt Statement to execute before break.
1273 */
1274#define AssertLogRelMsgFailedBreakStmt(a, stmt) \
1275 if (1) \
1276 { \
1277 RTAssertLogRelMsg1((const char *)0, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
1278 RTAssertLogRelMsg2(a); \
1279 RTAssertPanic(); \
1280 stmt; \
1281 break; \
1282 } else do {} while (0)
1283
1284/** @} */
1285
1286
1287
1288/** @name Release Asserions
1289 *
1290 * These assertions are always enabled.
1291 * @{
1292 */
1293
1294/** @def RTAssertReleasePanic()
1295 * Invokes RTAssertShouldPanic and RTAssertDoPanic.
1296 *
1297 * It might seem odd that RTAssertShouldPanic is necessary when its result isn't
1298 * checked, but it's done since RTAssertShouldPanic is overrideable and might be
1299 * used to bail out before taking down the system (the VMMR0 case).
1300 */
1301#define RTAssertReleasePanic() do { RTAssertShouldPanic(); RTAssertDoPanic(); } while (0)
1302
1303
1304/** @def AssertRelease
1305 * Assert that an expression is true. If it's not hit a breakpoint.
1306 *
1307 * @param expr Expression which should be true.
1308 */
1309#define AssertRelease(expr) \
1310 do { \
1311 if (RT_UNLIKELY(!(expr))) \
1312 { \
1313 AssertMsg1(#expr, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
1314 RTAssertReleasePanic(); \
1315 } \
1316 } while (0)
1317
1318/** @def AssertReleaseReturn
1319 * Assert that an expression is true, hit a breakpoing and return if it isn't.
1320 *
1321 * @param expr Expression which should be true.
1322 * @param rc What is to be presented to return.
1323 */
1324#define AssertReleaseReturn(expr, rc) \
1325 do { \
1326 if (RT_UNLIKELY(!(expr))) \
1327 { \
1328 AssertMsg1(#expr, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
1329 RTAssertReleasePanic(); \
1330 return (rc); \
1331 } \
1332 } while (0)
1333
1334/** @def AssertReleaseReturnVoid
1335 * Assert that an expression is true, hit a breakpoing and return if it isn't.
1336 *
1337 * @param expr Expression which should be true.
1338 */
1339#define AssertReleaseReturnVoid(expr) \
1340 do { \
1341 if (RT_UNLIKELY(!(expr))) \
1342 { \
1343 AssertMsg1(#expr, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
1344 RTAssertReleasePanic(); \
1345 return; \
1346 } \
1347 } while (0)
1348
1349
1350/** @def AssertReleaseBreak
1351 * Assert that an expression is true, hit a breakpoing and break if it isn't.
1352 *
1353 * @param expr Expression which should be true.
1354 */
1355#define AssertReleaseBreak(expr) \
1356 if { \
1357 if (RT_UNLIKELY(!(expr))) \
1358 { \
1359 AssertMsg1(#expr, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
1360 RTAssertReleasePanic(); \
1361 break; \
1362 } \
1363 } else do {} while (0)
1364
1365/** @def AssertReleaseBreakStmt
1366 * Assert that an expression is true, hit a breakpoing and break if it isn't.
1367 *
1368 * @param expr Expression which should be true.
1369 * @param stmt Statement to execute before break in case of a failed assertion.
1370 */
1371#define AssertReleaseBreakStmt(expr, stmt) \
1372 if (RT_UNLIKELY(!(expr))) \
1373 { \
1374 AssertMsg1(#expr, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
1375 RTAssertReleasePanic(); \
1376 stmt; \
1377 break; \
1378 } else do {} while (0)
1379
1380
1381/** @def AssertReleaseMsg
1382 * Assert that an expression is true, print the message and hit a breakpoint if it isn't.
1383 *
1384 * @param expr Expression which should be true.
1385 * @param a printf argument list (in parenthesis).
1386 */
1387#define AssertReleaseMsg(expr, a) \
1388 do { \
1389 if (RT_UNLIKELY(!(expr))) \
1390 { \
1391 AssertMsg1(#expr, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
1392 AssertMsg2 a; \
1393 RTAssertReleasePanic(); \
1394 } \
1395 } while (0)
1396
1397/** @def AssertReleaseMsgReturn
1398 * Assert that an expression is true, print the message and hit a breakpoint and return if it isn't.
1399 *
1400 * @param expr Expression which should be true.
1401 * @param a printf argument list (in parenthesis).
1402 * @param rc What is to be presented to return.
1403 */
1404#define AssertReleaseMsgReturn(expr, a, rc) \
1405 do { \
1406 if (RT_UNLIKELY(!(expr))) \
1407 { \
1408 AssertMsg1(#expr, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
1409 AssertMsg2 a; \
1410 RTAssertReleasePanic(); \
1411 return (rc); \
1412 } \
1413 } while (0)
1414
1415/** @def AssertReleaseMsgReturnVoid
1416 * Assert that an expression is true, print the message and hit a breakpoint and return if it isn't.
1417 *
1418 * @param expr Expression which should be true.
1419 * @param a printf argument list (in parenthesis).
1420 */
1421#define AssertReleaseMsgReturnVoid(expr, a) \
1422 do { \
1423 if (RT_UNLIKELY(!(expr))) \
1424 { \
1425 AssertMsg1(#expr, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
1426 AssertMsg2 a; \
1427 RTAssertReleasePanic(); \
1428 return; \
1429 } \
1430 } while (0)
1431
1432
1433/** @def AssertReleaseMsgBreak
1434 * Assert that an expression is true, print the message and hit a breakpoint and break if it isn't.
1435 *
1436 * @param expr Expression which should be true.
1437 * @param a printf argument list (in parenthesis).
1438 */
1439#define AssertReleaseMsgBreak(expr, a) \
1440 if (RT_UNLIKELY(!(expr))) \
1441 { \
1442 AssertMsg1(#expr, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
1443 AssertMsg2 a; \
1444 RTAssertReleasePanic(); \
1445 break; \
1446 } else do {} while (0)
1447
1448/** @def AssertReleaseMsgBreakStmt
1449 * Assert that an expression is true, print the message and hit a breakpoing and break if it isn't.
1450 *
1451 * @param expr Expression which should be true.
1452 * @param a printf argument list (in parenthesis).
1453 * @param stmt Statement to execute before break in case of a failed assertion.
1454 */
1455#define AssertReleaseMsgBreakStmt(expr, a, stmt) \
1456 if (RT_UNLIKELY(!(expr))) { \
1457 AssertMsg1(#expr, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
1458 AssertMsg2 a; \
1459 RTAssertReleasePanic(); \
1460 stmt; \
1461 break; \
1462 } else do {} while (0)
1463
1464
1465/** @def AssertReleaseFailed
1466 * An assertion failed, hit a breakpoint.
1467 */
1468#define AssertReleaseFailed() \
1469 do { \
1470 AssertMsg1((const char *)0, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
1471 RTAssertReleasePanic(); \
1472 } while (0)
1473
1474/** @def AssertReleaseFailedReturn
1475 * An assertion failed, hit a breakpoint and return.
1476 *
1477 * @param rc What is to be presented to return.
1478 */
1479#define AssertReleaseFailedReturn(rc) \
1480 do { \
1481 AssertMsg1((const char *)0, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
1482 RTAssertReleasePanic(); \
1483 return (rc); \
1484 } while (0)
1485
1486/** @def AssertReleaseFailedReturnVoid
1487 * An assertion failed, hit a breakpoint and return.
1488 */
1489#define AssertReleaseFailedReturnVoid() \
1490 do { \
1491 AssertMsg1((const char *)0, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
1492 RTAssertReleasePanic(); \
1493 return; \
1494 } while (0)
1495
1496
1497/** @def AssertReleaseFailedBreak
1498 * An assertion failed, hit a breakpoint and break.
1499 */
1500#define AssertReleaseFailedBreak() \
1501 if (1) { \
1502 AssertMsg1((const char *)0, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
1503 RTAssertReleasePanic(); \
1504 break; \
1505 } else do {} while (0)
1506
1507/** @def AssertReleaseFailedBreakStmt
1508 * An assertion failed, hit a breakpoint and break.
1509 *
1510 * @param stmt Statement to execute before break.
1511 */
1512#define AssertReleaseFailedBreakStmt(stmt) \
1513 if (1) { \
1514 AssertMsg1((const char *)0, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
1515 RTAssertReleasePanic(); \
1516 stmt; \
1517 break; \
1518 } else do {} while (0)
1519
1520
1521/** @def AssertReleaseMsgFailed
1522 * An assertion failed, print a message and hit a breakpoint.
1523 *
1524 * @param a printf argument list (in parenthesis).
1525 */
1526#define AssertReleaseMsgFailed(a) \
1527 do { \
1528 AssertMsg1((const char *)0, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
1529 AssertMsg2 a; \
1530 RTAssertReleasePanic(); \
1531 } while (0)
1532
1533/** @def AssertReleaseMsgFailedReturn
1534 * An assertion failed, print a message, hit a breakpoint and return.
1535 *
1536 * @param a printf argument list (in parenthesis).
1537 * @param rc What is to be presented to return.
1538 */
1539#define AssertReleaseMsgFailedReturn(a, rc) \
1540 do { \
1541 AssertMsg1((const char *)0, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
1542 AssertMsg2 a; \
1543 RTAssertReleasePanic(); \
1544 return (rc); \
1545 } while (0)
1546
1547/** @def AssertReleaseMsgFailedReturnVoid
1548 * An assertion failed, print a message, hit a breakpoint and return.
1549 *
1550 * @param a printf argument list (in parenthesis).
1551 */
1552#define AssertReleaseMsgFailedReturnVoid(a) \
1553 do { \
1554 AssertMsg1((const char *)0, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
1555 AssertMsg2 a; \
1556 RTAssertReleasePanic(); \
1557 return; \
1558 } while (0)
1559
1560
1561/** @def AssertReleaseMsgFailedBreak
1562 * An assertion failed, print a message, hit a breakpoint and break.
1563 *
1564 * @param a printf argument list (in parenthesis).
1565 */
1566#define AssertReleaseMsgFailedBreak(a) \
1567 if (1) { \
1568 AssertMsg1((const char *)0, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
1569 AssertMsg2 a; \
1570 RTAssertReleasePanic(); \
1571 break; \
1572 } else do {} while (0)
1573
1574/** @def AssertReleaseMsgFailedBreakStmt
1575 * An assertion failed, print a message, hit a breakpoint and break.
1576 *
1577 * @param a printf argument list (in parenthesis).
1578 * @param stmt Statement to execute before break.
1579 */
1580#define AssertReleaseMsgFailedBreakStmt(a, stmt) \
1581 if (1) { \
1582 AssertMsg1((const char *)0, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
1583 AssertMsg2 a; \
1584 RTAssertReleasePanic(); \
1585 stmt; \
1586 break; \
1587 } else do {} while (0)
1588
1589/** @} */
1590
1591
1592
1593/** @name Fatal Assertions
1594 * These are similar to release assertions except that you cannot ignore them in
1595 * any way, they will loop for ever if RTAssertDoPanic returns.
1596 *
1597 * @{
1598 */
1599
1600/** @def AssertFatal
1601 * Assert that an expression is true. If it's not hit a breakpoint (for ever).
1602 *
1603 * @param expr Expression which should be true.
1604 */
1605#define AssertFatal(expr) \
1606 do { \
1607 if (RT_UNLIKELY(!(expr))) \
1608 for (;;) \
1609 { \
1610 AssertMsg1(#expr, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
1611 RTAssertReleasePanic(); \
1612 } \
1613 } while (0)
1614
1615/** @def AssertFatalMsg
1616 * Assert that an expression is true, print the message and hit a breakpoint (for ever) if it isn't.
1617 *
1618 * @param expr Expression which should be true.
1619 * @param a printf argument list (in parenthesis).
1620 */
1621#define AssertFatalMsg(expr, a) \
1622 do { \
1623 if (RT_UNLIKELY(!(expr))) \
1624 for (;;) \
1625 { \
1626 AssertMsg1(#expr, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
1627 AssertMsg2 a; \
1628 RTAssertReleasePanic(); \
1629 } \
1630 } while (0)
1631
1632/** @def AssertFatalFailed
1633 * An assertion failed, hit a breakpoint (for ever).
1634 */
1635#define AssertFatalFailed() \
1636 do { \
1637 for (;;) \
1638 { \
1639 AssertMsg1((const char *)0, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
1640 RTAssertReleasePanic(); \
1641 } \
1642 } while (0)
1643
1644/** @def AssertFatalMsgFailed
1645 * An assertion failed, print a message and hit a breakpoint (for ever).
1646 *
1647 * @param a printf argument list (in parenthesis).
1648 */
1649#define AssertFatalMsgFailed(a) \
1650 do { \
1651 for (;;) \
1652 { \
1653 AssertMsg1((const char *)0, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
1654 AssertMsg2 a; \
1655 RTAssertReleasePanic(); \
1656 } \
1657 } while (0)
1658
1659/** @} */
1660
1661
1662
1663/** @name Convenience Assertions Macros
1664 * @{
1665 */
1666
1667/** @def AssertRC
1668 * Asserts a iprt status code successful.
1669 *
1670 * On failure it will print info about the rc and hit a breakpoint.
1671 *
1672 * @param rc iprt status code.
1673 * @remark rc is references multiple times. In release mode is NOREF()'ed.
1674 */
1675#define AssertRC(rc) AssertMsgRC(rc, ("%Rra\n", (rc)))
1676
1677/** @def AssertRCReturn
1678 * Asserts a iprt status code successful, bitch (RT_STRICT mode only) and return if it isn't.
1679 *
1680 * @param rc iprt status code.
1681 * @param rcRet What is to be presented to return.
1682 * @remark rc is references multiple times. In release mode is NOREF()'ed.
1683 */
1684#define AssertRCReturn(rc, rcRet) AssertMsgRCReturn(rc, ("%Rra\n", (rc)), rcRet)
1685
1686/** @def AssertRCReturnVoid
1687 * Asserts a iprt status code successful, bitch (RT_STRICT mode only) and return if it isn't.
1688 *
1689 * @param rc iprt status code.
1690 * @remark rc is references multiple times. In release mode is NOREF()'ed.
1691 */
1692#define AssertRCReturnVoid(rc) AssertMsgRCReturnVoid(rc, ("%Rra\n", (rc)))
1693
1694/** @def AssertRCBreak
1695 * Asserts a iprt status code successful, bitch (RT_STRICT mode only) and break if it isn't.
1696 *
1697 * @param rc iprt status code.
1698 * @remark rc is references multiple times. In release mode is NOREF()'ed.
1699 */
1700#define AssertRCBreak(rc) AssertMsgRCBreak(rc, ("%Rra\n", (rc)))
1701
1702/** @def AssertRCBreakStmt
1703 * Asserts a iprt status code successful, bitch (RT_STRICT mode only) and break if it isn't.
1704 *
1705 * @param rc iprt status code.
1706 * @param stmt Statement to execute before break in case of a failed assertion.
1707 * @remark rc is references multiple times. In release mode is NOREF()'ed.
1708 */
1709#define AssertRCBreakStmt(rc, stmt) AssertMsgRCBreakStmt(rc, ("%Rra\n", (rc)), stmt)
1710
1711/** @def AssertMsgRC
1712 * Asserts a iprt status code successful.
1713 *
1714 * It prints a custom message and hits a breakpoint on FAILURE.
1715 *
1716 * @param rc iprt status code.
1717 * @param msg printf argument list (in parenthesis).
1718 * @remark rc is references multiple times. In release mode is NOREF()'ed.
1719 */
1720#define AssertMsgRC(rc, msg) \
1721 do { AssertMsg(RT_SUCCESS_NP(rc), msg); NOREF(rc); } while (0)
1722
1723/** @def AssertMsgRCReturn
1724 * Asserts a iprt status code successful and if it's not return the specified status code.
1725 *
1726 * If RT_STRICT is defined the message will be printed and a breakpoint hit before it returns
1727 *
1728 * @param rc iprt status code.
1729 * @param msg printf argument list (in parenthesis).
1730 * @param rcRet What is to be presented to return.
1731 * @remark rc is references multiple times. In release mode is NOREF()'ed.
1732 */
1733#define AssertMsgRCReturn(rc, msg, rcRet) \
1734 do { AssertMsgReturn(RT_SUCCESS_NP(rc), msg, rcRet); NOREF(rc); } while (0)
1735
1736/** @def AssertMsgRCReturnVoid
1737 * Asserts a iprt status code successful and if it's not return.
1738 *
1739 * If RT_STRICT is defined the message will be printed and a breakpoint hit before it returns
1740 *
1741 * @param rc iprt status code.
1742 * @param msg printf argument list (in parenthesis).
1743 * @remark rc is references multiple times. In release mode is NOREF()'ed.
1744 */
1745#define AssertMsgRCReturnVoid(rc, msg) \
1746 do { AssertMsgReturnVoid(RT_SUCCESS_NP(rc), msg); NOREF(rc); } while (0)
1747
1748/** @def AssertMsgRCBreak
1749 * Asserts a iprt status code successful and if it's not break.
1750 *
1751 * If RT_STRICT is defined the message will be printed and a breakpoint hit before it breaks
1752 *
1753 * @param rc iprt status code.
1754 * @param msg printf argument list (in parenthesis).
1755 * @remark rc is references multiple times. In release mode is NOREF()'ed.
1756 */
1757#define AssertMsgRCBreak(rc, msg) \
1758 if (1) { AssertMsgBreak(RT_SUCCESS(rc), msg); NOREF(rc); } else do {} while (0)
1759
1760/** @def AssertMsgRCBreakStmt
1761 * Asserts a iprt status code successful and break if it's not.
1762 *
1763 * If RT_STRICT is defined the message will be printed and a breakpoint hit before it returns
1764 *
1765 * @param rc iprt status code.
1766 * @param msg printf argument list (in parenthesis).
1767 * @param stmt Statement to execute before break in case of a failed assertion.
1768 * @remark rc is references multiple times. In release mode is NOREF()'ed.
1769 */
1770#define AssertMsgRCBreakStmt(rc, msg, stmt) \
1771 if (1) { AssertMsgBreakStmt(RT_SUCCESS_NP(rc), msg, stmt); NOREF(rc); } else do {} while (0)
1772
1773/** @def AssertRCSuccess
1774 * Asserts an iprt status code equals VINF_SUCCESS.
1775 *
1776 * On failure it will print info about the rc and hit a breakpoint.
1777 *
1778 * @param rc iprt status code.
1779 * @remark rc is references multiple times. In release mode is NOREF()'ed.
1780 */
1781#define AssertRCSuccess(rc) AssertMsg((rc) == VINF_SUCCESS, ("%Rra\n", (rc)))
1782
1783/** @def AssertRCSuccessReturn
1784 * Asserts that an iprt status code equals VINF_SUCCESS, bitch (RT_STRICT mode only) and return if it isn't.
1785 *
1786 * @param rc iprt status code.
1787 * @param rcRet What is to be presented to return.
1788 * @remark rc is references multiple times. In release mode is NOREF()'ed.
1789 */
1790#define AssertRCSuccessReturn(rc, rcRet) AssertMsgReturn((rc) == VINF_SUCCESS, ("%Rra\n", (rc)), rcRet)
1791
1792/** @def AssertRCSuccessReturnVoid
1793 * Asserts that an iprt status code equals VINF_SUCCESS, bitch (RT_STRICT mode only) and return if it isn't.
1794 *
1795 * @param rc iprt status code.
1796 * @remark rc is references multiple times. In release mode is NOREF()'ed.
1797 */
1798#define AssertRCSuccessReturnVoid(rc) AssertMsgReturnVoid((rc) == VINF_SUCCESS, ("%Rra\n", (rc)))
1799
1800/** @def AssertRCSuccessBreak
1801 * Asserts that an iprt status code equals VINF_SUCCESS, bitch (RT_STRICT mode only) and break if it isn't.
1802 *
1803 * @param rc iprt status code.
1804 * @remark rc is references multiple times. In release mode is NOREF()'ed.
1805 */
1806#define AssertRCSuccessBreak(rc) AssertMsgBreak((rc) == VINF_SUCCESS, ("%Rra\n", (rc)))
1807
1808/** @def AssertRCSuccessBreakStmt
1809 * Asserts that an iprt status code equals VINF_SUCCESS, bitch (RT_STRICT mode only) and break if it isn't.
1810 *
1811 * @param rc iprt status code.
1812 * @param stmt Statement to execute before break in case of a failed assertion.
1813 * @remark rc is references multiple times. In release mode is NOREF()'ed.
1814 */
1815#define AssertRCSuccessBreakStmt(rc, stmt) AssertMsgBreakStmt((rc) == VINF_SUCCESS, ("%Rra\n", (rc)), stmt)
1816
1817
1818/** @def AssertLogRelRC
1819 * Asserts a iprt status code successful.
1820 *
1821 * @param rc iprt status code.
1822 * @remark rc is references multiple times.
1823 */
1824#define AssertLogRelRC(rc) AssertLogRelMsgRC(rc, ("%Rra\n", (rc)))
1825
1826/** @def AssertLogRelRCReturn
1827 * Asserts a iprt status code successful, returning \a rc if it isn't.
1828 *
1829 * @param rc iprt status code.
1830 * @param rcRet What is to be presented to return.
1831 * @remark rc is references multiple times.
1832 */
1833#define AssertLogRelRCReturn(rc, rcRet) AssertLogRelMsgRCReturn(rc, ("%Rra\n", (rc)), rcRet)
1834
1835/** @def AssertLogRelRCReturnVoid
1836 * Asserts a iprt status code successful, returning (void) if it isn't.
1837 *
1838 * @param rc iprt status code.
1839 * @remark rc is references multiple times.
1840 */
1841#define AssertLogRelRCReturnVoid(rc) AssertLogRelMsgRCReturnVoid(rc, ("%Rra\n", (rc)))
1842
1843/** @def AssertLogRelRCBreak
1844 * Asserts a iprt status code successful, breaking if it isn't.
1845 *
1846 * @param rc iprt status code.
1847 * @remark rc is references multiple times.
1848 */
1849#define AssertLogRelRCBreak(rc) AssertLogRelMsgRCBreak(rc, ("%Rra\n", (rc)))
1850
1851/** @def AssertLogRelRCBreakStmt
1852 * Asserts a iprt status code successful, execute \a statement and break if it isn't.
1853 *
1854 * @param rc iprt status code.
1855 * @param stmt Statement to execute before break in case of a failed assertion.
1856 * @remark rc is references multiple times.
1857 */
1858#define AssertLogRelRCBreakStmt(rc, stmt) AssertLogRelMsgRCBreakStmt(rc, ("%Rra\n", (rc)), stmt)
1859
1860/** @def AssertLogRelMsgRC
1861 * Asserts a iprt status code successful.
1862 *
1863 * @param rc iprt status code.
1864 * @param msg printf argument list (in parenthesis).
1865 * @remark rc is references multiple times.
1866 */
1867#define AssertLogRelMsgRC(rc, msg) AssertLogRelMsg(RT_SUCCESS_NP(rc), msg)
1868
1869/** @def AssertLogRelMsgRCReturn
1870 * Asserts a iprt status code successful.
1871 *
1872 * @param rc iprt status code.
1873 * @param msg printf argument list (in parenthesis).
1874 * @param rcRet What is to be presented to return.
1875 * @remark rc is references multiple times.
1876 */
1877#define AssertLogRelMsgRCReturn(rc, msg, rcRet) AssertLogRelMsgReturn(RT_SUCCESS_NP(rc), msg, rcRet)
1878
1879/** @def AssertLogRelMsgRCReturnVoid
1880 * Asserts a iprt status code successful.
1881 *
1882 * @param rc iprt status code.
1883 * @param msg printf argument list (in parenthesis).
1884 * @remark rc is references multiple times.
1885 */
1886#define AssertLogRelMsgRCReturnVoid(rc, msg) AssertLogRelMsgReturnVoid(RT_SUCCESS_NP(rc), msg)
1887
1888/** @def AssertLogRelMsgRCBreak
1889 * Asserts a iprt status code successful.
1890 *
1891 * @param rc iprt status code.
1892 * @param msg printf argument list (in parenthesis).
1893 * @remark rc is references multiple times.
1894 */
1895#define AssertLogRelMsgRCBreak(rc, msg) AssertLogRelMsgBreak(RT_SUCCESS(rc), msg)
1896
1897/** @def AssertLogRelMsgRCBreakStmt
1898 * Asserts a iprt status code successful, execute \a stmt and break if it isn't.
1899 *
1900 * @param rc iprt status code.
1901 * @param msg printf argument list (in parenthesis).
1902 * @param stmt Statement to execute before break in case of a failed assertion.
1903 * @remark rc is references multiple times.
1904 */
1905#define AssertLogRelMsgRCBreakStmt(rc, msg, stmt) AssertLogRelMsgBreakStmt(RT_SUCCESS_NP(rc), msg, stmt)
1906
1907/** @def AssertLogRelRCSuccess
1908 * Asserts that an iprt status code equals VINF_SUCCESS.
1909 *
1910 * @param rc iprt status code.
1911 * @remark rc is references multiple times.
1912 */
1913#define AssertLogRelRCSuccess(rc) AssertLogRelMsg((rc) == VINF_SUCCESS, ("%Rra\n", (rc)))
1914
1915/** @def AssertLogRelRCSuccessReturn
1916 * Asserts that an iprt status code equals VINF_SUCCESS.
1917 *
1918 * @param rc iprt status code.
1919 * @param rcRet What is to be presented to return.
1920 * @remark rc is references multiple times.
1921 */
1922#define AssertLogRelRCSuccessReturn(rc, rcRet) AssertLogRelMsgReturn((rc) == VINF_SUCCESS, ("%Rra\n", (rc)), rcRet)
1923
1924/** @def AssertLogRelRCSuccessReturnVoid
1925 * Asserts that an iprt status code equals VINF_SUCCESS.
1926 *
1927 * @param rc iprt status code.
1928 * @remark rc is references multiple times.
1929 */
1930#define AssertLogRelRCSuccessReturnVoid(rc) AssertLogRelMsgReturnVoid((rc) == VINF_SUCCESS, ("%Rra\n", (rc)))
1931
1932/** @def AssertLogRelRCSuccessBreak
1933 * Asserts that an iprt status code equals VINF_SUCCESS.
1934 *
1935 * @param rc iprt status code.
1936 * @remark rc is references multiple times.
1937 */
1938#define AssertLogRelRCSuccessBreak(rc) AssertLogRelMsgBreak((rc) == VINF_SUCCESS, ("%Rra\n", (rc)))
1939
1940/** @def AssertLogRelRCSuccessBreakStmt
1941 * Asserts that an iprt status code equals VINF_SUCCESS.
1942 *
1943 * @param rc iprt status code.
1944 * @param stmt Statement to execute before break in case of a failed assertion.
1945 * @remark rc is references multiple times.
1946 */
1947#define AssertLogRelRCSuccessBreakStmt(rc, stmt) AssertLogRelMsgBreakStmt((rc) == VINF_SUCCESS, ("%Rra\n", (rc)), stmt)
1948
1949
1950/** @def AssertReleaseRC
1951 * Asserts a iprt status code successful.
1952 *
1953 * On failure information about the error will be printed and a breakpoint hit.
1954 *
1955 * @param rc iprt status code.
1956 * @remark rc is references multiple times.
1957 */
1958#define AssertReleaseRC(rc) AssertReleaseMsgRC(rc, ("%Rra\n", (rc)))
1959
1960/** @def AssertReleaseRCReturn
1961 * Asserts a iprt status code successful, returning if it isn't.
1962 *
1963 * On failure information about the error will be printed, a breakpoint hit
1964 * and finally returning from the function if the breakpoint is somehow ignored.
1965 *
1966 * @param rc iprt status code.
1967 * @param rcRet What is to be presented to return.
1968 * @remark rc is references multiple times.
1969 */
1970#define AssertReleaseRCReturn(rc, rcRet) AssertReleaseMsgRCReturn(rc, ("%Rra\n", (rc)), rcRet)
1971
1972/** @def AssertReleaseRCReturnVoid
1973 * Asserts a iprt status code successful, returning if it isn't.
1974 *
1975 * On failure information about the error will be printed, a breakpoint hit
1976 * and finally returning from the function if the breakpoint is somehow ignored.
1977 *
1978 * @param rc iprt status code.
1979 * @remark rc is references multiple times.
1980 */
1981#define AssertReleaseRCReturnVoid(rc) AssertReleaseMsgRCReturnVoid(rc, ("%Rra\n", (rc)))
1982
1983/** @def AssertReleaseRCBreak
1984 * Asserts a iprt status code successful, breaking if it isn't.
1985 *
1986 * On failure information about the error will be printed, a breakpoint hit
1987 * and finally breaking the current statement if the breakpoint is somehow ignored.
1988 *
1989 * @param rc iprt status code.
1990 * @remark rc is references multiple times.
1991 */
1992#define AssertReleaseRCBreak(rc) AssertReleaseMsgRCBreak(rc, ("%Rra\n", (rc)))
1993
1994/** @def AssertReleaseRCBreakStmt
1995 * Asserts a iprt status code successful, break if it isn't.
1996 *
1997 * On failure information about the error will be printed, a breakpoint hit
1998 * and finally the break statement will be issued if the breakpoint is somehow ignored.
1999 *
2000 * @param rc iprt status code.
2001 * @param stmt Statement to execute before break in case of a failed assertion.
2002 * @remark rc is references multiple times.
2003 */
2004#define AssertReleaseRCBreakStmt(rc, stmt) AssertReleaseMsgRCBreakStmt(rc, ("%Rra\n", (rc)), stmt)
2005
2006/** @def AssertReleaseMsgRC
2007 * Asserts a iprt status code successful.
2008 *
2009 * On failure a custom message is printed and a breakpoint is hit.
2010 *
2011 * @param rc iprt status code.
2012 * @param msg printf argument list (in parenthesis).
2013 * @remark rc is references multiple times.
2014 */
2015#define AssertReleaseMsgRC(rc, msg) AssertReleaseMsg(RT_SUCCESS_NP(rc), msg)
2016
2017/** @def AssertReleaseMsgRCReturn
2018 * Asserts a iprt status code successful.
2019 *
2020 * On failure a custom message is printed, a breakpoint is hit, and finally
2021 * returning from the function if the breakpoint is showhow ignored.
2022 *
2023 * @param rc iprt status code.
2024 * @param msg printf argument list (in parenthesis).
2025 * @param rcRet What is to be presented to return.
2026 * @remark rc is references multiple times.
2027 */
2028#define AssertReleaseMsgRCReturn(rc, msg, rcRet) AssertReleaseMsgReturn(RT_SUCCESS_NP(rc), msg, rcRet)
2029
2030/** @def AssertReleaseMsgRCReturnVoid
2031 * Asserts a iprt status code successful.
2032 *
2033 * On failure a custom message is printed, a breakpoint is hit, and finally
2034 * returning from the function if the breakpoint is showhow ignored.
2035 *
2036 * @param rc iprt status code.
2037 * @param msg printf argument list (in parenthesis).
2038 * @remark rc is references multiple times.
2039 */
2040#define AssertReleaseMsgRCReturnVoid(rc, msg) AssertReleaseMsgReturnVoid(RT_SUCCESS_NP(rc), msg)
2041
2042/** @def AssertReleaseMsgRCBreak
2043 * Asserts a iprt status code successful.
2044 *
2045 * On failure a custom message is printed, a breakpoint is hit, and finally
2046 * breaking the current status if the breakpoint is showhow ignored.
2047 *
2048 * @param rc iprt status code.
2049 * @param msg printf argument list (in parenthesis).
2050 * @remark rc is references multiple times.
2051 */
2052#define AssertReleaseMsgRCBreak(rc, msg) AssertReleaseMsgBreak(RT_SUCCESS(rc), msg)
2053
2054/** @def AssertReleaseMsgRCBreakStmt
2055 * Asserts a iprt status code successful.
2056 *
2057 * On failure a custom message is printed, a breakpoint is hit, and finally
2058 * the brean statement is issued if the breakpoint is showhow ignored.
2059 *
2060 * @param rc iprt status code.
2061 * @param msg printf argument list (in parenthesis).
2062 * @param stmt Statement to execute before break in case of a failed assertion.
2063 * @remark rc is references multiple times.
2064 */
2065#define AssertReleaseMsgRCBreakStmt(rc, msg, stmt) AssertReleaseMsgBreakStmt(RT_SUCCESS_NP(rc), msg, stmt)
2066
2067/** @def AssertReleaseRCSuccess
2068 * Asserts that an iprt status code equals VINF_SUCCESS.
2069 *
2070 * On failure information about the error will be printed and a breakpoint hit.
2071 *
2072 * @param rc iprt status code.
2073 * @remark rc is references multiple times.
2074 */
2075#define AssertReleaseRCSuccess(rc) AssertReleaseMsg((rc) == VINF_SUCCESS, ("%Rra\n", (rc)))
2076
2077/** @def AssertReleaseRCSuccessReturn
2078 * Asserts that an iprt status code equals VINF_SUCCESS.
2079 *
2080 * On failure information about the error will be printed, a breakpoint hit
2081 * and finally returning from the function if the breakpoint is somehow ignored.
2082 *
2083 * @param rc iprt status code.
2084 * @param rcRet What is to be presented to return.
2085 * @remark rc is references multiple times.
2086 */
2087#define AssertReleaseRCSuccessReturn(rc, rcRet) AssertReleaseMsgReturn((rc) == VINF_SUCCESS, ("%Rra\n", (rc)), rcRet)
2088
2089/** @def AssertReleaseRCSuccessReturnVoid
2090 * Asserts that an iprt status code equals VINF_SUCCESS.
2091 *
2092 * On failure information about the error will be printed, a breakpoint hit
2093 * and finally returning from the function if the breakpoint is somehow ignored.
2094 *
2095 * @param rc iprt status code.
2096 * @remark rc is references multiple times.
2097 */
2098#define AssertReleaseRCSuccessReturnVoid(rc) AssertReleaseMsgReturnVoid((rc) == VINF_SUCCESS, ("%Rra\n", (rc)))
2099
2100/** @def AssertReleaseRCSuccessBreak
2101 * Asserts that an iprt status code equals VINF_SUCCESS.
2102 *
2103 * On failure information about the error will be printed, a breakpoint hit
2104 * and finally breaking the current statement if the breakpoint is somehow ignored.
2105 *
2106 * @param rc iprt status code.
2107 * @remark rc is references multiple times.
2108 */
2109#define AssertReleaseRCSuccessBreak(rc) AssertReleaseMsgBreak((rc) == VINF_SUCCESS, ("%Rra\n", (rc)))
2110
2111/** @def AssertReleaseRCSuccessBreakStmt
2112 * Asserts that an iprt status code equals VINF_SUCCESS.
2113 *
2114 * On failure information about the error will be printed, a breakpoint hit
2115 * and finally the break statement will be issued if the breakpoint is somehow ignored.
2116 *
2117 * @param rc iprt status code.
2118 * @param stmt Statement to execute before break in case of a failed assertion.
2119 * @remark rc is references multiple times.
2120 */
2121#define AssertReleaseRCSuccessBreakStmt(rc, stmt) AssertReleaseMsgBreakStmt((rc) == VINF_SUCCESS, ("%Rra\n", (rc)), stmt)
2122
2123
2124/** @def AssertFatalRC
2125 * Asserts a iprt status code successful.
2126 *
2127 * On failure information about the error will be printed and a breakpoint hit.
2128 *
2129 * @param rc iprt status code.
2130 * @remark rc is references multiple times.
2131 */
2132#define AssertFatalRC(rc) AssertFatalMsgRC(rc, ("%Rra\n", (rc)))
2133
2134/** @def AssertReleaseMsgRC
2135 * Asserts a iprt status code successful.
2136 *
2137 * On failure a custom message is printed and a breakpoint is hit.
2138 *
2139 * @param rc iprt status code.
2140 * @param msg printf argument list (in parenthesis).
2141 * @remark rc is references multiple times.
2142 */
2143#define AssertFatalMsgRC(rc, msg) AssertFatalMsg(RT_SUCCESS_NP(rc), msg)
2144
2145/** @def AssertFatalRCSuccess
2146 * Asserts that an iprt status code equals VINF_SUCCESS.
2147 *
2148 * On failure information about the error will be printed and a breakpoint hit.
2149 *
2150 * @param rc iprt status code.
2151 * @remark rc is references multiple times.
2152 */
2153#define AssertFatalRCSuccess(rc) AssertFatalMsg((rc) == VINF_SUCCESS, ("%Rra\n", (rc)))
2154
2155
2156/** @def AssertPtr
2157 * Asserts that a pointer is valid.
2158 *
2159 * @param pv The pointer.
2160 */
2161#define AssertPtr(pv) AssertMsg(VALID_PTR(pv), ("%p\n", (pv)))
2162
2163/** @def AssertPtrReturn
2164 * Asserts that a pointer is valid.
2165 *
2166 * @param pv The pointer.
2167 * @param rcRet What is to be presented to return.
2168 */
2169#define AssertPtrReturn(pv, rcRet) AssertMsgReturn(VALID_PTR(pv), ("%p\n", (pv)), rcRet)
2170
2171/** @def AssertPtrReturnVoid
2172 * Asserts that a pointer is valid.
2173 *
2174 * @param pv The pointer.
2175 */
2176#define AssertPtrReturnVoid(pv) AssertMsgReturnVoid(VALID_PTR(pv), ("%p\n", (pv)))
2177
2178/** @def AssertPtrBreak
2179 * Asserts that a pointer is valid.
2180 *
2181 * @param pv The pointer.
2182 */
2183#define AssertPtrBreak(pv) AssertMsgBreak(VALID_PTR(pv), ("%p\n", (pv)))
2184
2185/** @def AssertPtrBreakStmt
2186 * Asserts that a pointer is valid.
2187 *
2188 * @param pv The pointer.
2189 * @param stmt Statement to execute before break in case of a failed assertion.
2190 */
2191#define AssertPtrBreakStmt(pv, stmt) AssertMsgBreakStmt(VALID_PTR(pv), ("%p\n", (pv)), stmt)
2192
2193/** @def AssertPtrNull
2194 * Asserts that a pointer is valid or NULL.
2195 *
2196 * @param pv The pointer.
2197 */
2198#define AssertPtrNull(pv) AssertMsg(VALID_PTR(pv) || (pv) == NULL, ("%p\n", (pv)))
2199
2200/** @def AssertPtrNullReturn
2201 * Asserts that a pointer is valid or NULL.
2202 *
2203 * @param pv The pointer.
2204 * @param rcRet What is to be presented to return.
2205 */
2206#define AssertPtrNullReturn(pv, rcRet) AssertMsgReturn(VALID_PTR(pv) || (pv) == NULL, ("%p\n", (pv)), rcRet)
2207
2208/** @def AssertPtrNullReturnVoid
2209 * Asserts that a pointer is valid or NULL.
2210 *
2211 * @param pv The pointer.
2212 */
2213#define AssertPtrNullReturnVoid(pv) AssertMsgReturnVoid(VALID_PTR(pv) || (pv) == NULL, ("%p\n", (pv)))
2214
2215/** @def AssertPtrNullBreak
2216 * Asserts that a pointer is valid or NULL.
2217 *
2218 * @param pv The pointer.
2219 */
2220#define AssertPtrNullBreak(pv) AssertMsgBreak(VALID_PTR(pv) || (pv) == NULL, ("%p\n", (pv)))
2221
2222/** @def AssertPtrNullBreakStmt
2223 * Asserts that a pointer is valid or NULL.
2224 *
2225 * @param pv The pointer.
2226 * @param stmt Statement to execute before break in case of a failed assertion.
2227 */
2228#define AssertPtrNullBreakStmt(pv, stmt) AssertMsgBreakStmt(VALID_PTR(pv) || (pv) == NULL, ("%p\n", (pv)), stmt)
2229
2230/** @def AssertGCPhys32
2231 * Asserts that the high dword of a physical address is zero
2232 *
2233 * @param GCPhys The address (RTGCPHYS).
2234 */
2235#define AssertGCPhys32(GCPhys) AssertMsg(VALID_PHYS32(GCPhys), ("%RGp\n", (RTGCPHYS)(GCPhys)))
2236
2237/** @def AssertGCPtr32
2238 * Asserts that the high dword of a physical address is zero
2239 *
2240 * @param GCPtr The address (RTGCPTR).
2241 */
2242#if GC_ARCH_BITS == 32
2243# define AssertGCPtr32(GCPtr) do { } while (0)
2244#else
2245# define AssertGCPtr32(GCPtr) AssertMsg(!((GCPtr) & UINT64_C(0xffffffff00000000)), ("%RGv\n", GCPtr))
2246#endif
2247
2248/** @def AssertForEach
2249 * Equivalent to Assert for each value of the variable from the starting
2250 * value to the finishing one.
2251 *
2252 * @param var Name of the counter variable.
2253 * @param vartype Type of the counter variable.
2254 * @param first Lowest inclusive value of the counter variable.
2255 * This must be free from side effects.
2256 * @param end Highest exclusive value of the counter variable.
2257 * This must be free from side effects.
2258 * @param expr Expression which should be true for each value of @a var.
2259 */
2260#define AssertForEach(var, vartype, first, end, expr) \
2261 do { \
2262 vartype var; \
2263 Assert((first) == (first) && (end) == (end)); /* partial check for side effects */ \
2264 for (var = (first); var < (end); var++) \
2265 AssertMsg(expr, ("%s = %#RX64 (%RI64)", #var, (uint64_t)var, (int64_t)var)); \
2266 } while (0)
2267
2268/** @} */
2269
2270/** @} */
2271
2272#endif
2273
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette