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.

16030 lines
383 KiB

  1. /*++ BUILD Version: 0110 // Increment this if a change has global effects
  2. Copyright (c) Microsoft Corporation. All rights reserved.
  3. Module Name:
  4. wdm.h
  5. Abstract:
  6. This module defines the WDM types, constants, and functions that are
  7. exposed to device drivers.
  8. Revision History:
  9. --*/
  10. #ifndef _WDMDDK_
  11. #define _WDMDDK_
  12. #define _NTDDK_
  13. #ifndef RC_INVOKED
  14. #if _MSC_VER < 1300
  15. #error Compiler version not supported by Windows DDK
  16. #endif
  17. #endif // RC_INVOKED
  18. #define NT_INCLUDED
  19. #define _CTYPE_DISABLE_MACROS
  20. #include <excpt.h>
  21. #include <ntdef.h>
  22. #include <ntstatus.h>
  23. #include <bugcodes.h>
  24. #include <ntiologc.h>
  25. //
  26. // Define types that are not exported.
  27. //
  28. typedef struct _ACCESS_STATE *PACCESS_STATE;
  29. typedef struct _CALLBACK_OBJECT *PCALLBACK_OBJECT;
  30. typedef struct _EPROCESS *PEPROCESS;
  31. typedef struct _ETHREAD *PETHREAD;
  32. typedef struct _IO_TIMER *PIO_TIMER;
  33. typedef struct _KINTERRUPT *PKINTERRUPT;
  34. typedef struct _KTHREAD *PKTHREAD, *PRKTHREAD;
  35. typedef struct _OBJECT_TYPE *POBJECT_TYPE;
  36. typedef struct _SECURITY_QUALITY_OF_SERVICE *PSECURITY_QUALITY_OF_SERVICE;
  37. #if defined(_M_AMD64)
  38. PKTHREAD
  39. NTAPI
  40. KeGetCurrentThread(
  41. VOID
  42. );
  43. #endif // defined(_M_AMD64)
  44. #if defined(_M_IX86)
  45. PKTHREAD NTAPI KeGetCurrentThread();
  46. #endif // defined(_M_IX86)
  47. #if defined(_M_IA64)
  48. //
  49. // Define base address for kernel and user space
  50. //
  51. #ifdef _WIN64
  52. #define UREGION_INDEX 1
  53. #define KREGION_INDEX 7
  54. #define UADDRESS_BASE ((ULONG_PTR)UREGION_INDEX << 61)
  55. #define KADDRESS_BASE ((ULONG_PTR)KREGION_INDEX << 61)
  56. #else // !_WIN64
  57. #define KADDRESS_BASE 0
  58. #define UADDRESS_BASE 0
  59. #endif // !_WIN64
  60. //
  61. // Define Address of Processor Control Registers.
  62. //
  63. #define KIPCR ((ULONG_PTR)(KADDRESS_BASE + 0xffff0000)) // kernel address of first PCR
  64. //
  65. // Define Pointer to Processor Control Registers.
  66. //
  67. #define PCR ((volatile KPCR * const)KIPCR)
  68. PKTHREAD NTAPI KeGetCurrentThread();
  69. #endif // defined(_M_IA64)
  70. #include <mce.h>
  71. #ifndef FAR
  72. #define FAR
  73. #endif
  74. #define PsGetCurrentProcess() IoGetCurrentProcess()
  75. #define PsGetCurrentThread() ((PETHREAD) (KeGetCurrentThread()))
  76. extern NTSYSAPI CCHAR KeNumberProcessors;
  77. //
  78. // Define alignment macros to align structure sizes and pointers up and down.
  79. //
  80. #define ALIGN_DOWN(length, type) \
  81. ((ULONG)(length) & ~(sizeof(type) - 1))
  82. #define ALIGN_UP(length, type) \
  83. (ALIGN_DOWN(((ULONG)(length) + sizeof(type) - 1), type))
  84. #define ALIGN_DOWN_POINTER(address, type) \
  85. ((PVOID)((ULONG_PTR)(address) & ~((ULONG_PTR)sizeof(type) - 1)))
  86. #define ALIGN_UP_POINTER(address, type) \
  87. (ALIGN_DOWN_POINTER(((ULONG_PTR)(address) + sizeof(type) - 1), type))
  88. #define POOL_TAGGING 1
  89. #ifndef DBG
  90. #define DBG 0
  91. #endif
  92. #if DBG
  93. #define IF_DEBUG if (TRUE)
  94. #else
  95. #define IF_DEBUG if (FALSE)
  96. #endif
  97. #if DEVL
  98. extern ULONG NtGlobalFlag;
  99. #define IF_NTOS_DEBUG( FlagName ) \
  100. if (NtGlobalFlag & (FLG_ ## FlagName))
  101. #else
  102. #define IF_NTOS_DEBUG( FlagName ) if (FALSE)
  103. #endif
  104. //
  105. // Kernel definitions that need to be here for forward reference purposes
  106. //
  107. //
  108. // Processor modes.
  109. //
  110. typedef CCHAR KPROCESSOR_MODE;
  111. typedef enum _MODE {
  112. KernelMode,
  113. UserMode,
  114. MaximumMode
  115. } MODE;
  116. //
  117. // APC function types
  118. //
  119. //
  120. // Put in an empty definition for the KAPC so that the
  121. // routines can reference it before it is declared.
  122. //
  123. struct _KAPC;
  124. typedef
  125. VOID
  126. (*PKNORMAL_ROUTINE) (
  127. IN PVOID NormalContext,
  128. IN PVOID SystemArgument1,
  129. IN PVOID SystemArgument2
  130. );
  131. typedef
  132. VOID
  133. (*PKKERNEL_ROUTINE) (
  134. IN struct _KAPC *Apc,
  135. IN OUT PKNORMAL_ROUTINE *NormalRoutine,
  136. IN OUT PVOID *NormalContext,
  137. IN OUT PVOID *SystemArgument1,
  138. IN OUT PVOID *SystemArgument2
  139. );
  140. typedef
  141. VOID
  142. (*PKRUNDOWN_ROUTINE) (
  143. IN struct _KAPC *Apc
  144. );
  145. typedef
  146. BOOLEAN
  147. (*PKSYNCHRONIZE_ROUTINE) (
  148. IN PVOID SynchronizeContext
  149. );
  150. typedef
  151. BOOLEAN
  152. (*PKTRANSFER_ROUTINE) (
  153. VOID
  154. );
  155. //
  156. //
  157. // Asynchronous Procedure Call (APC) object
  158. //
  159. //
  160. typedef struct _KAPC {
  161. CSHORT Type;
  162. CSHORT Size;
  163. ULONG Spare0;
  164. struct _KTHREAD *Thread;
  165. LIST_ENTRY ApcListEntry;
  166. PKKERNEL_ROUTINE KernelRoutine;
  167. PKRUNDOWN_ROUTINE RundownRoutine;
  168. PKNORMAL_ROUTINE NormalRoutine;
  169. PVOID NormalContext;
  170. //
  171. // N.B. The following two members MUST be together.
  172. //
  173. PVOID SystemArgument1;
  174. PVOID SystemArgument2;
  175. CCHAR ApcStateIndex;
  176. KPROCESSOR_MODE ApcMode;
  177. BOOLEAN Inserted;
  178. } KAPC, *PKAPC, *RESTRICTED_POINTER PRKAPC;
  179. //
  180. // DPC routine
  181. //
  182. struct _KDPC;
  183. typedef
  184. VOID
  185. (*PKDEFERRED_ROUTINE) (
  186. IN struct _KDPC *Dpc,
  187. IN PVOID DeferredContext,
  188. IN PVOID SystemArgument1,
  189. IN PVOID SystemArgument2
  190. );
  191. //
  192. // Define DPC importance.
  193. //
  194. // LowImportance - Queue DPC at end of target DPC queue.
  195. // MediumImportance - Queue DPC at end of target DPC queue.
  196. // HighImportance - Queue DPC at front of target DPC DPC queue.
  197. //
  198. // If there is currently a DPC active on the target processor, or a DPC
  199. // interrupt has already been requested on the target processor when a
  200. // DPC is queued, then no further action is necessary. The DPC will be
  201. // executed on the target processor when its queue entry is processed.
  202. //
  203. // If there is not a DPC active on the target processor and a DPC interrupt
  204. // has not been requested on the target processor, then the exact treatment
  205. // of the DPC is dependent on whether the host system is a UP system or an
  206. // MP system.
  207. //
  208. // UP system.
  209. //
  210. // If the DPC is of medium or high importance, the current DPC queue depth
  211. // is greater than the maximum target depth, or current DPC request rate is
  212. // less the minimum target rate, then a DPC interrupt is requested on the
  213. // host processor and the DPC will be processed when the interrupt occurs.
  214. // Otherwise, no DPC interupt is requested and the DPC execution will be
  215. // delayed until the DPC queue depth is greater that the target depth or the
  216. // minimum DPC rate is less than the target rate.
  217. //
  218. // MP system.
  219. //
  220. // If the DPC is being queued to another processor and the depth of the DPC
  221. // queue on the target processor is greater than the maximum target depth or
  222. // the DPC is of high importance, then a DPC interrupt is requested on the
  223. // target processor and the DPC will be processed when the interrupt occurs.
  224. // Otherwise, the DPC execution will be delayed on the target processor until
  225. // the DPC queue depth on the target processor is greater that the maximum
  226. // target depth or the minimum DPC rate on the target processor is less than
  227. // the target mimimum rate.
  228. //
  229. // If the DPC is being queued to the current processor and the DPC is not of
  230. // low importance, the current DPC queue depth is greater than the maximum
  231. // target depth, or the minimum DPC rate is less than the minimum target rate,
  232. // then a DPC interrupt is request on the current processor and the DPV will
  233. // be processed whne the interrupt occurs. Otherwise, no DPC interupt is
  234. // requested and the DPC execution will be delayed until the DPC queue depth
  235. // is greater that the target depth or the minimum DPC rate is less than the
  236. // target rate.
  237. //
  238. typedef enum _KDPC_IMPORTANCE {
  239. LowImportance,
  240. MediumImportance,
  241. HighImportance
  242. } KDPC_IMPORTANCE;
  243. //
  244. // Define DPC type indicies.
  245. //
  246. #define DPC_NORMAL 0
  247. #define DPC_THREADED 1
  248. //
  249. // Deferred Procedure Call (DPC) object
  250. //
  251. typedef struct _KDPC {
  252. CSHORT Type;
  253. UCHAR Number;
  254. UCHAR Importance;
  255. LIST_ENTRY DpcListEntry;
  256. PKDEFERRED_ROUTINE DeferredRoutine;
  257. PVOID DeferredContext;
  258. PVOID SystemArgument1;
  259. PVOID SystemArgument2;
  260. PVOID DpcData;
  261. } KDPC, *PKDPC, *RESTRICTED_POINTER PRKDPC;
  262. //
  263. // Interprocessor interrupt worker routine function prototype.
  264. //
  265. typedef PVOID PKIPI_CONTEXT;
  266. typedef
  267. VOID
  268. (*PKIPI_WORKER)(
  269. IN PKIPI_CONTEXT PacketContext,
  270. IN PVOID Parameter1,
  271. IN PVOID Parameter2,
  272. IN PVOID Parameter3
  273. );
  274. //
  275. // Define interprocessor interrupt performance counters.
  276. //
  277. typedef struct _KIPI_COUNTS {
  278. ULONG Freeze;
  279. ULONG Packet;
  280. ULONG DPC;
  281. ULONG APC;
  282. ULONG FlushSingleTb;
  283. ULONG FlushMultipleTb;
  284. ULONG FlushEntireTb;
  285. ULONG GenericCall;
  286. ULONG ChangeColor;
  287. ULONG SweepDcache;
  288. ULONG SweepIcache;
  289. ULONG SweepIcacheRange;
  290. ULONG FlushIoBuffers;
  291. ULONG GratuitousDPC;
  292. } KIPI_COUNTS, *PKIPI_COUNTS;
  293. //
  294. // I/O system definitions.
  295. //
  296. // Define a Memory Descriptor List (MDL)
  297. //
  298. // An MDL describes pages in a virtual buffer in terms of physical pages. The
  299. // pages associated with the buffer are described in an array that is allocated
  300. // just after the MDL header structure itself.
  301. //
  302. // One simply calculates the base of the array by adding one to the base
  303. // MDL pointer:
  304. //
  305. // Pages = (PPFN_NUMBER) (Mdl + 1);
  306. //
  307. // Notice that while in the context of the subject thread, the base virtual
  308. // address of a buffer mapped by an MDL may be referenced using the following:
  309. //
  310. // Mdl->StartVa | Mdl->ByteOffset
  311. //
  312. typedef struct _MDL {
  313. struct _MDL *Next;
  314. CSHORT Size;
  315. CSHORT MdlFlags;
  316. struct _EPROCESS *Process;
  317. PVOID MappedSystemVa;
  318. PVOID StartVa;
  319. ULONG ByteCount;
  320. ULONG ByteOffset;
  321. } MDL, *PMDL;
  322. #define MDL_MAPPED_TO_SYSTEM_VA 0x0001
  323. #define MDL_PAGES_LOCKED 0x0002
  324. #define MDL_SOURCE_IS_NONPAGED_POOL 0x0004
  325. #define MDL_ALLOCATED_FIXED_SIZE 0x0008
  326. #define MDL_PARTIAL 0x0010
  327. #define MDL_PARTIAL_HAS_BEEN_MAPPED 0x0020
  328. #define MDL_IO_PAGE_READ 0x0040
  329. #define MDL_WRITE_OPERATION 0x0080
  330. #define MDL_PARENT_MAPPED_SYSTEM_VA 0x0100
  331. #define MDL_FREE_EXTRA_PTES 0x0200
  332. #define MDL_DESCRIBES_AWE 0x0400
  333. #define MDL_IO_SPACE 0x0800
  334. #define MDL_NETWORK_HEADER 0x1000
  335. #define MDL_MAPPING_CAN_FAIL 0x2000
  336. #define MDL_ALLOCATED_MUST_SUCCEED 0x4000
  337. #define MDL_MAPPING_FLAGS (MDL_MAPPED_TO_SYSTEM_VA | \
  338. MDL_PAGES_LOCKED | \
  339. MDL_SOURCE_IS_NONPAGED_POOL | \
  340. MDL_PARTIAL_HAS_BEEN_MAPPED | \
  341. MDL_PARENT_MAPPED_SYSTEM_VA | \
  342. MDL_SYSTEM_VA | \
  343. MDL_IO_SPACE )
  344. //
  345. // switch to DBG when appropriate
  346. //
  347. #if DBG
  348. #define PAGED_CODE() \
  349. { if (KeGetCurrentIrql() > APC_LEVEL) { \
  350. KdPrint(( "EX: Pageable code called at IRQL %d\n", KeGetCurrentIrql() )); \
  351. ASSERT(FALSE); \
  352. } \
  353. }
  354. #else
  355. #define PAGED_CODE() NOP_FUNCTION;
  356. #endif
  357. #define NTKERNELAPI DECLSPEC_IMPORT
  358. #define NTHALAPI DECLSPEC_IMPORT
  359. //
  360. // Common dispatcher object header
  361. //
  362. // N.B. The size field contains the number of dwords in the structure.
  363. //
  364. typedef struct _DISPATCHER_HEADER {
  365. union {
  366. struct {
  367. UCHAR Type;
  368. UCHAR Absolute;
  369. UCHAR Size;
  370. union {
  371. UCHAR Inserted;
  372. BOOLEAN DebugActive;
  373. };
  374. };
  375. volatile LONG Lock;
  376. };
  377. LONG SignalState;
  378. LIST_ENTRY WaitListHead;
  379. } DISPATCHER_HEADER;
  380. //
  381. // Event object
  382. //
  383. typedef struct _KEVENT {
  384. DISPATCHER_HEADER Header;
  385. } KEVENT, *PKEVENT, *RESTRICTED_POINTER PRKEVENT;
  386. //
  387. // Timer object
  388. //
  389. typedef struct _KTIMER {
  390. DISPATCHER_HEADER Header;
  391. ULARGE_INTEGER DueTime;
  392. LIST_ENTRY TimerListEntry;
  393. struct _KDPC *Dpc;
  394. LONG Period;
  395. } KTIMER, *PKTIMER, *RESTRICTED_POINTER PRKTIMER;
  396. typedef enum _LOCK_OPERATION {
  397. IoReadAccess,
  398. IoWriteAccess,
  399. IoModifyAccess
  400. } LOCK_OPERATION;
  401. #ifdef _X86_
  402. //
  403. // Disable these two pragmas that evaluate to "sti" "cli" on x86 so that driver
  404. // writers to not leave them inadvertantly in their code.
  405. //
  406. #if !defined(MIDL_PASS)
  407. #if !defined(RC_INVOKED)
  408. #if _MSC_VER >= 1200
  409. #pragma warning(push)
  410. #endif
  411. #pragma warning(disable:4164) // disable C4164 warning so that apps that
  412. // build with /Od don't get weird errors !
  413. #ifdef _M_IX86
  414. #pragma function(_enable)
  415. #pragma function(_disable)
  416. #endif
  417. #if _MSC_VER >= 1200
  418. #pragma warning(pop)
  419. #else
  420. #pragma warning(default:4164) // reenable C4164 warning
  421. #endif
  422. #endif
  423. #endif
  424. #if !defined(MIDL_PASS) || defined(_M_IX86)
  425. #if (_MSC_FULL_VER >= 13012035)
  426. //
  427. // Define bit scan intrinsics.
  428. //
  429. //#define BitScanForward _BitScanForward
  430. //#define BitScanReverse _BitScanReverse
  431. //BOOLEAN
  432. //_BitScanForward (
  433. // OUT ULONG *Index,
  434. // IN ULONG Mask
  435. // );
  436. //BOOLEAN
  437. //_BitScanReverse (
  438. // OUT ULONG *Index,
  439. // IN ULONG Mask
  440. // );
  441. //#pragma intrinsic(_BitScanForward)
  442. //#pragma intrinsic(_BitScanReverse)
  443. //
  444. // Define FS referencing intrinsics
  445. //
  446. #ifdef __cplusplus
  447. extern "C" {
  448. #endif
  449. UCHAR
  450. __readfsbyte (
  451. IN ULONG Offset
  452. );
  453. USHORT
  454. __readfsword (
  455. IN ULONG Offset
  456. );
  457. ULONG
  458. __readfsdword (
  459. IN ULONG Offset
  460. );
  461. VOID
  462. __writefsbyte (
  463. IN ULONG Offset,
  464. IN UCHAR Data
  465. );
  466. VOID
  467. __writefsword (
  468. IN ULONG Offset,
  469. IN USHORT Data
  470. );
  471. VOID
  472. __writefsdword (
  473. IN ULONG Offset,
  474. IN ULONG Data
  475. );
  476. #ifdef __cplusplus
  477. }
  478. #endif
  479. #pragma intrinsic(__readfsbyte)
  480. #pragma intrinsic(__readfsword)
  481. #pragma intrinsic(__readfsdword)
  482. #pragma intrinsic(__writefsbyte)
  483. #pragma intrinsic(__writefsword)
  484. #pragma intrinsic(__writefsdword)
  485. #endif
  486. #endif
  487. #endif // _X86_
  488. #if defined(_AMD64_)
  489. #if defined(_M_AMD64) && !defined(RC_INVOKED) && !defined(MIDL_PASS)
  490. //
  491. // Define bit test intrinsics.
  492. //
  493. #ifdef __cplusplus
  494. extern "C" {
  495. #endif
  496. #define BitTest _bittest
  497. #define BitTestAndComplement _bittestandcomplement
  498. #define BitTestAndSet _bittestandset
  499. #define BitTestAndReset _bittestandreset
  500. #define InterlockedBitTestAndSet _interlockedbittestandset
  501. #define InterlockedBitTestAndReset _interlockedbittestandreset
  502. #define BitTest64 _bittest64
  503. #define BitTestAndComplement64 _bittestandcomplement64
  504. #define BitTestAndSet64 _bittestandset64
  505. #define BitTestAndReset64 _bittestandreset64
  506. #define InterlockedBitTestAndSet64 _interlockedbittestandset64
  507. #define InterlockedBitTestAndReset64 _interlockedbittestandreset64
  508. BOOLEAN
  509. _bittest (
  510. IN LONG *Base,
  511. IN LONG Offset
  512. );
  513. BOOLEAN
  514. _bittestandcomplement (
  515. IN LONG *Base,
  516. IN LONG Offset
  517. );
  518. BOOLEAN
  519. _bittestandset (
  520. IN LONG *Base,
  521. IN LONG Offset
  522. );
  523. BOOLEAN
  524. _bittestandreset (
  525. IN LONG *Base,
  526. IN LONG Offset
  527. );
  528. BOOLEAN
  529. _interlockedbittestandset (
  530. IN LONG *Base,
  531. IN LONG Offset
  532. );
  533. BOOLEAN
  534. _interlockedbittestandreset (
  535. IN LONG *Base,
  536. IN LONG Offset
  537. );
  538. BOOLEAN
  539. _bittest64 (
  540. IN LONG64 *Base,
  541. IN LONG64 Offset
  542. );
  543. BOOLEAN
  544. _bittestandcomplement64 (
  545. IN LONG64 *Base,
  546. IN LONG64 Offset
  547. );
  548. BOOLEAN
  549. _bittestandset64 (
  550. IN LONG64 *Base,
  551. IN LONG64 Offset
  552. );
  553. BOOLEAN
  554. _bittestandreset64 (
  555. IN LONG64 *Base,
  556. IN LONG64 Offset
  557. );
  558. BOOLEAN
  559. _interlockedbittestandset64 (
  560. IN LONG64 *Base,
  561. IN LONG64 Offset
  562. );
  563. BOOLEAN
  564. _interlockedbittestandreset64 (
  565. IN LONG64 *Base,
  566. IN LONG64 Offset
  567. );
  568. #pragma intrinsic(_bittest)
  569. #pragma intrinsic(_bittestandcomplement)
  570. #pragma intrinsic(_bittestandset)
  571. #pragma intrinsic(_bittestandreset)
  572. #pragma intrinsic(_interlockedbittestandset)
  573. #pragma intrinsic(_interlockedbittestandreset)
  574. #pragma intrinsic(_bittest64)
  575. #pragma intrinsic(_bittestandcomplement64)
  576. #pragma intrinsic(_bittestandset64)
  577. #pragma intrinsic(_bittestandreset64)
  578. #pragma intrinsic(_interlockedbittestandset64)
  579. #pragma intrinsic(_interlockedbittestandreset64)
  580. //
  581. // Define bit scan intrinsics.
  582. //
  583. #define BitScanForward _BitScanForward
  584. #define BitScanReverse _BitScanReverse
  585. #define BitScanForward64 _BitScanForward64
  586. #define BitScanReverse64 _BitScanReverse64
  587. BOOLEAN
  588. _BitScanForward (
  589. OUT ULONG *Index,
  590. IN ULONG Mask
  591. );
  592. BOOLEAN
  593. _BitScanReverse (
  594. OUT ULONG *Index,
  595. IN ULONG Mask
  596. );
  597. BOOLEAN
  598. _BitScanForward64 (
  599. OUT ULONG *Index,
  600. IN ULONG64 Mask
  601. );
  602. BOOLEAN
  603. _BitScanReverse64 (
  604. OUT ULONG *Index,
  605. IN ULONG64 Mask
  606. );
  607. #pragma intrinsic(_BitScanForward)
  608. #pragma intrinsic(_BitScanReverse)
  609. #pragma intrinsic(_BitScanForward64)
  610. #pragma intrinsic(_BitScanReverse64)
  611. //
  612. // Define function to flush a cache line.
  613. //
  614. #define CacheLineFlush(Address) _mm_clflush(Address)
  615. VOID
  616. _mm_clflush (
  617. PVOID Address
  618. );
  619. #pragma intrinsic(_mm_clflush)
  620. //
  621. // Define memory fence intrinsics
  622. //
  623. #define LoadFence _mm_lfence
  624. #define MemoryFence _mm_mfence
  625. #define StoreFence _mm_sfence
  626. VOID
  627. _mm_lfence (
  628. VOID
  629. );
  630. VOID
  631. _mm_mfence (
  632. VOID
  633. );
  634. VOID
  635. _mm_sfence (
  636. VOID
  637. );
  638. void
  639. _mm_prefetch(
  640. CHAR CONST *a,
  641. int sel
  642. );
  643. /* constants for use with _mm_prefetch */
  644. #define _MM_HINT_T0 1
  645. #define _MM_HINT_T1 2
  646. #define _MM_HINT_T2 3
  647. #define _MM_HINT_NTA 0
  648. #pragma intrinsic(_mm_prefetch)
  649. #pragma intrinsic(_mm_lfence)
  650. #pragma intrinsic(_mm_mfence)
  651. #pragma intrinsic(_mm_sfence)
  652. #define YieldProcessor()
  653. #define MemoryBarrier _mm_mfence
  654. #define PreFetchCacheLine(l, a) _mm_prefetch((CHAR CONST *) a, l)
  655. //
  656. // PreFetchCacheLine level defines.
  657. //
  658. #define PF_TEMPORAL_LEVEL_1 _MM_HINT_T0
  659. #define PF_NON_TEMPORAL_LEVEL_ALL _MM_HINT_NTA
  660. //
  661. // Define function to get the caller's EFLAGs value.
  662. //
  663. #define GetCallersEflags() __getcallerseflags()
  664. unsigned __int32
  665. __getcallerseflags (
  666. VOID
  667. );
  668. #pragma intrinsic(__getcallerseflags)
  669. //
  670. // Define function to read the value of the time stamp counter
  671. //
  672. #define ReadTimeStampCounter() __rdtsc()
  673. ULONG64
  674. __rdtsc (
  675. VOID
  676. );
  677. #pragma intrinsic(__rdtsc)
  678. //
  679. // Define functions to move strings as bytes, words, dwords, and qwords.
  680. //
  681. VOID
  682. __movsb (
  683. IN PUCHAR Destination,
  684. IN PUCHAR Source,
  685. IN SIZE_T Count
  686. );
  687. VOID
  688. __movsw (
  689. IN PUSHORT Destination,
  690. IN PUSHORT Source,
  691. IN SIZE_T Count
  692. );
  693. VOID
  694. __movsd (
  695. IN PULONG Destination,
  696. IN PULONG Source,
  697. IN SIZE_T Count
  698. );
  699. VOID
  700. __movsq (
  701. IN PULONGLONG Destination,
  702. IN PULONGLONG Source,
  703. IN SIZE_T Count
  704. );
  705. #pragma intrinsic(__movsb)
  706. #pragma intrinsic(__movsw)
  707. #pragma intrinsic(__movsd)
  708. #pragma intrinsic(__movsq)
  709. //
  710. // Define functions to store strings as bytes, words, dwords, and qwords.
  711. //
  712. VOID
  713. __stosb (
  714. IN PUCHAR Destination,
  715. IN UCHAR Value,
  716. IN SIZE_T Count
  717. );
  718. VOID
  719. __stosw (
  720. IN PUSHORT Destination,
  721. IN USHORT Value,
  722. IN SIZE_T Count
  723. );
  724. VOID
  725. __stosd (
  726. IN PULONG Destination,
  727. IN ULONG Value,
  728. IN SIZE_T Count
  729. );
  730. VOID
  731. __stosq (
  732. IN PULONG64 Destination,
  733. IN ULONG64 Value,
  734. IN SIZE_T Count
  735. );
  736. #pragma intrinsic(__stosb)
  737. #pragma intrinsic(__stosw)
  738. #pragma intrinsic(__stosd)
  739. #pragma intrinsic(__stosq)
  740. //
  741. // Define functions to capture the high 64-bits of a 128-bit multiply.
  742. //
  743. #define MultiplyHigh __mulh
  744. #define UnsignedMultiplyHigh __umulh
  745. LONGLONG
  746. MultiplyHigh (
  747. IN LONGLONG Multiplier,
  748. IN LONGLONG Multiplicand
  749. );
  750. ULONGLONG
  751. UnsignedMultiplyHigh (
  752. IN ULONGLONG Multiplier,
  753. IN ULONGLONG Multiplicand
  754. );
  755. #pragma intrinsic(__mulh)
  756. #pragma intrinsic(__umulh)
  757. //
  758. // Define functions to read and write the uer TEB and the system PCR/PRCB.
  759. //
  760. UCHAR
  761. __readgsbyte (
  762. IN ULONG Offset
  763. );
  764. USHORT
  765. __readgsword (
  766. IN ULONG Offset
  767. );
  768. ULONG
  769. __readgsdword (
  770. IN ULONG Offset
  771. );
  772. ULONG64
  773. __readgsqword (
  774. IN ULONG Offset
  775. );
  776. VOID
  777. __writegsbyte (
  778. IN ULONG Offset,
  779. IN UCHAR Data
  780. );
  781. VOID
  782. __writegsword (
  783. IN ULONG Offset,
  784. IN USHORT Data
  785. );
  786. VOID
  787. __writegsdword (
  788. IN ULONG Offset,
  789. IN ULONG Data
  790. );
  791. VOID
  792. __writegsqword (
  793. IN ULONG Offset,
  794. IN ULONG64 Data
  795. );
  796. #pragma intrinsic(__readgsbyte)
  797. #pragma intrinsic(__readgsword)
  798. #pragma intrinsic(__readgsdword)
  799. #pragma intrinsic(__readgsqword)
  800. #pragma intrinsic(__writegsbyte)
  801. #pragma intrinsic(__writegsword)
  802. #pragma intrinsic(__writegsdword)
  803. #pragma intrinsic(__writegsqword)
  804. #ifdef __cplusplus
  805. }
  806. #endif
  807. #endif // defined(_M_AMD64) && !defined(RC_INVOKED) && !defined(MIDL_PASS)
  808. #endif // _AMD64_
  809. #ifdef _IA64_
  810. #endif // _IA64_
  811. //
  812. // Define an access token from a programmer's viewpoint. The structure is
  813. // completely opaque and the programer is only allowed to have pointers
  814. // to tokens.
  815. //
  816. typedef PVOID PACCESS_TOKEN;
  817. //
  818. // Pointer to a SECURITY_DESCRIPTOR opaque data type.
  819. //
  820. typedef PVOID PSECURITY_DESCRIPTOR;
  821. //
  822. // Define a pointer to the Security ID data type (an opaque data type)
  823. //
  824. typedef PVOID PSID;
  825. typedef ULONG ACCESS_MASK;
  826. typedef ACCESS_MASK *PACCESS_MASK;
  827. //
  828. // The following are masks for the predefined standard access types
  829. //
  830. #define DELETE (0x00010000L)
  831. #define READ_CONTROL (0x00020000L)
  832. #define WRITE_DAC (0x00040000L)
  833. #define WRITE_OWNER (0x00080000L)
  834. #define SYNCHRONIZE (0x00100000L)
  835. #define STANDARD_RIGHTS_REQUIRED (0x000F0000L)
  836. #define STANDARD_RIGHTS_READ (READ_CONTROL)
  837. #define STANDARD_RIGHTS_WRITE (READ_CONTROL)
  838. #define STANDARD_RIGHTS_EXECUTE (READ_CONTROL)
  839. #define STANDARD_RIGHTS_ALL (0x001F0000L)
  840. #define SPECIFIC_RIGHTS_ALL (0x0000FFFFL)
  841. //
  842. // AccessSystemAcl access type
  843. //
  844. #define ACCESS_SYSTEM_SECURITY (0x01000000L)
  845. //
  846. // MaximumAllowed access type
  847. //
  848. #define MAXIMUM_ALLOWED (0x02000000L)
  849. //
  850. // These are the generic rights.
  851. //
  852. #define GENERIC_READ (0x80000000L)
  853. #define GENERIC_WRITE (0x40000000L)
  854. #define GENERIC_EXECUTE (0x20000000L)
  855. #define GENERIC_ALL (0x10000000L)
  856. //
  857. // Define the generic mapping array. This is used to denote the
  858. // mapping of each generic access right to a specific access mask.
  859. //
  860. typedef struct _GENERIC_MAPPING {
  861. ACCESS_MASK GenericRead;
  862. ACCESS_MASK GenericWrite;
  863. ACCESS_MASK GenericExecute;
  864. ACCESS_MASK GenericAll;
  865. } GENERIC_MAPPING;
  866. typedef GENERIC_MAPPING *PGENERIC_MAPPING;
  867. ////////////////////////////////////////////////////////////////////////
  868. // //
  869. // LUID_AND_ATTRIBUTES //
  870. // //
  871. ////////////////////////////////////////////////////////////////////////
  872. //
  873. //
  874. #include <pshpack4.h>
  875. typedef struct _LUID_AND_ATTRIBUTES {
  876. LUID Luid;
  877. ULONG Attributes;
  878. } LUID_AND_ATTRIBUTES, * PLUID_AND_ATTRIBUTES;
  879. typedef LUID_AND_ATTRIBUTES LUID_AND_ATTRIBUTES_ARRAY[ANYSIZE_ARRAY];
  880. typedef LUID_AND_ATTRIBUTES_ARRAY *PLUID_AND_ATTRIBUTES_ARRAY;
  881. #include <poppack.h>
  882. // This is the *current* ACL revision
  883. #define ACL_REVISION (2)
  884. #define ACL_REVISION_DS (4)
  885. // This is the history of ACL revisions. Add a new one whenever
  886. // ACL_REVISION is updated
  887. #define ACL_REVISION1 (1)
  888. #define MIN_ACL_REVISION ACL_REVISION2
  889. #define ACL_REVISION2 (2)
  890. #define ACL_REVISION3 (3)
  891. #define ACL_REVISION4 (4)
  892. #define MAX_ACL_REVISION ACL_REVISION4
  893. typedef struct _ACL {
  894. UCHAR AclRevision;
  895. UCHAR Sbz1;
  896. USHORT AclSize;
  897. USHORT AceCount;
  898. USHORT Sbz2;
  899. } ACL;
  900. typedef ACL *PACL;
  901. //
  902. // Current security descriptor revision value
  903. //
  904. #define SECURITY_DESCRIPTOR_REVISION (1)
  905. #define SECURITY_DESCRIPTOR_REVISION1 (1)
  906. //
  907. // Privilege attributes
  908. //
  909. #define SE_PRIVILEGE_ENABLED_BY_DEFAULT (0x00000001L)
  910. #define SE_PRIVILEGE_ENABLED (0x00000002L)
  911. #define SE_PRIVILEGE_REMOVED (0X00000004L)
  912. #define SE_PRIVILEGE_USED_FOR_ACCESS (0x80000000L)
  913. //
  914. // Privilege Set Control flags
  915. //
  916. #define PRIVILEGE_SET_ALL_NECESSARY (1)
  917. //
  918. // Privilege Set - This is defined for a privilege set of one.
  919. // If more than one privilege is needed, then this structure
  920. // will need to be allocated with more space.
  921. //
  922. // Note: don't change this structure without fixing the INITIAL_PRIVILEGE_SET
  923. // structure (defined in se.h)
  924. //
  925. typedef struct _PRIVILEGE_SET {
  926. ULONG PrivilegeCount;
  927. ULONG Control;
  928. LUID_AND_ATTRIBUTES Privilege[ANYSIZE_ARRAY];
  929. } PRIVILEGE_SET, * PPRIVILEGE_SET;
  930. //
  931. // These must be converted to LUIDs before use.
  932. //
  933. #define SE_MIN_WELL_KNOWN_PRIVILEGE (2L)
  934. #define SE_CREATE_TOKEN_PRIVILEGE (2L)
  935. #define SE_ASSIGNPRIMARYTOKEN_PRIVILEGE (3L)
  936. #define SE_LOCK_MEMORY_PRIVILEGE (4L)
  937. #define SE_INCREASE_QUOTA_PRIVILEGE (5L)
  938. #define SE_MACHINE_ACCOUNT_PRIVILEGE (6L)
  939. #define SE_TCB_PRIVILEGE (7L)
  940. #define SE_SECURITY_PRIVILEGE (8L)
  941. #define SE_TAKE_OWNERSHIP_PRIVILEGE (9L)
  942. #define SE_LOAD_DRIVER_PRIVILEGE (10L)
  943. #define SE_SYSTEM_PROFILE_PRIVILEGE (11L)
  944. #define SE_SYSTEMTIME_PRIVILEGE (12L)
  945. #define SE_PROF_SINGLE_PROCESS_PRIVILEGE (13L)
  946. #define SE_INC_BASE_PRIORITY_PRIVILEGE (14L)
  947. #define SE_CREATE_PAGEFILE_PRIVILEGE (15L)
  948. #define SE_CREATE_PERMANENT_PRIVILEGE (16L)
  949. #define SE_BACKUP_PRIVILEGE (17L)
  950. #define SE_RESTORE_PRIVILEGE (18L)
  951. #define SE_SHUTDOWN_PRIVILEGE (19L)
  952. #define SE_DEBUG_PRIVILEGE (20L)
  953. #define SE_AUDIT_PRIVILEGE (21L)
  954. #define SE_SYSTEM_ENVIRONMENT_PRIVILEGE (22L)
  955. #define SE_CHANGE_NOTIFY_PRIVILEGE (23L)
  956. #define SE_REMOTE_SHUTDOWN_PRIVILEGE (24L)
  957. #define SE_UNDOCK_PRIVILEGE (25L)
  958. #define SE_SYNC_AGENT_PRIVILEGE (26L)
  959. #define SE_ENABLE_DELEGATION_PRIVILEGE (27L)
  960. #define SE_MANAGE_VOLUME_PRIVILEGE (28L)
  961. #define SE_IMPERSONATE_PRIVILEGE (29L)
  962. #define SE_CREATE_GLOBAL_PRIVILEGE (30L)
  963. #define SE_MAX_WELL_KNOWN_PRIVILEGE (SE_CREATE_GLOBAL_PRIVILEGE)
  964. //
  965. // Impersonation Level
  966. //
  967. // Impersonation level is represented by a pair of bits in Windows.
  968. // If a new impersonation level is added or lowest value is changed from
  969. // 0 to something else, fix the Windows CreateFile call.
  970. //
  971. typedef enum _SECURITY_IMPERSONATION_LEVEL {
  972. SecurityAnonymous,
  973. SecurityIdentification,
  974. SecurityImpersonation,
  975. SecurityDelegation
  976. } SECURITY_IMPERSONATION_LEVEL, * PSECURITY_IMPERSONATION_LEVEL;
  977. #define SECURITY_MAX_IMPERSONATION_LEVEL SecurityDelegation
  978. #define SECURITY_MIN_IMPERSONATION_LEVEL SecurityAnonymous
  979. #define DEFAULT_IMPERSONATION_LEVEL SecurityImpersonation
  980. #define VALID_IMPERSONATION_LEVEL(L) (((L) >= SECURITY_MIN_IMPERSONATION_LEVEL) && ((L) <= SECURITY_MAX_IMPERSONATION_LEVEL))
  981. //
  982. // Security Tracking Mode
  983. //
  984. #define SECURITY_DYNAMIC_TRACKING (TRUE)
  985. #define SECURITY_STATIC_TRACKING (FALSE)
  986. typedef BOOLEAN SECURITY_CONTEXT_TRACKING_MODE,
  987. * PSECURITY_CONTEXT_TRACKING_MODE;
  988. //
  989. // Quality Of Service
  990. //
  991. typedef struct _SECURITY_QUALITY_OF_SERVICE {
  992. ULONG Length;
  993. SECURITY_IMPERSONATION_LEVEL ImpersonationLevel;
  994. SECURITY_CONTEXT_TRACKING_MODE ContextTrackingMode;
  995. BOOLEAN EffectiveOnly;
  996. } SECURITY_QUALITY_OF_SERVICE, * PSECURITY_QUALITY_OF_SERVICE;
  997. //
  998. // Used to represent information related to a thread impersonation
  999. //
  1000. typedef struct _SE_IMPERSONATION_STATE {
  1001. PACCESS_TOKEN Token;
  1002. BOOLEAN CopyOnOpen;
  1003. BOOLEAN EffectiveOnly;
  1004. SECURITY_IMPERSONATION_LEVEL Level;
  1005. } SE_IMPERSONATION_STATE, *PSE_IMPERSONATION_STATE;
  1006. typedef ULONG SECURITY_INFORMATION, *PSECURITY_INFORMATION;
  1007. #define OWNER_SECURITY_INFORMATION (0x00000001L)
  1008. #define GROUP_SECURITY_INFORMATION (0x00000002L)
  1009. #define DACL_SECURITY_INFORMATION (0x00000004L)
  1010. #define SACL_SECURITY_INFORMATION (0x00000008L)
  1011. #define PROTECTED_DACL_SECURITY_INFORMATION (0x80000000L)
  1012. #define PROTECTED_SACL_SECURITY_INFORMATION (0x40000000L)
  1013. #define UNPROTECTED_DACL_SECURITY_INFORMATION (0x20000000L)
  1014. #define UNPROTECTED_SACL_SECURITY_INFORMATION (0x10000000L)
  1015. #define LOW_PRIORITY 0 // Lowest thread priority level
  1016. #define LOW_REALTIME_PRIORITY 16 // Lowest realtime priority level
  1017. #define HIGH_PRIORITY 31 // Highest thread priority level
  1018. #define MAXIMUM_PRIORITY 32 // Number of thread priority levels
  1019. #define MAXIMUM_WAIT_OBJECTS 64 // Maximum number of wait objects
  1020. #define MAXIMUM_SUSPEND_COUNT MAXCHAR // Maximum times thread can be suspended
  1021. //
  1022. // Define system time structure.
  1023. //
  1024. typedef struct _KSYSTEM_TIME {
  1025. ULONG LowPart;
  1026. LONG High1Time;
  1027. LONG High2Time;
  1028. } KSYSTEM_TIME, *PKSYSTEM_TIME;
  1029. //
  1030. // Thread priority
  1031. //
  1032. typedef LONG KPRIORITY;
  1033. //
  1034. // Spin Lock
  1035. //
  1036. typedef ULONG_PTR KSPIN_LOCK;
  1037. typedef KSPIN_LOCK *PKSPIN_LOCK;
  1038. //
  1039. // Interrupt routine (first level dispatch)
  1040. //
  1041. typedef
  1042. VOID
  1043. (*PKINTERRUPT_ROUTINE) (
  1044. VOID
  1045. );
  1046. //
  1047. // Profile source types
  1048. //
  1049. typedef enum _KPROFILE_SOURCE {
  1050. ProfileTime,
  1051. ProfileAlignmentFixup,
  1052. ProfileTotalIssues,
  1053. ProfilePipelineDry,
  1054. ProfileLoadInstructions,
  1055. ProfilePipelineFrozen,
  1056. ProfileBranchInstructions,
  1057. ProfileTotalNonissues,
  1058. ProfileDcacheMisses,
  1059. ProfileIcacheMisses,
  1060. ProfileCacheMisses,
  1061. ProfileBranchMispredictions,
  1062. ProfileStoreInstructions,
  1063. ProfileFpInstructions,
  1064. ProfileIntegerInstructions,
  1065. Profile2Issue,
  1066. Profile3Issue,
  1067. Profile4Issue,
  1068. ProfileSpecialInstructions,
  1069. ProfileTotalCycles,
  1070. ProfileIcacheIssues,
  1071. ProfileDcacheAccesses,
  1072. ProfileMemoryBarrierCycles,
  1073. ProfileLoadLinkedIssues,
  1074. ProfileMaximum
  1075. } KPROFILE_SOURCE;
  1076. //
  1077. // for move macros
  1078. //
  1079. #ifdef _MAC
  1080. #ifndef _INC_STRING
  1081. #include <string.h>
  1082. #endif /* _INC_STRING */
  1083. #else
  1084. #include <string.h>
  1085. #endif // _MAC
  1086. #ifndef _SLIST_HEADER_
  1087. #define _SLIST_HEADER_
  1088. #if defined(_WIN64)
  1089. //
  1090. // The type SINGLE_LIST_ENTRY is not suitable for use with SLISTs. For
  1091. // WIN64, an entry on an SLIST is required to be 16-byte aligned, while a
  1092. // SINGLE_LIST_ENTRY structure has only 8 byte alignment.
  1093. //
  1094. // Therefore, all SLIST code should use the SLIST_ENTRY type instead of the
  1095. // SINGLE_LIST_ENTRY type.
  1096. //
  1097. #pragma warning(push)
  1098. #pragma warning(disable:4324) // structure padded due to align()
  1099. typedef struct DECLSPEC_ALIGN(16) _SLIST_ENTRY *PSLIST_ENTRY;
  1100. typedef struct DECLSPEC_ALIGN(16) _SLIST_ENTRY {
  1101. PSLIST_ENTRY Next;
  1102. } SLIST_ENTRY;
  1103. #pragma warning(pop)
  1104. #else
  1105. #define SLIST_ENTRY SINGLE_LIST_ENTRY
  1106. #define _SLIST_ENTRY _SINGLE_LIST_ENTRY
  1107. #define PSLIST_ENTRY PSINGLE_LIST_ENTRY
  1108. #endif
  1109. #if defined(_WIN64)
  1110. typedef struct DECLSPEC_ALIGN(16) _SLIST_HEADER {
  1111. ULONGLONG Alignment;
  1112. ULONGLONG Region;
  1113. } SLIST_HEADER;
  1114. typedef struct _SLIST_HEADER *PSLIST_HEADER;
  1115. #else
  1116. typedef union _SLIST_HEADER {
  1117. ULONGLONG Alignment;
  1118. struct {
  1119. SLIST_ENTRY Next;
  1120. USHORT Depth;
  1121. USHORT Sequence;
  1122. };
  1123. } SLIST_HEADER, *PSLIST_HEADER;
  1124. #endif
  1125. #endif
  1126. //
  1127. // If debugging support enabled, define an ASSERT macro that works. Otherwise
  1128. // define the ASSERT macro to expand to an empty expression.
  1129. //
  1130. // The ASSERT macro has been updated to be an expression instead of a statement.
  1131. //
  1132. NTSYSAPI
  1133. VOID
  1134. NTAPI
  1135. RtlAssert(
  1136. PVOID FailedAssertion,
  1137. PVOID FileName,
  1138. ULONG LineNumber,
  1139. PCHAR Message
  1140. );
  1141. #if DBG
  1142. #define ASSERT( exp ) \
  1143. ((!(exp)) ? \
  1144. (RtlAssert( #exp, __FILE__, __LINE__, NULL ),FALSE) : \
  1145. TRUE)
  1146. #define ASSERTMSG( msg, exp ) \
  1147. ((!(exp)) ? \
  1148. (RtlAssert( #exp, __FILE__, __LINE__, msg ),FALSE) : \
  1149. TRUE)
  1150. #define RTL_SOFT_ASSERT(_exp) \
  1151. ((!(_exp)) ? \
  1152. (DbgPrint("%s(%d): Soft assertion failed\n Expression: %s\n", __FILE__, __LINE__, #_exp),FALSE) : \
  1153. TRUE)
  1154. #define RTL_SOFT_ASSERTMSG(_msg, _exp) \
  1155. ((!(_exp)) ? \
  1156. (DbgPrint("%s(%d): Soft assertion failed\n Expression: %s\n Message: %s\n", __FILE__, __LINE__, #_exp, (_msg)),FALSE) : \
  1157. TRUE)
  1158. #define RTL_VERIFY ASSERT
  1159. #define RTL_VERIFYMSG ASSERTMSG
  1160. #define RTL_SOFT_VERIFY RTL_SOFT_ASSERT
  1161. #define RTL_SOFT_VERIFYMSG RTL_SOFT_ASSERTMSG
  1162. #else
  1163. #define ASSERT( exp ) ((void) 0)
  1164. #define ASSERTMSG( msg, exp ) ((void) 0)
  1165. #define RTL_SOFT_ASSERT(_exp) ((void) 0)
  1166. #define RTL_SOFT_ASSERTMSG(_msg, _exp) ((void) 0)
  1167. #define RTL_VERIFY( exp ) ((exp) ? TRUE : FALSE)
  1168. #define RTL_VERIFYMSG( msg, exp ) ((exp) ? TRUE : FALSE)
  1169. #define RTL_SOFT_VERIFY(_exp) ((_exp) ? TRUE : FALSE)
  1170. #define RTL_SOFT_VERIFYMSG(msg, _exp) ((_exp) ? TRUE : FALSE)
  1171. #endif // DBG
  1172. //
  1173. // Doubly-linked list manipulation routines.
  1174. //
  1175. //
  1176. // VOID
  1177. // InitializeListHead32(
  1178. // PLIST_ENTRY32 ListHead
  1179. // );
  1180. //
  1181. #define InitializeListHead32(ListHead) (\
  1182. (ListHead)->Flink = (ListHead)->Blink = PtrToUlong((ListHead)))
  1183. #if !defined(MIDL_PASS) && !defined(SORTPP_PASS)
  1184. VOID
  1185. FORCEINLINE
  1186. InitializeListHead(
  1187. IN PLIST_ENTRY ListHead
  1188. )
  1189. {
  1190. ListHead->Flink = ListHead->Blink = ListHead;
  1191. }
  1192. //
  1193. // BOOLEAN
  1194. // IsListEmpty(
  1195. // PLIST_ENTRY ListHead
  1196. // );
  1197. //
  1198. #define IsListEmpty(ListHead) \
  1199. ((ListHead)->Flink == (ListHead))
  1200. BOOLEAN
  1201. FORCEINLINE
  1202. RemoveEntryList(
  1203. IN PLIST_ENTRY Entry
  1204. )
  1205. {
  1206. PLIST_ENTRY Blink;
  1207. PLIST_ENTRY Flink;
  1208. Flink = Entry->Flink;
  1209. Blink = Entry->Blink;
  1210. Blink->Flink = Flink;
  1211. Flink->Blink = Blink;
  1212. return (BOOLEAN)(Flink == Blink);
  1213. }
  1214. PLIST_ENTRY
  1215. FORCEINLINE
  1216. RemoveHeadList(
  1217. IN PLIST_ENTRY ListHead
  1218. )
  1219. {
  1220. PLIST_ENTRY Flink;
  1221. PLIST_ENTRY Entry;
  1222. Entry = ListHead->Flink;
  1223. Flink = Entry->Flink;
  1224. ListHead->Flink = Flink;
  1225. Flink->Blink = ListHead;
  1226. return Entry;
  1227. }
  1228. PLIST_ENTRY
  1229. FORCEINLINE
  1230. RemoveTailList(
  1231. IN PLIST_ENTRY ListHead
  1232. )
  1233. {
  1234. PLIST_ENTRY Blink;
  1235. PLIST_ENTRY Entry;
  1236. Entry = ListHead->Blink;
  1237. Blink = Entry->Blink;
  1238. ListHead->Blink = Blink;
  1239. Blink->Flink = ListHead;
  1240. return Entry;
  1241. }
  1242. VOID
  1243. FORCEINLINE
  1244. InsertTailList(
  1245. IN PLIST_ENTRY ListHead,
  1246. IN PLIST_ENTRY Entry
  1247. )
  1248. {
  1249. PLIST_ENTRY Blink;
  1250. Blink = ListHead->Blink;
  1251. Entry->Flink = ListHead;
  1252. Entry->Blink = Blink;
  1253. Blink->Flink = Entry;
  1254. ListHead->Blink = Entry;
  1255. }
  1256. VOID
  1257. FORCEINLINE
  1258. InsertHeadList(
  1259. IN PLIST_ENTRY ListHead,
  1260. IN PLIST_ENTRY Entry
  1261. )
  1262. {
  1263. PLIST_ENTRY Flink;
  1264. Flink = ListHead->Flink;
  1265. Entry->Flink = Flink;
  1266. Entry->Blink = ListHead;
  1267. Flink->Blink = Entry;
  1268. ListHead->Flink = Entry;
  1269. }
  1270. //
  1271. //
  1272. // PSINGLE_LIST_ENTRY
  1273. // PopEntryList(
  1274. // PSINGLE_LIST_ENTRY ListHead
  1275. // );
  1276. //
  1277. #define PopEntryList(ListHead) \
  1278. (ListHead)->Next;\
  1279. {\
  1280. PSINGLE_LIST_ENTRY FirstEntry;\
  1281. FirstEntry = (ListHead)->Next;\
  1282. if (FirstEntry != NULL) { \
  1283. (ListHead)->Next = FirstEntry->Next;\
  1284. } \
  1285. }
  1286. //
  1287. // VOID
  1288. // PushEntryList(
  1289. // PSINGLE_LIST_ENTRY ListHead,
  1290. // PSINGLE_LIST_ENTRY Entry
  1291. // );
  1292. //
  1293. #define PushEntryList(ListHead,Entry) \
  1294. (Entry)->Next = (ListHead)->Next; \
  1295. (ListHead)->Next = (Entry)
  1296. #endif // !MIDL_PASS
  1297. //
  1298. // Subroutines for dealing with the Registry
  1299. //
  1300. typedef NTSTATUS (NTAPI * PRTL_QUERY_REGISTRY_ROUTINE)(
  1301. IN PWSTR ValueName,
  1302. IN ULONG ValueType,
  1303. IN PVOID ValueData,
  1304. IN ULONG ValueLength,
  1305. IN PVOID Context,
  1306. IN PVOID EntryContext
  1307. );
  1308. typedef struct _RTL_QUERY_REGISTRY_TABLE {
  1309. PRTL_QUERY_REGISTRY_ROUTINE QueryRoutine;
  1310. ULONG Flags;
  1311. PWSTR Name;
  1312. PVOID EntryContext;
  1313. ULONG DefaultType;
  1314. PVOID DefaultData;
  1315. ULONG DefaultLength;
  1316. } RTL_QUERY_REGISTRY_TABLE, *PRTL_QUERY_REGISTRY_TABLE;
  1317. //
  1318. // The following flags specify how the Name field of a RTL_QUERY_REGISTRY_TABLE
  1319. // entry is interpreted. A NULL name indicates the end of the table.
  1320. //
  1321. #define RTL_QUERY_REGISTRY_SUBKEY 0x00000001 // Name is a subkey and remainder of
  1322. // table or until next subkey are value
  1323. // names for that subkey to look at.
  1324. #define RTL_QUERY_REGISTRY_TOPKEY 0x00000002 // Reset current key to original key for
  1325. // this and all following table entries.
  1326. #define RTL_QUERY_REGISTRY_REQUIRED 0x00000004 // Fail if no match found for this table
  1327. // entry.
  1328. #define RTL_QUERY_REGISTRY_NOVALUE 0x00000008 // Used to mark a table entry that has no
  1329. // value name, just wants a call out, not
  1330. // an enumeration of all values.
  1331. #define RTL_QUERY_REGISTRY_NOEXPAND 0x00000010 // Used to suppress the expansion of
  1332. // REG_MULTI_SZ into multiple callouts or
  1333. // to prevent the expansion of environment
  1334. // variable values in REG_EXPAND_SZ
  1335. #define RTL_QUERY_REGISTRY_DIRECT 0x00000020 // QueryRoutine field ignored. EntryContext
  1336. // field points to location to store value.
  1337. // For null terminated strings, EntryContext
  1338. // points to UNICODE_STRING structure that
  1339. // that describes maximum size of buffer.
  1340. // If .Buffer field is NULL then a buffer is
  1341. // allocated.
  1342. //
  1343. #define RTL_QUERY_REGISTRY_DELETE 0x00000040 // Used to delete value keys after they
  1344. // are queried.
  1345. NTSYSAPI
  1346. NTSTATUS
  1347. NTAPI
  1348. RtlQueryRegistryValues(
  1349. IN ULONG RelativeTo,
  1350. IN PCWSTR Path,
  1351. IN PRTL_QUERY_REGISTRY_TABLE QueryTable,
  1352. IN PVOID Context,
  1353. IN PVOID Environment OPTIONAL
  1354. );
  1355. NTSYSAPI
  1356. NTSTATUS
  1357. NTAPI
  1358. RtlWriteRegistryValue(
  1359. IN ULONG RelativeTo,
  1360. IN PCWSTR Path,
  1361. IN PCWSTR ValueName,
  1362. IN ULONG ValueType,
  1363. IN PVOID ValueData,
  1364. IN ULONG ValueLength
  1365. );
  1366. NTSYSAPI
  1367. NTSTATUS
  1368. NTAPI
  1369. RtlDeleteRegistryValue(
  1370. IN ULONG RelativeTo,
  1371. IN PCWSTR Path,
  1372. IN PCWSTR ValueName
  1373. );
  1374. //
  1375. // The following values for the RelativeTo parameter determine what the
  1376. // Path parameter to RtlQueryRegistryValues is relative to.
  1377. //
  1378. #define RTL_REGISTRY_ABSOLUTE 0 // Path is a full path
  1379. #define RTL_REGISTRY_SERVICES 1 // \Registry\Machine\System\CurrentControlSet\Services
  1380. #define RTL_REGISTRY_CONTROL 2 // \Registry\Machine\System\CurrentControlSet\Control
  1381. #define RTL_REGISTRY_WINDOWS_NT 3 // \Registry\Machine\Software\Microsoft\Windows NT\CurrentVersion
  1382. #define RTL_REGISTRY_DEVICEMAP 4 // \Registry\Machine\Hardware\DeviceMap
  1383. #define RTL_REGISTRY_USER 5 // \Registry\User\CurrentUser
  1384. #define RTL_REGISTRY_MAXIMUM 6
  1385. #define RTL_REGISTRY_HANDLE 0x40000000 // Low order bits are registry handle
  1386. #define RTL_REGISTRY_OPTIONAL 0x80000000 // Indicates the key node is optional
  1387. NTSYSAPI
  1388. NTSTATUS
  1389. NTAPI
  1390. RtlIntegerToUnicodeString (
  1391. ULONG Value,
  1392. ULONG Base,
  1393. PUNICODE_STRING String
  1394. );
  1395. NTSYSAPI
  1396. NTSTATUS
  1397. NTAPI
  1398. RtlInt64ToUnicodeString (
  1399. IN ULONGLONG Value,
  1400. IN ULONG Base OPTIONAL,
  1401. IN OUT PUNICODE_STRING String
  1402. );
  1403. #ifdef _WIN64
  1404. #define RtlIntPtrToUnicodeString(Value, Base, String) RtlInt64ToUnicodeString(Value, Base, String)
  1405. #else
  1406. #define RtlIntPtrToUnicodeString(Value, Base, String) RtlIntegerToUnicodeString(Value, Base, String)
  1407. #endif
  1408. NTSYSAPI
  1409. NTSTATUS
  1410. NTAPI
  1411. RtlUnicodeStringToInteger (
  1412. PCUNICODE_STRING String,
  1413. ULONG Base,
  1414. PULONG Value
  1415. );
  1416. //
  1417. // String manipulation routines
  1418. //
  1419. #ifdef _NTSYSTEM_
  1420. #define NLS_MB_CODE_PAGE_TAG NlsMbCodePageTag
  1421. #define NLS_MB_OEM_CODE_PAGE_TAG NlsMbOemCodePageTag
  1422. #else
  1423. #define NLS_MB_CODE_PAGE_TAG (*NlsMbCodePageTag)
  1424. #define NLS_MB_OEM_CODE_PAGE_TAG (*NlsMbOemCodePageTag)
  1425. #endif // _NTSYSTEM_
  1426. extern BOOLEAN NLS_MB_CODE_PAGE_TAG; // TRUE -> Multibyte CP, FALSE -> Singlebyte
  1427. extern BOOLEAN NLS_MB_OEM_CODE_PAGE_TAG; // TRUE -> Multibyte CP, FALSE -> Singlebyte
  1428. NTSYSAPI
  1429. VOID
  1430. NTAPI
  1431. RtlInitString(
  1432. PSTRING DestinationString,
  1433. PCSZ SourceString
  1434. );
  1435. NTSYSAPI
  1436. VOID
  1437. NTAPI
  1438. RtlInitAnsiString(
  1439. PANSI_STRING DestinationString,
  1440. PCSZ SourceString
  1441. );
  1442. NTSYSAPI
  1443. VOID
  1444. NTAPI
  1445. RtlInitUnicodeString(
  1446. PUNICODE_STRING DestinationString,
  1447. PCWSTR SourceString
  1448. );
  1449. #define RtlInitEmptyUnicodeString(_ucStr,_buf,_bufSize) \
  1450. ((_ucStr)->Buffer = (_buf), \
  1451. (_ucStr)->Length = 0, \
  1452. (_ucStr)->MaximumLength = (USHORT)(_bufSize))
  1453. //
  1454. // NLS String functions
  1455. //
  1456. NTSYSAPI
  1457. NTSTATUS
  1458. NTAPI
  1459. RtlAnsiStringToUnicodeString(
  1460. PUNICODE_STRING DestinationString,
  1461. PCANSI_STRING SourceString,
  1462. BOOLEAN AllocateDestinationString
  1463. );
  1464. NTSYSAPI
  1465. NTSTATUS
  1466. NTAPI
  1467. RtlUnicodeStringToAnsiString(
  1468. PANSI_STRING DestinationString,
  1469. PCUNICODE_STRING SourceString,
  1470. BOOLEAN AllocateDestinationString
  1471. );
  1472. NTSYSAPI
  1473. LONG
  1474. NTAPI
  1475. RtlCompareUnicodeString(
  1476. PCUNICODE_STRING String1,
  1477. PCUNICODE_STRING String2,
  1478. BOOLEAN CaseInSensitive
  1479. );
  1480. NTSYSAPI
  1481. BOOLEAN
  1482. NTAPI
  1483. RtlEqualUnicodeString(
  1484. PCUNICODE_STRING String1,
  1485. PCUNICODE_STRING String2,
  1486. BOOLEAN CaseInSensitive
  1487. );
  1488. #define HASH_STRING_ALGORITHM_DEFAULT (0)
  1489. #define HASH_STRING_ALGORITHM_X65599 (1)
  1490. #define HASH_STRING_ALGORITHM_INVALID (0xffffffff)
  1491. NTSYSAPI
  1492. NTSTATUS
  1493. NTAPI
  1494. RtlHashUnicodeString(
  1495. IN const UNICODE_STRING *String,
  1496. IN BOOLEAN CaseInSensitive,
  1497. IN ULONG HashAlgorithm,
  1498. OUT PULONG HashValue
  1499. );
  1500. NTSYSAPI
  1501. VOID
  1502. NTAPI
  1503. RtlCopyUnicodeString(
  1504. PUNICODE_STRING DestinationString,
  1505. PCUNICODE_STRING SourceString
  1506. );
  1507. NTSYSAPI
  1508. NTSTATUS
  1509. NTAPI
  1510. RtlAppendUnicodeStringToString (
  1511. PUNICODE_STRING Destination,
  1512. PCUNICODE_STRING Source
  1513. );
  1514. NTSYSAPI
  1515. NTSTATUS
  1516. NTAPI
  1517. RtlAppendUnicodeToString (
  1518. PUNICODE_STRING Destination,
  1519. PCWSTR Source
  1520. );
  1521. NTSYSAPI
  1522. VOID
  1523. NTAPI
  1524. RtlFreeUnicodeString(
  1525. PUNICODE_STRING UnicodeString
  1526. );
  1527. NTSYSAPI
  1528. VOID
  1529. NTAPI
  1530. RtlFreeAnsiString(
  1531. PANSI_STRING AnsiString
  1532. );
  1533. NTSYSAPI
  1534. ULONG
  1535. NTAPI
  1536. RtlxUnicodeStringToAnsiSize(
  1537. PCUNICODE_STRING UnicodeString
  1538. );
  1539. //
  1540. // NTSYSAPI
  1541. // ULONG
  1542. // NTAPI
  1543. // RtlUnicodeStringToAnsiSize(
  1544. // PUNICODE_STRING UnicodeString
  1545. // );
  1546. //
  1547. #define RtlUnicodeStringToAnsiSize(STRING) ( \
  1548. NLS_MB_CODE_PAGE_TAG ? \
  1549. RtlxUnicodeStringToAnsiSize(STRING) : \
  1550. ((STRING)->Length + sizeof(UNICODE_NULL)) / sizeof(WCHAR) \
  1551. )
  1552. NTSYSAPI
  1553. ULONG
  1554. NTAPI
  1555. RtlxAnsiStringToUnicodeSize(
  1556. PCANSI_STRING AnsiString
  1557. );
  1558. //
  1559. // NTSYSAPI
  1560. // ULONG
  1561. // NTAPI
  1562. // RtlAnsiStringToUnicodeSize(
  1563. // PANSI_STRING AnsiString
  1564. // );
  1565. //
  1566. #define RtlAnsiStringToUnicodeSize(STRING) ( \
  1567. NLS_MB_CODE_PAGE_TAG ? \
  1568. RtlxAnsiStringToUnicodeSize(STRING) : \
  1569. ((STRING)->Length + sizeof(ANSI_NULL)) * sizeof(WCHAR) \
  1570. )
  1571. #include <guiddef.h>
  1572. #ifndef DEFINE_GUIDEX
  1573. #define DEFINE_GUIDEX(name) EXTERN_C const CDECL GUID name
  1574. #endif // !defined(DEFINE_GUIDEX)
  1575. #ifndef STATICGUIDOF
  1576. #define STATICGUIDOF(guid) STATIC_##guid
  1577. #endif // !defined(STATICGUIDOF)
  1578. #ifndef __IID_ALIGNED__
  1579. #define __IID_ALIGNED__
  1580. #ifdef __cplusplus
  1581. inline int IsEqualGUIDAligned(REFGUID guid1, REFGUID guid2)
  1582. {
  1583. return ((*(PLONGLONG)(&guid1) == *(PLONGLONG)(&guid2)) && (*((PLONGLONG)(&guid1) + 1) == *((PLONGLONG)(&guid2) + 1)));
  1584. }
  1585. #else // !__cplusplus
  1586. #define IsEqualGUIDAligned(guid1, guid2) \
  1587. ((*(PLONGLONG)(guid1) == *(PLONGLONG)(guid2)) && (*((PLONGLONG)(guid1) + 1) == *((PLONGLONG)(guid2) + 1)))
  1588. #endif // !__cplusplus
  1589. #endif // !__IID_ALIGNED__
  1590. NTSYSAPI
  1591. NTSTATUS
  1592. NTAPI
  1593. RtlStringFromGUID(
  1594. IN REFGUID Guid,
  1595. OUT PUNICODE_STRING GuidString
  1596. );
  1597. NTSYSAPI
  1598. NTSTATUS
  1599. NTAPI
  1600. RtlGUIDFromString(
  1601. IN PUNICODE_STRING GuidString,
  1602. OUT GUID* Guid
  1603. );
  1604. //
  1605. // Fast primitives to compare, move, and zero memory
  1606. //
  1607. NTSYSAPI
  1608. SIZE_T
  1609. NTAPI
  1610. RtlCompareMemory (
  1611. const VOID *Source1,
  1612. const VOID *Source2,
  1613. SIZE_T Length
  1614. );
  1615. #define RtlEqualMemory(Destination,Source,Length) (!memcmp((Destination),(Source),(Length)))
  1616. #if defined(_M_AMD64)
  1617. NTSYSAPI
  1618. VOID
  1619. NTAPI
  1620. RtlCopyMemory (
  1621. VOID UNALIGNED *Destination,
  1622. CONST VOID UNALIGNED *Source,
  1623. SIZE_T Length
  1624. );
  1625. NTSYSAPI
  1626. VOID
  1627. NTAPI
  1628. RtlMoveMemory (
  1629. VOID UNALIGNED *Destination,
  1630. CONST VOID UNALIGNED *Source,
  1631. SIZE_T Length
  1632. );
  1633. NTSYSAPI
  1634. VOID
  1635. NTAPI
  1636. RtlFillMemory (
  1637. VOID UNALIGNED *Destination,
  1638. SIZE_T Length,
  1639. IN UCHAR Fill
  1640. );
  1641. NTSYSAPI
  1642. VOID
  1643. NTAPI
  1644. RtlZeroMemory (
  1645. VOID UNALIGNED *Destination,
  1646. SIZE_T Length
  1647. );
  1648. #else
  1649. #define RtlMoveMemory(Destination,Source,Length) memmove((Destination),(Source),(Length))
  1650. #define RtlCopyMemory(Destination,Source,Length) memcpy((Destination),(Source),(Length))
  1651. #define RtlFillMemory(Destination,Length,Fill) memset((Destination),(Fill),(Length))
  1652. #define RtlZeroMemory(Destination,Length) memset((Destination),0,(Length))
  1653. #endif
  1654. #if !defined(MIDL_PASS)
  1655. FORCEINLINE
  1656. PVOID
  1657. RtlSecureZeroMemory(
  1658. IN PVOID ptr,
  1659. IN SIZE_T cnt
  1660. )
  1661. {
  1662. volatile char *vptr = (volatile char *)ptr;
  1663. while (cnt) {
  1664. *vptr = 0;
  1665. vptr++;
  1666. cnt--;
  1667. }
  1668. return ptr;
  1669. }
  1670. #endif
  1671. #define RtlCopyBytes RtlCopyMemory
  1672. #define RtlZeroBytes RtlZeroMemory
  1673. #define RtlFillBytes RtlFillMemory
  1674. #if defined(_M_AMD64)
  1675. NTSYSAPI
  1676. VOID
  1677. NTAPI
  1678. RtlCopyMemoryNonTemporal (
  1679. VOID UNALIGNED *Destination,
  1680. CONST VOID UNALIGNED *Source,
  1681. SIZE_T Length
  1682. );
  1683. #else
  1684. #define RtlCopyMemoryNonTemporal RtlCopyMemory
  1685. #endif
  1686. NTSYSAPI
  1687. VOID
  1688. FASTCALL
  1689. RtlPrefetchMemoryNonTemporal(
  1690. IN PVOID Source,
  1691. IN SIZE_T Length
  1692. );
  1693. //
  1694. // Define kernel debugger print prototypes and macros.
  1695. //
  1696. // N.B. The following function cannot be directly imported because there are
  1697. // a few places in the source tree where this function is redefined.
  1698. //
  1699. VOID
  1700. NTAPI
  1701. DbgBreakPoint(
  1702. VOID
  1703. );
  1704. #define DBG_STATUS_CONTROL_C 1
  1705. #define DBG_STATUS_SYSRQ 2
  1706. #define DBG_STATUS_BUGCHECK_FIRST 3
  1707. #define DBG_STATUS_BUGCHECK_SECOND 4
  1708. #define DBG_STATUS_FATAL 5
  1709. #define DBG_STATUS_DEBUG_CONTROL 6
  1710. #define DBG_STATUS_WORKER 7
  1711. #if DBG
  1712. #define KdPrint(_x_) DbgPrint _x_
  1713. #define KdBreakPoint() DbgBreakPoint()
  1714. #else
  1715. #define KdPrint(_x_)
  1716. #define KdBreakPoint()
  1717. #endif
  1718. #ifndef _DBGNT_
  1719. ULONG
  1720. __cdecl
  1721. DbgPrint(
  1722. PCH Format,
  1723. ...
  1724. );
  1725. #endif // _DBGNT_
  1726. //
  1727. // Large integer arithmetic routines.
  1728. //
  1729. //
  1730. // Large integer add - 64-bits + 64-bits -> 64-bits
  1731. //
  1732. #if !defined(MIDL_PASS)
  1733. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  1734. __inline
  1735. LARGE_INTEGER
  1736. NTAPI
  1737. RtlLargeIntegerAdd (
  1738. LARGE_INTEGER Addend1,
  1739. LARGE_INTEGER Addend2
  1740. )
  1741. {
  1742. LARGE_INTEGER Sum;
  1743. Sum.QuadPart = Addend1.QuadPart + Addend2.QuadPart;
  1744. return Sum;
  1745. }
  1746. //
  1747. // Enlarged integer multiply - 32-bits * 32-bits -> 64-bits
  1748. //
  1749. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  1750. __inline
  1751. LARGE_INTEGER
  1752. NTAPI
  1753. RtlEnlargedIntegerMultiply (
  1754. LONG Multiplicand,
  1755. LONG Multiplier
  1756. )
  1757. {
  1758. LARGE_INTEGER Product;
  1759. Product.QuadPart = (LONGLONG)Multiplicand * (ULONGLONG)Multiplier;
  1760. return Product;
  1761. }
  1762. //
  1763. // Unsigned enlarged integer multiply - 32-bits * 32-bits -> 64-bits
  1764. //
  1765. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  1766. __inline
  1767. LARGE_INTEGER
  1768. NTAPI
  1769. RtlEnlargedUnsignedMultiply (
  1770. ULONG Multiplicand,
  1771. ULONG Multiplier
  1772. )
  1773. {
  1774. LARGE_INTEGER Product;
  1775. Product.QuadPart = (ULONGLONG)Multiplicand * (ULONGLONG)Multiplier;
  1776. return Product;
  1777. }
  1778. //
  1779. // Enlarged integer divide - 64-bits / 32-bits > 32-bits
  1780. //
  1781. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  1782. __inline
  1783. ULONG
  1784. NTAPI
  1785. RtlEnlargedUnsignedDivide (
  1786. IN ULARGE_INTEGER Dividend,
  1787. IN ULONG Divisor,
  1788. IN PULONG Remainder OPTIONAL
  1789. )
  1790. {
  1791. ULONG Quotient;
  1792. Quotient = (ULONG)(Dividend.QuadPart / Divisor);
  1793. if (ARGUMENT_PRESENT(Remainder)) {
  1794. *Remainder = (ULONG)(Dividend.QuadPart % Divisor);
  1795. }
  1796. return Quotient;
  1797. }
  1798. //
  1799. // Large integer negation - -(64-bits)
  1800. //
  1801. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  1802. __inline
  1803. LARGE_INTEGER
  1804. NTAPI
  1805. RtlLargeIntegerNegate (
  1806. LARGE_INTEGER Subtrahend
  1807. )
  1808. {
  1809. LARGE_INTEGER Difference;
  1810. Difference.QuadPart = -Subtrahend.QuadPart;
  1811. return Difference;
  1812. }
  1813. //
  1814. // Large integer subtract - 64-bits - 64-bits -> 64-bits.
  1815. //
  1816. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  1817. __inline
  1818. LARGE_INTEGER
  1819. NTAPI
  1820. RtlLargeIntegerSubtract (
  1821. LARGE_INTEGER Minuend,
  1822. LARGE_INTEGER Subtrahend
  1823. )
  1824. {
  1825. LARGE_INTEGER Difference;
  1826. Difference.QuadPart = Minuend.QuadPart - Subtrahend.QuadPart;
  1827. return Difference;
  1828. }
  1829. //
  1830. // Extended large integer magic divide - 64-bits / 32-bits -> 64-bits
  1831. //
  1832. #if defined(_AMD64_)
  1833. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  1834. __inline
  1835. LARGE_INTEGER
  1836. NTAPI
  1837. RtlExtendedMagicDivide (
  1838. LARGE_INTEGER Dividend,
  1839. LARGE_INTEGER MagicDivisor,
  1840. CCHAR ShiftCount
  1841. )
  1842. {
  1843. LARGE_INTEGER Quotient;
  1844. if (Dividend.QuadPart >= 0) {
  1845. Quotient.QuadPart = UnsignedMultiplyHigh(Dividend.QuadPart,
  1846. (ULONG64)MagicDivisor.QuadPart);
  1847. } else {
  1848. Quotient.QuadPart = UnsignedMultiplyHigh(-Dividend.QuadPart,
  1849. (ULONG64)MagicDivisor.QuadPart);
  1850. }
  1851. Quotient.QuadPart = (ULONG64)Quotient.QuadPart >> ShiftCount;
  1852. if (Dividend.QuadPart < 0) {
  1853. Quotient.QuadPart = - Quotient.QuadPart;
  1854. }
  1855. return Quotient;
  1856. }
  1857. #endif // defined(_AMD64_)
  1858. #if defined(_X86_) || defined(_IA64_)
  1859. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  1860. NTSYSAPI
  1861. LARGE_INTEGER
  1862. NTAPI
  1863. RtlExtendedMagicDivide (
  1864. LARGE_INTEGER Dividend,
  1865. LARGE_INTEGER MagicDivisor,
  1866. CCHAR ShiftCount
  1867. );
  1868. #endif // defined(_X86_) || defined(_IA64_)
  1869. #if defined(_AMD64_) || defined(_IA64_)
  1870. //
  1871. // Large Integer divide - 64-bits / 32-bits -> 64-bits
  1872. //
  1873. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  1874. __inline
  1875. LARGE_INTEGER
  1876. NTAPI
  1877. RtlExtendedLargeIntegerDivide (
  1878. LARGE_INTEGER Dividend,
  1879. ULONG Divisor,
  1880. PULONG Remainder OPTIONAL
  1881. )
  1882. {
  1883. LARGE_INTEGER Quotient;
  1884. Quotient.QuadPart = (ULONG64)Dividend.QuadPart / Divisor;
  1885. if (ARGUMENT_PRESENT(Remainder)) {
  1886. *Remainder = (ULONG)(Dividend.QuadPart % Divisor);
  1887. }
  1888. return Quotient;
  1889. }
  1890. //
  1891. // Extended integer multiply - 32-bits * 64-bits -> 64-bits
  1892. //
  1893. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  1894. __inline
  1895. LARGE_INTEGER
  1896. NTAPI
  1897. RtlExtendedIntegerMultiply (
  1898. LARGE_INTEGER Multiplicand,
  1899. LONG Multiplier
  1900. )
  1901. {
  1902. LARGE_INTEGER Product;
  1903. Product.QuadPart = Multiplicand.QuadPart * Multiplier;
  1904. return Product;
  1905. }
  1906. #else
  1907. //
  1908. // Large Integer divide - 64-bits / 32-bits -> 64-bits
  1909. //
  1910. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  1911. NTSYSAPI
  1912. LARGE_INTEGER
  1913. NTAPI
  1914. RtlExtendedLargeIntegerDivide (
  1915. LARGE_INTEGER Dividend,
  1916. ULONG Divisor,
  1917. PULONG Remainder
  1918. );
  1919. //
  1920. // Extended integer multiply - 32-bits * 64-bits -> 64-bits
  1921. //
  1922. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  1923. NTSYSAPI
  1924. LARGE_INTEGER
  1925. NTAPI
  1926. RtlExtendedIntegerMultiply (
  1927. LARGE_INTEGER Multiplicand,
  1928. LONG Multiplier
  1929. );
  1930. #endif // defined(_AMD64_) || defined(_IA64_)
  1931. //
  1932. // Large integer and - 64-bite & 64-bits -> 64-bits.
  1933. //
  1934. #if PRAGMA_DEPRECATED_DDK
  1935. #pragma deprecated(RtlLargeIntegerAnd) // Use native __int64 math
  1936. #endif
  1937. #define RtlLargeIntegerAnd(Result, Source, Mask) \
  1938. Result.QuadPart = Source.QuadPart & Mask.QuadPart
  1939. //
  1940. // Convert signed integer to large integer.
  1941. //
  1942. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  1943. __inline
  1944. LARGE_INTEGER
  1945. NTAPI
  1946. RtlConvertLongToLargeInteger (
  1947. LONG SignedInteger
  1948. )
  1949. {
  1950. LARGE_INTEGER Result;
  1951. Result.QuadPart = SignedInteger;
  1952. return Result;
  1953. }
  1954. //
  1955. // Convert unsigned integer to large integer.
  1956. //
  1957. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  1958. __inline
  1959. LARGE_INTEGER
  1960. NTAPI
  1961. RtlConvertUlongToLargeInteger (
  1962. ULONG UnsignedInteger
  1963. )
  1964. {
  1965. LARGE_INTEGER Result;
  1966. Result.QuadPart = UnsignedInteger;
  1967. return Result;
  1968. }
  1969. //
  1970. // Large integer shift routines.
  1971. //
  1972. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  1973. __inline
  1974. LARGE_INTEGER
  1975. NTAPI
  1976. RtlLargeIntegerShiftLeft (
  1977. LARGE_INTEGER LargeInteger,
  1978. CCHAR ShiftCount
  1979. )
  1980. {
  1981. LARGE_INTEGER Result;
  1982. Result.QuadPart = LargeInteger.QuadPart << ShiftCount;
  1983. return Result;
  1984. }
  1985. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  1986. __inline
  1987. LARGE_INTEGER
  1988. NTAPI
  1989. RtlLargeIntegerShiftRight (
  1990. LARGE_INTEGER LargeInteger,
  1991. CCHAR ShiftCount
  1992. )
  1993. {
  1994. LARGE_INTEGER Result;
  1995. Result.QuadPart = (ULONG64)LargeInteger.QuadPart >> ShiftCount;
  1996. return Result;
  1997. }
  1998. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  1999. __inline
  2000. LARGE_INTEGER
  2001. NTAPI
  2002. RtlLargeIntegerArithmeticShift (
  2003. LARGE_INTEGER LargeInteger,
  2004. CCHAR ShiftCount
  2005. )
  2006. {
  2007. LARGE_INTEGER Result;
  2008. Result.QuadPart = LargeInteger.QuadPart >> ShiftCount;
  2009. return Result;
  2010. }
  2011. //
  2012. // Large integer comparison routines.
  2013. //
  2014. #if PRAGMA_DEPRECATED_DDK
  2015. #pragma deprecated(RtlLargeIntegerGreaterThan) // Use native __int64 math
  2016. #pragma deprecated(RtlLargeIntegerGreaterThanOrEqualTo) // Use native __int64 math
  2017. #pragma deprecated(RtlLargeIntegerEqualTo) // Use native __int64 math
  2018. #pragma deprecated(RtlLargeIntegerNotEqualTo) // Use native __int64 math
  2019. #pragma deprecated(RtlLargeIntegerLessThan) // Use native __int64 math
  2020. #pragma deprecated(RtlLargeIntegerLessThanOrEqualTo) // Use native __int64 math
  2021. #pragma deprecated(RtlLargeIntegerGreaterThanZero) // Use native __int64 math
  2022. #pragma deprecated(RtlLargeIntegerGreaterOrEqualToZero) // Use native __int64 math
  2023. #pragma deprecated(RtlLargeIntegerEqualToZero) // Use native __int64 math
  2024. #pragma deprecated(RtlLargeIntegerNotEqualToZero) // Use native __int64 math
  2025. #pragma deprecated(RtlLargeIntegerLessThanZero) // Use native __int64 math
  2026. #pragma deprecated(RtlLargeIntegerLessOrEqualToZero) // Use native __int64 math
  2027. #endif
  2028. #define RtlLargeIntegerGreaterThan(X,Y) ( \
  2029. (((X).HighPart == (Y).HighPart) && ((X).LowPart > (Y).LowPart)) || \
  2030. ((X).HighPart > (Y).HighPart) \
  2031. )
  2032. #define RtlLargeIntegerGreaterThanOrEqualTo(X,Y) ( \
  2033. (((X).HighPart == (Y).HighPart) && ((X).LowPart >= (Y).LowPart)) || \
  2034. ((X).HighPart > (Y).HighPart) \
  2035. )
  2036. #define RtlLargeIntegerEqualTo(X,Y) ( \
  2037. !(((X).LowPart ^ (Y).LowPart) | ((X).HighPart ^ (Y).HighPart)) \
  2038. )
  2039. #define RtlLargeIntegerNotEqualTo(X,Y) ( \
  2040. (((X).LowPart ^ (Y).LowPart) | ((X).HighPart ^ (Y).HighPart)) \
  2041. )
  2042. #define RtlLargeIntegerLessThan(X,Y) ( \
  2043. (((X).HighPart == (Y).HighPart) && ((X).LowPart < (Y).LowPart)) || \
  2044. ((X).HighPart < (Y).HighPart) \
  2045. )
  2046. #define RtlLargeIntegerLessThanOrEqualTo(X,Y) ( \
  2047. (((X).HighPart == (Y).HighPart) && ((X).LowPart <= (Y).LowPart)) || \
  2048. ((X).HighPart < (Y).HighPart) \
  2049. )
  2050. #define RtlLargeIntegerGreaterThanZero(X) ( \
  2051. (((X).HighPart == 0) && ((X).LowPart > 0)) || \
  2052. ((X).HighPart > 0 ) \
  2053. )
  2054. #define RtlLargeIntegerGreaterOrEqualToZero(X) ( \
  2055. (X).HighPart >= 0 \
  2056. )
  2057. #define RtlLargeIntegerEqualToZero(X) ( \
  2058. !((X).LowPart | (X).HighPart) \
  2059. )
  2060. #define RtlLargeIntegerNotEqualToZero(X) ( \
  2061. ((X).LowPart | (X).HighPart) \
  2062. )
  2063. #define RtlLargeIntegerLessThanZero(X) ( \
  2064. ((X).HighPart < 0) \
  2065. )
  2066. #define RtlLargeIntegerLessOrEqualToZero(X) ( \
  2067. ((X).HighPart < 0) || !((X).LowPart | (X).HighPart) \
  2068. )
  2069. #endif // !defined(MIDL_PASS)
  2070. //
  2071. // Time conversion routines
  2072. //
  2073. typedef struct _TIME_FIELDS {
  2074. CSHORT Year; // range [1601...]
  2075. CSHORT Month; // range [1..12]
  2076. CSHORT Day; // range [1..31]
  2077. CSHORT Hour; // range [0..23]
  2078. CSHORT Minute; // range [0..59]
  2079. CSHORT Second; // range [0..59]
  2080. CSHORT Milliseconds;// range [0..999]
  2081. CSHORT Weekday; // range [0..6] == [Sunday..Saturday]
  2082. } TIME_FIELDS;
  2083. typedef TIME_FIELDS *PTIME_FIELDS;
  2084. NTSYSAPI
  2085. VOID
  2086. NTAPI
  2087. RtlTimeToTimeFields (
  2088. PLARGE_INTEGER Time,
  2089. PTIME_FIELDS TimeFields
  2090. );
  2091. //
  2092. // A time field record (Weekday ignored) -> 64 bit Time value
  2093. //
  2094. NTSYSAPI
  2095. BOOLEAN
  2096. NTAPI
  2097. RtlTimeFieldsToTime (
  2098. PTIME_FIELDS TimeFields,
  2099. PLARGE_INTEGER Time
  2100. );
  2101. //
  2102. // The following macros store and retrieve USHORTS and ULONGS from potentially
  2103. // unaligned addresses, avoiding alignment faults. they should probably be
  2104. // rewritten in assembler
  2105. //
  2106. #define SHORT_SIZE (sizeof(USHORT))
  2107. #define SHORT_MASK (SHORT_SIZE - 1)
  2108. #define LONG_SIZE (sizeof(LONG))
  2109. #define LONGLONG_SIZE (sizeof(LONGLONG))
  2110. #define LONG_MASK (LONG_SIZE - 1)
  2111. #define LONGLONG_MASK (LONGLONG_SIZE - 1)
  2112. #define LOWBYTE_MASK 0x00FF
  2113. #define FIRSTBYTE(VALUE) ((VALUE) & LOWBYTE_MASK)
  2114. #define SECONDBYTE(VALUE) (((VALUE) >> 8) & LOWBYTE_MASK)
  2115. #define THIRDBYTE(VALUE) (((VALUE) >> 16) & LOWBYTE_MASK)
  2116. #define FOURTHBYTE(VALUE) (((VALUE) >> 24) & LOWBYTE_MASK)
  2117. //
  2118. // if MIPS Big Endian, order of bytes is reversed.
  2119. //
  2120. #define SHORT_LEAST_SIGNIFICANT_BIT 0
  2121. #define SHORT_MOST_SIGNIFICANT_BIT 1
  2122. #define LONG_LEAST_SIGNIFICANT_BIT 0
  2123. #define LONG_3RD_MOST_SIGNIFICANT_BIT 1
  2124. #define LONG_2ND_MOST_SIGNIFICANT_BIT 2
  2125. #define LONG_MOST_SIGNIFICANT_BIT 3
  2126. //++
  2127. //
  2128. // VOID
  2129. // RtlStoreUshort (
  2130. // PUSHORT ADDRESS
  2131. // USHORT VALUE
  2132. // )
  2133. //
  2134. // Routine Description:
  2135. //
  2136. // This macro stores a USHORT value in at a particular address, avoiding
  2137. // alignment faults.
  2138. //
  2139. // Arguments:
  2140. //
  2141. // ADDRESS - where to store USHORT value
  2142. // VALUE - USHORT to store
  2143. //
  2144. // Return Value:
  2145. //
  2146. // none.
  2147. //
  2148. //--
  2149. #define RtlStoreUshort(ADDRESS,VALUE) \
  2150. if ((ULONG_PTR)(ADDRESS) & SHORT_MASK) { \
  2151. ((PUCHAR) (ADDRESS))[SHORT_LEAST_SIGNIFICANT_BIT] = (UCHAR)(FIRSTBYTE(VALUE)); \
  2152. ((PUCHAR) (ADDRESS))[SHORT_MOST_SIGNIFICANT_BIT ] = (UCHAR)(SECONDBYTE(VALUE)); \
  2153. } \
  2154. else { \
  2155. *((PUSHORT) (ADDRESS)) = (USHORT) VALUE; \
  2156. }
  2157. //++
  2158. //
  2159. // VOID
  2160. // RtlStoreUlong (
  2161. // PULONG ADDRESS
  2162. // ULONG VALUE
  2163. // )
  2164. //
  2165. // Routine Description:
  2166. //
  2167. // This macro stores a ULONG value in at a particular address, avoiding
  2168. // alignment faults.
  2169. //
  2170. // Arguments:
  2171. //
  2172. // ADDRESS - where to store ULONG value
  2173. // VALUE - ULONG to store
  2174. //
  2175. // Return Value:
  2176. //
  2177. // none.
  2178. //
  2179. // Note:
  2180. // Depending on the machine, we might want to call storeushort in the
  2181. // unaligned case.
  2182. //
  2183. //--
  2184. #define RtlStoreUlong(ADDRESS,VALUE) \
  2185. if ((ULONG_PTR)(ADDRESS) & LONG_MASK) { \
  2186. ((PUCHAR) (ADDRESS))[LONG_LEAST_SIGNIFICANT_BIT ] = (UCHAR)(FIRSTBYTE(VALUE)); \
  2187. ((PUCHAR) (ADDRESS))[LONG_3RD_MOST_SIGNIFICANT_BIT ] = (UCHAR)(SECONDBYTE(VALUE)); \
  2188. ((PUCHAR) (ADDRESS))[LONG_2ND_MOST_SIGNIFICANT_BIT ] = (UCHAR)(THIRDBYTE(VALUE)); \
  2189. ((PUCHAR) (ADDRESS))[LONG_MOST_SIGNIFICANT_BIT ] = (UCHAR)(FOURTHBYTE(VALUE)); \
  2190. } \
  2191. else { \
  2192. *((PULONG) (ADDRESS)) = (ULONG) (VALUE); \
  2193. }
  2194. //++
  2195. //
  2196. // VOID
  2197. // RtlStoreUlonglong (
  2198. // PULONGLONG ADDRESS
  2199. // ULONG VALUE
  2200. // )
  2201. //
  2202. // Routine Description:
  2203. //
  2204. // This macro stores a ULONGLONG value in at a particular address, avoiding
  2205. // alignment faults.
  2206. //
  2207. // Arguments:
  2208. //
  2209. // ADDRESS - where to store ULONGLONG value
  2210. // VALUE - ULONGLONG to store
  2211. //
  2212. // Return Value:
  2213. //
  2214. // none.
  2215. //
  2216. //--
  2217. #define RtlStoreUlonglong(ADDRESS,VALUE) \
  2218. if ((ULONG_PTR)(ADDRESS) & LONGLONG_MASK) { \
  2219. RtlStoreUlong((ULONG_PTR)(ADDRESS), \
  2220. (ULONGLONG)(VALUE) & 0xFFFFFFFF); \
  2221. RtlStoreUlong((ULONG_PTR)(ADDRESS)+sizeof(ULONG), \
  2222. (ULONGLONG)(VALUE) >> 32); \
  2223. } else { \
  2224. *((PULONGLONG)(ADDRESS)) = (ULONGLONG)(VALUE); \
  2225. }
  2226. //++
  2227. //
  2228. // VOID
  2229. // RtlStoreUlongPtr (
  2230. // PULONG_PTR ADDRESS
  2231. // ULONG_PTR VALUE
  2232. // )
  2233. //
  2234. // Routine Description:
  2235. //
  2236. // This macro stores a ULONG_PTR value in at a particular address, avoiding
  2237. // alignment faults.
  2238. //
  2239. // Arguments:
  2240. //
  2241. // ADDRESS - where to store ULONG_PTR value
  2242. // VALUE - ULONG_PTR to store
  2243. //
  2244. // Return Value:
  2245. //
  2246. // none.
  2247. //
  2248. //--
  2249. #ifdef _WIN64
  2250. #define RtlStoreUlongPtr(ADDRESS,VALUE) \
  2251. RtlStoreUlonglong(ADDRESS,VALUE)
  2252. #else
  2253. #define RtlStoreUlongPtr(ADDRESS,VALUE) \
  2254. RtlStoreUlong(ADDRESS,VALUE)
  2255. #endif
  2256. //++
  2257. //
  2258. // VOID
  2259. // RtlRetrieveUshort (
  2260. // PUSHORT DESTINATION_ADDRESS
  2261. // PUSHORT SOURCE_ADDRESS
  2262. // )
  2263. //
  2264. // Routine Description:
  2265. //
  2266. // This macro retrieves a USHORT value from the SOURCE address, avoiding
  2267. // alignment faults. The DESTINATION address is assumed to be aligned.
  2268. //
  2269. // Arguments:
  2270. //
  2271. // DESTINATION_ADDRESS - where to store USHORT value
  2272. // SOURCE_ADDRESS - where to retrieve USHORT value from
  2273. //
  2274. // Return Value:
  2275. //
  2276. // none.
  2277. //
  2278. //--
  2279. #define RtlRetrieveUshort(DEST_ADDRESS,SRC_ADDRESS) \
  2280. if ((ULONG_PTR)SRC_ADDRESS & SHORT_MASK) { \
  2281. ((PUCHAR) DEST_ADDRESS)[0] = ((PUCHAR) SRC_ADDRESS)[0]; \
  2282. ((PUCHAR) DEST_ADDRESS)[1] = ((PUCHAR) SRC_ADDRESS)[1]; \
  2283. } \
  2284. else { \
  2285. *((PUSHORT) DEST_ADDRESS) = *((PUSHORT) SRC_ADDRESS); \
  2286. } \
  2287. //++
  2288. //
  2289. // VOID
  2290. // RtlRetrieveUlong (
  2291. // PULONG DESTINATION_ADDRESS
  2292. // PULONG SOURCE_ADDRESS
  2293. // )
  2294. //
  2295. // Routine Description:
  2296. //
  2297. // This macro retrieves a ULONG value from the SOURCE address, avoiding
  2298. // alignment faults. The DESTINATION address is assumed to be aligned.
  2299. //
  2300. // Arguments:
  2301. //
  2302. // DESTINATION_ADDRESS - where to store ULONG value
  2303. // SOURCE_ADDRESS - where to retrieve ULONG value from
  2304. //
  2305. // Return Value:
  2306. //
  2307. // none.
  2308. //
  2309. // Note:
  2310. // Depending on the machine, we might want to call retrieveushort in the
  2311. // unaligned case.
  2312. //
  2313. //--
  2314. #define RtlRetrieveUlong(DEST_ADDRESS,SRC_ADDRESS) \
  2315. if ((ULONG_PTR)SRC_ADDRESS & LONG_MASK) { \
  2316. ((PUCHAR) DEST_ADDRESS)[0] = ((PUCHAR) SRC_ADDRESS)[0]; \
  2317. ((PUCHAR) DEST_ADDRESS)[1] = ((PUCHAR) SRC_ADDRESS)[1]; \
  2318. ((PUCHAR) DEST_ADDRESS)[2] = ((PUCHAR) SRC_ADDRESS)[2]; \
  2319. ((PUCHAR) DEST_ADDRESS)[3] = ((PUCHAR) SRC_ADDRESS)[3]; \
  2320. } \
  2321. else { \
  2322. *((PULONG) DEST_ADDRESS) = *((PULONG) SRC_ADDRESS); \
  2323. }
  2324. //
  2325. // BitMap routines. The following structure, routines, and macros are
  2326. // for manipulating bitmaps. The user is responsible for allocating a bitmap
  2327. // structure (which is really a header) and a buffer (which must be longword
  2328. // aligned and multiple longwords in size).
  2329. //
  2330. typedef struct _RTL_BITMAP {
  2331. ULONG SizeOfBitMap; // Number of bits in bit map
  2332. PULONG Buffer; // Pointer to the bit map itself
  2333. } RTL_BITMAP;
  2334. typedef RTL_BITMAP *PRTL_BITMAP;
  2335. //
  2336. // The following routine initializes a new bitmap. It does not alter the
  2337. // data currently in the bitmap. This routine must be called before
  2338. // any other bitmap routine/macro.
  2339. //
  2340. NTSYSAPI
  2341. VOID
  2342. NTAPI
  2343. RtlInitializeBitMap (
  2344. PRTL_BITMAP BitMapHeader,
  2345. PULONG BitMapBuffer,
  2346. ULONG SizeOfBitMap
  2347. );
  2348. //
  2349. // The following three routines clear, set, and test the state of a
  2350. // single bit in a bitmap.
  2351. //
  2352. NTSYSAPI
  2353. VOID
  2354. NTAPI
  2355. RtlClearBit (
  2356. PRTL_BITMAP BitMapHeader,
  2357. ULONG BitNumber
  2358. );
  2359. NTSYSAPI
  2360. VOID
  2361. NTAPI
  2362. RtlSetBit (
  2363. PRTL_BITMAP BitMapHeader,
  2364. ULONG BitNumber
  2365. );
  2366. NTSYSAPI
  2367. BOOLEAN
  2368. NTAPI
  2369. RtlTestBit (
  2370. PRTL_BITMAP BitMapHeader,
  2371. ULONG BitNumber
  2372. );
  2373. //
  2374. // The following two routines either clear or set all of the bits
  2375. // in a bitmap.
  2376. //
  2377. NTSYSAPI
  2378. VOID
  2379. NTAPI
  2380. RtlClearAllBits (
  2381. PRTL_BITMAP BitMapHeader
  2382. );
  2383. NTSYSAPI
  2384. VOID
  2385. NTAPI
  2386. RtlSetAllBits (
  2387. PRTL_BITMAP BitMapHeader
  2388. );
  2389. //
  2390. // The following two routines locate a contiguous region of either
  2391. // clear or set bits within the bitmap. The region will be at least
  2392. // as large as the number specified, and the search of the bitmap will
  2393. // begin at the specified hint index (which is a bit index within the
  2394. // bitmap, zero based). The return value is the bit index of the located
  2395. // region (zero based) or -1 (i.e., 0xffffffff) if such a region cannot
  2396. // be located
  2397. //
  2398. NTSYSAPI
  2399. ULONG
  2400. NTAPI
  2401. RtlFindClearBits (
  2402. PRTL_BITMAP BitMapHeader,
  2403. ULONG NumberToFind,
  2404. ULONG HintIndex
  2405. );
  2406. NTSYSAPI
  2407. ULONG
  2408. NTAPI
  2409. RtlFindSetBits (
  2410. PRTL_BITMAP BitMapHeader,
  2411. ULONG NumberToFind,
  2412. ULONG HintIndex
  2413. );
  2414. //
  2415. // The following two routines locate a contiguous region of either
  2416. // clear or set bits within the bitmap and either set or clear the bits
  2417. // within the located region. The region will be as large as the number
  2418. // specified, and the search for the region will begin at the specified
  2419. // hint index (which is a bit index within the bitmap, zero based). The
  2420. // return value is the bit index of the located region (zero based) or
  2421. // -1 (i.e., 0xffffffff) if such a region cannot be located. If a region
  2422. // cannot be located then the setting/clearing of the bitmap is not performed.
  2423. //
  2424. NTSYSAPI
  2425. ULONG
  2426. NTAPI
  2427. RtlFindClearBitsAndSet (
  2428. PRTL_BITMAP BitMapHeader,
  2429. ULONG NumberToFind,
  2430. ULONG HintIndex
  2431. );
  2432. NTSYSAPI
  2433. ULONG
  2434. NTAPI
  2435. RtlFindSetBitsAndClear (
  2436. PRTL_BITMAP BitMapHeader,
  2437. ULONG NumberToFind,
  2438. ULONG HintIndex
  2439. );
  2440. //
  2441. // The following two routines clear or set bits within a specified region
  2442. // of the bitmap. The starting index is zero based.
  2443. //
  2444. NTSYSAPI
  2445. VOID
  2446. NTAPI
  2447. RtlClearBits (
  2448. PRTL_BITMAP BitMapHeader,
  2449. ULONG StartingIndex,
  2450. ULONG NumberToClear
  2451. );
  2452. NTSYSAPI
  2453. VOID
  2454. NTAPI
  2455. RtlSetBits (
  2456. PRTL_BITMAP BitMapHeader,
  2457. ULONG StartingIndex,
  2458. ULONG NumberToSet
  2459. );
  2460. //
  2461. // The following routine locates a set of contiguous regions of clear
  2462. // bits within the bitmap. The caller specifies whether to return the
  2463. // longest runs or just the first found lcoated. The following structure is
  2464. // used to denote a contiguous run of bits. The two routines return an array
  2465. // of this structure, one for each run located.
  2466. //
  2467. typedef struct _RTL_BITMAP_RUN {
  2468. ULONG StartingIndex;
  2469. ULONG NumberOfBits;
  2470. } RTL_BITMAP_RUN;
  2471. typedef RTL_BITMAP_RUN *PRTL_BITMAP_RUN;
  2472. NTSYSAPI
  2473. ULONG
  2474. NTAPI
  2475. RtlFindClearRuns (
  2476. PRTL_BITMAP BitMapHeader,
  2477. PRTL_BITMAP_RUN RunArray,
  2478. ULONG SizeOfRunArray,
  2479. BOOLEAN LocateLongestRuns
  2480. );
  2481. //
  2482. // The following routine locates the longest contiguous region of
  2483. // clear bits within the bitmap. The returned starting index value
  2484. // denotes the first contiguous region located satisfying our requirements
  2485. // The return value is the length (in bits) of the longest region found.
  2486. //
  2487. NTSYSAPI
  2488. ULONG
  2489. NTAPI
  2490. RtlFindLongestRunClear (
  2491. PRTL_BITMAP BitMapHeader,
  2492. PULONG StartingIndex
  2493. );
  2494. //
  2495. // The following routine locates the first contiguous region of
  2496. // clear bits within the bitmap. The returned starting index value
  2497. // denotes the first contiguous region located satisfying our requirements
  2498. // The return value is the length (in bits) of the region found.
  2499. //
  2500. NTSYSAPI
  2501. ULONG
  2502. NTAPI
  2503. RtlFindFirstRunClear (
  2504. PRTL_BITMAP BitMapHeader,
  2505. PULONG StartingIndex
  2506. );
  2507. //
  2508. // The following macro returns the value of the bit stored within the
  2509. // bitmap at the specified location. If the bit is set a value of 1 is
  2510. // returned otherwise a value of 0 is returned.
  2511. //
  2512. // ULONG
  2513. // RtlCheckBit (
  2514. // PRTL_BITMAP BitMapHeader,
  2515. // ULONG BitPosition
  2516. // );
  2517. //
  2518. //
  2519. // To implement CheckBit the macro retrieves the longword containing the
  2520. // bit in question, shifts the longword to get the bit in question into the
  2521. // low order bit position and masks out all other bits.
  2522. //
  2523. #define RtlCheckBit(BMH,BP) ((((BMH)->Buffer[(BP) / 32]) >> ((BP) % 32)) & 0x1)
  2524. //
  2525. // The following two procedures return to the caller the total number of
  2526. // clear or set bits within the specified bitmap.
  2527. //
  2528. NTSYSAPI
  2529. ULONG
  2530. NTAPI
  2531. RtlNumberOfClearBits (
  2532. PRTL_BITMAP BitMapHeader
  2533. );
  2534. NTSYSAPI
  2535. ULONG
  2536. NTAPI
  2537. RtlNumberOfSetBits (
  2538. PRTL_BITMAP BitMapHeader
  2539. );
  2540. //
  2541. // The following two procedures return to the caller a boolean value
  2542. // indicating if the specified range of bits are all clear or set.
  2543. //
  2544. NTSYSAPI
  2545. BOOLEAN
  2546. NTAPI
  2547. RtlAreBitsClear (
  2548. PRTL_BITMAP BitMapHeader,
  2549. ULONG StartingIndex,
  2550. ULONG Length
  2551. );
  2552. NTSYSAPI
  2553. BOOLEAN
  2554. NTAPI
  2555. RtlAreBitsSet (
  2556. PRTL_BITMAP BitMapHeader,
  2557. ULONG StartingIndex,
  2558. ULONG Length
  2559. );
  2560. NTSYSAPI
  2561. ULONG
  2562. NTAPI
  2563. RtlFindNextForwardRunClear (
  2564. IN PRTL_BITMAP BitMapHeader,
  2565. IN ULONG FromIndex,
  2566. IN PULONG StartingRunIndex
  2567. );
  2568. NTSYSAPI
  2569. ULONG
  2570. NTAPI
  2571. RtlFindLastBackwardRunClear (
  2572. IN PRTL_BITMAP BitMapHeader,
  2573. IN ULONG FromIndex,
  2574. IN PULONG StartingRunIndex
  2575. );
  2576. //
  2577. // The following two procedures return to the caller a value indicating
  2578. // the position within a ULONGLONG of the most or least significant non-zero
  2579. // bit. A value of zero results in a return value of -1.
  2580. //
  2581. NTSYSAPI
  2582. CCHAR
  2583. NTAPI
  2584. RtlFindLeastSignificantBit (
  2585. IN ULONGLONG Set
  2586. );
  2587. NTSYSAPI
  2588. CCHAR
  2589. NTAPI
  2590. RtlFindMostSignificantBit (
  2591. IN ULONGLONG Set
  2592. );
  2593. //
  2594. // SecurityDescriptor RTL routine definitions
  2595. //
  2596. NTSYSAPI
  2597. NTSTATUS
  2598. NTAPI
  2599. RtlCreateSecurityDescriptor (
  2600. PSECURITY_DESCRIPTOR SecurityDescriptor,
  2601. ULONG Revision
  2602. );
  2603. NTSYSAPI
  2604. BOOLEAN
  2605. NTAPI
  2606. RtlValidSecurityDescriptor (
  2607. PSECURITY_DESCRIPTOR SecurityDescriptor
  2608. );
  2609. NTSYSAPI
  2610. ULONG
  2611. NTAPI
  2612. RtlLengthSecurityDescriptor (
  2613. PSECURITY_DESCRIPTOR SecurityDescriptor
  2614. );
  2615. NTSYSAPI
  2616. BOOLEAN
  2617. NTAPI
  2618. RtlValidRelativeSecurityDescriptor (
  2619. IN PSECURITY_DESCRIPTOR SecurityDescriptorInput,
  2620. IN ULONG SecurityDescriptorLength,
  2621. IN SECURITY_INFORMATION RequiredInformation
  2622. );
  2623. NTSYSAPI
  2624. NTSTATUS
  2625. NTAPI
  2626. RtlSetDaclSecurityDescriptor (
  2627. PSECURITY_DESCRIPTOR SecurityDescriptor,
  2628. BOOLEAN DaclPresent,
  2629. PACL Dacl,
  2630. BOOLEAN DaclDefaulted
  2631. );
  2632. //
  2633. // Byte swap routines. These are used to convert from little-endian to
  2634. // big-endian and vice-versa.
  2635. //
  2636. #if (defined(_M_IX86) && (_MSC_FULL_VER > 13009037)) || ((defined(_M_AMD64) || defined(_M_IA64)) && (_MSC_FULL_VER > 13009175))
  2637. #ifdef __cplusplus
  2638. extern "C" {
  2639. #endif
  2640. unsigned short __cdecl _byteswap_ushort(unsigned short);
  2641. unsigned long __cdecl _byteswap_ulong (unsigned long);
  2642. unsigned __int64 __cdecl _byteswap_uint64(unsigned __int64);
  2643. #ifdef __cplusplus
  2644. }
  2645. #endif
  2646. #pragma intrinsic(_byteswap_ushort)
  2647. #pragma intrinsic(_byteswap_ulong)
  2648. #pragma intrinsic(_byteswap_uint64)
  2649. #define RtlUshortByteSwap(_x) _byteswap_ushort((USHORT)(_x))
  2650. #define RtlUlongByteSwap(_x) _byteswap_ulong((_x))
  2651. #define RtlUlonglongByteSwap(_x) _byteswap_uint64((_x))
  2652. #else
  2653. USHORT
  2654. FASTCALL
  2655. RtlUshortByteSwap(
  2656. IN USHORT Source
  2657. );
  2658. ULONG
  2659. FASTCALL
  2660. RtlUlongByteSwap(
  2661. IN ULONG Source
  2662. );
  2663. ULONGLONG
  2664. FASTCALL
  2665. RtlUlonglongByteSwap(
  2666. IN ULONGLONG Source
  2667. );
  2668. #endif
  2669. //
  2670. // Component name filter id enumeration and levels.
  2671. //
  2672. #define DPFLTR_ERROR_LEVEL 0
  2673. #define DPFLTR_WARNING_LEVEL 1
  2674. #define DPFLTR_TRACE_LEVEL 2
  2675. #define DPFLTR_INFO_LEVEL 3
  2676. #define DPFLTR_MASK 0x80000000
  2677. typedef enum _DPFLTR_TYPE {
  2678. DPFLTR_SYSTEM_ID = 0,
  2679. DPFLTR_SMSS_ID = 1,
  2680. DPFLTR_SETUP_ID = 2,
  2681. DPFLTR_NTFS_ID = 3,
  2682. DPFLTR_FSTUB_ID = 4,
  2683. DPFLTR_CRASHDUMP_ID = 5,
  2684. DPFLTR_CDAUDIO_ID = 6,
  2685. DPFLTR_CDROM_ID = 7,
  2686. DPFLTR_CLASSPNP_ID = 8,
  2687. DPFLTR_DISK_ID = 9,
  2688. DPFLTR_REDBOOK_ID = 10,
  2689. DPFLTR_STORPROP_ID = 11,
  2690. DPFLTR_SCSIPORT_ID = 12,
  2691. DPFLTR_SCSIMINIPORT_ID = 13,
  2692. DPFLTR_CONFIG_ID = 14,
  2693. DPFLTR_I8042PRT_ID = 15,
  2694. DPFLTR_SERMOUSE_ID = 16,
  2695. DPFLTR_LSERMOUS_ID = 17,
  2696. DPFLTR_KBDHID_ID = 18,
  2697. DPFLTR_MOUHID_ID = 19,
  2698. DPFLTR_KBDCLASS_ID = 20,
  2699. DPFLTR_MOUCLASS_ID = 21,
  2700. DPFLTR_TWOTRACK_ID = 22,
  2701. DPFLTR_WMILIB_ID = 23,
  2702. DPFLTR_ACPI_ID = 24,
  2703. DPFLTR_AMLI_ID = 25,
  2704. DPFLTR_HALIA64_ID = 26,
  2705. DPFLTR_VIDEO_ID = 27,
  2706. DPFLTR_SVCHOST_ID = 28,
  2707. DPFLTR_VIDEOPRT_ID = 29,
  2708. DPFLTR_TCPIP_ID = 30,
  2709. DPFLTR_DMSYNTH_ID = 31,
  2710. DPFLTR_NTOSPNP_ID = 32,
  2711. DPFLTR_FASTFAT_ID = 33,
  2712. DPFLTR_SAMSS_ID = 34,
  2713. DPFLTR_PNPMGR_ID = 35,
  2714. DPFLTR_NETAPI_ID = 36,
  2715. DPFLTR_SCSERVER_ID = 37,
  2716. DPFLTR_SCCLIENT_ID = 38,
  2717. DPFLTR_SERIAL_ID = 39,
  2718. DPFLTR_SERENUM_ID = 40,
  2719. DPFLTR_UHCD_ID = 41,
  2720. DPFLTR_RPCPROXY_ID = 42,
  2721. DPFLTR_AUTOCHK_ID = 43,
  2722. DPFLTR_DCOMSS_ID = 44,
  2723. DPFLTR_UNIMODEM_ID = 45,
  2724. DPFLTR_SIS_ID = 46,
  2725. DPFLTR_FLTMGR_ID = 47,
  2726. DPFLTR_WMICORE_ID = 48,
  2727. DPFLTR_BURNENG_ID = 49,
  2728. DPFLTR_IMAPI_ID = 50,
  2729. DPFLTR_SXS_ID = 51,
  2730. DPFLTR_FUSION_ID = 52,
  2731. DPFLTR_IDLETASK_ID = 53,
  2732. DPFLTR_SOFTPCI_ID = 54,
  2733. DPFLTR_TAPE_ID = 55,
  2734. DPFLTR_MCHGR_ID = 56,
  2735. DPFLTR_IDEP_ID = 57,
  2736. DPFLTR_PCIIDE_ID = 58,
  2737. DPFLTR_FLOPPY_ID = 59,
  2738. DPFLTR_FDC_ID = 60,
  2739. DPFLTR_TERMSRV_ID = 61,
  2740. DPFLTR_W32TIME_ID = 62,
  2741. DPFLTR_PREFETCHER_ID = 63,
  2742. DPFLTR_RSFILTER_ID = 64,
  2743. DPFLTR_FCPORT_ID = 65,
  2744. DPFLTR_PCI_ID = 66,
  2745. DPFLTR_DMIO_ID = 67,
  2746. DPFLTR_DMCONFIG_ID = 68,
  2747. DPFLTR_DMADMIN_ID = 69,
  2748. DPFLTR_WSOCKTRANSPORT_ID = 70,
  2749. DPFLTR_VSS_ID = 71,
  2750. DPFLTR_PNPMEM_ID = 72,
  2751. DPFLTR_PROCESSOR_ID = 73,
  2752. DPFLTR_DMSERVER_ID = 74,
  2753. DPFLTR_SR_ID = 75,
  2754. DPFLTR_INFINIBAND_ID = 76,
  2755. DPFLTR_IHVDRIVER_ID = 77,
  2756. DPFLTR_IHVVIDEO_ID = 78,
  2757. DPFLTR_IHVAUDIO_ID = 79,
  2758. DPFLTR_IHVNETWORK_ID = 80,
  2759. DPFLTR_IHVSTREAMING_ID = 81,
  2760. DPFLTR_IHVBUS_ID = 82,
  2761. DPFLTR_HPS_ID = 83,
  2762. DPFLTR_RTLTHREADPOOL_ID = 84,
  2763. DPFLTR_LDR_ID = 85,
  2764. DPFLTR_TCPIP6_ID = 86,
  2765. DPFLTR_ISAPNP_ID = 87,
  2766. DPFLTR_SHPC_ID = 88,
  2767. DPFLTR_STORPORT_ID = 89,
  2768. DPFLTR_STORMINIPORT_ID = 90,
  2769. DPFLTR_PRINTSPOOLER_ID = 91,
  2770. DPFLTR_VSSDYNDISK_ID = 92,
  2771. DPFLTR_VERIFIER_ID = 93,
  2772. DPFLTR_VDS_ID = 94,
  2773. DPFLTR_VDSBAS_ID = 95,
  2774. DPFLTR_VDSDYNDR_ID = 96,
  2775. DPFLTR_VDSUTIL_ID = 97,
  2776. DPFLTR_DFRGIFC_ID = 98,
  2777. DPFLTR_ENDOFTABLE_ID
  2778. } DPFLTR_TYPE;
  2779. //
  2780. // Define the various device type values. Note that values used by Microsoft
  2781. // Corporation are in the range 0-32767, and 32768-65535 are reserved for use
  2782. // by customers.
  2783. //
  2784. #define DEVICE_TYPE ULONG
  2785. #define FILE_DEVICE_BEEP 0x00000001
  2786. #define FILE_DEVICE_CD_ROM 0x00000002
  2787. #define FILE_DEVICE_CD_ROM_FILE_SYSTEM 0x00000003
  2788. #define FILE_DEVICE_CONTROLLER 0x00000004
  2789. #define FILE_DEVICE_DATALINK 0x00000005
  2790. #define FILE_DEVICE_DFS 0x00000006
  2791. #define FILE_DEVICE_DISK 0x00000007
  2792. #define FILE_DEVICE_DISK_FILE_SYSTEM 0x00000008
  2793. #define FILE_DEVICE_FILE_SYSTEM 0x00000009
  2794. #define FILE_DEVICE_INPORT_PORT 0x0000000a
  2795. #define FILE_DEVICE_KEYBOARD 0x0000000b
  2796. #define FILE_DEVICE_MAILSLOT 0x0000000c
  2797. #define FILE_DEVICE_MIDI_IN 0x0000000d
  2798. #define FILE_DEVICE_MIDI_OUT 0x0000000e
  2799. #define FILE_DEVICE_MOUSE 0x0000000f
  2800. #define FILE_DEVICE_MULTI_UNC_PROVIDER 0x00000010
  2801. #define FILE_DEVICE_NAMED_PIPE 0x00000011
  2802. #define FILE_DEVICE_NETWORK 0x00000012
  2803. #define FILE_DEVICE_NETWORK_BROWSER 0x00000013
  2804. #define FILE_DEVICE_NETWORK_FILE_SYSTEM 0x00000014
  2805. #define FILE_DEVICE_NULL 0x00000015
  2806. #define FILE_DEVICE_PARALLEL_PORT 0x00000016
  2807. #define FILE_DEVICE_PHYSICAL_NETCARD 0x00000017
  2808. #define FILE_DEVICE_PRINTER 0x00000018
  2809. #define FILE_DEVICE_SCANNER 0x00000019
  2810. #define FILE_DEVICE_SERIAL_MOUSE_PORT 0x0000001a
  2811. #define FILE_DEVICE_SERIAL_PORT 0x0000001b
  2812. #define FILE_DEVICE_SCREEN 0x0000001c
  2813. #define FILE_DEVICE_SOUND 0x0000001d
  2814. #define FILE_DEVICE_STREAMS 0x0000001e
  2815. #define FILE_DEVICE_TAPE 0x0000001f
  2816. #define FILE_DEVICE_TAPE_FILE_SYSTEM 0x00000020
  2817. #define FILE_DEVICE_TRANSPORT 0x00000021
  2818. #define FILE_DEVICE_UNKNOWN 0x00000022
  2819. #define FILE_DEVICE_VIDEO 0x00000023
  2820. #define FILE_DEVICE_VIRTUAL_DISK 0x00000024
  2821. #define FILE_DEVICE_WAVE_IN 0x00000025
  2822. #define FILE_DEVICE_WAVE_OUT 0x00000026
  2823. #define FILE_DEVICE_8042_PORT 0x00000027
  2824. #define FILE_DEVICE_NETWORK_REDIRECTOR 0x00000028
  2825. #define FILE_DEVICE_BATTERY 0x00000029
  2826. #define FILE_DEVICE_BUS_EXTENDER 0x0000002a
  2827. #define FILE_DEVICE_MODEM 0x0000002b
  2828. #define FILE_DEVICE_VDM 0x0000002c
  2829. #define FILE_DEVICE_MASS_STORAGE 0x0000002d
  2830. #define FILE_DEVICE_SMB 0x0000002e
  2831. #define FILE_DEVICE_KS 0x0000002f
  2832. #define FILE_DEVICE_CHANGER 0x00000030
  2833. #define FILE_DEVICE_SMARTCARD 0x00000031
  2834. #define FILE_DEVICE_ACPI 0x00000032
  2835. #define FILE_DEVICE_DVD 0x00000033
  2836. #define FILE_DEVICE_FULLSCREEN_VIDEO 0x00000034
  2837. #define FILE_DEVICE_DFS_FILE_SYSTEM 0x00000035
  2838. #define FILE_DEVICE_DFS_VOLUME 0x00000036
  2839. #define FILE_DEVICE_SERENUM 0x00000037
  2840. #define FILE_DEVICE_TERMSRV 0x00000038
  2841. #define FILE_DEVICE_KSEC 0x00000039
  2842. #define FILE_DEVICE_FIPS 0x0000003A
  2843. #define FILE_DEVICE_INFINIBAND 0x0000003B
  2844. //
  2845. // Macro definition for defining IOCTL and FSCTL function control codes. Note
  2846. // that function codes 0-2047 are reserved for Microsoft Corporation, and
  2847. // 2048-4095 are reserved for customers.
  2848. //
  2849. #define CTL_CODE( DeviceType, Function, Method, Access ) ( \
  2850. ((DeviceType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method) \
  2851. )
  2852. //
  2853. // Macro to extract device type out of the device io control code
  2854. //
  2855. #define DEVICE_TYPE_FROM_CTL_CODE(ctrlCode) (((ULONG)(ctrlCode & 0xffff0000)) >> 16)
  2856. //
  2857. // Define the method codes for how buffers are passed for I/O and FS controls
  2858. //
  2859. #define METHOD_BUFFERED 0
  2860. #define METHOD_IN_DIRECT 1
  2861. #define METHOD_OUT_DIRECT 2
  2862. #define METHOD_NEITHER 3
  2863. //
  2864. // Define some easier to comprehend aliases:
  2865. // METHOD_DIRECT_TO_HARDWARE (writes, aka METHOD_IN_DIRECT)
  2866. // METHOD_DIRECT_FROM_HARDWARE (reads, aka METHOD_OUT_DIRECT)
  2867. //
  2868. #define METHOD_DIRECT_TO_HARDWARE METHOD_IN_DIRECT
  2869. #define METHOD_DIRECT_FROM_HARDWARE METHOD_OUT_DIRECT
  2870. //
  2871. // Define the access check value for any access
  2872. //
  2873. //
  2874. // The FILE_READ_ACCESS and FILE_WRITE_ACCESS constants are also defined in
  2875. // ntioapi.h as FILE_READ_DATA and FILE_WRITE_DATA. The values for these
  2876. // constants *MUST* always be in sync.
  2877. //
  2878. //
  2879. // FILE_SPECIAL_ACCESS is checked by the NT I/O system the same as FILE_ANY_ACCESS.
  2880. // The file systems, however, may add additional access checks for I/O and FS controls
  2881. // that use this value.
  2882. //
  2883. #define FILE_ANY_ACCESS 0
  2884. #define FILE_SPECIAL_ACCESS (FILE_ANY_ACCESS)
  2885. #define FILE_READ_ACCESS ( 0x0001 ) // file & pipe
  2886. #define FILE_WRITE_ACCESS ( 0x0002 ) // file & pipe
  2887. //
  2888. // Define access rights to files and directories
  2889. //
  2890. //
  2891. // The FILE_READ_DATA and FILE_WRITE_DATA constants are also defined in
  2892. // devioctl.h as FILE_READ_ACCESS and FILE_WRITE_ACCESS. The values for these
  2893. // constants *MUST* always be in sync.
  2894. // The values are redefined in devioctl.h because they must be available to
  2895. // both DOS and NT.
  2896. //
  2897. #define FILE_READ_DATA ( 0x0001 ) // file & pipe
  2898. #define FILE_LIST_DIRECTORY ( 0x0001 ) // directory
  2899. #define FILE_WRITE_DATA ( 0x0002 ) // file & pipe
  2900. #define FILE_ADD_FILE ( 0x0002 ) // directory
  2901. #define FILE_APPEND_DATA ( 0x0004 ) // file
  2902. #define FILE_ADD_SUBDIRECTORY ( 0x0004 ) // directory
  2903. #define FILE_CREATE_PIPE_INSTANCE ( 0x0004 ) // named pipe
  2904. #define FILE_READ_EA ( 0x0008 ) // file & directory
  2905. #define FILE_WRITE_EA ( 0x0010 ) // file & directory
  2906. #define FILE_EXECUTE ( 0x0020 ) // file
  2907. #define FILE_TRAVERSE ( 0x0020 ) // directory
  2908. #define FILE_DELETE_CHILD ( 0x0040 ) // directory
  2909. #define FILE_READ_ATTRIBUTES ( 0x0080 ) // all
  2910. #define FILE_WRITE_ATTRIBUTES ( 0x0100 ) // all
  2911. #define FILE_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | 0x1FF)
  2912. #define FILE_GENERIC_READ (STANDARD_RIGHTS_READ |\
  2913. FILE_READ_DATA |\
  2914. FILE_READ_ATTRIBUTES |\
  2915. FILE_READ_EA |\
  2916. SYNCHRONIZE)
  2917. #define FILE_GENERIC_WRITE (STANDARD_RIGHTS_WRITE |\
  2918. FILE_WRITE_DATA |\
  2919. FILE_WRITE_ATTRIBUTES |\
  2920. FILE_WRITE_EA |\
  2921. FILE_APPEND_DATA |\
  2922. SYNCHRONIZE)
  2923. #define FILE_GENERIC_EXECUTE (STANDARD_RIGHTS_EXECUTE |\
  2924. FILE_READ_ATTRIBUTES |\
  2925. FILE_EXECUTE |\
  2926. SYNCHRONIZE)
  2927. //
  2928. // Define share access rights to files and directories
  2929. //
  2930. #define FILE_SHARE_READ 0x00000001
  2931. #define FILE_SHARE_WRITE 0x00000002
  2932. #define FILE_SHARE_DELETE 0x00000004
  2933. #define FILE_SHARE_VALID_FLAGS 0x00000007
  2934. //
  2935. // Define the file attributes values
  2936. //
  2937. // Note: 0x00000008 is reserved for use for the old DOS VOLID (volume ID)
  2938. // and is therefore not considered valid in NT.
  2939. //
  2940. // Note: 0x00000010 is reserved for use for the old DOS SUBDIRECTORY flag
  2941. // and is therefore not considered valid in NT. This flag has
  2942. // been disassociated with file attributes since the other flags are
  2943. // protected with READ_ and WRITE_ATTRIBUTES access to the file.
  2944. //
  2945. // Note: Note also that the order of these flags is set to allow both the
  2946. // FAT and the Pinball File Systems to directly set the attributes
  2947. // flags in attributes words without having to pick each flag out
  2948. // individually. The order of these flags should not be changed!
  2949. //
  2950. #define FILE_ATTRIBUTE_READONLY 0x00000001
  2951. #define FILE_ATTRIBUTE_HIDDEN 0x00000002
  2952. #define FILE_ATTRIBUTE_SYSTEM 0x00000004
  2953. //OLD DOS VOLID 0x00000008
  2954. #define FILE_ATTRIBUTE_DIRECTORY 0x00000010
  2955. #define FILE_ATTRIBUTE_ARCHIVE 0x00000020
  2956. #define FILE_ATTRIBUTE_DEVICE 0x00000040
  2957. #define FILE_ATTRIBUTE_NORMAL 0x00000080
  2958. #define FILE_ATTRIBUTE_TEMPORARY 0x00000100
  2959. #define FILE_ATTRIBUTE_SPARSE_FILE 0x00000200
  2960. #define FILE_ATTRIBUTE_REPARSE_POINT 0x00000400
  2961. #define FILE_ATTRIBUTE_COMPRESSED 0x00000800
  2962. #define FILE_ATTRIBUTE_OFFLINE 0x00001000
  2963. #define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED 0x00002000
  2964. #define FILE_ATTRIBUTE_ENCRYPTED 0x00004000
  2965. #define FILE_ATTRIBUTE_VALID_FLAGS 0x00007fb7
  2966. #define FILE_ATTRIBUTE_VALID_SET_FLAGS 0x000031a7
  2967. //
  2968. // Define the create disposition values
  2969. //
  2970. #define FILE_SUPERSEDE 0x00000000
  2971. #define FILE_OPEN 0x00000001
  2972. #define FILE_CREATE 0x00000002
  2973. #define FILE_OPEN_IF 0x00000003
  2974. #define FILE_OVERWRITE 0x00000004
  2975. #define FILE_OVERWRITE_IF 0x00000005
  2976. #define FILE_MAXIMUM_DISPOSITION 0x00000005
  2977. //
  2978. // Define the create/open option flags
  2979. //
  2980. #define FILE_DIRECTORY_FILE 0x00000001
  2981. #define FILE_WRITE_THROUGH 0x00000002
  2982. #define FILE_SEQUENTIAL_ONLY 0x00000004
  2983. #define FILE_NO_INTERMEDIATE_BUFFERING 0x00000008
  2984. #define FILE_SYNCHRONOUS_IO_ALERT 0x00000010
  2985. #define FILE_SYNCHRONOUS_IO_NONALERT 0x00000020
  2986. #define FILE_NON_DIRECTORY_FILE 0x00000040
  2987. #define FILE_CREATE_TREE_CONNECTION 0x00000080
  2988. #define FILE_COMPLETE_IF_OPLOCKED 0x00000100
  2989. #define FILE_NO_EA_KNOWLEDGE 0x00000200
  2990. #define FILE_OPEN_FOR_RECOVERY 0x00000400
  2991. #define FILE_RANDOM_ACCESS 0x00000800
  2992. #define FILE_DELETE_ON_CLOSE 0x00001000
  2993. #define FILE_OPEN_BY_FILE_ID 0x00002000
  2994. #define FILE_OPEN_FOR_BACKUP_INTENT 0x00004000
  2995. #define FILE_NO_COMPRESSION 0x00008000
  2996. #define FILE_RESERVE_OPFILTER 0x00100000
  2997. #define FILE_OPEN_REPARSE_POINT 0x00200000
  2998. #define FILE_OPEN_NO_RECALL 0x00400000
  2999. #define FILE_OPEN_FOR_FREE_SPACE_QUERY 0x00800000
  3000. #define FILE_COPY_STRUCTURED_STORAGE 0x00000041
  3001. #define FILE_STRUCTURED_STORAGE 0x00000441
  3002. #define FILE_VALID_OPTION_FLAGS 0x00ffffff
  3003. #define FILE_VALID_PIPE_OPTION_FLAGS 0x00000032
  3004. #define FILE_VALID_MAILSLOT_OPTION_FLAGS 0x00000032
  3005. #define FILE_VALID_SET_FLAGS 0x00000036
  3006. //
  3007. // Define the I/O status information return values for NtCreateFile/NtOpenFile
  3008. //
  3009. #define FILE_SUPERSEDED 0x00000000
  3010. #define FILE_OPENED 0x00000001
  3011. #define FILE_CREATED 0x00000002
  3012. #define FILE_OVERWRITTEN 0x00000003
  3013. #define FILE_EXISTS 0x00000004
  3014. #define FILE_DOES_NOT_EXIST 0x00000005
  3015. //
  3016. // Define special ByteOffset parameters for read and write operations
  3017. //
  3018. #define FILE_WRITE_TO_END_OF_FILE 0xffffffff
  3019. #define FILE_USE_FILE_POINTER_POSITION 0xfffffffe
  3020. //
  3021. // Define alignment requirement values
  3022. //
  3023. #define FILE_BYTE_ALIGNMENT 0x00000000
  3024. #define FILE_WORD_ALIGNMENT 0x00000001
  3025. #define FILE_LONG_ALIGNMENT 0x00000003
  3026. #define FILE_QUAD_ALIGNMENT 0x00000007
  3027. #define FILE_OCTA_ALIGNMENT 0x0000000f
  3028. #define FILE_32_BYTE_ALIGNMENT 0x0000001f
  3029. #define FILE_64_BYTE_ALIGNMENT 0x0000003f
  3030. #define FILE_128_BYTE_ALIGNMENT 0x0000007f
  3031. #define FILE_256_BYTE_ALIGNMENT 0x000000ff
  3032. #define FILE_512_BYTE_ALIGNMENT 0x000001ff
  3033. //
  3034. // Define the maximum length of a filename string
  3035. //
  3036. #define MAXIMUM_FILENAME_LENGTH 256
  3037. //
  3038. // Define the various device characteristics flags
  3039. //
  3040. #define FILE_REMOVABLE_MEDIA 0x00000001
  3041. #define FILE_READ_ONLY_DEVICE 0x00000002
  3042. #define FILE_FLOPPY_DISKETTE 0x00000004
  3043. #define FILE_WRITE_ONCE_MEDIA 0x00000008
  3044. #define FILE_REMOTE_DEVICE 0x00000010
  3045. #define FILE_DEVICE_IS_MOUNTED 0x00000020
  3046. #define FILE_VIRTUAL_VOLUME 0x00000040
  3047. #define FILE_AUTOGENERATED_DEVICE_NAME 0x00000080
  3048. #define FILE_DEVICE_SECURE_OPEN 0x00000100
  3049. #define FILE_CHARACTERISTIC_PNP_DEVICE 0x00000800
  3050. //
  3051. // Define the base asynchronous I/O argument types
  3052. //
  3053. typedef struct _IO_STATUS_BLOCK {
  3054. union {
  3055. NTSTATUS Status;
  3056. PVOID Pointer;
  3057. };
  3058. ULONG_PTR Information;
  3059. } IO_STATUS_BLOCK, *PIO_STATUS_BLOCK;
  3060. #if defined(_WIN64)
  3061. typedef struct _IO_STATUS_BLOCK32 {
  3062. NTSTATUS Status;
  3063. ULONG Information;
  3064. } IO_STATUS_BLOCK32, *PIO_STATUS_BLOCK32;
  3065. #endif
  3066. //
  3067. // Define an Asynchronous Procedure Call from I/O viewpoint
  3068. //
  3069. typedef
  3070. VOID
  3071. (NTAPI *PIO_APC_ROUTINE) (
  3072. IN PVOID ApcContext,
  3073. IN PIO_STATUS_BLOCK IoStatusBlock,
  3074. IN ULONG Reserved
  3075. );
  3076. #define PIO_APC_ROUTINE_DEFINED
  3077. //
  3078. // Define the file information class values
  3079. //
  3080. // WARNING: The order of the following values are assumed by the I/O system.
  3081. // Any changes made here should be reflected there as well.
  3082. //
  3083. typedef enum _FILE_INFORMATION_CLASS {
  3084. FileBasicInformation = 4,
  3085. FileStandardInformation = 5,
  3086. FilePositionInformation = 14,
  3087. FileEndOfFileInformation = 20,
  3088. } FILE_INFORMATION_CLASS, *PFILE_INFORMATION_CLASS;
  3089. //
  3090. // Define the various structures which are returned on query operations
  3091. //
  3092. typedef struct _FILE_BASIC_INFORMATION {
  3093. LARGE_INTEGER CreationTime;
  3094. LARGE_INTEGER LastAccessTime;
  3095. LARGE_INTEGER LastWriteTime;
  3096. LARGE_INTEGER ChangeTime;
  3097. ULONG FileAttributes;
  3098. } FILE_BASIC_INFORMATION, *PFILE_BASIC_INFORMATION;
  3099. typedef struct _FILE_STANDARD_INFORMATION {
  3100. LARGE_INTEGER AllocationSize;
  3101. LARGE_INTEGER EndOfFile;
  3102. ULONG NumberOfLinks;
  3103. BOOLEAN DeletePending;
  3104. BOOLEAN Directory;
  3105. } FILE_STANDARD_INFORMATION, *PFILE_STANDARD_INFORMATION;
  3106. typedef struct _FILE_POSITION_INFORMATION {
  3107. LARGE_INTEGER CurrentByteOffset;
  3108. } FILE_POSITION_INFORMATION, *PFILE_POSITION_INFORMATION;
  3109. typedef struct _FILE_NETWORK_OPEN_INFORMATION {
  3110. LARGE_INTEGER CreationTime;
  3111. LARGE_INTEGER LastAccessTime;
  3112. LARGE_INTEGER LastWriteTime;
  3113. LARGE_INTEGER ChangeTime;
  3114. LARGE_INTEGER AllocationSize;
  3115. LARGE_INTEGER EndOfFile;
  3116. ULONG FileAttributes;
  3117. } FILE_NETWORK_OPEN_INFORMATION, *PFILE_NETWORK_OPEN_INFORMATION;
  3118. typedef struct _FILE_FULL_EA_INFORMATION {
  3119. ULONG NextEntryOffset;
  3120. UCHAR Flags;
  3121. UCHAR EaNameLength;
  3122. USHORT EaValueLength;
  3123. CHAR EaName[1];
  3124. } FILE_FULL_EA_INFORMATION, *PFILE_FULL_EA_INFORMATION;
  3125. //
  3126. // Define the file system information class values
  3127. //
  3128. // WARNING: The order of the following values are assumed by the I/O system.
  3129. // Any changes made here should be reflected there as well.
  3130. typedef enum _FSINFOCLASS {
  3131. FileFsVolumeInformation = 1,
  3132. FileFsLabelInformation, // 2
  3133. FileFsSizeInformation, // 3
  3134. FileFsDeviceInformation, // 4
  3135. FileFsAttributeInformation, // 5
  3136. FileFsControlInformation, // 6
  3137. FileFsFullSizeInformation, // 7
  3138. FileFsObjectIdInformation, // 8
  3139. FileFsDriverPathInformation, // 9
  3140. FileFsMaximumInformation
  3141. } FS_INFORMATION_CLASS, *PFS_INFORMATION_CLASS;
  3142. typedef struct _FILE_FS_DEVICE_INFORMATION {
  3143. DEVICE_TYPE DeviceType;
  3144. ULONG Characteristics;
  3145. } FILE_FS_DEVICE_INFORMATION, *PFILE_FS_DEVICE_INFORMATION;
  3146. //
  3147. // Define the I/O bus interface types.
  3148. //
  3149. typedef enum _INTERFACE_TYPE {
  3150. InterfaceTypeUndefined = -1,
  3151. Internal,
  3152. Isa,
  3153. Eisa,
  3154. MicroChannel,
  3155. TurboChannel,
  3156. PCIBus,
  3157. VMEBus,
  3158. NuBus,
  3159. PCMCIABus,
  3160. CBus,
  3161. MPIBus,
  3162. MPSABus,
  3163. ProcessorInternal,
  3164. InternalPowerBus,
  3165. PNPISABus,
  3166. PNPBus,
  3167. MaximumInterfaceType
  3168. }INTERFACE_TYPE, *PINTERFACE_TYPE;
  3169. //
  3170. // Define the DMA transfer widths.
  3171. //
  3172. typedef enum _DMA_WIDTH {
  3173. Width8Bits,
  3174. Width16Bits,
  3175. Width32Bits,
  3176. MaximumDmaWidth
  3177. }DMA_WIDTH, *PDMA_WIDTH;
  3178. //
  3179. // Define DMA transfer speeds.
  3180. //
  3181. typedef enum _DMA_SPEED {
  3182. Compatible,
  3183. TypeA,
  3184. TypeB,
  3185. TypeC,
  3186. TypeF,
  3187. MaximumDmaSpeed
  3188. }DMA_SPEED, *PDMA_SPEED;
  3189. //
  3190. // Define Interface reference/dereference routines for
  3191. // Interfaces exported by IRP_MN_QUERY_INTERFACE
  3192. //
  3193. typedef VOID (*PINTERFACE_REFERENCE)(PVOID Context);
  3194. typedef VOID (*PINTERFACE_DEREFERENCE)(PVOID Context);
  3195. //
  3196. // Define I/O Driver error log packet structure. This structure is filled in
  3197. // by the driver.
  3198. //
  3199. typedef struct _IO_ERROR_LOG_PACKET {
  3200. UCHAR MajorFunctionCode;
  3201. UCHAR RetryCount;
  3202. USHORT DumpDataSize;
  3203. USHORT NumberOfStrings;
  3204. USHORT StringOffset;
  3205. USHORT EventCategory;
  3206. NTSTATUS ErrorCode;
  3207. ULONG UniqueErrorValue;
  3208. NTSTATUS FinalStatus;
  3209. ULONG SequenceNumber;
  3210. ULONG IoControlCode;
  3211. LARGE_INTEGER DeviceOffset;
  3212. ULONG DumpData[1];
  3213. }IO_ERROR_LOG_PACKET, *PIO_ERROR_LOG_PACKET;
  3214. //
  3215. // Define the I/O error log message. This message is sent by the error log
  3216. // thread over the lpc port.
  3217. //
  3218. typedef struct _IO_ERROR_LOG_MESSAGE {
  3219. USHORT Type;
  3220. USHORT Size;
  3221. USHORT DriverNameLength;
  3222. LARGE_INTEGER TimeStamp;
  3223. ULONG DriverNameOffset;
  3224. IO_ERROR_LOG_PACKET EntryData;
  3225. }IO_ERROR_LOG_MESSAGE, *PIO_ERROR_LOG_MESSAGE;
  3226. //
  3227. // Define the maximum message size that will be sent over the LPC to the
  3228. // application reading the error log entries.
  3229. //
  3230. //
  3231. // Regardless of LPC size restrictions, ERROR_LOG_MAXIMUM_SIZE must remain
  3232. // a value that can fit in a UCHAR.
  3233. //
  3234. #define ERROR_LOG_LIMIT_SIZE (256-16)
  3235. //
  3236. // This limit, exclusive of IO_ERROR_LOG_MESSAGE_HEADER_LENGTH, also applies
  3237. // to IO_ERROR_LOG_MESSAGE_LENGTH
  3238. //
  3239. #define IO_ERROR_LOG_MESSAGE_HEADER_LENGTH (sizeof(IO_ERROR_LOG_MESSAGE) - \
  3240. sizeof(IO_ERROR_LOG_PACKET) + \
  3241. (sizeof(WCHAR) * 40))
  3242. #define ERROR_LOG_MESSAGE_LIMIT_SIZE \
  3243. (ERROR_LOG_LIMIT_SIZE + IO_ERROR_LOG_MESSAGE_HEADER_LENGTH)
  3244. //
  3245. // IO_ERROR_LOG_MESSAGE_LENGTH is
  3246. // min(PORT_MAXIMUM_MESSAGE_LENGTH, ERROR_LOG_MESSAGE_LIMIT_SIZE)
  3247. //
  3248. #define IO_ERROR_LOG_MESSAGE_LENGTH \
  3249. ((PORT_MAXIMUM_MESSAGE_LENGTH > ERROR_LOG_MESSAGE_LIMIT_SIZE) ? \
  3250. ERROR_LOG_MESSAGE_LIMIT_SIZE : \
  3251. PORT_MAXIMUM_MESSAGE_LENGTH)
  3252. //
  3253. // Define the maximum packet size a driver can allocate.
  3254. //
  3255. #define ERROR_LOG_MAXIMUM_SIZE (IO_ERROR_LOG_MESSAGE_LENGTH - \
  3256. IO_ERROR_LOG_MESSAGE_HEADER_LENGTH)
  3257. #ifdef _WIN64
  3258. #define PORT_MAXIMUM_MESSAGE_LENGTH 512
  3259. #else
  3260. #define PORT_MAXIMUM_MESSAGE_LENGTH 256
  3261. #endif
  3262. //
  3263. // Registry Specific Access Rights.
  3264. //
  3265. #define KEY_QUERY_VALUE (0x0001)
  3266. #define KEY_SET_VALUE (0x0002)
  3267. #define KEY_CREATE_SUB_KEY (0x0004)
  3268. #define KEY_ENUMERATE_SUB_KEYS (0x0008)
  3269. #define KEY_NOTIFY (0x0010)
  3270. #define KEY_CREATE_LINK (0x0020)
  3271. #define KEY_WOW64_32KEY (0x0200)
  3272. #define KEY_WOW64_64KEY (0x0100)
  3273. #define KEY_WOW64_RES (0x0300)
  3274. #define KEY_READ ((STANDARD_RIGHTS_READ |\
  3275. KEY_QUERY_VALUE |\
  3276. KEY_ENUMERATE_SUB_KEYS |\
  3277. KEY_NOTIFY) \
  3278. & \
  3279. (~SYNCHRONIZE))
  3280. #define KEY_WRITE ((STANDARD_RIGHTS_WRITE |\
  3281. KEY_SET_VALUE |\
  3282. KEY_CREATE_SUB_KEY) \
  3283. & \
  3284. (~SYNCHRONIZE))
  3285. #define KEY_EXECUTE ((KEY_READ) \
  3286. & \
  3287. (~SYNCHRONIZE))
  3288. #define KEY_ALL_ACCESS ((STANDARD_RIGHTS_ALL |\
  3289. KEY_QUERY_VALUE |\
  3290. KEY_SET_VALUE |\
  3291. KEY_CREATE_SUB_KEY |\
  3292. KEY_ENUMERATE_SUB_KEYS |\
  3293. KEY_NOTIFY |\
  3294. KEY_CREATE_LINK) \
  3295. & \
  3296. (~SYNCHRONIZE))
  3297. //
  3298. // Open/Create Options
  3299. //
  3300. #define REG_OPTION_RESERVED (0x00000000L) // Parameter is reserved
  3301. #define REG_OPTION_NON_VOLATILE (0x00000000L) // Key is preserved
  3302. // when system is rebooted
  3303. #define REG_OPTION_VOLATILE (0x00000001L) // Key is not preserved
  3304. // when system is rebooted
  3305. #define REG_OPTION_CREATE_LINK (0x00000002L) // Created key is a
  3306. // symbolic link
  3307. #define REG_OPTION_BACKUP_RESTORE (0x00000004L) // open for backup or restore
  3308. // special access rules
  3309. // privilege required
  3310. #define REG_OPTION_OPEN_LINK (0x00000008L) // Open symbolic link
  3311. #define REG_LEGAL_OPTION \
  3312. (REG_OPTION_RESERVED |\
  3313. REG_OPTION_NON_VOLATILE |\
  3314. REG_OPTION_VOLATILE |\
  3315. REG_OPTION_CREATE_LINK |\
  3316. REG_OPTION_BACKUP_RESTORE |\
  3317. REG_OPTION_OPEN_LINK)
  3318. //
  3319. // Key creation/open disposition
  3320. //
  3321. #define REG_CREATED_NEW_KEY (0x00000001L) // New Registry Key created
  3322. #define REG_OPENED_EXISTING_KEY (0x00000002L) // Existing Key opened
  3323. //
  3324. // hive format to be used by Reg(Nt)SaveKeyEx
  3325. //
  3326. #define REG_STANDARD_FORMAT 1
  3327. #define REG_LATEST_FORMAT 2
  3328. #define REG_NO_COMPRESSION 4
  3329. //
  3330. // Key restore flags
  3331. //
  3332. #define REG_WHOLE_HIVE_VOLATILE (0x00000001L) // Restore whole hive volatile
  3333. #define REG_REFRESH_HIVE (0x00000002L) // Unwind changes to last flush
  3334. #define REG_NO_LAZY_FLUSH (0x00000004L) // Never lazy flush this hive
  3335. #define REG_FORCE_RESTORE (0x00000008L) // Force the restore process even when we have open handles on subkeys
  3336. //
  3337. // Unload Flags
  3338. //
  3339. #define REG_FORCE_UNLOAD 1
  3340. //
  3341. // Key query structures
  3342. //
  3343. typedef struct _KEY_BASIC_INFORMATION {
  3344. LARGE_INTEGER LastWriteTime;
  3345. ULONG TitleIndex;
  3346. ULONG NameLength;
  3347. WCHAR Name[1]; // Variable length string
  3348. } KEY_BASIC_INFORMATION, *PKEY_BASIC_INFORMATION;
  3349. typedef struct _KEY_NODE_INFORMATION {
  3350. LARGE_INTEGER LastWriteTime;
  3351. ULONG TitleIndex;
  3352. ULONG ClassOffset;
  3353. ULONG ClassLength;
  3354. ULONG NameLength;
  3355. WCHAR Name[1]; // Variable length string
  3356. // Class[1]; // Variable length string not declared
  3357. } KEY_NODE_INFORMATION, *PKEY_NODE_INFORMATION;
  3358. typedef struct _KEY_FULL_INFORMATION {
  3359. LARGE_INTEGER LastWriteTime;
  3360. ULONG TitleIndex;
  3361. ULONG ClassOffset;
  3362. ULONG ClassLength;
  3363. ULONG SubKeys;
  3364. ULONG MaxNameLen;
  3365. ULONG MaxClassLen;
  3366. ULONG Values;
  3367. ULONG MaxValueNameLen;
  3368. ULONG MaxValueDataLen;
  3369. WCHAR Class[1]; // Variable length
  3370. } KEY_FULL_INFORMATION, *PKEY_FULL_INFORMATION;
  3371. typedef enum _KEY_INFORMATION_CLASS {
  3372. KeyBasicInformation,
  3373. KeyNodeInformation,
  3374. KeyFullInformation
  3375. } KEY_INFORMATION_CLASS;
  3376. typedef struct _KEY_WRITE_TIME_INFORMATION {
  3377. LARGE_INTEGER LastWriteTime;
  3378. } KEY_WRITE_TIME_INFORMATION, *PKEY_WRITE_TIME_INFORMATION;
  3379. typedef struct _KEY_USER_FLAGS_INFORMATION {
  3380. ULONG UserFlags;
  3381. } KEY_USER_FLAGS_INFORMATION, *PKEY_USER_FLAGS_INFORMATION;
  3382. typedef enum _KEY_SET_INFORMATION_CLASS {
  3383. KeyWriteTimeInformation,
  3384. KeyUserFlagsInformation,
  3385. MaxKeySetInfoClass // MaxKeySetInfoClass should always be the last enum
  3386. } KEY_SET_INFORMATION_CLASS;
  3387. //
  3388. // Value entry query structures
  3389. //
  3390. typedef struct _KEY_VALUE_BASIC_INFORMATION {
  3391. ULONG TitleIndex;
  3392. ULONG Type;
  3393. ULONG NameLength;
  3394. WCHAR Name[1]; // Variable size
  3395. } KEY_VALUE_BASIC_INFORMATION, *PKEY_VALUE_BASIC_INFORMATION;
  3396. typedef struct _KEY_VALUE_FULL_INFORMATION {
  3397. ULONG TitleIndex;
  3398. ULONG Type;
  3399. ULONG DataOffset;
  3400. ULONG DataLength;
  3401. ULONG NameLength;
  3402. WCHAR Name[1]; // Variable size
  3403. // Data[1]; // Variable size data not declared
  3404. } KEY_VALUE_FULL_INFORMATION, *PKEY_VALUE_FULL_INFORMATION;
  3405. typedef struct _KEY_VALUE_PARTIAL_INFORMATION {
  3406. ULONG TitleIndex;
  3407. ULONG Type;
  3408. ULONG DataLength;
  3409. UCHAR Data[1]; // Variable size
  3410. } KEY_VALUE_PARTIAL_INFORMATION, *PKEY_VALUE_PARTIAL_INFORMATION;
  3411. typedef struct _KEY_VALUE_PARTIAL_INFORMATION_ALIGN64 {
  3412. ULONG Type;
  3413. ULONG DataLength;
  3414. UCHAR Data[1]; // Variable size
  3415. } KEY_VALUE_PARTIAL_INFORMATION_ALIGN64, *PKEY_VALUE_PARTIAL_INFORMATION_ALIGN64;
  3416. typedef struct _KEY_VALUE_ENTRY {
  3417. PUNICODE_STRING ValueName;
  3418. ULONG DataLength;
  3419. ULONG DataOffset;
  3420. ULONG Type;
  3421. } KEY_VALUE_ENTRY, *PKEY_VALUE_ENTRY;
  3422. typedef enum _KEY_VALUE_INFORMATION_CLASS {
  3423. KeyValueBasicInformation,
  3424. KeyValueFullInformation,
  3425. KeyValuePartialInformation,
  3426. KeyValueFullInformationAlign64,
  3427. KeyValuePartialInformationAlign64,
  3428. MaxKeyValueInfoClass // MaxKeyValueInfoClass should always be the last enum
  3429. } KEY_VALUE_INFORMATION_CLASS;
  3430. #define OBJ_NAME_PATH_SEPARATOR ((WCHAR)L'\\')
  3431. //
  3432. // Object Manager Object Type Specific Access Rights.
  3433. //
  3434. #define OBJECT_TYPE_CREATE (0x0001)
  3435. #define OBJECT_TYPE_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | 0x1)
  3436. //
  3437. // Object Manager Directory Specific Access Rights.
  3438. //
  3439. #define DIRECTORY_QUERY (0x0001)
  3440. #define DIRECTORY_TRAVERSE (0x0002)
  3441. #define DIRECTORY_CREATE_OBJECT (0x0004)
  3442. #define DIRECTORY_CREATE_SUBDIRECTORY (0x0008)
  3443. #define DIRECTORY_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | 0xF)
  3444. //
  3445. // Object Manager Symbolic Link Specific Access Rights.
  3446. //
  3447. #define SYMBOLIC_LINK_QUERY (0x0001)
  3448. #define SYMBOLIC_LINK_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | 0x1)
  3449. typedef struct _OBJECT_NAME_INFORMATION {
  3450. UNICODE_STRING Name;
  3451. } OBJECT_NAME_INFORMATION, *POBJECT_NAME_INFORMATION;
  3452. #define DUPLICATE_CLOSE_SOURCE 0x00000001
  3453. #define DUPLICATE_SAME_ACCESS 0x00000002
  3454. #define DUPLICATE_SAME_ATTRIBUTES 0x00000004
  3455. //
  3456. // Section Information Structures.
  3457. //
  3458. typedef enum _SECTION_INHERIT {
  3459. ViewShare = 1,
  3460. ViewUnmap = 2
  3461. } SECTION_INHERIT;
  3462. //
  3463. // Section Access Rights.
  3464. //
  3465. #define SECTION_QUERY 0x0001
  3466. #define SECTION_MAP_WRITE 0x0002
  3467. #define SECTION_MAP_READ 0x0004
  3468. #define SECTION_MAP_EXECUTE 0x0008
  3469. #define SECTION_EXTEND_SIZE 0x0010
  3470. #define SECTION_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED|SECTION_QUERY|\
  3471. SECTION_MAP_WRITE | \
  3472. SECTION_MAP_READ | \
  3473. SECTION_MAP_EXECUTE | \
  3474. SECTION_EXTEND_SIZE)
  3475. #define SEGMENT_ALL_ACCESS SECTION_ALL_ACCESS
  3476. #define PAGE_NOACCESS 0x01
  3477. #define PAGE_READONLY 0x02
  3478. #define PAGE_READWRITE 0x04
  3479. #define PAGE_WRITECOPY 0x08
  3480. #define PAGE_EXECUTE 0x10
  3481. #define PAGE_EXECUTE_READ 0x20
  3482. #define PAGE_EXECUTE_READWRITE 0x40
  3483. #define PAGE_EXECUTE_WRITECOPY 0x80
  3484. #define PAGE_GUARD 0x100
  3485. #define PAGE_NOCACHE 0x200
  3486. #define PAGE_WRITECOMBINE 0x400
  3487. #define MEM_COMMIT 0x1000
  3488. #define MEM_RESERVE 0x2000
  3489. #define MEM_DECOMMIT 0x4000
  3490. #define MEM_RELEASE 0x8000
  3491. #define MEM_FREE 0x10000
  3492. #define MEM_PRIVATE 0x20000
  3493. #define MEM_MAPPED 0x40000
  3494. #define MEM_RESET 0x80000
  3495. #define MEM_TOP_DOWN 0x100000
  3496. #define MEM_LARGE_PAGES 0x20000000
  3497. #define MEM_4MB_PAGES 0x80000000
  3498. #define SEC_RESERVE 0x4000000
  3499. #define PROCESS_DUP_HANDLE (0x0040)
  3500. #define PROCESS_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | \
  3501. 0xFFF)
  3502. #if defined(_WIN64)
  3503. #define MAXIMUM_PROCESSORS 64
  3504. #else
  3505. #define MAXIMUM_PROCESSORS 32
  3506. #endif
  3507. //
  3508. // Thread Specific Access Rights
  3509. //
  3510. #define THREAD_TERMINATE (0x0001)
  3511. #define THREAD_SET_INFORMATION (0x0020)
  3512. #define THREAD_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | \
  3513. 0x3FF)
  3514. //
  3515. // ClientId
  3516. //
  3517. typedef struct _CLIENT_ID {
  3518. HANDLE UniqueProcess;
  3519. HANDLE UniqueThread;
  3520. } CLIENT_ID;
  3521. typedef CLIENT_ID *PCLIENT_ID;
  3522. #define NtCurrentProcess() ( (HANDLE)(LONG_PTR) -1 )
  3523. #define ZwCurrentProcess() NtCurrentProcess()
  3524. #define NtCurrentThread() ( (HANDLE)(LONG_PTR) -2 )
  3525. #define ZwCurrentThread() NtCurrentThread()
  3526. #ifndef _PO_DDK_
  3527. #define _PO_DDK_
  3528. typedef enum _SYSTEM_POWER_STATE {
  3529. PowerSystemUnspecified = 0,
  3530. PowerSystemWorking = 1,
  3531. PowerSystemSleeping1 = 2,
  3532. PowerSystemSleeping2 = 3,
  3533. PowerSystemSleeping3 = 4,
  3534. PowerSystemHibernate = 5,
  3535. PowerSystemShutdown = 6,
  3536. PowerSystemMaximum = 7
  3537. } SYSTEM_POWER_STATE, *PSYSTEM_POWER_STATE;
  3538. #define POWER_SYSTEM_MAXIMUM 7
  3539. typedef enum {
  3540. PowerActionNone = 0,
  3541. PowerActionReserved,
  3542. PowerActionSleep,
  3543. PowerActionHibernate,
  3544. PowerActionShutdown,
  3545. PowerActionShutdownReset,
  3546. PowerActionShutdownOff,
  3547. PowerActionWarmEject
  3548. } POWER_ACTION, *PPOWER_ACTION;
  3549. typedef enum _DEVICE_POWER_STATE {
  3550. PowerDeviceUnspecified = 0,
  3551. PowerDeviceD0,
  3552. PowerDeviceD1,
  3553. PowerDeviceD2,
  3554. PowerDeviceD3,
  3555. PowerDeviceMaximum
  3556. } DEVICE_POWER_STATE, *PDEVICE_POWER_STATE;
  3557. typedef union _POWER_STATE {
  3558. SYSTEM_POWER_STATE SystemState;
  3559. DEVICE_POWER_STATE DeviceState;
  3560. } POWER_STATE, *PPOWER_STATE;
  3561. typedef enum _POWER_STATE_TYPE {
  3562. SystemPowerState = 0,
  3563. DevicePowerState
  3564. } POWER_STATE_TYPE, *PPOWER_STATE_TYPE;
  3565. //
  3566. // Generic power related IOCTLs
  3567. //
  3568. #define IOCTL_QUERY_DEVICE_POWER_STATE \
  3569. CTL_CODE(FILE_DEVICE_BATTERY, 0x0, METHOD_BUFFERED, FILE_READ_ACCESS)
  3570. #define IOCTL_SET_DEVICE_WAKE \
  3571. CTL_CODE(FILE_DEVICE_BATTERY, 0x1, METHOD_BUFFERED, FILE_WRITE_ACCESS)
  3572. #define IOCTL_CANCEL_DEVICE_WAKE \
  3573. CTL_CODE(FILE_DEVICE_BATTERY, 0x2, METHOD_BUFFERED, FILE_WRITE_ACCESS)
  3574. //
  3575. // Defines for W32 interfaces
  3576. //
  3577. #define ES_SYSTEM_REQUIRED ((ULONG)0x00000001)
  3578. #define ES_DISPLAY_REQUIRED ((ULONG)0x00000002)
  3579. #define ES_USER_PRESENT ((ULONG)0x00000004)
  3580. #define ES_CONTINUOUS ((ULONG)0x80000000)
  3581. typedef ULONG EXECUTION_STATE;
  3582. typedef enum {
  3583. LT_DONT_CARE,
  3584. LT_LOWEST_LATENCY
  3585. } LATENCY_TIME;
  3586. //
  3587. // System power manager capabilities
  3588. //
  3589. typedef struct {
  3590. ULONG Granularity;
  3591. ULONG Capacity;
  3592. } BATTERY_REPORTING_SCALE, *PBATTERY_REPORTING_SCALE;
  3593. #endif // !_PO_DDK_
  3594. #if defined(_X86_)
  3595. //
  3596. // Types to use to contain PFNs and their counts.
  3597. //
  3598. typedef ULONG PFN_COUNT;
  3599. typedef LONG SPFN_NUMBER, *PSPFN_NUMBER;
  3600. typedef ULONG PFN_NUMBER, *PPFN_NUMBER;
  3601. //
  3602. // Define maximum size of flush multiple TB request.
  3603. //
  3604. #define FLUSH_MULTIPLE_MAXIMUM 32
  3605. //
  3606. // Indicate that the i386 compiler supports the pragma textout construct.
  3607. //
  3608. #define ALLOC_PRAGMA 1
  3609. //
  3610. // Indicate that the i386 compiler supports the DATA_SEG("INIT") and
  3611. // DATA_SEG("PAGE") pragmas
  3612. //
  3613. #define ALLOC_DATA_PRAGMA 1
  3614. #define NORMAL_DISPATCH_LENGTH 106
  3615. #define DISPATCH_LENGTH NORMAL_DISPATCH_LENGTH
  3616. //
  3617. // Interrupt Request Level definitions
  3618. //
  3619. #define PASSIVE_LEVEL 0 // Passive release level
  3620. #define LOW_LEVEL 0 // Lowest interrupt level
  3621. #define APC_LEVEL 1 // APC interrupt level
  3622. #define DISPATCH_LEVEL 2 // Dispatcher level
  3623. #define PROFILE_LEVEL 27 // timer used for profiling.
  3624. #define CLOCK1_LEVEL 28 // Interval clock 1 level - Not used on x86
  3625. #define CLOCK2_LEVEL 28 // Interval clock 2 level
  3626. #define IPI_LEVEL 29 // Interprocessor interrupt level
  3627. #define POWER_LEVEL 30 // Power failure level
  3628. #define HIGH_LEVEL 31 // Highest interrupt level
  3629. #define SYNCH_LEVEL (IPI_LEVEL-2)
  3630. //
  3631. // I/O space read and write macros.
  3632. //
  3633. // These have to be actual functions on the 386, because we need
  3634. // to use assembler, but cannot return a value if we inline it.
  3635. //
  3636. // The READ/WRITE_REGISTER_* calls manipulate I/O registers in MEMORY space.
  3637. // (Use x86 move instructions, with LOCK prefix to force correct behavior
  3638. // w.r.t. caches and write buffers.)
  3639. //
  3640. // The READ/WRITE_PORT_* calls manipulate I/O registers in PORT space.
  3641. // (Use x86 in/out instructions.)
  3642. //
  3643. NTKERNELAPI
  3644. UCHAR
  3645. NTAPI
  3646. READ_REGISTER_UCHAR(
  3647. PUCHAR Register
  3648. );
  3649. NTKERNELAPI
  3650. USHORT
  3651. NTAPI
  3652. READ_REGISTER_USHORT(
  3653. PUSHORT Register
  3654. );
  3655. NTKERNELAPI
  3656. ULONG
  3657. NTAPI
  3658. READ_REGISTER_ULONG(
  3659. PULONG Register
  3660. );
  3661. NTKERNELAPI
  3662. VOID
  3663. NTAPI
  3664. READ_REGISTER_BUFFER_UCHAR(
  3665. PUCHAR Register,
  3666. PUCHAR Buffer,
  3667. ULONG Count
  3668. );
  3669. NTKERNELAPI
  3670. VOID
  3671. NTAPI
  3672. READ_REGISTER_BUFFER_USHORT(
  3673. PUSHORT Register,
  3674. PUSHORT Buffer,
  3675. ULONG Count
  3676. );
  3677. NTKERNELAPI
  3678. VOID
  3679. NTAPI
  3680. READ_REGISTER_BUFFER_ULONG(
  3681. PULONG Register,
  3682. PULONG Buffer,
  3683. ULONG Count
  3684. );
  3685. NTKERNELAPI
  3686. VOID
  3687. NTAPI
  3688. WRITE_REGISTER_UCHAR(
  3689. PUCHAR Register,
  3690. UCHAR Value
  3691. );
  3692. NTKERNELAPI
  3693. VOID
  3694. NTAPI
  3695. WRITE_REGISTER_USHORT(
  3696. PUSHORT Register,
  3697. USHORT Value
  3698. );
  3699. NTKERNELAPI
  3700. VOID
  3701. NTAPI
  3702. WRITE_REGISTER_ULONG(
  3703. PULONG Register,
  3704. ULONG Value
  3705. );
  3706. NTKERNELAPI
  3707. VOID
  3708. NTAPI
  3709. WRITE_REGISTER_BUFFER_UCHAR(
  3710. PUCHAR Register,
  3711. PUCHAR Buffer,
  3712. ULONG Count
  3713. );
  3714. NTKERNELAPI
  3715. VOID
  3716. NTAPI
  3717. WRITE_REGISTER_BUFFER_USHORT(
  3718. PUSHORT Register,
  3719. PUSHORT Buffer,
  3720. ULONG Count
  3721. );
  3722. NTKERNELAPI
  3723. VOID
  3724. NTAPI
  3725. WRITE_REGISTER_BUFFER_ULONG(
  3726. PULONG Register,
  3727. PULONG Buffer,
  3728. ULONG Count
  3729. );
  3730. NTHALAPI
  3731. UCHAR
  3732. NTAPI
  3733. READ_PORT_UCHAR(
  3734. PUCHAR Port
  3735. );
  3736. NTHALAPI
  3737. USHORT
  3738. NTAPI
  3739. READ_PORT_USHORT(
  3740. PUSHORT Port
  3741. );
  3742. NTHALAPI
  3743. ULONG
  3744. NTAPI
  3745. READ_PORT_ULONG(
  3746. PULONG Port
  3747. );
  3748. NTHALAPI
  3749. VOID
  3750. NTAPI
  3751. READ_PORT_BUFFER_UCHAR(
  3752. PUCHAR Port,
  3753. PUCHAR Buffer,
  3754. ULONG Count
  3755. );
  3756. NTHALAPI
  3757. VOID
  3758. NTAPI
  3759. READ_PORT_BUFFER_USHORT(
  3760. PUSHORT Port,
  3761. PUSHORT Buffer,
  3762. ULONG Count
  3763. );
  3764. NTHALAPI
  3765. VOID
  3766. NTAPI
  3767. READ_PORT_BUFFER_ULONG(
  3768. PULONG Port,
  3769. PULONG Buffer,
  3770. ULONG Count
  3771. );
  3772. NTHALAPI
  3773. VOID
  3774. NTAPI
  3775. WRITE_PORT_UCHAR(
  3776. PUCHAR Port,
  3777. UCHAR Value
  3778. );
  3779. NTHALAPI
  3780. VOID
  3781. NTAPI
  3782. WRITE_PORT_USHORT(
  3783. PUSHORT Port,
  3784. USHORT Value
  3785. );
  3786. NTHALAPI
  3787. VOID
  3788. NTAPI
  3789. WRITE_PORT_ULONG(
  3790. PULONG Port,
  3791. ULONG Value
  3792. );
  3793. NTHALAPI
  3794. VOID
  3795. NTAPI
  3796. WRITE_PORT_BUFFER_UCHAR(
  3797. PUCHAR Port,
  3798. PUCHAR Buffer,
  3799. ULONG Count
  3800. );
  3801. NTHALAPI
  3802. VOID
  3803. NTAPI
  3804. WRITE_PORT_BUFFER_USHORT(
  3805. PUSHORT Port,
  3806. PUSHORT Buffer,
  3807. ULONG Count
  3808. );
  3809. NTHALAPI
  3810. VOID
  3811. NTAPI
  3812. WRITE_PORT_BUFFER_ULONG(
  3813. PULONG Port,
  3814. PULONG Buffer,
  3815. ULONG Count
  3816. );
  3817. //
  3818. // Get data cache fill size.
  3819. //
  3820. #if PRAGMA_DEPRECATED_DDK
  3821. #pragma deprecated(KeGetDcacheFillSize) // Use GetDmaAlignment
  3822. #endif
  3823. #define KeGetDcacheFillSize() 1L
  3824. #define KeFlushIoBuffers(Mdl, ReadOperation, DmaOperation)
  3825. #define ExAcquireSpinLock(Lock, OldIrql) KeAcquireSpinLock((Lock), (OldIrql))
  3826. #define ExReleaseSpinLock(Lock, OldIrql) KeReleaseSpinLock((Lock), (OldIrql))
  3827. #define ExAcquireSpinLockAtDpcLevel(Lock) KeAcquireSpinLockAtDpcLevel(Lock)
  3828. #define ExReleaseSpinLockFromDpcLevel(Lock) KeReleaseSpinLockFromDpcLevel(Lock)
  3829. #define KeQueryTickCount(CurrentCount ) { \
  3830. volatile PKSYSTEM_TIME _TickCount = *((PKSYSTEM_TIME *)(&KeTickCount)); \
  3831. while (TRUE) { \
  3832. (CurrentCount)->HighPart = _TickCount->High1Time; \
  3833. (CurrentCount)->LowPart = _TickCount->LowPart; \
  3834. if ((CurrentCount)->HighPart == _TickCount->High2Time) break; \
  3835. _asm { rep nop } \
  3836. } \
  3837. }
  3838. //
  3839. // The non-volatile 387 state
  3840. //
  3841. typedef struct _KFLOATING_SAVE {
  3842. ULONG DoNotUse1;
  3843. ULONG DoNotUse2;
  3844. ULONG DoNotUse3;
  3845. ULONG DoNotUse4;
  3846. ULONG DoNotUse5;
  3847. ULONG DoNotUse6;
  3848. ULONG DoNotUse7;
  3849. ULONG DoNotUse8;
  3850. } KFLOATING_SAVE, *PKFLOATING_SAVE;
  3851. //
  3852. // i386 Specific portions of mm component
  3853. //
  3854. //
  3855. // Define the page size for the Intel 386 as 4096 (0x1000).
  3856. //
  3857. #define PAGE_SIZE 0x1000
  3858. //
  3859. // Define the number of trailing zeroes in a page aligned virtual address.
  3860. // This is used as the shift count when shifting virtual addresses to
  3861. // virtual page numbers.
  3862. //
  3863. #define PAGE_SHIFT 12L
  3864. #define MmGetProcedureAddress(Address) (Address)
  3865. #define MmLockPagableCodeSection(Address) MmLockPagableDataSection(Address)
  3866. #define KIP0PCRADDRESS 0xffdff000
  3867. #define ExInterlockedAddUlong ExfInterlockedAddUlong
  3868. #define ExInterlockedInsertHeadList ExfInterlockedInsertHeadList
  3869. #define ExInterlockedInsertTailList ExfInterlockedInsertTailList
  3870. #define ExInterlockedRemoveHeadList ExfInterlockedRemoveHeadList
  3871. #define ExInterlockedPopEntryList ExfInterlockedPopEntryList
  3872. #define ExInterlockedPushEntryList ExfInterlockedPushEntryList
  3873. #if !defined(MIDL_PASS)
  3874. NTKERNELAPI
  3875. LONG
  3876. FASTCALL
  3877. InterlockedIncrement(
  3878. IN LONG volatile *Addend
  3879. );
  3880. NTKERNELAPI
  3881. LONG
  3882. FASTCALL
  3883. InterlockedDecrement(
  3884. IN LONG volatile *Addend
  3885. );
  3886. NTKERNELAPI
  3887. LONG
  3888. FASTCALL
  3889. InterlockedExchange(
  3890. IN OUT LONG volatile *Target,
  3891. IN LONG Value
  3892. );
  3893. #define InterlockedExchangePointer(Target, Value) \
  3894. (PVOID)InterlockedExchange((PLONG)(Target), (LONG)(Value))
  3895. LONG
  3896. FASTCALL
  3897. InterlockedExchangeAdd(
  3898. IN OUT LONG volatile *Addend,
  3899. IN LONG Increment
  3900. );
  3901. NTKERNELAPI
  3902. LONG
  3903. FASTCALL
  3904. InterlockedCompareExchange(
  3905. IN OUT LONG volatile *Destination,
  3906. IN LONG ExChange,
  3907. IN LONG Comperand
  3908. );
  3909. #define InterlockedCompareExchangePointer(Destination, ExChange, Comperand) \
  3910. (PVOID)InterlockedCompareExchange((PLONG)Destination, (LONG)ExChange, (LONG)Comperand)
  3911. #define InterlockedCompareExchange64(Destination, ExChange, Comperand) \
  3912. ExfInterlockedCompareExchange64(Destination, &(ExChange), &(Comperand))
  3913. NTKERNELAPI
  3914. LONGLONG
  3915. FASTCALL
  3916. ExfInterlockedCompareExchange64(
  3917. IN OUT LONGLONG volatile *Destination,
  3918. IN PLONGLONG ExChange,
  3919. IN PLONGLONG Comperand
  3920. );
  3921. FORCEINLINE
  3922. LONG
  3923. FASTCALL
  3924. InterlockedExchangeAdd(
  3925. IN OUT LONG volatile *Addend,
  3926. IN LONG Increment
  3927. )
  3928. {
  3929. __asm {
  3930. mov eax, Increment
  3931. mov ecx, Addend
  3932. lock xadd [ecx], eax
  3933. }
  3934. }
  3935. #endif // MIDL_PASS
  3936. #define InterlockedIncrementAcquire InterlockedIncrement
  3937. #define InterlockedIncrementRelease InterlockedIncrement
  3938. #define InterlockedDecrementAcquire InterlockedDecrement
  3939. #define InterlockedDecrementRelease InterlockedDecrement
  3940. #define InterlockedExchangeAcquire64 InterlockedExchange64
  3941. #define InterlockedCompareExchangeAcquire InterlockedCompareExchange
  3942. #define InterlockedCompareExchangeRelease InterlockedCompareExchange
  3943. #define InterlockedCompareExchangeAcquire64 InterlockedCompareExchange64
  3944. #define InterlockedCompareExchangeRelease64 InterlockedCompareExchange64
  3945. #if !defined(MIDL_PASS) && defined(_M_IX86)
  3946. //
  3947. // i386 function definitions
  3948. //
  3949. //
  3950. // Get current IRQL.
  3951. //
  3952. // On x86 this function resides in the HAL
  3953. //
  3954. NTHALAPI
  3955. KIRQL
  3956. NTAPI
  3957. KeGetCurrentIrql();
  3958. #endif // !defined(MIDL_PASS) && defined(_M_IX86)
  3959. //++
  3960. //
  3961. // VOID
  3962. // KeMemoryBarrier (
  3963. // VOID
  3964. // )
  3965. //
  3966. // VOID
  3967. // KeMemoryBarrierWithoutFence (
  3968. // VOID
  3969. // )
  3970. //
  3971. //
  3972. // Routine Description:
  3973. //
  3974. // These functions order memory accesses as seen by other processors.
  3975. //
  3976. // Arguments:
  3977. //
  3978. // None.
  3979. //
  3980. // Return Value:
  3981. //
  3982. // None.
  3983. //
  3984. //--
  3985. #ifdef __cplusplus
  3986. extern "C" {
  3987. #endif
  3988. VOID
  3989. _ReadWriteBarrier(
  3990. VOID
  3991. );
  3992. #ifdef __cplusplus
  3993. }
  3994. #endif
  3995. #pragma intrinsic (_ReadWriteBarrier)
  3996. FORCEINLINE
  3997. VOID
  3998. KeMemoryBarrier (
  3999. VOID
  4000. )
  4001. {
  4002. LONG Barrier;
  4003. __asm {
  4004. xchg Barrier, eax
  4005. }
  4006. }
  4007. #define KeMemoryBarrierWithoutFence() _ReadWriteBarrier()
  4008. NTKERNELAPI
  4009. NTSTATUS
  4010. NTAPI
  4011. KeSaveFloatingPointState (
  4012. OUT PKFLOATING_SAVE FloatSave
  4013. );
  4014. NTKERNELAPI
  4015. NTSTATUS
  4016. NTAPI
  4017. KeRestoreFloatingPointState (
  4018. IN PKFLOATING_SAVE FloatSave
  4019. );
  4020. #endif // defined(_X86_)
  4021. #if defined(_M_AMD64) && !defined(RC_INVOKED) && !defined(MIDL_PASS)
  4022. //
  4023. // Define intrinsic function to do in's and out's.
  4024. //
  4025. #ifdef __cplusplus
  4026. extern "C" {
  4027. #endif
  4028. UCHAR
  4029. __inbyte (
  4030. IN USHORT Port
  4031. );
  4032. USHORT
  4033. __inword (
  4034. IN USHORT Port
  4035. );
  4036. ULONG
  4037. __indword (
  4038. IN USHORT Port
  4039. );
  4040. VOID
  4041. __outbyte (
  4042. IN USHORT Port,
  4043. IN UCHAR Data
  4044. );
  4045. VOID
  4046. __outword (
  4047. IN USHORT Port,
  4048. IN USHORT Data
  4049. );
  4050. VOID
  4051. __outdword (
  4052. IN USHORT Port,
  4053. IN ULONG Data
  4054. );
  4055. VOID
  4056. __inbytestring (
  4057. IN USHORT Port,
  4058. IN PUCHAR Buffer,
  4059. IN ULONG Count
  4060. );
  4061. VOID
  4062. __inwordstring (
  4063. IN USHORT Port,
  4064. IN PUSHORT Buffer,
  4065. IN ULONG Count
  4066. );
  4067. VOID
  4068. __indwordstring (
  4069. IN USHORT Port,
  4070. IN PULONG Buffer,
  4071. IN ULONG Count
  4072. );
  4073. VOID
  4074. __outbytestring (
  4075. IN USHORT Port,
  4076. IN PUCHAR Buffer,
  4077. IN ULONG Count
  4078. );
  4079. VOID
  4080. __outwordstring (
  4081. IN USHORT Port,
  4082. IN PUSHORT Buffer,
  4083. IN ULONG Count
  4084. );
  4085. VOID
  4086. __outdwordstring (
  4087. IN USHORT Port,
  4088. IN PULONG Buffer,
  4089. IN ULONG Count
  4090. );
  4091. #ifdef __cplusplus
  4092. }
  4093. #endif
  4094. #pragma intrinsic(__inbyte)
  4095. #pragma intrinsic(__inword)
  4096. #pragma intrinsic(__indword)
  4097. #pragma intrinsic(__outbyte)
  4098. #pragma intrinsic(__outword)
  4099. #pragma intrinsic(__outdword)
  4100. #pragma intrinsic(__inbytestring)
  4101. #pragma intrinsic(__inwordstring)
  4102. #pragma intrinsic(__indwordstring)
  4103. #pragma intrinsic(__outbytestring)
  4104. #pragma intrinsic(__outwordstring)
  4105. #pragma intrinsic(__outdwordstring)
  4106. //
  4107. // Interlocked intrinsic functions.
  4108. //
  4109. #define InterlockedAnd _InterlockedAnd
  4110. #define InterlockedOr _InterlockedOr
  4111. #define InterlockedXor _InterlockedXor
  4112. #define InterlockedIncrement _InterlockedIncrement
  4113. #define InterlockedIncrementAcquire InterlockedIncrement
  4114. #define InterlockedIncrementRelease InterlockedIncrement
  4115. #define InterlockedDecrement _InterlockedDecrement
  4116. #define InterlockedDecrementAcquire InterlockedDecrement
  4117. #define InterlockedDecrementRelease InterlockedDecrement
  4118. #define InterlockedAdd _InterlockedAdd
  4119. #define InterlockedExchange _InterlockedExchange
  4120. #define InterlockedExchangeAdd _InterlockedExchangeAdd
  4121. #define InterlockedCompareExchange _InterlockedCompareExchange
  4122. #define InterlockedCompareExchangeAcquire InterlockedCompareExchange
  4123. #define InterlockedCompareExchangeRelease InterlockedCompareExchange
  4124. #define InterlockedAnd64 _InterlockedAnd64
  4125. #define InterlockedOr64 _InterlockedOr64
  4126. #define InterlockedXor64 _InterlockedXor64
  4127. #define InterlockedIncrement64 _InterlockedIncrement64
  4128. #define InterlockedDecrement64 _InterlockedDecrement64
  4129. #define InterlockedAdd64 _InterlockedAdd64
  4130. #define InterlockedExchange64 _InterlockedExchange64
  4131. #define InterlockedExchangeAcquire64 InterlockedExchange64
  4132. #define InterlockedExchangeAdd64 _InterlockedExchangeAdd64
  4133. #define InterlockedCompareExchange64 _InterlockedCompareExchange64
  4134. #define InterlockedCompareExchangeAcquire64 InterlockedCompareExchange64
  4135. #define InterlockedCompareExchangeRelease64 InterlockedCompareExchange64
  4136. #define InterlockedExchangePointer _InterlockedExchangePointer
  4137. #define InterlockedCompareExchangePointer _InterlockedCompareExchangePointer
  4138. #ifdef __cplusplus
  4139. extern "C" {
  4140. #endif
  4141. LONG
  4142. InterlockedAnd (
  4143. IN OUT LONG volatile *Destination,
  4144. IN LONG Value
  4145. );
  4146. LONG
  4147. InterlockedOr (
  4148. IN OUT LONG volatile *Destination,
  4149. IN LONG Value
  4150. );
  4151. LONG
  4152. InterlockedXor (
  4153. IN OUT LONG volatile *Destination,
  4154. IN LONG Value
  4155. );
  4156. LONG64
  4157. InterlockedAnd64 (
  4158. IN OUT LONG64 volatile *Destination,
  4159. IN LONG64 Value
  4160. );
  4161. LONG64
  4162. InterlockedOr64 (
  4163. IN OUT LONG64 volatile *Destination,
  4164. IN LONG64 Value
  4165. );
  4166. LONG64
  4167. InterlockedXor64 (
  4168. IN OUT LONG64 volatile *Destination,
  4169. IN LONG64 Value
  4170. );
  4171. LONG
  4172. InterlockedIncrement(
  4173. IN OUT LONG volatile *Addend
  4174. );
  4175. LONG
  4176. InterlockedDecrement(
  4177. IN OUT LONG volatile *Addend
  4178. );
  4179. LONG
  4180. InterlockedExchange(
  4181. IN OUT LONG volatile *Target,
  4182. IN LONG Value
  4183. );
  4184. LONG
  4185. InterlockedExchangeAdd(
  4186. IN OUT LONG volatile *Addend,
  4187. IN LONG Value
  4188. );
  4189. #if !defined(_X86AMD64_)
  4190. __forceinline
  4191. LONG
  4192. InterlockedAdd(
  4193. IN OUT LONG volatile *Addend,
  4194. IN LONG Value
  4195. )
  4196. {
  4197. return InterlockedExchangeAdd(Addend, Value) + Value;
  4198. }
  4199. #endif
  4200. LONG
  4201. InterlockedCompareExchange (
  4202. IN OUT LONG volatile *Destination,
  4203. IN LONG ExChange,
  4204. IN LONG Comperand
  4205. );
  4206. LONG64
  4207. InterlockedIncrement64(
  4208. IN OUT LONG64 volatile *Addend
  4209. );
  4210. LONG64
  4211. InterlockedDecrement64(
  4212. IN OUT LONG64 volatile *Addend
  4213. );
  4214. LONG64
  4215. InterlockedExchange64(
  4216. IN OUT LONG64 volatile *Target,
  4217. IN LONG64 Value
  4218. );
  4219. LONG64
  4220. InterlockedExchangeAdd64(
  4221. IN OUT LONG64 volatile *Addend,
  4222. IN LONG64 Value
  4223. );
  4224. #if !defined(_X86AMD64_)
  4225. __forceinline
  4226. LONG64
  4227. InterlockedAdd64(
  4228. IN OUT LONG64 volatile *Addend,
  4229. IN LONG64 Value
  4230. )
  4231. {
  4232. return InterlockedExchangeAdd64(Addend, Value) + Value;
  4233. }
  4234. #endif
  4235. LONG64
  4236. InterlockedCompareExchange64 (
  4237. IN OUT LONG64 volatile *Destination,
  4238. IN LONG64 ExChange,
  4239. IN LONG64 Comperand
  4240. );
  4241. PVOID
  4242. InterlockedCompareExchangePointer (
  4243. IN OUT PVOID volatile *Destination,
  4244. IN PVOID Exchange,
  4245. IN PVOID Comperand
  4246. );
  4247. PVOID
  4248. InterlockedExchangePointer(
  4249. IN OUT PVOID volatile *Target,
  4250. IN PVOID Value
  4251. );
  4252. #pragma intrinsic(_InterlockedAnd)
  4253. #pragma intrinsic(_InterlockedOr)
  4254. #pragma intrinsic(_InterlockedXor)
  4255. #pragma intrinsic(_InterlockedIncrement)
  4256. #pragma intrinsic(_InterlockedDecrement)
  4257. #pragma intrinsic(_InterlockedExchange)
  4258. #pragma intrinsic(_InterlockedExchangeAdd)
  4259. #pragma intrinsic(_InterlockedCompareExchange)
  4260. #pragma intrinsic(_InterlockedAnd64)
  4261. #pragma intrinsic(_InterlockedOr64)
  4262. #pragma intrinsic(_InterlockedXor64)
  4263. #pragma intrinsic(_InterlockedIncrement64)
  4264. #pragma intrinsic(_InterlockedDecrement64)
  4265. #pragma intrinsic(_InterlockedExchange64)
  4266. #pragma intrinsic(_InterlockedExchangeAdd64)
  4267. #pragma intrinsic(_InterlockedCompareExchange64)
  4268. #pragma intrinsic(_InterlockedExchangePointer)
  4269. #pragma intrinsic(_InterlockedCompareExchangePointer)
  4270. #ifdef __cplusplus
  4271. }
  4272. #endif
  4273. #endif // defined(_M_AMD64) && !defined(RC_INVOKED) && !defined(MIDL_PASS)
  4274. #if defined(_AMD64_)
  4275. //
  4276. // Types to use to contain PFNs and their counts.
  4277. //
  4278. typedef ULONG PFN_COUNT;
  4279. typedef LONG64 SPFN_NUMBER, *PSPFN_NUMBER;
  4280. typedef ULONG64 PFN_NUMBER, *PPFN_NUMBER;
  4281. //
  4282. // Define maximum size of flush multiple TB request.
  4283. //
  4284. #define FLUSH_MULTIPLE_MAXIMUM 32
  4285. //
  4286. // Indicate that the AMD64 compiler supports the allocate pragmas.
  4287. //
  4288. #define ALLOC_PRAGMA 1
  4289. #define ALLOC_DATA_PRAGMA 1
  4290. #define NORMAL_DISPATCH_LENGTH 106
  4291. #define DISPATCH_LENGTH NORMAL_DISPATCH_LENGTH
  4292. //
  4293. // Interrupt Request Level definitions
  4294. //
  4295. #define PASSIVE_LEVEL 0 // Passive release level
  4296. #define LOW_LEVEL 0 // Lowest interrupt level
  4297. #define APC_LEVEL 1 // APC interrupt level
  4298. #define DISPATCH_LEVEL 2 // Dispatcher level
  4299. #define CLOCK_LEVEL 13 // Interval clock level
  4300. #define IPI_LEVEL 14 // Interprocessor interrupt level
  4301. #define POWER_LEVEL 14 // Power failure level
  4302. #define PROFILE_LEVEL 15 // timer used for profiling.
  4303. #define HIGH_LEVEL 15 // Highest interrupt level
  4304. #define SYNCH_LEVEL (IPI_LEVEL-2)
  4305. //
  4306. // I/O space read and write macros.
  4307. //
  4308. // The READ/WRITE_REGISTER_* calls manipulate I/O registers in MEMORY space.
  4309. //
  4310. // The READ/WRITE_PORT_* calls manipulate I/O registers in PORT space.
  4311. //
  4312. __forceinline
  4313. UCHAR
  4314. READ_REGISTER_UCHAR (
  4315. volatile UCHAR *Register
  4316. )
  4317. {
  4318. return *Register;
  4319. }
  4320. __forceinline
  4321. USHORT
  4322. READ_REGISTER_USHORT (
  4323. volatile USHORT *Register
  4324. )
  4325. {
  4326. return *Register;
  4327. }
  4328. __forceinline
  4329. ULONG
  4330. READ_REGISTER_ULONG (
  4331. volatile ULONG *Register
  4332. )
  4333. {
  4334. return *Register;
  4335. }
  4336. __forceinline
  4337. VOID
  4338. READ_REGISTER_BUFFER_UCHAR (
  4339. PUCHAR Register,
  4340. PUCHAR Buffer,
  4341. ULONG Count
  4342. )
  4343. {
  4344. __movsb(Buffer, Register, Count);
  4345. return;
  4346. }
  4347. __forceinline
  4348. VOID
  4349. READ_REGISTER_BUFFER_USHORT (
  4350. PUSHORT Register,
  4351. PUSHORT Buffer,
  4352. ULONG Count
  4353. )
  4354. {
  4355. __movsw(Buffer, Register, Count);
  4356. return;
  4357. }
  4358. __forceinline
  4359. VOID
  4360. READ_REGISTER_BUFFER_ULONG (
  4361. PULONG Register,
  4362. PULONG Buffer,
  4363. ULONG Count
  4364. )
  4365. {
  4366. __movsd(Buffer, Register, Count);
  4367. return;
  4368. }
  4369. __forceinline
  4370. VOID
  4371. WRITE_REGISTER_UCHAR (
  4372. PUCHAR Register,
  4373. UCHAR Value
  4374. )
  4375. {
  4376. *Register = Value;
  4377. StoreFence();
  4378. return;
  4379. }
  4380. __forceinline
  4381. VOID
  4382. WRITE_REGISTER_USHORT (
  4383. PUSHORT Register,
  4384. USHORT Value
  4385. )
  4386. {
  4387. *Register = Value;
  4388. StoreFence();
  4389. return;
  4390. }
  4391. __forceinline
  4392. VOID
  4393. WRITE_REGISTER_ULONG (
  4394. PULONG Register,
  4395. ULONG Value
  4396. )
  4397. {
  4398. *Register = Value;
  4399. StoreFence();
  4400. return;
  4401. }
  4402. __forceinline
  4403. VOID
  4404. WRITE_REGISTER_BUFFER_UCHAR (
  4405. PUCHAR Register,
  4406. PUCHAR Buffer,
  4407. ULONG Count
  4408. )
  4409. {
  4410. __movsb(Register, Buffer, Count);
  4411. StoreFence();
  4412. return;
  4413. }
  4414. __forceinline
  4415. VOID
  4416. WRITE_REGISTER_BUFFER_USHORT (
  4417. PUSHORT Register,
  4418. PUSHORT Buffer,
  4419. ULONG Count
  4420. )
  4421. {
  4422. __movsw(Register, Buffer, Count);
  4423. StoreFence();
  4424. return;
  4425. }
  4426. __forceinline
  4427. VOID
  4428. WRITE_REGISTER_BUFFER_ULONG (
  4429. PULONG Register,
  4430. PULONG Buffer,
  4431. ULONG Count
  4432. )
  4433. {
  4434. __movsd(Register, Buffer, Count);
  4435. StoreFence();
  4436. return;
  4437. }
  4438. __forceinline
  4439. UCHAR
  4440. READ_PORT_UCHAR (
  4441. PUCHAR Port
  4442. )
  4443. {
  4444. return __inbyte((USHORT)((ULONG64)Port));
  4445. }
  4446. __forceinline
  4447. USHORT
  4448. READ_PORT_USHORT (
  4449. PUSHORT Port
  4450. )
  4451. {
  4452. return __inword((USHORT)((ULONG64)Port));
  4453. }
  4454. __forceinline
  4455. ULONG
  4456. READ_PORT_ULONG (
  4457. PULONG Port
  4458. )
  4459. {
  4460. return __indword((USHORT)((ULONG64)Port));
  4461. }
  4462. __forceinline
  4463. VOID
  4464. READ_PORT_BUFFER_UCHAR (
  4465. PUCHAR Port,
  4466. PUCHAR Buffer,
  4467. ULONG Count
  4468. )
  4469. {
  4470. __inbytestring((USHORT)((ULONG64)Port), Buffer, Count);
  4471. return;
  4472. }
  4473. __forceinline
  4474. VOID
  4475. READ_PORT_BUFFER_USHORT (
  4476. PUSHORT Port,
  4477. PUSHORT Buffer,
  4478. ULONG Count
  4479. )
  4480. {
  4481. __inwordstring((USHORT)((ULONG64)Port), Buffer, Count);
  4482. return;
  4483. }
  4484. __forceinline
  4485. VOID
  4486. READ_PORT_BUFFER_ULONG (
  4487. PULONG Port,
  4488. PULONG Buffer,
  4489. ULONG Count
  4490. )
  4491. {
  4492. __indwordstring((USHORT)((ULONG64)Port), Buffer, Count);
  4493. return;
  4494. }
  4495. __forceinline
  4496. VOID
  4497. WRITE_PORT_UCHAR (
  4498. PUCHAR Port,
  4499. UCHAR Value
  4500. )
  4501. {
  4502. __outbyte((USHORT)((ULONG64)Port), Value);
  4503. return;
  4504. }
  4505. __forceinline
  4506. VOID
  4507. WRITE_PORT_USHORT (
  4508. PUSHORT Port,
  4509. USHORT Value
  4510. )
  4511. {
  4512. __outword((USHORT)((ULONG64)Port), Value);
  4513. return;
  4514. }
  4515. __forceinline
  4516. VOID
  4517. WRITE_PORT_ULONG (
  4518. PULONG Port,
  4519. ULONG Value
  4520. )
  4521. {
  4522. __outdword((USHORT)((ULONG64)Port), Value);
  4523. return;
  4524. }
  4525. __forceinline
  4526. VOID
  4527. WRITE_PORT_BUFFER_UCHAR (
  4528. PUCHAR Port,
  4529. PUCHAR Buffer,
  4530. ULONG Count
  4531. )
  4532. {
  4533. __outbytestring((USHORT)((ULONG64)Port), Buffer, Count);
  4534. return;
  4535. }
  4536. __forceinline
  4537. VOID
  4538. WRITE_PORT_BUFFER_USHORT (
  4539. PUSHORT Port,
  4540. PUSHORT Buffer,
  4541. ULONG Count
  4542. )
  4543. {
  4544. __outwordstring((USHORT)((ULONG64)Port), Buffer, Count);
  4545. return;
  4546. }
  4547. __forceinline
  4548. VOID
  4549. WRITE_PORT_BUFFER_ULONG (
  4550. PULONG Port,
  4551. PULONG Buffer,
  4552. ULONG Count
  4553. )
  4554. {
  4555. __outdwordstring((USHORT)((ULONG64)Port), Buffer, Count);
  4556. return;
  4557. }
  4558. //
  4559. // Get data cache fill size.
  4560. //
  4561. #if PRAGMA_DEPRECATED_DDK
  4562. #pragma deprecated(KeGetDcacheFillSize) // Use GetDmaAlignment
  4563. #endif
  4564. #define KeGetDcacheFillSize() 1L
  4565. #define KeFlushIoBuffers(Mdl, ReadOperation, DmaOperation)
  4566. #define ExAcquireSpinLock(Lock, OldIrql) KeAcquireSpinLock((Lock), (OldIrql))
  4567. #define ExReleaseSpinLock(Lock, OldIrql) KeReleaseSpinLock((Lock), (OldIrql))
  4568. #define ExAcquireSpinLockAtDpcLevel(Lock) KeAcquireSpinLockAtDpcLevel(Lock)
  4569. #define ExReleaseSpinLockFromDpcLevel(Lock) KeReleaseSpinLockFromDpcLevel(Lock)
  4570. #define KI_USER_SHARED_DATA 0xFFFFF78000000000UI64
  4571. #define SharedUserData ((KUSER_SHARED_DATA * const)KI_USER_SHARED_DATA)
  4572. #define SharedInterruptTime (KI_USER_SHARED_DATA + 0x8)
  4573. #define SharedSystemTime (KI_USER_SHARED_DATA + 0x14)
  4574. #define SharedTickCount (KI_USER_SHARED_DATA + 0x320)
  4575. #define KeQueryInterruptTime() *((volatile ULONG64 *)(SharedInterruptTime))
  4576. #define KeQuerySystemTime(CurrentCount) \
  4577. *((PULONG64)(CurrentCount)) = *((volatile ULONG64 *)(SharedSystemTime))
  4578. #define KeQueryTickCount(CurrentCount) \
  4579. *((PULONG64)(CurrentCount)) = *((volatile ULONG64 *)(SharedTickCount))
  4580. //
  4581. // The nonvolatile floating state
  4582. //
  4583. typedef struct _KFLOATING_SAVE {
  4584. ULONG MxCsr;
  4585. } KFLOATING_SAVE, *PKFLOATING_SAVE;
  4586. //
  4587. // AMD64 Specific portions of mm component.
  4588. //
  4589. // Define the page size for the AMD64 as 4096 (0x1000).
  4590. //
  4591. #define PAGE_SIZE 0x1000
  4592. //
  4593. // Define the number of trailing zeroes in a page aligned virtual address.
  4594. // This is used as the shift count when shifting virtual addresses to
  4595. // virtual page numbers.
  4596. //
  4597. #define PAGE_SHIFT 12L
  4598. #define MmGetProcedureAddress(Address) (Address)
  4599. #define MmLockPagableCodeSection(Address) MmLockPagableDataSection(Address)
  4600. #if defined(_M_AMD64) && !defined(RC_INVOKED) && !defined(MIDL_PASS)
  4601. #endif // defined(_M_AMD64) && !defined(RC_INVOKED) && !defined(MIDL_PASS)
  4602. #if !defined(MIDL_PASS) && defined(_M_AMD64)
  4603. //
  4604. // AMD646 function prototype definitions
  4605. //
  4606. #endif // !defined(MIDL_PASS) && defined(_M_AMD64)
  4607. //++
  4608. //
  4609. //
  4610. // VOID
  4611. // KeMemoryBarrier (
  4612. // VOID
  4613. // )
  4614. //
  4615. // VOID
  4616. // KeMemoryBarrierWithoutFence (
  4617. // VOID
  4618. // )
  4619. //
  4620. //
  4621. // Routine Description:
  4622. //
  4623. // These functions order memory accesses as seen by other processors.
  4624. //
  4625. // Arguments:
  4626. //
  4627. // None.
  4628. //
  4629. // Return Value:
  4630. //
  4631. // None.
  4632. //
  4633. //--
  4634. #if !defined(_CROSS_PLATFORM_)
  4635. #ifdef __cplusplus
  4636. extern "C" {
  4637. #endif
  4638. VOID
  4639. _ReadWriteBarrier (
  4640. VOID
  4641. );
  4642. #pragma intrinsic(_ReadWriteBarrier)
  4643. #ifdef __cplusplus
  4644. }
  4645. #endif
  4646. #define KeMemoryBarrier() _ReadWriteBarrier()
  4647. #define KeMemoryBarrierWithoutFence() _ReadWriteBarrier()
  4648. #else
  4649. #define KeMemoryBarrier()
  4650. #define KeMemoryBarrierWithoutFence()
  4651. #endif
  4652. NTKERNELAPI
  4653. NTSTATUS
  4654. KeSaveFloatingPointState (
  4655. OUT PKFLOATING_SAVE SaveArea
  4656. );
  4657. NTKERNELAPI
  4658. NTSTATUS
  4659. KeRestoreFloatingPointState (
  4660. IN PKFLOATING_SAVE SaveArea
  4661. );
  4662. #endif // defined(_AMD64_)
  4663. #if defined(_AMD64_)
  4664. NTKERNELAPI
  4665. KIRQL
  4666. KeGetCurrentIrql (
  4667. VOID
  4668. );
  4669. NTKERNELAPI
  4670. VOID
  4671. KeLowerIrql (
  4672. IN KIRQL NewIrql
  4673. );
  4674. #define KeRaiseIrql(a,b) *(b) = KfRaiseIrql(a)
  4675. NTKERNELAPI
  4676. KIRQL
  4677. KfRaiseIrql (
  4678. IN KIRQL NewIrql
  4679. );
  4680. #endif // defined(_AMD64_)
  4681. #if defined(_IA64_)
  4682. //
  4683. // Types to use to contain PFNs and their counts.
  4684. //
  4685. typedef ULONG PFN_COUNT;
  4686. typedef LONG_PTR SPFN_NUMBER, *PSPFN_NUMBER;
  4687. typedef ULONG_PTR PFN_NUMBER, *PPFN_NUMBER;
  4688. //
  4689. // Indicate that the IA64 compiler supports the pragma textout construct.
  4690. //
  4691. #define ALLOC_PRAGMA 1
  4692. //
  4693. // Define intrinsic calls and their prototypes
  4694. //
  4695. #include "ia64reg.h"
  4696. #ifdef __cplusplus
  4697. extern "C" {
  4698. #endif
  4699. unsigned __int64 __getReg (int);
  4700. void __setReg (int, unsigned __int64);
  4701. void __isrlz (void);
  4702. void __dsrlz (void);
  4703. void __fwb (void);
  4704. void __mf (void);
  4705. void __mfa (void);
  4706. void __synci (void);
  4707. __int64 __thash (__int64);
  4708. __int64 __ttag (__int64);
  4709. void __ptcl (__int64, __int64);
  4710. void __ptcg (__int64, __int64);
  4711. void __ptcga (__int64, __int64);
  4712. void __ptri (__int64, __int64);
  4713. void __ptrd (__int64, __int64);
  4714. void __invalat (void);
  4715. void __break (int);
  4716. void __fc (__int64);
  4717. void __fci (__int64);
  4718. void __sum (int);
  4719. void __rsm (int);
  4720. void _ReleaseSpinLock( unsigned __int64 *);
  4721. void __yield();
  4722. void __lfetch(int, void const *);
  4723. void __lfetchfault(int, void const *);
  4724. #ifdef _M_IA64
  4725. #pragma intrinsic (__getReg)
  4726. #pragma intrinsic (__setReg)
  4727. #pragma intrinsic (__isrlz)
  4728. #pragma intrinsic (__dsrlz)
  4729. #pragma intrinsic (__fwb)
  4730. #pragma intrinsic (__mf)
  4731. #pragma intrinsic (__mfa)
  4732. #pragma intrinsic (__synci)
  4733. #pragma intrinsic (__thash)
  4734. #pragma intrinsic (__ttag)
  4735. #pragma intrinsic (__ptcl)
  4736. #pragma intrinsic (__ptcg)
  4737. #pragma intrinsic (__ptcga)
  4738. #pragma intrinsic (__ptri)
  4739. #pragma intrinsic (__ptrd)
  4740. #pragma intrinsic (__invalat)
  4741. #pragma intrinsic (__break)
  4742. #pragma intrinsic (__fc)
  4743. #pragma intrinsic (__fci)
  4744. #pragma intrinsic (__sum)
  4745. #pragma intrinsic (__rsm)
  4746. #pragma intrinsic (_ReleaseSpinLock)
  4747. #pragma intrinsic (__yield)
  4748. #pragma intrinsic (__lfetch)
  4749. #pragma intrinsic (__lfetchfault)
  4750. #endif // _M_IA64
  4751. #ifdef __cplusplus
  4752. }
  4753. #endif
  4754. //
  4755. // Define length of interrupt vector table.
  4756. //
  4757. #define MAXIMUM_VECTOR 256
  4758. //
  4759. // IA64 Interrupt Definitions.
  4760. //
  4761. //
  4762. // Define length of interrupt object dispatch code in longwords.
  4763. //
  4764. #define DISPATCH_LENGTH 2*2 // Length of dispatch code template in 32-bit words
  4765. // Begin of a block of definitions that must be synchronized with kxia64.h.
  4766. //
  4767. //
  4768. // Define Interrupt Request Levels.
  4769. //
  4770. #define PASSIVE_LEVEL 0 // Passive release level
  4771. #define LOW_LEVEL 0 // Lowest interrupt level
  4772. #define APC_LEVEL 1 // APC interrupt level
  4773. #define DISPATCH_LEVEL 2 // Dispatcher level
  4774. #define CMC_LEVEL 3 // Correctable machine check level
  4775. #define DEVICE_LEVEL_BASE 4 // 4 - 11 - Device IRQLs
  4776. #define PC_LEVEL 12 // Performance Counter IRQL
  4777. #define IPI_LEVEL 14 // IPI IRQL
  4778. #define CLOCK_LEVEL 13 // Clock Timer IRQL
  4779. #define POWER_LEVEL 15 // Power failure level
  4780. #define PROFILE_LEVEL 15 // Profiling level
  4781. #define HIGH_LEVEL 15 // Highest interrupt level
  4782. #if defined(_M_IA64) && !defined(RC_INVOKED)
  4783. #define InterlockedAdd _InterlockedAdd
  4784. #define InterlockedIncrement _InterlockedIncrement
  4785. #define InterlockedIncrementAcquire _InterlockedIncrement_acq
  4786. #define InterlockedIncrementRelease _InterlockedIncrement_rel
  4787. #define InterlockedDecrement _InterlockedDecrement
  4788. #define InterlockedDecrementAcquire _InterlockedDecrement_acq
  4789. #define InterlockedDecrementRelease _InterlockedDecrement_rel
  4790. #define InterlockedExchange _InterlockedExchange
  4791. #define InterlockedExchangeAdd _InterlockedExchangeAdd
  4792. #define InterlockedAdd64 _InterlockedAdd64
  4793. #define InterlockedIncrement64 _InterlockedIncrement64
  4794. #define InterlockedDecrement64 _InterlockedDecrement64
  4795. #define InterlockedExchange64 _InterlockedExchange64
  4796. #define InterlockedExchangeAcquire64 _InterlockedExchange64_acq
  4797. #define InterlockedExchangeAdd64 _InterlockedExchangeAdd64
  4798. #define InterlockedCompareExchange64 _InterlockedCompareExchange64
  4799. #define InterlockedCompareExchangeAcquire64 _InterlockedCompareExchange64_acq
  4800. #define InterlockedCompareExchangeRelease64 _InterlockedCompareExchange64_rel
  4801. #define InterlockedCompareExchange _InterlockedCompareExchange
  4802. #define InterlockedCompareExchangeAcquire _InterlockedCompareExchange_acq
  4803. #define InterlockedCompareExchangeRelease _InterlockedCompareExchange_rel
  4804. #define InterlockedExchangePointer _InterlockedExchangePointer
  4805. #define InterlockedCompareExchangePointer _InterlockedCompareExchangePointer
  4806. #ifdef __cplusplus
  4807. extern "C" {
  4808. #endif
  4809. LONG
  4810. __cdecl
  4811. InterlockedAdd (
  4812. LONG volatile *Addend,
  4813. LONG Value
  4814. );
  4815. LONGLONG
  4816. __cdecl
  4817. InterlockedAdd64 (
  4818. LONGLONG volatile *Addend,
  4819. LONGLONG Value
  4820. );
  4821. LONG
  4822. __cdecl
  4823. InterlockedIncrement(
  4824. IN OUT LONG volatile *Addend
  4825. );
  4826. LONG
  4827. __cdecl
  4828. InterlockedDecrement(
  4829. IN OUT LONG volatile *Addend
  4830. );
  4831. LONG
  4832. __cdecl
  4833. InterlockedIncrementAcquire(
  4834. IN OUT LONG volatile *Addend
  4835. );
  4836. LONG
  4837. __cdecl
  4838. InterlockedDecrementAcquire(
  4839. IN OUT LONG volatile *Addend
  4840. );
  4841. LONG
  4842. __cdecl
  4843. InterlockedIncrementRelease(
  4844. IN OUT LONG volatile *Addend
  4845. );
  4846. LONG
  4847. __cdecl
  4848. InterlockedDecrementRelease(
  4849. IN OUT LONG volatile *Addend
  4850. );
  4851. LONG
  4852. __cdecl
  4853. InterlockedExchange(
  4854. IN OUT LONG volatile *Target,
  4855. IN LONG Value
  4856. );
  4857. LONG
  4858. __cdecl
  4859. InterlockedExchangeAdd(
  4860. IN OUT LONG volatile *Addend,
  4861. IN LONG Value
  4862. );
  4863. LONG
  4864. __cdecl
  4865. InterlockedCompareExchange (
  4866. IN OUT LONG volatile *Destination,
  4867. IN LONG ExChange,
  4868. IN LONG Comperand
  4869. );
  4870. LONG
  4871. __cdecl
  4872. InterlockedCompareExchangeRelease (
  4873. IN OUT LONG volatile *Destination,
  4874. IN LONG ExChange,
  4875. IN LONG Comperand
  4876. );
  4877. LONG
  4878. __cdecl
  4879. InterlockedCompareExchangeAcquire (
  4880. IN OUT LONG volatile *Destination,
  4881. IN LONG ExChange,
  4882. IN LONG Comperand
  4883. );
  4884. LONGLONG
  4885. __cdecl
  4886. InterlockedIncrement64(
  4887. IN OUT LONGLONG volatile *Addend
  4888. );
  4889. LONGLONG
  4890. __cdecl
  4891. InterlockedDecrement64(
  4892. IN OUT LONGLONG volatile *Addend
  4893. );
  4894. LONGLONG
  4895. __cdecl
  4896. InterlockedExchange64(
  4897. IN OUT LONGLONG volatile *Target,
  4898. IN LONGLONG Value
  4899. );
  4900. LONGLONG
  4901. __cdecl
  4902. InterlockedExchangeAcquire64(
  4903. IN OUT LONGLONG volatile *Target,
  4904. IN LONGLONG Value
  4905. );
  4906. LONGLONG
  4907. __cdecl
  4908. InterlockedExchangeAdd64(
  4909. IN OUT LONGLONG volatile *Addend,
  4910. IN LONGLONG Value
  4911. );
  4912. LONGLONG
  4913. __cdecl
  4914. InterlockedCompareExchange64 (
  4915. IN OUT LONGLONG volatile *Destination,
  4916. IN LONGLONG ExChange,
  4917. IN LONGLONG Comperand
  4918. );
  4919. LONGLONG
  4920. __cdecl
  4921. InterlockedCompareExchangeAcquire64 (
  4922. IN OUT LONGLONG volatile *Destination,
  4923. IN LONGLONG ExChange,
  4924. IN LONGLONG Comperand
  4925. );
  4926. LONGLONG
  4927. __cdecl
  4928. InterlockedCompareExchangeRelease64 (
  4929. IN OUT LONGLONG volatile *Destination,
  4930. IN LONGLONG ExChange,
  4931. IN LONGLONG Comperand
  4932. );
  4933. PVOID
  4934. __cdecl
  4935. InterlockedCompareExchangePointer (
  4936. IN OUT PVOID volatile *Destination,
  4937. IN PVOID Exchange,
  4938. IN PVOID Comperand
  4939. );
  4940. PVOID
  4941. __cdecl
  4942. InterlockedExchangePointer(
  4943. IN OUT PVOID volatile *Target,
  4944. IN PVOID Value
  4945. );
  4946. #if !defined (InterlockedAnd64)
  4947. #define InterlockedAnd64 InterlockedAnd64_Inline
  4948. LONGLONG
  4949. FORCEINLINE
  4950. InterlockedAnd64_Inline (
  4951. IN OUT LONGLONG volatile *Destination,
  4952. IN LONGLONG Value
  4953. )
  4954. {
  4955. LONGLONG Old;
  4956. do {
  4957. Old = *Destination;
  4958. } while (InterlockedCompareExchange64(Destination,
  4959. Old & Value,
  4960. Old) != Old);
  4961. return Old;
  4962. }
  4963. #endif
  4964. #if !defined (InterlockedOr64)
  4965. #define InterlockedOr64 InterlockedOr64_Inline
  4966. LONGLONG
  4967. FORCEINLINE
  4968. InterlockedOr64_Inline (
  4969. IN OUT LONGLONG volatile *Destination,
  4970. IN LONGLONG Value
  4971. )
  4972. {
  4973. LONGLONG Old;
  4974. do {
  4975. Old = *Destination;
  4976. } while (InterlockedCompareExchange64(Destination,
  4977. Old | Value,
  4978. Old) != Old);
  4979. return Old;
  4980. }
  4981. #endif
  4982. #if !defined (InterlockedXor64)
  4983. #define InterlockedXor64 InterlockedXor64_Inline
  4984. LONGLONG
  4985. FORCEINLINE
  4986. InterlockedXor64_Inline (
  4987. IN OUT LONGLONG volatile *Destination,
  4988. IN LONGLONG Value
  4989. )
  4990. {
  4991. LONGLONG Old;
  4992. do {
  4993. Old = *Destination;
  4994. } while (InterlockedCompareExchange64(Destination,
  4995. Old ^ Value,
  4996. Old) != Old);
  4997. return Old;
  4998. }
  4999. #endif
  5000. #pragma intrinsic(_InterlockedAdd)
  5001. #pragma intrinsic(_InterlockedIncrement)
  5002. #pragma intrinsic(_InterlockedIncrement_acq)
  5003. #pragma intrinsic(_InterlockedIncrement_rel)
  5004. #pragma intrinsic(_InterlockedDecrement)
  5005. #pragma intrinsic(_InterlockedDecrement_acq)
  5006. #pragma intrinsic(_InterlockedDecrement_rel)
  5007. #pragma intrinsic(_InterlockedExchange)
  5008. #pragma intrinsic(_InterlockedCompareExchange)
  5009. #pragma intrinsic(_InterlockedCompareExchange_acq)
  5010. #pragma intrinsic(_InterlockedCompareExchange_rel)
  5011. #pragma intrinsic(_InterlockedExchangeAdd)
  5012. #pragma intrinsic(_InterlockedAdd64)
  5013. #pragma intrinsic(_InterlockedIncrement64)
  5014. #pragma intrinsic(_InterlockedDecrement64)
  5015. #pragma intrinsic(_InterlockedExchange64)
  5016. #pragma intrinsic(_InterlockedExchange64_acq)
  5017. #pragma intrinsic(_InterlockedCompareExchange64)
  5018. #pragma intrinsic(_InterlockedCompareExchange64_acq)
  5019. #pragma intrinsic(_InterlockedCompareExchange64_rel)
  5020. #pragma intrinsic(_InterlockedExchangeAdd64)
  5021. #pragma intrinsic(_InterlockedExchangePointer)
  5022. #pragma intrinsic(_InterlockedCompareExchangePointer)
  5023. #ifdef __cplusplus
  5024. }
  5025. #endif
  5026. #endif // defined(_M_IA64) && !defined(RC_INVOKED)
  5027. #define KI_USER_SHARED_DATA ((ULONG_PTR)(KADDRESS_BASE + 0xFFFE0000))
  5028. #define SharedUserData ((KUSER_SHARED_DATA * const)KI_USER_SHARED_DATA)
  5029. #define KeSaveFloatingPointState(a) STATUS_SUCCESS
  5030. #define KeRestoreFloatingPointState(a) STATUS_SUCCESS
  5031. //
  5032. //
  5033. // VOID
  5034. // KeMemoryBarrierWithoutFence (
  5035. // VOID
  5036. // )
  5037. //
  5038. //
  5039. // Routine Description:
  5040. //
  5041. // This function cases ordering of memory acceses generated by the compiler.
  5042. //
  5043. //
  5044. // Arguments:
  5045. //
  5046. // None.
  5047. //
  5048. // Return Value:
  5049. //
  5050. // None.
  5051. //--
  5052. #ifdef __cplusplus
  5053. extern "C" {
  5054. #endif
  5055. VOID
  5056. _ReadWriteBarrier (
  5057. VOID
  5058. );
  5059. #ifdef __cplusplus
  5060. }
  5061. #endif
  5062. #pragma intrinsic(_ReadWriteBarrier)
  5063. #define KeMemoryBarrierWithoutFence() _ReadWriteBarrier()
  5064. //++
  5065. //
  5066. //
  5067. // VOID
  5068. // KeMemoryBarrier (
  5069. // VOID
  5070. // )
  5071. //
  5072. //
  5073. // Routine Description:
  5074. //
  5075. // This function cases ordering of memory acceses as generated by the compiler and
  5076. // as seen by other processors.
  5077. //
  5078. //
  5079. // Arguments:
  5080. //
  5081. // None.
  5082. //
  5083. // Return Value:
  5084. //
  5085. // None.
  5086. //--
  5087. #define KE_MEMORY_BARRIER_REQUIRED
  5088. #define KeMemoryBarrier() {_ReadWriteBarrier();__mf ();_ReadWriteBarrier();}
  5089. //
  5090. // Define the page size
  5091. //
  5092. #define PAGE_SIZE 0x2000
  5093. //
  5094. // Define the number of trailing zeroes in a page aligned virtual address.
  5095. // This is used as the shift count when shifting virtual addresses to
  5096. // virtual page numbers.
  5097. //
  5098. #define PAGE_SHIFT 13L
  5099. //
  5100. // Cache and write buffer flush functions.
  5101. //
  5102. NTKERNELAPI
  5103. VOID
  5104. KeFlushIoBuffers (
  5105. IN PMDL Mdl,
  5106. IN BOOLEAN ReadOperation,
  5107. IN BOOLEAN DmaOperation
  5108. );
  5109. //
  5110. // Kernel breakin breakpoint
  5111. //
  5112. VOID
  5113. KeBreakinBreakpoint (
  5114. VOID
  5115. );
  5116. #define ExAcquireSpinLock(Lock, OldIrql) KeAcquireSpinLock((Lock), (OldIrql))
  5117. #define ExReleaseSpinLock(Lock, OldIrql) KeReleaseSpinLock((Lock), (OldIrql))
  5118. #define ExAcquireSpinLockAtDpcLevel(Lock) KeAcquireSpinLockAtDpcLevel(Lock)
  5119. #define ExReleaseSpinLockFromDpcLevel(Lock) KeReleaseSpinLockFromDpcLevel(Lock)
  5120. #define KeQueryTickCount(CurrentCount ) \
  5121. *(PULONGLONG)(CurrentCount) = **((volatile ULONGLONG **)(&KeTickCount));
  5122. //
  5123. // I/O space read and write macros.
  5124. //
  5125. NTHALAPI
  5126. UCHAR
  5127. READ_PORT_UCHAR (
  5128. PUCHAR RegisterAddress
  5129. );
  5130. NTHALAPI
  5131. USHORT
  5132. READ_PORT_USHORT (
  5133. PUSHORT RegisterAddress
  5134. );
  5135. NTHALAPI
  5136. ULONG
  5137. READ_PORT_ULONG (
  5138. PULONG RegisterAddress
  5139. );
  5140. NTHALAPI
  5141. VOID
  5142. READ_PORT_BUFFER_UCHAR (
  5143. PUCHAR portAddress,
  5144. PUCHAR readBuffer,
  5145. ULONG readCount
  5146. );
  5147. NTHALAPI
  5148. VOID
  5149. READ_PORT_BUFFER_USHORT (
  5150. PUSHORT portAddress,
  5151. PUSHORT readBuffer,
  5152. ULONG readCount
  5153. );
  5154. NTHALAPI
  5155. VOID
  5156. READ_PORT_BUFFER_ULONG (
  5157. PULONG portAddress,
  5158. PULONG readBuffer,
  5159. ULONG readCount
  5160. );
  5161. NTHALAPI
  5162. VOID
  5163. WRITE_PORT_UCHAR (
  5164. PUCHAR portAddress,
  5165. UCHAR Data
  5166. );
  5167. NTHALAPI
  5168. VOID
  5169. WRITE_PORT_USHORT (
  5170. PUSHORT portAddress,
  5171. USHORT Data
  5172. );
  5173. NTHALAPI
  5174. VOID
  5175. WRITE_PORT_ULONG (
  5176. PULONG portAddress,
  5177. ULONG Data
  5178. );
  5179. NTHALAPI
  5180. VOID
  5181. WRITE_PORT_BUFFER_UCHAR (
  5182. PUCHAR portAddress,
  5183. PUCHAR writeBuffer,
  5184. ULONG writeCount
  5185. );
  5186. NTHALAPI
  5187. VOID
  5188. WRITE_PORT_BUFFER_USHORT (
  5189. PUSHORT portAddress,
  5190. PUSHORT writeBuffer,
  5191. ULONG writeCount
  5192. );
  5193. NTHALAPI
  5194. VOID
  5195. WRITE_PORT_BUFFER_ULONG (
  5196. PULONG portAddress,
  5197. PULONG writeBuffer,
  5198. ULONG writeCount
  5199. );
  5200. #define READ_REGISTER_UCHAR(x) \
  5201. (__mf(), *(volatile UCHAR * const)(x))
  5202. #define READ_REGISTER_USHORT(x) \
  5203. (__mf(), *(volatile USHORT * const)(x))
  5204. #define READ_REGISTER_ULONG(x) \
  5205. (__mf(), *(volatile ULONG * const)(x))
  5206. #define READ_REGISTER_BUFFER_UCHAR(x, y, z) { \
  5207. PUCHAR registerBuffer = x; \
  5208. PUCHAR readBuffer = y; \
  5209. ULONG readCount; \
  5210. __mf(); \
  5211. for (readCount = z; readCount--; readBuffer++, registerBuffer++) { \
  5212. *readBuffer = *(volatile UCHAR * const)(registerBuffer); \
  5213. } \
  5214. }
  5215. #define READ_REGISTER_BUFFER_USHORT(x, y, z) { \
  5216. PUSHORT registerBuffer = x; \
  5217. PUSHORT readBuffer = y; \
  5218. ULONG readCount; \
  5219. __mf(); \
  5220. for (readCount = z; readCount--; readBuffer++, registerBuffer++) { \
  5221. *readBuffer = *(volatile USHORT * const)(registerBuffer); \
  5222. } \
  5223. }
  5224. #define READ_REGISTER_BUFFER_ULONG(x, y, z) { \
  5225. PULONG registerBuffer = x; \
  5226. PULONG readBuffer = y; \
  5227. ULONG readCount; \
  5228. __mf(); \
  5229. for (readCount = z; readCount--; readBuffer++, registerBuffer++) { \
  5230. *readBuffer = *(volatile ULONG * const)(registerBuffer); \
  5231. } \
  5232. }
  5233. #define WRITE_REGISTER_UCHAR(x, y) { \
  5234. *(volatile UCHAR * const)(x) = y; \
  5235. KeFlushWriteBuffer(); \
  5236. }
  5237. #define WRITE_REGISTER_USHORT(x, y) { \
  5238. *(volatile USHORT * const)(x) = y; \
  5239. KeFlushWriteBuffer(); \
  5240. }
  5241. #define WRITE_REGISTER_ULONG(x, y) { \
  5242. *(volatile ULONG * const)(x) = y; \
  5243. KeFlushWriteBuffer(); \
  5244. }
  5245. #define WRITE_REGISTER_BUFFER_UCHAR(x, y, z) { \
  5246. PUCHAR registerBuffer = x; \
  5247. PUCHAR writeBuffer = y; \
  5248. ULONG writeCount; \
  5249. for (writeCount = z; writeCount--; writeBuffer++, registerBuffer++) { \
  5250. *(volatile UCHAR * const)(registerBuffer) = *writeBuffer; \
  5251. } \
  5252. KeFlushWriteBuffer(); \
  5253. }
  5254. #define WRITE_REGISTER_BUFFER_USHORT(x, y, z) { \
  5255. PUSHORT registerBuffer = x; \
  5256. PUSHORT writeBuffer = y; \
  5257. ULONG writeCount; \
  5258. for (writeCount = z; writeCount--; writeBuffer++, registerBuffer++) { \
  5259. *(volatile USHORT * const)(registerBuffer) = *writeBuffer; \
  5260. } \
  5261. KeFlushWriteBuffer(); \
  5262. }
  5263. #define WRITE_REGISTER_BUFFER_ULONG(x, y, z) { \
  5264. PULONG registerBuffer = x; \
  5265. PULONG writeBuffer = y; \
  5266. ULONG writeCount; \
  5267. for (writeCount = z; writeCount--; writeBuffer++, registerBuffer++) { \
  5268. *(volatile ULONG * const)(registerBuffer) = *writeBuffer; \
  5269. } \
  5270. KeFlushWriteBuffer(); \
  5271. }
  5272. //
  5273. // Non-volatile floating point state
  5274. //
  5275. typedef struct _KFLOATING_SAVE {
  5276. ULONG Reserved;
  5277. } KFLOATING_SAVE, *PKFLOATING_SAVE;
  5278. NTKERNELAPI
  5279. KIRQL
  5280. KeGetCurrentIrql();
  5281. NTKERNELAPI
  5282. VOID
  5283. KeLowerIrql (
  5284. IN KIRQL NewIrql
  5285. );
  5286. NTKERNELAPI
  5287. VOID
  5288. KeRaiseIrql (
  5289. IN KIRQL NewIrql,
  5290. OUT PKIRQL OldIrql
  5291. );
  5292. #define MmGetProcedureAddress(Address) (Address)
  5293. #define MmLockPagableCodeSection(PLabelAddress) \
  5294. MmLockPagableDataSection((PVOID)(*((PULONGLONG)PLabelAddress)))
  5295. #define VRN_MASK 0xE000000000000000UI64 // Virtual Region Number mask
  5296. //
  5297. // The lowest address for system space.
  5298. //
  5299. #define MM_LOWEST_SYSTEM_ADDRESS ((PVOID)((ULONG_PTR)(KADDRESS_BASE + 0xC0C00000)))
  5300. #endif // defined(_IA64_)
  5301. //
  5302. // Event Specific Access Rights.
  5303. //
  5304. #define EVENT_QUERY_STATE 0x0001
  5305. #define EVENT_MODIFY_STATE 0x0002
  5306. #define EVENT_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE|0x3)
  5307. //
  5308. // Semaphore Specific Access Rights.
  5309. //
  5310. #define SEMAPHORE_QUERY_STATE 0x0001
  5311. #define SEMAPHORE_MODIFY_STATE 0x0002
  5312. #define SEMAPHORE_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE|0x3)
  5313. //
  5314. // Defined processor features
  5315. //
  5316. #define PF_FLOATING_POINT_PRECISION_ERRATA 0
  5317. #define PF_FLOATING_POINT_EMULATED 1
  5318. #define PF_COMPARE_EXCHANGE_DOUBLE 2
  5319. #define PF_MMX_INSTRUCTIONS_AVAILABLE 3
  5320. #define PF_PPC_MOVEMEM_64BIT_OK 4
  5321. #define PF_ALPHA_BYTE_INSTRUCTIONS 5
  5322. #define PF_XMMI_INSTRUCTIONS_AVAILABLE 6
  5323. #define PF_3DNOW_INSTRUCTIONS_AVAILABLE 7
  5324. #define PF_RDTSC_INSTRUCTION_AVAILABLE 8
  5325. #define PF_PAE_ENABLED 9
  5326. #define PF_XMMI64_INSTRUCTIONS_AVAILABLE 10
  5327. typedef enum _ALTERNATIVE_ARCHITECTURE_TYPE {
  5328. StandardDesign, // None == 0 == standard design
  5329. NEC98x86, // NEC PC98xx series on X86
  5330. EndAlternatives // past end of known alternatives
  5331. } ALTERNATIVE_ARCHITECTURE_TYPE;
  5332. // correctly define these run-time definitions for non X86 machines
  5333. #ifndef _X86_
  5334. #ifndef IsNEC_98
  5335. #define IsNEC_98 (FALSE)
  5336. #endif
  5337. #ifndef IsNotNEC_98
  5338. #define IsNotNEC_98 (TRUE)
  5339. #endif
  5340. #ifndef SetNEC_98
  5341. #define SetNEC_98
  5342. #endif
  5343. #ifndef SetNotNEC_98
  5344. #define SetNotNEC_98
  5345. #endif
  5346. #endif
  5347. #define PROCESSOR_FEATURE_MAX 64
  5348. //
  5349. // Predefined Value Types.
  5350. //
  5351. #define REG_NONE ( 0 ) // No value type
  5352. #define REG_SZ ( 1 ) // Unicode nul terminated string
  5353. #define REG_EXPAND_SZ ( 2 ) // Unicode nul terminated string
  5354. // (with environment variable references)
  5355. #define REG_BINARY ( 3 ) // Free form binary
  5356. #define REG_DWORD ( 4 ) // 32-bit number
  5357. #define REG_DWORD_LITTLE_ENDIAN ( 4 ) // 32-bit number (same as REG_DWORD)
  5358. #define REG_DWORD_BIG_ENDIAN ( 5 ) // 32-bit number
  5359. #define REG_LINK ( 6 ) // Symbolic Link (unicode)
  5360. #define REG_MULTI_SZ ( 7 ) // Multiple Unicode strings
  5361. #define REG_RESOURCE_LIST ( 8 ) // Resource list in the resource map
  5362. #define REG_FULL_RESOURCE_DESCRIPTOR ( 9 ) // Resource list in the hardware description
  5363. #define REG_RESOURCE_REQUIREMENTS_LIST ( 10 )
  5364. #define REG_QWORD ( 11 ) // 64-bit number
  5365. #define REG_QWORD_LITTLE_ENDIAN ( 11 ) // 64-bit number (same as REG_QWORD)
  5366. //
  5367. // Service Types (Bit Mask)
  5368. //
  5369. #define SERVICE_KERNEL_DRIVER 0x00000001
  5370. #define SERVICE_FILE_SYSTEM_DRIVER 0x00000002
  5371. #define SERVICE_ADAPTER 0x00000004
  5372. #define SERVICE_RECOGNIZER_DRIVER 0x00000008
  5373. #define SERVICE_DRIVER (SERVICE_KERNEL_DRIVER | \
  5374. SERVICE_FILE_SYSTEM_DRIVER | \
  5375. SERVICE_RECOGNIZER_DRIVER)
  5376. #define SERVICE_WIN32_OWN_PROCESS 0x00000010
  5377. #define SERVICE_WIN32_SHARE_PROCESS 0x00000020
  5378. #define SERVICE_WIN32 (SERVICE_WIN32_OWN_PROCESS | \
  5379. SERVICE_WIN32_SHARE_PROCESS)
  5380. #define SERVICE_INTERACTIVE_PROCESS 0x00000100
  5381. #define SERVICE_TYPE_ALL (SERVICE_WIN32 | \
  5382. SERVICE_ADAPTER | \
  5383. SERVICE_DRIVER | \
  5384. SERVICE_INTERACTIVE_PROCESS)
  5385. //
  5386. // Start Type
  5387. //
  5388. #define SERVICE_BOOT_START 0x00000000
  5389. #define SERVICE_SYSTEM_START 0x00000001
  5390. #define SERVICE_AUTO_START 0x00000002
  5391. #define SERVICE_DEMAND_START 0x00000003
  5392. #define SERVICE_DISABLED 0x00000004
  5393. //
  5394. // Error control type
  5395. //
  5396. #define SERVICE_ERROR_IGNORE 0x00000000
  5397. #define SERVICE_ERROR_NORMAL 0x00000001
  5398. #define SERVICE_ERROR_SEVERE 0x00000002
  5399. #define SERVICE_ERROR_CRITICAL 0x00000003
  5400. //
  5401. //
  5402. // Define the registry driver node enumerations
  5403. //
  5404. typedef enum _CM_SERVICE_NODE_TYPE {
  5405. DriverType = SERVICE_KERNEL_DRIVER,
  5406. FileSystemType = SERVICE_FILE_SYSTEM_DRIVER,
  5407. Win32ServiceOwnProcess = SERVICE_WIN32_OWN_PROCESS,
  5408. Win32ServiceShareProcess = SERVICE_WIN32_SHARE_PROCESS,
  5409. AdapterType = SERVICE_ADAPTER,
  5410. RecognizerType = SERVICE_RECOGNIZER_DRIVER
  5411. } SERVICE_NODE_TYPE;
  5412. typedef enum _CM_SERVICE_LOAD_TYPE {
  5413. BootLoad = SERVICE_BOOT_START,
  5414. SystemLoad = SERVICE_SYSTEM_START,
  5415. AutoLoad = SERVICE_AUTO_START,
  5416. DemandLoad = SERVICE_DEMAND_START,
  5417. DisableLoad = SERVICE_DISABLED
  5418. } SERVICE_LOAD_TYPE;
  5419. typedef enum _CM_ERROR_CONTROL_TYPE {
  5420. IgnoreError = SERVICE_ERROR_IGNORE,
  5421. NormalError = SERVICE_ERROR_NORMAL,
  5422. SevereError = SERVICE_ERROR_SEVERE,
  5423. CriticalError = SERVICE_ERROR_CRITICAL
  5424. } SERVICE_ERROR_TYPE;
  5425. //
  5426. // Resource List definitions
  5427. //
  5428. //
  5429. // Defines the Type in the RESOURCE_DESCRIPTOR
  5430. //
  5431. // NOTE: For all CM_RESOURCE_TYPE values, there must be a
  5432. // corresponding ResType value in the 32-bit ConfigMgr headerfile
  5433. // (cfgmgr32.h). Values in the range [0x6,0x80) use the same values
  5434. // as their ConfigMgr counterparts. CM_RESOURCE_TYPE values with
  5435. // the high bit set (i.e., in the range [0x80,0xFF]), are
  5436. // non-arbitrated resources. These correspond to the same values
  5437. // in cfgmgr32.h that have their high bit set (however, since
  5438. // cfgmgr32.h uses 16 bits for ResType values, these values are in
  5439. // the range [0x8000,0x807F). Note that ConfigMgr ResType values
  5440. // cannot be in the range [0x8080,0xFFFF), because they would not
  5441. // be able to map into CM_RESOURCE_TYPE values. (0xFFFF itself is
  5442. // a special value, because it maps to CmResourceTypeDeviceSpecific.)
  5443. //
  5444. typedef int CM_RESOURCE_TYPE;
  5445. // CmResourceTypeNull is reserved
  5446. #define CmResourceTypeNull 0 // ResType_All or ResType_None (0x0000)
  5447. #define CmResourceTypePort 1 // ResType_IO (0x0002)
  5448. #define CmResourceTypeInterrupt 2 // ResType_IRQ (0x0004)
  5449. #define CmResourceTypeMemory 3 // ResType_Mem (0x0001)
  5450. #define CmResourceTypeDma 4 // ResType_DMA (0x0003)
  5451. #define CmResourceTypeDeviceSpecific 5 // ResType_ClassSpecific (0xFFFF)
  5452. #define CmResourceTypeBusNumber 6 // ResType_BusNumber (0x0006)
  5453. #define CmResourceTypeNonArbitrated 128 // Not arbitrated if 0x80 bit set
  5454. #define CmResourceTypeConfigData 128 // ResType_Reserved (0x8000)
  5455. #define CmResourceTypeDevicePrivate 129 // ResType_DevicePrivate (0x8001)
  5456. #define CmResourceTypePcCardConfig 130 // ResType_PcCardConfig (0x8002)
  5457. #define CmResourceTypeMfCardConfig 131 // ResType_MfCardConfig (0x8003)
  5458. //
  5459. // Defines the ShareDisposition in the RESOURCE_DESCRIPTOR
  5460. //
  5461. typedef enum _CM_SHARE_DISPOSITION {
  5462. CmResourceShareUndetermined = 0, // Reserved
  5463. CmResourceShareDeviceExclusive,
  5464. CmResourceShareDriverExclusive,
  5465. CmResourceShareShared
  5466. } CM_SHARE_DISPOSITION;
  5467. //
  5468. // Define the bit masks for Flags when type is CmResourceTypeInterrupt
  5469. //
  5470. #define CM_RESOURCE_INTERRUPT_LEVEL_SENSITIVE 0
  5471. #define CM_RESOURCE_INTERRUPT_LATCHED 1
  5472. //
  5473. // Define the bit masks for Flags when type is CmResourceTypeMemory
  5474. //
  5475. #define CM_RESOURCE_MEMORY_READ_WRITE 0x0000
  5476. #define CM_RESOURCE_MEMORY_READ_ONLY 0x0001
  5477. #define CM_RESOURCE_MEMORY_WRITE_ONLY 0x0002
  5478. #define CM_RESOURCE_MEMORY_PREFETCHABLE 0x0004
  5479. #define CM_RESOURCE_MEMORY_COMBINEDWRITE 0x0008
  5480. #define CM_RESOURCE_MEMORY_24 0x0010
  5481. #define CM_RESOURCE_MEMORY_CACHEABLE 0x0020
  5482. //
  5483. // Define the bit masks for Flags when type is CmResourceTypePort
  5484. //
  5485. #define CM_RESOURCE_PORT_MEMORY 0x0000
  5486. #define CM_RESOURCE_PORT_IO 0x0001
  5487. #define CM_RESOURCE_PORT_10_BIT_DECODE 0x0004
  5488. #define CM_RESOURCE_PORT_12_BIT_DECODE 0x0008
  5489. #define CM_RESOURCE_PORT_16_BIT_DECODE 0x0010
  5490. #define CM_RESOURCE_PORT_POSITIVE_DECODE 0x0020
  5491. #define CM_RESOURCE_PORT_PASSIVE_DECODE 0x0040
  5492. #define CM_RESOURCE_PORT_WINDOW_DECODE 0x0080
  5493. //
  5494. // Define the bit masks for Flags when type is CmResourceTypeDma
  5495. //
  5496. #define CM_RESOURCE_DMA_8 0x0000
  5497. #define CM_RESOURCE_DMA_16 0x0001
  5498. #define CM_RESOURCE_DMA_32 0x0002
  5499. #define CM_RESOURCE_DMA_8_AND_16 0x0004
  5500. #define CM_RESOURCE_DMA_BUS_MASTER 0x0008
  5501. #define CM_RESOURCE_DMA_TYPE_A 0x0010
  5502. #define CM_RESOURCE_DMA_TYPE_B 0x0020
  5503. #define CM_RESOURCE_DMA_TYPE_F 0x0040
  5504. //
  5505. // This structure defines one type of resource used by a driver.
  5506. //
  5507. // There can only be *1* DeviceSpecificData block. It must be located at
  5508. // the end of all resource descriptors in a full descriptor block.
  5509. //
  5510. //
  5511. // Make sure alignment is made properly by compiler; otherwise move
  5512. // flags back to the top of the structure (common to all members of the
  5513. // union).
  5514. //
  5515. #include "pshpack4.h"
  5516. typedef struct _CM_PARTIAL_RESOURCE_DESCRIPTOR {
  5517. UCHAR Type;
  5518. UCHAR ShareDisposition;
  5519. USHORT Flags;
  5520. union {
  5521. //
  5522. // Range of resources, inclusive. These are physical, bus relative.
  5523. // It is known that Port and Memory below have the exact same layout
  5524. // as Generic.
  5525. //
  5526. struct {
  5527. PHYSICAL_ADDRESS Start;
  5528. ULONG Length;
  5529. } Generic;
  5530. //
  5531. //
  5532. struct {
  5533. PHYSICAL_ADDRESS Start;
  5534. ULONG Length;
  5535. } Port;
  5536. //
  5537. //
  5538. struct {
  5539. ULONG Level;
  5540. ULONG Vector;
  5541. KAFFINITY Affinity;
  5542. } Interrupt;
  5543. //
  5544. // Range of memory addresses, inclusive. These are physical, bus
  5545. // relative. The value should be the same as the one passed to
  5546. // HalTranslateBusAddress().
  5547. //
  5548. struct {
  5549. PHYSICAL_ADDRESS Start; // 64 bit physical addresses.
  5550. ULONG Length;
  5551. } Memory;
  5552. //
  5553. // Physical DMA channel.
  5554. //
  5555. struct {
  5556. ULONG Channel;
  5557. ULONG Port;
  5558. ULONG Reserved1;
  5559. } Dma;
  5560. //
  5561. // Device driver private data, usually used to help it figure
  5562. // what the resource assignments decisions that were made.
  5563. //
  5564. struct {
  5565. ULONG Data[3];
  5566. } DevicePrivate;
  5567. //
  5568. // Bus Number information.
  5569. //
  5570. struct {
  5571. ULONG Start;
  5572. ULONG Length;
  5573. ULONG Reserved;
  5574. } BusNumber;
  5575. //
  5576. // Device Specific information defined by the driver.
  5577. // The DataSize field indicates the size of the data in bytes. The
  5578. // data is located immediately after the DeviceSpecificData field in
  5579. // the structure.
  5580. //
  5581. struct {
  5582. ULONG DataSize;
  5583. ULONG Reserved1;
  5584. ULONG Reserved2;
  5585. } DeviceSpecificData;
  5586. } u;
  5587. } CM_PARTIAL_RESOURCE_DESCRIPTOR, *PCM_PARTIAL_RESOURCE_DESCRIPTOR;
  5588. #include "poppack.h"
  5589. //
  5590. // A Partial Resource List is what can be found in the ARC firmware
  5591. // or will be generated by ntdetect.com.
  5592. // The configuration manager will transform this structure into a Full
  5593. // resource descriptor when it is about to store it in the regsitry.
  5594. //
  5595. // Note: There must a be a convention to the order of fields of same type,
  5596. // (defined on a device by device basis) so that the fields can make sense
  5597. // to a driver (i.e. when multiple memory ranges are necessary).
  5598. //
  5599. typedef struct _CM_PARTIAL_RESOURCE_LIST {
  5600. USHORT Version;
  5601. USHORT Revision;
  5602. ULONG Count;
  5603. CM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptors[1];
  5604. } CM_PARTIAL_RESOURCE_LIST, *PCM_PARTIAL_RESOURCE_LIST;
  5605. //
  5606. // A Full Resource Descriptor is what can be found in the registry.
  5607. // This is what will be returned to a driver when it queries the registry
  5608. // to get device information; it will be stored under a key in the hardware
  5609. // description tree.
  5610. //
  5611. // Note: There must a be a convention to the order of fields of same type,
  5612. // (defined on a device by device basis) so that the fields can make sense
  5613. // to a driver (i.e. when multiple memory ranges are necessary).
  5614. //
  5615. typedef struct _CM_FULL_RESOURCE_DESCRIPTOR {
  5616. INTERFACE_TYPE DoNotUse1;
  5617. ULONG DoNotUse2;
  5618. CM_PARTIAL_RESOURCE_LIST PartialResourceList;
  5619. } CM_FULL_RESOURCE_DESCRIPTOR, *PCM_FULL_RESOURCE_DESCRIPTOR;
  5620. //
  5621. // The Resource list is what will be stored by the drivers into the
  5622. // resource map via the IO API.
  5623. //
  5624. typedef struct _CM_RESOURCE_LIST {
  5625. ULONG Count;
  5626. CM_FULL_RESOURCE_DESCRIPTOR List[1];
  5627. } CM_RESOURCE_LIST, *PCM_RESOURCE_LIST;
  5628. //
  5629. // Define the structures used to interpret configuration data of
  5630. // \\Registry\machine\hardware\description tree.
  5631. // Basically, these structures are used to interpret component
  5632. // sepcific data.
  5633. //
  5634. //
  5635. // Define DEVICE_FLAGS
  5636. //
  5637. typedef struct _DEVICE_FLAGS {
  5638. ULONG Failed : 1;
  5639. ULONG ReadOnly : 1;
  5640. ULONG Removable : 1;
  5641. ULONG ConsoleIn : 1;
  5642. ULONG ConsoleOut : 1;
  5643. ULONG Input : 1;
  5644. ULONG Output : 1;
  5645. } DEVICE_FLAGS, *PDEVICE_FLAGS;
  5646. //
  5647. // Define Component Information structure
  5648. //
  5649. typedef struct _CM_COMPONENT_INFORMATION {
  5650. DEVICE_FLAGS Flags;
  5651. ULONG Version;
  5652. ULONG Key;
  5653. KAFFINITY AffinityMask;
  5654. } CM_COMPONENT_INFORMATION, *PCM_COMPONENT_INFORMATION;
  5655. //
  5656. // The following structures are used to interpret x86
  5657. // DeviceSpecificData of CM_PARTIAL_RESOURCE_DESCRIPTOR.
  5658. // (Most of the structures are defined by BIOS. They are
  5659. // not aligned on word (or dword) boundary.
  5660. //
  5661. //
  5662. // Define the Rom Block structure
  5663. //
  5664. typedef struct _CM_ROM_BLOCK {
  5665. ULONG Address;
  5666. ULONG Size;
  5667. } CM_ROM_BLOCK, *PCM_ROM_BLOCK;
  5668. #include "pshpack1.h"
  5669. //
  5670. // Define INT13 driver parameter block
  5671. //
  5672. typedef struct _CM_INT13_DRIVE_PARAMETER {
  5673. USHORT DriveSelect;
  5674. ULONG MaxCylinders;
  5675. USHORT SectorsPerTrack;
  5676. USHORT MaxHeads;
  5677. USHORT NumberDrives;
  5678. } CM_INT13_DRIVE_PARAMETER, *PCM_INT13_DRIVE_PARAMETER;
  5679. //
  5680. // Define Mca POS data block for slot
  5681. //
  5682. typedef struct _CM_MCA_POS_DATA {
  5683. USHORT AdapterId;
  5684. UCHAR PosData1;
  5685. UCHAR PosData2;
  5686. UCHAR PosData3;
  5687. UCHAR PosData4;
  5688. } CM_MCA_POS_DATA, *PCM_MCA_POS_DATA;
  5689. //
  5690. // Memory configuration of eisa data block structure
  5691. //
  5692. typedef struct _EISA_MEMORY_TYPE {
  5693. UCHAR ReadWrite: 1;
  5694. UCHAR Cached : 1;
  5695. UCHAR Reserved0 :1;
  5696. UCHAR Type:2;
  5697. UCHAR Shared:1;
  5698. UCHAR Reserved1 :1;
  5699. UCHAR MoreEntries : 1;
  5700. } EISA_MEMORY_TYPE, *PEISA_MEMORY_TYPE;
  5701. typedef struct _EISA_MEMORY_CONFIGURATION {
  5702. EISA_MEMORY_TYPE ConfigurationByte;
  5703. UCHAR DataSize;
  5704. USHORT AddressLowWord;
  5705. UCHAR AddressHighByte;
  5706. USHORT MemorySize;
  5707. } EISA_MEMORY_CONFIGURATION, *PEISA_MEMORY_CONFIGURATION;
  5708. //
  5709. // Interrupt configurationn of eisa data block structure
  5710. //
  5711. typedef struct _EISA_IRQ_DESCRIPTOR {
  5712. UCHAR Interrupt : 4;
  5713. UCHAR Reserved :1;
  5714. UCHAR LevelTriggered :1;
  5715. UCHAR Shared : 1;
  5716. UCHAR MoreEntries : 1;
  5717. } EISA_IRQ_DESCRIPTOR, *PEISA_IRQ_DESCRIPTOR;
  5718. typedef struct _EISA_IRQ_CONFIGURATION {
  5719. EISA_IRQ_DESCRIPTOR ConfigurationByte;
  5720. UCHAR Reserved;
  5721. } EISA_IRQ_CONFIGURATION, *PEISA_IRQ_CONFIGURATION;
  5722. //
  5723. // DMA description of eisa data block structure
  5724. //
  5725. typedef struct _DMA_CONFIGURATION_BYTE0 {
  5726. UCHAR Channel : 3;
  5727. UCHAR Reserved : 3;
  5728. UCHAR Shared :1;
  5729. UCHAR MoreEntries :1;
  5730. } DMA_CONFIGURATION_BYTE0;
  5731. typedef struct _DMA_CONFIGURATION_BYTE1 {
  5732. UCHAR Reserved0 : 2;
  5733. UCHAR TransferSize : 2;
  5734. UCHAR Timing : 2;
  5735. UCHAR Reserved1 : 2;
  5736. } DMA_CONFIGURATION_BYTE1;
  5737. typedef struct _EISA_DMA_CONFIGURATION {
  5738. DMA_CONFIGURATION_BYTE0 ConfigurationByte0;
  5739. DMA_CONFIGURATION_BYTE1 ConfigurationByte1;
  5740. } EISA_DMA_CONFIGURATION, *PEISA_DMA_CONFIGURATION;
  5741. //
  5742. // Port description of eisa data block structure
  5743. //
  5744. typedef struct _EISA_PORT_DESCRIPTOR {
  5745. UCHAR NumberPorts : 5;
  5746. UCHAR Reserved :1;
  5747. UCHAR Shared :1;
  5748. UCHAR MoreEntries : 1;
  5749. } EISA_PORT_DESCRIPTOR, *PEISA_PORT_DESCRIPTOR;
  5750. typedef struct _EISA_PORT_CONFIGURATION {
  5751. EISA_PORT_DESCRIPTOR Configuration;
  5752. USHORT PortAddress;
  5753. } EISA_PORT_CONFIGURATION, *PEISA_PORT_CONFIGURATION;
  5754. //
  5755. // Eisa slot information definition
  5756. // N.B. This structure is different from the one defined
  5757. // in ARC eisa addendum.
  5758. //
  5759. typedef struct _CM_EISA_SLOT_INFORMATION {
  5760. UCHAR ReturnCode;
  5761. UCHAR ReturnFlags;
  5762. UCHAR MajorRevision;
  5763. UCHAR MinorRevision;
  5764. USHORT Checksum;
  5765. UCHAR NumberFunctions;
  5766. UCHAR FunctionInformation;
  5767. ULONG CompressedId;
  5768. } CM_EISA_SLOT_INFORMATION, *PCM_EISA_SLOT_INFORMATION;
  5769. //
  5770. // Eisa function information definition
  5771. //
  5772. typedef struct _CM_EISA_FUNCTION_INFORMATION {
  5773. ULONG CompressedId;
  5774. UCHAR IdSlotFlags1;
  5775. UCHAR IdSlotFlags2;
  5776. UCHAR MinorRevision;
  5777. UCHAR MajorRevision;
  5778. UCHAR Selections[26];
  5779. UCHAR FunctionFlags;
  5780. UCHAR TypeString[80];
  5781. EISA_MEMORY_CONFIGURATION EisaMemory[9];
  5782. EISA_IRQ_CONFIGURATION EisaIrq[7];
  5783. EISA_DMA_CONFIGURATION EisaDma[4];
  5784. EISA_PORT_CONFIGURATION EisaPort[20];
  5785. UCHAR InitializationData[60];
  5786. } CM_EISA_FUNCTION_INFORMATION, *PCM_EISA_FUNCTION_INFORMATION;
  5787. //
  5788. // The following defines the way pnp bios information is stored in
  5789. // the registry \\HKEY_LOCAL_MACHINE\HARDWARE\Description\System\MultifunctionAdapter\x
  5790. // key, where x is an integer number indicating adapter instance. The
  5791. // "Identifier" of the key must equal to "PNP BIOS" and the
  5792. // "ConfigurationData" is organized as follow:
  5793. //
  5794. // CM_PNP_BIOS_INSTALLATION_CHECK +
  5795. // CM_PNP_BIOS_DEVICE_NODE for device 1 +
  5796. // CM_PNP_BIOS_DEVICE_NODE for device 2 +
  5797. // ...
  5798. // CM_PNP_BIOS_DEVICE_NODE for device n
  5799. //
  5800. //
  5801. // Pnp BIOS device node structure
  5802. //
  5803. typedef struct _CM_PNP_BIOS_DEVICE_NODE {
  5804. USHORT Size;
  5805. UCHAR Node;
  5806. ULONG ProductId;
  5807. UCHAR DeviceType[3];
  5808. USHORT DeviceAttributes;
  5809. // followed by AllocatedResourceBlock, PossibleResourceBlock
  5810. // and CompatibleDeviceId
  5811. } CM_PNP_BIOS_DEVICE_NODE,*PCM_PNP_BIOS_DEVICE_NODE;
  5812. //
  5813. // Pnp BIOS Installation check
  5814. //
  5815. typedef struct _CM_PNP_BIOS_INSTALLATION_CHECK {
  5816. UCHAR Signature[4]; // $PnP (ascii)
  5817. UCHAR Revision;
  5818. UCHAR Length;
  5819. USHORT ControlField;
  5820. UCHAR Checksum;
  5821. ULONG EventFlagAddress; // Physical address
  5822. USHORT RealModeEntryOffset;
  5823. USHORT RealModeEntrySegment;
  5824. USHORT ProtectedModeEntryOffset;
  5825. ULONG ProtectedModeCodeBaseAddress;
  5826. ULONG OemDeviceId;
  5827. USHORT RealModeDataBaseAddress;
  5828. ULONG ProtectedModeDataBaseAddress;
  5829. } CM_PNP_BIOS_INSTALLATION_CHECK, *PCM_PNP_BIOS_INSTALLATION_CHECK;
  5830. #include "poppack.h"
  5831. //
  5832. // Masks for EISA function information
  5833. //
  5834. #define EISA_FUNCTION_ENABLED 0x80
  5835. #define EISA_FREE_FORM_DATA 0x40
  5836. #define EISA_HAS_PORT_INIT_ENTRY 0x20
  5837. #define EISA_HAS_PORT_RANGE 0x10
  5838. #define EISA_HAS_DMA_ENTRY 0x08
  5839. #define EISA_HAS_IRQ_ENTRY 0x04
  5840. #define EISA_HAS_MEMORY_ENTRY 0x02
  5841. #define EISA_HAS_TYPE_ENTRY 0x01
  5842. #define EISA_HAS_INFORMATION EISA_HAS_PORT_RANGE + \
  5843. EISA_HAS_DMA_ENTRY + \
  5844. EISA_HAS_IRQ_ENTRY + \
  5845. EISA_HAS_MEMORY_ENTRY + \
  5846. EISA_HAS_TYPE_ENTRY
  5847. //
  5848. // Masks for EISA memory configuration
  5849. //
  5850. #define EISA_MORE_ENTRIES 0x80
  5851. #define EISA_SYSTEM_MEMORY 0x00
  5852. #define EISA_MEMORY_TYPE_RAM 0x01
  5853. //
  5854. // Returned error code for EISA bios call
  5855. //
  5856. #define EISA_INVALID_SLOT 0x80
  5857. #define EISA_INVALID_FUNCTION 0x81
  5858. #define EISA_INVALID_CONFIGURATION 0x82
  5859. #define EISA_EMPTY_SLOT 0x83
  5860. #define EISA_INVALID_BIOS_CALL 0x86
  5861. //
  5862. // The following structures are used to interpret mips
  5863. // DeviceSpecificData of CM_PARTIAL_RESOURCE_DESCRIPTOR.
  5864. //
  5865. //
  5866. // Device data records for adapters.
  5867. //
  5868. //
  5869. // The device data record for the Emulex SCSI controller.
  5870. //
  5871. typedef struct _CM_SCSI_DEVICE_DATA {
  5872. USHORT Version;
  5873. USHORT Revision;
  5874. UCHAR HostIdentifier;
  5875. } CM_SCSI_DEVICE_DATA, *PCM_SCSI_DEVICE_DATA;
  5876. //
  5877. // Device data records for controllers.
  5878. //
  5879. //
  5880. // The device data record for the Video controller.
  5881. //
  5882. typedef struct _CM_VIDEO_DEVICE_DATA {
  5883. USHORT Version;
  5884. USHORT Revision;
  5885. ULONG VideoClock;
  5886. } CM_VIDEO_DEVICE_DATA, *PCM_VIDEO_DEVICE_DATA;
  5887. //
  5888. // The device data record for the SONIC network controller.
  5889. //
  5890. typedef struct _CM_SONIC_DEVICE_DATA {
  5891. USHORT Version;
  5892. USHORT Revision;
  5893. USHORT DataConfigurationRegister;
  5894. UCHAR EthernetAddress[8];
  5895. } CM_SONIC_DEVICE_DATA, *PCM_SONIC_DEVICE_DATA;
  5896. //
  5897. // The device data record for the serial controller.
  5898. //
  5899. typedef struct _CM_SERIAL_DEVICE_DATA {
  5900. USHORT Version;
  5901. USHORT Revision;
  5902. ULONG BaudClock;
  5903. } CM_SERIAL_DEVICE_DATA, *PCM_SERIAL_DEVICE_DATA;
  5904. //
  5905. // Device data records for peripherals.
  5906. //
  5907. //
  5908. // The device data record for the Monitor peripheral.
  5909. //
  5910. typedef struct _CM_MONITOR_DEVICE_DATA {
  5911. USHORT Version;
  5912. USHORT Revision;
  5913. USHORT HorizontalScreenSize;
  5914. USHORT VerticalScreenSize;
  5915. USHORT HorizontalResolution;
  5916. USHORT VerticalResolution;
  5917. USHORT HorizontalDisplayTimeLow;
  5918. USHORT HorizontalDisplayTime;
  5919. USHORT HorizontalDisplayTimeHigh;
  5920. USHORT HorizontalBackPorchLow;
  5921. USHORT HorizontalBackPorch;
  5922. USHORT HorizontalBackPorchHigh;
  5923. USHORT HorizontalFrontPorchLow;
  5924. USHORT HorizontalFrontPorch;
  5925. USHORT HorizontalFrontPorchHigh;
  5926. USHORT HorizontalSyncLow;
  5927. USHORT HorizontalSync;
  5928. USHORT HorizontalSyncHigh;
  5929. USHORT VerticalBackPorchLow;
  5930. USHORT VerticalBackPorch;
  5931. USHORT VerticalBackPorchHigh;
  5932. USHORT VerticalFrontPorchLow;
  5933. USHORT VerticalFrontPorch;
  5934. USHORT VerticalFrontPorchHigh;
  5935. USHORT VerticalSyncLow;
  5936. USHORT VerticalSync;
  5937. USHORT VerticalSyncHigh;
  5938. } CM_MONITOR_DEVICE_DATA, *PCM_MONITOR_DEVICE_DATA;
  5939. //
  5940. // The device data record for the Floppy peripheral.
  5941. //
  5942. typedef struct _CM_FLOPPY_DEVICE_DATA {
  5943. USHORT Version;
  5944. USHORT Revision;
  5945. CHAR Size[8];
  5946. ULONG MaxDensity;
  5947. ULONG MountDensity;
  5948. //
  5949. // New data fields for version >= 2.0
  5950. //
  5951. UCHAR StepRateHeadUnloadTime;
  5952. UCHAR HeadLoadTime;
  5953. UCHAR MotorOffTime;
  5954. UCHAR SectorLengthCode;
  5955. UCHAR SectorPerTrack;
  5956. UCHAR ReadWriteGapLength;
  5957. UCHAR DataTransferLength;
  5958. UCHAR FormatGapLength;
  5959. UCHAR FormatFillCharacter;
  5960. UCHAR HeadSettleTime;
  5961. UCHAR MotorSettleTime;
  5962. UCHAR MaximumTrackValue;
  5963. UCHAR DataTransferRate;
  5964. } CM_FLOPPY_DEVICE_DATA, *PCM_FLOPPY_DEVICE_DATA;
  5965. //
  5966. // The device data record for the Keyboard peripheral.
  5967. // The KeyboardFlags is defined (by x86 BIOS INT 16h, function 02) as:
  5968. // bit 7 : Insert on
  5969. // bit 6 : Caps Lock on
  5970. // bit 5 : Num Lock on
  5971. // bit 4 : Scroll Lock on
  5972. // bit 3 : Alt Key is down
  5973. // bit 2 : Ctrl Key is down
  5974. // bit 1 : Left shift key is down
  5975. // bit 0 : Right shift key is down
  5976. //
  5977. typedef struct _CM_KEYBOARD_DEVICE_DATA {
  5978. USHORT Version;
  5979. USHORT Revision;
  5980. UCHAR Type;
  5981. UCHAR Subtype;
  5982. USHORT KeyboardFlags;
  5983. } CM_KEYBOARD_DEVICE_DATA, *PCM_KEYBOARD_DEVICE_DATA;
  5984. //
  5985. // Declaration of the structure for disk geometries
  5986. //
  5987. typedef struct _CM_DISK_GEOMETRY_DEVICE_DATA {
  5988. ULONG BytesPerSector;
  5989. ULONG NumberOfCylinders;
  5990. ULONG SectorsPerTrack;
  5991. ULONG NumberOfHeads;
  5992. } CM_DISK_GEOMETRY_DEVICE_DATA, *PCM_DISK_GEOMETRY_DEVICE_DATA;
  5993. //
  5994. // Defines Resource Options
  5995. //
  5996. #define IO_RESOURCE_PREFERRED 0x01
  5997. #define IO_RESOURCE_DEFAULT 0x02
  5998. #define IO_RESOURCE_ALTERNATIVE 0x08
  5999. //
  6000. // This structure defines one type of resource requested by the driver
  6001. //
  6002. typedef struct _IO_RESOURCE_DESCRIPTOR {
  6003. UCHAR Option;
  6004. UCHAR Type; // use CM_RESOURCE_TYPE
  6005. UCHAR ShareDisposition; // use CM_SHARE_DISPOSITION
  6006. UCHAR Spare1;
  6007. USHORT Flags; // use CM resource flag defines
  6008. USHORT Spare2; // align
  6009. union {
  6010. struct {
  6011. ULONG Length;
  6012. ULONG Alignment;
  6013. PHYSICAL_ADDRESS MinimumAddress;
  6014. PHYSICAL_ADDRESS MaximumAddress;
  6015. } Port;
  6016. struct {
  6017. ULONG Length;
  6018. ULONG Alignment;
  6019. PHYSICAL_ADDRESS MinimumAddress;
  6020. PHYSICAL_ADDRESS MaximumAddress;
  6021. } Memory;
  6022. struct {
  6023. ULONG MinimumVector;
  6024. ULONG MaximumVector;
  6025. } Interrupt;
  6026. struct {
  6027. ULONG MinimumChannel;
  6028. ULONG MaximumChannel;
  6029. } Dma;
  6030. struct {
  6031. ULONG Length;
  6032. ULONG Alignment;
  6033. PHYSICAL_ADDRESS MinimumAddress;
  6034. PHYSICAL_ADDRESS MaximumAddress;
  6035. } Generic;
  6036. struct {
  6037. ULONG Data[3];
  6038. } DevicePrivate;
  6039. //
  6040. // Bus Number information.
  6041. //
  6042. struct {
  6043. ULONG Length;
  6044. ULONG MinBusNumber;
  6045. ULONG MaxBusNumber;
  6046. ULONG Reserved;
  6047. } BusNumber;
  6048. struct {
  6049. ULONG Priority; // use LCPRI_Xxx values in cfg.h
  6050. ULONG Reserved1;
  6051. ULONG Reserved2;
  6052. } ConfigData;
  6053. } u;
  6054. } IO_RESOURCE_DESCRIPTOR, *PIO_RESOURCE_DESCRIPTOR;
  6055. typedef struct _IO_RESOURCE_LIST {
  6056. USHORT Version;
  6057. USHORT Revision;
  6058. ULONG Count;
  6059. IO_RESOURCE_DESCRIPTOR Descriptors[1];
  6060. } IO_RESOURCE_LIST, *PIO_RESOURCE_LIST;
  6061. typedef struct _IO_RESOURCE_REQUIREMENTS_LIST {
  6062. ULONG ListSize;
  6063. INTERFACE_TYPE DoNotUse1;
  6064. ULONG DoNotUse2;
  6065. ULONG DoNotUse3;
  6066. ULONG Reserved[3];
  6067. ULONG AlternativeLists;
  6068. IO_RESOURCE_LIST List[1];
  6069. } IO_RESOURCE_REQUIREMENTS_LIST, *PIO_RESOURCE_REQUIREMENTS_LIST;
  6070. //
  6071. // Exception flag definitions.
  6072. //
  6073. #define EXCEPTION_NONCONTINUABLE 0x1 // Noncontinuable exception
  6074. //
  6075. // Define maximum number of exception parameters.
  6076. //
  6077. #define EXCEPTION_MAXIMUM_PARAMETERS 15 // maximum number of exception parameters
  6078. //
  6079. // Exception record definition.
  6080. //
  6081. typedef struct _EXCEPTION_RECORD {
  6082. NTSTATUS ExceptionCode;
  6083. ULONG ExceptionFlags;
  6084. struct _EXCEPTION_RECORD *ExceptionRecord;
  6085. PVOID ExceptionAddress;
  6086. ULONG NumberParameters;
  6087. ULONG_PTR ExceptionInformation[EXCEPTION_MAXIMUM_PARAMETERS];
  6088. } EXCEPTION_RECORD;
  6089. typedef EXCEPTION_RECORD *PEXCEPTION_RECORD;
  6090. typedef struct _EXCEPTION_RECORD32 {
  6091. NTSTATUS ExceptionCode;
  6092. ULONG ExceptionFlags;
  6093. ULONG ExceptionRecord;
  6094. ULONG ExceptionAddress;
  6095. ULONG NumberParameters;
  6096. ULONG ExceptionInformation[EXCEPTION_MAXIMUM_PARAMETERS];
  6097. } EXCEPTION_RECORD32, *PEXCEPTION_RECORD32;
  6098. typedef struct _EXCEPTION_RECORD64 {
  6099. NTSTATUS ExceptionCode;
  6100. ULONG ExceptionFlags;
  6101. ULONG64 ExceptionRecord;
  6102. ULONG64 ExceptionAddress;
  6103. ULONG NumberParameters;
  6104. ULONG __unusedAlignment;
  6105. ULONG64 ExceptionInformation[EXCEPTION_MAXIMUM_PARAMETERS];
  6106. } EXCEPTION_RECORD64, *PEXCEPTION_RECORD64;
  6107. //
  6108. // Typedef for pointer returned by exception_info()
  6109. //
  6110. typedef struct _EXCEPTION_POINTERS {
  6111. PEXCEPTION_RECORD ExceptionRecord;
  6112. PVOID ContextRecord;
  6113. } EXCEPTION_POINTERS, *PEXCEPTION_POINTERS;
  6114. #define THREAD_WAIT_OBJECTS 3 // Builtin usable wait blocks
  6115. //
  6116. // Interrupt modes.
  6117. //
  6118. typedef enum _KINTERRUPT_MODE {
  6119. LevelSensitive,
  6120. Latched
  6121. } KINTERRUPT_MODE;
  6122. //
  6123. // Wait reasons
  6124. //
  6125. typedef enum _KWAIT_REASON {
  6126. Executive,
  6127. FreePage,
  6128. PageIn,
  6129. PoolAllocation,
  6130. DelayExecution,
  6131. Suspended,
  6132. UserRequest,
  6133. WrExecutive,
  6134. WrFreePage,
  6135. WrPageIn,
  6136. WrPoolAllocation,
  6137. WrDelayExecution,
  6138. WrSuspended,
  6139. WrUserRequest,
  6140. WrEventPair,
  6141. WrQueue,
  6142. WrLpcReceive,
  6143. WrLpcReply,
  6144. WrVirtualMemory,
  6145. WrPageOut,
  6146. WrRendezvous,
  6147. Spare2,
  6148. Spare3,
  6149. Spare4,
  6150. Spare5,
  6151. Spare6,
  6152. WrKernel,
  6153. WrResource,
  6154. WrPushLock,
  6155. WrMutex,
  6156. WrQuantumEnd,
  6157. WrDispatchInt,
  6158. WrPreempted,
  6159. WrYieldExecution,
  6160. MaximumWaitReason
  6161. } KWAIT_REASON;
  6162. typedef struct _KWAIT_BLOCK {
  6163. LIST_ENTRY WaitListEntry;
  6164. struct _KTHREAD *RESTRICTED_POINTER Thread;
  6165. PVOID Object;
  6166. struct _KWAIT_BLOCK *RESTRICTED_POINTER NextWaitBlock;
  6167. USHORT WaitKey;
  6168. USHORT WaitType;
  6169. } KWAIT_BLOCK, *PKWAIT_BLOCK, *RESTRICTED_POINTER PRKWAIT_BLOCK;
  6170. //
  6171. // Thread start function
  6172. //
  6173. typedef
  6174. VOID
  6175. (*PKSTART_ROUTINE) (
  6176. IN PVOID StartContext
  6177. );
  6178. //
  6179. // Kernel object structure definitions
  6180. //
  6181. //
  6182. // Device Queue object and entry
  6183. //
  6184. typedef struct _KDEVICE_QUEUE {
  6185. CSHORT Type;
  6186. CSHORT Size;
  6187. LIST_ENTRY DeviceListHead;
  6188. KSPIN_LOCK Lock;
  6189. BOOLEAN Busy;
  6190. } KDEVICE_QUEUE, *PKDEVICE_QUEUE, *RESTRICTED_POINTER PRKDEVICE_QUEUE;
  6191. typedef struct _KDEVICE_QUEUE_ENTRY {
  6192. LIST_ENTRY DeviceListEntry;
  6193. ULONG SortKey;
  6194. BOOLEAN Inserted;
  6195. } KDEVICE_QUEUE_ENTRY, *PKDEVICE_QUEUE_ENTRY, *RESTRICTED_POINTER PRKDEVICE_QUEUE_ENTRY;
  6196. //
  6197. // Define the interrupt service function type and the empty struct
  6198. // type.
  6199. //
  6200. typedef
  6201. BOOLEAN
  6202. (*PKSERVICE_ROUTINE) (
  6203. IN struct _KINTERRUPT *Interrupt,
  6204. IN PVOID ServiceContext
  6205. );
  6206. //
  6207. // Mutant object
  6208. //
  6209. typedef struct _KMUTANT {
  6210. DISPATCHER_HEADER Header;
  6211. LIST_ENTRY MutantListEntry;
  6212. struct _KTHREAD *RESTRICTED_POINTER OwnerThread;
  6213. BOOLEAN Abandoned;
  6214. UCHAR ApcDisable;
  6215. } KMUTANT, *PKMUTANT, *RESTRICTED_POINTER PRKMUTANT, KMUTEX, *PKMUTEX, *RESTRICTED_POINTER PRKMUTEX;
  6216. //
  6217. //
  6218. // Semaphore object
  6219. //
  6220. typedef struct _KSEMAPHORE {
  6221. DISPATCHER_HEADER Header;
  6222. LONG Limit;
  6223. } KSEMAPHORE, *PKSEMAPHORE, *RESTRICTED_POINTER PRKSEMAPHORE;
  6224. //
  6225. // DPC object
  6226. //
  6227. NTKERNELAPI
  6228. VOID
  6229. KeInitializeDpc (
  6230. IN PRKDPC Dpc,
  6231. IN PKDEFERRED_ROUTINE DeferredRoutine,
  6232. IN PVOID DeferredContext
  6233. );
  6234. NTKERNELAPI
  6235. BOOLEAN
  6236. KeInsertQueueDpc (
  6237. IN PRKDPC Dpc,
  6238. IN PVOID SystemArgument1,
  6239. IN PVOID SystemArgument2
  6240. );
  6241. NTKERNELAPI
  6242. BOOLEAN
  6243. KeRemoveQueueDpc (
  6244. IN PRKDPC Dpc
  6245. );
  6246. NTKERNELAPI
  6247. VOID
  6248. KeFlushQueuedDpcs (
  6249. VOID
  6250. );
  6251. //
  6252. // Device queue object
  6253. //
  6254. NTKERNELAPI
  6255. VOID
  6256. KeInitializeDeviceQueue (
  6257. IN PKDEVICE_QUEUE DeviceQueue
  6258. );
  6259. NTKERNELAPI
  6260. BOOLEAN
  6261. KeInsertDeviceQueue (
  6262. IN PKDEVICE_QUEUE DeviceQueue,
  6263. IN PKDEVICE_QUEUE_ENTRY DeviceQueueEntry
  6264. );
  6265. NTKERNELAPI
  6266. BOOLEAN
  6267. KeInsertByKeyDeviceQueue (
  6268. IN PKDEVICE_QUEUE DeviceQueue,
  6269. IN PKDEVICE_QUEUE_ENTRY DeviceQueueEntry,
  6270. IN ULONG SortKey
  6271. );
  6272. NTKERNELAPI
  6273. PKDEVICE_QUEUE_ENTRY
  6274. KeRemoveDeviceQueue (
  6275. IN PKDEVICE_QUEUE DeviceQueue
  6276. );
  6277. NTKERNELAPI
  6278. PKDEVICE_QUEUE_ENTRY
  6279. KeRemoveByKeyDeviceQueue (
  6280. IN PKDEVICE_QUEUE DeviceQueue,
  6281. IN ULONG SortKey
  6282. );
  6283. NTKERNELAPI
  6284. PKDEVICE_QUEUE_ENTRY
  6285. KeRemoveByKeyDeviceQueueIfBusy (
  6286. IN PKDEVICE_QUEUE DeviceQueue,
  6287. IN ULONG SortKey
  6288. );
  6289. NTKERNELAPI
  6290. BOOLEAN
  6291. KeRemoveEntryDeviceQueue (
  6292. IN PKDEVICE_QUEUE DeviceQueue,
  6293. IN PKDEVICE_QUEUE_ENTRY DeviceQueueEntry
  6294. );
  6295. NTKERNELAPI
  6296. BOOLEAN
  6297. KeSynchronizeExecution (
  6298. IN PKINTERRUPT Interrupt,
  6299. IN PKSYNCHRONIZE_ROUTINE SynchronizeRoutine,
  6300. IN PVOID SynchronizeContext
  6301. );
  6302. NTKERNELAPI
  6303. KIRQL
  6304. KeAcquireInterruptSpinLock (
  6305. IN PKINTERRUPT Interrupt
  6306. );
  6307. NTKERNELAPI
  6308. VOID
  6309. KeReleaseInterruptSpinLock (
  6310. IN PKINTERRUPT Interrupt,
  6311. IN KIRQL OldIrql
  6312. );
  6313. //
  6314. // Kernel dispatcher object functions
  6315. //
  6316. // Event Object
  6317. //
  6318. NTKERNELAPI
  6319. VOID
  6320. KeInitializeEvent (
  6321. IN PRKEVENT Event,
  6322. IN EVENT_TYPE Type,
  6323. IN BOOLEAN State
  6324. );
  6325. NTKERNELAPI
  6326. VOID
  6327. KeClearEvent (
  6328. IN PRKEVENT Event
  6329. );
  6330. NTKERNELAPI
  6331. LONG
  6332. KeReadStateEvent (
  6333. IN PRKEVENT Event
  6334. );
  6335. NTKERNELAPI
  6336. LONG
  6337. KeResetEvent (
  6338. IN PRKEVENT Event
  6339. );
  6340. NTKERNELAPI
  6341. LONG
  6342. KeSetEvent (
  6343. IN PRKEVENT Event,
  6344. IN KPRIORITY Increment,
  6345. IN BOOLEAN Wait
  6346. );
  6347. //
  6348. // Mutex object
  6349. //
  6350. NTKERNELAPI
  6351. VOID
  6352. KeInitializeMutex (
  6353. IN PRKMUTEX Mutex,
  6354. IN ULONG Level
  6355. );
  6356. NTKERNELAPI
  6357. LONG
  6358. KeReadStateMutex (
  6359. IN PRKMUTEX Mutex
  6360. );
  6361. NTKERNELAPI
  6362. LONG
  6363. KeReleaseMutex (
  6364. IN PRKMUTEX Mutex,
  6365. IN BOOLEAN Wait
  6366. );
  6367. //
  6368. // Semaphore object
  6369. //
  6370. NTKERNELAPI
  6371. VOID
  6372. KeInitializeSemaphore (
  6373. IN PRKSEMAPHORE Semaphore,
  6374. IN LONG Count,
  6375. IN LONG Limit
  6376. );
  6377. NTKERNELAPI
  6378. LONG
  6379. KeReadStateSemaphore (
  6380. IN PRKSEMAPHORE Semaphore
  6381. );
  6382. NTKERNELAPI
  6383. LONG
  6384. KeReleaseSemaphore (
  6385. IN PRKSEMAPHORE Semaphore,
  6386. IN KPRIORITY Increment,
  6387. IN LONG Adjustment,
  6388. IN BOOLEAN Wait
  6389. );
  6390. NTKERNELAPI
  6391. NTSTATUS
  6392. KeDelayExecutionThread (
  6393. IN KPROCESSOR_MODE WaitMode,
  6394. IN BOOLEAN Alertable,
  6395. IN PLARGE_INTEGER Interval
  6396. );
  6397. NTKERNELAPI
  6398. KPRIORITY
  6399. KeQueryPriorityThread (
  6400. IN PKTHREAD Thread
  6401. );
  6402. NTKERNELAPI
  6403. ULONG
  6404. KeQueryRuntimeThread (
  6405. IN PKTHREAD Thread,
  6406. OUT PULONG UserTime
  6407. );
  6408. NTKERNELAPI
  6409. KPRIORITY
  6410. KeSetPriorityThread (
  6411. IN PKTHREAD Thread,
  6412. IN KPRIORITY Priority
  6413. );
  6414. NTKERNELAPI
  6415. VOID
  6416. KeEnterCriticalRegion (
  6417. VOID
  6418. );
  6419. NTKERNELAPI
  6420. VOID
  6421. KeLeaveCriticalRegion (
  6422. VOID
  6423. );
  6424. NTKERNELAPI
  6425. BOOLEAN
  6426. KeAreApcsDisabled (
  6427. VOID
  6428. );
  6429. //
  6430. // Timer object
  6431. //
  6432. NTKERNELAPI
  6433. VOID
  6434. KeInitializeTimer (
  6435. IN PKTIMER Timer
  6436. );
  6437. NTKERNELAPI
  6438. VOID
  6439. KeInitializeTimerEx (
  6440. IN PKTIMER Timer,
  6441. IN TIMER_TYPE Type
  6442. );
  6443. NTKERNELAPI
  6444. BOOLEAN
  6445. KeCancelTimer (
  6446. IN PKTIMER
  6447. );
  6448. NTKERNELAPI
  6449. BOOLEAN
  6450. KeReadStateTimer (
  6451. PKTIMER Timer
  6452. );
  6453. NTKERNELAPI
  6454. BOOLEAN
  6455. KeSetTimer (
  6456. IN PKTIMER Timer,
  6457. IN LARGE_INTEGER DueTime,
  6458. IN PKDPC Dpc OPTIONAL
  6459. );
  6460. NTKERNELAPI
  6461. BOOLEAN
  6462. KeSetTimerEx (
  6463. IN PKTIMER Timer,
  6464. IN LARGE_INTEGER DueTime,
  6465. IN LONG Period OPTIONAL,
  6466. IN PKDPC Dpc OPTIONAL
  6467. );
  6468. #define KeWaitForMutexObject KeWaitForSingleObject
  6469. NTKERNELAPI
  6470. NTSTATUS
  6471. KeWaitForMultipleObjects (
  6472. IN ULONG Count,
  6473. IN PVOID Object[],
  6474. IN WAIT_TYPE WaitType,
  6475. IN KWAIT_REASON WaitReason,
  6476. IN KPROCESSOR_MODE WaitMode,
  6477. IN BOOLEAN Alertable,
  6478. IN PLARGE_INTEGER Timeout OPTIONAL,
  6479. IN PKWAIT_BLOCK WaitBlockArray OPTIONAL
  6480. );
  6481. NTKERNELAPI
  6482. NTSTATUS
  6483. KeWaitForSingleObject (
  6484. IN PVOID Object,
  6485. IN KWAIT_REASON WaitReason,
  6486. IN KPROCESSOR_MODE WaitMode,
  6487. IN BOOLEAN Alertable,
  6488. IN PLARGE_INTEGER Timeout OPTIONAL
  6489. );
  6490. //
  6491. // Define interprocess interrupt generic call types.
  6492. //
  6493. typedef
  6494. ULONG_PTR
  6495. (*PKIPI_BROADCAST_WORKER)(
  6496. IN ULONG_PTR Argument
  6497. );
  6498. ULONG_PTR
  6499. KeIpiGenericCall (
  6500. IN PKIPI_BROADCAST_WORKER BroadcastFunction,
  6501. IN ULONG_PTR Context
  6502. );
  6503. //
  6504. // On X86 the following routines are defined in the HAL and imported by
  6505. // all other modules.
  6506. //
  6507. #if defined(_X86_) && !defined(_NTHAL_)
  6508. #define _DECL_HAL_KE_IMPORT __declspec(dllimport)
  6509. #else
  6510. #define _DECL_HAL_KE_IMPORT
  6511. #endif
  6512. //
  6513. // spin lock functions
  6514. //
  6515. #if defined(_X86_) && (defined(_WDMDDK_) || defined(WIN9X_COMPAT_SPINLOCK))
  6516. NTKERNELAPI
  6517. VOID
  6518. NTAPI
  6519. KeInitializeSpinLock (
  6520. IN PKSPIN_LOCK SpinLock
  6521. );
  6522. #else
  6523. __inline
  6524. VOID
  6525. NTAPI
  6526. KeInitializeSpinLock (
  6527. IN PKSPIN_LOCK SpinLock
  6528. )
  6529. {
  6530. *SpinLock = 0;
  6531. }
  6532. #endif
  6533. #if defined(_X86_)
  6534. NTKERNELAPI
  6535. VOID
  6536. FASTCALL
  6537. KefAcquireSpinLockAtDpcLevel (
  6538. IN PKSPIN_LOCK SpinLock
  6539. );
  6540. NTKERNELAPI
  6541. VOID
  6542. FASTCALL
  6543. KefReleaseSpinLockFromDpcLevel (
  6544. IN PKSPIN_LOCK SpinLock
  6545. );
  6546. #define KeAcquireSpinLockAtDpcLevel(a) KefAcquireSpinLockAtDpcLevel(a)
  6547. #define KeReleaseSpinLockFromDpcLevel(a) KefReleaseSpinLockFromDpcLevel(a)
  6548. _DECL_HAL_KE_IMPORT
  6549. KIRQL
  6550. FASTCALL
  6551. KfAcquireSpinLock (
  6552. IN PKSPIN_LOCK SpinLock
  6553. );
  6554. _DECL_HAL_KE_IMPORT
  6555. VOID
  6556. FASTCALL
  6557. KfReleaseSpinLock (
  6558. IN PKSPIN_LOCK SpinLock,
  6559. IN KIRQL NewIrql
  6560. );
  6561. #define KeAcquireSpinLock(a,b) *(b) = KfAcquireSpinLock(a)
  6562. #define KeReleaseSpinLock(a,b) KfReleaseSpinLock(a,b)
  6563. NTKERNELAPI
  6564. BOOLEAN
  6565. FASTCALL
  6566. KeTestSpinLock (
  6567. IN PKSPIN_LOCK SpinLock
  6568. );
  6569. NTKERNELAPI
  6570. BOOLEAN
  6571. FASTCALL
  6572. KeTryToAcquireSpinLockAtDpcLevel (
  6573. IN PKSPIN_LOCK SpinLock
  6574. );
  6575. #else
  6576. //
  6577. // These functions are imported for IA64, ntddk, ntifs, nthal, ntosp, and wdm.
  6578. // They can be inlined for the system on AMD64.
  6579. //
  6580. #define KeAcquireSpinLock(SpinLock, OldIrql) \
  6581. *(OldIrql) = KeAcquireSpinLockRaiseToDpc(SpinLock)
  6582. #if defined(_IA64_) || defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_) || defined(_NTHAL_) || defined(_NTOSP_) || defined(_WDMDDK_)
  6583. NTKERNELAPI
  6584. VOID
  6585. KeAcquireSpinLockAtDpcLevel (
  6586. IN PKSPIN_LOCK SpinLock
  6587. );
  6588. NTKERNELAPI
  6589. KIRQL
  6590. KeAcquireSpinLockRaiseToDpc (
  6591. IN PKSPIN_LOCK SpinLock
  6592. );
  6593. NTKERNELAPI
  6594. VOID
  6595. KeReleaseSpinLock (
  6596. IN PKSPIN_LOCK SpinLock,
  6597. IN KIRQL NewIrql
  6598. );
  6599. NTKERNELAPI
  6600. VOID
  6601. KeReleaseSpinLockFromDpcLevel (
  6602. IN PKSPIN_LOCK SpinLock
  6603. );
  6604. NTKERNELAPI
  6605. BOOLEAN
  6606. FASTCALL
  6607. KeTestSpinLock (
  6608. IN PKSPIN_LOCK SpinLock
  6609. );
  6610. NTKERNELAPI
  6611. BOOLEAN
  6612. FASTCALL
  6613. KeTryToAcquireSpinLockAtDpcLevel (
  6614. IN PKSPIN_LOCK SpinLock
  6615. );
  6616. #else
  6617. #if defined(_AMD64_)
  6618. //
  6619. // The system version of these functions are defined in amd64.h for AMD64.
  6620. //
  6621. #endif
  6622. #endif
  6623. #endif
  6624. #if defined(_X86_)
  6625. _DECL_HAL_KE_IMPORT
  6626. VOID
  6627. FASTCALL
  6628. KfLowerIrql (
  6629. IN KIRQL NewIrql
  6630. );
  6631. _DECL_HAL_KE_IMPORT
  6632. KIRQL
  6633. FASTCALL
  6634. KfRaiseIrql (
  6635. IN KIRQL NewIrql
  6636. );
  6637. #define KeLowerIrql(a) KfLowerIrql(a)
  6638. #define KeRaiseIrql(a,b) *(b) = KfRaiseIrql(a)
  6639. #elif defined(_IA64_)
  6640. //
  6641. // These function are defined in IA64.h for the IA64 platform.
  6642. //
  6643. #elif defined(_AMD64_)
  6644. //
  6645. // These function are defined in amd64.h for the AMD64 platform.
  6646. //
  6647. #else
  6648. #error "no target architecture"
  6649. #endif
  6650. //
  6651. // Miscellaneous kernel functions
  6652. //
  6653. typedef enum _KBUGCHECK_BUFFER_DUMP_STATE {
  6654. BufferEmpty,
  6655. BufferInserted,
  6656. BufferStarted,
  6657. BufferFinished,
  6658. BufferIncomplete
  6659. } KBUGCHECK_BUFFER_DUMP_STATE;
  6660. typedef
  6661. VOID
  6662. (*PKBUGCHECK_CALLBACK_ROUTINE) (
  6663. IN PVOID Buffer,
  6664. IN ULONG Length
  6665. );
  6666. typedef struct _KBUGCHECK_CALLBACK_RECORD {
  6667. LIST_ENTRY Entry;
  6668. PKBUGCHECK_CALLBACK_ROUTINE CallbackRoutine;
  6669. PVOID Buffer;
  6670. ULONG Length;
  6671. PUCHAR Component;
  6672. ULONG_PTR Checksum;
  6673. UCHAR State;
  6674. } KBUGCHECK_CALLBACK_RECORD, *PKBUGCHECK_CALLBACK_RECORD;
  6675. #define KeInitializeCallbackRecord(CallbackRecord) \
  6676. (CallbackRecord)->State = BufferEmpty
  6677. NTKERNELAPI
  6678. BOOLEAN
  6679. KeDeregisterBugCheckCallback (
  6680. IN PKBUGCHECK_CALLBACK_RECORD CallbackRecord
  6681. );
  6682. NTKERNELAPI
  6683. BOOLEAN
  6684. KeRegisterBugCheckCallback (
  6685. IN PKBUGCHECK_CALLBACK_RECORD CallbackRecord,
  6686. IN PKBUGCHECK_CALLBACK_ROUTINE CallbackRoutine,
  6687. IN PVOID Buffer,
  6688. IN ULONG Length,
  6689. IN PUCHAR Component
  6690. );
  6691. typedef enum _KBUGCHECK_CALLBACK_REASON {
  6692. KbCallbackInvalid,
  6693. KbCallbackReserved1,
  6694. KbCallbackSecondaryDumpData,
  6695. KbCallbackDumpIo,
  6696. } KBUGCHECK_CALLBACK_REASON;
  6697. typedef
  6698. VOID
  6699. (*PKBUGCHECK_REASON_CALLBACK_ROUTINE) (
  6700. IN KBUGCHECK_CALLBACK_REASON Reason,
  6701. IN struct _KBUGCHECK_REASON_CALLBACK_RECORD* Record,
  6702. IN OUT PVOID ReasonSpecificData,
  6703. IN ULONG ReasonSpecificDataLength
  6704. );
  6705. typedef struct _KBUGCHECK_REASON_CALLBACK_RECORD {
  6706. LIST_ENTRY Entry;
  6707. PKBUGCHECK_REASON_CALLBACK_ROUTINE CallbackRoutine;
  6708. PUCHAR Component;
  6709. ULONG_PTR Checksum;
  6710. KBUGCHECK_CALLBACK_REASON Reason;
  6711. UCHAR State;
  6712. } KBUGCHECK_REASON_CALLBACK_RECORD, *PKBUGCHECK_REASON_CALLBACK_RECORD;
  6713. typedef struct _KBUGCHECK_SECONDARY_DUMP_DATA {
  6714. IN PVOID InBuffer;
  6715. IN ULONG InBufferLength;
  6716. IN ULONG MaximumAllowed;
  6717. OUT GUID Guid;
  6718. OUT PVOID OutBuffer;
  6719. OUT ULONG OutBufferLength;
  6720. } KBUGCHECK_SECONDARY_DUMP_DATA, *PKBUGCHECK_SECONDARY_DUMP_DATA;
  6721. typedef enum _KBUGCHECK_DUMP_IO_TYPE
  6722. {
  6723. KbDumpIoInvalid,
  6724. KbDumpIoHeader,
  6725. KbDumpIoBody,
  6726. KbDumpIoSecondaryData,
  6727. KbDumpIoComplete
  6728. } KBUGCHECK_DUMP_IO_TYPE;
  6729. typedef struct _KBUGCHECK_DUMP_IO {
  6730. IN ULONG64 Offset;
  6731. IN PVOID Buffer;
  6732. IN ULONG BufferLength;
  6733. IN KBUGCHECK_DUMP_IO_TYPE Type;
  6734. } KBUGCHECK_DUMP_IO, *PKBUGCHECK_DUMP_IO;
  6735. NTKERNELAPI
  6736. BOOLEAN
  6737. KeDeregisterBugCheckReasonCallback (
  6738. IN PKBUGCHECK_REASON_CALLBACK_RECORD CallbackRecord
  6739. );
  6740. NTKERNELAPI
  6741. BOOLEAN
  6742. KeRegisterBugCheckReasonCallback (
  6743. IN PKBUGCHECK_REASON_CALLBACK_RECORD CallbackRecord,
  6744. IN PKBUGCHECK_REASON_CALLBACK_ROUTINE CallbackRoutine,
  6745. IN KBUGCHECK_CALLBACK_REASON Reason,
  6746. IN PUCHAR Component
  6747. );
  6748. typedef
  6749. BOOLEAN
  6750. (*PNMI_CALLBACK)(
  6751. IN PVOID Context,
  6752. IN BOOLEAN Handled
  6753. );
  6754. NTKERNELAPI
  6755. PVOID
  6756. KeRegisterNmiCallback(
  6757. PNMI_CALLBACK CallbackRoutine,
  6758. PVOID Context
  6759. );
  6760. NTSTATUS
  6761. KeDeregisterNmiCallback(
  6762. PVOID Handle
  6763. );
  6764. NTKERNELAPI
  6765. DECLSPEC_NORETURN
  6766. VOID
  6767. KeBugCheckEx(
  6768. IN ULONG BugCheckCode,
  6769. IN ULONG_PTR BugCheckParameter1,
  6770. IN ULONG_PTR BugCheckParameter2,
  6771. IN ULONG_PTR BugCheckParameter3,
  6772. IN ULONG_PTR BugCheckParameter4
  6773. );
  6774. #if !defined(_AMD64_)
  6775. NTKERNELAPI
  6776. ULONGLONG
  6777. KeQueryInterruptTime (
  6778. VOID
  6779. );
  6780. NTKERNELAPI
  6781. VOID
  6782. KeQuerySystemTime (
  6783. OUT PLARGE_INTEGER CurrentTime
  6784. );
  6785. #endif
  6786. NTKERNELAPI
  6787. ULONG
  6788. KeQueryTimeIncrement (
  6789. VOID
  6790. );
  6791. NTKERNELAPI
  6792. ULONG
  6793. KeGetRecommendedSharedDataAlignment (
  6794. VOID
  6795. );
  6796. #if defined(_IA64_)
  6797. extern volatile LARGE_INTEGER KeTickCount;
  6798. #elif defined(_X86_)
  6799. extern volatile KSYSTEM_TIME KeTickCount;
  6800. #endif
  6801. typedef enum _MEMORY_CACHING_TYPE_ORIG {
  6802. MmFrameBufferCached = 2
  6803. } MEMORY_CACHING_TYPE_ORIG;
  6804. typedef enum _MEMORY_CACHING_TYPE {
  6805. MmNonCached = FALSE,
  6806. MmCached = TRUE,
  6807. MmWriteCombined = MmFrameBufferCached,
  6808. MmHardwareCoherentCached,
  6809. MmCachingTypeDoNotUse1,
  6810. MmCachingTypeDoNotUse2,
  6811. MmMaximumCacheType
  6812. } MEMORY_CACHING_TYPE;
  6813. //
  6814. // Define external data.
  6815. // because of indirection for all drivers external to ntoskrnl these are actually ptrs
  6816. //
  6817. #if defined(_NTDDK_) || defined(_NTIFS_) || defined(_NTHAL_) || defined(_WDMDDK_) || defined(_NTOSP_)
  6818. extern PBOOLEAN KdDebuggerNotPresent;
  6819. extern PBOOLEAN KdDebuggerEnabled;
  6820. #define KD_DEBUGGER_ENABLED *KdDebuggerEnabled
  6821. #define KD_DEBUGGER_NOT_PRESENT *KdDebuggerNotPresent
  6822. #else
  6823. extern BOOLEAN KdDebuggerNotPresent;
  6824. extern BOOLEAN KdDebuggerEnabled;
  6825. #define KD_DEBUGGER_ENABLED KdDebuggerEnabled
  6826. #define KD_DEBUGGER_NOT_PRESENT KdDebuggerNotPresent
  6827. #endif
  6828. NTSTATUS
  6829. KdDisableDebugger(
  6830. VOID
  6831. );
  6832. NTSTATUS
  6833. KdEnableDebugger(
  6834. VOID
  6835. );
  6836. //
  6837. // KdRefreshDebuggerPresent attempts to communicate with
  6838. // the debugger host machine to refresh the state of
  6839. // KdDebuggerNotPresent. It returns the state of
  6840. // KdDebuggerNotPresent while the kd locks are held.
  6841. // KdDebuggerNotPresent may immediately change state
  6842. // after the kd locks are released so it may not
  6843. // match the return value.
  6844. //
  6845. BOOLEAN
  6846. KdRefreshDebuggerNotPresent(
  6847. VOID
  6848. );
  6849. //
  6850. // Pool Allocation routines (in pool.c)
  6851. //
  6852. typedef enum _POOL_TYPE {
  6853. NonPagedPool,
  6854. PagedPool,
  6855. NonPagedPoolMustSucceed,
  6856. DontUseThisType,
  6857. NonPagedPoolCacheAligned,
  6858. PagedPoolCacheAligned,
  6859. NonPagedPoolCacheAlignedMustS,
  6860. MaxPoolType
  6861. } POOL_TYPE;
  6862. #define POOL_COLD_ALLOCATION 256 // Note this cannot encode into the header.
  6863. DECLSPEC_DEPRECATED_DDK // Use ExAllocatePoolWithTag
  6864. NTKERNELAPI
  6865. PVOID
  6866. ExAllocatePool(
  6867. IN POOL_TYPE PoolType,
  6868. IN SIZE_T NumberOfBytes
  6869. );
  6870. DECLSPEC_DEPRECATED_DDK // Use ExAllocatePoolWithQuotaTag
  6871. NTKERNELAPI
  6872. PVOID
  6873. ExAllocatePoolWithQuota(
  6874. IN POOL_TYPE PoolType,
  6875. IN SIZE_T NumberOfBytes
  6876. );
  6877. NTKERNELAPI
  6878. PVOID
  6879. NTAPI
  6880. ExAllocatePoolWithTag(
  6881. IN POOL_TYPE PoolType,
  6882. IN SIZE_T NumberOfBytes,
  6883. IN ULONG Tag
  6884. );
  6885. //
  6886. // _EX_POOL_PRIORITY_ provides a method for the system to handle requests
  6887. // intelligently in low resource conditions.
  6888. //
  6889. // LowPoolPriority should be used when it is acceptable to the driver for the
  6890. // mapping request to fail if the system is low on resources. An example of
  6891. // this could be for a non-critical network connection where the driver can
  6892. // handle the failure case when system resources are close to being depleted.
  6893. //
  6894. // NormalPoolPriority should be used when it is acceptable to the driver for the
  6895. // mapping request to fail if the system is very low on resources. An example
  6896. // of this could be for a non-critical local filesystem request.
  6897. //
  6898. // HighPoolPriority should be used when it is unacceptable to the driver for the
  6899. // mapping request to fail unless the system is completely out of resources.
  6900. // An example of this would be the paging file path in a driver.
  6901. //
  6902. // SpecialPool can be specified to bound the allocation at a page end (or
  6903. // beginning). This should only be done on systems being debugged as the
  6904. // memory cost is expensive.
  6905. //
  6906. // N.B. These values are very carefully chosen so that the pool allocation
  6907. // code can quickly crack the priority request.
  6908. //
  6909. typedef enum _EX_POOL_PRIORITY {
  6910. LowPoolPriority,
  6911. LowPoolPrioritySpecialPoolOverrun = 8,
  6912. LowPoolPrioritySpecialPoolUnderrun = 9,
  6913. NormalPoolPriority = 16,
  6914. NormalPoolPrioritySpecialPoolOverrun = 24,
  6915. NormalPoolPrioritySpecialPoolUnderrun = 25,
  6916. HighPoolPriority = 32,
  6917. HighPoolPrioritySpecialPoolOverrun = 40,
  6918. HighPoolPrioritySpecialPoolUnderrun = 41
  6919. } EX_POOL_PRIORITY;
  6920. NTKERNELAPI
  6921. PVOID
  6922. NTAPI
  6923. ExAllocatePoolWithTagPriority(
  6924. IN POOL_TYPE PoolType,
  6925. IN SIZE_T NumberOfBytes,
  6926. IN ULONG Tag,
  6927. IN EX_POOL_PRIORITY Priority
  6928. );
  6929. #ifndef POOL_TAGGING
  6930. #define ExAllocatePoolWithTag(a,b,c) ExAllocatePool(a,b)
  6931. #endif //POOL_TAGGING
  6932. NTKERNELAPI
  6933. PVOID
  6934. ExAllocatePoolWithQuotaTag(
  6935. IN POOL_TYPE PoolType,
  6936. IN SIZE_T NumberOfBytes,
  6937. IN ULONG Tag
  6938. );
  6939. #ifndef POOL_TAGGING
  6940. #define ExAllocatePoolWithQuotaTag(a,b,c) ExAllocatePoolWithQuota(a,b)
  6941. #endif //POOL_TAGGING
  6942. NTKERNELAPI
  6943. VOID
  6944. NTAPI
  6945. ExFreePool(
  6946. IN PVOID P
  6947. );
  6948. NTKERNELAPI
  6949. VOID
  6950. ExFreePoolWithTag(
  6951. IN PVOID P,
  6952. IN ULONG Tag
  6953. );
  6954. //
  6955. // Routines to support fast mutexes.
  6956. //
  6957. typedef struct _FAST_MUTEX {
  6958. LONG Count;
  6959. PKTHREAD Owner;
  6960. ULONG Contention;
  6961. KEVENT Event;
  6962. ULONG OldIrql;
  6963. } FAST_MUTEX, *PFAST_MUTEX;
  6964. #define ExInitializeFastMutex(_FastMutex) \
  6965. (_FastMutex)->Count = 1; \
  6966. (_FastMutex)->Owner = NULL; \
  6967. (_FastMutex)->Contention = 0; \
  6968. KeInitializeEvent(&(_FastMutex)->Event, \
  6969. SynchronizationEvent, \
  6970. FALSE);
  6971. NTKERNELAPI
  6972. VOID
  6973. FASTCALL
  6974. ExAcquireFastMutexUnsafe (
  6975. IN PFAST_MUTEX FastMutex
  6976. );
  6977. NTKERNELAPI
  6978. VOID
  6979. FASTCALL
  6980. ExReleaseFastMutexUnsafe (
  6981. IN PFAST_MUTEX FastMutex
  6982. );
  6983. #if defined(_IA64_) || defined(_AMD64_)
  6984. NTKERNELAPI
  6985. VOID
  6986. FASTCALL
  6987. ExAcquireFastMutex (
  6988. IN PFAST_MUTEX FastMutex
  6989. );
  6990. NTKERNELAPI
  6991. VOID
  6992. FASTCALL
  6993. ExReleaseFastMutex (
  6994. IN PFAST_MUTEX FastMutex
  6995. );
  6996. NTKERNELAPI
  6997. BOOLEAN
  6998. FASTCALL
  6999. ExTryToAcquireFastMutex (
  7000. IN PFAST_MUTEX FastMutex
  7001. );
  7002. #elif defined(_X86_)
  7003. NTHALAPI
  7004. VOID
  7005. FASTCALL
  7006. ExAcquireFastMutex (
  7007. IN PFAST_MUTEX FastMutex
  7008. );
  7009. NTHALAPI
  7010. VOID
  7011. FASTCALL
  7012. ExReleaseFastMutex (
  7013. IN PFAST_MUTEX FastMutex
  7014. );
  7015. NTHALAPI
  7016. BOOLEAN
  7017. FASTCALL
  7018. ExTryToAcquireFastMutex (
  7019. IN PFAST_MUTEX FastMutex
  7020. );
  7021. #else
  7022. #error "Target architecture not defined"
  7023. #endif
  7024. //
  7025. #if defined(_WIN64)
  7026. #define ExInterlockedAddLargeStatistic(Addend, Increment) \
  7027. (VOID) InterlockedAdd64(&(Addend)->QuadPart, Increment)
  7028. #else
  7029. #ifdef __cplusplus
  7030. extern "C" {
  7031. #endif
  7032. LONG
  7033. _InterlockedAddLargeStatistic (
  7034. IN PLONGLONG Addend,
  7035. IN ULONG Increment
  7036. );
  7037. #ifdef __cplusplus
  7038. }
  7039. #endif
  7040. #pragma intrinsic (_InterlockedAddLargeStatistic)
  7041. #define ExInterlockedAddLargeStatistic(Addend,Increment) \
  7042. (VOID) _InterlockedAddLargeStatistic ((PLONGLONG)&(Addend)->QuadPart, Increment)
  7043. #endif
  7044. NTKERNELAPI
  7045. LARGE_INTEGER
  7046. ExInterlockedAddLargeInteger (
  7047. IN PLARGE_INTEGER Addend,
  7048. IN LARGE_INTEGER Increment,
  7049. IN PKSPIN_LOCK Lock
  7050. );
  7051. NTKERNELAPI
  7052. ULONG
  7053. FASTCALL
  7054. ExInterlockedAddUlong (
  7055. IN PULONG Addend,
  7056. IN ULONG Increment,
  7057. IN PKSPIN_LOCK Lock
  7058. );
  7059. #if defined(_AMD64_) || defined(_AXP64_) || defined(_IA64_)
  7060. #define ExInterlockedCompareExchange64(Destination, Exchange, Comperand, Lock) \
  7061. InterlockedCompareExchange64(Destination, *(Exchange), *(Comperand))
  7062. #elif defined(_ALPHA_)
  7063. #define ExInterlockedCompareExchange64(Destination, Exchange, Comperand, Lock) \
  7064. ExpInterlockedCompareExchange64(Destination, Exchange, Comperand)
  7065. #else
  7066. #define ExInterlockedCompareExchange64(Destination, Exchange, Comperand, Lock) \
  7067. ExfInterlockedCompareExchange64(Destination, Exchange, Comperand)
  7068. #endif
  7069. NTKERNELAPI
  7070. PLIST_ENTRY
  7071. FASTCALL
  7072. ExInterlockedInsertHeadList (
  7073. IN PLIST_ENTRY ListHead,
  7074. IN PLIST_ENTRY ListEntry,
  7075. IN PKSPIN_LOCK Lock
  7076. );
  7077. NTKERNELAPI
  7078. PLIST_ENTRY
  7079. FASTCALL
  7080. ExInterlockedInsertTailList (
  7081. IN PLIST_ENTRY ListHead,
  7082. IN PLIST_ENTRY ListEntry,
  7083. IN PKSPIN_LOCK Lock
  7084. );
  7085. NTKERNELAPI
  7086. PLIST_ENTRY
  7087. FASTCALL
  7088. ExInterlockedRemoveHeadList (
  7089. IN PLIST_ENTRY ListHead,
  7090. IN PKSPIN_LOCK Lock
  7091. );
  7092. NTKERNELAPI
  7093. PSINGLE_LIST_ENTRY
  7094. FASTCALL
  7095. ExInterlockedPopEntryList (
  7096. IN PSINGLE_LIST_ENTRY ListHead,
  7097. IN PKSPIN_LOCK Lock
  7098. );
  7099. NTKERNELAPI
  7100. PSINGLE_LIST_ENTRY
  7101. FASTCALL
  7102. ExInterlockedPushEntryList (
  7103. IN PSINGLE_LIST_ENTRY ListHead,
  7104. IN PSINGLE_LIST_ENTRY ListEntry,
  7105. IN PKSPIN_LOCK Lock
  7106. );
  7107. //
  7108. // Define interlocked sequenced listhead functions.
  7109. //
  7110. // A sequenced interlocked list is a singly linked list with a header that
  7111. // contains the current depth and a sequence number. Each time an entry is
  7112. // inserted or removed from the list the depth is updated and the sequence
  7113. // number is incremented. This enables AMD64, IA64, and Pentium and later
  7114. // machines to insert and remove from the list without the use of spinlocks.
  7115. //
  7116. #if !defined(_WINBASE_)
  7117. /*++
  7118. Routine Description:
  7119. This function initializes a sequenced singly linked listhead.
  7120. Arguments:
  7121. SListHead - Supplies a pointer to a sequenced singly linked listhead.
  7122. Return Value:
  7123. None.
  7124. --*/
  7125. #if defined(_WIN64) && (defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_) || defined(_NTHAL_) || defined(_NTOSP_))
  7126. NTKERNELAPI
  7127. VOID
  7128. InitializeSListHead (
  7129. IN PSLIST_HEADER SListHead
  7130. );
  7131. #else
  7132. __inline
  7133. VOID
  7134. InitializeSListHead (
  7135. IN PSLIST_HEADER SListHead
  7136. )
  7137. {
  7138. #ifdef _WIN64
  7139. //
  7140. // Slist headers must be 16 byte aligned.
  7141. //
  7142. if ((ULONG_PTR) SListHead & 0x0f) {
  7143. DbgPrint( "InitializeSListHead unaligned Slist header. Address = %p, Caller = %p\n", SListHead, _ReturnAddress());
  7144. RtlRaiseStatus(STATUS_DATATYPE_MISALIGNMENT);
  7145. }
  7146. #endif
  7147. SListHead->Alignment = 0;
  7148. //
  7149. // For IA-64 we save the region number of the elements of the list in a
  7150. // separate field. This imposes the requirement that all elements stored
  7151. // in the list are from the same region.
  7152. #if defined(_IA64_)
  7153. SListHead->Region = (ULONG_PTR)SListHead & VRN_MASK;
  7154. #elif defined(_AMD64_)
  7155. SListHead->Region = 0;
  7156. #endif
  7157. return;
  7158. }
  7159. #endif
  7160. #endif // !defined(_WINBASE_)
  7161. #define ExInitializeSListHead InitializeSListHead
  7162. PSLIST_ENTRY
  7163. FirstEntrySList (
  7164. IN const SLIST_HEADER *SListHead
  7165. );
  7166. /*++
  7167. Routine Description:
  7168. This function queries the current number of entries contained in a
  7169. sequenced single linked list.
  7170. Arguments:
  7171. SListHead - Supplies a pointer to the sequenced listhead which is
  7172. be queried.
  7173. Return Value:
  7174. The current number of entries in the sequenced singly linked list is
  7175. returned as the function value.
  7176. --*/
  7177. #if defined(_WIN64)
  7178. #if (defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_) || defined(_NTHAL_) || defined(_NTOSP_))
  7179. NTKERNELAPI
  7180. USHORT
  7181. ExQueryDepthSList (
  7182. IN PSLIST_HEADER SListHead
  7183. );
  7184. #else
  7185. __inline
  7186. USHORT
  7187. ExQueryDepthSList (
  7188. IN PSLIST_HEADER SListHead
  7189. )
  7190. {
  7191. return (USHORT)(SListHead->Alignment & 0xffff);
  7192. }
  7193. #endif
  7194. #else
  7195. #define ExQueryDepthSList(_listhead_) (_listhead_)->Depth
  7196. #endif
  7197. #if defined(_WIN64)
  7198. #define ExInterlockedPopEntrySList(Head, Lock) \
  7199. ExpInterlockedPopEntrySList(Head)
  7200. #define ExInterlockedPushEntrySList(Head, Entry, Lock) \
  7201. ExpInterlockedPushEntrySList(Head, Entry)
  7202. #define ExInterlockedFlushSList(Head) \
  7203. ExpInterlockedFlushSList(Head)
  7204. #if !defined(_WINBASE_)
  7205. #define InterlockedPopEntrySList(Head) \
  7206. ExpInterlockedPopEntrySList(Head)
  7207. #define InterlockedPushEntrySList(Head, Entry) \
  7208. ExpInterlockedPushEntrySList(Head, Entry)
  7209. #define InterlockedFlushSList(Head) \
  7210. ExpInterlockedFlushSList(Head)
  7211. #define QueryDepthSList(Head) \
  7212. ExQueryDepthSList(Head)
  7213. #endif // !defined(_WINBASE_)
  7214. NTKERNELAPI
  7215. PSLIST_ENTRY
  7216. ExpInterlockedPopEntrySList (
  7217. IN PSLIST_HEADER ListHead
  7218. );
  7219. NTKERNELAPI
  7220. PSLIST_ENTRY
  7221. ExpInterlockedPushEntrySList (
  7222. IN PSLIST_HEADER ListHead,
  7223. IN PSLIST_ENTRY ListEntry
  7224. );
  7225. NTKERNELAPI
  7226. PSLIST_ENTRY
  7227. ExpInterlockedFlushSList (
  7228. IN PSLIST_HEADER ListHead
  7229. );
  7230. #else
  7231. #if defined(_WIN2K_COMPAT_SLIST_USAGE) && defined(_X86_)
  7232. NTKERNELAPI
  7233. PSLIST_ENTRY
  7234. FASTCALL
  7235. ExInterlockedPopEntrySList (
  7236. IN PSLIST_HEADER ListHead,
  7237. IN PKSPIN_LOCK Lock
  7238. );
  7239. NTKERNELAPI
  7240. PSLIST_ENTRY
  7241. FASTCALL
  7242. ExInterlockedPushEntrySList (
  7243. IN PSLIST_HEADER ListHead,
  7244. IN PSLIST_ENTRY ListEntry,
  7245. IN PKSPIN_LOCK Lock
  7246. );
  7247. #else
  7248. #define ExInterlockedPopEntrySList(ListHead, Lock) \
  7249. InterlockedPopEntrySList(ListHead)
  7250. #define ExInterlockedPushEntrySList(ListHead, ListEntry, Lock) \
  7251. InterlockedPushEntrySList(ListHead, ListEntry)
  7252. #endif
  7253. NTKERNELAPI
  7254. PSLIST_ENTRY
  7255. FASTCALL
  7256. ExInterlockedFlushSList (
  7257. IN PSLIST_HEADER ListHead
  7258. );
  7259. #if !defined(_WINBASE_)
  7260. NTKERNELAPI
  7261. PSLIST_ENTRY
  7262. FASTCALL
  7263. InterlockedPopEntrySList (
  7264. IN PSLIST_HEADER ListHead
  7265. );
  7266. NTKERNELAPI
  7267. PSLIST_ENTRY
  7268. FASTCALL
  7269. InterlockedPushEntrySList (
  7270. IN PSLIST_HEADER ListHead,
  7271. IN PSLIST_ENTRY ListEntry
  7272. );
  7273. #define InterlockedFlushSList(Head) \
  7274. ExInterlockedFlushSList(Head)
  7275. #define QueryDepthSList(Head) \
  7276. ExQueryDepthSList(Head)
  7277. #endif // !defined(_WINBASE_)
  7278. #endif // defined(_WIN64)
  7279. typedef
  7280. PVOID
  7281. (*PALLOCATE_FUNCTION) (
  7282. IN POOL_TYPE PoolType,
  7283. IN SIZE_T NumberOfBytes,
  7284. IN ULONG Tag
  7285. );
  7286. typedef
  7287. VOID
  7288. (*PFREE_FUNCTION) (
  7289. IN PVOID Buffer
  7290. );
  7291. #if !defined(_WIN64) && (defined(_NTDDK_) || defined(_NTIFS_) || defined(_NDIS_))
  7292. typedef struct _GENERAL_LOOKASIDE {
  7293. #else
  7294. typedef struct DECLSPEC_CACHEALIGN _GENERAL_LOOKASIDE {
  7295. #endif
  7296. SLIST_HEADER ListHead;
  7297. USHORT Depth;
  7298. USHORT MaximumDepth;
  7299. ULONG TotalAllocates;
  7300. union {
  7301. ULONG AllocateMisses;
  7302. ULONG AllocateHits;
  7303. };
  7304. ULONG TotalFrees;
  7305. union {
  7306. ULONG FreeMisses;
  7307. ULONG FreeHits;
  7308. };
  7309. POOL_TYPE Type;
  7310. ULONG Tag;
  7311. ULONG Size;
  7312. PALLOCATE_FUNCTION Allocate;
  7313. PFREE_FUNCTION Free;
  7314. LIST_ENTRY ListEntry;
  7315. ULONG LastTotalAllocates;
  7316. union {
  7317. ULONG LastAllocateMisses;
  7318. ULONG LastAllocateHits;
  7319. };
  7320. ULONG Future[2];
  7321. } GENERAL_LOOKASIDE, *PGENERAL_LOOKASIDE;
  7322. #if !defined(_WIN64) && (defined(_NTDDK_) || defined(_NTIFS_) || defined(_NDIS_))
  7323. typedef struct _NPAGED_LOOKASIDE_LIST {
  7324. #else
  7325. typedef struct DECLSPEC_CACHEALIGN _NPAGED_LOOKASIDE_LIST {
  7326. #endif
  7327. GENERAL_LOOKASIDE L;
  7328. #if !defined(_AMD64_) && !defined(_IA64_)
  7329. KSPIN_LOCK Lock__ObsoleteButDoNotDelete;
  7330. #endif
  7331. } NPAGED_LOOKASIDE_LIST, *PNPAGED_LOOKASIDE_LIST;
  7332. NTKERNELAPI
  7333. VOID
  7334. ExInitializeNPagedLookasideList (
  7335. IN PNPAGED_LOOKASIDE_LIST Lookaside,
  7336. IN PALLOCATE_FUNCTION Allocate,
  7337. IN PFREE_FUNCTION Free,
  7338. IN ULONG Flags,
  7339. IN SIZE_T Size,
  7340. IN ULONG Tag,
  7341. IN USHORT Depth
  7342. );
  7343. NTKERNELAPI
  7344. VOID
  7345. ExDeleteNPagedLookasideList (
  7346. IN PNPAGED_LOOKASIDE_LIST Lookaside
  7347. );
  7348. __inline
  7349. PVOID
  7350. ExAllocateFromNPagedLookasideList(
  7351. IN PNPAGED_LOOKASIDE_LIST Lookaside
  7352. )
  7353. /*++
  7354. Routine Description:
  7355. This function removes (pops) the first entry from the specified
  7356. nonpaged lookaside list.
  7357. Arguments:
  7358. Lookaside - Supplies a pointer to a nonpaged lookaside list structure.
  7359. Return Value:
  7360. If an entry is removed from the specified lookaside list, then the
  7361. address of the entry is returned as the function value. Otherwise,
  7362. NULL is returned.
  7363. --*/
  7364. {
  7365. PVOID Entry;
  7366. Lookaside->L.TotalAllocates += 1;
  7367. #if defined(_WIN2K_COMPAT_SLIST_USAGE) && defined(_X86_)
  7368. Entry = ExInterlockedPopEntrySList(&Lookaside->L.ListHead,
  7369. &Lookaside->Lock__ObsoleteButDoNotDelete);
  7370. #else
  7371. Entry = InterlockedPopEntrySList(&Lookaside->L.ListHead);
  7372. #endif
  7373. if (Entry == NULL) {
  7374. Lookaside->L.AllocateMisses += 1;
  7375. Entry = (Lookaside->L.Allocate)(Lookaside->L.Type,
  7376. Lookaside->L.Size,
  7377. Lookaside->L.Tag);
  7378. }
  7379. return Entry;
  7380. }
  7381. __inline
  7382. VOID
  7383. ExFreeToNPagedLookasideList(
  7384. IN PNPAGED_LOOKASIDE_LIST Lookaside,
  7385. IN PVOID Entry
  7386. )
  7387. /*++
  7388. Routine Description:
  7389. This function inserts (pushes) the specified entry into the specified
  7390. nonpaged lookaside list.
  7391. Arguments:
  7392. Lookaside - Supplies a pointer to a nonpaged lookaside list structure.
  7393. Entry - Supples a pointer to the entry that is inserted in the
  7394. lookaside list.
  7395. Return Value:
  7396. None.
  7397. --*/
  7398. {
  7399. Lookaside->L.TotalFrees += 1;
  7400. if (ExQueryDepthSList(&Lookaside->L.ListHead) >= Lookaside->L.Depth) {
  7401. Lookaside->L.FreeMisses += 1;
  7402. (Lookaside->L.Free)(Entry);
  7403. } else {
  7404. #if defined(_WIN2K_COMPAT_SLIST_USAGE) && defined(_X86_)
  7405. ExInterlockedPushEntrySList(&Lookaside->L.ListHead,
  7406. (PSLIST_ENTRY)Entry,
  7407. &Lookaside->Lock__ObsoleteButDoNotDelete);
  7408. #else
  7409. InterlockedPushEntrySList(&Lookaside->L.ListHead,
  7410. (PSLIST_ENTRY)Entry);
  7411. #endif
  7412. }
  7413. return;
  7414. }
  7415. #if !defined(_WIN64) && (defined(_NTDDK_) || defined(_NTIFS_) || defined(_NDIS_))
  7416. typedef struct _PAGED_LOOKASIDE_LIST {
  7417. #else
  7418. typedef struct DECLSPEC_CACHEALIGN _PAGED_LOOKASIDE_LIST {
  7419. #endif
  7420. GENERAL_LOOKASIDE L;
  7421. #if !defined(_AMD64_) && !defined(_IA64_)
  7422. FAST_MUTEX Lock__ObsoleteButDoNotDelete;
  7423. #endif
  7424. } PAGED_LOOKASIDE_LIST, *PPAGED_LOOKASIDE_LIST;
  7425. NTKERNELAPI
  7426. VOID
  7427. ExInitializePagedLookasideList (
  7428. IN PPAGED_LOOKASIDE_LIST Lookaside,
  7429. IN PALLOCATE_FUNCTION Allocate,
  7430. IN PFREE_FUNCTION Free,
  7431. IN ULONG Flags,
  7432. IN SIZE_T Size,
  7433. IN ULONG Tag,
  7434. IN USHORT Depth
  7435. );
  7436. NTKERNELAPI
  7437. VOID
  7438. ExDeletePagedLookasideList (
  7439. IN PPAGED_LOOKASIDE_LIST Lookaside
  7440. );
  7441. #if defined(_WIN2K_COMPAT_SLIST_USAGE) && defined(_X86_)
  7442. NTKERNELAPI
  7443. PVOID
  7444. ExAllocateFromPagedLookasideList(
  7445. IN PPAGED_LOOKASIDE_LIST Lookaside
  7446. );
  7447. #else
  7448. __inline
  7449. PVOID
  7450. ExAllocateFromPagedLookasideList(
  7451. IN PPAGED_LOOKASIDE_LIST Lookaside
  7452. )
  7453. /*++
  7454. Routine Description:
  7455. This function removes (pops) the first entry from the specified
  7456. paged lookaside list.
  7457. Arguments:
  7458. Lookaside - Supplies a pointer to a paged lookaside list structure.
  7459. Return Value:
  7460. If an entry is removed from the specified lookaside list, then the
  7461. address of the entry is returned as the function value. Otherwise,
  7462. NULL is returned.
  7463. --*/
  7464. {
  7465. PVOID Entry;
  7466. Lookaside->L.TotalAllocates += 1;
  7467. Entry = InterlockedPopEntrySList(&Lookaside->L.ListHead);
  7468. if (Entry == NULL) {
  7469. Lookaside->L.AllocateMisses += 1;
  7470. Entry = (Lookaside->L.Allocate)(Lookaside->L.Type,
  7471. Lookaside->L.Size,
  7472. Lookaside->L.Tag);
  7473. }
  7474. return Entry;
  7475. }
  7476. #endif
  7477. #if defined(_WIN2K_COMPAT_SLIST_USAGE) && defined(_X86_)
  7478. NTKERNELAPI
  7479. VOID
  7480. ExFreeToPagedLookasideList(
  7481. IN PPAGED_LOOKASIDE_LIST Lookaside,
  7482. IN PVOID Entry
  7483. );
  7484. #else
  7485. __inline
  7486. VOID
  7487. ExFreeToPagedLookasideList(
  7488. IN PPAGED_LOOKASIDE_LIST Lookaside,
  7489. IN PVOID Entry
  7490. )
  7491. /*++
  7492. Routine Description:
  7493. This function inserts (pushes) the specified entry into the specified
  7494. paged lookaside list.
  7495. Arguments:
  7496. Lookaside - Supplies a pointer to a nonpaged lookaside list structure.
  7497. Entry - Supples a pointer to the entry that is inserted in the
  7498. lookaside list.
  7499. Return Value:
  7500. None.
  7501. --*/
  7502. {
  7503. Lookaside->L.TotalFrees += 1;
  7504. if (ExQueryDepthSList(&Lookaside->L.ListHead) >= Lookaside->L.Depth) {
  7505. Lookaside->L.FreeMisses += 1;
  7506. (Lookaside->L.Free)(Entry);
  7507. } else {
  7508. InterlockedPushEntrySList(&Lookaside->L.ListHead,
  7509. (PSLIST_ENTRY)Entry);
  7510. }
  7511. return;
  7512. }
  7513. #endif
  7514. NTKERNELAPI
  7515. VOID
  7516. NTAPI
  7517. ProbeForRead(
  7518. IN CONST VOID *Address,
  7519. IN SIZE_T Length,
  7520. IN ULONG Alignment
  7521. );
  7522. //
  7523. // Common probe for write functions.
  7524. //
  7525. NTKERNELAPI
  7526. VOID
  7527. NTAPI
  7528. ProbeForWrite (
  7529. IN PVOID Address,
  7530. IN SIZE_T Length,
  7531. IN ULONG Alignment
  7532. );
  7533. //
  7534. // Worker Thread
  7535. //
  7536. typedef enum _WORK_QUEUE_TYPE {
  7537. CriticalWorkQueue,
  7538. DelayedWorkQueue,
  7539. HyperCriticalWorkQueue,
  7540. MaximumWorkQueue
  7541. } WORK_QUEUE_TYPE;
  7542. typedef
  7543. VOID
  7544. (*PWORKER_THREAD_ROUTINE)(
  7545. IN PVOID Parameter
  7546. );
  7547. typedef struct _WORK_QUEUE_ITEM {
  7548. LIST_ENTRY List;
  7549. PWORKER_THREAD_ROUTINE WorkerRoutine;
  7550. PVOID Parameter;
  7551. } WORK_QUEUE_ITEM, *PWORK_QUEUE_ITEM;
  7552. #if PRAGMA_DEPRECATED_DDK
  7553. #pragma deprecated(ExInitializeWorkItem) // Use IoAllocateWorkItem
  7554. #endif
  7555. #define ExInitializeWorkItem(Item, Routine, Context) \
  7556. (Item)->WorkerRoutine = (Routine); \
  7557. (Item)->Parameter = (Context); \
  7558. (Item)->List.Flink = NULL;
  7559. DECLSPEC_DEPRECATED_DDK // Use IoQueueWorkItem
  7560. NTKERNELAPI
  7561. VOID
  7562. ExQueueWorkItem(
  7563. IN PWORK_QUEUE_ITEM WorkItem,
  7564. IN WORK_QUEUE_TYPE QueueType
  7565. );
  7566. NTKERNELAPI
  7567. BOOLEAN
  7568. ExIsProcessorFeaturePresent(
  7569. ULONG ProcessorFeature
  7570. );
  7571. //
  7572. // Define executive resource data structures.
  7573. //
  7574. typedef ULONG_PTR ERESOURCE_THREAD;
  7575. typedef ERESOURCE_THREAD *PERESOURCE_THREAD;
  7576. typedef struct _OWNER_ENTRY {
  7577. ERESOURCE_THREAD OwnerThread;
  7578. union {
  7579. LONG OwnerCount;
  7580. ULONG TableSize;
  7581. };
  7582. } OWNER_ENTRY, *POWNER_ENTRY;
  7583. typedef struct _ERESOURCE {
  7584. LIST_ENTRY SystemResourcesList;
  7585. POWNER_ENTRY OwnerTable;
  7586. SHORT ActiveCount;
  7587. USHORT Flag;
  7588. PKSEMAPHORE SharedWaiters;
  7589. PKEVENT ExclusiveWaiters;
  7590. OWNER_ENTRY OwnerThreads[2];
  7591. ULONG ContentionCount;
  7592. USHORT NumberOfSharedWaiters;
  7593. USHORT NumberOfExclusiveWaiters;
  7594. union {
  7595. PVOID Address;
  7596. ULONG_PTR CreatorBackTraceIndex;
  7597. };
  7598. KSPIN_LOCK SpinLock;
  7599. } ERESOURCE, *PERESOURCE;
  7600. //
  7601. // Values for ERESOURCE.Flag
  7602. //
  7603. #define ResourceNeverExclusive 0x10
  7604. #define ResourceReleaseByOtherThread 0x20
  7605. #define ResourceOwnedExclusive 0x80
  7606. #define RESOURCE_HASH_TABLE_SIZE 64
  7607. typedef struct _RESOURCE_HASH_ENTRY {
  7608. LIST_ENTRY ListEntry;
  7609. PVOID Address;
  7610. ULONG ContentionCount;
  7611. ULONG Number;
  7612. } RESOURCE_HASH_ENTRY, *PRESOURCE_HASH_ENTRY;
  7613. typedef struct _RESOURCE_PERFORMANCE_DATA {
  7614. ULONG ActiveResourceCount;
  7615. ULONG TotalResourceCount;
  7616. ULONG ExclusiveAcquire;
  7617. ULONG SharedFirstLevel;
  7618. ULONG SharedSecondLevel;
  7619. ULONG StarveFirstLevel;
  7620. ULONG StarveSecondLevel;
  7621. ULONG WaitForExclusive;
  7622. ULONG OwnerTableExpands;
  7623. ULONG MaximumTableExpand;
  7624. LIST_ENTRY HashTable[RESOURCE_HASH_TABLE_SIZE];
  7625. } RESOURCE_PERFORMANCE_DATA, *PRESOURCE_PERFORMANCE_DATA;
  7626. //
  7627. // Define executive resource function prototypes.
  7628. //
  7629. NTKERNELAPI
  7630. NTSTATUS
  7631. ExInitializeResourceLite(
  7632. IN PERESOURCE Resource
  7633. );
  7634. NTKERNELAPI
  7635. NTSTATUS
  7636. ExReinitializeResourceLite(
  7637. IN PERESOURCE Resource
  7638. );
  7639. NTKERNELAPI
  7640. BOOLEAN
  7641. ExAcquireResourceSharedLite(
  7642. IN PERESOURCE Resource,
  7643. IN BOOLEAN Wait
  7644. );
  7645. NTKERNELAPI
  7646. BOOLEAN
  7647. ExAcquireResourceExclusiveLite(
  7648. IN PERESOURCE Resource,
  7649. IN BOOLEAN Wait
  7650. );
  7651. NTKERNELAPI
  7652. BOOLEAN
  7653. ExAcquireSharedStarveExclusive(
  7654. IN PERESOURCE Resource,
  7655. IN BOOLEAN Wait
  7656. );
  7657. NTKERNELAPI
  7658. BOOLEAN
  7659. ExAcquireSharedWaitForExclusive(
  7660. IN PERESOURCE Resource,
  7661. IN BOOLEAN Wait
  7662. );
  7663. NTKERNELAPI
  7664. BOOLEAN
  7665. ExTryToAcquireResourceExclusiveLite(
  7666. IN PERESOURCE Resource
  7667. );
  7668. //
  7669. // VOID
  7670. // ExReleaseResource(
  7671. // IN PERESOURCE Resource
  7672. // );
  7673. //
  7674. #if PRAGMA_DEPRECATED_DDK
  7675. #pragma deprecated(ExReleaseResource) // Use ExReleaseResourceLite
  7676. #endif
  7677. #define ExReleaseResource(R) (ExReleaseResourceLite(R))
  7678. NTKERNELAPI
  7679. VOID
  7680. FASTCALL
  7681. ExReleaseResourceLite(
  7682. IN PERESOURCE Resource
  7683. );
  7684. NTKERNELAPI
  7685. VOID
  7686. ExReleaseResourceForThreadLite(
  7687. IN PERESOURCE Resource,
  7688. IN ERESOURCE_THREAD ResourceThreadId
  7689. );
  7690. NTKERNELAPI
  7691. VOID
  7692. ExSetResourceOwnerPointer(
  7693. IN PERESOURCE Resource,
  7694. IN PVOID OwnerPointer
  7695. );
  7696. NTKERNELAPI
  7697. VOID
  7698. ExConvertExclusiveToSharedLite(
  7699. IN PERESOURCE Resource
  7700. );
  7701. NTKERNELAPI
  7702. NTSTATUS
  7703. ExDeleteResourceLite (
  7704. IN PERESOURCE Resource
  7705. );
  7706. NTKERNELAPI
  7707. ULONG
  7708. ExGetExclusiveWaiterCount (
  7709. IN PERESOURCE Resource
  7710. );
  7711. NTKERNELAPI
  7712. ULONG
  7713. ExGetSharedWaiterCount (
  7714. IN PERESOURCE Resource
  7715. );
  7716. //
  7717. // ERESOURCE_THREAD
  7718. // ExGetCurrentResourceThread(
  7719. // );
  7720. //
  7721. #define ExGetCurrentResourceThread() ((ULONG_PTR)PsGetCurrentThread())
  7722. NTKERNELAPI
  7723. BOOLEAN
  7724. ExIsResourceAcquiredExclusiveLite (
  7725. IN PERESOURCE Resource
  7726. );
  7727. NTKERNELAPI
  7728. ULONG
  7729. ExIsResourceAcquiredSharedLite (
  7730. IN PERESOURCE Resource
  7731. );
  7732. //
  7733. // An acquired resource is always owned shared, as shared ownership is a subset
  7734. // of exclusive ownership.
  7735. //
  7736. #define ExIsResourceAcquiredLite ExIsResourceAcquiredSharedLite
  7737. //
  7738. // Get previous mode
  7739. //
  7740. NTKERNELAPI
  7741. KPROCESSOR_MODE
  7742. ExGetPreviousMode(
  7743. VOID
  7744. );
  7745. //
  7746. // Raise status from kernel mode.
  7747. //
  7748. NTKERNELAPI
  7749. VOID
  7750. NTAPI
  7751. ExRaiseStatus (
  7752. IN NTSTATUS Status
  7753. );
  7754. //
  7755. // Set timer resolution.
  7756. //
  7757. NTKERNELAPI
  7758. ULONG
  7759. ExSetTimerResolution (
  7760. IN ULONG DesiredTime,
  7761. IN BOOLEAN SetResolution
  7762. );
  7763. //
  7764. // Subtract time zone bias from system time to get local time.
  7765. //
  7766. NTKERNELAPI
  7767. VOID
  7768. ExSystemTimeToLocalTime (
  7769. IN PLARGE_INTEGER SystemTime,
  7770. OUT PLARGE_INTEGER LocalTime
  7771. );
  7772. //
  7773. // Add time zone bias to local time to get system time.
  7774. //
  7775. NTKERNELAPI
  7776. VOID
  7777. ExLocalTimeToSystemTime (
  7778. IN PLARGE_INTEGER LocalTime,
  7779. OUT PLARGE_INTEGER SystemTime
  7780. );
  7781. //
  7782. // Define the type for Callback function.
  7783. //
  7784. typedef struct _CALLBACK_OBJECT *PCALLBACK_OBJECT;
  7785. typedef VOID (*PCALLBACK_FUNCTION ) (
  7786. IN PVOID CallbackContext,
  7787. IN PVOID Argument1,
  7788. IN PVOID Argument2
  7789. );
  7790. NTKERNELAPI
  7791. NTSTATUS
  7792. ExCreateCallback (
  7793. OUT PCALLBACK_OBJECT *CallbackObject,
  7794. IN POBJECT_ATTRIBUTES ObjectAttributes,
  7795. IN BOOLEAN Create,
  7796. IN BOOLEAN AllowMultipleCallbacks
  7797. );
  7798. NTKERNELAPI
  7799. PVOID
  7800. ExRegisterCallback (
  7801. IN PCALLBACK_OBJECT CallbackObject,
  7802. IN PCALLBACK_FUNCTION CallbackFunction,
  7803. IN PVOID CallbackContext
  7804. );
  7805. NTKERNELAPI
  7806. VOID
  7807. ExUnregisterCallback (
  7808. IN PVOID CallbackRegistration
  7809. );
  7810. NTKERNELAPI
  7811. VOID
  7812. ExNotifyCallback (
  7813. IN PVOID CallbackObject,
  7814. IN PVOID Argument1,
  7815. IN PVOID Argument2
  7816. );
  7817. //
  7818. // suite support
  7819. //
  7820. NTKERNELAPI
  7821. BOOLEAN
  7822. ExVerifySuite(
  7823. SUITE_TYPE SuiteType
  7824. );
  7825. //
  7826. // Define a block to hold the actual routine registration.
  7827. //
  7828. typedef NTSTATUS (*PEX_CALLBACK_FUNCTION ) (
  7829. IN PVOID CallbackContext,
  7830. IN PVOID Argument1,
  7831. IN PVOID Argument2
  7832. );
  7833. //
  7834. // Registry kernel mode callbacks
  7835. //
  7836. //
  7837. // Hook selector
  7838. //
  7839. typedef enum _REG_NOTIFY_CLASS {
  7840. RegNtDeleteKey,
  7841. RegNtPreDeleteKey = RegNtDeleteKey,
  7842. RegNtSetValueKey,
  7843. RegNtPreSetValueKey = RegNtSetValueKey,
  7844. RegNtDeleteValueKey,
  7845. RegNtPreDeleteValueKey = RegNtDeleteValueKey,
  7846. RegNtSetInformationKey,
  7847. RegNtPreSetInformationKey = RegNtSetInformationKey,
  7848. RegNtRenameKey,
  7849. RegNtPreRenameKey = RegNtRenameKey,
  7850. RegNtEnumerateKey,
  7851. RegNtPreEnumerateKey = RegNtEnumerateKey,
  7852. RegNtEnumerateValueKey,
  7853. RegNtPreEnumerateValueKey = RegNtEnumerateValueKey,
  7854. RegNtQueryKey,
  7855. RegNtPreQueryKey = RegNtQueryKey,
  7856. RegNtQueryValueKey,
  7857. RegNtPreQueryValueKey = RegNtQueryValueKey,
  7858. RegNtQueryMultipleValueKey,
  7859. RegNtPreQueryMultipleValueKey = RegNtQueryMultipleValueKey,
  7860. RegNtPreCreateKey,
  7861. RegNtPostCreateKey,
  7862. RegNtPreOpenKey,
  7863. RegNtPostOpenKey,
  7864. RegNtKeyHandleClose,
  7865. RegNtPreKeyHandleClose = RegNtKeyHandleClose,
  7866. //
  7867. // .Net only
  7868. //
  7869. RegNtPostDeleteKey,
  7870. RegNtPostSetValueKey,
  7871. RegNtPostDeleteValueKey,
  7872. RegNtPostSetInformationKey,
  7873. RegNtPostRenameKey,
  7874. RegNtPostEnumerateKey,
  7875. RegNtPostEnumerateValueKey,
  7876. RegNtPostQueryKey,
  7877. RegNtPostQueryValueKey,
  7878. RegNtPostQueryMultipleValueKey,
  7879. RegNtPostKeyHandleClose,
  7880. RegNtPreCreateKeyEx,
  7881. RegNtPostCreateKeyEx,
  7882. RegNtPreOpenKeyEx,
  7883. RegNtPostOpenKeyEx
  7884. } REG_NOTIFY_CLASS;
  7885. //
  7886. // Parameter description for each notify class
  7887. //
  7888. typedef struct _REG_DELETE_KEY_INFORMATION {
  7889. PVOID Object; // IN
  7890. } REG_DELETE_KEY_INFORMATION, *PREG_DELETE_KEY_INFORMATION;
  7891. typedef struct _REG_SET_VALUE_KEY_INFORMATION {
  7892. PVOID Object; // IN
  7893. PUNICODE_STRING ValueName; // IN
  7894. ULONG TitleIndex; // IN
  7895. ULONG Type; // IN
  7896. PVOID Data; // IN
  7897. ULONG DataSize; // IN
  7898. } REG_SET_VALUE_KEY_INFORMATION, *PREG_SET_VALUE_KEY_INFORMATION;
  7899. typedef struct _REG_DELETE_VALUE_KEY_INFORMATION {
  7900. PVOID Object; // IN
  7901. PUNICODE_STRING ValueName; // IN
  7902. } REG_DELETE_VALUE_KEY_INFORMATION, *PREG_DELETE_VALUE_KEY_INFORMATION;
  7903. typedef struct _REG_SET_INFORMATION_KEY_INFORMATION {
  7904. PVOID Object; // IN
  7905. KEY_SET_INFORMATION_CLASS KeySetInformationClass; // IN
  7906. PVOID KeySetInformation; // IN
  7907. ULONG KeySetInformationLength;// IN
  7908. } REG_SET_INFORMATION_KEY_INFORMATION, *PREG_SET_INFORMATION_KEY_INFORMATION;
  7909. typedef struct _REG_ENUMERATE_KEY_INFORMATION {
  7910. PVOID Object; // IN
  7911. ULONG Index; // IN
  7912. KEY_INFORMATION_CLASS KeyInformationClass; // IN
  7913. PVOID KeyInformation; // IN
  7914. ULONG Length; // IN
  7915. PULONG ResultLength; // OUT
  7916. } REG_ENUMERATE_KEY_INFORMATION, *PREG_ENUMERATE_KEY_INFORMATION;
  7917. typedef struct _REG_ENUMERATE_VALUE_KEY_INFORMATION {
  7918. PVOID Object; // IN
  7919. ULONG Index; // IN
  7920. KEY_VALUE_INFORMATION_CLASS KeyValueInformationClass; // IN
  7921. PVOID KeyValueInformation; // IN
  7922. ULONG Length; // IN
  7923. PULONG ResultLength; // OUT
  7924. } REG_ENUMERATE_VALUE_KEY_INFORMATION, *PREG_ENUMERATE_VALUE_KEY_INFORMATION;
  7925. typedef struct _REG_QUERY_KEY_INFORMATION {
  7926. PVOID Object; // IN
  7927. KEY_INFORMATION_CLASS KeyInformationClass; // IN
  7928. PVOID KeyInformation; // IN
  7929. ULONG Length; // IN
  7930. PULONG ResultLength; // OUT
  7931. } REG_QUERY_KEY_INFORMATION, *PREG_QUERY_KEY_INFORMATION;
  7932. typedef struct _REG_QUERY_VALUE_KEY_INFORMATION {
  7933. PVOID Object; // IN
  7934. PUNICODE_STRING ValueName; // IN
  7935. KEY_VALUE_INFORMATION_CLASS KeyValueInformationClass; // IN
  7936. PVOID KeyValueInformation; // IN
  7937. ULONG Length; // IN
  7938. PULONG ResultLength; // OUT
  7939. } REG_QUERY_VALUE_KEY_INFORMATION, *PREG_QUERY_VALUE_KEY_INFORMATION;
  7940. typedef struct _REG_QUERY_MULTIPLE_VALUE_KEY_INFORMATION {
  7941. PVOID Object; // IN
  7942. PKEY_VALUE_ENTRY ValueEntries; // IN
  7943. ULONG EntryCount; // IN
  7944. PVOID ValueBuffer; // IN
  7945. PULONG BufferLength; // IN OUT
  7946. PULONG RequiredBufferLength; // OUT
  7947. } REG_QUERY_MULTIPLE_VALUE_KEY_INFORMATION, *PREG_QUERY_MULTIPLE_VALUE_KEY_INFORMATION;
  7948. typedef struct _REG_RENAME_KEY_INFORMATION {
  7949. PVOID Object; // IN
  7950. PUNICODE_STRING NewName; // IN
  7951. } REG_RENAME_KEY_INFORMATION, *PREG_RENAME_KEY_INFORMATION;
  7952. typedef struct _REG_KEY_HANDLE_CLOSE_INFORMATION {
  7953. PVOID Object; // IN
  7954. } REG_KEY_HANDLE_CLOSE_INFORMATION, *PREG_KEY_HANDLE_CLOSE_INFORMATION;
  7955. /* .Net Only */
  7956. typedef struct _REG_CREATE_KEY_INFORMATION {
  7957. PUNICODE_STRING CompleteName; // IN
  7958. PVOID RootObject; // IN
  7959. } REG_CREATE_KEY_INFORMATION, REG_OPEN_KEY_INFORMATION,*PREG_CREATE_KEY_INFORMATION, *PREG_OPEN_KEY_INFORMATION;
  7960. typedef struct _REG_POST_OPERATION_INFORMATION {
  7961. PVOID Object; // IN
  7962. NTSTATUS Status; // IN
  7963. } REG_POST_OPERATION_INFORMATION,*PREG_POST_OPERATION_INFORMATION;
  7964. /* end .Net Only */
  7965. /* XP only */
  7966. typedef struct _REG_PRE_CREATE_KEY_INFORMATION {
  7967. PUNICODE_STRING CompleteName; // IN
  7968. } REG_PRE_CREATE_KEY_INFORMATION, REG_PRE_OPEN_KEY_INFORMATION,*PREG_PRE_CREATE_KEY_INFORMATION, *PREG_PRE_OPEN_KEY_INFORMATION;;
  7969. typedef struct _REG_POST_CREATE_KEY_INFORMATION {
  7970. PUNICODE_STRING CompleteName; // IN
  7971. PVOID Object; // IN
  7972. NTSTATUS Status; // IN
  7973. } REG_POST_CREATE_KEY_INFORMATION,REG_POST_OPEN_KEY_INFORMATION, *PREG_POST_CREATE_KEY_INFORMATION, *PREG_POST_OPEN_KEY_INFORMATION;
  7974. /* end XP only */
  7975. NTSTATUS
  7976. CmRegisterCallback(IN PEX_CALLBACK_FUNCTION Function,
  7977. IN PVOID Context,
  7978. IN OUT PLARGE_INTEGER Cookie
  7979. );
  7980. NTSTATUS
  7981. CmUnRegisterCallback(IN LARGE_INTEGER Cookie);
  7982. //
  7983. // Priority increment definitions. The comment for each definition gives
  7984. // the names of the system services that use the definition when satisfying
  7985. // a wait.
  7986. //
  7987. //
  7988. // Priority increment used when satisfying a wait on an executive event
  7989. // (NtPulseEvent and NtSetEvent)
  7990. //
  7991. #define EVENT_INCREMENT 1
  7992. //
  7993. // Priority increment when no I/O has been done. This is used by device
  7994. // and file system drivers when completing an IRP (IoCompleteRequest).
  7995. //
  7996. #define IO_NO_INCREMENT 0
  7997. //
  7998. // Priority increment for completing CD-ROM I/O. This is used by CD-ROM device
  7999. // and file system drivers when completing an IRP (IoCompleteRequest)
  8000. //
  8001. #define IO_CD_ROM_INCREMENT 1
  8002. //
  8003. // Priority increment for completing disk I/O. This is used by disk device
  8004. // and file system drivers when completing an IRP (IoCompleteRequest)
  8005. //
  8006. #define IO_DISK_INCREMENT 1
  8007. //
  8008. // Priority increment for completing keyboard I/O. This is used by keyboard
  8009. // device drivers when completing an IRP (IoCompleteRequest)
  8010. //
  8011. #define IO_KEYBOARD_INCREMENT 6
  8012. //
  8013. // Priority increment for completing mailslot I/O. This is used by the mail-
  8014. // slot file system driver when completing an IRP (IoCompleteRequest).
  8015. //
  8016. #define IO_MAILSLOT_INCREMENT 2
  8017. //
  8018. // Priority increment for completing mouse I/O. This is used by mouse device
  8019. // drivers when completing an IRP (IoCompleteRequest)
  8020. //
  8021. #define IO_MOUSE_INCREMENT 6
  8022. //
  8023. // Priority increment for completing named pipe I/O. This is used by the
  8024. // named pipe file system driver when completing an IRP (IoCompleteRequest).
  8025. //
  8026. #define IO_NAMED_PIPE_INCREMENT 2
  8027. //
  8028. // Priority increment for completing network I/O. This is used by network
  8029. // device and network file system drivers when completing an IRP
  8030. // (IoCompleteRequest).
  8031. //
  8032. #define IO_NETWORK_INCREMENT 2
  8033. //
  8034. // Priority increment for completing parallel I/O. This is used by parallel
  8035. // device drivers when completing an IRP (IoCompleteRequest)
  8036. //
  8037. #define IO_PARALLEL_INCREMENT 1
  8038. //
  8039. // Priority increment for completing serial I/O. This is used by serial device
  8040. // drivers when completing an IRP (IoCompleteRequest)
  8041. //
  8042. #define IO_SERIAL_INCREMENT 2
  8043. //
  8044. // Priority increment for completing sound I/O. This is used by sound device
  8045. // drivers when completing an IRP (IoCompleteRequest)
  8046. //
  8047. #define IO_SOUND_INCREMENT 8
  8048. //
  8049. // Priority increment for completing video I/O. This is used by video device
  8050. // drivers when completing an IRP (IoCompleteRequest)
  8051. //
  8052. #define IO_VIDEO_INCREMENT 1
  8053. //
  8054. // Priority increment used when satisfying a wait on an executive semaphore
  8055. // (NtReleaseSemaphore)
  8056. //
  8057. #define SEMAPHORE_INCREMENT 1
  8058. //
  8059. // Indicates the system may do I/O to physical addresses above 4 GB.
  8060. //
  8061. extern PBOOLEAN Mm64BitPhysicalAddress;
  8062. //
  8063. // Define maximum disk transfer size to be used by MM and Cache Manager,
  8064. // so that packet-oriented disk drivers can optimize their packet allocation
  8065. // to this size.
  8066. //
  8067. #define MM_MAXIMUM_DISK_IO_SIZE (0x10000)
  8068. //++
  8069. //
  8070. // ULONG_PTR
  8071. // ROUND_TO_PAGES (
  8072. // IN ULONG_PTR Size
  8073. // )
  8074. //
  8075. // Routine Description:
  8076. //
  8077. // The ROUND_TO_PAGES macro takes a size in bytes and rounds it up to a
  8078. // multiple of the page size.
  8079. //
  8080. // NOTE: This macro fails for values 0xFFFFFFFF - (PAGE_SIZE - 1).
  8081. //
  8082. // Arguments:
  8083. //
  8084. // Size - Size in bytes to round up to a page multiple.
  8085. //
  8086. // Return Value:
  8087. //
  8088. // Returns the size rounded up to a multiple of the page size.
  8089. //
  8090. //--
  8091. #define ROUND_TO_PAGES(Size) (((ULONG_PTR)(Size) + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1))
  8092. //++
  8093. //
  8094. // ULONG
  8095. // BYTES_TO_PAGES (
  8096. // IN ULONG Size
  8097. // )
  8098. //
  8099. // Routine Description:
  8100. //
  8101. // The BYTES_TO_PAGES macro takes the size in bytes and calculates the
  8102. // number of pages required to contain the bytes.
  8103. //
  8104. // Arguments:
  8105. //
  8106. // Size - Size in bytes.
  8107. //
  8108. // Return Value:
  8109. //
  8110. // Returns the number of pages required to contain the specified size.
  8111. //
  8112. //--
  8113. #define BYTES_TO_PAGES(Size) (((Size) >> PAGE_SHIFT) + \
  8114. (((Size) & (PAGE_SIZE - 1)) != 0))
  8115. //++
  8116. //
  8117. // ULONG
  8118. // BYTE_OFFSET (
  8119. // IN PVOID Va
  8120. // )
  8121. //
  8122. // Routine Description:
  8123. //
  8124. // The BYTE_OFFSET macro takes a virtual address and returns the byte offset
  8125. // of that address within the page.
  8126. //
  8127. // Arguments:
  8128. //
  8129. // Va - Virtual address.
  8130. //
  8131. // Return Value:
  8132. //
  8133. // Returns the byte offset portion of the virtual address.
  8134. //
  8135. //--
  8136. #define BYTE_OFFSET(Va) ((ULONG)((LONG_PTR)(Va) & (PAGE_SIZE - 1)))
  8137. //++
  8138. //
  8139. // PVOID
  8140. // PAGE_ALIGN (
  8141. // IN PVOID Va
  8142. // )
  8143. //
  8144. // Routine Description:
  8145. //
  8146. // The PAGE_ALIGN macro takes a virtual address and returns a page-aligned
  8147. // virtual address for that page.
  8148. //
  8149. // Arguments:
  8150. //
  8151. // Va - Virtual address.
  8152. //
  8153. // Return Value:
  8154. //
  8155. // Returns the page aligned virtual address.
  8156. //
  8157. //--
  8158. #define PAGE_ALIGN(Va) ((PVOID)((ULONG_PTR)(Va) & ~(PAGE_SIZE - 1)))
  8159. //++
  8160. //
  8161. // ULONG
  8162. // ADDRESS_AND_SIZE_TO_SPAN_PAGES (
  8163. // IN PVOID Va,
  8164. // IN ULONG Size
  8165. // )
  8166. //
  8167. // Routine Description:
  8168. //
  8169. // The ADDRESS_AND_SIZE_TO_SPAN_PAGES macro takes a virtual address and
  8170. // size and returns the number of pages spanned by the size.
  8171. //
  8172. // Arguments:
  8173. //
  8174. // Va - Virtual address.
  8175. //
  8176. // Size - Size in bytes.
  8177. //
  8178. // Return Value:
  8179. //
  8180. // Returns the number of pages spanned by the size.
  8181. //
  8182. //--
  8183. #define ADDRESS_AND_SIZE_TO_SPAN_PAGES(Va,Size) \
  8184. ((ULONG)((((ULONG_PTR)(Va) & (PAGE_SIZE -1)) + (Size) + (PAGE_SIZE - 1)) >> PAGE_SHIFT))
  8185. #if PRAGMA_DEPRECATED_DDK
  8186. #pragma deprecated(COMPUTE_PAGES_SPANNED) // Use ADDRESS_AND_SIZE_TO_SPAN_PAGES
  8187. #endif
  8188. #define COMPUTE_PAGES_SPANNED(Va, Size) ADDRESS_AND_SIZE_TO_SPAN_PAGES(Va,Size)
  8189. //++
  8190. // PPFN_NUMBER
  8191. // MmGetMdlPfnArray (
  8192. // IN PMDL Mdl
  8193. // )
  8194. //
  8195. // Routine Description:
  8196. //
  8197. // The MmGetMdlPfnArray routine returns the virtual address of the
  8198. // first element of the array of physical page numbers associated with
  8199. // the MDL.
  8200. //
  8201. // Arguments:
  8202. //
  8203. // Mdl - Pointer to an MDL.
  8204. //
  8205. // Return Value:
  8206. //
  8207. // Returns the virtual address of the first element of the array of
  8208. // physical page numbers associated with the MDL.
  8209. //
  8210. //--
  8211. #define MmGetMdlPfnArray(Mdl) ((PPFN_NUMBER)(Mdl + 1))
  8212. //++
  8213. //
  8214. // PVOID
  8215. // MmGetMdlVirtualAddress (
  8216. // IN PMDL Mdl
  8217. // )
  8218. //
  8219. // Routine Description:
  8220. //
  8221. // The MmGetMdlVirtualAddress returns the virtual address of the buffer
  8222. // described by the Mdl.
  8223. //
  8224. // Arguments:
  8225. //
  8226. // Mdl - Pointer to an MDL.
  8227. //
  8228. // Return Value:
  8229. //
  8230. // Returns the virtual address of the buffer described by the Mdl
  8231. //
  8232. //--
  8233. #define MmGetMdlVirtualAddress(Mdl) \
  8234. ((PVOID) ((PCHAR) ((Mdl)->StartVa) + (Mdl)->ByteOffset))
  8235. //++
  8236. //
  8237. // ULONG
  8238. // MmGetMdlByteCount (
  8239. // IN PMDL Mdl
  8240. // )
  8241. //
  8242. // Routine Description:
  8243. //
  8244. // The MmGetMdlByteCount returns the length in bytes of the buffer
  8245. // described by the Mdl.
  8246. //
  8247. // Arguments:
  8248. //
  8249. // Mdl - Pointer to an MDL.
  8250. //
  8251. // Return Value:
  8252. //
  8253. // Returns the byte count of the buffer described by the Mdl
  8254. //
  8255. //--
  8256. #define MmGetMdlByteCount(Mdl) ((Mdl)->ByteCount)
  8257. //++
  8258. //
  8259. // ULONG
  8260. // MmGetMdlByteOffset (
  8261. // IN PMDL Mdl
  8262. // )
  8263. //
  8264. // Routine Description:
  8265. //
  8266. // The MmGetMdlByteOffset returns the byte offset within the page
  8267. // of the buffer described by the Mdl.
  8268. //
  8269. // Arguments:
  8270. //
  8271. // Mdl - Pointer to an MDL.
  8272. //
  8273. // Return Value:
  8274. //
  8275. // Returns the byte offset within the page of the buffer described by the Mdl
  8276. //
  8277. //--
  8278. #define MmGetMdlByteOffset(Mdl) ((Mdl)->ByteOffset)
  8279. //++
  8280. //
  8281. // PVOID
  8282. // MmGetMdlStartVa (
  8283. // IN PMDL Mdl
  8284. // )
  8285. //
  8286. // Routine Description:
  8287. //
  8288. // The MmGetMdlBaseVa returns the virtual address of the buffer
  8289. // described by the Mdl rounded down to the nearest page.
  8290. //
  8291. // Arguments:
  8292. //
  8293. // Mdl - Pointer to an MDL.
  8294. //
  8295. // Return Value:
  8296. //
  8297. // Returns the returns the starting virtual address of the MDL.
  8298. //
  8299. //
  8300. //--
  8301. #define MmGetMdlBaseVa(Mdl) ((Mdl)->StartVa)
  8302. typedef enum _MM_SYSTEM_SIZE {
  8303. MmSmallSystem,
  8304. MmMediumSystem,
  8305. MmLargeSystem
  8306. } MM_SYSTEMSIZE;
  8307. NTKERNELAPI
  8308. MM_SYSTEMSIZE
  8309. MmQuerySystemSize (
  8310. VOID
  8311. );
  8312. NTSTATUS
  8313. MmIsVerifierEnabled (
  8314. OUT PULONG VerifierFlags
  8315. );
  8316. NTSTATUS
  8317. MmAddVerifierThunks (
  8318. IN PVOID ThunkBuffer,
  8319. IN ULONG ThunkBufferSize
  8320. );
  8321. NTKERNELAPI
  8322. VOID
  8323. MmProbeAndLockProcessPages (
  8324. IN OUT PMDL MemoryDescriptorList,
  8325. IN PEPROCESS Process,
  8326. IN KPROCESSOR_MODE AccessMode,
  8327. IN LOCK_OPERATION Operation
  8328. );
  8329. //
  8330. // I/O support routines.
  8331. //
  8332. NTKERNELAPI
  8333. VOID
  8334. MmProbeAndLockPages (
  8335. IN OUT PMDL MemoryDescriptorList,
  8336. IN KPROCESSOR_MODE AccessMode,
  8337. IN LOCK_OPERATION Operation
  8338. );
  8339. NTKERNELAPI
  8340. VOID
  8341. MmUnlockPages (
  8342. IN PMDL MemoryDescriptorList
  8343. );
  8344. NTKERNELAPI
  8345. VOID
  8346. MmBuildMdlForNonPagedPool (
  8347. IN OUT PMDL MemoryDescriptorList
  8348. );
  8349. NTKERNELAPI
  8350. PVOID
  8351. MmMapLockedPages (
  8352. IN PMDL MemoryDescriptorList,
  8353. IN KPROCESSOR_MODE AccessMode
  8354. );
  8355. LOGICAL
  8356. MmIsIoSpaceActive (
  8357. IN PHYSICAL_ADDRESS StartAddress,
  8358. IN SIZE_T NumberOfBytes
  8359. );
  8360. NTKERNELAPI
  8361. PVOID
  8362. MmGetSystemRoutineAddress (
  8363. IN PUNICODE_STRING SystemRoutineName
  8364. );
  8365. NTKERNELAPI
  8366. NTSTATUS
  8367. MmAdvanceMdl (
  8368. IN PMDL Mdl,
  8369. IN ULONG NumberOfBytes
  8370. );
  8371. NTKERNELAPI
  8372. NTSTATUS
  8373. MmProtectMdlSystemAddress (
  8374. IN PMDL MemoryDescriptorList,
  8375. IN ULONG NewProtect
  8376. );
  8377. //
  8378. // _MM_PAGE_PRIORITY_ provides a method for the system to handle requests
  8379. // intelligently in low resource conditions.
  8380. //
  8381. // LowPagePriority should be used when it is acceptable to the driver for the
  8382. // mapping request to fail if the system is low on resources. An example of
  8383. // this could be for a non-critical network connection where the driver can
  8384. // handle the failure case when system resources are close to being depleted.
  8385. //
  8386. // NormalPagePriority should be used when it is acceptable to the driver for the
  8387. // mapping request to fail if the system is very low on resources. An example
  8388. // of this could be for a non-critical local filesystem request.
  8389. //
  8390. // HighPagePriority should be used when it is unacceptable to the driver for the
  8391. // mapping request to fail unless the system is completely out of resources.
  8392. // An example of this would be the paging file path in a driver.
  8393. //
  8394. typedef enum _MM_PAGE_PRIORITY {
  8395. LowPagePriority,
  8396. NormalPagePriority = 16,
  8397. HighPagePriority = 32
  8398. } MM_PAGE_PRIORITY;
  8399. //
  8400. // Note: This function is not available in WDM 1.0
  8401. //
  8402. NTKERNELAPI
  8403. PVOID
  8404. MmMapLockedPagesSpecifyCache (
  8405. IN PMDL MemoryDescriptorList,
  8406. IN KPROCESSOR_MODE AccessMode,
  8407. IN MEMORY_CACHING_TYPE CacheType,
  8408. IN PVOID BaseAddress,
  8409. IN ULONG BugCheckOnFailure,
  8410. IN MM_PAGE_PRIORITY Priority
  8411. );
  8412. NTKERNELAPI
  8413. VOID
  8414. MmUnmapLockedPages (
  8415. IN PVOID BaseAddress,
  8416. IN PMDL MemoryDescriptorList
  8417. );
  8418. PVOID
  8419. MmAllocateMappingAddress (
  8420. IN SIZE_T NumberOfBytes,
  8421. IN ULONG PoolTag
  8422. );
  8423. VOID
  8424. MmFreeMappingAddress (
  8425. IN PVOID BaseAddress,
  8426. IN ULONG PoolTag
  8427. );
  8428. PVOID
  8429. MmMapLockedPagesWithReservedMapping (
  8430. IN PVOID MappingAddress,
  8431. IN ULONG PoolTag,
  8432. IN PMDL MemoryDescriptorList,
  8433. IN MEMORY_CACHING_TYPE CacheType
  8434. );
  8435. VOID
  8436. MmUnmapReservedMapping (
  8437. IN PVOID BaseAddress,
  8438. IN ULONG PoolTag,
  8439. IN PMDL MemoryDescriptorList
  8440. );
  8441. NTKERNELAPI
  8442. PMDL
  8443. MmAllocatePagesForMdl (
  8444. IN PHYSICAL_ADDRESS LowAddress,
  8445. IN PHYSICAL_ADDRESS HighAddress,
  8446. IN PHYSICAL_ADDRESS SkipBytes,
  8447. IN SIZE_T TotalBytes
  8448. );
  8449. NTKERNELAPI
  8450. VOID
  8451. MmFreePagesFromMdl (
  8452. IN PMDL MemoryDescriptorList
  8453. );
  8454. NTKERNELAPI
  8455. PVOID
  8456. MmMapIoSpace (
  8457. IN PHYSICAL_ADDRESS PhysicalAddress,
  8458. IN SIZE_T NumberOfBytes,
  8459. IN MEMORY_CACHING_TYPE CacheType
  8460. );
  8461. NTKERNELAPI
  8462. VOID
  8463. MmUnmapIoSpace (
  8464. IN PVOID BaseAddress,
  8465. IN SIZE_T NumberOfBytes
  8466. );
  8467. NTKERNELAPI
  8468. SIZE_T
  8469. MmSizeOfMdl (
  8470. IN PVOID Base,
  8471. IN SIZE_T Length
  8472. );
  8473. DECLSPEC_DEPRECATED_DDK // Use IoAllocateMdl
  8474. NTKERNELAPI
  8475. PMDL
  8476. MmCreateMdl (
  8477. IN PMDL MemoryDescriptorList OPTIONAL,
  8478. IN PVOID Base,
  8479. IN SIZE_T Length
  8480. );
  8481. NTKERNELAPI
  8482. PVOID
  8483. MmLockPagableDataSection (
  8484. IN PVOID AddressWithinSection
  8485. );
  8486. NTKERNELAPI
  8487. VOID
  8488. MmResetDriverPaging (
  8489. IN PVOID AddressWithinSection
  8490. );
  8491. NTKERNELAPI
  8492. PVOID
  8493. MmPageEntireDriver (
  8494. IN PVOID AddressWithinSection
  8495. );
  8496. NTKERNELAPI
  8497. VOID
  8498. MmUnlockPagableImageSection(
  8499. IN PVOID ImageSectionHandle
  8500. );
  8501. //++
  8502. //
  8503. // VOID
  8504. // MmInitializeMdl (
  8505. // IN PMDL MemoryDescriptorList,
  8506. // IN PVOID BaseVa,
  8507. // IN SIZE_T Length
  8508. // )
  8509. //
  8510. // Routine Description:
  8511. //
  8512. // This routine initializes the header of a Memory Descriptor List (MDL).
  8513. //
  8514. // Arguments:
  8515. //
  8516. // MemoryDescriptorList - Pointer to the MDL to initialize.
  8517. //
  8518. // BaseVa - Base virtual address mapped by the MDL.
  8519. //
  8520. // Length - Length, in bytes, of the buffer mapped by the MDL.
  8521. //
  8522. // Return Value:
  8523. //
  8524. // None.
  8525. //
  8526. //--
  8527. #define MmInitializeMdl(MemoryDescriptorList, BaseVa, Length) { \
  8528. (MemoryDescriptorList)->Next = (PMDL) NULL; \
  8529. (MemoryDescriptorList)->Size = (CSHORT)(sizeof(MDL) + \
  8530. (sizeof(PFN_NUMBER) * ADDRESS_AND_SIZE_TO_SPAN_PAGES((BaseVa), (Length)))); \
  8531. (MemoryDescriptorList)->MdlFlags = 0; \
  8532. (MemoryDescriptorList)->StartVa = (PVOID) PAGE_ALIGN((BaseVa)); \
  8533. (MemoryDescriptorList)->ByteOffset = BYTE_OFFSET((BaseVa)); \
  8534. (MemoryDescriptorList)->ByteCount = (ULONG)(Length); \
  8535. }
  8536. //++
  8537. //
  8538. // PVOID
  8539. // MmGetSystemAddressForMdlSafe (
  8540. // IN PMDL MDL,
  8541. // IN MM_PAGE_PRIORITY PRIORITY
  8542. // )
  8543. //
  8544. // Routine Description:
  8545. //
  8546. // This routine returns the mapped address of an MDL. If the
  8547. // Mdl is not already mapped or a system address, it is mapped.
  8548. //
  8549. // Arguments:
  8550. //
  8551. // MemoryDescriptorList - Pointer to the MDL to map.
  8552. //
  8553. // Priority - Supplies an indication as to how important it is that this
  8554. // request succeed under low available PTE conditions.
  8555. //
  8556. // Return Value:
  8557. //
  8558. // Returns the base address where the pages are mapped. The base address
  8559. // has the same offset as the virtual address in the MDL.
  8560. //
  8561. // Unlike MmGetSystemAddressForMdl, Safe guarantees that it will always
  8562. // return NULL on failure instead of bugchecking the system.
  8563. //
  8564. // This macro is not usable by WDM 1.0 drivers as 1.0 did not include
  8565. // MmMapLockedPagesSpecifyCache. The solution for WDM 1.0 drivers is to
  8566. // provide synchronization and set/reset the MDL_MAPPING_CAN_FAIL bit.
  8567. //
  8568. //--
  8569. #define MmGetSystemAddressForMdlSafe(MDL, PRIORITY) \
  8570. (((MDL)->MdlFlags & (MDL_MAPPED_TO_SYSTEM_VA | \
  8571. MDL_SOURCE_IS_NONPAGED_POOL)) ? \
  8572. ((MDL)->MappedSystemVa) : \
  8573. (MmMapLockedPagesSpecifyCache((MDL), \
  8574. KernelMode, \
  8575. MmCached, \
  8576. NULL, \
  8577. FALSE, \
  8578. (PRIORITY))))
  8579. //++
  8580. //
  8581. // PVOID
  8582. // MmGetSystemAddressForMdl (
  8583. // IN PMDL MDL
  8584. // )
  8585. //
  8586. // Routine Description:
  8587. //
  8588. // This routine returns the mapped address of an MDL, if the
  8589. // Mdl is not already mapped or a system address, it is mapped.
  8590. //
  8591. // Arguments:
  8592. //
  8593. // MemoryDescriptorList - Pointer to the MDL to map.
  8594. //
  8595. // Return Value:
  8596. //
  8597. // Returns the base address where the pages are mapped. The base address
  8598. // has the same offset as the virtual address in the MDL.
  8599. //
  8600. //--
  8601. //#define MmGetSystemAddressForMdl(MDL)
  8602. // (((MDL)->MdlFlags & (MDL_MAPPED_TO_SYSTEM_VA)) ?
  8603. // ((MDL)->MappedSystemVa) :
  8604. // ((((MDL)->MdlFlags & (MDL_SOURCE_IS_NONPAGED_POOL)) ?
  8605. // ((PVOID)((ULONG)(MDL)->StartVa | (MDL)->ByteOffset)) :
  8606. // (MmMapLockedPages((MDL),KernelMode)))))
  8607. #if PRAGMA_DEPRECATED_DDK
  8608. #pragma deprecated(MmGetSystemAddressForMdl) // Use MmGetSystemAddressForMdlSafe
  8609. #endif
  8610. #define MmGetSystemAddressForMdl(MDL) \
  8611. (((MDL)->MdlFlags & (MDL_MAPPED_TO_SYSTEM_VA | \
  8612. MDL_SOURCE_IS_NONPAGED_POOL)) ? \
  8613. ((MDL)->MappedSystemVa) : \
  8614. (MmMapLockedPages((MDL),KernelMode)))
  8615. //++
  8616. //
  8617. // VOID
  8618. // MmPrepareMdlForReuse (
  8619. // IN PMDL MDL
  8620. // )
  8621. //
  8622. // Routine Description:
  8623. //
  8624. // This routine will take all of the steps necessary to allow an MDL to be
  8625. // re-used.
  8626. //
  8627. // Arguments:
  8628. //
  8629. // MemoryDescriptorList - Pointer to the MDL that will be re-used.
  8630. //
  8631. // Return Value:
  8632. //
  8633. // None.
  8634. //
  8635. //--
  8636. #define MmPrepareMdlForReuse(MDL) \
  8637. if (((MDL)->MdlFlags & MDL_PARTIAL_HAS_BEEN_MAPPED) != 0) { \
  8638. ASSERT(((MDL)->MdlFlags & MDL_PARTIAL) != 0); \
  8639. MmUnmapLockedPages( (MDL)->MappedSystemVa, (MDL) ); \
  8640. } else if (((MDL)->MdlFlags & MDL_PARTIAL) == 0) { \
  8641. ASSERT(((MDL)->MdlFlags & MDL_MAPPED_TO_SYSTEM_VA) == 0); \
  8642. }
  8643. typedef NTSTATUS (*PMM_DLL_INITIALIZE)(
  8644. IN PUNICODE_STRING RegistryPath
  8645. );
  8646. typedef NTSTATUS (*PMM_DLL_UNLOAD)(
  8647. VOID
  8648. );
  8649. //
  8650. // Define an empty typedef for the _DRIVER_OBJECT structure so it may be
  8651. // referenced by function types before it is actually defined.
  8652. //
  8653. struct _DRIVER_OBJECT;
  8654. NTKERNELAPI
  8655. LOGICAL
  8656. MmIsDriverVerifying (
  8657. IN struct _DRIVER_OBJECT *DriverObject
  8658. );
  8659. //
  8660. // Security operation codes
  8661. //
  8662. typedef enum _SECURITY_OPERATION_CODE {
  8663. SetSecurityDescriptor,
  8664. QuerySecurityDescriptor,
  8665. DeleteSecurityDescriptor,
  8666. AssignSecurityDescriptor
  8667. } SECURITY_OPERATION_CODE, *PSECURITY_OPERATION_CODE;
  8668. //
  8669. // Data structure used to capture subject security context
  8670. // for access validations and auditing.
  8671. //
  8672. // THE FIELDS OF THIS DATA STRUCTURE SHOULD BE CONSIDERED OPAQUE
  8673. // BY ALL EXCEPT THE SECURITY ROUTINES.
  8674. //
  8675. typedef struct _SECURITY_SUBJECT_CONTEXT {
  8676. PACCESS_TOKEN ClientToken;
  8677. SECURITY_IMPERSONATION_LEVEL ImpersonationLevel;
  8678. PACCESS_TOKEN PrimaryToken;
  8679. PVOID ProcessAuditId;
  8680. } SECURITY_SUBJECT_CONTEXT, *PSECURITY_SUBJECT_CONTEXT;
  8681. ///////////////////////////////////////////////////////////////////////////////
  8682. // //
  8683. // ACCESS_STATE and related structures //
  8684. // //
  8685. ///////////////////////////////////////////////////////////////////////////////
  8686. //
  8687. // Initial Privilege Set - Room for three privileges, which should
  8688. // be enough for most applications. This structure exists so that
  8689. // it can be imbedded in an ACCESS_STATE structure. Use PRIVILEGE_SET
  8690. // for all other references to Privilege sets.
  8691. //
  8692. #define INITIAL_PRIVILEGE_COUNT 3
  8693. typedef struct _INITIAL_PRIVILEGE_SET {
  8694. ULONG PrivilegeCount;
  8695. ULONG Control;
  8696. LUID_AND_ATTRIBUTES Privilege[INITIAL_PRIVILEGE_COUNT];
  8697. } INITIAL_PRIVILEGE_SET, * PINITIAL_PRIVILEGE_SET;
  8698. //
  8699. // Combine the information that describes the state
  8700. // of an access-in-progress into a single structure
  8701. //
  8702. typedef struct _ACCESS_STATE {
  8703. LUID OperationID;
  8704. BOOLEAN SecurityEvaluated;
  8705. BOOLEAN GenerateAudit;
  8706. BOOLEAN GenerateOnClose;
  8707. BOOLEAN PrivilegesAllocated;
  8708. ULONG Flags;
  8709. ACCESS_MASK RemainingDesiredAccess;
  8710. ACCESS_MASK PreviouslyGrantedAccess;
  8711. ACCESS_MASK OriginalDesiredAccess;
  8712. SECURITY_SUBJECT_CONTEXT SubjectSecurityContext;
  8713. PSECURITY_DESCRIPTOR SecurityDescriptor;
  8714. PVOID AuxData;
  8715. union {
  8716. INITIAL_PRIVILEGE_SET InitialPrivilegeSet;
  8717. PRIVILEGE_SET PrivilegeSet;
  8718. } Privileges;
  8719. BOOLEAN AuditPrivileges;
  8720. UNICODE_STRING ObjectName;
  8721. UNICODE_STRING ObjectTypeName;
  8722. } ACCESS_STATE, *PACCESS_STATE;
  8723. NTKERNELAPI
  8724. NTSTATUS
  8725. SeAssignSecurity (
  8726. IN PSECURITY_DESCRIPTOR ParentDescriptor OPTIONAL,
  8727. IN PSECURITY_DESCRIPTOR ExplicitDescriptor,
  8728. OUT PSECURITY_DESCRIPTOR *NewDescriptor,
  8729. IN BOOLEAN IsDirectoryObject,
  8730. IN PSECURITY_SUBJECT_CONTEXT SubjectContext,
  8731. IN PGENERIC_MAPPING GenericMapping,
  8732. IN POOL_TYPE PoolType
  8733. );
  8734. NTKERNELAPI
  8735. NTSTATUS
  8736. SeAssignSecurityEx (
  8737. IN PSECURITY_DESCRIPTOR ParentDescriptor OPTIONAL,
  8738. IN PSECURITY_DESCRIPTOR ExplicitDescriptor OPTIONAL,
  8739. OUT PSECURITY_DESCRIPTOR *NewDescriptor,
  8740. IN GUID *ObjectType OPTIONAL,
  8741. IN BOOLEAN IsDirectoryObject,
  8742. IN ULONG AutoInheritFlags,
  8743. IN PSECURITY_SUBJECT_CONTEXT SubjectContext,
  8744. IN PGENERIC_MAPPING GenericMapping,
  8745. IN POOL_TYPE PoolType
  8746. );
  8747. NTKERNELAPI
  8748. NTSTATUS
  8749. SeDeassignSecurity (
  8750. IN OUT PSECURITY_DESCRIPTOR *SecurityDescriptor
  8751. );
  8752. NTKERNELAPI
  8753. BOOLEAN
  8754. SeAccessCheck (
  8755. IN PSECURITY_DESCRIPTOR SecurityDescriptor,
  8756. IN PSECURITY_SUBJECT_CONTEXT SubjectSecurityContext,
  8757. IN BOOLEAN SubjectContextLocked,
  8758. IN ACCESS_MASK DesiredAccess,
  8759. IN ACCESS_MASK PreviouslyGrantedAccess,
  8760. OUT PPRIVILEGE_SET *Privileges OPTIONAL,
  8761. IN PGENERIC_MAPPING GenericMapping,
  8762. IN KPROCESSOR_MODE AccessMode,
  8763. OUT PACCESS_MASK GrantedAccess,
  8764. OUT PNTSTATUS AccessStatus
  8765. );
  8766. #ifdef SE_NTFS_WORLD_CACHE
  8767. VOID
  8768. SeGetWorldRights (
  8769. IN PSECURITY_DESCRIPTOR SecurityDescriptor,
  8770. IN PGENERIC_MAPPING GenericMapping,
  8771. OUT PACCESS_MASK GrantedAccess
  8772. );
  8773. #endif
  8774. NTKERNELAPI
  8775. BOOLEAN
  8776. SeValidSecurityDescriptor(
  8777. IN ULONG Length,
  8778. IN PSECURITY_DESCRIPTOR SecurityDescriptor
  8779. );
  8780. //
  8781. // System Thread and Process Creation and Termination
  8782. //
  8783. NTKERNELAPI
  8784. NTSTATUS
  8785. PsCreateSystemThread(
  8786. OUT PHANDLE ThreadHandle,
  8787. IN ULONG DesiredAccess,
  8788. IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL,
  8789. IN HANDLE ProcessHandle OPTIONAL,
  8790. OUT PCLIENT_ID ClientId OPTIONAL,
  8791. IN PKSTART_ROUTINE StartRoutine,
  8792. IN PVOID StartContext
  8793. );
  8794. NTKERNELAPI
  8795. NTSTATUS
  8796. PsTerminateSystemThread(
  8797. IN NTSTATUS ExitStatus
  8798. );
  8799. //
  8800. // Define I/O system data structure type codes. Each major data structure in
  8801. // the I/O system has a type code The type field in each structure is at the
  8802. // same offset. The following values can be used to determine which type of
  8803. // data structure a pointer refers to.
  8804. //
  8805. #define IO_TYPE_ADAPTER 0x00000001
  8806. #define IO_TYPE_CONTROLLER 0x00000002
  8807. #define IO_TYPE_DEVICE 0x00000003
  8808. #define IO_TYPE_DRIVER 0x00000004
  8809. #define IO_TYPE_FILE 0x00000005
  8810. #define IO_TYPE_IRP 0x00000006
  8811. #define IO_TYPE_MASTER_ADAPTER 0x00000007
  8812. #define IO_TYPE_OPEN_PACKET 0x00000008
  8813. #define IO_TYPE_TIMER 0x00000009
  8814. #define IO_TYPE_VPB 0x0000000a
  8815. #define IO_TYPE_ERROR_LOG 0x0000000b
  8816. #define IO_TYPE_ERROR_MESSAGE 0x0000000c
  8817. #define IO_TYPE_DEVICE_OBJECT_EXTENSION 0x0000000d
  8818. //
  8819. // Define the major function codes for IRPs.
  8820. //
  8821. #define IRP_MJ_CREATE 0x00
  8822. #define IRP_MJ_CREATE_NAMED_PIPE 0x01
  8823. #define IRP_MJ_CLOSE 0x02
  8824. #define IRP_MJ_READ 0x03
  8825. #define IRP_MJ_WRITE 0x04
  8826. #define IRP_MJ_QUERY_INFORMATION 0x05
  8827. #define IRP_MJ_SET_INFORMATION 0x06
  8828. #define IRP_MJ_QUERY_EA 0x07
  8829. #define IRP_MJ_SET_EA 0x08
  8830. #define IRP_MJ_FLUSH_BUFFERS 0x09
  8831. #define IRP_MJ_QUERY_VOLUME_INFORMATION 0x0a
  8832. #define IRP_MJ_SET_VOLUME_INFORMATION 0x0b
  8833. #define IRP_MJ_DIRECTORY_CONTROL 0x0c
  8834. #define IRP_MJ_FILE_SYSTEM_CONTROL 0x0d
  8835. #define IRP_MJ_DEVICE_CONTROL 0x0e
  8836. #define IRP_MJ_INTERNAL_DEVICE_CONTROL 0x0f
  8837. #define IRP_MJ_SHUTDOWN 0x10
  8838. #define IRP_MJ_LOCK_CONTROL 0x11
  8839. #define IRP_MJ_CLEANUP 0x12
  8840. #define IRP_MJ_CREATE_MAILSLOT 0x13
  8841. #define IRP_MJ_QUERY_SECURITY 0x14
  8842. #define IRP_MJ_SET_SECURITY 0x15
  8843. #define IRP_MJ_POWER 0x16
  8844. #define IRP_MJ_SYSTEM_CONTROL 0x17
  8845. #define IRP_MJ_DEVICE_CHANGE 0x18
  8846. #define IRP_MJ_QUERY_QUOTA 0x19
  8847. #define IRP_MJ_SET_QUOTA 0x1a
  8848. #define IRP_MJ_PNP 0x1b
  8849. #define IRP_MJ_PNP_POWER IRP_MJ_PNP // Obsolete....
  8850. #define IRP_MJ_MAXIMUM_FUNCTION 0x1b
  8851. //
  8852. // Make the Scsi major code the same as internal device control.
  8853. //
  8854. #define IRP_MJ_SCSI IRP_MJ_INTERNAL_DEVICE_CONTROL
  8855. //
  8856. // Define the minor function codes for IRPs. The lower 128 codes, from 0x00 to
  8857. // 0x7f are reserved to Microsoft. The upper 128 codes, from 0x80 to 0xff, are
  8858. // reserved to customers of Microsoft.
  8859. //
  8860. //
  8861. // Device Control Request minor function codes for SCSI support. Note that
  8862. // user requests are assumed to be zero.
  8863. //
  8864. #define IRP_MN_SCSI_CLASS 0x01
  8865. //
  8866. // PNP minor function codes.
  8867. //
  8868. #define IRP_MN_START_DEVICE 0x00
  8869. #define IRP_MN_QUERY_REMOVE_DEVICE 0x01
  8870. #define IRP_MN_REMOVE_DEVICE 0x02
  8871. #define IRP_MN_CANCEL_REMOVE_DEVICE 0x03
  8872. #define IRP_MN_STOP_DEVICE 0x04
  8873. #define IRP_MN_QUERY_STOP_DEVICE 0x05
  8874. #define IRP_MN_CANCEL_STOP_DEVICE 0x06
  8875. #define IRP_MN_QUERY_DEVICE_RELATIONS 0x07
  8876. #define IRP_MN_QUERY_INTERFACE 0x08
  8877. #define IRP_MN_QUERY_CAPABILITIES 0x09
  8878. #define IRP_MN_QUERY_RESOURCES 0x0A
  8879. #define IRP_MN_QUERY_RESOURCE_REQUIREMENTS 0x0B
  8880. #define IRP_MN_QUERY_DEVICE_TEXT 0x0C
  8881. #define IRP_MN_FILTER_RESOURCE_REQUIREMENTS 0x0D
  8882. #define IRP_MN_READ_CONFIG 0x0F
  8883. #define IRP_MN_WRITE_CONFIG 0x10
  8884. #define IRP_MN_EJECT 0x11
  8885. #define IRP_MN_SET_LOCK 0x12
  8886. #define IRP_MN_QUERY_ID 0x13
  8887. #define IRP_MN_QUERY_PNP_DEVICE_STATE 0x14
  8888. #define IRP_MN_QUERY_BUS_INFORMATION 0x15
  8889. #define IRP_MN_DEVICE_USAGE_NOTIFICATION 0x16
  8890. #define IRP_MN_SURPRISE_REMOVAL 0x17
  8891. //
  8892. // POWER minor function codes
  8893. //
  8894. #define IRP_MN_WAIT_WAKE 0x00
  8895. #define IRP_MN_POWER_SEQUENCE 0x01
  8896. #define IRP_MN_SET_POWER 0x02
  8897. #define IRP_MN_QUERY_POWER 0x03
  8898. //
  8899. // WMI minor function codes under IRP_MJ_SYSTEM_CONTROL
  8900. //
  8901. #define IRP_MN_QUERY_ALL_DATA 0x00
  8902. #define IRP_MN_QUERY_SINGLE_INSTANCE 0x01
  8903. #define IRP_MN_CHANGE_SINGLE_INSTANCE 0x02
  8904. #define IRP_MN_CHANGE_SINGLE_ITEM 0x03
  8905. #define IRP_MN_ENABLE_EVENTS 0x04
  8906. #define IRP_MN_DISABLE_EVENTS 0x05
  8907. #define IRP_MN_ENABLE_COLLECTION 0x06
  8908. #define IRP_MN_DISABLE_COLLECTION 0x07
  8909. #define IRP_MN_REGINFO 0x08
  8910. #define IRP_MN_EXECUTE_METHOD 0x09
  8911. // Minor code 0x0a is reserved
  8912. #define IRP_MN_REGINFO_EX 0x0b
  8913. //
  8914. // Define option flags for IoCreateFile. Note that these values must be
  8915. // exactly the same as the SL_... flags for a create function. Note also
  8916. // that there are flags that may be passed to IoCreateFile that are not
  8917. // placed in the stack location for the create IRP. These flags start in
  8918. // the next byte.
  8919. //
  8920. #define IO_FORCE_ACCESS_CHECK 0x0001
  8921. #define IO_NO_PARAMETER_CHECKING 0x0100
  8922. //
  8923. // Define Information fields for whether or not a REPARSE or a REMOUNT has
  8924. // occurred in the file system.
  8925. //
  8926. #define IO_REPARSE 0x0
  8927. #define IO_REMOUNT 0x1
  8928. //
  8929. // Define the objects that can be created by IoCreateFile.
  8930. //
  8931. typedef enum _CREATE_FILE_TYPE {
  8932. CreateFileTypeNone,
  8933. CreateFileTypeNamedPipe,
  8934. CreateFileTypeMailslot
  8935. } CREATE_FILE_TYPE;
  8936. //
  8937. // Define the structures used by the I/O system
  8938. //
  8939. //
  8940. // Define empty typedefs for the _IRP, _DEVICE_OBJECT, and _DRIVER_OBJECT
  8941. // structures so they may be referenced by function types before they are
  8942. // actually defined.
  8943. //
  8944. struct _DEVICE_DESCRIPTION;
  8945. struct _DEVICE_OBJECT;
  8946. struct _DMA_ADAPTER;
  8947. struct _DRIVER_OBJECT;
  8948. struct _DRIVE_LAYOUT_INFORMATION;
  8949. struct _DISK_PARTITION;
  8950. struct _FILE_OBJECT;
  8951. struct DECLSPEC_ALIGN(MEMORY_ALLOCATION_ALIGNMENT) _IRP;
  8952. struct _SCSI_REQUEST_BLOCK;
  8953. struct _SCATTER_GATHER_LIST;
  8954. //
  8955. // Define the I/O version of a DPC routine.
  8956. //
  8957. typedef
  8958. VOID
  8959. (*PIO_DPC_ROUTINE) (
  8960. IN PKDPC Dpc,
  8961. IN struct _DEVICE_OBJECT *DeviceObject,
  8962. IN struct _IRP *Irp,
  8963. IN PVOID Context
  8964. );
  8965. //
  8966. // Define driver timer routine type.
  8967. //
  8968. typedef
  8969. VOID
  8970. (*PIO_TIMER_ROUTINE) (
  8971. IN struct _DEVICE_OBJECT *DeviceObject,
  8972. IN PVOID Context
  8973. );
  8974. //
  8975. // Define driver initialization routine type.
  8976. //
  8977. typedef
  8978. NTSTATUS
  8979. (*PDRIVER_INITIALIZE) (
  8980. IN struct _DRIVER_OBJECT *DriverObject,
  8981. IN PUNICODE_STRING RegistryPath
  8982. );
  8983. //
  8984. // Define driver cancel routine type.
  8985. //
  8986. typedef
  8987. VOID
  8988. (*PDRIVER_CANCEL) (
  8989. IN struct _DEVICE_OBJECT *DeviceObject,
  8990. IN struct _IRP *Irp
  8991. );
  8992. //
  8993. // Define driver dispatch routine type.
  8994. //
  8995. typedef
  8996. NTSTATUS
  8997. (*PDRIVER_DISPATCH) (
  8998. IN struct _DEVICE_OBJECT *DeviceObject,
  8999. IN struct _IRP *Irp
  9000. );
  9001. //
  9002. // Define driver start I/O routine type.
  9003. //
  9004. typedef
  9005. VOID
  9006. (*PDRIVER_STARTIO) (
  9007. IN struct _DEVICE_OBJECT *DeviceObject,
  9008. IN struct _IRP *Irp
  9009. );
  9010. //
  9011. // Define driver unload routine type.
  9012. //
  9013. typedef
  9014. VOID
  9015. (*PDRIVER_UNLOAD) (
  9016. IN struct _DRIVER_OBJECT *DriverObject
  9017. );
  9018. //
  9019. // Define driver AddDevice routine type.
  9020. //
  9021. typedef
  9022. NTSTATUS
  9023. (*PDRIVER_ADD_DEVICE) (
  9024. IN struct _DRIVER_OBJECT *DriverObject,
  9025. IN struct _DEVICE_OBJECT *PhysicalDeviceObject
  9026. );
  9027. //
  9028. // Define fast I/O procedure prototypes.
  9029. //
  9030. // Fast I/O read and write procedures.
  9031. //
  9032. typedef
  9033. BOOLEAN
  9034. (*PFAST_IO_CHECK_IF_POSSIBLE) (
  9035. IN struct _FILE_OBJECT *FileObject,
  9036. IN PLARGE_INTEGER FileOffset,
  9037. IN ULONG Length,
  9038. IN BOOLEAN Wait,
  9039. IN ULONG LockKey,
  9040. IN BOOLEAN CheckForReadOperation,
  9041. OUT PIO_STATUS_BLOCK IoStatus,
  9042. IN struct _DEVICE_OBJECT *DeviceObject
  9043. );
  9044. typedef
  9045. BOOLEAN
  9046. (*PFAST_IO_READ) (
  9047. IN struct _FILE_OBJECT *FileObject,
  9048. IN PLARGE_INTEGER FileOffset,
  9049. IN ULONG Length,
  9050. IN BOOLEAN Wait,
  9051. IN ULONG LockKey,
  9052. OUT PVOID Buffer,
  9053. OUT PIO_STATUS_BLOCK IoStatus,
  9054. IN struct _DEVICE_OBJECT *DeviceObject
  9055. );
  9056. typedef
  9057. BOOLEAN
  9058. (*PFAST_IO_WRITE) (
  9059. IN struct _FILE_OBJECT *FileObject,
  9060. IN PLARGE_INTEGER FileOffset,
  9061. IN ULONG Length,
  9062. IN BOOLEAN Wait,
  9063. IN ULONG LockKey,
  9064. IN PVOID Buffer,
  9065. OUT PIO_STATUS_BLOCK IoStatus,
  9066. IN struct _DEVICE_OBJECT *DeviceObject
  9067. );
  9068. //
  9069. // Fast I/O query basic and standard information procedures.
  9070. //
  9071. typedef
  9072. BOOLEAN
  9073. (*PFAST_IO_QUERY_BASIC_INFO) (
  9074. IN struct _FILE_OBJECT *FileObject,
  9075. IN BOOLEAN Wait,
  9076. OUT PFILE_BASIC_INFORMATION Buffer,
  9077. OUT PIO_STATUS_BLOCK IoStatus,
  9078. IN struct _DEVICE_OBJECT *DeviceObject
  9079. );
  9080. typedef
  9081. BOOLEAN
  9082. (*PFAST_IO_QUERY_STANDARD_INFO) (
  9083. IN struct _FILE_OBJECT *FileObject,
  9084. IN BOOLEAN Wait,
  9085. OUT PFILE_STANDARD_INFORMATION Buffer,
  9086. OUT PIO_STATUS_BLOCK IoStatus,
  9087. IN struct _DEVICE_OBJECT *DeviceObject
  9088. );
  9089. //
  9090. // Fast I/O lock and unlock procedures.
  9091. //
  9092. typedef
  9093. BOOLEAN
  9094. (*PFAST_IO_LOCK) (
  9095. IN struct _FILE_OBJECT *FileObject,
  9096. IN PLARGE_INTEGER FileOffset,
  9097. IN PLARGE_INTEGER Length,
  9098. PEPROCESS ProcessId,
  9099. ULONG Key,
  9100. BOOLEAN FailImmediately,
  9101. BOOLEAN ExclusiveLock,
  9102. OUT PIO_STATUS_BLOCK IoStatus,
  9103. IN struct _DEVICE_OBJECT *DeviceObject
  9104. );
  9105. typedef
  9106. BOOLEAN
  9107. (*PFAST_IO_UNLOCK_SINGLE) (
  9108. IN struct _FILE_OBJECT *FileObject,
  9109. IN PLARGE_INTEGER FileOffset,
  9110. IN PLARGE_INTEGER Length,
  9111. PEPROCESS ProcessId,
  9112. ULONG Key,
  9113. OUT PIO_STATUS_BLOCK IoStatus,
  9114. IN struct _DEVICE_OBJECT *DeviceObject
  9115. );
  9116. typedef
  9117. BOOLEAN
  9118. (*PFAST_IO_UNLOCK_ALL) (
  9119. IN struct _FILE_OBJECT *FileObject,
  9120. PEPROCESS ProcessId,
  9121. OUT PIO_STATUS_BLOCK IoStatus,
  9122. IN struct _DEVICE_OBJECT *DeviceObject
  9123. );
  9124. typedef
  9125. BOOLEAN
  9126. (*PFAST_IO_UNLOCK_ALL_BY_KEY) (
  9127. IN struct _FILE_OBJECT *FileObject,
  9128. PVOID ProcessId,
  9129. ULONG Key,
  9130. OUT PIO_STATUS_BLOCK IoStatus,
  9131. IN struct _DEVICE_OBJECT *DeviceObject
  9132. );
  9133. //
  9134. // Fast I/O device control procedure.
  9135. //
  9136. typedef
  9137. BOOLEAN
  9138. (*PFAST_IO_DEVICE_CONTROL) (
  9139. IN struct _FILE_OBJECT *FileObject,
  9140. IN BOOLEAN Wait,
  9141. IN PVOID InputBuffer OPTIONAL,
  9142. IN ULONG InputBufferLength,
  9143. OUT PVOID OutputBuffer OPTIONAL,
  9144. IN ULONG OutputBufferLength,
  9145. IN ULONG IoControlCode,
  9146. OUT PIO_STATUS_BLOCK IoStatus,
  9147. IN struct _DEVICE_OBJECT *DeviceObject
  9148. );
  9149. //
  9150. // Define callbacks for NtCreateSection to synchronize correctly with
  9151. // the file system. It pre-acquires the resources that will be needed
  9152. // when calling to query and set file/allocation size in the file system.
  9153. //
  9154. typedef
  9155. VOID
  9156. (*PFAST_IO_ACQUIRE_FILE) (
  9157. IN struct _FILE_OBJECT *FileObject
  9158. );
  9159. typedef
  9160. VOID
  9161. (*PFAST_IO_RELEASE_FILE) (
  9162. IN struct _FILE_OBJECT *FileObject
  9163. );
  9164. //
  9165. // Define callback for drivers that have device objects attached to lower-
  9166. // level drivers' device objects. This callback is made when the lower-level
  9167. // driver is deleting its device object.
  9168. //
  9169. typedef
  9170. VOID
  9171. (*PFAST_IO_DETACH_DEVICE) (
  9172. IN struct _DEVICE_OBJECT *SourceDevice,
  9173. IN struct _DEVICE_OBJECT *TargetDevice
  9174. );
  9175. //
  9176. // This structure is used by the server to quickly get the information needed
  9177. // to service a server open call. It is takes what would be two fast io calls
  9178. // one for basic information and the other for standard information and makes
  9179. // it into one call.
  9180. //
  9181. typedef
  9182. BOOLEAN
  9183. (*PFAST_IO_QUERY_NETWORK_OPEN_INFO) (
  9184. IN struct _FILE_OBJECT *FileObject,
  9185. IN BOOLEAN Wait,
  9186. OUT struct _FILE_NETWORK_OPEN_INFORMATION *Buffer,
  9187. OUT struct _IO_STATUS_BLOCK *IoStatus,
  9188. IN struct _DEVICE_OBJECT *DeviceObject
  9189. );
  9190. //
  9191. // Define Mdl-based routines for the server to call
  9192. //
  9193. typedef
  9194. BOOLEAN
  9195. (*PFAST_IO_MDL_READ) (
  9196. IN struct _FILE_OBJECT *FileObject,
  9197. IN PLARGE_INTEGER FileOffset,
  9198. IN ULONG Length,
  9199. IN ULONG LockKey,
  9200. OUT PMDL *MdlChain,
  9201. OUT PIO_STATUS_BLOCK IoStatus,
  9202. IN struct _DEVICE_OBJECT *DeviceObject
  9203. );
  9204. typedef
  9205. BOOLEAN
  9206. (*PFAST_IO_MDL_READ_COMPLETE) (
  9207. IN struct _FILE_OBJECT *FileObject,
  9208. IN PMDL MdlChain,
  9209. IN struct _DEVICE_OBJECT *DeviceObject
  9210. );
  9211. typedef
  9212. BOOLEAN
  9213. (*PFAST_IO_PREPARE_MDL_WRITE) (
  9214. IN struct _FILE_OBJECT *FileObject,
  9215. IN PLARGE_INTEGER FileOffset,
  9216. IN ULONG Length,
  9217. IN ULONG LockKey,
  9218. OUT PMDL *MdlChain,
  9219. OUT PIO_STATUS_BLOCK IoStatus,
  9220. IN struct _DEVICE_OBJECT *DeviceObject
  9221. );
  9222. typedef
  9223. BOOLEAN
  9224. (*PFAST_IO_MDL_WRITE_COMPLETE) (
  9225. IN struct _FILE_OBJECT *FileObject,
  9226. IN PLARGE_INTEGER FileOffset,
  9227. IN PMDL MdlChain,
  9228. IN struct _DEVICE_OBJECT *DeviceObject
  9229. );
  9230. //
  9231. // If this routine is present, it will be called by FsRtl
  9232. // to acquire the file for the mapped page writer.
  9233. //
  9234. typedef
  9235. NTSTATUS
  9236. (*PFAST_IO_ACQUIRE_FOR_MOD_WRITE) (
  9237. IN struct _FILE_OBJECT *FileObject,
  9238. IN PLARGE_INTEGER EndingOffset,
  9239. OUT struct _ERESOURCE **ResourceToRelease,
  9240. IN struct _DEVICE_OBJECT *DeviceObject
  9241. );
  9242. typedef
  9243. NTSTATUS
  9244. (*PFAST_IO_RELEASE_FOR_MOD_WRITE) (
  9245. IN struct _FILE_OBJECT *FileObject,
  9246. IN struct _ERESOURCE *ResourceToRelease,
  9247. IN struct _DEVICE_OBJECT *DeviceObject
  9248. );
  9249. //
  9250. // If this routine is present, it will be called by FsRtl
  9251. // to acquire the file for the mapped page writer.
  9252. //
  9253. typedef
  9254. NTSTATUS
  9255. (*PFAST_IO_ACQUIRE_FOR_CCFLUSH) (
  9256. IN struct _FILE_OBJECT *FileObject,
  9257. IN struct _DEVICE_OBJECT *DeviceObject
  9258. );
  9259. typedef
  9260. NTSTATUS
  9261. (*PFAST_IO_RELEASE_FOR_CCFLUSH) (
  9262. IN struct _FILE_OBJECT *FileObject,
  9263. IN struct _DEVICE_OBJECT *DeviceObject
  9264. );
  9265. typedef
  9266. BOOLEAN
  9267. (*PFAST_IO_READ_COMPRESSED) (
  9268. IN struct _FILE_OBJECT *FileObject,
  9269. IN PLARGE_INTEGER FileOffset,
  9270. IN ULONG Length,
  9271. IN ULONG LockKey,
  9272. OUT PVOID Buffer,
  9273. OUT PMDL *MdlChain,
  9274. OUT PIO_STATUS_BLOCK IoStatus,
  9275. OUT struct _COMPRESSED_DATA_INFO *CompressedDataInfo,
  9276. IN ULONG CompressedDataInfoLength,
  9277. IN struct _DEVICE_OBJECT *DeviceObject
  9278. );
  9279. typedef
  9280. BOOLEAN
  9281. (*PFAST_IO_WRITE_COMPRESSED) (
  9282. IN struct _FILE_OBJECT *FileObject,
  9283. IN PLARGE_INTEGER FileOffset,
  9284. IN ULONG Length,
  9285. IN ULONG LockKey,
  9286. IN PVOID Buffer,
  9287. OUT PMDL *MdlChain,
  9288. OUT PIO_STATUS_BLOCK IoStatus,
  9289. IN struct _COMPRESSED_DATA_INFO *CompressedDataInfo,
  9290. IN ULONG CompressedDataInfoLength,
  9291. IN struct _DEVICE_OBJECT *DeviceObject
  9292. );
  9293. typedef
  9294. BOOLEAN
  9295. (*PFAST_IO_MDL_READ_COMPLETE_COMPRESSED) (
  9296. IN struct _FILE_OBJECT *FileObject,
  9297. IN PMDL MdlChain,
  9298. IN struct _DEVICE_OBJECT *DeviceObject
  9299. );
  9300. typedef
  9301. BOOLEAN
  9302. (*PFAST_IO_MDL_WRITE_COMPLETE_COMPRESSED) (
  9303. IN struct _FILE_OBJECT *FileObject,
  9304. IN PLARGE_INTEGER FileOffset,
  9305. IN PMDL MdlChain,
  9306. IN struct _DEVICE_OBJECT *DeviceObject
  9307. );
  9308. typedef
  9309. BOOLEAN
  9310. (*PFAST_IO_QUERY_OPEN) (
  9311. IN struct _IRP *Irp,
  9312. OUT PFILE_NETWORK_OPEN_INFORMATION NetworkInformation,
  9313. IN struct _DEVICE_OBJECT *DeviceObject
  9314. );
  9315. //
  9316. // Define the structure to describe the Fast I/O dispatch routines. Any
  9317. // additions made to this structure MUST be added monotonically to the end
  9318. // of the structure, and fields CANNOT be removed from the middle.
  9319. //
  9320. typedef struct _FAST_IO_DISPATCH {
  9321. ULONG SizeOfFastIoDispatch;
  9322. PFAST_IO_CHECK_IF_POSSIBLE FastIoCheckIfPossible;
  9323. PFAST_IO_READ FastIoRead;
  9324. PFAST_IO_WRITE FastIoWrite;
  9325. PFAST_IO_QUERY_BASIC_INFO FastIoQueryBasicInfo;
  9326. PFAST_IO_QUERY_STANDARD_INFO FastIoQueryStandardInfo;
  9327. PFAST_IO_LOCK FastIoLock;
  9328. PFAST_IO_UNLOCK_SINGLE FastIoUnlockSingle;
  9329. PFAST_IO_UNLOCK_ALL FastIoUnlockAll;
  9330. PFAST_IO_UNLOCK_ALL_BY_KEY FastIoUnlockAllByKey;
  9331. PFAST_IO_DEVICE_CONTROL FastIoDeviceControl;
  9332. PFAST_IO_ACQUIRE_FILE AcquireFileForNtCreateSection;
  9333. PFAST_IO_RELEASE_FILE ReleaseFileForNtCreateSection;
  9334. PFAST_IO_DETACH_DEVICE FastIoDetachDevice;
  9335. PFAST_IO_QUERY_NETWORK_OPEN_INFO FastIoQueryNetworkOpenInfo;
  9336. PFAST_IO_ACQUIRE_FOR_MOD_WRITE AcquireForModWrite;
  9337. PFAST_IO_MDL_READ MdlRead;
  9338. PFAST_IO_MDL_READ_COMPLETE MdlReadComplete;
  9339. PFAST_IO_PREPARE_MDL_WRITE PrepareMdlWrite;
  9340. PFAST_IO_MDL_WRITE_COMPLETE MdlWriteComplete;
  9341. PFAST_IO_READ_COMPRESSED FastIoReadCompressed;
  9342. PFAST_IO_WRITE_COMPRESSED FastIoWriteCompressed;
  9343. PFAST_IO_MDL_READ_COMPLETE_COMPRESSED MdlReadCompleteCompressed;
  9344. PFAST_IO_MDL_WRITE_COMPLETE_COMPRESSED MdlWriteCompleteCompressed;
  9345. PFAST_IO_QUERY_OPEN FastIoQueryOpen;
  9346. PFAST_IO_RELEASE_FOR_MOD_WRITE ReleaseForModWrite;
  9347. PFAST_IO_ACQUIRE_FOR_CCFLUSH AcquireForCcFlush;
  9348. PFAST_IO_RELEASE_FOR_CCFLUSH ReleaseForCcFlush;
  9349. } FAST_IO_DISPATCH, *PFAST_IO_DISPATCH;
  9350. //
  9351. // Define the actions that a driver execution routine may request of the
  9352. // adapter/controller allocation routines upon return.
  9353. //
  9354. typedef enum _IO_ALLOCATION_ACTION {
  9355. KeepObject = 1,
  9356. DeallocateObject,
  9357. DeallocateObjectKeepRegisters
  9358. } IO_ALLOCATION_ACTION, *PIO_ALLOCATION_ACTION;
  9359. //
  9360. // Define device driver adapter/controller execution routine.
  9361. //
  9362. typedef
  9363. IO_ALLOCATION_ACTION
  9364. (*PDRIVER_CONTROL) (
  9365. IN struct _DEVICE_OBJECT *DeviceObject,
  9366. IN struct _IRP *Irp,
  9367. IN PVOID MapRegisterBase,
  9368. IN PVOID Context
  9369. );
  9370. //
  9371. // Define the I/O system's security context type for use by file system's
  9372. // when checking access to volumes, files, and directories.
  9373. //
  9374. typedef struct _IO_SECURITY_CONTEXT {
  9375. PSECURITY_QUALITY_OF_SERVICE SecurityQos;
  9376. PACCESS_STATE AccessState;
  9377. ACCESS_MASK DesiredAccess;
  9378. ULONG FullCreateOptions;
  9379. } IO_SECURITY_CONTEXT, *PIO_SECURITY_CONTEXT;
  9380. //
  9381. // Define object type specific fields of various objects used by the I/O system
  9382. //
  9383. typedef struct _DMA_ADAPTER *PADAPTER_OBJECT;
  9384. //
  9385. // Define Wait Context Block (WCB)
  9386. //
  9387. typedef struct _WAIT_CONTEXT_BLOCK {
  9388. KDEVICE_QUEUE_ENTRY WaitQueueEntry;
  9389. PDRIVER_CONTROL DeviceRoutine;
  9390. PVOID DeviceContext;
  9391. ULONG NumberOfMapRegisters;
  9392. PVOID DeviceObject;
  9393. PVOID CurrentIrp;
  9394. PKDPC BufferChainingDpc;
  9395. } WAIT_CONTEXT_BLOCK, *PWAIT_CONTEXT_BLOCK;
  9396. //
  9397. // Define Device Object (DO) flags
  9398. //
  9399. #define DO_VERIFY_VOLUME 0x00000002
  9400. #define DO_BUFFERED_IO 0x00000004
  9401. #define DO_EXCLUSIVE 0x00000008
  9402. #define DO_DIRECT_IO 0x00000010
  9403. #define DO_MAP_IO_BUFFER 0x00000020
  9404. #define DO_DEVICE_INITIALIZING 0x00000080
  9405. #define DO_SHUTDOWN_REGISTERED 0x00000800
  9406. #define DO_BUS_ENUMERATED_DEVICE 0x00001000
  9407. #define DO_POWER_PAGABLE 0x00002000
  9408. #define DO_POWER_INRUSH 0x00004000
  9409. //
  9410. // Device Object structure definition
  9411. //
  9412. typedef struct DECLSPEC_ALIGN(MEMORY_ALLOCATION_ALIGNMENT) _DEVICE_OBJECT {
  9413. CSHORT Type;
  9414. USHORT Size;
  9415. LONG ReferenceCount;
  9416. struct _DRIVER_OBJECT *DriverObject;
  9417. struct _DEVICE_OBJECT *NextDevice;
  9418. struct _DEVICE_OBJECT *AttachedDevice;
  9419. struct _IRP *CurrentIrp;
  9420. PIO_TIMER Timer;
  9421. ULONG Flags; // See above: DO_...
  9422. ULONG Characteristics; // See ntioapi: FILE_...
  9423. PVOID DoNotUse1;
  9424. PVOID DeviceExtension;
  9425. DEVICE_TYPE DeviceType;
  9426. CCHAR StackSize;
  9427. union {
  9428. LIST_ENTRY ListEntry;
  9429. WAIT_CONTEXT_BLOCK Wcb;
  9430. } Queue;
  9431. ULONG AlignmentRequirement;
  9432. KDEVICE_QUEUE DeviceQueue;
  9433. KDPC Dpc;
  9434. //
  9435. // The following field is for exclusive use by the filesystem to keep
  9436. // track of the number of Fsp threads currently using the device
  9437. //
  9438. ULONG ActiveThreadCount;
  9439. PSECURITY_DESCRIPTOR SecurityDescriptor;
  9440. KEVENT DeviceLock;
  9441. USHORT SectorSize;
  9442. USHORT Spare1;
  9443. struct _DEVOBJ_EXTENSION *DeviceObjectExtension;
  9444. PVOID Reserved;
  9445. } DEVICE_OBJECT;
  9446. typedef struct _DEVICE_OBJECT *PDEVICE_OBJECT;
  9447. struct _DEVICE_OBJECT_POWER_EXTENSION;
  9448. typedef struct _DEVOBJ_EXTENSION {
  9449. CSHORT Type;
  9450. USHORT Size;
  9451. //
  9452. // Public part of the DeviceObjectExtension structure
  9453. //
  9454. PDEVICE_OBJECT DeviceObject; // owning device object
  9455. } DEVOBJ_EXTENSION, *PDEVOBJ_EXTENSION;
  9456. //
  9457. // Define Driver Object (DRVO) flags
  9458. //
  9459. #define DRVO_UNLOAD_INVOKED 0x00000001
  9460. #define DRVO_LEGACY_DRIVER 0x00000002
  9461. #define DRVO_BUILTIN_DRIVER 0x00000004 // Driver objects for Hal, PnP Mgr
  9462. typedef struct _DRIVER_EXTENSION {
  9463. //
  9464. // Back pointer to Driver Object
  9465. //
  9466. struct _DRIVER_OBJECT *DriverObject;
  9467. //
  9468. // The AddDevice entry point is called by the Plug & Play manager
  9469. // to inform the driver when a new device instance arrives that this
  9470. // driver must control.
  9471. //
  9472. PDRIVER_ADD_DEVICE AddDevice;
  9473. //
  9474. // The count field is used to count the number of times the driver has
  9475. // had its registered reinitialization routine invoked.
  9476. //
  9477. ULONG Count;
  9478. //
  9479. // The service name field is used by the pnp manager to determine
  9480. // where the driver related info is stored in the registry.
  9481. //
  9482. UNICODE_STRING ServiceKeyName;
  9483. //
  9484. // Note: any new shared fields get added here.
  9485. //
  9486. } DRIVER_EXTENSION, *PDRIVER_EXTENSION;
  9487. typedef struct _DRIVER_OBJECT {
  9488. CSHORT Type;
  9489. CSHORT Size;
  9490. //
  9491. // The following links all of the devices created by a single driver
  9492. // together on a list, and the Flags word provides an extensible flag
  9493. // location for driver objects.
  9494. //
  9495. PDEVICE_OBJECT DeviceObject;
  9496. ULONG Flags;
  9497. //
  9498. // The following section describes where the driver is loaded. The count
  9499. // field is used to count the number of times the driver has had its
  9500. // registered reinitialization routine invoked.
  9501. //
  9502. PVOID DriverStart;
  9503. ULONG DriverSize;
  9504. PVOID DriverSection;
  9505. PDRIVER_EXTENSION DriverExtension;
  9506. //
  9507. // The driver name field is used by the error log thread
  9508. // determine the name of the driver that an I/O request is/was bound.
  9509. //
  9510. UNICODE_STRING DriverName;
  9511. //
  9512. // The following section is for registry support. Thise is a pointer
  9513. // to the path to the hardware information in the registry
  9514. //
  9515. PUNICODE_STRING HardwareDatabase;
  9516. //
  9517. // The following section contains the optional pointer to an array of
  9518. // alternate entry points to a driver for "fast I/O" support. Fast I/O
  9519. // is performed by invoking the driver routine directly with separate
  9520. // parameters, rather than using the standard IRP call mechanism. Note
  9521. // that these functions may only be used for synchronous I/O, and when
  9522. // the file is cached.
  9523. //
  9524. PFAST_IO_DISPATCH FastIoDispatch;
  9525. //
  9526. // The following section describes the entry points to this particular
  9527. // driver. Note that the major function dispatch table must be the last
  9528. // field in the object so that it remains extensible.
  9529. //
  9530. PDRIVER_INITIALIZE DriverInit;
  9531. PDRIVER_STARTIO DriverStartIo;
  9532. PDRIVER_UNLOAD DriverUnload;
  9533. PDRIVER_DISPATCH MajorFunction[IRP_MJ_MAXIMUM_FUNCTION + 1];
  9534. } DRIVER_OBJECT;
  9535. typedef struct _DRIVER_OBJECT *PDRIVER_OBJECT;
  9536. //
  9537. // The following structure is pointed to by the SectionObject pointer field
  9538. // of a file object, and is allocated by the various NT file systems.
  9539. //
  9540. typedef struct _SECTION_OBJECT_POINTERS {
  9541. PVOID DataSectionObject;
  9542. PVOID SharedCacheMap;
  9543. PVOID ImageSectionObject;
  9544. } SECTION_OBJECT_POINTERS;
  9545. typedef SECTION_OBJECT_POINTERS *PSECTION_OBJECT_POINTERS;
  9546. //
  9547. // Define the format of a completion message.
  9548. //
  9549. typedef struct _IO_COMPLETION_CONTEXT {
  9550. PVOID Port;
  9551. PVOID Key;
  9552. } IO_COMPLETION_CONTEXT, *PIO_COMPLETION_CONTEXT;
  9553. //
  9554. // Define File Object (FO) flags
  9555. //
  9556. #define FO_FILE_OPEN 0x00000001
  9557. #define FO_SYNCHRONOUS_IO 0x00000002
  9558. #define FO_ALERTABLE_IO 0x00000004
  9559. #define FO_NO_INTERMEDIATE_BUFFERING 0x00000008
  9560. #define FO_WRITE_THROUGH 0x00000010
  9561. #define FO_SEQUENTIAL_ONLY 0x00000020
  9562. #define FO_CACHE_SUPPORTED 0x00000040
  9563. #define FO_NAMED_PIPE 0x00000080
  9564. #define FO_STREAM_FILE 0x00000100
  9565. #define FO_MAILSLOT 0x00000200
  9566. #define FO_GENERATE_AUDIT_ON_CLOSE 0x00000400
  9567. #define FO_DIRECT_DEVICE_OPEN 0x00000800
  9568. #define FO_FILE_MODIFIED 0x00001000
  9569. #define FO_FILE_SIZE_CHANGED 0x00002000
  9570. #define FO_CLEANUP_COMPLETE 0x00004000
  9571. #define FO_TEMPORARY_FILE 0x00008000
  9572. #define FO_DELETE_ON_CLOSE 0x00010000
  9573. #define FO_OPENED_CASE_SENSITIVE 0x00020000
  9574. #define FO_HANDLE_CREATED 0x00040000
  9575. #define FO_FILE_FAST_IO_READ 0x00080000
  9576. #define FO_RANDOM_ACCESS 0x00100000
  9577. #define FO_FILE_OPEN_CANCELLED 0x00200000
  9578. #define FO_VOLUME_OPEN 0x00400000
  9579. #define FO_FILE_OBJECT_HAS_EXTENSION 0x00800000
  9580. #define FO_REMOTE_ORIGIN 0x01000000
  9581. typedef struct _FILE_OBJECT {
  9582. CSHORT Type;
  9583. CSHORT Size;
  9584. PDEVICE_OBJECT DeviceObject;
  9585. PVOID DoNotUse1;
  9586. PVOID FsContext;
  9587. PVOID FsContext2;
  9588. PSECTION_OBJECT_POINTERS SectionObjectPointer;
  9589. PVOID PrivateCacheMap;
  9590. NTSTATUS FinalStatus;
  9591. struct _FILE_OBJECT *RelatedFileObject;
  9592. BOOLEAN LockOperation;
  9593. BOOLEAN DeletePending;
  9594. BOOLEAN ReadAccess;
  9595. BOOLEAN WriteAccess;
  9596. BOOLEAN DeleteAccess;
  9597. BOOLEAN SharedRead;
  9598. BOOLEAN SharedWrite;
  9599. BOOLEAN SharedDelete;
  9600. ULONG Flags;
  9601. UNICODE_STRING FileName;
  9602. LARGE_INTEGER CurrentByteOffset;
  9603. ULONG Waiters;
  9604. ULONG Busy;
  9605. PVOID LastLock;
  9606. KEVENT Lock;
  9607. KEVENT Event;
  9608. PIO_COMPLETION_CONTEXT CompletionContext;
  9609. } FILE_OBJECT;
  9610. typedef struct _FILE_OBJECT *PFILE_OBJECT;
  9611. //
  9612. // Define I/O Request Packet (IRP) flags
  9613. //
  9614. #define IRP_NOCACHE 0x00000001
  9615. #define IRP_PAGING_IO 0x00000002
  9616. #define IRP_MOUNT_COMPLETION 0x00000002
  9617. #define IRP_SYNCHRONOUS_API 0x00000004
  9618. #define IRP_ASSOCIATED_IRP 0x00000008
  9619. #define IRP_BUFFERED_IO 0x00000010
  9620. #define IRP_DEALLOCATE_BUFFER 0x00000020
  9621. #define IRP_INPUT_OPERATION 0x00000040
  9622. #define IRP_SYNCHRONOUS_PAGING_IO 0x00000040
  9623. #define IRP_CREATE_OPERATION 0x00000080
  9624. #define IRP_READ_OPERATION 0x00000100
  9625. #define IRP_WRITE_OPERATION 0x00000200
  9626. #define IRP_CLOSE_OPERATION 0x00000400
  9627. //
  9628. // Define I/O request packet (IRP) alternate flags for allocation control.
  9629. //
  9630. #define IRP_QUOTA_CHARGED 0x01
  9631. #define IRP_ALLOCATED_MUST_SUCCEED 0x02
  9632. #define IRP_ALLOCATED_FIXED_SIZE 0x04
  9633. #define IRP_LOOKASIDE_ALLOCATION 0x08
  9634. //
  9635. // I/O Request Packet (IRP) definition
  9636. //
  9637. typedef struct DECLSPEC_ALIGN(MEMORY_ALLOCATION_ALIGNMENT) _IRP {
  9638. CSHORT Type;
  9639. USHORT Size;
  9640. //
  9641. // Define the common fields used to control the IRP.
  9642. //
  9643. //
  9644. // Define a pointer to the Memory Descriptor List (MDL) for this I/O
  9645. // request. This field is only used if the I/O is "direct I/O".
  9646. //
  9647. PMDL MdlAddress;
  9648. //
  9649. // Flags word - used to remember various flags.
  9650. //
  9651. ULONG Flags;
  9652. //
  9653. // The following union is used for one of three purposes:
  9654. //
  9655. // 1. This IRP is an associated IRP. The field is a pointer to a master
  9656. // IRP.
  9657. //
  9658. // 2. This is the master IRP. The field is the count of the number of
  9659. // IRPs which must complete (associated IRPs) before the master can
  9660. // complete.
  9661. //
  9662. // 3. This operation is being buffered and the field is the address of
  9663. // the system space buffer.
  9664. //
  9665. union {
  9666. struct _IRP *MasterIrp;
  9667. LONG IrpCount;
  9668. PVOID SystemBuffer;
  9669. } AssociatedIrp;
  9670. //
  9671. // Thread list entry - allows queueing the IRP to the thread pending I/O
  9672. // request packet list.
  9673. //
  9674. LIST_ENTRY ThreadListEntry;
  9675. //
  9676. // I/O status - final status of operation.
  9677. //
  9678. IO_STATUS_BLOCK IoStatus;
  9679. //
  9680. // Requestor mode - mode of the original requestor of this operation.
  9681. //
  9682. KPROCESSOR_MODE RequestorMode;
  9683. //
  9684. // Pending returned - TRUE if pending was initially returned as the
  9685. // status for this packet.
  9686. //
  9687. BOOLEAN PendingReturned;
  9688. //
  9689. // Stack state information.
  9690. //
  9691. CHAR StackCount;
  9692. CHAR CurrentLocation;
  9693. //
  9694. // Cancel - packet has been canceled.
  9695. //
  9696. BOOLEAN Cancel;
  9697. //
  9698. // Cancel Irql - Irql at which the cancel spinlock was acquired.
  9699. //
  9700. KIRQL CancelIrql;
  9701. //
  9702. // ApcEnvironment - Used to save the APC environment at the time that the
  9703. // packet was initialized.
  9704. //
  9705. CCHAR ApcEnvironment;
  9706. //
  9707. // Allocation control flags.
  9708. //
  9709. UCHAR AllocationFlags;
  9710. //
  9711. // User parameters.
  9712. //
  9713. PIO_STATUS_BLOCK UserIosb;
  9714. PKEVENT UserEvent;
  9715. union {
  9716. struct {
  9717. PIO_APC_ROUTINE UserApcRoutine;
  9718. PVOID UserApcContext;
  9719. } AsynchronousParameters;
  9720. LARGE_INTEGER AllocationSize;
  9721. } Overlay;
  9722. //
  9723. // CancelRoutine - Used to contain the address of a cancel routine supplied
  9724. // by a device driver when the IRP is in a cancelable state.
  9725. //
  9726. PDRIVER_CANCEL CancelRoutine;
  9727. //
  9728. // Note that the UserBuffer parameter is outside of the stack so that I/O
  9729. // completion can copy data back into the user's address space without
  9730. // having to know exactly which service was being invoked. The length
  9731. // of the copy is stored in the second half of the I/O status block. If
  9732. // the UserBuffer field is NULL, then no copy is performed.
  9733. //
  9734. PVOID UserBuffer;
  9735. //
  9736. // Kernel structures
  9737. //
  9738. // The following section contains kernel structures which the IRP needs
  9739. // in order to place various work information in kernel controller system
  9740. // queues. Because the size and alignment cannot be controlled, they are
  9741. // placed here at the end so they just hang off and do not affect the
  9742. // alignment of other fields in the IRP.
  9743. //
  9744. union {
  9745. struct {
  9746. union {
  9747. //
  9748. // DeviceQueueEntry - The device queue entry field is used to
  9749. // queue the IRP to the device driver device queue.
  9750. //
  9751. KDEVICE_QUEUE_ENTRY DeviceQueueEntry;
  9752. struct {
  9753. //
  9754. // The following are available to the driver to use in
  9755. // whatever manner is desired, while the driver owns the
  9756. // packet.
  9757. //
  9758. PVOID DriverContext[4];
  9759. } ;
  9760. } ;
  9761. //
  9762. // Thread - pointer to caller's Thread Control Block.
  9763. //
  9764. PETHREAD Thread;
  9765. //
  9766. // Auxiliary buffer - pointer to any auxiliary buffer that is
  9767. // required to pass information to a driver that is not contained
  9768. // in a normal buffer.
  9769. //
  9770. PCHAR AuxiliaryBuffer;
  9771. //
  9772. // The following unnamed structure must be exactly identical
  9773. // to the unnamed structure used in the minipacket header used
  9774. // for completion queue entries.
  9775. //
  9776. struct {
  9777. //
  9778. // List entry - used to queue the packet to completion queue, among
  9779. // others.
  9780. //
  9781. LIST_ENTRY ListEntry;
  9782. union {
  9783. //
  9784. // Current stack location - contains a pointer to the current
  9785. // IO_STACK_LOCATION structure in the IRP stack. This field
  9786. // should never be directly accessed by drivers. They should
  9787. // use the standard functions.
  9788. //
  9789. struct _IO_STACK_LOCATION *CurrentStackLocation;
  9790. //
  9791. // Minipacket type.
  9792. //
  9793. ULONG PacketType;
  9794. };
  9795. };
  9796. //
  9797. // Original file object - pointer to the original file object
  9798. // that was used to open the file. This field is owned by the
  9799. // I/O system and should not be used by any other drivers.
  9800. //
  9801. PFILE_OBJECT OriginalFileObject;
  9802. } Overlay;
  9803. //
  9804. // APC - This APC control block is used for the special kernel APC as
  9805. // well as for the caller's APC, if one was specified in the original
  9806. // argument list. If so, then the APC is reused for the normal APC for
  9807. // whatever mode the caller was in and the "special" routine that is
  9808. // invoked before the APC gets control simply deallocates the IRP.
  9809. //
  9810. KAPC Apc;
  9811. //
  9812. // CompletionKey - This is the key that is used to distinguish
  9813. // individual I/O operations initiated on a single file handle.
  9814. //
  9815. PVOID CompletionKey;
  9816. } Tail;
  9817. } IRP, *PIRP;
  9818. //
  9819. // Define completion routine types for use in stack locations in an IRP
  9820. //
  9821. typedef
  9822. NTSTATUS
  9823. (*PIO_COMPLETION_ROUTINE) (
  9824. IN PDEVICE_OBJECT DeviceObject,
  9825. IN PIRP Irp,
  9826. IN PVOID Context
  9827. );
  9828. //
  9829. // Define stack location control flags
  9830. //
  9831. #define SL_PENDING_RETURNED 0x01
  9832. #define SL_INVOKE_ON_CANCEL 0x20
  9833. #define SL_INVOKE_ON_SUCCESS 0x40
  9834. #define SL_INVOKE_ON_ERROR 0x80
  9835. //
  9836. // Define flags for various functions
  9837. //
  9838. //
  9839. // Create / Create Named Pipe
  9840. //
  9841. // The following flags must exactly match those in the IoCreateFile call's
  9842. // options. The case sensitive flag is added in later, by the parse routine,
  9843. // and is not an actual option to open. Rather, it is part of the object
  9844. // manager's attributes structure.
  9845. //
  9846. #define SL_FORCE_ACCESS_CHECK 0x01
  9847. #define SL_OPEN_PAGING_FILE 0x02
  9848. #define SL_OPEN_TARGET_DIRECTORY 0x04
  9849. #define SL_CASE_SENSITIVE 0x80
  9850. //
  9851. // Read / Write
  9852. //
  9853. #define SL_KEY_SPECIFIED 0x01
  9854. #define SL_OVERRIDE_VERIFY_VOLUME 0x02
  9855. #define SL_WRITE_THROUGH 0x04
  9856. #define SL_FT_SEQUENTIAL_WRITE 0x08
  9857. //
  9858. // Device I/O Control
  9859. //
  9860. //
  9861. // Same SL_OVERRIDE_VERIFY_VOLUME as for read/write above.
  9862. //
  9863. #define SL_READ_ACCESS_GRANTED 0x01
  9864. #define SL_WRITE_ACCESS_GRANTED 0x04 // Gap for SL_OVERRIDE_VERIFY_VOLUME
  9865. //
  9866. // Lock
  9867. //
  9868. #define SL_FAIL_IMMEDIATELY 0x01
  9869. #define SL_EXCLUSIVE_LOCK 0x02
  9870. //
  9871. // QueryDirectory / QueryEa / QueryQuota
  9872. //
  9873. #define SL_RESTART_SCAN 0x01
  9874. #define SL_RETURN_SINGLE_ENTRY 0x02
  9875. #define SL_INDEX_SPECIFIED 0x04
  9876. //
  9877. // NotifyDirectory
  9878. //
  9879. #define SL_WATCH_TREE 0x01
  9880. //
  9881. // FileSystemControl
  9882. //
  9883. // minor: mount/verify volume
  9884. //
  9885. #define SL_ALLOW_RAW_MOUNT 0x01
  9886. //
  9887. // Define PNP/POWER types required by IRP_MJ_PNP/IRP_MJ_POWER.
  9888. //
  9889. typedef enum _DEVICE_RELATION_TYPE {
  9890. BusRelations,
  9891. EjectionRelations,
  9892. PowerRelations,
  9893. RemovalRelations,
  9894. TargetDeviceRelation,
  9895. SingleBusRelations
  9896. } DEVICE_RELATION_TYPE, *PDEVICE_RELATION_TYPE;
  9897. typedef struct _DEVICE_RELATIONS {
  9898. ULONG Count;
  9899. PDEVICE_OBJECT Objects[1]; // variable length
  9900. } DEVICE_RELATIONS, *PDEVICE_RELATIONS;
  9901. typedef enum _DEVICE_USAGE_NOTIFICATION_TYPE {
  9902. DeviceUsageTypeUndefined,
  9903. DeviceUsageTypePaging,
  9904. DeviceUsageTypeHibernation,
  9905. DeviceUsageTypeDumpFile
  9906. } DEVICE_USAGE_NOTIFICATION_TYPE;
  9907. // workaround overloaded definition (rpc generated headers all define INTERFACE
  9908. // to match the class name).
  9909. #undef INTERFACE
  9910. typedef struct _INTERFACE {
  9911. USHORT Size;
  9912. USHORT Version;
  9913. PVOID Context;
  9914. PINTERFACE_REFERENCE InterfaceReference;
  9915. PINTERFACE_DEREFERENCE InterfaceDereference;
  9916. // interface specific entries go here
  9917. } INTERFACE, *PINTERFACE;
  9918. typedef struct _DEVICE_CAPABILITIES {
  9919. USHORT Size;
  9920. USHORT Version; // the version documented here is version 1
  9921. ULONG DeviceD1:1;
  9922. ULONG DeviceD2:1;
  9923. ULONG LockSupported:1;
  9924. ULONG EjectSupported:1; // Ejectable in S0
  9925. ULONG Removable:1;
  9926. ULONG DockDevice:1;
  9927. ULONG UniqueID:1;
  9928. ULONG SilentInstall:1;
  9929. ULONG RawDeviceOK:1;
  9930. ULONG SurpriseRemovalOK:1;
  9931. ULONG WakeFromD0:1;
  9932. ULONG WakeFromD1:1;
  9933. ULONG WakeFromD2:1;
  9934. ULONG WakeFromD3:1;
  9935. ULONG HardwareDisabled:1;
  9936. ULONG NonDynamic:1;
  9937. ULONG WarmEjectSupported:1;
  9938. ULONG NoDisplayInUI:1;
  9939. ULONG Reserved:14;
  9940. ULONG Address;
  9941. ULONG UINumber;
  9942. DEVICE_POWER_STATE DeviceState[POWER_SYSTEM_MAXIMUM];
  9943. SYSTEM_POWER_STATE SystemWake;
  9944. DEVICE_POWER_STATE DeviceWake;
  9945. ULONG D1Latency;
  9946. ULONG D2Latency;
  9947. ULONG D3Latency;
  9948. } DEVICE_CAPABILITIES, *PDEVICE_CAPABILITIES;
  9949. typedef struct _POWER_SEQUENCE {
  9950. ULONG SequenceD1;
  9951. ULONG SequenceD2;
  9952. ULONG SequenceD3;
  9953. } POWER_SEQUENCE, *PPOWER_SEQUENCE;
  9954. typedef enum {
  9955. BusQueryDeviceID = 0, // <Enumerator>\<Enumerator-specific device id>
  9956. BusQueryHardwareIDs = 1, // Hardware ids
  9957. BusQueryCompatibleIDs = 2, // compatible device ids
  9958. BusQueryInstanceID = 3, // persistent id for this instance of the device
  9959. BusQueryDeviceSerialNumber = 4 // serial number for this device
  9960. } BUS_QUERY_ID_TYPE, *PBUS_QUERY_ID_TYPE;
  9961. typedef ULONG PNP_DEVICE_STATE, *PPNP_DEVICE_STATE;
  9962. #define PNP_DEVICE_DISABLED 0x00000001
  9963. #define PNP_DEVICE_DONT_DISPLAY_IN_UI 0x00000002
  9964. #define PNP_DEVICE_FAILED 0x00000004
  9965. #define PNP_DEVICE_REMOVED 0x00000008
  9966. #define PNP_DEVICE_RESOURCE_REQUIREMENTS_CHANGED 0x00000010
  9967. #define PNP_DEVICE_NOT_DISABLEABLE 0x00000020
  9968. typedef enum {
  9969. DeviceTextDescription = 0, // DeviceDesc property
  9970. DeviceTextLocationInformation = 1 // DeviceLocation property
  9971. } DEVICE_TEXT_TYPE, *PDEVICE_TEXT_TYPE;
  9972. //
  9973. // Define I/O Request Packet (IRP) stack locations
  9974. //
  9975. #if !defined(_AMD64_) && !defined(_IA64_)
  9976. #include "pshpack4.h"
  9977. #endif
  9978. #if defined(_WIN64)
  9979. #define POINTER_ALIGNMENT DECLSPEC_ALIGN(8)
  9980. #else
  9981. #define POINTER_ALIGNMENT
  9982. #endif
  9983. typedef struct _IO_STACK_LOCATION {
  9984. UCHAR MajorFunction;
  9985. UCHAR MinorFunction;
  9986. UCHAR Flags;
  9987. UCHAR Control;
  9988. //
  9989. // The following user parameters are based on the service that is being
  9990. // invoked. Drivers and file systems can determine which set to use based
  9991. // on the above major and minor function codes.
  9992. //
  9993. union {
  9994. //
  9995. // System service parameters for: NtCreateFile
  9996. //
  9997. struct {
  9998. PIO_SECURITY_CONTEXT SecurityContext;
  9999. ULONG Options;
  10000. USHORT POINTER_ALIGNMENT FileAttributes;
  10001. USHORT ShareAccess;
  10002. ULONG POINTER_ALIGNMENT EaLength;
  10003. } Create;
  10004. //
  10005. // System service parameters for: NtReadFile
  10006. //
  10007. struct {
  10008. ULONG Length;
  10009. ULONG POINTER_ALIGNMENT Key;
  10010. LARGE_INTEGER ByteOffset;
  10011. } Read;
  10012. //
  10013. // System service parameters for: NtWriteFile
  10014. //
  10015. struct {
  10016. ULONG Length;
  10017. ULONG POINTER_ALIGNMENT Key;
  10018. LARGE_INTEGER ByteOffset;
  10019. } Write;
  10020. //
  10021. // System service parameters for: NtQueryInformationFile
  10022. //
  10023. struct {
  10024. ULONG Length;
  10025. FILE_INFORMATION_CLASS POINTER_ALIGNMENT FileInformationClass;
  10026. } QueryFile;
  10027. //
  10028. // System service parameters for: NtSetInformationFile
  10029. //
  10030. struct {
  10031. ULONG Length;
  10032. FILE_INFORMATION_CLASS POINTER_ALIGNMENT FileInformationClass;
  10033. PFILE_OBJECT FileObject;
  10034. union {
  10035. struct {
  10036. BOOLEAN ReplaceIfExists;
  10037. BOOLEAN AdvanceOnly;
  10038. };
  10039. ULONG ClusterCount;
  10040. HANDLE DeleteHandle;
  10041. };
  10042. } SetFile;
  10043. //
  10044. // System service parameters for: NtQueryVolumeInformationFile
  10045. //
  10046. struct {
  10047. ULONG Length;
  10048. FS_INFORMATION_CLASS POINTER_ALIGNMENT FsInformationClass;
  10049. } QueryVolume;
  10050. //
  10051. // System service parameters for: NtFlushBuffersFile
  10052. //
  10053. // No extra user-supplied parameters.
  10054. //
  10055. //
  10056. // System service parameters for: NtDeviceIoControlFile
  10057. //
  10058. // Note that the user's output buffer is stored in the UserBuffer field
  10059. // and the user's input buffer is stored in the SystemBuffer field.
  10060. //
  10061. struct {
  10062. ULONG OutputBufferLength;
  10063. ULONG POINTER_ALIGNMENT InputBufferLength;
  10064. ULONG POINTER_ALIGNMENT IoControlCode;
  10065. PVOID Type3InputBuffer;
  10066. } DeviceIoControl;
  10067. //
  10068. // Non-system service parameters.
  10069. //
  10070. // Parameters for MountVolume
  10071. //
  10072. struct {
  10073. PVOID DoNotUse1;
  10074. PDEVICE_OBJECT DeviceObject;
  10075. } MountVolume;
  10076. //
  10077. // Parameters for VerifyVolume
  10078. //
  10079. struct {
  10080. PVOID DoNotUse1;
  10081. PDEVICE_OBJECT DeviceObject;
  10082. } VerifyVolume;
  10083. //
  10084. // Parameters for Scsi with internal device contorl.
  10085. //
  10086. struct {
  10087. struct _SCSI_REQUEST_BLOCK *Srb;
  10088. } Scsi;
  10089. //
  10090. // Parameters for IRP_MN_QUERY_DEVICE_RELATIONS
  10091. //
  10092. struct {
  10093. DEVICE_RELATION_TYPE Type;
  10094. } QueryDeviceRelations;
  10095. //
  10096. // Parameters for IRP_MN_QUERY_INTERFACE
  10097. //
  10098. struct {
  10099. CONST GUID *InterfaceType;
  10100. USHORT Size;
  10101. USHORT Version;
  10102. PINTERFACE Interface;
  10103. PVOID InterfaceSpecificData;
  10104. } QueryInterface;
  10105. //
  10106. // Parameters for IRP_MN_QUERY_CAPABILITIES
  10107. //
  10108. struct {
  10109. PDEVICE_CAPABILITIES Capabilities;
  10110. } DeviceCapabilities;
  10111. //
  10112. // Parameters for IRP_MN_FILTER_RESOURCE_REQUIREMENTS
  10113. //
  10114. struct {
  10115. PIO_RESOURCE_REQUIREMENTS_LIST IoResourceRequirementList;
  10116. } FilterResourceRequirements;
  10117. //
  10118. // Parameters for IRP_MN_READ_CONFIG and IRP_MN_WRITE_CONFIG
  10119. //
  10120. struct {
  10121. ULONG WhichSpace;
  10122. PVOID Buffer;
  10123. ULONG Offset;
  10124. ULONG POINTER_ALIGNMENT Length;
  10125. } ReadWriteConfig;
  10126. //
  10127. // Parameters for IRP_MN_SET_LOCK
  10128. //
  10129. struct {
  10130. BOOLEAN Lock;
  10131. } SetLock;
  10132. //
  10133. // Parameters for IRP_MN_QUERY_ID
  10134. //
  10135. struct {
  10136. BUS_QUERY_ID_TYPE IdType;
  10137. } QueryId;
  10138. //
  10139. // Parameters for IRP_MN_QUERY_DEVICE_TEXT
  10140. //
  10141. struct {
  10142. DEVICE_TEXT_TYPE DeviceTextType;
  10143. LCID POINTER_ALIGNMENT LocaleId;
  10144. } QueryDeviceText;
  10145. //
  10146. // Parameters for IRP_MN_DEVICE_USAGE_NOTIFICATION
  10147. //
  10148. struct {
  10149. BOOLEAN InPath;
  10150. BOOLEAN Reserved[3];
  10151. DEVICE_USAGE_NOTIFICATION_TYPE POINTER_ALIGNMENT Type;
  10152. } UsageNotification;
  10153. //
  10154. // Parameters for IRP_MN_WAIT_WAKE
  10155. //
  10156. struct {
  10157. SYSTEM_POWER_STATE PowerState;
  10158. } WaitWake;
  10159. //
  10160. // Parameter for IRP_MN_POWER_SEQUENCE
  10161. //
  10162. struct {
  10163. PPOWER_SEQUENCE PowerSequence;
  10164. } PowerSequence;
  10165. //
  10166. // Parameters for IRP_MN_SET_POWER and IRP_MN_QUERY_POWER
  10167. //
  10168. struct {
  10169. ULONG SystemContext;
  10170. POWER_STATE_TYPE POINTER_ALIGNMENT Type;
  10171. POWER_STATE POINTER_ALIGNMENT State;
  10172. POWER_ACTION POINTER_ALIGNMENT ShutdownType;
  10173. } Power;
  10174. //
  10175. // Parameters for StartDevice
  10176. //
  10177. struct {
  10178. PCM_RESOURCE_LIST AllocatedResources;
  10179. PCM_RESOURCE_LIST AllocatedResourcesTranslated;
  10180. } StartDevice;
  10181. //
  10182. // Parameters for Cleanup
  10183. //
  10184. // No extra parameters supplied
  10185. //
  10186. //
  10187. // WMI Irps
  10188. //
  10189. struct {
  10190. ULONG_PTR ProviderId;
  10191. PVOID DataPath;
  10192. ULONG BufferSize;
  10193. PVOID Buffer;
  10194. } WMI;
  10195. //
  10196. // Others - driver-specific
  10197. //
  10198. struct {
  10199. PVOID Argument1;
  10200. PVOID Argument2;
  10201. PVOID Argument3;
  10202. PVOID Argument4;
  10203. } Others;
  10204. } Parameters;
  10205. //
  10206. // Save a pointer to this device driver's device object for this request
  10207. // so it can be passed to the completion routine if needed.
  10208. //
  10209. PDEVICE_OBJECT DeviceObject;
  10210. //
  10211. // The following location contains a pointer to the file object for this
  10212. //
  10213. PFILE_OBJECT FileObject;
  10214. //
  10215. // The following routine is invoked depending on the flags in the above
  10216. // flags field.
  10217. //
  10218. PIO_COMPLETION_ROUTINE CompletionRoutine;
  10219. //
  10220. // The following is used to store the address of the context parameter
  10221. // that should be passed to the CompletionRoutine.
  10222. //
  10223. PVOID Context;
  10224. } IO_STACK_LOCATION, *PIO_STACK_LOCATION;
  10225. #if !defined(_AMD64_) && !defined(_IA64_)
  10226. #include "poppack.h"
  10227. #endif
  10228. //
  10229. // Define the share access structure used by file systems to determine
  10230. // whether or not another accessor may open the file.
  10231. //
  10232. typedef struct _SHARE_ACCESS {
  10233. ULONG OpenCount;
  10234. ULONG Readers;
  10235. ULONG Writers;
  10236. ULONG Deleters;
  10237. ULONG SharedRead;
  10238. ULONG SharedWrite;
  10239. ULONG SharedDelete;
  10240. } SHARE_ACCESS, *PSHARE_ACCESS;
  10241. //
  10242. // Public I/O routine definitions
  10243. //
  10244. NTKERNELAPI
  10245. VOID
  10246. IoAcquireCancelSpinLock(
  10247. OUT PKIRQL Irql
  10248. );
  10249. NTKERNELAPI
  10250. NTSTATUS
  10251. IoAllocateDriverObjectExtension(
  10252. IN PDRIVER_OBJECT DriverObject,
  10253. IN PVOID ClientIdentificationAddress,
  10254. IN ULONG DriverObjectExtensionSize,
  10255. OUT PVOID *DriverObjectExtension
  10256. );
  10257. NTKERNELAPI
  10258. PVOID
  10259. IoAllocateErrorLogEntry(
  10260. IN PVOID IoObject,
  10261. IN UCHAR EntrySize
  10262. );
  10263. NTKERNELAPI
  10264. PIRP
  10265. IoAllocateIrp(
  10266. IN CCHAR StackSize,
  10267. IN BOOLEAN ChargeQuota
  10268. );
  10269. NTKERNELAPI
  10270. PMDL
  10271. IoAllocateMdl(
  10272. IN PVOID VirtualAddress,
  10273. IN ULONG Length,
  10274. IN BOOLEAN SecondaryBuffer,
  10275. IN BOOLEAN ChargeQuota,
  10276. IN OUT PIRP Irp OPTIONAL
  10277. );
  10278. typedef enum _IO_PAGING_PRIORITY {
  10279. IoPagingPriorityInvalid, // Returned if a non-paging IO IRP is passed.
  10280. IoPagingPriorityNormal, // For regular paging IO
  10281. IoPagingPriorityHigh, // For high priority paging IO
  10282. IoPagingPriorityReserved1, // Reserved for future use.
  10283. IoPagingPriorityReserved2 // Reserved for future use.
  10284. } IO_PAGING_PRIORITY;
  10285. NTKERNELAPI
  10286. NTSTATUS
  10287. IoAttachDevice(
  10288. IN PDEVICE_OBJECT SourceDevice,
  10289. IN PUNICODE_STRING TargetDevice,
  10290. OUT PDEVICE_OBJECT *AttachedDevice
  10291. );
  10292. NTKERNELAPI
  10293. PDEVICE_OBJECT
  10294. IoAttachDeviceToDeviceStack(
  10295. IN PDEVICE_OBJECT SourceDevice,
  10296. IN PDEVICE_OBJECT TargetDevice
  10297. );
  10298. NTKERNELAPI
  10299. PIRP
  10300. IoBuildAsynchronousFsdRequest(
  10301. IN ULONG MajorFunction,
  10302. IN PDEVICE_OBJECT DeviceObject,
  10303. IN OUT PVOID Buffer OPTIONAL,
  10304. IN ULONG Length OPTIONAL,
  10305. IN PLARGE_INTEGER StartingOffset OPTIONAL,
  10306. IN PIO_STATUS_BLOCK IoStatusBlock OPTIONAL
  10307. );
  10308. NTKERNELAPI
  10309. PIRP
  10310. IoBuildDeviceIoControlRequest(
  10311. IN ULONG IoControlCode,
  10312. IN PDEVICE_OBJECT DeviceObject,
  10313. IN PVOID InputBuffer OPTIONAL,
  10314. IN ULONG InputBufferLength,
  10315. OUT PVOID OutputBuffer OPTIONAL,
  10316. IN ULONG OutputBufferLength,
  10317. IN BOOLEAN InternalDeviceIoControl,
  10318. IN PKEVENT Event,
  10319. OUT PIO_STATUS_BLOCK IoStatusBlock
  10320. );
  10321. NTKERNELAPI
  10322. VOID
  10323. IoBuildPartialMdl(
  10324. IN PMDL SourceMdl,
  10325. IN OUT PMDL TargetMdl,
  10326. IN PVOID VirtualAddress,
  10327. IN ULONG Length
  10328. );
  10329. typedef struct _BOOTDISK_INFORMATION {
  10330. LONGLONG BootPartitionOffset;
  10331. LONGLONG SystemPartitionOffset;
  10332. ULONG BootDeviceSignature;
  10333. ULONG SystemDeviceSignature;
  10334. } BOOTDISK_INFORMATION, *PBOOTDISK_INFORMATION;
  10335. //
  10336. // This structure should follow the previous structure field for field.
  10337. //
  10338. typedef struct _BOOTDISK_INFORMATION_EX {
  10339. LONGLONG BootPartitionOffset;
  10340. LONGLONG SystemPartitionOffset;
  10341. ULONG BootDeviceSignature;
  10342. ULONG SystemDeviceSignature;
  10343. GUID BootDeviceGuid;
  10344. GUID SystemDeviceGuid;
  10345. BOOLEAN BootDeviceIsGpt;
  10346. BOOLEAN SystemDeviceIsGpt;
  10347. } BOOTDISK_INFORMATION_EX, *PBOOTDISK_INFORMATION_EX;
  10348. NTKERNELAPI
  10349. NTSTATUS
  10350. IoGetBootDiskInformation(
  10351. IN OUT PBOOTDISK_INFORMATION BootDiskInformation,
  10352. IN ULONG Size
  10353. );
  10354. NTKERNELAPI
  10355. PIRP
  10356. IoBuildSynchronousFsdRequest(
  10357. IN ULONG MajorFunction,
  10358. IN PDEVICE_OBJECT DeviceObject,
  10359. IN OUT PVOID Buffer OPTIONAL,
  10360. IN ULONG Length OPTIONAL,
  10361. IN PLARGE_INTEGER StartingOffset OPTIONAL,
  10362. IN PKEVENT Event,
  10363. OUT PIO_STATUS_BLOCK IoStatusBlock
  10364. );
  10365. NTKERNELAPI
  10366. NTSTATUS
  10367. FASTCALL
  10368. IofCallDriver(
  10369. IN PDEVICE_OBJECT DeviceObject,
  10370. IN OUT PIRP Irp
  10371. );
  10372. #define IoCallDriver(a,b) \
  10373. IofCallDriver(a,b)
  10374. NTKERNELAPI
  10375. BOOLEAN
  10376. IoCancelIrp(
  10377. IN PIRP Irp
  10378. );
  10379. NTKERNELAPI
  10380. NTSTATUS
  10381. IoCheckShareAccess(
  10382. IN ACCESS_MASK DesiredAccess,
  10383. IN ULONG DesiredShareAccess,
  10384. IN OUT PFILE_OBJECT FileObject,
  10385. IN OUT PSHARE_ACCESS ShareAccess,
  10386. IN BOOLEAN Update
  10387. );
  10388. //
  10389. // This value should be returned from completion routines to continue
  10390. // completing the IRP upwards. Otherwise, STATUS_MORE_PROCESSING_REQUIRED
  10391. // should be returned.
  10392. //
  10393. #define STATUS_CONTINUE_COMPLETION STATUS_SUCCESS
  10394. //
  10395. // Completion routines can also use this enumeration in place of status codes.
  10396. //
  10397. typedef enum _IO_COMPLETION_ROUTINE_RESULT {
  10398. ContinueCompletion = STATUS_CONTINUE_COMPLETION,
  10399. StopCompletion = STATUS_MORE_PROCESSING_REQUIRED
  10400. } IO_COMPLETION_ROUTINE_RESULT, *PIO_COMPLETION_ROUTINE_RESULT;
  10401. NTKERNELAPI
  10402. VOID
  10403. FASTCALL
  10404. IofCompleteRequest(
  10405. IN PIRP Irp,
  10406. IN CCHAR PriorityBoost
  10407. );
  10408. #define IoCompleteRequest(a,b) \
  10409. IofCompleteRequest(a,b)
  10410. NTKERNELAPI
  10411. NTSTATUS
  10412. IoConnectInterrupt(
  10413. OUT PKINTERRUPT *InterruptObject,
  10414. IN PKSERVICE_ROUTINE ServiceRoutine,
  10415. IN PVOID ServiceContext,
  10416. IN PKSPIN_LOCK SpinLock OPTIONAL,
  10417. IN ULONG Vector,
  10418. IN KIRQL Irql,
  10419. IN KIRQL SynchronizeIrql,
  10420. IN KINTERRUPT_MODE InterruptMode,
  10421. IN BOOLEAN ShareVector,
  10422. IN KAFFINITY ProcessorEnableMask,
  10423. IN BOOLEAN FloatingSave
  10424. );
  10425. NTKERNELAPI
  10426. NTSTATUS
  10427. IoCreateDevice(
  10428. IN PDRIVER_OBJECT DriverObject,
  10429. IN ULONG DeviceExtensionSize,
  10430. IN PUNICODE_STRING DeviceName OPTIONAL,
  10431. IN DEVICE_TYPE DeviceType,
  10432. IN ULONG DeviceCharacteristics,
  10433. IN BOOLEAN Exclusive,
  10434. OUT PDEVICE_OBJECT *DeviceObject
  10435. );
  10436. #define WDM_MAJORVERSION 0x01
  10437. #define WDM_MINORVERSION 0x30
  10438. NTKERNELAPI
  10439. BOOLEAN
  10440. IoIsWdmVersionAvailable(
  10441. IN UCHAR MajorVersion,
  10442. IN UCHAR MinorVersion
  10443. );
  10444. NTKERNELAPI
  10445. NTSTATUS
  10446. IoCreateFile(
  10447. OUT PHANDLE FileHandle,
  10448. IN ACCESS_MASK DesiredAccess,
  10449. IN POBJECT_ATTRIBUTES ObjectAttributes,
  10450. OUT PIO_STATUS_BLOCK IoStatusBlock,
  10451. IN PLARGE_INTEGER AllocationSize OPTIONAL,
  10452. IN ULONG FileAttributes,
  10453. IN ULONG ShareAccess,
  10454. IN ULONG Disposition,
  10455. IN ULONG CreateOptions,
  10456. IN PVOID EaBuffer OPTIONAL,
  10457. IN ULONG EaLength,
  10458. IN CREATE_FILE_TYPE CreateFileType,
  10459. IN PVOID ExtraCreateParameters OPTIONAL,
  10460. IN ULONG Options
  10461. );
  10462. NTKERNELAPI
  10463. PKEVENT
  10464. IoCreateNotificationEvent(
  10465. IN PUNICODE_STRING EventName,
  10466. OUT PHANDLE EventHandle
  10467. );
  10468. NTKERNELAPI
  10469. NTSTATUS
  10470. IoCreateSymbolicLink(
  10471. IN PUNICODE_STRING SymbolicLinkName,
  10472. IN PUNICODE_STRING DeviceName
  10473. );
  10474. NTKERNELAPI
  10475. PKEVENT
  10476. IoCreateSynchronizationEvent(
  10477. IN PUNICODE_STRING EventName,
  10478. OUT PHANDLE EventHandle
  10479. );
  10480. NTKERNELAPI
  10481. NTSTATUS
  10482. IoCreateUnprotectedSymbolicLink(
  10483. IN PUNICODE_STRING SymbolicLinkName,
  10484. IN PUNICODE_STRING DeviceName
  10485. );
  10486. NTKERNELAPI
  10487. VOID
  10488. IoDeleteDevice(
  10489. IN PDEVICE_OBJECT DeviceObject
  10490. );
  10491. NTKERNELAPI
  10492. NTSTATUS
  10493. IoDeleteSymbolicLink(
  10494. IN PUNICODE_STRING SymbolicLinkName
  10495. );
  10496. NTKERNELAPI
  10497. VOID
  10498. IoDetachDevice(
  10499. IN OUT PDEVICE_OBJECT TargetDevice
  10500. );
  10501. NTKERNELAPI
  10502. VOID
  10503. IoDisconnectInterrupt(
  10504. IN PKINTERRUPT InterruptObject
  10505. );
  10506. NTKERNELAPI
  10507. VOID
  10508. IoFreeIrp(
  10509. IN PIRP Irp
  10510. );
  10511. NTKERNELAPI
  10512. VOID
  10513. IoFreeMdl(
  10514. IN PMDL Mdl
  10515. );
  10516. NTKERNELAPI
  10517. PDEVICE_OBJECT
  10518. IoGetAttachedDeviceReference(
  10519. IN PDEVICE_OBJECT DeviceObject
  10520. );
  10521. //++
  10522. //
  10523. // PIO_STACK_LOCATION
  10524. // IoGetCurrentIrpStackLocation(
  10525. // IN PIRP Irp
  10526. // )
  10527. //
  10528. // Routine Description:
  10529. //
  10530. // This routine is invoked to return a pointer to the current stack location
  10531. // in an I/O Request Packet (IRP).
  10532. //
  10533. // Arguments:
  10534. //
  10535. // Irp - Pointer to the I/O Request Packet.
  10536. //
  10537. // Return Value:
  10538. //
  10539. // The function value is a pointer to the current stack location in the
  10540. // packet.
  10541. //
  10542. //--
  10543. #define IoGetCurrentIrpStackLocation( Irp ) ( (Irp)->Tail.Overlay.CurrentStackLocation )
  10544. NTKERNELAPI
  10545. PVOID
  10546. IoGetDriverObjectExtension(
  10547. IN PDRIVER_OBJECT DriverObject,
  10548. IN PVOID ClientIdentificationAddress
  10549. );
  10550. NTKERNELAPI
  10551. PEPROCESS
  10552. IoGetCurrentProcess(
  10553. VOID
  10554. );
  10555. NTKERNELAPI
  10556. NTSTATUS
  10557. IoGetDeviceObjectPointer(
  10558. IN PUNICODE_STRING ObjectName,
  10559. IN ACCESS_MASK DesiredAccess,
  10560. OUT PFILE_OBJECT *FileObject,
  10561. OUT PDEVICE_OBJECT *DeviceObject
  10562. );
  10563. NTKERNELAPI
  10564. struct _DMA_ADAPTER *
  10565. IoGetDmaAdapter(
  10566. IN PDEVICE_OBJECT PhysicalDeviceObject,
  10567. IN struct _DEVICE_DESCRIPTION *DeviceDescription,
  10568. IN OUT PULONG NumberOfMapRegisters
  10569. );
  10570. NTKERNELAPI
  10571. BOOLEAN
  10572. IoForwardIrpSynchronously(
  10573. IN PDEVICE_OBJECT DeviceObject,
  10574. IN PIRP Irp
  10575. );
  10576. #define IoForwardAndCatchIrp IoForwardIrpSynchronously
  10577. //++
  10578. //
  10579. // ULONG
  10580. // IoGetFunctionCodeFromCtlCode(
  10581. // IN ULONG ControlCode
  10582. // )
  10583. //
  10584. // Routine Description:
  10585. //
  10586. // This routine extracts the function code from IOCTL and FSCTL function
  10587. // control codes.
  10588. // This routine should only be used by kernel mode code.
  10589. //
  10590. // Arguments:
  10591. //
  10592. // ControlCode - A function control code (IOCTL or FSCTL) from which the
  10593. // function code must be extracted.
  10594. //
  10595. // Return Value:
  10596. //
  10597. // The extracted function code.
  10598. //
  10599. // Note:
  10600. //
  10601. // The CTL_CODE macro, used to create IOCTL and FSCTL function control
  10602. // codes, is defined in ntioapi.h
  10603. //
  10604. //--
  10605. #define IoGetFunctionCodeFromCtlCode( ControlCode ) (\
  10606. ( ControlCode >> 2) & 0x00000FFF )
  10607. NTKERNELAPI
  10608. PVOID
  10609. IoGetInitialStack(
  10610. VOID
  10611. );
  10612. NTKERNELAPI
  10613. VOID
  10614. IoGetStackLimits (
  10615. OUT PULONG_PTR LowLimit,
  10616. OUT PULONG_PTR HighLimit
  10617. );
  10618. //
  10619. // The following function is used to tell the caller how much stack is available
  10620. //
  10621. FORCEINLINE
  10622. ULONG_PTR
  10623. IoGetRemainingStackSize (
  10624. VOID
  10625. )
  10626. {
  10627. ULONG_PTR Top;
  10628. ULONG_PTR Bottom;
  10629. IoGetStackLimits( &Bottom, &Top );
  10630. return((ULONG_PTR)(&Top) - Bottom );
  10631. }
  10632. //++
  10633. //
  10634. // PIO_STACK_LOCATION
  10635. // IoGetNextIrpStackLocation(
  10636. // IN PIRP Irp
  10637. // )
  10638. //
  10639. // Routine Description:
  10640. //
  10641. // This routine is invoked to return a pointer to the next stack location
  10642. // in an I/O Request Packet (IRP).
  10643. //
  10644. // Arguments:
  10645. //
  10646. // Irp - Pointer to the I/O Request Packet.
  10647. //
  10648. // Return Value:
  10649. //
  10650. // The function value is a pointer to the next stack location in the packet.
  10651. //
  10652. //--
  10653. #define IoGetNextIrpStackLocation( Irp ) (\
  10654. (Irp)->Tail.Overlay.CurrentStackLocation - 1 )
  10655. NTKERNELAPI
  10656. PDEVICE_OBJECT
  10657. IoGetRelatedDeviceObject(
  10658. IN PFILE_OBJECT FileObject
  10659. );
  10660. //++
  10661. //
  10662. // VOID
  10663. // IoInitializeDpcRequest(
  10664. // IN PDEVICE_OBJECT DeviceObject,
  10665. // IN PIO_DPC_ROUTINE DpcRoutine
  10666. // )
  10667. //
  10668. // Routine Description:
  10669. //
  10670. // This routine is invoked to initialize the DPC in a device object for a
  10671. // device driver during its initialization routine. The DPC is used later
  10672. // when the driver interrupt service routine requests that a DPC routine
  10673. // be queued for later execution.
  10674. //
  10675. // Arguments:
  10676. //
  10677. // DeviceObject - Pointer to the device object that the request is for.
  10678. //
  10679. // DpcRoutine - Address of the driver's DPC routine to be executed when
  10680. // the DPC is dequeued for processing.
  10681. //
  10682. // Return Value:
  10683. //
  10684. // None.
  10685. //
  10686. //--
  10687. #define IoInitializeDpcRequest( DeviceObject, DpcRoutine ) (\
  10688. KeInitializeDpc( &(DeviceObject)->Dpc, \
  10689. (PKDEFERRED_ROUTINE) (DpcRoutine), \
  10690. (DeviceObject) ) )
  10691. NTKERNELAPI
  10692. VOID
  10693. IoInitializeIrp(
  10694. IN OUT PIRP Irp,
  10695. IN USHORT PacketSize,
  10696. IN CCHAR StackSize
  10697. );
  10698. NTKERNELAPI
  10699. NTSTATUS
  10700. IoInitializeTimer(
  10701. IN PDEVICE_OBJECT DeviceObject,
  10702. IN PIO_TIMER_ROUTINE TimerRoutine,
  10703. IN PVOID Context
  10704. );
  10705. NTKERNELAPI
  10706. VOID
  10707. IoReuseIrp(
  10708. IN OUT PIRP Irp,
  10709. IN NTSTATUS Iostatus
  10710. );
  10711. //++
  10712. //
  10713. // BOOLEAN
  10714. // IoIsErrorUserInduced(
  10715. // IN NTSTATUS Status
  10716. // )
  10717. //
  10718. // Routine Description:
  10719. //
  10720. // This routine is invoked to determine if an error was as a
  10721. // result of user actions. Typically these error are related
  10722. // to removable media and will result in a pop-up.
  10723. //
  10724. // Arguments:
  10725. //
  10726. // Status - The status value to check.
  10727. //
  10728. // Return Value:
  10729. // The function value is TRUE if the user induced the error,
  10730. // otherwise FALSE is returned.
  10731. //
  10732. //--
  10733. #define IoIsErrorUserInduced( Status ) ((BOOLEAN) \
  10734. (((Status) == STATUS_DEVICE_NOT_READY) || \
  10735. ((Status) == STATUS_IO_TIMEOUT) || \
  10736. ((Status) == STATUS_MEDIA_WRITE_PROTECTED) || \
  10737. ((Status) == STATUS_NO_MEDIA_IN_DEVICE) || \
  10738. ((Status) == STATUS_VERIFY_REQUIRED) || \
  10739. ((Status) == STATUS_UNRECOGNIZED_MEDIA) || \
  10740. ((Status) == STATUS_WRONG_VOLUME)))
  10741. //++
  10742. //
  10743. // VOID
  10744. // IoMarkIrpPending(
  10745. // IN OUT PIRP Irp
  10746. // )
  10747. //
  10748. // Routine Description:
  10749. //
  10750. // This routine marks the specified I/O Request Packet (IRP) to indicate
  10751. // that an initial status of STATUS_PENDING was returned to the caller.
  10752. // This is used so that I/O completion can determine whether or not to
  10753. // fully complete the I/O operation requested by the packet.
  10754. //
  10755. // Arguments:
  10756. //
  10757. // Irp - Pointer to the I/O Request Packet to be marked pending.
  10758. //
  10759. // Return Value:
  10760. //
  10761. // None.
  10762. //
  10763. //--
  10764. #define IoMarkIrpPending( Irp ) ( \
  10765. IoGetCurrentIrpStackLocation( (Irp) )->Control |= SL_PENDING_RETURNED )
  10766. NTKERNELAPI
  10767. VOID
  10768. IoReleaseCancelSpinLock(
  10769. IN KIRQL Irql
  10770. );
  10771. //++
  10772. //
  10773. // VOID
  10774. // IoRequestDpc(
  10775. // IN PDEVICE_OBJECT DeviceObject,
  10776. // IN PIRP Irp,
  10777. // IN PVOID Context
  10778. // )
  10779. //
  10780. // Routine Description:
  10781. //
  10782. // This routine is invoked by the device driver's interrupt service routine
  10783. // to request that a DPC routine be queued for later execution at a lower
  10784. // IRQL.
  10785. //
  10786. // Arguments:
  10787. //
  10788. // DeviceObject - Device object for which the request is being processed.
  10789. //
  10790. // Irp - Pointer to the current I/O Request Packet (IRP) for the specified
  10791. // device.
  10792. //
  10793. // Context - Provides a general context parameter to be passed to the
  10794. // DPC routine.
  10795. //
  10796. // Return Value:
  10797. //
  10798. // None.
  10799. //
  10800. //--
  10801. #define IoRequestDpc( DeviceObject, Irp, Context ) ( \
  10802. KeInsertQueueDpc( &(DeviceObject)->Dpc, (Irp), (Context) ) )
  10803. //++
  10804. //
  10805. // PDRIVER_CANCEL
  10806. // IoSetCancelRoutine(
  10807. // IN PIRP Irp,
  10808. // IN PDRIVER_CANCEL CancelRoutine
  10809. // )
  10810. //
  10811. // Routine Description:
  10812. //
  10813. // This routine is invoked to set the address of a cancel routine which
  10814. // is to be invoked when an I/O packet has been canceled.
  10815. //
  10816. // Arguments:
  10817. //
  10818. // Irp - Pointer to the I/O Request Packet itself.
  10819. //
  10820. // CancelRoutine - Address of the cancel routine that is to be invoked
  10821. // if the IRP is cancelled.
  10822. //
  10823. // Return Value:
  10824. //
  10825. // Previous value of CancelRoutine field in the IRP.
  10826. //
  10827. //--
  10828. #define IoSetCancelRoutine( Irp, NewCancelRoutine ) ( \
  10829. (PDRIVER_CANCEL) (ULONG_PTR) InterlockedExchangePointer( (PVOID *) &(Irp)->CancelRoutine, (PVOID) (ULONG_PTR)(NewCancelRoutine) ) )
  10830. //++
  10831. //
  10832. // VOID
  10833. // IoSetCompletionRoutine(
  10834. // IN PIRP Irp,
  10835. // IN PIO_COMPLETION_ROUTINE CompletionRoutine,
  10836. // IN PVOID Context,
  10837. // IN BOOLEAN InvokeOnSuccess,
  10838. // IN BOOLEAN InvokeOnError,
  10839. // IN BOOLEAN InvokeOnCancel
  10840. // )
  10841. //
  10842. // Routine Description:
  10843. //
  10844. // This routine is invoked to set the address of a completion routine which
  10845. // is to be invoked when an I/O packet has been completed by a lower-level
  10846. // driver.
  10847. //
  10848. // Arguments:
  10849. //
  10850. // Irp - Pointer to the I/O Request Packet itself.
  10851. //
  10852. // CompletionRoutine - Address of the completion routine that is to be
  10853. // invoked once the next level driver completes the packet.
  10854. //
  10855. // Context - Specifies a context parameter to be passed to the completion
  10856. // routine.
  10857. //
  10858. // InvokeOnSuccess - Specifies that the completion routine is invoked when the
  10859. // operation is successfully completed.
  10860. //
  10861. // InvokeOnError - Specifies that the completion routine is invoked when the
  10862. // operation completes with an error status.
  10863. //
  10864. // InvokeOnCancel - Specifies that the completion routine is invoked when the
  10865. // operation is being canceled.
  10866. //
  10867. // Return Value:
  10868. //
  10869. // None.
  10870. //
  10871. //--
  10872. #define IoSetCompletionRoutine( Irp, Routine, CompletionContext, Success, Error, Cancel ) { \
  10873. PIO_STACK_LOCATION __irpSp; \
  10874. ASSERT( (Success) | (Error) | (Cancel) ? (Routine) != NULL : TRUE ); \
  10875. __irpSp = IoGetNextIrpStackLocation( (Irp) ); \
  10876. __irpSp->CompletionRoutine = (Routine); \
  10877. __irpSp->Context = (CompletionContext); \
  10878. __irpSp->Control = 0; \
  10879. if ((Success)) { __irpSp->Control = SL_INVOKE_ON_SUCCESS; } \
  10880. if ((Error)) { __irpSp->Control |= SL_INVOKE_ON_ERROR; } \
  10881. if ((Cancel)) { __irpSp->Control |= SL_INVOKE_ON_CANCEL; } }
  10882. NTSTATUS
  10883. IoSetCompletionRoutineEx(
  10884. IN PDEVICE_OBJECT DeviceObject,
  10885. IN PIRP Irp,
  10886. IN PIO_COMPLETION_ROUTINE CompletionRoutine,
  10887. IN PVOID Context,
  10888. IN BOOLEAN InvokeOnSuccess,
  10889. IN BOOLEAN InvokeOnError,
  10890. IN BOOLEAN InvokeOnCancel
  10891. );
  10892. //++
  10893. //
  10894. // VOID
  10895. // IoSetNextIrpStackLocation (
  10896. // IN OUT PIRP Irp
  10897. // )
  10898. //
  10899. // Routine Description:
  10900. //
  10901. // This routine is invoked to set the current IRP stack location to
  10902. // the next stack location, i.e. it "pushes" the stack.
  10903. //
  10904. // Arguments:
  10905. //
  10906. // Irp - Pointer to the I/O Request Packet (IRP).
  10907. //
  10908. // Return Value:
  10909. //
  10910. // None.
  10911. //
  10912. //--
  10913. #define IoSetNextIrpStackLocation( Irp ) { \
  10914. (Irp)->CurrentLocation--; \
  10915. (Irp)->Tail.Overlay.CurrentStackLocation--; }
  10916. //++
  10917. //
  10918. // VOID
  10919. // IoCopyCurrentIrpStackLocationToNext(
  10920. // IN PIRP Irp
  10921. // )
  10922. //
  10923. // Routine Description:
  10924. //
  10925. // This routine is invoked to copy the IRP stack arguments and file
  10926. // pointer from the current IrpStackLocation to the next
  10927. // in an I/O Request Packet (IRP).
  10928. //
  10929. // If the caller wants to call IoCallDriver with a completion routine
  10930. // but does not wish to change the arguments otherwise,
  10931. // the caller first calls IoCopyCurrentIrpStackLocationToNext,
  10932. // then IoSetCompletionRoutine, then IoCallDriver.
  10933. //
  10934. // Arguments:
  10935. //
  10936. // Irp - Pointer to the I/O Request Packet.
  10937. //
  10938. // Return Value:
  10939. //
  10940. // None.
  10941. //
  10942. //--
  10943. #define IoCopyCurrentIrpStackLocationToNext( Irp ) { \
  10944. PIO_STACK_LOCATION __irpSp; \
  10945. PIO_STACK_LOCATION __nextIrpSp; \
  10946. __irpSp = IoGetCurrentIrpStackLocation( (Irp) ); \
  10947. __nextIrpSp = IoGetNextIrpStackLocation( (Irp) ); \
  10948. RtlCopyMemory( __nextIrpSp, __irpSp, FIELD_OFFSET(IO_STACK_LOCATION, CompletionRoutine)); \
  10949. __nextIrpSp->Control = 0; }
  10950. //++
  10951. //
  10952. // VOID
  10953. // IoSkipCurrentIrpStackLocation (
  10954. // IN PIRP Irp
  10955. // )
  10956. //
  10957. // Routine Description:
  10958. //
  10959. // This routine is invoked to increment the current stack location of
  10960. // a given IRP.
  10961. //
  10962. // If the caller wishes to call the next driver in a stack, and does not
  10963. // wish to change the arguments, nor does he wish to set a completion
  10964. // routine, then the caller first calls IoSkipCurrentIrpStackLocation
  10965. // and the calls IoCallDriver.
  10966. //
  10967. // Arguments:
  10968. //
  10969. // Irp - Pointer to the I/O Request Packet.
  10970. //
  10971. // Return Value:
  10972. //
  10973. // None
  10974. //
  10975. //--
  10976. #define IoSkipCurrentIrpStackLocation( Irp ) { \
  10977. (Irp)->CurrentLocation++; \
  10978. (Irp)->Tail.Overlay.CurrentStackLocation++; }
  10979. NTKERNELAPI
  10980. VOID
  10981. IoSetShareAccess(
  10982. IN ACCESS_MASK DesiredAccess,
  10983. IN ULONG DesiredShareAccess,
  10984. IN OUT PFILE_OBJECT FileObject,
  10985. OUT PSHARE_ACCESS ShareAccess
  10986. );
  10987. typedef struct _IO_REMOVE_LOCK_TRACKING_BLOCK * PIO_REMOVE_LOCK_TRACKING_BLOCK;
  10988. typedef struct _IO_REMOVE_LOCK_COMMON_BLOCK {
  10989. BOOLEAN Removed;
  10990. BOOLEAN Reserved [3];
  10991. LONG IoCount;
  10992. KEVENT RemoveEvent;
  10993. } IO_REMOVE_LOCK_COMMON_BLOCK;
  10994. typedef struct _IO_REMOVE_LOCK_DBG_BLOCK {
  10995. LONG Signature;
  10996. ULONG HighWatermark;
  10997. LONGLONG MaxLockedTicks;
  10998. LONG AllocateTag;
  10999. LIST_ENTRY LockList;
  11000. KSPIN_LOCK Spin;
  11001. LONG LowMemoryCount;
  11002. ULONG Reserved1[4];
  11003. PVOID Reserved2;
  11004. PIO_REMOVE_LOCK_TRACKING_BLOCK Blocks;
  11005. } IO_REMOVE_LOCK_DBG_BLOCK;
  11006. typedef struct _IO_REMOVE_LOCK {
  11007. IO_REMOVE_LOCK_COMMON_BLOCK Common;
  11008. #if DBG
  11009. IO_REMOVE_LOCK_DBG_BLOCK Dbg;
  11010. #endif
  11011. } IO_REMOVE_LOCK, *PIO_REMOVE_LOCK;
  11012. #define IoInitializeRemoveLock(Lock, Tag, Maxmin, HighWater) \
  11013. IoInitializeRemoveLockEx (Lock, Tag, Maxmin, HighWater, sizeof (IO_REMOVE_LOCK))
  11014. NTSYSAPI
  11015. VOID
  11016. NTAPI
  11017. IoInitializeRemoveLockEx(
  11018. IN PIO_REMOVE_LOCK Lock,
  11019. IN ULONG AllocateTag, // Used only on checked kernels
  11020. IN ULONG MaxLockedMinutes, // Used only on checked kernels
  11021. IN ULONG HighWatermark, // Used only on checked kernels
  11022. IN ULONG RemlockSize // are we checked or free
  11023. );
  11024. //
  11025. // Initialize a remove lock.
  11026. //
  11027. // Note: Allocation for remove locks needs to be within the device extension,
  11028. // so that the memory for this structure stays allocated until such time as the
  11029. // device object itself is deallocated.
  11030. //
  11031. #define IoAcquireRemoveLock(RemoveLock, Tag) \
  11032. IoAcquireRemoveLockEx(RemoveLock, Tag, __FILE__, __LINE__, sizeof (IO_REMOVE_LOCK))
  11033. NTSYSAPI
  11034. NTSTATUS
  11035. NTAPI
  11036. IoAcquireRemoveLockEx (
  11037. IN PIO_REMOVE_LOCK RemoveLock,
  11038. IN OPTIONAL PVOID Tag, // Optional
  11039. IN PCSTR File,
  11040. IN ULONG Line,
  11041. IN ULONG RemlockSize // are we checked or free
  11042. );
  11043. //
  11044. // Routine Description:
  11045. //
  11046. // This routine is called to acquire the remove lock for a device object.
  11047. // While the lock is held, the caller can assume that no pending pnp REMOVE
  11048. // requests will be completed.
  11049. //
  11050. // The lock should be acquired immediately upon entering a dispatch routine.
  11051. // It should also be acquired before creating any new reference to the
  11052. // device object if there's a chance of releasing the reference before the
  11053. // new one is done, in addition to references to the driver code itself,
  11054. // which is removed from memory when the last device object goes.
  11055. //
  11056. // Arguments:
  11057. //
  11058. // RemoveLock - A pointer to an initialized REMOVE_LOCK structure.
  11059. //
  11060. // Tag - Used for tracking lock allocation and release. The same tag
  11061. // specified when acquiring the lock must be used to release the lock.
  11062. // Tags are only checked in checked versions of the driver.
  11063. //
  11064. // File - set to __FILE__ as the location in the code where the lock was taken.
  11065. //
  11066. // Line - set to __LINE__.
  11067. //
  11068. // Return Value:
  11069. //
  11070. // Returns whether or not the remove lock was obtained.
  11071. // If successful the caller should continue with work calling
  11072. // IoReleaseRemoveLock when finished.
  11073. //
  11074. // If not successful the lock was not obtained. The caller should abort the
  11075. // work but not call IoReleaseRemoveLock.
  11076. //
  11077. #define IoReleaseRemoveLock(RemoveLock, Tag) \
  11078. IoReleaseRemoveLockEx(RemoveLock, Tag, sizeof (IO_REMOVE_LOCK))
  11079. NTSYSAPI
  11080. VOID
  11081. NTAPI
  11082. IoReleaseRemoveLockEx(
  11083. IN PIO_REMOVE_LOCK RemoveLock,
  11084. IN PVOID Tag, // Optional
  11085. IN ULONG RemlockSize // are we checked or free
  11086. );
  11087. //
  11088. //
  11089. // Routine Description:
  11090. //
  11091. // This routine is called to release the remove lock on the device object. It
  11092. // must be called when finished using a previously locked reference to the
  11093. // device object. If an Tag was specified when acquiring the lock then the
  11094. // same Tag must be specified when releasing the lock.
  11095. //
  11096. // When the lock count reduces to zero, this routine will signal the waiting
  11097. // event to release the waiting thread deleting the device object protected
  11098. // by this lock.
  11099. //
  11100. // Arguments:
  11101. //
  11102. // DeviceObject - the device object to lock
  11103. //
  11104. // Tag - The TAG (if any) specified when acquiring the lock. This is used
  11105. // for lock tracking purposes
  11106. //
  11107. // Return Value:
  11108. //
  11109. // none
  11110. //
  11111. #define IoReleaseRemoveLockAndWait(RemoveLock, Tag) \
  11112. IoReleaseRemoveLockAndWaitEx(RemoveLock, Tag, sizeof (IO_REMOVE_LOCK))
  11113. NTSYSAPI
  11114. VOID
  11115. NTAPI
  11116. IoReleaseRemoveLockAndWaitEx(
  11117. IN PIO_REMOVE_LOCK RemoveLock,
  11118. IN PVOID Tag,
  11119. IN ULONG RemlockSize // are we checked or free
  11120. );
  11121. //
  11122. //
  11123. // Routine Description:
  11124. //
  11125. // This routine is called when the client would like to delete the
  11126. // remove-locked resource. This routine will block until all the remove
  11127. // locks have released.
  11128. //
  11129. // This routine MUST be called after acquiring the lock.
  11130. //
  11131. // Arguments:
  11132. //
  11133. // RemoveLock
  11134. //
  11135. // Return Value:
  11136. //
  11137. // none
  11138. //
  11139. //++
  11140. //
  11141. // USHORT
  11142. // IoSizeOfIrp(
  11143. // IN CCHAR StackSize
  11144. // )
  11145. //
  11146. // Routine Description:
  11147. //
  11148. // Determines the size of an IRP given the number of stack locations
  11149. // the IRP will have.
  11150. //
  11151. // Arguments:
  11152. //
  11153. // StackSize - Number of stack locations for the IRP.
  11154. //
  11155. // Return Value:
  11156. //
  11157. // Size in bytes of the IRP.
  11158. //
  11159. //--
  11160. #define IoSizeOfIrp( StackSize ) \
  11161. ((USHORT) (sizeof( IRP ) + ((StackSize) * (sizeof( IO_STACK_LOCATION )))))
  11162. NTKERNELAPI
  11163. VOID
  11164. IoStartNextPacket(
  11165. IN PDEVICE_OBJECT DeviceObject,
  11166. IN BOOLEAN Cancelable
  11167. );
  11168. NTKERNELAPI
  11169. VOID
  11170. IoStartNextPacketByKey(
  11171. IN PDEVICE_OBJECT DeviceObject,
  11172. IN BOOLEAN Cancelable,
  11173. IN ULONG Key
  11174. );
  11175. NTKERNELAPI
  11176. VOID
  11177. IoStartPacket(
  11178. IN PDEVICE_OBJECT DeviceObject,
  11179. IN PIRP Irp,
  11180. IN PULONG Key OPTIONAL,
  11181. IN PDRIVER_CANCEL CancelFunction OPTIONAL
  11182. );
  11183. VOID
  11184. IoSetStartIoAttributes(
  11185. IN PDEVICE_OBJECT DeviceObject,
  11186. IN BOOLEAN DeferredStartIo,
  11187. IN BOOLEAN NonCancelable
  11188. );
  11189. NTKERNELAPI
  11190. VOID
  11191. IoStartTimer(
  11192. IN PDEVICE_OBJECT DeviceObject
  11193. );
  11194. NTKERNELAPI
  11195. VOID
  11196. IoStopTimer(
  11197. IN PDEVICE_OBJECT DeviceObject
  11198. );
  11199. NTKERNELAPI
  11200. VOID
  11201. IoUnregisterShutdownNotification(
  11202. IN PDEVICE_OBJECT DeviceObject
  11203. );
  11204. NTKERNELAPI
  11205. VOID
  11206. IoWriteErrorLogEntry(
  11207. IN PVOID ElEntry
  11208. );
  11209. typedef struct _IO_WORKITEM *PIO_WORKITEM;
  11210. typedef
  11211. VOID
  11212. (*PIO_WORKITEM_ROUTINE) (
  11213. IN PDEVICE_OBJECT DeviceObject,
  11214. IN PVOID Context
  11215. );
  11216. PIO_WORKITEM
  11217. IoAllocateWorkItem(
  11218. PDEVICE_OBJECT DeviceObject
  11219. );
  11220. VOID
  11221. IoFreeWorkItem(
  11222. PIO_WORKITEM IoWorkItem
  11223. );
  11224. VOID
  11225. IoQueueWorkItem(
  11226. IN PIO_WORKITEM IoWorkItem,
  11227. IN PIO_WORKITEM_ROUTINE WorkerRoutine,
  11228. IN WORK_QUEUE_TYPE QueueType,
  11229. IN PVOID Context
  11230. );
  11231. NTKERNELAPI
  11232. NTSTATUS
  11233. IoWMIRegistrationControl(
  11234. IN PDEVICE_OBJECT DeviceObject,
  11235. IN ULONG Action
  11236. );
  11237. //
  11238. // Action code for IoWMIRegistrationControl api
  11239. //
  11240. #define WMIREG_ACTION_REGISTER 1
  11241. #define WMIREG_ACTION_DEREGISTER 2
  11242. #define WMIREG_ACTION_REREGISTER 3
  11243. #define WMIREG_ACTION_UPDATE_GUIDS 4
  11244. #define WMIREG_ACTION_BLOCK_IRPS 5
  11245. //
  11246. // Code passed in IRP_MN_REGINFO WMI irp
  11247. //
  11248. #define WMIREGISTER 0
  11249. #define WMIUPDATE 1
  11250. NTKERNELAPI
  11251. NTSTATUS
  11252. IoWMIAllocateInstanceIds(
  11253. IN GUID *Guid,
  11254. IN ULONG InstanceCount,
  11255. OUT ULONG *FirstInstanceId
  11256. );
  11257. NTKERNELAPI
  11258. NTSTATUS
  11259. IoWMISuggestInstanceName(
  11260. IN PDEVICE_OBJECT PhysicalDeviceObject OPTIONAL,
  11261. IN PUNICODE_STRING SymbolicLinkName OPTIONAL,
  11262. IN BOOLEAN CombineNames,
  11263. OUT PUNICODE_STRING SuggestedInstanceName
  11264. );
  11265. NTKERNELAPI
  11266. NTSTATUS
  11267. IoWMIWriteEvent(
  11268. IN PVOID WnodeEventItem
  11269. );
  11270. #if defined(_WIN64)
  11271. NTKERNELAPI
  11272. ULONG IoWMIDeviceObjectToProviderId(
  11273. PDEVICE_OBJECT DeviceObject
  11274. );
  11275. #else
  11276. #define IoWMIDeviceObjectToProviderId(DeviceObject) ((ULONG)(DeviceObject))
  11277. #endif
  11278. NTKERNELAPI
  11279. NTSTATUS IoWMIOpenBlock(
  11280. IN GUID *DataBlockGuid,
  11281. IN ULONG DesiredAccess,
  11282. OUT PVOID *DataBlockObject
  11283. );
  11284. NTKERNELAPI
  11285. NTSTATUS IoWMIQueryAllData(
  11286. IN PVOID DataBlockObject,
  11287. IN OUT ULONG *InOutBufferSize,
  11288. OUT /* non paged */ PVOID OutBuffer
  11289. );
  11290. NTKERNELAPI
  11291. NTSTATUS
  11292. IoWMIQueryAllDataMultiple(
  11293. IN PVOID *DataBlockObjectList,
  11294. IN ULONG ObjectCount,
  11295. IN OUT ULONG *InOutBufferSize,
  11296. OUT /* non paged */ PVOID OutBuffer
  11297. );
  11298. NTKERNELAPI
  11299. NTSTATUS
  11300. IoWMIQuerySingleInstance(
  11301. IN PVOID DataBlockObject,
  11302. IN PUNICODE_STRING InstanceName,
  11303. IN OUT ULONG *InOutBufferSize,
  11304. OUT /* non paged */ PVOID OutBuffer
  11305. );
  11306. NTKERNELAPI
  11307. NTSTATUS
  11308. IoWMIQuerySingleInstanceMultiple(
  11309. IN PVOID *DataBlockObjectList,
  11310. IN PUNICODE_STRING InstanceNames,
  11311. IN ULONG ObjectCount,
  11312. IN OUT ULONG *InOutBufferSize,
  11313. OUT /* non paged */ PVOID OutBuffer
  11314. );
  11315. NTKERNELAPI
  11316. NTSTATUS
  11317. IoWMISetSingleInstance(
  11318. IN PVOID DataBlockObject,
  11319. IN PUNICODE_STRING InstanceName,
  11320. IN ULONG Version,
  11321. IN ULONG ValueBufferSize,
  11322. IN PVOID ValueBuffer
  11323. );
  11324. NTKERNELAPI
  11325. NTSTATUS
  11326. IoWMISetSingleItem(
  11327. IN PVOID DataBlockObject,
  11328. IN PUNICODE_STRING InstanceName,
  11329. IN ULONG DataItemId,
  11330. IN ULONG Version,
  11331. IN ULONG ValueBufferSize,
  11332. IN PVOID ValueBuffer
  11333. );
  11334. NTKERNELAPI
  11335. NTSTATUS
  11336. IoWMIExecuteMethod(
  11337. IN PVOID DataBlockObject,
  11338. IN PUNICODE_STRING InstanceName,
  11339. IN ULONG MethodId,
  11340. IN ULONG InBufferSize,
  11341. IN OUT PULONG OutBufferSize,
  11342. IN OUT PUCHAR InOutBuffer
  11343. );
  11344. typedef VOID (*WMI_NOTIFICATION_CALLBACK)(
  11345. PVOID Wnode,
  11346. PVOID Context
  11347. );
  11348. NTKERNELAPI
  11349. NTSTATUS
  11350. IoWMISetNotificationCallback(
  11351. IN PVOID Object,
  11352. IN WMI_NOTIFICATION_CALLBACK Callback,
  11353. IN PVOID Context
  11354. );
  11355. NTKERNELAPI
  11356. NTSTATUS
  11357. IoWMIHandleToInstanceName(
  11358. IN PVOID DataBlockObject,
  11359. IN HANDLE FileHandle,
  11360. OUT PUNICODE_STRING InstanceName
  11361. );
  11362. NTKERNELAPI
  11363. NTSTATUS
  11364. IoWMIDeviceObjectToInstanceName(
  11365. IN PVOID DataBlockObject,
  11366. IN PDEVICE_OBJECT DeviceObject,
  11367. OUT PUNICODE_STRING InstanceName
  11368. );
  11369. #if defined(_WIN64)
  11370. BOOLEAN
  11371. IoIs32bitProcess(
  11372. IN PIRP Irp
  11373. );
  11374. #endif
  11375. VOID
  11376. IoFreeErrorLogEntry(
  11377. PVOID ElEntry
  11378. );
  11379. // Cancel SAFE API set start
  11380. //
  11381. // The following APIs are to help ease the pain of writing queue packages that
  11382. // handle the cancellation race well. The idea of this set of APIs is to not
  11383. // force a single queue data structure but allow the cancel logic to be hidden
  11384. // from the drivers. A driver implements a queue and as part of its header
  11385. // includes the IO_CSQ structure. In its initialization routine it calls
  11386. // IoInitializeCsq. Then in the dispatch routine when the driver wants to
  11387. // insert an IRP into the queue it calls IoCsqInsertIrp. When the driver wants
  11388. // to remove something from the queue it calls IoCsqRemoveIrp. Note that Insert
  11389. // can fail if the IRP was cancelled in the meantime. Remove can also fail if
  11390. // the IRP was already cancelled.
  11391. //
  11392. // There are typically two modes where drivers queue IRPs. These two modes are
  11393. // covered by the cancel safe queue API set.
  11394. //
  11395. // Mode 1:
  11396. // One is where the driver queues the IRP and at some later
  11397. // point in time dequeues an IRP and issues the IO request.
  11398. // For this mode the driver should use IoCsqInsertIrp and IoCsqRemoveNextIrp.
  11399. // The driver in this case is expected to pass NULL to the irp context
  11400. // parameter in IoInsertIrp.
  11401. //
  11402. // Mode 2:
  11403. // In this the driver queues theIRP, issues the IO request (like issuing a DMA
  11404. // request or writing to a register) and when the IO request completes (either
  11405. // using a DPC or timer) the driver dequeues the IRP and completes it. For this
  11406. // mode the driver should use IoCsqInsertIrp and IoCsqRemoveIrp. In this case
  11407. // the driver should allocate an IRP context and pass it in to IoCsqInsertIrp.
  11408. // The cancel API code creates an association between the IRP and the context
  11409. // and thus ensures that when the time comes to remove the IRP it can ascertain
  11410. // correctly.
  11411. //
  11412. // Note that the cancel API set assumes that the field DriverContext[3] is
  11413. // always available for use and that the driver does not use it.
  11414. //
  11415. //
  11416. // Bookkeeping structure. This should be opaque to drivers.
  11417. // Drivers typically include this as part of their queue headers.
  11418. // Given a CSQ pointer the driver should be able to get its
  11419. // queue header using CONTAINING_RECORD macro
  11420. //
  11421. typedef struct _IO_CSQ IO_CSQ, *PIO_CSQ;
  11422. #define IO_TYPE_CSQ_IRP_CONTEXT 1
  11423. #define IO_TYPE_CSQ 2
  11424. #define IO_TYPE_CSQ_EX 3
  11425. //
  11426. // IRP context structure. This structure is necessary if the driver is using
  11427. // the second mode.
  11428. //
  11429. typedef struct _IO_CSQ_IRP_CONTEXT {
  11430. ULONG Type;
  11431. PIRP Irp;
  11432. PIO_CSQ Csq;
  11433. } IO_CSQ_IRP_CONTEXT, *PIO_CSQ_IRP_CONTEXT;
  11434. //
  11435. // Routines that insert/remove IRP
  11436. //
  11437. typedef VOID
  11438. (*PIO_CSQ_INSERT_IRP)(
  11439. IN struct _IO_CSQ *Csq,
  11440. IN PIRP Irp
  11441. );
  11442. typedef NTSTATUS
  11443. (*PIO_CSQ_INSERT_IRP_EX)(
  11444. IN struct _IO_CSQ *Csq,
  11445. IN PIRP Irp,
  11446. IN OUT PVOID InsertContext
  11447. );
  11448. typedef VOID
  11449. (*PIO_CSQ_REMOVE_IRP)(
  11450. IN PIO_CSQ Csq,
  11451. IN PIRP Irp
  11452. );
  11453. //
  11454. // Retrieves next entry after Irp from the queue.
  11455. // Returns NULL if there are no entries in the queue.
  11456. // If Irp is NUL, returns the entry in the head of the queue.
  11457. // This routine does not remove the IRP from the queue.
  11458. //
  11459. typedef PIRP
  11460. (*PIO_CSQ_PEEK_NEXT_IRP)(
  11461. IN PIO_CSQ Csq,
  11462. IN PIRP Irp,
  11463. IN PVOID PeekContext
  11464. );
  11465. //
  11466. // Lock routine that protects the cancel safe queue.
  11467. //
  11468. typedef VOID
  11469. (*PIO_CSQ_ACQUIRE_LOCK)(
  11470. IN PIO_CSQ Csq,
  11471. OUT PKIRQL Irql
  11472. );
  11473. typedef VOID
  11474. (*PIO_CSQ_RELEASE_LOCK)(
  11475. IN PIO_CSQ Csq,
  11476. IN KIRQL Irql
  11477. );
  11478. //
  11479. // Completes the IRP with STATUS_CANCELLED. IRP is guaranteed to be valid
  11480. // In most cases this routine just calls IoCompleteRequest(Irp, STATUS_CANCELLED);
  11481. //
  11482. typedef VOID
  11483. (*PIO_CSQ_COMPLETE_CANCELED_IRP)(
  11484. IN PIO_CSQ Csq,
  11485. IN PIRP Irp
  11486. );
  11487. //
  11488. // Bookkeeping structure. This should be opaque to drivers.
  11489. // Drivers typically include this as part of their queue headers.
  11490. // Given a CSQ pointer the driver should be able to get its
  11491. // queue header using CONTAINING_RECORD macro
  11492. //
  11493. typedef struct _IO_CSQ {
  11494. ULONG Type;
  11495. PIO_CSQ_INSERT_IRP CsqInsertIrp;
  11496. PIO_CSQ_REMOVE_IRP CsqRemoveIrp;
  11497. PIO_CSQ_PEEK_NEXT_IRP CsqPeekNextIrp;
  11498. PIO_CSQ_ACQUIRE_LOCK CsqAcquireLock;
  11499. PIO_CSQ_RELEASE_LOCK CsqReleaseLock;
  11500. PIO_CSQ_COMPLETE_CANCELED_IRP CsqCompleteCanceledIrp;
  11501. PVOID ReservePointer; // Future expansion
  11502. } IO_CSQ, *PIO_CSQ;
  11503. //
  11504. // Initializes the cancel queue structure.
  11505. //
  11506. NTSTATUS
  11507. IoCsqInitialize(
  11508. IN PIO_CSQ Csq,
  11509. IN PIO_CSQ_INSERT_IRP CsqInsertIrp,
  11510. IN PIO_CSQ_REMOVE_IRP CsqRemoveIrp,
  11511. IN PIO_CSQ_PEEK_NEXT_IRP CsqPeekNextIrp,
  11512. IN PIO_CSQ_ACQUIRE_LOCK CsqAcquireLock,
  11513. IN PIO_CSQ_RELEASE_LOCK CsqReleaseLock,
  11514. IN PIO_CSQ_COMPLETE_CANCELED_IRP CsqCompleteCanceledIrp
  11515. );
  11516. NTSTATUS
  11517. IoCsqInitializeEx(
  11518. IN PIO_CSQ Csq,
  11519. IN PIO_CSQ_INSERT_IRP_EX CsqInsertIrp,
  11520. IN PIO_CSQ_REMOVE_IRP CsqRemoveIrp,
  11521. IN PIO_CSQ_PEEK_NEXT_IRP CsqPeekNextIrp,
  11522. IN PIO_CSQ_ACQUIRE_LOCK CsqAcquireLock,
  11523. IN PIO_CSQ_RELEASE_LOCK CsqReleaseLock,
  11524. IN PIO_CSQ_COMPLETE_CANCELED_IRP CsqCompleteCanceledIrp
  11525. );
  11526. //
  11527. // The caller calls this routine to insert the IRP and return STATUS_PENDING.
  11528. //
  11529. VOID
  11530. IoCsqInsertIrp(
  11531. IN PIO_CSQ Csq,
  11532. IN PIRP Irp,
  11533. IN PIO_CSQ_IRP_CONTEXT Context
  11534. );
  11535. NTSTATUS
  11536. IoCsqInsertIrpEx(
  11537. IN PIO_CSQ Csq,
  11538. IN PIRP Irp,
  11539. IN PIO_CSQ_IRP_CONTEXT Context,
  11540. IN PVOID InsertContext
  11541. );
  11542. //
  11543. // Returns an IRP if one can be found. NULL otherwise.
  11544. //
  11545. PIRP
  11546. IoCsqRemoveNextIrp(
  11547. IN PIO_CSQ Csq,
  11548. IN PVOID PeekContext
  11549. );
  11550. //
  11551. // This routine is called from timeout or DPCs.
  11552. // The context is presumably part of the DPC or timer context.
  11553. // If succesfull returns the IRP associated with context.
  11554. //
  11555. PIRP
  11556. IoCsqRemoveIrp(
  11557. IN PIO_CSQ Csq,
  11558. IN PIO_CSQ_IRP_CONTEXT Context
  11559. );
  11560. // Cancel SAFE API set end
  11561. #ifdef RUN_WPP
  11562. #include <evntrace.h>
  11563. #include <stdarg.h>
  11564. #endif // #ifdef RUN_WPP
  11565. #ifdef RUN_WPP
  11566. NTKERNELAPI
  11567. NTSTATUS
  11568. WmiTraceMessage(
  11569. IN TRACEHANDLE LoggerHandle,
  11570. IN ULONG MessageFlags,
  11571. IN LPGUID MessageGuid,
  11572. IN USHORT MessageNumber,
  11573. IN ...
  11574. );
  11575. NTKERNELAPI
  11576. NTSTATUS
  11577. WmiTraceMessageVa(
  11578. IN TRACEHANDLE LoggerHandle,
  11579. IN ULONG MessageFlags,
  11580. IN LPGUID MessageGuid,
  11581. IN USHORT MessageNumber,
  11582. IN va_list MessageArgList
  11583. );
  11584. #endif // #ifdef RUN_WPP
  11585. #ifndef TRACE_INFORMATION_CLASS_DEFINE
  11586. typedef enum _TRACE_INFORMATION_CLASS {
  11587. TraceIdClass,
  11588. TraceHandleClass,
  11589. TraceEnableFlagsClass,
  11590. TraceEnableLevelClass,
  11591. GlobalLoggerHandleClass,
  11592. EventLoggerHandleClass,
  11593. AllLoggerHandlesClass,
  11594. TraceHandleByNameClass
  11595. } TRACE_INFORMATION_CLASS;
  11596. NTKERNELAPI
  11597. NTSTATUS
  11598. WmiQueryTraceInformation(
  11599. IN TRACE_INFORMATION_CLASS TraceInformationClass,
  11600. OUT PVOID TraceInformation,
  11601. IN ULONG TraceInformationLength,
  11602. OUT PULONG RequiredLength OPTIONAL,
  11603. IN PVOID Buffer OPTIONAL
  11604. );
  11605. #define TRACE_INFORMATION_CLASS_DEFINE
  11606. #endif // TRACE_INFOPRMATION_CLASS_DEFINE
  11607. //
  11608. // Define PnP Device Property for IoGetDeviceProperty
  11609. //
  11610. typedef enum {
  11611. DevicePropertyDeviceDescription,
  11612. DevicePropertyHardwareID,
  11613. DevicePropertyCompatibleIDs,
  11614. DevicePropertyBootConfiguration,
  11615. DevicePropertyBootConfigurationTranslated,
  11616. DevicePropertyClassName,
  11617. DevicePropertyClassGuid,
  11618. DevicePropertyDriverKeyName,
  11619. DevicePropertyManufacturer,
  11620. DevicePropertyFriendlyName,
  11621. DevicePropertyLocationInformation,
  11622. DevicePropertyPhysicalDeviceObjectName,
  11623. DevicePropertyBusTypeGuid,
  11624. DevicePropertyLegacyBusType,
  11625. DevicePropertyBusNumber,
  11626. DevicePropertyEnumeratorName,
  11627. DevicePropertyAddress,
  11628. DevicePropertyUINumber,
  11629. DevicePropertyInstallState,
  11630. DevicePropertyRemovalPolicy
  11631. } DEVICE_REGISTRY_PROPERTY;
  11632. typedef BOOLEAN (*PTRANSLATE_BUS_ADDRESS)(
  11633. IN PVOID Context,
  11634. IN PHYSICAL_ADDRESS BusAddress,
  11635. IN ULONG Length,
  11636. IN OUT PULONG AddressSpace,
  11637. OUT PPHYSICAL_ADDRESS TranslatedAddress
  11638. );
  11639. typedef struct _DMA_ADAPTER *(*PGET_DMA_ADAPTER)(
  11640. IN PVOID Context,
  11641. IN struct _DEVICE_DESCRIPTION *DeviceDescriptor,
  11642. OUT PULONG NumberOfMapRegisters
  11643. );
  11644. typedef ULONG (*PGET_SET_DEVICE_DATA)(
  11645. IN PVOID Context,
  11646. IN ULONG DataType,
  11647. IN PVOID Buffer,
  11648. IN ULONG Offset,
  11649. IN ULONG Length
  11650. );
  11651. typedef enum _DEVICE_INSTALL_STATE {
  11652. InstallStateInstalled,
  11653. InstallStateNeedsReinstall,
  11654. InstallStateFailedInstall,
  11655. InstallStateFinishInstall
  11656. } DEVICE_INSTALL_STATE, *PDEVICE_INSTALL_STATE;
  11657. //
  11658. // Define structure returned in response to IRP_MN_QUERY_BUS_INFORMATION by a
  11659. // PDO indicating the type of bus the device exists on.
  11660. //
  11661. typedef struct _PNP_BUS_INFORMATION {
  11662. GUID BusTypeGuid;
  11663. INTERFACE_TYPE LegacyBusType;
  11664. ULONG BusNumber;
  11665. } PNP_BUS_INFORMATION, *PPNP_BUS_INFORMATION;
  11666. //
  11667. // Define structure returned in response to IRP_MN_QUERY_LEGACY_BUS_INFORMATION
  11668. // by an FDO indicating the type of bus it is. This is normally the same bus
  11669. // type as the device's children (i.e., as retrieved from the child PDO's via
  11670. // IRP_MN_QUERY_BUS_INFORMATION) except for cases like CardBus, which can
  11671. // support both 16-bit (PCMCIABus) and 32-bit (PCIBus) cards.
  11672. //
  11673. typedef struct _LEGACY_BUS_INFORMATION {
  11674. GUID BusTypeGuid;
  11675. INTERFACE_TYPE LegacyBusType;
  11676. ULONG BusNumber;
  11677. } LEGACY_BUS_INFORMATION, *PLEGACY_BUS_INFORMATION;
  11678. //
  11679. // Defines for IoGetDeviceProperty(DevicePropertyRemovalPolicy).
  11680. //
  11681. typedef enum _DEVICE_REMOVAL_POLICY {
  11682. RemovalPolicyExpectNoRemoval = 1,
  11683. RemovalPolicyExpectOrderlyRemoval = 2,
  11684. RemovalPolicyExpectSurpriseRemoval = 3
  11685. } DEVICE_REMOVAL_POLICY, *PDEVICE_REMOVAL_POLICY;
  11686. typedef struct _BUS_INTERFACE_STANDARD {
  11687. //
  11688. // generic interface header
  11689. //
  11690. USHORT Size;
  11691. USHORT Version;
  11692. PVOID Context;
  11693. PINTERFACE_REFERENCE InterfaceReference;
  11694. PINTERFACE_DEREFERENCE InterfaceDereference;
  11695. //
  11696. // standard bus interfaces
  11697. //
  11698. PTRANSLATE_BUS_ADDRESS TranslateBusAddress;
  11699. PGET_DMA_ADAPTER GetDmaAdapter;
  11700. PGET_SET_DEVICE_DATA SetBusData;
  11701. PGET_SET_DEVICE_DATA GetBusData;
  11702. } BUS_INTERFACE_STANDARD, *PBUS_INTERFACE_STANDARD;
  11703. //
  11704. // The following definitions are used in ACPI QueryInterface
  11705. //
  11706. typedef BOOLEAN (* PGPE_SERVICE_ROUTINE) (
  11707. PVOID,
  11708. PVOID);
  11709. typedef NTSTATUS (* PGPE_CONNECT_VECTOR) (
  11710. PDEVICE_OBJECT,
  11711. ULONG,
  11712. KINTERRUPT_MODE,
  11713. BOOLEAN,
  11714. PGPE_SERVICE_ROUTINE,
  11715. PVOID,
  11716. PVOID);
  11717. typedef NTSTATUS (* PGPE_DISCONNECT_VECTOR) (
  11718. PVOID);
  11719. typedef NTSTATUS (* PGPE_ENABLE_EVENT) (
  11720. PDEVICE_OBJECT,
  11721. PVOID);
  11722. typedef NTSTATUS (* PGPE_DISABLE_EVENT) (
  11723. PDEVICE_OBJECT,
  11724. PVOID);
  11725. typedef NTSTATUS (* PGPE_CLEAR_STATUS) (
  11726. PDEVICE_OBJECT,
  11727. PVOID);
  11728. typedef VOID (* PDEVICE_NOTIFY_CALLBACK) (
  11729. PVOID,
  11730. ULONG);
  11731. typedef NTSTATUS (* PREGISTER_FOR_DEVICE_NOTIFICATIONS) (
  11732. PDEVICE_OBJECT,
  11733. PDEVICE_NOTIFY_CALLBACK,
  11734. PVOID);
  11735. typedef void (* PUNREGISTER_FOR_DEVICE_NOTIFICATIONS) (
  11736. PDEVICE_OBJECT,
  11737. PDEVICE_NOTIFY_CALLBACK);
  11738. typedef struct _ACPI_INTERFACE_STANDARD {
  11739. //
  11740. // Generic interface header
  11741. //
  11742. USHORT Size;
  11743. USHORT Version;
  11744. PVOID Context;
  11745. PINTERFACE_REFERENCE InterfaceReference;
  11746. PINTERFACE_DEREFERENCE InterfaceDereference;
  11747. //
  11748. // ACPI interfaces
  11749. //
  11750. PGPE_CONNECT_VECTOR GpeConnectVector;
  11751. PGPE_DISCONNECT_VECTOR GpeDisconnectVector;
  11752. PGPE_ENABLE_EVENT GpeEnableEvent;
  11753. PGPE_DISABLE_EVENT GpeDisableEvent;
  11754. PGPE_CLEAR_STATUS GpeClearStatus;
  11755. PREGISTER_FOR_DEVICE_NOTIFICATIONS RegisterForDeviceNotifications;
  11756. PUNREGISTER_FOR_DEVICE_NOTIFICATIONS UnregisterForDeviceNotifications;
  11757. } ACPI_INTERFACE_STANDARD, *PACPI_INTERFACE_STANDARD;
  11758. NTKERNELAPI
  11759. VOID
  11760. IoInvalidateDeviceRelations(
  11761. IN PDEVICE_OBJECT DeviceObject,
  11762. IN DEVICE_RELATION_TYPE Type
  11763. );
  11764. NTKERNELAPI
  11765. VOID
  11766. IoRequestDeviceEject(
  11767. IN PDEVICE_OBJECT PhysicalDeviceObject
  11768. );
  11769. NTKERNELAPI
  11770. NTSTATUS
  11771. IoGetDeviceProperty(
  11772. IN PDEVICE_OBJECT DeviceObject,
  11773. IN DEVICE_REGISTRY_PROPERTY DeviceProperty,
  11774. IN ULONG BufferLength,
  11775. OUT PVOID PropertyBuffer,
  11776. OUT PULONG ResultLength
  11777. );
  11778. //
  11779. // The following definitions are used in IoOpenDeviceRegistryKey
  11780. //
  11781. #define PLUGPLAY_REGKEY_DEVICE 1
  11782. #define PLUGPLAY_REGKEY_DRIVER 2
  11783. #define PLUGPLAY_REGKEY_CURRENT_HWPROFILE 4
  11784. NTKERNELAPI
  11785. NTSTATUS
  11786. IoOpenDeviceRegistryKey(
  11787. IN PDEVICE_OBJECT DeviceObject,
  11788. IN ULONG DevInstKeyType,
  11789. IN ACCESS_MASK DesiredAccess,
  11790. OUT PHANDLE DevInstRegKey
  11791. );
  11792. NTKERNELAPI
  11793. NTSTATUS
  11794. NTAPI
  11795. IoRegisterDeviceInterface(
  11796. IN PDEVICE_OBJECT PhysicalDeviceObject,
  11797. IN CONST GUID *InterfaceClassGuid,
  11798. IN PUNICODE_STRING ReferenceString, OPTIONAL
  11799. OUT PUNICODE_STRING SymbolicLinkName
  11800. );
  11801. NTKERNELAPI
  11802. NTSTATUS
  11803. IoOpenDeviceInterfaceRegistryKey(
  11804. IN PUNICODE_STRING SymbolicLinkName,
  11805. IN ACCESS_MASK DesiredAccess,
  11806. OUT PHANDLE DeviceInterfaceKey
  11807. );
  11808. NTKERNELAPI
  11809. NTSTATUS
  11810. IoSetDeviceInterfaceState(
  11811. IN PUNICODE_STRING SymbolicLinkName,
  11812. IN BOOLEAN Enable
  11813. );
  11814. NTKERNELAPI
  11815. NTSTATUS
  11816. NTAPI
  11817. IoGetDeviceInterfaces(
  11818. IN CONST GUID *InterfaceClassGuid,
  11819. IN PDEVICE_OBJECT PhysicalDeviceObject OPTIONAL,
  11820. IN ULONG Flags,
  11821. OUT PWSTR *SymbolicLinkList
  11822. );
  11823. #define DEVICE_INTERFACE_INCLUDE_NONACTIVE 0x00000001
  11824. NTKERNELAPI
  11825. NTSTATUS
  11826. NTAPI
  11827. IoGetDeviceInterfaceAlias(
  11828. IN PUNICODE_STRING SymbolicLinkName,
  11829. IN CONST GUID *AliasInterfaceClassGuid,
  11830. OUT PUNICODE_STRING AliasSymbolicLinkName
  11831. );
  11832. //
  11833. // Define PnP notification event categories
  11834. //
  11835. typedef enum _IO_NOTIFICATION_EVENT_CATEGORY {
  11836. EventCategoryReserved,
  11837. EventCategoryHardwareProfileChange,
  11838. EventCategoryDeviceInterfaceChange,
  11839. EventCategoryTargetDeviceChange
  11840. } IO_NOTIFICATION_EVENT_CATEGORY;
  11841. //
  11842. // Define flags that modify the behavior of IoRegisterPlugPlayNotification
  11843. // for the various event categories...
  11844. //
  11845. #define PNPNOTIFY_DEVICE_INTERFACE_INCLUDE_EXISTING_INTERFACES 0x00000001
  11846. typedef
  11847. NTSTATUS
  11848. (*PDRIVER_NOTIFICATION_CALLBACK_ROUTINE) (
  11849. IN PVOID NotificationStructure,
  11850. IN PVOID Context
  11851. );
  11852. NTKERNELAPI
  11853. NTSTATUS
  11854. IoRegisterPlugPlayNotification(
  11855. IN IO_NOTIFICATION_EVENT_CATEGORY EventCategory,
  11856. IN ULONG EventCategoryFlags,
  11857. IN PVOID EventCategoryData OPTIONAL,
  11858. IN PDRIVER_OBJECT DriverObject,
  11859. IN PDRIVER_NOTIFICATION_CALLBACK_ROUTINE CallbackRoutine,
  11860. IN PVOID Context,
  11861. OUT PVOID *NotificationEntry
  11862. );
  11863. NTKERNELAPI
  11864. NTSTATUS
  11865. IoUnregisterPlugPlayNotification(
  11866. IN PVOID NotificationEntry
  11867. );
  11868. NTKERNELAPI
  11869. NTSTATUS
  11870. IoReportTargetDeviceChange(
  11871. IN PDEVICE_OBJECT PhysicalDeviceObject,
  11872. IN PVOID NotificationStructure // always begins with a PLUGPLAY_NOTIFICATION_HEADER
  11873. );
  11874. typedef
  11875. VOID
  11876. (*PDEVICE_CHANGE_COMPLETE_CALLBACK)(
  11877. IN PVOID Context
  11878. );
  11879. NTKERNELAPI
  11880. VOID
  11881. IoInvalidateDeviceState(
  11882. IN PDEVICE_OBJECT PhysicalDeviceObject
  11883. );
  11884. #define IoAdjustPagingPathCount(_count_,_paging_) { \
  11885. if (_paging_) { \
  11886. InterlockedIncrement(_count_); \
  11887. } else { \
  11888. InterlockedDecrement(_count_); \
  11889. } \
  11890. }
  11891. NTKERNELAPI
  11892. NTSTATUS
  11893. IoReportTargetDeviceChangeAsynchronous(
  11894. IN PDEVICE_OBJECT PhysicalDeviceObject,
  11895. IN PVOID NotificationStructure, // always begins with a PLUGPLAY_NOTIFICATION_HEADER
  11896. IN PDEVICE_CHANGE_COMPLETE_CALLBACK Callback, OPTIONAL
  11897. IN PVOID Context OPTIONAL
  11898. );
  11899. //
  11900. // Header structure for all Plug&Play notification events...
  11901. //
  11902. typedef struct _PLUGPLAY_NOTIFICATION_HEADER {
  11903. USHORT Version; // presently at version 1.
  11904. USHORT Size; // size (in bytes) of header + event-specific data.
  11905. GUID Event;
  11906. //
  11907. // Event-specific stuff starts here.
  11908. //
  11909. } PLUGPLAY_NOTIFICATION_HEADER, *PPLUGPLAY_NOTIFICATION_HEADER;
  11910. //
  11911. // Notification structure for all EventCategoryHardwareProfileChange events...
  11912. //
  11913. typedef struct _HWPROFILE_CHANGE_NOTIFICATION {
  11914. USHORT Version;
  11915. USHORT Size;
  11916. GUID Event;
  11917. //
  11918. // (No event-specific data)
  11919. //
  11920. } HWPROFILE_CHANGE_NOTIFICATION, *PHWPROFILE_CHANGE_NOTIFICATION;
  11921. //
  11922. // Notification structure for all EventCategoryDeviceInterfaceChange events...
  11923. //
  11924. typedef struct _DEVICE_INTERFACE_CHANGE_NOTIFICATION {
  11925. USHORT Version;
  11926. USHORT Size;
  11927. GUID Event;
  11928. //
  11929. // Event-specific data
  11930. //
  11931. GUID InterfaceClassGuid;
  11932. PUNICODE_STRING SymbolicLinkName;
  11933. } DEVICE_INTERFACE_CHANGE_NOTIFICATION, *PDEVICE_INTERFACE_CHANGE_NOTIFICATION;
  11934. //
  11935. // Notification structures for EventCategoryTargetDeviceChange...
  11936. //
  11937. //
  11938. // The following structure is used for TargetDeviceQueryRemove,
  11939. // TargetDeviceRemoveCancelled, and TargetDeviceRemoveComplete:
  11940. //
  11941. typedef struct _TARGET_DEVICE_REMOVAL_NOTIFICATION {
  11942. USHORT Version;
  11943. USHORT Size;
  11944. GUID Event;
  11945. //
  11946. // Event-specific data
  11947. //
  11948. PFILE_OBJECT FileObject;
  11949. } TARGET_DEVICE_REMOVAL_NOTIFICATION, *PTARGET_DEVICE_REMOVAL_NOTIFICATION;
  11950. //
  11951. // The following structure header is used for all other (i.e., 3rd-party)
  11952. // target device change events. The structure accommodates both a
  11953. // variable-length binary data buffer, and a variable-length unicode text
  11954. // buffer. The header must indicate where the text buffer begins, so that
  11955. // the data can be delivered in the appropriate format (ANSI or Unicode)
  11956. // to user-mode recipients (i.e., that have registered for handle-based
  11957. // notification via RegisterDeviceNotification).
  11958. //
  11959. typedef struct _TARGET_DEVICE_CUSTOM_NOTIFICATION {
  11960. USHORT Version;
  11961. USHORT Size;
  11962. GUID Event;
  11963. //
  11964. // Event-specific data
  11965. //
  11966. PFILE_OBJECT FileObject; // This field must be set to NULL by callers of
  11967. // IoReportTargetDeviceChange. Clients that
  11968. // have registered for target device change
  11969. // notification on the affected PDO will be
  11970. // called with this field set to the file object
  11971. // they specified during registration.
  11972. //
  11973. LONG NameBufferOffset; // offset (in bytes) from beginning of
  11974. // CustomDataBuffer where text begins (-1 if none)
  11975. //
  11976. UCHAR CustomDataBuffer[1]; // variable-length buffer, containing (optionally)
  11977. // a binary data at the start of the buffer,
  11978. // followed by an optional unicode text buffer
  11979. // (word-aligned).
  11980. //
  11981. } TARGET_DEVICE_CUSTOM_NOTIFICATION, *PTARGET_DEVICE_CUSTOM_NOTIFICATION;
  11982. //
  11983. // Define the device description structure.
  11984. //
  11985. typedef struct _DEVICE_DESCRIPTION {
  11986. ULONG Version;
  11987. BOOLEAN Master;
  11988. BOOLEAN ScatterGather;
  11989. BOOLEAN DemandMode;
  11990. BOOLEAN AutoInitialize;
  11991. BOOLEAN Dma32BitAddresses;
  11992. BOOLEAN IgnoreCount;
  11993. BOOLEAN Reserved1; // must be false
  11994. BOOLEAN Dma64BitAddresses;
  11995. ULONG DoNotUse2;
  11996. ULONG DmaChannel;
  11997. INTERFACE_TYPE InterfaceType;
  11998. DMA_WIDTH DmaWidth;
  11999. DMA_SPEED DmaSpeed;
  12000. ULONG MaximumLength;
  12001. ULONG DmaPort;
  12002. } DEVICE_DESCRIPTION, *PDEVICE_DESCRIPTION;
  12003. //
  12004. // Define the supported version numbers for the device description structure.
  12005. //
  12006. #define DEVICE_DESCRIPTION_VERSION 0
  12007. #define DEVICE_DESCRIPTION_VERSION1 1
  12008. #define DEVICE_DESCRIPTION_VERSION2 2
  12009. NTHALAPI
  12010. VOID
  12011. KeFlushWriteBuffer (
  12012. VOID
  12013. );
  12014. //
  12015. // Performance counter function.
  12016. //
  12017. NTHALAPI
  12018. LARGE_INTEGER
  12019. KeQueryPerformanceCounter (
  12020. OUT PLARGE_INTEGER PerformanceFrequency OPTIONAL
  12021. );
  12022. //
  12023. // Stall processor execution function.
  12024. //
  12025. NTHALAPI
  12026. VOID
  12027. KeStallExecutionProcessor (
  12028. IN ULONG MicroSeconds
  12029. );
  12030. typedef struct _SCATTER_GATHER_ELEMENT {
  12031. PHYSICAL_ADDRESS Address;
  12032. ULONG Length;
  12033. ULONG_PTR Reserved;
  12034. } SCATTER_GATHER_ELEMENT, *PSCATTER_GATHER_ELEMENT;
  12035. #if _MSC_VER >= 1200
  12036. #pragma warning(push)
  12037. #endif
  12038. #pragma warning(disable:4200)
  12039. typedef struct _SCATTER_GATHER_LIST {
  12040. ULONG NumberOfElements;
  12041. ULONG_PTR Reserved;
  12042. SCATTER_GATHER_ELEMENT Elements[];
  12043. } SCATTER_GATHER_LIST, *PSCATTER_GATHER_LIST;
  12044. #if _MSC_VER >= 1200
  12045. #pragma warning(pop)
  12046. #else
  12047. #pragma warning(default:4200)
  12048. #endif
  12049. typedef struct _DMA_OPERATIONS *PDMA_OPERATIONS;
  12050. typedef struct _DMA_ADAPTER {
  12051. USHORT Version;
  12052. USHORT Size;
  12053. PDMA_OPERATIONS DmaOperations;
  12054. // Private Bus Device Driver data follows,
  12055. } DMA_ADAPTER, *PDMA_ADAPTER;
  12056. typedef VOID (*PPUT_DMA_ADAPTER)(
  12057. PDMA_ADAPTER DmaAdapter
  12058. );
  12059. typedef PVOID (*PALLOCATE_COMMON_BUFFER)(
  12060. IN PDMA_ADAPTER DmaAdapter,
  12061. IN ULONG Length,
  12062. OUT PPHYSICAL_ADDRESS LogicalAddress,
  12063. IN BOOLEAN CacheEnabled
  12064. );
  12065. typedef VOID (*PFREE_COMMON_BUFFER)(
  12066. IN PDMA_ADAPTER DmaAdapter,
  12067. IN ULONG Length,
  12068. IN PHYSICAL_ADDRESS LogicalAddress,
  12069. IN PVOID VirtualAddress,
  12070. IN BOOLEAN CacheEnabled
  12071. );
  12072. typedef NTSTATUS (*PALLOCATE_ADAPTER_CHANNEL)(
  12073. IN PDMA_ADAPTER DmaAdapter,
  12074. IN PDEVICE_OBJECT DeviceObject,
  12075. IN ULONG NumberOfMapRegisters,
  12076. IN PDRIVER_CONTROL ExecutionRoutine,
  12077. IN PVOID Context
  12078. );
  12079. typedef BOOLEAN (*PFLUSH_ADAPTER_BUFFERS)(
  12080. IN PDMA_ADAPTER DmaAdapter,
  12081. IN PMDL Mdl,
  12082. IN PVOID MapRegisterBase,
  12083. IN PVOID CurrentVa,
  12084. IN ULONG Length,
  12085. IN BOOLEAN WriteToDevice
  12086. );
  12087. typedef VOID (*PFREE_ADAPTER_CHANNEL)(
  12088. IN PDMA_ADAPTER DmaAdapter
  12089. );
  12090. typedef VOID (*PFREE_MAP_REGISTERS)(
  12091. IN PDMA_ADAPTER DmaAdapter,
  12092. PVOID MapRegisterBase,
  12093. ULONG NumberOfMapRegisters
  12094. );
  12095. typedef PHYSICAL_ADDRESS (*PMAP_TRANSFER)(
  12096. IN PDMA_ADAPTER DmaAdapter,
  12097. IN PMDL Mdl,
  12098. IN PVOID MapRegisterBase,
  12099. IN PVOID CurrentVa,
  12100. IN OUT PULONG Length,
  12101. IN BOOLEAN WriteToDevice
  12102. );
  12103. typedef ULONG (*PGET_DMA_ALIGNMENT)(
  12104. IN PDMA_ADAPTER DmaAdapter
  12105. );
  12106. typedef ULONG (*PREAD_DMA_COUNTER)(
  12107. IN PDMA_ADAPTER DmaAdapter
  12108. );
  12109. typedef VOID
  12110. (*PDRIVER_LIST_CONTROL)(
  12111. IN struct _DEVICE_OBJECT *DeviceObject,
  12112. IN struct _IRP *Irp,
  12113. IN PSCATTER_GATHER_LIST ScatterGather,
  12114. IN PVOID Context
  12115. );
  12116. typedef NTSTATUS
  12117. (*PGET_SCATTER_GATHER_LIST)(
  12118. IN PDMA_ADAPTER DmaAdapter,
  12119. IN PDEVICE_OBJECT DeviceObject,
  12120. IN PMDL Mdl,
  12121. IN PVOID CurrentVa,
  12122. IN ULONG Length,
  12123. IN PDRIVER_LIST_CONTROL ExecutionRoutine,
  12124. IN PVOID Context,
  12125. IN BOOLEAN WriteToDevice
  12126. );
  12127. typedef VOID
  12128. (*PPUT_SCATTER_GATHER_LIST)(
  12129. IN PDMA_ADAPTER DmaAdapter,
  12130. IN PSCATTER_GATHER_LIST ScatterGather,
  12131. IN BOOLEAN WriteToDevice
  12132. );
  12133. typedef NTSTATUS
  12134. (*PCALCULATE_SCATTER_GATHER_LIST_SIZE)(
  12135. IN PDMA_ADAPTER DmaAdapter,
  12136. IN OPTIONAL PMDL Mdl,
  12137. IN PVOID CurrentVa,
  12138. IN ULONG Length,
  12139. OUT PULONG ScatterGatherListSize,
  12140. OUT OPTIONAL PULONG pNumberOfMapRegisters
  12141. );
  12142. typedef NTSTATUS
  12143. (*PBUILD_SCATTER_GATHER_LIST)(
  12144. IN PDMA_ADAPTER DmaAdapter,
  12145. IN PDEVICE_OBJECT DeviceObject,
  12146. IN PMDL Mdl,
  12147. IN PVOID CurrentVa,
  12148. IN ULONG Length,
  12149. IN PDRIVER_LIST_CONTROL ExecutionRoutine,
  12150. IN PVOID Context,
  12151. IN BOOLEAN WriteToDevice,
  12152. IN PVOID ScatterGatherBuffer,
  12153. IN ULONG ScatterGatherLength
  12154. );
  12155. typedef NTSTATUS
  12156. (*PBUILD_MDL_FROM_SCATTER_GATHER_LIST)(
  12157. IN PDMA_ADAPTER DmaAdapter,
  12158. IN PSCATTER_GATHER_LIST ScatterGather,
  12159. IN PMDL OriginalMdl,
  12160. OUT PMDL *TargetMdl
  12161. );
  12162. typedef struct _DMA_OPERATIONS {
  12163. ULONG Size;
  12164. PPUT_DMA_ADAPTER PutDmaAdapter;
  12165. PALLOCATE_COMMON_BUFFER AllocateCommonBuffer;
  12166. PFREE_COMMON_BUFFER FreeCommonBuffer;
  12167. PALLOCATE_ADAPTER_CHANNEL AllocateAdapterChannel;
  12168. PFLUSH_ADAPTER_BUFFERS FlushAdapterBuffers;
  12169. PFREE_ADAPTER_CHANNEL FreeAdapterChannel;
  12170. PFREE_MAP_REGISTERS FreeMapRegisters;
  12171. PMAP_TRANSFER MapTransfer;
  12172. PGET_DMA_ALIGNMENT GetDmaAlignment;
  12173. PREAD_DMA_COUNTER ReadDmaCounter;
  12174. PGET_SCATTER_GATHER_LIST GetScatterGatherList;
  12175. PPUT_SCATTER_GATHER_LIST PutScatterGatherList;
  12176. PCALCULATE_SCATTER_GATHER_LIST_SIZE CalculateScatterGatherList;
  12177. PBUILD_SCATTER_GATHER_LIST BuildScatterGatherList;
  12178. PBUILD_MDL_FROM_SCATTER_GATHER_LIST BuildMdlFromScatterGatherList;
  12179. } DMA_OPERATIONS;
  12180. DECLSPEC_DEPRECATED_DDK // Use AllocateCommonBuffer
  12181. FORCEINLINE
  12182. PVOID
  12183. HalAllocateCommonBuffer(
  12184. IN PDMA_ADAPTER DmaAdapter,
  12185. IN ULONG Length,
  12186. OUT PPHYSICAL_ADDRESS LogicalAddress,
  12187. IN BOOLEAN CacheEnabled
  12188. ){
  12189. PALLOCATE_COMMON_BUFFER allocateCommonBuffer;
  12190. PVOID commonBuffer;
  12191. allocateCommonBuffer = *(DmaAdapter)->DmaOperations->AllocateCommonBuffer;
  12192. ASSERT( allocateCommonBuffer != NULL );
  12193. commonBuffer = allocateCommonBuffer( DmaAdapter,
  12194. Length,
  12195. LogicalAddress,
  12196. CacheEnabled );
  12197. return commonBuffer;
  12198. }
  12199. DECLSPEC_DEPRECATED_DDK // Use FreeCommonBuffer
  12200. FORCEINLINE
  12201. VOID
  12202. HalFreeCommonBuffer(
  12203. IN PDMA_ADAPTER DmaAdapter,
  12204. IN ULONG Length,
  12205. IN PHYSICAL_ADDRESS LogicalAddress,
  12206. IN PVOID VirtualAddress,
  12207. IN BOOLEAN CacheEnabled
  12208. ){
  12209. PFREE_COMMON_BUFFER freeCommonBuffer;
  12210. freeCommonBuffer = *(DmaAdapter)->DmaOperations->FreeCommonBuffer;
  12211. ASSERT( freeCommonBuffer != NULL );
  12212. freeCommonBuffer( DmaAdapter,
  12213. Length,
  12214. LogicalAddress,
  12215. VirtualAddress,
  12216. CacheEnabled );
  12217. }
  12218. DECLSPEC_DEPRECATED_DDK // Use AllocateAdapterChannel
  12219. FORCEINLINE
  12220. NTSTATUS
  12221. IoAllocateAdapterChannel(
  12222. IN PDMA_ADAPTER DmaAdapter,
  12223. IN PDEVICE_OBJECT DeviceObject,
  12224. IN ULONG NumberOfMapRegisters,
  12225. IN PDRIVER_CONTROL ExecutionRoutine,
  12226. IN PVOID Context
  12227. ){
  12228. PALLOCATE_ADAPTER_CHANNEL allocateAdapterChannel;
  12229. NTSTATUS status;
  12230. allocateAdapterChannel =
  12231. *(DmaAdapter)->DmaOperations->AllocateAdapterChannel;
  12232. ASSERT( allocateAdapterChannel != NULL );
  12233. status = allocateAdapterChannel( DmaAdapter,
  12234. DeviceObject,
  12235. NumberOfMapRegisters,
  12236. ExecutionRoutine,
  12237. Context );
  12238. return status;
  12239. }
  12240. DECLSPEC_DEPRECATED_DDK // Use FlushAdapterBuffers
  12241. FORCEINLINE
  12242. BOOLEAN
  12243. IoFlushAdapterBuffers(
  12244. IN PDMA_ADAPTER DmaAdapter,
  12245. IN PMDL Mdl,
  12246. IN PVOID MapRegisterBase,
  12247. IN PVOID CurrentVa,
  12248. IN ULONG Length,
  12249. IN BOOLEAN WriteToDevice
  12250. ){
  12251. PFLUSH_ADAPTER_BUFFERS flushAdapterBuffers;
  12252. BOOLEAN result;
  12253. flushAdapterBuffers = *(DmaAdapter)->DmaOperations->FlushAdapterBuffers;
  12254. ASSERT( flushAdapterBuffers != NULL );
  12255. result = flushAdapterBuffers( DmaAdapter,
  12256. Mdl,
  12257. MapRegisterBase,
  12258. CurrentVa,
  12259. Length,
  12260. WriteToDevice );
  12261. return result;
  12262. }
  12263. DECLSPEC_DEPRECATED_DDK // Use FreeAdapterChannel
  12264. FORCEINLINE
  12265. VOID
  12266. IoFreeAdapterChannel(
  12267. IN PDMA_ADAPTER DmaAdapter
  12268. ){
  12269. PFREE_ADAPTER_CHANNEL freeAdapterChannel;
  12270. freeAdapterChannel = *(DmaAdapter)->DmaOperations->FreeAdapterChannel;
  12271. ASSERT( freeAdapterChannel != NULL );
  12272. freeAdapterChannel( DmaAdapter );
  12273. }
  12274. DECLSPEC_DEPRECATED_DDK // Use FreeMapRegisters
  12275. FORCEINLINE
  12276. VOID
  12277. IoFreeMapRegisters(
  12278. IN PDMA_ADAPTER DmaAdapter,
  12279. IN PVOID MapRegisterBase,
  12280. IN ULONG NumberOfMapRegisters
  12281. ){
  12282. PFREE_MAP_REGISTERS freeMapRegisters;
  12283. freeMapRegisters = *(DmaAdapter)->DmaOperations->FreeMapRegisters;
  12284. ASSERT( freeMapRegisters != NULL );
  12285. freeMapRegisters( DmaAdapter,
  12286. MapRegisterBase,
  12287. NumberOfMapRegisters );
  12288. }
  12289. DECLSPEC_DEPRECATED_DDK // Use MapTransfer
  12290. FORCEINLINE
  12291. PHYSICAL_ADDRESS
  12292. IoMapTransfer(
  12293. IN PDMA_ADAPTER DmaAdapter,
  12294. IN PMDL Mdl,
  12295. IN PVOID MapRegisterBase,
  12296. IN PVOID CurrentVa,
  12297. IN OUT PULONG Length,
  12298. IN BOOLEAN WriteToDevice
  12299. ){
  12300. PHYSICAL_ADDRESS physicalAddress;
  12301. PMAP_TRANSFER mapTransfer;
  12302. mapTransfer = *(DmaAdapter)->DmaOperations->MapTransfer;
  12303. ASSERT( mapTransfer != NULL );
  12304. physicalAddress = mapTransfer( DmaAdapter,
  12305. Mdl,
  12306. MapRegisterBase,
  12307. CurrentVa,
  12308. Length,
  12309. WriteToDevice );
  12310. return physicalAddress;
  12311. }
  12312. DECLSPEC_DEPRECATED_DDK // Use GetDmaAlignment
  12313. FORCEINLINE
  12314. ULONG
  12315. HalGetDmaAlignment(
  12316. IN PDMA_ADAPTER DmaAdapter
  12317. )
  12318. {
  12319. PGET_DMA_ALIGNMENT getDmaAlignment;
  12320. ULONG alignment;
  12321. getDmaAlignment = *(DmaAdapter)->DmaOperations->GetDmaAlignment;
  12322. ASSERT( getDmaAlignment != NULL );
  12323. alignment = getDmaAlignment( DmaAdapter );
  12324. return alignment;
  12325. }
  12326. DECLSPEC_DEPRECATED_DDK // Use ReadDmaCounter
  12327. FORCEINLINE
  12328. ULONG
  12329. HalReadDmaCounter(
  12330. IN PDMA_ADAPTER DmaAdapter
  12331. )
  12332. {
  12333. PREAD_DMA_COUNTER readDmaCounter;
  12334. ULONG counter;
  12335. readDmaCounter = *(DmaAdapter)->DmaOperations->ReadDmaCounter;
  12336. ASSERT( readDmaCounter != NULL );
  12337. counter = readDmaCounter( DmaAdapter );
  12338. return counter;
  12339. }
  12340. NTKERNELAPI
  12341. VOID
  12342. PoSetSystemState (
  12343. IN EXECUTION_STATE Flags
  12344. );
  12345. NTKERNELAPI
  12346. PVOID
  12347. PoRegisterSystemState (
  12348. IN PVOID StateHandle,
  12349. IN EXECUTION_STATE Flags
  12350. );
  12351. typedef
  12352. VOID
  12353. (*PREQUEST_POWER_COMPLETE) (
  12354. IN PDEVICE_OBJECT DeviceObject,
  12355. IN UCHAR MinorFunction,
  12356. IN POWER_STATE PowerState,
  12357. IN PVOID Context,
  12358. IN PIO_STATUS_BLOCK IoStatus
  12359. );
  12360. NTKERNELAPI
  12361. NTSTATUS
  12362. PoRequestPowerIrp (
  12363. IN PDEVICE_OBJECT DeviceObject,
  12364. IN UCHAR MinorFunction,
  12365. IN POWER_STATE PowerState,
  12366. IN PREQUEST_POWER_COMPLETE CompletionFunction,
  12367. IN PVOID Context,
  12368. OUT PIRP *Irp OPTIONAL
  12369. );
  12370. NTKERNELAPI
  12371. NTSTATUS
  12372. PoRequestShutdownEvent (
  12373. OUT PVOID *Event
  12374. );
  12375. NTKERNELAPI
  12376. NTSTATUS
  12377. PoRequestShutdownWait (
  12378. IN PETHREAD Thread
  12379. );
  12380. NTKERNELAPI
  12381. VOID
  12382. PoUnregisterSystemState (
  12383. IN PVOID StateHandle
  12384. );
  12385. NTKERNELAPI
  12386. POWER_STATE
  12387. PoSetPowerState (
  12388. IN PDEVICE_OBJECT DeviceObject,
  12389. IN POWER_STATE_TYPE Type,
  12390. IN POWER_STATE State
  12391. );
  12392. NTKERNELAPI
  12393. NTSTATUS
  12394. PoCallDriver (
  12395. IN PDEVICE_OBJECT DeviceObject,
  12396. IN OUT PIRP Irp
  12397. );
  12398. NTKERNELAPI
  12399. VOID
  12400. PoStartNextPowerIrp(
  12401. IN PIRP Irp
  12402. );
  12403. NTKERNELAPI
  12404. PULONG
  12405. PoRegisterDeviceForIdleDetection (
  12406. IN PDEVICE_OBJECT DeviceObject,
  12407. IN ULONG ConservationIdleTime,
  12408. IN ULONG PerformanceIdleTime,
  12409. IN DEVICE_POWER_STATE State
  12410. );
  12411. #define PoSetDeviceBusy(IdlePointer) \
  12412. *IdlePointer = 0
  12413. //
  12414. // \Callback\PowerState values
  12415. //
  12416. #define PO_CB_SYSTEM_POWER_POLICY 0
  12417. #define PO_CB_AC_STATUS 1
  12418. #define PO_CB_BUTTON_COLLISION 2
  12419. #define PO_CB_SYSTEM_STATE_LOCK 3
  12420. #define PO_CB_LID_SWITCH_STATE 4
  12421. #define PO_CB_PROCESSOR_POWER_POLICY 5
  12422. //
  12423. // Object Manager types
  12424. //
  12425. typedef struct _OBJECT_HANDLE_INFORMATION {
  12426. ULONG HandleAttributes;
  12427. ACCESS_MASK GrantedAccess;
  12428. } OBJECT_HANDLE_INFORMATION, *POBJECT_HANDLE_INFORMATION;
  12429. NTKERNELAPI
  12430. NTSTATUS
  12431. ObReferenceObjectByHandle(
  12432. IN HANDLE Handle,
  12433. IN ACCESS_MASK DesiredAccess,
  12434. IN POBJECT_TYPE ObjectType OPTIONAL,
  12435. IN KPROCESSOR_MODE AccessMode,
  12436. OUT PVOID *Object,
  12437. OUT POBJECT_HANDLE_INFORMATION HandleInformation OPTIONAL
  12438. );
  12439. #define ObDereferenceObject(a) \
  12440. ObfDereferenceObject(a)
  12441. #define ObReferenceObject(Object) ObfReferenceObject(Object)
  12442. NTKERNELAPI
  12443. LONG_PTR
  12444. FASTCALL
  12445. ObfReferenceObject(
  12446. IN PVOID Object
  12447. );
  12448. NTKERNELAPI
  12449. NTSTATUS
  12450. ObReferenceObjectByPointer(
  12451. IN PVOID Object,
  12452. IN ACCESS_MASK DesiredAccess,
  12453. IN POBJECT_TYPE ObjectType,
  12454. IN KPROCESSOR_MODE AccessMode
  12455. );
  12456. NTKERNELAPI
  12457. LONG_PTR
  12458. FASTCALL
  12459. ObfDereferenceObject(
  12460. IN PVOID Object
  12461. );
  12462. NTSTATUS
  12463. ObGetObjectSecurity(
  12464. IN PVOID Object,
  12465. OUT PSECURITY_DESCRIPTOR *SecurityDescriptor,
  12466. OUT PBOOLEAN MemoryAllocated
  12467. );
  12468. VOID
  12469. ObReleaseObjectSecurity(
  12470. IN PSECURITY_DESCRIPTOR SecurityDescriptor,
  12471. IN BOOLEAN MemoryAllocated
  12472. );
  12473. typedef struct _PCI_SLOT_NUMBER {
  12474. union {
  12475. struct {
  12476. ULONG DeviceNumber:5;
  12477. ULONG FunctionNumber:3;
  12478. ULONG Reserved:24;
  12479. } bits;
  12480. ULONG AsULONG;
  12481. } u;
  12482. } PCI_SLOT_NUMBER, *PPCI_SLOT_NUMBER;
  12483. #define PCI_TYPE0_ADDRESSES 6
  12484. #define PCI_TYPE1_ADDRESSES 2
  12485. #define PCI_TYPE2_ADDRESSES 5
  12486. typedef struct _PCI_COMMON_CONFIG {
  12487. USHORT VendorID; // (ro)
  12488. USHORT DeviceID; // (ro)
  12489. USHORT Command; // Device control
  12490. USHORT Status;
  12491. UCHAR RevisionID; // (ro)
  12492. UCHAR ProgIf; // (ro)
  12493. UCHAR SubClass; // (ro)
  12494. UCHAR BaseClass; // (ro)
  12495. UCHAR CacheLineSize; // (ro+)
  12496. UCHAR LatencyTimer; // (ro+)
  12497. UCHAR HeaderType; // (ro)
  12498. UCHAR BIST; // Built in self test
  12499. union {
  12500. struct _PCI_HEADER_TYPE_0 {
  12501. ULONG BaseAddresses[PCI_TYPE0_ADDRESSES];
  12502. ULONG CIS;
  12503. USHORT SubVendorID;
  12504. USHORT SubSystemID;
  12505. ULONG ROMBaseAddress;
  12506. UCHAR CapabilitiesPtr;
  12507. UCHAR Reserved1[3];
  12508. ULONG Reserved2;
  12509. UCHAR InterruptLine; //
  12510. UCHAR InterruptPin; // (ro)
  12511. UCHAR MinimumGrant; // (ro)
  12512. UCHAR MaximumLatency; // (ro)
  12513. } type0;
  12514. } u;
  12515. UCHAR DeviceSpecific[192];
  12516. } PCI_COMMON_CONFIG, *PPCI_COMMON_CONFIG;
  12517. #define PCI_COMMON_HDR_LENGTH (FIELD_OFFSET (PCI_COMMON_CONFIG, DeviceSpecific))
  12518. #define PCI_MAX_DEVICES 32
  12519. #define PCI_MAX_FUNCTION 8
  12520. #define PCI_MAX_BRIDGE_NUMBER 0xFF
  12521. #define PCI_INVALID_VENDORID 0xFFFF
  12522. //
  12523. // Bit encodings for PCI_COMMON_CONFIG.HeaderType
  12524. //
  12525. #define PCI_MULTIFUNCTION 0x80
  12526. #define PCI_DEVICE_TYPE 0x00
  12527. #define PCI_BRIDGE_TYPE 0x01
  12528. #define PCI_CARDBUS_BRIDGE_TYPE 0x02
  12529. #define PCI_CONFIGURATION_TYPE(PciData) \
  12530. (((PPCI_COMMON_CONFIG)(PciData))->HeaderType & ~PCI_MULTIFUNCTION)
  12531. #define PCI_MULTIFUNCTION_DEVICE(PciData) \
  12532. ((((PPCI_COMMON_CONFIG)(PciData))->HeaderType & PCI_MULTIFUNCTION) != 0)
  12533. //
  12534. // Bit encodings for PCI_COMMON_CONFIG.Command
  12535. //
  12536. #define PCI_ENABLE_IO_SPACE 0x0001
  12537. #define PCI_ENABLE_MEMORY_SPACE 0x0002
  12538. #define PCI_ENABLE_BUS_MASTER 0x0004
  12539. #define PCI_ENABLE_SPECIAL_CYCLES 0x0008
  12540. #define PCI_ENABLE_WRITE_AND_INVALIDATE 0x0010
  12541. #define PCI_ENABLE_VGA_COMPATIBLE_PALETTE 0x0020
  12542. #define PCI_ENABLE_PARITY 0x0040 // (ro+)
  12543. #define PCI_ENABLE_WAIT_CYCLE 0x0080 // (ro+)
  12544. #define PCI_ENABLE_SERR 0x0100 // (ro+)
  12545. #define PCI_ENABLE_FAST_BACK_TO_BACK 0x0200 // (ro)
  12546. //
  12547. // Bit encodings for PCI_COMMON_CONFIG.Status
  12548. //
  12549. #define PCI_STATUS_CAPABILITIES_LIST 0x0010 // (ro)
  12550. #define PCI_STATUS_66MHZ_CAPABLE 0x0020 // (ro)
  12551. #define PCI_STATUS_UDF_SUPPORTED 0x0040 // (ro)
  12552. #define PCI_STATUS_FAST_BACK_TO_BACK 0x0080 // (ro)
  12553. #define PCI_STATUS_DATA_PARITY_DETECTED 0x0100
  12554. #define PCI_STATUS_DEVSEL 0x0600 // 2 bits wide
  12555. #define PCI_STATUS_SIGNALED_TARGET_ABORT 0x0800
  12556. #define PCI_STATUS_RECEIVED_TARGET_ABORT 0x1000
  12557. #define PCI_STATUS_RECEIVED_MASTER_ABORT 0x2000
  12558. #define PCI_STATUS_SIGNALED_SYSTEM_ERROR 0x4000
  12559. #define PCI_STATUS_DETECTED_PARITY_ERROR 0x8000
  12560. //
  12561. // The NT PCI Driver uses a WhichSpace parameter on its CONFIG_READ/WRITE
  12562. // routines. The following values are defined-
  12563. //
  12564. #define PCI_WHICHSPACE_CONFIG 0x0
  12565. #define PCI_WHICHSPACE_ROM 0x52696350
  12566. //
  12567. // Base Class Code encodings for Base Class (from PCI spec rev 2.1).
  12568. //
  12569. #define PCI_CLASS_PRE_20 0x00
  12570. #define PCI_CLASS_MASS_STORAGE_CTLR 0x01
  12571. #define PCI_CLASS_NETWORK_CTLR 0x02
  12572. #define PCI_CLASS_DISPLAY_CTLR 0x03
  12573. #define PCI_CLASS_MULTIMEDIA_DEV 0x04
  12574. #define PCI_CLASS_MEMORY_CTLR 0x05
  12575. #define PCI_CLASS_BRIDGE_DEV 0x06
  12576. #define PCI_CLASS_SIMPLE_COMMS_CTLR 0x07
  12577. #define PCI_CLASS_BASE_SYSTEM_DEV 0x08
  12578. #define PCI_CLASS_INPUT_DEV 0x09
  12579. #define PCI_CLASS_DOCKING_STATION 0x0a
  12580. #define PCI_CLASS_PROCESSOR 0x0b
  12581. #define PCI_CLASS_SERIAL_BUS_CTLR 0x0c
  12582. #define PCI_CLASS_WIRELESS_CTLR 0x0d
  12583. #define PCI_CLASS_INTELLIGENT_IO_CTLR 0x0e
  12584. #define PCI_CLASS_SATELLITE_COMMS_CTLR 0x0f
  12585. #define PCI_CLASS_ENCRYPTION_DECRYPTION 0x10
  12586. #define PCI_CLASS_DATA_ACQ_SIGNAL_PROC 0x11
  12587. // 0d thru fe reserved
  12588. #define PCI_CLASS_NOT_DEFINED 0xff
  12589. //
  12590. // Sub Class Code encodings (PCI rev 2.1).
  12591. //
  12592. // Class 00 - PCI_CLASS_PRE_20
  12593. #define PCI_SUBCLASS_PRE_20_NON_VGA 0x00
  12594. #define PCI_SUBCLASS_PRE_20_VGA 0x01
  12595. // Class 01 - PCI_CLASS_MASS_STORAGE_CTLR
  12596. #define PCI_SUBCLASS_MSC_SCSI_BUS_CTLR 0x00
  12597. #define PCI_SUBCLASS_MSC_IDE_CTLR 0x01
  12598. #define PCI_SUBCLASS_MSC_FLOPPY_CTLR 0x02
  12599. #define PCI_SUBCLASS_MSC_IPI_CTLR 0x03
  12600. #define PCI_SUBCLASS_MSC_RAID_CTLR 0x04
  12601. #define PCI_SUBCLASS_MSC_OTHER 0x80
  12602. // Class 02 - PCI_CLASS_NETWORK_CTLR
  12603. #define PCI_SUBCLASS_NET_ETHERNET_CTLR 0x00
  12604. #define PCI_SUBCLASS_NET_TOKEN_RING_CTLR 0x01
  12605. #define PCI_SUBCLASS_NET_FDDI_CTLR 0x02
  12606. #define PCI_SUBCLASS_NET_ATM_CTLR 0x03
  12607. #define PCI_SUBCLASS_NET_ISDN_CTLR 0x04
  12608. #define PCI_SUBCLASS_NET_OTHER 0x80
  12609. // Class 03 - PCI_CLASS_DISPLAY_CTLR
  12610. // N.B. Sub Class 00 could be VGA or 8514 depending on Interface byte
  12611. #define PCI_SUBCLASS_VID_VGA_CTLR 0x00
  12612. #define PCI_SUBCLASS_VID_XGA_CTLR 0x01
  12613. #define PCI_SUBLCASS_VID_3D_CTLR 0x02
  12614. #define PCI_SUBCLASS_VID_OTHER 0x80
  12615. // Class 04 - PCI_CLASS_MULTIMEDIA_DEV
  12616. #define PCI_SUBCLASS_MM_VIDEO_DEV 0x00
  12617. #define PCI_SUBCLASS_MM_AUDIO_DEV 0x01
  12618. #define PCI_SUBCLASS_MM_TELEPHONY_DEV 0x02
  12619. #define PCI_SUBCLASS_MM_OTHER 0x80
  12620. // Class 05 - PCI_CLASS_MEMORY_CTLR
  12621. #define PCI_SUBCLASS_MEM_RAM 0x00
  12622. #define PCI_SUBCLASS_MEM_FLASH 0x01
  12623. #define PCI_SUBCLASS_MEM_OTHER 0x80
  12624. // Class 06 - PCI_CLASS_BRIDGE_DEV
  12625. #define PCI_SUBCLASS_BR_HOST 0x00
  12626. #define PCI_SUBCLASS_BR_ISA 0x01
  12627. #define PCI_SUBCLASS_BR_EISA 0x02
  12628. #define PCI_SUBCLASS_BR_MCA 0x03
  12629. #define PCI_SUBCLASS_BR_PCI_TO_PCI 0x04
  12630. #define PCI_SUBCLASS_BR_PCMCIA 0x05
  12631. #define PCI_SUBCLASS_BR_NUBUS 0x06
  12632. #define PCI_SUBCLASS_BR_CARDBUS 0x07
  12633. #define PCI_SUBCLASS_BR_RACEWAY 0x08
  12634. #define PCI_SUBCLASS_BR_OTHER 0x80
  12635. // Class 07 - PCI_CLASS_SIMPLE_COMMS_CTLR
  12636. // N.B. Sub Class 00 and 01 additional info in Interface byte
  12637. #define PCI_SUBCLASS_COM_SERIAL 0x00
  12638. #define PCI_SUBCLASS_COM_PARALLEL 0x01
  12639. #define PCI_SUBCLASS_COM_MULTIPORT 0x02
  12640. #define PCI_SUBCLASS_COM_MODEM 0x03
  12641. #define PCI_SUBCLASS_COM_OTHER 0x80
  12642. // Class 08 - PCI_CLASS_BASE_SYSTEM_DEV
  12643. // N.B. See Interface byte for additional info.
  12644. #define PCI_SUBCLASS_SYS_INTERRUPT_CTLR 0x00
  12645. #define PCI_SUBCLASS_SYS_DMA_CTLR 0x01
  12646. #define PCI_SUBCLASS_SYS_SYSTEM_TIMER 0x02
  12647. #define PCI_SUBCLASS_SYS_REAL_TIME_CLOCK 0x03
  12648. #define PCI_SUBCLASS_SYS_GEN_HOTPLUG_CTLR 0x04
  12649. #define PCI_SUBCLASS_SYS_OTHER 0x80
  12650. // Class 09 - PCI_CLASS_INPUT_DEV
  12651. #define PCI_SUBCLASS_INP_KEYBOARD 0x00
  12652. #define PCI_SUBCLASS_INP_DIGITIZER 0x01
  12653. #define PCI_SUBCLASS_INP_MOUSE 0x02
  12654. #define PCI_SUBCLASS_INP_SCANNER 0x03
  12655. #define PCI_SUBCLASS_INP_GAMEPORT 0x04
  12656. #define PCI_SUBCLASS_INP_OTHER 0x80
  12657. // Class 0a - PCI_CLASS_DOCKING_STATION
  12658. #define PCI_SUBCLASS_DOC_GENERIC 0x00
  12659. #define PCI_SUBCLASS_DOC_OTHER 0x80
  12660. // Class 0b - PCI_CLASS_PROCESSOR
  12661. #define PCI_SUBCLASS_PROC_386 0x00
  12662. #define PCI_SUBCLASS_PROC_486 0x01
  12663. #define PCI_SUBCLASS_PROC_PENTIUM 0x02
  12664. #define PCI_SUBCLASS_PROC_ALPHA 0x10
  12665. #define PCI_SUBCLASS_PROC_POWERPC 0x20
  12666. #define PCI_SUBCLASS_PROC_COPROCESSOR 0x40
  12667. // Class 0c - PCI_CLASS_SERIAL_BUS_CTLR
  12668. #define PCI_SUBCLASS_SB_IEEE1394 0x00
  12669. #define PCI_SUBCLASS_SB_ACCESS 0x01
  12670. #define PCI_SUBCLASS_SB_SSA 0x02
  12671. #define PCI_SUBCLASS_SB_USB 0x03
  12672. #define PCI_SUBCLASS_SB_FIBRE_CHANNEL 0x04
  12673. #define PCI_SUBCLASS_SB_SMBUS 0x05
  12674. // Class 0d - PCI_CLASS_WIRELESS_CTLR
  12675. #define PCI_SUBCLASS_WIRELESS_IRDA 0x00
  12676. #define PCI_SUBCLASS_WIRELESS_CON_IR 0x01
  12677. #define PCI_SUBCLASS_WIRELESS_RF 0x10
  12678. #define PCI_SUBCLASS_WIRELESS_OTHER 0x80
  12679. // Class 0e - PCI_CLASS_INTELLIGENT_IO_CTLR
  12680. #define PCI_SUBCLASS_INTIO_I2O 0x00
  12681. // Class 0f - PCI_CLASS_SATELLITE_CTLR
  12682. #define PCI_SUBCLASS_SAT_TV 0x01
  12683. #define PCI_SUBCLASS_SAT_AUDIO 0x02
  12684. #define PCI_SUBCLASS_SAT_VOICE 0x03
  12685. #define PCI_SUBCLASS_SAT_DATA 0x04
  12686. // Class 10 - PCI_CLASS_ENCRYPTION_DECRYPTION
  12687. #define PCI_SUBCLASS_CRYPTO_NET_COMP 0x00
  12688. #define PCI_SUBCLASS_CRYPTO_ENTERTAINMENT 0x10
  12689. #define PCI_SUBCLASS_CRYPTO_OTHER 0x80
  12690. // Class 11 - PCI_CLASS_DATA_ACQ_SIGNAL_PROC
  12691. #define PCI_SUBCLASS_DASP_DPIO 0x00
  12692. #define PCI_SUBCLASS_DASP_OTHER 0x80
  12693. //
  12694. // Bit encodes for PCI_COMMON_CONFIG.u.type0.BaseAddresses
  12695. //
  12696. #define PCI_ADDRESS_IO_SPACE 0x00000001 // (ro)
  12697. #define PCI_ADDRESS_MEMORY_TYPE_MASK 0x00000006 // (ro)
  12698. #define PCI_ADDRESS_MEMORY_PREFETCHABLE 0x00000008 // (ro)
  12699. #define PCI_ADDRESS_IO_ADDRESS_MASK 0xfffffffc
  12700. #define PCI_ADDRESS_MEMORY_ADDRESS_MASK 0xfffffff0
  12701. #define PCI_ADDRESS_ROM_ADDRESS_MASK 0xfffff800
  12702. #define PCI_TYPE_32BIT 0
  12703. #define PCI_TYPE_20BIT 2
  12704. #define PCI_TYPE_64BIT 4
  12705. //
  12706. // Bit encodes for PCI_COMMON_CONFIG.u.type0.ROMBaseAddresses
  12707. //
  12708. #define PCI_ROMADDRESS_ENABLED 0x00000001
  12709. //
  12710. // Reference notes for PCI configuration fields:
  12711. //
  12712. // ro these field are read only. changes to these fields are ignored
  12713. //
  12714. // ro+ these field are intended to be read only and should be initialized
  12715. // by the system to their proper values. However, driver may change
  12716. // these settings.
  12717. //
  12718. // ---
  12719. //
  12720. // All resources comsumed by a PCI device start as unitialized
  12721. // under NT. An uninitialized memory or I/O base address can be
  12722. // determined by checking it's corrisponding enabled bit in the
  12723. // PCI_COMMON_CONFIG.Command value. An InterruptLine is unitialized
  12724. // if it contains the value of -1.
  12725. //
  12726. #define PCI_DEVICE_PRESENT_INTERFACE_VERSION 1
  12727. //
  12728. // Flags for PCI_DEVICE_PRESENCE_PARAMETERS
  12729. //
  12730. #define PCI_USE_SUBSYSTEM_IDS 0x00000001
  12731. #define PCI_USE_REVISION 0x00000002
  12732. // The following flags are only valid for IsDevicePresentEx
  12733. #define PCI_USE_VENDEV_IDS 0x00000004
  12734. #define PCI_USE_CLASS_SUBCLASS 0x00000008
  12735. #define PCI_USE_PROGIF 0x00000010
  12736. #define PCI_USE_LOCAL_BUS 0x00000020
  12737. #define PCI_USE_LOCAL_DEVICE 0x00000040
  12738. //
  12739. // Search parameters structure for IsDevicePresentEx
  12740. //
  12741. typedef struct _PCI_DEVICE_PRESENCE_PARAMETERS {
  12742. ULONG Size;
  12743. ULONG Flags;
  12744. USHORT VendorID;
  12745. USHORT DeviceID;
  12746. UCHAR RevisionID;
  12747. USHORT SubVendorID;
  12748. USHORT SubSystemID;
  12749. UCHAR BaseClass;
  12750. UCHAR SubClass;
  12751. UCHAR ProgIf;
  12752. } PCI_DEVICE_PRESENCE_PARAMETERS, *PPCI_DEVICE_PRESENCE_PARAMETERS;
  12753. typedef
  12754. BOOLEAN
  12755. (*PPCI_IS_DEVICE_PRESENT) (
  12756. IN USHORT VendorID,
  12757. IN USHORT DeviceID,
  12758. IN UCHAR RevisionID,
  12759. IN USHORT SubVendorID,
  12760. IN USHORT SubSystemID,
  12761. IN ULONG Flags
  12762. );
  12763. typedef
  12764. BOOLEAN
  12765. (*PPCI_IS_DEVICE_PRESENT_EX) (
  12766. IN PVOID Context,
  12767. IN PPCI_DEVICE_PRESENCE_PARAMETERS Parameters
  12768. );
  12769. typedef struct _PCI_DEVICE_PRESENT_INTERFACE {
  12770. //
  12771. // generic interface header
  12772. //
  12773. USHORT Size;
  12774. USHORT Version;
  12775. PVOID Context;
  12776. PINTERFACE_REFERENCE InterfaceReference;
  12777. PINTERFACE_DEREFERENCE InterfaceDereference;
  12778. //
  12779. // pci device info
  12780. //
  12781. PPCI_IS_DEVICE_PRESENT IsDevicePresent;
  12782. PPCI_IS_DEVICE_PRESENT_EX IsDevicePresentEx;
  12783. } PCI_DEVICE_PRESENT_INTERFACE, *PPCI_DEVICE_PRESENT_INTERFACE;
  12784. #ifdef POOL_TAGGING
  12785. #define ExAllocatePool(a,b) ExAllocatePoolWithTag(a,b,' mdW')
  12786. #define ExAllocatePoolWithQuota(a,b) ExAllocatePoolWithQuotaTag(a,b,' kdD')
  12787. #endif
  12788. extern POBJECT_TYPE *IoFileObjectType;
  12789. extern POBJECT_TYPE *ExEventObjectType;
  12790. extern POBJECT_TYPE *ExSemaphoreObjectType;
  12791. //
  12792. // Define exported ZwXxx routines to device drivers.
  12793. //
  12794. NTSYSAPI
  12795. NTSTATUS
  12796. NTAPI
  12797. ZwCreateFile(
  12798. OUT PHANDLE FileHandle,
  12799. IN ACCESS_MASK DesiredAccess,
  12800. IN POBJECT_ATTRIBUTES ObjectAttributes,
  12801. OUT PIO_STATUS_BLOCK IoStatusBlock,
  12802. IN PLARGE_INTEGER AllocationSize OPTIONAL,
  12803. IN ULONG FileAttributes,
  12804. IN ULONG ShareAccess,
  12805. IN ULONG CreateDisposition,
  12806. IN ULONG CreateOptions,
  12807. IN PVOID EaBuffer OPTIONAL,
  12808. IN ULONG EaLength
  12809. );
  12810. NTSYSAPI
  12811. NTSTATUS
  12812. NTAPI
  12813. ZwOpenFile(
  12814. OUT PHANDLE FileHandle,
  12815. IN ACCESS_MASK DesiredAccess,
  12816. IN POBJECT_ATTRIBUTES ObjectAttributes,
  12817. OUT PIO_STATUS_BLOCK IoStatusBlock,
  12818. IN ULONG ShareAccess,
  12819. IN ULONG OpenOptions
  12820. );
  12821. NTSYSAPI
  12822. NTSTATUS
  12823. NTAPI
  12824. ZwQueryInformationFile(
  12825. IN HANDLE FileHandle,
  12826. OUT PIO_STATUS_BLOCK IoStatusBlock,
  12827. OUT PVOID FileInformation,
  12828. IN ULONG Length,
  12829. IN FILE_INFORMATION_CLASS FileInformationClass
  12830. );
  12831. NTSYSAPI
  12832. NTSTATUS
  12833. NTAPI
  12834. ZwSetInformationFile(
  12835. IN HANDLE FileHandle,
  12836. OUT PIO_STATUS_BLOCK IoStatusBlock,
  12837. IN PVOID FileInformation,
  12838. IN ULONG Length,
  12839. IN FILE_INFORMATION_CLASS FileInformationClass
  12840. );
  12841. NTSYSAPI
  12842. NTSTATUS
  12843. NTAPI
  12844. ZwReadFile(
  12845. IN HANDLE FileHandle,
  12846. IN HANDLE Event OPTIONAL,
  12847. IN PIO_APC_ROUTINE ApcRoutine OPTIONAL,
  12848. IN PVOID ApcContext OPTIONAL,
  12849. OUT PIO_STATUS_BLOCK IoStatusBlock,
  12850. OUT PVOID Buffer,
  12851. IN ULONG Length,
  12852. IN PLARGE_INTEGER ByteOffset OPTIONAL,
  12853. IN PULONG Key OPTIONAL
  12854. );
  12855. NTSYSAPI
  12856. NTSTATUS
  12857. NTAPI
  12858. ZwWriteFile(
  12859. IN HANDLE FileHandle,
  12860. IN HANDLE Event OPTIONAL,
  12861. IN PIO_APC_ROUTINE ApcRoutine OPTIONAL,
  12862. IN PVOID ApcContext OPTIONAL,
  12863. OUT PIO_STATUS_BLOCK IoStatusBlock,
  12864. IN PVOID Buffer,
  12865. IN ULONG Length,
  12866. IN PLARGE_INTEGER ByteOffset OPTIONAL,
  12867. IN PULONG Key OPTIONAL
  12868. );
  12869. NTSYSAPI
  12870. NTSTATUS
  12871. NTAPI
  12872. ZwClose(
  12873. IN HANDLE Handle
  12874. );
  12875. NTSYSAPI
  12876. NTSTATUS
  12877. NTAPI
  12878. ZwCreateDirectoryObject(
  12879. OUT PHANDLE DirectoryHandle,
  12880. IN ACCESS_MASK DesiredAccess,
  12881. IN POBJECT_ATTRIBUTES ObjectAttributes
  12882. );
  12883. NTSYSAPI
  12884. NTSTATUS
  12885. NTAPI
  12886. ZwMakeTemporaryObject(
  12887. IN HANDLE Handle
  12888. );
  12889. NTSYSAPI
  12890. NTSTATUS
  12891. NTAPI
  12892. ZwCreateSection (
  12893. OUT PHANDLE SectionHandle,
  12894. IN ACCESS_MASK DesiredAccess,
  12895. IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL,
  12896. IN PLARGE_INTEGER MaximumSize OPTIONAL,
  12897. IN ULONG SectionPageProtection,
  12898. IN ULONG AllocationAttributes,
  12899. IN HANDLE FileHandle OPTIONAL
  12900. );
  12901. NTSYSAPI
  12902. NTSTATUS
  12903. NTAPI
  12904. ZwOpenSection(
  12905. OUT PHANDLE SectionHandle,
  12906. IN ACCESS_MASK DesiredAccess,
  12907. IN POBJECT_ATTRIBUTES ObjectAttributes
  12908. );
  12909. NTSYSAPI
  12910. NTSTATUS
  12911. NTAPI
  12912. ZwMapViewOfSection(
  12913. IN HANDLE SectionHandle,
  12914. IN HANDLE ProcessHandle,
  12915. IN OUT PVOID *BaseAddress,
  12916. IN ULONG ZeroBits,
  12917. IN SIZE_T CommitSize,
  12918. IN OUT PLARGE_INTEGER SectionOffset OPTIONAL,
  12919. IN OUT PSIZE_T ViewSize,
  12920. IN SECTION_INHERIT InheritDisposition,
  12921. IN ULONG AllocationType,
  12922. IN ULONG Protect
  12923. );
  12924. NTSYSAPI
  12925. NTSTATUS
  12926. NTAPI
  12927. ZwUnmapViewOfSection(
  12928. IN HANDLE ProcessHandle,
  12929. IN PVOID BaseAddress
  12930. );
  12931. NTSYSAPI
  12932. NTSTATUS
  12933. NTAPI
  12934. ZwCreateKey(
  12935. OUT PHANDLE KeyHandle,
  12936. IN ACCESS_MASK DesiredAccess,
  12937. IN POBJECT_ATTRIBUTES ObjectAttributes,
  12938. IN ULONG TitleIndex,
  12939. IN PUNICODE_STRING Class OPTIONAL,
  12940. IN ULONG CreateOptions,
  12941. OUT PULONG Disposition OPTIONAL
  12942. );
  12943. NTSYSAPI
  12944. NTSTATUS
  12945. NTAPI
  12946. ZwOpenKey(
  12947. OUT PHANDLE KeyHandle,
  12948. IN ACCESS_MASK DesiredAccess,
  12949. IN POBJECT_ATTRIBUTES ObjectAttributes
  12950. );
  12951. NTSYSAPI
  12952. NTSTATUS
  12953. NTAPI
  12954. ZwDeleteKey(
  12955. IN HANDLE KeyHandle
  12956. );
  12957. NTSYSAPI
  12958. NTSTATUS
  12959. NTAPI
  12960. ZwDeleteValueKey(
  12961. IN HANDLE KeyHandle,
  12962. IN PUNICODE_STRING ValueName
  12963. );
  12964. NTSYSAPI
  12965. NTSTATUS
  12966. NTAPI
  12967. ZwEnumerateKey(
  12968. IN HANDLE KeyHandle,
  12969. IN ULONG Index,
  12970. IN KEY_INFORMATION_CLASS KeyInformationClass,
  12971. OUT PVOID KeyInformation,
  12972. IN ULONG Length,
  12973. OUT PULONG ResultLength
  12974. );
  12975. NTSYSAPI
  12976. NTSTATUS
  12977. NTAPI
  12978. ZwEnumerateValueKey(
  12979. IN HANDLE KeyHandle,
  12980. IN ULONG Index,
  12981. IN KEY_VALUE_INFORMATION_CLASS KeyValueInformationClass,
  12982. OUT PVOID KeyValueInformation,
  12983. IN ULONG Length,
  12984. OUT PULONG ResultLength
  12985. );
  12986. NTSYSAPI
  12987. NTSTATUS
  12988. NTAPI
  12989. ZwFlushKey(
  12990. IN HANDLE KeyHandle
  12991. );
  12992. NTSYSAPI
  12993. NTSTATUS
  12994. NTAPI
  12995. ZwQueryKey(
  12996. IN HANDLE KeyHandle,
  12997. IN KEY_INFORMATION_CLASS KeyInformationClass,
  12998. OUT PVOID KeyInformation,
  12999. IN ULONG Length,
  13000. OUT PULONG ResultLength
  13001. );
  13002. NTSYSAPI
  13003. NTSTATUS
  13004. NTAPI
  13005. ZwQueryValueKey(
  13006. IN HANDLE KeyHandle,
  13007. IN PUNICODE_STRING ValueName,
  13008. IN KEY_VALUE_INFORMATION_CLASS KeyValueInformationClass,
  13009. OUT PVOID KeyValueInformation,
  13010. IN ULONG Length,
  13011. OUT PULONG ResultLength
  13012. );
  13013. NTSYSAPI
  13014. NTSTATUS
  13015. NTAPI
  13016. ZwSetValueKey(
  13017. IN HANDLE KeyHandle,
  13018. IN PUNICODE_STRING ValueName,
  13019. IN ULONG TitleIndex OPTIONAL,
  13020. IN ULONG Type,
  13021. IN PVOID Data,
  13022. IN ULONG DataSize
  13023. );
  13024. NTSYSAPI
  13025. NTSTATUS
  13026. NTAPI
  13027. ZwOpenSymbolicLinkObject(
  13028. OUT PHANDLE LinkHandle,
  13029. IN ACCESS_MASK DesiredAccess,
  13030. IN POBJECT_ATTRIBUTES ObjectAttributes
  13031. );
  13032. NTSYSAPI
  13033. NTSTATUS
  13034. NTAPI
  13035. ZwQuerySymbolicLinkObject(
  13036. IN HANDLE LinkHandle,
  13037. IN OUT PUNICODE_STRING LinkTarget,
  13038. OUT PULONG ReturnedLength OPTIONAL
  13039. );
  13040. #ifdef VERIFIER_DDK_EXTENSIONS
  13041. #include <ddk_ext.h>
  13042. #endif
  13043. #endif // _WDMDDK_