- Move more stuff to wdm.h
[reactos.git] / include / ddk / winddk.h
1 /*
2 * winddk.h
3 *
4 * Windows Device Driver Kit
5 *
6 * This file is part of the w32api package.
7 *
8 * Contributors:
9 * Created by Casper S. Hornstrup <chorns@users.sourceforge.net>
10 *
11 * THIS SOFTWARE IS NOT COPYRIGHTED
12 *
13 * This source code is offered for use in the public domain. You may
14 * use, modify or distribute it freely.
15 *
16 * This code is distributed in the hope that it will be useful but
17 * WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
18 * DISCLAIMED. This includes but is not limited to warranties of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
20 *
21 */
22
23 #ifndef __WINDDK_H
24 #define __WINDDK_H
25
26 /* Helper macro to enable gcc's extension. */
27 #ifndef __GNU_EXTENSION
28 #ifdef __GNUC__
29 #define __GNU_EXTENSION __extension__
30 #else
31 #define __GNU_EXTENSION
32 #endif
33 #endif
34
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38
39 #include <excpt.h>
40 #include <ntdef.h>
41 #include <ntstatus.h>
42
43 #include "intrin.h"
44
45 #if !defined(_NTHAL_)
46 #define NTHALAPI DECLSPEC_IMPORT
47 #else
48 #define NTHALAPI
49 #endif
50
51 /* Pseudo modifiers for parameters */
52 #ifndef IN
53 #define IN
54 #endif
55 #ifndef OUT
56 #define OUT
57 #endif
58 #ifndef OPTIONAL
59 #define OPTIONAL
60 #endif
61 #ifndef UNALLIGNED
62 #define UNALLIGNED
63 #endif
64
65 #define CONST const
66
67 #define RESTRICTED_POINTER
68
69 #if defined(_WIN64)
70 #define POINTER_ALIGNMENT DECLSPEC_ALIGN(8)
71 #else
72 #define POINTER_ALIGNMENT
73 #endif
74
75 #define DECLSPEC_ADDRSAFE
76
77 #ifdef NONAMELESSUNION
78 # define _DDK_DUMMYUNION_MEMBER(name) DUMMYUNIONNAME.name
79 # define _DDK_DUMMYUNION_N_MEMBER(n, name) DUMMYUNIONNAME##n.name
80 #else
81 # define _DDK_DUMMYUNION_MEMBER(name) name
82 # define _DDK_DUMMYUNION_N_MEMBER(n, name) name
83 #endif
84
85 /*
86 ** Forward declarations
87 */
88
89 struct _KPCR;
90 struct _KPRCB;
91 struct _KTSS;
92 struct _DRIVE_LAYOUT_INFORMATION_EX;
93 struct _LOADER_PARAMETER_BLOCK;
94
95
96 #if 1
97 /* FIXME: Unknown definitions */
98 struct _SET_PARTITION_INFORMATION_EX;
99 typedef ULONG WAIT_TYPE;
100 #define WaitAll 0
101 #define WaitAny 1
102 typedef HANDLE TRACEHANDLE;
103 typedef PVOID PWMILIB_CONTEXT;
104 typedef ULONG LOGICAL;
105 #endif
106
107 /*
108 ** WmiLib specific structure
109 */
110 typedef enum
111 {
112 IrpProcessed, // Irp was processed and possibly completed
113 IrpNotCompleted, // Irp was process and NOT completed
114 IrpNotWmi, // Irp is not a WMI irp
115 IrpForward // Irp is wmi irp, but targeted at another device object
116 } SYSCTL_IRP_DISPOSITION, *PSYSCTL_IRP_DISPOSITION;
117
118 //
119 // Forwarder
120 //
121 struct _COMPRESSED_DATA_INFO;
122
123 #define KERNEL_STACK_SIZE 12288
124 #define KERNEL_LARGE_STACK_SIZE 61440
125 #define KERNEL_LARGE_STACK_COMMIT 12288
126
127 #define EXCEPTION_READ_FAULT 0
128 #define EXCEPTION_WRITE_FAULT 1
129 #define EXCEPTION_EXECUTE_FAULT 8
130
131 #define DPFLTR_ERROR_LEVEL 0
132 #define DPFLTR_WARNING_LEVEL 1
133 #define DPFLTR_TRACE_LEVEL 2
134 #define DPFLTR_INFO_LEVEL 3
135 #define DPFLTR_MASK 0x80000000
136
137 typedef enum _DPFLTR_TYPE
138 {
139 DPFLTR_SYSTEM_ID = 0,
140 DPFLTR_SMSS_ID = 1,
141 DPFLTR_SETUP_ID = 2,
142 DPFLTR_NTFS_ID = 3,
143 DPFLTR_FSTUB_ID = 4,
144 DPFLTR_CRASHDUMP_ID = 5,
145 DPFLTR_CDAUDIO_ID = 6,
146 DPFLTR_CDROM_ID = 7,
147 DPFLTR_CLASSPNP_ID = 8,
148 DPFLTR_DISK_ID = 9,
149 DPFLTR_REDBOOK_ID = 10,
150 DPFLTR_STORPROP_ID = 11,
151 DPFLTR_SCSIPORT_ID = 12,
152 DPFLTR_SCSIMINIPORT_ID = 13,
153 DPFLTR_CONFIG_ID = 14,
154 DPFLTR_I8042PRT_ID = 15,
155 DPFLTR_SERMOUSE_ID = 16,
156 DPFLTR_LSERMOUS_ID = 17,
157 DPFLTR_KBDHID_ID = 18,
158 DPFLTR_MOUHID_ID = 19,
159 DPFLTR_KBDCLASS_ID = 20,
160 DPFLTR_MOUCLASS_ID = 21,
161 DPFLTR_TWOTRACK_ID = 22,
162 DPFLTR_WMILIB_ID = 23,
163 DPFLTR_ACPI_ID = 24,
164 DPFLTR_AMLI_ID = 25,
165 DPFLTR_HALIA64_ID = 26,
166 DPFLTR_VIDEO_ID = 27,
167 DPFLTR_SVCHOST_ID = 28,
168 DPFLTR_VIDEOPRT_ID = 29,
169 DPFLTR_TCPIP_ID = 30,
170 DPFLTR_DMSYNTH_ID = 31,
171 DPFLTR_NTOSPNP_ID = 32,
172 DPFLTR_FASTFAT_ID = 33,
173 DPFLTR_SAMSS_ID = 34,
174 DPFLTR_PNPMGR_ID = 35,
175 DPFLTR_NETAPI_ID = 36,
176 DPFLTR_SCSERVER_ID = 37,
177 DPFLTR_SCCLIENT_ID = 38,
178 DPFLTR_SERIAL_ID = 39,
179 DPFLTR_SERENUM_ID = 40,
180 DPFLTR_UHCD_ID = 41,
181 DPFLTR_BOOTOK_ID = 42,
182 DPFLTR_BOOTVRFY_ID = 43,
183 DPFLTR_RPCPROXY_ID = 44,
184 DPFLTR_AUTOCHK_ID = 45,
185 DPFLTR_DCOMSS_ID = 46,
186 DPFLTR_UNIMODEM_ID = 47,
187 DPFLTR_SIS_ID = 48,
188 DPFLTR_FLTMGR_ID = 49,
189 DPFLTR_WMICORE_ID = 50,
190 DPFLTR_BURNENG_ID = 51,
191 DPFLTR_IMAPI_ID = 52,
192 DPFLTR_SXS_ID = 53,
193 DPFLTR_FUSION_ID = 54,
194 DPFLTR_IDLETASK_ID = 55,
195 DPFLTR_SOFTPCI_ID = 56,
196 DPFLTR_TAPE_ID = 57,
197 DPFLTR_MCHGR_ID = 58,
198 DPFLTR_IDEP_ID = 59,
199 DPFLTR_PCIIDE_ID = 60,
200 DPFLTR_FLOPPY_ID = 61,
201 DPFLTR_FDC_ID = 62,
202 DPFLTR_TERMSRV_ID = 63,
203 DPFLTR_W32TIME_ID = 64,
204 DPFLTR_PREFETCHER_ID = 65,
205 DPFLTR_RSFILTER_ID = 66,
206 DPFLTR_FCPORT_ID = 67,
207 DPFLTR_PCI_ID = 68,
208 DPFLTR_DMIO_ID = 69,
209 DPFLTR_DMCONFIG_ID = 70,
210 DPFLTR_DMADMIN_ID = 71,
211 DPFLTR_WSOCKTRANSPORT_ID = 72,
212 DPFLTR_VSS_ID = 73,
213 DPFLTR_PNPMEM_ID = 74,
214 DPFLTR_PROCESSOR_ID = 75,
215 DPFLTR_DMSERVER_ID = 76,
216 DPFLTR_SR_ID = 77,
217 DPFLTR_INFINIBAND_ID = 78,
218 DPFLTR_IHVDRIVER_ID = 79,
219 DPFLTR_IHVVIDEO_ID = 80,
220 DPFLTR_IHVAUDIO_ID = 81,
221 DPFLTR_IHVNETWORK_ID = 82,
222 DPFLTR_IHVSTREAMING_ID = 83,
223 DPFLTR_IHVBUS_ID = 84,
224 DPFLTR_HPS_ID = 85,
225 DPFLTR_RTLTHREADPOOL_ID = 86,
226 DPFLTR_LDR_ID = 87,
227 DPFLTR_TCPIP6_ID = 88,
228 DPFLTR_ISAPNP_ID = 89,
229 DPFLTR_SHPC_ID = 90,
230 DPFLTR_STORPORT_ID = 91,
231 DPFLTR_STORMINIPORT_ID = 92,
232 DPFLTR_PRINTSPOOLER_ID = 93,
233 DPFLTR_VDS_ID = 94,
234 DPFLTR_VDSBAS_ID = 95,
235 DPFLTR_VDSDYNDR_ID = 96,
236 DPFLTR_VDSUTIL_ID = 97,
237 DPFLTR_DFRGIFC_ID = 98,
238 DPFLTR_DEFAULT_ID = 99,
239 DPFLTR_MM_ID = 100,
240 DPFLTR_DFSC_ID = 101,
241 DPFLTR_WOW64_ID = 102,
242 DPFLTR_ENDOFTABLE_ID
243 } DPFLTR_TYPE;
244
245 /* also in winnt.h */
246
247 #define FILE_COPY_STRUCTURED_STORAGE 0x00000041
248 #define FILE_STRUCTURED_STORAGE 0x00000441
249
250 /* end winnt.h */
251
252 #define THREAD_ALERT (0x0004)
253
254 /* Exported object types */
255 extern POBJECT_TYPE NTSYSAPI ExDesktopObjectType;
256 extern POBJECT_TYPE NTSYSAPI ExEventObjectType;
257 extern POBJECT_TYPE NTSYSAPI ExSemaphoreObjectType;
258 extern POBJECT_TYPE NTSYSAPI ExWindowStationObjectType;
259 extern ULONG NTSYSAPI IoDeviceHandlerObjectSize;
260 extern POBJECT_TYPE NTSYSAPI IoDeviceHandlerObjectType;
261 extern POBJECT_TYPE NTSYSAPI IoDeviceObjectType;
262 extern POBJECT_TYPE NTSYSAPI IoDriverObjectType;
263 extern POBJECT_TYPE NTSYSAPI IoFileObjectType;
264 extern POBJECT_TYPE NTSYSAPI PsThreadType;
265 extern POBJECT_TYPE NTSYSAPI LpcPortObjectType;
266 extern POBJECT_TYPE NTSYSAPI SeTokenObjectType;
267 extern POBJECT_TYPE NTSYSAPI PsProcessType;
268
269 #if (NTDDI_VERSION >= NTDDI_LONGHORN)
270 extern volatile CCHAR NTSYSAPI KeNumberProcessors;
271 #else
272 #if (NTDDI_VERSION >= NTDDI_WINXP)
273 extern CCHAR NTSYSAPI KeNumberProcessors;
274 #else
275 //extern PCCHAR KeNumberProcessors;
276 extern NTSYSAPI CCHAR KeNumberProcessors; //FIXME: Note to Alex: I won't fix this atm, since I prefer to discuss this with you first.
277 #endif
278 #endif
279
280 #define MAX_WOW64_SHARED_ENTRIES 16
281
282 extern volatile KSYSTEM_TIME KeTickCount;
283
284 #define NX_SUPPORT_POLICY_ALWAYSOFF 0
285 #define NX_SUPPORT_POLICY_ALWAYSON 1
286 #define NX_SUPPORT_POLICY_OPTIN 2
287 #define NX_SUPPORT_POLICY_OPTOUT 3
288
289 typedef struct _KUSER_SHARED_DATA
290 {
291 ULONG TickCountLowDeprecated;
292 ULONG TickCountMultiplier;
293 volatile KSYSTEM_TIME InterruptTime;
294 volatile KSYSTEM_TIME SystemTime;
295 volatile KSYSTEM_TIME TimeZoneBias;
296 USHORT ImageNumberLow;
297 USHORT ImageNumberHigh;
298 WCHAR NtSystemRoot[260];
299 ULONG MaxStackTraceDepth;
300 ULONG CryptoExponent;
301 ULONG TimeZoneId;
302 ULONG LargePageMinimum;
303 ULONG Reserved2[7];
304 NT_PRODUCT_TYPE NtProductType;
305 BOOLEAN ProductTypeIsValid;
306 ULONG NtMajorVersion;
307 ULONG NtMinorVersion;
308 BOOLEAN ProcessorFeatures[PROCESSOR_FEATURE_MAX];
309 ULONG Reserved1;
310 ULONG Reserved3;
311 volatile ULONG TimeSlip;
312 ALTERNATIVE_ARCHITECTURE_TYPE AlternativeArchitecture;
313 LARGE_INTEGER SystemExpirationDate;
314 ULONG SuiteMask;
315 BOOLEAN KdDebuggerEnabled;
316 #if (NTDDI_VERSION >= NTDDI_WINXPSP2)
317 UCHAR NXSupportPolicy;
318 #endif
319 volatile ULONG ActiveConsoleId;
320 volatile ULONG DismountCount;
321 ULONG ComPlusPackage;
322 ULONG LastSystemRITEventTickCount;
323 ULONG NumberOfPhysicalPages;
324 BOOLEAN SafeBootMode;
325 ULONG TraceLogging;
326 ULONG Fill0;
327 ULONGLONG TestRetInstruction;
328 ULONG SystemCall;
329 ULONG SystemCallReturn;
330 ULONGLONG SystemCallPad[3];
331 __GNU_EXTENSION union {
332 volatile KSYSTEM_TIME TickCount;
333 volatile ULONG64 TickCountQuad;
334 };
335 ULONG Cookie;
336 #if (NTDDI_VERSION >= NTDDI_WS03)
337 LONGLONG ConsoleSessionForegroundProcessId;
338 ULONG Wow64SharedInformation[MAX_WOW64_SHARED_ENTRIES];
339 #endif
340 #if (NTDDI_VERSION >= NTDDI_LONGHORN)
341 USHORT UserModeGlobalLogger[8];
342 ULONG HeapTracingPid[2];
343 ULONG CritSecTracingPid[2];
344 __GNU_EXTENSION union
345 {
346 ULONG SharedDataFlags;
347 __GNU_EXTENSION struct
348 {
349 ULONG DbgErrorPortPresent:1;
350 ULONG DbgElevationEnabled:1;
351 ULONG DbgVirtEnabled:1;
352 ULONG DbgInstallerDetectEnabled:1;
353 ULONG SpareBits:28;
354 };
355 };
356 ULONG ImageFileExecutionOptions;
357 KAFFINITY ActiveProcessorAffinity;
358 #endif
359 } KUSER_SHARED_DATA, *PKUSER_SHARED_DATA;
360
361 /*
362 ** IRP function codes
363 */
364
365 #define IRP_MN_QUERY_DIRECTORY 0x01
366 #define IRP_MN_NOTIFY_CHANGE_DIRECTORY 0x02
367
368 #define IRP_MN_USER_FS_REQUEST 0x00
369 #define IRP_MN_MOUNT_VOLUME 0x01
370 #define IRP_MN_VERIFY_VOLUME 0x02
371 #define IRP_MN_LOAD_FILE_SYSTEM 0x03
372 #define IRP_MN_TRACK_LINK 0x04
373 #define IRP_MN_KERNEL_CALL 0x04
374
375 #define IRP_MN_LOCK 0x01
376 #define IRP_MN_UNLOCK_SINGLE 0x02
377 #define IRP_MN_UNLOCK_ALL 0x03
378 #define IRP_MN_UNLOCK_ALL_BY_KEY 0x04
379
380 #define IRP_MN_NORMAL 0x00
381 #define IRP_MN_DPC 0x01
382 #define IRP_MN_MDL 0x02
383 #define IRP_MN_COMPLETE 0x04
384 #define IRP_MN_COMPRESSED 0x08
385
386 #define IRP_MN_MDL_DPC (IRP_MN_MDL | IRP_MN_DPC)
387 #define IRP_MN_COMPLETE_MDL (IRP_MN_COMPLETE | IRP_MN_MDL)
388 #define IRP_MN_COMPLETE_MDL_DPC (IRP_MN_COMPLETE_MDL | IRP_MN_DPC)
389
390 #define IRP_MN_QUERY_LEGACY_BUS_INFORMATION 0x18
391
392 typedef EXCEPTION_DISPOSITION
393 (DDKAPI *PEXCEPTION_ROUTINE)(
394 IN struct _EXCEPTION_RECORD *ExceptionRecord,
395 IN PVOID EstablisherFrame,
396 IN OUT struct _CONTEXT *ContextRecord,
397 IN OUT PVOID DispatcherContext);
398
399 typedef NTSTATUS
400 (DDKAPI *PDRIVER_ENTRY)(
401 IN struct _DRIVER_OBJECT *DriverObject,
402 IN PUNICODE_STRING RegistryPath);
403
404 typedef VOID
405 (DDKAPI *PDRIVER_REINITIALIZE)(
406 IN struct _DRIVER_OBJECT *DriverObject,
407 IN PVOID Context,
408 IN ULONG Count);
409
410 typedef BOOLEAN
411 (DDKAPI *PKTRANSFER_ROUTINE)(
412 VOID);
413
414 #define ASSERT_GATE(object) \
415 ASSERT((((object)->Header.Type & KOBJECT_TYPE_MASK) == GateObject) || \
416 (((object)->Header.Type & KOBJECT_TYPE_MASK) == EventSynchronizationObject))
417
418 #define TIMER_TABLE_SIZE 512
419 #define TIMER_TABLE_SHIFT 9
420
421 #define ASSERT_TIMER(E) \
422 ASSERT(((E)->Header.Type == TimerNotificationObject) || \
423 ((E)->Header.Type == TimerSynchronizationObject))
424
425 #define ASSERT_MUTANT(E) \
426 ASSERT((E)->Header.Type == MutantObject)
427
428 #define ASSERT_SEMAPHORE(E) \
429 ASSERT((E)->Header.Type == SemaphoreObject)
430
431 #define ASSERT_EVENT(E) \
432 ASSERT(((E)->Header.Type == NotificationEvent) || \
433 ((E)->Header.Type == SynchronizationEvent))
434
435
436 typedef enum _TIMER_TYPE {
437 NotificationTimer,
438 SynchronizationTimer
439 } TIMER_TYPE;
440
441 #define KEYBOARD_INSERT_ON 0x08
442 #define KEYBOARD_CAPS_LOCK_ON 0x04
443 #define KEYBOARD_NUM_LOCK_ON 0x02
444 #define KEYBOARD_SCROLL_LOCK_ON 0x01
445 #define KEYBOARD_ALT_KEY_DOWN 0x80
446 #define KEYBOARD_CTRL_KEY_DOWN 0x40
447 #define KEYBOARD_LEFT_SHIFT_DOWN 0x20
448 #define KEYBOARD_RIGHT_SHIFT_DOWN 0x10
449
450 typedef struct _IO_COUNTERS {
451 ULONGLONG ReadOperationCount;
452 ULONGLONG WriteOperationCount;
453 ULONGLONG OtherOperationCount;
454 ULONGLONG ReadTransferCount;
455 ULONGLONG WriteTransferCount;
456 ULONGLONG OtherTransferCount;
457 } IO_COUNTERS, *PIO_COUNTERS;
458
459 typedef struct _VM_COUNTERS
460 {
461 SIZE_T PeakVirtualSize;
462 SIZE_T VirtualSize;
463 ULONG PageFaultCount;
464 SIZE_T PeakWorkingSetSize;
465 SIZE_T WorkingSetSize;
466 SIZE_T QuotaPeakPagedPoolUsage;
467 SIZE_T QuotaPagedPoolUsage;
468 SIZE_T QuotaPeakNonPagedPoolUsage;
469 SIZE_T QuotaNonPagedPoolUsage;
470 SIZE_T PagefileUsage;
471 SIZE_T PeakPagefileUsage;
472 } VM_COUNTERS, *PVM_COUNTERS;
473
474 typedef struct _VM_COUNTERS_EX
475 {
476 SIZE_T PeakVirtualSize;
477 SIZE_T VirtualSize;
478 ULONG PageFaultCount;
479 SIZE_T PeakWorkingSetSize;
480 SIZE_T WorkingSetSize;
481 SIZE_T QuotaPeakPagedPoolUsage;
482 SIZE_T QuotaPagedPoolUsage;
483 SIZE_T QuotaPeakNonPagedPoolUsage;
484 SIZE_T QuotaNonPagedPoolUsage;
485 SIZE_T PagefileUsage;
486 SIZE_T PeakPagefileUsage;
487 SIZE_T PrivateUsage;
488 } VM_COUNTERS_EX, *PVM_COUNTERS_EX;
489
490 typedef struct _POOLED_USAGE_AND_LIMITS
491 {
492 SIZE_T PeakPagedPoolUsage;
493 SIZE_T PagedPoolUsage;
494 SIZE_T PagedPoolLimit;
495 SIZE_T PeakNonPagedPoolUsage;
496 SIZE_T NonPagedPoolUsage;
497 SIZE_T NonPagedPoolLimit;
498 SIZE_T PeakPagefileUsage;
499 SIZE_T PagefileUsage;
500 SIZE_T PagefileLimit;
501 } POOLED_USAGE_AND_LIMITS, *PPOOLED_USAGE_AND_LIMITS;
502
503 typedef struct _CONTROLLER_OBJECT {
504 CSHORT Type;
505 CSHORT Size;
506 PVOID ControllerExtension;
507 KDEVICE_QUEUE DeviceWaitQueue;
508 ULONG Spare1;
509 LARGE_INTEGER Spare2;
510 } CONTROLLER_OBJECT, *PCONTROLLER_OBJECT;
511
512 /* DEVICE_OBJECT.Flags */
513
514 #define DO_DEVICE_HAS_NAME 0x00000040
515 #define DO_SYSTEM_BOOT_PARTITION 0x00000100
516 #define DO_LONG_TERM_REQUESTS 0x00000200
517 #define DO_NEVER_LAST_DEVICE 0x00000400
518 #define DO_LOW_PRIORITY_FILESYSTEM 0x00010000
519 #define DO_XIP 0x00020000
520
521 #define DRVO_REINIT_REGISTERED 0x00000008
522 #define DRVO_INITIALIZED 0x00000010
523 #define DRVO_BOOTREINIT_REGISTERED 0x00000020
524 #define DRVO_LEGACY_RESOURCES 0x00000040
525
526 typedef enum _ARBITER_REQUEST_SOURCE {
527 ArbiterRequestUndefined = -1,
528 ArbiterRequestLegacyReported,
529 ArbiterRequestHalReported,
530 ArbiterRequestLegacyAssigned,
531 ArbiterRequestPnpDetected,
532 ArbiterRequestPnpEnumerated
533 } ARBITER_REQUEST_SOURCE;
534
535 typedef enum _ARBITER_RESULT {
536 ArbiterResultUndefined = -1,
537 ArbiterResultSuccess,
538 ArbiterResultExternalConflict,
539 ArbiterResultNullRequest
540 } ARBITER_RESULT;
541
542 typedef enum _ARBITER_ACTION {
543 ArbiterActionTestAllocation,
544 ArbiterActionRetestAllocation,
545 ArbiterActionCommitAllocation,
546 ArbiterActionRollbackAllocation,
547 ArbiterActionQueryAllocatedResources,
548 ArbiterActionWriteReservedResources,
549 ArbiterActionQueryConflict,
550 ArbiterActionQueryArbitrate,
551 ArbiterActionAddReserved,
552 ArbiterActionBootAllocation
553 } ARBITER_ACTION, *PARBITER_ACTION;
554
555 typedef struct _ARBITER_CONFLICT_INFO {
556 PDEVICE_OBJECT OwningObject;
557 ULONGLONG Start;
558 ULONGLONG End;
559 } ARBITER_CONFLICT_INFO, *PARBITER_CONFLICT_INFO;
560
561 typedef struct _ARBITER_PARAMETERS {
562 union {
563 struct {
564 IN OUT PLIST_ENTRY ArbitrationList;
565 IN ULONG AllocateFromCount;
566 IN PCM_PARTIAL_RESOURCE_DESCRIPTOR AllocateFrom;
567 } TestAllocation;
568
569 struct {
570 IN OUT PLIST_ENTRY ArbitrationList;
571 IN ULONG AllocateFromCount;
572 IN PCM_PARTIAL_RESOURCE_DESCRIPTOR AllocateFrom;
573 } RetestAllocation;
574
575 struct {
576 IN OUT PLIST_ENTRY ArbitrationList;
577 } BootAllocation;
578
579 struct {
580 OUT PCM_PARTIAL_RESOURCE_LIST *AllocatedResources;
581 } QueryAllocatedResources;
582
583 struct {
584 IN PDEVICE_OBJECT PhysicalDeviceObject;
585 IN PIO_RESOURCE_DESCRIPTOR ConflictingResource;
586 OUT PULONG ConflictCount;
587 OUT PARBITER_CONFLICT_INFO *Conflicts;
588 } QueryConflict;
589
590 struct {
591 IN PLIST_ENTRY ArbitrationList;
592 } QueryArbitrate;
593
594 struct {
595 IN PDEVICE_OBJECT ReserveDevice;
596 } AddReserved;
597 } Parameters;
598 } ARBITER_PARAMETERS, *PARBITER_PARAMETERS;
599
600 #define ARBITER_FLAG_BOOT_CONFIG 0x00000001
601
602 typedef struct _ARBITER_LIST_ENTRY {
603 LIST_ENTRY ListEntry;
604 ULONG AlternativeCount;
605 PIO_RESOURCE_DESCRIPTOR Alternatives;
606 PDEVICE_OBJECT PhysicalDeviceObject;
607 ARBITER_REQUEST_SOURCE RequestSource;
608 ULONG Flags;
609 LONG_PTR WorkSpace;
610 INTERFACE_TYPE InterfaceType;
611 ULONG SlotNumber;
612 ULONG BusNumber;
613 PCM_PARTIAL_RESOURCE_DESCRIPTOR Assignment;
614 PIO_RESOURCE_DESCRIPTOR SelectedAlternative;
615 ARBITER_RESULT Result;
616 } ARBITER_LIST_ENTRY, *PARBITER_LIST_ENTRY;
617
618 typedef NTSTATUS
619 (DDKAPI *PARBITER_HANDLER)(
620 IN PVOID Context,
621 IN ARBITER_ACTION Action,
622 IN OUT PARBITER_PARAMETERS Parameters);
623
624 #define ARBITER_PARTIAL 0x00000001
625
626 typedef struct _ARBITER_INTERFACE {
627 USHORT Size;
628 USHORT Version;
629 PVOID Context;
630 PINTERFACE_REFERENCE InterfaceReference;
631 PINTERFACE_DEREFERENCE InterfaceDereference;
632 PARBITER_HANDLER ArbiterHandler;
633 ULONG Flags;
634 } ARBITER_INTERFACE, *PARBITER_INTERFACE;
635
636 typedef enum _HAL_QUERY_INFORMATION_CLASS {
637 HalInstalledBusInformation,
638 HalProfileSourceInformation,
639 HalInformationClassUnused1,
640 HalPowerInformation,
641 HalProcessorSpeedInformation,
642 HalCallbackInformation,
643 HalMapRegisterInformation,
644 HalMcaLogInformation,
645 HalFrameBufferCachingInformation,
646 HalDisplayBiosInformation,
647 HalProcessorFeatureInformation,
648 HalNumaTopologyInterface,
649 HalErrorInformation,
650 HalCmcLogInformation,
651 HalCpeLogInformation,
652 HalQueryMcaInterface,
653 HalQueryAMLIIllegalIOPortAddresses,
654 HalQueryMaxHotPlugMemoryAddress,
655 HalPartitionIpiInterface,
656 HalPlatformInformation,
657 HalQueryProfileSourceList
658 } HAL_QUERY_INFORMATION_CLASS, *PHAL_QUERY_INFORMATION_CLASS;
659
660 typedef enum _HAL_SET_INFORMATION_CLASS {
661 HalProfileSourceInterval,
662 HalProfileSourceInterruptHandler,
663 HalMcaRegisterDriver,
664 HalKernelErrorHandler,
665 HalCmcRegisterDriver,
666 HalCpeRegisterDriver,
667 HalMcaLog,
668 HalCmcLog,
669 HalCpeLog,
670 HalGenerateCmcInterrupt
671 } HAL_SET_INFORMATION_CLASS, *PHAL_SET_INFORMATION_CLASS;
672
673 typedef struct _HAL_PROFILE_SOURCE_INTERVAL
674 {
675 KPROFILE_SOURCE Source;
676 ULONG_PTR Interval;
677 } HAL_PROFILE_SOURCE_INTERVAL, *PHAL_PROFILE_SOURCE_INTERVAL;
678
679 typedef struct _HAL_PROFILE_SOURCE_INFORMATION
680 {
681 KPROFILE_SOURCE Source;
682 BOOLEAN Supported;
683 ULONG Interval;
684 } HAL_PROFILE_SOURCE_INFORMATION, *PHAL_PROFILE_SOURCE_INFORMATION;
685
686 typedef struct _MAP_REGISTER_ENTRY
687 {
688 PVOID MapRegister;
689 BOOLEAN WriteToDevice;
690 } MAP_REGISTER_ENTRY, *PMAP_REGISTER_ENTRY;
691
692 typedef struct
693 {
694 UCHAR Type;
695 BOOLEAN Valid;
696 UCHAR Reserved[2];
697 PUCHAR TranslatedAddress;
698 ULONG Length;
699 } DEBUG_DEVICE_ADDRESS, *PDEBUG_DEVICE_ADDRESS;
700
701 typedef struct
702 {
703 PHYSICAL_ADDRESS Start;
704 PHYSICAL_ADDRESS MaxEnd;
705 PVOID VirtualAddress;
706 ULONG Length;
707 BOOLEAN Cached;
708 BOOLEAN Aligned;
709 } DEBUG_MEMORY_REQUIREMENTS, *PDEBUG_MEMORY_REQUIREMENTS;
710
711 typedef struct
712 {
713 ULONG Bus;
714 ULONG Slot;
715 USHORT VendorID;
716 USHORT DeviceID;
717 UCHAR BaseClass;
718 UCHAR SubClass;
719 UCHAR ProgIf;
720 BOOLEAN Initialized;
721 DEBUG_DEVICE_ADDRESS BaseAddress[6];
722 DEBUG_MEMORY_REQUIREMENTS Memory;
723 } DEBUG_DEVICE_DESCRIPTOR, *PDEBUG_DEVICE_DESCRIPTOR;
724
725 /* Function Type Defintions for Dispatch Functions */
726 struct _DEVICE_CONTROL_CONTEXT;
727
728 typedef VOID
729 (DDKAPI *PDEVICE_CONTROL_COMPLETION)(
730 IN struct _DEVICE_CONTROL_CONTEXT *ControlContext);
731
732 typedef struct _DEVICE_CONTROL_CONTEXT {
733 NTSTATUS Status;
734 PDEVICE_HANDLER_OBJECT DeviceHandler;
735 PDEVICE_OBJECT DeviceObject;
736 ULONG ControlCode;
737 PVOID Buffer;
738 PULONG BufferLength;
739 PVOID Context;
740 } DEVICE_CONTROL_CONTEXT, *PDEVICE_CONTROL_CONTEXT;
741
742 typedef struct _PM_DISPATCH_TABLE {
743 ULONG Signature;
744 ULONG Version;
745 PVOID Function[1];
746 } PM_DISPATCH_TABLE, *PPM_DISPATCH_TABLE;
747
748 typedef enum _RESOURCE_TRANSLATION_DIRECTION {
749 TranslateChildToParent,
750 TranslateParentToChild
751 } RESOURCE_TRANSLATION_DIRECTION;
752
753 typedef NTSTATUS
754 (DDKAPI *PTRANSLATE_RESOURCE_HANDLER)(
755 IN PVOID Context,
756 IN PCM_PARTIAL_RESOURCE_DESCRIPTOR Source,
757 IN RESOURCE_TRANSLATION_DIRECTION Direction,
758 IN ULONG AlternativesCount,
759 IN IO_RESOURCE_DESCRIPTOR Alternatives[],
760 IN PDEVICE_OBJECT PhysicalDeviceObject,
761 OUT PCM_PARTIAL_RESOURCE_DESCRIPTOR Target);
762
763 typedef NTSTATUS
764 (DDKAPI *PTRANSLATE_RESOURCE_REQUIREMENTS_HANDLER)(
765 IN PVOID Context,
766 IN PIO_RESOURCE_DESCRIPTOR Source,
767 IN PDEVICE_OBJECT PhysicalDeviceObject,
768 OUT PULONG TargetCount,
769 OUT PIO_RESOURCE_DESCRIPTOR *Target);
770
771 typedef struct _TRANSLATOR_INTERFACE {
772 USHORT Size;
773 USHORT Version;
774 PVOID Context;
775 PINTERFACE_REFERENCE InterfaceReference;
776 PINTERFACE_DEREFERENCE InterfaceDereference;
777 PTRANSLATE_RESOURCE_HANDLER TranslateResources;
778 PTRANSLATE_RESOURCE_REQUIREMENTS_HANDLER TranslateResourceRequirements;
779 } TRANSLATOR_INTERFACE, *PTRANSLATOR_INTERFACE;
780
781 typedef NTSTATUS
782 (DDKAPI *pHalDeviceControl)(
783 IN PDEVICE_HANDLER_OBJECT DeviceHandler,
784 IN PDEVICE_OBJECT DeviceObject,
785 IN ULONG ControlCode,
786 IN OUT PVOID Buffer OPTIONAL,
787 IN OUT PULONG BufferLength OPTIONAL,
788 IN PVOID Context,
789 IN PDEVICE_CONTROL_COMPLETION CompletionRoutine);
790
791 typedef VOID
792 (FASTCALL *pHalExamineMBR)(
793 IN PDEVICE_OBJECT DeviceObject,
794 IN ULONG SectorSize,
795 IN ULONG MBRTypeIdentifier,
796 OUT PVOID *Buffer);
797
798 typedef VOID
799 (FASTCALL *pHalIoAssignDriveLetters)(
800 IN struct _LOADER_PARAMETER_BLOCK *LoaderBlock,
801 IN PSTRING NtDeviceName,
802 OUT PUCHAR NtSystemPath,
803 OUT PSTRING NtSystemPathString);
804
805 typedef NTSTATUS
806 (FASTCALL *pHalIoReadPartitionTable)(
807 IN PDEVICE_OBJECT DeviceObject,
808 IN ULONG SectorSize,
809 IN BOOLEAN ReturnRecognizedPartitions,
810 OUT struct _DRIVE_LAYOUT_INFORMATION **PartitionBuffer);
811
812 typedef NTSTATUS
813 (FASTCALL *pHalIoSetPartitionInformation)(
814 IN PDEVICE_OBJECT DeviceObject,
815 IN ULONG SectorSize,
816 IN ULONG PartitionNumber,
817 IN ULONG PartitionType);
818
819 typedef NTSTATUS
820 (FASTCALL *pHalIoWritePartitionTable)(
821 IN PDEVICE_OBJECT DeviceObject,
822 IN ULONG SectorSize,
823 IN ULONG SectorsPerTrack,
824 IN ULONG NumberOfHeads,
825 IN struct _DRIVE_LAYOUT_INFORMATION *PartitionBuffer);
826
827 typedef PBUS_HANDLER
828 (FASTCALL *pHalHandlerForBus)(
829 IN INTERFACE_TYPE InterfaceType,
830 IN ULONG BusNumber);
831
832 typedef VOID
833 (FASTCALL *pHalReferenceBusHandler)(
834 IN PBUS_HANDLER BusHandler);
835
836 typedef NTSTATUS
837 (DDKAPI *pHalQuerySystemInformation)(
838 IN HAL_QUERY_INFORMATION_CLASS InformationClass,
839 IN ULONG BufferSize,
840 IN OUT PVOID Buffer,
841 OUT PULONG ReturnedLength);
842
843 typedef NTSTATUS
844 (DDKAPI *pHalSetSystemInformation)(
845 IN HAL_SET_INFORMATION_CLASS InformationClass,
846 IN ULONG BufferSize,
847 IN PVOID Buffer);
848
849 typedef NTSTATUS
850 (DDKAPI *pHalQueryBusSlots)(
851 IN PBUS_HANDLER BusHandler,
852 IN ULONG BufferSize,
853 OUT PULONG SlotNumbers,
854 OUT PULONG ReturnedLength);
855
856 typedef NTSTATUS
857 (DDKAPI *pHalInitPnpDriver)(
858 VOID);
859
860 typedef NTSTATUS
861 (DDKAPI *pHalInitPowerManagement)(
862 IN PPM_DISPATCH_TABLE PmDriverDispatchTable,
863 OUT PPM_DISPATCH_TABLE *PmHalDispatchTable);
864
865 typedef struct _DMA_ADAPTER*
866 (DDKAPI *pHalGetDmaAdapter)(
867 IN PVOID Context,
868 IN struct _DEVICE_DESCRIPTION *DeviceDescriptor,
869 OUT PULONG NumberOfMapRegisters);
870
871 typedef NTSTATUS
872 (DDKAPI *pHalGetInterruptTranslator)(
873 IN INTERFACE_TYPE ParentInterfaceType,
874 IN ULONG ParentBusNumber,
875 IN INTERFACE_TYPE BridgeInterfaceType,
876 IN USHORT Size,
877 IN USHORT Version,
878 OUT PTRANSLATOR_INTERFACE Translator,
879 OUT PULONG BridgeBusNumber);
880
881 typedef NTSTATUS
882 (DDKAPI *pHalStartMirroring)(
883 VOID);
884
885 typedef NTSTATUS
886 (DDKAPI *pHalEndMirroring)(
887 IN ULONG PassNumber);
888
889 typedef NTSTATUS
890 (DDKAPI *pHalMirrorPhysicalMemory)(
891 IN PHYSICAL_ADDRESS PhysicalAddress,
892 IN LARGE_INTEGER NumberOfBytes);
893
894 typedef NTSTATUS
895 (DDKAPI *pHalMirrorVerify)(
896 IN PHYSICAL_ADDRESS PhysicalAddress,
897 IN LARGE_INTEGER NumberOfBytes);
898
899 typedef VOID
900 (DDKAPI *pHalEndOfBoot)(
901 VOID);
902
903 typedef
904 BOOLEAN
905 (DDKAPI *pHalTranslateBusAddress)(
906 IN INTERFACE_TYPE InterfaceType,
907 IN ULONG BusNumber,
908 IN PHYSICAL_ADDRESS BusAddress,
909 IN OUT PULONG AddressSpace,
910 OUT PPHYSICAL_ADDRESS TranslatedAddress
911 );
912
913 typedef
914 NTSTATUS
915 (DDKAPI *pHalAssignSlotResources)(
916 IN PUNICODE_STRING RegistryPath,
917 IN PUNICODE_STRING DriverClassName OPTIONAL,
918 IN PDRIVER_OBJECT DriverObject,
919 IN PDEVICE_OBJECT DeviceObject,
920 IN INTERFACE_TYPE BusType,
921 IN ULONG BusNumber,
922 IN ULONG SlotNumber,
923 IN OUT PCM_RESOURCE_LIST *AllocatedResources
924 );
925
926 typedef
927 VOID
928 (DDKAPI *pHalHaltSystem)(
929 VOID
930 );
931
932 typedef
933 BOOLEAN
934 (DDKAPI *pHalResetDisplay)(
935 VOID
936 );
937
938 typedef
939 UCHAR
940 (DDKAPI *pHalVectorToIDTEntry)(
941 ULONG Vector
942 );
943
944 typedef
945 BOOLEAN
946 (DDKAPI *pHalFindBusAddressTranslation)(
947 IN PHYSICAL_ADDRESS BusAddress,
948 IN OUT PULONG AddressSpace,
949 OUT PPHYSICAL_ADDRESS TranslatedAddress,
950 IN OUT PULONG_PTR Context,
951 IN BOOLEAN NextBus
952 );
953
954 typedef
955 NTSTATUS
956 (DDKAPI *pKdSetupPciDeviceForDebugging)(
957 IN PVOID LoaderBlock OPTIONAL,
958 IN OUT PDEBUG_DEVICE_DESCRIPTOR PciDevice
959 );
960
961 typedef
962 NTSTATUS
963 (DDKAPI *pKdReleasePciDeviceForDebugging)(
964 IN OUT PDEBUG_DEVICE_DESCRIPTOR PciDevice
965 );
966
967 typedef
968 PVOID
969 (DDKAPI *pKdGetAcpiTablePhase0)(
970 IN struct _LOADER_PARAMETER_BLOCK *LoaderBlock,
971 IN ULONG Signature
972 );
973
974 typedef
975 VOID
976 (DDKAPI *pKdCheckPowerButton)(
977 VOID
978 );
979
980 typedef
981 ULONG
982 (DDKAPI *pHalGetInterruptVector)(
983 IN INTERFACE_TYPE InterfaceType,
984 IN ULONG BusNumber,
985 IN ULONG BusInterruptLevel,
986 IN ULONG BusInterruptVector,
987 OUT PKIRQL Irql,
988 OUT PKAFFINITY Affinity
989 );
990
991 typedef
992 NTSTATUS
993 (DDKAPI *pHalGetVectorInput)(
994 IN ULONG Vector,
995 IN KAFFINITY Affinity,
996 OUT PULONG Input,
997 OUT PKINTERRUPT_POLARITY Polarity
998 );
999
1000 typedef
1001 PVOID
1002 (DDKAPI *pKdMapPhysicalMemory64)(
1003 IN PHYSICAL_ADDRESS PhysicalAddress,
1004 IN ULONG NumberPages
1005 );
1006
1007 typedef
1008 VOID
1009 (DDKAPI *pKdUnmapVirtualAddress)(
1010 IN PVOID VirtualAddress,
1011 IN ULONG NumberPages
1012 );
1013
1014 typedef
1015 ULONG
1016 (DDKAPI *pKdGetPciDataByOffset)(
1017 IN ULONG BusNumber,
1018 IN ULONG SlotNumber,
1019 OUT PVOID Buffer,
1020 IN ULONG Offset,
1021 IN ULONG Length
1022 );
1023
1024 typedef
1025 ULONG
1026 (DDKAPI *pKdSetPciDataByOffset)(
1027 IN ULONG BusNumber,
1028 IN ULONG SlotNumber,
1029 IN PVOID Buffer,
1030 IN ULONG Offset,
1031 IN ULONG Length
1032 );
1033
1034 typedef BOOLEAN
1035 (DDKAPI *PHAL_RESET_DISPLAY_PARAMETERS)(
1036 ULONG Columns, ULONG Rows);
1037
1038 typedef struct {
1039 ULONG Version;
1040 pHalQuerySystemInformation HalQuerySystemInformation;
1041 pHalSetSystemInformation HalSetSystemInformation;
1042 pHalQueryBusSlots HalQueryBusSlots;
1043 ULONG Spare1;
1044 pHalExamineMBR HalExamineMBR;
1045 pHalIoAssignDriveLetters HalIoAssignDriveLetters;
1046 pHalIoReadPartitionTable HalIoReadPartitionTable;
1047 pHalIoSetPartitionInformation HalIoSetPartitionInformation;
1048 pHalIoWritePartitionTable HalIoWritePartitionTable;
1049 pHalHandlerForBus HalReferenceHandlerForBus;
1050 pHalReferenceBusHandler HalReferenceBusHandler;
1051 pHalReferenceBusHandler HalDereferenceBusHandler;
1052 pHalInitPnpDriver HalInitPnpDriver;
1053 pHalInitPowerManagement HalInitPowerManagement;
1054 pHalGetDmaAdapter HalGetDmaAdapter;
1055 pHalGetInterruptTranslator HalGetInterruptTranslator;
1056 pHalStartMirroring HalStartMirroring;
1057 pHalEndMirroring HalEndMirroring;
1058 pHalMirrorPhysicalMemory HalMirrorPhysicalMemory;
1059 pHalEndOfBoot HalEndOfBoot;
1060 pHalMirrorVerify HalMirrorVerify;
1061 } HAL_DISPATCH, *PHAL_DISPATCH;
1062
1063 #if defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTHAL_)
1064 extern NTSYSAPI PHAL_DISPATCH HalDispatchTable;
1065 #define HALDISPATCH ((PHAL_DISPATCH)&HalDispatchTable)
1066 #else
1067 extern __declspec(dllexport) HAL_DISPATCH HalDispatchTable;
1068 #define HALDISPATCH (&HalDispatchTable)
1069 #endif
1070
1071 #define HAL_DISPATCH_VERSION 3
1072 #define HalDispatchTableVersion HALDISPATCH->Version
1073 #define HalQuerySystemInformation HALDISPATCH->HalQuerySystemInformation
1074 #define HalSetSystemInformation HALDISPATCH->HalSetSystemInformation
1075 #define HalQueryBusSlots HALDISPATCH->HalQueryBusSlots
1076 #define HalReferenceHandlerForBus HALDISPATCH->HalReferenceHandlerForBus
1077 #define HalReferenceBusHandler HALDISPATCH->HalReferenceBusHandler
1078 #define HalDereferenceBusHandler HALDISPATCH->HalDereferenceBusHandler
1079 #define HalInitPnpDriver HALDISPATCH->HalInitPnpDriver
1080 #define HalInitPowerManagement HALDISPATCH->HalInitPowerManagement
1081 #define HalGetDmaAdapter HALDISPATCH->HalGetDmaAdapter
1082 #define HalGetInterruptTranslator HALDISPATCH->HalGetInterruptTranslator
1083 #define HalStartMirroring HALDISPATCH->HalStartMirroring
1084 #define HalEndMirroring HALDISPATCH->HalEndMirroring
1085 #define HalMirrorPhysicalMemory HALDISPATCH->HalMirrorPhysicalMemory
1086 #define HalEndOfBoot HALDISPATCH->HalEndOfBoot
1087 #define HalMirrorVerify HALDISPATCH->HalMirrorVerify
1088
1089 typedef struct _FILE_ALIGNMENT_INFORMATION {
1090 ULONG AlignmentRequirement;
1091 } FILE_ALIGNMENT_INFORMATION, *PFILE_ALIGNMENT_INFORMATION;
1092
1093 typedef struct _FILE_NAME_INFORMATION {
1094 ULONG FileNameLength;
1095 WCHAR FileName[1];
1096 } FILE_NAME_INFORMATION, *PFILE_NAME_INFORMATION;
1097
1098
1099 typedef struct _FILE_ATTRIBUTE_TAG_INFORMATION {
1100 ULONG FileAttributes;
1101 ULONG ReparseTag;
1102 } FILE_ATTRIBUTE_TAG_INFORMATION, *PFILE_ATTRIBUTE_TAG_INFORMATION;
1103
1104 typedef struct _FILE_DISPOSITION_INFORMATION {
1105 BOOLEAN DeleteFile;
1106 } FILE_DISPOSITION_INFORMATION, *PFILE_DISPOSITION_INFORMATION;
1107
1108 typedef struct _FILE_END_OF_FILE_INFORMATION {
1109 LARGE_INTEGER EndOfFile;
1110 } FILE_END_OF_FILE_INFORMATION, *PFILE_END_OF_FILE_INFORMATION;
1111
1112 typedef struct _FILE_VALID_DATA_LENGTH_INFORMATION {
1113 LARGE_INTEGER ValidDataLength;
1114 } FILE_VALID_DATA_LENGTH_INFORMATION, *PFILE_VALID_DATA_LENGTH_INFORMATION;
1115
1116 typedef union _FILE_SEGMENT_ELEMENT {
1117 PVOID64 Buffer;
1118 ULONGLONG Alignment;
1119 }FILE_SEGMENT_ELEMENT, *PFILE_SEGMENT_ELEMENT;
1120
1121 #define SE_UNSOLICITED_INPUT_PRIVILEGE 6
1122
1123 typedef struct _KEY_USER_FLAGS_INFORMATION {
1124 ULONG UserFlags;
1125 } KEY_USER_FLAGS_INFORMATION, *PKEY_USER_FLAGS_INFORMATION;
1126
1127 #define PCI_ADDRESS_MEMORY_SPACE 0x00000000
1128
1129 typedef struct _OSVERSIONINFOA {
1130 ULONG dwOSVersionInfoSize;
1131 ULONG dwMajorVersion;
1132 ULONG dwMinorVersion;
1133 ULONG dwBuildNumber;
1134 ULONG dwPlatformId;
1135 CHAR szCSDVersion[128];
1136 } OSVERSIONINFOA, *POSVERSIONINFOA, *LPOSVERSIONINFOA;
1137
1138 typedef struct _OSVERSIONINFOW {
1139 ULONG dwOSVersionInfoSize;
1140 ULONG dwMajorVersion;
1141 ULONG dwMinorVersion;
1142 ULONG dwBuildNumber;
1143 ULONG dwPlatformId;
1144 WCHAR szCSDVersion[128];
1145 } OSVERSIONINFOW, *POSVERSIONINFOW, *LPOSVERSIONINFOW, RTL_OSVERSIONINFOW, *PRTL_OSVERSIONINFOW;
1146
1147 #ifdef UNICODE
1148 typedef OSVERSIONINFOW OSVERSIONINFO;
1149 typedef POSVERSIONINFOW POSVERSIONINFO;
1150 typedef LPOSVERSIONINFOW LPOSVERSIONINFO;
1151 #else
1152 typedef OSVERSIONINFOA OSVERSIONINFO;
1153 typedef POSVERSIONINFOA POSVERSIONINFO;
1154 typedef LPOSVERSIONINFOA LPOSVERSIONINFO;
1155 #endif // UNICODE
1156
1157 typedef struct _OSVERSIONINFOEXA {
1158 ULONG dwOSVersionInfoSize;
1159 ULONG dwMajorVersion;
1160 ULONG dwMinorVersion;
1161 ULONG dwBuildNumber;
1162 ULONG dwPlatformId;
1163 CHAR szCSDVersion[128];
1164 USHORT wServicePackMajor;
1165 USHORT wServicePackMinor;
1166 USHORT wSuiteMask;
1167 UCHAR wProductType;
1168 UCHAR wReserved;
1169 } OSVERSIONINFOEXA, *POSVERSIONINFOEXA, *LPOSVERSIONINFOEXA;
1170
1171 typedef struct _OSVERSIONINFOEXW {
1172 ULONG dwOSVersionInfoSize;
1173 ULONG dwMajorVersion;
1174 ULONG dwMinorVersion;
1175 ULONG dwBuildNumber;
1176 ULONG dwPlatformId;
1177 WCHAR szCSDVersion[128];
1178 USHORT wServicePackMajor;
1179 USHORT wServicePackMinor;
1180 USHORT wSuiteMask;
1181 UCHAR wProductType;
1182 UCHAR wReserved;
1183 } OSVERSIONINFOEXW, *POSVERSIONINFOEXW, *LPOSVERSIONINFOEXW, RTL_OSVERSIONINFOEXW, *PRTL_OSVERSIONINFOEXW;
1184
1185 #ifdef UNICODE
1186 typedef OSVERSIONINFOEXW OSVERSIONINFOEX;
1187 typedef POSVERSIONINFOEXW POSVERSIONINFOEX;
1188 typedef LPOSVERSIONINFOEXW LPOSVERSIONINFOEX;
1189 #else
1190 typedef OSVERSIONINFOEXA OSVERSIONINFOEX;
1191 typedef POSVERSIONINFOEXA POSVERSIONINFOEX;
1192 typedef LPOSVERSIONINFOEXA LPOSVERSIONINFOEX;
1193 #endif // UNICODE
1194
1195 NTSYSAPI
1196 ULONGLONG
1197 DDKAPI
1198 VerSetConditionMask(
1199 IN ULONGLONG ConditionMask,
1200 IN ULONG TypeMask,
1201 IN UCHAR Condition);
1202
1203 #define VER_SET_CONDITION(ConditionMask, TypeBitMask, ComparisonType) \
1204 ((ConditionMask) = VerSetConditionMask((ConditionMask), \
1205 (TypeBitMask), (ComparisonType)))
1206
1207 /* RtlVerifyVersionInfo() TypeMask */
1208
1209 #define VER_MINORVERSION 0x0000001
1210 #define VER_MAJORVERSION 0x0000002
1211 #define VER_BUILDNUMBER 0x0000004
1212 #define VER_PLATFORMID 0x0000008
1213 #define VER_SERVICEPACKMINOR 0x0000010
1214 #define VER_SERVICEPACKMAJOR 0x0000020
1215 #define VER_SUITENAME 0x0000040
1216 #define VER_PRODUCT_TYPE 0x0000080
1217
1218 /* RtlVerifyVersionInfo() ComparisonType */
1219
1220 #define VER_EQUAL 1
1221 #define VER_GREATER 2
1222 #define VER_GREATER_EQUAL 3
1223 #define VER_LESS 4
1224 #define VER_LESS_EQUAL 5
1225 #define VER_AND 6
1226 #define VER_OR 7
1227
1228 #define VER_CONDITION_MASK 7
1229 #define VER_NUM_BITS_PER_CONDITION_MASK 3
1230
1231 struct _RTL_RANGE;
1232
1233 typedef BOOLEAN
1234 (NTAPI *PRTL_CONFLICT_RANGE_CALLBACK) (
1235 PVOID Context,
1236 struct _RTL_RANGE *Range
1237 );
1238
1239 typedef enum _EVENT_TYPE {
1240 NotificationEvent,
1241 SynchronizationEvent
1242 } EVENT_TYPE;
1243
1244 typedef struct _KWAIT_BLOCK {
1245 LIST_ENTRY WaitListEntry;
1246 struct _KTHREAD * RESTRICTED_POINTER Thread;
1247 PVOID Object;
1248 struct _KWAIT_BLOCK * RESTRICTED_POINTER NextWaitBlock;
1249 USHORT WaitKey;
1250 UCHAR WaitType;
1251 UCHAR SpareByte;
1252 } KWAIT_BLOCK, *PKWAIT_BLOCK, *RESTRICTED_POINTER PRKWAIT_BLOCK;
1253
1254 typedef enum _KINTERRUPT_MODE {
1255 LevelSensitive,
1256 Latched
1257 } KINTERRUPT_MODE;
1258
1259 #define THREAD_WAIT_OBJECTS 3
1260
1261 typedef VOID
1262 (DDKAPI *PKINTERRUPT_ROUTINE)(
1263 VOID);
1264
1265 typedef enum _CREATE_FILE_TYPE {
1266 CreateFileTypeNone,
1267 CreateFileTypeNamedPipe,
1268 CreateFileTypeMailslot
1269 } CREATE_FILE_TYPE;
1270
1271 typedef struct _CONFIGURATION_INFORMATION {
1272 ULONG DiskCount;
1273 ULONG FloppyCount;
1274 ULONG CdRomCount;
1275 ULONG TapeCount;
1276 ULONG ScsiPortCount;
1277 ULONG SerialCount;
1278 ULONG ParallelCount;
1279 BOOLEAN AtDiskPrimaryAddressClaimed;
1280 BOOLEAN AtDiskSecondaryAddressClaimed;
1281 ULONG Version;
1282 ULONG MediumChangerCount;
1283 } CONFIGURATION_INFORMATION, *PCONFIGURATION_INFORMATION;
1284
1285 typedef enum _CONFIGURATION_TYPE {
1286 ArcSystem,
1287 CentralProcessor,
1288 FloatingPointProcessor,
1289 PrimaryIcache,
1290 PrimaryDcache,
1291 SecondaryIcache,
1292 SecondaryDcache,
1293 SecondaryCache,
1294 EisaAdapter,
1295 TcAdapter,
1296 ScsiAdapter,
1297 DtiAdapter,
1298 MultiFunctionAdapter,
1299 DiskController,
1300 TapeController,
1301 CdromController,
1302 WormController,
1303 SerialController,
1304 NetworkController,
1305 DisplayController,
1306 ParallelController,
1307 PointerController,
1308 KeyboardController,
1309 AudioController,
1310 OtherController,
1311 DiskPeripheral,
1312 FloppyDiskPeripheral,
1313 TapePeripheral,
1314 ModemPeripheral,
1315 MonitorPeripheral,
1316 PrinterPeripheral,
1317 PointerPeripheral,
1318 KeyboardPeripheral,
1319 TerminalPeripheral,
1320 OtherPeripheral,
1321 LinePeripheral,
1322 NetworkPeripheral,
1323 SystemMemory,
1324 DockingInformation,
1325 RealModeIrqRoutingTable,
1326 RealModePCIEnumeration,
1327 MaximumType
1328 } CONFIGURATION_TYPE, *PCONFIGURATION_TYPE;
1329
1330 #define IO_FORCE_ACCESS_CHECK 0x001
1331 #define IO_NO_PARAMETER_CHECKING 0x100
1332
1333 #define IO_REPARSE 0x0
1334 #define IO_REMOUNT 0x1
1335
1336 typedef NTSTATUS
1337 (DDKAPI *PIO_QUERY_DEVICE_ROUTINE)(
1338 IN PVOID Context,
1339 IN PUNICODE_STRING PathName,
1340 IN INTERFACE_TYPE BusType,
1341 IN ULONG BusNumber,
1342 IN PKEY_VALUE_FULL_INFORMATION *BusInformation,
1343 IN CONFIGURATION_TYPE ControllerType,
1344 IN ULONG ControllerNumber,
1345 IN PKEY_VALUE_FULL_INFORMATION *ControllerInformation,
1346 IN CONFIGURATION_TYPE PeripheralType,
1347 IN ULONG PeripheralNumber,
1348 IN PKEY_VALUE_FULL_INFORMATION *PeripheralInformation);
1349
1350 typedef enum _IO_QUERY_DEVICE_DATA_FORMAT {
1351 IoQueryDeviceIdentifier = 0,
1352 IoQueryDeviceConfigurationData,
1353 IoQueryDeviceComponentInformation,
1354 IoQueryDeviceMaxData
1355 } IO_QUERY_DEVICE_DATA_FORMAT, *PIO_QUERY_DEVICE_DATA_FORMAT;
1356
1357 typedef enum _KBUGCHECK_CALLBACK_REASON {
1358 KbCallbackInvalid,
1359 KbCallbackReserved1,
1360 KbCallbackSecondaryDumpData,
1361 KbCallbackDumpIo,
1362 } KBUGCHECK_CALLBACK_REASON;
1363
1364 struct _KBUGCHECK_REASON_CALLBACK_RECORD;
1365
1366 typedef VOID
1367 (DDKAPI *PKBUGCHECK_REASON_CALLBACK_ROUTINE)(
1368 IN KBUGCHECK_CALLBACK_REASON Reason,
1369 IN struct _KBUGCHECK_REASON_CALLBACK_RECORD *Record,
1370 IN OUT PVOID ReasonSpecificData,
1371 IN ULONG ReasonSpecificDataLength);
1372
1373 typedef struct _KBUGCHECK_REASON_CALLBACK_RECORD {
1374 LIST_ENTRY Entry;
1375 PKBUGCHECK_REASON_CALLBACK_ROUTINE CallbackRoutine;
1376 PUCHAR Component;
1377 ULONG_PTR Checksum;
1378 KBUGCHECK_CALLBACK_REASON Reason;
1379 UCHAR State;
1380 } KBUGCHECK_REASON_CALLBACK_RECORD, *PKBUGCHECK_REASON_CALLBACK_RECORD;
1381
1382 typedef enum _KBUGCHECK_BUFFER_DUMP_STATE {
1383 BufferEmpty,
1384 BufferInserted,
1385 BufferStarted,
1386 BufferFinished,
1387 BufferIncomplete
1388 } KBUGCHECK_BUFFER_DUMP_STATE;
1389
1390 typedef VOID
1391 (DDKAPI *PKBUGCHECK_CALLBACK_ROUTINE)(
1392 IN PVOID Buffer,
1393 IN ULONG Length);
1394
1395 typedef struct _KBUGCHECK_CALLBACK_RECORD {
1396 LIST_ENTRY Entry;
1397 PKBUGCHECK_CALLBACK_ROUTINE CallbackRoutine;
1398 PVOID Buffer;
1399 ULONG Length;
1400 PUCHAR Component;
1401 ULONG_PTR Checksum;
1402 UCHAR State;
1403 } KBUGCHECK_CALLBACK_RECORD, *PKBUGCHECK_CALLBACK_RECORD;
1404
1405 typedef BOOLEAN
1406 (DDKAPI *PNMI_CALLBACK)(
1407 IN PVOID Context,
1408 IN BOOLEAN Handled);
1409
1410 /*
1411 * VOID
1412 * KeInitializeCallbackRecord(
1413 * IN PKBUGCHECK_CALLBACK_RECORD CallbackRecord)
1414 */
1415 #define KeInitializeCallbackRecord(CallbackRecord) \
1416 CallbackRecord->State = BufferEmpty;
1417
1418 typedef enum _KDPC_IMPORTANCE {
1419 LowImportance,
1420 MediumImportance,
1421 HighImportance
1422 } KDPC_IMPORTANCE;
1423
1424 typedef enum _MEMORY_CACHING_TYPE_ORIG {
1425 MmFrameBufferCached = 2
1426 } MEMORY_CACHING_TYPE_ORIG;
1427
1428 typedef enum _MEMORY_CACHING_TYPE {
1429 MmNonCached = FALSE,
1430 MmCached = TRUE,
1431 MmWriteCombined = MmFrameBufferCached,
1432 MmHardwareCoherentCached,
1433 MmNonCachedUnordered,
1434 MmUSWCCached,
1435 MmMaximumCacheType
1436 } MEMORY_CACHING_TYPE;
1437
1438 typedef enum _MM_PAGE_PRIORITY {
1439 LowPagePriority,
1440 NormalPagePriority = 16,
1441 HighPagePriority = 32
1442 } MM_PAGE_PRIORITY;
1443
1444 typedef enum _LOCK_OPERATION {
1445 IoReadAccess,
1446 IoWriteAccess,
1447 IoModifyAccess
1448 } LOCK_OPERATION;
1449
1450 #define FLUSH_MULTIPLE_MAXIMUM 32
1451
1452 typedef enum _MM_SYSTEM_SIZE {
1453 MmSmallSystem,
1454 MmMediumSystem,
1455 MmLargeSystem
1456 } MM_SYSTEMSIZE;
1457
1458 typedef struct _OBJECT_HANDLE_INFORMATION {
1459 ULONG HandleAttributes;
1460 ACCESS_MASK GrantedAccess;
1461 } OBJECT_HANDLE_INFORMATION, *POBJECT_HANDLE_INFORMATION;
1462
1463 typedef struct _CLIENT_ID {
1464 HANDLE UniqueProcess;
1465 HANDLE UniqueThread;
1466 } CLIENT_ID, *PCLIENT_ID;
1467
1468 typedef VOID
1469 (DDKAPI *PKSTART_ROUTINE)(
1470 IN PVOID StartContext);
1471
1472 typedef VOID
1473 (DDKAPI *PCREATE_PROCESS_NOTIFY_ROUTINE)(
1474 IN HANDLE ParentId,
1475 IN HANDLE ProcessId,
1476 IN BOOLEAN Create);
1477
1478 typedef VOID
1479 (DDKAPI *PCREATE_THREAD_NOTIFY_ROUTINE)(
1480 IN HANDLE ProcessId,
1481 IN HANDLE ThreadId,
1482 IN BOOLEAN Create);
1483
1484 typedef struct _IMAGE_INFO {
1485 _ANONYMOUS_UNION union {
1486 ULONG Properties;
1487 _ANONYMOUS_STRUCT struct {
1488 ULONG ImageAddressingMode : 8;
1489 ULONG SystemModeImage : 1;
1490 ULONG ImageMappedToAllPids : 1;
1491 ULONG Reserved : 22;
1492 } DUMMYSTRUCTNAME;
1493 } DUMMYUNIONNAME;
1494 PVOID ImageBase;
1495 ULONG ImageSelector;
1496 SIZE_T ImageSize;
1497 ULONG ImageSectionNumber;
1498 } IMAGE_INFO, *PIMAGE_INFO;
1499
1500 #define IMAGE_ADDRESSING_MODE_32BIT 3
1501
1502 typedef VOID
1503 (DDKAPI *PLOAD_IMAGE_NOTIFY_ROUTINE)(
1504 IN PUNICODE_STRING FullImageName,
1505 IN HANDLE ProcessId,
1506 IN PIMAGE_INFO ImageInfo);
1507
1508 #pragma pack(push,4)
1509 typedef enum _BUS_DATA_TYPE {
1510 ConfigurationSpaceUndefined = -1,
1511 Cmos,
1512 EisaConfiguration,
1513 Pos,
1514 CbusConfiguration,
1515 PCIConfiguration,
1516 VMEConfiguration,
1517 NuBusConfiguration,
1518 PCMCIAConfiguration,
1519 MPIConfiguration,
1520 MPSAConfiguration,
1521 PNPISAConfiguration,
1522 SgiInternalConfiguration,
1523 MaximumBusDataType
1524 } BUS_DATA_TYPE, *PBUS_DATA_TYPE;
1525 #pragma pack(pop)
1526
1527 typedef struct _NT_TIB {
1528 struct _EXCEPTION_REGISTRATION_RECORD *ExceptionList;
1529 PVOID StackBase;
1530 PVOID StackLimit;
1531 PVOID SubSystemTib;
1532 _ANONYMOUS_UNION union {
1533 PVOID FiberData;
1534 ULONG Version;
1535 } DUMMYUNIONNAME;
1536 PVOID ArbitraryUserPointer;
1537 struct _NT_TIB *Self;
1538 } NT_TIB, *PNT_TIB;
1539
1540 typedef struct _NT_TIB32 {
1541 ULONG ExceptionList;
1542 ULONG StackBase;
1543 ULONG StackLimit;
1544 ULONG SubSystemTib;
1545 __GNU_EXTENSION union {
1546 ULONG FiberData;
1547 ULONG Version;
1548 };
1549 ULONG ArbitraryUserPointer;
1550 ULONG Self;
1551 } NT_TIB32,*PNT_TIB32;
1552
1553 typedef struct _NT_TIB64 {
1554 ULONG64 ExceptionList;
1555 ULONG64 StackBase;
1556 ULONG64 StackLimit;
1557 ULONG64 SubSystemTib;
1558 __GNU_EXTENSION union {
1559 ULONG64 FiberData;
1560 ULONG Version;
1561 };
1562 ULONG64 ArbitraryUserPointer;
1563 ULONG64 Self;
1564 } NT_TIB64,*PNT_TIB64;
1565
1566 typedef enum _PROCESSINFOCLASS {
1567 ProcessBasicInformation,
1568 ProcessQuotaLimits,
1569 ProcessIoCounters,
1570 ProcessVmCounters,
1571 ProcessTimes,
1572 ProcessBasePriority,
1573 ProcessRaisePriority,
1574 ProcessDebugPort,
1575 ProcessExceptionPort,
1576 ProcessAccessToken,
1577 ProcessLdtInformation,
1578 ProcessLdtSize,
1579 ProcessDefaultHardErrorMode,
1580 ProcessIoPortHandlers,
1581 ProcessPooledUsageAndLimits,
1582 ProcessWorkingSetWatch,
1583 ProcessUserModeIOPL,
1584 ProcessEnableAlignmentFaultFixup,
1585 ProcessPriorityClass,
1586 ProcessWx86Information,
1587 ProcessHandleCount,
1588 ProcessAffinityMask,
1589 ProcessPriorityBoost,
1590 ProcessDeviceMap,
1591 ProcessSessionInformation,
1592 ProcessForegroundInformation,
1593 ProcessWow64Information,
1594 ProcessImageFileName,
1595 ProcessLUIDDeviceMapsEnabled,
1596 ProcessBreakOnTermination,
1597 ProcessDebugObjectHandle,
1598 ProcessDebugFlags,
1599 ProcessHandleTracing,
1600 ProcessIoPriority,
1601 ProcessExecuteFlags,
1602 ProcessTlsInformation,
1603 ProcessCookie,
1604 ProcessImageInformation,
1605 ProcessCycleTime,
1606 ProcessPagePriority,
1607 ProcessInstrumentationCallback,
1608 MaxProcessInfoClass
1609 } PROCESSINFOCLASS;
1610
1611 typedef enum _THREADINFOCLASS {
1612 ThreadBasicInformation,
1613 ThreadTimes,
1614 ThreadPriority,
1615 ThreadBasePriority,
1616 ThreadAffinityMask,
1617 ThreadImpersonationToken,
1618 ThreadDescriptorTableEntry,
1619 ThreadEnableAlignmentFaultFixup,
1620 ThreadEventPair_Reusable,
1621 ThreadQuerySetWin32StartAddress,
1622 ThreadZeroTlsCell,
1623 ThreadPerformanceCount,
1624 ThreadAmILastThread,
1625 ThreadIdealProcessor,
1626 ThreadPriorityBoost,
1627 ThreadSetTlsArrayAddress,
1628 ThreadIsIoPending,
1629 ThreadHideFromDebugger,
1630 ThreadBreakOnTermination,
1631 ThreadSwitchLegacyState,
1632 ThreadIsTerminated,
1633 ThreadLastSystemCall,
1634 ThreadIoPriority,
1635 ThreadCycleTime,
1636 ThreadPagePriority,
1637 ThreadActualBasePriority,
1638 MaxThreadInfoClass
1639 } THREADINFOCLASS;
1640
1641 typedef struct _PROCESS_BASIC_INFORMATION
1642 {
1643 NTSTATUS ExitStatus;
1644 struct _PEB *PebBaseAddress;
1645 ULONG_PTR AffinityMask;
1646 KPRIORITY BasePriority;
1647 ULONG_PTR UniqueProcessId;
1648 ULONG_PTR InheritedFromUniqueProcessId;
1649 } PROCESS_BASIC_INFORMATION,*PPROCESS_BASIC_INFORMATION;
1650
1651 typedef struct _PROCESS_WS_WATCH_INFORMATION
1652 {
1653 PVOID FaultingPc;
1654 PVOID FaultingVa;
1655 } PROCESS_WS_WATCH_INFORMATION, *PPROCESS_WS_WATCH_INFORMATION;
1656
1657 typedef struct _PROCESS_DEVICEMAP_INFORMATION
1658 {
1659 __GNU_EXTENSION union
1660 {
1661 struct
1662 {
1663 HANDLE DirectoryHandle;
1664 } Set;
1665 struct
1666 {
1667 ULONG DriveMap;
1668 UCHAR DriveType[32];
1669 } Query;
1670 };
1671 } PROCESS_DEVICEMAP_INFORMATION, *PPROCESS_DEVICEMAP_INFORMATION;
1672
1673 typedef struct _KERNEL_USER_TIMES
1674 {
1675 LARGE_INTEGER CreateTime;
1676 LARGE_INTEGER ExitTime;
1677 LARGE_INTEGER KernelTime;
1678 LARGE_INTEGER UserTime;
1679 } KERNEL_USER_TIMES, *PKERNEL_USER_TIMES;
1680
1681 typedef struct _PROCESS_ACCESS_TOKEN
1682 {
1683 HANDLE Token;
1684 HANDLE Thread;
1685 } PROCESS_ACCESS_TOKEN, *PPROCESS_ACCESS_TOKEN;
1686
1687 typedef struct _PROCESS_SESSION_INFORMATION
1688 {
1689 ULONG SessionId;
1690 } PROCESS_SESSION_INFORMATION, *PPROCESS_SESSION_INFORMATION;
1691
1692 typedef VOID
1693 (DDKAPI *PREQUEST_POWER_COMPLETE)(
1694 IN PDEVICE_OBJECT DeviceObject,
1695 IN UCHAR MinorFunction,
1696 IN POWER_STATE PowerState,
1697 IN PVOID Context,
1698 IN PIO_STATUS_BLOCK IoStatus);
1699
1700 typedef enum _TRACE_INFORMATION_CLASS {
1701 TraceIdClass,
1702 TraceHandleClass,
1703 TraceEnableFlagsClass,
1704 TraceEnableLevelClass,
1705 GlobalLoggerHandleClass,
1706 EventLoggerHandleClass,
1707 AllLoggerHandlesClass,
1708 TraceHandleByNameClass
1709 } TRACE_INFORMATION_CLASS;
1710
1711 typedef enum _REG_NOTIFY_CLASS
1712 {
1713 RegNtDeleteKey,
1714 RegNtPreDeleteKey = RegNtDeleteKey,
1715 RegNtSetValueKey,
1716 RegNtPreSetValueKey = RegNtSetValueKey,
1717 RegNtDeleteValueKey,
1718 RegNtPreDeleteValueKey = RegNtDeleteValueKey,
1719 RegNtSetInformationKey,
1720 RegNtPreSetInformationKey = RegNtSetInformationKey,
1721 RegNtRenameKey,
1722 RegNtPreRenameKey = RegNtRenameKey,
1723 RegNtEnumerateKey,
1724 RegNtPreEnumerateKey = RegNtEnumerateKey,
1725 RegNtEnumerateValueKey,
1726 RegNtPreEnumerateValueKey = RegNtEnumerateValueKey,
1727 RegNtQueryKey,
1728 RegNtPreQueryKey = RegNtQueryKey,
1729 RegNtQueryValueKey,
1730 RegNtPreQueryValueKey = RegNtQueryValueKey,
1731 RegNtQueryMultipleValueKey,
1732 RegNtPreQueryMultipleValueKey = RegNtQueryMultipleValueKey,
1733 RegNtPreCreateKey,
1734 RegNtPostCreateKey,
1735 RegNtPreOpenKey,
1736 RegNtPostOpenKey,
1737 RegNtKeyHandleClose,
1738 RegNtPreKeyHandleClose = RegNtKeyHandleClose,
1739 RegNtPostDeleteKey,
1740 RegNtPostSetValueKey,
1741 RegNtPostDeleteValueKey,
1742 RegNtPostSetInformationKey,
1743 RegNtPostRenameKey,
1744 RegNtPostEnumerateKey,
1745 RegNtPostEnumerateValueKey,
1746 RegNtPostQueryKey,
1747 RegNtPostQueryValueKey,
1748 RegNtPostQueryMultipleValueKey,
1749 RegNtPostKeyHandleClose,
1750 RegNtPreCreateKeyEx,
1751 RegNtPostCreateKeyEx,
1752 RegNtPreOpenKeyEx,
1753 RegNtPostOpenKeyEx
1754 } REG_NOTIFY_CLASS, *PREG_NOTIFY_CLASS;
1755
1756 typedef NTSTATUS
1757 (NTAPI *PEX_CALLBACK_FUNCTION)(
1758 IN PVOID CallbackContext,
1759 IN PVOID Argument1,
1760 IN PVOID Argument2
1761 );
1762
1763 typedef struct _REG_DELETE_KEY_INFORMATION
1764 {
1765 PVOID Object;
1766 } REG_DELETE_KEY_INFORMATION, *PREG_DELETE_KEY_INFORMATION;
1767
1768 typedef struct _REG_SET_VALUE_KEY_INFORMATION
1769 {
1770 PVOID Object;
1771 PUNICODE_STRING ValueName;
1772 ULONG TitleIndex;
1773 ULONG Type;
1774 PVOID Data;
1775 ULONG DataSize;
1776 } REG_SET_VALUE_KEY_INFORMATION, *PREG_SET_VALUE_KEY_INFORMATION;
1777
1778 typedef struct _REG_DELETE_VALUE_KEY_INFORMATION
1779 {
1780 PVOID Object;
1781 PUNICODE_STRING ValueName;
1782 } REG_DELETE_VALUE_KEY_INFORMATION, *PREG_DELETE_VALUE_KEY_INFORMATION;
1783
1784 typedef struct _REG_SET_INFORMATION_KEY_INFORMATION
1785 {
1786 PVOID Object;
1787 KEY_SET_INFORMATION_CLASS KeySetInformationClass;
1788 PVOID KeySetInformation;
1789 ULONG KeySetInformationLength;
1790 } REG_SET_INFORMATION_KEY_INFORMATION, *PREG_SET_INFORMATION_KEY_INFORMATION;
1791
1792 typedef struct _REG_ENUMERATE_KEY_INFORMATION
1793 {
1794 PVOID Object;
1795 ULONG Index;
1796 KEY_INFORMATION_CLASS KeyInformationClass;
1797 PVOID KeyInformation;
1798 ULONG Length;
1799 PULONG ResultLength;
1800 } REG_ENUMERATE_KEY_INFORMATION, *PREG_ENUMERATE_KEY_INFORMATION;
1801
1802 typedef struct _REG_ENUMERATE_VALUE_KEY_INFORMATION
1803 {
1804 PVOID Object;
1805 ULONG Index;
1806 KEY_VALUE_INFORMATION_CLASS KeyValueInformationClass;
1807 PVOID KeyValueInformation;
1808 ULONG Length;
1809 PULONG ResultLength;
1810 } REG_ENUMERATE_VALUE_KEY_INFORMATION, *PREG_ENUMERATE_VALUE_KEY_INFORMATION;
1811
1812 typedef struct _REG_QUERY_KEY_INFORMATION
1813 {
1814 PVOID Object;
1815 KEY_INFORMATION_CLASS KeyInformationClass;
1816 PVOID KeyInformation;
1817 ULONG Length;
1818 PULONG ResultLength;
1819 } REG_QUERY_KEY_INFORMATION, *PREG_QUERY_KEY_INFORMATION;
1820
1821 typedef struct _REG_QUERY_VALUE_KEY_INFORMATION
1822 {
1823 PVOID Object;
1824 PUNICODE_STRING ValueName;
1825 KEY_VALUE_INFORMATION_CLASS KeyValueInformationClass;
1826 PVOID KeyValueInformation;
1827 ULONG Length;
1828 PULONG ResultLength;
1829 } REG_QUERY_VALUE_KEY_INFORMATION, *PREG_QUERY_VALUE_KEY_INFORMATION;
1830
1831 typedef struct _REG_QUERY_MULTIPLE_VALUE_KEY_INFORMATION
1832 {
1833 PVOID Object;
1834 PKEY_VALUE_ENTRY ValueEntries;
1835 ULONG EntryCount;
1836 PVOID ValueBuffer;
1837 PULONG BufferLength;
1838 PULONG RequiredBufferLength;
1839 } REG_QUERY_MULTIPLE_VALUE_KEY_INFORMATION, *PREG_QUERY_MULTIPLE_VALUE_KEY_INFORMATION;
1840
1841 typedef struct _REG_PRE_CREATE_KEY_INFORMATION
1842 {
1843 PUNICODE_STRING CompleteName;
1844 } REG_PRE_CREATE_KEY_INFORMATION, *PREG_PRE_CREATE_KEY_INFORMATION;
1845
1846 typedef struct _REG_POST_CREATE_KEY_INFORMATION
1847 {
1848 PUNICODE_STRING CompleteName;
1849 PVOID Object;
1850 NTSTATUS Status;
1851 } REG_POST_CREATE_KEY_INFORMATION, *PREG_POST_CREATE_KEY_INFORMATION;
1852
1853 typedef struct _REG_PRE_OPEN_KEY_INFORMATION
1854 {
1855 PUNICODE_STRING CompleteName;
1856 } REG_PRE_OPEN_KEY_INFORMATION, *PREG_PRE_OPEN_KEY_INFORMATION;
1857
1858 typedef struct _REG_POST_OPEN_KEY_INFORMATION
1859 {
1860 PUNICODE_STRING CompleteName;
1861 PVOID Object;
1862 NTSTATUS Status;
1863 } REG_POST_OPEN_KEY_INFORMATION, *PREG_POST_OPEN_KEY_INFORMATION;
1864
1865 typedef struct _REG_POST_OPERATION_INFORMATION
1866 {
1867 PVOID Object;
1868 NTSTATUS Status;
1869 } REG_POST_OPERATION_INFORMATION,*PREG_POST_OPERATION_INFORMATION;
1870
1871 typedef struct _REG_KEY_HANDLE_CLOSE_INFORMATION
1872 {
1873 PVOID Object;
1874 } REG_KEY_HANDLE_CLOSE_INFORMATION, *PREG_KEY_HANDLE_CLOSE_INFORMATION;
1875
1876 /*
1877 ** Storage structures
1878 */
1879 typedef enum _PARTITION_STYLE {
1880 PARTITION_STYLE_MBR,
1881 PARTITION_STYLE_GPT,
1882 PARTITION_STYLE_RAW
1883 } PARTITION_STYLE;
1884
1885 typedef struct _CREATE_DISK_MBR {
1886 ULONG Signature;
1887 } CREATE_DISK_MBR, *PCREATE_DISK_MBR;
1888
1889 typedef struct _CREATE_DISK_GPT {
1890 GUID DiskId;
1891 ULONG MaxPartitionCount;
1892 } CREATE_DISK_GPT, *PCREATE_DISK_GPT;
1893
1894 typedef struct _CREATE_DISK {
1895 PARTITION_STYLE PartitionStyle;
1896 _ANONYMOUS_UNION union {
1897 CREATE_DISK_MBR Mbr;
1898 CREATE_DISK_GPT Gpt;
1899 } DUMMYUNIONNAME;
1900 } CREATE_DISK, *PCREATE_DISK;
1901
1902 typedef struct _DISK_SIGNATURE {
1903 ULONG PartitionStyle;
1904 _ANONYMOUS_UNION union {
1905 struct {
1906 ULONG Signature;
1907 ULONG CheckSum;
1908 } Mbr;
1909 struct {
1910 GUID DiskId;
1911 } Gpt;
1912 } DUMMYUNIONNAME;
1913 } DISK_SIGNATURE, *PDISK_SIGNATURE;
1914
1915 typedef VOID
1916 (FASTCALL*PTIME_UPDATE_NOTIFY_ROUTINE)(
1917 IN HANDLE ThreadId,
1918 IN KPROCESSOR_MODE Mode);
1919
1920 #define DBG_STATUS_CONTROL_C 1
1921 #define DBG_STATUS_SYSRQ 2
1922 #define DBG_STATUS_BUGCHECK_FIRST 3
1923 #define DBG_STATUS_BUGCHECK_SECOND 4
1924 #define DBG_STATUS_FATAL 5
1925 #define DBG_STATUS_DEBUG_CONTROL 6
1926 #define DBG_STATUS_WORKER 7
1927
1928 typedef struct _PHYSICAL_MEMORY_RANGE {
1929 PHYSICAL_ADDRESS BaseAddress;
1930 LARGE_INTEGER NumberOfBytes;
1931 } PHYSICAL_MEMORY_RANGE, *PPHYSICAL_MEMORY_RANGE;
1932
1933 typedef ULONG_PTR
1934 (NTAPI *PDRIVER_VERIFIER_THUNK_ROUTINE)(
1935 IN PVOID Context);
1936
1937 typedef struct _DRIVER_VERIFIER_THUNK_PAIRS {
1938 PDRIVER_VERIFIER_THUNK_ROUTINE PristineRoutine;
1939 PDRIVER_VERIFIER_THUNK_ROUTINE NewRoutine;
1940 } DRIVER_VERIFIER_THUNK_PAIRS, *PDRIVER_VERIFIER_THUNK_PAIRS;
1941
1942 #define DRIVER_VERIFIER_SPECIAL_POOLING 0x0001
1943 #define DRIVER_VERIFIER_FORCE_IRQL_CHECKING 0x0002
1944 #define DRIVER_VERIFIER_INJECT_ALLOCATION_FAILURES 0x0004
1945 #define DRIVER_VERIFIER_TRACK_POOL_ALLOCATIONS 0x0008
1946 #define DRIVER_VERIFIER_IO_CHECKING 0x0010
1947
1948 #define HASH_STRING_ALGORITHM_DEFAULT 0
1949 #define HASH_STRING_ALGORITHM_X65599 1
1950 #define HASH_STRING_ALGORITHM_INVALID 0xffffffff
1951
1952 typedef VOID
1953 (DDKAPI *PTIMER_APC_ROUTINE)(
1954 IN PVOID TimerContext,
1955 IN ULONG TimerLowValue,
1956 IN LONG TimerHighValue);
1957
1958
1959
1960 /*
1961 ** WMI structures
1962 */
1963
1964 typedef VOID
1965 (DDKAPI *WMI_NOTIFICATION_CALLBACK)(
1966 PVOID Wnode,
1967 PVOID Context);
1968
1969
1970 /*
1971 ** Architecture specific structures
1972 */
1973 #define PCR_MINOR_VERSION 1
1974 #define PCR_MAJOR_VERSION 1
1975
1976 #ifdef _X86_
1977
1978 #define SIZE_OF_80387_REGISTERS 80
1979 #define CONTEXT_i386 0x10000
1980 #define CONTEXT_i486 0x10000
1981 #define CONTEXT_CONTROL (CONTEXT_i386|0x00000001L)
1982 #define CONTEXT_INTEGER (CONTEXT_i386|0x00000002L)
1983 #define CONTEXT_SEGMENTS (CONTEXT_i386|0x00000004L)
1984 #define CONTEXT_FLOATING_POINT (CONTEXT_i386|0x00000008L)
1985 #define CONTEXT_DEBUG_REGISTERS (CONTEXT_i386|0x00000010L)
1986 #define CONTEXT_EXTENDED_REGISTERS (CONTEXT_i386|0x00000020L)
1987 #define CONTEXT_FULL (CONTEXT_CONTROL|CONTEXT_INTEGER|CONTEXT_SEGMENTS)
1988 #define MAXIMUM_SUPPORTED_EXTENSION 512
1989
1990 typedef struct _FLOATING_SAVE_AREA {
1991 ULONG ControlWord;
1992 ULONG StatusWord;
1993 ULONG TagWord;
1994 ULONG ErrorOffset;
1995 ULONG ErrorSelector;
1996 ULONG DataOffset;
1997 ULONG DataSelector;
1998 UCHAR RegisterArea[SIZE_OF_80387_REGISTERS];
1999 ULONG Cr0NpxState;
2000 } FLOATING_SAVE_AREA, *PFLOATING_SAVE_AREA;
2001
2002 typedef struct _CONTEXT {
2003 ULONG ContextFlags;
2004 ULONG Dr0;
2005 ULONG Dr1;
2006 ULONG Dr2;
2007 ULONG Dr3;
2008 ULONG Dr6;
2009 ULONG Dr7;
2010 FLOATING_SAVE_AREA FloatSave;
2011 ULONG SegGs;
2012 ULONG SegFs;
2013 ULONG SegEs;
2014 ULONG SegDs;
2015 ULONG Edi;
2016 ULONG Esi;
2017 ULONG Ebx;
2018 ULONG Edx;
2019 ULONG Ecx;
2020 ULONG Eax;
2021 ULONG Ebp;
2022 ULONG Eip;
2023 ULONG SegCs;
2024 ULONG EFlags;
2025 ULONG Esp;
2026 ULONG SegSs;
2027 UCHAR ExtendedRegisters[MAXIMUM_SUPPORTED_EXTENSION];
2028 } CONTEXT;
2029
2030 //
2031 // Used to contain PFNs and PFN counts
2032 //
2033 typedef ULONG PFN_COUNT;
2034 typedef ULONG PFN_NUMBER, *PPFN_NUMBER;
2035 typedef LONG SPFN_NUMBER, *PSPFN_NUMBER;
2036
2037 #define PASSIVE_LEVEL 0
2038 #define LOW_LEVEL 0
2039 #define APC_LEVEL 1
2040 #define DISPATCH_LEVEL 2
2041 #define PROFILE_LEVEL 27
2042 #define CLOCK1_LEVEL 28
2043 #define CLOCK2_LEVEL 28
2044 #define IPI_LEVEL 29
2045 #define POWER_LEVEL 30
2046 #define HIGH_LEVEL 31
2047
2048 typedef struct _KPCR_TIB {
2049 PVOID ExceptionList; /* 00 */
2050 PVOID StackBase; /* 04 */
2051 PVOID StackLimit; /* 08 */
2052 PVOID SubSystemTib; /* 0C */
2053 _ANONYMOUS_UNION union {
2054 PVOID FiberData; /* 10 */
2055 ULONG Version; /* 10 */
2056 } DUMMYUNIONNAME;
2057 PVOID ArbitraryUserPointer; /* 14 */
2058 struct _KPCR_TIB *Self; /* 18 */
2059 } KPCR_TIB, *PKPCR_TIB; /* 1C */
2060
2061 typedef struct _KPCR {
2062 KPCR_TIB Tib; /* 00 */
2063 struct _KPCR *Self; /* 1C */
2064 struct _KPRCB *Prcb; /* 20 */
2065 KIRQL Irql; /* 24 */
2066 ULONG IRR; /* 28 */
2067 ULONG IrrActive; /* 2C */
2068 ULONG IDR; /* 30 */
2069 PVOID KdVersionBlock; /* 34 */
2070 PUSHORT IDT; /* 38 */
2071 PUSHORT GDT; /* 3C */
2072 struct _KTSS *TSS; /* 40 */
2073 USHORT MajorVersion; /* 44 */
2074 USHORT MinorVersion; /* 46 */
2075 KAFFINITY SetMember; /* 48 */
2076 ULONG StallScaleFactor; /* 4C */
2077 UCHAR SpareUnused; /* 50 */
2078 UCHAR Number; /* 51 */
2079 UCHAR Spare0;
2080 UCHAR SecondLevelCacheAssociativity;
2081 ULONG VdmAlert;
2082 ULONG KernelReserved[14]; // For use by the kernel
2083 ULONG SecondLevelCacheSize;
2084 ULONG HalReserved[16]; // For use by Hal
2085 } KPCR, *PKPCR; /* 54 */
2086
2087 #define KeGetPcr() PCR
2088
2089 typedef struct _KFLOATING_SAVE {
2090 ULONG ControlWord;
2091 ULONG StatusWord;
2092 ULONG ErrorOffset;
2093 ULONG ErrorSelector;
2094 ULONG DataOffset;
2095 ULONG DataSelector;
2096 ULONG Cr0NpxState;
2097 ULONG Spare1;
2098 } KFLOATING_SAVE, *PKFLOATING_SAVE;
2099
2100 FORCEINLINE
2101 ULONG
2102 KeGetCurrentProcessorNumber(VOID)
2103 {
2104 return (ULONG)__readfsbyte(FIELD_OFFSET(KPCR, Number));
2105 }
2106
2107 NTHALAPI
2108 KIRQL
2109 DDKAPI
2110 KeGetCurrentIrql(
2111 VOID);
2112
2113 NTKERNELAPI
2114 PRKTHREAD
2115 NTAPI
2116 KeGetCurrentThread(
2117 VOID);
2118
2119 #define KI_USER_SHARED_DATA 0xffdf0000
2120
2121 #define PAGE_SIZE 0x1000
2122 #define PAGE_SHIFT 12L
2123
2124 #define SharedUserData ((KUSER_SHARED_DATA * CONST) KI_USER_SHARED_DATA)
2125
2126 extern NTKERNELAPI PVOID MmHighestUserAddress;
2127 extern NTKERNELAPI PVOID MmSystemRangeStart;
2128 extern NTKERNELAPI ULONG_PTR MmUserProbeAddress;
2129
2130 #define MM_HIGHEST_USER_ADDRESS MmHighestUserAddress
2131 #define MM_SYSTEM_RANGE_START MmSystemRangeStart
2132 #define MM_USER_PROBE_ADDRESS MmUserProbeAddress
2133 #define MM_LOWEST_USER_ADDRESS (PVOID)0x10000
2134 #define MM_LOWEST_SYSTEM_ADDRESS (PVOID)0xC0C00000
2135
2136 #define MM_KSEG0_BASE MM_SYSTEM_RANGE_START
2137 #define MM_SYSTEM_SPACE_END 0xFFFFFFFF
2138
2139 #elif defined(__x86_64__)
2140
2141 #define CONTEXT_AMD64 0x100000
2142 #if !defined(RC_INVOKED)
2143 #define CONTEXT_CONTROL (CONTEXT_AMD64 | 0x1L)
2144 #define CONTEXT_INTEGER (CONTEXT_AMD64 | 0x2L)
2145 #define CONTEXT_SEGMENTS (CONTEXT_AMD64 | 0x4L)
2146 #define CONTEXT_FLOATING_POINT (CONTEXT_AMD64 | 0x8L)
2147 #define CONTEXT_DEBUG_REGISTERS (CONTEXT_AMD64 | 0x10L)
2148
2149 #define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_FLOATING_POINT)
2150 #define CONTEXT_ALL (CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_SEGMENTS | CONTEXT_FLOATING_POINT | CONTEXT_DEBUG_REGISTERS)
2151
2152 #define CONTEXT_EXCEPTION_ACTIVE 0x8000000
2153 #define CONTEXT_SERVICE_ACTIVE 0x10000000
2154 #define CONTEXT_EXCEPTION_REQUEST 0x40000000
2155 #define CONTEXT_EXCEPTION_REPORTING 0x80000000
2156 #endif
2157
2158 typedef struct DECLSPEC_ALIGN(16) _M128A {
2159 ULONGLONG Low;
2160 LONGLONG High;
2161 } M128A, *PM128A;
2162
2163 typedef struct _XMM_SAVE_AREA32 {
2164 USHORT ControlWord;
2165 USHORT StatusWord;
2166 UCHAR TagWord;
2167 UCHAR Reserved1;
2168 USHORT ErrorOpcode;
2169 ULONG ErrorOffset;
2170 USHORT ErrorSelector;
2171 USHORT Reserved2;
2172 ULONG DataOffset;
2173 USHORT DataSelector;
2174 USHORT Reserved3;
2175 ULONG MxCsr;
2176 ULONG MxCsr_Mask;
2177 M128A FloatRegisters[8];
2178 M128A XmmRegisters[16];
2179 UCHAR Reserved4[96];
2180 } XMM_SAVE_AREA32, *PXMM_SAVE_AREA32;
2181
2182 typedef struct DECLSPEC_ALIGN(16) _CONTEXT {
2183 ULONG64 P1Home;
2184 ULONG64 P2Home;
2185 ULONG64 P3Home;
2186 ULONG64 P4Home;
2187 ULONG64 P5Home;
2188 ULONG64 P6Home;
2189
2190 /* Control flags */
2191 ULONG ContextFlags;
2192 ULONG MxCsr;
2193
2194 /* Segment */
2195 USHORT SegCs;
2196 USHORT SegDs;
2197 USHORT SegEs;
2198 USHORT SegFs;
2199 USHORT SegGs;
2200 USHORT SegSs;
2201 ULONG EFlags;
2202
2203 /* Debug */
2204 ULONG64 Dr0;
2205 ULONG64 Dr1;
2206 ULONG64 Dr2;
2207 ULONG64 Dr3;
2208 ULONG64 Dr6;
2209 ULONG64 Dr7;
2210
2211 /* Integer */
2212 ULONG64 Rax;
2213 ULONG64 Rcx;
2214 ULONG64 Rdx;
2215 ULONG64 Rbx;
2216 ULONG64 Rsp;
2217 ULONG64 Rbp;
2218 ULONG64 Rsi;
2219 ULONG64 Rdi;
2220 ULONG64 R8;
2221 ULONG64 R9;
2222 ULONG64 R10;
2223 ULONG64 R11;
2224 ULONG64 R12;
2225 ULONG64 R13;
2226 ULONG64 R14;
2227 ULONG64 R15;
2228
2229 /* Counter */
2230 ULONG64 Rip;
2231
2232 /* Floating point */
2233 union {
2234 XMM_SAVE_AREA32 FltSave;
2235 struct {
2236 M128A Header[2];
2237 M128A Legacy[8];
2238 M128A Xmm0;
2239 M128A Xmm1;
2240 M128A Xmm2;
2241 M128A Xmm3;
2242 M128A Xmm4;
2243 M128A Xmm5;
2244 M128A Xmm6;
2245 M128A Xmm7;
2246 M128A Xmm8;
2247 M128A Xmm9;
2248 M128A Xmm10;
2249 M128A Xmm11;
2250 M128A Xmm12;
2251 M128A Xmm13;
2252 M128A Xmm14;
2253 M128A Xmm15;
2254 } DUMMYSTRUCTNAME;
2255 } DUMMYUNIONNAME;
2256
2257 /* Vector */
2258 M128A VectorRegister[26];
2259 ULONG64 VectorControl;
2260
2261 /* Debug control */
2262 ULONG64 DebugControl;
2263 ULONG64 LastBranchToRip;
2264 ULONG64 LastBranchFromRip;
2265 ULONG64 LastExceptionToRip;
2266 ULONG64 LastExceptionFromRip;
2267 } CONTEXT;
2268
2269 //
2270 // Used to contain PFNs and PFN counts
2271 //
2272 typedef ULONG PFN_COUNT;
2273 typedef ULONG64 PFN_NUMBER, *PPFN_NUMBER;
2274 typedef LONG64 SPFN_NUMBER, *PSPFN_NUMBER;
2275
2276 #define PASSIVE_LEVEL 0
2277 #define LOW_LEVEL 0
2278 #define APC_LEVEL 1
2279 #define DISPATCH_LEVEL 2
2280 #define CLOCK_LEVEL 13
2281 #define IPI_LEVEL 14
2282 #define POWER_LEVEL 14
2283 #define PROFILE_LEVEL 15
2284 #define HIGH_LEVEL 15
2285
2286 #define PAGE_SIZE 0x1000
2287 #define PAGE_SHIFT 12L
2288 #define PTI_SHIFT 12L
2289 #define PDI_SHIFT 21L
2290 #define PPI_SHIFT 30L
2291 #define PXI_SHIFT 39L
2292 #define PTE_PER_PAGE 512
2293 #define PDE_PER_PAGE 512
2294 #define PPE_PER_PAGE 512
2295 #define PXE_PER_PAGE 512
2296 #define PTI_MASK_AMD64 (PTE_PER_PAGE - 1)
2297 #define PDI_MASK_AMD64 (PDE_PER_PAGE - 1)
2298 #define PPI_MASK (PPE_PER_PAGE - 1)
2299 #define PXI_MASK (PXE_PER_PAGE - 1)
2300
2301 #define PXE_BASE 0xFFFFF6FB7DBED000ULL
2302 #define PXE_SELFMAP 0xFFFFF6FB7DBEDF68ULL
2303 #define PPE_BASE 0xFFFFF6FB7DA00000ULL
2304 #define PDE_BASE 0xFFFFF6FB40000000ULL
2305 #define PTE_BASE 0xFFFFF68000000000ULL
2306 #define PXE_TOP 0xFFFFF6FB7DBEDFFFULL
2307 #define PPE_TOP 0xFFFFF6FB7DBFFFFFULL
2308 #define PDE_TOP 0xFFFFF6FB7FFFFFFFULL
2309 #define PTE_TOP 0xFFFFF6FFFFFFFFFFULL
2310
2311 extern NTKERNELAPI PVOID MmHighestUserAddress;
2312 extern NTKERNELAPI PVOID MmSystemRangeStart;
2313 extern NTKERNELAPI ULONG_PTR MmUserProbeAddress;
2314
2315 #define MM_HIGHEST_USER_ADDRESS MmHighestUserAddress
2316 #define MM_SYSTEM_RANGE_START MmSystemRangeStart
2317 #define MM_USER_PROBE_ADDRESS MmUserProbeAddress
2318 #define MM_LOWEST_USER_ADDRESS (PVOID)0x10000
2319 #define MM_LOWEST_SYSTEM_ADDRESS (PVOID)0xFFFF080000000000ULL
2320 #define KI_USER_SHARED_DATA 0xFFFFF78000000000ULL
2321
2322 #define SharedUserData ((PKUSER_SHARED_DATA const)KI_USER_SHARED_DATA)
2323 #define SharedInterruptTime (&SharedUserData->InterruptTime)
2324 #define SharedSystemTime (&SharedUserData->SystemTime)
2325 #define SharedTickCount (&SharedUserData->TickCount)
2326
2327 #define KeQueryInterruptTime() \
2328 (*(volatile ULONG64*)SharedInterruptTime)
2329 #define KeQuerySystemTime(CurrentCount) \
2330 *(ULONG64*)(CurrentCount) = *(volatile ULONG64*)SharedSystemTime
2331 #define KeQueryTickCount(CurrentCount) \
2332 *(ULONG64*)(CurrentCount) = *(volatile ULONG64*)SharedTickCount
2333
2334 typedef struct _KPCR
2335 {
2336 __GNU_EXTENSION union
2337 {
2338 NT_TIB NtTib;
2339 __GNU_EXTENSION struct
2340 {
2341 union _KGDTENTRY64 *GdtBase;
2342 struct _KTSS64 *TssBase;
2343 ULONG64 UserRsp;
2344 struct _KPCR *Self;
2345 struct _KPRCB *CurrentPrcb;
2346 PKSPIN_LOCK_QUEUE LockArray;
2347 PVOID Used_Self;
2348 };
2349 };
2350 union _KIDTENTRY64 *IdtBase;
2351 ULONG64 Unused[2];
2352 KIRQL Irql;
2353 UCHAR SecondLevelCacheAssociativity;
2354 UCHAR ObsoleteNumber;
2355 UCHAR Fill0;
2356 ULONG Unused0[3];
2357 USHORT MajorVersion;
2358 USHORT MinorVersion;
2359 ULONG StallScaleFactor;
2360 PVOID Unused1[3];
2361 ULONG KernelReserved[15];
2362 ULONG SecondLevelCacheSize;
2363 ULONG HalReserved[16];
2364 ULONG Unused2;
2365 PVOID KdVersionBlock;
2366 PVOID Unused3;
2367 ULONG PcrAlign1[24];
2368 } KPCR, *PKPCR;
2369
2370 typedef struct _KFLOATING_SAVE {
2371 ULONG Dummy;
2372 } KFLOATING_SAVE, *PKFLOATING_SAVE;
2373
2374 NTKERNELAPI
2375 PRKTHREAD
2376 NTAPI
2377 KeGetCurrentThread(
2378 VOID);
2379
2380 FORCEINLINE
2381 PKPCR
2382 KeGetPcr(VOID)
2383 {
2384 return (PKPCR)__readgsqword(FIELD_OFFSET(KPCR, Self));
2385 }
2386
2387 FORCEINLINE
2388 ULONG
2389 KeGetCurrentProcessorNumber(VOID)
2390 {
2391 return (ULONG)__readgsword(0x184);
2392 }
2393
2394 #elif defined(__PowerPC__)
2395
2396 //
2397 // Used to contain PFNs and PFN counts
2398 //
2399 typedef ULONG PFN_COUNT;
2400 typedef ULONG PFN_NUMBER, *PPFN_NUMBER;
2401 typedef LONG SPFN_NUMBER, *PSPFN_NUMBER;
2402
2403 #define PASSIVE_LEVEL 0
2404 #define LOW_LEVEL 0
2405 #define APC_LEVEL 1
2406 #define DISPATCH_LEVEL 2
2407 #define PROFILE_LEVEL 27
2408 #define CLOCK1_LEVEL 28
2409 #define CLOCK2_LEVEL 28
2410 #define IPI_LEVEL 29
2411 #define POWER_LEVEL 30
2412 #define HIGH_LEVEL 31
2413
2414 typedef struct _KFLOATING_SAVE {
2415 ULONG Dummy;
2416 } KFLOATING_SAVE, *PKFLOATING_SAVE;
2417
2418 typedef struct _KPCR_TIB {
2419 PVOID ExceptionList; /* 00 */
2420 PVOID StackBase; /* 04 */
2421 PVOID StackLimit; /* 08 */
2422 PVOID SubSystemTib; /* 0C */
2423 _ANONYMOUS_UNION union {
2424 PVOID FiberData; /* 10 */
2425 ULONG Version; /* 10 */
2426 } DUMMYUNIONNAME;
2427 PVOID ArbitraryUserPointer; /* 14 */
2428 struct _KPCR_TIB *Self; /* 18 */
2429 } KPCR_TIB, *PKPCR_TIB; /* 1C */
2430
2431 #define PCR_MINOR_VERSION 1
2432 #define PCR_MAJOR_VERSION 1
2433
2434 typedef struct _KPCR {
2435 KPCR_TIB Tib; /* 00 */
2436 struct _KPCR *Self; /* 1C */
2437 struct _KPRCB *Prcb; /* 20 */
2438 KIRQL Irql; /* 24 */
2439 ULONG IRR; /* 28 */
2440 ULONG IrrActive; /* 2C */
2441 ULONG IDR; /* 30 */
2442 PVOID KdVersionBlock; /* 34 */
2443 PUSHORT IDT; /* 38 */
2444 PUSHORT GDT; /* 3C */
2445 struct _KTSS *TSS; /* 40 */
2446 USHORT MajorVersion; /* 44 */
2447 USHORT MinorVersion; /* 46 */
2448 KAFFINITY SetMember; /* 48 */
2449 ULONG StallScaleFactor; /* 4C */
2450 UCHAR SpareUnused; /* 50 */
2451 UCHAR Number; /* 51 */
2452 } KPCR, *PKPCR; /* 54 */
2453
2454 #define KeGetPcr() PCR
2455
2456 static __inline
2457 ULONG
2458 DDKAPI
2459 KeGetCurrentProcessorNumber(VOID)
2460 {
2461 ULONG Number;
2462 __asm__ __volatile__ (
2463 "lwz %0, %c1(12)\n"
2464 : "=r" (Number)
2465 : "i" (FIELD_OFFSET(KPCR, Number))
2466 );
2467 return Number;
2468 }
2469
2470 #elif defined(_MIPS_)
2471
2472 #error MIPS Headers are totally incorrect
2473
2474 //
2475 // Used to contain PFNs and PFN counts
2476 //
2477 typedef ULONG PFN_COUNT;
2478 typedef ULONG PFN_NUMBER, *PPFN_NUMBER;
2479 typedef LONG SPFN_NUMBER, *PSPFN_NUMBER;
2480
2481 #define PASSIVE_LEVEL 0
2482 #define APC_LEVEL 1
2483 #define DISPATCH_LEVEL 2
2484 #define PROFILE_LEVEL 27
2485 #define IPI_LEVEL 29
2486 #define HIGH_LEVEL 31
2487
2488 typedef struct _KPCR {
2489 struct _KPRCB *Prcb; /* 20 */
2490 KIRQL Irql; /* 24 */
2491 ULONG IRR; /* 28 */
2492 ULONG IDR; /* 30 */
2493 } KPCR, *PKPCR;
2494
2495 #define KeGetPcr() PCR
2496
2497 typedef struct _KFLOATING_SAVE {
2498 } KFLOATING_SAVE, *PKFLOATING_SAVE;
2499
2500 static __inline
2501 ULONG
2502 DDKAPI
2503 KeGetCurrentProcessorNumber(VOID)
2504 {
2505 return 0;
2506 }
2507
2508 #elif defined(_M_ARM)
2509
2510 //
2511 // NT-ARM is not documented, need DDK-ARM
2512 //
2513 #include <armddk.h>
2514
2515 #else
2516 #error Unknown architecture
2517 #endif
2518
2519 #define MM_DONT_ZERO_ALLOCATION 0x00000001
2520 #define MM_ALLOCATE_FROM_LOCAL_NODE_ONLY 0x00000002
2521
2522
2523 #define EFLAG_SIGN 0x8000
2524 #define EFLAG_ZERO 0x4000
2525 #define EFLAG_SELECT (EFLAG_SIGN | EFLAG_ZERO)
2526
2527 #define RESULT_NEGATIVE ((EFLAG_SIGN & ~EFLAG_ZERO) & EFLAG_SELECT)
2528 #define RESULT_ZERO ((~EFLAG_SIGN & EFLAG_ZERO) & EFLAG_SELECT)
2529 #define RESULT_POSITIVE ((~EFLAG_SIGN & ~EFLAG_ZERO) & EFLAG_SELECT)
2530
2531 typedef enum _INTERLOCKED_RESULT {
2532 ResultNegative = RESULT_NEGATIVE,
2533 ResultZero = RESULT_ZERO,
2534 ResultPositive = RESULT_POSITIVE
2535 } INTERLOCKED_RESULT;
2536
2537 typedef VOID
2538 (NTAPI *PciPin2Line)(
2539 IN struct _BUS_HANDLER *BusHandler,
2540 IN struct _BUS_HANDLER *RootHandler,
2541 IN PCI_SLOT_NUMBER SlotNumber,
2542 IN PPCI_COMMON_CONFIG PciData
2543 );
2544
2545 typedef VOID
2546 (NTAPI *PciLine2Pin)(
2547 IN struct _BUS_HANDLER *BusHandler,
2548 IN struct _BUS_HANDLER *RootHandler,
2549 IN PCI_SLOT_NUMBER SlotNumber,
2550 IN PPCI_COMMON_CONFIG PciNewData,
2551 IN PPCI_COMMON_CONFIG PciOldData
2552 );
2553
2554 typedef VOID
2555 (NTAPI *PciReadWriteConfig)(
2556 IN struct _BUS_HANDLER *BusHandler,
2557 IN PCI_SLOT_NUMBER Slot,
2558 IN PVOID Buffer,
2559 IN ULONG Offset,
2560 IN ULONG Length
2561 );
2562
2563 #define PCI_DATA_TAG ' ICP'
2564 #define PCI_DATA_VERSION 1
2565
2566 typedef struct _PCIBUSDATA
2567 {
2568 ULONG Tag;
2569 ULONG Version;
2570 PciReadWriteConfig ReadConfig;
2571 PciReadWriteConfig WriteConfig;
2572 PciPin2Line Pin2Line;
2573 PciLine2Pin Line2Pin;
2574 PCI_SLOT_NUMBER ParentSlot;
2575 PVOID Reserved[4];
2576 } PCIBUSDATA, *PPCIBUSDATA;
2577
2578
2579 /** SPINLOCK FUNCTIONS ********************************************************/
2580
2581 NTKERNELAPI
2582 BOOLEAN
2583 FASTCALL
2584 KeTryToAcquireSpinLockAtDpcLevel(
2585 IN OUT PKSPIN_LOCK SpinLock
2586 );
2587
2588 NTKERNELAPI
2589 BOOLEAN
2590 FASTCALL
2591 KeTestSpinLock(
2592 IN PKSPIN_LOCK SpinLock
2593 );
2594
2595 #if defined (_X86_)
2596
2597 #if defined(WIN9X_COMPAT_SPINLOCK)
2598
2599 NTKERNELAPI
2600 VOID
2601 NTAPI
2602 KeInitializeSpinLock(
2603 IN PKSPIN_LOCK SpinLock
2604 );
2605
2606 #else
2607
2608 FORCEINLINE
2609 VOID
2610 KeInitializeSpinLock(IN PKSPIN_LOCK SpinLock)
2611 {
2612 /* Clear the lock */
2613 *SpinLock = 0;
2614 }
2615
2616 #endif
2617
2618 NTHALAPI
2619 KIRQL
2620 FASTCALL
2621 KfAcquireSpinLock(
2622 IN PKSPIN_LOCK SpinLock);
2623
2624 NTHALAPI
2625 VOID
2626 FASTCALL
2627 KfReleaseSpinLock(
2628 IN PKSPIN_LOCK SpinLock,
2629 IN KIRQL NewIrql);
2630
2631 NTKERNELAPI
2632 VOID
2633 FASTCALL
2634 KefAcquireSpinLockAtDpcLevel(
2635 IN PKSPIN_LOCK SpinLock);
2636
2637 NTKERNELAPI
2638 VOID
2639 FASTCALL
2640 KefReleaseSpinLockFromDpcLevel(
2641 IN PKSPIN_LOCK SpinLock);
2642
2643 #define KeAcquireSpinLockAtDpcLevel(SpinLock) KefAcquireSpinLockAtDpcLevel(SpinLock)
2644 #define KeReleaseSpinLockFromDpcLevel(SpinLock) KefReleaseSpinLockFromDpcLevel(SpinLock)
2645 #define KeAcquireSpinLock(a,b) *(b) = KfAcquireSpinLock(a)
2646 #define KeReleaseSpinLock(a,b) KfReleaseSpinLock(a,b)
2647
2648 #define KeGetDcacheFillSize() 1L
2649
2650 #elif defined(_M_ARM) // !defined (_X86_)
2651
2652 FORCEINLINE
2653 VOID
2654 KeInitializeSpinLock(IN PKSPIN_LOCK SpinLock)
2655 {
2656 /* Clear the lock */
2657 *SpinLock = 0;
2658 }
2659
2660 NTHALAPI
2661 KIRQL
2662 FASTCALL
2663 KfAcquireSpinLock(
2664 IN PKSPIN_LOCK SpinLock);
2665
2666 NTHALAPI
2667 VOID
2668 FASTCALL
2669 KfReleaseSpinLock(
2670 IN PKSPIN_LOCK SpinLock,
2671 IN KIRQL NewIrql);
2672
2673
2674 NTKERNELAPI
2675 VOID
2676 FASTCALL
2677 KefAcquireSpinLockAtDpcLevel(
2678 IN PKSPIN_LOCK SpinLock);
2679
2680 NTKERNELAPI
2681 VOID
2682 FASTCALL
2683 KefReleaseSpinLockFromDpcLevel(
2684 IN PKSPIN_LOCK SpinLock);
2685
2686
2687 #define KeAcquireSpinLockAtDpcLevel(SpinLock) KefAcquireSpinLockAtDpcLevel(SpinLock)
2688 #define KeReleaseSpinLockFromDpcLevel(SpinLock) KefReleaseSpinLockFromDpcLevel(SpinLock)
2689 #define KeAcquireSpinLock(a,b) *(b) = KfAcquireSpinLock(a)
2690 #define KeReleaseSpinLock(a,b) KfReleaseSpinLock(a,b)
2691
2692 NTKERNELAPI
2693 VOID
2694 NTAPI
2695 KeInitializeSpinLock(
2696 IN PKSPIN_LOCK SpinLock);
2697
2698 #else
2699
2700 FORCEINLINE
2701 VOID
2702 NTAPI
2703 KeInitializeSpinLock(
2704 PKSPIN_LOCK SpinLock)
2705 {
2706 *SpinLock = 0;
2707 }
2708
2709 NTKERNELAPI
2710 VOID
2711 KeReleaseSpinLock(
2712 IN PKSPIN_LOCK SpinLock,
2713 IN KIRQL NewIrql);
2714
2715 NTKERNELAPI
2716 VOID
2717 KeAcquireSpinLockAtDpcLevel(
2718 IN PKSPIN_LOCK SpinLock);
2719
2720 NTKERNELAPI
2721 VOID
2722 KeReleaseSpinLockFromDpcLevel(
2723 IN PKSPIN_LOCK SpinLock);
2724
2725 NTKERNELAPI
2726 KIRQL
2727 KeAcquireSpinLockRaiseToDpc(
2728 IN PKSPIN_LOCK SpinLock);
2729
2730 #define KeAcquireSpinLock(SpinLock, OldIrql) \
2731 *(OldIrql) = KeAcquireSpinLockRaiseToDpc(SpinLock)
2732
2733 #endif // !defined (_X86_)
2734
2735 /*
2736 ** Utillity functions
2737 */
2738
2739 #define ARGUMENT_PRESENT(ArgumentPointer) \
2740 ((CHAR*)((ULONG_PTR)(ArgumentPointer)) != (CHAR*)NULL)
2741
2742 /*
2743 * ULONG
2744 * BYTE_OFFSET(
2745 * IN PVOID Va)
2746 */
2747 #define BYTE_OFFSET(Va) \
2748 ((ULONG) ((ULONG_PTR) (Va) & (PAGE_SIZE - 1)))
2749
2750 /*
2751 * ULONG
2752 * BYTES_TO_PAGES(
2753 * IN ULONG Size)
2754 */
2755 #define BYTES_TO_PAGES(Size) \
2756 ((ULONG) ((ULONG_PTR) (Size) >> PAGE_SHIFT) + (((ULONG) (Size) & (PAGE_SIZE - 1)) != 0))
2757
2758 /*
2759 * PVOID
2760 * PAGE_ALIGN(
2761 * IN PVOID Va)
2762 */
2763 #define PAGE_ALIGN(Va) \
2764 ((PVOID) ((ULONG_PTR)(Va) & ~(PAGE_SIZE - 1)))
2765
2766 /*
2767 * ULONG_PTR
2768 * ROUND_TO_PAGES(
2769 * IN ULONG_PTR Size)
2770 */
2771 #define ROUND_TO_PAGES(Size) \
2772 ((ULONG_PTR) (((ULONG_PTR) Size + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1)))
2773
2774
2775
2776 #if defined(_X86_) || defined(_AMD64_)
2777
2778 //
2779 // x86 and x64 performs a 0x2C interrupt
2780 //
2781 #define DbgRaiseAssertionFailure __int2c
2782
2783 #elif defined(_ARM_)
2784
2785 //
2786 // TODO
2787 //
2788
2789 #else
2790 #error Unsupported Architecture
2791 #endif
2792
2793 #if DBG
2794
2795 #define ASSERT(exp) \
2796 (VOID)((!(exp)) ? \
2797 RtlAssert( (PVOID)#exp, (PVOID)__FILE__, __LINE__, NULL ), FALSE : TRUE)
2798
2799 #define ASSERTMSG(msg, exp) \
2800 (VOID)((!(exp)) ? \
2801 RtlAssert( (PVOID)#exp, (PVOID)__FILE__, __LINE__, msg ), FALSE : TRUE)
2802
2803 #define RTL_SOFT_ASSERT(exp) \
2804 (VOID)((!(exp)) ? \
2805 DbgPrint("%s(%d): Soft assertion failed\n Expression: %s\n", __FILE__, __LINE__, #exp), FALSE : TRUE)
2806
2807 #define RTL_SOFT_ASSERTMSG(msg, exp) \
2808 (VOID)((!(exp)) ? \
2809 DbgPrint("%s(%d): Soft assertion failed\n Expression: %s\n Message: %s\n", __FILE__, __LINE__, #exp, (msg)), FALSE : TRUE)
2810
2811 #define RTL_VERIFY(exp) ASSERT(exp)
2812 #define RTL_VERIFYMSG(msg, exp) ASSERT(msg, exp)
2813
2814 #define RTL_SOFT_VERIFY(exp) RTL_SOFT_ASSERT(exp)
2815 #define RTL_SOFT_VERIFYMSG(msg, exp) RTL_SOFT_ASSERTMSG(msg, exp)
2816
2817 #if defined(_MSC_VER)
2818
2819 #define NT_ASSERT(exp) \
2820 ((!(exp)) ? \
2821 (__annotation(L"Debug", L"AssertFail", L#exp), \
2822 DbgRaiseAssertionFailure(), FALSE) : TRUE)
2823
2824 #define NT_ASSERTMSG(msg, exp) \
2825 ((!(exp)) ? \
2826 (__annotation(L"Debug", L"AssertFail", L##msg), \
2827 DbgRaiseAssertionFailure(), FALSE) : TRUE)
2828
2829 #define NT_ASSERTMSGW(msg, exp) \
2830 ((!(exp)) ? \
2831 (__annotation(L"Debug", L"AssertFail", msg), \
2832 DbgRaiseAssertionFailure(), FALSE) : TRUE)
2833
2834 #else
2835
2836 //
2837 // GCC doesn't support __annotation (nor PDB)
2838 //
2839 #define NT_ASSERT(exp) \
2840 (VOID)((!(exp)) ? (DbgRaiseAssertionFailure(), FALSE) : TRUE)
2841
2842 #define NT_ASSERTMSG NT_ASSERT
2843 #define NT_ASSERTMSGW NT_ASSERT
2844
2845 #endif
2846
2847 #else /* !DBG */
2848
2849 #define ASSERT(exp) ((VOID) 0)
2850 #define ASSERTMSG(msg, exp) ((VOID) 0)
2851
2852 #define RTL_SOFT_ASSERT(exp) ((VOID) 0)
2853 #define RTL_SOFT_ASSERTMSG(msg, exp) ((VOID) 0)
2854
2855 #define RTL_VERIFY(exp) ((exp) ? TRUE : FALSE)
2856 #define RTL_VERIFYMSG(msg, exp) ((exp) ? TRUE : FALSE)
2857
2858 #define RTL_SOFT_VERIFY(exp) ((exp) ? TRUE : FALSE)
2859 #define RTL_SOFT_VERIFYMSG(msg, exp) ((exp) ? TRUE : FALSE)
2860
2861 #define NT_ASSERT(exp) ((VOID)0)
2862 #define NT_ASSERTMSG(exp) ((VOID)0)
2863 #define NT_ASSERTMSGW(exp) ((VOID)0)
2864
2865 #endif /* DBG */
2866
2867 /* HACK HACK HACK - GCC (or perhaps LD) is messing this up */
2868 #if defined(_NTSYSTEM_) || defined(__GNUC__)
2869 #define NLS_MB_CODE_PAGE_TAG NlsMbCodePageTag
2870 #define NLS_MB_OEM_CODE_PAGE_TAG NlsMbOemCodePageTag
2871 #else
2872 #define NLS_MB_CODE_PAGE_TAG (*NlsMbCodePageTag)
2873 #define NLS_MB_OEM_CODE_PAGE_TAG (*NlsMbOemCodePageTag)
2874 #endif /* _NT_SYSTEM */
2875
2876 extern BOOLEAN NTSYSAPI NLS_MB_CODE_PAGE_TAG;
2877 extern BOOLEAN NTSYSAPI NLS_MB_OEM_CODE_PAGE_TAG;
2878
2879 /*
2880 ** Driver support routines
2881 */
2882
2883 /** Runtime library routines **/
2884
2885 static __inline VOID
2886 InitializeListHead(
2887 IN PLIST_ENTRY ListHead)
2888 {
2889 ListHead->Flink = ListHead->Blink = ListHead;
2890 }
2891
2892 static __inline VOID
2893 InsertHeadList(
2894 IN PLIST_ENTRY ListHead,
2895 IN PLIST_ENTRY Entry)
2896 {
2897 PLIST_ENTRY OldFlink;
2898 OldFlink = ListHead->Flink;
2899 Entry->Flink = OldFlink;
2900 Entry->Blink = ListHead;
2901 OldFlink->Blink = Entry;
2902 ListHead->Flink = Entry;
2903 }
2904
2905 static __inline VOID
2906 InsertTailList(
2907 IN PLIST_ENTRY ListHead,
2908 IN PLIST_ENTRY Entry)
2909 {
2910 PLIST_ENTRY OldBlink;
2911 OldBlink = ListHead->Blink;
2912 Entry->Flink = ListHead;
2913 Entry->Blink = OldBlink;
2914 OldBlink->Flink = Entry;
2915 ListHead->Blink = Entry;
2916 }
2917
2918 /*
2919 * BOOLEAN
2920 * IsListEmpty(
2921 * IN PLIST_ENTRY ListHead)
2922 */
2923 #define IsListEmpty(_ListHead) \
2924 ((_ListHead)->Flink == (_ListHead))
2925
2926 /*
2927 * PSINGLE_LIST_ENTRY
2928 * PopEntryList(
2929 * IN PSINGLE_LIST_ENTRY ListHead)
2930 */
2931 #define PopEntryList(ListHead) \
2932 (ListHead)->Next; \
2933 { \
2934 PSINGLE_LIST_ENTRY _FirstEntry; \
2935 _FirstEntry = (ListHead)->Next; \
2936 if (_FirstEntry != NULL) \
2937 (ListHead)->Next = _FirstEntry->Next; \
2938 }
2939
2940 /*
2941 * VOID
2942 * PushEntryList(
2943 * IN PSINGLE_LIST_ENTRY ListHead,
2944 * IN PSINGLE_LIST_ENTRY Entry)
2945 */
2946 #define PushEntryList(_ListHead, _Entry) \
2947 (_Entry)->Next = (_ListHead)->Next; \
2948 (_ListHead)->Next = (_Entry); \
2949
2950 static __inline BOOLEAN
2951 RemoveEntryList(
2952 IN PLIST_ENTRY Entry)
2953 {
2954 PLIST_ENTRY OldFlink;
2955 PLIST_ENTRY OldBlink;
2956
2957 OldFlink = Entry->Flink;
2958 OldBlink = Entry->Blink;
2959 OldFlink->Blink = OldBlink;
2960 OldBlink->Flink = OldFlink;
2961 return (BOOLEAN)(OldFlink == OldBlink);
2962 }
2963
2964 static __inline PLIST_ENTRY
2965 RemoveHeadList(
2966 IN PLIST_ENTRY ListHead)
2967 {
2968 PLIST_ENTRY Flink;
2969 PLIST_ENTRY Entry;
2970
2971 Entry = ListHead->Flink;
2972 Flink = Entry->Flink;
2973 ListHead->Flink = Flink;
2974 Flink->Blink = ListHead;
2975 return Entry;
2976 }
2977
2978 static __inline PLIST_ENTRY
2979 RemoveTailList(
2980 IN PLIST_ENTRY ListHead)
2981 {
2982 PLIST_ENTRY Blink;
2983 PLIST_ENTRY Entry;
2984
2985 Entry = ListHead->Blink;
2986 Blink = Entry->Blink;
2987 ListHead->Blink = Blink;
2988 Blink->Flink = ListHead;
2989 return Entry;
2990 }
2991
2992 NTSYSAPI
2993 NTSTATUS
2994 NTAPI
2995 RtlCharToInteger(
2996 IN PCSZ String,
2997 IN ULONG Base OPTIONAL,
2998 IN OUT PULONG Value);
2999
3000 NTSYSAPI
3001 LONG
3002 NTAPI
3003 RtlCompareString(
3004 IN PSTRING String1,
3005 IN PSTRING String2,
3006 BOOLEAN CaseInSensitive);
3007
3008 #if !defined(MIDL_PASS)
3009
3010 FORCEINLINE
3011 LUID
3012 NTAPI
3013 RtlConvertLongToLuid(
3014 IN LONG Val)
3015 {
3016 LUID Luid;
3017 LARGE_INTEGER Temp;
3018
3019 Temp.QuadPart = Val;
3020 Luid.LowPart = Temp.u.LowPart;
3021 Luid.HighPart = Temp.u.HighPart;
3022
3023 return Luid;
3024 }
3025
3026 FORCEINLINE
3027 LUID
3028 NTAPI
3029 RtlConvertUlongToLuid(
3030 IN ULONG Val)
3031 {
3032 LUID Luid;
3033
3034 Luid.LowPart = Val;
3035 Luid.HighPart = 0;
3036
3037 return Luid;
3038 }
3039 #endif
3040
3041
3042 NTSYSAPI
3043 VOID
3044 NTAPI
3045 RtlCopyMemory32(
3046 IN VOID UNALIGNED *Destination,
3047 IN CONST VOID UNALIGNED *Source,
3048 IN ULONG Length);
3049
3050 NTSYSAPI
3051 VOID
3052 NTAPI
3053 RtlCopyString(
3054 IN OUT PSTRING DestinationString,
3055 IN PSTRING SourceString OPTIONAL);
3056
3057 NTSYSAPI
3058 BOOLEAN
3059 NTAPI
3060 RtlEqualString(
3061 IN PSTRING String1,
3062 IN PSTRING String2,
3063 IN BOOLEAN CaseInSensitive);
3064
3065 #if (defined(_M_AMD64) || defined(_M_IA64)) && !defined(_REALLY_GET_CALLERS_CALLER_)
3066 #define RtlGetCallersAddress(CallersAddress, CallersCaller) \
3067 *CallersAddress = (PVOID)_ReturnAddress(); \
3068 *CallersCaller = NULL;
3069 #else
3070 NTSYSAPI
3071 VOID
3072 NTAPI
3073 RtlGetCallersAddress(
3074 OUT PVOID *CallersAddress,
3075 OUT PVOID *CallersCaller);
3076 #endif
3077
3078 NTSYSAPI
3079 NTSTATUS
3080 NTAPI
3081 RtlGetVersion(
3082 IN OUT PRTL_OSVERSIONINFOW lpVersionInformation);
3083
3084 NTSYSAPI
3085 VOID
3086 NTAPI
3087 RtlMapGenericMask(
3088 IN OUT PACCESS_MASK AccessMask,
3089 IN PGENERIC_MAPPING GenericMapping);
3090
3091 NTSYSAPI
3092 BOOLEAN
3093 NTAPI
3094 RtlPrefixUnicodeString(
3095 IN PCUNICODE_STRING String1,
3096 IN PCUNICODE_STRING String2,
3097 IN BOOLEAN CaseInSensitive);
3098
3099 NTSYSAPI
3100 NTSTATUS
3101 NTAPI
3102 RtlUpcaseUnicodeString(
3103 IN OUT PUNICODE_STRING DestinationString OPTIONAL,
3104 IN PCUNICODE_STRING SourceString,
3105 IN BOOLEAN AllocateDestinationString);
3106
3107 NTSYSAPI
3108 CHAR
3109 NTAPI
3110 RtlUpperChar(
3111 IN CHAR Character);
3112
3113 NTSYSAPI
3114 VOID
3115 NTAPI
3116 RtlUpperString(
3117 IN OUT PSTRING DestinationString,
3118 IN PSTRING SourceString);
3119
3120 NTSYSAPI
3121 NTSTATUS
3122 NTAPI
3123 RtlVerifyVersionInfo(
3124 IN PRTL_OSVERSIONINFOEXW VersionInfo,
3125 IN ULONG TypeMask,
3126 IN ULONGLONG ConditionMask);
3127
3128 NTSYSAPI
3129 NTSTATUS
3130 NTAPI
3131 RtlVolumeDeviceToDosName(
3132 IN PVOID VolumeDeviceObject,
3133 OUT PUNICODE_STRING DosName);
3134
3135 NTSYSAPI
3136 ULONG
3137 NTAPI
3138 RtlWalkFrameChain(
3139 OUT PVOID *Callers,
3140 IN ULONG Count,
3141 IN ULONG Flags);
3142
3143 NTKERNELAPI
3144 BOOLEAN
3145 NTAPI
3146 KeAreAllApcsDisabled(
3147 VOID
3148 );
3149
3150 /* Guarded Mutex routines */
3151
3152 NTKERNELAPI
3153 VOID
3154 FASTCALL
3155 KeAcquireGuardedMutex(
3156 IN OUT PKGUARDED_MUTEX GuardedMutex
3157 );
3158
3159 NTKERNELAPI
3160 VOID
3161 FASTCALL
3162 KeAcquireGuardedMutexUnsafe(
3163 IN OUT PKGUARDED_MUTEX GuardedMutex
3164 );
3165
3166 NTKERNELAPI
3167 VOID
3168 NTAPI
3169 KeEnterGuardedRegion(
3170 VOID
3171 );
3172
3173 NTKERNELAPI
3174 VOID
3175 NTAPI
3176 KeLeaveGuardedRegion(
3177 VOID
3178 );
3179
3180 NTKERNELAPI
3181 VOID
3182 FASTCALL
3183 KeInitializeGuardedMutex(
3184 OUT PKGUARDED_MUTEX GuardedMutex
3185 );
3186
3187 NTKERNELAPI
3188 VOID
3189 FASTCALL
3190 KeReleaseGuardedMutexUnsafe(
3191 IN OUT PKGUARDED_MUTEX GuardedMutex
3192 );
3193
3194 NTKERNELAPI
3195 VOID
3196 FASTCALL
3197 KeReleaseGuardedMutex(
3198 IN OUT PKGUARDED_MUTEX GuardedMutex
3199 );
3200
3201 NTKERNELAPI
3202 BOOLEAN
3203 FASTCALL
3204 KeTryToAcquireGuardedMutex(
3205 IN OUT PKGUARDED_MUTEX GuardedMutex
3206 );
3207
3208 /* Fast Mutex */
3209 #define ExInitializeFastMutex(_FastMutex) \
3210 { \
3211 (_FastMutex)->Count = FM_LOCK_BIT; \
3212 (_FastMutex)->Owner = NULL; \
3213 (_FastMutex)->Contention = 0; \
3214 KeInitializeEvent(&(_FastMutex)->Gate, SynchronizationEvent, FALSE); \
3215 }
3216
3217 NTKERNELAPI
3218 VOID
3219 NTAPI
3220 KeInitializeEvent(
3221 IN PRKEVENT Event,
3222 IN EVENT_TYPE Type,
3223 IN BOOLEAN State);
3224
3225 /******************************************************************************
3226 * Executive Types *
3227 ******************************************************************************/
3228
3229 typedef struct _ZONE_SEGMENT_HEADER {
3230 SINGLE_LIST_ENTRY SegmentList;
3231 PVOID Reserved;
3232 } ZONE_SEGMENT_HEADER, *PZONE_SEGMENT_HEADER;
3233
3234 typedef struct _ZONE_HEADER {
3235 SINGLE_LIST_ENTRY FreeList;
3236 SINGLE_LIST_ENTRY SegmentList;
3237 ULONG BlockSize;
3238 ULONG TotalSegmentSize;
3239 } ZONE_HEADER, *PZONE_HEADER;
3240
3241 #define PROTECTED_POOL 0x80000000
3242
3243 /******************************************************************************
3244 * Executive Functions *
3245 ******************************************************************************/
3246
3247 NTKERNELAPI
3248 NTSTATUS
3249 NTAPI
3250 ExExtendZone(
3251 IN PZONE_HEADER Zone,
3252 IN PVOID Segment,
3253 IN ULONG SegmentSize);
3254
3255 static __inline PVOID
3256 ExAllocateFromZone(
3257 IN PZONE_HEADER Zone)
3258 {
3259 if (Zone->FreeList.Next)
3260 Zone->FreeList.Next = Zone->FreeList.Next->Next;
3261 return (PVOID) Zone->FreeList.Next;
3262 }
3263
3264 static __inline PVOID
3265 ExFreeToZone(
3266 IN PZONE_HEADER Zone,
3267 IN PVOID Block)
3268 {
3269 ((PSINGLE_LIST_ENTRY) Block)->Next = Zone->FreeList.Next;
3270 Zone->FreeList.Next = ((PSINGLE_LIST_ENTRY) Block);
3271 return ((PSINGLE_LIST_ENTRY) Block)->Next;
3272 }
3273
3274 NTKERNELAPI
3275 NTSTATUS
3276 NTAPI
3277 ExInitializeZone(
3278 IN PZONE_HEADER Zone,
3279 IN ULONG BlockSize,
3280 IN PVOID InitialSegment,
3281 IN ULONG InitialSegmentSize);
3282
3283 /*
3284 * PVOID
3285 * ExInterlockedAllocateFromZone(
3286 * IN PZONE_HEADER Zone,
3287 * IN PKSPIN_LOCK Lock)
3288 */
3289 #define ExInterlockedAllocateFromZone(Zone, Lock) \
3290 ((PVOID) ExInterlockedPopEntryList(&Zone->FreeList, Lock))
3291
3292 NTKERNELAPI
3293 NTSTATUS
3294 NTAPI
3295 ExInterlockedExtendZone(
3296 IN PZONE_HEADER Zone,
3297 IN PVOID Segment,
3298 IN ULONG SegmentSize,
3299 IN PKSPIN_LOCK Lock);
3300
3301 /* PVOID
3302 * ExInterlockedFreeToZone(
3303 * IN PZONE_HEADER Zone,
3304 * IN PVOID Block,
3305 * IN PKSPIN_LOCK Lock);
3306 */
3307 #define ExInterlockedFreeToZone(Zone, Block, Lock) \
3308 ExInterlockedPushEntryList(&(Zone)->FreeList, (PSINGLE_LIST_ENTRY)(Block), Lock)
3309
3310 /*
3311 * VOID
3312 * InitializeSListHead(
3313 * IN PSLIST_HEADER SListHead)
3314 */
3315 #define InitializeSListHead(_SListHead) \
3316 (_SListHead)->Alignment = 0
3317
3318 #define ExInitializeSListHead InitializeSListHead
3319
3320 /*
3321 * BOOLEAN
3322 * ExIsFullZone(
3323 * IN PZONE_HEADER Zone)
3324 */
3325 #define ExIsFullZone(Zone) \
3326 ((Zone)->FreeList.Next == (PSINGLE_LIST_ENTRY) NULL)
3327
3328 /* BOOLEAN
3329 * ExIsObjectInFirstZoneSegment(
3330 * IN PZONE_HEADER Zone,
3331 * IN PVOID Object);
3332 */
3333 #define ExIsObjectInFirstZoneSegment(Zone,Object) \
3334 ((BOOLEAN)( ((PUCHAR)(Object) >= (PUCHAR)(Zone)->SegmentList.Next) && \
3335 ((PUCHAR)(Object) < (PUCHAR)(Zone)->SegmentList.Next + \
3336 (Zone)->TotalSegmentSize)) )
3337
3338 NTKERNELAPI
3339 DECLSPEC_NORETURN
3340 VOID
3341 NTAPI
3342 ExRaiseAccessViolation(
3343 VOID);
3344
3345 NTKERNELAPI
3346 DECLSPEC_NORETURN
3347 VOID
3348 NTAPI
3349 ExRaiseDatatypeMisalignment(
3350 VOID);
3351
3352 NTKERNELAPI
3353 NTSTATUS
3354 NTAPI
3355 ExUuidCreate(
3356 OUT UUID *Uuid);
3357
3358 #define ExAcquireResourceExclusive ExAcquireResourceExclusiveLite
3359 #define ExAcquireResourceShared ExAcquireResourceSharedLite
3360 #define ExConvertExclusiveToShared ExConvertExclusiveToSharedLite
3361 #define ExDeleteResource ExDeleteResourceLite
3362 #define ExInitializeResource ExInitializeResourceLite
3363 #define ExIsResourceAcquiredExclusive ExIsResourceAcquiredExclusiveLite
3364 #define ExIsResourceAcquiredShared ExIsResourceAcquiredSharedLite
3365 #define ExIsResourceAcquired ExIsResourceAcquiredSharedLite
3366 #define ExReleaseResourceForThread ExReleaseResourceForThreadLite
3367
3368
3369 #if DBG
3370
3371 #define PAGED_CODE() { \
3372 if (KeGetCurrentIrql() > APC_LEVEL) { \
3373 KdPrint( ("NTDDK: Pageable code called at IRQL > APC_LEVEL (%d)\n", KeGetCurrentIrql() )); \
3374 ASSERT(FALSE); \
3375 } \
3376 }
3377
3378 #else
3379
3380 #define PAGED_CODE()
3381
3382 #endif
3383
3384 NTKERNELAPI
3385 VOID
3386 NTAPI
3387 ProbeForRead(
3388 IN CONST VOID *Address,
3389 IN SIZE_T Length,
3390 IN ULONG Alignment);
3391
3392 NTKERNELAPI
3393 VOID
3394 NTAPI
3395 ProbeForWrite(
3396 IN PVOID Address,
3397 IN SIZE_T Length,
3398 IN ULONG Alignment);
3399
3400
3401
3402 /** Configuration manager routines **/
3403
3404 NTKERNELAPI
3405 NTSTATUS
3406 NTAPI
3407 CmRegisterCallback(
3408 IN PEX_CALLBACK_FUNCTION Function,
3409 IN PVOID Context,
3410 IN OUT PLARGE_INTEGER Cookie);
3411
3412 NTKERNELAPI
3413 NTSTATUS
3414 NTAPI
3415 CmUnRegisterCallback(
3416 IN LARGE_INTEGER Cookie);
3417
3418
3419
3420 /** Filesystem runtime library routines **/
3421
3422 NTKERNELAPI
3423 BOOLEAN
3424 NTAPI
3425 FsRtlIsTotalDeviceFailure(
3426 IN NTSTATUS Status);
3427
3428
3429
3430 /** Hardware abstraction layer routines **/
3431
3432 NTHALAPI
3433 BOOLEAN
3434 NTAPI
3435 HalMakeBeep(
3436 IN ULONG Frequency);
3437
3438 NTKERNELAPI
3439 VOID
3440 FASTCALL
3441 HalExamineMBR(
3442 IN PDEVICE_OBJECT DeviceObject,
3443 IN ULONG SectorSize,
3444 IN ULONG MBRTypeIdentifier,
3445 OUT PVOID *Buffer);
3446
3447 VOID
3448 NTAPI
3449 HalPutDmaAdapter(
3450 PADAPTER_OBJECT AdapterObject
3451 );
3452
3453
3454 /** Io access routines **/
3455
3456 #if !defined(_M_AMD64)
3457 NTHALAPI
3458 VOID
3459 NTAPI
3460 READ_PORT_BUFFER_UCHAR(
3461 IN PUCHAR Port,
3462 IN PUCHAR Buffer,
3463 IN ULONG Count);
3464
3465 NTHALAPI
3466 VOID
3467 NTAPI
3468 READ_PORT_BUFFER_ULONG(
3469 IN PULONG Port,
3470 IN PULONG Buffer,
3471 IN ULONG Count);
3472
3473 NTHALAPI
3474 VOID
3475 NTAPI
3476 READ_PORT_BUFFER_USHORT(
3477 IN PUSHORT Port,
3478 IN PUSHORT Buffer,
3479 IN ULONG Count);
3480
3481 NTHALAPI
3482 UCHAR
3483 NTAPI
3484 READ_PORT_UCHAR(
3485 IN PUCHAR Port);
3486
3487 NTHALAPI
3488 ULONG
3489 NTAPI
3490 READ_PORT_ULONG(
3491 IN PULONG Port);
3492
3493 NTHALAPI
3494 USHORT
3495 NTAPI
3496 READ_PORT_USHORT(
3497 IN PUSHORT Port);
3498
3499 NTKERNELAPI
3500 VOID
3501 NTAPI
3502 READ_REGISTER_BUFFER_UCHAR(
3503 IN PUCHAR Register,
3504 IN PUCHAR Buffer,
3505 IN ULONG Count);
3506
3507 NTKERNELAPI
3508 VOID
3509 NTAPI
3510 READ_REGISTER_BUFFER_ULONG(
3511 IN PULONG Register,
3512 IN PULONG Buffer,
3513 IN ULONG Count);
3514
3515 NTKERNELAPI
3516 VOID
3517 NTAPI
3518 READ_REGISTER_BUFFER_USHORT(
3519 IN PUSHORT Register,
3520 IN PUSHORT Buffer,
3521 IN ULONG Count);
3522
3523 NTKERNELAPI
3524 UCHAR
3525 NTAPI
3526 READ_REGISTER_UCHAR(
3527 IN PUCHAR Register);
3528
3529 NTKERNELAPI
3530 ULONG
3531 NTAPI
3532 READ_REGISTER_ULONG(
3533 IN PULONG Register);
3534
3535 NTKERNELAPI
3536 USHORT
3537 NTAPI
3538 READ_REGISTER_USHORT(
3539 IN PUSHORT Register);
3540
3541 NTHALAPI
3542 VOID
3543 NTAPI
3544 WRITE_PORT_BUFFER_UCHAR(
3545 IN PUCHAR Port,
3546 IN PUCHAR Buffer,
3547 IN ULONG Count);
3548
3549 NTHALAPI
3550 VOID
3551 NTAPI
3552 WRITE_PORT_BUFFER_ULONG(
3553 IN PULONG Port,
3554 IN PULONG Buffer,
3555 IN ULONG Count);
3556
3557 NTHALAPI
3558 VOID
3559 NTAPI
3560 WRITE_PORT_BUFFER_USHORT(
3561 IN PUSHORT Port,
3562 IN PUSHORT Buffer,
3563 IN ULONG Count);
3564
3565 NTHALAPI
3566 VOID
3567 NTAPI
3568 WRITE_PORT_UCHAR(
3569 IN PUCHAR Port,
3570 IN UCHAR Value);
3571
3572 NTHALAPI
3573 VOID
3574 NTAPI
3575 WRITE_PORT_ULONG(
3576 IN PULONG Port,
3577 IN ULONG Value);
3578
3579 NTHALAPI
3580 VOID
3581 NTAPI
3582 WRITE_PORT_USHORT(
3583 IN PUSHORT Port,
3584 IN USHORT Value);
3585
3586 NTKERNELAPI
3587 VOID
3588 NTAPI
3589 WRITE_REGISTER_BUFFER_UCHAR(
3590 IN PUCHAR Register,
3591 IN PUCHAR Buffer,
3592 IN ULONG Count);
3593
3594 NTKERNELAPI
3595 VOID
3596 NTAPI
3597 WRITE_REGISTER_BUFFER_ULONG(
3598 IN PULONG Register,
3599 IN PULONG Buffer,
3600 IN ULONG Count);
3601
3602 NTKERNELAPI
3603 VOID
3604 NTAPI
3605 WRITE_REGISTER_BUFFER_USHORT(
3606 IN PUSHORT Register,
3607 IN PUSHORT Buffer,
3608 IN ULONG Count);
3609
3610 NTKERNELAPI
3611 VOID
3612 NTAPI
3613 WRITE_REGISTER_UCHAR(
3614 IN PUCHAR Register,
3615 IN UCHAR Value);
3616
3617 NTKERNELAPI
3618 VOID
3619 NTAPI
3620 WRITE_REGISTER_ULONG(
3621 IN PULONG Register,
3622 IN ULONG Value);
3623
3624 NTKERNELAPI
3625 VOID
3626 NTAPI
3627 WRITE_REGISTER_USHORT(
3628 IN PUSHORT Register,
3629 IN USHORT Value);
3630
3631 #else
3632
3633 FORCEINLINE
3634 VOID
3635 READ_PORT_BUFFER_UCHAR(
3636 IN PUCHAR Port,
3637 IN PUCHAR Buffer,
3638 IN ULONG Count)
3639 {
3640 __inbytestring((USHORT)(ULONG_PTR)Port, Buffer, Count);
3641 }
3642
3643 FORCEINLINE
3644 VOID
3645 READ_PORT_BUFFER_ULONG(
3646 IN PULONG Port,
3647 IN PULONG Buffer,
3648 IN ULONG Count)
3649 {
3650 __indwordstring((USHORT)(ULONG_PTR)Port, Buffer, Count);
3651 }
3652
3653 FORCEINLINE
3654 VOID
3655 READ_PORT_BUFFER_USHORT(
3656 IN PUSHORT Port,
3657 IN PUSHORT Buffer,
3658 IN ULONG Count)
3659 {
3660 __inwordstring((USHORT)(ULONG_PTR)Port, Buffer, Count);
3661 }
3662
3663 FORCEINLINE
3664 UCHAR
3665 READ_PORT_UCHAR(
3666 IN PUCHAR Port)
3667 {
3668 return __inbyte((USHORT)(ULONG_PTR)Port);
3669 }
3670
3671 FORCEINLINE
3672 ULONG
3673 READ_PORT_ULONG(
3674 IN PULONG Port)
3675 {
3676 return __indword((USHORT)(ULONG_PTR)Port);
3677 }
3678
3679 FORCEINLINE
3680 USHORT
3681 READ_PORT_USHORT(
3682 IN PUSHORT Port)
3683 {
3684 return __inword((USHORT)(ULONG_PTR)Port);
3685 }
3686
3687 FORCEINLINE
3688 VOID
3689 READ_REGISTER_BUFFER_UCHAR(
3690 IN PUCHAR Register,
3691 IN PUCHAR Buffer,
3692 IN ULONG Count)
3693 {
3694 __movsb(Register, Buffer, Count);
3695 }
3696
3697 FORCEINLINE
3698 VOID
3699 READ_REGISTER_BUFFER_ULONG(
3700 IN PULONG Register,
3701 IN PULONG Buffer,
3702 IN ULONG Count)
3703 {
3704 __movsd(Register, Buffer, Count);
3705 }
3706
3707 FORCEINLINE
3708 VOID
3709 READ_REGISTER_BUFFER_USHORT(
3710 IN PUSHORT Register,
3711 IN PUSHORT Buffer,
3712 IN ULONG Count)
3713 {
3714 __movsw(Register, Buffer, Count);
3715 }
3716
3717 FORCEINLINE
3718 UCHAR
3719 READ_REGISTER_UCHAR(
3720 IN PUCHAR Register)
3721 {
3722 return *Register;
3723 }
3724
3725 FORCEINLINE
3726 ULONG
3727 READ_REGISTER_ULONG(
3728 IN PULONG Register)
3729 {
3730 return *Register;
3731 }
3732
3733 FORCEINLINE
3734 USHORT
3735 READ_REGISTER_USHORT(
3736 IN PUSHORT Register)
3737 {
3738 return *Register;
3739 }
3740
3741 FORCEINLINE
3742 VOID
3743 WRITE_PORT_BUFFER_UCHAR(
3744 IN PUCHAR Port,
3745 IN PUCHAR Buffer,
3746 IN ULONG Count)
3747 {
3748 __outbytestring((USHORT)(ULONG_PTR)Port, Buffer, Count);
3749 }
3750
3751 FORCEINLINE
3752 VOID
3753 WRITE_PORT_BUFFER_ULONG(
3754 IN PULONG Port,
3755 IN PULONG Buffer,
3756 IN ULONG Count)
3757 {
3758 __outdwordstring((USHORT)(ULONG_PTR)Port, Buffer, Count);
3759 }
3760
3761 FORCEINLINE
3762 VOID
3763 WRITE_PORT_BUFFER_USHORT(
3764 IN PUSHORT Port,
3765 IN PUSHORT Buffer,
3766 IN ULONG Count)
3767 {
3768 __outwordstring((USHORT)(ULONG_PTR)Port, Buffer, Count);
3769 }
3770
3771 FORCEINLINE
3772 VOID
3773 WRITE_PORT_UCHAR(
3774 IN PUCHAR Port,
3775 IN UCHAR Value)
3776 {
3777 __outbyte((USHORT)(ULONG_PTR)Port, Value);
3778 }
3779
3780 FORCEINLINE
3781 VOID
3782 WRITE_PORT_ULONG(
3783 IN PULONG Port,
3784 IN ULONG Value)
3785 {
3786 __outdword((USHORT)(ULONG_PTR)Port, Value);
3787 }
3788
3789 FORCEINLINE
3790 VOID
3791 WRITE_PORT_USHORT(
3792 IN PUSHORT Port,
3793 IN USHORT Value)
3794 {
3795 __outword((USHORT)(ULONG_PTR)Port, Value);
3796 }
3797
3798 FORCEINLINE
3799 VOID
3800 WRITE_REGISTER_BUFFER_UCHAR(
3801 IN PUCHAR Register,
3802 IN PUCHAR Buffer,
3803 IN ULONG Count)
3804 {
3805 LONG Synch;
3806 __movsb(Register, Buffer, Count);
3807 InterlockedOr(&Synch, 1);
3808 }
3809
3810 FORCEINLINE
3811 VOID
3812 WRITE_REGISTER_BUFFER_ULONG(
3813 IN PULONG Register,
3814 IN PULONG Buffer,
3815 IN ULONG Count)
3816 {
3817 LONG Synch;
3818 __movsd(Register, Buffer, Count);
3819 InterlockedOr(&Synch, 1);
3820 }
3821
3822 FORCEINLINE
3823 VOID
3824 WRITE_REGISTER_BUFFER_USHORT(
3825 IN PUSHORT Register,
3826 IN PUSHORT Buffer,
3827 IN ULONG Count)
3828 {
3829 LONG Synch;
3830 __movsw(Register, Buffer, Count);
3831 InterlockedOr(&Synch, 1);
3832 }
3833
3834 FORCEINLINE
3835 VOID
3836 WRITE_REGISTER_UCHAR(
3837 IN PUCHAR Register,
3838 IN UCHAR Value)
3839 {
3840 LONG Synch;
3841 *Register = Value;
3842 InterlockedOr(&Synch, 1);
3843 }
3844
3845 FORCEINLINE
3846 VOID
3847 WRITE_REGISTER_ULONG(
3848 IN PULONG Register,
3849 IN ULONG Value)
3850 {
3851 LONG Synch;
3852 *Register = Value;
3853 InterlockedOr(&Synch, 1);
3854 }
3855
3856 FORCEINLINE
3857 VOID
3858 WRITE_REGISTER_USHORT(
3859 IN PUSHORT Register,
3860 IN USHORT Value)
3861 {
3862 LONG Sync;
3863 *Register = Value;
3864 InterlockedOr(&Sync, 1);
3865 }
3866
3867 #endif
3868
3869 /** I/O manager routines **/
3870
3871 NTKERNELAPI
3872 VOID
3873 NTAPI
3874 IoAcquireCancelSpinLock(
3875 OUT PKIRQL Irql);
3876
3877 NTKERNELAPI
3878 NTSTATUS
3879 NTAPI
3880 IoAcquireRemoveLockEx(
3881 IN PIO_REMOVE_LOCK RemoveLock,
3882 IN OPTIONAL PVOID Tag OPTIONAL,
3883 IN PCSTR File,
3884 IN ULONG Line,
3885 IN ULONG RemlockSize);
3886
3887 /*
3888 * NTSTATUS
3889 * IoAcquireRemoveLock(
3890 * IN PIO_REMOVE_LOCK RemoveLock,
3891 * IN OPTIONAL PVOID Tag)
3892 */
3893 #define IoAcquireRemoveLock(_RemoveLock, \
3894 _Tag) \
3895 IoAcquireRemoveLockEx(_RemoveLock, _Tag, __FILE__, __LINE__, sizeof(IO_REMOVE_LOCK))
3896
3897 /*
3898 * VOID
3899 * IoAdjustPagingPathCount(
3900 * IN PLONG Count,
3901 * IN BOOLEAN Increment)
3902 */
3903 #define IoAdjustPagingPathCount(_Count, \
3904 _Increment) \
3905 { \
3906 if (_Increment) \
3907 { \
3908 InterlockedIncrement(_Count); \
3909 } \
3910 else \
3911 { \
3912 InterlockedDecrement(_Count); \
3913 } \
3914 }
3915
3916 #ifndef DMA_MACROS_DEFINED
3917 NTKERNELAPI
3918 NTSTATUS
3919 NTAPI
3920 IoAllocateAdapterChannel(
3921 IN PADAPTER_OBJECT AdapterObject,
3922 IN PDEVICE_OBJECT DeviceObject,
3923 IN ULONG NumberOfMapRegisters,
3924 IN PDRIVER_CONTROL ExecutionRoutine,
3925 IN PVOID Context);
3926 #endif
3927
3928 NTKERNELAPI
3929 VOID
3930 NTAPI
3931 IoAllocateController(
3932 IN PCONTROLLER_OBJECT ControllerObject,
3933 IN PDEVICE_OBJECT DeviceObject,
3934 IN PDRIVER_CONTROL ExecutionRoutine,
3935 IN PVOID Context);
3936
3937 NTKERNELAPI
3938 NTSTATUS
3939 NTAPI
3940 IoAllocateDriverObjectExtension(
3941 IN PDRIVER_OBJECT DriverObject,
3942 IN PVOID ClientIdentificationAddress,
3943 IN ULONG DriverObjectExtensionSize,
3944 OUT PVOID *DriverObjectExtension);
3945
3946 NTKERNELAPI
3947 PVOID
3948 NTAPI
3949 IoAllocateErrorLogEntry(
3950 IN PVOID IoObject,
3951 IN UCHAR EntrySize);
3952
3953 NTKERNELAPI
3954 PIRP
3955 NTAPI
3956 IoAllocateIrp(
3957 IN CCHAR StackSize,
3958 IN BOOLEAN ChargeQuota);
3959
3960 NTKERNELAPI
3961 PMDL
3962 NTAPI
3963 IoAllocateMdl(
3964 IN PVOID VirtualAddress,
3965 IN ULONG Length,
3966 IN BOOLEAN SecondaryBuffer,
3967 IN BOOLEAN ChargeQuota,
3968 IN OUT PIRP Irp OPTIONAL);
3969
3970 NTKERNELAPI
3971 PIO_WORKITEM
3972 NTAPI
3973 IoAllocateWorkItem(
3974 IN PDEVICE_OBJECT DeviceObject);
3975
3976 /*
3977 * VOID IoAssignArcName(
3978 * IN PUNICODE_STRING ArcName,
3979 * IN PUNICODE_STRING Dev