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-2015 OpenWorks LLP
11 info@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 /* This is where we bootstrap msvc compatibility */
40 #ifndef _MSC_VER /* gcc/clang/etc stuff */
41 #define LIKELY(x) __builtin_expect(!!(x), 1)
42 #define UNLIKELY(x) __builtin_expect(!!(x), 0)
43 #define CAST_AS(x) (__typeof__(x))
44
45 #else /* msvc stuff */
46 #define LIKELY(x) (x)
47 #define UNLIKELY(x) (x)
48 #define CAST_AS(x)
49
50 #define __builtin_memset memset
51 #define __builtin_memcpy memcpy
52 #define __PRETTY_FUNCTION__ __FUNCDNAME__
53
54 #define __attribute__(x)
55 #define __attribute(x)
56 #define __inline__
57 #define inline
58 #endif
59
60 /* It is important that the sizes of the following data types (on the
61 host) are as stated. LibVEX_Init therefore checks these at
62 startup. */
63
64 /* Always 8 bits. */
65 typedef unsigned char UChar;
66 typedef signed char Char;
67 typedef char HChar; /* signfulness depends on host */
68 /* Only to be used for printf etc
69 format strings */
70
71 /* Always 16 bits. */
72 typedef unsigned short UShort;
73 typedef signed short Short;
74
75 /* Always 32 bits. */
76 typedef unsigned int UInt;
77 typedef signed int Int;
78
79 /* Always 64 bits. */
80 typedef unsigned long long int ULong;
81 typedef signed long long int Long;
82
83 /* Equivalent of C's size_t type. The type is unsigned and has this
84 storage requirement:
85 32 bits on a 32-bit architecture
86 64 bits on a 64-bit architecture. */
87 typedef unsigned long SizeT;
88
89 /* Always 128 bits. */
90 typedef UInt U128[4];
91
92 /* Always 256 bits. */
93 typedef UInt U256[8];
94
95 /* A union for doing 128-bit vector primitives conveniently. */
96 typedef
97 union {
98 UChar w8[16];
99 UShort w16[8];
100 UInt w32[4];
101 ULong w64[2];
102 }
103 V128;
104
105 /* A union for doing 256-bit vector primitives conveniently. */
106 typedef
107 union {
108 UChar w8[32];
109 UShort w16[16];
110 UInt w32[8];
111 ULong w64[4];
112 }
113 V256;
114
115 /* Floating point. */
116 typedef float Float; /* IEEE754 single-precision (32-bit) value */
117 typedef double Double; /* IEEE754 double-precision (64-bit) value */
118
119 /* Bool is always 8 bits. */
120 typedef unsigned char Bool;
121 #define True ((Bool)1)
122 #define False ((Bool)0)
123
124 /* Use this to coerce the result of a C comparison to a Bool. This is
125 useful when compiling with Intel icc with ultra-paranoid
126 compilation flags (-Wall). */
toBool(Int x)127 static inline Bool toBool ( Int x ) {
128 Int r = (x == 0) ? False : True;
129 return (Bool)r;
130 }
toUChar(Int x)131 static inline UChar toUChar ( Int x ) {
132 x &= 0xFF;
133 return (UChar)x;
134 }
toHChar(Int x)135 static inline HChar toHChar ( Int x ) {
136 x &= 0xFF;
137 return (HChar)x;
138 }
toUShort(Int x)139 static inline UShort toUShort ( Int x ) {
140 x &= 0xFFFF;
141 return (UShort)x;
142 }
toShort(Int x)143 static inline Short toShort ( Int x ) {
144 x &= 0xFFFF;
145 return (Short)x;
146 }
toUInt(Long x)147 static inline UInt toUInt ( Long x ) {
148 x &= 0xFFFFFFFFLL;
149 return (UInt)x;
150 }
151
152 /* 32/64 bit addresses. */
153 typedef UInt Addr32;
154 typedef ULong Addr64;
155
156 /* An address. In order to analyze 64-bit guests on 32-bit hosts, this must be
157 64 bits wide. */
158 typedef Addr64 Addr;
159
160
161 /* Something which has the same size as void* on the host. That is,
162 it is 32 bits on a 32-bit host and 64 bits on a 64-bit host, and so
163 it can safely be coerced to and from a pointer type on the host
164 machine. */
165 #ifdef _WIN64
166 typedef unsigned long long HWord;
167 #else
168 typedef unsigned long HWord;
169 #endif
170
171 /* Set up VEX_HOST_WORDSIZE and VEX_REGPARM. */
172 #undef VEX_HOST_WORDSIZE
173 #undef VEX_REGPARM
174
175 /* The following 4 work OK for Linux. */
176 #if defined(__x86_64__) || defined(_WIN64)
177 # define VEX_HOST_WORDSIZE 8
178 # define VEX_REGPARM(_n) /* */
179
180 #elif defined(__i386__)
181 # define VEX_HOST_WORDSIZE 4
182 # define VEX_REGPARM(_n) __attribute__((regparm(_n)))
183
184 #elif defined(_WIN32) && !defined(_WIN64)
185 # define VEX_HOST_WORDSIZE 4
186 # define VEX_REGPARM(_n) /* ought to be __fastcall */
187
188 #elif defined(__powerpc__) && defined(__powerpc64__)
189 # define VEX_HOST_WORDSIZE 8
190 # define VEX_REGPARM(_n) /* */
191
192 #elif defined(__powerpc__) && !defined(__powerpc64__)
193 # define VEX_HOST_WORDSIZE 4
194 # define VEX_REGPARM(_n) /* */
195
196 #elif defined(__arm__) && !defined(__aarch64__)
197 # define VEX_HOST_WORDSIZE 4
198 # define VEX_REGPARM(_n) /* */
199
200 #elif defined(__aarch64__) && !defined(__arm__)
201 # define VEX_HOST_WORDSIZE 8
202 # define VEX_REGPARM(_n) /* */
203
204 #elif defined(__s390x__)
205 # define VEX_HOST_WORDSIZE 8
206 # define VEX_REGPARM(_n) /* */
207
208 #elif defined(__mips__) && (__mips == 64)
209 # define VEX_HOST_WORDSIZE 8
210 # define VEX_REGPARM(_n) /* */
211
212 #elif defined(__mips__) && (__mips != 64)
213 # define VEX_HOST_WORDSIZE 4
214 # define VEX_REGPARM(_n) /* */
215
216 #elif defined(__tilegx__)
217 # define VEX_HOST_WORDSIZE 8
218 # define VEX_REGPARM(_n) /* */
219
220 #else
221 # error "Vex: Fatal: Can't establish the host architecture"
222 #endif
223
224
225 #endif /* ndef __LIBVEX_BASICTYPES_H */
226
227 /*---------------------------------------------------------------*/
228 /*--- libvex_basictypes.h ---*/
229 /*---------------------------------------------------------------*/
230
231