1 #ifndef __NTDDK_EX__H__
2 #define __NTDDK_EX__H__
6 #define ASSERT(x) ((void)0)
7 // #define ASSERT(x) if (!(x)) { RtlAssert("#x",__FILE__,__LINE__, ""); }
10 #ifndef FILE_CHARACTERISTIC_PNP_DEVICE // DDK 2003
11 #define FILE_CHARACTERISTIC_PNP_DEVICE 0x00000800
12 #endif // !FILE_CHARACTERISTIC_PNP_DEVICE
14 typedef enum _SYSTEM_INFORMATION_CLASS
{
15 SystemBasicInformation
,
16 SystemProcessorInformation
,
17 SystemPerformanceInformation
,
18 SystemTimeOfDayInformation
,
19 SystemPathInformation
,
20 SystemProcessInformation
,
21 SystemCallCountInformation
,
22 SystemDeviceInformation
,
23 SystemProcessorPerformanceInformation
,
24 SystemFlagsInformation
,
25 SystemCallTimeInformation
,
26 SystemModuleInformation
,
27 SystemLocksInformation
,
28 SystemStackTraceInformation
,
29 SystemPagedPoolInformation
,
30 SystemNonPagedPoolInformation
,
31 SystemHandleInformation
,
32 SystemObjectInformation
,
33 SystemPageFileInformation
,
34 SystemVdmInstemulInformation
,
35 SystemVdmBopInformation
,
36 SystemFileCacheInformation
,
37 SystemPoolTagInformation
,
38 SystemInterruptInformation
,
39 SystemDpcBehaviorInformation
,
40 SystemFullMemoryInformation
,
41 SystemLoadGdiDriverInformation
,
42 SystemUnloadGdiDriverInformation
,
43 SystemTimeAdjustmentInformation
,
44 SystemSummaryMemoryInformation
,
46 SystemNextEventIdInformation
,
47 SystemEventIdsInformation
,
48 SystemCrashDumpInformation
,
50 SystemMirrorMemoryInformation
,
51 SystemPerformanceTraceInformation
,
54 SystemExceptionInformation
,
55 SystemCrashDumpStateInformation
,
56 SystemKernelDebuggerInformation
,
57 SystemContextSwitchInformation
,
58 SystemRegistryQuotaInformation
,
59 SystemExtendServiceTableInformation
,
60 SystemPrioritySeperation
,
61 SystemPlugPlayBusInformation
,
62 SystemDockInformation
,
64 SystemPowerInformationNative
,
65 #elif defined IRP_MN_START_DEVICE
66 SystemPowerInformationInfo
,
68 SystemPowerInformation
,
70 SystemProcessorSpeedInformation
,
71 SystemCurrentTimeZoneInformation
,
72 SystemLookasideInformation
,
74 SystemTimeSlipNotification
,
77 SystemSessionInformation
,
78 SystemRangeStartInformation
,
79 SystemVerifierInformation
,
81 SystemSessionProcessesInformation
,
82 SystemLoadGdiDriverInSystemSpaceInformation
,
83 SystemNumaProcessorMap
,
84 SystemPrefetcherInformation
,
85 SystemExtendedProcessInformation
,
86 SystemRecommendedSharedDataAlignment
,
88 SystemNumaAvailableMemory
,
89 SystemProcessorPowerInformation
,
90 SystemEmulationBasicInformation
,
91 SystemEmulationProcessorInformation
,
92 SystemExtendedHanfleInformation
,
93 SystemLostDelayedWriteInformation
,
94 SystemBigPoolInformation
,
95 SystemSessionPoolTagInformation
,
96 SystemSessionMappedViewInformation
,
97 SystemHotpatchInformation
,
98 SystemObjectSecurityMode
,
99 SystemWatchDogTimerHandler
,
100 SystemWatchDogTimerInformation
,
101 SystemLogicalProcessorInformation
,
102 SystemWo64SharedInformationObosolete
,
103 SystemRegisterFirmwareTableInformationHandler
,
104 SystemFirmwareTableInformation
,
105 SystemModuleInformationEx
,
106 SystemVerifierTriageInformation
,
107 SystemSuperfetchInformation
,
108 SystemMemoryListInformation
,
109 SystemFileCacheInformationEx
,
110 SystemThreadPriorityClientIdInformation
,
111 SystemProcessorIdleCycleTimeInformation
,
112 SystemVerifierCancellationInformation
,
113 SystemProcessorPowerInformationEx
,
114 SystemRefTraceInformation
,
115 SystemSpecialPoolInformation
,
116 SystemProcessIdInformation
,
117 SystemErrorPortInformation
,
118 SystemBootEnvironmentInformation
,
119 SystemHypervisorInformation
,
120 SystemVerifierInformationEx
,
121 SystemTimeZoneInformation
,
122 SystemImageFileExecutionOptionsInformation
,
123 SystemCoverageInformation
,
124 SystemPrefetchPathInformation
,
125 SystemVerifierFaultsInformation
,
128 } SYSTEM_INFORMATION_CLASS
;
134 ZwQuerySystemInformation(
135 IN SYSTEM_INFORMATION_CLASS SystemInfoClass
,
136 OUT PVOID SystemInfoBuffer
,
137 IN ULONG SystemInfoBufferSize
,
138 OUT PULONG BytesReturned OPTIONAL
144 NtQuerySystemInformation(
145 IN SYSTEM_INFORMATION_CLASS SystemInfoClass
,
146 OUT PVOID SystemInfoBuffer
,
147 IN ULONG SystemInfoBufferSize
,
148 OUT PULONG BytesReturned OPTIONAL
151 typedef struct _SYSTEM_BASIC_INFORMATION
{
153 ULONG TimerResolution
;
155 ULONG NumberOfPhysicalPages
;
156 ULONG LowestPhysicalPageNumber
;
157 ULONG HighestPhysicalPageNumber
;
158 ULONG AllocationGranularity
;
159 ULONG MinimumUserModeAddress
;
160 ULONG MaximumUserModeAddress
;
161 KAFFINITY ActiveProcessorsAffinityMask
;
162 CCHAR NumberOfProcessors
;
163 } SYSTEM_BASIC_INFORMATION
, *PSYSTEM_BASIC_INFORMATION
;
165 typedef struct _SYSTEM_MODULE_ENTRY
169 PVOID ModuleBaseAddress
;
172 ULONG ModuleEntryIndex
;
173 USHORT ModuleNameLength
;
174 USHORT ModuleNameOffset
;
175 CHAR ModuleName
[256];
176 } SYSTEM_MODULE_ENTRY
, * PSYSTEM_MODULE_ENTRY
;
178 typedef struct _SYSTEM_MODULE_INFORMATION
181 SYSTEM_MODULE_ENTRY Module
[1];
182 } SYSTEM_MODULE_INFORMATION
, *PSYSTEM_MODULE_INFORMATION
;
184 typedef unsigned short WORD
;
186 typedef unsigned int BOOL
;
188 typedef unsigned long DWORD
;
189 typedef unsigned char BYTE
;
192 typedef struct _LDR_DATA_TABLE_ENTRY
{
193 LIST_ENTRY LoadOrder
;
194 LIST_ENTRY MemoryOrder
;
195 LIST_ENTRY InitializationOrder
;
196 PVOID ModuleBaseAddress
;
199 UNICODE_STRING FullModuleName
;
200 UNICODE_STRING ModuleName
;
207 PVOID SectionPointer
;
212 } LDR_DATA_TABLE_ENTRY
, *PLDR_DATA_TABLE_ENTRY
;
214 typedef struct _PEB_LDR_DATA
{
218 LIST_ENTRY LoadOrder
;
219 LIST_ENTRY MemoryOrder
;
220 LIST_ENTRY InitializationOrder
;
221 } PEB_LDR_DATA
, *PPEB_LDR_DATA
;
223 typedef struct _PEB_FREE_BLOCK
{
224 struct _PEB_FREE_BLOCK
*Next
;
226 } PEB_FREE_BLOCK
, *PPEB_FREE_BLOCK
;
228 #define GDI_HANDLE_BUFFER_SIZE 34
230 #define TLS_MINIMUM_AVAILABLE 64 // winnt
232 typedef struct _PEB
{
233 BOOLEAN InheritedAddressSpace
; // These four fields cannot change unless the
234 BOOLEAN ReadImageFileExecOptions
; //
235 BOOLEAN BeingDebugged
; //
236 BOOLEAN SpareBool
; //
237 HANDLE Mutant
; // INITIAL_PEB structure is also updated.
239 PVOID ImageBaseAddress
;
241 struct _RTL_USER_PROCESS_PARAMETERS
*ProcessParameters
;
245 PVOID FastPebLockRoutine
;
246 PVOID FastPebUnlockRoutine
;
247 ULONG EnvironmentUpdateCount
;
248 PVOID KernelCallbackTable
;
249 HANDLE EventLogSection
;
251 PPEB_FREE_BLOCK FreeList
;
252 ULONG TlsExpansionCounter
;
254 ULONG TlsBitmapBits
[2]; // relates to TLS_MINIMUM_AVAILABLE
255 PVOID ReadOnlySharedMemoryBase
;
256 PVOID ReadOnlySharedMemoryHeap
;
257 PVOID
*ReadOnlyStaticServerData
;
258 PVOID AnsiCodePageData
;
259 PVOID OemCodePageData
;
260 PVOID UnicodeCaseTableData
;
262 // Useful information for LdrpInitialize
263 ULONG NumberOfProcessors
;
266 // Passed up from MmCreatePeb from Session Manager registry key
268 LARGE_INTEGER CriticalSectionTimeout
;
269 ULONG HeapSegmentReserve
;
270 ULONG HeapSegmentCommit
;
271 ULONG HeapDeCommitTotalFreeThreshold
;
272 ULONG HeapDeCommitFreeBlockThreshold
;
274 // Where heap manager keeps track of all heaps created for a process
275 // Fields initialized by MmCreatePeb. ProcessHeaps is initialized
276 // to point to the first free byte after the PEB and MaximumNumberOfHeaps
277 // is computed from the page size used to hold the PEB, less the fixed
278 // size of this data structure.
281 ULONG MaximumNumberOfHeaps
;
286 PVOID GdiSharedHandleTable
;
287 PVOID ProcessStarterHelper
;
288 PVOID GdiDCAttributeList
;
291 // Following fields filled in by MmCreatePeb from system values and/or
294 ULONG OSMajorVersion
;
295 ULONG OSMinorVersion
;
298 ULONG ImageSubsystem
;
299 ULONG ImageSubsystemMajorVersion
;
300 ULONG ImageSubsystemMinorVersion
;
301 ULONG ImageProcessAffinityMask
;
302 ULONG GdiHandleBuffer
[GDI_HANDLE_BUFFER_SIZE
];
306 // Gdi command batching
309 #define GDI_BATCH_BUFFER_SIZE 310
311 typedef struct _GDI_TEB_BATCH
{
314 ULONG Buffer
[GDI_BATCH_BUFFER_SIZE
];
315 } GDI_TEB_BATCH
,*PGDI_TEB_BATCH
;
318 // TEB - The thread environment block
321 #define STATIC_UNICODE_BUFFER_LENGTH 261
322 #define WIN32_CLIENT_INFO_LENGTH 31
323 #define WIN32_CLIENT_INFO_SPIN_COUNT 1
325 typedef struct _TEB
{
327 PVOID EnvironmentPointer
;
329 PVOID ActiveRpcHandle
;
330 PVOID ThreadLocalStoragePointer
;
331 PPEB ProcessEnvironmentBlock
;
332 ULONG LastErrorValue
;
333 ULONG CountOfOwnedCriticalSections
;
334 PVOID CsrClientThread
;
335 PVOID Win32ThreadInfo
; // PtiCurrent
336 ULONG Win32ClientInfo
[WIN32_CLIENT_INFO_LENGTH
]; // User32 Client Info
337 PVOID WOW32Reserved
; // used by WOW
339 ULONG FpSoftwareStatusRegister
;
340 PVOID SystemReserved1
[54]; // Used by FP emulator
341 PVOID Spare1
; // unused
342 NTSTATUS ExceptionCode
; // for RaiseUserException
343 UCHAR SpareBytes1
[40];
344 PVOID SystemReserved2
[10]; // Used by user/console for temp obja
345 GDI_TEB_BATCH GdiTebBatch
; // Gdi batching
349 CLIENT_ID RealClientId
;
350 HANDLE GdiCachedProcessHandle
;
353 PVOID GdiThreadLocalInfo
;
354 PVOID UserReserved
[5]; // unused
355 PVOID glDispatchTable
[280]; // OpenGL
356 ULONG glReserved1
[26]; // OpenGL
357 PVOID glReserved2
; // OpenGL
358 PVOID glSectionInfo
; // OpenGL
359 PVOID glSection
; // OpenGL
360 PVOID glTable
; // OpenGL
361 PVOID glCurrentRC
; // OpenGL
362 PVOID glContext
; // OpenGL
363 ULONG LastStatusValue
;
364 UNICODE_STRING StaticUnicodeString
;
365 WCHAR StaticUnicodeBuffer
[STATIC_UNICODE_BUFFER_LENGTH
];
366 PVOID DeallocationStack
;
367 PVOID TlsSlots
[TLS_MINIMUM_AVAILABLE
];
370 PVOID ReservedForNtRpc
;
371 PVOID DbgSsReserved
[2];
372 ULONG HardErrorsAreDisabled
;
373 PVOID Instrumentation
[16];
374 PVOID WinSockData
; // WinSock
379 PVOID ReservedForOle
;
380 ULONG WaitingOnLoaderLock
;
384 typedef struct _KTHREAD_HDR
{
387 // The dispatcher header and mutant listhead are faifly infrequently
388 // referenced, but pad the thread to a 32-byte boundary (assumption
389 // that pool allocation is in units of 32-bytes).
392 DISPATCHER_HEADER Header
;
393 LIST_ENTRY MutantListHead
;
396 // The following fields are referenced during trap, interrupts, or
399 // N.B. The Teb address and TlsArray are loaded as a quadword quantity
400 // on MIPS and therefore must to on a quadword boundary.
410 BOOLEAN Alerted
[MaximumMode
];
415 /* KAPC_STATE ApcState;
416 ULONG ContextSwitches;
419 // The following fields are referenced during wait operations.
424 KPROCESSOR_MODE WaitMode;
427 PRKWAIT_BLOCK WaitBlockList;
428 LIST_ENTRY WaitListEntry;
431 UCHAR DecrementCount;
432 SCHAR PriorityDecrement;
434 KWAIT_BLOCK WaitBlock[THREAD_WAIT_OBJECTS + 1];
436 ULONG KernelApcDisable;
437 KAFFINITY UserAffinity;
438 BOOLEAN SystemAffinityActive;
441 // struct _ECHANNEL *Channel;
443 // PCHANNEL_MESSAGE SystemView;
444 // PCHANNEL_MESSAGE ThreadView;
447 // The following fields are referenced during queue operations.
451 KSPIN_LOCK ApcQueueLock;
453 LIST_ENTRY QueueListEntry;
456 // The following fields are referenced during read and find ready
462 BOOLEAN ProcessReadyQueue;
463 BOOLEAN KernelStackResident;
467 // The following fields are referenced suring system calls.
472 PKTRAP_FRAME TrapFrame;
473 PKAPC_STATE ApcStatePointer[2];
474 UCHAR EnableStackSwap;
480 // The following entries are reference during clock interrupts.
487 // The following fileds are referenced during APC queuing and process
491 KAPC_STATE SavedApcState;
494 BOOLEAN ApcQueueable;
495 BOOLEAN AutoAlignment;
498 // The following fields are referenced when the thread is initialized
499 // and very infrequently thereafter.
504 KSEMAPHORE SuspendSemaphore;
505 LIST_ENTRY ThreadListEntry;
508 // N.B. The below four UCHARs share the same DWORD and are modified
509 // by other threads. Therefore, they must ALWAYS be modified
510 // under the dispatcher lock to prevent granularity problems
511 // on Alpha machines.
515 UCHAR IdealProcessor;
518 } KTHREAD_HDR
, *PKTHREAD_HDR
;
521 typedef struct _IMAGE_DOS_HEADER
{ // DOS .EXE header
522 WORD e_magic
; // Magic number
523 WORD e_cblp
; // Bytes on last page of file
524 WORD e_cp
; // Pages in file
525 WORD e_crlc
; // Relocations
526 WORD e_cparhdr
; // Size of header in paragraphs
527 WORD e_minalloc
; // Minimum extra paragraphs needed
528 WORD e_maxalloc
; // Maximum extra paragraphs needed
529 WORD e_ss
; // Initial (relative) SS value
530 WORD e_sp
; // Initial SP value
531 WORD e_csum
; // Checksum
532 WORD e_ip
; // Initial IP value
533 WORD e_cs
; // Initial (relative) CS value
534 WORD e_lfarlc
; // File address of relocation table
535 WORD e_ovno
; // Overlay number
536 WORD e_res
[4]; // Reserved words
537 WORD e_oemid
; // OEM identifier (for e_oeminfo)
538 WORD e_oeminfo
; // OEM information; e_oemid specific
539 WORD e_res2
[10]; // Reserved words
540 LONG e_lfanew
; // File address of new exe header
541 } IMAGE_DOS_HEADER
, *PIMAGE_DOS_HEADER
;
543 typedef struct _IMAGE_FILE_HEADER
{
545 WORD NumberOfSections
;
547 DWORD PointerToSymbolTable
;
548 DWORD NumberOfSymbols
;
549 WORD SizeOfOptionalHeader
;
550 WORD Characteristics
;
551 } IMAGE_FILE_HEADER
, *PIMAGE_FILE_HEADER
;
553 typedef struct _IMAGE_DATA_DIRECTORY
{
554 DWORD VirtualAddress
;
556 } IMAGE_DATA_DIRECTORY
, *PIMAGE_DATA_DIRECTORY
;
557 #define IMAGE_NUMBEROF_DIRECTORY_ENTRIES 16
560 typedef struct _IMAGE_OPTIONAL_HEADER
{
566 BYTE MajorLinkerVersion
;
567 BYTE MinorLinkerVersion
;
569 DWORD SizeOfInitializedData
;
570 DWORD SizeOfUninitializedData
;
571 DWORD AddressOfEntryPoint
;
576 // NT additional fields.
580 DWORD SectionAlignment
;
582 WORD MajorOperatingSystemVersion
;
583 WORD MinorOperatingSystemVersion
;
584 WORD MajorImageVersion
;
585 WORD MinorImageVersion
;
586 WORD MajorSubsystemVersion
;
587 WORD MinorSubsystemVersion
;
588 DWORD Win32VersionValue
;
593 WORD DllCharacteristics
;
594 DWORD SizeOfStackReserve
;
595 DWORD SizeOfStackCommit
;
596 DWORD SizeOfHeapReserve
;
597 DWORD SizeOfHeapCommit
;
599 DWORD NumberOfRvaAndSizes
;
600 IMAGE_DATA_DIRECTORY DataDirectory
[IMAGE_NUMBEROF_DIRECTORY_ENTRIES
];
601 } IMAGE_OPTIONAL_HEADER32
, *PIMAGE_OPTIONAL_HEADER32
;
603 typedef struct _IMAGE_NT_HEADERS
{
605 IMAGE_FILE_HEADER FileHeader
;
606 IMAGE_OPTIONAL_HEADER32 OptionalHeader
;
607 } IMAGE_NT_HEADERS32
, *PIMAGE_NT_HEADERS32
;
608 typedef IMAGE_NT_HEADERS32 IMAGE_NT_HEADERS
;
609 typedef PIMAGE_NT_HEADERS32 PIMAGE_NT_HEADERS
;
611 #define IMAGE_DIRECTORY_ENTRY_EXPORT 0 // Export Directory
613 typedef struct _IMAGE_EXPORT_DIRECTORY
{
614 DWORD Characteristics
;
620 DWORD NumberOfFunctions
;
622 DWORD AddressOfFunctions
; // RVA from base of image
623 DWORD AddressOfNames
; // RVA from base of image
624 DWORD AddressOfNameOrdinals
; // RVA from base of image
625 } IMAGE_EXPORT_DIRECTORY
, *PIMAGE_EXPORT_DIRECTORY
;
638 HalQueryDisplayParameters (
639 OUT PULONG WidthInCharacters
,
640 OUT PULONG HeightInLines
,
641 OUT PULONG CursorColumn
,
648 HalSetDisplayParameters (
649 IN ULONG CursorColumn
,
653 extern ULONG NtBuildNumber
;
655 #endif //__NTDDK_EX__H__