Add a fourth parameter to the DEFINE_DACVAR macro that is the actual fully qualified...
[platform/upstream/coreclr.git] / src / pal / inc / pal.h
1 //
2 // Copyright (c) Microsoft. All rights reserved.
3 // Licensed under the MIT license. See LICENSE file in the project root for full license information. 
4 //
5
6 /*++
7
8
9
10  This file includes parts which are Copyright (c) 1982-1986 Regents
11  of the University of California.  All rights reserved.  The
12  Berkeley Software License Agreement specifies the terms and
13  conditions for redistribution.
14
15
16 Module Name:
17
18     pal.h
19
20 Abstract:
21
22     Rotor Platform Adaptation Layer (PAL) header file.  This file
23     defines all types and API calls required by the Rotor port of
24     the Microsoft Common Language Runtime.
25
26     Defines which control the behavior of this include file:
27       UNICODE - define it to set the Ansi/Unicode neutral names to
28                 be the ...W names.  Otherwise the neutral names default
29                 to be the ...A names.
30       PAL_IMPLEMENTATION - define it when implementing the PAL.  Otherwise
31                 leave it undefined when consuming the PAL.
32
33     Note:  some fields in structs have been renamed from the original
34     SDK documentation names, with _PAL_Undefined appended.  This leaves
35     the structure layout identical to its Win32 version, but prevents
36     PAL consumers from inadvertently referencing undefined fields.
37
38     If you want to add a PAL_ wrapper function to a native function in
39     here, you also need to edit palinternal.h and win32pal.h.
40     
41
42
43 --*/
44
45 #ifndef __PAL_H__
46 #define __PAL_H__
47
48 #ifdef  __cplusplus
49 extern "C" {
50 #endif
51
52 #if defined (PLATFORM_UNIX)
53 // This macro is used to standardize the wide character string literals between UNIX and Windows.
54 // Unix L"" is UTF32, and on windows it's UTF16.  Because of built-in assumptions on the size
55 // of string literals, it's important to match behaviour between Unix and Windows.  Unix will be defined
56 // as u"" (char16_t)
57 #define W(str)  u##str
58
59 // Undefine the QUOTE_MACRO_L helper and redefine it in terms of u.
60 // The reason that we do this is that quote macro is defined in ndp\common\inc,
61 // not inside of coreclr sources.
62
63 #define QUOTE_MACRO_L(x) QUOTE_MACRO_u(x)
64 #define QUOTE_MACRO_u_HELPER(x)     u###x
65 #define QUOTE_MACRO_u(x)            QUOTE_MACRO_u_HELPER(x)
66
67 #endif
68
69 #include <pal_char16.h>
70 #include <pal_error.h>
71 #include <pal_mstypes.h>
72
73 /******************* Processor-specific glue  *****************************/
74
75 #ifndef _MSC_VER
76
77 #if defined(__i686__) && !defined(_M_IX86)
78 #define _M_IX86 600
79 #elif defined(__i586__) && !defined(_M_IX86)
80 #define _M_IX86 500
81 #elif defined(__i486__) && !defined(_M_IX86)
82 #define _M_IX86 400
83 #elif defined(__i386__) && !defined(_M_IX86)
84 #define _M_IX86 300
85 #elif defined(__ppc__) && !defined(_M_PPC)
86 #define _M_PPC 100
87 #elif defined(_AIX) && defined(_POWER) && !defined(_M_PPC)
88 #define _M_PPC 100
89 #elif defined(__sparc__) && !defined(_M_SPARC)
90 #define _M_SPARC 100
91 #elif defined(__hppa__) && !defined(_M_PARISC)
92 #define _M_PARISC 100
93 #elif defined(__ia64__) && !defined(_M_IA64)
94 #define _M_IA64 64100
95 #elif defined(__x86_64__) && !defined(_M_AMD64)
96 #define _M_AMD64 100
97 #endif
98
99 #if defined(_M_IX86) && !defined(_X86_)
100 #define _X86_
101 #elif defined(_M_ALPHA) && !defined(_ALPHA_)
102 #define _ALPHA_
103 #elif defined(_M_PPC) && !defined(_PPC_)
104 #define _PPC_
105 #elif defined(_M_SPARC) && !defined(_SPARC_)
106 #define _SPARC_
107 #elif defined(_M_PARISC) && !defined(_PARISC_)
108 #define _PARISC_
109 #elif defined(_M_MRX000) && !defined(_MIPS_)
110 #define _MIPS_
111 #elif defined(_M_M68K) && !defined(_68K_)
112 #define _68K_
113 #elif defined(_M_IA64) && !defined(_IA64_)
114 #define _IA64_
115 #elif defined(_M_AMD64) && !defined(_AMD64_)
116 #define _AMD64_
117 #endif
118
119 #endif // !_MSC_VER
120
121 /******************* ABI-specific glue *******************************/
122
123 #if defined(_PPC_) || defined(_PPC64_) || defined(_SPARC_) || defined(_PARISC_) || defined(_IA64_)
124 #define BIGENDIAN 1
125 #endif
126
127 #ifdef __APPLE__
128 // Both PowerPC, i386 and x86_64 on Mac OS X use 16-byte alignment.
129 #define STACK_ALIGN_BITS             4
130 #define STACK_ALIGN_REQ             (1 << STACK_ALIGN_BITS)
131 #endif
132
133 #define MAX_PATH 260
134 #define _MAX_PATH   260 /* max. length of full pathname */
135 #define _MAX_DRIVE  3   /* max. length of drive component */
136 #define _MAX_DIR    256 /* max. length of path component */
137 #define _MAX_FNAME  256 /* max. length of file name component */
138 #define _MAX_EXT    256 /* max. length of extension component */
139
140 #define MAXSHORT      0x7fff
141 #define MAXLONG       0x7fffffff
142 #define MAXCHAR       0x7f
143 #define MAXDWORD      0xffffffff
144
145 //  Sorting IDs.
146 //
147 //  Note that the named locale APIs (eg CompareStringExEx) are recommended.
148 //
149
150 #define LANG_CHINESE                     0x04
151 #define LANG_ENGLISH                     0x09
152 #define LANG_JAPANESE                    0x11
153 #define LANG_KOREAN                      0x12
154 #define LANG_THAI                        0x1e
155
156 /******************* Compiler-specific glue *******************************/
157
158 #ifndef _MSC_VER
159 #if defined(CORECLR)
160 // Define this if the underlying platform supports true 2-pass EH.
161 // At the same time, this enables running several PAL instances
162 // side-by-side.
163 #define FEATURE_PAL_SXS 1
164 #endif // CORECLR
165 #endif // !_MSC_VER
166
167
168 #if defined(_MSC_VER) || defined(__llvm__)
169 #define DECLSPEC_ALIGN(x)   __declspec(align(x))
170 #else
171 #define DECLSPEC_ALIGN(x) 
172 #endif
173
174 #define DECLSPEC_NORETURN   PAL_NORETURN
175
176 #ifndef _MSC_VER
177 #define __assume(x) (void)0
178 #define __annotation(x)
179 #endif //!MSC_VER
180
181 #ifdef _MSC_VER
182
183 #if defined(_M_MRX000) || defined(_M_ALPHA) || defined(_M_PPC) || defined(_M_IA64)
184 #define UNALIGNED __unaligned
185 #else
186 #define UNALIGNED
187 #endif
188
189 #else // _MSC_VER
190
191 #define UNALIGNED
192
193 #endif // _MSC_VER
194
195 #ifdef _M_ALPHA
196
197 typedef struct {
198     char *a0;       /* pointer to first homed integer argument */
199     int offset;     /* byte offset of next parameter */
200 } va_list;
201
202 #define va_start(list, v) __builtin_va_start(list, v, 1)
203 #define va_end(list)
204
205 #elif __GNUC__
206
207 #if defined(_AIX)
208
209 typedef __builtin_va_list __gnuc_va_list;
210 typedef __builtin_va_list va_list;
211 #define va_start(v,l)   __builtin_va_start(v,l)
212 #define va_end          __builtin_va_end
213 #define va_arg          __builtin_va_arg
214
215 #else // _AIX
216
217 #if __GNUC__ == 2
218 typedef void * va_list;
219 #else
220 typedef __builtin_va_list va_list;
221 #endif  // __GNUC__
222
223 /* We should consider if the va_arg definition here is actually necessary.
224    Could we use the standard va_arg definition? */
225
226 #if __GNUC__ == 2
227 #if defined(_SPARC_) || defined(_PARISC_) // ToDo: is this the right thing for PARISC?
228 #define va_start(list, v) (__builtin_next_arg(v), list = (char *) __builtin_saveregs())
229 #define __va_rounded_size(TYPE)  \
230   (((sizeof (TYPE) + sizeof (int) - 1) / sizeof (int)) * sizeof (int))
231 #define __record_type_class 12
232 #define __real_type_class 8
233 #define va_arg(pvar,TYPE)                                       \
234 __extension__                                                   \
235 (*({((__builtin_classify_type (*(TYPE*) 0) >= __record_type_class \
236       || (__builtin_classify_type (*(TYPE*) 0) == __real_type_class \
237           && sizeof (TYPE) == 16))                              \
238     ? ((pvar) = (char *)(pvar) + __va_rounded_size (TYPE *),    \
239        *(TYPE **) (void *) ((char *)(pvar) - __va_rounded_size (TYPE *))) \
240     : __va_rounded_size (TYPE) == 8                             \
241     ? ({ union {char __d[sizeof (TYPE)]; int __i[2];} __u;      \
242          __u.__i[0] = ((int *) (void *) (pvar))[0];             \
243          __u.__i[1] = ((int *) (void *) (pvar))[1];             \
244          (pvar) = (char *)(pvar) + 8;                           \
245          (TYPE *) (void *) __u.__d; })                          \
246     : ((pvar) = (char *)(pvar) + __va_rounded_size (TYPE),      \
247        ((TYPE *) (void *) ((char *)(pvar) - __va_rounded_size (TYPE)))));}))
248 #else   // _SPARC_ or _PARISC_
249 // GCC 2.95.3 on non-SPARC
250 #define __va_size(type) (((sizeof(type) + sizeof(int) - 1) / sizeof(int)) * sizeof(int))
251 #define va_start(list, v) ((list) = (va_list) __builtin_next_arg(v))
252 #define va_arg(ap, type) (*(type *)((ap) += __va_size(type), (ap) - __va_size(type)))
253 #endif  // _SPARC_ or _PARISC_
254 #else // __GNUC__ == 2
255 #define va_start    __builtin_va_start
256 #define va_arg      __builtin_va_arg
257 #endif // __GNUC__ == 2
258
259 #define va_copy     __builtin_va_copy
260 #define va_end      __builtin_va_end
261
262 #endif // _AIX
263
264 #define VOID void
265
266 #define PUB __attribute__((visibility("default")))
267
268 #else // __GNUC__
269
270 typedef char * va_list;
271
272 #define _INTSIZEOF(n)   ( (sizeof(n) + sizeof(int) - 1) & ~(sizeof(int) - 1) )
273
274 #if _MSC_VER >= 1400
275
276 #ifdef  __cplusplus
277 #define _ADDRESSOF(v)   ( &reinterpret_cast<const char &>(v) )
278 #else
279 #define _ADDRESSOF(v)   ( &(v) )
280 #endif
281
282 #define _crt_va_start(ap,v)  ( ap = (va_list)_ADDRESSOF(v) + _INTSIZEOF(v) )
283 #define _crt_va_arg(ap,t)    ( *(t *)((ap += _INTSIZEOF(t)) - _INTSIZEOF(t)) )
284 #define _crt_va_end(ap)      ( ap = (va_list)0 )
285
286 #define va_start _crt_va_start
287 #define va_arg _crt_va_arg
288 #define va_end _crt_va_end
289
290 #else  // _MSC_VER
291
292 #define va_start(ap,v)    (ap = (va_list) (&(v)) + _INTSIZEOF(v))
293 #define va_arg(ap,t)    ( *(t *)((ap += _INTSIZEOF(t)) - _INTSIZEOF(t)) )
294 #define va_end(ap)
295
296 #endif // _MSC_VER
297
298 #define va_copy(dest,src) (dest = src)
299
300 #endif // __GNUC__
301
302 /******************* PAL-Specific Entrypoints *****************************/
303
304 #define IsDebuggerPresent PAL_IsDebuggerPresent
305
306 PALIMPORT
307 BOOL
308 PALAPI
309 PAL_IsDebuggerPresent();
310  
311 #define MAXIMUM_SUSPEND_COUNT  MAXCHAR
312
313 #define CHAR_BIT      8
314
315 #define SCHAR_MIN   (-128)
316 #define SCHAR_MAX     127
317 #define UCHAR_MAX     0xff
318
319 #define SHRT_MIN    (-32768)
320 #define SHRT_MAX      32767
321 #define USHRT_MAX     0xffff
322
323 #define INT_MIN     (-2147483647 - 1)
324 #define INT_MAX       2147483647
325 #define UINT_MAX      0xffffffff
326
327 #define LONG_MIN    (-2147483647L - 1)
328 #define LONG_MAX      2147483647L
329 #define ULONG_MAX     0xffffffffUL
330
331 #define FLT_MAX 3.402823466e+38F
332 #define DBL_MAX 1.7976931348623157e+308
333
334 /* minimum signed 64 bit value */
335 #define _I64_MIN    (I64(-9223372036854775807) - 1)
336 /* maximum signed 64 bit value */
337 #define _I64_MAX      I64(9223372036854775807)
338 /* maximum unsigned 64 bit value */
339 #define _UI64_MAX     UI64(0xffffffffffffffff)
340
341 #define _I8_MAX   SCHAR_MAX
342 #define _I8_MIN   SCHAR_MIN
343 #define _I16_MAX  SHRT_MAX
344 #define _I16_MIN  SHRT_MIN
345 #define _I32_MAX  INT_MAX
346 #define _I32_MIN  INT_MIN
347 #define _UI8_MAX  UCHAR_MAX
348 #define _UI8_MIN  UCHAR_MIN
349 #define _UI16_MAX USHRT_MAX
350 #define _UI16_MIN USHRT_MIN
351 #define _UI32_MAX UINT_MAX
352 #define _UI32_MIN UINT_MIN
353
354 #ifndef NULL
355 #if defined(__cplusplus)
356 #define NULL    0
357 #else
358 #define NULL    ((void *)0)
359 #endif
360 #endif
361
362 typedef ULONG64   fpos_t;
363
364 #if _WIN64 || _MSC_VER >= 1400
365 typedef __int64 time_t;
366 #else
367 typedef long time_t;
368 #endif
369 #define _TIME_T_DEFINED
370
371 #if ENABLE_DOWNLEVEL_FOR_NLS
372 #define MAKELCID(lgid, srtid)  ((DWORD)((((DWORD)((WORD  )(srtid))) << 16) |  \
373                                          ((DWORD)((WORD  )(lgid)))))
374 #define LANGIDFROMLCID(lcid)   ((WORD)(lcid))
375 #define SORTIDFROMLCID(lcid)   ((WORD)((((DWORD)(lcid)) >> 16) & 0xf))
376
377 #define LANG_NEUTRAL                     0x00
378 #define LANG_INVARIANT                   0x7f
379 #define SUBLANG_NEUTRAL                  0x00    // language neutral
380 #define SUBLANG_DEFAULT                  0x01    // user default
381 #define SORT_DEFAULT                     0x0     // sorting default
382
383 #define MAKELANGID(p, s)       ((((WORD  )(s)) << 10) | (WORD  )(p))
384 #define PRIMARYLANGID(lgid)    ((WORD  )(lgid) & 0x3ff)
385 #define SUBLANGID(lgid)        ((WORD  )(lgid) >> 10)
386
387 #define LANG_USER_DEFAULT      (MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT))
388 #define LOCALE_USER_DEFAULT    (MAKELCID(LANG_USER_DEFAULT, SORT_DEFAULT))
389 #define LOCALE_NEUTRAL         (MAKELCID(MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), SORT_DEFAULT))
390 #define LOCALE_US_ENGLISH      (MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT))
391 #define LOCALE_INVARIANT       (MAKELCID(MAKELANGID(LANG_INVARIANT, SUBLANG_NEUTRAL), SORT_DEFAULT))
392
393 #define SUBLANG_ENGLISH_US               0x01
394 #define SUBLANG_CHINESE_TRADITIONAL      0x01    /* Chinese (Traditional) */
395
396 #endif // ENABLE_DOWNLEVEL_FOR_NLS
397
398
399 #define CT_CTYPE1                 0x00000001  /* ctype 1 information */
400 #define CT_CTYPE2                 0x00000002  /* ctype 2 information */
401 #define CT_CTYPE3                 0x00000004  /* ctype 3 information */
402 #define C1_UPPER                  0x0001      /* upper case */
403 #define C1_LOWER                  0x0002      /* lower case */
404 #define C1_DIGIT                  0x0004      /* decimal digits */
405 #define C1_SPACE                  0x0008      /* spacing characters */
406 #define C1_PUNCT                  0x0010      /* punctuation characters */
407 #define C1_CNTRL                  0x0020      /* control characters */
408 #define C1_BLANK                  0x0040      /* blank characters */
409 #define C1_XDIGIT                 0x0080      /* other digits */
410 #define C1_ALPHA                  0x0100      /* any linguistic character */
411 #define C2_LEFTTORIGHT            0x0001      /* left to right */
412 #define C2_RIGHTTOLEFT            0x0002      /* right to left */
413 #define C2_EUROPENUMBER           0x0003      /* European number, digit */
414 #define C2_EUROPESEPARATOR        0x0004      /* European numeric separator */
415 #define C2_EUROPETERMINATOR       0x0005      /* European numeric terminator */
416 #define C2_ARABICNUMBER           0x0006      /* Arabic number */
417 #define C2_COMMONSEPARATOR        0x0007      /* common numeric separator */
418 #define C2_BLOCKSEPARATOR         0x0008      /* block separator */
419 #define C2_SEGMENTSEPARATOR       0x0009      /* segment separator */
420 #define C2_WHITESPACE             0x000A      /* white space */
421 #define C2_OTHERNEUTRAL           0x000B      /* other neutrals */
422 #define C2_NOTAPPLICABLE          0x0000      /* no implicit directionality */
423 #define C3_NONSPACING             0x0001      /* nonspacing character */
424 #define C3_DIACRITIC              0x0002      /* diacritic mark */
425 #define C3_VOWELMARK              0x0004      /* vowel mark */
426 #define C3_SYMBOL                 0x0008      /* symbols */
427 #define C3_KATAKANA               0x0010      /* katakana character */
428 #define C3_HIRAGANA               0x0020      /* hiragana character */
429 #define C3_HALFWIDTH              0x0040      /* half width character */
430 #define C3_FULLWIDTH              0x0080      /* full width character */
431 #define C3_IDEOGRAPH              0x0100      /* ideographic character */
432 #define C3_KASHIDA                0x0200      /* Arabic kashida character */
433 #define C3_LEXICAL                0x0400      /* lexical character */
434 #define C3_ALPHA                  0x8000      /* any ling. char (C1_ALPHA) */
435 #define C3_NOTAPPLICABLE          0x0000      /* ctype 3 is not applicable */
436
437 #define DLL_PROCESS_ATTACH 1
438 #define DLL_THREAD_ATTACH  2
439 #define DLL_THREAD_DETACH  3
440 #define DLL_PROCESS_DETACH 0
441
442 typedef DWORD (PALAPI *PTHREAD_START_ROUTINE)(LPVOID lpThreadParameter);
443 typedef PTHREAD_START_ROUTINE LPTHREAD_START_ROUTINE;
444
445 /******************* PAL-Specific Entrypoints *****************************/
446
447 PALIMPORT
448 int
449 PALAPI
450 PAL_Initialize(
451             int argc,
452             const char * const argv[]);
453
454 PALIMPORT
455 DWORD
456 PALAPI
457 PAL_InitializeCoreCLR(
458             const char *szExePath,
459             const char *szCoreCLRPath,
460             BOOL fStayInPAL);
461
462 PALIMPORT
463 DWORD_PTR
464 PALAPI
465 PAL_EntryPoint(
466     IN LPTHREAD_START_ROUTINE lpStartAddress,
467     IN LPVOID lpParameter);
468
469 /// <summary>
470 /// This function shuts down PAL and exits the current process.
471 /// </summary>
472 PALIMPORT
473 void
474 PALAPI
475 PAL_Terminate(
476           void);
477
478 /// <summary>
479 /// This function shuts down PAL and exits the current process with
480 /// the specified exit code.
481 /// </summary>
482 PALIMPORT
483 void
484 PALAPI
485 PAL_TerminateEx(int exitCode);
486
487 PALIMPORT
488 void
489 PALAPI
490 PAL_InitializeDebug(
491           void);
492
493 PALIMPORT
494 HMODULE
495 PALAPI
496 PAL_RegisterLibraryW(
497          IN LPCWSTR lpLibFileName);
498
499 PALIMPORT
500 BOOL
501 PALAPI
502 PAL_UnregisterLibraryW(
503          IN HMODULE hLibModule);
504
505 #ifdef UNICODE
506 #define PAL_RegisterLibrary PAL_RegisterLibraryW
507 #define PAL_UnregisterLibrary PAL_UnregisterLibraryW
508 #endif
509
510 PALIMPORT
511 BOOL
512 PALAPI
513 PAL_GetPALDirectoryW(
514              OUT LPWSTR lpDirectoryName,
515              IN UINT cchDirectoryName);
516
517 PALIMPORT
518 BOOL
519 PALAPI
520 PAL_GetPALDirectoryA(
521              OUT LPSTR lpDirectoryName,
522              IN UINT cchDirectoryName);
523
524 #ifdef UNICODE
525 #define PAL_GetPALDirectory PAL_GetPALDirectoryW
526 #else
527 #define PAL_GetPALDirectory PAL_GetPALDirectoryA
528 #endif
529
530 PALIMPORT
531 BOOL
532 PALAPI
533 PAL_Random(
534         IN BOOL bStrong,
535         IN OUT LPVOID lpBuffer,
536         IN DWORD dwLength);
537
538 // This helper will be used *only* by the CoreCLR to determine
539 // if an address lies inside CoreCLR or not.
540 //
541 // This shouldnt be used by any other component that links into the PAL.
542 PALIMPORT 
543 BOOL
544 PALAPI
545 PAL_IsIPInCoreCLR(IN PVOID address);
546
547 #ifdef PLATFORM_UNIX
548
549 PALIMPORT
550 DWORD
551 PALAPI
552 PAL_CreateExecWatchpoint(
553     HANDLE hThread,
554     PVOID pvInstruction
555     );
556
557 PALIMPORT
558 DWORD
559 PALAPI
560 PAL_DeleteExecWatchpoint(
561     HANDLE hThread,
562     PVOID pvInstruction
563     );
564
565 #endif
566
567
568 PALIMPORT
569 DWORD
570 PALAPI
571 PAL_PublishDacTableAddress(
572     IN PVOID address,
573     IN ULONG size
574     );
575
576 PALIMPORT
577 DWORD
578 PALAPI
579 PAL_GetDacTableAddress(
580     IN DWORD pid,
581     OUT PVOID *pAddress,
582     OUT PULONG pSize
583     );
584
585 PALIMPORT
586 VOID
587 PALAPI
588 PAL_CleanupDacTableAddress(
589     );
590
591
592 PALIMPORT
593 BOOL
594 PALAPI
595 PAL_RegisterMacEHPort();
596
597
598 /******************* winuser.h Entrypoints *******************************/
599
600 PALIMPORT
601 LPSTR
602 PALAPI
603 CharNextA(
604             IN LPCSTR lpsz);
605
606 PALIMPORT
607 LPSTR
608 PALAPI
609 CharNextExA(
610         IN WORD CodePage,
611         IN LPCSTR lpCurrentChar,
612         IN DWORD dwFlags);
613
614 #ifndef UNICODE
615 #define CharNext CharNextA
616 #define CharNextEx CharNextExA
617 #endif
618
619
620 PALIMPORT
621 int
622 PALAPIV
623 wsprintfA(
624       OUT LPSTR,
625       IN LPCSTR,
626       ...);
627
628 PALIMPORT
629 int
630 PALAPIV
631 wsprintfW(
632       OUT LPWSTR,
633       IN LPCWSTR,
634       ...);
635
636 #ifdef UNICODE
637 #define wsprintf wsprintfW
638 #else
639 #define wsprintf wsprintfA
640 #endif
641
642 #define MB_OK                   0x00000000L
643 #define MB_OKCANCEL             0x00000001L
644 #define MB_ABORTRETRYIGNORE     0x00000002L
645 #define MB_YESNO                0x00000004L
646 #define MB_RETRYCANCEL          0x00000005L
647
648 #define MB_ICONHAND             0x00000010L
649 #define MB_ICONQUESTION         0x00000020L
650 #define MB_ICONEXCLAMATION      0x00000030L
651 #define MB_ICONASTERISK         0x00000040L
652
653 #define MB_ICONINFORMATION      MB_ICONASTERISK
654 #define MB_ICONSTOP             MB_ICONHAND
655 #define MB_ICONERROR            MB_ICONHAND
656
657 #define MB_DEFBUTTON1           0x00000000L
658 #define MB_DEFBUTTON2           0x00000100L
659 #define MB_DEFBUTTON3           0x00000200L
660
661 #define MB_SYSTEMMODAL          0x00001000L
662 #define MB_TASKMODAL            0x00002000L
663 #define MB_SETFOREGROUND        0x00010000L
664 #define MB_TOPMOST              0x00040000L
665
666 #define MB_NOFOCUS                  0x00008000L
667 #define MB_SETFOREGROUND            0x00010000L
668 #define MB_DEFAULT_DESKTOP_ONLY     0x00020000L
669
670 // Note: this is the NT 4.0 and greater value.
671 #define MB_SERVICE_NOTIFICATION 0x00200000L
672
673 #define MB_TYPEMASK             0x0000000FL
674 #define MB_ICONMASK             0x000000F0L
675 #define MB_DEFMASK              0x00000F00L
676
677 #define IDOK                    1
678 #define IDCANCEL                2
679 #define IDABORT                 3
680 #define IDRETRY                 4
681 #define IDIGNORE                5
682 #define IDYES                   6
683 #define IDNO                    7
684
685 PALIMPORT
686 int
687 PALAPI
688 MessageBoxW(
689         IN LPVOID hWnd,  // NOTE: diff from winuser.h
690         IN LPCWSTR lpText,
691         IN LPCWSTR lpCaption,
692         IN UINT uType);
693
694 #ifdef UNICODE
695 #define MessageBox MessageBoxW
696 #endif
697
698 /***************** wincon.h Entrypoints **********************************/
699
700 #define CTRL_C_EVENT        0
701 #define CTRL_BREAK_EVENT    1
702 #define CTRL_CLOSE_EVENT    2
703 // 3 is reserved!
704 // 4 is reserved!
705 #define CTRL_LOGOFF_EVENT   5
706 #define CTRL_SHUTDOWN_EVENT 6
707
708 typedef
709 BOOL
710 (PALAPI *PHANDLER_ROUTINE)(
711     DWORD CtrlType
712     );
713
714 PALIMPORT
715 BOOL
716 PALAPI
717 SetConsoleCtrlHandler(
718               IN PHANDLER_ROUTINE HandlerRoutine,
719               IN BOOL Add);
720
721 #ifndef CORECLR
722 PALIMPORT
723 BOOL
724 PALAPI
725 GenerateConsoleCtrlEvent(
726     IN DWORD dwCtrlEvent,
727     IN DWORD dwProcessGroupId
728     );
729 #endif // !CORECLR
730
731 //end wincon.h Entrypoints
732
733 // From win32.h
734 #ifndef _CRTIMP
735 #define _CRTIMP __declspec(dllimport)
736 #endif
737
738 /******************* winbase.h Entrypoints and defines ************************/
739 PALIMPORT
740 BOOL
741 PALAPI
742 AreFileApisANSI(
743         VOID);
744
745 typedef struct _SECURITY_ATTRIBUTES {
746             DWORD nLength;
747             LPVOID lpSecurityDescriptor;
748             BOOL bInheritHandle;
749 } SECURITY_ATTRIBUTES, *PSECURITY_ATTRIBUTES, *LPSECURITY_ATTRIBUTES;
750
751 #define _SH_DENYWR      0x20    /* deny write mode */
752
753 #define FILE_READ_DATA            ( 0x0001 )    // file & pipe
754 #define FILE_APPEND_DATA          ( 0x0004 )    // file
755
756 #define GENERIC_READ               (0x80000000L)
757 #define GENERIC_WRITE              (0x40000000L)
758
759 #define FILE_SHARE_READ            0x00000001
760 #define FILE_SHARE_WRITE           0x00000002
761 #define FILE_SHARE_DELETE          0x00000004
762
763 #define CREATE_NEW                 1
764 #define CREATE_ALWAYS              2
765 #define OPEN_EXISTING              3
766 #define OPEN_ALWAYS                4
767 #define TRUNCATE_EXISTING          5
768
769 #define FILE_ATTRIBUTE_READONLY                 0x00000001
770 #define FILE_ATTRIBUTE_HIDDEN                   0x00000002
771 #define FILE_ATTRIBUTE_SYSTEM                   0x00000004
772 #define FILE_ATTRIBUTE_DIRECTORY                0x00000010
773 #define FILE_ATTRIBUTE_ARCHIVE                  0x00000020
774 #define FILE_ATTRIBUTE_NORMAL                   0x00000080
775
776 #define FILE_FLAG_WRITE_THROUGH    0x80000000
777 #define FILE_FLAG_NO_BUFFERING     0x20000000
778 #define FILE_FLAG_RANDOM_ACCESS    0x10000000
779 #define FILE_FLAG_SEQUENTIAL_SCAN  0x08000000
780 #define FILE_FLAG_BACKUP_SEMANTICS 0x02000000
781
782 #define FILE_BEGIN                 0
783 #define FILE_CURRENT               1
784 #define FILE_END                   2
785
786 #define STILL_ACTIVE (0x00000103L)
787
788 #define INVALID_SET_FILE_POINTER   ((DWORD)-1)
789
790 PALIMPORT
791 HANDLE
792 PALAPI
793 CreateFileA(
794         IN LPCSTR lpFileName,
795         IN DWORD dwDesiredAccess,
796         IN DWORD dwShareMode,
797         IN LPSECURITY_ATTRIBUTES lpSecurityAttributes,
798         IN DWORD dwCreationDisposition,
799         IN DWORD dwFlagsAndAttributes,
800         IN HANDLE hTemplateFile);
801
802 PALIMPORT
803 HANDLE
804 PALAPI
805 CreateFileW(
806         IN LPCWSTR lpFileName,
807         IN DWORD dwDesiredAccess,
808         IN DWORD dwShareMode,
809         IN LPSECURITY_ATTRIBUTES lpSecurityAttributes,
810         IN DWORD dwCreationDisposition,
811         IN DWORD dwFlagsAndAttributes,
812         IN HANDLE hTemplateFile);
813
814 #ifdef UNICODE
815 #define CreateFile CreateFileW
816 #else
817 #define CreateFile CreateFileA
818 #endif
819
820 PALIMPORT
821 BOOL
822 PALAPI
823 LockFile(
824     IN HANDLE hFile,
825     IN DWORD dwFileOffsetLow,
826     IN DWORD dwFileOffsetHigh,
827     IN DWORD nNumberOfBytesToLockLow,
828     IN DWORD nNumberOfBytesToLockHigh
829     );
830
831 PALIMPORT
832 BOOL
833 PALAPI
834 UnlockFile(
835     IN HANDLE hFile,
836     IN DWORD dwFileOffsetLow,
837     IN DWORD dwFileOffsetHigh,
838     IN DWORD nNumberOfBytesToUnlockLow,
839     IN DWORD nNumberOfBytesToUnlockHigh
840     );
841
842 PALIMPORT
843 DWORD
844 PALAPI
845 SearchPathA(
846     IN LPCSTR lpPath,
847     IN LPCSTR lpFileName,
848     IN LPCSTR lpExtension,
849     IN DWORD nBufferLength,
850     OUT LPSTR lpBuffer,
851     OUT LPSTR *lpFilePart
852     );
853
854 PALIMPORT
855 DWORD
856 PALAPI
857 SearchPathW(
858     IN LPCWSTR lpPath,
859     IN LPCWSTR lpFileName,
860     IN LPCWSTR lpExtension,
861     IN DWORD nBufferLength,
862     OUT LPWSTR lpBuffer,
863     OUT LPWSTR *lpFilePart
864     );
865 #ifdef UNICODE
866 #define SearchPath  SearchPathW
867 #else
868 #define SearchPath  SearchPathA
869 #endif // !UNICODE
870
871
872 PALIMPORT
873 BOOL
874 PALAPI
875 CopyFileA(
876       IN LPCSTR lpExistingFileName,
877       IN LPCSTR lpNewFileName,
878       IN BOOL bFailIfExists);
879
880 PALIMPORT
881 BOOL
882 PALAPI
883 CopyFileW(
884       IN LPCWSTR lpExistingFileName,
885       IN LPCWSTR lpNewFileName,
886       IN BOOL bFailIfExists);
887
888 #ifdef UNICODE
889 #define CopyFile CopyFileW
890 #else
891 #define CopyFile CopyFileA
892 #endif
893
894 PALIMPORT
895 BOOL
896 PALAPI
897 DeleteFileA(
898         IN LPCSTR lpFileName);
899
900 PALIMPORT
901 BOOL
902 PALAPI
903 DeleteFileW(
904         IN LPCWSTR lpFileName);
905
906 #ifdef UNICODE
907 #define DeleteFile DeleteFileW
908 #else
909 #define DeleteFile DeleteFileA
910 #endif
911
912
913 PALIMPORT
914 BOOL
915 PALAPI
916 MoveFileA(
917      IN LPCSTR lpExistingFileName,
918      IN LPCSTR lpNewFileName);
919
920 PALIMPORT
921 BOOL
922 PALAPI
923 MoveFileW(
924      IN LPCWSTR lpExistingFileName,
925      IN LPCWSTR lpNewFileName);
926
927 #ifdef UNICODE
928 #define MoveFile MoveFileW
929 #else
930 #define MoveFile MoveFileA
931 #endif
932
933 #define MOVEFILE_REPLACE_EXISTING      0x00000001
934 #define MOVEFILE_COPY_ALLOWED          0x00000002
935
936 PALIMPORT
937 BOOL
938 PALAPI
939 MoveFileExA(
940         IN LPCSTR lpExistingFileName,
941         IN LPCSTR lpNewFileName,
942         IN DWORD dwFlags);
943
944 PALIMPORT
945 BOOL
946 PALAPI
947 MoveFileExW(
948         IN LPCWSTR lpExistingFileName,
949         IN LPCWSTR lpNewFileName,
950         IN DWORD dwFlags);
951
952 #ifdef UNICODE
953 #define MoveFileEx MoveFileExW
954 #else
955 #define MoveFileEx MoveFileExA
956 #endif
957
958 PALIMPORT
959 BOOL
960 PALAPI
961 CreateDirectoryA(
962          IN LPCSTR lpPathName,
963          IN LPSECURITY_ATTRIBUTES lpSecurityAttributes);
964
965 PALIMPORT
966 BOOL
967 PALAPI
968 CreateDirectoryW(
969          IN LPCWSTR lpPathName,
970          IN LPSECURITY_ATTRIBUTES lpSecurityAttributes);
971
972 #ifdef UNICODE
973 #define CreateDirectory CreateDirectoryW
974 #else
975 #define CreateDirectory CreateDirectoryA
976 #endif
977
978 PALIMPORT
979 BOOL
980 PALAPI
981 RemoveDirectoryW(
982          IN LPCWSTR lpPathName);
983
984 PALIMPORT
985 BOOL
986 PALAPI
987 RemoveDirectoryA(
988          IN LPCSTR lpPathName);
989
990 #ifdef UNICODE
991 #define RemoveDirectory RemoveDirectoryW
992 #else
993 #define RemoveDirectory RemoveDirectoryA
994 #endif
995
996 typedef struct _BY_HANDLE_FILE_INFORMATION {  
997     DWORD dwFileAttributes;
998     FILETIME ftCreationTime;
999     FILETIME ftLastAccessTime;
1000     FILETIME ftLastWriteTime;
1001     DWORD dwVolumeSerialNumber;
1002     DWORD nFileSizeHigh;
1003     DWORD nFileSizeLow;
1004     DWORD nNumberOfLinks;
1005     DWORD nFileIndexHigh;
1006     DWORD nFileIndexLow;
1007 } BY_HANDLE_FILE_INFORMATION, *PBY_HANDLE_FILE_INFORMATION, *LPBY_HANDLE_FILE_INFORMATION;
1008
1009 typedef struct _WIN32_FIND_DATAA {
1010     DWORD dwFileAttributes;
1011     FILETIME ftCreationTime;
1012     FILETIME ftLastAccessTime;
1013     FILETIME ftLastWriteTime;
1014     DWORD nFileSizeHigh;
1015     DWORD nFileSizeLow;
1016     DWORD dwReserved0;
1017     DWORD dwReserved1;
1018     CHAR cFileName[ MAX_PATH ];
1019     CHAR cAlternateFileName[ 14 ];
1020 } WIN32_FIND_DATAA, *PWIN32_FIND_DATAA, *LPWIN32_FIND_DATAA;
1021
1022 typedef struct _WIN32_FIND_DATAW {
1023     DWORD dwFileAttributes;
1024     FILETIME ftCreationTime;
1025     FILETIME ftLastAccessTime;
1026     FILETIME ftLastWriteTime;
1027     DWORD nFileSizeHigh;
1028     DWORD nFileSizeLow;
1029     DWORD dwReserved0;
1030     DWORD dwReserved1;
1031     WCHAR cFileName[ MAX_PATH ];
1032     WCHAR cAlternateFileName[ 14 ];
1033 } WIN32_FIND_DATAW, *PWIN32_FIND_DATAW, *LPWIN32_FIND_DATAW;
1034
1035 #ifdef UNICODE
1036 typedef WIN32_FIND_DATAW WIN32_FIND_DATA;
1037 typedef PWIN32_FIND_DATAW PWIN32_FIND_DATA;
1038 typedef LPWIN32_FIND_DATAW LPWIN32_FIND_DATA;
1039 #else
1040 typedef WIN32_FIND_DATAA WIN32_FIND_DATA;
1041 typedef PWIN32_FIND_DATAA PWIN32_FIND_DATA;
1042 typedef LPWIN32_FIND_DATAA LPWIN32_FIND_DATA;
1043 #endif
1044
1045 PALIMPORT
1046 HANDLE
1047 PALAPI
1048 FindFirstFileA(
1049            IN LPCSTR lpFileName,
1050            OUT LPWIN32_FIND_DATAA lpFindFileData);
1051
1052 PALIMPORT
1053 HANDLE
1054 PALAPI
1055 FindFirstFileW(
1056            IN LPCWSTR lpFileName,
1057            OUT LPWIN32_FIND_DATAW lpFindFileData);
1058
1059 #ifdef UNICODE
1060 #define FindFirstFile FindFirstFileW
1061 #else
1062 #define FindFirstFile FindFirstFileA
1063 #endif
1064
1065 PALIMPORT
1066 BOOL
1067 PALAPI
1068 FindNextFileA(
1069           IN HANDLE hFindFile,
1070           OUT LPWIN32_FIND_DATAA lpFindFileData);
1071
1072 PALIMPORT
1073 BOOL
1074 PALAPI
1075 FindNextFileW(
1076           IN HANDLE hFindFile,
1077           OUT LPWIN32_FIND_DATAW lpFindFileData);
1078
1079 #ifdef UNICODE
1080 #define FindNextFile FindNextFileW
1081 #else
1082 #define FindNextFile FindNextFileA
1083 #endif
1084
1085 PALIMPORT
1086 BOOL
1087 PALAPI
1088 FindClose(
1089       IN OUT HANDLE hFindFile);
1090
1091 PALIMPORT
1092 DWORD
1093 PALAPI
1094 GetFileAttributesA(
1095            IN LPCSTR lpFileName);
1096
1097 PALIMPORT
1098 DWORD
1099 PALAPI
1100 GetFileAttributesW(
1101            IN LPCWSTR lpFileName);
1102
1103 #ifdef UNICODE
1104 #define GetFileAttributes GetFileAttributesW
1105 #else
1106 #define GetFileAttributes GetFileAttributesA
1107 #endif
1108
1109 typedef enum _GET_FILEEX_INFO_LEVELS {
1110   GetFileExInfoStandard
1111 } GET_FILEEX_INFO_LEVELS;
1112
1113 typedef struct _WIN32_FILE_ATTRIBUTE_DATA {
1114     DWORD      dwFileAttributes;
1115     FILETIME   ftCreationTime;
1116     FILETIME   ftLastAccessTime;
1117     FILETIME   ftLastWriteTime;
1118     DWORD      nFileSizeHigh;
1119     DWORD      nFileSizeLow;
1120 } WIN32_FILE_ATTRIBUTE_DATA, *LPWIN32_FILE_ATTRIBUTE_DATA;
1121
1122 PALIMPORT
1123 BOOL
1124 PALAPI
1125 GetFileAttributesExW(
1126              IN LPCWSTR lpFileName,
1127              IN GET_FILEEX_INFO_LEVELS fInfoLevelId,
1128              OUT LPVOID lpFileInformation);
1129
1130 #ifdef UNICODE
1131 #define GetFileAttributesEx GetFileAttributesExW
1132 #endif
1133
1134 PALIMPORT
1135 BOOL
1136 PALAPI
1137 SetFileAttributesA(
1138            IN LPCSTR lpFileName,
1139            IN DWORD dwFileAttributes);
1140
1141 PALIMPORT
1142 BOOL
1143 PALAPI
1144 SetFileAttributesW(
1145            IN LPCWSTR lpFileName,
1146            IN DWORD dwFileAttributes);
1147
1148 #ifdef UNICODE
1149 #define SetFileAttributes SetFileAttributesW
1150 #else
1151 #define SetFileAttributes SetFileAttributesA
1152 #endif
1153
1154 typedef LPVOID LPOVERLAPPED;  // diff from winbase.h
1155
1156 PALIMPORT
1157 BOOL
1158 PALAPI
1159 WriteFile(
1160       IN HANDLE hFile,
1161       IN LPCVOID lpBuffer,
1162       IN DWORD nNumberOfBytesToWrite,
1163       OUT LPDWORD lpNumberOfBytesWritten,
1164       IN LPOVERLAPPED lpOverlapped);
1165
1166 PALIMPORT
1167 BOOL
1168 PALAPI
1169 ReadFile(
1170      IN HANDLE hFile,
1171      OUT LPVOID lpBuffer,
1172      IN DWORD nNumberOfBytesToRead,
1173      OUT LPDWORD lpNumberOfBytesRead,
1174      IN LPOVERLAPPED lpOverlapped);
1175
1176 #define STD_INPUT_HANDLE         ((DWORD)-10)
1177 #define STD_OUTPUT_HANDLE        ((DWORD)-11)
1178 #define STD_ERROR_HANDLE         ((DWORD)-12)
1179
1180 PALIMPORT
1181 HANDLE
1182 PALAPI
1183 GetStdHandle(
1184          IN DWORD nStdHandle);
1185
1186 PALIMPORT
1187 BOOL
1188 PALAPI
1189 SetEndOfFile(
1190          IN HANDLE hFile);
1191
1192 PALIMPORT
1193 DWORD
1194 PALAPI
1195 SetFilePointer(
1196            IN HANDLE hFile,
1197            IN LONG lDistanceToMove,
1198            IN PLONG lpDistanceToMoveHigh,
1199            IN DWORD dwMoveMethod);
1200
1201 PALIMPORT
1202 BOOL
1203 PALAPI
1204 SetFilePointerEx(
1205            IN HANDLE hFile,
1206            IN LARGE_INTEGER liDistanceToMove,
1207            OUT PLARGE_INTEGER lpNewFilePointer,
1208            IN DWORD dwMoveMethod);
1209
1210 PALIMPORT
1211 DWORD
1212 PALAPI
1213 GetFileSize(
1214         IN HANDLE hFile,
1215         OUT LPDWORD lpFileSizeHigh);
1216
1217 PALIMPORT
1218 BOOL
1219 PALAPI GetFileSizeEx(
1220         IN   HANDLE hFile,
1221         OUT  PLARGE_INTEGER lpFileSize);
1222
1223 PALIMPORT
1224 BOOL
1225 PALAPI
1226 GetFileInformationByHandle(
1227         IN HANDLE hFile,
1228         OUT BY_HANDLE_FILE_INFORMATION* lpFileInformation);
1229
1230 PALIMPORT
1231 LONG
1232 PALAPI
1233 CompareFileTime(
1234         IN CONST FILETIME *lpFileTime1,
1235         IN CONST FILETIME *lpFileTime2);
1236
1237 PALIMPORT
1238 BOOL
1239 PALAPI
1240 SetFileTime(
1241         IN HANDLE hFile,
1242         IN CONST FILETIME *lpCreationTime,
1243         IN CONST FILETIME *lpLastAccessTime,
1244         IN CONST FILETIME *lpLastWriteTime);
1245
1246 PALIMPORT
1247 BOOL
1248 PALAPI
1249 GetFileTime(
1250         IN HANDLE hFile,
1251         OUT LPFILETIME lpCreationTime,
1252         OUT LPFILETIME lpLastAccessTime,
1253         OUT LPFILETIME lpLastWriteTime);
1254
1255 PALIMPORT
1256 BOOL
1257 PALAPI
1258 FileTimeToLocalFileTime(
1259             IN CONST FILETIME *lpFileTime,
1260             OUT LPFILETIME lpLocalFileTime);
1261
1262 PALIMPORT
1263 BOOL
1264 PALAPI
1265 LocalFileTimeToFileTime(
1266             IN CONST FILETIME *lpLocalFileTime,
1267             OUT LPFILETIME lpFileTime);
1268
1269
1270 PALIMPORT
1271 VOID
1272 PALAPI
1273 GetSystemTimeAsFileTime(
1274             OUT LPFILETIME lpSystemTimeAsFileTime);
1275
1276 typedef struct _SYSTEMTIME {
1277     WORD wYear;
1278     WORD wMonth;
1279     WORD wDayOfWeek;
1280     WORD wDay;
1281     WORD wHour;
1282     WORD wMinute;
1283     WORD wSecond;
1284     WORD wMilliseconds;
1285 } SYSTEMTIME, *PSYSTEMTIME, *LPSYSTEMTIME;
1286
1287 PALIMPORT
1288 VOID
1289 PALAPI
1290 GetSystemTime(
1291           OUT LPSYSTEMTIME lpSystemTime);
1292
1293 PALIMPORT
1294 BOOL
1295 PALAPI
1296 FileTimeToSystemTime(
1297             IN CONST FILETIME *lpFileTime,
1298             OUT LPSYSTEMTIME lpSystemTime);
1299
1300 PALIMPORT
1301 BOOL
1302 PALAPI
1303 FileTimeToDosDateTime(
1304     IN CONST FILETIME *lpFileTime,
1305     OUT LPWORD lpFatDate,
1306     OUT LPWORD lpFatTime
1307     );
1308
1309 PALIMPORT
1310 BOOL
1311 PALAPI
1312 DosDateTimeToFileTime(
1313     IN WORD wFatDate,
1314     IN WORD wFatTime,
1315     OUT LPFILETIME lpFileTime
1316     );
1317
1318
1319
1320 PALIMPORT
1321 BOOL
1322 PALAPI
1323 FlushFileBuffers(
1324          IN HANDLE hFile);
1325
1326 #define FILE_TYPE_UNKNOWN         0x0000
1327 #define FILE_TYPE_DISK            0x0001
1328 #define FILE_TYPE_CHAR            0x0002
1329 #define FILE_TYPE_PIPE            0x0003
1330 #define FILE_TYPE_REMOTE          0x8000
1331
1332 PALIMPORT
1333 DWORD
1334 PALAPI
1335 GetFileType(
1336         IN HANDLE hFile);
1337
1338 PALIMPORT
1339 UINT
1340 PALAPI
1341 GetConsoleCP(
1342          VOID);
1343
1344 PALIMPORT
1345 UINT
1346 PALAPI
1347 GetConsoleOutputCP(
1348            VOID);
1349
1350 PALIMPORT
1351 DWORD
1352 PALAPI
1353 GetFullPathNameA(
1354          IN LPCSTR lpFileName,
1355          IN DWORD nBufferLength,
1356          OUT LPSTR lpBuffer,
1357          OUT LPSTR *lpFilePart);
1358
1359 PALIMPORT
1360 DWORD
1361 PALAPI
1362 GetFullPathNameW(
1363          IN LPCWSTR lpFileName,
1364          IN DWORD nBufferLength,
1365          OUT LPWSTR lpBuffer,
1366          OUT LPWSTR *lpFilePart);
1367
1368 #ifdef UNICODE
1369 #define GetFullPathName GetFullPathNameW
1370 #else
1371 #define GetFullPathName GetFullPathNameA
1372 #endif
1373
1374 PALIMPORT
1375 DWORD
1376 PALAPI
1377 GetLongPathNameW(
1378          IN LPCWSTR lpszShortPath,
1379                  OUT LPWSTR lpszLongPath,
1380          IN DWORD cchBuffer);
1381
1382 #ifdef UNICODE
1383 #define GetLongPathName GetLongPathNameW
1384 #endif
1385
1386 PALIMPORT
1387 DWORD
1388 PALAPI
1389 GetShortPathNameW(
1390          IN LPCWSTR lpszLongPath,
1391                  OUT LPWSTR lpszShortPath,
1392          IN DWORD cchBuffer);
1393
1394 #ifdef UNICODE
1395 #define GetShortPathName GetShortPathNameW
1396 #endif
1397
1398
1399 PALIMPORT
1400 UINT
1401 PALAPI
1402 GetTempFileNameA(
1403          IN LPCSTR lpPathName,
1404          IN LPCSTR lpPrefixString,
1405          IN UINT uUnique,
1406          OUT LPSTR lpTempFileName);
1407
1408 PALIMPORT
1409 UINT
1410 PALAPI
1411 GetTempFileNameW(
1412          IN LPCWSTR lpPathName,
1413          IN LPCWSTR lpPrefixString,
1414          IN UINT uUnique,
1415          OUT LPWSTR lpTempFileName);
1416
1417 #ifdef UNICODE
1418 #define GetTempFileName GetTempFileNameW
1419 #else
1420 #define GetTempFileName GetTempFileNameA
1421 #endif
1422
1423 PALIMPORT
1424 DWORD
1425 PALAPI
1426 GetTempPathA(
1427          IN DWORD nBufferLength,
1428          OUT LPSTR lpBuffer);
1429
1430 PALIMPORT
1431 DWORD
1432 PALAPI
1433 GetTempPathW(
1434          IN DWORD nBufferLength,
1435          OUT LPWSTR lpBuffer);
1436
1437 #ifdef UNICODE
1438 #define GetTempPath GetTempPathW
1439 #else
1440 #define GetTempPath GetTempPathA
1441 #endif
1442
1443 PALIMPORT
1444 DWORD
1445 PALAPI
1446 GetCurrentDirectoryA(
1447              IN DWORD nBufferLength,
1448              OUT LPSTR lpBuffer);
1449
1450 PALIMPORT
1451 DWORD
1452 PALAPI
1453 GetCurrentDirectoryW(
1454              IN DWORD nBufferLength,
1455              OUT LPWSTR lpBuffer);
1456
1457 #ifdef UNICODE
1458 #define GetCurrentDirectory GetCurrentDirectoryW
1459 #else
1460 #define GetCurrentDirectory GetCurrentDirectoryA
1461 #endif
1462
1463 PALIMPORT
1464 BOOL
1465 PALAPI
1466 SetCurrentDirectoryA(
1467             IN LPCSTR lpPathName);
1468
1469 PALIMPORT
1470 BOOL
1471 PALAPI
1472 SetCurrentDirectoryW(
1473             IN LPCWSTR lpPathName);
1474
1475
1476 #ifdef UNICODE
1477 #define SetCurrentDirectory SetCurrentDirectoryW
1478 #else
1479 #define SetCurrentDirectory SetCurrentDirectoryA
1480 #endif
1481
1482 // maximum length of the NETBIOS name (not including NULL)
1483 #define MAX_COMPUTERNAME_LENGTH 15
1484
1485 // maximum length of the username (not including NULL)
1486 #define UNLEN   256
1487
1488 PALIMPORT
1489 BOOL
1490 PALAPI
1491 GetUserNameW(
1492     OUT LPWSTR lpBuffer,      // address of name buffer
1493     IN OUT LPDWORD nSize );   // address of size of name buffer
1494
1495 PALIMPORT
1496 BOOL
1497 PALAPI
1498 GetComputerNameW(
1499     OUT LPWSTR lpBuffer,     // address of name buffer
1500     IN OUT LPDWORD nSize);   // address of size of name buffer
1501
1502 #ifdef UNICODE
1503 #define GetUserName GetUserNameW
1504 #define GetComputerName GetComputerNameW
1505 #endif // UNICODE
1506
1507 PALIMPORT
1508 HANDLE
1509 PALAPI
1510 CreateSemaphoreA(
1511          IN LPSECURITY_ATTRIBUTES lpSemaphoreAttributes,
1512          IN LONG lInitialCount,
1513          IN LONG lMaximumCount,
1514          IN LPCSTR lpName);
1515
1516 PALIMPORT
1517 HANDLE
1518 PALAPI
1519 CreateSemaphoreExA(
1520          IN LPSECURITY_ATTRIBUTES lpSemaphoreAttributes,
1521          IN LONG lInitialCount,
1522          IN LONG lMaximumCount,
1523          IN LPCSTR lpName,
1524          IN /*_Reserved_*/  DWORD dwFlags,
1525          IN DWORD dwDesiredAccess);
1526
1527 PALIMPORT
1528 HANDLE
1529 PALAPI
1530 CreateSemaphoreW(
1531          IN LPSECURITY_ATTRIBUTES lpSemaphoreAttributes,
1532          IN LONG lInitialCount,
1533          IN LONG lMaximumCount,
1534          IN LPCWSTR lpName);
1535
1536 PALIMPORT
1537 HANDLE
1538 PALAPI
1539 CreateSemaphoreExW(
1540         IN LPSECURITY_ATTRIBUTES lpSemaphoreAttributes,
1541         IN LONG lInitialCount,
1542         IN LONG lMaximumCount,
1543         IN LPCWSTR lpName,
1544         IN /*_Reserved_*/  DWORD dwFlags,
1545         IN DWORD dwDesiredAccess);
1546
1547 #ifdef UNICODE
1548 #define CreateSemaphore CreateSemaphoreW
1549 #define CreateSemaphoreEx CreateSemaphoreExW
1550 #else
1551 #define CreateSemaphore CreateSemaphoreA
1552 #define CreateSemaphoreEx CreateSemaphoreExA
1553 #endif
1554
1555 PALIMPORT
1556 BOOL
1557 PALAPI
1558 ReleaseSemaphore(
1559          IN HANDLE hSemaphore,
1560          IN LONG lReleaseCount,
1561          OUT LPLONG lpPreviousCount);
1562
1563 PALIMPORT
1564 HANDLE
1565 PALAPI
1566 CreateEventA(
1567          IN LPSECURITY_ATTRIBUTES lpEventAttributes,
1568          IN BOOL bManualReset,
1569          IN BOOL bInitialState,
1570          IN LPCSTR lpName);
1571
1572 PALIMPORT
1573 HANDLE
1574 PALAPI
1575 CreateEventW(
1576          IN LPSECURITY_ATTRIBUTES lpEventAttributes,
1577          IN BOOL bManualReset,
1578          IN BOOL bInitialState,
1579          IN LPCWSTR lpName);
1580
1581 #ifdef UNICODE
1582 #define CreateEvent CreateEventW
1583 #else
1584 #define CreateEvent CreateEventA
1585 #endif
1586
1587 PALIMPORT
1588 BOOL
1589 PALAPI
1590 SetEvent(
1591      IN HANDLE hEvent);
1592
1593 PALIMPORT
1594 BOOL
1595 PALAPI
1596 ResetEvent(
1597        IN HANDLE hEvent);
1598
1599 PALIMPORT
1600 HANDLE
1601 PALAPI
1602 OpenEventW(
1603        IN DWORD dwDesiredAccess,
1604        IN BOOL bInheritHandle,
1605        IN LPCWSTR lpName);
1606
1607 #ifdef UNICODE
1608 #define OpenEvent OpenEventW
1609 #endif
1610
1611 PALIMPORT
1612 HANDLE
1613 PALAPI
1614 CreateMutexW(
1615     IN LPSECURITY_ATTRIBUTES lpMutexAttributes,
1616     IN BOOL bInitialOwner,
1617     IN LPCWSTR lpName);
1618
1619 PALIMPORT
1620 HANDLE
1621 PALAPI
1622 CreateMutexA(
1623     IN LPSECURITY_ATTRIBUTES lpMutexAttributes,
1624     IN BOOL bInitialOwner,
1625     IN LPCSTR lpName);
1626
1627 #ifdef UNICODE
1628 #define CreateMutex  CreateMutexW
1629 #else
1630 #define CreateMutex  CreateMutexA
1631 #endif
1632
1633 PALIMPORT
1634 HANDLE
1635 PALAPI
1636 OpenMutexW(
1637        IN DWORD dwDesiredAccess,
1638        IN BOOL bInheritHandle,
1639        IN LPCWSTR lpName);
1640
1641 PALIMPORT
1642 HANDLE
1643 PALAPI
1644 OpenMutexA(
1645        IN DWORD dwDesiredAccess,
1646        IN BOOL bInheritHandle,
1647        IN LPCSTR lpName);
1648
1649 #ifdef UNICODE
1650 #define OpenMutex  OpenMutexW
1651 #else
1652 #define OpenMutex  OpenMutexA
1653 #endif // UNICODE
1654
1655 PALIMPORT
1656 BOOL
1657 PALAPI
1658 ReleaseMutex(
1659     IN HANDLE hMutex);
1660
1661 PALIMPORT
1662 DWORD
1663 PALAPI
1664 GetCurrentProcessId(
1665             VOID);
1666
1667 PALIMPORT
1668 HANDLE
1669 PALAPI
1670 GetCurrentProcess(
1671           VOID);
1672
1673 PALIMPORT
1674 DWORD
1675 PALAPI
1676 GetCurrentThreadId(
1677            VOID);
1678
1679 // To work around multiply-defined symbols in the Carbon framework.
1680 #define GetCurrentThread PAL_GetCurrentThread
1681 PALIMPORT
1682 HANDLE
1683 PALAPI
1684 GetCurrentThread(
1685          VOID);
1686
1687
1688 #define STARTF_USESTDHANDLES       0x00000100
1689
1690 typedef struct _STARTUPINFOW {
1691     DWORD cb;
1692     LPWSTR lpReserved_PAL_Undefined;
1693     LPWSTR lpDesktop_PAL_Undefined;
1694     LPWSTR lpTitle_PAL_Undefined;
1695     DWORD dwX_PAL_Undefined;
1696     DWORD dwY_PAL_Undefined;
1697     DWORD dwXSize_PAL_Undefined;
1698     DWORD dwYSize_PAL_Undefined;
1699     DWORD dwXCountChars_PAL_Undefined;
1700     DWORD dwYCountChars_PAL_Undefined;
1701     DWORD dwFillAttribute_PAL_Undefined;
1702     DWORD dwFlags;
1703     WORD wShowWindow_PAL_Undefined;
1704     WORD cbReserved2_PAL_Undefined;
1705     LPBYTE lpReserved2_PAL_Undefined;
1706     HANDLE hStdInput;
1707     HANDLE hStdOutput;
1708     HANDLE hStdError;
1709 } STARTUPINFOW, *LPSTARTUPINFOW;
1710
1711 typedef struct _STARTUPINFOA {
1712     DWORD cb;
1713     LPSTR lpReserved_PAL_Undefined;
1714     LPSTR lpDesktop_PAL_Undefined;
1715     LPSTR lpTitle_PAL_Undefined;
1716     DWORD dwX_PAL_Undefined;
1717     DWORD dwY_PAL_Undefined;
1718     DWORD dwXSize_PAL_Undefined;
1719     DWORD dwYSize_PAL_Undefined;
1720     DWORD dwXCountChars_PAL_Undefined;
1721     DWORD dwYCountChars_PAL_Undefined;
1722     DWORD dwFillAttribute_PAL_Undefined;
1723     DWORD dwFlags;
1724     WORD wShowWindow_PAL_Undefined;
1725     WORD cbReserved2_PAL_Undefined;
1726     LPBYTE lpReserved2_PAL_Undefined;
1727     HANDLE hStdInput;
1728     HANDLE hStdOutput;
1729     HANDLE hStdError;
1730 } STARTUPINFOA, *LPSTARTUPINFOA;
1731
1732 #ifdef UNICODE
1733 typedef STARTUPINFOW STARTUPINFO;
1734 typedef LPSTARTUPINFOW LPSTARTUPINFO;
1735 #else
1736 typedef STARTUPINFOA STARTUPINFO;
1737 typedef LPSTARTUPINFOW LPSTARTUPINFO;
1738 #endif
1739
1740 #define CREATE_NEW_CONSOLE          0x00000010
1741
1742 #define NORMAL_PRIORITY_CLASS             0x00000020
1743
1744 typedef struct _PROCESS_INFORMATION {
1745     HANDLE hProcess;
1746     HANDLE hThread;
1747     DWORD dwProcessId;
1748     DWORD dwThreadId_PAL_Undefined;
1749 } PROCESS_INFORMATION, *PPROCESS_INFORMATION, *LPPROCESS_INFORMATION;
1750
1751 PALIMPORT
1752 BOOL
1753 PALAPI
1754 CreateProcessA(
1755            IN LPCSTR lpApplicationName,
1756            IN LPSTR lpCommandLine,
1757            IN LPSECURITY_ATTRIBUTES lpProcessAttributes,
1758            IN LPSECURITY_ATTRIBUTES lpThreadAttributes,
1759            IN BOOL bInheritHandles,
1760            IN DWORD dwCreationFlags,
1761            IN LPVOID lpEnvironment,
1762            IN LPCSTR lpCurrentDirectory,
1763            IN LPSTARTUPINFOA lpStartupInfo,
1764            OUT LPPROCESS_INFORMATION lpProcessInformation);
1765
1766 PALIMPORT
1767 BOOL
1768 PALAPI
1769 CreateProcessW(
1770            IN LPCWSTR lpApplicationName,
1771            IN LPWSTR lpCommandLine,
1772            IN LPSECURITY_ATTRIBUTES lpProcessAttributes,
1773            IN LPSECURITY_ATTRIBUTES lpThreadAttributes,
1774            IN BOOL bInheritHandles,
1775            IN DWORD dwCreationFlags,
1776            IN LPVOID lpEnvironment,
1777            IN LPCWSTR lpCurrentDirectory,
1778            IN LPSTARTUPINFOW lpStartupInfo,
1779            OUT LPPROCESS_INFORMATION lpProcessInformation);
1780
1781 #ifdef UNICODE
1782 #define CreateProcess CreateProcessW
1783 #else
1784 #define CreateProcess CreateProcessA
1785 #endif
1786
1787 PALIMPORT
1788 PAL_NORETURN
1789 VOID
1790 PALAPI
1791 ExitProcess(
1792         IN UINT uExitCode);
1793
1794 PALIMPORT
1795 BOOL
1796 PALAPI
1797 TerminateProcess(
1798          IN HANDLE hProcess,
1799          IN UINT uExitCode);
1800
1801 PALIMPORT
1802 BOOL
1803 PALAPI
1804 GetExitCodeProcess(
1805            IN HANDLE hProcess,
1806            IN LPDWORD lpExitCode);
1807
1808 PALIMPORT
1809 BOOL
1810 PALAPI
1811 GetProcessTimes(
1812         IN HANDLE hProcess,
1813         OUT LPFILETIME lpCreationTime,
1814         OUT LPFILETIME lpExitTime,
1815         OUT LPFILETIME lpKernelTime,
1816         OUT LPFILETIME lpUserTime);
1817
1818 #define MAXIMUM_WAIT_OBJECTS  64
1819 #define WAIT_OBJECT_0 0
1820 #define WAIT_ABANDONED   0x00000080
1821 #define WAIT_ABANDONED_0 0x00000080
1822 #define WAIT_TIMEOUT 258
1823 #define WAIT_FAILED ((DWORD)0xFFFFFFFF)
1824
1825 #define INFINITE 0xFFFFFFFF // Infinite timeout
1826
1827 PALIMPORT
1828 DWORD
1829 PALAPI
1830 WaitForSingleObject(
1831             IN HANDLE hHandle,
1832             IN DWORD dwMilliseconds);
1833
1834 PALIMPORT
1835 DWORD
1836 PALAPI
1837 WaitForSingleObjectEx(
1838             IN HANDLE hHandle,
1839             IN DWORD dwMilliseconds,
1840             IN BOOL bAlertable);
1841
1842 PALIMPORT
1843 DWORD
1844 PALAPI
1845 WaitForMultipleObjects(
1846                IN DWORD nCount,
1847                IN CONST HANDLE *lpHandles,
1848                IN BOOL bWaitAll,
1849                IN DWORD dwMilliseconds);
1850
1851 PALIMPORT
1852 DWORD
1853 PALAPI
1854 WaitForMultipleObjectsEx(
1855              IN DWORD nCount,
1856              IN CONST HANDLE *lpHandles,
1857              IN BOOL bWaitAll,
1858              IN DWORD dwMilliseconds,
1859              IN BOOL bAlertable);
1860
1861 PALIMPORT
1862 RHANDLE
1863 PALAPI
1864 PAL_LocalHandleToRemote(
1865             IN HANDLE hLocal);
1866
1867 PALIMPORT
1868 HANDLE
1869 PALAPI
1870 PAL_RemoteHandleToLocal(
1871             IN RHANDLE hRemote);
1872
1873
1874 #define DUPLICATE_CLOSE_SOURCE      0x00000001
1875 #define DUPLICATE_SAME_ACCESS       0x00000002
1876
1877 PALIMPORT
1878 BOOL
1879 PALAPI
1880 DuplicateHandle(
1881         IN HANDLE hSourceProcessHandle,
1882         IN HANDLE hSourceHandle,
1883         IN HANDLE hTargetProcessHandle,
1884         OUT LPHANDLE lpTargetHandle,
1885         IN DWORD dwDesiredAccess,
1886         IN BOOL bInheritHandle,
1887         IN DWORD dwOptions);
1888
1889 PALIMPORT
1890 VOID
1891 PALAPI
1892 Sleep(
1893       IN DWORD dwMilliseconds);
1894
1895 PALIMPORT
1896 DWORD
1897 PALAPI
1898 SleepEx(
1899     IN DWORD dwMilliseconds,
1900     IN BOOL bAlertable);
1901
1902 PALIMPORT
1903 BOOL
1904 PALAPI
1905 SwitchToThread(
1906     VOID);
1907
1908 #define DEBUG_PROCESS                     0x00000001
1909 #define DEBUG_ONLY_THIS_PROCESS           0x00000002
1910 #define CREATE_SUSPENDED                  0x00000004
1911 #define STACK_SIZE_PARAM_IS_A_RESERVATION 0x00010000
1912
1913 PALIMPORT
1914 HANDLE
1915 PALAPI
1916 CreateThread(
1917          IN LPSECURITY_ATTRIBUTES lpThreadAttributes,
1918          IN DWORD dwStackSize,
1919          IN LPTHREAD_START_ROUTINE lpStartAddress,
1920          IN LPVOID lpParameter,
1921          IN DWORD dwCreationFlags,
1922          OUT LPDWORD lpThreadId);
1923
1924 PALIMPORT
1925 PAL_NORETURN
1926 VOID
1927 PALAPI
1928 ExitThread(
1929        IN DWORD dwExitCode);
1930
1931 PALIMPORT
1932 BOOL
1933 PALAPI
1934 GetExitCodeThread(
1935            IN HANDLE hThread,
1936            IN LPDWORD lpExitCode);
1937
1938 PALIMPORT
1939 DWORD
1940 PALAPI
1941 SuspendThread(
1942           IN HANDLE hThread);
1943
1944 PALIMPORT
1945 DWORD
1946 PALAPI
1947 ResumeThread(
1948          IN HANDLE hThread);
1949
1950 typedef VOID (PALAPI *PAPCFUNC)(ULONG_PTR dwParam);
1951
1952 PALIMPORT
1953 DWORD
1954 PALAPI
1955 QueueUserAPC(
1956          IN PAPCFUNC pfnAPC,
1957          IN HANDLE hThread,
1958          IN ULONG_PTR dwData);
1959
1960 #ifdef _X86_
1961
1962 //
1963 // ***********************************************************************************
1964 //
1965 // NOTE: These context definitions are replicated in ndp/clr/src/debug/inc/DbgTargetContext.h (for the
1966 // purposes manipulating contexts from different platforms during remote debugging). Be sure to keep those
1967 // definitions in sync if you make any changes here.
1968 //
1969 // ***********************************************************************************
1970 //
1971
1972 #define SIZE_OF_80387_REGISTERS      80
1973
1974 #define CONTEXT_i386            0x00010000
1975 #define CONTEXT_CONTROL         (CONTEXT_i386 | 0x00000001L) // SS:SP, CS:IP, FLAGS, BP
1976 #define CONTEXT_INTEGER         (CONTEXT_i386 | 0x00000002L) // AX, BX, CX, DX, SI, DI
1977 #define CONTEXT_SEGMENTS        (CONTEXT_i386 | 0x00000004L)
1978 #define CONTEXT_FLOATING_POINT  (CONTEXT_i386 | 0x00000008L) // 387 state
1979 #define CONTEXT_DEBUG_REGISTERS (CONTEXT_i386 | 0x00000010L)
1980
1981 #define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_SEGMENTS)
1982 #define CONTEXT_EXTENDED_REGISTERS  (CONTEXT_i386 | 0x00000020L)
1983 #define CONTEXT_ALL (CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_SEGMENTS | CONTEXT_FLOATING_POINT | CONTEXT_DEBUG_REGISTERS | CONTEXT_EXTENDED_REGISTERS)
1984
1985 #define MAXIMUM_SUPPORTED_EXTENSION     512
1986
1987 typedef struct _FLOATING_SAVE_AREA {
1988     DWORD   ControlWord;
1989     DWORD   StatusWord;
1990     DWORD   TagWord;
1991     DWORD   ErrorOffset;
1992     DWORD   ErrorSelector;
1993     DWORD   DataOffset;
1994     DWORD   DataSelector;
1995     BYTE    RegisterArea[SIZE_OF_80387_REGISTERS];
1996     DWORD   Cr0NpxState;
1997 } FLOATING_SAVE_AREA;
1998
1999 typedef FLOATING_SAVE_AREA *PFLOATING_SAVE_AREA;
2000
2001 typedef struct _CONTEXT {
2002     ULONG ContextFlags;
2003
2004     ULONG   Dr0_PAL_Undefined;
2005     ULONG   Dr1_PAL_Undefined;
2006     ULONG   Dr2_PAL_Undefined;
2007     ULONG   Dr3_PAL_Undefined;
2008     ULONG   Dr6_PAL_Undefined;
2009     ULONG   Dr7_PAL_Undefined;
2010
2011     FLOATING_SAVE_AREA FloatSave;
2012
2013     ULONG   SegGs_PAL_Undefined;
2014     ULONG   SegFs_PAL_Undefined;
2015     ULONG   SegEs_PAL_Undefined;
2016     ULONG   SegDs_PAL_Undefined;
2017
2018     ULONG   Edi;
2019     ULONG   Esi;
2020     ULONG   Ebx;
2021     ULONG   Edx;
2022     ULONG   Ecx;
2023     ULONG   Eax;
2024
2025     ULONG   Ebp;
2026     ULONG   Eip;
2027     ULONG   SegCs;
2028     ULONG   EFlags;
2029     ULONG   Esp;
2030     ULONG   SegSs;
2031
2032     UCHAR   ExtendedRegisters[MAXIMUM_SUPPORTED_EXTENSION];
2033
2034 } CONTEXT, *PCONTEXT, *LPCONTEXT;
2035
2036 // To support saving and loading xmm register context we need to know the offset in the ExtendedRegisters
2037 // section at which they are stored. This has been determined experimentally since I have found no
2038 // documentation thus far but it corresponds to the offset we'd expect if a fxsave instruction was used to
2039 // store the regular FP state along with the XMM registers at the start of the extended registers section.
2040 // Technically the offset doesn't really matter if no code in the PAL or runtime knows what the offset should
2041 // be either (as long as we're consistent across GetThreadContext() and SetThreadContext() and we don't
2042 // support any other values in the ExtendedRegisters) but we might as well be as accurate as we can.
2043 #define CONTEXT_EXREG_XMM_OFFSET 160
2044
2045 #elif defined(_PPC_)
2046
2047 //
2048 // ***********************************************************************************
2049 //
2050 // NOTE: These context definitions are replicated in ndp/clr/src/debug/inc/DbgTargetContext.h (for the
2051 // purposes manipulating contexts from different platforms during remote debugging). Be sure to keep those
2052 // definitions in sync if you make any changes here.
2053 //
2054 // ***********************************************************************************
2055 //
2056
2057 #define CONTEXT_CONTROL         0x00000001L
2058 #define CONTEXT_FLOATING_POINT  0x00000002L
2059 #define CONTEXT_INTEGER         0x00000004L
2060
2061 #define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_FLOATING_POINT | CONTEXT_INTEGER)
2062 #define CONTEXT_ALL CONTEXT_FULL
2063
2064 typedef struct _CONTEXT {
2065
2066     //
2067     // This section is specified/returned if the ContextFlags word contains
2068     // the flag CONTEXT_FLOATING_POINT.
2069     //
2070
2071     double Fpr0;                        // Floating registers 0..31
2072     double Fpr1;
2073     double Fpr2;
2074     double Fpr3;
2075     double Fpr4;
2076     double Fpr5;
2077     double Fpr6;
2078     double Fpr7;
2079     double Fpr8;
2080     double Fpr9;
2081     double Fpr10;
2082     double Fpr11;
2083     double Fpr12;
2084     double Fpr13;
2085     double Fpr14;
2086     double Fpr15;
2087     double Fpr16;
2088     double Fpr17;
2089     double Fpr18;
2090     double Fpr19;
2091     double Fpr20;
2092     double Fpr21;
2093     double Fpr22;
2094     double Fpr23;
2095     double Fpr24;
2096     double Fpr25;
2097     double Fpr26;
2098     double Fpr27;
2099     double Fpr28;
2100     double Fpr29;
2101     double Fpr30;
2102     double Fpr31;
2103     double Fpscr;                       // Floating point status/control reg
2104
2105     //
2106     // This section is specified/returned if the ContextFlags word contains
2107     // the flag CONTEXT_INTEGER.
2108     //
2109
2110     ULONG Gpr0;                         // General registers 0..31
2111     ULONG Gpr1;                         // StackPointer
2112     ULONG Gpr2;
2113     ULONG Gpr3;
2114     ULONG Gpr4;
2115     ULONG Gpr5;
2116     ULONG Gpr6;
2117     ULONG Gpr7;
2118     ULONG Gpr8;
2119     ULONG Gpr9;
2120     ULONG Gpr10;
2121     ULONG Gpr11;
2122     ULONG Gpr12;
2123     ULONG Gpr13;
2124     ULONG Gpr14;
2125     ULONG Gpr15;
2126     ULONG Gpr16;
2127     ULONG Gpr17;
2128     ULONG Gpr18;
2129     ULONG Gpr19;
2130     ULONG Gpr20;
2131     ULONG Gpr21;
2132     ULONG Gpr22;
2133     ULONG Gpr23;
2134     ULONG Gpr24;
2135     ULONG Gpr25;
2136     ULONG Gpr26;
2137     ULONG Gpr27;
2138     ULONG Gpr28;
2139     ULONG Gpr29;
2140     ULONG Gpr30;
2141     ULONG Gpr31;
2142
2143     ULONG Cr;                           // Condition register
2144     ULONG Xer;                          // Fixed point exception register
2145
2146     //
2147     // This section is specified/returned if the ContextFlags word contains
2148     // the flag CONTEXT_CONTROL.
2149     //
2150
2151     ULONG Msr;                          // Machine status register
2152     ULONG Iar;                          // Instruction address register
2153     ULONG Lr;                           // Link register
2154     ULONG Ctr;                          // Count register
2155
2156     //
2157     // The flags values within this flag control the contents of
2158     // a CONTEXT record.
2159     //
2160     // If the context record is used as an input parameter, then
2161     // for each portion of the context record controlled by a flag
2162     // whose value is set, it is assumed that that portion of the
2163     // context record contains valid context. If the context record
2164     // is being used to modify a thread's context, then only that
2165     // portion of the threads context will be modified.
2166     //
2167     // If the context record is used as an IN OUT parameter to capture
2168     // the context of a thread, then only those portions of the thread's
2169     // context corresponding to set flags will be returned.
2170     //
2171     // The context record is never used as an OUT only parameter.
2172     //
2173
2174     ULONG ContextFlags;
2175
2176     ULONG Fill[3];                      // Pad out to multiple of 16 bytes
2177
2178     //
2179     // This section is specified/returned if CONTEXT_DEBUG_REGISTERS is
2180     // set in ContextFlags.  Note that CONTEXT_DEBUG_REGISTERS is NOT
2181     // included in CONTEXT_FULL.
2182     //
2183     ULONG Dr0;                          // Breakpoint Register 1
2184     ULONG Dr1;                          // Breakpoint Register 2
2185     ULONG Dr2;                          // Breakpoint Register 3
2186     ULONG Dr3;                          // Breakpoint Register 4
2187     ULONG Dr4;                          // Breakpoint Register 5
2188     ULONG Dr5;                          // Breakpoint Register 6
2189     ULONG Dr6;                          // Debug Status Register
2190     ULONG Dr7;                          // Debug Control Register
2191
2192 } CONTEXT, *PCONTEXT, *LPCONTEXT;
2193
2194 #elif defined(_SPARC_)
2195
2196 #define CONTEXT_CONTROL         0x00000001L
2197 #define CONTEXT_FLOATING_POINT  0x00000002L
2198 #define CONTEXT_INTEGER         0x00000004L
2199
2200 #define COUNT_FLOATING_REGISTER 32
2201 #define COUNT_DOUBLE_REGISTER 16
2202 #define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_FLOATING_POINT | CONTEXT_INTEGER)
2203 #define CONTEXT_ALL CONTEXT_FULL
2204
2205 typedef struct _CONTEXT {
2206     //
2207     // This section is specified/returned if the ContextFlags word contains
2208     // the flag CONTEXT_INTEGER.
2209     //
2210     ULONG g0;
2211     ULONG g1;
2212     ULONG g2;
2213     ULONG g3;
2214     ULONG g4;
2215     ULONG g5;
2216     ULONG g6;
2217     ULONG g7;
2218     ULONG o0;
2219     ULONG o1;
2220     ULONG o2;
2221     ULONG o3;
2222     ULONG o4;
2223     ULONG o5;
2224     ULONG sp;
2225     ULONG o7;
2226     ULONG l0;
2227     ULONG l1;
2228     ULONG l2;
2229     ULONG l3;
2230     ULONG l4;
2231     ULONG l5;
2232     ULONG l6;
2233     ULONG l7;
2234     ULONG i0;
2235     ULONG i1;
2236     ULONG i2;
2237     ULONG i3;
2238     ULONG i4;
2239     ULONG i5;
2240     ULONG fp;
2241     ULONG i7;
2242
2243     ULONG y;
2244
2245     //
2246     // This section is specified/returned if the ContextFlags word contains
2247     // the flag CONTEXT_CONTROL.
2248     //
2249 #if defined(__sparcv9)
2250     ULONG ccr;
2251 #else
2252     ULONG psr;
2253 #endif
2254     ULONG pc;     // program counter
2255     ULONG npc;    // next address to be executed
2256
2257     ULONG ContextFlags;
2258
2259     //
2260     // This section is specified/returned if the ContextFlags word contains
2261     // the flag CONTEXT_FLOATING_POINT.
2262     //
2263     ULONGLONG fsr;
2264     union {
2265         float f[COUNT_FLOATING_REGISTER];
2266         double d[COUNT_DOUBLE_REGISTER];
2267         } fprs;
2268
2269 } CONTEXT, *PCONTEXT, *LPCONTEXT;
2270
2271 #elif defined(_PARISC_)
2272
2273 // ToDo: Get this correct for PARISC architecture
2274 #define CONTEXT_CONTROL         0x00000001L
2275 #define CONTEXT_FLOATING_POINT  0x00000002L
2276 #define CONTEXT_INTEGER         0x00000004L
2277
2278 #define COUNT_FLOATING_REGISTER 32
2279 #define COUNT_DOUBLE_REGISTER 16
2280 #define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_FLOATING_POINT | CONTEXT_INTEGER)
2281 #define CONTEXT_ALL CONTEXT_FULL
2282
2283 typedef struct _CONTEXT {
2284     //
2285     // This section is specified/returned if the ContextFlags word contains
2286     // the flag CONTEXT_INTEGER.
2287     //
2288     ULONG g0;
2289     ULONG g1;
2290     ULONG g2;
2291     ULONG g3;
2292     ULONG g4;
2293     ULONG g5;
2294     ULONG g6;
2295     ULONG g7;
2296     ULONG o0;
2297     ULONG o1;
2298     ULONG o2;
2299     ULONG o3;
2300     ULONG o4;
2301     ULONG o5;
2302     ULONG sp;
2303     ULONG o7;
2304     ULONG l0;
2305     ULONG l1;
2306     ULONG l2;
2307     ULONG l3;
2308     ULONG l4;
2309     ULONG l5;
2310     ULONG l6;
2311     ULONG l7;
2312     ULONG i0;
2313     ULONG i1;
2314     ULONG i2;
2315     ULONG i3;
2316     ULONG i4;
2317     ULONG i5;
2318     ULONG fp;
2319     ULONG i7;
2320
2321     ULONG y;
2322
2323     //
2324     // This section is specified/returned if the ContextFlags word contains
2325     // the flag CONTEXT_CONTROL.
2326     //
2327     ULONG psr;
2328     ULONG pc;     // program counter
2329     ULONG npc;    // next address to be executed
2330
2331     ULONG ContextFlags;
2332
2333     //
2334     // This section is specified/returned if the ContextFlags word contains
2335     // the flag CONTEXT_FLOATING_POINT.
2336     //
2337     ULONGLONG fsr;
2338     union {
2339         float f[COUNT_FLOATING_REGISTER];
2340         double d[COUNT_DOUBLE_REGISTER];
2341         } fprs;
2342
2343 } CONTEXT, *PCONTEXT, *LPCONTEXT;
2344
2345 #elif defined(_IA64_)
2346
2347 // copied from winnt.h
2348 typedef struct _FLOAT128 {
2349     __int64 LowPart;
2350     __int64 HighPart;
2351 } FLOAT128;
2352
2353 typedef FLOAT128 *PFLOAT128;
2354
2355 // begin_ntddk begin_nthal
2356
2357 //
2358 // The following flags control the contents of the CONTEXT structure.
2359 //
2360
2361 #if !defined(RC_INVOKED)
2362
2363 #define CONTEXT_IA64                    0x00080000
2364
2365 #define CONTEXT_CONTROL                 (CONTEXT_IA64 | 0x00000001L)
2366 #define CONTEXT_LOWER_FLOATING_POINT    (CONTEXT_IA64 | 0x00000002L)
2367 #define CONTEXT_HIGHER_FLOATING_POINT   (CONTEXT_IA64 | 0x00000004L)
2368 #define CONTEXT_INTEGER                 (CONTEXT_IA64 | 0x00000008L)
2369 #define CONTEXT_DEBUG                   (CONTEXT_IA64 | 0x00000010L)
2370 #define CONTEXT_IA32_CONTROL            (CONTEXT_IA64 | 0x00000020L)  // Includes StIPSR
2371
2372
2373 #define CONTEXT_FLOATING_POINT          (CONTEXT_LOWER_FLOATING_POINT | CONTEXT_HIGHER_FLOATING_POINT)
2374 #define CONTEXT_FULL                    (CONTEXT_CONTROL | CONTEXT_FLOATING_POINT | CONTEXT_INTEGER | CONTEXT_IA32_CONTROL)
2375 #define CONTEXT_ALL                     (CONTEXT_CONTROL | CONTEXT_FLOATING_POINT | CONTEXT_INTEGER | CONTEXT_DEBUG | CONTEXT_IA32_CONTROL)
2376
2377 #define CONTEXT_EXCEPTION_ACTIVE        0x8000000
2378 #define CONTEXT_SERVICE_ACTIVE          0x10000000
2379 #define CONTEXT_EXCEPTION_REQUEST       0x40000000
2380 #define CONTEXT_EXCEPTION_REPORTING     0x80000000
2381
2382 #endif // !defined(RC_INVOKED)
2383
2384 //
2385 // Context Frame
2386 //
2387 //  This frame has a several purposes: 1) it is used as an argument to
2388 //  NtContinue, 2) it is used to construct a call frame for APC delivery,
2389 //  3) it is used to construct a call frame for exception dispatching
2390 //  in user mode, 4) it is used in the user level thread creation
2391 //  routines, and 5) it is used to to pass thread state to debuggers.
2392 //
2393 //  N.B. Because this record is used as a call frame, it must be EXACTLY
2394 //  a multiple of 16 bytes in length and aligned on a 16-byte boundary.
2395 //
2396
2397 typedef struct _CONTEXT {
2398
2399     //
2400     // The flags values within this flag control the contents of
2401     // a CONTEXT record.
2402     //
2403     // If the context record is used as an input parameter, then
2404     // for each portion of the context record controlled by a flag
2405     // whose value is set, it is assumed that that portion of the
2406     // context record contains valid context. If the context record
2407     // is being used to modify a thread's context, then only that
2408     // portion of the threads context will be modified.
2409     //
2410     // If the context record is used as an IN OUT parameter to capture
2411     // the context of a thread, then only those portions of the thread's
2412     // context corresponding to set flags will be returned.
2413     //
2414     // The context record is never used as an OUT only parameter.
2415     //
2416
2417     DWORD ContextFlags;
2418     DWORD Fill1[3];         // for alignment of following on 16-byte boundary
2419
2420     //
2421     // This section is specified/returned if the ContextFlags word contains
2422     // the flag CONTEXT_DEBUG.
2423     //
2424     // N.B. CONTEXT_DEBUG is *not* part of CONTEXT_FULL.
2425     //
2426
2427     ULONGLONG DbI0;
2428     ULONGLONG DbI1;
2429     ULONGLONG DbI2;
2430     ULONGLONG DbI3;
2431     ULONGLONG DbI4;
2432     ULONGLONG DbI5;
2433     ULONGLONG DbI6;
2434     ULONGLONG DbI7;
2435
2436     ULONGLONG DbD0;
2437     ULONGLONG DbD1;
2438     ULONGLONG DbD2;
2439     ULONGLONG DbD3;
2440     ULONGLONG DbD4;
2441     ULONGLONG DbD5;
2442     ULONGLONG DbD6;
2443     ULONGLONG DbD7;
2444
2445     //
2446     // This section is specified/returned if the ContextFlags word contains
2447     // the flag CONTEXT_LOWER_FLOATING_POINT.
2448     //
2449
2450     FLOAT128 FltS0;
2451     FLOAT128 FltS1;
2452     FLOAT128 FltS2;
2453     FLOAT128 FltS3;
2454     FLOAT128 FltT0;
2455     FLOAT128 FltT1;
2456     FLOAT128 FltT2;
2457     FLOAT128 FltT3;
2458     FLOAT128 FltT4;
2459     FLOAT128 FltT5;
2460     FLOAT128 FltT6;
2461     FLOAT128 FltT7;
2462     FLOAT128 FltT8;
2463     FLOAT128 FltT9;
2464
2465     //
2466     // This section is specified/returned if the ContextFlags word contains
2467     // the flag CONTEXT_HIGHER_FLOATING_POINT.
2468     //
2469
2470     FLOAT128 FltS4;
2471     FLOAT128 FltS5;
2472     FLOAT128 FltS6;
2473     FLOAT128 FltS7;
2474     FLOAT128 FltS8;
2475     FLOAT128 FltS9;
2476     FLOAT128 FltS10;
2477     FLOAT128 FltS11;
2478     FLOAT128 FltS12;
2479     FLOAT128 FltS13;
2480     FLOAT128 FltS14;
2481     FLOAT128 FltS15;
2482     FLOAT128 FltS16;
2483     FLOAT128 FltS17;
2484     FLOAT128 FltS18;
2485     FLOAT128 FltS19;
2486
2487     FLOAT128 FltF32;
2488     FLOAT128 FltF33;
2489     FLOAT128 FltF34;
2490     FLOAT128 FltF35;
2491     FLOAT128 FltF36;
2492     FLOAT128 FltF37;
2493     FLOAT128 FltF38;
2494     FLOAT128 FltF39;
2495
2496     FLOAT128 FltF40;
2497     FLOAT128 FltF41;
2498     FLOAT128 FltF42;
2499     FLOAT128 FltF43;
2500     FLOAT128 FltF44;
2501     FLOAT128 FltF45;
2502     FLOAT128 FltF46;
2503     FLOAT128 FltF47;
2504     FLOAT128 FltF48;
2505     FLOAT128 FltF49;
2506
2507     FLOAT128 FltF50;
2508     FLOAT128 FltF51;
2509     FLOAT128 FltF52;
2510     FLOAT128 FltF53;
2511     FLOAT128 FltF54;
2512     FLOAT128 FltF55;
2513     FLOAT128 FltF56;
2514     FLOAT128 FltF57;
2515     FLOAT128 FltF58;
2516     FLOAT128 FltF59;
2517
2518     FLOAT128 FltF60;
2519     FLOAT128 FltF61;
2520     FLOAT128 FltF62;
2521     FLOAT128 FltF63;
2522     FLOAT128 FltF64;
2523     FLOAT128 FltF65;
2524     FLOAT128 FltF66;
2525     FLOAT128 FltF67;
2526     FLOAT128 FltF68;
2527     FLOAT128 FltF69;
2528
2529     FLOAT128 FltF70;
2530     FLOAT128 FltF71;
2531     FLOAT128 FltF72;
2532     FLOAT128 FltF73;
2533     FLOAT128 FltF74;
2534     FLOAT128 FltF75;
2535     FLOAT128 FltF76;
2536     FLOAT128 FltF77;
2537     FLOAT128 FltF78;
2538     FLOAT128 FltF79;
2539
2540     FLOAT128 FltF80;
2541     FLOAT128 FltF81;
2542     FLOAT128 FltF82;
2543     FLOAT128 FltF83;
2544     FLOAT128 FltF84;
2545     FLOAT128 FltF85;
2546     FLOAT128 FltF86;
2547     FLOAT128 FltF87;
2548     FLOAT128 FltF88;
2549     FLOAT128 FltF89;
2550
2551     FLOAT128 FltF90;
2552     FLOAT128 FltF91;
2553     FLOAT128 FltF92;
2554     FLOAT128 FltF93;
2555     FLOAT128 FltF94;
2556     FLOAT128 FltF95;
2557     FLOAT128 FltF96;
2558     FLOAT128 FltF97;
2559     FLOAT128 FltF98;
2560     FLOAT128 FltF99;
2561
2562     FLOAT128 FltF100;
2563     FLOAT128 FltF101;
2564     FLOAT128 FltF102;
2565     FLOAT128 FltF103;
2566     FLOAT128 FltF104;
2567     FLOAT128 FltF105;
2568     FLOAT128 FltF106;
2569     FLOAT128 FltF107;
2570     FLOAT128 FltF108;
2571     FLOAT128 FltF109;
2572
2573     FLOAT128 FltF110;
2574     FLOAT128 FltF111;
2575     FLOAT128 FltF112;
2576     FLOAT128 FltF113;
2577     FLOAT128 FltF114;
2578     FLOAT128 FltF115;
2579     FLOAT128 FltF116;
2580     FLOAT128 FltF117;
2581     FLOAT128 FltF118;
2582     FLOAT128 FltF119;
2583
2584     FLOAT128 FltF120;
2585     FLOAT128 FltF121;
2586     FLOAT128 FltF122;
2587     FLOAT128 FltF123;
2588     FLOAT128 FltF124;
2589     FLOAT128 FltF125;
2590     FLOAT128 FltF126;
2591     FLOAT128 FltF127;
2592
2593     //
2594     // This section is specified/returned if the ContextFlags word contains
2595     // the flag CONTEXT_LOWER_FLOATING_POINT | CONTEXT_HIGHER_FLOATING_POINT | CONTEXT_CONTROL.
2596     //
2597
2598     ULONGLONG StFPSR;       //  FP status
2599
2600     //
2601     // This section is specified/returned if the ContextFlags word contains
2602     // the flag CONTEXT_INTEGER.
2603     //
2604     // N.B. The registers gp, sp, rp are part of the control context
2605     //
2606
2607     ULONGLONG IntGp;        //  r1, volatile
2608     ULONGLONG IntT0;        //  r2-r3, volatile
2609     ULONGLONG IntT1;        //
2610     ULONGLONG IntS0;        //  r4-r7, preserved
2611     ULONGLONG IntS1;
2612     ULONGLONG IntS2;
2613     ULONGLONG IntS3;
2614     ULONGLONG IntV0;        //  r8, volatile
2615     ULONGLONG IntT2;        //  r9-r11, volatile
2616     ULONGLONG IntT3;
2617     ULONGLONG IntT4;
2618     ULONGLONG IntSp;        //  stack pointer (r12), special
2619     ULONGLONG IntTeb;       //  teb (r13), special
2620     ULONGLONG IntT5;        //  r14-r31, volatile
2621     ULONGLONG IntT6;
2622     ULONGLONG IntT7;
2623     ULONGLONG IntT8;
2624     ULONGLONG IntT9;
2625     ULONGLONG IntT10;
2626     ULONGLONG IntT11;
2627     ULONGLONG IntT12;
2628     ULONGLONG IntT13;
2629     ULONGLONG IntT14;
2630     ULONGLONG IntT15;
2631     ULONGLONG IntT16;
2632     ULONGLONG IntT17;
2633     ULONGLONG IntT18;
2634     ULONGLONG IntT19;
2635     ULONGLONG IntT20;
2636     ULONGLONG IntT21;
2637     ULONGLONG IntT22;
2638
2639     ULONGLONG IntNats;      //  Nat bits for r1-r31
2640                             //  r1-r31 in bits 1 thru 31.
2641     ULONGLONG Preds;        //  predicates, preserved
2642
2643     ULONGLONG BrRp;         //  return pointer, b0, preserved
2644     ULONGLONG BrS0;         //  b1-b5, preserved
2645     ULONGLONG BrS1;
2646     ULONGLONG BrS2;
2647     ULONGLONG BrS3;
2648     ULONGLONG BrS4;
2649     ULONGLONG BrT0;         //  b6-b7, volatile
2650     ULONGLONG BrT1;
2651
2652     //
2653     // This section is specified/returned if the ContextFlags word contains
2654     // the flag CONTEXT_CONTROL.
2655     //
2656
2657     // Other application registers
2658     ULONGLONG ApUNAT;       //  User Nat collection register, preserved
2659     ULONGLONG ApLC;         //  Loop counter register, preserved
2660     ULONGLONG ApEC;         //  Epilog counter register, preserved
2661     ULONGLONG ApCCV;        //  CMPXCHG value register, volatile
2662     ULONGLONG ApDCR;        //  Default control register (TBD)
2663
2664     // Register stack info
2665     ULONGLONG RsPFS;        //  Previous function state, preserved
2666     ULONGLONG RsBSP;        //  Backing store pointer, preserved
2667     ULONGLONG RsBSPSTORE;
2668     ULONGLONG RsRSC;        //  RSE configuration, volatile
2669     ULONGLONG RsRNAT;       //  RSE Nat collection register, preserved
2670
2671     // Trap Status Information
2672     ULONGLONG StIPSR;       //  Interruption Processor Status
2673     ULONGLONG StIIP;        //  Interruption IP
2674     ULONGLONG StIFS;        //  Interruption Function State
2675
2676     // iA32 related control registers
2677     ULONGLONG StFCR;        //  copy of Ar21
2678     ULONGLONG Eflag;        //  Eflag copy of Ar24
2679     ULONGLONG SegCSD;       //  iA32 CSDescriptor (Ar25)
2680     ULONGLONG SegSSD;       //  iA32 SSDescriptor (Ar26)
2681     ULONGLONG Cflag;        //  Cr0+Cr4 copy of Ar27
2682     ULONGLONG StFSR;        //  x86 FP status (copy of AR28)
2683     ULONGLONG StFIR;        //  x86 FP status (copy of AR29)
2684     ULONGLONG StFDR;        //  x86 FP status (copy of AR30)
2685
2686       ULONGLONG UNUSEDPACK;   //  added to pack StFDR to 16-bytes
2687
2688 } CONTEXT, *PCONTEXT, *LPCONTEXT;
2689 #elif defined(_AMD64_)
2690 // copied from winnt.h
2691
2692 #define CONTEXT_AMD64   0x100000
2693
2694 #define CONTEXT_CONTROL (CONTEXT_AMD64 | 0x1L)
2695 #define CONTEXT_INTEGER (CONTEXT_AMD64 | 0x2L)
2696 #define CONTEXT_SEGMENTS (CONTEXT_AMD64 | 0x4L)
2697 #define CONTEXT_FLOATING_POINT  (CONTEXT_AMD64 | 0x8L)
2698 #define CONTEXT_DEBUG_REGISTERS (CONTEXT_AMD64 | 0x10L)
2699
2700 #define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_FLOATING_POINT)
2701
2702 #define CONTEXT_ALL (CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_SEGMENTS | CONTEXT_FLOATING_POINT | CONTEXT_DEBUG_REGISTERS)
2703
2704 #define CONTEXT_EXCEPTION_ACTIVE 0x8000000
2705 #define CONTEXT_SERVICE_ACTIVE 0x10000000
2706 #define CONTEXT_EXCEPTION_REQUEST 0x40000000
2707 #define CONTEXT_EXCEPTION_REPORTING 0x80000000
2708
2709 typedef struct DECLSPEC_ALIGN(16) _M128A {
2710     ULONGLONG Low;
2711     LONGLONG High;
2712 } M128A, *PM128A;
2713
2714 typedef struct _XMM_SAVE_AREA32 {
2715     WORD   ControlWord;
2716     WORD   StatusWord;
2717     BYTE  TagWord;
2718     BYTE  Reserved1;
2719     WORD   ErrorOpcode;
2720     DWORD ErrorOffset;
2721     WORD   ErrorSelector;
2722     WORD   Reserved2;
2723     DWORD DataOffset;
2724     WORD   DataSelector;
2725     WORD   Reserved3;
2726     DWORD MxCsr;
2727     DWORD MxCsr_Mask;
2728     M128A FloatRegisters[8];
2729     M128A XmmRegisters[16];
2730     BYTE  Reserved4[96];
2731 } XMM_SAVE_AREA32, *PXMM_SAVE_AREA32;
2732
2733 #define LEGACY_SAVE_AREA_LENGTH sizeof(XMM_SAVE_AREA32)
2734
2735 //
2736 // Context Frame
2737 //
2738 //  This frame has a several purposes: 1) it is used as an argument to
2739 //  NtContinue, 2) is is used to constuct a call frame for APC delivery,
2740 //  and 3) it is used in the user level thread creation routines.
2741 //
2742 //
2743 // The flags field within this record controls the contents of a CONTEXT
2744 // record.
2745 //
2746 // If the context record is used as an input parameter, then for each
2747 // portion of the context record controlled by a flag whose value is
2748 // set, it is assumed that that portion of the context record contains
2749 // valid context. If the context record is being used to modify a threads
2750 // context, then only that portion of the threads context is modified.
2751 //
2752 // If the context record is used as an output parameter to capture the
2753 // context of a thread, then only those portions of the thread's context
2754 // corresponding to set flags will be returned.
2755 //
2756 // CONTEXT_CONTROL specifies SegSs, Rsp, SegCs, Rip, and EFlags.
2757 //
2758 // CONTEXT_INTEGER specifies Rax, Rcx, Rdx, Rbx, Rbp, Rsi, Rdi, and R8-R15.
2759 //
2760 // CONTEXT_SEGMENTS specifies SegDs, SegEs, SegFs, and SegGs.
2761 //
2762 // CONTEXT_DEBUG_REGISTERS specifies Dr0-Dr3 and Dr6-Dr7.
2763 //
2764 // CONTEXT_MMX_REGISTERS specifies the floating point and extended registers
2765 //     Mm0/St0-Mm7/St7 and Xmm0-Xmm15).
2766 //
2767
2768 typedef struct DECLSPEC_ALIGN(16) _CONTEXT {
2769
2770     //
2771     // Register parameter home addresses.
2772     //
2773     // N.B. These fields are for convience - they could be used to extend the
2774     //      context record in the future.
2775     //
2776
2777     DWORD64 P1Home;
2778     DWORD64 P2Home;
2779     DWORD64 P3Home;
2780     DWORD64 P4Home;
2781     DWORD64 P5Home;
2782     DWORD64 P6Home;
2783
2784     //
2785     // Control flags.
2786     //
2787
2788     DWORD ContextFlags;
2789     DWORD MxCsr;
2790
2791     //
2792     // Segment Registers and processor flags.
2793     //
2794
2795     WORD   SegCs;
2796     WORD   SegDs;
2797     WORD   SegEs;
2798     WORD   SegFs;
2799     WORD   SegGs;
2800     WORD   SegSs;
2801     DWORD EFlags;
2802
2803     //
2804     // Debug registers
2805     //
2806
2807     DWORD64 Dr0;
2808     DWORD64 Dr1;
2809     DWORD64 Dr2;
2810     DWORD64 Dr3;
2811     DWORD64 Dr6;
2812     DWORD64 Dr7;
2813
2814     //
2815     // Integer registers.
2816     //
2817
2818     DWORD64 Rax;
2819     DWORD64 Rcx;
2820     DWORD64 Rdx;
2821     DWORD64 Rbx;
2822     DWORD64 Rsp;
2823     DWORD64 Rbp;
2824     DWORD64 Rsi;
2825     DWORD64 Rdi;
2826     DWORD64 R8;
2827     DWORD64 R9;
2828     DWORD64 R10;
2829     DWORD64 R11;
2830     DWORD64 R12;
2831     DWORD64 R13;
2832     DWORD64 R14;
2833     DWORD64 R15;
2834
2835     //
2836     // Program counter.
2837     //
2838
2839     DWORD64 Rip;
2840
2841     //
2842     // Floating point state.
2843     //
2844
2845     union {
2846         XMM_SAVE_AREA32 FltSave;
2847         struct {
2848             M128A Header[2];
2849             M128A Legacy[8];
2850             M128A Xmm0;
2851             M128A Xmm1;
2852             M128A Xmm2;
2853             M128A Xmm3;
2854             M128A Xmm4;
2855             M128A Xmm5;
2856             M128A Xmm6;
2857             M128A Xmm7;
2858             M128A Xmm8;
2859             M128A Xmm9;
2860             M128A Xmm10;
2861             M128A Xmm11;
2862             M128A Xmm12;
2863             M128A Xmm13;
2864             M128A Xmm14;
2865             M128A Xmm15;
2866         };
2867     };
2868
2869     //
2870     // Vector registers.
2871     //
2872
2873     M128A VectorRegister[26];
2874     DWORD64 VectorControl;
2875
2876     //
2877     // Special debug control registers.
2878     //
2879
2880     DWORD64 DebugControl;
2881     DWORD64 LastBranchToRip;
2882     DWORD64 LastBranchFromRip;
2883     DWORD64 LastExceptionToRip;
2884     DWORD64 LastExceptionFromRip;
2885 } CONTEXT, *PCONTEXT, *LPCONTEXT;
2886
2887 //
2888 // Nonvolatile context pointer record.
2889 //
2890
2891 typedef struct _KNONVOLATILE_CONTEXT_POINTERS {
2892     union {
2893         PM128A FloatingContext[16];
2894         struct {
2895             PM128A Xmm0;
2896             PM128A Xmm1;
2897             PM128A Xmm2;
2898             PM128A Xmm3;
2899             PM128A Xmm4;
2900             PM128A Xmm5;
2901             PM128A Xmm6;
2902             PM128A Xmm7;
2903             PM128A Xmm8;
2904             PM128A Xmm9;
2905             PM128A Xmm10;
2906             PM128A Xmm11;
2907             PM128A Xmm12;
2908             PM128A Xmm13;
2909             PM128A Xmm14;
2910             PM128A Xmm15;
2911         } ;
2912     } ;
2913
2914     union {
2915         PDWORD64 IntegerContext[16];
2916         struct {
2917             PDWORD64 Rax;
2918             PDWORD64 Rcx;
2919             PDWORD64 Rdx;
2920             PDWORD64 Rbx;
2921             PDWORD64 Rsp;
2922             PDWORD64 Rbp;
2923             PDWORD64 Rsi;
2924             PDWORD64 Rdi;
2925             PDWORD64 R8;
2926             PDWORD64 R9;
2927             PDWORD64 R10;
2928             PDWORD64 R11;
2929             PDWORD64 R12;
2930             PDWORD64 R13;
2931             PDWORD64 R14;
2932             PDWORD64 R15;
2933         } ;
2934     } ;
2935
2936 } KNONVOLATILE_CONTEXT_POINTERS, *PKNONVOLATILE_CONTEXT_POINTERS;
2937
2938 #else
2939 #error Unknown architecture for defining CONTEXT.
2940 #endif
2941
2942
2943 PALIMPORT
2944 BOOL
2945 PALAPI
2946 GetThreadContext(
2947          IN HANDLE hThread,
2948          IN OUT LPCONTEXT lpContext);
2949
2950 PALIMPORT
2951 BOOL
2952 PALAPI
2953 SetThreadContext(
2954          IN HANDLE hThread,
2955          IN CONST CONTEXT *lpContext);
2956
2957 #define THREAD_BASE_PRIORITY_LOWRT    15
2958 #define THREAD_BASE_PRIORITY_MAX      2
2959 #define THREAD_BASE_PRIORITY_MIN      (-2)
2960 #define THREAD_BASE_PRIORITY_IDLE     (-15)
2961
2962 #define THREAD_PRIORITY_LOWEST        THREAD_BASE_PRIORITY_MIN
2963 #define THREAD_PRIORITY_BELOW_NORMAL  (THREAD_PRIORITY_LOWEST+1)
2964 #define THREAD_PRIORITY_NORMAL        0
2965 #define THREAD_PRIORITY_HIGHEST       THREAD_BASE_PRIORITY_MAX
2966 #define THREAD_PRIORITY_ABOVE_NORMAL  (THREAD_PRIORITY_HIGHEST-1)
2967 #define THREAD_PRIORITY_ERROR_RETURN  (MAXLONG)
2968
2969 #define THREAD_PRIORITY_TIME_CRITICAL THREAD_BASE_PRIORITY_LOWRT
2970 #define THREAD_PRIORITY_IDLE          THREAD_BASE_PRIORITY_IDLE
2971
2972 PALIMPORT
2973 int
2974 PALAPI
2975 GetThreadPriority(
2976           IN HANDLE hThread);
2977
2978 PALIMPORT
2979 BOOL
2980 PALAPI
2981 SetThreadPriority(
2982           IN HANDLE hThread,
2983           IN int nPriority);
2984
2985 PALIMPORT
2986 BOOL
2987 PALAPI
2988 GetThreadTimes(
2989         IN HANDLE hThread,
2990         OUT LPFILETIME lpCreationTime,
2991         OUT LPFILETIME lpExitTime,
2992         OUT LPFILETIME lpKernelTime,
2993         OUT LPFILETIME lpUserTime);
2994                 
2995 #define TLS_OUT_OF_INDEXES ((DWORD)0xFFFFFFFF)
2996
2997 PALIMPORT
2998 DWORD
2999 PALAPI
3000 TlsAlloc(
3001      VOID);
3002
3003 PALIMPORT
3004 LPVOID
3005 PALAPI
3006 TlsGetValue(
3007         IN DWORD dwTlsIndex);
3008
3009 PALIMPORT
3010 BOOL
3011 PALAPI
3012 TlsSetValue(
3013         IN DWORD dwTlsIndex,
3014         IN LPVOID lpTlsValue);
3015
3016 PALIMPORT
3017 BOOL
3018 PALAPI
3019 TlsFree(
3020     IN DWORD dwTlsIndex);
3021
3022 PALIMPORT
3023 void *
3024 PALAPI
3025 PAL_GetStackBase();
3026
3027 PALIMPORT
3028 void *
3029 PALAPI
3030 PAL_GetStackLimit();
3031
3032 #ifdef PLATFORM_UNIX
3033
3034 #if defined(__FreeBSD__) && defined(_X86_)
3035 #define PAL_CS_NATIVE_DATA_SIZE 12
3036 #elif defined(__sun__)
3037 #define PAL_CS_NATIVE_DATA_SIZE 48
3038 #elif defined(__hpux__) && (defined(__hppa__) || defined (__ia64__))
3039 #define PAL_CS_NATIVE_DATA_SIZE 148
3040 #elif defined(_AIX)
3041 #define PAL_CS_NATIVE_DATA_SIZE 100
3042 #elif defined(__APPLE__) && defined(__i386__)
3043 #define PAL_CS_NATIVE_DATA_SIZE 76
3044 #elif defined(__APPLE__) && defined(__x86_64__)
3045 #define PAL_CS_NATIVE_DATA_SIZE 120
3046 #elif defined(__LINUX__) && defined(__x86_64__)
3047 #define PAL_CS_NATIVE_DATA_SIZE 96
3048 #else 
3049 #error  PAL_CS_NATIVE_DATA_SIZE is not defined for this architecture
3050 #endif
3051     
3052 #endif // PLATFORM_UNIX
3053
3054 // 
3055 typedef struct _CRITICAL_SECTION {
3056     PVOID DebugInfo;
3057     LONG LockCount;
3058     LONG RecursionCount;
3059     HANDLE OwningThread;
3060     HANDLE LockSemaphore;
3061     ULONG_PTR SpinCount;
3062
3063 #ifdef PLATFORM_UNIX
3064     BOOL bInternal;
3065     volatile DWORD dwInitState;
3066     union CSNativeDataStorage
3067     {
3068         BYTE rgNativeDataStorage[PAL_CS_NATIVE_DATA_SIZE]; 
3069         VOID * pvAlign; // make sure the storage is machine-pointer-size aligned
3070     } csnds;    
3071 #endif // PLATFORM_UNIX    
3072 } CRITICAL_SECTION, *PCRITICAL_SECTION, *LPCRITICAL_SECTION;
3073
3074 PALIMPORT VOID PALAPI EnterCriticalSection(IN OUT LPCRITICAL_SECTION lpCriticalSection);
3075 PALIMPORT VOID PALAPI LeaveCriticalSection(IN OUT LPCRITICAL_SECTION lpCriticalSection);
3076 PALIMPORT VOID PALAPI InitializeCriticalSection(OUT LPCRITICAL_SECTION lpCriticalSection);
3077 PALIMPORT VOID PALAPI DeleteCriticalSection(IN OUT LPCRITICAL_SECTION lpCriticalSection);
3078 PALIMPORT BOOL PALAPI TryEnterCriticalSection(IN OUT LPCRITICAL_SECTION lpCriticalSection);
3079
3080 #define SEM_FAILCRITICALERRORS          0x0001
3081 #define SEM_NOOPENFILEERRORBOX          0x8000
3082
3083 PALIMPORT
3084 UINT
3085 PALAPI
3086 SetErrorMode(
3087          IN UINT uMode);
3088
3089 #define PAGE_NOACCESS                   0x01
3090 #define PAGE_READONLY                   0x02
3091 #define PAGE_READWRITE                  0x04
3092 #define PAGE_WRITECOPY                  0x08
3093 #define PAGE_EXECUTE                    0x10
3094 #define PAGE_EXECUTE_READ               0x20
3095 #define PAGE_EXECUTE_READWRITE          0x40
3096 #define PAGE_EXECUTE_WRITECOPY          0x80
3097 #define MEM_COMMIT                      0x1000
3098 #define MEM_RESERVE                     0x2000
3099 #define MEM_DECOMMIT                    0x4000
3100 #define MEM_RELEASE                     0x8000
3101 #define MEM_FREE                        0x10000
3102 #define MEM_PRIVATE                     0x20000
3103 #define MEM_MAPPED                      0x40000
3104 #define MEM_TOP_DOWN                    0x100000
3105 #define MEM_WRITE_WATCH                 0x200000
3106
3107 PALIMPORT
3108 HANDLE
3109 PALAPI
3110 CreateFileMappingA(
3111            IN HANDLE hFile,
3112            IN LPSECURITY_ATTRIBUTES lpFileMappingAttributes,
3113            IN DWORD flProtect,
3114            IN DWORD dwMaximumSizeHigh,
3115            IN DWORD dwMaximumSizeLow,
3116            IN LPCSTR lpName);
3117
3118 PALIMPORT
3119 HANDLE
3120 PALAPI
3121 CreateFileMappingW(
3122            IN HANDLE hFile,
3123            IN LPSECURITY_ATTRIBUTES lpFileMappingAttributes,
3124            IN DWORD flProtect,
3125            IN DWORD dwMaxmimumSizeHigh,
3126            IN DWORD dwMaximumSizeLow,
3127            IN LPCWSTR lpName);
3128
3129 #ifdef UNICODE
3130 #define CreateFileMapping CreateFileMappingW
3131 #else
3132 #define CreateFileMapping CreateFileMappingA
3133 #endif
3134
3135 #define SECTION_QUERY       0x0001
3136 #define SECTION_MAP_WRITE   0x0002
3137 #define SECTION_MAP_READ    0x0004
3138 #define SECTION_ALL_ACCESS  (SECTION_MAP_READ | SECTION_MAP_WRITE) // diff from winnt.h
3139
3140 #define FILE_MAP_WRITE      SECTION_MAP_WRITE
3141 #define FILE_MAP_READ       SECTION_MAP_READ
3142 #define FILE_MAP_ALL_ACCESS SECTION_ALL_ACCESS
3143 #define FILE_MAP_COPY       SECTION_QUERY
3144
3145 PALIMPORT
3146 HANDLE
3147 PALAPI
3148 OpenFileMappingA(
3149          IN DWORD dwDesiredAccess,
3150          IN BOOL bInheritHandle,
3151          IN LPCSTR lpName);
3152
3153 PALIMPORT
3154 HANDLE
3155 PALAPI
3156 OpenFileMappingW(
3157          IN DWORD dwDesiredAccess,
3158          IN BOOL bInheritHandle,
3159          IN LPCWSTR lpName);
3160
3161 #ifdef UNICODE
3162 #define OpenFileMapping OpenFileMappingW
3163 #else
3164 #define OpenFileMapping OpenFileMappingA
3165 #endif
3166
3167 PALIMPORT
3168 LPVOID
3169 PALAPI
3170 MapViewOfFile(
3171           IN HANDLE hFileMappingObject,
3172           IN DWORD dwDesiredAccess,
3173           IN DWORD dwFileOffsetHigh,
3174           IN DWORD dwFileOffsetLow,
3175           IN SIZE_T dwNumberOfBytesToMap);
3176
3177 PALIMPORT
3178 LPVOID
3179 PALAPI
3180 MapViewOfFileEx(
3181           IN HANDLE hFileMappingObject,
3182           IN DWORD dwDesiredAccess,
3183           IN DWORD dwFileOffsetHigh,
3184           IN DWORD dwFileOffsetLow,
3185           IN SIZE_T dwNumberOfBytesToMap,
3186           IN LPVOID lpBaseAddress);
3187           
3188 PALIMPORT
3189 BOOL
3190 PALAPI
3191 FlushViewOfFile(
3192         IN LPVOID lpBaseAddress,
3193         IN SIZE_T dwNumberOfBytesToFlush);
3194
3195 PALIMPORT
3196 BOOL
3197 PALAPI
3198 UnmapViewOfFile(
3199         IN LPCVOID lpBaseAddress);
3200
3201 PALIMPORT
3202 HMODULE
3203 PALAPI
3204 LoadLibraryA(
3205          IN LPCSTR lpLibFileName);
3206
3207 PALIMPORT
3208 HMODULE
3209 PALAPI
3210 LoadLibraryW(
3211          IN LPCWSTR lpLibFileName);
3212
3213 PALIMPORT
3214 HMODULE
3215 PALAPI
3216 LoadLibraryExA(
3217         IN LPCSTR lpLibFileName,
3218         IN /*Reserved*/ HANDLE hFile,
3219         IN DWORD dwFlags);
3220
3221 PALIMPORT
3222 HMODULE
3223 PALAPI
3224 LoadLibraryExW(
3225         IN LPCWSTR lpLibFileName,
3226         IN /*Reserved*/ HANDLE hFile,
3227         IN DWORD dwFlags);
3228
3229 /*++
3230 Function:
3231   PAL_LOADLoadPEFile
3232
3233 Abstract
3234   Loads a PE file into memory.  Properly maps all of the sections in the PE file.  Returns a pointer to the
3235   loaded base.
3236
3237 Parameters:
3238     IN hFile    - The file to load
3239
3240 Return value:
3241     A valid base address if successful.
3242     0 if failure
3243 --*/
3244 void * PAL_LOADLoadPEFile(HANDLE hFile);
3245
3246 /*++
3247     PAL_LOADUnloadPEFile
3248
3249     Unload a PE file that was loaded by PAL_LOADLoadPEFile().
3250
3251 Parameters:
3252     IN ptr - the file pointer returned by PAL_LOADLoadPEFile()
3253
3254 Return value:
3255     TRUE - success
3256     FALSE - failure (incorrect ptr, etc.)
3257 --*/
3258
3259 BOOL PAL_LOADUnloadPEFile(void * ptr);
3260
3261
3262 #ifdef UNICODE
3263 #define LoadLibrary LoadLibraryW
3264 #define LoadLibraryEx LoadLibraryExW
3265 #else
3266 #define LoadLibrary LoadLibraryA
3267 #define LoadLibraryEx LoadLibraryExA
3268 #endif
3269
3270 typedef INT_PTR (PALAPI *FARPROC)();
3271
3272 PALIMPORT
3273 FARPROC
3274 PALAPI
3275 GetProcAddress(
3276            IN HMODULE hModule,
3277            IN LPCSTR lpProcName);
3278
3279 PALIMPORT
3280 BOOL
3281 PALAPI
3282 FreeLibrary(
3283         IN OUT HMODULE hLibModule);
3284
3285 PALIMPORT
3286 PAL_NORETURN
3287 VOID
3288 PALAPI
3289 FreeLibraryAndExitThread(
3290              IN HMODULE hLibModule,
3291              IN DWORD dwExitCode);
3292
3293 PALIMPORT
3294 BOOL
3295 PALAPI
3296 DisableThreadLibraryCalls(
3297     IN HMODULE hLibModule);
3298
3299 PALIMPORT
3300 DWORD
3301 PALAPI
3302 GetModuleFileNameA(
3303            IN HMODULE hModule,
3304            OUT LPSTR lpFileName,
3305            IN DWORD nSize);
3306
3307 PALIMPORT
3308 DWORD
3309 PALAPI
3310 GetModuleFileNameW(
3311            IN HMODULE hModule,
3312            OUT LPWSTR lpFileName,
3313            IN DWORD nSize);
3314
3315 #ifdef UNICODE
3316 #define GetModuleFileName GetModuleFileNameW
3317 #else
3318 #define GetModuleFileName GetModuleFileNameA
3319 #endif
3320
3321 // Get base address of the coreclr module
3322 PALAPI
3323 LPCVOID
3324 PAL_GetCoreClrModuleBase();
3325
3326 PALIMPORT
3327 LPVOID
3328 PALAPI
3329 VirtualAlloc(
3330          IN LPVOID lpAddress,
3331          IN SIZE_T dwSize,
3332          IN DWORD flAllocationType,
3333          IN DWORD flProtect);
3334
3335 PALIMPORT
3336 BOOL
3337 PALAPI
3338 VirtualFree(
3339         IN LPVOID lpAddress,
3340         IN SIZE_T dwSize,
3341         IN DWORD dwFreeType);
3342
3343 PALIMPORT
3344 BOOL
3345 PALAPI
3346 VirtualProtect(
3347            IN LPVOID lpAddress,
3348            IN SIZE_T dwSize,
3349            IN DWORD flNewProtect,
3350            OUT PDWORD lpflOldProtect);
3351
3352 #if defined(_AMD64_)
3353 typedef struct _MEMORYSTATUSEX {
3354   DWORD     dwLength;
3355   DWORD     dwMemoryLoad;
3356   DWORDLONG ullTotalPhys;
3357   DWORDLONG ullAvailPhys;
3358   DWORDLONG ullTotalPageFile;
3359   DWORDLONG ullAvailPageFile;
3360   DWORDLONG ullTotalVirtual;
3361   DWORDLONG ullAvailVirtual;
3362   DWORDLONG ullAvailExtendedVirtual;
3363 } MEMORYSTATUSEX, *LPMEMORYSTATUSEX;
3364
3365 PALIMPORT 
3366 BOOL
3367 PALAPI
3368 GlobalMemoryStatusEx(
3369             IN OUT LPMEMORYSTATUSEX lpBuffer);
3370
3371 #endif // _AMD64_
3372
3373 typedef struct _MEMORY_BASIC_INFORMATION {
3374     PVOID BaseAddress;
3375     PVOID AllocationBase_PAL_Undefined;
3376     DWORD AllocationProtect;
3377     SIZE_T RegionSize;
3378     DWORD State;
3379     DWORD Protect;
3380     DWORD Type;
3381 } MEMORY_BASIC_INFORMATION, *PMEMORY_BASIC_INFORMATION;
3382
3383 PALIMPORT
3384 SIZE_T
3385 PALAPI
3386 VirtualQuery(
3387          IN LPCVOID lpAddress,
3388          OUT PMEMORY_BASIC_INFORMATION lpBuffer,
3389          IN SIZE_T dwLength);
3390
3391 PALIMPORT
3392 BOOL
3393 PALAPI
3394 ReadProcessMemory(
3395           IN HANDLE hProcess,
3396           IN LPCVOID lpBaseAddress,
3397           OUT LPVOID lpBuffer,
3398           IN SIZE_T nSize,
3399           OUT SIZE_T * lpNumberOfBytesRead);
3400
3401 PALIMPORT
3402 VOID
3403 PALAPI
3404 RtlMoveMemory(
3405           IN PVOID Destination,
3406           IN CONST VOID *Source,
3407           IN SIZE_T Length);
3408
3409 PALIMPORT
3410 VOID
3411 PALAPI
3412 RtlZeroMemory(
3413     IN PVOID Destination,
3414     IN SIZE_T Length);
3415
3416 #define MoveMemory memmove
3417 #define CopyMemory memcpy
3418 #define FillMemory(Destination,Length,Fill) memset((Destination),(Fill),(Length))
3419 #define ZeroMemory(Destination,Length) memset((Destination),0,(Length))
3420
3421
3422 PALIMPORT
3423 HANDLE
3424 PALAPI
3425 GetProcessHeap(
3426            VOID);
3427
3428 #define HEAP_ZERO_MEMORY 0x00000008
3429
3430 #ifdef __APPLE__
3431 PALIMPORT
3432 HANDLE
3433 PALAPI
3434 HeapCreate(
3435                IN DWORD flOptions,
3436                IN SIZE_T dwInitialSize,
3437                IN SIZE_T dwMaximumSize);
3438 #endif // __APPLE__
3439
3440 PALIMPORT
3441 LPVOID
3442 PALAPI
3443 HeapAlloc(
3444       IN HANDLE hHeap,
3445       IN DWORD dwFlags,
3446       IN SIZE_T dwBytes);
3447
3448 PALIMPORT
3449 LPVOID
3450 PALAPI
3451 HeapReAlloc(
3452     IN HANDLE hHeap,
3453     IN DWORD dwFlags,
3454     IN LPVOID lpMem,
3455     IN SIZE_T dwBytes
3456     );
3457
3458 PALIMPORT
3459 BOOL
3460 PALAPI
3461 HeapFree(
3462      IN HANDLE hHeap,
3463      IN DWORD dwFlags,
3464      IN LPVOID lpMem);
3465
3466 typedef enum _HEAP_INFORMATION_CLASS {
3467     HeapCompatibilityInformation,
3468     HeapEnableTerminationOnCorruption
3469 } HEAP_INFORMATION_CLASS;
3470
3471 PALIMPORT
3472 BOOL
3473 PALAPI
3474 HeapSetInformation(
3475         IN OPTIONAL HANDLE HeapHandle,
3476         IN HEAP_INFORMATION_CLASS HeapInformationClass,
3477         IN PVOID HeapInformation,
3478         IN SIZE_T HeapInformationLength);
3479
3480 #define LMEM_FIXED          0x0000
3481 #define LMEM_ZEROINIT       0x0040
3482 #define LPTR                (LMEM_FIXED | LMEM_ZEROINIT)
3483
3484 PALIMPORT
3485 HLOCAL
3486 PALAPI
3487 LocalAlloc(
3488        IN UINT uFlags,
3489        IN SIZE_T uBytes);
3490
3491 PALIMPORT
3492 HLOCAL
3493 PALAPI
3494 LocalFree(
3495       IN HLOCAL hMem);
3496
3497 PALIMPORT
3498 BOOL
3499 PALAPI
3500 FlushInstructionCache(
3501               IN HANDLE hProcess,
3502               IN LPCVOID lpBaseAddress,
3503               IN SIZE_T dwSize);
3504
3505 #if ENABLE_DOWNLEVEL_FOR_NLS
3506
3507 PALIMPORT
3508 BOOL
3509 PALAPI
3510 GetStringTypeExW(
3511          IN LCID Locale,
3512          IN DWORD dwInfoType,
3513          IN LPCWSTR lpSrcStr,
3514          IN int cchSrc,
3515          OUT LPWORD lpCharType);
3516
3517 #ifdef UNICODE
3518 #define GetStringTypeEx GetStringTypeExW
3519 #endif
3520
3521 #endif // ENABLE_DOWNLEVEL_FOR_NLS
3522
3523
3524 #define NORM_IGNORECASE           0x00000001  // ignore case
3525 #define NORM_IGNOREWIDTH          0x00020000  // ignore width
3526
3527 #define NORM_LINGUISTIC_CASING    0x08000000  // use linguistic rules for casing
3528
3529 #ifdef __APPLE__
3530 #define NORM_IGNORENONSPACE       0x00000002  // ignore nonspacing chars
3531 #define NORM_IGNORESYMBOLS        0x00000004  // ignore symbols
3532 #define NORM_IGNOREKANATYPE       0x00010000  // ignore kanatype
3533 #define SORT_STRINGSORT           0x00001000  // use string sort method
3534 #endif // __APPLE__
3535
3536
3537 typedef struct nlsversioninfo { 
3538   DWORD     dwNLSVersionInfoSize; 
3539   DWORD     dwNLSVersion; 
3540   DWORD     dwDefinedVersion; 
3541 } NLSVERSIONINFO, *LPNLSVERSIONINFO; 
3542
3543 #define CSTR_LESS_THAN     1
3544 #define CSTR_EQUAL         2
3545 #define CSTR_GREATER_THAN  3
3546
3547 #if ENABLE_DOWNLEVEL_FOR_NLS
3548
3549
3550 PALIMPORT
3551 int
3552 PALAPI
3553 CompareStringA(
3554     IN LCID     Locale,
3555     IN DWORD    dwCmpFlags,
3556     IN LPCSTR   lpString1,
3557     IN int      cchCount1,
3558     IN LPCSTR   lpString2,
3559     IN int      cchCount2);
3560
3561 PALIMPORT
3562 int
3563 PALAPI
3564 CompareStringW(
3565     IN LCID     Locale,
3566     IN DWORD    dwCmpFlags,
3567     IN LPCWSTR  lpString1,
3568     IN int      cchCount1,
3569     IN LPCWSTR  lpString2,
3570     IN int      cchCount2);
3571
3572 #endif // ENABLE_DOWNLEVEL_FOR_NLS
3573
3574
3575 PALIMPORT
3576 int
3577 PALAPI
3578 CompareStringEx(
3579     IN LPCWSTR lpLocaleName,
3580     IN DWORD    dwCmpFlags,
3581     IN LPCWSTR  lpString1,
3582     IN int      cchCount1,
3583     IN LPCWSTR  lpString2,
3584     IN int      cchCount2,
3585     IN LPNLSVERSIONINFO lpVersionInformation,
3586     IN LPVOID lpReserved,
3587     IN LPARAM lParam);
3588
3589
3590 #ifdef UNICODE
3591 #define CompareString  CompareStringW
3592 #endif
3593
3594 #define MAX_LEADBYTES         12
3595 #define MAX_DEFAULTCHAR       2
3596
3597 PALIMPORT
3598 UINT
3599 PALAPI
3600 GetACP(void);
3601
3602 typedef struct _cpinfo {
3603     UINT MaxCharSize;
3604     BYTE DefaultChar[MAX_DEFAULTCHAR];
3605     BYTE LeadByte[MAX_LEADBYTES];
3606 } CPINFO, *LPCPINFO;
3607
3608 PALIMPORT
3609 BOOL
3610 PALAPI
3611 GetCPInfo(
3612       IN UINT CodePage,
3613       OUT LPCPINFO lpCPInfo);
3614
3615 PALIMPORT
3616 BOOL
3617 PALAPI
3618 IsDBCSLeadByteEx(
3619          IN UINT CodePage,
3620          IN BYTE TestChar);
3621
3622 PALIMPORT
3623 BOOL
3624 PALAPI
3625 IsDBCSLeadByte(
3626         IN BYTE TestChar);
3627
3628 PALIMPORT
3629 BOOL
3630 PALAPI
3631 IsValidCodePage(
3632         IN UINT CodePage);
3633         
3634
3635 #define MB_PRECOMPOSED            0x00000001
3636 #define MB_ERR_INVALID_CHARS      0x00000008
3637
3638 PALIMPORT
3639 int
3640 PALAPI
3641 MultiByteToWideChar(
3642             IN UINT CodePage,
3643             IN DWORD dwFlags,
3644             IN LPCSTR lpMultiByteStr,
3645             IN int cbMultiByte,
3646             OUT LPWSTR lpWideCharStr,
3647             IN int cchWideChar);
3648
3649 #define WC_NO_BEST_FIT_CHARS      0x00000400
3650
3651 PALIMPORT
3652 int
3653 PALAPI
3654 WideCharToMultiByte(
3655             IN UINT CodePage,
3656             IN DWORD dwFlags,
3657             IN LPCWSTR lpWideCharStr,
3658             IN int cchWideChar,
3659             OUT LPSTR lpMultiByteStr,
3660             IN int cbMultyByte,
3661             IN LPCSTR lpDefaultChar,
3662             OUT LPBOOL lpUsedDefaultChar);
3663
3664 #if ENABLE_DOWNLEVEL_FOR_NLS
3665
3666 PALIMPORT
3667 LANGID
3668 PALAPI
3669 GetSystemDefaultLangID(
3670                void);
3671
3672 PALIMPORT
3673 LANGID
3674 PALAPI
3675 GetUserDefaultLangID(
3676              void);
3677
3678 PALIMPORT
3679 BOOL
3680 PALAPI
3681 SetThreadLocale(
3682         IN LCID Locale);
3683
3684 PALIMPORT
3685 LCID
3686 PALAPI
3687 GetThreadLocale(
3688         void);
3689
3690 #endif //ENABLE_DOWNLEVEL_FOR_NLS
3691
3692 //
3693 //  Locale Types.
3694 //
3695 //  These types are used for the GetLocaleInfo NLS API routine.
3696 //
3697
3698 #ifdef __APPLE__
3699
3700 //
3701 //  The following LCTypes may be used in combination with any other LCTypes.
3702 //
3703 //    LOCALE_NOUSEROVERRIDE is also used in GetTimeFormat and
3704 //    GetDateFormat.
3705 //
3706 //    LOCALE_RETURN_NUMBER will return the result from GetLocaleInfo as a
3707 //    number instead of a string.  This flag is only valid for the LCTypes
3708 //    beginning with LOCALE_I.
3709 //
3710 #define LOCALE_NOUSEROVERRIDE         0x80000000    /* do not use user overrides */
3711 #define LOCALE_RETURN_NUMBER          0x20000000    /* return number instead of string */
3712 #define LOCALE_RETURN_GENITIVE_NAMES  0x10000000   //Flag to return the Genitive forms of month names
3713
3714 #define LOCALE_SLOCALIZEDDISPLAYNAME  0x00000002   // localized name of locale, eg "German (Germany)" in UI language
3715 #define LOCALE_SENGLISHDISPLAYNAME    0x00000072   // Display name (language + country usually) in English, eg "German (Germany)"
3716 #define LOCALE_SNATIVEDISPLAYNAME     0x00000073   // Display name in native locale language, eg "Deutsch (Deutschland)
3717
3718 #define LOCALE_SLOCALIZEDLANGUAGENAME 0x0000006f   // Language Display Name for a language, eg "German" in UI language
3719 #define LOCALE_SENGLISHLANGUAGENAME   0x00001001   // English name of language, eg "German"
3720 #define LOCALE_SNATIVELANGUAGENAME    0x00000004   // native name of language, eg "Deutsch"
3721
3722 #define LOCALE_SLOCALIZEDCOUNTRYNAME  0x00000006   // localized name of country, eg "Germany" in UI language
3723 #define LOCALE_SENGLISHCOUNTRYNAME    0x00001002   // English name of country, eg "Germany"
3724 #define LOCALE_SNATIVECOUNTRYNAME     0x00000008   // native name of country, eg "Deutschland"
3725
3726 //
3727 //  The following LCTypes are mutually exclusive in that they may NOT
3728 //  be used in combination with each other.
3729 //
3730 #define LOCALE_ILANGUAGE              0x00000001    /* language id */
3731 #define LOCALE_SLANGUAGE              0x00000002    /* localized name of language */
3732 #define LOCALE_SENGLANGUAGE           0x00001001    /* English name of language */
3733 #define LOCALE_SABBREVLANGNAME        0x00000003    /* abbreviated language name */
3734 #define LOCALE_SNATIVELANGNAME        0x00000004    /* native name of language */
3735 #define LOCALE_ICOUNTRY               0x00000005    /* country code */
3736 #define LOCALE_SCOUNTRY               0x00000006    /* localized name of country */
3737
3738 #define LOCALE_SENGCOUNTRY            0x00001002    /* English name of country */
3739 #define LOCALE_SABBREVCTRYNAME        0x00000007    /* abbreviated country name */
3740 #define LOCALE_SNATIVECTRYNAME        0x00000008    /* native name of country */
3741
3742 #define LOCALE_SLIST                  0x0000000C    /* list item separator */
3743 #define LOCALE_IMEASURE               0x0000000D    /* 0 = metric, 1 = US */
3744
3745 #define LOCALE_SDECIMAL               0x0000000E    /* decimal separator */
3746 #define LOCALE_STHOUSAND              0x0000000F    /* thousand separator */
3747 #define LOCALE_SGROUPING              0x00000010    /* digit grouping */
3748 #define LOCALE_IDIGITS                0x00000011    /* number of fractional digits */
3749 #define LOCALE_ILZERO                 0x00000012    /* leading zeros for decimal */
3750 #define LOCALE_INEGNUMBER             0x00001010    /* negative number mode */
3751 #define LOCALE_SNATIVEDIGITS          0x00000013    /* native ascii 0-9 */
3752
3753 #define LOCALE_SCURRENCY              0x00000014    /* local monetary symbol */
3754 #define LOCALE_SINTLSYMBOL            0x00000015    /* intl monetary symbol */
3755 #define LOCALE_SMONDECIMALSEP         0x00000016    /* monetary decimal separator */
3756 #define LOCALE_SMONTHOUSANDSEP        0x00000017    /* monetary thousand separator */
3757 #define LOCALE_SMONGROUPING           0x00000018    /* monetary grouping */
3758 #define LOCALE_ICURRDIGITS            0x00000019    /* # local monetary digits */
3759 #define LOCALE_IINTLCURRDIGITS        0x0000001A    /* # intl monetary digits */
3760 #define LOCALE_ICURRENCY              0x0000001B    /* positive currency mode */
3761 #define LOCALE_INEGCURR               0x0000001C    /* negative currency mode */
3762
3763 #define LOCALE_SSHORTDATE             0x0000001F    /* short date format string */
3764 #define LOCALE_SLONGDATE              0x00000020    /* long date format string */
3765 #define LOCALE_STIMEFORMAT            0x00001003    /* time format string */
3766 #define LOCALE_S1159                  0x00000028    /* AM designator */
3767 #define LOCALE_S2359                  0x00000029    /* PM designator */
3768
3769 #define LOCALE_ICALENDARTYPE          0x00001009    /* type of calendar specifier */
3770 #define LOCALE_IFIRSTDAYOFWEEK        0x0000100C    /* first day of week specifier */
3771 #define LOCALE_IFIRSTWEEKOFYEAR       0x0000100D    /* first week of year specifier */
3772
3773 #define LOCALE_SDAYNAME1              0x0000002A    /* long name for Monday */
3774 #define LOCALE_SDAYNAME2              0x0000002B    /* long name for Tuesday */
3775 #define LOCALE_SDAYNAME3              0x0000002C    /* long name for Wednesday */
3776 #define LOCALE_SDAYNAME4              0x0000002D    /* long name for Thursday */
3777 #define LOCALE_SDAYNAME5              0x0000002E    /* long name for Friday */
3778 #define LOCALE_SDAYNAME6              0x0000002F    /* long name for Saturday */
3779 #define LOCALE_SDAYNAME7              0x00000030    /* long name for Sunday */
3780 #define LOCALE_SABBREVDAYNAME1        0x00000031    /* abbreviated name for Monday */
3781 #define LOCALE_SABBREVDAYNAME2        0x00000032    /* abbreviated name for Tuesday */
3782 #define LOCALE_SABBREVDAYNAME3        0x00000033    /* abbreviated name for Wednesday */
3783 #define LOCALE_SABBREVDAYNAME4        0x00000034    /* abbreviated name for Thursday */
3784 #define LOCALE_SABBREVDAYNAME5        0x00000035    /* abbreviated name for Friday */
3785 #define LOCALE_SABBREVDAYNAME6        0x00000036    /* abbreviated name for Saturday */
3786 #define LOCALE_SABBREVDAYNAME7        0x00000037    /* abbreviated name for Sunday */
3787 #define LOCALE_SMONTHNAME1            0x00000038    /* long name for January */
3788 #define LOCALE_SMONTHNAME2            0x00000039    /* long name for February */
3789 #define LOCALE_SMONTHNAME3            0x0000003A    /* long name for March */
3790 #define LOCALE_SMONTHNAME4            0x0000003B    /* long name for April */
3791 #define LOCALE_SMONTHNAME5            0x0000003C    /* long name for May */
3792 #define LOCALE_SMONTHNAME6            0x0000003D    /* long name for June */
3793 #define LOCALE_SMONTHNAME7            0x0000003E    /* long name for July */
3794 #define LOCALE_SMONTHNAME8            0x0000003F    /* long name for August */
3795 #define LOCALE_SMONTHNAME9            0x00000040    /* long name for September */
3796 #define LOCALE_SMONTHNAME10           0x00000041    /* long name for October */
3797 #define LOCALE_SMONTHNAME11           0x00000042    /* long name for November */
3798 #define LOCALE_SMONTHNAME12           0x00000043    /* long name for December */
3799 #define LOCALE_SMONTHNAME13           0x0000100E    /* long name for 13th month (if exists) */
3800 #define LOCALE_SABBREVMONTHNAME1      0x00000044    /* abbreviated name for January */
3801 #define LOCALE_SABBREVMONTHNAME2      0x00000045    /* abbreviated name for February */
3802 #define LOCALE_SABBREVMONTHNAME3      0x00000046    /* abbreviated name for March */
3803 #define LOCALE_SABBREVMONTHNAME4      0x00000047    /* abbreviated name for April */
3804 #define LOCALE_SABBREVMONTHNAME5      0x00000048    /* abbreviated name for May */
3805 #define LOCALE_SABBREVMONTHNAME6      0x00000049    /* abbreviated name for June */
3806 #define LOCALE_SABBREVMONTHNAME7      0x0000004A    /* abbreviated name for July */
3807 #define LOCALE_SABBREVMONTHNAME8      0x0000004B    /* abbreviated name for August */
3808 #define LOCALE_SABBREVMONTHNAME9      0x0000004C    /* abbreviated name for September */
3809 #define LOCALE_SABBREVMONTHNAME10     0x0000004D    /* abbreviated name for October */
3810 #define LOCALE_SABBREVMONTHNAME11     0x0000004E    /* abbreviated name for November */
3811 #define LOCALE_SABBREVMONTHNAME12     0x0000004F    /* abbreviated name for December */
3812 #define LOCALE_SABBREVMONTHNAME13     0x0000100F    /* abbreviated name for 13th month (if exists) */
3813
3814 #define LOCALE_SPOSITIVESIGN          0x00000050    /* positive sign */
3815 #define LOCALE_SNEGATIVESIGN          0x00000051    /* negative sign */
3816
3817 #define LOCALE_FONTSIGNATURE          0x00000058    /* font signature */
3818 #define LOCALE_SISO639LANGNAME        0x00000059    /* ISO abbreviated language name */
3819 #define LOCALE_SISO3166CTRYNAME       0x0000005A    /* ISO abbreviated country name */
3820
3821 #define LOCALE_SENGCURRNAME           0x00001007    /* english name of currency */
3822 #define LOCALE_SNATIVECURRNAME        0x00001008    /* native name of currency */
3823 #define LOCALE_SYEARMONTH             0x00001006    /* year month format string */
3824 #define LOCALE_IDIGITSUBSTITUTION     0x00001014    /* 0 = context, 1 = none, 2 = national */
3825
3826 #define LOCALE_SNAME                  0x0000005C    /* locale name <language>[-<Script>][-<REGION>[_<sort order>]] */
3827 #define LOCALE_SDURATION              0x0000005d    /* time duration format */
3828 #define LOCALE_SKEYBOARDSTOINSTALL    0x0000005e    /* (windows only) keyboards to install */
3829 #define LOCALE_SSHORTESTDAYNAME1      0x00000060    /* Shortest day name for Monday */
3830 #define LOCALE_SSHORTESTDAYNAME2      0x00000061    /* Shortest day name for Tuesday */
3831 #define LOCALE_SSHORTESTDAYNAME3      0x00000062    /* Shortest day name for Wednesday */
3832 #define LOCALE_SSHORTESTDAYNAME4      0x00000063    /* Shortest day name for Thursday */
3833 #define LOCALE_SSHORTESTDAYNAME5      0x00000064    /* Shortest day name for Friday */
3834 #define LOCALE_SSHORTESTDAYNAME6      0x00000065    /* Shortest day name for Saturday */
3835 #define LOCALE_SSHORTESTDAYNAME7      0x00000066    /* Shortest day name for Sunday */
3836 #define LOCALE_SISO639LANGNAME2       0x00000067    /* 3 character ISO abbreviated language name */
3837 #define LOCALE_SISO3166CTRYNAME2      0x00000068    /* 3 character ISO country name */
3838 #define LOCALE_SNAN                   0x00000069    /* Not a Number */
3839 #define LOCALE_SPOSINFINITY           0x0000006a    /* + Infinity */
3840 #define LOCALE_SNEGINFINITY           0x0000006b    /* - Infinity */
3841 #define LOCALE_SSCRIPTS               0x0000006c    /* Typical scripts in the locale */
3842 #define LOCALE_SPARENT                0x0000006d    /* Fallback name for resources */
3843 #define LOCALE_SCONSOLEFALLBACKNAME   0x0000006e    /* Fallback name for within the console */
3844 #define LOCALE_SLANGDISPLAYNAME       0x0000006f    /* Language Display Name for a language */ 
3845 #define LOCALE_IREADINGLAYOUT         0x00000070   // Returns one of the following 4 reading layout values:
3846                                                    // 0 - Left to right (eg en-US)
3847                                                    // 1 - Right to left (eg arabic locales)
3848                                                    // 2 - Vertical top to bottom with columns to the left and also left to right (ja-JP locales)
3849                                                    // 3 - Vertical top to bottom with columns proceeding to the right
3850 #define LOCALE_INEUTRAL               0x00000071   // Returns 0 for specific cultures, 1 for neutral cultures.
3851 #define LOCALE_INEGATIVEPERCENT       0x00000074   // Returns 0-11 for the negative percent format
3852 #define LOCALE_IPOSITIVEPERCENT       0x00000075   // Returns 0-3 for the positive percent formatIPOSITIVEPERCENT
3853 #define LOCALE_SPERCENT               0x00000076   // Returns the percent symbol
3854 #define LOCALE_SPERMILLE              0x00000077   // Returns the permille (U+2030) symbol
3855 #define LOCALE_SMONTHDAY              0x00000078   // Returns the preferred month/day format
3856 #define LOCALE_SSHORTTIME             0x00000079   // Returns the preferred short time format (ie: no seconds, just h:mm)
3857 #define LOCALE_SOPENTYPELANGUAGETAG   0x0000007a   // Open type language tag, eg: "latn" or "dflt"
3858 #define LOCALE_SSORTLOCALE            0x0000007b   // Name of locale to use for sorting/collation/casing behavior.
3859
3860 #define LCMAP_LINGUISTIC_CASING       0x01000000    /* Use linguistic casing */
3861
3862 #define CAL_RETURN_GENITIVE_NAMES       LOCALE_RETURN_GENITIVE_NAMES  // return genitive forms of month names
3863
3864 #define CAL_SSHORTESTDAYNAME1         0x00000031
3865 #define CAL_SSHORTESTDAYNAME2         0x00000032
3866 #define CAL_SSHORTESTDAYNAME3         0x00000033
3867 #define CAL_SSHORTESTDAYNAME4         0x00000034
3868 #define CAL_SSHORTESTDAYNAME5         0x00000035
3869 #define CAL_SSHORTESTDAYNAME6         0x00000036
3870 #define CAL_SSHORTESTDAYNAME7         0x00000037
3871
3872 #define CAL_SMONTHDAY                   0x00000038  // Month/day pattern (reserve for potential inclusion in a future version)
3873 #define CAL_SERASTRING                  0x00000004  // era name for IYearOffsetRanges, eg A.D.
3874 #define CAL_SABBREVERASTRING            0x00000039  // Abbreviated era string (eg: AD)
3875
3876 #define CAL_SSHORTDATE            0x00000005  /* short date format string */
3877 #define CAL_SLONGDATE             0x00000006  /* long date format string */
3878 #define CAL_SDAYNAME1             0x00000007  /* native name for Monday */
3879 #define CAL_SDAYNAME2             0x00000008  /* native name for Tuesday */
3880 #define CAL_SDAYNAME3             0x00000009  /* native name for Wednesday */
3881 #define CAL_SDAYNAME4             0x0000000a  /* native name for Thursday */
3882 #define CAL_SDAYNAME5             0x0000000b  /* native name for Friday */
3883 #define CAL_SDAYNAME6             0x0000000c  /* native name for Saturday */
3884 #define CAL_SDAYNAME7             0x0000000d  /* native name for Sunday */
3885 #define CAL_SABBREVDAYNAME1       0x0000000e  /* abbreviated name for Monday */
3886 #define CAL_SABBREVDAYNAME2       0x0000000f  /* abbreviated name for Tuesday */
3887 #define CAL_SABBREVDAYNAME3       0x00000010  /* abbreviated name for Wednesday */
3888 #define CAL_SABBREVDAYNAME4       0x00000011  /* abbreviated name for Thursday */
3889 #define CAL_SABBREVDAYNAME5       0x00000012  /* abbreviated name for Friday */
3890 #define CAL_SABBREVDAYNAME6       0x00000013  /* abbreviated name for Saturday */
3891 #define CAL_SABBREVDAYNAME7       0x00000014  /* abbreviated name for Sunday */
3892 #define CAL_SMONTHNAME1           0x00000015  /* native name for January */
3893 #define CAL_SMONTHNAME2           0x00000016  /* native name for February */
3894 #define CAL_SMONTHNAME3           0x00000017  /* native name for March */
3895 #define CAL_SMONTHNAME4           0x00000018  /* native name for April */
3896 #define CAL_SMONTHNAME5           0x00000019  /* native name for May */
3897 #define CAL_SMONTHNAME6           0x0000001a  /* native name for June */
3898 #define CAL_SMONTHNAME7           0x0000001b  /* native name for July */
3899 #define CAL_SMONTHNAME8           0x0000001c  /* native name for August */
3900 #define CAL_SMONTHNAME9           0x0000001d  /* native name for September */
3901 #define CAL_SMONTHNAME10          0x0000001e  /* native name for October */
3902 #define CAL_SMONTHNAME11          0x0000001f  /* native name for November */
3903 #define CAL_SMONTHNAME12          0x00000020  /* native name for December */
3904 #define CAL_SMONTHNAME13          0x00000021  /* native name for 13th month (if any) */
3905 #define CAL_SABBREVMONTHNAME1     0x00000022  /* abbreviated name for January */
3906 #define CAL_SABBREVMONTHNAME2     0x00000023  /* abbreviated name for February */
3907 #define CAL_SABBREVMONTHNAME3     0x00000024  /* abbreviated name for March */
3908 #define CAL_SABBREVMONTHNAME4     0x00000025  /* abbreviated name for April */
3909 #define CAL_SABBREVMONTHNAME5     0x00000026  /* abbreviated name for May */
3910 #define CAL_SABBREVMONTHNAME6     0x00000027  /* abbreviated name for June */
3911 #define CAL_SABBREVMONTHNAME7     0x00000028  /* abbreviated name for July */
3912 #define CAL_SABBREVMONTHNAME8     0x00000029  /* abbreviated name for August */
3913 #define CAL_SABBREVMONTHNAME9     0x0000002a  /* abbreviated name for September */
3914 #define CAL_SABBREVMONTHNAME10    0x0000002b  /* abbreviated name for October */
3915 #define CAL_SABBREVMONTHNAME11    0x0000002c  /* abbreviated name for November */
3916 #define CAL_SABBREVMONTHNAME12    0x0000002d  /* abbreviated name for December */
3917 #define CAL_SABBREVMONTHNAME13    0x0000002e  /* abbreviated name for 13th month (if any) */
3918 #define CAL_SYEARMONTH            0x0000002f  /* year month format string */
3919
3920
3921 #else // __APPLE__
3922
3923 #define LOCALE_SDECIMAL               0x0000000E    /* decimal separator */
3924 #define LOCALE_STHOUSAND              0x0000000F    /* thousand separator */
3925 #define LOCALE_ILZERO                 0x00000012    /* leading zeros for decimal */
3926 #define LOCALE_SCURRENCY              0x00000014    /* local monetary symbol */
3927 #define LOCALE_SMONDECIMALSEP         0x00000016    /* monetary decimal separator */
3928 #define LOCALE_SMONTHOUSANDSEP        0x00000017    /* monetary thousand separator */
3929
3930 #endif // __APPLE__
3931
3932
3933 #if ENABLE_DOWNLEVEL_FOR_NLS
3934
3935 PALIMPORT
3936 int
3937 PALAPI
3938 GetLocaleInfoW(
3939     IN LCID     Locale,
3940     IN LCTYPE   LCType,
3941     OUT LPWSTR  lpLCData,
3942     IN int      cchData);
3943
3944 #endif // ENABLE_DOWNLEVEL_FOR_NLS
3945
3946 PALIMPORT
3947 int
3948 PALAPI
3949 GetLocaleInfoEx(
3950     IN LPCWSTR  lpLocaleName,
3951     IN LCTYPE   LCType,
3952     OUT LPWSTR  lpLCData,
3953     IN int      cchData);
3954
3955
3956 PALIMPORT
3957 int 
3958 PALAPI
3959 CompareStringOrdinal(
3960     IN LPCWSTR lpString1, 
3961         IN int cchCount1, 
3962         IN LPCWSTR lpString2, 
3963         IN int cchCount2, 
3964         IN BOOL bIgnoreCase);
3965
3966 typedef struct _nlsversioninfoex { 
3967   DWORD  dwNLSVersionInfoSize; 
3968   DWORD  dwNLSVersion; 
3969   DWORD  dwDefinedVersion; 
3970   DWORD  dwEffectiveId;   
3971   GUID  guidCustomVersion; 
3972   } NLSVERSIONINFOEX, *LPNLSVERSIONINFOEX; 
3973
3974 PALIMPORT
3975 int 
3976 PALAPI
3977 FindNLSStringEx(
3978     IN LPCWSTR lpLocaleName, 
3979         IN DWORD dwFindNLSStringFlags, 
3980         IN LPCWSTR lpStringSource, 
3981         IN int cchSource, 
3982     IN LPCWSTR lpStringValue, 
3983         IN int cchValue, 
3984         OUT LPINT pcchFound, 
3985         IN LPNLSVERSIONINFOEX lpVersionInformation, 
3986         IN LPVOID lpReserved, 
3987         IN LPARAM lParam );
3988
3989 typedef enum {
3990     COMPARE_STRING = 0x0001,
3991 } NLS_FUNCTION;
3992
3993 PALIMPORT
3994 BOOL 
3995 PALAPI
3996 IsNLSDefinedString(
3997     IN NLS_FUNCTION Function, 
3998         IN DWORD dwFlags, 
3999         IN LPNLSVERSIONINFOEX lpVersionInfo, 
4000         IN LPCWSTR lpString, 
4001         IN int cchStr );
4002
4003
4004 PALIMPORT
4005 int
4006 PALAPI
4007 ResolveLocaleName(
4008     IN LPCWSTR lpNameToResolve,
4009         OUT LPWSTR lpLocaleName,
4010         IN int cchLocaleName );
4011
4012 PALIMPORT
4013 BOOL 
4014 PALAPI
4015 GetThreadPreferredUILanguages(
4016     IN DWORD  dwFlags,
4017     OUT PULONG  pulNumLanguages,
4018     OUT PWSTR  pwszLanguagesBuffer,
4019     IN OUT PULONG  pcchLanguagesBuffer);
4020
4021
4022 PALIMPORT
4023 int 
4024 PALAPI
4025 GetSystemDefaultLocaleName(
4026     OUT LPWSTR lpLocaleName, 
4027         IN int cchLocaleName);
4028
4029 #ifdef UNICODE
4030 #define GetLocaleInfo GetLocaleInfoW
4031 #endif
4032
4033 #if ENABLE_DOWNLEVEL_FOR_NLS
4034 PALIMPORT
4035 LCID
4036 PALAPI
4037 GetUserDefaultLCID(
4038            void);
4039 #endif
4040
4041
4042 PALIMPORT
4043 int
4044 PALAPI
4045 GetUserDefaultLocaleName(
4046            OUT LPWSTR lpLocaleName,
4047            IN int cchLocaleName);
4048
4049
4050
4051
4052 #define TIME_ZONE_ID_INVALID ((DWORD)0xFFFFFFFF)
4053 #define TIME_ZONE_ID_UNKNOWN  0
4054 #define TIME_ZONE_ID_STANDARD 1
4055 #define TIME_ZONE_ID_DAYLIGHT 2
4056
4057
4058 typedef struct _TIME_ZONE_INFORMATION {
4059     LONG Bias;
4060     WCHAR StandardName[ 32 ];
4061     SYSTEMTIME StandardDate;
4062     LONG StandardBias;
4063     WCHAR DaylightName[ 32 ];
4064     SYSTEMTIME DaylightDate;
4065     LONG DaylightBias;
4066 } TIME_ZONE_INFORMATION, *PTIME_ZONE_INFORMATION, *LPTIME_ZONE_INFORMATION;
4067
4068 PALIMPORT
4069 DWORD
4070 PALAPI
4071 GetTimeZoneInformation(
4072                OUT LPTIME_ZONE_INFORMATION lpTimeZoneInformation);
4073
4074 PALIMPORT
4075 DWORD
4076 PALAPI
4077 PAL_GetTimeZoneInformation(
4078                IN int year,
4079                OUT LPTIME_ZONE_INFORMATION lpTimeZoneInformation);
4080
4081 #define LCID_INSTALLED            0x00000001  // installed locale ids
4082 #define LCID_SUPPORTED            0x00000002  // supported locale ids
4083 #ifdef __APPLE__
4084 #define LCID_ALTERNATE_SORTS      0x00000004  // alternate sort locale ids
4085 #endif // __APPLE__
4086
4087 #if ENABLE_DOWNLEVEL_FOR_NLS
4088 PALIMPORT
4089 BOOL
4090 PALAPI
4091 IsValidLocale(
4092           IN LCID Locale,
4093           IN DWORD dwFlags);
4094 #endif // ENABLE_DOWNLEVEL_FOR_NLS
4095
4096
4097 typedef DWORD CALID;
4098 typedef DWORD CALTYPE;
4099
4100 #define CAL_ITWODIGITYEARMAX 0x00000030 // two digit year max
4101 #define CAL_RETURN_NUMBER    0x20000000 // return number instead of string
4102
4103 #define CAL_GREGORIAN                 1 // Gregorian (localized) calendar
4104 #define CAL_GREGORIAN_US              2 // Gregorian (U.S.) calendar
4105 #define CAL_JAPAN                     3 // Japanese Emperor Era calendar
4106 #define CAL_TAIWAN                    4 // Taiwan Era calendar
4107 #define CAL_KOREA                     5 // Korean Tangun Era calendar
4108 #define CAL_HIJRI                     6 // Hijri (Arabic Lunar) calendar
4109 #define CAL_THAI                      7 // Thai calendar
4110 #define CAL_HEBREW                    8 // Hebrew (Lunar) calendar
4111 #define CAL_GREGORIAN_ME_FRENCH       9 // Gregorian Middle East French calendar
4112 #define CAL_GREGORIAN_ARABIC         10 // Gregorian Arabic calendar
4113 #define CAL_GREGORIAN_XLIT_ENGLISH   11 // Gregorian Transliterated English calendar
4114 #define CAL_GREGORIAN_XLIT_FRENCH    12 // Gregorian Transliterated French calendar
4115 #define CAL_JULIAN                   13
4116
4117 #if ENABLE_DOWNLEVEL_FOR_NLS
4118 PALIMPORT
4119 int
4120 PALAPI
4121 GetCalendarInfoW(
4122          IN LCID Locale,
4123          IN CALID Calendar,
4124          IN CALTYPE CalType,
4125          OUT LPWSTR lpCalData,
4126          IN int cchData,
4127          OUT LPDWORD lpValue);
4128
4129 #ifdef UNICODE
4130 #define GetCalendarInfo GetCalendarInfoW
4131 #endif
4132
4133 #endif // ENABLE_DOWNLEVEL_FOR_NLS
4134
4135
4136 PALIMPORT
4137 int
4138 PALAPI
4139 GetCalendarInfoEx(
4140          IN LPCWSTR lpLocaleName,
4141          IN CALID Calendar,
4142          IN LPCWSTR lpReserved,
4143          IN CALTYPE CalType,
4144          OUT LPWSTR lpCalData,
4145          IN int cchData,
4146          OUT LPDWORD lpValue);
4147
4148 #if ENABLE_DOWNLEVEL_FOR_NLS
4149 typedef BOOL (CALLBACK* LOCALE_ENUMPROCW)(LPWSTR);
4150
4151 PALIMPORT
4152 BOOL
4153 PALAPI
4154 EnumSystemLocalesW(
4155     IN LOCALE_ENUMPROCW lpLocaleEnumProc,
4156     IN DWORD            dwFlags);
4157 #endif //  ENABLE_DOWNLEVEL_FOR_NLS
4158
4159 #define DATE_SHORTDATE            0x00000001  // use short date picture
4160 #define DATE_LONGDATE             0x00000002  // use long date picture
4161 #define DATE_YEARMONTH            0x00000008  // use year month picture
4162
4163 typedef BOOL (CALLBACK* DATEFMT_ENUMPROCEXW)(LPWSTR, CALID);
4164
4165 #if ENABLE_DOWNLEVEL_FOR_NLS
4166
4167 PALIMPORT
4168 BOOL
4169 PALAPI
4170 EnumDateFormatsExW(
4171     IN DATEFMT_ENUMPROCEXW lpDateFmtEnumProcEx,
4172     IN LCID                Locale,
4173     IN DWORD               dwFlags);
4174
4175 #else // ENABLE_DOWNLEVEL_FOR_NLS
4176
4177 typedef BOOL (CALLBACK* DATEFMT_ENUMPROCEXEXW)(LPWSTR, CALID, LPARAM);
4178
4179 PALIMPORT
4180 BOOL
4181 PALAPI
4182 EnumDateFormatsExEx(
4183     IN DATEFMT_ENUMPROCEXEXW lpDateFmtEnumProcEx,
4184     IN LPCWSTR          lpLocaleName,
4185     IN DWORD               dwFlags,
4186     IN LPARAM      lParam);
4187
4188 #endif // ENABLE_DOWNLEVEL_FOR_NLS
4189
4190 typedef BOOL (CALLBACK* TIMEFMT_ENUMPROCW)(LPWSTR);
4191
4192 #if ENABLE_DOWNLEVEL_FOR_NLS
4193
4194 PALIMPORT
4195 BOOL
4196 PALAPI
4197 EnumTimeFormatsW(
4198     IN TIMEFMT_ENUMPROCW lpTimeFmtEnumProc,
4199     IN LCID              Locale,
4200     IN DWORD             dwFlags);
4201
4202 #else // ENABLE_DOWNLEVEL_FOR_NLS
4203
4204 typedef BOOL (CALLBACK* TIMEFMT_ENUMPROCEXW)(LPWSTR, LPARAM);
4205
4206 PALIMPORT
4207 BOOL
4208 PALAPI
4209 EnumTimeFormatsEx(
4210     IN TIMEFMT_ENUMPROCEXW lpTimeFmtEnumProc,
4211     IN LPCWSTR          lpLocaleName,
4212     IN DWORD             dwFlags,
4213     IN LPARAM    lParam);
4214
4215 #endif // ENABLE_DOWNLEVEL_FOR_NLS
4216
4217 #define ENUM_ALL_CALENDARS        0xffffffff  // enumerate all calendars
4218 #define CAL_ICALINTVALUE          0x00000001  // calendar type
4219 #define CAL_NOUSEROVERRIDE        LOCALE_NOUSEROVERRIDE  // do not use user overrides
4220 #define CAL_SCALNAME              0x00000002  // native name of calendar
4221
4222 typedef BOOL (CALLBACK* CALINFO_ENUMPROCEXW)(LPWSTR,CALID);
4223
4224 #if ENABLE_DOWNLEVEL_FOR_NLS
4225
4226 PALIMPORT
4227 BOOL
4228 PALAPI
4229 EnumCalendarInfoExW(
4230     IN CALINFO_ENUMPROCEXW lpCalInfoEnumProc,
4231     IN LCID              Locale,
4232     IN CALID             Calendar,
4233     IN CALTYPE           CalType);
4234
4235 #else // ENABLE_DOWNLEVEL_FOR_NLS
4236
4237 typedef BOOL (CALLBACK* CALINFO_ENUMPROCEXEXW)(LPWSTR, CALID, LPWSTR, LPARAM);
4238
4239 PALIMPORT
4240 BOOL
4241 PALAPI
4242 EnumCalendarInfoExEx(
4243     IN CALINFO_ENUMPROCEXEXW lpCalInfoEnumProc,
4244     IN LPCWSTR          lpLocaleName,
4245     IN CALID             Calendar,
4246     IN LPCWSTR           lpReserved,
4247     IN CALTYPE           CalType,
4248     IN LPARAM        lParam);
4249
4250 #endif // ENABLE_DOWNLEVEL_FOR_NLS
4251
4252 #define LCMAP_LOWERCASE  0x00000100
4253 #define LCMAP_UPPERCASE  0x00000200
4254
4255 #if ENABLE_DOWNLEVEL_FOR_NLS
4256
4257 PALIMPORT
4258 int
4259 PALAPI
4260 LCMapStringW(
4261     IN LCID    Locale,
4262     IN DWORD   dwMapFlags,
4263     IN LPCWSTR lpSrcStr,
4264     IN int     cchSrc,
4265     OUT LPWSTR lpDestStr,
4266     IN int     cchDest);
4267
4268 #ifdef UNICODE
4269 #define LCMapString LCMapStringW
4270 #endif
4271
4272
4273 #endif // ENABLE_DOWNLEVEL_FOR_NLS
4274
4275
4276 PALIMPORT
4277 int
4278 PALAPI
4279 LCMapStringEx(
4280     IN LPCWSTR    lpLocaleName,
4281     IN DWORD   dwMapFlags,
4282     IN LPCWSTR lpSrcStr,
4283     IN int     cchSrc,
4284     OUT LPWSTR lpDestStr,
4285     IN int     cchDest,
4286     IN LPNLSVERSIONINFO lpVersionInformation, 
4287     IN LPVOID lpReserved, 
4288     IN LPARAM lParam );
4289
4290 PALIMPORT
4291 int
4292 PALAPI
4293 PAL_LCMapCharW(
4294     IN LPCWSTR    lpLocaleName,
4295     IN DWORD   dwMapFlags,
4296     IN WCHAR   srcChar,
4297     OUT WCHAR  *destChar,
4298     LPNLSVERSIONINFO lpVersionInformation,
4299     LPVOID lpReserved,
4300     LPARAM lParam );
4301
4302 PALIMPORT
4303 int
4304 PALAPI
4305 PAL_NormalizeStringExW(
4306     IN LPCWSTR    lpLocaleName,
4307     IN DWORD   dwMapFlags,
4308     IN LPCWSTR lpSrcStr,
4309     IN int     cchSrc,
4310     OUT LPWSTR lpDestStr,
4311     IN int     cchDest);
4312
4313
4314 PALIMPORT
4315 int
4316 PALAPI
4317 PAL_FormatDateW(
4318     IN LPCWSTR   lpLocaleName,
4319     IN LPCWSTR   lpFormat,
4320     IN BOOL fUseUTC,
4321     IN BOOL fUseCustomTz,
4322     IN int tzOffsetSeconds,
4323     IN LPSYSTEMTIME lpTime,    
4324     OUT LPWSTR lpDestStr,
4325     IN int     cchDest);
4326
4327 PALIMPORT
4328 int
4329 PALAPI
4330 PAL_ParseDateW(
4331     IN LPCWSTR   lpLocaleName,
4332     IN LPCWSTR   lpFormat,
4333     IN LPCWSTR   lpString,
4334     OUT LPSYSTEMTIME lpTime);
4335
4336 PALIMPORT
4337 int
4338 PALAPI
4339 PAL_GetCalendar(
4340     IN LPCWSTR   lpLocaleName,
4341     OUT CALID*   pCalendar);
4342
4343 #define GEOID_NOT_AVAILABLE -1
4344
4345 // "a number", might represent different types
4346 typedef struct PALNUMBER__* PALNUMBER;
4347
4348 // return NULL on OOM
4349 PALIMPORT PALNUMBER PALAPI PAL_DoubleToNumber(double);
4350 PALIMPORT PALNUMBER PALAPI PAL_Int64ToNumber(INT64);
4351 PALIMPORT PALNUMBER PALAPI PAL_UInt64ToNumber(UINT64);
4352 PALIMPORT PALNUMBER PALAPI PAL_IntToNumber(int);
4353 PALIMPORT PALNUMBER PALAPI PAL_UIntToNumber(unsigned int);
4354
4355 PALIMPORT void PALAPI PAL_ReleaseNumber(PALNUMBER);
4356
4357
4358 // return string length if Buffer is NULL or the result fits in cchBuffer, otherwise -1
4359 PALIMPORT int PALAPI PAL_FormatScientific(LPCWSTR sLocale, LPWSTR pBuffer, SIZE_T cchBuffer, PALNUMBER number, int nMinDigits, int nMaxDigits,
4360                                                                       LPCWSTR sExponent, LPCWSTR sNumberDecimal, LPCWSTR sPositive, LPCWSTR sNegative, LPCWSTR sZero);
4361
4362 PALIMPORT int PALAPI  PAL_FormatCurrency(LPCWSTR sLocale, LPWSTR pBuffer, SIZE_T cchBuffer, PALNUMBER number, int nMinDigits, int nMaxDigits, int iNegativeFormat, int iPositiveFormat,
4363                       int iPrimaryGroup, int iSecondaryGroup, LPCWSTR sCurrencyDecimal, LPCWSTR sCurrencyGroup, LPCWSTR sNegative, LPCWSTR sCurrency, LPCWSTR sZero);
4364
4365 PALIMPORT int PALAPI  PAL_FormatPercent(LPCWSTR sLocale, LPWSTR pBuffer, SIZE_T cchBuffer, PALNUMBER number,  int nMinDigits, int nMaxDigits,int iNegativeFormat, int iPositiveFormat, 
4366                       int iPrimaryGroup, int iSecondaryGroup, LPCWSTR sPercentDecimal, LPCWSTR sPercentGroup, LPCWSTR sNegative, LPCWSTR sPercent, LPCWSTR sZero);
4367
4368 PALIMPORT int PALAPI  PAL_FormatDecimal(LPCWSTR sLocale, LPWSTR pBuffer, SIZE_T cchBuffer, PALNUMBER number, int nMinDigits, int nMaxDigits, int iNegativeFormat,
4369                                     int iPrimaryGroup, int iSecondaryGroup,  LPCWSTR sDecimal, LPCWSTR sGroup, LPCWSTR sNegative, LPCWSTR sZero);
4370
4371
4372 #define DATE_USE_ALT_CALENDAR 0x00000004
4373
4374 #if ENABLE_DOWNLEVEL_FOR_NLS
4375
4376 PALIMPORT
4377 int
4378 PALAPI
4379 GetDateFormatW(
4380            IN LCID Locale,
4381            IN DWORD dwFlags,
4382            IN CONST SYSTEMTIME *lpDate,
4383            IN LPCWSTR lpFormat,
4384            OUT LPWSTR lpDateStr,
4385            IN int cchDate);
4386
4387 #else
4388
4389 PALIMPORT
4390 int
4391 PALAPI
4392 GetDateFormatEx(
4393            IN LPCWSTR Locale,
4394            IN DWORD dwFlags,
4395            IN CONST SYSTEMTIME *lpDate,
4396            IN LPCWSTR lpFormat,
4397            OUT LPWSTR lpDateStr,
4398            IN int cchDate,
4399            IN LPCWSTR lpCalendar);
4400
4401
4402 #endif // ENABLE_DOWNLEVEL_FOR_NLS
4403
4404 PALIMPORT
4405 int
4406 PALAPI
4407 GetDateFormatEx(
4408            IN LPCWSTR lpLocaleName,
4409            IN DWORD dwFlags,
4410            IN CONST SYSTEMTIME *lpDate,
4411            IN LPCWSTR lpFormat,
4412            OUT LPWSTR lpDateStr,
4413            IN int cchDate,
4414            LPCWSTR lpCalendar);
4415
4416
4417 #ifdef UNICODE
4418 #define GetDateFormat GetDateFormatW
4419 #endif
4420
4421 #define EXCEPTION_NONCONTINUABLE 0x1
4422 #define EXCEPTION_UNWINDING 0x2
4423
4424 #ifdef FEATURE_PAL_SXS
4425
4426 #define EXCEPTION_EXIT_UNWIND 0x4       // Exit unwind is in progress (not used by PAL SEH)
4427 #define EXCEPTION_NESTED_CALL 0x10      // Nested exception handler call
4428 #define EXCEPTION_TARGET_UNWIND 0x20    // Target unwind in progress
4429 #define EXCEPTION_COLLIDED_UNWIND 0x40  // Collided exception handler call
4430 #define EXCEPTION_SKIP_VEH 0x200
4431
4432 #define EXCEPTION_UNWIND (EXCEPTION_UNWINDING | EXCEPTION_EXIT_UNWIND | \
4433                           EXCEPTION_TARGET_UNWIND | EXCEPTION_COLLIDED_UNWIND)
4434
4435 #define IS_DISPATCHING(Flag) ((Flag & EXCEPTION_UNWIND) == 0)
4436 #define IS_UNWINDING(Flag) ((Flag & EXCEPTION_UNWIND) != 0)
4437 #define IS_TARGET_UNWIND(Flag) (Flag & EXCEPTION_TARGET_UNWIND)
4438
4439 #endif // FEATURE_PAL_SXS
4440
4441 #define EXCEPTION_IS_SIGNAL 0x100
4442
4443 #define EXCEPTION_MAXIMUM_PARAMETERS 15
4444
4445 // Index in the ExceptionInformation array where we will keep the reference
4446 // to the native exception that needs to be deleted when dispatching
4447 // exception in managed code.
4448 #define NATIVE_EXCEPTION_ASYNC_SLOT (EXCEPTION_MAXIMUM_PARAMETERS-1)
4449
4450 typedef struct _EXCEPTION_RECORD {
4451     DWORD ExceptionCode;
4452     DWORD ExceptionFlags;
4453     struct _EXCEPTION_RECORD *ExceptionRecord;
4454     PVOID ExceptionAddress;
4455     DWORD NumberParameters;
4456     ULONG_PTR ExceptionInformation[EXCEPTION_MAXIMUM_PARAMETERS];
4457 } EXCEPTION_RECORD, *PEXCEPTION_RECORD;
4458
4459 typedef struct _EXCEPTION_POINTERS {
4460     PEXCEPTION_RECORD ExceptionRecord;
4461     PCONTEXT ContextRecord;
4462 } EXCEPTION_POINTERS, *PEXCEPTION_POINTERS, *LPEXCEPTION_POINTERS;
4463
4464 #ifdef FEATURE_PAL_SXS
4465
4466 typedef LONG EXCEPTION_DISPOSITION;
4467
4468 enum {
4469     ExceptionContinueExecution,
4470     ExceptionContinueSearch,
4471     ExceptionNestedException,
4472     ExceptionCollidedUnwind,
4473 };
4474
4475 #endif // FEATURE_PAL_SXS
4476
4477 //
4478 // A function table entry is generated for each frame function.
4479 //
4480 typedef struct _RUNTIME_FUNCTION {
4481     DWORD BeginAddress;
4482     DWORD EndAddress;
4483     DWORD UnwindData;
4484 } RUNTIME_FUNCTION, *PRUNTIME_FUNCTION;
4485
4486 PALIMPORT
4487 BOOL
4488 PALAPI
4489 WriteProcessMemory(IN HANDLE hProcess,
4490                    IN LPVOID lpBaseAddress,
4491                    IN LPCVOID lpBuffer,
4492                    IN SIZE_T nSize,
4493                    OUT SIZE_T * lpNumberOfBytesWritten);
4494
4495 #define STANDARD_RIGHTS_REQUIRED  (0x000F0000L)
4496 #define SYNCHRONIZE               (0x00100000L)
4497 #define READ_CONTROL              (0x00020000L)
4498
4499 #define EVENT_MODIFY_STATE        (0x0002)
4500 #define EVENT_ALL_ACCESS          (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | \
4501                                    0x3) 
4502
4503 #define MUTANT_QUERY_STATE        (0x0001)
4504 #define MUTANT_ALL_ACCESS         (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | \
4505                                    MUTANT_QUERY_STATE)
4506 #define MUTEX_ALL_ACCESS          MUTANT_ALL_ACCESS
4507
4508 #define SEMAPHORE_MODIFY_STATE    (0x0002)
4509 #define SEMAPHORE_ALL_ACCESS      (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | \
4510                                    0x3)
4511
4512 #define PROCESS_TERMINATE         (0x0001)  
4513 #define PROCESS_CREATE_THREAD     (0x0002)  
4514 #define PROCESS_SET_SESSIONID     (0x0004)  
4515 #define PROCESS_VM_OPERATION      (0x0008)  
4516 #define PROCESS_VM_READ           (0x0010)  
4517 #define PROCESS_VM_WRITE          (0x0020)  
4518 #define PROCESS_DUP_HANDLE        (0x0040)  
4519 #define PROCESS_CREATE_PROCESS    (0x0080)  
4520 #define PROCESS_SET_QUOTA         (0x0100)  
4521 #define PROCESS_SET_INFORMATION   (0x0200)  
4522 #define PROCESS_QUERY_INFORMATION (0x0400)  
4523 #define PROCESS_SUSPEND_RESUME    (0x0800)  
4524 #define PROCESS_ALL_ACCESS        (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | \
4525                                    0xFFF)
4526
4527 PALIMPORT
4528 HANDLE
4529 PALAPI
4530 OpenProcess(
4531     IN DWORD dwDesiredAccess, /* PROCESS_DUP_HANDLE or PROCESS_ALL_ACCESS */
4532     IN BOOL bInheritHandle,
4533     IN DWORD dwProcessId
4534     );
4535
4536 PALIMPORT
4537 VOID
4538 PALAPI
4539 OutputDebugStringA(
4540            IN LPCSTR lpOutputString);
4541
4542 PALIMPORT
4543 VOID
4544 PALAPI
4545 OutputDebugStringW(
4546            IN LPCWSTR lpOutputStrig);
4547
4548 #ifdef UNICODE
4549 #define OutputDebugString OutputDebugStringW
4550 #else
4551 #define OutputDebugString OutputDebugStringA
4552 #endif
4553
4554 PALIMPORT
4555 VOID
4556 PALAPI
4557 DebugBreak(
4558        VOID);
4559
4560 PALIMPORT
4561 LPWSTR
4562 PALAPI
4563 lstrcatW(
4564      IN OUT LPWSTR lpString1,
4565      IN LPCWSTR lpString2);
4566
4567 #ifdef UNICODE
4568 #define lstrcat lstrcatW
4569 #endif
4570
4571 PALIMPORT
4572 LPWSTR
4573 PALAPI
4574 lstrcpyW(
4575      OUT LPWSTR lpString1,
4576      IN LPCWSTR lpString2);
4577
4578 #ifdef UNICODE
4579 #define lstrcpy lstrcpyW
4580 #endif
4581
4582 PALIMPORT
4583 int
4584 PALAPI
4585 lstrlenA(
4586      IN LPCSTR lpString);
4587
4588 PALIMPORT
4589 int
4590 PALAPI
4591 lstrlenW(
4592      IN LPCWSTR lpString);
4593
4594 #ifdef UNICODE
4595 #define lstrlen lstrlenW
4596 #else
4597 #define lstrlen lstrlenA
4598 #endif
4599
4600 PALIMPORT
4601 LPWSTR
4602 PALAPI
4603 lstrcpynW(
4604       OUT LPWSTR lpString1,
4605       IN LPCWSTR lpString2,
4606       IN int iMaxLength);
4607
4608 #ifdef UNICODE
4609 #define lstrcpyn lstrcpynW
4610 #endif
4611
4612
4613 PALIMPORT
4614 DWORD
4615 PALAPI
4616 GetEnvironmentVariableA(
4617             IN LPCSTR lpName,
4618             OUT LPSTR lpBuffer,
4619             IN DWORD nSize);
4620
4621 PALIMPORT
4622 DWORD
4623 PALAPI
4624 GetEnvironmentVariableW(
4625             IN LPCWSTR lpName,
4626             OUT LPWSTR lpBuffer,
4627             IN DWORD nSize);
4628
4629 #ifdef UNICODE
4630 #define GetEnvironmentVariable GetEnvironmentVariableW
4631 #else
4632 #define GetEnvironmentVariable GetEnvironmentVariableA
4633 #endif
4634
4635 PALIMPORT
4636 BOOL
4637 PALAPI
4638 SetEnvironmentVariableA(
4639             IN LPCSTR lpName,
4640             IN LPCSTR lpValue);
4641
4642 PALIMPORT
4643 BOOL
4644 PALAPI
4645 SetEnvironmentVariableW(
4646             IN LPCWSTR lpName,
4647             IN LPCWSTR lpValue);
4648
4649 #ifdef UNICODE
4650 #define SetEnvironmentVariable SetEnvironmentVariableW
4651 #else
4652 #define SetEnvironmentVariable SetEnvironmentVariableA
4653 #endif
4654
4655 PALIMPORT
4656 LPSTR
4657 PALAPI
4658 GetEnvironmentStringsA(
4659                VOID);
4660
4661 PALIMPORT
4662 LPWSTR
4663 PALAPI
4664 GetEnvironmentStringsW(
4665                VOID);
4666
4667 #ifdef UNICODE
4668 #define GetEnvironmentStrings GetEnvironmentStringsW
4669 #else
4670 #define GetEnvironmentStrings GetEnvironmentStringsA
4671 #endif
4672
4673 PALIMPORT
4674 BOOL
4675 PALAPI
4676 FreeEnvironmentStringsA(
4677             IN LPSTR);
4678
4679 PALIMPORT
4680 BOOL
4681 PALAPI
4682 FreeEnvironmentStringsW(
4683             IN LPWSTR);
4684
4685 #ifdef UNICODE
4686 #define FreeEnvironmentStrings FreeEnvironmentStringsW
4687 #else
4688 #define FreeEnvironmentStrings FreeEnvironmentStringsA
4689 #endif
4690
4691 PALIMPORT
4692 BOOL
4693 PALAPI
4694 CloseHandle(
4695         IN OUT HANDLE hObject);
4696
4697 PALIMPORT
4698 VOID
4699 PALAPI
4700 RaiseException(
4701            IN DWORD dwExceptionCode,
4702            IN DWORD dwExceptionFlags,
4703            IN DWORD nNumberOfArguments,
4704            IN CONST ULONG_PTR *lpArguments);
4705
4706 #ifdef FEATURE_PAL_SXS
4707 PALIMPORT
4708 PAL_NORETURN
4709 VOID
4710 PALAPI
4711 PAL_RaiseException(
4712            IN PEXCEPTION_POINTERS ExceptionPointers);
4713 #endif // FEATURE_PAL_SXS
4714
4715 PALIMPORT
4716 DWORD
4717 PALAPI
4718 GetTickCount(
4719          VOID);
4720
4721 PALIMPORT
4722 ULONGLONG
4723 PALAPI
4724 GetTickCount64();
4725
4726 PALIMPORT
4727 BOOL
4728 PALAPI
4729 QueryPerformanceCounter(
4730     OUT LARGE_INTEGER *lpPerformanceCount
4731     );
4732
4733 PALIMPORT
4734 BOOL
4735 PALAPI
4736 QueryPerformanceFrequency(
4737     OUT LARGE_INTEGER *lpFrequency
4738     );
4739
4740 PALIMPORT
4741 BOOL
4742 PALAPI
4743 QueryThreadCycleTime(
4744     IN HANDLE ThreadHandle,
4745     OUT PULONG64 CycleTime);
4746
4747 #ifndef FEATURE_PAL_SXS
4748
4749 typedef LONG (PALAPI *PTOP_LEVEL_EXCEPTION_FILTER)(
4750                            struct _EXCEPTION_POINTERS *ExceptionInfo);
4751 typedef PTOP_LEVEL_EXCEPTION_FILTER LPTOP_LEVEL_EXCEPTION_FILTER;
4752
4753 PALIMPORT
4754 LPTOP_LEVEL_EXCEPTION_FILTER
4755 PALAPI
4756 SetUnhandledExceptionFilter(
4757                 IN LPTOP_LEVEL_EXCEPTION_FILTER lpTopLevelExceptionFilter);
4758
4759 #else // FEATURE_PAL_SXS
4760
4761 typedef EXCEPTION_DISPOSITION (PALAPI *PVECTORED_EXCEPTION_HANDLER)(
4762                            struct _EXCEPTION_POINTERS *ExceptionPointers);
4763
4764 #endif // FEATURE_PAL_SXS
4765
4766 // Define BitScanForward64 and BitScanForward
4767 // Per MSDN, BitScanForward64 will search the mask data from LSB to MSB for a set bit.
4768 // If one is found, its bit position is returned in the out PDWORD argument and 1 is returned.
4769 // Otherwise, 0 is returned.
4770 //
4771 // On GCC, the equivalent function is __builtin_ffsl. It returns 1+index of the least
4772 // significant set bit, or 0 if if mask is zero.
4773 //
4774 // The same is true for BitScanForward, except that the GCC function is __builtin_ffs.
4775
4776 PALIMPORT
4777 unsigned char
4778 PALAPI
4779 BitScanForward(
4780              IN OUT PDWORD Index,
4781              IN UINT qwMask);
4782
4783 PALIMPORT
4784 LONG
4785 PALAPI
4786 InterlockedIncrement(
4787              IN OUT LONG volatile *lpAddend);
4788
4789 PALIMPORT
4790 LONG
4791 PALAPI
4792 InterlockedDecrement(
4793              IN OUT LONG volatile *lpAddend);
4794
4795 PALIMPORT
4796 LONG
4797 PALAPI
4798 InterlockedExchange(
4799             IN OUT LONG volatile *Target,
4800             IN LONG Value);
4801
4802 PALIMPORT
4803 LONG
4804 PALAPI
4805 InterlockedCompareExchange(
4806                IN OUT LONG volatile *Destination,
4807                IN LONG Exchange,
4808                IN LONG Comperand);
4809
4810 PALIMPORT
4811 LONG
4812 PALAPI
4813 InterlockedCompareExchangeAcquire(
4814                IN OUT LONG volatile *Destination,
4815                IN LONG Exchange,
4816                IN LONG Comperand);
4817
4818 PALIMPORT
4819 LONG
4820 PALAPI
4821 InterlockedCompareExchangeRelease(
4822                IN OUT LONG volatile *Destination,
4823                IN LONG Exchange,
4824                IN LONG Comperand);
4825                
4826 PALIMPORT
4827 LONG
4828 PALAPI
4829 InterlockedExchangeAdd(
4830                IN OUT LONG volatile *Addend,
4831                IN LONG Value);
4832                
4833 PALIMPORT
4834 LONG
4835 PALAPI
4836 InterlockedAnd(
4837                IN OUT LONG volatile *Destination,
4838                IN LONG Value);
4839
4840 PALIMPORT
4841 LONG
4842 PALAPI
4843 InterlockedOr(
4844               IN OUT LONG volatile *Destination,
4845               IN LONG Value);
4846
4847 PALIMPORT
4848 unsigned char
4849 PALAPI
4850 BitScanForward64(
4851              IN OUT PDWORD Index,
4852              IN UINT64 qwMask);
4853
4854 PALIMPORT
4855 LONGLONG
4856 PALAPI
4857 InterlockedIncrement64(
4858              IN OUT LONGLONG volatile *lpAddend);
4859
4860 PALIMPORT
4861 LONGLONG
4862 PALAPI
4863 InterlockedDecrement64(
4864              IN OUT LONGLONG volatile *lpAddend);
4865
4866 PALIMPORT
4867 LONGLONG
4868 PALAPI
4869 InterlockedExchange64(
4870             IN OUT LONGLONG volatile *Target,
4871             IN LONGLONG Value);
4872             
4873 PALIMPORT
4874 LONGLONG
4875 PALAPI
4876 InterlockedExchangeAdd64(
4877                IN OUT LONGLONG volatile *Addend,
4878                IN LONGLONG Value);
4879
4880 PALIMPORT
4881 LONGLONG
4882 PALAPI
4883 InterlockedCompareExchange64(
4884                IN OUT LONGLONG volatile *Destination,
4885                IN LONGLONG Exchange,
4886                IN LONGLONG Comperand);
4887
4888 #if defined(BIT64)
4889 #define InterlockedExchangePointer(Target, Value) \
4890     ((PVOID)InterlockedExchange64((PLONG64)(Target), (LONGLONG)(Value)))
4891
4892 #define InterlockedCompareExchangePointer(Destination, ExChange, Comperand) \
4893     ((PVOID)InterlockedCompareExchange64((PLONG64)(Destination), (LONGLONG)(ExChange), (LONGLONG)(Comperand)))
4894 #else
4895 #define InterlockedExchangePointer(Target, Value) \
4896     ((PVOID)(UINT_PTR)InterlockedExchange((PLONG)(UINT_PTR)(Target), (LONG)(UINT_PTR)(Value)))
4897
4898 #define InterlockedCompareExchangePointer(Destination, ExChange, Comperand) \
4899     ((PVOID)(UINT_PTR)InterlockedCompareExchange((PLONG)(UINT_PTR)(Destination), (LONG)(UINT_PTR)(ExChange), (LONG)(UINT_PTR)(Comperand)))
4900 #endif
4901
4902 PALIMPORT
4903 VOID
4904 PALAPI
4905 MemoryBarrier(
4906     VOID);
4907
4908 PALIMPORT
4909 VOID
4910 PALAPI
4911 YieldProcessor(
4912     VOID);
4913
4914 PALIMPORT
4915 DWORD
4916 PALAPI
4917 GetCurrentProcessorNumber();
4918     
4919 #define FORMAT_MESSAGE_ALLOCATE_BUFFER 0x00000100
4920 #define FORMAT_MESSAGE_IGNORE_INSERTS  0x00000200
4921 #define FORMAT_MESSAGE_FROM_STRING     0x00000400
4922 #define FORMAT_MESSAGE_FROM_SYSTEM     0x00001000
4923 #define FORMAT_MESSAGE_ARGUMENT_ARRAY  0x00002000
4924 #define FORMAT_MESSAGE_MAX_WIDTH_MASK  0x000000FF
4925
4926 PALIMPORT
4927 DWORD
4928 PALAPI
4929 FormatMessageW(
4930            IN DWORD dwFlags,
4931            IN LPCVOID lpSource,
4932            IN DWORD dwMessageId,
4933            IN DWORD dwLanguageId,
4934            OUT LPWSTR lpBffer,
4935            IN DWORD nSize,
4936            IN va_list *Arguments);
4937
4938 #ifdef UNICODE
4939 #define FormatMessage FormatMessageW
4940 #endif
4941
4942
4943 PALIMPORT
4944 DWORD
4945 PALAPI
4946 GetLastError(
4947          VOID);
4948
4949 PALIMPORT
4950 VOID
4951 PALAPI
4952 SetLastError(
4953          IN DWORD dwErrCode);
4954
4955 PALIMPORT
4956 LPWSTR
4957 PALAPI
4958 GetCommandLineW(
4959         VOID);
4960
4961 #ifdef UNICODE
4962 #define GetCommandLine GetCommandLineW
4963 #endif
4964
4965 PALIMPORT
4966 VOID 
4967 PALAPI 
4968 RtlRestoreContext(
4969   IN PCONTEXT ContextRecord,
4970   IN PEXCEPTION_RECORD ExceptionRecord
4971 );
4972
4973 PALIMPORT
4974 VOID 
4975 PALAPI 
4976 RtlCaptureContext(
4977   OUT PCONTEXT ContextRecord
4978 );
4979
4980 PALIMPORT
4981 UINT 
4982 PALAPI 
4983 GetWriteWatch(
4984   IN DWORD dwFlags,
4985   IN PVOID lpBaseAddress,
4986   IN SIZE_T dwRegionSize,
4987   OUT PVOID *lpAddresses,
4988   IN OUT PULONG_PTR lpdwCount,
4989   OUT PULONG lpdwGranularity
4990 );
4991
4992 PALIMPORT
4993 UINT 
4994 PALAPI 
4995 ResetWriteWatch(
4996   IN LPVOID lpBaseAddress,
4997   IN SIZE_T dwRegionSize
4998 );
4999
5000 PALIMPORT
5001 VOID 
5002 PALAPI 
5003 FlushProcessWriteBuffers();
5004
5005 #define VER_PLATFORM_WIN32_WINDOWS        1
5006 #define VER_PLATFORM_WIN32_NT        2
5007 #define VER_PLATFORM_UNIX            10
5008 #define VER_PLATFORM_MACOSX          11
5009
5010 typedef struct _OSVERSIONINFOA {
5011     DWORD dwOSVersionInfoSize;
5012     DWORD dwMajorVersion;
5013     DWORD dwMinorVersion;
5014     DWORD dwBuildNumber;
5015     DWORD dwPlatformId;
5016     CHAR szCSDVersion[ 128 ];
5017 } OSVERSIONINFOA, *POSVERSIONINFOA, *LPOSVERSIONINFOA;
5018
5019 typedef struct _OSVERSIONINFOW {
5020     DWORD dwOSVersionInfoSize;
5021     DWORD dwMajorVersion;
5022     DWORD dwMinorVersion;
5023     DWORD dwBuildNumber;
5024     DWORD dwPlatformId;
5025     WCHAR szCSDVersion[ 128 ];
5026 } OSVERSIONINFOW, *POSVERSIONINFOW, *LPOSVERSIONINFOW;
5027
5028 #ifdef UNICODE
5029 typedef OSVERSIONINFOW OSVERSIONINFO;
5030 typedef POSVERSIONINFOW POSVERSIONINFO;
5031 typedef LPOSVERSIONINFOW LPOSVERSIONINFO;
5032 #else
5033 typedef OSVERSIONINFOA OSVERSIONINFO;
5034 typedef POSVERSIONINFOA POSVERSIONINFO;
5035 typedef LPOSVERSIONINFOA LPOSVERSIONINFO;
5036 #endif
5037
5038 typedef struct _OSVERSIONINFOEXA {
5039     DWORD dwOSVersionInfoSize;
5040     DWORD dwMajorVersion;
5041     DWORD dwMinorVersion;
5042     DWORD dwBuildNumber;
5043     DWORD dwPlatformId;
5044     CHAR szCSDVersion[ 128 ];
5045     WORD  wServicePackMajor;
5046     WORD  wServicePackMinor;
5047     WORD  wSuiteMask;
5048     BYTE  wProductType;
5049     BYTE  wReserved;
5050 } OSVERSIONINFOEXA, *POSVERSIONINFOEXA, *LPOSVERSIONINFOEXA;
5051
5052 typedef struct _OSVERSIONINFOEXW {
5053     DWORD dwOSVersionInfoSize;
5054     DWORD dwMajorVersion;
5055     DWORD dwMinorVersion;
5056     DWORD dwBuildNumber;
5057     DWORD dwPlatformId;
5058     WCHAR szCSDVersion[ 128 ];
5059     WORD  wServicePackMajor;
5060     WORD  wServicePackMinor;
5061     WORD  wSuiteMask;
5062     BYTE  wProductType;
5063     BYTE  wReserved;
5064 } OSVERSIONINFOEXW, *POSVERSIONINFOEXW, *LPOSVERSIONINFOEXW;
5065
5066 #ifdef UNICODE
5067 typedef OSVERSIONINFOEXW OSVERSIONINFOEX;
5068 typedef POSVERSIONINFOEXW POSVERSIONINFOEX;
5069 typedef LPOSVERSIONINFOEXW LPOSVERSIONINFOEX;
5070 #else
5071 typedef OSVERSIONINFOEXA OSVERSIONINFOEX;
5072 typedef POSVERSIONINFOEXA POSVERSIONINFOEX;
5073 typedef LPOSVERSIONINFOEXA LPOSVERSIONINFOEX;
5074 #endif
5075
5076 PALIMPORT
5077 BOOL
5078 PALAPI
5079 GetVersionExA(
5080           IN OUT LPOSVERSIONINFOA lpVersionInformation);
5081
5082 PALIMPORT
5083 BOOL
5084 PALAPI
5085 GetVersionExW(
5086           IN OUT LPOSVERSIONINFOW lpVersionInformation);
5087
5088 #ifdef UNICODE
5089 #define GetVersionEx GetVersionExW
5090 #else
5091 #define GetVersionEx GetVersionExA
5092 #endif
5093
5094 #define IMAGE_FILE_MACHINE_I386              0x014c
5095 #define IMAGE_FILE_MACHINE_ARM64             0xAA64  // ARM64 Little-Endian
5096
5097 typedef struct _SYSTEM_INFO {
5098     WORD wProcessorArchitecture_PAL_Undefined;
5099     WORD wReserved_PAL_Undefined; // NOTE: diff from winbase.h - no obsolete dwOemId union
5100     DWORD dwPageSize;
5101     LPVOID lpMinimumApplicationAddress;
5102     LPVOID lpMaximumApplicationAddress;
5103     DWORD_PTR dwActiveProcessorMask_PAL_Undefined;
5104     DWORD dwNumberOfProcessors;
5105     DWORD dwProcessorType_PAL_Undefined;
5106     DWORD dwAllocationGranularity;
5107     WORD wProcessorLevel_PAL_Undefined;
5108     WORD wProcessorRevision_PAL_Undefined;
5109 } SYSTEM_INFO, *LPSYSTEM_INFO;
5110
5111 PALIMPORT
5112 VOID
5113 PALAPI
5114 GetSystemInfo(
5115           OUT LPSYSTEM_INFO lpSystemInfo);
5116
5117 PALIMPORT
5118 BOOL
5119 PALAPI
5120 GetDiskFreeSpaceW(
5121           LPCWSTR lpDirectoryName,
5122           LPDWORD lpSectorsPerCluster,
5123           LPDWORD lpBytesPerSector,
5124           LPDWORD lpNumberOfFreeClusters,
5125           LPDWORD lpTotalNumberOfClusters);
5126
5127 #ifdef UNICODE
5128 #define GetDiskFreeSpace GetDiskFreeSpaceW
5129 #endif
5130
5131 PALIMPORT
5132 BOOL
5133 PALAPI
5134 CreatePipe(
5135     OUT PHANDLE hReadPipe,
5136     OUT PHANDLE hWritePipe,
5137     IN LPSECURITY_ATTRIBUTES lpPipeAttributes,
5138     IN DWORD nSize
5139     );
5140
5141 PALIMPORT
5142 BOOL
5143 PALAPI
5144 DeregisterEventSource (
5145     IN HANDLE hEventLog
5146     );
5147
5148 PALIMPORT
5149 HANDLE
5150 PALAPI
5151 RegisterEventSourceA (
5152     IN OPTIONAL LPCSTR lpUNCServerName,
5153     IN     LPCSTR lpSourceName
5154     );
5155 PALIMPORT
5156 HANDLE
5157 PALAPI
5158 RegisterEventSourceW (
5159     IN OPTIONAL LPCWSTR lpUNCServerName,
5160     IN     LPCWSTR lpSourceName
5161     );
5162 #ifdef UNICODE
5163 #define RegisterEventSource  RegisterEventSourceW
5164 #else
5165 #define RegisterEventSource  RegisterEventSourceA
5166 #endif // !UNICODE
5167
5168 //
5169 // The types of events that can be logged.
5170 //
5171 #define EVENTLOG_SUCCESS                0x0000
5172 #define EVENTLOG_ERROR_TYPE             0x0001
5173 #define EVENTLOG_WARNING_TYPE           0x0002
5174 #define EVENTLOG_INFORMATION_TYPE       0x0004
5175 #define EVENTLOG_AUDIT_SUCCESS          0x0008
5176 #define EVENTLOG_AUDIT_FAILURE          0x0010
5177
5178 PALIMPORT
5179 BOOL
5180 PALAPI
5181 ReportEventA (
5182     IN     HANDLE     hEventLog,
5183     IN     WORD       wType,
5184     IN     WORD       wCategory,
5185     IN     DWORD      dwEventID,
5186     IN OPTIONAL PSID       lpUserSid,
5187     IN     WORD       wNumStrings,
5188     IN     DWORD      dwDataSize,
5189     IN OPTIONAL LPCSTR *lpStrings,
5190     IN OPTIONAL LPVOID lpRawData
5191     );
5192 PALIMPORT
5193 BOOL
5194 PALAPI
5195 ReportEventW (
5196     IN     HANDLE     hEventLog,
5197     IN     WORD       wType,
5198     IN     WORD       wCategory,
5199     IN     DWORD      dwEventID,
5200     IN OPTIONAL PSID       lpUserSid,
5201     IN     WORD       wNumStrings,
5202     IN     DWORD      dwDataSize,
5203     IN OPTIONAL LPCWSTR *lpStrings,
5204     IN OPTIONAL LPVOID lpRawData
5205     );
5206 #ifdef UNICODE
5207 #define ReportEvent  ReportEventW
5208 #else
5209 #define ReportEvent  ReportEventA
5210 #endif // !UNICODE
5211
5212
5213 /******************* C Runtime Entrypoints *******************************/
5214
5215 #ifdef PLATFORM_UNIX
5216 /* Some C runtime functions needs to be reimplemented by the PAL.
5217    To avoid name collisions, those functions have been renamed using
5218    defines */
5219 #define exit          PAL_exit
5220 #define atexit        PAL_atexit
5221 #define printf        PAL_printf
5222 #define vprintf       PAL_vprintf
5223 #define wprintf       PAL_wprintf
5224 #define sprintf       PAL_sprintf
5225 #define swprintf      PAL_swprintf
5226 #define sscanf        PAL_sscanf
5227 #define wcsspn        PAL_wcsspn
5228 #define wcstod        PAL_wcstod
5229 #define wcstol        PAL_wcstol
5230 #define wcstoul       PAL_wcstoul
5231 #define wcscat        PAL_wcscat
5232 #define wcscpy        PAL_wcscpy
5233 #define wcslen        PAL_wcslen
5234 #define wcsncmp       PAL_wcsncmp
5235 #define wcschr        PAL_wcschr
5236 #define wcsrchr       PAL_wcsrchr
5237 #define swscanf       PAL_swscanf
5238 #define wcspbrk       PAL_wcspbrk
5239 #define wcsstr        PAL_wcsstr
5240 #define wcscmp        PAL_wcscmp
5241 #define wcsncat       PAL_wcsncat
5242 #define wcsncpy       PAL_wcsncpy
5243 #define wcstok        PAL_wcstok
5244 #define wcscspn       PAL_wcscspn
5245 #define iswalpha      PAL_iswalpha
5246 #define iswdigit      PAL_iswdigit
5247 #define iswprint      PAL_iswprint
5248 #define iswspace      PAL_iswspace
5249 #define iswupper      PAL_iswupper
5250 #define iswxdigit     PAL_iswxdigit
5251 #define towlower      PAL_towlower
5252 #define towupper      PAL_towupper
5253 #define vsprintf      PAL_vsprintf
5254 #define vswprintf     PAL_vswprintf
5255 #define realloc       PAL_realloc
5256 #define fopen         PAL_fopen
5257 #define strtok        PAL_strtok
5258 #define strtoul       PAL_strtoul
5259 #define fprintf       PAL_fprintf
5260 #define fwprintf      PAL_fwprintf
5261 #define vfprintf      PAL_vfprintf
5262 #define vfwprintf     PAL_vfwprintf
5263 #define ctime         PAL_ctime
5264 #define localtime     PAL_localtime
5265 #define mktime        PAL_mktime
5266 #define rand          PAL_rand
5267 #define getenv        PAL_getenv
5268 #define fgets         PAL_fgets
5269 #define fgetws        PAL_fgetws
5270 #define fputc         PAL_fputc
5271 #define putchar       PAL_putchar
5272 #define qsort         PAL_qsort
5273 #define bsearch       PAL_bsearch
5274 #define ferror        PAL_ferror
5275 #define fread         PAL_fread
5276 #define fwrite        PAL_fwrite
5277 #define feof          PAL_feof
5278 #define ftell         PAL_ftell
5279 #define fclose        PAL_fclose
5280 #define setbuf        PAL_setbuf
5281 #define fflush        PAL_fflush
5282 #define fputs         PAL_fputs
5283 #define fseek         PAL_fseek
5284 #define fgetpos       PAL_fgetpos
5285 #define fsetpos       PAL_fsetpos
5286 #define getc          PAL_getc
5287 #define fgetc         PAL_getc // not a typo
5288 #define ungetc        PAL_ungetc
5289 #define setvbuf       PAL_setvbuf
5290 #define atol          PAL_atol
5291 #define acos          PAL_acos
5292 #define asin          PAL_asin
5293 #define atan2         PAL_atan2
5294 #define exp           PAL_exp
5295 #define labs          PAL_labs
5296 #define log           PAL_log
5297 #define log10         PAL_log10
5298 #define pow           PAL_pow
5299 #define malloc        PAL_malloc
5300 #define free          PAL_free
5301 #define mkstemp       PAL_mkstemp
5302 #define rename        PAL_rename
5303 #define unlink        PAL_unlink
5304 /* Note the TWO underscores. */
5305 #define _vsnprintf    PAL__vsnprintf
5306 #define _vsnwprintf   PAL__wvsnprintf
5307 #define _strdup       PAL__strdup
5308 #define _getcwd       PAL__getcwd
5309 #define _open         PAL__open
5310 #define _close        PAL__close
5311 #define _wcstoui64    PAL__wcstoui64
5312 #define _flushall     PAL__flushall
5313
5314 #ifdef _AMD64_ 
5315 #define _mm_getcsr    PAL__mm_getcsr
5316 #define _mm_setcsr    PAL__mm_setcsr
5317 #endif // _AMD64_
5318
5319 #endif /* PLATFORM_UNIX */
5320
5321 #ifndef _CONST_RETURN
5322 #ifdef  __cplusplus
5323 #define _CONST_RETURN  const
5324 #define _CRT_CONST_CORRECT_OVERLOADS
5325 #else
5326 #define _CONST_RETURN
5327 #endif
5328 #endif
5329
5330 /* For backwards compatibility */
5331 #define _WConst_return _CONST_RETURN
5332
5333 #define EOF     (-1)
5334
5335 typedef int errno_t;
5336
5337 typedef struct {
5338     int quot;
5339     int rem;
5340 } div_t;
5341
5342 PALIMPORT div_t div(int numer, int denom);
5343
5344 PALIMPORT void * __cdecl memcpy(void *, const void *, size_t);
5345 PALIMPORT errno_t __cdecl memcpy_s(void *, size_t, const void *, size_t);
5346 PALIMPORT int    __cdecl memcmp(const void *, const void *, size_t);
5347 PALIMPORT void * __cdecl memset(void *, int, size_t);
5348 PALIMPORT void * __cdecl memmove(void *, const void *, size_t);
5349 PALIMPORT errno_t __cdecl memmove_s(void *, size_t, const void *, size_t);
5350 PALIMPORT void * __cdecl memchr(const void *, int, size_t);
5351
5352 PALIMPORT size_t __cdecl strlen(const char *);
5353 PALIMPORT int __cdecl strcmp(const char*, const char *);
5354 PALIMPORT int __cdecl strncmp(const char*, const char *, size_t);
5355 PALIMPORT int __cdecl _stricmp(const char *, const char *);
5356 PALIMPORT int __cdecl _strnicmp(const char *, const char *, size_t);
5357 PALIMPORT char * __cdecl strcat(char *, const char *);
5358 PALIMPORT char * __cdecl strncat(char *, const char *, size_t);
5359 PALIMPORT char * __cdecl strcpy(char *, const char *);
5360 PALIMPORT char * __cdecl strncpy(char *, const char *, size_t);
5361 PALIMPORT char * __cdecl strchr(const char *, int);
5362 PALIMPORT char * __cdecl strrchr(const char *, int);
5363 PALIMPORT char * __cdecl strpbrk(const char *, const char *);
5364 PALIMPORT char * __cdecl strstr(const char *, const char *);
5365 PALIMPORT char * __cdecl strtok(char *, const char *);
5366 PALIMPORT size_t __cdecl strspn(const char *, const char *);
5367 PALIMPORT size_t  __cdecl strcspn(const char *, const char *);
5368 PALIMPORT int __cdecl sprintf(char *, const char *, ...);
5369 PALIMPORT int __cdecl vsprintf(char *, const char *, va_list);
5370 PALIMPORT int __cdecl _snprintf(char *, size_t, const char *, ...);
5371 PALIMPORT int __cdecl _vsnprintf(char *, size_t, const char *, va_list);
5372 PALIMPORT int __cdecl sscanf(const char *, const char *, ...);
5373 PALIMPORT char * __cdecl _strlwr(char *);
5374 PALIMPORT int __cdecl atoi(const char *);
5375 PALIMPORT LONG __cdecl atol(const char *);
5376 PALIMPORT ULONG __cdecl strtoul(const char *, char **, int);
5377 PALIMPORT double __cdecl atof(const char *);
5378 PALIMPORT char * __cdecl _gcvt_s(char *, int, double, int);
5379 PALIMPORT char * __cdecl _ecvt(double, int, int *, int *);
5380 PALIMPORT double __cdecl strtod(const char *, char **);
5381 PALIMPORT int __cdecl isprint(int);
5382 PALIMPORT int __cdecl isspace(int);
5383 PALIMPORT int __cdecl isalpha(int);
5384 PALIMPORT int __cdecl isalnum(int);
5385 PALIMPORT int __cdecl isdigit(int);
5386 PALIMPORT int __cdecl isxdigit(int);
5387 PALIMPORT int __cdecl isupper(int);
5388 PALIMPORT int __cdecl islower(int);
5389 PALIMPORT int __cdecl __iscsym(int);
5390 PALIMPORT int __cdecl tolower(int);
5391 PALIMPORT int __cdecl toupper(int);
5392
5393 PALIMPORT size_t __cdecl _mbslen(const unsigned char *);
5394 PALIMPORT unsigned char * __cdecl _mbsinc(const unsigned char *);
5395 PALIMPORT unsigned char * __cdecl _mbsninc(const unsigned char *, size_t);
5396 PALIMPORT unsigned char * __cdecl _mbsdec(const unsigned char *, const unsigned char *);
5397
5398 PALIMPORT size_t __cdecl wcslen(const wchar_t *);
5399 PALIMPORT int __cdecl wcscmp(const wchar_t*, const wchar_t*);
5400 PALIMPORT int __cdecl wcsncmp(const wchar_t *, const wchar_t *, size_t);
5401 PALIMPORT int __cdecl _wcsicmp(const wchar_t *, const wchar_t*);
5402 PALIMPORT int __cdecl _wcsnicmp(const wchar_t *, const wchar_t *, size_t);
5403 PALIMPORT wchar_t * __cdecl wcscat(wchar_t *, const wchar_t *);
5404 PALIMPORT wchar_t * __cdecl wcsncat(wchar_t *, const wchar_t *, size_t);
5405 PALIMPORT wchar_t * __cdecl wcscpy(wchar_t *, const wchar_t *);
5406 PALIMPORT wchar_t * __cdecl wcsncpy(wchar_t *, const wchar_t *, size_t);
5407 PALIMPORT const wchar_t * __cdecl wcschr(const wchar_t *, wchar_t);
5408 PALIMPORT const wchar_t * __cdecl wcsrchr(const wchar_t *, wchar_t);
5409 PALIMPORT wchar_t _WConst_return * __cdecl wcspbrk(const wchar_t *, const wchar_t *);
5410 PALIMPORT wchar_t _WConst_return * __cdecl wcsstr(const wchar_t *, const wchar_t *);
5411 PALIMPORT wchar_t * __cdecl wcstok(wchar_t *, const wchar_t *);
5412 PALIMPORT size_t __cdecl wcscspn(const wchar_t *, const wchar_t *);
5413 PALIMPORT int __cdecl swprintf(wchar_t *, const wchar_t *, ...);
5414 PALIMPORT int __cdecl vswprintf(wchar_t *, const wchar_t *, va_list);
5415 PALIMPORT int __cdecl _snwprintf(wchar_t *, size_t, const wchar_t *, ...);
5416 PALIMPORT int __cdecl _vsnwprintf(wchar_t *, size_t, const wchar_t *, va_list);
5417 PALIMPORT int __cdecl swscanf(const wchar_t *, const wchar_t *, ...);
5418 PALIMPORT wchar_t * __cdecl _wcslwr(wchar_t *);
5419 PALIMPORT LONG __cdecl wcstol(const wchar_t *, wchar_t **, int);
5420 PALIMPORT ULONG __cdecl wcstoul(const wchar_t *, wchar_t **, int);
5421 PALIMPORT ULONGLONG _wcstoui64(const wchar_t *, wchar_t **, int);
5422 PALIMPORT wchar_t * __cdecl _itow(int, wchar_t *, int);
5423 PALIMPORT wchar_t * __cdecl _i64tow(__int64, wchar_t *, int);
5424 PALIMPORT wchar_t * __cdecl _ui64tow(unsigned __int64, wchar_t *, int);
5425 PALIMPORT int __cdecl _wtoi(const wchar_t *);
5426 PALIMPORT size_t __cdecl wcsspn (const wchar_t *, const wchar_t *);
5427 PALIMPORT double __cdecl wcstod(const wchar_t *, wchar_t **);
5428 PALIMPORT int __cdecl iswalpha(wchar_t);
5429 PALIMPORT int __cdecl iswprint(wchar_t);
5430 PALIMPORT int __cdecl iswupper(wchar_t);
5431 PALIMPORT int __cdecl iswspace(wchar_t);
5432 PALIMPORT int __cdecl iswdigit(wchar_t);
5433 PALIMPORT int __cdecl iswxdigit(wchar_t);
5434 PALIMPORT wchar_t __cdecl towlower(wchar_t);
5435 PALIMPORT wchar_t __cdecl towupper(wchar_t);
5436
5437
5438 #ifdef __cplusplus
5439 extern "C++" {
5440 inline wchar_t *wcschr(wchar_t *_S, wchar_t _C)
5441         {return ((wchar_t *)wcschr((const wchar_t *)_S, _C)); }
5442 inline wchar_t *wcsrchr(wchar_t *_S, wchar_t _C)
5443         {return ((wchar_t *)wcsrchr((const wchar_t *)_S, _C)); }
5444 inline wchar_t *wcspbrk(wchar_t *_S, const wchar_t *_P)
5445         {return ((wchar_t *)wcspbrk((const wchar_t *)_S, _P)); }
5446 inline wchar_t *wcsstr(wchar_t *_S, const wchar_t *_P)
5447         {return ((wchar_t *)wcsstr((const wchar_t *)_S, _P)); }
5448 }
5449 #endif
5450
5451 PALIMPORT unsigned int __cdecl _rotl(unsigned int, int);
5452 // On 64 bit unix, make the long an int.
5453 #ifdef BIT64
5454 #define _lrotl _rotl
5455 #endif // BIT64
5456
5457 PALIMPORT unsigned int __cdecl _rotr(unsigned int, int);
5458 PALIMPORT int __cdecl abs(int);
5459 PALIMPORT double __cdecl fabs(double); 
5460 PALIMPORT LONG __cdecl labs(LONG);
5461 // clang complains if this is declared with __int64
5462 PALIMPORT long long __cdecl llabs(long long);
5463
5464 PALIMPORT double __cdecl sqrt(double);
5465 PALIMPORT double __cdecl log(double);
5466 PALIMPORT double __cdecl log10(double);
5467 PALIMPORT double __cdecl exp(double);
5468 PALIMPORT double __cdecl pow(double, double);
5469 PALIMPORT double __cdecl acos(double);
5470 PALIMPORT double __cdecl asin(double);
5471 PALIMPORT double __cdecl atan(double);
5472 PALIMPORT double __cdecl atan2(double,double);
5473 PALIMPORT double __cdecl cos(double);
5474 PALIMPORT double __cdecl sin(double);
5475 PALIMPORT double __cdecl tan(double);
5476 PALIMPORT double __cdecl cosh(double);
5477 PALIMPORT double __cdecl sinh(double);
5478 PALIMPORT double __cdecl tanh(double);
5479 PALIMPORT double __cdecl fmod(double, double);
5480 PALIMPORT double __cdecl floor(double);
5481 PALIMPORT double __cdecl ceil(double);
5482 PALIMPORT double __cdecl fabs(double);
5483 PALIMPORT double __cdecl modf(double, double *);
5484 PALIMPORT float __cdecl modff(float, float *);
5485
5486 PALIMPORT int __cdecl _finite(double);
5487 PALIMPORT int __cdecl _isnan(double);
5488 PALIMPORT double __cdecl _copysign(double, double);
5489
5490 #ifdef __cplusplus
5491 extern "C++" {
5492 inline float fabsf(float _X)
5493 {
5494     return ((float)fabs((double)_X));
5495 }
5496
5497 #ifdef BIT64
5498 inline __int64 abs(__int64 _X) {
5499     return llabs(_X);
5500 }
5501 #endif
5502 }
5503 #endif
5504
5505 PALIMPORT void * __cdecl malloc(size_t);
5506 PALIMPORT void   __cdecl free(void *);
5507 PALIMPORT void * __cdecl realloc(void *, size_t);
5508 PALIMPORT char * __cdecl _strdup(const char *);
5509
5510 #if defined(_MSC_VER)
5511 #define alloca _alloca
5512 #elif defined(PLATFORM_UNIX)
5513 #define _alloca alloca
5514 #else
5515 // MingW
5516 #define _alloca __builtin_alloca
5517 #define alloca __builtin_alloca
5518 #endif //_MSC_VER
5519
5520 #if defined(__GNUC__) && defined(PLATFORM_UNIX)
5521 // we set -fno-builtin on the command line. This requires that if
5522 // we use alloca, with either have to call __builtin_alloca, or
5523 // ensure that the alloca call doesn't happen in code which is
5524 // modifying the stack (such as "memset (alloca(x), y, z)"
5525
5526 #define alloca  __builtin_alloca
5527 #endif // __GNUC__
5528
5529 #define max(a, b) (((a) > (b)) ? (a) : (b))
5530 #define min(a, b) (((a) < (b)) ? (a) : (b))
5531
5532 PALIMPORT PAL_NORETURN void __cdecl exit(int);
5533 int __cdecl atexit(void (__cdecl *function)(void));
5534
5535 PALIMPORT void __cdecl qsort(void *, size_t, size_t, int (__cdecl *)(const void *, const void *));
5536 PALIMPORT void * __cdecl bsearch(const void *, const void *, size_t, size_t,
5537 int (__cdecl *)(const void *, const void *));
5538
5539 PALIMPORT void __cdecl _splitpath(const char *, char *, char *, char *, char *);
5540 PALIMPORT void __cdecl _wsplitpath(const wchar_t *, wchar_t *, wchar_t *, wchar_t *, wchar_t *);
5541 PALIMPORT void __cdecl _makepath(char *, const char *, const char *, const char *, const char *);
5542 PALIMPORT void __cdecl _wmakepath(wchar_t *, const wchar_t *, const wchar_t *, const wchar_t *, const wchar_t *);
5543 PALIMPORT char * __cdecl _fullpath(char *, const char *, size_t);
5544
5545 PALIMPORT void __cdecl _swab(char *, char *, int);
5546
5547 PALIMPORT time_t __cdecl time(time_t *);
5548
5549 struct tm {
5550         int tm_sec;     /* seconds after the minute - [0,59] */
5551         int tm_min;     /* minutes after the hour - [0,59] */
5552         int tm_hour;    /* hours since midnight - [0,23] */
5553         int tm_mday;    /* day of the month - [1,31] */
5554         int tm_mon;     /* months since January - [0,11] */
5555         int tm_year;    /* years since 1900 */
5556         int tm_wday;    /* days since Sunday - [0,6] */
5557         int tm_yday;    /* days since January 1 - [0,365] */
5558         int tm_isdst;   /* daylight savings time flag */
5559         };
5560
5561 PALIMPORT struct tm * __cdecl localtime(const time_t *);
5562 PALIMPORT time_t __cdecl mktime(struct tm *);
5563 PALIMPORT char * __cdecl ctime(const time_t *);
5564
5565 PALIMPORT int __cdecl _open_osfhandle(INT_PTR, int);
5566 PALIMPORT int __cdecl _close(int);
5567
5568 PALIMPORT int __cdecl _flushall();
5569
5570 struct _FILE;
5571 typedef struct _FILE FILE;
5572
5573 #define SEEK_SET    0
5574 #define SEEK_CUR    1
5575 #define SEEK_END    2
5576
5577 /* Locale categories */
5578 #define LC_ALL          0
5579 #define LC_COLLATE      1
5580 #define LC_CTYPE        2
5581 #define LC_MONETARY     3
5582 #define LC_NUMERIC      4
5583 #define LC_TIME         5
5584
5585 #define _IOFBF  0       /* setvbuf should set fully buffered */
5586 #define _IOLBF  1       /* setvbuf should set line buffered */
5587 #define _IONBF  2       /* setvbuf should set unbuffered */
5588
5589 PALIMPORT int __cdecl fclose(FILE *);
5590 PALIMPORT void __cdecl setbuf(FILE *, char*);
5591 PALIMPORT int __cdecl fflush(FILE *);
5592 PALIMPORT size_t __cdecl fwrite(const void *, size_t, size_t, FILE *);
5593 PALIMPORT size_t __cdecl fread(void *, size_t, size_t, FILE *);
5594 PALIMPORT char * __cdecl fgets(char *, int, FILE *);
5595 PALIMPORT wchar_t * __cdecl fgetws(wchar_t *, int, FILE *);
5596 PALIMPORT int __cdecl fputs(const char *, FILE *);
5597 PALIMPORT int __cdecl fputc(int c, FILE *stream);
5598 PALIMPORT int __cdecl putchar(int c);
5599 PALIMPORT int __cdecl fprintf(FILE *, const char *, ...);
5600 PALIMPORT int __cdecl fwprintf(FILE *, const wchar_t *, ...);
5601 PALIMPORT int __cdecl vfprintf(FILE *, const char *, va_list);
5602 PALIMPORT int __cdecl vfwprintf(FILE *, const wchar_t *, va_list);
5603 PALIMPORT int __cdecl _getw(FILE *);
5604 PALIMPORT int __cdecl _putw(int, FILE *);
5605 PALIMPORT int __cdecl fseek(FILE *, LONG, int);
5606 PALIMPORT int __cdecl fgetpos(FILE *, fpos_t *);
5607 PALIMPORT int __cdecl fsetpos(FILE *, const fpos_t *);
5608 PALIMPORT LONG __cdecl ftell(FILE *);
5609 PALIMPORT int __cdecl feof(FILE *);
5610 PALIMPORT int __cdecl ferror(FILE *);
5611 PALIMPORT FILE * __cdecl fopen(const char *, const char *);
5612 PALIMPORT FILE * __cdecl _fdopen(int, const char *);
5613 PALIMPORT FILE * __cdecl _wfopen(const wchar_t *, const wchar_t *);
5614 PALIMPORT FILE * __cdecl _wfsopen(const wchar_t *, const wchar_t *, int);
5615 PALIMPORT int __cdecl getc(FILE *stream);
5616 PALIMPORT int __cdecl fgetc(FILE *stream);
5617 PALIMPORT int __cdecl ungetc(int c, FILE *stream);
5618 PALIMPORT int __cdecl setvbuf(FILE *stream, char *, int, size_t);
5619
5620 /* Maximum value that can be returned by the rand function. */
5621
5622 #define RAND_MAX 0x7fff
5623
5624 PALIMPORT int    __cdecl rand(void);
5625 PALIMPORT void   __cdecl srand(unsigned int);
5626
5627 PALIMPORT int __cdecl printf(const char *, ...);
5628 PALIMPORT int __cdecl vprintf(const char *, va_list);
5629 PALIMPORT int __cdecl wprintf(const wchar_t*, ...);
5630
5631 #ifdef _MSC_VER
5632 #define PAL_get_caller _MSC_VER
5633 #else
5634 #define PAL_get_caller 0
5635 #endif
5636
5637 PALIMPORT FILE * __cdecl PAL_get_stdout(int caller);
5638 PALIMPORT FILE * __cdecl PAL_get_stdin(int caller);
5639 PALIMPORT FILE * __cdecl PAL_get_stderr(int caller);
5640 PALIMPORT int * __cdecl PAL_errno(int caller);
5641
5642 #define stdout (PAL_get_stdout(PAL_get_caller))
5643 #define stdin  (PAL_get_stdin(PAL_get_caller))
5644 #define stderr (PAL_get_stderr(PAL_get_caller))
5645 #define errno   (*PAL_errno(PAL_get_caller))
5646
5647 PALIMPORT char * __cdecl getenv(const char *);
5648 PALIMPORT int __cdecl _putenv(const char *);
5649
5650 #define ERANGE          34
5651
5652 /******************* PAL-specific I/O completion port *****************/
5653
5654 typedef struct _PAL_IOCP_CPU_INFORMATION {
5655     union {
5656         FILETIME ftLastRecordedIdleTime;
5657         FILETIME ftLastRecordedCurrentTime;
5658     } LastRecordedTime;
5659     FILETIME ftLastRecordedKernelTime;
5660     FILETIME ftLastRecordedUserTime;
5661 } PAL_IOCP_CPU_INFORMATION;
5662
5663 PALIMPORT
5664 INT
5665 PALAPI
5666 PAL_GetCPUBusyTime(
5667     IN OUT PAL_IOCP_CPU_INFORMATION *lpPrevCPUInfo);
5668
5669 /****************PAL Perf functions for PInvoke*********************/
5670 #if PAL_PERF
5671 PALIMPORT
5672 VOID
5673 PALAPI
5674 PAL_EnableProcessProfile(VOID);
5675
5676 PALIMPORT
5677 VOID
5678 PALAPI
5679 PAL_DisableProcessProfile(VOID);
5680
5681 PALIMPORT
5682 BOOL
5683 PALAPI
5684 PAL_IsProcessProfileEnabled(VOID);
5685
5686 PALIMPORT
5687 INT64
5688 PALAPI
5689 PAL_GetCpuTickCount(VOID);
5690 #endif // PAL_PERF
5691
5692 /******************* PAL functions for SIMD extensions *****************/
5693
5694 PALIMPORT
5695 unsigned int _mm_getcsr(void);
5696
5697 PALIMPORT
5698 void _mm_setcsr(unsigned int i);
5699
5700 /******************* PAL side-by-side support  ************************/
5701
5702 #ifdef FEATURE_PAL_SXS
5703 //
5704 // Some versions of the PAL support several PALs side-by-side
5705 // in the process.  To avoid those PALs interfering with one
5706 // another, they need to be told by clients when they are active
5707 // and when they are not.
5708 //
5709
5710 // To avoid performance problems incurred by swapping thread
5711 // exception ports every time we leave the PAL, there's also
5712 // the concept of entering/leaving the PAL at its top boundary
5713 // (entering down/leaving up) or at the bottom boundary
5714 // (leaving down/entering up).
5715
5716 typedef enum _PAL_Boundary {
5717     PAL_BoundaryTop,            // closer to main()
5718     PAL_BoundaryBottom,         // closer to execution
5719     PAL_BoundaryEH,             // out-of-band during EH
5720     
5721     PAL_BoundaryMax = PAL_BoundaryEH
5722 } PAL_Boundary;
5723
5724 // This function needs to be called on a thread when it enters
5725 // a region of code that depends on this instance of the PAL
5726 // in the process, and the current thread may or may not be
5727 // known to the PAL.  This function can fail (for something else
5728 // than an internal error) if this is the first time that the
5729 // current thread entered this PAL.  Note that PAL_Initialize
5730 // implies a call to this function.  Does not modify LastError.
5731 PALIMPORT
5732 DWORD
5733 PALAPI
5734 PAL_Enter(PAL_Boundary boundary);
5735
5736 // Returns TRUE if we this thread has already entered the PAL,
5737 // returns FALSE if we have not entered the PAL.
5738 PALIMPORT
5739 BOOL
5740 PALAPI
5741 PAL_HasEntered();
5742
5743 // Equivalent to PAL_Enter(PAL_BoundaryTop) and is for stub
5744 // code generation use.
5745 PALIMPORT
5746 DWORD
5747 PALAPI
5748 PAL_EnterTop();
5749
5750 // This function needs to be called on a thread when it enters
5751 // a region of code that depends on this instance of the PAL
5752 // in the process, and the current thread is already known to
5753 // the PAL.  Does not modify LastError.
5754 PALIMPORT
5755 VOID
5756 PALAPI
5757 PAL_Reenter(PAL_Boundary boundary);
5758
5759 // This function needs to be called on a thread when it enters
5760 // a region of code that depends on this instance of the PAL
5761 // in the process, and it is unknown whether the current thread
5762 // is already running in the PAL.  Returns TRUE if and only if
5763 // the thread was not running in the PAL previously.  Does not
5764 // modify LastError.
5765 PALIMPORT
5766 BOOL
5767 PALAPI
5768 PAL_ReenterForEH(VOID);
5769
5770 // This function needs to be called on a thread when it leaves
5771 // a region of code that depends on this instance of the PAL
5772 // in the process.  Does not modify LastError.
5773 PALIMPORT
5774 VOID
5775 PALAPI
5776 PAL_Leave(PAL_Boundary boundary);
5777
5778 // This function is equivalent to PAL_Leave(PAL_BoundaryBottom)
5779 // and is available to limit the creation of stub code.
5780 PALIMPORT
5781 VOID
5782 PALAPI
5783 PAL_LeaveBottom();
5784
5785 // This function is equivalent to PAL_Leave(PAL_BoundaryTop)
5786 // and is available to limit the creation of stub code.
5787 PALIMPORT
5788 VOID
5789 PALAPI
5790 PAL_LeaveTop();
5791
5792 // Returns TRUE if the argument HMODULE denotes the PAL itself.
5793 PALIMPORT
5794 BOOL
5795 PALAPI
5796 PAL_IsSelf(IN HMODULE);
5797
5798 #ifdef  __cplusplus
5799 //
5800 // A holder to enter the PAL for a specific region of code.
5801 // Previously, we must have been executing outside the PAL
5802 // (unless fEnter is set to FALSE).
5803 //
5804 class PAL_EnterHolder
5805 {
5806 private:
5807     BOOL m_fEntered;
5808     DWORD m_palError;
5809 public:
5810     PAL_EnterHolder(BOOL fEnter = TRUE) : m_palError(ERROR_SUCCESS)
5811     {
5812         if (fEnter)
5813         {
5814             m_palError = PAL_Enter(PAL_BoundaryTop);
5815             m_fEntered = m_palError == ERROR_SUCCESS;
5816         }
5817         else
5818         {
5819             m_fEntered = FALSE;
5820         }
5821     }
5822
5823     ~PAL_EnterHolder()
5824     {
5825         if (m_fEntered)
5826         {
5827             PAL_Leave(PAL_BoundaryTop);
5828         }
5829     }
5830
5831     DWORD GetError()
5832     {
5833         return m_palError;
5834     }
5835     
5836     void SuppressRelease()
5837     {
5838         // Used to avoid calling PAL_Leave() when 
5839         // another code path will explicitly do so.
5840         m_fEntered = FALSE;
5841     }
5842 };
5843
5844 class PAL_LeaveHolder
5845 {
5846 public:
5847     PAL_LeaveHolder()
5848     {
5849         PAL_Leave(PAL_BoundaryBottom);
5850     }
5851
5852     ~PAL_LeaveHolder()
5853     {
5854         PAL_Reenter(PAL_BoundaryBottom);
5855     }
5856 };
5857 #endif // __cplusplus
5858
5859 #else // FEATURE_PAL_SXS
5860
5861 #define PAL_Enter(boundary) ERROR_SUCCESS
5862 #define PAL_Reenter(boundary)
5863 #define PAL_Leave(boundary)
5864
5865 #ifdef __cplusplus
5866 class PAL_EnterHolder {
5867 public:
5868     // using constructor to suppress the "unused variable" warnings
5869     PAL_EnterHolder(){}
5870 };
5871 class PAL_LeaveHolder {
5872 public:
5873     // using constructor to suppress the "unused variable" warnings
5874     PAL_LeaveHolder(){}
5875 };
5876 #endif // __cplusplus
5877
5878 #endif // FEATURE_PAL_SXS
5879
5880 #if FEATURE_PAL_SXS
5881
5882 #include "pal_unwind.h"
5883
5884 // A pretend exception code that we use to stand for external exceptions,
5885 // such as a C++ exception leaking across a P/Invoke boundary into
5886 // COMPlusFrameHandler.
5887 #define EXCEPTION_FOREIGN 0xe0455874    // 0xe0000000 | 'EXT'
5888
5889 // Test whether the argument exceptionObject is an SEH exception.  If it is,
5890 // return the associated exception pointers.  If it is not, return NULL.
5891 PALIMPORT
5892 EXCEPTION_POINTERS *
5893 PALAPI
5894 PAL_GetExceptionPointers(struct _Unwind_Exception *exceptionObject);
5895
5896 typedef void (*PFN_PAL_BODY)(void *pvParam);
5897
5898 typedef struct _PAL_DISPATCHER_CONTEXT {
5899     _Unwind_Action actions;
5900     struct _Unwind_Exception *exception_object;
5901     struct _Unwind_Context *context;
5902 } PAL_DISPATCHER_CONTEXT;
5903
5904 typedef EXCEPTION_DISPOSITION (*PFN_PAL_EXCEPTION_FILTER)(
5905     EXCEPTION_POINTERS *ExceptionPointers,
5906     PAL_DISPATCHER_CONTEXT *DispatcherContext,
5907     void *pvParam);
5908
5909 #ifdef __cplusplus
5910
5911 struct PAL_SEHException
5912 {
5913 public:
5914     // Note that the following two are actually embedded in this heap-allocated
5915     // instance - in contrast to Win32, where the exception record would usually
5916     // be allocated on the stack.  This is needed because foreign cleanup handlers
5917     // partially unwind the stack on the second pass.
5918     EXCEPTION_POINTERS ExceptionPointers;
5919     EXCEPTION_RECORD ExceptionRecord;
5920     CONTEXT ContextRecord;
5921
5922     PAL_SEHException(EXCEPTION_RECORD *pExceptionRecord, CONTEXT *pContextRecord)
5923     {
5924         ExceptionPointers.ExceptionRecord = &ExceptionRecord;
5925         ExceptionPointers.ContextRecord = &ContextRecord;
5926         ExceptionRecord = *pExceptionRecord;
5927         ContextRecord = *pContextRecord;
5928     }
5929 };
5930
5931 #endif // __cplusplus
5932
5933 // Start of a try block for exceptions raised by RaiseException
5934 #define PAL_TRY(__ParamType, __paramDef, __paramRef)                            \
5935 {                                                                               \
5936     __ParamType __param = __paramRef;                                           \
5937     auto tryBlock = [](__ParamType __paramDef)                                  \
5938     {
5939
5940 // Start of an exception handler. If an exception raised by the RaiseException 
5941 // occurs in the try block and the disposition is EXCEPTION_EXECUTE_HANDLER, 
5942 // the handler code is executed. If the disposition is EXCEPTION_CONTINUE_SEARCH,
5943 // the exception is rethrown. The EXCEPTION_CONTINUE_EXECUTION disposition is
5944 // not supported.
5945 #define PAL_EXCEPT(dispositionExpression)                                       \
5946     };                                                                          \
5947     const bool isFinally = false;                                               \
5948     auto finallyBlock = []() {};                                                \
5949     try                                                                         \
5950     {                                                                           \
5951         tryBlock(__param);                                                      \
5952     }                                                                           \
5953     catch (PAL_SEHException& ex)                                                \
5954     {                                                                           \
5955         EXCEPTION_DISPOSITION disposition = dispositionExpression;              \
5956         _ASSERTE(disposition != EXCEPTION_CONTINUE_EXECUTION);                  \
5957         if (disposition == EXCEPTION_CONTINUE_SEARCH)                           \
5958         {                                                                       \
5959             throw;                                                              \
5960         }
5961
5962
5963 // Start of an exception handler. It works the same way as the PAL_EXCEPT except
5964 // that the disposition is obtained by calling the specified filter.
5965 #define PAL_EXCEPT_FILTER(filter) PAL_EXCEPT(filter(&ex.ExceptionPointers, __param))
5966
5967 // Start of a finally block. The finally block is executed both when the try block
5968 // finishes or when an exception is raised using the RaiseException in it.
5969 #define PAL_FINALLY                     \
5970     };                                  \
5971     const bool isFinally = true;        \
5972     auto finallyBlock = [&]()           \
5973     {                       
5974
5975 // End of an except or a finally block.
5976 #define PAL_ENDTRY                      \
5977     };                                  \
5978     if (isFinally)                      \
5979     {                                   \
5980         try                             \
5981         {                               \
5982             tryBlock(__param);          \
5983         }                               \
5984         catch (...)                     \
5985         {                               \
5986             finallyBlock();             \
5987             throw;                      \
5988         }                               \
5989         finallyBlock();                 \
5990     }                                   \
5991 }
5992
5993 #endif // FEATURE_PAL_SXS
5994
5995 #define PAL_CPP_THROW(type, obj) { throw obj; }
5996 #define PAL_CPP_RETHROW { throw; }
5997 #define PAL_CPP_TRY                     try {
5998 #define PAL_CPP_CATCH_EXCEPTION(ident)  } catch (Exception *ident) { PAL_Reenter(PAL_BoundaryBottom);
5999 #define PAL_CPP_CATCH_EXCEPTION_NOARG   } catch (Exception *) { PAL_Reenter(PAL_BoundaryBottom);
6000 #define PAL_CPP_CATCH_DERIVED(type, ident) } catch (type *ident) { PAL_Reenter(PAL_BoundaryBottom);
6001 #define PAL_CPP_CATCH_ALL               } catch (...) { PAL_Reenter(PAL_BoundaryBottom);
6002 #define PAL_CPP_ENDTRY                  }
6003
6004 #ifdef _MSC_VER
6005 #pragma warning(disable:4611) // interaction between '_setjmp' and C++ object destruction is non-portable
6006 #endif
6007
6008 #ifdef FEATURE_PAL_SXS
6009
6010 #define PAL_TRY_FOR_DLLMAIN(ParamType, paramDef, paramRef, _reason) PAL_TRY(ParamType, paramDef, paramRef)
6011
6012 #else // FEATURE_PAL_SXS
6013
6014 #define PAL_TRY(ParamType, paramDef, paramRef)                          \
6015     {                                                                   \
6016         ParamType __param = paramRef;                                   \
6017         ParamType paramDef; paramDef = __param;                         \
6018         try {
6019 #define PAL_TRY_FOR_DLLMAIN(ParamType, paramDef, paramRef, _reason)     \
6020     {                                                                   \
6021         ParamType __param = paramRef;                                   \
6022         ParamType paramDef; paramDef = __param;                         \
6023         try {
6024 #define PAL_ENDTRY                                                      \
6025         }                                                               \
6026     }
6027
6028 #endif // FEATURE_PAL_SXS
6029
6030 #define EXCEPTION_CONTINUE_SEARCH   0
6031 #define EXCEPTION_EXECUTE_HANDLER   1
6032 #define EXCEPTION_CONTINUE_EXECUTION -1
6033
6034 // Platform-specific library naming
6035 // 
6036 #ifdef PLATFORM_UNIX
6037 #ifdef __APPLE__
6038 #define MAKEDLLNAME_W(name) u"lib" name u".dylib"
6039 #define MAKEDLLNAME_A(name)  "lib" name  ".dylib"
6040 #elif defined(_AIX)
6041 #define MAKEDLLNAME_W(name) L"lib" name L".a"
6042 #define MAKEDLLNAME_A(name)  "lib" name  ".a"
6043 #elif defined(__hppa__) || defined(_IA64_)
6044 #define MAKEDLLNAME_W(name) L"lib" name L".sl"
6045 #define MAKEDLLNAME_A(name)  "lib" name  ".sl"
6046 #else
6047 #define MAKEDLLNAME_W(name) u"lib" name u".so"
6048 #define MAKEDLLNAME_A(name)  "lib" name  ".so"
6049 #endif
6050 #else
6051 #define MAKEDLLNAME_W(name) name L".dll"
6052 #define MAKEDLLNAME_A(name) name  ".dll"
6053 #endif
6054
6055 #ifdef UNICODE
6056 #define MAKEDLLNAME(x) MAKEDLLNAME_W(x)
6057 #else
6058 #define MAKEDLLNAME(x) MAKEDLLNAME_A(x)
6059 #endif
6060
6061 #define DBG_EXCEPTION_HANDLED            ((DWORD   )0x00010001L)    
6062 #define DBG_CONTINUE                     ((DWORD   )0x00010002L)    
6063 #define DBG_EXCEPTION_NOT_HANDLED        ((DWORD   )0x80010001L)    
6064
6065 #define DBG_TERMINATE_THREAD             ((DWORD   )0x40010003L)    
6066 #define DBG_TERMINATE_PROCESS            ((DWORD   )0x40010004L)    
6067 #define DBG_CONTROL_C                    ((DWORD   )0x40010005L)    
6068 #define DBG_RIPEXCEPTION                 ((DWORD   )0x40010007L)    
6069 #define DBG_CONTROL_BREAK                ((DWORD   )0x40010008L)    
6070 #define DBG_COMMAND_EXCEPTION            ((DWORD   )0x40010009L)    
6071
6072 #define STATUS_USER_APC                  ((DWORD   )0x000000C0L)
6073 #define STATUS_GUARD_PAGE_VIOLATION      ((DWORD   )0x80000001L)
6074 #define STATUS_DATATYPE_MISALIGNMENT     ((DWORD   )0x80000002L)
6075 #define STATUS_BREAKPOINT                ((DWORD   )0x80000003L)
6076 #define STATUS_SINGLE_STEP               ((DWORD   )0x80000004L)
6077 #define STATUS_LONGJUMP                  ((DWORD   )0x80000026L)
6078 #define STATUS_UNWIND_CONSOLIDATE        ((DWORD   )0x80000029L)
6079 #define STATUS_ACCESS_VIOLATION          ((DWORD   )0xC0000005L)
6080 #define STATUS_IN_PAGE_ERROR             ((DWORD   )0xC0000006L)
6081 #define STATUS_INVALID_HANDLE            ((DWORD   )0xC0000008L)
6082 #define STATUS_NO_MEMORY                 ((DWORD   )0xC0000017L)
6083 #define STATUS_ILLEGAL_INSTRUCTION       ((DWORD   )0xC000001DL)
6084 #define STATUS_NONCONTINUABLE_EXCEPTION  ((DWORD   )0xC0000025L)
6085 #define STATUS_INVALID_DISPOSITION       ((DWORD   )0xC0000026L)
6086 #define STATUS_ARRAY_BOUNDS_EXCEEDED     ((DWORD   )0xC000008CL)
6087 #define STATUS_FLOAT_DENORMAL_OPERAND    ((DWORD   )0xC000008DL)
6088 #define STATUS_FLOAT_DIVIDE_BY_ZERO      ((DWORD   )0xC000008EL)
6089 #define STATUS_FLOAT_INEXACT_RESULT      ((DWORD   )0xC000008FL)
6090 #define STATUS_FLOAT_INVALID_OPERATION   ((DWORD   )0xC0000090L)
6091 #define STATUS_FLOAT_OVERFLOW            ((DWORD   )0xC0000091L)
6092 #define STATUS_FLOAT_STACK_CHECK         ((DWORD   )0xC0000092L)
6093 #define STATUS_FLOAT_UNDERFLOW           ((DWORD   )0xC0000093L)
6094 #define STATUS_INTEGER_DIVIDE_BY_ZERO    ((DWORD   )0xC0000094L)
6095 #define STATUS_INTEGER_OVERFLOW          ((DWORD   )0xC0000095L)
6096 #define STATUS_PRIVILEGED_INSTRUCTION    ((DWORD   )0xC0000096L)
6097 #define STATUS_STACK_OVERFLOW            ((DWORD   )0xC00000FDL)
6098 #define STATUS_CONTROL_C_EXIT            ((DWORD   )0xC000013AL)
6099
6100 #define WAIT_IO_COMPLETION                  STATUS_USER_APC
6101
6102 #define EXCEPTION_ACCESS_VIOLATION          STATUS_ACCESS_VIOLATION
6103 #define EXCEPTION_DATATYPE_MISALIGNMENT     STATUS_DATATYPE_MISALIGNMENT
6104 #define EXCEPTION_BREAKPOINT                STATUS_BREAKPOINT
6105 #define EXCEPTION_SINGLE_STEP               STATUS_SINGLE_STEP
6106 #define EXCEPTION_ARRAY_BOUNDS_EXCEEDED     STATUS_ARRAY_BOUNDS_EXCEEDED
6107 #define EXCEPTION_FLT_DENORMAL_OPERAND      STATUS_FLOAT_DENORMAL_OPERAND
6108 #define EXCEPTION_FLT_DIVIDE_BY_ZERO        STATUS_FLOAT_DIVIDE_BY_ZERO
6109 #define EXCEPTION_FLT_INEXACT_RESULT        STATUS_FLOAT_INEXACT_RESULT
6110 #define EXCEPTION_FLT_INVALID_OPERATION     STATUS_FLOAT_INVALID_OPERATION
6111 #define EXCEPTION_FLT_OVERFLOW              STATUS_FLOAT_OVERFLOW
6112 #define EXCEPTION_FLT_STACK_CHECK           STATUS_FLOAT_STACK_CHECK
6113 #define EXCEPTION_FLT_UNDERFLOW             STATUS_FLOAT_UNDERFLOW
6114 #define EXCEPTION_INT_DIVIDE_BY_ZERO        STATUS_INTEGER_DIVIDE_BY_ZERO
6115 #define EXCEPTION_INT_OVERFLOW              STATUS_INTEGER_OVERFLOW
6116 #define EXCEPTION_PRIV_INSTRUCTION          STATUS_PRIVILEGED_INSTRUCTION
6117 #define EXCEPTION_IN_PAGE_ERROR             STATUS_IN_PAGE_ERROR
6118 #define EXCEPTION_ILLEGAL_INSTRUCTION       STATUS_ILLEGAL_INSTRUCTION
6119 #define EXCEPTION_NONCONTINUABLE_EXCEPTION  STATUS_NONCONTINUABLE_EXCEPTION
6120 #define EXCEPTION_STACK_OVERFLOW            STATUS_STACK_OVERFLOW
6121 #define EXCEPTION_INVALID_DISPOSITION       STATUS_INVALID_DISPOSITION
6122 #define EXCEPTION_GUARD_PAGE                STATUS_GUARD_PAGE_VIOLATION
6123 #define EXCEPTION_INVALID_HANDLE            STATUS_INVALID_HANDLE
6124
6125 #define CONTROL_C_EXIT                      STATUS_CONTROL_C_EXIT
6126
6127 /*  These are from the <FCNTL.H> file in windows.
6128     They are needed for _open_osfhandle.*/
6129 #define _O_RDONLY   0x0000
6130 #define _O_APPEND   0x0008
6131 #define _O_TEXT     0x4000
6132 #define _O_BINARY   0x8000
6133
6134 #ifdef  __cplusplus
6135 }
6136 #endif
6137
6138 #endif // __PAL_H__