source: trunk/include/k/kDefs.h@ 103

Last change on this file since 103 was 103, checked in by bird, 8 years ago

kDefs.h: GNU hurd.

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