VirtualBox

source: kStuff/trunk/include/k/kTypes.h@ 58

Last change on this file since 58 was 29, checked in by bird, 15 years ago

Finally got around execute the switch to the MIT license.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 17.5 KB
Line 
1/* $Id: kTypes.h 29 2009-07-01 20:30:29Z bird $ */
2/** @file
3 * kTypes - Typedefs And Related Constants And Macros.
4 */
5
6/*
7 * Copyright (c) 2006-2009 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_kTypes_h___
32#define ___k_kTypes_h___
33
34#include <k/kDefs.h>
35
36/** @defgroup grp_kTypes kTypes - Typedefs And Related Constants And Macros
37 * @{
38 */
39
40/** @typedef KI64
41 * 64-bit signed integer. */
42/** @typedef KU64
43 * 64-bit unsigned integer. */
44/** @def KI64_C
45 * 64-bit signed integer constant.
46 * @param c The constant value. */
47/** @def KU64_C
48 * 64-bit unsigned integer constant.
49 * @param c The constant value. */
50/** @def KI64_PRI
51 * 64-bit signed integer printf format. */
52/** @def KU64_PRI
53 * 64-bit unsigned integer printf format. */
54/** @def KX64_PRI
55 * 64-bit signed and unsigned integer hexadecimal printf format. */
56
57/** @typedef KI32
58 * 32-bit signed integer. */
59/** @typedef KU32
60 * 32-bit unsigned integer. */
61/** @def KI32_C
62 * 32-bit signed integer constant.
63 * @param c The constant value. */
64/** @def KU32_C
65 * 32-bit unsigned integer constant.
66 * @param c The constant value. */
67/** @def KI32_PRI
68 * 32-bit signed integer printf format. */
69/** @def KU32_PRI
70 * 32-bit unsigned integer printf format. */
71/** @def KX32_PRI
72 * 32-bit signed and unsigned integer hexadecimal printf format. */
73
74/** @typedef KI16
75 * 16-bit signed integer. */
76/** @typedef KU16
77 * 16-bit unsigned integer. */
78/** @def KI16_C
79 * 16-bit signed integer constant.
80 * @param c The value. */
81/** @def KU16_C
82 * 16-bit unsigned integer constant.
83 * @param c The value. */
84/** @def KI16_PRI
85 * 16-bit signed integer printf format. */
86/** @def KU16_PRI
87 * 16-bit unsigned integer printf format. */
88/** @def KX16_PRI
89 * 16-bit signed and unsigned integer hexadecimal printf format. */
90
91/** @typedef KI8
92 * 8-bit signed integer. */
93/** @typedef KU8
94 * 8-bit unsigned integer. */
95/** @def KI8_C
96 * 8-bit signed integer constant.
97 * @param c The constant value. */
98/** @def KU8_C
99 * 8-bit unsigned integer constant.
100 * @param c The constant value. */
101/** @def KI8_PRI
102 * 8-bit signed integer printf format. */
103/** @def KU8_PRI
104 * 8-bit unsigned integer printf format. */
105/** @def KX8_PRI
106 * 8-bit signed and unsigned integer hexadecimal printf format. */
107
108/** @typedef KSIZE
109 * Memory size type; unsigned integer. */
110/** @typedef KSSIZE
111 * Memory size type; signed integer. */
112/** @def KSIZE_C
113 * Memory size constant.
114 * @param c The constant value. */
115/** @def KSSIZE_C
116 * Memory size constant.
117 * @param c The constant value. */
118/** @def KSIZE_MAX
119 * Memory size max constant.*/
120/** @def KSSIZE_MAX
121 * Memory size max constant.*/
122/** @def KSSIZE_MIN
123 * Memory size min constant.*/
124/** @def KSIZE_PRI
125 * Memory size printf format. */
126/** @def KSSIZE_PRI
127 * Memory size printf format. */
128
129/** @typedef KIPTR
130 * Signed integer type capable of containing a pointer value. */
131/** @typedef KUPTR
132 * Unsigned integer type capable of containing a pointer value. */
133/** @def KIPTR_C
134 * Signed pointer constant.
135 * @param c The constant value. */
136/** @def KUPTR_C
137 * Unsigned pointer constant.
138 * @param c The constant value. */
139/** @def KIPTR_MAX
140 * Signed pointer max constant.*/
141/** @def KIPTR_MIN
142 * Signed pointer min constant.*/
143/** @def KUPTR_MAX
144 * Unsigned pointer max constant.*/
145/** @def KIPTR_PRI
146 * Signed pointer printf format. */
147/** @def KUPTR_PRI
148 * Unsigned pointer printf format. */
149
150
151#if K_ARCH_BITS == 32
152 /* ASSUMES int == long == 32-bit, short == 16-bit, char == 8-bit. */
153# ifdef _MSC_VER
154typedef signed __int64 KI64;
155typedef unsigned __int64 KU64;
156#define KI64_PRI "I64d"
157#define KU64_PRI "I64u"
158#define KX64_PRI "I64x"
159# else
160typedef signed long long int KI64;
161typedef unsigned long long int KU64;
162#define KI64_PRI "lld"
163#define KU64_PRI "llu"
164#define KX64_PRI "llx"
165# endif
166typedef signed int KI32;
167typedef unsigned int KU32;
168typedef signed short int KI16;
169typedef unsigned short int KU16;
170typedef signed char KI8;
171typedef unsigned char KU8;
172#define KI64_C(c) (c ## LL)
173#define KU64_C(c) (c ## ULL)
174#define KI32_C(c) (c)
175#define KU32_C(c) (c)
176#define KI16_C(c) (c)
177#define KU16_C(c) (c)
178#define KI8_C(c) (c)
179#define KU8_C(c) (c)
180
181#define KI32_PRI "d"
182#define KU32_PRI "u"
183#define KX32_PRI "x"
184#define KI16_PRI "d"
185#define KU16_PRI "u"
186#define KX16_PRI "x"
187#define KI8_PRI "d"
188#define KU8_PRI "u"
189#define KX8_PRI "x"
190
191typedef KI32 KSSIZE;
192#define KSSIZE(c) KI32_C(c)
193#define KSSIZE_MAX KI32_MAX
194#define KSSIZE_MIN KI32_MIN
195#define KSSIZE_PRI KX32_PRI
196
197typedef KU32 KSIZE;
198#define KSIZE_C(c) KU32_C(c)
199#define KSIZE_MAX KU32_MAX
200#define KSIZE_PRI KX32_PRI
201#define KIPTR_C(c) KI32_C(c)
202
203typedef KI32 KIPTR;
204#define KIPTR_MAX KI32_MAX
205#define KIPTR_MIN KI32_MIN
206#define KIPTR_PRI KX32_PRI
207
208typedef KU32 KUPTR;
209#define KUPTR_C(c) KU32_C(c)
210#define KUPTR_MAX KU32_MAX
211#define KUPTR_PRI KX32_PRI
212
213
214#elif K_ARCH_BITS == 64
215
216# if K_OS == K_OS_WINDOWS
217# if _MSC_VER
218typedef signed __int64 KI64;
219typedef unsigned __int64 KU64;
220# define KI64_PRI "I64d"
221# define KU64_PRI "I64u"
222# define KX64_PRI "I64x"
223# else
224typedef signed long long int KI64;
225typedef unsigned long long int KU64;
226# define KI64_PRI "lld"
227# define KU64_PRI "llu"
228# define KX64_PRI "llx"
229# endif
230# define KI64_C(c) (c ## LL)
231# define KU64_C(c) (c ## ULL)
232# else
233typedef signed long int KI64;
234typedef unsigned long int KU64;
235# define KI64_C(c) (c ## L)
236# define KU64_C(c) (c ## UL)
237# define KI64_PRI "ld"
238# define KU64_PRI "lu"
239# define KX64_PRI "lx"
240# endif
241typedef signed int KI32;
242typedef unsigned int KU32;
243typedef signed short KI16;
244typedef unsigned short KU16;
245typedef signed char KI8;
246typedef unsigned char KU8;
247#define KI32_C(c) (c)
248#define KU32_C(c) (c)
249#define KI16_C(c) (c)
250#define KU16_C(c) (c)
251#define KI8_C(c) (c)
252#define KU8_C(c) (c)
253
254#define KI32_PRI "d"
255#define KU32_PRI "u"
256#define KX32_PRI "x"
257#define KI16_PRI "d"
258#define KU16_PRI "u"
259#define KX16_PRI "x"
260#define KI8_PRI "d"
261#define KU8_PRI "u"
262#define KX8_PRI "x"
263
264typedef KI64 KSSIZE;
265#define KSSIZE(c) KI64_C(c)
266#define KSSIZE_MAX KI64_MAX
267#define KSSIZE_MIN KI64_MIN
268#define KSSIZE_PRI KX64_PRI
269
270typedef KU64 KSIZE;
271#define KSIZE_C(c) KU64_C(c)
272#define KSIZE_MAX KU64_MAX
273#define KSIZE_PRI KX64_PRI
274
275typedef KI64 KIPTR;
276#define KIPTR_C(c) KI64_C(c)
277#define KIPTR_MAX KI64_MAX
278#define KIPTR_MIN KI64_MIN
279#define KIPTR_PRI KX64_PRI
280
281typedef KU64 KUPTR;
282#define KUPTR_C(c) KU64_C(c)
283#define KUPTR_MAX KU64_MAX
284#define KUPTR_PRI KX64_PRI
285
286#else
287# error "Port Me"
288#endif
289
290
291/** Min KI8 value. */
292#define KI8_MIN (KI8_C(-0x7f) - 1)
293/** Min KI16 value. */
294#define KI16_MIN (KI16_C(-0x7fff) - 1)
295/** Min KI32 value. */
296#define KI32_MIN (KI32_C(-0x7fffffff) - 1)
297/** Min KI64 value. */
298#define KI64_MIN (KI64_C(-0x7fffffffffffffff) - 1)
299/** Max KI8 value. */
300#define KI8_MAX KI8_C(0x7f)
301/** Max KI16 value. */
302#define KI16_MAX KI16_C(0x7fff)
303/** Max KI32 value. */
304#define KI32_MAX KI32_C(0x7fffffff)
305/** Max KI64 value. */
306#define KI64_MAX KI64_C(0x7fffffffffffffff)
307/** Max KU8 value. */
308#define KU8_MAX KU8_C(0xff)
309/** Max KU16 value. */
310#define KU16_MAX KU16_C(0xffff)
311/** Max KU32 value. */
312#define KU32_MAX KU32_C(0xffffffff)
313/** Max KU64 value. */
314#define KU64_MAX KU64_C(0xffffffffffffffff)
315
316/** File offset. */
317typedef KI64 KFOFF;
318/** Pointer a file offset. */
319typedef KFOFF *PFOFF;
320/** Pointer a const file offset. */
321typedef KFOFF *PCFOFF;
322/** The min value for the KFOFF type. */
323#define KFOFF_MIN KI64_MIN
324/** The max value for the KFOFF type. */
325#define KFOFF_MAX KI64_MAX
326/** File offset contstant.
327 * @param c The constant value. */
328#define KFOFF_C(c) KI64_C(c)
329/** File offset printf format. */
330#define KFOFF_PRI KI64_PRI
331
332
333/**
334 * Memory Protection.
335 */
336typedef enum KPROT
337{
338 /** The usual invalid 0. */
339 KPROT_INVALID = 0,
340 /** No access (page not present). */
341 KPROT_NOACCESS,
342 /** Read only. */
343 KPROT_READONLY,
344 /** Read & write. */
345 KPROT_READWRITE,
346 /** Read & copy on write. */
347 KPROT_WRITECOPY,
348 /** Execute only. */
349 KPROT_EXECUTE,
350 /** Execute & read. */
351 KPROT_EXECUTE_READ,
352 /** Execute, read & write. */
353 KPROT_EXECUTE_READWRITE,
354 /** Execute, read & copy on write. */
355 KPROT_EXECUTE_WRITECOPY,
356 /** The usual end value. (exclusive) */
357 KPROT_END,
358 /** Blow the type up to 32-bits. */
359 KPROT_32BIT_HACK = 0x7fffffff
360} KPROT;
361/** Pointer to a memory protection enum. */
362typedef KPROT *PKPROT;
363/** Pointer to a const memory protection enum. */
364typedef KPROT const *PCKPROT;
365
366/** Boolean.
367 * This can be used as a tri-state type, but then you *must* do == checks. */
368typedef KI8 KBOOL;
369/** Pointer to a boolean value. */
370typedef KBOOL *PKBOOL;
371/** Pointer to a const boolean value. */
372typedef KBOOL const *PCKBOOL;
373/** Maxium value the KBOOL type can hold (officially). */
374#define KBOOL_MIN KI8_C(-1)
375/** Maxium value the KBOOL type can hold (officially). */
376#define KBOOL_MAX KI8_C(1)
377/** The KBOOL printf format. */
378#define KBOOL_PRI KU8_PRI
379/** Boolean true constant. */
380#define K_TRUE KI8_C(1)
381/** Boolean false constant. */
382#define K_FALSE KI8_C(0)
383/** Boolean unknown constant (the third state). */
384#define K_UNKNOWN KI8_C(-1)
385
386
387/**
388 * Integer union.
389 */
390typedef union KUINT
391{
392 KFOFF iBig; /**< The biggest member. */
393 KBOOL fBool; /**< Boolean. */
394 KU8 b; /**< unsigned 8-bit. */
395 KU8 u8; /**< unsigned 8-bit. */
396 KI8 i8; /**< signed 8-bit. */
397 KU16 u16; /**< unsigned 16-bit. */
398 KI16 i16; /**< signed 16-bit. */
399 KU32 u32; /**< unsigned 32-bit. */
400 KI32 i32; /**< signed 32-bit. */
401 KU64 u64; /**< unsigned 64-bit. */
402 KI64 i64; /**< signed 64-bit. */
403 KSIZE cbUnsign; /**< unsigned size. */
404 KSSIZE cbSign; /**< signed size. */
405 KFOFF offFile; /**< file offset. */
406 KUPTR uPtr; /**< unsigned pointer. */
407 KIPTR iPtr; /**< signed pointer. */
408 void *pv; /**< void pointer. */
409 char ch; /**< char. */
410 unsigned char uch; /**< unsigned char. */
411 signed char chSigned; /**< signed char. */
412 unsigned short uShort; /**< Unsigned short. */
413 signed short iShort; /**< Signed short. */
414 unsigned int uInt; /**< Unsigned int. */
415 signed int iInt; /**< Signed int. */
416 unsigned long uLong; /**< Unsigned long. */
417 signed long iLong; /**< Signed long. */
418} KUINT;
419
420
421/**
422 * Integer pointer union.
423 */
424typedef union KPUINT
425{
426 KFOFF *piBig; /**< The biggest member. */
427 KBOOL *pfBool; /**< Boolean. */
428 KU8 *pb; /**< unsigned 8-bit. */
429 KU8 *pu8; /**< unsigned 8-bit. */
430 KI8 *pi8; /**< signed 8-bit. */
431 KU16 *pu16; /**< unsigned 16-bit. */
432 KI16 *pi16; /**< signed 16-bit. */
433 KU32 *pu32; /**< unsigned 32-bit. */
434 KI32 *pi32; /**< signed 32-bit. */
435 KU64 *pu64; /**< unsigned 64-bit. */
436 KI64 *pi64; /**< signed 64-bit. */
437 KSIZE *pcbUnsign; /**< unsigned size. */
438 KSSIZE *pcbSign; /**< signed size. */
439 KFOFF *poffFile; /**< file offset. */
440 KUPTR *puPtr; /**< unsigned pointer. */
441 KIPTR *piPtr; /**< signed pointer. */
442 void **ppv; /**< void pointer pointer. */
443 void *pv; /**< void pointer. */
444 char *pch; /**< char. */
445 char *psz; /**< zero terminated string. */
446 unsigned char *puch; /**< unsigned char. */
447 signed char *pchSigned; /**< signed char. */
448 unsigned short *puShort; /**< Unsigned short. */
449 signed short *piShort; /**< Signed short. */
450 unsigned int *puInt; /**< Unsigned int. */
451 signed int *piInt; /**< Signed int. */
452 unsigned long *puLong; /**< Unsigned long. */
453 signed long *piLong; /**< Signed long. */
454} KPUINT;
455
456/**
457 * Integer const pointer union.
458 */
459typedef union KPCUINT
460{
461 KFOFF const *piBig; /**< The biggest member. */
462 KBOOL const *pfBool; /**< Boolean. */
463 KU8 const *pb; /**< byte. */
464 KU8 const *pu8; /**< unsigned 8-bit. */
465 KI8 const *pi8; /**< signed 8-bit. */
466 KU16 const *pu16; /**< unsigned 16-bit. */
467 KI16 const *pi16; /**< signed 16-bit. */
468 KU32 const *pu32; /**< unsigned 32-bit. */
469 KI32 const *pi32; /**< signed 32-bit. */
470 KU64 const *pu64; /**< unsigned 64-bit. */
471 KI64 const *pi64; /**< signed 64-bit. */
472 KSIZE const *pcbUnsign; /**< unsigned size. */
473 KSSIZE const *pcbSign; /**< signed size. */
474 KFOFF const *poffFile; /**< file offset. */
475 KUPTR const *puPtr; /**< unsigned pointer. */
476 KIPTR const *piPtr; /**< signed pointer. */
477 void const **ppv; /**< void pointer pointer. */
478 void const *pv; /**< void pointer. */
479 char const *pch; /**< char. */
480 char const *psz; /**< zero terminated string. */
481 unsigned char const *puch; /**< unsigned char. */
482 signed char const *pchSigned; /**< signed char. */
483 unsigned short const *puShort; /**< Unsigned short. */
484 signed short const *piShort; /**< Signed short. */
485 unsigned int const *puInt; /**< Unsigned int. */
486 signed int const *piInt; /**< Signed int. */
487 unsigned long const *puLong; /**< Unsigned long. */
488 signed long const *piLong; /**< Signed long. */
489} KPCUINT;
490
491
492/** @name Forward Declarations / Handle Types.
493 * @{ */
494
495/** Pointer to a file provider instance. */
496typedef struct KRDR *PKRDR;
497/** Pointer to a file provider instance pointer. */
498typedef struct KRDR **PPKRDR;
499
500/** Pointer to a loader segment. */
501typedef struct KLDRSEG *PKLDRSEG;
502/** Pointer to a loader segment. */
503typedef const struct KLDRSEG *PCKLDRSEG;
504
505/** @} */
506
507/** @} */
508
509#endif
510
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