VirtualBox

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

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

kDefs.h: m68k

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