VirtualBox

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

Last change on this file since 17 was 17, checked in by bird, 16 years ago

k/kTypes.h: Added some big union types that will come in handy when parsing stuff.

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