1// Licensed to the .NET Foundation under one or more agreements.
2// The .NET Foundation licenses this file to you under the MIT license.
3// See the LICENSE file in the project root for more information.
4
5/*++
6
7
8
9
10
11--*/
12
13////////////////////////////////////////////////////////////////////////
14// Extensions to the usual posix header files
15////////////////////////////////////////////////////////////////////////
16
17#ifndef __PAL_MSTYPES_H__
18#define __PAL_MSTYPES_H__
19
20#ifdef __cplusplus
21extern "C" {
22#endif
23
24////////////////////////////////////////////////////////////////////////
25// calling convention stuff
26////////////////////////////////////////////////////////////////////////
27
28
29#ifdef __cplusplus
30#define EXTERN_C extern "C"
31#else
32#define EXTERN_C
33#endif // __cplusplus
34
35#ifndef _MSC_VER
36
37// Note: Win32-hosted GCC predefines __stdcall and __cdecl, but Unix-
38// hosted GCC does not.
39
40#ifdef __i386__
41
42#if !defined(__stdcall)
43#define __stdcall __attribute__((stdcall))
44#endif
45#if !defined(_stdcall)
46#define _stdcall __stdcall
47#endif
48
49#if !defined(__cdecl)
50#define __cdecl __attribute__((cdecl))
51#endif
52#if !defined(_cdecl)
53#define _cdecl __cdecl
54#endif
55#if !defined(CDECL)
56#define CDECL __cdecl
57#endif
58
59
60#else // !defined(__i386__)
61
62#define __stdcall
63#define _stdcall
64#define __cdecl
65#define _cdecl
66#define CDECL
67
68// On ARM __fastcall is ignored and causes a compile error
69#if !defined(PAL_STDCPP_COMPAT) || defined(__arm__)
70# undef __fastcall
71# undef _fastcall
72# define __fastcall
73# define _fastcall
74#endif // !defined(PAL_STDCPP_COMPAT) || defined(__arm__)
75
76#endif // !defined(__i386__)
77
78#define CALLBACK __cdecl
79
80#if !defined(_declspec)
81#define _declspec(e) __declspec(e)
82#endif
83
84#if defined(_VAC_) && defined(__cplusplus)
85#define __inline inline
86#endif
87
88#define __forceinline inline
89
90#endif // !_MSC_VER
91
92#ifdef _MSC_VER
93
94#if defined(PAL_IMPLEMENTATION)
95#define PALIMPORT
96#else
97#define PALIMPORT __declspec(dllimport)
98#endif
99#define PAL_NORETURN __declspec(noreturn)
100
101#else
102
103#define PALIMPORT
104#define PAL_NORETURN __attribute__((noreturn))
105
106#endif
107
108#define PALAPI __cdecl
109#define PALAPIV __cdecl
110
111////////////////////////////////////////////////////////////////////////
112// Type attribute stuff
113////////////////////////////////////////////////////////////////////////
114
115#define CONST const
116#define IN
117#define OUT
118#define OPTIONAL
119#define FAR
120
121#ifdef UNICODE
122#define __TEXT(x) L##x
123#else
124#define __TEXT(x) x
125#endif
126#define TEXT(x) __TEXT(x)
127
128////////////////////////////////////////////////////////////////////////
129// Some special values
130////////////////////////////////////////////////////////////////////////
131
132#ifndef TRUE
133#define TRUE 1
134#endif
135
136#ifndef FALSE
137#define FALSE 0
138#endif
139
140////////////////////////////////////////////////////////////////////////
141// Misc. type helpers
142////////////////////////////////////////////////////////////////////////
143
144#ifdef _MSC_VER
145
146// MSVC's way of declaring large integer constants
147// If you define these in one step, without the _HELPER macros, you
148// get extra whitespace when composing these with other concatenating macros.
149#define I64_HELPER(x) x ## i64
150#define I64(x) I64_HELPER(x)
151
152#define UI64_HELPER(x) x ## ui64
153#define UI64(x) UI64_HELPER(x)
154
155#else // _MSC_VER
156
157// GCC's way of declaring large integer constants
158// If you define these in one step, without the _HELPER macros, you
159// get extra whitespace when composing these with other concatenating macros.
160#define I64_HELPER(x) x ## LL
161#define I64(x) I64_HELPER(x)
162
163#define UI64_HELPER(x) x ## ULL
164#define UI64(x) UI64_HELPER(x)
165
166#endif // _MSC_VER
167
168////////////////////////////////////////////////////////////////////////
169// Misc. types
170////////////////////////////////////////////////////////////////////////
171
172#ifndef _MSC_VER
173
174// A bunch of source files (e.g. most of the ndp tree) include pal.h
175// but are written to be LLP64, not LP64. (LP64 => long = 64 bits
176// LLP64 => longs = 32 bits, long long = 64 bits)
177//
178// To handle this difference, we #define long to be int (and thus 32 bits) when
179// compiling those files. (See the bottom of this file or search for
180// #define long to see where we do this.)
181//
182// But this fix is more complicated than it seems, because we also use the
183// preprocessor to #define __int64 to long for LP64 architectures (__int64
184// isn't a builtin in gcc). We don't want __int64 to be an int (by cascading
185// macro rules). So we play this little trick below where we add
186// __cppmungestrip before "long", which is what we're really #defining __int64
187// to. The preprocessor sees __cppmungestriplong as something different than
188// long, so it doesn't replace it with int. The during the cppmunge phase, we
189// remove the __cppmungestrip part, leaving long for the compiler to see.
190//
191// Note that we can't just use a typedef to define __int64 as long before
192// #defining long because typedefed types can't be signedness-agnostic (i.e.
193// they must be either signed or unsigned) and we want to be able to use
194// __int64 as though it were intrinsic
195
196#ifdef BIT64
197#define __int64 long
198#else // BIT64
199#define __int64 long long
200#endif // BIT64
201
202#define __int32 int
203#define __int16 short int
204#define __int8 char // assumes char is signed
205
206#endif // _MSC_VER
207
208#ifndef PAL_STDCPP_COMPAT
209// Defined in gnu's types.h. For non PAL_IMPLEMENTATION system
210// includes are not included, so we need to define them.
211#ifndef PAL_IMPLEMENTATION
212
213// OS X already defines these types in 64 bit
214#if !defined(_TARGET_MAC64)
215typedef __int64 int64_t;
216typedef unsigned __int64 uint64_t;
217typedef __int32 int32_t;
218typedef unsigned __int32 uint32_t;
219typedef __int16 int16_t;
220typedef unsigned __int16 uint16_t;
221typedef __int8 int8_t;
222typedef unsigned __int8 uint8_t;
223#endif
224
225#endif // PAL_IMPLEMENTATION
226
227#ifndef _MSC_VER
228
229#if _WIN64
230typedef long double LONG_DOUBLE;
231#endif
232
233#endif // _MSC_VER
234#endif // !PAL_STDCPP_COMPAT
235
236typedef void VOID;
237
238typedef int LONG; // NOTE: diff from windows.h, for LP64 compat
239typedef unsigned int ULONG; // NOTE: diff from windows.h, for LP64 compat
240
241typedef __int64 LONGLONG;
242typedef unsigned __int64 ULONGLONG;
243typedef ULONGLONG DWORD64;
244typedef DWORD64 *PDWORD64;
245typedef LONGLONG *PLONG64;
246typedef ULONGLONG *PULONG64;
247typedef ULONGLONG *PULONGLONG;
248typedef ULONG *PULONG;
249typedef short SHORT;
250typedef SHORT *PSHORT;
251typedef unsigned short USHORT;
252typedef USHORT *PUSHORT;
253typedef unsigned char UCHAR;
254typedef UCHAR *PUCHAR;
255typedef char *PSZ;
256typedef ULONGLONG DWORDLONG;
257
258typedef unsigned int DWORD; // NOTE: diff from windows.h, for LP64 compat
259typedef unsigned int DWORD32, *PDWORD32;
260
261typedef int BOOL;
262typedef unsigned char BYTE;
263typedef unsigned short WORD;
264typedef float FLOAT;
265typedef double DOUBLE;
266typedef BOOL *PBOOL;
267typedef BOOL *LPBOOL;
268typedef BYTE *PBYTE;
269typedef BYTE *LPBYTE;
270typedef const BYTE *LPCBYTE;
271typedef int *PINT;
272typedef int *LPINT;
273typedef WORD *PWORD;
274typedef WORD *LPWORD;
275typedef LONG *LPLONG;
276typedef LPLONG PLONG;
277typedef DWORD *PDWORD;
278typedef DWORD *LPDWORD;
279typedef void *PVOID;
280typedef void *LPVOID;
281typedef CONST void *LPCVOID;
282typedef int INT;
283typedef unsigned int UINT;
284typedef unsigned int *PUINT;
285typedef BYTE BOOLEAN;
286typedef BOOLEAN *PBOOLEAN;
287
288typedef unsigned __int8 UINT8;
289typedef signed __int8 INT8;
290typedef unsigned __int16 UINT16;
291typedef signed __int16 INT16;
292typedef unsigned __int32 UINT32, *PUINT32;
293typedef signed __int32 INT32, *PINT32;
294typedef unsigned __int64 UINT64, *PUINT64;
295typedef signed __int64 INT64, *PINT64;
296
297typedef unsigned __int32 ULONG32, *PULONG32;
298typedef signed __int32 LONG32, *PLONG32;
299typedef unsigned __int64 ULONG64;
300typedef signed __int64 LONG64;
301
302#if defined(_X86_) && _MSC_VER >= 1300
303#define _W64 __w64
304#else
305#define _W64
306#endif
307
308#ifdef BIT64
309
310#define _atoi64 (__int64)atoll
311
312typedef __int64 INT_PTR, *PINT_PTR;
313typedef unsigned __int64 UINT_PTR, *PUINT_PTR;
314typedef __int64 LONG_PTR, *PLONG_PTR;
315typedef unsigned __int64 ULONG_PTR, *PULONG_PTR;
316typedef unsigned __int64 DWORD_PTR, *PDWORD_PTR;
317
318/* maximum signed 64 bit value */
319#define LONG_PTR_MAX I64(9223372036854775807)
320/* maximum unsigned 64 bit value */
321#define ULONG_PTR_MAX UI64(0xffffffffffffffff)
322
323#ifndef SIZE_MAX
324#define SIZE_MAX _UI64_MAX
325#endif
326
327#define __int3264 __int64
328
329#if !defined(BIT64)
330__inline
331unsigned long
332HandleToULong(
333 const void *h
334 )
335{
336 return((unsigned long) (ULONG_PTR) h );
337}
338
339__inline
340long
341HandleToLong(
342 const void *h
343 )
344{
345 return((long) (LONG_PTR) h );
346}
347
348__inline
349void *
350ULongToHandle(
351 const unsigned long h
352 )
353{
354 return((void *) (UINT_PTR) h );
355}
356
357
358__inline
359void *
360LongToHandle(
361 const long h
362 )
363{
364 return((void *) (INT_PTR) h );
365}
366
367
368__inline
369unsigned long
370PtrToUlong(
371 const void *p
372 )
373{
374 return((unsigned long) (ULONG_PTR) p );
375}
376
377__inline
378unsigned int
379PtrToUint(
380 const void *p
381 )
382{
383 return((unsigned int) (UINT_PTR) p );
384}
385
386__inline
387unsigned short
388PtrToUshort(
389 const void *p
390 )
391{
392 return((unsigned short) (unsigned long) (ULONG_PTR) p );
393}
394
395__inline
396long
397PtrToLong(
398 const void *p
399 )
400{
401 return((long) (LONG_PTR) p );
402}
403
404__inline
405int
406PtrToInt(
407 const void *p
408 )
409{
410 return((int) (INT_PTR) p );
411}
412
413__inline
414short
415PtrToShort(
416 const void *p
417 )
418{
419 return((short) (long) (LONG_PTR) p );
420}
421
422__inline
423void *
424IntToPtr(
425 const int i
426 )
427// Caution: IntToPtr() sign-extends the int value.
428{
429 return( (void *)(INT_PTR)i );
430}
431
432__inline
433void *
434UIntToPtr(
435 const unsigned int ui
436 )
437// Caution: UIntToPtr() zero-extends the unsigned int value.
438{
439 return( (void *)(UINT_PTR)ui );
440}
441
442__inline
443void *
444LongToPtr(
445 const long l
446 )
447// Caution: LongToPtr() sign-extends the long value.
448{
449 return( (void *)(LONG_PTR)l );
450}
451
452__inline
453void *
454ULongToPtr(
455 const unsigned long ul
456 )
457// Caution: ULongToPtr() zero-extends the unsigned long value.
458{
459 return( (void *)(ULONG_PTR)ul );
460}
461
462__inline
463void *
464ShortToPtr(
465 const short s
466 )
467// Caution: ShortToPtr() sign-extends the short value.
468{
469 return( (void *)(INT_PTR)s );
470}
471
472__inline
473void *
474UShortToPtr(
475 const unsigned short us
476 )
477// Caution: UShortToPtr() zero-extends the unsigned short value.
478{
479 return( (void *)(UINT_PTR)us );
480}
481
482#else // !defined(BIT64)
483#define HandleToULong( h ) ((ULONG)(ULONG_PTR)(h) )
484#define HandleToLong( h ) ((LONG)(LONG_PTR) (h) )
485#define ULongToHandle( ul ) ((HANDLE)(ULONG_PTR) (ul) )
486#define LongToHandle( h ) ((HANDLE)(LONG_PTR) (h) )
487#define PtrToUlong( p ) ((ULONG)(ULONG_PTR) (p) )
488#define PtrToLong( p ) ((LONG)(LONG_PTR) (p) )
489#define PtrToUint( p ) ((UINT)(UINT_PTR) (p) )
490#define PtrToInt( p ) ((INT)(INT_PTR) (p) )
491#define PtrToUshort( p ) ((unsigned short)(ULONG_PTR)(p) )
492#define PtrToShort( p ) ((short)(LONG_PTR)(p) )
493#define IntToPtr( i ) ((VOID *)(INT_PTR)((int)(i)))
494#define UIntToPtr( ui ) ((VOID *)(UINT_PTR)((unsigned int)(ui)))
495#define LongToPtr( l ) ((VOID *)(LONG_PTR)((long)(l)))
496#define ULongToPtr( ul ) ((VOID *)(ULONG_PTR)((unsigned long)(ul)))
497#define ShortToPtr( s ) ((VOID *)(INT_PTR)((short)(s)))
498#define UShortToPtr( us ) ((VOID *)(UINT_PTR)((unsigned short)(s)))
499#endif // !defined(BIT64)
500
501
502
503#else
504
505typedef _W64 __int32 INT_PTR;
506typedef _W64 unsigned __int32 UINT_PTR;
507
508typedef _W64 __int32 LONG_PTR;
509typedef _W64 unsigned __int32 ULONG_PTR, *PULONG_PTR;
510typedef _W64 unsigned __int32 DWORD_PTR, *PDWORD_PTR;
511
512/* maximum signed 32 bit value */
513#define LONG_PTR_MAX 2147483647L
514/* maximum unsigned 32 bit value */
515#define ULONG_PTR_MAX 0xffffffffUL
516
517#ifndef SIZE_MAX
518#define SIZE_MAX UINT_MAX
519#endif
520
521#define __int3264 __int32
522
523#define HandleToULong( h ) ((ULONG)(ULONG_PTR)(h) )
524#define HandleToLong( h ) ((LONG)(LONG_PTR) (h) )
525#define ULongToHandle( ul ) ((HANDLE)(ULONG_PTR) (ul) )
526#define LongToHandle( h ) ((HANDLE)(LONG_PTR) (h) )
527#define PtrToUlong( p ) ((ULONG)(ULONG_PTR) (p) )
528#define PtrToLong( p ) ((LONG)(LONG_PTR) (p) )
529#define PtrToUint( p ) ((UINT)(UINT_PTR) (p) )
530#define PtrToInt( p ) ((INT)(INT_PTR) (p) )
531#define PtrToUshort( p ) ((unsigned short)(ULONG_PTR)(p) )
532#define PtrToShort( p ) ((short)(LONG_PTR)(p) )
533#define IntToPtr( i ) ((VOID *)(INT_PTR)((int)i))
534#define UIntToPtr( ui ) ((VOID *)(UINT_PTR)((unsigned int)ui))
535#define LongToPtr( l ) ((VOID *)(LONG_PTR)((long)l))
536#define ULongToPtr( ul ) ((VOID *)(ULONG_PTR)((unsigned long)ul))
537#define ShortToPtr( s ) ((VOID *)(INT_PTR)((short)s))
538#define UShortToPtr( us ) ((VOID *)(UINT_PTR)((unsigned short)s))
539
540#endif
541
542#define HandleToUlong(h) HandleToULong(h)
543#define UlongToHandle(ul) ULongToHandle(ul)
544#define UlongToPtr(ul) ULongToPtr(ul)
545#define UintToPtr(ui) UIntToPtr(ui)
546
547typedef ULONG_PTR SIZE_T, *PSIZE_T;
548typedef LONG_PTR SSIZE_T, *PSSIZE_T;
549
550#ifndef SIZE_T_MAX
551#define SIZE_T_MAX ULONG_PTR_MAX
552#endif // SIZE_T_MAX
553
554#ifndef SSIZE_T_MAX
555#define SSIZE_T_MAX LONG_PTR_MAX
556#endif
557
558#ifndef SSIZE_T_MIN
559#define SSIZE_T_MIN I64(0x8000000000000000)
560#endif
561
562#ifndef PAL_STDCPP_COMPAT
563#if defined(__APPLE_CC__) || defined(__linux__)
564#ifdef BIT64
565typedef unsigned long size_t;
566typedef long ptrdiff_t;
567#else // !BIT64
568typedef unsigned int size_t;
569typedef int ptrdiff_t;
570#endif // !BIT64
571#else
572typedef ULONG_PTR size_t;
573typedef LONG_PTR ptrdiff_t;
574#endif
575#endif // !PAL_STDCPP_COMPAT
576#define _SIZE_T_DEFINED
577
578typedef LONG_PTR LPARAM;
579
580#define _PTRDIFF_T_DEFINED
581#ifdef _MINGW_
582// We need to define _PTRDIFF_T to make sure ptrdiff_t doesn't get defined
583// again by system headers - but only for MinGW.
584#define _PTRDIFF_T
585#endif
586
587#ifdef PAL_STDCPP_COMPAT
588
589typedef char16_t WCHAR;
590
591#else // PAL_STDCPP_COMPAT
592
593typedef wchar_t WCHAR;
594#if defined(__linux__)
595#ifdef BIT64
596typedef long int intptr_t;
597typedef unsigned long int uintptr_t;
598#else // !BIT64
599typedef int intptr_t;
600typedef unsigned int uintptr_t;
601#endif // !BIT64
602#else
603typedef INT_PTR intptr_t;
604typedef UINT_PTR uintptr_t;
605#endif
606
607#endif // PAL_STDCPP_COMPAT
608
609#define _INTPTR_T_DEFINED
610#define _UINTPTR_T_DEFINED
611
612typedef DWORD LCID;
613typedef PDWORD PLCID;
614typedef WORD LANGID;
615
616typedef DWORD LCTYPE;
617
618typedef WCHAR *PWCHAR;
619typedef WCHAR *LPWCH, *PWCH;
620typedef CONST WCHAR *LPCWCH, *PCWCH;
621typedef WCHAR *NWPSTR;
622typedef WCHAR *LPWSTR, *PWSTR;
623
624typedef CONST WCHAR *LPCWSTR, *PCWSTR;
625
626typedef char CHAR;
627typedef CHAR *PCHAR;
628typedef CHAR *LPCH, *PCH;
629typedef CONST CHAR *LPCCH, *PCCH;
630typedef CHAR *NPSTR;
631typedef CHAR *LPSTR, *PSTR;
632typedef CONST CHAR *LPCSTR, *PCSTR;
633
634#ifdef UNICODE
635typedef WCHAR TCHAR;
636typedef WCHAR _TCHAR;
637#else
638typedef CHAR TCHAR;
639typedef CHAR _TCHAR;
640#endif
641typedef TCHAR *PTCHAR;
642typedef TCHAR *LPTSTR, *PTSTR;
643typedef CONST TCHAR *LPCTSTR;
644
645#define MAKEWORD(a, b) ((WORD)(((BYTE)((DWORD_PTR)(a) & 0xff)) | ((WORD)((BYTE)((DWORD_PTR)(b) & 0xff))) << 8))
646#define MAKELONG(a, b) ((LONG)(((WORD)((DWORD_PTR)(a) & 0xffff)) | ((DWORD)((WORD)((DWORD_PTR)(b) & 0xffff))) << 16))
647#define LOWORD(l) ((WORD)((DWORD_PTR)(l) & 0xffff))
648#define HIWORD(l) ((WORD)((DWORD_PTR)(l) >> 16))
649#define LOBYTE(w) ((BYTE)((DWORD_PTR)(w) & 0xff))
650#define HIBYTE(w) ((BYTE)((DWORD_PTR)(w) >> 8))
651
652typedef VOID *HANDLE;
653typedef HANDLE HWND;
654typedef struct __PAL_RemoteHandle__ { HANDLE h; } *RHANDLE;
655typedef HANDLE *PHANDLE;
656typedef HANDLE *LPHANDLE;
657#define INVALID_HANDLE_VALUE ((VOID *)(-1))
658#define INVALID_FILE_SIZE ((DWORD)0xFFFFFFFF)
659#define INVALID_FILE_ATTRIBUTES ((DWORD) -1)
660typedef HANDLE HMODULE;
661typedef HANDLE HINSTANCE;
662typedef HANDLE HGLOBAL;
663typedef HANDLE HLOCAL;
664typedef HANDLE HRSRC;
665
666typedef LONG HRESULT;
667typedef LONG NTSTATUS;
668
669typedef union _LARGE_INTEGER {
670 struct {
671#if BIGENDIAN
672 LONG HighPart;
673 DWORD LowPart;
674#else
675 DWORD LowPart;
676 LONG HighPart;
677#endif
678 } u;
679 LONGLONG QuadPart;
680} LARGE_INTEGER, *PLARGE_INTEGER;
681
682#ifndef GUID_DEFINED
683typedef struct _GUID {
684 ULONG Data1; // NOTE: diff from Win32, for LP64
685 USHORT Data2;
686 USHORT Data3;
687 UCHAR Data4[ 8 ];
688} GUID;
689typedef const GUID *LPCGUID;
690#define GUID_DEFINED
691#endif // !GUID_DEFINED
692
693typedef struct _FILETIME {
694 DWORD dwLowDateTime;
695 DWORD dwHighDateTime;
696} FILETIME, *PFILETIME, *LPFILETIME;
697
698/* Code Page Default Values */
699#define CP_ACP 0 /* default to ANSI code page */
700#define CP_OEMCP 1 /* default to OEM code page */
701#define CP_MACCP 2 /* default to MAC code page */
702#define CP_THREAD_ACP 3 /* current thread's ANSI code page */
703#define CP_WINUNICODE 1200
704#define CP_UNICODE 1200 /* Unicode */
705#define CP_UNICODESWAP 1201 /* Unicode Big-Endian */
706#define CP_UTF7 65000 /* UTF-7 translation */
707#define CP_UTF8 65001 /* UTF-8 translation */
708
709typedef PVOID PSID;
710
711#ifdef __cplusplus
712}
713#endif
714
715#endif // __PAL_MSTYPES_H__
716