Logo Search packages:      
Sourcecode: virtualbox-ose version File versions

kTypes.h

Go to the documentation of this file.
/* $Id: kTypes.h 29 2009-07-01 20:30:29Z bird $ */
/** @file
 * kTypes - Typedefs And Related Constants And Macros.
 */

/*
 * Copyright (c) 2006-2009 Knut St. Osmundsen <bird-kStuff-spamix@anduin.net>
 *
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the "Software"), to deal in the Software without
 * restriction, including without limitation the rights to use,
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following
 * conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 */

#ifndef ___k_kTypes_h___
#define ___k_kTypes_h___

#include <k/kDefs.h>

/** @defgroup grp_kTypes    kTypes - Typedefs And Related Constants And Macros
 * @{
 */

/** @typedef KI64
 * 64-bit signed integer. */
/** @typedef KU64
 * 64-bit unsigned integer. */
/** @def KI64_C
 * 64-bit signed integer constant.
 * @param c         The constant value. */
/** @def KU64_C
 * 64-bit unsigned integer constant.
 * @param c         The constant value. */
/** @def KI64_PRI
 * 64-bit signed integer printf format. */
/** @def KU64_PRI
 * 64-bit unsigned integer printf format. */
/** @def KX64_PRI
 * 64-bit signed and unsigned integer hexadecimal printf format. */

/** @typedef KI32
 * 32-bit signed integer. */
/** @typedef KU32
 * 32-bit unsigned integer. */
/** @def KI32_C
 * 32-bit signed integer constant.
 * @param c         The constant value. */
/** @def KU32_C
 * 32-bit unsigned integer constant.
 * @param c         The constant value. */
/** @def KI32_PRI
 * 32-bit signed integer printf format. */
/** @def KU32_PRI
 * 32-bit unsigned integer printf format. */
/** @def KX32_PRI
 * 32-bit signed and unsigned integer hexadecimal printf format. */

/** @typedef KI16
 * 16-bit signed integer. */
/** @typedef KU16
 * 16-bit unsigned integer. */
/** @def KI16_C
 * 16-bit signed integer constant.
 * @param c         The value. */
/** @def KU16_C
 * 16-bit unsigned integer constant.
 * @param c         The value. */
/** @def KI16_PRI
 * 16-bit signed integer printf format. */
/** @def KU16_PRI
 * 16-bit unsigned integer printf format. */
/** @def KX16_PRI
 * 16-bit signed and unsigned integer hexadecimal printf format. */

/** @typedef KI8
 * 8-bit signed integer. */
/** @typedef KU8
 * 8-bit unsigned integer. */
/** @def KI8_C
 * 8-bit signed integer constant.
 * @param c         The constant value. */
/** @def KU8_C
 * 8-bit unsigned integer constant.
 * @param c         The constant value. */
/** @def KI8_PRI
 * 8-bit signed integer printf format. */
/** @def KU8_PRI
 * 8-bit unsigned integer printf format. */
/** @def KX8_PRI
 * 8-bit signed and unsigned integer hexadecimal printf format. */

/** @typedef KSIZE
 * Memory size type; unsigned integer. */
/** @typedef KSSIZE
 * Memory size type; signed integer. */
/** @def KSIZE_C
 * Memory size constant.
 * @param c         The constant value. */
/** @def KSSIZE_C
 * Memory size constant.
 * @param c         The constant value. */
/** @def KSIZE_MAX
 * Memory size max constant.*/
/** @def KSSIZE_MAX
 * Memory size max constant.*/
/** @def KSSIZE_MIN
 * Memory size min constant.*/
/** @def KSIZE_PRI
 * Memory size printf format. */
/** @def KSSIZE_PRI
 * Memory size printf format. */

/** @typedef KIPTR
 * Signed integer type capable of containing a pointer value.  */
/** @typedef KUPTR
 * Unsigned integer type capable of containing a pointer value.  */
/** @def KIPTR_C
 * Signed pointer constant.
 * @param c         The constant value. */
/** @def KUPTR_C
 * Unsigned pointer constant.
 * @param c         The constant value. */
/** @def KIPTR_MAX
 * Signed pointer max constant.*/
/** @def KIPTR_MIN
 * Signed pointer min constant.*/
/** @def KUPTR_MAX
 * Unsigned pointer max constant.*/
/** @def KIPTR_PRI
 * Signed pointer printf format. */
/** @def KUPTR_PRI
 * Unsigned pointer printf format. */


#if K_ARCH_BITS == 32
  /* ASSUMES int == long == 32-bit, short == 16-bit, char == 8-bit. */
# ifdef _MSC_VER
typedef signed __int64          KI64;
typedef unsigned __int64        KU64;
#define KI64_PRI                "I64d"
#define KU64_PRI                "I64u"
#define KX64_PRI                "I64x"
# else
typedef signed long long int    KI64;
typedef unsigned long long int  KU64;
#define KI64_PRI                "lld"
#define KU64_PRI                "llu"
#define KX64_PRI                "llx"
# endif
typedef signed int              KI32;
typedef unsigned int            KU32;
typedef signed short int        KI16;
typedef unsigned short int      KU16;
typedef signed char             KI8;
typedef unsigned char           KU8;
#define KI64_C(c)               (c ## LL)
#define KU64_C(c)               (c ## ULL)
#define KI32_C(c)               (c)
#define KU32_C(c)               (c)
#define KI16_C(c)               (c)
#define KU16_C(c)               (c)
#define KI8_C(c)                (c)
#define KU8_C(c)                (c)

#define KI32_PRI                "d"
#define KU32_PRI                "u"
#define KX32_PRI                "x"
#define KI16_PRI                "d"
#define KU16_PRI                "u"
#define KX16_PRI                "x"
#define KI8_PRI                 "d"
#define KU8_PRI                 "u"
#define KX8_PRI                 "x"

typedef KI32                    KSSIZE;
#define KSSIZE(c)               KI32_C(c)
#define KSSIZE_MAX              KI32_MAX
#define KSSIZE_MIN              KI32_MIN
#define KSSIZE_PRI              KX32_PRI

typedef KU32                    KSIZE;
#define KSIZE_C(c)              KU32_C(c)
#define KSIZE_MAX               KU32_MAX
#define KSIZE_PRI               KX32_PRI
#define KIPTR_C(c)              KI32_C(c)

typedef KI32                    KIPTR;
#define KIPTR_MAX               KI32_MAX
#define KIPTR_MIN               KI32_MIN
#define KIPTR_PRI               KX32_PRI

typedef KU32                    KUPTR;
#define KUPTR_C(c)              KU32_C(c)
#define KUPTR_MAX               KU32_MAX
#define KUPTR_PRI               KX32_PRI


#elif K_ARCH_BITS == 64

# if K_OS == K_OS_WINDOWS
#  if _MSC_VER
typedef signed __int64          KI64;
typedef unsigned __int64        KU64;
#   define KI64_PRI             "I64d"
#   define KU64_PRI             "I64u"
#   define KX64_PRI             "I64x"
#  else
typedef signed long long int    KI64;
typedef unsigned long long int  KU64;
#   define KI64_PRI              "lld"
#   define KU64_PRI              "llu"
#   define KX64_PRI              "llx"
#  endif
#  define KI64_C(c)             (c ## LL)
#  define KU64_C(c)             (c ## ULL)
# else
typedef signed long int         KI64;
typedef unsigned long int       KU64;
#  define KI64_C(c)             (c ## L)
#  define KU64_C(c)             (c ## UL)
#  define KI64_PRI              "ld"
#  define KU64_PRI              "lu"
#  define KX64_PRI              "lx"
# endif
typedef signed int              KI32;
typedef unsigned int            KU32;
typedef signed short            KI16;
typedef unsigned short          KU16;
typedef signed char             KI8;
typedef unsigned char           KU8;
#define KI32_C(c)               (c)
#define KU32_C(c)               (c)
#define KI16_C(c)               (c)
#define KU16_C(c)               (c)
#define KI8_C(c)                (c)
#define KU8_C(c)                (c)

#define KI32_PRI                "d"
#define KU32_PRI                "u"
#define KX32_PRI                "x"
#define KI16_PRI                "d"
#define KU16_PRI                "u"
#define KX16_PRI                "x"
#define KI8_PRI                 "d"
#define KU8_PRI                 "u"
#define KX8_PRI                 "x"

typedef KI64                    KSSIZE;
#define KSSIZE(c)               KI64_C(c)
#define KSSIZE_MAX              KI64_MAX
#define KSSIZE_MIN              KI64_MIN
#define KSSIZE_PRI              KX64_PRI

typedef KU64                    KSIZE;
#define KSIZE_C(c)              KU64_C(c)
#define KSIZE_MAX               KU64_MAX
#define KSIZE_PRI               KX64_PRI

typedef KI64                    KIPTR;
#define KIPTR_C(c)              KI64_C(c)
#define KIPTR_MAX               KI64_MAX
#define KIPTR_MIN               KI64_MIN
#define KIPTR_PRI               KX64_PRI

typedef KU64                    KUPTR;
#define KUPTR_C(c)              KU64_C(c)
#define KUPTR_MAX               KU64_MAX
#define KUPTR_PRI               KX64_PRI

#else
# error "Port Me"
#endif


/** Min KI8 value. */
00292 #define KI8_MIN                 (KI8_C(-0x7f) - 1)
/** Min KI16 value. */
00294 #define KI16_MIN                (KI16_C(-0x7fff) - 1)
/** Min KI32 value. */
00296 #define KI32_MIN                (KI32_C(-0x7fffffff) - 1)
/** Min KI64 value. */
00298 #define KI64_MIN                (KI64_C(-0x7fffffffffffffff) - 1)
/** Max KI8 value. */
00300 #define KI8_MAX                 KI8_C(0x7f)
/** Max KI16 value. */
00302 #define KI16_MAX                KI16_C(0x7fff)
/** Max KI32 value. */
00304 #define KI32_MAX                KI32_C(0x7fffffff)
/** Max KI64 value. */
00306 #define KI64_MAX                KI64_C(0x7fffffffffffffff)
/** Max KU8 value. */
00308 #define KU8_MAX                 KU8_C(0xff)
/** Max KU16 value. */
00310 #define KU16_MAX                KU16_C(0xffff)
/** Max KU32 value. */
00312 #define KU32_MAX                KU32_C(0xffffffff)
/** Max KU64 value. */
00314 #define KU64_MAX                KU64_C(0xffffffffffffffff)

/** File offset. */
00317 typedef KI64                    KFOFF;
/** Pointer a file offset. */
00319 typedef KFOFF                  *PFOFF;
/** Pointer a const file offset. */
00321 typedef KFOFF                  *PCFOFF;
/** The min value for the KFOFF type. */
00323 #define KFOFF_MIN               KI64_MIN
/** The max value for the KFOFF type. */
00325 #define KFOFF_MAX               KI64_MAX
/** File offset contstant.
 * @param c         The constant value. */
00328 #define KFOFF_C(c)              KI64_C(c)
/** File offset printf format. */
00330 #define KFOFF_PRI               KI64_PRI


/**
 * Memory Protection.
 */
00336 typedef enum KPROT
{
    /** The usual invalid 0. */
00339     KPROT_INVALID = 0,
    /** No access (page not present). */
00341     KPROT_NOACCESS,
    /** Read only. */
00343     KPROT_READONLY,
    /** Read & write. */
00345     KPROT_READWRITE,
    /** Read & copy on write. */
00347     KPROT_WRITECOPY,
    /** Execute only. */
00349     KPROT_EXECUTE,
    /** Execute & read. */
00351     KPROT_EXECUTE_READ,
    /** Execute, read & write. */
00353     KPROT_EXECUTE_READWRITE,
    /** Execute, read & copy on write. */
00355     KPROT_EXECUTE_WRITECOPY,
    /** The usual end value. (exclusive) */
00357     KPROT_END,
    /** Blow the type up to 32-bits. */
00359     KPROT_32BIT_HACK = 0x7fffffff
} KPROT;
/** Pointer to a memory protection enum. */
00362 typedef KPROT                  *PKPROT;
/** Pointer to a const memory protection enum. */
00364 typedef KPROT const            *PCKPROT;

/** Boolean.
 * This can be used as a tri-state type, but then you *must* do == checks. */
00368 typedef KI8                     KBOOL;
/** Pointer to a boolean value. */
00370 typedef KBOOL                  *PKBOOL;
/** Pointer to a const boolean value. */
00372 typedef KBOOL const            *PCKBOOL;
/** Maxium value the KBOOL type can hold (officially). */
00374 #define KBOOL_MIN               KI8_C(-1)
/** Maxium value the KBOOL type can hold (officially). */
00376 #define KBOOL_MAX               KI8_C(1)
/** The KBOOL printf format. */
00378 #define KBOOL_PRI               KU8_PRI
/** Boolean true constant. */
00380 #define K_TRUE                  KI8_C(1)
/** Boolean false constant. */
00382 #define K_FALSE                 KI8_C(0)
/** Boolean unknown constant (the third state). */
00384 #define K_UNKNOWN               KI8_C(-1)


/**
 * Integer union.
 */
00390 typedef union KUINT
{
00392     KFOFF           iBig;               /**< The biggest member. */
00393     KBOOL           fBool;              /**< Boolean. */
00394     KU8             b;                  /**< unsigned 8-bit. */
00395     KU8             u8;                 /**< unsigned 8-bit. */
00396     KI8             i8;                 /**< signed 8-bit.  */
00397     KU16            u16;                /**< unsigned 16-bit. */
00398     KI16            i16;                /**< signed 16-bit. */
00399     KU32            u32;                /**< unsigned 32-bit. */
00400     KI32            i32;                /**< signed 32-bit. */
00401     KU64            u64;                /**< unsigned 64-bit. */
00402     KI64            i64;                /**< signed 64-bit. */
00403     KSIZE           cbUnsign;           /**< unsigned size. */
00404     KSSIZE          cbSign;             /**< signed size. */
00405     KFOFF           offFile;            /**< file offset. */
00406     KUPTR           uPtr;               /**< unsigned pointer. */
00407     KIPTR           iPtr;               /**< signed pointer. */
00408     void           *pv;                 /**< void pointer. */
00409     char            ch;                 /**< char. */
00410     unsigned char   uch;                /**< unsigned char. */
00411     signed char     chSigned;           /**< signed char. */
00412     unsigned short  uShort;             /**< Unsigned short. */
00413     signed short    iShort;             /**< Signed short. */
00414     unsigned int    uInt;               /**< Unsigned int. */
00415     signed int      iInt;               /**< Signed int. */
00416     unsigned long   uLong;              /**< Unsigned long. */
00417     signed long     iLong;              /**< Signed long. */
} KUINT;


/**
 * Integer pointer union.
 */
00424 typedef union KPUINT
{
00426     KFOFF          *piBig;              /**< The biggest member. */
00427     KBOOL          *pfBool;             /**< Boolean. */
00428     KU8            *pb;                 /**< unsigned 8-bit. */
00429     KU8            *pu8;                /**< unsigned 8-bit. */
00430     KI8            *pi8;                /**< signed 8-bit. */
00431     KU16           *pu16;               /**< unsigned 16-bit. */
00432     KI16           *pi16;               /**< signed 16-bit. */
00433     KU32           *pu32;               /**< unsigned 32-bit. */
00434     KI32           *pi32;               /**< signed 32-bit. */
00435     KU64           *pu64;               /**< unsigned 64-bit. */
00436     KI64           *pi64;               /**< signed 64-bit. */
00437     KSIZE          *pcbUnsign;          /**< unsigned size. */
00438     KSSIZE         *pcbSign;            /**< signed size. */
00439     KFOFF          *poffFile;           /**< file offset. */
00440     KUPTR          *puPtr;              /**< unsigned pointer. */
00441     KIPTR          *piPtr;              /**< signed pointer. */
00442     void          **ppv;                /**< void pointer pointer. */
00443     void           *pv;                 /**< void pointer. */
00444     char           *pch;                /**< char. */
00445     char           *psz;                /**< zero terminated string. */
00446     unsigned char  *puch;               /**< unsigned char. */
00447     signed char    *pchSigned;          /**< signed char. */
00448     unsigned short *puShort;            /**< Unsigned short. */
00449     signed short   *piShort;            /**< Signed short. */
00450     unsigned int   *puInt;              /**< Unsigned int. */
00451     signed int     *piInt;              /**< Signed int. */
00452     unsigned long  *puLong;             /**< Unsigned long. */
00453     signed long    *piLong;             /**< Signed long. */
} KPUINT;

/**
 * Integer const pointer union.
 */
00459 typedef union KPCUINT
{
00461     KFOFF  const   *piBig;              /**< The biggest member. */
00462     KBOOL  const   *pfBool;             /**< Boolean. */
00463     KU8    const   *pb;                 /**< byte.  */
00464     KU8    const   *pu8;                /**< unsigned 8-bit.  */
00465     KI8    const   *pi8;                /**< signed 8-bit.  */
00466     KU16   const   *pu16;               /**< unsigned 16-bit. */
00467     KI16   const   *pi16;               /**< signed 16-bit. */
00468     KU32   const   *pu32;               /**< unsigned 32-bit. */
00469     KI32   const   *pi32;               /**< signed 32-bit. */
00470     KU64   const   *pu64;               /**< unsigned 64-bit. */
00471     KI64   const   *pi64;               /**< signed 64-bit. */
00472     KSIZE  const   *pcbUnsign;          /**< unsigned size. */
00473     KSSIZE const   *pcbSign;            /**< signed size. */
00474     KFOFF  const   *poffFile;           /**< file offset. */
00475     KUPTR  const   *puPtr;              /**< unsigned pointer. */
00476     KIPTR  const   *piPtr;              /**< signed pointer. */
00477     void   const  **ppv;                /**< void pointer pointer. */
00478     void   const   *pv;                 /**< void pointer. */
00479     char   const   *pch;                /**< char. */
00480     char   const   *psz;                /**< zero terminated string. */
00481     unsigned char  const *puch;         /**< unsigned char. */
00482     signed char    const *pchSigned;    /**< signed char. */
00483     unsigned short const *puShort;      /**< Unsigned short. */
00484     signed short   const *piShort;      /**< Signed short. */
00485     unsigned int   const *puInt;        /**< Unsigned int. */
00486     signed int     const *piInt;        /**< Signed int. */
00487     unsigned long  const *puLong;       /**< Unsigned long. */
00488     signed long    const *piLong;       /**< Signed long. */
} KPCUINT;


/** @name   Forward Declarations / Handle Types.
 * @{ */

/** Pointer to a file provider instance. */
00496 typedef struct KRDR *PKRDR;
/** Pointer to a file provider instance pointer. */
00498 typedef struct KRDR **PPKRDR;

/** Pointer to a loader segment. */
00501 typedef struct KLDRSEG *PKLDRSEG;
/** Pointer to a loader segment. */
00503 typedef const struct KLDRSEG *PCKLDRSEG;

/** @} */

/** @} */

#endif


Generated by  Doxygen 1.6.0   Back to index