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

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

kDefs.h: arm endian detection (K_ENDIAN).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 19.1 KB
Line 
1/* $Id: kDefs.h 99 2017-09-30 11:33:30Z 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/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# endif
231# else
232# error "Port Me"
233# endif
234#else
235 /* validate the user specified value. */
236# if (K_ARCH & K_ARCH_BIT_MASK) != K_ARCH_BIT_8 \
237 && (K_ARCH & K_ARCH_BIT_MASK) != K_ARCH_BIT_16 \
238 && (K_ARCH & K_ARCH_BIT_MASK) != K_ARCH_BIT_32 \
239 && (K_ARCH & K_ARCH_BIT_MASK) != K_ARCH_BIT_64 \
240 && (K_ARCH & K_ARCH_BIT_MASK) != K_ARCH_BIT_128
241# error "Invalid K_ARCH value (bit)"
242# endif
243# if (K_ARCH & K_ARCH_END_MASK) != K_ARCH_END_LITTLE \
244 && (K_ARCH & K_ARCH_END_MASK) != K_ARCH_END_BIG \
245 && (K_ARCH & K_ARCH_END_MASK) != K_ARCH_END_BI
246# error "Invalid K_ARCH value (endian)"
247# endif
248# if (K_ARCH & ~(K_ARCH_BIT_MASK | K_ARCH_BIT_END_MASK)) < K_ARCH_UNKNOWN \
249 || (K_ARCH & ~(K_ARCH_BIT_MASK | K_ARCH_BIT_END_MASK)) >= K_ARCH_MAX
250# error "Invalid K_ARCH value"
251# endif
252#endif
253
254/** @def K_ARCH_IS_VALID
255 * Check if the architecture identifier is valid.
256 * @param arch The K_ARCH_* define to examin.
257 */
258#define K_ARCH_IS_VALID(arch) ( ( ((arch) & K_ARCH_BIT_MASK) == K_ARCH_BIT_8 \
259 || ((arch) & K_ARCH_BIT_MASK) == K_ARCH_BIT_16 \
260 || ((arch) & K_ARCH_BIT_MASK) == K_ARCH_BIT_32 \
261 || ((arch) & K_ARCH_BIT_MASK) == K_ARCH_BIT_64 \
262 || ((arch) & K_ARCH_BIT_MASK) == K_ARCH_BIT_128) \
263 && \
264 ( ((arch) & K_ARCH_END_MASK) == K_ARCH_END_LITTLE \
265 || ((arch) & K_ARCH_END_MASK) == K_ARCH_END_BIG \
266 || ((arch) & K_ARCH_END_MASK) == K_ARCH_END_BI) \
267 && \
268 ( ((arch) & ~(K_ARCH_BIT_MASK | K_ARCH_END_MASK)) >= K_ARCH_UNKNOWN \
269 && ((arch) & ~(K_ARCH_BIT_MASK | K_ARCH_END_MASK)) < K_ARCH_MAX) \
270 )
271
272/** @def K_ARCH_BITS_EX
273 * Determin the architure byte width of the specified architecture.
274 * @param arch The K_ARCH_* define to examin.
275 */
276#define K_ARCH_BITS_EX(arch) ( ((arch) & K_ARCH_BIT_MASK) >> K_ARCH_BIT_SHIFT )
277
278/** @def K_ARCH_BYTES_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_BYTES_EX(arch) ( ((arch) & K_ARCH_BIT_MASK) >> K_ARCH_BYTE_SHIFT )
283
284/** @def K_ARCH_ENDIAN_EX
285 * Determin the K_ENDIAN value for the specified architecture.
286 * @param arch The K_ARCH_* define to examin.
287 */
288#define K_ARCH_ENDIAN_EX(arch) ( ((arch) & K_ARCH_END_MASK) >> K_ARCH_END_SHIFT )
289
290/** @def K_ARCH_BITS
291 * Determin the target architure bit width.
292 */
293#define K_ARCH_BITS K_ARCH_BITS_EX(K_ARCH)
294
295/** @def K_ARCH_BYTES
296 * Determin the target architure byte width.
297 */
298#define K_ARCH_BYTES K_ARCH_BYTES_EX(K_ARCH)
299
300/** @def K_ARCH_ENDIAN
301 * Determin the target K_ENDIAN value.
302 */
303#define K_ARCH_ENDIAN K_ARCH_ENDIAN_EX(K_ARCH)
304
305
306
307/** @name Endianness Identifiers.
308 * These are the value that the K_ENDIAN \#define can take.
309 * @{ */
310#define K_ENDIAN_LITTLE 1 /**< Little-endian. */
311#define K_ENDIAN_BIG 2 /**< Big-endian. */
312#define K_ENDIAN_BI 3 /**< Bi-endian, can be switched. Only used with K_ARCH. */
313/** @} */
314
315/** @def K_ENDIAN
316 * The value of this \#define indicates the target endianness.
317 *
318 * @remark It's necessary to define this (or add the necessary deduction here)
319 * on bi-endian architectures.
320 */
321#ifndef K_ENDIAN
322 /* use K_ARCH if possible. */
323# if K_ARCH_ENDIAN != K_ENDIAN_BI
324# define K_ENDIAN K_ARCH_ENDIAN
325# elif defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && defined(__ORDER_BIG_ENDIAN__)
326# if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
327# define K_ENDIAN K_ARCH_LITTLE
328# elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
329# define K_ENDIAN K_ARCH_BIG
330# else
331# error "Port Me or define K_ENDIAN."
332# endif
333# else
334# error "Port Me or define K_ENDIAN."
335# endif
336#else
337 /* validate the user defined value. */
338# if K_ENDIAN != K_ENDIAN_LITTLE
339 && K_ENDIAN != K_ENDIAN_BIG
340# error "K_ENDIAN must either be defined as K_ENDIAN_LITTLE or as K_ENDIAN_BIG."
341# endif
342#endif
343
344/** @name Endian Conversion
345 * @{ */
346
347/** @def K_E2E_U16
348 * Convert the endian of an unsigned 16-bit value. */
349# define K_E2E_U16(u16) ( (KU16) (((u16) >> 8) | ((u16) << 8)) )
350/** @def K_E2E_U32
351 * Convert the endian of an unsigned 32-bit value. */
352# define K_E2E_U32(u32) ( ( ((u32) & KU32_C(0xff000000)) >> 24 ) \
353 | ( ((u32) & KU32_C(0x00ff0000)) >> 8 ) \
354 | ( ((u32) & KU32_C(0x0000ff00)) << 8 ) \
355 | ( ((u32) & KU32_C(0x000000ff)) << 24 ) \
356 )
357/** @def K_E2E_U64
358 * Convert the endian of an unsigned 64-bit value. */
359# define K_E2E_U64(u64) ( ( ((u64) & KU64_C(0xff00000000000000)) >> 56 ) \
360 | ( ((u64) & KU64_C(0x00ff000000000000)) >> 40 ) \
361 | ( ((u64) & KU64_C(0x0000ff0000000000)) >> 24 ) \
362 | ( ((u64) & KU64_C(0x000000ff00000000)) >> 8 ) \
363 | ( ((u64) & KU64_C(0x00000000ff000000)) << 8 ) \
364 | ( ((u64) & KU64_C(0x0000000000ff0000)) << 24 ) \
365 | ( ((u64) & KU64_C(0x000000000000ff00)) << 40 ) \
366 | ( ((u64) & KU64_C(0x00000000000000ff)) << 56 ) \
367 )
368
369/** @def K_LE2H_U16
370 * Unsigned 16-bit little-endian to host endian. */
371/** @def K_LE2H_U32
372 * Unsigned 32-bit little-endian to host endian. */
373/** @def K_LE2H_U64
374 * Unsigned 64-bit little-endian to host endian. */
375/** @def K_BE2H_U16
376 * Unsigned 16-bit big-endian to host endian. */
377/** @def K_BE2H_U32
378 * Unsigned 32-bit big-endian to host endian. */
379/** @def K_BE2H_U64
380 * Unsigned 64-bit big-endian to host endian. */
381#if K_ENDIAN == K_ENDIAN_LITTLE
382# define K_LE2H_U16(u16) ((KU16)(u16))
383# define K_LE2H_U32(u32) ((KU32)(u32))
384# define K_LE2H_U64(u64) ((KU64)(u32))
385# define K_BE2H_U16(u16) K_E2E_U16(u16)
386# define K_BE2H_U32(u32) K_E2E_U32(u32)
387# define K_BE2H_U64(u64) K_E2E_U64(u64)
388#else
389# define K_LE2H_U16(u16) K_E2E_U16(u16)
390# define K_LE2H_U32(u32) K_E2E_U32(u32)
391# define K_LE2H_U64(u64) K_E2E_U64(u64)
392# define K_BE2H_U16(u16) ((KU16)(u16))
393# define K_BE2H_U32(u32) ((KU32)(u32))
394# define K_BE2H_U64(u64) ((KU64)(u32))
395#endif
396
397
398
399/** @def K_INLINE
400 * How to say 'inline' in both C and C++ dialects.
401 * @param type The return type.
402 */
403#ifdef __cplusplus
404# if defined(__GNUC__)
405# define K_INLINE static inline
406# else
407# define K_INLINE inline
408# endif
409#else
410# if defined(__GNUC__)
411# define K_INLINE static __inline__
412# elif defined(_MSC_VER)
413# define K_INLINE static __inline
414# else
415# error "Port Me"
416# endif
417#endif
418
419/** @def K_EXPORT
420 * What to put in front of an exported function.
421 */
422#if K_OS == K_OS_OS2 || K_OS == K_OS_WINDOWS
423# define K_EXPORT __declspec(dllexport)
424#else
425# define K_EXPORT
426#endif
427
428/** @def K_IMPORT
429 * What to put in front of an imported function.
430 */
431#if K_OS == K_OS_OS2 || K_OS == K_OS_WINDOWS
432# define K_IMPORT __declspec(dllimport)
433#else
434# define K_IMPORT extern
435#endif
436
437/** @def K_DECL_EXPORT
438 * Declare an exported function.
439 * @param type The return type.
440 */
441#define K_DECL_EXPORT(type) K_EXPORT type
442
443/** @def K_DECL_IMPORT
444 * Declare an import function.
445 * @param type The return type.
446 */
447#define K_DECL_IMPORT(type) K_IMPORT type
448
449/** @def K_DECL_INLINE
450 * Declare an inline function.
451 * @param type The return type.
452 * @remark Don't use on (class) methods.
453 */
454#define K_DECL_INLINE(type) K_INLINE type
455
456
457/** Get the minimum of two values. */
458#define K_MIN(a, b) ( (a) <= (b) ? (a) : (b) )
459/** Get the maximum of two values. */
460#define K_MAX(a, b) ( (a) >= (b) ? (a) : (b) )
461/** Calculate the offset of a structure member. */
462#define K_OFFSETOF(strct, memb) ( (KSIZE)( &((strct *)0)->memb ) )
463/** Align a size_t value. */
464#define K_ALIGN_Z(val, align) ( ((val) + ((align) - 1)) & ~(KSIZE)((align) - 1) )
465/** Align a void * value. */
466#define K_ALIGN_P(pv, align) ( (void *)( ((KUPTR)(pv) + ((align) - 1)) & ~(KUPTR)((align) - 1) ) )
467/** Number of elements in an array. */
468#define K_ELEMENTS(a) ( sizeof(a) / sizeof((a)[0]) )
469/** Checks if the specified pointer is a valid address or not. */
470#define K_VALID_PTR(ptr) ( (KUPTR)(ptr) + 0x1000U >= 0x2000U )
471/** Makes a 32-bit bit mask. */
472#define K_BIT32(bit) ( KU32_C(1) << (bit))
473/** Makes a 64-bit bit mask. */
474#define K_BIT64(bit) ( KU64_C(1) << (bit))
475/** Shuts up unused parameter and unused variable warnings. */
476#define K_NOREF(var) ( (void)(var) )
477
478
479/** @name Parameter validation macros
480 * @{ */
481
482/** Return/Crash validation of a string argument. */
483#define K_VALIDATE_STRING(str) \
484 do { \
485 if (!K_VALID_PTR(str)) \
486 return KERR_INVALID_POINTER; \
487 kHlpStrLen(str); \
488 } while (0)
489
490/** Return/Crash validation of an optional string argument. */
491#define K_VALIDATE_OPTIONAL_STRING(str) \
492 do { \
493 if (str) \
494 K_VALIDATE_STRING(str); \
495 } while (0)
496
497/** Return/Crash validation of an output buffer. */
498#define K_VALIDATE_BUFFER(buf, cb) \
499 do { \
500 if (!K_VALID_PTR(buf)) \
501 return KERR_INVALID_POINTER; \
502 if ((cb) != 0) \
503 { \
504 KU8 __b; \
505 KU8 volatile *__pb = (KU8 volatile *)(buf); \
506 KSIZE __cbPage1 = 0x1000 - ((KUPTR)(__pb) & 0xfff); /* ASSUMES page size! */ \
507 __b = *__pb; *__pb = 0xff; *__pb = __b; \
508 if ((cb) > __cbPage1) \
509 { \
510 KSIZE __cb = (cb) - __cbPage1; \
511 __pb -= __cbPage1; \
512 for (;;) \
513 { \
514 __b = *__pb; *__pb = 0xff; *__pb = __b; \
515 if (__cb < 0x1000) \
516 break; \
517 __pb += 0x1000; \
518 __cb -= 0x1000; \
519 } \
520 } \
521 } \
522 else \
523 return KERR_INVALID_PARAMETER; \
524 } while (0)
525
526/** Return/Crash validation of an optional output buffer. */
527#define K_VALIDATE_OPTIONAL_BUFFER(buf, cb) \
528 do { \
529 if ((buf) && (cb) != 0) \
530 K_VALIDATE_BUFFER(buf, cb); \
531 } while (0)
532
533/** Return validation of an enum argument. */
534#define K_VALIDATE_ENUM(arg, enumname) \
535 do { \
536 if ((arg) <= enumname##_INVALID || (arg) >= enumname##_END) \
537 return KERR_INVALID_PARAMETER; \
538 } while (0)
539
540/** Return validation of a flags argument. */
541#define K_VALIDATE_FLAGS(arg, AllowedMask) \
542 do { \
543 if ((arg) & ~(AllowedMask)) \
544 return KERR_INVALID_PARAMETER; \
545 } while (0)
546
547/** @} */
548
549/** @def NULL
550 * The nil pointer value. */
551#ifndef NULL
552# ifdef __cplusplus
553# define NULL 0
554# else
555# define NULL ((void *)0)
556# endif
557#endif
558
559/** @} */
560
561#endif
562
Note: See TracBrowser for help on using the repository browser.