135666602492ecfcde01b4e1a74fe9372dd9217e
[platform/upstream/coreclr.git] / src / inc / clrnt.h
1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
4
5
6 #ifndef CLRNT_H_
7 #define CLRNT_H_
8
9 #include "staticcontract.h"
10 #include "cfi.h"
11
12 //
13 // This file is the result of some changes to the SDK header files.
14 // In particular, nt.h and some of its dependencies are no longer
15 // available except as "nonship" files.  As a result, this file
16 // was created as a simple cut and past of structures and functions
17 // from NT that are either not yet documented or have been overlooked
18 // as being part of the platform SDK.
19 //
20
21 //
22 // ALL PLATFORMS
23 //
24
25 #define STATUS_INVALID_PARAMETER_3       ((NTSTATUS)0xC00000F1L)
26 #define STATUS_INVALID_PARAMETER_4       ((NTSTATUS)0xC00000F2L)
27 #define STATUS_UNSUCCESSFUL              ((NTSTATUS)0xC0000001L)
28 #define STATUS_SUCCESS                   ((NTSTATUS)0x00000000L)
29
30 #ifndef STATUS_UNWIND
31 #define STATUS_UNWIND                    ((NTSTATUS)0x80000027L)
32 #endif
33
34 #ifndef DBG_PRINTEXCEPTION_C 
35 #define DBG_PRINTEXCEPTION_C             ((DWORD)0x40010006L)
36 #endif
37
38 #ifndef STATUS_UNWIND_CONSOLIDATE
39 #define STATUS_UNWIND_CONSOLIDATE        ((NTSTATUS)0x80000029L)
40 #endif
41
42 #ifndef STATUS_LONGJUMP
43 #define STATUS_LONGJUMP        ((NTSTATUS)0x80000026L)
44 #endif
45
46 #ifndef LOCALE_NAME_MAX_LENGTH
47 #define LOCALE_NAME_MAX_LENGTH 85
48 #endif // !LOCALE_NAME_MAX_LENGTH
49
50 #ifndef SUBLANG_CUSTOM_DEFAULT
51 #define SUBLANG_CUSTOM_DEFAULT                      0x03    // default custom language/locale
52 #define SUBLANG_CUSTOM_UNSPECIFIED                  0x04    // custom language/locale
53 #define LOCALE_CUSTOM_DEFAULT                                                 \
54               (MAKELCID(MAKELANGID(LANG_NEUTRAL, SUBLANG_CUSTOM_DEFAULT), SORT_DEFAULT))
55 #define LOCALE_CUSTOM_UNSPECIFIED                                             \
56               (MAKELCID(MAKELANGID(LANG_NEUTRAL, SUBLANG_CUSTOM_UNSPECIFIED), SORT_DEFAULT))
57 #endif // !SUBLANG_CUSTOM_DEFAULT
58
59 #ifndef __out_xcount_opt
60 #define __out_xcount_opt(var) __out
61 #endif 
62
63 #ifndef __encoded_pointer
64 #define __encoded_pointer
65 #endif 
66
67 #ifndef __range
68 #define __range(min, man)
69 #endif 
70
71 #ifndef __field_bcount
72 #define __field_bcount(size)
73 #endif
74
75 #ifndef __field_ecount_opt
76 #define __field_ecount_opt(nFields) 
77 #endif
78
79 #ifndef __field_ecount
80 #define __field_ecount(EHCount)
81 #endif
82
83 #undef _Ret_bytecap_
84 #define _Ret_bytecap_(_Size) 
85
86 #ifndef NT_SUCCESS
87 #define NT_SUCCESS(Status) (((NTSTATUS)(Status)) >= 0)
88 #endif
89
90 #define ARGUMENT_PRESENT(ArgumentPointer)    (\
91     (CHAR *)(ArgumentPointer) != (CHAR *)(NULL) )
92
93 #define EXCEPTION_CHAIN_END ((PEXCEPTION_REGISTRATION_RECORD)-1)
94
95 typedef signed char SCHAR;
96 typedef SCHAR *PSCHAR;
97 typedef LONG NTSTATUS;
98
99 #ifndef FEATURE_PAL
100
101 #define TLS_MINIMUM_AVAILABLE 64    // winnt
102 #define TLS_EXPANSION_SLOTS   1024
103
104 typedef enum _THREADINFOCLASS {
105     ThreadBasicInformation,
106     ThreadTimes,
107     ThreadPriority,
108     ThreadBasePriority,
109     ThreadAffinityMask,
110     ThreadImpersonationToken,
111     ThreadDescriptorTableEntry,
112     ThreadEnableAlignmentFaultFixup,
113     ThreadEventPair_Reusable,
114     ThreadQuerySetWin32StartAddress,
115     ThreadZeroTlsCell,
116     ThreadPerformanceCount,
117     ThreadAmILastThread,
118     ThreadIdealProcessor,
119     ThreadPriorityBoost,
120     ThreadSetTlsArrayAddress,
121     ThreadIsIoPending,
122     ThreadHideFromDebugger,
123     ThreadBreakOnTermination,
124     MaxThreadInfoClass
125     } THREADINFOCLASS;
126
127 typedef enum _SYSTEM_INFORMATION_CLASS {
128     SystemBasicInformation,
129     SystemProcessorInformation,             // obsolete...delete
130     SystemPerformanceInformation,
131     SystemTimeOfDayInformation,
132     SystemPathInformation,
133     SystemProcessInformation,
134     SystemCallCountInformation,
135     SystemDeviceInformation,
136     SystemProcessorPerformanceInformation,
137     SystemFlagsInformation,
138     SystemCallTimeInformation,
139     SystemModuleInformation,
140     SystemLocksInformation,
141     SystemStackTraceInformation,
142     SystemPagedPoolInformation,
143     SystemNonPagedPoolInformation,
144     SystemHandleInformation,
145     SystemObjectInformation,
146     SystemPageFileInformation,
147     SystemVdmInstemulInformation,
148     SystemVdmBopInformation,
149     SystemFileCacheInformation,
150     SystemPoolTagInformation,
151     SystemInterruptInformation,
152     SystemDpcBehaviorInformation,
153     SystemFullMemoryInformation,
154     SystemLoadGdiDriverInformation,
155     SystemUnloadGdiDriverInformation,
156     SystemTimeAdjustmentInformation,
157     SystemSummaryMemoryInformation,
158     SystemMirrorMemoryInformation,
159     SystemPerformanceTraceInformation,
160     SystemObsolete0,
161     SystemExceptionInformation,
162     SystemCrashDumpStateInformation,
163     SystemKernelDebuggerInformation,
164     SystemContextSwitchInformation,
165     SystemRegistryQuotaInformation,
166     SystemExtendServiceTableInformation,
167     SystemPrioritySeperation,
168     SystemVerifierAddDriverInformation,
169     SystemVerifierRemoveDriverInformation,
170     SystemProcessorIdleInformation,
171     SystemLegacyDriverInformation,
172     SystemCurrentTimeZoneInformation,
173     SystemLookasideInformation,
174     SystemTimeSlipNotification,
175     SystemSessionCreate,
176     SystemSessionDetach,
177     SystemSessionInformation,
178     SystemRangeStartInformation,
179     SystemVerifierInformation,
180     SystemVerifierThunkExtend,
181     SystemSessionProcessInformation,
182     SystemLoadGdiDriverInSystemSpace,
183     SystemNumaProcessorMap,
184     SystemPrefetcherInformation,
185     SystemExtendedProcessInformation,
186     SystemRecommendedSharedDataAlignment,
187     SystemComPlusPackage,
188     SystemNumaAvailableMemory,
189     SystemProcessorPowerInformation,
190     SystemEmulationBasicInformation,
191     SystemEmulationProcessorInformation,
192     SystemExtendedHandleInformation,
193     SystemLostDelayedWriteInformation
194 } SYSTEM_INFORMATION_CLASS;
195
196 typedef enum _EVENT_INFORMATION_CLASS {
197     EventBasicInformation
198     } EVENT_INFORMATION_CLASS;
199
200 typedef struct _SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION {
201     LARGE_INTEGER IdleTime;
202     LARGE_INTEGER KernelTime;
203     LARGE_INTEGER UserTime;
204     LARGE_INTEGER DpcTime;          // DEVL only
205     LARGE_INTEGER InterruptTime;    // DEVL only
206     ULONG InterruptCount;
207 } SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION, *PSYSTEM_PROCESSOR_PERFORMANCE_INFORMATION;
208
209 typedef enum _EVENT_TYPE {
210     NotificationEvent,
211     SynchronizationEvent
212     } EVENT_TYPE;
213
214 typedef struct _EVENT_BASIC_INFORMATION {
215     EVENT_TYPE EventType;
216     LONG EventState;
217 } EVENT_BASIC_INFORMATION, *PEVENT_BASIC_INFORMATION;
218
219 #define RTL_MEG                   (1024UL * 1024UL)
220 #define RTLP_IMAGE_MAX_DOS_HEADER ( 256UL * RTL_MEG)
221
222 typedef struct _SYSTEM_KERNEL_DEBUGGER_INFORMATION {
223     BOOLEAN KernelDebuggerEnabled;
224     BOOLEAN KernelDebuggerNotPresent;
225 } SYSTEM_KERNEL_DEBUGGER_INFORMATION, *PSYSTEM_KERNEL_DEBUGGER_INFORMATION;
226
227 typedef struct _STRING {
228     USHORT Length;
229     USHORT MaximumLength;
230 #ifdef MIDL_PASS
231     [size_is(MaximumLength), length_is(Length) ]
232 #endif // MIDL_PASS
233     PCHAR Buffer;
234 } STRING;
235 typedef STRING *PSTRING;
236
237 typedef STRING ANSI_STRING;
238 typedef PSTRING PANSI_STRING;
239
240 typedef STRING OEM_STRING;
241 typedef PSTRING POEM_STRING;
242 typedef CONST STRING* PCOEM_STRING;
243
244 typedef struct _UNICODE_STRING {
245     USHORT Length;
246     USHORT MaximumLength;
247 #ifdef MIDL_PASS
248     [size_is(MaximumLength / 2), length_is((Length) / 2) ] USHORT * Buffer;
249 #else // MIDL_PASS
250     PWSTR  Buffer;
251 #endif // MIDL_PASS
252 } UNICODE_STRING;
253 typedef UNICODE_STRING *PUNICODE_STRING;
254 typedef const UNICODE_STRING *PCUNICODE_STRING;
255 #define UNICODE_NULL ((WCHAR)0) // winnt
256
257 typedef struct _STRING32 {
258     USHORT   Length;
259     USHORT   MaximumLength;
260     ULONG  Buffer;
261 } STRING32;
262 typedef STRING32 *PSTRING32;
263
264 typedef STRING32 UNICODE_STRING32;
265 typedef UNICODE_STRING32 *PUNICODE_STRING32;
266
267 typedef STRING32 ANSI_STRING32;
268 typedef ANSI_STRING32 *PANSI_STRING32;
269
270
271 typedef struct _STRING64 {
272     USHORT   Length;
273     USHORT   MaximumLength;
274     ULONGLONG  Buffer;
275 } STRING64;
276 typedef STRING64 *PSTRING64;
277
278 typedef STRING64 UNICODE_STRING64;
279 typedef UNICODE_STRING64 *PUNICODE_STRING64;
280
281 typedef STRING64 ANSI_STRING64;
282 typedef ANSI_STRING64 *PANSI_STRING64;
283
284 #define GDI_HANDLE_BUFFER_SIZE32  34
285 #define GDI_HANDLE_BUFFER_SIZE64  60
286
287 #if !defined(_TARGET_AMD64_)
288 #define GDI_HANDLE_BUFFER_SIZE      GDI_HANDLE_BUFFER_SIZE32
289 #else
290 #define GDI_HANDLE_BUFFER_SIZE      GDI_HANDLE_BUFFER_SIZE64
291 #endif
292
293 typedef ULONG GDI_HANDLE_BUFFER32[GDI_HANDLE_BUFFER_SIZE32];
294 typedef ULONG GDI_HANDLE_BUFFER64[GDI_HANDLE_BUFFER_SIZE64];
295 typedef ULONG GDI_HANDLE_BUFFER  [GDI_HANDLE_BUFFER_SIZE  ];
296
297
298 typedef struct _PEB_LDR_DATA {
299     ULONG Length;
300     BOOLEAN Initialized;
301     HANDLE SsHandle;
302     LIST_ENTRY InLoadOrderModuleList;
303     LIST_ENTRY InMemoryOrderModuleList;
304     LIST_ENTRY InInitializationOrderModuleList;
305     PVOID EntryInProgress;
306 } PEB_LDR_DATA, *PPEB_LDR_DATA;
307
308 typedef struct _PEB_FREE_BLOCK {
309     struct _PEB_FREE_BLOCK *Next;
310     ULONG Size;
311 } PEB_FREE_BLOCK, *PPEB_FREE_BLOCK;
312
313 typedef PVOID* PPVOID;
314
315 typedef
316 VOID
317 (*PPS_POST_PROCESS_INIT_ROUTINE) (
318     VOID
319     );
320
321 typedef struct _LDR_DATA_TABLE_ENTRY {
322     LIST_ENTRY InLoadOrderLinks;
323     LIST_ENTRY InMemoryOrderLinks;
324     LIST_ENTRY InInitializationOrderLinks;
325     PVOID DllBase;
326     PVOID EntryPoint;
327     ULONG SizeOfImage;
328     UNICODE_STRING FullDllName;
329     UNICODE_STRING BaseDllName;
330     ULONG Flags;
331     USHORT LoadCount;
332     USHORT TlsIndex;
333     union _foo {
334         LIST_ENTRY HashLinks;
335         struct _bar {
336             PVOID SectionPointer;
337             ULONG CheckSum;
338         };
339     };
340     union _foo2 {
341         struct _bar2 {
342             ULONG TimeDateStamp;
343         };
344         struct _bar3 {
345             PVOID LoadedImports;
346         };
347     };
348     PVOID EntryPointActivationContext;
349 } LDR_DATA_TABLE_ENTRY, *PLDR_DATA_TABLE_ENTRY;
350
351 #define TYPE3(arg) arg
352
353 typedef struct _PEB {
354     BOOLEAN InheritedAddressSpace;      // These four fields cannot change unless the
355     BOOLEAN ReadImageFileExecOptions;   //
356     BOOLEAN BeingDebugged;              //
357     BOOLEAN SpareBool;                  //
358     HANDLE Mutant;                      // INITIAL_PEB structure is also updated.
359
360     PVOID ImageBaseAddress;
361     PPEB_LDR_DATA Ldr;
362     TYPE3(struct _RTL_USER_PROCESS_PARAMETERS*) ProcessParameters;
363     PVOID SubSystemData;
364     PVOID ProcessHeap;
365     TYPE3(struct _RTL_CRITICAL_SECTION*) FastPebLock;
366     PVOID FastPebLockRoutine;
367     PVOID FastPebUnlockRoutine;
368     ULONG EnvironmentUpdateCount;
369     PVOID KernelCallbackTable;
370     ULONG SystemReserved[1];
371
372     struct _foo {
373         ULONG ExecuteOptions : 2;
374         ULONG SpareBits : 30;
375     };
376
377
378     PPEB_FREE_BLOCK FreeList;
379     ULONG TlsExpansionCounter;
380     PVOID TlsBitmap;
381     ULONG TlsBitmapBits[2];         // TLS_MINIMUM_AVAILABLE bits
382     PVOID ReadOnlySharedMemoryBase;
383     PVOID ReadOnlySharedMemoryHeap;
384     PPVOID ReadOnlyStaticServerData;
385     PVOID AnsiCodePageData;
386     PVOID OemCodePageData;
387     PVOID UnicodeCaseTableData;
388
389     //
390     // Useful information for LdrpInitialize
391     ULONG NumberOfProcessors;
392     ULONG NtGlobalFlag;
393
394     //
395     // Passed up from MmCreatePeb from Session Manager registry key
396     //
397
398     LARGE_INTEGER CriticalSectionTimeout;
399     SIZE_T HeapSegmentReserve;
400     SIZE_T HeapSegmentCommit;
401     SIZE_T HeapDeCommitTotalFreeThreshold;
402     SIZE_T HeapDeCommitFreeBlockThreshold;
403
404     //
405     // Where heap manager keeps track of all heaps created for a process
406     // Fields initialized by MmCreatePeb.  ProcessHeaps is initialized
407     // to point to the first free byte after the PEB and MaximumNumberOfHeaps
408     // is computed from the page size used to hold the PEB, less the fixed
409     // size of this data structure.
410     //
411
412     ULONG NumberOfHeaps;
413     ULONG MaximumNumberOfHeaps;
414     PPVOID ProcessHeaps;
415
416     //
417     //
418     PVOID GdiSharedHandleTable;
419     PVOID ProcessStarterHelper;
420     ULONG GdiDCAttributeList;
421     PVOID LoaderLock;
422
423     //
424     // Following fields filled in by MmCreatePeb from system values and/or
425     // image header.
426     //
427
428     ULONG OSMajorVersion;
429     ULONG OSMinorVersion;
430     USHORT OSBuildNumber;
431     USHORT OSCSDVersion;
432     ULONG OSPlatformId;
433     ULONG ImageSubsystem;
434     ULONG ImageSubsystemMajorVersion;
435     ULONG ImageSubsystemMinorVersion;
436     ULONG_PTR ImageProcessAffinityMask;
437     GDI_HANDLE_BUFFER GdiHandleBuffer;
438     PPS_POST_PROCESS_INIT_ROUTINE PostProcessInitRoutine;
439
440     PVOID TlsExpansionBitmap;
441     ULONG TlsExpansionBitmapBits[32];   // TLS_EXPANSION_SLOTS bits
442
443     //
444     // Id of the Hydra session in which this process is running
445     //
446     ULONG SessionId;
447
448     //
449     // Filled in by LdrpInstallAppcompatBackend
450     //
451     ULARGE_INTEGER AppCompatFlags;
452
453     //
454     // ntuser appcompat flags
455     //
456     ULARGE_INTEGER AppCompatFlagsUser;
457
458     //
459     // Filled in by LdrpInstallAppcompatBackend
460     //
461     PVOID pShimData;
462
463     //
464     // Filled in by LdrQueryImageFileExecutionOptions
465     //
466     PVOID AppCompatInfo;
467
468     //
469     // Used by GetVersionExW as the szCSDVersion string
470     //
471     UNICODE_STRING CSDVersion;
472
473     //
474     // Fusion stuff
475     //
476     PVOID ActivationContextData;
477     PVOID ProcessAssemblyStorageMap;
478     PVOID SystemDefaultActivationContextData;
479     PVOID SystemAssemblyStorageMap;
480
481     //
482     // Enforced minimum initial commit stack
483     //
484     SIZE_T MinimumStackCommit;
485
486 } PEB, *PPEB;
487
488 #define ACTIVATION_CONTEXT_STACK_FLAG_QUERIES_DISABLED (0x00000001)
489
490 typedef struct _ACTIVATION_CONTEXT_STACK {
491     ULONG Flags;
492     ULONG NextCookieSequenceNumber;
493     PVOID ActiveFrame;
494     LIST_ENTRY FrameListCache;
495
496 #if NT_SXS_PERF_COUNTERS_ENABLED
497     struct _ACTIVATION_CONTEXT_STACK_PERF_COUNTERS {
498         ULONGLONG Activations;
499         ULONGLONG ActivationCycles;
500         ULONGLONG Deactivations;
501         ULONGLONG DeactivationCycles;
502     } Counters;
503 #endif // NT_SXS_PERF_COUNTERS_ENABLED
504 } ACTIVATION_CONTEXT_STACK, *PACTIVATION_CONTEXT_STACK;
505
506 typedef const ACTIVATION_CONTEXT_STACK *PCACTIVATION_CONTEXT_STACK;
507
508 #define TEB_ACTIVE_FRAME_CONTEXT_FLAG_EXTENDED (0x00000001)
509
510 typedef struct _TEB_ACTIVE_FRAME_CONTEXT {
511     ULONG Flags;
512     PCSTR FrameName;
513 } TEB_ACTIVE_FRAME_CONTEXT, *PTEB_ACTIVE_FRAME_CONTEXT;
514
515 typedef const struct _TEB_ACTIVE_FRAME_CONTEXT *PCTEB_ACTIVE_FRAME_CONTEXT;
516
517 typedef struct _TEB_ACTIVE_FRAME_CONTEXT_EX {
518     TEB_ACTIVE_FRAME_CONTEXT BasicContext;
519     PCSTR SourceLocation; // e.g. "Z:\foo\bar\baz.c"
520 } TEB_ACTIVE_FRAME_CONTEXT_EX, *PTEB_ACTIVE_FRAME_CONTEXT_EX;
521
522 typedef const struct _TEB_ACTIVE_FRAME_CONTEXT_EX *PCTEB_ACTIVE_FRAME_CONTEXT_EX;
523
524 #define TEB_ACTIVE_FRAME_FLAG_EXTENDED (0x00000001)
525
526 typedef struct _TEB_ACTIVE_FRAME {
527     ULONG Flags;
528     TYPE3(struct _TEB_ACTIVE_FRAME*) Previous;
529     PCTEB_ACTIVE_FRAME_CONTEXT Context;
530 } TEB_ACTIVE_FRAME, *PTEB_ACTIVE_FRAME;
531
532 typedef const struct _TEB_ACTIVE_FRAME *PCTEB_ACTIVE_FRAME;
533
534 typedef struct _TEB_ACTIVE_FRAME_EX {
535     TEB_ACTIVE_FRAME BasicFrame;
536     PVOID ExtensionIdentifier; // use address of your DLL Main or something unique to your mapping in the address space
537 } TEB_ACTIVE_FRAME_EX, *PTEB_ACTIVE_FRAME_EX;
538
539 typedef const struct _TEB_ACTIVE_FRAME_EX *PCTEB_ACTIVE_FRAME_EX;
540
541 typedef struct _CLIENT_ID {
542     HANDLE UniqueProcess;
543     HANDLE UniqueThread;
544 } CLIENT_ID;
545 typedef CLIENT_ID *PCLIENT_ID;
546
547 #define GDI_BATCH_BUFFER_SIZE 310
548
549 typedef struct _GDI_TEB_BATCH {
550     ULONG    Offset;
551     ULONG_PTR HDC;
552     ULONG    Buffer[GDI_BATCH_BUFFER_SIZE];
553 } GDI_TEB_BATCH,*PGDI_TEB_BATCH;
554
555 typedef struct _Wx86ThreadState {
556     PULONG  CallBx86Eip;
557     PVOID   DeallocationCpu;
558     BOOLEAN UseKnownWx86Dll;
559     char    OleStubInvoked;
560 } WX86THREAD, *PWX86THREAD;
561
562 #define STATIC_UNICODE_BUFFER_LENGTH 261
563 #define WIN32_CLIENT_INFO_LENGTH 62
564
565 typedef struct _PEB* PPEB;
566
567 typedef struct _TEB {
568     NT_TIB NtTib;
569     PVOID  EnvironmentPointer;
570     CLIENT_ID ClientId;
571     PVOID ActiveRpcHandle;
572     PVOID ThreadLocalStoragePointer;
573 #if defined(PEBTEB_BITS)
574     PVOID ProcessEnvironmentBlock;
575 #else
576     PPEB ProcessEnvironmentBlock;
577 #endif
578     ULONG LastErrorValue;
579     ULONG CountOfOwnedCriticalSections;
580     PVOID CsrClientThread;
581     PVOID Win32ThreadInfo;          // PtiCurrent
582     ULONG User32Reserved[26];       // user32.dll items
583     ULONG UserReserved[5];          // Winsrv SwitchStack
584     PVOID WOW32Reserved;            // used by WOW
585     LCID CurrentLocale;
586     ULONG FpSoftwareStatusRegister; // offset known by outsiders!
587     PVOID SystemReserved1[54];      // Used by FP emulator
588     NTSTATUS ExceptionCode;         // for RaiseUserException
589     ACTIVATION_CONTEXT_STACK ActivationContextStack;   // Fusion activation stack
590     // sizeof(PVOID) is a way to express processor-dependence, more generally than #ifdef _WIN64
591     UCHAR SpareBytes1[48 - sizeof(PVOID) - sizeof(ACTIVATION_CONTEXT_STACK)];
592     GDI_TEB_BATCH GdiTebBatch;      // Gdi batching
593     CLIENT_ID RealClientId;
594     HANDLE GdiCachedProcessHandle;
595     ULONG GdiClientPID;
596     ULONG GdiClientTID;
597     PVOID GdiThreadLocalInfo;
598     ULONG_PTR Win32ClientInfo[WIN32_CLIENT_INFO_LENGTH]; // User32 Client Info
599     PVOID glDispatchTable[233];     // OpenGL
600     ULONG_PTR glReserved1[29];      // OpenGL
601     PVOID glReserved2;              // OpenGL
602     PVOID glSectionInfo;            // OpenGL
603     PVOID glSection;                // OpenGL
604     PVOID glTable;                  // OpenGL
605     PVOID glCurrentRC;              // OpenGL
606     PVOID glContext;                // OpenGL
607     ULONG LastStatusValue;
608     UNICODE_STRING StaticUnicodeString;
609     WCHAR StaticUnicodeBuffer[STATIC_UNICODE_BUFFER_LENGTH];
610     PVOID DeallocationStack;
611     PVOID TlsSlots[TLS_MINIMUM_AVAILABLE];
612     LIST_ENTRY TlsLinks;
613     PVOID Vdm;
614     PVOID ReservedForNtRpc;
615     PVOID DbgSsReserved[2];
616     ULONG HardErrorsAreDisabled;
617     PVOID Instrumentation[16];
618     PVOID WinSockData;              // WinSock
619     ULONG GdiBatchCount;
620     BOOLEAN InDbgPrint;
621     BOOLEAN FreeStackOnTermination;
622     BOOLEAN HasFiberData;
623     BOOLEAN IdealProcessor;
624     ULONG Spare3;
625     PVOID ReservedForPerf;
626     PVOID ReservedForOle;
627     ULONG WaitingOnLoaderLock;
628     WX86THREAD Wx86Thread;
629     PPVOID TlsExpansionSlots;
630     LCID ImpersonationLocale;       // Current locale of impersonated user
631     ULONG IsImpersonating;          // Thread impersonation status
632     PVOID NlsCache;                 // NLS thread cache
633     PVOID pShimData;                // Per thread data used in the shim
634     ULONG HeapVirtualAffinity;
635     HANDLE CurrentTransactionHandle;// reserved for TxF transaction context
636     PTEB_ACTIVE_FRAME ActiveFrame;
637 } TEB;
638 typedef TEB *PTEB;
639
640 typedef struct _CURDIR {
641     UNICODE_STRING DosPath;
642     HANDLE Handle;
643 } CURDIR, *PCURDIR;
644
645 #define RTL_USER_PROC_CURDIR_CLOSE      0x00000002
646 #define RTL_USER_PROC_CURDIR_INHERIT    0x00000003
647
648 typedef struct _RTL_DRIVE_LETTER_CURDIR {
649     USHORT Flags;
650     USHORT Length;
651     ULONG TimeStamp;
652     STRING DosPath;
653 } RTL_DRIVE_LETTER_CURDIR, *PRTL_DRIVE_LETTER_CURDIR;
654
655
656 #define RTL_MAX_DRIVE_LETTERS 32
657 #define RTL_DRIVE_LETTER_VALID (USHORT)0x0001
658
659 typedef struct _RTL_USER_PROCESS_PARAMETERS {
660     ULONG MaximumLength;
661     ULONG Length;
662
663     ULONG Flags;
664     ULONG DebugFlags;
665
666     HANDLE ConsoleHandle;
667     ULONG  ConsoleFlags;
668     HANDLE StandardInput;
669     HANDLE StandardOutput;
670     HANDLE StandardError;
671
672     CURDIR CurrentDirectory;        // ProcessParameters
673     UNICODE_STRING DllPath;         // ProcessParameters
674     UNICODE_STRING ImagePathName;   // ProcessParameters
675     UNICODE_STRING CommandLine;     // ProcessParameters
676     PVOID Environment;              // NtAllocateVirtualMemory
677
678     ULONG StartingX;
679     ULONG StartingY;
680     ULONG CountX;
681     ULONG CountY;
682     ULONG CountCharsX;
683     ULONG CountCharsY;
684     ULONG FillAttribute;
685
686     ULONG WindowFlags;
687     ULONG ShowWindowFlags;
688     UNICODE_STRING WindowTitle;     // ProcessParameters
689     UNICODE_STRING DesktopInfo;     // ProcessParameters
690     UNICODE_STRING ShellInfo;       // ProcessParameters
691     UNICODE_STRING RuntimeData;     // ProcessParameters
692     RTL_DRIVE_LETTER_CURDIR CurrentDirectores[ RTL_MAX_DRIVE_LETTERS ];
693 } RTL_USER_PROCESS_PARAMETERS, *PRTL_USER_PROCESS_PARAMETERS;
694
695
696 typedef enum _PROCESSINFOCLASS {
697     ProcessBasicInformation,
698     ProcessQuotaLimits,
699     ProcessIoCounters,
700     ProcessVmCounters,
701     ProcessTimes,
702     ProcessBasePriority,
703     ProcessRaisePriority,
704     ProcessDebugPort,
705     ProcessExceptionPort,
706     ProcessAccessToken,
707     ProcessLdtInformation,
708     ProcessLdtSize,
709     ProcessDefaultHardErrorMode,
710     ProcessIoPortHandlers,          // Note: this is kernel mode only
711     ProcessPooledUsageAndLimits,
712     ProcessWorkingSetWatch,
713     ProcessUserModeIOPL,
714     ProcessEnableAlignmentFaultFixup,
715     ProcessPriorityClass,
716     ProcessWx86Information,
717     ProcessHandleCount,
718     ProcessAffinityMask,
719     ProcessPriorityBoost,
720     ProcessDeviceMap,
721     ProcessSessionInformation,
722     ProcessForegroundInformation,
723     ProcessWow64Information,
724     ProcessImageFileName,
725     ProcessLUIDDeviceMapsEnabled,
726     ProcessBreakOnTermination,
727     ProcessDebugObjectHandle,
728     ProcessDebugFlags,
729     ProcessHandleTracing,
730     MaxProcessInfoClass             // MaxProcessInfoClass should always be the last enum
731     } PROCESSINFOCLASS;
732
733
734 typedef struct _VM_COUNTERS {
735     SIZE_T PeakVirtualSize;
736     SIZE_T VirtualSize;
737     ULONG PageFaultCount;
738     SIZE_T PeakWorkingSetSize;
739     SIZE_T WorkingSetSize;
740     SIZE_T QuotaPeakPagedPoolUsage;
741     SIZE_T QuotaPagedPoolUsage;
742     SIZE_T QuotaPeakNonPagedPoolUsage;
743     SIZE_T QuotaNonPagedPoolUsage;
744     SIZE_T PagefileUsage;
745     SIZE_T PeakPagefileUsage;
746 } VM_COUNTERS;
747 typedef VM_COUNTERS *PVM_COUNTERS;
748
749 #undef TYPE3
750
751 #endif // !defined(FEATURE_PAL)
752
753 #if !defined(_TARGET_X86_)
754
755 typedef enum _FUNCTION_TABLE_TYPE {
756     RF_SORTED,
757     RF_UNSORTED,
758     RF_CALLBACK
759 } FUNCTION_TABLE_TYPE;
760
761 typedef struct _DYNAMIC_FUNCTION_TABLE {
762     LIST_ENTRY Links;
763     PT_RUNTIME_FUNCTION FunctionTable;
764     LARGE_INTEGER TimeStamp;
765     
766 #ifdef _TARGET_ARM_
767     ULONG MinimumAddress;
768     ULONG MaximumAddress;
769     ULONG BaseAddress;
770 #else
771     ULONG64 MinimumAddress;
772     ULONG64 MaximumAddress;
773     ULONG64 BaseAddress;
774 #endif
775
776     PGET_RUNTIME_FUNCTION_CALLBACK Callback;
777     PVOID Context;
778     PWSTR OutOfProcessCallbackDll;
779     FUNCTION_TABLE_TYPE Type;
780     ULONG EntryCount;
781 } DYNAMIC_FUNCTION_TABLE, *PDYNAMIC_FUNCTION_TABLE;
782
783 #endif // !_TARGET_X86_
784
785 //
786 //   AMD64
787 //
788 #ifdef _TARGET_AMD64_
789
790 #define RUNTIME_FUNCTION__BeginAddress(prf)             (prf)->BeginAddress
791 #define RUNTIME_FUNCTION__SetBeginAddress(prf,address)  ((prf)->BeginAddress = (address))
792
793 #define RUNTIME_FUNCTION__EndAddress(prf, ImageBase)    (prf)->EndAddress
794
795 #define RUNTIME_FUNCTION__GetUnwindInfoAddress(prf) (prf)->UnwindData
796 #define RUNTIME_FUNCTION__SetUnwindInfoAddress(prf,address) do { (prf)->UnwindData = (address); } while (0)
797 #define OFFSETOF__RUNTIME_FUNCTION__UnwindInfoAddress offsetof(T_RUNTIME_FUNCTION, UnwindData)
798
799 #include "win64unwind.h"
800
801 typedef
802 PEXCEPTION_ROUTINE
803 (RtlVirtualUnwindFn) (
804     IN ULONG HandlerType,
805     IN ULONG64 ImageBase,
806     IN ULONG64 ControlPc,
807     IN PT_RUNTIME_FUNCTION FunctionEntry,
808     IN OUT PCONTEXT ContextRecord,
809     OUT PVOID *HandlerData,
810     OUT PULONG64 EstablisherFrame,
811     IN OUT PKNONVOLATILE_CONTEXT_POINTERS ContextPointers OPTIONAL
812     );
813
814 #ifndef FEATURE_PAL
815 extern RtlVirtualUnwindFn* RtlVirtualUnwind_Unsafe;
816 #else // !FEATURE_PAL
817 PEXCEPTION_ROUTINE
818 RtlVirtualUnwind_Unsafe(
819     IN ULONG HandlerType,
820     IN ULONG64 ImageBase,
821     IN ULONG64 ControlPc,
822     IN PT_RUNTIME_FUNCTION FunctionEntry,
823     IN OUT PCONTEXT ContextRecord,
824     OUT PVOID *HandlerData,
825     OUT PULONG64 EstablisherFrame,
826     IN OUT PKNONVOLATILE_CONTEXT_POINTERS ContextPointers OPTIONAL
827     );
828 #endif // !FEATURE_PAL
829
830 #endif // _TARGET_AMD64_
831
832 //
833 //  X86
834 //
835
836 #ifdef _TARGET_X86_
837 #ifndef FEATURE_PAL
838 //
839 // x86 ABI does not define RUNTIME_FUNCTION. Define our own to allow unification between x86 and other platforms.
840 //
841 typedef struct _RUNTIME_FUNCTION {
842     DWORD BeginAddress;
843     DWORD UnwindData;
844 } RUNTIME_FUNCTION, *PRUNTIME_FUNCTION;
845
846 typedef struct _DISPATCHER_CONTEXT {
847     _EXCEPTION_REGISTRATION_RECORD* RegistrationPointer;
848 } DISPATCHER_CONTEXT, *PDISPATCHER_CONTEXT;
849
850 #endif // !FEATURE_PAL
851
852 #define RUNTIME_FUNCTION__BeginAddress(prf)             (prf)->BeginAddress
853 #define RUNTIME_FUNCTION__SetBeginAddress(prf,addr)     ((prf)->BeginAddress = (addr))
854
855 #ifdef WIN64EXCEPTIONS
856 #include "win64unwind.h"
857
858 FORCEINLINE
859 DWORD
860 RtlpGetFunctionEndAddress (
861     __in PT_RUNTIME_FUNCTION FunctionEntry,
862     __in TADDR ImageBase
863     )
864 {
865     PTR_UNWIND_INFO pUnwindInfo = (PTR_UNWIND_INFO)(ImageBase + FunctionEntry->UnwindData);
866
867     return FunctionEntry->BeginAddress + pUnwindInfo->FunctionLength;
868 }
869
870 #define RUNTIME_FUNCTION__EndAddress(prf, ImageBase)   RtlpGetFunctionEndAddress(prf, ImageBase)
871
872 #define RUNTIME_FUNCTION__GetUnwindInfoAddress(prf)    (prf)->UnwindData
873 #define RUNTIME_FUNCTION__SetUnwindInfoAddress(prf, addr) do { (prf)->UnwindData = (addr); } while(0)
874
875 EXTERN_C
876 NTSYSAPI
877 PEXCEPTION_ROUTINE
878 NTAPI
879 RtlVirtualUnwind (
880     __in DWORD HandlerType,
881     __in DWORD ImageBase,
882     __in DWORD ControlPc,
883     __in PRUNTIME_FUNCTION FunctionEntry,
884     __inout PT_CONTEXT ContextRecord,
885     __out PVOID *HandlerData,
886     __out PDWORD EstablisherFrame,
887     __inout_opt PT_KNONVOLATILE_CONTEXT_POINTERS ContextPointers
888     );
889 #endif // WIN64EXCEPTIONS
890
891 #endif // _TARGET_X86_
892
893 #ifdef _TARGET_ARM_
894 #include "daccess.h"
895
896 //
897 // Define unwind information flags.
898 //
899
900 #define UNW_FLAG_NHANDLER               0x0             /* any handler */
901 #define UNW_FLAG_EHANDLER               0x1             /* filter handler */
902 #define UNW_FLAG_UHANDLER               0x2             /* unwind handler */
903                                                             
904 // This function returns the length of a function using the new unwind info on arm.
905 // Taken from minkernel\ntos\rtl\arm\ntrtlarm.h.
906 FORCEINLINE
907 ULONG
908 RtlpGetFunctionEndAddress (
909     __in PT_RUNTIME_FUNCTION FunctionEntry,
910     __in TADDR ImageBase
911     )
912 {
913     ULONG FunctionLength;
914     
915     FunctionLength = FunctionEntry->UnwindData;
916     if ((FunctionLength & 3) != 0) {
917         FunctionLength = (FunctionLength >> 2) & 0x7ff;
918     } else {
919         FunctionLength = *(PTR_ULONG)(ImageBase + FunctionLength) & 0x3ffff;
920     }
921     
922     return FunctionEntry->BeginAddress + 2 * FunctionLength;
923 }
924
925 #define RUNTIME_FUNCTION__BeginAddress(FunctionEntry)               ThumbCodeToDataPointer<DWORD,DWORD>((FunctionEntry)->BeginAddress)
926 #define RUNTIME_FUNCTION__SetBeginAddress(FunctionEntry,address)    ((FunctionEntry)->BeginAddress = DataPointerToThumbCode<DWORD,DWORD>(address))
927
928 #define RUNTIME_FUNCTION__EndAddress(FunctionEntry, ImageBase)      ThumbCodeToDataPointer<DWORD,DWORD>(RtlpGetFunctionEndAddress(FunctionEntry, ImageBase))
929
930 #define RUNTIME_FUNCTION__SetUnwindInfoAddress(prf,address) do { (prf)->UnwindData = (address); } while (0)
931
932 typedef struct _UNWIND_INFO {
933     // dummy
934 } UNWIND_INFO, *PUNWIND_INFO;
935
936 #if defined(FEATURE_PAL) || defined(_X86_)
937 EXTERN_C
938 NTSYSAPI
939 VOID
940 NTAPI
941 RtlUnwindEx (
942     __in_opt PVOID TargetFrame,
943     __in_opt PVOID TargetIp,
944     __in_opt PEXCEPTION_RECORD ExceptionRecord,
945     __in PVOID ReturnValue,
946     __in PT_CONTEXT ContextRecord,
947     __in_opt PUNWIND_HISTORY_TABLE HistoryTable
948     );
949
950 EXTERN_C
951 NTSYSAPI
952 PEXCEPTION_ROUTINE
953 NTAPI
954 RtlVirtualUnwind (
955     __in DWORD HandlerType,
956     __in DWORD ImageBase,
957     __in DWORD ControlPc,
958     __in PRUNTIME_FUNCTION FunctionEntry,
959     __inout PT_CONTEXT ContextRecord,
960     __out PVOID *HandlerData,
961     __out PDWORD EstablisherFrame,
962     __inout_opt PT_KNONVOLATILE_CONTEXT_POINTERS ContextPointers
963     );
964 #endif // FEATURE_PAL || _X86_
965
966 #define UNW_FLAG_NHANDLER 0x0
967
968 #endif // _TARGET_ARM_
969
970 #ifdef _TARGET_ARM64_
971 #include "daccess.h"
972
973 #define UNW_FLAG_NHANDLER               0x0             /* any handler */
974 #define UNW_FLAG_EHANDLER               0x1             /* filter handler */
975 #define UNW_FLAG_UHANDLER               0x2             /* unwind handler */
976
977 // This function returns the RVA of the end of the function (exclusive, so one byte after the actual end)
978 // using the unwind info on ARM64. (see ExternalAPIs\Win9CoreSystem\inc\winnt.h)
979 FORCEINLINE
980 ULONG64
981 RtlpGetFunctionEndAddress (
982     __in PT_RUNTIME_FUNCTION FunctionEntry,
983     __in ULONG64 ImageBase
984     )
985 {
986     ULONG64 FunctionLength;
987     
988     FunctionLength = FunctionEntry->UnwindData;
989     if ((FunctionLength & 3) != 0) {
990         FunctionLength = (FunctionLength >> 2) & 0x7ff;
991     } else {
992         FunctionLength = *(PTR_ULONG64)(ImageBase + FunctionLength) & 0x3ffff;
993     }
994     
995     return FunctionEntry->BeginAddress + 4 * FunctionLength;
996 }
997
998 #define RUNTIME_FUNCTION__BeginAddress(FunctionEntry)               ((FunctionEntry)->BeginAddress)
999 #define RUNTIME_FUNCTION__SetBeginAddress(FunctionEntry,address)    ((FunctionEntry)->BeginAddress = (address))
1000
1001 #define RUNTIME_FUNCTION__EndAddress(FunctionEntry, ImageBase)      (RtlpGetFunctionEndAddress(FunctionEntry, (ULONG64)(ImageBase)))
1002
1003 #define RUNTIME_FUNCTION__SetUnwindInfoAddress(prf,address)         do { (prf)->UnwindData = (address); } while (0)
1004
1005 typedef struct _UNWIND_INFO {
1006     // dummy
1007 } UNWIND_INFO, *PUNWIND_INFO;
1008
1009 EXTERN_C
1010 NTSYSAPI
1011 PEXCEPTION_ROUTINE
1012 NTAPI
1013 RtlVirtualUnwind(
1014     IN ULONG HandlerType,
1015     IN ULONG64 ImageBase,
1016     IN ULONG64 ControlPc,
1017     IN PRUNTIME_FUNCTION FunctionEntry,
1018     IN OUT PCONTEXT ContextRecord,
1019     OUT PVOID *HandlerData,
1020     OUT PULONG64 EstablisherFrame,
1021     IN OUT PKNONVOLATILE_CONTEXT_POINTERS ContextPointers OPTIONAL
1022     );
1023
1024 #ifndef IMAGE_FILE_MACHINE_ARM64
1025 #define IMAGE_FILE_MACHINE_ARM64             0xAA64  // ARM64 Little-Endian
1026 #endif
1027
1028 #ifndef IMAGE_REL_ARM64_BRANCH26
1029 #define IMAGE_REL_ARM64_BRANCH26        0x0003  // 26 bit offset << 2 & sign ext. for B & BL
1030 #endif
1031
1032 #ifndef IMAGE_REL_ARM64_PAGEBASE_REL21
1033 #define IMAGE_REL_ARM64_PAGEBASE_REL21  0x0004  // ADRP 21 bit PC-relative page address
1034 #endif
1035
1036 #ifndef IMAGE_REL_ARM64_PAGEOFFSET_12A
1037 #define IMAGE_REL_ARM64_PAGEOFFSET_12A  0x0006  // ADD 12 bit page offset
1038 #endif
1039
1040 #endif
1041
1042 #endif  // CLRNT_H_