Source code of Windows XP (NT5)
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.

15207 lines
351 KiB

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