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

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

kDefs.h: Detect 64-bit arm (gcc).

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