Patrik Stridvall | 2d0bb2a | 1999-07-04 15:56:03 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Compilers that uses ILP32, LP64 or P64 type models |
| 3 | * for both Win32 and Win64 are supported by this file. |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 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 |
Jonathan Ernst | 360a3f9 | 2006-05-18 14:49:52 +0200 | [diff] [blame] | 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA |
Patrik Stridvall | 2d0bb2a | 1999-07-04 15:56:03 +0000 | [diff] [blame] | 20 | */ |
| 21 | |
| 22 | #ifndef __WINE_BASETSD_H |
| 23 | #define __WINE_BASETSD_H |
| 24 | |
Patrik Stridvall | 2d0bb2a | 1999-07-04 15:56:03 +0000 | [diff] [blame] | 25 | #ifdef __cplusplus |
| 26 | extern "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 Gouget | a3317a5 | 2007-07-05 16:10:30 +0200 | [diff] [blame] | 35 | * Linux/{Alpha, Sparc64} and most (all?) other 64-bit Unices use |
Patrik Stridvall | 2d0bb2a | 1999-07-04 15:56:03 +0000 | [diff] [blame] | 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. |
| 39 | */ |
| 40 | |
Alexandre Julliard | 58c6419 | 2006-07-10 13:05:20 +0200 | [diff] [blame] | 41 | #if defined(__x86_64__) && !defined(_WIN64) |
Alexandre Julliard | bdf01c3 | 2005-09-22 10:58:04 +0000 | [diff] [blame] | 42 | #define _WIN64 |
| 43 | #endif |
| 44 | |
Francois Gouget | dff5004 | 2004-08-26 00:31:20 +0000 | [diff] [blame] | 45 | /* Type model independent typedefs */ |
Dimitrie O. Paun | fb82973 | 2002-11-23 01:03:40 +0000 | [diff] [blame] | 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" |
| 50 | */ |
Alexandre Julliard | f602ec6 | 2003-03-16 23:54:18 +0000 | [diff] [blame] | 51 | #if !defined(_MSC_VER) && !defined(__WIDL__) |
Dimitrie O. Paun | fb82973 | 2002-11-23 01:03:40 +0000 | [diff] [blame] | 52 | # 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 Julliard | 74d63c0 | 2008-12-09 17:42:13 +0100 | [diff] [blame] | 62 | # if defined(_WIN64) && !defined(__MINGW64__) |
Alexandre Julliard | bdf01c3 | 2005-09-22 10:58:04 +0000 | [diff] [blame] | 63 | # define __int64 long |
| 64 | # else |
| 65 | # define __int64 long long |
| 66 | # endif |
Dimitrie O. Paun | fb82973 | 2002-11-23 01:03:40 +0000 | [diff] [blame] | 67 | # endif |
Patrik Stridvall | 395e8ba | 2002-02-05 18:09:29 +0000 | [diff] [blame] | 68 | #endif /* !defined(_MSC_VER) */ |
Patrik Stridvall | 2d0bb2a | 1999-07-04 15:56:03 +0000 | [diff] [blame] | 69 | |
Alexandre Julliard | 47a88ba | 2004-05-04 00:43:02 +0000 | [diff] [blame] | 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))) |
| 76 | # else |
| 77 | # define DECLSPEC_ALIGN(x) |
| 78 | # endif |
| 79 | #endif |
| 80 | |
Alexandre Julliard | f602ec6 | 2003-03-16 23:54:18 +0000 | [diff] [blame] | 81 | typedef signed char INT8, *PINT8; |
| 82 | typedef signed short INT16, *PINT16; |
| 83 | typedef signed int INT32, *PINT32; |
Alexandre Julliard | f602ec6 | 2003-03-16 23:54:18 +0000 | [diff] [blame] | 84 | typedef unsigned char UINT8, *PUINT8; |
| 85 | typedef unsigned short UINT16, *PUINT16; |
| 86 | typedef unsigned int UINT32, *PUINT32; |
Alexandre Julliard | f602ec6 | 2003-03-16 23:54:18 +0000 | [diff] [blame] | 87 | typedef signed int LONG32, *PLONG32; |
| 88 | typedef unsigned int ULONG32, *PULONG32; |
| 89 | typedef unsigned int DWORD32, *PDWORD32; |
James Hawkins | ee84795 | 2005-02-18 12:56:35 +0000 | [diff] [blame] | 90 | |
| 91 | #ifdef _MSC_VER |
| 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; |
| 97 | #else |
| 98 | typedef signed __int64 DECLSPEC_ALIGN(8) INT64, *PINT64; |
| 99 | typedef unsigned __int64 DECLSPEC_ALIGN(8) UINT64, *PUINT64; |
Alexandre Julliard | 47a88ba | 2004-05-04 00:43:02 +0000 | [diff] [blame] | 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; |
James Hawkins | ee84795 | 2005-02-18 12:56:35 +0000 | [diff] [blame] | 103 | #endif |
Patrik Stridvall | 2d0bb2a | 1999-07-04 15:56:03 +0000 | [diff] [blame] | 104 | |
| 105 | /* Win32 or Win64 dependent typedef/defines. */ |
| 106 | |
| 107 | #ifdef _WIN64 |
| 108 | |
Alexandre Julliard | dd0bdbe | 2002-09-12 17:29:12 +0000 | [diff] [blame] | 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; |
Patrik Stridvall | 2d0bb2a | 1999-07-04 15:56:03 +0000 | [diff] [blame] | 114 | |
| 115 | #define MAXINT_PTR 0x7fffffffffffffff |
| 116 | #define MININT_PTR 0x8000000000000000 |
| 117 | #define MAXUINT_PTR 0xffffffffffffffff |
| 118 | |
Jacek Caban | 1b3f647 | 2009-04-01 03:41:55 +0200 | [diff] [blame] | 119 | typedef __int64 SHANDLE_PTR; |
| 120 | typedef unsigned __int64 HANDLE_PTR; |
Alexandre Julliard | f602ec6 | 2003-03-16 23:54:18 +0000 | [diff] [blame] | 121 | typedef int HALF_PTR, *PHALF_PTR; |
| 122 | typedef unsigned int UHALF_PTR, *PUHALF_PTR; |
Patrik Stridvall | 2d0bb2a | 1999-07-04 15:56:03 +0000 | [diff] [blame] | 123 | |
| 124 | #define MAXHALF_PTR 0x7fffffff |
| 125 | #define MINHALF_PTR 0x80000000 |
| 126 | #define MAXUHALF_PTR 0xffffffff |
| 127 | |
Dmitry Timoshkov | c365747 | 2007-05-21 19:58:58 +0900 | [diff] [blame] | 128 | #if !defined(__midl) && !defined(__WIDL__) |
| 129 | |
| 130 | static inline ULONG32 HandleToULong(const void *h) |
| 131 | { |
| 132 | return (ULONG_PTR)h; |
| 133 | } |
| 134 | |
| 135 | static inline LONG32 HandleToLong(const void *h) |
| 136 | { |
| 137 | return (LONG_PTR)h; |
| 138 | } |
| 139 | |
| 140 | static inline void *ULongToHandle(ULONG32 ul) |
| 141 | { |
| 142 | return (void *)(ULONG_PTR)ul; |
| 143 | } |
| 144 | |
| 145 | static inline void *LongToHandle(LONG32 l) |
| 146 | { |
| 147 | return (void *)(LONG_PTR)l; |
| 148 | } |
| 149 | |
| 150 | static inline ULONG32 PtrToUlong(const void *p) |
| 151 | { |
| 152 | return (ULONG_PTR)p; |
| 153 | } |
| 154 | |
| 155 | static inline LONG32 PtrToLong(const void *p) |
| 156 | { |
| 157 | return (LONG_PTR)p; |
| 158 | } |
| 159 | |
| 160 | static inline UINT32 PtrToUint(const void *p) |
| 161 | { |
| 162 | return (UINT_PTR)p; |
| 163 | } |
| 164 | |
| 165 | static inline INT32 PtrToInt(const void *p) |
| 166 | { |
| 167 | return (INT_PTR)p; |
| 168 | } |
| 169 | |
| 170 | static inline UINT16 PtrToUshort(const void *p) |
| 171 | { |
| 172 | return (ULONG_PTR)p; |
| 173 | } |
| 174 | |
| 175 | static inline INT16 PtrToShort(const void *p) |
| 176 | { |
| 177 | return (LONG_PTR)p; |
| 178 | } |
| 179 | |
| 180 | static inline void *IntToPtr(INT32 i) |
| 181 | { |
| 182 | return (void *)(INT_PTR)i; |
| 183 | } |
| 184 | |
| 185 | static inline void *UIntToPtr(UINT32 ui) |
| 186 | { |
| 187 | return (void *)(UINT_PTR)ui; |
| 188 | } |
| 189 | |
| 190 | static inline void *LongToPtr(LONG32 l) |
| 191 | { |
| 192 | return (void *)(LONG_PTR)l; |
| 193 | } |
| 194 | |
| 195 | static inline void *ULongToPtr(ULONG32 ul) |
| 196 | { |
| 197 | return (void *)(ULONG_PTR)ul; |
| 198 | } |
| 199 | |
| 200 | #endif /* !__midl && !__WIDL__ */ |
| 201 | |
Patrik Stridvall | 2d0bb2a | 1999-07-04 15:56:03 +0000 | [diff] [blame] | 202 | #else /* FIXME: defined(_WIN32) */ |
| 203 | |
Dmitry Timoshkov | 3c9e7a7 | 2007-05-24 23:41:17 +0900 | [diff] [blame] | 204 | typedef long INT_PTR, *PINT_PTR; |
| 205 | typedef unsigned long UINT_PTR, *PUINT_PTR; |
Dmitry Timoshkov | 472d016 | 2002-09-21 01:21:00 +0000 | [diff] [blame] | 206 | typedef long LONG_PTR, *PLONG_PTR; |
Dmitry Timoshkov | 472d016 | 2002-09-21 01:21:00 +0000 | [diff] [blame] | 207 | typedef unsigned long ULONG_PTR, *PULONG_PTR; |
| 208 | typedef ULONG_PTR DWORD_PTR, *PDWORD_PTR; |
Patrik Stridvall | 2d0bb2a | 1999-07-04 15:56:03 +0000 | [diff] [blame] | 209 | |
| 210 | #define MAXINT_PTR 0x7fffffff |
| 211 | #define MININT_PTR 0x80000000 |
| 212 | #define MAXUINT_PTR 0xffffffff |
| 213 | |
Jacek Caban | 1b3f647 | 2009-04-01 03:41:55 +0200 | [diff] [blame] | 214 | typedef long SHANDLE_PTR; |
| 215 | typedef unsigned long HANDLE_PTR; |
Alexandre Julliard | f602ec6 | 2003-03-16 23:54:18 +0000 | [diff] [blame] | 216 | typedef signed short HALF_PTR, *PHALF_PTR; |
| 217 | typedef unsigned short UHALF_PTR, *PUHALF_PTR; |
Patrik Stridvall | 2d0bb2a | 1999-07-04 15:56:03 +0000 | [diff] [blame] | 218 | |
| 219 | #define MAXUHALF_PTR 0xffff |
| 220 | #define MAXHALF_PTR 0x7fff |
| 221 | #define MINHALF_PTR 0x8000 |
| 222 | |
Dmitry Timoshkov | c365747 | 2007-05-21 19:58:58 +0900 | [diff] [blame] | 223 | #define HandleToULong(h) ((ULONG)(ULONG_PTR)(h)) |
| 224 | #define HandleToLong(h) ((LONG)(LONG_PTR)(h)) |
| 225 | #define ULongToHandle(ul) ((HANDLE)(ULONG_PTR)(ul)) |
Dmitry Timoshkov | 0cfe42b | 2007-05-23 17:32:33 +0900 | [diff] [blame] | 226 | #define LongToHandle(l) ((HANDLE)(LONG_PTR)(l)) |
Dmitry Timoshkov | c365747 | 2007-05-21 19:58:58 +0900 | [diff] [blame] | 227 | #define PtrToUlong(p) ((ULONG)(ULONG_PTR)(p)) |
| 228 | #define PtrToLong(p) ((LONG)(LONG_PTR)(p)) |
| 229 | #define PtrToUint(p) ((UINT)(UINT_PTR)(p)) |
| 230 | #define PtrToInt(p) ((INT)(INT_PTR)(p)) |
| 231 | #define PtrToUshort(p) ((USHORT)(ULONG_PTR)(p)) |
| 232 | #define PtrToShort(p) ((SHORT)(LONG_PTR)(p)) |
| 233 | #define IntToPtr(i) ((void *)(INT_PTR)((INT)i)) |
| 234 | #define UIntToPtr(ui) ((void *)(UINT_PTR)((UINT)ui)) |
| 235 | #define LongToPtr(l) ((void *)(LONG_PTR)((LONG)l)) |
| 236 | #define ULongToPtr(ul) ((void *)(ULONG_PTR)((ULONG)ul)) |
| 237 | |
Patrik Stridvall | 2d0bb2a | 1999-07-04 15:56:03 +0000 | [diff] [blame] | 238 | #endif /* defined(_WIN64) || defined(_WIN32) */ |
| 239 | |
Dmitry Timoshkov | 3a12fa9 | 2007-07-13 14:18:29 +0900 | [diff] [blame] | 240 | #define HandleToUlong(h) HandleToULong(h) |
| 241 | #define UlongToHandle(ul) ULongToHandle(ul) |
| 242 | #define UintToPtr(ui) UIntToPtr(ui) |
| 243 | #define UlongToPtr(ul) ULongToPtr(ul) |
| 244 | |
Dmitry Timoshkov | 472d016 | 2002-09-21 01:21:00 +0000 | [diff] [blame] | 245 | typedef LONG_PTR SSIZE_T, *PSSIZE_T; |
| 246 | typedef ULONG_PTR SIZE_T, *PSIZE_T; |
Patrik Stridvall | 2d0bb2a | 1999-07-04 15:56:03 +0000 | [diff] [blame] | 247 | |
Mike McCormack | a941fe7 | 2005-06-27 09:49:56 +0000 | [diff] [blame] | 248 | typedef ULONG_PTR KAFFINITY, *PKAFFINITY; |
| 249 | |
Alexandre Julliard | 9f0ff1b | 2002-05-29 02:02:19 +0000 | [diff] [blame] | 250 | /* Some Wine-specific definitions */ |
| 251 | |
| 252 | /* Architecture dependent settings. */ |
| 253 | /* These are hardcoded to avoid dependencies on config.h in Winelib apps. */ |
| 254 | #if defined(__i386__) |
| 255 | # undef WORDS_BIGENDIAN |
| 256 | # undef BITFIELDS_BIGENDIAN |
| 257 | # define ALLOW_UNALIGNED_ACCESS |
Kevin Koltzau | ca8c230 | 2005-07-18 09:11:42 +0000 | [diff] [blame] | 258 | #elif defined(__x86_64__) |
| 259 | # undef WORDS_BIGENDIAN |
| 260 | # undef BITFIELDS_BIGENDIAN |
| 261 | # define ALLOW_UNALIGNED_ACCESS |
Alexandre Julliard | 9f0ff1b | 2002-05-29 02:02:19 +0000 | [diff] [blame] | 262 | #elif defined(__sparc__) |
| 263 | # define WORDS_BIGENDIAN |
| 264 | # define BITFIELDS_BIGENDIAN |
| 265 | # undef ALLOW_UNALIGNED_ACCESS |
Pierre d'Herbemont | 7f3074d | 2003-07-15 20:46:40 +0000 | [diff] [blame] | 266 | #elif defined(__powerpc__) |
Alexandre Julliard | 9f0ff1b | 2002-05-29 02:02:19 +0000 | [diff] [blame] | 267 | # define WORDS_BIGENDIAN |
| 268 | # define BITFIELDS_BIGENDIAN |
| 269 | # undef ALLOW_UNALIGNED_ACCESS |
Steven Edwards | 31e4629 | 2002-12-10 19:04:45 +0000 | [diff] [blame] | 270 | #elif defined(__ALPHA__) |
Vincent Béron | e990342 | 2004-10-18 19:37:30 +0000 | [diff] [blame] | 271 | # undef WORDS_BIGENDIAN |
| 272 | # undef BITFIELDS_BIGENDIAN |
Steven Edwards | 31e4629 | 2002-12-10 19:04:45 +0000 | [diff] [blame] | 273 | # undef ALLOW_UNALIGNED_ACCESS |
André Hentschel | 14d5186 | 2009-09-22 16:31:17 +0200 | [diff] [blame] | 274 | #elif defined(__arm__) |
| 275 | # undef WORDS_BIGENDIAN |
| 276 | # undef BITFIELDS_BIGENDIAN |
| 277 | # undef ALLOW_UNALIGNED_ACCESS |
Jon Griffiths | 9770914 | 2008-06-28 04:25:54 -0700 | [diff] [blame] | 278 | #elif !defined(RC_INVOKED) && !defined(__WIDL__) && !defined(__midl) |
Alexandre Julliard | 9f0ff1b | 2002-05-29 02:02:19 +0000 | [diff] [blame] | 279 | # error Unknown CPU architecture! |
| 280 | #endif |
| 281 | |
Patrik Stridvall | 2d0bb2a | 1999-07-04 15:56:03 +0000 | [diff] [blame] | 282 | #ifdef __cplusplus |
| 283 | } /* extern "C" */ |
| 284 | #endif /* defined(__cplusplus) */ |
| 285 | |
| 286 | #endif /* !defined(__WINE_BASETSD_H) */ |