1 #ifndef __NTDDK_EX__H__
2 #define __NTDDK_EX__H__
9 #define ASSERT //(x) if (!(x)) {RtlAssert("#x",__FILE__,__LINE__, ""); }
13 #ifndef FILE_CHARACTERISTIC_PNP_DEVICE // DDK 2003
15 #define FILE_CHARACTERISTIC_PNP_DEVICE 0x00000800
17 typedef enum _SYSTEM_INFORMATION_CLASS
{
18 SystemBasicInformation
,
19 SystemProcessorInformation
,
20 SystemPerformanceInformation
,
21 SystemTimeOfDayInformation
,
22 SystemPathInformation
,
23 SystemProcessInformation
,
24 SystemCallCountInformation
,
25 SystemDeviceInformation
,
26 SystemProcessorPerformanceInformation
,
27 SystemFlagsInformation
,
28 SystemCallTimeInformation
,
29 SystemModuleInformation
,
30 SystemLocksInformation
,
31 SystemStackTraceInformation
,
32 SystemPagedPoolInformation
,
33 SystemNonPagedPoolInformation
,
34 SystemHandleInformation
,
35 SystemObjectInformation
,
36 SystemPageFileInformation
,
37 SystemVdmInstemulInformation
,
38 SystemVdmBopInformation
,
39 SystemFileCacheInformation
,
40 SystemPoolTagInformation
,
41 SystemInterruptInformation
,
42 SystemDpcBehaviorInformation
,
43 SystemFullMemoryInformation
,
44 SystemLoadGdiDriverInformation
,
45 SystemUnloadGdiDriverInformation
,
46 SystemTimeAdjustmentInformation
,
47 SystemSummaryMemoryInformation
,
49 SystemNextEventIdInformation
,
50 SystemEventIdsInformation
,
51 SystemCrashDumpInformation
,
53 SystemMirrorMemoryInformation
,
54 SystemPerformanceTraceInformation
,
57 SystemExceptionInformation
,
58 SystemCrashDumpStateInformation
,
59 SystemKernelDebuggerInformation
,
60 SystemContextSwitchInformation
,
61 SystemRegistryQuotaInformation
,
62 SystemExtendServiceTableInformation
,
63 SystemPrioritySeperation
,
64 SystemPlugPlayBusInformation
,
65 SystemDockInformation
,
67 SystemPowerInformationNative
,
68 #elif defined IRP_MN_START_DEVICE
69 SystemPowerInformationInfo
,
71 SystemPowerInformation
,
73 SystemProcessorSpeedInformation
,
74 SystemCurrentTimeZoneInformation
,
75 SystemLookasideInformation
,
77 SystemTimeSlipNotification
,
80 SystemSessionInformation
,
81 SystemRangeStartInformation
,
82 SystemVerifierInformation
,
84 SystemSessionProcessesInformation
,
85 SystemLoadGdiDriverInSystemSpaceInformation
,
86 SystemNumaProcessorMap
,
87 SystemPrefetcherInformation
,
88 SystemExtendedProcessInformation
,
89 SystemRecommendedSharedDataAlignment
,
91 SystemNumaAvailableMemory
,
92 SystemProcessorPowerInformation
,
93 SystemEmulationBasicInformation
,
94 SystemEmulationProcessorInformation
,
95 SystemExtendedHanfleInformation
,
96 SystemLostDelayedWriteInformation
,
97 SystemBigPoolInformation
,
98 SystemSessionPoolTagInformation
,
99 SystemSessionMappedViewInformation
,
100 SystemHotpatchInformation
,
101 SystemObjectSecurityMode
,
102 SystemWatchDogTimerHandler
,
103 SystemWatchDogTimerInformation
,
104 SystemLogicalProcessorInformation
,
105 SystemWo64SharedInformationObosolete
,
106 SystemRegisterFirmwareTableInformationHandler
,
107 SystemFirmwareTableInformation
,
108 SystemModuleInformationEx
,
109 SystemVerifierTriageInformation
,
110 SystemSuperfetchInformation
,
111 SystemMemoryListInformation
,
112 SystemFileCacheInformationEx
,
113 SystemThreadPriorityClientIdInformation
,
114 SystemProcessorIdleCycleTimeInformation
,
115 SystemVerifierCancellationInformation
,
116 SystemProcessorPowerInformationEx
,
117 SystemRefTraceInformation
,
118 SystemSpecialPoolInformation
,
119 SystemProcessIdInformation
,
120 SystemErrorPortInformation
,
121 SystemBootEnvironmentInformation
,
122 SystemHypervisorInformation
,
123 SystemVerifierInformationEx
,
124 SystemTimeZoneInformation
,
125 SystemImageFileExecutionOptionsInformation
,
126 SystemCoverageInformation
,
127 SystemPrefetchPathInformation
,
128 SystemVerifierFaultsInformation
,
131 } SYSTEM_INFORMATION_CLASS
;
133 #endif // !FILE_CHARACTERISTIC_PNP_DEVICE
139 ZwQuerySystemInformation(
140 IN SYSTEM_INFORMATION_CLASS SystemInfoClass
,
141 OUT PVOID SystemInfoBuffer
,
142 IN ULONG SystemInfoBufferSize
,
143 OUT PULONG BytesReturned OPTIONAL
149 NtQuerySystemInformation(
150 IN SYSTEM_INFORMATION_CLASS SystemInfoClass
,
151 OUT PVOID SystemInfoBuffer
,
152 IN ULONG SystemInfoBufferSize
,
153 OUT PULONG BytesReturned OPTIONAL
156 typedef struct _SYSTEM_BASIC_INFORMATION
{
158 ULONG TimerResolution
;
160 ULONG NumberOfPhysicalPages
;
161 ULONG LowestPhysicalPageNumber
;
162 ULONG HighestPhysicalPageNumber
;
163 ULONG AllocationGranularity
;
164 ULONG MinimumUserModeAddress
;
165 ULONG MaximumUserModeAddress
;
166 KAFFINITY ActiveProcessorsAffinityMask
;
167 CCHAR NumberOfProcessors
;
168 } SYSTEM_BASIC_INFORMATION
, *PSYSTEM_BASIC_INFORMATION
;
170 typedef struct _SYSTEM_MODULE_ENTRY
174 PVOID ModuleBaseAddress
;
177 ULONG ModuleEntryIndex
;
178 USHORT ModuleNameLength
;
179 USHORT ModuleNameOffset
;
180 CHAR ModuleName
[256];
181 } SYSTEM_MODULE_ENTRY
, * PSYSTEM_MODULE_ENTRY
;
183 typedef struct _SYSTEM_MODULE_INFORMATION
186 SYSTEM_MODULE_ENTRY Module
[1];
187 } SYSTEM_MODULE_INFORMATION
, *PSYSTEM_MODULE_INFORMATION
;
189 typedef unsigned short WORD
;
191 typedef unsigned int BOOL
;
193 typedef unsigned long DWORD
;
194 typedef unsigned char BYTE
;
197 typedef struct _LDR_DATA_TABLE_ENTRY
{
198 LIST_ENTRY LoadOrder
;
199 LIST_ENTRY MemoryOrder
;
200 LIST_ENTRY InitializationOrder
;
201 PVOID ModuleBaseAddress
;
204 UNICODE_STRING FullModuleName
;
205 UNICODE_STRING ModuleName
;
212 PVOID SectionPointer
;
217 } LDR_DATA_TABLE_ENTRY
, *PLDR_DATA_TABLE_ENTRY
;
219 typedef struct _PEB_LDR_DATA
{
223 LIST_ENTRY LoadOrder
;
224 LIST_ENTRY MemoryOrder
;
225 LIST_ENTRY InitializationOrder
;
226 } PEB_LDR_DATA
, *PPEB_LDR_DATA
;
228 typedef struct _PEB_FREE_BLOCK
{
229 struct _PEB_FREE_BLOCK
*Next
;
231 } PEB_FREE_BLOCK
, *PPEB_FREE_BLOCK
;
233 #define GDI_HANDLE_BUFFER_SIZE 34
235 #define TLS_MINIMUM_AVAILABLE 64 // winnt
237 typedef struct _PEB
{
238 BOOLEAN InheritedAddressSpace
; // These four fields cannot change unless the
239 BOOLEAN ReadImageFileExecOptions
; //
240 BOOLEAN BeingDebugged
; //
241 BOOLEAN SpareBool
; //
242 HANDLE Mutant
; // INITIAL_PEB structure is also updated.
244 PVOID ImageBaseAddress
;
246 struct _RTL_USER_PROCESS_PARAMETERS
*ProcessParameters
;
250 PVOID FastPebLockRoutine
;
251 PVOID FastPebUnlockRoutine
;
252 ULONG EnvironmentUpdateCount
;
253 PVOID KernelCallbackTable
;
254 HANDLE EventLogSection
;
256 PPEB_FREE_BLOCK FreeList
;
257 ULONG TlsExpansionCounter
;
259 ULONG TlsBitmapBits
[2]; // relates to TLS_MINIMUM_AVAILABLE
260 PVOID ReadOnlySharedMemoryBase
;
261 PVOID ReadOnlySharedMemoryHeap
;
262 PVOID
*ReadOnlyStaticServerData
;
263 PVOID AnsiCodePageData
;
264 PVOID OemCodePageData
;
265 PVOID UnicodeCaseTableData
;
267 // Useful information for LdrpInitialize
268 ULONG NumberOfProcessors
;
271 // Passed up from MmCreatePeb from Session Manager registry key
273 LARGE_INTEGER CriticalSectionTimeout
;
274 ULONG HeapSegmentReserve
;
275 ULONG HeapSegmentCommit
;
276 ULONG HeapDeCommitTotalFreeThreshold
;
277 ULONG HeapDeCommitFreeBlockThreshold
;
279 // Where heap manager keeps track of all heaps created for a process
280 // Fields initialized by MmCreatePeb. ProcessHeaps is initialized
281 // to point to the first free byte after the PEB and MaximumNumberOfHeaps
282 // is computed from the page size used to hold the PEB, less the fixed
283 // size of this data structure.
286 ULONG MaximumNumberOfHeaps
;
291 PVOID GdiSharedHandleTable
;
292 PVOID ProcessStarterHelper
;
293 PVOID GdiDCAttributeList
;
296 // Following fields filled in by MmCreatePeb from system values and/or
299 ULONG OSMajorVersion
;
300 ULONG OSMinorVersion
;
303 ULONG ImageSubsystem
;
304 ULONG ImageSubsystemMajorVersion
;
305 ULONG ImageSubsystemMinorVersion
;
306 ULONG ImageProcessAffinityMask
;
307 ULONG GdiHandleBuffer
[GDI_HANDLE_BUFFER_SIZE
];
311 // Gdi command batching
314 #define GDI_BATCH_BUFFER_SIZE 310
316 typedef struct _GDI_TEB_BATCH
{
319 ULONG Buffer
[GDI_BATCH_BUFFER_SIZE
];
320 } GDI_TEB_BATCH
,*PGDI_TEB_BATCH
;
323 // TEB - The thread environment block
326 #define STATIC_UNICODE_BUFFER_LENGTH 261
327 #define WIN32_CLIENT_INFO_LENGTH 31
328 #define WIN32_CLIENT_INFO_SPIN_COUNT 1
330 typedef struct _TEB
{
332 PVOID EnvironmentPointer
;
334 PVOID ActiveRpcHandle
;
335 PVOID ThreadLocalStoragePointer
;
336 PPEB ProcessEnvironmentBlock
;
337 ULONG LastErrorValue
;
338 ULONG CountOfOwnedCriticalSections
;
339 PVOID CsrClientThread
;
340 PVOID Win32ThreadInfo
; // PtiCurrent
341 ULONG Win32ClientInfo
[WIN32_CLIENT_INFO_LENGTH
]; // User32 Client Info
342 PVOID WOW32Reserved
; // used by WOW
344 ULONG FpSoftwareStatusRegister
;
345 PVOID SystemReserved1
[54]; // Used by FP emulator
346 PVOID Spare1
; // unused
347 NTSTATUS ExceptionCode
; // for RaiseUserException
348 UCHAR SpareBytes1
[40];
349 PVOID SystemReserved2
[10]; // Used by user/console for temp obja
350 GDI_TEB_BATCH GdiTebBatch
; // Gdi batching
354 CLIENT_ID RealClientId
;
355 HANDLE GdiCachedProcessHandle
;
358 PVOID GdiThreadLocalInfo
;
359 PVOID UserReserved
[5]; // unused
360 PVOID glDispatchTable
[280]; // OpenGL
361 ULONG glReserved1
[26]; // OpenGL
362 PVOID glReserved2
; // OpenGL
363 PVOID glSectionInfo
; // OpenGL
364 PVOID glSection
; // OpenGL
365 PVOID glTable
; // OpenGL
366 PVOID glCurrentRC
; // OpenGL
367 PVOID glContext
; // OpenGL
368 ULONG LastStatusValue
;
369 UNICODE_STRING StaticUnicodeString
;
370 WCHAR StaticUnicodeBuffer
[STATIC_UNICODE_BUFFER_LENGTH
];
371 PVOID DeallocationStack
;
372 PVOID TlsSlots
[TLS_MINIMUM_AVAILABLE
];
375 PVOID ReservedForNtRpc
;
376 PVOID DbgSsReserved
[2];
377 ULONG HardErrorsAreDisabled
;
378 PVOID Instrumentation
[16];
379 PVOID WinSockData
; // WinSock
384 PVOID ReservedForOle
;
385 ULONG WaitingOnLoaderLock
;
389 typedef struct _KTHREAD_HDR
{
392 // The dispatcher header and mutant listhead are faifly infrequently
393 // referenced, but pad the thread to a 32-byte boundary (assumption
394 // that pool allocation is in units of 32-bytes).
397 DISPATCHER_HEADER Header
;
398 LIST_ENTRY MutantListHead
;
401 // The following fields are referenced during trap, interrupts, or
404 // N.B. The Teb address and TlsArray are loaded as a quadword quantity
405 // on MIPS and therefore must to on a quadword boundary.
415 BOOLEAN Alerted
[MaximumMode
];
420 /* KAPC_STATE ApcState;
421 ULONG ContextSwitches;
424 // The following fields are referenced during wait operations.
429 KPROCESSOR_MODE WaitMode;
432 PRKWAIT_BLOCK WaitBlockList;
433 LIST_ENTRY WaitListEntry;
436 UCHAR DecrementCount;
437 SCHAR PriorityDecrement;
439 KWAIT_BLOCK WaitBlock[THREAD_WAIT_OBJECTS + 1];
441 ULONG KernelApcDisable;
442 KAFFINITY UserAffinity;
443 BOOLEAN SystemAffinityActive;
446 // struct _ECHANNEL *Channel;
448 // PCHANNEL_MESSAGE SystemView;
449 // PCHANNEL_MESSAGE ThreadView;
452 // The following fields are referenced during queue operations.
456 KSPIN_LOCK ApcQueueLock;
458 LIST_ENTRY QueueListEntry;
461 // The following fields are referenced during read and find ready
467 BOOLEAN ProcessReadyQueue;
468 BOOLEAN KernelStackResident;
472 // The following fields are referenced suring system calls.
477 PKTRAP_FRAME TrapFrame;
478 PKAPC_STATE ApcStatePointer[2];
479 UCHAR EnableStackSwap;
485 // The following entries are reference during clock interrupts.
492 // The following fileds are referenced during APC queuing and process
496 KAPC_STATE SavedApcState;
499 BOOLEAN ApcQueueable;
500 BOOLEAN AutoAlignment;
503 // The following fields are referenced when the thread is initialized
504 // and very infrequently thereafter.
509 KSEMAPHORE SuspendSemaphore;
510 LIST_ENTRY ThreadListEntry;
513 // N.B. The below four UCHARs share the same DWORD and are modified
514 // by other threads. Therefore, they must ALWAYS be modified
515 // under the dispatcher lock to prevent granularity problems
516 // on Alpha machines.
520 UCHAR IdealProcessor;
523 } KTHREAD_HDR
, *PKTHREAD_HDR
;
526 typedef struct _IMAGE_DOS_HEADER
{ // DOS .EXE header
527 WORD e_magic
; // Magic number
528 WORD e_cblp
; // Bytes on last page of file
529 WORD e_cp
; // Pages in file
530 WORD e_crlc
; // Relocations
531 WORD e_cparhdr
; // Size of header in paragraphs
532 WORD e_minalloc
; // Minimum extra paragraphs needed
533 WORD e_maxalloc
; // Maximum extra paragraphs needed
534 WORD e_ss
; // Initial (relative) SS value
535 WORD e_sp
; // Initial SP value
536 WORD e_csum
; // Checksum
537 WORD e_ip
; // Initial IP value
538 WORD e_cs
; // Initial (relative) CS value
539 WORD e_lfarlc
; // File address of relocation table
540 WORD e_ovno
; // Overlay number
541 WORD e_res
[4]; // Reserved words
542 WORD e_oemid
; // OEM identifier (for e_oeminfo)
543 WORD e_oeminfo
; // OEM information; e_oemid specific
544 WORD e_res2
[10]; // Reserved words
545 LONG e_lfanew
; // File address of new exe header
546 } IMAGE_DOS_HEADER
, *PIMAGE_DOS_HEADER
;
548 typedef struct _IMAGE_FILE_HEADER
{
550 WORD NumberOfSections
;
552 DWORD PointerToSymbolTable
;
553 DWORD NumberOfSymbols
;
554 WORD SizeOfOptionalHeader
;
555 WORD Characteristics
;
556 } IMAGE_FILE_HEADER
, *PIMAGE_FILE_HEADER
;
558 typedef struct _IMAGE_DATA_DIRECTORY
{
559 DWORD VirtualAddress
;
561 } IMAGE_DATA_DIRECTORY
, *PIMAGE_DATA_DIRECTORY
;
562 #define IMAGE_NUMBEROF_DIRECTORY_ENTRIES 16
565 typedef struct _IMAGE_OPTIONAL_HEADER
{
571 BYTE MajorLinkerVersion
;
572 BYTE MinorLinkerVersion
;
574 DWORD SizeOfInitializedData
;
575 DWORD SizeOfUninitializedData
;
576 DWORD AddressOfEntryPoint
;
581 // NT additional fields.
585 DWORD SectionAlignment
;
587 WORD MajorOperatingSystemVersion
;
588 WORD MinorOperatingSystemVersion
;
589 WORD MajorImageVersion
;
590 WORD MinorImageVersion
;
591 WORD MajorSubsystemVersion
;
592 WORD MinorSubsystemVersion
;
593 DWORD Win32VersionValue
;
598 WORD DllCharacteristics
;
599 DWORD SizeOfStackReserve
;
600 DWORD SizeOfStackCommit
;
601 DWORD SizeOfHeapReserve
;
602 DWORD SizeOfHeapCommit
;
604 DWORD NumberOfRvaAndSizes
;
605 IMAGE_DATA_DIRECTORY DataDirectory
[IMAGE_NUMBEROF_DIRECTORY_ENTRIES
];
606 } IMAGE_OPTIONAL_HEADER32
, *PIMAGE_OPTIONAL_HEADER32
;
608 typedef struct _IMAGE_NT_HEADERS
{
610 IMAGE_FILE_HEADER FileHeader
;
611 IMAGE_OPTIONAL_HEADER32 OptionalHeader
;
612 } IMAGE_NT_HEADERS32
, *PIMAGE_NT_HEADERS32
;
613 typedef IMAGE_NT_HEADERS32 IMAGE_NT_HEADERS
;
614 typedef PIMAGE_NT_HEADERS32 PIMAGE_NT_HEADERS
;
616 #define IMAGE_DIRECTORY_ENTRY_EXPORT 0 // Export Directory
618 typedef struct _IMAGE_EXPORT_DIRECTORY
{
619 DWORD Characteristics
;
625 DWORD NumberOfFunctions
;
627 DWORD AddressOfFunctions
; // RVA from base of image
628 DWORD AddressOfNames
; // RVA from base of image
629 DWORD AddressOfNameOrdinals
; // RVA from base of image
630 } IMAGE_EXPORT_DIRECTORY
, *PIMAGE_EXPORT_DIRECTORY
;
641 HalQueryDisplayParameters (
642 OUT PULONG WidthInCharacters
,
643 OUT PULONG HeightInLines
,
644 OUT PULONG CursorColumn
,
650 HalSetDisplayParameters (
651 IN ULONG CursorColumn
,
655 extern ULONG NtBuildNumber
;
657 #endif //__NTDDK_EX__H__