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