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.
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.
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
21 PAL_IMPLEMENTATION - define it when implementing the PAL. Otherwise
22 leave it undefined when consuming the PAL.
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.
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.
39 #ifdef PAL_STDCPP_COMPAT
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
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.
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)
70 #include <pal_char16.h>
71 #include <pal_error.h>
72 #include <pal_mstypes.h>
74 /******************* Processor-specific glue *****************************/
78 #if defined(__i686__) && !defined(_M_IX86)
80 #elif defined(__i586__) && !defined(_M_IX86)
82 #elif defined(__i486__) && !defined(_M_IX86)
84 #elif defined(__i386__) && !defined(_M_IX86)
86 #elif defined(__ppc__) && !defined(_M_PPC)
88 #elif defined(_AIX) && defined(_POWER) && !defined(_M_PPC)
90 #elif defined(__sparc__) && !defined(_M_SPARC)
92 #elif defined(__hppa__) && !defined(_M_PARISC)
94 #elif defined(__ia64__) && !defined(_M_IA64)
96 #elif defined(__x86_64__) && !defined(_M_AMD64)
98 #elif defined(__arm__) && !defined(_M_ARM)
100 #elif defined(__aarch64__) && !defined(_M_ARM64)
104 #if defined(_M_IX86) && !defined(_X86_)
106 #elif defined(_M_ALPHA) && !defined(_ALPHA_)
108 #elif defined(_M_PPC) && !defined(_PPC_)
110 #elif defined(_M_SPARC) && !defined(_SPARC_)
112 #elif defined(_M_PARISC) && !defined(_PARISC_)
114 #elif defined(_M_MRX000) && !defined(_MIPS_)
116 #elif defined(_M_M68K) && !defined(_68K_)
118 #elif defined(_M_IA64) && !defined(_IA64_)
120 #elif defined(_M_AMD64) && !defined(_AMD64_)
122 #elif defined(_M_ARM) && !defined(_ARM_)
124 #elif defined(_M_ARM64) && !defined(_ARM64_)
130 /******************* ABI-specific glue *******************************/
132 #if defined(_PPC_) || defined(_PPC64_) || defined(_SPARC_) || defined(_PARISC_) || defined(_IA64_)
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)
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 */
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 */
154 #define MAXSHORT 0x7fff
155 #define MAXLONG 0x7fffffff
157 #define MAXDWORD 0xffffffff
161 // Note that the named locale APIs (eg CompareStringExEx) are recommended.
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
170 /******************* Compiler-specific glue *******************************/
174 // Define this if the underlying platform supports true 2-pass EH.
175 // At the same time, this enables running several PAL instances
177 #define FEATURE_PAL_SXS 1
181 #if defined(_MSC_VER) || defined(__llvm__)
182 #define DECLSPEC_ALIGN(x) __declspec(align(x))
184 #define DECLSPEC_ALIGN(x)
187 #define DECLSPEC_NORETURN PAL_NORETURN
189 #if !defined(_MSC_VER) || defined(SOURCE_FORMATTING)
190 #define __assume(x) (void)0
191 #define __annotation(x)
196 #if defined(_M_MRX000) || defined(_M_ALPHA) || defined(_M_PPC) || defined(_M_IA64)
197 #define UNALIGNED __unaligned
210 #define FORCEINLINE inline
212 #define FORCEINLINE __forceinline
216 #ifndef PAL_STDCPP_COMPAT
221 char *a0; /* pointer to first homed integer argument */
222 int offset; /* byte offset of next parameter */
225 #define va_start(list, v) __builtin_va_start(list, v, 1)
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
241 typedef void * va_list;
243 typedef __builtin_va_list va_list;
246 /* We should consider if the va_arg definition here is actually necessary.
247 Could we use the standard va_arg definition? */
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) \
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
282 #define va_copy __builtin_va_copy
283 #define va_end __builtin_va_end
289 #define PUB __attribute__((visibility("default")))
293 typedef char * va_list;
295 #define _INTSIZEOF(n) ( (sizeof(n) + sizeof(int) - 1) & ~(sizeof(int) - 1) )
300 #define _ADDRESSOF(v) ( &reinterpret_cast<const char &>(v) )
302 #define _ADDRESSOF(v) ( &(v) )
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 )
309 #define va_start _crt_va_start
310 #define va_arg _crt_va_arg
311 #define va_end _crt_va_end
315 #define va_start(ap,v) (ap = (va_list) (&(v)) + _INTSIZEOF(v))
316 #define va_arg(ap,t) ( *(t *)((ap += _INTSIZEOF(t)) - _INTSIZEOF(t)) )
321 #define va_copy(dest,src) (dest = src)
325 #endif // !PAL_STDCPP_COMPAT
327 /******************* PAL-Specific Entrypoints *****************************/
329 #define IsDebuggerPresent PAL_IsDebuggerPresent
334 PAL_IsDebuggerPresent(VOID);
336 #define MAXIMUM_SUSPEND_COUNT MAXCHAR
340 #define SCHAR_MIN (-128)
341 #define SCHAR_MAX 127
342 #define UCHAR_MAX 0xff
344 #define SHRT_MIN (-32768)
345 #define SHRT_MAX 32767
346 #define USHRT_MAX 0xffff
348 #define INT_MIN (-2147483647 - 1)
349 #define INT_MAX 2147483647
350 #define UINT_MAX 0xffffffff
352 #define LONG_MIN (-2147483647L - 1)
353 #define LONG_MAX 2147483647L
354 #define ULONG_MAX 0xffffffffUL
356 #define FLT_MAX 3.402823466e+38F
357 #define DBL_MAX 1.7976931348623157e+308
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)
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
379 #ifdef PAL_STDCPP_COMPAT
384 #if defined(__cplusplus)
387 #define NULL ((void *)0)
391 #if defined(PAL_STDCPP_COMPAT) && !defined(__cplusplus)
393 #endif // defined(PAL_STDCPP_COMPAT) && !defined(__cplusplus)
395 #ifndef PAL_STDCPP_COMPAT
397 #if _WIN64 || _MSC_VER >= 1400
398 typedef __int64 time_t;
402 #define _TIME_T_DEFINED
403 #endif // !PAL_STDCPP_COMPAT
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))
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
418 #define MAKELANGID(p, s) ((((WORD )(s)) << 10) | (WORD )(p))
419 #define PRIMARYLANGID(lgid) ((WORD )(lgid) & 0x3ff)
420 #define SUBLANGID(lgid) ((WORD )(lgid) >> 10)
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))
430 #define SUBLANG_ENGLISH_US 0x01
431 #define SUBLANG_CHINESE_TRADITIONAL 0x01 /* Chinese (Traditional) */
433 #endif // ENABLE_DOWNLEVEL_FOR_NLS
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 */
474 #define DLL_PROCESS_ATTACH 1
475 #define DLL_THREAD_ATTACH 2
476 #define DLL_THREAD_DETACH 3
477 #define DLL_PROCESS_DETACH 0
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
486 // PAL_Initialize() flags
487 #define PAL_INITIALIZE (PAL_INITIALIZE_SYNC_THREAD | PAL_INITIALIZE_STD_HANDLES)
489 // PAL_InitializeDLL() flags - don't start any of the helper threads
490 #define PAL_INITIALIZE_DLL PAL_INITIALIZE_NONE
492 // PAL_InitializeCoreCLR() flags
493 #define PAL_INITIALIZE_CORECLR (PAL_INITIALIZE | PAL_INITIALIZE_EXEC_ALLOCATOR | PAL_INITIALIZE_REGISTER_SIGTERM_HANDLER | PAL_INITIALIZE_DEBUGGER_EXCEPTIONS)
495 typedef DWORD (PALAPI *PTHREAD_START_ROUTINE)(LPVOID lpThreadParameter);
496 typedef PTHREAD_START_ROUTINE LPTHREAD_START_ROUTINE;
498 /******************* PAL-Specific Entrypoints *****************************/
505 const char * const argv[]);
510 PAL_InitializeDLL(VOID);
515 PAL_InitializeCoreCLR(
516 const char *szExePath);
522 IN LPTHREAD_START_ROUTINE lpStartAddress,
523 IN LPVOID lpParameter);
526 /// This function shuts down PAL WITHOUT exiting the current process.
535 /// This function shuts down PAL and exits the current process.
544 /// This function shuts down PAL and exits the current process with
545 /// the specified exit code.
553 typedef VOID (*PSHUTDOWN_CALLBACK)(void);
558 PAL_SetShutdownCallback(
559 IN PSHUTDOWN_CALLBACK callback);
561 typedef VOID (*PPAL_STARTUP_CALLBACK)(
569 PAL_RegisterForRuntimeStartup(
570 IN DWORD dwProcessId,
571 IN PPAL_STARTUP_CALLBACK pfnCallback,
573 OUT PVOID *ppUnregisterToken);
578 PAL_UnregisterForRuntimeStartup(
579 IN PVOID pUnregisterToken);
584 PAL_NotifyRuntimeStarted(VOID);
586 static const int MAX_DEBUGGER_TRANSPORT_PIPE_NAME_LENGTH = 64;
591 PAL_GetTransportPipeName(char *name, DWORD id, const char *suffix);
603 IN LPCSTR lpLibFileName);
608 PAL_UnregisterModule(
609 IN HINSTANCE hInstance);
614 PAL_GetPALDirectoryW(
615 OUT LPWSTR lpDirectoryName,
616 IN OUT UINT* cchDirectoryName);
618 #define PAL_GetPALDirectory PAL_GetPALDirectoryW
620 #define PAL_GetPALDirectory PAL_GetPALDirectoryA
628 IN OUT LPVOID lpBuffer,
636 PAL_CreateExecWatchpoint(
644 PAL_DeleteExecWatchpoint(
659 /******************* winuser.h Entrypoints *******************************/
672 IN LPCSTR lpCurrentChar,
676 #define CharNext CharNextA
677 #define CharNextEx CharNextExA
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
687 #define MB_ICONHAND 0x00000010L
688 #define MB_ICONQUESTION 0x00000020L
689 #define MB_ICONEXCLAMATION 0x00000030L
690 #define MB_ICONASTERISK 0x00000040L
692 #define MB_ICONINFORMATION MB_ICONASTERISK
693 #define MB_ICONSTOP MB_ICONHAND
694 #define MB_ICONERROR MB_ICONHAND
696 #define MB_DEFBUTTON1 0x00000000L
697 #define MB_DEFBUTTON2 0x00000100L
698 #define MB_DEFBUTTON3 0x00000200L
700 #define MB_SYSTEMMODAL 0x00001000L
701 #define MB_TASKMODAL 0x00002000L
702 #define MB_SETFOREGROUND 0x00010000L
703 #define MB_TOPMOST 0x00040000L
705 #define MB_NOFOCUS 0x00008000L
706 #define MB_SETFOREGROUND 0x00010000L
707 #define MB_DEFAULT_DESKTOP_ONLY 0x00020000L
709 // Note: this is the NT 4.0 and greater value.
710 #define MB_SERVICE_NOTIFICATION 0x00200000L
712 #define MB_TYPEMASK 0x0000000FL
713 #define MB_ICONMASK 0x000000F0L
714 #define MB_DEFMASK 0x00000F00L
729 IN LPVOID hWnd, // NOTE: diff from winuser.h
731 IN LPCWSTR lpCaption,
736 #define MessageBox MessageBoxW
738 #define MessageBox MessageBoxA
741 /***************** wincon.h Entrypoints **********************************/
743 #define CTRL_C_EVENT 0
744 #define CTRL_BREAK_EVENT 1
745 #define CTRL_CLOSE_EVENT 2
748 #define CTRL_LOGOFF_EVENT 5
749 #define CTRL_SHUTDOWN_EVENT 6
753 (PALAPI *PHANDLER_ROUTINE)(
761 GenerateConsoleCtrlEvent(
762 IN DWORD dwCtrlEvent,
763 IN DWORD dwProcessGroupId
767 //end wincon.h Entrypoints
774 #define _CRTIMP __declspec(dllimport)
778 /******************* winbase.h Entrypoints and defines ************************/
785 typedef struct _SECURITY_ATTRIBUTES {
787 LPVOID lpSecurityDescriptor;
789 } SECURITY_ATTRIBUTES, *PSECURITY_ATTRIBUTES, *LPSECURITY_ATTRIBUTES;
791 #define _SH_DENYWR 0x20 /* deny write mode */
793 #define FILE_READ_DATA ( 0x0001 ) // file & pipe
794 #define FILE_APPEND_DATA ( 0x0004 ) // file
796 #define GENERIC_READ (0x80000000L)
797 #define GENERIC_WRITE (0x40000000L)
799 #define FILE_SHARE_READ 0x00000001
800 #define FILE_SHARE_WRITE 0x00000002
801 #define FILE_SHARE_DELETE 0x00000004
804 #define CREATE_ALWAYS 2
805 #define OPEN_EXISTING 3
806 #define OPEN_ALWAYS 4
807 #define TRUNCATE_EXISTING 5
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
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
824 #define FILE_CURRENT 1
827 #define STILL_ACTIVE (0x00000103L)
829 #define INVALID_SET_FILE_POINTER ((DWORD)-1)
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);
845 #define CreateFile CreateFileW
847 #define CreateFile CreateFileA
855 IN DWORD dwFileOffsetLow,
856 IN DWORD dwFileOffsetHigh,
857 IN DWORD nNumberOfBytesToLockLow,
858 IN DWORD nNumberOfBytesToLockHigh
866 IN DWORD dwFileOffsetLow,
867 IN DWORD dwFileOffsetHigh,
868 IN DWORD nNumberOfBytesToUnlockLow,
869 IN DWORD nNumberOfBytesToUnlockHigh
878 IN LPCWSTR lpFileName,
879 IN LPCWSTR lpExtension,
880 IN DWORD nBufferLength,
882 OUT LPWSTR *lpFilePart
885 #define SearchPath SearchPathW
887 #define SearchPath SearchPathA
896 IN LPCWSTR lpExistingFileName,
897 IN LPCWSTR lpNewFileName,
898 IN BOOL bFailIfExists);
901 #define CopyFile CopyFileW
903 #define CopyFile CopyFileA
911 IN LPCWSTR lpFileName);
914 #define DeleteFile DeleteFileW
916 #define DeleteFile DeleteFileA
925 IN LPCWSTR lpExistingFileName,
926 IN LPCWSTR lpNewFileName);
929 #define MoveFile MoveFileW
931 #define MoveFile MoveFileA
934 #define MOVEFILE_REPLACE_EXISTING 0x00000001
935 #define MOVEFILE_COPY_ALLOWED 0x00000002
942 IN LPCWSTR lpExistingFileName,
943 IN LPCWSTR lpNewFileName,
947 #define MoveFileEx MoveFileExW
949 #define MoveFileEx MoveFileExA
956 IN LPCWSTR lpPathName,
957 IN LPSECURITY_ATTRIBUTES lpSecurityAttributes);
960 #define CreateDirectory CreateDirectoryW
962 #define CreateDirectory CreateDirectoryA
969 IN LPCWSTR lpPathName);
972 #define RemoveDirectory RemoveDirectoryW
974 #define RemoveDirectory RemoveDirectoryA
977 typedef struct _BY_HANDLE_FILE_INFORMATION {
978 DWORD dwFileAttributes;
979 FILETIME ftCreationTime;
980 FILETIME ftLastAccessTime;
981 FILETIME ftLastWriteTime;
982 DWORD dwVolumeSerialNumber;
985 DWORD nNumberOfLinks;
986 DWORD nFileIndexHigh;
988 } BY_HANDLE_FILE_INFORMATION, *PBY_HANDLE_FILE_INFORMATION, *LPBY_HANDLE_FILE_INFORMATION;
990 typedef struct _WIN32_FIND_DATAA {
991 DWORD dwFileAttributes;
992 FILETIME ftCreationTime;
993 FILETIME ftLastAccessTime;
994 FILETIME ftLastWriteTime;
999 CHAR cFileName[ MAX_PATH_FNAME ];
1000 CHAR cAlternateFileName[ 14 ];
1001 } WIN32_FIND_DATAA, *PWIN32_FIND_DATAA, *LPWIN32_FIND_DATAA;
1003 typedef struct _WIN32_FIND_DATAW {
1004 DWORD dwFileAttributes;
1005 FILETIME ftCreationTime;
1006 FILETIME ftLastAccessTime;
1007 FILETIME ftLastWriteTime;
1008 DWORD nFileSizeHigh;
1012 WCHAR cFileName[ MAX_PATH_FNAME ];
1013 WCHAR cAlternateFileName[ 14 ];
1014 } WIN32_FIND_DATAW, *PWIN32_FIND_DATAW, *LPWIN32_FIND_DATAW;
1017 typedef WIN32_FIND_DATAW WIN32_FIND_DATA;
1018 typedef PWIN32_FIND_DATAW PWIN32_FIND_DATA;
1019 typedef LPWIN32_FIND_DATAW LPWIN32_FIND_DATA;
1021 typedef WIN32_FIND_DATAA WIN32_FIND_DATA;
1022 typedef PWIN32_FIND_DATAA PWIN32_FIND_DATA;
1023 typedef LPWIN32_FIND_DATAA LPWIN32_FIND_DATA;
1030 IN LPCWSTR lpFileName,
1031 OUT LPWIN32_FIND_DATAW lpFindFileData);
1034 #define FindFirstFile FindFirstFileW
1036 #define FindFirstFile FindFirstFileA
1043 IN HANDLE hFindFile,
1044 OUT LPWIN32_FIND_DATAW lpFindFileData);
1047 #define FindNextFile FindNextFileW
1049 #define FindNextFile FindNextFileA
1056 IN OUT HANDLE hFindFile);
1062 IN LPCWSTR lpFileName);
1065 #define GetFileAttributes GetFileAttributesW
1067 #define GetFileAttributes GetFileAttributesA
1070 typedef enum _GET_FILEEX_INFO_LEVELS {
1071 GetFileExInfoStandard
1072 } GET_FILEEX_INFO_LEVELS;
1074 typedef enum _FINDEX_INFO_LEVELS {
1077 FindExInfoMaxInfoLevel
1078 } FINDEX_INFO_LEVELS;
1080 typedef enum _FINDEX_SEARCH_OPS {
1081 FindExSearchNameMatch,
1082 FindExSearchLimitToDirectories,
1083 FindExSearchLimitToDevices,
1084 FindExSearchMaxSearchOp
1085 } FINDEX_SEARCH_OPS;
1087 typedef struct _WIN32_FILE_ATTRIBUTE_DATA {
1088 DWORD dwFileAttributes;
1089 FILETIME ftCreationTime;
1090 FILETIME ftLastAccessTime;
1091 FILETIME ftLastWriteTime;
1092 DWORD nFileSizeHigh;
1094 } WIN32_FILE_ATTRIBUTE_DATA, *LPWIN32_FILE_ATTRIBUTE_DATA;
1099 GetFileAttributesExW(
1100 IN LPCWSTR lpFileName,
1101 IN GET_FILEEX_INFO_LEVELS fInfoLevelId,
1102 OUT LPVOID lpFileInformation);
1105 #define GetFileAttributesEx GetFileAttributesExW
1112 IN LPCWSTR lpFileName,
1113 IN DWORD dwFileAttributes);
1116 #define SetFileAttributes SetFileAttributesW
1118 #define SetFileAttributes SetFileAttributesA
1121 typedef LPVOID LPOVERLAPPED; // diff from winbase.h
1128 IN LPCVOID lpBuffer,
1129 IN DWORD nNumberOfBytesToWrite,
1130 OUT LPDWORD lpNumberOfBytesWritten,
1131 IN LPOVERLAPPED lpOverlapped);
1138 OUT LPVOID lpBuffer,
1139 IN DWORD nNumberOfBytesToRead,
1140 OUT LPDWORD lpNumberOfBytesRead,
1141 IN LPOVERLAPPED lpOverlapped);
1143 #define STD_INPUT_HANDLE ((DWORD)-10)
1144 #define STD_OUTPUT_HANDLE ((DWORD)-11)
1145 #define STD_ERROR_HANDLE ((DWORD)-12)
1151 IN DWORD nStdHandle);
1164 IN LONG lDistanceToMove,
1165 IN PLONG lpDistanceToMoveHigh,
1166 IN DWORD dwMoveMethod);
1173 IN LARGE_INTEGER liDistanceToMove,
1174 OUT PLARGE_INTEGER lpNewFilePointer,
1175 IN DWORD dwMoveMethod);
1182 OUT LPDWORD lpFileSizeHigh);
1186 PALAPI GetFileSizeEx(
1188 OUT PLARGE_INTEGER lpFileSize);
1193 GetFileInformationByHandle(
1195 OUT BY_HANDLE_FILE_INFORMATION* lpFileInformation);
1201 IN CONST FILETIME *lpFileTime1,
1202 IN CONST FILETIME *lpFileTime2);
1209 IN CONST FILETIME *lpCreationTime,
1210 IN CONST FILETIME *lpLastAccessTime,
1211 IN CONST FILETIME *lpLastWriteTime);
1218 OUT LPFILETIME lpCreationTime,
1219 OUT LPFILETIME lpLastAccessTime,
1220 OUT LPFILETIME lpLastWriteTime);
1225 GetSystemTimeAsFileTime(
1226 OUT LPFILETIME lpSystemTimeAsFileTime);
1228 typedef struct _SYSTEMTIME {
1237 } SYSTEMTIME, *PSYSTEMTIME, *LPSYSTEMTIME;
1243 OUT LPSYSTEMTIME lpSystemTime);
1248 FileTimeToSystemTime(
1249 IN CONST FILETIME *lpFileTime,
1250 OUT LPSYSTEMTIME lpSystemTime);
1255 FileTimeToDosDateTime(
1256 IN CONST FILETIME *lpFileTime,
1257 OUT LPWORD lpFatDate,
1258 OUT LPWORD lpFatTime
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
1297 IN LPCWSTR lpFileName,
1298 IN DWORD nBufferLength,
1299 OUT LPWSTR lpBuffer,
1300 OUT LPWSTR *lpFilePart);
1303 #define GetFullPathName GetFullPathNameW
1305 #define GetFullPathName GetFullPathNameA
1312 IN LPCWSTR lpszShortPath,
1313 OUT LPWSTR lpszLongPath,
1314 IN DWORD cchBuffer);
1317 #define GetLongPathName GetLongPathNameW
1324 IN LPCWSTR lpszLongPath,
1325 OUT LPWSTR lpszShortPath,
1326 IN DWORD cchBuffer);
1329 #define GetShortPathName GetShortPathNameW
1337 IN LPCWSTR lpPathName,
1338 IN LPCWSTR lpPrefixString,
1340 OUT LPWSTR lpTempFileName);
1343 #define GetTempFileName GetTempFileNameW
1345 #define GetTempFileName GetTempFileNameA
1352 IN DWORD nBufferLength,
1353 OUT LPWSTR lpBuffer);
1356 #define GetTempPath GetTempPathW
1358 #define GetTempPath GetTempPathA
1364 GetCurrentDirectoryW(
1365 IN DWORD nBufferLength,
1366 OUT LPWSTR lpBuffer);
1369 #define GetCurrentDirectory GetCurrentDirectoryW
1371 #define GetCurrentDirectory GetCurrentDirectoryA
1377 SetCurrentDirectoryW(
1378 IN LPCWSTR lpPathName);
1382 #define SetCurrentDirectory SetCurrentDirectoryW
1384 #define SetCurrentDirectory SetCurrentDirectoryA
1387 // maximum length of the NETBIOS name (not including NULL)
1388 #define MAX_COMPUTERNAME_LENGTH 15
1390 // maximum length of the username (not including NULL)
1397 OUT LPWSTR lpBuffer, // address of name buffer
1398 IN OUT LPDWORD nSize ); // address of size of name buffer
1404 OUT LPWSTR lpBuffer, // address of name buffer
1405 IN OUT LPDWORD nSize); // address of size of name buffer
1408 #define GetUserName GetUserNameW
1409 #define GetComputerName GetComputerNameW
1416 IN LPSECURITY_ATTRIBUTES lpSemaphoreAttributes,
1417 IN LONG lInitialCount,
1418 IN LONG lMaximumCount,
1425 IN LPSECURITY_ATTRIBUTES lpSemaphoreAttributes,
1426 IN LONG lInitialCount,
1427 IN LONG lMaximumCount,
1429 IN /*_Reserved_*/ DWORD dwFlags,
1430 IN DWORD dwDesiredAccess);
1436 IN DWORD dwDesiredAccess,
1437 IN BOOL bInheritHandle,
1441 #define CreateSemaphore CreateSemaphoreW
1442 #define CreateSemaphoreEx CreateSemaphoreExW
1444 #define CreateSemaphore CreateSemaphoreA
1445 #define CreateSemaphoreEx CreateSemaphoreExA
1452 IN HANDLE hSemaphore,
1453 IN LONG lReleaseCount,
1454 OUT LPLONG lpPreviousCount);
1460 IN LPSECURITY_ATTRIBUTES lpEventAttributes,
1461 IN BOOL bManualReset,
1462 IN BOOL bInitialState,
1466 #define CreateEvent CreateEventW
1468 #define CreateEvent CreateEventA
1487 IN DWORD dwDesiredAccess,
1488 IN BOOL bInheritHandle,
1492 #define OpenEvent OpenEventW
1499 IN LPSECURITY_ATTRIBUTES lpMutexAttributes,
1500 IN BOOL bInitialOwner,
1504 #define CreateMutex CreateMutexW
1506 #define CreateMutex CreateMutexA
1513 IN DWORD dwDesiredAccess,
1514 IN BOOL bInheritHandle,
1519 #define OpenMutex OpenMutexW
1521 #define OpenMutex OpenMutexA
1533 GetCurrentProcessId(
1539 GetCurrentSessionId(
1554 // To work around multiply-defined symbols in the Carbon framework.
1555 #define GetCurrentThread PAL_GetCurrentThread
1563 #define STARTF_USESTDHANDLES 0x00000100
1565 typedef struct _STARTUPINFOW {
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;
1578 WORD wShowWindow_PAL_Undefined;
1579 WORD cbReserved2_PAL_Undefined;
1580 LPBYTE lpReserved2_PAL_Undefined;
1584 } STARTUPINFOW, *LPSTARTUPINFOW;
1586 typedef struct _STARTUPINFOA {
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;
1599 WORD wShowWindow_PAL_Undefined;
1600 WORD cbReserved2_PAL_Undefined;
1601 LPBYTE lpReserved2_PAL_Undefined;
1605 } STARTUPINFOA, *LPSTARTUPINFOA;
1608 typedef STARTUPINFOW STARTUPINFO;
1609 typedef LPSTARTUPINFOW LPSTARTUPINFO;
1611 typedef STARTUPINFOA STARTUPINFO;
1612 typedef LPSTARTUPINFOW LPSTARTUPINFO;
1615 #define CREATE_NEW_CONSOLE 0x00000010
1617 #define NORMAL_PRIORITY_CLASS 0x00000020
1619 typedef struct _PROCESS_INFORMATION {
1623 DWORD dwThreadId_PAL_Undefined;
1624 } PROCESS_INFORMATION, *PPROCESS_INFORMATION, *LPPROCESS_INFORMATION;
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);
1642 #define CreateProcess CreateProcessW
1644 #define CreateProcess CreateProcessA
1666 IN LPDWORD lpExitCode);
1673 OUT LPFILETIME lpCreationTime,
1674 OUT LPFILETIME lpExitTime,
1675 OUT LPFILETIME lpKernelTime,
1676 OUT LPFILETIME lpUserTime);
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)
1685 #define INFINITE 0xFFFFFFFF // Infinite timeout
1690 WaitForSingleObject(
1692 IN DWORD dwMilliseconds);
1697 WaitForSingleObjectEx(
1699 IN DWORD dwMilliseconds,
1700 IN BOOL bAlertable);
1705 WaitForMultipleObjects(
1707 IN CONST HANDLE *lpHandles,
1709 IN DWORD dwMilliseconds);
1714 WaitForMultipleObjectsEx(
1716 IN CONST HANDLE *lpHandles,
1718 IN DWORD dwMilliseconds,
1719 IN BOOL bAlertable);
1724 PAL_LocalHandleToRemote(
1730 PAL_RemoteHandleToLocal(
1731 IN RHANDLE hRemote);
1734 #define DUPLICATE_CLOSE_SOURCE 0x00000001
1735 #define DUPLICATE_SAME_ACCESS 0x00000002
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);
1753 IN DWORD dwMilliseconds);
1759 IN DWORD dwMilliseconds,
1760 IN BOOL bAlertable);
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
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);
1789 IN DWORD dwExitCode);
1796 IN LPDWORD lpExitCode);
1804 typedef VOID (PALAPI *PAPCFUNC)(ULONG_PTR dwParam);
1812 IN ULONG_PTR dwData);
1817 // ***********************************************************************************
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.
1823 // ***********************************************************************************
1826 #define SIZE_OF_80387_REGISTERS 80
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)
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)
1839 #define MAXIMUM_SUPPORTED_EXTENSION 512
1841 #define CONTEXT_XSTATE (CONTEXT_i386 | 0x40L)
1843 #define CONTEXT_EXCEPTION_ACTIVE 0x8000000L
1844 #define CONTEXT_SERVICE_ACTIVE 0x10000000L
1845 #define CONTEXT_EXCEPTION_REQUEST 0x40000000L
1846 #define CONTEXT_EXCEPTION_REPORTING 0x80000000L
1848 typedef struct _FLOATING_SAVE_AREA {
1853 DWORD ErrorSelector;
1856 BYTE RegisterArea[SIZE_OF_80387_REGISTERS];
1858 } FLOATING_SAVE_AREA;
1860 typedef FLOATING_SAVE_AREA *PFLOATING_SAVE_AREA;
1862 typedef struct _CONTEXT {
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;
1872 FLOATING_SAVE_AREA FloatSave;
1874 ULONG SegGs_PAL_Undefined;
1875 ULONG SegFs_PAL_Undefined;
1876 ULONG SegEs_PAL_Undefined;
1877 ULONG SegDs_PAL_Undefined;
1893 UCHAR ExtendedRegisters[MAXIMUM_SUPPORTED_EXTENSION];
1895 } CONTEXT, *PCONTEXT, *LPCONTEXT;
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
1906 typedef struct _KNONVOLATILE_CONTEXT_POINTERS {
1908 // TODO WIP x86/Linux, need to fix this.
1914 } KNONVOLATILE_CONTEXT_POINTERS, *PKNONVOLATILE_CONTEXT_POINTERS;
1916 #elif defined(_PPC_)
1919 // ***********************************************************************************
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.
1925 // ***********************************************************************************
1928 #define CONTEXT_CONTROL 0x00000001L
1929 #define CONTEXT_FLOATING_POINT 0x00000002L
1930 #define CONTEXT_INTEGER 0x00000004L
1932 #define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_FLOATING_POINT | CONTEXT_INTEGER)
1933 #define CONTEXT_ALL CONTEXT_FULL
1935 typedef struct _CONTEXT {
1938 // This section is specified/returned if the ContextFlags word contains
1939 // the flag CONTEXT_FLOATING_POINT.
1942 double Fpr0; // Floating registers 0..31
1974 double Fpscr; // Floating point status/control reg
1977 // This section is specified/returned if the ContextFlags word contains
1978 // the flag CONTEXT_INTEGER.
1981 ULONG Gpr0; // General registers 0..31
1982 ULONG Gpr1; // StackPointer
2014 ULONG Cr; // Condition register
2015 ULONG Xer; // Fixed point exception register
2018 // This section is specified/returned if the ContextFlags word contains
2019 // the flag CONTEXT_CONTROL.
2022 ULONG Msr; // Machine status register
2023 ULONG Iar; // Instruction address register
2024 ULONG Lr; // Link register
2025 ULONG Ctr; // Count register
2028 // The flags values within this flag control the contents of
2029 // a CONTEXT record.
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.
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.
2042 // The context record is never used as an OUT only parameter.
2047 ULONG Fill[3]; // Pad out to multiple of 16 bytes
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.
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
2063 } CONTEXT, *PCONTEXT, *LPCONTEXT;
2065 #elif defined(_SPARC_)
2067 #define CONTEXT_CONTROL 0x00000001L
2068 #define CONTEXT_FLOATING_POINT 0x00000002L
2069 #define CONTEXT_INTEGER 0x00000004L
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
2076 typedef struct _CONTEXT {
2078 // This section is specified/returned if the ContextFlags word contains
2079 // the flag CONTEXT_INTEGER.
2117 // This section is specified/returned if the ContextFlags word contains
2118 // the flag CONTEXT_CONTROL.
2120 #if defined(__sparcv9)
2125 ULONG pc; // program counter
2126 ULONG npc; // next address to be executed
2131 // This section is specified/returned if the ContextFlags word contains
2132 // the flag CONTEXT_FLOATING_POINT.
2136 float f[COUNT_FLOATING_REGISTER];
2137 double d[COUNT_DOUBLE_REGISTER];
2140 } CONTEXT, *PCONTEXT, *LPCONTEXT;
2142 #elif defined(_PARISC_)
2144 // ToDo: Get this correct for PARISC architecture
2145 #define CONTEXT_CONTROL 0x00000001L
2146 #define CONTEXT_FLOATING_POINT 0x00000002L
2147 #define CONTEXT_INTEGER 0x00000004L
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
2154 typedef struct _CONTEXT {
2156 // This section is specified/returned if the ContextFlags word contains
2157 // the flag CONTEXT_INTEGER.
2195 // This section is specified/returned if the ContextFlags word contains
2196 // the flag CONTEXT_CONTROL.
2199 ULONG pc; // program counter
2200 ULONG npc; // next address to be executed
2205 // This section is specified/returned if the ContextFlags word contains
2206 // the flag CONTEXT_FLOATING_POINT.
2210 float f[COUNT_FLOATING_REGISTER];
2211 double d[COUNT_DOUBLE_REGISTER];
2214 } CONTEXT, *PCONTEXT, *LPCONTEXT;
2216 #elif defined(_IA64_)
2218 // copied from winnt.h
2219 typedef struct _FLOAT128 {
2224 typedef FLOAT128 *PFLOAT128;
2226 // begin_ntddk begin_nthal
2229 // The following flags control the contents of the CONTEXT structure.
2232 #if !defined(RC_INVOKED)
2234 #define CONTEXT_IA64 0x00080000
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
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)
2248 #define CONTEXT_EXCEPTION_ACTIVE 0x8000000
2249 #define CONTEXT_SERVICE_ACTIVE 0x10000000
2250 #define CONTEXT_EXCEPTION_REQUEST 0x40000000
2251 #define CONTEXT_EXCEPTION_REPORTING 0x80000000
2253 #endif // !defined(RC_INVOKED)
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.
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.
2268 typedef struct _CONTEXT {
2271 // The flags values within this flag control the contents of
2272 // a CONTEXT record.
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.
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.
2285 // The context record is never used as an OUT only parameter.
2289 DWORD Fill1[3]; // for alignment of following on 16-byte boundary
2292 // This section is specified/returned if the ContextFlags word contains
2293 // the flag CONTEXT_DEBUG.
2295 // N.B. CONTEXT_DEBUG is *not* part of CONTEXT_FULL.
2317 // This section is specified/returned if the ContextFlags word contains
2318 // the flag CONTEXT_LOWER_FLOATING_POINT.
2337 // This section is specified/returned if the ContextFlags word contains
2338 // the flag CONTEXT_HIGHER_FLOATING_POINT.
2465 // This section is specified/returned if the ContextFlags word contains
2466 // the flag CONTEXT_LOWER_FLOATING_POINT | CONTEXT_HIGHER_FLOATING_POINT | CONTEXT_CONTROL.
2469 ULONGLONG StFPSR; // FP status
2472 // This section is specified/returned if the ContextFlags word contains
2473 // the flag CONTEXT_INTEGER.
2475 // N.B. The registers gp, sp, rp are part of the control context
2478 ULONGLONG IntGp; // r1, volatile
2479 ULONGLONG IntT0; // r2-r3, volatile
2481 ULONGLONG IntS0; // r4-r7, preserved
2485 ULONGLONG IntV0; // r8, volatile
2486 ULONGLONG IntT2; // r9-r11, volatile
2489 ULONGLONG IntSp; // stack pointer (r12), special
2490 ULONGLONG IntTeb; // teb (r13), special
2491 ULONGLONG IntT5; // r14-r31, volatile
2510 ULONGLONG IntNats; // Nat bits for r1-r31
2511 // r1-r31 in bits 1 thru 31.
2512 ULONGLONG Preds; // predicates, preserved
2514 ULONGLONG BrRp; // return pointer, b0, preserved
2515 ULONGLONG BrS0; // b1-b5, preserved
2520 ULONGLONG BrT0; // b6-b7, volatile
2524 // This section is specified/returned if the ContextFlags word contains
2525 // the flag CONTEXT_CONTROL.
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)
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
2542 // Trap Status Information
2543 ULONGLONG StIPSR; // Interruption Processor Status
2544 ULONGLONG StIIP; // Interruption IP
2545 ULONGLONG StIFS; // Interruption Function State
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)
2557 ULONGLONG UNUSEDPACK; // added to pack StFDR to 16-bytes
2559 } CONTEXT, *PCONTEXT, *LPCONTEXT;
2560 #elif defined(_AMD64_)
2561 // copied from winnt.h
2563 #define CONTEXT_AMD64 0x100000
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)
2571 #define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_FLOATING_POINT)
2573 #define CONTEXT_ALL (CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_SEGMENTS | CONTEXT_FLOATING_POINT | CONTEXT_DEBUG_REGISTERS)
2575 #define CONTEXT_XSTATE (CONTEXT_AMD64 | 0x40L)
2577 #define CONTEXT_EXCEPTION_ACTIVE 0x8000000
2578 #define CONTEXT_SERVICE_ACTIVE 0x10000000
2579 #define CONTEXT_EXCEPTION_REQUEST 0x40000000
2580 #define CONTEXT_EXCEPTION_REPORTING 0x80000000
2582 typedef struct DECLSPEC_ALIGN(16) _M128A {
2587 typedef struct _XMM_SAVE_AREA32 {
2601 M128A FloatRegisters[8];
2602 M128A XmmRegisters[16];
2604 } XMM_SAVE_AREA32, *PXMM_SAVE_AREA32;
2606 #define LEGACY_SAVE_AREA_LENGTH sizeof(XMM_SAVE_AREA32)
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.
2616 // The flags field within this record controls the contents of a CONTEXT
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.
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.
2629 // CONTEXT_CONTROL specifies SegSs, Rsp, SegCs, Rip, and EFlags.
2631 // CONTEXT_INTEGER specifies Rax, Rcx, Rdx, Rbx, Rbp, Rsi, Rdi, and R8-R15.
2633 // CONTEXT_SEGMENTS specifies SegDs, SegEs, SegFs, and SegGs.
2635 // CONTEXT_DEBUG_REGISTERS specifies Dr0-Dr3 and Dr6-Dr7.
2637 // CONTEXT_MMX_REGISTERS specifies the floating point and extended registers
2638 // Mm0/St0-Mm7/St7 and Xmm0-Xmm15).
2641 typedef struct DECLSPEC_ALIGN(16) _CONTEXT {
2644 // Register parameter home addresses.
2646 // N.B. These fields are for convience - they could be used to extend the
2647 // context record in the future.
2665 // Segment Registers and processor flags.
2688 // Integer registers.
2715 // Floating point state.
2719 XMM_SAVE_AREA32 FltSave;
2743 // Vector registers.
2746 M128A VectorRegister[26];
2747 DWORD64 VectorControl;
2750 // Special debug control registers.
2753 DWORD64 DebugControl;
2754 DWORD64 LastBranchToRip;
2755 DWORD64 LastBranchFromRip;
2756 DWORD64 LastExceptionToRip;
2757 DWORD64 LastExceptionFromRip;
2758 } CONTEXT, *PCONTEXT, *LPCONTEXT;
2761 // Nonvolatile context pointer record.
2764 typedef struct _KNONVOLATILE_CONTEXT_POINTERS {
2766 PM128A FloatingContext[16];
2788 PDWORD64 IntegerContext[16];
2809 } KNONVOLATILE_CONTEXT_POINTERS, *PKNONVOLATILE_CONTEXT_POINTERS;
2811 #elif defined(_ARM_)
2813 #define CONTEXT_ARM 0x00200000L
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)
2822 #define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_FLOATING_POINT)
2824 #define CONTEXT_ALL (CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_FLOATING_POINT | CONTEXT_DEBUG_REGISTERS)
2826 #define CONTEXT_EXCEPTION_ACTIVE 0x8000000L
2827 #define CONTEXT_SERVICE_ACTIVE 0x10000000L
2828 #define CONTEXT_EXCEPTION_REQUEST 0x40000000L
2829 #define CONTEXT_EXCEPTION_REPORTING 0x80000000L
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.
2838 #define CONTEXT_UNWOUND_TO_CALL 0x20000000
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.
2846 #define ARM_MAX_BREAKPOINTS 8
2847 #define ARM_MAX_WATCHPOINTS 1
2849 typedef struct _NEON128 {
2852 } NEON128, *PNEON128;
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.
2862 // The flags field within this record controls the contents of a CONTEXT
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.
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.
2875 // CONTEXT_CONTROL specifies Sp, Lr, Pc, and Cpsr
2877 // CONTEXT_INTEGER specifies R0-R12
2879 // CONTEXT_FLOATING_POINT specifies Q0-Q15 / D0-D31 / S0-S31
2881 // CONTEXT_DEBUG_REGISTERS specifies up to 16 of DBGBVR, DBGBCR, DBGWVR,
2885 typedef struct DECLSPEC_ALIGN(8) _CONTEXT {
2894 // Integer registers
2912 // Control Registers
2921 // Floating Point/NEON Registers
2936 DWORD Bvr[ARM_MAX_BREAKPOINTS];
2937 DWORD Bcr[ARM_MAX_BREAKPOINTS];
2938 DWORD Wvr[ARM_MAX_WATCHPOINTS];
2939 DWORD Wcr[ARM_MAX_WATCHPOINTS];
2943 } CONTEXT, *PCONTEXT, *LPCONTEXT;
2946 // Nonvolatile context pointer record.
2949 typedef struct _KNONVOLATILE_CONTEXT_POINTERS {
2970 } KNONVOLATILE_CONTEXT_POINTERS, *PKNONVOLATILE_CONTEXT_POINTERS;
2972 typedef struct _IMAGE_ARM_RUNTIME_FUNCTION_ENTRY {
2979 DWORD FunctionLength : 11;
2986 DWORD StackAdjust : 10;
2989 } IMAGE_ARM_RUNTIME_FUNCTION_ENTRY, * PIMAGE_ARM_RUNTIME_FUNCTION_ENTRY;
2991 #elif defined(_ARM64_)
2993 #define CONTEXT_ARM64 0x00400000L
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)
3000 #define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_FLOATING_POINT)
3002 #define CONTEXT_ALL (CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_FLOATING_POINT | CONTEXT_DEBUG_REGISTERS)
3004 #define CONTEXT_EXCEPTION_ACTIVE 0x8000000L
3005 #define CONTEXT_SERVICE_ACTIVE 0x10000000L
3006 #define CONTEXT_EXCEPTION_REQUEST 0x40000000L
3007 #define CONTEXT_EXCEPTION_REPORTING 0x80000000L
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.
3016 #define CONTEXT_UNWOUND_TO_CALL 0x20000000
3019 // Define initial Cpsr/Fpscr value
3022 #define INITIAL_CPSR 0x10
3023 #define INITIAL_FPSCR 0
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.
3033 #define ARM64_MAX_BREAKPOINTS 8
3034 #define ARM64_MAX_WATCHPOINTS 2
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.
3044 // The flags field within this record controls the contents of a CONTEXT
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.
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.
3057 // CONTEXT_CONTROL specifies Sp, Lr, Pc, and Cpsr
3059 // CONTEXT_INTEGER specifies R0-R12
3061 // CONTEXT_FLOATING_POINT specifies Q0-Q15 / D0-D31 / S0-S31
3063 // CONTEXT_DEBUG_REGISTERS specifies up to 16 of DBGBVR, DBGBCR, DBGWVR,
3067 typedef struct _NEON128 {
3070 } NEON128, *PNEON128;
3072 typedef struct DECLSPEC_ALIGN(16) _CONTEXT {
3078 /* +0x000 */ DWORD ContextFlags;
3081 // Integer registers
3084 /* +0x004 */ DWORD Cpsr; // NZVF + DAIF + CurrentEL + SPSel
3085 /* +0x008 */ union {
3119 /* +0x0f0 */ DWORD64 Fp;
3120 /* +0x0f8 */ DWORD64 Lr;
3121 /* +0x100 */ DWORD64 Sp;
3122 /* +0x108 */ DWORD64 Pc;
3125 // Floating Point/NEON Registers
3128 /* +0x110 */ NEON128 V[32];
3129 /* +0x310 */ DWORD Fpcr;
3130 /* +0x314 */ DWORD Fpsr;
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];
3142 } CONTEXT, *PCONTEXT, *LPCONTEXT;
3145 // Nonvolatile context pointer record.
3148 typedef struct _KNONVOLATILE_CONTEXT_POINTERS {
3172 } KNONVOLATILE_CONTEXT_POINTERS, *PKNONVOLATILE_CONTEXT_POINTERS;
3175 #error Unknown architecture for defining CONTEXT.
3184 IN OUT LPCONTEXT lpContext);
3191 IN CONST CONTEXT *lpContext);
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)
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)
3205 #define THREAD_PRIORITY_TIME_CRITICAL THREAD_BASE_PRIORITY_LOWRT
3206 #define THREAD_PRIORITY_IDLE THREAD_BASE_PRIORITY_IDLE
3226 OUT LPFILETIME lpCreationTime,
3227 OUT LPFILETIME lpExitTime,
3228 OUT LPFILETIME lpKernelTime,
3229 OUT LPFILETIME lpUserTime);
3231 #define TLS_OUT_OF_INDEXES ((DWORD)0xFFFFFFFF)
3243 IN DWORD dwTlsIndex);
3249 IN DWORD dwTlsIndex,
3250 IN LPVOID lpTlsValue);
3256 IN DWORD dwTlsIndex);
3261 PAL_GetStackBase(VOID);
3266 PAL_GetStackLimit(VOID);
3271 PAL_GetLogicalCpuCountFromOS(VOID);
3276 PAL_GetLogicalProcessorCacheSizeFromOS(VOID);
3278 typedef BOOL (*ReadMemoryWordCallback)(SIZE_T address, SIZE_T *value);
3280 PALIMPORT BOOL PALAPI PAL_VirtualUnwind(CONTEXT *context, KNONVOLATILE_CONTEXT_POINTERS *contextPointers);
3282 PALIMPORT BOOL PALAPI PAL_VirtualUnwindOutOfProc(CONTEXT *context,
3283 KNONVOLATILE_CONTEXT_POINTERS *contextPointers,
3285 ReadMemoryWordCallback readMemCallback);
3287 #define GetLogicalProcessorCacheSizeFromOS PAL_GetLogicalProcessorCacheSizeFromOS
3289 #ifdef PLATFORM_UNIX
3291 /* PAL_CS_NATIVE_DATA_SIZE is defined as sizeof(PAL_CRITICAL_SECTION_NATIVE_DATA) */
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
3331 #error PAL_CS_NATIVE_DATA_SIZE is not defined for this architecture
3334 #endif // PLATFORM_UNIX
3337 typedef struct _CRITICAL_SECTION {
3340 LONG RecursionCount;
3341 HANDLE OwningThread;
3342 HANDLE LockSemaphore;
3343 ULONG_PTR SpinCount;
3345 #ifdef PLATFORM_UNIX
3347 volatile DWORD dwInitState;
3348 union CSNativeDataStorage
3350 BYTE rgNativeDataStorage[PAL_CS_NATIVE_DATA_SIZE];
3351 VOID * pvAlign; // make sure the storage is machine-pointer-size aligned
3353 #endif // PLATFORM_UNIX
3354 } CRITICAL_SECTION, *PCRITICAL_SECTION, *LPCRITICAL_SECTION;
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);
3363 #define SEM_FAILCRITICALERRORS 0x0001
3364 #define SEM_NOOPENFILEERRORBOX 0x8000
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
3397 IN LPSECURITY_ATTRIBUTES lpFileMappingAttributes,
3399 IN DWORD dwMaxmimumSizeHigh,
3400 IN DWORD dwMaximumSizeLow,
3404 #define CreateFileMapping CreateFileMappingW
3406 #define CreateFileMapping CreateFileMappingA
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
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
3423 IN DWORD dwDesiredAccess,
3424 IN BOOL bInheritHandle,
3428 #define OpenFileMapping OpenFileMappingW
3430 #define OpenFileMapping OpenFileMappingA
3437 IN HANDLE hFileMappingObject,
3438 IN DWORD dwDesiredAccess,
3439 IN DWORD dwFileOffsetHigh,
3440 IN DWORD dwFileOffsetLow,
3441 IN SIZE_T dwNumberOfBytesToMap);
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);
3458 IN LPVOID lpBaseAddress,
3459 IN SIZE_T dwNumberOfBytesToFlush);
3465 IN LPCVOID lpBaseAddress);
3472 IN LPCWSTR lpLibFileName);
3478 IN LPCWSTR lpLibFileName,
3479 IN /*Reserved*/ HANDLE hFile,
3485 PAL_LoadLibraryDirect(
3486 IN LPCWSTR lpLibFileName);
3491 PAL_RegisterLibraryDirect(
3493 IN LPCWSTR lpLibFileName);
3500 Loads a PE file into memory. Properly maps all of the sections in the PE file. Returns a pointer to the
3504 IN hFile - The file to load
3507 A valid base address if successful.
3512 PAL_LOADLoadPEFile(HANDLE hFile);
3515 PAL_LOADUnloadPEFile
3517 Unload a PE file that was loaded by PAL_LOADLoadPEFile().
3520 IN ptr - the file pointer returned by PAL_LOADLoadPEFile()
3524 FALSE - failure (incorrect ptr, etc.)
3528 PAL_LOADUnloadPEFile(void * ptr);
3531 #define LoadLibrary LoadLibraryW
3532 #define LoadLibraryEx LoadLibraryExW
3534 #define LoadLibrary LoadLibraryA
3535 #define LoadLibraryEx LoadLibraryExA
3538 typedef INT_PTR (PALAPI *FARPROC)();
3545 IN LPCSTR lpProcName);
3551 IN OUT HMODULE hLibModule);
3557 FreeLibraryAndExitThread(
3558 IN HMODULE hLibModule,
3559 IN DWORD dwExitCode);
3564 DisableThreadLibraryCalls(
3565 IN HMODULE hLibModule);
3572 OUT LPWSTR lpFileName,
3576 #define GetModuleFileName GetModuleFileNameW
3578 #define GetModuleFileName GetModuleFileNameA
3584 GetModuleFileNameExW(
3587 OUT LPWSTR lpFilename,
3592 #define GetModuleFileNameEx GetModuleFileNameExW
3595 // Get base address of the module containing a given symbol
3598 PAL_GetSymbolModuleBase(void *symbol);
3604 IN LPVOID lpAddress,
3606 IN DWORD flAllocationType,
3607 IN DWORD flProtect);
3613 IN LPVOID lpAddress,
3615 IN DWORD dwFreeType);
3621 IN LPVOID lpAddress,
3623 IN DWORD flNewProtect,
3624 OUT PDWORD lpflOldProtect);
3626 typedef struct _MEMORYSTATUSEX {
3629 DWORDLONG ullTotalPhys;
3630 DWORDLONG ullAvailPhys;
3631 DWORDLONG ullTotalPageFile;
3632 DWORDLONG ullAvailPageFile;
3633 DWORDLONG ullTotalVirtual;
3634 DWORDLONG ullAvailVirtual;
3635 DWORDLONG ullAvailExtendedVirtual;
3636 } MEMORYSTATUSEX, *LPMEMORYSTATUSEX;
3641 GlobalMemoryStatusEx(
3642 IN OUT LPMEMORYSTATUSEX lpBuffer);
3644 typedef struct _MEMORY_BASIC_INFORMATION {
3646 PVOID AllocationBase_PAL_Undefined;
3647 DWORD AllocationProtect;
3652 } MEMORY_BASIC_INFORMATION, *PMEMORY_BASIC_INFORMATION;
3658 IN LPCVOID lpAddress,
3659 OUT PMEMORY_BASIC_INFORMATION lpBuffer,
3660 IN SIZE_T dwLength);
3666 IN PVOID Destination,
3667 IN CONST VOID *Source,
3674 IN PVOID Destination,
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))
3689 #define HEAP_ZERO_MEMORY 0x00000008
3696 IN SIZE_T dwInitialSize,
3697 IN SIZE_T dwMaximumSize);
3725 typedef enum _HEAP_INFORMATION_CLASS {
3726 HeapCompatibilityInformation,
3727 HeapEnableTerminationOnCorruption
3728 } HEAP_INFORMATION_CLASS;
3734 IN OPTIONAL HANDLE HeapHandle,
3735 IN HEAP_INFORMATION_CLASS HeapInformationClass,
3736 IN PVOID HeapInformation,
3737 IN SIZE_T HeapInformationLength);
3739 #define LMEM_FIXED 0x0000
3740 #define LMEM_MOVEABLE 0x0002
3741 #define LMEM_ZEROINIT 0x0040
3742 #define LPTR (LMEM_FIXED | LMEM_ZEROINIT)
3768 FlushInstructionCache(
3770 IN LPCVOID lpBaseAddress,
3773 #if ENABLE_DOWNLEVEL_FOR_NLS
3780 IN DWORD dwInfoType,
3781 IN LPCWSTR lpSrcStr,
3783 OUT LPWORD lpCharType);
3786 #define GetStringTypeEx GetStringTypeExW
3789 #endif // ENABLE_DOWNLEVEL_FOR_NLS
3792 #define NORM_IGNORECASE 0x00000001 // ignore case
3793 #define NORM_IGNOREWIDTH 0x00020000 // ignore width
3795 #define NORM_LINGUISTIC_CASING 0x08000000 // use linguistic rules for casing
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
3805 typedef struct nlsversioninfo {
3806 DWORD dwNLSVersionInfoSize;
3808 DWORD dwDefinedVersion;
3809 } NLSVERSIONINFO, *LPNLSVERSIONINFO;
3811 #define CSTR_LESS_THAN 1
3812 #define CSTR_EQUAL 2
3813 #define CSTR_GREATER_THAN 3
3815 #if ENABLE_DOWNLEVEL_FOR_NLS
3823 IN DWORD dwCmpFlags,
3824 IN LPCWSTR lpString1,
3826 IN LPCWSTR lpString2,
3829 #endif // ENABLE_DOWNLEVEL_FOR_NLS
3836 IN LPCWSTR lpLocaleName,
3837 IN DWORD dwCmpFlags,
3838 IN LPCWSTR lpString1,
3840 IN LPCWSTR lpString2,
3842 IN LPNLSVERSIONINFO lpVersionInformation,
3843 IN LPVOID lpReserved,
3848 #define CompareString CompareStringW
3851 #define MAX_LEADBYTES 12
3852 #define MAX_DEFAULTCHAR 2
3859 typedef struct _cpinfo {
3861 BYTE DefaultChar[MAX_DEFAULTCHAR];
3862 BYTE LeadByte[MAX_LEADBYTES];
3863 } CPINFO, *LPCPINFO;
3870 OUT LPCPINFO lpCPInfo);
3892 #define MB_PRECOMPOSED 0x00000001
3893 #define MB_ERR_INVALID_CHARS 0x00000008
3898 MultiByteToWideChar(
3901 IN LPCSTR lpMultiByteStr,
3903 OUT LPWSTR lpWideCharStr,
3904 IN int cchWideChar);
3906 #define WC_NO_BEST_FIT_CHARS 0x00000400
3911 WideCharToMultiByte(
3914 IN LPCWSTR lpWideCharStr,
3916 OUT LPSTR lpMultiByteStr,
3918 IN LPCSTR lpDefaultChar,
3919 OUT LPBOOL lpUsedDefaultChar);
3921 #if ENABLE_DOWNLEVEL_FOR_NLS
3926 GetSystemDefaultLangID(
3932 GetUserDefaultLangID(
3947 #endif //ENABLE_DOWNLEVEL_FOR_NLS
3952 // These types are used for the GetLocaleInfo NLS API routine.
3958 // The following LCTypes may be used in combination with any other LCTypes.
3960 // LOCALE_NOUSEROVERRIDE is also used in GetTimeFormat and
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.
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
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)
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"
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"
3984 // The following LCTypes are mutually exclusive in that they may NOT
3985 // be used in combination with each other.
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 */
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 */
3999 #define LOCALE_SLIST 0x0000000C /* list item separator */
4000 #define LOCALE_IMEASURE 0x0000000D /* 0 = metric, 1 = US */
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 */
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 */
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 */
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 */
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) */
4071 #define LOCALE_SPOSITIVESIGN 0x00000050 /* positive sign */
4072 #define LOCALE_SNEGATIVESIGN 0x00000051 /* negative sign */
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 */
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 */
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.
4117 #define LCMAP_LINGUISTIC_CASING 0x01000000 /* Use linguistic casing */
4119 #define CAL_RETURN_GENITIVE_NAMES LOCALE_RETURN_GENITIVE_NAMES // return genitive forms of month names
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
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)
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 */
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 */
4190 #if ENABLE_DOWNLEVEL_FOR_NLS
4198 OUT LPWSTR lpLCData,
4201 #endif // ENABLE_DOWNLEVEL_FOR_NLS
4207 IN LPCWSTR lpLocaleName,
4209 OUT LPWSTR lpLCData,
4216 CompareStringOrdinal(
4217 IN LPCWSTR lpString1,
4219 IN LPCWSTR lpString2,
4221 IN BOOL bIgnoreCase);
4223 typedef struct _nlsversioninfoex {
4224 DWORD dwNLSVersionInfoSize;
4226 DWORD dwDefinedVersion;
4227 DWORD dwEffectiveId;
4228 GUID guidCustomVersion;
4229 } NLSVERSIONINFOEX, *LPNLSVERSIONINFOEX;
4235 IN LPCWSTR lpLocaleName,
4236 IN DWORD dwFindNLSStringFlags,
4237 IN LPCWSTR lpStringSource,
4239 IN LPCWSTR lpStringValue,
4241 OUT LPINT pcchFound,
4242 IN LPNLSVERSIONINFOEX lpVersionInformation,
4243 IN LPVOID lpReserved,
4247 COMPARE_STRING = 0x0001,
4254 IN NLS_FUNCTION Function,
4256 IN LPNLSVERSIONINFOEX lpVersionInfo,
4257 IN LPCWSTR lpString,
4265 IN LPCWSTR lpNameToResolve,
4266 OUT LPWSTR lpLocaleName,
4267 IN int cchLocaleName );
4272 GetThreadPreferredUILanguages(
4274 OUT PULONG pulNumLanguages,
4275 OUT PWSTR pwszLanguagesBuffer,
4276 IN OUT PULONG pcchLanguagesBuffer);
4282 GetSystemDefaultLocaleName(
4283 OUT LPWSTR lpLocaleName,
4284 IN int cchLocaleName);
4287 #define GetLocaleInfo GetLocaleInfoW
4290 #if ENABLE_DOWNLEVEL_FOR_NLS
4302 GetUserDefaultLocaleName(
4303 OUT LPWSTR lpLocaleName,
4304 IN int cchLocaleName);
4307 #define LCID_INSTALLED 0x00000001 // installed locale ids
4308 #define LCID_SUPPORTED 0x00000002 // supported locale ids
4310 #define LCID_ALTERNATE_SORTS 0x00000004 // alternate sort locale ids
4313 #if ENABLE_DOWNLEVEL_FOR_NLS
4320 #endif // ENABLE_DOWNLEVEL_FOR_NLS
4323 typedef DWORD CALID;
4324 typedef DWORD CALTYPE;
4326 #define CAL_ITWODIGITYEARMAX 0x00000030 // two digit year max
4327 #define CAL_RETURN_NUMBER 0x20000000 // return number instead of string
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
4343 #if ENABLE_DOWNLEVEL_FOR_NLS
4351 OUT LPWSTR lpCalData,
4353 OUT LPDWORD lpValue);
4356 #define GetCalendarInfo GetCalendarInfoW
4359 #endif // ENABLE_DOWNLEVEL_FOR_NLS
4366 IN LPCWSTR lpLocaleName,
4368 IN LPCWSTR lpReserved,
4370 OUT LPWSTR lpCalData,
4372 OUT LPDWORD lpValue);
4374 #if ENABLE_DOWNLEVEL_FOR_NLS
4375 typedef BOOL (CALLBACK* LOCALE_ENUMPROCW)(LPWSTR);
4381 IN LOCALE_ENUMPROCW lpLocaleEnumProc,
4383 #endif // ENABLE_DOWNLEVEL_FOR_NLS
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
4389 typedef BOOL (CALLBACK* DATEFMT_ENUMPROCEXW)(LPWSTR, CALID);
4391 #if ENABLE_DOWNLEVEL_FOR_NLS
4397 IN DATEFMT_ENUMPROCEXW lpDateFmtEnumProcEx,
4401 #else // ENABLE_DOWNLEVEL_FOR_NLS
4403 typedef BOOL (CALLBACK* DATEFMT_ENUMPROCEXEXW)(LPWSTR, CALID, LPARAM);
4408 EnumDateFormatsExEx(
4409 IN DATEFMT_ENUMPROCEXEXW lpDateFmtEnumProcEx,
4410 IN LPCWSTR lpLocaleName,
4414 #endif // ENABLE_DOWNLEVEL_FOR_NLS
4416 typedef BOOL (CALLBACK* TIMEFMT_ENUMPROCW)(LPWSTR);
4418 #if ENABLE_DOWNLEVEL_FOR_NLS
4424 IN TIMEFMT_ENUMPROCW lpTimeFmtEnumProc,
4428 #else // ENABLE_DOWNLEVEL_FOR_NLS
4430 typedef BOOL (CALLBACK* TIMEFMT_ENUMPROCEXW)(LPWSTR, LPARAM);
4436 IN TIMEFMT_ENUMPROCEXW lpTimeFmtEnumProc,
4437 IN LPCWSTR lpLocaleName,
4441 #endif // ENABLE_DOWNLEVEL_FOR_NLS
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
4448 typedef BOOL (CALLBACK* CALINFO_ENUMPROCEXW)(LPWSTR,CALID);
4450 #if ENABLE_DOWNLEVEL_FOR_NLS
4455 EnumCalendarInfoExW(
4456 IN CALINFO_ENUMPROCEXW lpCalInfoEnumProc,
4459 IN CALTYPE CalType);
4461 #else // ENABLE_DOWNLEVEL_FOR_NLS
4463 typedef BOOL (CALLBACK* CALINFO_ENUMPROCEXEXW)(LPWSTR, CALID, LPWSTR, LPARAM);
4468 EnumCalendarInfoExEx(
4469 IN CALINFO_ENUMPROCEXEXW lpCalInfoEnumProc,
4470 IN LPCWSTR lpLocaleName,
4472 IN LPCWSTR lpReserved,
4476 #endif // ENABLE_DOWNLEVEL_FOR_NLS
4478 #define LCMAP_LOWERCASE 0x00000100
4479 #define LCMAP_UPPERCASE 0x00000200
4481 #if ENABLE_DOWNLEVEL_FOR_NLS
4488 IN DWORD dwMapFlags,
4489 IN LPCWSTR lpSrcStr,
4491 OUT LPWSTR lpDestStr,
4495 #define LCMapString LCMapStringW
4499 #endif // ENABLE_DOWNLEVEL_FOR_NLS
4506 IN LPCWSTR lpLocaleName,
4507 IN DWORD dwMapFlags,
4508 IN LPCWSTR lpSrcStr,
4510 OUT LPWSTR lpDestStr,
4512 IN LPNLSVERSIONINFO lpVersionInformation,
4513 IN LPVOID lpReserved,
4520 IN LPCWSTR lpLocaleName,
4521 IN DWORD dwMapFlags,
4523 OUT WCHAR *destChar,
4524 LPNLSVERSIONINFO lpVersionInformation,
4531 PAL_NormalizeStringExW(
4532 IN LPCWSTR lpLocaleName,
4533 IN DWORD dwMapFlags,
4534 IN LPCWSTR lpSrcStr,
4536 OUT LPWSTR lpDestStr,
4543 IN LPCWSTR lpLocaleName,
4544 IN LPCWSTR lpFormat,
4545 IN LPCWSTR lpString,
4546 OUT LPSYSTEMTIME lpTime);
4552 IN LPCWSTR lpLocaleName,
4553 OUT CALID* pCalendar);
4555 #define GEOID_NOT_AVAILABLE -1
4557 #define DATE_USE_ALT_CALENDAR 0x00000004
4559 #if ENABLE_DOWNLEVEL_FOR_NLS
4567 IN CONST SYSTEMTIME *lpDate,
4568 IN LPCWSTR lpFormat,
4569 OUT LPWSTR lpDateStr,
4580 IN CONST SYSTEMTIME *lpDate,
4581 IN LPCWSTR lpFormat,
4582 OUT LPWSTR lpDateStr,
4584 IN LPCWSTR lpCalendar);
4587 #endif // ENABLE_DOWNLEVEL_FOR_NLS
4593 IN LPCWSTR lpLocaleName,
4595 IN CONST SYSTEMTIME *lpDate,
4596 IN LPCWSTR lpFormat,
4597 OUT LPWSTR lpDateStr,
4599 LPCWSTR lpCalendar);
4603 #define GetDateFormat GetDateFormatW
4610 PAL_GetResourceString(
4612 IN LPCSTR lpResourceStr,
4613 OUT LPWSTR lpWideCharStr,
4614 IN int cchWideChar);
4619 PAL_BindResources(IN LPCSTR lpDomain);
4621 #define EXCEPTION_NONCONTINUABLE 0x1
4622 #define EXCEPTION_UNWINDING 0x2
4624 #ifdef FEATURE_PAL_SXS
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
4632 #define EXCEPTION_UNWIND (EXCEPTION_UNWINDING | EXCEPTION_EXIT_UNWIND | \
4633 EXCEPTION_TARGET_UNWIND | EXCEPTION_COLLIDED_UNWIND)
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)
4639 #endif // FEATURE_PAL_SXS
4641 #define EXCEPTION_IS_SIGNAL 0x100
4643 #define EXCEPTION_MAXIMUM_PARAMETERS 15
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)
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;
4659 typedef struct _EXCEPTION_POINTERS {
4660 PEXCEPTION_RECORD ExceptionRecord;
4661 PCONTEXT ContextRecord;
4662 } EXCEPTION_POINTERS, *PEXCEPTION_POINTERS, *LPEXCEPTION_POINTERS;
4664 #ifdef FEATURE_PAL_SXS
4666 typedef LONG EXCEPTION_DISPOSITION;
4669 ExceptionContinueExecution,
4670 ExceptionContinueSearch,
4671 ExceptionNestedException,
4672 ExceptionCollidedUnwind,
4675 #endif // FEATURE_PAL_SXS
4678 // A function table entry is generated for each frame function.
4680 typedef struct _RUNTIME_FUNCTION {
4686 } RUNTIME_FUNCTION, *PRUNTIME_FUNCTION;
4688 #define STANDARD_RIGHTS_REQUIRED (0x000F0000L)
4689 #define SYNCHRONIZE (0x00100000L)
4690 #define READ_CONTROL (0x00020000L)
4692 #define EVENT_MODIFY_STATE (0x0002)
4693 #define EVENT_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | \
4696 #define MUTANT_QUERY_STATE (0x0001)
4697 #define MUTANT_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | \
4699 #define MUTEX_ALL_ACCESS MUTANT_ALL_ACCESS
4701 #define SEMAPHORE_MODIFY_STATE (0x0002)
4702 #define SEMAPHORE_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | \
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 | \
4724 IN DWORD dwDesiredAccess, /* PROCESS_DUP_HANDLE or PROCESS_ALL_ACCESS */
4725 IN BOOL bInheritHandle,
4726 IN DWORD dwProcessId
4734 OUT HMODULE *lphModule,
4736 OUT LPDWORD lpcbNeeded
4743 IN LPCSTR lpOutputString);
4749 IN LPCWSTR lpOutputStrig);
4752 #define OutputDebugString OutputDebugStringW
4754 #define OutputDebugString OutputDebugStringA
4767 IN LPCSTR lpString);
4773 IN LPCWSTR lpString);
4776 #define lstrlen lstrlenW
4778 #define lstrlen lstrlenA
4784 GetEnvironmentVariableW(
4786 OUT LPWSTR lpBuffer,
4790 #define GetEnvironmentVariable GetEnvironmentVariableW
4792 #define GetEnvironmentVariable GetEnvironmentVariableA
4798 SetEnvironmentVariableW(
4800 IN LPCWSTR lpValue);
4803 #define SetEnvironmentVariable SetEnvironmentVariableW
4805 #define SetEnvironmentVariable SetEnvironmentVariableA
4811 GetEnvironmentStringsW(
4815 #define GetEnvironmentStrings GetEnvironmentStringsW
4817 #define GetEnvironmentStrings GetEnvironmentStringsA
4823 FreeEnvironmentStringsW(
4827 #define FreeEnvironmentStrings FreeEnvironmentStringsW
4829 #define FreeEnvironmentStrings FreeEnvironmentStringsA
4836 IN OUT HANDLE hObject);
4842 IN DWORD dwExceptionCode,
4843 IN DWORD dwExceptionFlags,
4844 IN DWORD nNumberOfArguments,
4845 IN CONST ULONG_PTR *lpArguments);
4847 #ifdef FEATURE_PAL_SXS
4853 IN PEXCEPTION_POINTERS ExceptionPointers);
4854 #endif // FEATURE_PAL_SXS
4865 GetTickCount64(VOID);
4870 QueryPerformanceCounter(
4871 OUT LARGE_INTEGER *lpPerformanceCount
4877 QueryPerformanceFrequency(
4878 OUT LARGE_INTEGER *lpFrequency
4884 QueryThreadCycleTime(
4885 IN HANDLE ThreadHandle,
4886 OUT PULONG64 CycleTime);
4888 #ifndef FEATURE_PAL_SXS
4890 typedef LONG (PALAPI *PTOP_LEVEL_EXCEPTION_FILTER)(
4891 struct _EXCEPTION_POINTERS *ExceptionInfo);
4892 typedef PTOP_LEVEL_EXCEPTION_FILTER LPTOP_LEVEL_EXCEPTION_FILTER;
4895 LPTOP_LEVEL_EXCEPTION_FILTER
4897 SetUnhandledExceptionFilter(
4898 IN LPTOP_LEVEL_EXCEPTION_FILTER lpTopLevelExceptionFilter);
4900 #else // FEATURE_PAL_SXS
4902 typedef EXCEPTION_DISPOSITION (PALAPI *PVECTORED_EXCEPTION_HANDLER)(
4903 struct _EXCEPTION_POINTERS *ExceptionPointers);
4905 #endif // FEATURE_PAL_SXS
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.
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.
4915 // The same is true for BitScanForward, except that the GCC function is __builtin_ffs.
4922 IN OUT PDWORD Index,
4925 unsigned char bRet = FALSE;
4926 int iIndex = __builtin_ffsl(qwMask);
4929 // Set the Index after deducting unity
4930 *Index = (DWORD)(iIndex - 1);
4943 IN OUT PDWORD Index,
4946 unsigned char bRet = FALSE;
4947 int iIndex = __builtin_ffsl(qwMask);
4950 // Set the Index after deducting unity
4951 *Index = (DWORD)(iIndex - 1);
4960 InterlockedIncrement
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
4970 [in/out] Pointer to the variable to increment.
4974 The return value is the resulting incremented value.
4982 InterlockedIncrement(
4983 IN OUT LONG volatile *lpAddend)
4985 return __sync_add_and_fetch(lpAddend, (LONG)1);
4993 InterlockedIncrement64(
4994 IN OUT LONGLONG volatile *lpAddend)
4996 return __sync_add_and_fetch(lpAddend, (LONGLONG)1);
5001 InterlockedDecrement
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
5011 [in/out] Pointer to the variable to decrement.
5015 The return value is the resulting decremented value.
5023 InterlockedDecrement(
5024 IN OUT LONG volatile *lpAddend)
5026 return __sync_sub_and_fetch(lpAddend, (LONG)1);
5034 InterlockedDecrement64(
5035 IN OUT LONGLONG volatile *lpAddend)
5037 return __sync_sub_and_fetch(lpAddend, (LONGLONG)1);
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.
5051 [in/out] Pointer to the value to exchange. The function sets
5052 this variable to Value, and returns its prior value.
5054 [in] Specifies a new value for the variable pointed to by Target.
5058 The function returns the initial value pointed to by Target.
5066 InterlockedExchange(
5067 IN OUT LONG volatile *Target,
5070 return __sync_swap(Target, Value);
5078 InterlockedExchange64(
5079 IN OUT LONGLONG volatile *Target,
5082 return __sync_swap(Target, Value);
5087 InterlockedCompareExchange
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.
5094 If you are exchanging pointer values, this function has been
5095 superseded by the InterlockedCompareExchangePointer function.
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.
5105 The return value is the initial value of the destination.
5113 InterlockedCompareExchange(
5114 IN OUT LONG volatile *Destination,
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 */);
5129 InterlockedCompareExchangeAcquire(
5130 IN OUT LONG volatile *Destination,
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 */);
5146 InterlockedCompareExchangeRelease(
5147 IN OUT LONG volatile *Destination,
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 */);
5158 // See the 32-bit variant in interlock2.s
5164 InterlockedCompareExchange64(
5165 IN OUT LONGLONG volatile *Destination,
5166 IN LONGLONG Exchange,
5167 IN LONGLONG Comperand)
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 */);
5177 InterlockedExchangeAdd
5179 The InterlockedExchangeAdd function atomically adds the value of 'Value'
5180 to the variable that 'Addend' points to.
5185 [in/out] Pointer to the variable to to added.
5189 The return value is the original value that 'Addend' pointed to.
5197 InterlockedExchangeAdd(
5198 IN OUT LONG volatile *Addend,
5201 return __sync_fetch_and_add(Addend, Value);
5209 InterlockedExchangeAdd64(
5210 IN OUT LONGLONG volatile *Addend,
5213 return __sync_fetch_and_add(Addend, Value);
5222 IN OUT LONG volatile *Destination,
5225 return __sync_fetch_and_and(Destination, Value);
5234 IN OUT LONG volatile *Destination,
5237 return __sync_fetch_and_or(Destination, Value);
5245 InterlockedBitTestAndReset(
5246 IN OUT LONG volatile *Base,
5249 return (InterlockedAnd(Base, ~(1 << Bit)) & (1 << Bit)) != 0;
5257 InterlockedBitTestAndSet(
5258 IN OUT LONG volatile *Base,
5261 return (InterlockedOr(Base, (1 << Bit)) & (1 << Bit)) != 0;
5265 #define InterlockedExchangePointer(Target, Value) \
5266 ((PVOID)InterlockedExchange64((PLONG64)(Target), (LONGLONG)(Value)))
5268 #define InterlockedCompareExchangePointer(Destination, ExChange, Comperand) \
5269 ((PVOID)InterlockedCompareExchange64((PLONG64)(Destination), (LONGLONG)(ExChange), (LONGLONG)(Comperand)))
5271 #define InterlockedExchangePointer(Target, Value) \
5272 ((PVOID)(UINT_PTR)InterlockedExchange((PLONG)(UINT_PTR)(Target), (LONG)(UINT_PTR)(Value)))
5274 #define InterlockedCompareExchangePointer(Destination, ExChange, Comperand) \
5275 ((PVOID)(UINT_PTR)InterlockedCompareExchange((PLONG)(UINT_PTR)(Destination), (LONG)(UINT_PTR)(ExChange), (LONG)(UINT_PTR)(Comperand)))
5282 The MemoryBarrier function creates a full memory barrier.
5293 __sync_synchronize();
5305 GetCurrentProcessorNumber(VOID);
5309 PAL_HasGetCurrentProcessorNumber
5311 Checks if GetCurrentProcessorNumber is available in the current environment
5317 PAL_HasGetCurrentProcessorNumber(VOID);
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
5331 IN LPCVOID lpSource,
5332 IN DWORD dwMessageId,
5333 IN DWORD dwLanguageId,
5336 IN va_list *Arguments);
5339 #define FormatMessage FormatMessageW
5353 IN DWORD dwErrCode);
5362 #define GetCommandLine GetCommandLineW
5369 IN PCONTEXT ContextRecord,
5370 IN PEXCEPTION_RECORD ExceptionRecord
5377 OUT PCONTEXT ContextRecord
5385 IN PVOID lpBaseAddress,
5386 IN SIZE_T dwRegionSize,
5387 OUT PVOID *lpAddresses,
5388 IN OUT PULONG_PTR lpdwCount,
5389 OUT PULONG lpdwGranularity
5396 IN LPVOID lpBaseAddress,
5397 IN SIZE_T dwRegionSize
5403 FlushProcessWriteBuffers(VOID);
5405 typedef void (*PAL_ActivationFunction)(CONTEXT *context);
5406 typedef BOOL (*PAL_SafeActivationCheckFunction)(SIZE_T ip, BOOL checkingCurrentThread);
5411 PAL_SetActivationFunction(
5412 IN PAL_ActivationFunction pActivationFunction,
5413 IN PAL_SafeActivationCheckFunction pSafeActivationCheckFunction);
5418 PAL_InjectActivation(
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
5427 typedef struct _OSVERSIONINFOA {
5428 DWORD dwOSVersionInfoSize;
5429 DWORD dwMajorVersion;
5430 DWORD dwMinorVersion;
5431 DWORD dwBuildNumber;
5433 CHAR szCSDVersion[ 128 ];
5434 } OSVERSIONINFOA, *POSVERSIONINFOA, *LPOSVERSIONINFOA;
5436 typedef struct _OSVERSIONINFOW {
5437 DWORD dwOSVersionInfoSize;
5438 DWORD dwMajorVersion;
5439 DWORD dwMinorVersion;
5440 DWORD dwBuildNumber;
5442 WCHAR szCSDVersion[ 128 ];
5443 } OSVERSIONINFOW, *POSVERSIONINFOW, *LPOSVERSIONINFOW;
5446 typedef OSVERSIONINFOW OSVERSIONINFO;
5447 typedef POSVERSIONINFOW POSVERSIONINFO;
5448 typedef LPOSVERSIONINFOW LPOSVERSIONINFO;
5450 typedef OSVERSIONINFOA OSVERSIONINFO;
5451 typedef POSVERSIONINFOA POSVERSIONINFO;
5452 typedef LPOSVERSIONINFOA LPOSVERSIONINFO;
5455 typedef struct _OSVERSIONINFOEXA {
5456 DWORD dwOSVersionInfoSize;
5457 DWORD dwMajorVersion;
5458 DWORD dwMinorVersion;
5459 DWORD dwBuildNumber;
5461 CHAR szCSDVersion[ 128 ];
5462 WORD wServicePackMajor;
5463 WORD wServicePackMinor;
5467 } OSVERSIONINFOEXA, *POSVERSIONINFOEXA, *LPOSVERSIONINFOEXA;
5469 typedef struct _OSVERSIONINFOEXW {
5470 DWORD dwOSVersionInfoSize;
5471 DWORD dwMajorVersion;
5472 DWORD dwMinorVersion;
5473 DWORD dwBuildNumber;
5475 WCHAR szCSDVersion[ 128 ];
5476 WORD wServicePackMajor;
5477 WORD wServicePackMinor;
5481 } OSVERSIONINFOEXW, *POSVERSIONINFOEXW, *LPOSVERSIONINFOEXW;
5484 typedef OSVERSIONINFOEXW OSVERSIONINFOEX;
5485 typedef POSVERSIONINFOEXW POSVERSIONINFOEX;
5486 typedef LPOSVERSIONINFOEXW LPOSVERSIONINFOEX;
5488 typedef OSVERSIONINFOEXA OSVERSIONINFOEX;
5489 typedef POSVERSIONINFOEXA POSVERSIONINFOEX;
5490 typedef LPOSVERSIONINFOEXA LPOSVERSIONINFOEX;
5497 IN OUT LPOSVERSIONINFOW lpVersionInformation);
5500 #define GetVersionEx GetVersionExW
5502 #define GetVersionEx GetVersionExA
5505 #define IMAGE_FILE_MACHINE_I386 0x014c
5506 #define IMAGE_FILE_MACHINE_ARM64 0xAA64 // ARM64 Little-Endian
5508 typedef struct _SYSTEM_INFO {
5509 WORD wProcessorArchitecture_PAL_Undefined;
5510 WORD wReserved_PAL_Undefined; // NOTE: diff from winbase.h - no obsolete dwOemId union
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;
5526 OUT LPSYSTEM_INFO lpSystemInfo);
5532 LPCWSTR lpDirectoryName,
5533 LPDWORD lpSectorsPerCluster,
5534 LPDWORD lpBytesPerSector,
5535 LPDWORD lpNumberOfFreeClusters,
5536 LPDWORD lpTotalNumberOfClusters);
5539 #define GetDiskFreeSpace GetDiskFreeSpaceW
5546 OUT PHANDLE hReadPipe,
5547 OUT PHANDLE hWritePipe,
5548 IN LPSECURITY_ATTRIBUTES lpPipeAttributes,
5555 DeregisterEventSource (
5562 RegisterEventSourceA (
5563 IN OPTIONAL LPCSTR lpUNCServerName,
5564 IN LPCSTR lpSourceName
5569 RegisterEventSourceW (
5570 IN OPTIONAL LPCWSTR lpUNCServerName,
5571 IN LPCWSTR lpSourceName
5574 #define RegisterEventSource RegisterEventSourceW
5576 #define RegisterEventSource RegisterEventSourceA
5580 // The types of events that can be logged.
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
5593 IN HANDLE hEventLog,
5597 IN OPTIONAL PSID lpUserSid,
5598 IN WORD wNumStrings,
5599 IN DWORD dwDataSize,
5600 IN OPTIONAL LPCSTR *lpStrings,
5601 IN OPTIONAL LPVOID lpRawData
5607 IN HANDLE hEventLog,
5611 IN OPTIONAL PSID lpUserSid,
5612 IN WORD wNumStrings,
5613 IN DWORD dwDataSize,
5614 IN OPTIONAL LPCWSTR *lpStrings,
5615 IN OPTIONAL LPVOID lpRawData
5618 #define ReportEvent ReportEventW
5620 #define ReportEvent ReportEventA
5626 CoCreateGuid(OUT GUID * pguid);
5628 #if defined FEATURE_PAL_ANSI
5629 #include "palprivate.h"
5630 #endif //FEATURE_PAL_ANSI
5631 /******************* C Runtime Entrypoints *******************************/
5633 /* Some C runtime functions needs to be reimplemented by the PAL.
5634 To avoid name collisions, those functions have been renamed using
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
5712 #define log10 PAL_log10
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
5734 #define _mm_getcsr PAL__mm_getcsr
5735 #define _mm_setcsr PAL__mm_setcsr
5738 #endif // !PAL_STDCPP_COMPAT
5739 #endif // PLATFORM_UNIX
5741 #ifndef _CONST_RETURN
5743 #define _CONST_RETURN const
5744 #define _CRT_CONST_CORRECT_OVERLOADS
5746 #define _CONST_RETURN
5750 /* For backwards compatibility */
5751 #define _WConst_return _CONST_RETURN
5755 typedef int errno_t;
5757 #ifndef PAL_STDCPP_COMPAT
5764 PALIMPORT div_t div(int numer, int denom);
5772 Overlapping buffer-safe version of memcpy.
5773 See MSDN doc for memcpy
5777 void *PAL_memcpy (void *dest, const void *src, size_t count);
5779 PALIMPORT void * __cdecl memcpy(void *, const void *, size_t);
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);
5824 #endif // PAL_STDCPP_COMPAT
5827 #if !defined(_TRUNCATE)
5828 #define _TRUNCATE ((size_t)-1)
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);
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);
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 *);
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)); }
5912 unsigned int __cdecl _rotl(unsigned int value, int shift)
5914 unsigned int retval = 0;
5917 retval = (value << shift) | (value >> (sizeof(int) * CHAR_BIT - shift));
5921 // On 64 bit unix, make the long an int.
5923 #define _lrotl _rotl
5935 unsigned int __cdecl _rotr(unsigned int value, int shift)
5937 unsigned int retval;
5940 retval = (value >> shift) | (value << (sizeof(int) * CHAR_BIT - shift));
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);
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);
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);
5999 #ifndef PAL_STDCPP_COMPAT
6004 inline __int64 abs(__int64 _X) {
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 *);
6016 #if defined(_MSC_VER)
6017 #define alloca _alloca
6018 #elif defined(PLATFORM_UNIX)
6019 #define _alloca alloca
6022 #define _alloca __builtin_alloca
6023 #define alloca __builtin_alloca
6026 #if defined(__GNUC__) && defined(PLATFORM_UNIX)
6027 #define alloca __builtin_alloca
6030 #define max(a, b) (((a) > (b)) ? (a) : (b))
6031 #define min(a, b) (((a) < (b)) ? (a) : (b))
6033 #endif // !PAL_STDCPP_COMPAT
6035 PALIMPORT PAL_NORETURN void __cdecl exit(int);
6036 int __cdecl atexit(void (__cdecl *function)(void));
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 *));
6042 PALIMPORT char * __cdecl _fullpath(char *, const char *, size_t);
6044 #ifndef PAL_STDCPP_COMPAT
6045 PALIMPORT time_t __cdecl time(time_t *);
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 */
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
6064 PALIMPORT int __cdecl _open_osfhandle(INT_PTR, int);
6065 PALIMPORT int __cdecl _close(int);
6066 PALIMPORT int __cdecl _flushall();
6068 #ifdef PAL_STDCPP_COMPAT
6071 typedef struct _PAL_FILE PAL_FILE;
6073 #else // PAL_STDCPP_COMPAT
6076 typedef struct _FILE FILE;
6077 typedef struct _FILE PAL_FILE;
6083 /* Locale categories */
6085 #define LC_COLLATE 1
6087 #define LC_MONETARY 3
6088 #define LC_NUMERIC 4
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 */
6095 #endif // PAL_STDCPP_COMPAT
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*, ...);
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);
6128 /* Maximum value that can be returned by the rand function. */
6130 #ifndef PAL_STDCPP_COMPAT
6131 #define RAND_MAX 0x7fff
6132 #endif // !PAL_STDCPP_COMPAT
6134 PALIMPORT int __cdecl rand(void);
6135 PALIMPORT void __cdecl srand(unsigned int);
6137 PALIMPORT int __cdecl printf(const char *, ...);
6138 PALIMPORT int __cdecl vprintf(const char *, va_list);
6141 #define PAL_get_caller _MSC_VER
6143 #define PAL_get_caller 0
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);
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
6163 PALIMPORT char * __cdecl getenv(const char *);
6164 PALIMPORT int __cdecl _putenv(const char *);
6168 /******************* PAL-specific I/O completion port *****************/
6170 typedef struct _PAL_IOCP_CPU_INFORMATION {
6172 FILETIME ftLastRecordedIdleTime;
6173 FILETIME ftLastRecordedCurrentTime;
6175 FILETIME ftLastRecordedKernelTime;
6176 FILETIME ftLastRecordedUserTime;
6177 } PAL_IOCP_CPU_INFORMATION;
6183 IN OUT PAL_IOCP_CPU_INFORMATION *lpPrevCPUInfo);
6185 /****************PAL Perf functions for PInvoke*********************/
6190 PAL_EnableProcessProfile(VOID);
6195 PAL_DisableProcessProfile(VOID);
6200 PAL_IsProcessProfileEnabled(VOID);
6205 PAL_GetCpuTickCount(VOID);
6208 /******************* PAL functions for SIMD extensions *****************/
6211 unsigned int _mm_getcsr(void);
6214 void _mm_setcsr(unsigned int i);
6216 /******************* PAL side-by-side support ************************/
6218 #ifdef FEATURE_PAL_SXS
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.
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).
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
6237 PAL_BoundaryMax = PAL_BoundaryEH
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.
6250 PAL_Enter(PAL_Boundary boundary);
6252 // Returns TRUE if we this thread has already entered the PAL,
6253 // returns FALSE if we have not entered the PAL.
6257 PAL_HasEntered(VOID);
6259 // Equivalent to PAL_Enter(PAL_BoundaryTop) and is for stub
6260 // code generation use.
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.
6273 PAL_Reenter(PAL_Boundary boundary);
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.
6284 PAL_ReenterForEH(VOID);
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.
6292 PAL_Leave(PAL_Boundary boundary);
6294 // This function is equivalent to PAL_Leave(PAL_BoundaryBottom)
6295 // and is available to limit the creation of stub code.
6299 PAL_LeaveBottom(VOID);
6301 // This function is equivalent to PAL_Leave(PAL_BoundaryTop)
6302 // and is available to limit the creation of stub code.
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).
6314 class PAL_EnterHolder
6320 PAL_EnterHolder(BOOL fEnter = TRUE) : m_palError(ERROR_SUCCESS)
6324 m_palError = PAL_Enter(PAL_BoundaryTop);
6325 m_fEntered = m_palError == ERROR_SUCCESS;
6337 PAL_Leave(PAL_BoundaryTop);
6346 void SuppressRelease()
6348 // Used to avoid calling PAL_Leave() when
6349 // another code path will explicitly do so.
6354 class PAL_LeaveHolder
6359 PAL_Leave(PAL_BoundaryBottom);
6364 PAL_Reenter(PAL_BoundaryBottom);
6367 #endif // __cplusplus
6369 #else // FEATURE_PAL_SXS
6371 #define PAL_Enter(boundary) ERROR_SUCCESS
6372 #define PAL_Reenter(boundary)
6373 #define PAL_Leave(boundary)
6376 class PAL_EnterHolder {
6378 // using constructor to suppress the "unused variable" warnings
6379 PAL_EnterHolder() {}
6381 class PAL_LeaveHolder {
6383 // using constructor to suppress the "unused variable" warnings
6384 PAL_LeaveHolder() {}
6386 #endif // __cplusplus
6388 #endif // FEATURE_PAL_SXS
6392 #include "pal_unwind.h"
6397 PAL_FreeExceptionRecords(
6398 IN EXCEPTION_RECORD *exceptionRecord,
6399 IN CONTEXT *contextRecord);
6401 #define EXCEPTION_CONTINUE_SEARCH 0
6402 #define EXCEPTION_EXECUTE_HANDLER 1
6403 #define EXCEPTION_CONTINUE_EXECUTION -1
6405 struct PAL_SEHException
6408 static const SIZE_T NoTargetFrameSp = SIZE_MAX;
6410 void Move(PAL_SEHException& ex)
6412 ExceptionPointers.ExceptionRecord = ex.ExceptionPointers.ExceptionRecord;
6413 ExceptionPointers.ContextRecord = ex.ExceptionPointers.ContextRecord;
6414 TargetFrameSp = ex.TargetFrameSp;
6421 if (ExceptionPointers.ExceptionRecord != NULL)
6423 PAL_FreeExceptionRecords(ExceptionPointers.ExceptionRecord, ExceptionPointers.ContextRecord);
6424 ExceptionPointers.ExceptionRecord = NULL;
6425 ExceptionPointers.ContextRecord = NULL;
6430 EXCEPTION_POINTERS ExceptionPointers;
6431 // Target frame stack pointer set before the 2nd pass.
6432 SIZE_T TargetFrameSp;
6434 PAL_SEHException(EXCEPTION_RECORD *pExceptionRecord, CONTEXT *pContextRecord)
6436 ExceptionPointers.ExceptionRecord = pExceptionRecord;
6437 ExceptionPointers.ContextRecord = pContextRecord;
6438 TargetFrameSp = NoTargetFrameSp;
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;
6452 PAL_SEHException(PAL_SEHException&& ex)
6457 PAL_SEHException& operator=(PAL_SEHException&& ex)
6471 ExceptionPointers.ExceptionRecord = NULL;
6472 ExceptionPointers.ContextRecord = NULL;
6473 TargetFrameSp = NoTargetFrameSp;
6476 CONTEXT* GetContextRecord()
6478 return ExceptionPointers.ContextRecord;
6481 EXCEPTION_RECORD* GetExceptionRecord()
6483 return ExceptionPointers.ExceptionRecord;
6488 return (TargetFrameSp == NoTargetFrameSp);
6491 void SecondPassDone()
6493 TargetFrameSp = NoTargetFrameSp;
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);
6505 PAL_SetHardwareExceptionHandler(
6506 IN PHARDWARE_EXCEPTION_HANDLER exceptionHandler,
6507 IN PHARDWARE_EXCEPTION_SAFETY_CHECK_FUNCTION exceptionCheckFunction);
6512 PAL_SetGetGcMarkerExceptionCode(
6513 IN PGET_GCMARKER_EXCEPTION_CODE getGcMarkerExceptionCode);
6518 PAL_ThrowExceptionFromContext(
6519 IN CONTEXT* context,
6520 IN PAL_SEHException* ex);
6525 PAL_SetTerminationRequestHandler(
6526 IN PTERMINATION_REQUEST_HANDLER terminationRequestHandler);
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.
6533 class CatchHardwareExceptionHolder
6536 CatchHardwareExceptionHolder();
6538 ~CatchHardwareExceptionHolder();
6540 static bool IsEnabled();
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
6548 #ifdef FEATURE_ENABLE_HARDWARE_EXCEPTIONS
6549 #define HardwareExceptionHolder CatchHardwareExceptionHolder __catchHardwareException;
6551 #define HardwareExceptionHolder
6552 #endif // FEATURE_ENABLE_HARDWARE_EXCEPTIONS
6554 #ifdef FEATURE_PAL_SXS
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.
6564 class NativeExceptionHolderBase
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;
6570 // The next holder on the stack
6571 NativeExceptionHolderBase *m_next;
6574 NativeExceptionHolderBase();
6576 ~NativeExceptionHolderBase();
6579 // Calls the holder's filter handler.
6580 virtual EXCEPTION_DISPOSITION InvokeFilter(PAL_SEHException& ex) = 0;
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).
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);
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
6597 template<class FilterType>
6598 class NativeExceptionHolder : public NativeExceptionHolderBase
6600 FilterType* m_exceptionFilter;
6603 NativeExceptionHolder(FilterType* exceptionFilter)
6604 : NativeExceptionHolderBase()
6606 m_exceptionFilter = exceptionFilter;
6609 virtual EXCEPTION_DISPOSITION InvokeFilter(PAL_SEHException& ex)
6611 return (*m_exceptionFilter)(ex);
6616 // This is a native exception holder that is used when the catch catches
6619 class NativeExceptionHolderCatchAll : public NativeExceptionHolderBase
6623 NativeExceptionHolderCatchAll()
6624 : NativeExceptionHolderBase()
6628 virtual EXCEPTION_DISPOSITION InvokeFilter(PAL_SEHException& ex)
6630 return EXCEPTION_EXECUTE_HANDLER;
6634 // This is a native exception holder that doesn't catch any exceptions.
6635 class NativeExceptionHolderNoCatch : public NativeExceptionHolderBase
6639 NativeExceptionHolderNoCatch()
6640 : NativeExceptionHolderBase()
6644 virtual EXCEPTION_DISPOSITION InvokeFilter(PAL_SEHException& ex)
6646 return EXCEPTION_CONTINUE_SEARCH;
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.
6655 class NativeExceptionHolderFactory
6658 template<class FilterType>
6659 static NativeExceptionHolder<FilterType> CreateHolder(FilterType* exceptionFilter)
6661 return NativeExceptionHolder<FilterType>(exceptionFilter);
6665 // Start of a try block for exceptions raised by RaiseException
6666 #define PAL_TRY(__ParamType, __paramDef, __paramRef) \
6668 __ParamType __param = __paramRef; \
6669 auto tryBlock = [](__ParamType __paramDef) \
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
6677 #define PAL_EXCEPT(dispositionExpression) \
6679 const bool isFinally = false; \
6680 auto finallyBlock = []() {}; \
6681 EXCEPTION_DISPOSITION disposition = EXCEPTION_CONTINUE_EXECUTION; \
6682 auto exceptionFilter = [&disposition, &__param](PAL_SEHException& ex) \
6684 disposition = dispositionExpression; \
6685 _ASSERTE(disposition != EXCEPTION_CONTINUE_EXECUTION); \
6686 return disposition; \
6690 HardwareExceptionHolder \
6691 auto __exceptionHolder = NativeExceptionHolderFactory::CreateHolder(&exceptionFilter); \
6692 __exceptionHolder.Push(); \
6693 tryBlock(__param); \
6695 catch (PAL_SEHException& ex) \
6697 if (disposition == EXCEPTION_CONTINUE_EXECUTION) \
6699 exceptionFilter(ex); \
6701 if (disposition == EXCEPTION_CONTINUE_SEARCH) \
6705 ex.SecondPassDone();
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))
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 \
6715 const bool isFinally = true; \
6716 auto finallyBlock = [&]() \
6719 // End of an except or a finally block.
6720 #define PAL_ENDTRY \
6726 tryBlock(__param); \
6739 #endif // FEATURE_PAL_SXS
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); \
6750 catch (PAL_SEHException& ex) { ex.SecondPassDone(); } \
6753 #define PAL_CPP_ENDTRY }
6756 #pragma warning(disable:4611) // interaction between '_setjmp' and C++ object destruction is non-portable
6759 #ifdef FEATURE_PAL_SXS
6761 #define PAL_TRY_FOR_DLLMAIN(ParamType, paramDef, paramRef, _reason) PAL_TRY(ParamType, paramDef, paramRef)
6763 #else // FEATURE_PAL_SXS
6765 #define PAL_TRY(ParamType, paramDef, paramRef) \
6767 ParamType __param = paramRef; \
6768 ParamType paramDef; paramDef = __param; \
6770 HardwareExceptionHolder
6772 #define PAL_TRY_FOR_DLLMAIN(ParamType, paramDef, paramRef, _reason) \
6774 ParamType __param = paramRef; \
6775 ParamType paramDef; paramDef = __param; \
6777 HardwareExceptionHolder
6779 #define PAL_ENDTRY \
6783 #endif // FEATURE_PAL_SXS
6785 #endif // __cplusplus
6787 // Platform-specific library naming
6789 #ifdef PLATFORM_UNIX
6791 #define MAKEDLLNAME_W(name) u"lib" name u".dylib"
6792 #define MAKEDLLNAME_A(name) "lib" name ".dylib"
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"
6800 #define MAKEDLLNAME_W(name) u"lib" name u".so"
6801 #define MAKEDLLNAME_A(name) "lib" name ".so"
6804 #define MAKEDLLNAME_W(name) name L".dll"
6805 #define MAKEDLLNAME_A(name) name ".dll"
6809 #define MAKEDLLNAME(x) MAKEDLLNAME_W(x)
6811 #define MAKEDLLNAME(x) MAKEDLLNAME_A(x)
6814 #define PAL_SHLIB_PREFIX "lib"
6817 #define PAL_SHLIB_SUFFIX ".dylib"
6819 #define PAL_SHLIB_SUFFIX ".a"
6821 #define PAL_SHLIB_SUFFIX ".sl"
6823 #define PAL_SHLIB_SUFFIX ".so"
6826 #define DBG_EXCEPTION_HANDLED ((DWORD )0x00010001L)
6827 #define DBG_CONTINUE ((DWORD )0x00010002L)
6828 #define DBG_EXCEPTION_NOT_HANDLED ((DWORD )0x80010001L)
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)
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)
6865 #define WAIT_IO_COMPLETION STATUS_USER_APC
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
6890 #define CONTROL_C_EXIT STATUS_CONTROL_C_EXIT
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