blob: 6ce0102eb1cd0fec96235019012478e304f9cd29 [file] [log] [blame]
Patrik Stridvall2d0bb2a1999-07-04 15:56:03 +00001/*
2 * Compilers that uses ILP32, LP64 or P64 type models
3 * for both Win32 and Win64 are supported by this file.
Alexandre Julliard0799c1a2002-03-09 23:29:33 +00004 *
5 * Copyright (C) 1999 Patrik Stridvall
6 *
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.
11 *
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.
16 *
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
Jonathan Ernst360a3f92006-05-18 14:49:52 +020019 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
Patrik Stridvall2d0bb2a1999-07-04 15:56:03 +000020 */
21
22#ifndef __WINE_BASETSD_H
23#define __WINE_BASETSD_H
24
Patrik Stridvall2d0bb2a1999-07-04 15:56:03 +000025#ifdef __cplusplus
26extern "C" {
27#endif /* defined(__cplusplus) */
28
29/*
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.
33 *
34 * Win64, however, will cause some problems when implemented under Unix.
Francois Gougeta3317a52007-07-05 16:10:30 +020035 * Linux/{Alpha, Sparc64} and most (all?) other 64-bit Unices use
Patrik Stridvall2d0bb2a1999-07-04 15:56:03 +000036 * 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.
39 */
40
Alexandre Julliard58c64192006-07-10 13:05:20 +020041#if defined(__x86_64__) && !defined(_WIN64)
Alexandre Julliardbdf01c32005-09-22 10:58:04 +000042#define _WIN64
43#endif
44
Francois Gougetdff50042004-08-26 00:31:20 +000045/* Type model independent typedefs */
Dimitrie O. Paunfb829732002-11-23 01:03:40 +000046/* 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"
50 */
Alexandre Julliardf602ec62003-03-16 23:54:18 +000051#if !defined(_MSC_VER) && !defined(__WIDL__)
Dimitrie O. Paunfb829732002-11-23 01:03:40 +000052# ifndef __int8
53# define __int8 char
54# endif
55# ifndef __int16
56# define __int16 short
57# endif
58# ifndef __int32
59# define __int32 int
60# endif
61# ifndef __int64
Alexandre Julliard74d63c02008-12-09 17:42:13 +010062# if defined(_WIN64) && !defined(__MINGW64__)
Alexandre Julliardbdf01c32005-09-22 10:58:04 +000063# define __int64 long
64# else
65# define __int64 long long
66# endif
Dimitrie O. Paunfb829732002-11-23 01:03:40 +000067# endif
Patrik Stridvall395e8ba2002-02-05 18:09:29 +000068#endif /* !defined(_MSC_VER) */
Patrik Stridvall2d0bb2a1999-07-04 15:56:03 +000069
Alexandre Julliard47a88ba2004-05-04 00:43:02 +000070/* 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)))
76# else
77# define DECLSPEC_ALIGN(x)
78# endif
79#endif
80
Alexandre Julliardf602ec62003-03-16 23:54:18 +000081typedef signed char INT8, *PINT8;
82typedef signed short INT16, *PINT16;
83typedef signed int INT32, *PINT32;
Alexandre Julliardf602ec62003-03-16 23:54:18 +000084typedef unsigned char UINT8, *PUINT8;
85typedef unsigned short UINT16, *PUINT16;
86typedef unsigned int UINT32, *PUINT32;
Alexandre Julliardf602ec62003-03-16 23:54:18 +000087typedef signed int LONG32, *PLONG32;
88typedef unsigned int ULONG32, *PULONG32;
89typedef unsigned int DWORD32, *PDWORD32;
James Hawkinsee847952005-02-18 12:56:35 +000090
91#ifdef _MSC_VER
92typedef signed __int64 INT64, *PINT64;
93typedef unsigned __int64 UINT64, *PUINT64;
94typedef signed __int64 LONG64, *PLONG64;
95typedef unsigned __int64 ULONG64, *PULONG64;
96typedef unsigned __int64 DWORD64, *PDWORD64;
97#else
98typedef signed __int64 DECLSPEC_ALIGN(8) INT64, *PINT64;
99typedef unsigned __int64 DECLSPEC_ALIGN(8) UINT64, *PUINT64;
Alexandre Julliard47a88ba2004-05-04 00:43:02 +0000100typedef signed __int64 DECLSPEC_ALIGN(8) LONG64, *PLONG64;
101typedef unsigned __int64 DECLSPEC_ALIGN(8) ULONG64, *PULONG64;
102typedef unsigned __int64 DECLSPEC_ALIGN(8) DWORD64, *PDWORD64;
James Hawkinsee847952005-02-18 12:56:35 +0000103#endif
Patrik Stridvall2d0bb2a1999-07-04 15:56:03 +0000104
Rob Shearman2906af52009-11-07 15:55:01 +0100105/* Basic pointer-sized integer types */
Patrik Stridvall2d0bb2a1999-07-04 15:56:03 +0000106
Rob Shearman2906af52009-11-07 15:55:01 +0100107#if defined(__midl) || defined(__WIDL__)
108
109typedef /* [public] */ signed __int3264 INT_PTR, *PINT_PTR;
110typedef /* [public] */ signed __int3264 LONG_PTR, *PLONG_PTR;
111typedef /* [public] */ unsigned __int3264 UINT_PTR, *PUINT_PTR;
112typedef /* [public] */ unsigned __int3264 ULONG_PTR, *PULONG_PTR;
113typedef ULONG_PTR DWORD_PTR, *PDWORD_PTR;
114
115#elif defined(_WIN64)
116
117#define __int3264 __int64
Patrik Stridvall2d0bb2a1999-07-04 15:56:03 +0000118
Alexandre Julliarddd0bdbe2002-09-12 17:29:12 +0000119typedef signed __int64 INT_PTR, *PINT_PTR;
120typedef signed __int64 LONG_PTR, *PLONG_PTR;
121typedef unsigned __int64 UINT_PTR, *PUINT_PTR;
122typedef unsigned __int64 ULONG_PTR, *PULONG_PTR;
Rob Shearman2906af52009-11-07 15:55:01 +0100123typedef ULONG_PTR DWORD_PTR, *PDWORD_PTR;
124
125#else
126
127#define __int3264 __int32
128
129typedef long INT_PTR, *PINT_PTR;
130typedef unsigned long UINT_PTR, *PUINT_PTR;
131typedef long LONG_PTR, *PLONG_PTR;
132typedef unsigned long ULONG_PTR, *PULONG_PTR;
133typedef ULONG_PTR DWORD_PTR, *PDWORD_PTR;
134
135#endif
136
137/* Win32 or Win64 dependent typedef/defines. */
138
139#ifdef _WIN64
Patrik Stridvall2d0bb2a1999-07-04 15:56:03 +0000140
141#define MAXINT_PTR 0x7fffffffffffffff
142#define MININT_PTR 0x8000000000000000
143#define MAXUINT_PTR 0xffffffffffffffff
144
Jacek Caban1b3f6472009-04-01 03:41:55 +0200145typedef __int64 SHANDLE_PTR;
146typedef unsigned __int64 HANDLE_PTR;
Alexandre Julliardf602ec62003-03-16 23:54:18 +0000147typedef int HALF_PTR, *PHALF_PTR;
148typedef unsigned int UHALF_PTR, *PUHALF_PTR;
Patrik Stridvall2d0bb2a1999-07-04 15:56:03 +0000149
150#define MAXHALF_PTR 0x7fffffff
151#define MINHALF_PTR 0x80000000
152#define MAXUHALF_PTR 0xffffffff
153
Dmitry Timoshkovc3657472007-05-21 19:58:58 +0900154#if !defined(__midl) && !defined(__WIDL__)
155
156static inline ULONG32 HandleToULong(const void *h)
157{
158 return (ULONG_PTR)h;
159}
160
161static inline LONG32 HandleToLong(const void *h)
162{
163 return (LONG_PTR)h;
164}
165
166static inline void *ULongToHandle(ULONG32 ul)
167{
168 return (void *)(ULONG_PTR)ul;
169}
170
171static inline void *LongToHandle(LONG32 l)
172{
173 return (void *)(LONG_PTR)l;
174}
175
176static inline ULONG32 PtrToUlong(const void *p)
177{
178 return (ULONG_PTR)p;
179}
180
181static inline LONG32 PtrToLong(const void *p)
182{
183 return (LONG_PTR)p;
184}
185
186static inline UINT32 PtrToUint(const void *p)
187{
188 return (UINT_PTR)p;
189}
190
191static inline INT32 PtrToInt(const void *p)
192{
193 return (INT_PTR)p;
194}
195
196static inline UINT16 PtrToUshort(const void *p)
197{
198 return (ULONG_PTR)p;
199}
200
201static inline INT16 PtrToShort(const void *p)
202{
203 return (LONG_PTR)p;
204}
205
206static inline void *IntToPtr(INT32 i)
207{
208 return (void *)(INT_PTR)i;
209}
210
211static inline void *UIntToPtr(UINT32 ui)
212{
213 return (void *)(UINT_PTR)ui;
214}
215
216static inline void *LongToPtr(LONG32 l)
217{
218 return (void *)(LONG_PTR)l;
219}
220
221static inline void *ULongToPtr(ULONG32 ul)
222{
223 return (void *)(ULONG_PTR)ul;
224}
225
226#endif /* !__midl && !__WIDL__ */
227
Patrik Stridvall2d0bb2a1999-07-04 15:56:03 +0000228#else /* FIXME: defined(_WIN32) */
229
Patrik Stridvall2d0bb2a1999-07-04 15:56:03 +0000230#define MAXINT_PTR 0x7fffffff
231#define MININT_PTR 0x80000000
232#define MAXUINT_PTR 0xffffffff
233
Jacek Caban1b3f6472009-04-01 03:41:55 +0200234typedef long SHANDLE_PTR;
235typedef unsigned long HANDLE_PTR;
Alexandre Julliardf602ec62003-03-16 23:54:18 +0000236typedef signed short HALF_PTR, *PHALF_PTR;
237typedef unsigned short UHALF_PTR, *PUHALF_PTR;
Patrik Stridvall2d0bb2a1999-07-04 15:56:03 +0000238
239#define MAXUHALF_PTR 0xffff
240#define MAXHALF_PTR 0x7fff
241#define MINHALF_PTR 0x8000
242
Dmitry Timoshkovc3657472007-05-21 19:58:58 +0900243#define HandleToULong(h) ((ULONG)(ULONG_PTR)(h))
244#define HandleToLong(h) ((LONG)(LONG_PTR)(h))
245#define ULongToHandle(ul) ((HANDLE)(ULONG_PTR)(ul))
Dmitry Timoshkov0cfe42b2007-05-23 17:32:33 +0900246#define LongToHandle(l) ((HANDLE)(LONG_PTR)(l))
Dmitry Timoshkovc3657472007-05-21 19:58:58 +0900247#define PtrToUlong(p) ((ULONG)(ULONG_PTR)(p))
248#define PtrToLong(p) ((LONG)(LONG_PTR)(p))
249#define PtrToUint(p) ((UINT)(UINT_PTR)(p))
250#define PtrToInt(p) ((INT)(INT_PTR)(p))
251#define PtrToUshort(p) ((USHORT)(ULONG_PTR)(p))
252#define PtrToShort(p) ((SHORT)(LONG_PTR)(p))
253#define IntToPtr(i) ((void *)(INT_PTR)((INT)i))
254#define UIntToPtr(ui) ((void *)(UINT_PTR)((UINT)ui))
255#define LongToPtr(l) ((void *)(LONG_PTR)((LONG)l))
256#define ULongToPtr(ul) ((void *)(ULONG_PTR)((ULONG)ul))
257
Patrik Stridvall2d0bb2a1999-07-04 15:56:03 +0000258#endif /* defined(_WIN64) || defined(_WIN32) */
259
Dmitry Timoshkov3a12fa92007-07-13 14:18:29 +0900260#define HandleToUlong(h) HandleToULong(h)
261#define UlongToHandle(ul) ULongToHandle(ul)
262#define UintToPtr(ui) UIntToPtr(ui)
263#define UlongToPtr(ul) ULongToPtr(ul)
264
Dmitry Timoshkov472d0162002-09-21 01:21:00 +0000265typedef LONG_PTR SSIZE_T, *PSSIZE_T;
266typedef ULONG_PTR SIZE_T, *PSIZE_T;
Patrik Stridvall2d0bb2a1999-07-04 15:56:03 +0000267
Mike McCormacka941fe72005-06-27 09:49:56 +0000268typedef ULONG_PTR KAFFINITY, *PKAFFINITY;
269
Alexandre Julliard9f0ff1b2002-05-29 02:02:19 +0000270/* Some Wine-specific definitions */
271
272/* Architecture dependent settings. */
273/* These are hardcoded to avoid dependencies on config.h in Winelib apps. */
274#if defined(__i386__)
275# undef WORDS_BIGENDIAN
276# undef BITFIELDS_BIGENDIAN
277# define ALLOW_UNALIGNED_ACCESS
Kevin Koltzauca8c2302005-07-18 09:11:42 +0000278#elif defined(__x86_64__)
279# undef WORDS_BIGENDIAN
280# undef BITFIELDS_BIGENDIAN
281# define ALLOW_UNALIGNED_ACCESS
Alexandre Julliard9f0ff1b2002-05-29 02:02:19 +0000282#elif defined(__sparc__)
283# define WORDS_BIGENDIAN
284# define BITFIELDS_BIGENDIAN
285# undef ALLOW_UNALIGNED_ACCESS
Pierre d'Herbemont7f3074d2003-07-15 20:46:40 +0000286#elif defined(__powerpc__)
Alexandre Julliard9f0ff1b2002-05-29 02:02:19 +0000287# define WORDS_BIGENDIAN
288# define BITFIELDS_BIGENDIAN
289# undef ALLOW_UNALIGNED_ACCESS
Steven Edwards31e46292002-12-10 19:04:45 +0000290#elif defined(__ALPHA__)
Vincent Bérone9903422004-10-18 19:37:30 +0000291# undef WORDS_BIGENDIAN
292# undef BITFIELDS_BIGENDIAN
Steven Edwards31e46292002-12-10 19:04:45 +0000293# undef ALLOW_UNALIGNED_ACCESS
André Hentschel14d51862009-09-22 16:31:17 +0200294#elif defined(__arm__)
295# undef WORDS_BIGENDIAN
296# undef BITFIELDS_BIGENDIAN
297# undef ALLOW_UNALIGNED_ACCESS
Jon Griffiths97709142008-06-28 04:25:54 -0700298#elif !defined(RC_INVOKED) && !defined(__WIDL__) && !defined(__midl)
Alexandre Julliard9f0ff1b2002-05-29 02:02:19 +0000299# error Unknown CPU architecture!
300#endif
301
Patrik Stridvall2d0bb2a1999-07-04 15:56:03 +0000302#ifdef __cplusplus
303} /* extern "C" */
304#endif /* defined(__cplusplus) */
305
306#endif /* !defined(__WINE_BASETSD_H) */