VirtualBox

source: kBuild/trunk/src/lib/k/kDefs.h@ 2698

Last change on this file since 2698 was 2546, checked in by bird, 13 years ago

Applied modified patches for Haiku support from Mike Smith.

  • Property svn:eol-style set to native
File size: 18.9 KB
Line 
1/* $Id: kDefs.h 15 2008-05-05 22:14:33Z bird $ */
2/** @file
3 *
4 * kTypes - Defines and Macros.
5 *
6 * Copyright (c) 2007-2010 knut st. osmundsen <[email protected]>
7 *
8 *
9 * This file is part of k*.
10 *
11 * k* is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License as published
13 * by the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * k* is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public License
22 * along with k*; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 *
25 */
26
27#ifndef ___k_kDefs_h___
28#define ___k_kDefs_h___
29
30/** @defgroup grp_kDefs kDefs - Defines and Macros
31 * @{ */
32
33/** @name Operative System Identifiers.
34 * These are the value that the K_OS \#define can take.
35 * @{
36 */
37/** Unknown OS. */
38#define K_OS_UNKNOWN 0
39/** Darwin - aka Mac OS X. */
40#define K_OS_DARWIN 1
41/** DragonFly BSD. */
42#define K_OS_DRAGONFLY 2
43/** FreeBSD. */
44#define K_OS_FREEBSD 3
45/** Haiku. */
46#define K_OS_HAIKU 4
47/** Linux. */
48#define K_OS_LINUX 5
49/** NetBSD. */
50#define K_OS_NETBSD 6
51/** NT (native). */
52#define K_OS_NT 7
53/** OpenBSD*/
54#define K_OS_OPENBSD 8
55/** OS/2 */
56#define K_OS_OS2 9
57/** Solaris */
58#define K_OS_SOLARIS 10
59/** Windows. */
60#define K_OS_WINDOWS 11
61/** The max K_OS_* value (exclusive). */
62#define K_OS_MAX 12
63/** @} */
64
65/** @def K_OS
66 * Indicates which OS we're targetting. It's a \#define with is
67 * assigned one of the K_OS_* defines above.
68 *
69 * So to test if we're on FreeBSD do the following:
70 * @code
71 * #if K_OS == K_OS_FREEBSD
72 * some_funky_freebsd_specific_stuff();
73 * #endif
74 * @endcode
75 */
76#ifndef K_OS
77# if defined(__APPLE__)
78# define K_OS K_OS_DARWIN
79# elif defined(__DragonFly__)
80# define K_OS K_OS_DRAGONFLY
81# elif defined(__FreeBSD__) /*??*/
82# define K_OS K_OS_FREEBSD
83# elif defined(__HAIKU__)
84# define K_OS K_OS_HAIKU
85# elif defined(__gnu_linux__)
86# define K_OS K_OS_LINUX
87# elif defined(__NetBSD__) /*??*/
88# define K_OS K_OS_NETBSD
89# elif defined(__OpenBSD__) /*??*/
90# define K_OS K_OS_OPENBSD
91# elif defined(__OS2__)
92# define K_OS K_OS_OS2
93# elif defined(__sun__) || defined(__SunOS__) || defined(__sun) || defined(__SunOS)
94# define K_OS K_OS_SOLARIS
95# elif defined(_WIN32) || defined(_WIN64)
96# define K_OS K_OS_WINDOWS
97# else
98# error "Port Me"
99# endif
100#endif
101#if K_OS < K_OS_UNKNOWN || K_OS >= K_OS_MAX
102# error "Invalid K_OS value."
103#endif
104
105
106
107/** @name Architecture bit width.
108 * @{ */
109#define K_ARCH_BIT_8 0x0100 /**< 8-bit */
110#define K_ARCH_BIT_16 0x0200 /**< 16-bit */
111#define K_ARCH_BIT_32 0x0400 /**< 32-bit */
112#define K_ARCH_BIT_64 0x0800 /**< 64-bit */
113#define K_ARCH_BIT_128 0x1000 /**< 128-bit */
114#define K_ARCH_BIT_MASK 0x1f00 /**< The bit mask. */
115#define K_ARCH_BIT_SHIFT 5 /**< Shift count for producing the width in bits. */
116#define K_ARCH_BYTE_SHIFT 8 /**< Shift count for producing the width in bytes. */
117/** @} */
118
119/** @name Architecture Endianness.
120 * @{ */
121#define K_ARCH_END_LITTLE 0x2000 /**< Little-endian. */
122#define K_ARCH_END_BIG 0x4000 /**< Big-endian. */
123#define K_ARCH_END_BI 0x6000 /**< Bi-endian, can be switched. */
124#define K_ARCH_END_MASK 0x6000 /**< The endian mask. */
125#define K_ARCH_END_SHIFT 13 /**< Shift count for converting between this K_ENDIAN_*. */
126/** @} */
127
128/** @name Architecture Identifiers.
129 * These are the value that the K_ARCH \#define can take.
130 *@{ */
131/** Unknown CPU architecture. */
132#define K_ARCH_UNKNOWN ( 0 )
133/** Clone or Intel 16-bit x86. */
134#define K_ARCH_X86_16 ( 1 | K_ARCH_BIT_16 | K_ARCH_END_LITTLE)
135/** Clone or Intel 32-bit x86. */
136#define K_ARCH_X86_32 ( 2 | K_ARCH_BIT_32 | K_ARCH_END_LITTLE)
137/** AMD64 (including clones). */
138#define K_ARCH_AMD64 ( 3 | K_ARCH_BIT_64 | K_ARCH_END_LITTLE)
139/** Itanic (64-bit). */
140#define K_ARCH_IA64 ( 4 | K_ARCH_BIT_64 | K_ARCH_END_BI)
141/** ALPHA (64-bit). */
142#define K_ARCH_ALPHA ( 5 | K_ARCH_BIT_64 | K_ARCH_END_BI)
143/** ALPHA limited to 32-bit. */
144#define K_ARCH_ALPHA_32 ( 6 | K_ARCH_BIT_32 | K_ARCH_END_BI)
145/** 32-bit ARM. */
146#define K_ARCH_ARM_32 ( 7 | K_ARCH_BIT_32 | K_ARCH_END_BI)
147/** 64-bit ARM. */
148#define K_ARCH_ARM_64 ( 8 | K_ARCH_BIT_64 | K_ARCH_END_BI)
149/** 32-bit MIPS. */
150#define K_ARCH_MIPS_32 ( 9 | K_ARCH_BIT_32 | K_ARCH_END_BI)
151/** 64-bit MIPS. */
152#define K_ARCH_MIPS_64 (10 | K_ARCH_BIT_64 | K_ARCH_END_BI)
153/** 32-bit PA-RISC. */
154#define K_ARCH_PARISC_32 (11 | K_ARCH_BIT_32 | K_ARCH_END_BI)
155/** 64-bit PA-RISC. */
156#define K_ARCH_PARISC_64 (12 | K_ARCH_BIT_64 | K_ARCH_END_BI)
157/** 32-bit PowerPC. */
158#define K_ARCH_POWERPC_32 (13 | K_ARCH_BIT_32 | K_ARCH_END_BI)
159/** 64-bit PowerPC. */
160#define K_ARCH_POWERPC_64 (14 | K_ARCH_BIT_64 | K_ARCH_END_BI)
161/** 32(31)-bit S390. */
162#define K_ARCH_S390_32 (15 | K_ARCH_BIT_32 | K_ARCH_END_BIG)
163/** 64-bit S390. */
164#define K_ARCH_S390_64 (16 | K_ARCH_BIT_64 | K_ARCH_END_BIG)
165/** 32-bit SPARC. */
166#define K_ARCH_SPARC_32 (17 | K_ARCH_BIT_32 | K_ARCH_END_BIG)
167/** 64-bit SPARC. */
168#define K_ARCH_SPARC_64 (18 | K_ARCH_BIT_64 | K_ARCH_END_BI)
169/** The end of the valid architecture values (exclusive). */
170#define K_ARCH_MAX (19)
171/** @} */
172
173
174/** @def K_ARCH
175 * The value of this \#define indicates which architecture we're targetting.
176 */
177#ifndef K_ARCH
178 /* detection based on compiler defines. */
179# if defined(__amd64__) || defined(__x86_64__) || defined(__AMD64__) || defined(_M_X64) || defined(__amd64)
180# define K_ARCH K_ARCH_AMD64
181# elif defined(__i386__) || defined(__x86__) || defined(__X86__) || defined(_M_IX86) || defined(__i386)
182# define K_ARCH K_ARCH_X86_32
183# elif defined(__ia64__) || defined(__IA64__) || defined(_M_IA64)
184# define K_ARCH K_ARCH_IA64
185# elif defined(__alpha__)
186# define K_ARCH K_ARCH_ALPHA
187# elif defined(__arm__) || defined(__arm32__)
188# define K_ARCH K_ARCH_ARM_32
189# elif defined(__hppa__) && defined(__LP64__)
190# define K_ARCH K_ARCH_PARISC_64
191# elif defined(__hppa__)
192# define K_ARCH K_ARCH_PARISC_32
193# elif defined(__mips64)
194# define K_ARCH K_ARCH_MIPS_64
195# elif defined(__mips__)
196# define K_ARCH K_ARCH_MIPS_32
197# elif defined(__powerpc64__) || defined(__ppc64__) || defined(__PPC64__)
198# define K_ARCH K_ARCH_POWERPC_64
199# elif defined(__powerpc__) || defined(__ppc__) || defined(__PPC__)
200# define K_ARCH K_ARCH_POWERPC_32
201# elif defined(__sparcv9__) || defined(__sparcv9)
202# define K_ARCH K_ARCH_SPARC_64
203# elif defined(__sparc__) || defined(__sparc)
204# define K_ARCH K_ARCH_SPARC_32
205# elif defined(__s390x__)
206# define K_ARCH K_ARCH_S390_64
207# elif defined(__s390__)
208# define K_ARCH K_ARCH_S390_32
209# else
210# error "Port Me"
211# endif
212#else
213 /* validate the user specified value. */
214# if (K_ARCH & K_ARCH_BIT_MASK) != K_ARCH_BIT_8 \
215 && (K_ARCH & K_ARCH_BIT_MASK) != K_ARCH_BIT_16 \
216 && (K_ARCH & K_ARCH_BIT_MASK) != K_ARCH_BIT_32 \
217 && (K_ARCH & K_ARCH_BIT_MASK) != K_ARCH_BIT_64 \
218 && (K_ARCH & K_ARCH_BIT_MASK) != K_ARCH_BIT_128
219# error "Invalid K_ARCH value (bit)"
220# endif
221# if (K_ARCH & K_ARCH_END_MASK) != K_ARCH_END_LITTLE \
222 && (K_ARCH & K_ARCH_END_MASK) != K_ARCH_END_BIG \
223 && (K_ARCH & K_ARCH_END_MASK) != K_ARCH_END_BI
224# error "Invalid K_ARCH value (endian)"
225# endif
226# if (K_ARCH & ~(K_ARCH_BIT_MASK | K_ARCH_BIT_END_MASK)) < K_ARCH_UNKNOWN \
227 || (K_ARCH & ~(K_ARCH_BIT_MASK | K_ARCH_BIT_END_MASK)) >= K_ARCH_MAX
228# error "Invalid K_ARCH value"
229# endif
230#endif
231
232/** @def K_ARCH_IS_VALID
233 * Check if the architecture identifier is valid.
234 * @param arch The K_ARCH_* define to examin.
235 */
236#define K_ARCH_IS_VALID(arch) ( ( ((arch) & K_ARCH_BIT_MASK) == K_ARCH_BIT_8 \
237 || ((arch) & K_ARCH_BIT_MASK) == K_ARCH_BIT_16 \
238 || ((arch) & K_ARCH_BIT_MASK) == K_ARCH_BIT_32 \
239 || ((arch) & K_ARCH_BIT_MASK) == K_ARCH_BIT_64 \
240 || ((arch) & K_ARCH_BIT_MASK) == K_ARCH_BIT_128) \
241 && \
242 ( ((arch) & K_ARCH_END_MASK) == K_ARCH_END_LITTLE \
243 || ((arch) & K_ARCH_END_MASK) == K_ARCH_END_BIG \
244 || ((arch) & K_ARCH_END_MASK) == K_ARCH_END_BI) \
245 && \
246 ( ((arch) & ~(K_ARCH_BIT_MASK | K_ARCH_END_MASK)) >= K_ARCH_UNKNOWN \
247 && ((arch) & ~(K_ARCH_BIT_MASK | K_ARCH_END_MASK)) < K_ARCH_MAX) \
248 )
249
250/** @def K_ARCH_BITS_EX
251 * Determin the architure byte width of the specified architecture.
252 * @param arch The K_ARCH_* define to examin.
253 */
254#define K_ARCH_BITS_EX(arch) ( ((arch) & K_ARCH_BIT_MASK) >> K_ARCH_BIT_SHIFT )
255
256/** @def K_ARCH_BYTES_EX
257 * Determin the architure byte width of the specified architecture.
258 * @param arch The K_ARCH_* define to examin.
259 */
260#define K_ARCH_BYTES_EX(arch) ( ((arch) & K_ARCH_BIT_MASK) >> K_ARCH_BYTE_SHIFT )
261
262/** @def K_ARCH_ENDIAN_EX
263 * Determin the K_ENDIAN value for the specified architecture.
264 * @param arch The K_ARCH_* define to examin.
265 */
266#define K_ARCH_ENDIAN_EX(arch) ( ((arch) & K_ARCH_END_MASK) >> K_ARCH_END_SHIFT )
267
268/** @def K_ARCH_BITS
269 * Determin the target architure bit width.
270 */
271#define K_ARCH_BITS K_ARCH_BITS_EX(K_ARCH)
272
273/** @def K_ARCH_BYTES
274 * Determin the target architure byte width.
275 */
276#define K_ARCH_BYTES K_ARCH_BYTES_EX(K_ARCH)
277
278/** @def K_ARCH_ENDIAN
279 * Determin the target K_ENDIAN value.
280 */
281#define K_ARCH_ENDIAN K_ARCH_ENDIAN_EX(K_ARCH)
282
283
284
285/** @name Endianness Identifiers.
286 * These are the value that the K_ENDIAN \#define can take.
287 * @{ */
288#define K_ENDIAN_LITTLE 1 /**< Little-endian. */
289#define K_ENDIAN_BIG 2 /**< Big-endian. */
290#define K_ENDIAN_BI 3 /**< Bi-endian, can be switched. Only used with K_ARCH. */
291/** @} */
292
293/** @def K_ENDIAN
294 * The value of this \#define indicates the target endianness.
295 *
296 * @remark It's necessary to define this (or add the necessary dection here)
297 * on bi-endian architectures.
298 */
299#ifndef K_ENDIAN
300 /* use K_ARCH if possible. */
301# if K_ARCH_END != K_ENDIAN_BI
302# define K_ENDIAN K_ARCH_ENDIAN
303# else
304# error "Port Me or define K_ENDIAN."
305# endif
306#else
307 /* validate the user defined value. */
308# if K_ENDIAN != K_ENDIAN_LITTLE
309 && K_ENDIAN != K_ENDIAN_BIG
310# error "K_ENDIAN must either be defined as K_ENDIAN_LITTLE or as K_ENDIAN_BIG."
311# endif
312#endif
313
314/** @name Endian Conversion
315 * @{ */
316
317/** @def K_E2E_U16
318 * Convert the endian of an unsigned 16-bit value. */
319# define K_E2E_U16(u16) ( (KU16) (((u16) >> 8) | ((u16) << 8)) )
320/** @def K_E2E_U32
321 * Convert the endian of an unsigned 32-bit value. */
322# define K_E2E_U32(u32) ( ( ((u32) & KU32_C(0xff000000)) >> 24 ) \
323 | ( ((u32) & KU32_C(0x00ff0000)) >> 8 ) \
324 | ( ((u32) & KU32_C(0x0000ff00)) << 8 ) \
325 | ( ((u32) & KU32_C(0x000000ff)) << 24 ) \
326 )
327/** @def K_E2E_U64
328 * Convert the endian of an unsigned 64-bit value. */
329# define K_E2E_U64(u64) ( ( ((u64) & KU64_C(0xff00000000000000)) >> 56 ) \
330 | ( ((u64) & KU64_C(0x00ff000000000000)) >> 40 ) \
331 | ( ((u64) & KU64_C(0x0000ff0000000000)) >> 24 ) \
332 | ( ((u64) & KU64_C(0x000000ff00000000)) >> 8 ) \
333 | ( ((u64) & KU64_C(0x00000000ff000000)) << 8 ) \
334 | ( ((u64) & KU64_C(0x0000000000ff0000)) << 24 ) \
335 | ( ((u64) & KU64_C(0x000000000000ff00)) << 40 ) \
336 | ( ((u64) & KU64_C(0x00000000000000ff)) << 56 ) \
337 )
338
339/** @def K_LE2H_U16
340 * Unsigned 16-bit little-endian to host endian. */
341/** @def K_LE2H_U32
342 * Unsigned 32-bit little-endian to host endian. */
343/** @def K_LE2H_U64
344 * Unsigned 64-bit little-endian to host endian. */
345/** @def K_BE2H_U16
346 * Unsigned 16-bit big-endian to host endian. */
347/** @def K_BE2H_U32
348 * Unsigned 32-bit big-endian to host endian. */
349/** @def K_BE2H_U64
350 * Unsigned 64-bit big-endian to host endian. */
351#if K_ENDIAN == K_ENDIAN_LITTLE
352# define K_LE2H_U16(u16) ((KU16)(u16))
353# define K_LE2H_U32(u32) ((KU32)(u32))
354# define K_LE2H_U64(u64) ((KU64)(u32))
355# define K_BE2H_U16(u16) K_E2E_U16(u16)
356# define K_BE2H_U32(u32) K_E2E_U32(u32)
357# define K_BE2H_U64(u64) K_E2E_U64(u64)
358#else
359# define K_LE2H_U16(u16) K_E2E_U16(u16)
360# define K_LE2H_U32(u32) K_E2E_U32(u32)
361# define K_LE2H_U64(u64) K_E2E_U64(u64)
362# define K_BE2H_U16(u16) ((KU16)(u16))
363# define K_BE2H_U32(u32) ((KU32)(u32))
364# define K_BE2H_U64(u64) ((KU64)(u32))
365#endif
366
367/** @def K_H2LE_U16
368 * Unsigned 16-bit host endian to little-endian.. */
369/** @def K_H2LE_U32
370 * Unsigned 32-bit host endian to little-endian.. */
371/** @def K_H2LE_U64
372 * Unsigned 64-bit host endian to little-endian.. */
373/** @def K_H2BE_U16
374 * Unsigned 16-bit host endian to big-endian.. */
375/** @def K_H2BE_U32
376 * Unsigned 32-bit host endian to big-endian.. */
377/** @def K_H2BE_U64
378 * Unsigned 64-bit host endian to big-endian.. */
379#if K_ENDIAN == K_ENDIAN_LITTLE
380# define K_H2LE_U16(u16) ((KU16)(u16))
381# define K_H2LE_U32(u32) ((KU32)(u32))
382# define K_H2LE_U64(u64) ((KU64)(u32))
383# define K_H2BE_U16(u16) K_E2E_U16(u16)
384# define K_H2BE_U32(u32) K_E2E_U32(u32)
385# define K_H2BE_U64(u64) K_E2E_U64(u64)
386#else
387# define K_H2LE_U16(u16) K_E2E_U16(u16)
388# define K_H2LE_U32(u32) K_E2E_U32(u32)
389# define K_H2LE_U64(u64) K_E2E_U64(u64)
390# define K_H2BE_U16(u16) ((KU16)(u16))
391# define K_H2BE_U32(u32) ((KU32)(u32))
392# define K_H2BE_U64(u64) ((KU64)(u32))
393#endif
394
395
396
397/** @def K_INLINE
398 * How to say 'inline' in both C and C++ dialects.
399 * @param type The return type.
400 */
401#ifdef __cplusplus
402# if defined(__GNUC__)
403# define K_INLINE static inline
404# else
405# define K_INLINE inline
406# endif
407#else
408# if defined(__GNUC__)
409# define K_INLINE static __inline__
410# elif defined(_MSC_VER)
411# define K_INLINE static _Inline
412# else
413# error "Port Me"
414# endif
415#endif
416
417/** @def K_EXPORT
418 * What to put in front of an exported function.
419 */
420#if K_OS == K_OS_OS2 || K_OS == K_OS_WINDOWS
421# define K_EXPORT __declspec(dllexport)
422#else
423# define K_EXPORT
424#endif
425
426/** @def K_IMPORT
427 * What to put in front of an imported function.
428 */
429#if K_OS == K_OS_OS2 || K_OS == K_OS_WINDOWS
430# define K_IMPORT __declspec(dllimport)
431#else
432# define K_IMPORT extern
433#endif
434
435/** @def K_DECL_EXPORT
436 * Declare an exported function.
437 * @param type The return type.
438 */
439#define K_DECL_EXPORT(type) K_EXPORT type
440
441/** @def K_DECL_IMPORT
442 * Declare an import function.
443 * @param type The return type.
444 */
445#define K_DECL_IMPORT(type) K_IMPORT type
446
447/** @def K_DECL_INLINE
448 * Declare an inline function.
449 * @param type The return type.
450 * @remark Don't use on (class) methods.
451 */
452#define K_DECL_INLINE(type) K_INLINE type
453
454
455/** Get the minimum of two values. */
456#define K_MIN(a, b) ( (a) <= (b) ? (a) : (b) )
457/** Get the maximum of two values. */
458#define K_MAX(a, b) ( (a) >= (b) ? (a) : (b) )
459/** Calculate the offset of a structure member. */
460#define K_OFFSETOF(strct, memb) ( (KSIZE)( &((strct *)0)->memb ) )
461/** Align a size_t value. */
462#define K_ALIGN_Z(val, align) ( ((val) + ((align) - 1)) & ~(KSIZE)((align) - 1) )
463/** Align a void * value. */
464#define K_ALIGN_P(pv, align) ( (void *)( ((KUPTR)(pv) + ((align) - 1)) & ~(KUPTR)((align) - 1) ) )
465/** Number of elements in an array. */
466#define K_ELEMENTS(a) ( sizeof(a) / sizeof((a)[0]) )
467/** Checks if the specified pointer is a valid address or not. */
468#define K_VALID_PTR(ptr) ( (KUPTR)(ptr) + 0x1000U >= 0x2000U )
469/** Makes a 32-bit bit mask. */
470#define K_BIT32(bit) ( KU32_C(1) << (bit))
471/** Makes a 64-bit bit mask. */
472#define K_BIT64(bit) ( KU64_C(1) << (bit))
473/** Shuts up unused parameter and unused variable warnings. */
474#define K_NOREF(var) ( (void)(var) )
475
476
477/** @name Parameter validation macros
478 * @{ */
479
480/** Return/Crash validation of a string argument. */
481#define K_VALIDATE_STRING(str) \
482 do { \
483 if (!K_VALID_PTR(str)) \
484 return KERR_INVALID_POINTER; \
485 kHlpStrLen(str); \
486 } while (0)
487
488/** Return/Crash validation of an optional string argument. */
489#define K_VALIDATE_OPTIONAL_STRING(str) \
490 do { \
491 if (str) \
492 K_VALIDATE_STRING(str); \
493 } while (0)
494
495/** Return/Crash validation of an output buffer. */
496#define K_VALIDATE_BUFFER(buf, cb) \
497 do { \
498 if (!K_VALID_PTR(buf)) \
499 return KERR_INVALID_POINTER; \
500 if ((cb) != 0) \
501 { \
502 KU8 __b; \
503 KU8 volatile *__pb = (KU8 volatile *)(buf); \
504 KSIZE __cbPage1 = 0x1000 - ((KUPTR)(__pb) & 0xfff); /* ASSUMES page size! */ \
505 __b = *__pb; *__pb = 0xff; *__pb = __b; \
506 if ((cb) > __cbPage1) \
507 { \
508 KSIZE __cb = (cb) - __cbPage1; \
509 __pb -= __cbPage1; \
510 for (;;) \
511 { \
512 __b = *__pb; *__pb = 0xff; *__pb = __b; \
513 if (__cb < 0x1000) \
514 break; \
515 __pb += 0x1000; \
516 __cb -= 0x1000; \
517 } \
518 } \
519 } \
520 else \
521 return KERR_INVALID_PARAMETER; \
522 } while (0)
523
524/** Return/Crash validation of an optional output buffer. */
525#define K_VALIDATE_OPTIONAL_BUFFER(buf, cb) \
526 do { \
527 if ((buf) && (cb) != 0) \
528 K_VALIDATE_BUFFER(buf, cb); \
529 } while (0)
530
531/** Return validation of an enum argument. */
532#define K_VALIDATE_ENUM(arg, enumname) \
533 do { \
534 if ((arg) <= enumname##_INVALID || (arg) >= enumname##_END) \
535 return KERR_INVALID_PARAMETER; \
536 } while (0)
537
538/** Return validation of a flags argument. */
539#define K_VALIDATE_FLAGS(arg, AllowedMask) \
540 do { \
541 if ((arg) & ~(AllowedMask)) \
542 return KERR_INVALID_PARAMETER; \
543 } while (0)
544
545/** @} */
546
547/** @def NULL
548 * The nil pointer value. */
549#ifndef NULL
550# ifdef __cplusplus
551# define NULL 0
552# else
553# define NULL ((void *)0)
554# endif
555#endif
556
557/** @} */
558
559#endif
560
Note: See TracBrowser for help on using the repository browser.

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