Commit made by Daniel, including the implementation of the daemon.
[vdi_driver.git] / src / func_defines.h
blobb893745345859010128614aece1e098276d39b15
1 #ifndef FUNC_DEFINES_H
2 #define FUNC_DEFINES_H
4 #include "cdefs.h"
6 /** Get major version from combined version. */
7 #define VDI_GET_VERSION_MAJOR(uVer) ((uVer) >> 16)
8 /** Get minor version from combined version. */
9 #define VDI_GET_VERSION_MINOR(uVer) ((uVer) & 0xffff)
11 /** @def AssertFailed
12 * An assertion failed hit breakpoint.
14 #ifdef RT_STRICT
15 # define AssertFailed() \
16 do { \
17 AssertMsg1((const char *)0, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
18 AssertBreakpoint(); \
19 } while (0)
20 #else
21 # define AssertFailed() do { } while (0)
22 #endif
24 /** @def AssertMsg
25 * Assert that an expression is true. If it's not print message and hit breakpoint.
26 * @param expr Expression which should be true.
27 * @param a printf argument list (in parenthesis).
29 #ifdef RT_STRICT
30 # define AssertMsg(expr, a) \
31 do { \
32 if (RT_UNLIKELY(!(expr))) \
33 { \
34 AssertMsg1(#expr, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
35 AssertMsg2 a; \
36 AssertBreakpoint(); \
37 } \
38 } while (0)
39 #else
40 # define AssertMsg(expr, a) do { } while (0)
41 #endif
43 /** @def AssertReleaseMsg
44 * Assert that an expression is true, print the message and hit a breakpoint if it isn't.
46 * @param expr Expression which should be true.
47 * @param a printf argument list (in parenthesis).
49 #ifdef RT_STRICT
50 #define AssertReleaseMsg(expr, a) \
51 do { \
52 if (RT_UNLIKELY(!(expr))) \
53 { \
54 AssertMsg1(#expr, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
55 AssertMsg2 a; \
56 AssertReleaseBreakpoint(); \
57 } \
58 } while (0)
59 #else
60 # define AssertReleaseMsg(expr, a) do { } while (0)
61 #endif
63 /** @def RT_ALIGN_T
64 * Align macro.
65 * @param u Value to align.
66 * @param uAlignment The alignment. Power of two!
67 * @param type Integer type to use while aligning.
68 * @remark This macro is the prefered alignment macro, it doesn't have any of the pitfalls RT_ALIGN has.
70 #define RT_ALIGN_T(u, uAlignment, type) ( ((type)(u) + ((uAlignment) - 1)) & ~(type)((uAlignment) - 1) )
72 /** @def RT_ALIGN_32
73 * Align macro for a 32-bit value.
74 * @param u32 Value to align.
75 * @param uAlignment The alignment. Power of two!
77 #define RT_ALIGN_32(u32, uAlignment) RT_ALIGN_T(u32, uAlignment, uint32_t)
79 /** @def Assert
80 * Assert that an expression is true. If it's not hit breakpoint.
81 * @param expr Expression which should be true.
83 #ifdef RT_STRICT
84 # define Assert(expr) \
85 do { \
86 if (RT_UNLIKELY(!(expr))) \
87 { \
88 AssertMsg1(#expr, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
89 AssertBreakpoint(); \
90 } \
91 } while (0)
92 #else
93 # define Assert(expr) do { } while (0)
94 #endif
96 /** @def RT_MIN
97 * Finds the minimum value.
98 * @returns The lower of the two.
99 * @param Value1 Value 1
100 * @param Value2 Value 2
102 #define RT_MIN(Value1, Value2) ((Value1) <= (Value2) ? (Value1) : (Value2))
104 /** @def AssertMsgRC
105 * Asserts a iprt status code successful.
107 * It prints a custom message and hits a breakpoint on FAILURE.
109 * @param rc iprt status code.
110 * @param msg printf argument list (in parenthesis).
111 * @remark rc is references multiple times. In release mode is NOREF()'ed.
113 #define AssertMsgRC(rc, msg) \
114 do { AssertMsg(RT_SUCCESS(rc), msg); NOREF(rc); } while (0)
116 /** @def AssertRC
117 * Asserts a iprt status code successful.
119 * On failure it will print info about the rc and hit a breakpoint.
121 * @param rc iprt status code.
122 * @remark rc is references multiple times. In release mode is NOREF()'ed.
124 #define AssertRC(rc) AssertMsgRC(rc, ("%Vra\n", (rc)))
126 /** @def AssertReleaseMsgRC
127 * Asserts a iprt status code successful.
129 * On failure a custom message is printed and a breakpoint is hit.
131 * @param rc iprt status code.
132 * @param msg printf argument list (in parenthesis).
133 * @remark rc is references multiple times.
135 #define AssertReleaseMsgRC(rc, msg) AssertReleaseMsg(RT_SUCCESS(rc), msg)
137 /** @def AssertReleaseRC
138 * Asserts a iprt status code successful.
140 * On failure information about the error will be printed and a breakpoint hit.
142 * @param rc iprt status code.
143 * @remark rc is references multiple times.
145 #define AssertReleaseRC(rc) AssertReleaseMsgRC(rc, ("%Vra\n", (rc)))
147 /** @def AssertReturn
148 * Assert that an expression is true and returns if it isn't.
149 * In RT_STRICT mode it will hit a breakpoint before returning.
151 * @param expr Expression which should be true.
152 * @param rc What is to be presented to return.
154 #ifdef RT_STRICT
155 # define AssertReturn(expr, rc) \
156 do { \
157 if (RT_UNLIKELY(!(expr))) \
159 AssertMsg1(#expr, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
160 AssertBreakpoint(); \
161 return (rc); \
163 } while (0)
164 #else
165 # define AssertReturn(expr, rc) \
166 do { \
167 if (RT_UNLIKELY(!(expr))) \
168 return (rc); \
169 } while (0)
170 #endif
172 /** @def AssertMsgFailed
173 * An assertion failed print a message and a hit breakpoint.
175 * @param a printf argument list (in parenthesis).
177 #ifdef RT_STRICT
178 # define AssertMsgFailed(a) \
179 do { \
180 AssertMsg1((const char *)0, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
181 AssertMsg2 a; \
182 AssertBreakpoint(); \
183 } while (0)
184 #else
185 # define AssertMsgFailed(a) do { } while (0)
186 #endif
188 /** @def AssertMsgReturn
189 * Assert that an expression is true and returns if it isn't.
190 * In RT_STRICT mode it will hit a breakpoint before returning.
192 * @param expr Expression which should be true.
193 * @param a printf argument list (in parenthesis).
194 * @param rc What is to be presented to return.
196 #ifdef RT_STRICT
197 # define AssertMsgReturn(expr, a, rc) \
198 do { \
199 if (RT_UNLIKELY(!(expr))) \
201 AssertMsg1(#expr, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
202 AssertMsg2 a; \
203 AssertBreakpoint(); \
204 return (rc); \
206 } while (0)
207 #else
208 # define AssertMsgReturn(expr, a, rc) \
209 do { \
210 if (RT_UNLIKELY(!(expr))) \
211 return (rc); \
212 } while (0)
213 #endif
215 /** @def AssertPtrReturn
216 * Asserts that a pointer is valid.
218 * @param pv The pointer.
219 * @param rcRet What is to be presented to return.
221 #define AssertPtrReturn(pv, rcRet) AssertMsgReturn(VALID_PTR(pv), ("%p\n", (pv)), rcRet)
223 /** @def AssertRelease
224 * Assert that an expression is true. If it's not hit a breakpoint.
226 * @param expr Expression which should be true.
228 #define AssertRelease(expr) \
229 do { } \
230 while (0)
232 #endif