1 2 /*---------------------------------------------------------------*/ 3 /*--- begin libvex_basictypes.h ---*/ 4 /*---------------------------------------------------------------*/ 5 6 /* 7 This file is part of Valgrind, a dynamic binary instrumentation 8 framework. 9 10 Copyright (C) 2004-2012 OpenWorks LLP 11 info (at) open-works.net 12 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. 17 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. 22 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 26 02110-1301, USA. 27 28 The GNU General Public License is contained in the file COPYING. 29 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. 34 */ 35 36 #ifndef __LIBVEX_BASICTYPES_H 37 #define __LIBVEX_BASICTYPES_H 38 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 41 startup. */ 42 43 /* Always 8 bits. */ 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 48 format strings */ 49 50 /* Always 16 bits. */ 51 typedef unsigned short UShort; 52 typedef signed short Short; 53 54 /* Always 32 bits. */ 55 typedef unsigned int UInt; 56 typedef signed int Int; 57 58 /* Always 64 bits. */ 59 typedef unsigned long long int ULong; 60 typedef signed long long int Long; 61 62 /* Always 128 bits. */ 63 typedef UInt U128[4]; 64 65 /* Always 256 bits. */ 66 typedef UInt U256[8]; 67 68 /* A union for doing 128-bit vector primitives conveniently. */ 69 typedef 70 union { 71 UChar w8[16]; 72 UShort w16[8]; 73 UInt w32[4]; 74 ULong w64[2]; 75 } 76 V128; 77 78 /* Floating point. */ 79 typedef float Float; /* IEEE754 single-precision (32-bit) value */ 80 typedef double Double; /* IEEE754 double-precision (64-bit) value */ 81 82 /* Bool is always 8 bits. */ 83 typedef unsigned char Bool; 84 #define True ((Bool)1) 85 #define False ((Bool)0) 86 87 /* Use this to coerce the result of a C comparison to a Bool. This is 88 useful when compiling with Intel icc with ultra-paranoid 89 compilation flags (-Wall). */ 90 static inline Bool toBool ( Int x ) { 91 Int r = (x == 0) ? False : True; 92 return (Bool)r; 93 } 94 static inline UChar toUChar ( Int x ) { 95 x &= 0xFF; 96 return (UChar)x; 97 } 98 static inline HChar toHChar ( Int x ) { 99 x &= 0xFF; 100 return (HChar)x; 101 } 102 static inline UShort toUShort ( Int x ) { 103 x &= 0xFFFF; 104 return (UShort)x; 105 } 106 static inline Short toShort ( Int x ) { 107 x &= 0xFFFF; 108 return (Short)x; 109 } 110 static inline UInt toUInt ( Long x ) { 111 x &= 0xFFFFFFFFLL; 112 return (UInt)x; 113 } 114 115 /* 32/64 bit addresses. */ 116 typedef UInt Addr32; 117 typedef ULong Addr64; 118 119 /* Something which has the same size as void* on the host. That is, 120 it is 32 bits on a 32-bit host and 64 bits on a 64-bit host, and so 121 it can safely be coerced to and from a pointer type on the host 122 machine. */ 123 typedef unsigned long HWord; 124 125 126 /* This is so useful it should be visible absolutely everywhere. */ 127 #if !defined(offsetof) 128 # define offsetof(type,memb) ((Int)(HWord)&((type*)0)->memb) 129 #endif 130 131 132 /* We need to know the host word size in order to write Ptr_to_ULong 133 and ULong_to_Ptr in a way that doesn't cause compilers to complain. 134 These functions allow us to cast pointers to and from 64-bit 135 integers without complaints from compilers, regardless of the host 136 word size. 137 138 Also set up VEX_REGPARM. 139 */ 140 141 #undef VEX_HOST_WORDSIZE 142 #undef VEX_REGPARM 143 144 /* The following 4 work OK for Linux. */ 145 #if defined(__x86_64__) 146 # define VEX_HOST_WORDSIZE 8 147 # define VEX_REGPARM(_n) /* */ 148 149 #elif defined(__i386__) 150 # define VEX_HOST_WORDSIZE 4 151 # define VEX_REGPARM(_n) __attribute__((regparm(_n))) 152 153 #elif defined(__powerpc__) && defined(__powerpc64__) 154 # define VEX_HOST_WORDSIZE 8 155 # define VEX_REGPARM(_n) /* */ 156 157 #elif defined(__powerpc__) && !defined(__powerpc64__) 158 # define VEX_HOST_WORDSIZE 4 159 # define VEX_REGPARM(_n) /* */ 160 161 #elif defined(__arm__) 162 # define VEX_HOST_WORDSIZE 4 163 # define VEX_REGPARM(_n) /* */ 164 165 #elif defined(_AIX) && !defined(__64BIT__) 166 # define VEX_HOST_WORDSIZE 4 167 # define VEX_REGPARM(_n) /* */ 168 169 #elif defined(_AIX) && defined(__64BIT__) 170 # define VEX_HOST_WORDSIZE 8 171 # define VEX_REGPARM(_n) /* */ 172 173 #elif defined(__s390x__) 174 # define VEX_HOST_WORDSIZE 8 175 # define VEX_REGPARM(_n) /* */ 176 177 #elif defined(__mips__) 178 # define VEX_HOST_WORDSIZE 4 179 # define VEX_REGPARM(_n) /* */ 180 181 #else 182 # error "Vex: Fatal: Can't establish the host architecture" 183 #endif 184 185 186 #if VEX_HOST_WORDSIZE == 8 187 static inline ULong Ptr_to_ULong ( void* p ) { 188 return (ULong)p; 189 } 190 static inline void* ULong_to_Ptr ( ULong n ) { 191 return (void*)n; 192 } 193 #elif VEX_HOST_WORDSIZE == 4 194 static inline ULong Ptr_to_ULong ( void* p ) { 195 UInt w = (UInt)p; 196 return (ULong)w; 197 } 198 static inline void* ULong_to_Ptr ( ULong n ) { 199 UInt w = (UInt)n; 200 return (void*)w; 201 } 202 #else 203 # error "Vex: Fatal: Can't define Ptr_to_ULong / ULong_to_Ptr" 204 #endif 205 206 207 #endif /* ndef __LIBVEX_BASICTYPES_H */ 208 209 /*---------------------------------------------------------------*/ 210 /*--- libvex_basictypes.h ---*/ 211 /*---------------------------------------------------------------*/ 212