1 #ifndef __NTDDK_EX__H__
2 #define __NTDDK_EX__H__
9 //#define ASSERT //(x) if (!(x)) {RtlAssert("#x",__FILE__,__LINE__, ""); }
10 #define ASSERT(x) // FIXME: WTF!
14 #ifndef FILE_CHARACTERISTIC_PNP_DEVICE // DDK 2003
16 #define FILE_CHARACTERISTIC_PNP_DEVICE 0x00000800
18 typedef enum _SYSTEM_INFORMATION_CLASS
{
19 SystemBasicInformation
,
20 SystemProcessorInformation
,
21 SystemPerformanceInformation
,
22 SystemTimeOfDayInformation
,
23 SystemPathInformation
,
24 SystemProcessInformation
,
25 SystemCallCountInformation
,
26 SystemDeviceInformation
,
27 SystemProcessorPerformanceInformation
,
28 SystemFlagsInformation
,
29 SystemCallTimeInformation
,
30 SystemModuleInformation
,
31 SystemLocksInformation
,
32 SystemStackTraceInformation
,
33 SystemPagedPoolInformation
,
34 SystemNonPagedPoolInformation
,
35 SystemHandleInformation
,
36 SystemObjectInformation
,
37 SystemPageFileInformation
,
38 SystemVdmInstemulInformation
,
39 SystemVdmBopInformation
,
40 SystemFileCacheInformation
,
41 SystemPoolTagInformation
,
42 SystemInterruptInformation
,
43 SystemDpcBehaviorInformation
,
44 SystemFullMemoryInformation
,
45 SystemLoadGdiDriverInformation
,
46 SystemUnloadGdiDriverInformation
,
47 SystemTimeAdjustmentInformation
,
48 SystemSummaryMemoryInformation
,
50 SystemNextEventIdInformation
,
51 SystemEventIdsInformation
,
52 SystemCrashDumpInformation
,
54 SystemMirrorMemoryInformation
,
55 SystemPerformanceTraceInformation
,
58 SystemExceptionInformation
,
59 SystemCrashDumpStateInformation
,
60 SystemKernelDebuggerInformation
,
61 SystemContextSwitchInformation
,
62 SystemRegistryQuotaInformation
,
63 SystemExtendServiceTableInformation
,
64 SystemPrioritySeperation
,
65 SystemPlugPlayBusInformation
,
66 SystemDockInformation
,
68 SystemPowerInformationNative
,
69 #elif defined IRP_MN_START_DEVICE
70 SystemPowerInformationInfo
,
72 SystemPowerInformation
,
74 SystemProcessorSpeedInformation
,
75 SystemCurrentTimeZoneInformation
,
76 SystemLookasideInformation
,
78 SystemTimeSlipNotification
,
81 SystemSessionInformation
,
82 SystemRangeStartInformation
,
83 SystemVerifierInformation
,
85 SystemSessionProcessesInformation
,
86 SystemLoadGdiDriverInSystemSpaceInformation
,
87 SystemNumaProcessorMap
,
88 SystemPrefetcherInformation
,
89 SystemExtendedProcessInformation
,
90 SystemRecommendedSharedDataAlignment
,
92 SystemNumaAvailableMemory
,
93 SystemProcessorPowerInformation
,
94 SystemEmulationBasicInformation
,
95 SystemEmulationProcessorInformation
,
96 SystemExtendedHanfleInformation
,
97 SystemLostDelayedWriteInformation
,
98 SystemBigPoolInformation
,
99 SystemSessionPoolTagInformation
,
100 SystemSessionMappedViewInformation
,
101 SystemHotpatchInformation
,
102 SystemObjectSecurityMode
,
103 SystemWatchDogTimerHandler
,
104 SystemWatchDogTimerInformation
,
105 SystemLogicalProcessorInformation
,
106 SystemWo64SharedInformationObosolete
,
107 SystemRegisterFirmwareTableInformationHandler
,
108 SystemFirmwareTableInformation
,
109 SystemModuleInformationEx
,
110 SystemVerifierTriageInformation
,
111 SystemSuperfetchInformation
,
112 SystemMemoryListInformation
,
113 SystemFileCacheInformationEx
,
114 SystemThreadPriorityClientIdInformation
,
115 SystemProcessorIdleCycleTimeInformation
,
116 SystemVerifierCancellationInformation
,
117 SystemProcessorPowerInformationEx
,
118 SystemRefTraceInformation
,
119 SystemSpecialPoolInformation
,
120 SystemProcessIdInformation
,
121 SystemErrorPortInformation
,
122 SystemBootEnvironmentInformation
,
123 SystemHypervisorInformation
,
124 SystemVerifierInformationEx
,
125 SystemTimeZoneInformation
,
126 SystemImageFileExecutionOptionsInformation
,
127 SystemCoverageInformation
,
128 SystemPrefetchPathInformation
,
129 SystemVerifierFaultsInformation
,
132 } SYSTEM_INFORMATION_CLASS
;
134 #endif // !FILE_CHARACTERISTIC_PNP_DEVICE
140 ZwQuerySystemInformation(
141 IN SYSTEM_INFORMATION_CLASS SystemInfoClass
,
142 OUT PVOID SystemInfoBuffer
,
143 IN ULONG SystemInfoBufferSize
,
144 OUT PULONG BytesReturned OPTIONAL
150 NtQuerySystemInformation(
151 IN SYSTEM_INFORMATION_CLASS SystemInfoClass
,
152 OUT PVOID SystemInfoBuffer
,
153 IN ULONG SystemInfoBufferSize
,
154 OUT PULONG BytesReturned OPTIONAL
157 typedef struct _SYSTEM_BASIC_INFORMATION
{
159 ULONG TimerResolution
;
161 ULONG NumberOfPhysicalPages
;
162 ULONG LowestPhysicalPageNumber
;
163 ULONG HighestPhysicalPageNumber
;
164 ULONG AllocationGranularity
;
165 ULONG MinimumUserModeAddress
;
166 ULONG MaximumUserModeAddress
;
167 KAFFINITY ActiveProcessorsAffinityMask
;
168 CCHAR NumberOfProcessors
;
169 } SYSTEM_BASIC_INFORMATION
, *PSYSTEM_BASIC_INFORMATION
;
171 typedef struct _SYSTEM_MODULE_ENTRY
175 PVOID ModuleBaseAddress
;
178 ULONG ModuleEntryIndex
;
179 USHORT ModuleNameLength
;
180 USHORT ModuleNameOffset
;
181 CHAR ModuleName
[256];
182 } SYSTEM_MODULE_ENTRY
, * PSYSTEM_MODULE_ENTRY
;
184 typedef struct _SYSTEM_MODULE_INFORMATION
187 SYSTEM_MODULE_ENTRY Module
[1];
188 } SYSTEM_MODULE_INFORMATION
, *PSYSTEM_MODULE_INFORMATION
;
190 typedef unsigned short WORD
;
192 typedef unsigned int BOOL
;
194 typedef unsigned long DWORD
;
195 typedef unsigned char BYTE
;
198 typedef struct _LDR_DATA_TABLE_ENTRY
{
199 LIST_ENTRY LoadOrder
;
200 LIST_ENTRY MemoryOrder
;
201 LIST_ENTRY InitializationOrder
;
202 PVOID ModuleBaseAddress
;
205 UNICODE_STRING FullModuleName
;
206 UNICODE_STRING ModuleName
;
213 PVOID SectionPointer
;
218 } LDR_DATA_TABLE_ENTRY
, *PLDR_DATA_TABLE_ENTRY
;
220 typedef struct _PEB_LDR_DATA
{
224 LIST_ENTRY LoadOrder
;
225 LIST_ENTRY MemoryOrder
;
226 LIST_ENTRY InitializationOrder
;
227 } PEB_LDR_DATA
, *PPEB_LDR_DATA
;
229 typedef struct _PEB_FREE_BLOCK
{
230 struct _PEB_FREE_BLOCK
*Next
;
232 } PEB_FREE_BLOCK
, *PPEB_FREE_BLOCK
;
234 #define GDI_HANDLE_BUFFER_SIZE 34
236 #define TLS_MINIMUM_AVAILABLE 64 // winnt
238 typedef struct _PEB
{
239 BOOLEAN InheritedAddressSpace
; // These four fields cannot change unless the
240 BOOLEAN ReadImageFileExecOptions
; //
241 BOOLEAN BeingDebugged
; //
242 BOOLEAN SpareBool
; //
243 HANDLE Mutant
; // INITIAL_PEB structure is also updated.
245 PVOID ImageBaseAddress
;
247 struct _RTL_USER_PROCESS_PARAMETERS
*ProcessParameters
;
251 PVOID FastPebLockRoutine
;
252 PVOID FastPebUnlockRoutine
;
253 ULONG EnvironmentUpdateCount
;
254 PVOID KernelCallbackTable
;
255 HANDLE EventLogSection
;
257 PPEB_FREE_BLOCK FreeList
;
258 ULONG TlsExpansionCounter
;
260 ULONG TlsBitmapBits
[2]; // relates to TLS_MINIMUM_AVAILABLE
261 PVOID ReadOnlySharedMemoryBase
;
262 PVOID ReadOnlySharedMemoryHeap
;
263 PVOID
*ReadOnlyStaticServerData
;
264 PVOID AnsiCodePageData
;
265 PVOID OemCodePageData
;
266 PVOID UnicodeCaseTableData
;
268 // Useful information for LdrpInitialize
269 ULONG NumberOfProcessors
;
272 // Passed up from MmCreatePeb from Session Manager registry key
274 LARGE_INTEGER CriticalSectionTimeout
;
275 ULONG HeapSegmentReserve
;
276 ULONG HeapSegmentCommit
;
277 ULONG HeapDeCommitTotalFreeThreshold
;
278 ULONG HeapDeCommitFreeBlockThreshold
;
280 // Where heap manager keeps track of all heaps created for a process
281 // Fields initialized by MmCreatePeb. ProcessHeaps is initialized
282 // to point to the first free byte after the PEB and MaximumNumberOfHeaps
283 // is computed from the page size used to hold the PEB, less the fixed
284 // size of this data structure.
287 ULONG MaximumNumberOfHeaps
;
292 PVOID GdiSharedHandleTable
;
293 PVOID ProcessStarterHelper
;
294 PVOID GdiDCAttributeList
;
297 // Following fields filled in by MmCreatePeb from system values and/or
300 ULONG OSMajorVersion
;
301 ULONG OSMinorVersion
;
304 ULONG ImageSubsystem
;
305 ULONG ImageSubsystemMajorVersion
;
306 ULONG ImageSubsystemMinorVersion
;
307 ULONG ImageProcessAffinityMask
;
308 ULONG GdiHandleBuffer
[GDI_HANDLE_BUFFER_SIZE
];
312 // Gdi command batching
315 #define GDI_BATCH_BUFFER_SIZE 310
317 typedef struct _GDI_TEB_BATCH
{
320 ULONG Buffer
[GDI_BATCH_BUFFER_SIZE
];
321 } GDI_TEB_BATCH
,*PGDI_TEB_BATCH
;
324 // TEB - The thread environment block
327 #define STATIC_UNICODE_BUFFER_LENGTH 261
328 #define WIN32_CLIENT_INFO_LENGTH 31
329 #define WIN32_CLIENT_INFO_SPIN_COUNT 1
331 typedef struct _TEB
{
333 PVOID EnvironmentPointer
;
335 PVOID ActiveRpcHandle
;
336 PVOID ThreadLocalStoragePointer
;
337 PPEB ProcessEnvironmentBlock
;
338 ULONG LastErrorValue
;
339 ULONG CountOfOwnedCriticalSections
;
340 PVOID CsrClientThread
;
341 PVOID Win32ThreadInfo
; // PtiCurrent
342 ULONG Win32ClientInfo
[WIN32_CLIENT_INFO_LENGTH
]; // User32 Client Info
343 PVOID WOW32Reserved
; // used by WOW
345 ULONG FpSoftwareStatusRegister
;
346 PVOID SystemReserved1
[54]; // Used by FP emulator
347 PVOID Spare1
; // unused
348 NTSTATUS ExceptionCode
; // for RaiseUserException
349 UCHAR SpareBytes1
[40];
350 PVOID SystemReserved2
[10]; // Used by user/console for temp obja
351 GDI_TEB_BATCH GdiTebBatch
; // Gdi batching
355 CLIENT_ID RealClientId
;
356 HANDLE GdiCachedProcessHandle
;
359 PVOID GdiThreadLocalInfo
;
360 PVOID UserReserved
[5]; // unused
361 PVOID glDispatchTable
[280]; // OpenGL
362 ULONG glReserved1
[26]; // OpenGL
363 PVOID glReserved2
; // OpenGL
364 PVOID glSectionInfo
; // OpenGL
365 PVOID glSection
; // OpenGL
366 PVOID glTable
; // OpenGL
367 PVOID glCurrentRC
; // OpenGL
368 PVOID glContext
; // OpenGL
369 ULONG LastStatusValue
;
370 UNICODE_STRING StaticUnicodeString
;
371 WCHAR StaticUnicodeBuffer
[STATIC_UNICODE_BUFFER_LENGTH
];
372 PVOID DeallocationStack
;
373 PVOID TlsSlots
[TLS_MINIMUM_AVAILABLE
];
376 PVOID ReservedForNtRpc
;
377 PVOID DbgSsReserved
[2];
378 ULONG HardErrorsAreDisabled
;
379 PVOID Instrumentation
[16];
380 PVOID WinSockData
; // WinSock
385 PVOID ReservedForOle
;
386 ULONG WaitingOnLoaderLock
;
390 typedef struct _KTHREAD_HDR
{
393 // The dispatcher header and mutant listhead are faifly infrequently
394 // referenced, but pad the thread to a 32-byte boundary (assumption
395 // that pool allocation is in units of 32-bytes).
398 DISPATCHER_HEADER Header
;
399 LIST_ENTRY MutantListHead
;
402 // The following fields are referenced during trap, interrupts, or
405 // N.B. The Teb address and TlsArray are loaded as a quadword quantity
406 // on MIPS and therefore must to on a quadword boundary.
416 BOOLEAN Alerted
[MaximumMode
];
421 /* KAPC_STATE ApcState;
422 ULONG ContextSwitches;
425 // The following fields are referenced during wait operations.
430 KPROCESSOR_MODE WaitMode;
433 PRKWAIT_BLOCK WaitBlockList;
434 LIST_ENTRY WaitListEntry;
437 UCHAR DecrementCount;
438 SCHAR PriorityDecrement;
440 KWAIT_BLOCK WaitBlock[THREAD_WAIT_OBJECTS + 1];
442 ULONG KernelApcDisable;
443 KAFFINITY UserAffinity;
444 BOOLEAN SystemAffinityActive;
447 // struct _ECHANNEL *Channel;
449 // PCHANNEL_MESSAGE SystemView;
450 // PCHANNEL_MESSAGE ThreadView;
453 // The following fields are referenced during queue operations.
457 KSPIN_LOCK ApcQueueLock;
459 LIST_ENTRY QueueListEntry;
462 // The following fields are referenced during read and find ready
468 BOOLEAN ProcessReadyQueue;
469 BOOLEAN KernelStackResident;
473 // The following fields are referenced suring system calls.
478 PKTRAP_FRAME TrapFrame;
479 PKAPC_STATE ApcStatePointer[2];
480 UCHAR EnableStackSwap;
486 // The following entries are reference during clock interrupts.
493 // The following fileds are referenced during APC queuing and process
497 KAPC_STATE SavedApcState;
500 BOOLEAN ApcQueueable;
501 BOOLEAN AutoAlignment;
504 // The following fields are referenced when the thread is initialized
505 // and very infrequently thereafter.
510 KSEMAPHORE SuspendSemaphore;
511 LIST_ENTRY ThreadListEntry;
514 // N.B. The below four UCHARs share the same DWORD and are modified
515 // by other threads. Therefore, they must ALWAYS be modified
516 // under the dispatcher lock to prevent granularity problems
517 // on Alpha machines.
521 UCHAR IdealProcessor;
524 } KTHREAD_HDR
, *PKTHREAD_HDR
;
527 typedef struct _IMAGE_DOS_HEADER
{ // DOS .EXE header
528 WORD e_magic
; // Magic number
529 WORD e_cblp
; // Bytes on last page of file
530 WORD e_cp
; // Pages in file
531 WORD e_crlc
; // Relocations
532 WORD e_cparhdr
; // Size of header in paragraphs
533 WORD e_minalloc
; // Minimum extra paragraphs needed
534 WORD e_maxalloc
; // Maximum extra paragraphs needed
535 WORD e_ss
; // Initial (relative) SS value
536 WORD e_sp
; // Initial SP value
537 WORD e_csum
; // Checksum
538 WORD e_ip
; // Initial IP value
539 WORD e_cs
; // Initial (relative) CS value
540 WORD e_lfarlc
; // File address of relocation table
541 WORD e_ovno
; // Overlay number
542 WORD e_res
[4]; // Reserved words
543 WORD e_oemid
; // OEM identifier (for e_oeminfo)
544 WORD e_oeminfo
; // OEM information; e_oemid specific
545 WORD e_res2
[10]; // Reserved words
546 LONG e_lfanew
; // File address of new exe header
547 } IMAGE_DOS_HEADER
, *PIMAGE_DOS_HEADER
;
549 typedef struct _IMAGE_FILE_HEADER
{
551 WORD NumberOfSections
;
553 DWORD PointerToSymbolTable
;
554 DWORD NumberOfSymbols
;
555 WORD SizeOfOptionalHeader
;
556 WORD Characteristics
;
557 } IMAGE_FILE_HEADER
, *PIMAGE_FILE_HEADER
;
559 typedef struct _IMAGE_DATA_DIRECTORY
{
560 DWORD VirtualAddress
;
562 } IMAGE_DATA_DIRECTORY
, *PIMAGE_DATA_DIRECTORY
;
563 #define IMAGE_NUMBEROF_DIRECTORY_ENTRIES 16
566 typedef struct _IMAGE_OPTIONAL_HEADER
{
572 BYTE MajorLinkerVersion
;
573 BYTE MinorLinkerVersion
;
575 DWORD SizeOfInitializedData
;
576 DWORD SizeOfUninitializedData
;
577 DWORD AddressOfEntryPoint
;
582 // NT additional fields.
586 DWORD SectionAlignment
;
588 WORD MajorOperatingSystemVersion
;
589 WORD MinorOperatingSystemVersion
;
590 WORD MajorImageVersion
;
591 WORD MinorImageVersion
;
592 WORD MajorSubsystemVersion
;
593 WORD MinorSubsystemVersion
;
594 DWORD Win32VersionValue
;
599 WORD DllCharacteristics
;
600 DWORD SizeOfStackReserve
;
601 DWORD SizeOfStackCommit
;
602 DWORD SizeOfHeapReserve
;
603 DWORD SizeOfHeapCommit
;
605 DWORD NumberOfRvaAndSizes
;
606 IMAGE_DATA_DIRECTORY DataDirectory
[IMAGE_NUMBEROF_DIRECTORY_ENTRIES
];
607 } IMAGE_OPTIONAL_HEADER32
, *PIMAGE_OPTIONAL_HEADER32
;
609 typedef struct _IMAGE_NT_HEADERS
{
611 IMAGE_FILE_HEADER FileHeader
;
612 IMAGE_OPTIONAL_HEADER32 OptionalHeader
;
613 } IMAGE_NT_HEADERS32
, *PIMAGE_NT_HEADERS32
;
614 typedef IMAGE_NT_HEADERS32 IMAGE_NT_HEADERS
;
615 typedef PIMAGE_NT_HEADERS32 PIMAGE_NT_HEADERS
;
617 #define IMAGE_DIRECTORY_ENTRY_EXPORT 0 // Export Directory
619 typedef struct _IMAGE_EXPORT_DIRECTORY
{
620 DWORD Characteristics
;
626 DWORD NumberOfFunctions
;
628 DWORD AddressOfFunctions
; // RVA from base of image
629 DWORD AddressOfNames
; // RVA from base of image
630 DWORD AddressOfNameOrdinals
; // RVA from base of image
631 } IMAGE_EXPORT_DIRECTORY
, *PIMAGE_EXPORT_DIRECTORY
;
642 HalQueryDisplayParameters (
643 OUT PULONG WidthInCharacters
,
644 OUT PULONG HeightInLines
,
645 OUT PULONG CursorColumn
,
651 HalSetDisplayParameters (
652 IN ULONG CursorColumn
,
656 extern ULONG NtBuildNumber
;
658 #endif //__NTDDK_EX__H__