2 * Copyright 2004-2005 Ivan Leo Puoti
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #define POINTER_ALIGNMENT DECLSPEC_ALIGN(8)
28 #define POINTER_ALIGNMENT
31 typedef ULONG_PTR KSPIN_LOCK
, *PKSPIN_LOCK
;
36 typedef VOID (WINAPI
*PKDEFERRED_ROUTINE
)(struct _KDPC
*, PVOID
, PVOID
, PVOID
);
38 typedef struct _DISPATCHER_HEADER
{
44 LIST_ENTRY WaitListHead
;
45 } DISPATCHER_HEADER
, *PDISPATCHER_HEADER
;
47 typedef struct _KEVENT
{
48 DISPATCHER_HEADER Header
;
49 } KEVENT
, *PKEVENT
, *RESTRICTED_POINTER PRKEVENT
;
51 typedef struct _KDPC
{
55 LIST_ENTRY DpcListEntry
;
56 PKDEFERRED_ROUTINE DeferredRoutine
;
57 PVOID DeferredContext
;
58 PVOID SystemArgument1
;
59 PVOID SystemArgument2
;
61 } KDPC
, *PKDPC
, *RESTRICTED_POINTER PRKDPC
;
63 typedef struct _KDEVICE_QUEUE_ENTRY
{
64 LIST_ENTRY DeviceListEntry
;
67 } KDEVICE_QUEUE_ENTRY
, *PKDEVICE_QUEUE_ENTRY
,
68 *RESTRICTED_POINTER PRKDEVICE_QUEUE_ENTRY
;
70 typedef struct _KDEVICE_QUEUE
{
73 LIST_ENTRY DeviceListHead
;
76 } KDEVICE_QUEUE
, *PKDEVICE_QUEUE
, *RESTRICTED_POINTER PRKDEVICE_QUEUE
;
78 typedef struct _IO_TIMER
*PIO_TIMER
;
79 typedef struct _ETHREAD
*PETHREAD
;
81 #define MAXIMUM_VOLUME_LABEL_LENGTH (32 * sizeof(WCHAR))
87 USHORT VolumeLabelLength
;
88 struct _DEVICE_OBJECT
*DeviceObject
;
89 struct _DEVICE_OBJECT
*RealDevice
;
92 WCHAR VolumeLabel
[MAXIMUM_VOLUME_LABEL_LENGTH
/ sizeof(WCHAR
)];
96 typedef struct _WAIT_CONTEXT_BLOCK
{
97 KDEVICE_QUEUE_ENTRY WaitQueueEntry
;
98 struct _DRIVER_CONTROL
*DeviceRoutine
;
100 ULONG NumberOfMapRegisters
;
103 PKDPC BufferChainingDpc
;
104 } WAIT_CONTEXT_BLOCK
, *PWAIT_CONTEXT_BLOCK
;
107 #define DEVICE_TYPE ULONG
109 #define IRP_MJ_MAXIMUM_FUNCTION 0x1b
110 #define IRP_MJ_DEVICE_CONTROL 0x0e
112 typedef struct _DEVICE_OBJECT
{
116 struct _DRIVER_OBJECT
*DriverObject
;
117 struct _DEVICE_OBJECT
*NextDevice
;
118 struct _DEVICE_OBJECT
*AttachedDevice
;
119 struct _IRP
*CurrentIrp
;
122 ULONG Characteristics
;
124 PVOID DeviceExtension
;
125 DEVICE_TYPE DeviceType
;
128 LIST_ENTRY ListEntry
;
129 WAIT_CONTEXT_BLOCK Wcb
;
131 ULONG AlignmentRequirement
;
132 KDEVICE_QUEUE DeviceQueue
;
134 ULONG ActiveThreadCount
;
135 PSECURITY_DESCRIPTOR SecurityDescriptor
;
139 struct _DEVOBJ_EXTENSION
*DeviceObjectExtension
;
142 typedef struct _DEVICE_OBJECT
*PDEVICE_OBJECT
;
144 typedef struct _DRIVER_EXTENSION
{
145 struct _DRIVER_OBJECT
*DriverObject
;
148 UNICODE_STRING ServiceKeyName
;
149 } DRIVER_EXTENSION
, *PDRIVER_EXTENSION
;
151 typedef struct _DRIVER_OBJECT
{
154 PDEVICE_OBJECT DeviceObject
;
159 PDRIVER_EXTENSION DriverExtension
;
160 UNICODE_STRING DriverName
;
161 PUNICODE_STRING HardwareDatabase
;
162 PVOID FastIoDispatch
;
166 PVOID MajorFunction
[IRP_MJ_MAXIMUM_FUNCTION
+ 1];
168 typedef struct _DRIVER_OBJECT
*PDRIVER_OBJECT
;
170 /* Irp definitions */
171 typedef UCHAR KIRQL
, *PKIRQL
;
172 typedef CCHAR KPROCESSOR_MODE
;
174 typedef VOID (WINAPI
*PDRIVER_CANCEL
)(
175 IN
struct _DEVICE_OBJECT
*DeviceObject
,
176 IN
struct _IRP
*Irp
);
178 typedef VOID (WINAPI
*PKNORMAL_ROUTINE
)(
179 IN PVOID NormalContext
,
180 IN PVOID SystemArgument1
,
181 IN PVOID SystemArgument2
);
183 typedef VOID (WINAPI
*PKKERNEL_ROUTINE
)(
184 IN
struct _KAPC
*Apc
,
185 IN OUT PKNORMAL_ROUTINE
*NormalRoutine
,
186 IN OUT PVOID
*NormalContext
,
187 IN OUT PVOID
*SystemArgument1
,
188 IN OUT PVOID
*SystemArgument2
);
190 typedef VOID (WINAPI
*PKRUNDOWN_ROUTINE
)(
191 IN
struct _KAPC
*Apc
);
193 typedef struct _KAPC
{
197 struct _KTHREAD
*Thread
;
198 LIST_ENTRY ApcListEntry
;
199 PKKERNEL_ROUTINE KernelRoutine
;
200 PKRUNDOWN_ROUTINE RundownRoutine
;
201 PKNORMAL_ROUTINE NormalRoutine
;
203 PVOID SystemArgument1
;
204 PVOID SystemArgument2
;
206 KPROCESSOR_MODE ApcMode
;
208 } KAPC
, *PKAPC
, *RESTRICTED_POINTER PRKAPC
;
210 #include <pshpack1.h>
211 typedef struct _IRP
{
214 struct _MDL
*MdlAddress
;
217 struct _IRP
*MasterIrp
;
221 LIST_ENTRY ThreadListEntry
;
222 IO_STATUS_BLOCK IoStatus
;
223 KPROCESSOR_MODE RequestorMode
;
224 BOOLEAN PendingReturned
;
226 CHAR CurrentLocation
;
229 CCHAR ApcEnvironment
;
230 UCHAR AllocationFlags
;
231 PIO_STATUS_BLOCK UserIosb
;
235 PIO_APC_ROUTINE UserApcRoutine
;
236 PVOID UserApcContext
;
237 } AsynchronousParameters
;
238 LARGE_INTEGER AllocationSize
;
240 PDRIVER_CANCEL CancelRoutine
;
245 KDEVICE_QUEUE_ENTRY DeviceQueueEntry
;
247 PVOID DriverContext
[4];
251 PCHAR AuxiliaryBuffer
;
253 LIST_ENTRY ListEntry
;
255 struct _IO_STACK_LOCATION
*CurrentStackLocation
;
259 struct _FILE_OBJECT
*OriginalFileObject
;
265 typedef struct _IRP
*PIRP
;
268 /* MDL definitions */
270 typedef VOID (WINAPI
*PINTERFACE_REFERENCE
)(
273 typedef VOID (WINAPI
*PINTERFACE_DEREFERENCE
)(
276 typedef struct _INTERFACE
{
280 PINTERFACE_REFERENCE InterfaceReference
;
281 PINTERFACE_DEREFERENCE InterfaceDereference
;
282 } INTERFACE
, *PINTERFACE
;
284 typedef struct _SECTION_OBJECT_POINTERS
{
285 PVOID DataSectionObject
;
286 PVOID SharedCacheMap
;
287 PVOID ImageSectionObject
;
288 } SECTION_OBJECT_POINTERS
, *PSECTION_OBJECT_POINTERS
;
290 typedef struct _IO_COMPLETION_CONTEXT
{
293 } IO_COMPLETION_CONTEXT
, *PIO_COMPLETION_CONTEXT
;
295 typedef enum _DEVICE_RELATION_TYPE
{
300 TargetDeviceRelation
,
302 } DEVICE_RELATION_TYPE
, *PDEVICE_RELATION_TYPE
;
304 typedef struct _FILE_OBJECT
{
307 PDEVICE_OBJECT DeviceObject
;
311 PSECTION_OBJECT_POINTERS SectionObjectPointer
;
312 PVOID PrivateCacheMap
;
313 NTSTATUS FinalStatus
;
314 struct _FILE_OBJECT
*RelatedFileObject
;
315 BOOLEAN LockOperation
;
316 BOOLEAN DeletePending
;
319 BOOLEAN DeleteAccess
;
322 BOOLEAN SharedDelete
;
324 UNICODE_STRING FileName
;
325 LARGE_INTEGER CurrentByteOffset
;
331 PIO_COMPLETION_CONTEXT CompletionContext
;
333 typedef struct _FILE_OBJECT
*PFILE_OBJECT
;
335 #define INITIAL_PRIVILEGE_COUNT 3
337 typedef struct _INITIAL_PRIVILEGE_SET
{
338 ULONG PrivilegeCount
;
340 LUID_AND_ATTRIBUTES Privilege
[INITIAL_PRIVILEGE_COUNT
];
341 } INITIAL_PRIVILEGE_SET
, * PINITIAL_PRIVILEGE_SET
;
343 typedef struct _SECURITY_SUBJECT_CONTEXT
{
344 PACCESS_TOKEN ClientToken
;
345 SECURITY_IMPERSONATION_LEVEL ImpersonationLevel
;
346 PACCESS_TOKEN PrimaryToken
;
347 PVOID ProcessAuditId
;
348 } SECURITY_SUBJECT_CONTEXT
, *PSECURITY_SUBJECT_CONTEXT
;
350 typedef struct _ACCESS_STATE
{
352 BOOLEAN SecurityEvaluated
;
353 BOOLEAN GenerateAudit
;
354 BOOLEAN GenerateOnClose
;
355 BOOLEAN PrivilegesAllocated
;
357 ACCESS_MASK RemainingDesiredAccess
;
358 ACCESS_MASK PreviouslyGrantedAccess
;
359 ACCESS_MASK OriginalDesiredAccess
;
360 SECURITY_SUBJECT_CONTEXT SubjectSecurityContext
;
361 PSECURITY_DESCRIPTOR SecurityDescriptor
;
364 INITIAL_PRIVILEGE_SET InitialPrivilegeSet
;
365 PRIVILEGE_SET PrivilegeSet
;
368 BOOLEAN AuditPrivileges
;
369 UNICODE_STRING ObjectName
;
370 UNICODE_STRING ObjectTypeName
;
371 } ACCESS_STATE
, *PACCESS_STATE
;
373 typedef struct _IO_SECURITY_CONTEXT
{
374 PSECURITY_QUALITY_OF_SERVICE SecurityQos
;
375 PACCESS_STATE AccessState
;
376 ACCESS_MASK DesiredAccess
;
377 ULONG FullCreateOptions
;
378 } IO_SECURITY_CONTEXT
, *PIO_SECURITY_CONTEXT
;
380 typedef struct _DEVICE_CAPABILITIES
{
385 ULONG LockSupported
: 1;
386 ULONG EjectSupported
: 1;
388 ULONG DockDevice
: 1;
390 ULONG SilentInstall
: 1;
391 ULONG RawDeviceOK
: 1;
392 ULONG SurpriseRemovalOK
: 1;
393 ULONG WakeFromD0
: 1;
394 ULONG WakeFromD1
: 1;
395 ULONG WakeFromD2
: 1;
396 ULONG WakeFromD3
: 1;
397 ULONG HardwareDisabled
: 1;
398 ULONG NonDynamic
: 1;
399 ULONG WarmEjectSupported
: 1;
400 ULONG NoDisplayInUI
: 1;
404 DEVICE_POWER_STATE DeviceState
[PowerSystemMaximum
];
405 SYSTEM_POWER_STATE SystemWake
;
406 DEVICE_POWER_STATE DeviceWake
;
410 } DEVICE_CAPABILITIES
, *PDEVICE_CAPABILITIES
;
412 typedef enum _INTERFACE_TYPE
{
413 InterfaceTypeUndefined
= -1,
431 } INTERFACE_TYPE
, *PINTERFACE_TYPE
;
433 typedef LARGE_INTEGER PHYSICAL_ADDRESS
, *PPHYSICAL_ADDRESS
;
435 #define IO_RESOURCE_PREFERRED 0x01
436 #define IO_RESOURCE_DEFAULT 0x02
437 #define IO_RESOURCE_ALTERNATIVE 0x08
439 typedef struct _IO_RESOURCE_DESCRIPTOR
{
442 UCHAR ShareDisposition
;
450 PHYSICAL_ADDRESS MinimumAddress
;
451 PHYSICAL_ADDRESS MaximumAddress
;
456 PHYSICAL_ADDRESS MinimumAddress
;
457 PHYSICAL_ADDRESS MaximumAddress
;
464 ULONG MinimumChannel
;
465 ULONG MaximumChannel
;
470 PHYSICAL_ADDRESS MinimumAddress
;
471 PHYSICAL_ADDRESS MaximumAddress
;
488 } IO_RESOURCE_DESCRIPTOR
, *PIO_RESOURCE_DESCRIPTOR
;
490 typedef struct _IO_RESOURCE_LIST
{
494 IO_RESOURCE_DESCRIPTOR Descriptors
[1];
495 } IO_RESOURCE_LIST
, *PIO_RESOURCE_LIST
;
497 typedef struct _IO_RESOURCE_REQUIREMENTS_LIST
{
499 INTERFACE_TYPE InterfaceType
;
503 ULONG AlternativeLists
;
504 IO_RESOURCE_LIST List
[1];
505 } IO_RESOURCE_REQUIREMENTS_LIST
, *PIO_RESOURCE_REQUIREMENTS_LIST
;
507 typedef enum _BUS_QUERY_ID_TYPE
{
510 BusQueryCompatibleIDs
,
512 BusQueryDeviceSerialNumber
513 } BUS_QUERY_ID_TYPE
, *PBUS_QUERY_ID_TYPE
;
515 typedef enum _DEVICE_TEXT_TYPE
{
516 DeviceTextDescription
,
517 DeviceTextLocationInformation
518 } DEVICE_TEXT_TYPE
, *PDEVICE_TEXT_TYPE
;
520 typedef enum _DEVICE_USAGE_NOTIFICATION_TYPE
{
521 DeviceUsageTypeUndefined
,
522 DeviceUsageTypePaging
,
523 DeviceUsageTypeHibernation
,
524 DeviceUsageTypeDumpFile
525 } DEVICE_USAGE_NOTIFICATION_TYPE
;
527 typedef struct _POWER_SEQUENCE
{
531 } POWER_SEQUENCE
, *PPOWER_SEQUENCE
;
533 typedef enum _POWER_STATE_TYPE
{
536 } POWER_STATE_TYPE
, *PPOWER_STATE_TYPE
;
538 typedef union _POWER_STATE
{
539 SYSTEM_POWER_STATE SystemState
;
540 DEVICE_POWER_STATE DeviceState
;
541 } POWER_STATE
, *PPOWER_STATE
;
543 typedef struct _CM_PARTIAL_RESOURCE_DESCRIPTOR
{
545 UCHAR ShareDisposition
;
549 PHYSICAL_ADDRESS Start
;
553 PHYSICAL_ADDRESS Start
;
562 PHYSICAL_ADDRESS Start
;
582 } DeviceSpecificData
;
584 } CM_PARTIAL_RESOURCE_DESCRIPTOR
, *PCM_PARTIAL_RESOURCE_DESCRIPTOR
;
586 typedef struct _CM_PARTIAL_RESOURCE_LIST
{
590 CM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptors
[1];
591 } CM_PARTIAL_RESOURCE_LIST
, *PCM_PARTIAL_RESOURCE_LIST
;
593 typedef struct _CM_FULL_RESOURCE_DESCRIPTOR
{
594 INTERFACE_TYPE InterfaceType
;
596 CM_PARTIAL_RESOURCE_LIST PartialResourceList
;
597 } CM_FULL_RESOURCE_DESCRIPTOR
, *PCM_FULL_RESOURCE_DESCRIPTOR
;
599 typedef struct _CM_RESOURCE_LIST
{
601 CM_FULL_RESOURCE_DESCRIPTOR List
[1];
602 } CM_RESOURCE_LIST
, *PCM_RESOURCE_LIST
;
604 typedef NTSTATUS (WINAPI
*PIO_COMPLETION_ROUTINE
)(
605 IN
struct _DEVICE_OBJECT
*DeviceObject
,
609 #include <pshpack1.h>
610 typedef struct _IO_STACK_LOCATION
{
617 PIO_SECURITY_CONTEXT SecurityContext
;
619 USHORT POINTER_ALIGNMENT FileAttributes
;
621 ULONG POINTER_ALIGNMENT EaLength
;
625 ULONG POINTER_ALIGNMENT Key
;
626 LARGE_INTEGER ByteOffset
;
630 ULONG POINTER_ALIGNMENT Key
;
631 LARGE_INTEGER ByteOffset
;
635 FILE_INFORMATION_CLASS POINTER_ALIGNMENT FileInformationClass
;
639 FILE_INFORMATION_CLASS POINTER_ALIGNMENT FileInformationClass
;
640 PFILE_OBJECT FileObject
;
643 BOOLEAN ReplaceIfExists
;
652 FS_INFORMATION_CLASS POINTER_ALIGNMENT FsInformationClass
;
655 ULONG OutputBufferLength
;
656 ULONG POINTER_ALIGNMENT InputBufferLength
;
657 ULONG POINTER_ALIGNMENT IoControlCode
;
658 PVOID Type3InputBuffer
;
661 SECURITY_INFORMATION SecurityInformation
;
662 ULONG POINTER_ALIGNMENT Length
;
665 SECURITY_INFORMATION SecurityInformation
;
666 PSECURITY_DESCRIPTOR SecurityDescriptor
;
670 PDEVICE_OBJECT DeviceObject
;
674 PDEVICE_OBJECT DeviceObject
;
677 struct _SCSI_REQUEST_BLOCK
*Srb
;
680 DEVICE_RELATION_TYPE Type
;
681 } QueryDeviceRelations
;
683 CONST GUID
*InterfaceType
;
686 PINTERFACE Interface
;
687 PVOID InterfaceSpecificData
;
690 PDEVICE_CAPABILITIES Capabilities
;
691 } DeviceCapabilities
;
693 PIO_RESOURCE_REQUIREMENTS_LIST IoResourceRequirementList
;
694 } FilterResourceRequirements
;
699 ULONG POINTER_ALIGNMENT Length
;
705 BUS_QUERY_ID_TYPE IdType
;
708 DEVICE_TEXT_TYPE DeviceTextType
;
709 LCID POINTER_ALIGNMENT LocaleId
;
714 DEVICE_USAGE_NOTIFICATION_TYPE POINTER_ALIGNMENT Type
;
717 SYSTEM_POWER_STATE PowerState
;
720 PPOWER_SEQUENCE PowerSequence
;
724 POWER_STATE_TYPE POINTER_ALIGNMENT Type
;
725 POWER_STATE POINTER_ALIGNMENT State
;
726 POWER_ACTION POINTER_ALIGNMENT ShutdownType
;
729 PCM_RESOURCE_LIST AllocatedResources
;
730 PCM_RESOURCE_LIST AllocatedResourcesTranslated
;
733 ULONG_PTR ProviderId
;
745 PDEVICE_OBJECT DeviceObject
;
746 PFILE_OBJECT FileObject
;
747 PIO_COMPLETION_ROUTINE CompletionRoutine
;
749 } IO_STACK_LOCATION
, *PIO_STACK_LOCATION
;
752 typedef struct _MDL
{
756 struct _EPROCESS
*Process
;
757 PVOID MappedSystemVa
;
763 typedef NTSTATUS (WINAPI
*PDRIVER_DISPATCH
)(
764 IN
struct _DEVICE_OBJECT
*DeviceObject
,
765 IN
struct _IRP
*Irp
);
767 typedef struct _KSYSTEM_TIME
{
771 } KSYSTEM_TIME
, *PKSYSTEM_TIME
;
773 typedef enum _NT_PRODUCT_TYPE
{
777 } NT_PRODUCT_TYPE
, *PNT_PRODUCT_TYPE
;
779 #define PROCESSOR_FEATURE_MAX 64
781 typedef enum _ALTERNATIVE_ARCHITECTURE_TYPE
786 } ALTERNATIVE_ARCHITECTURE_TYPE
;
788 typedef struct _KUSER_SHARED_DATA
{
789 ULONG TickCountLowDeprecated
;
790 ULONG TickCountMultiplier
;
791 volatile KSYSTEM_TIME InterruptTime
;
792 volatile KSYSTEM_TIME SystemTime
;
793 volatile KSYSTEM_TIME TimeZoneBias
;
794 USHORT ImageNumberLow
;
795 USHORT ImageNumberHigh
;
796 WCHAR NtSystemRoot
[260];
797 ULONG MaxStckTraceDepth
;
798 ULONG CryptoExponent
;
800 ULONG LargePageMinimum
;
802 NT_PRODUCT_TYPE NtProductType
;
803 BOOLEAN ProductTypeIsValid
;
804 ULONG MajorNtVersion
;
805 ULONG MinorNtVersion
;
806 BOOLEAN ProcessorFeatures
[PROCESSOR_FEATURE_MAX
];
809 volatile ULONG TimeSlip
;
810 ALTERNATIVE_ARCHITECTURE_TYPE AlternativeArchitecture
;
811 LARGE_INTEGER SystemExpirationDate
;
813 BOOLEAN KdDebuggerEnabled
;
814 volatile ULONG ActiveConsoleId
;
815 volatile ULONG DismountCount
;
816 ULONG ComPlusPackage
;
817 ULONG LastSystemRITEventTickCount
;
818 ULONG NumberOfPhysicalPages
;
819 BOOLEAN SafeBootMode
;
822 ULONGLONG SystemCall
[4];
824 volatile KSYSTEM_TIME TickCount
;
825 volatile ULONG64 TickCountQuad
;
827 } KSHARED_USER_DATA
, *PKSHARED_USER_DATA
;
829 #define IoGetCurrentIrpStackLocation(_Irp) ((_Irp)->Tail.Overlay.CurrentStackLocation)
834 /* directory object access rights */
835 #define DIRECTORY_QUERY 0x0001
836 #define DIRECTORY_TRAVERSE 0x0002
837 #define DIRECTORY_CREATE_OBJECT 0x0004
838 #define DIRECTORY_CREATE_SUBDIRECTORY 0x0008
839 #define DIRECTORY_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | 0xF)
841 /* symbolic link access rights */
842 #define SYMBOLIC_LINK_QUERY 0x0001
843 #define SYMBOLIC_LINK_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | 0x1)