2 /*---------------------------------------------------------------*/
3 /*--- begin libvex_basictypes.h ---*/
4 /*---------------------------------------------------------------*/
7 This file is part of Valgrind, a dynamic binary instrumentation
10 Copyright (C) 2004-2010 OpenWorks LLP
13 This program is free software; you can redistribute it and/or
14 modify it under the terms of the GNU General Public License as
15 published by the Free Software Foundation; either version 2 of the
16 License, or (at your option) any later version.
18 This program is distributed in the hope that it will be useful, but
19 WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
28 The GNU General Public License is contained in the file COPYING.
30 Neither the names of the U.S. Department of Energy nor the
31 University of California nor the names of its contributors may be
32 used to endorse or promote products derived from this software
33 without prior written permission.
36 #ifndef __LIBVEX_BASICTYPES_H
37 #define __LIBVEX_BASICTYPES_H
39 /* It is important that the sizes of the following data types (on the
40 host) are as stated. LibVEX_Init therefore checks these at
44 typedef unsigned char UChar;
45 typedef signed char Char;
46 typedef char HChar; /* signfulness depends on host */
47 /* Only to be used for printf etc
51 typedef unsigned short UShort;
52 typedef signed short Short;
55 typedef unsigned int UInt;
56 typedef signed int Int;
59 typedef unsigned long long int ULong;
60 typedef signed long long int Long;
62 /* Always 128 bits. */
65 /* A union for doing 128-bit vector primitives conveniently. */
76 typedef float Float; /* IEEE754 single-precision (32-bit) value */
77 typedef double Double; /* IEEE754 double-precision (64-bit) value */
79 /* Bool is always 8 bits. */
80 typedef unsigned char Bool;
81 #define True ((Bool)1)
82 #define False ((Bool)0)
84 /* Use this to coerce the result of a C comparison to a Bool. This is
85 useful when compiling with Intel icc with ultra-paranoid
86 compilation flags (-Wall). */
87 static inline Bool toBool ( Int x ) {
88 Int r = (x == 0) ? False : True;
91 static inline UChar toUChar ( Int x ) {
95 static inline HChar toHChar ( Int x ) {
99 static inline UShort toUShort ( Int x ) {
103 static inline Short toShort ( Int x ) {
107 static inline UInt toUInt ( Long x ) {
112 /* 32/64 bit addresses. */
114 typedef ULong Addr64;
116 /* Something which has the same size as void* on the host. That is,
117 it is 32 bits on a 32-bit host and 64 bits on a 64-bit host, and so
118 it can safely be coerced to and from a pointer type on the host
120 typedef unsigned long HWord;
123 /* This is so useful it should be visible absolutely everywhere. */
124 #if !defined(offsetof)
125 # define offsetof(type,memb) ((Int)(HWord)&((type*)0)->memb)
129 /* We need to know the host word size in order to write Ptr_to_ULong
130 and ULong_to_Ptr in a way that doesn't cause compilers to complain.
131 These functions allow us to cast pointers to and from 64-bit
132 integers without complaints from compilers, regardless of the host
135 #undef VEX_HOST_WORDSIZE
137 /* The following 4 work OK for Linux. */
138 #if defined(__x86_64__)
139 # define VEX_HOST_WORDSIZE 8
140 #elif defined(__i386__)
141 # define VEX_HOST_WORDSIZE 4
142 #elif defined(__powerpc__) && defined(__powerpc64__)
143 # define VEX_HOST_WORDSIZE 8
144 #elif defined(__powerpc__) && !defined(__powerpc64__)
145 # define VEX_HOST_WORDSIZE 4
146 #elif defined(__arm__)
147 # define VEX_HOST_WORDSIZE 4
149 #elif defined(_AIX) && !defined(__64BIT__)
150 # define VEX_HOST_WORDSIZE 4
151 #elif defined(_AIX) && defined(__64BIT__)
152 # define VEX_HOST_WORDSIZE 8
155 # error "Vex: Fatal: Can't establish the host architecture"
159 #if VEX_HOST_WORDSIZE == 8
160 static inline ULong Ptr_to_ULong ( void* p ) {
163 static inline void* ULong_to_Ptr ( ULong n ) {
166 #elif VEX_HOST_WORDSIZE == 4
167 static inline ULong Ptr_to_ULong ( void* p ) {
171 static inline void* ULong_to_Ptr ( ULong n ) {
176 # error "Vex: Fatal: Can't define Ptr_to_ULong / ULong_to_Ptr"
180 #endif /* ndef __LIBVEX_BASICTYPES_H */
182 /*---------------------------------------------------------------*/
183 /*--- libvex_basictypes.h ---*/
184 /*---------------------------------------------------------------*/