VirtualBox

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

Last change on this file since 2468 was 2413, checked in by bird, 15 years ago

copyright year update.

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