xref: /reactos/sdk/include/xdk/ketypes.h (revision 835438f6)
1 /******************************************************************************
2  *                              Kernel Types                                  *
3  ******************************************************************************/
4 $if (_WDMDDK_)
5 
6 typedef UCHAR KIRQL, *PKIRQL;
7 typedef CCHAR KPROCESSOR_MODE;
8 typedef LONG KPRIORITY;
9 
10 typedef enum _MODE {
11   KernelMode,
12   UserMode,
13   MaximumMode
14 } MODE;
15 
16 #define CACHE_FULLY_ASSOCIATIVE 0xFF
17 #define MAXIMUM_SUSPEND_COUNT   MAXCHAR
18 
19 #define EVENT_QUERY_STATE (0x0001)
20 #define EVENT_MODIFY_STATE (0x0002)
21 #define EVENT_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | 0x3)
22 
23 #define LTP_PC_SMT 0x1
24 
25 #if (NTDDI_VERSION < NTDDI_WIN7) || defined(_X86_) || !defined(NT_PROCESSOR_GROUPS)
26 #define SINGLE_GROUP_LEGACY_API        1
27 #endif
28 
29 #define SEMAPHORE_QUERY_STATE (0x0001)
30 #define SEMAPHORE_MODIFY_STATE (0x0002)
31 #define SEMAPHORE_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | 0x3)
32 
33 $endif(_WDMDDK_)
34 $if(_WDMDDK_ || _WINNT_)
35 
36 typedef struct _PROCESSOR_GROUP_INFO {
37   UCHAR MaximumProcessorCount;
38   UCHAR ActiveProcessorCount;
39   UCHAR Reserved[38];
40   KAFFINITY ActiveProcessorMask;
41 } PROCESSOR_GROUP_INFO, *PPROCESSOR_GROUP_INFO;
42 
43 typedef enum _PROCESSOR_CACHE_TYPE {
44   CacheUnified,
45   CacheInstruction,
46   CacheData,
47   CacheTrace
48 } PROCESSOR_CACHE_TYPE;
49 
50 typedef struct _CACHE_DESCRIPTOR {
51   UCHAR Level;
52   UCHAR Associativity;
53   USHORT LineSize;
54   ULONG Size;
55   PROCESSOR_CACHE_TYPE Type;
56 } CACHE_DESCRIPTOR, *PCACHE_DESCRIPTOR;
57 
58 typedef struct _NUMA_NODE_RELATIONSHIP {
59   ULONG NodeNumber;
60   UCHAR Reserved[20];
61   GROUP_AFFINITY GroupMask;
62 } NUMA_NODE_RELATIONSHIP, *PNUMA_NODE_RELATIONSHIP;
63 
64 typedef struct _CACHE_RELATIONSHIP {
65   UCHAR Level;
66   UCHAR Associativity;
67   USHORT LineSize;
68   ULONG CacheSize;
69   PROCESSOR_CACHE_TYPE Type;
70   UCHAR Reserved[20];
71   GROUP_AFFINITY GroupMask;
72 } CACHE_RELATIONSHIP, *PCACHE_RELATIONSHIP;
73 
74 typedef struct _GROUP_RELATIONSHIP {
75   USHORT MaximumGroupCount;
76   USHORT ActiveGroupCount;
77   UCHAR Reserved[20];
78   PROCESSOR_GROUP_INFO GroupInfo[ANYSIZE_ARRAY];
79 } GROUP_RELATIONSHIP, *PGROUP_RELATIONSHIP;
80 
81 typedef enum _LOGICAL_PROCESSOR_RELATIONSHIP {
82   RelationProcessorCore,
83   RelationNumaNode,
84   RelationCache,
85   RelationProcessorPackage,
86   RelationGroup,
87   RelationAll = 0xffff
88 } LOGICAL_PROCESSOR_RELATIONSHIP;
89 
90 typedef struct _PROCESSOR_RELATIONSHIP {
91   UCHAR Flags;
92   UCHAR Reserved[21];
93   USHORT GroupCount;
94   _Field_size_(GroupCount) GROUP_AFFINITY GroupMask[ANYSIZE_ARRAY];
95 } PROCESSOR_RELATIONSHIP, *PPROCESSOR_RELATIONSHIP;
96 
97 typedef struct _SYSTEM_LOGICAL_PROCESSOR_INFORMATION {
98   ULONG_PTR ProcessorMask;
99   LOGICAL_PROCESSOR_RELATIONSHIP Relationship;
100   _ANONYMOUS_UNION union {
101     struct {
102       UCHAR Flags;
103     } ProcessorCore;
104     struct {
105       ULONG NodeNumber;
106     } NumaNode;
107     CACHE_DESCRIPTOR Cache;
108     ULONGLONG Reserved[2];
109   } DUMMYUNIONNAME;
110 } SYSTEM_LOGICAL_PROCESSOR_INFORMATION, *PSYSTEM_LOGICAL_PROCESSOR_INFORMATION;
111 
112 typedef struct _SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX {
113   LOGICAL_PROCESSOR_RELATIONSHIP Relationship;
114   ULONG Size;
115   _ANONYMOUS_UNION union {
116     PROCESSOR_RELATIONSHIP Processor;
117     NUMA_NODE_RELATIONSHIP NumaNode;
118     CACHE_RELATIONSHIP Cache;
119     GROUP_RELATIONSHIP Group;
120   } DUMMYUNIONNAME;
121 } SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX, *PSYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX;
122 
123 /* Processor features */
124 #define PF_FLOATING_POINT_PRECISION_ERRATA       0
125 #define PF_FLOATING_POINT_EMULATED               1
126 #define PF_COMPARE_EXCHANGE_DOUBLE               2
127 #define PF_MMX_INSTRUCTIONS_AVAILABLE            3
128 #define PF_PPC_MOVEMEM_64BIT_OK                  4
129 #define PF_ALPHA_BYTE_INSTRUCTIONS               5
130 #define PF_XMMI_INSTRUCTIONS_AVAILABLE           6
131 #define PF_3DNOW_INSTRUCTIONS_AVAILABLE          7
132 #define PF_RDTSC_INSTRUCTION_AVAILABLE           8
133 #define PF_PAE_ENABLED                           9
134 #define PF_XMMI64_INSTRUCTIONS_AVAILABLE        10
135 #define PF_SSE_DAZ_MODE_AVAILABLE               11
136 #define PF_NX_ENABLED                           12
137 #define PF_SSE3_INSTRUCTIONS_AVAILABLE          13
138 #define PF_COMPARE_EXCHANGE128                  14
139 #define PF_COMPARE64_EXCHANGE128                15
140 #define PF_CHANNELS_ENABLED                     16
141 #define PF_XSAVE_ENABLED                        17
142 #define PF_ARM_VFP_32_REGISTERS_AVAILABLE       18
143 #define PF_ARM_NEON_INSTRUCTIONS_AVAILABLE      19
144 #define PF_SECOND_LEVEL_ADDRESS_TRANSLATION     20
145 #define PF_VIRT_FIRMWARE_ENABLED                21
146 #define PF_RDWRFSGSBASE_AVAILABLE               22
147 #define PF_FASTFAIL_AVAILABLE                   23
148 #define PF_ARM_DIVIDE_INSTRUCTION_AVAILABLE     24
149 #define PF_ARM_64BIT_LOADSTORE_ATOMIC           25
150 #define PF_ARM_EXTERNAL_CACHE_AVAILABLE         26
151 #define PF_ARM_FMAC_INSTRUCTIONS_AVAILABLE      27
152 #define PF_RDRAND_INSTRUCTION_AVAILABLE         28
153 #define PF_ARM_V8_INSTRUCTIONS_AVAILABLE        29
154 #define PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE 30
155 #define PF_ARM_V8_CRC32_INSTRUCTIONS_AVAILABLE  31
156 #define PF_RDTSCP_INSTRUCTION_AVAILABLE         32
157 #define PF_RDPID_INSTRUCTION_AVAILABLE          33
158 #define PF_ARM_V81_ATOMIC_INSTRUCTIONS_AVAILABLE 34
159 #define PF_SSSE3_INSTRUCTIONS_AVAILABLE         36
160 #define PF_SSE4_1_INSTRUCTIONS_AVAILABLE        37
161 #define PF_SSE4_2_INSTRUCTIONS_AVAILABLE        38
162 #define PF_AVX_INSTRUCTIONS_AVAILABLE           39
163 #define PF_AVX2_INSTRUCTIONS_AVAILABLE          40
164 #define PF_AVX512F_INSTRUCTIONS_AVAILABLE       41
165 #define PF_ARM_V82_DP_INSTRUCTIONS_AVAILABLE    43
166 #define PF_ARM_V83_JSCVT_INSTRUCTIONS_AVAILABLE 44
167 #define PF_ARM_V83_LRCPC_INSTRUCTIONS_AVAILABLE 45
168 
169 $endif(_WDMDDK_ || _WINNT_)
170 $if(_WDMDDK_)
171 
172 #define MAXIMUM_WAIT_OBJECTS              64
173 
174 #define ASSERT_APC(Object) \
175     NT_ASSERT((Object)->Type == ApcObject)
176 
177 #define ASSERT_DPC(Object) \
178     NT_ASSERT(((Object)->Type == 0) || \
179               ((Object)->Type == DpcObject) || \
180               ((Object)->Type == ThreadedDpcObject))
181 
182 #define ASSERT_GATE(Object) \
183     NT_ASSERT((((Object)->Header.Type & KOBJECT_TYPE_MASK) == GateObject) || \
184               (((Object)->Header.Type & KOBJECT_TYPE_MASK) == EventSynchronizationObject))
185 
186 #define ASSERT_DEVICE_QUEUE(Object) \
187     NT_ASSERT((Object)->Type == DeviceQueueObject)
188 
189 #define ASSERT_TIMER(Object) \
190     NT_ASSERT(((Object)->Header.Type == TimerNotificationObject) || \
191               ((Object)->Header.Type == TimerSynchronizationObject))
192 
193 #define ASSERT_MUTANT(Object) \
194     NT_ASSERT((Object)->Header.Type == MutantObject)
195 
196 #define ASSERT_SEMAPHORE(Object) \
197     NT_ASSERT((Object)->Header.Type == SemaphoreObject)
198 
199 #define ASSERT_EVENT(Object) \
200     NT_ASSERT(((Object)->Header.Type == NotificationEvent) || \
201               ((Object)->Header.Type == SynchronizationEvent))
202 
203 #define DPC_NORMAL 0
204 #define DPC_THREADED 1
205 
206 #define GM_LOCK_BIT          0x1
207 #define GM_LOCK_BIT_V        0x0
208 #define GM_LOCK_WAITER_WOKEN 0x2
209 #define GM_LOCK_WAITER_INC   0x4
210 
211 #define LOCK_QUEUE_WAIT_BIT               0
212 #define LOCK_QUEUE_OWNER_BIT              1
213 
214 #define LOCK_QUEUE_WAIT                   1
215 #define LOCK_QUEUE_OWNER                  2
216 #define LOCK_QUEUE_TIMER_LOCK_SHIFT       4
217 #define LOCK_QUEUE_TIMER_TABLE_LOCKS (1 << (8 - LOCK_QUEUE_TIMER_LOCK_SHIFT))
218 
219 #define PROCESSOR_FEATURE_MAX 64
220 
221 #define DBG_STATUS_CONTROL_C              1
222 #define DBG_STATUS_SYSRQ                  2
223 #define DBG_STATUS_BUGCHECK_FIRST         3
224 #define DBG_STATUS_BUGCHECK_SECOND        4
225 #define DBG_STATUS_FATAL                  5
226 #define DBG_STATUS_DEBUG_CONTROL          6
227 #define DBG_STATUS_WORKER                 7
228 
229 #if defined(_WIN64)
230 #define MAXIMUM_PROC_PER_GROUP 64
231 #else
232 #define MAXIMUM_PROC_PER_GROUP 32
233 #endif
234 #define MAXIMUM_PROCESSORS          MAXIMUM_PROC_PER_GROUP
235 
236 #define EXCEPTION_DIVIDED_BY_ZERO       0
237 #define EXCEPTION_DEBUG                 1
238 #define EXCEPTION_NMI                   2
239 #define EXCEPTION_INT3                  3
240 #define EXCEPTION_BOUND_CHECK           5
241 #define EXCEPTION_INVALID_OPCODE        6
242 #define EXCEPTION_NPX_NOT_AVAILABLE     7
243 #define EXCEPTION_DOUBLE_FAULT          8
244 #define EXCEPTION_NPX_OVERRUN           9
245 #define EXCEPTION_INVALID_TSS           0x0A
246 #define EXCEPTION_SEGMENT_NOT_PRESENT   0x0B
247 #define EXCEPTION_STACK_FAULT           0x0C
248 #define EXCEPTION_GP_FAULT              0x0D
249 #define EXCEPTION_RESERVED_TRAP         0x0F
250 #define EXCEPTION_NPX_ERROR             0x010
251 #define EXCEPTION_ALIGNMENT_CHECK       0x011
252 
253 typedef enum _KBUGCHECK_CALLBACK_REASON {
254   KbCallbackInvalid,
255   KbCallbackReserved1,
256   KbCallbackSecondaryDumpData,
257   KbCallbackDumpIo,
258   KbCallbackAddPages
259 } KBUGCHECK_CALLBACK_REASON;
260 
261 struct _KBUGCHECK_REASON_CALLBACK_RECORD;
262 
263 _Function_class_(KBUGCHECK_REASON_CALLBACK_ROUTINE)
264 _IRQL_requires_same_
265 typedef VOID
266 (NTAPI KBUGCHECK_REASON_CALLBACK_ROUTINE)(
267     _In_ KBUGCHECK_CALLBACK_REASON Reason,
268     _In_ struct _KBUGCHECK_REASON_CALLBACK_RECORD *Record,
269     _Inout_ PVOID ReasonSpecificData,
270     _In_ ULONG ReasonSpecificDataLength);
271 typedef KBUGCHECK_REASON_CALLBACK_ROUTINE *PKBUGCHECK_REASON_CALLBACK_ROUTINE;
272 
273 typedef struct _KBUGCHECK_ADD_PAGES {
274   _Inout_ PVOID Context;
275   _Inout_ ULONG Flags;
276   _In_ ULONG BugCheckCode;
277   _Out_ ULONG_PTR Address;
278   _Out_ ULONG_PTR Count;
279 } KBUGCHECK_ADD_PAGES, *PKBUGCHECK_ADD_PAGES;
280 
281 typedef struct _KBUGCHECK_SECONDARY_DUMP_DATA {
282   _In_ PVOID InBuffer;
283   _In_ ULONG InBufferLength;
284   _In_ ULONG MaximumAllowed;
285   _Out_ GUID Guid;
286   _Out_ PVOID OutBuffer;
287   _Out_ ULONG OutBufferLength;
288 } KBUGCHECK_SECONDARY_DUMP_DATA, *PKBUGCHECK_SECONDARY_DUMP_DATA;
289 
290 typedef enum _KBUGCHECK_DUMP_IO_TYPE {
291   KbDumpIoInvalid,
292   KbDumpIoHeader,
293   KbDumpIoBody,
294   KbDumpIoSecondaryData,
295   KbDumpIoComplete
296 } KBUGCHECK_DUMP_IO_TYPE;
297 
298 typedef struct _KBUGCHECK_DUMP_IO {
299   _In_ ULONG64 Offset;
300   _In_ PVOID Buffer;
301   _In_ ULONG BufferLength;
302   _In_ KBUGCHECK_DUMP_IO_TYPE Type;
303 } KBUGCHECK_DUMP_IO, *PKBUGCHECK_DUMP_IO;
304 
305 #define KB_ADD_PAGES_FLAG_VIRTUAL_ADDRESS         0x00000001UL
306 #define KB_ADD_PAGES_FLAG_PHYSICAL_ADDRESS        0x00000002UL
307 #define KB_ADD_PAGES_FLAG_ADDITIONAL_RANGES_EXIST 0x80000000UL
308 
309 typedef struct _KBUGCHECK_REASON_CALLBACK_RECORD {
310   LIST_ENTRY Entry;
311   PKBUGCHECK_REASON_CALLBACK_ROUTINE CallbackRoutine;
312   PUCHAR Component;
313   ULONG_PTR Checksum;
314   KBUGCHECK_CALLBACK_REASON Reason;
315   UCHAR State;
316 } KBUGCHECK_REASON_CALLBACK_RECORD, *PKBUGCHECK_REASON_CALLBACK_RECORD;
317 
318 typedef enum _KBUGCHECK_BUFFER_DUMP_STATE {
319   BufferEmpty,
320   BufferInserted,
321   BufferStarted,
322   BufferFinished,
323   BufferIncomplete
324 } KBUGCHECK_BUFFER_DUMP_STATE;
325 
326 _Function_class_(KBUGCHECK_CALLBACK_ROUTINE)
327 _IRQL_requires_same_
328 typedef VOID
329 (NTAPI KBUGCHECK_CALLBACK_ROUTINE)(
330   IN PVOID Buffer,
331   IN ULONG Length);
332 typedef KBUGCHECK_CALLBACK_ROUTINE *PKBUGCHECK_CALLBACK_ROUTINE;
333 
334 typedef struct _KBUGCHECK_CALLBACK_RECORD {
335   LIST_ENTRY Entry;
336   PKBUGCHECK_CALLBACK_ROUTINE CallbackRoutine;
337   _Field_size_bytes_opt_(Length) PVOID Buffer;
338   ULONG Length;
339   PUCHAR Component;
340   ULONG_PTR Checksum;
341   UCHAR State;
342 } KBUGCHECK_CALLBACK_RECORD, *PKBUGCHECK_CALLBACK_RECORD;
343 
344 _Function_class_(NMI_CALLBACK)
345 _IRQL_requires_same_
346 typedef BOOLEAN
347 (NTAPI NMI_CALLBACK)(
348   _In_opt_ PVOID Context,
349   _In_ BOOLEAN Handled);
350 typedef NMI_CALLBACK *PNMI_CALLBACK;
351 
352 typedef enum _KE_PROCESSOR_CHANGE_NOTIFY_STATE {
353   KeProcessorAddStartNotify = 0,
354   KeProcessorAddCompleteNotify,
355   KeProcessorAddFailureNotify
356 } KE_PROCESSOR_CHANGE_NOTIFY_STATE;
357 
358 typedef struct _KE_PROCESSOR_CHANGE_NOTIFY_CONTEXT {
359   KE_PROCESSOR_CHANGE_NOTIFY_STATE State;
360   ULONG NtNumber;
361   NTSTATUS Status;
362 #if (NTDDI_VERSION >= NTDDI_WIN7)
363   PROCESSOR_NUMBER ProcNumber;
364 #endif
365 } KE_PROCESSOR_CHANGE_NOTIFY_CONTEXT, *PKE_PROCESSOR_CHANGE_NOTIFY_CONTEXT;
366 
367 _IRQL_requires_same_
368 _Function_class_(PROCESSOR_CALLBACK_FUNCTION)
369 typedef VOID
370 (NTAPI PROCESSOR_CALLBACK_FUNCTION)(
371   _In_ PVOID CallbackContext,
372   _In_ PKE_PROCESSOR_CHANGE_NOTIFY_CONTEXT ChangeContext,
373   _Inout_ PNTSTATUS OperationStatus);
374 typedef PROCESSOR_CALLBACK_FUNCTION *PPROCESSOR_CALLBACK_FUNCTION;
375 
376 #define KE_PROCESSOR_CHANGE_ADD_EXISTING         1
377 
378 #define INVALID_PROCESSOR_INDEX     0xffffffff
379 
380 typedef enum _KINTERRUPT_POLARITY {
381   InterruptPolarityUnknown,
382   InterruptActiveHigh,
383   InterruptActiveLow
384 } KINTERRUPT_POLARITY, *PKINTERRUPT_POLARITY;
385 
386 typedef enum _KPROFILE_SOURCE {
387   ProfileTime,
388   ProfileAlignmentFixup,
389   ProfileTotalIssues,
390   ProfilePipelineDry,
391   ProfileLoadInstructions,
392   ProfilePipelineFrozen,
393   ProfileBranchInstructions,
394   ProfileTotalNonissues,
395   ProfileDcacheMisses,
396   ProfileIcacheMisses,
397   ProfileCacheMisses,
398   ProfileBranchMispredictions,
399   ProfileStoreInstructions,
400   ProfileFpInstructions,
401   ProfileIntegerInstructions,
402   Profile2Issue,
403   Profile3Issue,
404   Profile4Issue,
405   ProfileSpecialInstructions,
406   ProfileTotalCycles,
407   ProfileIcacheIssues,
408   ProfileDcacheAccesses,
409   ProfileMemoryBarrierCycles,
410   ProfileLoadLinkedIssues,
411   ProfileMaximum
412 } KPROFILE_SOURCE;
413 
414 typedef enum _KWAIT_REASON {
415   Executive,
416   FreePage,
417   PageIn,
418   PoolAllocation,
419   DelayExecution,
420   Suspended,
421   UserRequest,
422   WrExecutive,
423   WrFreePage,
424   WrPageIn,
425   WrPoolAllocation,
426   WrDelayExecution,
427   WrSuspended,
428   WrUserRequest,
429   WrEventPair,
430   WrQueue,
431   WrLpcReceive,
432   WrLpcReply,
433   WrVirtualMemory,
434   WrPageOut,
435   WrRendezvous,
436   WrKeyedEvent,
437   WrTerminated,
438   WrProcessInSwap,
439   WrCpuRateControl,
440   WrCalloutStack,
441   WrKernel,
442   WrResource,
443   WrPushLock,
444   WrMutex,
445   WrQuantumEnd,
446   WrDispatchInt,
447   WrPreempted,
448   WrYieldExecution,
449   WrFastMutex,
450   WrGuardedMutex,
451   WrRundown,
452   MaximumWaitReason
453 } KWAIT_REASON;
454 
455 typedef struct _KWAIT_BLOCK {
456   LIST_ENTRY WaitListEntry;
457 #if (NTDDI_VERSION >= NTDDI_WIN8)
458   UCHAR WaitType;
459   volatile UCHAR BlockState;
460   USHORT WaitKey;
461 #ifdef _WIN64
462   LONG SpareLong;
463 #endif
464   union {
465     struct _KTHREAD *Thread;
466     struct _KQUEUE *NotificationQueue;
467   };
468   PVOID Object;
469   PVOID SparePtr;
470 #else
471   struct _KTHREAD *Thread;
472   PVOID Object;
473   struct _KWAIT_BLOCK *NextWaitBlock;
474   USHORT WaitKey;
475   UCHAR WaitType;
476 #if (NTDDI_VERSION >= NTDDI_WIN7)
477   volatile UCHAR BlockState;
478 #else
479   UCHAR SpareByte;
480 #endif
481 #if defined(_WIN64)
482   LONG SpareLong;
483 #endif
484 #endif
485 } KWAIT_BLOCK, *PKWAIT_BLOCK, *PRKWAIT_BLOCK;
486 
487 typedef enum _KINTERRUPT_MODE {
488   LevelSensitive,
489   Latched
490 } KINTERRUPT_MODE;
491 
492 #define THREAD_WAIT_OBJECTS 3
493 
494 _IRQL_requires_same_
495 _Function_class_(KSTART_ROUTINE)
496 typedef VOID
497 (NTAPI KSTART_ROUTINE)(
498   _In_ PVOID StartContext);
499 typedef KSTART_ROUTINE *PKSTART_ROUTINE;
500 
501 typedef VOID
502 (NTAPI *PKINTERRUPT_ROUTINE)(
503   VOID);
504 
505 _Function_class_(KSERVICE_ROUTINE)
506 _IRQL_requires_(HIGH_LEVEL)
507 _IRQL_requires_same_
508 typedef BOOLEAN
509 (NTAPI KSERVICE_ROUTINE)(
510   _In_ struct _KINTERRUPT *Interrupt,
511   _In_ PVOID ServiceContext);
512 typedef KSERVICE_ROUTINE *PKSERVICE_ROUTINE;
513 
514 _Function_class_(KMESSAGE_SERVICE_ROUTINE)
515 _IRQL_requires_same_
516 typedef BOOLEAN
517 (NTAPI KMESSAGE_SERVICE_ROUTINE)(
518   _In_ struct _KINTERRUPT *Interrupt,
519   _In_ PVOID ServiceContext,
520   _In_ ULONG MessageID);
521 typedef KMESSAGE_SERVICE_ROUTINE *PKMESSAGE_SERVICE_ROUTINE;
522 
523 typedef enum _KD_OPTION {
524   KD_OPTION_SET_BLOCK_ENABLE,
525 } KD_OPTION;
526 
527 #ifdef _NTSYSTEM_
528 typedef VOID
529 (NTAPI *PKNORMAL_ROUTINE)(
530   IN PVOID NormalContext OPTIONAL,
531   IN PVOID SystemArgument1 OPTIONAL,
532   IN PVOID SystemArgument2 OPTIONAL);
533 
534 typedef VOID
535 (NTAPI *PKRUNDOWN_ROUTINE)(
536   IN struct _KAPC *Apc);
537 
538 typedef VOID
539 (NTAPI *PKKERNEL_ROUTINE)(
540   IN struct _KAPC *Apc,
541   IN OUT PKNORMAL_ROUTINE *NormalRoutine OPTIONAL,
542   IN OUT PVOID *NormalContext OPTIONAL,
543   IN OUT PVOID *SystemArgument1 OPTIONAL,
544   IN OUT PVOID *SystemArgument2 OPTIONAL);
545 #endif
546 
547 typedef struct _KAPC {
548   UCHAR Type;
549   UCHAR SpareByte0;
550   UCHAR Size;
551   UCHAR SpareByte1;
552   ULONG SpareLong0;
553   struct _KTHREAD *Thread;
554   LIST_ENTRY ApcListEntry;
555 #ifdef _NTSYSTEM_
556   PKKERNEL_ROUTINE KernelRoutine;
557   PKRUNDOWN_ROUTINE RundownRoutine;
558   PKNORMAL_ROUTINE NormalRoutine;
559 #else
560   PVOID Reserved[3];
561 #endif
562   PVOID NormalContext;
563   PVOID SystemArgument1;
564   PVOID SystemArgument2;
565   CCHAR ApcStateIndex;
566   KPROCESSOR_MODE ApcMode;
567   BOOLEAN Inserted;
568 } KAPC, *PKAPC, *RESTRICTED_POINTER PRKAPC;
569 
570 #define KAPC_OFFSET_TO_SPARE_BYTE0 FIELD_OFFSET(KAPC, SpareByte0)
571 #define KAPC_OFFSET_TO_SPARE_BYTE1 FIELD_OFFSET(KAPC, SpareByte1)
572 #define KAPC_OFFSET_TO_SPARE_LONG FIELD_OFFSET(KAPC, SpareLong0)
573 #define KAPC_OFFSET_TO_SYSTEMARGUMENT1 FIELD_OFFSET(KAPC, SystemArgument1)
574 #define KAPC_OFFSET_TO_SYSTEMARGUMENT2 FIELD_OFFSET(KAPC, SystemArgument2)
575 #define KAPC_OFFSET_TO_APCSTATEINDEX FIELD_OFFSET(KAPC, ApcStateIndex)
576 #define KAPC_ACTUAL_LENGTH (FIELD_OFFSET(KAPC, Inserted) + sizeof(BOOLEAN))
577 
578 typedef struct _KDEVICE_QUEUE_ENTRY {
579   LIST_ENTRY DeviceListEntry;
580   ULONG SortKey;
581   BOOLEAN Inserted;
582 } KDEVICE_QUEUE_ENTRY, *PKDEVICE_QUEUE_ENTRY,
583 *RESTRICTED_POINTER PRKDEVICE_QUEUE_ENTRY;
584 
585 typedef PVOID PKIPI_CONTEXT;
586 
587 typedef VOID
588 (NTAPI *PKIPI_WORKER)(
589   IN OUT PKIPI_CONTEXT PacketContext,
590   IN PVOID Parameter1 OPTIONAL,
591   IN PVOID Parameter2 OPTIONAL,
592   IN PVOID Parameter3 OPTIONAL);
593 
594 typedef struct _KIPI_COUNTS {
595   ULONG Freeze;
596   ULONG Packet;
597   ULONG DPC;
598   ULONG APC;
599   ULONG FlushSingleTb;
600   ULONG FlushMultipleTb;
601   ULONG FlushEntireTb;
602   ULONG GenericCall;
603   ULONG ChangeColor;
604   ULONG SweepDcache;
605   ULONG SweepIcache;
606   ULONG SweepIcacheRange;
607   ULONG FlushIoBuffers;
608   ULONG GratuitousDPC;
609 } KIPI_COUNTS, *PKIPI_COUNTS;
610 
611 _IRQL_requires_same_
612 _Function_class_(KIPI_BROADCAST_WORKER)
613 _IRQL_requires_(IPI_LEVEL)
614 typedef ULONG_PTR
615 (NTAPI KIPI_BROADCAST_WORKER)(
616   _In_ ULONG_PTR Argument);
617 typedef KIPI_BROADCAST_WORKER *PKIPI_BROADCAST_WORKER;
618 
619 typedef ULONG_PTR KSPIN_LOCK, *PKSPIN_LOCK;
620 
621 typedef struct _KSPIN_LOCK_QUEUE {
622   struct _KSPIN_LOCK_QUEUE *volatile Next;
623   PKSPIN_LOCK volatile Lock;
624 } KSPIN_LOCK_QUEUE, *PKSPIN_LOCK_QUEUE;
625 
626 typedef struct _KLOCK_QUEUE_HANDLE {
627   KSPIN_LOCK_QUEUE LockQueue;
628   KIRQL OldIrql;
629 } KLOCK_QUEUE_HANDLE, *PKLOCK_QUEUE_HANDLE;
630 
631 #if defined(_AMD64_)
632 
633 typedef ULONG64 KSPIN_LOCK_QUEUE_NUMBER;
634 
635 #define LockQueueDispatcherLock 0
636 #define LockQueueExpansionLock 1
637 #define LockQueuePfnLock 2
638 #define LockQueueSystemSpaceLock 3
639 #define LockQueueVacbLock 4
640 #define LockQueueMasterLock 5
641 #define LockQueueNonPagedPoolLock 6
642 #define LockQueueIoCancelLock 7
643 #define LockQueueWorkQueueLock 8
644 #define LockQueueIoVpbLock 9
645 #define LockQueueIoDatabaseLock 10
646 #define LockQueueIoCompletionLock 11
647 #define LockQueueNtfsStructLock 12
648 #define LockQueueAfdWorkQueueLock 13
649 #define LockQueueBcbLock 14
650 #define LockQueueMmNonPagedPoolLock 15
651 #define LockQueueUnusedSpare16 16
652 #define LockQueueTimerTableLock 17
653 #define LockQueueMaximumLock (LockQueueTimerTableLock + LOCK_QUEUE_TIMER_TABLE_LOCKS)
654 
655 #else
656 
657 typedef enum _KSPIN_LOCK_QUEUE_NUMBER {
658   LockQueueDispatcherLock,
659   LockQueueExpansionLock,
660   LockQueuePfnLock,
661   LockQueueSystemSpaceLock,
662   LockQueueVacbLock,
663   LockQueueMasterLock,
664   LockQueueNonPagedPoolLock,
665   LockQueueIoCancelLock,
666   LockQueueWorkQueueLock,
667   LockQueueIoVpbLock,
668   LockQueueIoDatabaseLock,
669   LockQueueIoCompletionLock,
670   LockQueueNtfsStructLock,
671   LockQueueAfdWorkQueueLock,
672   LockQueueBcbLock,
673   LockQueueMmNonPagedPoolLock,
674   LockQueueUnusedSpare16,
675   LockQueueTimerTableLock,
676   LockQueueMaximumLock = LockQueueTimerTableLock + LOCK_QUEUE_TIMER_TABLE_LOCKS
677 } KSPIN_LOCK_QUEUE_NUMBER, *PKSPIN_LOCK_QUEUE_NUMBER;
678 
679 #endif /* defined(_AMD64_) */
680 
681 _Function_class_(KDEFERRED_ROUTINE)
682 _IRQL_requires_(DISPATCH_LEVEL)
683 _IRQL_requires_same_
684 typedef VOID
685 (NTAPI KDEFERRED_ROUTINE)(
686   _In_ struct _KDPC *Dpc,
687   _In_opt_ PVOID DeferredContext,
688   _In_opt_ PVOID SystemArgument1,
689   _In_opt_ PVOID SystemArgument2);
690 typedef KDEFERRED_ROUTINE *PKDEFERRED_ROUTINE;
691 
692 typedef enum _KDPC_IMPORTANCE {
693   LowImportance,
694   MediumImportance,
695   HighImportance,
696   MediumHighImportance
697 } KDPC_IMPORTANCE;
698 
699 typedef struct _KDPC {
700   UCHAR Type;
701   UCHAR Importance;
702   volatile USHORT Number;
703   LIST_ENTRY DpcListEntry;
704   PKDEFERRED_ROUTINE DeferredRoutine;
705   PVOID DeferredContext;
706   PVOID SystemArgument1;
707   PVOID SystemArgument2;
708   volatile PVOID DpcData;
709 } KDPC, *PKDPC, *RESTRICTED_POINTER PRKDPC;
710 
711 typedef struct _KDPC_WATCHDOG_INFORMATION {
712   ULONG DpcTimeLimit;
713   ULONG DpcTimeCount;
714   ULONG DpcWatchdogLimit;
715   ULONG DpcWatchdogCount;
716   ULONG Reserved;
717 } KDPC_WATCHDOG_INFORMATION, *PKDPC_WATCHDOG_INFORMATION;
718 
719 typedef struct _KDEVICE_QUEUE {
720   CSHORT Type;
721   CSHORT Size;
722   LIST_ENTRY DeviceListHead;
723   KSPIN_LOCK Lock;
724 # if defined(_AMD64_)
725   _ANONYMOUS_UNION union {
726     BOOLEAN Busy;
727     _ANONYMOUS_STRUCT struct {
728       LONG64 Reserved:8;
729       LONG64 Hint:56;
730     } DUMMYSTRUCTNAME;
731   } DUMMYUNIONNAME;
732 # else
733   BOOLEAN Busy;
734 # endif
735 } KDEVICE_QUEUE, *PKDEVICE_QUEUE, *RESTRICTED_POINTER PRKDEVICE_QUEUE;
736 
737 #define TIMER_EXPIRED_INDEX_BITS        6
738 #define TIMER_PROCESSOR_INDEX_BITS      5
739 
740 typedef struct _DISPATCHER_HEADER {
741   _ANONYMOUS_UNION union {
742     _ANONYMOUS_STRUCT struct {
743       UCHAR Type;
744       _ANONYMOUS_UNION union {
745         _ANONYMOUS_UNION union {
746           UCHAR TimerControlFlags;
747           _ANONYMOUS_STRUCT struct {
748             UCHAR Absolute:1;
749             UCHAR Coalescable:1;
750             UCHAR KeepShifting:1;
751             UCHAR EncodedTolerableDelay:5;
752           } DUMMYSTRUCTNAME;
753         } DUMMYUNIONNAME;
754         UCHAR Abandoned;
755 #if (NTDDI_VERSION < NTDDI_WIN7)
756         UCHAR NpxIrql;
757 #endif
758         BOOLEAN Signalling;
759       } DUMMYUNIONNAME;
760       _ANONYMOUS_UNION union {
761         _ANONYMOUS_UNION union {
762           UCHAR ThreadControlFlags;
763           _ANONYMOUS_STRUCT struct {
764             UCHAR CpuThrottled:1;
765             UCHAR CycleProfiling:1;
766             UCHAR CounterProfiling:1;
767             UCHAR Reserved:5;
768           } DUMMYSTRUCTNAME;
769         } DUMMYUNIONNAME;
770         UCHAR Size;
771         UCHAR Hand;
772       } DUMMYUNIONNAME2;
773       _ANONYMOUS_UNION union {
774 #if (NTDDI_VERSION >= NTDDI_WIN7)
775         _ANONYMOUS_UNION union {
776           UCHAR TimerMiscFlags;
777           _ANONYMOUS_STRUCT struct {
778 #if !defined(_X86_)
779             UCHAR Index:TIMER_EXPIRED_INDEX_BITS;
780 #else
781             UCHAR Index:1;
782             UCHAR Processor:TIMER_PROCESSOR_INDEX_BITS;
783 #endif
784             UCHAR Inserted:1;
785             volatile UCHAR Expired:1;
786           } DUMMYSTRUCTNAME;
787         } DUMMYUNIONNAME;
788 #else
789         /* Pre Win7 compatibility fix to latest WDK */
790         UCHAR Inserted;
791 #endif
792         _ANONYMOUS_UNION union {
793           BOOLEAN DebugActive;
794           _ANONYMOUS_STRUCT struct {
795             BOOLEAN ActiveDR7:1;
796             BOOLEAN Instrumented:1;
797             BOOLEAN Reserved2:4;
798             BOOLEAN UmsScheduled:1;
799             BOOLEAN UmsPrimary:1;
800           } DUMMYSTRUCTNAME;
801         } DUMMYUNIONNAME; /* should probably be DUMMYUNIONNAME2, but this is what WDK says */
802         BOOLEAN DpcActive;
803       } DUMMYUNIONNAME3;
804     } DUMMYSTRUCTNAME;
805     volatile LONG Lock;
806   } DUMMYUNIONNAME;
807   LONG SignalState;
808   LIST_ENTRY WaitListHead;
809 } DISPATCHER_HEADER, *PDISPATCHER_HEADER;
810 
811 typedef struct _KEVENT {
812   DISPATCHER_HEADER Header;
813 } KEVENT, *PKEVENT, *RESTRICTED_POINTER PRKEVENT;
814 
815 typedef struct _KSEMAPHORE {
816   DISPATCHER_HEADER Header;
817   LONG Limit;
818 } KSEMAPHORE, *PKSEMAPHORE, *RESTRICTED_POINTER PRKSEMAPHORE;
819 
820 #define KSEMAPHORE_ACTUAL_LENGTH (FIELD_OFFSET(KSEMAPHORE, Limit) + sizeof(LONG))
821 
822 typedef struct _KGATE {
823   DISPATCHER_HEADER Header;
824 } KGATE, *PKGATE, *RESTRICTED_POINTER PRKGATE;
825 
826 typedef struct _KGUARDED_MUTEX {
827   volatile LONG Count;
828   PKTHREAD Owner;
829   ULONG Contention;
830   KGATE Gate;
831   _ANONYMOUS_UNION union {
832     _ANONYMOUS_STRUCT struct {
833       SHORT KernelApcDisable;
834       SHORT SpecialApcDisable;
835     } DUMMYSTRUCTNAME;
836     ULONG CombinedApcDisable;
837   } DUMMYUNIONNAME;
838 } KGUARDED_MUTEX, *PKGUARDED_MUTEX;
839 
840 typedef struct _KMUTANT {
841   DISPATCHER_HEADER Header;
842   LIST_ENTRY MutantListEntry;
843   struct _KTHREAD *RESTRICTED_POINTER OwnerThread;
844   BOOLEAN Abandoned;
845   UCHAR ApcDisable;
846 } KMUTANT, *PKMUTANT, *RESTRICTED_POINTER PRKMUTANT, KMUTEX, *PKMUTEX, *RESTRICTED_POINTER PRKMUTEX;
847 
848 #define TIMER_TABLE_SIZE 512
849 #define TIMER_TABLE_SHIFT 9
850 
851 typedef struct _KTIMER {
852   DISPATCHER_HEADER Header;
853   ULARGE_INTEGER DueTime;
854   LIST_ENTRY TimerListEntry;
855   struct _KDPC *Dpc;
856 #if (NTDDI_VERSION >= NTDDI_WIN7) && !defined(_X86_)
857   ULONG Processor;
858 #endif
859   ULONG Period;
860 } KTIMER, *PKTIMER, *RESTRICTED_POINTER PRKTIMER;
861 
862 typedef enum _LOCK_OPERATION {
863   IoReadAccess,
864   IoWriteAccess,
865   IoModifyAccess
866 } LOCK_OPERATION;
867 
868 #define KTIMER_ACTUAL_LENGTH (FIELD_OFFSET(KTIMER, Period) + sizeof(LONG))
869 
870 _Function_class_(KSYNCHRONIZE_ROUTINE)
871 _IRQL_requires_same_
872 typedef BOOLEAN
873 (NTAPI KSYNCHRONIZE_ROUTINE)(
874   _In_ PVOID SynchronizeContext);
875 typedef KSYNCHRONIZE_ROUTINE *PKSYNCHRONIZE_ROUTINE;
876 
877 typedef enum _POOL_TYPE {
878   NonPagedPool,
879   PagedPool,
880   NonPagedPoolMustSucceed,
881   DontUseThisType,
882   NonPagedPoolCacheAligned,
883   PagedPoolCacheAligned,
884   NonPagedPoolCacheAlignedMustS,
885   MaxPoolType,
886 
887   NonPagedPoolBase = 0,
888   NonPagedPoolBaseMustSucceed = NonPagedPoolBase + 2,
889   NonPagedPoolBaseCacheAligned = NonPagedPoolBase + 4,
890   NonPagedPoolBaseCacheAlignedMustS = NonPagedPoolBase + 6,
891 
892   NonPagedPoolSession = 32,
893   PagedPoolSession,
894   NonPagedPoolMustSucceedSession,
895   DontUseThisTypeSession,
896   NonPagedPoolCacheAlignedSession,
897   PagedPoolCacheAlignedSession,
898   NonPagedPoolCacheAlignedMustSSession
899 } POOL_TYPE;
900 
901 typedef enum _ALTERNATIVE_ARCHITECTURE_TYPE {
902   StandardDesign,
903   NEC98x86,
904   EndAlternatives
905 } ALTERNATIVE_ARCHITECTURE_TYPE;
906 
907 /* Correctly define these run-time definitions for non X86 machines */
908 #ifndef _X86_
909 
910 #ifndef IsNEC_98
911 #define IsNEC_98 (FALSE)
912 #endif
913 
914 #ifndef IsNotNEC_98
915 #define IsNotNEC_98 (TRUE)
916 #endif
917 
918 #ifndef SetNEC_98
919 #define SetNEC_98
920 #endif
921 
922 #ifndef SetNotNEC_98
923 #define SetNotNEC_98
924 #endif
925 
926 #endif
927 
928 typedef struct _KSYSTEM_TIME {
929   ULONG LowPart;
930   LONG High1Time;
931   LONG High2Time;
932 } KSYSTEM_TIME, *PKSYSTEM_TIME;
933 
934 typedef struct DECLSPEC_ALIGN(16) _M128A {
935   ULONGLONG Low;
936   LONGLONG High;
937 } M128A, *PM128A;
938 
939 typedef struct DECLSPEC_ALIGN(16) _XSAVE_FORMAT {
940   USHORT ControlWord;
941   USHORT StatusWord;
942   UCHAR TagWord;
943   UCHAR Reserved1;
944   USHORT ErrorOpcode;
945   ULONG ErrorOffset;
946   USHORT ErrorSelector;
947   USHORT Reserved2;
948   ULONG DataOffset;
949   USHORT DataSelector;
950   USHORT Reserved3;
951   ULONG MxCsr;
952   ULONG MxCsr_Mask;
953   M128A FloatRegisters[8];
954 #if defined(_WIN64)
955   M128A XmmRegisters[16];
956   UCHAR Reserved4[96];
957 #else
958   M128A XmmRegisters[8];
959   UCHAR Reserved4[192];
960   ULONG StackControl[7];
961   ULONG Cr0NpxState;
962 #endif
963 } XSAVE_FORMAT, *PXSAVE_FORMAT;
964 
965 typedef struct DECLSPEC_ALIGN(8) _XSAVE_AREA_HEADER {
966   ULONG64 Mask;
967   ULONG64 Reserved[7];
968 } XSAVE_AREA_HEADER, *PXSAVE_AREA_HEADER;
969 
970 typedef struct DECLSPEC_ALIGN(16) _XSAVE_AREA {
971   XSAVE_FORMAT LegacyState;
972   XSAVE_AREA_HEADER Header;
973 } XSAVE_AREA, *PXSAVE_AREA;
974 
975 typedef struct _XSTATE_CONTEXT {
976   ULONG64 Mask;
977   ULONG Length;
978   ULONG Reserved1;
979   _Field_size_bytes_opt_(Length) PXSAVE_AREA Area;
980 #if defined(_X86_)
981   ULONG Reserved2;
982 #endif
983   PVOID Buffer;
984 #if defined(_X86_)
985   ULONG Reserved3;
986 #endif
987 } XSTATE_CONTEXT, *PXSTATE_CONTEXT;
988 
989 typedef struct _XSTATE_SAVE {
990 #if defined(_AMD64_)
991   struct _XSTATE_SAVE* Prev;
992   struct _KTHREAD* Thread;
993   UCHAR Level;
994   XSTATE_CONTEXT XStateContext;
995 #elif defined(_IA64_) || defined(_ARM_) || defined(_ARM64_)
996   ULONG Dummy;
997 #elif defined(_X86_)
998   _ANONYMOUS_UNION union {
999     _ANONYMOUS_STRUCT struct {
1000       LONG64 Reserved1;
1001       ULONG Reserved2;
1002       struct _XSTATE_SAVE* Prev;
1003       PXSAVE_AREA Reserved3;
1004       struct _KTHREAD* Thread;
1005       PVOID Reserved4;
1006       UCHAR Level;
1007     } DUMMYSTRUCTNAME;
1008     XSTATE_CONTEXT XStateContext;
1009   } DUMMYUNIONNAME;
1010 #endif
1011 } XSTATE_SAVE, *PXSTATE_SAVE;
1012 
1013 #ifdef _X86_
1014 
1015 #define MAXIMUM_SUPPORTED_EXTENSION  512
1016 
1017 #if !defined(__midl) && !defined(MIDL_PASS)
1018 C_ASSERT(sizeof(XSAVE_FORMAT) == MAXIMUM_SUPPORTED_EXTENSION);
1019 #endif
1020 
1021 #endif /* _X86_ */
1022 
1023 #define XSAVE_ALIGN                    64
1024 #define MINIMAL_XSTATE_AREA_LENGTH     sizeof(XSAVE_AREA)
1025 
1026 #if !defined(__midl) && !defined(MIDL_PASS)
1027 C_ASSERT((sizeof(XSAVE_FORMAT) & (XSAVE_ALIGN - 1)) == 0);
1028 C_ASSERT((FIELD_OFFSET(XSAVE_AREA, Header) & (XSAVE_ALIGN - 1)) == 0);
1029 C_ASSERT(MINIMAL_XSTATE_AREA_LENGTH == 512 + 64);
1030 #endif
1031 
1032 typedef struct _CONTEXT_CHUNK {
1033   LONG Offset;
1034   ULONG Length;
1035 } CONTEXT_CHUNK, *PCONTEXT_CHUNK;
1036 
1037 typedef struct _CONTEXT_EX {
1038   CONTEXT_CHUNK All;
1039   CONTEXT_CHUNK Legacy;
1040   CONTEXT_CHUNK XState;
1041 } CONTEXT_EX, *PCONTEXT_EX;
1042 
1043 #define CONTEXT_EX_LENGTH         ALIGN_UP_BY(sizeof(CONTEXT_EX), STACK_ALIGN)
1044 
1045 #if (NTDDI_VERSION >= NTDDI_VISTA)
1046 extern NTSYSAPI volatile CCHAR KeNumberProcessors;
1047 #elif (NTDDI_VERSION >= NTDDI_WINXP)
1048 extern NTSYSAPI CCHAR KeNumberProcessors;
1049 #else
1050 __CREATE_NTOS_DATA_IMPORT_ALIAS(KeNumberProcessors)
1051 extern PCCHAR KeNumberProcessors;
1052 #endif
1053 
1054 $endif (_WDMDDK_)
1055 $if (_NTDDK_)
1056 
1057 typedef struct _EXCEPTION_REGISTRATION_RECORD
1058 {
1059   struct _EXCEPTION_REGISTRATION_RECORD *Next;
1060   PEXCEPTION_ROUTINE Handler;
1061 } EXCEPTION_REGISTRATION_RECORD, *PEXCEPTION_REGISTRATION_RECORD;
1062 
1063 typedef struct _NT_TIB {
1064   struct _EXCEPTION_REGISTRATION_RECORD *ExceptionList;
1065   PVOID StackBase;
1066   PVOID StackLimit;
1067   PVOID SubSystemTib;
1068   _ANONYMOUS_UNION union {
1069     PVOID FiberData;
1070     ULONG Version;
1071   } DUMMYUNIONNAME;
1072   PVOID ArbitraryUserPointer;
1073   struct _NT_TIB *Self;
1074 } NT_TIB, *PNT_TIB;
1075 
1076 typedef struct _NT_TIB32 {
1077   ULONG ExceptionList;
1078   ULONG StackBase;
1079   ULONG StackLimit;
1080   ULONG SubSystemTib;
1081   _ANONYMOUS_UNION union {
1082     ULONG FiberData;
1083     ULONG Version;
1084   } DUMMYUNIONNAME;
1085   ULONG ArbitraryUserPointer;
1086   ULONG Self;
1087 } NT_TIB32,*PNT_TIB32;
1088 
1089 typedef struct _NT_TIB64 {
1090   ULONG64 ExceptionList;
1091   ULONG64 StackBase;
1092   ULONG64 StackLimit;
1093   ULONG64 SubSystemTib;
1094   _ANONYMOUS_UNION union {
1095     ULONG64 FiberData;
1096     ULONG Version;
1097   } DUMMYUNIONNAME;
1098   ULONG64 ArbitraryUserPointer;
1099   ULONG64 Self;
1100 } NT_TIB64,*PNT_TIB64;
1101 
1102 _IRQL_requires_same_
1103 _Function_class_(EXPAND_STACK_CALLOUT)
1104 typedef VOID
1105 (NTAPI EXPAND_STACK_CALLOUT)(
1106   _In_opt_ PVOID Parameter);
1107 typedef EXPAND_STACK_CALLOUT *PEXPAND_STACK_CALLOUT;
1108 
1109 typedef VOID
1110 (NTAPI *PTIMER_APC_ROUTINE)(
1111   _In_ PVOID TimerContext,
1112   _In_ ULONG TimerLowValue,
1113   _In_ LONG TimerHighValue);
1114 
1115 typedef enum _TIMER_SET_INFORMATION_CLASS {
1116   TimerSetCoalescableTimer,
1117   MaxTimerInfoClass
1118 } TIMER_SET_INFORMATION_CLASS;
1119 
1120 #if (NTDDI_VERSION >= NTDDI_WIN7)
1121 typedef struct _TIMER_SET_COALESCABLE_TIMER_INFO {
1122   _In_ LARGE_INTEGER DueTime;
1123   _In_opt_ PTIMER_APC_ROUTINE TimerApcRoutine;
1124   _In_opt_ PVOID TimerContext;
1125   _In_opt_ struct _COUNTED_REASON_CONTEXT *WakeContext;
1126   _In_opt_ ULONG Period;
1127   _In_ ULONG TolerableDelay;
1128   _Out_opt_ PBOOLEAN PreviousState;
1129 } TIMER_SET_COALESCABLE_TIMER_INFO, *PTIMER_SET_COALESCABLE_TIMER_INFO;
1130 #endif /* (NTDDI_VERSION >= NTDDI_WIN7) */
1131 
1132 #define XSTATE_LEGACY_FLOATING_POINT        0
1133 #define XSTATE_LEGACY_SSE                   1
1134 #define XSTATE_GSSE                         2
1135 #define XSTATE_AVX                          XSTATE_GSSE
1136 #define XSTATE_MPX_BNDREGS                  3
1137 #define XSTATE_MPX_BNDCSR                   4
1138 #define XSTATE_AVX512_KMASK                 5
1139 #define XSTATE_AVX512_ZMM_H                 6
1140 #define XSTATE_AVX512_ZMM                   7
1141 #define XSTATE_IPT                          8
1142 #define XSTATE_PASID                        10
1143 #define XSTATE_CET_U                        11
1144 #define XSTATE_CET_S                        12
1145 #define XSTATE_AMX_TILE_CONFIG              17
1146 #define XSTATE_AMX_TILE_DATA                18
1147 #define XSTATE_LWP                          62
1148 #define MAXIMUM_XSTATE_FEATURES             64
1149 
1150 #define XSTATE_MASK_LEGACY_FLOATING_POINT   (1LL << (XSTATE_LEGACY_FLOATING_POINT))
1151 #define XSTATE_MASK_LEGACY_SSE              (1LL << (XSTATE_LEGACY_SSE))
1152 #define XSTATE_MASK_LEGACY                  (XSTATE_MASK_LEGACY_FLOATING_POINT | XSTATE_MASK_LEGACY_SSE)
1153 #define XSTATE_MASK_GSSE                    (1LL << (XSTATE_GSSE))
1154 #define XSTATE_MASK_AVX                     XSTATE_MASK_GSSE
1155 #define XSTATE_MASK_MPX                     ((1LL << (XSTATE_MPX_BNDREGS)) | (1LL << (XSTATE_MPX_BNDCSR)))
1156 #define XSTATE_MASK_AVX512                  ((1LL << (XSTATE_AVX512_KMASK)) | (1LL << (XSTATE_AVX512_ZMM_H)) |  (1LL << (XSTATE_AVX512_ZMM)))
1157 #define XSTATE_MASK_IPT                     (1LL << (XSTATE_IPT))
1158 #define XSTATE_MASK_PASID                   (1LL << (XSTATE_PASID))
1159 #define XSTATE_MASK_CET_U                   (1LL << (XSTATE_CET_U))
1160 #define XSTATE_MASK_CET_S                   (1LL << (XSTATE_CET_S))
1161 #define XSTATE_MASK_AMX_TILE_CONFIG         (1LL << (XSTATE_AMX_TILE_CONFIG))
1162 #define XSTATE_MASK_AMX_TILE_DATA           (1LL << (XSTATE_AMX_TILE_DATA))
1163 #define XSTATE_MASK_LWP                     (1LL << (XSTATE_LWP))
1164 
1165 #if defined(_AMD64_)
1166 #define XSTATE_MASK_ALLOWED \
1167     (XSTATE_MASK_LEGACY | \
1168      XSTATE_MASK_AVX | \
1169      XSTATE_MASK_MPX | \
1170      XSTATE_MASK_AVX512 | \
1171      XSTATE_MASK_IPT | \
1172      XSTATE_MASK_PASID | \
1173      XSTATE_MASK_CET_U | \
1174      XSTATE_MASK_AMX_TILE_CONFIG | \
1175      XSTATE_MASK_AMX_TILE_DATA | \
1176      XSTATE_MASK_LWP)
1177 #elif defined(_X86_)
1178 #define XSTATE_MASK_ALLOWED \
1179     (XSTATE_MASK_LEGACY | \
1180      XSTATE_MASK_AVX | \
1181      XSTATE_MASK_MPX | \
1182      XSTATE_MASK_AVX512 | \
1183      XSTATE_MASK_IPT | \
1184      XSTATE_MASK_CET_U | \
1185      XSTATE_MASK_LWP)
1186 #endif
1187 
1188 #define XSTATE_MASK_PERSISTENT              ((1LL << (XSTATE_MPX_BNDCSR)) | XSTATE_MASK_LWP)
1189 #define XSTATE_MASK_USER_VISIBLE_SUPERVISOR (XSTATE_MASK_CET_U)
1190 #define XSTATE_MASK_LARGE_FEATURES          (XSTATE_MASK_AMX_TILE_DATA)
1191 
1192 #if defined(_X86_)
1193 #if !defined(__midl) && !defined(MIDL_PASS)
1194 C_ASSERT((XSTATE_MASK_ALLOWED & XSTATE_MASK_LARGE_FEATURES) == 0);
1195 #endif
1196 #endif
1197 
1198 #define XSTATE_COMPACTION_ENABLE            63
1199 #define XSTATE_COMPACTION_ENABLE_MASK       (1LL << (XSTATE_COMPACTION_ENABLE))
1200 #define XSTATE_ALIGN_BIT                    1
1201 #define XSTATE_ALIGN_MASK                   (1LL << (XSTATE_ALIGN_BIT))
1202 
1203 #define XSTATE_XFD_BIT                      2
1204 #define XSTATE_XFD_MASK                     (1LL << (XSTATE_XFD_BIT))
1205 
1206 #define XSTATE_CONTROLFLAG_XSAVEOPT_MASK    1
1207 #define XSTATE_CONTROLFLAG_XSAVEC_MASK      2
1208 #define XSTATE_CONTROLFLAG_XFD_MASK         4
1209 #define XSTATE_CONTROLFLAG_VALID_MASK \
1210     (XSTATE_CONTROLFLAG_XSAVEOPT_MASK | \
1211      XSTATE_CONTROLFLAG_XSAVEC_MASK | \
1212      XSTATE_CONTROLFLAG_XFD_MASK)
1213 
1214 #define MAXIMUM_XSTATE_FEATURES             64
1215 
1216 typedef struct _XSTATE_FEATURE {
1217   ULONG Offset;
1218   ULONG Size;
1219 } XSTATE_FEATURE, *PXSTATE_FEATURE;
1220 
1221 typedef struct _XSTATE_CONFIGURATION
1222 {
1223     ULONG64 EnabledFeatures;
1224 #if (NTDDI_VERSION >= NTDDI_WINBLUE)
1225     ULONG64 EnabledVolatileFeatures;
1226 #endif
1227     ULONG Size;
1228     union
1229     {
1230         ULONG ControlFlags;
1231         struct
1232         {
1233             ULONG OptimizedSave:1;
1234             ULONG CompactionEnabled:1; // WIN10+
1235         };
1236     };
1237     XSTATE_FEATURE Features[MAXIMUM_XSTATE_FEATURES];
1238 #if (NTDDI_VERSION >= NTDDI_WIN10)
1239     ULONG64 EnabledSupervisorFeatures;
1240     ULONG64 AlignedFeatures;
1241     ULONG AllFeatureSize;
1242     ULONG AllFeatures[MAXIMUM_XSTATE_FEATURES];
1243 #endif
1244 #if (NTDDI_VERSION >= NTDDI_WIN10_RS5)
1245     ULONG64 EnabledUserVisibleSupervisorFeatures;
1246 #endif
1247 #if (NTDDI_VERSION >= NTDDI_WIN11)
1248     ULONG64 ExtendedFeatureDisableFeatures;
1249     ULONG AllNonLargeFeatureSize;
1250     ULONG Spare;
1251 #endif
1252 } XSTATE_CONFIGURATION, *PXSTATE_CONFIGURATION;
1253 
1254 #define MAX_WOW64_SHARED_ENTRIES 16
1255 
1256 //
1257 // Flags for NXSupportPolicy
1258 //
1259 #if (NTDDI_VERSION >= NTDDI_WINXPSP2)
1260 #define NX_SUPPORT_POLICY_ALWAYSOFF 0
1261 #define NX_SUPPORT_POLICY_ALWAYSON  1
1262 #define NX_SUPPORT_POLICY_OPTIN     2
1263 #define NX_SUPPORT_POLICY_OPTOUT    3
1264 #endif
1265 
1266 //
1267 // Shared Kernel User Data
1268 // Keep in sync with sdk/include/ndk/ketypes.h
1269 //
1270 typedef struct _KUSER_SHARED_DATA
1271 {
1272     ULONG TickCountLowDeprecated;                           // 0x0
1273     ULONG TickCountMultiplier;                              // 0x4
1274     volatile KSYSTEM_TIME InterruptTime;                    // 0x8
1275     volatile KSYSTEM_TIME SystemTime;                       // 0x14
1276     volatile KSYSTEM_TIME TimeZoneBias;                     // 0x20
1277     USHORT ImageNumberLow;                                  // 0x2c
1278     USHORT ImageNumberHigh;                                 // 0x2e
1279     WCHAR NtSystemRoot[260];                                // 0x30
1280     ULONG MaxStackTraceDepth;                               // 0x238
1281     ULONG CryptoExponent;                                   // 0x23c
1282     ULONG TimeZoneId;                                       // 0x240
1283     ULONG LargePageMinimum;                                 // 0x244
1284     ULONG Reserved2[7];                                     // 0x248
1285     NT_PRODUCT_TYPE NtProductType;                          // 0x264
1286     BOOLEAN ProductTypeIsValid;                             // 0x268
1287     ULONG NtMajorVersion;                                   // 0x26c
1288     ULONG NtMinorVersion;                                   // 0x270
1289     BOOLEAN ProcessorFeatures[PROCESSOR_FEATURE_MAX];       // 0x274
1290     ULONG Reserved1;                                        // 0x2b4
1291     ULONG Reserved3;                                        // 0x2b8
1292     volatile ULONG TimeSlip;                                // 0x2bc
1293     ALTERNATIVE_ARCHITECTURE_TYPE AlternativeArchitecture;  // 0x2c0
1294     ULONG AltArchitecturePad[1];                            // 0x2c4
1295     LARGE_INTEGER SystemExpirationDate;                     // 0x2c8
1296     ULONG SuiteMask;                                        // 0x2d0
1297     BOOLEAN KdDebuggerEnabled;                              // 0x2d4
1298 #if (NTDDI_VERSION >= NTDDI_WINXPSP2)
1299     UCHAR NXSupportPolicy;                                  // 0x2d5
1300 #endif
1301     volatile ULONG ActiveConsoleId;                         // 0x2d8
1302     volatile ULONG DismountCount;                           // 0x2dc
1303     ULONG ComPlusPackage;                                   // 0x2e0
1304     ULONG LastSystemRITEventTickCount;                      // 0x2e4
1305     ULONG NumberOfPhysicalPages;                            // 0x2e8
1306     BOOLEAN SafeBootMode;                                   // 0x2ec
1307 #if (NTDDI_VERSION >= NTDDI_WIN7)
1308     union
1309     {
1310         UCHAR TscQpcData;                                   // 0x2ed
1311         struct
1312         {
1313             UCHAR TscQpcEnabled:1;                          // 0x2ed
1314             UCHAR TscQpcSpareFlag:1;                        // 0x2ed
1315             UCHAR TscQpcShift:6;                            // 0x2ed
1316         } DUMMYSTRUCTNAME;
1317     } DUMMYUNIONNAME;
1318     UCHAR TscQpcPad[2];                                     // 0x2ee
1319 #endif
1320 #if (NTDDI_VERSION >= NTDDI_VISTA)
1321     union
1322     {
1323         ULONG SharedDataFlags;                              // 0x2f0
1324         struct
1325         {
1326             ULONG DbgErrorPortPresent:1;                    // 0x2f0
1327             ULONG DbgElevationEnabled:1;                    // 0x2f0
1328             ULONG DbgVirtEnabled:1;                         // 0x2f0
1329             ULONG DbgInstallerDetectEnabled:1;              // 0x2f0
1330             ULONG DbgSystemDllRelocated:1;                  // 0x2f0
1331             ULONG DbgDynProcessorEnabled:1;                 // 0x2f0
1332             ULONG DbgSEHValidationEnabled:1;                // 0x2f0
1333             ULONG SpareBits:25;                             // 0x2f0
1334         } DUMMYSTRUCTNAME2;
1335     } DUMMYUNIONNAME2;
1336 #else
1337     ULONG TraceLogging;
1338 #endif
1339     ULONG DataFlagsPad[1];                                  // 0x2f4
1340     ULONGLONG TestRetInstruction;                           // 0x2f8
1341     ULONG SystemCall;                                       // 0x300
1342     ULONG SystemCallReturn;                                 // 0x304
1343     ULONGLONG SystemCallPad[3];                             // 0x308
1344     union
1345     {
1346         volatile KSYSTEM_TIME TickCount;                    // 0x320
1347         volatile ULONG64 TickCountQuad;                     // 0x320
1348         struct
1349         {
1350             ULONG ReservedTickCountOverlay[3];              // 0x320
1351             ULONG TickCountPad[1];                          // 0x32c
1352         } DUMMYSTRUCTNAME;
1353     } DUMMYUNIONNAME3;
1354     ULONG Cookie;                                           // 0x330
1355 #if (NTDDI_VERSION >= NTDDI_VISTA)
1356     ULONG CookiePad[1];                                     // 0x334
1357     LONGLONG ConsoleSessionForegroundProcessId;             // 0x338
1358 #endif
1359 #if (NTDDI_VERSION >= NTDDI_WS03)
1360     ULONG Wow64SharedInformation[MAX_WOW64_SHARED_ENTRIES]; // 2K3: 0x334 / Vista+: 0x340
1361 #endif
1362 #if (NTDDI_VERSION >= NTDDI_VISTA)
1363 #if (NTDDI_VERSION >= NTDDI_WIN7)
1364     USHORT UserModeGlobalLogger[16];                        // 0x380
1365 #else
1366     USHORT UserModeGlobalLogger[8];                         // 0x380
1367     ULONG HeapTracingPid[2];                                // 0x390
1368     ULONG CritSecTracingPid[2];                             // 0x398
1369 #endif
1370     ULONG ImageFileExecutionOptions;                        // 0x3a0
1371 #if (NTDDI_VERSION >= NTDDI_VISTASP1)
1372     ULONG LangGenerationCount;                              // 0x3a4
1373 #else
1374   /* 4 bytes padding */
1375 #endif
1376     ULONGLONG Reserved5;                                    // 0x3a8
1377     volatile ULONG64 InterruptTimeBias;                     // 0x3b0
1378 #endif // NTDDI_VERSION >= NTDDI_VISTA
1379 #if (NTDDI_VERSION >= NTDDI_WIN7)
1380     volatile ULONG64 TscQpcBias;                            // 0x3b8
1381     volatile ULONG ActiveProcessorCount;                    // 0x3c0
1382     volatile USHORT ActiveGroupCount;                       // 0x3c4
1383     USHORT Reserved4;                                       // 0x3c6
1384     volatile ULONG AitSamplingValue;                        // 0x3c8
1385     volatile ULONG AppCompatFlag;                           // 0x3cc
1386     ULONGLONG SystemDllNativeRelocation;                    // 0x3d0
1387     ULONG SystemDllWowRelocation;                           // 0x3d8
1388     ULONG XStatePad[1];                                     // 0x3dc
1389     XSTATE_CONFIGURATION XState;                            // 0x3e0
1390 #endif
1391 } KUSER_SHARED_DATA, *PKUSER_SHARED_DATA;
1392 
1393 #if (NTDDI_VERSION >= NTDDI_VISTA)
1394 extern NTSYSAPI volatile CCHAR KeNumberProcessors;
1395 #elif (NTDDI_VERSION >= NTDDI_WINXP)
1396 extern NTSYSAPI CCHAR KeNumberProcessors;
1397 #else
1398 extern PCCHAR KeNumberProcessors;
1399 #endif
1400 
1401 $endif (_NTDDK_)
1402 $if (_NTIFS_)
1403 typedef struct _KAPC_STATE {
1404   LIST_ENTRY ApcListHead[MaximumMode];
1405   PKPROCESS Process;
1406   BOOLEAN KernelApcInProgress;
1407   BOOLEAN KernelApcPending;
1408   BOOLEAN UserApcPending;
1409 } KAPC_STATE, *PKAPC_STATE, *RESTRICTED_POINTER PRKAPC_STATE;
1410 
1411 #define KAPC_STATE_ACTUAL_LENGTH (FIELD_OFFSET(KAPC_STATE, UserApcPending) + sizeof(BOOLEAN))
1412 
1413 #define ASSERT_QUEUE(Q) ASSERT(((Q)->Header.Type & KOBJECT_TYPE_MASK) == QueueObject);
1414 
1415 typedef struct _KQUEUE {
1416   DISPATCHER_HEADER Header;
1417   LIST_ENTRY EntryListHead;
1418   volatile ULONG CurrentCount;
1419   ULONG MaximumCount;
1420   LIST_ENTRY ThreadListHead;
1421 } KQUEUE, *PKQUEUE, *RESTRICTED_POINTER PRKQUEUE;
1422 
1423 $endif (_NTIFS_)
1424 
1425