Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
wine-mirror
GitHub Repository: wine-mirror/wine
Path: blob/master/include/basetsd.h
4389 views
1
/*
2
* Compilers that uses ILP32, LP64 or P64 type models
3
* for both Win32 and Win64 are supported by this file.
4
*
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
19
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20
*/
21
22
#ifndef _BASETSD_H_
23
#define _BASETSD_H_
24
25
#ifdef __cplusplus
26
extern "C" {
27
#endif /* defined(__cplusplus) */
28
29
/*
30
* Win32 was easy to implement under Unix since most 32-bit Unices use the same
31
* type model (ILP32) as Win32, where int, long and pointer are 32-bit.
32
*
33
* Win64, however, can cause some problems. Most 64-bit Unices use the LP64 type
34
* model where int is 32-bit and long and pointer are 64-bit. Win64 on the other
35
* hand uses the LLP64 type model where int and long are 32 bit and pointer is
36
* 64-bit.
37
*/
38
39
#if (defined(__x86_64__) || defined(__powerpc64__) || defined(__aarch64__)) && !defined(_WIN64)
40
#define _WIN64
41
#endif
42
43
/* Type model independent typedefs */
44
/* The __intXX types are native types defined by the MS C compiler.
45
* Apps that make use of them before they get defined here, can
46
* simply add to the command line:
47
* -D__int8=char -D__int16=short -D__int32=int "-D__int64=long long"
48
*/
49
#if !defined(_MSC_VER) && !defined(__WIDL__)
50
# ifndef __int8
51
# define __int8 char
52
# endif
53
# ifndef __int16
54
# define __int16 short
55
# endif
56
# ifndef __int32
57
# define __int32 int
58
# endif
59
# ifndef __int64
60
# if defined(_WIN64) && !defined(__MINGW64__)
61
# define __int64 long
62
# else
63
# define __int64 long long
64
# endif
65
# endif
66
#endif /* !defined(_MSC_VER) */
67
68
#ifndef __has_declspec_attribute
69
# if defined(_MSC_VER)
70
# define __has_declspec_attribute(x) 1
71
# else
72
# define __has_declspec_attribute(x) 0
73
# endif
74
#endif
75
76
/* FIXME: DECLSPEC_ALIGN should be declared only in winnt.h, but we need it here too */
77
#ifndef DECLSPEC_ALIGN
78
# ifdef __GNUC__
79
# define DECLSPEC_ALIGN(x) __attribute__((aligned(x)))
80
# elif __has_declspec_attribute(align) && !defined(MIDL_PASS)
81
# define DECLSPEC_ALIGN(x) __declspec(align(x))
82
# else
83
# define DECLSPEC_ALIGN(x)
84
# endif
85
#endif
86
87
typedef signed char INT8, *PINT8;
88
typedef signed short INT16, *PINT16;
89
typedef signed int INT32, *PINT32;
90
typedef unsigned char UINT8, *PUINT8;
91
typedef unsigned short UINT16, *PUINT16;
92
typedef unsigned int UINT32, *PUINT32;
93
typedef signed int LONG32, *PLONG32;
94
typedef unsigned int ULONG32, *PULONG32;
95
typedef unsigned int DWORD32, *PDWORD32;
96
97
#ifdef _MSC_VER
98
typedef signed __int64 INT64;
99
typedef unsigned __int64 UINT64;
100
typedef signed __int64 LONG64;
101
typedef unsigned __int64 ULONG64;
102
typedef unsigned __int64 DWORD64;
103
#else
104
typedef signed __int64 DECLSPEC_ALIGN(8) INT64;
105
typedef unsigned __int64 DECLSPEC_ALIGN(8) UINT64;
106
typedef signed __int64 DECLSPEC_ALIGN(8) LONG64;
107
typedef unsigned __int64 DECLSPEC_ALIGN(8) ULONG64;
108
typedef unsigned __int64 DECLSPEC_ALIGN(8) DWORD64;
109
#endif
110
typedef INT64 *PINT64;
111
typedef UINT64 *PUINT64;
112
typedef LONG64 *PLONG64;
113
typedef ULONG64 *PULONG64;
114
typedef DWORD64 *PDWORD64;
115
116
/* Basic pointer-sized integer types */
117
118
#if defined(__midl) || defined(__WIDL__)
119
120
typedef /* [public] */ signed __int3264 INT_PTR, *PINT_PTR;
121
typedef /* [public] */ signed __int3264 LONG_PTR, *PLONG_PTR;
122
typedef /* [public] */ unsigned __int3264 UINT_PTR, *PUINT_PTR;
123
typedef /* [public] */ unsigned __int3264 ULONG_PTR, *PULONG_PTR;
124
125
#elif defined(_WIN64)
126
127
#define __int3264 __int64
128
129
typedef signed __int64 INT_PTR, *PINT_PTR;
130
typedef signed __int64 LONG_PTR, *PLONG_PTR;
131
typedef unsigned __int64 UINT_PTR, *PUINT_PTR;
132
typedef unsigned __int64 ULONG_PTR, *PULONG_PTR;
133
134
#else
135
136
#define __int3264 __int32
137
138
typedef int INT_PTR, *PINT_PTR;
139
typedef unsigned int UINT_PTR, *PUINT_PTR;
140
/* clang warns about long type in %I formats */
141
#if defined(__WINESRC__) && defined(__clang__) && (defined(__MINGW32__) || defined(_MSC_VER))
142
typedef int LONG_PTR, *PLONG_PTR;
143
typedef unsigned int ULONG_PTR, *PULONG_PTR;
144
#else
145
typedef long LONG_PTR, *PLONG_PTR;
146
typedef unsigned long ULONG_PTR, *PULONG_PTR;
147
#endif
148
149
#endif
150
151
/* Win32 or Win64 dependent typedef/defines. */
152
153
#ifdef _WIN64
154
155
#define MAXINT_PTR 0x7fffffffffffffff
156
#define MININT_PTR 0x8000000000000000
157
#define MAXUINT_PTR 0xffffffffffffffff
158
159
typedef int HALF_PTR, *PHALF_PTR;
160
typedef unsigned int UHALF_PTR, *PUHALF_PTR;
161
162
#define MAXHALF_PTR 0x7fffffff
163
#define MINHALF_PTR 0x80000000
164
#define MAXUHALF_PTR 0xffffffff
165
166
#if !defined(__midl) && !defined(__WIDL__)
167
168
#if !defined(__LP64__) && !defined(WINE_NO_LONG_TYPES) && !defined(WINE_UNIX_LIB)
169
170
static inline unsigned long HandleToULong(const void *h)
171
{
172
return (unsigned long)(ULONG_PTR)h;
173
}
174
175
static inline long HandleToLong(const void *h)
176
{
177
return (long)(LONG_PTR)h;
178
}
179
180
static inline unsigned long PtrToUlong(const void *p)
181
{
182
return (unsigned long)(ULONG_PTR)p;
183
}
184
185
static inline long PtrToLong(const void *p)
186
{
187
return (long)(LONG_PTR)p;
188
}
189
190
191
#else
192
193
static inline unsigned HandleToULong(const void *h)
194
{
195
return (unsigned)(ULONG_PTR)h;
196
}
197
198
static inline int HandleToLong(const void *h)
199
{
200
return (int)(LONG_PTR)h;
201
}
202
203
static inline unsigned PtrToUlong(const void *p)
204
{
205
return (unsigned)(ULONG_PTR)p;
206
}
207
208
static inline int PtrToLong(const void *p)
209
{
210
return (int)(LONG_PTR)p;
211
}
212
213
214
#endif /* !defined(__LP64__) && !defined(WINE_NO_LONG_TYPES) && !defined(WINE_UNIX_LIB) */
215
216
static inline void *ULongToHandle(ULONG32 ul)
217
{
218
return (void *)(ULONG_PTR)ul;
219
}
220
221
static inline void *LongToHandle(LONG32 l)
222
{
223
return (void *)(LONG_PTR)l;
224
}
225
226
static inline UINT32 PtrToUint(const void *p)
227
{
228
return (UINT32)(UINT_PTR)p;
229
}
230
231
static inline INT32 PtrToInt(const void *p)
232
{
233
return (INT32)(INT_PTR)p;
234
}
235
236
static inline UINT16 PtrToUshort(const void *p)
237
{
238
return (UINT16)(ULONG_PTR)p;
239
}
240
241
static inline INT16 PtrToShort(const void *p)
242
{
243
return (INT16)(LONG_PTR)p;
244
}
245
246
static inline void *IntToPtr(INT32 i)
247
{
248
return (void *)(INT_PTR)i;
249
}
250
251
static inline void *UIntToPtr(UINT32 ui)
252
{
253
return (void *)(UINT_PTR)ui;
254
}
255
256
static inline void *LongToPtr(LONG32 l)
257
{
258
return (void *)(LONG_PTR)l;
259
}
260
261
static inline void *ULongToPtr(ULONG32 ul)
262
{
263
return (void *)(ULONG_PTR)ul;
264
}
265
266
#endif /* !__midl && !__WIDL__ */
267
268
#else /* FIXME: defined(_WIN32) */
269
270
#define MAXINT_PTR 0x7fffffff
271
#define MININT_PTR 0x80000000
272
#define MAXUINT_PTR 0xffffffff
273
274
typedef signed short HALF_PTR, *PHALF_PTR;
275
typedef unsigned short UHALF_PTR, *PUHALF_PTR;
276
277
#define MAXUHALF_PTR 0xffff
278
#define MAXHALF_PTR 0x7fff
279
#define MINHALF_PTR 0x8000
280
281
#define HandleToULong(h) ((ULONG)(ULONG_PTR)(h))
282
#define HandleToLong(h) ((LONG)(LONG_PTR)(h))
283
#define ULongToHandle(ul) ((HANDLE)(ULONG_PTR)(ul))
284
#define LongToHandle(l) ((HANDLE)(LONG_PTR)(l))
285
#define PtrToUlong(p) ((ULONG)(ULONG_PTR)(p))
286
#define PtrToLong(p) ((LONG)(LONG_PTR)(p))
287
#define PtrToUint(p) ((UINT)(UINT_PTR)(p))
288
#define PtrToInt(p) ((INT)(INT_PTR)(p))
289
#define PtrToUshort(p) ((USHORT)(ULONG_PTR)(p))
290
#define PtrToShort(p) ((SHORT)(LONG_PTR)(p))
291
#define IntToPtr(i) ((void *)(INT_PTR)((INT)i))
292
#define UIntToPtr(ui) ((void *)(UINT_PTR)((UINT)ui))
293
#define LongToPtr(l) ((void *)(LONG_PTR)((LONG)l))
294
#define ULongToPtr(ul) ((void *)(ULONG_PTR)((ULONG)ul))
295
296
#endif /* defined(_WIN64) || defined(_WIN32) */
297
298
#define HandleToUlong(h) HandleToULong(h)
299
#define UlongToHandle(ul) ULongToHandle(ul)
300
#define UintToPtr(ui) UIntToPtr(ui)
301
#define UlongToPtr(ul) ULongToPtr(ul)
302
303
typedef LONG_PTR SHANDLE_PTR;
304
typedef ULONG_PTR HANDLE_PTR;
305
typedef LONG_PTR SSIZE_T, *PSSIZE_T;
306
typedef ULONG_PTR SIZE_T, *PSIZE_T;
307
typedef ULONG_PTR DWORD_PTR, *PDWORD_PTR;
308
typedef ULONG_PTR KAFFINITY, *PKAFFINITY;
309
310
#define MINLONGLONG ((LONGLONG)~MAXLONGLONG)
311
312
#ifdef __cplusplus
313
} /* extern "C" */
314
#endif /* defined(__cplusplus) */
315
316
#endif /* !defined(_BASETSD_H_) */
317
318