VirtualBox

source: kStuff/trunk/include/k/kDefs.h@ 97

Last change on this file since 97 was 97, checked in by bird, 7 years ago

kDefs.h: GNU/kFreeBSD; GNU/kNetBSD; SuperH arch.

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