2 * Compilers that uses ILP32, LP64 or P64 type models
3 * for both Win32 and Win64 are supported by this file.
5 * Copyright (C) 1999 Patrik Stridvall
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #ifndef __WINE_BASETSD_H
23 #define __WINE_BASETSD_H
27 #endif /* defined(__cplusplus) */
30 * Win32 was easy to implement under Unix since most (all?) 32-bit
31 * Unices uses the same type model (ILP32) as Win32, where int, long
32 * and pointer are 32-bit.
34 * Win64, however, will cause some problems when implemented under Unix.
35 * Linux/{Alpha, Sparc64} and most (all?) other 64-bit Unices use
36 * the LP64 type model where int is 32-bit and long and pointer are
37 * 64-bit. Win64 on the other hand uses the P64 (sometimes called LLP64)
38 * type model where int and long are 32 bit and pointer is 64-bit.
41 #if defined(__x86_64__) && !defined(_WIN64)
45 /* Type model independent typedefs */
46 /* The __intXX types are native types defined by the MS C compiler.
47 * Apps that make use of them before they get defined here, can
48 * simply add to the command line:
49 * -D__int8=char -D__int16=short -D__int32=int "-D__int64=long long"
51 #if !defined(_MSC_VER) && !defined(__WIDL__)
56 # define __int16 short
62 # if defined(_WIN64) && !defined(__MINGW64__)
65 # define __int64 long long
68 #endif /* !defined(_MSC_VER) */
70 /* FIXME: DECLSPEC_ALIGN should be declared only in winnt.h, but we need it here too */
71 #ifndef DECLSPEC_ALIGN
72 # if defined(_MSC_VER) && (_MSC_VER >= 1300) && !defined(MIDL_PASS)
73 # define DECLSPEC_ALIGN(x) __declspec(align(x))
74 # elif defined(__GNUC__)
75 # define DECLSPEC_ALIGN(x) __attribute__((aligned(x)))
77 # define DECLSPEC_ALIGN(x)
81 typedef signed char INT8, *PINT8;
82 typedef signed short INT16, *PINT16;
83 typedef signed int INT32, *PINT32;
84 typedef unsigned char UINT8, *PUINT8;
85 typedef unsigned short UINT16, *PUINT16;
86 typedef unsigned int UINT32, *PUINT32;
87 typedef signed int LONG32, *PLONG32;
88 typedef unsigned int ULONG32, *PULONG32;
89 typedef unsigned int DWORD32, *PDWORD32;
92 typedef signed __int64 INT64, *PINT64;
93 typedef unsigned __int64 UINT64, *PUINT64;
94 typedef signed __int64 LONG64, *PLONG64;
95 typedef unsigned __int64 ULONG64, *PULONG64;
96 typedef unsigned __int64 DWORD64, *PDWORD64;
98 typedef signed __int64 DECLSPEC_ALIGN(8) INT64, *PINT64;
99 typedef unsigned __int64 DECLSPEC_ALIGN(8) UINT64, *PUINT64;
100 typedef signed __int64 DECLSPEC_ALIGN(8) LONG64, *PLONG64;
101 typedef unsigned __int64 DECLSPEC_ALIGN(8) ULONG64, *PULONG64;
102 typedef unsigned __int64 DECLSPEC_ALIGN(8) DWORD64, *PDWORD64;
105 /* Win32 or Win64 dependent typedef/defines. */
109 typedef signed __int64 INT_PTR, *PINT_PTR;
110 typedef signed __int64 LONG_PTR, *PLONG_PTR;
111 typedef unsigned __int64 UINT_PTR, *PUINT_PTR;
112 typedef unsigned __int64 ULONG_PTR, *PULONG_PTR;
113 typedef unsigned __int64 DWORD_PTR, *PDWORD_PTR;
115 #define MAXINT_PTR 0x7fffffffffffffff
116 #define MININT_PTR 0x8000000000000000
117 #define MAXUINT_PTR 0xffffffffffffffff
119 typedef int HALF_PTR, *PHALF_PTR;
120 typedef unsigned int UHALF_PTR, *PUHALF_PTR;
122 #define MAXHALF_PTR 0x7fffffff
123 #define MINHALF_PTR 0x80000000
124 #define MAXUHALF_PTR 0xffffffff
126 #if !defined(__midl) && !defined(__WIDL__)
128 static inline ULONG32 HandleToULong(const void *h)
133 static inline LONG32 HandleToLong(const void *h)
138 static inline void *ULongToHandle(ULONG32 ul)
140 return (void *)(ULONG_PTR)ul;
143 static inline void *LongToHandle(LONG32 l)
145 return (void *)(LONG_PTR)l;
148 static inline ULONG32 PtrToUlong(const void *p)
153 static inline LONG32 PtrToLong(const void *p)
158 static inline UINT32 PtrToUint(const void *p)
163 static inline INT32 PtrToInt(const void *p)
168 static inline UINT16 PtrToUshort(const void *p)
173 static inline INT16 PtrToShort(const void *p)
178 static inline void *IntToPtr(INT32 i)
180 return (void *)(INT_PTR)i;
183 static inline void *UIntToPtr(UINT32 ui)
185 return (void *)(UINT_PTR)ui;
188 static inline void *LongToPtr(LONG32 l)
190 return (void *)(LONG_PTR)l;
193 static inline void *ULongToPtr(ULONG32 ul)
195 return (void *)(ULONG_PTR)ul;
198 #endif /* !__midl && !__WIDL__ */
200 #else /* FIXME: defined(_WIN32) */
202 typedef long INT_PTR, *PINT_PTR;
203 typedef unsigned long UINT_PTR, *PUINT_PTR;
204 typedef long LONG_PTR, *PLONG_PTR;
205 typedef unsigned long ULONG_PTR, *PULONG_PTR;
206 typedef ULONG_PTR DWORD_PTR, *PDWORD_PTR;
208 #define MAXINT_PTR 0x7fffffff
209 #define MININT_PTR 0x80000000
210 #define MAXUINT_PTR 0xffffffff
212 typedef signed short HALF_PTR, *PHALF_PTR;
213 typedef unsigned short UHALF_PTR, *PUHALF_PTR;
215 #define MAXUHALF_PTR 0xffff
216 #define MAXHALF_PTR 0x7fff
217 #define MINHALF_PTR 0x8000
219 #define HandleToULong(h) ((ULONG)(ULONG_PTR)(h))
220 #define HandleToLong(h) ((LONG)(LONG_PTR)(h))
221 #define ULongToHandle(ul) ((HANDLE)(ULONG_PTR)(ul))
222 #define LongToHandle(l) ((HANDLE)(LONG_PTR)(l))
223 #define PtrToUlong(p) ((ULONG)(ULONG_PTR)(p))
224 #define PtrToLong(p) ((LONG)(LONG_PTR)(p))
225 #define PtrToUint(p) ((UINT)(UINT_PTR)(p))
226 #define PtrToInt(p) ((INT)(INT_PTR)(p))
227 #define PtrToUshort(p) ((USHORT)(ULONG_PTR)(p))
228 #define PtrToShort(p) ((SHORT)(LONG_PTR)(p))
229 #define IntToPtr(i) ((void *)(INT_PTR)((INT)i))
230 #define UIntToPtr(ui) ((void *)(UINT_PTR)((UINT)ui))
231 #define LongToPtr(l) ((void *)(LONG_PTR)((LONG)l))
232 #define ULongToPtr(ul) ((void *)(ULONG_PTR)((ULONG)ul))
234 #endif /* defined(_WIN64) || defined(_WIN32) */
236 #define HandleToUlong(h) HandleToULong(h)
237 #define UlongToHandle(ul) ULongToHandle(ul)
238 #define UintToPtr(ui) UIntToPtr(ui)
239 #define UlongToPtr(ul) ULongToPtr(ul)
241 typedef LONG_PTR SSIZE_T, *PSSIZE_T;
242 typedef ULONG_PTR SIZE_T, *PSIZE_T;
244 typedef ULONG_PTR KAFFINITY, *PKAFFINITY;
246 /* Some Wine-specific definitions */
248 /* Architecture dependent settings. */
249 /* These are hardcoded to avoid dependencies on config.h in Winelib apps. */
250 #if defined(__i386__)
251 # undef WORDS_BIGENDIAN
252 # undef BITFIELDS_BIGENDIAN
253 # define ALLOW_UNALIGNED_ACCESS
254 #elif defined(__x86_64__)
255 # undef WORDS_BIGENDIAN
256 # undef BITFIELDS_BIGENDIAN
257 # define ALLOW_UNALIGNED_ACCESS
258 #elif defined(__sparc__)
259 # define WORDS_BIGENDIAN
260 # define BITFIELDS_BIGENDIAN
261 # undef ALLOW_UNALIGNED_ACCESS
262 #elif defined(__powerpc__)
263 # define WORDS_BIGENDIAN
264 # define BITFIELDS_BIGENDIAN
265 # undef ALLOW_UNALIGNED_ACCESS
266 #elif defined(__ALPHA__)
267 # undef WORDS_BIGENDIAN
268 # undef BITFIELDS_BIGENDIAN
269 # undef ALLOW_UNALIGNED_ACCESS
270 #elif !defined(RC_INVOKED) && !defined(__WIDL__) && !defined(__midl)
271 # error Unknown CPU architecture!
276 #endif /* defined(__cplusplus) */
278 #endif /* !defined(__WINE_BASETSD_H) */