Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

23494 lines
559 KiB

  1. /*++ BUILD Version: 0121 // Increment this if a change has global effects
  2. Copyright (c) Microsoft Corporation. All rights reserved.
  3. Module Name:
  4. ntddk.h
  5. Abstract:
  6. This module defines the NT types, constants, and functions that are
  7. exposed to device drivers.
  8. Revision History:
  9. --*/
  10. #ifndef _NTDDK_
  11. #define _NTDDK_
  12. #ifndef RC_INVOKED
  13. #if _MSC_VER < 1300
  14. #error Compiler version not supported by Windows DDK
  15. #endif
  16. #endif // RC_INVOKED
  17. #define NT_INCLUDED
  18. #define _CTYPE_DISABLE_MACROS
  19. #include <excpt.h>
  20. #include <ntdef.h>
  21. #include <ntstatus.h>
  22. #include <bugcodes.h>
  23. #include <ntiologc.h>
  24. //
  25. // Kernel Mutex Level Numbers (must be globallly assigned within executive)
  26. // The third token in the name is the sub-component name that defines and
  27. // uses the level number.
  28. //
  29. //
  30. // Used by Vdm for protecting io simulation structures
  31. //
  32. #define MUTEX_LEVEL_VDM_IO (ULONG)0x00000001
  33. #define MUTEX_LEVEL_EX_PROFILE (ULONG)0x00000040
  34. //
  35. // The LANMAN Redirector uses the file system major function, but defines
  36. // it's own mutex levels. We can do this safely because we know that the
  37. // local filesystem will never call the remote filesystem and vice versa.
  38. //
  39. #define MUTEX_LEVEL_RDR_FILESYS_DATABASE (ULONG)0x10100000
  40. #define MUTEX_LEVEL_RDR_FILESYS_SECURITY (ULONG)0x10100001
  41. //
  42. // File System levels.
  43. //
  44. #define MUTEX_LEVEL_FILESYSTEM_RAW_VCB (ULONG)0x11000006
  45. //
  46. // In the NT STREAMS environment, a mutex is used to serialize open, close
  47. // and Scheduler threads executing in a subsystem-parallelized stack.
  48. //
  49. #define MUTEX_LEVEL_STREAMS_SUBSYS (ULONG)0x11001001
  50. //
  51. // Mutex level used by LDT support on x86
  52. //
  53. #define MUTEX_LEVEL_PS_LDT (ULONG)0x1F000000
  54. //
  55. // Define types that are not exported.
  56. //
  57. typedef struct _BUS_HANDLER *PBUS_HANDLER;
  58. typedef struct _CALLBACK_OBJECT *PCALLBACK_OBJECT;
  59. typedef struct _DEVICE_HANDLER_OBJECT *PDEVICE_HANDLER_OBJECT;
  60. typedef struct _EPROCESS *PEPROCESS;
  61. typedef struct _ETHREAD *PETHREAD;
  62. typedef struct _IO_TIMER *PIO_TIMER;
  63. typedef struct _KINTERRUPT *PKINTERRUPT;
  64. typedef struct _KTHREAD *PKTHREAD, *PRKTHREAD;
  65. typedef struct _OBJECT_TYPE *POBJECT_TYPE;
  66. typedef struct _PEB *PPEB;
  67. #if defined(_M_AMD64)
  68. PKTHREAD
  69. NTAPI
  70. KeGetCurrentThread(
  71. VOID
  72. );
  73. #endif // defined(_M_AMD64)
  74. #if defined(_M_IX86)
  75. PKTHREAD NTAPI KeGetCurrentThread();
  76. #endif // defined(_M_IX86)
  77. #if defined(_M_IA64)
  78. //
  79. // Define Address of Processor Control Registers.
  80. //
  81. #define KIPCR ((ULONG_PTR)(KADDRESS_BASE + 0xffff0000)) // kernel address of first PCR
  82. //
  83. // Define Pointer to Processor Control Registers.
  84. //
  85. #define PCR ((volatile KPCR * const)KIPCR)
  86. PKTHREAD NTAPI KeGetCurrentThread();
  87. #endif // defined(_M_IA64)
  88. #define PsGetCurrentProcess() IoGetCurrentProcess()
  89. #define PsGetCurrentThread() ((PETHREAD) (KeGetCurrentThread()))
  90. extern NTSYSAPI CCHAR KeNumberProcessors;
  91. #include <mce.h>
  92. #ifndef FAR
  93. #define FAR
  94. #endif
  95. //
  96. // Define alignment macros to align structure sizes and pointers up and down.
  97. //
  98. #define ALIGN_DOWN(length, type) \
  99. ((ULONG)(length) & ~(sizeof(type) - 1))
  100. #define ALIGN_UP(length, type) \
  101. (ALIGN_DOWN(((ULONG)(length) + sizeof(type) - 1), type))
  102. #define ALIGN_DOWN_POINTER(address, type) \
  103. ((PVOID)((ULONG_PTR)(address) & ~((ULONG_PTR)sizeof(type) - 1)))
  104. #define ALIGN_UP_POINTER(address, type) \
  105. (ALIGN_DOWN_POINTER(((ULONG_PTR)(address) + sizeof(type) - 1), type))
  106. #define POOL_TAGGING 1
  107. #ifndef DBG
  108. #define DBG 0
  109. #endif
  110. #if DBG
  111. #define IF_DEBUG if (TRUE)
  112. #else
  113. #define IF_DEBUG if (FALSE)
  114. #endif
  115. #if DEVL
  116. extern ULONG NtGlobalFlag;
  117. #define IF_NTOS_DEBUG( FlagName ) \
  118. if (NtGlobalFlag & (FLG_ ## FlagName))
  119. #else
  120. #define IF_NTOS_DEBUG( FlagName ) if (FALSE)
  121. #endif
  122. //
  123. // Kernel definitions that need to be here for forward reference purposes
  124. //
  125. //
  126. // Processor modes.
  127. //
  128. typedef CCHAR KPROCESSOR_MODE;
  129. typedef enum _MODE {
  130. KernelMode,
  131. UserMode,
  132. MaximumMode
  133. } MODE;
  134. //
  135. // APC function types
  136. //
  137. //
  138. // Put in an empty definition for the KAPC so that the
  139. // routines can reference it before it is declared.
  140. //
  141. struct _KAPC;
  142. typedef
  143. VOID
  144. (*PKNORMAL_ROUTINE) (
  145. IN PVOID NormalContext,
  146. IN PVOID SystemArgument1,
  147. IN PVOID SystemArgument2
  148. );
  149. typedef
  150. VOID
  151. (*PKKERNEL_ROUTINE) (
  152. IN struct _KAPC *Apc,
  153. IN OUT PKNORMAL_ROUTINE *NormalRoutine,
  154. IN OUT PVOID *NormalContext,
  155. IN OUT PVOID *SystemArgument1,
  156. IN OUT PVOID *SystemArgument2
  157. );
  158. typedef
  159. VOID
  160. (*PKRUNDOWN_ROUTINE) (
  161. IN struct _KAPC *Apc
  162. );
  163. typedef
  164. BOOLEAN
  165. (*PKSYNCHRONIZE_ROUTINE) (
  166. IN PVOID SynchronizeContext
  167. );
  168. typedef
  169. BOOLEAN
  170. (*PKTRANSFER_ROUTINE) (
  171. VOID
  172. );
  173. //
  174. //
  175. // Asynchronous Procedure Call (APC) object
  176. //
  177. //
  178. typedef struct _KAPC {
  179. CSHORT Type;
  180. CSHORT Size;
  181. ULONG Spare0;
  182. struct _KTHREAD *Thread;
  183. LIST_ENTRY ApcListEntry;
  184. PKKERNEL_ROUTINE KernelRoutine;
  185. PKRUNDOWN_ROUTINE RundownRoutine;
  186. PKNORMAL_ROUTINE NormalRoutine;
  187. PVOID NormalContext;
  188. //
  189. // N.B. The following two members MUST be together.
  190. //
  191. PVOID SystemArgument1;
  192. PVOID SystemArgument2;
  193. CCHAR ApcStateIndex;
  194. KPROCESSOR_MODE ApcMode;
  195. BOOLEAN Inserted;
  196. } KAPC, *PKAPC, *RESTRICTED_POINTER PRKAPC;
  197. //
  198. // DPC routine
  199. //
  200. struct _KDPC;
  201. typedef
  202. VOID
  203. (*PKDEFERRED_ROUTINE) (
  204. IN struct _KDPC *Dpc,
  205. IN PVOID DeferredContext,
  206. IN PVOID SystemArgument1,
  207. IN PVOID SystemArgument2
  208. );
  209. //
  210. // Define DPC importance.
  211. //
  212. // LowImportance - Queue DPC at end of target DPC queue.
  213. // MediumImportance - Queue DPC at end of target DPC queue.
  214. // HighImportance - Queue DPC at front of target DPC DPC queue.
  215. //
  216. // If there is currently a DPC active on the target processor, or a DPC
  217. // interrupt has already been requested on the target processor when a
  218. // DPC is queued, then no further action is necessary. The DPC will be
  219. // executed on the target processor when its queue entry is processed.
  220. //
  221. // If there is not a DPC active on the target processor and a DPC interrupt
  222. // has not been requested on the target processor, then the exact treatment
  223. // of the DPC is dependent on whether the host system is a UP system or an
  224. // MP system.
  225. //
  226. // UP system.
  227. //
  228. // If the DPC is of medium or high importance, the current DPC queue depth
  229. // is greater than the maximum target depth, or current DPC request rate is
  230. // less the minimum target rate, then a DPC interrupt is requested on the
  231. // host processor and the DPC will be processed when the interrupt occurs.
  232. // Otherwise, no DPC interupt is requested and the DPC execution will be
  233. // delayed until the DPC queue depth is greater that the target depth or the
  234. // minimum DPC rate is less than the target rate.
  235. //
  236. // MP system.
  237. //
  238. // If the DPC is being queued to another processor and the depth of the DPC
  239. // queue on the target processor is greater than the maximum target depth or
  240. // the DPC is of high importance, then a DPC interrupt is requested on the
  241. // target processor and the DPC will be processed when the interrupt occurs.
  242. // Otherwise, the DPC execution will be delayed on the target processor until
  243. // the DPC queue depth on the target processor is greater that the maximum
  244. // target depth or the minimum DPC rate on the target processor is less than
  245. // the target mimimum rate.
  246. //
  247. // If the DPC is being queued to the current processor and the DPC is not of
  248. // low importance, the current DPC queue depth is greater than the maximum
  249. // target depth, or the minimum DPC rate is less than the minimum target rate,
  250. // then a DPC interrupt is request on the current processor and the DPV will
  251. // be processed whne the interrupt occurs. Otherwise, no DPC interupt is
  252. // requested and the DPC execution will be delayed until the DPC queue depth
  253. // is greater that the target depth or the minimum DPC rate is less than the
  254. // target rate.
  255. //
  256. typedef enum _KDPC_IMPORTANCE {
  257. LowImportance,
  258. MediumImportance,
  259. HighImportance
  260. } KDPC_IMPORTANCE;
  261. //
  262. // Define DPC type indicies.
  263. //
  264. #define DPC_NORMAL 0
  265. #define DPC_THREADED 1
  266. //
  267. // Deferred Procedure Call (DPC) object
  268. //
  269. typedef struct _KDPC {
  270. CSHORT Type;
  271. UCHAR Number;
  272. UCHAR Importance;
  273. LIST_ENTRY DpcListEntry;
  274. PKDEFERRED_ROUTINE DeferredRoutine;
  275. PVOID DeferredContext;
  276. PVOID SystemArgument1;
  277. PVOID SystemArgument2;
  278. PVOID DpcData;
  279. } KDPC, *PKDPC, *RESTRICTED_POINTER PRKDPC;
  280. //
  281. // Interprocessor interrupt worker routine function prototype.
  282. //
  283. typedef PVOID PKIPI_CONTEXT;
  284. typedef
  285. VOID
  286. (*PKIPI_WORKER)(
  287. IN PKIPI_CONTEXT PacketContext,
  288. IN PVOID Parameter1,
  289. IN PVOID Parameter2,
  290. IN PVOID Parameter3
  291. );
  292. //
  293. // Define interprocessor interrupt performance counters.
  294. //
  295. typedef struct _KIPI_COUNTS {
  296. ULONG Freeze;
  297. ULONG Packet;
  298. ULONG DPC;
  299. ULONG APC;
  300. ULONG FlushSingleTb;
  301. ULONG FlushMultipleTb;
  302. ULONG FlushEntireTb;
  303. ULONG GenericCall;
  304. ULONG ChangeColor;
  305. ULONG SweepDcache;
  306. ULONG SweepIcache;
  307. ULONG SweepIcacheRange;
  308. ULONG FlushIoBuffers;
  309. ULONG GratuitousDPC;
  310. } KIPI_COUNTS, *PKIPI_COUNTS;
  311. //
  312. // I/O system definitions.
  313. //
  314. // Define a Memory Descriptor List (MDL)
  315. //
  316. // An MDL describes pages in a virtual buffer in terms of physical pages. The
  317. // pages associated with the buffer are described in an array that is allocated
  318. // just after the MDL header structure itself.
  319. //
  320. // One simply calculates the base of the array by adding one to the base
  321. // MDL pointer:
  322. //
  323. // Pages = (PPFN_NUMBER) (Mdl + 1);
  324. //
  325. // Notice that while in the context of the subject thread, the base virtual
  326. // address of a buffer mapped by an MDL may be referenced using the following:
  327. //
  328. // Mdl->StartVa | Mdl->ByteOffset
  329. //
  330. typedef struct _MDL {
  331. struct _MDL *Next;
  332. CSHORT Size;
  333. CSHORT MdlFlags;
  334. struct _EPROCESS *Process;
  335. PVOID MappedSystemVa;
  336. PVOID StartVa;
  337. ULONG ByteCount;
  338. ULONG ByteOffset;
  339. } MDL, *PMDL;
  340. #define MDL_MAPPED_TO_SYSTEM_VA 0x0001
  341. #define MDL_PAGES_LOCKED 0x0002
  342. #define MDL_SOURCE_IS_NONPAGED_POOL 0x0004
  343. #define MDL_ALLOCATED_FIXED_SIZE 0x0008
  344. #define MDL_PARTIAL 0x0010
  345. #define MDL_PARTIAL_HAS_BEEN_MAPPED 0x0020
  346. #define MDL_IO_PAGE_READ 0x0040
  347. #define MDL_WRITE_OPERATION 0x0080
  348. #define MDL_PARENT_MAPPED_SYSTEM_VA 0x0100
  349. #define MDL_FREE_EXTRA_PTES 0x0200
  350. #define MDL_DESCRIBES_AWE 0x0400
  351. #define MDL_IO_SPACE 0x0800
  352. #define MDL_NETWORK_HEADER 0x1000
  353. #define MDL_MAPPING_CAN_FAIL 0x2000
  354. #define MDL_ALLOCATED_MUST_SUCCEED 0x4000
  355. #define MDL_MAPPING_FLAGS (MDL_MAPPED_TO_SYSTEM_VA | \
  356. MDL_PAGES_LOCKED | \
  357. MDL_SOURCE_IS_NONPAGED_POOL | \
  358. MDL_PARTIAL_HAS_BEEN_MAPPED | \
  359. MDL_PARENT_MAPPED_SYSTEM_VA | \
  360. MDL_SYSTEM_VA | \
  361. MDL_IO_SPACE )
  362. //
  363. // switch to DBG when appropriate
  364. //
  365. #if DBG
  366. #define PAGED_CODE() \
  367. { if (KeGetCurrentIrql() > APC_LEVEL) { \
  368. KdPrint(( "EX: Pageable code called at IRQL %d\n", KeGetCurrentIrql() )); \
  369. ASSERT(FALSE); \
  370. } \
  371. }
  372. #else
  373. #define PAGED_CODE() NOP_FUNCTION;
  374. #endif
  375. #define NTKERNELAPI DECLSPEC_IMPORT
  376. #if !defined(_NTHAL_) && !defined(_BLDR_)
  377. #define NTHALAPI DECLSPEC_IMPORT // wdm ntndis ntifs ntosp
  378. #else
  379. #define NTHALAPI // nthal
  380. #endif
  381. //
  382. // Common dispatcher object header
  383. //
  384. // N.B. The size field contains the number of dwords in the structure.
  385. //
  386. typedef struct _DISPATCHER_HEADER {
  387. union {
  388. struct {
  389. UCHAR Type;
  390. UCHAR Absolute;
  391. UCHAR Size;
  392. union {
  393. UCHAR Inserted;
  394. BOOLEAN DebugActive;
  395. };
  396. };
  397. volatile LONG Lock;
  398. };
  399. LONG SignalState;
  400. LIST_ENTRY WaitListHead;
  401. } DISPATCHER_HEADER;
  402. //
  403. // Event object
  404. //
  405. typedef struct _KEVENT {
  406. DISPATCHER_HEADER Header;
  407. } KEVENT, *PKEVENT, *RESTRICTED_POINTER PRKEVENT;
  408. //
  409. // Timer object
  410. //
  411. typedef struct _KTIMER {
  412. DISPATCHER_HEADER Header;
  413. ULARGE_INTEGER DueTime;
  414. LIST_ENTRY TimerListEntry;
  415. struct _KDPC *Dpc;
  416. LONG Period;
  417. } KTIMER, *PKTIMER, *RESTRICTED_POINTER PRKTIMER;
  418. typedef enum _LOCK_OPERATION {
  419. IoReadAccess,
  420. IoWriteAccess,
  421. IoModifyAccess
  422. } LOCK_OPERATION;
  423. #ifdef _X86_
  424. //
  425. // Disable these two pragmas that evaluate to "sti" "cli" on x86 so that driver
  426. // writers to not leave them inadvertantly in their code.
  427. //
  428. #if !defined(MIDL_PASS)
  429. #if !defined(RC_INVOKED)
  430. #if _MSC_VER >= 1200
  431. #pragma warning(push)
  432. #endif
  433. #pragma warning(disable:4164) // disable C4164 warning so that apps that
  434. // build with /Od don't get weird errors !
  435. #ifdef _M_IX86
  436. #pragma function(_enable)
  437. #pragma function(_disable)
  438. #endif
  439. #if _MSC_VER >= 1200
  440. #pragma warning(pop)
  441. #else
  442. #pragma warning(default:4164) // reenable C4164 warning
  443. #endif
  444. #endif
  445. #endif
  446. #if !defined(MIDL_PASS) || defined(_M_IX86)
  447. #if (_MSC_FULL_VER >= 13012035)
  448. //
  449. // Define bit scan intrinsics.
  450. //
  451. //#define BitScanForward _BitScanForward
  452. //#define BitScanReverse _BitScanReverse
  453. //BOOLEAN
  454. //_BitScanForward (
  455. // OUT ULONG *Index,
  456. // IN ULONG Mask
  457. // );
  458. //BOOLEAN
  459. //_BitScanReverse (
  460. // OUT ULONG *Index,
  461. // IN ULONG Mask
  462. // );
  463. //#pragma intrinsic(_BitScanForward)
  464. //#pragma intrinsic(_BitScanReverse)
  465. //
  466. // Define FS referencing intrinsics
  467. //
  468. #ifdef __cplusplus
  469. extern "C" {
  470. #endif
  471. UCHAR
  472. __readfsbyte (
  473. IN ULONG Offset
  474. );
  475. USHORT
  476. __readfsword (
  477. IN ULONG Offset
  478. );
  479. ULONG
  480. __readfsdword (
  481. IN ULONG Offset
  482. );
  483. VOID
  484. __writefsbyte (
  485. IN ULONG Offset,
  486. IN UCHAR Data
  487. );
  488. VOID
  489. __writefsword (
  490. IN ULONG Offset,
  491. IN USHORT Data
  492. );
  493. VOID
  494. __writefsdword (
  495. IN ULONG Offset,
  496. IN ULONG Data
  497. );
  498. #ifdef __cplusplus
  499. }
  500. #endif
  501. #pragma intrinsic(__readfsbyte)
  502. #pragma intrinsic(__readfsword)
  503. #pragma intrinsic(__readfsdword)
  504. #pragma intrinsic(__writefsbyte)
  505. #pragma intrinsic(__writefsword)
  506. #pragma intrinsic(__writefsdword)
  507. #endif
  508. #endif
  509. //
  510. // Size of kernel mode stack.
  511. //
  512. #define KERNEL_STACK_SIZE 12288
  513. //
  514. // Define size of large kernel mode stack for callbacks.
  515. //
  516. #define KERNEL_LARGE_STACK_SIZE 61440
  517. //
  518. // Define number of pages to initialize in a large kernel stack.
  519. //
  520. #define KERNEL_LARGE_STACK_COMMIT 12288
  521. #ifdef _X86_
  522. #if !defined(MIDL_PASS) && defined(_M_IX86)
  523. FORCEINLINE
  524. VOID
  525. MemoryBarrier (
  526. VOID
  527. )
  528. {
  529. LONG Barrier;
  530. __asm {
  531. xchg Barrier, eax
  532. }
  533. }
  534. #define YieldProcessor() __asm { rep nop }
  535. //
  536. // Prefetch is not supported on all x86 procssors.
  537. //
  538. #define PreFetchCacheLine(l, a)
  539. //
  540. // PreFetchCacheLine level defines.
  541. //
  542. #define PF_TEMPORAL_LEVEL_1
  543. #define PF_NON_TEMPORAL_LEVEL_ALL
  544. #endif
  545. //
  546. // Define the size of the 80387 save area, which is in the context frame.
  547. //
  548. #define SIZE_OF_80387_REGISTERS 80
  549. //
  550. // The following flags control the contents of the CONTEXT structure.
  551. //
  552. #if !defined(RC_INVOKED)
  553. #define CONTEXT_i386 0x00010000 // this assumes that i386 and
  554. #define CONTEXT_i486 0x00010000 // i486 have identical context records
  555. #define CONTEXT_CONTROL (CONTEXT_i386 | 0x00000001L) // SS:SP, CS:IP, FLAGS, BP
  556. #define CONTEXT_INTEGER (CONTEXT_i386 | 0x00000002L) // AX, BX, CX, DX, SI, DI
  557. #define CONTEXT_SEGMENTS (CONTEXT_i386 | 0x00000004L) // DS, ES, FS, GS
  558. #define CONTEXT_FLOATING_POINT (CONTEXT_i386 | 0x00000008L) // 387 state
  559. #define CONTEXT_DEBUG_REGISTERS (CONTEXT_i386 | 0x00000010L) // DB 0-3,6,7
  560. #define CONTEXT_EXTENDED_REGISTERS (CONTEXT_i386 | 0x00000020L) // cpu specific extensions
  561. #define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_INTEGER |\
  562. CONTEXT_SEGMENTS)
  563. #define CONTEXT_ALL (CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_SEGMENTS | CONTEXT_FLOATING_POINT | CONTEXT_DEBUG_REGISTERS | CONTEXT_EXTENDED_REGISTERS)
  564. #endif
  565. #define MAXIMUM_SUPPORTED_EXTENSION 512
  566. typedef struct _FLOATING_SAVE_AREA {
  567. ULONG ControlWord;
  568. ULONG StatusWord;
  569. ULONG TagWord;
  570. ULONG ErrorOffset;
  571. ULONG ErrorSelector;
  572. ULONG DataOffset;
  573. ULONG DataSelector;
  574. UCHAR RegisterArea[SIZE_OF_80387_REGISTERS];
  575. ULONG Cr0NpxState;
  576. } FLOATING_SAVE_AREA;
  577. typedef FLOATING_SAVE_AREA *PFLOATING_SAVE_AREA;
  578. //
  579. // Context Frame
  580. //
  581. // This frame has a several purposes: 1) it is used as an argument to
  582. // NtContinue, 2) is is used to constuct a call frame for APC delivery,
  583. // and 3) it is used in the user level thread creation routines.
  584. //
  585. // The layout of the record conforms to a standard call frame.
  586. //
  587. typedef struct _CONTEXT {
  588. //
  589. // The flags values within this flag control the contents of
  590. // a CONTEXT record.
  591. //
  592. // If the context record is used as an input parameter, then
  593. // for each portion of the context record controlled by a flag
  594. // whose value is set, it is assumed that that portion of the
  595. // context record contains valid context. If the context record
  596. // is being used to modify a threads context, then only that
  597. // portion of the threads context will be modified.
  598. //
  599. // If the context record is used as an IN OUT parameter to capture
  600. // the context of a thread, then only those portions of the thread's
  601. // context corresponding to set flags will be returned.
  602. //
  603. // The context record is never used as an OUT only parameter.
  604. //
  605. ULONG ContextFlags;
  606. //
  607. // This section is specified/returned if CONTEXT_DEBUG_REGISTERS is
  608. // set in ContextFlags. Note that CONTEXT_DEBUG_REGISTERS is NOT
  609. // included in CONTEXT_FULL.
  610. //
  611. ULONG Dr0;
  612. ULONG Dr1;
  613. ULONG Dr2;
  614. ULONG Dr3;
  615. ULONG Dr6;
  616. ULONG Dr7;
  617. //
  618. // This section is specified/returned if the
  619. // ContextFlags word contians the flag CONTEXT_FLOATING_POINT.
  620. //
  621. FLOATING_SAVE_AREA FloatSave;
  622. //
  623. // This section is specified/returned if the
  624. // ContextFlags word contians the flag CONTEXT_SEGMENTS.
  625. //
  626. ULONG SegGs;
  627. ULONG SegFs;
  628. ULONG SegEs;
  629. ULONG SegDs;
  630. //
  631. // This section is specified/returned if the
  632. // ContextFlags word contians the flag CONTEXT_INTEGER.
  633. //
  634. ULONG Edi;
  635. ULONG Esi;
  636. ULONG Ebx;
  637. ULONG Edx;
  638. ULONG Ecx;
  639. ULONG Eax;
  640. //
  641. // This section is specified/returned if the
  642. // ContextFlags word contians the flag CONTEXT_CONTROL.
  643. //
  644. ULONG Ebp;
  645. ULONG Eip;
  646. ULONG SegCs; // MUST BE SANITIZED
  647. ULONG EFlags; // MUST BE SANITIZED
  648. ULONG Esp;
  649. ULONG SegSs;
  650. //
  651. // This section is specified/returned if the ContextFlags word
  652. // contains the flag CONTEXT_EXTENDED_REGISTERS.
  653. // The format and contexts are processor specific
  654. //
  655. UCHAR ExtendedRegisters[MAXIMUM_SUPPORTED_EXTENSION];
  656. } CONTEXT;
  657. typedef CONTEXT *PCONTEXT;
  658. #endif //_X86_
  659. #endif // _X86_
  660. #if defined(_AMD64_)
  661. #if defined(_M_AMD64) && !defined(RC_INVOKED) && !defined(MIDL_PASS)
  662. //
  663. // Define bit test intrinsics.
  664. //
  665. #ifdef __cplusplus
  666. extern "C" {
  667. #endif
  668. #define BitTest _bittest
  669. #define BitTestAndComplement _bittestandcomplement
  670. #define BitTestAndSet _bittestandset
  671. #define BitTestAndReset _bittestandreset
  672. #define InterlockedBitTestAndSet _interlockedbittestandset
  673. #define InterlockedBitTestAndReset _interlockedbittestandreset
  674. #define BitTest64 _bittest64
  675. #define BitTestAndComplement64 _bittestandcomplement64
  676. #define BitTestAndSet64 _bittestandset64
  677. #define BitTestAndReset64 _bittestandreset64
  678. #define InterlockedBitTestAndSet64 _interlockedbittestandset64
  679. #define InterlockedBitTestAndReset64 _interlockedbittestandreset64
  680. BOOLEAN
  681. _bittest (
  682. IN LONG *Base,
  683. IN LONG Offset
  684. );
  685. BOOLEAN
  686. _bittestandcomplement (
  687. IN LONG *Base,
  688. IN LONG Offset
  689. );
  690. BOOLEAN
  691. _bittestandset (
  692. IN LONG *Base,
  693. IN LONG Offset
  694. );
  695. BOOLEAN
  696. _bittestandreset (
  697. IN LONG *Base,
  698. IN LONG Offset
  699. );
  700. BOOLEAN
  701. _interlockedbittestandset (
  702. IN LONG *Base,
  703. IN LONG Offset
  704. );
  705. BOOLEAN
  706. _interlockedbittestandreset (
  707. IN LONG *Base,
  708. IN LONG Offset
  709. );
  710. BOOLEAN
  711. _bittest64 (
  712. IN LONG64 *Base,
  713. IN LONG64 Offset
  714. );
  715. BOOLEAN
  716. _bittestandcomplement64 (
  717. IN LONG64 *Base,
  718. IN LONG64 Offset
  719. );
  720. BOOLEAN
  721. _bittestandset64 (
  722. IN LONG64 *Base,
  723. IN LONG64 Offset
  724. );
  725. BOOLEAN
  726. _bittestandreset64 (
  727. IN LONG64 *Base,
  728. IN LONG64 Offset
  729. );
  730. BOOLEAN
  731. _interlockedbittestandset64 (
  732. IN LONG64 *Base,
  733. IN LONG64 Offset
  734. );
  735. BOOLEAN
  736. _interlockedbittestandreset64 (
  737. IN LONG64 *Base,
  738. IN LONG64 Offset
  739. );
  740. #pragma intrinsic(_bittest)
  741. #pragma intrinsic(_bittestandcomplement)
  742. #pragma intrinsic(_bittestandset)
  743. #pragma intrinsic(_bittestandreset)
  744. #pragma intrinsic(_interlockedbittestandset)
  745. #pragma intrinsic(_interlockedbittestandreset)
  746. #pragma intrinsic(_bittest64)
  747. #pragma intrinsic(_bittestandcomplement64)
  748. #pragma intrinsic(_bittestandset64)
  749. #pragma intrinsic(_bittestandreset64)
  750. #pragma intrinsic(_interlockedbittestandset64)
  751. #pragma intrinsic(_interlockedbittestandreset64)
  752. //
  753. // Define bit scan intrinsics.
  754. //
  755. #define BitScanForward _BitScanForward
  756. #define BitScanReverse _BitScanReverse
  757. #define BitScanForward64 _BitScanForward64
  758. #define BitScanReverse64 _BitScanReverse64
  759. BOOLEAN
  760. _BitScanForward (
  761. OUT ULONG *Index,
  762. IN ULONG Mask
  763. );
  764. BOOLEAN
  765. _BitScanReverse (
  766. OUT ULONG *Index,
  767. IN ULONG Mask
  768. );
  769. BOOLEAN
  770. _BitScanForward64 (
  771. OUT ULONG *Index,
  772. IN ULONG64 Mask
  773. );
  774. BOOLEAN
  775. _BitScanReverse64 (
  776. OUT ULONG *Index,
  777. IN ULONG64 Mask
  778. );
  779. #pragma intrinsic(_BitScanForward)
  780. #pragma intrinsic(_BitScanReverse)
  781. #pragma intrinsic(_BitScanForward64)
  782. #pragma intrinsic(_BitScanReverse64)
  783. //
  784. // Define function to flush a cache line.
  785. //
  786. #define CacheLineFlush(Address) _mm_clflush(Address)
  787. VOID
  788. _mm_clflush (
  789. PVOID Address
  790. );
  791. #pragma intrinsic(_mm_clflush)
  792. //
  793. // Define memory fence intrinsics
  794. //
  795. #define LoadFence _mm_lfence
  796. #define MemoryFence _mm_mfence
  797. #define StoreFence _mm_sfence
  798. VOID
  799. _mm_lfence (
  800. VOID
  801. );
  802. VOID
  803. _mm_mfence (
  804. VOID
  805. );
  806. VOID
  807. _mm_sfence (
  808. VOID
  809. );
  810. void
  811. _mm_prefetch(
  812. CHAR CONST *a,
  813. int sel
  814. );
  815. /* constants for use with _mm_prefetch */
  816. #define _MM_HINT_T0 1
  817. #define _MM_HINT_T1 2
  818. #define _MM_HINT_T2 3
  819. #define _MM_HINT_NTA 0
  820. #pragma intrinsic(_mm_prefetch)
  821. #pragma intrinsic(_mm_lfence)
  822. #pragma intrinsic(_mm_mfence)
  823. #pragma intrinsic(_mm_sfence)
  824. #define YieldProcessor()
  825. #define MemoryBarrier _mm_mfence
  826. #define PreFetchCacheLine(l, a) _mm_prefetch((CHAR CONST *) a, l)
  827. //
  828. // PreFetchCacheLine level defines.
  829. //
  830. #define PF_TEMPORAL_LEVEL_1 _MM_HINT_T0
  831. #define PF_NON_TEMPORAL_LEVEL_ALL _MM_HINT_NTA
  832. //
  833. // Define function to get the caller's EFLAGs value.
  834. //
  835. #define GetCallersEflags() __getcallerseflags()
  836. unsigned __int32
  837. __getcallerseflags (
  838. VOID
  839. );
  840. #pragma intrinsic(__getcallerseflags)
  841. //
  842. // Define function to read the value of the time stamp counter
  843. //
  844. #define ReadTimeStampCounter() __rdtsc()
  845. ULONG64
  846. __rdtsc (
  847. VOID
  848. );
  849. #pragma intrinsic(__rdtsc)
  850. //
  851. // Define functions to move strings as bytes, words, dwords, and qwords.
  852. //
  853. VOID
  854. __movsb (
  855. IN PUCHAR Destination,
  856. IN PUCHAR Source,
  857. IN SIZE_T Count
  858. );
  859. VOID
  860. __movsw (
  861. IN PUSHORT Destination,
  862. IN PUSHORT Source,
  863. IN SIZE_T Count
  864. );
  865. VOID
  866. __movsd (
  867. IN PULONG Destination,
  868. IN PULONG Source,
  869. IN SIZE_T Count
  870. );
  871. VOID
  872. __movsq (
  873. IN PULONGLONG Destination,
  874. IN PULONGLONG Source,
  875. IN SIZE_T Count
  876. );
  877. #pragma intrinsic(__movsb)
  878. #pragma intrinsic(__movsw)
  879. #pragma intrinsic(__movsd)
  880. #pragma intrinsic(__movsq)
  881. //
  882. // Define functions to store strings as bytes, words, dwords, and qwords.
  883. //
  884. VOID
  885. __stosb (
  886. IN PUCHAR Destination,
  887. IN UCHAR Value,
  888. IN SIZE_T Count
  889. );
  890. VOID
  891. __stosw (
  892. IN PUSHORT Destination,
  893. IN USHORT Value,
  894. IN SIZE_T Count
  895. );
  896. VOID
  897. __stosd (
  898. IN PULONG Destination,
  899. IN ULONG Value,
  900. IN SIZE_T Count
  901. );
  902. VOID
  903. __stosq (
  904. IN PULONG64 Destination,
  905. IN ULONG64 Value,
  906. IN SIZE_T Count
  907. );
  908. #pragma intrinsic(__stosb)
  909. #pragma intrinsic(__stosw)
  910. #pragma intrinsic(__stosd)
  911. #pragma intrinsic(__stosq)
  912. //
  913. // Define functions to capture the high 64-bits of a 128-bit multiply.
  914. //
  915. #define MultiplyHigh __mulh
  916. #define UnsignedMultiplyHigh __umulh
  917. LONGLONG
  918. MultiplyHigh (
  919. IN LONGLONG Multiplier,
  920. IN LONGLONG Multiplicand
  921. );
  922. ULONGLONG
  923. UnsignedMultiplyHigh (
  924. IN ULONGLONG Multiplier,
  925. IN ULONGLONG Multiplicand
  926. );
  927. #pragma intrinsic(__mulh)
  928. #pragma intrinsic(__umulh)
  929. //
  930. // Define functions to read and write the uer TEB and the system PCR/PRCB.
  931. //
  932. UCHAR
  933. __readgsbyte (
  934. IN ULONG Offset
  935. );
  936. USHORT
  937. __readgsword (
  938. IN ULONG Offset
  939. );
  940. ULONG
  941. __readgsdword (
  942. IN ULONG Offset
  943. );
  944. ULONG64
  945. __readgsqword (
  946. IN ULONG Offset
  947. );
  948. VOID
  949. __writegsbyte (
  950. IN ULONG Offset,
  951. IN UCHAR Data
  952. );
  953. VOID
  954. __writegsword (
  955. IN ULONG Offset,
  956. IN USHORT Data
  957. );
  958. VOID
  959. __writegsdword (
  960. IN ULONG Offset,
  961. IN ULONG Data
  962. );
  963. VOID
  964. __writegsqword (
  965. IN ULONG Offset,
  966. IN ULONG64 Data
  967. );
  968. #pragma intrinsic(__readgsbyte)
  969. #pragma intrinsic(__readgsword)
  970. #pragma intrinsic(__readgsdword)
  971. #pragma intrinsic(__readgsqword)
  972. #pragma intrinsic(__writegsbyte)
  973. #pragma intrinsic(__writegsword)
  974. #pragma intrinsic(__writegsdword)
  975. #pragma intrinsic(__writegsqword)
  976. #ifdef __cplusplus
  977. }
  978. #endif
  979. #endif // defined(_M_AMD64) && !defined(RC_INVOKED) && !defined(MIDL_PASS)
  980. //
  981. // Size of kernel mode stack.
  982. //
  983. #define KERNEL_STACK_SIZE 0x6000
  984. //
  985. // Define size of large kernel mode stack for callbacks.
  986. //
  987. #define KERNEL_LARGE_STACK_SIZE 0xf000
  988. //
  989. // Define number of pages to initialize in a large kernel stack.
  990. //
  991. #define KERNEL_LARGE_STACK_COMMIT 0x5000
  992. //
  993. // Define the size of the stack used for processing an MCA exception.
  994. //
  995. #define KERNEL_MCA_EXCEPTION_STACK_SIZE 0x2000
  996. //
  997. // The following flags control the contents of the CONTEXT structure.
  998. //
  999. #if !defined(RC_INVOKED)
  1000. #define CONTEXT_AMD64 0x100000
  1001. #define CONTEXT_CONTROL (CONTEXT_AMD64 | 0x1L)
  1002. #define CONTEXT_INTEGER (CONTEXT_AMD64 | 0x2L)
  1003. #define CONTEXT_SEGMENTS (CONTEXT_AMD64 | 0x4L)
  1004. #define CONTEXT_FLOATING_POINT (CONTEXT_AMD64 | 0x8L)
  1005. #define CONTEXT_DEBUG_REGISTERS (CONTEXT_AMD64 | 0x10L)
  1006. #define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_FLOATING_POINT)
  1007. #define CONTEXT_ALL (CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_SEGMENTS | CONTEXT_FLOATING_POINT | CONTEXT_DEBUG_REGISTERS)
  1008. #endif // !defined(RC_INVOKED)
  1009. //
  1010. // Define initial MxCsr control.
  1011. //
  1012. #define INITIAL_MXCSR 0x1f80 // initial MXCSR value
  1013. //
  1014. // Define 128-bit 16-byte aligned xmm register type.
  1015. //
  1016. typedef struct DECLSPEC_ALIGN(16) _M128 {
  1017. ULONGLONG Low;
  1018. LONGLONG High;
  1019. } M128, *PM128;
  1020. //
  1021. // Format of data for fnsave/frstor instructions.
  1022. //
  1023. // This structure is used to store the legacy floating point state.
  1024. //
  1025. typedef struct _LEGACY_SAVE_AREA {
  1026. USHORT ControlWord;
  1027. USHORT Reserved0;
  1028. USHORT StatusWord;
  1029. USHORT Reserved1;
  1030. USHORT TagWord;
  1031. USHORT Reserved2;
  1032. ULONG ErrorOffset;
  1033. USHORT ErrorSelector;
  1034. USHORT ErrorOpcode;
  1035. ULONG DataOffset;
  1036. USHORT DataSelector;
  1037. USHORT Reserved3;
  1038. UCHAR FloatRegisters[8 * 10];
  1039. } LEGACY_SAVE_AREA, *PLEGACY_SAVE_AREA;
  1040. #define LEGACY_SAVE_AREA_LENGTH ((sizeof(LEGACY_SAVE_AREA) + 15) & ~15)
  1041. //
  1042. // Context Frame
  1043. //
  1044. // This frame has a several purposes: 1) it is used as an argument to
  1045. // NtContinue, 2) is is used to constuct a call frame for APC delivery,
  1046. // and 3) it is used in the user level thread creation routines.
  1047. //
  1048. //
  1049. // The flags field within this record controls the contents of a CONTEXT
  1050. // record.
  1051. //
  1052. // If the context record is used as an input parameter, then for each
  1053. // portion of the context record controlled by a flag whose value is
  1054. // set, it is assumed that that portion of the context record contains
  1055. // valid context. If the context record is being used to modify a threads
  1056. // context, then only that portion of the threads context is modified.
  1057. //
  1058. // If the context record is used as an output parameter to capture the
  1059. // context of a thread, then only those portions of the thread's context
  1060. // corresponding to set flags will be returned.
  1061. //
  1062. // CONTEXT_CONTROL specifies SegSs, Rsp, SegCs, Rip, and EFlags.
  1063. //
  1064. // CONTEXT_INTEGER specifies Rax, Rcx, Rdx, Rbx, Rbp, Rsi, Rdi, and R8-R15.
  1065. //
  1066. // CONTEXT_SEGMENTS specifies SegDs, SegEs, SegFs, and SegGs.
  1067. //
  1068. // CONTEXT_DEBUG_REGISTERS specifies Dr0-Dr3 and Dr6-Dr7.
  1069. //
  1070. // CONTEXT_MMX_REGISTERS specifies the floating point and extended registers
  1071. // Mm0/St0-Mm7/St7 and Xmm0-Xmm15).
  1072. //
  1073. typedef struct DECLSPEC_ALIGN(16) _CONTEXT {
  1074. //
  1075. // Register parameter home addresses.
  1076. //
  1077. ULONG64 P1Home;
  1078. ULONG64 P2Home;
  1079. ULONG64 P3Home;
  1080. ULONG64 P4Home;
  1081. ULONG64 P5Home;
  1082. ULONG64 P6Home;
  1083. //
  1084. // Control flags.
  1085. //
  1086. ULONG ContextFlags;
  1087. ULONG MxCsr;
  1088. //
  1089. // Segment Registers and processor flags.
  1090. //
  1091. USHORT SegCs;
  1092. USHORT SegDs;
  1093. USHORT SegEs;
  1094. USHORT SegFs;
  1095. USHORT SegGs;
  1096. USHORT SegSs;
  1097. ULONG EFlags;
  1098. //
  1099. // Debug registers
  1100. //
  1101. ULONG64 Dr0;
  1102. ULONG64 Dr1;
  1103. ULONG64 Dr2;
  1104. ULONG64 Dr3;
  1105. ULONG64 Dr6;
  1106. ULONG64 Dr7;
  1107. //
  1108. // Integer registers.
  1109. //
  1110. ULONG64 Rax;
  1111. ULONG64 Rcx;
  1112. ULONG64 Rdx;
  1113. ULONG64 Rbx;
  1114. ULONG64 Rsp;
  1115. ULONG64 Rbp;
  1116. ULONG64 Rsi;
  1117. ULONG64 Rdi;
  1118. ULONG64 R8;
  1119. ULONG64 R9;
  1120. ULONG64 R10;
  1121. ULONG64 R11;
  1122. ULONG64 R12;
  1123. ULONG64 R13;
  1124. ULONG64 R14;
  1125. ULONG64 R15;
  1126. //
  1127. // Program counter.
  1128. //
  1129. ULONG64 Rip;
  1130. //
  1131. // MMX/floating point state.
  1132. //
  1133. M128 Xmm0;
  1134. M128 Xmm1;
  1135. M128 Xmm2;
  1136. M128 Xmm3;
  1137. M128 Xmm4;
  1138. M128 Xmm5;
  1139. M128 Xmm6;
  1140. M128 Xmm7;
  1141. M128 Xmm8;
  1142. M128 Xmm9;
  1143. M128 Xmm10;
  1144. M128 Xmm11;
  1145. M128 Xmm12;
  1146. M128 Xmm13;
  1147. M128 Xmm14;
  1148. M128 Xmm15;
  1149. //
  1150. // Legacy floating point state.
  1151. //
  1152. LEGACY_SAVE_AREA FltSave;
  1153. ULONG Fill;
  1154. //
  1155. // Special debug control registers.
  1156. //
  1157. ULONG64 DebugControl;
  1158. ULONG64 LastBranchToRip;
  1159. ULONG64 LastBranchFromRip;
  1160. ULONG64 LastExceptionToRip;
  1161. ULONG64 LastExceptionFromRip;
  1162. ULONG64 Fill1;
  1163. } CONTEXT, *PCONTEXT;
  1164. #endif // _AMD64_
  1165. #ifdef _IA64_
  1166. //
  1167. // Define size of kernel mode stack.
  1168. //
  1169. #define KERNEL_STACK_SIZE 0x8000
  1170. //
  1171. // Define size of large kernel mode stack for callbacks.
  1172. //
  1173. #define KERNEL_LARGE_STACK_SIZE 0x1A000
  1174. //
  1175. // Define number of pages to initialize in a large kernel stack.
  1176. //
  1177. #define KERNEL_LARGE_STACK_COMMIT 0x8000
  1178. //
  1179. // Define size of kernel mode backing store stack.
  1180. //
  1181. #define KERNEL_BSTORE_SIZE 0x8000
  1182. //
  1183. // Define size of large kernel mode backing store for callbacks.
  1184. //
  1185. #define KERNEL_LARGE_BSTORE_SIZE 0x10000
  1186. //
  1187. // Define number of pages to initialize in a large kernel backing store.
  1188. //
  1189. #define KERNEL_LARGE_BSTORE_COMMIT 0x8000
  1190. //
  1191. // Define base address for kernel and user space.
  1192. //
  1193. #define UREGION_INDEX 0
  1194. #define KREGION_INDEX 7
  1195. #define UADDRESS_BASE ((ULONGLONG)UREGION_INDEX << 61)
  1196. #define KADDRESS_BASE ((ULONGLONG)KREGION_INDEX << 61)
  1197. void
  1198. __yield(
  1199. void
  1200. );
  1201. void
  1202. __mf(
  1203. void
  1204. );
  1205. void
  1206. __lfetch(
  1207. int Level,
  1208. VOID CONST *Address
  1209. );
  1210. void
  1211. __lfetchfault(
  1212. int Level,
  1213. VOID CONST *Address
  1214. );
  1215. //
  1216. // __lfetch control defines.
  1217. //
  1218. #define MD_LFHINT_NONE 0x00
  1219. #define MD_LFHINT_NT1 0x01
  1220. #define MD_LFHINT_NT2 0x02
  1221. #define MD_LFHINT_NTA 0x03
  1222. #pragma intrinsic (__yield)
  1223. #pragma intrinsic (__lfetch)
  1224. #pragma intrinsic (__lfetchfault)
  1225. #pragma intrinsic (__mf)
  1226. #define YieldProcessor __yield
  1227. #define MemoryBarrier __mf
  1228. #define PreFetchCacheLine __lfetch
  1229. //
  1230. // PreFetchCacheLine level defines.
  1231. //
  1232. #define PF_TEMPORAL_LEVEL_1 MD_LFHINT_NONE
  1233. #define PF_NON_TEMPORAL_LEVEL_ALL MD_LFHINT_NTA
  1234. //
  1235. // The following flags control the contents of the CONTEXT structure.
  1236. //
  1237. #if !defined(RC_INVOKED)
  1238. #define CONTEXT_IA64 0x00080000
  1239. #define CONTEXT_CONTROL (CONTEXT_IA64 | 0x00000001L)
  1240. #define CONTEXT_LOWER_FLOATING_POINT (CONTEXT_IA64 | 0x00000002L)
  1241. #define CONTEXT_HIGHER_FLOATING_POINT (CONTEXT_IA64 | 0x00000004L)
  1242. #define CONTEXT_INTEGER (CONTEXT_IA64 | 0x00000008L)
  1243. #define CONTEXT_DEBUG (CONTEXT_IA64 | 0x00000010L)
  1244. #define CONTEXT_IA32_CONTROL (CONTEXT_IA64 | 0x00000020L) // Includes StIPSR
  1245. #define CONTEXT_FLOATING_POINT (CONTEXT_LOWER_FLOATING_POINT | CONTEXT_HIGHER_FLOATING_POINT)
  1246. #define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_FLOATING_POINT | CONTEXT_INTEGER | CONTEXT_IA32_CONTROL)
  1247. #define CONTEXT_ALL (CONTEXT_CONTROL | CONTEXT_FLOATING_POINT | CONTEXT_INTEGER | CONTEXT_DEBUG | CONTEXT_IA32_CONTROL)
  1248. #define CONTEXT_EXCEPTION_ACTIVE 0x8000000
  1249. #define CONTEXT_SERVICE_ACTIVE 0x10000000
  1250. #define CONTEXT_EXCEPTION_REQUEST 0x40000000
  1251. #define CONTEXT_EXCEPTION_REPORTING 0x80000000
  1252. #endif // !defined(RC_INVOKED)
  1253. //
  1254. // Context Frame
  1255. //
  1256. // This frame has a several purposes: 1) it is used as an argument to
  1257. // NtContinue, 2) it is used to construct a call frame for APC delivery,
  1258. // 3) it is used to construct a call frame for exception dispatching
  1259. // in user mode, 4) it is used in the user level thread creation
  1260. // routines, and 5) it is used to to pass thread state to debuggers.
  1261. //
  1262. // N.B. Because this record is used as a call frame, it must be EXACTLY
  1263. // a multiple of 16 bytes in length and aligned on a 16-byte boundary.
  1264. //
  1265. typedef struct _CONTEXT {
  1266. //
  1267. // The flags values within this flag control the contents of
  1268. // a CONTEXT record.
  1269. //
  1270. // If the context record is used as an input parameter, then
  1271. // for each portion of the context record controlled by a flag
  1272. // whose value is set, it is assumed that that portion of the
  1273. // context record contains valid context. If the context record
  1274. // is being used to modify a thread's context, then only that
  1275. // portion of the threads context will be modified.
  1276. //
  1277. // If the context record is used as an IN OUT parameter to capture
  1278. // the context of a thread, then only those portions of the thread's
  1279. // context corresponding to set flags will be returned.
  1280. //
  1281. // The context record is never used as an OUT only parameter.
  1282. //
  1283. ULONG ContextFlags;
  1284. ULONG Fill1[3]; // for alignment of following on 16-byte boundary
  1285. //
  1286. // This section is specified/returned if the ContextFlags word contains
  1287. // the flag CONTEXT_DEBUG.
  1288. //
  1289. // N.B. CONTEXT_DEBUG is *not* part of CONTEXT_FULL.
  1290. //
  1291. ULONGLONG DbI0;
  1292. ULONGLONG DbI1;
  1293. ULONGLONG DbI2;
  1294. ULONGLONG DbI3;
  1295. ULONGLONG DbI4;
  1296. ULONGLONG DbI5;
  1297. ULONGLONG DbI6;
  1298. ULONGLONG DbI7;
  1299. ULONGLONG DbD0;
  1300. ULONGLONG DbD1;
  1301. ULONGLONG DbD2;
  1302. ULONGLONG DbD3;
  1303. ULONGLONG DbD4;
  1304. ULONGLONG DbD5;
  1305. ULONGLONG DbD6;
  1306. ULONGLONG DbD7;
  1307. //
  1308. // This section is specified/returned if the ContextFlags word contains
  1309. // the flag CONTEXT_LOWER_FLOATING_POINT.
  1310. //
  1311. FLOAT128 FltS0;
  1312. FLOAT128 FltS1;
  1313. FLOAT128 FltS2;
  1314. FLOAT128 FltS3;
  1315. FLOAT128 FltT0;
  1316. FLOAT128 FltT1;
  1317. FLOAT128 FltT2;
  1318. FLOAT128 FltT3;
  1319. FLOAT128 FltT4;
  1320. FLOAT128 FltT5;
  1321. FLOAT128 FltT6;
  1322. FLOAT128 FltT7;
  1323. FLOAT128 FltT8;
  1324. FLOAT128 FltT9;
  1325. //
  1326. // This section is specified/returned if the ContextFlags word contains
  1327. // the flag CONTEXT_HIGHER_FLOATING_POINT.
  1328. //
  1329. FLOAT128 FltS4;
  1330. FLOAT128 FltS5;
  1331. FLOAT128 FltS6;
  1332. FLOAT128 FltS7;
  1333. FLOAT128 FltS8;
  1334. FLOAT128 FltS9;
  1335. FLOAT128 FltS10;
  1336. FLOAT128 FltS11;
  1337. FLOAT128 FltS12;
  1338. FLOAT128 FltS13;
  1339. FLOAT128 FltS14;
  1340. FLOAT128 FltS15;
  1341. FLOAT128 FltS16;
  1342. FLOAT128 FltS17;
  1343. FLOAT128 FltS18;
  1344. FLOAT128 FltS19;
  1345. FLOAT128 FltF32;
  1346. FLOAT128 FltF33;
  1347. FLOAT128 FltF34;
  1348. FLOAT128 FltF35;
  1349. FLOAT128 FltF36;
  1350. FLOAT128 FltF37;
  1351. FLOAT128 FltF38;
  1352. FLOAT128 FltF39;
  1353. FLOAT128 FltF40;
  1354. FLOAT128 FltF41;
  1355. FLOAT128 FltF42;
  1356. FLOAT128 FltF43;
  1357. FLOAT128 FltF44;
  1358. FLOAT128 FltF45;
  1359. FLOAT128 FltF46;
  1360. FLOAT128 FltF47;
  1361. FLOAT128 FltF48;
  1362. FLOAT128 FltF49;
  1363. FLOAT128 FltF50;
  1364. FLOAT128 FltF51;
  1365. FLOAT128 FltF52;
  1366. FLOAT128 FltF53;
  1367. FLOAT128 FltF54;
  1368. FLOAT128 FltF55;
  1369. FLOAT128 FltF56;
  1370. FLOAT128 FltF57;
  1371. FLOAT128 FltF58;
  1372. FLOAT128 FltF59;
  1373. FLOAT128 FltF60;
  1374. FLOAT128 FltF61;
  1375. FLOAT128 FltF62;
  1376. FLOAT128 FltF63;
  1377. FLOAT128 FltF64;
  1378. FLOAT128 FltF65;
  1379. FLOAT128 FltF66;
  1380. FLOAT128 FltF67;
  1381. FLOAT128 FltF68;
  1382. FLOAT128 FltF69;
  1383. FLOAT128 FltF70;
  1384. FLOAT128 FltF71;
  1385. FLOAT128 FltF72;
  1386. FLOAT128 FltF73;
  1387. FLOAT128 FltF74;
  1388. FLOAT128 FltF75;
  1389. FLOAT128 FltF76;
  1390. FLOAT128 FltF77;
  1391. FLOAT128 FltF78;
  1392. FLOAT128 FltF79;
  1393. FLOAT128 FltF80;
  1394. FLOAT128 FltF81;
  1395. FLOAT128 FltF82;
  1396. FLOAT128 FltF83;
  1397. FLOAT128 FltF84;
  1398. FLOAT128 FltF85;
  1399. FLOAT128 FltF86;
  1400. FLOAT128 FltF87;
  1401. FLOAT128 FltF88;
  1402. FLOAT128 FltF89;
  1403. FLOAT128 FltF90;
  1404. FLOAT128 FltF91;
  1405. FLOAT128 FltF92;
  1406. FLOAT128 FltF93;
  1407. FLOAT128 FltF94;
  1408. FLOAT128 FltF95;
  1409. FLOAT128 FltF96;
  1410. FLOAT128 FltF97;
  1411. FLOAT128 FltF98;
  1412. FLOAT128 FltF99;
  1413. FLOAT128 FltF100;
  1414. FLOAT128 FltF101;
  1415. FLOAT128 FltF102;
  1416. FLOAT128 FltF103;
  1417. FLOAT128 FltF104;
  1418. FLOAT128 FltF105;
  1419. FLOAT128 FltF106;
  1420. FLOAT128 FltF107;
  1421. FLOAT128 FltF108;
  1422. FLOAT128 FltF109;
  1423. FLOAT128 FltF110;
  1424. FLOAT128 FltF111;
  1425. FLOAT128 FltF112;
  1426. FLOAT128 FltF113;
  1427. FLOAT128 FltF114;
  1428. FLOAT128 FltF115;
  1429. FLOAT128 FltF116;
  1430. FLOAT128 FltF117;
  1431. FLOAT128 FltF118;
  1432. FLOAT128 FltF119;
  1433. FLOAT128 FltF120;
  1434. FLOAT128 FltF121;
  1435. FLOAT128 FltF122;
  1436. FLOAT128 FltF123;
  1437. FLOAT128 FltF124;
  1438. FLOAT128 FltF125;
  1439. FLOAT128 FltF126;
  1440. FLOAT128 FltF127;
  1441. //
  1442. // This section is specified/returned if the ContextFlags word contains
  1443. // the flag CONTEXT_LOWER_FLOATING_POINT | CONTEXT_HIGHER_FLOATING_POINT | CONTEXT_CONTROL.
  1444. //
  1445. ULONGLONG StFPSR; // FP status
  1446. //
  1447. // This section is specified/returned if the ContextFlags word contains
  1448. // the flag CONTEXT_INTEGER.
  1449. //
  1450. // N.B. The registers gp, sp, rp are part of the control context
  1451. //
  1452. ULONGLONG IntGp; // r1, volatile
  1453. ULONGLONG IntT0; // r2-r3, volatile
  1454. ULONGLONG IntT1; //
  1455. ULONGLONG IntS0; // r4-r7, preserved
  1456. ULONGLONG IntS1;
  1457. ULONGLONG IntS2;
  1458. ULONGLONG IntS3;
  1459. ULONGLONG IntV0; // r8, volatile
  1460. ULONGLONG IntT2; // r9-r11, volatile
  1461. ULONGLONG IntT3;
  1462. ULONGLONG IntT4;
  1463. ULONGLONG IntSp; // stack pointer (r12), special
  1464. ULONGLONG IntTeb; // teb (r13), special
  1465. ULONGLONG IntT5; // r14-r31, volatile
  1466. ULONGLONG IntT6;
  1467. ULONGLONG IntT7;
  1468. ULONGLONG IntT8;
  1469. ULONGLONG IntT9;
  1470. ULONGLONG IntT10;
  1471. ULONGLONG IntT11;
  1472. ULONGLONG IntT12;
  1473. ULONGLONG IntT13;
  1474. ULONGLONG IntT14;
  1475. ULONGLONG IntT15;
  1476. ULONGLONG IntT16;
  1477. ULONGLONG IntT17;
  1478. ULONGLONG IntT18;
  1479. ULONGLONG IntT19;
  1480. ULONGLONG IntT20;
  1481. ULONGLONG IntT21;
  1482. ULONGLONG IntT22;
  1483. ULONGLONG IntNats; // Nat bits for r1-r31
  1484. // r1-r31 in bits 1 thru 31.
  1485. ULONGLONG Preds; // predicates, preserved
  1486. ULONGLONG BrRp; // return pointer, b0, preserved
  1487. ULONGLONG BrS0; // b1-b5, preserved
  1488. ULONGLONG BrS1;
  1489. ULONGLONG BrS2;
  1490. ULONGLONG BrS3;
  1491. ULONGLONG BrS4;
  1492. ULONGLONG BrT0; // b6-b7, volatile
  1493. ULONGLONG BrT1;
  1494. //
  1495. // This section is specified/returned if the ContextFlags word contains
  1496. // the flag CONTEXT_CONTROL.
  1497. //
  1498. // Other application registers
  1499. ULONGLONG ApUNAT; // User Nat collection register, preserved
  1500. ULONGLONG ApLC; // Loop counter register, preserved
  1501. ULONGLONG ApEC; // Epilog counter register, preserved
  1502. ULONGLONG ApCCV; // CMPXCHG value register, volatile
  1503. ULONGLONG ApDCR; // Default control register (TBD)
  1504. // Register stack info
  1505. ULONGLONG RsPFS; // Previous function state, preserved
  1506. ULONGLONG RsBSP; // Backing store pointer, preserved
  1507. ULONGLONG RsBSPSTORE;
  1508. ULONGLONG RsRSC; // RSE configuration, volatile
  1509. ULONGLONG RsRNAT; // RSE Nat collection register, preserved
  1510. // Trap Status Information
  1511. ULONGLONG StIPSR; // Interruption Processor Status
  1512. ULONGLONG StIIP; // Interruption IP
  1513. ULONGLONG StIFS; // Interruption Function State
  1514. // iA32 related control registers
  1515. ULONGLONG StFCR; // copy of Ar21
  1516. ULONGLONG Eflag; // Eflag copy of Ar24
  1517. ULONGLONG SegCSD; // iA32 CSDescriptor (Ar25)
  1518. ULONGLONG SegSSD; // iA32 SSDescriptor (Ar26)
  1519. ULONGLONG Cflag; // Cr0+Cr4 copy of Ar27
  1520. ULONGLONG StFSR; // x86 FP status (copy of AR28)
  1521. ULONGLONG StFIR; // x86 FP status (copy of AR29)
  1522. ULONGLONG StFDR; // x86 FP status (copy of AR30)
  1523. ULONGLONG UNUSEDPACK; // added to pack StFDR to 16-bytes
  1524. } CONTEXT, *PCONTEXT;
  1525. //
  1526. // Plabel descriptor structure definition
  1527. //
  1528. typedef struct _PLABEL_DESCRIPTOR {
  1529. ULONGLONG EntryPoint;
  1530. ULONGLONG GlobalPointer;
  1531. } PLABEL_DESCRIPTOR, *PPLABEL_DESCRIPTOR;
  1532. #endif // _IA64_
  1533. //
  1534. // Define an access token from a programmer's viewpoint. The structure is
  1535. // completely opaque and the programer is only allowed to have pointers
  1536. // to tokens.
  1537. //
  1538. typedef PVOID PACCESS_TOKEN;
  1539. //
  1540. // Pointer to a SECURITY_DESCRIPTOR opaque data type.
  1541. //
  1542. typedef PVOID PSECURITY_DESCRIPTOR;
  1543. //
  1544. // Define a pointer to the Security ID data type (an opaque data type)
  1545. //
  1546. typedef PVOID PSID;
  1547. typedef ULONG ACCESS_MASK;
  1548. typedef ACCESS_MASK *PACCESS_MASK;
  1549. //
  1550. // The following are masks for the predefined standard access types
  1551. //
  1552. #define DELETE (0x00010000L)
  1553. #define READ_CONTROL (0x00020000L)
  1554. #define WRITE_DAC (0x00040000L)
  1555. #define WRITE_OWNER (0x00080000L)
  1556. #define SYNCHRONIZE (0x00100000L)
  1557. #define STANDARD_RIGHTS_REQUIRED (0x000F0000L)
  1558. #define STANDARD_RIGHTS_READ (READ_CONTROL)
  1559. #define STANDARD_RIGHTS_WRITE (READ_CONTROL)
  1560. #define STANDARD_RIGHTS_EXECUTE (READ_CONTROL)
  1561. #define STANDARD_RIGHTS_ALL (0x001F0000L)
  1562. #define SPECIFIC_RIGHTS_ALL (0x0000FFFFL)
  1563. //
  1564. // AccessSystemAcl access type
  1565. //
  1566. #define ACCESS_SYSTEM_SECURITY (0x01000000L)
  1567. //
  1568. // MaximumAllowed access type
  1569. //
  1570. #define MAXIMUM_ALLOWED (0x02000000L)
  1571. //
  1572. // These are the generic rights.
  1573. //
  1574. #define GENERIC_READ (0x80000000L)
  1575. #define GENERIC_WRITE (0x40000000L)
  1576. #define GENERIC_EXECUTE (0x20000000L)
  1577. #define GENERIC_ALL (0x10000000L)
  1578. //
  1579. // Define the generic mapping array. This is used to denote the
  1580. // mapping of each generic access right to a specific access mask.
  1581. //
  1582. typedef struct _GENERIC_MAPPING {
  1583. ACCESS_MASK GenericRead;
  1584. ACCESS_MASK GenericWrite;
  1585. ACCESS_MASK GenericExecute;
  1586. ACCESS_MASK GenericAll;
  1587. } GENERIC_MAPPING;
  1588. typedef GENERIC_MAPPING *PGENERIC_MAPPING;
  1589. ////////////////////////////////////////////////////////////////////////
  1590. // //
  1591. // LUID_AND_ATTRIBUTES //
  1592. // //
  1593. ////////////////////////////////////////////////////////////////////////
  1594. //
  1595. //
  1596. #include <pshpack4.h>
  1597. typedef struct _LUID_AND_ATTRIBUTES {
  1598. LUID Luid;
  1599. ULONG Attributes;
  1600. } LUID_AND_ATTRIBUTES, * PLUID_AND_ATTRIBUTES;
  1601. typedef LUID_AND_ATTRIBUTES LUID_AND_ATTRIBUTES_ARRAY[ANYSIZE_ARRAY];
  1602. typedef LUID_AND_ATTRIBUTES_ARRAY *PLUID_AND_ATTRIBUTES_ARRAY;
  1603. #include <poppack.h>
  1604. typedef enum {
  1605. WinNullSid = 0,
  1606. WinWorldSid = 1,
  1607. WinLocalSid = 2,
  1608. WinCreatorOwnerSid = 3,
  1609. WinCreatorGroupSid = 4,
  1610. WinCreatorOwnerServerSid = 5,
  1611. WinCreatorGroupServerSid = 6,
  1612. WinNtAuthoritySid = 7,
  1613. WinDialupSid = 8,
  1614. WinNetworkSid = 9,
  1615. WinBatchSid = 10,
  1616. WinInteractiveSid = 11,
  1617. WinServiceSid = 12,
  1618. WinAnonymousSid = 13,
  1619. WinProxySid = 14,
  1620. WinEnterpriseControllersSid = 15,
  1621. WinSelfSid = 16,
  1622. WinAuthenticatedUserSid = 17,
  1623. WinRestrictedCodeSid = 18,
  1624. WinTerminalServerSid = 19,
  1625. WinRemoteLogonIdSid = 20,
  1626. WinLogonIdsSid = 21,
  1627. WinLocalSystemSid = 22,
  1628. WinLocalServiceSid = 23,
  1629. WinNetworkServiceSid = 24,
  1630. WinBuiltinDomainSid = 25,
  1631. WinBuiltinAdministratorsSid = 26,
  1632. WinBuiltinUsersSid = 27,
  1633. WinBuiltinGuestsSid = 28,
  1634. WinBuiltinPowerUsersSid = 29,
  1635. WinBuiltinAccountOperatorsSid = 30,
  1636. WinBuiltinSystemOperatorsSid = 31,
  1637. WinBuiltinPrintOperatorsSid = 32,
  1638. WinBuiltinBackupOperatorsSid = 33,
  1639. WinBuiltinReplicatorSid = 34,
  1640. WinBuiltinPreWindows2000CompatibleAccessSid = 35,
  1641. WinBuiltinRemoteDesktopUsersSid = 36,
  1642. WinBuiltinNetworkConfigurationOperatorsSid = 37,
  1643. WinAccountAdministratorSid = 38,
  1644. WinAccountGuestSid = 39,
  1645. WinAccountKrbtgtSid = 40,
  1646. WinAccountDomainAdminsSid = 41,
  1647. WinAccountDomainUsersSid = 42,
  1648. WinAccountDomainGuestsSid = 43,
  1649. WinAccountComputersSid = 44,
  1650. WinAccountControllersSid = 45,
  1651. WinAccountCertAdminsSid = 46,
  1652. WinAccountSchemaAdminsSid = 47,
  1653. WinAccountEnterpriseAdminsSid = 48,
  1654. WinAccountPolicyAdminsSid = 49,
  1655. WinAccountRasAndIasServersSid = 50,
  1656. WinNTLMAuthenticationSid = 51,
  1657. WinDigestAuthenticationSid = 52,
  1658. WinSChannelAuthenticationSid = 53,
  1659. WinThisOrganizationSid = 54,
  1660. WinOtherOrganizationSid = 55,
  1661. WinBuiltinIncomingForestTrustBuildersSid = 56,
  1662. WinBuiltinPerfMonitoringUsersSid = 57,
  1663. WinBuiltinPerfLoggingUsersSid = 58,
  1664. WinBuiltinAuthorizationAccessSid = 59,
  1665. WinBuiltinTerminalServerLicenseServersSid = 60,
  1666. } WELL_KNOWN_SID_TYPE;
  1667. // This is the *current* ACL revision
  1668. #define ACL_REVISION (2)
  1669. #define ACL_REVISION_DS (4)
  1670. // This is the history of ACL revisions. Add a new one whenever
  1671. // ACL_REVISION is updated
  1672. #define ACL_REVISION1 (1)
  1673. #define MIN_ACL_REVISION ACL_REVISION2
  1674. #define ACL_REVISION2 (2)
  1675. #define ACL_REVISION3 (3)
  1676. #define ACL_REVISION4 (4)
  1677. #define MAX_ACL_REVISION ACL_REVISION4
  1678. typedef struct _ACL {
  1679. UCHAR AclRevision;
  1680. UCHAR Sbz1;
  1681. USHORT AclSize;
  1682. USHORT AceCount;
  1683. USHORT Sbz2;
  1684. } ACL;
  1685. typedef ACL *PACL;
  1686. //
  1687. // Current security descriptor revision value
  1688. //
  1689. #define SECURITY_DESCRIPTOR_REVISION (1)
  1690. #define SECURITY_DESCRIPTOR_REVISION1 (1)
  1691. //
  1692. // Privilege attributes
  1693. //
  1694. #define SE_PRIVILEGE_ENABLED_BY_DEFAULT (0x00000001L)
  1695. #define SE_PRIVILEGE_ENABLED (0x00000002L)
  1696. #define SE_PRIVILEGE_REMOVED (0X00000004L)
  1697. #define SE_PRIVILEGE_USED_FOR_ACCESS (0x80000000L)
  1698. //
  1699. // Privilege Set Control flags
  1700. //
  1701. #define PRIVILEGE_SET_ALL_NECESSARY (1)
  1702. //
  1703. // Privilege Set - This is defined for a privilege set of one.
  1704. // If more than one privilege is needed, then this structure
  1705. // will need to be allocated with more space.
  1706. //
  1707. // Note: don't change this structure without fixing the INITIAL_PRIVILEGE_SET
  1708. // structure (defined in se.h)
  1709. //
  1710. typedef struct _PRIVILEGE_SET {
  1711. ULONG PrivilegeCount;
  1712. ULONG Control;
  1713. LUID_AND_ATTRIBUTES Privilege[ANYSIZE_ARRAY];
  1714. } PRIVILEGE_SET, * PPRIVILEGE_SET;
  1715. //
  1716. // These must be converted to LUIDs before use.
  1717. //
  1718. #define SE_MIN_WELL_KNOWN_PRIVILEGE (2L)
  1719. #define SE_CREATE_TOKEN_PRIVILEGE (2L)
  1720. #define SE_ASSIGNPRIMARYTOKEN_PRIVILEGE (3L)
  1721. #define SE_LOCK_MEMORY_PRIVILEGE (4L)
  1722. #define SE_INCREASE_QUOTA_PRIVILEGE (5L)
  1723. //
  1724. // Unsolicited Input is obsolete and unused.
  1725. //
  1726. #define SE_UNSOLICITED_INPUT_PRIVILEGE (6L)
  1727. #define SE_MACHINE_ACCOUNT_PRIVILEGE (6L)
  1728. #define SE_TCB_PRIVILEGE (7L)
  1729. #define SE_SECURITY_PRIVILEGE (8L)
  1730. #define SE_TAKE_OWNERSHIP_PRIVILEGE (9L)
  1731. #define SE_LOAD_DRIVER_PRIVILEGE (10L)
  1732. #define SE_SYSTEM_PROFILE_PRIVILEGE (11L)
  1733. #define SE_SYSTEMTIME_PRIVILEGE (12L)
  1734. #define SE_PROF_SINGLE_PROCESS_PRIVILEGE (13L)
  1735. #define SE_INC_BASE_PRIORITY_PRIVILEGE (14L)
  1736. #define SE_CREATE_PAGEFILE_PRIVILEGE (15L)
  1737. #define SE_CREATE_PERMANENT_PRIVILEGE (16L)
  1738. #define SE_BACKUP_PRIVILEGE (17L)
  1739. #define SE_RESTORE_PRIVILEGE (18L)
  1740. #define SE_SHUTDOWN_PRIVILEGE (19L)
  1741. #define SE_DEBUG_PRIVILEGE (20L)
  1742. #define SE_AUDIT_PRIVILEGE (21L)
  1743. #define SE_SYSTEM_ENVIRONMENT_PRIVILEGE (22L)
  1744. #define SE_CHANGE_NOTIFY_PRIVILEGE (23L)
  1745. #define SE_REMOTE_SHUTDOWN_PRIVILEGE (24L)
  1746. #define SE_UNDOCK_PRIVILEGE (25L)
  1747. #define SE_SYNC_AGENT_PRIVILEGE (26L)
  1748. #define SE_ENABLE_DELEGATION_PRIVILEGE (27L)
  1749. #define SE_MANAGE_VOLUME_PRIVILEGE (28L)
  1750. #define SE_IMPERSONATE_PRIVILEGE (29L)
  1751. #define SE_CREATE_GLOBAL_PRIVILEGE (30L)
  1752. #define SE_MAX_WELL_KNOWN_PRIVILEGE (SE_CREATE_GLOBAL_PRIVILEGE)
  1753. //
  1754. // Impersonation Level
  1755. //
  1756. // Impersonation level is represented by a pair of bits in Windows.
  1757. // If a new impersonation level is added or lowest value is changed from
  1758. // 0 to something else, fix the Windows CreateFile call.
  1759. //
  1760. typedef enum _SECURITY_IMPERSONATION_LEVEL {
  1761. SecurityAnonymous,
  1762. SecurityIdentification,
  1763. SecurityImpersonation,
  1764. SecurityDelegation
  1765. } SECURITY_IMPERSONATION_LEVEL, * PSECURITY_IMPERSONATION_LEVEL;
  1766. #define SECURITY_MAX_IMPERSONATION_LEVEL SecurityDelegation
  1767. #define SECURITY_MIN_IMPERSONATION_LEVEL SecurityAnonymous
  1768. #define DEFAULT_IMPERSONATION_LEVEL SecurityImpersonation
  1769. #define VALID_IMPERSONATION_LEVEL(L) (((L) >= SECURITY_MIN_IMPERSONATION_LEVEL) && ((L) <= SECURITY_MAX_IMPERSONATION_LEVEL))
  1770. //
  1771. // Security Tracking Mode
  1772. //
  1773. #define SECURITY_DYNAMIC_TRACKING (TRUE)
  1774. #define SECURITY_STATIC_TRACKING (FALSE)
  1775. typedef BOOLEAN SECURITY_CONTEXT_TRACKING_MODE,
  1776. * PSECURITY_CONTEXT_TRACKING_MODE;
  1777. //
  1778. // Quality Of Service
  1779. //
  1780. typedef struct _SECURITY_QUALITY_OF_SERVICE {
  1781. ULONG Length;
  1782. SECURITY_IMPERSONATION_LEVEL ImpersonationLevel;
  1783. SECURITY_CONTEXT_TRACKING_MODE ContextTrackingMode;
  1784. BOOLEAN EffectiveOnly;
  1785. } SECURITY_QUALITY_OF_SERVICE, * PSECURITY_QUALITY_OF_SERVICE;
  1786. //
  1787. // Used to represent information related to a thread impersonation
  1788. //
  1789. typedef struct _SE_IMPERSONATION_STATE {
  1790. PACCESS_TOKEN Token;
  1791. BOOLEAN CopyOnOpen;
  1792. BOOLEAN EffectiveOnly;
  1793. SECURITY_IMPERSONATION_LEVEL Level;
  1794. } SE_IMPERSONATION_STATE, *PSE_IMPERSONATION_STATE;
  1795. typedef ULONG SECURITY_INFORMATION, *PSECURITY_INFORMATION;
  1796. #define OWNER_SECURITY_INFORMATION (0x00000001L)
  1797. #define GROUP_SECURITY_INFORMATION (0x00000002L)
  1798. #define DACL_SECURITY_INFORMATION (0x00000004L)
  1799. #define SACL_SECURITY_INFORMATION (0x00000008L)
  1800. #define PROTECTED_DACL_SECURITY_INFORMATION (0x80000000L)
  1801. #define PROTECTED_SACL_SECURITY_INFORMATION (0x40000000L)
  1802. #define UNPROTECTED_DACL_SECURITY_INFORMATION (0x20000000L)
  1803. #define UNPROTECTED_SACL_SECURITY_INFORMATION (0x10000000L)
  1804. #define LOW_PRIORITY 0 // Lowest thread priority level
  1805. #define LOW_REALTIME_PRIORITY 16 // Lowest realtime priority level
  1806. #define HIGH_PRIORITY 31 // Highest thread priority level
  1807. #define MAXIMUM_PRIORITY 32 // Number of thread priority levels
  1808. #define MAXIMUM_WAIT_OBJECTS 64 // Maximum number of wait objects
  1809. #define MAXIMUM_SUSPEND_COUNT MAXCHAR // Maximum times thread can be suspended
  1810. //
  1811. // Define system time structure.
  1812. //
  1813. typedef struct _KSYSTEM_TIME {
  1814. ULONG LowPart;
  1815. LONG High1Time;
  1816. LONG High2Time;
  1817. } KSYSTEM_TIME, *PKSYSTEM_TIME;
  1818. //
  1819. // Thread priority
  1820. //
  1821. typedef LONG KPRIORITY;
  1822. //
  1823. // Spin Lock
  1824. //
  1825. typedef ULONG_PTR KSPIN_LOCK;
  1826. typedef KSPIN_LOCK *PKSPIN_LOCK;
  1827. //
  1828. // Define per processor lock queue structure.
  1829. //
  1830. // N.B. The lock field of the spin lock queue structure contains the address
  1831. // of the associated kernel spin lock, an owner bit, and a lock bit. Bit
  1832. // 0 of the spin lock address is the wait bit and bit 1 is the owner bit.
  1833. // The use of this field is such that the bits can be set and cleared
  1834. // noninterlocked, however, the back pointer must be preserved.
  1835. //
  1836. // The lock wait bit is set when a processor enqueues itself on the lock
  1837. // queue and it is not the only entry in the queue. The processor will
  1838. // spin on this bit waiting for the lock to be granted.
  1839. //
  1840. // The owner bit is set when the processor owns the respective lock.
  1841. //
  1842. // The next field of the spin lock queue structure is used to line the
  1843. // queued lock structures together in fifo order. It also can set set and
  1844. // cleared noninterlocked.
  1845. //
  1846. #define LOCK_QUEUE_WAIT 1
  1847. #define LOCK_QUEUE_OWNER 2
  1848. typedef enum _KSPIN_LOCK_QUEUE_NUMBER {
  1849. LockQueueDispatcherLock,
  1850. LockQueueUnusedSpare1,
  1851. LockQueuePfnLock,
  1852. LockQueueSystemSpaceLock,
  1853. LockQueueVacbLock,
  1854. LockQueueMasterLock,
  1855. LockQueueNonPagedPoolLock,
  1856. LockQueueIoCancelLock,
  1857. LockQueueWorkQueueLock,
  1858. LockQueueIoVpbLock,
  1859. LockQueueIoDatabaseLock,
  1860. LockQueueIoCompletionLock,
  1861. LockQueueNtfsStructLock,
  1862. LockQueueAfdWorkQueueLock,
  1863. LockQueueBcbLock,
  1864. LockQueueMmNonPagedPoolLock,
  1865. LockQueueMaximumLock
  1866. } KSPIN_LOCK_QUEUE_NUMBER, *PKSPIN_LOCK_QUEUE_NUMBER;
  1867. typedef struct _KSPIN_LOCK_QUEUE {
  1868. struct _KSPIN_LOCK_QUEUE * volatile Next;
  1869. PKSPIN_LOCK volatile Lock;
  1870. } KSPIN_LOCK_QUEUE, *PKSPIN_LOCK_QUEUE;
  1871. typedef struct _KLOCK_QUEUE_HANDLE {
  1872. KSPIN_LOCK_QUEUE LockQueue;
  1873. KIRQL OldIrql;
  1874. } KLOCK_QUEUE_HANDLE, *PKLOCK_QUEUE_HANDLE;
  1875. //
  1876. // Interrupt routine (first level dispatch)
  1877. //
  1878. typedef
  1879. VOID
  1880. (*PKINTERRUPT_ROUTINE) (
  1881. VOID
  1882. );
  1883. //
  1884. // Profile source types
  1885. //
  1886. typedef enum _KPROFILE_SOURCE {
  1887. ProfileTime,
  1888. ProfileAlignmentFixup,
  1889. ProfileTotalIssues,
  1890. ProfilePipelineDry,
  1891. ProfileLoadInstructions,
  1892. ProfilePipelineFrozen,
  1893. ProfileBranchInstructions,
  1894. ProfileTotalNonissues,
  1895. ProfileDcacheMisses,
  1896. ProfileIcacheMisses,
  1897. ProfileCacheMisses,
  1898. ProfileBranchMispredictions,
  1899. ProfileStoreInstructions,
  1900. ProfileFpInstructions,
  1901. ProfileIntegerInstructions,
  1902. Profile2Issue,
  1903. Profile3Issue,
  1904. Profile4Issue,
  1905. ProfileSpecialInstructions,
  1906. ProfileTotalCycles,
  1907. ProfileIcacheIssues,
  1908. ProfileDcacheAccesses,
  1909. ProfileMemoryBarrierCycles,
  1910. ProfileLoadLinkedIssues,
  1911. ProfileMaximum
  1912. } KPROFILE_SOURCE;
  1913. //
  1914. // for move macros
  1915. //
  1916. #ifdef _MAC
  1917. #ifndef _INC_STRING
  1918. #include <string.h>
  1919. #endif /* _INC_STRING */
  1920. #else
  1921. #include <string.h>
  1922. #endif // _MAC
  1923. #ifndef _SLIST_HEADER_
  1924. #define _SLIST_HEADER_
  1925. #if defined(_WIN64)
  1926. //
  1927. // The type SINGLE_LIST_ENTRY is not suitable for use with SLISTs. For
  1928. // WIN64, an entry on an SLIST is required to be 16-byte aligned, while a
  1929. // SINGLE_LIST_ENTRY structure has only 8 byte alignment.
  1930. //
  1931. // Therefore, all SLIST code should use the SLIST_ENTRY type instead of the
  1932. // SINGLE_LIST_ENTRY type.
  1933. //
  1934. #pragma warning(push)
  1935. #pragma warning(disable:4324) // structure padded due to align()
  1936. typedef struct DECLSPEC_ALIGN(16) _SLIST_ENTRY *PSLIST_ENTRY;
  1937. typedef struct DECLSPEC_ALIGN(16) _SLIST_ENTRY {
  1938. PSLIST_ENTRY Next;
  1939. } SLIST_ENTRY;
  1940. #pragma warning(pop)
  1941. #else
  1942. #define SLIST_ENTRY SINGLE_LIST_ENTRY
  1943. #define _SLIST_ENTRY _SINGLE_LIST_ENTRY
  1944. #define PSLIST_ENTRY PSINGLE_LIST_ENTRY
  1945. #endif
  1946. #if defined(_WIN64)
  1947. typedef struct DECLSPEC_ALIGN(16) _SLIST_HEADER {
  1948. ULONGLONG Alignment;
  1949. ULONGLONG Region;
  1950. } SLIST_HEADER;
  1951. typedef struct _SLIST_HEADER *PSLIST_HEADER;
  1952. #else
  1953. typedef union _SLIST_HEADER {
  1954. ULONGLONG Alignment;
  1955. struct {
  1956. SLIST_ENTRY Next;
  1957. USHORT Depth;
  1958. USHORT Sequence;
  1959. };
  1960. } SLIST_HEADER, *PSLIST_HEADER;
  1961. #endif
  1962. #endif
  1963. //
  1964. // If debugging support enabled, define an ASSERT macro that works. Otherwise
  1965. // define the ASSERT macro to expand to an empty expression.
  1966. //
  1967. // The ASSERT macro has been updated to be an expression instead of a statement.
  1968. //
  1969. NTSYSAPI
  1970. VOID
  1971. NTAPI
  1972. RtlAssert(
  1973. PVOID FailedAssertion,
  1974. PVOID FileName,
  1975. ULONG LineNumber,
  1976. PCHAR Message
  1977. );
  1978. #if DBG
  1979. #define ASSERT( exp ) \
  1980. ((!(exp)) ? \
  1981. (RtlAssert( #exp, __FILE__, __LINE__, NULL ),FALSE) : \
  1982. TRUE)
  1983. #define ASSERTMSG( msg, exp ) \
  1984. ((!(exp)) ? \
  1985. (RtlAssert( #exp, __FILE__, __LINE__, msg ),FALSE) : \
  1986. TRUE)
  1987. #define RTL_SOFT_ASSERT(_exp) \
  1988. ((!(_exp)) ? \
  1989. (DbgPrint("%s(%d): Soft assertion failed\n Expression: %s\n", __FILE__, __LINE__, #_exp),FALSE) : \
  1990. TRUE)
  1991. #define RTL_SOFT_ASSERTMSG(_msg, _exp) \
  1992. ((!(_exp)) ? \
  1993. (DbgPrint("%s(%d): Soft assertion failed\n Expression: %s\n Message: %s\n", __FILE__, __LINE__, #_exp, (_msg)),FALSE) : \
  1994. TRUE)
  1995. #define RTL_VERIFY ASSERT
  1996. #define RTL_VERIFYMSG ASSERTMSG
  1997. #define RTL_SOFT_VERIFY RTL_SOFT_ASSERT
  1998. #define RTL_SOFT_VERIFYMSG RTL_SOFT_ASSERTMSG
  1999. #else
  2000. #define ASSERT( exp ) ((void) 0)
  2001. #define ASSERTMSG( msg, exp ) ((void) 0)
  2002. #define RTL_SOFT_ASSERT(_exp) ((void) 0)
  2003. #define RTL_SOFT_ASSERTMSG(_msg, _exp) ((void) 0)
  2004. #define RTL_VERIFY( exp ) ((exp) ? TRUE : FALSE)
  2005. #define RTL_VERIFYMSG( msg, exp ) ((exp) ? TRUE : FALSE)
  2006. #define RTL_SOFT_VERIFY(_exp) ((_exp) ? TRUE : FALSE)
  2007. #define RTL_SOFT_VERIFYMSG(msg, _exp) ((_exp) ? TRUE : FALSE)
  2008. #endif // DBG
  2009. //
  2010. // Doubly-linked list manipulation routines.
  2011. //
  2012. //
  2013. // VOID
  2014. // InitializeListHead32(
  2015. // PLIST_ENTRY32 ListHead
  2016. // );
  2017. //
  2018. #define InitializeListHead32(ListHead) (\
  2019. (ListHead)->Flink = (ListHead)->Blink = PtrToUlong((ListHead)))
  2020. #if !defined(MIDL_PASS) && !defined(SORTPP_PASS)
  2021. VOID
  2022. FORCEINLINE
  2023. InitializeListHead(
  2024. IN PLIST_ENTRY ListHead
  2025. )
  2026. {
  2027. ListHead->Flink = ListHead->Blink = ListHead;
  2028. }
  2029. //
  2030. // BOOLEAN
  2031. // IsListEmpty(
  2032. // PLIST_ENTRY ListHead
  2033. // );
  2034. //
  2035. #define IsListEmpty(ListHead) \
  2036. ((ListHead)->Flink == (ListHead))
  2037. BOOLEAN
  2038. FORCEINLINE
  2039. RemoveEntryList(
  2040. IN PLIST_ENTRY Entry
  2041. )
  2042. {
  2043. PLIST_ENTRY Blink;
  2044. PLIST_ENTRY Flink;
  2045. Flink = Entry->Flink;
  2046. Blink = Entry->Blink;
  2047. Blink->Flink = Flink;
  2048. Flink->Blink = Blink;
  2049. return (BOOLEAN)(Flink == Blink);
  2050. }
  2051. PLIST_ENTRY
  2052. FORCEINLINE
  2053. RemoveHeadList(
  2054. IN PLIST_ENTRY ListHead
  2055. )
  2056. {
  2057. PLIST_ENTRY Flink;
  2058. PLIST_ENTRY Entry;
  2059. Entry = ListHead->Flink;
  2060. Flink = Entry->Flink;
  2061. ListHead->Flink = Flink;
  2062. Flink->Blink = ListHead;
  2063. return Entry;
  2064. }
  2065. PLIST_ENTRY
  2066. FORCEINLINE
  2067. RemoveTailList(
  2068. IN PLIST_ENTRY ListHead
  2069. )
  2070. {
  2071. PLIST_ENTRY Blink;
  2072. PLIST_ENTRY Entry;
  2073. Entry = ListHead->Blink;
  2074. Blink = Entry->Blink;
  2075. ListHead->Blink = Blink;
  2076. Blink->Flink = ListHead;
  2077. return Entry;
  2078. }
  2079. VOID
  2080. FORCEINLINE
  2081. InsertTailList(
  2082. IN PLIST_ENTRY ListHead,
  2083. IN PLIST_ENTRY Entry
  2084. )
  2085. {
  2086. PLIST_ENTRY Blink;
  2087. Blink = ListHead->Blink;
  2088. Entry->Flink = ListHead;
  2089. Entry->Blink = Blink;
  2090. Blink->Flink = Entry;
  2091. ListHead->Blink = Entry;
  2092. }
  2093. VOID
  2094. FORCEINLINE
  2095. InsertHeadList(
  2096. IN PLIST_ENTRY ListHead,
  2097. IN PLIST_ENTRY Entry
  2098. )
  2099. {
  2100. PLIST_ENTRY Flink;
  2101. Flink = ListHead->Flink;
  2102. Entry->Flink = Flink;
  2103. Entry->Blink = ListHead;
  2104. Flink->Blink = Entry;
  2105. ListHead->Flink = Entry;
  2106. }
  2107. //
  2108. //
  2109. // PSINGLE_LIST_ENTRY
  2110. // PopEntryList(
  2111. // PSINGLE_LIST_ENTRY ListHead
  2112. // );
  2113. //
  2114. #define PopEntryList(ListHead) \
  2115. (ListHead)->Next;\
  2116. {\
  2117. PSINGLE_LIST_ENTRY FirstEntry;\
  2118. FirstEntry = (ListHead)->Next;\
  2119. if (FirstEntry != NULL) { \
  2120. (ListHead)->Next = FirstEntry->Next;\
  2121. } \
  2122. }
  2123. //
  2124. // VOID
  2125. // PushEntryList(
  2126. // PSINGLE_LIST_ENTRY ListHead,
  2127. // PSINGLE_LIST_ENTRY Entry
  2128. // );
  2129. //
  2130. #define PushEntryList(ListHead,Entry) \
  2131. (Entry)->Next = (ListHead)->Next; \
  2132. (ListHead)->Next = (Entry)
  2133. #endif // !MIDL_PASS
  2134. #if defined (_MSC_VER) && ( _MSC_VER >= 900 )
  2135. PVOID
  2136. _ReturnAddress (
  2137. VOID
  2138. );
  2139. #pragma intrinsic(_ReturnAddress)
  2140. #endif
  2141. #if (defined(_M_AMD64) || defined(_M_IA64)) && !defined(_REALLY_GET_CALLERS_CALLER_)
  2142. #define RtlGetCallersAddress(CallersAddress, CallersCaller) \
  2143. *CallersAddress = (PVOID)_ReturnAddress(); \
  2144. *CallersCaller = NULL;
  2145. #else
  2146. NTSYSAPI
  2147. VOID
  2148. NTAPI
  2149. RtlGetCallersAddress(
  2150. OUT PVOID *CallersAddress,
  2151. OUT PVOID *CallersCaller
  2152. );
  2153. #endif
  2154. NTSYSAPI
  2155. ULONG
  2156. NTAPI
  2157. RtlWalkFrameChain (
  2158. OUT PVOID *Callers,
  2159. IN ULONG Count,
  2160. IN ULONG Flags
  2161. );
  2162. //
  2163. // Subroutines for dealing with the Registry
  2164. //
  2165. typedef NTSTATUS (NTAPI * PRTL_QUERY_REGISTRY_ROUTINE)(
  2166. IN PWSTR ValueName,
  2167. IN ULONG ValueType,
  2168. IN PVOID ValueData,
  2169. IN ULONG ValueLength,
  2170. IN PVOID Context,
  2171. IN PVOID EntryContext
  2172. );
  2173. typedef struct _RTL_QUERY_REGISTRY_TABLE {
  2174. PRTL_QUERY_REGISTRY_ROUTINE QueryRoutine;
  2175. ULONG Flags;
  2176. PWSTR Name;
  2177. PVOID EntryContext;
  2178. ULONG DefaultType;
  2179. PVOID DefaultData;
  2180. ULONG DefaultLength;
  2181. } RTL_QUERY_REGISTRY_TABLE, *PRTL_QUERY_REGISTRY_TABLE;
  2182. //
  2183. // The following flags specify how the Name field of a RTL_QUERY_REGISTRY_TABLE
  2184. // entry is interpreted. A NULL name indicates the end of the table.
  2185. //
  2186. #define RTL_QUERY_REGISTRY_SUBKEY 0x00000001 // Name is a subkey and remainder of
  2187. // table or until next subkey are value
  2188. // names for that subkey to look at.
  2189. #define RTL_QUERY_REGISTRY_TOPKEY 0x00000002 // Reset current key to original key for
  2190. // this and all following table entries.
  2191. #define RTL_QUERY_REGISTRY_REQUIRED 0x00000004 // Fail if no match found for this table
  2192. // entry.
  2193. #define RTL_QUERY_REGISTRY_NOVALUE 0x00000008 // Used to mark a table entry that has no
  2194. // value name, just wants a call out, not
  2195. // an enumeration of all values.
  2196. #define RTL_QUERY_REGISTRY_NOEXPAND 0x00000010 // Used to suppress the expansion of
  2197. // REG_MULTI_SZ into multiple callouts or
  2198. // to prevent the expansion of environment
  2199. // variable values in REG_EXPAND_SZ
  2200. #define RTL_QUERY_REGISTRY_DIRECT 0x00000020 // QueryRoutine field ignored. EntryContext
  2201. // field points to location to store value.
  2202. // For null terminated strings, EntryContext
  2203. // points to UNICODE_STRING structure that
  2204. // that describes maximum size of buffer.
  2205. // If .Buffer field is NULL then a buffer is
  2206. // allocated.
  2207. //
  2208. #define RTL_QUERY_REGISTRY_DELETE 0x00000040 // Used to delete value keys after they
  2209. // are queried.
  2210. NTSYSAPI
  2211. NTSTATUS
  2212. NTAPI
  2213. RtlQueryRegistryValues(
  2214. IN ULONG RelativeTo,
  2215. IN PCWSTR Path,
  2216. IN PRTL_QUERY_REGISTRY_TABLE QueryTable,
  2217. IN PVOID Context,
  2218. IN PVOID Environment OPTIONAL
  2219. );
  2220. NTSYSAPI
  2221. NTSTATUS
  2222. NTAPI
  2223. RtlWriteRegistryValue(
  2224. IN ULONG RelativeTo,
  2225. IN PCWSTR Path,
  2226. IN PCWSTR ValueName,
  2227. IN ULONG ValueType,
  2228. IN PVOID ValueData,
  2229. IN ULONG ValueLength
  2230. );
  2231. NTSYSAPI
  2232. NTSTATUS
  2233. NTAPI
  2234. RtlDeleteRegistryValue(
  2235. IN ULONG RelativeTo,
  2236. IN PCWSTR Path,
  2237. IN PCWSTR ValueName
  2238. );
  2239. NTSYSAPI
  2240. NTSTATUS
  2241. NTAPI
  2242. RtlCreateRegistryKey(
  2243. IN ULONG RelativeTo,
  2244. IN PWSTR Path
  2245. );
  2246. NTSYSAPI
  2247. NTSTATUS
  2248. NTAPI
  2249. RtlCheckRegistryKey(
  2250. IN ULONG RelativeTo,
  2251. IN PWSTR Path
  2252. );
  2253. //
  2254. // The following values for the RelativeTo parameter determine what the
  2255. // Path parameter to RtlQueryRegistryValues is relative to.
  2256. //
  2257. #define RTL_REGISTRY_ABSOLUTE 0 // Path is a full path
  2258. #define RTL_REGISTRY_SERVICES 1 // \Registry\Machine\System\CurrentControlSet\Services
  2259. #define RTL_REGISTRY_CONTROL 2 // \Registry\Machine\System\CurrentControlSet\Control
  2260. #define RTL_REGISTRY_WINDOWS_NT 3 // \Registry\Machine\Software\Microsoft\Windows NT\CurrentVersion
  2261. #define RTL_REGISTRY_DEVICEMAP 4 // \Registry\Machine\Hardware\DeviceMap
  2262. #define RTL_REGISTRY_USER 5 // \Registry\User\CurrentUser
  2263. #define RTL_REGISTRY_MAXIMUM 6
  2264. #define RTL_REGISTRY_HANDLE 0x40000000 // Low order bits are registry handle
  2265. #define RTL_REGISTRY_OPTIONAL 0x80000000 // Indicates the key node is optional
  2266. NTSYSAPI
  2267. NTSTATUS
  2268. NTAPI
  2269. RtlCharToInteger (
  2270. PCSZ String,
  2271. ULONG Base,
  2272. PULONG Value
  2273. );
  2274. NTSYSAPI
  2275. NTSTATUS
  2276. NTAPI
  2277. RtlIntegerToUnicodeString (
  2278. ULONG Value,
  2279. ULONG Base,
  2280. PUNICODE_STRING String
  2281. );
  2282. NTSYSAPI
  2283. NTSTATUS
  2284. NTAPI
  2285. RtlInt64ToUnicodeString (
  2286. IN ULONGLONG Value,
  2287. IN ULONG Base OPTIONAL,
  2288. IN OUT PUNICODE_STRING String
  2289. );
  2290. #ifdef _WIN64
  2291. #define RtlIntPtrToUnicodeString(Value, Base, String) RtlInt64ToUnicodeString(Value, Base, String)
  2292. #else
  2293. #define RtlIntPtrToUnicodeString(Value, Base, String) RtlIntegerToUnicodeString(Value, Base, String)
  2294. #endif
  2295. NTSYSAPI
  2296. NTSTATUS
  2297. NTAPI
  2298. RtlUnicodeStringToInteger (
  2299. PCUNICODE_STRING String,
  2300. ULONG Base,
  2301. PULONG Value
  2302. );
  2303. //
  2304. // String manipulation routines
  2305. //
  2306. #ifdef _NTSYSTEM_
  2307. #define NLS_MB_CODE_PAGE_TAG NlsMbCodePageTag
  2308. #define NLS_MB_OEM_CODE_PAGE_TAG NlsMbOemCodePageTag
  2309. #else
  2310. #define NLS_MB_CODE_PAGE_TAG (*NlsMbCodePageTag)
  2311. #define NLS_MB_OEM_CODE_PAGE_TAG (*NlsMbOemCodePageTag)
  2312. #endif // _NTSYSTEM_
  2313. extern BOOLEAN NLS_MB_CODE_PAGE_TAG; // TRUE -> Multibyte CP, FALSE -> Singlebyte
  2314. extern BOOLEAN NLS_MB_OEM_CODE_PAGE_TAG; // TRUE -> Multibyte CP, FALSE -> Singlebyte
  2315. NTSYSAPI
  2316. VOID
  2317. NTAPI
  2318. RtlInitString(
  2319. PSTRING DestinationString,
  2320. PCSZ SourceString
  2321. );
  2322. NTSYSAPI
  2323. VOID
  2324. NTAPI
  2325. RtlInitAnsiString(
  2326. PANSI_STRING DestinationString,
  2327. PCSZ SourceString
  2328. );
  2329. NTSYSAPI
  2330. VOID
  2331. NTAPI
  2332. RtlInitUnicodeString(
  2333. PUNICODE_STRING DestinationString,
  2334. PCWSTR SourceString
  2335. );
  2336. #define RtlInitEmptyUnicodeString(_ucStr,_buf,_bufSize) \
  2337. ((_ucStr)->Buffer = (_buf), \
  2338. (_ucStr)->Length = 0, \
  2339. (_ucStr)->MaximumLength = (USHORT)(_bufSize))
  2340. NTSYSAPI
  2341. VOID
  2342. NTAPI
  2343. RtlCopyString(
  2344. PSTRING DestinationString,
  2345. const STRING * SourceString
  2346. );
  2347. NTSYSAPI
  2348. CHAR
  2349. NTAPI
  2350. RtlUpperChar (
  2351. CHAR Character
  2352. );
  2353. NTSYSAPI
  2354. LONG
  2355. NTAPI
  2356. RtlCompareString(
  2357. const STRING * String1,
  2358. const STRING * String2,
  2359. BOOLEAN CaseInSensitive
  2360. );
  2361. NTSYSAPI
  2362. BOOLEAN
  2363. NTAPI
  2364. RtlEqualString(
  2365. const STRING * String1,
  2366. const STRING * String2,
  2367. BOOLEAN CaseInSensitive
  2368. );
  2369. NTSYSAPI
  2370. VOID
  2371. NTAPI
  2372. RtlUpperString(
  2373. PSTRING DestinationString,
  2374. const STRING * SourceString
  2375. );
  2376. //
  2377. // NLS String functions
  2378. //
  2379. NTSYSAPI
  2380. NTSTATUS
  2381. NTAPI
  2382. RtlAnsiStringToUnicodeString(
  2383. PUNICODE_STRING DestinationString,
  2384. PCANSI_STRING SourceString,
  2385. BOOLEAN AllocateDestinationString
  2386. );
  2387. NTSYSAPI
  2388. NTSTATUS
  2389. NTAPI
  2390. RtlUnicodeStringToAnsiString(
  2391. PANSI_STRING DestinationString,
  2392. PCUNICODE_STRING SourceString,
  2393. BOOLEAN AllocateDestinationString
  2394. );
  2395. NTSYSAPI
  2396. LONG
  2397. NTAPI
  2398. RtlCompareUnicodeString(
  2399. PCUNICODE_STRING String1,
  2400. PCUNICODE_STRING String2,
  2401. BOOLEAN CaseInSensitive
  2402. );
  2403. NTSYSAPI
  2404. BOOLEAN
  2405. NTAPI
  2406. RtlEqualUnicodeString(
  2407. PCUNICODE_STRING String1,
  2408. PCUNICODE_STRING String2,
  2409. BOOLEAN CaseInSensitive
  2410. );
  2411. #define HASH_STRING_ALGORITHM_DEFAULT (0)
  2412. #define HASH_STRING_ALGORITHM_X65599 (1)
  2413. #define HASH_STRING_ALGORITHM_INVALID (0xffffffff)
  2414. NTSYSAPI
  2415. NTSTATUS
  2416. NTAPI
  2417. RtlHashUnicodeString(
  2418. IN const UNICODE_STRING *String,
  2419. IN BOOLEAN CaseInSensitive,
  2420. IN ULONG HashAlgorithm,
  2421. OUT PULONG HashValue
  2422. );
  2423. NTSYSAPI
  2424. BOOLEAN
  2425. NTAPI
  2426. RtlPrefixUnicodeString(
  2427. IN PCUNICODE_STRING String1,
  2428. IN PCUNICODE_STRING String2,
  2429. IN BOOLEAN CaseInSensitive
  2430. );
  2431. NTSYSAPI
  2432. NTSTATUS
  2433. NTAPI
  2434. RtlUpcaseUnicodeString(
  2435. PUNICODE_STRING DestinationString,
  2436. PCUNICODE_STRING SourceString,
  2437. BOOLEAN AllocateDestinationString
  2438. );
  2439. NTSYSAPI
  2440. VOID
  2441. NTAPI
  2442. RtlCopyUnicodeString(
  2443. PUNICODE_STRING DestinationString,
  2444. PCUNICODE_STRING SourceString
  2445. );
  2446. NTSYSAPI
  2447. NTSTATUS
  2448. NTAPI
  2449. RtlAppendUnicodeStringToString (
  2450. PUNICODE_STRING Destination,
  2451. PCUNICODE_STRING Source
  2452. );
  2453. NTSYSAPI
  2454. NTSTATUS
  2455. NTAPI
  2456. RtlAppendUnicodeToString (
  2457. PUNICODE_STRING Destination,
  2458. PCWSTR Source
  2459. );
  2460. NTSYSAPI
  2461. WCHAR
  2462. NTAPI
  2463. RtlUpcaseUnicodeChar(
  2464. WCHAR SourceCharacter
  2465. );
  2466. NTSYSAPI
  2467. WCHAR
  2468. NTAPI
  2469. RtlDowncaseUnicodeChar(
  2470. WCHAR SourceCharacter
  2471. );
  2472. NTSYSAPI
  2473. VOID
  2474. NTAPI
  2475. RtlFreeUnicodeString(
  2476. PUNICODE_STRING UnicodeString
  2477. );
  2478. NTSYSAPI
  2479. VOID
  2480. NTAPI
  2481. RtlFreeAnsiString(
  2482. PANSI_STRING AnsiString
  2483. );
  2484. NTSYSAPI
  2485. ULONG
  2486. NTAPI
  2487. RtlxAnsiStringToUnicodeSize(
  2488. PCANSI_STRING AnsiString
  2489. );
  2490. //
  2491. // NTSYSAPI
  2492. // ULONG
  2493. // NTAPI
  2494. // RtlAnsiStringToUnicodeSize(
  2495. // PANSI_STRING AnsiString
  2496. // );
  2497. //
  2498. #define RtlAnsiStringToUnicodeSize(STRING) ( \
  2499. NLS_MB_CODE_PAGE_TAG ? \
  2500. RtlxAnsiStringToUnicodeSize(STRING) : \
  2501. ((STRING)->Length + sizeof(ANSI_NULL)) * sizeof(WCHAR) \
  2502. )
  2503. #include <guiddef.h>
  2504. #ifndef DEFINE_GUIDEX
  2505. #define DEFINE_GUIDEX(name) EXTERN_C const CDECL GUID name
  2506. #endif // !defined(DEFINE_GUIDEX)
  2507. #ifndef STATICGUIDOF
  2508. #define STATICGUIDOF(guid) STATIC_##guid
  2509. #endif // !defined(STATICGUIDOF)
  2510. #ifndef __IID_ALIGNED__
  2511. #define __IID_ALIGNED__
  2512. #ifdef __cplusplus
  2513. inline int IsEqualGUIDAligned(REFGUID guid1, REFGUID guid2)
  2514. {
  2515. return ((*(PLONGLONG)(&guid1) == *(PLONGLONG)(&guid2)) && (*((PLONGLONG)(&guid1) + 1) == *((PLONGLONG)(&guid2) + 1)));
  2516. }
  2517. #else // !__cplusplus
  2518. #define IsEqualGUIDAligned(guid1, guid2) \
  2519. ((*(PLONGLONG)(guid1) == *(PLONGLONG)(guid2)) && (*((PLONGLONG)(guid1) + 1) == *((PLONGLONG)(guid2) + 1)))
  2520. #endif // !__cplusplus
  2521. #endif // !__IID_ALIGNED__
  2522. NTSYSAPI
  2523. NTSTATUS
  2524. NTAPI
  2525. RtlStringFromGUID(
  2526. IN REFGUID Guid,
  2527. OUT PUNICODE_STRING GuidString
  2528. );
  2529. NTSYSAPI
  2530. NTSTATUS
  2531. NTAPI
  2532. RtlGUIDFromString(
  2533. IN PUNICODE_STRING GuidString,
  2534. OUT GUID* Guid
  2535. );
  2536. //
  2537. // Fast primitives to compare, move, and zero memory
  2538. //
  2539. NTSYSAPI
  2540. SIZE_T
  2541. NTAPI
  2542. RtlCompareMemory (
  2543. const VOID *Source1,
  2544. const VOID *Source2,
  2545. SIZE_T Length
  2546. );
  2547. #define RtlEqualMemory(Destination,Source,Length) (!memcmp((Destination),(Source),(Length)))
  2548. #if defined(_M_AMD64)
  2549. NTSYSAPI
  2550. VOID
  2551. NTAPI
  2552. RtlCopyMemory (
  2553. VOID UNALIGNED *Destination,
  2554. CONST VOID UNALIGNED *Source,
  2555. SIZE_T Length
  2556. );
  2557. NTSYSAPI
  2558. VOID
  2559. NTAPI
  2560. RtlMoveMemory (
  2561. VOID UNALIGNED *Destination,
  2562. CONST VOID UNALIGNED *Source,
  2563. SIZE_T Length
  2564. );
  2565. NTSYSAPI
  2566. VOID
  2567. NTAPI
  2568. RtlFillMemory (
  2569. VOID UNALIGNED *Destination,
  2570. SIZE_T Length,
  2571. IN UCHAR Fill
  2572. );
  2573. NTSYSAPI
  2574. VOID
  2575. NTAPI
  2576. RtlZeroMemory (
  2577. VOID UNALIGNED *Destination,
  2578. SIZE_T Length
  2579. );
  2580. #else
  2581. #define RtlMoveMemory(Destination,Source,Length) memmove((Destination),(Source),(Length))
  2582. #define RtlCopyMemory(Destination,Source,Length) memcpy((Destination),(Source),(Length))
  2583. #define RtlFillMemory(Destination,Length,Fill) memset((Destination),(Fill),(Length))
  2584. #define RtlZeroMemory(Destination,Length) memset((Destination),0,(Length))
  2585. #endif
  2586. #if !defined(MIDL_PASS)
  2587. FORCEINLINE
  2588. PVOID
  2589. RtlSecureZeroMemory(
  2590. IN PVOID ptr,
  2591. IN SIZE_T cnt
  2592. )
  2593. {
  2594. volatile char *vptr = (volatile char *)ptr;
  2595. while (cnt) {
  2596. *vptr = 0;
  2597. vptr++;
  2598. cnt--;
  2599. }
  2600. return ptr;
  2601. }
  2602. #endif
  2603. #define RtlCopyBytes RtlCopyMemory
  2604. #define RtlZeroBytes RtlZeroMemory
  2605. #define RtlFillBytes RtlFillMemory
  2606. #if defined(_M_AMD64)
  2607. NTSYSAPI
  2608. VOID
  2609. NTAPI
  2610. RtlCopyMemoryNonTemporal (
  2611. VOID UNALIGNED *Destination,
  2612. CONST VOID UNALIGNED *Source,
  2613. SIZE_T Length
  2614. );
  2615. #else
  2616. #define RtlCopyMemoryNonTemporal RtlCopyMemory
  2617. #endif
  2618. NTSYSAPI
  2619. VOID
  2620. FASTCALL
  2621. RtlPrefetchMemoryNonTemporal(
  2622. IN PVOID Source,
  2623. IN SIZE_T Length
  2624. );
  2625. //
  2626. // Define kernel debugger print prototypes and macros.
  2627. //
  2628. // N.B. The following function cannot be directly imported because there are
  2629. // a few places in the source tree where this function is redefined.
  2630. //
  2631. VOID
  2632. NTAPI
  2633. DbgBreakPoint(
  2634. VOID
  2635. );
  2636. NTSYSAPI
  2637. VOID
  2638. NTAPI
  2639. DbgBreakPointWithStatus(
  2640. IN ULONG Status
  2641. );
  2642. #define DBG_STATUS_CONTROL_C 1
  2643. #define DBG_STATUS_SYSRQ 2
  2644. #define DBG_STATUS_BUGCHECK_FIRST 3
  2645. #define DBG_STATUS_BUGCHECK_SECOND 4
  2646. #define DBG_STATUS_FATAL 5
  2647. #define DBG_STATUS_DEBUG_CONTROL 6
  2648. #define DBG_STATUS_WORKER 7
  2649. #if DBG
  2650. #define KdPrint(_x_) DbgPrint _x_
  2651. #define KdPrintEx(_x_) DbgPrintEx _x_
  2652. #define vKdPrintEx(_x_) vDbgPrintEx _x_
  2653. #define vKdPrintExWithPrefix(_x_) vDbgPrintExWithPrefix _x_
  2654. #define KdBreakPoint() DbgBreakPoint()
  2655. #define KdBreakPointWithStatus(s) DbgBreakPointWithStatus(s)
  2656. #else
  2657. #define KdPrint(_x_)
  2658. #define KdPrintEx(_x_)
  2659. #define vKdPrintEx(_x_)
  2660. #define vKdPrintExWithPrefix(_x_)
  2661. #define KdBreakPoint()
  2662. #define KdBreakPointWithStatus(s)
  2663. #endif
  2664. #ifndef _DBGNT_
  2665. ULONG
  2666. __cdecl
  2667. DbgPrint(
  2668. PCH Format,
  2669. ...
  2670. );
  2671. ULONG
  2672. __cdecl
  2673. DbgPrintEx(
  2674. IN ULONG ComponentId,
  2675. IN ULONG Level,
  2676. IN PCH Format,
  2677. ...
  2678. );
  2679. #ifdef _VA_LIST_DEFINED
  2680. ULONG
  2681. vDbgPrintEx(
  2682. IN ULONG ComponentId,
  2683. IN ULONG Level,
  2684. IN PCH Format,
  2685. va_list arglist
  2686. );
  2687. ULONG
  2688. vDbgPrintExWithPrefix(
  2689. IN PCH Prefix,
  2690. IN ULONG ComponentId,
  2691. IN ULONG Level,
  2692. IN PCH Format,
  2693. va_list arglist
  2694. );
  2695. #endif
  2696. ULONG
  2697. __cdecl
  2698. DbgPrintReturnControlC(
  2699. PCH Format,
  2700. ...
  2701. );
  2702. NTSYSAPI
  2703. NTSTATUS
  2704. DbgQueryDebugFilterState(
  2705. IN ULONG ComponentId,
  2706. IN ULONG Level
  2707. );
  2708. NTSYSAPI
  2709. NTSTATUS
  2710. DbgSetDebugFilterState(
  2711. IN ULONG ComponentId,
  2712. IN ULONG Level,
  2713. IN BOOLEAN State
  2714. );
  2715. #endif // _DBGNT_
  2716. //
  2717. // Large integer arithmetic routines.
  2718. //
  2719. //
  2720. // Large integer add - 64-bits + 64-bits -> 64-bits
  2721. //
  2722. #if !defined(MIDL_PASS)
  2723. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  2724. __inline
  2725. LARGE_INTEGER
  2726. NTAPI
  2727. RtlLargeIntegerAdd (
  2728. LARGE_INTEGER Addend1,
  2729. LARGE_INTEGER Addend2
  2730. )
  2731. {
  2732. LARGE_INTEGER Sum;
  2733. Sum.QuadPart = Addend1.QuadPart + Addend2.QuadPart;
  2734. return Sum;
  2735. }
  2736. //
  2737. // Enlarged integer multiply - 32-bits * 32-bits -> 64-bits
  2738. //
  2739. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  2740. __inline
  2741. LARGE_INTEGER
  2742. NTAPI
  2743. RtlEnlargedIntegerMultiply (
  2744. LONG Multiplicand,
  2745. LONG Multiplier
  2746. )
  2747. {
  2748. LARGE_INTEGER Product;
  2749. Product.QuadPart = (LONGLONG)Multiplicand * (ULONGLONG)Multiplier;
  2750. return Product;
  2751. }
  2752. //
  2753. // Unsigned enlarged integer multiply - 32-bits * 32-bits -> 64-bits
  2754. //
  2755. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  2756. __inline
  2757. LARGE_INTEGER
  2758. NTAPI
  2759. RtlEnlargedUnsignedMultiply (
  2760. ULONG Multiplicand,
  2761. ULONG Multiplier
  2762. )
  2763. {
  2764. LARGE_INTEGER Product;
  2765. Product.QuadPart = (ULONGLONG)Multiplicand * (ULONGLONG)Multiplier;
  2766. return Product;
  2767. }
  2768. //
  2769. // Enlarged integer divide - 64-bits / 32-bits > 32-bits
  2770. //
  2771. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  2772. __inline
  2773. ULONG
  2774. NTAPI
  2775. RtlEnlargedUnsignedDivide (
  2776. IN ULARGE_INTEGER Dividend,
  2777. IN ULONG Divisor,
  2778. IN PULONG Remainder OPTIONAL
  2779. )
  2780. {
  2781. ULONG Quotient;
  2782. Quotient = (ULONG)(Dividend.QuadPart / Divisor);
  2783. if (ARGUMENT_PRESENT(Remainder)) {
  2784. *Remainder = (ULONG)(Dividend.QuadPart % Divisor);
  2785. }
  2786. return Quotient;
  2787. }
  2788. //
  2789. // Large integer negation - -(64-bits)
  2790. //
  2791. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  2792. __inline
  2793. LARGE_INTEGER
  2794. NTAPI
  2795. RtlLargeIntegerNegate (
  2796. LARGE_INTEGER Subtrahend
  2797. )
  2798. {
  2799. LARGE_INTEGER Difference;
  2800. Difference.QuadPart = -Subtrahend.QuadPart;
  2801. return Difference;
  2802. }
  2803. //
  2804. // Large integer subtract - 64-bits - 64-bits -> 64-bits.
  2805. //
  2806. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  2807. __inline
  2808. LARGE_INTEGER
  2809. NTAPI
  2810. RtlLargeIntegerSubtract (
  2811. LARGE_INTEGER Minuend,
  2812. LARGE_INTEGER Subtrahend
  2813. )
  2814. {
  2815. LARGE_INTEGER Difference;
  2816. Difference.QuadPart = Minuend.QuadPart - Subtrahend.QuadPart;
  2817. return Difference;
  2818. }
  2819. //
  2820. // Extended large integer magic divide - 64-bits / 32-bits -> 64-bits
  2821. //
  2822. #if defined(_AMD64_)
  2823. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  2824. __inline
  2825. LARGE_INTEGER
  2826. NTAPI
  2827. RtlExtendedMagicDivide (
  2828. LARGE_INTEGER Dividend,
  2829. LARGE_INTEGER MagicDivisor,
  2830. CCHAR ShiftCount
  2831. )
  2832. {
  2833. LARGE_INTEGER Quotient;
  2834. if (Dividend.QuadPart >= 0) {
  2835. Quotient.QuadPart = UnsignedMultiplyHigh(Dividend.QuadPart,
  2836. (ULONG64)MagicDivisor.QuadPart);
  2837. } else {
  2838. Quotient.QuadPart = UnsignedMultiplyHigh(-Dividend.QuadPart,
  2839. (ULONG64)MagicDivisor.QuadPart);
  2840. }
  2841. Quotient.QuadPart = (ULONG64)Quotient.QuadPart >> ShiftCount;
  2842. if (Dividend.QuadPart < 0) {
  2843. Quotient.QuadPart = - Quotient.QuadPart;
  2844. }
  2845. return Quotient;
  2846. }
  2847. #endif // defined(_AMD64_)
  2848. #if defined(_X86_) || defined(_IA64_)
  2849. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  2850. NTSYSAPI
  2851. LARGE_INTEGER
  2852. NTAPI
  2853. RtlExtendedMagicDivide (
  2854. LARGE_INTEGER Dividend,
  2855. LARGE_INTEGER MagicDivisor,
  2856. CCHAR ShiftCount
  2857. );
  2858. #endif // defined(_X86_) || defined(_IA64_)
  2859. #if defined(_AMD64_) || defined(_IA64_)
  2860. //
  2861. // Large Integer divide - 64-bits / 32-bits -> 64-bits
  2862. //
  2863. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  2864. __inline
  2865. LARGE_INTEGER
  2866. NTAPI
  2867. RtlExtendedLargeIntegerDivide (
  2868. LARGE_INTEGER Dividend,
  2869. ULONG Divisor,
  2870. PULONG Remainder OPTIONAL
  2871. )
  2872. {
  2873. LARGE_INTEGER Quotient;
  2874. Quotient.QuadPart = (ULONG64)Dividend.QuadPart / Divisor;
  2875. if (ARGUMENT_PRESENT(Remainder)) {
  2876. *Remainder = (ULONG)(Dividend.QuadPart % Divisor);
  2877. }
  2878. return Quotient;
  2879. }
  2880. //
  2881. // Large Integer divide - 64-bits / 64-bits -> 64-bits
  2882. //
  2883. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  2884. __inline
  2885. LARGE_INTEGER
  2886. NTAPI
  2887. RtlLargeIntegerDivide (
  2888. LARGE_INTEGER Dividend,
  2889. LARGE_INTEGER Divisor,
  2890. PLARGE_INTEGER Remainder OPTIONAL
  2891. )
  2892. {
  2893. LARGE_INTEGER Quotient;
  2894. Quotient.QuadPart = Dividend.QuadPart / Divisor.QuadPart;
  2895. if (ARGUMENT_PRESENT(Remainder)) {
  2896. Remainder->QuadPart = Dividend.QuadPart % Divisor.QuadPart;
  2897. }
  2898. return Quotient;
  2899. }
  2900. //
  2901. // Extended integer multiply - 32-bits * 64-bits -> 64-bits
  2902. //
  2903. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  2904. __inline
  2905. LARGE_INTEGER
  2906. NTAPI
  2907. RtlExtendedIntegerMultiply (
  2908. LARGE_INTEGER Multiplicand,
  2909. LONG Multiplier
  2910. )
  2911. {
  2912. LARGE_INTEGER Product;
  2913. Product.QuadPart = Multiplicand.QuadPart * Multiplier;
  2914. return Product;
  2915. }
  2916. #else
  2917. //
  2918. // Large Integer divide - 64-bits / 32-bits -> 64-bits
  2919. //
  2920. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  2921. NTSYSAPI
  2922. LARGE_INTEGER
  2923. NTAPI
  2924. RtlExtendedLargeIntegerDivide (
  2925. LARGE_INTEGER Dividend,
  2926. ULONG Divisor,
  2927. PULONG Remainder
  2928. );
  2929. //
  2930. // Large Integer divide - 64-bits / 64-bits -> 64-bits
  2931. //
  2932. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  2933. NTSYSAPI
  2934. LARGE_INTEGER
  2935. NTAPI
  2936. RtlLargeIntegerDivide (
  2937. LARGE_INTEGER Dividend,
  2938. LARGE_INTEGER Divisor,
  2939. PLARGE_INTEGER Remainder
  2940. );
  2941. //
  2942. // Extended integer multiply - 32-bits * 64-bits -> 64-bits
  2943. //
  2944. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  2945. NTSYSAPI
  2946. LARGE_INTEGER
  2947. NTAPI
  2948. RtlExtendedIntegerMultiply (
  2949. LARGE_INTEGER Multiplicand,
  2950. LONG Multiplier
  2951. );
  2952. #endif // defined(_AMD64_) || defined(_IA64_)
  2953. //
  2954. // Large integer and - 64-bite & 64-bits -> 64-bits.
  2955. //
  2956. #if PRAGMA_DEPRECATED_DDK
  2957. #pragma deprecated(RtlLargeIntegerAnd) // Use native __int64 math
  2958. #endif
  2959. #define RtlLargeIntegerAnd(Result, Source, Mask) \
  2960. Result.QuadPart = Source.QuadPart & Mask.QuadPart
  2961. //
  2962. // Convert signed integer to large integer.
  2963. //
  2964. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  2965. __inline
  2966. LARGE_INTEGER
  2967. NTAPI
  2968. RtlConvertLongToLargeInteger (
  2969. LONG SignedInteger
  2970. )
  2971. {
  2972. LARGE_INTEGER Result;
  2973. Result.QuadPart = SignedInteger;
  2974. return Result;
  2975. }
  2976. //
  2977. // Convert unsigned integer to large integer.
  2978. //
  2979. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  2980. __inline
  2981. LARGE_INTEGER
  2982. NTAPI
  2983. RtlConvertUlongToLargeInteger (
  2984. ULONG UnsignedInteger
  2985. )
  2986. {
  2987. LARGE_INTEGER Result;
  2988. Result.QuadPart = UnsignedInteger;
  2989. return Result;
  2990. }
  2991. //
  2992. // Large integer shift routines.
  2993. //
  2994. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  2995. __inline
  2996. LARGE_INTEGER
  2997. NTAPI
  2998. RtlLargeIntegerShiftLeft (
  2999. LARGE_INTEGER LargeInteger,
  3000. CCHAR ShiftCount
  3001. )
  3002. {
  3003. LARGE_INTEGER Result;
  3004. Result.QuadPart = LargeInteger.QuadPart << ShiftCount;
  3005. return Result;
  3006. }
  3007. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  3008. __inline
  3009. LARGE_INTEGER
  3010. NTAPI
  3011. RtlLargeIntegerShiftRight (
  3012. LARGE_INTEGER LargeInteger,
  3013. CCHAR ShiftCount
  3014. )
  3015. {
  3016. LARGE_INTEGER Result;
  3017. Result.QuadPart = (ULONG64)LargeInteger.QuadPart >> ShiftCount;
  3018. return Result;
  3019. }
  3020. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  3021. __inline
  3022. LARGE_INTEGER
  3023. NTAPI
  3024. RtlLargeIntegerArithmeticShift (
  3025. LARGE_INTEGER LargeInteger,
  3026. CCHAR ShiftCount
  3027. )
  3028. {
  3029. LARGE_INTEGER Result;
  3030. Result.QuadPart = LargeInteger.QuadPart >> ShiftCount;
  3031. return Result;
  3032. }
  3033. //
  3034. // Large integer comparison routines.
  3035. //
  3036. #if PRAGMA_DEPRECATED_DDK
  3037. #pragma deprecated(RtlLargeIntegerGreaterThan) // Use native __int64 math
  3038. #pragma deprecated(RtlLargeIntegerGreaterThanOrEqualTo) // Use native __int64 math
  3039. #pragma deprecated(RtlLargeIntegerEqualTo) // Use native __int64 math
  3040. #pragma deprecated(RtlLargeIntegerNotEqualTo) // Use native __int64 math
  3041. #pragma deprecated(RtlLargeIntegerLessThan) // Use native __int64 math
  3042. #pragma deprecated(RtlLargeIntegerLessThanOrEqualTo) // Use native __int64 math
  3043. #pragma deprecated(RtlLargeIntegerGreaterThanZero) // Use native __int64 math
  3044. #pragma deprecated(RtlLargeIntegerGreaterOrEqualToZero) // Use native __int64 math
  3045. #pragma deprecated(RtlLargeIntegerEqualToZero) // Use native __int64 math
  3046. #pragma deprecated(RtlLargeIntegerNotEqualToZero) // Use native __int64 math
  3047. #pragma deprecated(RtlLargeIntegerLessThanZero) // Use native __int64 math
  3048. #pragma deprecated(RtlLargeIntegerLessOrEqualToZero) // Use native __int64 math
  3049. #endif
  3050. #define RtlLargeIntegerGreaterThan(X,Y) ( \
  3051. (((X).HighPart == (Y).HighPart) && ((X).LowPart > (Y).LowPart)) || \
  3052. ((X).HighPart > (Y).HighPart) \
  3053. )
  3054. #define RtlLargeIntegerGreaterThanOrEqualTo(X,Y) ( \
  3055. (((X).HighPart == (Y).HighPart) && ((X).LowPart >= (Y).LowPart)) || \
  3056. ((X).HighPart > (Y).HighPart) \
  3057. )
  3058. #define RtlLargeIntegerEqualTo(X,Y) ( \
  3059. !(((X).LowPart ^ (Y).LowPart) | ((X).HighPart ^ (Y).HighPart)) \
  3060. )
  3061. #define RtlLargeIntegerNotEqualTo(X,Y) ( \
  3062. (((X).LowPart ^ (Y).LowPart) | ((X).HighPart ^ (Y).HighPart)) \
  3063. )
  3064. #define RtlLargeIntegerLessThan(X,Y) ( \
  3065. (((X).HighPart == (Y).HighPart) && ((X).LowPart < (Y).LowPart)) || \
  3066. ((X).HighPart < (Y).HighPart) \
  3067. )
  3068. #define RtlLargeIntegerLessThanOrEqualTo(X,Y) ( \
  3069. (((X).HighPart == (Y).HighPart) && ((X).LowPart <= (Y).LowPart)) || \
  3070. ((X).HighPart < (Y).HighPart) \
  3071. )
  3072. #define RtlLargeIntegerGreaterThanZero(X) ( \
  3073. (((X).HighPart == 0) && ((X).LowPart > 0)) || \
  3074. ((X).HighPart > 0 ) \
  3075. )
  3076. #define RtlLargeIntegerGreaterOrEqualToZero(X) ( \
  3077. (X).HighPart >= 0 \
  3078. )
  3079. #define RtlLargeIntegerEqualToZero(X) ( \
  3080. !((X).LowPart | (X).HighPart) \
  3081. )
  3082. #define RtlLargeIntegerNotEqualToZero(X) ( \
  3083. ((X).LowPart | (X).HighPart) \
  3084. )
  3085. #define RtlLargeIntegerLessThanZero(X) ( \
  3086. ((X).HighPart < 0) \
  3087. )
  3088. #define RtlLargeIntegerLessOrEqualToZero(X) ( \
  3089. ((X).HighPart < 0) || !((X).LowPart | (X).HighPart) \
  3090. )
  3091. #endif // !defined(MIDL_PASS)
  3092. //
  3093. // Time conversion routines
  3094. //
  3095. typedef struct _TIME_FIELDS {
  3096. CSHORT Year; // range [1601...]
  3097. CSHORT Month; // range [1..12]
  3098. CSHORT Day; // range [1..31]
  3099. CSHORT Hour; // range [0..23]
  3100. CSHORT Minute; // range [0..59]
  3101. CSHORT Second; // range [0..59]
  3102. CSHORT Milliseconds;// range [0..999]
  3103. CSHORT Weekday; // range [0..6] == [Sunday..Saturday]
  3104. } TIME_FIELDS;
  3105. typedef TIME_FIELDS *PTIME_FIELDS;
  3106. NTSYSAPI
  3107. VOID
  3108. NTAPI
  3109. RtlTimeToTimeFields (
  3110. PLARGE_INTEGER Time,
  3111. PTIME_FIELDS TimeFields
  3112. );
  3113. //
  3114. // A time field record (Weekday ignored) -> 64 bit Time value
  3115. //
  3116. NTSYSAPI
  3117. BOOLEAN
  3118. NTAPI
  3119. RtlTimeFieldsToTime (
  3120. PTIME_FIELDS TimeFields,
  3121. PLARGE_INTEGER Time
  3122. );
  3123. //
  3124. // The following macros store and retrieve USHORTS and ULONGS from potentially
  3125. // unaligned addresses, avoiding alignment faults. they should probably be
  3126. // rewritten in assembler
  3127. //
  3128. #define SHORT_SIZE (sizeof(USHORT))
  3129. #define SHORT_MASK (SHORT_SIZE - 1)
  3130. #define LONG_SIZE (sizeof(LONG))
  3131. #define LONGLONG_SIZE (sizeof(LONGLONG))
  3132. #define LONG_MASK (LONG_SIZE - 1)
  3133. #define LONGLONG_MASK (LONGLONG_SIZE - 1)
  3134. #define LOWBYTE_MASK 0x00FF
  3135. #define FIRSTBYTE(VALUE) ((VALUE) & LOWBYTE_MASK)
  3136. #define SECONDBYTE(VALUE) (((VALUE) >> 8) & LOWBYTE_MASK)
  3137. #define THIRDBYTE(VALUE) (((VALUE) >> 16) & LOWBYTE_MASK)
  3138. #define FOURTHBYTE(VALUE) (((VALUE) >> 24) & LOWBYTE_MASK)
  3139. //
  3140. // if MIPS Big Endian, order of bytes is reversed.
  3141. //
  3142. #define SHORT_LEAST_SIGNIFICANT_BIT 0
  3143. #define SHORT_MOST_SIGNIFICANT_BIT 1
  3144. #define LONG_LEAST_SIGNIFICANT_BIT 0
  3145. #define LONG_3RD_MOST_SIGNIFICANT_BIT 1
  3146. #define LONG_2ND_MOST_SIGNIFICANT_BIT 2
  3147. #define LONG_MOST_SIGNIFICANT_BIT 3
  3148. //++
  3149. //
  3150. // VOID
  3151. // RtlStoreUshort (
  3152. // PUSHORT ADDRESS
  3153. // USHORT VALUE
  3154. // )
  3155. //
  3156. // Routine Description:
  3157. //
  3158. // This macro stores a USHORT value in at a particular address, avoiding
  3159. // alignment faults.
  3160. //
  3161. // Arguments:
  3162. //
  3163. // ADDRESS - where to store USHORT value
  3164. // VALUE - USHORT to store
  3165. //
  3166. // Return Value:
  3167. //
  3168. // none.
  3169. //
  3170. //--
  3171. #define RtlStoreUshort(ADDRESS,VALUE) \
  3172. if ((ULONG_PTR)(ADDRESS) & SHORT_MASK) { \
  3173. ((PUCHAR) (ADDRESS))[SHORT_LEAST_SIGNIFICANT_BIT] = (UCHAR)(FIRSTBYTE(VALUE)); \
  3174. ((PUCHAR) (ADDRESS))[SHORT_MOST_SIGNIFICANT_BIT ] = (UCHAR)(SECONDBYTE(VALUE)); \
  3175. } \
  3176. else { \
  3177. *((PUSHORT) (ADDRESS)) = (USHORT) VALUE; \
  3178. }
  3179. //++
  3180. //
  3181. // VOID
  3182. // RtlStoreUlong (
  3183. // PULONG ADDRESS
  3184. // ULONG VALUE
  3185. // )
  3186. //
  3187. // Routine Description:
  3188. //
  3189. // This macro stores a ULONG value in at a particular address, avoiding
  3190. // alignment faults.
  3191. //
  3192. // Arguments:
  3193. //
  3194. // ADDRESS - where to store ULONG value
  3195. // VALUE - ULONG to store
  3196. //
  3197. // Return Value:
  3198. //
  3199. // none.
  3200. //
  3201. // Note:
  3202. // Depending on the machine, we might want to call storeushort in the
  3203. // unaligned case.
  3204. //
  3205. //--
  3206. #define RtlStoreUlong(ADDRESS,VALUE) \
  3207. if ((ULONG_PTR)(ADDRESS) & LONG_MASK) { \
  3208. ((PUCHAR) (ADDRESS))[LONG_LEAST_SIGNIFICANT_BIT ] = (UCHAR)(FIRSTBYTE(VALUE)); \
  3209. ((PUCHAR) (ADDRESS))[LONG_3RD_MOST_SIGNIFICANT_BIT ] = (UCHAR)(SECONDBYTE(VALUE)); \
  3210. ((PUCHAR) (ADDRESS))[LONG_2ND_MOST_SIGNIFICANT_BIT ] = (UCHAR)(THIRDBYTE(VALUE)); \
  3211. ((PUCHAR) (ADDRESS))[LONG_MOST_SIGNIFICANT_BIT ] = (UCHAR)(FOURTHBYTE(VALUE)); \
  3212. } \
  3213. else { \
  3214. *((PULONG) (ADDRESS)) = (ULONG) (VALUE); \
  3215. }
  3216. //++
  3217. //
  3218. // VOID
  3219. // RtlStoreUlonglong (
  3220. // PULONGLONG ADDRESS
  3221. // ULONG VALUE
  3222. // )
  3223. //
  3224. // Routine Description:
  3225. //
  3226. // This macro stores a ULONGLONG value in at a particular address, avoiding
  3227. // alignment faults.
  3228. //
  3229. // Arguments:
  3230. //
  3231. // ADDRESS - where to store ULONGLONG value
  3232. // VALUE - ULONGLONG to store
  3233. //
  3234. // Return Value:
  3235. //
  3236. // none.
  3237. //
  3238. //--
  3239. #define RtlStoreUlonglong(ADDRESS,VALUE) \
  3240. if ((ULONG_PTR)(ADDRESS) & LONGLONG_MASK) { \
  3241. RtlStoreUlong((ULONG_PTR)(ADDRESS), \
  3242. (ULONGLONG)(VALUE) & 0xFFFFFFFF); \
  3243. RtlStoreUlong((ULONG_PTR)(ADDRESS)+sizeof(ULONG), \
  3244. (ULONGLONG)(VALUE) >> 32); \
  3245. } else { \
  3246. *((PULONGLONG)(ADDRESS)) = (ULONGLONG)(VALUE); \
  3247. }
  3248. //++
  3249. //
  3250. // VOID
  3251. // RtlStoreUlongPtr (
  3252. // PULONG_PTR ADDRESS
  3253. // ULONG_PTR VALUE
  3254. // )
  3255. //
  3256. // Routine Description:
  3257. //
  3258. // This macro stores a ULONG_PTR value in at a particular address, avoiding
  3259. // alignment faults.
  3260. //
  3261. // Arguments:
  3262. //
  3263. // ADDRESS - where to store ULONG_PTR value
  3264. // VALUE - ULONG_PTR to store
  3265. //
  3266. // Return Value:
  3267. //
  3268. // none.
  3269. //
  3270. //--
  3271. #ifdef _WIN64
  3272. #define RtlStoreUlongPtr(ADDRESS,VALUE) \
  3273. RtlStoreUlonglong(ADDRESS,VALUE)
  3274. #else
  3275. #define RtlStoreUlongPtr(ADDRESS,VALUE) \
  3276. RtlStoreUlong(ADDRESS,VALUE)
  3277. #endif
  3278. //++
  3279. //
  3280. // VOID
  3281. // RtlRetrieveUshort (
  3282. // PUSHORT DESTINATION_ADDRESS
  3283. // PUSHORT SOURCE_ADDRESS
  3284. // )
  3285. //
  3286. // Routine Description:
  3287. //
  3288. // This macro retrieves a USHORT value from the SOURCE address, avoiding
  3289. // alignment faults. The DESTINATION address is assumed to be aligned.
  3290. //
  3291. // Arguments:
  3292. //
  3293. // DESTINATION_ADDRESS - where to store USHORT value
  3294. // SOURCE_ADDRESS - where to retrieve USHORT value from
  3295. //
  3296. // Return Value:
  3297. //
  3298. // none.
  3299. //
  3300. //--
  3301. #define RtlRetrieveUshort(DEST_ADDRESS,SRC_ADDRESS) \
  3302. if ((ULONG_PTR)SRC_ADDRESS & SHORT_MASK) { \
  3303. ((PUCHAR) DEST_ADDRESS)[0] = ((PUCHAR) SRC_ADDRESS)[0]; \
  3304. ((PUCHAR) DEST_ADDRESS)[1] = ((PUCHAR) SRC_ADDRESS)[1]; \
  3305. } \
  3306. else { \
  3307. *((PUSHORT) DEST_ADDRESS) = *((PUSHORT) SRC_ADDRESS); \
  3308. } \
  3309. //++
  3310. //
  3311. // VOID
  3312. // RtlRetrieveUlong (
  3313. // PULONG DESTINATION_ADDRESS
  3314. // PULONG SOURCE_ADDRESS
  3315. // )
  3316. //
  3317. // Routine Description:
  3318. //
  3319. // This macro retrieves a ULONG value from the SOURCE address, avoiding
  3320. // alignment faults. The DESTINATION address is assumed to be aligned.
  3321. //
  3322. // Arguments:
  3323. //
  3324. // DESTINATION_ADDRESS - where to store ULONG value
  3325. // SOURCE_ADDRESS - where to retrieve ULONG value from
  3326. //
  3327. // Return Value:
  3328. //
  3329. // none.
  3330. //
  3331. // Note:
  3332. // Depending on the machine, we might want to call retrieveushort in the
  3333. // unaligned case.
  3334. //
  3335. //--
  3336. #define RtlRetrieveUlong(DEST_ADDRESS,SRC_ADDRESS) \
  3337. if ((ULONG_PTR)SRC_ADDRESS & LONG_MASK) { \
  3338. ((PUCHAR) DEST_ADDRESS)[0] = ((PUCHAR) SRC_ADDRESS)[0]; \
  3339. ((PUCHAR) DEST_ADDRESS)[1] = ((PUCHAR) SRC_ADDRESS)[1]; \
  3340. ((PUCHAR) DEST_ADDRESS)[2] = ((PUCHAR) SRC_ADDRESS)[2]; \
  3341. ((PUCHAR) DEST_ADDRESS)[3] = ((PUCHAR) SRC_ADDRESS)[3]; \
  3342. } \
  3343. else { \
  3344. *((PULONG) DEST_ADDRESS) = *((PULONG) SRC_ADDRESS); \
  3345. }
  3346. //
  3347. // BitMap routines. The following structure, routines, and macros are
  3348. // for manipulating bitmaps. The user is responsible for allocating a bitmap
  3349. // structure (which is really a header) and a buffer (which must be longword
  3350. // aligned and multiple longwords in size).
  3351. //
  3352. typedef struct _RTL_BITMAP {
  3353. ULONG SizeOfBitMap; // Number of bits in bit map
  3354. PULONG Buffer; // Pointer to the bit map itself
  3355. } RTL_BITMAP;
  3356. typedef RTL_BITMAP *PRTL_BITMAP;
  3357. //
  3358. // The following routine initializes a new bitmap. It does not alter the
  3359. // data currently in the bitmap. This routine must be called before
  3360. // any other bitmap routine/macro.
  3361. //
  3362. NTSYSAPI
  3363. VOID
  3364. NTAPI
  3365. RtlInitializeBitMap (
  3366. PRTL_BITMAP BitMapHeader,
  3367. PULONG BitMapBuffer,
  3368. ULONG SizeOfBitMap
  3369. );
  3370. //
  3371. // The following three routines clear, set, and test the state of a
  3372. // single bit in a bitmap.
  3373. //
  3374. NTSYSAPI
  3375. VOID
  3376. NTAPI
  3377. RtlClearBit (
  3378. PRTL_BITMAP BitMapHeader,
  3379. ULONG BitNumber
  3380. );
  3381. NTSYSAPI
  3382. VOID
  3383. NTAPI
  3384. RtlSetBit (
  3385. PRTL_BITMAP BitMapHeader,
  3386. ULONG BitNumber
  3387. );
  3388. NTSYSAPI
  3389. BOOLEAN
  3390. NTAPI
  3391. RtlTestBit (
  3392. PRTL_BITMAP BitMapHeader,
  3393. ULONG BitNumber
  3394. );
  3395. //
  3396. // The following two routines either clear or set all of the bits
  3397. // in a bitmap.
  3398. //
  3399. NTSYSAPI
  3400. VOID
  3401. NTAPI
  3402. RtlClearAllBits (
  3403. PRTL_BITMAP BitMapHeader
  3404. );
  3405. NTSYSAPI
  3406. VOID
  3407. NTAPI
  3408. RtlSetAllBits (
  3409. PRTL_BITMAP BitMapHeader
  3410. );
  3411. //
  3412. // The following two routines locate a contiguous region of either
  3413. // clear or set bits within the bitmap. The region will be at least
  3414. // as large as the number specified, and the search of the bitmap will
  3415. // begin at the specified hint index (which is a bit index within the
  3416. // bitmap, zero based). The return value is the bit index of the located
  3417. // region (zero based) or -1 (i.e., 0xffffffff) if such a region cannot
  3418. // be located
  3419. //
  3420. NTSYSAPI
  3421. ULONG
  3422. NTAPI
  3423. RtlFindClearBits (
  3424. PRTL_BITMAP BitMapHeader,
  3425. ULONG NumberToFind,
  3426. ULONG HintIndex
  3427. );
  3428. NTSYSAPI
  3429. ULONG
  3430. NTAPI
  3431. RtlFindSetBits (
  3432. PRTL_BITMAP BitMapHeader,
  3433. ULONG NumberToFind,
  3434. ULONG HintIndex
  3435. );
  3436. //
  3437. // The following two routines locate a contiguous region of either
  3438. // clear or set bits within the bitmap and either set or clear the bits
  3439. // within the located region. The region will be as large as the number
  3440. // specified, and the search for the region will begin at the specified
  3441. // hint index (which is a bit index within the bitmap, zero based). The
  3442. // return value is the bit index of the located region (zero based) or
  3443. // -1 (i.e., 0xffffffff) if such a region cannot be located. If a region
  3444. // cannot be located then the setting/clearing of the bitmap is not performed.
  3445. //
  3446. NTSYSAPI
  3447. ULONG
  3448. NTAPI
  3449. RtlFindClearBitsAndSet (
  3450. PRTL_BITMAP BitMapHeader,
  3451. ULONG NumberToFind,
  3452. ULONG HintIndex
  3453. );
  3454. NTSYSAPI
  3455. ULONG
  3456. NTAPI
  3457. RtlFindSetBitsAndClear (
  3458. PRTL_BITMAP BitMapHeader,
  3459. ULONG NumberToFind,
  3460. ULONG HintIndex
  3461. );
  3462. //
  3463. // The following two routines clear or set bits within a specified region
  3464. // of the bitmap. The starting index is zero based.
  3465. //
  3466. NTSYSAPI
  3467. VOID
  3468. NTAPI
  3469. RtlClearBits (
  3470. PRTL_BITMAP BitMapHeader,
  3471. ULONG StartingIndex,
  3472. ULONG NumberToClear
  3473. );
  3474. NTSYSAPI
  3475. VOID
  3476. NTAPI
  3477. RtlSetBits (
  3478. PRTL_BITMAP BitMapHeader,
  3479. ULONG StartingIndex,
  3480. ULONG NumberToSet
  3481. );
  3482. //
  3483. // The following routine locates a set of contiguous regions of clear
  3484. // bits within the bitmap. The caller specifies whether to return the
  3485. // longest runs or just the first found lcoated. The following structure is
  3486. // used to denote a contiguous run of bits. The two routines return an array
  3487. // of this structure, one for each run located.
  3488. //
  3489. typedef struct _RTL_BITMAP_RUN {
  3490. ULONG StartingIndex;
  3491. ULONG NumberOfBits;
  3492. } RTL_BITMAP_RUN;
  3493. typedef RTL_BITMAP_RUN *PRTL_BITMAP_RUN;
  3494. NTSYSAPI
  3495. ULONG
  3496. NTAPI
  3497. RtlFindClearRuns (
  3498. PRTL_BITMAP BitMapHeader,
  3499. PRTL_BITMAP_RUN RunArray,
  3500. ULONG SizeOfRunArray,
  3501. BOOLEAN LocateLongestRuns
  3502. );
  3503. //
  3504. // The following routine locates the longest contiguous region of
  3505. // clear bits within the bitmap. The returned starting index value
  3506. // denotes the first contiguous region located satisfying our requirements
  3507. // The return value is the length (in bits) of the longest region found.
  3508. //
  3509. NTSYSAPI
  3510. ULONG
  3511. NTAPI
  3512. RtlFindLongestRunClear (
  3513. PRTL_BITMAP BitMapHeader,
  3514. PULONG StartingIndex
  3515. );
  3516. //
  3517. // The following routine locates the first contiguous region of
  3518. // clear bits within the bitmap. The returned starting index value
  3519. // denotes the first contiguous region located satisfying our requirements
  3520. // The return value is the length (in bits) of the region found.
  3521. //
  3522. NTSYSAPI
  3523. ULONG
  3524. NTAPI
  3525. RtlFindFirstRunClear (
  3526. PRTL_BITMAP BitMapHeader,
  3527. PULONG StartingIndex
  3528. );
  3529. //
  3530. // The following macro returns the value of the bit stored within the
  3531. // bitmap at the specified location. If the bit is set a value of 1 is
  3532. // returned otherwise a value of 0 is returned.
  3533. //
  3534. // ULONG
  3535. // RtlCheckBit (
  3536. // PRTL_BITMAP BitMapHeader,
  3537. // ULONG BitPosition
  3538. // );
  3539. //
  3540. //
  3541. // To implement CheckBit the macro retrieves the longword containing the
  3542. // bit in question, shifts the longword to get the bit in question into the
  3543. // low order bit position and masks out all other bits.
  3544. //
  3545. #define RtlCheckBit(BMH,BP) ((((BMH)->Buffer[(BP) / 32]) >> ((BP) % 32)) & 0x1)
  3546. //
  3547. // The following two procedures return to the caller the total number of
  3548. // clear or set bits within the specified bitmap.
  3549. //
  3550. NTSYSAPI
  3551. ULONG
  3552. NTAPI
  3553. RtlNumberOfClearBits (
  3554. PRTL_BITMAP BitMapHeader
  3555. );
  3556. NTSYSAPI
  3557. ULONG
  3558. NTAPI
  3559. RtlNumberOfSetBits (
  3560. PRTL_BITMAP BitMapHeader
  3561. );
  3562. //
  3563. // The following two procedures return to the caller a boolean value
  3564. // indicating if the specified range of bits are all clear or set.
  3565. //
  3566. NTSYSAPI
  3567. BOOLEAN
  3568. NTAPI
  3569. RtlAreBitsClear (
  3570. PRTL_BITMAP BitMapHeader,
  3571. ULONG StartingIndex,
  3572. ULONG Length
  3573. );
  3574. NTSYSAPI
  3575. BOOLEAN
  3576. NTAPI
  3577. RtlAreBitsSet (
  3578. PRTL_BITMAP BitMapHeader,
  3579. ULONG StartingIndex,
  3580. ULONG Length
  3581. );
  3582. NTSYSAPI
  3583. ULONG
  3584. NTAPI
  3585. RtlFindNextForwardRunClear (
  3586. IN PRTL_BITMAP BitMapHeader,
  3587. IN ULONG FromIndex,
  3588. IN PULONG StartingRunIndex
  3589. );
  3590. NTSYSAPI
  3591. ULONG
  3592. NTAPI
  3593. RtlFindLastBackwardRunClear (
  3594. IN PRTL_BITMAP BitMapHeader,
  3595. IN ULONG FromIndex,
  3596. IN PULONG StartingRunIndex
  3597. );
  3598. //
  3599. // The following two procedures return to the caller a value indicating
  3600. // the position within a ULONGLONG of the most or least significant non-zero
  3601. // bit. A value of zero results in a return value of -1.
  3602. //
  3603. NTSYSAPI
  3604. CCHAR
  3605. NTAPI
  3606. RtlFindLeastSignificantBit (
  3607. IN ULONGLONG Set
  3608. );
  3609. NTSYSAPI
  3610. CCHAR
  3611. NTAPI
  3612. RtlFindMostSignificantBit (
  3613. IN ULONGLONG Set
  3614. );
  3615. //
  3616. // BOOLEAN
  3617. // RtlEqualLuid(
  3618. // PLUID L1,
  3619. // PLUID L2
  3620. // );
  3621. #define RtlEqualLuid(L1, L2) (((L1)->LowPart == (L2)->LowPart) && \
  3622. ((L1)->HighPart == (L2)->HighPart))
  3623. //
  3624. // BOOLEAN
  3625. // RtlIsZeroLuid(
  3626. // PLUID L1
  3627. // );
  3628. //
  3629. #define RtlIsZeroLuid(L1) ((BOOLEAN) (((L1)->LowPart | (L1)->HighPart) == 0))
  3630. #if !defined(MIDL_PASS)
  3631. FORCEINLINE LUID
  3632. NTAPI
  3633. RtlConvertLongToLuid(
  3634. LONG Long
  3635. )
  3636. {
  3637. LUID TempLuid;
  3638. LARGE_INTEGER TempLi;
  3639. TempLi.QuadPart = Long;
  3640. TempLuid.LowPart = TempLi.LowPart;
  3641. TempLuid.HighPart = TempLi.HighPart;
  3642. return(TempLuid);
  3643. }
  3644. FORCEINLINE
  3645. LUID
  3646. NTAPI
  3647. RtlConvertUlongToLuid(
  3648. ULONG Ulong
  3649. )
  3650. {
  3651. LUID TempLuid;
  3652. TempLuid.LowPart = Ulong;
  3653. TempLuid.HighPart = 0;
  3654. return(TempLuid);
  3655. }
  3656. #endif
  3657. NTSYSAPI
  3658. VOID
  3659. NTAPI
  3660. RtlMapGenericMask(
  3661. PACCESS_MASK AccessMask,
  3662. PGENERIC_MAPPING GenericMapping
  3663. );
  3664. //
  3665. // SecurityDescriptor RTL routine definitions
  3666. //
  3667. NTSYSAPI
  3668. NTSTATUS
  3669. NTAPI
  3670. RtlCreateSecurityDescriptor (
  3671. PSECURITY_DESCRIPTOR SecurityDescriptor,
  3672. ULONG Revision
  3673. );
  3674. NTSYSAPI
  3675. BOOLEAN
  3676. NTAPI
  3677. RtlValidSecurityDescriptor (
  3678. PSECURITY_DESCRIPTOR SecurityDescriptor
  3679. );
  3680. NTSYSAPI
  3681. ULONG
  3682. NTAPI
  3683. RtlLengthSecurityDescriptor (
  3684. PSECURITY_DESCRIPTOR SecurityDescriptor
  3685. );
  3686. NTSYSAPI
  3687. BOOLEAN
  3688. NTAPI
  3689. RtlValidRelativeSecurityDescriptor (
  3690. IN PSECURITY_DESCRIPTOR SecurityDescriptorInput,
  3691. IN ULONG SecurityDescriptorLength,
  3692. IN SECURITY_INFORMATION RequiredInformation
  3693. );
  3694. NTSYSAPI
  3695. NTSTATUS
  3696. NTAPI
  3697. RtlSetDaclSecurityDescriptor (
  3698. PSECURITY_DESCRIPTOR SecurityDescriptor,
  3699. BOOLEAN DaclPresent,
  3700. PACL Dacl,
  3701. BOOLEAN DaclDefaulted
  3702. );
  3703. //
  3704. // Range list package
  3705. //
  3706. typedef struct _RTL_RANGE {
  3707. //
  3708. // The start of the range
  3709. //
  3710. ULONGLONG Start; // Read only
  3711. //
  3712. // The end of the range
  3713. //
  3714. ULONGLONG End; // Read only
  3715. //
  3716. // Data the user passed in when they created the range
  3717. //
  3718. PVOID UserData; // Read/Write
  3719. //
  3720. // The owner of the range
  3721. //
  3722. PVOID Owner; // Read/Write
  3723. //
  3724. // User defined flags the user specified when they created the range
  3725. //
  3726. UCHAR Attributes; // Read/Write
  3727. //
  3728. // Flags (RTL_RANGE_*)
  3729. //
  3730. UCHAR Flags; // Read only
  3731. } RTL_RANGE, *PRTL_RANGE;
  3732. #define RTL_RANGE_SHARED 0x01
  3733. #define RTL_RANGE_CONFLICT 0x02
  3734. typedef struct _RTL_RANGE_LIST {
  3735. //
  3736. // The list of ranges
  3737. //
  3738. LIST_ENTRY ListHead;
  3739. //
  3740. // These always come in useful
  3741. //
  3742. ULONG Flags; // use RANGE_LIST_FLAG_*
  3743. //
  3744. // The number of entries in the list
  3745. //
  3746. ULONG Count;
  3747. //
  3748. // Every time an add/delete operation is performed on the list this is
  3749. // incremented. It is checked during iteration to ensure that the list
  3750. // hasn't changed between GetFirst/GetNext or GetNext/GetNext calls
  3751. //
  3752. ULONG Stamp;
  3753. } RTL_RANGE_LIST, *PRTL_RANGE_LIST;
  3754. typedef struct _RANGE_LIST_ITERATOR {
  3755. PLIST_ENTRY RangeListHead;
  3756. PLIST_ENTRY MergedHead;
  3757. PVOID Current;
  3758. ULONG Stamp;
  3759. } RTL_RANGE_LIST_ITERATOR, *PRTL_RANGE_LIST_ITERATOR;
  3760. NTSYSAPI
  3761. VOID
  3762. NTAPI
  3763. RtlInitializeRangeList(
  3764. IN OUT PRTL_RANGE_LIST RangeList
  3765. );
  3766. NTSYSAPI
  3767. VOID
  3768. NTAPI
  3769. RtlFreeRangeList(
  3770. IN PRTL_RANGE_LIST RangeList
  3771. );
  3772. NTSYSAPI
  3773. NTSTATUS
  3774. NTAPI
  3775. RtlCopyRangeList(
  3776. OUT PRTL_RANGE_LIST CopyRangeList,
  3777. IN PRTL_RANGE_LIST RangeList
  3778. );
  3779. #define RTL_RANGE_LIST_ADD_IF_CONFLICT 0x00000001
  3780. #define RTL_RANGE_LIST_ADD_SHARED 0x00000002
  3781. NTSYSAPI
  3782. NTSTATUS
  3783. NTAPI
  3784. RtlAddRange(
  3785. IN OUT PRTL_RANGE_LIST RangeList,
  3786. IN ULONGLONG Start,
  3787. IN ULONGLONG End,
  3788. IN UCHAR Attributes,
  3789. IN ULONG Flags,
  3790. IN PVOID UserData, OPTIONAL
  3791. IN PVOID Owner OPTIONAL
  3792. );
  3793. NTSYSAPI
  3794. NTSTATUS
  3795. NTAPI
  3796. RtlDeleteRange(
  3797. IN OUT PRTL_RANGE_LIST RangeList,
  3798. IN ULONGLONG Start,
  3799. IN ULONGLONG End,
  3800. IN PVOID Owner
  3801. );
  3802. NTSYSAPI
  3803. NTSTATUS
  3804. NTAPI
  3805. RtlDeleteOwnersRanges(
  3806. IN OUT PRTL_RANGE_LIST RangeList,
  3807. IN PVOID Owner
  3808. );
  3809. #define RTL_RANGE_LIST_SHARED_OK 0x00000001
  3810. #define RTL_RANGE_LIST_NULL_CONFLICT_OK 0x00000002
  3811. typedef
  3812. BOOLEAN
  3813. (*PRTL_CONFLICT_RANGE_CALLBACK) (
  3814. IN PVOID Context,
  3815. IN PRTL_RANGE Range
  3816. );
  3817. NTSYSAPI
  3818. NTSTATUS
  3819. NTAPI
  3820. RtlFindRange(
  3821. IN PRTL_RANGE_LIST RangeList,
  3822. IN ULONGLONG Minimum,
  3823. IN ULONGLONG Maximum,
  3824. IN ULONG Length,
  3825. IN ULONG Alignment,
  3826. IN ULONG Flags,
  3827. IN UCHAR AttributeAvailableMask,
  3828. IN PVOID Context OPTIONAL,
  3829. IN PRTL_CONFLICT_RANGE_CALLBACK Callback OPTIONAL,
  3830. OUT PULONGLONG Start
  3831. );
  3832. NTSYSAPI
  3833. NTSTATUS
  3834. NTAPI
  3835. RtlIsRangeAvailable(
  3836. IN PRTL_RANGE_LIST RangeList,
  3837. IN ULONGLONG Start,
  3838. IN ULONGLONG End,
  3839. IN ULONG Flags,
  3840. IN UCHAR AttributeAvailableMask,
  3841. IN PVOID Context OPTIONAL,
  3842. IN PRTL_CONFLICT_RANGE_CALLBACK Callback OPTIONAL,
  3843. OUT PBOOLEAN Available
  3844. );
  3845. #define FOR_ALL_RANGES(RangeList, Iterator, Current) \
  3846. for (RtlGetFirstRange((RangeList), (Iterator), &(Current)); \
  3847. (Current) != NULL; \
  3848. RtlGetNextRange((Iterator), &(Current), TRUE) \
  3849. )
  3850. #define FOR_ALL_RANGES_BACKWARDS(RangeList, Iterator, Current) \
  3851. for (RtlGetLastRange((RangeList), (Iterator), &(Current)); \
  3852. (Current) != NULL; \
  3853. RtlGetNextRange((Iterator), &(Current), FALSE) \
  3854. )
  3855. NTSYSAPI
  3856. NTSTATUS
  3857. NTAPI
  3858. RtlGetFirstRange(
  3859. IN PRTL_RANGE_LIST RangeList,
  3860. OUT PRTL_RANGE_LIST_ITERATOR Iterator,
  3861. OUT PRTL_RANGE *Range
  3862. );
  3863. NTSYSAPI
  3864. NTSTATUS
  3865. NTAPI
  3866. RtlGetLastRange(
  3867. IN PRTL_RANGE_LIST RangeList,
  3868. OUT PRTL_RANGE_LIST_ITERATOR Iterator,
  3869. OUT PRTL_RANGE *Range
  3870. );
  3871. NTSYSAPI
  3872. NTSTATUS
  3873. NTAPI
  3874. RtlGetNextRange(
  3875. IN OUT PRTL_RANGE_LIST_ITERATOR Iterator,
  3876. OUT PRTL_RANGE *Range,
  3877. IN BOOLEAN MoveForwards
  3878. );
  3879. #define RTL_RANGE_LIST_MERGE_IF_CONFLICT RTL_RANGE_LIST_ADD_IF_CONFLICT
  3880. NTSYSAPI
  3881. NTSTATUS
  3882. NTAPI
  3883. RtlMergeRangeLists(
  3884. OUT PRTL_RANGE_LIST MergedRangeList,
  3885. IN PRTL_RANGE_LIST RangeList1,
  3886. IN PRTL_RANGE_LIST RangeList2,
  3887. IN ULONG Flags
  3888. );
  3889. NTSYSAPI
  3890. NTSTATUS
  3891. NTAPI
  3892. RtlInvertRangeList(
  3893. OUT PRTL_RANGE_LIST InvertedRangeList,
  3894. IN PRTL_RANGE_LIST RangeList
  3895. );
  3896. //
  3897. // Byte swap routines. These are used to convert from little-endian to
  3898. // big-endian and vice-versa.
  3899. //
  3900. #if (defined(_M_IX86) && (_MSC_FULL_VER > 13009037)) || ((defined(_M_AMD64) || defined(_M_IA64)) && (_MSC_FULL_VER > 13009175))
  3901. #ifdef __cplusplus
  3902. extern "C" {
  3903. #endif
  3904. unsigned short __cdecl _byteswap_ushort(unsigned short);
  3905. unsigned long __cdecl _byteswap_ulong (unsigned long);
  3906. unsigned __int64 __cdecl _byteswap_uint64(unsigned __int64);
  3907. #ifdef __cplusplus
  3908. }
  3909. #endif
  3910. #pragma intrinsic(_byteswap_ushort)
  3911. #pragma intrinsic(_byteswap_ulong)
  3912. #pragma intrinsic(_byteswap_uint64)
  3913. #define RtlUshortByteSwap(_x) _byteswap_ushort((USHORT)(_x))
  3914. #define RtlUlongByteSwap(_x) _byteswap_ulong((_x))
  3915. #define RtlUlonglongByteSwap(_x) _byteswap_uint64((_x))
  3916. #else
  3917. USHORT
  3918. FASTCALL
  3919. RtlUshortByteSwap(
  3920. IN USHORT Source
  3921. );
  3922. ULONG
  3923. FASTCALL
  3924. RtlUlongByteSwap(
  3925. IN ULONG Source
  3926. );
  3927. ULONGLONG
  3928. FASTCALL
  3929. RtlUlonglongByteSwap(
  3930. IN ULONGLONG Source
  3931. );
  3932. #endif
  3933. //
  3934. // Routine for converting from a volume device object to a DOS name.
  3935. //
  3936. NTSYSAPI
  3937. NTSTATUS
  3938. NTAPI
  3939. RtlVolumeDeviceToDosName(
  3940. IN PVOID VolumeDeviceObject,
  3941. OUT PUNICODE_STRING DosName
  3942. );
  3943. typedef struct _OSVERSIONINFOA {
  3944. ULONG dwOSVersionInfoSize;
  3945. ULONG dwMajorVersion;
  3946. ULONG dwMinorVersion;
  3947. ULONG dwBuildNumber;
  3948. ULONG dwPlatformId;
  3949. CHAR szCSDVersion[ 128 ]; // Maintenance string for PSS usage
  3950. } OSVERSIONINFOA, *POSVERSIONINFOA, *LPOSVERSIONINFOA;
  3951. typedef struct _OSVERSIONINFOW {
  3952. ULONG dwOSVersionInfoSize;
  3953. ULONG dwMajorVersion;
  3954. ULONG dwMinorVersion;
  3955. ULONG dwBuildNumber;
  3956. ULONG dwPlatformId;
  3957. WCHAR szCSDVersion[ 128 ]; // Maintenance string for PSS usage
  3958. } OSVERSIONINFOW, *POSVERSIONINFOW, *LPOSVERSIONINFOW, RTL_OSVERSIONINFOW, *PRTL_OSVERSIONINFOW;
  3959. #ifdef UNICODE
  3960. typedef OSVERSIONINFOW OSVERSIONINFO;
  3961. typedef POSVERSIONINFOW POSVERSIONINFO;
  3962. typedef LPOSVERSIONINFOW LPOSVERSIONINFO;
  3963. #else
  3964. typedef OSVERSIONINFOA OSVERSIONINFO;
  3965. typedef POSVERSIONINFOA POSVERSIONINFO;
  3966. typedef LPOSVERSIONINFOA LPOSVERSIONINFO;
  3967. #endif // UNICODE
  3968. typedef struct _OSVERSIONINFOEXA {
  3969. ULONG dwOSVersionInfoSize;
  3970. ULONG dwMajorVersion;
  3971. ULONG dwMinorVersion;
  3972. ULONG dwBuildNumber;
  3973. ULONG dwPlatformId;
  3974. CHAR szCSDVersion[ 128 ]; // Maintenance string for PSS usage
  3975. USHORT wServicePackMajor;
  3976. USHORT wServicePackMinor;
  3977. USHORT wSuiteMask;
  3978. UCHAR wProductType;
  3979. UCHAR wReserved;
  3980. } OSVERSIONINFOEXA, *POSVERSIONINFOEXA, *LPOSVERSIONINFOEXA;
  3981. typedef struct _OSVERSIONINFOEXW {
  3982. ULONG dwOSVersionInfoSize;
  3983. ULONG dwMajorVersion;
  3984. ULONG dwMinorVersion;
  3985. ULONG dwBuildNumber;
  3986. ULONG dwPlatformId;
  3987. WCHAR szCSDVersion[ 128 ]; // Maintenance string for PSS usage
  3988. USHORT wServicePackMajor;
  3989. USHORT wServicePackMinor;
  3990. USHORT wSuiteMask;
  3991. UCHAR wProductType;
  3992. UCHAR wReserved;
  3993. } OSVERSIONINFOEXW, *POSVERSIONINFOEXW, *LPOSVERSIONINFOEXW, RTL_OSVERSIONINFOEXW, *PRTL_OSVERSIONINFOEXW;
  3994. #ifdef UNICODE
  3995. typedef OSVERSIONINFOEXW OSVERSIONINFOEX;
  3996. typedef POSVERSIONINFOEXW POSVERSIONINFOEX;
  3997. typedef LPOSVERSIONINFOEXW LPOSVERSIONINFOEX;
  3998. #else
  3999. typedef OSVERSIONINFOEXA OSVERSIONINFOEX;
  4000. typedef POSVERSIONINFOEXA POSVERSIONINFOEX;
  4001. typedef LPOSVERSIONINFOEXA LPOSVERSIONINFOEX;
  4002. #endif // UNICODE
  4003. //
  4004. // RtlVerifyVersionInfo() conditions
  4005. //
  4006. #define VER_EQUAL 1
  4007. #define VER_GREATER 2
  4008. #define VER_GREATER_EQUAL 3
  4009. #define VER_LESS 4
  4010. #define VER_LESS_EQUAL 5
  4011. #define VER_AND 6
  4012. #define VER_OR 7
  4013. #define VER_CONDITION_MASK 7
  4014. #define VER_NUM_BITS_PER_CONDITION_MASK 3
  4015. //
  4016. // RtlVerifyVersionInfo() type mask bits
  4017. //
  4018. #define VER_MINORVERSION 0x0000001
  4019. #define VER_MAJORVERSION 0x0000002
  4020. #define VER_BUILDNUMBER 0x0000004
  4021. #define VER_PLATFORMID 0x0000008
  4022. #define VER_SERVICEPACKMINOR 0x0000010
  4023. #define VER_SERVICEPACKMAJOR 0x0000020
  4024. #define VER_SUITENAME 0x0000040
  4025. #define VER_PRODUCT_TYPE 0x0000080
  4026. //
  4027. // RtlVerifyVersionInfo() os product type values
  4028. //
  4029. #define VER_NT_WORKSTATION 0x0000001
  4030. #define VER_NT_DOMAIN_CONTROLLER 0x0000002
  4031. #define VER_NT_SERVER 0x0000003
  4032. //
  4033. // dwPlatformId defines:
  4034. //
  4035. #define VER_PLATFORM_WIN32s 0
  4036. #define VER_PLATFORM_WIN32_WINDOWS 1
  4037. #define VER_PLATFORM_WIN32_NT 2
  4038. //
  4039. //
  4040. // VerifyVersionInfo() macro to set the condition mask
  4041. //
  4042. // For documentation sakes here's the old version of the macro that got
  4043. // changed to call an API
  4044. // #define VER_SET_CONDITION(_m_,_t_,_c_) _m_=(_m_|(_c_<<(1<<_t_)))
  4045. //
  4046. #define VER_SET_CONDITION(_m_,_t_,_c_) \
  4047. ((_m_)=VerSetConditionMask((_m_),(_t_),(_c_)))
  4048. ULONGLONG
  4049. NTAPI
  4050. VerSetConditionMask(
  4051. IN ULONGLONG ConditionMask,
  4052. IN ULONG TypeMask,
  4053. IN UCHAR Condition
  4054. );
  4055. //
  4056. //
  4057. NTSYSAPI
  4058. NTSTATUS
  4059. RtlGetVersion(
  4060. OUT PRTL_OSVERSIONINFOW lpVersionInformation
  4061. );
  4062. NTSYSAPI
  4063. NTSTATUS
  4064. RtlVerifyVersionInfo(
  4065. IN PRTL_OSVERSIONINFOEXW VersionInfo,
  4066. IN ULONG TypeMask,
  4067. IN ULONGLONG ConditionMask
  4068. );
  4069. //
  4070. //
  4071. // Interlocked bit manipulation interfaces
  4072. //
  4073. #define RtlInterlockedSetBits(Flags, Flag) \
  4074. InterlockedOr((PLONG)(Flags), Flag)
  4075. #define RtlInterlockedAndBits(Flags, Flag) \
  4076. InterlockedAnd((PLONG)(Flags), Flag)
  4077. #define RtlInterlockedClearBits(Flags, Flag) \
  4078. RtlInterlockedAndBits(Flags, ~(Flag))
  4079. #define RtlInterlockedXorBits(Flags, Flag) \
  4080. InterlockedXor(Flags, Flag)
  4081. #define RtlInterlockedSetBitsDiscardReturn(Flags, Flag) \
  4082. (VOID) RtlInterlockedSetBits(Flags, Flag)
  4083. #define RtlInterlockedAndBitsDiscardReturn(Flags, Flag) \
  4084. (VOID) RtlInterlockedAndBits(Flags, Flag)
  4085. #define RtlInterlockedClearBitsDiscardReturn(Flags, Flag) \
  4086. RtlInterlockedAndBitsDiscardReturn(Flags, ~(Flag))
  4087. //
  4088. // Component name filter id enumeration and levels.
  4089. //
  4090. #define DPFLTR_ERROR_LEVEL 0
  4091. #define DPFLTR_WARNING_LEVEL 1
  4092. #define DPFLTR_TRACE_LEVEL 2
  4093. #define DPFLTR_INFO_LEVEL 3
  4094. #define DPFLTR_MASK 0x80000000
  4095. typedef enum _DPFLTR_TYPE {
  4096. DPFLTR_SYSTEM_ID = 0,
  4097. DPFLTR_SMSS_ID = 1,
  4098. DPFLTR_SETUP_ID = 2,
  4099. DPFLTR_NTFS_ID = 3,
  4100. DPFLTR_FSTUB_ID = 4,
  4101. DPFLTR_CRASHDUMP_ID = 5,
  4102. DPFLTR_CDAUDIO_ID = 6,
  4103. DPFLTR_CDROM_ID = 7,
  4104. DPFLTR_CLASSPNP_ID = 8,
  4105. DPFLTR_DISK_ID = 9,
  4106. DPFLTR_REDBOOK_ID = 10,
  4107. DPFLTR_STORPROP_ID = 11,
  4108. DPFLTR_SCSIPORT_ID = 12,
  4109. DPFLTR_SCSIMINIPORT_ID = 13,
  4110. DPFLTR_CONFIG_ID = 14,
  4111. DPFLTR_I8042PRT_ID = 15,
  4112. DPFLTR_SERMOUSE_ID = 16,
  4113. DPFLTR_LSERMOUS_ID = 17,
  4114. DPFLTR_KBDHID_ID = 18,
  4115. DPFLTR_MOUHID_ID = 19,
  4116. DPFLTR_KBDCLASS_ID = 20,
  4117. DPFLTR_MOUCLASS_ID = 21,
  4118. DPFLTR_TWOTRACK_ID = 22,
  4119. DPFLTR_WMILIB_ID = 23,
  4120. DPFLTR_ACPI_ID = 24,
  4121. DPFLTR_AMLI_ID = 25,
  4122. DPFLTR_HALIA64_ID = 26,
  4123. DPFLTR_VIDEO_ID = 27,
  4124. DPFLTR_SVCHOST_ID = 28,
  4125. DPFLTR_VIDEOPRT_ID = 29,
  4126. DPFLTR_TCPIP_ID = 30,
  4127. DPFLTR_DMSYNTH_ID = 31,
  4128. DPFLTR_NTOSPNP_ID = 32,
  4129. DPFLTR_FASTFAT_ID = 33,
  4130. DPFLTR_SAMSS_ID = 34,
  4131. DPFLTR_PNPMGR_ID = 35,
  4132. DPFLTR_NETAPI_ID = 36,
  4133. DPFLTR_SCSERVER_ID = 37,
  4134. DPFLTR_SCCLIENT_ID = 38,
  4135. DPFLTR_SERIAL_ID = 39,
  4136. DPFLTR_SERENUM_ID = 40,
  4137. DPFLTR_UHCD_ID = 41,
  4138. DPFLTR_RPCPROXY_ID = 42,
  4139. DPFLTR_AUTOCHK_ID = 43,
  4140. DPFLTR_DCOMSS_ID = 44,
  4141. DPFLTR_UNIMODEM_ID = 45,
  4142. DPFLTR_SIS_ID = 46,
  4143. DPFLTR_FLTMGR_ID = 47,
  4144. DPFLTR_WMICORE_ID = 48,
  4145. DPFLTR_BURNENG_ID = 49,
  4146. DPFLTR_IMAPI_ID = 50,
  4147. DPFLTR_SXS_ID = 51,
  4148. DPFLTR_FUSION_ID = 52,
  4149. DPFLTR_IDLETASK_ID = 53,
  4150. DPFLTR_SOFTPCI_ID = 54,
  4151. DPFLTR_TAPE_ID = 55,
  4152. DPFLTR_MCHGR_ID = 56,
  4153. DPFLTR_IDEP_ID = 57,
  4154. DPFLTR_PCIIDE_ID = 58,
  4155. DPFLTR_FLOPPY_ID = 59,
  4156. DPFLTR_FDC_ID = 60,
  4157. DPFLTR_TERMSRV_ID = 61,
  4158. DPFLTR_W32TIME_ID = 62,
  4159. DPFLTR_PREFETCHER_ID = 63,
  4160. DPFLTR_RSFILTER_ID = 64,
  4161. DPFLTR_FCPORT_ID = 65,
  4162. DPFLTR_PCI_ID = 66,
  4163. DPFLTR_DMIO_ID = 67,
  4164. DPFLTR_DMCONFIG_ID = 68,
  4165. DPFLTR_DMADMIN_ID = 69,
  4166. DPFLTR_WSOCKTRANSPORT_ID = 70,
  4167. DPFLTR_VSS_ID = 71,
  4168. DPFLTR_PNPMEM_ID = 72,
  4169. DPFLTR_PROCESSOR_ID = 73,
  4170. DPFLTR_DMSERVER_ID = 74,
  4171. DPFLTR_SR_ID = 75,
  4172. DPFLTR_INFINIBAND_ID = 76,
  4173. DPFLTR_IHVDRIVER_ID = 77,
  4174. DPFLTR_IHVVIDEO_ID = 78,
  4175. DPFLTR_IHVAUDIO_ID = 79,
  4176. DPFLTR_IHVNETWORK_ID = 80,
  4177. DPFLTR_IHVSTREAMING_ID = 81,
  4178. DPFLTR_IHVBUS_ID = 82,
  4179. DPFLTR_HPS_ID = 83,
  4180. DPFLTR_RTLTHREADPOOL_ID = 84,
  4181. DPFLTR_LDR_ID = 85,
  4182. DPFLTR_TCPIP6_ID = 86,
  4183. DPFLTR_ISAPNP_ID = 87,
  4184. DPFLTR_SHPC_ID = 88,
  4185. DPFLTR_STORPORT_ID = 89,
  4186. DPFLTR_STORMINIPORT_ID = 90,
  4187. DPFLTR_PRINTSPOOLER_ID = 91,
  4188. DPFLTR_VSSDYNDISK_ID = 92,
  4189. DPFLTR_VERIFIER_ID = 93,
  4190. DPFLTR_VDS_ID = 94,
  4191. DPFLTR_VDSBAS_ID = 95,
  4192. DPFLTR_VDSDYNDR_ID = 96,
  4193. DPFLTR_VDSUTIL_ID = 97,
  4194. DPFLTR_DFRGIFC_ID = 98,
  4195. DPFLTR_ENDOFTABLE_ID
  4196. } DPFLTR_TYPE;
  4197. //
  4198. // Define the various device type values. Note that values used by Microsoft
  4199. // Corporation are in the range 0-32767, and 32768-65535 are reserved for use
  4200. // by customers.
  4201. //
  4202. #define DEVICE_TYPE ULONG
  4203. #define FILE_DEVICE_BEEP 0x00000001
  4204. #define FILE_DEVICE_CD_ROM 0x00000002
  4205. #define FILE_DEVICE_CD_ROM_FILE_SYSTEM 0x00000003
  4206. #define FILE_DEVICE_CONTROLLER 0x00000004
  4207. #define FILE_DEVICE_DATALINK 0x00000005
  4208. #define FILE_DEVICE_DFS 0x00000006
  4209. #define FILE_DEVICE_DISK 0x00000007
  4210. #define FILE_DEVICE_DISK_FILE_SYSTEM 0x00000008
  4211. #define FILE_DEVICE_FILE_SYSTEM 0x00000009
  4212. #define FILE_DEVICE_INPORT_PORT 0x0000000a
  4213. #define FILE_DEVICE_KEYBOARD 0x0000000b
  4214. #define FILE_DEVICE_MAILSLOT 0x0000000c
  4215. #define FILE_DEVICE_MIDI_IN 0x0000000d
  4216. #define FILE_DEVICE_MIDI_OUT 0x0000000e
  4217. #define FILE_DEVICE_MOUSE 0x0000000f
  4218. #define FILE_DEVICE_MULTI_UNC_PROVIDER 0x00000010
  4219. #define FILE_DEVICE_NAMED_PIPE 0x00000011
  4220. #define FILE_DEVICE_NETWORK 0x00000012
  4221. #define FILE_DEVICE_NETWORK_BROWSER 0x00000013
  4222. #define FILE_DEVICE_NETWORK_FILE_SYSTEM 0x00000014
  4223. #define FILE_DEVICE_NULL 0x00000015
  4224. #define FILE_DEVICE_PARALLEL_PORT 0x00000016
  4225. #define FILE_DEVICE_PHYSICAL_NETCARD 0x00000017
  4226. #define FILE_DEVICE_PRINTER 0x00000018
  4227. #define FILE_DEVICE_SCANNER 0x00000019
  4228. #define FILE_DEVICE_SERIAL_MOUSE_PORT 0x0000001a
  4229. #define FILE_DEVICE_SERIAL_PORT 0x0000001b
  4230. #define FILE_DEVICE_SCREEN 0x0000001c
  4231. #define FILE_DEVICE_SOUND 0x0000001d
  4232. #define FILE_DEVICE_STREAMS 0x0000001e
  4233. #define FILE_DEVICE_TAPE 0x0000001f
  4234. #define FILE_DEVICE_TAPE_FILE_SYSTEM 0x00000020
  4235. #define FILE_DEVICE_TRANSPORT 0x00000021
  4236. #define FILE_DEVICE_UNKNOWN 0x00000022
  4237. #define FILE_DEVICE_VIDEO 0x00000023
  4238. #define FILE_DEVICE_VIRTUAL_DISK 0x00000024
  4239. #define FILE_DEVICE_WAVE_IN 0x00000025
  4240. #define FILE_DEVICE_WAVE_OUT 0x00000026
  4241. #define FILE_DEVICE_8042_PORT 0x00000027
  4242. #define FILE_DEVICE_NETWORK_REDIRECTOR 0x00000028
  4243. #define FILE_DEVICE_BATTERY 0x00000029
  4244. #define FILE_DEVICE_BUS_EXTENDER 0x0000002a
  4245. #define FILE_DEVICE_MODEM 0x0000002b
  4246. #define FILE_DEVICE_VDM 0x0000002c
  4247. #define FILE_DEVICE_MASS_STORAGE 0x0000002d
  4248. #define FILE_DEVICE_SMB 0x0000002e
  4249. #define FILE_DEVICE_KS 0x0000002f
  4250. #define FILE_DEVICE_CHANGER 0x00000030
  4251. #define FILE_DEVICE_SMARTCARD 0x00000031
  4252. #define FILE_DEVICE_ACPI 0x00000032
  4253. #define FILE_DEVICE_DVD 0x00000033
  4254. #define FILE_DEVICE_FULLSCREEN_VIDEO 0x00000034
  4255. #define FILE_DEVICE_DFS_FILE_SYSTEM 0x00000035
  4256. #define FILE_DEVICE_DFS_VOLUME 0x00000036
  4257. #define FILE_DEVICE_SERENUM 0x00000037
  4258. #define FILE_DEVICE_TERMSRV 0x00000038
  4259. #define FILE_DEVICE_KSEC 0x00000039
  4260. #define FILE_DEVICE_FIPS 0x0000003A
  4261. #define FILE_DEVICE_INFINIBAND 0x0000003B
  4262. //
  4263. // Macro definition for defining IOCTL and FSCTL function control codes. Note
  4264. // that function codes 0-2047 are reserved for Microsoft Corporation, and
  4265. // 2048-4095 are reserved for customers.
  4266. //
  4267. #define CTL_CODE( DeviceType, Function, Method, Access ) ( \
  4268. ((DeviceType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method) \
  4269. )
  4270. //
  4271. // Macro to extract device type out of the device io control code
  4272. //
  4273. #define DEVICE_TYPE_FROM_CTL_CODE(ctrlCode) (((ULONG)(ctrlCode & 0xffff0000)) >> 16)
  4274. //
  4275. // Define the method codes for how buffers are passed for I/O and FS controls
  4276. //
  4277. #define METHOD_BUFFERED 0
  4278. #define METHOD_IN_DIRECT 1
  4279. #define METHOD_OUT_DIRECT 2
  4280. #define METHOD_NEITHER 3
  4281. //
  4282. // Define some easier to comprehend aliases:
  4283. // METHOD_DIRECT_TO_HARDWARE (writes, aka METHOD_IN_DIRECT)
  4284. // METHOD_DIRECT_FROM_HARDWARE (reads, aka METHOD_OUT_DIRECT)
  4285. //
  4286. #define METHOD_DIRECT_TO_HARDWARE METHOD_IN_DIRECT
  4287. #define METHOD_DIRECT_FROM_HARDWARE METHOD_OUT_DIRECT
  4288. //
  4289. // Define the access check value for any access
  4290. //
  4291. //
  4292. // The FILE_READ_ACCESS and FILE_WRITE_ACCESS constants are also defined in
  4293. // ntioapi.h as FILE_READ_DATA and FILE_WRITE_DATA. The values for these
  4294. // constants *MUST* always be in sync.
  4295. //
  4296. //
  4297. // FILE_SPECIAL_ACCESS is checked by the NT I/O system the same as FILE_ANY_ACCESS.
  4298. // The file systems, however, may add additional access checks for I/O and FS controls
  4299. // that use this value.
  4300. //
  4301. #define FILE_ANY_ACCESS 0
  4302. #define FILE_SPECIAL_ACCESS (FILE_ANY_ACCESS)
  4303. #define FILE_READ_ACCESS ( 0x0001 ) // file & pipe
  4304. #define FILE_WRITE_ACCESS ( 0x0002 ) // file & pipe
  4305. //
  4306. // Define access rights to files and directories
  4307. //
  4308. //
  4309. // The FILE_READ_DATA and FILE_WRITE_DATA constants are also defined in
  4310. // devioctl.h as FILE_READ_ACCESS and FILE_WRITE_ACCESS. The values for these
  4311. // constants *MUST* always be in sync.
  4312. // The values are redefined in devioctl.h because they must be available to
  4313. // both DOS and NT.
  4314. //
  4315. #define FILE_READ_DATA ( 0x0001 ) // file & pipe
  4316. #define FILE_LIST_DIRECTORY ( 0x0001 ) // directory
  4317. #define FILE_WRITE_DATA ( 0x0002 ) // file & pipe
  4318. #define FILE_ADD_FILE ( 0x0002 ) // directory
  4319. #define FILE_APPEND_DATA ( 0x0004 ) // file
  4320. #define FILE_ADD_SUBDIRECTORY ( 0x0004 ) // directory
  4321. #define FILE_CREATE_PIPE_INSTANCE ( 0x0004 ) // named pipe
  4322. #define FILE_READ_EA ( 0x0008 ) // file & directory
  4323. #define FILE_WRITE_EA ( 0x0010 ) // file & directory
  4324. #define FILE_EXECUTE ( 0x0020 ) // file
  4325. #define FILE_TRAVERSE ( 0x0020 ) // directory
  4326. #define FILE_DELETE_CHILD ( 0x0040 ) // directory
  4327. #define FILE_READ_ATTRIBUTES ( 0x0080 ) // all
  4328. #define FILE_WRITE_ATTRIBUTES ( 0x0100 ) // all
  4329. #define FILE_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | 0x1FF)
  4330. #define FILE_GENERIC_READ (STANDARD_RIGHTS_READ |\
  4331. FILE_READ_DATA |\
  4332. FILE_READ_ATTRIBUTES |\
  4333. FILE_READ_EA |\
  4334. SYNCHRONIZE)
  4335. #define FILE_GENERIC_WRITE (STANDARD_RIGHTS_WRITE |\
  4336. FILE_WRITE_DATA |\
  4337. FILE_WRITE_ATTRIBUTES |\
  4338. FILE_WRITE_EA |\
  4339. FILE_APPEND_DATA |\
  4340. SYNCHRONIZE)
  4341. #define FILE_GENERIC_EXECUTE (STANDARD_RIGHTS_EXECUTE |\
  4342. FILE_READ_ATTRIBUTES |\
  4343. FILE_EXECUTE |\
  4344. SYNCHRONIZE)
  4345. //
  4346. // Define share access rights to files and directories
  4347. //
  4348. #define FILE_SHARE_READ 0x00000001
  4349. #define FILE_SHARE_WRITE 0x00000002
  4350. #define FILE_SHARE_DELETE 0x00000004
  4351. #define FILE_SHARE_VALID_FLAGS 0x00000007
  4352. //
  4353. // Define the file attributes values
  4354. //
  4355. // Note: 0x00000008 is reserved for use for the old DOS VOLID (volume ID)
  4356. // and is therefore not considered valid in NT.
  4357. //
  4358. // Note: 0x00000010 is reserved for use for the old DOS SUBDIRECTORY flag
  4359. // and is therefore not considered valid in NT. This flag has
  4360. // been disassociated with file attributes since the other flags are
  4361. // protected with READ_ and WRITE_ATTRIBUTES access to the file.
  4362. //
  4363. // Note: Note also that the order of these flags is set to allow both the
  4364. // FAT and the Pinball File Systems to directly set the attributes
  4365. // flags in attributes words without having to pick each flag out
  4366. // individually. The order of these flags should not be changed!
  4367. //
  4368. #define FILE_ATTRIBUTE_READONLY 0x00000001
  4369. #define FILE_ATTRIBUTE_HIDDEN 0x00000002
  4370. #define FILE_ATTRIBUTE_SYSTEM 0x00000004
  4371. //OLD DOS VOLID 0x00000008
  4372. #define FILE_ATTRIBUTE_DIRECTORY 0x00000010
  4373. #define FILE_ATTRIBUTE_ARCHIVE 0x00000020
  4374. #define FILE_ATTRIBUTE_DEVICE 0x00000040
  4375. #define FILE_ATTRIBUTE_NORMAL 0x00000080
  4376. #define FILE_ATTRIBUTE_TEMPORARY 0x00000100
  4377. #define FILE_ATTRIBUTE_SPARSE_FILE 0x00000200
  4378. #define FILE_ATTRIBUTE_REPARSE_POINT 0x00000400
  4379. #define FILE_ATTRIBUTE_COMPRESSED 0x00000800
  4380. #define FILE_ATTRIBUTE_OFFLINE 0x00001000
  4381. #define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED 0x00002000
  4382. #define FILE_ATTRIBUTE_ENCRYPTED 0x00004000
  4383. #define FILE_ATTRIBUTE_VALID_FLAGS 0x00007fb7
  4384. #define FILE_ATTRIBUTE_VALID_SET_FLAGS 0x000031a7
  4385. //
  4386. // Define the create disposition values
  4387. //
  4388. #define FILE_SUPERSEDE 0x00000000
  4389. #define FILE_OPEN 0x00000001
  4390. #define FILE_CREATE 0x00000002
  4391. #define FILE_OPEN_IF 0x00000003
  4392. #define FILE_OVERWRITE 0x00000004
  4393. #define FILE_OVERWRITE_IF 0x00000005
  4394. #define FILE_MAXIMUM_DISPOSITION 0x00000005
  4395. //
  4396. // Define the create/open option flags
  4397. //
  4398. #define FILE_DIRECTORY_FILE 0x00000001
  4399. #define FILE_WRITE_THROUGH 0x00000002
  4400. #define FILE_SEQUENTIAL_ONLY 0x00000004
  4401. #define FILE_NO_INTERMEDIATE_BUFFERING 0x00000008
  4402. #define FILE_SYNCHRONOUS_IO_ALERT 0x00000010
  4403. #define FILE_SYNCHRONOUS_IO_NONALERT 0x00000020
  4404. #define FILE_NON_DIRECTORY_FILE 0x00000040
  4405. #define FILE_CREATE_TREE_CONNECTION 0x00000080
  4406. #define FILE_COMPLETE_IF_OPLOCKED 0x00000100
  4407. #define FILE_NO_EA_KNOWLEDGE 0x00000200
  4408. #define FILE_OPEN_FOR_RECOVERY 0x00000400
  4409. #define FILE_RANDOM_ACCESS 0x00000800
  4410. #define FILE_DELETE_ON_CLOSE 0x00001000
  4411. #define FILE_OPEN_BY_FILE_ID 0x00002000
  4412. #define FILE_OPEN_FOR_BACKUP_INTENT 0x00004000
  4413. #define FILE_NO_COMPRESSION 0x00008000
  4414. #define FILE_RESERVE_OPFILTER 0x00100000
  4415. #define FILE_OPEN_REPARSE_POINT 0x00200000
  4416. #define FILE_OPEN_NO_RECALL 0x00400000
  4417. #define FILE_OPEN_FOR_FREE_SPACE_QUERY 0x00800000
  4418. #define FILE_COPY_STRUCTURED_STORAGE 0x00000041
  4419. #define FILE_STRUCTURED_STORAGE 0x00000441
  4420. #define FILE_VALID_OPTION_FLAGS 0x00ffffff
  4421. #define FILE_VALID_PIPE_OPTION_FLAGS 0x00000032
  4422. #define FILE_VALID_MAILSLOT_OPTION_FLAGS 0x00000032
  4423. #define FILE_VALID_SET_FLAGS 0x00000036
  4424. //
  4425. // Define the I/O status information return values for NtCreateFile/NtOpenFile
  4426. //
  4427. #define FILE_SUPERSEDED 0x00000000
  4428. #define FILE_OPENED 0x00000001
  4429. #define FILE_CREATED 0x00000002
  4430. #define FILE_OVERWRITTEN 0x00000003
  4431. #define FILE_EXISTS 0x00000004
  4432. #define FILE_DOES_NOT_EXIST 0x00000005
  4433. //
  4434. // Define special ByteOffset parameters for read and write operations
  4435. //
  4436. #define FILE_WRITE_TO_END_OF_FILE 0xffffffff
  4437. #define FILE_USE_FILE_POINTER_POSITION 0xfffffffe
  4438. //
  4439. // Define alignment requirement values
  4440. //
  4441. #define FILE_BYTE_ALIGNMENT 0x00000000
  4442. #define FILE_WORD_ALIGNMENT 0x00000001
  4443. #define FILE_LONG_ALIGNMENT 0x00000003
  4444. #define FILE_QUAD_ALIGNMENT 0x00000007
  4445. #define FILE_OCTA_ALIGNMENT 0x0000000f
  4446. #define FILE_32_BYTE_ALIGNMENT 0x0000001f
  4447. #define FILE_64_BYTE_ALIGNMENT 0x0000003f
  4448. #define FILE_128_BYTE_ALIGNMENT 0x0000007f
  4449. #define FILE_256_BYTE_ALIGNMENT 0x000000ff
  4450. #define FILE_512_BYTE_ALIGNMENT 0x000001ff
  4451. //
  4452. // Define the maximum length of a filename string
  4453. //
  4454. #define MAXIMUM_FILENAME_LENGTH 256
  4455. //
  4456. // Define the various device characteristics flags
  4457. //
  4458. #define FILE_REMOVABLE_MEDIA 0x00000001
  4459. #define FILE_READ_ONLY_DEVICE 0x00000002
  4460. #define FILE_FLOPPY_DISKETTE 0x00000004
  4461. #define FILE_WRITE_ONCE_MEDIA 0x00000008
  4462. #define FILE_REMOTE_DEVICE 0x00000010
  4463. #define FILE_DEVICE_IS_MOUNTED 0x00000020
  4464. #define FILE_VIRTUAL_VOLUME 0x00000040
  4465. #define FILE_AUTOGENERATED_DEVICE_NAME 0x00000080
  4466. #define FILE_DEVICE_SECURE_OPEN 0x00000100
  4467. #define FILE_CHARACTERISTIC_PNP_DEVICE 0x00000800
  4468. //
  4469. // The FILE_EXPECT flags will only exist for WinXP. After that they will be
  4470. // ignored and an IRP will be sent in their place.
  4471. //
  4472. #define FILE_CHARACTERISTICS_EXPECT_ORDERLY_REMOVAL 0x00000200
  4473. #define FILE_CHARACTERISTICS_EXPECT_SURPRISE_REMOVAL 0x00000300
  4474. #define FILE_CHARACTERISTICS_REMOVAL_POLICY_MASK 0x00000300
  4475. //
  4476. // flags specified here will be propagated up and down a device stack
  4477. // after FDO and all filter devices are added, but before the device
  4478. // stack is started
  4479. //
  4480. #define FILE_CHARACTERISTICS_PROPAGATED ( FILE_REMOVABLE_MEDIA | \
  4481. FILE_READ_ONLY_DEVICE | \
  4482. FILE_FLOPPY_DISKETTE | \
  4483. FILE_WRITE_ONCE_MEDIA | \
  4484. FILE_DEVICE_SECURE_OPEN )
  4485. //
  4486. // Define the base asynchronous I/O argument types
  4487. //
  4488. typedef struct _IO_STATUS_BLOCK {
  4489. union {
  4490. NTSTATUS Status;
  4491. PVOID Pointer;
  4492. };
  4493. ULONG_PTR Information;
  4494. } IO_STATUS_BLOCK, *PIO_STATUS_BLOCK;
  4495. #if defined(_WIN64)
  4496. typedef struct _IO_STATUS_BLOCK32 {
  4497. NTSTATUS Status;
  4498. ULONG Information;
  4499. } IO_STATUS_BLOCK32, *PIO_STATUS_BLOCK32;
  4500. #endif
  4501. //
  4502. // Define an Asynchronous Procedure Call from I/O viewpoint
  4503. //
  4504. typedef
  4505. VOID
  4506. (NTAPI *PIO_APC_ROUTINE) (
  4507. IN PVOID ApcContext,
  4508. IN PIO_STATUS_BLOCK IoStatusBlock,
  4509. IN ULONG Reserved
  4510. );
  4511. #define PIO_APC_ROUTINE_DEFINED
  4512. //
  4513. // Define the file information class values
  4514. //
  4515. // WARNING: The order of the following values are assumed by the I/O system.
  4516. // Any changes made here should be reflected there as well.
  4517. //
  4518. typedef enum _FILE_INFORMATION_CLASS {
  4519. FileDirectoryInformation = 1,
  4520. FileFullDirectoryInformation, // 2
  4521. FileBothDirectoryInformation, // 3
  4522. FileBasicInformation, // 4 wdm
  4523. FileStandardInformation, // 5 wdm
  4524. FileInternalInformation, // 6
  4525. FileEaInformation, // 7
  4526. FileAccessInformation, // 8
  4527. FileNameInformation, // 9
  4528. FileRenameInformation, // 10
  4529. FileLinkInformation, // 11
  4530. FileNamesInformation, // 12
  4531. FileDispositionInformation, // 13
  4532. FilePositionInformation, // 14 wdm
  4533. FileFullEaInformation, // 15
  4534. FileModeInformation, // 16
  4535. FileAlignmentInformation, // 17
  4536. FileAllInformation, // 18
  4537. FileAllocationInformation, // 19
  4538. FileEndOfFileInformation, // 20 wdm
  4539. FileAlternateNameInformation, // 21
  4540. FileStreamInformation, // 22
  4541. FilePipeInformation, // 23
  4542. FilePipeLocalInformation, // 24
  4543. FilePipeRemoteInformation, // 25
  4544. FileMailslotQueryInformation, // 26
  4545. FileMailslotSetInformation, // 27
  4546. FileCompressionInformation, // 28
  4547. FileObjectIdInformation, // 29
  4548. FileCompletionInformation, // 30
  4549. FileMoveClusterInformation, // 31
  4550. FileQuotaInformation, // 32
  4551. FileReparsePointInformation, // 33
  4552. FileNetworkOpenInformation, // 34
  4553. FileAttributeTagInformation, // 35
  4554. FileTrackingInformation, // 36
  4555. FileIdBothDirectoryInformation, // 37
  4556. FileIdFullDirectoryInformation, // 38
  4557. FileValidDataLengthInformation, // 39
  4558. FileShortNameInformation, // 40
  4559. FileMaximumInformation
  4560. } FILE_INFORMATION_CLASS, *PFILE_INFORMATION_CLASS;
  4561. //
  4562. // Define the various structures which are returned on query operations
  4563. //
  4564. typedef struct _FILE_BASIC_INFORMATION {
  4565. LARGE_INTEGER CreationTime;
  4566. LARGE_INTEGER LastAccessTime;
  4567. LARGE_INTEGER LastWriteTime;
  4568. LARGE_INTEGER ChangeTime;
  4569. ULONG FileAttributes;
  4570. } FILE_BASIC_INFORMATION, *PFILE_BASIC_INFORMATION;
  4571. typedef struct _FILE_STANDARD_INFORMATION {
  4572. LARGE_INTEGER AllocationSize;
  4573. LARGE_INTEGER EndOfFile;
  4574. ULONG NumberOfLinks;
  4575. BOOLEAN DeletePending;
  4576. BOOLEAN Directory;
  4577. } FILE_STANDARD_INFORMATION, *PFILE_STANDARD_INFORMATION;
  4578. typedef struct _FILE_POSITION_INFORMATION {
  4579. LARGE_INTEGER CurrentByteOffset;
  4580. } FILE_POSITION_INFORMATION, *PFILE_POSITION_INFORMATION;
  4581. typedef struct _FILE_ALIGNMENT_INFORMATION {
  4582. ULONG AlignmentRequirement;
  4583. } FILE_ALIGNMENT_INFORMATION, *PFILE_ALIGNMENT_INFORMATION;
  4584. typedef struct _FILE_NAME_INFORMATION {
  4585. ULONG FileNameLength;
  4586. WCHAR FileName[1];
  4587. } FILE_NAME_INFORMATION, *PFILE_NAME_INFORMATION;
  4588. typedef struct _FILE_NETWORK_OPEN_INFORMATION {
  4589. LARGE_INTEGER CreationTime;
  4590. LARGE_INTEGER LastAccessTime;
  4591. LARGE_INTEGER LastWriteTime;
  4592. LARGE_INTEGER ChangeTime;
  4593. LARGE_INTEGER AllocationSize;
  4594. LARGE_INTEGER EndOfFile;
  4595. ULONG FileAttributes;
  4596. } FILE_NETWORK_OPEN_INFORMATION, *PFILE_NETWORK_OPEN_INFORMATION;
  4597. typedef struct _FILE_ATTRIBUTE_TAG_INFORMATION {
  4598. ULONG FileAttributes;
  4599. ULONG ReparseTag;
  4600. } FILE_ATTRIBUTE_TAG_INFORMATION, *PFILE_ATTRIBUTE_TAG_INFORMATION;
  4601. typedef struct _FILE_DISPOSITION_INFORMATION {
  4602. BOOLEAN DeleteFile;
  4603. } FILE_DISPOSITION_INFORMATION, *PFILE_DISPOSITION_INFORMATION;
  4604. typedef struct _FILE_END_OF_FILE_INFORMATION {
  4605. LARGE_INTEGER EndOfFile;
  4606. } FILE_END_OF_FILE_INFORMATION, *PFILE_END_OF_FILE_INFORMATION;
  4607. typedef struct _FILE_VALID_DATA_LENGTH_INFORMATION {
  4608. LARGE_INTEGER ValidDataLength;
  4609. } FILE_VALID_DATA_LENGTH_INFORMATION, *PFILE_VALID_DATA_LENGTH_INFORMATION;
  4610. typedef struct _FILE_FULL_EA_INFORMATION {
  4611. ULONG NextEntryOffset;
  4612. UCHAR Flags;
  4613. UCHAR EaNameLength;
  4614. USHORT EaValueLength;
  4615. CHAR EaName[1];
  4616. } FILE_FULL_EA_INFORMATION, *PFILE_FULL_EA_INFORMATION;
  4617. //
  4618. // Define the file system information class values
  4619. //
  4620. // WARNING: The order of the following values are assumed by the I/O system.
  4621. // Any changes made here should be reflected there as well.
  4622. typedef enum _FSINFOCLASS {
  4623. FileFsVolumeInformation = 1,
  4624. FileFsLabelInformation, // 2
  4625. FileFsSizeInformation, // 3
  4626. FileFsDeviceInformation, // 4
  4627. FileFsAttributeInformation, // 5
  4628. FileFsControlInformation, // 6
  4629. FileFsFullSizeInformation, // 7
  4630. FileFsObjectIdInformation, // 8
  4631. FileFsDriverPathInformation, // 9
  4632. FileFsMaximumInformation
  4633. } FS_INFORMATION_CLASS, *PFS_INFORMATION_CLASS;
  4634. typedef struct _FILE_FS_DEVICE_INFORMATION {
  4635. DEVICE_TYPE DeviceType;
  4636. ULONG Characteristics;
  4637. } FILE_FS_DEVICE_INFORMATION, *PFILE_FS_DEVICE_INFORMATION;
  4638. //
  4639. // Define segement buffer structure for scatter/gather read/write.
  4640. //
  4641. typedef union _FILE_SEGMENT_ELEMENT {
  4642. PVOID64 Buffer;
  4643. ULONGLONG Alignment;
  4644. }FILE_SEGMENT_ELEMENT, *PFILE_SEGMENT_ELEMENT;
  4645. //
  4646. // Define the I/O bus interface types.
  4647. //
  4648. typedef enum _INTERFACE_TYPE {
  4649. InterfaceTypeUndefined = -1,
  4650. Internal,
  4651. Isa,
  4652. Eisa,
  4653. MicroChannel,
  4654. TurboChannel,
  4655. PCIBus,
  4656. VMEBus,
  4657. NuBus,
  4658. PCMCIABus,
  4659. CBus,
  4660. MPIBus,
  4661. MPSABus,
  4662. ProcessorInternal,
  4663. InternalPowerBus,
  4664. PNPISABus,
  4665. PNPBus,
  4666. MaximumInterfaceType
  4667. }INTERFACE_TYPE, *PINTERFACE_TYPE;
  4668. //
  4669. // Define the DMA transfer widths.
  4670. //
  4671. typedef enum _DMA_WIDTH {
  4672. Width8Bits,
  4673. Width16Bits,
  4674. Width32Bits,
  4675. MaximumDmaWidth
  4676. }DMA_WIDTH, *PDMA_WIDTH;
  4677. //
  4678. // Define DMA transfer speeds.
  4679. //
  4680. typedef enum _DMA_SPEED {
  4681. Compatible,
  4682. TypeA,
  4683. TypeB,
  4684. TypeC,
  4685. TypeF,
  4686. MaximumDmaSpeed
  4687. }DMA_SPEED, *PDMA_SPEED;
  4688. //
  4689. // Define Interface reference/dereference routines for
  4690. // Interfaces exported by IRP_MN_QUERY_INTERFACE
  4691. //
  4692. typedef VOID (*PINTERFACE_REFERENCE)(PVOID Context);
  4693. typedef VOID (*PINTERFACE_DEREFERENCE)(PVOID Context);
  4694. //
  4695. // Define types of bus information.
  4696. //
  4697. typedef enum _BUS_DATA_TYPE {
  4698. ConfigurationSpaceUndefined = -1,
  4699. Cmos,
  4700. EisaConfiguration,
  4701. Pos,
  4702. CbusConfiguration,
  4703. PCIConfiguration,
  4704. VMEConfiguration,
  4705. NuBusConfiguration,
  4706. PCMCIAConfiguration,
  4707. MPIConfiguration,
  4708. MPSAConfiguration,
  4709. PNPISAConfiguration,
  4710. SgiInternalConfiguration,
  4711. MaximumBusDataType
  4712. } BUS_DATA_TYPE, *PBUS_DATA_TYPE;
  4713. //
  4714. // Define I/O Driver error log packet structure. This structure is filled in
  4715. // by the driver.
  4716. //
  4717. typedef struct _IO_ERROR_LOG_PACKET {
  4718. UCHAR MajorFunctionCode;
  4719. UCHAR RetryCount;
  4720. USHORT DumpDataSize;
  4721. USHORT NumberOfStrings;
  4722. USHORT StringOffset;
  4723. USHORT EventCategory;
  4724. NTSTATUS ErrorCode;
  4725. ULONG UniqueErrorValue;
  4726. NTSTATUS FinalStatus;
  4727. ULONG SequenceNumber;
  4728. ULONG IoControlCode;
  4729. LARGE_INTEGER DeviceOffset;
  4730. ULONG DumpData[1];
  4731. }IO_ERROR_LOG_PACKET, *PIO_ERROR_LOG_PACKET;
  4732. //
  4733. // Define the I/O error log message. This message is sent by the error log
  4734. // thread over the lpc port.
  4735. //
  4736. typedef struct _IO_ERROR_LOG_MESSAGE {
  4737. USHORT Type;
  4738. USHORT Size;
  4739. USHORT DriverNameLength;
  4740. LARGE_INTEGER TimeStamp;
  4741. ULONG DriverNameOffset;
  4742. IO_ERROR_LOG_PACKET EntryData;
  4743. }IO_ERROR_LOG_MESSAGE, *PIO_ERROR_LOG_MESSAGE;
  4744. //
  4745. // Define the maximum message size that will be sent over the LPC to the
  4746. // application reading the error log entries.
  4747. //
  4748. //
  4749. // Regardless of LPC size restrictions, ERROR_LOG_MAXIMUM_SIZE must remain
  4750. // a value that can fit in a UCHAR.
  4751. //
  4752. #define ERROR_LOG_LIMIT_SIZE (256-16)
  4753. //
  4754. // This limit, exclusive of IO_ERROR_LOG_MESSAGE_HEADER_LENGTH, also applies
  4755. // to IO_ERROR_LOG_MESSAGE_LENGTH
  4756. //
  4757. #define IO_ERROR_LOG_MESSAGE_HEADER_LENGTH (sizeof(IO_ERROR_LOG_MESSAGE) - \
  4758. sizeof(IO_ERROR_LOG_PACKET) + \
  4759. (sizeof(WCHAR) * 40))
  4760. #define ERROR_LOG_MESSAGE_LIMIT_SIZE \
  4761. (ERROR_LOG_LIMIT_SIZE + IO_ERROR_LOG_MESSAGE_HEADER_LENGTH)
  4762. //
  4763. // IO_ERROR_LOG_MESSAGE_LENGTH is
  4764. // min(PORT_MAXIMUM_MESSAGE_LENGTH, ERROR_LOG_MESSAGE_LIMIT_SIZE)
  4765. //
  4766. #define IO_ERROR_LOG_MESSAGE_LENGTH \
  4767. ((PORT_MAXIMUM_MESSAGE_LENGTH > ERROR_LOG_MESSAGE_LIMIT_SIZE) ? \
  4768. ERROR_LOG_MESSAGE_LIMIT_SIZE : \
  4769. PORT_MAXIMUM_MESSAGE_LENGTH)
  4770. //
  4771. // Define the maximum packet size a driver can allocate.
  4772. //
  4773. #define ERROR_LOG_MAXIMUM_SIZE (IO_ERROR_LOG_MESSAGE_LENGTH - \
  4774. IO_ERROR_LOG_MESSAGE_HEADER_LENGTH)
  4775. #ifdef _WIN64
  4776. #define PORT_MAXIMUM_MESSAGE_LENGTH 512
  4777. #else
  4778. #define PORT_MAXIMUM_MESSAGE_LENGTH 256
  4779. #endif
  4780. //
  4781. // Registry Specific Access Rights.
  4782. //
  4783. #define KEY_QUERY_VALUE (0x0001)
  4784. #define KEY_SET_VALUE (0x0002)
  4785. #define KEY_CREATE_SUB_KEY (0x0004)
  4786. #define KEY_ENUMERATE_SUB_KEYS (0x0008)
  4787. #define KEY_NOTIFY (0x0010)
  4788. #define KEY_CREATE_LINK (0x0020)
  4789. #define KEY_WOW64_32KEY (0x0200)
  4790. #define KEY_WOW64_64KEY (0x0100)
  4791. #define KEY_WOW64_RES (0x0300)
  4792. #define KEY_READ ((STANDARD_RIGHTS_READ |\
  4793. KEY_QUERY_VALUE |\
  4794. KEY_ENUMERATE_SUB_KEYS |\
  4795. KEY_NOTIFY) \
  4796. & \
  4797. (~SYNCHRONIZE))
  4798. #define KEY_WRITE ((STANDARD_RIGHTS_WRITE |\
  4799. KEY_SET_VALUE |\
  4800. KEY_CREATE_SUB_KEY) \
  4801. & \
  4802. (~SYNCHRONIZE))
  4803. #define KEY_EXECUTE ((KEY_READ) \
  4804. & \
  4805. (~SYNCHRONIZE))
  4806. #define KEY_ALL_ACCESS ((STANDARD_RIGHTS_ALL |\
  4807. KEY_QUERY_VALUE |\
  4808. KEY_SET_VALUE |\
  4809. KEY_CREATE_SUB_KEY |\
  4810. KEY_ENUMERATE_SUB_KEYS |\
  4811. KEY_NOTIFY |\
  4812. KEY_CREATE_LINK) \
  4813. & \
  4814. (~SYNCHRONIZE))
  4815. //
  4816. // Open/Create Options
  4817. //
  4818. #define REG_OPTION_RESERVED (0x00000000L) // Parameter is reserved
  4819. #define REG_OPTION_NON_VOLATILE (0x00000000L) // Key is preserved
  4820. // when system is rebooted
  4821. #define REG_OPTION_VOLATILE (0x00000001L) // Key is not preserved
  4822. // when system is rebooted
  4823. #define REG_OPTION_CREATE_LINK (0x00000002L) // Created key is a
  4824. // symbolic link
  4825. #define REG_OPTION_BACKUP_RESTORE (0x00000004L) // open for backup or restore
  4826. // special access rules
  4827. // privilege required
  4828. #define REG_OPTION_OPEN_LINK (0x00000008L) // Open symbolic link
  4829. #define REG_LEGAL_OPTION \
  4830. (REG_OPTION_RESERVED |\
  4831. REG_OPTION_NON_VOLATILE |\
  4832. REG_OPTION_VOLATILE |\
  4833. REG_OPTION_CREATE_LINK |\
  4834. REG_OPTION_BACKUP_RESTORE |\
  4835. REG_OPTION_OPEN_LINK)
  4836. //
  4837. // Key creation/open disposition
  4838. //
  4839. #define REG_CREATED_NEW_KEY (0x00000001L) // New Registry Key created
  4840. #define REG_OPENED_EXISTING_KEY (0x00000002L) // Existing Key opened
  4841. //
  4842. // hive format to be used by Reg(Nt)SaveKeyEx
  4843. //
  4844. #define REG_STANDARD_FORMAT 1
  4845. #define REG_LATEST_FORMAT 2
  4846. #define REG_NO_COMPRESSION 4
  4847. //
  4848. // Key restore flags
  4849. //
  4850. #define REG_WHOLE_HIVE_VOLATILE (0x00000001L) // Restore whole hive volatile
  4851. #define REG_REFRESH_HIVE (0x00000002L) // Unwind changes to last flush
  4852. #define REG_NO_LAZY_FLUSH (0x00000004L) // Never lazy flush this hive
  4853. #define REG_FORCE_RESTORE (0x00000008L) // Force the restore process even when we have open handles on subkeys
  4854. //
  4855. // Unload Flags
  4856. //
  4857. #define REG_FORCE_UNLOAD 1
  4858. //
  4859. // Key query structures
  4860. //
  4861. typedef struct _KEY_BASIC_INFORMATION {
  4862. LARGE_INTEGER LastWriteTime;
  4863. ULONG TitleIndex;
  4864. ULONG NameLength;
  4865. WCHAR Name[1]; // Variable length string
  4866. } KEY_BASIC_INFORMATION, *PKEY_BASIC_INFORMATION;
  4867. typedef struct _KEY_NODE_INFORMATION {
  4868. LARGE_INTEGER LastWriteTime;
  4869. ULONG TitleIndex;
  4870. ULONG ClassOffset;
  4871. ULONG ClassLength;
  4872. ULONG NameLength;
  4873. WCHAR Name[1]; // Variable length string
  4874. // Class[1]; // Variable length string not declared
  4875. } KEY_NODE_INFORMATION, *PKEY_NODE_INFORMATION;
  4876. typedef struct _KEY_FULL_INFORMATION {
  4877. LARGE_INTEGER LastWriteTime;
  4878. ULONG TitleIndex;
  4879. ULONG ClassOffset;
  4880. ULONG ClassLength;
  4881. ULONG SubKeys;
  4882. ULONG MaxNameLen;
  4883. ULONG MaxClassLen;
  4884. ULONG Values;
  4885. ULONG MaxValueNameLen;
  4886. ULONG MaxValueDataLen;
  4887. WCHAR Class[1]; // Variable length
  4888. } KEY_FULL_INFORMATION, *PKEY_FULL_INFORMATION;
  4889. typedef struct _KEY_NAME_INFORMATION {
  4890. ULONG NameLength;
  4891. WCHAR Name[1]; // Variable length string
  4892. } KEY_NAME_INFORMATION, *PKEY_NAME_INFORMATION;
  4893. typedef struct _KEY_CACHED_INFORMATION {
  4894. LARGE_INTEGER LastWriteTime;
  4895. ULONG TitleIndex;
  4896. ULONG SubKeys;
  4897. ULONG MaxNameLen;
  4898. ULONG Values;
  4899. ULONG MaxValueNameLen;
  4900. ULONG MaxValueDataLen;
  4901. ULONG NameLength;
  4902. WCHAR Name[1]; // Variable length string
  4903. } KEY_CACHED_INFORMATION, *PKEY_CACHED_INFORMATION;
  4904. typedef struct _KEY_FLAGS_INFORMATION {
  4905. ULONG UserFlags;
  4906. } KEY_FLAGS_INFORMATION, *PKEY_FLAGS_INFORMATION;
  4907. typedef enum _KEY_INFORMATION_CLASS {
  4908. KeyBasicInformation,
  4909. KeyNodeInformation,
  4910. KeyFullInformation
  4911. ,
  4912. KeyNameInformation,
  4913. KeyCachedInformation,
  4914. KeyFlagsInformation,
  4915. MaxKeyInfoClass // MaxKeyInfoClass should always be the last enum
  4916. } KEY_INFORMATION_CLASS;
  4917. typedef struct _KEY_WRITE_TIME_INFORMATION {
  4918. LARGE_INTEGER LastWriteTime;
  4919. } KEY_WRITE_TIME_INFORMATION, *PKEY_WRITE_TIME_INFORMATION;
  4920. typedef struct _KEY_USER_FLAGS_INFORMATION {
  4921. ULONG UserFlags;
  4922. } KEY_USER_FLAGS_INFORMATION, *PKEY_USER_FLAGS_INFORMATION;
  4923. typedef enum _KEY_SET_INFORMATION_CLASS {
  4924. KeyWriteTimeInformation,
  4925. KeyUserFlagsInformation,
  4926. MaxKeySetInfoClass // MaxKeySetInfoClass should always be the last enum
  4927. } KEY_SET_INFORMATION_CLASS;
  4928. //
  4929. // Value entry query structures
  4930. //
  4931. typedef struct _KEY_VALUE_BASIC_INFORMATION {
  4932. ULONG TitleIndex;
  4933. ULONG Type;
  4934. ULONG NameLength;
  4935. WCHAR Name[1]; // Variable size
  4936. } KEY_VALUE_BASIC_INFORMATION, *PKEY_VALUE_BASIC_INFORMATION;
  4937. typedef struct _KEY_VALUE_FULL_INFORMATION {
  4938. ULONG TitleIndex;
  4939. ULONG Type;
  4940. ULONG DataOffset;
  4941. ULONG DataLength;
  4942. ULONG NameLength;
  4943. WCHAR Name[1]; // Variable size
  4944. // Data[1]; // Variable size data not declared
  4945. } KEY_VALUE_FULL_INFORMATION, *PKEY_VALUE_FULL_INFORMATION;
  4946. typedef struct _KEY_VALUE_PARTIAL_INFORMATION {
  4947. ULONG TitleIndex;
  4948. ULONG Type;
  4949. ULONG DataLength;
  4950. UCHAR Data[1]; // Variable size
  4951. } KEY_VALUE_PARTIAL_INFORMATION, *PKEY_VALUE_PARTIAL_INFORMATION;
  4952. typedef struct _KEY_VALUE_PARTIAL_INFORMATION_ALIGN64 {
  4953. ULONG Type;
  4954. ULONG DataLength;
  4955. UCHAR Data[1]; // Variable size
  4956. } KEY_VALUE_PARTIAL_INFORMATION_ALIGN64, *PKEY_VALUE_PARTIAL_INFORMATION_ALIGN64;
  4957. typedef struct _KEY_VALUE_ENTRY {
  4958. PUNICODE_STRING ValueName;
  4959. ULONG DataLength;
  4960. ULONG DataOffset;
  4961. ULONG Type;
  4962. } KEY_VALUE_ENTRY, *PKEY_VALUE_ENTRY;
  4963. typedef enum _KEY_VALUE_INFORMATION_CLASS {
  4964. KeyValueBasicInformation,
  4965. KeyValueFullInformation,
  4966. KeyValuePartialInformation,
  4967. KeyValueFullInformationAlign64,
  4968. KeyValuePartialInformationAlign64,
  4969. MaxKeyValueInfoClass // MaxKeyValueInfoClass should always be the last enum
  4970. } KEY_VALUE_INFORMATION_CLASS;
  4971. #define OBJ_NAME_PATH_SEPARATOR ((WCHAR)L'\\')
  4972. //
  4973. // Object Manager Object Type Specific Access Rights.
  4974. //
  4975. #define OBJECT_TYPE_CREATE (0x0001)
  4976. #define OBJECT_TYPE_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | 0x1)
  4977. //
  4978. // Object Manager Directory Specific Access Rights.
  4979. //
  4980. #define DIRECTORY_QUERY (0x0001)
  4981. #define DIRECTORY_TRAVERSE (0x0002)
  4982. #define DIRECTORY_CREATE_OBJECT (0x0004)
  4983. #define DIRECTORY_CREATE_SUBDIRECTORY (0x0008)
  4984. #define DIRECTORY_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | 0xF)
  4985. //
  4986. // Object Manager Symbolic Link Specific Access Rights.
  4987. //
  4988. #define SYMBOLIC_LINK_QUERY (0x0001)
  4989. #define SYMBOLIC_LINK_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | 0x1)
  4990. typedef struct _OBJECT_NAME_INFORMATION {
  4991. UNICODE_STRING Name;
  4992. } OBJECT_NAME_INFORMATION, *POBJECT_NAME_INFORMATION;
  4993. #define DUPLICATE_CLOSE_SOURCE 0x00000001
  4994. #define DUPLICATE_SAME_ACCESS 0x00000002
  4995. #define DUPLICATE_SAME_ATTRIBUTES 0x00000004
  4996. //
  4997. // Section Information Structures.
  4998. //
  4999. typedef enum _SECTION_INHERIT {
  5000. ViewShare = 1,
  5001. ViewUnmap = 2
  5002. } SECTION_INHERIT;
  5003. //
  5004. // Section Access Rights.
  5005. //
  5006. #define SECTION_QUERY 0x0001
  5007. #define SECTION_MAP_WRITE 0x0002
  5008. #define SECTION_MAP_READ 0x0004
  5009. #define SECTION_MAP_EXECUTE 0x0008
  5010. #define SECTION_EXTEND_SIZE 0x0010
  5011. #define SECTION_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED|SECTION_QUERY|\
  5012. SECTION_MAP_WRITE | \
  5013. SECTION_MAP_READ | \
  5014. SECTION_MAP_EXECUTE | \
  5015. SECTION_EXTEND_SIZE)
  5016. #define SEGMENT_ALL_ACCESS SECTION_ALL_ACCESS
  5017. #define PAGE_NOACCESS 0x01
  5018. #define PAGE_READONLY 0x02
  5019. #define PAGE_READWRITE 0x04
  5020. #define PAGE_WRITECOPY 0x08
  5021. #define PAGE_EXECUTE 0x10
  5022. #define PAGE_EXECUTE_READ 0x20
  5023. #define PAGE_EXECUTE_READWRITE 0x40
  5024. #define PAGE_EXECUTE_WRITECOPY 0x80
  5025. #define PAGE_GUARD 0x100
  5026. #define PAGE_NOCACHE 0x200
  5027. #define PAGE_WRITECOMBINE 0x400
  5028. #define MEM_COMMIT 0x1000
  5029. #define MEM_RESERVE 0x2000
  5030. #define MEM_DECOMMIT 0x4000
  5031. #define MEM_RELEASE 0x8000
  5032. #define MEM_FREE 0x10000
  5033. #define MEM_PRIVATE 0x20000
  5034. #define MEM_MAPPED 0x40000
  5035. #define MEM_RESET 0x80000
  5036. #define MEM_TOP_DOWN 0x100000
  5037. #define MEM_LARGE_PAGES 0x20000000
  5038. #define MEM_4MB_PAGES 0x80000000
  5039. #define SEC_RESERVE 0x4000000
  5040. #define PROCESS_DUP_HANDLE (0x0040)
  5041. #define PROCESS_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | \
  5042. 0xFFF)
  5043. #if defined(_WIN64)
  5044. #define MAXIMUM_PROCESSORS 64
  5045. #else
  5046. #define MAXIMUM_PROCESSORS 32
  5047. #endif
  5048. //
  5049. // Thread Specific Access Rights
  5050. //
  5051. #define THREAD_TERMINATE (0x0001)
  5052. #define THREAD_SET_INFORMATION (0x0020)
  5053. #define THREAD_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | \
  5054. 0x3FF)
  5055. //
  5056. // ClientId
  5057. //
  5058. typedef struct _CLIENT_ID {
  5059. HANDLE UniqueProcess;
  5060. HANDLE UniqueThread;
  5061. } CLIENT_ID;
  5062. typedef CLIENT_ID *PCLIENT_ID;
  5063. //
  5064. // Thread Environment Block (and portable part of Thread Information Block)
  5065. //
  5066. //
  5067. // NT_TIB - Thread Information Block - Portable part.
  5068. //
  5069. // This is the subsystem portable part of the Thread Information Block.
  5070. // It appears as the first part of the TEB for all threads which have
  5071. // a user mode component.
  5072. //
  5073. //
  5074. typedef struct _NT_TIB {
  5075. struct _EXCEPTION_REGISTRATION_RECORD *ExceptionList;
  5076. PVOID StackBase;
  5077. PVOID StackLimit;
  5078. PVOID SubSystemTib;
  5079. union {
  5080. PVOID FiberData;
  5081. ULONG Version;
  5082. };
  5083. PVOID ArbitraryUserPointer;
  5084. struct _NT_TIB *Self;
  5085. } NT_TIB;
  5086. typedef NT_TIB *PNT_TIB;
  5087. //
  5088. // 32 and 64 bit specific version for wow64 and the debugger
  5089. //
  5090. typedef struct _NT_TIB32 {
  5091. ULONG ExceptionList;
  5092. ULONG StackBase;
  5093. ULONG StackLimit;
  5094. ULONG SubSystemTib;
  5095. union {
  5096. ULONG FiberData;
  5097. ULONG Version;
  5098. };
  5099. ULONG ArbitraryUserPointer;
  5100. ULONG Self;
  5101. } NT_TIB32, *PNT_TIB32;
  5102. typedef struct _NT_TIB64 {
  5103. ULONG64 ExceptionList;
  5104. ULONG64 StackBase;
  5105. ULONG64 StackLimit;
  5106. ULONG64 SubSystemTib;
  5107. union {
  5108. ULONG64 FiberData;
  5109. ULONG Version;
  5110. };
  5111. ULONG64 ArbitraryUserPointer;
  5112. ULONG64 Self;
  5113. } NT_TIB64, *PNT_TIB64;
  5114. //
  5115. // Process Information Classes
  5116. //
  5117. typedef enum _PROCESSINFOCLASS {
  5118. ProcessBasicInformation,
  5119. ProcessQuotaLimits,
  5120. ProcessIoCounters,
  5121. ProcessVmCounters,
  5122. ProcessTimes,
  5123. ProcessBasePriority,
  5124. ProcessRaisePriority,
  5125. ProcessDebugPort,
  5126. ProcessExceptionPort,
  5127. ProcessAccessToken,
  5128. ProcessLdtInformation,
  5129. ProcessLdtSize,
  5130. ProcessDefaultHardErrorMode,
  5131. ProcessIoPortHandlers, // Note: this is kernel mode only
  5132. ProcessPooledUsageAndLimits,
  5133. ProcessWorkingSetWatch,
  5134. ProcessUserModeIOPL,
  5135. ProcessEnableAlignmentFaultFixup,
  5136. ProcessPriorityClass,
  5137. ProcessWx86Information,
  5138. ProcessHandleCount,
  5139. ProcessAffinityMask,
  5140. ProcessPriorityBoost,
  5141. ProcessDeviceMap,
  5142. ProcessSessionInformation,
  5143. ProcessForegroundInformation,
  5144. ProcessWow64Information,
  5145. ProcessImageFileName,
  5146. ProcessLUIDDeviceMapsEnabled,
  5147. ProcessBreakOnTermination,
  5148. ProcessDebugObjectHandle,
  5149. ProcessDebugFlags,
  5150. ProcessHandleTracing,
  5151. MaxProcessInfoClass // MaxProcessInfoClass should always be the last enum
  5152. } PROCESSINFOCLASS;
  5153. //
  5154. // Thread Information Classes
  5155. //
  5156. typedef enum _THREADINFOCLASS {
  5157. ThreadBasicInformation,
  5158. ThreadTimes,
  5159. ThreadPriority,
  5160. ThreadBasePriority,
  5161. ThreadAffinityMask,
  5162. ThreadImpersonationToken,
  5163. ThreadDescriptorTableEntry,
  5164. ThreadEnableAlignmentFaultFixup,
  5165. ThreadEventPair_Reusable,
  5166. ThreadQuerySetWin32StartAddress,
  5167. ThreadZeroTlsCell,
  5168. ThreadPerformanceCount,
  5169. ThreadAmILastThread,
  5170. ThreadIdealProcessor,
  5171. ThreadPriorityBoost,
  5172. ThreadSetTlsArrayAddress,
  5173. ThreadIsIoPending,
  5174. ThreadHideFromDebugger,
  5175. ThreadBreakOnTermination,
  5176. MaxThreadInfoClass
  5177. } THREADINFOCLASS;
  5178. //
  5179. // Process Information Structures
  5180. //
  5181. //
  5182. // PageFaultHistory Information
  5183. // NtQueryInformationProcess using ProcessWorkingSetWatch
  5184. //
  5185. typedef struct _PROCESS_WS_WATCH_INFORMATION {
  5186. PVOID FaultingPc;
  5187. PVOID FaultingVa;
  5188. } PROCESS_WS_WATCH_INFORMATION, *PPROCESS_WS_WATCH_INFORMATION;
  5189. //
  5190. // Basic Process Information
  5191. // NtQueryInformationProcess using ProcessBasicInfo
  5192. //
  5193. typedef struct _PROCESS_BASIC_INFORMATION {
  5194. NTSTATUS ExitStatus;
  5195. PPEB PebBaseAddress;
  5196. ULONG_PTR AffinityMask;
  5197. KPRIORITY BasePriority;
  5198. ULONG_PTR UniqueProcessId;
  5199. ULONG_PTR InheritedFromUniqueProcessId;
  5200. } PROCESS_BASIC_INFORMATION;
  5201. typedef PROCESS_BASIC_INFORMATION *PPROCESS_BASIC_INFORMATION;
  5202. //
  5203. // Process Device Map information
  5204. // NtQueryInformationProcess using ProcessDeviceMap
  5205. // NtSetInformationProcess using ProcessDeviceMap
  5206. //
  5207. typedef struct _PROCESS_DEVICEMAP_INFORMATION {
  5208. union {
  5209. struct {
  5210. HANDLE DirectoryHandle;
  5211. } Set;
  5212. struct {
  5213. ULONG DriveMap;
  5214. UCHAR DriveType[ 32 ];
  5215. } Query;
  5216. };
  5217. } PROCESS_DEVICEMAP_INFORMATION, *PPROCESS_DEVICEMAP_INFORMATION;
  5218. typedef struct _PROCESS_DEVICEMAP_INFORMATION_EX {
  5219. union {
  5220. struct {
  5221. HANDLE DirectoryHandle;
  5222. } Set;
  5223. struct {
  5224. ULONG DriveMap;
  5225. UCHAR DriveType[ 32 ];
  5226. } Query;
  5227. };
  5228. ULONG Flags; // specifies that the query type
  5229. } PROCESS_DEVICEMAP_INFORMATION_EX, *PPROCESS_DEVICEMAP_INFORMATION_EX;
  5230. //
  5231. // PROCESS_DEVICEMAP_INFORMATION_EX flags
  5232. //
  5233. #define PROCESS_LUID_DOSDEVICES_ONLY 0x00000001
  5234. //
  5235. // Multi-User Session specific Process Information
  5236. // NtQueryInformationProcess using ProcessSessionInformation
  5237. //
  5238. typedef struct _PROCESS_SESSION_INFORMATION {
  5239. ULONG SessionId;
  5240. } PROCESS_SESSION_INFORMATION, *PPROCESS_SESSION_INFORMATION;
  5241. typedef struct _PROCESS_HANDLE_TRACING_ENABLE {
  5242. ULONG Flags;
  5243. } PROCESS_HANDLE_TRACING_ENABLE, *PPROCESS_HANDLE_TRACING_ENABLE;
  5244. typedef struct _PROCESS_HANDLE_TRACING_ENABLE_EX {
  5245. ULONG Flags;
  5246. ULONG TotalSlots;
  5247. } PROCESS_HANDLE_TRACING_ENABLE_EX, *PPROCESS_HANDLE_TRACING_ENABLE_EX;
  5248. #define PROCESS_HANDLE_TRACING_MAX_STACKS 16
  5249. typedef struct _PROCESS_HANDLE_TRACING_ENTRY {
  5250. HANDLE Handle;
  5251. CLIENT_ID ClientId;
  5252. ULONG Type;
  5253. PVOID Stacks[PROCESS_HANDLE_TRACING_MAX_STACKS];
  5254. } PROCESS_HANDLE_TRACING_ENTRY, *PPROCESS_HANDLE_TRACING_ENTRY;
  5255. typedef struct _PROCESS_HANDLE_TRACING_QUERY {
  5256. HANDLE Handle;
  5257. ULONG TotalTraces;
  5258. PROCESS_HANDLE_TRACING_ENTRY HandleTrace[1];
  5259. } PROCESS_HANDLE_TRACING_QUERY, *PPROCESS_HANDLE_TRACING_QUERY;
  5260. //
  5261. // Process Quotas
  5262. // NtQueryInformationProcess using ProcessQuotaLimits
  5263. // NtQueryInformationProcess using ProcessPooledQuotaLimits
  5264. // NtSetInformationProcess using ProcessQuotaLimits
  5265. //
  5266. typedef struct _QUOTA_LIMITS {
  5267. SIZE_T PagedPoolLimit;
  5268. SIZE_T NonPagedPoolLimit;
  5269. SIZE_T MinimumWorkingSetSize;
  5270. SIZE_T MaximumWorkingSetSize;
  5271. SIZE_T PagefileLimit;
  5272. LARGE_INTEGER TimeLimit;
  5273. } QUOTA_LIMITS, *PQUOTA_LIMITS;
  5274. #define QUOTA_LIMITS_HARDWS_MIN_ENABLE 0x00000001
  5275. #define QUOTA_LIMITS_HARDWS_MIN_DISABLE 0x00000002
  5276. #define QUOTA_LIMITS_HARDWS_MAX_ENABLE 0x00000004
  5277. #define QUOTA_LIMITS_HARDWS_MAX_DISABLE 0x00000008
  5278. typedef struct _QUOTA_LIMITS_EX {
  5279. SIZE_T PagedPoolLimit;
  5280. SIZE_T NonPagedPoolLimit;
  5281. SIZE_T MinimumWorkingSetSize;
  5282. SIZE_T MaximumWorkingSetSize;
  5283. SIZE_T PagefileLimit;
  5284. LARGE_INTEGER TimeLimit;
  5285. SIZE_T Reserved1;
  5286. SIZE_T Reserved2;
  5287. SIZE_T Reserved3;
  5288. SIZE_T Reserved4;
  5289. ULONG Flags;
  5290. ULONG Reserved5;
  5291. } QUOTA_LIMITS_EX, *PQUOTA_LIMITS_EX;
  5292. //
  5293. // Process I/O Counters
  5294. // NtQueryInformationProcess using ProcessIoCounters
  5295. //
  5296. typedef struct _IO_COUNTERS {
  5297. ULONGLONG ReadOperationCount;
  5298. ULONGLONG WriteOperationCount;
  5299. ULONGLONG OtherOperationCount;
  5300. ULONGLONG ReadTransferCount;
  5301. ULONGLONG WriteTransferCount;
  5302. ULONGLONG OtherTransferCount;
  5303. } IO_COUNTERS;
  5304. typedef IO_COUNTERS *PIO_COUNTERS;
  5305. //
  5306. // Process Virtual Memory Counters
  5307. // NtQueryInformationProcess using ProcessVmCounters
  5308. //
  5309. typedef struct _VM_COUNTERS {
  5310. SIZE_T PeakVirtualSize;
  5311. SIZE_T VirtualSize;
  5312. ULONG PageFaultCount;
  5313. SIZE_T PeakWorkingSetSize;
  5314. SIZE_T WorkingSetSize;
  5315. SIZE_T QuotaPeakPagedPoolUsage;
  5316. SIZE_T QuotaPagedPoolUsage;
  5317. SIZE_T QuotaPeakNonPagedPoolUsage;
  5318. SIZE_T QuotaNonPagedPoolUsage;
  5319. SIZE_T PagefileUsage;
  5320. SIZE_T PeakPagefileUsage;
  5321. } VM_COUNTERS;
  5322. typedef VM_COUNTERS *PVM_COUNTERS;
  5323. typedef struct _VM_COUNTERS_EX {
  5324. SIZE_T PeakVirtualSize;
  5325. SIZE_T VirtualSize;
  5326. ULONG PageFaultCount;
  5327. SIZE_T PeakWorkingSetSize;
  5328. SIZE_T WorkingSetSize;
  5329. SIZE_T QuotaPeakPagedPoolUsage;
  5330. SIZE_T QuotaPagedPoolUsage;
  5331. SIZE_T QuotaPeakNonPagedPoolUsage;
  5332. SIZE_T QuotaNonPagedPoolUsage;
  5333. SIZE_T PagefileUsage;
  5334. SIZE_T PeakPagefileUsage;
  5335. SIZE_T PrivateUsage;
  5336. } VM_COUNTERS_EX;
  5337. typedef VM_COUNTERS_EX *PVM_COUNTERS_EX;
  5338. //
  5339. // Process Pooled Quota Usage and Limits
  5340. // NtQueryInformationProcess using ProcessPooledUsageAndLimits
  5341. //
  5342. typedef struct _POOLED_USAGE_AND_LIMITS {
  5343. SIZE_T PeakPagedPoolUsage;
  5344. SIZE_T PagedPoolUsage;
  5345. SIZE_T PagedPoolLimit;
  5346. SIZE_T PeakNonPagedPoolUsage;
  5347. SIZE_T NonPagedPoolUsage;
  5348. SIZE_T NonPagedPoolLimit;
  5349. SIZE_T PeakPagefileUsage;
  5350. SIZE_T PagefileUsage;
  5351. SIZE_T PagefileLimit;
  5352. } POOLED_USAGE_AND_LIMITS;
  5353. typedef POOLED_USAGE_AND_LIMITS *PPOOLED_USAGE_AND_LIMITS;
  5354. //
  5355. // Process Security Context Information
  5356. // NtSetInformationProcess using ProcessAccessToken
  5357. // PROCESS_SET_ACCESS_TOKEN access to the process is needed
  5358. // to use this info level.
  5359. //
  5360. typedef struct _PROCESS_ACCESS_TOKEN {
  5361. //
  5362. // Handle to Primary token to assign to the process.
  5363. // TOKEN_ASSIGN_PRIMARY access to this token is needed.
  5364. //
  5365. HANDLE Token;
  5366. //
  5367. // Handle to the initial thread of the process.
  5368. // A process's access token can only be changed if the process has
  5369. // no threads or one thread. If the process has no threads, this
  5370. // field must be set to NULL. Otherwise, it must contain a handle
  5371. // open to the process's only thread. THREAD_QUERY_INFORMATION access
  5372. // is needed via this handle.
  5373. HANDLE Thread;
  5374. } PROCESS_ACCESS_TOKEN, *PPROCESS_ACCESS_TOKEN;
  5375. //
  5376. // Process/Thread System and User Time
  5377. // NtQueryInformationProcess using ProcessTimes
  5378. // NtQueryInformationThread using ThreadTimes
  5379. //
  5380. typedef struct _KERNEL_USER_TIMES {
  5381. LARGE_INTEGER CreateTime;
  5382. LARGE_INTEGER ExitTime;
  5383. LARGE_INTEGER KernelTime;
  5384. LARGE_INTEGER UserTime;
  5385. } KERNEL_USER_TIMES;
  5386. typedef KERNEL_USER_TIMES *PKERNEL_USER_TIMES;
  5387. NTSYSCALLAPI
  5388. NTSTATUS
  5389. NTAPI
  5390. NtOpenProcess (
  5391. OUT PHANDLE ProcessHandle,
  5392. IN ACCESS_MASK DesiredAccess,
  5393. IN POBJECT_ATTRIBUTES ObjectAttributes,
  5394. IN PCLIENT_ID ClientId OPTIONAL
  5395. );
  5396. #define NtCurrentProcess() ( (HANDLE)(LONG_PTR) -1 )
  5397. #define ZwCurrentProcess() NtCurrentProcess()
  5398. NTSYSCALLAPI
  5399. NTSTATUS
  5400. NTAPI
  5401. NtQueryInformationProcess(
  5402. IN HANDLE ProcessHandle,
  5403. IN PROCESSINFOCLASS ProcessInformationClass,
  5404. OUT PVOID ProcessInformation,
  5405. IN ULONG ProcessInformationLength,
  5406. OUT PULONG ReturnLength OPTIONAL
  5407. );
  5408. #define NtCurrentThread() ( (HANDLE)(LONG_PTR) -2 )
  5409. #define ZwCurrentThread() NtCurrentThread()
  5410. #ifndef _PO_DDK_
  5411. #define _PO_DDK_
  5412. typedef enum _SYSTEM_POWER_STATE {
  5413. PowerSystemUnspecified = 0,
  5414. PowerSystemWorking = 1,
  5415. PowerSystemSleeping1 = 2,
  5416. PowerSystemSleeping2 = 3,
  5417. PowerSystemSleeping3 = 4,
  5418. PowerSystemHibernate = 5,
  5419. PowerSystemShutdown = 6,
  5420. PowerSystemMaximum = 7
  5421. } SYSTEM_POWER_STATE, *PSYSTEM_POWER_STATE;
  5422. #define POWER_SYSTEM_MAXIMUM 7
  5423. typedef enum {
  5424. PowerActionNone = 0,
  5425. PowerActionReserved,
  5426. PowerActionSleep,
  5427. PowerActionHibernate,
  5428. PowerActionShutdown,
  5429. PowerActionShutdownReset,
  5430. PowerActionShutdownOff,
  5431. PowerActionWarmEject
  5432. } POWER_ACTION, *PPOWER_ACTION;
  5433. typedef enum _DEVICE_POWER_STATE {
  5434. PowerDeviceUnspecified = 0,
  5435. PowerDeviceD0,
  5436. PowerDeviceD1,
  5437. PowerDeviceD2,
  5438. PowerDeviceD3,
  5439. PowerDeviceMaximum
  5440. } DEVICE_POWER_STATE, *PDEVICE_POWER_STATE;
  5441. typedef union _POWER_STATE {
  5442. SYSTEM_POWER_STATE SystemState;
  5443. DEVICE_POWER_STATE DeviceState;
  5444. } POWER_STATE, *PPOWER_STATE;
  5445. typedef enum _POWER_STATE_TYPE {
  5446. SystemPowerState = 0,
  5447. DevicePowerState
  5448. } POWER_STATE_TYPE, *PPOWER_STATE_TYPE;
  5449. //
  5450. // Generic power related IOCTLs
  5451. //
  5452. #define IOCTL_QUERY_DEVICE_POWER_STATE \
  5453. CTL_CODE(FILE_DEVICE_BATTERY, 0x0, METHOD_BUFFERED, FILE_READ_ACCESS)
  5454. #define IOCTL_SET_DEVICE_WAKE \
  5455. CTL_CODE(FILE_DEVICE_BATTERY, 0x1, METHOD_BUFFERED, FILE_WRITE_ACCESS)
  5456. #define IOCTL_CANCEL_DEVICE_WAKE \
  5457. CTL_CODE(FILE_DEVICE_BATTERY, 0x2, METHOD_BUFFERED, FILE_WRITE_ACCESS)
  5458. //
  5459. // Defines for W32 interfaces
  5460. //
  5461. #define ES_SYSTEM_REQUIRED ((ULONG)0x00000001)
  5462. #define ES_DISPLAY_REQUIRED ((ULONG)0x00000002)
  5463. #define ES_USER_PRESENT ((ULONG)0x00000004)
  5464. #define ES_CONTINUOUS ((ULONG)0x80000000)
  5465. typedef ULONG EXECUTION_STATE;
  5466. typedef enum {
  5467. LT_DONT_CARE,
  5468. LT_LOWEST_LATENCY
  5469. } LATENCY_TIME;
  5470. typedef enum {
  5471. SystemPowerPolicyAc,
  5472. SystemPowerPolicyDc,
  5473. VerifySystemPolicyAc,
  5474. VerifySystemPolicyDc,
  5475. SystemPowerCapabilities,
  5476. SystemBatteryState,
  5477. SystemPowerStateHandler,
  5478. ProcessorStateHandler,
  5479. SystemPowerPolicyCurrent,
  5480. AdministratorPowerPolicy,
  5481. SystemReserveHiberFile,
  5482. ProcessorInformation,
  5483. SystemPowerInformation,
  5484. ProcessorStateHandler2,
  5485. LastWakeTime, // Compare with KeQueryInterruptTime()
  5486. LastSleepTime, // Compare with KeQueryInterruptTime()
  5487. SystemExecutionState,
  5488. SystemPowerStateNotifyHandler,
  5489. ProcessorPowerPolicyAc,
  5490. ProcessorPowerPolicyDc,
  5491. VerifyProcessorPowerPolicyAc,
  5492. VerifyProcessorPowerPolicyDc,
  5493. ProcessorPowerPolicyCurrent,
  5494. SystemPowerStateLogging,
  5495. SystemPowerLoggingEntry
  5496. } POWER_INFORMATION_LEVEL;
  5497. //
  5498. // System power manager capabilities
  5499. //
  5500. typedef struct {
  5501. ULONG Granularity;
  5502. ULONG Capacity;
  5503. } BATTERY_REPORTING_SCALE, *PBATTERY_REPORTING_SCALE;
  5504. #endif // !_PO_DDK_
  5505. #if defined(_X86_)
  5506. //
  5507. // Types to use to contain PFNs and their counts.
  5508. //
  5509. typedef ULONG PFN_COUNT;
  5510. typedef LONG SPFN_NUMBER, *PSPFN_NUMBER;
  5511. typedef ULONG PFN_NUMBER, *PPFN_NUMBER;
  5512. //
  5513. // Define maximum size of flush multiple TB request.
  5514. //
  5515. #define FLUSH_MULTIPLE_MAXIMUM 32
  5516. //
  5517. // Indicate that the i386 compiler supports the pragma textout construct.
  5518. //
  5519. #define ALLOC_PRAGMA 1
  5520. //
  5521. // Indicate that the i386 compiler supports the DATA_SEG("INIT") and
  5522. // DATA_SEG("PAGE") pragmas
  5523. //
  5524. #define ALLOC_DATA_PRAGMA 1
  5525. #define NORMAL_DISPATCH_LENGTH 106
  5526. #define DISPATCH_LENGTH NORMAL_DISPATCH_LENGTH
  5527. //
  5528. // Interrupt Request Level definitions
  5529. //
  5530. #define PASSIVE_LEVEL 0 // Passive release level
  5531. #define LOW_LEVEL 0 // Lowest interrupt level
  5532. #define APC_LEVEL 1 // APC interrupt level
  5533. #define DISPATCH_LEVEL 2 // Dispatcher level
  5534. #define PROFILE_LEVEL 27 // timer used for profiling.
  5535. #define CLOCK1_LEVEL 28 // Interval clock 1 level - Not used on x86
  5536. #define CLOCK2_LEVEL 28 // Interval clock 2 level
  5537. #define IPI_LEVEL 29 // Interprocessor interrupt level
  5538. #define POWER_LEVEL 30 // Power failure level
  5539. #define HIGH_LEVEL 31 // Highest interrupt level
  5540. #define SYNCH_LEVEL (IPI_LEVEL-2)
  5541. //
  5542. // I/O space read and write macros.
  5543. //
  5544. // These have to be actual functions on the 386, because we need
  5545. // to use assembler, but cannot return a value if we inline it.
  5546. //
  5547. // The READ/WRITE_REGISTER_* calls manipulate I/O registers in MEMORY space.
  5548. // (Use x86 move instructions, with LOCK prefix to force correct behavior
  5549. // w.r.t. caches and write buffers.)
  5550. //
  5551. // The READ/WRITE_PORT_* calls manipulate I/O registers in PORT space.
  5552. // (Use x86 in/out instructions.)
  5553. //
  5554. NTKERNELAPI
  5555. UCHAR
  5556. NTAPI
  5557. READ_REGISTER_UCHAR(
  5558. PUCHAR Register
  5559. );
  5560. NTKERNELAPI
  5561. USHORT
  5562. NTAPI
  5563. READ_REGISTER_USHORT(
  5564. PUSHORT Register
  5565. );
  5566. NTKERNELAPI
  5567. ULONG
  5568. NTAPI
  5569. READ_REGISTER_ULONG(
  5570. PULONG Register
  5571. );
  5572. NTKERNELAPI
  5573. VOID
  5574. NTAPI
  5575. READ_REGISTER_BUFFER_UCHAR(
  5576. PUCHAR Register,
  5577. PUCHAR Buffer,
  5578. ULONG Count
  5579. );
  5580. NTKERNELAPI
  5581. VOID
  5582. NTAPI
  5583. READ_REGISTER_BUFFER_USHORT(
  5584. PUSHORT Register,
  5585. PUSHORT Buffer,
  5586. ULONG Count
  5587. );
  5588. NTKERNELAPI
  5589. VOID
  5590. NTAPI
  5591. READ_REGISTER_BUFFER_ULONG(
  5592. PULONG Register,
  5593. PULONG Buffer,
  5594. ULONG Count
  5595. );
  5596. NTKERNELAPI
  5597. VOID
  5598. NTAPI
  5599. WRITE_REGISTER_UCHAR(
  5600. PUCHAR Register,
  5601. UCHAR Value
  5602. );
  5603. NTKERNELAPI
  5604. VOID
  5605. NTAPI
  5606. WRITE_REGISTER_USHORT(
  5607. PUSHORT Register,
  5608. USHORT Value
  5609. );
  5610. NTKERNELAPI
  5611. VOID
  5612. NTAPI
  5613. WRITE_REGISTER_ULONG(
  5614. PULONG Register,
  5615. ULONG Value
  5616. );
  5617. NTKERNELAPI
  5618. VOID
  5619. NTAPI
  5620. WRITE_REGISTER_BUFFER_UCHAR(
  5621. PUCHAR Register,
  5622. PUCHAR Buffer,
  5623. ULONG Count
  5624. );
  5625. NTKERNELAPI
  5626. VOID
  5627. NTAPI
  5628. WRITE_REGISTER_BUFFER_USHORT(
  5629. PUSHORT Register,
  5630. PUSHORT Buffer,
  5631. ULONG Count
  5632. );
  5633. NTKERNELAPI
  5634. VOID
  5635. NTAPI
  5636. WRITE_REGISTER_BUFFER_ULONG(
  5637. PULONG Register,
  5638. PULONG Buffer,
  5639. ULONG Count
  5640. );
  5641. NTHALAPI
  5642. UCHAR
  5643. NTAPI
  5644. READ_PORT_UCHAR(
  5645. PUCHAR Port
  5646. );
  5647. NTHALAPI
  5648. USHORT
  5649. NTAPI
  5650. READ_PORT_USHORT(
  5651. PUSHORT Port
  5652. );
  5653. NTHALAPI
  5654. ULONG
  5655. NTAPI
  5656. READ_PORT_ULONG(
  5657. PULONG Port
  5658. );
  5659. NTHALAPI
  5660. VOID
  5661. NTAPI
  5662. READ_PORT_BUFFER_UCHAR(
  5663. PUCHAR Port,
  5664. PUCHAR Buffer,
  5665. ULONG Count
  5666. );
  5667. NTHALAPI
  5668. VOID
  5669. NTAPI
  5670. READ_PORT_BUFFER_USHORT(
  5671. PUSHORT Port,
  5672. PUSHORT Buffer,
  5673. ULONG Count
  5674. );
  5675. NTHALAPI
  5676. VOID
  5677. NTAPI
  5678. READ_PORT_BUFFER_ULONG(
  5679. PULONG Port,
  5680. PULONG Buffer,
  5681. ULONG Count
  5682. );
  5683. NTHALAPI
  5684. VOID
  5685. NTAPI
  5686. WRITE_PORT_UCHAR(
  5687. PUCHAR Port,
  5688. UCHAR Value
  5689. );
  5690. NTHALAPI
  5691. VOID
  5692. NTAPI
  5693. WRITE_PORT_USHORT(
  5694. PUSHORT Port,
  5695. USHORT Value
  5696. );
  5697. NTHALAPI
  5698. VOID
  5699. NTAPI
  5700. WRITE_PORT_ULONG(
  5701. PULONG Port,
  5702. ULONG Value
  5703. );
  5704. NTHALAPI
  5705. VOID
  5706. NTAPI
  5707. WRITE_PORT_BUFFER_UCHAR(
  5708. PUCHAR Port,
  5709. PUCHAR Buffer,
  5710. ULONG Count
  5711. );
  5712. NTHALAPI
  5713. VOID
  5714. NTAPI
  5715. WRITE_PORT_BUFFER_USHORT(
  5716. PUSHORT Port,
  5717. PUSHORT Buffer,
  5718. ULONG Count
  5719. );
  5720. NTHALAPI
  5721. VOID
  5722. NTAPI
  5723. WRITE_PORT_BUFFER_ULONG(
  5724. PULONG Port,
  5725. PULONG Buffer,
  5726. ULONG Count
  5727. );
  5728. //
  5729. // Get data cache fill size.
  5730. //
  5731. #if PRAGMA_DEPRECATED_DDK
  5732. #pragma deprecated(KeGetDcacheFillSize) // Use GetDmaAlignment
  5733. #endif
  5734. #define KeGetDcacheFillSize() 1L
  5735. #define KeFlushIoBuffers(Mdl, ReadOperation, DmaOperation)
  5736. #define ExAcquireSpinLock(Lock, OldIrql) KeAcquireSpinLock((Lock), (OldIrql))
  5737. #define ExReleaseSpinLock(Lock, OldIrql) KeReleaseSpinLock((Lock), (OldIrql))
  5738. #define ExAcquireSpinLockAtDpcLevel(Lock) KeAcquireSpinLockAtDpcLevel(Lock)
  5739. #define ExReleaseSpinLockFromDpcLevel(Lock) KeReleaseSpinLockFromDpcLevel(Lock)
  5740. #if defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_)
  5741. #define KeQueryTickCount(CurrentCount ) { \
  5742. volatile PKSYSTEM_TIME _TickCount = *((PKSYSTEM_TIME *)(&KeTickCount)); \
  5743. while (TRUE) { \
  5744. (CurrentCount)->HighPart = _TickCount->High1Time; \
  5745. (CurrentCount)->LowPart = _TickCount->LowPart; \
  5746. if ((CurrentCount)->HighPart == _TickCount->High2Time) break; \
  5747. _asm { rep nop } \
  5748. } \
  5749. }
  5750. #else
  5751. VOID
  5752. NTAPI
  5753. KeQueryTickCount (
  5754. OUT PLARGE_INTEGER CurrentCount
  5755. );
  5756. #endif // defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_)
  5757. //
  5758. // Processor Control Region Structure Definition
  5759. //
  5760. #define PCR_MINOR_VERSION 1
  5761. #define PCR_MAJOR_VERSION 1
  5762. typedef struct _KPCR {
  5763. //
  5764. // Start of the architecturally defined section of the PCR. This section
  5765. // may be directly addressed by vendor/platform specific HAL code and will
  5766. // not change from version to version of NT.
  5767. //
  5768. // Certain fields in the TIB are not used in kernel mode. These include the
  5769. // stack limit, subsystem TIB, fiber data, arbitrary user pointer, and the
  5770. // self address of then PCR itself (another field has been added for that
  5771. // purpose). Therefore, these fields are overlaid with other data to get
  5772. // better cache locality.
  5773. //
  5774. union {
  5775. NT_TIB NtTib;
  5776. struct {
  5777. struct _EXCEPTION_REGISTRATION_RECORD *Used_ExceptionList;
  5778. PVOID Used_StackBase;
  5779. PVOID PerfGlobalGroupMask;
  5780. PVOID TssCopy;
  5781. ULONG ContextSwitches;
  5782. KAFFINITY SetMemberCopy;
  5783. PVOID Used_Self;
  5784. };
  5785. };
  5786. struct _KPCR *SelfPcr; // flat address of this PCR
  5787. struct _KPRCB *Prcb; // pointer to Prcb
  5788. KIRQL Irql; // do not use 3 bytes after this as
  5789. // HALs assume they are zero.
  5790. ULONG IRR;
  5791. ULONG IrrActive;
  5792. ULONG IDR;
  5793. PVOID KdVersionBlock;
  5794. struct _KIDTENTRY *IDT;
  5795. struct _KGDTENTRY *GDT;
  5796. struct _KTSS *TSS;
  5797. USHORT MajorVersion;
  5798. USHORT MinorVersion;
  5799. KAFFINITY SetMember;
  5800. ULONG StallScaleFactor;
  5801. UCHAR SpareUnused;
  5802. UCHAR Number;
  5803. } KPCR, *PKPCR;
  5804. //
  5805. // The non-volatile 387 state
  5806. //
  5807. typedef struct _KFLOATING_SAVE {
  5808. ULONG ControlWord;
  5809. ULONG StatusWord;
  5810. ULONG ErrorOffset;
  5811. ULONG ErrorSelector;
  5812. ULONG DataOffset; // Not used in wdm
  5813. ULONG DataSelector;
  5814. ULONG Cr0NpxState;
  5815. ULONG Spare1; // Not used in wdm
  5816. } KFLOATING_SAVE, *PKFLOATING_SAVE;
  5817. //
  5818. // i386 Specific portions of mm component
  5819. //
  5820. //
  5821. // Define the page size for the Intel 386 as 4096 (0x1000).
  5822. //
  5823. #define PAGE_SIZE 0x1000
  5824. //
  5825. // Define the number of trailing zeroes in a page aligned virtual address.
  5826. // This is used as the shift count when shifting virtual addresses to
  5827. // virtual page numbers.
  5828. //
  5829. #define PAGE_SHIFT 12L
  5830. //
  5831. // Define the number of bits to shift to right justify the Page Directory Index
  5832. // field of a PTE.
  5833. //
  5834. #define PDI_SHIFT_X86 22
  5835. #define PDI_SHIFT_X86PAE 21
  5836. #if !defined (_X86PAE_)
  5837. #define PDI_SHIFT PDI_SHIFT_X86
  5838. #else
  5839. #define PDI_SHIFT PDI_SHIFT_X86PAE
  5840. #define PPI_SHIFT 30
  5841. #endif
  5842. //
  5843. // Define the number of bits to shift to right justify the Page Table Index
  5844. // field of a PTE.
  5845. //
  5846. #define PTI_SHIFT 12
  5847. //
  5848. // Define the highest user address and user probe address.
  5849. //
  5850. extern PVOID *MmHighestUserAddress;
  5851. extern PVOID *MmSystemRangeStart;
  5852. extern ULONG *MmUserProbeAddress;
  5853. #define MM_HIGHEST_USER_ADDRESS *MmHighestUserAddress
  5854. #define MM_SYSTEM_RANGE_START *MmSystemRangeStart
  5855. #define MM_USER_PROBE_ADDRESS *MmUserProbeAddress
  5856. //
  5857. // The lowest user address reserves the low 64k.
  5858. //
  5859. #define MM_LOWEST_USER_ADDRESS (PVOID)0x10000
  5860. //
  5861. // The lowest address for system space.
  5862. //
  5863. #if !defined (_X86PAE_)
  5864. #define MM_LOWEST_SYSTEM_ADDRESS (PVOID)0xC0800000
  5865. #else
  5866. #define MM_LOWEST_SYSTEM_ADDRESS (PVOID)0xC0C00000
  5867. #endif
  5868. #define MmGetProcedureAddress(Address) (Address)
  5869. #define MmLockPagableCodeSection(Address) MmLockPagableDataSection(Address)
  5870. #define KIP0PCRADDRESS 0xffdff000
  5871. #define KI_USER_SHARED_DATA 0xffdf0000
  5872. #define SharedUserData ((KUSER_SHARED_DATA * const) KI_USER_SHARED_DATA)
  5873. //
  5874. // Result type definition for i386. (Machine specific enumerate type
  5875. // which is return type for portable exinterlockedincrement/decrement
  5876. // procedures.) In general, you should use the enumerated type defined
  5877. // in ex.h instead of directly referencing these constants.
  5878. //
  5879. // Flags loaded into AH by LAHF instruction
  5880. #define EFLAG_SIGN 0x8000
  5881. #define EFLAG_ZERO 0x4000
  5882. #define EFLAG_SELECT (EFLAG_SIGN | EFLAG_ZERO)
  5883. #define RESULT_NEGATIVE ((EFLAG_SIGN & ~EFLAG_ZERO) & EFLAG_SELECT)
  5884. #define RESULT_ZERO ((~EFLAG_SIGN & EFLAG_ZERO) & EFLAG_SELECT)
  5885. #define RESULT_POSITIVE ((~EFLAG_SIGN & ~EFLAG_ZERO) & EFLAG_SELECT)
  5886. //
  5887. // Convert various portable ExInterlock APIs into their architectural
  5888. // equivalents.
  5889. //
  5890. #if PRAGMA_DEPRECATED_DDK
  5891. #pragma deprecated(ExInterlockedIncrementLong) // Use InterlockedIncrement
  5892. #pragma deprecated(ExInterlockedDecrementLong) // Use InterlockedDecrement
  5893. #pragma deprecated(ExInterlockedExchangeUlong) // Use InterlockedExchange
  5894. #endif
  5895. #define ExInterlockedIncrementLong(Addend,Lock) \
  5896. Exfi386InterlockedIncrementLong(Addend)
  5897. #define ExInterlockedDecrementLong(Addend,Lock) \
  5898. Exfi386InterlockedDecrementLong(Addend)
  5899. #define ExInterlockedExchangeUlong(Target,Value,Lock) \
  5900. Exfi386InterlockedExchangeUlong(Target,Value)
  5901. #define ExInterlockedAddUlong ExfInterlockedAddUlong
  5902. #define ExInterlockedInsertHeadList ExfInterlockedInsertHeadList
  5903. #define ExInterlockedInsertTailList ExfInterlockedInsertTailList
  5904. #define ExInterlockedRemoveHeadList ExfInterlockedRemoveHeadList
  5905. #define ExInterlockedPopEntryList ExfInterlockedPopEntryList
  5906. #define ExInterlockedPushEntryList ExfInterlockedPushEntryList
  5907. //
  5908. // Prototypes for architectural specific versions of Exi386 Api
  5909. //
  5910. //
  5911. // Interlocked result type is portable, but its values are machine specific.
  5912. // Constants for value are in i386.h, mips.h, etc.
  5913. //
  5914. typedef enum _INTERLOCKED_RESULT {
  5915. ResultNegative = RESULT_NEGATIVE,
  5916. ResultZero = RESULT_ZERO,
  5917. ResultPositive = RESULT_POSITIVE
  5918. } INTERLOCKED_RESULT;
  5919. NTKERNELAPI
  5920. INTERLOCKED_RESULT
  5921. FASTCALL
  5922. Exfi386InterlockedIncrementLong (
  5923. IN PLONG Addend
  5924. );
  5925. NTKERNELAPI
  5926. INTERLOCKED_RESULT
  5927. FASTCALL
  5928. Exfi386InterlockedDecrementLong (
  5929. IN PLONG Addend
  5930. );
  5931. NTKERNELAPI
  5932. ULONG
  5933. FASTCALL
  5934. Exfi386InterlockedExchangeUlong (
  5935. IN PULONG Target,
  5936. IN ULONG Value
  5937. );
  5938. #if !defined(_WINBASE_) && !defined(NONTOSPINTERLOCK)
  5939. #if !defined(MIDL_PASS) // wdm
  5940. #if defined(NO_INTERLOCKED_INTRINSICS) || defined(_CROSS_PLATFORM_)
  5941. NTKERNELAPI
  5942. LONG
  5943. FASTCALL
  5944. InterlockedIncrement(
  5945. IN LONG volatile *Addend
  5946. );
  5947. NTKERNELAPI
  5948. LONG
  5949. FASTCALL
  5950. InterlockedDecrement(
  5951. IN LONG volatile *Addend
  5952. );
  5953. NTKERNELAPI
  5954. LONG
  5955. FASTCALL
  5956. InterlockedExchange(
  5957. IN OUT LONG volatile *Target,
  5958. IN LONG Value
  5959. );
  5960. #define InterlockedExchangePointer(Target, Value) \
  5961. (PVOID)InterlockedExchange((PLONG)(Target), (LONG)(Value))
  5962. LONG
  5963. FASTCALL
  5964. InterlockedExchangeAdd(
  5965. IN OUT LONG volatile *Addend,
  5966. IN LONG Increment
  5967. );
  5968. NTKERNELAPI
  5969. LONG
  5970. FASTCALL
  5971. InterlockedCompareExchange(
  5972. IN OUT LONG volatile *Destination,
  5973. IN LONG ExChange,
  5974. IN LONG Comperand
  5975. );
  5976. #define InterlockedCompareExchangePointer(Destination, ExChange, Comperand) \
  5977. (PVOID)InterlockedCompareExchange((PLONG)Destination, (LONG)ExChange, (LONG)Comperand)
  5978. #define InterlockedCompareExchange64(Destination, ExChange, Comperand) \
  5979. ExfInterlockedCompareExchange64(Destination, &(ExChange), &(Comperand))
  5980. NTKERNELAPI
  5981. LONGLONG
  5982. FASTCALL
  5983. ExfInterlockedCompareExchange64(
  5984. IN OUT LONGLONG volatile *Destination,
  5985. IN PLONGLONG ExChange,
  5986. IN PLONGLONG Comperand
  5987. );
  5988. #else // NO_INTERLOCKED_INTRINSICS || _CROSS_PLATFORM_
  5989. #define InterlockedExchangePointer(Target, Value) \
  5990. (PVOID)InterlockedExchange((PLONG)Target, (LONG)Value)
  5991. #if (_MSC_FULL_VER > 13009037)
  5992. LONG
  5993. __cdecl
  5994. _InterlockedExchange(
  5995. IN OUT LONG volatile *Target,
  5996. IN LONG Value
  5997. );
  5998. #pragma intrinsic (_InterlockedExchange)
  5999. #define InterlockedExchange _InterlockedExchange
  6000. #else
  6001. FORCEINLINE
  6002. LONG
  6003. FASTCALL
  6004. InterlockedExchange(
  6005. IN OUT LONG volatile *Target,
  6006. IN LONG Value
  6007. )
  6008. {
  6009. __asm {
  6010. mov eax, Value
  6011. mov ecx, Target
  6012. xchg [ecx], eax
  6013. }
  6014. }
  6015. #endif
  6016. #if (_MSC_FULL_VER > 13009037)
  6017. LONG
  6018. __cdecl
  6019. _InterlockedIncrement(
  6020. IN LONG volatile *Addend
  6021. );
  6022. #pragma intrinsic (_InterlockedIncrement)
  6023. #define InterlockedIncrement _InterlockedIncrement
  6024. #else
  6025. #define InterlockedIncrement(Addend) (InterlockedExchangeAdd (Addend, 1)+1)
  6026. #endif
  6027. #if (_MSC_FULL_VER > 13009037)
  6028. LONG
  6029. __cdecl
  6030. _InterlockedDecrement(
  6031. IN LONG volatile *Addend
  6032. );
  6033. #pragma intrinsic (_InterlockedDecrement)
  6034. #define InterlockedDecrement _InterlockedDecrement
  6035. #else
  6036. #define InterlockedDecrement(Addend) (InterlockedExchangeAdd (Addend, -1)-1)
  6037. #endif
  6038. #if (_MSC_FULL_VER > 13009037)
  6039. LONG
  6040. __cdecl
  6041. _InterlockedExchangeAdd(
  6042. IN OUT LONG volatile *Addend,
  6043. IN LONG Increment
  6044. );
  6045. #pragma intrinsic (_InterlockedExchangeAdd)
  6046. #define InterlockedExchangeAdd _InterlockedExchangeAdd
  6047. #else
  6048. FORCEINLINE
  6049. LONG
  6050. FASTCALL
  6051. InterlockedExchangeAdd(
  6052. IN OUT LONG volatile *Addend,
  6053. IN LONG Increment
  6054. )
  6055. {
  6056. __asm {
  6057. mov eax, Increment
  6058. mov ecx, Addend
  6059. lock xadd [ecx], eax
  6060. }
  6061. }
  6062. #endif
  6063. #if (_MSC_FULL_VER > 13009037)
  6064. LONG
  6065. __cdecl
  6066. _InterlockedCompareExchange (
  6067. IN OUT LONG volatile *Destination,
  6068. IN LONG ExChange,
  6069. IN LONG Comperand
  6070. );
  6071. #pragma intrinsic (_InterlockedCompareExchange)
  6072. #define InterlockedCompareExchange (LONG)_InterlockedCompareExchange
  6073. #else
  6074. FORCEINLINE
  6075. LONG
  6076. FASTCALL
  6077. InterlockedCompareExchange(
  6078. IN OUT LONG volatile *Destination,
  6079. IN LONG Exchange,
  6080. IN LONG Comperand
  6081. )
  6082. {
  6083. __asm {
  6084. mov eax, Comperand
  6085. mov ecx, Destination
  6086. mov edx, Exchange
  6087. lock cmpxchg [ecx], edx
  6088. }
  6089. }
  6090. #endif
  6091. #define InterlockedCompareExchangePointer(Destination, ExChange, Comperand) \
  6092. (PVOID)InterlockedCompareExchange((PLONG)Destination, (LONG)ExChange, (LONG)Comperand)
  6093. #define InterlockedCompareExchange64(Destination, ExChange, Comperand) \
  6094. ExfInterlockedCompareExchange64(Destination, &(ExChange), &(Comperand))
  6095. NTKERNELAPI
  6096. LONGLONG
  6097. FASTCALL
  6098. ExfInterlockedCompareExchange64(
  6099. IN OUT LONGLONG volatile *Destination,
  6100. IN PLONGLONG ExChange,
  6101. IN PLONGLONG Comperand
  6102. );
  6103. #endif // INTERLOCKED_INTRINSICS || _CROSS_PLATFORM_
  6104. #endif // MIDL_PASS
  6105. #define InterlockedIncrementAcquire InterlockedIncrement
  6106. #define InterlockedIncrementRelease InterlockedIncrement
  6107. #define InterlockedDecrementAcquire InterlockedDecrement
  6108. #define InterlockedDecrementRelease InterlockedDecrement
  6109. #define InterlockedExchangeAcquire64 InterlockedExchange64
  6110. #define InterlockedCompareExchangeAcquire InterlockedCompareExchange
  6111. #define InterlockedCompareExchangeRelease InterlockedCompareExchange
  6112. #define InterlockedCompareExchangeAcquire64 InterlockedCompareExchange64
  6113. #define InterlockedCompareExchangeRelease64 InterlockedCompareExchange64
  6114. #endif // __WINBASE__ && !NONTOSPINTERLOCK
  6115. //
  6116. // Turn these instrinsics off until the compiler can handle them
  6117. //
  6118. #if (_MSC_FULL_VER > 13009037)
  6119. LONG
  6120. _InterlockedOr (
  6121. IN OUT LONG volatile *Target,
  6122. IN LONG Set
  6123. );
  6124. #pragma intrinsic (_InterlockedOr)
  6125. #define InterlockedOr _InterlockedOr
  6126. LONG
  6127. _InterlockedAnd (
  6128. IN OUT LONG volatile *Target,
  6129. IN LONG Set
  6130. );
  6131. #pragma intrinsic (_InterlockedAnd)
  6132. #define InterlockedAnd _InterlockedAnd
  6133. LONG
  6134. _InterlockedXor (
  6135. IN OUT LONG volatile *Target,
  6136. IN LONG Set
  6137. );
  6138. #pragma intrinsic (_InterlockedXor)
  6139. #define InterlockedXor _InterlockedXor
  6140. #else // compiler version
  6141. FORCEINLINE
  6142. LONG
  6143. InterlockedAnd (
  6144. IN OUT LONG volatile *Target,
  6145. LONG Set
  6146. )
  6147. {
  6148. LONG i;
  6149. LONG j;
  6150. j = *Target;
  6151. do {
  6152. i = j;
  6153. j = InterlockedCompareExchange(Target,
  6154. i & Set,
  6155. i);
  6156. } while (i != j);
  6157. return j;
  6158. }
  6159. FORCEINLINE
  6160. LONG
  6161. InterlockedOr (
  6162. IN OUT LONG volatile *Target,
  6163. IN LONG Set
  6164. )
  6165. {
  6166. LONG i;
  6167. LONG j;
  6168. j = *Target;
  6169. do {
  6170. i = j;
  6171. j = InterlockedCompareExchange(Target,
  6172. i | Set,
  6173. i);
  6174. } while (i != j);
  6175. return j;
  6176. }
  6177. #endif // compiler version
  6178. #if !defined(MIDL_PASS) && defined(_M_IX86)
  6179. //
  6180. // i386 function definitions
  6181. //
  6182. #if _MSC_VER >= 1200
  6183. #pragma warning(push)
  6184. #endif
  6185. #pragma warning(disable:4035) // re-enable below
  6186. #define _PCR fs:[0]
  6187. //
  6188. // Get current IRQL.
  6189. //
  6190. // On x86 this function resides in the HAL
  6191. //
  6192. NTHALAPI
  6193. KIRQL
  6194. NTAPI
  6195. KeGetCurrentIrql();
  6196. //
  6197. // Get the current processor number
  6198. //
  6199. FORCEINLINE
  6200. ULONG
  6201. NTAPI
  6202. KeGetCurrentProcessorNumber(VOID)
  6203. {
  6204. #if (_MSC_FULL_VER >= 13012035)
  6205. return (ULONG) __readfsbyte (FIELD_OFFSET (KPCR, Number));
  6206. #else
  6207. __asm { movzx eax, _PCR KPCR.Number }
  6208. #endif
  6209. }
  6210. #if _MSC_VER >= 1200
  6211. #pragma warning(pop)
  6212. #else
  6213. #pragma warning(default:4035)
  6214. #endif
  6215. #endif // !defined(MIDL_PASS) && defined(_M_IX86)
  6216. //++
  6217. //
  6218. // VOID
  6219. // KeMemoryBarrier (
  6220. // VOID
  6221. // )
  6222. //
  6223. // VOID
  6224. // KeMemoryBarrierWithoutFence (
  6225. // VOID
  6226. // )
  6227. //
  6228. //
  6229. // Routine Description:
  6230. //
  6231. // These functions order memory accesses as seen by other processors.
  6232. //
  6233. // Arguments:
  6234. //
  6235. // None.
  6236. //
  6237. // Return Value:
  6238. //
  6239. // None.
  6240. //
  6241. //--
  6242. #ifdef __cplusplus
  6243. extern "C" {
  6244. #endif
  6245. VOID
  6246. _ReadWriteBarrier(
  6247. VOID
  6248. );
  6249. #ifdef __cplusplus
  6250. }
  6251. #endif
  6252. #pragma intrinsic (_ReadWriteBarrier)
  6253. FORCEINLINE
  6254. VOID
  6255. KeMemoryBarrier (
  6256. VOID
  6257. )
  6258. {
  6259. LONG Barrier;
  6260. __asm {
  6261. xchg Barrier, eax
  6262. }
  6263. }
  6264. #define KeMemoryBarrierWithoutFence() _ReadWriteBarrier()
  6265. NTKERNELAPI
  6266. NTSTATUS
  6267. NTAPI
  6268. KeSaveFloatingPointState (
  6269. OUT PKFLOATING_SAVE FloatSave
  6270. );
  6271. NTKERNELAPI
  6272. NTSTATUS
  6273. NTAPI
  6274. KeRestoreFloatingPointState (
  6275. IN PKFLOATING_SAVE FloatSave
  6276. );
  6277. #endif // defined(_X86_)
  6278. // Use the following for kernel mode runtime checks of X86 system architecture
  6279. #ifdef _X86_
  6280. #ifdef IsNEC_98
  6281. #undef IsNEC_98
  6282. #endif
  6283. #ifdef IsNotNEC_98
  6284. #undef IsNotNEC_98
  6285. #endif
  6286. #ifdef SetNEC_98
  6287. #undef SetNEC_98
  6288. #endif
  6289. #ifdef SetNotNEC_98
  6290. #undef SetNotNEC_98
  6291. #endif
  6292. #define IsNEC_98 (SharedUserData->AlternativeArchitecture == NEC98x86)
  6293. #define IsNotNEC_98 (SharedUserData->AlternativeArchitecture != NEC98x86)
  6294. #define SetNEC_98 SharedUserData->AlternativeArchitecture = NEC98x86
  6295. #define SetNotNEC_98 SharedUserData->AlternativeArchitecture = StandardDesign
  6296. #endif
  6297. #if defined(_M_AMD64) && !defined(RC_INVOKED) && !defined(MIDL_PASS)
  6298. //
  6299. // Define intrinsic function to do in's and out's.
  6300. //
  6301. #ifdef __cplusplus
  6302. extern "C" {
  6303. #endif
  6304. UCHAR
  6305. __inbyte (
  6306. IN USHORT Port
  6307. );
  6308. USHORT
  6309. __inword (
  6310. IN USHORT Port
  6311. );
  6312. ULONG
  6313. __indword (
  6314. IN USHORT Port
  6315. );
  6316. VOID
  6317. __outbyte (
  6318. IN USHORT Port,
  6319. IN UCHAR Data
  6320. );
  6321. VOID
  6322. __outword (
  6323. IN USHORT Port,
  6324. IN USHORT Data
  6325. );
  6326. VOID
  6327. __outdword (
  6328. IN USHORT Port,
  6329. IN ULONG Data
  6330. );
  6331. VOID
  6332. __inbytestring (
  6333. IN USHORT Port,
  6334. IN PUCHAR Buffer,
  6335. IN ULONG Count
  6336. );
  6337. VOID
  6338. __inwordstring (
  6339. IN USHORT Port,
  6340. IN PUSHORT Buffer,
  6341. IN ULONG Count
  6342. );
  6343. VOID
  6344. __indwordstring (
  6345. IN USHORT Port,
  6346. IN PULONG Buffer,
  6347. IN ULONG Count
  6348. );
  6349. VOID
  6350. __outbytestring (
  6351. IN USHORT Port,
  6352. IN PUCHAR Buffer,
  6353. IN ULONG Count
  6354. );
  6355. VOID
  6356. __outwordstring (
  6357. IN USHORT Port,
  6358. IN PUSHORT Buffer,
  6359. IN ULONG Count
  6360. );
  6361. VOID
  6362. __outdwordstring (
  6363. IN USHORT Port,
  6364. IN PULONG Buffer,
  6365. IN ULONG Count
  6366. );
  6367. #ifdef __cplusplus
  6368. }
  6369. #endif
  6370. #pragma intrinsic(__inbyte)
  6371. #pragma intrinsic(__inword)
  6372. #pragma intrinsic(__indword)
  6373. #pragma intrinsic(__outbyte)
  6374. #pragma intrinsic(__outword)
  6375. #pragma intrinsic(__outdword)
  6376. #pragma intrinsic(__inbytestring)
  6377. #pragma intrinsic(__inwordstring)
  6378. #pragma intrinsic(__indwordstring)
  6379. #pragma intrinsic(__outbytestring)
  6380. #pragma intrinsic(__outwordstring)
  6381. #pragma intrinsic(__outdwordstring)
  6382. //
  6383. // Interlocked intrinsic functions.
  6384. //
  6385. #define InterlockedAnd _InterlockedAnd
  6386. #define InterlockedOr _InterlockedOr
  6387. #define InterlockedXor _InterlockedXor
  6388. #define InterlockedIncrement _InterlockedIncrement
  6389. #define InterlockedIncrementAcquire InterlockedIncrement
  6390. #define InterlockedIncrementRelease InterlockedIncrement
  6391. #define InterlockedDecrement _InterlockedDecrement
  6392. #define InterlockedDecrementAcquire InterlockedDecrement
  6393. #define InterlockedDecrementRelease InterlockedDecrement
  6394. #define InterlockedAdd _InterlockedAdd
  6395. #define InterlockedExchange _InterlockedExchange
  6396. #define InterlockedExchangeAdd _InterlockedExchangeAdd
  6397. #define InterlockedCompareExchange _InterlockedCompareExchange
  6398. #define InterlockedCompareExchangeAcquire InterlockedCompareExchange
  6399. #define InterlockedCompareExchangeRelease InterlockedCompareExchange
  6400. #define InterlockedAnd64 _InterlockedAnd64
  6401. #define InterlockedOr64 _InterlockedOr64
  6402. #define InterlockedXor64 _InterlockedXor64
  6403. #define InterlockedIncrement64 _InterlockedIncrement64
  6404. #define InterlockedDecrement64 _InterlockedDecrement64
  6405. #define InterlockedAdd64 _InterlockedAdd64
  6406. #define InterlockedExchange64 _InterlockedExchange64
  6407. #define InterlockedExchangeAcquire64 InterlockedExchange64
  6408. #define InterlockedExchangeAdd64 _InterlockedExchangeAdd64
  6409. #define InterlockedCompareExchange64 _InterlockedCompareExchange64
  6410. #define InterlockedCompareExchangeAcquire64 InterlockedCompareExchange64
  6411. #define InterlockedCompareExchangeRelease64 InterlockedCompareExchange64
  6412. #define InterlockedExchangePointer _InterlockedExchangePointer
  6413. #define InterlockedCompareExchangePointer _InterlockedCompareExchangePointer
  6414. #ifdef __cplusplus
  6415. extern "C" {
  6416. #endif
  6417. LONG
  6418. InterlockedAnd (
  6419. IN OUT LONG volatile *Destination,
  6420. IN LONG Value
  6421. );
  6422. LONG
  6423. InterlockedOr (
  6424. IN OUT LONG volatile *Destination,
  6425. IN LONG Value
  6426. );
  6427. LONG
  6428. InterlockedXor (
  6429. IN OUT LONG volatile *Destination,
  6430. IN LONG Value
  6431. );
  6432. LONG64
  6433. InterlockedAnd64 (
  6434. IN OUT LONG64 volatile *Destination,
  6435. IN LONG64 Value
  6436. );
  6437. LONG64
  6438. InterlockedOr64 (
  6439. IN OUT LONG64 volatile *Destination,
  6440. IN LONG64 Value
  6441. );
  6442. LONG64
  6443. InterlockedXor64 (
  6444. IN OUT LONG64 volatile *Destination,
  6445. IN LONG64 Value
  6446. );
  6447. LONG
  6448. InterlockedIncrement(
  6449. IN OUT LONG volatile *Addend
  6450. );
  6451. LONG
  6452. InterlockedDecrement(
  6453. IN OUT LONG volatile *Addend
  6454. );
  6455. LONG
  6456. InterlockedExchange(
  6457. IN OUT LONG volatile *Target,
  6458. IN LONG Value
  6459. );
  6460. LONG
  6461. InterlockedExchangeAdd(
  6462. IN OUT LONG volatile *Addend,
  6463. IN LONG Value
  6464. );
  6465. #if !defined(_X86AMD64_)
  6466. __forceinline
  6467. LONG
  6468. InterlockedAdd(
  6469. IN OUT LONG volatile *Addend,
  6470. IN LONG Value
  6471. )
  6472. {
  6473. return InterlockedExchangeAdd(Addend, Value) + Value;
  6474. }
  6475. #endif
  6476. LONG
  6477. InterlockedCompareExchange (
  6478. IN OUT LONG volatile *Destination,
  6479. IN LONG ExChange,
  6480. IN LONG Comperand
  6481. );
  6482. LONG64
  6483. InterlockedIncrement64(
  6484. IN OUT LONG64 volatile *Addend
  6485. );
  6486. LONG64
  6487. InterlockedDecrement64(
  6488. IN OUT LONG64 volatile *Addend
  6489. );
  6490. LONG64
  6491. InterlockedExchange64(
  6492. IN OUT LONG64 volatile *Target,
  6493. IN LONG64 Value
  6494. );
  6495. LONG64
  6496. InterlockedExchangeAdd64(
  6497. IN OUT LONG64 volatile *Addend,
  6498. IN LONG64 Value
  6499. );
  6500. #if !defined(_X86AMD64_)
  6501. __forceinline
  6502. LONG64
  6503. InterlockedAdd64(
  6504. IN OUT LONG64 volatile *Addend,
  6505. IN LONG64 Value
  6506. )
  6507. {
  6508. return InterlockedExchangeAdd64(Addend, Value) + Value;
  6509. }
  6510. #endif
  6511. LONG64
  6512. InterlockedCompareExchange64 (
  6513. IN OUT LONG64 volatile *Destination,
  6514. IN LONG64 ExChange,
  6515. IN LONG64 Comperand
  6516. );
  6517. PVOID
  6518. InterlockedCompareExchangePointer (
  6519. IN OUT PVOID volatile *Destination,
  6520. IN PVOID Exchange,
  6521. IN PVOID Comperand
  6522. );
  6523. PVOID
  6524. InterlockedExchangePointer(
  6525. IN OUT PVOID volatile *Target,
  6526. IN PVOID Value
  6527. );
  6528. #pragma intrinsic(_InterlockedAnd)
  6529. #pragma intrinsic(_InterlockedOr)
  6530. #pragma intrinsic(_InterlockedXor)
  6531. #pragma intrinsic(_InterlockedIncrement)
  6532. #pragma intrinsic(_InterlockedDecrement)
  6533. #pragma intrinsic(_InterlockedExchange)
  6534. #pragma intrinsic(_InterlockedExchangeAdd)
  6535. #pragma intrinsic(_InterlockedCompareExchange)
  6536. #pragma intrinsic(_InterlockedAnd64)
  6537. #pragma intrinsic(_InterlockedOr64)
  6538. #pragma intrinsic(_InterlockedXor64)
  6539. #pragma intrinsic(_InterlockedIncrement64)
  6540. #pragma intrinsic(_InterlockedDecrement64)
  6541. #pragma intrinsic(_InterlockedExchange64)
  6542. #pragma intrinsic(_InterlockedExchangeAdd64)
  6543. #pragma intrinsic(_InterlockedCompareExchange64)
  6544. #pragma intrinsic(_InterlockedExchangePointer)
  6545. #pragma intrinsic(_InterlockedCompareExchangePointer)
  6546. #ifdef __cplusplus
  6547. }
  6548. #endif
  6549. #endif // defined(_M_AMD64) && !defined(RC_INVOKED) && !defined(MIDL_PASS)
  6550. #if defined(_AMD64_)
  6551. //
  6552. // Types to use to contain PFNs and their counts.
  6553. //
  6554. typedef ULONG PFN_COUNT;
  6555. typedef LONG64 SPFN_NUMBER, *PSPFN_NUMBER;
  6556. typedef ULONG64 PFN_NUMBER, *PPFN_NUMBER;
  6557. //
  6558. // Define maximum size of flush multiple TB request.
  6559. //
  6560. #define FLUSH_MULTIPLE_MAXIMUM 32
  6561. //
  6562. // Indicate that the AMD64 compiler supports the allocate pragmas.
  6563. //
  6564. #define ALLOC_PRAGMA 1
  6565. #define ALLOC_DATA_PRAGMA 1
  6566. #define NORMAL_DISPATCH_LENGTH 106
  6567. #define DISPATCH_LENGTH NORMAL_DISPATCH_LENGTH
  6568. //
  6569. // Interrupt Request Level definitions
  6570. //
  6571. #define PASSIVE_LEVEL 0 // Passive release level
  6572. #define LOW_LEVEL 0 // Lowest interrupt level
  6573. #define APC_LEVEL 1 // APC interrupt level
  6574. #define DISPATCH_LEVEL 2 // Dispatcher level
  6575. #define CLOCK_LEVEL 13 // Interval clock level
  6576. #define IPI_LEVEL 14 // Interprocessor interrupt level
  6577. #define POWER_LEVEL 14 // Power failure level
  6578. #define PROFILE_LEVEL 15 // timer used for profiling.
  6579. #define HIGH_LEVEL 15 // Highest interrupt level
  6580. #define SYNCH_LEVEL (IPI_LEVEL-2)
  6581. //
  6582. // I/O space read and write macros.
  6583. //
  6584. // The READ/WRITE_REGISTER_* calls manipulate I/O registers in MEMORY space.
  6585. //
  6586. // The READ/WRITE_PORT_* calls manipulate I/O registers in PORT space.
  6587. //
  6588. __forceinline
  6589. UCHAR
  6590. READ_REGISTER_UCHAR (
  6591. volatile UCHAR *Register
  6592. )
  6593. {
  6594. return *Register;
  6595. }
  6596. __forceinline
  6597. USHORT
  6598. READ_REGISTER_USHORT (
  6599. volatile USHORT *Register
  6600. )
  6601. {
  6602. return *Register;
  6603. }
  6604. __forceinline
  6605. ULONG
  6606. READ_REGISTER_ULONG (
  6607. volatile ULONG *Register
  6608. )
  6609. {
  6610. return *Register;
  6611. }
  6612. __forceinline
  6613. VOID
  6614. READ_REGISTER_BUFFER_UCHAR (
  6615. PUCHAR Register,
  6616. PUCHAR Buffer,
  6617. ULONG Count
  6618. )
  6619. {
  6620. __movsb(Buffer, Register, Count);
  6621. return;
  6622. }
  6623. __forceinline
  6624. VOID
  6625. READ_REGISTER_BUFFER_USHORT (
  6626. PUSHORT Register,
  6627. PUSHORT Buffer,
  6628. ULONG Count
  6629. )
  6630. {
  6631. __movsw(Buffer, Register, Count);
  6632. return;
  6633. }
  6634. __forceinline
  6635. VOID
  6636. READ_REGISTER_BUFFER_ULONG (
  6637. PULONG Register,
  6638. PULONG Buffer,
  6639. ULONG Count
  6640. )
  6641. {
  6642. __movsd(Buffer, Register, Count);
  6643. return;
  6644. }
  6645. __forceinline
  6646. VOID
  6647. WRITE_REGISTER_UCHAR (
  6648. PUCHAR Register,
  6649. UCHAR Value
  6650. )
  6651. {
  6652. *Register = Value;
  6653. StoreFence();
  6654. return;
  6655. }
  6656. __forceinline
  6657. VOID
  6658. WRITE_REGISTER_USHORT (
  6659. PUSHORT Register,
  6660. USHORT Value
  6661. )
  6662. {
  6663. *Register = Value;
  6664. StoreFence();
  6665. return;
  6666. }
  6667. __forceinline
  6668. VOID
  6669. WRITE_REGISTER_ULONG (
  6670. PULONG Register,
  6671. ULONG Value
  6672. )
  6673. {
  6674. *Register = Value;
  6675. StoreFence();
  6676. return;
  6677. }
  6678. __forceinline
  6679. VOID
  6680. WRITE_REGISTER_BUFFER_UCHAR (
  6681. PUCHAR Register,
  6682. PUCHAR Buffer,
  6683. ULONG Count
  6684. )
  6685. {
  6686. __movsb(Register, Buffer, Count);
  6687. StoreFence();
  6688. return;
  6689. }
  6690. __forceinline
  6691. VOID
  6692. WRITE_REGISTER_BUFFER_USHORT (
  6693. PUSHORT Register,
  6694. PUSHORT Buffer,
  6695. ULONG Count
  6696. )
  6697. {
  6698. __movsw(Register, Buffer, Count);
  6699. StoreFence();
  6700. return;
  6701. }
  6702. __forceinline
  6703. VOID
  6704. WRITE_REGISTER_BUFFER_ULONG (
  6705. PULONG Register,
  6706. PULONG Buffer,
  6707. ULONG Count
  6708. )
  6709. {
  6710. __movsd(Register, Buffer, Count);
  6711. StoreFence();
  6712. return;
  6713. }
  6714. __forceinline
  6715. UCHAR
  6716. READ_PORT_UCHAR (
  6717. PUCHAR Port
  6718. )
  6719. {
  6720. return __inbyte((USHORT)((ULONG64)Port));
  6721. }
  6722. __forceinline
  6723. USHORT
  6724. READ_PORT_USHORT (
  6725. PUSHORT Port
  6726. )
  6727. {
  6728. return __inword((USHORT)((ULONG64)Port));
  6729. }
  6730. __forceinline
  6731. ULONG
  6732. READ_PORT_ULONG (
  6733. PULONG Port
  6734. )
  6735. {
  6736. return __indword((USHORT)((ULONG64)Port));
  6737. }
  6738. __forceinline
  6739. VOID
  6740. READ_PORT_BUFFER_UCHAR (
  6741. PUCHAR Port,
  6742. PUCHAR Buffer,
  6743. ULONG Count
  6744. )
  6745. {
  6746. __inbytestring((USHORT)((ULONG64)Port), Buffer, Count);
  6747. return;
  6748. }
  6749. __forceinline
  6750. VOID
  6751. READ_PORT_BUFFER_USHORT (
  6752. PUSHORT Port,
  6753. PUSHORT Buffer,
  6754. ULONG Count
  6755. )
  6756. {
  6757. __inwordstring((USHORT)((ULONG64)Port), Buffer, Count);
  6758. return;
  6759. }
  6760. __forceinline
  6761. VOID
  6762. READ_PORT_BUFFER_ULONG (
  6763. PULONG Port,
  6764. PULONG Buffer,
  6765. ULONG Count
  6766. )
  6767. {
  6768. __indwordstring((USHORT)((ULONG64)Port), Buffer, Count);
  6769. return;
  6770. }
  6771. __forceinline
  6772. VOID
  6773. WRITE_PORT_UCHAR (
  6774. PUCHAR Port,
  6775. UCHAR Value
  6776. )
  6777. {
  6778. __outbyte((USHORT)((ULONG64)Port), Value);
  6779. return;
  6780. }
  6781. __forceinline
  6782. VOID
  6783. WRITE_PORT_USHORT (
  6784. PUSHORT Port,
  6785. USHORT Value
  6786. )
  6787. {
  6788. __outword((USHORT)((ULONG64)Port), Value);
  6789. return;
  6790. }
  6791. __forceinline
  6792. VOID
  6793. WRITE_PORT_ULONG (
  6794. PULONG Port,
  6795. ULONG Value
  6796. )
  6797. {
  6798. __outdword((USHORT)((ULONG64)Port), Value);
  6799. return;
  6800. }
  6801. __forceinline
  6802. VOID
  6803. WRITE_PORT_BUFFER_UCHAR (
  6804. PUCHAR Port,
  6805. PUCHAR Buffer,
  6806. ULONG Count
  6807. )
  6808. {
  6809. __outbytestring((USHORT)((ULONG64)Port), Buffer, Count);
  6810. return;
  6811. }
  6812. __forceinline
  6813. VOID
  6814. WRITE_PORT_BUFFER_USHORT (
  6815. PUSHORT Port,
  6816. PUSHORT Buffer,
  6817. ULONG Count
  6818. )
  6819. {
  6820. __outwordstring((USHORT)((ULONG64)Port), Buffer, Count);
  6821. return;
  6822. }
  6823. __forceinline
  6824. VOID
  6825. WRITE_PORT_BUFFER_ULONG (
  6826. PULONG Port,
  6827. PULONG Buffer,
  6828. ULONG Count
  6829. )
  6830. {
  6831. __outdwordstring((USHORT)((ULONG64)Port), Buffer, Count);
  6832. return;
  6833. }
  6834. //
  6835. // Get data cache fill size.
  6836. //
  6837. #if PRAGMA_DEPRECATED_DDK
  6838. #pragma deprecated(KeGetDcacheFillSize) // Use GetDmaAlignment
  6839. #endif
  6840. #define KeGetDcacheFillSize() 1L
  6841. #define KeFlushIoBuffers(Mdl, ReadOperation, DmaOperation)
  6842. #define ExAcquireSpinLock(Lock, OldIrql) KeAcquireSpinLock((Lock), (OldIrql))
  6843. #define ExReleaseSpinLock(Lock, OldIrql) KeReleaseSpinLock((Lock), (OldIrql))
  6844. #define ExAcquireSpinLockAtDpcLevel(Lock) KeAcquireSpinLockAtDpcLevel(Lock)
  6845. #define ExReleaseSpinLockFromDpcLevel(Lock) KeReleaseSpinLockFromDpcLevel(Lock)
  6846. #define KI_USER_SHARED_DATA 0xFFFFF78000000000UI64
  6847. #define SharedUserData ((KUSER_SHARED_DATA * const)KI_USER_SHARED_DATA)
  6848. #define SharedInterruptTime (KI_USER_SHARED_DATA + 0x8)
  6849. #define SharedSystemTime (KI_USER_SHARED_DATA + 0x14)
  6850. #define SharedTickCount (KI_USER_SHARED_DATA + 0x320)
  6851. #define KeQueryInterruptTime() *((volatile ULONG64 *)(SharedInterruptTime))
  6852. #define KeQuerySystemTime(CurrentCount) \
  6853. *((PULONG64)(CurrentCount)) = *((volatile ULONG64 *)(SharedSystemTime))
  6854. #define KeQueryTickCount(CurrentCount) \
  6855. *((PULONG64)(CurrentCount)) = *((volatile ULONG64 *)(SharedTickCount))
  6856. //
  6857. // Processor Control Region Structure Definition
  6858. //
  6859. #define PCR_MINOR_VERSION 1
  6860. #define PCR_MAJOR_VERSION 1
  6861. typedef struct _KPCR {
  6862. //
  6863. // Start of the architecturally defined section of the PCR. This section
  6864. // may be directly addressed by vendor/platform specific HAL code and will
  6865. // not change from version to version of NT.
  6866. //
  6867. // Certain fields in the TIB are not used in kernel mode. These include the
  6868. // exception list, stack base, stack limit, subsystem TIB, fiber data, and
  6869. // the arbitrary user pointer. Therefore, these fields are overlaid with
  6870. // other data to get better cache locality.
  6871. union {
  6872. NT_TIB NtTib;
  6873. struct {
  6874. union _KGDTENTRY64 *GdtBase;
  6875. struct _KTSS64 *TssBase;
  6876. PVOID PerfGlobalGroupMask;
  6877. struct _KPCR *Self;
  6878. ULONG ContextSwitches;
  6879. ULONG NotUsed;
  6880. KAFFINITY SetMember;
  6881. PVOID Used_Self;
  6882. };
  6883. };
  6884. struct _KPRCB *CurrentPrcb;
  6885. ULONG64 SavedRcx;
  6886. ULONG64 SavedR11;
  6887. KIRQL Irql;
  6888. UCHAR SecondLevelCacheAssociativity;
  6889. UCHAR Number;
  6890. UCHAR Fill0;
  6891. ULONG Irr;
  6892. ULONG IrrActive;
  6893. ULONG Idr;
  6894. USHORT MajorVersion;
  6895. USHORT MinorVersion;
  6896. ULONG StallScaleFactor;
  6897. union _KIDTENTRY64 *IdtBase;
  6898. PVOID Unused1;
  6899. PVOID Unused2;
  6900. } KPCR, *PKPCR;
  6901. //
  6902. // Exception frame
  6903. //
  6904. // This frame is established when handling an exception. It provides a place
  6905. // to save all nonvolatile registers. The volatile registers will already
  6906. // have been saved in a trap frame.
  6907. //
  6908. // N.B. The exception frame has a built in exception record capable of
  6909. // storing information for four parameter values. This exception
  6910. // record is used exclusively within the trap handling code.
  6911. //
  6912. #define EXCEPTION_AREA_SIZE 64
  6913. typedef struct _KEXCEPTION_FRAME {
  6914. //
  6915. // Home address for the parameter registers.
  6916. //
  6917. ULONG64 P1Home;
  6918. ULONG64 P2Home;
  6919. ULONG64 P3Home;
  6920. ULONG64 P4Home;
  6921. ULONG64 P5;
  6922. //
  6923. // Kernel callout initial stack value.
  6924. //
  6925. ULONG64 InitialStack;
  6926. //
  6927. // Saved nonvolatile floating registers.
  6928. //
  6929. M128 Xmm6;
  6930. M128 Xmm7;
  6931. M128 Xmm8;
  6932. M128 Xmm9;
  6933. M128 Xmm10;
  6934. M128 Xmm11;
  6935. M128 Xmm12;
  6936. M128 Xmm13;
  6937. M128 Xmm14;
  6938. M128 Xmm15;
  6939. //
  6940. // Kernel callout frame variables.
  6941. //
  6942. ULONG64 TrapFrame;
  6943. ULONG64 CallbackStack;
  6944. ULONG64 OutputBuffer;
  6945. ULONG64 OutputLength;
  6946. //
  6947. // Exception record for exceptions.
  6948. //
  6949. UCHAR ExceptionRecord[EXCEPTION_AREA_SIZE];
  6950. //
  6951. // Saved nonvolatile register - not always saved.
  6952. //
  6953. ULONG64 Fill1;
  6954. ULONG64 Rbp;
  6955. //
  6956. // Saved nonvolatile registers.
  6957. //
  6958. ULONG64 Rbx;
  6959. ULONG64 Rdi;
  6960. ULONG64 Rsi;
  6961. ULONG64 R12;
  6962. ULONG64 R13;
  6963. ULONG64 R14;
  6964. ULONG64 R15;
  6965. //
  6966. // EFLAGS and return address.
  6967. //
  6968. ULONG64 Return;
  6969. } KEXCEPTION_FRAME, *PKEXCEPTION_FRAME;
  6970. //
  6971. // Trap frame
  6972. //
  6973. // This frame is established when handling a trap. It provides a place to
  6974. // save all volatile registers. The nonvolatile registers are saved in an
  6975. // exception frame or through the normal C calling conventions for saved
  6976. // registers.
  6977. //
  6978. typedef struct _KTRAP_FRAME {
  6979. //
  6980. // Home address for the parameter registers.
  6981. //
  6982. ULONG64 P1Home;
  6983. ULONG64 P2Home;
  6984. ULONG64 P3Home;
  6985. ULONG64 P4Home;
  6986. ULONG64 P5;
  6987. //
  6988. // Previous processor mode (system services only) and previous IRQL
  6989. // (interrupts only).
  6990. //
  6991. KPROCESSOR_MODE PreviousMode;
  6992. KIRQL PreviousIrql;
  6993. //
  6994. // Page fault load/store indicator.
  6995. //
  6996. UCHAR FaultIndicator;
  6997. UCHAR Fill0;
  6998. //
  6999. // Floating point state.
  7000. //
  7001. ULONG MxCsr;
  7002. //
  7003. // Volatile registers.
  7004. //
  7005. // N.B. These registers are only saved on exceptions and interrupts. They
  7006. // are not saved for system calls.
  7007. //
  7008. ULONG64 Rax;
  7009. ULONG64 Rcx;
  7010. ULONG64 Rdx;
  7011. ULONG64 R8;
  7012. ULONG64 R9;
  7013. ULONG64 R10;
  7014. ULONG64 R11;
  7015. ULONG64 Spare0;
  7016. //
  7017. // Volatile floating registers.
  7018. //
  7019. // N.B. These registers are only saved on exceptions and interrupts. They
  7020. // are not saved for system calls.
  7021. //
  7022. M128 Xmm0;
  7023. M128 Xmm1;
  7024. M128 Xmm2;
  7025. M128 Xmm3;
  7026. M128 Xmm4;
  7027. M128 Xmm5;
  7028. //
  7029. // Page fault address.
  7030. //
  7031. ULONG64 FaultAddress;
  7032. //
  7033. // Debug registers.
  7034. //
  7035. ULONG64 Dr0;
  7036. ULONG64 Dr1;
  7037. ULONG64 Dr2;
  7038. ULONG64 Dr3;
  7039. ULONG64 Dr6;
  7040. ULONG64 Dr7;
  7041. //
  7042. // Special debug registers.
  7043. //
  7044. ULONG64 DebugControl;
  7045. ULONG64 LastBranchToRip;
  7046. ULONG64 LastBranchFromRip;
  7047. ULONG64 LastExceptionToRip;
  7048. ULONG64 LastExceptionFromRip;
  7049. //
  7050. // Segment registers
  7051. //
  7052. USHORT SegDs;
  7053. USHORT SegEs;
  7054. USHORT SegFs;
  7055. USHORT SegGs;
  7056. //
  7057. // Previous trap frame address.
  7058. //
  7059. ULONG64 TrapFrame;
  7060. //
  7061. // Saved nonvolatile registers RBX, RDI and RSI. These registers are only
  7062. // saved in system service trap frames.
  7063. //
  7064. ULONG64 Rbx;
  7065. ULONG64 Rdi;
  7066. ULONG64 Rsi;
  7067. //
  7068. // Saved nonvolatile register RBP. This register is used as a frame
  7069. // pointer during trap processing and is saved in all trap frames.
  7070. //
  7071. ULONG64 Rbp;
  7072. //
  7073. // Information pushed by hardware.
  7074. //
  7075. // N.B. The error code is not always pushed by hardware. For those cases
  7076. // where it is not pushed by hardware a dummy error code is allocated
  7077. // on the stack.
  7078. //
  7079. ULONG64 ErrorCode;
  7080. ULONG64 Rip;
  7081. USHORT SegCs;
  7082. USHORT Fill1[3];
  7083. ULONG EFlags;
  7084. ULONG Fill2;
  7085. ULONG64 Rsp;
  7086. USHORT SegSs;
  7087. USHORT Fill3[3];
  7088. } KTRAP_FRAME, *PKTRAP_FRAME;
  7089. //
  7090. // The nonvolatile floating state
  7091. //
  7092. typedef struct _KFLOATING_SAVE {
  7093. ULONG MxCsr;
  7094. } KFLOATING_SAVE, *PKFLOATING_SAVE;
  7095. //
  7096. // AMD64 Specific portions of mm component.
  7097. //
  7098. // Define the page size for the AMD64 as 4096 (0x1000).
  7099. //
  7100. #define PAGE_SIZE 0x1000
  7101. //
  7102. // Define the number of trailing zeroes in a page aligned virtual address.
  7103. // This is used as the shift count when shifting virtual addresses to
  7104. // virtual page numbers.
  7105. //
  7106. #define PAGE_SHIFT 12L
  7107. #define PXE_BASE 0xFFFFF6FB7DBED000UI64
  7108. #define PXE_SELFMAP 0xFFFFF6FB7DBEDF68UI64
  7109. #define PPE_BASE 0xFFFFF6FB7DA00000UI64
  7110. #define PDE_BASE 0xFFFFF6FB40000000UI64
  7111. #define PTE_BASE 0xFFFFF68000000000UI64
  7112. #define PXE_TOP 0xFFFFF6FB7DBEDFFFUI64
  7113. #define PPE_TOP 0xFFFFF6FB7DBFFFFFUI64
  7114. #define PDE_TOP 0xFFFFF6FB7FFFFFFFUI64
  7115. #define PTE_TOP 0xFFFFF6FFFFFFFFFFUI64
  7116. #define PDE_KTBASE_AMD64 PPE_BASE
  7117. #define PTI_SHIFT 12
  7118. #define PDI_SHIFT 21
  7119. #define PPI_SHIFT 30
  7120. #define PXI_SHIFT 39
  7121. #define PTE_PER_PAGE 512
  7122. #define PDE_PER_PAGE 512
  7123. #define PPE_PER_PAGE 512
  7124. #define PXE_PER_PAGE 512
  7125. #define PTI_MASK_AMD64 (PTE_PER_PAGE - 1)
  7126. #define PDI_MASK_AMD64 (PDE_PER_PAGE - 1)
  7127. #define PPI_MASK (PPE_PER_PAGE - 1)
  7128. #define PXI_MASK (PXE_PER_PAGE - 1)
  7129. //
  7130. // Define the highest user address and user probe address.
  7131. //
  7132. extern PVOID *MmHighestUserAddress;
  7133. extern PVOID *MmSystemRangeStart;
  7134. extern ULONG64 *MmUserProbeAddress;
  7135. #define MM_HIGHEST_USER_ADDRESS *MmHighestUserAddress
  7136. #define MM_SYSTEM_RANGE_START *MmSystemRangeStart
  7137. #define MM_USER_PROBE_ADDRESS *MmUserProbeAddress
  7138. //
  7139. // The lowest user address reserves the low 64k.
  7140. //
  7141. #define MM_LOWEST_USER_ADDRESS (PVOID)0x10000
  7142. //
  7143. // The lowest address for system space.
  7144. //
  7145. #define MM_LOWEST_SYSTEM_ADDRESS (PVOID)0xFFFF080000000000
  7146. #define MmGetProcedureAddress(Address) (Address)
  7147. #define MmLockPagableCodeSection(Address) MmLockPagableDataSection(Address)
  7148. //
  7149. // Intrinsic functions
  7150. //
  7151. #if defined(_M_AMD64) && !defined(RC_INVOKED) && !defined(MIDL_PASS)
  7152. //
  7153. // The following routines are provided for backward compatibility with old
  7154. // code. They are no longer the preferred way to accomplish these functions.
  7155. //
  7156. #if PRAGMA_DEPRECATED_DDK
  7157. #pragma deprecated(ExInterlockedIncrementLong) // Use InterlockedIncrement
  7158. #pragma deprecated(ExInterlockedDecrementLong) // Use InterlockedDecrement
  7159. #pragma deprecated(ExInterlockedExchangeUlong) // Use InterlockedExchange
  7160. #endif
  7161. #define RESULT_ZERO 0
  7162. #define RESULT_NEGATIVE 1
  7163. #define RESULT_POSITIVE 2
  7164. typedef enum _INTERLOCKED_RESULT {
  7165. ResultNegative = RESULT_NEGATIVE,
  7166. ResultZero = RESULT_ZERO,
  7167. ResultPositive = RESULT_POSITIVE
  7168. } INTERLOCKED_RESULT;
  7169. #define ExInterlockedDecrementLong(Addend, Lock) \
  7170. _ExInterlockedDecrementLong(Addend)
  7171. __forceinline
  7172. LONG
  7173. _ExInterlockedDecrementLong (
  7174. IN OUT PLONG Addend
  7175. )
  7176. {
  7177. LONG Result;
  7178. Result = InterlockedDecrement(Addend);
  7179. if (Result < 0) {
  7180. return ResultNegative;
  7181. } else if (Result > 0) {
  7182. return ResultPositive;
  7183. } else {
  7184. return ResultZero;
  7185. }
  7186. }
  7187. #define ExInterlockedIncrementLong(Addend, Lock) \
  7188. _ExInterlockedIncrementLong(Addend)
  7189. __forceinline
  7190. LONG
  7191. _ExInterlockedIncrementLong (
  7192. IN OUT PLONG Addend
  7193. )
  7194. {
  7195. LONG Result;
  7196. Result = InterlockedIncrement(Addend);
  7197. if (Result < 0) {
  7198. return ResultNegative;
  7199. } else if (Result > 0) {
  7200. return ResultPositive;
  7201. } else {
  7202. return ResultZero;
  7203. }
  7204. }
  7205. #define ExInterlockedExchangeUlong(Target, Value, Lock) \
  7206. _ExInterlockedExchangeUlong(Target, Value)
  7207. __forceinline
  7208. _ExInterlockedExchangeUlong (
  7209. IN OUT PULONG Target,
  7210. IN ULONG Value
  7211. )
  7212. {
  7213. return (ULONG)InterlockedExchange((PLONG)Target, (LONG)Value);
  7214. }
  7215. #endif // defined(_M_AMD64) && !defined(RC_INVOKED) && !defined(MIDL_PASS)
  7216. #if !defined(MIDL_PASS) && defined(_M_AMD64)
  7217. //
  7218. // AMD646 function prototype definitions
  7219. //
  7220. //
  7221. // Get the current processor number
  7222. //
  7223. __forceinline
  7224. ULONG
  7225. KeGetCurrentProcessorNumber (
  7226. VOID
  7227. )
  7228. {
  7229. return (ULONG)__readgsbyte(FIELD_OFFSET(KPCR, Number));
  7230. }
  7231. #endif // !defined(MIDL_PASS) && defined(_M_AMD64)
  7232. //++
  7233. //
  7234. //
  7235. // VOID
  7236. // KeMemoryBarrier (
  7237. // VOID
  7238. // )
  7239. //
  7240. // VOID
  7241. // KeMemoryBarrierWithoutFence (
  7242. // VOID
  7243. // )
  7244. //
  7245. //
  7246. // Routine Description:
  7247. //
  7248. // These functions order memory accesses as seen by other processors.
  7249. //
  7250. // Arguments:
  7251. //
  7252. // None.
  7253. //
  7254. // Return Value:
  7255. //
  7256. // None.
  7257. //
  7258. //--
  7259. #if !defined(_CROSS_PLATFORM_)
  7260. #ifdef __cplusplus
  7261. extern "C" {
  7262. #endif
  7263. VOID
  7264. _ReadWriteBarrier (
  7265. VOID
  7266. );
  7267. #pragma intrinsic(_ReadWriteBarrier)
  7268. #ifdef __cplusplus
  7269. }
  7270. #endif
  7271. #define KeMemoryBarrier() _ReadWriteBarrier()
  7272. #define KeMemoryBarrierWithoutFence() _ReadWriteBarrier()
  7273. #else
  7274. #define KeMemoryBarrier()
  7275. #define KeMemoryBarrierWithoutFence()
  7276. #endif
  7277. NTKERNELAPI
  7278. NTSTATUS
  7279. KeSaveFloatingPointState (
  7280. OUT PKFLOATING_SAVE SaveArea
  7281. );
  7282. NTKERNELAPI
  7283. NTSTATUS
  7284. KeRestoreFloatingPointState (
  7285. IN PKFLOATING_SAVE SaveArea
  7286. );
  7287. #endif // defined(_AMD64_)
  7288. #if defined(_AMD64_)
  7289. NTKERNELAPI
  7290. KIRQL
  7291. KeGetCurrentIrql (
  7292. VOID
  7293. );
  7294. NTKERNELAPI
  7295. VOID
  7296. KeLowerIrql (
  7297. IN KIRQL NewIrql
  7298. );
  7299. #define KeRaiseIrql(a,b) *(b) = KfRaiseIrql(a)
  7300. NTKERNELAPI
  7301. KIRQL
  7302. KfRaiseIrql (
  7303. IN KIRQL NewIrql
  7304. );
  7305. NTKERNELAPI
  7306. KIRQL
  7307. KeRaiseIrqlToDpcLevel (
  7308. VOID
  7309. );
  7310. NTKERNELAPI
  7311. KIRQL
  7312. KeRaiseIrqlToSynchLevel (
  7313. VOID
  7314. );
  7315. #endif // defined(_AMD64_)
  7316. #if defined(_IA64_)
  7317. //
  7318. // Types to use to contain PFNs and their counts.
  7319. //
  7320. typedef ULONG PFN_COUNT;
  7321. typedef LONG_PTR SPFN_NUMBER, *PSPFN_NUMBER;
  7322. typedef ULONG_PTR PFN_NUMBER, *PPFN_NUMBER;
  7323. //
  7324. // Indicate that the IA64 compiler supports the pragma textout construct.
  7325. //
  7326. #define ALLOC_PRAGMA 1
  7327. //
  7328. // Define intrinsic calls and their prototypes
  7329. //
  7330. #include "ia64reg.h"
  7331. #ifdef __cplusplus
  7332. extern "C" {
  7333. #endif
  7334. unsigned __int64 __getReg (int);
  7335. void __setReg (int, unsigned __int64);
  7336. void __isrlz (void);
  7337. void __dsrlz (void);
  7338. void __fwb (void);
  7339. void __mf (void);
  7340. void __mfa (void);
  7341. void __synci (void);
  7342. __int64 __thash (__int64);
  7343. __int64 __ttag (__int64);
  7344. void __ptcl (__int64, __int64);
  7345. void __ptcg (__int64, __int64);
  7346. void __ptcga (__int64, __int64);
  7347. void __ptri (__int64, __int64);
  7348. void __ptrd (__int64, __int64);
  7349. void __invalat (void);
  7350. void __break (int);
  7351. void __fc (__int64);
  7352. void __fci (__int64);
  7353. void __sum (int);
  7354. void __rsm (int);
  7355. void _ReleaseSpinLock( unsigned __int64 *);
  7356. void __yield();
  7357. void __lfetch(int, void const *);
  7358. void __lfetchfault(int, void const *);
  7359. #ifdef _M_IA64
  7360. #pragma intrinsic (__getReg)
  7361. #pragma intrinsic (__setReg)
  7362. #pragma intrinsic (__isrlz)
  7363. #pragma intrinsic (__dsrlz)
  7364. #pragma intrinsic (__fwb)
  7365. #pragma intrinsic (__mf)
  7366. #pragma intrinsic (__mfa)
  7367. #pragma intrinsic (__synci)
  7368. #pragma intrinsic (__thash)
  7369. #pragma intrinsic (__ttag)
  7370. #pragma intrinsic (__ptcl)
  7371. #pragma intrinsic (__ptcg)
  7372. #pragma intrinsic (__ptcga)
  7373. #pragma intrinsic (__ptri)
  7374. #pragma intrinsic (__ptrd)
  7375. #pragma intrinsic (__invalat)
  7376. #pragma intrinsic (__break)
  7377. #pragma intrinsic (__fc)
  7378. #pragma intrinsic (__fci)
  7379. #pragma intrinsic (__sum)
  7380. #pragma intrinsic (__rsm)
  7381. #pragma intrinsic (_ReleaseSpinLock)
  7382. #pragma intrinsic (__yield)
  7383. #pragma intrinsic (__lfetch)
  7384. #pragma intrinsic (__lfetchfault)
  7385. #endif // _M_IA64
  7386. #ifdef __cplusplus
  7387. }
  7388. #endif
  7389. //
  7390. // Define length of interrupt vector table.
  7391. //
  7392. #define MAXIMUM_VECTOR 256
  7393. //
  7394. // IA64 specific interlocked operation result values.
  7395. //
  7396. #define RESULT_ZERO 0
  7397. #define RESULT_NEGATIVE 1
  7398. #define RESULT_POSITIVE 2
  7399. //
  7400. // Interlocked result type is portable, but its values are machine specific.
  7401. // Constants for values are in i386.h, mips.h, etc.
  7402. //
  7403. typedef enum _INTERLOCKED_RESULT {
  7404. ResultNegative = RESULT_NEGATIVE,
  7405. ResultZero = RESULT_ZERO,
  7406. ResultPositive = RESULT_POSITIVE
  7407. } INTERLOCKED_RESULT;
  7408. //
  7409. // Convert portable interlock interfaces to architecture specific interfaces.
  7410. //
  7411. #if PRAGMA_DEPRECATED_DDK
  7412. #pragma deprecated(ExInterlockedIncrementLong) // Use InterlockedIncrement
  7413. #pragma deprecated(ExInterlockedDecrementLong) // Use InterlockedDecrement
  7414. #pragma deprecated(ExInterlockedExchangeUlong) // Use InterlockedExchange
  7415. #endif
  7416. #define ExInterlockedIncrementLong(Addend, Lock) \
  7417. ExIa64InterlockedIncrementLong(Addend)
  7418. #define ExInterlockedDecrementLong(Addend, Lock) \
  7419. ExIa64InterlockedDecrementLong(Addend)
  7420. #define ExInterlockedExchangeUlong(Target, Value, Lock) \
  7421. ExIa64InterlockedExchangeUlong(Target, Value)
  7422. NTKERNELAPI
  7423. INTERLOCKED_RESULT
  7424. ExIa64InterlockedIncrementLong (
  7425. IN PLONG Addend
  7426. );
  7427. NTKERNELAPI
  7428. INTERLOCKED_RESULT
  7429. ExIa64InterlockedDecrementLong (
  7430. IN PLONG Addend
  7431. );
  7432. NTKERNELAPI
  7433. ULONG
  7434. ExIa64InterlockedExchangeUlong (
  7435. IN PULONG Target,
  7436. IN ULONG Value
  7437. );
  7438. //
  7439. // IA64 Interrupt Definitions.
  7440. //
  7441. //
  7442. // Define length of interrupt object dispatch code in longwords.
  7443. //
  7444. #define DISPATCH_LENGTH 2*2 // Length of dispatch code template in 32-bit words
  7445. // Begin of a block of definitions that must be synchronized with kxia64.h.
  7446. //
  7447. //
  7448. // Define Interrupt Request Levels.
  7449. //
  7450. #define PASSIVE_LEVEL 0 // Passive release level
  7451. #define LOW_LEVEL 0 // Lowest interrupt level
  7452. #define APC_LEVEL 1 // APC interrupt level
  7453. #define DISPATCH_LEVEL 2 // Dispatcher level
  7454. #define CMC_LEVEL 3 // Correctable machine check level
  7455. #define DEVICE_LEVEL_BASE 4 // 4 - 11 - Device IRQLs
  7456. #define PC_LEVEL 12 // Performance Counter IRQL
  7457. #define IPI_LEVEL 14 // IPI IRQL
  7458. #define CLOCK_LEVEL 13 // Clock Timer IRQL
  7459. #define POWER_LEVEL 15 // Power failure level
  7460. #define PROFILE_LEVEL 15 // Profiling level
  7461. #define HIGH_LEVEL 15 // Highest interrupt level
  7462. #if defined(_M_IA64) && !defined(RC_INVOKED)
  7463. #define InterlockedAdd _InterlockedAdd
  7464. #define InterlockedIncrement _InterlockedIncrement
  7465. #define InterlockedIncrementAcquire _InterlockedIncrement_acq
  7466. #define InterlockedIncrementRelease _InterlockedIncrement_rel
  7467. #define InterlockedDecrement _InterlockedDecrement
  7468. #define InterlockedDecrementAcquire _InterlockedDecrement_acq
  7469. #define InterlockedDecrementRelease _InterlockedDecrement_rel
  7470. #define InterlockedExchange _InterlockedExchange
  7471. #define InterlockedExchangeAdd _InterlockedExchangeAdd
  7472. #define InterlockedAdd64 _InterlockedAdd64
  7473. #define InterlockedIncrement64 _InterlockedIncrement64
  7474. #define InterlockedDecrement64 _InterlockedDecrement64
  7475. #define InterlockedExchange64 _InterlockedExchange64
  7476. #define InterlockedExchangeAcquire64 _InterlockedExchange64_acq
  7477. #define InterlockedExchangeAdd64 _InterlockedExchangeAdd64
  7478. #define InterlockedCompareExchange64 _InterlockedCompareExchange64
  7479. #define InterlockedCompareExchangeAcquire64 _InterlockedCompareExchange64_acq
  7480. #define InterlockedCompareExchangeRelease64 _InterlockedCompareExchange64_rel
  7481. #define InterlockedCompareExchange _InterlockedCompareExchange
  7482. #define InterlockedCompareExchangeAcquire _InterlockedCompareExchange_acq
  7483. #define InterlockedCompareExchangeRelease _InterlockedCompareExchange_rel
  7484. #define InterlockedExchangePointer _InterlockedExchangePointer
  7485. #define InterlockedCompareExchangePointer _InterlockedCompareExchangePointer
  7486. #ifdef __cplusplus
  7487. extern "C" {
  7488. #endif
  7489. LONG
  7490. __cdecl
  7491. InterlockedAdd (
  7492. LONG volatile *Addend,
  7493. LONG Value
  7494. );
  7495. LONGLONG
  7496. __cdecl
  7497. InterlockedAdd64 (
  7498. LONGLONG volatile *Addend,
  7499. LONGLONG Value
  7500. );
  7501. LONG
  7502. __cdecl
  7503. InterlockedIncrement(
  7504. IN OUT LONG volatile *Addend
  7505. );
  7506. LONG
  7507. __cdecl
  7508. InterlockedDecrement(
  7509. IN OUT LONG volatile *Addend
  7510. );
  7511. LONG
  7512. __cdecl
  7513. InterlockedIncrementAcquire(
  7514. IN OUT LONG volatile *Addend
  7515. );
  7516. LONG
  7517. __cdecl
  7518. InterlockedDecrementAcquire(
  7519. IN OUT LONG volatile *Addend
  7520. );
  7521. LONG
  7522. __cdecl
  7523. InterlockedIncrementRelease(
  7524. IN OUT LONG volatile *Addend
  7525. );
  7526. LONG
  7527. __cdecl
  7528. InterlockedDecrementRelease(
  7529. IN OUT LONG volatile *Addend
  7530. );
  7531. LONG
  7532. __cdecl
  7533. InterlockedExchange(
  7534. IN OUT LONG volatile *Target,
  7535. IN LONG Value
  7536. );
  7537. LONG
  7538. __cdecl
  7539. InterlockedExchangeAdd(
  7540. IN OUT LONG volatile *Addend,
  7541. IN LONG Value
  7542. );
  7543. LONG
  7544. __cdecl
  7545. InterlockedCompareExchange (
  7546. IN OUT LONG volatile *Destination,
  7547. IN LONG ExChange,
  7548. IN LONG Comperand
  7549. );
  7550. LONG
  7551. __cdecl
  7552. InterlockedCompareExchangeRelease (
  7553. IN OUT LONG volatile *Destination,
  7554. IN LONG ExChange,
  7555. IN LONG Comperand
  7556. );
  7557. LONG
  7558. __cdecl
  7559. InterlockedCompareExchangeAcquire (
  7560. IN OUT LONG volatile *Destination,
  7561. IN LONG ExChange,
  7562. IN LONG Comperand
  7563. );
  7564. LONGLONG
  7565. __cdecl
  7566. InterlockedIncrement64(
  7567. IN OUT LONGLONG volatile *Addend
  7568. );
  7569. LONGLONG
  7570. __cdecl
  7571. InterlockedDecrement64(
  7572. IN OUT LONGLONG volatile *Addend
  7573. );
  7574. LONGLONG
  7575. __cdecl
  7576. InterlockedExchange64(
  7577. IN OUT LONGLONG volatile *Target,
  7578. IN LONGLONG Value
  7579. );
  7580. LONGLONG
  7581. __cdecl
  7582. InterlockedExchangeAcquire64(
  7583. IN OUT LONGLONG volatile *Target,
  7584. IN LONGLONG Value
  7585. );
  7586. LONGLONG
  7587. __cdecl
  7588. InterlockedExchangeAdd64(
  7589. IN OUT LONGLONG volatile *Addend,
  7590. IN LONGLONG Value
  7591. );
  7592. LONGLONG
  7593. __cdecl
  7594. InterlockedCompareExchange64 (
  7595. IN OUT LONGLONG volatile *Destination,
  7596. IN LONGLONG ExChange,
  7597. IN LONGLONG Comperand
  7598. );
  7599. LONGLONG
  7600. __cdecl
  7601. InterlockedCompareExchangeAcquire64 (
  7602. IN OUT LONGLONG volatile *Destination,
  7603. IN LONGLONG ExChange,
  7604. IN LONGLONG Comperand
  7605. );
  7606. LONGLONG
  7607. __cdecl
  7608. InterlockedCompareExchangeRelease64 (
  7609. IN OUT LONGLONG volatile *Destination,
  7610. IN LONGLONG ExChange,
  7611. IN LONGLONG Comperand
  7612. );
  7613. PVOID
  7614. __cdecl
  7615. InterlockedCompareExchangePointer (
  7616. IN OUT PVOID volatile *Destination,
  7617. IN PVOID Exchange,
  7618. IN PVOID Comperand
  7619. );
  7620. PVOID
  7621. __cdecl
  7622. InterlockedExchangePointer(
  7623. IN OUT PVOID volatile *Target,
  7624. IN PVOID Value
  7625. );
  7626. #if !defined (InterlockedAnd64)
  7627. #define InterlockedAnd64 InterlockedAnd64_Inline
  7628. LONGLONG
  7629. FORCEINLINE
  7630. InterlockedAnd64_Inline (
  7631. IN OUT LONGLONG volatile *Destination,
  7632. IN LONGLONG Value
  7633. )
  7634. {
  7635. LONGLONG Old;
  7636. do {
  7637. Old = *Destination;
  7638. } while (InterlockedCompareExchange64(Destination,
  7639. Old & Value,
  7640. Old) != Old);
  7641. return Old;
  7642. }
  7643. #endif
  7644. #if !defined (InterlockedOr64)
  7645. #define InterlockedOr64 InterlockedOr64_Inline
  7646. LONGLONG
  7647. FORCEINLINE
  7648. InterlockedOr64_Inline (
  7649. IN OUT LONGLONG volatile *Destination,
  7650. IN LONGLONG Value
  7651. )
  7652. {
  7653. LONGLONG Old;
  7654. do {
  7655. Old = *Destination;
  7656. } while (InterlockedCompareExchange64(Destination,
  7657. Old | Value,
  7658. Old) != Old);
  7659. return Old;
  7660. }
  7661. #endif
  7662. #if !defined (InterlockedXor64)
  7663. #define InterlockedXor64 InterlockedXor64_Inline
  7664. LONGLONG
  7665. FORCEINLINE
  7666. InterlockedXor64_Inline (
  7667. IN OUT LONGLONG volatile *Destination,
  7668. IN LONGLONG Value
  7669. )
  7670. {
  7671. LONGLONG Old;
  7672. do {
  7673. Old = *Destination;
  7674. } while (InterlockedCompareExchange64(Destination,
  7675. Old ^ Value,
  7676. Old) != Old);
  7677. return Old;
  7678. }
  7679. #endif
  7680. #pragma intrinsic(_InterlockedAdd)
  7681. #pragma intrinsic(_InterlockedIncrement)
  7682. #pragma intrinsic(_InterlockedIncrement_acq)
  7683. #pragma intrinsic(_InterlockedIncrement_rel)
  7684. #pragma intrinsic(_InterlockedDecrement)
  7685. #pragma intrinsic(_InterlockedDecrement_acq)
  7686. #pragma intrinsic(_InterlockedDecrement_rel)
  7687. #pragma intrinsic(_InterlockedExchange)
  7688. #pragma intrinsic(_InterlockedCompareExchange)
  7689. #pragma intrinsic(_InterlockedCompareExchange_acq)
  7690. #pragma intrinsic(_InterlockedCompareExchange_rel)
  7691. #pragma intrinsic(_InterlockedExchangeAdd)
  7692. #pragma intrinsic(_InterlockedAdd64)
  7693. #pragma intrinsic(_InterlockedIncrement64)
  7694. #pragma intrinsic(_InterlockedDecrement64)
  7695. #pragma intrinsic(_InterlockedExchange64)
  7696. #pragma intrinsic(_InterlockedExchange64_acq)
  7697. #pragma intrinsic(_InterlockedCompareExchange64)
  7698. #pragma intrinsic(_InterlockedCompareExchange64_acq)
  7699. #pragma intrinsic(_InterlockedCompareExchange64_rel)
  7700. #pragma intrinsic(_InterlockedExchangeAdd64)
  7701. #pragma intrinsic(_InterlockedExchangePointer)
  7702. #pragma intrinsic(_InterlockedCompareExchangePointer)
  7703. #ifdef __cplusplus
  7704. }
  7705. #endif
  7706. #endif // defined(_M_IA64) && !defined(RC_INVOKED)
  7707. __forceinline
  7708. LONG
  7709. InterlockedAnd (
  7710. IN OUT LONG volatile *Target,
  7711. LONG Set
  7712. )
  7713. {
  7714. LONG i;
  7715. LONG j;
  7716. j = *Target;
  7717. do {
  7718. i = j;
  7719. j = InterlockedCompareExchange(Target,
  7720. i & Set,
  7721. i);
  7722. } while (i != j);
  7723. return j;
  7724. }
  7725. __forceinline
  7726. LONG
  7727. InterlockedOr (
  7728. IN OUT LONG volatile *Target,
  7729. IN LONG Set
  7730. )
  7731. {
  7732. LONG i;
  7733. LONG j;
  7734. j = *Target;
  7735. do {
  7736. i = j;
  7737. j = InterlockedCompareExchange(Target,
  7738. i | Set,
  7739. i);
  7740. } while (i != j);
  7741. return j;
  7742. }
  7743. __forceinline
  7744. LONG
  7745. InterlockedXor (
  7746. IN OUT LONG volatile *Target,
  7747. IN LONG Set
  7748. )
  7749. {
  7750. LONG i;
  7751. LONG j;
  7752. j = *Target;
  7753. do {
  7754. i = j;
  7755. j = InterlockedCompareExchange(Target,
  7756. i ^ Set,
  7757. i);
  7758. } while (i != j);
  7759. return j;
  7760. }
  7761. #define KI_USER_SHARED_DATA ((ULONG_PTR)(KADDRESS_BASE + 0xFFFE0000))
  7762. #define SharedUserData ((KUSER_SHARED_DATA * const)KI_USER_SHARED_DATA)
  7763. //
  7764. // Get address of processor control region.
  7765. //
  7766. #define KeGetPcr() PCR
  7767. //
  7768. // Get address of current kernel thread object.
  7769. //
  7770. #if defined(_M_IA64)
  7771. #define KeGetCurrentThread() PCR->CurrentThread
  7772. #endif
  7773. //
  7774. // Get current processor number.
  7775. //
  7776. #define KeGetCurrentProcessorNumber() ((ULONG)(PCR->Number))
  7777. //
  7778. // Get data cache fill size.
  7779. //
  7780. #if PRAGMA_DEPRECATED_DDK
  7781. #pragma deprecated(KeGetDcacheFillSize) // Use GetDmaAlignment
  7782. #endif
  7783. #define KeGetDcacheFillSize() PCR->DcacheFillSize
  7784. #define KeSaveFloatingPointState(a) STATUS_SUCCESS
  7785. #define KeRestoreFloatingPointState(a) STATUS_SUCCESS
  7786. //
  7787. //
  7788. // VOID
  7789. // KeMemoryBarrierWithoutFence (
  7790. // VOID
  7791. // )
  7792. //
  7793. //
  7794. // Routine Description:
  7795. //
  7796. // This function cases ordering of memory acceses generated by the compiler.
  7797. //
  7798. //
  7799. // Arguments:
  7800. //
  7801. // None.
  7802. //
  7803. // Return Value:
  7804. //
  7805. // None.
  7806. //--
  7807. #ifdef __cplusplus
  7808. extern "C" {
  7809. #endif
  7810. VOID
  7811. _ReadWriteBarrier (
  7812. VOID
  7813. );
  7814. #ifdef __cplusplus
  7815. }
  7816. #endif
  7817. #pragma intrinsic(_ReadWriteBarrier)
  7818. #define KeMemoryBarrierWithoutFence() _ReadWriteBarrier()
  7819. //++
  7820. //
  7821. //
  7822. // VOID
  7823. // KeMemoryBarrier (
  7824. // VOID
  7825. // )
  7826. //
  7827. //
  7828. // Routine Description:
  7829. //
  7830. // This function cases ordering of memory acceses as generated by the compiler and
  7831. // as seen by other processors.
  7832. //
  7833. //
  7834. // Arguments:
  7835. //
  7836. // None.
  7837. //
  7838. // Return Value:
  7839. //
  7840. // None.
  7841. //--
  7842. #define KE_MEMORY_BARRIER_REQUIRED
  7843. #define KeMemoryBarrier() {_ReadWriteBarrier();__mf ();_ReadWriteBarrier();}
  7844. //
  7845. // Define the page size
  7846. //
  7847. #define PAGE_SIZE 0x2000
  7848. //
  7849. // Define the number of trailing zeroes in a page aligned virtual address.
  7850. // This is used as the shift count when shifting virtual addresses to
  7851. // virtual page numbers.
  7852. //
  7853. #define PAGE_SHIFT 13L
  7854. //
  7855. // Cache and write buffer flush functions.
  7856. //
  7857. NTKERNELAPI
  7858. VOID
  7859. KeFlushIoBuffers (
  7860. IN PMDL Mdl,
  7861. IN BOOLEAN ReadOperation,
  7862. IN BOOLEAN DmaOperation
  7863. );
  7864. //
  7865. // Kernel breakin breakpoint
  7866. //
  7867. VOID
  7868. KeBreakinBreakpoint (
  7869. VOID
  7870. );
  7871. #define ExAcquireSpinLock(Lock, OldIrql) KeAcquireSpinLock((Lock), (OldIrql))
  7872. #define ExReleaseSpinLock(Lock, OldIrql) KeReleaseSpinLock((Lock), (OldIrql))
  7873. #define ExAcquireSpinLockAtDpcLevel(Lock) KeAcquireSpinLockAtDpcLevel(Lock)
  7874. #define ExReleaseSpinLockFromDpcLevel(Lock) KeReleaseSpinLockFromDpcLevel(Lock)
  7875. #if defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_)
  7876. #define KeQueryTickCount(CurrentCount ) \
  7877. *(PULONGLONG)(CurrentCount) = **((volatile ULONGLONG **)(&KeTickCount));
  7878. #else
  7879. NTKERNELAPI
  7880. VOID
  7881. KeQueryTickCount (
  7882. OUT PLARGE_INTEGER CurrentCount
  7883. );
  7884. #endif // defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_)
  7885. //
  7886. // I/O space read and write macros.
  7887. //
  7888. NTHALAPI
  7889. UCHAR
  7890. READ_PORT_UCHAR (
  7891. PUCHAR RegisterAddress
  7892. );
  7893. NTHALAPI
  7894. USHORT
  7895. READ_PORT_USHORT (
  7896. PUSHORT RegisterAddress
  7897. );
  7898. NTHALAPI
  7899. ULONG
  7900. READ_PORT_ULONG (
  7901. PULONG RegisterAddress
  7902. );
  7903. NTHALAPI
  7904. VOID
  7905. READ_PORT_BUFFER_UCHAR (
  7906. PUCHAR portAddress,
  7907. PUCHAR readBuffer,
  7908. ULONG readCount
  7909. );
  7910. NTHALAPI
  7911. VOID
  7912. READ_PORT_BUFFER_USHORT (
  7913. PUSHORT portAddress,
  7914. PUSHORT readBuffer,
  7915. ULONG readCount
  7916. );
  7917. NTHALAPI
  7918. VOID
  7919. READ_PORT_BUFFER_ULONG (
  7920. PULONG portAddress,
  7921. PULONG readBuffer,
  7922. ULONG readCount
  7923. );
  7924. NTHALAPI
  7925. VOID
  7926. WRITE_PORT_UCHAR (
  7927. PUCHAR portAddress,
  7928. UCHAR Data
  7929. );
  7930. NTHALAPI
  7931. VOID
  7932. WRITE_PORT_USHORT (
  7933. PUSHORT portAddress,
  7934. USHORT Data
  7935. );
  7936. NTHALAPI
  7937. VOID
  7938. WRITE_PORT_ULONG (
  7939. PULONG portAddress,
  7940. ULONG Data
  7941. );
  7942. NTHALAPI
  7943. VOID
  7944. WRITE_PORT_BUFFER_UCHAR (
  7945. PUCHAR portAddress,
  7946. PUCHAR writeBuffer,
  7947. ULONG writeCount
  7948. );
  7949. NTHALAPI
  7950. VOID
  7951. WRITE_PORT_BUFFER_USHORT (
  7952. PUSHORT portAddress,
  7953. PUSHORT writeBuffer,
  7954. ULONG writeCount
  7955. );
  7956. NTHALAPI
  7957. VOID
  7958. WRITE_PORT_BUFFER_ULONG (
  7959. PULONG portAddress,
  7960. PULONG writeBuffer,
  7961. ULONG writeCount
  7962. );
  7963. #define READ_REGISTER_UCHAR(x) \
  7964. (__mf(), *(volatile UCHAR * const)(x))
  7965. #define READ_REGISTER_USHORT(x) \
  7966. (__mf(), *(volatile USHORT * const)(x))
  7967. #define READ_REGISTER_ULONG(x) \
  7968. (__mf(), *(volatile ULONG * const)(x))
  7969. #define READ_REGISTER_BUFFER_UCHAR(x, y, z) { \
  7970. PUCHAR registerBuffer = x; \
  7971. PUCHAR readBuffer = y; \
  7972. ULONG readCount; \
  7973. __mf(); \
  7974. for (readCount = z; readCount--; readBuffer++, registerBuffer++) { \
  7975. *readBuffer = *(volatile UCHAR * const)(registerBuffer); \
  7976. } \
  7977. }
  7978. #define READ_REGISTER_BUFFER_USHORT(x, y, z) { \
  7979. PUSHORT registerBuffer = x; \
  7980. PUSHORT readBuffer = y; \
  7981. ULONG readCount; \
  7982. __mf(); \
  7983. for (readCount = z; readCount--; readBuffer++, registerBuffer++) { \
  7984. *readBuffer = *(volatile USHORT * const)(registerBuffer); \
  7985. } \
  7986. }
  7987. #define READ_REGISTER_BUFFER_ULONG(x, y, z) { \
  7988. PULONG registerBuffer = x; \
  7989. PULONG readBuffer = y; \
  7990. ULONG readCount; \
  7991. __mf(); \
  7992. for (readCount = z; readCount--; readBuffer++, registerBuffer++) { \
  7993. *readBuffer = *(volatile ULONG * const)(registerBuffer); \
  7994. } \
  7995. }
  7996. #define WRITE_REGISTER_UCHAR(x, y) { \
  7997. *(volatile UCHAR * const)(x) = y; \
  7998. KeFlushWriteBuffer(); \
  7999. }
  8000. #define WRITE_REGISTER_USHORT(x, y) { \
  8001. *(volatile USHORT * const)(x) = y; \
  8002. KeFlushWriteBuffer(); \
  8003. }
  8004. #define WRITE_REGISTER_ULONG(x, y) { \
  8005. *(volatile ULONG * const)(x) = y; \
  8006. KeFlushWriteBuffer(); \
  8007. }
  8008. #define WRITE_REGISTER_BUFFER_UCHAR(x, y, z) { \
  8009. PUCHAR registerBuffer = x; \
  8010. PUCHAR writeBuffer = y; \
  8011. ULONG writeCount; \
  8012. for (writeCount = z; writeCount--; writeBuffer++, registerBuffer++) { \
  8013. *(volatile UCHAR * const)(registerBuffer) = *writeBuffer; \
  8014. } \
  8015. KeFlushWriteBuffer(); \
  8016. }
  8017. #define WRITE_REGISTER_BUFFER_USHORT(x, y, z) { \
  8018. PUSHORT registerBuffer = x; \
  8019. PUSHORT writeBuffer = y; \
  8020. ULONG writeCount; \
  8021. for (writeCount = z; writeCount--; writeBuffer++, registerBuffer++) { \
  8022. *(volatile USHORT * const)(registerBuffer) = *writeBuffer; \
  8023. } \
  8024. KeFlushWriteBuffer(); \
  8025. }
  8026. #define WRITE_REGISTER_BUFFER_ULONG(x, y, z) { \
  8027. PULONG registerBuffer = x; \
  8028. PULONG writeBuffer = y; \
  8029. ULONG writeCount; \
  8030. for (writeCount = z; writeCount--; writeBuffer++, registerBuffer++) { \
  8031. *(volatile ULONG * const)(registerBuffer) = *writeBuffer; \
  8032. } \
  8033. KeFlushWriteBuffer(); \
  8034. }
  8035. //
  8036. // Non-volatile floating point state
  8037. //
  8038. typedef struct _KFLOATING_SAVE {
  8039. ULONG Reserved;
  8040. } KFLOATING_SAVE, *PKFLOATING_SAVE;
  8041. //
  8042. // Define Processor Control Region Structure.
  8043. //
  8044. #define PCR_MINOR_VERSION 1
  8045. #define PCR_MAJOR_VERSION 1
  8046. typedef struct _KPCR {
  8047. //
  8048. // Major and minor version numbers of the PCR.
  8049. //
  8050. ULONG MinorVersion;
  8051. ULONG MajorVersion;
  8052. //
  8053. // Start of the architecturally defined section of the PCR. This section
  8054. // may be directly addressed by vendor/platform specific HAL code and will
  8055. // not change from version to version of NT.
  8056. //
  8057. //
  8058. // First and second level cache parameters.
  8059. //
  8060. ULONG FirstLevelDcacheSize;
  8061. ULONG FirstLevelDcacheFillSize;
  8062. ULONG FirstLevelIcacheSize;
  8063. ULONG FirstLevelIcacheFillSize;
  8064. ULONG SecondLevelDcacheSize;
  8065. ULONG SecondLevelDcacheFillSize;
  8066. ULONG SecondLevelIcacheSize;
  8067. ULONG SecondLevelIcacheFillSize;
  8068. //
  8069. // Data cache alignment and fill size used for cache flushing and alignment.
  8070. // These fields are set to the larger of the first and second level data
  8071. // cache fill sizes.
  8072. //
  8073. ULONG DcacheAlignment;
  8074. ULONG DcacheFillSize;
  8075. //
  8076. // Instruction cache alignment and fill size used for cache flushing and
  8077. // alignment. These fields are set to the larger of the first and second
  8078. // level data cache fill sizes.
  8079. //
  8080. ULONG IcacheAlignment;
  8081. ULONG IcacheFillSize;
  8082. //
  8083. // Processor identification from PrId register.
  8084. //
  8085. ULONG ProcessorId;
  8086. //
  8087. // Profiling data.
  8088. //
  8089. ULONG ProfileInterval;
  8090. ULONG ProfileCount;
  8091. //
  8092. // Stall execution count and scale factor.
  8093. //
  8094. ULONG StallExecutionCount;
  8095. ULONG StallScaleFactor;
  8096. ULONG InterruptionCount;
  8097. //
  8098. // Space reserved for the system.
  8099. //
  8100. ULONGLONG SystemReserved[6];
  8101. //
  8102. // Space reserved for the HAL
  8103. //
  8104. ULONGLONG HalReserved[64];
  8105. //
  8106. // IRQL mapping tables.
  8107. //
  8108. UCHAR IrqlMask[64];
  8109. UCHAR IrqlTable[64];
  8110. //
  8111. // External Interrupt vectors.
  8112. //
  8113. PKINTERRUPT_ROUTINE InterruptRoutine[MAXIMUM_VECTOR];
  8114. //
  8115. // Reserved interrupt vector mask.
  8116. //
  8117. ULONG ReservedVectors;
  8118. //
  8119. // Processor affinity mask.
  8120. //
  8121. KAFFINITY SetMember;
  8122. //
  8123. // Complement of the processor affinity mask.
  8124. //
  8125. KAFFINITY NotMember;
  8126. //
  8127. // Pointer to processor control block.
  8128. //
  8129. struct _KPRCB *Prcb;
  8130. //
  8131. // Shadow copy of Prcb->CurrentThread for fast access
  8132. //
  8133. struct _KTHREAD *CurrentThread;
  8134. //
  8135. // Processor number.
  8136. //
  8137. CCHAR Number; // Processor Number
  8138. } KPCR, *PKPCR;
  8139. NTKERNELAPI
  8140. KIRQL
  8141. KeGetCurrentIrql();
  8142. NTKERNELAPI
  8143. VOID
  8144. KeLowerIrql (
  8145. IN KIRQL NewIrql
  8146. );
  8147. NTKERNELAPI
  8148. VOID
  8149. KeRaiseIrql (
  8150. IN KIRQL NewIrql,
  8151. OUT PKIRQL OldIrql
  8152. );
  8153. NTKERNELAPI
  8154. KIRQL
  8155. KeRaiseIrqlToDpcLevel (
  8156. VOID
  8157. );
  8158. NTKERNELAPI
  8159. KIRQL
  8160. KeRaiseIrqlToSynchLevel (
  8161. VOID
  8162. );
  8163. //
  8164. // The highest user address reserves 64K bytes for a guard page. This
  8165. // the probing of address from kernel mode to only have to check the
  8166. // starting address for structures of 64k bytes or less.
  8167. //
  8168. extern NTKERNELAPI PVOID MmHighestUserAddress;
  8169. extern NTKERNELAPI PVOID MmSystemRangeStart;
  8170. extern NTKERNELAPI ULONG_PTR MmUserProbeAddress;
  8171. #define MM_HIGHEST_USER_ADDRESS MmHighestUserAddress
  8172. #define MM_USER_PROBE_ADDRESS MmUserProbeAddress
  8173. #define MM_SYSTEM_RANGE_START MmSystemRangeStart
  8174. //
  8175. // The lowest user address reserves the low 64k.
  8176. //
  8177. #define MM_LOWEST_USER_ADDRESS (PVOID)((ULONG_PTR)(UADDRESS_BASE+0x00010000))
  8178. #define MmGetProcedureAddress(Address) (Address)
  8179. #define MmLockPagableCodeSection(PLabelAddress) \
  8180. MmLockPagableDataSection((PVOID)(*((PULONGLONG)PLabelAddress)))
  8181. #define VRN_MASK 0xE000000000000000UI64 // Virtual Region Number mask
  8182. //
  8183. // The lowest address for system space.
  8184. //
  8185. #define MM_LOWEST_SYSTEM_ADDRESS ((PVOID)((ULONG_PTR)(KADDRESS_BASE + 0xC0C00000)))
  8186. #endif // defined(_IA64_)
  8187. //
  8188. // Event Specific Access Rights.
  8189. //
  8190. #define EVENT_QUERY_STATE 0x0001
  8191. #define EVENT_MODIFY_STATE 0x0002
  8192. #define EVENT_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE|0x3)
  8193. //
  8194. // Semaphore Specific Access Rights.
  8195. //
  8196. #define SEMAPHORE_QUERY_STATE 0x0001
  8197. #define SEMAPHORE_MODIFY_STATE 0x0002
  8198. #define SEMAPHORE_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE|0x3)
  8199. //
  8200. // Timer APC routine definition.
  8201. //
  8202. typedef
  8203. VOID
  8204. (*PTIMER_APC_ROUTINE) (
  8205. IN PVOID TimerContext,
  8206. IN ULONG TimerLowValue,
  8207. IN LONG TimerHighValue
  8208. );
  8209. //
  8210. // Driver Verifier Definitions
  8211. //
  8212. typedef ULONG_PTR (*PDRIVER_VERIFIER_THUNK_ROUTINE) (
  8213. IN PVOID Context
  8214. );
  8215. //
  8216. // This structure is passed in by drivers that want to thunk callers of
  8217. // their exports.
  8218. //
  8219. typedef struct _DRIVER_VERIFIER_THUNK_PAIRS {
  8220. PDRIVER_VERIFIER_THUNK_ROUTINE PristineRoutine;
  8221. PDRIVER_VERIFIER_THUNK_ROUTINE NewRoutine;
  8222. } DRIVER_VERIFIER_THUNK_PAIRS, *PDRIVER_VERIFIER_THUNK_PAIRS;
  8223. //
  8224. // Driver Verifier flags.
  8225. //
  8226. #define DRIVER_VERIFIER_SPECIAL_POOLING 0x0001
  8227. #define DRIVER_VERIFIER_FORCE_IRQL_CHECKING 0x0002
  8228. #define DRIVER_VERIFIER_INJECT_ALLOCATION_FAILURES 0x0004
  8229. #define DRIVER_VERIFIER_TRACK_POOL_ALLOCATIONS 0x0008
  8230. #define DRIVER_VERIFIER_IO_CHECKING 0x0010
  8231. //
  8232. // Defined processor features
  8233. //
  8234. #define PF_FLOATING_POINT_PRECISION_ERRATA 0
  8235. #define PF_FLOATING_POINT_EMULATED 1
  8236. #define PF_COMPARE_EXCHANGE_DOUBLE 2
  8237. #define PF_MMX_INSTRUCTIONS_AVAILABLE 3
  8238. #define PF_PPC_MOVEMEM_64BIT_OK 4
  8239. #define PF_ALPHA_BYTE_INSTRUCTIONS 5
  8240. #define PF_XMMI_INSTRUCTIONS_AVAILABLE 6
  8241. #define PF_3DNOW_INSTRUCTIONS_AVAILABLE 7
  8242. #define PF_RDTSC_INSTRUCTION_AVAILABLE 8
  8243. #define PF_PAE_ENABLED 9
  8244. #define PF_XMMI64_INSTRUCTIONS_AVAILABLE 10
  8245. typedef enum _ALTERNATIVE_ARCHITECTURE_TYPE {
  8246. StandardDesign, // None == 0 == standard design
  8247. NEC98x86, // NEC PC98xx series on X86
  8248. EndAlternatives // past end of known alternatives
  8249. } ALTERNATIVE_ARCHITECTURE_TYPE;
  8250. // correctly define these run-time definitions for non X86 machines
  8251. #ifndef _X86_
  8252. #ifndef IsNEC_98
  8253. #define IsNEC_98 (FALSE)
  8254. #endif
  8255. #ifndef IsNotNEC_98
  8256. #define IsNotNEC_98 (TRUE)
  8257. #endif
  8258. #ifndef SetNEC_98
  8259. #define SetNEC_98
  8260. #endif
  8261. #ifndef SetNotNEC_98
  8262. #define SetNotNEC_98
  8263. #endif
  8264. #endif
  8265. #define PROCESSOR_FEATURE_MAX 64
  8266. #if defined(REMOTE_BOOT)
  8267. //
  8268. // Defined system flags.
  8269. //
  8270. /* the following two lines should be tagged with "winnt" when REMOTE_BOOT is on. */
  8271. #define SYSTEM_FLAG_REMOTE_BOOT_CLIENT 0x00000001
  8272. #define SYSTEM_FLAG_DISKLESS_CLIENT 0x00000002
  8273. #endif // defined(REMOTE_BOOT)
  8274. //
  8275. // Define data shared between kernel and user mode.
  8276. //
  8277. // N.B. User mode has read only access to this data
  8278. //
  8279. #ifdef _MAC
  8280. #pragma warning( disable : 4121)
  8281. #endif
  8282. //
  8283. // WARNING: This structure must have exactly the same layout for 32- and
  8284. // 64-bit systems. The layout of this structure cannot change and new
  8285. // fields can only be added to the end of the structure. Deprecated
  8286. // fields cannot be deleted. Platform specific fields are included on
  8287. // all systems.
  8288. //
  8289. // Layout exactness is required for Wow64 support of 32bit applications
  8290. // on Win64 systems.
  8291. //
  8292. // The layout itself cannot change since this sturcture has been exported
  8293. // in ntddk, ntifs.h, and nthal.h for some time.
  8294. //
  8295. typedef struct _KUSER_SHARED_DATA {
  8296. //
  8297. // Current low 32-bit of tick count and tick count multiplier.
  8298. //
  8299. // N.B. The tick count is updated each time the clock ticks.
  8300. //
  8301. ULONG TickCountLowDeprecated;
  8302. ULONG TickCountMultiplier;
  8303. //
  8304. // Current 64-bit interrupt time in 100ns units.
  8305. //
  8306. volatile KSYSTEM_TIME InterruptTime;
  8307. //
  8308. // Current 64-bit system time in 100ns units.
  8309. //
  8310. volatile KSYSTEM_TIME SystemTime;
  8311. //
  8312. // Current 64-bit time zone bias.
  8313. //
  8314. volatile KSYSTEM_TIME TimeZoneBias;
  8315. //
  8316. // Support image magic number range for the host system.
  8317. //
  8318. // N.B. This is an inclusive range.
  8319. //
  8320. USHORT ImageNumberLow;
  8321. USHORT ImageNumberHigh;
  8322. //
  8323. // Copy of system root in Unicode
  8324. //
  8325. WCHAR NtSystemRoot[ 260 ];
  8326. //
  8327. // Maximum stack trace depth if tracing enabled.
  8328. //
  8329. ULONG MaxStackTraceDepth;
  8330. //
  8331. // Crypto Exponent
  8332. //
  8333. ULONG CryptoExponent;
  8334. //
  8335. // TimeZoneId
  8336. //
  8337. ULONG TimeZoneId;
  8338. ULONG LargePageMinimum;
  8339. ULONG Reserved2[ 7 ];
  8340. //
  8341. // product type
  8342. //
  8343. NT_PRODUCT_TYPE NtProductType;
  8344. BOOLEAN ProductTypeIsValid;
  8345. //
  8346. // NT Version. Note that each process sees a version from its PEB, but
  8347. // if the process is running with an altered view of the system version,
  8348. // the following two fields are used to correctly identify the version
  8349. //
  8350. ULONG NtMajorVersion;
  8351. ULONG NtMinorVersion;
  8352. //
  8353. // Processor Feature Bits
  8354. //
  8355. BOOLEAN ProcessorFeatures[PROCESSOR_FEATURE_MAX];
  8356. //
  8357. // Reserved fields - do not use
  8358. //
  8359. ULONG Reserved1;
  8360. ULONG Reserved3;
  8361. //
  8362. // Time slippage while in debugger
  8363. //
  8364. volatile ULONG TimeSlip;
  8365. //
  8366. // Alternative system architecture. Example: NEC PC98xx on x86
  8367. //
  8368. ALTERNATIVE_ARCHITECTURE_TYPE AlternativeArchitecture;
  8369. //
  8370. // If the system is an evaluation unit, the following field contains the
  8371. // date and time that the evaluation unit expires. A value of 0 indicates
  8372. // that there is no expiration. A non-zero value is the UTC absolute time
  8373. // that the system expires.
  8374. //
  8375. LARGE_INTEGER SystemExpirationDate;
  8376. //
  8377. // Suite Support
  8378. //
  8379. ULONG SuiteMask;
  8380. //
  8381. // TRUE if a kernel debugger is connected/enabled
  8382. //
  8383. BOOLEAN KdDebuggerEnabled;
  8384. //
  8385. // Current console session Id. Always zero on non-TS systems
  8386. //
  8387. volatile ULONG ActiveConsoleId;
  8388. //
  8389. // Force-dismounts cause handles to become invalid. Rather than
  8390. // always probe handles, we maintain a serial number of
  8391. // dismounts that clients can use to see if they need to probe
  8392. // handles.
  8393. //
  8394. volatile ULONG DismountCount;
  8395. //
  8396. // This field indicates the status of the 64-bit COM+ package on the system.
  8397. // It indicates whether the Itermediate Language (IL) COM+ images need to
  8398. // use the 64-bit COM+ runtime or the 32-bit COM+ runtime.
  8399. //
  8400. ULONG ComPlusPackage;
  8401. //
  8402. // Time in tick count for system-wide last user input across all
  8403. // terminal sessions. For MP performance, it is not updated all
  8404. // the time (e.g. once a minute per session). It is used for idle
  8405. // detection.
  8406. //
  8407. ULONG LastSystemRITEventTickCount;
  8408. //
  8409. // Number of physical pages in the system. This can dynamically
  8410. // change as physical memory can be added or removed from a running
  8411. // system.
  8412. //
  8413. ULONG NumberOfPhysicalPages;
  8414. //
  8415. // True if the system was booted in safe boot mode.
  8416. //
  8417. BOOLEAN SafeBootMode;
  8418. //
  8419. // The following field is used for Heap and CritSec Tracing
  8420. // The last bit is set for Critical Sec Collision tracing and
  8421. // second Last bit is for Heap Tracing
  8422. // Also the first 16 bits are used as counter.
  8423. //
  8424. ULONG TraceLogging;
  8425. //
  8426. // Depending on the processor, the code for fast system call
  8427. // will differ, the following buffer is filled with the appropriate
  8428. // code sequence and user mode code will branch through it.
  8429. //
  8430. // (32 bytes, using ULONGLONG for alignment).
  8431. //
  8432. // N.B. The following two fields are only used on 32-bit systems.
  8433. //
  8434. ULONGLONG Fill0; // alignment
  8435. ULONGLONG SystemCall[4];
  8436. //
  8437. // The 64-bit tick count.
  8438. //
  8439. union {
  8440. volatile KSYSTEM_TIME TickCount;
  8441. volatile ULONG64 TickCountQuad;
  8442. };
  8443. } KUSER_SHARED_DATA, *PKUSER_SHARED_DATA;
  8444. #ifdef _MAC
  8445. #pragma warning( default : 4121 )
  8446. #endif
  8447. //
  8448. // Predefined Value Types.
  8449. //
  8450. #define REG_NONE ( 0 ) // No value type
  8451. #define REG_SZ ( 1 ) // Unicode nul terminated string
  8452. #define REG_EXPAND_SZ ( 2 ) // Unicode nul terminated string
  8453. // (with environment variable references)
  8454. #define REG_BINARY ( 3 ) // Free form binary
  8455. #define REG_DWORD ( 4 ) // 32-bit number
  8456. #define REG_DWORD_LITTLE_ENDIAN ( 4 ) // 32-bit number (same as REG_DWORD)
  8457. #define REG_DWORD_BIG_ENDIAN ( 5 ) // 32-bit number
  8458. #define REG_LINK ( 6 ) // Symbolic Link (unicode)
  8459. #define REG_MULTI_SZ ( 7 ) // Multiple Unicode strings
  8460. #define REG_RESOURCE_LIST ( 8 ) // Resource list in the resource map
  8461. #define REG_FULL_RESOURCE_DESCRIPTOR ( 9 ) // Resource list in the hardware description
  8462. #define REG_RESOURCE_REQUIREMENTS_LIST ( 10 )
  8463. #define REG_QWORD ( 11 ) // 64-bit number
  8464. #define REG_QWORD_LITTLE_ENDIAN ( 11 ) // 64-bit number (same as REG_QWORD)
  8465. //
  8466. // Service Types (Bit Mask)
  8467. //
  8468. #define SERVICE_KERNEL_DRIVER 0x00000001
  8469. #define SERVICE_FILE_SYSTEM_DRIVER 0x00000002
  8470. #define SERVICE_ADAPTER 0x00000004
  8471. #define SERVICE_RECOGNIZER_DRIVER 0x00000008
  8472. #define SERVICE_DRIVER (SERVICE_KERNEL_DRIVER | \
  8473. SERVICE_FILE_SYSTEM_DRIVER | \
  8474. SERVICE_RECOGNIZER_DRIVER)
  8475. #define SERVICE_WIN32_OWN_PROCESS 0x00000010
  8476. #define SERVICE_WIN32_SHARE_PROCESS 0x00000020
  8477. #define SERVICE_WIN32 (SERVICE_WIN32_OWN_PROCESS | \
  8478. SERVICE_WIN32_SHARE_PROCESS)
  8479. #define SERVICE_INTERACTIVE_PROCESS 0x00000100
  8480. #define SERVICE_TYPE_ALL (SERVICE_WIN32 | \
  8481. SERVICE_ADAPTER | \
  8482. SERVICE_DRIVER | \
  8483. SERVICE_INTERACTIVE_PROCESS)
  8484. //
  8485. // Start Type
  8486. //
  8487. #define SERVICE_BOOT_START 0x00000000
  8488. #define SERVICE_SYSTEM_START 0x00000001
  8489. #define SERVICE_AUTO_START 0x00000002
  8490. #define SERVICE_DEMAND_START 0x00000003
  8491. #define SERVICE_DISABLED 0x00000004
  8492. //
  8493. // Error control type
  8494. //
  8495. #define SERVICE_ERROR_IGNORE 0x00000000
  8496. #define SERVICE_ERROR_NORMAL 0x00000001
  8497. #define SERVICE_ERROR_SEVERE 0x00000002
  8498. #define SERVICE_ERROR_CRITICAL 0x00000003
  8499. //
  8500. //
  8501. // Define the registry driver node enumerations
  8502. //
  8503. typedef enum _CM_SERVICE_NODE_TYPE {
  8504. DriverType = SERVICE_KERNEL_DRIVER,
  8505. FileSystemType = SERVICE_FILE_SYSTEM_DRIVER,
  8506. Win32ServiceOwnProcess = SERVICE_WIN32_OWN_PROCESS,
  8507. Win32ServiceShareProcess = SERVICE_WIN32_SHARE_PROCESS,
  8508. AdapterType = SERVICE_ADAPTER,
  8509. RecognizerType = SERVICE_RECOGNIZER_DRIVER
  8510. } SERVICE_NODE_TYPE;
  8511. typedef enum _CM_SERVICE_LOAD_TYPE {
  8512. BootLoad = SERVICE_BOOT_START,
  8513. SystemLoad = SERVICE_SYSTEM_START,
  8514. AutoLoad = SERVICE_AUTO_START,
  8515. DemandLoad = SERVICE_DEMAND_START,
  8516. DisableLoad = SERVICE_DISABLED
  8517. } SERVICE_LOAD_TYPE;
  8518. typedef enum _CM_ERROR_CONTROL_TYPE {
  8519. IgnoreError = SERVICE_ERROR_IGNORE,
  8520. NormalError = SERVICE_ERROR_NORMAL,
  8521. SevereError = SERVICE_ERROR_SEVERE,
  8522. CriticalError = SERVICE_ERROR_CRITICAL
  8523. } SERVICE_ERROR_TYPE;
  8524. //
  8525. // Resource List definitions
  8526. //
  8527. //
  8528. // Defines the Type in the RESOURCE_DESCRIPTOR
  8529. //
  8530. // NOTE: For all CM_RESOURCE_TYPE values, there must be a
  8531. // corresponding ResType value in the 32-bit ConfigMgr headerfile
  8532. // (cfgmgr32.h). Values in the range [0x6,0x80) use the same values
  8533. // as their ConfigMgr counterparts. CM_RESOURCE_TYPE values with
  8534. // the high bit set (i.e., in the range [0x80,0xFF]), are
  8535. // non-arbitrated resources. These correspond to the same values
  8536. // in cfgmgr32.h that have their high bit set (however, since
  8537. // cfgmgr32.h uses 16 bits for ResType values, these values are in
  8538. // the range [0x8000,0x807F). Note that ConfigMgr ResType values
  8539. // cannot be in the range [0x8080,0xFFFF), because they would not
  8540. // be able to map into CM_RESOURCE_TYPE values. (0xFFFF itself is
  8541. // a special value, because it maps to CmResourceTypeDeviceSpecific.)
  8542. //
  8543. typedef int CM_RESOURCE_TYPE;
  8544. // CmResourceTypeNull is reserved
  8545. #define CmResourceTypeNull 0 // ResType_All or ResType_None (0x0000)
  8546. #define CmResourceTypePort 1 // ResType_IO (0x0002)
  8547. #define CmResourceTypeInterrupt 2 // ResType_IRQ (0x0004)
  8548. #define CmResourceTypeMemory 3 // ResType_Mem (0x0001)
  8549. #define CmResourceTypeDma 4 // ResType_DMA (0x0003)
  8550. #define CmResourceTypeDeviceSpecific 5 // ResType_ClassSpecific (0xFFFF)
  8551. #define CmResourceTypeBusNumber 6 // ResType_BusNumber (0x0006)
  8552. #define CmResourceTypeMaximum 7
  8553. #define CmResourceTypeNonArbitrated 128 // Not arbitrated if 0x80 bit set
  8554. #define CmResourceTypeConfigData 128 // ResType_Reserved (0x8000)
  8555. #define CmResourceTypeDevicePrivate 129 // ResType_DevicePrivate (0x8001)
  8556. #define CmResourceTypePcCardConfig 130 // ResType_PcCardConfig (0x8002)
  8557. #define CmResourceTypeMfCardConfig 131 // ResType_MfCardConfig (0x8003)
  8558. //
  8559. // Defines the ShareDisposition in the RESOURCE_DESCRIPTOR
  8560. //
  8561. typedef enum _CM_SHARE_DISPOSITION {
  8562. CmResourceShareUndetermined = 0, // Reserved
  8563. CmResourceShareDeviceExclusive,
  8564. CmResourceShareDriverExclusive,
  8565. CmResourceShareShared
  8566. } CM_SHARE_DISPOSITION;
  8567. //
  8568. // Define the bit masks for Flags when type is CmResourceTypeInterrupt
  8569. //
  8570. #define CM_RESOURCE_INTERRUPT_LEVEL_SENSITIVE 0
  8571. #define CM_RESOURCE_INTERRUPT_LATCHED 1
  8572. //
  8573. // Define the bit masks for Flags when type is CmResourceTypeMemory
  8574. //
  8575. #define CM_RESOURCE_MEMORY_READ_WRITE 0x0000
  8576. #define CM_RESOURCE_MEMORY_READ_ONLY 0x0001
  8577. #define CM_RESOURCE_MEMORY_WRITE_ONLY 0x0002
  8578. #define CM_RESOURCE_MEMORY_PREFETCHABLE 0x0004
  8579. #define CM_RESOURCE_MEMORY_COMBINEDWRITE 0x0008
  8580. #define CM_RESOURCE_MEMORY_24 0x0010
  8581. #define CM_RESOURCE_MEMORY_CACHEABLE 0x0020
  8582. //
  8583. // Define the bit masks for Flags when type is CmResourceTypePort
  8584. //
  8585. #define CM_RESOURCE_PORT_MEMORY 0x0000
  8586. #define CM_RESOURCE_PORT_IO 0x0001
  8587. #define CM_RESOURCE_PORT_10_BIT_DECODE 0x0004
  8588. #define CM_RESOURCE_PORT_12_BIT_DECODE 0x0008
  8589. #define CM_RESOURCE_PORT_16_BIT_DECODE 0x0010
  8590. #define CM_RESOURCE_PORT_POSITIVE_DECODE 0x0020
  8591. #define CM_RESOURCE_PORT_PASSIVE_DECODE 0x0040
  8592. #define CM_RESOURCE_PORT_WINDOW_DECODE 0x0080
  8593. //
  8594. // Define the bit masks for Flags when type is CmResourceTypeDma
  8595. //
  8596. #define CM_RESOURCE_DMA_8 0x0000
  8597. #define CM_RESOURCE_DMA_16 0x0001
  8598. #define CM_RESOURCE_DMA_32 0x0002
  8599. #define CM_RESOURCE_DMA_8_AND_16 0x0004
  8600. #define CM_RESOURCE_DMA_BUS_MASTER 0x0008
  8601. #define CM_RESOURCE_DMA_TYPE_A 0x0010
  8602. #define CM_RESOURCE_DMA_TYPE_B 0x0020
  8603. #define CM_RESOURCE_DMA_TYPE_F 0x0040
  8604. //
  8605. // This structure defines one type of resource used by a driver.
  8606. //
  8607. // There can only be *1* DeviceSpecificData block. It must be located at
  8608. // the end of all resource descriptors in a full descriptor block.
  8609. //
  8610. //
  8611. // Make sure alignment is made properly by compiler; otherwise move
  8612. // flags back to the top of the structure (common to all members of the
  8613. // union).
  8614. //
  8615. #include "pshpack4.h"
  8616. typedef struct _CM_PARTIAL_RESOURCE_DESCRIPTOR {
  8617. UCHAR Type;
  8618. UCHAR ShareDisposition;
  8619. USHORT Flags;
  8620. union {
  8621. //
  8622. // Range of resources, inclusive. These are physical, bus relative.
  8623. // It is known that Port and Memory below have the exact same layout
  8624. // as Generic.
  8625. //
  8626. struct {
  8627. PHYSICAL_ADDRESS Start;
  8628. ULONG Length;
  8629. } Generic;
  8630. //
  8631. // Range of port numbers, inclusive. These are physical, bus
  8632. // relative. The value should be the same as the one passed to
  8633. // HalTranslateBusAddress().
  8634. //
  8635. struct {
  8636. PHYSICAL_ADDRESS Start;
  8637. ULONG Length;
  8638. } Port;
  8639. //
  8640. // IRQL and vector. Should be same values as were passed to
  8641. // HalGetInterruptVector().
  8642. //
  8643. struct {
  8644. ULONG Level;
  8645. ULONG Vector;
  8646. KAFFINITY Affinity;
  8647. } Interrupt;
  8648. //
  8649. // Range of memory addresses, inclusive. These are physical, bus
  8650. // relative. The value should be the same as the one passed to
  8651. // HalTranslateBusAddress().
  8652. //
  8653. struct {
  8654. PHYSICAL_ADDRESS Start; // 64 bit physical addresses.
  8655. ULONG Length;
  8656. } Memory;
  8657. //
  8658. // Physical DMA channel.
  8659. //
  8660. struct {
  8661. ULONG Channel;
  8662. ULONG Port;
  8663. ULONG Reserved1;
  8664. } Dma;
  8665. //
  8666. // Device driver private data, usually used to help it figure
  8667. // what the resource assignments decisions that were made.
  8668. //
  8669. struct {
  8670. ULONG Data[3];
  8671. } DevicePrivate;
  8672. //
  8673. // Bus Number information.
  8674. //
  8675. struct {
  8676. ULONG Start;
  8677. ULONG Length;
  8678. ULONG Reserved;
  8679. } BusNumber;
  8680. //
  8681. // Device Specific information defined by the driver.
  8682. // The DataSize field indicates the size of the data in bytes. The
  8683. // data is located immediately after the DeviceSpecificData field in
  8684. // the structure.
  8685. //
  8686. struct {
  8687. ULONG DataSize;
  8688. ULONG Reserved1;
  8689. ULONG Reserved2;
  8690. } DeviceSpecificData;
  8691. } u;
  8692. } CM_PARTIAL_RESOURCE_DESCRIPTOR, *PCM_PARTIAL_RESOURCE_DESCRIPTOR;
  8693. #include "poppack.h"
  8694. //
  8695. // A Partial Resource List is what can be found in the ARC firmware
  8696. // or will be generated by ntdetect.com.
  8697. // The configuration manager will transform this structure into a Full
  8698. // resource descriptor when it is about to store it in the regsitry.
  8699. //
  8700. // Note: There must a be a convention to the order of fields of same type,
  8701. // (defined on a device by device basis) so that the fields can make sense
  8702. // to a driver (i.e. when multiple memory ranges are necessary).
  8703. //
  8704. typedef struct _CM_PARTIAL_RESOURCE_LIST {
  8705. USHORT Version;
  8706. USHORT Revision;
  8707. ULONG Count;
  8708. CM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptors[1];
  8709. } CM_PARTIAL_RESOURCE_LIST, *PCM_PARTIAL_RESOURCE_LIST;
  8710. //
  8711. // A Full Resource Descriptor is what can be found in the registry.
  8712. // This is what will be returned to a driver when it queries the registry
  8713. // to get device information; it will be stored under a key in the hardware
  8714. // description tree.
  8715. //
  8716. // Note: The BusNumber and Type are redundant information, but we will keep
  8717. // it since it allows the driver _not_ to append it when it is creating
  8718. // a resource list which could possibly span multiple buses.
  8719. //
  8720. // Note: There must a be a convention to the order of fields of same type,
  8721. // (defined on a device by device basis) so that the fields can make sense
  8722. // to a driver (i.e. when multiple memory ranges are necessary).
  8723. //
  8724. typedef struct _CM_FULL_RESOURCE_DESCRIPTOR {
  8725. INTERFACE_TYPE InterfaceType; // unused for WDM
  8726. ULONG BusNumber; // unused for WDM
  8727. CM_PARTIAL_RESOURCE_LIST PartialResourceList;
  8728. } CM_FULL_RESOURCE_DESCRIPTOR, *PCM_FULL_RESOURCE_DESCRIPTOR;
  8729. //
  8730. // The Resource list is what will be stored by the drivers into the
  8731. // resource map via the IO API.
  8732. //
  8733. typedef struct _CM_RESOURCE_LIST {
  8734. ULONG Count;
  8735. CM_FULL_RESOURCE_DESCRIPTOR List[1];
  8736. } CM_RESOURCE_LIST, *PCM_RESOURCE_LIST;
  8737. //
  8738. // Define the structures used to interpret configuration data of
  8739. // \\Registry\machine\hardware\description tree.
  8740. // Basically, these structures are used to interpret component
  8741. // sepcific data.
  8742. //
  8743. //
  8744. // Define DEVICE_FLAGS
  8745. //
  8746. typedef struct _DEVICE_FLAGS {
  8747. ULONG Failed : 1;
  8748. ULONG ReadOnly : 1;
  8749. ULONG Removable : 1;
  8750. ULONG ConsoleIn : 1;
  8751. ULONG ConsoleOut : 1;
  8752. ULONG Input : 1;
  8753. ULONG Output : 1;
  8754. } DEVICE_FLAGS, *PDEVICE_FLAGS;
  8755. //
  8756. // Define Component Information structure
  8757. //
  8758. typedef struct _CM_COMPONENT_INFORMATION {
  8759. DEVICE_FLAGS Flags;
  8760. ULONG Version;
  8761. ULONG Key;
  8762. KAFFINITY AffinityMask;
  8763. } CM_COMPONENT_INFORMATION, *PCM_COMPONENT_INFORMATION;
  8764. //
  8765. // The following structures are used to interpret x86
  8766. // DeviceSpecificData of CM_PARTIAL_RESOURCE_DESCRIPTOR.
  8767. // (Most of the structures are defined by BIOS. They are
  8768. // not aligned on word (or dword) boundary.
  8769. //
  8770. //
  8771. // Define the Rom Block structure
  8772. //
  8773. typedef struct _CM_ROM_BLOCK {
  8774. ULONG Address;
  8775. ULONG Size;
  8776. } CM_ROM_BLOCK, *PCM_ROM_BLOCK;
  8777. #include "pshpack1.h"
  8778. //
  8779. // Define INT13 driver parameter block
  8780. //
  8781. typedef struct _CM_INT13_DRIVE_PARAMETER {
  8782. USHORT DriveSelect;
  8783. ULONG MaxCylinders;
  8784. USHORT SectorsPerTrack;
  8785. USHORT MaxHeads;
  8786. USHORT NumberDrives;
  8787. } CM_INT13_DRIVE_PARAMETER, *PCM_INT13_DRIVE_PARAMETER;
  8788. //
  8789. // Define Mca POS data block for slot
  8790. //
  8791. typedef struct _CM_MCA_POS_DATA {
  8792. USHORT AdapterId;
  8793. UCHAR PosData1;
  8794. UCHAR PosData2;
  8795. UCHAR PosData3;
  8796. UCHAR PosData4;
  8797. } CM_MCA_POS_DATA, *PCM_MCA_POS_DATA;
  8798. //
  8799. // Memory configuration of eisa data block structure
  8800. //
  8801. typedef struct _EISA_MEMORY_TYPE {
  8802. UCHAR ReadWrite: 1;
  8803. UCHAR Cached : 1;
  8804. UCHAR Reserved0 :1;
  8805. UCHAR Type:2;
  8806. UCHAR Shared:1;
  8807. UCHAR Reserved1 :1;
  8808. UCHAR MoreEntries : 1;
  8809. } EISA_MEMORY_TYPE, *PEISA_MEMORY_TYPE;
  8810. typedef struct _EISA_MEMORY_CONFIGURATION {
  8811. EISA_MEMORY_TYPE ConfigurationByte;
  8812. UCHAR DataSize;
  8813. USHORT AddressLowWord;
  8814. UCHAR AddressHighByte;
  8815. USHORT MemorySize;
  8816. } EISA_MEMORY_CONFIGURATION, *PEISA_MEMORY_CONFIGURATION;
  8817. //
  8818. // Interrupt configurationn of eisa data block structure
  8819. //
  8820. typedef struct _EISA_IRQ_DESCRIPTOR {
  8821. UCHAR Interrupt : 4;
  8822. UCHAR Reserved :1;
  8823. UCHAR LevelTriggered :1;
  8824. UCHAR Shared : 1;
  8825. UCHAR MoreEntries : 1;
  8826. } EISA_IRQ_DESCRIPTOR, *PEISA_IRQ_DESCRIPTOR;
  8827. typedef struct _EISA_IRQ_CONFIGURATION {
  8828. EISA_IRQ_DESCRIPTOR ConfigurationByte;
  8829. UCHAR Reserved;
  8830. } EISA_IRQ_CONFIGURATION, *PEISA_IRQ_CONFIGURATION;
  8831. //
  8832. // DMA description of eisa data block structure
  8833. //
  8834. typedef struct _DMA_CONFIGURATION_BYTE0 {
  8835. UCHAR Channel : 3;
  8836. UCHAR Reserved : 3;
  8837. UCHAR Shared :1;
  8838. UCHAR MoreEntries :1;
  8839. } DMA_CONFIGURATION_BYTE0;
  8840. typedef struct _DMA_CONFIGURATION_BYTE1 {
  8841. UCHAR Reserved0 : 2;
  8842. UCHAR TransferSize : 2;
  8843. UCHAR Timing : 2;
  8844. UCHAR Reserved1 : 2;
  8845. } DMA_CONFIGURATION_BYTE1;
  8846. typedef struct _EISA_DMA_CONFIGURATION {
  8847. DMA_CONFIGURATION_BYTE0 ConfigurationByte0;
  8848. DMA_CONFIGURATION_BYTE1 ConfigurationByte1;
  8849. } EISA_DMA_CONFIGURATION, *PEISA_DMA_CONFIGURATION;
  8850. //
  8851. // Port description of eisa data block structure
  8852. //
  8853. typedef struct _EISA_PORT_DESCRIPTOR {
  8854. UCHAR NumberPorts : 5;
  8855. UCHAR Reserved :1;
  8856. UCHAR Shared :1;
  8857. UCHAR MoreEntries : 1;
  8858. } EISA_PORT_DESCRIPTOR, *PEISA_PORT_DESCRIPTOR;
  8859. typedef struct _EISA_PORT_CONFIGURATION {
  8860. EISA_PORT_DESCRIPTOR Configuration;
  8861. USHORT PortAddress;
  8862. } EISA_PORT_CONFIGURATION, *PEISA_PORT_CONFIGURATION;
  8863. //
  8864. // Eisa slot information definition
  8865. // N.B. This structure is different from the one defined
  8866. // in ARC eisa addendum.
  8867. //
  8868. typedef struct _CM_EISA_SLOT_INFORMATION {
  8869. UCHAR ReturnCode;
  8870. UCHAR ReturnFlags;
  8871. UCHAR MajorRevision;
  8872. UCHAR MinorRevision;
  8873. USHORT Checksum;
  8874. UCHAR NumberFunctions;
  8875. UCHAR FunctionInformation;
  8876. ULONG CompressedId;
  8877. } CM_EISA_SLOT_INFORMATION, *PCM_EISA_SLOT_INFORMATION;
  8878. //
  8879. // Eisa function information definition
  8880. //
  8881. typedef struct _CM_EISA_FUNCTION_INFORMATION {
  8882. ULONG CompressedId;
  8883. UCHAR IdSlotFlags1;
  8884. UCHAR IdSlotFlags2;
  8885. UCHAR MinorRevision;
  8886. UCHAR MajorRevision;
  8887. UCHAR Selections[26];
  8888. UCHAR FunctionFlags;
  8889. UCHAR TypeString[80];
  8890. EISA_MEMORY_CONFIGURATION EisaMemory[9];
  8891. EISA_IRQ_CONFIGURATION EisaIrq[7];
  8892. EISA_DMA_CONFIGURATION EisaDma[4];
  8893. EISA_PORT_CONFIGURATION EisaPort[20];
  8894. UCHAR InitializationData[60];
  8895. } CM_EISA_FUNCTION_INFORMATION, *PCM_EISA_FUNCTION_INFORMATION;
  8896. //
  8897. // The following defines the way pnp bios information is stored in
  8898. // the registry \\HKEY_LOCAL_MACHINE\HARDWARE\Description\System\MultifunctionAdapter\x
  8899. // key, where x is an integer number indicating adapter instance. The
  8900. // "Identifier" of the key must equal to "PNP BIOS" and the
  8901. // "ConfigurationData" is organized as follow:
  8902. //
  8903. // CM_PNP_BIOS_INSTALLATION_CHECK +
  8904. // CM_PNP_BIOS_DEVICE_NODE for device 1 +
  8905. // CM_PNP_BIOS_DEVICE_NODE for device 2 +
  8906. // ...
  8907. // CM_PNP_BIOS_DEVICE_NODE for device n
  8908. //
  8909. //
  8910. // Pnp BIOS device node structure
  8911. //
  8912. typedef struct _CM_PNP_BIOS_DEVICE_NODE {
  8913. USHORT Size;
  8914. UCHAR Node;
  8915. ULONG ProductId;
  8916. UCHAR DeviceType[3];
  8917. USHORT DeviceAttributes;
  8918. // followed by AllocatedResourceBlock, PossibleResourceBlock
  8919. // and CompatibleDeviceId
  8920. } CM_PNP_BIOS_DEVICE_NODE,*PCM_PNP_BIOS_DEVICE_NODE;
  8921. //
  8922. // Pnp BIOS Installation check
  8923. //
  8924. typedef struct _CM_PNP_BIOS_INSTALLATION_CHECK {
  8925. UCHAR Signature[4]; // $PnP (ascii)
  8926. UCHAR Revision;
  8927. UCHAR Length;
  8928. USHORT ControlField;
  8929. UCHAR Checksum;
  8930. ULONG EventFlagAddress; // Physical address
  8931. USHORT RealModeEntryOffset;
  8932. USHORT RealModeEntrySegment;
  8933. USHORT ProtectedModeEntryOffset;
  8934. ULONG ProtectedModeCodeBaseAddress;
  8935. ULONG OemDeviceId;
  8936. USHORT RealModeDataBaseAddress;
  8937. ULONG ProtectedModeDataBaseAddress;
  8938. } CM_PNP_BIOS_INSTALLATION_CHECK, *PCM_PNP_BIOS_INSTALLATION_CHECK;
  8939. #include "poppack.h"
  8940. //
  8941. // Masks for EISA function information
  8942. //
  8943. #define EISA_FUNCTION_ENABLED 0x80
  8944. #define EISA_FREE_FORM_DATA 0x40
  8945. #define EISA_HAS_PORT_INIT_ENTRY 0x20
  8946. #define EISA_HAS_PORT_RANGE 0x10
  8947. #define EISA_HAS_DMA_ENTRY 0x08
  8948. #define EISA_HAS_IRQ_ENTRY 0x04
  8949. #define EISA_HAS_MEMORY_ENTRY 0x02
  8950. #define EISA_HAS_TYPE_ENTRY 0x01
  8951. #define EISA_HAS_INFORMATION EISA_HAS_PORT_RANGE + \
  8952. EISA_HAS_DMA_ENTRY + \
  8953. EISA_HAS_IRQ_ENTRY + \
  8954. EISA_HAS_MEMORY_ENTRY + \
  8955. EISA_HAS_TYPE_ENTRY
  8956. //
  8957. // Masks for EISA memory configuration
  8958. //
  8959. #define EISA_MORE_ENTRIES 0x80
  8960. #define EISA_SYSTEM_MEMORY 0x00
  8961. #define EISA_MEMORY_TYPE_RAM 0x01
  8962. //
  8963. // Returned error code for EISA bios call
  8964. //
  8965. #define EISA_INVALID_SLOT 0x80
  8966. #define EISA_INVALID_FUNCTION 0x81
  8967. #define EISA_INVALID_CONFIGURATION 0x82
  8968. #define EISA_EMPTY_SLOT 0x83
  8969. #define EISA_INVALID_BIOS_CALL 0x86
  8970. //
  8971. // The following structures are used to interpret mips
  8972. // DeviceSpecificData of CM_PARTIAL_RESOURCE_DESCRIPTOR.
  8973. //
  8974. //
  8975. // Device data records for adapters.
  8976. //
  8977. //
  8978. // The device data record for the Emulex SCSI controller.
  8979. //
  8980. typedef struct _CM_SCSI_DEVICE_DATA {
  8981. USHORT Version;
  8982. USHORT Revision;
  8983. UCHAR HostIdentifier;
  8984. } CM_SCSI_DEVICE_DATA, *PCM_SCSI_DEVICE_DATA;
  8985. //
  8986. // Device data records for controllers.
  8987. //
  8988. //
  8989. // The device data record for the Video controller.
  8990. //
  8991. typedef struct _CM_VIDEO_DEVICE_DATA {
  8992. USHORT Version;
  8993. USHORT Revision;
  8994. ULONG VideoClock;
  8995. } CM_VIDEO_DEVICE_DATA, *PCM_VIDEO_DEVICE_DATA;
  8996. //
  8997. // The device data record for the SONIC network controller.
  8998. //
  8999. typedef struct _CM_SONIC_DEVICE_DATA {
  9000. USHORT Version;
  9001. USHORT Revision;
  9002. USHORT DataConfigurationRegister;
  9003. UCHAR EthernetAddress[8];
  9004. } CM_SONIC_DEVICE_DATA, *PCM_SONIC_DEVICE_DATA;
  9005. //
  9006. // The device data record for the serial controller.
  9007. //
  9008. typedef struct _CM_SERIAL_DEVICE_DATA {
  9009. USHORT Version;
  9010. USHORT Revision;
  9011. ULONG BaudClock;
  9012. } CM_SERIAL_DEVICE_DATA, *PCM_SERIAL_DEVICE_DATA;
  9013. //
  9014. // Device data records for peripherals.
  9015. //
  9016. //
  9017. // The device data record for the Monitor peripheral.
  9018. //
  9019. typedef struct _CM_MONITOR_DEVICE_DATA {
  9020. USHORT Version;
  9021. USHORT Revision;
  9022. USHORT HorizontalScreenSize;
  9023. USHORT VerticalScreenSize;
  9024. USHORT HorizontalResolution;
  9025. USHORT VerticalResolution;
  9026. USHORT HorizontalDisplayTimeLow;
  9027. USHORT HorizontalDisplayTime;
  9028. USHORT HorizontalDisplayTimeHigh;
  9029. USHORT HorizontalBackPorchLow;
  9030. USHORT HorizontalBackPorch;
  9031. USHORT HorizontalBackPorchHigh;
  9032. USHORT HorizontalFrontPorchLow;
  9033. USHORT HorizontalFrontPorch;
  9034. USHORT HorizontalFrontPorchHigh;
  9035. USHORT HorizontalSyncLow;
  9036. USHORT HorizontalSync;
  9037. USHORT HorizontalSyncHigh;
  9038. USHORT VerticalBackPorchLow;
  9039. USHORT VerticalBackPorch;
  9040. USHORT VerticalBackPorchHigh;
  9041. USHORT VerticalFrontPorchLow;
  9042. USHORT VerticalFrontPorch;
  9043. USHORT VerticalFrontPorchHigh;
  9044. USHORT VerticalSyncLow;
  9045. USHORT VerticalSync;
  9046. USHORT VerticalSyncHigh;
  9047. } CM_MONITOR_DEVICE_DATA, *PCM_MONITOR_DEVICE_DATA;
  9048. //
  9049. // The device data record for the Floppy peripheral.
  9050. //
  9051. typedef struct _CM_FLOPPY_DEVICE_DATA {
  9052. USHORT Version;
  9053. USHORT Revision;
  9054. CHAR Size[8];
  9055. ULONG MaxDensity;
  9056. ULONG MountDensity;
  9057. //
  9058. // New data fields for version >= 2.0
  9059. //
  9060. UCHAR StepRateHeadUnloadTime;
  9061. UCHAR HeadLoadTime;
  9062. UCHAR MotorOffTime;
  9063. UCHAR SectorLengthCode;
  9064. UCHAR SectorPerTrack;
  9065. UCHAR ReadWriteGapLength;
  9066. UCHAR DataTransferLength;
  9067. UCHAR FormatGapLength;
  9068. UCHAR FormatFillCharacter;
  9069. UCHAR HeadSettleTime;
  9070. UCHAR MotorSettleTime;
  9071. UCHAR MaximumTrackValue;
  9072. UCHAR DataTransferRate;
  9073. } CM_FLOPPY_DEVICE_DATA, *PCM_FLOPPY_DEVICE_DATA;
  9074. //
  9075. // The device data record for the Keyboard peripheral.
  9076. // The KeyboardFlags is defined (by x86 BIOS INT 16h, function 02) as:
  9077. // bit 7 : Insert on
  9078. // bit 6 : Caps Lock on
  9079. // bit 5 : Num Lock on
  9080. // bit 4 : Scroll Lock on
  9081. // bit 3 : Alt Key is down
  9082. // bit 2 : Ctrl Key is down
  9083. // bit 1 : Left shift key is down
  9084. // bit 0 : Right shift key is down
  9085. //
  9086. typedef struct _CM_KEYBOARD_DEVICE_DATA {
  9087. USHORT Version;
  9088. USHORT Revision;
  9089. UCHAR Type;
  9090. UCHAR Subtype;
  9091. USHORT KeyboardFlags;
  9092. } CM_KEYBOARD_DEVICE_DATA, *PCM_KEYBOARD_DEVICE_DATA;
  9093. //
  9094. // Declaration of the structure for disk geometries
  9095. //
  9096. typedef struct _CM_DISK_GEOMETRY_DEVICE_DATA {
  9097. ULONG BytesPerSector;
  9098. ULONG NumberOfCylinders;
  9099. ULONG SectorsPerTrack;
  9100. ULONG NumberOfHeads;
  9101. } CM_DISK_GEOMETRY_DEVICE_DATA, *PCM_DISK_GEOMETRY_DEVICE_DATA;
  9102. //
  9103. // Declaration of the structure for the PcCard ISA IRQ map
  9104. //
  9105. typedef struct _CM_PCCARD_DEVICE_DATA {
  9106. UCHAR Flags;
  9107. UCHAR ErrorCode;
  9108. USHORT Reserved;
  9109. ULONG BusData;
  9110. ULONG DeviceId;
  9111. ULONG LegacyBaseAddress;
  9112. UCHAR IRQMap[16];
  9113. } CM_PCCARD_DEVICE_DATA, *PCM_PCCARD_DEVICE_DATA;
  9114. // Definitions for Flags
  9115. #define PCCARD_MAP_ERROR 0x01
  9116. #define PCCARD_DEVICE_PCI 0x10
  9117. #define PCCARD_SCAN_DISABLED 0x01
  9118. #define PCCARD_MAP_ZERO 0x02
  9119. #define PCCARD_NO_TIMER 0x03
  9120. #define PCCARD_NO_PIC 0x04
  9121. #define PCCARD_NO_LEGACY_BASE 0x05
  9122. #define PCCARD_DUP_LEGACY_BASE 0x06
  9123. #define PCCARD_NO_CONTROLLERS 0x07
  9124. //
  9125. // Defines Resource Options
  9126. //
  9127. #define IO_RESOURCE_PREFERRED 0x01
  9128. #define IO_RESOURCE_DEFAULT 0x02
  9129. #define IO_RESOURCE_ALTERNATIVE 0x08
  9130. //
  9131. // This structure defines one type of resource requested by the driver
  9132. //
  9133. typedef struct _IO_RESOURCE_DESCRIPTOR {
  9134. UCHAR Option;
  9135. UCHAR Type; // use CM_RESOURCE_TYPE
  9136. UCHAR ShareDisposition; // use CM_SHARE_DISPOSITION
  9137. UCHAR Spare1;
  9138. USHORT Flags; // use CM resource flag defines
  9139. USHORT Spare2; // align
  9140. union {
  9141. struct {
  9142. ULONG Length;
  9143. ULONG Alignment;
  9144. PHYSICAL_ADDRESS MinimumAddress;
  9145. PHYSICAL_ADDRESS MaximumAddress;
  9146. } Port;
  9147. struct {
  9148. ULONG Length;
  9149. ULONG Alignment;
  9150. PHYSICAL_ADDRESS MinimumAddress;
  9151. PHYSICAL_ADDRESS MaximumAddress;
  9152. } Memory;
  9153. struct {
  9154. ULONG MinimumVector;
  9155. ULONG MaximumVector;
  9156. } Interrupt;
  9157. struct {
  9158. ULONG MinimumChannel;
  9159. ULONG MaximumChannel;
  9160. } Dma;
  9161. struct {
  9162. ULONG Length;
  9163. ULONG Alignment;
  9164. PHYSICAL_ADDRESS MinimumAddress;
  9165. PHYSICAL_ADDRESS MaximumAddress;
  9166. } Generic;
  9167. struct {
  9168. ULONG Data[3];
  9169. } DevicePrivate;
  9170. //
  9171. // Bus Number information.
  9172. //
  9173. struct {
  9174. ULONG Length;
  9175. ULONG MinBusNumber;
  9176. ULONG MaxBusNumber;
  9177. ULONG Reserved;
  9178. } BusNumber;
  9179. struct {
  9180. ULONG Priority; // use LCPRI_Xxx values in cfg.h
  9181. ULONG Reserved1;
  9182. ULONG Reserved2;
  9183. } ConfigData;
  9184. } u;
  9185. } IO_RESOURCE_DESCRIPTOR, *PIO_RESOURCE_DESCRIPTOR;
  9186. typedef struct _IO_RESOURCE_LIST {
  9187. USHORT Version;
  9188. USHORT Revision;
  9189. ULONG Count;
  9190. IO_RESOURCE_DESCRIPTOR Descriptors[1];
  9191. } IO_RESOURCE_LIST, *PIO_RESOURCE_LIST;
  9192. typedef struct _IO_RESOURCE_REQUIREMENTS_LIST {
  9193. ULONG ListSize;
  9194. INTERFACE_TYPE InterfaceType; // unused for WDM
  9195. ULONG BusNumber; // unused for WDM
  9196. ULONG SlotNumber;
  9197. ULONG Reserved[3];
  9198. ULONG AlternativeLists;
  9199. IO_RESOURCE_LIST List[1];
  9200. } IO_RESOURCE_REQUIREMENTS_LIST, *PIO_RESOURCE_REQUIREMENTS_LIST;
  9201. //
  9202. // Exception flag definitions.
  9203. //
  9204. #define EXCEPTION_NONCONTINUABLE 0x1 // Noncontinuable exception
  9205. //
  9206. // Define maximum number of exception parameters.
  9207. //
  9208. #define EXCEPTION_MAXIMUM_PARAMETERS 15 // maximum number of exception parameters
  9209. //
  9210. // Exception record definition.
  9211. //
  9212. typedef struct _EXCEPTION_RECORD {
  9213. NTSTATUS ExceptionCode;
  9214. ULONG ExceptionFlags;
  9215. struct _EXCEPTION_RECORD *ExceptionRecord;
  9216. PVOID ExceptionAddress;
  9217. ULONG NumberParameters;
  9218. ULONG_PTR ExceptionInformation[EXCEPTION_MAXIMUM_PARAMETERS];
  9219. } EXCEPTION_RECORD;
  9220. typedef EXCEPTION_RECORD *PEXCEPTION_RECORD;
  9221. typedef struct _EXCEPTION_RECORD32 {
  9222. NTSTATUS ExceptionCode;
  9223. ULONG ExceptionFlags;
  9224. ULONG ExceptionRecord;
  9225. ULONG ExceptionAddress;
  9226. ULONG NumberParameters;
  9227. ULONG ExceptionInformation[EXCEPTION_MAXIMUM_PARAMETERS];
  9228. } EXCEPTION_RECORD32, *PEXCEPTION_RECORD32;
  9229. typedef struct _EXCEPTION_RECORD64 {
  9230. NTSTATUS ExceptionCode;
  9231. ULONG ExceptionFlags;
  9232. ULONG64 ExceptionRecord;
  9233. ULONG64 ExceptionAddress;
  9234. ULONG NumberParameters;
  9235. ULONG __unusedAlignment;
  9236. ULONG64 ExceptionInformation[EXCEPTION_MAXIMUM_PARAMETERS];
  9237. } EXCEPTION_RECORD64, *PEXCEPTION_RECORD64;
  9238. //
  9239. // Typedef for pointer returned by exception_info()
  9240. //
  9241. typedef struct _EXCEPTION_POINTERS {
  9242. PEXCEPTION_RECORD ExceptionRecord;
  9243. PCONTEXT ContextRecord;
  9244. } EXCEPTION_POINTERS, *PEXCEPTION_POINTERS;
  9245. //
  9246. // Define configuration routine types.
  9247. //
  9248. // Configuration information.
  9249. //
  9250. typedef enum _CONFIGURATION_TYPE {
  9251. ArcSystem,
  9252. CentralProcessor,
  9253. FloatingPointProcessor,
  9254. PrimaryIcache,
  9255. PrimaryDcache,
  9256. SecondaryIcache,
  9257. SecondaryDcache,
  9258. SecondaryCache,
  9259. EisaAdapter,
  9260. TcAdapter,
  9261. ScsiAdapter,
  9262. DtiAdapter,
  9263. MultiFunctionAdapter,
  9264. DiskController,
  9265. TapeController,
  9266. CdromController,
  9267. WormController,
  9268. SerialController,
  9269. NetworkController,
  9270. DisplayController,
  9271. ParallelController,
  9272. PointerController,
  9273. KeyboardController,
  9274. AudioController,
  9275. OtherController,
  9276. DiskPeripheral,
  9277. FloppyDiskPeripheral,
  9278. TapePeripheral,
  9279. ModemPeripheral,
  9280. MonitorPeripheral,
  9281. PrinterPeripheral,
  9282. PointerPeripheral,
  9283. KeyboardPeripheral,
  9284. TerminalPeripheral,
  9285. OtherPeripheral,
  9286. LinePeripheral,
  9287. NetworkPeripheral,
  9288. SystemMemory,
  9289. DockingInformation,
  9290. RealModeIrqRoutingTable,
  9291. RealModePCIEnumeration,
  9292. MaximumType
  9293. } CONFIGURATION_TYPE, *PCONFIGURATION_TYPE;
  9294. #define THREAD_WAIT_OBJECTS 3 // Builtin usable wait blocks
  9295. //
  9296. #if defined(_X86_)
  9297. #define PAUSE_PROCESSOR _asm { rep nop }
  9298. #else
  9299. #define PAUSE_PROCESSOR
  9300. #endif
  9301. //
  9302. // Interrupt modes.
  9303. //
  9304. typedef enum _KINTERRUPT_MODE {
  9305. LevelSensitive,
  9306. Latched
  9307. } KINTERRUPT_MODE;
  9308. //
  9309. // Wait reasons
  9310. //
  9311. typedef enum _KWAIT_REASON {
  9312. Executive,
  9313. FreePage,
  9314. PageIn,
  9315. PoolAllocation,
  9316. DelayExecution,
  9317. Suspended,
  9318. UserRequest,
  9319. WrExecutive,
  9320. WrFreePage,
  9321. WrPageIn,
  9322. WrPoolAllocation,
  9323. WrDelayExecution,
  9324. WrSuspended,
  9325. WrUserRequest,
  9326. WrEventPair,
  9327. WrQueue,
  9328. WrLpcReceive,
  9329. WrLpcReply,
  9330. WrVirtualMemory,
  9331. WrPageOut,
  9332. WrRendezvous,
  9333. Spare2,
  9334. Spare3,
  9335. Spare4,
  9336. Spare5,
  9337. Spare6,
  9338. WrKernel,
  9339. WrResource,
  9340. WrPushLock,
  9341. WrMutex,
  9342. WrQuantumEnd,
  9343. WrDispatchInt,
  9344. WrPreempted,
  9345. WrYieldExecution,
  9346. MaximumWaitReason
  9347. } KWAIT_REASON;
  9348. typedef struct _KWAIT_BLOCK {
  9349. LIST_ENTRY WaitListEntry;
  9350. struct _KTHREAD *RESTRICTED_POINTER Thread;
  9351. PVOID Object;
  9352. struct _KWAIT_BLOCK *RESTRICTED_POINTER NextWaitBlock;
  9353. USHORT WaitKey;
  9354. USHORT WaitType;
  9355. } KWAIT_BLOCK, *PKWAIT_BLOCK, *RESTRICTED_POINTER PRKWAIT_BLOCK;
  9356. //
  9357. // Thread start function
  9358. //
  9359. typedef
  9360. VOID
  9361. (*PKSTART_ROUTINE) (
  9362. IN PVOID StartContext
  9363. );
  9364. //
  9365. // Kernel object structure definitions
  9366. //
  9367. //
  9368. // Device Queue object and entry
  9369. //
  9370. typedef struct _KDEVICE_QUEUE {
  9371. CSHORT Type;
  9372. CSHORT Size;
  9373. LIST_ENTRY DeviceListHead;
  9374. KSPIN_LOCK Lock;
  9375. BOOLEAN Busy;
  9376. } KDEVICE_QUEUE, *PKDEVICE_QUEUE, *RESTRICTED_POINTER PRKDEVICE_QUEUE;
  9377. typedef struct _KDEVICE_QUEUE_ENTRY {
  9378. LIST_ENTRY DeviceListEntry;
  9379. ULONG SortKey;
  9380. BOOLEAN Inserted;
  9381. } KDEVICE_QUEUE_ENTRY, *PKDEVICE_QUEUE_ENTRY, *RESTRICTED_POINTER PRKDEVICE_QUEUE_ENTRY;
  9382. //
  9383. // Define the interrupt service function type and the empty struct
  9384. // type.
  9385. //
  9386. typedef
  9387. BOOLEAN
  9388. (*PKSERVICE_ROUTINE) (
  9389. IN struct _KINTERRUPT *Interrupt,
  9390. IN PVOID ServiceContext
  9391. );
  9392. //
  9393. // Mutant object
  9394. //
  9395. typedef struct _KMUTANT {
  9396. DISPATCHER_HEADER Header;
  9397. LIST_ENTRY MutantListEntry;
  9398. struct _KTHREAD *RESTRICTED_POINTER OwnerThread;
  9399. BOOLEAN Abandoned;
  9400. UCHAR ApcDisable;
  9401. } KMUTANT, *PKMUTANT, *RESTRICTED_POINTER PRKMUTANT, KMUTEX, *PKMUTEX, *RESTRICTED_POINTER PRKMUTEX;
  9402. //
  9403. //
  9404. // Semaphore object
  9405. //
  9406. typedef struct _KSEMAPHORE {
  9407. DISPATCHER_HEADER Header;
  9408. LONG Limit;
  9409. } KSEMAPHORE, *PKSEMAPHORE, *RESTRICTED_POINTER PRKSEMAPHORE;
  9410. //
  9411. // DPC object
  9412. //
  9413. NTKERNELAPI
  9414. VOID
  9415. KeInitializeDpc (
  9416. IN PRKDPC Dpc,
  9417. IN PKDEFERRED_ROUTINE DeferredRoutine,
  9418. IN PVOID DeferredContext
  9419. );
  9420. NTKERNELAPI
  9421. BOOLEAN
  9422. KeInsertQueueDpc (
  9423. IN PRKDPC Dpc,
  9424. IN PVOID SystemArgument1,
  9425. IN PVOID SystemArgument2
  9426. );
  9427. NTKERNELAPI
  9428. BOOLEAN
  9429. KeRemoveQueueDpc (
  9430. IN PRKDPC Dpc
  9431. );
  9432. NTKERNELAPI
  9433. VOID
  9434. KeSetImportanceDpc (
  9435. IN PRKDPC Dpc,
  9436. IN KDPC_IMPORTANCE Importance
  9437. );
  9438. NTKERNELAPI
  9439. VOID
  9440. KeSetTargetProcessorDpc (
  9441. IN PRKDPC Dpc,
  9442. IN CCHAR Number
  9443. );
  9444. NTKERNELAPI
  9445. VOID
  9446. KeFlushQueuedDpcs (
  9447. VOID
  9448. );
  9449. //
  9450. // Device queue object
  9451. //
  9452. NTKERNELAPI
  9453. VOID
  9454. KeInitializeDeviceQueue (
  9455. IN PKDEVICE_QUEUE DeviceQueue
  9456. );
  9457. NTKERNELAPI
  9458. BOOLEAN
  9459. KeInsertDeviceQueue (
  9460. IN PKDEVICE_QUEUE DeviceQueue,
  9461. IN PKDEVICE_QUEUE_ENTRY DeviceQueueEntry
  9462. );
  9463. NTKERNELAPI
  9464. BOOLEAN
  9465. KeInsertByKeyDeviceQueue (
  9466. IN PKDEVICE_QUEUE DeviceQueue,
  9467. IN PKDEVICE_QUEUE_ENTRY DeviceQueueEntry,
  9468. IN ULONG SortKey
  9469. );
  9470. NTKERNELAPI
  9471. PKDEVICE_QUEUE_ENTRY
  9472. KeRemoveDeviceQueue (
  9473. IN PKDEVICE_QUEUE DeviceQueue
  9474. );
  9475. NTKERNELAPI
  9476. PKDEVICE_QUEUE_ENTRY
  9477. KeRemoveByKeyDeviceQueue (
  9478. IN PKDEVICE_QUEUE DeviceQueue,
  9479. IN ULONG SortKey
  9480. );
  9481. NTKERNELAPI
  9482. PKDEVICE_QUEUE_ENTRY
  9483. KeRemoveByKeyDeviceQueueIfBusy (
  9484. IN PKDEVICE_QUEUE DeviceQueue,
  9485. IN ULONG SortKey
  9486. );
  9487. NTKERNELAPI
  9488. BOOLEAN
  9489. KeRemoveEntryDeviceQueue (
  9490. IN PKDEVICE_QUEUE DeviceQueue,
  9491. IN PKDEVICE_QUEUE_ENTRY DeviceQueueEntry
  9492. );
  9493. NTKERNELAPI
  9494. BOOLEAN
  9495. KeSynchronizeExecution (
  9496. IN PKINTERRUPT Interrupt,
  9497. IN PKSYNCHRONIZE_ROUTINE SynchronizeRoutine,
  9498. IN PVOID SynchronizeContext
  9499. );
  9500. NTKERNELAPI
  9501. KIRQL
  9502. KeAcquireInterruptSpinLock (
  9503. IN PKINTERRUPT Interrupt
  9504. );
  9505. NTKERNELAPI
  9506. VOID
  9507. KeReleaseInterruptSpinLock (
  9508. IN PKINTERRUPT Interrupt,
  9509. IN KIRQL OldIrql
  9510. );
  9511. //
  9512. // Kernel dispatcher object functions
  9513. //
  9514. // Event Object
  9515. //
  9516. NTKERNELAPI
  9517. VOID
  9518. KeInitializeEvent (
  9519. IN PRKEVENT Event,
  9520. IN EVENT_TYPE Type,
  9521. IN BOOLEAN State
  9522. );
  9523. NTKERNELAPI
  9524. VOID
  9525. KeClearEvent (
  9526. IN PRKEVENT Event
  9527. );
  9528. NTKERNELAPI
  9529. LONG
  9530. KePulseEvent (
  9531. IN PRKEVENT Event,
  9532. IN KPRIORITY Increment,
  9533. IN BOOLEAN Wait
  9534. );
  9535. NTKERNELAPI
  9536. LONG
  9537. KeReadStateEvent (
  9538. IN PRKEVENT Event
  9539. );
  9540. NTKERNELAPI
  9541. LONG
  9542. KeResetEvent (
  9543. IN PRKEVENT Event
  9544. );
  9545. NTKERNELAPI
  9546. LONG
  9547. KeSetEvent (
  9548. IN PRKEVENT Event,
  9549. IN KPRIORITY Increment,
  9550. IN BOOLEAN Wait
  9551. );
  9552. //
  9553. // Mutex object
  9554. //
  9555. NTKERNELAPI
  9556. VOID
  9557. KeInitializeMutex (
  9558. IN PRKMUTEX Mutex,
  9559. IN ULONG Level
  9560. );
  9561. NTKERNELAPI
  9562. LONG
  9563. KeReadStateMutex (
  9564. IN PRKMUTEX Mutex
  9565. );
  9566. NTKERNELAPI
  9567. LONG
  9568. KeReleaseMutex (
  9569. IN PRKMUTEX Mutex,
  9570. IN BOOLEAN Wait
  9571. );
  9572. //
  9573. // Semaphore object
  9574. //
  9575. NTKERNELAPI
  9576. VOID
  9577. KeInitializeSemaphore (
  9578. IN PRKSEMAPHORE Semaphore,
  9579. IN LONG Count,
  9580. IN LONG Limit
  9581. );
  9582. NTKERNELAPI
  9583. LONG
  9584. KeReadStateSemaphore (
  9585. IN PRKSEMAPHORE Semaphore
  9586. );
  9587. NTKERNELAPI
  9588. LONG
  9589. KeReleaseSemaphore (
  9590. IN PRKSEMAPHORE Semaphore,
  9591. IN KPRIORITY Increment,
  9592. IN LONG Adjustment,
  9593. IN BOOLEAN Wait
  9594. );
  9595. NTKERNELAPI
  9596. NTSTATUS
  9597. KeDelayExecutionThread (
  9598. IN KPROCESSOR_MODE WaitMode,
  9599. IN BOOLEAN Alertable,
  9600. IN PLARGE_INTEGER Interval
  9601. );
  9602. NTKERNELAPI
  9603. KPRIORITY
  9604. KeQueryPriorityThread (
  9605. IN PKTHREAD Thread
  9606. );
  9607. NTKERNELAPI
  9608. ULONG
  9609. KeQueryRuntimeThread (
  9610. IN PKTHREAD Thread,
  9611. OUT PULONG UserTime
  9612. );
  9613. NTKERNELAPI
  9614. LONG
  9615. KeSetBasePriorityThread (
  9616. IN PKTHREAD Thread,
  9617. IN LONG Increment
  9618. );
  9619. NTKERNELAPI
  9620. KPRIORITY
  9621. KeSetPriorityThread (
  9622. IN PKTHREAD Thread,
  9623. IN KPRIORITY Priority
  9624. );
  9625. #if ((defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_) ||defined(_NTHAL_)) && !defined(_NTSYSTEM_DRIVER_) || defined(_NTOSP_))
  9626. NTKERNELAPI
  9627. VOID
  9628. KeEnterCriticalRegion (
  9629. VOID
  9630. );
  9631. NTKERNELAPI
  9632. VOID
  9633. KeLeaveCriticalRegion (
  9634. VOID
  9635. );
  9636. NTKERNELAPI
  9637. BOOLEAN
  9638. KeAreApcsDisabled (
  9639. VOID
  9640. );
  9641. #endif
  9642. //
  9643. // Timer object
  9644. //
  9645. NTKERNELAPI
  9646. VOID
  9647. KeInitializeTimer (
  9648. IN PKTIMER Timer
  9649. );
  9650. NTKERNELAPI
  9651. VOID
  9652. KeInitializeTimerEx (
  9653. IN PKTIMER Timer,
  9654. IN TIMER_TYPE Type
  9655. );
  9656. NTKERNELAPI
  9657. BOOLEAN
  9658. KeCancelTimer (
  9659. IN PKTIMER
  9660. );
  9661. NTKERNELAPI
  9662. BOOLEAN
  9663. KeReadStateTimer (
  9664. PKTIMER Timer
  9665. );
  9666. NTKERNELAPI
  9667. BOOLEAN
  9668. KeSetTimer (
  9669. IN PKTIMER Timer,
  9670. IN LARGE_INTEGER DueTime,
  9671. IN PKDPC Dpc OPTIONAL
  9672. );
  9673. NTKERNELAPI
  9674. BOOLEAN
  9675. KeSetTimerEx (
  9676. IN PKTIMER Timer,
  9677. IN LARGE_INTEGER DueTime,
  9678. IN LONG Period OPTIONAL,
  9679. IN PKDPC Dpc OPTIONAL
  9680. );
  9681. #define KeWaitForMutexObject KeWaitForSingleObject
  9682. NTKERNELAPI
  9683. NTSTATUS
  9684. KeWaitForMultipleObjects (
  9685. IN ULONG Count,
  9686. IN PVOID Object[],
  9687. IN WAIT_TYPE WaitType,
  9688. IN KWAIT_REASON WaitReason,
  9689. IN KPROCESSOR_MODE WaitMode,
  9690. IN BOOLEAN Alertable,
  9691. IN PLARGE_INTEGER Timeout OPTIONAL,
  9692. IN PKWAIT_BLOCK WaitBlockArray OPTIONAL
  9693. );
  9694. NTKERNELAPI
  9695. NTSTATUS
  9696. KeWaitForSingleObject (
  9697. IN PVOID Object,
  9698. IN KWAIT_REASON WaitReason,
  9699. IN KPROCESSOR_MODE WaitMode,
  9700. IN BOOLEAN Alertable,
  9701. IN PLARGE_INTEGER Timeout OPTIONAL
  9702. );
  9703. //
  9704. // Define interprocess interrupt generic call types.
  9705. //
  9706. typedef
  9707. ULONG_PTR
  9708. (*PKIPI_BROADCAST_WORKER)(
  9709. IN ULONG_PTR Argument
  9710. );
  9711. ULONG_PTR
  9712. KeIpiGenericCall (
  9713. IN PKIPI_BROADCAST_WORKER BroadcastFunction,
  9714. IN ULONG_PTR Context
  9715. );
  9716. //
  9717. // On X86 the following routines are defined in the HAL and imported by
  9718. // all other modules.
  9719. //
  9720. #if defined(_X86_) && !defined(_NTHAL_)
  9721. #define _DECL_HAL_KE_IMPORT __declspec(dllimport)
  9722. #else
  9723. #define _DECL_HAL_KE_IMPORT
  9724. #endif
  9725. //
  9726. // spin lock functions
  9727. //
  9728. #if defined(_X86_) && (defined(_WDMDDK_) || defined(WIN9X_COMPAT_SPINLOCK))
  9729. NTKERNELAPI
  9730. VOID
  9731. NTAPI
  9732. KeInitializeSpinLock (
  9733. IN PKSPIN_LOCK SpinLock
  9734. );
  9735. #else
  9736. __inline
  9737. VOID
  9738. NTAPI
  9739. KeInitializeSpinLock (
  9740. IN PKSPIN_LOCK SpinLock
  9741. )
  9742. {
  9743. *SpinLock = 0;
  9744. }
  9745. #endif
  9746. #if defined(_X86_)
  9747. NTKERNELAPI
  9748. VOID
  9749. FASTCALL
  9750. KefAcquireSpinLockAtDpcLevel (
  9751. IN PKSPIN_LOCK SpinLock
  9752. );
  9753. NTKERNELAPI
  9754. VOID
  9755. FASTCALL
  9756. KefReleaseSpinLockFromDpcLevel (
  9757. IN PKSPIN_LOCK SpinLock
  9758. );
  9759. #define KeAcquireSpinLockAtDpcLevel(a) KefAcquireSpinLockAtDpcLevel(a)
  9760. #define KeReleaseSpinLockFromDpcLevel(a) KefReleaseSpinLockFromDpcLevel(a)
  9761. _DECL_HAL_KE_IMPORT
  9762. KIRQL
  9763. FASTCALL
  9764. KfAcquireSpinLock (
  9765. IN PKSPIN_LOCK SpinLock
  9766. );
  9767. _DECL_HAL_KE_IMPORT
  9768. VOID
  9769. FASTCALL
  9770. KfReleaseSpinLock (
  9771. IN PKSPIN_LOCK SpinLock,
  9772. IN KIRQL NewIrql
  9773. );
  9774. #define KeAcquireSpinLock(a,b) *(b) = KfAcquireSpinLock(a)
  9775. #define KeReleaseSpinLock(a,b) KfReleaseSpinLock(a,b)
  9776. NTKERNELAPI
  9777. BOOLEAN
  9778. FASTCALL
  9779. KeTestSpinLock (
  9780. IN PKSPIN_LOCK SpinLock
  9781. );
  9782. NTKERNELAPI
  9783. BOOLEAN
  9784. FASTCALL
  9785. KeTryToAcquireSpinLockAtDpcLevel (
  9786. IN PKSPIN_LOCK SpinLock
  9787. );
  9788. #else
  9789. //
  9790. // These functions are imported for IA64, ntddk, ntifs, nthal, ntosp, and wdm.
  9791. // They can be inlined for the system on AMD64.
  9792. //
  9793. #define KeAcquireSpinLock(SpinLock, OldIrql) \
  9794. *(OldIrql) = KeAcquireSpinLockRaiseToDpc(SpinLock)
  9795. #if defined(_IA64_) || defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_) || defined(_NTHAL_) || defined(_NTOSP_) || defined(_WDMDDK_)
  9796. NTKERNELAPI
  9797. VOID
  9798. KeAcquireSpinLockAtDpcLevel (
  9799. IN PKSPIN_LOCK SpinLock
  9800. );
  9801. NTKERNELAPI
  9802. KIRQL
  9803. KeAcquireSpinLockRaiseToDpc (
  9804. IN PKSPIN_LOCK SpinLock
  9805. );
  9806. NTKERNELAPI
  9807. VOID
  9808. KeReleaseSpinLock (
  9809. IN PKSPIN_LOCK SpinLock,
  9810. IN KIRQL NewIrql
  9811. );
  9812. NTKERNELAPI
  9813. VOID
  9814. KeReleaseSpinLockFromDpcLevel (
  9815. IN PKSPIN_LOCK SpinLock
  9816. );
  9817. NTKERNELAPI
  9818. BOOLEAN
  9819. FASTCALL
  9820. KeTestSpinLock (
  9821. IN PKSPIN_LOCK SpinLock
  9822. );
  9823. NTKERNELAPI
  9824. BOOLEAN
  9825. FASTCALL
  9826. KeTryToAcquireSpinLockAtDpcLevel (
  9827. IN PKSPIN_LOCK SpinLock
  9828. );
  9829. #else
  9830. #if defined(_AMD64_)
  9831. //
  9832. // The system version of these functions are defined in amd64.h for AMD64.
  9833. //
  9834. #endif
  9835. #endif
  9836. #endif
  9837. #if defined(_X86_)
  9838. _DECL_HAL_KE_IMPORT
  9839. VOID
  9840. FASTCALL
  9841. KfLowerIrql (
  9842. IN KIRQL NewIrql
  9843. );
  9844. _DECL_HAL_KE_IMPORT
  9845. KIRQL
  9846. FASTCALL
  9847. KfRaiseIrql (
  9848. IN KIRQL NewIrql
  9849. );
  9850. _DECL_HAL_KE_IMPORT
  9851. KIRQL
  9852. KeRaiseIrqlToDpcLevel(
  9853. VOID
  9854. );
  9855. #define KeLowerIrql(a) KfLowerIrql(a)
  9856. #define KeRaiseIrql(a,b) *(b) = KfRaiseIrql(a)
  9857. #elif defined(_IA64_)
  9858. //
  9859. // These function are defined in IA64.h for the IA64 platform.
  9860. //
  9861. #elif defined(_AMD64_)
  9862. //
  9863. // These function are defined in amd64.h for the AMD64 platform.
  9864. //
  9865. #else
  9866. #error "no target architecture"
  9867. #endif
  9868. //
  9869. // Queued spin lock functions for "in stack" lock handles.
  9870. //
  9871. // The following three functions RAISE and LOWER IRQL when a queued
  9872. // in stack spin lock is acquired or released using these routines.
  9873. //
  9874. _DECL_HAL_KE_IMPORT
  9875. VOID
  9876. FASTCALL
  9877. KeAcquireInStackQueuedSpinLock (
  9878. IN PKSPIN_LOCK SpinLock,
  9879. IN PKLOCK_QUEUE_HANDLE LockHandle
  9880. );
  9881. _DECL_HAL_KE_IMPORT
  9882. VOID
  9883. FASTCALL
  9884. KeReleaseInStackQueuedSpinLock (
  9885. IN PKLOCK_QUEUE_HANDLE LockHandle
  9886. );
  9887. //
  9888. // The following two functions do NOT raise or lower IRQL when a queued
  9889. // in stack spin lock is acquired or released using these functions.
  9890. //
  9891. NTKERNELAPI
  9892. VOID
  9893. FASTCALL
  9894. KeAcquireInStackQueuedSpinLockAtDpcLevel (
  9895. IN PKSPIN_LOCK SpinLock,
  9896. IN PKLOCK_QUEUE_HANDLE LockHandle
  9897. );
  9898. NTKERNELAPI
  9899. VOID
  9900. FASTCALL
  9901. KeReleaseInStackQueuedSpinLockFromDpcLevel (
  9902. IN PKLOCK_QUEUE_HANDLE LockHandle
  9903. );
  9904. //
  9905. // Miscellaneous kernel functions
  9906. //
  9907. typedef enum _KBUGCHECK_BUFFER_DUMP_STATE {
  9908. BufferEmpty,
  9909. BufferInserted,
  9910. BufferStarted,
  9911. BufferFinished,
  9912. BufferIncomplete
  9913. } KBUGCHECK_BUFFER_DUMP_STATE;
  9914. typedef
  9915. VOID
  9916. (*PKBUGCHECK_CALLBACK_ROUTINE) (
  9917. IN PVOID Buffer,
  9918. IN ULONG Length
  9919. );
  9920. typedef struct _KBUGCHECK_CALLBACK_RECORD {
  9921. LIST_ENTRY Entry;
  9922. PKBUGCHECK_CALLBACK_ROUTINE CallbackRoutine;
  9923. PVOID Buffer;
  9924. ULONG Length;
  9925. PUCHAR Component;
  9926. ULONG_PTR Checksum;
  9927. UCHAR State;
  9928. } KBUGCHECK_CALLBACK_RECORD, *PKBUGCHECK_CALLBACK_RECORD;
  9929. #define KeInitializeCallbackRecord(CallbackRecord) \
  9930. (CallbackRecord)->State = BufferEmpty
  9931. NTKERNELAPI
  9932. BOOLEAN
  9933. KeDeregisterBugCheckCallback (
  9934. IN PKBUGCHECK_CALLBACK_RECORD CallbackRecord
  9935. );
  9936. NTKERNELAPI
  9937. BOOLEAN
  9938. KeRegisterBugCheckCallback (
  9939. IN PKBUGCHECK_CALLBACK_RECORD CallbackRecord,
  9940. IN PKBUGCHECK_CALLBACK_ROUTINE CallbackRoutine,
  9941. IN PVOID Buffer,
  9942. IN ULONG Length,
  9943. IN PUCHAR Component
  9944. );
  9945. typedef enum _KBUGCHECK_CALLBACK_REASON {
  9946. KbCallbackInvalid,
  9947. KbCallbackReserved1,
  9948. KbCallbackSecondaryDumpData,
  9949. KbCallbackDumpIo,
  9950. } KBUGCHECK_CALLBACK_REASON;
  9951. typedef
  9952. VOID
  9953. (*PKBUGCHECK_REASON_CALLBACK_ROUTINE) (
  9954. IN KBUGCHECK_CALLBACK_REASON Reason,
  9955. IN struct _KBUGCHECK_REASON_CALLBACK_RECORD* Record,
  9956. IN OUT PVOID ReasonSpecificData,
  9957. IN ULONG ReasonSpecificDataLength
  9958. );
  9959. typedef struct _KBUGCHECK_REASON_CALLBACK_RECORD {
  9960. LIST_ENTRY Entry;
  9961. PKBUGCHECK_REASON_CALLBACK_ROUTINE CallbackRoutine;
  9962. PUCHAR Component;
  9963. ULONG_PTR Checksum;
  9964. KBUGCHECK_CALLBACK_REASON Reason;
  9965. UCHAR State;
  9966. } KBUGCHECK_REASON_CALLBACK_RECORD, *PKBUGCHECK_REASON_CALLBACK_RECORD;
  9967. typedef struct _KBUGCHECK_SECONDARY_DUMP_DATA {
  9968. IN PVOID InBuffer;
  9969. IN ULONG InBufferLength;
  9970. IN ULONG MaximumAllowed;
  9971. OUT GUID Guid;
  9972. OUT PVOID OutBuffer;
  9973. OUT ULONG OutBufferLength;
  9974. } KBUGCHECK_SECONDARY_DUMP_DATA, *PKBUGCHECK_SECONDARY_DUMP_DATA;
  9975. typedef enum _KBUGCHECK_DUMP_IO_TYPE
  9976. {
  9977. KbDumpIoInvalid,
  9978. KbDumpIoHeader,
  9979. KbDumpIoBody,
  9980. KbDumpIoSecondaryData,
  9981. KbDumpIoComplete
  9982. } KBUGCHECK_DUMP_IO_TYPE;
  9983. typedef struct _KBUGCHECK_DUMP_IO {
  9984. IN ULONG64 Offset;
  9985. IN PVOID Buffer;
  9986. IN ULONG BufferLength;
  9987. IN KBUGCHECK_DUMP_IO_TYPE Type;
  9988. } KBUGCHECK_DUMP_IO, *PKBUGCHECK_DUMP_IO;
  9989. NTKERNELAPI
  9990. BOOLEAN
  9991. KeDeregisterBugCheckReasonCallback (
  9992. IN PKBUGCHECK_REASON_CALLBACK_RECORD CallbackRecord
  9993. );
  9994. NTKERNELAPI
  9995. BOOLEAN
  9996. KeRegisterBugCheckReasonCallback (
  9997. IN PKBUGCHECK_REASON_CALLBACK_RECORD CallbackRecord,
  9998. IN PKBUGCHECK_REASON_CALLBACK_ROUTINE CallbackRoutine,
  9999. IN KBUGCHECK_CALLBACK_REASON Reason,
  10000. IN PUCHAR Component
  10001. );
  10002. typedef
  10003. BOOLEAN
  10004. (*PNMI_CALLBACK)(
  10005. IN PVOID Context,
  10006. IN BOOLEAN Handled
  10007. );
  10008. NTKERNELAPI
  10009. PVOID
  10010. KeRegisterNmiCallback(
  10011. PNMI_CALLBACK CallbackRoutine,
  10012. PVOID Context
  10013. );
  10014. NTSTATUS
  10015. KeDeregisterNmiCallback(
  10016. PVOID Handle
  10017. );
  10018. NTKERNELAPI
  10019. DECLSPEC_NORETURN
  10020. VOID
  10021. NTAPI
  10022. KeBugCheck (
  10023. IN ULONG BugCheckCode
  10024. );
  10025. NTKERNELAPI
  10026. DECLSPEC_NORETURN
  10027. VOID
  10028. KeBugCheckEx(
  10029. IN ULONG BugCheckCode,
  10030. IN ULONG_PTR BugCheckParameter1,
  10031. IN ULONG_PTR BugCheckParameter2,
  10032. IN ULONG_PTR BugCheckParameter3,
  10033. IN ULONG_PTR BugCheckParameter4
  10034. );
  10035. #if defined(_AMD64_) || defined(_X86_)
  10036. NTKERNELAPI
  10037. BOOLEAN
  10038. KeInvalidateAllCaches (
  10039. VOID
  10040. );
  10041. #endif
  10042. #if !defined(_AMD64_)
  10043. NTKERNELAPI
  10044. ULONGLONG
  10045. KeQueryInterruptTime (
  10046. VOID
  10047. );
  10048. NTKERNELAPI
  10049. VOID
  10050. KeQuerySystemTime (
  10051. OUT PLARGE_INTEGER CurrentTime
  10052. );
  10053. #endif
  10054. NTKERNELAPI
  10055. ULONG
  10056. KeQueryTimeIncrement (
  10057. VOID
  10058. );
  10059. NTKERNELAPI
  10060. ULONG
  10061. KeGetRecommendedSharedDataAlignment (
  10062. VOID
  10063. );
  10064. NTKERNELAPI
  10065. KAFFINITY
  10066. KeQueryActiveProcessors (
  10067. VOID
  10068. );
  10069. #if defined(_IA64_)
  10070. extern volatile LARGE_INTEGER KeTickCount;
  10071. #elif defined(_X86_)
  10072. extern volatile KSYSTEM_TIME KeTickCount;
  10073. #endif
  10074. typedef enum _MEMORY_CACHING_TYPE_ORIG {
  10075. MmFrameBufferCached = 2
  10076. } MEMORY_CACHING_TYPE_ORIG;
  10077. typedef enum _MEMORY_CACHING_TYPE {
  10078. MmNonCached = FALSE,
  10079. MmCached = TRUE,
  10080. MmWriteCombined = MmFrameBufferCached,
  10081. MmHardwareCoherentCached,
  10082. MmNonCachedUnordered, // IA64
  10083. MmUSWCCached,
  10084. MmMaximumCacheType
  10085. } MEMORY_CACHING_TYPE;
  10086. //
  10087. // Define external data.
  10088. // because of indirection for all drivers external to ntoskrnl these are actually ptrs
  10089. //
  10090. #if defined(_NTDDK_) || defined(_NTIFS_) || defined(_NTHAL_) || defined(_WDMDDK_) || defined(_NTOSP_)
  10091. extern PBOOLEAN KdDebuggerNotPresent;
  10092. extern PBOOLEAN KdDebuggerEnabled;
  10093. #define KD_DEBUGGER_ENABLED *KdDebuggerEnabled
  10094. #define KD_DEBUGGER_NOT_PRESENT *KdDebuggerNotPresent
  10095. #else
  10096. extern BOOLEAN KdDebuggerNotPresent;
  10097. extern BOOLEAN KdDebuggerEnabled;
  10098. #define KD_DEBUGGER_ENABLED KdDebuggerEnabled
  10099. #define KD_DEBUGGER_NOT_PRESENT KdDebuggerNotPresent
  10100. #endif
  10101. NTSTATUS
  10102. KdDisableDebugger(
  10103. VOID
  10104. );
  10105. NTSTATUS
  10106. KdEnableDebugger(
  10107. VOID
  10108. );
  10109. //
  10110. // KdRefreshDebuggerPresent attempts to communicate with
  10111. // the debugger host machine to refresh the state of
  10112. // KdDebuggerNotPresent. It returns the state of
  10113. // KdDebuggerNotPresent while the kd locks are held.
  10114. // KdDebuggerNotPresent may immediately change state
  10115. // after the kd locks are released so it may not
  10116. // match the return value.
  10117. //
  10118. BOOLEAN
  10119. KdRefreshDebuggerNotPresent(
  10120. VOID
  10121. );
  10122. //
  10123. // Pool Allocation routines (in pool.c)
  10124. //
  10125. typedef enum _POOL_TYPE {
  10126. NonPagedPool,
  10127. PagedPool,
  10128. NonPagedPoolMustSucceed,
  10129. DontUseThisType,
  10130. NonPagedPoolCacheAligned,
  10131. PagedPoolCacheAligned,
  10132. NonPagedPoolCacheAlignedMustS,
  10133. MaxPoolType
  10134. ,
  10135. //
  10136. // Note these per session types are carefully chosen so that the appropriate
  10137. // masking still applies as well as MaxPoolType above.
  10138. //
  10139. NonPagedPoolSession = 32,
  10140. PagedPoolSession = NonPagedPoolSession + 1,
  10141. NonPagedPoolMustSucceedSession = PagedPoolSession + 1,
  10142. DontUseThisTypeSession = NonPagedPoolMustSucceedSession + 1,
  10143. NonPagedPoolCacheAlignedSession = DontUseThisTypeSession + 1,
  10144. PagedPoolCacheAlignedSession = NonPagedPoolCacheAlignedSession + 1,
  10145. NonPagedPoolCacheAlignedMustSSession = PagedPoolCacheAlignedSession + 1,
  10146. } POOL_TYPE;
  10147. #define POOL_COLD_ALLOCATION 256 // Note this cannot encode into the header.
  10148. DECLSPEC_DEPRECATED_DDK // Use ExAllocatePoolWithTag
  10149. NTKERNELAPI
  10150. PVOID
  10151. ExAllocatePool(
  10152. IN POOL_TYPE PoolType,
  10153. IN SIZE_T NumberOfBytes
  10154. );
  10155. DECLSPEC_DEPRECATED_DDK // Use ExAllocatePoolWithQuotaTag
  10156. NTKERNELAPI
  10157. PVOID
  10158. ExAllocatePoolWithQuota(
  10159. IN POOL_TYPE PoolType,
  10160. IN SIZE_T NumberOfBytes
  10161. );
  10162. NTKERNELAPI
  10163. PVOID
  10164. NTAPI
  10165. ExAllocatePoolWithTag(
  10166. IN POOL_TYPE PoolType,
  10167. IN SIZE_T NumberOfBytes,
  10168. IN ULONG Tag
  10169. );
  10170. //
  10171. // _EX_POOL_PRIORITY_ provides a method for the system to handle requests
  10172. // intelligently in low resource conditions.
  10173. //
  10174. // LowPoolPriority should be used when it is acceptable to the driver for the
  10175. // mapping request to fail if the system is low on resources. An example of
  10176. // this could be for a non-critical network connection where the driver can
  10177. // handle the failure case when system resources are close to being depleted.
  10178. //
  10179. // NormalPoolPriority should be used when it is acceptable to the driver for the
  10180. // mapping request to fail if the system is very low on resources. An example
  10181. // of this could be for a non-critical local filesystem request.
  10182. //
  10183. // HighPoolPriority should be used when it is unacceptable to the driver for the
  10184. // mapping request to fail unless the system is completely out of resources.
  10185. // An example of this would be the paging file path in a driver.
  10186. //
  10187. // SpecialPool can be specified to bound the allocation at a page end (or
  10188. // beginning). This should only be done on systems being debugged as the
  10189. // memory cost is expensive.
  10190. //
  10191. // N.B. These values are very carefully chosen so that the pool allocation
  10192. // code can quickly crack the priority request.
  10193. //
  10194. typedef enum _EX_POOL_PRIORITY {
  10195. LowPoolPriority,
  10196. LowPoolPrioritySpecialPoolOverrun = 8,
  10197. LowPoolPrioritySpecialPoolUnderrun = 9,
  10198. NormalPoolPriority = 16,
  10199. NormalPoolPrioritySpecialPoolOverrun = 24,
  10200. NormalPoolPrioritySpecialPoolUnderrun = 25,
  10201. HighPoolPriority = 32,
  10202. HighPoolPrioritySpecialPoolOverrun = 40,
  10203. HighPoolPrioritySpecialPoolUnderrun = 41
  10204. } EX_POOL_PRIORITY;
  10205. NTKERNELAPI
  10206. PVOID
  10207. NTAPI
  10208. ExAllocatePoolWithTagPriority(
  10209. IN POOL_TYPE PoolType,
  10210. IN SIZE_T NumberOfBytes,
  10211. IN ULONG Tag,
  10212. IN EX_POOL_PRIORITY Priority
  10213. );
  10214. #ifndef POOL_TAGGING
  10215. #define ExAllocatePoolWithTag(a,b,c) ExAllocatePool(a,b)
  10216. #endif //POOL_TAGGING
  10217. NTKERNELAPI
  10218. PVOID
  10219. ExAllocatePoolWithQuotaTag(
  10220. IN POOL_TYPE PoolType,
  10221. IN SIZE_T NumberOfBytes,
  10222. IN ULONG Tag
  10223. );
  10224. #ifndef POOL_TAGGING
  10225. #define ExAllocatePoolWithQuotaTag(a,b,c) ExAllocatePoolWithQuota(a,b)
  10226. #endif //POOL_TAGGING
  10227. NTKERNELAPI
  10228. VOID
  10229. NTAPI
  10230. ExFreePool(
  10231. IN PVOID P
  10232. );
  10233. #if defined(POOL_TAGGING)
  10234. #define ExFreePool(a) ExFreePoolWithTag(a,0)
  10235. #endif
  10236. //
  10237. // If high order bit in Pool tag is set, then must use ExFreePoolWithTag to free
  10238. //
  10239. #define PROTECTED_POOL 0x80000000
  10240. NTKERNELAPI
  10241. VOID
  10242. ExFreePoolWithTag(
  10243. IN PVOID P,
  10244. IN ULONG Tag
  10245. );
  10246. //
  10247. // Routines to support fast mutexes.
  10248. //
  10249. typedef struct _FAST_MUTEX {
  10250. LONG Count;
  10251. PKTHREAD Owner;
  10252. ULONG Contention;
  10253. KEVENT Event;
  10254. ULONG OldIrql;
  10255. } FAST_MUTEX, *PFAST_MUTEX;
  10256. #define ExInitializeFastMutex(_FastMutex) \
  10257. (_FastMutex)->Count = 1; \
  10258. (_FastMutex)->Owner = NULL; \
  10259. (_FastMutex)->Contention = 0; \
  10260. KeInitializeEvent(&(_FastMutex)->Event, \
  10261. SynchronizationEvent, \
  10262. FALSE);
  10263. NTKERNELAPI
  10264. VOID
  10265. FASTCALL
  10266. ExAcquireFastMutexUnsafe (
  10267. IN PFAST_MUTEX FastMutex
  10268. );
  10269. NTKERNELAPI
  10270. VOID
  10271. FASTCALL
  10272. ExReleaseFastMutexUnsafe (
  10273. IN PFAST_MUTEX FastMutex
  10274. );
  10275. #if defined(_IA64_) || defined(_AMD64_)
  10276. NTKERNELAPI
  10277. VOID
  10278. FASTCALL
  10279. ExAcquireFastMutex (
  10280. IN PFAST_MUTEX FastMutex
  10281. );
  10282. NTKERNELAPI
  10283. VOID
  10284. FASTCALL
  10285. ExReleaseFastMutex (
  10286. IN PFAST_MUTEX FastMutex
  10287. );
  10288. NTKERNELAPI
  10289. BOOLEAN
  10290. FASTCALL
  10291. ExTryToAcquireFastMutex (
  10292. IN PFAST_MUTEX FastMutex
  10293. );
  10294. #elif defined(_X86_)
  10295. NTHALAPI
  10296. VOID
  10297. FASTCALL
  10298. ExAcquireFastMutex (
  10299. IN PFAST_MUTEX FastMutex
  10300. );
  10301. NTHALAPI
  10302. VOID
  10303. FASTCALL
  10304. ExReleaseFastMutex (
  10305. IN PFAST_MUTEX FastMutex
  10306. );
  10307. NTHALAPI
  10308. BOOLEAN
  10309. FASTCALL
  10310. ExTryToAcquireFastMutex (
  10311. IN PFAST_MUTEX FastMutex
  10312. );
  10313. #else
  10314. #error "Target architecture not defined"
  10315. #endif
  10316. //
  10317. #if defined(_WIN64)
  10318. #define ExInterlockedAddLargeStatistic(Addend, Increment) \
  10319. (VOID) InterlockedAdd64(&(Addend)->QuadPart, Increment)
  10320. #else
  10321. #ifdef __cplusplus
  10322. extern "C" {
  10323. #endif
  10324. LONG
  10325. _InterlockedAddLargeStatistic (
  10326. IN PLONGLONG Addend,
  10327. IN ULONG Increment
  10328. );
  10329. #ifdef __cplusplus
  10330. }
  10331. #endif
  10332. #pragma intrinsic (_InterlockedAddLargeStatistic)
  10333. #define ExInterlockedAddLargeStatistic(Addend,Increment) \
  10334. (VOID) _InterlockedAddLargeStatistic ((PLONGLONG)&(Addend)->QuadPart, Increment)
  10335. #endif
  10336. NTKERNELAPI
  10337. LARGE_INTEGER
  10338. ExInterlockedAddLargeInteger (
  10339. IN PLARGE_INTEGER Addend,
  10340. IN LARGE_INTEGER Increment,
  10341. IN PKSPIN_LOCK Lock
  10342. );
  10343. NTKERNELAPI
  10344. ULONG
  10345. FASTCALL
  10346. ExInterlockedAddUlong (
  10347. IN PULONG Addend,
  10348. IN ULONG Increment,
  10349. IN PKSPIN_LOCK Lock
  10350. );
  10351. #if defined(_AMD64_) || defined(_AXP64_) || defined(_IA64_)
  10352. #define ExInterlockedCompareExchange64(Destination, Exchange, Comperand, Lock) \
  10353. InterlockedCompareExchange64(Destination, *(Exchange), *(Comperand))
  10354. #elif defined(_ALPHA_)
  10355. #define ExInterlockedCompareExchange64(Destination, Exchange, Comperand, Lock) \
  10356. ExpInterlockedCompareExchange64(Destination, Exchange, Comperand)
  10357. #else
  10358. #define ExInterlockedCompareExchange64(Destination, Exchange, Comperand, Lock) \
  10359. ExfInterlockedCompareExchange64(Destination, Exchange, Comperand)
  10360. #endif
  10361. NTKERNELAPI
  10362. PLIST_ENTRY
  10363. FASTCALL
  10364. ExInterlockedInsertHeadList (
  10365. IN PLIST_ENTRY ListHead,
  10366. IN PLIST_ENTRY ListEntry,
  10367. IN PKSPIN_LOCK Lock
  10368. );
  10369. NTKERNELAPI
  10370. PLIST_ENTRY
  10371. FASTCALL
  10372. ExInterlockedInsertTailList (
  10373. IN PLIST_ENTRY ListHead,
  10374. IN PLIST_ENTRY ListEntry,
  10375. IN PKSPIN_LOCK Lock
  10376. );
  10377. NTKERNELAPI
  10378. PLIST_ENTRY
  10379. FASTCALL
  10380. ExInterlockedRemoveHeadList (
  10381. IN PLIST_ENTRY ListHead,
  10382. IN PKSPIN_LOCK Lock
  10383. );
  10384. NTKERNELAPI
  10385. PSINGLE_LIST_ENTRY
  10386. FASTCALL
  10387. ExInterlockedPopEntryList (
  10388. IN PSINGLE_LIST_ENTRY ListHead,
  10389. IN PKSPIN_LOCK Lock
  10390. );
  10391. NTKERNELAPI
  10392. PSINGLE_LIST_ENTRY
  10393. FASTCALL
  10394. ExInterlockedPushEntryList (
  10395. IN PSINGLE_LIST_ENTRY ListHead,
  10396. IN PSINGLE_LIST_ENTRY ListEntry,
  10397. IN PKSPIN_LOCK Lock
  10398. );
  10399. //
  10400. // Define interlocked sequenced listhead functions.
  10401. //
  10402. // A sequenced interlocked list is a singly linked list with a header that
  10403. // contains the current depth and a sequence number. Each time an entry is
  10404. // inserted or removed from the list the depth is updated and the sequence
  10405. // number is incremented. This enables AMD64, IA64, and Pentium and later
  10406. // machines to insert and remove from the list without the use of spinlocks.
  10407. //
  10408. #if !defined(_WINBASE_)
  10409. /*++
  10410. Routine Description:
  10411. This function initializes a sequenced singly linked listhead.
  10412. Arguments:
  10413. SListHead - Supplies a pointer to a sequenced singly linked listhead.
  10414. Return Value:
  10415. None.
  10416. --*/
  10417. #if defined(_WIN64) && (defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_) || defined(_NTHAL_) || defined(_NTOSP_))
  10418. NTKERNELAPI
  10419. VOID
  10420. InitializeSListHead (
  10421. IN PSLIST_HEADER SListHead
  10422. );
  10423. #else
  10424. __inline
  10425. VOID
  10426. InitializeSListHead (
  10427. IN PSLIST_HEADER SListHead
  10428. )
  10429. {
  10430. #ifdef _WIN64
  10431. //
  10432. // Slist headers must be 16 byte aligned.
  10433. //
  10434. if ((ULONG_PTR) SListHead & 0x0f) {
  10435. DbgPrint( "InitializeSListHead unaligned Slist header. Address = %p, Caller = %p\n", SListHead, _ReturnAddress());
  10436. RtlRaiseStatus(STATUS_DATATYPE_MISALIGNMENT);
  10437. }
  10438. #endif
  10439. SListHead->Alignment = 0;
  10440. //
  10441. // For IA-64 we save the region number of the elements of the list in a
  10442. // separate field. This imposes the requirement that all elements stored
  10443. // in the list are from the same region.
  10444. #if defined(_IA64_)
  10445. SListHead->Region = (ULONG_PTR)SListHead & VRN_MASK;
  10446. #elif defined(_AMD64_)
  10447. SListHead->Region = 0;
  10448. #endif
  10449. return;
  10450. }
  10451. #endif
  10452. #endif // !defined(_WINBASE_)
  10453. #define ExInitializeSListHead InitializeSListHead
  10454. PSLIST_ENTRY
  10455. FirstEntrySList (
  10456. IN const SLIST_HEADER *SListHead
  10457. );
  10458. /*++
  10459. Routine Description:
  10460. This function queries the current number of entries contained in a
  10461. sequenced single linked list.
  10462. Arguments:
  10463. SListHead - Supplies a pointer to the sequenced listhead which is
  10464. be queried.
  10465. Return Value:
  10466. The current number of entries in the sequenced singly linked list is
  10467. returned as the function value.
  10468. --*/
  10469. #if defined(_WIN64)
  10470. #if (defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_) || defined(_NTHAL_) || defined(_NTOSP_))
  10471. NTKERNELAPI
  10472. USHORT
  10473. ExQueryDepthSList (
  10474. IN PSLIST_HEADER SListHead
  10475. );
  10476. #else
  10477. __inline
  10478. USHORT
  10479. ExQueryDepthSList (
  10480. IN PSLIST_HEADER SListHead
  10481. )
  10482. {
  10483. return (USHORT)(SListHead->Alignment & 0xffff);
  10484. }
  10485. #endif
  10486. #else
  10487. #define ExQueryDepthSList(_listhead_) (_listhead_)->Depth
  10488. #endif
  10489. #if defined(_WIN64)
  10490. #define ExInterlockedPopEntrySList(Head, Lock) \
  10491. ExpInterlockedPopEntrySList(Head)
  10492. #define ExInterlockedPushEntrySList(Head, Entry, Lock) \
  10493. ExpInterlockedPushEntrySList(Head, Entry)
  10494. #define ExInterlockedFlushSList(Head) \
  10495. ExpInterlockedFlushSList(Head)
  10496. #if !defined(_WINBASE_)
  10497. #define InterlockedPopEntrySList(Head) \
  10498. ExpInterlockedPopEntrySList(Head)
  10499. #define InterlockedPushEntrySList(Head, Entry) \
  10500. ExpInterlockedPushEntrySList(Head, Entry)
  10501. #define InterlockedFlushSList(Head) \
  10502. ExpInterlockedFlushSList(Head)
  10503. #define QueryDepthSList(Head) \
  10504. ExQueryDepthSList(Head)
  10505. #endif // !defined(_WINBASE_)
  10506. NTKERNELAPI
  10507. PSLIST_ENTRY
  10508. ExpInterlockedPopEntrySList (
  10509. IN PSLIST_HEADER ListHead
  10510. );
  10511. NTKERNELAPI
  10512. PSLIST_ENTRY
  10513. ExpInterlockedPushEntrySList (
  10514. IN PSLIST_HEADER ListHead,
  10515. IN PSLIST_ENTRY ListEntry
  10516. );
  10517. NTKERNELAPI
  10518. PSLIST_ENTRY
  10519. ExpInterlockedFlushSList (
  10520. IN PSLIST_HEADER ListHead
  10521. );
  10522. #else
  10523. #if defined(_WIN2K_COMPAT_SLIST_USAGE) && defined(_X86_)
  10524. NTKERNELAPI
  10525. PSLIST_ENTRY
  10526. FASTCALL
  10527. ExInterlockedPopEntrySList (
  10528. IN PSLIST_HEADER ListHead,
  10529. IN PKSPIN_LOCK Lock
  10530. );
  10531. NTKERNELAPI
  10532. PSLIST_ENTRY
  10533. FASTCALL
  10534. ExInterlockedPushEntrySList (
  10535. IN PSLIST_HEADER ListHead,
  10536. IN PSLIST_ENTRY ListEntry,
  10537. IN PKSPIN_LOCK Lock
  10538. );
  10539. #else
  10540. #define ExInterlockedPopEntrySList(ListHead, Lock) \
  10541. InterlockedPopEntrySList(ListHead)
  10542. #define ExInterlockedPushEntrySList(ListHead, ListEntry, Lock) \
  10543. InterlockedPushEntrySList(ListHead, ListEntry)
  10544. #endif
  10545. NTKERNELAPI
  10546. PSLIST_ENTRY
  10547. FASTCALL
  10548. ExInterlockedFlushSList (
  10549. IN PSLIST_HEADER ListHead
  10550. );
  10551. #if !defined(_WINBASE_)
  10552. NTKERNELAPI
  10553. PSLIST_ENTRY
  10554. FASTCALL
  10555. InterlockedPopEntrySList (
  10556. IN PSLIST_HEADER ListHead
  10557. );
  10558. NTKERNELAPI
  10559. PSLIST_ENTRY
  10560. FASTCALL
  10561. InterlockedPushEntrySList (
  10562. IN PSLIST_HEADER ListHead,
  10563. IN PSLIST_ENTRY ListEntry
  10564. );
  10565. #define InterlockedFlushSList(Head) \
  10566. ExInterlockedFlushSList(Head)
  10567. #define QueryDepthSList(Head) \
  10568. ExQueryDepthSList(Head)
  10569. #endif // !defined(_WINBASE_)
  10570. #endif // defined(_WIN64)
  10571. typedef
  10572. PVOID
  10573. (*PALLOCATE_FUNCTION) (
  10574. IN POOL_TYPE PoolType,
  10575. IN SIZE_T NumberOfBytes,
  10576. IN ULONG Tag
  10577. );
  10578. typedef
  10579. VOID
  10580. (*PFREE_FUNCTION) (
  10581. IN PVOID Buffer
  10582. );
  10583. #if !defined(_WIN64) && (defined(_NTDDK_) || defined(_NTIFS_) || defined(_NDIS_))
  10584. typedef struct _GENERAL_LOOKASIDE {
  10585. #else
  10586. typedef struct DECLSPEC_CACHEALIGN _GENERAL_LOOKASIDE {
  10587. #endif
  10588. SLIST_HEADER ListHead;
  10589. USHORT Depth;
  10590. USHORT MaximumDepth;
  10591. ULONG TotalAllocates;
  10592. union {
  10593. ULONG AllocateMisses;
  10594. ULONG AllocateHits;
  10595. };
  10596. ULONG TotalFrees;
  10597. union {
  10598. ULONG FreeMisses;
  10599. ULONG FreeHits;
  10600. };
  10601. POOL_TYPE Type;
  10602. ULONG Tag;
  10603. ULONG Size;
  10604. PALLOCATE_FUNCTION Allocate;
  10605. PFREE_FUNCTION Free;
  10606. LIST_ENTRY ListEntry;
  10607. ULONG LastTotalAllocates;
  10608. union {
  10609. ULONG LastAllocateMisses;
  10610. ULONG LastAllocateHits;
  10611. };
  10612. ULONG Future[2];
  10613. } GENERAL_LOOKASIDE, *PGENERAL_LOOKASIDE;
  10614. #if !defined(_WIN64) && (defined(_NTDDK_) || defined(_NTIFS_) || defined(_NDIS_))
  10615. typedef struct _NPAGED_LOOKASIDE_LIST {
  10616. #else
  10617. typedef struct DECLSPEC_CACHEALIGN _NPAGED_LOOKASIDE_LIST {
  10618. #endif
  10619. GENERAL_LOOKASIDE L;
  10620. #if !defined(_AMD64_) && !defined(_IA64_)
  10621. KSPIN_LOCK Lock__ObsoleteButDoNotDelete;
  10622. #endif
  10623. } NPAGED_LOOKASIDE_LIST, *PNPAGED_LOOKASIDE_LIST;
  10624. NTKERNELAPI
  10625. VOID
  10626. ExInitializeNPagedLookasideList (
  10627. IN PNPAGED_LOOKASIDE_LIST Lookaside,
  10628. IN PALLOCATE_FUNCTION Allocate,
  10629. IN PFREE_FUNCTION Free,
  10630. IN ULONG Flags,
  10631. IN SIZE_T Size,
  10632. IN ULONG Tag,
  10633. IN USHORT Depth
  10634. );
  10635. NTKERNELAPI
  10636. VOID
  10637. ExDeleteNPagedLookasideList (
  10638. IN PNPAGED_LOOKASIDE_LIST Lookaside
  10639. );
  10640. __inline
  10641. PVOID
  10642. ExAllocateFromNPagedLookasideList(
  10643. IN PNPAGED_LOOKASIDE_LIST Lookaside
  10644. )
  10645. /*++
  10646. Routine Description:
  10647. This function removes (pops) the first entry from the specified
  10648. nonpaged lookaside list.
  10649. Arguments:
  10650. Lookaside - Supplies a pointer to a nonpaged lookaside list structure.
  10651. Return Value:
  10652. If an entry is removed from the specified lookaside list, then the
  10653. address of the entry is returned as the function value. Otherwise,
  10654. NULL is returned.
  10655. --*/
  10656. {
  10657. PVOID Entry;
  10658. Lookaside->L.TotalAllocates += 1;
  10659. #if defined(_WIN2K_COMPAT_SLIST_USAGE) && defined(_X86_)
  10660. Entry = ExInterlockedPopEntrySList(&Lookaside->L.ListHead,
  10661. &Lookaside->Lock__ObsoleteButDoNotDelete);
  10662. #else
  10663. Entry = InterlockedPopEntrySList(&Lookaside->L.ListHead);
  10664. #endif
  10665. if (Entry == NULL) {
  10666. Lookaside->L.AllocateMisses += 1;
  10667. Entry = (Lookaside->L.Allocate)(Lookaside->L.Type,
  10668. Lookaside->L.Size,
  10669. Lookaside->L.Tag);
  10670. }
  10671. return Entry;
  10672. }
  10673. __inline
  10674. VOID
  10675. ExFreeToNPagedLookasideList(
  10676. IN PNPAGED_LOOKASIDE_LIST Lookaside,
  10677. IN PVOID Entry
  10678. )
  10679. /*++
  10680. Routine Description:
  10681. This function inserts (pushes) the specified entry into the specified
  10682. nonpaged lookaside list.
  10683. Arguments:
  10684. Lookaside - Supplies a pointer to a nonpaged lookaside list structure.
  10685. Entry - Supples a pointer to the entry that is inserted in the
  10686. lookaside list.
  10687. Return Value:
  10688. None.
  10689. --*/
  10690. {
  10691. Lookaside->L.TotalFrees += 1;
  10692. if (ExQueryDepthSList(&Lookaside->L.ListHead) >= Lookaside->L.Depth) {
  10693. Lookaside->L.FreeMisses += 1;
  10694. (Lookaside->L.Free)(Entry);
  10695. } else {
  10696. #if defined(_WIN2K_COMPAT_SLIST_USAGE) && defined(_X86_)
  10697. ExInterlockedPushEntrySList(&Lookaside->L.ListHead,
  10698. (PSLIST_ENTRY)Entry,
  10699. &Lookaside->Lock__ObsoleteButDoNotDelete);
  10700. #else
  10701. InterlockedPushEntrySList(&Lookaside->L.ListHead,
  10702. (PSLIST_ENTRY)Entry);
  10703. #endif
  10704. }
  10705. return;
  10706. }
  10707. #if !defined(_WIN64) && (defined(_NTDDK_) || defined(_NTIFS_) || defined(_NDIS_))
  10708. typedef struct _PAGED_LOOKASIDE_LIST {
  10709. #else
  10710. typedef struct DECLSPEC_CACHEALIGN _PAGED_LOOKASIDE_LIST {
  10711. #endif
  10712. GENERAL_LOOKASIDE L;
  10713. #if !defined(_AMD64_) && !defined(_IA64_)
  10714. FAST_MUTEX Lock__ObsoleteButDoNotDelete;
  10715. #endif
  10716. } PAGED_LOOKASIDE_LIST, *PPAGED_LOOKASIDE_LIST;
  10717. NTKERNELAPI
  10718. VOID
  10719. ExInitializePagedLookasideList (
  10720. IN PPAGED_LOOKASIDE_LIST Lookaside,
  10721. IN PALLOCATE_FUNCTION Allocate,
  10722. IN PFREE_FUNCTION Free,
  10723. IN ULONG Flags,
  10724. IN SIZE_T Size,
  10725. IN ULONG Tag,
  10726. IN USHORT Depth
  10727. );
  10728. NTKERNELAPI
  10729. VOID
  10730. ExDeletePagedLookasideList (
  10731. IN PPAGED_LOOKASIDE_LIST Lookaside
  10732. );
  10733. #if defined(_WIN2K_COMPAT_SLIST_USAGE) && defined(_X86_)
  10734. NTKERNELAPI
  10735. PVOID
  10736. ExAllocateFromPagedLookasideList(
  10737. IN PPAGED_LOOKASIDE_LIST Lookaside
  10738. );
  10739. #else
  10740. __inline
  10741. PVOID
  10742. ExAllocateFromPagedLookasideList(
  10743. IN PPAGED_LOOKASIDE_LIST Lookaside
  10744. )
  10745. /*++
  10746. Routine Description:
  10747. This function removes (pops) the first entry from the specified
  10748. paged lookaside list.
  10749. Arguments:
  10750. Lookaside - Supplies a pointer to a paged lookaside list structure.
  10751. Return Value:
  10752. If an entry is removed from the specified lookaside list, then the
  10753. address of the entry is returned as the function value. Otherwise,
  10754. NULL is returned.
  10755. --*/
  10756. {
  10757. PVOID Entry;
  10758. Lookaside->L.TotalAllocates += 1;
  10759. Entry = InterlockedPopEntrySList(&Lookaside->L.ListHead);
  10760. if (Entry == NULL) {
  10761. Lookaside->L.AllocateMisses += 1;
  10762. Entry = (Lookaside->L.Allocate)(Lookaside->L.Type,
  10763. Lookaside->L.Size,
  10764. Lookaside->L.Tag);
  10765. }
  10766. return Entry;
  10767. }
  10768. #endif
  10769. #if defined(_WIN2K_COMPAT_SLIST_USAGE) && defined(_X86_)
  10770. NTKERNELAPI
  10771. VOID
  10772. ExFreeToPagedLookasideList(
  10773. IN PPAGED_LOOKASIDE_LIST Lookaside,
  10774. IN PVOID Entry
  10775. );
  10776. #else
  10777. __inline
  10778. VOID
  10779. ExFreeToPagedLookasideList(
  10780. IN PPAGED_LOOKASIDE_LIST Lookaside,
  10781. IN PVOID Entry
  10782. )
  10783. /*++
  10784. Routine Description:
  10785. This function inserts (pushes) the specified entry into the specified
  10786. paged lookaside list.
  10787. Arguments:
  10788. Lookaside - Supplies a pointer to a nonpaged lookaside list structure.
  10789. Entry - Supples a pointer to the entry that is inserted in the
  10790. lookaside list.
  10791. Return Value:
  10792. None.
  10793. --*/
  10794. {
  10795. Lookaside->L.TotalFrees += 1;
  10796. if (ExQueryDepthSList(&Lookaside->L.ListHead) >= Lookaside->L.Depth) {
  10797. Lookaside->L.FreeMisses += 1;
  10798. (Lookaside->L.Free)(Entry);
  10799. } else {
  10800. InterlockedPushEntrySList(&Lookaside->L.ListHead,
  10801. (PSLIST_ENTRY)Entry);
  10802. }
  10803. return;
  10804. }
  10805. #endif
  10806. NTKERNELAPI
  10807. VOID
  10808. NTAPI
  10809. ProbeForRead(
  10810. IN CONST VOID *Address,
  10811. IN SIZE_T Length,
  10812. IN ULONG Alignment
  10813. );
  10814. //
  10815. // Common probe for write functions.
  10816. //
  10817. NTKERNELAPI
  10818. VOID
  10819. NTAPI
  10820. ProbeForWrite (
  10821. IN PVOID Address,
  10822. IN SIZE_T Length,
  10823. IN ULONG Alignment
  10824. );
  10825. //
  10826. // Worker Thread
  10827. //
  10828. typedef enum _WORK_QUEUE_TYPE {
  10829. CriticalWorkQueue,
  10830. DelayedWorkQueue,
  10831. HyperCriticalWorkQueue,
  10832. MaximumWorkQueue
  10833. } WORK_QUEUE_TYPE;
  10834. typedef
  10835. VOID
  10836. (*PWORKER_THREAD_ROUTINE)(
  10837. IN PVOID Parameter
  10838. );
  10839. typedef struct _WORK_QUEUE_ITEM {
  10840. LIST_ENTRY List;
  10841. PWORKER_THREAD_ROUTINE WorkerRoutine;
  10842. PVOID Parameter;
  10843. } WORK_QUEUE_ITEM, *PWORK_QUEUE_ITEM;
  10844. #if PRAGMA_DEPRECATED_DDK
  10845. #pragma deprecated(ExInitializeWorkItem) // Use IoAllocateWorkItem
  10846. #endif
  10847. #define ExInitializeWorkItem(Item, Routine, Context) \
  10848. (Item)->WorkerRoutine = (Routine); \
  10849. (Item)->Parameter = (Context); \
  10850. (Item)->List.Flink = NULL;
  10851. DECLSPEC_DEPRECATED_DDK // Use IoQueueWorkItem
  10852. NTKERNELAPI
  10853. VOID
  10854. ExQueueWorkItem(
  10855. IN PWORK_QUEUE_ITEM WorkItem,
  10856. IN WORK_QUEUE_TYPE QueueType
  10857. );
  10858. NTKERNELAPI
  10859. BOOLEAN
  10860. ExIsProcessorFeaturePresent(
  10861. ULONG ProcessorFeature
  10862. );
  10863. //
  10864. // Zone Allocation
  10865. //
  10866. typedef struct _ZONE_SEGMENT_HEADER {
  10867. SINGLE_LIST_ENTRY SegmentList;
  10868. PVOID Reserved;
  10869. } ZONE_SEGMENT_HEADER, *PZONE_SEGMENT_HEADER;
  10870. typedef struct _ZONE_HEADER {
  10871. SINGLE_LIST_ENTRY FreeList;
  10872. SINGLE_LIST_ENTRY SegmentList;
  10873. ULONG BlockSize;
  10874. ULONG TotalSegmentSize;
  10875. } ZONE_HEADER, *PZONE_HEADER;
  10876. DECLSPEC_DEPRECATED_DDK
  10877. NTKERNELAPI
  10878. NTSTATUS
  10879. ExInitializeZone(
  10880. IN PZONE_HEADER Zone,
  10881. IN ULONG BlockSize,
  10882. IN PVOID InitialSegment,
  10883. IN ULONG InitialSegmentSize
  10884. );
  10885. DECLSPEC_DEPRECATED_DDK
  10886. NTKERNELAPI
  10887. NTSTATUS
  10888. ExExtendZone(
  10889. IN PZONE_HEADER Zone,
  10890. IN PVOID Segment,
  10891. IN ULONG SegmentSize
  10892. );
  10893. DECLSPEC_DEPRECATED_DDK
  10894. NTKERNELAPI
  10895. NTSTATUS
  10896. ExInterlockedExtendZone(
  10897. IN PZONE_HEADER Zone,
  10898. IN PVOID Segment,
  10899. IN ULONG SegmentSize,
  10900. IN PKSPIN_LOCK Lock
  10901. );
  10902. //++
  10903. //
  10904. // PVOID
  10905. // ExAllocateFromZone(
  10906. // IN PZONE_HEADER Zone
  10907. // )
  10908. //
  10909. // Routine Description:
  10910. //
  10911. // This routine removes an entry from the zone and returns a pointer to it.
  10912. //
  10913. // Arguments:
  10914. //
  10915. // Zone - Pointer to the zone header controlling the storage from which the
  10916. // entry is to be allocated.
  10917. //
  10918. // Return Value:
  10919. //
  10920. // The function value is a pointer to the storage allocated from the zone.
  10921. //
  10922. //--
  10923. #if PRAGMA_DEPRECATED_DDK
  10924. #pragma deprecated(ExAllocateFromZone)
  10925. #endif
  10926. #define ExAllocateFromZone(Zone) \
  10927. (PVOID)((Zone)->FreeList.Next); \
  10928. if ( (Zone)->FreeList.Next ) (Zone)->FreeList.Next = (Zone)->FreeList.Next->Next
  10929. //++
  10930. //
  10931. // PVOID
  10932. // ExFreeToZone(
  10933. // IN PZONE_HEADER Zone,
  10934. // IN PVOID Block
  10935. // )
  10936. //
  10937. // Routine Description:
  10938. //
  10939. // This routine places the specified block of storage back onto the free
  10940. // list in the specified zone.
  10941. //
  10942. // Arguments:
  10943. //
  10944. // Zone - Pointer to the zone header controlling the storage to which the
  10945. // entry is to be inserted.
  10946. //
  10947. // Block - Pointer to the block of storage to be freed back to the zone.
  10948. //
  10949. // Return Value:
  10950. //
  10951. // Pointer to previous block of storage that was at the head of the free
  10952. // list. NULL implies the zone went from no available free blocks to
  10953. // at least one free block.
  10954. //
  10955. //--
  10956. #if PRAGMA_DEPRECATED_DDK
  10957. #pragma deprecated(ExFreeToZone)
  10958. #endif
  10959. #define ExFreeToZone(Zone,Block) \
  10960. ( ((PSINGLE_LIST_ENTRY)(Block))->Next = (Zone)->FreeList.Next, \
  10961. (Zone)->FreeList.Next = ((PSINGLE_LIST_ENTRY)(Block)), \
  10962. ((PSINGLE_LIST_ENTRY)(Block))->Next \
  10963. )
  10964. //++
  10965. //
  10966. // BOOLEAN
  10967. // ExIsFullZone(
  10968. // IN PZONE_HEADER Zone
  10969. // )
  10970. //
  10971. // Routine Description:
  10972. //
  10973. // This routine determines if the specified zone is full or not. A zone
  10974. // is considered full if the free list is empty.
  10975. //
  10976. // Arguments:
  10977. //
  10978. // Zone - Pointer to the zone header to be tested.
  10979. //
  10980. // Return Value:
  10981. //
  10982. // TRUE if the zone is full and FALSE otherwise.
  10983. //
  10984. //--
  10985. #if PRAGMA_DEPRECATED_DDK
  10986. #pragma deprecated(ExIsFullZone)
  10987. #endif
  10988. #define ExIsFullZone(Zone) \
  10989. ( (Zone)->FreeList.Next == (PSINGLE_LIST_ENTRY)NULL )
  10990. //++
  10991. //
  10992. // PVOID
  10993. // ExInterlockedAllocateFromZone(
  10994. // IN PZONE_HEADER Zone,
  10995. // IN PKSPIN_LOCK Lock
  10996. // )
  10997. //
  10998. // Routine Description:
  10999. //
  11000. // This routine removes an entry from the zone and returns a pointer to it.
  11001. // The removal is performed with the specified lock owned for the sequence
  11002. // to make it MP-safe.
  11003. //
  11004. // Arguments:
  11005. //
  11006. // Zone - Pointer to the zone header controlling the storage from which the
  11007. // entry is to be allocated.
  11008. //
  11009. // Lock - Pointer to the spin lock which should be obtained before removing
  11010. // the entry from the allocation list. The lock is released before
  11011. // returning to the caller.
  11012. //
  11013. // Return Value:
  11014. //
  11015. // The function value is a pointer to the storage allocated from the zone.
  11016. //
  11017. //--
  11018. #if PRAGMA_DEPRECATED_DDK
  11019. #pragma deprecated(ExInterlockedAllocateFromZone)
  11020. #endif
  11021. #define ExInterlockedAllocateFromZone(Zone,Lock) \
  11022. (PVOID) ExInterlockedPopEntryList( &(Zone)->FreeList, Lock )
  11023. //++
  11024. //
  11025. // PVOID
  11026. // ExInterlockedFreeToZone(
  11027. // IN PZONE_HEADER Zone,
  11028. // IN PVOID Block,
  11029. // IN PKSPIN_LOCK Lock
  11030. // )
  11031. //
  11032. // Routine Description:
  11033. //
  11034. // This routine places the specified block of storage back onto the free
  11035. // list in the specified zone. The insertion is performed with the lock
  11036. // owned for the sequence to make it MP-safe.
  11037. //
  11038. // Arguments:
  11039. //
  11040. // Zone - Pointer to the zone header controlling the storage to which the
  11041. // entry is to be inserted.
  11042. //
  11043. // Block - Pointer to the block of storage to be freed back to the zone.
  11044. //
  11045. // Lock - Pointer to the spin lock which should be obtained before inserting
  11046. // the entry onto the free list. The lock is released before returning
  11047. // to the caller.
  11048. //
  11049. // Return Value:
  11050. //
  11051. // Pointer to previous block of storage that was at the head of the free
  11052. // list. NULL implies the zone went from no available free blocks to
  11053. // at least one free block.
  11054. //
  11055. //--
  11056. #if PRAGMA_DEPRECATED_DDK
  11057. #pragma deprecated(ExInterlockedFreeToZone)
  11058. #endif
  11059. #define ExInterlockedFreeToZone(Zone,Block,Lock) \
  11060. ExInterlockedPushEntryList( &(Zone)->FreeList, ((PSINGLE_LIST_ENTRY) (Block)), Lock )
  11061. //++
  11062. //
  11063. // BOOLEAN
  11064. // ExIsObjectInFirstZoneSegment(
  11065. // IN PZONE_HEADER Zone,
  11066. // IN PVOID Object
  11067. // )
  11068. //
  11069. // Routine Description:
  11070. //
  11071. // This routine determines if the specified pointer lives in the zone.
  11072. //
  11073. // Arguments:
  11074. //
  11075. // Zone - Pointer to the zone header controlling the storage to which the
  11076. // object may belong.
  11077. //
  11078. // Object - Pointer to the object in question.
  11079. //
  11080. // Return Value:
  11081. //
  11082. // TRUE if the Object came from the first segment of zone.
  11083. //
  11084. //--
  11085. #if PRAGMA_DEPRECATED_DDK
  11086. #pragma deprecated(ExIsObjectInFirstZoneSegment)
  11087. #endif
  11088. #define ExIsObjectInFirstZoneSegment(Zone,Object) ((BOOLEAN) \
  11089. (((PUCHAR)(Object) >= (PUCHAR)(Zone)->SegmentList.Next) && \
  11090. ((PUCHAR)(Object) < (PUCHAR)(Zone)->SegmentList.Next + \
  11091. (Zone)->TotalSegmentSize)) \
  11092. )
  11093. //
  11094. // Define executive resource data structures.
  11095. //
  11096. typedef ULONG_PTR ERESOURCE_THREAD;
  11097. typedef ERESOURCE_THREAD *PERESOURCE_THREAD;
  11098. typedef struct _OWNER_ENTRY {
  11099. ERESOURCE_THREAD OwnerThread;
  11100. union {
  11101. LONG OwnerCount;
  11102. ULONG TableSize;
  11103. };
  11104. } OWNER_ENTRY, *POWNER_ENTRY;
  11105. typedef struct _ERESOURCE {
  11106. LIST_ENTRY SystemResourcesList;
  11107. POWNER_ENTRY OwnerTable;
  11108. SHORT ActiveCount;
  11109. USHORT Flag;
  11110. PKSEMAPHORE SharedWaiters;
  11111. PKEVENT ExclusiveWaiters;
  11112. OWNER_ENTRY OwnerThreads[2];
  11113. ULONG ContentionCount;
  11114. USHORT NumberOfSharedWaiters;
  11115. USHORT NumberOfExclusiveWaiters;
  11116. union {
  11117. PVOID Address;
  11118. ULONG_PTR CreatorBackTraceIndex;
  11119. };
  11120. KSPIN_LOCK SpinLock;
  11121. } ERESOURCE, *PERESOURCE;
  11122. //
  11123. // Values for ERESOURCE.Flag
  11124. //
  11125. #define ResourceNeverExclusive 0x10
  11126. #define ResourceReleaseByOtherThread 0x20
  11127. #define ResourceOwnedExclusive 0x80
  11128. #define RESOURCE_HASH_TABLE_SIZE 64
  11129. typedef struct _RESOURCE_HASH_ENTRY {
  11130. LIST_ENTRY ListEntry;
  11131. PVOID Address;
  11132. ULONG ContentionCount;
  11133. ULONG Number;
  11134. } RESOURCE_HASH_ENTRY, *PRESOURCE_HASH_ENTRY;
  11135. typedef struct _RESOURCE_PERFORMANCE_DATA {
  11136. ULONG ActiveResourceCount;
  11137. ULONG TotalResourceCount;
  11138. ULONG ExclusiveAcquire;
  11139. ULONG SharedFirstLevel;
  11140. ULONG SharedSecondLevel;
  11141. ULONG StarveFirstLevel;
  11142. ULONG StarveSecondLevel;
  11143. ULONG WaitForExclusive;
  11144. ULONG OwnerTableExpands;
  11145. ULONG MaximumTableExpand;
  11146. LIST_ENTRY HashTable[RESOURCE_HASH_TABLE_SIZE];
  11147. } RESOURCE_PERFORMANCE_DATA, *PRESOURCE_PERFORMANCE_DATA;
  11148. //
  11149. // Define executive resource function prototypes.
  11150. //
  11151. NTKERNELAPI
  11152. NTSTATUS
  11153. ExInitializeResourceLite(
  11154. IN PERESOURCE Resource
  11155. );
  11156. NTKERNELAPI
  11157. NTSTATUS
  11158. ExReinitializeResourceLite(
  11159. IN PERESOURCE Resource
  11160. );
  11161. NTKERNELAPI
  11162. BOOLEAN
  11163. ExAcquireResourceSharedLite(
  11164. IN PERESOURCE Resource,
  11165. IN BOOLEAN Wait
  11166. );
  11167. NTKERNELAPI
  11168. BOOLEAN
  11169. ExAcquireResourceExclusiveLite(
  11170. IN PERESOURCE Resource,
  11171. IN BOOLEAN Wait
  11172. );
  11173. NTKERNELAPI
  11174. BOOLEAN
  11175. ExAcquireSharedStarveExclusive(
  11176. IN PERESOURCE Resource,
  11177. IN BOOLEAN Wait
  11178. );
  11179. NTKERNELAPI
  11180. BOOLEAN
  11181. ExAcquireSharedWaitForExclusive(
  11182. IN PERESOURCE Resource,
  11183. IN BOOLEAN Wait
  11184. );
  11185. NTKERNELAPI
  11186. BOOLEAN
  11187. ExTryToAcquireResourceExclusiveLite(
  11188. IN PERESOURCE Resource
  11189. );
  11190. //
  11191. // VOID
  11192. // ExReleaseResource(
  11193. // IN PERESOURCE Resource
  11194. // );
  11195. //
  11196. #if PRAGMA_DEPRECATED_DDK
  11197. #pragma deprecated(ExReleaseResource) // Use ExReleaseResourceLite
  11198. #endif
  11199. #define ExReleaseResource(R) (ExReleaseResourceLite(R))
  11200. NTKERNELAPI
  11201. VOID
  11202. FASTCALL
  11203. ExReleaseResourceLite(
  11204. IN PERESOURCE Resource
  11205. );
  11206. NTKERNELAPI
  11207. VOID
  11208. ExReleaseResourceForThreadLite(
  11209. IN PERESOURCE Resource,
  11210. IN ERESOURCE_THREAD ResourceThreadId
  11211. );
  11212. NTKERNELAPI
  11213. VOID
  11214. ExSetResourceOwnerPointer(
  11215. IN PERESOURCE Resource,
  11216. IN PVOID OwnerPointer
  11217. );
  11218. NTKERNELAPI
  11219. VOID
  11220. ExConvertExclusiveToSharedLite(
  11221. IN PERESOURCE Resource
  11222. );
  11223. NTKERNELAPI
  11224. NTSTATUS
  11225. ExDeleteResourceLite (
  11226. IN PERESOURCE Resource
  11227. );
  11228. NTKERNELAPI
  11229. ULONG
  11230. ExGetExclusiveWaiterCount (
  11231. IN PERESOURCE Resource
  11232. );
  11233. NTKERNELAPI
  11234. ULONG
  11235. ExGetSharedWaiterCount (
  11236. IN PERESOURCE Resource
  11237. );
  11238. //
  11239. // ERESOURCE_THREAD
  11240. // ExGetCurrentResourceThread(
  11241. // );
  11242. //
  11243. #define ExGetCurrentResourceThread() ((ULONG_PTR)PsGetCurrentThread())
  11244. NTKERNELAPI
  11245. BOOLEAN
  11246. ExIsResourceAcquiredExclusiveLite (
  11247. IN PERESOURCE Resource
  11248. );
  11249. NTKERNELAPI
  11250. ULONG
  11251. ExIsResourceAcquiredSharedLite (
  11252. IN PERESOURCE Resource
  11253. );
  11254. //
  11255. // An acquired resource is always owned shared, as shared ownership is a subset
  11256. // of exclusive ownership.
  11257. //
  11258. #define ExIsResourceAcquiredLite ExIsResourceAcquiredSharedLite
  11259. //
  11260. // ntddk.h stole the entrypoints we wanted so fix them up here.
  11261. //
  11262. #if PRAGMA_DEPRECATED_DDK
  11263. #pragma deprecated(ExInitializeResource) // use ExInitializeResourceLite
  11264. #pragma deprecated(ExAcquireResourceShared) // use ExAcquireResourceSharedLite
  11265. #pragma deprecated(ExAcquireResourceExclusive) // use ExAcquireResourceExclusiveLite
  11266. #pragma deprecated(ExReleaseResourceForThread) // use ExReleaseResourceForThreadLite
  11267. #pragma deprecated(ExConvertExclusiveToShared) // use ExConvertExclusiveToSharedLite
  11268. #pragma deprecated(ExDeleteResource) // use ExDeleteResourceLite
  11269. #pragma deprecated(ExIsResourceAcquiredExclusive) // use ExIsResourceAcquiredExclusiveLite
  11270. #pragma deprecated(ExIsResourceAcquiredShared) // use ExIsResourceAcquiredSharedLite
  11271. #pragma deprecated(ExIsResourceAcquired) // use ExIsResourceAcquiredSharedLite
  11272. #endif
  11273. #define ExInitializeResource ExInitializeResourceLite
  11274. #define ExAcquireResourceShared ExAcquireResourceSharedLite
  11275. #define ExAcquireResourceExclusive ExAcquireResourceExclusiveLite
  11276. #define ExReleaseResourceForThread ExReleaseResourceForThreadLite
  11277. #define ExConvertExclusiveToShared ExConvertExclusiveToSharedLite
  11278. #define ExDeleteResource ExDeleteResourceLite
  11279. #define ExIsResourceAcquiredExclusive ExIsResourceAcquiredExclusiveLite
  11280. #define ExIsResourceAcquiredShared ExIsResourceAcquiredSharedLite
  11281. #define ExIsResourceAcquired ExIsResourceAcquiredSharedLite
  11282. //
  11283. // Get previous mode
  11284. //
  11285. NTKERNELAPI
  11286. KPROCESSOR_MODE
  11287. ExGetPreviousMode(
  11288. VOID
  11289. );
  11290. //
  11291. // Raise status from kernel mode.
  11292. //
  11293. NTKERNELAPI
  11294. VOID
  11295. NTAPI
  11296. ExRaiseStatus (
  11297. IN NTSTATUS Status
  11298. );
  11299. NTKERNELAPI
  11300. VOID
  11301. ExRaiseDatatypeMisalignment (
  11302. VOID
  11303. );
  11304. NTKERNELAPI
  11305. VOID
  11306. ExRaiseAccessViolation (
  11307. VOID
  11308. );
  11309. //
  11310. // Set timer resolution.
  11311. //
  11312. NTKERNELAPI
  11313. ULONG
  11314. ExSetTimerResolution (
  11315. IN ULONG DesiredTime,
  11316. IN BOOLEAN SetResolution
  11317. );
  11318. //
  11319. // Subtract time zone bias from system time to get local time.
  11320. //
  11321. NTKERNELAPI
  11322. VOID
  11323. ExSystemTimeToLocalTime (
  11324. IN PLARGE_INTEGER SystemTime,
  11325. OUT PLARGE_INTEGER LocalTime
  11326. );
  11327. //
  11328. // Add time zone bias to local time to get system time.
  11329. //
  11330. NTKERNELAPI
  11331. VOID
  11332. ExLocalTimeToSystemTime (
  11333. IN PLARGE_INTEGER LocalTime,
  11334. OUT PLARGE_INTEGER SystemTime
  11335. );
  11336. //
  11337. // Define the type for Callback function.
  11338. //
  11339. typedef struct _CALLBACK_OBJECT *PCALLBACK_OBJECT;
  11340. typedef VOID (*PCALLBACK_FUNCTION ) (
  11341. IN PVOID CallbackContext,
  11342. IN PVOID Argument1,
  11343. IN PVOID Argument2
  11344. );
  11345. NTKERNELAPI
  11346. NTSTATUS
  11347. ExCreateCallback (
  11348. OUT PCALLBACK_OBJECT *CallbackObject,
  11349. IN POBJECT_ATTRIBUTES ObjectAttributes,
  11350. IN BOOLEAN Create,
  11351. IN BOOLEAN AllowMultipleCallbacks
  11352. );
  11353. NTKERNELAPI
  11354. PVOID
  11355. ExRegisterCallback (
  11356. IN PCALLBACK_OBJECT CallbackObject,
  11357. IN PCALLBACK_FUNCTION CallbackFunction,
  11358. IN PVOID CallbackContext
  11359. );
  11360. NTKERNELAPI
  11361. VOID
  11362. ExUnregisterCallback (
  11363. IN PVOID CallbackRegistration
  11364. );
  11365. NTKERNELAPI
  11366. VOID
  11367. ExNotifyCallback (
  11368. IN PVOID CallbackObject,
  11369. IN PVOID Argument1,
  11370. IN PVOID Argument2
  11371. );
  11372. //
  11373. // UUID Generation
  11374. //
  11375. typedef GUID UUID;
  11376. NTKERNELAPI
  11377. NTSTATUS
  11378. ExUuidCreate(
  11379. OUT UUID *Uuid
  11380. );
  11381. //
  11382. // suite support
  11383. //
  11384. NTKERNELAPI
  11385. BOOLEAN
  11386. ExVerifySuite(
  11387. SUITE_TYPE SuiteType
  11388. );
  11389. //
  11390. // Define a block to hold the actual routine registration.
  11391. //
  11392. typedef NTSTATUS (*PEX_CALLBACK_FUNCTION ) (
  11393. IN PVOID CallbackContext,
  11394. IN PVOID Argument1,
  11395. IN PVOID Argument2
  11396. );
  11397. //
  11398. // Registry kernel mode callbacks
  11399. //
  11400. //
  11401. // Hook selector
  11402. //
  11403. typedef enum _REG_NOTIFY_CLASS {
  11404. RegNtDeleteKey,
  11405. RegNtPreDeleteKey = RegNtDeleteKey,
  11406. RegNtSetValueKey,
  11407. RegNtPreSetValueKey = RegNtSetValueKey,
  11408. RegNtDeleteValueKey,
  11409. RegNtPreDeleteValueKey = RegNtDeleteValueKey,
  11410. RegNtSetInformationKey,
  11411. RegNtPreSetInformationKey = RegNtSetInformationKey,
  11412. RegNtRenameKey,
  11413. RegNtPreRenameKey = RegNtRenameKey,
  11414. RegNtEnumerateKey,
  11415. RegNtPreEnumerateKey = RegNtEnumerateKey,
  11416. RegNtEnumerateValueKey,
  11417. RegNtPreEnumerateValueKey = RegNtEnumerateValueKey,
  11418. RegNtQueryKey,
  11419. RegNtPreQueryKey = RegNtQueryKey,
  11420. RegNtQueryValueKey,
  11421. RegNtPreQueryValueKey = RegNtQueryValueKey,
  11422. RegNtQueryMultipleValueKey,
  11423. RegNtPreQueryMultipleValueKey = RegNtQueryMultipleValueKey,
  11424. RegNtPreCreateKey,
  11425. RegNtPostCreateKey,
  11426. RegNtPreOpenKey,
  11427. RegNtPostOpenKey,
  11428. RegNtKeyHandleClose,
  11429. RegNtPreKeyHandleClose = RegNtKeyHandleClose,
  11430. //
  11431. // .Net only
  11432. //
  11433. RegNtPostDeleteKey,
  11434. RegNtPostSetValueKey,
  11435. RegNtPostDeleteValueKey,
  11436. RegNtPostSetInformationKey,
  11437. RegNtPostRenameKey,
  11438. RegNtPostEnumerateKey,
  11439. RegNtPostEnumerateValueKey,
  11440. RegNtPostQueryKey,
  11441. RegNtPostQueryValueKey,
  11442. RegNtPostQueryMultipleValueKey,
  11443. RegNtPostKeyHandleClose,
  11444. RegNtPreCreateKeyEx,
  11445. RegNtPostCreateKeyEx,
  11446. RegNtPreOpenKeyEx,
  11447. RegNtPostOpenKeyEx
  11448. } REG_NOTIFY_CLASS;
  11449. //
  11450. // Parameter description for each notify class
  11451. //
  11452. typedef struct _REG_DELETE_KEY_INFORMATION {
  11453. PVOID Object; // IN
  11454. } REG_DELETE_KEY_INFORMATION, *PREG_DELETE_KEY_INFORMATION;
  11455. typedef struct _REG_SET_VALUE_KEY_INFORMATION {
  11456. PVOID Object; // IN
  11457. PUNICODE_STRING ValueName; // IN
  11458. ULONG TitleIndex; // IN
  11459. ULONG Type; // IN
  11460. PVOID Data; // IN
  11461. ULONG DataSize; // IN
  11462. } REG_SET_VALUE_KEY_INFORMATION, *PREG_SET_VALUE_KEY_INFORMATION;
  11463. typedef struct _REG_DELETE_VALUE_KEY_INFORMATION {
  11464. PVOID Object; // IN
  11465. PUNICODE_STRING ValueName; // IN
  11466. } REG_DELETE_VALUE_KEY_INFORMATION, *PREG_DELETE_VALUE_KEY_INFORMATION;
  11467. typedef struct _REG_SET_INFORMATION_KEY_INFORMATION {
  11468. PVOID Object; // IN
  11469. KEY_SET_INFORMATION_CLASS KeySetInformationClass; // IN
  11470. PVOID KeySetInformation; // IN
  11471. ULONG KeySetInformationLength;// IN
  11472. } REG_SET_INFORMATION_KEY_INFORMATION, *PREG_SET_INFORMATION_KEY_INFORMATION;
  11473. typedef struct _REG_ENUMERATE_KEY_INFORMATION {
  11474. PVOID Object; // IN
  11475. ULONG Index; // IN
  11476. KEY_INFORMATION_CLASS KeyInformationClass; // IN
  11477. PVOID KeyInformation; // IN
  11478. ULONG Length; // IN
  11479. PULONG ResultLength; // OUT
  11480. } REG_ENUMERATE_KEY_INFORMATION, *PREG_ENUMERATE_KEY_INFORMATION;
  11481. typedef struct _REG_ENUMERATE_VALUE_KEY_INFORMATION {
  11482. PVOID Object; // IN
  11483. ULONG Index; // IN
  11484. KEY_VALUE_INFORMATION_CLASS KeyValueInformationClass; // IN
  11485. PVOID KeyValueInformation; // IN
  11486. ULONG Length; // IN
  11487. PULONG ResultLength; // OUT
  11488. } REG_ENUMERATE_VALUE_KEY_INFORMATION, *PREG_ENUMERATE_VALUE_KEY_INFORMATION;
  11489. typedef struct _REG_QUERY_KEY_INFORMATION {
  11490. PVOID Object; // IN
  11491. KEY_INFORMATION_CLASS KeyInformationClass; // IN
  11492. PVOID KeyInformation; // IN
  11493. ULONG Length; // IN
  11494. PULONG ResultLength; // OUT
  11495. } REG_QUERY_KEY_INFORMATION, *PREG_QUERY_KEY_INFORMATION;
  11496. typedef struct _REG_QUERY_VALUE_KEY_INFORMATION {
  11497. PVOID Object; // IN
  11498. PUNICODE_STRING ValueName; // IN
  11499. KEY_VALUE_INFORMATION_CLASS KeyValueInformationClass; // IN
  11500. PVOID KeyValueInformation; // IN
  11501. ULONG Length; // IN
  11502. PULONG ResultLength; // OUT
  11503. } REG_QUERY_VALUE_KEY_INFORMATION, *PREG_QUERY_VALUE_KEY_INFORMATION;
  11504. typedef struct _REG_QUERY_MULTIPLE_VALUE_KEY_INFORMATION {
  11505. PVOID Object; // IN
  11506. PKEY_VALUE_ENTRY ValueEntries; // IN
  11507. ULONG EntryCount; // IN
  11508. PVOID ValueBuffer; // IN
  11509. PULONG BufferLength; // IN OUT
  11510. PULONG RequiredBufferLength; // OUT
  11511. } REG_QUERY_MULTIPLE_VALUE_KEY_INFORMATION, *PREG_QUERY_MULTIPLE_VALUE_KEY_INFORMATION;
  11512. typedef struct _REG_RENAME_KEY_INFORMATION {
  11513. PVOID Object; // IN
  11514. PUNICODE_STRING NewName; // IN
  11515. } REG_RENAME_KEY_INFORMATION, *PREG_RENAME_KEY_INFORMATION;
  11516. typedef struct _REG_KEY_HANDLE_CLOSE_INFORMATION {
  11517. PVOID Object; // IN
  11518. } REG_KEY_HANDLE_CLOSE_INFORMATION, *PREG_KEY_HANDLE_CLOSE_INFORMATION;
  11519. /* .Net Only */
  11520. typedef struct _REG_CREATE_KEY_INFORMATION {
  11521. PUNICODE_STRING CompleteName; // IN
  11522. PVOID RootObject; // IN
  11523. } REG_CREATE_KEY_INFORMATION, REG_OPEN_KEY_INFORMATION,*PREG_CREATE_KEY_INFORMATION, *PREG_OPEN_KEY_INFORMATION;
  11524. typedef struct _REG_POST_OPERATION_INFORMATION {
  11525. PVOID Object; // IN
  11526. NTSTATUS Status; // IN
  11527. } REG_POST_OPERATION_INFORMATION,*PREG_POST_OPERATION_INFORMATION;
  11528. /* end .Net Only */
  11529. /* XP only */
  11530. typedef struct _REG_PRE_CREATE_KEY_INFORMATION {
  11531. PUNICODE_STRING CompleteName; // IN
  11532. } REG_PRE_CREATE_KEY_INFORMATION, REG_PRE_OPEN_KEY_INFORMATION,*PREG_PRE_CREATE_KEY_INFORMATION, *PREG_PRE_OPEN_KEY_INFORMATION;;
  11533. typedef struct _REG_POST_CREATE_KEY_INFORMATION {
  11534. PUNICODE_STRING CompleteName; // IN
  11535. PVOID Object; // IN
  11536. NTSTATUS Status; // IN
  11537. } REG_POST_CREATE_KEY_INFORMATION,REG_POST_OPEN_KEY_INFORMATION, *PREG_POST_CREATE_KEY_INFORMATION, *PREG_POST_OPEN_KEY_INFORMATION;
  11538. /* end XP only */
  11539. NTSTATUS
  11540. CmRegisterCallback(IN PEX_CALLBACK_FUNCTION Function,
  11541. IN PVOID Context,
  11542. IN OUT PLARGE_INTEGER Cookie
  11543. );
  11544. NTSTATUS
  11545. CmUnRegisterCallback(IN LARGE_INTEGER Cookie);
  11546. //
  11547. // Priority increment definitions. The comment for each definition gives
  11548. // the names of the system services that use the definition when satisfying
  11549. // a wait.
  11550. //
  11551. //
  11552. // Priority increment used when satisfying a wait on an executive event
  11553. // (NtPulseEvent and NtSetEvent)
  11554. //
  11555. #define EVENT_INCREMENT 1
  11556. //
  11557. // Priority increment when no I/O has been done. This is used by device
  11558. // and file system drivers when completing an IRP (IoCompleteRequest).
  11559. //
  11560. #define IO_NO_INCREMENT 0
  11561. //
  11562. // Priority increment for completing CD-ROM I/O. This is used by CD-ROM device
  11563. // and file system drivers when completing an IRP (IoCompleteRequest)
  11564. //
  11565. #define IO_CD_ROM_INCREMENT 1
  11566. //
  11567. // Priority increment for completing disk I/O. This is used by disk device
  11568. // and file system drivers when completing an IRP (IoCompleteRequest)
  11569. //
  11570. #define IO_DISK_INCREMENT 1
  11571. //
  11572. // Priority increment for completing keyboard I/O. This is used by keyboard
  11573. // device drivers when completing an IRP (IoCompleteRequest)
  11574. //
  11575. #define IO_KEYBOARD_INCREMENT 6
  11576. //
  11577. // Priority increment for completing mailslot I/O. This is used by the mail-
  11578. // slot file system driver when completing an IRP (IoCompleteRequest).
  11579. //
  11580. #define IO_MAILSLOT_INCREMENT 2
  11581. //
  11582. // Priority increment for completing mouse I/O. This is used by mouse device
  11583. // drivers when completing an IRP (IoCompleteRequest)
  11584. //
  11585. #define IO_MOUSE_INCREMENT 6
  11586. //
  11587. // Priority increment for completing named pipe I/O. This is used by the
  11588. // named pipe file system driver when completing an IRP (IoCompleteRequest).
  11589. //
  11590. #define IO_NAMED_PIPE_INCREMENT 2
  11591. //
  11592. // Priority increment for completing network I/O. This is used by network
  11593. // device and network file system drivers when completing an IRP
  11594. // (IoCompleteRequest).
  11595. //
  11596. #define IO_NETWORK_INCREMENT 2
  11597. //
  11598. // Priority increment for completing parallel I/O. This is used by parallel
  11599. // device drivers when completing an IRP (IoCompleteRequest)
  11600. //
  11601. #define IO_PARALLEL_INCREMENT 1
  11602. //
  11603. // Priority increment for completing serial I/O. This is used by serial device
  11604. // drivers when completing an IRP (IoCompleteRequest)
  11605. //
  11606. #define IO_SERIAL_INCREMENT 2
  11607. //
  11608. // Priority increment for completing sound I/O. This is used by sound device
  11609. // drivers when completing an IRP (IoCompleteRequest)
  11610. //
  11611. #define IO_SOUND_INCREMENT 8
  11612. //
  11613. // Priority increment for completing video I/O. This is used by video device
  11614. // drivers when completing an IRP (IoCompleteRequest)
  11615. //
  11616. #define IO_VIDEO_INCREMENT 1
  11617. //
  11618. // Priority increment used when satisfying a wait on an executive semaphore
  11619. // (NtReleaseSemaphore)
  11620. //
  11621. #define SEMAPHORE_INCREMENT 1
  11622. //
  11623. // Indicates the system may do I/O to physical addresses above 4 GB.
  11624. //
  11625. extern PBOOLEAN Mm64BitPhysicalAddress;
  11626. //
  11627. // Define maximum disk transfer size to be used by MM and Cache Manager,
  11628. // so that packet-oriented disk drivers can optimize their packet allocation
  11629. // to this size.
  11630. //
  11631. #define MM_MAXIMUM_DISK_IO_SIZE (0x10000)
  11632. //++
  11633. //
  11634. // ULONG_PTR
  11635. // ROUND_TO_PAGES (
  11636. // IN ULONG_PTR Size
  11637. // )
  11638. //
  11639. // Routine Description:
  11640. //
  11641. // The ROUND_TO_PAGES macro takes a size in bytes and rounds it up to a
  11642. // multiple of the page size.
  11643. //
  11644. // NOTE: This macro fails for values 0xFFFFFFFF - (PAGE_SIZE - 1).
  11645. //
  11646. // Arguments:
  11647. //
  11648. // Size - Size in bytes to round up to a page multiple.
  11649. //
  11650. // Return Value:
  11651. //
  11652. // Returns the size rounded up to a multiple of the page size.
  11653. //
  11654. //--
  11655. #define ROUND_TO_PAGES(Size) (((ULONG_PTR)(Size) + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1))
  11656. //++
  11657. //
  11658. // ULONG
  11659. // BYTES_TO_PAGES (
  11660. // IN ULONG Size
  11661. // )
  11662. //
  11663. // Routine Description:
  11664. //
  11665. // The BYTES_TO_PAGES macro takes the size in bytes and calculates the
  11666. // number of pages required to contain the bytes.
  11667. //
  11668. // Arguments:
  11669. //
  11670. // Size - Size in bytes.
  11671. //
  11672. // Return Value:
  11673. //
  11674. // Returns the number of pages required to contain the specified size.
  11675. //
  11676. //--
  11677. #define BYTES_TO_PAGES(Size) (((Size) >> PAGE_SHIFT) + \
  11678. (((Size) & (PAGE_SIZE - 1)) != 0))
  11679. //++
  11680. //
  11681. // ULONG
  11682. // BYTE_OFFSET (
  11683. // IN PVOID Va
  11684. // )
  11685. //
  11686. // Routine Description:
  11687. //
  11688. // The BYTE_OFFSET macro takes a virtual address and returns the byte offset
  11689. // of that address within the page.
  11690. //
  11691. // Arguments:
  11692. //
  11693. // Va - Virtual address.
  11694. //
  11695. // Return Value:
  11696. //
  11697. // Returns the byte offset portion of the virtual address.
  11698. //
  11699. //--
  11700. #define BYTE_OFFSET(Va) ((ULONG)((LONG_PTR)(Va) & (PAGE_SIZE - 1)))
  11701. //++
  11702. //
  11703. // PVOID
  11704. // PAGE_ALIGN (
  11705. // IN PVOID Va
  11706. // )
  11707. //
  11708. // Routine Description:
  11709. //
  11710. // The PAGE_ALIGN macro takes a virtual address and returns a page-aligned
  11711. // virtual address for that page.
  11712. //
  11713. // Arguments:
  11714. //
  11715. // Va - Virtual address.
  11716. //
  11717. // Return Value:
  11718. //
  11719. // Returns the page aligned virtual address.
  11720. //
  11721. //--
  11722. #define PAGE_ALIGN(Va) ((PVOID)((ULONG_PTR)(Va) & ~(PAGE_SIZE - 1)))
  11723. //++
  11724. //
  11725. // ULONG
  11726. // ADDRESS_AND_SIZE_TO_SPAN_PAGES (
  11727. // IN PVOID Va,
  11728. // IN ULONG Size
  11729. // )
  11730. //
  11731. // Routine Description:
  11732. //
  11733. // The ADDRESS_AND_SIZE_TO_SPAN_PAGES macro takes a virtual address and
  11734. // size and returns the number of pages spanned by the size.
  11735. //
  11736. // Arguments:
  11737. //
  11738. // Va - Virtual address.
  11739. //
  11740. // Size - Size in bytes.
  11741. //
  11742. // Return Value:
  11743. //
  11744. // Returns the number of pages spanned by the size.
  11745. //
  11746. //--
  11747. #define ADDRESS_AND_SIZE_TO_SPAN_PAGES(Va,Size) \
  11748. ((ULONG)((((ULONG_PTR)(Va) & (PAGE_SIZE -1)) + (Size) + (PAGE_SIZE - 1)) >> PAGE_SHIFT))
  11749. #if PRAGMA_DEPRECATED_DDK
  11750. #pragma deprecated(COMPUTE_PAGES_SPANNED) // Use ADDRESS_AND_SIZE_TO_SPAN_PAGES
  11751. #endif
  11752. #define COMPUTE_PAGES_SPANNED(Va, Size) ADDRESS_AND_SIZE_TO_SPAN_PAGES(Va,Size)
  11753. //++
  11754. // PPFN_NUMBER
  11755. // MmGetMdlPfnArray (
  11756. // IN PMDL Mdl
  11757. // )
  11758. //
  11759. // Routine Description:
  11760. //
  11761. // The MmGetMdlPfnArray routine returns the virtual address of the
  11762. // first element of the array of physical page numbers associated with
  11763. // the MDL.
  11764. //
  11765. // Arguments:
  11766. //
  11767. // Mdl - Pointer to an MDL.
  11768. //
  11769. // Return Value:
  11770. //
  11771. // Returns the virtual address of the first element of the array of
  11772. // physical page numbers associated with the MDL.
  11773. //
  11774. //--
  11775. #define MmGetMdlPfnArray(Mdl) ((PPFN_NUMBER)(Mdl + 1))
  11776. //++
  11777. //
  11778. // PVOID
  11779. // MmGetMdlVirtualAddress (
  11780. // IN PMDL Mdl
  11781. // )
  11782. //
  11783. // Routine Description:
  11784. //
  11785. // The MmGetMdlVirtualAddress returns the virtual address of the buffer
  11786. // described by the Mdl.
  11787. //
  11788. // Arguments:
  11789. //
  11790. // Mdl - Pointer to an MDL.
  11791. //
  11792. // Return Value:
  11793. //
  11794. // Returns the virtual address of the buffer described by the Mdl
  11795. //
  11796. //--
  11797. #define MmGetMdlVirtualAddress(Mdl) \
  11798. ((PVOID) ((PCHAR) ((Mdl)->StartVa) + (Mdl)->ByteOffset))
  11799. //++
  11800. //
  11801. // ULONG
  11802. // MmGetMdlByteCount (
  11803. // IN PMDL Mdl
  11804. // )
  11805. //
  11806. // Routine Description:
  11807. //
  11808. // The MmGetMdlByteCount returns the length in bytes of the buffer
  11809. // described by the Mdl.
  11810. //
  11811. // Arguments:
  11812. //
  11813. // Mdl - Pointer to an MDL.
  11814. //
  11815. // Return Value:
  11816. //
  11817. // Returns the byte count of the buffer described by the Mdl
  11818. //
  11819. //--
  11820. #define MmGetMdlByteCount(Mdl) ((Mdl)->ByteCount)
  11821. //++
  11822. //
  11823. // ULONG
  11824. // MmGetMdlByteOffset (
  11825. // IN PMDL Mdl
  11826. // )
  11827. //
  11828. // Routine Description:
  11829. //
  11830. // The MmGetMdlByteOffset returns the byte offset within the page
  11831. // of the buffer described by the Mdl.
  11832. //
  11833. // Arguments:
  11834. //
  11835. // Mdl - Pointer to an MDL.
  11836. //
  11837. // Return Value:
  11838. //
  11839. // Returns the byte offset within the page of the buffer described by the Mdl
  11840. //
  11841. //--
  11842. #define MmGetMdlByteOffset(Mdl) ((Mdl)->ByteOffset)
  11843. //++
  11844. //
  11845. // PVOID
  11846. // MmGetMdlStartVa (
  11847. // IN PMDL Mdl
  11848. // )
  11849. //
  11850. // Routine Description:
  11851. //
  11852. // The MmGetMdlBaseVa returns the virtual address of the buffer
  11853. // described by the Mdl rounded down to the nearest page.
  11854. //
  11855. // Arguments:
  11856. //
  11857. // Mdl - Pointer to an MDL.
  11858. //
  11859. // Return Value:
  11860. //
  11861. // Returns the returns the starting virtual address of the MDL.
  11862. //
  11863. //
  11864. //--
  11865. #define MmGetMdlBaseVa(Mdl) ((Mdl)->StartVa)
  11866. typedef enum _MM_SYSTEM_SIZE {
  11867. MmSmallSystem,
  11868. MmMediumSystem,
  11869. MmLargeSystem
  11870. } MM_SYSTEMSIZE;
  11871. NTKERNELAPI
  11872. MM_SYSTEMSIZE
  11873. MmQuerySystemSize (
  11874. VOID
  11875. );
  11876. NTKERNELAPI
  11877. BOOLEAN
  11878. MmIsThisAnNtAsSystem (
  11879. VOID
  11880. );
  11881. NTSTATUS
  11882. MmIsVerifierEnabled (
  11883. OUT PULONG VerifierFlags
  11884. );
  11885. NTSTATUS
  11886. MmAddVerifierThunks (
  11887. IN PVOID ThunkBuffer,
  11888. IN ULONG ThunkBufferSize
  11889. );
  11890. NTKERNELAPI
  11891. VOID
  11892. MmProbeAndLockProcessPages (
  11893. IN OUT PMDL MemoryDescriptorList,
  11894. IN PEPROCESS Process,
  11895. IN KPROCESSOR_MODE AccessMode,
  11896. IN LOCK_OPERATION Operation
  11897. );
  11898. //
  11899. // I/O support routines.
  11900. //
  11901. NTKERNELAPI
  11902. VOID
  11903. MmProbeAndLockPages (
  11904. IN OUT PMDL MemoryDescriptorList,
  11905. IN KPROCESSOR_MODE AccessMode,
  11906. IN LOCK_OPERATION Operation
  11907. );
  11908. NTKERNELAPI
  11909. VOID
  11910. MmUnlockPages (
  11911. IN PMDL MemoryDescriptorList
  11912. );
  11913. NTKERNELAPI
  11914. VOID
  11915. MmBuildMdlForNonPagedPool (
  11916. IN OUT PMDL MemoryDescriptorList
  11917. );
  11918. NTKERNELAPI
  11919. PVOID
  11920. MmMapLockedPages (
  11921. IN PMDL MemoryDescriptorList,
  11922. IN KPROCESSOR_MODE AccessMode
  11923. );
  11924. LOGICAL
  11925. MmIsIoSpaceActive (
  11926. IN PHYSICAL_ADDRESS StartAddress,
  11927. IN SIZE_T NumberOfBytes
  11928. );
  11929. NTKERNELAPI
  11930. PVOID
  11931. MmGetSystemRoutineAddress (
  11932. IN PUNICODE_STRING SystemRoutineName
  11933. );
  11934. NTKERNELAPI
  11935. NTSTATUS
  11936. MmAdvanceMdl (
  11937. IN PMDL Mdl,
  11938. IN ULONG NumberOfBytes
  11939. );
  11940. NTKERNELAPI
  11941. NTSTATUS
  11942. MmMapUserAddressesToPage (
  11943. IN PVOID BaseAddress,
  11944. IN SIZE_T NumberOfBytes,
  11945. IN PVOID PageAddress
  11946. );
  11947. NTKERNELAPI
  11948. NTSTATUS
  11949. MmProtectMdlSystemAddress (
  11950. IN PMDL MemoryDescriptorList,
  11951. IN ULONG NewProtect
  11952. );
  11953. //
  11954. // _MM_PAGE_PRIORITY_ provides a method for the system to handle requests
  11955. // intelligently in low resource conditions.
  11956. //
  11957. // LowPagePriority should be used when it is acceptable to the driver for the
  11958. // mapping request to fail if the system is low on resources. An example of
  11959. // this could be for a non-critical network connection where the driver can
  11960. // handle the failure case when system resources are close to being depleted.
  11961. //
  11962. // NormalPagePriority should be used when it is acceptable to the driver for the
  11963. // mapping request to fail if the system is very low on resources. An example
  11964. // of this could be for a non-critical local filesystem request.
  11965. //
  11966. // HighPagePriority should be used when it is unacceptable to the driver for the
  11967. // mapping request to fail unless the system is completely out of resources.
  11968. // An example of this would be the paging file path in a driver.
  11969. //
  11970. typedef enum _MM_PAGE_PRIORITY {
  11971. LowPagePriority,
  11972. NormalPagePriority = 16,
  11973. HighPagePriority = 32
  11974. } MM_PAGE_PRIORITY;
  11975. //
  11976. // Note: This function is not available in WDM 1.0
  11977. //
  11978. NTKERNELAPI
  11979. PVOID
  11980. MmMapLockedPagesSpecifyCache (
  11981. IN PMDL MemoryDescriptorList,
  11982. IN KPROCESSOR_MODE AccessMode,
  11983. IN MEMORY_CACHING_TYPE CacheType,
  11984. IN PVOID BaseAddress,
  11985. IN ULONG BugCheckOnFailure,
  11986. IN MM_PAGE_PRIORITY Priority
  11987. );
  11988. NTKERNELAPI
  11989. VOID
  11990. MmUnmapLockedPages (
  11991. IN PVOID BaseAddress,
  11992. IN PMDL MemoryDescriptorList
  11993. );
  11994. PVOID
  11995. MmAllocateMappingAddress (
  11996. IN SIZE_T NumberOfBytes,
  11997. IN ULONG PoolTag
  11998. );
  11999. VOID
  12000. MmFreeMappingAddress (
  12001. IN PVOID BaseAddress,
  12002. IN ULONG PoolTag
  12003. );
  12004. PVOID
  12005. MmMapLockedPagesWithReservedMapping (
  12006. IN PVOID MappingAddress,
  12007. IN ULONG PoolTag,
  12008. IN PMDL MemoryDescriptorList,
  12009. IN MEMORY_CACHING_TYPE CacheType
  12010. );
  12011. VOID
  12012. MmUnmapReservedMapping (
  12013. IN PVOID BaseAddress,
  12014. IN ULONG PoolTag,
  12015. IN PMDL MemoryDescriptorList
  12016. );
  12017. typedef struct _PHYSICAL_MEMORY_RANGE {
  12018. PHYSICAL_ADDRESS BaseAddress;
  12019. LARGE_INTEGER NumberOfBytes;
  12020. } PHYSICAL_MEMORY_RANGE, *PPHYSICAL_MEMORY_RANGE;
  12021. NTKERNELAPI
  12022. NTSTATUS
  12023. MmAddPhysicalMemory (
  12024. IN PPHYSICAL_ADDRESS StartAddress,
  12025. IN OUT PLARGE_INTEGER NumberOfBytes
  12026. );
  12027. NTKERNELAPI
  12028. NTSTATUS
  12029. MmRemovePhysicalMemory (
  12030. IN PPHYSICAL_ADDRESS StartAddress,
  12031. IN OUT PLARGE_INTEGER NumberOfBytes
  12032. );
  12033. NTKERNELAPI
  12034. PPHYSICAL_MEMORY_RANGE
  12035. MmGetPhysicalMemoryRanges (
  12036. VOID
  12037. );
  12038. NTKERNELAPI
  12039. PMDL
  12040. MmAllocatePagesForMdl (
  12041. IN PHYSICAL_ADDRESS LowAddress,
  12042. IN PHYSICAL_ADDRESS HighAddress,
  12043. IN PHYSICAL_ADDRESS SkipBytes,
  12044. IN SIZE_T TotalBytes
  12045. );
  12046. NTKERNELAPI
  12047. VOID
  12048. MmFreePagesFromMdl (
  12049. IN PMDL MemoryDescriptorList
  12050. );
  12051. NTKERNELAPI
  12052. PVOID
  12053. MmMapIoSpace (
  12054. IN PHYSICAL_ADDRESS PhysicalAddress,
  12055. IN SIZE_T NumberOfBytes,
  12056. IN MEMORY_CACHING_TYPE CacheType
  12057. );
  12058. NTKERNELAPI
  12059. VOID
  12060. MmUnmapIoSpace (
  12061. IN PVOID BaseAddress,
  12062. IN SIZE_T NumberOfBytes
  12063. );
  12064. NTKERNELAPI
  12065. PVOID
  12066. MmMapVideoDisplay (
  12067. IN PHYSICAL_ADDRESS PhysicalAddress,
  12068. IN SIZE_T NumberOfBytes,
  12069. IN MEMORY_CACHING_TYPE CacheType
  12070. );
  12071. NTKERNELAPI
  12072. VOID
  12073. MmUnmapVideoDisplay (
  12074. IN PVOID BaseAddress,
  12075. IN SIZE_T NumberOfBytes
  12076. );
  12077. NTKERNELAPI
  12078. PHYSICAL_ADDRESS
  12079. MmGetPhysicalAddress (
  12080. IN PVOID BaseAddress
  12081. );
  12082. NTKERNELAPI
  12083. PVOID
  12084. MmGetVirtualForPhysical (
  12085. IN PHYSICAL_ADDRESS PhysicalAddress
  12086. );
  12087. NTKERNELAPI
  12088. PVOID
  12089. MmAllocateContiguousMemory (
  12090. IN SIZE_T NumberOfBytes,
  12091. IN PHYSICAL_ADDRESS HighestAcceptableAddress
  12092. );
  12093. NTKERNELAPI
  12094. PVOID
  12095. MmAllocateContiguousMemorySpecifyCache (
  12096. IN SIZE_T NumberOfBytes,
  12097. IN PHYSICAL_ADDRESS LowestAcceptableAddress,
  12098. IN PHYSICAL_ADDRESS HighestAcceptableAddress,
  12099. IN PHYSICAL_ADDRESS BoundaryAddressMultiple OPTIONAL,
  12100. IN MEMORY_CACHING_TYPE CacheType
  12101. );
  12102. NTKERNELAPI
  12103. VOID
  12104. MmFreeContiguousMemory (
  12105. IN PVOID BaseAddress
  12106. );
  12107. NTKERNELAPI
  12108. VOID
  12109. MmFreeContiguousMemorySpecifyCache (
  12110. IN PVOID BaseAddress,
  12111. IN SIZE_T NumberOfBytes,
  12112. IN MEMORY_CACHING_TYPE CacheType
  12113. );
  12114. NTKERNELAPI
  12115. PVOID
  12116. MmAllocateNonCachedMemory (
  12117. IN SIZE_T NumberOfBytes
  12118. );
  12119. NTKERNELAPI
  12120. VOID
  12121. MmFreeNonCachedMemory (
  12122. IN PVOID BaseAddress,
  12123. IN SIZE_T NumberOfBytes
  12124. );
  12125. NTKERNELAPI
  12126. BOOLEAN
  12127. MmIsAddressValid (
  12128. IN PVOID VirtualAddress
  12129. );
  12130. DECLSPEC_DEPRECATED_DDK
  12131. NTKERNELAPI
  12132. BOOLEAN
  12133. MmIsNonPagedSystemAddressValid (
  12134. IN PVOID VirtualAddress
  12135. );
  12136. NTKERNELAPI
  12137. SIZE_T
  12138. MmSizeOfMdl (
  12139. IN PVOID Base,
  12140. IN SIZE_T Length
  12141. );
  12142. DECLSPEC_DEPRECATED_DDK // Use IoAllocateMdl
  12143. NTKERNELAPI
  12144. PMDL
  12145. MmCreateMdl (
  12146. IN PMDL MemoryDescriptorList OPTIONAL,
  12147. IN PVOID Base,
  12148. IN SIZE_T Length
  12149. );
  12150. NTKERNELAPI
  12151. PVOID
  12152. MmLockPagableDataSection (
  12153. IN PVOID AddressWithinSection
  12154. );
  12155. NTKERNELAPI
  12156. VOID
  12157. MmLockPagableSectionByHandle (
  12158. IN PVOID ImageSectionHandle
  12159. );
  12160. NTKERNELAPI
  12161. VOID
  12162. MmResetDriverPaging (
  12163. IN PVOID AddressWithinSection
  12164. );
  12165. NTKERNELAPI
  12166. PVOID
  12167. MmPageEntireDriver (
  12168. IN PVOID AddressWithinSection
  12169. );
  12170. NTKERNELAPI
  12171. VOID
  12172. MmUnlockPagableImageSection(
  12173. IN PVOID ImageSectionHandle
  12174. );
  12175. //
  12176. // Note that even though this function prototype
  12177. // says "HANDLE", MmSecureVirtualMemory does NOT return
  12178. // anything resembling a Win32-style handle. The return
  12179. // value from this function can ONLY be used with MmUnsecureVirtualMemory.
  12180. //
  12181. NTKERNELAPI
  12182. HANDLE
  12183. MmSecureVirtualMemory (
  12184. IN PVOID Address,
  12185. IN SIZE_T Size,
  12186. IN ULONG ProbeMode
  12187. );
  12188. NTKERNELAPI
  12189. VOID
  12190. MmUnsecureVirtualMemory (
  12191. IN HANDLE SecureHandle
  12192. );
  12193. NTKERNELAPI
  12194. NTSTATUS
  12195. MmMapViewInSystemSpace (
  12196. IN PVOID Section,
  12197. OUT PVOID *MappedBase,
  12198. IN PSIZE_T ViewSize
  12199. );
  12200. NTKERNELAPI
  12201. NTSTATUS
  12202. MmUnmapViewInSystemSpace (
  12203. IN PVOID MappedBase
  12204. );
  12205. NTKERNELAPI
  12206. NTSTATUS
  12207. MmMapViewInSessionSpace (
  12208. IN PVOID Section,
  12209. OUT PVOID *MappedBase,
  12210. IN OUT PSIZE_T ViewSize
  12211. );
  12212. NTKERNELAPI
  12213. NTSTATUS
  12214. MmUnmapViewInSessionSpace (
  12215. IN PVOID MappedBase
  12216. );
  12217. //++
  12218. //
  12219. // VOID
  12220. // MmInitializeMdl (
  12221. // IN PMDL MemoryDescriptorList,
  12222. // IN PVOID BaseVa,
  12223. // IN SIZE_T Length
  12224. // )
  12225. //
  12226. // Routine Description:
  12227. //
  12228. // This routine initializes the header of a Memory Descriptor List (MDL).
  12229. //
  12230. // Arguments:
  12231. //
  12232. // MemoryDescriptorList - Pointer to the MDL to initialize.
  12233. //
  12234. // BaseVa - Base virtual address mapped by the MDL.
  12235. //
  12236. // Length - Length, in bytes, of the buffer mapped by the MDL.
  12237. //
  12238. // Return Value:
  12239. //
  12240. // None.
  12241. //
  12242. //--
  12243. #define MmInitializeMdl(MemoryDescriptorList, BaseVa, Length) { \
  12244. (MemoryDescriptorList)->Next = (PMDL) NULL; \
  12245. (MemoryDescriptorList)->Size = (CSHORT)(sizeof(MDL) + \
  12246. (sizeof(PFN_NUMBER) * ADDRESS_AND_SIZE_TO_SPAN_PAGES((BaseVa), (Length)))); \
  12247. (MemoryDescriptorList)->MdlFlags = 0; \
  12248. (MemoryDescriptorList)->StartVa = (PVOID) PAGE_ALIGN((BaseVa)); \
  12249. (MemoryDescriptorList)->ByteOffset = BYTE_OFFSET((BaseVa)); \
  12250. (MemoryDescriptorList)->ByteCount = (ULONG)(Length); \
  12251. }
  12252. //++
  12253. //
  12254. // PVOID
  12255. // MmGetSystemAddressForMdlSafe (
  12256. // IN PMDL MDL,
  12257. // IN MM_PAGE_PRIORITY PRIORITY
  12258. // )
  12259. //
  12260. // Routine Description:
  12261. //
  12262. // This routine returns the mapped address of an MDL. If the
  12263. // Mdl is not already mapped or a system address, it is mapped.
  12264. //
  12265. // Arguments:
  12266. //
  12267. // MemoryDescriptorList - Pointer to the MDL to map.
  12268. //
  12269. // Priority - Supplies an indication as to how important it is that this
  12270. // request succeed under low available PTE conditions.
  12271. //
  12272. // Return Value:
  12273. //
  12274. // Returns the base address where the pages are mapped. The base address
  12275. // has the same offset as the virtual address in the MDL.
  12276. //
  12277. // Unlike MmGetSystemAddressForMdl, Safe guarantees that it will always
  12278. // return NULL on failure instead of bugchecking the system.
  12279. //
  12280. // This macro is not usable by WDM 1.0 drivers as 1.0 did not include
  12281. // MmMapLockedPagesSpecifyCache. The solution for WDM 1.0 drivers is to
  12282. // provide synchronization and set/reset the MDL_MAPPING_CAN_FAIL bit.
  12283. //
  12284. //--
  12285. #define MmGetSystemAddressForMdlSafe(MDL, PRIORITY) \
  12286. (((MDL)->MdlFlags & (MDL_MAPPED_TO_SYSTEM_VA | \
  12287. MDL_SOURCE_IS_NONPAGED_POOL)) ? \
  12288. ((MDL)->MappedSystemVa) : \
  12289. (MmMapLockedPagesSpecifyCache((MDL), \
  12290. KernelMode, \
  12291. MmCached, \
  12292. NULL, \
  12293. FALSE, \
  12294. (PRIORITY))))
  12295. //++
  12296. //
  12297. // PVOID
  12298. // MmGetSystemAddressForMdl (
  12299. // IN PMDL MDL
  12300. // )
  12301. //
  12302. // Routine Description:
  12303. //
  12304. // This routine returns the mapped address of an MDL, if the
  12305. // Mdl is not already mapped or a system address, it is mapped.
  12306. //
  12307. // Arguments:
  12308. //
  12309. // MemoryDescriptorList - Pointer to the MDL to map.
  12310. //
  12311. // Return Value:
  12312. //
  12313. // Returns the base address where the pages are mapped. The base address
  12314. // has the same offset as the virtual address in the MDL.
  12315. //
  12316. //--
  12317. //#define MmGetSystemAddressForMdl(MDL)
  12318. // (((MDL)->MdlFlags & (MDL_MAPPED_TO_SYSTEM_VA)) ?
  12319. // ((MDL)->MappedSystemVa) :
  12320. // ((((MDL)->MdlFlags & (MDL_SOURCE_IS_NONPAGED_POOL)) ?
  12321. // ((PVOID)((ULONG)(MDL)->StartVa | (MDL)->ByteOffset)) :
  12322. // (MmMapLockedPages((MDL),KernelMode)))))
  12323. #if PRAGMA_DEPRECATED_DDK
  12324. #pragma deprecated(MmGetSystemAddressForMdl) // Use MmGetSystemAddressForMdlSafe
  12325. #endif
  12326. #define MmGetSystemAddressForMdl(MDL) \
  12327. (((MDL)->MdlFlags & (MDL_MAPPED_TO_SYSTEM_VA | \
  12328. MDL_SOURCE_IS_NONPAGED_POOL)) ? \
  12329. ((MDL)->MappedSystemVa) : \
  12330. (MmMapLockedPages((MDL),KernelMode)))
  12331. //++
  12332. //
  12333. // VOID
  12334. // MmPrepareMdlForReuse (
  12335. // IN PMDL MDL
  12336. // )
  12337. //
  12338. // Routine Description:
  12339. //
  12340. // This routine will take all of the steps necessary to allow an MDL to be
  12341. // re-used.
  12342. //
  12343. // Arguments:
  12344. //
  12345. // MemoryDescriptorList - Pointer to the MDL that will be re-used.
  12346. //
  12347. // Return Value:
  12348. //
  12349. // None.
  12350. //
  12351. //--
  12352. #define MmPrepareMdlForReuse(MDL) \
  12353. if (((MDL)->MdlFlags & MDL_PARTIAL_HAS_BEEN_MAPPED) != 0) { \
  12354. ASSERT(((MDL)->MdlFlags & MDL_PARTIAL) != 0); \
  12355. MmUnmapLockedPages( (MDL)->MappedSystemVa, (MDL) ); \
  12356. } else if (((MDL)->MdlFlags & MDL_PARTIAL) == 0) { \
  12357. ASSERT(((MDL)->MdlFlags & MDL_MAPPED_TO_SYSTEM_VA) == 0); \
  12358. }
  12359. typedef NTSTATUS (*PMM_DLL_INITIALIZE)(
  12360. IN PUNICODE_STRING RegistryPath
  12361. );
  12362. typedef NTSTATUS (*PMM_DLL_UNLOAD)(
  12363. VOID
  12364. );
  12365. NTKERNELAPI
  12366. NTSTATUS
  12367. MmCreateMirror (
  12368. VOID
  12369. );
  12370. //
  12371. // Define an empty typedef for the _DRIVER_OBJECT structure so it may be
  12372. // referenced by function types before it is actually defined.
  12373. //
  12374. struct _DRIVER_OBJECT;
  12375. NTKERNELAPI
  12376. LOGICAL
  12377. MmIsDriverVerifying (
  12378. IN struct _DRIVER_OBJECT *DriverObject
  12379. );
  12380. //
  12381. // Security operation codes
  12382. //
  12383. typedef enum _SECURITY_OPERATION_CODE {
  12384. SetSecurityDescriptor,
  12385. QuerySecurityDescriptor,
  12386. DeleteSecurityDescriptor,
  12387. AssignSecurityDescriptor
  12388. } SECURITY_OPERATION_CODE, *PSECURITY_OPERATION_CODE;
  12389. //
  12390. // Data structure used to capture subject security context
  12391. // for access validations and auditing.
  12392. //
  12393. // THE FIELDS OF THIS DATA STRUCTURE SHOULD BE CONSIDERED OPAQUE
  12394. // BY ALL EXCEPT THE SECURITY ROUTINES.
  12395. //
  12396. typedef struct _SECURITY_SUBJECT_CONTEXT {
  12397. PACCESS_TOKEN ClientToken;
  12398. SECURITY_IMPERSONATION_LEVEL ImpersonationLevel;
  12399. PACCESS_TOKEN PrimaryToken;
  12400. PVOID ProcessAuditId;
  12401. } SECURITY_SUBJECT_CONTEXT, *PSECURITY_SUBJECT_CONTEXT;
  12402. ///////////////////////////////////////////////////////////////////////////////
  12403. // //
  12404. // ACCESS_STATE and related structures //
  12405. // //
  12406. ///////////////////////////////////////////////////////////////////////////////
  12407. //
  12408. // Initial Privilege Set - Room for three privileges, which should
  12409. // be enough for most applications. This structure exists so that
  12410. // it can be imbedded in an ACCESS_STATE structure. Use PRIVILEGE_SET
  12411. // for all other references to Privilege sets.
  12412. //
  12413. #define INITIAL_PRIVILEGE_COUNT 3
  12414. typedef struct _INITIAL_PRIVILEGE_SET {
  12415. ULONG PrivilegeCount;
  12416. ULONG Control;
  12417. LUID_AND_ATTRIBUTES Privilege[INITIAL_PRIVILEGE_COUNT];
  12418. } INITIAL_PRIVILEGE_SET, * PINITIAL_PRIVILEGE_SET;
  12419. //
  12420. // Combine the information that describes the state
  12421. // of an access-in-progress into a single structure
  12422. //
  12423. typedef struct _ACCESS_STATE {
  12424. LUID OperationID;
  12425. BOOLEAN SecurityEvaluated;
  12426. BOOLEAN GenerateAudit;
  12427. BOOLEAN GenerateOnClose;
  12428. BOOLEAN PrivilegesAllocated;
  12429. ULONG Flags;
  12430. ACCESS_MASK RemainingDesiredAccess;
  12431. ACCESS_MASK PreviouslyGrantedAccess;
  12432. ACCESS_MASK OriginalDesiredAccess;
  12433. SECURITY_SUBJECT_CONTEXT SubjectSecurityContext;
  12434. PSECURITY_DESCRIPTOR SecurityDescriptor;
  12435. PVOID AuxData;
  12436. union {
  12437. INITIAL_PRIVILEGE_SET InitialPrivilegeSet;
  12438. PRIVILEGE_SET PrivilegeSet;
  12439. } Privileges;
  12440. BOOLEAN AuditPrivileges;
  12441. UNICODE_STRING ObjectName;
  12442. UNICODE_STRING ObjectTypeName;
  12443. } ACCESS_STATE, *PACCESS_STATE;
  12444. NTKERNELAPI
  12445. NTSTATUS
  12446. SeAssignSecurity (
  12447. IN PSECURITY_DESCRIPTOR ParentDescriptor OPTIONAL,
  12448. IN PSECURITY_DESCRIPTOR ExplicitDescriptor,
  12449. OUT PSECURITY_DESCRIPTOR *NewDescriptor,
  12450. IN BOOLEAN IsDirectoryObject,
  12451. IN PSECURITY_SUBJECT_CONTEXT SubjectContext,
  12452. IN PGENERIC_MAPPING GenericMapping,
  12453. IN POOL_TYPE PoolType
  12454. );
  12455. NTKERNELAPI
  12456. NTSTATUS
  12457. SeAssignSecurityEx (
  12458. IN PSECURITY_DESCRIPTOR ParentDescriptor OPTIONAL,
  12459. IN PSECURITY_DESCRIPTOR ExplicitDescriptor OPTIONAL,
  12460. OUT PSECURITY_DESCRIPTOR *NewDescriptor,
  12461. IN GUID *ObjectType OPTIONAL,
  12462. IN BOOLEAN IsDirectoryObject,
  12463. IN ULONG AutoInheritFlags,
  12464. IN PSECURITY_SUBJECT_CONTEXT SubjectContext,
  12465. IN PGENERIC_MAPPING GenericMapping,
  12466. IN POOL_TYPE PoolType
  12467. );
  12468. NTKERNELAPI
  12469. NTSTATUS
  12470. SeDeassignSecurity (
  12471. IN OUT PSECURITY_DESCRIPTOR *SecurityDescriptor
  12472. );
  12473. NTKERNELAPI
  12474. BOOLEAN
  12475. SeAccessCheck (
  12476. IN PSECURITY_DESCRIPTOR SecurityDescriptor,
  12477. IN PSECURITY_SUBJECT_CONTEXT SubjectSecurityContext,
  12478. IN BOOLEAN SubjectContextLocked,
  12479. IN ACCESS_MASK DesiredAccess,
  12480. IN ACCESS_MASK PreviouslyGrantedAccess,
  12481. OUT PPRIVILEGE_SET *Privileges OPTIONAL,
  12482. IN PGENERIC_MAPPING GenericMapping,
  12483. IN KPROCESSOR_MODE AccessMode,
  12484. OUT PACCESS_MASK GrantedAccess,
  12485. OUT PNTSTATUS AccessStatus
  12486. );
  12487. #ifdef SE_NTFS_WORLD_CACHE
  12488. VOID
  12489. SeGetWorldRights (
  12490. IN PSECURITY_DESCRIPTOR SecurityDescriptor,
  12491. IN PGENERIC_MAPPING GenericMapping,
  12492. OUT PACCESS_MASK GrantedAccess
  12493. );
  12494. #endif
  12495. NTKERNELAPI
  12496. BOOLEAN
  12497. SeValidSecurityDescriptor(
  12498. IN ULONG Length,
  12499. IN PSECURITY_DESCRIPTOR SecurityDescriptor
  12500. );
  12501. NTKERNELAPI
  12502. BOOLEAN
  12503. SeSinglePrivilegeCheck(
  12504. LUID PrivilegeValue,
  12505. KPROCESSOR_MODE PreviousMode
  12506. );
  12507. //
  12508. // System Thread and Process Creation and Termination
  12509. //
  12510. NTKERNELAPI
  12511. NTSTATUS
  12512. PsCreateSystemThread(
  12513. OUT PHANDLE ThreadHandle,
  12514. IN ULONG DesiredAccess,
  12515. IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL,
  12516. IN HANDLE ProcessHandle OPTIONAL,
  12517. OUT PCLIENT_ID ClientId OPTIONAL,
  12518. IN PKSTART_ROUTINE StartRoutine,
  12519. IN PVOID StartContext
  12520. );
  12521. NTKERNELAPI
  12522. NTSTATUS
  12523. PsTerminateSystemThread(
  12524. IN NTSTATUS ExitStatus
  12525. );
  12526. typedef
  12527. VOID
  12528. (*PCREATE_PROCESS_NOTIFY_ROUTINE)(
  12529. IN HANDLE ParentId,
  12530. IN HANDLE ProcessId,
  12531. IN BOOLEAN Create
  12532. );
  12533. NTSTATUS
  12534. PsSetCreateProcessNotifyRoutine(
  12535. IN PCREATE_PROCESS_NOTIFY_ROUTINE NotifyRoutine,
  12536. IN BOOLEAN Remove
  12537. );
  12538. typedef
  12539. VOID
  12540. (*PCREATE_THREAD_NOTIFY_ROUTINE)(
  12541. IN HANDLE ProcessId,
  12542. IN HANDLE ThreadId,
  12543. IN BOOLEAN Create
  12544. );
  12545. NTSTATUS
  12546. PsSetCreateThreadNotifyRoutine(
  12547. IN PCREATE_THREAD_NOTIFY_ROUTINE NotifyRoutine
  12548. );
  12549. NTSTATUS
  12550. PsRemoveCreateThreadNotifyRoutine (
  12551. IN PCREATE_THREAD_NOTIFY_ROUTINE NotifyRoutine
  12552. );
  12553. //
  12554. // Structures for Load Image Notify
  12555. //
  12556. typedef struct _IMAGE_INFO {
  12557. union {
  12558. ULONG Properties;
  12559. struct {
  12560. ULONG ImageAddressingMode : 8; // code addressing mode
  12561. ULONG SystemModeImage : 1; // system mode image
  12562. ULONG ImageMappedToAllPids : 1; // image mapped into all processes
  12563. ULONG Reserved : 22;
  12564. };
  12565. };
  12566. PVOID ImageBase;
  12567. ULONG ImageSelector;
  12568. SIZE_T ImageSize;
  12569. ULONG ImageSectionNumber;
  12570. } IMAGE_INFO, *PIMAGE_INFO;
  12571. #define IMAGE_ADDRESSING_MODE_32BIT 3
  12572. typedef
  12573. VOID
  12574. (*PLOAD_IMAGE_NOTIFY_ROUTINE)(
  12575. IN PUNICODE_STRING FullImageName,
  12576. IN HANDLE ProcessId, // pid into which image is being mapped
  12577. IN PIMAGE_INFO ImageInfo
  12578. );
  12579. NTSTATUS
  12580. PsSetLoadImageNotifyRoutine(
  12581. IN PLOAD_IMAGE_NOTIFY_ROUTINE NotifyRoutine
  12582. );
  12583. NTSTATUS
  12584. PsRemoveLoadImageNotifyRoutine(
  12585. IN PLOAD_IMAGE_NOTIFY_ROUTINE NotifyRoutine
  12586. );
  12587. HANDLE
  12588. PsGetCurrentProcessId( VOID );
  12589. HANDLE
  12590. PsGetCurrentThreadId( VOID );
  12591. BOOLEAN
  12592. PsGetVersion(
  12593. PULONG MajorVersion OPTIONAL,
  12594. PULONG MinorVersion OPTIONAL,
  12595. PULONG BuildNumber OPTIONAL,
  12596. PUNICODE_STRING CSDVersion OPTIONAL
  12597. );
  12598. //
  12599. // Define I/O system data structure type codes. Each major data structure in
  12600. // the I/O system has a type code The type field in each structure is at the
  12601. // same offset. The following values can be used to determine which type of
  12602. // data structure a pointer refers to.
  12603. //
  12604. #define IO_TYPE_ADAPTER 0x00000001
  12605. #define IO_TYPE_CONTROLLER 0x00000002
  12606. #define IO_TYPE_DEVICE 0x00000003
  12607. #define IO_TYPE_DRIVER 0x00000004
  12608. #define IO_TYPE_FILE 0x00000005
  12609. #define IO_TYPE_IRP 0x00000006
  12610. #define IO_TYPE_MASTER_ADAPTER 0x00000007
  12611. #define IO_TYPE_OPEN_PACKET 0x00000008
  12612. #define IO_TYPE_TIMER 0x00000009
  12613. #define IO_TYPE_VPB 0x0000000a
  12614. #define IO_TYPE_ERROR_LOG 0x0000000b
  12615. #define IO_TYPE_ERROR_MESSAGE 0x0000000c
  12616. #define IO_TYPE_DEVICE_OBJECT_EXTENSION 0x0000000d
  12617. //
  12618. // Define the major function codes for IRPs.
  12619. //
  12620. #define IRP_MJ_CREATE 0x00
  12621. #define IRP_MJ_CREATE_NAMED_PIPE 0x01
  12622. #define IRP_MJ_CLOSE 0x02
  12623. #define IRP_MJ_READ 0x03
  12624. #define IRP_MJ_WRITE 0x04
  12625. #define IRP_MJ_QUERY_INFORMATION 0x05
  12626. #define IRP_MJ_SET_INFORMATION 0x06
  12627. #define IRP_MJ_QUERY_EA 0x07
  12628. #define IRP_MJ_SET_EA 0x08
  12629. #define IRP_MJ_FLUSH_BUFFERS 0x09
  12630. #define IRP_MJ_QUERY_VOLUME_INFORMATION 0x0a
  12631. #define IRP_MJ_SET_VOLUME_INFORMATION 0x0b
  12632. #define IRP_MJ_DIRECTORY_CONTROL 0x0c
  12633. #define IRP_MJ_FILE_SYSTEM_CONTROL 0x0d
  12634. #define IRP_MJ_DEVICE_CONTROL 0x0e
  12635. #define IRP_MJ_INTERNAL_DEVICE_CONTROL 0x0f
  12636. #define IRP_MJ_SHUTDOWN 0x10
  12637. #define IRP_MJ_LOCK_CONTROL 0x11
  12638. #define IRP_MJ_CLEANUP 0x12
  12639. #define IRP_MJ_CREATE_MAILSLOT 0x13
  12640. #define IRP_MJ_QUERY_SECURITY 0x14
  12641. #define IRP_MJ_SET_SECURITY 0x15
  12642. #define IRP_MJ_POWER 0x16
  12643. #define IRP_MJ_SYSTEM_CONTROL 0x17
  12644. #define IRP_MJ_DEVICE_CHANGE 0x18
  12645. #define IRP_MJ_QUERY_QUOTA 0x19
  12646. #define IRP_MJ_SET_QUOTA 0x1a
  12647. #define IRP_MJ_PNP 0x1b
  12648. #define IRP_MJ_PNP_POWER IRP_MJ_PNP // Obsolete....
  12649. #define IRP_MJ_MAXIMUM_FUNCTION 0x1b
  12650. //
  12651. // Make the Scsi major code the same as internal device control.
  12652. //
  12653. #define IRP_MJ_SCSI IRP_MJ_INTERNAL_DEVICE_CONTROL
  12654. //
  12655. // Define the minor function codes for IRPs. The lower 128 codes, from 0x00 to
  12656. // 0x7f are reserved to Microsoft. The upper 128 codes, from 0x80 to 0xff, are
  12657. // reserved to customers of Microsoft.
  12658. //
  12659. //
  12660. // Directory control minor function codes
  12661. //
  12662. #define IRP_MN_QUERY_DIRECTORY 0x01
  12663. #define IRP_MN_NOTIFY_CHANGE_DIRECTORY 0x02
  12664. //
  12665. // File system control minor function codes. Note that "user request" is
  12666. // assumed to be zero by both the I/O system and file systems. Do not change
  12667. // this value.
  12668. //
  12669. #define IRP_MN_USER_FS_REQUEST 0x00
  12670. #define IRP_MN_MOUNT_VOLUME 0x01
  12671. #define IRP_MN_VERIFY_VOLUME 0x02
  12672. #define IRP_MN_LOAD_FILE_SYSTEM 0x03
  12673. #define IRP_MN_TRACK_LINK 0x04 // To be obsoleted soon
  12674. #define IRP_MN_KERNEL_CALL 0x04
  12675. //
  12676. // Lock control minor function codes
  12677. //
  12678. #define IRP_MN_LOCK 0x01
  12679. #define IRP_MN_UNLOCK_SINGLE 0x02
  12680. #define IRP_MN_UNLOCK_ALL 0x03
  12681. #define IRP_MN_UNLOCK_ALL_BY_KEY 0x04
  12682. //
  12683. // Read and Write minor function codes for file systems supporting Lan Manager
  12684. // software. All of these subfunction codes are invalid if the file has been
  12685. // opened with FO_NO_INTERMEDIATE_BUFFERING. They are also invalid in combi-
  12686. // nation with synchronous calls (Irp Flag or file open option).
  12687. //
  12688. // Note that "normal" is assumed to be zero by both the I/O system and file
  12689. // systems. Do not change this value.
  12690. //
  12691. #define IRP_MN_NORMAL 0x00
  12692. #define IRP_MN_DPC 0x01
  12693. #define IRP_MN_MDL 0x02
  12694. #define IRP_MN_COMPLETE 0x04
  12695. #define IRP_MN_COMPRESSED 0x08
  12696. #define IRP_MN_MDL_DPC (IRP_MN_MDL | IRP_MN_DPC)
  12697. #define IRP_MN_COMPLETE_MDL (IRP_MN_COMPLETE | IRP_MN_MDL)
  12698. #define IRP_MN_COMPLETE_MDL_DPC (IRP_MN_COMPLETE_MDL | IRP_MN_DPC)
  12699. //
  12700. // Device Control Request minor function codes for SCSI support. Note that
  12701. // user requests are assumed to be zero.
  12702. //
  12703. #define IRP_MN_SCSI_CLASS 0x01
  12704. //
  12705. // PNP minor function codes.
  12706. //
  12707. #define IRP_MN_START_DEVICE 0x00
  12708. #define IRP_MN_QUERY_REMOVE_DEVICE 0x01
  12709. #define IRP_MN_REMOVE_DEVICE 0x02
  12710. #define IRP_MN_CANCEL_REMOVE_DEVICE 0x03
  12711. #define IRP_MN_STOP_DEVICE 0x04
  12712. #define IRP_MN_QUERY_STOP_DEVICE 0x05
  12713. #define IRP_MN_CANCEL_STOP_DEVICE 0x06
  12714. #define IRP_MN_QUERY_DEVICE_RELATIONS 0x07
  12715. #define IRP_MN_QUERY_INTERFACE 0x08
  12716. #define IRP_MN_QUERY_CAPABILITIES 0x09
  12717. #define IRP_MN_QUERY_RESOURCES 0x0A
  12718. #define IRP_MN_QUERY_RESOURCE_REQUIREMENTS 0x0B
  12719. #define IRP_MN_QUERY_DEVICE_TEXT 0x0C
  12720. #define IRP_MN_FILTER_RESOURCE_REQUIREMENTS 0x0D
  12721. #define IRP_MN_READ_CONFIG 0x0F
  12722. #define IRP_MN_WRITE_CONFIG 0x10
  12723. #define IRP_MN_EJECT 0x11
  12724. #define IRP_MN_SET_LOCK 0x12
  12725. #define IRP_MN_QUERY_ID 0x13
  12726. #define IRP_MN_QUERY_PNP_DEVICE_STATE 0x14
  12727. #define IRP_MN_QUERY_BUS_INFORMATION 0x15
  12728. #define IRP_MN_DEVICE_USAGE_NOTIFICATION 0x16
  12729. #define IRP_MN_SURPRISE_REMOVAL 0x17
  12730. #define IRP_MN_QUERY_LEGACY_BUS_INFORMATION 0x18
  12731. //
  12732. // POWER minor function codes
  12733. //
  12734. #define IRP_MN_WAIT_WAKE 0x00
  12735. #define IRP_MN_POWER_SEQUENCE 0x01
  12736. #define IRP_MN_SET_POWER 0x02
  12737. #define IRP_MN_QUERY_POWER 0x03
  12738. //
  12739. // WMI minor function codes under IRP_MJ_SYSTEM_CONTROL
  12740. //
  12741. #define IRP_MN_QUERY_ALL_DATA 0x00
  12742. #define IRP_MN_QUERY_SINGLE_INSTANCE 0x01
  12743. #define IRP_MN_CHANGE_SINGLE_INSTANCE 0x02
  12744. #define IRP_MN_CHANGE_SINGLE_ITEM 0x03
  12745. #define IRP_MN_ENABLE_EVENTS 0x04
  12746. #define IRP_MN_DISABLE_EVENTS 0x05
  12747. #define IRP_MN_ENABLE_COLLECTION 0x06
  12748. #define IRP_MN_DISABLE_COLLECTION 0x07
  12749. #define IRP_MN_REGINFO 0x08
  12750. #define IRP_MN_EXECUTE_METHOD 0x09
  12751. // Minor code 0x0a is reserved
  12752. #define IRP_MN_REGINFO_EX 0x0b
  12753. //
  12754. // Define option flags for IoCreateFile. Note that these values must be
  12755. // exactly the same as the SL_... flags for a create function. Note also
  12756. // that there are flags that may be passed to IoCreateFile that are not
  12757. // placed in the stack location for the create IRP. These flags start in
  12758. // the next byte.
  12759. //
  12760. #define IO_FORCE_ACCESS_CHECK 0x0001
  12761. #define IO_NO_PARAMETER_CHECKING 0x0100
  12762. //
  12763. // Define Information fields for whether or not a REPARSE or a REMOUNT has
  12764. // occurred in the file system.
  12765. //
  12766. #define IO_REPARSE 0x0
  12767. #define IO_REMOUNT 0x1
  12768. //
  12769. // Define callout routine type for use in IoQueryDeviceDescription().
  12770. //
  12771. typedef NTSTATUS (*PIO_QUERY_DEVICE_ROUTINE)(
  12772. IN PVOID Context,
  12773. IN PUNICODE_STRING PathName,
  12774. IN INTERFACE_TYPE BusType,
  12775. IN ULONG BusNumber,
  12776. IN PKEY_VALUE_FULL_INFORMATION *BusInformation,
  12777. IN CONFIGURATION_TYPE ControllerType,
  12778. IN ULONG ControllerNumber,
  12779. IN PKEY_VALUE_FULL_INFORMATION *ControllerInformation,
  12780. IN CONFIGURATION_TYPE PeripheralType,
  12781. IN ULONG PeripheralNumber,
  12782. IN PKEY_VALUE_FULL_INFORMATION *PeripheralInformation
  12783. );
  12784. // Defines the order of the information in the array of
  12785. // PKEY_VALUE_FULL_INFORMATION.
  12786. //
  12787. typedef enum _IO_QUERY_DEVICE_DATA_FORMAT {
  12788. IoQueryDeviceIdentifier = 0,
  12789. IoQueryDeviceConfigurationData,
  12790. IoQueryDeviceComponentInformation,
  12791. IoQueryDeviceMaxData
  12792. } IO_QUERY_DEVICE_DATA_FORMAT, *PIO_QUERY_DEVICE_DATA_FORMAT;
  12793. //
  12794. // Define the objects that can be created by IoCreateFile.
  12795. //
  12796. typedef enum _CREATE_FILE_TYPE {
  12797. CreateFileTypeNone,
  12798. CreateFileTypeNamedPipe,
  12799. CreateFileTypeMailslot
  12800. } CREATE_FILE_TYPE;
  12801. //
  12802. // Define the structures used by the I/O system
  12803. //
  12804. //
  12805. // Define empty typedefs for the _IRP, _DEVICE_OBJECT, and _DRIVER_OBJECT
  12806. // structures so they may be referenced by function types before they are
  12807. // actually defined.
  12808. //
  12809. struct _DEVICE_DESCRIPTION;
  12810. struct _DEVICE_OBJECT;
  12811. struct _DMA_ADAPTER;
  12812. struct _DRIVER_OBJECT;
  12813. struct _DRIVE_LAYOUT_INFORMATION;
  12814. struct _DISK_PARTITION;
  12815. struct _FILE_OBJECT;
  12816. struct DECLSPEC_ALIGN(MEMORY_ALLOCATION_ALIGNMENT) _IRP;
  12817. struct _SCSI_REQUEST_BLOCK;
  12818. struct _SCATTER_GATHER_LIST;
  12819. //
  12820. // Define the I/O version of a DPC routine.
  12821. //
  12822. typedef
  12823. VOID
  12824. (*PIO_DPC_ROUTINE) (
  12825. IN PKDPC Dpc,
  12826. IN struct _DEVICE_OBJECT *DeviceObject,
  12827. IN struct _IRP *Irp,
  12828. IN PVOID Context
  12829. );
  12830. //
  12831. // Define driver timer routine type.
  12832. //
  12833. typedef
  12834. VOID
  12835. (*PIO_TIMER_ROUTINE) (
  12836. IN struct _DEVICE_OBJECT *DeviceObject,
  12837. IN PVOID Context
  12838. );
  12839. //
  12840. // Define driver initialization routine type.
  12841. //
  12842. typedef
  12843. NTSTATUS
  12844. (*PDRIVER_INITIALIZE) (
  12845. IN struct _DRIVER_OBJECT *DriverObject,
  12846. IN PUNICODE_STRING RegistryPath
  12847. );
  12848. //
  12849. // Define driver reinitialization routine type.
  12850. //
  12851. typedef
  12852. VOID
  12853. (*PDRIVER_REINITIALIZE) (
  12854. IN struct _DRIVER_OBJECT *DriverObject,
  12855. IN PVOID Context,
  12856. IN ULONG Count
  12857. );
  12858. //
  12859. // Define driver cancel routine type.
  12860. //
  12861. typedef
  12862. VOID
  12863. (*PDRIVER_CANCEL) (
  12864. IN struct _DEVICE_OBJECT *DeviceObject,
  12865. IN struct _IRP *Irp
  12866. );
  12867. //
  12868. // Define driver dispatch routine type.
  12869. //
  12870. typedef
  12871. NTSTATUS
  12872. (*PDRIVER_DISPATCH) (
  12873. IN struct _DEVICE_OBJECT *DeviceObject,
  12874. IN struct _IRP *Irp
  12875. );
  12876. //
  12877. // Define driver start I/O routine type.
  12878. //
  12879. typedef
  12880. VOID
  12881. (*PDRIVER_STARTIO) (
  12882. IN struct _DEVICE_OBJECT *DeviceObject,
  12883. IN struct _IRP *Irp
  12884. );
  12885. //
  12886. // Define driver unload routine type.
  12887. //
  12888. typedef
  12889. VOID
  12890. (*PDRIVER_UNLOAD) (
  12891. IN struct _DRIVER_OBJECT *DriverObject
  12892. );
  12893. //
  12894. // Define driver AddDevice routine type.
  12895. //
  12896. typedef
  12897. NTSTATUS
  12898. (*PDRIVER_ADD_DEVICE) (
  12899. IN struct _DRIVER_OBJECT *DriverObject,
  12900. IN struct _DEVICE_OBJECT *PhysicalDeviceObject
  12901. );
  12902. //
  12903. // Define fast I/O procedure prototypes.
  12904. //
  12905. // Fast I/O read and write procedures.
  12906. //
  12907. typedef
  12908. BOOLEAN
  12909. (*PFAST_IO_CHECK_IF_POSSIBLE) (
  12910. IN struct _FILE_OBJECT *FileObject,
  12911. IN PLARGE_INTEGER FileOffset,
  12912. IN ULONG Length,
  12913. IN BOOLEAN Wait,
  12914. IN ULONG LockKey,
  12915. IN BOOLEAN CheckForReadOperation,
  12916. OUT PIO_STATUS_BLOCK IoStatus,
  12917. IN struct _DEVICE_OBJECT *DeviceObject
  12918. );
  12919. typedef
  12920. BOOLEAN
  12921. (*PFAST_IO_READ) (
  12922. IN struct _FILE_OBJECT *FileObject,
  12923. IN PLARGE_INTEGER FileOffset,
  12924. IN ULONG Length,
  12925. IN BOOLEAN Wait,
  12926. IN ULONG LockKey,
  12927. OUT PVOID Buffer,
  12928. OUT PIO_STATUS_BLOCK IoStatus,
  12929. IN struct _DEVICE_OBJECT *DeviceObject
  12930. );
  12931. typedef
  12932. BOOLEAN
  12933. (*PFAST_IO_WRITE) (
  12934. IN struct _FILE_OBJECT *FileObject,
  12935. IN PLARGE_INTEGER FileOffset,
  12936. IN ULONG Length,
  12937. IN BOOLEAN Wait,
  12938. IN ULONG LockKey,
  12939. IN PVOID Buffer,
  12940. OUT PIO_STATUS_BLOCK IoStatus,
  12941. IN struct _DEVICE_OBJECT *DeviceObject
  12942. );
  12943. //
  12944. // Fast I/O query basic and standard information procedures.
  12945. //
  12946. typedef
  12947. BOOLEAN
  12948. (*PFAST_IO_QUERY_BASIC_INFO) (
  12949. IN struct _FILE_OBJECT *FileObject,
  12950. IN BOOLEAN Wait,
  12951. OUT PFILE_BASIC_INFORMATION Buffer,
  12952. OUT PIO_STATUS_BLOCK IoStatus,
  12953. IN struct _DEVICE_OBJECT *DeviceObject
  12954. );
  12955. typedef
  12956. BOOLEAN
  12957. (*PFAST_IO_QUERY_STANDARD_INFO) (
  12958. IN struct _FILE_OBJECT *FileObject,
  12959. IN BOOLEAN Wait,
  12960. OUT PFILE_STANDARD_INFORMATION Buffer,
  12961. OUT PIO_STATUS_BLOCK IoStatus,
  12962. IN struct _DEVICE_OBJECT *DeviceObject
  12963. );
  12964. //
  12965. // Fast I/O lock and unlock procedures.
  12966. //
  12967. typedef
  12968. BOOLEAN
  12969. (*PFAST_IO_LOCK) (
  12970. IN struct _FILE_OBJECT *FileObject,
  12971. IN PLARGE_INTEGER FileOffset,
  12972. IN PLARGE_INTEGER Length,
  12973. PEPROCESS ProcessId,
  12974. ULONG Key,
  12975. BOOLEAN FailImmediately,
  12976. BOOLEAN ExclusiveLock,
  12977. OUT PIO_STATUS_BLOCK IoStatus,
  12978. IN struct _DEVICE_OBJECT *DeviceObject
  12979. );
  12980. typedef
  12981. BOOLEAN
  12982. (*PFAST_IO_UNLOCK_SINGLE) (
  12983. IN struct _FILE_OBJECT *FileObject,
  12984. IN PLARGE_INTEGER FileOffset,
  12985. IN PLARGE_INTEGER Length,
  12986. PEPROCESS ProcessId,
  12987. ULONG Key,
  12988. OUT PIO_STATUS_BLOCK IoStatus,
  12989. IN struct _DEVICE_OBJECT *DeviceObject
  12990. );
  12991. typedef
  12992. BOOLEAN
  12993. (*PFAST_IO_UNLOCK_ALL) (
  12994. IN struct _FILE_OBJECT *FileObject,
  12995. PEPROCESS ProcessId,
  12996. OUT PIO_STATUS_BLOCK IoStatus,
  12997. IN struct _DEVICE_OBJECT *DeviceObject
  12998. );
  12999. typedef
  13000. BOOLEAN
  13001. (*PFAST_IO_UNLOCK_ALL_BY_KEY) (
  13002. IN struct _FILE_OBJECT *FileObject,
  13003. PVOID ProcessId,
  13004. ULONG Key,
  13005. OUT PIO_STATUS_BLOCK IoStatus,
  13006. IN struct _DEVICE_OBJECT *DeviceObject
  13007. );
  13008. //
  13009. // Fast I/O device control procedure.
  13010. //
  13011. typedef
  13012. BOOLEAN
  13013. (*PFAST_IO_DEVICE_CONTROL) (
  13014. IN struct _FILE_OBJECT *FileObject,
  13015. IN BOOLEAN Wait,
  13016. IN PVOID InputBuffer OPTIONAL,
  13017. IN ULONG InputBufferLength,
  13018. OUT PVOID OutputBuffer OPTIONAL,
  13019. IN ULONG OutputBufferLength,
  13020. IN ULONG IoControlCode,
  13021. OUT PIO_STATUS_BLOCK IoStatus,
  13022. IN struct _DEVICE_OBJECT *DeviceObject
  13023. );
  13024. //
  13025. // Define callbacks for NtCreateSection to synchronize correctly with
  13026. // the file system. It pre-acquires the resources that will be needed
  13027. // when calling to query and set file/allocation size in the file system.
  13028. //
  13029. typedef
  13030. VOID
  13031. (*PFAST_IO_ACQUIRE_FILE) (
  13032. IN struct _FILE_OBJECT *FileObject
  13033. );
  13034. typedef
  13035. VOID
  13036. (*PFAST_IO_RELEASE_FILE) (
  13037. IN struct _FILE_OBJECT *FileObject
  13038. );
  13039. //
  13040. // Define callback for drivers that have device objects attached to lower-
  13041. // level drivers' device objects. This callback is made when the lower-level
  13042. // driver is deleting its device object.
  13043. //
  13044. typedef
  13045. VOID
  13046. (*PFAST_IO_DETACH_DEVICE) (
  13047. IN struct _DEVICE_OBJECT *SourceDevice,
  13048. IN struct _DEVICE_OBJECT *TargetDevice
  13049. );
  13050. //
  13051. // This structure is used by the server to quickly get the information needed
  13052. // to service a server open call. It is takes what would be two fast io calls
  13053. // one for basic information and the other for standard information and makes
  13054. // it into one call.
  13055. //
  13056. typedef
  13057. BOOLEAN
  13058. (*PFAST_IO_QUERY_NETWORK_OPEN_INFO) (
  13059. IN struct _FILE_OBJECT *FileObject,
  13060. IN BOOLEAN Wait,
  13061. OUT struct _FILE_NETWORK_OPEN_INFORMATION *Buffer,
  13062. OUT struct _IO_STATUS_BLOCK *IoStatus,
  13063. IN struct _DEVICE_OBJECT *DeviceObject
  13064. );
  13065. //
  13066. // Define Mdl-based routines for the server to call
  13067. //
  13068. typedef
  13069. BOOLEAN
  13070. (*PFAST_IO_MDL_READ) (
  13071. IN struct _FILE_OBJECT *FileObject,
  13072. IN PLARGE_INTEGER FileOffset,
  13073. IN ULONG Length,
  13074. IN ULONG LockKey,
  13075. OUT PMDL *MdlChain,
  13076. OUT PIO_STATUS_BLOCK IoStatus,
  13077. IN struct _DEVICE_OBJECT *DeviceObject
  13078. );
  13079. typedef
  13080. BOOLEAN
  13081. (*PFAST_IO_MDL_READ_COMPLETE) (
  13082. IN struct _FILE_OBJECT *FileObject,
  13083. IN PMDL MdlChain,
  13084. IN struct _DEVICE_OBJECT *DeviceObject
  13085. );
  13086. typedef
  13087. BOOLEAN
  13088. (*PFAST_IO_PREPARE_MDL_WRITE) (
  13089. IN struct _FILE_OBJECT *FileObject,
  13090. IN PLARGE_INTEGER FileOffset,
  13091. IN ULONG Length,
  13092. IN ULONG LockKey,
  13093. OUT PMDL *MdlChain,
  13094. OUT PIO_STATUS_BLOCK IoStatus,
  13095. IN struct _DEVICE_OBJECT *DeviceObject
  13096. );
  13097. typedef
  13098. BOOLEAN
  13099. (*PFAST_IO_MDL_WRITE_COMPLETE) (
  13100. IN struct _FILE_OBJECT *FileObject,
  13101. IN PLARGE_INTEGER FileOffset,
  13102. IN PMDL MdlChain,
  13103. IN struct _DEVICE_OBJECT *DeviceObject
  13104. );
  13105. //
  13106. // If this routine is present, it will be called by FsRtl
  13107. // to acquire the file for the mapped page writer.
  13108. //
  13109. typedef
  13110. NTSTATUS
  13111. (*PFAST_IO_ACQUIRE_FOR_MOD_WRITE) (
  13112. IN struct _FILE_OBJECT *FileObject,
  13113. IN PLARGE_INTEGER EndingOffset,
  13114. OUT struct _ERESOURCE **ResourceToRelease,
  13115. IN struct _DEVICE_OBJECT *DeviceObject
  13116. );
  13117. typedef
  13118. NTSTATUS
  13119. (*PFAST_IO_RELEASE_FOR_MOD_WRITE) (
  13120. IN struct _FILE_OBJECT *FileObject,
  13121. IN struct _ERESOURCE *ResourceToRelease,
  13122. IN struct _DEVICE_OBJECT *DeviceObject
  13123. );
  13124. //
  13125. // If this routine is present, it will be called by FsRtl
  13126. // to acquire the file for the mapped page writer.
  13127. //
  13128. typedef
  13129. NTSTATUS
  13130. (*PFAST_IO_ACQUIRE_FOR_CCFLUSH) (
  13131. IN struct _FILE_OBJECT *FileObject,
  13132. IN struct _DEVICE_OBJECT *DeviceObject
  13133. );
  13134. typedef
  13135. NTSTATUS
  13136. (*PFAST_IO_RELEASE_FOR_CCFLUSH) (
  13137. IN struct _FILE_OBJECT *FileObject,
  13138. IN struct _DEVICE_OBJECT *DeviceObject
  13139. );
  13140. typedef
  13141. BOOLEAN
  13142. (*PFAST_IO_READ_COMPRESSED) (
  13143. IN struct _FILE_OBJECT *FileObject,
  13144. IN PLARGE_INTEGER FileOffset,
  13145. IN ULONG Length,
  13146. IN ULONG LockKey,
  13147. OUT PVOID Buffer,
  13148. OUT PMDL *MdlChain,
  13149. OUT PIO_STATUS_BLOCK IoStatus,
  13150. OUT struct _COMPRESSED_DATA_INFO *CompressedDataInfo,
  13151. IN ULONG CompressedDataInfoLength,
  13152. IN struct _DEVICE_OBJECT *DeviceObject
  13153. );
  13154. typedef
  13155. BOOLEAN
  13156. (*PFAST_IO_WRITE_COMPRESSED) (
  13157. IN struct _FILE_OBJECT *FileObject,
  13158. IN PLARGE_INTEGER FileOffset,
  13159. IN ULONG Length,
  13160. IN ULONG LockKey,
  13161. IN PVOID Buffer,
  13162. OUT PMDL *MdlChain,
  13163. OUT PIO_STATUS_BLOCK IoStatus,
  13164. IN struct _COMPRESSED_DATA_INFO *CompressedDataInfo,
  13165. IN ULONG CompressedDataInfoLength,
  13166. IN struct _DEVICE_OBJECT *DeviceObject
  13167. );
  13168. typedef
  13169. BOOLEAN
  13170. (*PFAST_IO_MDL_READ_COMPLETE_COMPRESSED) (
  13171. IN struct _FILE_OBJECT *FileObject,
  13172. IN PMDL MdlChain,
  13173. IN struct _DEVICE_OBJECT *DeviceObject
  13174. );
  13175. typedef
  13176. BOOLEAN
  13177. (*PFAST_IO_MDL_WRITE_COMPLETE_COMPRESSED) (
  13178. IN struct _FILE_OBJECT *FileObject,
  13179. IN PLARGE_INTEGER FileOffset,
  13180. IN PMDL MdlChain,
  13181. IN struct _DEVICE_OBJECT *DeviceObject
  13182. );
  13183. typedef
  13184. BOOLEAN
  13185. (*PFAST_IO_QUERY_OPEN) (
  13186. IN struct _IRP *Irp,
  13187. OUT PFILE_NETWORK_OPEN_INFORMATION NetworkInformation,
  13188. IN struct _DEVICE_OBJECT *DeviceObject
  13189. );
  13190. //
  13191. // Define the structure to describe the Fast I/O dispatch routines. Any
  13192. // additions made to this structure MUST be added monotonically to the end
  13193. // of the structure, and fields CANNOT be removed from the middle.
  13194. //
  13195. typedef struct _FAST_IO_DISPATCH {
  13196. ULONG SizeOfFastIoDispatch;
  13197. PFAST_IO_CHECK_IF_POSSIBLE FastIoCheckIfPossible;
  13198. PFAST_IO_READ FastIoRead;
  13199. PFAST_IO_WRITE FastIoWrite;
  13200. PFAST_IO_QUERY_BASIC_INFO FastIoQueryBasicInfo;
  13201. PFAST_IO_QUERY_STANDARD_INFO FastIoQueryStandardInfo;
  13202. PFAST_IO_LOCK FastIoLock;
  13203. PFAST_IO_UNLOCK_SINGLE FastIoUnlockSingle;
  13204. PFAST_IO_UNLOCK_ALL FastIoUnlockAll;
  13205. PFAST_IO_UNLOCK_ALL_BY_KEY FastIoUnlockAllByKey;
  13206. PFAST_IO_DEVICE_CONTROL FastIoDeviceControl;
  13207. PFAST_IO_ACQUIRE_FILE AcquireFileForNtCreateSection;
  13208. PFAST_IO_RELEASE_FILE ReleaseFileForNtCreateSection;
  13209. PFAST_IO_DETACH_DEVICE FastIoDetachDevice;
  13210. PFAST_IO_QUERY_NETWORK_OPEN_INFO FastIoQueryNetworkOpenInfo;
  13211. PFAST_IO_ACQUIRE_FOR_MOD_WRITE AcquireForModWrite;
  13212. PFAST_IO_MDL_READ MdlRead;
  13213. PFAST_IO_MDL_READ_COMPLETE MdlReadComplete;
  13214. PFAST_IO_PREPARE_MDL_WRITE PrepareMdlWrite;
  13215. PFAST_IO_MDL_WRITE_COMPLETE MdlWriteComplete;
  13216. PFAST_IO_READ_COMPRESSED FastIoReadCompressed;
  13217. PFAST_IO_WRITE_COMPRESSED FastIoWriteCompressed;
  13218. PFAST_IO_MDL_READ_COMPLETE_COMPRESSED MdlReadCompleteCompressed;
  13219. PFAST_IO_MDL_WRITE_COMPLETE_COMPRESSED MdlWriteCompleteCompressed;
  13220. PFAST_IO_QUERY_OPEN FastIoQueryOpen;
  13221. PFAST_IO_RELEASE_FOR_MOD_WRITE ReleaseForModWrite;
  13222. PFAST_IO_ACQUIRE_FOR_CCFLUSH AcquireForCcFlush;
  13223. PFAST_IO_RELEASE_FOR_CCFLUSH ReleaseForCcFlush;
  13224. } FAST_IO_DISPATCH, *PFAST_IO_DISPATCH;
  13225. //
  13226. // Define the actions that a driver execution routine may request of the
  13227. // adapter/controller allocation routines upon return.
  13228. //
  13229. typedef enum _IO_ALLOCATION_ACTION {
  13230. KeepObject = 1,
  13231. DeallocateObject,
  13232. DeallocateObjectKeepRegisters
  13233. } IO_ALLOCATION_ACTION, *PIO_ALLOCATION_ACTION;
  13234. //
  13235. // Define device driver adapter/controller execution routine.
  13236. //
  13237. typedef
  13238. IO_ALLOCATION_ACTION
  13239. (*PDRIVER_CONTROL) (
  13240. IN struct _DEVICE_OBJECT *DeviceObject,
  13241. IN struct _IRP *Irp,
  13242. IN PVOID MapRegisterBase,
  13243. IN PVOID Context
  13244. );
  13245. //
  13246. // Define the I/O system's security context type for use by file system's
  13247. // when checking access to volumes, files, and directories.
  13248. //
  13249. typedef struct _IO_SECURITY_CONTEXT {
  13250. PSECURITY_QUALITY_OF_SERVICE SecurityQos;
  13251. PACCESS_STATE AccessState;
  13252. ACCESS_MASK DesiredAccess;
  13253. ULONG FullCreateOptions;
  13254. } IO_SECURITY_CONTEXT, *PIO_SECURITY_CONTEXT;
  13255. //
  13256. // Define Volume Parameter Block (VPB) flags.
  13257. //
  13258. #define VPB_MOUNTED 0x00000001
  13259. #define VPB_LOCKED 0x00000002
  13260. #define VPB_PERSISTENT 0x00000004
  13261. #define VPB_REMOVE_PENDING 0x00000008
  13262. #define VPB_RAW_MOUNT 0x00000010
  13263. //
  13264. // Volume Parameter Block (VPB)
  13265. //
  13266. #define MAXIMUM_VOLUME_LABEL_LENGTH (32 * sizeof(WCHAR)) // 32 characters
  13267. typedef struct _VPB {
  13268. CSHORT Type;
  13269. CSHORT Size;
  13270. USHORT Flags;
  13271. USHORT VolumeLabelLength; // in bytes
  13272. struct _DEVICE_OBJECT *DeviceObject;
  13273. struct _DEVICE_OBJECT *RealDevice;
  13274. ULONG SerialNumber;
  13275. ULONG ReferenceCount;
  13276. WCHAR VolumeLabel[MAXIMUM_VOLUME_LABEL_LENGTH / sizeof(WCHAR)];
  13277. } VPB, *PVPB;
  13278. #if defined(_WIN64)
  13279. //
  13280. // Use __inline DMA macros (hal.h)
  13281. //
  13282. #ifndef USE_DMA_MACROS
  13283. #define USE_DMA_MACROS
  13284. #endif
  13285. //
  13286. // Only PnP drivers!
  13287. //
  13288. #ifndef NO_LEGACY_DRIVERS
  13289. #define NO_LEGACY_DRIVERS
  13290. #endif
  13291. #endif // _WIN64
  13292. #if defined(USE_DMA_MACROS) && (defined(_NTDDK_) || defined(_NTDRIVER_) || defined(_NTOSP_))
  13293. //
  13294. // Define object type specific fields of various objects used by the I/O system
  13295. //
  13296. typedef struct _DMA_ADAPTER *PADAPTER_OBJECT;
  13297. #else
  13298. //
  13299. // Define object type specific fields of various objects used by the I/O system
  13300. //
  13301. typedef struct _ADAPTER_OBJECT *PADAPTER_OBJECT;
  13302. #endif // USE_DMA_MACROS && (_NTDDK_ || _NTDRIVER_ || _NTOSP_)
  13303. //
  13304. // Define Wait Context Block (WCB)
  13305. //
  13306. typedef struct _WAIT_CONTEXT_BLOCK {
  13307. KDEVICE_QUEUE_ENTRY WaitQueueEntry;
  13308. PDRIVER_CONTROL DeviceRoutine;
  13309. PVOID DeviceContext;
  13310. ULONG NumberOfMapRegisters;
  13311. PVOID DeviceObject;
  13312. PVOID CurrentIrp;
  13313. PKDPC BufferChainingDpc;
  13314. } WAIT_CONTEXT_BLOCK, *PWAIT_CONTEXT_BLOCK;
  13315. typedef struct _CONTROLLER_OBJECT {
  13316. CSHORT Type;
  13317. CSHORT Size;
  13318. PVOID ControllerExtension;
  13319. KDEVICE_QUEUE DeviceWaitQueue;
  13320. ULONG Spare1;
  13321. LARGE_INTEGER Spare2;
  13322. } CONTROLLER_OBJECT, *PCONTROLLER_OBJECT;
  13323. //
  13324. // Define Device Object (DO) flags
  13325. //
  13326. #define DO_VERIFY_VOLUME 0x00000002
  13327. #define DO_BUFFERED_IO 0x00000004
  13328. #define DO_EXCLUSIVE 0x00000008
  13329. #define DO_DIRECT_IO 0x00000010
  13330. #define DO_MAP_IO_BUFFER 0x00000020
  13331. #define DO_DEVICE_HAS_NAME 0x00000040
  13332. #define DO_DEVICE_INITIALIZING 0x00000080
  13333. #define DO_SYSTEM_BOOT_PARTITION 0x00000100
  13334. #define DO_LONG_TERM_REQUESTS 0x00000200
  13335. #define DO_NEVER_LAST_DEVICE 0x00000400
  13336. #define DO_SHUTDOWN_REGISTERED 0x00000800
  13337. #define DO_BUS_ENUMERATED_DEVICE 0x00001000
  13338. #define DO_POWER_PAGABLE 0x00002000
  13339. #define DO_POWER_INRUSH 0x00004000
  13340. #define DO_LOW_PRIORITY_FILESYSTEM 0x00010000
  13341. //
  13342. // Device Object structure definition
  13343. //
  13344. typedef struct DECLSPEC_ALIGN(MEMORY_ALLOCATION_ALIGNMENT) _DEVICE_OBJECT {
  13345. CSHORT Type;
  13346. USHORT Size;
  13347. LONG ReferenceCount;
  13348. struct _DRIVER_OBJECT *DriverObject;
  13349. struct _DEVICE_OBJECT *NextDevice;
  13350. struct _DEVICE_OBJECT *AttachedDevice;
  13351. struct _IRP *CurrentIrp;
  13352. PIO_TIMER Timer;
  13353. ULONG Flags; // See above: DO_...
  13354. ULONG Characteristics; // See ntioapi: FILE_...
  13355. PVPB Vpb;
  13356. PVOID DeviceExtension;
  13357. DEVICE_TYPE DeviceType;
  13358. CCHAR StackSize;
  13359. union {
  13360. LIST_ENTRY ListEntry;
  13361. WAIT_CONTEXT_BLOCK Wcb;
  13362. } Queue;
  13363. ULONG AlignmentRequirement;
  13364. KDEVICE_QUEUE DeviceQueue;
  13365. KDPC Dpc;
  13366. //
  13367. // The following field is for exclusive use by the filesystem to keep
  13368. // track of the number of Fsp threads currently using the device
  13369. //
  13370. ULONG ActiveThreadCount;
  13371. PSECURITY_DESCRIPTOR SecurityDescriptor;
  13372. KEVENT DeviceLock;
  13373. USHORT SectorSize;
  13374. USHORT Spare1;
  13375. struct _DEVOBJ_EXTENSION *DeviceObjectExtension;
  13376. PVOID Reserved;
  13377. } DEVICE_OBJECT;
  13378. typedef struct _DEVICE_OBJECT *PDEVICE_OBJECT;
  13379. struct _DEVICE_OBJECT_POWER_EXTENSION;
  13380. typedef struct _DEVOBJ_EXTENSION {
  13381. CSHORT Type;
  13382. USHORT Size;
  13383. //
  13384. // Public part of the DeviceObjectExtension structure
  13385. //
  13386. PDEVICE_OBJECT DeviceObject; // owning device object
  13387. } DEVOBJ_EXTENSION, *PDEVOBJ_EXTENSION;
  13388. //
  13389. // Define Driver Object (DRVO) flags
  13390. //
  13391. #define DRVO_UNLOAD_INVOKED 0x00000001
  13392. #define DRVO_LEGACY_DRIVER 0x00000002
  13393. #define DRVO_BUILTIN_DRIVER 0x00000004 // Driver objects for Hal, PnP Mgr
  13394. #define DRVO_REINIT_REGISTERED 0x00000008
  13395. #define DRVO_INITIALIZED 0x00000010
  13396. #define DRVO_BOOTREINIT_REGISTERED 0x00000020
  13397. #define DRVO_LEGACY_RESOURCES 0x00000040
  13398. typedef struct _DRIVER_EXTENSION {
  13399. //
  13400. // Back pointer to Driver Object
  13401. //
  13402. struct _DRIVER_OBJECT *DriverObject;
  13403. //
  13404. // The AddDevice entry point is called by the Plug & Play manager
  13405. // to inform the driver when a new device instance arrives that this
  13406. // driver must control.
  13407. //
  13408. PDRIVER_ADD_DEVICE AddDevice;
  13409. //
  13410. // The count field is used to count the number of times the driver has
  13411. // had its registered reinitialization routine invoked.
  13412. //
  13413. ULONG Count;
  13414. //
  13415. // The service name field is used by the pnp manager to determine
  13416. // where the driver related info is stored in the registry.
  13417. //
  13418. UNICODE_STRING ServiceKeyName;
  13419. //
  13420. // Note: any new shared fields get added here.
  13421. //
  13422. } DRIVER_EXTENSION, *PDRIVER_EXTENSION;
  13423. typedef struct _DRIVER_OBJECT {
  13424. CSHORT Type;
  13425. CSHORT Size;
  13426. //
  13427. // The following links all of the devices created by a single driver
  13428. // together on a list, and the Flags word provides an extensible flag
  13429. // location for driver objects.
  13430. //
  13431. PDEVICE_OBJECT DeviceObject;
  13432. ULONG Flags;
  13433. //
  13434. // The following section describes where the driver is loaded. The count
  13435. // field is used to count the number of times the driver has had its
  13436. // registered reinitialization routine invoked.
  13437. //
  13438. PVOID DriverStart;
  13439. ULONG DriverSize;
  13440. PVOID DriverSection;
  13441. PDRIVER_EXTENSION DriverExtension;
  13442. //
  13443. // The driver name field is used by the error log thread
  13444. // determine the name of the driver that an I/O request is/was bound.
  13445. //
  13446. UNICODE_STRING DriverName;
  13447. //
  13448. // The following section is for registry support. Thise is a pointer
  13449. // to the path to the hardware information in the registry
  13450. //
  13451. PUNICODE_STRING HardwareDatabase;
  13452. //
  13453. // The following section contains the optional pointer to an array of
  13454. // alternate entry points to a driver for "fast I/O" support. Fast I/O
  13455. // is performed by invoking the driver routine directly with separate
  13456. // parameters, rather than using the standard IRP call mechanism. Note
  13457. // that these functions may only be used for synchronous I/O, and when
  13458. // the file is cached.
  13459. //
  13460. PFAST_IO_DISPATCH FastIoDispatch;
  13461. //
  13462. // The following section describes the entry points to this particular
  13463. // driver. Note that the major function dispatch table must be the last
  13464. // field in the object so that it remains extensible.
  13465. //
  13466. PDRIVER_INITIALIZE DriverInit;
  13467. PDRIVER_STARTIO DriverStartIo;
  13468. PDRIVER_UNLOAD DriverUnload;
  13469. PDRIVER_DISPATCH MajorFunction[IRP_MJ_MAXIMUM_FUNCTION + 1];
  13470. } DRIVER_OBJECT;
  13471. typedef struct _DRIVER_OBJECT *PDRIVER_OBJECT;
  13472. //
  13473. // The following structure is pointed to by the SectionObject pointer field
  13474. // of a file object, and is allocated by the various NT file systems.
  13475. //
  13476. typedef struct _SECTION_OBJECT_POINTERS {
  13477. PVOID DataSectionObject;
  13478. PVOID SharedCacheMap;
  13479. PVOID ImageSectionObject;
  13480. } SECTION_OBJECT_POINTERS;
  13481. typedef SECTION_OBJECT_POINTERS *PSECTION_OBJECT_POINTERS;
  13482. //
  13483. // Define the format of a completion message.
  13484. //
  13485. typedef struct _IO_COMPLETION_CONTEXT {
  13486. PVOID Port;
  13487. PVOID Key;
  13488. } IO_COMPLETION_CONTEXT, *PIO_COMPLETION_CONTEXT;
  13489. //
  13490. // Define File Object (FO) flags
  13491. //
  13492. #define FO_FILE_OPEN 0x00000001
  13493. #define FO_SYNCHRONOUS_IO 0x00000002
  13494. #define FO_ALERTABLE_IO 0x00000004
  13495. #define FO_NO_INTERMEDIATE_BUFFERING 0x00000008
  13496. #define FO_WRITE_THROUGH 0x00000010
  13497. #define FO_SEQUENTIAL_ONLY 0x00000020
  13498. #define FO_CACHE_SUPPORTED 0x00000040
  13499. #define FO_NAMED_PIPE 0x00000080
  13500. #define FO_STREAM_FILE 0x00000100
  13501. #define FO_MAILSLOT 0x00000200
  13502. #define FO_GENERATE_AUDIT_ON_CLOSE 0x00000400
  13503. #define FO_DIRECT_DEVICE_OPEN 0x00000800
  13504. #define FO_FILE_MODIFIED 0x00001000
  13505. #define FO_FILE_SIZE_CHANGED 0x00002000
  13506. #define FO_CLEANUP_COMPLETE 0x00004000
  13507. #define FO_TEMPORARY_FILE 0x00008000
  13508. #define FO_DELETE_ON_CLOSE 0x00010000
  13509. #define FO_OPENED_CASE_SENSITIVE 0x00020000
  13510. #define FO_HANDLE_CREATED 0x00040000
  13511. #define FO_FILE_FAST_IO_READ 0x00080000
  13512. #define FO_RANDOM_ACCESS 0x00100000
  13513. #define FO_FILE_OPEN_CANCELLED 0x00200000
  13514. #define FO_VOLUME_OPEN 0x00400000
  13515. #define FO_FILE_OBJECT_HAS_EXTENSION 0x00800000
  13516. #define FO_REMOTE_ORIGIN 0x01000000
  13517. typedef struct _FILE_OBJECT {
  13518. CSHORT Type;
  13519. CSHORT Size;
  13520. PDEVICE_OBJECT DeviceObject;
  13521. PVPB Vpb;
  13522. PVOID FsContext;
  13523. PVOID FsContext2;
  13524. PSECTION_OBJECT_POINTERS SectionObjectPointer;
  13525. PVOID PrivateCacheMap;
  13526. NTSTATUS FinalStatus;
  13527. struct _FILE_OBJECT *RelatedFileObject;
  13528. BOOLEAN LockOperation;
  13529. BOOLEAN DeletePending;
  13530. BOOLEAN ReadAccess;
  13531. BOOLEAN WriteAccess;
  13532. BOOLEAN DeleteAccess;
  13533. BOOLEAN SharedRead;
  13534. BOOLEAN SharedWrite;
  13535. BOOLEAN SharedDelete;
  13536. ULONG Flags;
  13537. UNICODE_STRING FileName;
  13538. LARGE_INTEGER CurrentByteOffset;
  13539. ULONG Waiters;
  13540. ULONG Busy;
  13541. PVOID LastLock;
  13542. KEVENT Lock;
  13543. KEVENT Event;
  13544. PIO_COMPLETION_CONTEXT CompletionContext;
  13545. } FILE_OBJECT;
  13546. typedef struct _FILE_OBJECT *PFILE_OBJECT;
  13547. //
  13548. // Define I/O Request Packet (IRP) flags
  13549. //
  13550. #define IRP_NOCACHE 0x00000001
  13551. #define IRP_PAGING_IO 0x00000002
  13552. #define IRP_MOUNT_COMPLETION 0x00000002
  13553. #define IRP_SYNCHRONOUS_API 0x00000004
  13554. #define IRP_ASSOCIATED_IRP 0x00000008
  13555. #define IRP_BUFFERED_IO 0x00000010
  13556. #define IRP_DEALLOCATE_BUFFER 0x00000020
  13557. #define IRP_INPUT_OPERATION 0x00000040
  13558. #define IRP_SYNCHRONOUS_PAGING_IO 0x00000040
  13559. #define IRP_CREATE_OPERATION 0x00000080
  13560. #define IRP_READ_OPERATION 0x00000100
  13561. #define IRP_WRITE_OPERATION 0x00000200
  13562. #define IRP_CLOSE_OPERATION 0x00000400
  13563. #define IRP_DEFER_IO_COMPLETION 0x00000800
  13564. #define IRP_OB_QUERY_NAME 0x00001000
  13565. #define IRP_HOLD_DEVICE_QUEUE 0x00002000
  13566. //
  13567. // Define I/O request packet (IRP) alternate flags for allocation control.
  13568. //
  13569. #define IRP_QUOTA_CHARGED 0x01
  13570. #define IRP_ALLOCATED_MUST_SUCCEED 0x02
  13571. #define IRP_ALLOCATED_FIXED_SIZE 0x04
  13572. #define IRP_LOOKASIDE_ALLOCATION 0x08
  13573. //
  13574. // I/O Request Packet (IRP) definition
  13575. //
  13576. typedef struct DECLSPEC_ALIGN(MEMORY_ALLOCATION_ALIGNMENT) _IRP {
  13577. CSHORT Type;
  13578. USHORT Size;
  13579. //
  13580. // Define the common fields used to control the IRP.
  13581. //
  13582. //
  13583. // Define a pointer to the Memory Descriptor List (MDL) for this I/O
  13584. // request. This field is only used if the I/O is "direct I/O".
  13585. //
  13586. PMDL MdlAddress;
  13587. //
  13588. // Flags word - used to remember various flags.
  13589. //
  13590. ULONG Flags;
  13591. //
  13592. // The following union is used for one of three purposes:
  13593. //
  13594. // 1. This IRP is an associated IRP. The field is a pointer to a master
  13595. // IRP.
  13596. //
  13597. // 2. This is the master IRP. The field is the count of the number of
  13598. // IRPs which must complete (associated IRPs) before the master can
  13599. // complete.
  13600. //
  13601. // 3. This operation is being buffered and the field is the address of
  13602. // the system space buffer.
  13603. //
  13604. union {
  13605. struct _IRP *MasterIrp;
  13606. LONG IrpCount;
  13607. PVOID SystemBuffer;
  13608. } AssociatedIrp;
  13609. //
  13610. // Thread list entry - allows queueing the IRP to the thread pending I/O
  13611. // request packet list.
  13612. //
  13613. LIST_ENTRY ThreadListEntry;
  13614. //
  13615. // I/O status - final status of operation.
  13616. //
  13617. IO_STATUS_BLOCK IoStatus;
  13618. //
  13619. // Requestor mode - mode of the original requestor of this operation.
  13620. //
  13621. KPROCESSOR_MODE RequestorMode;
  13622. //
  13623. // Pending returned - TRUE if pending was initially returned as the
  13624. // status for this packet.
  13625. //
  13626. BOOLEAN PendingReturned;
  13627. //
  13628. // Stack state information.
  13629. //
  13630. CHAR StackCount;
  13631. CHAR CurrentLocation;
  13632. //
  13633. // Cancel - packet has been canceled.
  13634. //
  13635. BOOLEAN Cancel;
  13636. //
  13637. // Cancel Irql - Irql at which the cancel spinlock was acquired.
  13638. //
  13639. KIRQL CancelIrql;
  13640. //
  13641. // ApcEnvironment - Used to save the APC environment at the time that the
  13642. // packet was initialized.
  13643. //
  13644. CCHAR ApcEnvironment;
  13645. //
  13646. // Allocation control flags.
  13647. //
  13648. UCHAR AllocationFlags;
  13649. //
  13650. // User parameters.
  13651. //
  13652. PIO_STATUS_BLOCK UserIosb;
  13653. PKEVENT UserEvent;
  13654. union {
  13655. struct {
  13656. PIO_APC_ROUTINE UserApcRoutine;
  13657. PVOID UserApcContext;
  13658. } AsynchronousParameters;
  13659. LARGE_INTEGER AllocationSize;
  13660. } Overlay;
  13661. //
  13662. // CancelRoutine - Used to contain the address of a cancel routine supplied
  13663. // by a device driver when the IRP is in a cancelable state.
  13664. //
  13665. PDRIVER_CANCEL CancelRoutine;
  13666. //
  13667. // Note that the UserBuffer parameter is outside of the stack so that I/O
  13668. // completion can copy data back into the user's address space without
  13669. // having to know exactly which service was being invoked. The length
  13670. // of the copy is stored in the second half of the I/O status block. If
  13671. // the UserBuffer field is NULL, then no copy is performed.
  13672. //
  13673. PVOID UserBuffer;
  13674. //
  13675. // Kernel structures
  13676. //
  13677. // The following section contains kernel structures which the IRP needs
  13678. // in order to place various work information in kernel controller system
  13679. // queues. Because the size and alignment cannot be controlled, they are
  13680. // placed here at the end so they just hang off and do not affect the
  13681. // alignment of other fields in the IRP.
  13682. //
  13683. union {
  13684. struct {
  13685. union {
  13686. //
  13687. // DeviceQueueEntry - The device queue entry field is used to
  13688. // queue the IRP to the device driver device queue.
  13689. //
  13690. KDEVICE_QUEUE_ENTRY DeviceQueueEntry;
  13691. struct {
  13692. //
  13693. // The following are available to the driver to use in
  13694. // whatever manner is desired, while the driver owns the
  13695. // packet.
  13696. //
  13697. PVOID DriverContext[4];
  13698. } ;
  13699. } ;
  13700. //
  13701. // Thread - pointer to caller's Thread Control Block.
  13702. //
  13703. PETHREAD Thread;
  13704. //
  13705. // Auxiliary buffer - pointer to any auxiliary buffer that is
  13706. // required to pass information to a driver that is not contained
  13707. // in a normal buffer.
  13708. //
  13709. PCHAR AuxiliaryBuffer;
  13710. //
  13711. // The following unnamed structure must be exactly identical
  13712. // to the unnamed structure used in the minipacket header used
  13713. // for completion queue entries.
  13714. //
  13715. struct {
  13716. //
  13717. // List entry - used to queue the packet to completion queue, among
  13718. // others.
  13719. //
  13720. LIST_ENTRY ListEntry;
  13721. union {
  13722. //
  13723. // Current stack location - contains a pointer to the current
  13724. // IO_STACK_LOCATION structure in the IRP stack. This field
  13725. // should never be directly accessed by drivers. They should
  13726. // use the standard functions.
  13727. //
  13728. struct _IO_STACK_LOCATION *CurrentStackLocation;
  13729. //
  13730. // Minipacket type.
  13731. //
  13732. ULONG PacketType;
  13733. };
  13734. };
  13735. //
  13736. // Original file object - pointer to the original file object
  13737. // that was used to open the file. This field is owned by the
  13738. // I/O system and should not be used by any other drivers.
  13739. //
  13740. PFILE_OBJECT OriginalFileObject;
  13741. } Overlay;
  13742. //
  13743. // APC - This APC control block is used for the special kernel APC as
  13744. // well as for the caller's APC, if one was specified in the original
  13745. // argument list. If so, then the APC is reused for the normal APC for
  13746. // whatever mode the caller was in and the "special" routine that is
  13747. // invoked before the APC gets control simply deallocates the IRP.
  13748. //
  13749. KAPC Apc;
  13750. //
  13751. // CompletionKey - This is the key that is used to distinguish
  13752. // individual I/O operations initiated on a single file handle.
  13753. //
  13754. PVOID CompletionKey;
  13755. } Tail;
  13756. } IRP, *PIRP;
  13757. //
  13758. // Define completion routine types for use in stack locations in an IRP
  13759. //
  13760. typedef
  13761. NTSTATUS
  13762. (*PIO_COMPLETION_ROUTINE) (
  13763. IN PDEVICE_OBJECT DeviceObject,
  13764. IN PIRP Irp,
  13765. IN PVOID Context
  13766. );
  13767. //
  13768. // Define stack location control flags
  13769. //
  13770. #define SL_PENDING_RETURNED 0x01
  13771. #define SL_INVOKE_ON_CANCEL 0x20
  13772. #define SL_INVOKE_ON_SUCCESS 0x40
  13773. #define SL_INVOKE_ON_ERROR 0x80
  13774. //
  13775. // Define flags for various functions
  13776. //
  13777. //
  13778. // Create / Create Named Pipe
  13779. //
  13780. // The following flags must exactly match those in the IoCreateFile call's
  13781. // options. The case sensitive flag is added in later, by the parse routine,
  13782. // and is not an actual option to open. Rather, it is part of the object
  13783. // manager's attributes structure.
  13784. //
  13785. #define SL_FORCE_ACCESS_CHECK 0x01
  13786. #define SL_OPEN_PAGING_FILE 0x02
  13787. #define SL_OPEN_TARGET_DIRECTORY 0x04
  13788. #define SL_CASE_SENSITIVE 0x80
  13789. //
  13790. // Read / Write
  13791. //
  13792. #define SL_KEY_SPECIFIED 0x01
  13793. #define SL_OVERRIDE_VERIFY_VOLUME 0x02
  13794. #define SL_WRITE_THROUGH 0x04
  13795. #define SL_FT_SEQUENTIAL_WRITE 0x08
  13796. //
  13797. // Device I/O Control
  13798. //
  13799. //
  13800. // Same SL_OVERRIDE_VERIFY_VOLUME as for read/write above.
  13801. //
  13802. #define SL_READ_ACCESS_GRANTED 0x01
  13803. #define SL_WRITE_ACCESS_GRANTED 0x04 // Gap for SL_OVERRIDE_VERIFY_VOLUME
  13804. //
  13805. // Lock
  13806. //
  13807. #define SL_FAIL_IMMEDIATELY 0x01
  13808. #define SL_EXCLUSIVE_LOCK 0x02
  13809. //
  13810. // QueryDirectory / QueryEa / QueryQuota
  13811. //
  13812. #define SL_RESTART_SCAN 0x01
  13813. #define SL_RETURN_SINGLE_ENTRY 0x02
  13814. #define SL_INDEX_SPECIFIED 0x04
  13815. //
  13816. // NotifyDirectory
  13817. //
  13818. #define SL_WATCH_TREE 0x01
  13819. //
  13820. // FileSystemControl
  13821. //
  13822. // minor: mount/verify volume
  13823. //
  13824. #define SL_ALLOW_RAW_MOUNT 0x01
  13825. //
  13826. // Define PNP/POWER types required by IRP_MJ_PNP/IRP_MJ_POWER.
  13827. //
  13828. typedef enum _DEVICE_RELATION_TYPE {
  13829. BusRelations,
  13830. EjectionRelations,
  13831. PowerRelations,
  13832. RemovalRelations,
  13833. TargetDeviceRelation,
  13834. SingleBusRelations
  13835. } DEVICE_RELATION_TYPE, *PDEVICE_RELATION_TYPE;
  13836. typedef struct _DEVICE_RELATIONS {
  13837. ULONG Count;
  13838. PDEVICE_OBJECT Objects[1]; // variable length
  13839. } DEVICE_RELATIONS, *PDEVICE_RELATIONS;
  13840. typedef enum _DEVICE_USAGE_NOTIFICATION_TYPE {
  13841. DeviceUsageTypeUndefined,
  13842. DeviceUsageTypePaging,
  13843. DeviceUsageTypeHibernation,
  13844. DeviceUsageTypeDumpFile
  13845. } DEVICE_USAGE_NOTIFICATION_TYPE;
  13846. // workaround overloaded definition (rpc generated headers all define INTERFACE
  13847. // to match the class name).
  13848. #undef INTERFACE
  13849. typedef struct _INTERFACE {
  13850. USHORT Size;
  13851. USHORT Version;
  13852. PVOID Context;
  13853. PINTERFACE_REFERENCE InterfaceReference;
  13854. PINTERFACE_DEREFERENCE InterfaceDereference;
  13855. // interface specific entries go here
  13856. } INTERFACE, *PINTERFACE;
  13857. typedef struct _DEVICE_CAPABILITIES {
  13858. USHORT Size;
  13859. USHORT Version; // the version documented here is version 1
  13860. ULONG DeviceD1:1;
  13861. ULONG DeviceD2:1;
  13862. ULONG LockSupported:1;
  13863. ULONG EjectSupported:1; // Ejectable in S0
  13864. ULONG Removable:1;
  13865. ULONG DockDevice:1;
  13866. ULONG UniqueID:1;
  13867. ULONG SilentInstall:1;
  13868. ULONG RawDeviceOK:1;
  13869. ULONG SurpriseRemovalOK:1;
  13870. ULONG WakeFromD0:1;
  13871. ULONG WakeFromD1:1;
  13872. ULONG WakeFromD2:1;
  13873. ULONG WakeFromD3:1;
  13874. ULONG HardwareDisabled:1;
  13875. ULONG NonDynamic:1;
  13876. ULONG WarmEjectSupported:1;
  13877. ULONG NoDisplayInUI:1;
  13878. ULONG Reserved:14;
  13879. ULONG Address;
  13880. ULONG UINumber;
  13881. DEVICE_POWER_STATE DeviceState[POWER_SYSTEM_MAXIMUM];
  13882. SYSTEM_POWER_STATE SystemWake;
  13883. DEVICE_POWER_STATE DeviceWake;
  13884. ULONG D1Latency;
  13885. ULONG D2Latency;
  13886. ULONG D3Latency;
  13887. } DEVICE_CAPABILITIES, *PDEVICE_CAPABILITIES;
  13888. typedef struct _POWER_SEQUENCE {
  13889. ULONG SequenceD1;
  13890. ULONG SequenceD2;
  13891. ULONG SequenceD3;
  13892. } POWER_SEQUENCE, *PPOWER_SEQUENCE;
  13893. typedef enum {
  13894. BusQueryDeviceID = 0, // <Enumerator>\<Enumerator-specific device id>
  13895. BusQueryHardwareIDs = 1, // Hardware ids
  13896. BusQueryCompatibleIDs = 2, // compatible device ids
  13897. BusQueryInstanceID = 3, // persistent id for this instance of the device
  13898. BusQueryDeviceSerialNumber = 4 // serial number for this device
  13899. } BUS_QUERY_ID_TYPE, *PBUS_QUERY_ID_TYPE;
  13900. typedef ULONG PNP_DEVICE_STATE, *PPNP_DEVICE_STATE;
  13901. #define PNP_DEVICE_DISABLED 0x00000001
  13902. #define PNP_DEVICE_DONT_DISPLAY_IN_UI 0x00000002
  13903. #define PNP_DEVICE_FAILED 0x00000004
  13904. #define PNP_DEVICE_REMOVED 0x00000008
  13905. #define PNP_DEVICE_RESOURCE_REQUIREMENTS_CHANGED 0x00000010
  13906. #define PNP_DEVICE_NOT_DISABLEABLE 0x00000020
  13907. typedef enum {
  13908. DeviceTextDescription = 0, // DeviceDesc property
  13909. DeviceTextLocationInformation = 1 // DeviceLocation property
  13910. } DEVICE_TEXT_TYPE, *PDEVICE_TEXT_TYPE;
  13911. //
  13912. // Define I/O Request Packet (IRP) stack locations
  13913. //
  13914. #if !defined(_AMD64_) && !defined(_IA64_)
  13915. #include "pshpack4.h"
  13916. #endif
  13917. #if defined(_WIN64)
  13918. #define POINTER_ALIGNMENT DECLSPEC_ALIGN(8)
  13919. #else
  13920. #define POINTER_ALIGNMENT
  13921. #endif
  13922. typedef struct _IO_STACK_LOCATION {
  13923. UCHAR MajorFunction;
  13924. UCHAR MinorFunction;
  13925. UCHAR Flags;
  13926. UCHAR Control;
  13927. //
  13928. // The following user parameters are based on the service that is being
  13929. // invoked. Drivers and file systems can determine which set to use based
  13930. // on the above major and minor function codes.
  13931. //
  13932. union {
  13933. //
  13934. // System service parameters for: NtCreateFile
  13935. //
  13936. struct {
  13937. PIO_SECURITY_CONTEXT SecurityContext;
  13938. ULONG Options;
  13939. USHORT POINTER_ALIGNMENT FileAttributes;
  13940. USHORT ShareAccess;
  13941. ULONG POINTER_ALIGNMENT EaLength;
  13942. } Create;
  13943. //
  13944. // System service parameters for: NtReadFile
  13945. //
  13946. struct {
  13947. ULONG Length;
  13948. ULONG POINTER_ALIGNMENT Key;
  13949. LARGE_INTEGER ByteOffset;
  13950. } Read;
  13951. //
  13952. // System service parameters for: NtWriteFile
  13953. //
  13954. struct {
  13955. ULONG Length;
  13956. ULONG POINTER_ALIGNMENT Key;
  13957. LARGE_INTEGER ByteOffset;
  13958. } Write;
  13959. //
  13960. // System service parameters for: NtQueryInformationFile
  13961. //
  13962. struct {
  13963. ULONG Length;
  13964. FILE_INFORMATION_CLASS POINTER_ALIGNMENT FileInformationClass;
  13965. } QueryFile;
  13966. //
  13967. // System service parameters for: NtSetInformationFile
  13968. //
  13969. struct {
  13970. ULONG Length;
  13971. FILE_INFORMATION_CLASS POINTER_ALIGNMENT FileInformationClass;
  13972. PFILE_OBJECT FileObject;
  13973. union {
  13974. struct {
  13975. BOOLEAN ReplaceIfExists;
  13976. BOOLEAN AdvanceOnly;
  13977. };
  13978. ULONG ClusterCount;
  13979. HANDLE DeleteHandle;
  13980. };
  13981. } SetFile;
  13982. //
  13983. // System service parameters for: NtQueryVolumeInformationFile
  13984. //
  13985. struct {
  13986. ULONG Length;
  13987. FS_INFORMATION_CLASS POINTER_ALIGNMENT FsInformationClass;
  13988. } QueryVolume;
  13989. //
  13990. // System service parameters for: NtFlushBuffersFile
  13991. //
  13992. // No extra user-supplied parameters.
  13993. //
  13994. //
  13995. // System service parameters for: NtDeviceIoControlFile
  13996. //
  13997. // Note that the user's output buffer is stored in the UserBuffer field
  13998. // and the user's input buffer is stored in the SystemBuffer field.
  13999. //
  14000. struct {
  14001. ULONG OutputBufferLength;
  14002. ULONG POINTER_ALIGNMENT InputBufferLength;
  14003. ULONG POINTER_ALIGNMENT IoControlCode;
  14004. PVOID Type3InputBuffer;
  14005. } DeviceIoControl;
  14006. //
  14007. // System service parameters for: NtQuerySecurityObject
  14008. //
  14009. struct {
  14010. SECURITY_INFORMATION SecurityInformation;
  14011. ULONG POINTER_ALIGNMENT Length;
  14012. } QuerySecurity;
  14013. //
  14014. // System service parameters for: NtSetSecurityObject
  14015. //
  14016. struct {
  14017. SECURITY_INFORMATION SecurityInformation;
  14018. PSECURITY_DESCRIPTOR SecurityDescriptor;
  14019. } SetSecurity;
  14020. //
  14021. // Non-system service parameters.
  14022. //
  14023. // Parameters for MountVolume
  14024. //
  14025. struct {
  14026. PVPB Vpb;
  14027. PDEVICE_OBJECT DeviceObject;
  14028. } MountVolume;
  14029. //
  14030. // Parameters for VerifyVolume
  14031. //
  14032. struct {
  14033. PVPB Vpb;
  14034. PDEVICE_OBJECT DeviceObject;
  14035. } VerifyVolume;
  14036. //
  14037. // Parameters for Scsi with internal device contorl.
  14038. //
  14039. struct {
  14040. struct _SCSI_REQUEST_BLOCK *Srb;
  14041. } Scsi;
  14042. //
  14043. // Parameters for IRP_MN_QUERY_DEVICE_RELATIONS
  14044. //
  14045. struct {
  14046. DEVICE_RELATION_TYPE Type;
  14047. } QueryDeviceRelations;
  14048. //
  14049. // Parameters for IRP_MN_QUERY_INTERFACE
  14050. //
  14051. struct {
  14052. CONST GUID *InterfaceType;
  14053. USHORT Size;
  14054. USHORT Version;
  14055. PINTERFACE Interface;
  14056. PVOID InterfaceSpecificData;
  14057. } QueryInterface;
  14058. //
  14059. // Parameters for IRP_MN_QUERY_CAPABILITIES
  14060. //
  14061. struct {
  14062. PDEVICE_CAPABILITIES Capabilities;
  14063. } DeviceCapabilities;
  14064. //
  14065. // Parameters for IRP_MN_FILTER_RESOURCE_REQUIREMENTS
  14066. //
  14067. struct {
  14068. PIO_RESOURCE_REQUIREMENTS_LIST IoResourceRequirementList;
  14069. } FilterResourceRequirements;
  14070. //
  14071. // Parameters for IRP_MN_READ_CONFIG and IRP_MN_WRITE_CONFIG
  14072. //
  14073. struct {
  14074. ULONG WhichSpace;
  14075. PVOID Buffer;
  14076. ULONG Offset;
  14077. ULONG POINTER_ALIGNMENT Length;
  14078. } ReadWriteConfig;
  14079. //
  14080. // Parameters for IRP_MN_SET_LOCK
  14081. //
  14082. struct {
  14083. BOOLEAN Lock;
  14084. } SetLock;
  14085. //
  14086. // Parameters for IRP_MN_QUERY_ID
  14087. //
  14088. struct {
  14089. BUS_QUERY_ID_TYPE IdType;
  14090. } QueryId;
  14091. //
  14092. // Parameters for IRP_MN_QUERY_DEVICE_TEXT
  14093. //
  14094. struct {
  14095. DEVICE_TEXT_TYPE DeviceTextType;
  14096. LCID POINTER_ALIGNMENT LocaleId;
  14097. } QueryDeviceText;
  14098. //
  14099. // Parameters for IRP_MN_DEVICE_USAGE_NOTIFICATION
  14100. //
  14101. struct {
  14102. BOOLEAN InPath;
  14103. BOOLEAN Reserved[3];
  14104. DEVICE_USAGE_NOTIFICATION_TYPE POINTER_ALIGNMENT Type;
  14105. } UsageNotification;
  14106. //
  14107. // Parameters for IRP_MN_WAIT_WAKE
  14108. //
  14109. struct {
  14110. SYSTEM_POWER_STATE PowerState;
  14111. } WaitWake;
  14112. //
  14113. // Parameter for IRP_MN_POWER_SEQUENCE
  14114. //
  14115. struct {
  14116. PPOWER_SEQUENCE PowerSequence;
  14117. } PowerSequence;
  14118. //
  14119. // Parameters for IRP_MN_SET_POWER and IRP_MN_QUERY_POWER
  14120. //
  14121. struct {
  14122. ULONG SystemContext;
  14123. POWER_STATE_TYPE POINTER_ALIGNMENT Type;
  14124. POWER_STATE POINTER_ALIGNMENT State;
  14125. POWER_ACTION POINTER_ALIGNMENT ShutdownType;
  14126. } Power;
  14127. //
  14128. // Parameters for StartDevice
  14129. //
  14130. struct {
  14131. PCM_RESOURCE_LIST AllocatedResources;
  14132. PCM_RESOURCE_LIST AllocatedResourcesTranslated;
  14133. } StartDevice;
  14134. //
  14135. // Parameters for Cleanup
  14136. //
  14137. // No extra parameters supplied
  14138. //
  14139. //
  14140. // WMI Irps
  14141. //
  14142. struct {
  14143. ULONG_PTR ProviderId;
  14144. PVOID DataPath;
  14145. ULONG BufferSize;
  14146. PVOID Buffer;
  14147. } WMI;
  14148. //
  14149. // Others - driver-specific
  14150. //
  14151. struct {
  14152. PVOID Argument1;
  14153. PVOID Argument2;
  14154. PVOID Argument3;
  14155. PVOID Argument4;
  14156. } Others;
  14157. } Parameters;
  14158. //
  14159. // Save a pointer to this device driver's device object for this request
  14160. // so it can be passed to the completion routine if needed.
  14161. //
  14162. PDEVICE_OBJECT DeviceObject;
  14163. //
  14164. // The following location contains a pointer to the file object for this
  14165. //
  14166. PFILE_OBJECT FileObject;
  14167. //
  14168. // The following routine is invoked depending on the flags in the above
  14169. // flags field.
  14170. //
  14171. PIO_COMPLETION_ROUTINE CompletionRoutine;
  14172. //
  14173. // The following is used to store the address of the context parameter
  14174. // that should be passed to the CompletionRoutine.
  14175. //
  14176. PVOID Context;
  14177. } IO_STACK_LOCATION, *PIO_STACK_LOCATION;
  14178. #if !defined(_AMD64_) && !defined(_IA64_)
  14179. #include "poppack.h"
  14180. #endif
  14181. //
  14182. // Define the share access structure used by file systems to determine
  14183. // whether or not another accessor may open the file.
  14184. //
  14185. typedef struct _SHARE_ACCESS {
  14186. ULONG OpenCount;
  14187. ULONG Readers;
  14188. ULONG Writers;
  14189. ULONG Deleters;
  14190. ULONG SharedRead;
  14191. ULONG SharedWrite;
  14192. ULONG SharedDelete;
  14193. } SHARE_ACCESS, *PSHARE_ACCESS;
  14194. //
  14195. // The following structure is used by drivers that are initializing to
  14196. // determine the number of devices of a particular type that have already
  14197. // been initialized. It is also used to track whether or not the AtDisk
  14198. // address range has already been claimed. Finally, it is used by the
  14199. // NtQuerySystemInformation system service to return device type counts.
  14200. //
  14201. typedef struct _CONFIGURATION_INFORMATION {
  14202. //
  14203. // This field indicates the total number of disks in the system. This
  14204. // number should be used by the driver to determine the name of new
  14205. // disks. This field should be updated by the driver as it finds new
  14206. // disks.
  14207. //
  14208. ULONG DiskCount; // Count of hard disks thus far
  14209. ULONG FloppyCount; // Count of floppy disks thus far
  14210. ULONG CdRomCount; // Count of CD-ROM drives thus far
  14211. ULONG TapeCount; // Count of tape drives thus far
  14212. ULONG ScsiPortCount; // Count of SCSI port adapters thus far
  14213. ULONG SerialCount; // Count of serial devices thus far
  14214. ULONG ParallelCount; // Count of parallel devices thus far
  14215. //
  14216. // These next two fields indicate ownership of one of the two IO address
  14217. // spaces that are used by WD1003-compatable disk controllers.
  14218. //
  14219. BOOLEAN AtDiskPrimaryAddressClaimed; // 0x1F0 - 0x1FF
  14220. BOOLEAN AtDiskSecondaryAddressClaimed; // 0x170 - 0x17F
  14221. //
  14222. // Indicates the structure version, as anything value belong this will have been added.
  14223. // Use the structure size as the version.
  14224. //
  14225. ULONG Version;
  14226. //
  14227. // Indicates the total number of medium changer devices in the system.
  14228. // This field will be updated by the drivers as it determines that
  14229. // new devices have been found and will be supported.
  14230. //
  14231. ULONG MediumChangerCount;
  14232. } CONFIGURATION_INFORMATION, *PCONFIGURATION_INFORMATION;
  14233. //
  14234. // Public I/O routine definitions
  14235. //
  14236. NTKERNELAPI
  14237. VOID
  14238. IoAcquireCancelSpinLock(
  14239. OUT PKIRQL Irql
  14240. );
  14241. DECLSPEC_DEPRECATED_DDK // Use AllocateAdapterChannel
  14242. NTKERNELAPI
  14243. NTSTATUS
  14244. IoAllocateAdapterChannel(
  14245. IN PADAPTER_OBJECT AdapterObject,
  14246. IN PDEVICE_OBJECT DeviceObject,
  14247. IN ULONG NumberOfMapRegisters,
  14248. IN PDRIVER_CONTROL ExecutionRoutine,
  14249. IN PVOID Context
  14250. );
  14251. NTKERNELAPI
  14252. VOID
  14253. IoAllocateController(
  14254. IN PCONTROLLER_OBJECT ControllerObject,
  14255. IN PDEVICE_OBJECT DeviceObject,
  14256. IN PDRIVER_CONTROL ExecutionRoutine,
  14257. IN PVOID Context
  14258. );
  14259. NTKERNELAPI
  14260. NTSTATUS
  14261. IoAllocateDriverObjectExtension(
  14262. IN PDRIVER_OBJECT DriverObject,
  14263. IN PVOID ClientIdentificationAddress,
  14264. IN ULONG DriverObjectExtensionSize,
  14265. OUT PVOID *DriverObjectExtension
  14266. );
  14267. NTKERNELAPI
  14268. PVOID
  14269. IoAllocateErrorLogEntry(
  14270. IN PVOID IoObject,
  14271. IN UCHAR EntrySize
  14272. );
  14273. NTKERNELAPI
  14274. PIRP
  14275. IoAllocateIrp(
  14276. IN CCHAR StackSize,
  14277. IN BOOLEAN ChargeQuota
  14278. );
  14279. NTKERNELAPI
  14280. PMDL
  14281. IoAllocateMdl(
  14282. IN PVOID VirtualAddress,
  14283. IN ULONG Length,
  14284. IN BOOLEAN SecondaryBuffer,
  14285. IN BOOLEAN ChargeQuota,
  14286. IN OUT PIRP Irp OPTIONAL
  14287. );
  14288. //++
  14289. //
  14290. // VOID
  14291. // IoAssignArcName(
  14292. // IN PUNICODE_STRING ArcName,
  14293. // IN PUNICODE_STRING DeviceName
  14294. // )
  14295. //
  14296. // Routine Description:
  14297. //
  14298. // This routine is invoked by drivers of bootable media to create a symbolic
  14299. // link between the ARC name of their device and its NT name. This allows
  14300. // the system to determine which device in the system was actually booted
  14301. // from since the ARC firmware only deals in ARC names, and NT only deals
  14302. // in NT names.
  14303. //
  14304. // Arguments:
  14305. //
  14306. // ArcName - Supplies the Unicode string representing the ARC name.
  14307. //
  14308. // DeviceName - Supplies the name to which the ARCname refers.
  14309. //
  14310. // Return Value:
  14311. //
  14312. // None.
  14313. //
  14314. //--
  14315. #define IoAssignArcName( ArcName, DeviceName ) ( \
  14316. IoCreateSymbolicLink( (ArcName), (DeviceName) ) )
  14317. DECLSPEC_DEPRECATED_DDK // Use Pnp or IoReprtDetectedDevice
  14318. NTKERNELAPI
  14319. NTSTATUS
  14320. IoAssignResources (
  14321. IN PUNICODE_STRING RegistryPath,
  14322. IN PUNICODE_STRING DriverClassName OPTIONAL,
  14323. IN PDRIVER_OBJECT DriverObject,
  14324. IN PDEVICE_OBJECT DeviceObject OPTIONAL,
  14325. IN PIO_RESOURCE_REQUIREMENTS_LIST RequestedResources,
  14326. IN OUT PCM_RESOURCE_LIST *AllocatedResources
  14327. );
  14328. typedef enum _IO_PAGING_PRIORITY {
  14329. IoPagingPriorityInvalid, // Returned if a non-paging IO IRP is passed.
  14330. IoPagingPriorityNormal, // For regular paging IO
  14331. IoPagingPriorityHigh, // For high priority paging IO
  14332. IoPagingPriorityReserved1, // Reserved for future use.
  14333. IoPagingPriorityReserved2 // Reserved for future use.
  14334. } IO_PAGING_PRIORITY;
  14335. NTKERNELAPI
  14336. NTSTATUS
  14337. IoAttachDevice(
  14338. IN PDEVICE_OBJECT SourceDevice,
  14339. IN PUNICODE_STRING TargetDevice,
  14340. OUT PDEVICE_OBJECT *AttachedDevice
  14341. );
  14342. DECLSPEC_DEPRECATED_DDK // Use IoAttachDeviceToDeviceStack
  14343. NTKERNELAPI
  14344. NTSTATUS
  14345. IoAttachDeviceByPointer(
  14346. IN PDEVICE_OBJECT SourceDevice,
  14347. IN PDEVICE_OBJECT TargetDevice
  14348. );
  14349. NTKERNELAPI
  14350. PDEVICE_OBJECT
  14351. IoAttachDeviceToDeviceStack(
  14352. IN PDEVICE_OBJECT SourceDevice,
  14353. IN PDEVICE_OBJECT TargetDevice
  14354. );
  14355. NTKERNELAPI
  14356. PIRP
  14357. IoBuildAsynchronousFsdRequest(
  14358. IN ULONG MajorFunction,
  14359. IN PDEVICE_OBJECT DeviceObject,
  14360. IN OUT PVOID Buffer OPTIONAL,
  14361. IN ULONG Length OPTIONAL,
  14362. IN PLARGE_INTEGER StartingOffset OPTIONAL,
  14363. IN PIO_STATUS_BLOCK IoStatusBlock OPTIONAL
  14364. );
  14365. NTKERNELAPI
  14366. PIRP
  14367. IoBuildDeviceIoControlRequest(
  14368. IN ULONG IoControlCode,
  14369. IN PDEVICE_OBJECT DeviceObject,
  14370. IN PVOID InputBuffer OPTIONAL,
  14371. IN ULONG InputBufferLength,
  14372. OUT PVOID OutputBuffer OPTIONAL,
  14373. IN ULONG OutputBufferLength,
  14374. IN BOOLEAN InternalDeviceIoControl,
  14375. IN PKEVENT Event,
  14376. OUT PIO_STATUS_BLOCK IoStatusBlock
  14377. );
  14378. NTKERNELAPI
  14379. VOID
  14380. IoBuildPartialMdl(
  14381. IN PMDL SourceMdl,
  14382. IN OUT PMDL TargetMdl,
  14383. IN PVOID VirtualAddress,
  14384. IN ULONG Length
  14385. );
  14386. typedef struct _BOOTDISK_INFORMATION {
  14387. LONGLONG BootPartitionOffset;
  14388. LONGLONG SystemPartitionOffset;
  14389. ULONG BootDeviceSignature;
  14390. ULONG SystemDeviceSignature;
  14391. } BOOTDISK_INFORMATION, *PBOOTDISK_INFORMATION;
  14392. //
  14393. // This structure should follow the previous structure field for field.
  14394. //
  14395. typedef struct _BOOTDISK_INFORMATION_EX {
  14396. LONGLONG BootPartitionOffset;
  14397. LONGLONG SystemPartitionOffset;
  14398. ULONG BootDeviceSignature;
  14399. ULONG SystemDeviceSignature;
  14400. GUID BootDeviceGuid;
  14401. GUID SystemDeviceGuid;
  14402. BOOLEAN BootDeviceIsGpt;
  14403. BOOLEAN SystemDeviceIsGpt;
  14404. } BOOTDISK_INFORMATION_EX, *PBOOTDISK_INFORMATION_EX;
  14405. NTKERNELAPI
  14406. NTSTATUS
  14407. IoGetBootDiskInformation(
  14408. IN OUT PBOOTDISK_INFORMATION BootDiskInformation,
  14409. IN ULONG Size
  14410. );
  14411. NTKERNELAPI
  14412. PIRP
  14413. IoBuildSynchronousFsdRequest(
  14414. IN ULONG MajorFunction,
  14415. IN PDEVICE_OBJECT DeviceObject,
  14416. IN OUT PVOID Buffer OPTIONAL,
  14417. IN ULONG Length OPTIONAL,
  14418. IN PLARGE_INTEGER StartingOffset OPTIONAL,
  14419. IN PKEVENT Event,
  14420. OUT PIO_STATUS_BLOCK IoStatusBlock
  14421. );
  14422. NTKERNELAPI
  14423. NTSTATUS
  14424. FASTCALL
  14425. IofCallDriver(
  14426. IN PDEVICE_OBJECT DeviceObject,
  14427. IN OUT PIRP Irp
  14428. );
  14429. #define IoCallDriver(a,b) \
  14430. IofCallDriver(a,b)
  14431. NTKERNELAPI
  14432. BOOLEAN
  14433. IoCancelIrp(
  14434. IN PIRP Irp
  14435. );
  14436. NTKERNELAPI
  14437. NTSTATUS
  14438. IoCheckShareAccess(
  14439. IN ACCESS_MASK DesiredAccess,
  14440. IN ULONG DesiredShareAccess,
  14441. IN OUT PFILE_OBJECT FileObject,
  14442. IN OUT PSHARE_ACCESS ShareAccess,
  14443. IN BOOLEAN Update
  14444. );
  14445. //
  14446. // This value should be returned from completion routines to continue
  14447. // completing the IRP upwards. Otherwise, STATUS_MORE_PROCESSING_REQUIRED
  14448. // should be returned.
  14449. //
  14450. #define STATUS_CONTINUE_COMPLETION STATUS_SUCCESS
  14451. //
  14452. // Completion routines can also use this enumeration in place of status codes.
  14453. //
  14454. typedef enum _IO_COMPLETION_ROUTINE_RESULT {
  14455. ContinueCompletion = STATUS_CONTINUE_COMPLETION,
  14456. StopCompletion = STATUS_MORE_PROCESSING_REQUIRED
  14457. } IO_COMPLETION_ROUTINE_RESULT, *PIO_COMPLETION_ROUTINE_RESULT;
  14458. NTKERNELAPI
  14459. VOID
  14460. FASTCALL
  14461. IofCompleteRequest(
  14462. IN PIRP Irp,
  14463. IN CCHAR PriorityBoost
  14464. );
  14465. #define IoCompleteRequest(a,b) \
  14466. IofCompleteRequest(a,b)
  14467. NTKERNELAPI
  14468. NTSTATUS
  14469. IoConnectInterrupt(
  14470. OUT PKINTERRUPT *InterruptObject,
  14471. IN PKSERVICE_ROUTINE ServiceRoutine,
  14472. IN PVOID ServiceContext,
  14473. IN PKSPIN_LOCK SpinLock OPTIONAL,
  14474. IN ULONG Vector,
  14475. IN KIRQL Irql,
  14476. IN KIRQL SynchronizeIrql,
  14477. IN KINTERRUPT_MODE InterruptMode,
  14478. IN BOOLEAN ShareVector,
  14479. IN KAFFINITY ProcessorEnableMask,
  14480. IN BOOLEAN FloatingSave
  14481. );
  14482. NTKERNELAPI
  14483. PCONTROLLER_OBJECT
  14484. IoCreateController(
  14485. IN ULONG Size
  14486. );
  14487. NTKERNELAPI
  14488. NTSTATUS
  14489. IoCreateDevice(
  14490. IN PDRIVER_OBJECT DriverObject,
  14491. IN ULONG DeviceExtensionSize,
  14492. IN PUNICODE_STRING DeviceName OPTIONAL,
  14493. IN DEVICE_TYPE DeviceType,
  14494. IN ULONG DeviceCharacteristics,
  14495. IN BOOLEAN Exclusive,
  14496. OUT PDEVICE_OBJECT *DeviceObject
  14497. );
  14498. #define WDM_MAJORVERSION 0x01
  14499. #define WDM_MINORVERSION 0x30
  14500. NTKERNELAPI
  14501. BOOLEAN
  14502. IoIsWdmVersionAvailable(
  14503. IN UCHAR MajorVersion,
  14504. IN UCHAR MinorVersion
  14505. );
  14506. NTKERNELAPI
  14507. NTSTATUS
  14508. IoCreateFile(
  14509. OUT PHANDLE FileHandle,
  14510. IN ACCESS_MASK DesiredAccess,
  14511. IN POBJECT_ATTRIBUTES ObjectAttributes,
  14512. OUT PIO_STATUS_BLOCK IoStatusBlock,
  14513. IN PLARGE_INTEGER AllocationSize OPTIONAL,
  14514. IN ULONG FileAttributes,
  14515. IN ULONG ShareAccess,
  14516. IN ULONG Disposition,
  14517. IN ULONG CreateOptions,
  14518. IN PVOID EaBuffer OPTIONAL,
  14519. IN ULONG EaLength,
  14520. IN CREATE_FILE_TYPE CreateFileType,
  14521. IN PVOID ExtraCreateParameters OPTIONAL,
  14522. IN ULONG Options
  14523. );
  14524. NTKERNELAPI
  14525. PKEVENT
  14526. IoCreateNotificationEvent(
  14527. IN PUNICODE_STRING EventName,
  14528. OUT PHANDLE EventHandle
  14529. );
  14530. NTKERNELAPI
  14531. NTSTATUS
  14532. IoCreateSymbolicLink(
  14533. IN PUNICODE_STRING SymbolicLinkName,
  14534. IN PUNICODE_STRING DeviceName
  14535. );
  14536. NTKERNELAPI
  14537. PKEVENT
  14538. IoCreateSynchronizationEvent(
  14539. IN PUNICODE_STRING EventName,
  14540. OUT PHANDLE EventHandle
  14541. );
  14542. NTKERNELAPI
  14543. NTSTATUS
  14544. IoCreateUnprotectedSymbolicLink(
  14545. IN PUNICODE_STRING SymbolicLinkName,
  14546. IN PUNICODE_STRING DeviceName
  14547. );
  14548. //++
  14549. //
  14550. // VOID
  14551. // IoDeassignArcName(
  14552. // IN PUNICODE_STRING ArcName
  14553. // )
  14554. //
  14555. // Routine Description:
  14556. //
  14557. // This routine is invoked by drivers to deassign an ARC name that they
  14558. // created to a device. This is generally only called if the driver is
  14559. // deleting the device object, which means that the driver is probably
  14560. // unloading.
  14561. //
  14562. // Arguments:
  14563. //
  14564. // ArcName - Supplies the ARC name to be removed.
  14565. //
  14566. // Return Value:
  14567. //
  14568. // None.
  14569. //
  14570. //--
  14571. #define IoDeassignArcName( ArcName ) ( \
  14572. IoDeleteSymbolicLink( (ArcName) ) )
  14573. NTKERNELAPI
  14574. VOID
  14575. IoDeleteController(
  14576. IN PCONTROLLER_OBJECT ControllerObject
  14577. );
  14578. NTKERNELAPI
  14579. VOID
  14580. IoDeleteDevice(
  14581. IN PDEVICE_OBJECT DeviceObject
  14582. );
  14583. NTKERNELAPI
  14584. NTSTATUS
  14585. IoDeleteSymbolicLink(
  14586. IN PUNICODE_STRING SymbolicLinkName
  14587. );
  14588. NTKERNELAPI
  14589. VOID
  14590. IoDetachDevice(
  14591. IN OUT PDEVICE_OBJECT TargetDevice
  14592. );
  14593. NTKERNELAPI
  14594. VOID
  14595. IoDisconnectInterrupt(
  14596. IN PKINTERRUPT InterruptObject
  14597. );
  14598. NTKERNELAPI
  14599. VOID
  14600. IoFreeController(
  14601. IN PCONTROLLER_OBJECT ControllerObject
  14602. );
  14603. NTKERNELAPI
  14604. VOID
  14605. IoFreeIrp(
  14606. IN PIRP Irp
  14607. );
  14608. NTKERNELAPI
  14609. VOID
  14610. IoFreeMdl(
  14611. IN PMDL Mdl
  14612. );
  14613. NTKERNELAPI
  14614. PDEVICE_OBJECT
  14615. IoGetAttachedDeviceReference(
  14616. IN PDEVICE_OBJECT DeviceObject
  14617. );
  14618. NTKERNELAPI
  14619. PCONFIGURATION_INFORMATION
  14620. IoGetConfigurationInformation( VOID );
  14621. //++
  14622. //
  14623. // PIO_STACK_LOCATION
  14624. // IoGetCurrentIrpStackLocation(
  14625. // IN PIRP Irp
  14626. // )
  14627. //
  14628. // Routine Description:
  14629. //
  14630. // This routine is invoked to return a pointer to the current stack location
  14631. // in an I/O Request Packet (IRP).
  14632. //
  14633. // Arguments:
  14634. //
  14635. // Irp - Pointer to the I/O Request Packet.
  14636. //
  14637. // Return Value:
  14638. //
  14639. // The function value is a pointer to the current stack location in the
  14640. // packet.
  14641. //
  14642. //--
  14643. #define IoGetCurrentIrpStackLocation( Irp ) ( (Irp)->Tail.Overlay.CurrentStackLocation )
  14644. NTKERNELAPI
  14645. PDEVICE_OBJECT
  14646. IoGetDeviceToVerify(
  14647. IN PETHREAD Thread
  14648. );
  14649. NTKERNELAPI
  14650. PVOID
  14651. IoGetDriverObjectExtension(
  14652. IN PDRIVER_OBJECT DriverObject,
  14653. IN PVOID ClientIdentificationAddress
  14654. );
  14655. NTKERNELAPI
  14656. PEPROCESS
  14657. IoGetCurrentProcess(
  14658. VOID
  14659. );
  14660. NTKERNELAPI
  14661. NTSTATUS
  14662. IoGetDeviceObjectPointer(
  14663. IN PUNICODE_STRING ObjectName,
  14664. IN ACCESS_MASK DesiredAccess,
  14665. OUT PFILE_OBJECT *FileObject,
  14666. OUT PDEVICE_OBJECT *DeviceObject
  14667. );
  14668. NTKERNELAPI
  14669. struct _DMA_ADAPTER *
  14670. IoGetDmaAdapter(
  14671. IN PDEVICE_OBJECT PhysicalDeviceObject, OPTIONAL // required for PnP drivers
  14672. IN struct _DEVICE_DESCRIPTION *DeviceDescription,
  14673. IN OUT PULONG NumberOfMapRegisters
  14674. );
  14675. NTKERNELAPI
  14676. BOOLEAN
  14677. IoForwardIrpSynchronously(
  14678. IN PDEVICE_OBJECT DeviceObject,
  14679. IN PIRP Irp
  14680. );
  14681. #define IoForwardAndCatchIrp IoForwardIrpSynchronously
  14682. NTKERNELAPI
  14683. PGENERIC_MAPPING
  14684. IoGetFileObjectGenericMapping(
  14685. VOID
  14686. );
  14687. //++
  14688. //
  14689. // ULONG
  14690. // IoGetFunctionCodeFromCtlCode(
  14691. // IN ULONG ControlCode
  14692. // )
  14693. //
  14694. // Routine Description:
  14695. //
  14696. // This routine extracts the function code from IOCTL and FSCTL function
  14697. // control codes.
  14698. // This routine should only be used by kernel mode code.
  14699. //
  14700. // Arguments:
  14701. //
  14702. // ControlCode - A function control code (IOCTL or FSCTL) from which the
  14703. // function code must be extracted.
  14704. //
  14705. // Return Value:
  14706. //
  14707. // The extracted function code.
  14708. //
  14709. // Note:
  14710. //
  14711. // The CTL_CODE macro, used to create IOCTL and FSCTL function control
  14712. // codes, is defined in ntioapi.h
  14713. //
  14714. //--
  14715. #define IoGetFunctionCodeFromCtlCode( ControlCode ) (\
  14716. ( ControlCode >> 2) & 0x00000FFF )
  14717. NTKERNELAPI
  14718. PVOID
  14719. IoGetInitialStack(
  14720. VOID
  14721. );
  14722. NTKERNELAPI
  14723. VOID
  14724. IoGetStackLimits (
  14725. OUT PULONG_PTR LowLimit,
  14726. OUT PULONG_PTR HighLimit
  14727. );
  14728. //
  14729. // The following function is used to tell the caller how much stack is available
  14730. //
  14731. FORCEINLINE
  14732. ULONG_PTR
  14733. IoGetRemainingStackSize (
  14734. VOID
  14735. )
  14736. {
  14737. ULONG_PTR Top;
  14738. ULONG_PTR Bottom;
  14739. IoGetStackLimits( &Bottom, &Top );
  14740. return((ULONG_PTR)(&Top) - Bottom );
  14741. }
  14742. //++
  14743. //
  14744. // PIO_STACK_LOCATION
  14745. // IoGetNextIrpStackLocation(
  14746. // IN PIRP Irp
  14747. // )
  14748. //
  14749. // Routine Description:
  14750. //
  14751. // This routine is invoked to return a pointer to the next stack location
  14752. // in an I/O Request Packet (IRP).
  14753. //
  14754. // Arguments:
  14755. //
  14756. // Irp - Pointer to the I/O Request Packet.
  14757. //
  14758. // Return Value:
  14759. //
  14760. // The function value is a pointer to the next stack location in the packet.
  14761. //
  14762. //--
  14763. #define IoGetNextIrpStackLocation( Irp ) (\
  14764. (Irp)->Tail.Overlay.CurrentStackLocation - 1 )
  14765. NTKERNELAPI
  14766. PDEVICE_OBJECT
  14767. IoGetRelatedDeviceObject(
  14768. IN PFILE_OBJECT FileObject
  14769. );
  14770. //++
  14771. //
  14772. // VOID
  14773. // IoInitializeDpcRequest(
  14774. // IN PDEVICE_OBJECT DeviceObject,
  14775. // IN PIO_DPC_ROUTINE DpcRoutine
  14776. // )
  14777. //
  14778. // Routine Description:
  14779. //
  14780. // This routine is invoked to initialize the DPC in a device object for a
  14781. // device driver during its initialization routine. The DPC is used later
  14782. // when the driver interrupt service routine requests that a DPC routine
  14783. // be queued for later execution.
  14784. //
  14785. // Arguments:
  14786. //
  14787. // DeviceObject - Pointer to the device object that the request is for.
  14788. //
  14789. // DpcRoutine - Address of the driver's DPC routine to be executed when
  14790. // the DPC is dequeued for processing.
  14791. //
  14792. // Return Value:
  14793. //
  14794. // None.
  14795. //
  14796. //--
  14797. #define IoInitializeDpcRequest( DeviceObject, DpcRoutine ) (\
  14798. KeInitializeDpc( &(DeviceObject)->Dpc, \
  14799. (PKDEFERRED_ROUTINE) (DpcRoutine), \
  14800. (DeviceObject) ) )
  14801. NTKERNELAPI
  14802. VOID
  14803. IoInitializeIrp(
  14804. IN OUT PIRP Irp,
  14805. IN USHORT PacketSize,
  14806. IN CCHAR StackSize
  14807. );
  14808. NTKERNELAPI
  14809. NTSTATUS
  14810. IoInitializeTimer(
  14811. IN PDEVICE_OBJECT DeviceObject,
  14812. IN PIO_TIMER_ROUTINE TimerRoutine,
  14813. IN PVOID Context
  14814. );
  14815. NTKERNELAPI
  14816. VOID
  14817. IoReuseIrp(
  14818. IN OUT PIRP Irp,
  14819. IN NTSTATUS Iostatus
  14820. );
  14821. NTKERNELAPI
  14822. VOID
  14823. IoCancelFileOpen(
  14824. IN PDEVICE_OBJECT DeviceObject,
  14825. IN PFILE_OBJECT FileObject
  14826. );
  14827. //++
  14828. //
  14829. // BOOLEAN
  14830. // IoIsErrorUserInduced(
  14831. // IN NTSTATUS Status
  14832. // )
  14833. //
  14834. // Routine Description:
  14835. //
  14836. // This routine is invoked to determine if an error was as a
  14837. // result of user actions. Typically these error are related
  14838. // to removable media and will result in a pop-up.
  14839. //
  14840. // Arguments:
  14841. //
  14842. // Status - The status value to check.
  14843. //
  14844. // Return Value:
  14845. // The function value is TRUE if the user induced the error,
  14846. // otherwise FALSE is returned.
  14847. //
  14848. //--
  14849. #define IoIsErrorUserInduced( Status ) ((BOOLEAN) \
  14850. (((Status) == STATUS_DEVICE_NOT_READY) || \
  14851. ((Status) == STATUS_IO_TIMEOUT) || \
  14852. ((Status) == STATUS_MEDIA_WRITE_PROTECTED) || \
  14853. ((Status) == STATUS_NO_MEDIA_IN_DEVICE) || \
  14854. ((Status) == STATUS_VERIFY_REQUIRED) || \
  14855. ((Status) == STATUS_UNRECOGNIZED_MEDIA) || \
  14856. ((Status) == STATUS_WRONG_VOLUME)))
  14857. NTKERNELAPI
  14858. PIRP
  14859. IoMakeAssociatedIrp(
  14860. IN PIRP Irp,
  14861. IN CCHAR StackSize
  14862. );
  14863. //++
  14864. //
  14865. // VOID
  14866. // IoMarkIrpPending(
  14867. // IN OUT PIRP Irp
  14868. // )
  14869. //
  14870. // Routine Description:
  14871. //
  14872. // This routine marks the specified I/O Request Packet (IRP) to indicate
  14873. // that an initial status of STATUS_PENDING was returned to the caller.
  14874. // This is used so that I/O completion can determine whether or not to
  14875. // fully complete the I/O operation requested by the packet.
  14876. //
  14877. // Arguments:
  14878. //
  14879. // Irp - Pointer to the I/O Request Packet to be marked pending.
  14880. //
  14881. // Return Value:
  14882. //
  14883. // None.
  14884. //
  14885. //--
  14886. #define IoMarkIrpPending( Irp ) ( \
  14887. IoGetCurrentIrpStackLocation( (Irp) )->Control |= SL_PENDING_RETURNED )
  14888. DECLSPEC_DEPRECATED_DDK // Use IoGetDeviceProperty
  14889. NTKERNELAPI
  14890. NTSTATUS
  14891. IoQueryDeviceDescription(
  14892. IN PINTERFACE_TYPE BusType OPTIONAL,
  14893. IN PULONG BusNumber OPTIONAL,
  14894. IN PCONFIGURATION_TYPE ControllerType OPTIONAL,
  14895. IN PULONG ControllerNumber OPTIONAL,
  14896. IN PCONFIGURATION_TYPE PeripheralType OPTIONAL,
  14897. IN PULONG PeripheralNumber OPTIONAL,
  14898. IN PIO_QUERY_DEVICE_ROUTINE CalloutRoutine,
  14899. IN PVOID Context
  14900. );
  14901. NTKERNELAPI
  14902. VOID
  14903. IoRaiseHardError(
  14904. IN PIRP Irp,
  14905. IN PVPB Vpb OPTIONAL,
  14906. IN PDEVICE_OBJECT RealDeviceObject
  14907. );
  14908. NTKERNELAPI
  14909. BOOLEAN
  14910. IoRaiseInformationalHardError(
  14911. IN NTSTATUS ErrorStatus,
  14912. IN PUNICODE_STRING String OPTIONAL,
  14913. IN PKTHREAD Thread OPTIONAL
  14914. );
  14915. NTKERNELAPI
  14916. BOOLEAN
  14917. IoSetThreadHardErrorMode(
  14918. IN BOOLEAN EnableHardErrors
  14919. );
  14920. NTKERNELAPI
  14921. VOID
  14922. IoRegisterBootDriverReinitialization(
  14923. IN PDRIVER_OBJECT DriverObject,
  14924. IN PDRIVER_REINITIALIZE DriverReinitializationRoutine,
  14925. IN PVOID Context
  14926. );
  14927. NTKERNELAPI
  14928. VOID
  14929. IoRegisterDriverReinitialization(
  14930. IN PDRIVER_OBJECT DriverObject,
  14931. IN PDRIVER_REINITIALIZE DriverReinitializationRoutine,
  14932. IN PVOID Context
  14933. );
  14934. NTKERNELAPI
  14935. NTSTATUS
  14936. IoRegisterShutdownNotification(
  14937. IN PDEVICE_OBJECT DeviceObject
  14938. );
  14939. NTKERNELAPI
  14940. NTSTATUS
  14941. IoRegisterLastChanceShutdownNotification(
  14942. IN PDEVICE_OBJECT DeviceObject
  14943. );
  14944. NTKERNELAPI
  14945. VOID
  14946. IoReleaseCancelSpinLock(
  14947. IN KIRQL Irql
  14948. );
  14949. NTKERNELAPI
  14950. VOID
  14951. IoRemoveShareAccess(
  14952. IN PFILE_OBJECT FileObject,
  14953. IN OUT PSHARE_ACCESS ShareAccess
  14954. );
  14955. DECLSPEC_DEPRECATED_DDK // Use IoReportResourceForDetection
  14956. NTKERNELAPI
  14957. NTSTATUS
  14958. IoReportResourceUsage(
  14959. IN PUNICODE_STRING DriverClassName OPTIONAL,
  14960. IN PDRIVER_OBJECT DriverObject,
  14961. IN PCM_RESOURCE_LIST DriverList OPTIONAL,
  14962. IN ULONG DriverListSize OPTIONAL,
  14963. IN PDEVICE_OBJECT DeviceObject,
  14964. IN PCM_RESOURCE_LIST DeviceList OPTIONAL,
  14965. IN ULONG DeviceListSize OPTIONAL,
  14966. IN BOOLEAN OverrideConflict,
  14967. OUT PBOOLEAN ConflictDetected
  14968. );
  14969. //++
  14970. //
  14971. // VOID
  14972. // IoRequestDpc(
  14973. // IN PDEVICE_OBJECT DeviceObject,
  14974. // IN PIRP Irp,
  14975. // IN PVOID Context
  14976. // )
  14977. //
  14978. // Routine Description:
  14979. //
  14980. // This routine is invoked by the device driver's interrupt service routine
  14981. // to request that a DPC routine be queued for later execution at a lower
  14982. // IRQL.
  14983. //
  14984. // Arguments:
  14985. //
  14986. // DeviceObject - Device object for which the request is being processed.
  14987. //
  14988. // Irp - Pointer to the current I/O Request Packet (IRP) for the specified
  14989. // device.
  14990. //
  14991. // Context - Provides a general context parameter to be passed to the
  14992. // DPC routine.
  14993. //
  14994. // Return Value:
  14995. //
  14996. // None.
  14997. //
  14998. //--
  14999. #define IoRequestDpc( DeviceObject, Irp, Context ) ( \
  15000. KeInsertQueueDpc( &(DeviceObject)->Dpc, (Irp), (Context) ) )
  15001. //++
  15002. //
  15003. // PDRIVER_CANCEL
  15004. // IoSetCancelRoutine(
  15005. // IN PIRP Irp,
  15006. // IN PDRIVER_CANCEL CancelRoutine
  15007. // )
  15008. //
  15009. // Routine Description:
  15010. //
  15011. // This routine is invoked to set the address of a cancel routine which
  15012. // is to be invoked when an I/O packet has been canceled.
  15013. //
  15014. // Arguments:
  15015. //
  15016. // Irp - Pointer to the I/O Request Packet itself.
  15017. //
  15018. // CancelRoutine - Address of the cancel routine that is to be invoked
  15019. // if the IRP is cancelled.
  15020. //
  15021. // Return Value:
  15022. //
  15023. // Previous value of CancelRoutine field in the IRP.
  15024. //
  15025. //--
  15026. #define IoSetCancelRoutine( Irp, NewCancelRoutine ) ( \
  15027. (PDRIVER_CANCEL) (ULONG_PTR) InterlockedExchangePointer( (PVOID *) &(Irp)->CancelRoutine, (PVOID) (ULONG_PTR)(NewCancelRoutine) ) )
  15028. //++
  15029. //
  15030. // VOID
  15031. // IoSetCompletionRoutine(
  15032. // IN PIRP Irp,
  15033. // IN PIO_COMPLETION_ROUTINE CompletionRoutine,
  15034. // IN PVOID Context,
  15035. // IN BOOLEAN InvokeOnSuccess,
  15036. // IN BOOLEAN InvokeOnError,
  15037. // IN BOOLEAN InvokeOnCancel
  15038. // )
  15039. //
  15040. // Routine Description:
  15041. //
  15042. // This routine is invoked to set the address of a completion routine which
  15043. // is to be invoked when an I/O packet has been completed by a lower-level
  15044. // driver.
  15045. //
  15046. // Arguments:
  15047. //
  15048. // Irp - Pointer to the I/O Request Packet itself.
  15049. //
  15050. // CompletionRoutine - Address of the completion routine that is to be
  15051. // invoked once the next level driver completes the packet.
  15052. //
  15053. // Context - Specifies a context parameter to be passed to the completion
  15054. // routine.
  15055. //
  15056. // InvokeOnSuccess - Specifies that the completion routine is invoked when the
  15057. // operation is successfully completed.
  15058. //
  15059. // InvokeOnError - Specifies that the completion routine is invoked when the
  15060. // operation completes with an error status.
  15061. //
  15062. // InvokeOnCancel - Specifies that the completion routine is invoked when the
  15063. // operation is being canceled.
  15064. //
  15065. // Return Value:
  15066. //
  15067. // None.
  15068. //
  15069. //--
  15070. #define IoSetCompletionRoutine( Irp, Routine, CompletionContext, Success, Error, Cancel ) { \
  15071. PIO_STACK_LOCATION __irpSp; \
  15072. ASSERT( (Success) | (Error) | (Cancel) ? (Routine) != NULL : TRUE ); \
  15073. __irpSp = IoGetNextIrpStackLocation( (Irp) ); \
  15074. __irpSp->CompletionRoutine = (Routine); \
  15075. __irpSp->Context = (CompletionContext); \
  15076. __irpSp->Control = 0; \
  15077. if ((Success)) { __irpSp->Control = SL_INVOKE_ON_SUCCESS; } \
  15078. if ((Error)) { __irpSp->Control |= SL_INVOKE_ON_ERROR; } \
  15079. if ((Cancel)) { __irpSp->Control |= SL_INVOKE_ON_CANCEL; } }
  15080. NTSTATUS
  15081. IoSetCompletionRoutineEx(
  15082. IN PDEVICE_OBJECT DeviceObject,
  15083. IN PIRP Irp,
  15084. IN PIO_COMPLETION_ROUTINE CompletionRoutine,
  15085. IN PVOID Context,
  15086. IN BOOLEAN InvokeOnSuccess,
  15087. IN BOOLEAN InvokeOnError,
  15088. IN BOOLEAN InvokeOnCancel
  15089. );
  15090. NTKERNELAPI
  15091. VOID
  15092. IoSetHardErrorOrVerifyDevice(
  15093. IN PIRP Irp,
  15094. IN PDEVICE_OBJECT DeviceObject
  15095. );
  15096. //++
  15097. //
  15098. // VOID
  15099. // IoSetNextIrpStackLocation (
  15100. // IN OUT PIRP Irp
  15101. // )
  15102. //
  15103. // Routine Description:
  15104. //
  15105. // This routine is invoked to set the current IRP stack location to
  15106. // the next stack location, i.e. it "pushes" the stack.
  15107. //
  15108. // Arguments:
  15109. //
  15110. // Irp - Pointer to the I/O Request Packet (IRP).
  15111. //
  15112. // Return Value:
  15113. //
  15114. // None.
  15115. //
  15116. //--
  15117. #define IoSetNextIrpStackLocation( Irp ) { \
  15118. (Irp)->CurrentLocation--; \
  15119. (Irp)->Tail.Overlay.CurrentStackLocation--; }
  15120. //++
  15121. //
  15122. // VOID
  15123. // IoCopyCurrentIrpStackLocationToNext(
  15124. // IN PIRP Irp
  15125. // )
  15126. //
  15127. // Routine Description:
  15128. //
  15129. // This routine is invoked to copy the IRP stack arguments and file
  15130. // pointer from the current IrpStackLocation to the next
  15131. // in an I/O Request Packet (IRP).
  15132. //
  15133. // If the caller wants to call IoCallDriver with a completion routine
  15134. // but does not wish to change the arguments otherwise,
  15135. // the caller first calls IoCopyCurrentIrpStackLocationToNext,
  15136. // then IoSetCompletionRoutine, then IoCallDriver.
  15137. //
  15138. // Arguments:
  15139. //
  15140. // Irp - Pointer to the I/O Request Packet.
  15141. //
  15142. // Return Value:
  15143. //
  15144. // None.
  15145. //
  15146. //--
  15147. #define IoCopyCurrentIrpStackLocationToNext( Irp ) { \
  15148. PIO_STACK_LOCATION __irpSp; \
  15149. PIO_STACK_LOCATION __nextIrpSp; \
  15150. __irpSp = IoGetCurrentIrpStackLocation( (Irp) ); \
  15151. __nextIrpSp = IoGetNextIrpStackLocation( (Irp) ); \
  15152. RtlCopyMemory( __nextIrpSp, __irpSp, FIELD_OFFSET(IO_STACK_LOCATION, CompletionRoutine)); \
  15153. __nextIrpSp->Control = 0; }
  15154. //++
  15155. //
  15156. // VOID
  15157. // IoSkipCurrentIrpStackLocation (
  15158. // IN PIRP Irp
  15159. // )
  15160. //
  15161. // Routine Description:
  15162. //
  15163. // This routine is invoked to increment the current stack location of
  15164. // a given IRP.
  15165. //
  15166. // If the caller wishes to call the next driver in a stack, and does not
  15167. // wish to change the arguments, nor does he wish to set a completion
  15168. // routine, then the caller first calls IoSkipCurrentIrpStackLocation
  15169. // and the calls IoCallDriver.
  15170. //
  15171. // Arguments:
  15172. //
  15173. // Irp - Pointer to the I/O Request Packet.
  15174. //
  15175. // Return Value:
  15176. //
  15177. // None
  15178. //
  15179. //--
  15180. #define IoSkipCurrentIrpStackLocation( Irp ) { \
  15181. (Irp)->CurrentLocation++; \
  15182. (Irp)->Tail.Overlay.CurrentStackLocation++; }
  15183. NTKERNELAPI
  15184. VOID
  15185. IoSetShareAccess(
  15186. IN ACCESS_MASK DesiredAccess,
  15187. IN ULONG DesiredShareAccess,
  15188. IN OUT PFILE_OBJECT FileObject,
  15189. OUT PSHARE_ACCESS ShareAccess
  15190. );
  15191. typedef struct _IO_REMOVE_LOCK_TRACKING_BLOCK * PIO_REMOVE_LOCK_TRACKING_BLOCK;
  15192. typedef struct _IO_REMOVE_LOCK_COMMON_BLOCK {
  15193. BOOLEAN Removed;
  15194. BOOLEAN Reserved [3];
  15195. LONG IoCount;
  15196. KEVENT RemoveEvent;
  15197. } IO_REMOVE_LOCK_COMMON_BLOCK;
  15198. typedef struct _IO_REMOVE_LOCK_DBG_BLOCK {
  15199. LONG Signature;
  15200. ULONG HighWatermark;
  15201. LONGLONG MaxLockedTicks;
  15202. LONG AllocateTag;
  15203. LIST_ENTRY LockList;
  15204. KSPIN_LOCK Spin;
  15205. LONG LowMemoryCount;
  15206. ULONG Reserved1[4];
  15207. PVOID Reserved2;
  15208. PIO_REMOVE_LOCK_TRACKING_BLOCK Blocks;
  15209. } IO_REMOVE_LOCK_DBG_BLOCK;
  15210. typedef struct _IO_REMOVE_LOCK {
  15211. IO_REMOVE_LOCK_COMMON_BLOCK Common;
  15212. #if DBG
  15213. IO_REMOVE_LOCK_DBG_BLOCK Dbg;
  15214. #endif
  15215. } IO_REMOVE_LOCK, *PIO_REMOVE_LOCK;
  15216. #define IoInitializeRemoveLock(Lock, Tag, Maxmin, HighWater) \
  15217. IoInitializeRemoveLockEx (Lock, Tag, Maxmin, HighWater, sizeof (IO_REMOVE_LOCK))
  15218. NTSYSAPI
  15219. VOID
  15220. NTAPI
  15221. IoInitializeRemoveLockEx(
  15222. IN PIO_REMOVE_LOCK Lock,
  15223. IN ULONG AllocateTag, // Used only on checked kernels
  15224. IN ULONG MaxLockedMinutes, // Used only on checked kernels
  15225. IN ULONG HighWatermark, // Used only on checked kernels
  15226. IN ULONG RemlockSize // are we checked or free
  15227. );
  15228. //
  15229. // Initialize a remove lock.
  15230. //
  15231. // Note: Allocation for remove locks needs to be within the device extension,
  15232. // so that the memory for this structure stays allocated until such time as the
  15233. // device object itself is deallocated.
  15234. //
  15235. #define IoAcquireRemoveLock(RemoveLock, Tag) \
  15236. IoAcquireRemoveLockEx(RemoveLock, Tag, __FILE__, __LINE__, sizeof (IO_REMOVE_LOCK))
  15237. NTSYSAPI
  15238. NTSTATUS
  15239. NTAPI
  15240. IoAcquireRemoveLockEx (
  15241. IN PIO_REMOVE_LOCK RemoveLock,
  15242. IN OPTIONAL PVOID Tag, // Optional
  15243. IN PCSTR File,
  15244. IN ULONG Line,
  15245. IN ULONG RemlockSize // are we checked or free
  15246. );
  15247. //
  15248. // Routine Description:
  15249. //
  15250. // This routine is called to acquire the remove lock for a device object.
  15251. // While the lock is held, the caller can assume that no pending pnp REMOVE
  15252. // requests will be completed.
  15253. //
  15254. // The lock should be acquired immediately upon entering a dispatch routine.
  15255. // It should also be acquired before creating any new reference to the
  15256. // device object if there's a chance of releasing the reference before the
  15257. // new one is done, in addition to references to the driver code itself,
  15258. // which is removed from memory when the last device object goes.
  15259. //
  15260. // Arguments:
  15261. //
  15262. // RemoveLock - A pointer to an initialized REMOVE_LOCK structure.
  15263. //
  15264. // Tag - Used for tracking lock allocation and release. The same tag
  15265. // specified when acquiring the lock must be used to release the lock.
  15266. // Tags are only checked in checked versions of the driver.
  15267. //
  15268. // File - set to __FILE__ as the location in the code where the lock was taken.
  15269. //
  15270. // Line - set to __LINE__.
  15271. //
  15272. // Return Value:
  15273. //
  15274. // Returns whether or not the remove lock was obtained.
  15275. // If successful the caller should continue with work calling
  15276. // IoReleaseRemoveLock when finished.
  15277. //
  15278. // If not successful the lock was not obtained. The caller should abort the
  15279. // work but not call IoReleaseRemoveLock.
  15280. //
  15281. #define IoReleaseRemoveLock(RemoveLock, Tag) \
  15282. IoReleaseRemoveLockEx(RemoveLock, Tag, sizeof (IO_REMOVE_LOCK))
  15283. NTSYSAPI
  15284. VOID
  15285. NTAPI
  15286. IoReleaseRemoveLockEx(
  15287. IN PIO_REMOVE_LOCK RemoveLock,
  15288. IN PVOID Tag, // Optional
  15289. IN ULONG RemlockSize // are we checked or free
  15290. );
  15291. //
  15292. //
  15293. // Routine Description:
  15294. //
  15295. // This routine is called to release the remove lock on the device object. It
  15296. // must be called when finished using a previously locked reference to the
  15297. // device object. If an Tag was specified when acquiring the lock then the
  15298. // same Tag must be specified when releasing the lock.
  15299. //
  15300. // When the lock count reduces to zero, this routine will signal the waiting
  15301. // event to release the waiting thread deleting the device object protected
  15302. // by this lock.
  15303. //
  15304. // Arguments:
  15305. //
  15306. // DeviceObject - the device object to lock
  15307. //
  15308. // Tag - The TAG (if any) specified when acquiring the lock. This is used
  15309. // for lock tracking purposes
  15310. //
  15311. // Return Value:
  15312. //
  15313. // none
  15314. //
  15315. #define IoReleaseRemoveLockAndWait(RemoveLock, Tag) \
  15316. IoReleaseRemoveLockAndWaitEx(RemoveLock, Tag, sizeof (IO_REMOVE_LOCK))
  15317. NTSYSAPI
  15318. VOID
  15319. NTAPI
  15320. IoReleaseRemoveLockAndWaitEx(
  15321. IN PIO_REMOVE_LOCK RemoveLock,
  15322. IN PVOID Tag,
  15323. IN ULONG RemlockSize // are we checked or free
  15324. );
  15325. //
  15326. //
  15327. // Routine Description:
  15328. //
  15329. // This routine is called when the client would like to delete the
  15330. // remove-locked resource. This routine will block until all the remove
  15331. // locks have released.
  15332. //
  15333. // This routine MUST be called after acquiring the lock.
  15334. //
  15335. // Arguments:
  15336. //
  15337. // RemoveLock
  15338. //
  15339. // Return Value:
  15340. //
  15341. // none
  15342. //
  15343. //++
  15344. //
  15345. // USHORT
  15346. // IoSizeOfIrp(
  15347. // IN CCHAR StackSize
  15348. // )
  15349. //
  15350. // Routine Description:
  15351. //
  15352. // Determines the size of an IRP given the number of stack locations
  15353. // the IRP will have.
  15354. //
  15355. // Arguments:
  15356. //
  15357. // StackSize - Number of stack locations for the IRP.
  15358. //
  15359. // Return Value:
  15360. //
  15361. // Size in bytes of the IRP.
  15362. //
  15363. //--
  15364. #define IoSizeOfIrp( StackSize ) \
  15365. ((USHORT) (sizeof( IRP ) + ((StackSize) * (sizeof( IO_STACK_LOCATION )))))
  15366. NTKERNELAPI
  15367. VOID
  15368. IoStartNextPacket(
  15369. IN PDEVICE_OBJECT DeviceObject,
  15370. IN BOOLEAN Cancelable
  15371. );
  15372. NTKERNELAPI
  15373. VOID
  15374. IoStartNextPacketByKey(
  15375. IN PDEVICE_OBJECT DeviceObject,
  15376. IN BOOLEAN Cancelable,
  15377. IN ULONG Key
  15378. );
  15379. NTKERNELAPI
  15380. VOID
  15381. IoStartPacket(
  15382. IN PDEVICE_OBJECT DeviceObject,
  15383. IN PIRP Irp,
  15384. IN PULONG Key OPTIONAL,
  15385. IN PDRIVER_CANCEL CancelFunction OPTIONAL
  15386. );
  15387. VOID
  15388. IoSetStartIoAttributes(
  15389. IN PDEVICE_OBJECT DeviceObject,
  15390. IN BOOLEAN DeferredStartIo,
  15391. IN BOOLEAN NonCancelable
  15392. );
  15393. NTKERNELAPI
  15394. VOID
  15395. IoStartTimer(
  15396. IN PDEVICE_OBJECT DeviceObject
  15397. );
  15398. NTKERNELAPI
  15399. VOID
  15400. IoStopTimer(
  15401. IN PDEVICE_OBJECT DeviceObject
  15402. );
  15403. NTKERNELAPI
  15404. VOID
  15405. IoUnregisterShutdownNotification(
  15406. IN PDEVICE_OBJECT DeviceObject
  15407. );
  15408. NTKERNELAPI
  15409. VOID
  15410. IoUpdateShareAccess(
  15411. IN PFILE_OBJECT FileObject,
  15412. IN OUT PSHARE_ACCESS ShareAccess
  15413. );
  15414. NTKERNELAPI
  15415. VOID
  15416. IoWriteErrorLogEntry(
  15417. IN PVOID ElEntry
  15418. );
  15419. typedef struct _IO_WORKITEM *PIO_WORKITEM;
  15420. typedef
  15421. VOID
  15422. (*PIO_WORKITEM_ROUTINE) (
  15423. IN PDEVICE_OBJECT DeviceObject,
  15424. IN PVOID Context
  15425. );
  15426. PIO_WORKITEM
  15427. IoAllocateWorkItem(
  15428. PDEVICE_OBJECT DeviceObject
  15429. );
  15430. VOID
  15431. IoFreeWorkItem(
  15432. PIO_WORKITEM IoWorkItem
  15433. );
  15434. VOID
  15435. IoQueueWorkItem(
  15436. IN PIO_WORKITEM IoWorkItem,
  15437. IN PIO_WORKITEM_ROUTINE WorkerRoutine,
  15438. IN WORK_QUEUE_TYPE QueueType,
  15439. IN PVOID Context
  15440. );
  15441. NTKERNELAPI
  15442. NTSTATUS
  15443. IoWMIRegistrationControl(
  15444. IN PDEVICE_OBJECT DeviceObject,
  15445. IN ULONG Action
  15446. );
  15447. //
  15448. // Action code for IoWMIRegistrationControl api
  15449. //
  15450. #define WMIREG_ACTION_REGISTER 1
  15451. #define WMIREG_ACTION_DEREGISTER 2
  15452. #define WMIREG_ACTION_REREGISTER 3
  15453. #define WMIREG_ACTION_UPDATE_GUIDS 4
  15454. #define WMIREG_ACTION_BLOCK_IRPS 5
  15455. //
  15456. // Code passed in IRP_MN_REGINFO WMI irp
  15457. //
  15458. #define WMIREGISTER 0
  15459. #define WMIUPDATE 1
  15460. NTKERNELAPI
  15461. NTSTATUS
  15462. IoWMIAllocateInstanceIds(
  15463. IN GUID *Guid,
  15464. IN ULONG InstanceCount,
  15465. OUT ULONG *FirstInstanceId
  15466. );
  15467. NTKERNELAPI
  15468. NTSTATUS
  15469. IoWMISuggestInstanceName(
  15470. IN PDEVICE_OBJECT PhysicalDeviceObject OPTIONAL,
  15471. IN PUNICODE_STRING SymbolicLinkName OPTIONAL,
  15472. IN BOOLEAN CombineNames,
  15473. OUT PUNICODE_STRING SuggestedInstanceName
  15474. );
  15475. NTKERNELAPI
  15476. NTSTATUS
  15477. IoWMIWriteEvent(
  15478. IN PVOID WnodeEventItem
  15479. );
  15480. #if defined(_WIN64)
  15481. NTKERNELAPI
  15482. ULONG IoWMIDeviceObjectToProviderId(
  15483. PDEVICE_OBJECT DeviceObject
  15484. );
  15485. #else
  15486. #define IoWMIDeviceObjectToProviderId(DeviceObject) ((ULONG)(DeviceObject))
  15487. #endif
  15488. NTKERNELAPI
  15489. NTSTATUS IoWMIOpenBlock(
  15490. IN GUID *DataBlockGuid,
  15491. IN ULONG DesiredAccess,
  15492. OUT PVOID *DataBlockObject
  15493. );
  15494. NTKERNELAPI
  15495. NTSTATUS IoWMIQueryAllData(
  15496. IN PVOID DataBlockObject,
  15497. IN OUT ULONG *InOutBufferSize,
  15498. OUT /* non paged */ PVOID OutBuffer
  15499. );
  15500. NTKERNELAPI
  15501. NTSTATUS
  15502. IoWMIQueryAllDataMultiple(
  15503. IN PVOID *DataBlockObjectList,
  15504. IN ULONG ObjectCount,
  15505. IN OUT ULONG *InOutBufferSize,
  15506. OUT /* non paged */ PVOID OutBuffer
  15507. );
  15508. NTKERNELAPI
  15509. NTSTATUS
  15510. IoWMIQuerySingleInstance(
  15511. IN PVOID DataBlockObject,
  15512. IN PUNICODE_STRING InstanceName,
  15513. IN OUT ULONG *InOutBufferSize,
  15514. OUT /* non paged */ PVOID OutBuffer
  15515. );
  15516. NTKERNELAPI
  15517. NTSTATUS
  15518. IoWMIQuerySingleInstanceMultiple(
  15519. IN PVOID *DataBlockObjectList,
  15520. IN PUNICODE_STRING InstanceNames,
  15521. IN ULONG ObjectCount,
  15522. IN OUT ULONG *InOutBufferSize,
  15523. OUT /* non paged */ PVOID OutBuffer
  15524. );
  15525. NTKERNELAPI
  15526. NTSTATUS
  15527. IoWMISetSingleInstance(
  15528. IN PVOID DataBlockObject,
  15529. IN PUNICODE_STRING InstanceName,
  15530. IN ULONG Version,
  15531. IN ULONG ValueBufferSize,
  15532. IN PVOID ValueBuffer
  15533. );
  15534. NTKERNELAPI
  15535. NTSTATUS
  15536. IoWMISetSingleItem(
  15537. IN PVOID DataBlockObject,
  15538. IN PUNICODE_STRING InstanceName,
  15539. IN ULONG DataItemId,
  15540. IN ULONG Version,
  15541. IN ULONG ValueBufferSize,
  15542. IN PVOID ValueBuffer
  15543. );
  15544. NTKERNELAPI
  15545. NTSTATUS
  15546. IoWMIExecuteMethod(
  15547. IN PVOID DataBlockObject,
  15548. IN PUNICODE_STRING InstanceName,
  15549. IN ULONG MethodId,
  15550. IN ULONG InBufferSize,
  15551. IN OUT PULONG OutBufferSize,
  15552. IN OUT PUCHAR InOutBuffer
  15553. );
  15554. typedef VOID (*WMI_NOTIFICATION_CALLBACK)(
  15555. PVOID Wnode,
  15556. PVOID Context
  15557. );
  15558. NTKERNELAPI
  15559. NTSTATUS
  15560. IoWMISetNotificationCallback(
  15561. IN PVOID Object,
  15562. IN WMI_NOTIFICATION_CALLBACK Callback,
  15563. IN PVOID Context
  15564. );
  15565. NTKERNELAPI
  15566. NTSTATUS
  15567. IoWMIHandleToInstanceName(
  15568. IN PVOID DataBlockObject,
  15569. IN HANDLE FileHandle,
  15570. OUT PUNICODE_STRING InstanceName
  15571. );
  15572. NTKERNELAPI
  15573. NTSTATUS
  15574. IoWMIDeviceObjectToInstanceName(
  15575. IN PVOID DataBlockObject,
  15576. IN PDEVICE_OBJECT DeviceObject,
  15577. OUT PUNICODE_STRING InstanceName
  15578. );
  15579. #if defined(_WIN64)
  15580. BOOLEAN
  15581. IoIs32bitProcess(
  15582. IN PIRP Irp
  15583. );
  15584. #endif
  15585. NTKERNELAPI
  15586. VOID
  15587. FASTCALL
  15588. HalExamineMBR(
  15589. IN PDEVICE_OBJECT DeviceObject,
  15590. IN ULONG SectorSize,
  15591. IN ULONG MBRTypeIdentifier,
  15592. OUT PVOID *Buffer
  15593. );
  15594. DECLSPEC_DEPRECATED_DDK // Use IoReadPartitionTableEx
  15595. NTKERNELAPI
  15596. NTSTATUS
  15597. FASTCALL
  15598. IoReadPartitionTable(
  15599. IN PDEVICE_OBJECT DeviceObject,
  15600. IN ULONG SectorSize,
  15601. IN BOOLEAN ReturnRecognizedPartitions,
  15602. OUT struct _DRIVE_LAYOUT_INFORMATION **PartitionBuffer
  15603. );
  15604. DECLSPEC_DEPRECATED_DDK // Use IoSetPartitionInformationEx
  15605. NTKERNELAPI
  15606. NTSTATUS
  15607. FASTCALL
  15608. IoSetPartitionInformation(
  15609. IN PDEVICE_OBJECT DeviceObject,
  15610. IN ULONG SectorSize,
  15611. IN ULONG PartitionNumber,
  15612. IN ULONG PartitionType
  15613. );
  15614. DECLSPEC_DEPRECATED_DDK // Use IoWritePartitionTableEx
  15615. NTKERNELAPI
  15616. NTSTATUS
  15617. FASTCALL
  15618. IoWritePartitionTable(
  15619. IN PDEVICE_OBJECT DeviceObject,
  15620. IN ULONG SectorSize,
  15621. IN ULONG SectorsPerTrack,
  15622. IN ULONG NumberOfHeads,
  15623. IN struct _DRIVE_LAYOUT_INFORMATION *PartitionBuffer
  15624. );
  15625. NTKERNELAPI
  15626. NTSTATUS
  15627. IoCreateDisk(
  15628. IN PDEVICE_OBJECT DeviceObject,
  15629. IN struct _CREATE_DISK* Disk
  15630. );
  15631. NTKERNELAPI
  15632. NTSTATUS
  15633. IoReadPartitionTableEx(
  15634. IN PDEVICE_OBJECT DeviceObject,
  15635. IN struct _DRIVE_LAYOUT_INFORMATION_EX** DriveLayout
  15636. );
  15637. NTKERNELAPI
  15638. NTSTATUS
  15639. IoWritePartitionTableEx(
  15640. IN PDEVICE_OBJECT DeviceObject,
  15641. IN struct _DRIVE_LAYOUT_INFORMATION_EX* DriveLayout
  15642. );
  15643. NTKERNELAPI
  15644. NTSTATUS
  15645. IoSetPartitionInformationEx(
  15646. IN PDEVICE_OBJECT DeviceObject,
  15647. IN ULONG PartitionNumber,
  15648. IN struct _SET_PARTITION_INFORMATION_EX* PartitionInfo
  15649. );
  15650. NTKERNELAPI
  15651. NTSTATUS
  15652. IoUpdateDiskGeometry(
  15653. IN PDEVICE_OBJECT DeviceObject,
  15654. IN struct _DISK_GEOMETRY_EX* OldDiskGeometry,
  15655. IN struct _DISK_GEOMETRY_EX* NewDiskGeometry
  15656. );
  15657. NTKERNELAPI
  15658. NTSTATUS
  15659. IoVerifyPartitionTable(
  15660. IN PDEVICE_OBJECT DeviceObject,
  15661. IN BOOLEAN FixErrors
  15662. );
  15663. typedef struct _DISK_SIGNATURE {
  15664. ULONG PartitionStyle;
  15665. union {
  15666. struct {
  15667. ULONG Signature;
  15668. ULONG CheckSum;
  15669. } Mbr;
  15670. struct {
  15671. GUID DiskId;
  15672. } Gpt;
  15673. };
  15674. } DISK_SIGNATURE, *PDISK_SIGNATURE;
  15675. NTKERNELAPI
  15676. NTSTATUS
  15677. IoReadDiskSignature(
  15678. IN PDEVICE_OBJECT DeviceObject,
  15679. IN ULONG BytesPerSector,
  15680. OUT PDISK_SIGNATURE Signature
  15681. );
  15682. NTSTATUS
  15683. IoVolumeDeviceToDosName(
  15684. IN PVOID VolumeDeviceObject,
  15685. OUT PUNICODE_STRING DosName
  15686. );
  15687. NTSTATUS
  15688. IoSetSystemPartition(
  15689. PUNICODE_STRING VolumeNameString
  15690. );
  15691. VOID
  15692. IoFreeErrorLogEntry(
  15693. PVOID ElEntry
  15694. );
  15695. // Cancel SAFE API set start
  15696. //
  15697. // The following APIs are to help ease the pain of writing queue packages that
  15698. // handle the cancellation race well. The idea of this set of APIs is to not
  15699. // force a single queue data structure but allow the cancel logic to be hidden
  15700. // from the drivers. A driver implements a queue and as part of its header
  15701. // includes the IO_CSQ structure. In its initialization routine it calls
  15702. // IoInitializeCsq. Then in the dispatch routine when the driver wants to
  15703. // insert an IRP into the queue it calls IoCsqInsertIrp. When the driver wants
  15704. // to remove something from the queue it calls IoCsqRemoveIrp. Note that Insert
  15705. // can fail if the IRP was cancelled in the meantime. Remove can also fail if
  15706. // the IRP was already cancelled.
  15707. //
  15708. // There are typically two modes where drivers queue IRPs. These two modes are
  15709. // covered by the cancel safe queue API set.
  15710. //
  15711. // Mode 1:
  15712. // One is where the driver queues the IRP and at some later
  15713. // point in time dequeues an IRP and issues the IO request.
  15714. // For this mode the driver should use IoCsqInsertIrp and IoCsqRemoveNextIrp.
  15715. // The driver in this case is expected to pass NULL to the irp context
  15716. // parameter in IoInsertIrp.
  15717. //
  15718. // Mode 2:
  15719. // In this the driver queues theIRP, issues the IO request (like issuing a DMA
  15720. // request or writing to a register) and when the IO request completes (either
  15721. // using a DPC or timer) the driver dequeues the IRP and completes it. For this
  15722. // mode the driver should use IoCsqInsertIrp and IoCsqRemoveIrp. In this case
  15723. // the driver should allocate an IRP context and pass it in to IoCsqInsertIrp.
  15724. // The cancel API code creates an association between the IRP and the context
  15725. // and thus ensures that when the time comes to remove the IRP it can ascertain
  15726. // correctly.
  15727. //
  15728. // Note that the cancel API set assumes that the field DriverContext[3] is
  15729. // always available for use and that the driver does not use it.
  15730. //
  15731. //
  15732. // Bookkeeping structure. This should be opaque to drivers.
  15733. // Drivers typically include this as part of their queue headers.
  15734. // Given a CSQ pointer the driver should be able to get its
  15735. // queue header using CONTAINING_RECORD macro
  15736. //
  15737. typedef struct _IO_CSQ IO_CSQ, *PIO_CSQ;
  15738. #define IO_TYPE_CSQ_IRP_CONTEXT 1
  15739. #define IO_TYPE_CSQ 2
  15740. #define IO_TYPE_CSQ_EX 3
  15741. //
  15742. // IRP context structure. This structure is necessary if the driver is using
  15743. // the second mode.
  15744. //
  15745. typedef struct _IO_CSQ_IRP_CONTEXT {
  15746. ULONG Type;
  15747. PIRP Irp;
  15748. PIO_CSQ Csq;
  15749. } IO_CSQ_IRP_CONTEXT, *PIO_CSQ_IRP_CONTEXT;
  15750. //
  15751. // Routines that insert/remove IRP
  15752. //
  15753. typedef VOID
  15754. (*PIO_CSQ_INSERT_IRP)(
  15755. IN struct _IO_CSQ *Csq,
  15756. IN PIRP Irp
  15757. );
  15758. typedef NTSTATUS
  15759. (*PIO_CSQ_INSERT_IRP_EX)(
  15760. IN struct _IO_CSQ *Csq,
  15761. IN PIRP Irp,
  15762. IN OUT PVOID InsertContext
  15763. );
  15764. typedef VOID
  15765. (*PIO_CSQ_REMOVE_IRP)(
  15766. IN PIO_CSQ Csq,
  15767. IN PIRP Irp
  15768. );
  15769. //
  15770. // Retrieves next entry after Irp from the queue.
  15771. // Returns NULL if there are no entries in the queue.
  15772. // If Irp is NUL, returns the entry in the head of the queue.
  15773. // This routine does not remove the IRP from the queue.
  15774. //
  15775. typedef PIRP
  15776. (*PIO_CSQ_PEEK_NEXT_IRP)(
  15777. IN PIO_CSQ Csq,
  15778. IN PIRP Irp,
  15779. IN PVOID PeekContext
  15780. );
  15781. //
  15782. // Lock routine that protects the cancel safe queue.
  15783. //
  15784. typedef VOID
  15785. (*PIO_CSQ_ACQUIRE_LOCK)(
  15786. IN PIO_CSQ Csq,
  15787. OUT PKIRQL Irql
  15788. );
  15789. typedef VOID
  15790. (*PIO_CSQ_RELEASE_LOCK)(
  15791. IN PIO_CSQ Csq,
  15792. IN KIRQL Irql
  15793. );
  15794. //
  15795. // Completes the IRP with STATUS_CANCELLED. IRP is guaranteed to be valid
  15796. // In most cases this routine just calls IoCompleteRequest(Irp, STATUS_CANCELLED);
  15797. //
  15798. typedef VOID
  15799. (*PIO_CSQ_COMPLETE_CANCELED_IRP)(
  15800. IN PIO_CSQ Csq,
  15801. IN PIRP Irp
  15802. );
  15803. //
  15804. // Bookkeeping structure. This should be opaque to drivers.
  15805. // Drivers typically include this as part of their queue headers.
  15806. // Given a CSQ pointer the driver should be able to get its
  15807. // queue header using CONTAINING_RECORD macro
  15808. //
  15809. typedef struct _IO_CSQ {
  15810. ULONG Type;
  15811. PIO_CSQ_INSERT_IRP CsqInsertIrp;
  15812. PIO_CSQ_REMOVE_IRP CsqRemoveIrp;
  15813. PIO_CSQ_PEEK_NEXT_IRP CsqPeekNextIrp;
  15814. PIO_CSQ_ACQUIRE_LOCK CsqAcquireLock;
  15815. PIO_CSQ_RELEASE_LOCK CsqReleaseLock;
  15816. PIO_CSQ_COMPLETE_CANCELED_IRP CsqCompleteCanceledIrp;
  15817. PVOID ReservePointer; // Future expansion
  15818. } IO_CSQ, *PIO_CSQ;
  15819. //
  15820. // Initializes the cancel queue structure.
  15821. //
  15822. NTSTATUS
  15823. IoCsqInitialize(
  15824. IN PIO_CSQ Csq,
  15825. IN PIO_CSQ_INSERT_IRP CsqInsertIrp,
  15826. IN PIO_CSQ_REMOVE_IRP CsqRemoveIrp,
  15827. IN PIO_CSQ_PEEK_NEXT_IRP CsqPeekNextIrp,
  15828. IN PIO_CSQ_ACQUIRE_LOCK CsqAcquireLock,
  15829. IN PIO_CSQ_RELEASE_LOCK CsqReleaseLock,
  15830. IN PIO_CSQ_COMPLETE_CANCELED_IRP CsqCompleteCanceledIrp
  15831. );
  15832. NTSTATUS
  15833. IoCsqInitializeEx(
  15834. IN PIO_CSQ Csq,
  15835. IN PIO_CSQ_INSERT_IRP_EX CsqInsertIrp,
  15836. IN PIO_CSQ_REMOVE_IRP CsqRemoveIrp,
  15837. IN PIO_CSQ_PEEK_NEXT_IRP CsqPeekNextIrp,
  15838. IN PIO_CSQ_ACQUIRE_LOCK CsqAcquireLock,
  15839. IN PIO_CSQ_RELEASE_LOCK CsqReleaseLock,
  15840. IN PIO_CSQ_COMPLETE_CANCELED_IRP CsqCompleteCanceledIrp
  15841. );
  15842. //
  15843. // The caller calls this routine to insert the IRP and return STATUS_PENDING.
  15844. //
  15845. VOID
  15846. IoCsqInsertIrp(
  15847. IN PIO_CSQ Csq,
  15848. IN PIRP Irp,
  15849. IN PIO_CSQ_IRP_CONTEXT Context
  15850. );
  15851. NTSTATUS
  15852. IoCsqInsertIrpEx(
  15853. IN PIO_CSQ Csq,
  15854. IN PIRP Irp,
  15855. IN PIO_CSQ_IRP_CONTEXT Context,
  15856. IN PVOID InsertContext
  15857. );
  15858. //
  15859. // Returns an IRP if one can be found. NULL otherwise.
  15860. //
  15861. PIRP
  15862. IoCsqRemoveNextIrp(
  15863. IN PIO_CSQ Csq,
  15864. IN PVOID PeekContext
  15865. );
  15866. //
  15867. // This routine is called from timeout or DPCs.
  15868. // The context is presumably part of the DPC or timer context.
  15869. // If succesfull returns the IRP associated with context.
  15870. //
  15871. PIRP
  15872. IoCsqRemoveIrp(
  15873. IN PIO_CSQ Csq,
  15874. IN PIO_CSQ_IRP_CONTEXT Context
  15875. );
  15876. // Cancel SAFE API set end
  15877. NTSTATUS
  15878. IoValidateDeviceIoControlAccess(
  15879. IN PIRP Irp,
  15880. IN ULONG RequiredAccess
  15881. );
  15882. IO_PAGING_PRIORITY
  15883. FASTCALL
  15884. IoGetPagingIoPriority(
  15885. IN PIRP IRP
  15886. );
  15887. #ifdef RUN_WPP
  15888. #include <evntrace.h>
  15889. #include <stdarg.h>
  15890. #endif // #ifdef RUN_WPP
  15891. #ifdef RUN_WPP
  15892. NTKERNELAPI
  15893. NTSTATUS
  15894. WmiTraceMessage(
  15895. IN TRACEHANDLE LoggerHandle,
  15896. IN ULONG MessageFlags,
  15897. IN LPGUID MessageGuid,
  15898. IN USHORT MessageNumber,
  15899. IN ...
  15900. );
  15901. NTKERNELAPI
  15902. NTSTATUS
  15903. WmiTraceMessageVa(
  15904. IN TRACEHANDLE LoggerHandle,
  15905. IN ULONG MessageFlags,
  15906. IN LPGUID MessageGuid,
  15907. IN USHORT MessageNumber,
  15908. IN va_list MessageArgList
  15909. );
  15910. #endif // #ifdef RUN_WPP
  15911. #ifndef TRACE_INFORMATION_CLASS_DEFINE
  15912. typedef enum _TRACE_INFORMATION_CLASS {
  15913. TraceIdClass,
  15914. TraceHandleClass,
  15915. TraceEnableFlagsClass,
  15916. TraceEnableLevelClass,
  15917. GlobalLoggerHandleClass,
  15918. EventLoggerHandleClass,
  15919. AllLoggerHandlesClass,
  15920. TraceHandleByNameClass
  15921. } TRACE_INFORMATION_CLASS;
  15922. NTKERNELAPI
  15923. NTSTATUS
  15924. WmiQueryTraceInformation(
  15925. IN TRACE_INFORMATION_CLASS TraceInformationClass,
  15926. OUT PVOID TraceInformation,
  15927. IN ULONG TraceInformationLength,
  15928. OUT PULONG RequiredLength OPTIONAL,
  15929. IN PVOID Buffer OPTIONAL
  15930. );
  15931. #define TRACE_INFORMATION_CLASS_DEFINE
  15932. #endif // TRACE_INFOPRMATION_CLASS_DEFINE
  15933. //
  15934. // Define PnP Device Property for IoGetDeviceProperty
  15935. //
  15936. typedef enum {
  15937. DevicePropertyDeviceDescription,
  15938. DevicePropertyHardwareID,
  15939. DevicePropertyCompatibleIDs,
  15940. DevicePropertyBootConfiguration,
  15941. DevicePropertyBootConfigurationTranslated,
  15942. DevicePropertyClassName,
  15943. DevicePropertyClassGuid,
  15944. DevicePropertyDriverKeyName,
  15945. DevicePropertyManufacturer,
  15946. DevicePropertyFriendlyName,
  15947. DevicePropertyLocationInformation,
  15948. DevicePropertyPhysicalDeviceObjectName,
  15949. DevicePropertyBusTypeGuid,
  15950. DevicePropertyLegacyBusType,
  15951. DevicePropertyBusNumber,
  15952. DevicePropertyEnumeratorName,
  15953. DevicePropertyAddress,
  15954. DevicePropertyUINumber,
  15955. DevicePropertyInstallState,
  15956. DevicePropertyRemovalPolicy
  15957. } DEVICE_REGISTRY_PROPERTY;
  15958. typedef BOOLEAN (*PTRANSLATE_BUS_ADDRESS)(
  15959. IN PVOID Context,
  15960. IN PHYSICAL_ADDRESS BusAddress,
  15961. IN ULONG Length,
  15962. IN OUT PULONG AddressSpace,
  15963. OUT PPHYSICAL_ADDRESS TranslatedAddress
  15964. );
  15965. typedef struct _DMA_ADAPTER *(*PGET_DMA_ADAPTER)(
  15966. IN PVOID Context,
  15967. IN struct _DEVICE_DESCRIPTION *DeviceDescriptor,
  15968. OUT PULONG NumberOfMapRegisters
  15969. );
  15970. typedef ULONG (*PGET_SET_DEVICE_DATA)(
  15971. IN PVOID Context,
  15972. IN ULONG DataType,
  15973. IN PVOID Buffer,
  15974. IN ULONG Offset,
  15975. IN ULONG Length
  15976. );
  15977. typedef enum _DEVICE_INSTALL_STATE {
  15978. InstallStateInstalled,
  15979. InstallStateNeedsReinstall,
  15980. InstallStateFailedInstall,
  15981. InstallStateFinishInstall
  15982. } DEVICE_INSTALL_STATE, *PDEVICE_INSTALL_STATE;
  15983. //
  15984. // Define structure returned in response to IRP_MN_QUERY_BUS_INFORMATION by a
  15985. // PDO indicating the type of bus the device exists on.
  15986. //
  15987. typedef struct _PNP_BUS_INFORMATION {
  15988. GUID BusTypeGuid;
  15989. INTERFACE_TYPE LegacyBusType;
  15990. ULONG BusNumber;
  15991. } PNP_BUS_INFORMATION, *PPNP_BUS_INFORMATION;
  15992. //
  15993. // Define structure returned in response to IRP_MN_QUERY_LEGACY_BUS_INFORMATION
  15994. // by an FDO indicating the type of bus it is. This is normally the same bus
  15995. // type as the device's children (i.e., as retrieved from the child PDO's via
  15996. // IRP_MN_QUERY_BUS_INFORMATION) except for cases like CardBus, which can
  15997. // support both 16-bit (PCMCIABus) and 32-bit (PCIBus) cards.
  15998. //
  15999. typedef struct _LEGACY_BUS_INFORMATION {
  16000. GUID BusTypeGuid;
  16001. INTERFACE_TYPE LegacyBusType;
  16002. ULONG BusNumber;
  16003. } LEGACY_BUS_INFORMATION, *PLEGACY_BUS_INFORMATION;
  16004. //
  16005. // Defines for IoGetDeviceProperty(DevicePropertyRemovalPolicy).
  16006. //
  16007. typedef enum _DEVICE_REMOVAL_POLICY {
  16008. RemovalPolicyExpectNoRemoval = 1,
  16009. RemovalPolicyExpectOrderlyRemoval = 2,
  16010. RemovalPolicyExpectSurpriseRemoval = 3
  16011. } DEVICE_REMOVAL_POLICY, *PDEVICE_REMOVAL_POLICY;
  16012. typedef struct _BUS_INTERFACE_STANDARD {
  16013. //
  16014. // generic interface header
  16015. //
  16016. USHORT Size;
  16017. USHORT Version;
  16018. PVOID Context;
  16019. PINTERFACE_REFERENCE InterfaceReference;
  16020. PINTERFACE_DEREFERENCE InterfaceDereference;
  16021. //
  16022. // standard bus interfaces
  16023. //
  16024. PTRANSLATE_BUS_ADDRESS TranslateBusAddress;
  16025. PGET_DMA_ADAPTER GetDmaAdapter;
  16026. PGET_SET_DEVICE_DATA SetBusData;
  16027. PGET_SET_DEVICE_DATA GetBusData;
  16028. } BUS_INTERFACE_STANDARD, *PBUS_INTERFACE_STANDARD;
  16029. typedef struct _AGP_TARGET_BUS_INTERFACE_STANDARD {
  16030. //
  16031. // generic interface header
  16032. //
  16033. USHORT Size;
  16034. USHORT Version;
  16035. PVOID Context;
  16036. PINTERFACE_REFERENCE InterfaceReference;
  16037. PINTERFACE_DEREFERENCE InterfaceDereference;
  16038. //
  16039. // config munging routines
  16040. //
  16041. PGET_SET_DEVICE_DATA SetBusData;
  16042. PGET_SET_DEVICE_DATA GetBusData;
  16043. UCHAR CapabilityID; // 2 (AGPv2 host) or new 0xE (AGPv3 bridge)
  16044. } AGP_TARGET_BUS_INTERFACE_STANDARD, *PAGP_TARGET_BUS_INTERFACE_STANDARD;
  16045. //
  16046. // The following definitions are used in ACPI QueryInterface
  16047. //
  16048. typedef BOOLEAN (* PGPE_SERVICE_ROUTINE) (
  16049. PVOID,
  16050. PVOID);
  16051. typedef NTSTATUS (* PGPE_CONNECT_VECTOR) (
  16052. PDEVICE_OBJECT,
  16053. ULONG,
  16054. KINTERRUPT_MODE,
  16055. BOOLEAN,
  16056. PGPE_SERVICE_ROUTINE,
  16057. PVOID,
  16058. PVOID);
  16059. typedef NTSTATUS (* PGPE_DISCONNECT_VECTOR) (
  16060. PVOID);
  16061. typedef NTSTATUS (* PGPE_ENABLE_EVENT) (
  16062. PDEVICE_OBJECT,
  16063. PVOID);
  16064. typedef NTSTATUS (* PGPE_DISABLE_EVENT) (
  16065. PDEVICE_OBJECT,
  16066. PVOID);
  16067. typedef NTSTATUS (* PGPE_CLEAR_STATUS) (
  16068. PDEVICE_OBJECT,
  16069. PVOID);
  16070. typedef VOID (* PDEVICE_NOTIFY_CALLBACK) (
  16071. PVOID,
  16072. ULONG);
  16073. typedef NTSTATUS (* PREGISTER_FOR_DEVICE_NOTIFICATIONS) (
  16074. PDEVICE_OBJECT,
  16075. PDEVICE_NOTIFY_CALLBACK,
  16076. PVOID);
  16077. typedef void (* PUNREGISTER_FOR_DEVICE_NOTIFICATIONS) (
  16078. PDEVICE_OBJECT,
  16079. PDEVICE_NOTIFY_CALLBACK);
  16080. typedef struct _ACPI_INTERFACE_STANDARD {
  16081. //
  16082. // Generic interface header
  16083. //
  16084. USHORT Size;
  16085. USHORT Version;
  16086. PVOID Context;
  16087. PINTERFACE_REFERENCE InterfaceReference;
  16088. PINTERFACE_DEREFERENCE InterfaceDereference;
  16089. //
  16090. // ACPI interfaces
  16091. //
  16092. PGPE_CONNECT_VECTOR GpeConnectVector;
  16093. PGPE_DISCONNECT_VECTOR GpeDisconnectVector;
  16094. PGPE_ENABLE_EVENT GpeEnableEvent;
  16095. PGPE_DISABLE_EVENT GpeDisableEvent;
  16096. PGPE_CLEAR_STATUS GpeClearStatus;
  16097. PREGISTER_FOR_DEVICE_NOTIFICATIONS RegisterForDeviceNotifications;
  16098. PUNREGISTER_FOR_DEVICE_NOTIFICATIONS UnregisterForDeviceNotifications;
  16099. } ACPI_INTERFACE_STANDARD, *PACPI_INTERFACE_STANDARD;
  16100. NTKERNELAPI
  16101. NTSTATUS
  16102. IoReportDetectedDevice(
  16103. IN PDRIVER_OBJECT DriverObject,
  16104. IN INTERFACE_TYPE LegacyBusType,
  16105. IN ULONG BusNumber,
  16106. IN ULONG SlotNumber,
  16107. IN PCM_RESOURCE_LIST ResourceList,
  16108. IN PIO_RESOURCE_REQUIREMENTS_LIST ResourceRequirements OPTIONAL,
  16109. IN BOOLEAN ResourceAssigned,
  16110. IN OUT PDEVICE_OBJECT *DeviceObject
  16111. );
  16112. NTKERNELAPI
  16113. VOID
  16114. IoInvalidateDeviceRelations(
  16115. IN PDEVICE_OBJECT DeviceObject,
  16116. IN DEVICE_RELATION_TYPE Type
  16117. );
  16118. NTKERNELAPI
  16119. VOID
  16120. IoRequestDeviceEject(
  16121. IN PDEVICE_OBJECT PhysicalDeviceObject
  16122. );
  16123. NTKERNELAPI
  16124. NTSTATUS
  16125. IoGetDeviceProperty(
  16126. IN PDEVICE_OBJECT DeviceObject,
  16127. IN DEVICE_REGISTRY_PROPERTY DeviceProperty,
  16128. IN ULONG BufferLength,
  16129. OUT PVOID PropertyBuffer,
  16130. OUT PULONG ResultLength
  16131. );
  16132. //
  16133. // The following definitions are used in IoOpenDeviceRegistryKey
  16134. //
  16135. #define PLUGPLAY_REGKEY_DEVICE 1
  16136. #define PLUGPLAY_REGKEY_DRIVER 2
  16137. #define PLUGPLAY_REGKEY_CURRENT_HWPROFILE 4
  16138. NTKERNELAPI
  16139. NTSTATUS
  16140. IoOpenDeviceRegistryKey(
  16141. IN PDEVICE_OBJECT DeviceObject,
  16142. IN ULONG DevInstKeyType,
  16143. IN ACCESS_MASK DesiredAccess,
  16144. OUT PHANDLE DevInstRegKey
  16145. );
  16146. NTKERNELAPI
  16147. NTSTATUS
  16148. NTAPI
  16149. IoRegisterDeviceInterface(
  16150. IN PDEVICE_OBJECT PhysicalDeviceObject,
  16151. IN CONST GUID *InterfaceClassGuid,
  16152. IN PUNICODE_STRING ReferenceString, OPTIONAL
  16153. OUT PUNICODE_STRING SymbolicLinkName
  16154. );
  16155. NTKERNELAPI
  16156. NTSTATUS
  16157. IoOpenDeviceInterfaceRegistryKey(
  16158. IN PUNICODE_STRING SymbolicLinkName,
  16159. IN ACCESS_MASK DesiredAccess,
  16160. OUT PHANDLE DeviceInterfaceKey
  16161. );
  16162. NTKERNELAPI
  16163. NTSTATUS
  16164. IoSetDeviceInterfaceState(
  16165. IN PUNICODE_STRING SymbolicLinkName,
  16166. IN BOOLEAN Enable
  16167. );
  16168. NTKERNELAPI
  16169. NTSTATUS
  16170. NTAPI
  16171. IoGetDeviceInterfaces(
  16172. IN CONST GUID *InterfaceClassGuid,
  16173. IN PDEVICE_OBJECT PhysicalDeviceObject OPTIONAL,
  16174. IN ULONG Flags,
  16175. OUT PWSTR *SymbolicLinkList
  16176. );
  16177. #define DEVICE_INTERFACE_INCLUDE_NONACTIVE 0x00000001
  16178. NTKERNELAPI
  16179. NTSTATUS
  16180. NTAPI
  16181. IoGetDeviceInterfaceAlias(
  16182. IN PUNICODE_STRING SymbolicLinkName,
  16183. IN CONST GUID *AliasInterfaceClassGuid,
  16184. OUT PUNICODE_STRING AliasSymbolicLinkName
  16185. );
  16186. //
  16187. // Define PnP notification event categories
  16188. //
  16189. typedef enum _IO_NOTIFICATION_EVENT_CATEGORY {
  16190. EventCategoryReserved,
  16191. EventCategoryHardwareProfileChange,
  16192. EventCategoryDeviceInterfaceChange,
  16193. EventCategoryTargetDeviceChange
  16194. } IO_NOTIFICATION_EVENT_CATEGORY;
  16195. //
  16196. // Define flags that modify the behavior of IoRegisterPlugPlayNotification
  16197. // for the various event categories...
  16198. //
  16199. #define PNPNOTIFY_DEVICE_INTERFACE_INCLUDE_EXISTING_INTERFACES 0x00000001
  16200. typedef
  16201. NTSTATUS
  16202. (*PDRIVER_NOTIFICATION_CALLBACK_ROUTINE) (
  16203. IN PVOID NotificationStructure,
  16204. IN PVOID Context
  16205. );
  16206. NTKERNELAPI
  16207. NTSTATUS
  16208. IoRegisterPlugPlayNotification(
  16209. IN IO_NOTIFICATION_EVENT_CATEGORY EventCategory,
  16210. IN ULONG EventCategoryFlags,
  16211. IN PVOID EventCategoryData OPTIONAL,
  16212. IN PDRIVER_OBJECT DriverObject,
  16213. IN PDRIVER_NOTIFICATION_CALLBACK_ROUTINE CallbackRoutine,
  16214. IN PVOID Context,
  16215. OUT PVOID *NotificationEntry
  16216. );
  16217. NTKERNELAPI
  16218. NTSTATUS
  16219. IoUnregisterPlugPlayNotification(
  16220. IN PVOID NotificationEntry
  16221. );
  16222. NTKERNELAPI
  16223. NTSTATUS
  16224. IoReportTargetDeviceChange(
  16225. IN PDEVICE_OBJECT PhysicalDeviceObject,
  16226. IN PVOID NotificationStructure // always begins with a PLUGPLAY_NOTIFICATION_HEADER
  16227. );
  16228. typedef
  16229. VOID
  16230. (*PDEVICE_CHANGE_COMPLETE_CALLBACK)(
  16231. IN PVOID Context
  16232. );
  16233. NTKERNELAPI
  16234. VOID
  16235. IoInvalidateDeviceState(
  16236. IN PDEVICE_OBJECT PhysicalDeviceObject
  16237. );
  16238. #define IoAdjustPagingPathCount(_count_,_paging_) { \
  16239. if (_paging_) { \
  16240. InterlockedIncrement(_count_); \
  16241. } else { \
  16242. InterlockedDecrement(_count_); \
  16243. } \
  16244. }
  16245. NTKERNELAPI
  16246. NTSTATUS
  16247. IoReportTargetDeviceChangeAsynchronous(
  16248. IN PDEVICE_OBJECT PhysicalDeviceObject,
  16249. IN PVOID NotificationStructure, // always begins with a PLUGPLAY_NOTIFICATION_HEADER
  16250. IN PDEVICE_CHANGE_COMPLETE_CALLBACK Callback, OPTIONAL
  16251. IN PVOID Context OPTIONAL
  16252. );
  16253. //
  16254. // Device location interface declarations
  16255. //
  16256. typedef
  16257. NTSTATUS
  16258. (*PGET_LOCATION_STRING) (
  16259. IN PVOID Context,
  16260. OUT PWCHAR *LocationStrings
  16261. );
  16262. typedef struct _PNP_LOCATION_INTERFACE {
  16263. //
  16264. // generic interface header
  16265. //
  16266. USHORT Size;
  16267. USHORT Version;
  16268. PVOID Context;
  16269. PINTERFACE_REFERENCE InterfaceReference;
  16270. PINTERFACE_DEREFERENCE InterfaceDereference;
  16271. //
  16272. // interface specific entry
  16273. //
  16274. PGET_LOCATION_STRING GetLocationString;
  16275. } PNP_LOCATION_INTERFACE, *PPNP_LOCATION_INTERFACE;
  16276. //
  16277. // Resource arbiter declarations
  16278. //
  16279. typedef enum _ARBITER_ACTION {
  16280. ArbiterActionTestAllocation,
  16281. ArbiterActionRetestAllocation,
  16282. ArbiterActionCommitAllocation,
  16283. ArbiterActionRollbackAllocation,
  16284. ArbiterActionQueryAllocatedResources,
  16285. ArbiterActionWriteReservedResources,
  16286. ArbiterActionQueryConflict,
  16287. ArbiterActionQueryArbitrate,
  16288. ArbiterActionAddReserved,
  16289. ArbiterActionBootAllocation
  16290. } ARBITER_ACTION, *PARBITER_ACTION;
  16291. typedef struct _ARBITER_CONFLICT_INFO {
  16292. //
  16293. // The device object owning the device that is causing the conflict
  16294. //
  16295. PDEVICE_OBJECT OwningObject;
  16296. //
  16297. // The start of the conflicting range
  16298. //
  16299. ULONGLONG Start;
  16300. //
  16301. // The end of the conflicting range
  16302. //
  16303. ULONGLONG End;
  16304. } ARBITER_CONFLICT_INFO, *PARBITER_CONFLICT_INFO;
  16305. //
  16306. // The parameters for those actions
  16307. //
  16308. typedef struct _ARBITER_PARAMETERS {
  16309. union {
  16310. struct {
  16311. //
  16312. // Doubly linked list of ARBITER_LIST_ENTRY's
  16313. //
  16314. IN OUT PLIST_ENTRY ArbitrationList;
  16315. //
  16316. // The size of the AllocateFrom array
  16317. //
  16318. IN ULONG AllocateFromCount;
  16319. //
  16320. // Array of resource descriptors describing the resources available
  16321. // to the arbiter for it to arbitrate
  16322. //
  16323. IN PCM_PARTIAL_RESOURCE_DESCRIPTOR AllocateFrom;
  16324. } TestAllocation;
  16325. struct {
  16326. //
  16327. // Doubly linked list of ARBITER_LIST_ENTRY's
  16328. //
  16329. IN OUT PLIST_ENTRY ArbitrationList;
  16330. //
  16331. // The size of the AllocateFrom array
  16332. //
  16333. IN ULONG AllocateFromCount;
  16334. //
  16335. // Array of resource descriptors describing the resources available
  16336. // to the arbiter for it to arbitrate
  16337. //
  16338. IN PCM_PARTIAL_RESOURCE_DESCRIPTOR AllocateFrom;
  16339. } RetestAllocation;
  16340. struct {
  16341. //
  16342. // Doubly linked list of ARBITER_LIST_ENTRY's
  16343. //
  16344. IN OUT PLIST_ENTRY ArbitrationList;
  16345. } BootAllocation;
  16346. struct {
  16347. //
  16348. // The resources that are currently allocated
  16349. //
  16350. OUT PCM_PARTIAL_RESOURCE_LIST *AllocatedResources;
  16351. } QueryAllocatedResources;
  16352. struct {
  16353. //
  16354. // This is the device we are trying to find a conflict for
  16355. //
  16356. IN PDEVICE_OBJECT PhysicalDeviceObject;
  16357. //
  16358. // This is the resource to find the conflict for
  16359. //
  16360. IN PIO_RESOURCE_DESCRIPTOR ConflictingResource;
  16361. //
  16362. // Number of devices conflicting on the resource
  16363. //
  16364. OUT PULONG ConflictCount;
  16365. //
  16366. // Pointer to array describing the conflicting device objects and ranges
  16367. //
  16368. OUT PARBITER_CONFLICT_INFO *Conflicts;
  16369. } QueryConflict;
  16370. struct {
  16371. //
  16372. // Doubly linked list of ARBITER_LIST_ENTRY's - should have
  16373. // only one entry
  16374. //
  16375. IN PLIST_ENTRY ArbitrationList;
  16376. } QueryArbitrate;
  16377. struct {
  16378. //
  16379. // Indicates the device whose resources are to be marked as reserved
  16380. //
  16381. PDEVICE_OBJECT ReserveDevice;
  16382. } AddReserved;
  16383. } Parameters;
  16384. } ARBITER_PARAMETERS, *PARBITER_PARAMETERS;
  16385. typedef enum _ARBITER_REQUEST_SOURCE {
  16386. ArbiterRequestUndefined = -1,
  16387. ArbiterRequestLegacyReported, // IoReportResourceUsage
  16388. ArbiterRequestHalReported, // IoReportHalResourceUsage
  16389. ArbiterRequestLegacyAssigned, // IoAssignResources
  16390. ArbiterRequestPnpDetected, // IoReportResourceForDetection
  16391. ArbiterRequestPnpEnumerated // IRP_MN_QUERY_RESOURCE_REQUIREMENTS
  16392. } ARBITER_REQUEST_SOURCE;
  16393. typedef enum _ARBITER_RESULT {
  16394. ArbiterResultUndefined = -1,
  16395. ArbiterResultSuccess,
  16396. ArbiterResultExternalConflict, // This indicates that the request can never be solved for devices in this list
  16397. ArbiterResultNullRequest // The request was for length zero and thus no translation should be attempted
  16398. } ARBITER_RESULT;
  16399. //
  16400. // ARBITER_FLAG_BOOT_CONFIG - this indicates that the request is for the
  16401. // resources assigned by the firmware/BIOS. It should be succeeded even if
  16402. // it conflicts with another devices boot config.
  16403. //
  16404. #define ARBITER_FLAG_BOOT_CONFIG 0x00000001
  16405. NTKERNELAPI
  16406. NTSTATUS
  16407. IoReportResourceForDetection(
  16408. IN PDRIVER_OBJECT DriverObject,
  16409. IN PCM_RESOURCE_LIST DriverList OPTIONAL,
  16410. IN ULONG DriverListSize OPTIONAL,
  16411. IN PDEVICE_OBJECT DeviceObject OPTIONAL,
  16412. IN PCM_RESOURCE_LIST DeviceList OPTIONAL,
  16413. IN ULONG DeviceListSize OPTIONAL,
  16414. OUT PBOOLEAN ConflictDetected
  16415. );
  16416. typedef struct _ARBITER_LIST_ENTRY {
  16417. //
  16418. // This is a doubly linked list of entries for easy sorting
  16419. //
  16420. LIST_ENTRY ListEntry;
  16421. //
  16422. // The number of alternative allocation
  16423. //
  16424. ULONG AlternativeCount;
  16425. //
  16426. // Pointer to an array of resource descriptors for the possible allocations
  16427. //
  16428. PIO_RESOURCE_DESCRIPTOR Alternatives;
  16429. //
  16430. // The device object of the device requesting these resources.
  16431. //
  16432. PDEVICE_OBJECT PhysicalDeviceObject;
  16433. //
  16434. // Indicates where the request came from
  16435. //
  16436. ARBITER_REQUEST_SOURCE RequestSource;
  16437. //
  16438. // Flags these indicate a variety of things (use ARBITER_FLAG_*)
  16439. //
  16440. ULONG Flags;
  16441. //
  16442. // Space to aid the arbiter in processing the list it is initialized to 0 when
  16443. // the entry is created. The system will not attempt to interpret it.
  16444. //
  16445. LONG_PTR WorkSpace;
  16446. //
  16447. // Interface Type, Slot Number and Bus Number from Resource Requirements list,
  16448. // used only for reverse identification.
  16449. //
  16450. INTERFACE_TYPE InterfaceType;
  16451. ULONG SlotNumber;
  16452. ULONG BusNumber;
  16453. //
  16454. // A pointer to a descriptor to indicate the resource that was allocated.
  16455. // This is allocated by the system and filled in by the arbiter in response to an
  16456. // ArbiterActionTestAllocation.
  16457. //
  16458. PCM_PARTIAL_RESOURCE_DESCRIPTOR Assignment;
  16459. //
  16460. // Pointer to the alternative that was chosen from to provide the assignment.
  16461. // This is filled in by the arbiter in response to an ArbiterActionTestAllocation.
  16462. //
  16463. PIO_RESOURCE_DESCRIPTOR SelectedAlternative;
  16464. //
  16465. // The result of the operation
  16466. // This is filled in by the arbiter in response to an ArbiterActionTestAllocation.
  16467. //
  16468. ARBITER_RESULT Result;
  16469. } ARBITER_LIST_ENTRY, *PARBITER_LIST_ENTRY;
  16470. //
  16471. // The arbiter's entry point
  16472. //
  16473. typedef
  16474. NTSTATUS
  16475. (*PARBITER_HANDLER) (
  16476. IN PVOID Context,
  16477. IN ARBITER_ACTION Action,
  16478. IN OUT PARBITER_PARAMETERS Parameters
  16479. );
  16480. //
  16481. // Arbiter interface
  16482. //
  16483. #define ARBITER_PARTIAL 0x00000001
  16484. typedef struct _ARBITER_INTERFACE {
  16485. //
  16486. // Generic interface header
  16487. //
  16488. USHORT Size;
  16489. USHORT Version;
  16490. PVOID Context;
  16491. PINTERFACE_REFERENCE InterfaceReference;
  16492. PINTERFACE_DEREFERENCE InterfaceDereference;
  16493. //
  16494. // Entry point to the arbiter
  16495. //
  16496. PARBITER_HANDLER ArbiterHandler;
  16497. //
  16498. // Other information about the arbiter, use ARBITER_* flags
  16499. //
  16500. ULONG Flags;
  16501. } ARBITER_INTERFACE, *PARBITER_INTERFACE;
  16502. //
  16503. // The directions translation can take place in
  16504. //
  16505. typedef enum _RESOURCE_TRANSLATION_DIRECTION { // ntosp
  16506. TranslateChildToParent, // ntosp
  16507. TranslateParentToChild // ntosp
  16508. } RESOURCE_TRANSLATION_DIRECTION; // ntosp
  16509. //
  16510. // Translation functions
  16511. //
  16512. typedef
  16513. NTSTATUS
  16514. (*PTRANSLATE_RESOURCE_HANDLER)(
  16515. IN PVOID Context,
  16516. IN PCM_PARTIAL_RESOURCE_DESCRIPTOR Source,
  16517. IN RESOURCE_TRANSLATION_DIRECTION Direction,
  16518. IN ULONG AlternativesCount, OPTIONAL
  16519. IN IO_RESOURCE_DESCRIPTOR Alternatives[], OPTIONAL
  16520. IN PDEVICE_OBJECT PhysicalDeviceObject,
  16521. OUT PCM_PARTIAL_RESOURCE_DESCRIPTOR Target
  16522. );
  16523. typedef
  16524. NTSTATUS
  16525. (*PTRANSLATE_RESOURCE_REQUIREMENTS_HANDLER)(
  16526. IN PVOID Context,
  16527. IN PIO_RESOURCE_DESCRIPTOR Source,
  16528. IN PDEVICE_OBJECT PhysicalDeviceObject,
  16529. OUT PULONG TargetCount,
  16530. OUT PIO_RESOURCE_DESCRIPTOR *Target
  16531. );
  16532. //
  16533. // Translator Interface
  16534. //
  16535. typedef struct _TRANSLATOR_INTERFACE {
  16536. USHORT Size;
  16537. USHORT Version;
  16538. PVOID Context;
  16539. PINTERFACE_REFERENCE InterfaceReference;
  16540. PINTERFACE_DEREFERENCE InterfaceDereference;
  16541. PTRANSLATE_RESOURCE_HANDLER TranslateResources;
  16542. PTRANSLATE_RESOURCE_REQUIREMENTS_HANDLER TranslateResourceRequirements;
  16543. } TRANSLATOR_INTERFACE, *PTRANSLATOR_INTERFACE;
  16544. //
  16545. // Header structure for all Plug&Play notification events...
  16546. //
  16547. typedef struct _PLUGPLAY_NOTIFICATION_HEADER {
  16548. USHORT Version; // presently at version 1.
  16549. USHORT Size; // size (in bytes) of header + event-specific data.
  16550. GUID Event;
  16551. //
  16552. // Event-specific stuff starts here.
  16553. //
  16554. } PLUGPLAY_NOTIFICATION_HEADER, *PPLUGPLAY_NOTIFICATION_HEADER;
  16555. //
  16556. // Notification structure for all EventCategoryHardwareProfileChange events...
  16557. //
  16558. typedef struct _HWPROFILE_CHANGE_NOTIFICATION {
  16559. USHORT Version;
  16560. USHORT Size;
  16561. GUID Event;
  16562. //
  16563. // (No event-specific data)
  16564. //
  16565. } HWPROFILE_CHANGE_NOTIFICATION, *PHWPROFILE_CHANGE_NOTIFICATION;
  16566. //
  16567. // Notification structure for all EventCategoryDeviceInterfaceChange events...
  16568. //
  16569. typedef struct _DEVICE_INTERFACE_CHANGE_NOTIFICATION {
  16570. USHORT Version;
  16571. USHORT Size;
  16572. GUID Event;
  16573. //
  16574. // Event-specific data
  16575. //
  16576. GUID InterfaceClassGuid;
  16577. PUNICODE_STRING SymbolicLinkName;
  16578. } DEVICE_INTERFACE_CHANGE_NOTIFICATION, *PDEVICE_INTERFACE_CHANGE_NOTIFICATION;
  16579. //
  16580. // Notification structures for EventCategoryTargetDeviceChange...
  16581. //
  16582. //
  16583. // The following structure is used for TargetDeviceQueryRemove,
  16584. // TargetDeviceRemoveCancelled, and TargetDeviceRemoveComplete:
  16585. //
  16586. typedef struct _TARGET_DEVICE_REMOVAL_NOTIFICATION {
  16587. USHORT Version;
  16588. USHORT Size;
  16589. GUID Event;
  16590. //
  16591. // Event-specific data
  16592. //
  16593. PFILE_OBJECT FileObject;
  16594. } TARGET_DEVICE_REMOVAL_NOTIFICATION, *PTARGET_DEVICE_REMOVAL_NOTIFICATION;
  16595. //
  16596. // The following structure header is used for all other (i.e., 3rd-party)
  16597. // target device change events. The structure accommodates both a
  16598. // variable-length binary data buffer, and a variable-length unicode text
  16599. // buffer. The header must indicate where the text buffer begins, so that
  16600. // the data can be delivered in the appropriate format (ANSI or Unicode)
  16601. // to user-mode recipients (i.e., that have registered for handle-based
  16602. // notification via RegisterDeviceNotification).
  16603. //
  16604. typedef struct _TARGET_DEVICE_CUSTOM_NOTIFICATION {
  16605. USHORT Version;
  16606. USHORT Size;
  16607. GUID Event;
  16608. //
  16609. // Event-specific data
  16610. //
  16611. PFILE_OBJECT FileObject; // This field must be set to NULL by callers of
  16612. // IoReportTargetDeviceChange. Clients that
  16613. // have registered for target device change
  16614. // notification on the affected PDO will be
  16615. // called with this field set to the file object
  16616. // they specified during registration.
  16617. //
  16618. LONG NameBufferOffset; // offset (in bytes) from beginning of
  16619. // CustomDataBuffer where text begins (-1 if none)
  16620. //
  16621. UCHAR CustomDataBuffer[1]; // variable-length buffer, containing (optionally)
  16622. // a binary data at the start of the buffer,
  16623. // followed by an optional unicode text buffer
  16624. // (word-aligned).
  16625. //
  16626. } TARGET_DEVICE_CUSTOM_NOTIFICATION, *PTARGET_DEVICE_CUSTOM_NOTIFICATION;
  16627. //
  16628. // Define the device description structure.
  16629. //
  16630. typedef struct _DEVICE_DESCRIPTION {
  16631. ULONG Version;
  16632. BOOLEAN Master;
  16633. BOOLEAN ScatterGather;
  16634. BOOLEAN DemandMode;
  16635. BOOLEAN AutoInitialize;
  16636. BOOLEAN Dma32BitAddresses;
  16637. BOOLEAN IgnoreCount;
  16638. BOOLEAN Reserved1; // must be false
  16639. BOOLEAN Dma64BitAddresses;
  16640. ULONG BusNumber; // unused for WDM
  16641. ULONG DmaChannel;
  16642. INTERFACE_TYPE InterfaceType;
  16643. DMA_WIDTH DmaWidth;
  16644. DMA_SPEED DmaSpeed;
  16645. ULONG MaximumLength;
  16646. ULONG DmaPort;
  16647. } DEVICE_DESCRIPTION, *PDEVICE_DESCRIPTION;
  16648. //
  16649. // Define the supported version numbers for the device description structure.
  16650. //
  16651. #define DEVICE_DESCRIPTION_VERSION 0
  16652. #define DEVICE_DESCRIPTION_VERSION1 1
  16653. #define DEVICE_DESCRIPTION_VERSION2 2
  16654. //
  16655. // The following function prototypes are for HAL routines with a prefix of Hal.
  16656. //
  16657. // General functions.
  16658. //
  16659. typedef
  16660. BOOLEAN
  16661. (*PHAL_RESET_DISPLAY_PARAMETERS) (
  16662. IN ULONG Columns,
  16663. IN ULONG Rows
  16664. );
  16665. DECLSPEC_DEPRECATED_DDK
  16666. NTHALAPI
  16667. VOID
  16668. HalAcquireDisplayOwnership (
  16669. IN PHAL_RESET_DISPLAY_PARAMETERS ResetDisplayParameters
  16670. );
  16671. #if defined(_IA64_)
  16672. DECLSPEC_DEPRECATED_DDK // Use GetDmaRequirement
  16673. NTHALAPI
  16674. ULONG
  16675. HalGetDmaAlignmentRequirement (
  16676. VOID
  16677. );
  16678. #endif
  16679. #if defined(_M_IX86) || defined(_M_AMD64)
  16680. #define HalGetDmaAlignmentRequirement() 1L
  16681. #endif
  16682. NTHALAPI
  16683. VOID
  16684. KeFlushWriteBuffer (
  16685. VOID
  16686. );
  16687. //
  16688. // I/O driver configuration functions.
  16689. //
  16690. #if !defined(NO_LEGACY_DRIVERS)
  16691. DECLSPEC_DEPRECATED_DDK // Use Pnp or IoReportDetectedDevice
  16692. NTHALAPI
  16693. NTSTATUS
  16694. HalAssignSlotResources (
  16695. IN PUNICODE_STRING RegistryPath,
  16696. IN PUNICODE_STRING DriverClassName OPTIONAL,
  16697. IN PDRIVER_OBJECT DriverObject,
  16698. IN PDEVICE_OBJECT DeviceObject,
  16699. IN INTERFACE_TYPE BusType,
  16700. IN ULONG BusNumber,
  16701. IN ULONG SlotNumber,
  16702. IN OUT PCM_RESOURCE_LIST *AllocatedResources
  16703. );
  16704. DECLSPEC_DEPRECATED_DDK // Use Pnp or IoReportDetectedDevice
  16705. NTHALAPI
  16706. ULONG
  16707. HalGetInterruptVector(
  16708. IN INTERFACE_TYPE InterfaceType,
  16709. IN ULONG BusNumber,
  16710. IN ULONG BusInterruptLevel,
  16711. IN ULONG BusInterruptVector,
  16712. OUT PKIRQL Irql,
  16713. OUT PKAFFINITY Affinity
  16714. );
  16715. DECLSPEC_DEPRECATED_DDK // Use IRP_MN_QUERY_INTERFACE and IRP_MN_READ_CONFIG
  16716. NTHALAPI
  16717. ULONG
  16718. HalSetBusData(
  16719. IN BUS_DATA_TYPE BusDataType,
  16720. IN ULONG BusNumber,
  16721. IN ULONG SlotNumber,
  16722. IN PVOID Buffer,
  16723. IN ULONG Length
  16724. );
  16725. #endif // NO_LEGACY_DRIVERS
  16726. DECLSPEC_DEPRECATED_DDK // Use IRP_MN_QUERY_INTERFACE and IRP_MN_READ_CONFIG
  16727. NTHALAPI
  16728. ULONG
  16729. HalSetBusDataByOffset(
  16730. IN BUS_DATA_TYPE BusDataType,
  16731. IN ULONG BusNumber,
  16732. IN ULONG SlotNumber,
  16733. IN PVOID Buffer,
  16734. IN ULONG Offset,
  16735. IN ULONG Length
  16736. );
  16737. DECLSPEC_DEPRECATED_DDK // Use IRP_MN_QUERY_INTERFACE and IRP_MN_READ_CONFIG
  16738. NTHALAPI
  16739. BOOLEAN
  16740. HalTranslateBusAddress(
  16741. IN INTERFACE_TYPE InterfaceType,
  16742. IN ULONG BusNumber,
  16743. IN PHYSICAL_ADDRESS BusAddress,
  16744. IN OUT PULONG AddressSpace,
  16745. OUT PPHYSICAL_ADDRESS TranslatedAddress
  16746. );
  16747. //
  16748. // Values for AddressSpace parameter of HalTranslateBusAddress
  16749. //
  16750. // 0x0 - Memory space
  16751. // 0x1 - Port space
  16752. // 0x2 - 0x1F - Address spaces specific for Alpha
  16753. // 0x2 - UserMode view of memory space
  16754. // 0x3 - UserMode view of port space
  16755. // 0x4 - Dense memory space
  16756. // 0x5 - reserved
  16757. // 0x6 - UserMode view of dense memory space
  16758. // 0x7 - 0x1F - reserved
  16759. //
  16760. NTHALAPI
  16761. PVOID
  16762. HalAllocateCrashDumpRegisters(
  16763. IN PADAPTER_OBJECT AdapterObject,
  16764. IN OUT PULONG NumberOfMapRegisters
  16765. );
  16766. #if !defined(NO_LEGACY_DRIVERS)
  16767. DECLSPEC_DEPRECATED_DDK // Use IRP_MN_QUERY_INTERFACE and IRP_MN_READ_CONFIG
  16768. NTHALAPI
  16769. ULONG
  16770. HalGetBusData(
  16771. IN BUS_DATA_TYPE BusDataType,
  16772. IN ULONG BusNumber,
  16773. IN ULONG SlotNumber,
  16774. IN PVOID Buffer,
  16775. IN ULONG Length
  16776. );
  16777. #endif // NO_LEGACY_DRIVERS
  16778. DECLSPEC_DEPRECATED_DDK // Use IRP_MN_QUERY_INTERFACE and IRP_MN_READ_CONFIG
  16779. NTHALAPI
  16780. ULONG
  16781. HalGetBusDataByOffset(
  16782. IN BUS_DATA_TYPE BusDataType,
  16783. IN ULONG BusNumber,
  16784. IN ULONG SlotNumber,
  16785. IN PVOID Buffer,
  16786. IN ULONG Offset,
  16787. IN ULONG Length
  16788. );
  16789. DECLSPEC_DEPRECATED_DDK // Use IoGetDmaAdapter
  16790. NTHALAPI
  16791. PADAPTER_OBJECT
  16792. HalGetAdapter(
  16793. IN PDEVICE_DESCRIPTION DeviceDescription,
  16794. IN OUT PULONG NumberOfMapRegisters
  16795. );
  16796. //
  16797. // System beep functions.
  16798. //
  16799. #if !defined(NO_LEGACY_DRIVERS)
  16800. DECLSPEC_DEPRECATED_DDK
  16801. NTHALAPI
  16802. BOOLEAN
  16803. HalMakeBeep(
  16804. IN ULONG Frequency
  16805. );
  16806. #endif // NO_LEGACY_DRIVERS
  16807. //
  16808. // The following function prototypes are for HAL routines with a prefix of Io.
  16809. //
  16810. // DMA adapter object functions.
  16811. //
  16812. //
  16813. // Performance counter function.
  16814. //
  16815. NTHALAPI
  16816. LARGE_INTEGER
  16817. KeQueryPerformanceCounter (
  16818. OUT PLARGE_INTEGER PerformanceFrequency OPTIONAL
  16819. );
  16820. //
  16821. // Stall processor execution function.
  16822. //
  16823. NTHALAPI
  16824. VOID
  16825. KeStallExecutionProcessor (
  16826. IN ULONG MicroSeconds
  16827. );
  16828. typedef
  16829. VOID
  16830. (*PDEVICE_CONTROL_COMPLETION)(
  16831. IN struct _DEVICE_CONTROL_CONTEXT *ControlContext
  16832. );
  16833. typedef struct _DEVICE_CONTROL_CONTEXT {
  16834. NTSTATUS Status;
  16835. PDEVICE_HANDLER_OBJECT DeviceHandler;
  16836. PDEVICE_OBJECT DeviceObject;
  16837. ULONG ControlCode;
  16838. PVOID Buffer;
  16839. PULONG BufferLength;
  16840. PVOID Context;
  16841. } DEVICE_CONTROL_CONTEXT, *PDEVICE_CONTROL_CONTEXT;
  16842. typedef
  16843. PBUS_HANDLER
  16844. (FASTCALL *pHalHandlerForBus) (
  16845. IN INTERFACE_TYPE InterfaceType,
  16846. IN ULONG BusNumber
  16847. );
  16848. typedef
  16849. VOID
  16850. (FASTCALL *pHalReferenceBusHandler) (
  16851. IN PBUS_HANDLER BusHandler
  16852. );
  16853. //*****************************************************************************
  16854. // HAL Function dispatch
  16855. //
  16856. typedef enum _HAL_QUERY_INFORMATION_CLASS {
  16857. HalInstalledBusInformation,
  16858. HalProfileSourceInformation,
  16859. HalInformationClassUnused1,
  16860. HalPowerInformation,
  16861. HalProcessorSpeedInformation,
  16862. HalCallbackInformation,
  16863. HalMapRegisterInformation,
  16864. HalMcaLogInformation, // Machine Check Abort Information
  16865. HalFrameBufferCachingInformation,
  16866. HalDisplayBiosInformation,
  16867. HalProcessorFeatureInformation,
  16868. HalNumaTopologyInterface,
  16869. HalErrorInformation, // General MCA, CMC, CPE Error Information.
  16870. HalCmcLogInformation, // Processor Corrected Machine Check Information
  16871. HalCpeLogInformation, // Corrected Platform Error Information
  16872. HalQueryMcaInterface,
  16873. HalQueryAMLIIllegalIOPortAddresses,
  16874. HalQueryMaxHotPlugMemoryAddress,
  16875. HalPartitionIpiInterface,
  16876. HalPlatformInformation,
  16877. HalQueryProfileSourceList
  16878. // information levels >= 0x8000000 reserved for OEM use
  16879. } HAL_QUERY_INFORMATION_CLASS, *PHAL_QUERY_INFORMATION_CLASS;
  16880. typedef enum _HAL_SET_INFORMATION_CLASS {
  16881. HalProfileSourceInterval,
  16882. HalProfileSourceInterruptHandler,
  16883. HalMcaRegisterDriver, // Registring Machine Check Abort driver
  16884. HalKernelErrorHandler,
  16885. HalCmcRegisterDriver, // Registring Processor Corrected Machine Check driver
  16886. HalCpeRegisterDriver, // Registring Corrected Platform Error driver
  16887. HalMcaLog,
  16888. HalCmcLog,
  16889. HalCpeLog,
  16890. HalGenerateCmcInterrupt // Used to test CMC
  16891. } HAL_SET_INFORMATION_CLASS, *PHAL_SET_INFORMATION_CLASS;
  16892. typedef
  16893. NTSTATUS
  16894. (*pHalQuerySystemInformation)(
  16895. IN HAL_QUERY_INFORMATION_CLASS InformationClass,
  16896. IN ULONG BufferSize,
  16897. IN OUT PVOID Buffer,
  16898. OUT PULONG ReturnedLength
  16899. );
  16900. typedef
  16901. NTSTATUS
  16902. (*pHalSetSystemInformation)(
  16903. IN HAL_SET_INFORMATION_CLASS InformationClass,
  16904. IN ULONG BufferSize,
  16905. IN PVOID Buffer
  16906. );
  16907. typedef
  16908. VOID
  16909. (FASTCALL *pHalExamineMBR)(
  16910. IN PDEVICE_OBJECT DeviceObject,
  16911. IN ULONG SectorSize,
  16912. IN ULONG MBRTypeIdentifier,
  16913. OUT PVOID *Buffer
  16914. );
  16915. typedef
  16916. VOID
  16917. (FASTCALL *pHalIoAssignDriveLetters)(
  16918. IN struct _LOADER_PARAMETER_BLOCK *LoaderBlock,
  16919. IN PSTRING NtDeviceName,
  16920. OUT PUCHAR NtSystemPath,
  16921. OUT PSTRING NtSystemPathString
  16922. );
  16923. typedef
  16924. NTSTATUS
  16925. (FASTCALL *pHalIoReadPartitionTable)(
  16926. IN PDEVICE_OBJECT DeviceObject,
  16927. IN ULONG SectorSize,
  16928. IN BOOLEAN ReturnRecognizedPartitions,
  16929. OUT struct _DRIVE_LAYOUT_INFORMATION **PartitionBuffer
  16930. );
  16931. typedef
  16932. NTSTATUS
  16933. (FASTCALL *pHalIoSetPartitionInformation)(
  16934. IN PDEVICE_OBJECT DeviceObject,
  16935. IN ULONG SectorSize,
  16936. IN ULONG PartitionNumber,
  16937. IN ULONG PartitionType
  16938. );
  16939. typedef
  16940. NTSTATUS
  16941. (FASTCALL *pHalIoWritePartitionTable)(
  16942. IN PDEVICE_OBJECT DeviceObject,
  16943. IN ULONG SectorSize,
  16944. IN ULONG SectorsPerTrack,
  16945. IN ULONG NumberOfHeads,
  16946. IN struct _DRIVE_LAYOUT_INFORMATION *PartitionBuffer
  16947. );
  16948. typedef
  16949. NTSTATUS
  16950. (*pHalQueryBusSlots)(
  16951. IN PBUS_HANDLER BusHandler,
  16952. IN ULONG BufferSize,
  16953. OUT PULONG SlotNumbers,
  16954. OUT PULONG ReturnedLength
  16955. );
  16956. typedef
  16957. NTSTATUS
  16958. (*pHalInitPnpDriver)(
  16959. VOID
  16960. );
  16961. typedef struct _PM_DISPATCH_TABLE {
  16962. ULONG Signature;
  16963. ULONG Version;
  16964. PVOID Function[1];
  16965. } PM_DISPATCH_TABLE, *PPM_DISPATCH_TABLE;
  16966. typedef
  16967. NTSTATUS
  16968. (*pHalInitPowerManagement)(
  16969. IN PPM_DISPATCH_TABLE PmDriverDispatchTable,
  16970. OUT PPM_DISPATCH_TABLE *PmHalDispatchTable
  16971. );
  16972. typedef
  16973. struct _DMA_ADAPTER *
  16974. (*pHalGetDmaAdapter)(
  16975. IN PVOID Context,
  16976. IN struct _DEVICE_DESCRIPTION *DeviceDescriptor,
  16977. OUT PULONG NumberOfMapRegisters
  16978. );
  16979. typedef
  16980. NTSTATUS
  16981. (*pHalGetInterruptTranslator)(
  16982. IN INTERFACE_TYPE ParentInterfaceType,
  16983. IN ULONG ParentBusNumber,
  16984. IN INTERFACE_TYPE BridgeInterfaceType,
  16985. IN USHORT Size,
  16986. IN USHORT Version,
  16987. OUT PTRANSLATOR_INTERFACE Translator,
  16988. OUT PULONG BridgeBusNumber
  16989. );
  16990. typedef
  16991. BOOLEAN
  16992. (*pHalTranslateBusAddress)(
  16993. IN INTERFACE_TYPE InterfaceType,
  16994. IN ULONG BusNumber,
  16995. IN PHYSICAL_ADDRESS BusAddress,
  16996. IN OUT PULONG AddressSpace,
  16997. OUT PPHYSICAL_ADDRESS TranslatedAddress
  16998. );
  16999. typedef
  17000. NTSTATUS
  17001. (*pHalAssignSlotResources) (
  17002. IN PUNICODE_STRING RegistryPath,
  17003. IN PUNICODE_STRING DriverClassName OPTIONAL,
  17004. IN PDRIVER_OBJECT DriverObject,
  17005. IN PDEVICE_OBJECT DeviceObject,
  17006. IN INTERFACE_TYPE BusType,
  17007. IN ULONG BusNumber,
  17008. IN ULONG SlotNumber,
  17009. IN OUT PCM_RESOURCE_LIST *AllocatedResources
  17010. );
  17011. typedef
  17012. VOID
  17013. (*pHalHaltSystem) (
  17014. VOID
  17015. );
  17016. typedef
  17017. BOOLEAN
  17018. (*pHalResetDisplay) (
  17019. VOID
  17020. );
  17021. typedef struct _MAP_REGISTER_ENTRY {
  17022. PVOID MapRegister;
  17023. BOOLEAN WriteToDevice;
  17024. } MAP_REGISTER_ENTRY, *PMAP_REGISTER_ENTRY;
  17025. typedef
  17026. UCHAR
  17027. (*pHalVectorToIDTEntry) (
  17028. ULONG Vector
  17029. );
  17030. typedef
  17031. BOOLEAN
  17032. (*pHalFindBusAddressTranslation) (
  17033. IN PHYSICAL_ADDRESS BusAddress,
  17034. IN OUT PULONG AddressSpace,
  17035. OUT PPHYSICAL_ADDRESS TranslatedAddress,
  17036. IN OUT PULONG_PTR Context,
  17037. IN BOOLEAN NextBus
  17038. );
  17039. typedef
  17040. NTSTATUS
  17041. (*pHalStartMirroring)(
  17042. VOID
  17043. );
  17044. typedef
  17045. NTSTATUS
  17046. (*pHalEndMirroring)(
  17047. IN ULONG PassNumber
  17048. );
  17049. typedef
  17050. NTSTATUS
  17051. (*pHalMirrorPhysicalMemory)(
  17052. IN PHYSICAL_ADDRESS PhysicalAddress,
  17053. IN LARGE_INTEGER NumberOfBytes
  17054. );
  17055. typedef
  17056. NTSTATUS
  17057. (*pHalMirrorVerify)(
  17058. IN PHYSICAL_ADDRESS PhysicalAddress,
  17059. IN LARGE_INTEGER NumberOfBytes
  17060. );
  17061. typedef struct {
  17062. UCHAR Type; //CmResourceType
  17063. BOOLEAN Valid;
  17064. UCHAR Reserved[2];
  17065. PUCHAR TranslatedAddress;
  17066. ULONG Length;
  17067. } DEBUG_DEVICE_ADDRESS, *PDEBUG_DEVICE_ADDRESS;
  17068. typedef struct {
  17069. PHYSICAL_ADDRESS Start;
  17070. PHYSICAL_ADDRESS MaxEnd;
  17071. PVOID VirtualAddress;
  17072. ULONG Length;
  17073. BOOLEAN Cached;
  17074. BOOLEAN Aligned;
  17075. } DEBUG_MEMORY_REQUIREMENTS, *PDEBUG_MEMORY_REQUIREMENTS;
  17076. typedef struct {
  17077. ULONG Bus;
  17078. ULONG Slot;
  17079. USHORT VendorID;
  17080. USHORT DeviceID;
  17081. UCHAR BaseClass;
  17082. UCHAR SubClass;
  17083. UCHAR ProgIf;
  17084. BOOLEAN Initialized;
  17085. DEBUG_DEVICE_ADDRESS BaseAddress[6];
  17086. DEBUG_MEMORY_REQUIREMENTS Memory;
  17087. } DEBUG_DEVICE_DESCRIPTOR, *PDEBUG_DEVICE_DESCRIPTOR;
  17088. typedef
  17089. NTSTATUS
  17090. (*pKdSetupPciDeviceForDebugging)(
  17091. IN PVOID LoaderBlock, OPTIONAL
  17092. IN OUT PDEBUG_DEVICE_DESCRIPTOR PciDevice
  17093. );
  17094. typedef
  17095. NTSTATUS
  17096. (*pKdReleasePciDeviceForDebugging)(
  17097. IN OUT PDEBUG_DEVICE_DESCRIPTOR PciDevice
  17098. );
  17099. typedef
  17100. PVOID
  17101. (*pKdGetAcpiTablePhase0)(
  17102. IN struct _LOADER_PARAMETER_BLOCK *LoaderBlock,
  17103. IN ULONG Signature
  17104. );
  17105. typedef
  17106. VOID
  17107. (*pKdCheckPowerButton)(
  17108. VOID
  17109. );
  17110. typedef
  17111. VOID
  17112. (*pHalEndOfBoot)(
  17113. VOID
  17114. );
  17115. typedef
  17116. PVOID
  17117. (*pKdMapPhysicalMemory64)(
  17118. IN PHYSICAL_ADDRESS PhysicalAddress,
  17119. IN ULONG NumberPages
  17120. );
  17121. typedef
  17122. VOID
  17123. (*pKdUnmapVirtualAddress)(
  17124. IN PVOID VirtualAddress,
  17125. IN ULONG NumberPages
  17126. );
  17127. typedef struct {
  17128. ULONG Version;
  17129. pHalQuerySystemInformation HalQuerySystemInformation;
  17130. pHalSetSystemInformation HalSetSystemInformation;
  17131. pHalQueryBusSlots HalQueryBusSlots;
  17132. ULONG Spare1;
  17133. pHalExamineMBR HalExamineMBR;
  17134. pHalIoAssignDriveLetters HalIoAssignDriveLetters;
  17135. pHalIoReadPartitionTable HalIoReadPartitionTable;
  17136. pHalIoSetPartitionInformation HalIoSetPartitionInformation;
  17137. pHalIoWritePartitionTable HalIoWritePartitionTable;
  17138. pHalHandlerForBus HalReferenceHandlerForBus;
  17139. pHalReferenceBusHandler HalReferenceBusHandler;
  17140. pHalReferenceBusHandler HalDereferenceBusHandler;
  17141. pHalInitPnpDriver HalInitPnpDriver;
  17142. pHalInitPowerManagement HalInitPowerManagement;
  17143. pHalGetDmaAdapter HalGetDmaAdapter;
  17144. pHalGetInterruptTranslator HalGetInterruptTranslator;
  17145. pHalStartMirroring HalStartMirroring;
  17146. pHalEndMirroring HalEndMirroring;
  17147. pHalMirrorPhysicalMemory HalMirrorPhysicalMemory;
  17148. pHalEndOfBoot HalEndOfBoot;
  17149. pHalMirrorVerify HalMirrorVerify;
  17150. } HAL_DISPATCH, *PHAL_DISPATCH;
  17151. #if defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_) || defined(_NTHAL_)
  17152. extern PHAL_DISPATCH HalDispatchTable;
  17153. #define HALDISPATCH HalDispatchTable
  17154. #else
  17155. extern HAL_DISPATCH HalDispatchTable;
  17156. #define HALDISPATCH (&HalDispatchTable)
  17157. #endif
  17158. #define HAL_DISPATCH_VERSION 3
  17159. #define HalDispatchTableVersion HALDISPATCH->Version
  17160. #define HalQuerySystemInformation HALDISPATCH->HalQuerySystemInformation
  17161. #define HalSetSystemInformation HALDISPATCH->HalSetSystemInformation
  17162. #define HalQueryBusSlots HALDISPATCH->HalQueryBusSlots
  17163. #define HalReferenceHandlerForBus HALDISPATCH->HalReferenceHandlerForBus
  17164. #define HalReferenceBusHandler HALDISPATCH->HalReferenceBusHandler
  17165. #define HalDereferenceBusHandler HALDISPATCH->HalDereferenceBusHandler
  17166. #define HalInitPnpDriver HALDISPATCH->HalInitPnpDriver
  17167. #define HalInitPowerManagement HALDISPATCH->HalInitPowerManagement
  17168. #define HalGetDmaAdapter HALDISPATCH->HalGetDmaAdapter
  17169. #define HalGetInterruptTranslator HALDISPATCH->HalGetInterruptTranslator
  17170. #define HalStartMirroring HALDISPATCH->HalStartMirroring
  17171. #define HalEndMirroring HALDISPATCH->HalEndMirroring
  17172. #define HalMirrorPhysicalMemory HALDISPATCH->HalMirrorPhysicalMemory
  17173. #define HalEndOfBoot HALDISPATCH->HalEndOfBoot
  17174. #define HalMirrorVerify HALDISPATCH->HalMirrorVerify
  17175. //
  17176. // HAL System Information Structures.
  17177. //
  17178. // for the information class "HalInstalledBusInformation"
  17179. typedef struct _HAL_BUS_INFORMATION{
  17180. INTERFACE_TYPE BusType;
  17181. BUS_DATA_TYPE ConfigurationType;
  17182. ULONG BusNumber;
  17183. ULONG Reserved;
  17184. } HAL_BUS_INFORMATION, *PHAL_BUS_INFORMATION;
  17185. // for the information class "HalProfileSourceInformation"
  17186. typedef struct _HAL_PROFILE_SOURCE_INFORMATION {
  17187. KPROFILE_SOURCE Source;
  17188. BOOLEAN Supported;
  17189. ULONG Interval;
  17190. } HAL_PROFILE_SOURCE_INFORMATION, *PHAL_PROFILE_SOURCE_INFORMATION;
  17191. // for the information class "HalProfileSourceInformation"
  17192. typedef struct _HAL_PROFILE_SOURCE_INFORMATION_EX {
  17193. KPROFILE_SOURCE Source;
  17194. BOOLEAN Supported;
  17195. ULONG_PTR Interval;
  17196. ULONG_PTR DefInterval;
  17197. ULONG_PTR MaxInterval;
  17198. ULONG_PTR MinInterval;
  17199. } HAL_PROFILE_SOURCE_INFORMATION_EX, *PHAL_PROFILE_SOURCE_INFORMATION_EX;
  17200. // for the information class "HalProfileSourceInterval"
  17201. typedef struct _HAL_PROFILE_SOURCE_INTERVAL {
  17202. KPROFILE_SOURCE Source;
  17203. ULONG_PTR Interval;
  17204. } HAL_PROFILE_SOURCE_INTERVAL, *PHAL_PROFILE_SOURCE_INTERVAL;
  17205. // for the information class "HalQueryProfileSourceList"
  17206. typedef struct _HAL_PROFILE_SOURCE_LIST {
  17207. KPROFILE_SOURCE Source;
  17208. PWSTR Description;
  17209. } HAL_PROFILE_SOURCE_LIST, *PHAL_PROFILE_SOURCE_LIST;
  17210. // for the information class "HalDispayBiosInformation"
  17211. typedef enum _HAL_DISPLAY_BIOS_INFORMATION {
  17212. HalDisplayInt10Bios,
  17213. HalDisplayEmulatedBios,
  17214. HalDisplayNoBios
  17215. } HAL_DISPLAY_BIOS_INFORMATION, *PHAL_DISPLAY_BIOS_INFORMATION;
  17216. // for the information class "HalPowerInformation"
  17217. typedef struct _HAL_POWER_INFORMATION {
  17218. ULONG TBD;
  17219. } HAL_POWER_INFORMATION, *PHAL_POWER_INFORMATION;
  17220. // for the information class "HalProcessorSpeedInformation"
  17221. typedef struct _HAL_PROCESSOR_SPEED_INFO {
  17222. ULONG ProcessorSpeed;
  17223. } HAL_PROCESSOR_SPEED_INFORMATION, *PHAL_PROCESSOR_SPEED_INFORMATION;
  17224. // for the information class "HalCallbackInformation"
  17225. typedef struct _HAL_CALLBACKS {
  17226. PCALLBACK_OBJECT SetSystemInformation;
  17227. PCALLBACK_OBJECT BusCheck;
  17228. } HAL_CALLBACKS, *PHAL_CALLBACKS;
  17229. // for the information class "HalProcessorFeatureInformation"
  17230. typedef struct _HAL_PROCESSOR_FEATURE {
  17231. ULONG UsableFeatureBits;
  17232. } HAL_PROCESSOR_FEATURE;
  17233. // for the information class "HalNumaTopologyInterface"
  17234. typedef ULONG HALNUMAPAGETONODE;
  17235. typedef
  17236. HALNUMAPAGETONODE
  17237. (*PHALNUMAPAGETONODE)(
  17238. IN ULONG_PTR PhysicalPageNumber
  17239. );
  17240. typedef
  17241. NTSTATUS
  17242. (*PHALNUMAQUERYPROCESSORNODE)(
  17243. IN ULONG ProcessorNumber,
  17244. OUT PUSHORT Identifier,
  17245. OUT PUCHAR Node
  17246. );
  17247. typedef struct _HAL_NUMA_TOPOLOGY_INTERFACE {
  17248. ULONG NumberOfNodes;
  17249. PHALNUMAQUERYPROCESSORNODE QueryProcessorNode;
  17250. PHALNUMAPAGETONODE PageToNode;
  17251. } HAL_NUMA_TOPOLOGY_INTERFACE;
  17252. typedef
  17253. NTSTATUS
  17254. (*PHALIOREADWRITEHANDLER)(
  17255. IN BOOLEAN fRead,
  17256. IN ULONG dwAddr,
  17257. IN ULONG dwSize,
  17258. IN OUT PULONG pdwData
  17259. );
  17260. // for the information class "HalQueryIllegalIOPortAddresses"
  17261. typedef struct _HAL_AMLI_BAD_IO_ADDRESS_LIST
  17262. {
  17263. ULONG BadAddrBegin;
  17264. ULONG BadAddrSize;
  17265. ULONG OSVersionTrigger;
  17266. PHALIOREADWRITEHANDLER IOHandler;
  17267. } HAL_AMLI_BAD_IO_ADDRESS_LIST, *PHAL_AMLI_BAD_IO_ADDRESS_LIST;
  17268. #if defined(_X86_) || defined(_IA64_) || defined(_AMD64_)
  17269. //
  17270. // HalQueryMcaInterface
  17271. //
  17272. typedef
  17273. VOID
  17274. (*PHALMCAINTERFACELOCK)(
  17275. VOID
  17276. );
  17277. typedef
  17278. VOID
  17279. (*PHALMCAINTERFACEUNLOCK)(
  17280. VOID
  17281. );
  17282. typedef
  17283. NTSTATUS
  17284. (*PHALMCAINTERFACEREADREGISTER)(
  17285. IN UCHAR BankNumber,
  17286. IN OUT PVOID Exception
  17287. );
  17288. typedef struct _HAL_MCA_INTERFACE {
  17289. PHALMCAINTERFACELOCK Lock;
  17290. PHALMCAINTERFACEUNLOCK Unlock;
  17291. PHALMCAINTERFACEREADREGISTER ReadRegister;
  17292. } HAL_MCA_INTERFACE;
  17293. #if defined(_AMD64_)
  17294. struct _KTRAP_FRAME;
  17295. struct _KEXCEPTION_FRAME;
  17296. typedef
  17297. ERROR_SEVERITY
  17298. (*PDRIVER_EXCPTN_CALLBACK) (
  17299. IN PVOID Context,
  17300. IN struct _KTRAP_FRAME *TrapFrame,
  17301. IN struct _KEXCEPTION_FRAME *ExceptionFrame,
  17302. IN PMCA_EXCEPTION Exception
  17303. );
  17304. #endif
  17305. #if defined(_X86_) || defined(_IA64_)
  17306. typedef
  17307. #if defined(_IA64_)
  17308. ERROR_SEVERITY
  17309. #else
  17310. VOID
  17311. #endif
  17312. (*PDRIVER_EXCPTN_CALLBACK) (
  17313. IN PVOID Context,
  17314. IN PMCA_EXCEPTION BankLog
  17315. );
  17316. #endif
  17317. typedef PDRIVER_EXCPTN_CALLBACK PDRIVER_MCA_EXCEPTION_CALLBACK;
  17318. //
  17319. // Structure to record the callbacks from driver
  17320. //
  17321. typedef struct _MCA_DRIVER_INFO {
  17322. PDRIVER_MCA_EXCEPTION_CALLBACK ExceptionCallback;
  17323. PKDEFERRED_ROUTINE DpcCallback;
  17324. PVOID DeviceContext;
  17325. } MCA_DRIVER_INFO, *PMCA_DRIVER_INFO;
  17326. typedef struct _HAL_ERROR_INFO {
  17327. ULONG Version; // Version of this structure
  17328. ULONG Reserved; //
  17329. ULONG McaMaxSize; // Maximum size of a Machine Check Abort record
  17330. ULONG McaPreviousEventsCount; // Flag indicating previous or early-boot MCA event logs.
  17331. ULONG McaCorrectedEventsCount; // Number of corrected MCA events since boot. approx.
  17332. ULONG McaKernelDeliveryFails; // Number of Kernel callback failures. approx.
  17333. ULONG McaDriverDpcQueueFails; // Number of OEM MCA Driver Dpc queueing failures. approx.
  17334. ULONG McaReserved;
  17335. ULONG CmcMaxSize; // Maximum size of a Corrected Machine Check record
  17336. ULONG CmcPollingInterval; // In units of seconds
  17337. ULONG CmcInterruptsCount; // Number of CMC interrupts. approx.
  17338. ULONG CmcKernelDeliveryFails; // Number of Kernel callback failures. approx.
  17339. ULONG CmcDriverDpcQueueFails; // Number of OEM CMC Driver Dpc queueing failures. approx.
  17340. ULONG CmcGetStateFails; // Number of failures in getting the log from FW.
  17341. ULONG CmcClearStateFails; // Number of failures in clearing the log from FW.
  17342. ULONG CmcReserved;
  17343. ULONGLONG CmcLogId; // Last seen record identifier.
  17344. ULONG CpeMaxSize; // Maximum size of a Corrected Platform Event record
  17345. ULONG CpePollingInterval; // In units of seconds
  17346. ULONG CpeInterruptsCount; // Number of CPE interrupts. approx.
  17347. ULONG CpeKernelDeliveryFails; // Number of Kernel callback failures. approx.
  17348. ULONG CpeDriverDpcQueueFails; // Number of OEM CPE Driver Dpc queueing failures. approx.
  17349. ULONG CpeGetStateFails; // Number of failures in getting the log from FW.
  17350. ULONG CpeClearStateFails; // Number of failures in clearing the log from FW.
  17351. ULONG CpeInterruptSources; // Number of SAPIC Platform Interrupt Sources
  17352. ULONGLONG CpeLogId; // Last seen record identifier.
  17353. ULONGLONG KernelReserved[4];
  17354. } HAL_ERROR_INFO, *PHAL_ERROR_INFO;
  17355. #define HAL_MCE_INTERRUPTS_BASED ((ULONG)-1)
  17356. #define HAL_MCE_DISABLED ((ULONG)0)
  17357. //
  17358. // Known values for HAL_ERROR_INFO.CmcPollingInterval.
  17359. //
  17360. #define HAL_CMC_INTERRUPTS_BASED HAL_MCE_INTERRUPTS_BASED
  17361. #define HAL_CMC_DISABLED HAL_MCE_DISABLED
  17362. //
  17363. // Known values for HAL_ERROR_INFO.CpePollingInterval.
  17364. //
  17365. #define HAL_CPE_INTERRUPTS_BASED HAL_MCE_INTERRUPTS_BASED
  17366. #define HAL_CPE_DISABLED HAL_MCE_DISABLED
  17367. #define HAL_MCA_INTERRUPTS_BASED HAL_MCE_INTERRUPTS_BASED
  17368. #define HAL_MCA_DISABLED HAL_MCE_DISABLED
  17369. //
  17370. // Driver Callback type for the information class "HalCmcRegisterDriver"
  17371. //
  17372. typedef
  17373. VOID
  17374. (*PDRIVER_CMC_EXCEPTION_CALLBACK) (
  17375. IN PVOID Context,
  17376. IN PCMC_EXCEPTION CmcLog
  17377. );
  17378. //
  17379. // Driver Callback type for the information class "HalCpeRegisterDriver"
  17380. //
  17381. typedef
  17382. VOID
  17383. (*PDRIVER_CPE_EXCEPTION_CALLBACK) (
  17384. IN PVOID Context,
  17385. IN PCPE_EXCEPTION CmcLog
  17386. );
  17387. //
  17388. //
  17389. // Structure to record the callbacks from driver
  17390. //
  17391. typedef struct _CMC_DRIVER_INFO {
  17392. PDRIVER_CMC_EXCEPTION_CALLBACK ExceptionCallback;
  17393. PKDEFERRED_ROUTINE DpcCallback;
  17394. PVOID DeviceContext;
  17395. } CMC_DRIVER_INFO, *PCMC_DRIVER_INFO;
  17396. typedef struct _CPE_DRIVER_INFO {
  17397. PDRIVER_CPE_EXCEPTION_CALLBACK ExceptionCallback;
  17398. PKDEFERRED_ROUTINE DpcCallback;
  17399. PVOID DeviceContext;
  17400. } CPE_DRIVER_INFO, *PCPE_DRIVER_INFO;
  17401. #endif // defined(_X86_) || defined(_IA64_) || defined(_AMD64_)
  17402. #if defined(_IA64_)
  17403. typedef
  17404. NTSTATUS
  17405. (*HALSENDCROSSPARTITIONIPI)(
  17406. IN USHORT ProcessorID,
  17407. IN UCHAR HardwareVector
  17408. );
  17409. typedef
  17410. NTSTATUS
  17411. (*HALRESERVECROSSPARTITIONINTERRUPTVECTOR)(
  17412. OUT PULONG Vector,
  17413. OUT PKIRQL Irql,
  17414. IN OUT PKAFFINITY Affinity,
  17415. OUT PUCHAR HardwareVector
  17416. );
  17417. typedef struct _HAL_CROSS_PARTITION_IPI_INTERFACE {
  17418. HALSENDCROSSPARTITIONIPI HalSendCrossPartitionIpi;
  17419. HALRESERVECROSSPARTITIONINTERRUPTVECTOR HalReserveCrossPartitionInterruptVector;
  17420. } HAL_CROSS_PARTITION_IPI_INTERFACE;
  17421. #endif
  17422. typedef struct _HAL_PLATFORM_INFORMATION {
  17423. ULONG PlatformFlags;
  17424. } HAL_PLATFORM_INFORMATION, *PHAL_PLATFORM_INFORMATION;
  17425. //
  17426. // These platform flags are carried over from the IPPT table
  17427. // definition if appropriate.
  17428. //
  17429. #define HAL_PLATFORM_DISABLE_WRITE_COMBINING 0x01L
  17430. #define HAL_PLATFORM_DISABLE_PTCG 0x04L
  17431. #define HAL_PLATFORM_DISABLE_UC_MAIN_MEMORY 0x08L
  17432. #define HAL_PLATFORM_ENABLE_WRITE_COMBINING_MMIO 0x10L
  17433. #define HAL_PLATFORM_ACPI_TABLES_CACHED 0x20L
  17434. typedef struct _SCATTER_GATHER_ELEMENT {
  17435. PHYSICAL_ADDRESS Address;
  17436. ULONG Length;
  17437. ULONG_PTR Reserved;
  17438. } SCATTER_GATHER_ELEMENT, *PSCATTER_GATHER_ELEMENT;
  17439. #if _MSC_VER >= 1200
  17440. #pragma warning(push)
  17441. #endif
  17442. #pragma warning(disable:4200)
  17443. typedef struct _SCATTER_GATHER_LIST {
  17444. ULONG NumberOfElements;
  17445. ULONG_PTR Reserved;
  17446. SCATTER_GATHER_ELEMENT Elements[];
  17447. } SCATTER_GATHER_LIST, *PSCATTER_GATHER_LIST;
  17448. #if _MSC_VER >= 1200
  17449. #pragma warning(pop)
  17450. #else
  17451. #pragma warning(default:4200)
  17452. #endif
  17453. typedef struct _DMA_OPERATIONS *PDMA_OPERATIONS;
  17454. typedef struct _DMA_ADAPTER {
  17455. USHORT Version;
  17456. USHORT Size;
  17457. PDMA_OPERATIONS DmaOperations;
  17458. // Private Bus Device Driver data follows,
  17459. } DMA_ADAPTER, *PDMA_ADAPTER;
  17460. typedef VOID (*PPUT_DMA_ADAPTER)(
  17461. PDMA_ADAPTER DmaAdapter
  17462. );
  17463. typedef PVOID (*PALLOCATE_COMMON_BUFFER)(
  17464. IN PDMA_ADAPTER DmaAdapter,
  17465. IN ULONG Length,
  17466. OUT PPHYSICAL_ADDRESS LogicalAddress,
  17467. IN BOOLEAN CacheEnabled
  17468. );
  17469. typedef VOID (*PFREE_COMMON_BUFFER)(
  17470. IN PDMA_ADAPTER DmaAdapter,
  17471. IN ULONG Length,
  17472. IN PHYSICAL_ADDRESS LogicalAddress,
  17473. IN PVOID VirtualAddress,
  17474. IN BOOLEAN CacheEnabled
  17475. );
  17476. typedef NTSTATUS (*PALLOCATE_ADAPTER_CHANNEL)(
  17477. IN PDMA_ADAPTER DmaAdapter,
  17478. IN PDEVICE_OBJECT DeviceObject,
  17479. IN ULONG NumberOfMapRegisters,
  17480. IN PDRIVER_CONTROL ExecutionRoutine,
  17481. IN PVOID Context
  17482. );
  17483. typedef BOOLEAN (*PFLUSH_ADAPTER_BUFFERS)(
  17484. IN PDMA_ADAPTER DmaAdapter,
  17485. IN PMDL Mdl,
  17486. IN PVOID MapRegisterBase,
  17487. IN PVOID CurrentVa,
  17488. IN ULONG Length,
  17489. IN BOOLEAN WriteToDevice
  17490. );
  17491. typedef VOID (*PFREE_ADAPTER_CHANNEL)(
  17492. IN PDMA_ADAPTER DmaAdapter
  17493. );
  17494. typedef VOID (*PFREE_MAP_REGISTERS)(
  17495. IN PDMA_ADAPTER DmaAdapter,
  17496. PVOID MapRegisterBase,
  17497. ULONG NumberOfMapRegisters
  17498. );
  17499. typedef PHYSICAL_ADDRESS (*PMAP_TRANSFER)(
  17500. IN PDMA_ADAPTER DmaAdapter,
  17501. IN PMDL Mdl,
  17502. IN PVOID MapRegisterBase,
  17503. IN PVOID CurrentVa,
  17504. IN OUT PULONG Length,
  17505. IN BOOLEAN WriteToDevice
  17506. );
  17507. typedef ULONG (*PGET_DMA_ALIGNMENT)(
  17508. IN PDMA_ADAPTER DmaAdapter
  17509. );
  17510. typedef ULONG (*PREAD_DMA_COUNTER)(
  17511. IN PDMA_ADAPTER DmaAdapter
  17512. );
  17513. typedef VOID
  17514. (*PDRIVER_LIST_CONTROL)(
  17515. IN struct _DEVICE_OBJECT *DeviceObject,
  17516. IN struct _IRP *Irp,
  17517. IN PSCATTER_GATHER_LIST ScatterGather,
  17518. IN PVOID Context
  17519. );
  17520. typedef NTSTATUS
  17521. (*PGET_SCATTER_GATHER_LIST)(
  17522. IN PDMA_ADAPTER DmaAdapter,
  17523. IN PDEVICE_OBJECT DeviceObject,
  17524. IN PMDL Mdl,
  17525. IN PVOID CurrentVa,
  17526. IN ULONG Length,
  17527. IN PDRIVER_LIST_CONTROL ExecutionRoutine,
  17528. IN PVOID Context,
  17529. IN BOOLEAN WriteToDevice
  17530. );
  17531. typedef VOID
  17532. (*PPUT_SCATTER_GATHER_LIST)(
  17533. IN PDMA_ADAPTER DmaAdapter,
  17534. IN PSCATTER_GATHER_LIST ScatterGather,
  17535. IN BOOLEAN WriteToDevice
  17536. );
  17537. typedef NTSTATUS
  17538. (*PCALCULATE_SCATTER_GATHER_LIST_SIZE)(
  17539. IN PDMA_ADAPTER DmaAdapter,
  17540. IN OPTIONAL PMDL Mdl,
  17541. IN PVOID CurrentVa,
  17542. IN ULONG Length,
  17543. OUT PULONG ScatterGatherListSize,
  17544. OUT OPTIONAL PULONG pNumberOfMapRegisters
  17545. );
  17546. typedef NTSTATUS
  17547. (*PBUILD_SCATTER_GATHER_LIST)(
  17548. IN PDMA_ADAPTER DmaAdapter,
  17549. IN PDEVICE_OBJECT DeviceObject,
  17550. IN PMDL Mdl,
  17551. IN PVOID CurrentVa,
  17552. IN ULONG Length,
  17553. IN PDRIVER_LIST_CONTROL ExecutionRoutine,
  17554. IN PVOID Context,
  17555. IN BOOLEAN WriteToDevice,
  17556. IN PVOID ScatterGatherBuffer,
  17557. IN ULONG ScatterGatherLength
  17558. );
  17559. typedef NTSTATUS
  17560. (*PBUILD_MDL_FROM_SCATTER_GATHER_LIST)(
  17561. IN PDMA_ADAPTER DmaAdapter,
  17562. IN PSCATTER_GATHER_LIST ScatterGather,
  17563. IN PMDL OriginalMdl,
  17564. OUT PMDL *TargetMdl
  17565. );
  17566. typedef struct _DMA_OPERATIONS {
  17567. ULONG Size;
  17568. PPUT_DMA_ADAPTER PutDmaAdapter;
  17569. PALLOCATE_COMMON_BUFFER AllocateCommonBuffer;
  17570. PFREE_COMMON_BUFFER FreeCommonBuffer;
  17571. PALLOCATE_ADAPTER_CHANNEL AllocateAdapterChannel;
  17572. PFLUSH_ADAPTER_BUFFERS FlushAdapterBuffers;
  17573. PFREE_ADAPTER_CHANNEL FreeAdapterChannel;
  17574. PFREE_MAP_REGISTERS FreeMapRegisters;
  17575. PMAP_TRANSFER MapTransfer;
  17576. PGET_DMA_ALIGNMENT GetDmaAlignment;
  17577. PREAD_DMA_COUNTER ReadDmaCounter;
  17578. PGET_SCATTER_GATHER_LIST GetScatterGatherList;
  17579. PPUT_SCATTER_GATHER_LIST PutScatterGatherList;
  17580. PCALCULATE_SCATTER_GATHER_LIST_SIZE CalculateScatterGatherList;
  17581. PBUILD_SCATTER_GATHER_LIST BuildScatterGatherList;
  17582. PBUILD_MDL_FROM_SCATTER_GATHER_LIST BuildMdlFromScatterGatherList;
  17583. } DMA_OPERATIONS;
  17584. #if defined(_WIN64)
  17585. //
  17586. // Use __inline DMA macros (hal.h)
  17587. //
  17588. #ifndef USE_DMA_MACROS
  17589. #define USE_DMA_MACROS
  17590. #endif
  17591. //
  17592. // Only PnP drivers!
  17593. //
  17594. #ifndef NO_LEGACY_DRIVERS
  17595. #define NO_LEGACY_DRIVERS
  17596. #endif
  17597. #endif // _WIN64
  17598. #if defined(USE_DMA_MACROS) && (defined(_NTDDK_) || defined(_NTDRIVER_))
  17599. DECLSPEC_DEPRECATED_DDK // Use AllocateCommonBuffer
  17600. FORCEINLINE
  17601. PVOID
  17602. HalAllocateCommonBuffer(
  17603. IN PDMA_ADAPTER DmaAdapter,
  17604. IN ULONG Length,
  17605. OUT PPHYSICAL_ADDRESS LogicalAddress,
  17606. IN BOOLEAN CacheEnabled
  17607. ){
  17608. PALLOCATE_COMMON_BUFFER allocateCommonBuffer;
  17609. PVOID commonBuffer;
  17610. allocateCommonBuffer = *(DmaAdapter)->DmaOperations->AllocateCommonBuffer;
  17611. ASSERT( allocateCommonBuffer != NULL );
  17612. commonBuffer = allocateCommonBuffer( DmaAdapter,
  17613. Length,
  17614. LogicalAddress,
  17615. CacheEnabled );
  17616. return commonBuffer;
  17617. }
  17618. DECLSPEC_DEPRECATED_DDK // Use FreeCommonBuffer
  17619. FORCEINLINE
  17620. VOID
  17621. HalFreeCommonBuffer(
  17622. IN PDMA_ADAPTER DmaAdapter,
  17623. IN ULONG Length,
  17624. IN PHYSICAL_ADDRESS LogicalAddress,
  17625. IN PVOID VirtualAddress,
  17626. IN BOOLEAN CacheEnabled
  17627. ){
  17628. PFREE_COMMON_BUFFER freeCommonBuffer;
  17629. freeCommonBuffer = *(DmaAdapter)->DmaOperations->FreeCommonBuffer;
  17630. ASSERT( freeCommonBuffer != NULL );
  17631. freeCommonBuffer( DmaAdapter,
  17632. Length,
  17633. LogicalAddress,
  17634. VirtualAddress,
  17635. CacheEnabled );
  17636. }
  17637. DECLSPEC_DEPRECATED_DDK // Use AllocateAdapterChannel
  17638. FORCEINLINE
  17639. NTSTATUS
  17640. IoAllocateAdapterChannel(
  17641. IN PDMA_ADAPTER DmaAdapter,
  17642. IN PDEVICE_OBJECT DeviceObject,
  17643. IN ULONG NumberOfMapRegisters,
  17644. IN PDRIVER_CONTROL ExecutionRoutine,
  17645. IN PVOID Context
  17646. ){
  17647. PALLOCATE_ADAPTER_CHANNEL allocateAdapterChannel;
  17648. NTSTATUS status;
  17649. allocateAdapterChannel =
  17650. *(DmaAdapter)->DmaOperations->AllocateAdapterChannel;
  17651. ASSERT( allocateAdapterChannel != NULL );
  17652. status = allocateAdapterChannel( DmaAdapter,
  17653. DeviceObject,
  17654. NumberOfMapRegisters,
  17655. ExecutionRoutine,
  17656. Context );
  17657. return status;
  17658. }
  17659. DECLSPEC_DEPRECATED_DDK // Use FlushAdapterBuffers
  17660. FORCEINLINE
  17661. BOOLEAN
  17662. IoFlushAdapterBuffers(
  17663. IN PDMA_ADAPTER DmaAdapter,
  17664. IN PMDL Mdl,
  17665. IN PVOID MapRegisterBase,
  17666. IN PVOID CurrentVa,
  17667. IN ULONG Length,
  17668. IN BOOLEAN WriteToDevice
  17669. ){
  17670. PFLUSH_ADAPTER_BUFFERS flushAdapterBuffers;
  17671. BOOLEAN result;
  17672. flushAdapterBuffers = *(DmaAdapter)->DmaOperations->FlushAdapterBuffers;
  17673. ASSERT( flushAdapterBuffers != NULL );
  17674. result = flushAdapterBuffers( DmaAdapter,
  17675. Mdl,
  17676. MapRegisterBase,
  17677. CurrentVa,
  17678. Length,
  17679. WriteToDevice );
  17680. return result;
  17681. }
  17682. DECLSPEC_DEPRECATED_DDK // Use FreeAdapterChannel
  17683. FORCEINLINE
  17684. VOID
  17685. IoFreeAdapterChannel(
  17686. IN PDMA_ADAPTER DmaAdapter
  17687. ){
  17688. PFREE_ADAPTER_CHANNEL freeAdapterChannel;
  17689. freeAdapterChannel = *(DmaAdapter)->DmaOperations->FreeAdapterChannel;
  17690. ASSERT( freeAdapterChannel != NULL );
  17691. freeAdapterChannel( DmaAdapter );
  17692. }
  17693. DECLSPEC_DEPRECATED_DDK // Use FreeMapRegisters
  17694. FORCEINLINE
  17695. VOID
  17696. IoFreeMapRegisters(
  17697. IN PDMA_ADAPTER DmaAdapter,
  17698. IN PVOID MapRegisterBase,
  17699. IN ULONG NumberOfMapRegisters
  17700. ){
  17701. PFREE_MAP_REGISTERS freeMapRegisters;
  17702. freeMapRegisters = *(DmaAdapter)->DmaOperations->FreeMapRegisters;
  17703. ASSERT( freeMapRegisters != NULL );
  17704. freeMapRegisters( DmaAdapter,
  17705. MapRegisterBase,
  17706. NumberOfMapRegisters );
  17707. }
  17708. DECLSPEC_DEPRECATED_DDK // Use MapTransfer
  17709. FORCEINLINE
  17710. PHYSICAL_ADDRESS
  17711. IoMapTransfer(
  17712. IN PDMA_ADAPTER DmaAdapter,
  17713. IN PMDL Mdl,
  17714. IN PVOID MapRegisterBase,
  17715. IN PVOID CurrentVa,
  17716. IN OUT PULONG Length,
  17717. IN BOOLEAN WriteToDevice
  17718. ){
  17719. PHYSICAL_ADDRESS physicalAddress;
  17720. PMAP_TRANSFER mapTransfer;
  17721. mapTransfer = *(DmaAdapter)->DmaOperations->MapTransfer;
  17722. ASSERT( mapTransfer != NULL );
  17723. physicalAddress = mapTransfer( DmaAdapter,
  17724. Mdl,
  17725. MapRegisterBase,
  17726. CurrentVa,
  17727. Length,
  17728. WriteToDevice );
  17729. return physicalAddress;
  17730. }
  17731. DECLSPEC_DEPRECATED_DDK // Use GetDmaAlignment
  17732. FORCEINLINE
  17733. ULONG
  17734. HalGetDmaAlignment(
  17735. IN PDMA_ADAPTER DmaAdapter
  17736. )
  17737. {
  17738. PGET_DMA_ALIGNMENT getDmaAlignment;
  17739. ULONG alignment;
  17740. getDmaAlignment = *(DmaAdapter)->DmaOperations->GetDmaAlignment;
  17741. ASSERT( getDmaAlignment != NULL );
  17742. alignment = getDmaAlignment( DmaAdapter );
  17743. return alignment;
  17744. }
  17745. DECLSPEC_DEPRECATED_DDK // Use ReadDmaCounter
  17746. FORCEINLINE
  17747. ULONG
  17748. HalReadDmaCounter(
  17749. IN PDMA_ADAPTER DmaAdapter
  17750. )
  17751. {
  17752. PREAD_DMA_COUNTER readDmaCounter;
  17753. ULONG counter;
  17754. readDmaCounter = *(DmaAdapter)->DmaOperations->ReadDmaCounter;
  17755. ASSERT( readDmaCounter != NULL );
  17756. counter = readDmaCounter( DmaAdapter );
  17757. return counter;
  17758. }
  17759. #else
  17760. //
  17761. // DMA adapter object functions.
  17762. //
  17763. DECLSPEC_DEPRECATED_DDK // Use AllocateAdapterChannel
  17764. NTHALAPI
  17765. NTSTATUS
  17766. HalAllocateAdapterChannel(
  17767. IN PADAPTER_OBJECT AdapterObject,
  17768. IN PWAIT_CONTEXT_BLOCK Wcb,
  17769. IN ULONG NumberOfMapRegisters,
  17770. IN PDRIVER_CONTROL ExecutionRoutine
  17771. );
  17772. DECLSPEC_DEPRECATED_DDK // Use AllocateCommonBuffer
  17773. NTHALAPI
  17774. PVOID
  17775. HalAllocateCommonBuffer(
  17776. IN PADAPTER_OBJECT AdapterObject,
  17777. IN ULONG Length,
  17778. OUT PPHYSICAL_ADDRESS LogicalAddress,
  17779. IN BOOLEAN CacheEnabled
  17780. );
  17781. DECLSPEC_DEPRECATED_DDK // Use FreeCommonBuffer
  17782. NTHALAPI
  17783. VOID
  17784. HalFreeCommonBuffer(
  17785. IN PADAPTER_OBJECT AdapterObject,
  17786. IN ULONG Length,
  17787. IN PHYSICAL_ADDRESS LogicalAddress,
  17788. IN PVOID VirtualAddress,
  17789. IN BOOLEAN CacheEnabled
  17790. );
  17791. DECLSPEC_DEPRECATED_DDK // Use ReadDmaCounter
  17792. NTHALAPI
  17793. ULONG
  17794. HalReadDmaCounter(
  17795. IN PADAPTER_OBJECT AdapterObject
  17796. );
  17797. DECLSPEC_DEPRECATED_DDK // Use FlushAdapterBuffers
  17798. NTHALAPI
  17799. BOOLEAN
  17800. IoFlushAdapterBuffers(
  17801. IN PADAPTER_OBJECT AdapterObject,
  17802. IN PMDL Mdl,
  17803. IN PVOID MapRegisterBase,
  17804. IN PVOID CurrentVa,
  17805. IN ULONG Length,
  17806. IN BOOLEAN WriteToDevice
  17807. );
  17808. DECLSPEC_DEPRECATED_DDK // Use FreeAdapterChannel
  17809. NTHALAPI
  17810. VOID
  17811. IoFreeAdapterChannel(
  17812. IN PADAPTER_OBJECT AdapterObject
  17813. );
  17814. DECLSPEC_DEPRECATED_DDK // Use FreeMapRegisters
  17815. NTHALAPI
  17816. VOID
  17817. IoFreeMapRegisters(
  17818. IN PADAPTER_OBJECT AdapterObject,
  17819. IN PVOID MapRegisterBase,
  17820. IN ULONG NumberOfMapRegisters
  17821. );
  17822. DECLSPEC_DEPRECATED_DDK // Use MapTransfer
  17823. NTHALAPI
  17824. PHYSICAL_ADDRESS
  17825. IoMapTransfer(
  17826. IN PADAPTER_OBJECT AdapterObject,
  17827. IN PMDL Mdl,
  17828. IN PVOID MapRegisterBase,
  17829. IN PVOID CurrentVa,
  17830. IN OUT PULONG Length,
  17831. IN BOOLEAN WriteToDevice
  17832. );
  17833. #endif // USE_DMA_MACROS && (_NTDDK_ || _NTDRIVER_)
  17834. DECLSPEC_DEPRECATED_DDK
  17835. NTSTATUS
  17836. HalGetScatterGatherList ( // Use GetScatterGatherList
  17837. IN PADAPTER_OBJECT DmaAdapter,
  17838. IN PDEVICE_OBJECT DeviceObject,
  17839. IN PMDL Mdl,
  17840. IN PVOID CurrentVa,
  17841. IN ULONG Length,
  17842. IN PDRIVER_LIST_CONTROL ExecutionRoutine,
  17843. IN PVOID Context,
  17844. IN BOOLEAN WriteToDevice
  17845. );
  17846. DECLSPEC_DEPRECATED_DDK // Use PutScatterGatherList
  17847. VOID
  17848. HalPutScatterGatherList (
  17849. IN PADAPTER_OBJECT DmaAdapter,
  17850. IN PSCATTER_GATHER_LIST ScatterGather,
  17851. IN BOOLEAN WriteToDevice
  17852. );
  17853. DECLSPEC_DEPRECATED_DDK // Use PutDmaAdapter
  17854. VOID
  17855. HalPutDmaAdapter(
  17856. IN PADAPTER_OBJECT DmaAdapter
  17857. );
  17858. NTKERNELAPI
  17859. VOID
  17860. PoSetSystemState (
  17861. IN EXECUTION_STATE Flags
  17862. );
  17863. NTKERNELAPI
  17864. PVOID
  17865. PoRegisterSystemState (
  17866. IN PVOID StateHandle,
  17867. IN EXECUTION_STATE Flags
  17868. );
  17869. typedef
  17870. VOID
  17871. (*PREQUEST_POWER_COMPLETE) (
  17872. IN PDEVICE_OBJECT DeviceObject,
  17873. IN UCHAR MinorFunction,
  17874. IN POWER_STATE PowerState,
  17875. IN PVOID Context,
  17876. IN PIO_STATUS_BLOCK IoStatus
  17877. );
  17878. NTKERNELAPI
  17879. NTSTATUS
  17880. PoRequestPowerIrp (
  17881. IN PDEVICE_OBJECT DeviceObject,
  17882. IN UCHAR MinorFunction,
  17883. IN POWER_STATE PowerState,
  17884. IN PREQUEST_POWER_COMPLETE CompletionFunction,
  17885. IN PVOID Context,
  17886. OUT PIRP *Irp OPTIONAL
  17887. );
  17888. NTKERNELAPI
  17889. NTSTATUS
  17890. PoRequestShutdownEvent (
  17891. OUT PVOID *Event
  17892. );
  17893. NTKERNELAPI
  17894. NTSTATUS
  17895. PoRequestShutdownWait (
  17896. IN PETHREAD Thread
  17897. );
  17898. NTKERNELAPI
  17899. VOID
  17900. PoUnregisterSystemState (
  17901. IN PVOID StateHandle
  17902. );
  17903. NTKERNELAPI
  17904. POWER_STATE
  17905. PoSetPowerState (
  17906. IN PDEVICE_OBJECT DeviceObject,
  17907. IN POWER_STATE_TYPE Type,
  17908. IN POWER_STATE State
  17909. );
  17910. NTKERNELAPI
  17911. NTSTATUS
  17912. PoCallDriver (
  17913. IN PDEVICE_OBJECT DeviceObject,
  17914. IN OUT PIRP Irp
  17915. );
  17916. NTKERNELAPI
  17917. VOID
  17918. PoStartNextPowerIrp(
  17919. IN PIRP Irp
  17920. );
  17921. NTKERNELAPI
  17922. PULONG
  17923. PoRegisterDeviceForIdleDetection (
  17924. IN PDEVICE_OBJECT DeviceObject,
  17925. IN ULONG ConservationIdleTime,
  17926. IN ULONG PerformanceIdleTime,
  17927. IN DEVICE_POWER_STATE State
  17928. );
  17929. #define PoSetDeviceBusy(IdlePointer) \
  17930. *IdlePointer = 0
  17931. //
  17932. // \Callback\PowerState values
  17933. //
  17934. #define PO_CB_SYSTEM_POWER_POLICY 0
  17935. #define PO_CB_AC_STATUS 1
  17936. #define PO_CB_BUTTON_COLLISION 2
  17937. #define PO_CB_SYSTEM_STATE_LOCK 3
  17938. #define PO_CB_LID_SWITCH_STATE 4
  17939. #define PO_CB_PROCESSOR_POWER_POLICY 5
  17940. //
  17941. // Determine if there is a complete device failure on an error.
  17942. //
  17943. NTKERNELAPI
  17944. BOOLEAN
  17945. FsRtlIsTotalDeviceFailure(
  17946. IN NTSTATUS Status
  17947. );
  17948. //
  17949. // Object Manager types
  17950. //
  17951. typedef struct _OBJECT_HANDLE_INFORMATION {
  17952. ULONG HandleAttributes;
  17953. ACCESS_MASK GrantedAccess;
  17954. } OBJECT_HANDLE_INFORMATION, *POBJECT_HANDLE_INFORMATION;
  17955. NTKERNELAPI
  17956. NTSTATUS
  17957. ObReferenceObjectByHandle(
  17958. IN HANDLE Handle,
  17959. IN ACCESS_MASK DesiredAccess,
  17960. IN POBJECT_TYPE ObjectType OPTIONAL,
  17961. IN KPROCESSOR_MODE AccessMode,
  17962. OUT PVOID *Object,
  17963. OUT POBJECT_HANDLE_INFORMATION HandleInformation OPTIONAL
  17964. );
  17965. #define ObDereferenceObject(a) \
  17966. ObfDereferenceObject(a)
  17967. #define ObReferenceObject(Object) ObfReferenceObject(Object)
  17968. NTKERNELAPI
  17969. LONG_PTR
  17970. FASTCALL
  17971. ObfReferenceObject(
  17972. IN PVOID Object
  17973. );
  17974. NTKERNELAPI
  17975. NTSTATUS
  17976. ObReferenceObjectByPointer(
  17977. IN PVOID Object,
  17978. IN ACCESS_MASK DesiredAccess,
  17979. IN POBJECT_TYPE ObjectType,
  17980. IN KPROCESSOR_MODE AccessMode
  17981. );
  17982. NTKERNELAPI
  17983. LONG_PTR
  17984. FASTCALL
  17985. ObfDereferenceObject(
  17986. IN PVOID Object
  17987. );
  17988. NTSTATUS
  17989. ObGetObjectSecurity(
  17990. IN PVOID Object,
  17991. OUT PSECURITY_DESCRIPTOR *SecurityDescriptor,
  17992. OUT PBOOLEAN MemoryAllocated
  17993. );
  17994. VOID
  17995. ObReleaseObjectSecurity(
  17996. IN PSECURITY_DESCRIPTOR SecurityDescriptor,
  17997. IN BOOLEAN MemoryAllocated
  17998. );
  17999. //
  18000. // A PCI driver can read the complete 256 bytes of configuration
  18001. // information for any PCI device by calling:
  18002. //
  18003. // ULONG
  18004. // HalGetBusData (
  18005. // IN BUS_DATA_TYPE PCIConfiguration,
  18006. // IN ULONG PciBusNumber,
  18007. // IN PCI_SLOT_NUMBER VirtualSlotNumber,
  18008. // IN PPCI_COMMON_CONFIG &PCIDeviceConfig,
  18009. // IN ULONG sizeof (PCIDeviceConfig)
  18010. // );
  18011. //
  18012. // A return value of 0 means that the specified PCI bus does not exist.
  18013. //
  18014. // A return value of 2, with a VendorID of PCI_INVALID_VENDORID means
  18015. // that the PCI bus does exist, but there is no device at the specified
  18016. // VirtualSlotNumber (PCI Device/Function number).
  18017. //
  18018. //
  18019. typedef struct _PCI_SLOT_NUMBER {
  18020. union {
  18021. struct {
  18022. ULONG DeviceNumber:5;
  18023. ULONG FunctionNumber:3;
  18024. ULONG Reserved:24;
  18025. } bits;
  18026. ULONG AsULONG;
  18027. } u;
  18028. } PCI_SLOT_NUMBER, *PPCI_SLOT_NUMBER;
  18029. #define PCI_TYPE0_ADDRESSES 6
  18030. #define PCI_TYPE1_ADDRESSES 2
  18031. #define PCI_TYPE2_ADDRESSES 5
  18032. typedef struct _PCI_COMMON_CONFIG {
  18033. USHORT VendorID; // (ro)
  18034. USHORT DeviceID; // (ro)
  18035. USHORT Command; // Device control
  18036. USHORT Status;
  18037. UCHAR RevisionID; // (ro)
  18038. UCHAR ProgIf; // (ro)
  18039. UCHAR SubClass; // (ro)
  18040. UCHAR BaseClass; // (ro)
  18041. UCHAR CacheLineSize; // (ro+)
  18042. UCHAR LatencyTimer; // (ro+)
  18043. UCHAR HeaderType; // (ro)
  18044. UCHAR BIST; // Built in self test
  18045. union {
  18046. struct _PCI_HEADER_TYPE_0 {
  18047. ULONG BaseAddresses[PCI_TYPE0_ADDRESSES];
  18048. ULONG CIS;
  18049. USHORT SubVendorID;
  18050. USHORT SubSystemID;
  18051. ULONG ROMBaseAddress;
  18052. UCHAR CapabilitiesPtr;
  18053. UCHAR Reserved1[3];
  18054. ULONG Reserved2;
  18055. UCHAR InterruptLine; //
  18056. UCHAR InterruptPin; // (ro)
  18057. UCHAR MinimumGrant; // (ro)
  18058. UCHAR MaximumLatency; // (ro)
  18059. } type0;
  18060. //
  18061. // PCI to PCI Bridge
  18062. //
  18063. struct _PCI_HEADER_TYPE_1 {
  18064. ULONG BaseAddresses[PCI_TYPE1_ADDRESSES];
  18065. UCHAR PrimaryBus;
  18066. UCHAR SecondaryBus;
  18067. UCHAR SubordinateBus;
  18068. UCHAR SecondaryLatency;
  18069. UCHAR IOBase;
  18070. UCHAR IOLimit;
  18071. USHORT SecondaryStatus;
  18072. USHORT MemoryBase;
  18073. USHORT MemoryLimit;
  18074. USHORT PrefetchBase;
  18075. USHORT PrefetchLimit;
  18076. ULONG PrefetchBaseUpper32;
  18077. ULONG PrefetchLimitUpper32;
  18078. USHORT IOBaseUpper16;
  18079. USHORT IOLimitUpper16;
  18080. UCHAR CapabilitiesPtr;
  18081. UCHAR Reserved1[3];
  18082. ULONG ROMBaseAddress;
  18083. UCHAR InterruptLine;
  18084. UCHAR InterruptPin;
  18085. USHORT BridgeControl;
  18086. } type1;
  18087. //
  18088. // PCI to CARDBUS Bridge
  18089. //
  18090. struct _PCI_HEADER_TYPE_2 {
  18091. ULONG SocketRegistersBaseAddress;
  18092. UCHAR CapabilitiesPtr;
  18093. UCHAR Reserved;
  18094. USHORT SecondaryStatus;
  18095. UCHAR PrimaryBus;
  18096. UCHAR SecondaryBus;
  18097. UCHAR SubordinateBus;
  18098. UCHAR SecondaryLatency;
  18099. struct {
  18100. ULONG Base;
  18101. ULONG Limit;
  18102. } Range[PCI_TYPE2_ADDRESSES-1];
  18103. UCHAR InterruptLine;
  18104. UCHAR InterruptPin;
  18105. USHORT BridgeControl;
  18106. } type2;
  18107. } u;
  18108. UCHAR DeviceSpecific[192];
  18109. } PCI_COMMON_CONFIG, *PPCI_COMMON_CONFIG;
  18110. #define PCI_COMMON_HDR_LENGTH (FIELD_OFFSET (PCI_COMMON_CONFIG, DeviceSpecific))
  18111. #define PCI_MAX_DEVICES 32
  18112. #define PCI_MAX_FUNCTION 8
  18113. #define PCI_MAX_BRIDGE_NUMBER 0xFF
  18114. #define PCI_INVALID_VENDORID 0xFFFF
  18115. //
  18116. // Bit encodings for PCI_COMMON_CONFIG.HeaderType
  18117. //
  18118. #define PCI_MULTIFUNCTION 0x80
  18119. #define PCI_DEVICE_TYPE 0x00
  18120. #define PCI_BRIDGE_TYPE 0x01
  18121. #define PCI_CARDBUS_BRIDGE_TYPE 0x02
  18122. #define PCI_CONFIGURATION_TYPE(PciData) \
  18123. (((PPCI_COMMON_CONFIG)(PciData))->HeaderType & ~PCI_MULTIFUNCTION)
  18124. #define PCI_MULTIFUNCTION_DEVICE(PciData) \
  18125. ((((PPCI_COMMON_CONFIG)(PciData))->HeaderType & PCI_MULTIFUNCTION) != 0)
  18126. //
  18127. // Bit encodings for PCI_COMMON_CONFIG.Command
  18128. //
  18129. #define PCI_ENABLE_IO_SPACE 0x0001
  18130. #define PCI_ENABLE_MEMORY_SPACE 0x0002
  18131. #define PCI_ENABLE_BUS_MASTER 0x0004
  18132. #define PCI_ENABLE_SPECIAL_CYCLES 0x0008
  18133. #define PCI_ENABLE_WRITE_AND_INVALIDATE 0x0010
  18134. #define PCI_ENABLE_VGA_COMPATIBLE_PALETTE 0x0020
  18135. #define PCI_ENABLE_PARITY 0x0040 // (ro+)
  18136. #define PCI_ENABLE_WAIT_CYCLE 0x0080 // (ro+)
  18137. #define PCI_ENABLE_SERR 0x0100 // (ro+)
  18138. #define PCI_ENABLE_FAST_BACK_TO_BACK 0x0200 // (ro)
  18139. //
  18140. // Bit encodings for PCI_COMMON_CONFIG.Status
  18141. //
  18142. #define PCI_STATUS_CAPABILITIES_LIST 0x0010 // (ro)
  18143. #define PCI_STATUS_66MHZ_CAPABLE 0x0020 // (ro)
  18144. #define PCI_STATUS_UDF_SUPPORTED 0x0040 // (ro)
  18145. #define PCI_STATUS_FAST_BACK_TO_BACK 0x0080 // (ro)
  18146. #define PCI_STATUS_DATA_PARITY_DETECTED 0x0100
  18147. #define PCI_STATUS_DEVSEL 0x0600 // 2 bits wide
  18148. #define PCI_STATUS_SIGNALED_TARGET_ABORT 0x0800
  18149. #define PCI_STATUS_RECEIVED_TARGET_ABORT 0x1000
  18150. #define PCI_STATUS_RECEIVED_MASTER_ABORT 0x2000
  18151. #define PCI_STATUS_SIGNALED_SYSTEM_ERROR 0x4000
  18152. #define PCI_STATUS_DETECTED_PARITY_ERROR 0x8000
  18153. //
  18154. // The NT PCI Driver uses a WhichSpace parameter on its CONFIG_READ/WRITE
  18155. // routines. The following values are defined-
  18156. //
  18157. #define PCI_WHICHSPACE_CONFIG 0x0
  18158. #define PCI_WHICHSPACE_ROM 0x52696350
  18159. //
  18160. // PCI Capability IDs
  18161. //
  18162. #define PCI_CAPABILITY_ID_POWER_MANAGEMENT 0x01
  18163. #define PCI_CAPABILITY_ID_AGP 0x02
  18164. #define PCI_CAPABILITY_ID_MSI 0x05
  18165. #define PCI_CAPABILITY_ID_AGP_TARGET 0x0E
  18166. //
  18167. // All PCI Capability structures have the following header.
  18168. //
  18169. // CapabilityID is used to identify the type of the structure (is
  18170. // one of the PCI_CAPABILITY_ID values above.
  18171. //
  18172. // Next is the offset in PCI Configuration space (0x40 - 0xfc) of the
  18173. // next capability structure in the list, or 0x00 if there are no more
  18174. // entries.
  18175. //
  18176. typedef struct _PCI_CAPABILITIES_HEADER {
  18177. UCHAR CapabilityID;
  18178. UCHAR Next;
  18179. } PCI_CAPABILITIES_HEADER, *PPCI_CAPABILITIES_HEADER;
  18180. //
  18181. // Power Management Capability
  18182. //
  18183. typedef struct _PCI_PMC {
  18184. UCHAR Version:3;
  18185. UCHAR PMEClock:1;
  18186. UCHAR Rsvd1:1;
  18187. UCHAR DeviceSpecificInitialization:1;
  18188. UCHAR Rsvd2:2;
  18189. struct _PM_SUPPORT {
  18190. UCHAR Rsvd2:1;
  18191. UCHAR D1:1;
  18192. UCHAR D2:1;
  18193. UCHAR PMED0:1;
  18194. UCHAR PMED1:1;
  18195. UCHAR PMED2:1;
  18196. UCHAR PMED3Hot:1;
  18197. UCHAR PMED3Cold:1;
  18198. } Support;
  18199. } PCI_PMC, *PPCI_PMC;
  18200. typedef struct _PCI_PMCSR {
  18201. USHORT PowerState:2;
  18202. USHORT Rsvd1:6;
  18203. USHORT PMEEnable:1;
  18204. USHORT DataSelect:4;
  18205. USHORT DataScale:2;
  18206. USHORT PMEStatus:1;
  18207. } PCI_PMCSR, *PPCI_PMCSR;
  18208. typedef struct _PCI_PMCSR_BSE {
  18209. UCHAR Rsvd1:6;
  18210. UCHAR D3HotSupportsStopClock:1; // B2_B3#
  18211. UCHAR BusPowerClockControlEnabled:1; // BPCC_EN
  18212. } PCI_PMCSR_BSE, *PPCI_PMCSR_BSE;
  18213. typedef struct _PCI_PM_CAPABILITY {
  18214. PCI_CAPABILITIES_HEADER Header;
  18215. //
  18216. // Power Management Capabilities (Offset = 2)
  18217. //
  18218. union {
  18219. PCI_PMC Capabilities;
  18220. USHORT AsUSHORT;
  18221. } PMC;
  18222. //
  18223. // Power Management Control/Status (Offset = 4)
  18224. //
  18225. union {
  18226. PCI_PMCSR ControlStatus;
  18227. USHORT AsUSHORT;
  18228. } PMCSR;
  18229. //
  18230. // PMCSR PCI-PCI Bridge Support Extensions
  18231. //
  18232. union {
  18233. PCI_PMCSR_BSE BridgeSupport;
  18234. UCHAR AsUCHAR;
  18235. } PMCSR_BSE;
  18236. //
  18237. // Optional read only 8 bit Data register. Contents controlled by
  18238. // DataSelect and DataScale in ControlStatus.
  18239. //
  18240. UCHAR Data;
  18241. } PCI_PM_CAPABILITY, *PPCI_PM_CAPABILITY;
  18242. //
  18243. // AGP Capability
  18244. //
  18245. typedef struct _PCI_AGP_CAPABILITY {
  18246. PCI_CAPABILITIES_HEADER Header;
  18247. USHORT Minor:4;
  18248. USHORT Major:4;
  18249. USHORT Rsvd1:8;
  18250. struct _PCI_AGP_STATUS {
  18251. ULONG Rate:3;
  18252. ULONG Agp3Mode:1;
  18253. ULONG FastWrite:1;
  18254. ULONG FourGB:1;
  18255. ULONG HostTransDisable:1;
  18256. ULONG Gart64:1;
  18257. ULONG ITA_Coherent:1;
  18258. ULONG SideBandAddressing:1; // SBA
  18259. ULONG CalibrationCycle:3;
  18260. ULONG AsyncRequestSize:3;
  18261. ULONG Rsvd1:1;
  18262. ULONG Isoch:1;
  18263. ULONG Rsvd2:6;
  18264. ULONG RequestQueueDepthMaximum:8; // RQ
  18265. } AGPStatus;
  18266. struct _PCI_AGP_COMMAND {
  18267. ULONG Rate:3;
  18268. ULONG Rsvd1:1;
  18269. ULONG FastWriteEnable:1;
  18270. ULONG FourGBEnable:1;
  18271. ULONG Rsvd2:1;
  18272. ULONG Gart64:1;
  18273. ULONG AGPEnable:1;
  18274. ULONG SBAEnable:1;
  18275. ULONG CalibrationCycle:3;
  18276. ULONG AsyncReqSize:3;
  18277. ULONG Rsvd3:8;
  18278. ULONG RequestQueueDepth:8;
  18279. } AGPCommand;
  18280. } PCI_AGP_CAPABILITY, *PPCI_AGP_CAPABILITY;
  18281. //
  18282. // An AGPv3 Target must have an extended capability,
  18283. // but it's only present for a Master when the Isoch
  18284. // bit is set in its status register
  18285. //
  18286. typedef enum _EXTENDED_AGP_REGISTER {
  18287. IsochStatus,
  18288. AgpControl,
  18289. ApertureSize,
  18290. AperturePageSize,
  18291. GartLow,
  18292. GartHigh,
  18293. IsochCommand
  18294. } EXTENDED_AGP_REGISTER, *PEXTENDED_AGP_REGISTER;
  18295. typedef struct _PCI_AGP_ISOCH_STATUS {
  18296. ULONG ErrorCode: 2;
  18297. ULONG Rsvd1: 1;
  18298. ULONG Isoch_L: 3;
  18299. ULONG Isoch_Y: 2;
  18300. ULONG Isoch_N: 8;
  18301. ULONG Rsvd2: 16;
  18302. } PCI_AGP_ISOCH_STATUS, *PPCI_AGP_ISOCH_STATUS;
  18303. typedef struct _PCI_AGP_CONTROL {
  18304. ULONG Rsvd1: 7;
  18305. ULONG GTLB_Enable: 1;
  18306. ULONG AP_Enable: 1;
  18307. ULONG CAL_Disable: 1;
  18308. ULONG Rsvd2: 22;
  18309. } PCI_AGP_CONTROL, *PPCI_AGP_CONTROL;
  18310. typedef struct _PCI_AGP_APERTURE_PAGE_SIZE {
  18311. USHORT PageSizeMask: 11;
  18312. USHORT Rsvd1: 1;
  18313. USHORT PageSizeSelect: 4;
  18314. } PCI_AGP_APERTURE_PAGE_SIZE, *PPCI_AGP_APERTURE_PAGE_SIZE;
  18315. typedef struct _PCI_AGP_ISOCH_COMMAND {
  18316. USHORT Rsvd1: 6;
  18317. USHORT Isoch_Y: 2;
  18318. USHORT Isoch_N: 8;
  18319. } PCI_AGP_ISOCH_COMMAND, *PPCI_AGP_ISOCH_COMMAND;
  18320. typedef struct PCI_AGP_EXTENDED_CAPABILITY {
  18321. PCI_AGP_ISOCH_STATUS IsochStatus;
  18322. //
  18323. // Target only ----------------<<-begin->>
  18324. //
  18325. PCI_AGP_CONTROL AgpControl;
  18326. USHORT ApertureSize;
  18327. PCI_AGP_APERTURE_PAGE_SIZE AperturePageSize;
  18328. ULONG GartLow;
  18329. ULONG GartHigh;
  18330. //
  18331. // ------------------------------<<-end->>
  18332. //
  18333. PCI_AGP_ISOCH_COMMAND IsochCommand;
  18334. } PCI_AGP_EXTENDED_CAPABILITY, *PPCI_AGP_EXTENDED_CAPABILITY;
  18335. #define PCI_AGP_RATE_1X 0x1
  18336. #define PCI_AGP_RATE_2X 0x2
  18337. #define PCI_AGP_RATE_4X 0x4
  18338. //
  18339. // MSI (Message Signalled Interrupts) Capability
  18340. //
  18341. typedef struct _PCI_MSI_CAPABILITY {
  18342. PCI_CAPABILITIES_HEADER Header;
  18343. struct _PCI_MSI_MESSAGE_CONTROL {
  18344. USHORT MSIEnable:1;
  18345. USHORT MultipleMessageCapable:3;
  18346. USHORT MultipleMessageEnable:3;
  18347. USHORT CapableOf64Bits:1;
  18348. USHORT Reserved:8;
  18349. } MessageControl;
  18350. union {
  18351. struct _PCI_MSI_MESSAGE_ADDRESS {
  18352. ULONG_PTR Reserved:2; // always zero, DWORD aligned address
  18353. ULONG_PTR Address:30;
  18354. } Register;
  18355. ULONG_PTR Raw;
  18356. } MessageAddress;
  18357. //
  18358. // The rest of the Capability structure differs depending on whether
  18359. // 32bit or 64bit addressing is being used.
  18360. //
  18361. // (The CapableOf64Bits bit above determines this)
  18362. //
  18363. union {
  18364. // For 64 bit devices
  18365. struct _PCI_MSI_64BIT_DATA {
  18366. ULONG MessageUpperAddress;
  18367. USHORT MessageData;
  18368. } Bit64;
  18369. // For 32 bit devices
  18370. struct _PCI_MSI_32BIT_DATA {
  18371. USHORT MessageData;
  18372. ULONG Unused;
  18373. } Bit32;
  18374. } Data;
  18375. } PCI_MSI_CAPABILITY, *PPCI_PCI_CAPABILITY;
  18376. //
  18377. // Base Class Code encodings for Base Class (from PCI spec rev 2.1).
  18378. //
  18379. #define PCI_CLASS_PRE_20 0x00
  18380. #define PCI_CLASS_MASS_STORAGE_CTLR 0x01
  18381. #define PCI_CLASS_NETWORK_CTLR 0x02
  18382. #define PCI_CLASS_DISPLAY_CTLR 0x03
  18383. #define PCI_CLASS_MULTIMEDIA_DEV 0x04
  18384. #define PCI_CLASS_MEMORY_CTLR 0x05
  18385. #define PCI_CLASS_BRIDGE_DEV 0x06
  18386. #define PCI_CLASS_SIMPLE_COMMS_CTLR 0x07
  18387. #define PCI_CLASS_BASE_SYSTEM_DEV 0x08
  18388. #define PCI_CLASS_INPUT_DEV 0x09
  18389. #define PCI_CLASS_DOCKING_STATION 0x0a
  18390. #define PCI_CLASS_PROCESSOR 0x0b
  18391. #define PCI_CLASS_SERIAL_BUS_CTLR 0x0c
  18392. #define PCI_CLASS_WIRELESS_CTLR 0x0d
  18393. #define PCI_CLASS_INTELLIGENT_IO_CTLR 0x0e
  18394. #define PCI_CLASS_SATELLITE_COMMS_CTLR 0x0f
  18395. #define PCI_CLASS_ENCRYPTION_DECRYPTION 0x10
  18396. #define PCI_CLASS_DATA_ACQ_SIGNAL_PROC 0x11
  18397. // 0d thru fe reserved
  18398. #define PCI_CLASS_NOT_DEFINED 0xff
  18399. //
  18400. // Sub Class Code encodings (PCI rev 2.1).
  18401. //
  18402. // Class 00 - PCI_CLASS_PRE_20
  18403. #define PCI_SUBCLASS_PRE_20_NON_VGA 0x00
  18404. #define PCI_SUBCLASS_PRE_20_VGA 0x01
  18405. // Class 01 - PCI_CLASS_MASS_STORAGE_CTLR
  18406. #define PCI_SUBCLASS_MSC_SCSI_BUS_CTLR 0x00
  18407. #define PCI_SUBCLASS_MSC_IDE_CTLR 0x01
  18408. #define PCI_SUBCLASS_MSC_FLOPPY_CTLR 0x02
  18409. #define PCI_SUBCLASS_MSC_IPI_CTLR 0x03
  18410. #define PCI_SUBCLASS_MSC_RAID_CTLR 0x04
  18411. #define PCI_SUBCLASS_MSC_OTHER 0x80
  18412. // Class 02 - PCI_CLASS_NETWORK_CTLR
  18413. #define PCI_SUBCLASS_NET_ETHERNET_CTLR 0x00
  18414. #define PCI_SUBCLASS_NET_TOKEN_RING_CTLR 0x01
  18415. #define PCI_SUBCLASS_NET_FDDI_CTLR 0x02
  18416. #define PCI_SUBCLASS_NET_ATM_CTLR 0x03
  18417. #define PCI_SUBCLASS_NET_ISDN_CTLR 0x04
  18418. #define PCI_SUBCLASS_NET_OTHER 0x80
  18419. // Class 03 - PCI_CLASS_DISPLAY_CTLR
  18420. // N.B. Sub Class 00 could be VGA or 8514 depending on Interface byte
  18421. #define PCI_SUBCLASS_VID_VGA_CTLR 0x00
  18422. #define PCI_SUBCLASS_VID_XGA_CTLR 0x01
  18423. #define PCI_SUBLCASS_VID_3D_CTLR 0x02
  18424. #define PCI_SUBCLASS_VID_OTHER 0x80
  18425. // Class 04 - PCI_CLASS_MULTIMEDIA_DEV
  18426. #define PCI_SUBCLASS_MM_VIDEO_DEV 0x00
  18427. #define PCI_SUBCLASS_MM_AUDIO_DEV 0x01
  18428. #define PCI_SUBCLASS_MM_TELEPHONY_DEV 0x02
  18429. #define PCI_SUBCLASS_MM_OTHER 0x80
  18430. // Class 05 - PCI_CLASS_MEMORY_CTLR
  18431. #define PCI_SUBCLASS_MEM_RAM 0x00
  18432. #define PCI_SUBCLASS_MEM_FLASH 0x01
  18433. #define PCI_SUBCLASS_MEM_OTHER 0x80
  18434. // Class 06 - PCI_CLASS_BRIDGE_DEV
  18435. #define PCI_SUBCLASS_BR_HOST 0x00
  18436. #define PCI_SUBCLASS_BR_ISA 0x01
  18437. #define PCI_SUBCLASS_BR_EISA 0x02
  18438. #define PCI_SUBCLASS_BR_MCA 0x03
  18439. #define PCI_SUBCLASS_BR_PCI_TO_PCI 0x04
  18440. #define PCI_SUBCLASS_BR_PCMCIA 0x05
  18441. #define PCI_SUBCLASS_BR_NUBUS 0x06
  18442. #define PCI_SUBCLASS_BR_CARDBUS 0x07
  18443. #define PCI_SUBCLASS_BR_RACEWAY 0x08
  18444. #define PCI_SUBCLASS_BR_OTHER 0x80
  18445. // Class 07 - PCI_CLASS_SIMPLE_COMMS_CTLR
  18446. // N.B. Sub Class 00 and 01 additional info in Interface byte
  18447. #define PCI_SUBCLASS_COM_SERIAL 0x00
  18448. #define PCI_SUBCLASS_COM_PARALLEL 0x01
  18449. #define PCI_SUBCLASS_COM_MULTIPORT 0x02
  18450. #define PCI_SUBCLASS_COM_MODEM 0x03
  18451. #define PCI_SUBCLASS_COM_OTHER 0x80
  18452. // Class 08 - PCI_CLASS_BASE_SYSTEM_DEV
  18453. // N.B. See Interface byte for additional info.
  18454. #define PCI_SUBCLASS_SYS_INTERRUPT_CTLR 0x00
  18455. #define PCI_SUBCLASS_SYS_DMA_CTLR 0x01
  18456. #define PCI_SUBCLASS_SYS_SYSTEM_TIMER 0x02
  18457. #define PCI_SUBCLASS_SYS_REAL_TIME_CLOCK 0x03
  18458. #define PCI_SUBCLASS_SYS_GEN_HOTPLUG_CTLR 0x04
  18459. #define PCI_SUBCLASS_SYS_OTHER 0x80
  18460. // Class 09 - PCI_CLASS_INPUT_DEV
  18461. #define PCI_SUBCLASS_INP_KEYBOARD 0x00
  18462. #define PCI_SUBCLASS_INP_DIGITIZER 0x01
  18463. #define PCI_SUBCLASS_INP_MOUSE 0x02
  18464. #define PCI_SUBCLASS_INP_SCANNER 0x03
  18465. #define PCI_SUBCLASS_INP_GAMEPORT 0x04
  18466. #define PCI_SUBCLASS_INP_OTHER 0x80
  18467. // Class 0a - PCI_CLASS_DOCKING_STATION
  18468. #define PCI_SUBCLASS_DOC_GENERIC 0x00
  18469. #define PCI_SUBCLASS_DOC_OTHER 0x80
  18470. // Class 0b - PCI_CLASS_PROCESSOR
  18471. #define PCI_SUBCLASS_PROC_386 0x00
  18472. #define PCI_SUBCLASS_PROC_486 0x01
  18473. #define PCI_SUBCLASS_PROC_PENTIUM 0x02
  18474. #define PCI_SUBCLASS_PROC_ALPHA 0x10
  18475. #define PCI_SUBCLASS_PROC_POWERPC 0x20
  18476. #define PCI_SUBCLASS_PROC_COPROCESSOR 0x40
  18477. // Class 0c - PCI_CLASS_SERIAL_BUS_CTLR
  18478. #define PCI_SUBCLASS_SB_IEEE1394 0x00
  18479. #define PCI_SUBCLASS_SB_ACCESS 0x01
  18480. #define PCI_SUBCLASS_SB_SSA 0x02
  18481. #define PCI_SUBCLASS_SB_USB 0x03
  18482. #define PCI_SUBCLASS_SB_FIBRE_CHANNEL 0x04
  18483. #define PCI_SUBCLASS_SB_SMBUS 0x05
  18484. // Class 0d - PCI_CLASS_WIRELESS_CTLR
  18485. #define PCI_SUBCLASS_WIRELESS_IRDA 0x00
  18486. #define PCI_SUBCLASS_WIRELESS_CON_IR 0x01
  18487. #define PCI_SUBCLASS_WIRELESS_RF 0x10
  18488. #define PCI_SUBCLASS_WIRELESS_OTHER 0x80
  18489. // Class 0e - PCI_CLASS_INTELLIGENT_IO_CTLR
  18490. #define PCI_SUBCLASS_INTIO_I2O 0x00
  18491. // Class 0f - PCI_CLASS_SATELLITE_CTLR
  18492. #define PCI_SUBCLASS_SAT_TV 0x01
  18493. #define PCI_SUBCLASS_SAT_AUDIO 0x02
  18494. #define PCI_SUBCLASS_SAT_VOICE 0x03
  18495. #define PCI_SUBCLASS_SAT_DATA 0x04
  18496. // Class 10 - PCI_CLASS_ENCRYPTION_DECRYPTION
  18497. #define PCI_SUBCLASS_CRYPTO_NET_COMP 0x00
  18498. #define PCI_SUBCLASS_CRYPTO_ENTERTAINMENT 0x10
  18499. #define PCI_SUBCLASS_CRYPTO_OTHER 0x80
  18500. // Class 11 - PCI_CLASS_DATA_ACQ_SIGNAL_PROC
  18501. #define PCI_SUBCLASS_DASP_DPIO 0x00
  18502. #define PCI_SUBCLASS_DASP_OTHER 0x80
  18503. //
  18504. // Bit encodes for PCI_COMMON_CONFIG.u.type0.BaseAddresses
  18505. //
  18506. #define PCI_ADDRESS_IO_SPACE 0x00000001 // (ro)
  18507. #define PCI_ADDRESS_MEMORY_TYPE_MASK 0x00000006 // (ro)
  18508. #define PCI_ADDRESS_MEMORY_PREFETCHABLE 0x00000008 // (ro)
  18509. #define PCI_ADDRESS_IO_ADDRESS_MASK 0xfffffffc
  18510. #define PCI_ADDRESS_MEMORY_ADDRESS_MASK 0xfffffff0
  18511. #define PCI_ADDRESS_ROM_ADDRESS_MASK 0xfffff800
  18512. #define PCI_TYPE_32BIT 0
  18513. #define PCI_TYPE_20BIT 2
  18514. #define PCI_TYPE_64BIT 4
  18515. //
  18516. // Bit encodes for PCI_COMMON_CONFIG.u.type0.ROMBaseAddresses
  18517. //
  18518. #define PCI_ROMADDRESS_ENABLED 0x00000001
  18519. //
  18520. // Reference notes for PCI configuration fields:
  18521. //
  18522. // ro these field are read only. changes to these fields are ignored
  18523. //
  18524. // ro+ these field are intended to be read only and should be initialized
  18525. // by the system to their proper values. However, driver may change
  18526. // these settings.
  18527. //
  18528. // ---
  18529. //
  18530. // All resources comsumed by a PCI device start as unitialized
  18531. // under NT. An uninitialized memory or I/O base address can be
  18532. // determined by checking it's corrisponding enabled bit in the
  18533. // PCI_COMMON_CONFIG.Command value. An InterruptLine is unitialized
  18534. // if it contains the value of -1.
  18535. //
  18536. //
  18537. // Portable portion of HAL & HAL bus extender definitions for BUSHANDLER
  18538. // BusData for installed PCI buses.
  18539. //
  18540. typedef VOID
  18541. (*PciPin2Line) (
  18542. IN struct _BUS_HANDLER *BusHandler,
  18543. IN struct _BUS_HANDLER *RootHandler,
  18544. IN PCI_SLOT_NUMBER SlotNumber,
  18545. IN PPCI_COMMON_CONFIG PciData
  18546. );
  18547. typedef VOID
  18548. (*PciLine2Pin) (
  18549. IN struct _BUS_HANDLER *BusHandler,
  18550. IN struct _BUS_HANDLER *RootHandler,
  18551. IN PCI_SLOT_NUMBER SlotNumber,
  18552. IN PPCI_COMMON_CONFIG PciNewData,
  18553. IN PPCI_COMMON_CONFIG PciOldData
  18554. );
  18555. typedef VOID
  18556. (*PciReadWriteConfig) (
  18557. IN struct _BUS_HANDLER *BusHandler,
  18558. IN PCI_SLOT_NUMBER Slot,
  18559. IN PVOID Buffer,
  18560. IN ULONG Offset,
  18561. IN ULONG Length
  18562. );
  18563. #define PCI_DATA_TAG ' ICP'
  18564. #define PCI_DATA_VERSION 1
  18565. typedef struct _PCIBUSDATA {
  18566. ULONG Tag;
  18567. ULONG Version;
  18568. PciReadWriteConfig ReadConfig;
  18569. PciReadWriteConfig WriteConfig;
  18570. PciPin2Line Pin2Line;
  18571. PciLine2Pin Line2Pin;
  18572. PCI_SLOT_NUMBER ParentSlot;
  18573. PVOID Reserved[4];
  18574. } PCIBUSDATA, *PPCIBUSDATA;
  18575. typedef ULONG (*PCI_READ_WRITE_CONFIG)(
  18576. IN PVOID Context,
  18577. IN UCHAR BusOffset,
  18578. IN ULONG Slot,
  18579. IN PVOID Buffer,
  18580. IN ULONG Offset,
  18581. IN ULONG Length
  18582. );
  18583. typedef VOID (*PCI_PIN_TO_LINE)(
  18584. IN PVOID Context,
  18585. IN PPCI_COMMON_CONFIG PciData
  18586. );
  18587. typedef VOID (*PCI_LINE_TO_PIN)(
  18588. IN PVOID Context,
  18589. IN PPCI_COMMON_CONFIG PciNewData,
  18590. IN PPCI_COMMON_CONFIG PciOldData
  18591. );
  18592. typedef struct _PCI_BUS_INTERFACE_STANDARD {
  18593. //
  18594. // generic interface header
  18595. //
  18596. USHORT Size;
  18597. USHORT Version;
  18598. PVOID Context;
  18599. PINTERFACE_REFERENCE InterfaceReference;
  18600. PINTERFACE_DEREFERENCE InterfaceDereference;
  18601. //
  18602. // standard PCI bus interfaces
  18603. //
  18604. PCI_READ_WRITE_CONFIG ReadConfig;
  18605. PCI_READ_WRITE_CONFIG WriteConfig;
  18606. PCI_PIN_TO_LINE PinToLine;
  18607. PCI_LINE_TO_PIN LineToPin;
  18608. } PCI_BUS_INTERFACE_STANDARD, *PPCI_BUS_INTERFACE_STANDARD;
  18609. #define PCI_BUS_INTERFACE_STANDARD_VERSION 1
  18610. #define PCI_DEVICE_PRESENT_INTERFACE_VERSION 1
  18611. //
  18612. // Flags for PCI_DEVICE_PRESENCE_PARAMETERS
  18613. //
  18614. #define PCI_USE_SUBSYSTEM_IDS 0x00000001
  18615. #define PCI_USE_REVISION 0x00000002
  18616. // The following flags are only valid for IsDevicePresentEx
  18617. #define PCI_USE_VENDEV_IDS 0x00000004
  18618. #define PCI_USE_CLASS_SUBCLASS 0x00000008
  18619. #define PCI_USE_PROGIF 0x00000010
  18620. #define PCI_USE_LOCAL_BUS 0x00000020
  18621. #define PCI_USE_LOCAL_DEVICE 0x00000040
  18622. //
  18623. // Search parameters structure for IsDevicePresentEx
  18624. //
  18625. typedef struct _PCI_DEVICE_PRESENCE_PARAMETERS {
  18626. ULONG Size;
  18627. ULONG Flags;
  18628. USHORT VendorID;
  18629. USHORT DeviceID;
  18630. UCHAR RevisionID;
  18631. USHORT SubVendorID;
  18632. USHORT SubSystemID;
  18633. UCHAR BaseClass;
  18634. UCHAR SubClass;
  18635. UCHAR ProgIf;
  18636. } PCI_DEVICE_PRESENCE_PARAMETERS, *PPCI_DEVICE_PRESENCE_PARAMETERS;
  18637. typedef
  18638. BOOLEAN
  18639. (*PPCI_IS_DEVICE_PRESENT) (
  18640. IN USHORT VendorID,
  18641. IN USHORT DeviceID,
  18642. IN UCHAR RevisionID,
  18643. IN USHORT SubVendorID,
  18644. IN USHORT SubSystemID,
  18645. IN ULONG Flags
  18646. );
  18647. typedef
  18648. BOOLEAN
  18649. (*PPCI_IS_DEVICE_PRESENT_EX) (
  18650. IN PVOID Context,
  18651. IN PPCI_DEVICE_PRESENCE_PARAMETERS Parameters
  18652. );
  18653. typedef struct _PCI_DEVICE_PRESENT_INTERFACE {
  18654. //
  18655. // generic interface header
  18656. //
  18657. USHORT Size;
  18658. USHORT Version;
  18659. PVOID Context;
  18660. PINTERFACE_REFERENCE InterfaceReference;
  18661. PINTERFACE_DEREFERENCE InterfaceDereference;
  18662. //
  18663. // pci device info
  18664. //
  18665. PPCI_IS_DEVICE_PRESENT IsDevicePresent;
  18666. PPCI_IS_DEVICE_PRESENT_EX IsDevicePresentEx;
  18667. } PCI_DEVICE_PRESENT_INTERFACE, *PPCI_DEVICE_PRESENT_INTERFACE;
  18668. #ifdef POOL_TAGGING
  18669. #define ExAllocatePool(a,b) ExAllocatePoolWithTag(a,b,' kdD')
  18670. #define ExAllocatePoolWithQuota(a,b) ExAllocatePoolWithQuotaTag(a,b,' kdD')
  18671. #endif
  18672. extern POBJECT_TYPE *IoFileObjectType;
  18673. extern POBJECT_TYPE *ExEventObjectType;
  18674. extern POBJECT_TYPE *ExSemaphoreObjectType;
  18675. //
  18676. // Define exported ZwXxx routines to device drivers.
  18677. //
  18678. NTSYSAPI
  18679. NTSTATUS
  18680. NTAPI
  18681. ZwCreateFile(
  18682. OUT PHANDLE FileHandle,
  18683. IN ACCESS_MASK DesiredAccess,
  18684. IN POBJECT_ATTRIBUTES ObjectAttributes,
  18685. OUT PIO_STATUS_BLOCK IoStatusBlock,
  18686. IN PLARGE_INTEGER AllocationSize OPTIONAL,
  18687. IN ULONG FileAttributes,
  18688. IN ULONG ShareAccess,
  18689. IN ULONG CreateDisposition,
  18690. IN ULONG CreateOptions,
  18691. IN PVOID EaBuffer OPTIONAL,
  18692. IN ULONG EaLength
  18693. );
  18694. NTSYSAPI
  18695. NTSTATUS
  18696. NTAPI
  18697. ZwOpenFile(
  18698. OUT PHANDLE FileHandle,
  18699. IN ACCESS_MASK DesiredAccess,
  18700. IN POBJECT_ATTRIBUTES ObjectAttributes,
  18701. OUT PIO_STATUS_BLOCK IoStatusBlock,
  18702. IN ULONG ShareAccess,
  18703. IN ULONG OpenOptions
  18704. );
  18705. NTSYSAPI
  18706. NTSTATUS
  18707. NTAPI
  18708. ZwQueryInformationFile(
  18709. IN HANDLE FileHandle,
  18710. OUT PIO_STATUS_BLOCK IoStatusBlock,
  18711. OUT PVOID FileInformation,
  18712. IN ULONG Length,
  18713. IN FILE_INFORMATION_CLASS FileInformationClass
  18714. );
  18715. NTSYSAPI
  18716. NTSTATUS
  18717. NTAPI
  18718. ZwSetInformationFile(
  18719. IN HANDLE FileHandle,
  18720. OUT PIO_STATUS_BLOCK IoStatusBlock,
  18721. IN PVOID FileInformation,
  18722. IN ULONG Length,
  18723. IN FILE_INFORMATION_CLASS FileInformationClass
  18724. );
  18725. NTSYSAPI
  18726. NTSTATUS
  18727. NTAPI
  18728. ZwReadFile(
  18729. IN HANDLE FileHandle,
  18730. IN HANDLE Event OPTIONAL,
  18731. IN PIO_APC_ROUTINE ApcRoutine OPTIONAL,
  18732. IN PVOID ApcContext OPTIONAL,
  18733. OUT PIO_STATUS_BLOCK IoStatusBlock,
  18734. OUT PVOID Buffer,
  18735. IN ULONG Length,
  18736. IN PLARGE_INTEGER ByteOffset OPTIONAL,
  18737. IN PULONG Key OPTIONAL
  18738. );
  18739. NTSYSAPI
  18740. NTSTATUS
  18741. NTAPI
  18742. ZwWriteFile(
  18743. IN HANDLE FileHandle,
  18744. IN HANDLE Event OPTIONAL,
  18745. IN PIO_APC_ROUTINE ApcRoutine OPTIONAL,
  18746. IN PVOID ApcContext OPTIONAL,
  18747. OUT PIO_STATUS_BLOCK IoStatusBlock,
  18748. IN PVOID Buffer,
  18749. IN ULONG Length,
  18750. IN PLARGE_INTEGER ByteOffset OPTIONAL,
  18751. IN PULONG Key OPTIONAL
  18752. );
  18753. NTSYSAPI
  18754. NTSTATUS
  18755. NTAPI
  18756. ZwClose(
  18757. IN HANDLE Handle
  18758. );
  18759. NTSYSAPI
  18760. NTSTATUS
  18761. NTAPI
  18762. ZwCreateDirectoryObject(
  18763. OUT PHANDLE DirectoryHandle,
  18764. IN ACCESS_MASK DesiredAccess,
  18765. IN POBJECT_ATTRIBUTES ObjectAttributes
  18766. );
  18767. NTSYSAPI
  18768. NTSTATUS
  18769. NTAPI
  18770. ZwMakeTemporaryObject(
  18771. IN HANDLE Handle
  18772. );
  18773. NTSYSAPI
  18774. NTSTATUS
  18775. NTAPI
  18776. ZwCreateSection (
  18777. OUT PHANDLE SectionHandle,
  18778. IN ACCESS_MASK DesiredAccess,
  18779. IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL,
  18780. IN PLARGE_INTEGER MaximumSize OPTIONAL,
  18781. IN ULONG SectionPageProtection,
  18782. IN ULONG AllocationAttributes,
  18783. IN HANDLE FileHandle OPTIONAL
  18784. );
  18785. NTSYSAPI
  18786. NTSTATUS
  18787. NTAPI
  18788. ZwOpenSection(
  18789. OUT PHANDLE SectionHandle,
  18790. IN ACCESS_MASK DesiredAccess,
  18791. IN POBJECT_ATTRIBUTES ObjectAttributes
  18792. );
  18793. NTSYSAPI
  18794. NTSTATUS
  18795. NTAPI
  18796. ZwMapViewOfSection(
  18797. IN HANDLE SectionHandle,
  18798. IN HANDLE ProcessHandle,
  18799. IN OUT PVOID *BaseAddress,
  18800. IN ULONG ZeroBits,
  18801. IN SIZE_T CommitSize,
  18802. IN OUT PLARGE_INTEGER SectionOffset OPTIONAL,
  18803. IN OUT PSIZE_T ViewSize,
  18804. IN SECTION_INHERIT InheritDisposition,
  18805. IN ULONG AllocationType,
  18806. IN ULONG Protect
  18807. );
  18808. NTSYSAPI
  18809. NTSTATUS
  18810. NTAPI
  18811. ZwUnmapViewOfSection(
  18812. IN HANDLE ProcessHandle,
  18813. IN PVOID BaseAddress
  18814. );
  18815. NTSYSAPI
  18816. NTSTATUS
  18817. NTAPI
  18818. ZwSetInformationThread(
  18819. IN HANDLE ThreadHandle,
  18820. IN THREADINFOCLASS ThreadInformationClass,
  18821. IN PVOID ThreadInformation,
  18822. IN ULONG ThreadInformationLength
  18823. );
  18824. NTSYSAPI
  18825. NTSTATUS
  18826. NTAPI
  18827. ZwCreateKey(
  18828. OUT PHANDLE KeyHandle,
  18829. IN ACCESS_MASK DesiredAccess,
  18830. IN POBJECT_ATTRIBUTES ObjectAttributes,
  18831. IN ULONG TitleIndex,
  18832. IN PUNICODE_STRING Class OPTIONAL,
  18833. IN ULONG CreateOptions,
  18834. OUT PULONG Disposition OPTIONAL
  18835. );
  18836. NTSYSAPI
  18837. NTSTATUS
  18838. NTAPI
  18839. ZwOpenKey(
  18840. OUT PHANDLE KeyHandle,
  18841. IN ACCESS_MASK DesiredAccess,
  18842. IN POBJECT_ATTRIBUTES ObjectAttributes
  18843. );
  18844. NTSYSAPI
  18845. NTSTATUS
  18846. NTAPI
  18847. ZwDeleteKey(
  18848. IN HANDLE KeyHandle
  18849. );
  18850. NTSYSAPI
  18851. NTSTATUS
  18852. NTAPI
  18853. ZwDeleteValueKey(
  18854. IN HANDLE KeyHandle,
  18855. IN PUNICODE_STRING ValueName
  18856. );
  18857. NTSYSAPI
  18858. NTSTATUS
  18859. NTAPI
  18860. ZwEnumerateKey(
  18861. IN HANDLE KeyHandle,
  18862. IN ULONG Index,
  18863. IN KEY_INFORMATION_CLASS KeyInformationClass,
  18864. OUT PVOID KeyInformation,
  18865. IN ULONG Length,
  18866. OUT PULONG ResultLength
  18867. );
  18868. NTSYSAPI
  18869. NTSTATUS
  18870. NTAPI
  18871. ZwEnumerateValueKey(
  18872. IN HANDLE KeyHandle,
  18873. IN ULONG Index,
  18874. IN KEY_VALUE_INFORMATION_CLASS KeyValueInformationClass,
  18875. OUT PVOID KeyValueInformation,
  18876. IN ULONG Length,
  18877. OUT PULONG ResultLength
  18878. );
  18879. NTSYSAPI
  18880. NTSTATUS
  18881. NTAPI
  18882. ZwFlushKey(
  18883. IN HANDLE KeyHandle
  18884. );
  18885. NTSYSAPI
  18886. NTSTATUS
  18887. NTAPI
  18888. ZwQueryKey(
  18889. IN HANDLE KeyHandle,
  18890. IN KEY_INFORMATION_CLASS KeyInformationClass,
  18891. OUT PVOID KeyInformation,
  18892. IN ULONG Length,
  18893. OUT PULONG ResultLength
  18894. );
  18895. NTSYSAPI
  18896. NTSTATUS
  18897. NTAPI
  18898. ZwQueryValueKey(
  18899. IN HANDLE KeyHandle,
  18900. IN PUNICODE_STRING ValueName,
  18901. IN KEY_VALUE_INFORMATION_CLASS KeyValueInformationClass,
  18902. OUT PVOID KeyValueInformation,
  18903. IN ULONG Length,
  18904. OUT PULONG ResultLength
  18905. );
  18906. NTSYSAPI
  18907. NTSTATUS
  18908. NTAPI
  18909. ZwSetValueKey(
  18910. IN HANDLE KeyHandle,
  18911. IN PUNICODE_STRING ValueName,
  18912. IN ULONG TitleIndex OPTIONAL,
  18913. IN ULONG Type,
  18914. IN PVOID Data,
  18915. IN ULONG DataSize
  18916. );
  18917. NTSYSAPI
  18918. NTSTATUS
  18919. NTAPI
  18920. ZwOpenSymbolicLinkObject(
  18921. OUT PHANDLE LinkHandle,
  18922. IN ACCESS_MASK DesiredAccess,
  18923. IN POBJECT_ATTRIBUTES ObjectAttributes
  18924. );
  18925. NTSYSAPI
  18926. NTSTATUS
  18927. NTAPI
  18928. ZwQuerySymbolicLinkObject(
  18929. IN HANDLE LinkHandle,
  18930. IN OUT PUNICODE_STRING LinkTarget,
  18931. OUT PULONG ReturnedLength OPTIONAL
  18932. );
  18933. NTSTATUS
  18934. ZwCreateTimer (
  18935. OUT PHANDLE TimerHandle,
  18936. IN ACCESS_MASK DesiredAccess,
  18937. IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL,
  18938. IN TIMER_TYPE TimerType
  18939. );
  18940. NTSTATUS
  18941. ZwOpenTimer (
  18942. OUT PHANDLE TimerHandle,
  18943. IN ACCESS_MASK DesiredAccess,
  18944. IN POBJECT_ATTRIBUTES ObjectAttributes
  18945. );
  18946. NTSTATUS
  18947. ZwCancelTimer (
  18948. IN HANDLE TimerHandle,
  18949. OUT PBOOLEAN CurrentState OPTIONAL
  18950. );
  18951. NTSTATUS
  18952. ZwSetTimer (
  18953. IN HANDLE TimerHandle,
  18954. IN PLARGE_INTEGER DueTime,
  18955. IN PTIMER_APC_ROUTINE TimerApcRoutine OPTIONAL,
  18956. IN PVOID TimerContext OPTIONAL,
  18957. IN BOOLEAN WakeTimer,
  18958. IN LONG Period OPTIONAL,
  18959. OUT PBOOLEAN PreviousState OPTIONAL
  18960. );
  18961. #ifdef VERIFIER_DDK_EXTENSIONS
  18962. #include <ddk_ext.h>
  18963. #endif
  18964. #endif // _NTDDK_