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

21415 lines
498 KiB

  1. /*++ BUILD Version: 0134 // Increment this if a change has global effects
  2. Copyright (c) Microsoft Corporation. All rights reserved.
  3. Module Name:
  4. ntosp.h
  5. Abstract:
  6. This module defines the NT types, constants, and functions that are
  7. exposed to external projects like Windows and Termsrv
  8. Revision History:
  9. --*/
  10. #ifndef _NTOSP_
  11. #define _NTOSP_
  12. #ifdef _NTDDK_
  13. #error "Can't include ntddk.h and ntosp.h"
  14. #else
  15. #define _NTDDK_
  16. #endif
  17. #include <nt.h>
  18. #include <ntrtl.h>
  19. #include <excpt.h>
  20. #include <ntdef.h>
  21. #include <bugcodes.h>
  22. #include <arc.h>
  23. #include <arccodes.h>
  24. //
  25. // Kernel Mutex Level Numbers (must be globallly assigned within executive)
  26. // The third token in the name is the sub-component name that defines and
  27. // uses the level number.
  28. //
  29. //
  30. // Used by Vdm for protecting io simulation structures
  31. //
  32. #define MUTEX_LEVEL_VDM_IO (ULONG)0x00000001
  33. #define MUTEX_LEVEL_EX_PROFILE (ULONG)0x00000040
  34. //
  35. // The LANMAN Redirector uses the file system major function, but defines
  36. // it's own mutex levels. We can do this safely because we know that the
  37. // local filesystem will never call the remote filesystem and vice versa.
  38. //
  39. #define MUTEX_LEVEL_RDR_FILESYS_DATABASE (ULONG)0x10100000
  40. #define MUTEX_LEVEL_RDR_FILESYS_SECURITY (ULONG)0x10100001
  41. //
  42. // File System levels.
  43. //
  44. #define MUTEX_LEVEL_FILESYSTEM_RAW_VCB (ULONG)0x11000006
  45. //
  46. // In the NT STREAMS environment, a mutex is used to serialize open, close
  47. // and Scheduler threads executing in a subsystem-parallelized stack.
  48. //
  49. #define MUTEX_LEVEL_STREAMS_SUBSYS (ULONG)0x11001001
  50. //
  51. // Mutex level used by LDT support on x86
  52. //
  53. #define MUTEX_LEVEL_PS_LDT (ULONG)0x1F000000
  54. #ifdef __cplusplus
  55. extern "C" { // extern "C"
  56. #endif
  57. //
  58. // Define types that are not exported.
  59. //
  60. typedef struct _ACCESS_STATE *PACCESS_STATE;
  61. typedef struct _BUS_HANDLER *PBUS_HANDLER;
  62. typedef struct _EJOB *PEJOB;
  63. typedef struct _EPROCESS *PEPROCESS;
  64. typedef struct _ERESOURCE *PERESOURCE;
  65. typedef struct _ETHREAD *PETHREAD;
  66. typedef struct _IO_TIMER *PIO_TIMER;
  67. typedef struct _IRP *PIRP;
  68. typedef struct _KPROCESS *PKPROCESS, *RESTRICTED_POINTER PRKPROCESS;
  69. typedef struct _KTHREAD *PKTHREAD, *PRKTHREAD;
  70. typedef struct _KTRAP_FRAME *PKTRAP_FRAME;
  71. typedef struct _LOADER_PARAMETER_BLOCK *PLOADER_PARAMETER_BLOCK;
  72. typedef struct _TRANSLATOR_INTERFACE *PTRANSLATOR_INTERFACE;
  73. typedef struct _HANDLE_TABLE *PHANDLE_TABLE;
  74. //
  75. // Define macros to fix up structure references
  76. //
  77. #define PEProcessToPKProcess(P) ((PKPROCESS)P)
  78. #if defined(_M_AMD64)
  79. PKTHREAD
  80. NTAPI
  81. KeGetCurrentThread(
  82. VOID
  83. );
  84. #endif // defined(_M_AMD64)
  85. #if defined(_M_IX86)
  86. PKTHREAD NTAPI KeGetCurrentThread();
  87. #endif // defined(_M_IX86)
  88. #if defined(_M_IA64)
  89. //
  90. // Define Address of Processor Control Registers.
  91. //
  92. #define KIPCR ((ULONG_PTR)(KADDRESS_BASE + 0xffff0000)) // kernel address of first PCR
  93. //
  94. // Define Pointer to Processor Control Registers.
  95. //
  96. #define PCR ((volatile KPCR * const)KIPCR)
  97. PKTHREAD NTAPI KeGetCurrentThread();
  98. #endif // defined(_M_IA64)
  99. //
  100. // Define per processor nonpaged lookaside list descriptor structure.
  101. //
  102. struct _NPAGED_LOOKASIDE_LIST;
  103. typedef struct _PP_LOOKASIDE_LIST {
  104. struct _GENERAL_LOOKASIDE *P;
  105. struct _GENERAL_LOOKASIDE *L;
  106. } PP_LOOKASIDE_LIST, *PPP_LOOKASIDE_LIST;
  107. //
  108. // Define the number of small pool lists.
  109. //
  110. // N.B. This value is used in pool.h and is used to allocate single entry
  111. // lookaside lists in the processor block of each processor.
  112. #define POOL_SMALL_LISTS 32
  113. // begin_ntddk begin_wdm begin_nthal begin_ntifs
  114. //
  115. // Define alignment macros to align structure sizes and pointers up and down.
  116. //
  117. #define ALIGN_DOWN(length, type) \
  118. ((ULONG)(length) & ~(sizeof(type) - 1))
  119. #define ALIGN_UP(length, type) \
  120. (ALIGN_DOWN(((ULONG)(length) + sizeof(type) - 1), type))
  121. #define ALIGN_DOWN_POINTER(address, type) \
  122. ((PVOID)((ULONG_PTR)(address) & ~((ULONG_PTR)sizeof(type) - 1)))
  123. #define ALIGN_UP_POINTER(address, type) \
  124. (ALIGN_DOWN_POINTER(((ULONG_PTR)(address) + sizeof(type) - 1), type))
  125. #define POOL_TAGGING 1
  126. #ifndef DBG
  127. #define DBG 0
  128. #endif
  129. #if DBG
  130. #define IF_DEBUG if (TRUE)
  131. #else
  132. #define IF_DEBUG if (FALSE)
  133. #endif
  134. #if DEVL
  135. extern ULONG NtGlobalFlag;
  136. #define IF_NTOS_DEBUG( FlagName ) \
  137. if (NtGlobalFlag & (FLG_ ## FlagName))
  138. #else
  139. #define IF_NTOS_DEBUG( FlagName ) if (FALSE)
  140. #endif
  141. //
  142. // Kernel definitions that need to be here for forward reference purposes
  143. //
  144. // begin_ntndis
  145. //
  146. // Processor modes.
  147. //
  148. typedef CCHAR KPROCESSOR_MODE;
  149. typedef enum _MODE {
  150. KernelMode,
  151. UserMode,
  152. MaximumMode
  153. } MODE;
  154. // end_ntndis
  155. //
  156. // APC function types
  157. //
  158. //
  159. // Put in an empty definition for the KAPC so that the
  160. // routines can reference it before it is declared.
  161. //
  162. struct _KAPC;
  163. typedef
  164. VOID
  165. (*PKNORMAL_ROUTINE) (
  166. IN PVOID NormalContext,
  167. IN PVOID SystemArgument1,
  168. IN PVOID SystemArgument2
  169. );
  170. typedef
  171. VOID
  172. (*PKKERNEL_ROUTINE) (
  173. IN struct _KAPC *Apc,
  174. IN OUT PKNORMAL_ROUTINE *NormalRoutine,
  175. IN OUT PVOID *NormalContext,
  176. IN OUT PVOID *SystemArgument1,
  177. IN OUT PVOID *SystemArgument2
  178. );
  179. typedef
  180. VOID
  181. (*PKRUNDOWN_ROUTINE) (
  182. IN struct _KAPC *Apc
  183. );
  184. typedef
  185. BOOLEAN
  186. (*PKSYNCHRONIZE_ROUTINE) (
  187. IN PVOID SynchronizeContext
  188. );
  189. typedef
  190. BOOLEAN
  191. (*PKTRANSFER_ROUTINE) (
  192. VOID
  193. );
  194. //
  195. //
  196. // Asynchronous Procedure Call (APC) object
  197. //
  198. //
  199. typedef struct _KAPC {
  200. CSHORT Type;
  201. CSHORT Size;
  202. ULONG Spare0;
  203. struct _KTHREAD *Thread;
  204. LIST_ENTRY ApcListEntry;
  205. PKKERNEL_ROUTINE KernelRoutine;
  206. PKRUNDOWN_ROUTINE RundownRoutine;
  207. PKNORMAL_ROUTINE NormalRoutine;
  208. PVOID NormalContext;
  209. //
  210. // N.B. The following two members MUST be together.
  211. //
  212. PVOID SystemArgument1;
  213. PVOID SystemArgument2;
  214. CCHAR ApcStateIndex;
  215. KPROCESSOR_MODE ApcMode;
  216. BOOLEAN Inserted;
  217. } KAPC, *PKAPC, *RESTRICTED_POINTER PRKAPC;
  218. // begin_ntndis
  219. //
  220. // DPC routine
  221. //
  222. struct _KDPC;
  223. typedef
  224. VOID
  225. (*PKDEFERRED_ROUTINE) (
  226. IN struct _KDPC *Dpc,
  227. IN PVOID DeferredContext,
  228. IN PVOID SystemArgument1,
  229. IN PVOID SystemArgument2
  230. );
  231. //
  232. // Define DPC importance.
  233. //
  234. // LowImportance - Queue DPC at end of target DPC queue.
  235. // MediumImportance - Queue DPC at end of target DPC queue.
  236. // HighImportance - Queue DPC at front of target DPC DPC queue.
  237. //
  238. // If there is currently a DPC active on the target processor, or a DPC
  239. // interrupt has already been requested on the target processor when a
  240. // DPC is queued, then no further action is necessary. The DPC will be
  241. // executed on the target processor when its queue entry is processed.
  242. //
  243. // If there is not a DPC active on the target processor and a DPC interrupt
  244. // has not been requested on the target processor, then the exact treatment
  245. // of the DPC is dependent on whether the host system is a UP system or an
  246. // MP system.
  247. //
  248. // UP system.
  249. //
  250. // If the DPC is of medium or high importance, the current DPC queue depth
  251. // is greater than the maximum target depth, or current DPC request rate is
  252. // less the minimum target rate, then a DPC interrupt is requested on the
  253. // host processor and the DPC will be processed when the interrupt occurs.
  254. // Otherwise, no DPC interupt is requested and the DPC execution will be
  255. // delayed until the DPC queue depth is greater that the target depth or the
  256. // minimum DPC rate is less than the target rate.
  257. //
  258. // MP system.
  259. //
  260. // If the DPC is being queued to another processor and the depth of the DPC
  261. // queue on the target processor is greater than the maximum target depth or
  262. // the DPC is of high importance, then a DPC interrupt is requested on the
  263. // target processor and the DPC will be processed when the interrupt occurs.
  264. // Otherwise, the DPC execution will be delayed on the target processor until
  265. // the DPC queue depth on the target processor is greater that the maximum
  266. // target depth or the minimum DPC rate on the target processor is less than
  267. // the target mimimum rate.
  268. //
  269. // If the DPC is being queued to the current processor and the DPC is not of
  270. // low importance, the current DPC queue depth is greater than the maximum
  271. // target depth, or the minimum DPC rate is less than the minimum target rate,
  272. // then a DPC interrupt is request on the current processor and the DPV will
  273. // be processed whne the interrupt occurs. Otherwise, no DPC interupt is
  274. // requested and the DPC execution will be delayed until the DPC queue depth
  275. // is greater that the target depth or the minimum DPC rate is less than the
  276. // target rate.
  277. //
  278. typedef enum _KDPC_IMPORTANCE {
  279. LowImportance,
  280. MediumImportance,
  281. HighImportance
  282. } KDPC_IMPORTANCE;
  283. //
  284. // Define DPC type indicies.
  285. //
  286. #define DPC_NORMAL 0
  287. #define DPC_THREADED 1
  288. //
  289. // Deferred Procedure Call (DPC) object
  290. //
  291. typedef struct _KDPC {
  292. CSHORT Type;
  293. UCHAR Number;
  294. UCHAR Importance;
  295. LIST_ENTRY DpcListEntry;
  296. PKDEFERRED_ROUTINE DeferredRoutine;
  297. PVOID DeferredContext;
  298. PVOID SystemArgument1;
  299. PVOID SystemArgument2;
  300. PVOID DpcData;
  301. } KDPC, *PKDPC, *RESTRICTED_POINTER PRKDPC;
  302. //
  303. // Interprocessor interrupt worker routine function prototype.
  304. //
  305. typedef PVOID PKIPI_CONTEXT;
  306. typedef
  307. VOID
  308. (*PKIPI_WORKER)(
  309. IN PKIPI_CONTEXT PacketContext,
  310. IN PVOID Parameter1,
  311. IN PVOID Parameter2,
  312. IN PVOID Parameter3
  313. );
  314. //
  315. // Define interprocessor interrupt performance counters.
  316. //
  317. typedef struct _KIPI_COUNTS {
  318. ULONG Freeze;
  319. ULONG Packet;
  320. ULONG DPC;
  321. ULONG APC;
  322. ULONG FlushSingleTb;
  323. ULONG FlushMultipleTb;
  324. ULONG FlushEntireTb;
  325. ULONG GenericCall;
  326. ULONG ChangeColor;
  327. ULONG SweepDcache;
  328. ULONG SweepIcache;
  329. ULONG SweepIcacheRange;
  330. ULONG FlushIoBuffers;
  331. ULONG GratuitousDPC;
  332. } KIPI_COUNTS, *PKIPI_COUNTS;
  333. //
  334. // I/O system definitions.
  335. //
  336. // Define a Memory Descriptor List (MDL)
  337. //
  338. // An MDL describes pages in a virtual buffer in terms of physical pages. The
  339. // pages associated with the buffer are described in an array that is allocated
  340. // just after the MDL header structure itself.
  341. //
  342. // One simply calculates the base of the array by adding one to the base
  343. // MDL pointer:
  344. //
  345. // Pages = (PPFN_NUMBER) (Mdl + 1);
  346. //
  347. // Notice that while in the context of the subject thread, the base virtual
  348. // address of a buffer mapped by an MDL may be referenced using the following:
  349. //
  350. // Mdl->StartVa | Mdl->ByteOffset
  351. //
  352. typedef struct _MDL {
  353. struct _MDL *Next;
  354. CSHORT Size;
  355. CSHORT MdlFlags;
  356. struct _EPROCESS *Process;
  357. PVOID MappedSystemVa;
  358. PVOID StartVa;
  359. ULONG ByteCount;
  360. ULONG ByteOffset;
  361. } MDL, *PMDL;
  362. #define MDL_MAPPED_TO_SYSTEM_VA 0x0001
  363. #define MDL_PAGES_LOCKED 0x0002
  364. #define MDL_SOURCE_IS_NONPAGED_POOL 0x0004
  365. #define MDL_ALLOCATED_FIXED_SIZE 0x0008
  366. #define MDL_PARTIAL 0x0010
  367. #define MDL_PARTIAL_HAS_BEEN_MAPPED 0x0020
  368. #define MDL_IO_PAGE_READ 0x0040
  369. #define MDL_WRITE_OPERATION 0x0080
  370. #define MDL_PARENT_MAPPED_SYSTEM_VA 0x0100
  371. #define MDL_FREE_EXTRA_PTES 0x0200
  372. #define MDL_DESCRIBES_AWE 0x0400
  373. #define MDL_IO_SPACE 0x0800
  374. #define MDL_NETWORK_HEADER 0x1000
  375. #define MDL_MAPPING_CAN_FAIL 0x2000
  376. #define MDL_ALLOCATED_MUST_SUCCEED 0x4000
  377. #define MDL_MAPPING_FLAGS (MDL_MAPPED_TO_SYSTEM_VA | \
  378. MDL_PAGES_LOCKED | \
  379. MDL_SOURCE_IS_NONPAGED_POOL | \
  380. MDL_PARTIAL_HAS_BEEN_MAPPED | \
  381. MDL_PARENT_MAPPED_SYSTEM_VA | \
  382. MDL_SYSTEM_VA | \
  383. MDL_IO_SPACE )
  384. // end_ntndis
  385. //
  386. // switch to DBG when appropriate
  387. //
  388. #if DBG
  389. #define PAGED_CODE() \
  390. { if (KeGetCurrentIrql() > APC_LEVEL) { \
  391. KdPrint(( "EX: Pageable code called at IRQL %d\n", KeGetCurrentIrql() )); \
  392. ASSERT(FALSE); \
  393. } \
  394. }
  395. #else
  396. #define PAGED_CODE() NOP_FUNCTION;
  397. #endif
  398. //
  399. // Data structure used to represent client security context for a thread.
  400. // This data structure is used to support impersonation.
  401. //
  402. // THE FIELDS OF THIS DATA STRUCTURE SHOULD BE CONSIDERED OPAQUE
  403. // BY ALL EXCEPT THE SECURITY ROUTINES.
  404. //
  405. typedef struct _SECURITY_CLIENT_CONTEXT {
  406. SECURITY_QUALITY_OF_SERVICE SecurityQos;
  407. PACCESS_TOKEN ClientToken;
  408. BOOLEAN DirectlyAccessClientToken;
  409. BOOLEAN DirectAccessEffectiveOnly;
  410. BOOLEAN ServerIsRemote;
  411. TOKEN_CONTROL ClientTokenControl;
  412. } SECURITY_CLIENT_CONTEXT, *PSECURITY_CLIENT_CONTEXT;
  413. //
  414. // where
  415. //
  416. // SecurityQos - is the security quality of service information in effect
  417. // for this client. This information is used when directly accessing
  418. // the client's token. In this case, the information here over-rides
  419. // the information in the client's token. If a copy of the client's
  420. // token is requested, it must be generated using this information,
  421. // not the information in the client's token. In all cases, this
  422. // information may not provide greater access than the information
  423. // in the client's token. In particular, if the client's token is
  424. // an impersonation token with an impersonation level of
  425. // "SecurityDelegation", but the information in this field indicates
  426. // an impersonation level of "SecurityIdentification", then
  427. // the server may only get a copy of the token with an Identification
  428. // level of impersonation.
  429. //
  430. // ClientToken - If the DirectlyAccessClientToken field is FALSE,
  431. // then this field contains a pointer to a duplicate of the
  432. // client's token. Otherwise, this field points directly to
  433. // the client's token.
  434. //
  435. // DirectlyAccessClientToken - This boolean flag indicates whether the
  436. // token pointed to by ClientToken is a copy of the client's token
  437. // or is a direct reference to the client's token. A value of TRUE
  438. // indicates the client's token is directly accessed, FALSE indicates
  439. // a copy has been made.
  440. //
  441. // DirectAccessEffectiveOnly - This boolean flag indicates whether the
  442. // the disabled portions of the token that is currently directly
  443. // referenced may be enabled. This field is only valid if the
  444. // DirectlyAccessClientToken field is TRUE. In that case, this
  445. // value supersedes the EffectiveOnly value in the SecurityQos
  446. // FOR THE CURRENT TOKEN ONLY! If the client changes to impersonate
  447. // another client, this value may change. This value is always
  448. // minimized by the EffectiveOnly flag in the SecurityQos field.
  449. //
  450. // ServerIsRemote - If TRUE indicates that the server of the client's
  451. // request is remote. This is used for determining the legitimacy
  452. // of certain levels of impersonation and to determine how to
  453. // track context.
  454. //
  455. // ClientTokenControl - If the ServerIsRemote flag is TRUE, and the
  456. // tracking mode is DYNAMIC, then this field contains a copy of
  457. // the TOKEN_SOURCE from the client's token to assist in deciding
  458. // whether the information at the remote server needs to be
  459. // updated to match the current state of the client's security
  460. // context.
  461. //
  462. //
  463. // NOTE: At some point, we may find it worthwhile to keep an array of
  464. // elements in this data structure, where each element of the
  465. // array contains {ClientToken, ClientTokenControl} fields.
  466. // This would allow efficient handling of the case where a client
  467. // thread was constantly switching between a couple different
  468. // contexts - presumably impersonating client's of its own.
  469. //
  470. #if defined(_NTSYSTEM_)
  471. #define NTKERNELAPI
  472. #else
  473. #define NTKERNELAPI DECLSPEC_IMPORT // wdm ntddk nthal ntndis ntifs
  474. #endif
  475. #define NTHALAPI DECLSPEC_IMPORT
  476. //
  477. // Common dispatcher object header
  478. //
  479. // N.B. The size field contains the number of dwords in the structure.
  480. //
  481. typedef struct _DISPATCHER_HEADER {
  482. union {
  483. struct {
  484. UCHAR Type;
  485. UCHAR Absolute;
  486. UCHAR Size;
  487. union {
  488. UCHAR Inserted;
  489. BOOLEAN DebugActive;
  490. };
  491. };
  492. volatile LONG Lock;
  493. };
  494. LONG SignalState;
  495. LIST_ENTRY WaitListHead;
  496. } DISPATCHER_HEADER;
  497. //
  498. // Event object
  499. //
  500. typedef struct _KEVENT {
  501. DISPATCHER_HEADER Header;
  502. } KEVENT, *PKEVENT, *RESTRICTED_POINTER PRKEVENT;
  503. //
  504. // Timer object
  505. //
  506. typedef struct _KTIMER {
  507. DISPATCHER_HEADER Header;
  508. ULARGE_INTEGER DueTime;
  509. LIST_ENTRY TimerListEntry;
  510. struct _KDPC *Dpc;
  511. LONG Period;
  512. } KTIMER, *PKTIMER, *RESTRICTED_POINTER PRKTIMER;
  513. typedef enum _LOCK_OPERATION {
  514. IoReadAccess,
  515. IoWriteAccess,
  516. IoModifyAccess
  517. } LOCK_OPERATION;
  518. #ifndef _SLIST_HEADER_
  519. #define _SLIST_HEADER_
  520. #if defined(_WIN64)
  521. //
  522. // The type SINGLE_LIST_ENTRY is not suitable for use with SLISTs. For
  523. // WIN64, an entry on an SLIST is required to be 16-byte aligned, while a
  524. // SINGLE_LIST_ENTRY structure has only 8 byte alignment.
  525. //
  526. // Therefore, all SLIST code should use the SLIST_ENTRY type instead of the
  527. // SINGLE_LIST_ENTRY type.
  528. //
  529. #pragma warning(push)
  530. #pragma warning(disable:4324) // structure padded due to align()
  531. typedef struct DECLSPEC_ALIGN(16) _SLIST_ENTRY *PSLIST_ENTRY;
  532. typedef struct DECLSPEC_ALIGN(16) _SLIST_ENTRY {
  533. PSLIST_ENTRY Next;
  534. } SLIST_ENTRY;
  535. #pragma warning(pop)
  536. #else
  537. #define SLIST_ENTRY SINGLE_LIST_ENTRY
  538. #define _SLIST_ENTRY _SINGLE_LIST_ENTRY
  539. #define PSLIST_ENTRY PSINGLE_LIST_ENTRY
  540. #endif
  541. #if defined(_WIN64)
  542. typedef struct DECLSPEC_ALIGN(16) _SLIST_HEADER {
  543. ULONGLONG Alignment;
  544. ULONGLONG Region;
  545. } SLIST_HEADER;
  546. typedef struct _SLIST_HEADER *PSLIST_HEADER;
  547. #else
  548. typedef union _SLIST_HEADER {
  549. ULONGLONG Alignment;
  550. struct {
  551. SLIST_ENTRY Next;
  552. USHORT Depth;
  553. USHORT Sequence;
  554. };
  555. } SLIST_HEADER, *PSLIST_HEADER;
  556. #endif
  557. #endif
  558. //
  559. // Some simple Rtl routines for IP address <-> string literal conversion
  560. //
  561. struct in_addr;
  562. struct in6_addr;
  563. NTSYSAPI
  564. PSTR
  565. NTAPI
  566. RtlIpv4AddressToStringA (
  567. IN const struct in_addr *Addr,
  568. OUT PSTR S
  569. );
  570. NTSYSAPI
  571. PSTR
  572. NTAPI
  573. RtlIpv6AddressToStringA (
  574. IN const struct in6_addr *Addr,
  575. OUT PSTR S
  576. );
  577. NTSYSAPI
  578. NTSTATUS
  579. NTAPI
  580. RtlIpv4AddressToStringExA(
  581. IN const struct in_addr *Address,
  582. IN USHORT Port,
  583. OUT PSTR AddressString,
  584. IN OUT PULONG AddressStringLength
  585. );
  586. NTSYSAPI
  587. NTSTATUS
  588. NTAPI
  589. RtlIpv6AddressToStringExA(
  590. IN const struct in6_addr *Address,
  591. IN ULONG ScopeId,
  592. IN USHORT Port,
  593. OUT PSTR AddressString,
  594. IN OUT PULONG AddressStringLength
  595. );
  596. NTSYSAPI
  597. PWSTR
  598. NTAPI
  599. RtlIpv4AddressToStringW (
  600. IN const struct in_addr *Addr,
  601. OUT PWSTR S
  602. );
  603. NTSYSAPI
  604. PWSTR
  605. NTAPI
  606. RtlIpv6AddressToStringW (
  607. IN const struct in6_addr *Addr,
  608. OUT PWSTR S
  609. );
  610. NTSYSAPI
  611. NTSTATUS
  612. NTAPI
  613. RtlIpv4AddressToStringExW(
  614. IN const struct in_addr *Address,
  615. IN USHORT Port,
  616. OUT PWSTR AddressString,
  617. IN OUT PULONG AddressStringLength
  618. );
  619. NTSYSAPI
  620. NTSTATUS
  621. NTAPI
  622. RtlIpv6AddressToStringExW(
  623. IN const struct in6_addr *Address,
  624. IN ULONG ScopeId,
  625. IN USHORT Port,
  626. OUT PWSTR AddressString,
  627. IN OUT PULONG AddressStringLength
  628. );
  629. NTSYSAPI
  630. NTSTATUS
  631. NTAPI
  632. RtlIpv4StringToAddressA (
  633. IN PCSTR S,
  634. IN BOOLEAN Strict,
  635. OUT PCSTR *Terminator,
  636. OUT struct in_addr *Addr
  637. );
  638. NTSYSAPI
  639. NTSTATUS
  640. NTAPI
  641. RtlIpv6StringToAddressA (
  642. IN PCSTR S,
  643. OUT PCSTR *Terminator,
  644. OUT struct in6_addr *Addr
  645. );
  646. NTSYSAPI
  647. NTSTATUS
  648. NTAPI
  649. RtlIpv4StringToAddressExA (
  650. IN PCSTR AddressString,
  651. IN BOOLEAN Strict,
  652. OUT struct in_addr *Address,
  653. OUT PUSHORT Port
  654. );
  655. NTSYSAPI
  656. NTSTATUS
  657. NTAPI
  658. RtlIpv6StringToAddressExA (
  659. IN PCSTR AddressString,
  660. OUT struct in6_addr *Address,
  661. OUT PULONG ScopeId,
  662. OUT PUSHORT Port
  663. );
  664. NTSYSAPI
  665. NTSTATUS
  666. NTAPI
  667. RtlIpv4StringToAddressW (
  668. IN PCWSTR S,
  669. IN BOOLEAN Strict,
  670. OUT LPCWSTR *Terminator,
  671. OUT struct in_addr *Addr
  672. );
  673. NTSYSAPI
  674. NTSTATUS
  675. NTAPI
  676. RtlIpv6StringToAddressW (
  677. IN PCWSTR S,
  678. OUT PCWSTR *Terminator,
  679. OUT struct in6_addr *Addr
  680. );
  681. NTSYSAPI
  682. NTSTATUS
  683. NTAPI
  684. RtlIpv4StringToAddressExW (
  685. IN PCWSTR AddressString,
  686. IN BOOLEAN Strict,
  687. OUT struct in_addr *Address,
  688. OUT PUSHORT Port
  689. );
  690. NTSYSAPI
  691. NTSTATUS
  692. NTAPI
  693. RtlIpv6StringToAddressExW (
  694. IN PCWSTR AddressString,
  695. OUT struct in6_addr *Address,
  696. OUT PULONG ScopeId,
  697. OUT PUSHORT Port
  698. );
  699. #ifdef UNICODE
  700. #define RtlIpv4AddressToString RtlIpv4AddressToStringW
  701. #define RtlIpv6AddressToString RtlIpv6AddressToStringW
  702. #define RtlIpv4StringToAddress RtlIpv4StringToAddressW
  703. #define RtlIpv6StringToAddress RtlIpv6StringToAddressW
  704. #define RtlIpv6StringToAddressEx RtlIpv6StringToAddressExW
  705. #define RtlIpv4AddressToStringEx RtlIpv4AddressToStringExW
  706. #define RtlIpv6AddressToStringEx RtlIpv6AddressToStringExW
  707. #define RtlIpv4StringToAddressEx RtlIpv4StringToAddressExW
  708. #else
  709. #define RtlIpv4AddressToString RtlIpv4AddressToStringA
  710. #define RtlIpv6AddressToString RtlIpv6AddressToStringA
  711. #define RtlIpv4StringToAddress RtlIpv4StringToAddressA
  712. #define RtlIpv6StringToAddress RtlIpv6StringToAddressA
  713. #define RtlIpv6StringToAddressEx RtlIpv6StringToAddressExA
  714. #define RtlIpv4AddressToStringEx RtlIpv4AddressToStringExA
  715. #define RtlIpv6AddressToStringEx RtlIpv6AddressToStringExA
  716. #define RtlIpv4StringToAddressEx RtlIpv4StringToAddressExA
  717. #endif // UNICODE
  718. //
  719. // Structures used by the kernel drivers to describe which ports must be
  720. // hooked out directly from the V86 emulator to the driver.
  721. //
  722. typedef enum _EMULATOR_PORT_ACCESS_TYPE {
  723. Uchar,
  724. Ushort,
  725. Ulong
  726. } EMULATOR_PORT_ACCESS_TYPE, *PEMULATOR_PORT_ACCESS_TYPE;
  727. //
  728. // Access Modes
  729. //
  730. #define EMULATOR_READ_ACCESS 0x01
  731. #define EMULATOR_WRITE_ACCESS 0x02
  732. typedef struct _EMULATOR_ACCESS_ENTRY {
  733. ULONG BasePort;
  734. ULONG NumConsecutivePorts;
  735. EMULATOR_PORT_ACCESS_TYPE AccessType;
  736. UCHAR AccessMode;
  737. UCHAR StringSupport;
  738. PVOID Routine;
  739. } EMULATOR_ACCESS_ENTRY, *PEMULATOR_ACCESS_ENTRY;
  740. // end_ntminiport
  741. //
  742. // These are the various function prototypes of the routines that are
  743. // provided by the kernel driver to hook out access to io ports.
  744. //
  745. typedef
  746. NTSTATUS
  747. (*PDRIVER_IO_PORT_UCHAR ) (
  748. IN ULONG_PTR Context,
  749. IN ULONG Port,
  750. IN UCHAR AccessMode,
  751. IN OUT PUCHAR Data
  752. );
  753. typedef
  754. NTSTATUS
  755. (*PDRIVER_IO_PORT_UCHAR_STRING ) (
  756. IN ULONG_PTR Context,
  757. IN ULONG Port,
  758. IN UCHAR AccessMode,
  759. IN OUT PUCHAR Data,
  760. IN ULONG DataLength
  761. );
  762. typedef
  763. NTSTATUS
  764. (*PDRIVER_IO_PORT_USHORT ) (
  765. IN ULONG_PTR Context,
  766. IN ULONG Port,
  767. IN UCHAR AccessMode,
  768. IN OUT PUSHORT Data
  769. );
  770. typedef
  771. NTSTATUS
  772. (*PDRIVER_IO_PORT_USHORT_STRING ) (
  773. IN ULONG_PTR Context,
  774. IN ULONG Port,
  775. IN UCHAR AccessMode,
  776. IN OUT PUSHORT Data,
  777. IN ULONG DataLength // number of words
  778. );
  779. typedef
  780. NTSTATUS
  781. (*PDRIVER_IO_PORT_ULONG ) (
  782. IN ULONG_PTR Context,
  783. IN ULONG Port,
  784. IN UCHAR AccessMode,
  785. IN OUT PULONG Data
  786. );
  787. typedef
  788. NTSTATUS
  789. (*PDRIVER_IO_PORT_ULONG_STRING ) (
  790. IN ULONG_PTR Context,
  791. IN ULONG Port,
  792. IN UCHAR AccessMode,
  793. IN OUT PULONG Data,
  794. IN ULONG DataLength // number of dwords
  795. );
  796. #if defined(_X86_)
  797. //
  798. // Types to use to contain PFNs and their counts.
  799. //
  800. typedef ULONG PFN_COUNT;
  801. typedef LONG SPFN_NUMBER, *PSPFN_NUMBER;
  802. typedef ULONG PFN_NUMBER, *PPFN_NUMBER;
  803. //
  804. // Define maximum size of flush multiple TB request.
  805. //
  806. #define FLUSH_MULTIPLE_MAXIMUM 32
  807. //
  808. // Indicate that the i386 compiler supports the pragma textout construct.
  809. //
  810. #define ALLOC_PRAGMA 1
  811. //
  812. // Indicate that the i386 compiler supports the DATA_SEG("INIT") and
  813. // DATA_SEG("PAGE") pragmas
  814. //
  815. #define ALLOC_DATA_PRAGMA 1
  816. //
  817. // Interrupt Request Level definitions
  818. //
  819. #define PASSIVE_LEVEL 0 // Passive release level
  820. #define LOW_LEVEL 0 // Lowest interrupt level
  821. #define APC_LEVEL 1 // APC interrupt level
  822. #define DISPATCH_LEVEL 2 // Dispatcher level
  823. #define PROFILE_LEVEL 27 // timer used for profiling.
  824. #define CLOCK1_LEVEL 28 // Interval clock 1 level - Not used on x86
  825. #define CLOCK2_LEVEL 28 // Interval clock 2 level
  826. #define IPI_LEVEL 29 // Interprocessor interrupt level
  827. #define POWER_LEVEL 30 // Power failure level
  828. #define HIGH_LEVEL 31 // Highest interrupt level
  829. #define SYNCH_LEVEL (IPI_LEVEL-2)
  830. #define MODE_MASK 1
  831. //
  832. // I/O space read and write macros.
  833. //
  834. // These have to be actual functions on the 386, because we need
  835. // to use assembler, but cannot return a value if we inline it.
  836. //
  837. // The READ/WRITE_REGISTER_* calls manipulate I/O registers in MEMORY space.
  838. // (Use x86 move instructions, with LOCK prefix to force correct behavior
  839. // w.r.t. caches and write buffers.)
  840. //
  841. // The READ/WRITE_PORT_* calls manipulate I/O registers in PORT space.
  842. // (Use x86 in/out instructions.)
  843. //
  844. NTKERNELAPI
  845. UCHAR
  846. NTAPI
  847. READ_REGISTER_UCHAR(
  848. PUCHAR Register
  849. );
  850. NTKERNELAPI
  851. USHORT
  852. NTAPI
  853. READ_REGISTER_USHORT(
  854. PUSHORT Register
  855. );
  856. NTKERNELAPI
  857. ULONG
  858. NTAPI
  859. READ_REGISTER_ULONG(
  860. PULONG Register
  861. );
  862. NTKERNELAPI
  863. VOID
  864. NTAPI
  865. READ_REGISTER_BUFFER_UCHAR(
  866. PUCHAR Register,
  867. PUCHAR Buffer,
  868. ULONG Count
  869. );
  870. NTKERNELAPI
  871. VOID
  872. NTAPI
  873. READ_REGISTER_BUFFER_USHORT(
  874. PUSHORT Register,
  875. PUSHORT Buffer,
  876. ULONG Count
  877. );
  878. NTKERNELAPI
  879. VOID
  880. NTAPI
  881. READ_REGISTER_BUFFER_ULONG(
  882. PULONG Register,
  883. PULONG Buffer,
  884. ULONG Count
  885. );
  886. NTKERNELAPI
  887. VOID
  888. NTAPI
  889. WRITE_REGISTER_UCHAR(
  890. PUCHAR Register,
  891. UCHAR Value
  892. );
  893. NTKERNELAPI
  894. VOID
  895. NTAPI
  896. WRITE_REGISTER_USHORT(
  897. PUSHORT Register,
  898. USHORT Value
  899. );
  900. NTKERNELAPI
  901. VOID
  902. NTAPI
  903. WRITE_REGISTER_ULONG(
  904. PULONG Register,
  905. ULONG Value
  906. );
  907. NTKERNELAPI
  908. VOID
  909. NTAPI
  910. WRITE_REGISTER_BUFFER_UCHAR(
  911. PUCHAR Register,
  912. PUCHAR Buffer,
  913. ULONG Count
  914. );
  915. NTKERNELAPI
  916. VOID
  917. NTAPI
  918. WRITE_REGISTER_BUFFER_USHORT(
  919. PUSHORT Register,
  920. PUSHORT Buffer,
  921. ULONG Count
  922. );
  923. NTKERNELAPI
  924. VOID
  925. NTAPI
  926. WRITE_REGISTER_BUFFER_ULONG(
  927. PULONG Register,
  928. PULONG Buffer,
  929. ULONG Count
  930. );
  931. NTHALAPI
  932. UCHAR
  933. NTAPI
  934. READ_PORT_UCHAR(
  935. PUCHAR Port
  936. );
  937. NTHALAPI
  938. USHORT
  939. NTAPI
  940. READ_PORT_USHORT(
  941. PUSHORT Port
  942. );
  943. NTHALAPI
  944. ULONG
  945. NTAPI
  946. READ_PORT_ULONG(
  947. PULONG Port
  948. );
  949. NTHALAPI
  950. VOID
  951. NTAPI
  952. READ_PORT_BUFFER_UCHAR(
  953. PUCHAR Port,
  954. PUCHAR Buffer,
  955. ULONG Count
  956. );
  957. NTHALAPI
  958. VOID
  959. NTAPI
  960. READ_PORT_BUFFER_USHORT(
  961. PUSHORT Port,
  962. PUSHORT Buffer,
  963. ULONG Count
  964. );
  965. NTHALAPI
  966. VOID
  967. NTAPI
  968. READ_PORT_BUFFER_ULONG(
  969. PULONG Port,
  970. PULONG Buffer,
  971. ULONG Count
  972. );
  973. NTHALAPI
  974. VOID
  975. NTAPI
  976. WRITE_PORT_UCHAR(
  977. PUCHAR Port,
  978. UCHAR Value
  979. );
  980. NTHALAPI
  981. VOID
  982. NTAPI
  983. WRITE_PORT_USHORT(
  984. PUSHORT Port,
  985. USHORT Value
  986. );
  987. NTHALAPI
  988. VOID
  989. NTAPI
  990. WRITE_PORT_ULONG(
  991. PULONG Port,
  992. ULONG Value
  993. );
  994. NTHALAPI
  995. VOID
  996. NTAPI
  997. WRITE_PORT_BUFFER_UCHAR(
  998. PUCHAR Port,
  999. PUCHAR Buffer,
  1000. ULONG Count
  1001. );
  1002. NTHALAPI
  1003. VOID
  1004. NTAPI
  1005. WRITE_PORT_BUFFER_USHORT(
  1006. PUSHORT Port,
  1007. PUSHORT Buffer,
  1008. ULONG Count
  1009. );
  1010. NTHALAPI
  1011. VOID
  1012. NTAPI
  1013. WRITE_PORT_BUFFER_ULONG(
  1014. PULONG Port,
  1015. PULONG Buffer,
  1016. ULONG Count
  1017. );
  1018. // end_ntndis
  1019. //
  1020. // Get data cache fill size.
  1021. //
  1022. #if PRAGMA_DEPRECATED_DDK
  1023. #pragma deprecated(KeGetDcacheFillSize) // Use GetDmaAlignment
  1024. #endif
  1025. #define KeGetDcacheFillSize() 1L
  1026. #define KeFlushIoBuffers(Mdl, ReadOperation, DmaOperation)
  1027. #define ExAcquireSpinLock(Lock, OldIrql) KeAcquireSpinLock((Lock), (OldIrql))
  1028. #define ExReleaseSpinLock(Lock, OldIrql) KeReleaseSpinLock((Lock), (OldIrql))
  1029. #define ExAcquireSpinLockAtDpcLevel(Lock) KeAcquireSpinLockAtDpcLevel(Lock)
  1030. #define ExReleaseSpinLockFromDpcLevel(Lock) KeReleaseSpinLockFromDpcLevel(Lock)
  1031. #if defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_)
  1032. // begin_wdm
  1033. #define KeQueryTickCount(CurrentCount ) { \
  1034. volatile PKSYSTEM_TIME _TickCount = *((PKSYSTEM_TIME *)(&KeTickCount)); \
  1035. while (TRUE) { \
  1036. (CurrentCount)->HighPart = _TickCount->High1Time; \
  1037. (CurrentCount)->LowPart = _TickCount->LowPart; \
  1038. if ((CurrentCount)->HighPart == _TickCount->High2Time) break; \
  1039. _asm { rep nop } \
  1040. } \
  1041. }
  1042. // end_wdm
  1043. #else
  1044. VOID
  1045. NTAPI
  1046. KeQueryTickCount (
  1047. OUT PLARGE_INTEGER CurrentCount
  1048. );
  1049. #endif // defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_)
  1050. //
  1051. // 386 hardware structures
  1052. //
  1053. //
  1054. // A Page Table Entry on an Intel 386/486 has the following definition.
  1055. //
  1056. // **** NOTE A PRIVATE COPY OF THIS EXISTS IN THE MM\I386 DIRECTORY! ****
  1057. // **** ANY CHANGES NEED TO BE MADE TO BOTH HEADER FILES. ****
  1058. //
  1059. typedef struct _HARDWARE_PTE_X86 {
  1060. ULONG Valid : 1;
  1061. ULONG Write : 1;
  1062. ULONG Owner : 1;
  1063. ULONG WriteThrough : 1;
  1064. ULONG CacheDisable : 1;
  1065. ULONG Accessed : 1;
  1066. ULONG Dirty : 1;
  1067. ULONG LargePage : 1;
  1068. ULONG Global : 1;
  1069. ULONG CopyOnWrite : 1; // software field
  1070. ULONG Prototype : 1; // software field
  1071. ULONG reserved : 1; // software field
  1072. ULONG PageFrameNumber : 20;
  1073. } HARDWARE_PTE_X86, *PHARDWARE_PTE_X86;
  1074. typedef struct _HARDWARE_PTE_X86PAE {
  1075. union {
  1076. struct {
  1077. ULONGLONG Valid : 1;
  1078. ULONGLONG Write : 1;
  1079. ULONGLONG Owner : 1;
  1080. ULONGLONG WriteThrough : 1;
  1081. ULONGLONG CacheDisable : 1;
  1082. ULONGLONG Accessed : 1;
  1083. ULONGLONG Dirty : 1;
  1084. ULONGLONG LargePage : 1;
  1085. ULONGLONG Global : 1;
  1086. ULONGLONG CopyOnWrite : 1; // software field
  1087. ULONGLONG Prototype : 1; // software field
  1088. ULONGLONG reserved0 : 1; // software field
  1089. ULONGLONG PageFrameNumber : 26;
  1090. ULONGLONG reserved1 : 26; // software field
  1091. };
  1092. struct {
  1093. ULONG LowPart;
  1094. ULONG HighPart;
  1095. };
  1096. };
  1097. } HARDWARE_PTE_X86PAE, *PHARDWARE_PTE_X86PAE;
  1098. //
  1099. // Special check to work around mspdb limitation
  1100. //
  1101. #if defined (_NTSYM_HARDWARE_PTE_SYMBOL_)
  1102. #if !defined (_X86PAE_)
  1103. typedef struct _HARDWARE_PTE {
  1104. ULONG Valid : 1;
  1105. ULONG Write : 1;
  1106. ULONG Owner : 1;
  1107. ULONG WriteThrough : 1;
  1108. ULONG CacheDisable : 1;
  1109. ULONG Accessed : 1;
  1110. ULONG Dirty : 1;
  1111. ULONG LargePage : 1;
  1112. ULONG Global : 1;
  1113. ULONG CopyOnWrite : 1; // software field
  1114. ULONG Prototype : 1; // software field
  1115. ULONG reserved : 1; // software field
  1116. ULONG PageFrameNumber : 20;
  1117. } HARDWARE_PTE, *PHARDWARE_PTE;
  1118. #else
  1119. typedef struct _HARDWARE_PTE {
  1120. union {
  1121. struct {
  1122. ULONGLONG Valid : 1;
  1123. ULONGLONG Write : 1;
  1124. ULONGLONG Owner : 1;
  1125. ULONGLONG WriteThrough : 1;
  1126. ULONGLONG CacheDisable : 1;
  1127. ULONGLONG Accessed : 1;
  1128. ULONGLONG Dirty : 1;
  1129. ULONGLONG LargePage : 1;
  1130. ULONGLONG Global : 1;
  1131. ULONGLONG CopyOnWrite : 1; // software field
  1132. ULONGLONG Prototype : 1; // software field
  1133. ULONGLONG reserved0 : 1; // software field
  1134. ULONGLONG PageFrameNumber : 26;
  1135. ULONGLONG reserved1 : 26; // software field
  1136. };
  1137. struct {
  1138. ULONG LowPart;
  1139. ULONG HighPart;
  1140. };
  1141. };
  1142. } HARDWARE_PTE, *PHARDWARE_PTE;
  1143. #endif
  1144. #else
  1145. #if !defined (_X86PAE_)
  1146. typedef HARDWARE_PTE_X86 HARDWARE_PTE;
  1147. typedef PHARDWARE_PTE_X86 PHARDWARE_PTE;
  1148. #else
  1149. typedef HARDWARE_PTE_X86PAE HARDWARE_PTE;
  1150. typedef PHARDWARE_PTE_X86PAE PHARDWARE_PTE;
  1151. #endif
  1152. #endif
  1153. //
  1154. // GDT Entry
  1155. //
  1156. typedef struct _KGDTENTRY {
  1157. USHORT LimitLow;
  1158. USHORT BaseLow;
  1159. union {
  1160. struct {
  1161. UCHAR BaseMid;
  1162. UCHAR Flags1; // Declare as bytes to avoid alignment
  1163. UCHAR Flags2; // Problems.
  1164. UCHAR BaseHi;
  1165. } Bytes;
  1166. struct {
  1167. ULONG BaseMid : 8;
  1168. ULONG Type : 5;
  1169. ULONG Dpl : 2;
  1170. ULONG Pres : 1;
  1171. ULONG LimitHi : 4;
  1172. ULONG Sys : 1;
  1173. ULONG Reserved_0 : 1;
  1174. ULONG Default_Big : 1;
  1175. ULONG Granularity : 1;
  1176. ULONG BaseHi : 8;
  1177. } Bits;
  1178. } HighWord;
  1179. } KGDTENTRY, *PKGDTENTRY;
  1180. #define TYPE_CODE 0x10 // 11010 = Code, Readable, NOT Conforming, Accessed
  1181. #define TYPE_DATA 0x12 // 10010 = Data, ReadWrite, NOT Expanddown, Accessed
  1182. #define TYPE_TSS 0x01 // 01001 = NonBusy TSS
  1183. #define TYPE_LDT 0x02 // 00010 = LDT
  1184. #define DPL_USER 3
  1185. #define DPL_SYSTEM 0
  1186. #define GRAN_BYTE 0
  1187. #define GRAN_PAGE 1
  1188. #define SELECTOR_TABLE_INDEX 0x04
  1189. #define IDT_NMI_VECTOR 2
  1190. #define IDT_DFH_VECTOR 8
  1191. #define NMI_TSS_DESC_OFFSET 0x58
  1192. #define DF_TSS_DESC_OFFSET 0x50
  1193. //
  1194. // Entry of Interrupt Descriptor Table (IDTENTRY)
  1195. //
  1196. typedef struct _KIDTENTRY {
  1197. USHORT Offset;
  1198. USHORT Selector;
  1199. USHORT Access;
  1200. USHORT ExtendedOffset;
  1201. } KIDTENTRY;
  1202. typedef KIDTENTRY *PKIDTENTRY;
  1203. //
  1204. // TSS (Task switch segment) NT only uses to control stack switches.
  1205. //
  1206. // The only fields we actually care about are Esp0, Ss0, the IoMapBase
  1207. // and the IoAccessMaps themselves.
  1208. //
  1209. //
  1210. // N.B. Size of TSS must be <= 0xDFFF
  1211. //
  1212. //
  1213. // The interrupt direction bitmap is used on Pentium to allow
  1214. // the processor to emulate V86 mode software interrupts for us.
  1215. // There is one for each IOPM. It is located by subtracting
  1216. // 32 from the IOPM base in the Tss.
  1217. //
  1218. #define INT_DIRECTION_MAP_SIZE 32
  1219. typedef UCHAR KINT_DIRECTION_MAP[INT_DIRECTION_MAP_SIZE];
  1220. #define IOPM_COUNT 1 // Number of i/o access maps that
  1221. // exist (in addition to
  1222. // IO_ACCESS_MAP_NONE)
  1223. #define IO_ACCESS_MAP_NONE 0
  1224. #define IOPM_SIZE 8192 // Size of map callers can set.
  1225. #define PIOPM_SIZE 8196 // Size of structure we must allocate
  1226. // to hold it.
  1227. typedef UCHAR KIO_ACCESS_MAP[IOPM_SIZE];
  1228. typedef KIO_ACCESS_MAP *PKIO_ACCESS_MAP;
  1229. typedef struct _KiIoAccessMap {
  1230. KINT_DIRECTION_MAP DirectionMap;
  1231. UCHAR IoMap[PIOPM_SIZE];
  1232. } KIIO_ACCESS_MAP;
  1233. typedef struct _KTSS {
  1234. USHORT Backlink;
  1235. USHORT Reserved0;
  1236. ULONG Esp0;
  1237. USHORT Ss0;
  1238. USHORT Reserved1;
  1239. ULONG NotUsed1[4];
  1240. ULONG CR3;
  1241. ULONG Eip;
  1242. ULONG EFlags;
  1243. ULONG Eax;
  1244. ULONG Ecx;
  1245. ULONG Edx;
  1246. ULONG Ebx;
  1247. ULONG Esp;
  1248. ULONG Ebp;
  1249. ULONG Esi;
  1250. ULONG Edi;
  1251. USHORT Es;
  1252. USHORT Reserved2;
  1253. USHORT Cs;
  1254. USHORT Reserved3;
  1255. USHORT Ss;
  1256. USHORT Reserved4;
  1257. USHORT Ds;
  1258. USHORT Reserved5;
  1259. USHORT Fs;
  1260. USHORT Reserved6;
  1261. USHORT Gs;
  1262. USHORT Reserved7;
  1263. USHORT LDT;
  1264. USHORT Reserved8;
  1265. USHORT Flags;
  1266. USHORT IoMapBase;
  1267. KIIO_ACCESS_MAP IoMaps[IOPM_COUNT];
  1268. //
  1269. // This is the Software interrupt direction bitmap associated with
  1270. // IO_ACCESS_MAP_NONE
  1271. //
  1272. KINT_DIRECTION_MAP IntDirectionMap;
  1273. } KTSS, *PKTSS;
  1274. #define KiComputeIopmOffset(MapNumber) \
  1275. (MapNumber == IO_ACCESS_MAP_NONE) ? \
  1276. (USHORT)(sizeof(KTSS)) : \
  1277. (USHORT)(FIELD_OFFSET(KTSS, IoMaps[MapNumber-1].IoMap))
  1278. // begin_windbgkd
  1279. //
  1280. // Special Registers for i386
  1281. //
  1282. #ifdef _X86_
  1283. typedef struct _DESCRIPTOR {
  1284. USHORT Pad;
  1285. USHORT Limit;
  1286. ULONG Base;
  1287. } KDESCRIPTOR, *PKDESCRIPTOR;
  1288. typedef struct _KSPECIAL_REGISTERS {
  1289. ULONG Cr0;
  1290. ULONG Cr2;
  1291. ULONG Cr3;
  1292. ULONG Cr4;
  1293. ULONG KernelDr0;
  1294. ULONG KernelDr1;
  1295. ULONG KernelDr2;
  1296. ULONG KernelDr3;
  1297. ULONG KernelDr6;
  1298. ULONG KernelDr7;
  1299. KDESCRIPTOR Gdtr;
  1300. KDESCRIPTOR Idtr;
  1301. USHORT Tr;
  1302. USHORT Ldtr;
  1303. ULONG Reserved[6];
  1304. } KSPECIAL_REGISTERS, *PKSPECIAL_REGISTERS;
  1305. //
  1306. // Processor State frame: Before a processor freezes itself, it
  1307. // dumps the processor state to the processor state frame for
  1308. // debugger to examine.
  1309. //
  1310. typedef struct _KPROCESSOR_STATE {
  1311. struct _CONTEXT ContextFrame;
  1312. struct _KSPECIAL_REGISTERS SpecialRegisters;
  1313. } KPROCESSOR_STATE, *PKPROCESSOR_STATE;
  1314. #endif // _X86_
  1315. // end_windbgkd
  1316. //
  1317. // DPC data structure definition.
  1318. //
  1319. typedef struct _KDPC_DATA {
  1320. LIST_ENTRY DpcListHead;
  1321. KSPIN_LOCK DpcLock;
  1322. volatile ULONG DpcQueueDepth;
  1323. ULONG DpcCount;
  1324. } KDPC_DATA, *PKDPC_DATA;
  1325. //
  1326. // Processor Control Block (PRCB)
  1327. //
  1328. #define PRCB_MAJOR_VERSION 1
  1329. #define PRCB_MINOR_VERSION 1
  1330. #define PRCB_BUILD_DEBUG 0x0001
  1331. #define PRCB_BUILD_UNIPROCESSOR 0x0002
  1332. typedef struct _KPRCB {
  1333. //
  1334. // Start of the architecturally defined section of the PRCB. This section
  1335. // may be directly addressed by vendor/platform specific HAL code and will
  1336. // not change from version to version of NT.
  1337. //
  1338. USHORT MinorVersion;
  1339. USHORT MajorVersion;
  1340. struct _KTHREAD *CurrentThread;
  1341. struct _KTHREAD *NextThread;
  1342. struct _KTHREAD *IdleThread;
  1343. CCHAR Number;
  1344. CCHAR Reserved;
  1345. USHORT BuildType;
  1346. KAFFINITY SetMember;
  1347. CCHAR CpuType;
  1348. CCHAR CpuID;
  1349. USHORT CpuStep;
  1350. struct _KPROCESSOR_STATE ProcessorState;
  1351. ULONG KernelReserved[16]; // For use by the kernel
  1352. ULONG HalReserved[16]; // For use by Hal
  1353. //
  1354. // Per processor lock queue entries.
  1355. //
  1356. // N.B. The following padding is such that the first lock entry falls in the
  1357. // last eight bytes of a cache line. This makes the dispatcher lock and
  1358. // the context swap lock lie in separate cache lines.
  1359. //
  1360. UCHAR PrcbPad0[28 + 64];
  1361. KSPIN_LOCK_QUEUE LockQueue[16];
  1362. UCHAR PrcbPad1[8];
  1363. // End of the architecturally defined section of the PRCB.
  1364. } KPRCB, *PKPRCB, *RESTRICTED_POINTER PRKPRCB;
  1365. //
  1366. // Processor Control Region Structure Definition
  1367. //
  1368. #define PCR_MINOR_VERSION 1
  1369. #define PCR_MAJOR_VERSION 1
  1370. typedef struct _KPCR {
  1371. //
  1372. // Start of the architecturally defined section of the PCR. This section
  1373. // may be directly addressed by vendor/platform specific HAL code and will
  1374. // not change from version to version of NT.
  1375. //
  1376. // Certain fields in the TIB are not used in kernel mode. These include the
  1377. // stack limit, subsystem TIB, fiber data, arbitrary user pointer, and the
  1378. // self address of then PCR itself (another field has been added for that
  1379. // purpose). Therefore, these fields are overlaid with other data to get
  1380. // better cache locality.
  1381. //
  1382. union {
  1383. NT_TIB NtTib;
  1384. struct {
  1385. struct _EXCEPTION_REGISTRATION_RECORD *Used_ExceptionList;
  1386. PVOID Used_StackBase;
  1387. PVOID PerfGlobalGroupMask;
  1388. PVOID TssCopy;
  1389. ULONG ContextSwitches;
  1390. KAFFINITY SetMemberCopy;
  1391. PVOID Used_Self;
  1392. };
  1393. };
  1394. struct _KPCR *SelfPcr; // flat address of this PCR
  1395. struct _KPRCB *Prcb; // pointer to Prcb
  1396. KIRQL Irql; // do not use 3 bytes after this as
  1397. // HALs assume they are zero.
  1398. ULONG IRR;
  1399. ULONG IrrActive;
  1400. ULONG IDR;
  1401. PVOID KdVersionBlock;
  1402. struct _KIDTENTRY *IDT;
  1403. struct _KGDTENTRY *GDT;
  1404. struct _KTSS *TSS;
  1405. USHORT MajorVersion;
  1406. USHORT MinorVersion;
  1407. KAFFINITY SetMember;
  1408. ULONG StallScaleFactor;
  1409. UCHAR SpareUnused;
  1410. UCHAR Number;
  1411. } KPCR, *PKPCR;
  1412. //
  1413. // bits defined in Eflags
  1414. //
  1415. #define EFLAGS_CF_MASK 0x00000001L
  1416. #define EFLAGS_PF_MASK 0x00000004L
  1417. #define EFLAGS_AF_MASK 0x00000010L
  1418. #define EFLAGS_ZF_MASK 0x00000040L
  1419. #define EFLAGS_SF_MASK 0x00000080L
  1420. #define EFLAGS_TF 0x00000100L
  1421. #define EFLAGS_INTERRUPT_MASK 0x00000200L
  1422. #define EFLAGS_DF_MASK 0x00000400L
  1423. #define EFLAGS_OF_MASK 0x00000800L
  1424. #define EFLAGS_IOPL_MASK 0x00003000L
  1425. #define EFLAGS_NT 0x00004000L
  1426. #define EFLAGS_RF 0x00010000L
  1427. #define EFLAGS_V86_MASK 0x00020000L
  1428. #define EFLAGS_ALIGN_CHECK 0x00040000L
  1429. #define EFLAGS_VIF 0x00080000L
  1430. #define EFLAGS_VIP 0x00100000L
  1431. #define EFLAGS_ID_MASK 0x00200000L
  1432. #define EFLAGS_USER_SANITIZE 0x003f4dd7L
  1433. // end_nthal
  1434. //
  1435. // Sanitize segCS and eFlags based on a processor mode.
  1436. //
  1437. // If kernel mode,
  1438. // force CPL == 0
  1439. //
  1440. // If user mode,
  1441. // force CPL == 3
  1442. //
  1443. #define SANITIZE_SEG(segCS, mode) (\
  1444. ((mode) == KernelMode ? \
  1445. ((0x00000000L) | ((segCS) & 0xfffc)) : \
  1446. ((0x00000003L) | ((segCS) & 0xffff))))
  1447. //
  1448. // If kernel mode, then
  1449. // let caller specify Carry, Parity, AuxCarry, Zero, Sign, Trap,
  1450. // Direction, Overflow, Interrupt, AlignCheck.
  1451. //
  1452. // If user mode, then
  1453. // let caller specify Carry, Parity, AuxCarry, Zero, Sign, Trap,
  1454. // Direction, Overflow, AlignCheck.
  1455. // force Interrupts on.
  1456. //
  1457. #define SANITIZE_FLAGS(eFlags, mode) (\
  1458. ((mode) == KernelMode ? \
  1459. ((0x00000000L) | ((eFlags) & 0x003f0fd7)) : \
  1460. ((EFLAGS_INTERRUPT_MASK) | ((eFlags) & EFLAGS_USER_SANITIZE))))
  1461. //
  1462. // Masks for Dr7 and sanitize macros for various Dr registers.
  1463. //
  1464. #define DR6_LEGAL 0x0000e00f
  1465. #define DR7_LEGAL 0xffff0155 // R/W, LEN for Dr0-Dr4,
  1466. // Local enable for Dr0-Dr4,
  1467. // Le for "perfect" trapping
  1468. #define DR7_ACTIVE 0x00000055 // If any of these bits are set, a Dr is active
  1469. #define SANITIZE_DR6(Dr6, mode) ((Dr6 & DR6_LEGAL));
  1470. #define SANITIZE_DR7(Dr7, mode) ((Dr7 & DR7_LEGAL));
  1471. #define SANITIZE_DRADDR(DrReg, mode) ( \
  1472. (mode) == KernelMode ? \
  1473. (DrReg) : \
  1474. (((PVOID)DrReg <= MM_HIGHEST_USER_ADDRESS) ? \
  1475. (DrReg) : \
  1476. (0) \
  1477. ) \
  1478. )
  1479. //
  1480. // Define macro to clear reserved bits from MXCSR so that we don't
  1481. // GP fault when doing an FRSTOR
  1482. //
  1483. extern ULONG KiMXCsrMask;
  1484. #define SANITIZE_MXCSR(_mxcsr_) ((_mxcsr_) & KiMXCsrMask)
  1485. //
  1486. // Nonvolatile context pointers
  1487. //
  1488. // bryanwi 21 feb 90 - This is bogus. The 386 doesn't have
  1489. // enough nonvolatile context to make this
  1490. // structure worthwhile. Can't declare a
  1491. // field to be void, so declare a Junk structure
  1492. // instead.
  1493. typedef struct _KNONVOLATILE_CONTEXT_POINTERS {
  1494. ULONG Junk;
  1495. } KNONVOLATILE_CONTEXT_POINTERS, *PKNONVOLATILE_CONTEXT_POINTERS;
  1496. // begin_nthal
  1497. //
  1498. // Trap frame
  1499. //
  1500. // NOTE - We deal only with 32bit registers, so the assembler equivalents
  1501. // are always the extended forms.
  1502. //
  1503. // NOTE - Unless you want to run like slow molasses everywhere in the
  1504. // the system, this structure must be of DWORD length, DWORD
  1505. // aligned, and its elements must all be DWORD aligned.
  1506. //
  1507. // NOTE WELL -
  1508. //
  1509. // The i386 does not build stack frames in a consistent format, the
  1510. // frames vary depending on whether or not a privilege transition
  1511. // was involved.
  1512. //
  1513. // In order to make NtContinue work for both user mode and kernel
  1514. // mode callers, we must force a canonical stack.
  1515. //
  1516. // If we're called from kernel mode, this structure is 8 bytes longer
  1517. // than the actual frame!
  1518. //
  1519. // WARNING:
  1520. //
  1521. // KTRAP_FRAME_LENGTH needs to be 16byte integral (at present.)
  1522. //
  1523. typedef struct _KTRAP_FRAME {
  1524. //
  1525. // Following 4 values are only used and defined for DBG systems,
  1526. // but are always allocated to make switching from DBG to non-DBG
  1527. // and back quicker. They are not DEVL because they have a non-0
  1528. // performance impact.
  1529. //
  1530. ULONG DbgEbp; // Copy of User EBP set up so KB will work.
  1531. ULONG DbgEip; // EIP of caller to system call, again, for KB.
  1532. ULONG DbgArgMark; // Marker to show no args here.
  1533. ULONG DbgArgPointer; // Pointer to the actual args
  1534. //
  1535. // Temporary values used when frames are edited.
  1536. //
  1537. //
  1538. // NOTE: Any code that want's ESP must materialize it, since it
  1539. // is not stored in the frame for kernel mode callers.
  1540. //
  1541. // And code that sets ESP in a KERNEL mode frame, must put
  1542. // the new value in TempEsp, make sure that TempSegCs holds
  1543. // the real SegCs value, and put a special marker value into SegCs.
  1544. //
  1545. ULONG TempSegCs;
  1546. ULONG TempEsp;
  1547. //
  1548. // Debug registers.
  1549. //
  1550. ULONG Dr0;
  1551. ULONG Dr1;
  1552. ULONG Dr2;
  1553. ULONG Dr3;
  1554. ULONG Dr6;
  1555. ULONG Dr7;
  1556. //
  1557. // Segment registers
  1558. //
  1559. ULONG SegGs;
  1560. ULONG SegEs;
  1561. ULONG SegDs;
  1562. //
  1563. // Volatile registers
  1564. //
  1565. ULONG Edx;
  1566. ULONG Ecx;
  1567. ULONG Eax;
  1568. //
  1569. // Nesting state, not part of context record
  1570. //
  1571. ULONG PreviousPreviousMode;
  1572. PEXCEPTION_REGISTRATION_RECORD ExceptionList;
  1573. // Trash if caller was user mode.
  1574. // Saved exception list if caller
  1575. // was kernel mode or we're in
  1576. // an interrupt.
  1577. //
  1578. // FS is TIB/PCR pointer, is here to make save sequence easy
  1579. //
  1580. ULONG SegFs;
  1581. //
  1582. // Non-volatile registers
  1583. //
  1584. ULONG Edi;
  1585. ULONG Esi;
  1586. ULONG Ebx;
  1587. ULONG Ebp;
  1588. //
  1589. // Control registers
  1590. //
  1591. ULONG ErrCode;
  1592. ULONG Eip;
  1593. ULONG SegCs;
  1594. ULONG EFlags;
  1595. ULONG HardwareEsp; // WARNING - segSS:esp are only here for stacks
  1596. ULONG HardwareSegSs; // that involve a ring transition.
  1597. ULONG V86Es; // these will be present for all transitions from
  1598. ULONG V86Ds; // V86 mode
  1599. ULONG V86Fs;
  1600. ULONG V86Gs;
  1601. } KTRAP_FRAME;
  1602. typedef KTRAP_FRAME *PKTRAP_FRAME;
  1603. typedef KTRAP_FRAME *PKEXCEPTION_FRAME;
  1604. #define KTRAP_FRAME_LENGTH (sizeof(KTRAP_FRAME))
  1605. #define KTRAP_FRAME_ALIGN (sizeof(ULONG))
  1606. #define KTRAP_FRAME_ROUND (KTRAP_FRAME_ALIGN-1)
  1607. //
  1608. // Bits forced to 0 in SegCs if Esp has been edited.
  1609. //
  1610. #define FRAME_EDITED 0xfff8
  1611. // end_nthal
  1612. //
  1613. // The frame saved by KiCallUserMode is defined here to allow
  1614. // the kernel debugger to trace the entire kernel stack
  1615. // when usermode callouts are pending.
  1616. //
  1617. typedef struct _KCALLOUT_FRAME {
  1618. ULONG InStk; // saved initial stack address
  1619. ULONG TrFr; // saved callback trap frame
  1620. ULONG CbStk; // saved callback stack address
  1621. ULONG Edi; // saved nonvolatile registers
  1622. ULONG Esi; //
  1623. ULONG Ebx; //
  1624. ULONG Ebp; //
  1625. ULONG Ret; // saved return address
  1626. ULONG OutBf; // address to store output buffer
  1627. ULONG OutLn; // address to store output length
  1628. } KCALLOUT_FRAME;
  1629. typedef KCALLOUT_FRAME *PKCALLOUT_FRAME;
  1630. //
  1631. // Switch Frame
  1632. //
  1633. // 386 doesn't have an "exception frame", and doesn't normally make
  1634. // any use of nonvolatile context register structures.
  1635. //
  1636. // However, swapcontext in ctxswap.c and KeInitializeThread in
  1637. // thredini.c need to share common stack structure used at thread
  1638. // startup and switch time.
  1639. //
  1640. // This is that structure.
  1641. //
  1642. typedef struct _KSWITCHFRAME {
  1643. ULONG ExceptionList;
  1644. ULONG ApcBypassDisable;
  1645. ULONG RetAddr;
  1646. } KSWITCHFRAME, *PKSWITCHFRAME;
  1647. //
  1648. // Various 387 defines
  1649. //
  1650. #define I386_80387_NP_VECTOR 0x07 // trap 7 when hardware not present
  1651. // begin_ntddk begin_wdm
  1652. //
  1653. // The non-volatile 387 state
  1654. //
  1655. typedef struct _KFLOATING_SAVE {
  1656. ULONG ControlWord;
  1657. ULONG StatusWord;
  1658. ULONG ErrorOffset;
  1659. ULONG ErrorSelector;
  1660. ULONG DataOffset; // Not used in wdm
  1661. ULONG DataSelector;
  1662. ULONG Cr0NpxState;
  1663. ULONG Spare1; // Not used in wdm
  1664. } KFLOATING_SAVE, *PKFLOATING_SAVE;
  1665. //
  1666. // i386 Specific portions of mm component
  1667. //
  1668. //
  1669. // Define the page size for the Intel 386 as 4096 (0x1000).
  1670. //
  1671. #define PAGE_SIZE 0x1000
  1672. //
  1673. // Define the number of trailing zeroes in a page aligned virtual address.
  1674. // This is used as the shift count when shifting virtual addresses to
  1675. // virtual page numbers.
  1676. //
  1677. #define PAGE_SHIFT 12L
  1678. // end_ntndis end_wdm
  1679. //
  1680. // Define the number of bits to shift to right justify the Page Directory Index
  1681. // field of a PTE.
  1682. //
  1683. #define PDI_SHIFT_X86 22
  1684. #define PDI_SHIFT_X86PAE 21
  1685. #if !defined (_X86PAE_)
  1686. #define PDI_SHIFT PDI_SHIFT_X86
  1687. #else
  1688. #define PDI_SHIFT PDI_SHIFT_X86PAE
  1689. #define PPI_SHIFT 30
  1690. #endif
  1691. //
  1692. // Define the number of bits to shift to right justify the Page Table Index
  1693. // field of a PTE.
  1694. //
  1695. #define PTI_SHIFT 12
  1696. //
  1697. // Define the highest user address and user probe address.
  1698. //
  1699. extern PVOID *MmHighestUserAddress;
  1700. extern PVOID *MmSystemRangeStart;
  1701. extern ULONG *MmUserProbeAddress;
  1702. #define MM_HIGHEST_USER_ADDRESS *MmHighestUserAddress
  1703. #define MM_SYSTEM_RANGE_START *MmSystemRangeStart
  1704. #define MM_USER_PROBE_ADDRESS *MmUserProbeAddress
  1705. //
  1706. // The lowest user address reserves the low 64k.
  1707. //
  1708. #define MM_LOWEST_USER_ADDRESS (PVOID)0x10000
  1709. //
  1710. // The lowest address for system space.
  1711. //
  1712. #if !defined (_X86PAE_)
  1713. #define MM_LOWEST_SYSTEM_ADDRESS (PVOID)0xC0800000
  1714. #else
  1715. #define MM_LOWEST_SYSTEM_ADDRESS (PVOID)0xC0C00000
  1716. #endif
  1717. // begin_wdm
  1718. #define MmGetProcedureAddress(Address) (Address)
  1719. #define MmLockPagableCodeSection(Address) MmLockPagableDataSection(Address)
  1720. // end_ntddk end_wdm
  1721. //
  1722. // Define the number of bits to shift to right justify the Page Directory Index
  1723. // field of a PTE.
  1724. //
  1725. #define PDI_SHIFT_X86 22
  1726. #define PDI_SHIFT_X86PAE 21
  1727. #if !defined (_X86PAE_)
  1728. #define PDI_SHIFT PDI_SHIFT_X86
  1729. #else
  1730. #define PDI_SHIFT PDI_SHIFT_X86PAE
  1731. #define PPI_SHIFT 30
  1732. #endif
  1733. //
  1734. // Define the number of bits to shift to right justify the Page Table Index
  1735. // field of a PTE.
  1736. //
  1737. #define PTI_SHIFT 12
  1738. //
  1739. // Define page directory and page base addresses.
  1740. //
  1741. #define PDE_BASE_X86 0xc0300000
  1742. #define PDE_BASE_X86PAE 0xc0600000
  1743. #define PTE_TOP_X86 0xC03FFFFF
  1744. #define PDE_TOP_X86 0xC0300FFF
  1745. #define PTE_TOP_X86PAE 0xC07FFFFF
  1746. #define PDE_TOP_X86PAE 0xC0603FFF
  1747. #if !defined (_X86PAE_)
  1748. #define PDE_BASE PDE_BASE_X86
  1749. #define PTE_TOP PTE_TOP_X86
  1750. #define PDE_TOP PDE_TOP_X86
  1751. #else
  1752. #define PDE_BASE PDE_BASE_X86PAE
  1753. #define PTE_TOP PTE_TOP_X86PAE
  1754. #define PDE_TOP PDE_TOP_X86PAE
  1755. #endif
  1756. #define PTE_BASE 0xc0000000
  1757. #define KIP0PCRADDRESS 0xffdff000
  1758. #define KI_USER_SHARED_DATA 0xffdf0000
  1759. #define SharedUserData ((KUSER_SHARED_DATA * const) KI_USER_SHARED_DATA)
  1760. //
  1761. // Result type definition for i386. (Machine specific enumerate type
  1762. // which is return type for portable exinterlockedincrement/decrement
  1763. // procedures.) In general, you should use the enumerated type defined
  1764. // in ex.h instead of directly referencing these constants.
  1765. //
  1766. // Flags loaded into AH by LAHF instruction
  1767. #define EFLAG_SIGN 0x8000
  1768. #define EFLAG_ZERO 0x4000
  1769. #define EFLAG_SELECT (EFLAG_SIGN | EFLAG_ZERO)
  1770. #define RESULT_NEGATIVE ((EFLAG_SIGN & ~EFLAG_ZERO) & EFLAG_SELECT)
  1771. #define RESULT_ZERO ((~EFLAG_SIGN & EFLAG_ZERO) & EFLAG_SELECT)
  1772. #define RESULT_POSITIVE ((~EFLAG_SIGN & ~EFLAG_ZERO) & EFLAG_SELECT)
  1773. //
  1774. // Convert various portable ExInterlock APIs into their architectural
  1775. // equivalents.
  1776. //
  1777. #if PRAGMA_DEPRECATED_DDK
  1778. #pragma deprecated(ExInterlockedIncrementLong) // Use InterlockedIncrement
  1779. #pragma deprecated(ExInterlockedDecrementLong) // Use InterlockedDecrement
  1780. #pragma deprecated(ExInterlockedExchangeUlong) // Use InterlockedExchange
  1781. #endif
  1782. #define ExInterlockedIncrementLong(Addend,Lock) \
  1783. Exfi386InterlockedIncrementLong(Addend)
  1784. #define ExInterlockedDecrementLong(Addend,Lock) \
  1785. Exfi386InterlockedDecrementLong(Addend)
  1786. #define ExInterlockedExchangeUlong(Target,Value,Lock) \
  1787. Exfi386InterlockedExchangeUlong(Target,Value)
  1788. // begin_wdm
  1789. #define ExInterlockedAddUlong ExfInterlockedAddUlong
  1790. #define ExInterlockedInsertHeadList ExfInterlockedInsertHeadList
  1791. #define ExInterlockedInsertTailList ExfInterlockedInsertTailList
  1792. #define ExInterlockedRemoveHeadList ExfInterlockedRemoveHeadList
  1793. #define ExInterlockedPopEntryList ExfInterlockedPopEntryList
  1794. #define ExInterlockedPushEntryList ExfInterlockedPushEntryList
  1795. // end_wdm
  1796. //
  1797. // Prototypes for architectural specific versions of Exi386 Api
  1798. //
  1799. //
  1800. // Interlocked result type is portable, but its values are machine specific.
  1801. // Constants for value are in i386.h, mips.h, etc.
  1802. //
  1803. typedef enum _INTERLOCKED_RESULT {
  1804. ResultNegative = RESULT_NEGATIVE,
  1805. ResultZero = RESULT_ZERO,
  1806. ResultPositive = RESULT_POSITIVE
  1807. } INTERLOCKED_RESULT;
  1808. NTKERNELAPI
  1809. INTERLOCKED_RESULT
  1810. FASTCALL
  1811. Exfi386InterlockedIncrementLong (
  1812. IN PLONG Addend
  1813. );
  1814. NTKERNELAPI
  1815. INTERLOCKED_RESULT
  1816. FASTCALL
  1817. Exfi386InterlockedDecrementLong (
  1818. IN PLONG Addend
  1819. );
  1820. NTKERNELAPI
  1821. ULONG
  1822. FASTCALL
  1823. Exfi386InterlockedExchangeUlong (
  1824. IN PULONG Target,
  1825. IN ULONG Value
  1826. );
  1827. #if !defined(_WINBASE_) && !defined(NONTOSPINTERLOCK)
  1828. #if !defined(MIDL_PASS) // wdm
  1829. #if defined(NO_INTERLOCKED_INTRINSICS) || defined(_CROSS_PLATFORM_)
  1830. // begin_wdm
  1831. NTKERNELAPI
  1832. LONG
  1833. FASTCALL
  1834. InterlockedIncrement(
  1835. IN LONG volatile *Addend
  1836. );
  1837. NTKERNELAPI
  1838. LONG
  1839. FASTCALL
  1840. InterlockedDecrement(
  1841. IN LONG volatile *Addend
  1842. );
  1843. NTKERNELAPI
  1844. LONG
  1845. FASTCALL
  1846. InterlockedExchange(
  1847. IN OUT LONG volatile *Target,
  1848. IN LONG Value
  1849. );
  1850. #define InterlockedExchangePointer(Target, Value) \
  1851. (PVOID)InterlockedExchange((PLONG)(Target), (LONG)(Value))
  1852. LONG
  1853. FASTCALL
  1854. InterlockedExchangeAdd(
  1855. IN OUT LONG volatile *Addend,
  1856. IN LONG Increment
  1857. );
  1858. NTKERNELAPI
  1859. LONG
  1860. FASTCALL
  1861. InterlockedCompareExchange(
  1862. IN OUT LONG volatile *Destination,
  1863. IN LONG ExChange,
  1864. IN LONG Comperand
  1865. );
  1866. #define InterlockedCompareExchangePointer(Destination, ExChange, Comperand) \
  1867. (PVOID)InterlockedCompareExchange((PLONG)Destination, (LONG)ExChange, (LONG)Comperand)
  1868. #define InterlockedCompareExchange64(Destination, ExChange, Comperand) \
  1869. ExfInterlockedCompareExchange64(Destination, &(ExChange), &(Comperand))
  1870. NTKERNELAPI
  1871. LONGLONG
  1872. FASTCALL
  1873. ExfInterlockedCompareExchange64(
  1874. IN OUT LONGLONG volatile *Destination,
  1875. IN PLONGLONG ExChange,
  1876. IN PLONGLONG Comperand
  1877. );
  1878. // end_wdm
  1879. #else // NO_INTERLOCKED_INTRINSICS || _CROSS_PLATFORM_
  1880. #define InterlockedExchangePointer(Target, Value) \
  1881. (PVOID)InterlockedExchange((PLONG)Target, (LONG)Value)
  1882. #if (_MSC_FULL_VER > 13009037)
  1883. LONG
  1884. __cdecl
  1885. _InterlockedExchange(
  1886. IN OUT LONG volatile *Target,
  1887. IN LONG Value
  1888. );
  1889. #pragma intrinsic (_InterlockedExchange)
  1890. #define InterlockedExchange _InterlockedExchange
  1891. #else
  1892. FORCEINLINE
  1893. LONG
  1894. FASTCALL
  1895. InterlockedExchange(
  1896. IN OUT LONG volatile *Target,
  1897. IN LONG Value
  1898. )
  1899. {
  1900. __asm {
  1901. mov eax, Value
  1902. mov ecx, Target
  1903. xchg [ecx], eax
  1904. }
  1905. }
  1906. #endif
  1907. #if (_MSC_FULL_VER > 13009037)
  1908. LONG
  1909. __cdecl
  1910. _InterlockedIncrement(
  1911. IN LONG volatile *Addend
  1912. );
  1913. #pragma intrinsic (_InterlockedIncrement)
  1914. #define InterlockedIncrement _InterlockedIncrement
  1915. #else
  1916. #define InterlockedIncrement(Addend) (InterlockedExchangeAdd (Addend, 1)+1)
  1917. #endif
  1918. #if (_MSC_FULL_VER > 13009037)
  1919. LONG
  1920. __cdecl
  1921. _InterlockedDecrement(
  1922. IN LONG volatile *Addend
  1923. );
  1924. #pragma intrinsic (_InterlockedDecrement)
  1925. #define InterlockedDecrement _InterlockedDecrement
  1926. #else
  1927. #define InterlockedDecrement(Addend) (InterlockedExchangeAdd (Addend, -1)-1)
  1928. #endif
  1929. #if (_MSC_FULL_VER > 13009037)
  1930. LONG
  1931. __cdecl
  1932. _InterlockedExchangeAdd(
  1933. IN OUT LONG volatile *Addend,
  1934. IN LONG Increment
  1935. );
  1936. #pragma intrinsic (_InterlockedExchangeAdd)
  1937. #define InterlockedExchangeAdd _InterlockedExchangeAdd
  1938. #else
  1939. // begin_wdm
  1940. FORCEINLINE
  1941. LONG
  1942. FASTCALL
  1943. InterlockedExchangeAdd(
  1944. IN OUT LONG volatile *Addend,
  1945. IN LONG Increment
  1946. )
  1947. {
  1948. __asm {
  1949. mov eax, Increment
  1950. mov ecx, Addend
  1951. lock xadd [ecx], eax
  1952. }
  1953. }
  1954. // end_wdm
  1955. #endif
  1956. #if (_MSC_FULL_VER > 13009037)
  1957. LONG
  1958. __cdecl
  1959. _InterlockedCompareExchange (
  1960. IN OUT LONG volatile *Destination,
  1961. IN LONG ExChange,
  1962. IN LONG Comperand
  1963. );
  1964. #pragma intrinsic (_InterlockedCompareExchange)
  1965. #define InterlockedCompareExchange (LONG)_InterlockedCompareExchange
  1966. #else
  1967. FORCEINLINE
  1968. LONG
  1969. FASTCALL
  1970. InterlockedCompareExchange(
  1971. IN OUT LONG volatile *Destination,
  1972. IN LONG Exchange,
  1973. IN LONG Comperand
  1974. )
  1975. {
  1976. __asm {
  1977. mov eax, Comperand
  1978. mov ecx, Destination
  1979. mov edx, Exchange
  1980. lock cmpxchg [ecx], edx
  1981. }
  1982. }
  1983. #endif
  1984. #define InterlockedCompareExchangePointer(Destination, ExChange, Comperand) \
  1985. (PVOID)InterlockedCompareExchange((PLONG)Destination, (LONG)ExChange, (LONG)Comperand)
  1986. #define InterlockedCompareExchange64(Destination, ExChange, Comperand) \
  1987. ExfInterlockedCompareExchange64(Destination, &(ExChange), &(Comperand))
  1988. NTKERNELAPI
  1989. LONGLONG
  1990. FASTCALL
  1991. ExfInterlockedCompareExchange64(
  1992. IN OUT LONGLONG volatile *Destination,
  1993. IN PLONGLONG ExChange,
  1994. IN PLONGLONG Comperand
  1995. );
  1996. #endif // INTERLOCKED_INTRINSICS || _CROSS_PLATFORM_
  1997. // begin_wdm
  1998. #endif // MIDL_PASS
  1999. #define InterlockedIncrementAcquire InterlockedIncrement
  2000. #define InterlockedIncrementRelease InterlockedIncrement
  2001. #define InterlockedDecrementAcquire InterlockedDecrement
  2002. #define InterlockedDecrementRelease InterlockedDecrement
  2003. #define InterlockedExchangeAcquire64 InterlockedExchange64
  2004. #define InterlockedCompareExchangeAcquire InterlockedCompareExchange
  2005. #define InterlockedCompareExchangeRelease InterlockedCompareExchange
  2006. #define InterlockedCompareExchangeAcquire64 InterlockedCompareExchange64
  2007. #define InterlockedCompareExchangeRelease64 InterlockedCompareExchange64
  2008. #endif // __WINBASE__ && !NONTOSPINTERLOCK
  2009. typedef struct _PROCESS_IO_PORT_HANDLER_INFORMATION {
  2010. BOOLEAN Install; // true if handlers to be installed
  2011. ULONG NumEntries;
  2012. ULONG Context;
  2013. PEMULATOR_ACCESS_ENTRY EmulatorAccessEntries;
  2014. } PROCESS_IO_PORT_HANDLER_INFORMATION, *PPROCESS_IO_PORT_HANDLER_INFORMATION;
  2015. //
  2016. // Vdm Objects and Io handling structure
  2017. //
  2018. typedef struct _VDM_IO_HANDLER_FUNCTIONS {
  2019. PDRIVER_IO_PORT_ULONG UlongIo;
  2020. PDRIVER_IO_PORT_ULONG_STRING UlongStringIo;
  2021. PDRIVER_IO_PORT_USHORT UshortIo[2];
  2022. PDRIVER_IO_PORT_USHORT_STRING UshortStringIo[2];
  2023. PDRIVER_IO_PORT_UCHAR UcharIo[4];
  2024. PDRIVER_IO_PORT_UCHAR_STRING UcharStringIo[4];
  2025. } VDM_IO_HANDLER_FUNCTIONS, *PVDM_IO_HANDLER_FUNCTIONS;
  2026. typedef struct _VDM_IO_HANDLER {
  2027. struct _VDM_IO_HANDLER *Next;
  2028. ULONG PortNumber;
  2029. VDM_IO_HANDLER_FUNCTIONS IoFunctions[2];
  2030. } VDM_IO_HANDLER, *PVDM_IO_HANDLER;
  2031. // begin_nthal begin_ntddk begin_wdm
  2032. #if !defined(MIDL_PASS) && defined(_M_IX86)
  2033. //
  2034. // i386 function definitions
  2035. //
  2036. // end_wdm
  2037. #if _MSC_VER >= 1200
  2038. #pragma warning(push)
  2039. #endif
  2040. #pragma warning(disable:4035) // re-enable below
  2041. #define _PCR fs:[0]
  2042. //
  2043. // Get address of current processor block.
  2044. //
  2045. // WARNING: This inline macro can only be used by the kernel or hal
  2046. //
  2047. FORCEINLINE
  2048. PKPRCB
  2049. NTAPI
  2050. KeGetCurrentPrcb (VOID)
  2051. {
  2052. #if (_MSC_FULL_VER >= 13012035)
  2053. return (PKPRCB) (ULONG_PTR) __readfsdword (FIELD_OFFSET (KPCR, Prcb));
  2054. #else
  2055. __asm { mov eax, _PCR KPCR.Prcb }
  2056. #endif
  2057. }
  2058. // begin_ntddk begin_wdm
  2059. //
  2060. // Get current IRQL.
  2061. //
  2062. // On x86 this function resides in the HAL
  2063. //
  2064. // end_ntddk end_wdm
  2065. #if defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_) || defined(_NTHAL_) || !defined(_APIC_TPR_)
  2066. // begin_ntddk begin_wdm
  2067. NTHALAPI
  2068. KIRQL
  2069. NTAPI
  2070. KeGetCurrentIrql();
  2071. // end_ntddk end_wdm
  2072. #endif
  2073. // begin_ntddk begin_wdm
  2074. // end_wdm
  2075. //
  2076. // Get the current processor number
  2077. //
  2078. FORCEINLINE
  2079. ULONG
  2080. NTAPI
  2081. KeGetCurrentProcessorNumber(VOID)
  2082. {
  2083. #if (_MSC_FULL_VER >= 13012035)
  2084. return (ULONG) __readfsbyte (FIELD_OFFSET (KPCR, Number));
  2085. #else
  2086. __asm { movzx eax, _PCR KPCR.Number }
  2087. #endif
  2088. }
  2089. #if _MSC_VER >= 1200
  2090. #pragma warning(pop)
  2091. #else
  2092. #pragma warning(default:4035)
  2093. #endif
  2094. // begin_wdm
  2095. #endif // !defined(MIDL_PASS) && defined(_M_IX86)
  2096. //++
  2097. //
  2098. // VOID
  2099. // KeMemoryBarrier (
  2100. // VOID
  2101. // )
  2102. //
  2103. // VOID
  2104. // KeMemoryBarrierWithoutFence (
  2105. // VOID
  2106. // )
  2107. //
  2108. //
  2109. // Routine Description:
  2110. //
  2111. // These functions order memory accesses as seen by other processors.
  2112. //
  2113. // Arguments:
  2114. //
  2115. // None.
  2116. //
  2117. // Return Value:
  2118. //
  2119. // None.
  2120. //
  2121. //--
  2122. #ifdef __cplusplus
  2123. extern "C" {
  2124. #endif
  2125. VOID
  2126. _ReadWriteBarrier(
  2127. VOID
  2128. );
  2129. #ifdef __cplusplus
  2130. }
  2131. #endif
  2132. #pragma intrinsic (_ReadWriteBarrier)
  2133. FORCEINLINE
  2134. VOID
  2135. KeMemoryBarrier (
  2136. VOID
  2137. )
  2138. {
  2139. LONG Barrier;
  2140. __asm {
  2141. xchg Barrier, eax
  2142. }
  2143. }
  2144. #define KeMemoryBarrierWithoutFence() _ReadWriteBarrier()
  2145. NTKERNELAPI
  2146. NTSTATUS
  2147. NTAPI
  2148. KeSaveFloatingPointState (
  2149. OUT PKFLOATING_SAVE FloatSave
  2150. );
  2151. NTKERNELAPI
  2152. NTSTATUS
  2153. NTAPI
  2154. KeRestoreFloatingPointState (
  2155. IN PKFLOATING_SAVE FloatSave
  2156. );
  2157. // end_ntddk end_wdm
  2158. // begin_nthal
  2159. NTKERNELAPI
  2160. VOID
  2161. NTAPI
  2162. KeProfileInterruptWithSource (
  2163. IN struct _KTRAP_FRAME *TrapFrame,
  2164. IN KPROFILE_SOURCE ProfileSource
  2165. );
  2166. #endif // defined(_X86_)
  2167. #ifdef _X86_
  2168. VOID
  2169. NTAPI
  2170. Ke386SetLdtProcess (
  2171. struct _KPROCESS *Process,
  2172. PLDT_ENTRY Ldt,
  2173. ULONG Limit
  2174. );
  2175. VOID
  2176. NTAPI
  2177. Ke386SetDescriptorProcess (
  2178. struct _KPROCESS *Process,
  2179. ULONG Offset,
  2180. LDT_ENTRY LdtEntry
  2181. );
  2182. VOID
  2183. NTAPI
  2184. Ke386GetGdtEntryThread (
  2185. struct _KTHREAD *Thread,
  2186. ULONG Offset,
  2187. PKGDTENTRY Descriptor
  2188. );
  2189. BOOLEAN
  2190. NTAPI
  2191. Ke386SetIoAccessMap (
  2192. ULONG MapNumber,
  2193. PKIO_ACCESS_MAP IoAccessMap
  2194. );
  2195. BOOLEAN
  2196. NTAPI
  2197. Ke386QueryIoAccessMap (
  2198. ULONG MapNumber,
  2199. PKIO_ACCESS_MAP IoAccessMap
  2200. );
  2201. BOOLEAN
  2202. NTAPI
  2203. Ke386IoSetAccessProcess (
  2204. struct _KPROCESS *Process,
  2205. ULONG MapNumber
  2206. );
  2207. VOID
  2208. NTAPI
  2209. Ke386SetIOPL(
  2210. VOID
  2211. );
  2212. NTSTATUS
  2213. NTAPI
  2214. Ke386CallBios (
  2215. IN ULONG BiosCommand,
  2216. IN OUT PCONTEXT BiosArguments
  2217. );
  2218. VOID
  2219. NTAPI
  2220. KiEditIopmDpc (
  2221. IN struct _KDPC *Dpc,
  2222. IN PVOID DeferredContext,
  2223. IN PVOID SystemArgument1,
  2224. IN PVOID SystemArgument2
  2225. );
  2226. BOOLEAN
  2227. NTAPI
  2228. Ki386GetSelectorParameters(
  2229. IN USHORT Selector,
  2230. OUT PULONG Flags,
  2231. OUT PULONG Base,
  2232. OUT PULONG Limit
  2233. );
  2234. ULONG
  2235. Ki386DispatchOpcodeV86 (
  2236. IN PKTRAP_FRAME TrapFrame
  2237. );
  2238. ULONG
  2239. Ki386DispatchOpcode (
  2240. IN PKTRAP_FRAME TrapFrame
  2241. );
  2242. NTSTATUS
  2243. NTAPI
  2244. Ke386SetVdmInterruptHandler (
  2245. IN struct _KPROCESS *Process,
  2246. IN ULONG Interrupt,
  2247. IN USHORT Selector,
  2248. IN ULONG Offset,
  2249. IN BOOLEAN Gate32
  2250. );
  2251. #endif //_X86_
  2252. #define INIT_SYSTEMROOT_LINKNAME "\\SystemRoot"
  2253. #define INIT_SYSTEMROOT_DLLPATH "\\SystemRoot\\System32"
  2254. #define INIT_SYSTEMROOT_BINPATH "\\SystemRoot\\System32"
  2255. extern ULONG NtBuildNumber;
  2256. #if defined(_M_AMD64) && !defined(RC_INVOKED) && !defined(MIDL_PASS)
  2257. //
  2258. // Define intrinsic function to do in's and out's.
  2259. //
  2260. #ifdef __cplusplus
  2261. extern "C" {
  2262. #endif
  2263. UCHAR
  2264. __inbyte (
  2265. IN USHORT Port
  2266. );
  2267. USHORT
  2268. __inword (
  2269. IN USHORT Port
  2270. );
  2271. ULONG
  2272. __indword (
  2273. IN USHORT Port
  2274. );
  2275. VOID
  2276. __outbyte (
  2277. IN USHORT Port,
  2278. IN UCHAR Data
  2279. );
  2280. VOID
  2281. __outword (
  2282. IN USHORT Port,
  2283. IN USHORT Data
  2284. );
  2285. VOID
  2286. __outdword (
  2287. IN USHORT Port,
  2288. IN ULONG Data
  2289. );
  2290. VOID
  2291. __inbytestring (
  2292. IN USHORT Port,
  2293. IN PUCHAR Buffer,
  2294. IN ULONG Count
  2295. );
  2296. VOID
  2297. __inwordstring (
  2298. IN USHORT Port,
  2299. IN PUSHORT Buffer,
  2300. IN ULONG Count
  2301. );
  2302. VOID
  2303. __indwordstring (
  2304. IN USHORT Port,
  2305. IN PULONG Buffer,
  2306. IN ULONG Count
  2307. );
  2308. VOID
  2309. __outbytestring (
  2310. IN USHORT Port,
  2311. IN PUCHAR Buffer,
  2312. IN ULONG Count
  2313. );
  2314. VOID
  2315. __outwordstring (
  2316. IN USHORT Port,
  2317. IN PUSHORT Buffer,
  2318. IN ULONG Count
  2319. );
  2320. VOID
  2321. __outdwordstring (
  2322. IN USHORT Port,
  2323. IN PULONG Buffer,
  2324. IN ULONG Count
  2325. );
  2326. #ifdef __cplusplus
  2327. }
  2328. #endif
  2329. #pragma intrinsic(__inbyte)
  2330. #pragma intrinsic(__inword)
  2331. #pragma intrinsic(__indword)
  2332. #pragma intrinsic(__outbyte)
  2333. #pragma intrinsic(__outword)
  2334. #pragma intrinsic(__outdword)
  2335. #pragma intrinsic(__inbytestring)
  2336. #pragma intrinsic(__inwordstring)
  2337. #pragma intrinsic(__indwordstring)
  2338. #pragma intrinsic(__outbytestring)
  2339. #pragma intrinsic(__outwordstring)
  2340. #pragma intrinsic(__outdwordstring)
  2341. //
  2342. // Interlocked intrinsic functions.
  2343. //
  2344. #define InterlockedAnd _InterlockedAnd
  2345. #define InterlockedOr _InterlockedOr
  2346. #define InterlockedXor _InterlockedXor
  2347. #define InterlockedIncrement _InterlockedIncrement
  2348. #define InterlockedIncrementAcquire InterlockedIncrement
  2349. #define InterlockedIncrementRelease InterlockedIncrement
  2350. #define InterlockedDecrement _InterlockedDecrement
  2351. #define InterlockedDecrementAcquire InterlockedDecrement
  2352. #define InterlockedDecrementRelease InterlockedDecrement
  2353. #define InterlockedAdd _InterlockedAdd
  2354. #define InterlockedExchange _InterlockedExchange
  2355. #define InterlockedExchangeAdd _InterlockedExchangeAdd
  2356. #define InterlockedCompareExchange _InterlockedCompareExchange
  2357. #define InterlockedCompareExchangeAcquire InterlockedCompareExchange
  2358. #define InterlockedCompareExchangeRelease InterlockedCompareExchange
  2359. #define InterlockedAnd64 _InterlockedAnd64
  2360. #define InterlockedOr64 _InterlockedOr64
  2361. #define InterlockedXor64 _InterlockedXor64
  2362. #define InterlockedIncrement64 _InterlockedIncrement64
  2363. #define InterlockedDecrement64 _InterlockedDecrement64
  2364. #define InterlockedAdd64 _InterlockedAdd64
  2365. #define InterlockedExchange64 _InterlockedExchange64
  2366. #define InterlockedExchangeAcquire64 InterlockedExchange64
  2367. #define InterlockedExchangeAdd64 _InterlockedExchangeAdd64
  2368. #define InterlockedCompareExchange64 _InterlockedCompareExchange64
  2369. #define InterlockedCompareExchangeAcquire64 InterlockedCompareExchange64
  2370. #define InterlockedCompareExchangeRelease64 InterlockedCompareExchange64
  2371. #define InterlockedExchangePointer _InterlockedExchangePointer
  2372. #define InterlockedCompareExchangePointer _InterlockedCompareExchangePointer
  2373. #ifdef __cplusplus
  2374. extern "C" {
  2375. #endif
  2376. LONG
  2377. InterlockedAnd (
  2378. IN OUT LONG volatile *Destination,
  2379. IN LONG Value
  2380. );
  2381. LONG
  2382. InterlockedOr (
  2383. IN OUT LONG volatile *Destination,
  2384. IN LONG Value
  2385. );
  2386. LONG
  2387. InterlockedXor (
  2388. IN OUT LONG volatile *Destination,
  2389. IN LONG Value
  2390. );
  2391. LONG64
  2392. InterlockedAnd64 (
  2393. IN OUT LONG64 volatile *Destination,
  2394. IN LONG64 Value
  2395. );
  2396. LONG64
  2397. InterlockedOr64 (
  2398. IN OUT LONG64 volatile *Destination,
  2399. IN LONG64 Value
  2400. );
  2401. LONG64
  2402. InterlockedXor64 (
  2403. IN OUT LONG64 volatile *Destination,
  2404. IN LONG64 Value
  2405. );
  2406. LONG
  2407. InterlockedIncrement(
  2408. IN OUT LONG volatile *Addend
  2409. );
  2410. LONG
  2411. InterlockedDecrement(
  2412. IN OUT LONG volatile *Addend
  2413. );
  2414. LONG
  2415. InterlockedExchange(
  2416. IN OUT LONG volatile *Target,
  2417. IN LONG Value
  2418. );
  2419. LONG
  2420. InterlockedExchangeAdd(
  2421. IN OUT LONG volatile *Addend,
  2422. IN LONG Value
  2423. );
  2424. #if !defined(_X86AMD64_)
  2425. __forceinline
  2426. LONG
  2427. InterlockedAdd(
  2428. IN OUT LONG volatile *Addend,
  2429. IN LONG Value
  2430. )
  2431. {
  2432. return InterlockedExchangeAdd(Addend, Value) + Value;
  2433. }
  2434. #endif
  2435. LONG
  2436. InterlockedCompareExchange (
  2437. IN OUT LONG volatile *Destination,
  2438. IN LONG ExChange,
  2439. IN LONG Comperand
  2440. );
  2441. LONG64
  2442. InterlockedIncrement64(
  2443. IN OUT LONG64 volatile *Addend
  2444. );
  2445. LONG64
  2446. InterlockedDecrement64(
  2447. IN OUT LONG64 volatile *Addend
  2448. );
  2449. LONG64
  2450. InterlockedExchange64(
  2451. IN OUT LONG64 volatile *Target,
  2452. IN LONG64 Value
  2453. );
  2454. LONG64
  2455. InterlockedExchangeAdd64(
  2456. IN OUT LONG64 volatile *Addend,
  2457. IN LONG64 Value
  2458. );
  2459. #if !defined(_X86AMD64_)
  2460. __forceinline
  2461. LONG64
  2462. InterlockedAdd64(
  2463. IN OUT LONG64 volatile *Addend,
  2464. IN LONG64 Value
  2465. )
  2466. {
  2467. return InterlockedExchangeAdd64(Addend, Value) + Value;
  2468. }
  2469. #endif
  2470. LONG64
  2471. InterlockedCompareExchange64 (
  2472. IN OUT LONG64 volatile *Destination,
  2473. IN LONG64 ExChange,
  2474. IN LONG64 Comperand
  2475. );
  2476. PVOID
  2477. InterlockedCompareExchangePointer (
  2478. IN OUT PVOID volatile *Destination,
  2479. IN PVOID Exchange,
  2480. IN PVOID Comperand
  2481. );
  2482. PVOID
  2483. InterlockedExchangePointer(
  2484. IN OUT PVOID volatile *Target,
  2485. IN PVOID Value
  2486. );
  2487. #pragma intrinsic(_InterlockedAnd)
  2488. #pragma intrinsic(_InterlockedOr)
  2489. #pragma intrinsic(_InterlockedXor)
  2490. #pragma intrinsic(_InterlockedIncrement)
  2491. #pragma intrinsic(_InterlockedDecrement)
  2492. #pragma intrinsic(_InterlockedExchange)
  2493. #pragma intrinsic(_InterlockedExchangeAdd)
  2494. #pragma intrinsic(_InterlockedCompareExchange)
  2495. #pragma intrinsic(_InterlockedAnd64)
  2496. #pragma intrinsic(_InterlockedOr64)
  2497. #pragma intrinsic(_InterlockedXor64)
  2498. #pragma intrinsic(_InterlockedIncrement64)
  2499. #pragma intrinsic(_InterlockedDecrement64)
  2500. #pragma intrinsic(_InterlockedExchange64)
  2501. #pragma intrinsic(_InterlockedExchangeAdd64)
  2502. #pragma intrinsic(_InterlockedCompareExchange64)
  2503. #pragma intrinsic(_InterlockedExchangePointer)
  2504. #pragma intrinsic(_InterlockedCompareExchangePointer)
  2505. #ifdef __cplusplus
  2506. }
  2507. #endif
  2508. #endif // defined(_M_AMD64) && !defined(RC_INVOKED) && !defined(MIDL_PASS)
  2509. #if defined(_AMD64_)
  2510. //
  2511. // Types to use to contain PFNs and their counts.
  2512. //
  2513. typedef ULONG PFN_COUNT;
  2514. typedef LONG64 SPFN_NUMBER, *PSPFN_NUMBER;
  2515. typedef ULONG64 PFN_NUMBER, *PPFN_NUMBER;
  2516. //
  2517. // Define maximum size of flush multiple TB request.
  2518. //
  2519. #define FLUSH_MULTIPLE_MAXIMUM 32
  2520. //
  2521. // Indicate that the AMD64 compiler supports the allocate pragmas.
  2522. //
  2523. #define ALLOC_PRAGMA 1
  2524. #define ALLOC_DATA_PRAGMA 1
  2525. //
  2526. // Define constants for bits in CR0.
  2527. //
  2528. #define CR0_PE 0x00000001 // protection enable
  2529. #define CR0_MP 0x00000002 // math present
  2530. #define CR0_EM 0x00000004 // emulate math coprocessor
  2531. #define CR0_TS 0x00000008 // task switched
  2532. #define CR0_ET 0x00000010 // extension type (80387)
  2533. #define CR0_NE 0x00000020 // numeric error
  2534. #define CR0_WP 0x00010000 // write protect
  2535. #define CR0_AM 0x00040000 // alignment mask
  2536. #define CR0_NW 0x20000000 // not write-through
  2537. #define CR0_CD 0x40000000 // cache disable
  2538. #define CR0_PG 0x80000000 // paging
  2539. //
  2540. // Define functions to read and write CR0.
  2541. //
  2542. #ifdef __cplusplus
  2543. extern "C" {
  2544. #endif
  2545. #define ReadCR0() __readcr0()
  2546. ULONG64
  2547. __readcr0 (
  2548. VOID
  2549. );
  2550. #define WriteCR0(Data) __writecr0(Data)
  2551. VOID
  2552. __writecr0 (
  2553. IN ULONG64 Data
  2554. );
  2555. #pragma intrinsic(__readcr0)
  2556. #pragma intrinsic(__writecr0)
  2557. //
  2558. // Define functions to read and write CR3.
  2559. //
  2560. #define ReadCR3() __readcr3()
  2561. ULONG64
  2562. __readcr3 (
  2563. VOID
  2564. );
  2565. #define WriteCR3(Data) __writecr3(Data)
  2566. VOID
  2567. __writecr3 (
  2568. IN ULONG64 Data
  2569. );
  2570. #pragma intrinsic(__readcr3)
  2571. #pragma intrinsic(__writecr3)
  2572. //
  2573. // Define constants for bits in CR4.
  2574. //
  2575. #define CR4_VME 0x00000001 // V86 mode extensions
  2576. #define CR4_PVI 0x00000002 // Protected mode virtual interrupts
  2577. #define CR4_TSD 0x00000004 // Time stamp disable
  2578. #define CR4_DE 0x00000008 // Debugging Extensions
  2579. #define CR4_PSE 0x00000010 // Page size extensions
  2580. #define CR4_PAE 0x00000020 // Physical address extensions
  2581. #define CR4_MCE 0x00000040 // Machine check enable
  2582. #define CR4_PGE 0x00000080 // Page global enable
  2583. #define CR4_FXSR 0x00000200 // FXSR used by OS
  2584. #define CR4_XMMEXCPT 0x00000400 // XMMI used by OS
  2585. //
  2586. // Define functions to read and write CR4.
  2587. //
  2588. #define ReadCR4() __readcr4()
  2589. ULONG64
  2590. __readcr4 (
  2591. VOID
  2592. );
  2593. #define WriteCR4(Data) __writecr4(Data)
  2594. VOID
  2595. __writecr4 (
  2596. IN ULONG64 Data
  2597. );
  2598. #pragma intrinsic(__readcr4)
  2599. #pragma intrinsic(__writecr4)
  2600. //
  2601. // Define functions to read and write CR8.
  2602. //
  2603. // CR8 is the APIC TPR register.
  2604. //
  2605. #define ReadCR8() __readcr8()
  2606. ULONG64
  2607. __readcr8 (
  2608. VOID
  2609. );
  2610. #define WriteCR8(Data) __writecr8(Data)
  2611. VOID
  2612. __writecr8 (
  2613. IN ULONG64 Data
  2614. );
  2615. #pragma intrinsic(__readcr8)
  2616. #pragma intrinsic(__writecr8)
  2617. #ifdef __cplusplus
  2618. }
  2619. #endif
  2620. //
  2621. // Interrupt Request Level definitions
  2622. //
  2623. #define PASSIVE_LEVEL 0 // Passive release level
  2624. #define LOW_LEVEL 0 // Lowest interrupt level
  2625. #define APC_LEVEL 1 // APC interrupt level
  2626. #define DISPATCH_LEVEL 2 // Dispatcher level
  2627. #define CLOCK_LEVEL 13 // Interval clock level
  2628. #define IPI_LEVEL 14 // Interprocessor interrupt level
  2629. #define POWER_LEVEL 14 // Power failure level
  2630. #define PROFILE_LEVEL 15 // timer used for profiling.
  2631. #define HIGH_LEVEL 15 // Highest interrupt level
  2632. #define SYNCH_LEVEL (IPI_LEVEL-2)
  2633. #define MODE_MASK 1
  2634. //
  2635. // I/O space read and write macros.
  2636. //
  2637. // The READ/WRITE_REGISTER_* calls manipulate I/O registers in MEMORY space.
  2638. //
  2639. // The READ/WRITE_PORT_* calls manipulate I/O registers in PORT space.
  2640. //
  2641. __forceinline
  2642. UCHAR
  2643. READ_REGISTER_UCHAR (
  2644. volatile UCHAR *Register
  2645. )
  2646. {
  2647. return *Register;
  2648. }
  2649. __forceinline
  2650. USHORT
  2651. READ_REGISTER_USHORT (
  2652. volatile USHORT *Register
  2653. )
  2654. {
  2655. return *Register;
  2656. }
  2657. __forceinline
  2658. ULONG
  2659. READ_REGISTER_ULONG (
  2660. volatile ULONG *Register
  2661. )
  2662. {
  2663. return *Register;
  2664. }
  2665. __forceinline
  2666. VOID
  2667. READ_REGISTER_BUFFER_UCHAR (
  2668. PUCHAR Register,
  2669. PUCHAR Buffer,
  2670. ULONG Count
  2671. )
  2672. {
  2673. __movsb(Buffer, Register, Count);
  2674. return;
  2675. }
  2676. __forceinline
  2677. VOID
  2678. READ_REGISTER_BUFFER_USHORT (
  2679. PUSHORT Register,
  2680. PUSHORT Buffer,
  2681. ULONG Count
  2682. )
  2683. {
  2684. __movsw(Buffer, Register, Count);
  2685. return;
  2686. }
  2687. __forceinline
  2688. VOID
  2689. READ_REGISTER_BUFFER_ULONG (
  2690. PULONG Register,
  2691. PULONG Buffer,
  2692. ULONG Count
  2693. )
  2694. {
  2695. __movsd(Buffer, Register, Count);
  2696. return;
  2697. }
  2698. __forceinline
  2699. VOID
  2700. WRITE_REGISTER_UCHAR (
  2701. PUCHAR Register,
  2702. UCHAR Value
  2703. )
  2704. {
  2705. *Register = Value;
  2706. StoreFence();
  2707. return;
  2708. }
  2709. __forceinline
  2710. VOID
  2711. WRITE_REGISTER_USHORT (
  2712. PUSHORT Register,
  2713. USHORT Value
  2714. )
  2715. {
  2716. *Register = Value;
  2717. StoreFence();
  2718. return;
  2719. }
  2720. __forceinline
  2721. VOID
  2722. WRITE_REGISTER_ULONG (
  2723. PULONG Register,
  2724. ULONG Value
  2725. )
  2726. {
  2727. *Register = Value;
  2728. StoreFence();
  2729. return;
  2730. }
  2731. __forceinline
  2732. VOID
  2733. WRITE_REGISTER_BUFFER_UCHAR (
  2734. PUCHAR Register,
  2735. PUCHAR Buffer,
  2736. ULONG Count
  2737. )
  2738. {
  2739. __movsb(Register, Buffer, Count);
  2740. StoreFence();
  2741. return;
  2742. }
  2743. __forceinline
  2744. VOID
  2745. WRITE_REGISTER_BUFFER_USHORT (
  2746. PUSHORT Register,
  2747. PUSHORT Buffer,
  2748. ULONG Count
  2749. )
  2750. {
  2751. __movsw(Register, Buffer, Count);
  2752. StoreFence();
  2753. return;
  2754. }
  2755. __forceinline
  2756. VOID
  2757. WRITE_REGISTER_BUFFER_ULONG (
  2758. PULONG Register,
  2759. PULONG Buffer,
  2760. ULONG Count
  2761. )
  2762. {
  2763. __movsd(Register, Buffer, Count);
  2764. StoreFence();
  2765. return;
  2766. }
  2767. __forceinline
  2768. UCHAR
  2769. READ_PORT_UCHAR (
  2770. PUCHAR Port
  2771. )
  2772. {
  2773. return __inbyte((USHORT)((ULONG64)Port));
  2774. }
  2775. __forceinline
  2776. USHORT
  2777. READ_PORT_USHORT (
  2778. PUSHORT Port
  2779. )
  2780. {
  2781. return __inword((USHORT)((ULONG64)Port));
  2782. }
  2783. __forceinline
  2784. ULONG
  2785. READ_PORT_ULONG (
  2786. PULONG Port
  2787. )
  2788. {
  2789. return __indword((USHORT)((ULONG64)Port));
  2790. }
  2791. __forceinline
  2792. VOID
  2793. READ_PORT_BUFFER_UCHAR (
  2794. PUCHAR Port,
  2795. PUCHAR Buffer,
  2796. ULONG Count
  2797. )
  2798. {
  2799. __inbytestring((USHORT)((ULONG64)Port), Buffer, Count);
  2800. return;
  2801. }
  2802. __forceinline
  2803. VOID
  2804. READ_PORT_BUFFER_USHORT (
  2805. PUSHORT Port,
  2806. PUSHORT Buffer,
  2807. ULONG Count
  2808. )
  2809. {
  2810. __inwordstring((USHORT)((ULONG64)Port), Buffer, Count);
  2811. return;
  2812. }
  2813. __forceinline
  2814. VOID
  2815. READ_PORT_BUFFER_ULONG (
  2816. PULONG Port,
  2817. PULONG Buffer,
  2818. ULONG Count
  2819. )
  2820. {
  2821. __indwordstring((USHORT)((ULONG64)Port), Buffer, Count);
  2822. return;
  2823. }
  2824. __forceinline
  2825. VOID
  2826. WRITE_PORT_UCHAR (
  2827. PUCHAR Port,
  2828. UCHAR Value
  2829. )
  2830. {
  2831. __outbyte((USHORT)((ULONG64)Port), Value);
  2832. return;
  2833. }
  2834. __forceinline
  2835. VOID
  2836. WRITE_PORT_USHORT (
  2837. PUSHORT Port,
  2838. USHORT Value
  2839. )
  2840. {
  2841. __outword((USHORT)((ULONG64)Port), Value);
  2842. return;
  2843. }
  2844. __forceinline
  2845. VOID
  2846. WRITE_PORT_ULONG (
  2847. PULONG Port,
  2848. ULONG Value
  2849. )
  2850. {
  2851. __outdword((USHORT)((ULONG64)Port), Value);
  2852. return;
  2853. }
  2854. __forceinline
  2855. VOID
  2856. WRITE_PORT_BUFFER_UCHAR (
  2857. PUCHAR Port,
  2858. PUCHAR Buffer,
  2859. ULONG Count
  2860. )
  2861. {
  2862. __outbytestring((USHORT)((ULONG64)Port), Buffer, Count);
  2863. return;
  2864. }
  2865. __forceinline
  2866. VOID
  2867. WRITE_PORT_BUFFER_USHORT (
  2868. PUSHORT Port,
  2869. PUSHORT Buffer,
  2870. ULONG Count
  2871. )
  2872. {
  2873. __outwordstring((USHORT)((ULONG64)Port), Buffer, Count);
  2874. return;
  2875. }
  2876. __forceinline
  2877. VOID
  2878. WRITE_PORT_BUFFER_ULONG (
  2879. PULONG Port,
  2880. PULONG Buffer,
  2881. ULONG Count
  2882. )
  2883. {
  2884. __outdwordstring((USHORT)((ULONG64)Port), Buffer, Count);
  2885. return;
  2886. }
  2887. // end_ntndis
  2888. //
  2889. // Get data cache fill size.
  2890. //
  2891. #if PRAGMA_DEPRECATED_DDK
  2892. #pragma deprecated(KeGetDcacheFillSize) // Use GetDmaAlignment
  2893. #endif
  2894. #define KeGetDcacheFillSize() 1L
  2895. #define KeFlushIoBuffers(Mdl, ReadOperation, DmaOperation)
  2896. #define ExAcquireSpinLock(Lock, OldIrql) KeAcquireSpinLock((Lock), (OldIrql))
  2897. #define ExReleaseSpinLock(Lock, OldIrql) KeReleaseSpinLock((Lock), (OldIrql))
  2898. #define ExAcquireSpinLockAtDpcLevel(Lock) KeAcquireSpinLockAtDpcLevel(Lock)
  2899. #define ExReleaseSpinLockFromDpcLevel(Lock) KeReleaseSpinLockFromDpcLevel(Lock)
  2900. #define KI_USER_SHARED_DATA 0xFFFFF78000000000UI64
  2901. #define SharedUserData ((KUSER_SHARED_DATA * const)KI_USER_SHARED_DATA)
  2902. #define SharedInterruptTime (KI_USER_SHARED_DATA + 0x8)
  2903. #define SharedSystemTime (KI_USER_SHARED_DATA + 0x14)
  2904. #define SharedTickCount (KI_USER_SHARED_DATA + 0x320)
  2905. #define KeQueryInterruptTime() *((volatile ULONG64 *)(SharedInterruptTime))
  2906. #define KeQuerySystemTime(CurrentCount) \
  2907. *((PULONG64)(CurrentCount)) = *((volatile ULONG64 *)(SharedSystemTime))
  2908. #define KeQueryTickCount(CurrentCount) \
  2909. *((PULONG64)(CurrentCount)) = *((volatile ULONG64 *)(SharedTickCount))
  2910. //
  2911. // AMD64 hardware structures
  2912. //
  2913. // A Page Table Entry on an AMD64 has the following definition.
  2914. //
  2915. #define _HARDWARE_PTE_WORKING_SET_BITS 11
  2916. typedef struct _HARDWARE_PTE {
  2917. ULONG64 Valid : 1;
  2918. ULONG64 Write : 1; // UP version
  2919. ULONG64 Owner : 1;
  2920. ULONG64 WriteThrough : 1;
  2921. ULONG64 CacheDisable : 1;
  2922. ULONG64 Accessed : 1;
  2923. ULONG64 Dirty : 1;
  2924. ULONG64 LargePage : 1;
  2925. ULONG64 Global : 1;
  2926. ULONG64 CopyOnWrite : 1; // software field
  2927. ULONG64 Prototype : 1; // software field
  2928. ULONG64 reserved0 : 1; // software field
  2929. ULONG64 PageFrameNumber : 28;
  2930. ULONG64 reserved1 : 24 - (_HARDWARE_PTE_WORKING_SET_BITS+1);
  2931. ULONG64 SoftwareWsIndex : _HARDWARE_PTE_WORKING_SET_BITS;
  2932. ULONG64 NoExecute : 1;
  2933. } HARDWARE_PTE, *PHARDWARE_PTE;
  2934. //
  2935. // Define macro to initialize directory table base.
  2936. //
  2937. #define INITIALIZE_DIRECTORY_TABLE_BASE(dirbase,pfn) \
  2938. *((PULONG64)(dirbase)) = (((ULONG64)(pfn)) << PAGE_SHIFT)
  2939. //
  2940. // Define Global Descriptor Table (GDT) entry structure and constants.
  2941. //
  2942. // Define descriptor type codes.
  2943. //
  2944. #define TYPE_CODE 0x1A // 11010 = code, read only
  2945. #define TYPE_DATA 0x12 // 10010 = data, read and write
  2946. #define TYPE_TSS64 0x09 // 01001 = task state segment
  2947. //
  2948. // Define descriptor privilege levels for user and system.
  2949. //
  2950. #define DPL_USER 3
  2951. #define DPL_SYSTEM 0
  2952. //
  2953. // Define limit granularity.
  2954. //
  2955. #define GRANULARITY_BYTE 0
  2956. #define GRANULARITY_PAGE 1
  2957. #define SELECTOR_TABLE_INDEX 0x04
  2958. typedef union _KGDTENTRY64 {
  2959. struct {
  2960. USHORT LimitLow;
  2961. USHORT BaseLow;
  2962. union {
  2963. struct {
  2964. UCHAR BaseMiddle;
  2965. UCHAR Flags1;
  2966. UCHAR Flags2;
  2967. UCHAR BaseHigh;
  2968. } Bytes;
  2969. struct {
  2970. ULONG BaseMiddle : 8;
  2971. ULONG Type : 5;
  2972. ULONG Dpl : 2;
  2973. ULONG Present : 1;
  2974. ULONG LimitHigh : 4;
  2975. ULONG System : 1;
  2976. ULONG LongMode : 1;
  2977. ULONG DefaultBig : 1;
  2978. ULONG Granularity : 1;
  2979. ULONG BaseHigh : 8;
  2980. } Bits;
  2981. };
  2982. ULONG BaseUpper;
  2983. ULONG MustBeZero;
  2984. };
  2985. ULONG64 Alignment;
  2986. } KGDTENTRY64, *PKGDTENTRY64;
  2987. //
  2988. // Define Interrupt Descriptor Table (IDT) entry structure and constants.
  2989. //
  2990. typedef union _KIDTENTRY64 {
  2991. struct {
  2992. USHORT OffsetLow;
  2993. USHORT Selector;
  2994. USHORT IstIndex : 3;
  2995. USHORT Reserved0 : 5;
  2996. USHORT Type : 5;
  2997. USHORT Dpl : 2;
  2998. USHORT Present : 1;
  2999. USHORT OffsetMiddle;
  3000. ULONG OffsetHigh;
  3001. ULONG Reserved1;
  3002. };
  3003. ULONG64 Alignment;
  3004. } KIDTENTRY64, *PKIDTENTRY64;
  3005. //
  3006. // Define two union definitions used for parsing addresses into the
  3007. // component fields required by a GDT.
  3008. //
  3009. typedef union _KGDT_BASE {
  3010. struct {
  3011. USHORT BaseLow;
  3012. UCHAR BaseMiddle;
  3013. UCHAR BaseHigh;
  3014. ULONG BaseUpper;
  3015. };
  3016. ULONG64 Base;
  3017. } KGDT_BASE, *PKGDT_BASE;
  3018. C_ASSERT(sizeof(KGDT_BASE) == sizeof(ULONG64));
  3019. typedef union _KGDT_LIMIT {
  3020. struct {
  3021. USHORT LimitLow;
  3022. USHORT LimitHigh : 4;
  3023. USHORT MustBeZero : 12;
  3024. };
  3025. ULONG Limit;
  3026. } KGDT_LIMIT, *PKGDT_LIMIT;
  3027. C_ASSERT(sizeof(KGDT_LIMIT) == sizeof(ULONG));
  3028. //
  3029. // Define Task State Segment (TSS) structure and constants.
  3030. //
  3031. // Task switches are not supported by the AMD64, but a task state segment
  3032. // must be present to define the kernel stack pointer and I/O map base.
  3033. //
  3034. // N.B. This structure is misaligned as per the AMD64 specification.
  3035. //
  3036. // N.B. The size of TSS must be <= 0xDFFF.
  3037. //
  3038. #pragma pack(push, 4)
  3039. typedef struct _KTSS64 {
  3040. ULONG Reserved0;
  3041. ULONG64 Rsp0;
  3042. ULONG64 Rsp1;
  3043. ULONG64 Rsp2;
  3044. //
  3045. // Element 0 of the Ist is reserved
  3046. //
  3047. ULONG64 Ist[8];
  3048. ULONG64 Reserved1;
  3049. USHORT IoMapBase;
  3050. } KTSS64, *PKTSS64;
  3051. #pragma pack(pop)
  3052. C_ASSERT((sizeof(KTSS64) % sizeof(PVOID)) == 0);
  3053. #define TSS_IST_RESERVED 0
  3054. #define TSS_IST_PANIC 1
  3055. #define TSS_IST_MCA 2
  3056. #define IO_ACCESS_MAP_NONE FALSE
  3057. #define KiComputeIopmOffset(Enable) (sizeof(KTSS64))
  3058. // begin_windbgkd
  3059. #if defined(_AMD64_)
  3060. //
  3061. // Define pseudo descriptor structures for both 64- and 32-bit mode.
  3062. //
  3063. typedef struct _KDESCRIPTOR {
  3064. USHORT Pad[3];
  3065. USHORT Limit;
  3066. PVOID Base;
  3067. } KDESCRIPTOR, *PKDESCRIPTOR;
  3068. typedef struct _KDESCRIPTOR32 {
  3069. USHORT Pad[3];
  3070. USHORT Limit;
  3071. ULONG Base;
  3072. } KDESCRIPTOR32, *PKDESCRIPTOR32;
  3073. //
  3074. // Define special kernel registers and the initial MXCSR value.
  3075. //
  3076. typedef struct _KSPECIAL_REGISTERS {
  3077. ULONG64 Cr0;
  3078. ULONG64 Cr2;
  3079. ULONG64 Cr3;
  3080. ULONG64 Cr4;
  3081. ULONG64 KernelDr0;
  3082. ULONG64 KernelDr1;
  3083. ULONG64 KernelDr2;
  3084. ULONG64 KernelDr3;
  3085. ULONG64 KernelDr6;
  3086. ULONG64 KernelDr7;
  3087. KDESCRIPTOR Gdtr;
  3088. KDESCRIPTOR Idtr;
  3089. USHORT Tr;
  3090. USHORT Ldtr;
  3091. ULONG MxCsr;
  3092. ULONG64 DebugControl;
  3093. ULONG64 LastBranchToRip;
  3094. ULONG64 LastBranchFromRip;
  3095. ULONG64 LastExceptionToRip;
  3096. ULONG64 LastExceptionFromRip;
  3097. ULONG64 Cr8;
  3098. ULONG64 MsrGsBase;
  3099. ULONG64 MsrGsSwap;
  3100. ULONG64 MsrStar;
  3101. ULONG64 MsrLStar;
  3102. ULONG64 MsrCStar;
  3103. ULONG64 MsrSyscallMask;
  3104. } KSPECIAL_REGISTERS, *PKSPECIAL_REGISTERS;
  3105. //
  3106. // Define processor state structure.
  3107. //
  3108. typedef struct _KPROCESSOR_STATE {
  3109. KSPECIAL_REGISTERS SpecialRegisters;
  3110. CONTEXT ContextFrame;
  3111. } KPROCESSOR_STATE, *PKPROCESSOR_STATE;
  3112. #endif // _AMD64_
  3113. // end_windbgkd
  3114. //
  3115. // DPC data structure definition.
  3116. //
  3117. typedef struct _KDPC_DATA {
  3118. LIST_ENTRY DpcListHead;
  3119. KSPIN_LOCK DpcLock;
  3120. volatile ULONG DpcQueueDepth;
  3121. ULONG DpcCount;
  3122. } KDPC_DATA, *PKDPC_DATA;
  3123. //
  3124. // Processor Control Block (PRCB)
  3125. //
  3126. #define PRCB_MAJOR_VERSION 1
  3127. #define PRCB_MINOR_VERSION 1
  3128. #define PRCB_BUILD_DEBUG 0x1
  3129. #define PRCB_BUILD_UNIPROCESSOR 0x2
  3130. typedef struct _KPRCB {
  3131. //
  3132. // Start of the architecturally defined section of the PRCB. This section
  3133. // may be directly addressed by vendor/platform specific HAL code and will
  3134. // not change from version to version of NT.
  3135. //
  3136. USHORT MinorVersion;
  3137. USHORT MajorVersion;
  3138. CCHAR Number;
  3139. CCHAR Reserved;
  3140. USHORT BuildType;
  3141. struct _KTHREAD *CurrentThread;
  3142. struct _KTHREAD *NextThread;
  3143. struct _KTHREAD *IdleThread;
  3144. KAFFINITY SetMember;
  3145. KAFFINITY NotSetMember;
  3146. KSPIN_LOCK PrcbLock;
  3147. KPROCESSOR_STATE ProcessorState;
  3148. CCHAR CpuType;
  3149. CCHAR CpuID;
  3150. USHORT CpuStep;
  3151. ULONG PrcbPad00;
  3152. ULONG64 HalReserved[8];
  3153. UCHAR PrcbPad0[104];
  3154. //
  3155. // End of the architecturally defined section of the PRCB.
  3156. //
  3157. } KPRCB, *PKPRCB, *RESTRICTED_POINTER PRKPRCB;
  3158. //
  3159. // Processor Control Region Structure Definition
  3160. //
  3161. #define PCR_MINOR_VERSION 1
  3162. #define PCR_MAJOR_VERSION 1
  3163. typedef struct _KPCR {
  3164. //
  3165. // Start of the architecturally defined section of the PCR. This section
  3166. // may be directly addressed by vendor/platform specific HAL code and will
  3167. // not change from version to version of NT.
  3168. //
  3169. // Certain fields in the TIB are not used in kernel mode. These include the
  3170. // exception list, stack base, stack limit, subsystem TIB, fiber data, and
  3171. // the arbitrary user pointer. Therefore, these fields are overlaid with
  3172. // other data to get better cache locality.
  3173. union {
  3174. NT_TIB NtTib;
  3175. struct {
  3176. union _KGDTENTRY64 *GdtBase;
  3177. struct _KTSS64 *TssBase;
  3178. PVOID PerfGlobalGroupMask;
  3179. struct _KPCR *Self;
  3180. ULONG ContextSwitches;
  3181. ULONG NotUsed;
  3182. KAFFINITY SetMember;
  3183. PVOID Used_Self;
  3184. };
  3185. };
  3186. struct _KPRCB *CurrentPrcb;
  3187. ULONG64 SavedRcx;
  3188. ULONG64 SavedR11;
  3189. KIRQL Irql;
  3190. UCHAR SecondLevelCacheAssociativity;
  3191. UCHAR Number;
  3192. UCHAR Fill0;
  3193. ULONG Irr;
  3194. ULONG IrrActive;
  3195. ULONG Idr;
  3196. USHORT MajorVersion;
  3197. USHORT MinorVersion;
  3198. ULONG StallScaleFactor;
  3199. union _KIDTENTRY64 *IdtBase;
  3200. PVOID Unused1;
  3201. PVOID Unused2;
  3202. } KPCR, *PKPCR;
  3203. //
  3204. // Define legacy floating status word bit masks.
  3205. //
  3206. #define FSW_INVALID_OPERATION 0x1
  3207. #define FSW_DENORMAL 0x2
  3208. #define FSW_ZERO_DIVIDE 0x4
  3209. #define FSW_OVERFLOW 0x8
  3210. #define FSW_UNDERFLOW 0x10
  3211. #define FSW_PRECISION 0x20
  3212. #define FSW_STACK_FAULT 0x40
  3213. #define FSW_CONDITION_CODE_0 0x100
  3214. #define FSW_CONDITION_CODE_1 0x200
  3215. #define FSW_CONDITION_CODE_2 0x400
  3216. #define FSW_CONDITION_CODE_3 0x4000
  3217. #define FSW_ERROR_MASK (FSW_INVALID_OPERATION | FSW_DENORMAL | \
  3218. FSW_ZERO_DIVIDE | FSW_OVERFLOW | FSW_UNDERFLOW | \
  3219. FSW_PRECISION)
  3220. //
  3221. // Define legacy floating states.
  3222. //
  3223. #define LEGACY_STATE_UNUSED 0
  3224. #define LEGACY_STATE_SCRUB 1
  3225. #define LEGACY_STATE_SWITCH 2
  3226. //
  3227. // Define MxCsr floating control/status word bit masks.
  3228. //
  3229. // No flush to zero, round to nearest, and all exception masked.
  3230. //
  3231. #define XSW_INVALID_OPERATION 0x1
  3232. #define XSW_DENORMAL 0x2
  3233. #define XSW_ZERO_DIVIDE 0x4
  3234. #define XSW_OVERFLOW 0x8
  3235. #define XSW_UNDERFLOW 0x10
  3236. #define XSW_PRECISION 0x20
  3237. #define XSW_ERROR_MASK (XSW_INVALID_OPERATION | XSW_DENORMAL | \
  3238. XSW_ZERO_DIVIDE | XSW_OVERFLOW | XSW_UNDERFLOW | \
  3239. XSW_PRECISION)
  3240. #define XSW_ERROR_SHIFT 7
  3241. #define XCW_INVALID_OPERATION 0x80
  3242. #define XCW_DENORMAL 0x100
  3243. #define XCW_ZERO_DIVIDE 0x200
  3244. #define XCW_OVERFLOW 0x400
  3245. #define XCW_UNDERFLOW 0x800
  3246. #define XCW_PRECISION 0x1000
  3247. #define XCW_ROUND_CONTROL 0x6000
  3248. #define XCW_FLUSH_ZERO 0x8000
  3249. //
  3250. // Define EFLAG bit masks and shift offsets.
  3251. //
  3252. #define EFLAGS_CF_MASK 0x00000001 // carry flag
  3253. #define EFLAGS_PF_MASK 0x00000004 // parity flag
  3254. #define EFALGS_AF_MASK 0x00000010 // auxiliary carry flag
  3255. #define EFLAGS_ZF_MASK 0x00000040 // zero flag
  3256. #define EFLAGS_SF_MASK 0x00000080 // sign flag
  3257. #define EFLAGS_TF_MASK 0x00000100 // trap flag
  3258. #define EFLAGS_IF_MASK 0x00000200 // interrupt flag
  3259. #define EFLAGS_DF_MASK 0x00000400 // direction flag
  3260. #define EFLAGS_OF_MASK 0x00000800 // overflow flag
  3261. #define EFLAGS_IOPL_MASK 0x00003000 // I/O privilege level
  3262. #define EFLAGS_NT_MASK 0x00004000 // nested task
  3263. #define EFLAGS_RF_MASK 0x00010000 // resume flag
  3264. #define EFLAGS_VM_MASK 0x00020000 // virtual 8086 mode
  3265. #define EFLAGS_AC_MASK 0x00040000 // alignment check
  3266. #define EFLAGS_VIF_MASK 0x00080000 // virtual interrupt flag
  3267. #define EFLAGS_VIP_MASK 0x00100000 // virtual interrupt pending
  3268. #define EFLAGS_ID_MASK 0x00200000 // identification flag
  3269. #define EFLAGS_TF_SHIFT 8 // trap
  3270. #define EFLAGS_IF_SHIFT 9 // interrupt enable
  3271. // end_nthal
  3272. //
  3273. // Define sanitize EFLAGS macro.
  3274. //
  3275. // If kernel mode, then
  3276. // caller can specify Carry, Parity, AuxCarry, Zero, Sign, Trap,
  3277. // Interrupt, Direction, Overflow, and identification.
  3278. //
  3279. // If user mode, then
  3280. // caller can specify Carry, Parity, AuxCarry, Zero, Sign, Trap,
  3281. // Direction, Overflow, and force Interrupt on.
  3282. //
  3283. #define EFLAGS_KERNEL_SANITIZE 0x00210fd5L
  3284. #define EFLAGS_USER_SANITIZE 0x00010dd5L
  3285. #define SANITIZE_EFLAGS(eFlags, mode) ( \
  3286. ((mode) == KernelMode ? \
  3287. ((eFlags) & EFLAGS_KERNEL_SANITIZE) : \
  3288. (((eFlags) & EFLAGS_USER_SANITIZE) | EFLAGS_IF_MASK)))
  3289. //
  3290. // Define sanitize debug register macros.
  3291. //
  3292. // Define control register settable bits and active mask.
  3293. //
  3294. #define DR7_LEGAL 0xffff0155
  3295. #define DR7_ACTIVE 0x00000055
  3296. //
  3297. // Define macro to sanitize the debug control register.
  3298. //
  3299. #define SANITIZE_DR7(Dr7, mode) ((Dr7 & DR7_LEGAL));
  3300. //
  3301. // Define macro to santitize debug address registers.
  3302. //
  3303. #define SANITIZE_DRADDR(DrReg, mode) \
  3304. ((mode) == KernelMode ? \
  3305. (DrReg) : \
  3306. (((PVOID)(DrReg) <= MM_HIGHEST_USER_ADDRESS) ? (DrReg) : 0)) \
  3307. //
  3308. // Define macro to clear reserved bits from MXCSR.
  3309. //
  3310. #define SANITIZE_MXCSR(_mxcsr_) ((_mxcsr_) & 0xffbf)
  3311. //
  3312. // Define macro to clear reserved bits for legacy FP control word.
  3313. //
  3314. #define SANITIZE_FCW(_fcw_) ((_fcw_) & 0x1f37)
  3315. // begin_nthal begin_ntddk
  3316. //
  3317. // Exception frame
  3318. //
  3319. // This frame is established when handling an exception. It provides a place
  3320. // to save all nonvolatile registers. The volatile registers will already
  3321. // have been saved in a trap frame.
  3322. //
  3323. // N.B. The exception frame has a built in exception record capable of
  3324. // storing information for four parameter values. This exception
  3325. // record is used exclusively within the trap handling code.
  3326. //
  3327. #define EXCEPTION_AREA_SIZE 64
  3328. typedef struct _KEXCEPTION_FRAME {
  3329. //
  3330. // Home address for the parameter registers.
  3331. //
  3332. ULONG64 P1Home;
  3333. ULONG64 P2Home;
  3334. ULONG64 P3Home;
  3335. ULONG64 P4Home;
  3336. ULONG64 P5;
  3337. //
  3338. // Kernel callout initial stack value.
  3339. //
  3340. ULONG64 InitialStack;
  3341. //
  3342. // Saved nonvolatile floating registers.
  3343. //
  3344. M128 Xmm6;
  3345. M128 Xmm7;
  3346. M128 Xmm8;
  3347. M128 Xmm9;
  3348. M128 Xmm10;
  3349. M128 Xmm11;
  3350. M128 Xmm12;
  3351. M128 Xmm13;
  3352. M128 Xmm14;
  3353. M128 Xmm15;
  3354. //
  3355. // Kernel callout frame variables.
  3356. //
  3357. ULONG64 TrapFrame;
  3358. ULONG64 CallbackStack;
  3359. ULONG64 OutputBuffer;
  3360. ULONG64 OutputLength;
  3361. //
  3362. // Exception record for exceptions.
  3363. //
  3364. UCHAR ExceptionRecord[EXCEPTION_AREA_SIZE];
  3365. //
  3366. // Saved nonvolatile register - not always saved.
  3367. //
  3368. ULONG64 Fill1;
  3369. ULONG64 Rbp;
  3370. //
  3371. // Saved nonvolatile registers.
  3372. //
  3373. ULONG64 Rbx;
  3374. ULONG64 Rdi;
  3375. ULONG64 Rsi;
  3376. ULONG64 R12;
  3377. ULONG64 R13;
  3378. ULONG64 R14;
  3379. ULONG64 R15;
  3380. //
  3381. // EFLAGS and return address.
  3382. //
  3383. ULONG64 Return;
  3384. } KEXCEPTION_FRAME, *PKEXCEPTION_FRAME;
  3385. // end_ntddk
  3386. #define KEXCEPTION_FRAME_LENGTH sizeof(KEXCEPTION_FRAME)
  3387. C_ASSERT((sizeof(KEXCEPTION_FRAME) & STACK_ROUND) == 0);
  3388. #define EXCEPTION_RECORD_LENGTH \
  3389. ((sizeof(EXCEPTION_RECORD) + STACK_ROUND) & ~STACK_ROUND)
  3390. #if !defined(_X86AMD64_)
  3391. C_ASSERT(EXCEPTION_AREA_SIZE == (FIELD_OFFSET(EXCEPTION_RECORD, ExceptionInformation) + (4 * sizeof(ULONG_PTR))));
  3392. #endif
  3393. //
  3394. // Machine Frame
  3395. //
  3396. // This frame is established by code that trampolines to user mode (e.g. user
  3397. // APC, user callback, dispatch user exception, etc.). The purpose of this
  3398. // frame is to allow unwinding through these callbacks if an exception occurs.
  3399. //
  3400. // N.B. This frame is identical to the frame that is pushed for a trap without
  3401. // an error code and is identical to the hardware part of a trap frame.
  3402. //
  3403. typedef struct _MACHINE_FRAME {
  3404. ULONG64 Rip;
  3405. USHORT SegCs;
  3406. USHORT Fill1[3];
  3407. ULONG EFlags;
  3408. ULONG Fill2;
  3409. ULONG64 Rsp;
  3410. USHORT SegSs;
  3411. USHORT Fill3[3];
  3412. } MACHINE_FRAME, *PMACHINE_FRAME;
  3413. #define MACHINE_FRAME_LENGTH sizeof(MACHINE_FRAME)
  3414. C_ASSERT((sizeof(MACHINE_FRAME) & STACK_ROUND) == 8);
  3415. //
  3416. // Switch Frame
  3417. //
  3418. // This frame is established by the code that switches context from one
  3419. // thread to the next and is used by the thread initialization code to
  3420. // construct a stack that will start the execution of a thread in the
  3421. // thread start up code.
  3422. //
  3423. typedef struct _KSWITCH_FRAME {
  3424. ULONG64 P1Home;
  3425. ULONG64 P2Home;
  3426. ULONG64 P3Home;
  3427. ULONG64 P4Home;
  3428. ULONG64 P5Home;
  3429. ULONG MxCsr;
  3430. KIRQL ApcBypass;
  3431. UCHAR Fill1[3];
  3432. ULONG64 Rbp;
  3433. ULONG64 Return;
  3434. } KSWITCH_FRAME, *PKSWITCH_FRAME;
  3435. #define KSWITCH_FRAME_LENGTH sizeof(KSWITCH_FRAME)
  3436. C_ASSERT((sizeof(KSWITCH_FRAME) & STACK_ROUND) == 0);
  3437. //
  3438. // Start system thread frame.
  3439. //
  3440. // This frame is established by the AMD64 specific thread initialization
  3441. // code. It is used to store the initial context for starting a system
  3442. // thread.
  3443. //
  3444. typedef struct _KSTART_FRAME {
  3445. ULONG64 P1Home;
  3446. ULONG64 P2Home;
  3447. ULONG64 P3Home;
  3448. ULONG64 Return;
  3449. } KSTART_FRAME, *PKSTART_FRAME;
  3450. #define KSTART_FRAME_LENGTH sizeof(KSTART_FRAME)
  3451. C_ASSERT((sizeof(KSTART_FRAME) & STACK_ROUND) == 0);
  3452. // begin_ntddk
  3453. //
  3454. // Trap frame
  3455. //
  3456. // This frame is established when handling a trap. It provides a place to
  3457. // save all volatile registers. The nonvolatile registers are saved in an
  3458. // exception frame or through the normal C calling conventions for saved
  3459. // registers.
  3460. //
  3461. typedef struct _KTRAP_FRAME {
  3462. //
  3463. // Home address for the parameter registers.
  3464. //
  3465. ULONG64 P1Home;
  3466. ULONG64 P2Home;
  3467. ULONG64 P3Home;
  3468. ULONG64 P4Home;
  3469. ULONG64 P5;
  3470. //
  3471. // Previous processor mode (system services only) and previous IRQL
  3472. // (interrupts only).
  3473. //
  3474. KPROCESSOR_MODE PreviousMode;
  3475. KIRQL PreviousIrql;
  3476. //
  3477. // Page fault load/store indicator.
  3478. //
  3479. UCHAR FaultIndicator;
  3480. UCHAR Fill0;
  3481. //
  3482. // Floating point state.
  3483. //
  3484. ULONG MxCsr;
  3485. //
  3486. // Volatile registers.
  3487. //
  3488. // N.B. These registers are only saved on exceptions and interrupts. They
  3489. // are not saved for system calls.
  3490. //
  3491. ULONG64 Rax;
  3492. ULONG64 Rcx;
  3493. ULONG64 Rdx;
  3494. ULONG64 R8;
  3495. ULONG64 R9;
  3496. ULONG64 R10;
  3497. ULONG64 R11;
  3498. ULONG64 Spare0;
  3499. //
  3500. // Volatile floating registers.
  3501. //
  3502. // N.B. These registers are only saved on exceptions and interrupts. They
  3503. // are not saved for system calls.
  3504. //
  3505. M128 Xmm0;
  3506. M128 Xmm1;
  3507. M128 Xmm2;
  3508. M128 Xmm3;
  3509. M128 Xmm4;
  3510. M128 Xmm5;
  3511. //
  3512. // Page fault address.
  3513. //
  3514. ULONG64 FaultAddress;
  3515. //
  3516. // Debug registers.
  3517. //
  3518. ULONG64 Dr0;
  3519. ULONG64 Dr1;
  3520. ULONG64 Dr2;
  3521. ULONG64 Dr3;
  3522. ULONG64 Dr6;
  3523. ULONG64 Dr7;
  3524. //
  3525. // Special debug registers.
  3526. //
  3527. ULONG64 DebugControl;
  3528. ULONG64 LastBranchToRip;
  3529. ULONG64 LastBranchFromRip;
  3530. ULONG64 LastExceptionToRip;
  3531. ULONG64 LastExceptionFromRip;
  3532. //
  3533. // Segment registers
  3534. //
  3535. USHORT SegDs;
  3536. USHORT SegEs;
  3537. USHORT SegFs;
  3538. USHORT SegGs;
  3539. //
  3540. // Previous trap frame address.
  3541. //
  3542. ULONG64 TrapFrame;
  3543. //
  3544. // Saved nonvolatile registers RBX, RDI and RSI. These registers are only
  3545. // saved in system service trap frames.
  3546. //
  3547. ULONG64 Rbx;
  3548. ULONG64 Rdi;
  3549. ULONG64 Rsi;
  3550. //
  3551. // Saved nonvolatile register RBP. This register is used as a frame
  3552. // pointer during trap processing and is saved in all trap frames.
  3553. //
  3554. ULONG64 Rbp;
  3555. //
  3556. // Information pushed by hardware.
  3557. //
  3558. // N.B. The error code is not always pushed by hardware. For those cases
  3559. // where it is not pushed by hardware a dummy error code is allocated
  3560. // on the stack.
  3561. //
  3562. ULONG64 ErrorCode;
  3563. ULONG64 Rip;
  3564. USHORT SegCs;
  3565. USHORT Fill1[3];
  3566. ULONG EFlags;
  3567. ULONG Fill2;
  3568. ULONG64 Rsp;
  3569. USHORT SegSs;
  3570. USHORT Fill3[3];
  3571. } KTRAP_FRAME, *PKTRAP_FRAME;
  3572. // end_ntddk
  3573. #define KTRAP_FRAME_LENGTH sizeof(KTRAP_FRAME)
  3574. C_ASSERT((sizeof(KTRAP_FRAME) & STACK_ROUND) == 0);
  3575. //
  3576. // IPI, profile, update run time, and update system time interrupt routines.
  3577. //
  3578. NTKERNELAPI
  3579. VOID
  3580. KeIpiInterrupt (
  3581. IN PKTRAP_FRAME TrapFrame
  3582. );
  3583. NTKERNELAPI
  3584. VOID
  3585. KeProfileInterruptWithSource (
  3586. IN PKTRAP_FRAME TrapFrame,
  3587. IN KPROFILE_SOURCE ProfileSource
  3588. );
  3589. NTKERNELAPI
  3590. VOID
  3591. KeUpdateRunTime (
  3592. IN PKTRAP_FRAME TrapFrame
  3593. );
  3594. NTKERNELAPI
  3595. VOID
  3596. KeUpdateSystemTime (
  3597. IN PKTRAP_FRAME TrapFrame,
  3598. IN ULONG64 Increment
  3599. );
  3600. // end_nthal
  3601. //
  3602. // The frame saved by the call out to user mode code is defined here to allow
  3603. // the kernel debugger to trace the entire kernel stack when user mode callouts
  3604. // are active.
  3605. //
  3606. // N.B. The kernel callout frame is the same as an exception frame.
  3607. //
  3608. typedef KEXCEPTION_FRAME KCALLOUT_FRAME;
  3609. typedef PKEXCEPTION_FRAME PKCALLOUT_FRAME;
  3610. typedef struct _UCALLOUT_FRAME {
  3611. ULONG64 P1Home;
  3612. ULONG64 P2Home;
  3613. ULONG64 P3Home;
  3614. ULONG64 P4Home;
  3615. PVOID Buffer;
  3616. ULONG Length;
  3617. ULONG ApiNumber;
  3618. MACHINE_FRAME MachineFrame;
  3619. } UCALLOUT_FRAME, *PUCALLOUT_FRAME;
  3620. #define UCALLOUT_FRAME_LENGTH sizeof(UCALLOUT_FRAME)
  3621. C_ASSERT((sizeof(UCALLOUT_FRAME) & STACK_ROUND) == 8);
  3622. // begin_ntddk begin_wdm
  3623. //
  3624. // The nonvolatile floating state
  3625. //
  3626. typedef struct _KFLOATING_SAVE {
  3627. ULONG MxCsr;
  3628. } KFLOATING_SAVE, *PKFLOATING_SAVE;
  3629. //
  3630. // AMD64 Specific portions of mm component.
  3631. //
  3632. // Define the page size for the AMD64 as 4096 (0x1000).
  3633. //
  3634. #define PAGE_SIZE 0x1000
  3635. //
  3636. // Define the number of trailing zeroes in a page aligned virtual address.
  3637. // This is used as the shift count when shifting virtual addresses to
  3638. // virtual page numbers.
  3639. //
  3640. #define PAGE_SHIFT 12L
  3641. // end_ntndis end_wdm
  3642. #define PXE_BASE 0xFFFFF6FB7DBED000UI64
  3643. #define PXE_SELFMAP 0xFFFFF6FB7DBEDF68UI64
  3644. #define PPE_BASE 0xFFFFF6FB7DA00000UI64
  3645. #define PDE_BASE 0xFFFFF6FB40000000UI64
  3646. #define PTE_BASE 0xFFFFF68000000000UI64
  3647. #define PXE_TOP 0xFFFFF6FB7DBEDFFFUI64
  3648. #define PPE_TOP 0xFFFFF6FB7DBFFFFFUI64
  3649. #define PDE_TOP 0xFFFFF6FB7FFFFFFFUI64
  3650. #define PTE_TOP 0xFFFFF6FFFFFFFFFFUI64
  3651. #define PDE_KTBASE_AMD64 PPE_BASE
  3652. #define PTI_SHIFT 12
  3653. #define PDI_SHIFT 21
  3654. #define PPI_SHIFT 30
  3655. #define PXI_SHIFT 39
  3656. #define PTE_PER_PAGE 512
  3657. #define PDE_PER_PAGE 512
  3658. #define PPE_PER_PAGE 512
  3659. #define PXE_PER_PAGE 512
  3660. #define PTI_MASK_AMD64 (PTE_PER_PAGE - 1)
  3661. #define PDI_MASK_AMD64 (PDE_PER_PAGE - 1)
  3662. #define PPI_MASK (PPE_PER_PAGE - 1)
  3663. #define PXI_MASK (PXE_PER_PAGE - 1)
  3664. //
  3665. // Define the highest user address and user probe address.
  3666. //
  3667. extern PVOID *MmHighestUserAddress;
  3668. extern PVOID *MmSystemRangeStart;
  3669. extern ULONG64 *MmUserProbeAddress;
  3670. #define MM_HIGHEST_USER_ADDRESS *MmHighestUserAddress
  3671. #define MM_SYSTEM_RANGE_START *MmSystemRangeStart
  3672. #define MM_USER_PROBE_ADDRESS *MmUserProbeAddress
  3673. //
  3674. // The lowest user address reserves the low 64k.
  3675. //
  3676. #define MM_LOWEST_USER_ADDRESS (PVOID)0x10000
  3677. //
  3678. // The lowest address for system space.
  3679. //
  3680. #define MM_LOWEST_SYSTEM_ADDRESS (PVOID)0xFFFF080000000000
  3681. // begin_wdm
  3682. #define MmGetProcedureAddress(Address) (Address)
  3683. #define MmLockPagableCodeSection(Address) MmLockPagableDataSection(Address)
  3684. //
  3685. // Intrinsic functions
  3686. //
  3687. // begin_wdm
  3688. #if defined(_M_AMD64) && !defined(RC_INVOKED) && !defined(MIDL_PASS)
  3689. // end_wdm
  3690. //
  3691. // The following routines are provided for backward compatibility with old
  3692. // code. They are no longer the preferred way to accomplish these functions.
  3693. //
  3694. #if PRAGMA_DEPRECATED_DDK
  3695. #pragma deprecated(ExInterlockedIncrementLong) // Use InterlockedIncrement
  3696. #pragma deprecated(ExInterlockedDecrementLong) // Use InterlockedDecrement
  3697. #pragma deprecated(ExInterlockedExchangeUlong) // Use InterlockedExchange
  3698. #endif
  3699. #define RESULT_ZERO 0
  3700. #define RESULT_NEGATIVE 1
  3701. #define RESULT_POSITIVE 2
  3702. typedef enum _INTERLOCKED_RESULT {
  3703. ResultNegative = RESULT_NEGATIVE,
  3704. ResultZero = RESULT_ZERO,
  3705. ResultPositive = RESULT_POSITIVE
  3706. } INTERLOCKED_RESULT;
  3707. #define ExInterlockedDecrementLong(Addend, Lock) \
  3708. _ExInterlockedDecrementLong(Addend)
  3709. __forceinline
  3710. LONG
  3711. _ExInterlockedDecrementLong (
  3712. IN OUT PLONG Addend
  3713. )
  3714. {
  3715. LONG Result;
  3716. Result = InterlockedDecrement(Addend);
  3717. if (Result < 0) {
  3718. return ResultNegative;
  3719. } else if (Result > 0) {
  3720. return ResultPositive;
  3721. } else {
  3722. return ResultZero;
  3723. }
  3724. }
  3725. #define ExInterlockedIncrementLong(Addend, Lock) \
  3726. _ExInterlockedIncrementLong(Addend)
  3727. __forceinline
  3728. LONG
  3729. _ExInterlockedIncrementLong (
  3730. IN OUT PLONG Addend
  3731. )
  3732. {
  3733. LONG Result;
  3734. Result = InterlockedIncrement(Addend);
  3735. if (Result < 0) {
  3736. return ResultNegative;
  3737. } else if (Result > 0) {
  3738. return ResultPositive;
  3739. } else {
  3740. return ResultZero;
  3741. }
  3742. }
  3743. #define ExInterlockedExchangeUlong(Target, Value, Lock) \
  3744. _ExInterlockedExchangeUlong(Target, Value)
  3745. __forceinline
  3746. _ExInterlockedExchangeUlong (
  3747. IN OUT PULONG Target,
  3748. IN ULONG Value
  3749. )
  3750. {
  3751. return (ULONG)InterlockedExchange((PLONG)Target, (LONG)Value);
  3752. }
  3753. // begin_wdm
  3754. #endif // defined(_M_AMD64) && !defined(RC_INVOKED) && !defined(MIDL_PASS)
  3755. #if !defined(MIDL_PASS) && defined(_M_AMD64)
  3756. //
  3757. // AMD646 function prototype definitions
  3758. //
  3759. // end_wdm
  3760. //
  3761. // Get address of current processor block.
  3762. //
  3763. __forceinline
  3764. PKPRCB
  3765. KeGetCurrentPrcb (
  3766. VOID
  3767. )
  3768. {
  3769. return (PKPRCB)__readgsqword(FIELD_OFFSET(KPCR, CurrentPrcb));
  3770. }
  3771. // begin_ntddk
  3772. //
  3773. // Get the current processor number
  3774. //
  3775. __forceinline
  3776. ULONG
  3777. KeGetCurrentProcessorNumber (
  3778. VOID
  3779. )
  3780. {
  3781. return (ULONG)__readgsbyte(FIELD_OFFSET(KPCR, Number));
  3782. }
  3783. // begin_wdm
  3784. #endif // !defined(MIDL_PASS) && defined(_M_AMD64)
  3785. //++
  3786. //
  3787. //
  3788. // VOID
  3789. // KeMemoryBarrier (
  3790. // VOID
  3791. // )
  3792. //
  3793. // VOID
  3794. // KeMemoryBarrierWithoutFence (
  3795. // VOID
  3796. // )
  3797. //
  3798. //
  3799. // Routine Description:
  3800. //
  3801. // These functions order memory accesses as seen by other processors.
  3802. //
  3803. // Arguments:
  3804. //
  3805. // None.
  3806. //
  3807. // Return Value:
  3808. //
  3809. // None.
  3810. //
  3811. //--
  3812. #if !defined(_CROSS_PLATFORM_)
  3813. #ifdef __cplusplus
  3814. extern "C" {
  3815. #endif
  3816. VOID
  3817. _ReadWriteBarrier (
  3818. VOID
  3819. );
  3820. #pragma intrinsic(_ReadWriteBarrier)
  3821. #ifdef __cplusplus
  3822. }
  3823. #endif
  3824. #define KeMemoryBarrier() _ReadWriteBarrier()
  3825. #define KeMemoryBarrierWithoutFence() _ReadWriteBarrier()
  3826. #else
  3827. #define KeMemoryBarrier()
  3828. #define KeMemoryBarrierWithoutFence()
  3829. #endif
  3830. NTKERNELAPI
  3831. NTSTATUS
  3832. KeSaveFloatingPointState (
  3833. OUT PKFLOATING_SAVE SaveArea
  3834. );
  3835. NTKERNELAPI
  3836. NTSTATUS
  3837. KeRestoreFloatingPointState (
  3838. IN PKFLOATING_SAVE SaveArea
  3839. );
  3840. #endif // defined(_AMD64_)
  3841. //
  3842. // Platform specific kernel fucntions to raise and lower IRQL.
  3843. //
  3844. // These functions are imported for ntddk, ntifs, and wdm. They are
  3845. // inlined for nthal, ntosp, and the system.
  3846. //
  3847. #if defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_) || defined(_WDMDDK_)
  3848. // begin_ntddk begin_wdm
  3849. #if defined(_AMD64_)
  3850. NTKERNELAPI
  3851. KIRQL
  3852. KeGetCurrentIrql (
  3853. VOID
  3854. );
  3855. NTKERNELAPI
  3856. VOID
  3857. KeLowerIrql (
  3858. IN KIRQL NewIrql
  3859. );
  3860. #define KeRaiseIrql(a,b) *(b) = KfRaiseIrql(a)
  3861. NTKERNELAPI
  3862. KIRQL
  3863. KfRaiseIrql (
  3864. IN KIRQL NewIrql
  3865. );
  3866. // end_wdm
  3867. NTKERNELAPI
  3868. KIRQL
  3869. KeRaiseIrqlToDpcLevel (
  3870. VOID
  3871. );
  3872. NTKERNELAPI
  3873. KIRQL
  3874. KeRaiseIrqlToSynchLevel (
  3875. VOID
  3876. );
  3877. // begin_wdm
  3878. #endif // defined(_AMD64_)
  3879. // end_ntddk end_wdm
  3880. #else
  3881. // begin_nthal
  3882. #if defined(_AMD64_) && !defined(MIDL_PASS)
  3883. __forceinline
  3884. KIRQL
  3885. KeGetCurrentIrql (
  3886. VOID
  3887. )
  3888. /*++
  3889. Routine Description:
  3890. This function return the current IRQL.
  3891. Arguments:
  3892. None.
  3893. Return Value:
  3894. The current IRQL is returned as the function value.
  3895. --*/
  3896. {
  3897. return (KIRQL)ReadCR8();
  3898. }
  3899. __forceinline
  3900. VOID
  3901. KeLowerIrql (
  3902. IN KIRQL NewIrql
  3903. )
  3904. /*++
  3905. Routine Description:
  3906. This function lowers the IRQL to the specified value.
  3907. Arguments:
  3908. NewIrql - Supplies the new IRQL value.
  3909. Return Value:
  3910. None.
  3911. --*/
  3912. {
  3913. ASSERT(KeGetCurrentIrql() >= NewIrql);
  3914. WriteCR8(NewIrql);
  3915. return;
  3916. }
  3917. #define KeRaiseIrql(a,b) *(b) = KfRaiseIrql(a)
  3918. __forceinline
  3919. KIRQL
  3920. KfRaiseIrql (
  3921. IN KIRQL NewIrql
  3922. )
  3923. /*++
  3924. Routine Description:
  3925. This function raises the current IRQL to the specified value and returns
  3926. the previous IRQL.
  3927. Arguments:
  3928. NewIrql (cl) - Supplies the new IRQL value.
  3929. Return Value:
  3930. The previous IRQL is retured as the function value.
  3931. --*/
  3932. {
  3933. KIRQL OldIrql;
  3934. OldIrql = KeGetCurrentIrql();
  3935. ASSERT(OldIrql <= NewIrql);
  3936. WriteCR8(NewIrql);
  3937. return OldIrql;
  3938. }
  3939. __forceinline
  3940. KIRQL
  3941. KeRaiseIrqlToDpcLevel (
  3942. VOID
  3943. )
  3944. /*++
  3945. Routine Description:
  3946. This function raises the current IRQL to DPC_LEVEL and returns the
  3947. previous IRQL.
  3948. Arguments:
  3949. None.
  3950. Return Value:
  3951. The previous IRQL is retured as the function value.
  3952. --*/
  3953. {
  3954. KIRQL OldIrql;
  3955. OldIrql = KeGetCurrentIrql();
  3956. ASSERT(OldIrql <= DISPATCH_LEVEL);
  3957. WriteCR8(DISPATCH_LEVEL);
  3958. return OldIrql;
  3959. }
  3960. __forceinline
  3961. KIRQL
  3962. KeRaiseIrqlToSynchLevel (
  3963. VOID
  3964. )
  3965. /*++
  3966. Routine Description:
  3967. This function raises the current IRQL to SYNCH_LEVEL and returns the
  3968. previous IRQL.
  3969. Arguments:
  3970. Return Value:
  3971. The previous IRQL is retured as the function value.
  3972. --*/
  3973. {
  3974. KIRQL OldIrql;
  3975. OldIrql = KeGetCurrentIrql();
  3976. ASSERT(OldIrql <= SYNCH_LEVEL);
  3977. WriteCR8(SYNCH_LEVEL);
  3978. return OldIrql;
  3979. }
  3980. #endif // defined(_AMD64_) && !defined(MIDL_PASS)
  3981. // end_nthal
  3982. #endif // defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_) || defined(_WDMDDK_)
  3983. #if defined(_IA64_)
  3984. //
  3985. // Types to use to contain PFNs and their counts.
  3986. //
  3987. typedef ULONG PFN_COUNT;
  3988. typedef LONG_PTR SPFN_NUMBER, *PSPFN_NUMBER;
  3989. typedef ULONG_PTR PFN_NUMBER, *PPFN_NUMBER;
  3990. //
  3991. // Indicate that the IA64 compiler supports the pragma textout construct.
  3992. //
  3993. #define ALLOC_PRAGMA 1
  3994. //
  3995. // Define intrinsic calls and their prototypes
  3996. //
  3997. #include "ia64reg.h"
  3998. #ifdef __cplusplus
  3999. extern "C" {
  4000. #endif
  4001. unsigned __int64 __getReg (int);
  4002. void __setReg (int, unsigned __int64);
  4003. void __isrlz (void);
  4004. void __dsrlz (void);
  4005. void __fwb (void);
  4006. void __mf (void);
  4007. void __mfa (void);
  4008. void __synci (void);
  4009. __int64 __thash (__int64);
  4010. __int64 __ttag (__int64);
  4011. void __ptcl (__int64, __int64);
  4012. void __ptcg (__int64, __int64);
  4013. void __ptcga (__int64, __int64);
  4014. void __ptri (__int64, __int64);
  4015. void __ptrd (__int64, __int64);
  4016. void __invalat (void);
  4017. void __break (int);
  4018. void __fc (__int64);
  4019. void __fci (__int64);
  4020. void __sum (int);
  4021. void __rsm (int);
  4022. void _ReleaseSpinLock( unsigned __int64 *);
  4023. void __yield();
  4024. void __lfetch(int, void const *);
  4025. void __lfetchfault(int, void const *);
  4026. #ifdef _M_IA64
  4027. #pragma intrinsic (__getReg)
  4028. #pragma intrinsic (__setReg)
  4029. #pragma intrinsic (__isrlz)
  4030. #pragma intrinsic (__dsrlz)
  4031. #pragma intrinsic (__fwb)
  4032. #pragma intrinsic (__mf)
  4033. #pragma intrinsic (__mfa)
  4034. #pragma intrinsic (__synci)
  4035. #pragma intrinsic (__thash)
  4036. #pragma intrinsic (__ttag)
  4037. #pragma intrinsic (__ptcl)
  4038. #pragma intrinsic (__ptcg)
  4039. #pragma intrinsic (__ptcga)
  4040. #pragma intrinsic (__ptri)
  4041. #pragma intrinsic (__ptrd)
  4042. #pragma intrinsic (__invalat)
  4043. #pragma intrinsic (__break)
  4044. #pragma intrinsic (__fc)
  4045. #pragma intrinsic (__fci)
  4046. #pragma intrinsic (__sum)
  4047. #pragma intrinsic (__rsm)
  4048. #pragma intrinsic (_ReleaseSpinLock)
  4049. #pragma intrinsic (__yield)
  4050. #pragma intrinsic (__lfetch)
  4051. #pragma intrinsic (__lfetchfault)
  4052. #endif // _M_IA64
  4053. #ifdef __cplusplus
  4054. }
  4055. #endif
  4056. // end_ntndis
  4057. //
  4058. // Define length of interrupt vector table.
  4059. //
  4060. #define MAXIMUM_VECTOR 256
  4061. // end_wdm
  4062. //
  4063. // IA64 specific interlocked operation result values.
  4064. //
  4065. #define RESULT_ZERO 0
  4066. #define RESULT_NEGATIVE 1
  4067. #define RESULT_POSITIVE 2
  4068. //
  4069. // Interlocked result type is portable, but its values are machine specific.
  4070. // Constants for values are in i386.h, mips.h, etc.
  4071. //
  4072. typedef enum _INTERLOCKED_RESULT {
  4073. ResultNegative = RESULT_NEGATIVE,
  4074. ResultZero = RESULT_ZERO,
  4075. ResultPositive = RESULT_POSITIVE
  4076. } INTERLOCKED_RESULT;
  4077. //
  4078. // Convert portable interlock interfaces to architecture specific interfaces.
  4079. //
  4080. #if PRAGMA_DEPRECATED_DDK
  4081. #pragma deprecated(ExInterlockedIncrementLong) // Use InterlockedIncrement
  4082. #pragma deprecated(ExInterlockedDecrementLong) // Use InterlockedDecrement
  4083. #pragma deprecated(ExInterlockedExchangeUlong) // Use InterlockedExchange
  4084. #endif
  4085. #define ExInterlockedIncrementLong(Addend, Lock) \
  4086. ExIa64InterlockedIncrementLong(Addend)
  4087. #define ExInterlockedDecrementLong(Addend, Lock) \
  4088. ExIa64InterlockedDecrementLong(Addend)
  4089. #define ExInterlockedExchangeUlong(Target, Value, Lock) \
  4090. ExIa64InterlockedExchangeUlong(Target, Value)
  4091. NTKERNELAPI
  4092. INTERLOCKED_RESULT
  4093. ExIa64InterlockedIncrementLong (
  4094. IN PLONG Addend
  4095. );
  4096. NTKERNELAPI
  4097. INTERLOCKED_RESULT
  4098. ExIa64InterlockedDecrementLong (
  4099. IN PLONG Addend
  4100. );
  4101. NTKERNELAPI
  4102. ULONG
  4103. ExIa64InterlockedExchangeUlong (
  4104. IN PULONG Target,
  4105. IN ULONG Value
  4106. );
  4107. // begin_wdm
  4108. //
  4109. // IA64 Interrupt Definitions.
  4110. //
  4111. //
  4112. // Define length of interrupt object dispatch code in longwords.
  4113. //
  4114. #define DISPATCH_LENGTH 2*2 // Length of dispatch code template in 32-bit words
  4115. // Begin of a block of definitions that must be synchronized with kxia64.h.
  4116. //
  4117. //
  4118. // Define Interrupt Request Levels.
  4119. //
  4120. #define PASSIVE_LEVEL 0 // Passive release level
  4121. #define LOW_LEVEL 0 // Lowest interrupt level
  4122. #define APC_LEVEL 1 // APC interrupt level
  4123. #define DISPATCH_LEVEL 2 // Dispatcher level
  4124. #define CMC_LEVEL 3 // Correctable machine check level
  4125. #define DEVICE_LEVEL_BASE 4 // 4 - 11 - Device IRQLs
  4126. #define PC_LEVEL 12 // Performance Counter IRQL
  4127. #define IPI_LEVEL 14 // IPI IRQL
  4128. #define CLOCK_LEVEL 13 // Clock Timer IRQL
  4129. #define POWER_LEVEL 15 // Power failure level
  4130. #define PROFILE_LEVEL 15 // Profiling level
  4131. #define HIGH_LEVEL 15 // Highest interrupt level
  4132. #if defined(_M_IA64) && !defined(RC_INVOKED)
  4133. #define InterlockedAdd _InterlockedAdd
  4134. #define InterlockedIncrement _InterlockedIncrement
  4135. #define InterlockedIncrementAcquire _InterlockedIncrement_acq
  4136. #define InterlockedIncrementRelease _InterlockedIncrement_rel
  4137. #define InterlockedDecrement _InterlockedDecrement
  4138. #define InterlockedDecrementAcquire _InterlockedDecrement_acq
  4139. #define InterlockedDecrementRelease _InterlockedDecrement_rel
  4140. #define InterlockedExchange _InterlockedExchange
  4141. #define InterlockedExchangeAdd _InterlockedExchangeAdd
  4142. #define InterlockedAdd64 _InterlockedAdd64
  4143. #define InterlockedIncrement64 _InterlockedIncrement64
  4144. #define InterlockedDecrement64 _InterlockedDecrement64
  4145. #define InterlockedExchange64 _InterlockedExchange64
  4146. #define InterlockedExchangeAcquire64 _InterlockedExchange64_acq
  4147. #define InterlockedExchangeAdd64 _InterlockedExchangeAdd64
  4148. #define InterlockedCompareExchange64 _InterlockedCompareExchange64
  4149. #define InterlockedCompareExchangeAcquire64 _InterlockedCompareExchange64_acq
  4150. #define InterlockedCompareExchangeRelease64 _InterlockedCompareExchange64_rel
  4151. #define InterlockedCompareExchange _InterlockedCompareExchange
  4152. #define InterlockedCompareExchangeAcquire _InterlockedCompareExchange_acq
  4153. #define InterlockedCompareExchangeRelease _InterlockedCompareExchange_rel
  4154. #define InterlockedExchangePointer _InterlockedExchangePointer
  4155. #define InterlockedCompareExchangePointer _InterlockedCompareExchangePointer
  4156. #ifdef __cplusplus
  4157. extern "C" {
  4158. #endif
  4159. LONG
  4160. __cdecl
  4161. InterlockedAdd (
  4162. LONG volatile *Addend,
  4163. LONG Value
  4164. );
  4165. LONGLONG
  4166. __cdecl
  4167. InterlockedAdd64 (
  4168. LONGLONG volatile *Addend,
  4169. LONGLONG Value
  4170. );
  4171. LONG
  4172. __cdecl
  4173. InterlockedIncrement(
  4174. IN OUT LONG volatile *Addend
  4175. );
  4176. LONG
  4177. __cdecl
  4178. InterlockedDecrement(
  4179. IN OUT LONG volatile *Addend
  4180. );
  4181. LONG
  4182. __cdecl
  4183. InterlockedIncrementAcquire(
  4184. IN OUT LONG volatile *Addend
  4185. );
  4186. LONG
  4187. __cdecl
  4188. InterlockedDecrementAcquire(
  4189. IN OUT LONG volatile *Addend
  4190. );
  4191. LONG
  4192. __cdecl
  4193. InterlockedIncrementRelease(
  4194. IN OUT LONG volatile *Addend
  4195. );
  4196. LONG
  4197. __cdecl
  4198. InterlockedDecrementRelease(
  4199. IN OUT LONG volatile *Addend
  4200. );
  4201. LONG
  4202. __cdecl
  4203. InterlockedExchange(
  4204. IN OUT LONG volatile *Target,
  4205. IN LONG Value
  4206. );
  4207. LONG
  4208. __cdecl
  4209. InterlockedExchangeAdd(
  4210. IN OUT LONG volatile *Addend,
  4211. IN LONG Value
  4212. );
  4213. LONG
  4214. __cdecl
  4215. InterlockedCompareExchange (
  4216. IN OUT LONG volatile *Destination,
  4217. IN LONG ExChange,
  4218. IN LONG Comperand
  4219. );
  4220. LONG
  4221. __cdecl
  4222. InterlockedCompareExchangeRelease (
  4223. IN OUT LONG volatile *Destination,
  4224. IN LONG ExChange,
  4225. IN LONG Comperand
  4226. );
  4227. LONG
  4228. __cdecl
  4229. InterlockedCompareExchangeAcquire (
  4230. IN OUT LONG volatile *Destination,
  4231. IN LONG ExChange,
  4232. IN LONG Comperand
  4233. );
  4234. LONGLONG
  4235. __cdecl
  4236. InterlockedIncrement64(
  4237. IN OUT LONGLONG volatile *Addend
  4238. );
  4239. LONGLONG
  4240. __cdecl
  4241. InterlockedDecrement64(
  4242. IN OUT LONGLONG volatile *Addend
  4243. );
  4244. LONGLONG
  4245. __cdecl
  4246. InterlockedExchange64(
  4247. IN OUT LONGLONG volatile *Target,
  4248. IN LONGLONG Value
  4249. );
  4250. LONGLONG
  4251. __cdecl
  4252. InterlockedExchangeAcquire64(
  4253. IN OUT LONGLONG volatile *Target,
  4254. IN LONGLONG Value
  4255. );
  4256. LONGLONG
  4257. __cdecl
  4258. InterlockedExchangeAdd64(
  4259. IN OUT LONGLONG volatile *Addend,
  4260. IN LONGLONG Value
  4261. );
  4262. LONGLONG
  4263. __cdecl
  4264. InterlockedCompareExchange64 (
  4265. IN OUT LONGLONG volatile *Destination,
  4266. IN LONGLONG ExChange,
  4267. IN LONGLONG Comperand
  4268. );
  4269. LONGLONG
  4270. __cdecl
  4271. InterlockedCompareExchangeAcquire64 (
  4272. IN OUT LONGLONG volatile *Destination,
  4273. IN LONGLONG ExChange,
  4274. IN LONGLONG Comperand
  4275. );
  4276. LONGLONG
  4277. __cdecl
  4278. InterlockedCompareExchangeRelease64 (
  4279. IN OUT LONGLONG volatile *Destination,
  4280. IN LONGLONG ExChange,
  4281. IN LONGLONG Comperand
  4282. );
  4283. PVOID
  4284. __cdecl
  4285. InterlockedCompareExchangePointer (
  4286. IN OUT PVOID volatile *Destination,
  4287. IN PVOID Exchange,
  4288. IN PVOID Comperand
  4289. );
  4290. PVOID
  4291. __cdecl
  4292. InterlockedExchangePointer(
  4293. IN OUT PVOID volatile *Target,
  4294. IN PVOID Value
  4295. );
  4296. #if !defined (InterlockedAnd64)
  4297. #define InterlockedAnd64 InterlockedAnd64_Inline
  4298. LONGLONG
  4299. FORCEINLINE
  4300. InterlockedAnd64_Inline (
  4301. IN OUT LONGLONG volatile *Destination,
  4302. IN LONGLONG Value
  4303. )
  4304. {
  4305. LONGLONG Old;
  4306. do {
  4307. Old = *Destination;
  4308. } while (InterlockedCompareExchange64(Destination,
  4309. Old & Value,
  4310. Old) != Old);
  4311. return Old;
  4312. }
  4313. #endif
  4314. #if !defined (InterlockedOr64)
  4315. #define InterlockedOr64 InterlockedOr64_Inline
  4316. LONGLONG
  4317. FORCEINLINE
  4318. InterlockedOr64_Inline (
  4319. IN OUT LONGLONG volatile *Destination,
  4320. IN LONGLONG Value
  4321. )
  4322. {
  4323. LONGLONG Old;
  4324. do {
  4325. Old = *Destination;
  4326. } while (InterlockedCompareExchange64(Destination,
  4327. Old | Value,
  4328. Old) != Old);
  4329. return Old;
  4330. }
  4331. #endif
  4332. #if !defined (InterlockedXor64)
  4333. #define InterlockedXor64 InterlockedXor64_Inline
  4334. LONGLONG
  4335. FORCEINLINE
  4336. InterlockedXor64_Inline (
  4337. IN OUT LONGLONG volatile *Destination,
  4338. IN LONGLONG Value
  4339. )
  4340. {
  4341. LONGLONG Old;
  4342. do {
  4343. Old = *Destination;
  4344. } while (InterlockedCompareExchange64(Destination,
  4345. Old ^ Value,
  4346. Old) != Old);
  4347. return Old;
  4348. }
  4349. #endif
  4350. #pragma intrinsic(_InterlockedAdd)
  4351. #pragma intrinsic(_InterlockedIncrement)
  4352. #pragma intrinsic(_InterlockedIncrement_acq)
  4353. #pragma intrinsic(_InterlockedIncrement_rel)
  4354. #pragma intrinsic(_InterlockedDecrement)
  4355. #pragma intrinsic(_InterlockedDecrement_acq)
  4356. #pragma intrinsic(_InterlockedDecrement_rel)
  4357. #pragma intrinsic(_InterlockedExchange)
  4358. #pragma intrinsic(_InterlockedCompareExchange)
  4359. #pragma intrinsic(_InterlockedCompareExchange_acq)
  4360. #pragma intrinsic(_InterlockedCompareExchange_rel)
  4361. #pragma intrinsic(_InterlockedExchangeAdd)
  4362. #pragma intrinsic(_InterlockedAdd64)
  4363. #pragma intrinsic(_InterlockedIncrement64)
  4364. #pragma intrinsic(_InterlockedDecrement64)
  4365. #pragma intrinsic(_InterlockedExchange64)
  4366. #pragma intrinsic(_InterlockedExchange64_acq)
  4367. #pragma intrinsic(_InterlockedCompareExchange64)
  4368. #pragma intrinsic(_InterlockedCompareExchange64_acq)
  4369. #pragma intrinsic(_InterlockedCompareExchange64_rel)
  4370. #pragma intrinsic(_InterlockedExchangeAdd64)
  4371. #pragma intrinsic(_InterlockedExchangePointer)
  4372. #pragma intrinsic(_InterlockedCompareExchangePointer)
  4373. #ifdef __cplusplus
  4374. }
  4375. #endif
  4376. #endif // defined(_M_IA64) && !defined(RC_INVOKED)
  4377. // end_wdm
  4378. __forceinline
  4379. LONG
  4380. InterlockedAnd (
  4381. IN OUT LONG volatile *Target,
  4382. LONG Set
  4383. )
  4384. {
  4385. LONG i;
  4386. LONG j;
  4387. j = *Target;
  4388. do {
  4389. i = j;
  4390. j = InterlockedCompareExchange(Target,
  4391. i & Set,
  4392. i);
  4393. } while (i != j);
  4394. return j;
  4395. }
  4396. __forceinline
  4397. LONG
  4398. InterlockedOr (
  4399. IN OUT LONG volatile *Target,
  4400. IN LONG Set
  4401. )
  4402. {
  4403. LONG i;
  4404. LONG j;
  4405. j = *Target;
  4406. do {
  4407. i = j;
  4408. j = InterlockedCompareExchange(Target,
  4409. i | Set,
  4410. i);
  4411. } while (i != j);
  4412. return j;
  4413. }
  4414. __forceinline
  4415. LONG
  4416. InterlockedXor (
  4417. IN OUT LONG volatile *Target,
  4418. IN LONG Set
  4419. )
  4420. {
  4421. LONG i;
  4422. LONG j;
  4423. j = *Target;
  4424. do {
  4425. i = j;
  4426. j = InterlockedCompareExchange(Target,
  4427. i ^ Set,
  4428. i);
  4429. } while (i != j);
  4430. return j;
  4431. }
  4432. #define KI_USER_SHARED_DATA ((ULONG_PTR)(KADDRESS_BASE + 0xFFFE0000))
  4433. #define SharedUserData ((KUSER_SHARED_DATA * const)KI_USER_SHARED_DATA)
  4434. // end_wdm
  4435. //
  4436. // Get address of processor control region.
  4437. //
  4438. #define KeGetPcr() PCR
  4439. //
  4440. // Get address of current kernel thread object.
  4441. //
  4442. #if defined(_M_IA64)
  4443. #define KeGetCurrentThread() PCR->CurrentThread
  4444. #endif
  4445. //
  4446. // Get current processor number.
  4447. //
  4448. #define KeGetCurrentProcessorNumber() ((ULONG)(PCR->Number))
  4449. //
  4450. // Get data cache fill size.
  4451. //
  4452. #if PRAGMA_DEPRECATED_DDK
  4453. #pragma deprecated(KeGetDcacheFillSize) // Use GetDmaAlignment
  4454. #endif
  4455. #define KeGetDcacheFillSize() PCR->DcacheFillSize
  4456. #define KeSaveFloatingPointState(a) STATUS_SUCCESS
  4457. #define KeRestoreFloatingPointState(a) STATUS_SUCCESS
  4458. //
  4459. //
  4460. // VOID
  4461. // KeMemoryBarrierWithoutFence (
  4462. // VOID
  4463. // )
  4464. //
  4465. //
  4466. // Routine Description:
  4467. //
  4468. // This function cases ordering of memory acceses generated by the compiler.
  4469. //
  4470. //
  4471. // Arguments:
  4472. //
  4473. // None.
  4474. //
  4475. // Return Value:
  4476. //
  4477. // None.
  4478. //--
  4479. #ifdef __cplusplus
  4480. extern "C" {
  4481. #endif
  4482. VOID
  4483. _ReadWriteBarrier (
  4484. VOID
  4485. );
  4486. #ifdef __cplusplus
  4487. }
  4488. #endif
  4489. #pragma intrinsic(_ReadWriteBarrier)
  4490. #define KeMemoryBarrierWithoutFence() _ReadWriteBarrier()
  4491. //++
  4492. //
  4493. //
  4494. // VOID
  4495. // KeMemoryBarrier (
  4496. // VOID
  4497. // )
  4498. //
  4499. //
  4500. // Routine Description:
  4501. //
  4502. // This function cases ordering of memory acceses as generated by the compiler and
  4503. // as seen by other processors.
  4504. //
  4505. //
  4506. // Arguments:
  4507. //
  4508. // None.
  4509. //
  4510. // Return Value:
  4511. //
  4512. // None.
  4513. //--
  4514. #define KE_MEMORY_BARRIER_REQUIRED
  4515. #define KeMemoryBarrier() {_ReadWriteBarrier();__mf ();_ReadWriteBarrier();}
  4516. //
  4517. // Define the page size
  4518. //
  4519. #define PAGE_SIZE 0x2000
  4520. //
  4521. // Define the number of trailing zeroes in a page aligned virtual address.
  4522. // This is used as the shift count when shifting virtual addresses to
  4523. // virtual page numbers.
  4524. //
  4525. #define PAGE_SHIFT 13L
  4526. //
  4527. // Cache and write buffer flush functions.
  4528. //
  4529. NTKERNELAPI
  4530. VOID
  4531. KeFlushIoBuffers (
  4532. IN PMDL Mdl,
  4533. IN BOOLEAN ReadOperation,
  4534. IN BOOLEAN DmaOperation
  4535. );
  4536. #define ExAcquireSpinLock(Lock, OldIrql) KeAcquireSpinLock((Lock), (OldIrql))
  4537. #define ExReleaseSpinLock(Lock, OldIrql) KeReleaseSpinLock((Lock), (OldIrql))
  4538. #define ExAcquireSpinLockAtDpcLevel(Lock) KeAcquireSpinLockAtDpcLevel(Lock)
  4539. #define ExReleaseSpinLockFromDpcLevel(Lock) KeReleaseSpinLockFromDpcLevel(Lock)
  4540. #if defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_)
  4541. // begin_wdm
  4542. #define KeQueryTickCount(CurrentCount ) \
  4543. *(PULONGLONG)(CurrentCount) = **((volatile ULONGLONG **)(&KeTickCount));
  4544. // end_wdm
  4545. #else
  4546. NTKERNELAPI
  4547. VOID
  4548. KeQueryTickCount (
  4549. OUT PLARGE_INTEGER CurrentCount
  4550. );
  4551. #endif // defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_)
  4552. //
  4553. // I/O space read and write macros.
  4554. //
  4555. NTHALAPI
  4556. UCHAR
  4557. READ_PORT_UCHAR (
  4558. PUCHAR RegisterAddress
  4559. );
  4560. NTHALAPI
  4561. USHORT
  4562. READ_PORT_USHORT (
  4563. PUSHORT RegisterAddress
  4564. );
  4565. NTHALAPI
  4566. ULONG
  4567. READ_PORT_ULONG (
  4568. PULONG RegisterAddress
  4569. );
  4570. NTHALAPI
  4571. VOID
  4572. READ_PORT_BUFFER_UCHAR (
  4573. PUCHAR portAddress,
  4574. PUCHAR readBuffer,
  4575. ULONG readCount
  4576. );
  4577. NTHALAPI
  4578. VOID
  4579. READ_PORT_BUFFER_USHORT (
  4580. PUSHORT portAddress,
  4581. PUSHORT readBuffer,
  4582. ULONG readCount
  4583. );
  4584. NTHALAPI
  4585. VOID
  4586. READ_PORT_BUFFER_ULONG (
  4587. PULONG portAddress,
  4588. PULONG readBuffer,
  4589. ULONG readCount
  4590. );
  4591. NTHALAPI
  4592. VOID
  4593. WRITE_PORT_UCHAR (
  4594. PUCHAR portAddress,
  4595. UCHAR Data
  4596. );
  4597. NTHALAPI
  4598. VOID
  4599. WRITE_PORT_USHORT (
  4600. PUSHORT portAddress,
  4601. USHORT Data
  4602. );
  4603. NTHALAPI
  4604. VOID
  4605. WRITE_PORT_ULONG (
  4606. PULONG portAddress,
  4607. ULONG Data
  4608. );
  4609. NTHALAPI
  4610. VOID
  4611. WRITE_PORT_BUFFER_UCHAR (
  4612. PUCHAR portAddress,
  4613. PUCHAR writeBuffer,
  4614. ULONG writeCount
  4615. );
  4616. NTHALAPI
  4617. VOID
  4618. WRITE_PORT_BUFFER_USHORT (
  4619. PUSHORT portAddress,
  4620. PUSHORT writeBuffer,
  4621. ULONG writeCount
  4622. );
  4623. NTHALAPI
  4624. VOID
  4625. WRITE_PORT_BUFFER_ULONG (
  4626. PULONG portAddress,
  4627. PULONG writeBuffer,
  4628. ULONG writeCount
  4629. );
  4630. #define READ_REGISTER_UCHAR(x) \
  4631. (__mf(), *(volatile UCHAR * const)(x))
  4632. #define READ_REGISTER_USHORT(x) \
  4633. (__mf(), *(volatile USHORT * const)(x))
  4634. #define READ_REGISTER_ULONG(x) \
  4635. (__mf(), *(volatile ULONG * const)(x))
  4636. #define READ_REGISTER_BUFFER_UCHAR(x, y, z) { \
  4637. PUCHAR registerBuffer = x; \
  4638. PUCHAR readBuffer = y; \
  4639. ULONG readCount; \
  4640. __mf(); \
  4641. for (readCount = z; readCount--; readBuffer++, registerBuffer++) { \
  4642. *readBuffer = *(volatile UCHAR * const)(registerBuffer); \
  4643. } \
  4644. }
  4645. #define READ_REGISTER_BUFFER_USHORT(x, y, z) { \
  4646. PUSHORT registerBuffer = x; \
  4647. PUSHORT readBuffer = y; \
  4648. ULONG readCount; \
  4649. __mf(); \
  4650. for (readCount = z; readCount--; readBuffer++, registerBuffer++) { \
  4651. *readBuffer = *(volatile USHORT * const)(registerBuffer); \
  4652. } \
  4653. }
  4654. #define READ_REGISTER_BUFFER_ULONG(x, y, z) { \
  4655. PULONG registerBuffer = x; \
  4656. PULONG readBuffer = y; \
  4657. ULONG readCount; \
  4658. __mf(); \
  4659. for (readCount = z; readCount--; readBuffer++, registerBuffer++) { \
  4660. *readBuffer = *(volatile ULONG * const)(registerBuffer); \
  4661. } \
  4662. }
  4663. #define WRITE_REGISTER_UCHAR(x, y) { \
  4664. *(volatile UCHAR * const)(x) = y; \
  4665. KeFlushWriteBuffer(); \
  4666. }
  4667. #define WRITE_REGISTER_USHORT(x, y) { \
  4668. *(volatile USHORT * const)(x) = y; \
  4669. KeFlushWriteBuffer(); \
  4670. }
  4671. #define WRITE_REGISTER_ULONG(x, y) { \
  4672. *(volatile ULONG * const)(x) = y; \
  4673. KeFlushWriteBuffer(); \
  4674. }
  4675. #define WRITE_REGISTER_BUFFER_UCHAR(x, y, z) { \
  4676. PUCHAR registerBuffer = x; \
  4677. PUCHAR writeBuffer = y; \
  4678. ULONG writeCount; \
  4679. for (writeCount = z; writeCount--; writeBuffer++, registerBuffer++) { \
  4680. *(volatile UCHAR * const)(registerBuffer) = *writeBuffer; \
  4681. } \
  4682. KeFlushWriteBuffer(); \
  4683. }
  4684. #define WRITE_REGISTER_BUFFER_USHORT(x, y, z) { \
  4685. PUSHORT registerBuffer = x; \
  4686. PUSHORT writeBuffer = y; \
  4687. ULONG writeCount; \
  4688. for (writeCount = z; writeCount--; writeBuffer++, registerBuffer++) { \
  4689. *(volatile USHORT * const)(registerBuffer) = *writeBuffer; \
  4690. } \
  4691. KeFlushWriteBuffer(); \
  4692. }
  4693. #define WRITE_REGISTER_BUFFER_ULONG(x, y, z) { \
  4694. PULONG registerBuffer = x; \
  4695. PULONG writeBuffer = y; \
  4696. ULONG writeCount; \
  4697. for (writeCount = z; writeCount--; writeBuffer++, registerBuffer++) { \
  4698. *(volatile ULONG * const)(registerBuffer) = *writeBuffer; \
  4699. } \
  4700. KeFlushWriteBuffer(); \
  4701. }
  4702. //
  4703. // Non-volatile floating point state
  4704. //
  4705. typedef struct _KFLOATING_SAVE {
  4706. ULONG Reserved;
  4707. } KFLOATING_SAVE, *PKFLOATING_SAVE;
  4708. //
  4709. // Define Processor Control Region Structure.
  4710. //
  4711. #define PCR_MINOR_VERSION 1
  4712. #define PCR_MAJOR_VERSION 1
  4713. typedef struct _KPCR {
  4714. //
  4715. // Major and minor version numbers of the PCR.
  4716. //
  4717. ULONG MinorVersion;
  4718. ULONG MajorVersion;
  4719. //
  4720. // Start of the architecturally defined section of the PCR. This section
  4721. // may be directly addressed by vendor/platform specific HAL code and will
  4722. // not change from version to version of NT.
  4723. //
  4724. //
  4725. // First and second level cache parameters.
  4726. //
  4727. ULONG FirstLevelDcacheSize;
  4728. ULONG FirstLevelDcacheFillSize;
  4729. ULONG FirstLevelIcacheSize;
  4730. ULONG FirstLevelIcacheFillSize;
  4731. ULONG SecondLevelDcacheSize;
  4732. ULONG SecondLevelDcacheFillSize;
  4733. ULONG SecondLevelIcacheSize;
  4734. ULONG SecondLevelIcacheFillSize;
  4735. //
  4736. // Data cache alignment and fill size used for cache flushing and alignment.
  4737. // These fields are set to the larger of the first and second level data
  4738. // cache fill sizes.
  4739. //
  4740. ULONG DcacheAlignment;
  4741. ULONG DcacheFillSize;
  4742. //
  4743. // Instruction cache alignment and fill size used for cache flushing and
  4744. // alignment. These fields are set to the larger of the first and second
  4745. // level data cache fill sizes.
  4746. //
  4747. ULONG IcacheAlignment;
  4748. ULONG IcacheFillSize;
  4749. //
  4750. // Processor identification from PrId register.
  4751. //
  4752. ULONG ProcessorId;
  4753. //
  4754. // Profiling data.
  4755. //
  4756. ULONG ProfileInterval;
  4757. ULONG ProfileCount;
  4758. //
  4759. // Stall execution count and scale factor.
  4760. //
  4761. ULONG StallExecutionCount;
  4762. ULONG StallScaleFactor;
  4763. ULONG InterruptionCount;
  4764. //
  4765. // Space reserved for the system.
  4766. //
  4767. ULONGLONG SystemReserved[6];
  4768. //
  4769. // Space reserved for the HAL
  4770. //
  4771. ULONGLONG HalReserved[64];
  4772. //
  4773. // IRQL mapping tables.
  4774. //
  4775. UCHAR IrqlMask[64];
  4776. UCHAR IrqlTable[64];
  4777. //
  4778. // External Interrupt vectors.
  4779. //
  4780. PKINTERRUPT_ROUTINE InterruptRoutine[MAXIMUM_VECTOR];
  4781. //
  4782. // Reserved interrupt vector mask.
  4783. //
  4784. ULONG ReservedVectors;
  4785. //
  4786. // Processor affinity mask.
  4787. //
  4788. KAFFINITY SetMember;
  4789. //
  4790. // Complement of the processor affinity mask.
  4791. //
  4792. KAFFINITY NotMember;
  4793. //
  4794. // Pointer to processor control block.
  4795. //
  4796. struct _KPRCB *Prcb;
  4797. //
  4798. // Shadow copy of Prcb->CurrentThread for fast access
  4799. //
  4800. struct _KTHREAD *CurrentThread;
  4801. //
  4802. // Processor number.
  4803. //
  4804. CCHAR Number; // Processor Number
  4805. } KPCR, *PKPCR;
  4806. NTKERNELAPI
  4807. KIRQL
  4808. KeGetCurrentIrql();
  4809. NTKERNELAPI
  4810. VOID
  4811. KeLowerIrql (
  4812. IN KIRQL NewIrql
  4813. );
  4814. NTKERNELAPI
  4815. VOID
  4816. KeRaiseIrql (
  4817. IN KIRQL NewIrql,
  4818. OUT PKIRQL OldIrql
  4819. );
  4820. // end_wdm
  4821. NTKERNELAPI
  4822. KIRQL
  4823. KeRaiseIrqlToDpcLevel (
  4824. VOID
  4825. );
  4826. NTKERNELAPI
  4827. KIRQL
  4828. KeRaiseIrqlToSynchLevel (
  4829. VOID
  4830. );
  4831. //
  4832. // The highest user address reserves 64K bytes for a guard page. This
  4833. // the probing of address from kernel mode to only have to check the
  4834. // starting address for structures of 64k bytes or less.
  4835. //
  4836. extern NTKERNELAPI PVOID MmHighestUserAddress;
  4837. extern NTKERNELAPI PVOID MmSystemRangeStart;
  4838. extern NTKERNELAPI ULONG_PTR MmUserProbeAddress;
  4839. #define MM_HIGHEST_USER_ADDRESS MmHighestUserAddress
  4840. #define MM_USER_PROBE_ADDRESS MmUserProbeAddress
  4841. #define MM_SYSTEM_RANGE_START MmSystemRangeStart
  4842. //
  4843. // The lowest user address reserves the low 64k.
  4844. //
  4845. #define MM_LOWEST_USER_ADDRESS (PVOID)((ULONG_PTR)(UADDRESS_BASE+0x00010000))
  4846. // begin_wdm
  4847. #define MmGetProcedureAddress(Address) (Address)
  4848. #define MmLockPagableCodeSection(PLabelAddress) \
  4849. MmLockPagableDataSection((PVOID)(*((PULONGLONG)PLabelAddress)))
  4850. #define VRN_MASK 0xE000000000000000UI64 // Virtual Region Number mask
  4851. #endif // defined(_IA64_)
  4852. //
  4853. // Define structure of boot driver list.
  4854. //
  4855. typedef struct _BOOT_DRIVER_LIST_ENTRY {
  4856. LIST_ENTRY Link;
  4857. UNICODE_STRING FilePath;
  4858. UNICODE_STRING RegistryPath;
  4859. PKLDR_DATA_TABLE_ENTRY LdrEntry;
  4860. } BOOT_DRIVER_LIST_ENTRY, *PBOOT_DRIVER_LIST_ENTRY;
  4861. #define THREAD_WAIT_OBJECTS 3 // Builtin usable wait blocks
  4862. //
  4863. #if defined(_X86_)
  4864. #define PAUSE_PROCESSOR _asm { rep nop }
  4865. #else
  4866. #define PAUSE_PROCESSOR
  4867. #endif
  4868. //
  4869. // Define macro to generate an affinity mask.
  4870. //
  4871. #if defined(_NTHAL_) || defined(_NTOSP_)
  4872. #define AFFINITY_MASK(n) ((ULONG_PTR)1 << (n))
  4873. #else
  4874. #if !defined(_WIN64)
  4875. #define KiAffinityArray KiMask32Array
  4876. #endif
  4877. extern const ULONG_PTR KiAffinityArray[];
  4878. #define AFFINITY_MASK(n) (KiAffinityArray[n])
  4879. #endif
  4880. typedef enum _KAPC_ENVIRONMENT {
  4881. OriginalApcEnvironment,
  4882. AttachedApcEnvironment,
  4883. CurrentApcEnvironment,
  4884. InsertApcEnvironment
  4885. } KAPC_ENVIRONMENT;
  4886. // begin_ntddk begin_wdm begin_nthal begin_ntminiport begin_ntifs begin_ntndis
  4887. //
  4888. // Interrupt modes.
  4889. //
  4890. typedef enum _KINTERRUPT_MODE {
  4891. LevelSensitive,
  4892. Latched
  4893. } KINTERRUPT_MODE;
  4894. //
  4895. // Wait reasons
  4896. //
  4897. typedef enum _KWAIT_REASON {
  4898. Executive,
  4899. FreePage,
  4900. PageIn,
  4901. PoolAllocation,
  4902. DelayExecution,
  4903. Suspended,
  4904. UserRequest,
  4905. WrExecutive,
  4906. WrFreePage,
  4907. WrPageIn,
  4908. WrPoolAllocation,
  4909. WrDelayExecution,
  4910. WrSuspended,
  4911. WrUserRequest,
  4912. WrEventPair,
  4913. WrQueue,
  4914. WrLpcReceive,
  4915. WrLpcReply,
  4916. WrVirtualMemory,
  4917. WrPageOut,
  4918. WrRendezvous,
  4919. Spare2,
  4920. Spare3,
  4921. Spare4,
  4922. Spare5,
  4923. Spare6,
  4924. WrKernel,
  4925. WrResource,
  4926. WrPushLock,
  4927. WrMutex,
  4928. WrQuantumEnd,
  4929. WrDispatchInt,
  4930. WrPreempted,
  4931. WrYieldExecution,
  4932. MaximumWaitReason
  4933. } KWAIT_REASON;
  4934. // end_ntddk end_wdm end_nthal
  4935. //
  4936. // Miscellaneous type definitions
  4937. //
  4938. // APC state
  4939. //
  4940. typedef struct _KAPC_STATE {
  4941. LIST_ENTRY ApcListHead[MaximumMode];
  4942. struct _KPROCESS *Process;
  4943. BOOLEAN KernelApcInProgress;
  4944. BOOLEAN KernelApcPending;
  4945. BOOLEAN UserApcPending;
  4946. } KAPC_STATE, *PKAPC_STATE, *RESTRICTED_POINTER PRKAPC_STATE;
  4947. typedef struct _KWAIT_BLOCK {
  4948. LIST_ENTRY WaitListEntry;
  4949. struct _KTHREAD *RESTRICTED_POINTER Thread;
  4950. PVOID Object;
  4951. struct _KWAIT_BLOCK *RESTRICTED_POINTER NextWaitBlock;
  4952. USHORT WaitKey;
  4953. USHORT WaitType;
  4954. } KWAIT_BLOCK, *PKWAIT_BLOCK, *RESTRICTED_POINTER PRKWAIT_BLOCK;
  4955. //
  4956. // Thread start function
  4957. //
  4958. typedef
  4959. VOID
  4960. (*PKSTART_ROUTINE) (
  4961. IN PVOID StartContext
  4962. );
  4963. //
  4964. // Kernel object structure definitions
  4965. //
  4966. //
  4967. // Device Queue object and entry
  4968. //
  4969. typedef struct _KDEVICE_QUEUE {
  4970. CSHORT Type;
  4971. CSHORT Size;
  4972. LIST_ENTRY DeviceListHead;
  4973. KSPIN_LOCK Lock;
  4974. BOOLEAN Busy;
  4975. } KDEVICE_QUEUE, *PKDEVICE_QUEUE, *RESTRICTED_POINTER PRKDEVICE_QUEUE;
  4976. typedef struct _KDEVICE_QUEUE_ENTRY {
  4977. LIST_ENTRY DeviceListEntry;
  4978. ULONG SortKey;
  4979. BOOLEAN Inserted;
  4980. } KDEVICE_QUEUE_ENTRY, *PKDEVICE_QUEUE_ENTRY, *RESTRICTED_POINTER PRKDEVICE_QUEUE_ENTRY;
  4981. //
  4982. // Define the interrupt service function type and the empty struct
  4983. // type.
  4984. //
  4985. typedef
  4986. BOOLEAN
  4987. (*PKSERVICE_ROUTINE) (
  4988. IN struct _KINTERRUPT *Interrupt,
  4989. IN PVOID ServiceContext
  4990. );
  4991. typedef struct _KINTERRUPT *PKINTERRUPT, *RESTRICTED_POINTER PRKINTERRUPT;
  4992. //
  4993. // Mutant object
  4994. //
  4995. typedef struct _KMUTANT {
  4996. DISPATCHER_HEADER Header;
  4997. LIST_ENTRY MutantListEntry;
  4998. struct _KTHREAD *RESTRICTED_POINTER OwnerThread;
  4999. BOOLEAN Abandoned;
  5000. UCHAR ApcDisable;
  5001. } KMUTANT, *PKMUTANT, *RESTRICTED_POINTER PRKMUTANT, KMUTEX, *PKMUTEX, *RESTRICTED_POINTER PRKMUTEX;
  5002. typedef struct _KQUEUE {
  5003. DISPATCHER_HEADER Header;
  5004. LIST_ENTRY EntryListHead;
  5005. ULONG CurrentCount;
  5006. ULONG MaximumCount;
  5007. LIST_ENTRY ThreadListHead;
  5008. } KQUEUE, *PKQUEUE, *RESTRICTED_POINTER PRKQUEUE;
  5009. //
  5010. //
  5011. // Semaphore object
  5012. //
  5013. typedef struct _KSEMAPHORE {
  5014. DISPATCHER_HEADER Header;
  5015. LONG Limit;
  5016. } KSEMAPHORE, *PKSEMAPHORE, *RESTRICTED_POINTER PRKSEMAPHORE;
  5017. NTKERNELAPI
  5018. VOID
  5019. KeInitializeApc (
  5020. IN PRKAPC Apc,
  5021. IN PRKTHREAD Thread,
  5022. IN KAPC_ENVIRONMENT Environment,
  5023. IN PKKERNEL_ROUTINE KernelRoutine,
  5024. IN PKRUNDOWN_ROUTINE RundownRoutine OPTIONAL,
  5025. IN PKNORMAL_ROUTINE NormalRoutine OPTIONAL,
  5026. IN KPROCESSOR_MODE ProcessorMode OPTIONAL,
  5027. IN PVOID NormalContext OPTIONAL
  5028. );
  5029. PLIST_ENTRY
  5030. KeFlushQueueApc (
  5031. IN PKTHREAD Thread,
  5032. IN KPROCESSOR_MODE ProcessorMode
  5033. );
  5034. NTKERNELAPI
  5035. BOOLEAN
  5036. KeInsertQueueApc (
  5037. IN PRKAPC Apc,
  5038. IN PVOID SystemArgument1,
  5039. IN PVOID SystemArgument2,
  5040. IN KPRIORITY Increment
  5041. );
  5042. BOOLEAN
  5043. KeRemoveQueueApc (
  5044. IN PKAPC Apc
  5045. );
  5046. VOID
  5047. KeGenericCallDpc (
  5048. IN PKDEFERRED_ROUTINE Routine,
  5049. IN PVOID Context
  5050. );
  5051. VOID
  5052. KeSignalCallDpcDone (
  5053. IN PVOID SystemArgument1
  5054. );
  5055. LOGICAL
  5056. KeSignalCallDpcSynchronize (
  5057. IN PVOID SystemArgument2
  5058. );
  5059. //
  5060. // DPC object
  5061. //
  5062. NTKERNELAPI
  5063. VOID
  5064. KeInitializeDpc (
  5065. IN PRKDPC Dpc,
  5066. IN PKDEFERRED_ROUTINE DeferredRoutine,
  5067. IN PVOID DeferredContext
  5068. );
  5069. // end_ntddk end_wdm end_nthal end_ntifs
  5070. NTKERNELAPI
  5071. VOID
  5072. KeInitializeThreadedDpc (
  5073. IN PRKDPC Dpc,
  5074. IN PKDEFERRED_ROUTINE DeferredRoutine,
  5075. IN PVOID DeferredContext
  5076. );
  5077. // begin_ntddk begin_wdm begin_nthal begin_ntifs
  5078. NTKERNELAPI
  5079. BOOLEAN
  5080. KeInsertQueueDpc (
  5081. IN PRKDPC Dpc,
  5082. IN PVOID SystemArgument1,
  5083. IN PVOID SystemArgument2
  5084. );
  5085. NTKERNELAPI
  5086. BOOLEAN
  5087. KeRemoveQueueDpc (
  5088. IN PRKDPC Dpc
  5089. );
  5090. // end_wdm
  5091. NTKERNELAPI
  5092. VOID
  5093. KeSetImportanceDpc (
  5094. IN PRKDPC Dpc,
  5095. IN KDPC_IMPORTANCE Importance
  5096. );
  5097. NTKERNELAPI
  5098. VOID
  5099. KeSetTargetProcessorDpc (
  5100. IN PRKDPC Dpc,
  5101. IN CCHAR Number
  5102. );
  5103. // begin_wdm
  5104. NTKERNELAPI
  5105. VOID
  5106. KeFlushQueuedDpcs (
  5107. VOID
  5108. );
  5109. //
  5110. // Device queue object
  5111. //
  5112. NTKERNELAPI
  5113. VOID
  5114. KeInitializeDeviceQueue (
  5115. IN PKDEVICE_QUEUE DeviceQueue
  5116. );
  5117. NTKERNELAPI
  5118. BOOLEAN
  5119. KeInsertDeviceQueue (
  5120. IN PKDEVICE_QUEUE DeviceQueue,
  5121. IN PKDEVICE_QUEUE_ENTRY DeviceQueueEntry
  5122. );
  5123. NTKERNELAPI
  5124. BOOLEAN
  5125. KeInsertByKeyDeviceQueue (
  5126. IN PKDEVICE_QUEUE DeviceQueue,
  5127. IN PKDEVICE_QUEUE_ENTRY DeviceQueueEntry,
  5128. IN ULONG SortKey
  5129. );
  5130. NTKERNELAPI
  5131. PKDEVICE_QUEUE_ENTRY
  5132. KeRemoveDeviceQueue (
  5133. IN PKDEVICE_QUEUE DeviceQueue
  5134. );
  5135. NTKERNELAPI
  5136. PKDEVICE_QUEUE_ENTRY
  5137. KeRemoveByKeyDeviceQueue (
  5138. IN PKDEVICE_QUEUE DeviceQueue,
  5139. IN ULONG SortKey
  5140. );
  5141. NTKERNELAPI
  5142. PKDEVICE_QUEUE_ENTRY
  5143. KeRemoveByKeyDeviceQueueIfBusy (
  5144. IN PKDEVICE_QUEUE DeviceQueue,
  5145. IN ULONG SortKey
  5146. );
  5147. NTKERNELAPI
  5148. BOOLEAN
  5149. KeRemoveEntryDeviceQueue (
  5150. IN PKDEVICE_QUEUE DeviceQueue,
  5151. IN PKDEVICE_QUEUE_ENTRY DeviceQueueEntry
  5152. );
  5153. NTKERNELAPI
  5154. BOOLEAN
  5155. KeSynchronizeExecution (
  5156. IN PKINTERRUPT Interrupt,
  5157. IN PKSYNCHRONIZE_ROUTINE SynchronizeRoutine,
  5158. IN PVOID SynchronizeContext
  5159. );
  5160. NTKERNELAPI
  5161. KIRQL
  5162. KeAcquireInterruptSpinLock (
  5163. IN PKINTERRUPT Interrupt
  5164. );
  5165. NTKERNELAPI
  5166. VOID
  5167. KeReleaseInterruptSpinLock (
  5168. IN PKINTERRUPT Interrupt,
  5169. IN KIRQL OldIrql
  5170. );
  5171. //
  5172. // Kernel dispatcher object functions
  5173. //
  5174. // Event Object
  5175. //
  5176. NTKERNELAPI
  5177. VOID
  5178. KeInitializeEvent (
  5179. IN PRKEVENT Event,
  5180. IN EVENT_TYPE Type,
  5181. IN BOOLEAN State
  5182. );
  5183. NTKERNELAPI
  5184. VOID
  5185. KeClearEvent (
  5186. IN PRKEVENT Event
  5187. );
  5188. NTKERNELAPI
  5189. LONG
  5190. KePulseEvent (
  5191. IN PRKEVENT Event,
  5192. IN KPRIORITY Increment,
  5193. IN BOOLEAN Wait
  5194. );
  5195. NTKERNELAPI
  5196. LONG
  5197. KeReadStateEvent (
  5198. IN PRKEVENT Event
  5199. );
  5200. NTKERNELAPI
  5201. LONG
  5202. KeResetEvent (
  5203. IN PRKEVENT Event
  5204. );
  5205. NTKERNELAPI
  5206. LONG
  5207. KeSetEvent (
  5208. IN PRKEVENT Event,
  5209. IN KPRIORITY Increment,
  5210. IN BOOLEAN Wait
  5211. );
  5212. //
  5213. // Mutex object
  5214. //
  5215. NTKERNELAPI
  5216. VOID
  5217. KeInitializeMutex (
  5218. IN PRKMUTEX Mutex,
  5219. IN ULONG Level
  5220. );
  5221. NTKERNELAPI
  5222. LONG
  5223. KeReadStateMutex (
  5224. IN PRKMUTEX Mutex
  5225. );
  5226. NTKERNELAPI
  5227. LONG
  5228. KeReleaseMutex (
  5229. IN PRKMUTEX Mutex,
  5230. IN BOOLEAN Wait
  5231. );
  5232. // end_ntddk end_wdm
  5233. //
  5234. // Queue Object.
  5235. //
  5236. NTKERNELAPI
  5237. VOID
  5238. KeInitializeQueue (
  5239. IN PRKQUEUE Queue,
  5240. IN ULONG Count OPTIONAL
  5241. );
  5242. NTKERNELAPI
  5243. LONG
  5244. KeReadStateQueue (
  5245. IN PRKQUEUE Queue
  5246. );
  5247. NTKERNELAPI
  5248. LONG
  5249. KeInsertQueue (
  5250. IN PRKQUEUE Queue,
  5251. IN PLIST_ENTRY Entry
  5252. );
  5253. NTKERNELAPI
  5254. LONG
  5255. KeInsertHeadQueue (
  5256. IN PRKQUEUE Queue,
  5257. IN PLIST_ENTRY Entry
  5258. );
  5259. NTKERNELAPI
  5260. PLIST_ENTRY
  5261. KeRemoveQueue (
  5262. IN PRKQUEUE Queue,
  5263. IN KPROCESSOR_MODE WaitMode,
  5264. IN PLARGE_INTEGER Timeout OPTIONAL
  5265. );
  5266. PLIST_ENTRY
  5267. KeRundownQueue (
  5268. IN PRKQUEUE Queue
  5269. );
  5270. // begin_ntddk begin_wdm
  5271. //
  5272. // Semaphore object
  5273. //
  5274. NTKERNELAPI
  5275. VOID
  5276. KeInitializeSemaphore (
  5277. IN PRKSEMAPHORE Semaphore,
  5278. IN LONG Count,
  5279. IN LONG Limit
  5280. );
  5281. NTKERNELAPI
  5282. LONG
  5283. KeReadStateSemaphore (
  5284. IN PRKSEMAPHORE Semaphore
  5285. );
  5286. NTKERNELAPI
  5287. LONG
  5288. KeReleaseSemaphore (
  5289. IN PRKSEMAPHORE Semaphore,
  5290. IN KPRIORITY Increment,
  5291. IN LONG Adjustment,
  5292. IN BOOLEAN Wait
  5293. );
  5294. NTKERNELAPI
  5295. VOID
  5296. KeAttachProcess (
  5297. IN PRKPROCESS Process
  5298. );
  5299. NTKERNELAPI
  5300. VOID
  5301. KeDetachProcess (
  5302. VOID
  5303. );
  5304. NTKERNELAPI
  5305. VOID
  5306. KeStackAttachProcess (
  5307. IN PRKPROCESS PROCESS,
  5308. OUT PRKAPC_STATE ApcState
  5309. );
  5310. NTKERNELAPI
  5311. VOID
  5312. KeUnstackDetachProcess (
  5313. IN PRKAPC_STATE ApcState
  5314. );
  5315. NTKERNELAPI
  5316. BOOLEAN
  5317. KeIsAttachedProcess(
  5318. VOID
  5319. );
  5320. NTKERNELAPI // ntddk wdm nthal ntifs
  5321. NTSTATUS // ntddk wdm nthal ntifs
  5322. KeDelayExecutionThread ( // ntddk wdm nthal ntifs
  5323. IN KPROCESSOR_MODE WaitMode, // ntddk wdm nthal ntifs
  5324. IN BOOLEAN Alertable, // ntddk wdm nthal ntifs
  5325. IN PLARGE_INTEGER Interval // ntddk wdm nthal ntifs
  5326. ); // ntddk wdm nthal ntifs
  5327. // ntddk wdm nthal ntifs
  5328. VOID
  5329. KeRevertToUserAffinityThread (
  5330. VOID
  5331. );
  5332. VOID
  5333. KeSetSystemAffinityThread (
  5334. IN KAFFINITY Affinity
  5335. );
  5336. NTKERNELAPI
  5337. LONG
  5338. KeSetBasePriorityThread (
  5339. IN PKTHREAD Thread,
  5340. IN LONG Increment
  5341. );
  5342. NTKERNELAPI
  5343. BOOLEAN
  5344. KeSetKernelStackSwapEnable (
  5345. IN BOOLEAN Enable
  5346. );
  5347. // end_ntifs
  5348. NTKERNELAPI // ntddk wdm nthal ntifs
  5349. KPRIORITY // ntddk wdm nthal ntifs
  5350. KeSetPriorityThread ( // ntddk wdm nthal ntifs
  5351. IN PKTHREAD Thread, // ntddk wdm nthal ntifs
  5352. IN KPRIORITY Priority // ntddk wdm nthal ntifs
  5353. ); // ntddk wdm nthal ntifs
  5354. // ntddk wdm nthal ntifs
  5355. #if ((defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_) ||defined(_NTHAL_)) && !defined(_NTSYSTEM_DRIVER_) || defined(_NTOSP_))
  5356. // begin_wdm
  5357. NTKERNELAPI
  5358. VOID
  5359. KeEnterCriticalRegion (
  5360. VOID
  5361. );
  5362. NTKERNELAPI
  5363. VOID
  5364. KeLeaveCriticalRegion (
  5365. VOID
  5366. );
  5367. NTKERNELAPI
  5368. BOOLEAN
  5369. KeAreApcsDisabled (
  5370. VOID
  5371. );
  5372. // end_wdm
  5373. #endif
  5374. // begin_wdm
  5375. //
  5376. // Timer object
  5377. //
  5378. NTKERNELAPI
  5379. VOID
  5380. KeInitializeTimer (
  5381. IN PKTIMER Timer
  5382. );
  5383. NTKERNELAPI
  5384. VOID
  5385. KeInitializeTimerEx (
  5386. IN PKTIMER Timer,
  5387. IN TIMER_TYPE Type
  5388. );
  5389. NTKERNELAPI
  5390. BOOLEAN
  5391. KeCancelTimer (
  5392. IN PKTIMER
  5393. );
  5394. NTKERNELAPI
  5395. BOOLEAN
  5396. KeReadStateTimer (
  5397. PKTIMER Timer
  5398. );
  5399. NTKERNELAPI
  5400. BOOLEAN
  5401. KeSetTimer (
  5402. IN PKTIMER Timer,
  5403. IN LARGE_INTEGER DueTime,
  5404. IN PKDPC Dpc OPTIONAL
  5405. );
  5406. NTKERNELAPI
  5407. BOOLEAN
  5408. KeSetTimerEx (
  5409. IN PKTIMER Timer,
  5410. IN LARGE_INTEGER DueTime,
  5411. IN LONG Period OPTIONAL,
  5412. IN PKDPC Dpc OPTIONAL
  5413. );
  5414. #define KeWaitForMutexObject KeWaitForSingleObject
  5415. NTKERNELAPI
  5416. NTSTATUS
  5417. KeWaitForMultipleObjects (
  5418. IN ULONG Count,
  5419. IN PVOID Object[],
  5420. IN WAIT_TYPE WaitType,
  5421. IN KWAIT_REASON WaitReason,
  5422. IN KPROCESSOR_MODE WaitMode,
  5423. IN BOOLEAN Alertable,
  5424. IN PLARGE_INTEGER Timeout OPTIONAL,
  5425. IN PKWAIT_BLOCK WaitBlockArray OPTIONAL
  5426. );
  5427. NTKERNELAPI
  5428. NTSTATUS
  5429. KeWaitForSingleObject (
  5430. IN PVOID Object,
  5431. IN KWAIT_REASON WaitReason,
  5432. IN KPROCESSOR_MODE WaitMode,
  5433. IN BOOLEAN Alertable,
  5434. IN PLARGE_INTEGER Timeout OPTIONAL
  5435. );
  5436. //
  5437. // Define interprocess interrupt generic call types.
  5438. //
  5439. typedef
  5440. ULONG_PTR
  5441. (*PKIPI_BROADCAST_WORKER)(
  5442. IN ULONG_PTR Argument
  5443. );
  5444. ULONG_PTR
  5445. KeIpiGenericCall (
  5446. IN PKIPI_BROADCAST_WORKER BroadcastFunction,
  5447. IN ULONG_PTR Context
  5448. );
  5449. //
  5450. // On X86 the following routines are defined in the HAL and imported by
  5451. // all other modules.
  5452. //
  5453. #if defined(_X86_) && !defined(_NTHAL_)
  5454. #define _DECL_HAL_KE_IMPORT __declspec(dllimport)
  5455. #else
  5456. #define _DECL_HAL_KE_IMPORT
  5457. #endif
  5458. _DECL_HAL_KE_IMPORT
  5459. KIRQL
  5460. FASTCALL
  5461. KeAcquireQueuedSpinLock (
  5462. IN KSPIN_LOCK_QUEUE_NUMBER Number
  5463. );
  5464. _DECL_HAL_KE_IMPORT
  5465. VOID
  5466. FASTCALL
  5467. KeReleaseQueuedSpinLock (
  5468. IN KSPIN_LOCK_QUEUE_NUMBER Number,
  5469. IN KIRQL OldIrql
  5470. );
  5471. _DECL_HAL_KE_IMPORT
  5472. LOGICAL
  5473. FASTCALL
  5474. KeTryToAcquireQueuedSpinLock(
  5475. IN KSPIN_LOCK_QUEUE_NUMBER Number,
  5476. IN PKIRQL OldIrql
  5477. );
  5478. //
  5479. // spin lock functions
  5480. //
  5481. #if defined(_X86_) && (defined(_WDMDDK_) || defined(WIN9X_COMPAT_SPINLOCK))
  5482. NTKERNELAPI
  5483. VOID
  5484. NTAPI
  5485. KeInitializeSpinLock (
  5486. IN PKSPIN_LOCK SpinLock
  5487. );
  5488. #else
  5489. __inline
  5490. VOID
  5491. NTAPI
  5492. KeInitializeSpinLock (
  5493. IN PKSPIN_LOCK SpinLock
  5494. )
  5495. {
  5496. *SpinLock = 0;
  5497. }
  5498. #endif
  5499. #if defined(_X86_)
  5500. NTKERNELAPI
  5501. VOID
  5502. FASTCALL
  5503. KefAcquireSpinLockAtDpcLevel (
  5504. IN PKSPIN_LOCK SpinLock
  5505. );
  5506. NTKERNELAPI
  5507. VOID
  5508. FASTCALL
  5509. KefReleaseSpinLockFromDpcLevel (
  5510. IN PKSPIN_LOCK SpinLock
  5511. );
  5512. #define KeAcquireSpinLockAtDpcLevel(a) KefAcquireSpinLockAtDpcLevel(a)
  5513. #define KeReleaseSpinLockFromDpcLevel(a) KefReleaseSpinLockFromDpcLevel(a)
  5514. _DECL_HAL_KE_IMPORT
  5515. KIRQL
  5516. FASTCALL
  5517. KfAcquireSpinLock (
  5518. IN PKSPIN_LOCK SpinLock
  5519. );
  5520. _DECL_HAL_KE_IMPORT
  5521. VOID
  5522. FASTCALL
  5523. KfReleaseSpinLock (
  5524. IN PKSPIN_LOCK SpinLock,
  5525. IN KIRQL NewIrql
  5526. );
  5527. // end_wdm end_ntddk
  5528. _DECL_HAL_KE_IMPORT
  5529. KIRQL
  5530. FASTCALL
  5531. KeAcquireSpinLockRaiseToSynch (
  5532. IN PKSPIN_LOCK SpinLock
  5533. );
  5534. // begin_wdm begin_ntddk
  5535. #define KeAcquireSpinLock(a,b) *(b) = KfAcquireSpinLock(a)
  5536. #define KeReleaseSpinLock(a,b) KfReleaseSpinLock(a,b)
  5537. NTKERNELAPI
  5538. BOOLEAN
  5539. FASTCALL
  5540. KeTestSpinLock (
  5541. IN PKSPIN_LOCK SpinLock
  5542. );
  5543. NTKERNELAPI
  5544. BOOLEAN
  5545. FASTCALL
  5546. KeTryToAcquireSpinLockAtDpcLevel (
  5547. IN PKSPIN_LOCK SpinLock
  5548. );
  5549. #else
  5550. //
  5551. // These functions are imported for IA64, ntddk, ntifs, nthal, ntosp, and wdm.
  5552. // They can be inlined for the system on AMD64.
  5553. //
  5554. #define KeAcquireSpinLock(SpinLock, OldIrql) \
  5555. *(OldIrql) = KeAcquireSpinLockRaiseToDpc(SpinLock)
  5556. #if defined(_IA64_) || defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_) || defined(_NTHAL_) || defined(_NTOSP_) || defined(_WDMDDK_)
  5557. // end_wdm end_ntddk
  5558. NTKERNELAPI
  5559. KIRQL
  5560. FASTCALL
  5561. KeAcquireSpinLockRaiseToSynch (
  5562. IN PKSPIN_LOCK SpinLock
  5563. );
  5564. // begin_wdm begin_ntddk
  5565. NTKERNELAPI
  5566. VOID
  5567. KeAcquireSpinLockAtDpcLevel (
  5568. IN PKSPIN_LOCK SpinLock
  5569. );
  5570. NTKERNELAPI
  5571. KIRQL
  5572. KeAcquireSpinLockRaiseToDpc (
  5573. IN PKSPIN_LOCK SpinLock
  5574. );
  5575. NTKERNELAPI
  5576. VOID
  5577. KeReleaseSpinLock (
  5578. IN PKSPIN_LOCK SpinLock,
  5579. IN KIRQL NewIrql
  5580. );
  5581. NTKERNELAPI
  5582. VOID
  5583. KeReleaseSpinLockFromDpcLevel (
  5584. IN PKSPIN_LOCK SpinLock
  5585. );
  5586. NTKERNELAPI
  5587. BOOLEAN
  5588. FASTCALL
  5589. KeTestSpinLock (
  5590. IN PKSPIN_LOCK SpinLock
  5591. );
  5592. NTKERNELAPI
  5593. BOOLEAN
  5594. FASTCALL
  5595. KeTryToAcquireSpinLockAtDpcLevel (
  5596. IN PKSPIN_LOCK SpinLock
  5597. );
  5598. #else
  5599. #if defined(_AMD64_)
  5600. //
  5601. // The system version of these functions are defined in amd64.h for AMD64.
  5602. //
  5603. #endif
  5604. #endif
  5605. #endif
  5606. // end_wdm end_ntddk end_nthal end_ntifs
  5607. NTKERNELAPI
  5608. KIRQL
  5609. FASTCALL
  5610. KeAcquireSpinLockForDpc (
  5611. IN PKSPIN_LOCK SpinLock
  5612. );
  5613. NTKERNELAPI
  5614. VOID
  5615. FASTCALL
  5616. KeReleaseSpinLockForDpc (
  5617. IN PKSPIN_LOCK SpinLock,
  5618. IN KIRQL OldIrql
  5619. );
  5620. #if defined(_X86_)
  5621. _DECL_HAL_KE_IMPORT
  5622. VOID
  5623. FASTCALL
  5624. KfLowerIrql (
  5625. IN KIRQL NewIrql
  5626. );
  5627. _DECL_HAL_KE_IMPORT
  5628. KIRQL
  5629. FASTCALL
  5630. KfRaiseIrql (
  5631. IN KIRQL NewIrql
  5632. );
  5633. // end_wdm
  5634. _DECL_HAL_KE_IMPORT
  5635. KIRQL
  5636. KeRaiseIrqlToDpcLevel(
  5637. VOID
  5638. );
  5639. // end_ntddk
  5640. _DECL_HAL_KE_IMPORT
  5641. KIRQL
  5642. KeRaiseIrqlToSynchLevel(
  5643. VOID
  5644. );
  5645. // begin_wdm begin_ntddk
  5646. #define KeLowerIrql(a) KfLowerIrql(a)
  5647. #define KeRaiseIrql(a,b) *(b) = KfRaiseIrql(a)
  5648. // end_wdm
  5649. // begin_wdm
  5650. #elif defined(_IA64_)
  5651. //
  5652. // These function are defined in IA64.h for the IA64 platform.
  5653. //
  5654. #elif defined(_AMD64_)
  5655. //
  5656. // These function are defined in amd64.h for the AMD64 platform.
  5657. //
  5658. #else
  5659. #error "no target architecture"
  5660. #endif
  5661. //
  5662. // Queued spin lock functions for "in stack" lock handles.
  5663. //
  5664. // The following three functions RAISE and LOWER IRQL when a queued
  5665. // in stack spin lock is acquired or released using these routines.
  5666. //
  5667. _DECL_HAL_KE_IMPORT
  5668. VOID
  5669. FASTCALL
  5670. KeAcquireInStackQueuedSpinLock (
  5671. IN PKSPIN_LOCK SpinLock,
  5672. IN PKLOCK_QUEUE_HANDLE LockHandle
  5673. );
  5674. _DECL_HAL_KE_IMPORT
  5675. VOID
  5676. FASTCALL
  5677. KeReleaseInStackQueuedSpinLock (
  5678. IN PKLOCK_QUEUE_HANDLE LockHandle
  5679. );
  5680. //
  5681. // The following two functions do NOT raise or lower IRQL when a queued
  5682. // in stack spin lock is acquired or released using these functions.
  5683. //
  5684. NTKERNELAPI
  5685. VOID
  5686. FASTCALL
  5687. KeAcquireInStackQueuedSpinLockAtDpcLevel (
  5688. IN PKSPIN_LOCK SpinLock,
  5689. IN PKLOCK_QUEUE_HANDLE LockHandle
  5690. );
  5691. NTKERNELAPI
  5692. VOID
  5693. FASTCALL
  5694. KeReleaseInStackQueuedSpinLockFromDpcLevel (
  5695. IN PKLOCK_QUEUE_HANDLE LockHandle
  5696. );
  5697. // end_ntddk end_nthal end_ntifs
  5698. //
  5699. // The following two functions conditionally raise or lower IRQL when a
  5700. // queued in-stack spin lock is acquired or released using these functions.
  5701. //
  5702. NTKERNELAPI
  5703. VOID
  5704. FASTCALL
  5705. KeAcquireInStackQueuedSpinLockForDpc (
  5706. IN PKSPIN_LOCK SpinLock,
  5707. IN PKLOCK_QUEUE_HANDLE LockHandle
  5708. );
  5709. NTKERNELAPI
  5710. VOID
  5711. FASTCALL
  5712. KeReleaseInStackQueuedSpinLockForDpc (
  5713. IN PKLOCK_QUEUE_HANDLE LockHandle
  5714. );
  5715. //
  5716. // Miscellaneous kernel functions
  5717. //
  5718. typedef enum _KBUGCHECK_BUFFER_DUMP_STATE {
  5719. BufferEmpty,
  5720. BufferInserted,
  5721. BufferStarted,
  5722. BufferFinished,
  5723. BufferIncomplete
  5724. } KBUGCHECK_BUFFER_DUMP_STATE;
  5725. typedef
  5726. VOID
  5727. (*PKBUGCHECK_CALLBACK_ROUTINE) (
  5728. IN PVOID Buffer,
  5729. IN ULONG Length
  5730. );
  5731. typedef struct _KBUGCHECK_CALLBACK_RECORD {
  5732. LIST_ENTRY Entry;
  5733. PKBUGCHECK_CALLBACK_ROUTINE CallbackRoutine;
  5734. PVOID Buffer;
  5735. ULONG Length;
  5736. PUCHAR Component;
  5737. ULONG_PTR Checksum;
  5738. UCHAR State;
  5739. } KBUGCHECK_CALLBACK_RECORD, *PKBUGCHECK_CALLBACK_RECORD;
  5740. #define KeInitializeCallbackRecord(CallbackRecord) \
  5741. (CallbackRecord)->State = BufferEmpty
  5742. NTKERNELAPI
  5743. BOOLEAN
  5744. KeDeregisterBugCheckCallback (
  5745. IN PKBUGCHECK_CALLBACK_RECORD CallbackRecord
  5746. );
  5747. NTKERNELAPI
  5748. BOOLEAN
  5749. KeRegisterBugCheckCallback (
  5750. IN PKBUGCHECK_CALLBACK_RECORD CallbackRecord,
  5751. IN PKBUGCHECK_CALLBACK_ROUTINE CallbackRoutine,
  5752. IN PVOID Buffer,
  5753. IN ULONG Length,
  5754. IN PUCHAR Component
  5755. );
  5756. typedef enum _KBUGCHECK_CALLBACK_REASON {
  5757. KbCallbackInvalid,
  5758. KbCallbackReserved1,
  5759. KbCallbackSecondaryDumpData,
  5760. KbCallbackDumpIo,
  5761. } KBUGCHECK_CALLBACK_REASON;
  5762. typedef
  5763. VOID
  5764. (*PKBUGCHECK_REASON_CALLBACK_ROUTINE) (
  5765. IN KBUGCHECK_CALLBACK_REASON Reason,
  5766. IN struct _KBUGCHECK_REASON_CALLBACK_RECORD* Record,
  5767. IN OUT PVOID ReasonSpecificData,
  5768. IN ULONG ReasonSpecificDataLength
  5769. );
  5770. typedef struct _KBUGCHECK_REASON_CALLBACK_RECORD {
  5771. LIST_ENTRY Entry;
  5772. PKBUGCHECK_REASON_CALLBACK_ROUTINE CallbackRoutine;
  5773. PUCHAR Component;
  5774. ULONG_PTR Checksum;
  5775. KBUGCHECK_CALLBACK_REASON Reason;
  5776. UCHAR State;
  5777. } KBUGCHECK_REASON_CALLBACK_RECORD, *PKBUGCHECK_REASON_CALLBACK_RECORD;
  5778. typedef struct _KBUGCHECK_SECONDARY_DUMP_DATA {
  5779. IN PVOID InBuffer;
  5780. IN ULONG InBufferLength;
  5781. IN ULONG MaximumAllowed;
  5782. OUT GUID Guid;
  5783. OUT PVOID OutBuffer;
  5784. OUT ULONG OutBufferLength;
  5785. } KBUGCHECK_SECONDARY_DUMP_DATA, *PKBUGCHECK_SECONDARY_DUMP_DATA;
  5786. typedef enum _KBUGCHECK_DUMP_IO_TYPE
  5787. {
  5788. KbDumpIoInvalid,
  5789. KbDumpIoHeader,
  5790. KbDumpIoBody,
  5791. KbDumpIoSecondaryData,
  5792. KbDumpIoComplete
  5793. } KBUGCHECK_DUMP_IO_TYPE;
  5794. typedef struct _KBUGCHECK_DUMP_IO {
  5795. IN ULONG64 Offset;
  5796. IN PVOID Buffer;
  5797. IN ULONG BufferLength;
  5798. IN KBUGCHECK_DUMP_IO_TYPE Type;
  5799. } KBUGCHECK_DUMP_IO, *PKBUGCHECK_DUMP_IO;
  5800. NTKERNELAPI
  5801. BOOLEAN
  5802. KeDeregisterBugCheckReasonCallback (
  5803. IN PKBUGCHECK_REASON_CALLBACK_RECORD CallbackRecord
  5804. );
  5805. NTKERNELAPI
  5806. BOOLEAN
  5807. KeRegisterBugCheckReasonCallback (
  5808. IN PKBUGCHECK_REASON_CALLBACK_RECORD CallbackRecord,
  5809. IN PKBUGCHECK_REASON_CALLBACK_ROUTINE CallbackRoutine,
  5810. IN KBUGCHECK_CALLBACK_REASON Reason,
  5811. IN PUCHAR Component
  5812. );
  5813. typedef
  5814. BOOLEAN
  5815. (*PNMI_CALLBACK)(
  5816. IN PVOID Context,
  5817. IN BOOLEAN Handled
  5818. );
  5819. NTKERNELAPI
  5820. PVOID
  5821. KeRegisterNmiCallback(
  5822. PNMI_CALLBACK CallbackRoutine,
  5823. PVOID Context
  5824. );
  5825. NTSTATUS
  5826. KeDeregisterNmiCallback(
  5827. PVOID Handle
  5828. );
  5829. // end_wdm
  5830. NTKERNELAPI
  5831. DECLSPEC_NORETURN
  5832. VOID
  5833. NTAPI
  5834. KeBugCheck (
  5835. IN ULONG BugCheckCode
  5836. );
  5837. NTKERNELAPI
  5838. DECLSPEC_NORETURN
  5839. VOID
  5840. KeBugCheckEx(
  5841. IN ULONG BugCheckCode,
  5842. IN ULONG_PTR BugCheckParameter1,
  5843. IN ULONG_PTR BugCheckParameter2,
  5844. IN ULONG_PTR BugCheckParameter3,
  5845. IN ULONG_PTR BugCheckParameter4
  5846. );
  5847. #define WIN32K_SERVICE_INDEX 1
  5848. #define IIS_SERVICE_INDEX 2
  5849. NTKERNELAPI
  5850. BOOLEAN
  5851. KeAddSystemServiceTable(
  5852. IN PULONG_PTR Base,
  5853. IN PULONG Count OPTIONAL,
  5854. IN ULONG Limit,
  5855. IN PUCHAR Number,
  5856. IN ULONG Index
  5857. );
  5858. NTKERNELAPI
  5859. BOOLEAN
  5860. KeRemoveSystemServiceTable(
  5861. IN ULONG Index
  5862. );
  5863. #if !defined(_AMD64_)
  5864. NTKERNELAPI
  5865. ULONGLONG
  5866. KeQueryInterruptTime (
  5867. VOID
  5868. );
  5869. NTKERNELAPI
  5870. VOID
  5871. KeQuerySystemTime (
  5872. OUT PLARGE_INTEGER CurrentTime
  5873. );
  5874. #endif
  5875. NTKERNELAPI
  5876. ULONG
  5877. KeQueryTimeIncrement (
  5878. VOID
  5879. );
  5880. NTKERNELAPI
  5881. ULONG
  5882. KeGetRecommendedSharedDataAlignment (
  5883. VOID
  5884. );
  5885. // end_wdm
  5886. NTKERNELAPI
  5887. KAFFINITY
  5888. KeQueryActiveProcessors (
  5889. VOID
  5890. );
  5891. //
  5892. // Define the firmware routine types
  5893. //
  5894. typedef enum _FIRMWARE_REENTRY {
  5895. HalHaltRoutine,
  5896. HalPowerDownRoutine,
  5897. HalRestartRoutine,
  5898. HalRebootRoutine,
  5899. HalInteractiveModeRoutine,
  5900. HalMaximumRoutine
  5901. } FIRMWARE_REENTRY, *PFIRMWARE_REENTRY;
  5902. NTKERNELAPI
  5903. NTSTATUS
  5904. KeUserModeCallback (
  5905. IN ULONG ApiNumber,
  5906. IN PVOID InputBuffer,
  5907. IN ULONG InputLength,
  5908. OUT PVOID *OutputBuffer,
  5909. OUT PULONG OutputLength
  5910. );
  5911. extern PLOADER_PARAMETER_BLOCK KeLoaderBlock;
  5912. extern NTSYSAPI CCHAR KeNumberProcessors;
  5913. #if defined(_IA64_)
  5914. extern volatile LARGE_INTEGER KeTickCount;
  5915. #elif defined(_X86_)
  5916. extern volatile KSYSTEM_TIME KeTickCount;
  5917. #endif
  5918. typedef enum _MEMORY_CACHING_TYPE_ORIG {
  5919. MmFrameBufferCached = 2
  5920. } MEMORY_CACHING_TYPE_ORIG;
  5921. typedef enum _MEMORY_CACHING_TYPE {
  5922. MmNonCached = FALSE,
  5923. MmCached = TRUE,
  5924. MmWriteCombined = MmFrameBufferCached,
  5925. MmHardwareCoherentCached,
  5926. MmNonCachedUnordered, // IA64
  5927. MmUSWCCached,
  5928. MmMaximumCacheType
  5929. } MEMORY_CACHING_TYPE;
  5930. //
  5931. // Pool Allocation routines (in pool.c)
  5932. //
  5933. typedef enum _POOL_TYPE {
  5934. NonPagedPool,
  5935. PagedPool,
  5936. NonPagedPoolMustSucceed,
  5937. DontUseThisType,
  5938. NonPagedPoolCacheAligned,
  5939. PagedPoolCacheAligned,
  5940. NonPagedPoolCacheAlignedMustS,
  5941. MaxPoolType
  5942. // end_wdm
  5943. ,
  5944. //
  5945. // Note these per session types are carefully chosen so that the appropriate
  5946. // masking still applies as well as MaxPoolType above.
  5947. //
  5948. NonPagedPoolSession = 32,
  5949. PagedPoolSession = NonPagedPoolSession + 1,
  5950. NonPagedPoolMustSucceedSession = PagedPoolSession + 1,
  5951. DontUseThisTypeSession = NonPagedPoolMustSucceedSession + 1,
  5952. NonPagedPoolCacheAlignedSession = DontUseThisTypeSession + 1,
  5953. PagedPoolCacheAlignedSession = NonPagedPoolCacheAlignedSession + 1,
  5954. NonPagedPoolCacheAlignedMustSSession = PagedPoolCacheAlignedSession + 1,
  5955. // begin_wdm
  5956. } POOL_TYPE;
  5957. #define POOL_COLD_ALLOCATION 256 // Note this cannot encode into the header.
  5958. // end_ntddk end_wdm end_nthal end_ntifs end_ntndis begin_ntosp
  5959. //
  5960. // The following two definitions control the raising of exceptions on quota
  5961. // and allocation failures.
  5962. //
  5963. #define POOL_QUOTA_FAIL_INSTEAD_OF_RAISE 8
  5964. #define POOL_RAISE_IF_ALLOCATION_FAILURE 16 // ntifs
  5965. #define POOL_MM_ALLOCATION 0x80000000 // Note this cannot encode into the header.
  5966. DECLSPEC_DEPRECATED_DDK // Use ExAllocatePoolWithTag
  5967. NTKERNELAPI
  5968. PVOID
  5969. ExAllocatePool(
  5970. IN POOL_TYPE PoolType,
  5971. IN SIZE_T NumberOfBytes
  5972. );
  5973. DECLSPEC_DEPRECATED_DDK // Use ExAllocatePoolWithQuotaTag
  5974. NTKERNELAPI
  5975. PVOID
  5976. ExAllocatePoolWithQuota(
  5977. IN POOL_TYPE PoolType,
  5978. IN SIZE_T NumberOfBytes
  5979. );
  5980. NTKERNELAPI
  5981. PVOID
  5982. NTAPI
  5983. ExAllocatePoolWithTag(
  5984. IN POOL_TYPE PoolType,
  5985. IN SIZE_T NumberOfBytes,
  5986. IN ULONG Tag
  5987. );
  5988. //
  5989. // _EX_POOL_PRIORITY_ provides a method for the system to handle requests
  5990. // intelligently in low resource conditions.
  5991. //
  5992. // LowPoolPriority should be used when it is acceptable to the driver for the
  5993. // mapping request to fail if the system is low on resources. An example of
  5994. // this could be for a non-critical network connection where the driver can
  5995. // handle the failure case when system resources are close to being depleted.
  5996. //
  5997. // NormalPoolPriority should be used when it is acceptable to the driver for the
  5998. // mapping request to fail if the system is very low on resources. An example
  5999. // of this could be for a non-critical local filesystem request.
  6000. //
  6001. // HighPoolPriority should be used when it is unacceptable to the driver for the
  6002. // mapping request to fail unless the system is completely out of resources.
  6003. // An example of this would be the paging file path in a driver.
  6004. //
  6005. // SpecialPool can be specified to bound the allocation at a page end (or
  6006. // beginning). This should only be done on systems being debugged as the
  6007. // memory cost is expensive.
  6008. //
  6009. // N.B. These values are very carefully chosen so that the pool allocation
  6010. // code can quickly crack the priority request.
  6011. //
  6012. typedef enum _EX_POOL_PRIORITY {
  6013. LowPoolPriority,
  6014. LowPoolPrioritySpecialPoolOverrun = 8,
  6015. LowPoolPrioritySpecialPoolUnderrun = 9,
  6016. NormalPoolPriority = 16,
  6017. NormalPoolPrioritySpecialPoolOverrun = 24,
  6018. NormalPoolPrioritySpecialPoolUnderrun = 25,
  6019. HighPoolPriority = 32,
  6020. HighPoolPrioritySpecialPoolOverrun = 40,
  6021. HighPoolPrioritySpecialPoolUnderrun = 41
  6022. } EX_POOL_PRIORITY;
  6023. NTKERNELAPI
  6024. PVOID
  6025. NTAPI
  6026. ExAllocatePoolWithTagPriority(
  6027. IN POOL_TYPE PoolType,
  6028. IN SIZE_T NumberOfBytes,
  6029. IN ULONG Tag,
  6030. IN EX_POOL_PRIORITY Priority
  6031. );
  6032. #ifndef POOL_TAGGING
  6033. #define ExAllocatePoolWithTag(a,b,c) ExAllocatePool(a,b)
  6034. #endif //POOL_TAGGING
  6035. NTKERNELAPI
  6036. PVOID
  6037. ExAllocatePoolWithQuotaTag(
  6038. IN POOL_TYPE PoolType,
  6039. IN SIZE_T NumberOfBytes,
  6040. IN ULONG Tag
  6041. );
  6042. #ifndef POOL_TAGGING
  6043. #define ExAllocatePoolWithQuotaTag(a,b,c) ExAllocatePoolWithQuota(a,b)
  6044. #endif //POOL_TAGGING
  6045. NTKERNELAPI
  6046. VOID
  6047. NTAPI
  6048. ExFreePool(
  6049. IN PVOID P
  6050. );
  6051. // end_wdm
  6052. #if defined(POOL_TAGGING)
  6053. #define ExFreePool(a) ExFreePoolWithTag(a,0)
  6054. #endif
  6055. //
  6056. // If high order bit in Pool tag is set, then must use ExFreePoolWithTag to free
  6057. //
  6058. #define PROTECTED_POOL 0x80000000
  6059. // begin_wdm
  6060. NTKERNELAPI
  6061. VOID
  6062. ExFreePoolWithTag(
  6063. IN PVOID P,
  6064. IN ULONG Tag
  6065. );
  6066. // end_ntddk end_wdm end_nthal end_ntifs
  6067. #ifndef POOL_TAGGING
  6068. #define ExFreePoolWithTag(a,b) ExFreePool(a)
  6069. #endif //POOL_TAGGING
  6070. NTKERNELAPI // ntifs
  6071. SIZE_T // ntifs
  6072. ExQueryPoolBlockSize ( // ntifs
  6073. IN PVOID PoolBlock, // ntifs
  6074. OUT PBOOLEAN QuotaCharged // ntifs
  6075. ); // ntifs
  6076. //
  6077. // Routines to support fast mutexes.
  6078. //
  6079. typedef struct _FAST_MUTEX {
  6080. LONG Count;
  6081. PKTHREAD Owner;
  6082. ULONG Contention;
  6083. KEVENT Event;
  6084. ULONG OldIrql;
  6085. } FAST_MUTEX, *PFAST_MUTEX;
  6086. #define ExInitializeFastMutex(_FastMutex) \
  6087. (_FastMutex)->Count = 1; \
  6088. (_FastMutex)->Owner = NULL; \
  6089. (_FastMutex)->Contention = 0; \
  6090. KeInitializeEvent(&(_FastMutex)->Event, \
  6091. SynchronizationEvent, \
  6092. FALSE);
  6093. NTKERNELAPI
  6094. VOID
  6095. FASTCALL
  6096. ExAcquireFastMutexUnsafe (
  6097. IN PFAST_MUTEX FastMutex
  6098. );
  6099. NTKERNELAPI
  6100. VOID
  6101. FASTCALL
  6102. ExReleaseFastMutexUnsafe (
  6103. IN PFAST_MUTEX FastMutex
  6104. );
  6105. #if defined(_IA64_) || defined(_AMD64_)
  6106. NTKERNELAPI
  6107. VOID
  6108. FASTCALL
  6109. ExAcquireFastMutex (
  6110. IN PFAST_MUTEX FastMutex
  6111. );
  6112. NTKERNELAPI
  6113. VOID
  6114. FASTCALL
  6115. ExReleaseFastMutex (
  6116. IN PFAST_MUTEX FastMutex
  6117. );
  6118. NTKERNELAPI
  6119. BOOLEAN
  6120. FASTCALL
  6121. ExTryToAcquireFastMutex (
  6122. IN PFAST_MUTEX FastMutex
  6123. );
  6124. #elif defined(_X86_)
  6125. NTHALAPI
  6126. VOID
  6127. FASTCALL
  6128. ExAcquireFastMutex (
  6129. IN PFAST_MUTEX FastMutex
  6130. );
  6131. NTHALAPI
  6132. VOID
  6133. FASTCALL
  6134. ExReleaseFastMutex (
  6135. IN PFAST_MUTEX FastMutex
  6136. );
  6137. NTHALAPI
  6138. BOOLEAN
  6139. FASTCALL
  6140. ExTryToAcquireFastMutex (
  6141. IN PFAST_MUTEX FastMutex
  6142. );
  6143. #else
  6144. #error "Target architecture not defined"
  6145. #endif
  6146. //
  6147. #if defined(_WIN64)
  6148. #define ExInterlockedAddLargeStatistic(Addend, Increment) \
  6149. (VOID) InterlockedAdd64(&(Addend)->QuadPart, Increment)
  6150. #else
  6151. #ifdef __cplusplus
  6152. extern "C" {
  6153. #endif
  6154. LONG
  6155. _InterlockedAddLargeStatistic (
  6156. IN PLONGLONG Addend,
  6157. IN ULONG Increment
  6158. );
  6159. #ifdef __cplusplus
  6160. }
  6161. #endif
  6162. #pragma intrinsic (_InterlockedAddLargeStatistic)
  6163. #define ExInterlockedAddLargeStatistic(Addend,Increment) \
  6164. (VOID) _InterlockedAddLargeStatistic ((PLONGLONG)&(Addend)->QuadPart, Increment)
  6165. #endif
  6166. // end_ntndis
  6167. NTKERNELAPI
  6168. LARGE_INTEGER
  6169. ExInterlockedAddLargeInteger (
  6170. IN PLARGE_INTEGER Addend,
  6171. IN LARGE_INTEGER Increment,
  6172. IN PKSPIN_LOCK Lock
  6173. );
  6174. NTKERNELAPI
  6175. ULONG
  6176. FASTCALL
  6177. ExInterlockedAddUlong (
  6178. IN PULONG Addend,
  6179. IN ULONG Increment,
  6180. IN PKSPIN_LOCK Lock
  6181. );
  6182. #if defined(_AMD64_) || defined(_AXP64_) || defined(_IA64_)
  6183. #define ExInterlockedCompareExchange64(Destination, Exchange, Comperand, Lock) \
  6184. InterlockedCompareExchange64(Destination, *(Exchange), *(Comperand))
  6185. #elif defined(_ALPHA_)
  6186. #define ExInterlockedCompareExchange64(Destination, Exchange, Comperand, Lock) \
  6187. ExpInterlockedCompareExchange64(Destination, Exchange, Comperand)
  6188. #else
  6189. #define ExInterlockedCompareExchange64(Destination, Exchange, Comperand, Lock) \
  6190. ExfInterlockedCompareExchange64(Destination, Exchange, Comperand)
  6191. #endif
  6192. NTKERNELAPI
  6193. PLIST_ENTRY
  6194. FASTCALL
  6195. ExInterlockedInsertHeadList (
  6196. IN PLIST_ENTRY ListHead,
  6197. IN PLIST_ENTRY ListEntry,
  6198. IN PKSPIN_LOCK Lock
  6199. );
  6200. NTKERNELAPI
  6201. PLIST_ENTRY
  6202. FASTCALL
  6203. ExInterlockedInsertTailList (
  6204. IN PLIST_ENTRY ListHead,
  6205. IN PLIST_ENTRY ListEntry,
  6206. IN PKSPIN_LOCK Lock
  6207. );
  6208. NTKERNELAPI
  6209. PLIST_ENTRY
  6210. FASTCALL
  6211. ExInterlockedRemoveHeadList (
  6212. IN PLIST_ENTRY ListHead,
  6213. IN PKSPIN_LOCK Lock
  6214. );
  6215. NTKERNELAPI
  6216. PSINGLE_LIST_ENTRY
  6217. FASTCALL
  6218. ExInterlockedPopEntryList (
  6219. IN PSINGLE_LIST_ENTRY ListHead,
  6220. IN PKSPIN_LOCK Lock
  6221. );
  6222. NTKERNELAPI
  6223. PSINGLE_LIST_ENTRY
  6224. FASTCALL
  6225. ExInterlockedPushEntryList (
  6226. IN PSINGLE_LIST_ENTRY ListHead,
  6227. IN PSINGLE_LIST_ENTRY ListEntry,
  6228. IN PKSPIN_LOCK Lock
  6229. );
  6230. //
  6231. // Define interlocked sequenced listhead functions.
  6232. //
  6233. // A sequenced interlocked list is a singly linked list with a header that
  6234. // contains the current depth and a sequence number. Each time an entry is
  6235. // inserted or removed from the list the depth is updated and the sequence
  6236. // number is incremented. This enables AMD64, IA64, and Pentium and later
  6237. // machines to insert and remove from the list without the use of spinlocks.
  6238. //
  6239. #if !defined(_WINBASE_)
  6240. /*++
  6241. Routine Description:
  6242. This function initializes a sequenced singly linked listhead.
  6243. Arguments:
  6244. SListHead - Supplies a pointer to a sequenced singly linked listhead.
  6245. Return Value:
  6246. None.
  6247. --*/
  6248. #if defined(_WIN64) && (defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_) || defined(_NTHAL_) || defined(_NTOSP_))
  6249. NTKERNELAPI
  6250. VOID
  6251. InitializeSListHead (
  6252. IN PSLIST_HEADER SListHead
  6253. );
  6254. #else
  6255. __inline
  6256. VOID
  6257. InitializeSListHead (
  6258. IN PSLIST_HEADER SListHead
  6259. )
  6260. {
  6261. #ifdef _WIN64
  6262. //
  6263. // Slist headers must be 16 byte aligned.
  6264. //
  6265. if ((ULONG_PTR) SListHead & 0x0f) {
  6266. DbgPrint( "InitializeSListHead unaligned Slist header. Address = %p, Caller = %p\n", SListHead, _ReturnAddress());
  6267. RtlRaiseStatus(STATUS_DATATYPE_MISALIGNMENT);
  6268. }
  6269. #endif
  6270. SListHead->Alignment = 0;
  6271. //
  6272. // For IA-64 we save the region number of the elements of the list in a
  6273. // separate field. This imposes the requirement that all elements stored
  6274. // in the list are from the same region.
  6275. #if defined(_IA64_)
  6276. SListHead->Region = (ULONG_PTR)SListHead & VRN_MASK;
  6277. #elif defined(_AMD64_)
  6278. SListHead->Region = 0;
  6279. #endif
  6280. return;
  6281. }
  6282. #endif
  6283. #endif // !defined(_WINBASE_)
  6284. #define ExInitializeSListHead InitializeSListHead
  6285. PSLIST_ENTRY
  6286. FirstEntrySList (
  6287. IN const SLIST_HEADER *SListHead
  6288. );
  6289. /*++
  6290. Routine Description:
  6291. This function queries the current number of entries contained in a
  6292. sequenced single linked list.
  6293. Arguments:
  6294. SListHead - Supplies a pointer to the sequenced listhead which is
  6295. be queried.
  6296. Return Value:
  6297. The current number of entries in the sequenced singly linked list is
  6298. returned as the function value.
  6299. --*/
  6300. #if defined(_WIN64)
  6301. #if (defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_) || defined(_NTHAL_) || defined(_NTOSP_))
  6302. NTKERNELAPI
  6303. USHORT
  6304. ExQueryDepthSList (
  6305. IN PSLIST_HEADER SListHead
  6306. );
  6307. #else
  6308. __inline
  6309. USHORT
  6310. ExQueryDepthSList (
  6311. IN PSLIST_HEADER SListHead
  6312. )
  6313. {
  6314. return (USHORT)(SListHead->Alignment & 0xffff);
  6315. }
  6316. #endif
  6317. #else
  6318. #define ExQueryDepthSList(_listhead_) (_listhead_)->Depth
  6319. #endif
  6320. #if defined(_WIN64)
  6321. #define ExInterlockedPopEntrySList(Head, Lock) \
  6322. ExpInterlockedPopEntrySList(Head)
  6323. #define ExInterlockedPushEntrySList(Head, Entry, Lock) \
  6324. ExpInterlockedPushEntrySList(Head, Entry)
  6325. #define ExInterlockedFlushSList(Head) \
  6326. ExpInterlockedFlushSList(Head)
  6327. #if !defined(_WINBASE_)
  6328. #define InterlockedPopEntrySList(Head) \
  6329. ExpInterlockedPopEntrySList(Head)
  6330. #define InterlockedPushEntrySList(Head, Entry) \
  6331. ExpInterlockedPushEntrySList(Head, Entry)
  6332. #define InterlockedFlushSList(Head) \
  6333. ExpInterlockedFlushSList(Head)
  6334. #define QueryDepthSList(Head) \
  6335. ExQueryDepthSList(Head)
  6336. #endif // !defined(_WINBASE_)
  6337. NTKERNELAPI
  6338. PSLIST_ENTRY
  6339. ExpInterlockedPopEntrySList (
  6340. IN PSLIST_HEADER ListHead
  6341. );
  6342. NTKERNELAPI
  6343. PSLIST_ENTRY
  6344. ExpInterlockedPushEntrySList (
  6345. IN PSLIST_HEADER ListHead,
  6346. IN PSLIST_ENTRY ListEntry
  6347. );
  6348. NTKERNELAPI
  6349. PSLIST_ENTRY
  6350. ExpInterlockedFlushSList (
  6351. IN PSLIST_HEADER ListHead
  6352. );
  6353. #else
  6354. #if defined(_WIN2K_COMPAT_SLIST_USAGE) && defined(_X86_)
  6355. NTKERNELAPI
  6356. PSLIST_ENTRY
  6357. FASTCALL
  6358. ExInterlockedPopEntrySList (
  6359. IN PSLIST_HEADER ListHead,
  6360. IN PKSPIN_LOCK Lock
  6361. );
  6362. NTKERNELAPI
  6363. PSLIST_ENTRY
  6364. FASTCALL
  6365. ExInterlockedPushEntrySList (
  6366. IN PSLIST_HEADER ListHead,
  6367. IN PSLIST_ENTRY ListEntry,
  6368. IN PKSPIN_LOCK Lock
  6369. );
  6370. #else
  6371. #define ExInterlockedPopEntrySList(ListHead, Lock) \
  6372. InterlockedPopEntrySList(ListHead)
  6373. #define ExInterlockedPushEntrySList(ListHead, ListEntry, Lock) \
  6374. InterlockedPushEntrySList(ListHead, ListEntry)
  6375. #endif
  6376. NTKERNELAPI
  6377. PSLIST_ENTRY
  6378. FASTCALL
  6379. ExInterlockedFlushSList (
  6380. IN PSLIST_HEADER ListHead
  6381. );
  6382. #if !defined(_WINBASE_)
  6383. NTKERNELAPI
  6384. PSLIST_ENTRY
  6385. FASTCALL
  6386. InterlockedPopEntrySList (
  6387. IN PSLIST_HEADER ListHead
  6388. );
  6389. NTKERNELAPI
  6390. PSLIST_ENTRY
  6391. FASTCALL
  6392. InterlockedPushEntrySList (
  6393. IN PSLIST_HEADER ListHead,
  6394. IN PSLIST_ENTRY ListEntry
  6395. );
  6396. #define InterlockedFlushSList(Head) \
  6397. ExInterlockedFlushSList(Head)
  6398. #define QueryDepthSList(Head) \
  6399. ExQueryDepthSList(Head)
  6400. #endif // !defined(_WINBASE_)
  6401. #endif // defined(_WIN64)
  6402. typedef
  6403. PVOID
  6404. (*PALLOCATE_FUNCTION) (
  6405. IN POOL_TYPE PoolType,
  6406. IN SIZE_T NumberOfBytes,
  6407. IN ULONG Tag
  6408. );
  6409. typedef
  6410. VOID
  6411. (*PFREE_FUNCTION) (
  6412. IN PVOID Buffer
  6413. );
  6414. #if !defined(_WIN64) && (defined(_NTDDK_) || defined(_NTIFS_) || defined(_NDIS_))
  6415. typedef struct _GENERAL_LOOKASIDE {
  6416. #else
  6417. typedef struct DECLSPEC_CACHEALIGN _GENERAL_LOOKASIDE {
  6418. #endif
  6419. SLIST_HEADER ListHead;
  6420. USHORT Depth;
  6421. USHORT MaximumDepth;
  6422. ULONG TotalAllocates;
  6423. union {
  6424. ULONG AllocateMisses;
  6425. ULONG AllocateHits;
  6426. };
  6427. ULONG TotalFrees;
  6428. union {
  6429. ULONG FreeMisses;
  6430. ULONG FreeHits;
  6431. };
  6432. POOL_TYPE Type;
  6433. ULONG Tag;
  6434. ULONG Size;
  6435. PALLOCATE_FUNCTION Allocate;
  6436. PFREE_FUNCTION Free;
  6437. LIST_ENTRY ListEntry;
  6438. ULONG LastTotalAllocates;
  6439. union {
  6440. ULONG LastAllocateMisses;
  6441. ULONG LastAllocateHits;
  6442. };
  6443. ULONG Future[2];
  6444. } GENERAL_LOOKASIDE, *PGENERAL_LOOKASIDE;
  6445. #if !defined(_WIN64) && (defined(_NTDDK_) || defined(_NTIFS_) || defined(_NDIS_))
  6446. typedef struct _NPAGED_LOOKASIDE_LIST {
  6447. #else
  6448. typedef struct DECLSPEC_CACHEALIGN _NPAGED_LOOKASIDE_LIST {
  6449. #endif
  6450. GENERAL_LOOKASIDE L;
  6451. #if !defined(_AMD64_) && !defined(_IA64_)
  6452. KSPIN_LOCK Lock__ObsoleteButDoNotDelete;
  6453. #endif
  6454. } NPAGED_LOOKASIDE_LIST, *PNPAGED_LOOKASIDE_LIST;
  6455. NTKERNELAPI
  6456. VOID
  6457. ExInitializeNPagedLookasideList (
  6458. IN PNPAGED_LOOKASIDE_LIST Lookaside,
  6459. IN PALLOCATE_FUNCTION Allocate,
  6460. IN PFREE_FUNCTION Free,
  6461. IN ULONG Flags,
  6462. IN SIZE_T Size,
  6463. IN ULONG Tag,
  6464. IN USHORT Depth
  6465. );
  6466. NTKERNELAPI
  6467. VOID
  6468. ExDeleteNPagedLookasideList (
  6469. IN PNPAGED_LOOKASIDE_LIST Lookaside
  6470. );
  6471. __inline
  6472. PVOID
  6473. ExAllocateFromNPagedLookasideList(
  6474. IN PNPAGED_LOOKASIDE_LIST Lookaside
  6475. )
  6476. /*++
  6477. Routine Description:
  6478. This function removes (pops) the first entry from the specified
  6479. nonpaged lookaside list.
  6480. Arguments:
  6481. Lookaside - Supplies a pointer to a nonpaged lookaside list structure.
  6482. Return Value:
  6483. If an entry is removed from the specified lookaside list, then the
  6484. address of the entry is returned as the function value. Otherwise,
  6485. NULL is returned.
  6486. --*/
  6487. {
  6488. PVOID Entry;
  6489. Lookaside->L.TotalAllocates += 1;
  6490. #if defined(_WIN2K_COMPAT_SLIST_USAGE) && defined(_X86_)
  6491. Entry = ExInterlockedPopEntrySList(&Lookaside->L.ListHead,
  6492. &Lookaside->Lock__ObsoleteButDoNotDelete);
  6493. #else
  6494. Entry = InterlockedPopEntrySList(&Lookaside->L.ListHead);
  6495. #endif
  6496. if (Entry == NULL) {
  6497. Lookaside->L.AllocateMisses += 1;
  6498. Entry = (Lookaside->L.Allocate)(Lookaside->L.Type,
  6499. Lookaside->L.Size,
  6500. Lookaside->L.Tag);
  6501. }
  6502. return Entry;
  6503. }
  6504. __inline
  6505. VOID
  6506. ExFreeToNPagedLookasideList(
  6507. IN PNPAGED_LOOKASIDE_LIST Lookaside,
  6508. IN PVOID Entry
  6509. )
  6510. /*++
  6511. Routine Description:
  6512. This function inserts (pushes) the specified entry into the specified
  6513. nonpaged lookaside list.
  6514. Arguments:
  6515. Lookaside - Supplies a pointer to a nonpaged lookaside list structure.
  6516. Entry - Supples a pointer to the entry that is inserted in the
  6517. lookaside list.
  6518. Return Value:
  6519. None.
  6520. --*/
  6521. {
  6522. Lookaside->L.TotalFrees += 1;
  6523. if (ExQueryDepthSList(&Lookaside->L.ListHead) >= Lookaside->L.Depth) {
  6524. Lookaside->L.FreeMisses += 1;
  6525. (Lookaside->L.Free)(Entry);
  6526. } else {
  6527. #if defined(_WIN2K_COMPAT_SLIST_USAGE) && defined(_X86_)
  6528. ExInterlockedPushEntrySList(&Lookaside->L.ListHead,
  6529. (PSLIST_ENTRY)Entry,
  6530. &Lookaside->Lock__ObsoleteButDoNotDelete);
  6531. #else
  6532. InterlockedPushEntrySList(&Lookaside->L.ListHead,
  6533. (PSLIST_ENTRY)Entry);
  6534. #endif
  6535. }
  6536. return;
  6537. }
  6538. // end_ntndis
  6539. #if !defined(_WIN64) && (defined(_NTDDK_) || defined(_NTIFS_) || defined(_NDIS_))
  6540. typedef struct _PAGED_LOOKASIDE_LIST {
  6541. #else
  6542. typedef struct DECLSPEC_CACHEALIGN _PAGED_LOOKASIDE_LIST {
  6543. #endif
  6544. GENERAL_LOOKASIDE L;
  6545. #if !defined(_AMD64_) && !defined(_IA64_)
  6546. FAST_MUTEX Lock__ObsoleteButDoNotDelete;
  6547. #endif
  6548. } PAGED_LOOKASIDE_LIST, *PPAGED_LOOKASIDE_LIST;
  6549. NTKERNELAPI
  6550. VOID
  6551. ExInitializePagedLookasideList (
  6552. IN PPAGED_LOOKASIDE_LIST Lookaside,
  6553. IN PALLOCATE_FUNCTION Allocate,
  6554. IN PFREE_FUNCTION Free,
  6555. IN ULONG Flags,
  6556. IN SIZE_T Size,
  6557. IN ULONG Tag,
  6558. IN USHORT Depth
  6559. );
  6560. NTKERNELAPI
  6561. VOID
  6562. ExDeletePagedLookasideList (
  6563. IN PPAGED_LOOKASIDE_LIST Lookaside
  6564. );
  6565. #if defined(_WIN2K_COMPAT_SLIST_USAGE) && defined(_X86_)
  6566. NTKERNELAPI
  6567. PVOID
  6568. ExAllocateFromPagedLookasideList(
  6569. IN PPAGED_LOOKASIDE_LIST Lookaside
  6570. );
  6571. #else
  6572. __inline
  6573. PVOID
  6574. ExAllocateFromPagedLookasideList(
  6575. IN PPAGED_LOOKASIDE_LIST Lookaside
  6576. )
  6577. /*++
  6578. Routine Description:
  6579. This function removes (pops) the first entry from the specified
  6580. paged lookaside list.
  6581. Arguments:
  6582. Lookaside - Supplies a pointer to a paged lookaside list structure.
  6583. Return Value:
  6584. If an entry is removed from the specified lookaside list, then the
  6585. address of the entry is returned as the function value. Otherwise,
  6586. NULL is returned.
  6587. --*/
  6588. {
  6589. PVOID Entry;
  6590. Lookaside->L.TotalAllocates += 1;
  6591. Entry = InterlockedPopEntrySList(&Lookaside->L.ListHead);
  6592. if (Entry == NULL) {
  6593. Lookaside->L.AllocateMisses += 1;
  6594. Entry = (Lookaside->L.Allocate)(Lookaside->L.Type,
  6595. Lookaside->L.Size,
  6596. Lookaside->L.Tag);
  6597. }
  6598. return Entry;
  6599. }
  6600. #endif
  6601. #if defined(_WIN2K_COMPAT_SLIST_USAGE) && defined(_X86_)
  6602. NTKERNELAPI
  6603. VOID
  6604. ExFreeToPagedLookasideList(
  6605. IN PPAGED_LOOKASIDE_LIST Lookaside,
  6606. IN PVOID Entry
  6607. );
  6608. #else
  6609. __inline
  6610. VOID
  6611. ExFreeToPagedLookasideList(
  6612. IN PPAGED_LOOKASIDE_LIST Lookaside,
  6613. IN PVOID Entry
  6614. )
  6615. /*++
  6616. Routine Description:
  6617. This function inserts (pushes) the specified entry into the specified
  6618. paged lookaside list.
  6619. Arguments:
  6620. Lookaside - Supplies a pointer to a nonpaged lookaside list structure.
  6621. Entry - Supples a pointer to the entry that is inserted in the
  6622. lookaside list.
  6623. Return Value:
  6624. None.
  6625. --*/
  6626. {
  6627. Lookaside->L.TotalFrees += 1;
  6628. if (ExQueryDepthSList(&Lookaside->L.ListHead) >= Lookaside->L.Depth) {
  6629. Lookaside->L.FreeMisses += 1;
  6630. (Lookaside->L.Free)(Entry);
  6631. } else {
  6632. InterlockedPushEntrySList(&Lookaside->L.ListHead,
  6633. (PSLIST_ENTRY)Entry);
  6634. }
  6635. return;
  6636. }
  6637. #endif
  6638. NTKERNELAPI
  6639. VOID
  6640. NTAPI
  6641. ProbeForRead(
  6642. IN CONST VOID *Address,
  6643. IN SIZE_T Length,
  6644. IN ULONG Alignment
  6645. );
  6646. // Probe function definitions
  6647. //
  6648. // Probe for read functions.
  6649. //
  6650. //++
  6651. //
  6652. // VOID
  6653. // ProbeForRead(
  6654. // IN PVOID Address,
  6655. // IN ULONG Length,
  6656. // IN ULONG Alignment
  6657. // )
  6658. //
  6659. //--
  6660. #define ProbeForRead(Address, Length, Alignment) { \
  6661. ASSERT(((Alignment) == 1) || ((Alignment) == 2) || \
  6662. ((Alignment) == 4) || ((Alignment) == 8) || \
  6663. ((Alignment) == 16)); \
  6664. \
  6665. if ((Length) != 0) { \
  6666. if (((ULONG_PTR)(Address) & ((Alignment) - 1)) != 0) { \
  6667. ExRaiseDatatypeMisalignment(); \
  6668. \
  6669. } \
  6670. if ((((ULONG_PTR)(Address) + (Length)) < (ULONG_PTR)(Address)) || \
  6671. (((ULONG_PTR)(Address) + (Length)) > (ULONG_PTR)MM_USER_PROBE_ADDRESS)) { \
  6672. ExRaiseAccessViolation(); \
  6673. } \
  6674. } \
  6675. }
  6676. //++
  6677. //
  6678. // VOID
  6679. // ProbeForReadSmallStructure(
  6680. // IN PVOID Address,
  6681. // IN ULONG Length,
  6682. // IN ULONG Alignment
  6683. // )
  6684. //
  6685. //--
  6686. #define ProbeForReadSmallStructure(Address,Size,Alignment) { \
  6687. ASSERT(((Alignment) == 1) || ((Alignment) == 2) || \
  6688. ((Alignment) == 4) || ((Alignment) == 8) || \
  6689. ((Alignment) == 16)); \
  6690. if (Size == 0 || Size > 0x10000) { \
  6691. ASSERT (0); \
  6692. ProbeForRead (Address,Size,Alignment); \
  6693. } else { \
  6694. if (((ULONG_PTR)(Address) & ((Alignment) - 1)) != 0) { \
  6695. ExRaiseDatatypeMisalignment(); \
  6696. } \
  6697. if ((ULONG_PTR)(Address) >= (ULONG_PTR)MM_USER_PROBE_ADDRESS) { \
  6698. *(volatile ULONG * const)MM_USER_PROBE_ADDRESS = 0; \
  6699. } \
  6700. } \
  6701. }
  6702. //++
  6703. //
  6704. // BOOLEAN
  6705. // ProbeAndReadBoolean(
  6706. // IN PBOOLEAN Address
  6707. // )
  6708. //
  6709. //--
  6710. #define ProbeAndReadBoolean(Address) \
  6711. (((Address) >= (BOOLEAN * const)MM_USER_PROBE_ADDRESS) ? \
  6712. (*(volatile BOOLEAN * const)MM_USER_PROBE_ADDRESS) : (*(volatile BOOLEAN *)(Address)))
  6713. //++
  6714. //
  6715. // CHAR
  6716. // ProbeAndReadChar(
  6717. // IN PCHAR Address
  6718. // )
  6719. //
  6720. //--
  6721. #define ProbeAndReadChar(Address) \
  6722. (((Address) >= (CHAR * const)MM_USER_PROBE_ADDRESS) ? \
  6723. (*(volatile CHAR * const)MM_USER_PROBE_ADDRESS) : (*(volatile CHAR *)(Address)))
  6724. //++
  6725. //
  6726. // UCHAR
  6727. // ProbeAndReadUchar(
  6728. // IN PUCHAR Address
  6729. // )
  6730. //
  6731. //--
  6732. #define ProbeAndReadUchar(Address) \
  6733. (((Address) >= (UCHAR * const)MM_USER_PROBE_ADDRESS) ? \
  6734. (*(volatile UCHAR * const)MM_USER_PROBE_ADDRESS) : (*(volatile UCHAR *)(Address)))
  6735. //++
  6736. //
  6737. // SHORT
  6738. // ProbeAndReadShort(
  6739. // IN PSHORT Address
  6740. // )
  6741. //
  6742. //--
  6743. #define ProbeAndReadShort(Address) \
  6744. (((Address) >= (SHORT * const)MM_USER_PROBE_ADDRESS) ? \
  6745. (*(volatile SHORT * const)MM_USER_PROBE_ADDRESS) : (*(volatile SHORT *)(Address)))
  6746. //++
  6747. //
  6748. // USHORT
  6749. // ProbeAndReadUshort(
  6750. // IN PUSHORT Address
  6751. // )
  6752. //
  6753. //--
  6754. #define ProbeAndReadUshort(Address) \
  6755. (((Address) >= (USHORT * const)MM_USER_PROBE_ADDRESS) ? \
  6756. (*(volatile USHORT * const)MM_USER_PROBE_ADDRESS) : (*(volatile USHORT *)(Address)))
  6757. //++
  6758. //
  6759. // HANDLE
  6760. // ProbeAndReadHandle(
  6761. // IN PHANDLE Address
  6762. // )
  6763. //
  6764. //--
  6765. #define ProbeAndReadHandle(Address) \
  6766. (((Address) >= (HANDLE * const)MM_USER_PROBE_ADDRESS) ? \
  6767. (*(volatile HANDLE * const)MM_USER_PROBE_ADDRESS) : (*(volatile HANDLE *)(Address)))
  6768. //++
  6769. //
  6770. // PVOID
  6771. // ProbeAndReadPointer(
  6772. // IN PVOID *Address
  6773. // )
  6774. //
  6775. //--
  6776. #define ProbeAndReadPointer(Address) \
  6777. (((Address) >= (PVOID * const)MM_USER_PROBE_ADDRESS) ? \
  6778. (*(volatile PVOID * const)MM_USER_PROBE_ADDRESS) : (*(volatile PVOID *)(Address)))
  6779. //++
  6780. //
  6781. // LONG
  6782. // ProbeAndReadLong(
  6783. // IN PLONG Address
  6784. // )
  6785. //
  6786. //--
  6787. #define ProbeAndReadLong(Address) \
  6788. (((Address) >= (LONG * const)MM_USER_PROBE_ADDRESS) ? \
  6789. (*(volatile LONG * const)MM_USER_PROBE_ADDRESS) : (*(volatile LONG *)(Address)))
  6790. //++
  6791. //
  6792. // ULONG
  6793. // ProbeAndReadUlong(
  6794. // IN PULONG Address
  6795. // )
  6796. //
  6797. //--
  6798. #define ProbeAndReadUlong(Address) \
  6799. (((Address) >= (ULONG * const)MM_USER_PROBE_ADDRESS) ? \
  6800. (*(volatile ULONG * const)MM_USER_PROBE_ADDRESS) : (*(volatile ULONG *)(Address)))
  6801. //++
  6802. //
  6803. // ULONG_PTR
  6804. // ProbeAndReadUlong_ptr(
  6805. // IN PULONG_PTR Address
  6806. // )
  6807. //
  6808. //--
  6809. #define ProbeAndReadUlong_ptr(Address) \
  6810. (((Address) >= (ULONG_PTR * const)MM_USER_PROBE_ADDRESS) ? \
  6811. (*(volatile ULONG_PTR * const)MM_USER_PROBE_ADDRESS) : (*(volatile ULONG_PTR *)(Address)))
  6812. //++
  6813. //
  6814. // QUAD
  6815. // ProbeAndReadQuad(
  6816. // IN PQUAD Address
  6817. // )
  6818. //
  6819. //--
  6820. #define ProbeAndReadQuad(Address) \
  6821. (((Address) >= (QUAD * const)MM_USER_PROBE_ADDRESS) ? \
  6822. (*(volatile QUAD * const)MM_USER_PROBE_ADDRESS) : (*(volatile QUAD *)(Address)))
  6823. //++
  6824. //
  6825. // UQUAD
  6826. // ProbeAndReadUquad(
  6827. // IN PUQUAD Address
  6828. // )
  6829. //
  6830. //--
  6831. #define ProbeAndReadUquad(Address) \
  6832. (((Address) >= (UQUAD * const)MM_USER_PROBE_ADDRESS) ? \
  6833. (*(volatile UQUAD * const)MM_USER_PROBE_ADDRESS) : (*(volatile UQUAD *)(Address)))
  6834. //++
  6835. //
  6836. // LARGE_INTEGER
  6837. // ProbeAndReadLargeInteger(
  6838. // IN PLARGE_INTEGER Source
  6839. // )
  6840. //
  6841. //--
  6842. #define ProbeAndReadLargeInteger(Source) \
  6843. (((Source) >= (LARGE_INTEGER * const)MM_USER_PROBE_ADDRESS) ? \
  6844. (*(volatile LARGE_INTEGER * const)MM_USER_PROBE_ADDRESS) : (*(volatile LARGE_INTEGER *)(Source)))
  6845. //++
  6846. //
  6847. // ULARGE_INTEGER
  6848. // ProbeAndReadUlargeInteger(
  6849. // IN PULARGE_INTEGER Source
  6850. // )
  6851. //
  6852. //--
  6853. #define ProbeAndReadUlargeInteger(Source) \
  6854. (((Source) >= (ULARGE_INTEGER * const)MM_USER_PROBE_ADDRESS) ? \
  6855. (*(volatile ULARGE_INTEGER * const)MM_USER_PROBE_ADDRESS) : (*(volatile ULARGE_INTEGER *)(Source)))
  6856. //++
  6857. //
  6858. // UNICODE_STRING
  6859. // ProbeAndReadUnicodeString(
  6860. // IN PUNICODE_STRING Source
  6861. // )
  6862. //
  6863. //--
  6864. #define ProbeAndReadUnicodeString(Source) \
  6865. (((Source) >= (UNICODE_STRING * const)MM_USER_PROBE_ADDRESS) ? \
  6866. (*(volatile UNICODE_STRING * const)MM_USER_PROBE_ADDRESS) : (*(volatile UNICODE_STRING *)(Source)))
  6867. //++
  6868. //
  6869. // <STRUCTURE>
  6870. // ProbeAndReadStructure(
  6871. // IN P<STRUCTURE> Source
  6872. // <STRUCTURE>
  6873. // )
  6874. //
  6875. //--
  6876. #define ProbeAndReadStructure(Source,STRUCTURE) \
  6877. (((Source) >= (STRUCTURE * const)MM_USER_PROBE_ADDRESS) ? \
  6878. (*(STRUCTURE * const)MM_USER_PROBE_ADDRESS) : (*(STRUCTURE *)(Source)))
  6879. //
  6880. // Probe for write functions definitions.
  6881. //
  6882. //++
  6883. //
  6884. // VOID
  6885. // ProbeForWriteBoolean(
  6886. // IN PBOOLEAN Address
  6887. // )
  6888. //
  6889. //--
  6890. #define ProbeForWriteBoolean(Address) { \
  6891. if ((Address) >= (BOOLEAN * const)MM_USER_PROBE_ADDRESS) { \
  6892. *(volatile BOOLEAN * const)MM_USER_PROBE_ADDRESS = 0; \
  6893. } \
  6894. \
  6895. *(volatile BOOLEAN *)(Address) = *(volatile BOOLEAN *)(Address); \
  6896. }
  6897. //++
  6898. //
  6899. // VOID
  6900. // ProbeForWriteChar(
  6901. // IN PCHAR Address
  6902. // )
  6903. //
  6904. //--
  6905. #define ProbeForWriteChar(Address) { \
  6906. if ((Address) >= (CHAR * const)MM_USER_PROBE_ADDRESS) { \
  6907. *(volatile CHAR * const)MM_USER_PROBE_ADDRESS = 0; \
  6908. } \
  6909. \
  6910. *(volatile CHAR *)(Address) = *(volatile CHAR *)(Address); \
  6911. }
  6912. //++
  6913. //
  6914. // VOID
  6915. // ProbeForWriteUchar(
  6916. // IN PUCHAR Address
  6917. // )
  6918. //
  6919. //--
  6920. #define ProbeForWriteUchar(Address) { \
  6921. if ((Address) >= (UCHAR * const)MM_USER_PROBE_ADDRESS) { \
  6922. *(volatile UCHAR * const)MM_USER_PROBE_ADDRESS = 0; \
  6923. } \
  6924. \
  6925. *(volatile UCHAR *)(Address) = *(volatile UCHAR *)(Address); \
  6926. }
  6927. //++
  6928. //
  6929. // VOID
  6930. // ProbeForWriteIoStatus(
  6931. // IN PIO_STATUS_BLOCK Address
  6932. // )
  6933. //
  6934. //--
  6935. #define ProbeForWriteIoStatus(Address) { \
  6936. if ((Address) >= (IO_STATUS_BLOCK * const)MM_USER_PROBE_ADDRESS) { \
  6937. *(volatile ULONG * const)MM_USER_PROBE_ADDRESS = 0; \
  6938. } \
  6939. \
  6940. *(volatile IO_STATUS_BLOCK *)(Address) = *(volatile IO_STATUS_BLOCK *)(Address); \
  6941. }
  6942. #ifdef _WIN64
  6943. #define ProbeForWriteIoStatusEx(Address, Cookie) { \
  6944. if ((Address) >= (IO_STATUS_BLOCK * const)MM_USER_PROBE_ADDRESS) { \
  6945. *(volatile ULONG * const)MM_USER_PROBE_ADDRESS = 0; \
  6946. } \
  6947. if ((ULONG_PTR)(Cookie) & (ULONG)1) { \
  6948. *(volatile IO_STATUS_BLOCK32 *)(Address) = *(volatile IO_STATUS_BLOCK32 *)(Address);\
  6949. } else { \
  6950. *(volatile IO_STATUS_BLOCK *)(Address) = *(volatile IO_STATUS_BLOCK *)(Address); \
  6951. } \
  6952. }
  6953. #else
  6954. #define ProbeForWriteIoStatusEx(Address, Cookie) ProbeForWriteIoStatus(Address)
  6955. #endif
  6956. //++
  6957. //
  6958. // VOID
  6959. // ProbeForWriteShort(
  6960. // IN PSHORT Address
  6961. // )
  6962. //
  6963. //--
  6964. #define ProbeForWriteShort(Address) { \
  6965. if ((Address) >= (SHORT * const)MM_USER_PROBE_ADDRESS) { \
  6966. *(volatile SHORT * const)MM_USER_PROBE_ADDRESS = 0; \
  6967. } \
  6968. \
  6969. *(volatile SHORT *)(Address) = *(volatile SHORT *)(Address); \
  6970. }
  6971. //++
  6972. //
  6973. // VOID
  6974. // ProbeForWriteUshort(
  6975. // IN PUSHORT Address
  6976. // )
  6977. //
  6978. //--
  6979. #define ProbeForWriteUshort(Address) { \
  6980. if ((Address) >= (USHORT * const)MM_USER_PROBE_ADDRESS) { \
  6981. *(volatile USHORT * const)MM_USER_PROBE_ADDRESS = 0; \
  6982. } \
  6983. \
  6984. *(volatile USHORT *)(Address) = *(volatile USHORT *)(Address); \
  6985. }
  6986. //++
  6987. //
  6988. // VOID
  6989. // ProbeForWriteHandle(
  6990. // IN PHANDLE Address
  6991. // )
  6992. //
  6993. //--
  6994. #define ProbeForWriteHandle(Address) { \
  6995. if ((Address) >= (HANDLE * const)MM_USER_PROBE_ADDRESS) { \
  6996. *(volatile HANDLE * const)MM_USER_PROBE_ADDRESS = 0; \
  6997. } \
  6998. \
  6999. *(volatile HANDLE *)(Address) = *(volatile HANDLE *)(Address); \
  7000. }
  7001. //++
  7002. //
  7003. // VOID
  7004. // ProbeAndZeroHandle(
  7005. // IN PHANDLE Address
  7006. // )
  7007. //
  7008. //--
  7009. #define ProbeAndZeroHandle(Address) { \
  7010. if ((Address) >= (HANDLE * const)MM_USER_PROBE_ADDRESS) { \
  7011. *(volatile HANDLE * const)MM_USER_PROBE_ADDRESS = 0; \
  7012. } \
  7013. \
  7014. *(volatile HANDLE *)(Address) = 0; \
  7015. }
  7016. //++
  7017. //
  7018. // VOID
  7019. // ProbeForWritePointer(
  7020. // IN PVOID Address
  7021. // )
  7022. //
  7023. //--
  7024. #define ProbeForWritePointer(Address) { \
  7025. if ((PVOID *)(Address) >= (PVOID * const)MM_USER_PROBE_ADDRESS) { \
  7026. *(volatile PVOID * const)MM_USER_PROBE_ADDRESS = NULL; \
  7027. } \
  7028. \
  7029. *(volatile PVOID *)(Address) = *(volatile PVOID *)(Address); \
  7030. }
  7031. //++
  7032. //
  7033. // VOID
  7034. // ProbeAndNullPointer(
  7035. // IN PVOID *Address
  7036. // )
  7037. //
  7038. //--
  7039. #define ProbeAndNullPointer(Address) { \
  7040. if ((PVOID *)(Address) >= (PVOID * const)MM_USER_PROBE_ADDRESS) { \
  7041. *(volatile PVOID * const)MM_USER_PROBE_ADDRESS = NULL; \
  7042. } \
  7043. \
  7044. *(volatile PVOID *)(Address) = NULL; \
  7045. }
  7046. //++
  7047. //
  7048. // VOID
  7049. // ProbeForWriteLong(
  7050. // IN PLONG Address
  7051. // )
  7052. //
  7053. //--
  7054. #define ProbeForWriteLong(Address) { \
  7055. if ((Address) >= (LONG * const)MM_USER_PROBE_ADDRESS) { \
  7056. *(volatile LONG * const)MM_USER_PROBE_ADDRESS = 0; \
  7057. } \
  7058. \
  7059. *(volatile LONG *)(Address) = *(volatile LONG *)(Address); \
  7060. }
  7061. //++
  7062. //
  7063. // VOID
  7064. // ProbeForWriteUlong(
  7065. // IN PULONG Address
  7066. // )
  7067. //
  7068. //--
  7069. #define ProbeForWriteUlong(Address) { \
  7070. if ((Address) >= (ULONG * const)MM_USER_PROBE_ADDRESS) { \
  7071. *(volatile ULONG * const)MM_USER_PROBE_ADDRESS = 0; \
  7072. } \
  7073. \
  7074. *(volatile ULONG *)(Address) = *(volatile ULONG *)(Address); \
  7075. }
  7076. //++
  7077. //
  7078. // VOID
  7079. // ProbeForWriteUlong_ptr(
  7080. // IN PULONG_PTR Address
  7081. // )
  7082. //
  7083. //--
  7084. #define ProbeForWriteUlong_ptr(Address) { \
  7085. if ((Address) >= (ULONG_PTR * const)MM_USER_PROBE_ADDRESS) { \
  7086. *(volatile ULONG_PTR * const)MM_USER_PROBE_ADDRESS = 0; \
  7087. } \
  7088. \
  7089. *(volatile ULONG_PTR *)(Address) = *(volatile ULONG_PTR *)(Address); \
  7090. }
  7091. //++
  7092. //
  7093. // VOID
  7094. // ProbeForWriteQuad(
  7095. // IN PQUAD Address
  7096. // )
  7097. //
  7098. //--
  7099. #define ProbeForWriteQuad(Address) { \
  7100. if ((Address) >= (QUAD * const)MM_USER_PROBE_ADDRESS) { \
  7101. *(volatile LONG * const)MM_USER_PROBE_ADDRESS = 0; \
  7102. } \
  7103. \
  7104. *(volatile QUAD *)(Address) = *(volatile QUAD *)(Address); \
  7105. }
  7106. //++
  7107. //
  7108. // VOID
  7109. // ProbeForWriteUquad(
  7110. // IN PUQUAD Address
  7111. // )
  7112. //
  7113. //--
  7114. #define ProbeForWriteUquad(Address) { \
  7115. if ((Address) >= (QUAD * const)MM_USER_PROBE_ADDRESS) { \
  7116. *(volatile ULONG * const)MM_USER_PROBE_ADDRESS = 0; \
  7117. } \
  7118. \
  7119. *(volatile UQUAD *)(Address) = *(volatile UQUAD *)(Address); \
  7120. }
  7121. //
  7122. // Probe and write functions definitions.
  7123. //
  7124. //++
  7125. //
  7126. // VOID
  7127. // ProbeAndWriteBoolean(
  7128. // IN PBOOLEAN Address,
  7129. // IN BOOLEAN Value
  7130. // )
  7131. //
  7132. //--
  7133. #define ProbeAndWriteBoolean(Address, Value) { \
  7134. if ((Address) >= (BOOLEAN * const)MM_USER_PROBE_ADDRESS) { \
  7135. *(volatile BOOLEAN * const)MM_USER_PROBE_ADDRESS = 0; \
  7136. } \
  7137. \
  7138. *(Address) = (Value); \
  7139. }
  7140. //++
  7141. //
  7142. // VOID
  7143. // ProbeAndWriteChar(
  7144. // IN PCHAR Address,
  7145. // IN CHAR Value
  7146. // )
  7147. //
  7148. //--
  7149. #define ProbeAndWriteChar(Address, Value) { \
  7150. if ((Address) >= (CHAR * const)MM_USER_PROBE_ADDRESS) { \
  7151. *(volatile CHAR * const)MM_USER_PROBE_ADDRESS = 0; \
  7152. } \
  7153. \
  7154. *(Address) = (Value); \
  7155. }
  7156. //++
  7157. //
  7158. // VOID
  7159. // ProbeAndWriteUchar(
  7160. // IN PUCHAR Address,
  7161. // IN UCHAR Value
  7162. // )
  7163. //
  7164. //--
  7165. #define ProbeAndWriteUchar(Address, Value) { \
  7166. if ((Address) >= (UCHAR * const)MM_USER_PROBE_ADDRESS) { \
  7167. *(volatile UCHAR * const)MM_USER_PROBE_ADDRESS = 0; \
  7168. } \
  7169. \
  7170. *(Address) = (Value); \
  7171. }
  7172. //++
  7173. //
  7174. // VOID
  7175. // ProbeAndWriteShort(
  7176. // IN PSHORT Address,
  7177. // IN SHORT Value
  7178. // )
  7179. //
  7180. //--
  7181. #define ProbeAndWriteShort(Address, Value) { \
  7182. if ((Address) >= (SHORT * const)MM_USER_PROBE_ADDRESS) { \
  7183. *(volatile SHORT * const)MM_USER_PROBE_ADDRESS = 0; \
  7184. } \
  7185. \
  7186. *(Address) = (Value); \
  7187. }
  7188. //++
  7189. //
  7190. // VOID
  7191. // ProbeAndWriteUshort(
  7192. // IN PUSHORT Address,
  7193. // IN USHORT Value
  7194. // )
  7195. //
  7196. //--
  7197. #define ProbeAndWriteUshort(Address, Value) { \
  7198. if ((Address) >= (USHORT * const)MM_USER_PROBE_ADDRESS) { \
  7199. *(volatile USHORT * const)MM_USER_PROBE_ADDRESS = 0; \
  7200. } \
  7201. \
  7202. *(Address) = (Value); \
  7203. }
  7204. //++
  7205. //
  7206. // VOID
  7207. // ProbeAndWriteHandle(
  7208. // IN PHANDLE Address,
  7209. // IN HANDLE Value
  7210. // )
  7211. //
  7212. //--
  7213. #define ProbeAndWriteHandle(Address, Value) { \
  7214. if ((Address) >= (HANDLE * const)MM_USER_PROBE_ADDRESS) { \
  7215. *(volatile HANDLE * const)MM_USER_PROBE_ADDRESS = 0; \
  7216. } \
  7217. \
  7218. *(Address) = (Value); \
  7219. }
  7220. //++
  7221. //
  7222. // VOID
  7223. // ProbeAndWriteLong(
  7224. // IN PLONG Address,
  7225. // IN LONG Value
  7226. // )
  7227. //
  7228. //--
  7229. #define ProbeAndWriteLong(Address, Value) { \
  7230. if ((Address) >= (LONG * const)MM_USER_PROBE_ADDRESS) { \
  7231. *(volatile LONG * const)MM_USER_PROBE_ADDRESS = 0; \
  7232. } \
  7233. \
  7234. *(Address) = (Value); \
  7235. }
  7236. //++
  7237. //
  7238. // VOID
  7239. // ProbeAndWriteUlong(
  7240. // IN PULONG Address,
  7241. // IN ULONG Value
  7242. // )
  7243. //
  7244. //--
  7245. #define ProbeAndWriteUlong(Address, Value) { \
  7246. if ((Address) >= (ULONG * const)MM_USER_PROBE_ADDRESS) { \
  7247. *(volatile ULONG * const)MM_USER_PROBE_ADDRESS = 0; \
  7248. } \
  7249. \
  7250. *(Address) = (Value); \
  7251. }
  7252. //++
  7253. //
  7254. // VOID
  7255. // ProbeAndWriteQuad(
  7256. // IN PQUAD Address,
  7257. // IN QUAD Value
  7258. // )
  7259. //
  7260. //--
  7261. #define ProbeAndWriteQuad(Address, Value) { \
  7262. if ((Address) >= (QUAD * const)MM_USER_PROBE_ADDRESS) { \
  7263. *(volatile LONG * const)MM_USER_PROBE_ADDRESS = 0; \
  7264. } \
  7265. \
  7266. *(Address) = (Value); \
  7267. }
  7268. //++
  7269. //
  7270. // VOID
  7271. // ProbeAndWriteUquad(
  7272. // IN PUQUAD Address,
  7273. // IN UQUAD Value
  7274. // )
  7275. //
  7276. //--
  7277. #define ProbeAndWriteUquad(Address, Value) { \
  7278. if ((Address) >= (UQUAD * const)MM_USER_PROBE_ADDRESS) { \
  7279. *(volatile ULONG * const)MM_USER_PROBE_ADDRESS = 0; \
  7280. } \
  7281. \
  7282. *(Address) = (Value); \
  7283. }
  7284. //++
  7285. //
  7286. // VOID
  7287. // ProbeAndWriteSturcture(
  7288. // IN P<STRUCTURE> Address,
  7289. // IN <STRUCTURE> Value,
  7290. // <STRUCTURE>
  7291. // )
  7292. //
  7293. //--
  7294. #define ProbeAndWriteStructure(Address, Value,STRUCTURE) { \
  7295. if ((STRUCTURE * const)(Address) >= (STRUCTURE * const)MM_USER_PROBE_ADDRESS) { \
  7296. *(volatile ULONG * const)MM_USER_PROBE_ADDRESS = 0; \
  7297. } \
  7298. \
  7299. *(Address) = (Value); \
  7300. }
  7301. // begin_ntifs begin_ntddk begin_wdm begin_ntosp
  7302. //
  7303. // Common probe for write functions.
  7304. //
  7305. NTKERNELAPI
  7306. VOID
  7307. NTAPI
  7308. ProbeForWrite (
  7309. IN PVOID Address,
  7310. IN SIZE_T Length,
  7311. IN ULONG Alignment
  7312. );
  7313. //
  7314. // Worker Thread
  7315. //
  7316. typedef enum _WORK_QUEUE_TYPE {
  7317. CriticalWorkQueue,
  7318. DelayedWorkQueue,
  7319. HyperCriticalWorkQueue,
  7320. MaximumWorkQueue
  7321. } WORK_QUEUE_TYPE;
  7322. typedef
  7323. VOID
  7324. (*PWORKER_THREAD_ROUTINE)(
  7325. IN PVOID Parameter
  7326. );
  7327. typedef struct _WORK_QUEUE_ITEM {
  7328. LIST_ENTRY List;
  7329. PWORKER_THREAD_ROUTINE WorkerRoutine;
  7330. PVOID Parameter;
  7331. } WORK_QUEUE_ITEM, *PWORK_QUEUE_ITEM;
  7332. #if PRAGMA_DEPRECATED_DDK
  7333. #pragma deprecated(ExInitializeWorkItem) // Use IoAllocateWorkItem
  7334. #endif
  7335. #define ExInitializeWorkItem(Item, Routine, Context) \
  7336. (Item)->WorkerRoutine = (Routine); \
  7337. (Item)->Parameter = (Context); \
  7338. (Item)->List.Flink = NULL;
  7339. DECLSPEC_DEPRECATED_DDK // Use IoQueueWorkItem
  7340. NTKERNELAPI
  7341. VOID
  7342. ExQueueWorkItem(
  7343. IN PWORK_QUEUE_ITEM WorkItem,
  7344. IN WORK_QUEUE_TYPE QueueType
  7345. );
  7346. NTKERNELAPI
  7347. BOOLEAN
  7348. ExIsProcessorFeaturePresent(
  7349. ULONG ProcessorFeature
  7350. );
  7351. //
  7352. // Zone Allocation
  7353. //
  7354. typedef struct _ZONE_SEGMENT_HEADER {
  7355. SINGLE_LIST_ENTRY SegmentList;
  7356. PVOID Reserved;
  7357. } ZONE_SEGMENT_HEADER, *PZONE_SEGMENT_HEADER;
  7358. typedef struct _ZONE_HEADER {
  7359. SINGLE_LIST_ENTRY FreeList;
  7360. SINGLE_LIST_ENTRY SegmentList;
  7361. ULONG BlockSize;
  7362. ULONG TotalSegmentSize;
  7363. } ZONE_HEADER, *PZONE_HEADER;
  7364. DECLSPEC_DEPRECATED_DDK
  7365. NTKERNELAPI
  7366. NTSTATUS
  7367. ExInitializeZone(
  7368. IN PZONE_HEADER Zone,
  7369. IN ULONG BlockSize,
  7370. IN PVOID InitialSegment,
  7371. IN ULONG InitialSegmentSize
  7372. );
  7373. DECLSPEC_DEPRECATED_DDK
  7374. NTKERNELAPI
  7375. NTSTATUS
  7376. ExExtendZone(
  7377. IN PZONE_HEADER Zone,
  7378. IN PVOID Segment,
  7379. IN ULONG SegmentSize
  7380. );
  7381. DECLSPEC_DEPRECATED_DDK
  7382. NTKERNELAPI
  7383. NTSTATUS
  7384. ExInterlockedExtendZone(
  7385. IN PZONE_HEADER Zone,
  7386. IN PVOID Segment,
  7387. IN ULONG SegmentSize,
  7388. IN PKSPIN_LOCK Lock
  7389. );
  7390. //++
  7391. //
  7392. // PVOID
  7393. // ExAllocateFromZone(
  7394. // IN PZONE_HEADER Zone
  7395. // )
  7396. //
  7397. // Routine Description:
  7398. //
  7399. // This routine removes an entry from the zone and returns a pointer to it.
  7400. //
  7401. // Arguments:
  7402. //
  7403. // Zone - Pointer to the zone header controlling the storage from which the
  7404. // entry is to be allocated.
  7405. //
  7406. // Return Value:
  7407. //
  7408. // The function value is a pointer to the storage allocated from the zone.
  7409. //
  7410. //--
  7411. #if PRAGMA_DEPRECATED_DDK
  7412. #pragma deprecated(ExAllocateFromZone)
  7413. #endif
  7414. #define ExAllocateFromZone(Zone) \
  7415. (PVOID)((Zone)->FreeList.Next); \
  7416. if ( (Zone)->FreeList.Next ) (Zone)->FreeList.Next = (Zone)->FreeList.Next->Next
  7417. //++
  7418. //
  7419. // PVOID
  7420. // ExFreeToZone(
  7421. // IN PZONE_HEADER Zone,
  7422. // IN PVOID Block
  7423. // )
  7424. //
  7425. // Routine Description:
  7426. //
  7427. // This routine places the specified block of storage back onto the free
  7428. // list in the specified zone.
  7429. //
  7430. // Arguments:
  7431. //
  7432. // Zone - Pointer to the zone header controlling the storage to which the
  7433. // entry is to be inserted.
  7434. //
  7435. // Block - Pointer to the block of storage to be freed back to the zone.
  7436. //
  7437. // Return Value:
  7438. //
  7439. // Pointer to previous block of storage that was at the head of the free
  7440. // list. NULL implies the zone went from no available free blocks to
  7441. // at least one free block.
  7442. //
  7443. //--
  7444. #if PRAGMA_DEPRECATED_DDK
  7445. #pragma deprecated(ExFreeToZone)
  7446. #endif
  7447. #define ExFreeToZone(Zone,Block) \
  7448. ( ((PSINGLE_LIST_ENTRY)(Block))->Next = (Zone)->FreeList.Next, \
  7449. (Zone)->FreeList.Next = ((PSINGLE_LIST_ENTRY)(Block)), \
  7450. ((PSINGLE_LIST_ENTRY)(Block))->Next \
  7451. )
  7452. //++
  7453. //
  7454. // BOOLEAN
  7455. // ExIsFullZone(
  7456. // IN PZONE_HEADER Zone
  7457. // )
  7458. //
  7459. // Routine Description:
  7460. //
  7461. // This routine determines if the specified zone is full or not. A zone
  7462. // is considered full if the free list is empty.
  7463. //
  7464. // Arguments:
  7465. //
  7466. // Zone - Pointer to the zone header to be tested.
  7467. //
  7468. // Return Value:
  7469. //
  7470. // TRUE if the zone is full and FALSE otherwise.
  7471. //
  7472. //--
  7473. #if PRAGMA_DEPRECATED_DDK
  7474. #pragma deprecated(ExIsFullZone)
  7475. #endif
  7476. #define ExIsFullZone(Zone) \
  7477. ( (Zone)->FreeList.Next == (PSINGLE_LIST_ENTRY)NULL )
  7478. //++
  7479. //
  7480. // PVOID
  7481. // ExInterlockedAllocateFromZone(
  7482. // IN PZONE_HEADER Zone,
  7483. // IN PKSPIN_LOCK Lock
  7484. // )
  7485. //
  7486. // Routine Description:
  7487. //
  7488. // This routine removes an entry from the zone and returns a pointer to it.
  7489. // The removal is performed with the specified lock owned for the sequence
  7490. // to make it MP-safe.
  7491. //
  7492. // Arguments:
  7493. //
  7494. // Zone - Pointer to the zone header controlling the storage from which the
  7495. // entry is to be allocated.
  7496. //
  7497. // Lock - Pointer to the spin lock which should be obtained before removing
  7498. // the entry from the allocation list. The lock is released before
  7499. // returning to the caller.
  7500. //
  7501. // Return Value:
  7502. //
  7503. // The function value is a pointer to the storage allocated from the zone.
  7504. //
  7505. //--
  7506. #if PRAGMA_DEPRECATED_DDK
  7507. #pragma deprecated(ExInterlockedAllocateFromZone)
  7508. #endif
  7509. #define ExInterlockedAllocateFromZone(Zone,Lock) \
  7510. (PVOID) ExInterlockedPopEntryList( &(Zone)->FreeList, Lock )
  7511. //++
  7512. //
  7513. // PVOID
  7514. // ExInterlockedFreeToZone(
  7515. // IN PZONE_HEADER Zone,
  7516. // IN PVOID Block,
  7517. // IN PKSPIN_LOCK Lock
  7518. // )
  7519. //
  7520. // Routine Description:
  7521. //
  7522. // This routine places the specified block of storage back onto the free
  7523. // list in the specified zone. The insertion is performed with the lock
  7524. // owned for the sequence to make it MP-safe.
  7525. //
  7526. // Arguments:
  7527. //
  7528. // Zone - Pointer to the zone header controlling the storage to which the
  7529. // entry is to be inserted.
  7530. //
  7531. // Block - Pointer to the block of storage to be freed back to the zone.
  7532. //
  7533. // Lock - Pointer to the spin lock which should be obtained before inserting
  7534. // the entry onto the free list. The lock is released before returning
  7535. // to the caller.
  7536. //
  7537. // Return Value:
  7538. //
  7539. // Pointer to previous block of storage that was at the head of the free
  7540. // list. NULL implies the zone went from no available free blocks to
  7541. // at least one free block.
  7542. //
  7543. //--
  7544. #if PRAGMA_DEPRECATED_DDK
  7545. #pragma deprecated(ExInterlockedFreeToZone)
  7546. #endif
  7547. #define ExInterlockedFreeToZone(Zone,Block,Lock) \
  7548. ExInterlockedPushEntryList( &(Zone)->FreeList, ((PSINGLE_LIST_ENTRY) (Block)), Lock )
  7549. //++
  7550. //
  7551. // BOOLEAN
  7552. // ExIsObjectInFirstZoneSegment(
  7553. // IN PZONE_HEADER Zone,
  7554. // IN PVOID Object
  7555. // )
  7556. //
  7557. // Routine Description:
  7558. //
  7559. // This routine determines if the specified pointer lives in the zone.
  7560. //
  7561. // Arguments:
  7562. //
  7563. // Zone - Pointer to the zone header controlling the storage to which the
  7564. // object may belong.
  7565. //
  7566. // Object - Pointer to the object in question.
  7567. //
  7568. // Return Value:
  7569. //
  7570. // TRUE if the Object came from the first segment of zone.
  7571. //
  7572. //--
  7573. #if PRAGMA_DEPRECATED_DDK
  7574. #pragma deprecated(ExIsObjectInFirstZoneSegment)
  7575. #endif
  7576. #define ExIsObjectInFirstZoneSegment(Zone,Object) ((BOOLEAN) \
  7577. (((PUCHAR)(Object) >= (PUCHAR)(Zone)->SegmentList.Next) && \
  7578. ((PUCHAR)(Object) < (PUCHAR)(Zone)->SegmentList.Next + \
  7579. (Zone)->TotalSegmentSize)) \
  7580. )
  7581. //
  7582. // Define executive resource data structures.
  7583. //
  7584. typedef ULONG_PTR ERESOURCE_THREAD;
  7585. typedef ERESOURCE_THREAD *PERESOURCE_THREAD;
  7586. typedef struct _OWNER_ENTRY {
  7587. ERESOURCE_THREAD OwnerThread;
  7588. union {
  7589. LONG OwnerCount;
  7590. ULONG TableSize;
  7591. };
  7592. } OWNER_ENTRY, *POWNER_ENTRY;
  7593. typedef struct _ERESOURCE {
  7594. LIST_ENTRY SystemResourcesList;
  7595. POWNER_ENTRY OwnerTable;
  7596. SHORT ActiveCount;
  7597. USHORT Flag;
  7598. PKSEMAPHORE SharedWaiters;
  7599. PKEVENT ExclusiveWaiters;
  7600. OWNER_ENTRY OwnerThreads[2];
  7601. ULONG ContentionCount;
  7602. USHORT NumberOfSharedWaiters;
  7603. USHORT NumberOfExclusiveWaiters;
  7604. union {
  7605. PVOID Address;
  7606. ULONG_PTR CreatorBackTraceIndex;
  7607. };
  7608. KSPIN_LOCK SpinLock;
  7609. } ERESOURCE, *PERESOURCE;
  7610. //
  7611. // Values for ERESOURCE.Flag
  7612. //
  7613. #define ResourceNeverExclusive 0x10
  7614. #define ResourceReleaseByOtherThread 0x20
  7615. #define ResourceOwnedExclusive 0x80
  7616. #define RESOURCE_HASH_TABLE_SIZE 64
  7617. typedef struct _RESOURCE_HASH_ENTRY {
  7618. LIST_ENTRY ListEntry;
  7619. PVOID Address;
  7620. ULONG ContentionCount;
  7621. ULONG Number;
  7622. } RESOURCE_HASH_ENTRY, *PRESOURCE_HASH_ENTRY;
  7623. typedef struct _RESOURCE_PERFORMANCE_DATA {
  7624. ULONG ActiveResourceCount;
  7625. ULONG TotalResourceCount;
  7626. ULONG ExclusiveAcquire;
  7627. ULONG SharedFirstLevel;
  7628. ULONG SharedSecondLevel;
  7629. ULONG StarveFirstLevel;
  7630. ULONG StarveSecondLevel;
  7631. ULONG WaitForExclusive;
  7632. ULONG OwnerTableExpands;
  7633. ULONG MaximumTableExpand;
  7634. LIST_ENTRY HashTable[RESOURCE_HASH_TABLE_SIZE];
  7635. } RESOURCE_PERFORMANCE_DATA, *PRESOURCE_PERFORMANCE_DATA;
  7636. //
  7637. // Define executive resource function prototypes.
  7638. //
  7639. NTKERNELAPI
  7640. NTSTATUS
  7641. ExInitializeResourceLite(
  7642. IN PERESOURCE Resource
  7643. );
  7644. NTKERNELAPI
  7645. NTSTATUS
  7646. ExReinitializeResourceLite(
  7647. IN PERESOURCE Resource
  7648. );
  7649. NTKERNELAPI
  7650. BOOLEAN
  7651. ExAcquireResourceSharedLite(
  7652. IN PERESOURCE Resource,
  7653. IN BOOLEAN Wait
  7654. );
  7655. NTKERNELAPI
  7656. BOOLEAN
  7657. ExAcquireResourceExclusiveLite(
  7658. IN PERESOURCE Resource,
  7659. IN BOOLEAN Wait
  7660. );
  7661. NTKERNELAPI
  7662. BOOLEAN
  7663. ExAcquireSharedStarveExclusive(
  7664. IN PERESOURCE Resource,
  7665. IN BOOLEAN Wait
  7666. );
  7667. NTKERNELAPI
  7668. BOOLEAN
  7669. ExAcquireSharedWaitForExclusive(
  7670. IN PERESOURCE Resource,
  7671. IN BOOLEAN Wait
  7672. );
  7673. NTKERNELAPI
  7674. BOOLEAN
  7675. ExTryToAcquireResourceExclusiveLite(
  7676. IN PERESOURCE Resource
  7677. );
  7678. //
  7679. // VOID
  7680. // ExReleaseResource(
  7681. // IN PERESOURCE Resource
  7682. // );
  7683. //
  7684. #if PRAGMA_DEPRECATED_DDK
  7685. #pragma deprecated(ExReleaseResource) // Use ExReleaseResourceLite
  7686. #endif
  7687. #define ExReleaseResource(R) (ExReleaseResourceLite(R))
  7688. NTKERNELAPI
  7689. VOID
  7690. FASTCALL
  7691. ExReleaseResourceLite(
  7692. IN PERESOURCE Resource
  7693. );
  7694. NTKERNELAPI
  7695. VOID
  7696. ExReleaseResourceForThreadLite(
  7697. IN PERESOURCE Resource,
  7698. IN ERESOURCE_THREAD ResourceThreadId
  7699. );
  7700. NTKERNELAPI
  7701. VOID
  7702. ExSetResourceOwnerPointer(
  7703. IN PERESOURCE Resource,
  7704. IN PVOID OwnerPointer
  7705. );
  7706. NTKERNELAPI
  7707. VOID
  7708. ExConvertExclusiveToSharedLite(
  7709. IN PERESOURCE Resource
  7710. );
  7711. NTKERNELAPI
  7712. NTSTATUS
  7713. ExDeleteResourceLite (
  7714. IN PERESOURCE Resource
  7715. );
  7716. NTKERNELAPI
  7717. ULONG
  7718. ExGetExclusiveWaiterCount (
  7719. IN PERESOURCE Resource
  7720. );
  7721. NTKERNELAPI
  7722. ULONG
  7723. ExGetSharedWaiterCount (
  7724. IN PERESOURCE Resource
  7725. );
  7726. //
  7727. // ERESOURCE_THREAD
  7728. // ExGetCurrentResourceThread(
  7729. // );
  7730. //
  7731. #define ExGetCurrentResourceThread() ((ULONG_PTR)PsGetCurrentThread())
  7732. NTKERNELAPI
  7733. BOOLEAN
  7734. ExIsResourceAcquiredExclusiveLite (
  7735. IN PERESOURCE Resource
  7736. );
  7737. NTKERNELAPI
  7738. ULONG
  7739. ExIsResourceAcquiredSharedLite (
  7740. IN PERESOURCE Resource
  7741. );
  7742. //
  7743. // An acquired resource is always owned shared, as shared ownership is a subset
  7744. // of exclusive ownership.
  7745. //
  7746. #define ExIsResourceAcquiredLite ExIsResourceAcquiredSharedLite
  7747. // end_wdm
  7748. //
  7749. // ntddk.h stole the entrypoints we wanted so fix them up here.
  7750. //
  7751. #if PRAGMA_DEPRECATED_DDK
  7752. #pragma deprecated(ExInitializeResource) // use ExInitializeResourceLite
  7753. #pragma deprecated(ExAcquireResourceShared) // use ExAcquireResourceSharedLite
  7754. #pragma deprecated(ExAcquireResourceExclusive) // use ExAcquireResourceExclusiveLite
  7755. #pragma deprecated(ExReleaseResourceForThread) // use ExReleaseResourceForThreadLite
  7756. #pragma deprecated(ExConvertExclusiveToShared) // use ExConvertExclusiveToSharedLite
  7757. #pragma deprecated(ExDeleteResource) // use ExDeleteResourceLite
  7758. #pragma deprecated(ExIsResourceAcquiredExclusive) // use ExIsResourceAcquiredExclusiveLite
  7759. #pragma deprecated(ExIsResourceAcquiredShared) // use ExIsResourceAcquiredSharedLite
  7760. #pragma deprecated(ExIsResourceAcquired) // use ExIsResourceAcquiredSharedLite
  7761. #endif
  7762. #define ExInitializeResource ExInitializeResourceLite
  7763. #define ExAcquireResourceShared ExAcquireResourceSharedLite
  7764. #define ExAcquireResourceExclusive ExAcquireResourceExclusiveLite
  7765. #define ExReleaseResourceForThread ExReleaseResourceForThreadLite
  7766. #define ExConvertExclusiveToShared ExConvertExclusiveToSharedLite
  7767. #define ExDeleteResource ExDeleteResourceLite
  7768. #define ExIsResourceAcquiredExclusive ExIsResourceAcquiredExclusiveLite
  7769. #define ExIsResourceAcquiredShared ExIsResourceAcquiredSharedLite
  7770. #define ExIsResourceAcquired ExIsResourceAcquiredSharedLite
  7771. //
  7772. // Push lock definitions
  7773. //
  7774. typedef struct _EX_PUSH_LOCK {
  7775. #define EX_PUSH_LOCK_WAITING 0x1
  7776. #define EX_PUSH_LOCK_EXCLUSIVE 0x2
  7777. #define EX_PUSH_LOCK_SHARE_INC 0x4
  7778. union {
  7779. struct {
  7780. ULONG_PTR Waiting : 1;
  7781. ULONG_PTR Exclusive : 1;
  7782. ULONG_PTR Shared : sizeof (ULONG_PTR) * 8 - 2;
  7783. };
  7784. ULONG_PTR Value;
  7785. PVOID Ptr;
  7786. };
  7787. } EX_PUSH_LOCK, *PEX_PUSH_LOCK;
  7788. #if defined (NT_UP)
  7789. #define EX_CACHE_LINE_SIZE 16
  7790. #define EX_PUSH_LOCK_FANNED_COUNT 1
  7791. #else
  7792. #define EX_CACHE_LINE_SIZE 128
  7793. #define EX_PUSH_LOCK_FANNED_COUNT (PAGE_SIZE/EX_CACHE_LINE_SIZE)
  7794. #endif
  7795. //
  7796. // Define a fan out structure for n push locks each in its own cache line
  7797. //
  7798. typedef struct _EX_PUSH_LOCK_CACHE_AWARE {
  7799. PEX_PUSH_LOCK Locks[EX_PUSH_LOCK_FANNED_COUNT];
  7800. } EX_PUSH_LOCK_CACHE_AWARE, *PEX_PUSH_LOCK_CACHE_AWARE;
  7801. //
  7802. // Define structure thats a push lock padded to the size of a cache line
  7803. //
  7804. typedef struct _EX_PUSH_LOCK_CACHE_AWARE_PADDED {
  7805. EX_PUSH_LOCK Lock;
  7806. union {
  7807. UCHAR Pad[EX_CACHE_LINE_SIZE - sizeof (EX_PUSH_LOCK)];
  7808. BOOLEAN Single;
  7809. };
  7810. } EX_PUSH_LOCK_CACHE_AWARE_PADDED, *PEX_PUSH_LOCK_CACHE_AWARE_PADDED;
  7811. //begin_ntifs
  7812. //
  7813. // Rundown protection structure
  7814. //
  7815. typedef struct _EX_RUNDOWN_REF {
  7816. #define EX_RUNDOWN_ACTIVE 0x1
  7817. #define EX_RUNDOWN_COUNT_SHIFT 0x1
  7818. #define EX_RUNDOWN_COUNT_INC (1<<EX_RUNDOWN_COUNT_SHIFT)
  7819. union {
  7820. ULONG_PTR Count;
  7821. PVOID Ptr;
  7822. };
  7823. } EX_RUNDOWN_REF, *PEX_RUNDOWN_REF;
  7824. //end_ntifs
  7825. //
  7826. // The Ex/Ob handle table interface package (in handle.c)
  7827. //
  7828. //
  7829. // The Ex/Ob handle table package uses a common handle definition. The actual
  7830. // type definition for a handle is a pvoid and is declared in sdk/inc. This
  7831. // package uses only the low 32 bits of the pvoid pointer.
  7832. //
  7833. // For simplicity we declare a new typedef called an exhandle
  7834. //
  7835. // The 2 bits of an EXHANDLE is available to the application and is
  7836. // ignored by the system. The next 24 bits store the handle table entry
  7837. // index and is used to refer to a particular entry in a handle table.
  7838. //
  7839. // Note that this format is immutable because there are outside programs with
  7840. // hardwired code that already assumes the format of a handle.
  7841. //
  7842. typedef struct _EXHANDLE {
  7843. union {
  7844. struct {
  7845. //
  7846. // Application available tag bits
  7847. //
  7848. ULONG TagBits : 2;
  7849. //
  7850. // The handle table entry index
  7851. //
  7852. ULONG Index : 30;
  7853. };
  7854. HANDLE GenericHandleOverlay;
  7855. #define HANDLE_VALUE_INC 4 // Amount to increment the Value to get to the next handle
  7856. ULONG_PTR Value;
  7857. };
  7858. } EXHANDLE, *PEXHANDLE;
  7859. //
  7860. // Get previous mode
  7861. //
  7862. NTKERNELAPI
  7863. KPROCESSOR_MODE
  7864. ExGetPreviousMode(
  7865. VOID
  7866. );
  7867. //
  7868. // Raise status from kernel mode.
  7869. //
  7870. NTKERNELAPI
  7871. VOID
  7872. NTAPI
  7873. ExRaiseStatus (
  7874. IN NTSTATUS Status
  7875. );
  7876. // end_wdm
  7877. NTKERNELAPI
  7878. VOID
  7879. ExRaiseDatatypeMisalignment (
  7880. VOID
  7881. );
  7882. NTKERNELAPI
  7883. VOID
  7884. ExRaiseAccessViolation (
  7885. VOID
  7886. );
  7887. NTKERNELAPI
  7888. NTSTATUS
  7889. ExRaiseHardError(
  7890. IN NTSTATUS ErrorStatus,
  7891. IN ULONG NumberOfParameters,
  7892. IN ULONG UnicodeStringParameterMask,
  7893. IN PULONG_PTR Parameters,
  7894. IN ULONG ValidResponseOptions,
  7895. OUT PULONG Response
  7896. );
  7897. int
  7898. ExSystemExceptionFilter(
  7899. VOID
  7900. );
  7901. NTKERNELAPI
  7902. VOID
  7903. ExGetCurrentProcessorCpuUsage(
  7904. IN PULONG CpuUsage
  7905. );
  7906. NTKERNELAPI
  7907. VOID
  7908. ExGetCurrentProcessorCounts(
  7909. OUT PULONG IdleCount,
  7910. OUT PULONG KernelAndUser,
  7911. OUT PULONG Index
  7912. );
  7913. //
  7914. // Set timer resolution.
  7915. //
  7916. NTKERNELAPI
  7917. ULONG
  7918. ExSetTimerResolution (
  7919. IN ULONG DesiredTime,
  7920. IN BOOLEAN SetResolution
  7921. );
  7922. //
  7923. // Subtract time zone bias from system time to get local time.
  7924. //
  7925. NTKERNELAPI
  7926. VOID
  7927. ExSystemTimeToLocalTime (
  7928. IN PLARGE_INTEGER SystemTime,
  7929. OUT PLARGE_INTEGER LocalTime
  7930. );
  7931. //
  7932. // Add time zone bias to local time to get system time.
  7933. //
  7934. NTKERNELAPI
  7935. VOID
  7936. ExLocalTimeToSystemTime (
  7937. IN PLARGE_INTEGER LocalTime,
  7938. OUT PLARGE_INTEGER SystemTime
  7939. );
  7940. //
  7941. // Define the type for Callback function.
  7942. //
  7943. typedef struct _CALLBACK_OBJECT *PCALLBACK_OBJECT;
  7944. typedef VOID (*PCALLBACK_FUNCTION ) (
  7945. IN PVOID CallbackContext,
  7946. IN PVOID Argument1,
  7947. IN PVOID Argument2
  7948. );
  7949. NTKERNELAPI
  7950. NTSTATUS
  7951. ExCreateCallback (
  7952. OUT PCALLBACK_OBJECT *CallbackObject,
  7953. IN POBJECT_ATTRIBUTES ObjectAttributes,
  7954. IN BOOLEAN Create,
  7955. IN BOOLEAN AllowMultipleCallbacks
  7956. );
  7957. NTKERNELAPI
  7958. PVOID
  7959. ExRegisterCallback (
  7960. IN PCALLBACK_OBJECT CallbackObject,
  7961. IN PCALLBACK_FUNCTION CallbackFunction,
  7962. IN PVOID CallbackContext
  7963. );
  7964. NTKERNELAPI
  7965. VOID
  7966. ExUnregisterCallback (
  7967. IN PVOID CallbackRegistration
  7968. );
  7969. NTKERNELAPI
  7970. VOID
  7971. ExNotifyCallback (
  7972. IN PVOID CallbackObject,
  7973. IN PVOID Argument1,
  7974. IN PVOID Argument2
  7975. );
  7976. typedef
  7977. PVOID
  7978. (*PKWIN32_GLOBALATOMTABLE_CALLOUT) ( void );
  7979. extern PKWIN32_GLOBALATOMTABLE_CALLOUT ExGlobalAtomTableCallout;
  7980. //
  7981. // UUID Generation
  7982. //
  7983. typedef GUID UUID;
  7984. NTKERNELAPI
  7985. NTSTATUS
  7986. ExUuidCreate(
  7987. OUT UUID *Uuid
  7988. );
  7989. //
  7990. // Rundown Locks
  7991. //
  7992. NTKERNELAPI
  7993. VOID
  7994. FASTCALL
  7995. ExInitializeRundownProtection (
  7996. IN PEX_RUNDOWN_REF RunRef
  7997. );
  7998. NTKERNELAPI
  7999. VOID
  8000. FASTCALL
  8001. ExReInitializeRundownProtection (
  8002. IN PEX_RUNDOWN_REF RunRef
  8003. );
  8004. NTKERNELAPI
  8005. BOOLEAN
  8006. FASTCALL
  8007. ExAcquireRundownProtection (
  8008. IN PEX_RUNDOWN_REF RunRef
  8009. );
  8010. NTKERNELAPI
  8011. BOOLEAN
  8012. FASTCALL
  8013. ExAcquireRundownProtectionEx (
  8014. IN PEX_RUNDOWN_REF RunRef,
  8015. IN ULONG Count
  8016. );
  8017. NTKERNELAPI
  8018. VOID
  8019. FASTCALL
  8020. ExReleaseRundownProtection (
  8021. IN PEX_RUNDOWN_REF RunRef
  8022. );
  8023. NTKERNELAPI
  8024. VOID
  8025. FASTCALL
  8026. ExReleaseRundownProtectionEx (
  8027. IN PEX_RUNDOWN_REF RunRef,
  8028. IN ULONG Count
  8029. );
  8030. NTKERNELAPI
  8031. VOID
  8032. FASTCALL
  8033. ExRundownCompleted (
  8034. IN PEX_RUNDOWN_REF RunRef
  8035. );
  8036. NTKERNELAPI
  8037. VOID
  8038. FASTCALL
  8039. ExWaitForRundownProtectionRelease (
  8040. IN PEX_RUNDOWN_REF RunRef
  8041. );
  8042. #if !defined(NONTOSPINTERLOCK)
  8043. VOID
  8044. FORCEINLINE
  8045. ExInitializePushLock (
  8046. IN PEX_PUSH_LOCK PushLock
  8047. )
  8048. /*++
  8049. Routine Description:
  8050. Initialize a push lock structure
  8051. Arguments:
  8052. PushLock - Push lock to be initialized
  8053. Return Value:
  8054. None
  8055. --*/
  8056. {
  8057. PushLock->Value = 0;
  8058. }
  8059. NTKERNELAPI
  8060. VOID
  8061. FASTCALL
  8062. ExfAcquirePushLockExclusive (
  8063. IN PEX_PUSH_LOCK PushLock
  8064. );
  8065. NTKERNELAPI
  8066. VOID
  8067. FASTCALL
  8068. ExfAcquirePushLockShared (
  8069. IN PEX_PUSH_LOCK PushLock
  8070. );
  8071. NTKERNELAPI
  8072. VOID
  8073. FASTCALL
  8074. ExfReleasePushLock (
  8075. IN PEX_PUSH_LOCK PushLock
  8076. );
  8077. VOID
  8078. FORCEINLINE
  8079. ExAcquirePushLockExclusive (
  8080. IN PEX_PUSH_LOCK PushLock
  8081. )
  8082. /*++
  8083. Routine Description:
  8084. Acquire a push lock exclusively
  8085. Arguments:
  8086. PushLock - Push lock to be acquired
  8087. Return Value:
  8088. None
  8089. --*/
  8090. {
  8091. if (InterlockedCompareExchangePointer (&PushLock->Ptr,
  8092. (PVOID)EX_PUSH_LOCK_EXCLUSIVE,
  8093. NULL) != NULL) {
  8094. ExfAcquirePushLockExclusive (PushLock);
  8095. }
  8096. }
  8097. BOOLEAN
  8098. FORCEINLINE
  8099. ExTryAcquirePushLockExclusive (
  8100. IN PEX_PUSH_LOCK PushLock
  8101. )
  8102. /*++
  8103. Routine Description:
  8104. Try and acquire a push lock exclusively
  8105. Arguments:
  8106. PushLock - Push lock to be acquired
  8107. Return Value:
  8108. BOOLEAN - TRUE: Acquire was successfull, FALSE: Lock was already acquired
  8109. --*/
  8110. {
  8111. if (InterlockedCompareExchangePointer (&PushLock->Ptr,
  8112. (PVOID)EX_PUSH_LOCK_EXCLUSIVE,
  8113. NULL) == NULL) {
  8114. return TRUE;
  8115. } else {
  8116. return FALSE;
  8117. }
  8118. }
  8119. VOID
  8120. FORCEINLINE
  8121. ExAcquirePushLockShared (
  8122. IN PEX_PUSH_LOCK PushLock
  8123. )
  8124. /*++
  8125. Routine Description:
  8126. Acquire a push lock shared
  8127. Arguments:
  8128. PushLock - Push lock to be acquired
  8129. Return Value:
  8130. None
  8131. --*/
  8132. {
  8133. EX_PUSH_LOCK OldValue, NewValue;
  8134. OldValue = *PushLock;
  8135. OldValue.Value &= ~(EX_PUSH_LOCK_EXCLUSIVE | EX_PUSH_LOCK_WAITING);
  8136. NewValue.Value = OldValue.Value + EX_PUSH_LOCK_SHARE_INC;
  8137. if (InterlockedCompareExchangePointer (&PushLock->Ptr,
  8138. NewValue.Ptr,
  8139. OldValue.Ptr) != OldValue.Ptr) {
  8140. ExfAcquirePushLockShared (PushLock);
  8141. }
  8142. }
  8143. VOID
  8144. FORCEINLINE
  8145. ExAcquirePushLockSharedAssumeNoOwner (
  8146. IN PEX_PUSH_LOCK PushLock
  8147. )
  8148. /*++
  8149. Routine Description:
  8150. Acquire a push lock shared making the assumption that its not currently owned.
  8151. Arguments:
  8152. PushLock - Push lock to be acquired
  8153. Return Value:
  8154. None
  8155. --*/
  8156. {
  8157. if (InterlockedCompareExchangePointer (&PushLock->Ptr,
  8158. (PVOID)EX_PUSH_LOCK_SHARE_INC,
  8159. NULL) != NULL) {
  8160. ExfAcquirePushLockShared (PushLock);
  8161. }
  8162. }
  8163. BOOLEAN
  8164. FORCEINLINE
  8165. ExTryConvertPushLockSharedToExclusive (
  8166. IN PEX_PUSH_LOCK PushLock
  8167. )
  8168. /*++
  8169. Routine Description:
  8170. Attempts to convert a shared acquire to exclusive. If other sharers or waiters are present
  8171. the function fails.
  8172. Arguments:
  8173. PushLock - Push lock to be acquired
  8174. Return Value:
  8175. BOOLEAN - TRUE: Conversion worked ok, FALSE: The conversion could not be achieved
  8176. --*/
  8177. {
  8178. if (InterlockedCompareExchangePointer (&PushLock->Ptr, (PVOID) EX_PUSH_LOCK_EXCLUSIVE,
  8179. (PVOID) EX_PUSH_LOCK_SHARE_INC) ==
  8180. (PVOID)EX_PUSH_LOCK_SHARE_INC) {
  8181. return TRUE;
  8182. } else {
  8183. return FALSE;
  8184. }
  8185. }
  8186. VOID
  8187. FORCEINLINE
  8188. ExReleasePushLock (
  8189. IN PEX_PUSH_LOCK PushLock
  8190. )
  8191. /*++
  8192. Routine Description:
  8193. Release a push lock that was acquired exclusively or shared
  8194. Arguments:
  8195. PushLock - Push lock to be released
  8196. Return Value:
  8197. None
  8198. --*/
  8199. {
  8200. EX_PUSH_LOCK OldValue, NewValue;
  8201. OldValue = *PushLock;
  8202. OldValue.Value &= ~EX_PUSH_LOCK_WAITING;
  8203. NewValue.Value = (OldValue.Value - EX_PUSH_LOCK_EXCLUSIVE) &
  8204. ~EX_PUSH_LOCK_EXCLUSIVE;
  8205. if (InterlockedCompareExchangePointer (&PushLock->Ptr,
  8206. NewValue.Ptr,
  8207. OldValue.Ptr) != OldValue.Ptr) {
  8208. ExfReleasePushLock (PushLock);
  8209. }
  8210. }
  8211. VOID
  8212. FORCEINLINE
  8213. ExReleasePushLockExclusive (
  8214. IN PEX_PUSH_LOCK PushLock
  8215. )
  8216. /*++
  8217. Routine Description:
  8218. Release a push lock that was acquired exclusively
  8219. Arguments:
  8220. PushLock - Push lock to be released
  8221. Return Value:
  8222. None
  8223. --*/
  8224. {
  8225. ASSERT (PushLock->Value & (EX_PUSH_LOCK_WAITING|EX_PUSH_LOCK_EXCLUSIVE));
  8226. if (InterlockedCompareExchangePointer (&PushLock->Ptr,
  8227. NULL,
  8228. (PVOID)EX_PUSH_LOCK_EXCLUSIVE) != (PVOID)EX_PUSH_LOCK_EXCLUSIVE) {
  8229. ExfReleasePushLock (PushLock);
  8230. }
  8231. }
  8232. VOID
  8233. FORCEINLINE
  8234. ExReleasePushLockShared (
  8235. IN PEX_PUSH_LOCK PushLock
  8236. )
  8237. /*++
  8238. Routine Description:
  8239. Release a push lock that was acquired shared
  8240. Arguments:
  8241. PushLock - Push lock to be released
  8242. Return Value:
  8243. None
  8244. --*/
  8245. {
  8246. EX_PUSH_LOCK OldValue, NewValue;
  8247. OldValue = *PushLock;
  8248. ASSERT (OldValue.Waiting || !OldValue.Exclusive);
  8249. OldValue.Value &= ~EX_PUSH_LOCK_WAITING;
  8250. NewValue.Value = OldValue.Value - EX_PUSH_LOCK_SHARE_INC;
  8251. if (InterlockedCompareExchangePointer (&PushLock->Ptr,
  8252. NewValue.Ptr,
  8253. OldValue.Ptr) != OldValue.Ptr) {
  8254. ExfReleasePushLock (PushLock);
  8255. }
  8256. }
  8257. VOID
  8258. FORCEINLINE
  8259. ExReleasePushLockSharedAssumeSingleOwner (
  8260. IN PEX_PUSH_LOCK PushLock
  8261. )
  8262. /*++
  8263. Routine Description:
  8264. Release a push lock that was acquired shared assuming that we are the only owner
  8265. Arguments:
  8266. PushLock - Push lock to be released
  8267. Return Value:
  8268. None
  8269. --*/
  8270. {
  8271. #if DBG
  8272. EX_PUSH_LOCK OldValue;
  8273. OldValue = *PushLock;
  8274. ASSERT (OldValue.Waiting || !OldValue.Exclusive);
  8275. #endif
  8276. if (InterlockedCompareExchangePointer (&PushLock->Ptr,
  8277. NULL,
  8278. (PVOID)EX_PUSH_LOCK_SHARE_INC) != (PVOID)EX_PUSH_LOCK_SHARE_INC) {
  8279. ExfReleasePushLock (PushLock);
  8280. }
  8281. }
  8282. //
  8283. // This is a block held on the local stack of the waiting threads.
  8284. //
  8285. typedef struct _EX_PUSH_LOCK_WAIT_BLOCK *PEX_PUSH_LOCK_WAIT_BLOCK;
  8286. typedef struct _EX_PUSH_LOCK_WAIT_BLOCK {
  8287. KEVENT WakeEvent;
  8288. PEX_PUSH_LOCK_WAIT_BLOCK Next;
  8289. PEX_PUSH_LOCK_WAIT_BLOCK Last;
  8290. PEX_PUSH_LOCK_WAIT_BLOCK Previous;
  8291. ULONG ShareCount;
  8292. BOOLEAN Exclusive;
  8293. } EX_PUSH_LOCK_WAIT_BLOCK;
  8294. VOID
  8295. FORCEINLINE
  8296. ExWaitForUnblockPushLock (
  8297. IN PEX_PUSH_LOCK PushLock,
  8298. IN PEX_PUSH_LOCK_WAIT_BLOCK WaitBlock OPTIONAL
  8299. )
  8300. {
  8301. UNREFERENCED_PARAMETER (PushLock);
  8302. KeWaitForSingleObject (&WaitBlock->WakeEvent,
  8303. Executive,
  8304. KernelMode,
  8305. FALSE,
  8306. NULL);
  8307. }
  8308. NTKERNELAPI
  8309. PEX_PUSH_LOCK_CACHE_AWARE
  8310. ExAllocateCacheAwarePushLock (
  8311. VOID
  8312. );
  8313. NTKERNELAPI
  8314. VOID
  8315. ExFreeCacheAwarePushLock (
  8316. PEX_PUSH_LOCK_CACHE_AWARE PushLock
  8317. );
  8318. NTKERNELAPI
  8319. VOID
  8320. ExAcquireCacheAwarePushLockExclusive (
  8321. IN PEX_PUSH_LOCK_CACHE_AWARE CacheAwarePushLock
  8322. );
  8323. NTKERNELAPI
  8324. VOID
  8325. ExReleaseCacheAwarePushLockExclusive (
  8326. IN PEX_PUSH_LOCK_CACHE_AWARE CacheAwarePushLock
  8327. );
  8328. PEX_PUSH_LOCK
  8329. FORCEINLINE
  8330. ExAcquireCacheAwarePushLockShared (
  8331. IN PEX_PUSH_LOCK_CACHE_AWARE CacheAwarePushLock
  8332. )
  8333. /*++
  8334. Routine Description:
  8335. Acquire a cache aware push lock shared.
  8336. Arguments:
  8337. PushLock - Cache aware push lock to be acquired
  8338. Return Value:
  8339. None
  8340. --*/
  8341. {
  8342. PEX_PUSH_LOCK PushLock;
  8343. //
  8344. // Take a single one of the slots in shared mode.
  8345. // Exclusive acquires must obtain all the slots exclusive.
  8346. //
  8347. PushLock = CacheAwarePushLock->Locks[KeGetCurrentProcessorNumber()%EX_PUSH_LOCK_FANNED_COUNT];
  8348. ExAcquirePushLockSharedAssumeNoOwner (PushLock);
  8349. // ExAcquirePushLockShared (PushLock);
  8350. return PushLock;
  8351. }
  8352. VOID
  8353. FORCEINLINE
  8354. ExReleaseCacheAwarePushLockShared (
  8355. IN PEX_PUSH_LOCK PushLock
  8356. )
  8357. /*++
  8358. Routine Description:
  8359. Acquire a cache aware push lock shared.
  8360. Arguments:
  8361. PushLock - Part of cache aware push lock returned by ExAcquireCacheAwarePushLockShared
  8362. Return Value:
  8363. None
  8364. --*/
  8365. {
  8366. ExReleasePushLockSharedAssumeSingleOwner (PushLock);
  8367. // ExReleasePushLockShared (PushLock);
  8368. return;
  8369. }
  8370. #endif // !defined(NONTOSPINTERLOCK)
  8371. //
  8372. // Define external data.
  8373. // because of indirection for all drivers external to ntoskrnl these are actually ptrs
  8374. //
  8375. #if defined(_NTDDK_) || defined(_NTIFS_) || defined(_NTHAL_) || defined(_WDMDDK_) || defined(_NTOSP_)
  8376. extern PBOOLEAN KdDebuggerNotPresent;
  8377. extern PBOOLEAN KdDebuggerEnabled;
  8378. #define KD_DEBUGGER_ENABLED *KdDebuggerEnabled
  8379. #define KD_DEBUGGER_NOT_PRESENT *KdDebuggerNotPresent
  8380. #else
  8381. extern BOOLEAN KdDebuggerNotPresent;
  8382. extern BOOLEAN KdDebuggerEnabled;
  8383. #define KD_DEBUGGER_ENABLED KdDebuggerEnabled
  8384. #define KD_DEBUGGER_NOT_PRESENT KdDebuggerNotPresent
  8385. #endif
  8386. //
  8387. // Priority increment definitions. The comment for each definition gives
  8388. // the names of the system services that use the definition when satisfying
  8389. // a wait.
  8390. //
  8391. //
  8392. // Priority increment used when satisfying a wait on an executive event
  8393. // (NtPulseEvent and NtSetEvent)
  8394. //
  8395. #define EVENT_INCREMENT 1
  8396. //
  8397. // Priority increment when no I/O has been done. This is used by device
  8398. // and file system drivers when completing an IRP (IoCompleteRequest).
  8399. //
  8400. #define IO_NO_INCREMENT 0
  8401. //
  8402. // Priority increment for completing CD-ROM I/O. This is used by CD-ROM device
  8403. // and file system drivers when completing an IRP (IoCompleteRequest)
  8404. //
  8405. #define IO_CD_ROM_INCREMENT 1
  8406. //
  8407. // Priority increment for completing disk I/O. This is used by disk device
  8408. // and file system drivers when completing an IRP (IoCompleteRequest)
  8409. //
  8410. #define IO_DISK_INCREMENT 1
  8411. // end_ntifs
  8412. //
  8413. // Priority increment for completing keyboard I/O. This is used by keyboard
  8414. // device drivers when completing an IRP (IoCompleteRequest)
  8415. //
  8416. #define IO_KEYBOARD_INCREMENT 6
  8417. // begin_ntifs
  8418. //
  8419. // Priority increment for completing mailslot I/O. This is used by the mail-
  8420. // slot file system driver when completing an IRP (IoCompleteRequest).
  8421. //
  8422. #define IO_MAILSLOT_INCREMENT 2
  8423. // end_ntifs
  8424. //
  8425. // Priority increment for completing mouse I/O. This is used by mouse device
  8426. // drivers when completing an IRP (IoCompleteRequest)
  8427. //
  8428. #define IO_MOUSE_INCREMENT 6
  8429. // begin_ntifs
  8430. //
  8431. // Priority increment for completing named pipe I/O. This is used by the
  8432. // named pipe file system driver when completing an IRP (IoCompleteRequest).
  8433. //
  8434. #define IO_NAMED_PIPE_INCREMENT 2
  8435. //
  8436. // Priority increment for completing network I/O. This is used by network
  8437. // device and network file system drivers when completing an IRP
  8438. // (IoCompleteRequest).
  8439. //
  8440. #define IO_NETWORK_INCREMENT 2
  8441. // end_ntifs
  8442. //
  8443. // Priority increment for completing parallel I/O. This is used by parallel
  8444. // device drivers when completing an IRP (IoCompleteRequest)
  8445. //
  8446. #define IO_PARALLEL_INCREMENT 1
  8447. //
  8448. // Priority increment for completing serial I/O. This is used by serial device
  8449. // drivers when completing an IRP (IoCompleteRequest)
  8450. //
  8451. #define IO_SERIAL_INCREMENT 2
  8452. //
  8453. // Priority increment for completing sound I/O. This is used by sound device
  8454. // drivers when completing an IRP (IoCompleteRequest)
  8455. //
  8456. #define IO_SOUND_INCREMENT 8
  8457. //
  8458. // Priority increment for completing video I/O. This is used by video device
  8459. // drivers when completing an IRP (IoCompleteRequest)
  8460. //
  8461. #define IO_VIDEO_INCREMENT 1
  8462. // end_ntddk end_wdm
  8463. //
  8464. // Priority increment used when satisfying a wait on an executive mutant
  8465. // (NtReleaseMutant)
  8466. //
  8467. #define MUTANT_INCREMENT 1
  8468. // begin_ntddk begin_wdm begin_ntifs
  8469. //
  8470. // Priority increment used when satisfying a wait on an executive semaphore
  8471. // (NtReleaseSemaphore)
  8472. //
  8473. #define SEMAPHORE_INCREMENT 1
  8474. //
  8475. // Define I/O system data structure type codes. Each major data structure in
  8476. // the I/O system has a type code The type field in each structure is at the
  8477. // same offset. The following values can be used to determine which type of
  8478. // data structure a pointer refers to.
  8479. //
  8480. #define IO_TYPE_ADAPTER 0x00000001
  8481. #define IO_TYPE_CONTROLLER 0x00000002
  8482. #define IO_TYPE_DEVICE 0x00000003
  8483. #define IO_TYPE_DRIVER 0x00000004
  8484. #define IO_TYPE_FILE 0x00000005
  8485. #define IO_TYPE_IRP 0x00000006
  8486. #define IO_TYPE_MASTER_ADAPTER 0x00000007
  8487. #define IO_TYPE_OPEN_PACKET 0x00000008
  8488. #define IO_TYPE_TIMER 0x00000009
  8489. #define IO_TYPE_VPB 0x0000000a
  8490. #define IO_TYPE_ERROR_LOG 0x0000000b
  8491. #define IO_TYPE_ERROR_MESSAGE 0x0000000c
  8492. #define IO_TYPE_DEVICE_OBJECT_EXTENSION 0x0000000d
  8493. //
  8494. // Define the major function codes for IRPs.
  8495. //
  8496. #define IRP_MJ_CREATE 0x00
  8497. #define IRP_MJ_CREATE_NAMED_PIPE 0x01
  8498. #define IRP_MJ_CLOSE 0x02
  8499. #define IRP_MJ_READ 0x03
  8500. #define IRP_MJ_WRITE 0x04
  8501. #define IRP_MJ_QUERY_INFORMATION 0x05
  8502. #define IRP_MJ_SET_INFORMATION 0x06
  8503. #define IRP_MJ_QUERY_EA 0x07
  8504. #define IRP_MJ_SET_EA 0x08
  8505. #define IRP_MJ_FLUSH_BUFFERS 0x09
  8506. #define IRP_MJ_QUERY_VOLUME_INFORMATION 0x0a
  8507. #define IRP_MJ_SET_VOLUME_INFORMATION 0x0b
  8508. #define IRP_MJ_DIRECTORY_CONTROL 0x0c
  8509. #define IRP_MJ_FILE_SYSTEM_CONTROL 0x0d
  8510. #define IRP_MJ_DEVICE_CONTROL 0x0e
  8511. #define IRP_MJ_INTERNAL_DEVICE_CONTROL 0x0f
  8512. #define IRP_MJ_SHUTDOWN 0x10
  8513. #define IRP_MJ_LOCK_CONTROL 0x11
  8514. #define IRP_MJ_CLEANUP 0x12
  8515. #define IRP_MJ_CREATE_MAILSLOT 0x13
  8516. #define IRP_MJ_QUERY_SECURITY 0x14
  8517. #define IRP_MJ_SET_SECURITY 0x15
  8518. #define IRP_MJ_POWER 0x16
  8519. #define IRP_MJ_SYSTEM_CONTROL 0x17
  8520. #define IRP_MJ_DEVICE_CHANGE 0x18
  8521. #define IRP_MJ_QUERY_QUOTA 0x19
  8522. #define IRP_MJ_SET_QUOTA 0x1a
  8523. #define IRP_MJ_PNP 0x1b
  8524. #define IRP_MJ_PNP_POWER IRP_MJ_PNP // Obsolete....
  8525. #define IRP_MJ_MAXIMUM_FUNCTION 0x1b
  8526. //
  8527. // Make the Scsi major code the same as internal device control.
  8528. //
  8529. #define IRP_MJ_SCSI IRP_MJ_INTERNAL_DEVICE_CONTROL
  8530. //
  8531. // Define the minor function codes for IRPs. The lower 128 codes, from 0x00 to
  8532. // 0x7f are reserved to Microsoft. The upper 128 codes, from 0x80 to 0xff, are
  8533. // reserved to customers of Microsoft.
  8534. //
  8535. // end_wdm end_ntndis
  8536. //
  8537. // Directory control minor function codes
  8538. //
  8539. #define IRP_MN_QUERY_DIRECTORY 0x01
  8540. #define IRP_MN_NOTIFY_CHANGE_DIRECTORY 0x02
  8541. //
  8542. // File system control minor function codes. Note that "user request" is
  8543. // assumed to be zero by both the I/O system and file systems. Do not change
  8544. // this value.
  8545. //
  8546. #define IRP_MN_USER_FS_REQUEST 0x00
  8547. #define IRP_MN_MOUNT_VOLUME 0x01
  8548. #define IRP_MN_VERIFY_VOLUME 0x02
  8549. #define IRP_MN_LOAD_FILE_SYSTEM 0x03
  8550. #define IRP_MN_TRACK_LINK 0x04 // To be obsoleted soon
  8551. #define IRP_MN_KERNEL_CALL 0x04
  8552. //
  8553. // Lock control minor function codes
  8554. //
  8555. #define IRP_MN_LOCK 0x01
  8556. #define IRP_MN_UNLOCK_SINGLE 0x02
  8557. #define IRP_MN_UNLOCK_ALL 0x03
  8558. #define IRP_MN_UNLOCK_ALL_BY_KEY 0x04
  8559. //
  8560. // Read and Write minor function codes for file systems supporting Lan Manager
  8561. // software. All of these subfunction codes are invalid if the file has been
  8562. // opened with FO_NO_INTERMEDIATE_BUFFERING. They are also invalid in combi-
  8563. // nation with synchronous calls (Irp Flag or file open option).
  8564. //
  8565. // Note that "normal" is assumed to be zero by both the I/O system and file
  8566. // systems. Do not change this value.
  8567. //
  8568. #define IRP_MN_NORMAL 0x00
  8569. #define IRP_MN_DPC 0x01
  8570. #define IRP_MN_MDL 0x02
  8571. #define IRP_MN_COMPLETE 0x04
  8572. #define IRP_MN_COMPRESSED 0x08
  8573. #define IRP_MN_MDL_DPC (IRP_MN_MDL | IRP_MN_DPC)
  8574. #define IRP_MN_COMPLETE_MDL (IRP_MN_COMPLETE | IRP_MN_MDL)
  8575. #define IRP_MN_COMPLETE_MDL_DPC (IRP_MN_COMPLETE_MDL | IRP_MN_DPC)
  8576. // begin_wdm
  8577. //
  8578. // Device Control Request minor function codes for SCSI support. Note that
  8579. // user requests are assumed to be zero.
  8580. //
  8581. #define IRP_MN_SCSI_CLASS 0x01
  8582. //
  8583. // PNP minor function codes.
  8584. //
  8585. #define IRP_MN_START_DEVICE 0x00
  8586. #define IRP_MN_QUERY_REMOVE_DEVICE 0x01
  8587. #define IRP_MN_REMOVE_DEVICE 0x02
  8588. #define IRP_MN_CANCEL_REMOVE_DEVICE 0x03
  8589. #define IRP_MN_STOP_DEVICE 0x04
  8590. #define IRP_MN_QUERY_STOP_DEVICE 0x05
  8591. #define IRP_MN_CANCEL_STOP_DEVICE 0x06
  8592. #define IRP_MN_QUERY_DEVICE_RELATIONS 0x07
  8593. #define IRP_MN_QUERY_INTERFACE 0x08
  8594. #define IRP_MN_QUERY_CAPABILITIES 0x09
  8595. #define IRP_MN_QUERY_RESOURCES 0x0A
  8596. #define IRP_MN_QUERY_RESOURCE_REQUIREMENTS 0x0B
  8597. #define IRP_MN_QUERY_DEVICE_TEXT 0x0C
  8598. #define IRP_MN_FILTER_RESOURCE_REQUIREMENTS 0x0D
  8599. #define IRP_MN_READ_CONFIG 0x0F
  8600. #define IRP_MN_WRITE_CONFIG 0x10
  8601. #define IRP_MN_EJECT 0x11
  8602. #define IRP_MN_SET_LOCK 0x12
  8603. #define IRP_MN_QUERY_ID 0x13
  8604. #define IRP_MN_QUERY_PNP_DEVICE_STATE 0x14
  8605. #define IRP_MN_QUERY_BUS_INFORMATION 0x15
  8606. #define IRP_MN_DEVICE_USAGE_NOTIFICATION 0x16
  8607. #define IRP_MN_SURPRISE_REMOVAL 0x17
  8608. // end_wdm
  8609. #define IRP_MN_QUERY_LEGACY_BUS_INFORMATION 0x18
  8610. // begin_wdm
  8611. //
  8612. // POWER minor function codes
  8613. //
  8614. #define IRP_MN_WAIT_WAKE 0x00
  8615. #define IRP_MN_POWER_SEQUENCE 0x01
  8616. #define IRP_MN_SET_POWER 0x02
  8617. #define IRP_MN_QUERY_POWER 0x03
  8618. // begin_ntminiport
  8619. //
  8620. // WMI minor function codes under IRP_MJ_SYSTEM_CONTROL
  8621. //
  8622. #define IRP_MN_QUERY_ALL_DATA 0x00
  8623. #define IRP_MN_QUERY_SINGLE_INSTANCE 0x01
  8624. #define IRP_MN_CHANGE_SINGLE_INSTANCE 0x02
  8625. #define IRP_MN_CHANGE_SINGLE_ITEM 0x03
  8626. #define IRP_MN_ENABLE_EVENTS 0x04
  8627. #define IRP_MN_DISABLE_EVENTS 0x05
  8628. #define IRP_MN_ENABLE_COLLECTION 0x06
  8629. #define IRP_MN_DISABLE_COLLECTION 0x07
  8630. #define IRP_MN_REGINFO 0x08
  8631. #define IRP_MN_EXECUTE_METHOD 0x09
  8632. // Minor code 0x0a is reserved
  8633. #define IRP_MN_REGINFO_EX 0x0b
  8634. // end_ntminiport
  8635. //
  8636. // Define option flags for IoCreateFile. Note that these values must be
  8637. // exactly the same as the SL_... flags for a create function. Note also
  8638. // that there are flags that may be passed to IoCreateFile that are not
  8639. // placed in the stack location for the create IRP. These flags start in
  8640. // the next byte.
  8641. //
  8642. #define IO_FORCE_ACCESS_CHECK 0x0001
  8643. #define IO_NO_PARAMETER_CHECKING 0x0100
  8644. //
  8645. // Define Information fields for whether or not a REPARSE or a REMOUNT has
  8646. // occurred in the file system.
  8647. //
  8648. #define IO_REPARSE 0x0
  8649. #define IO_REMOUNT 0x1
  8650. // end_ntddk end_wdm
  8651. #define IO_CHECK_CREATE_PARAMETERS 0x0200
  8652. #define IO_ATTACH_DEVICE 0x0400
  8653. //
  8654. // This flag is only meaning full to IoCreateFileSpecifyDeviceObjectHint.
  8655. // FileHandles created using IoCreateFileSpecifyDeviceObjectHint with this
  8656. // flag set will bypass ShareAccess checks on this file.
  8657. //
  8658. #define IO_IGNORE_SHARE_ACCESS_CHECK 0x0800 // Ignores share access checks on opens.
  8659. typedef
  8660. VOID
  8661. (*PSTALL_ROUTINE) (
  8662. IN ULONG Delay
  8663. );
  8664. //
  8665. // Define the interfaces for the dump driver's routines.
  8666. //
  8667. typedef
  8668. BOOLEAN
  8669. (*PDUMP_DRIVER_OPEN) (
  8670. IN LARGE_INTEGER PartitionOffset
  8671. );
  8672. typedef
  8673. NTSTATUS
  8674. (*PDUMP_DRIVER_WRITE) (
  8675. IN PLARGE_INTEGER DiskByteOffset,
  8676. IN PMDL Mdl
  8677. );
  8678. //
  8679. // Actions accepted by DRIVER_WRITE_PENDING
  8680. //
  8681. #define IO_DUMP_WRITE_FULFILL 0 // fulfill IO request as if DRIVER_WAIT
  8682. #define IO_DUMP_WRITE_START 1 // start new IO
  8683. #define IO_DUMP_WRITE_RESUME 2 // resume pending IO
  8684. #define IO_DUMP_WRITE_FINISH 3 // finish pending IO
  8685. #define IO_DUMP_WRITE_INIT 4 // initialize locals
  8686. // size of data used by WRITE_PENDING that should be preserved
  8687. // between the calls
  8688. #define IO_DUMP_WRITE_DATA_PAGES 2
  8689. #define IO_DUMP_WRITE_DATA_SIZE (IO_DUMP_WRITE_DATA_PAGES << PAGE_SHIFT)
  8690. typedef
  8691. NTSTATUS
  8692. (*PDUMP_DRIVER_WRITE_PENDING) (
  8693. IN LONG Action,
  8694. IN PLARGE_INTEGER DiskByteOffset,
  8695. IN PMDL Mdl,
  8696. IN PVOID LocalData
  8697. );
  8698. typedef
  8699. VOID
  8700. (*PDUMP_DRIVER_FINISH) (
  8701. VOID
  8702. );
  8703. struct _ADAPTER_OBJECT;
  8704. //
  8705. // This is the information passed from the system to the disk dump driver
  8706. // during the driver's initialization.
  8707. //
  8708. typedef struct _DUMP_INITIALIZATION_CONTEXT {
  8709. ULONG Length;
  8710. ULONG Reserved; // Was MBR Checksum. Should be zero now.
  8711. PVOID MemoryBlock;
  8712. PVOID CommonBuffer[2];
  8713. PHYSICAL_ADDRESS PhysicalAddress[2];
  8714. PSTALL_ROUTINE StallRoutine;
  8715. PDUMP_DRIVER_OPEN OpenRoutine;
  8716. PDUMP_DRIVER_WRITE WriteRoutine;
  8717. PDUMP_DRIVER_FINISH FinishRoutine;
  8718. struct _ADAPTER_OBJECT *AdapterObject;
  8719. PVOID MappedRegisterBase;
  8720. PVOID PortConfiguration;
  8721. BOOLEAN CrashDump;
  8722. ULONG MaximumTransferSize;
  8723. ULONG CommonBufferSize;
  8724. PVOID TargetAddress; //Opaque pointer to target address structure
  8725. PDUMP_DRIVER_WRITE_PENDING WritePendingRoutine;
  8726. ULONG PartitionStyle;
  8727. union {
  8728. struct {
  8729. ULONG Signature;
  8730. ULONG CheckSum;
  8731. } Mbr;
  8732. struct {
  8733. GUID DiskId;
  8734. } Gpt;
  8735. } DiskInfo;
  8736. } DUMP_INITIALIZATION_CONTEXT, *PDUMP_INITIALIZATION_CONTEXT;
  8737. // begin_ntddk
  8738. //
  8739. // Define callout routine type for use in IoQueryDeviceDescription().
  8740. //
  8741. typedef NTSTATUS (*PIO_QUERY_DEVICE_ROUTINE)(
  8742. IN PVOID Context,
  8743. IN PUNICODE_STRING PathName,
  8744. IN INTERFACE_TYPE BusType,
  8745. IN ULONG BusNumber,
  8746. IN PKEY_VALUE_FULL_INFORMATION *BusInformation,
  8747. IN CONFIGURATION_TYPE ControllerType,
  8748. IN ULONG ControllerNumber,
  8749. IN PKEY_VALUE_FULL_INFORMATION *ControllerInformation,
  8750. IN CONFIGURATION_TYPE PeripheralType,
  8751. IN ULONG PeripheralNumber,
  8752. IN PKEY_VALUE_FULL_INFORMATION *PeripheralInformation
  8753. );
  8754. // Defines the order of the information in the array of
  8755. // PKEY_VALUE_FULL_INFORMATION.
  8756. //
  8757. typedef enum _IO_QUERY_DEVICE_DATA_FORMAT {
  8758. IoQueryDeviceIdentifier = 0,
  8759. IoQueryDeviceConfigurationData,
  8760. IoQueryDeviceComponentInformation,
  8761. IoQueryDeviceMaxData
  8762. } IO_QUERY_DEVICE_DATA_FORMAT, *PIO_QUERY_DEVICE_DATA_FORMAT;
  8763. // begin_wdm begin_ntifs
  8764. //
  8765. // Define the objects that can be created by IoCreateFile.
  8766. //
  8767. typedef enum _CREATE_FILE_TYPE {
  8768. CreateFileTypeNone,
  8769. CreateFileTypeNamedPipe,
  8770. CreateFileTypeMailslot
  8771. } CREATE_FILE_TYPE;
  8772. // end_ntddk end_wdm end_ntifs
  8773. //
  8774. // Define the named pipe create parameters structure used for internal calls
  8775. // to IoCreateFile when a named pipe is being created. This structure allows
  8776. // code invoking this routine to pass information specific to this function
  8777. // when creating a named pipe.
  8778. //
  8779. typedef struct _NAMED_PIPE_CREATE_PARAMETERS {
  8780. ULONG NamedPipeType;
  8781. ULONG ReadMode;
  8782. ULONG CompletionMode;
  8783. ULONG MaximumInstances;
  8784. ULONG InboundQuota;
  8785. ULONG OutboundQuota;
  8786. LARGE_INTEGER DefaultTimeout;
  8787. BOOLEAN TimeoutSpecified;
  8788. } NAMED_PIPE_CREATE_PARAMETERS, *PNAMED_PIPE_CREATE_PARAMETERS;
  8789. //
  8790. // Define the structures used by the I/O system
  8791. //
  8792. //
  8793. // Define empty typedefs for the _IRP, _DEVICE_OBJECT, and _DRIVER_OBJECT
  8794. // structures so they may be referenced by function types before they are
  8795. // actually defined.
  8796. //
  8797. struct _DEVICE_DESCRIPTION;
  8798. struct _DEVICE_OBJECT;
  8799. struct _DMA_ADAPTER;
  8800. struct _DRIVER_OBJECT;
  8801. struct _DRIVE_LAYOUT_INFORMATION;
  8802. struct _DISK_PARTITION;
  8803. struct _FILE_OBJECT;
  8804. struct DECLSPEC_ALIGN(MEMORY_ALLOCATION_ALIGNMENT) _IRP;
  8805. struct _SCSI_REQUEST_BLOCK;
  8806. struct _SCATTER_GATHER_LIST;
  8807. //
  8808. // Define the I/O version of a DPC routine.
  8809. //
  8810. typedef
  8811. VOID
  8812. (*PIO_DPC_ROUTINE) (
  8813. IN PKDPC Dpc,
  8814. IN struct _DEVICE_OBJECT *DeviceObject,
  8815. IN struct _IRP *Irp,
  8816. IN PVOID Context
  8817. );
  8818. //
  8819. // Define driver timer routine type.
  8820. //
  8821. typedef
  8822. VOID
  8823. (*PIO_TIMER_ROUTINE) (
  8824. IN struct _DEVICE_OBJECT *DeviceObject,
  8825. IN PVOID Context
  8826. );
  8827. //
  8828. // Define driver initialization routine type.
  8829. //
  8830. typedef
  8831. NTSTATUS
  8832. (*PDRIVER_INITIALIZE) (
  8833. IN struct _DRIVER_OBJECT *DriverObject,
  8834. IN PUNICODE_STRING RegistryPath
  8835. );
  8836. // end_wdm
  8837. //
  8838. // Define driver reinitialization routine type.
  8839. //
  8840. typedef
  8841. VOID
  8842. (*PDRIVER_REINITIALIZE) (
  8843. IN struct _DRIVER_OBJECT *DriverObject,
  8844. IN PVOID Context,
  8845. IN ULONG Count
  8846. );
  8847. // begin_wdm begin_ntndis
  8848. //
  8849. // Define driver cancel routine type.
  8850. //
  8851. typedef
  8852. VOID
  8853. (*PDRIVER_CANCEL) (
  8854. IN struct _DEVICE_OBJECT *DeviceObject,
  8855. IN struct _IRP *Irp
  8856. );
  8857. //
  8858. // Define driver dispatch routine type.
  8859. //
  8860. typedef
  8861. NTSTATUS
  8862. (*PDRIVER_DISPATCH) (
  8863. IN struct _DEVICE_OBJECT *DeviceObject,
  8864. IN struct _IRP *Irp
  8865. );
  8866. //
  8867. // Define driver start I/O routine type.
  8868. //
  8869. typedef
  8870. VOID
  8871. (*PDRIVER_STARTIO) (
  8872. IN struct _DEVICE_OBJECT *DeviceObject,
  8873. IN struct _IRP *Irp
  8874. );
  8875. //
  8876. // Define driver unload routine type.
  8877. //
  8878. typedef
  8879. VOID
  8880. (*PDRIVER_UNLOAD) (
  8881. IN struct _DRIVER_OBJECT *DriverObject
  8882. );
  8883. //
  8884. // Define driver AddDevice routine type.
  8885. //
  8886. typedef
  8887. NTSTATUS
  8888. (*PDRIVER_ADD_DEVICE) (
  8889. IN struct _DRIVER_OBJECT *DriverObject,
  8890. IN struct _DEVICE_OBJECT *PhysicalDeviceObject
  8891. );
  8892. //
  8893. // Define fast I/O procedure prototypes.
  8894. //
  8895. // Fast I/O read and write procedures.
  8896. //
  8897. typedef
  8898. BOOLEAN
  8899. (*PFAST_IO_CHECK_IF_POSSIBLE) (
  8900. IN struct _FILE_OBJECT *FileObject,
  8901. IN PLARGE_INTEGER FileOffset,
  8902. IN ULONG Length,
  8903. IN BOOLEAN Wait,
  8904. IN ULONG LockKey,
  8905. IN BOOLEAN CheckForReadOperation,
  8906. OUT PIO_STATUS_BLOCK IoStatus,
  8907. IN struct _DEVICE_OBJECT *DeviceObject
  8908. );
  8909. typedef
  8910. BOOLEAN
  8911. (*PFAST_IO_READ) (
  8912. IN struct _FILE_OBJECT *FileObject,
  8913. IN PLARGE_INTEGER FileOffset,
  8914. IN ULONG Length,
  8915. IN BOOLEAN Wait,
  8916. IN ULONG LockKey,
  8917. OUT PVOID Buffer,
  8918. OUT PIO_STATUS_BLOCK IoStatus,
  8919. IN struct _DEVICE_OBJECT *DeviceObject
  8920. );
  8921. typedef
  8922. BOOLEAN
  8923. (*PFAST_IO_WRITE) (
  8924. IN struct _FILE_OBJECT *FileObject,
  8925. IN PLARGE_INTEGER FileOffset,
  8926. IN ULONG Length,
  8927. IN BOOLEAN Wait,
  8928. IN ULONG LockKey,
  8929. IN PVOID Buffer,
  8930. OUT PIO_STATUS_BLOCK IoStatus,
  8931. IN struct _DEVICE_OBJECT *DeviceObject
  8932. );
  8933. //
  8934. // Fast I/O query basic and standard information procedures.
  8935. //
  8936. typedef
  8937. BOOLEAN
  8938. (*PFAST_IO_QUERY_BASIC_INFO) (
  8939. IN struct _FILE_OBJECT *FileObject,
  8940. IN BOOLEAN Wait,
  8941. OUT PFILE_BASIC_INFORMATION Buffer,
  8942. OUT PIO_STATUS_BLOCK IoStatus,
  8943. IN struct _DEVICE_OBJECT *DeviceObject
  8944. );
  8945. typedef
  8946. BOOLEAN
  8947. (*PFAST_IO_QUERY_STANDARD_INFO) (
  8948. IN struct _FILE_OBJECT *FileObject,
  8949. IN BOOLEAN Wait,
  8950. OUT PFILE_STANDARD_INFORMATION Buffer,
  8951. OUT PIO_STATUS_BLOCK IoStatus,
  8952. IN struct _DEVICE_OBJECT *DeviceObject
  8953. );
  8954. //
  8955. // Fast I/O lock and unlock procedures.
  8956. //
  8957. typedef
  8958. BOOLEAN
  8959. (*PFAST_IO_LOCK) (
  8960. IN struct _FILE_OBJECT *FileObject,
  8961. IN PLARGE_INTEGER FileOffset,
  8962. IN PLARGE_INTEGER Length,
  8963. PEPROCESS ProcessId,
  8964. ULONG Key,
  8965. BOOLEAN FailImmediately,
  8966. BOOLEAN ExclusiveLock,
  8967. OUT PIO_STATUS_BLOCK IoStatus,
  8968. IN struct _DEVICE_OBJECT *DeviceObject
  8969. );
  8970. typedef
  8971. BOOLEAN
  8972. (*PFAST_IO_UNLOCK_SINGLE) (
  8973. IN struct _FILE_OBJECT *FileObject,
  8974. IN PLARGE_INTEGER FileOffset,
  8975. IN PLARGE_INTEGER Length,
  8976. PEPROCESS ProcessId,
  8977. ULONG Key,
  8978. OUT PIO_STATUS_BLOCK IoStatus,
  8979. IN struct _DEVICE_OBJECT *DeviceObject
  8980. );
  8981. typedef
  8982. BOOLEAN
  8983. (*PFAST_IO_UNLOCK_ALL) (
  8984. IN struct _FILE_OBJECT *FileObject,
  8985. PEPROCESS ProcessId,
  8986. OUT PIO_STATUS_BLOCK IoStatus,
  8987. IN struct _DEVICE_OBJECT *DeviceObject
  8988. );
  8989. typedef
  8990. BOOLEAN
  8991. (*PFAST_IO_UNLOCK_ALL_BY_KEY) (
  8992. IN struct _FILE_OBJECT *FileObject,
  8993. PVOID ProcessId,
  8994. ULONG Key,
  8995. OUT PIO_STATUS_BLOCK IoStatus,
  8996. IN struct _DEVICE_OBJECT *DeviceObject
  8997. );
  8998. //
  8999. // Fast I/O device control procedure.
  9000. //
  9001. typedef
  9002. BOOLEAN
  9003. (*PFAST_IO_DEVICE_CONTROL) (
  9004. IN struct _FILE_OBJECT *FileObject,
  9005. IN BOOLEAN Wait,
  9006. IN PVOID InputBuffer OPTIONAL,
  9007. IN ULONG InputBufferLength,
  9008. OUT PVOID OutputBuffer OPTIONAL,
  9009. IN ULONG OutputBufferLength,
  9010. IN ULONG IoControlCode,
  9011. OUT PIO_STATUS_BLOCK IoStatus,
  9012. IN struct _DEVICE_OBJECT *DeviceObject
  9013. );
  9014. //
  9015. // Define callbacks for NtCreateSection to synchronize correctly with
  9016. // the file system. It pre-acquires the resources that will be needed
  9017. // when calling to query and set file/allocation size in the file system.
  9018. //
  9019. typedef
  9020. VOID
  9021. (*PFAST_IO_ACQUIRE_FILE) (
  9022. IN struct _FILE_OBJECT *FileObject
  9023. );
  9024. typedef
  9025. VOID
  9026. (*PFAST_IO_RELEASE_FILE) (
  9027. IN struct _FILE_OBJECT *FileObject
  9028. );
  9029. //
  9030. // Define callback for drivers that have device objects attached to lower-
  9031. // level drivers' device objects. This callback is made when the lower-level
  9032. // driver is deleting its device object.
  9033. //
  9034. typedef
  9035. VOID
  9036. (*PFAST_IO_DETACH_DEVICE) (
  9037. IN struct _DEVICE_OBJECT *SourceDevice,
  9038. IN struct _DEVICE_OBJECT *TargetDevice
  9039. );
  9040. //
  9041. // This structure is used by the server to quickly get the information needed
  9042. // to service a server open call. It is takes what would be two fast io calls
  9043. // one for basic information and the other for standard information and makes
  9044. // it into one call.
  9045. //
  9046. typedef
  9047. BOOLEAN
  9048. (*PFAST_IO_QUERY_NETWORK_OPEN_INFO) (
  9049. IN struct _FILE_OBJECT *FileObject,
  9050. IN BOOLEAN Wait,
  9051. OUT struct _FILE_NETWORK_OPEN_INFORMATION *Buffer,
  9052. OUT struct _IO_STATUS_BLOCK *IoStatus,
  9053. IN struct _DEVICE_OBJECT *DeviceObject
  9054. );
  9055. //
  9056. // Define Mdl-based routines for the server to call
  9057. //
  9058. typedef
  9059. BOOLEAN
  9060. (*PFAST_IO_MDL_READ) (
  9061. IN struct _FILE_OBJECT *FileObject,
  9062. IN PLARGE_INTEGER FileOffset,
  9063. IN ULONG Length,
  9064. IN ULONG LockKey,
  9065. OUT PMDL *MdlChain,
  9066. OUT PIO_STATUS_BLOCK IoStatus,
  9067. IN struct _DEVICE_OBJECT *DeviceObject
  9068. );
  9069. typedef
  9070. BOOLEAN
  9071. (*PFAST_IO_MDL_READ_COMPLETE) (
  9072. IN struct _FILE_OBJECT *FileObject,
  9073. IN PMDL MdlChain,
  9074. IN struct _DEVICE_OBJECT *DeviceObject
  9075. );
  9076. typedef
  9077. BOOLEAN
  9078. (*PFAST_IO_PREPARE_MDL_WRITE) (
  9079. IN struct _FILE_OBJECT *FileObject,
  9080. IN PLARGE_INTEGER FileOffset,
  9081. IN ULONG Length,
  9082. IN ULONG LockKey,
  9083. OUT PMDL *MdlChain,
  9084. OUT PIO_STATUS_BLOCK IoStatus,
  9085. IN struct _DEVICE_OBJECT *DeviceObject
  9086. );
  9087. typedef
  9088. BOOLEAN
  9089. (*PFAST_IO_MDL_WRITE_COMPLETE) (
  9090. IN struct _FILE_OBJECT *FileObject,
  9091. IN PLARGE_INTEGER FileOffset,
  9092. IN PMDL MdlChain,
  9093. IN struct _DEVICE_OBJECT *DeviceObject
  9094. );
  9095. //
  9096. // If this routine is present, it will be called by FsRtl
  9097. // to acquire the file for the mapped page writer.
  9098. //
  9099. typedef
  9100. NTSTATUS
  9101. (*PFAST_IO_ACQUIRE_FOR_MOD_WRITE) (
  9102. IN struct _FILE_OBJECT *FileObject,
  9103. IN PLARGE_INTEGER EndingOffset,
  9104. OUT struct _ERESOURCE **ResourceToRelease,
  9105. IN struct _DEVICE_OBJECT *DeviceObject
  9106. );
  9107. typedef
  9108. NTSTATUS
  9109. (*PFAST_IO_RELEASE_FOR_MOD_WRITE) (
  9110. IN struct _FILE_OBJECT *FileObject,
  9111. IN struct _ERESOURCE *ResourceToRelease,
  9112. IN struct _DEVICE_OBJECT *DeviceObject
  9113. );
  9114. //
  9115. // If this routine is present, it will be called by FsRtl
  9116. // to acquire the file for the mapped page writer.
  9117. //
  9118. typedef
  9119. NTSTATUS
  9120. (*PFAST_IO_ACQUIRE_FOR_CCFLUSH) (
  9121. IN struct _FILE_OBJECT *FileObject,
  9122. IN struct _DEVICE_OBJECT *DeviceObject
  9123. );
  9124. typedef
  9125. NTSTATUS
  9126. (*PFAST_IO_RELEASE_FOR_CCFLUSH) (
  9127. IN struct _FILE_OBJECT *FileObject,
  9128. IN struct _DEVICE_OBJECT *DeviceObject
  9129. );
  9130. typedef
  9131. BOOLEAN
  9132. (*PFAST_IO_READ_COMPRESSED) (
  9133. IN struct _FILE_OBJECT *FileObject,
  9134. IN PLARGE_INTEGER FileOffset,
  9135. IN ULONG Length,
  9136. IN ULONG LockKey,
  9137. OUT PVOID Buffer,
  9138. OUT PMDL *MdlChain,
  9139. OUT PIO_STATUS_BLOCK IoStatus,
  9140. OUT struct _COMPRESSED_DATA_INFO *CompressedDataInfo,
  9141. IN ULONG CompressedDataInfoLength,
  9142. IN struct _DEVICE_OBJECT *DeviceObject
  9143. );
  9144. typedef
  9145. BOOLEAN
  9146. (*PFAST_IO_WRITE_COMPRESSED) (
  9147. IN struct _FILE_OBJECT *FileObject,
  9148. IN PLARGE_INTEGER FileOffset,
  9149. IN ULONG Length,
  9150. IN ULONG LockKey,
  9151. IN PVOID Buffer,
  9152. OUT PMDL *MdlChain,
  9153. OUT PIO_STATUS_BLOCK IoStatus,
  9154. IN struct _COMPRESSED_DATA_INFO *CompressedDataInfo,
  9155. IN ULONG CompressedDataInfoLength,
  9156. IN struct _DEVICE_OBJECT *DeviceObject
  9157. );
  9158. typedef
  9159. BOOLEAN
  9160. (*PFAST_IO_MDL_READ_COMPLETE_COMPRESSED) (
  9161. IN struct _FILE_OBJECT *FileObject,
  9162. IN PMDL MdlChain,
  9163. IN struct _DEVICE_OBJECT *DeviceObject
  9164. );
  9165. typedef
  9166. BOOLEAN
  9167. (*PFAST_IO_MDL_WRITE_COMPLETE_COMPRESSED) (
  9168. IN struct _FILE_OBJECT *FileObject,
  9169. IN PLARGE_INTEGER FileOffset,
  9170. IN PMDL MdlChain,
  9171. IN struct _DEVICE_OBJECT *DeviceObject
  9172. );
  9173. typedef
  9174. BOOLEAN
  9175. (*PFAST_IO_QUERY_OPEN) (
  9176. IN struct _IRP *Irp,
  9177. OUT PFILE_NETWORK_OPEN_INFORMATION NetworkInformation,
  9178. IN struct _DEVICE_OBJECT *DeviceObject
  9179. );
  9180. //
  9181. // Define the structure to describe the Fast I/O dispatch routines. Any
  9182. // additions made to this structure MUST be added monotonically to the end
  9183. // of the structure, and fields CANNOT be removed from the middle.
  9184. //
  9185. typedef struct _FAST_IO_DISPATCH {
  9186. ULONG SizeOfFastIoDispatch;
  9187. PFAST_IO_CHECK_IF_POSSIBLE FastIoCheckIfPossible;
  9188. PFAST_IO_READ FastIoRead;
  9189. PFAST_IO_WRITE FastIoWrite;
  9190. PFAST_IO_QUERY_BASIC_INFO FastIoQueryBasicInfo;
  9191. PFAST_IO_QUERY_STANDARD_INFO FastIoQueryStandardInfo;
  9192. PFAST_IO_LOCK FastIoLock;
  9193. PFAST_IO_UNLOCK_SINGLE FastIoUnlockSingle;
  9194. PFAST_IO_UNLOCK_ALL FastIoUnlockAll;
  9195. PFAST_IO_UNLOCK_ALL_BY_KEY FastIoUnlockAllByKey;
  9196. PFAST_IO_DEVICE_CONTROL FastIoDeviceControl;
  9197. PFAST_IO_ACQUIRE_FILE AcquireFileForNtCreateSection;
  9198. PFAST_IO_RELEASE_FILE ReleaseFileForNtCreateSection;
  9199. PFAST_IO_DETACH_DEVICE FastIoDetachDevice;
  9200. PFAST_IO_QUERY_NETWORK_OPEN_INFO FastIoQueryNetworkOpenInfo;
  9201. PFAST_IO_ACQUIRE_FOR_MOD_WRITE AcquireForModWrite;
  9202. PFAST_IO_MDL_READ MdlRead;
  9203. PFAST_IO_MDL_READ_COMPLETE MdlReadComplete;
  9204. PFAST_IO_PREPARE_MDL_WRITE PrepareMdlWrite;
  9205. PFAST_IO_MDL_WRITE_COMPLETE MdlWriteComplete;
  9206. PFAST_IO_READ_COMPRESSED FastIoReadCompressed;
  9207. PFAST_IO_WRITE_COMPRESSED FastIoWriteCompressed;
  9208. PFAST_IO_MDL_READ_COMPLETE_COMPRESSED MdlReadCompleteCompressed;
  9209. PFAST_IO_MDL_WRITE_COMPLETE_COMPRESSED MdlWriteCompleteCompressed;
  9210. PFAST_IO_QUERY_OPEN FastIoQueryOpen;
  9211. PFAST_IO_RELEASE_FOR_MOD_WRITE ReleaseForModWrite;
  9212. PFAST_IO_ACQUIRE_FOR_CCFLUSH AcquireForCcFlush;
  9213. PFAST_IO_RELEASE_FOR_CCFLUSH ReleaseForCcFlush;
  9214. } FAST_IO_DISPATCH, *PFAST_IO_DISPATCH;
  9215. //
  9216. // Define the actions that a driver execution routine may request of the
  9217. // adapter/controller allocation routines upon return.
  9218. //
  9219. typedef enum _IO_ALLOCATION_ACTION {
  9220. KeepObject = 1,
  9221. DeallocateObject,
  9222. DeallocateObjectKeepRegisters
  9223. } IO_ALLOCATION_ACTION, *PIO_ALLOCATION_ACTION;
  9224. //
  9225. // Define device driver adapter/controller execution routine.
  9226. //
  9227. typedef
  9228. IO_ALLOCATION_ACTION
  9229. (*PDRIVER_CONTROL) (
  9230. IN struct _DEVICE_OBJECT *DeviceObject,
  9231. IN struct _IRP *Irp,
  9232. IN PVOID MapRegisterBase,
  9233. IN PVOID Context
  9234. );
  9235. //
  9236. // Define the I/O system's security context type for use by file system's
  9237. // when checking access to volumes, files, and directories.
  9238. //
  9239. typedef struct _IO_SECURITY_CONTEXT {
  9240. PSECURITY_QUALITY_OF_SERVICE SecurityQos;
  9241. PACCESS_STATE AccessState;
  9242. ACCESS_MASK DesiredAccess;
  9243. ULONG FullCreateOptions;
  9244. } IO_SECURITY_CONTEXT, *PIO_SECURITY_CONTEXT;
  9245. //
  9246. // Define Volume Parameter Block (VPB) flags.
  9247. //
  9248. #define VPB_MOUNTED 0x00000001
  9249. #define VPB_LOCKED 0x00000002
  9250. #define VPB_PERSISTENT 0x00000004
  9251. #define VPB_REMOVE_PENDING 0x00000008
  9252. #define VPB_RAW_MOUNT 0x00000010
  9253. //
  9254. // Volume Parameter Block (VPB)
  9255. //
  9256. #define MAXIMUM_VOLUME_LABEL_LENGTH (32 * sizeof(WCHAR)) // 32 characters
  9257. typedef struct _VPB {
  9258. CSHORT Type;
  9259. CSHORT Size;
  9260. USHORT Flags;
  9261. USHORT VolumeLabelLength; // in bytes
  9262. struct _DEVICE_OBJECT *DeviceObject;
  9263. struct _DEVICE_OBJECT *RealDevice;
  9264. ULONG SerialNumber;
  9265. ULONG ReferenceCount;
  9266. WCHAR VolumeLabel[MAXIMUM_VOLUME_LABEL_LENGTH / sizeof(WCHAR)];
  9267. } VPB, *PVPB;
  9268. #if defined(_WIN64)
  9269. //
  9270. // Use __inline DMA macros (hal.h)
  9271. //
  9272. #ifndef USE_DMA_MACROS
  9273. #define USE_DMA_MACROS
  9274. #endif
  9275. //
  9276. // Only PnP drivers!
  9277. //
  9278. #ifndef NO_LEGACY_DRIVERS
  9279. #define NO_LEGACY_DRIVERS
  9280. #endif
  9281. #endif // _WIN64
  9282. #if defined(USE_DMA_MACROS) && (defined(_NTDDK_) || defined(_NTDRIVER_) || defined(_NTOSP_))
  9283. // begin_wdm
  9284. //
  9285. // Define object type specific fields of various objects used by the I/O system
  9286. //
  9287. typedef struct _DMA_ADAPTER *PADAPTER_OBJECT;
  9288. // end_wdm
  9289. #else
  9290. //
  9291. // Define object type specific fields of various objects used by the I/O system
  9292. //
  9293. typedef struct _ADAPTER_OBJECT *PADAPTER_OBJECT; // ntndis
  9294. #endif // USE_DMA_MACROS && (_NTDDK_ || _NTDRIVER_ || _NTOSP_)
  9295. // begin_wdm
  9296. //
  9297. // Define Wait Context Block (WCB)
  9298. //
  9299. typedef struct _WAIT_CONTEXT_BLOCK {
  9300. KDEVICE_QUEUE_ENTRY WaitQueueEntry;
  9301. PDRIVER_CONTROL DeviceRoutine;
  9302. PVOID DeviceContext;
  9303. ULONG NumberOfMapRegisters;
  9304. PVOID DeviceObject;
  9305. PVOID CurrentIrp;
  9306. PKDPC BufferChainingDpc;
  9307. } WAIT_CONTEXT_BLOCK, *PWAIT_CONTEXT_BLOCK;
  9308. // end_wdm
  9309. typedef struct _CONTROLLER_OBJECT {
  9310. CSHORT Type;
  9311. CSHORT Size;
  9312. PVOID ControllerExtension;
  9313. KDEVICE_QUEUE DeviceWaitQueue;
  9314. ULONG Spare1;
  9315. LARGE_INTEGER Spare2;
  9316. } CONTROLLER_OBJECT, *PCONTROLLER_OBJECT;
  9317. // begin_wdm
  9318. //
  9319. // Define Device Object (DO) flags
  9320. //
  9321. // end_wdm end_ntddk end_nthal end_ntifs
  9322. #define DO_VERIFY_VOLUME 0x00000002 // ntddk nthal ntifs wdm
  9323. #define DO_BUFFERED_IO 0x00000004 // ntddk nthal ntifs wdm
  9324. #define DO_EXCLUSIVE 0x00000008 // ntddk nthal ntifs wdm
  9325. #define DO_DIRECT_IO 0x00000010 // ntddk nthal ntifs wdm
  9326. #define DO_MAP_IO_BUFFER 0x00000020 // ntddk nthal ntifs wdm
  9327. #define DO_DEVICE_HAS_NAME 0x00000040 // ntddk nthal ntifs
  9328. #define DO_DEVICE_INITIALIZING 0x00000080 // ntddk nthal ntifs wdm
  9329. #define DO_SYSTEM_BOOT_PARTITION 0x00000100 // ntddk nthal ntifs
  9330. #define DO_LONG_TERM_REQUESTS 0x00000200 // ntddk nthal ntifs
  9331. #define DO_NEVER_LAST_DEVICE 0x00000400 // ntddk nthal ntifs
  9332. #define DO_SHUTDOWN_REGISTERED 0x00000800 // ntddk nthal ntifs wdm
  9333. #define DO_BUS_ENUMERATED_DEVICE 0x00001000 // ntddk nthal ntifs wdm
  9334. #define DO_POWER_PAGABLE 0x00002000 // ntddk nthal ntifs wdm
  9335. #define DO_POWER_INRUSH 0x00004000 // ntddk nthal ntifs wdm
  9336. #define DO_POWER_NOOP 0x00008000
  9337. #define DO_LOW_PRIORITY_FILESYSTEM 0x00010000 // ntddk nthal ntifs
  9338. #define DO_XIP 0x00020000
  9339. // begin_wdm begin_ntddk begin_nthal begin_ntifs
  9340. //
  9341. // Device Object structure definition
  9342. //
  9343. typedef struct DECLSPEC_ALIGN(MEMORY_ALLOCATION_ALIGNMENT) _DEVICE_OBJECT {
  9344. CSHORT Type;
  9345. USHORT Size;
  9346. LONG ReferenceCount;
  9347. struct _DRIVER_OBJECT *DriverObject;
  9348. struct _DEVICE_OBJECT *NextDevice;
  9349. struct _DEVICE_OBJECT *AttachedDevice;
  9350. struct _IRP *CurrentIrp;
  9351. PIO_TIMER Timer;
  9352. ULONG Flags; // See above: DO_...
  9353. ULONG Characteristics; // See ntioapi: FILE_...
  9354. PVPB Vpb;
  9355. PVOID DeviceExtension;
  9356. DEVICE_TYPE DeviceType;
  9357. CCHAR StackSize;
  9358. union {
  9359. LIST_ENTRY ListEntry;
  9360. WAIT_CONTEXT_BLOCK Wcb;
  9361. } Queue;
  9362. ULONG AlignmentRequirement;
  9363. KDEVICE_QUEUE DeviceQueue;
  9364. KDPC Dpc;
  9365. //
  9366. // The following field is for exclusive use by the filesystem to keep
  9367. // track of the number of Fsp threads currently using the device
  9368. //
  9369. ULONG ActiveThreadCount;
  9370. PSECURITY_DESCRIPTOR SecurityDescriptor;
  9371. KEVENT DeviceLock;
  9372. USHORT SectorSize;
  9373. USHORT Spare1;
  9374. struct _DEVOBJ_EXTENSION *DeviceObjectExtension;
  9375. PVOID Reserved;
  9376. } DEVICE_OBJECT;
  9377. typedef struct _DEVICE_OBJECT *PDEVICE_OBJECT; // ntndis
  9378. struct _DEVICE_OBJECT_POWER_EXTENSION;
  9379. typedef struct _DEVOBJ_EXTENSION {
  9380. CSHORT Type;
  9381. USHORT Size;
  9382. //
  9383. // Public part of the DeviceObjectExtension structure
  9384. //
  9385. PDEVICE_OBJECT DeviceObject; // owning device object
  9386. } DEVOBJ_EXTENSION, *PDEVOBJ_EXTENSION;
  9387. //
  9388. // Define Driver Object (DRVO) flags
  9389. //
  9390. #define DRVO_UNLOAD_INVOKED 0x00000001
  9391. #define DRVO_LEGACY_DRIVER 0x00000002
  9392. #define DRVO_BUILTIN_DRIVER 0x00000004 // Driver objects for Hal, PnP Mgr
  9393. // end_wdm
  9394. #define DRVO_REINIT_REGISTERED 0x00000008
  9395. #define DRVO_INITIALIZED 0x00000010
  9396. #define DRVO_BOOTREINIT_REGISTERED 0x00000020
  9397. #define DRVO_LEGACY_RESOURCES 0x00000040
  9398. // begin_wdm
  9399. typedef struct _DRIVER_EXTENSION {
  9400. //
  9401. // Back pointer to Driver Object
  9402. //
  9403. struct _DRIVER_OBJECT *DriverObject;
  9404. //
  9405. // The AddDevice entry point is called by the Plug & Play manager
  9406. // to inform the driver when a new device instance arrives that this
  9407. // driver must control.
  9408. //
  9409. PDRIVER_ADD_DEVICE AddDevice;
  9410. //
  9411. // The count field is used to count the number of times the driver has
  9412. // had its registered reinitialization routine invoked.
  9413. //
  9414. ULONG Count;
  9415. //
  9416. // The service name field is used by the pnp manager to determine
  9417. // where the driver related info is stored in the registry.
  9418. //
  9419. UNICODE_STRING ServiceKeyName;
  9420. //
  9421. // Note: any new shared fields get added here.
  9422. //
  9423. } DRIVER_EXTENSION, *PDRIVER_EXTENSION;
  9424. typedef struct _DRIVER_OBJECT {
  9425. CSHORT Type;
  9426. CSHORT Size;
  9427. //
  9428. // The following links all of the devices created by a single driver
  9429. // together on a list, and the Flags word provides an extensible flag
  9430. // location for driver objects.
  9431. //
  9432. PDEVICE_OBJECT DeviceObject;
  9433. ULONG Flags;
  9434. //
  9435. // The following section describes where the driver is loaded. The count
  9436. // field is used to count the number of times the driver has had its
  9437. // registered reinitialization routine invoked.
  9438. //
  9439. PVOID DriverStart;
  9440. ULONG DriverSize;
  9441. PVOID DriverSection;
  9442. PDRIVER_EXTENSION DriverExtension;
  9443. //
  9444. // The driver name field is used by the error log thread
  9445. // determine the name of the driver that an I/O request is/was bound.
  9446. //
  9447. UNICODE_STRING DriverName;
  9448. //
  9449. // The following section is for registry support. Thise is a pointer
  9450. // to the path to the hardware information in the registry
  9451. //
  9452. PUNICODE_STRING HardwareDatabase;
  9453. //
  9454. // The following section contains the optional pointer to an array of
  9455. // alternate entry points to a driver for "fast I/O" support. Fast I/O
  9456. // is performed by invoking the driver routine directly with separate
  9457. // parameters, rather than using the standard IRP call mechanism. Note
  9458. // that these functions may only be used for synchronous I/O, and when
  9459. // the file is cached.
  9460. //
  9461. PFAST_IO_DISPATCH FastIoDispatch;
  9462. //
  9463. // The following section describes the entry points to this particular
  9464. // driver. Note that the major function dispatch table must be the last
  9465. // field in the object so that it remains extensible.
  9466. //
  9467. PDRIVER_INITIALIZE DriverInit;
  9468. PDRIVER_STARTIO DriverStartIo;
  9469. PDRIVER_UNLOAD DriverUnload;
  9470. PDRIVER_DISPATCH MajorFunction[IRP_MJ_MAXIMUM_FUNCTION + 1];
  9471. } DRIVER_OBJECT;
  9472. typedef struct _DRIVER_OBJECT *PDRIVER_OBJECT; // ntndis
  9473. //
  9474. // The following structure is pointed to by the SectionObject pointer field
  9475. // of a file object, and is allocated by the various NT file systems.
  9476. //
  9477. typedef struct _SECTION_OBJECT_POINTERS {
  9478. PVOID DataSectionObject;
  9479. PVOID SharedCacheMap;
  9480. PVOID ImageSectionObject;
  9481. } SECTION_OBJECT_POINTERS;
  9482. typedef SECTION_OBJECT_POINTERS *PSECTION_OBJECT_POINTERS;
  9483. //
  9484. // Define the format of a completion message.
  9485. //
  9486. typedef struct _IO_COMPLETION_CONTEXT {
  9487. PVOID Port;
  9488. PVOID Key;
  9489. } IO_COMPLETION_CONTEXT, *PIO_COMPLETION_CONTEXT;
  9490. //
  9491. // Define File Object (FO) flags
  9492. //
  9493. #define FO_FILE_OPEN 0x00000001
  9494. #define FO_SYNCHRONOUS_IO 0x00000002
  9495. #define FO_ALERTABLE_IO 0x00000004
  9496. #define FO_NO_INTERMEDIATE_BUFFERING 0x00000008
  9497. #define FO_WRITE_THROUGH 0x00000010
  9498. #define FO_SEQUENTIAL_ONLY 0x00000020
  9499. #define FO_CACHE_SUPPORTED 0x00000040
  9500. #define FO_NAMED_PIPE 0x00000080
  9501. #define FO_STREAM_FILE 0x00000100
  9502. #define FO_MAILSLOT 0x00000200
  9503. #define FO_GENERATE_AUDIT_ON_CLOSE 0x00000400
  9504. #define FO_DIRECT_DEVICE_OPEN 0x00000800
  9505. #define FO_FILE_MODIFIED 0x00001000
  9506. #define FO_FILE_SIZE_CHANGED 0x00002000
  9507. #define FO_CLEANUP_COMPLETE 0x00004000
  9508. #define FO_TEMPORARY_FILE 0x00008000
  9509. #define FO_DELETE_ON_CLOSE 0x00010000
  9510. #define FO_OPENED_CASE_SENSITIVE 0x00020000
  9511. #define FO_HANDLE_CREATED 0x00040000
  9512. #define FO_FILE_FAST_IO_READ 0x00080000
  9513. #define FO_RANDOM_ACCESS 0x00100000
  9514. #define FO_FILE_OPEN_CANCELLED 0x00200000
  9515. #define FO_VOLUME_OPEN 0x00400000
  9516. #define FO_FILE_OBJECT_HAS_EXTENSION 0x00800000
  9517. #define FO_REMOTE_ORIGIN 0x01000000
  9518. typedef struct _FILE_OBJECT {
  9519. CSHORT Type;
  9520. CSHORT Size;
  9521. PDEVICE_OBJECT DeviceObject;
  9522. PVPB Vpb;
  9523. PVOID FsContext;
  9524. PVOID FsContext2;
  9525. PSECTION_OBJECT_POINTERS SectionObjectPointer;
  9526. PVOID PrivateCacheMap;
  9527. NTSTATUS FinalStatus;
  9528. struct _FILE_OBJECT *RelatedFileObject;
  9529. BOOLEAN LockOperation;
  9530. BOOLEAN DeletePending;
  9531. BOOLEAN ReadAccess;
  9532. BOOLEAN WriteAccess;
  9533. BOOLEAN DeleteAccess;
  9534. BOOLEAN SharedRead;
  9535. BOOLEAN SharedWrite;
  9536. BOOLEAN SharedDelete;
  9537. ULONG Flags;
  9538. UNICODE_STRING FileName;
  9539. LARGE_INTEGER CurrentByteOffset;
  9540. ULONG Waiters;
  9541. ULONG Busy;
  9542. PVOID LastLock;
  9543. KEVENT Lock;
  9544. KEVENT Event;
  9545. PIO_COMPLETION_CONTEXT CompletionContext;
  9546. } FILE_OBJECT;
  9547. typedef struct _FILE_OBJECT *PFILE_OBJECT; // ntndis
  9548. //
  9549. // Define I/O Request Packet (IRP) flags
  9550. //
  9551. #define IRP_NOCACHE 0x00000001
  9552. #define IRP_PAGING_IO 0x00000002
  9553. #define IRP_MOUNT_COMPLETION 0x00000002
  9554. #define IRP_SYNCHRONOUS_API 0x00000004
  9555. #define IRP_ASSOCIATED_IRP 0x00000008
  9556. #define IRP_BUFFERED_IO 0x00000010
  9557. #define IRP_DEALLOCATE_BUFFER 0x00000020
  9558. #define IRP_INPUT_OPERATION 0x00000040
  9559. #define IRP_SYNCHRONOUS_PAGING_IO 0x00000040
  9560. #define IRP_CREATE_OPERATION 0x00000080
  9561. #define IRP_READ_OPERATION 0x00000100
  9562. #define IRP_WRITE_OPERATION 0x00000200
  9563. #define IRP_CLOSE_OPERATION 0x00000400
  9564. // end_wdm
  9565. #define IRP_DEFER_IO_COMPLETION 0x00000800
  9566. #define IRP_OB_QUERY_NAME 0x00001000
  9567. #define IRP_HOLD_DEVICE_QUEUE 0x00002000
  9568. // begin_wdm
  9569. //
  9570. // Define I/O request packet (IRP) alternate flags for allocation control.
  9571. //
  9572. #define IRP_QUOTA_CHARGED 0x01
  9573. #define IRP_ALLOCATED_MUST_SUCCEED 0x02
  9574. #define IRP_ALLOCATED_FIXED_SIZE 0x04
  9575. #define IRP_LOOKASIDE_ALLOCATION 0x08
  9576. //
  9577. // I/O Request Packet (IRP) definition
  9578. //
  9579. typedef struct DECLSPEC_ALIGN(MEMORY_ALLOCATION_ALIGNMENT) _IRP {
  9580. CSHORT Type;
  9581. USHORT Size;
  9582. //
  9583. // Define the common fields used to control the IRP.
  9584. //
  9585. //
  9586. // Define a pointer to the Memory Descriptor List (MDL) for this I/O
  9587. // request. This field is only used if the I/O is "direct I/O".
  9588. //
  9589. PMDL MdlAddress;
  9590. //
  9591. // Flags word - used to remember various flags.
  9592. //
  9593. ULONG Flags;
  9594. //
  9595. // The following union is used for one of three purposes:
  9596. //
  9597. // 1. This IRP is an associated IRP. The field is a pointer to a master
  9598. // IRP.
  9599. //
  9600. // 2. This is the master IRP. The field is the count of the number of
  9601. // IRPs which must complete (associated IRPs) before the master can
  9602. // complete.
  9603. //
  9604. // 3. This operation is being buffered and the field is the address of
  9605. // the system space buffer.
  9606. //
  9607. union {
  9608. struct _IRP *MasterIrp;
  9609. LONG IrpCount;
  9610. PVOID SystemBuffer;
  9611. } AssociatedIrp;
  9612. //
  9613. // Thread list entry - allows queueing the IRP to the thread pending I/O
  9614. // request packet list.
  9615. //
  9616. LIST_ENTRY ThreadListEntry;
  9617. //
  9618. // I/O status - final status of operation.
  9619. //
  9620. IO_STATUS_BLOCK IoStatus;
  9621. //
  9622. // Requestor mode - mode of the original requestor of this operation.
  9623. //
  9624. KPROCESSOR_MODE RequestorMode;
  9625. //
  9626. // Pending returned - TRUE if pending was initially returned as the
  9627. // status for this packet.
  9628. //
  9629. BOOLEAN PendingReturned;
  9630. //
  9631. // Stack state information.
  9632. //
  9633. CHAR StackCount;
  9634. CHAR CurrentLocation;
  9635. //
  9636. // Cancel - packet has been canceled.
  9637. //
  9638. BOOLEAN Cancel;
  9639. //
  9640. // Cancel Irql - Irql at which the cancel spinlock was acquired.
  9641. //
  9642. KIRQL CancelIrql;
  9643. //
  9644. // ApcEnvironment - Used to save the APC environment at the time that the
  9645. // packet was initialized.
  9646. //
  9647. CCHAR ApcEnvironment;
  9648. //
  9649. // Allocation control flags.
  9650. //
  9651. UCHAR AllocationFlags;
  9652. //
  9653. // User parameters.
  9654. //
  9655. PIO_STATUS_BLOCK UserIosb;
  9656. PKEVENT UserEvent;
  9657. union {
  9658. struct {
  9659. PIO_APC_ROUTINE UserApcRoutine;
  9660. PVOID UserApcContext;
  9661. } AsynchronousParameters;
  9662. LARGE_INTEGER AllocationSize;
  9663. } Overlay;
  9664. //
  9665. // CancelRoutine - Used to contain the address of a cancel routine supplied
  9666. // by a device driver when the IRP is in a cancelable state.
  9667. //
  9668. PDRIVER_CANCEL CancelRoutine;
  9669. //
  9670. // Note that the UserBuffer parameter is outside of the stack so that I/O
  9671. // completion can copy data back into the user's address space without
  9672. // having to know exactly which service was being invoked. The length
  9673. // of the copy is stored in the second half of the I/O status block. If
  9674. // the UserBuffer field is NULL, then no copy is performed.
  9675. //
  9676. PVOID UserBuffer;
  9677. //
  9678. // Kernel structures
  9679. //
  9680. // The following section contains kernel structures which the IRP needs
  9681. // in order to place various work information in kernel controller system
  9682. // queues. Because the size and alignment cannot be controlled, they are
  9683. // placed here at the end so they just hang off and do not affect the
  9684. // alignment of other fields in the IRP.
  9685. //
  9686. union {
  9687. struct {
  9688. union {
  9689. //
  9690. // DeviceQueueEntry - The device queue entry field is used to
  9691. // queue the IRP to the device driver device queue.
  9692. //
  9693. KDEVICE_QUEUE_ENTRY DeviceQueueEntry;
  9694. struct {
  9695. //
  9696. // The following are available to the driver to use in
  9697. // whatever manner is desired, while the driver owns the
  9698. // packet.
  9699. //
  9700. PVOID DriverContext[4];
  9701. } ;
  9702. } ;
  9703. //
  9704. // Thread - pointer to caller's Thread Control Block.
  9705. //
  9706. PETHREAD Thread;
  9707. //
  9708. // Auxiliary buffer - pointer to any auxiliary buffer that is
  9709. // required to pass information to a driver that is not contained
  9710. // in a normal buffer.
  9711. //
  9712. PCHAR AuxiliaryBuffer;
  9713. //
  9714. // The following unnamed structure must be exactly identical
  9715. // to the unnamed structure used in the minipacket header used
  9716. // for completion queue entries.
  9717. //
  9718. struct {
  9719. //
  9720. // List entry - used to queue the packet to completion queue, among
  9721. // others.
  9722. //
  9723. LIST_ENTRY ListEntry;
  9724. union {
  9725. //
  9726. // Current stack location - contains a pointer to the current
  9727. // IO_STACK_LOCATION structure in the IRP stack. This field
  9728. // should never be directly accessed by drivers. They should
  9729. // use the standard functions.
  9730. //
  9731. struct _IO_STACK_LOCATION *CurrentStackLocation;
  9732. //
  9733. // Minipacket type.
  9734. //
  9735. ULONG PacketType;
  9736. };
  9737. };
  9738. //
  9739. // Original file object - pointer to the original file object
  9740. // that was used to open the file. This field is owned by the
  9741. // I/O system and should not be used by any other drivers.
  9742. //
  9743. PFILE_OBJECT OriginalFileObject;
  9744. } Overlay;
  9745. //
  9746. // APC - This APC control block is used for the special kernel APC as
  9747. // well as for the caller's APC, if one was specified in the original
  9748. // argument list. If so, then the APC is reused for the normal APC for
  9749. // whatever mode the caller was in and the "special" routine that is
  9750. // invoked before the APC gets control simply deallocates the IRP.
  9751. //
  9752. KAPC Apc;
  9753. //
  9754. // CompletionKey - This is the key that is used to distinguish
  9755. // individual I/O operations initiated on a single file handle.
  9756. //
  9757. PVOID CompletionKey;
  9758. } Tail;
  9759. } IRP, *PIRP;
  9760. //
  9761. // Define completion routine types for use in stack locations in an IRP
  9762. //
  9763. typedef
  9764. NTSTATUS
  9765. (*PIO_COMPLETION_ROUTINE) (
  9766. IN PDEVICE_OBJECT DeviceObject,
  9767. IN PIRP Irp,
  9768. IN PVOID Context
  9769. );
  9770. //
  9771. // Define stack location control flags
  9772. //
  9773. #define SL_PENDING_RETURNED 0x01
  9774. #define SL_INVOKE_ON_CANCEL 0x20
  9775. #define SL_INVOKE_ON_SUCCESS 0x40
  9776. #define SL_INVOKE_ON_ERROR 0x80
  9777. //
  9778. // Define flags for various functions
  9779. //
  9780. //
  9781. // Create / Create Named Pipe
  9782. //
  9783. // The following flags must exactly match those in the IoCreateFile call's
  9784. // options. The case sensitive flag is added in later, by the parse routine,
  9785. // and is not an actual option to open. Rather, it is part of the object
  9786. // manager's attributes structure.
  9787. //
  9788. #define SL_FORCE_ACCESS_CHECK 0x01
  9789. #define SL_OPEN_PAGING_FILE 0x02
  9790. #define SL_OPEN_TARGET_DIRECTORY 0x04
  9791. #define SL_CASE_SENSITIVE 0x80
  9792. //
  9793. // Read / Write
  9794. //
  9795. #define SL_KEY_SPECIFIED 0x01
  9796. #define SL_OVERRIDE_VERIFY_VOLUME 0x02
  9797. #define SL_WRITE_THROUGH 0x04
  9798. #define SL_FT_SEQUENTIAL_WRITE 0x08
  9799. //
  9800. // Device I/O Control
  9801. //
  9802. //
  9803. // Same SL_OVERRIDE_VERIFY_VOLUME as for read/write above.
  9804. //
  9805. #define SL_READ_ACCESS_GRANTED 0x01
  9806. #define SL_WRITE_ACCESS_GRANTED 0x04 // Gap for SL_OVERRIDE_VERIFY_VOLUME
  9807. //
  9808. // Lock
  9809. //
  9810. #define SL_FAIL_IMMEDIATELY 0x01
  9811. #define SL_EXCLUSIVE_LOCK 0x02
  9812. //
  9813. // QueryDirectory / QueryEa / QueryQuota
  9814. //
  9815. #define SL_RESTART_SCAN 0x01
  9816. #define SL_RETURN_SINGLE_ENTRY 0x02
  9817. #define SL_INDEX_SPECIFIED 0x04
  9818. //
  9819. // NotifyDirectory
  9820. //
  9821. #define SL_WATCH_TREE 0x01
  9822. //
  9823. // FileSystemControl
  9824. //
  9825. // minor: mount/verify volume
  9826. //
  9827. #define SL_ALLOW_RAW_MOUNT 0x01
  9828. //
  9829. // Define PNP/POWER types required by IRP_MJ_PNP/IRP_MJ_POWER.
  9830. //
  9831. typedef enum _DEVICE_RELATION_TYPE {
  9832. BusRelations,
  9833. EjectionRelations,
  9834. PowerRelations,
  9835. RemovalRelations,
  9836. TargetDeviceRelation,
  9837. SingleBusRelations
  9838. } DEVICE_RELATION_TYPE, *PDEVICE_RELATION_TYPE;
  9839. typedef struct _DEVICE_RELATIONS {
  9840. ULONG Count;
  9841. PDEVICE_OBJECT Objects[1]; // variable length
  9842. } DEVICE_RELATIONS, *PDEVICE_RELATIONS;
  9843. typedef enum _DEVICE_USAGE_NOTIFICATION_TYPE {
  9844. DeviceUsageTypeUndefined,
  9845. DeviceUsageTypePaging,
  9846. DeviceUsageTypeHibernation,
  9847. DeviceUsageTypeDumpFile
  9848. } DEVICE_USAGE_NOTIFICATION_TYPE;
  9849. // begin_ntminiport
  9850. // workaround overloaded definition (rpc generated headers all define INTERFACE
  9851. // to match the class name).
  9852. #undef INTERFACE
  9853. typedef struct _INTERFACE {
  9854. USHORT Size;
  9855. USHORT Version;
  9856. PVOID Context;
  9857. PINTERFACE_REFERENCE InterfaceReference;
  9858. PINTERFACE_DEREFERENCE InterfaceDereference;
  9859. // interface specific entries go here
  9860. } INTERFACE, *PINTERFACE;
  9861. // end_ntminiport
  9862. typedef struct _DEVICE_CAPABILITIES {
  9863. USHORT Size;
  9864. USHORT Version; // the version documented here is version 1
  9865. ULONG DeviceD1:1;
  9866. ULONG DeviceD2:1;
  9867. ULONG LockSupported:1;
  9868. ULONG EjectSupported:1; // Ejectable in S0
  9869. ULONG Removable:1;
  9870. ULONG DockDevice:1;
  9871. ULONG UniqueID:1;
  9872. ULONG SilentInstall:1;
  9873. ULONG RawDeviceOK:1;
  9874. ULONG SurpriseRemovalOK:1;
  9875. ULONG WakeFromD0:1;
  9876. ULONG WakeFromD1:1;
  9877. ULONG WakeFromD2:1;
  9878. ULONG WakeFromD3:1;
  9879. ULONG HardwareDisabled:1;
  9880. ULONG NonDynamic:1;
  9881. ULONG WarmEjectSupported:1;
  9882. ULONG NoDisplayInUI:1;
  9883. ULONG Reserved:14;
  9884. ULONG Address;
  9885. ULONG UINumber;
  9886. DEVICE_POWER_STATE DeviceState[POWER_SYSTEM_MAXIMUM];
  9887. SYSTEM_POWER_STATE SystemWake;
  9888. DEVICE_POWER_STATE DeviceWake;
  9889. ULONG D1Latency;
  9890. ULONG D2Latency;
  9891. ULONG D3Latency;
  9892. } DEVICE_CAPABILITIES, *PDEVICE_CAPABILITIES;
  9893. typedef struct _POWER_SEQUENCE {
  9894. ULONG SequenceD1;
  9895. ULONG SequenceD2;
  9896. ULONG SequenceD3;
  9897. } POWER_SEQUENCE, *PPOWER_SEQUENCE;
  9898. typedef enum {
  9899. BusQueryDeviceID = 0, // <Enumerator>\<Enumerator-specific device id>
  9900. BusQueryHardwareIDs = 1, // Hardware ids
  9901. BusQueryCompatibleIDs = 2, // compatible device ids
  9902. BusQueryInstanceID = 3, // persistent id for this instance of the device
  9903. BusQueryDeviceSerialNumber = 4 // serial number for this device
  9904. } BUS_QUERY_ID_TYPE, *PBUS_QUERY_ID_TYPE;
  9905. typedef ULONG PNP_DEVICE_STATE, *PPNP_DEVICE_STATE;
  9906. #define PNP_DEVICE_DISABLED 0x00000001
  9907. #define PNP_DEVICE_DONT_DISPLAY_IN_UI 0x00000002
  9908. #define PNP_DEVICE_FAILED 0x00000004
  9909. #define PNP_DEVICE_REMOVED 0x00000008
  9910. #define PNP_DEVICE_RESOURCE_REQUIREMENTS_CHANGED 0x00000010
  9911. #define PNP_DEVICE_NOT_DISABLEABLE 0x00000020
  9912. typedef enum {
  9913. DeviceTextDescription = 0, // DeviceDesc property
  9914. DeviceTextLocationInformation = 1 // DeviceLocation property
  9915. } DEVICE_TEXT_TYPE, *PDEVICE_TEXT_TYPE;
  9916. //
  9917. // Define I/O Request Packet (IRP) stack locations
  9918. //
  9919. #if !defined(_AMD64_) && !defined(_IA64_)
  9920. #include "pshpack4.h"
  9921. #endif
  9922. // begin_ntndis
  9923. #if defined(_WIN64)
  9924. #define POINTER_ALIGNMENT DECLSPEC_ALIGN(8)
  9925. #else
  9926. #define POINTER_ALIGNMENT
  9927. #endif
  9928. // end_ntndis
  9929. typedef struct _IO_STACK_LOCATION {
  9930. UCHAR MajorFunction;
  9931. UCHAR MinorFunction;
  9932. UCHAR Flags;
  9933. UCHAR Control;
  9934. //
  9935. // The following user parameters are based on the service that is being
  9936. // invoked. Drivers and file systems can determine which set to use based
  9937. // on the above major and minor function codes.
  9938. //
  9939. union {
  9940. //
  9941. // System service parameters for: NtCreateFile
  9942. //
  9943. struct {
  9944. PIO_SECURITY_CONTEXT SecurityContext;
  9945. ULONG Options;
  9946. USHORT POINTER_ALIGNMENT FileAttributes;
  9947. USHORT ShareAccess;
  9948. ULONG POINTER_ALIGNMENT EaLength;
  9949. } Create;
  9950. //
  9951. // System service parameters for: NtReadFile
  9952. //
  9953. struct {
  9954. ULONG Length;
  9955. ULONG POINTER_ALIGNMENT Key;
  9956. LARGE_INTEGER ByteOffset;
  9957. } Read;
  9958. //
  9959. // System service parameters for: NtWriteFile
  9960. //
  9961. struct {
  9962. ULONG Length;
  9963. ULONG POINTER_ALIGNMENT Key;
  9964. LARGE_INTEGER ByteOffset;
  9965. } Write;
  9966. // end_ntddk end_wdm end_nthal
  9967. //
  9968. // System service parameters for: NtQueryDirectoryFile
  9969. //
  9970. struct {
  9971. ULONG Length;
  9972. PUNICODE_STRING FileName;
  9973. FILE_INFORMATION_CLASS FileInformationClass;
  9974. ULONG POINTER_ALIGNMENT FileIndex;
  9975. } QueryDirectory;
  9976. //
  9977. // System service parameters for: NtNotifyChangeDirectoryFile
  9978. //
  9979. struct {
  9980. ULONG Length;
  9981. ULONG POINTER_ALIGNMENT CompletionFilter;
  9982. } NotifyDirectory;
  9983. // begin_ntddk begin_wdm begin_nthal
  9984. //
  9985. // System service parameters for: NtQueryInformationFile
  9986. //
  9987. struct {
  9988. ULONG Length;
  9989. FILE_INFORMATION_CLASS POINTER_ALIGNMENT FileInformationClass;
  9990. } QueryFile;
  9991. //
  9992. // System service parameters for: NtSetInformationFile
  9993. //
  9994. struct {
  9995. ULONG Length;
  9996. FILE_INFORMATION_CLASS POINTER_ALIGNMENT FileInformationClass;
  9997. PFILE_OBJECT FileObject;
  9998. union {
  9999. struct {
  10000. BOOLEAN ReplaceIfExists;
  10001. BOOLEAN AdvanceOnly;
  10002. };
  10003. ULONG ClusterCount;
  10004. HANDLE DeleteHandle;
  10005. };
  10006. } SetFile;
  10007. //
  10008. // System service parameters for: NtQueryVolumeInformationFile
  10009. //
  10010. struct {
  10011. ULONG Length;
  10012. FS_INFORMATION_CLASS POINTER_ALIGNMENT FsInformationClass;
  10013. } QueryVolume;
  10014. //
  10015. // System service parameters for: NtFsControlFile
  10016. //
  10017. // Note that the user's output buffer is stored in the UserBuffer field
  10018. // and the user's input buffer is stored in the SystemBuffer field.
  10019. //
  10020. struct {
  10021. ULONG OutputBufferLength;
  10022. ULONG POINTER_ALIGNMENT InputBufferLength;
  10023. ULONG POINTER_ALIGNMENT FsControlCode;
  10024. PVOID Type3InputBuffer;
  10025. } FileSystemControl;
  10026. //
  10027. // System service parameters for: NtLockFile/NtUnlockFile
  10028. //
  10029. struct {
  10030. PLARGE_INTEGER Length;
  10031. ULONG POINTER_ALIGNMENT Key;
  10032. LARGE_INTEGER ByteOffset;
  10033. } LockControl;
  10034. // begin_ntddk begin_wdm begin_nthal
  10035. //
  10036. // System service parameters for: NtFlushBuffersFile
  10037. //
  10038. // No extra user-supplied parameters.
  10039. //
  10040. // end_ntddk end_wdm end_nthal
  10041. //
  10042. // System service parameters for: NtDeviceIoControlFile
  10043. //
  10044. // Note that the user's output buffer is stored in the UserBuffer field
  10045. // and the user's input buffer is stored in the SystemBuffer field.
  10046. //
  10047. struct {
  10048. ULONG OutputBufferLength;
  10049. ULONG POINTER_ALIGNMENT InputBufferLength;
  10050. ULONG POINTER_ALIGNMENT IoControlCode;
  10051. PVOID Type3InputBuffer;
  10052. } DeviceIoControl;
  10053. // end_wdm
  10054. //
  10055. // System service parameters for: NtQuerySecurityObject
  10056. //
  10057. struct {
  10058. SECURITY_INFORMATION SecurityInformation;
  10059. ULONG POINTER_ALIGNMENT Length;
  10060. } QuerySecurity;
  10061. //
  10062. // System service parameters for: NtSetSecurityObject
  10063. //
  10064. struct {
  10065. SECURITY_INFORMATION SecurityInformation;
  10066. PSECURITY_DESCRIPTOR SecurityDescriptor;
  10067. } SetSecurity;
  10068. // begin_wdm
  10069. //
  10070. // Non-system service parameters.
  10071. //
  10072. // Parameters for MountVolume
  10073. //
  10074. struct {
  10075. PVPB Vpb;
  10076. PDEVICE_OBJECT DeviceObject;
  10077. } MountVolume;
  10078. //
  10079. // Parameters for VerifyVolume
  10080. //
  10081. struct {
  10082. PVPB Vpb;
  10083. PDEVICE_OBJECT DeviceObject;
  10084. } VerifyVolume;
  10085. //
  10086. // Parameters for Scsi with internal device contorl.
  10087. //
  10088. struct {
  10089. struct _SCSI_REQUEST_BLOCK *Srb;
  10090. } Scsi;
  10091. //
  10092. // Parameters for IRP_MN_QUERY_DEVICE_RELATIONS
  10093. //
  10094. struct {
  10095. DEVICE_RELATION_TYPE Type;
  10096. } QueryDeviceRelations;
  10097. //
  10098. // Parameters for IRP_MN_QUERY_INTERFACE
  10099. //
  10100. struct {
  10101. CONST GUID *InterfaceType;
  10102. USHORT Size;
  10103. USHORT Version;
  10104. PINTERFACE Interface;
  10105. PVOID InterfaceSpecificData;
  10106. } QueryInterface;
  10107. // end_ntifs
  10108. //
  10109. // Parameters for IRP_MN_QUERY_CAPABILITIES
  10110. //
  10111. struct {
  10112. PDEVICE_CAPABILITIES Capabilities;
  10113. } DeviceCapabilities;
  10114. //
  10115. // Parameters for IRP_MN_FILTER_RESOURCE_REQUIREMENTS
  10116. //
  10117. struct {
  10118. PIO_RESOURCE_REQUIREMENTS_LIST IoResourceRequirementList;
  10119. } FilterResourceRequirements;
  10120. //
  10121. // Parameters for IRP_MN_READ_CONFIG and IRP_MN_WRITE_CONFIG
  10122. //
  10123. struct {
  10124. ULONG WhichSpace;
  10125. PVOID Buffer;
  10126. ULONG Offset;
  10127. ULONG POINTER_ALIGNMENT Length;
  10128. } ReadWriteConfig;
  10129. //
  10130. // Parameters for IRP_MN_SET_LOCK
  10131. //
  10132. struct {
  10133. BOOLEAN Lock;
  10134. } SetLock;
  10135. //
  10136. // Parameters for IRP_MN_QUERY_ID
  10137. //
  10138. struct {
  10139. BUS_QUERY_ID_TYPE IdType;
  10140. } QueryId;
  10141. //
  10142. // Parameters for IRP_MN_QUERY_DEVICE_TEXT
  10143. //
  10144. struct {
  10145. DEVICE_TEXT_TYPE DeviceTextType;
  10146. LCID POINTER_ALIGNMENT LocaleId;
  10147. } QueryDeviceText;
  10148. //
  10149. // Parameters for IRP_MN_DEVICE_USAGE_NOTIFICATION
  10150. //
  10151. struct {
  10152. BOOLEAN InPath;
  10153. BOOLEAN Reserved[3];
  10154. DEVICE_USAGE_NOTIFICATION_TYPE POINTER_ALIGNMENT Type;
  10155. } UsageNotification;
  10156. //
  10157. // Parameters for IRP_MN_WAIT_WAKE
  10158. //
  10159. struct {
  10160. SYSTEM_POWER_STATE PowerState;
  10161. } WaitWake;
  10162. //
  10163. // Parameter for IRP_MN_POWER_SEQUENCE
  10164. //
  10165. struct {
  10166. PPOWER_SEQUENCE PowerSequence;
  10167. } PowerSequence;
  10168. //
  10169. // Parameters for IRP_MN_SET_POWER and IRP_MN_QUERY_POWER
  10170. //
  10171. struct {
  10172. ULONG SystemContext;
  10173. POWER_STATE_TYPE POINTER_ALIGNMENT Type;
  10174. POWER_STATE POINTER_ALIGNMENT State;
  10175. POWER_ACTION POINTER_ALIGNMENT ShutdownType;
  10176. } Power;
  10177. //
  10178. // Parameters for StartDevice
  10179. //
  10180. struct {
  10181. PCM_RESOURCE_LIST AllocatedResources;
  10182. PCM_RESOURCE_LIST AllocatedResourcesTranslated;
  10183. } StartDevice;
  10184. // begin_ntifs
  10185. //
  10186. // Parameters for Cleanup
  10187. //
  10188. // No extra parameters supplied
  10189. //
  10190. //
  10191. // WMI Irps
  10192. //
  10193. struct {
  10194. ULONG_PTR ProviderId;
  10195. PVOID DataPath;
  10196. ULONG BufferSize;
  10197. PVOID Buffer;
  10198. } WMI;
  10199. //
  10200. // Others - driver-specific
  10201. //
  10202. struct {
  10203. PVOID Argument1;
  10204. PVOID Argument2;
  10205. PVOID Argument3;
  10206. PVOID Argument4;
  10207. } Others;
  10208. } Parameters;
  10209. //
  10210. // Save a pointer to this device driver's device object for this request
  10211. // so it can be passed to the completion routine if needed.
  10212. //
  10213. PDEVICE_OBJECT DeviceObject;
  10214. //
  10215. // The following location contains a pointer to the file object for this
  10216. //
  10217. PFILE_OBJECT FileObject;
  10218. //
  10219. // The following routine is invoked depending on the flags in the above
  10220. // flags field.
  10221. //
  10222. PIO_COMPLETION_ROUTINE CompletionRoutine;
  10223. //
  10224. // The following is used to store the address of the context parameter
  10225. // that should be passed to the CompletionRoutine.
  10226. //
  10227. PVOID Context;
  10228. } IO_STACK_LOCATION, *PIO_STACK_LOCATION;
  10229. #if !defined(_AMD64_) && !defined(_IA64_)
  10230. #include "poppack.h"
  10231. #endif
  10232. //
  10233. // Define the share access structure used by file systems to determine
  10234. // whether or not another accessor may open the file.
  10235. //
  10236. typedef struct _SHARE_ACCESS {
  10237. ULONG OpenCount;
  10238. ULONG Readers;
  10239. ULONG Writers;
  10240. ULONG Deleters;
  10241. ULONG SharedRead;
  10242. ULONG SharedWrite;
  10243. ULONG SharedDelete;
  10244. } SHARE_ACCESS, *PSHARE_ACCESS;
  10245. // end_wdm
  10246. //
  10247. // The following structure is used by drivers that are initializing to
  10248. // determine the number of devices of a particular type that have already
  10249. // been initialized. It is also used to track whether or not the AtDisk
  10250. // address range has already been claimed. Finally, it is used by the
  10251. // NtQuerySystemInformation system service to return device type counts.
  10252. //
  10253. typedef struct _CONFIGURATION_INFORMATION {
  10254. //
  10255. // This field indicates the total number of disks in the system. This
  10256. // number should be used by the driver to determine the name of new
  10257. // disks. This field should be updated by the driver as it finds new
  10258. // disks.
  10259. //
  10260. ULONG DiskCount; // Count of hard disks thus far
  10261. ULONG FloppyCount; // Count of floppy disks thus far
  10262. ULONG CdRomCount; // Count of CD-ROM drives thus far
  10263. ULONG TapeCount; // Count of tape drives thus far
  10264. ULONG ScsiPortCount; // Count of SCSI port adapters thus far
  10265. ULONG SerialCount; // Count of serial devices thus far
  10266. ULONG ParallelCount; // Count of parallel devices thus far
  10267. //
  10268. // These next two fields indicate ownership of one of the two IO address
  10269. // spaces that are used by WD1003-compatable disk controllers.
  10270. //
  10271. BOOLEAN AtDiskPrimaryAddressClaimed; // 0x1F0 - 0x1FF
  10272. BOOLEAN AtDiskSecondaryAddressClaimed; // 0x170 - 0x17F
  10273. //
  10274. // Indicates the structure version, as anything value belong this will have been added.
  10275. // Use the structure size as the version.
  10276. //
  10277. ULONG Version;
  10278. //
  10279. // Indicates the total number of medium changer devices in the system.
  10280. // This field will be updated by the drivers as it determines that
  10281. // new devices have been found and will be supported.
  10282. //
  10283. ULONG MediumChangerCount;
  10284. } CONFIGURATION_INFORMATION, *PCONFIGURATION_INFORMATION;
  10285. //
  10286. // Public I/O routine definitions
  10287. //
  10288. NTKERNELAPI
  10289. VOID
  10290. IoAcquireCancelSpinLock(
  10291. OUT PKIRQL Irql
  10292. );
  10293. DECLSPEC_DEPRECATED_DDK // Use AllocateAdapterChannel
  10294. NTKERNELAPI
  10295. NTSTATUS
  10296. IoAllocateAdapterChannel(
  10297. IN PADAPTER_OBJECT AdapterObject,
  10298. IN PDEVICE_OBJECT DeviceObject,
  10299. IN ULONG NumberOfMapRegisters,
  10300. IN PDRIVER_CONTROL ExecutionRoutine,
  10301. IN PVOID Context
  10302. );
  10303. NTKERNELAPI
  10304. VOID
  10305. IoAllocateController(
  10306. IN PCONTROLLER_OBJECT ControllerObject,
  10307. IN PDEVICE_OBJECT DeviceObject,
  10308. IN PDRIVER_CONTROL ExecutionRoutine,
  10309. IN PVOID Context
  10310. );
  10311. // begin_wdm
  10312. NTKERNELAPI
  10313. NTSTATUS
  10314. IoAllocateDriverObjectExtension(
  10315. IN PDRIVER_OBJECT DriverObject,
  10316. IN PVOID ClientIdentificationAddress,
  10317. IN ULONG DriverObjectExtensionSize,
  10318. OUT PVOID *DriverObjectExtension
  10319. );
  10320. // begin_ntifs
  10321. NTKERNELAPI
  10322. PVOID
  10323. IoAllocateErrorLogEntry(
  10324. IN PVOID IoObject,
  10325. IN UCHAR EntrySize
  10326. );
  10327. NTKERNELAPI
  10328. PIRP
  10329. IoAllocateIrp(
  10330. IN CCHAR StackSize,
  10331. IN BOOLEAN ChargeQuota
  10332. );
  10333. NTKERNELAPI
  10334. PMDL
  10335. IoAllocateMdl(
  10336. IN PVOID VirtualAddress,
  10337. IN ULONG Length,
  10338. IN BOOLEAN SecondaryBuffer,
  10339. IN BOOLEAN ChargeQuota,
  10340. IN OUT PIRP Irp OPTIONAL
  10341. );
  10342. // end_wdm end_ntifs
  10343. //++
  10344. //
  10345. // VOID
  10346. // IoAssignArcName(
  10347. // IN PUNICODE_STRING ArcName,
  10348. // IN PUNICODE_STRING DeviceName
  10349. // )
  10350. //
  10351. // Routine Description:
  10352. //
  10353. // This routine is invoked by drivers of bootable media to create a symbolic
  10354. // link between the ARC name of their device and its NT name. This allows
  10355. // the system to determine which device in the system was actually booted
  10356. // from since the ARC firmware only deals in ARC names, and NT only deals
  10357. // in NT names.
  10358. //
  10359. // Arguments:
  10360. //
  10361. // ArcName - Supplies the Unicode string representing the ARC name.
  10362. //
  10363. // DeviceName - Supplies the name to which the ARCname refers.
  10364. //
  10365. // Return Value:
  10366. //
  10367. // None.
  10368. //
  10369. //--
  10370. #define IoAssignArcName( ArcName, DeviceName ) ( \
  10371. IoCreateSymbolicLink( (ArcName), (DeviceName) ) )
  10372. DECLSPEC_DEPRECATED_DDK // Use Pnp or IoReprtDetectedDevice
  10373. NTKERNELAPI
  10374. NTSTATUS
  10375. IoAssignResources (
  10376. IN PUNICODE_STRING RegistryPath,
  10377. IN PUNICODE_STRING DriverClassName OPTIONAL,
  10378. IN PDRIVER_OBJECT DriverObject,
  10379. IN PDEVICE_OBJECT DeviceObject OPTIONAL,
  10380. IN PIO_RESOURCE_REQUIREMENTS_LIST RequestedResources,
  10381. IN OUT PCM_RESOURCE_LIST *AllocatedResources
  10382. );
  10383. typedef enum _IO_PAGING_PRIORITY {
  10384. IoPagingPriorityInvalid, // Returned if a non-paging IO IRP is passed.
  10385. IoPagingPriorityNormal, // For regular paging IO
  10386. IoPagingPriorityHigh, // For high priority paging IO
  10387. IoPagingPriorityReserved1, // Reserved for future use.
  10388. IoPagingPriorityReserved2 // Reserved for future use.
  10389. } IO_PAGING_PRIORITY;
  10390. NTKERNELAPI
  10391. NTSTATUS
  10392. IoAttachDevice(
  10393. IN PDEVICE_OBJECT SourceDevice,
  10394. IN PUNICODE_STRING TargetDevice,
  10395. OUT PDEVICE_OBJECT *AttachedDevice
  10396. );
  10397. // end_wdm
  10398. DECLSPEC_DEPRECATED_DDK // Use IoAttachDeviceToDeviceStack
  10399. NTKERNELAPI
  10400. NTSTATUS
  10401. IoAttachDeviceByPointer(
  10402. IN PDEVICE_OBJECT SourceDevice,
  10403. IN PDEVICE_OBJECT TargetDevice
  10404. );
  10405. // begin_wdm
  10406. NTKERNELAPI
  10407. PDEVICE_OBJECT
  10408. IoAttachDeviceToDeviceStack(
  10409. IN PDEVICE_OBJECT SourceDevice,
  10410. IN PDEVICE_OBJECT TargetDevice
  10411. );
  10412. NTKERNELAPI
  10413. PIRP
  10414. IoBuildAsynchronousFsdRequest(
  10415. IN ULONG MajorFunction,
  10416. IN PDEVICE_OBJECT DeviceObject,
  10417. IN OUT PVOID Buffer OPTIONAL,
  10418. IN ULONG Length OPTIONAL,
  10419. IN PLARGE_INTEGER StartingOffset OPTIONAL,
  10420. IN PIO_STATUS_BLOCK IoStatusBlock OPTIONAL
  10421. );
  10422. NTKERNELAPI
  10423. PIRP
  10424. IoBuildDeviceIoControlRequest(
  10425. IN ULONG IoControlCode,
  10426. IN PDEVICE_OBJECT DeviceObject,
  10427. IN PVOID InputBuffer OPTIONAL,
  10428. IN ULONG InputBufferLength,
  10429. OUT PVOID OutputBuffer OPTIONAL,
  10430. IN ULONG OutputBufferLength,
  10431. IN BOOLEAN InternalDeviceIoControl,
  10432. IN PKEVENT Event,
  10433. OUT PIO_STATUS_BLOCK IoStatusBlock
  10434. );
  10435. NTKERNELAPI
  10436. VOID
  10437. IoBuildPartialMdl(
  10438. IN PMDL SourceMdl,
  10439. IN OUT PMDL TargetMdl,
  10440. IN PVOID VirtualAddress,
  10441. IN ULONG Length
  10442. );
  10443. typedef struct _BOOTDISK_INFORMATION {
  10444. LONGLONG BootPartitionOffset;
  10445. LONGLONG SystemPartitionOffset;
  10446. ULONG BootDeviceSignature;
  10447. ULONG SystemDeviceSignature;
  10448. } BOOTDISK_INFORMATION, *PBOOTDISK_INFORMATION;
  10449. //
  10450. // This structure should follow the previous structure field for field.
  10451. //
  10452. typedef struct _BOOTDISK_INFORMATION_EX {
  10453. LONGLONG BootPartitionOffset;
  10454. LONGLONG SystemPartitionOffset;
  10455. ULONG BootDeviceSignature;
  10456. ULONG SystemDeviceSignature;
  10457. GUID BootDeviceGuid;
  10458. GUID SystemDeviceGuid;
  10459. BOOLEAN BootDeviceIsGpt;
  10460. BOOLEAN SystemDeviceIsGpt;
  10461. } BOOTDISK_INFORMATION_EX, *PBOOTDISK_INFORMATION_EX;
  10462. NTKERNELAPI
  10463. NTSTATUS
  10464. IoGetBootDiskInformation(
  10465. IN OUT PBOOTDISK_INFORMATION BootDiskInformation,
  10466. IN ULONG Size
  10467. );
  10468. NTKERNELAPI
  10469. PIRP
  10470. IoBuildSynchronousFsdRequest(
  10471. IN ULONG MajorFunction,
  10472. IN PDEVICE_OBJECT DeviceObject,
  10473. IN OUT PVOID Buffer OPTIONAL,
  10474. IN ULONG Length OPTIONAL,
  10475. IN PLARGE_INTEGER StartingOffset OPTIONAL,
  10476. IN PKEVENT Event,
  10477. OUT PIO_STATUS_BLOCK IoStatusBlock
  10478. );
  10479. NTKERNELAPI
  10480. NTSTATUS
  10481. FASTCALL
  10482. IofCallDriver(
  10483. IN PDEVICE_OBJECT DeviceObject,
  10484. IN OUT PIRP Irp
  10485. );
  10486. #define IoCallDriver(a,b) \
  10487. IofCallDriver(a,b)
  10488. NTKERNELAPI
  10489. BOOLEAN
  10490. IoCancelIrp(
  10491. IN PIRP Irp
  10492. );
  10493. NTKERNELAPI
  10494. NTSTATUS
  10495. IoCheckShareAccess(
  10496. IN ACCESS_MASK DesiredAccess,
  10497. IN ULONG DesiredShareAccess,
  10498. IN OUT PFILE_OBJECT FileObject,
  10499. IN OUT PSHARE_ACCESS ShareAccess,
  10500. IN BOOLEAN Update
  10501. );
  10502. //
  10503. // This value should be returned from completion routines to continue
  10504. // completing the IRP upwards. Otherwise, STATUS_MORE_PROCESSING_REQUIRED
  10505. // should be returned.
  10506. //
  10507. #define STATUS_CONTINUE_COMPLETION STATUS_SUCCESS
  10508. //
  10509. // Completion routines can also use this enumeration in place of status codes.
  10510. //
  10511. typedef enum _IO_COMPLETION_ROUTINE_RESULT {
  10512. ContinueCompletion = STATUS_CONTINUE_COMPLETION,
  10513. StopCompletion = STATUS_MORE_PROCESSING_REQUIRED
  10514. } IO_COMPLETION_ROUTINE_RESULT, *PIO_COMPLETION_ROUTINE_RESULT;
  10515. NTKERNELAPI
  10516. VOID
  10517. FASTCALL
  10518. IofCompleteRequest(
  10519. IN PIRP Irp,
  10520. IN CCHAR PriorityBoost
  10521. );
  10522. #define IoCompleteRequest(a,b) \
  10523. IofCompleteRequest(a,b)
  10524. // end_ntifs
  10525. NTKERNELAPI
  10526. NTSTATUS
  10527. IoConnectInterrupt(
  10528. OUT PKINTERRUPT *InterruptObject,
  10529. IN PKSERVICE_ROUTINE ServiceRoutine,
  10530. IN PVOID ServiceContext,
  10531. IN PKSPIN_LOCK SpinLock OPTIONAL,
  10532. IN ULONG Vector,
  10533. IN KIRQL Irql,
  10534. IN KIRQL SynchronizeIrql,
  10535. IN KINTERRUPT_MODE InterruptMode,
  10536. IN BOOLEAN ShareVector,
  10537. IN KAFFINITY ProcessorEnableMask,
  10538. IN BOOLEAN FloatingSave
  10539. );
  10540. // end_wdm
  10541. NTKERNELAPI
  10542. PCONTROLLER_OBJECT
  10543. IoCreateController(
  10544. IN ULONG Size
  10545. );
  10546. // begin_wdm begin_ntifs
  10547. NTKERNELAPI
  10548. NTSTATUS
  10549. IoCreateDevice(
  10550. IN PDRIVER_OBJECT DriverObject,
  10551. IN ULONG DeviceExtensionSize,
  10552. IN PUNICODE_STRING DeviceName OPTIONAL,
  10553. IN DEVICE_TYPE DeviceType,
  10554. IN ULONG DeviceCharacteristics,
  10555. IN BOOLEAN Exclusive,
  10556. OUT PDEVICE_OBJECT *DeviceObject
  10557. );
  10558. #define WDM_MAJORVERSION 0x01
  10559. #define WDM_MINORVERSION 0x30
  10560. NTKERNELAPI
  10561. BOOLEAN
  10562. IoIsWdmVersionAvailable(
  10563. IN UCHAR MajorVersion,
  10564. IN UCHAR MinorVersion
  10565. );
  10566. // end_nthal
  10567. NTKERNELAPI
  10568. NTSTATUS
  10569. IoCreateFile(
  10570. OUT PHANDLE FileHandle,
  10571. IN ACCESS_MASK DesiredAccess,
  10572. IN POBJECT_ATTRIBUTES ObjectAttributes,
  10573. OUT PIO_STATUS_BLOCK IoStatusBlock,
  10574. IN PLARGE_INTEGER AllocationSize OPTIONAL,
  10575. IN ULONG FileAttributes,
  10576. IN ULONG ShareAccess,
  10577. IN ULONG Disposition,
  10578. IN ULONG CreateOptions,
  10579. IN PVOID EaBuffer OPTIONAL,
  10580. IN ULONG EaLength,
  10581. IN CREATE_FILE_TYPE CreateFileType,
  10582. IN PVOID ExtraCreateParameters OPTIONAL,
  10583. IN ULONG Options
  10584. );
  10585. NTKERNELAPI
  10586. PKEVENT
  10587. IoCreateNotificationEvent(
  10588. IN PUNICODE_STRING EventName,
  10589. OUT PHANDLE EventHandle
  10590. );
  10591. NTKERNELAPI
  10592. NTSTATUS
  10593. IoCreateSymbolicLink(
  10594. IN PUNICODE_STRING SymbolicLinkName,
  10595. IN PUNICODE_STRING DeviceName
  10596. );
  10597. NTKERNELAPI
  10598. PKEVENT
  10599. IoCreateSynchronizationEvent(
  10600. IN PUNICODE_STRING EventName,
  10601. OUT PHANDLE EventHandle
  10602. );
  10603. NTKERNELAPI
  10604. NTSTATUS
  10605. IoCreateUnprotectedSymbolicLink(
  10606. IN PUNICODE_STRING SymbolicLinkName,
  10607. IN PUNICODE_STRING DeviceName
  10608. );
  10609. // end_wdm
  10610. //++
  10611. //
  10612. // VOID
  10613. // IoDeassignArcName(
  10614. // IN PUNICODE_STRING ArcName
  10615. // )
  10616. //
  10617. // Routine Description:
  10618. //
  10619. // This routine is invoked by drivers to deassign an ARC name that they
  10620. // created to a device. This is generally only called if the driver is
  10621. // deleting the device object, which means that the driver is probably
  10622. // unloading.
  10623. //
  10624. // Arguments:
  10625. //
  10626. // ArcName - Supplies the ARC name to be removed.
  10627. //
  10628. // Return Value:
  10629. //
  10630. // None.
  10631. //
  10632. //--
  10633. #define IoDeassignArcName( ArcName ) ( \
  10634. IoDeleteSymbolicLink( (ArcName) ) )
  10635. // end_ntifs
  10636. NTKERNELAPI
  10637. VOID
  10638. IoDeleteController(
  10639. IN PCONTROLLER_OBJECT ControllerObject
  10640. );
  10641. // begin_wdm begin_ntifs
  10642. NTKERNELAPI
  10643. VOID
  10644. IoDeleteDevice(
  10645. IN PDEVICE_OBJECT DeviceObject
  10646. );
  10647. NTKERNELAPI
  10648. NTSTATUS
  10649. IoDeleteSymbolicLink(
  10650. IN PUNICODE_STRING SymbolicLinkName
  10651. );
  10652. NTKERNELAPI
  10653. VOID
  10654. IoDetachDevice(
  10655. IN OUT PDEVICE_OBJECT TargetDevice
  10656. );
  10657. // end_ntifs
  10658. NTKERNELAPI
  10659. VOID
  10660. IoDisconnectInterrupt(
  10661. IN PKINTERRUPT InterruptObject
  10662. );
  10663. // end_ntddk end_wdm end_nthal
  10664. NTKERNELAPI
  10665. VOID
  10666. IoEnqueueIrp(
  10667. IN PIRP Irp
  10668. );
  10669. NTKERNELAPI
  10670. VOID
  10671. IoFreeController(
  10672. IN PCONTROLLER_OBJECT ControllerObject
  10673. );
  10674. // begin_wdm begin_ntifs
  10675. NTKERNELAPI
  10676. VOID
  10677. IoFreeIrp(
  10678. IN PIRP Irp
  10679. );
  10680. NTKERNELAPI
  10681. VOID
  10682. IoFreeMdl(
  10683. IN PMDL Mdl
  10684. );
  10685. NTKERNELAPI
  10686. PDEVICE_OBJECT
  10687. IoGetAttachedDevice(
  10688. IN PDEVICE_OBJECT DeviceObject
  10689. );
  10690. NTKERNELAPI // ntddk wdm nthal
  10691. PDEVICE_OBJECT // ntddk wdm nthal
  10692. IoGetAttachedDeviceReference( // ntddk wdm nthal
  10693. IN PDEVICE_OBJECT DeviceObject // ntddk wdm nthal
  10694. ); // ntddk wdm nthal
  10695. // ntddk wdm nthal
  10696. NTKERNELAPI
  10697. PDEVICE_OBJECT
  10698. IoGetBaseFileSystemDeviceObject(
  10699. IN PFILE_OBJECT FileObject
  10700. );
  10701. NTKERNELAPI // ntddk nthal ntosp
  10702. PCONFIGURATION_INFORMATION // ntddk nthal ntosp
  10703. IoGetConfigurationInformation( VOID ); // ntddk nthal ntosp
  10704. // begin_ntddk begin_wdm begin_nthal
  10705. //++
  10706. //
  10707. // PIO_STACK_LOCATION
  10708. // IoGetCurrentIrpStackLocation(
  10709. // IN PIRP Irp
  10710. // )
  10711. //
  10712. // Routine Description:
  10713. //
  10714. // This routine is invoked to return a pointer to the current stack location
  10715. // in an I/O Request Packet (IRP).
  10716. //
  10717. // Arguments:
  10718. //
  10719. // Irp - Pointer to the I/O Request Packet.
  10720. //
  10721. // Return Value:
  10722. //
  10723. // The function value is a pointer to the current stack location in the
  10724. // packet.
  10725. //
  10726. //--
  10727. #define IoGetCurrentIrpStackLocation( Irp ) ( (Irp)->Tail.Overlay.CurrentStackLocation )
  10728. // end_nthal end_wdm
  10729. NTKERNELAPI
  10730. PDEVICE_OBJECT
  10731. IoGetDeviceToVerify(
  10732. IN PETHREAD Thread
  10733. );
  10734. // begin_wdm
  10735. NTKERNELAPI
  10736. PVOID
  10737. IoGetDriverObjectExtension(
  10738. IN PDRIVER_OBJECT DriverObject,
  10739. IN PVOID ClientIdentificationAddress
  10740. );
  10741. NTKERNELAPI
  10742. PEPROCESS
  10743. IoGetCurrentProcess(
  10744. VOID
  10745. );
  10746. // begin_nthal
  10747. NTKERNELAPI
  10748. NTSTATUS
  10749. IoGetDeviceObjectPointer(
  10750. IN PUNICODE_STRING ObjectName,
  10751. IN ACCESS_MASK DesiredAccess,
  10752. OUT PFILE_OBJECT *FileObject,
  10753. OUT PDEVICE_OBJECT *DeviceObject
  10754. );
  10755. NTKERNELAPI
  10756. struct _DMA_ADAPTER *
  10757. IoGetDmaAdapter(
  10758. IN PDEVICE_OBJECT PhysicalDeviceObject, OPTIONAL // required for PnP drivers
  10759. IN struct _DEVICE_DESCRIPTION *DeviceDescription,
  10760. IN OUT PULONG NumberOfMapRegisters
  10761. );
  10762. NTKERNELAPI
  10763. BOOLEAN
  10764. IoForwardIrpSynchronously(
  10765. IN PDEVICE_OBJECT DeviceObject,
  10766. IN PIRP Irp
  10767. );
  10768. #define IoForwardAndCatchIrp IoForwardIrpSynchronously
  10769. // end_wdm
  10770. NTKERNELAPI
  10771. PGENERIC_MAPPING
  10772. IoGetFileObjectGenericMapping(
  10773. VOID
  10774. );
  10775. // end_nthal
  10776. // begin_wdm
  10777. //++
  10778. //
  10779. // ULONG
  10780. // IoGetFunctionCodeFromCtlCode(
  10781. // IN ULONG ControlCode
  10782. // )
  10783. //
  10784. // Routine Description:
  10785. //
  10786. // This routine extracts the function code from IOCTL and FSCTL function
  10787. // control codes.
  10788. // This routine should only be used by kernel mode code.
  10789. //
  10790. // Arguments:
  10791. //
  10792. // ControlCode - A function control code (IOCTL or FSCTL) from which the
  10793. // function code must be extracted.
  10794. //
  10795. // Return Value:
  10796. //
  10797. // The extracted function code.
  10798. //
  10799. // Note:
  10800. //
  10801. // The CTL_CODE macro, used to create IOCTL and FSCTL function control
  10802. // codes, is defined in ntioapi.h
  10803. //
  10804. //--
  10805. #define IoGetFunctionCodeFromCtlCode( ControlCode ) (\
  10806. ( ControlCode >> 2) & 0x00000FFF )
  10807. // begin_nthal
  10808. NTKERNELAPI
  10809. PVOID
  10810. IoGetInitialStack(
  10811. VOID
  10812. );
  10813. NTKERNELAPI
  10814. VOID
  10815. IoGetStackLimits (
  10816. OUT PULONG_PTR LowLimit,
  10817. OUT PULONG_PTR HighLimit
  10818. );
  10819. //
  10820. // The following function is used to tell the caller how much stack is available
  10821. //
  10822. FORCEINLINE
  10823. ULONG_PTR
  10824. IoGetRemainingStackSize (
  10825. VOID
  10826. )
  10827. {
  10828. ULONG_PTR Top;
  10829. ULONG_PTR Bottom;
  10830. IoGetStackLimits( &Bottom, &Top );
  10831. return((ULONG_PTR)(&Top) - Bottom );
  10832. }
  10833. //++
  10834. //
  10835. // PIO_STACK_LOCATION
  10836. // IoGetNextIrpStackLocation(
  10837. // IN PIRP Irp
  10838. // )
  10839. //
  10840. // Routine Description:
  10841. //
  10842. // This routine is invoked to return a pointer to the next stack location
  10843. // in an I/O Request Packet (IRP).
  10844. //
  10845. // Arguments:
  10846. //
  10847. // Irp - Pointer to the I/O Request Packet.
  10848. //
  10849. // Return Value:
  10850. //
  10851. // The function value is a pointer to the next stack location in the packet.
  10852. //
  10853. //--
  10854. #define IoGetNextIrpStackLocation( Irp ) (\
  10855. (Irp)->Tail.Overlay.CurrentStackLocation - 1 )
  10856. NTKERNELAPI
  10857. PDEVICE_OBJECT
  10858. IoGetRelatedDeviceObject(
  10859. IN PFILE_OBJECT FileObject
  10860. );
  10861. // end_ntddk end_wdm end_nthal
  10862. NTKERNELAPI
  10863. ULONG
  10864. IoGetRequestorProcessId(
  10865. IN PIRP Irp
  10866. );
  10867. NTKERNELAPI
  10868. PEPROCESS
  10869. IoGetRequestorProcess(
  10870. IN PIRP Irp
  10871. );
  10872. //++
  10873. //
  10874. // VOID
  10875. // IoInitializeDpcRequest(
  10876. // IN PDEVICE_OBJECT DeviceObject,
  10877. // IN PIO_DPC_ROUTINE DpcRoutine
  10878. // )
  10879. //
  10880. // end_ntddk end_wdm end_nthal
  10881. // VOID
  10882. // IoInitializeTheadedDpcRequest(
  10883. // IN PDEVICE_OBJECT DeviceObject,
  10884. // IN PIO_DPC_ROUTINE DpcRoutine
  10885. // )
  10886. //
  10887. // begin_ntddk begin_wdm begin_nthal
  10888. // Routine Description:
  10889. //
  10890. // This routine is invoked to initialize the DPC in a device object for a
  10891. // device driver during its initialization routine. The DPC is used later
  10892. // when the driver interrupt service routine requests that a DPC routine
  10893. // be queued for later execution.
  10894. //
  10895. // Arguments:
  10896. //
  10897. // DeviceObject - Pointer to the device object that the request is for.
  10898. //
  10899. // DpcRoutine - Address of the driver's DPC routine to be executed when
  10900. // the DPC is dequeued for processing.
  10901. //
  10902. // Return Value:
  10903. //
  10904. // None.
  10905. //
  10906. //--
  10907. #define IoInitializeDpcRequest( DeviceObject, DpcRoutine ) (\
  10908. KeInitializeDpc( &(DeviceObject)->Dpc, \
  10909. (PKDEFERRED_ROUTINE) (DpcRoutine), \
  10910. (DeviceObject) ) )
  10911. // end_ntddk end_wdm end_nthal
  10912. #define IoInitializeThreadedDpcRequest( DeviceObject, DpcRoutine ) (\
  10913. KeInitializeThreadedDpc( &(DeviceObject)->Dpc, \
  10914. (PKDEFERRED_ROUTINE) (DpcRoutine), \
  10915. (DeviceObject) ) )
  10916. // begin_ntddk begin_wdm begin_nthal
  10917. NTKERNELAPI
  10918. VOID
  10919. IoInitializeIrp(
  10920. IN OUT PIRP Irp,
  10921. IN USHORT PacketSize,
  10922. IN CCHAR StackSize
  10923. );
  10924. NTKERNELAPI
  10925. NTSTATUS
  10926. IoInitializeTimer(
  10927. IN PDEVICE_OBJECT DeviceObject,
  10928. IN PIO_TIMER_ROUTINE TimerRoutine,
  10929. IN PVOID Context
  10930. );
  10931. NTKERNELAPI
  10932. VOID
  10933. IoReuseIrp(
  10934. IN OUT PIRP Irp,
  10935. IN NTSTATUS Iostatus
  10936. );
  10937. // end_wdm
  10938. NTKERNELAPI
  10939. VOID
  10940. IoCancelFileOpen(
  10941. IN PDEVICE_OBJECT DeviceObject,
  10942. IN PFILE_OBJECT FileObject
  10943. );
  10944. //++
  10945. //
  10946. // BOOLEAN
  10947. // IoIsErrorUserInduced(
  10948. // IN NTSTATUS Status
  10949. // )
  10950. //
  10951. // Routine Description:
  10952. //
  10953. // This routine is invoked to determine if an error was as a
  10954. // result of user actions. Typically these error are related
  10955. // to removable media and will result in a pop-up.
  10956. //
  10957. // Arguments:
  10958. //
  10959. // Status - The status value to check.
  10960. //
  10961. // Return Value:
  10962. // The function value is TRUE if the user induced the error,
  10963. // otherwise FALSE is returned.
  10964. //
  10965. //--
  10966. #define IoIsErrorUserInduced( Status ) ((BOOLEAN) \
  10967. (((Status) == STATUS_DEVICE_NOT_READY) || \
  10968. ((Status) == STATUS_IO_TIMEOUT) || \
  10969. ((Status) == STATUS_MEDIA_WRITE_PROTECTED) || \
  10970. ((Status) == STATUS_NO_MEDIA_IN_DEVICE) || \
  10971. ((Status) == STATUS_VERIFY_REQUIRED) || \
  10972. ((Status) == STATUS_UNRECOGNIZED_MEDIA) || \
  10973. ((Status) == STATUS_WRONG_VOLUME)))
  10974. NTKERNELAPI
  10975. PIRP
  10976. IoMakeAssociatedIrp(
  10977. IN PIRP Irp,
  10978. IN CCHAR StackSize
  10979. );
  10980. // begin_wdm
  10981. //++
  10982. //
  10983. // VOID
  10984. // IoMarkIrpPending(
  10985. // IN OUT PIRP Irp
  10986. // )
  10987. //
  10988. // Routine Description:
  10989. //
  10990. // This routine marks the specified I/O Request Packet (IRP) to indicate
  10991. // that an initial status of STATUS_PENDING was returned to the caller.
  10992. // This is used so that I/O completion can determine whether or not to
  10993. // fully complete the I/O operation requested by the packet.
  10994. //
  10995. // Arguments:
  10996. //
  10997. // Irp - Pointer to the I/O Request Packet to be marked pending.
  10998. //
  10999. // Return Value:
  11000. //
  11001. // None.
  11002. //
  11003. //--
  11004. #define IoMarkIrpPending( Irp ) ( \
  11005. IoGetCurrentIrpStackLocation( (Irp) )->Control |= SL_PENDING_RETURNED )
  11006. DECLSPEC_DEPRECATED_DDK // Use IoGetDeviceProperty
  11007. NTKERNELAPI
  11008. NTSTATUS
  11009. IoQueryDeviceDescription(
  11010. IN PINTERFACE_TYPE BusType OPTIONAL,
  11011. IN PULONG BusNumber OPTIONAL,
  11012. IN PCONFIGURATION_TYPE ControllerType OPTIONAL,
  11013. IN PULONG ControllerNumber OPTIONAL,
  11014. IN PCONFIGURATION_TYPE PeripheralType OPTIONAL,
  11015. IN PULONG PeripheralNumber OPTIONAL,
  11016. IN PIO_QUERY_DEVICE_ROUTINE CalloutRoutine,
  11017. IN PVOID Context
  11018. );
  11019. NTKERNELAPI
  11020. VOID
  11021. IoQueueThreadIrp(
  11022. IN PIRP Irp
  11023. );
  11024. NTKERNELAPI
  11025. VOID
  11026. IoRaiseHardError(
  11027. IN PIRP Irp,
  11028. IN PVPB Vpb OPTIONAL,
  11029. IN PDEVICE_OBJECT RealDeviceObject
  11030. );
  11031. NTKERNELAPI
  11032. BOOLEAN
  11033. IoRaiseInformationalHardError(
  11034. IN NTSTATUS ErrorStatus,
  11035. IN PUNICODE_STRING String OPTIONAL,
  11036. IN PKTHREAD Thread OPTIONAL
  11037. );
  11038. NTKERNELAPI
  11039. BOOLEAN
  11040. IoSetThreadHardErrorMode(
  11041. IN BOOLEAN EnableHardErrors
  11042. );
  11043. NTKERNELAPI
  11044. VOID
  11045. IoRegisterBootDriverReinitialization(
  11046. IN PDRIVER_OBJECT DriverObject,
  11047. IN PDRIVER_REINITIALIZE DriverReinitializationRoutine,
  11048. IN PVOID Context
  11049. );
  11050. NTKERNELAPI
  11051. VOID
  11052. IoRegisterDriverReinitialization(
  11053. IN PDRIVER_OBJECT DriverObject,
  11054. IN PDRIVER_REINITIALIZE DriverReinitializationRoutine,
  11055. IN PVOID Context
  11056. );
  11057. NTKERNELAPI
  11058. NTSTATUS
  11059. IoRegisterShutdownNotification(
  11060. IN PDEVICE_OBJECT DeviceObject
  11061. );
  11062. NTKERNELAPI
  11063. NTSTATUS
  11064. IoRegisterLastChanceShutdownNotification(
  11065. IN PDEVICE_OBJECT DeviceObject
  11066. );
  11067. // begin_wdm
  11068. NTKERNELAPI
  11069. VOID
  11070. IoReleaseCancelSpinLock(
  11071. IN KIRQL Irql
  11072. );
  11073. NTKERNELAPI
  11074. VOID
  11075. IoRemoveShareAccess(
  11076. IN PFILE_OBJECT FileObject,
  11077. IN OUT PSHARE_ACCESS ShareAccess
  11078. );
  11079. DECLSPEC_DEPRECATED_DDK // Use IoReportResourceForDetection
  11080. NTKERNELAPI
  11081. NTSTATUS
  11082. IoReportResourceUsage(
  11083. IN PUNICODE_STRING DriverClassName OPTIONAL,
  11084. IN PDRIVER_OBJECT DriverObject,
  11085. IN PCM_RESOURCE_LIST DriverList OPTIONAL,
  11086. IN ULONG DriverListSize OPTIONAL,
  11087. IN PDEVICE_OBJECT DeviceObject,
  11088. IN PCM_RESOURCE_LIST DeviceList OPTIONAL,
  11089. IN ULONG DeviceListSize OPTIONAL,
  11090. IN BOOLEAN OverrideConflict,
  11091. OUT PBOOLEAN ConflictDetected
  11092. );
  11093. // begin_wdm
  11094. //++
  11095. //
  11096. // VOID
  11097. // IoRequestDpc(
  11098. // IN PDEVICE_OBJECT DeviceObject,
  11099. // IN PIRP Irp,
  11100. // IN PVOID Context
  11101. // )
  11102. //
  11103. // Routine Description:
  11104. //
  11105. // This routine is invoked by the device driver's interrupt service routine
  11106. // to request that a DPC routine be queued for later execution at a lower
  11107. // IRQL.
  11108. //
  11109. // Arguments:
  11110. //
  11111. // DeviceObject - Device object for which the request is being processed.
  11112. //
  11113. // Irp - Pointer to the current I/O Request Packet (IRP) for the specified
  11114. // device.
  11115. //
  11116. // Context - Provides a general context parameter to be passed to the
  11117. // DPC routine.
  11118. //
  11119. // Return Value:
  11120. //
  11121. // None.
  11122. //
  11123. //--
  11124. #define IoRequestDpc( DeviceObject, Irp, Context ) ( \
  11125. KeInsertQueueDpc( &(DeviceObject)->Dpc, (Irp), (Context) ) )
  11126. //++
  11127. //
  11128. // PDRIVER_CANCEL
  11129. // IoSetCancelRoutine(
  11130. // IN PIRP Irp,
  11131. // IN PDRIVER_CANCEL CancelRoutine
  11132. // )
  11133. //
  11134. // Routine Description:
  11135. //
  11136. // This routine is invoked to set the address of a cancel routine which
  11137. // is to be invoked when an I/O packet has been canceled.
  11138. //
  11139. // Arguments:
  11140. //
  11141. // Irp - Pointer to the I/O Request Packet itself.
  11142. //
  11143. // CancelRoutine - Address of the cancel routine that is to be invoked
  11144. // if the IRP is cancelled.
  11145. //
  11146. // Return Value:
  11147. //
  11148. // Previous value of CancelRoutine field in the IRP.
  11149. //
  11150. //--
  11151. #define IoSetCancelRoutine( Irp, NewCancelRoutine ) ( \
  11152. (PDRIVER_CANCEL) (ULONG_PTR) InterlockedExchangePointer( (PVOID *) &(Irp)->CancelRoutine, (PVOID) (ULONG_PTR)(NewCancelRoutine) ) )
  11153. //++
  11154. //
  11155. // VOID
  11156. // IoSetCompletionRoutine(
  11157. // IN PIRP Irp,
  11158. // IN PIO_COMPLETION_ROUTINE CompletionRoutine,
  11159. // IN PVOID Context,
  11160. // IN BOOLEAN InvokeOnSuccess,
  11161. // IN BOOLEAN InvokeOnError,
  11162. // IN BOOLEAN InvokeOnCancel
  11163. // )
  11164. //
  11165. // Routine Description:
  11166. //
  11167. // This routine is invoked to set the address of a completion routine which
  11168. // is to be invoked when an I/O packet has been completed by a lower-level
  11169. // driver.
  11170. //
  11171. // Arguments:
  11172. //
  11173. // Irp - Pointer to the I/O Request Packet itself.
  11174. //
  11175. // CompletionRoutine - Address of the completion routine that is to be
  11176. // invoked once the next level driver completes the packet.
  11177. //
  11178. // Context - Specifies a context parameter to be passed to the completion
  11179. // routine.
  11180. //
  11181. // InvokeOnSuccess - Specifies that the completion routine is invoked when the
  11182. // operation is successfully completed.
  11183. //
  11184. // InvokeOnError - Specifies that the completion routine is invoked when the
  11185. // operation completes with an error status.
  11186. //
  11187. // InvokeOnCancel - Specifies that the completion routine is invoked when the
  11188. // operation is being canceled.
  11189. //
  11190. // Return Value:
  11191. //
  11192. // None.
  11193. //
  11194. //--
  11195. #define IoSetCompletionRoutine( Irp, Routine, CompletionContext, Success, Error, Cancel ) { \
  11196. PIO_STACK_LOCATION __irpSp; \
  11197. ASSERT( (Success) | (Error) | (Cancel) ? (Routine) != NULL : TRUE ); \
  11198. __irpSp = IoGetNextIrpStackLocation( (Irp) ); \
  11199. __irpSp->CompletionRoutine = (Routine); \
  11200. __irpSp->Context = (CompletionContext); \
  11201. __irpSp->Control = 0; \
  11202. if ((Success)) { __irpSp->Control = SL_INVOKE_ON_SUCCESS; } \
  11203. if ((Error)) { __irpSp->Control |= SL_INVOKE_ON_ERROR; } \
  11204. if ((Cancel)) { __irpSp->Control |= SL_INVOKE_ON_CANCEL; } }
  11205. NTSTATUS
  11206. IoSetCompletionRoutineEx(
  11207. IN PDEVICE_OBJECT DeviceObject,
  11208. IN PIRP Irp,
  11209. IN PIO_COMPLETION_ROUTINE CompletionRoutine,
  11210. IN PVOID Context,
  11211. IN BOOLEAN InvokeOnSuccess,
  11212. IN BOOLEAN InvokeOnError,
  11213. IN BOOLEAN InvokeOnCancel
  11214. );
  11215. NTKERNELAPI
  11216. VOID
  11217. IoSetHardErrorOrVerifyDevice(
  11218. IN PIRP Irp,
  11219. IN PDEVICE_OBJECT DeviceObject
  11220. );
  11221. // end_ntddk end_nthal
  11222. NTKERNELAPI
  11223. NTSTATUS
  11224. IoSetInformation(
  11225. IN PFILE_OBJECT FileObject,
  11226. IN FILE_INFORMATION_CLASS FileInformationClass,
  11227. IN ULONG Length,
  11228. IN PVOID FileInformation
  11229. );
  11230. //++
  11231. //
  11232. // VOID
  11233. // IoSetNextIrpStackLocation (
  11234. // IN OUT PIRP Irp
  11235. // )
  11236. //
  11237. // Routine Description:
  11238. //
  11239. // This routine is invoked to set the current IRP stack location to
  11240. // the next stack location, i.e. it "pushes" the stack.
  11241. //
  11242. // Arguments:
  11243. //
  11244. // Irp - Pointer to the I/O Request Packet (IRP).
  11245. //
  11246. // Return Value:
  11247. //
  11248. // None.
  11249. //
  11250. //--
  11251. #define IoSetNextIrpStackLocation( Irp ) { \
  11252. (Irp)->CurrentLocation--; \
  11253. (Irp)->Tail.Overlay.CurrentStackLocation--; }
  11254. //++
  11255. //
  11256. // VOID
  11257. // IoCopyCurrentIrpStackLocationToNext(
  11258. // IN PIRP Irp
  11259. // )
  11260. //
  11261. // Routine Description:
  11262. //
  11263. // This routine is invoked to copy the IRP stack arguments and file
  11264. // pointer from the current IrpStackLocation to the next
  11265. // in an I/O Request Packet (IRP).
  11266. //
  11267. // If the caller wants to call IoCallDriver with a completion routine
  11268. // but does not wish to change the arguments otherwise,
  11269. // the caller first calls IoCopyCurrentIrpStackLocationToNext,
  11270. // then IoSetCompletionRoutine, then IoCallDriver.
  11271. //
  11272. // Arguments:
  11273. //
  11274. // Irp - Pointer to the I/O Request Packet.
  11275. //
  11276. // Return Value:
  11277. //
  11278. // None.
  11279. //
  11280. //--
  11281. #define IoCopyCurrentIrpStackLocationToNext( Irp ) { \
  11282. PIO_STACK_LOCATION __irpSp; \
  11283. PIO_STACK_LOCATION __nextIrpSp; \
  11284. __irpSp = IoGetCurrentIrpStackLocation( (Irp) ); \
  11285. __nextIrpSp = IoGetNextIrpStackLocation( (Irp) ); \
  11286. RtlCopyMemory( __nextIrpSp, __irpSp, FIELD_OFFSET(IO_STACK_LOCATION, CompletionRoutine)); \
  11287. __nextIrpSp->Control = 0; }
  11288. //++
  11289. //
  11290. // VOID
  11291. // IoSkipCurrentIrpStackLocation (
  11292. // IN PIRP Irp
  11293. // )
  11294. //
  11295. // Routine Description:
  11296. //
  11297. // This routine is invoked to increment the current stack location of
  11298. // a given IRP.
  11299. //
  11300. // If the caller wishes to call the next driver in a stack, and does not
  11301. // wish to change the arguments, nor does he wish to set a completion
  11302. // routine, then the caller first calls IoSkipCurrentIrpStackLocation
  11303. // and the calls IoCallDriver.
  11304. //
  11305. // Arguments:
  11306. //
  11307. // Irp - Pointer to the I/O Request Packet.
  11308. //
  11309. // Return Value:
  11310. //
  11311. // None
  11312. //
  11313. //--
  11314. #define IoSkipCurrentIrpStackLocation( Irp ) { \
  11315. (Irp)->CurrentLocation++; \
  11316. (Irp)->Tail.Overlay.CurrentStackLocation++; }
  11317. NTKERNELAPI
  11318. VOID
  11319. IoSetShareAccess(
  11320. IN ACCESS_MASK DesiredAccess,
  11321. IN ULONG DesiredShareAccess,
  11322. IN OUT PFILE_OBJECT FileObject,
  11323. OUT PSHARE_ACCESS ShareAccess
  11324. );
  11325. typedef struct _IO_REMOVE_LOCK_TRACKING_BLOCK * PIO_REMOVE_LOCK_TRACKING_BLOCK;
  11326. typedef struct _IO_REMOVE_LOCK_COMMON_BLOCK {
  11327. BOOLEAN Removed;
  11328. BOOLEAN Reserved [3];
  11329. LONG IoCount;
  11330. KEVENT RemoveEvent;
  11331. } IO_REMOVE_LOCK_COMMON_BLOCK;
  11332. typedef struct _IO_REMOVE_LOCK_DBG_BLOCK {
  11333. LONG Signature;
  11334. ULONG HighWatermark;
  11335. LONGLONG MaxLockedTicks;
  11336. LONG AllocateTag;
  11337. LIST_ENTRY LockList;
  11338. KSPIN_LOCK Spin;
  11339. LONG LowMemoryCount;
  11340. ULONG Reserved1[4];
  11341. PVOID Reserved2;
  11342. PIO_REMOVE_LOCK_TRACKING_BLOCK Blocks;
  11343. } IO_REMOVE_LOCK_DBG_BLOCK;
  11344. typedef struct _IO_REMOVE_LOCK {
  11345. IO_REMOVE_LOCK_COMMON_BLOCK Common;
  11346. #if DBG
  11347. IO_REMOVE_LOCK_DBG_BLOCK Dbg;
  11348. #endif
  11349. } IO_REMOVE_LOCK, *PIO_REMOVE_LOCK;
  11350. #define IoInitializeRemoveLock(Lock, Tag, Maxmin, HighWater) \
  11351. IoInitializeRemoveLockEx (Lock, Tag, Maxmin, HighWater, sizeof (IO_REMOVE_LOCK))
  11352. NTSYSAPI
  11353. VOID
  11354. NTAPI
  11355. IoInitializeRemoveLockEx(
  11356. IN PIO_REMOVE_LOCK Lock,
  11357. IN ULONG AllocateTag, // Used only on checked kernels
  11358. IN ULONG MaxLockedMinutes, // Used only on checked kernels
  11359. IN ULONG HighWatermark, // Used only on checked kernels
  11360. IN ULONG RemlockSize // are we checked or free
  11361. );
  11362. //
  11363. // Initialize a remove lock.
  11364. //
  11365. // Note: Allocation for remove locks needs to be within the device extension,
  11366. // so that the memory for this structure stays allocated until such time as the
  11367. // device object itself is deallocated.
  11368. //
  11369. #define IoAcquireRemoveLock(RemoveLock, Tag) \
  11370. IoAcquireRemoveLockEx(RemoveLock, Tag, __FILE__, __LINE__, sizeof (IO_REMOVE_LOCK))
  11371. NTSYSAPI
  11372. NTSTATUS
  11373. NTAPI
  11374. IoAcquireRemoveLockEx (
  11375. IN PIO_REMOVE_LOCK RemoveLock,
  11376. IN OPTIONAL PVOID Tag, // Optional
  11377. IN PCSTR File,
  11378. IN ULONG Line,
  11379. IN ULONG RemlockSize // are we checked or free
  11380. );
  11381. //
  11382. // Routine Description:
  11383. //
  11384. // This routine is called to acquire the remove lock for a device object.
  11385. // While the lock is held, the caller can assume that no pending pnp REMOVE
  11386. // requests will be completed.
  11387. //
  11388. // The lock should be acquired immediately upon entering a dispatch routine.
  11389. // It should also be acquired before creating any new reference to the
  11390. // device object if there's a chance of releasing the reference before the
  11391. // new one is done, in addition to references to the driver code itself,
  11392. // which is removed from memory when the last device object goes.
  11393. //
  11394. // Arguments:
  11395. //
  11396. // RemoveLock - A pointer to an initialized REMOVE_LOCK structure.
  11397. //
  11398. // Tag - Used for tracking lock allocation and release. The same tag
  11399. // specified when acquiring the lock must be used to release the lock.
  11400. // Tags are only checked in checked versions of the driver.
  11401. //
  11402. // File - set to __FILE__ as the location in the code where the lock was taken.
  11403. //
  11404. // Line - set to __LINE__.
  11405. //
  11406. // Return Value:
  11407. //
  11408. // Returns whether or not the remove lock was obtained.
  11409. // If successful the caller should continue with work calling
  11410. // IoReleaseRemoveLock when finished.
  11411. //
  11412. // If not successful the lock was not obtained. The caller should abort the
  11413. // work but not call IoReleaseRemoveLock.
  11414. //
  11415. #define IoReleaseRemoveLock(RemoveLock, Tag) \
  11416. IoReleaseRemoveLockEx(RemoveLock, Tag, sizeof (IO_REMOVE_LOCK))
  11417. NTSYSAPI
  11418. VOID
  11419. NTAPI
  11420. IoReleaseRemoveLockEx(
  11421. IN PIO_REMOVE_LOCK RemoveLock,
  11422. IN PVOID Tag, // Optional
  11423. IN ULONG RemlockSize // are we checked or free
  11424. );
  11425. //
  11426. //
  11427. // Routine Description:
  11428. //
  11429. // This routine is called to release the remove lock on the device object. It
  11430. // must be called when finished using a previously locked reference to the
  11431. // device object. If an Tag was specified when acquiring the lock then the
  11432. // same Tag must be specified when releasing the lock.
  11433. //
  11434. // When the lock count reduces to zero, this routine will signal the waiting
  11435. // event to release the waiting thread deleting the device object protected
  11436. // by this lock.
  11437. //
  11438. // Arguments:
  11439. //
  11440. // DeviceObject - the device object to lock
  11441. //
  11442. // Tag - The TAG (if any) specified when acquiring the lock. This is used
  11443. // for lock tracking purposes
  11444. //
  11445. // Return Value:
  11446. //
  11447. // none
  11448. //
  11449. #define IoReleaseRemoveLockAndWait(RemoveLock, Tag) \
  11450. IoReleaseRemoveLockAndWaitEx(RemoveLock, Tag, sizeof (IO_REMOVE_LOCK))
  11451. NTSYSAPI
  11452. VOID
  11453. NTAPI
  11454. IoReleaseRemoveLockAndWaitEx(
  11455. IN PIO_REMOVE_LOCK RemoveLock,
  11456. IN PVOID Tag,
  11457. IN ULONG RemlockSize // are we checked or free
  11458. );
  11459. //
  11460. //
  11461. // Routine Description:
  11462. //
  11463. // This routine is called when the client would like to delete the
  11464. // remove-locked resource. This routine will block until all the remove
  11465. // locks have released.
  11466. //
  11467. // This routine MUST be called after acquiring the lock.
  11468. //
  11469. // Arguments:
  11470. //
  11471. // RemoveLock
  11472. //
  11473. // Return Value:
  11474. //
  11475. // none
  11476. //
  11477. //++
  11478. //
  11479. // USHORT
  11480. // IoSizeOfIrp(
  11481. // IN CCHAR StackSize
  11482. // )
  11483. //
  11484. // Routine Description:
  11485. //
  11486. // Determines the size of an IRP given the number of stack locations
  11487. // the IRP will have.
  11488. //
  11489. // Arguments:
  11490. //
  11491. // StackSize - Number of stack locations for the IRP.
  11492. //
  11493. // Return Value:
  11494. //
  11495. // Size in bytes of the IRP.
  11496. //
  11497. //--
  11498. #define IoSizeOfIrp( StackSize ) \
  11499. ((USHORT) (sizeof( IRP ) + ((StackSize) * (sizeof( IO_STACK_LOCATION )))))
  11500. // end_ntifs
  11501. NTKERNELAPI
  11502. VOID
  11503. IoStartNextPacket(
  11504. IN PDEVICE_OBJECT DeviceObject,
  11505. IN BOOLEAN Cancelable
  11506. );
  11507. NTKERNELAPI
  11508. VOID
  11509. IoStartNextPacketByKey(
  11510. IN PDEVICE_OBJECT DeviceObject,
  11511. IN BOOLEAN Cancelable,
  11512. IN ULONG Key
  11513. );
  11514. NTKERNELAPI
  11515. VOID
  11516. IoStartPacket(
  11517. IN PDEVICE_OBJECT DeviceObject,
  11518. IN PIRP Irp,
  11519. IN PULONG Key OPTIONAL,
  11520. IN PDRIVER_CANCEL CancelFunction OPTIONAL
  11521. );
  11522. VOID
  11523. IoSetStartIoAttributes(
  11524. IN PDEVICE_OBJECT DeviceObject,
  11525. IN BOOLEAN DeferredStartIo,
  11526. IN BOOLEAN NonCancelable
  11527. );
  11528. // begin_ntifs
  11529. NTKERNELAPI
  11530. VOID
  11531. IoStartTimer(
  11532. IN PDEVICE_OBJECT DeviceObject
  11533. );
  11534. NTKERNELAPI
  11535. VOID
  11536. IoStopTimer(
  11537. IN PDEVICE_OBJECT DeviceObject
  11538. );
  11539. NTKERNELAPI
  11540. PEPROCESS
  11541. IoThreadToProcess(
  11542. IN PETHREAD Thread
  11543. );
  11544. NTKERNELAPI
  11545. VOID
  11546. IoUnregisterShutdownNotification(
  11547. IN PDEVICE_OBJECT DeviceObject
  11548. );
  11549. // end_wdm
  11550. NTKERNELAPI
  11551. VOID
  11552. IoUpdateShareAccess(
  11553. IN PFILE_OBJECT FileObject,
  11554. IN OUT PSHARE_ACCESS ShareAccess
  11555. );
  11556. // end_ntddk end_nthal
  11557. NTKERNELAPI
  11558. NTSTATUS
  11559. IoVerifyVolume(
  11560. IN PDEVICE_OBJECT DeviceObject,
  11561. IN BOOLEAN AllowRawMount
  11562. );
  11563. NTKERNELAPI // ntddk wdm nthal
  11564. VOID // ntddk wdm nthal
  11565. IoWriteErrorLogEntry( // ntddk wdm nthal
  11566. IN PVOID ElEntry // ntddk wdm nthal
  11567. ); // ntddk wdm nthal
  11568. NTKERNELAPI
  11569. NTSTATUS
  11570. IoCreateDriver (
  11571. IN PUNICODE_STRING DriverName, OPTIONAL
  11572. IN PDRIVER_INITIALIZE InitializationFunction
  11573. );
  11574. NTKERNELAPI
  11575. VOID
  11576. IoDeleteDriver (
  11577. IN PDRIVER_OBJECT DriverObject
  11578. );
  11579. typedef struct _IO_WORKITEM *PIO_WORKITEM;
  11580. typedef
  11581. VOID
  11582. (*PIO_WORKITEM_ROUTINE) (
  11583. IN PDEVICE_OBJECT DeviceObject,
  11584. IN PVOID Context
  11585. );
  11586. PIO_WORKITEM
  11587. IoAllocateWorkItem(
  11588. PDEVICE_OBJECT DeviceObject
  11589. );
  11590. VOID
  11591. IoFreeWorkItem(
  11592. PIO_WORKITEM IoWorkItem
  11593. );
  11594. VOID
  11595. IoQueueWorkItem(
  11596. IN PIO_WORKITEM IoWorkItem,
  11597. IN PIO_WORKITEM_ROUTINE WorkerRoutine,
  11598. IN WORK_QUEUE_TYPE QueueType,
  11599. IN PVOID Context
  11600. );
  11601. NTKERNELAPI
  11602. NTSTATUS
  11603. IoWMIRegistrationControl(
  11604. IN PDEVICE_OBJECT DeviceObject,
  11605. IN ULONG Action
  11606. );
  11607. //
  11608. // Action code for IoWMIRegistrationControl api
  11609. //
  11610. #define WMIREG_ACTION_REGISTER 1
  11611. #define WMIREG_ACTION_DEREGISTER 2
  11612. #define WMIREG_ACTION_REREGISTER 3
  11613. #define WMIREG_ACTION_UPDATE_GUIDS 4
  11614. #define WMIREG_ACTION_BLOCK_IRPS 5
  11615. //
  11616. // Code passed in IRP_MN_REGINFO WMI irp
  11617. //
  11618. #define WMIREGISTER 0
  11619. #define WMIUPDATE 1
  11620. NTKERNELAPI
  11621. NTSTATUS
  11622. IoWMIAllocateInstanceIds(
  11623. IN GUID *Guid,
  11624. IN ULONG InstanceCount,
  11625. OUT ULONG *FirstInstanceId
  11626. );
  11627. NTKERNELAPI
  11628. NTSTATUS
  11629. IoWMISuggestInstanceName(
  11630. IN PDEVICE_OBJECT PhysicalDeviceObject OPTIONAL,
  11631. IN PUNICODE_STRING SymbolicLinkName OPTIONAL,
  11632. IN BOOLEAN CombineNames,
  11633. OUT PUNICODE_STRING SuggestedInstanceName
  11634. );
  11635. NTKERNELAPI
  11636. NTSTATUS
  11637. IoWMIWriteEvent(
  11638. IN PVOID WnodeEventItem
  11639. );
  11640. #if defined(_WIN64)
  11641. NTKERNELAPI
  11642. ULONG IoWMIDeviceObjectToProviderId(
  11643. PDEVICE_OBJECT DeviceObject
  11644. );
  11645. #else
  11646. #define IoWMIDeviceObjectToProviderId(DeviceObject) ((ULONG)(DeviceObject))
  11647. #endif
  11648. NTKERNELAPI
  11649. NTSTATUS IoWMIOpenBlock(
  11650. IN GUID *DataBlockGuid,
  11651. IN ULONG DesiredAccess,
  11652. OUT PVOID *DataBlockObject
  11653. );
  11654. NTKERNELAPI
  11655. NTSTATUS IoWMIQueryAllData(
  11656. IN PVOID DataBlockObject,
  11657. IN OUT ULONG *InOutBufferSize,
  11658. OUT /* non paged */ PVOID OutBuffer
  11659. );
  11660. NTKERNELAPI
  11661. NTSTATUS
  11662. IoWMIQueryAllDataMultiple(
  11663. IN PVOID *DataBlockObjectList,
  11664. IN ULONG ObjectCount,
  11665. IN OUT ULONG *InOutBufferSize,
  11666. OUT /* non paged */ PVOID OutBuffer
  11667. );
  11668. NTKERNELAPI
  11669. NTSTATUS
  11670. IoWMIQuerySingleInstance(
  11671. IN PVOID DataBlockObject,
  11672. IN PUNICODE_STRING InstanceName,
  11673. IN OUT ULONG *InOutBufferSize,
  11674. OUT /* non paged */ PVOID OutBuffer
  11675. );
  11676. NTKERNELAPI
  11677. NTSTATUS
  11678. IoWMIQuerySingleInstanceMultiple(
  11679. IN PVOID *DataBlockObjectList,
  11680. IN PUNICODE_STRING InstanceNames,
  11681. IN ULONG ObjectCount,
  11682. IN OUT ULONG *InOutBufferSize,
  11683. OUT /* non paged */ PVOID OutBuffer
  11684. );
  11685. NTKERNELAPI
  11686. NTSTATUS
  11687. IoWMISetSingleInstance(
  11688. IN PVOID DataBlockObject,
  11689. IN PUNICODE_STRING InstanceName,
  11690. IN ULONG Version,
  11691. IN ULONG ValueBufferSize,
  11692. IN PVOID ValueBuffer
  11693. );
  11694. NTKERNELAPI
  11695. NTSTATUS
  11696. IoWMISetSingleItem(
  11697. IN PVOID DataBlockObject,
  11698. IN PUNICODE_STRING InstanceName,
  11699. IN ULONG DataItemId,
  11700. IN ULONG Version,
  11701. IN ULONG ValueBufferSize,
  11702. IN PVOID ValueBuffer
  11703. );
  11704. NTKERNELAPI
  11705. NTSTATUS
  11706. IoWMIExecuteMethod(
  11707. IN PVOID DataBlockObject,
  11708. IN PUNICODE_STRING InstanceName,
  11709. IN ULONG MethodId,
  11710. IN ULONG InBufferSize,
  11711. IN OUT PULONG OutBufferSize,
  11712. IN OUT PUCHAR InOutBuffer
  11713. );
  11714. typedef VOID (*WMI_NOTIFICATION_CALLBACK)(
  11715. PVOID Wnode,
  11716. PVOID Context
  11717. );
  11718. NTKERNELAPI
  11719. NTSTATUS
  11720. IoWMISetNotificationCallback(
  11721. IN PVOID Object,
  11722. IN WMI_NOTIFICATION_CALLBACK Callback,
  11723. IN PVOID Context
  11724. );
  11725. NTKERNELAPI
  11726. NTSTATUS
  11727. IoWMIHandleToInstanceName(
  11728. IN PVOID DataBlockObject,
  11729. IN HANDLE FileHandle,
  11730. OUT PUNICODE_STRING InstanceName
  11731. );
  11732. NTKERNELAPI
  11733. NTSTATUS
  11734. IoWMIDeviceObjectToInstanceName(
  11735. IN PVOID DataBlockObject,
  11736. IN PDEVICE_OBJECT DeviceObject,
  11737. OUT PUNICODE_STRING InstanceName
  11738. );
  11739. NTKERNELAPI
  11740. NTSTATUS
  11741. IoSetIoCompletion (
  11742. IN PVOID IoCompletion,
  11743. IN PVOID KeyContext,
  11744. IN PVOID ApcContext,
  11745. IN NTSTATUS IoStatus,
  11746. IN ULONG_PTR IoStatusInformation,
  11747. IN BOOLEAN Quota
  11748. );
  11749. #if defined(_WIN64)
  11750. BOOLEAN
  11751. IoIs32bitProcess(
  11752. IN PIRP Irp
  11753. );
  11754. #endif
  11755. NTKERNELAPI
  11756. VOID
  11757. FASTCALL
  11758. IoAssignDriveLetters(
  11759. PLOADER_PARAMETER_BLOCK LoaderBlock,
  11760. PSTRING NtDeviceName,
  11761. OUT PUCHAR NtSystemPath,
  11762. OUT PSTRING NtSystemPathString
  11763. );
  11764. DECLSPEC_DEPRECATED_DDK // Use IoWritePartitionTableEx
  11765. NTKERNELAPI
  11766. NTSTATUS
  11767. FASTCALL
  11768. IoWritePartitionTable(
  11769. IN PDEVICE_OBJECT DeviceObject,
  11770. IN ULONG SectorSize,
  11771. IN ULONG SectorsPerTrack,
  11772. IN ULONG NumberOfHeads,
  11773. IN struct _DRIVE_LAYOUT_INFORMATION *PartitionBuffer
  11774. );
  11775. NTKERNELAPI
  11776. NTSTATUS
  11777. IoCreateDisk(
  11778. IN PDEVICE_OBJECT DeviceObject,
  11779. IN struct _CREATE_DISK* Disk
  11780. );
  11781. NTKERNELAPI
  11782. NTSTATUS
  11783. IoReadPartitionTableEx(
  11784. IN PDEVICE_OBJECT DeviceObject,
  11785. IN struct _DRIVE_LAYOUT_INFORMATION_EX** DriveLayout
  11786. );
  11787. NTKERNELAPI
  11788. NTSTATUS
  11789. IoWritePartitionTableEx(
  11790. IN PDEVICE_OBJECT DeviceObject,
  11791. IN struct _DRIVE_LAYOUT_INFORMATION_EX* DriveLayout
  11792. );
  11793. NTKERNELAPI
  11794. NTSTATUS
  11795. IoSetPartitionInformationEx(
  11796. IN PDEVICE_OBJECT DeviceObject,
  11797. IN ULONG PartitionNumber,
  11798. IN struct _SET_PARTITION_INFORMATION_EX* PartitionInfo
  11799. );
  11800. NTKERNELAPI
  11801. NTSTATUS
  11802. IoUpdateDiskGeometry(
  11803. IN PDEVICE_OBJECT DeviceObject,
  11804. IN struct _DISK_GEOMETRY_EX* OldDiskGeometry,
  11805. IN struct _DISK_GEOMETRY_EX* NewDiskGeometry
  11806. );
  11807. NTKERNELAPI
  11808. NTSTATUS
  11809. IoVerifyPartitionTable(
  11810. IN PDEVICE_OBJECT DeviceObject,
  11811. IN BOOLEAN FixErrors
  11812. );
  11813. typedef struct _DISK_SIGNATURE {
  11814. ULONG PartitionStyle;
  11815. union {
  11816. struct {
  11817. ULONG Signature;
  11818. ULONG CheckSum;
  11819. } Mbr;
  11820. struct {
  11821. GUID DiskId;
  11822. } Gpt;
  11823. };
  11824. } DISK_SIGNATURE, *PDISK_SIGNATURE;
  11825. NTKERNELAPI
  11826. NTSTATUS
  11827. IoReadDiskSignature(
  11828. IN PDEVICE_OBJECT DeviceObject,
  11829. IN ULONG BytesPerSector,
  11830. OUT PDISK_SIGNATURE Signature
  11831. );
  11832. NTSTATUS
  11833. IoVolumeDeviceToDosName(
  11834. IN PVOID VolumeDeviceObject,
  11835. OUT PUNICODE_STRING DosName
  11836. );
  11837. NTSTATUS
  11838. IoEnumerateDeviceObjectList(
  11839. IN PDRIVER_OBJECT DriverObject,
  11840. IN PDEVICE_OBJECT *DeviceObjectList,
  11841. IN ULONG DeviceObjectListSize,
  11842. OUT PULONG ActualNumberDeviceObjects
  11843. );
  11844. PDEVICE_OBJECT
  11845. IoGetLowerDeviceObject(
  11846. IN PDEVICE_OBJECT DeviceObject
  11847. );
  11848. PDEVICE_OBJECT
  11849. IoGetDeviceAttachmentBaseRef(
  11850. IN PDEVICE_OBJECT DeviceObject
  11851. );
  11852. NTSTATUS
  11853. IoGetDiskDeviceObject(
  11854. IN PDEVICE_OBJECT FileSystemDeviceObject,
  11855. OUT PDEVICE_OBJECT *DiskDeviceObject
  11856. );
  11857. NTSTATUS
  11858. IoSetSystemPartition(
  11859. PUNICODE_STRING VolumeNameString
  11860. );
  11861. // begin_wdm
  11862. VOID
  11863. IoFreeErrorLogEntry(
  11864. PVOID ElEntry
  11865. );
  11866. // Cancel SAFE API set start
  11867. //
  11868. // The following APIs are to help ease the pain of writing queue packages that
  11869. // handle the cancellation race well. The idea of this set of APIs is to not
  11870. // force a single queue data structure but allow the cancel logic to be hidden
  11871. // from the drivers. A driver implements a queue and as part of its header
  11872. // includes the IO_CSQ structure. In its initialization routine it calls
  11873. // IoInitializeCsq. Then in the dispatch routine when the driver wants to
  11874. // insert an IRP into the queue it calls IoCsqInsertIrp. When the driver wants
  11875. // to remove something from the queue it calls IoCsqRemoveIrp. Note that Insert
  11876. // can fail if the IRP was cancelled in the meantime. Remove can also fail if
  11877. // the IRP was already cancelled.
  11878. //
  11879. // There are typically two modes where drivers queue IRPs. These two modes are
  11880. // covered by the cancel safe queue API set.
  11881. //
  11882. // Mode 1:
  11883. // One is where the driver queues the IRP and at some later
  11884. // point in time dequeues an IRP and issues the IO request.
  11885. // For this mode the driver should use IoCsqInsertIrp and IoCsqRemoveNextIrp.
  11886. // The driver in this case is expected to pass NULL to the irp context
  11887. // parameter in IoInsertIrp.
  11888. //
  11889. // Mode 2:
  11890. // In this the driver queues theIRP, issues the IO request (like issuing a DMA
  11891. // request or writing to a register) and when the IO request completes (either
  11892. // using a DPC or timer) the driver dequeues the IRP and completes it. For this
  11893. // mode the driver should use IoCsqInsertIrp and IoCsqRemoveIrp. In this case
  11894. // the driver should allocate an IRP context and pass it in to IoCsqInsertIrp.
  11895. // The cancel API code creates an association between the IRP and the context
  11896. // and thus ensures that when the time comes to remove the IRP it can ascertain
  11897. // correctly.
  11898. //
  11899. // Note that the cancel API set assumes that the field DriverContext[3] is
  11900. // always available for use and that the driver does not use it.
  11901. //
  11902. //
  11903. // Bookkeeping structure. This should be opaque to drivers.
  11904. // Drivers typically include this as part of their queue headers.
  11905. // Given a CSQ pointer the driver should be able to get its
  11906. // queue header using CONTAINING_RECORD macro
  11907. //
  11908. typedef struct _IO_CSQ IO_CSQ, *PIO_CSQ;
  11909. #define IO_TYPE_CSQ_IRP_CONTEXT 1
  11910. #define IO_TYPE_CSQ 2
  11911. #define IO_TYPE_CSQ_EX 3
  11912. //
  11913. // IRP context structure. This structure is necessary if the driver is using
  11914. // the second mode.
  11915. //
  11916. typedef struct _IO_CSQ_IRP_CONTEXT {
  11917. ULONG Type;
  11918. PIRP Irp;
  11919. PIO_CSQ Csq;
  11920. } IO_CSQ_IRP_CONTEXT, *PIO_CSQ_IRP_CONTEXT;
  11921. //
  11922. // Routines that insert/remove IRP
  11923. //
  11924. typedef VOID
  11925. (*PIO_CSQ_INSERT_IRP)(
  11926. IN struct _IO_CSQ *Csq,
  11927. IN PIRP Irp
  11928. );
  11929. typedef NTSTATUS
  11930. (*PIO_CSQ_INSERT_IRP_EX)(
  11931. IN struct _IO_CSQ *Csq,
  11932. IN PIRP Irp,
  11933. IN OUT PVOID InsertContext
  11934. );
  11935. typedef VOID
  11936. (*PIO_CSQ_REMOVE_IRP)(
  11937. IN PIO_CSQ Csq,
  11938. IN PIRP Irp
  11939. );
  11940. //
  11941. // Retrieves next entry after Irp from the queue.
  11942. // Returns NULL if there are no entries in the queue.
  11943. // If Irp is NUL, returns the entry in the head of the queue.
  11944. // This routine does not remove the IRP from the queue.
  11945. //
  11946. typedef PIRP
  11947. (*PIO_CSQ_PEEK_NEXT_IRP)(
  11948. IN PIO_CSQ Csq,
  11949. IN PIRP Irp,
  11950. IN PVOID PeekContext
  11951. );
  11952. //
  11953. // Lock routine that protects the cancel safe queue.
  11954. //
  11955. typedef VOID
  11956. (*PIO_CSQ_ACQUIRE_LOCK)(
  11957. IN PIO_CSQ Csq,
  11958. OUT PKIRQL Irql
  11959. );
  11960. typedef VOID
  11961. (*PIO_CSQ_RELEASE_LOCK)(
  11962. IN PIO_CSQ Csq,
  11963. IN KIRQL Irql
  11964. );
  11965. //
  11966. // Completes the IRP with STATUS_CANCELLED. IRP is guaranteed to be valid
  11967. // In most cases this routine just calls IoCompleteRequest(Irp, STATUS_CANCELLED);
  11968. //
  11969. typedef VOID
  11970. (*PIO_CSQ_COMPLETE_CANCELED_IRP)(
  11971. IN PIO_CSQ Csq,
  11972. IN PIRP Irp
  11973. );
  11974. //
  11975. // Bookkeeping structure. This should be opaque to drivers.
  11976. // Drivers typically include this as part of their queue headers.
  11977. // Given a CSQ pointer the driver should be able to get its
  11978. // queue header using CONTAINING_RECORD macro
  11979. //
  11980. typedef struct _IO_CSQ {
  11981. ULONG Type;
  11982. PIO_CSQ_INSERT_IRP CsqInsertIrp;
  11983. PIO_CSQ_REMOVE_IRP CsqRemoveIrp;
  11984. PIO_CSQ_PEEK_NEXT_IRP CsqPeekNextIrp;
  11985. PIO_CSQ_ACQUIRE_LOCK CsqAcquireLock;
  11986. PIO_CSQ_RELEASE_LOCK CsqReleaseLock;
  11987. PIO_CSQ_COMPLETE_CANCELED_IRP CsqCompleteCanceledIrp;
  11988. PVOID ReservePointer; // Future expansion
  11989. } IO_CSQ, *PIO_CSQ;
  11990. //
  11991. // Initializes the cancel queue structure.
  11992. //
  11993. NTSTATUS
  11994. IoCsqInitialize(
  11995. IN PIO_CSQ Csq,
  11996. IN PIO_CSQ_INSERT_IRP CsqInsertIrp,
  11997. IN PIO_CSQ_REMOVE_IRP CsqRemoveIrp,
  11998. IN PIO_CSQ_PEEK_NEXT_IRP CsqPeekNextIrp,
  11999. IN PIO_CSQ_ACQUIRE_LOCK CsqAcquireLock,
  12000. IN PIO_CSQ_RELEASE_LOCK CsqReleaseLock,
  12001. IN PIO_CSQ_COMPLETE_CANCELED_IRP CsqCompleteCanceledIrp
  12002. );
  12003. NTSTATUS
  12004. IoCsqInitializeEx(
  12005. IN PIO_CSQ Csq,
  12006. IN PIO_CSQ_INSERT_IRP_EX CsqInsertIrp,
  12007. IN PIO_CSQ_REMOVE_IRP CsqRemoveIrp,
  12008. IN PIO_CSQ_PEEK_NEXT_IRP CsqPeekNextIrp,
  12009. IN PIO_CSQ_ACQUIRE_LOCK CsqAcquireLock,
  12010. IN PIO_CSQ_RELEASE_LOCK CsqReleaseLock,
  12011. IN PIO_CSQ_COMPLETE_CANCELED_IRP CsqCompleteCanceledIrp
  12012. );
  12013. //
  12014. // The caller calls this routine to insert the IRP and return STATUS_PENDING.
  12015. //
  12016. VOID
  12017. IoCsqInsertIrp(
  12018. IN PIO_CSQ Csq,
  12019. IN PIRP Irp,
  12020. IN PIO_CSQ_IRP_CONTEXT Context
  12021. );
  12022. NTSTATUS
  12023. IoCsqInsertIrpEx(
  12024. IN PIO_CSQ Csq,
  12025. IN PIRP Irp,
  12026. IN PIO_CSQ_IRP_CONTEXT Context,
  12027. IN PVOID InsertContext
  12028. );
  12029. //
  12030. // Returns an IRP if one can be found. NULL otherwise.
  12031. //
  12032. PIRP
  12033. IoCsqRemoveNextIrp(
  12034. IN PIO_CSQ Csq,
  12035. IN PVOID PeekContext
  12036. );
  12037. //
  12038. // This routine is called from timeout or DPCs.
  12039. // The context is presumably part of the DPC or timer context.
  12040. // If succesfull returns the IRP associated with context.
  12041. //
  12042. PIRP
  12043. IoCsqRemoveIrp(
  12044. IN PIO_CSQ Csq,
  12045. IN PIO_CSQ_IRP_CONTEXT Context
  12046. );
  12047. // Cancel SAFE API set end
  12048. NTSTATUS
  12049. IoCreateFileSpecifyDeviceObjectHint(
  12050. OUT PHANDLE FileHandle,
  12051. IN ACCESS_MASK DesiredAccess,
  12052. IN POBJECT_ATTRIBUTES ObjectAttributes,
  12053. OUT PIO_STATUS_BLOCK IoStatusBlock,
  12054. IN PLARGE_INTEGER AllocationSize OPTIONAL,
  12055. IN ULONG FileAttributes,
  12056. IN ULONG ShareAccess,
  12057. IN ULONG Disposition,
  12058. IN ULONG CreateOptions,
  12059. IN PVOID EaBuffer OPTIONAL,
  12060. IN ULONG EaLength,
  12061. IN CREATE_FILE_TYPE CreateFileType,
  12062. IN PVOID ExtraCreateParameters OPTIONAL,
  12063. IN ULONG Options,
  12064. IN PVOID DeviceObject
  12065. );
  12066. NTSTATUS
  12067. IoAttachDeviceToDeviceStackSafe(
  12068. IN PDEVICE_OBJECT SourceDevice,
  12069. IN PDEVICE_OBJECT TargetDevice,
  12070. OUT PDEVICE_OBJECT *AttachedToDeviceObject
  12071. );
  12072. NTSTATUS
  12073. IoValidateDeviceIoControlAccess(
  12074. IN PIRP Irp,
  12075. IN ULONG RequiredAccess
  12076. );
  12077. IO_PAGING_PRIORITY
  12078. FASTCALL
  12079. IoGetPagingIoPriority(
  12080. IN PIRP IRP
  12081. );
  12082. //
  12083. // Define PnP Device Property for IoGetDeviceProperty
  12084. //
  12085. typedef enum {
  12086. DevicePropertyDeviceDescription,
  12087. DevicePropertyHardwareID,
  12088. DevicePropertyCompatibleIDs,
  12089. DevicePropertyBootConfiguration,
  12090. DevicePropertyBootConfigurationTranslated,
  12091. DevicePropertyClassName,
  12092. DevicePropertyClassGuid,
  12093. DevicePropertyDriverKeyName,
  12094. DevicePropertyManufacturer,
  12095. DevicePropertyFriendlyName,
  12096. DevicePropertyLocationInformation,
  12097. DevicePropertyPhysicalDeviceObjectName,
  12098. DevicePropertyBusTypeGuid,
  12099. DevicePropertyLegacyBusType,
  12100. DevicePropertyBusNumber,
  12101. DevicePropertyEnumeratorName,
  12102. DevicePropertyAddress,
  12103. DevicePropertyUINumber,
  12104. DevicePropertyInstallState,
  12105. DevicePropertyRemovalPolicy
  12106. } DEVICE_REGISTRY_PROPERTY;
  12107. typedef BOOLEAN (*PTRANSLATE_BUS_ADDRESS)(
  12108. IN PVOID Context,
  12109. IN PHYSICAL_ADDRESS BusAddress,
  12110. IN ULONG Length,
  12111. IN OUT PULONG AddressSpace,
  12112. OUT PPHYSICAL_ADDRESS TranslatedAddress
  12113. );
  12114. typedef struct _DMA_ADAPTER *(*PGET_DMA_ADAPTER)(
  12115. IN PVOID Context,
  12116. IN struct _DEVICE_DESCRIPTION *DeviceDescriptor,
  12117. OUT PULONG NumberOfMapRegisters
  12118. );
  12119. typedef ULONG (*PGET_SET_DEVICE_DATA)(
  12120. IN PVOID Context,
  12121. IN ULONG DataType,
  12122. IN PVOID Buffer,
  12123. IN ULONG Offset,
  12124. IN ULONG Length
  12125. );
  12126. typedef enum _DEVICE_INSTALL_STATE {
  12127. InstallStateInstalled,
  12128. InstallStateNeedsReinstall,
  12129. InstallStateFailedInstall,
  12130. InstallStateFinishInstall
  12131. } DEVICE_INSTALL_STATE, *PDEVICE_INSTALL_STATE;
  12132. //
  12133. // Define structure returned in response to IRP_MN_QUERY_BUS_INFORMATION by a
  12134. // PDO indicating the type of bus the device exists on.
  12135. //
  12136. typedef struct _PNP_BUS_INFORMATION {
  12137. GUID BusTypeGuid;
  12138. INTERFACE_TYPE LegacyBusType;
  12139. ULONG BusNumber;
  12140. } PNP_BUS_INFORMATION, *PPNP_BUS_INFORMATION;
  12141. //
  12142. // Define structure returned in response to IRP_MN_QUERY_LEGACY_BUS_INFORMATION
  12143. // by an FDO indicating the type of bus it is. This is normally the same bus
  12144. // type as the device's children (i.e., as retrieved from the child PDO's via
  12145. // IRP_MN_QUERY_BUS_INFORMATION) except for cases like CardBus, which can
  12146. // support both 16-bit (PCMCIABus) and 32-bit (PCIBus) cards.
  12147. //
  12148. typedef struct _LEGACY_BUS_INFORMATION {
  12149. GUID BusTypeGuid;
  12150. INTERFACE_TYPE LegacyBusType;
  12151. ULONG BusNumber;
  12152. } LEGACY_BUS_INFORMATION, *PLEGACY_BUS_INFORMATION;
  12153. //
  12154. // Defines for IoGetDeviceProperty(DevicePropertyRemovalPolicy).
  12155. //
  12156. typedef enum _DEVICE_REMOVAL_POLICY {
  12157. RemovalPolicyExpectNoRemoval = 1,
  12158. RemovalPolicyExpectOrderlyRemoval = 2,
  12159. RemovalPolicyExpectSurpriseRemoval = 3
  12160. } DEVICE_REMOVAL_POLICY, *PDEVICE_REMOVAL_POLICY;
  12161. typedef struct _BUS_INTERFACE_STANDARD {
  12162. //
  12163. // generic interface header
  12164. //
  12165. USHORT Size;
  12166. USHORT Version;
  12167. PVOID Context;
  12168. PINTERFACE_REFERENCE InterfaceReference;
  12169. PINTERFACE_DEREFERENCE InterfaceDereference;
  12170. //
  12171. // standard bus interfaces
  12172. //
  12173. PTRANSLATE_BUS_ADDRESS TranslateBusAddress;
  12174. PGET_DMA_ADAPTER GetDmaAdapter;
  12175. PGET_SET_DEVICE_DATA SetBusData;
  12176. PGET_SET_DEVICE_DATA GetBusData;
  12177. } BUS_INTERFACE_STANDARD, *PBUS_INTERFACE_STANDARD;
  12178. // end_wdm
  12179. typedef struct _AGP_TARGET_BUS_INTERFACE_STANDARD {
  12180. //
  12181. // generic interface header
  12182. //
  12183. USHORT Size;
  12184. USHORT Version;
  12185. PVOID Context;
  12186. PINTERFACE_REFERENCE InterfaceReference;
  12187. PINTERFACE_DEREFERENCE InterfaceDereference;
  12188. //
  12189. // config munging routines
  12190. //
  12191. PGET_SET_DEVICE_DATA SetBusData;
  12192. PGET_SET_DEVICE_DATA GetBusData;
  12193. UCHAR CapabilityID; // 2 (AGPv2 host) or new 0xE (AGPv3 bridge)
  12194. } AGP_TARGET_BUS_INTERFACE_STANDARD, *PAGP_TARGET_BUS_INTERFACE_STANDARD;
  12195. // begin_wdm
  12196. //
  12197. // The following definitions are used in ACPI QueryInterface
  12198. //
  12199. typedef BOOLEAN (* PGPE_SERVICE_ROUTINE) (
  12200. PVOID,
  12201. PVOID);
  12202. typedef NTSTATUS (* PGPE_CONNECT_VECTOR) (
  12203. PDEVICE_OBJECT,
  12204. ULONG,
  12205. KINTERRUPT_MODE,
  12206. BOOLEAN,
  12207. PGPE_SERVICE_ROUTINE,
  12208. PVOID,
  12209. PVOID);
  12210. typedef NTSTATUS (* PGPE_DISCONNECT_VECTOR) (
  12211. PVOID);
  12212. typedef NTSTATUS (* PGPE_ENABLE_EVENT) (
  12213. PDEVICE_OBJECT,
  12214. PVOID);
  12215. typedef NTSTATUS (* PGPE_DISABLE_EVENT) (
  12216. PDEVICE_OBJECT,
  12217. PVOID);
  12218. typedef NTSTATUS (* PGPE_CLEAR_STATUS) (
  12219. PDEVICE_OBJECT,
  12220. PVOID);
  12221. typedef VOID (* PDEVICE_NOTIFY_CALLBACK) (
  12222. PVOID,
  12223. ULONG);
  12224. typedef NTSTATUS (* PREGISTER_FOR_DEVICE_NOTIFICATIONS) (
  12225. PDEVICE_OBJECT,
  12226. PDEVICE_NOTIFY_CALLBACK,
  12227. PVOID);
  12228. typedef void (* PUNREGISTER_FOR_DEVICE_NOTIFICATIONS) (
  12229. PDEVICE_OBJECT,
  12230. PDEVICE_NOTIFY_CALLBACK);
  12231. typedef struct _ACPI_INTERFACE_STANDARD {
  12232. //
  12233. // Generic interface header
  12234. //
  12235. USHORT Size;
  12236. USHORT Version;
  12237. PVOID Context;
  12238. PINTERFACE_REFERENCE InterfaceReference;
  12239. PINTERFACE_DEREFERENCE InterfaceDereference;
  12240. //
  12241. // ACPI interfaces
  12242. //
  12243. PGPE_CONNECT_VECTOR GpeConnectVector;
  12244. PGPE_DISCONNECT_VECTOR GpeDisconnectVector;
  12245. PGPE_ENABLE_EVENT GpeEnableEvent;
  12246. PGPE_DISABLE_EVENT GpeDisableEvent;
  12247. PGPE_CLEAR_STATUS GpeClearStatus;
  12248. PREGISTER_FOR_DEVICE_NOTIFICATIONS RegisterForDeviceNotifications;
  12249. PUNREGISTER_FOR_DEVICE_NOTIFICATIONS UnregisterForDeviceNotifications;
  12250. } ACPI_INTERFACE_STANDARD, *PACPI_INTERFACE_STANDARD;
  12251. // end_wdm end_ntddk
  12252. typedef enum _ACPI_REG_TYPE {
  12253. PM1a_ENABLE,
  12254. PM1b_ENABLE,
  12255. PM1a_STATUS,
  12256. PM1b_STATUS,
  12257. PM1a_CONTROL,
  12258. PM1b_CONTROL,
  12259. GP_STATUS,
  12260. GP_ENABLE,
  12261. SMI_CMD,
  12262. MaxRegType
  12263. } ACPI_REG_TYPE, *PACPI_REG_TYPE;
  12264. typedef USHORT (*PREAD_ACPI_REGISTER) (
  12265. IN ACPI_REG_TYPE AcpiReg,
  12266. IN ULONG Register);
  12267. typedef VOID (*PWRITE_ACPI_REGISTER) (
  12268. IN ACPI_REG_TYPE AcpiReg,
  12269. IN ULONG Register,
  12270. IN USHORT Value
  12271. );
  12272. typedef struct ACPI_REGS_INTERFACE_STANDARD {
  12273. //
  12274. // generic interface header
  12275. //
  12276. USHORT Size;
  12277. USHORT Version;
  12278. PVOID Context;
  12279. PINTERFACE_REFERENCE InterfaceReference;
  12280. PINTERFACE_DEREFERENCE InterfaceDereference;
  12281. //
  12282. // READ/WRITE_ACPI_REGISTER functions
  12283. //
  12284. PREAD_ACPI_REGISTER ReadAcpiRegister;
  12285. PWRITE_ACPI_REGISTER WriteAcpiRegister;
  12286. } ACPI_REGS_INTERFACE_STANDARD, *PACPI_REGS_INTERFACE_STANDARD;
  12287. typedef NTSTATUS (*PHAL_QUERY_ALLOCATE_PORT_RANGE) (
  12288. IN BOOLEAN IsSparse,
  12289. IN BOOLEAN PrimaryIsMmio,
  12290. IN PVOID VirtBaseAddr OPTIONAL,
  12291. IN PHYSICAL_ADDRESS PhysBaseAddr, // Only valid if PrimaryIsMmio = TRUE
  12292. IN ULONG Length, // Only valid if PrimaryIsMmio = TRUE
  12293. OUT PUSHORT NewRangeId
  12294. );
  12295. typedef VOID (*PHAL_FREE_PORT_RANGE)(
  12296. IN USHORT RangeId
  12297. );
  12298. typedef struct _HAL_PORT_RANGE_INTERFACE {
  12299. //
  12300. // generic interface header
  12301. //
  12302. USHORT Size;
  12303. USHORT Version;
  12304. PVOID Context;
  12305. PINTERFACE_REFERENCE InterfaceReference;
  12306. PINTERFACE_DEREFERENCE InterfaceDereference;
  12307. //
  12308. // QueryAllocateRange/FreeRange functions
  12309. //
  12310. PHAL_QUERY_ALLOCATE_PORT_RANGE QueryAllocateRange;
  12311. PHAL_FREE_PORT_RANGE FreeRange;
  12312. } HAL_PORT_RANGE_INTERFACE, *PHAL_PORT_RANGE_INTERFACE;
  12313. //
  12314. // describe the CMOS HAL interface
  12315. //
  12316. typedef enum _CMOS_DEVICE_TYPE {
  12317. CmosTypeStdPCAT,
  12318. CmosTypeIntelPIIX4,
  12319. CmosTypeDal1501
  12320. } CMOS_DEVICE_TYPE;
  12321. typedef
  12322. ULONG
  12323. (*PREAD_ACPI_CMOS) (
  12324. IN CMOS_DEVICE_TYPE CmosType,
  12325. IN ULONG SourceAddress,
  12326. IN PUCHAR DataBuffer,
  12327. IN ULONG ByteCount
  12328. );
  12329. typedef
  12330. ULONG
  12331. (*PWRITE_ACPI_CMOS) (
  12332. IN CMOS_DEVICE_TYPE CmosType,
  12333. IN ULONG SourceAddress,
  12334. IN PUCHAR DataBuffer,
  12335. IN ULONG ByteCount
  12336. );
  12337. typedef struct _ACPI_CMOS_INTERFACE_STANDARD {
  12338. //
  12339. // generic interface header
  12340. //
  12341. USHORT Size;
  12342. USHORT Version;
  12343. PVOID Context;
  12344. PINTERFACE_REFERENCE InterfaceReference;
  12345. PINTERFACE_DEREFERENCE InterfaceDereference;
  12346. //
  12347. // READ/WRITE_ACPI_CMOS functions
  12348. //
  12349. PREAD_ACPI_CMOS ReadCmos;
  12350. PWRITE_ACPI_CMOS WriteCmos;
  12351. } ACPI_CMOS_INTERFACE_STANDARD, *PACPI_CMOS_INTERFACE_STANDARD;
  12352. //
  12353. // These definitions are used for getting PCI Interrupt Routing interfaces
  12354. //
  12355. typedef struct {
  12356. PVOID LinkNode;
  12357. ULONG StaticVector;
  12358. UCHAR Flags;
  12359. } ROUTING_TOKEN, *PROUTING_TOKEN;
  12360. //
  12361. // Flag indicating that the device supports
  12362. // MSI interrupt routing or that the provided token contains
  12363. // MSI routing information
  12364. //
  12365. #define PCI_MSI_ROUTING 0x1
  12366. #define PCI_STATIC_ROUTING 0x2
  12367. typedef
  12368. NTSTATUS
  12369. (*PGET_INTERRUPT_ROUTING)(
  12370. IN PDEVICE_OBJECT Pdo,
  12371. OUT ULONG *Bus,
  12372. OUT ULONG *PciSlot,
  12373. OUT UCHAR *InterruptLine,
  12374. OUT UCHAR *InterruptPin,
  12375. OUT UCHAR *ClassCode,
  12376. OUT UCHAR *SubClassCode,
  12377. OUT PDEVICE_OBJECT *ParentPdo,
  12378. OUT ROUTING_TOKEN *RoutingToken,
  12379. OUT UCHAR *Flags
  12380. );
  12381. typedef
  12382. NTSTATUS
  12383. (*PSET_INTERRUPT_ROUTING_TOKEN)(
  12384. IN PDEVICE_OBJECT Pdo,
  12385. IN PROUTING_TOKEN RoutingToken
  12386. );
  12387. typedef
  12388. VOID
  12389. (*PUPDATE_INTERRUPT_LINE)(
  12390. IN PDEVICE_OBJECT Pdo,
  12391. IN UCHAR LineRegister
  12392. );
  12393. typedef struct _INT_ROUTE_INTERFACE_STANDARD {
  12394. //
  12395. // generic interface header
  12396. //
  12397. USHORT Size;
  12398. USHORT Version;
  12399. PVOID Context;
  12400. PINTERFACE_REFERENCE InterfaceReference;
  12401. PINTERFACE_DEREFERENCE InterfaceDereference;
  12402. //
  12403. // standard bus interfaces
  12404. //
  12405. PGET_INTERRUPT_ROUTING GetInterruptRouting;
  12406. PSET_INTERRUPT_ROUTING_TOKEN SetInterruptRoutingToken;
  12407. PUPDATE_INTERRUPT_LINE UpdateInterruptLine;
  12408. } INT_ROUTE_INTERFACE_STANDARD, *PINT_ROUTE_INTERFACE_STANDARD;
  12409. // Some well-known interface versions supported by the PCI Bus Driver
  12410. #define PCI_INT_ROUTE_INTRF_STANDARD_VER 1
  12411. NTKERNELAPI
  12412. NTSTATUS
  12413. IoSynchronousInvalidateDeviceRelations(
  12414. PDEVICE_OBJECT DeviceObject,
  12415. DEVICE_RELATION_TYPE Type
  12416. );
  12417. // begin_ntddk begin_nthal begin_ntifs
  12418. NTKERNELAPI
  12419. NTSTATUS
  12420. IoReportDetectedDevice(
  12421. IN PDRIVER_OBJECT DriverObject,
  12422. IN INTERFACE_TYPE LegacyBusType,
  12423. IN ULONG BusNumber,
  12424. IN ULONG SlotNumber,
  12425. IN PCM_RESOURCE_LIST ResourceList,
  12426. IN PIO_RESOURCE_REQUIREMENTS_LIST ResourceRequirements OPTIONAL,
  12427. IN BOOLEAN ResourceAssigned,
  12428. IN OUT PDEVICE_OBJECT *DeviceObject
  12429. );
  12430. // begin_wdm
  12431. NTKERNELAPI
  12432. VOID
  12433. IoInvalidateDeviceRelations(
  12434. IN PDEVICE_OBJECT DeviceObject,
  12435. IN DEVICE_RELATION_TYPE Type
  12436. );
  12437. NTKERNELAPI
  12438. VOID
  12439. IoRequestDeviceEject(
  12440. IN PDEVICE_OBJECT PhysicalDeviceObject
  12441. );
  12442. NTKERNELAPI
  12443. NTSTATUS
  12444. IoGetDeviceProperty(
  12445. IN PDEVICE_OBJECT DeviceObject,
  12446. IN DEVICE_REGISTRY_PROPERTY DeviceProperty,
  12447. IN ULONG BufferLength,
  12448. OUT PVOID PropertyBuffer,
  12449. OUT PULONG ResultLength
  12450. );
  12451. //
  12452. // The following definitions are used in IoOpenDeviceRegistryKey
  12453. //
  12454. #define PLUGPLAY_REGKEY_DEVICE 1
  12455. #define PLUGPLAY_REGKEY_DRIVER 2
  12456. #define PLUGPLAY_REGKEY_CURRENT_HWPROFILE 4
  12457. NTKERNELAPI
  12458. NTSTATUS
  12459. IoOpenDeviceRegistryKey(
  12460. IN PDEVICE_OBJECT DeviceObject,
  12461. IN ULONG DevInstKeyType,
  12462. IN ACCESS_MASK DesiredAccess,
  12463. OUT PHANDLE DevInstRegKey
  12464. );
  12465. NTKERNELAPI
  12466. NTSTATUS
  12467. NTAPI
  12468. IoRegisterDeviceInterface(
  12469. IN PDEVICE_OBJECT PhysicalDeviceObject,
  12470. IN CONST GUID *InterfaceClassGuid,
  12471. IN PUNICODE_STRING ReferenceString, OPTIONAL
  12472. OUT PUNICODE_STRING SymbolicLinkName
  12473. );
  12474. NTKERNELAPI
  12475. NTSTATUS
  12476. IoOpenDeviceInterfaceRegistryKey(
  12477. IN PUNICODE_STRING SymbolicLinkName,
  12478. IN ACCESS_MASK DesiredAccess,
  12479. OUT PHANDLE DeviceInterfaceKey
  12480. );
  12481. NTKERNELAPI
  12482. NTSTATUS
  12483. IoSetDeviceInterfaceState(
  12484. IN PUNICODE_STRING SymbolicLinkName,
  12485. IN BOOLEAN Enable
  12486. );
  12487. NTKERNELAPI
  12488. NTSTATUS
  12489. NTAPI
  12490. IoGetDeviceInterfaces(
  12491. IN CONST GUID *InterfaceClassGuid,
  12492. IN PDEVICE_OBJECT PhysicalDeviceObject OPTIONAL,
  12493. IN ULONG Flags,
  12494. OUT PWSTR *SymbolicLinkList
  12495. );
  12496. #define DEVICE_INTERFACE_INCLUDE_NONACTIVE 0x00000001
  12497. NTKERNELAPI
  12498. NTSTATUS
  12499. NTAPI
  12500. IoGetDeviceInterfaceAlias(
  12501. IN PUNICODE_STRING SymbolicLinkName,
  12502. IN CONST GUID *AliasInterfaceClassGuid,
  12503. OUT PUNICODE_STRING AliasSymbolicLinkName
  12504. );
  12505. //
  12506. // Define PnP notification event categories
  12507. //
  12508. typedef enum _IO_NOTIFICATION_EVENT_CATEGORY {
  12509. EventCategoryReserved,
  12510. EventCategoryHardwareProfileChange,
  12511. EventCategoryDeviceInterfaceChange,
  12512. EventCategoryTargetDeviceChange
  12513. } IO_NOTIFICATION_EVENT_CATEGORY;
  12514. //
  12515. // Define flags that modify the behavior of IoRegisterPlugPlayNotification
  12516. // for the various event categories...
  12517. //
  12518. #define PNPNOTIFY_DEVICE_INTERFACE_INCLUDE_EXISTING_INTERFACES 0x00000001
  12519. typedef
  12520. NTSTATUS
  12521. (*PDRIVER_NOTIFICATION_CALLBACK_ROUTINE) (
  12522. IN PVOID NotificationStructure,
  12523. IN PVOID Context
  12524. );
  12525. NTKERNELAPI
  12526. NTSTATUS
  12527. IoRegisterPlugPlayNotification(
  12528. IN IO_NOTIFICATION_EVENT_CATEGORY EventCategory,
  12529. IN ULONG EventCategoryFlags,
  12530. IN PVOID EventCategoryData OPTIONAL,
  12531. IN PDRIVER_OBJECT DriverObject,
  12532. IN PDRIVER_NOTIFICATION_CALLBACK_ROUTINE CallbackRoutine,
  12533. IN PVOID Context,
  12534. OUT PVOID *NotificationEntry
  12535. );
  12536. NTKERNELAPI
  12537. NTSTATUS
  12538. IoUnregisterPlugPlayNotification(
  12539. IN PVOID NotificationEntry
  12540. );
  12541. NTKERNELAPI
  12542. NTSTATUS
  12543. IoReportTargetDeviceChange(
  12544. IN PDEVICE_OBJECT PhysicalDeviceObject,
  12545. IN PVOID NotificationStructure // always begins with a PLUGPLAY_NOTIFICATION_HEADER
  12546. );
  12547. typedef
  12548. VOID
  12549. (*PDEVICE_CHANGE_COMPLETE_CALLBACK)(
  12550. IN PVOID Context
  12551. );
  12552. NTKERNELAPI
  12553. VOID
  12554. IoInvalidateDeviceState(
  12555. IN PDEVICE_OBJECT PhysicalDeviceObject
  12556. );
  12557. #define IoAdjustPagingPathCount(_count_,_paging_) { \
  12558. if (_paging_) { \
  12559. InterlockedIncrement(_count_); \
  12560. } else { \
  12561. InterlockedDecrement(_count_); \
  12562. } \
  12563. }
  12564. NTKERNELAPI
  12565. NTSTATUS
  12566. IoReportTargetDeviceChangeAsynchronous(
  12567. IN PDEVICE_OBJECT PhysicalDeviceObject,
  12568. IN PVOID NotificationStructure, // always begins with a PLUGPLAY_NOTIFICATION_HEADER
  12569. IN PDEVICE_CHANGE_COMPLETE_CALLBACK Callback, OPTIONAL
  12570. IN PVOID Context OPTIONAL
  12571. );
  12572. NTKERNELAPI
  12573. NTSTATUS
  12574. IoReportResourceForDetection(
  12575. IN PDRIVER_OBJECT DriverObject,
  12576. IN PCM_RESOURCE_LIST DriverList OPTIONAL,
  12577. IN ULONG DriverListSize OPTIONAL,
  12578. IN PDEVICE_OBJECT DeviceObject OPTIONAL,
  12579. IN PCM_RESOURCE_LIST DeviceList OPTIONAL,
  12580. IN ULONG DeviceListSize OPTIONAL,
  12581. OUT PBOOLEAN ConflictDetected
  12582. );
  12583. typedef enum _RESOURCE_TRANSLATION_DIRECTION {
  12584. TranslateChildToParent,
  12585. TranslateParentToChild
  12586. } RESOURCE_TRANSLATION_DIRECTION;
  12587. typedef
  12588. NTSTATUS
  12589. (*PTRANSLATE_RESOURCE_HANDLER)(
  12590. IN PVOID Context,
  12591. IN PCM_PARTIAL_RESOURCE_DESCRIPTOR Source,
  12592. IN RESOURCE_TRANSLATION_DIRECTION Direction,
  12593. IN ULONG AlternativesCount, OPTIONAL
  12594. IN IO_RESOURCE_DESCRIPTOR Alternatives[], OPTIONAL
  12595. IN PDEVICE_OBJECT PhysicalDeviceObject,
  12596. OUT PCM_PARTIAL_RESOURCE_DESCRIPTOR Target
  12597. );
  12598. typedef
  12599. NTSTATUS
  12600. (*PTRANSLATE_RESOURCE_REQUIREMENTS_HANDLER)(
  12601. IN PVOID Context,
  12602. IN PIO_RESOURCE_DESCRIPTOR Source,
  12603. IN PDEVICE_OBJECT PhysicalDeviceObject,
  12604. OUT PULONG TargetCount,
  12605. OUT PIO_RESOURCE_DESCRIPTOR *Target
  12606. );
  12607. //
  12608. // Translator Interface
  12609. //
  12610. typedef struct _TRANSLATOR_INTERFACE {
  12611. USHORT Size;
  12612. USHORT Version;
  12613. PVOID Context;
  12614. PINTERFACE_REFERENCE InterfaceReference;
  12615. PINTERFACE_DEREFERENCE InterfaceDereference;
  12616. PTRANSLATE_RESOURCE_HANDLER TranslateResources;
  12617. PTRANSLATE_RESOURCE_REQUIREMENTS_HANDLER TranslateResourceRequirements;
  12618. } TRANSLATOR_INTERFACE, *PTRANSLATOR_INTERFACE;
  12619. //
  12620. // Header structure for all Plug&Play notification events...
  12621. //
  12622. typedef struct _PLUGPLAY_NOTIFICATION_HEADER {
  12623. USHORT Version; // presently at version 1.
  12624. USHORT Size; // size (in bytes) of header + event-specific data.
  12625. GUID Event;
  12626. //
  12627. // Event-specific stuff starts here.
  12628. //
  12629. } PLUGPLAY_NOTIFICATION_HEADER, *PPLUGPLAY_NOTIFICATION_HEADER;
  12630. //
  12631. // Notification structure for all EventCategoryHardwareProfileChange events...
  12632. //
  12633. typedef struct _HWPROFILE_CHANGE_NOTIFICATION {
  12634. USHORT Version;
  12635. USHORT Size;
  12636. GUID Event;
  12637. //
  12638. // (No event-specific data)
  12639. //
  12640. } HWPROFILE_CHANGE_NOTIFICATION, *PHWPROFILE_CHANGE_NOTIFICATION;
  12641. //
  12642. // Notification structure for all EventCategoryDeviceInterfaceChange events...
  12643. //
  12644. typedef struct _DEVICE_INTERFACE_CHANGE_NOTIFICATION {
  12645. USHORT Version;
  12646. USHORT Size;
  12647. GUID Event;
  12648. //
  12649. // Event-specific data
  12650. //
  12651. GUID InterfaceClassGuid;
  12652. PUNICODE_STRING SymbolicLinkName;
  12653. } DEVICE_INTERFACE_CHANGE_NOTIFICATION, *PDEVICE_INTERFACE_CHANGE_NOTIFICATION;
  12654. //
  12655. // Notification structures for EventCategoryTargetDeviceChange...
  12656. //
  12657. //
  12658. // The following structure is used for TargetDeviceQueryRemove,
  12659. // TargetDeviceRemoveCancelled, and TargetDeviceRemoveComplete:
  12660. //
  12661. typedef struct _TARGET_DEVICE_REMOVAL_NOTIFICATION {
  12662. USHORT Version;
  12663. USHORT Size;
  12664. GUID Event;
  12665. //
  12666. // Event-specific data
  12667. //
  12668. PFILE_OBJECT FileObject;
  12669. } TARGET_DEVICE_REMOVAL_NOTIFICATION, *PTARGET_DEVICE_REMOVAL_NOTIFICATION;
  12670. //
  12671. // The following structure header is used for all other (i.e., 3rd-party)
  12672. // target device change events. The structure accommodates both a
  12673. // variable-length binary data buffer, and a variable-length unicode text
  12674. // buffer. The header must indicate where the text buffer begins, so that
  12675. // the data can be delivered in the appropriate format (ANSI or Unicode)
  12676. // to user-mode recipients (i.e., that have registered for handle-based
  12677. // notification via RegisterDeviceNotification).
  12678. //
  12679. typedef struct _TARGET_DEVICE_CUSTOM_NOTIFICATION {
  12680. USHORT Version;
  12681. USHORT Size;
  12682. GUID Event;
  12683. //
  12684. // Event-specific data
  12685. //
  12686. PFILE_OBJECT FileObject; // This field must be set to NULL by callers of
  12687. // IoReportTargetDeviceChange. Clients that
  12688. // have registered for target device change
  12689. // notification on the affected PDO will be
  12690. // called with this field set to the file object
  12691. // they specified during registration.
  12692. //
  12693. LONG NameBufferOffset; // offset (in bytes) from beginning of
  12694. // CustomDataBuffer where text begins (-1 if none)
  12695. //
  12696. UCHAR CustomDataBuffer[1]; // variable-length buffer, containing (optionally)
  12697. // a binary data at the start of the buffer,
  12698. // followed by an optional unicode text buffer
  12699. // (word-aligned).
  12700. //
  12701. } TARGET_DEVICE_CUSTOM_NOTIFICATION, *PTARGET_DEVICE_CUSTOM_NOTIFICATION;
  12702. ULONG
  12703. IoPnPDeliverServicePowerNotification(
  12704. IN POWER_ACTION PowerOperation,
  12705. IN ULONG PowerNotificationCode,
  12706. IN ULONG PowerNotificationData,
  12707. IN BOOLEAN Synchronous
  12708. );
  12709. //
  12710. // Define OEM bitmapped font check values.
  12711. //
  12712. #define OEM_FONT_VERSION 0x200
  12713. #define OEM_FONT_TYPE 0
  12714. #define OEM_FONT_ITALIC 0
  12715. #define OEM_FONT_UNDERLINE 0
  12716. #define OEM_FONT_STRIKEOUT 0
  12717. #define OEM_FONT_CHARACTER_SET 255
  12718. #define OEM_FONT_FAMILY (3 << 4)
  12719. //
  12720. // Define OEM bitmapped font file header structure.
  12721. //
  12722. // N.B. this is a packed structure.
  12723. //
  12724. #include "pshpack1.h"
  12725. typedef struct _OEM_FONT_FILE_HEADER {
  12726. USHORT Version;
  12727. ULONG FileSize;
  12728. UCHAR Copyright[60];
  12729. USHORT Type;
  12730. USHORT Points;
  12731. USHORT VerticleResolution;
  12732. USHORT HorizontalResolution;
  12733. USHORT Ascent;
  12734. USHORT InternalLeading;
  12735. USHORT ExternalLeading;
  12736. UCHAR Italic;
  12737. UCHAR Underline;
  12738. UCHAR StrikeOut;
  12739. USHORT Weight;
  12740. UCHAR CharacterSet;
  12741. USHORT PixelWidth;
  12742. USHORT PixelHeight;
  12743. UCHAR Family;
  12744. USHORT AverageWidth;
  12745. USHORT MaximumWidth;
  12746. UCHAR FirstCharacter;
  12747. UCHAR LastCharacter;
  12748. UCHAR DefaultCharacter;
  12749. UCHAR BreakCharacter;
  12750. USHORT WidthInBytes;
  12751. ULONG Device;
  12752. ULONG Face;
  12753. ULONG BitsPointer;
  12754. ULONG BitsOffset;
  12755. UCHAR Filler;
  12756. struct {
  12757. USHORT Width;
  12758. USHORT Offset;
  12759. } Map[1];
  12760. } OEM_FONT_FILE_HEADER, *POEM_FONT_FILE_HEADER;
  12761. #include "poppack.h"
  12762. //
  12763. // Define the device description structure.
  12764. //
  12765. typedef struct _DEVICE_DESCRIPTION {
  12766. ULONG Version;
  12767. BOOLEAN Master;
  12768. BOOLEAN ScatterGather;
  12769. BOOLEAN DemandMode;
  12770. BOOLEAN AutoInitialize;
  12771. BOOLEAN Dma32BitAddresses;
  12772. BOOLEAN IgnoreCount;
  12773. BOOLEAN Reserved1; // must be false
  12774. BOOLEAN Dma64BitAddresses;
  12775. ULONG BusNumber; // unused for WDM
  12776. ULONG DmaChannel;
  12777. INTERFACE_TYPE InterfaceType;
  12778. DMA_WIDTH DmaWidth;
  12779. DMA_SPEED DmaSpeed;
  12780. ULONG MaximumLength;
  12781. ULONG DmaPort;
  12782. } DEVICE_DESCRIPTION, *PDEVICE_DESCRIPTION;
  12783. //
  12784. // Define the supported version numbers for the device description structure.
  12785. //
  12786. #define DEVICE_DESCRIPTION_VERSION 0
  12787. #define DEVICE_DESCRIPTION_VERSION1 1
  12788. #define DEVICE_DESCRIPTION_VERSION2 2
  12789. // end_ntddk end_wdm
  12790. //
  12791. // Boot record disk partition table entry structure format.
  12792. //
  12793. typedef struct _PARTITION_DESCRIPTOR {
  12794. UCHAR ActiveFlag; // Bootable or not
  12795. UCHAR StartingTrack; // Not used
  12796. UCHAR StartingCylinderLsb; // Not used
  12797. UCHAR StartingCylinderMsb; // Not used
  12798. UCHAR PartitionType; // 12 bit FAT, 16 bit FAT etc.
  12799. UCHAR EndingTrack; // Not used
  12800. UCHAR EndingCylinderLsb; // Not used
  12801. UCHAR EndingCylinderMsb; // Not used
  12802. UCHAR StartingSectorLsb0; // Hidden sectors
  12803. UCHAR StartingSectorLsb1;
  12804. UCHAR StartingSectorMsb0;
  12805. UCHAR StartingSectorMsb1;
  12806. UCHAR PartitionLengthLsb0; // Sectors in this partition
  12807. UCHAR PartitionLengthLsb1;
  12808. UCHAR PartitionLengthMsb0;
  12809. UCHAR PartitionLengthMsb1;
  12810. } PARTITION_DESCRIPTOR, *PPARTITION_DESCRIPTOR;
  12811. //
  12812. // Number of partition table entries
  12813. //
  12814. #define NUM_PARTITION_TABLE_ENTRIES 4
  12815. //
  12816. // Partition table record and boot signature offsets in 16-bit words.
  12817. //
  12818. #define PARTITION_TABLE_OFFSET (0x1be / 2)
  12819. #define BOOT_SIGNATURE_OFFSET ((0x200 / 2) - 1)
  12820. //
  12821. // Boot record signature value.
  12822. //
  12823. #define BOOT_RECORD_SIGNATURE (0xaa55)
  12824. //
  12825. // Initial size of the Partition list structure.
  12826. //
  12827. #define PARTITION_BUFFER_SIZE 2048
  12828. //
  12829. // Partition active flag - i.e., boot indicator
  12830. //
  12831. #define PARTITION_ACTIVE_FLAG 0x80
  12832. //
  12833. // Get and set environment variable values.
  12834. //
  12835. NTHALAPI
  12836. ARC_STATUS
  12837. HalGetEnvironmentVariable (
  12838. IN PCHAR Variable,
  12839. IN USHORT Length,
  12840. OUT PCHAR Buffer
  12841. );
  12842. NTHALAPI
  12843. ARC_STATUS
  12844. HalSetEnvironmentVariable (
  12845. IN PCHAR Variable,
  12846. IN PCHAR Value
  12847. );
  12848. NTHALAPI
  12849. NTSTATUS
  12850. HalGetEnvironmentVariableEx (
  12851. IN PWSTR VariableName,
  12852. IN LPGUID VendorGuid,
  12853. OUT PVOID Value,
  12854. IN OUT PULONG ValueLength,
  12855. OUT PULONG Attributes OPTIONAL
  12856. );
  12857. NTSTATUS
  12858. HalSetEnvironmentVariableEx (
  12859. IN PWSTR VariableName,
  12860. IN LPGUID VendorGuid,
  12861. IN PVOID Value,
  12862. IN ULONG ValueLength,
  12863. IN ULONG Attributes
  12864. );
  12865. NTSTATUS
  12866. HalEnumerateEnvironmentVariablesEx (
  12867. IN ULONG InformationClass,
  12868. OUT PVOID Buffer,
  12869. IN OUT PULONG BufferLength
  12870. );
  12871. #if defined(_IA64_)
  12872. NTHALAPI
  12873. VOID
  12874. HalFlushIoBuffers (
  12875. IN PMDL Mdl,
  12876. IN BOOLEAN ReadOperation,
  12877. IN BOOLEAN DmaOperation
  12878. );
  12879. // begin_ntddk begin_ntifs begin_ntndis
  12880. DECLSPEC_DEPRECATED_DDK // Use GetDmaRequirement
  12881. NTHALAPI
  12882. ULONG
  12883. HalGetDmaAlignmentRequirement (
  12884. VOID
  12885. );
  12886. #endif
  12887. #if defined(_M_IX86) || defined(_M_AMD64)
  12888. #define HalGetDmaAlignmentRequirement() 1L
  12889. #endif
  12890. NTHALAPI // ntddk ntifs wdm ntndis
  12891. VOID // ntddk ntifs wdm ntndis
  12892. KeFlushWriteBuffer ( // ntddk ntifs wdm ntndis
  12893. VOID // ntddk ntifs wdm ntndis
  12894. ); // ntddk ntifs wdm ntndis
  12895. // ntddk ntifs wdm ntndis
  12896. #if defined(_ALPHA_)
  12897. NTHALAPI
  12898. PVOID
  12899. HalCreateQva(
  12900. IN PHYSICAL_ADDRESS PhysicalAddress,
  12901. IN PVOID VirtualAddress
  12902. );
  12903. NTHALAPI
  12904. PVOID
  12905. HalDereferenceQva(
  12906. PVOID Qva,
  12907. INTERFACE_TYPE InterfaceType,
  12908. ULONG BusNumber
  12909. );
  12910. #endif
  12911. #if !defined(_X86_)
  12912. NTHALAPI
  12913. BOOLEAN
  12914. HalCallBios (
  12915. IN ULONG BiosCommand,
  12916. IN OUT PULONG Eax,
  12917. IN OUT PULONG Ebx,
  12918. IN OUT PULONG Ecx,
  12919. IN OUT PULONG Edx,
  12920. IN OUT PULONG Esi,
  12921. IN OUT PULONG Edi,
  12922. IN OUT PULONG Ebp
  12923. );
  12924. #endif
  12925. NTHALAPI
  12926. BOOLEAN
  12927. HalQueryRealTimeClock (
  12928. OUT PTIME_FIELDS TimeFields
  12929. );
  12930. //
  12931. // Firmware interface functions.
  12932. //
  12933. NTHALAPI
  12934. VOID
  12935. HalReturnToFirmware (
  12936. IN FIRMWARE_REENTRY Routine
  12937. );
  12938. //
  12939. // System interrupts functions.
  12940. //
  12941. NTHALAPI
  12942. VOID
  12943. HalDisableSystemInterrupt (
  12944. IN ULONG Vector,
  12945. IN KIRQL Irql
  12946. );
  12947. NTHALAPI
  12948. BOOLEAN
  12949. HalEnableSystemInterrupt (
  12950. IN ULONG Vector,
  12951. IN KIRQL Irql,
  12952. IN KINTERRUPT_MODE InterruptMode
  12953. );
  12954. // begin_ntddk
  12955. //
  12956. // I/O driver configuration functions.
  12957. //
  12958. #if !defined(NO_LEGACY_DRIVERS)
  12959. DECLSPEC_DEPRECATED_DDK // Use Pnp or IoReportDetectedDevice
  12960. NTHALAPI
  12961. NTSTATUS
  12962. HalAssignSlotResources (
  12963. IN PUNICODE_STRING RegistryPath,
  12964. IN PUNICODE_STRING DriverClassName OPTIONAL,
  12965. IN PDRIVER_OBJECT DriverObject,
  12966. IN PDEVICE_OBJECT DeviceObject,
  12967. IN INTERFACE_TYPE BusType,
  12968. IN ULONG BusNumber,
  12969. IN ULONG SlotNumber,
  12970. IN OUT PCM_RESOURCE_LIST *AllocatedResources
  12971. );
  12972. DECLSPEC_DEPRECATED_DDK // Use Pnp or IoReportDetectedDevice
  12973. NTHALAPI
  12974. ULONG
  12975. HalGetInterruptVector(
  12976. IN INTERFACE_TYPE InterfaceType,
  12977. IN ULONG BusNumber,
  12978. IN ULONG BusInterruptLevel,
  12979. IN ULONG BusInterruptVector,
  12980. OUT PKIRQL Irql,
  12981. OUT PKAFFINITY Affinity
  12982. );
  12983. DECLSPEC_DEPRECATED_DDK // Use IRP_MN_QUERY_INTERFACE and IRP_MN_READ_CONFIG
  12984. NTHALAPI
  12985. ULONG
  12986. HalSetBusData(
  12987. IN BUS_DATA_TYPE BusDataType,
  12988. IN ULONG BusNumber,
  12989. IN ULONG SlotNumber,
  12990. IN PVOID Buffer,
  12991. IN ULONG Length
  12992. );
  12993. #endif // NO_LEGACY_DRIVERS
  12994. DECLSPEC_DEPRECATED_DDK // Use IRP_MN_QUERY_INTERFACE and IRP_MN_READ_CONFIG
  12995. NTHALAPI
  12996. ULONG
  12997. HalSetBusDataByOffset(
  12998. IN BUS_DATA_TYPE BusDataType,
  12999. IN ULONG BusNumber,
  13000. IN ULONG SlotNumber,
  13001. IN PVOID Buffer,
  13002. IN ULONG Offset,
  13003. IN ULONG Length
  13004. );
  13005. DECLSPEC_DEPRECATED_DDK // Use IRP_MN_QUERY_INTERFACE and IRP_MN_READ_CONFIG
  13006. NTHALAPI
  13007. BOOLEAN
  13008. HalTranslateBusAddress(
  13009. IN INTERFACE_TYPE InterfaceType,
  13010. IN ULONG BusNumber,
  13011. IN PHYSICAL_ADDRESS BusAddress,
  13012. IN OUT PULONG AddressSpace,
  13013. OUT PPHYSICAL_ADDRESS TranslatedAddress
  13014. );
  13015. //
  13016. // Values for AddressSpace parameter of HalTranslateBusAddress
  13017. //
  13018. // 0x0 - Memory space
  13019. // 0x1 - Port space
  13020. // 0x2 - 0x1F - Address spaces specific for Alpha
  13021. // 0x2 - UserMode view of memory space
  13022. // 0x3 - UserMode view of port space
  13023. // 0x4 - Dense memory space
  13024. // 0x5 - reserved
  13025. // 0x6 - UserMode view of dense memory space
  13026. // 0x7 - 0x1F - reserved
  13027. //
  13028. NTHALAPI
  13029. PVOID
  13030. HalAllocateCrashDumpRegisters(
  13031. IN PADAPTER_OBJECT AdapterObject,
  13032. IN OUT PULONG NumberOfMapRegisters
  13033. );
  13034. #if !defined(NO_LEGACY_DRIVERS)
  13035. DECLSPEC_DEPRECATED_DDK // Use IRP_MN_QUERY_INTERFACE and IRP_MN_READ_CONFIG
  13036. NTHALAPI
  13037. ULONG
  13038. HalGetBusData(
  13039. IN BUS_DATA_TYPE BusDataType,
  13040. IN ULONG BusNumber,
  13041. IN ULONG SlotNumber,
  13042. IN PVOID Buffer,
  13043. IN ULONG Length
  13044. );
  13045. #endif // NO_LEGACY_DRIVERS
  13046. DECLSPEC_DEPRECATED_DDK // Use IRP_MN_QUERY_INTERFACE and IRP_MN_READ_CONFIG
  13047. NTHALAPI
  13048. ULONG
  13049. HalGetBusDataByOffset(
  13050. IN BUS_DATA_TYPE BusDataType,
  13051. IN ULONG BusNumber,
  13052. IN ULONG SlotNumber,
  13053. IN PVOID Buffer,
  13054. IN ULONG Offset,
  13055. IN ULONG Length
  13056. );
  13057. DECLSPEC_DEPRECATED_DDK // Use IoGetDmaAdapter
  13058. NTHALAPI
  13059. PADAPTER_OBJECT
  13060. HalGetAdapter(
  13061. IN PDEVICE_DESCRIPTION DeviceDescription,
  13062. IN OUT PULONG NumberOfMapRegisters
  13063. );
  13064. //
  13065. // System beep functions.
  13066. //
  13067. #if !defined(NO_LEGACY_DRIVERS)
  13068. DECLSPEC_DEPRECATED_DDK
  13069. NTHALAPI
  13070. BOOLEAN
  13071. HalMakeBeep(
  13072. IN ULONG Frequency
  13073. );
  13074. #endif // NO_LEGACY_DRIVERS
  13075. //
  13076. // The following function prototypes are for HAL routines with a prefix of Io.
  13077. //
  13078. // DMA adapter object functions.
  13079. //
  13080. //
  13081. // Performance counter function.
  13082. //
  13083. NTHALAPI
  13084. LARGE_INTEGER
  13085. KeQueryPerformanceCounter (
  13086. OUT PLARGE_INTEGER PerformanceFrequency OPTIONAL
  13087. );
  13088. // begin_ntndis
  13089. //
  13090. // Stall processor execution function.
  13091. //
  13092. NTHALAPI
  13093. VOID
  13094. KeStallExecutionProcessor (
  13095. IN ULONG MicroSeconds
  13096. );
  13097. typedef
  13098. NTSTATUS
  13099. (*PINSTALL_BUS_HANDLER)(
  13100. IN PBUS_HANDLER Bus
  13101. );
  13102. typedef
  13103. NTSTATUS
  13104. (*pHalRegisterBusHandler)(
  13105. IN INTERFACE_TYPE InterfaceType,
  13106. IN BUS_DATA_TYPE AssociatedConfigurationSpace,
  13107. IN ULONG BusNumber,
  13108. IN INTERFACE_TYPE ParentBusType,
  13109. IN ULONG ParentBusNumber,
  13110. IN ULONG SizeofBusExtensionData,
  13111. IN PINSTALL_BUS_HANDLER InstallBusHandlers,
  13112. OUT PBUS_HANDLER *BusHandler
  13113. );
  13114. typedef
  13115. PBUS_HANDLER
  13116. (FASTCALL *pHalHandlerForBus) (
  13117. IN INTERFACE_TYPE InterfaceType,
  13118. IN ULONG BusNumber
  13119. );
  13120. typedef
  13121. PBUS_HANDLER
  13122. (FASTCALL *pHalHandlerForConfigSpace) (
  13123. IN BUS_DATA_TYPE ConfigSpace,
  13124. IN ULONG BusNumber
  13125. );
  13126. typedef
  13127. VOID
  13128. (FASTCALL *pHalReferenceBusHandler) (
  13129. IN PBUS_HANDLER BusHandler
  13130. );
  13131. typedef
  13132. VOID
  13133. (*pHalSetWakeEnable)(
  13134. IN BOOLEAN Enable
  13135. );
  13136. typedef
  13137. VOID
  13138. (*pHalSetWakeAlarm)(
  13139. IN ULONGLONG WakeTime,
  13140. IN PTIME_FIELDS WakeTimeFields
  13141. );
  13142. typedef
  13143. VOID
  13144. (*pHalLocateHiberRanges)(
  13145. IN PVOID MemoryMap
  13146. );
  13147. // begin_ntddk
  13148. //*****************************************************************************
  13149. // HAL Function dispatch
  13150. //
  13151. typedef enum _HAL_QUERY_INFORMATION_CLASS {
  13152. HalInstalledBusInformation,
  13153. HalProfileSourceInformation,
  13154. HalInformationClassUnused1,
  13155. HalPowerInformation,
  13156. HalProcessorSpeedInformation,
  13157. HalCallbackInformation,
  13158. HalMapRegisterInformation,
  13159. HalMcaLogInformation, // Machine Check Abort Information
  13160. HalFrameBufferCachingInformation,
  13161. HalDisplayBiosInformation,
  13162. HalProcessorFeatureInformation,
  13163. HalNumaTopologyInterface,
  13164. HalErrorInformation, // General MCA, CMC, CPE Error Information.
  13165. HalCmcLogInformation, // Processor Corrected Machine Check Information
  13166. HalCpeLogInformation, // Corrected Platform Error Information
  13167. HalQueryMcaInterface,
  13168. HalQueryAMLIIllegalIOPortAddresses,
  13169. HalQueryMaxHotPlugMemoryAddress,
  13170. HalPartitionIpiInterface,
  13171. HalPlatformInformation,
  13172. HalQueryProfileSourceList
  13173. // information levels >= 0x8000000 reserved for OEM use
  13174. } HAL_QUERY_INFORMATION_CLASS, *PHAL_QUERY_INFORMATION_CLASS;
  13175. typedef enum _HAL_SET_INFORMATION_CLASS {
  13176. HalProfileSourceInterval,
  13177. HalProfileSourceInterruptHandler,
  13178. HalMcaRegisterDriver, // Registring Machine Check Abort driver
  13179. HalKernelErrorHandler,
  13180. HalCmcRegisterDriver, // Registring Processor Corrected Machine Check driver
  13181. HalCpeRegisterDriver, // Registring Corrected Platform Error driver
  13182. HalMcaLog,
  13183. HalCmcLog,
  13184. HalCpeLog,
  13185. HalGenerateCmcInterrupt // Used to test CMC
  13186. } HAL_SET_INFORMATION_CLASS, *PHAL_SET_INFORMATION_CLASS;
  13187. typedef
  13188. NTSTATUS
  13189. (*pHalQuerySystemInformation)(
  13190. IN HAL_QUERY_INFORMATION_CLASS InformationClass,
  13191. IN ULONG BufferSize,
  13192. IN OUT PVOID Buffer,
  13193. OUT PULONG ReturnedLength
  13194. );
  13195. // end_ntddk
  13196. NTSTATUS
  13197. HaliQuerySystemInformation(
  13198. IN HAL_SET_INFORMATION_CLASS InformationClass,
  13199. IN ULONG BufferSize,
  13200. IN OUT PVOID Buffer,
  13201. OUT PULONG ReturnedLength
  13202. );
  13203. NTSTATUS
  13204. HaliHandlePCIConfigSpaceAccess(
  13205. IN BOOLEAN Read,
  13206. IN ULONG Addr,
  13207. IN ULONG Size,
  13208. IN OUT PULONG pData
  13209. );
  13210. //begin_ntddk
  13211. typedef
  13212. NTSTATUS
  13213. (*pHalSetSystemInformation)(
  13214. IN HAL_SET_INFORMATION_CLASS InformationClass,
  13215. IN ULONG BufferSize,
  13216. IN PVOID Buffer
  13217. );
  13218. // end_ntddk
  13219. NTSTATUS
  13220. HaliSetSystemInformation(
  13221. IN HAL_SET_INFORMATION_CLASS InformationClass,
  13222. IN ULONG BufferSize,
  13223. IN PVOID Buffer
  13224. );
  13225. // begin_ntddk
  13226. typedef
  13227. VOID
  13228. (FASTCALL *pHalExamineMBR)(
  13229. IN PDEVICE_OBJECT DeviceObject,
  13230. IN ULONG SectorSize,
  13231. IN ULONG MBRTypeIdentifier,
  13232. OUT PVOID *Buffer
  13233. );
  13234. typedef
  13235. VOID
  13236. (FASTCALL *pHalIoAssignDriveLetters)(
  13237. IN struct _LOADER_PARAMETER_BLOCK *LoaderBlock,
  13238. IN PSTRING NtDeviceName,
  13239. OUT PUCHAR NtSystemPath,
  13240. OUT PSTRING NtSystemPathString
  13241. );
  13242. typedef
  13243. NTSTATUS
  13244. (FASTCALL *pHalIoReadPartitionTable)(
  13245. IN PDEVICE_OBJECT DeviceObject,
  13246. IN ULONG SectorSize,
  13247. IN BOOLEAN ReturnRecognizedPartitions,
  13248. OUT struct _DRIVE_LAYOUT_INFORMATION **PartitionBuffer
  13249. );
  13250. typedef
  13251. NTSTATUS
  13252. (FASTCALL *pHalIoSetPartitionInformation)(
  13253. IN PDEVICE_OBJECT DeviceObject,
  13254. IN ULONG SectorSize,
  13255. IN ULONG PartitionNumber,
  13256. IN ULONG PartitionType
  13257. );
  13258. typedef
  13259. NTSTATUS
  13260. (FASTCALL *pHalIoWritePartitionTable)(
  13261. IN PDEVICE_OBJECT DeviceObject,
  13262. IN ULONG SectorSize,
  13263. IN ULONG SectorsPerTrack,
  13264. IN ULONG NumberOfHeads,
  13265. IN struct _DRIVE_LAYOUT_INFORMATION *PartitionBuffer
  13266. );
  13267. typedef
  13268. NTSTATUS
  13269. (*pHalQueryBusSlots)(
  13270. IN PBUS_HANDLER BusHandler,
  13271. IN ULONG BufferSize,
  13272. OUT PULONG SlotNumbers,
  13273. OUT PULONG ReturnedLength
  13274. );
  13275. typedef
  13276. NTSTATUS
  13277. (*pHalInitPnpDriver)(
  13278. VOID
  13279. );
  13280. // end_ntddk
  13281. NTSTATUS
  13282. HaliInitPnpDriver(
  13283. VOID
  13284. );
  13285. // begin_ntddk
  13286. typedef struct _PM_DISPATCH_TABLE {
  13287. ULONG Signature;
  13288. ULONG Version;
  13289. PVOID Function[1];
  13290. } PM_DISPATCH_TABLE, *PPM_DISPATCH_TABLE;
  13291. typedef
  13292. NTSTATUS
  13293. (*pHalInitPowerManagement)(
  13294. IN PPM_DISPATCH_TABLE PmDriverDispatchTable,
  13295. OUT PPM_DISPATCH_TABLE *PmHalDispatchTable
  13296. );
  13297. // end_ntddk
  13298. NTSTATUS
  13299. HaliInitPowerManagement(
  13300. IN PPM_DISPATCH_TABLE PmDriverDispatchTable,
  13301. IN OUT PPM_DISPATCH_TABLE *PmHalDispatchTable
  13302. );
  13303. // begin_ntddk
  13304. typedef
  13305. struct _DMA_ADAPTER *
  13306. (*pHalGetDmaAdapter)(
  13307. IN PVOID Context,
  13308. IN struct _DEVICE_DESCRIPTION *DeviceDescriptor,
  13309. OUT PULONG NumberOfMapRegisters
  13310. );
  13311. // end_ntddk
  13312. struct _DMA_ADAPTER *
  13313. HaliGetDmaAdapter(
  13314. IN PVOID Context,
  13315. IN struct _DEVICE_DESCRIPTION *DeviceDescriptor,
  13316. OUT PULONG NumberOfMapRegisters
  13317. );
  13318. // begin_ntddk
  13319. typedef
  13320. NTSTATUS
  13321. (*pHalGetInterruptTranslator)(
  13322. IN INTERFACE_TYPE ParentInterfaceType,
  13323. IN ULONG ParentBusNumber,
  13324. IN INTERFACE_TYPE BridgeInterfaceType,
  13325. IN USHORT Size,
  13326. IN USHORT Version,
  13327. OUT PTRANSLATOR_INTERFACE Translator,
  13328. OUT PULONG BridgeBusNumber
  13329. );
  13330. // end_ntddk
  13331. NTSTATUS
  13332. HaliGetInterruptTranslator(
  13333. IN INTERFACE_TYPE ParentInterfaceType,
  13334. IN ULONG ParentBusNumber,
  13335. IN INTERFACE_TYPE BridgeInterfaceType,
  13336. IN USHORT Size,
  13337. IN USHORT Version,
  13338. OUT PTRANSLATOR_INTERFACE Translator,
  13339. OUT PULONG BridgeBusNumber
  13340. );
  13341. // begin_ntddk
  13342. typedef
  13343. BOOLEAN
  13344. (*pHalTranslateBusAddress)(
  13345. IN INTERFACE_TYPE InterfaceType,
  13346. IN ULONG BusNumber,
  13347. IN PHYSICAL_ADDRESS BusAddress,
  13348. IN OUT PULONG AddressSpace,
  13349. OUT PPHYSICAL_ADDRESS TranslatedAddress
  13350. );
  13351. typedef
  13352. NTSTATUS
  13353. (*pHalAssignSlotResources) (
  13354. IN PUNICODE_STRING RegistryPath,
  13355. IN PUNICODE_STRING DriverClassName OPTIONAL,
  13356. IN PDRIVER_OBJECT DriverObject,
  13357. IN PDEVICE_OBJECT DeviceObject,
  13358. IN INTERFACE_TYPE BusType,
  13359. IN ULONG BusNumber,
  13360. IN ULONG SlotNumber,
  13361. IN OUT PCM_RESOURCE_LIST *AllocatedResources
  13362. );
  13363. typedef
  13364. VOID
  13365. (*pHalHaltSystem) (
  13366. VOID
  13367. );
  13368. typedef
  13369. BOOLEAN
  13370. (*pHalResetDisplay) (
  13371. VOID
  13372. );
  13373. // begin_ntndis
  13374. typedef struct _MAP_REGISTER_ENTRY {
  13375. PVOID MapRegister;
  13376. BOOLEAN WriteToDevice;
  13377. } MAP_REGISTER_ENTRY, *PMAP_REGISTER_ENTRY;
  13378. // end_ntndis
  13379. // end_ntddk
  13380. typedef
  13381. NTSTATUS
  13382. (*pHalAllocateMapRegisters)(
  13383. IN struct _ADAPTER_OBJECT *DmaAdapter,
  13384. IN ULONG NumberOfMapRegisters,
  13385. IN ULONG BaseAddressCount,
  13386. OUT PMAP_REGISTER_ENTRY MapRegsiterArray
  13387. );
  13388. NTSTATUS
  13389. HalAllocateMapRegisters(
  13390. IN struct _ADAPTER_OBJECT *DmaAdapter,
  13391. IN ULONG NumberOfMapRegisters,
  13392. IN ULONG BaseAddressCount,
  13393. OUT PMAP_REGISTER_ENTRY MapRegsiterArray
  13394. );
  13395. // begin_ntddk
  13396. typedef
  13397. UCHAR
  13398. (*pHalVectorToIDTEntry) (
  13399. ULONG Vector
  13400. );
  13401. typedef
  13402. BOOLEAN
  13403. (*pHalFindBusAddressTranslation) (
  13404. IN PHYSICAL_ADDRESS BusAddress,
  13405. IN OUT PULONG AddressSpace,
  13406. OUT PPHYSICAL_ADDRESS TranslatedAddress,
  13407. IN OUT PULONG_PTR Context,
  13408. IN BOOLEAN NextBus
  13409. );
  13410. typedef
  13411. NTSTATUS
  13412. (*pHalStartMirroring)(
  13413. VOID
  13414. );
  13415. typedef
  13416. NTSTATUS
  13417. (*pHalEndMirroring)(
  13418. IN ULONG PassNumber
  13419. );
  13420. typedef
  13421. NTSTATUS
  13422. (*pHalMirrorPhysicalMemory)(
  13423. IN PHYSICAL_ADDRESS PhysicalAddress,
  13424. IN LARGE_INTEGER NumberOfBytes
  13425. );
  13426. typedef
  13427. NTSTATUS
  13428. (*pHalMirrorVerify)(
  13429. IN PHYSICAL_ADDRESS PhysicalAddress,
  13430. IN LARGE_INTEGER NumberOfBytes
  13431. );
  13432. typedef struct {
  13433. UCHAR Type; //CmResourceType
  13434. BOOLEAN Valid;
  13435. UCHAR Reserved[2];
  13436. PUCHAR TranslatedAddress;
  13437. ULONG Length;
  13438. } DEBUG_DEVICE_ADDRESS, *PDEBUG_DEVICE_ADDRESS;
  13439. typedef struct {
  13440. PHYSICAL_ADDRESS Start;
  13441. PHYSICAL_ADDRESS MaxEnd;
  13442. PVOID VirtualAddress;
  13443. ULONG Length;
  13444. BOOLEAN Cached;
  13445. BOOLEAN Aligned;
  13446. } DEBUG_MEMORY_REQUIREMENTS, *PDEBUG_MEMORY_REQUIREMENTS;
  13447. typedef struct {
  13448. ULONG Bus;
  13449. ULONG Slot;
  13450. USHORT VendorID;
  13451. USHORT DeviceID;
  13452. UCHAR BaseClass;
  13453. UCHAR SubClass;
  13454. UCHAR ProgIf;
  13455. BOOLEAN Initialized;
  13456. DEBUG_DEVICE_ADDRESS BaseAddress[6];
  13457. DEBUG_MEMORY_REQUIREMENTS Memory;
  13458. } DEBUG_DEVICE_DESCRIPTOR, *PDEBUG_DEVICE_DESCRIPTOR;
  13459. typedef
  13460. NTSTATUS
  13461. (*pKdSetupPciDeviceForDebugging)(
  13462. IN PVOID LoaderBlock, OPTIONAL
  13463. IN OUT PDEBUG_DEVICE_DESCRIPTOR PciDevice
  13464. );
  13465. typedef
  13466. NTSTATUS
  13467. (*pKdReleasePciDeviceForDebugging)(
  13468. IN OUT PDEBUG_DEVICE_DESCRIPTOR PciDevice
  13469. );
  13470. typedef
  13471. PVOID
  13472. (*pKdGetAcpiTablePhase0)(
  13473. IN struct _LOADER_PARAMETER_BLOCK *LoaderBlock,
  13474. IN ULONG Signature
  13475. );
  13476. typedef
  13477. VOID
  13478. (*pKdCheckPowerButton)(
  13479. VOID
  13480. );
  13481. typedef
  13482. VOID
  13483. (*pHalEndOfBoot)(
  13484. VOID
  13485. );
  13486. typedef
  13487. PVOID
  13488. (*pKdMapPhysicalMemory64)(
  13489. IN PHYSICAL_ADDRESS PhysicalAddress,
  13490. IN ULONG NumberPages
  13491. );
  13492. typedef
  13493. VOID
  13494. (*pKdUnmapVirtualAddress)(
  13495. IN PVOID VirtualAddress,
  13496. IN ULONG NumberPages
  13497. );
  13498. typedef struct {
  13499. ULONG Version;
  13500. pHalQuerySystemInformation HalQuerySystemInformation;
  13501. pHalSetSystemInformation HalSetSystemInformation;
  13502. pHalQueryBusSlots HalQueryBusSlots;
  13503. ULONG Spare1;
  13504. pHalExamineMBR HalExamineMBR;
  13505. pHalIoAssignDriveLetters HalIoAssignDriveLetters;
  13506. pHalIoReadPartitionTable HalIoReadPartitionTable;
  13507. pHalIoSetPartitionInformation HalIoSetPartitionInformation;
  13508. pHalIoWritePartitionTable HalIoWritePartitionTable;
  13509. pHalHandlerForBus HalReferenceHandlerForBus;
  13510. pHalReferenceBusHandler HalReferenceBusHandler;
  13511. pHalReferenceBusHandler HalDereferenceBusHandler;
  13512. pHalInitPnpDriver HalInitPnpDriver;
  13513. pHalInitPowerManagement HalInitPowerManagement;
  13514. pHalGetDmaAdapter HalGetDmaAdapter;
  13515. pHalGetInterruptTranslator HalGetInterruptTranslator;
  13516. pHalStartMirroring HalStartMirroring;
  13517. pHalEndMirroring HalEndMirroring;
  13518. pHalMirrorPhysicalMemory HalMirrorPhysicalMemory;
  13519. pHalEndOfBoot HalEndOfBoot;
  13520. pHalMirrorVerify HalMirrorVerify;
  13521. } HAL_DISPATCH, *PHAL_DISPATCH;
  13522. #if defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_) || defined(_NTHAL_)
  13523. extern PHAL_DISPATCH HalDispatchTable;
  13524. #define HALDISPATCH HalDispatchTable
  13525. #else
  13526. extern HAL_DISPATCH HalDispatchTable;
  13527. #define HALDISPATCH (&HalDispatchTable)
  13528. #endif
  13529. #define HAL_DISPATCH_VERSION 3
  13530. #define HalDispatchTableVersion HALDISPATCH->Version
  13531. #define HalQuerySystemInformation HALDISPATCH->HalQuerySystemInformation
  13532. #define HalSetSystemInformation HALDISPATCH->HalSetSystemInformation
  13533. #define HalQueryBusSlots HALDISPATCH->HalQueryBusSlots
  13534. #define HalReferenceHandlerForBus HALDISPATCH->HalReferenceHandlerForBus
  13535. #define HalReferenceBusHandler HALDISPATCH->HalReferenceBusHandler
  13536. #define HalDereferenceBusHandler HALDISPATCH->HalDereferenceBusHandler
  13537. #define HalInitPnpDriver HALDISPATCH->HalInitPnpDriver
  13538. #define HalInitPowerManagement HALDISPATCH->HalInitPowerManagement
  13539. #define HalGetDmaAdapter HALDISPATCH->HalGetDmaAdapter
  13540. #define HalGetInterruptTranslator HALDISPATCH->HalGetInterruptTranslator
  13541. #define HalStartMirroring HALDISPATCH->HalStartMirroring
  13542. #define HalEndMirroring HALDISPATCH->HalEndMirroring
  13543. #define HalMirrorPhysicalMemory HALDISPATCH->HalMirrorPhysicalMemory
  13544. #define HalEndOfBoot HALDISPATCH->HalEndOfBoot
  13545. #define HalMirrorVerify HALDISPATCH->HalMirrorVerify
  13546. // end_ntddk
  13547. typedef struct {
  13548. ULONG Version;
  13549. pHalHandlerForBus HalHandlerForBus;
  13550. pHalHandlerForConfigSpace HalHandlerForConfigSpace;
  13551. pHalLocateHiberRanges HalLocateHiberRanges;
  13552. pHalRegisterBusHandler HalRegisterBusHandler;
  13553. pHalSetWakeEnable HalSetWakeEnable;
  13554. pHalSetWakeAlarm HalSetWakeAlarm;
  13555. pHalTranslateBusAddress HalPciTranslateBusAddress;
  13556. pHalAssignSlotResources HalPciAssignSlotResources;
  13557. pHalHaltSystem HalHaltSystem;
  13558. pHalFindBusAddressTranslation HalFindBusAddressTranslation;
  13559. pHalResetDisplay HalResetDisplay;
  13560. pHalAllocateMapRegisters HalAllocateMapRegisters;
  13561. pKdSetupPciDeviceForDebugging KdSetupPciDeviceForDebugging;
  13562. pKdReleasePciDeviceForDebugging KdReleasePciDeviceForDebugging;
  13563. pKdGetAcpiTablePhase0 KdGetAcpiTablePhase0;
  13564. pKdCheckPowerButton KdCheckPowerButton;
  13565. pHalVectorToIDTEntry HalVectorToIDTEntry;
  13566. pKdMapPhysicalMemory64 KdMapPhysicalMemory64;
  13567. pKdUnmapVirtualAddress KdUnmapVirtualAddress;
  13568. } HAL_PRIVATE_DISPATCH, *PHAL_PRIVATE_DISPATCH;
  13569. #if defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_) || defined(_NTHAL_)
  13570. extern PHAL_PRIVATE_DISPATCH HalPrivateDispatchTable;
  13571. #define HALPDISPATCH HalPrivateDispatchTable
  13572. #else
  13573. extern HAL_PRIVATE_DISPATCH HalPrivateDispatchTable;
  13574. #define HALPDISPATCH (&HalPrivateDispatchTable)
  13575. #endif
  13576. #define HAL_PRIVATE_DISPATCH_VERSION 2
  13577. #define HalRegisterBusHandler HALPDISPATCH->HalRegisterBusHandler
  13578. #define HalHandlerForBus HALPDISPATCH->HalHandlerForBus
  13579. #define HalHandlerForConfigSpace HALPDISPATCH->HalHandlerForConfigSpace
  13580. #define HalLocateHiberRanges HALPDISPATCH->HalLocateHiberRanges
  13581. #define HalSetWakeEnable HALPDISPATCH->HalSetWakeEnable
  13582. #define HalSetWakeAlarm HALPDISPATCH->HalSetWakeAlarm
  13583. #define HalHaltSystem HALPDISPATCH->HalHaltSystem
  13584. #define HalResetDisplay HALPDISPATCH->HalResetDisplay
  13585. #define HalAllocateMapRegisters HALPDISPATCH->HalAllocateMapRegisters
  13586. #define KdSetupPciDeviceForDebugging HALPDISPATCH->KdSetupPciDeviceForDebugging
  13587. #define KdReleasePciDeviceForDebugging HALPDISPATCH->KdReleasePciDeviceForDebugging
  13588. #define KdGetAcpiTablePhase0 HALPDISPATCH->KdGetAcpiTablePhase0
  13589. #define KdCheckPowerButton HALPDISPATCH->KdCheckPowerButton
  13590. #define HalVectorToIDTEntry HALPDISPATCH->HalVectorToIDTEntry
  13591. #define KdMapPhysicalMemory64 HALPDISPATCH->KdMapPhysicalMemory64
  13592. #define KdUnmapVirtualAddress HALPDISPATCH->KdUnmapVirtualAddress
  13593. // begin_ntddk
  13594. //
  13595. // HAL System Information Structures.
  13596. //
  13597. // for the information class "HalInstalledBusInformation"
  13598. typedef struct _HAL_BUS_INFORMATION{
  13599. INTERFACE_TYPE BusType;
  13600. BUS_DATA_TYPE ConfigurationType;
  13601. ULONG BusNumber;
  13602. ULONG Reserved;
  13603. } HAL_BUS_INFORMATION, *PHAL_BUS_INFORMATION;
  13604. // for the information class "HalProfileSourceInformation"
  13605. typedef struct _HAL_PROFILE_SOURCE_INFORMATION {
  13606. KPROFILE_SOURCE Source;
  13607. BOOLEAN Supported;
  13608. ULONG Interval;
  13609. } HAL_PROFILE_SOURCE_INFORMATION, *PHAL_PROFILE_SOURCE_INFORMATION;
  13610. // for the information class "HalProfileSourceInformation"
  13611. typedef struct _HAL_PROFILE_SOURCE_INFORMATION_EX {
  13612. KPROFILE_SOURCE Source;
  13613. BOOLEAN Supported;
  13614. ULONG_PTR Interval;
  13615. ULONG_PTR DefInterval;
  13616. ULONG_PTR MaxInterval;
  13617. ULONG_PTR MinInterval;
  13618. } HAL_PROFILE_SOURCE_INFORMATION_EX, *PHAL_PROFILE_SOURCE_INFORMATION_EX;
  13619. // for the information class "HalProfileSourceInterval"
  13620. typedef struct _HAL_PROFILE_SOURCE_INTERVAL {
  13621. KPROFILE_SOURCE Source;
  13622. ULONG_PTR Interval;
  13623. } HAL_PROFILE_SOURCE_INTERVAL, *PHAL_PROFILE_SOURCE_INTERVAL;
  13624. // for the information class "HalQueryProfileSourceList"
  13625. typedef struct _HAL_PROFILE_SOURCE_LIST {
  13626. KPROFILE_SOURCE Source;
  13627. PWSTR Description;
  13628. } HAL_PROFILE_SOURCE_LIST, *PHAL_PROFILE_SOURCE_LIST;
  13629. // for the information class "HalDispayBiosInformation"
  13630. typedef enum _HAL_DISPLAY_BIOS_INFORMATION {
  13631. HalDisplayInt10Bios,
  13632. HalDisplayEmulatedBios,
  13633. HalDisplayNoBios
  13634. } HAL_DISPLAY_BIOS_INFORMATION, *PHAL_DISPLAY_BIOS_INFORMATION;
  13635. // for the information class "HalPowerInformation"
  13636. typedef struct _HAL_POWER_INFORMATION {
  13637. ULONG TBD;
  13638. } HAL_POWER_INFORMATION, *PHAL_POWER_INFORMATION;
  13639. // for the information class "HalProcessorSpeedInformation"
  13640. typedef struct _HAL_PROCESSOR_SPEED_INFO {
  13641. ULONG ProcessorSpeed;
  13642. } HAL_PROCESSOR_SPEED_INFORMATION, *PHAL_PROCESSOR_SPEED_INFORMATION;
  13643. // for the information class "HalCallbackInformation"
  13644. typedef struct _HAL_CALLBACKS {
  13645. PCALLBACK_OBJECT SetSystemInformation;
  13646. PCALLBACK_OBJECT BusCheck;
  13647. } HAL_CALLBACKS, *PHAL_CALLBACKS;
  13648. // for the information class "HalProcessorFeatureInformation"
  13649. typedef struct _HAL_PROCESSOR_FEATURE {
  13650. ULONG UsableFeatureBits;
  13651. } HAL_PROCESSOR_FEATURE;
  13652. // for the information class "HalNumaTopologyInterface"
  13653. typedef ULONG HALNUMAPAGETONODE;
  13654. typedef
  13655. HALNUMAPAGETONODE
  13656. (*PHALNUMAPAGETONODE)(
  13657. IN ULONG_PTR PhysicalPageNumber
  13658. );
  13659. typedef
  13660. NTSTATUS
  13661. (*PHALNUMAQUERYPROCESSORNODE)(
  13662. IN ULONG ProcessorNumber,
  13663. OUT PUSHORT Identifier,
  13664. OUT PUCHAR Node
  13665. );
  13666. typedef struct _HAL_NUMA_TOPOLOGY_INTERFACE {
  13667. ULONG NumberOfNodes;
  13668. PHALNUMAQUERYPROCESSORNODE QueryProcessorNode;
  13669. PHALNUMAPAGETONODE PageToNode;
  13670. } HAL_NUMA_TOPOLOGY_INTERFACE;
  13671. typedef
  13672. NTSTATUS
  13673. (*PHALIOREADWRITEHANDLER)(
  13674. IN BOOLEAN fRead,
  13675. IN ULONG dwAddr,
  13676. IN ULONG dwSize,
  13677. IN OUT PULONG pdwData
  13678. );
  13679. // for the information class "HalQueryIllegalIOPortAddresses"
  13680. typedef struct _HAL_AMLI_BAD_IO_ADDRESS_LIST
  13681. {
  13682. ULONG BadAddrBegin;
  13683. ULONG BadAddrSize;
  13684. ULONG OSVersionTrigger;
  13685. PHALIOREADWRITEHANDLER IOHandler;
  13686. } HAL_AMLI_BAD_IO_ADDRESS_LIST, *PHAL_AMLI_BAD_IO_ADDRESS_LIST;
  13687. typedef struct _SCATTER_GATHER_ELEMENT {
  13688. PHYSICAL_ADDRESS Address;
  13689. ULONG Length;
  13690. ULONG_PTR Reserved;
  13691. } SCATTER_GATHER_ELEMENT, *PSCATTER_GATHER_ELEMENT;
  13692. #if _MSC_VER >= 1200
  13693. #pragma warning(push)
  13694. #endif
  13695. #pragma warning(disable:4200)
  13696. typedef struct _SCATTER_GATHER_LIST {
  13697. ULONG NumberOfElements;
  13698. ULONG_PTR Reserved;
  13699. SCATTER_GATHER_ELEMENT Elements[];
  13700. } SCATTER_GATHER_LIST, *PSCATTER_GATHER_LIST;
  13701. #if _MSC_VER >= 1200
  13702. #pragma warning(pop)
  13703. #else
  13704. #pragma warning(default:4200)
  13705. #endif
  13706. // end_ntndis
  13707. typedef struct _DMA_OPERATIONS *PDMA_OPERATIONS;
  13708. typedef struct _DMA_ADAPTER {
  13709. USHORT Version;
  13710. USHORT Size;
  13711. PDMA_OPERATIONS DmaOperations;
  13712. // Private Bus Device Driver data follows,
  13713. } DMA_ADAPTER, *PDMA_ADAPTER;
  13714. typedef VOID (*PPUT_DMA_ADAPTER)(
  13715. PDMA_ADAPTER DmaAdapter
  13716. );
  13717. typedef PVOID (*PALLOCATE_COMMON_BUFFER)(
  13718. IN PDMA_ADAPTER DmaAdapter,
  13719. IN ULONG Length,
  13720. OUT PPHYSICAL_ADDRESS LogicalAddress,
  13721. IN BOOLEAN CacheEnabled
  13722. );
  13723. typedef VOID (*PFREE_COMMON_BUFFER)(
  13724. IN PDMA_ADAPTER DmaAdapter,
  13725. IN ULONG Length,
  13726. IN PHYSICAL_ADDRESS LogicalAddress,
  13727. IN PVOID VirtualAddress,
  13728. IN BOOLEAN CacheEnabled
  13729. );
  13730. typedef NTSTATUS (*PALLOCATE_ADAPTER_CHANNEL)(
  13731. IN PDMA_ADAPTER DmaAdapter,
  13732. IN PDEVICE_OBJECT DeviceObject,
  13733. IN ULONG NumberOfMapRegisters,
  13734. IN PDRIVER_CONTROL ExecutionRoutine,
  13735. IN PVOID Context
  13736. );
  13737. typedef BOOLEAN (*PFLUSH_ADAPTER_BUFFERS)(
  13738. IN PDMA_ADAPTER DmaAdapter,
  13739. IN PMDL Mdl,
  13740. IN PVOID MapRegisterBase,
  13741. IN PVOID CurrentVa,
  13742. IN ULONG Length,
  13743. IN BOOLEAN WriteToDevice
  13744. );
  13745. typedef VOID (*PFREE_ADAPTER_CHANNEL)(
  13746. IN PDMA_ADAPTER DmaAdapter
  13747. );
  13748. typedef VOID (*PFREE_MAP_REGISTERS)(
  13749. IN PDMA_ADAPTER DmaAdapter,
  13750. PVOID MapRegisterBase,
  13751. ULONG NumberOfMapRegisters
  13752. );
  13753. typedef PHYSICAL_ADDRESS (*PMAP_TRANSFER)(
  13754. IN PDMA_ADAPTER DmaAdapter,
  13755. IN PMDL Mdl,
  13756. IN PVOID MapRegisterBase,
  13757. IN PVOID CurrentVa,
  13758. IN OUT PULONG Length,
  13759. IN BOOLEAN WriteToDevice
  13760. );
  13761. typedef ULONG (*PGET_DMA_ALIGNMENT)(
  13762. IN PDMA_ADAPTER DmaAdapter
  13763. );
  13764. typedef ULONG (*PREAD_DMA_COUNTER)(
  13765. IN PDMA_ADAPTER DmaAdapter
  13766. );
  13767. typedef VOID
  13768. (*PDRIVER_LIST_CONTROL)(
  13769. IN struct _DEVICE_OBJECT *DeviceObject,
  13770. IN struct _IRP *Irp,
  13771. IN PSCATTER_GATHER_LIST ScatterGather,
  13772. IN PVOID Context
  13773. );
  13774. typedef NTSTATUS
  13775. (*PGET_SCATTER_GATHER_LIST)(
  13776. IN PDMA_ADAPTER DmaAdapter,
  13777. IN PDEVICE_OBJECT DeviceObject,
  13778. IN PMDL Mdl,
  13779. IN PVOID CurrentVa,
  13780. IN ULONG Length,
  13781. IN PDRIVER_LIST_CONTROL ExecutionRoutine,
  13782. IN PVOID Context,
  13783. IN BOOLEAN WriteToDevice
  13784. );
  13785. typedef VOID
  13786. (*PPUT_SCATTER_GATHER_LIST)(
  13787. IN PDMA_ADAPTER DmaAdapter,
  13788. IN PSCATTER_GATHER_LIST ScatterGather,
  13789. IN BOOLEAN WriteToDevice
  13790. );
  13791. typedef NTSTATUS
  13792. (*PCALCULATE_SCATTER_GATHER_LIST_SIZE)(
  13793. IN PDMA_ADAPTER DmaAdapter,
  13794. IN OPTIONAL PMDL Mdl,
  13795. IN PVOID CurrentVa,
  13796. IN ULONG Length,
  13797. OUT PULONG ScatterGatherListSize,
  13798. OUT OPTIONAL PULONG pNumberOfMapRegisters
  13799. );
  13800. typedef NTSTATUS
  13801. (*PBUILD_SCATTER_GATHER_LIST)(
  13802. IN PDMA_ADAPTER DmaAdapter,
  13803. IN PDEVICE_OBJECT DeviceObject,
  13804. IN PMDL Mdl,
  13805. IN PVOID CurrentVa,
  13806. IN ULONG Length,
  13807. IN PDRIVER_LIST_CONTROL ExecutionRoutine,
  13808. IN PVOID Context,
  13809. IN BOOLEAN WriteToDevice,
  13810. IN PVOID ScatterGatherBuffer,
  13811. IN ULONG ScatterGatherLength
  13812. );
  13813. typedef NTSTATUS
  13814. (*PBUILD_MDL_FROM_SCATTER_GATHER_LIST)(
  13815. IN PDMA_ADAPTER DmaAdapter,
  13816. IN PSCATTER_GATHER_LIST ScatterGather,
  13817. IN PMDL OriginalMdl,
  13818. OUT PMDL *TargetMdl
  13819. );
  13820. typedef struct _DMA_OPERATIONS {
  13821. ULONG Size;
  13822. PPUT_DMA_ADAPTER PutDmaAdapter;
  13823. PALLOCATE_COMMON_BUFFER AllocateCommonBuffer;
  13824. PFREE_COMMON_BUFFER FreeCommonBuffer;
  13825. PALLOCATE_ADAPTER_CHANNEL AllocateAdapterChannel;
  13826. PFLUSH_ADAPTER_BUFFERS FlushAdapterBuffers;
  13827. PFREE_ADAPTER_CHANNEL FreeAdapterChannel;
  13828. PFREE_MAP_REGISTERS FreeMapRegisters;
  13829. PMAP_TRANSFER MapTransfer;
  13830. PGET_DMA_ALIGNMENT GetDmaAlignment;
  13831. PREAD_DMA_COUNTER ReadDmaCounter;
  13832. PGET_SCATTER_GATHER_LIST GetScatterGatherList;
  13833. PPUT_SCATTER_GATHER_LIST PutScatterGatherList;
  13834. PCALCULATE_SCATTER_GATHER_LIST_SIZE CalculateScatterGatherList;
  13835. PBUILD_SCATTER_GATHER_LIST BuildScatterGatherList;
  13836. PBUILD_MDL_FROM_SCATTER_GATHER_LIST BuildMdlFromScatterGatherList;
  13837. } DMA_OPERATIONS;
  13838. // end_wdm
  13839. #if defined(_WIN64)
  13840. //
  13841. // Use __inline DMA macros (hal.h)
  13842. //
  13843. #ifndef USE_DMA_MACROS
  13844. #define USE_DMA_MACROS
  13845. #endif
  13846. //
  13847. // Only PnP drivers!
  13848. //
  13849. #ifndef NO_LEGACY_DRIVERS
  13850. #define NO_LEGACY_DRIVERS
  13851. #endif
  13852. #endif // _WIN64
  13853. #if defined(USE_DMA_MACROS) && (defined(_NTDDK_) || defined(_NTDRIVER_))
  13854. // begin_wdm
  13855. DECLSPEC_DEPRECATED_DDK // Use AllocateCommonBuffer
  13856. FORCEINLINE
  13857. PVOID
  13858. HalAllocateCommonBuffer(
  13859. IN PDMA_ADAPTER DmaAdapter,
  13860. IN ULONG Length,
  13861. OUT PPHYSICAL_ADDRESS LogicalAddress,
  13862. IN BOOLEAN CacheEnabled
  13863. ){
  13864. PALLOCATE_COMMON_BUFFER allocateCommonBuffer;
  13865. PVOID commonBuffer;
  13866. allocateCommonBuffer = *(DmaAdapter)->DmaOperations->AllocateCommonBuffer;
  13867. ASSERT( allocateCommonBuffer != NULL );
  13868. commonBuffer = allocateCommonBuffer( DmaAdapter,
  13869. Length,
  13870. LogicalAddress,
  13871. CacheEnabled );
  13872. return commonBuffer;
  13873. }
  13874. DECLSPEC_DEPRECATED_DDK // Use FreeCommonBuffer
  13875. FORCEINLINE
  13876. VOID
  13877. HalFreeCommonBuffer(
  13878. IN PDMA_ADAPTER DmaAdapter,
  13879. IN ULONG Length,
  13880. IN PHYSICAL_ADDRESS LogicalAddress,
  13881. IN PVOID VirtualAddress,
  13882. IN BOOLEAN CacheEnabled
  13883. ){
  13884. PFREE_COMMON_BUFFER freeCommonBuffer;
  13885. freeCommonBuffer = *(DmaAdapter)->DmaOperations->FreeCommonBuffer;
  13886. ASSERT( freeCommonBuffer != NULL );
  13887. freeCommonBuffer( DmaAdapter,
  13888. Length,
  13889. LogicalAddress,
  13890. VirtualAddress,
  13891. CacheEnabled );
  13892. }
  13893. DECLSPEC_DEPRECATED_DDK // Use AllocateAdapterChannel
  13894. FORCEINLINE
  13895. NTSTATUS
  13896. IoAllocateAdapterChannel(
  13897. IN PDMA_ADAPTER DmaAdapter,
  13898. IN PDEVICE_OBJECT DeviceObject,
  13899. IN ULONG NumberOfMapRegisters,
  13900. IN PDRIVER_CONTROL ExecutionRoutine,
  13901. IN PVOID Context
  13902. ){
  13903. PALLOCATE_ADAPTER_CHANNEL allocateAdapterChannel;
  13904. NTSTATUS status;
  13905. allocateAdapterChannel =
  13906. *(DmaAdapter)->DmaOperations->AllocateAdapterChannel;
  13907. ASSERT( allocateAdapterChannel != NULL );
  13908. status = allocateAdapterChannel( DmaAdapter,
  13909. DeviceObject,
  13910. NumberOfMapRegisters,
  13911. ExecutionRoutine,
  13912. Context );
  13913. return status;
  13914. }
  13915. DECLSPEC_DEPRECATED_DDK // Use FlushAdapterBuffers
  13916. FORCEINLINE
  13917. BOOLEAN
  13918. IoFlushAdapterBuffers(
  13919. IN PDMA_ADAPTER DmaAdapter,
  13920. IN PMDL Mdl,
  13921. IN PVOID MapRegisterBase,
  13922. IN PVOID CurrentVa,
  13923. IN ULONG Length,
  13924. IN BOOLEAN WriteToDevice
  13925. ){
  13926. PFLUSH_ADAPTER_BUFFERS flushAdapterBuffers;
  13927. BOOLEAN result;
  13928. flushAdapterBuffers = *(DmaAdapter)->DmaOperations->FlushAdapterBuffers;
  13929. ASSERT( flushAdapterBuffers != NULL );
  13930. result = flushAdapterBuffers( DmaAdapter,
  13931. Mdl,
  13932. MapRegisterBase,
  13933. CurrentVa,
  13934. Length,
  13935. WriteToDevice );
  13936. return result;
  13937. }
  13938. DECLSPEC_DEPRECATED_DDK // Use FreeAdapterChannel
  13939. FORCEINLINE
  13940. VOID
  13941. IoFreeAdapterChannel(
  13942. IN PDMA_ADAPTER DmaAdapter
  13943. ){
  13944. PFREE_ADAPTER_CHANNEL freeAdapterChannel;
  13945. freeAdapterChannel = *(DmaAdapter)->DmaOperations->FreeAdapterChannel;
  13946. ASSERT( freeAdapterChannel != NULL );
  13947. freeAdapterChannel( DmaAdapter );
  13948. }
  13949. DECLSPEC_DEPRECATED_DDK // Use FreeMapRegisters
  13950. FORCEINLINE
  13951. VOID
  13952. IoFreeMapRegisters(
  13953. IN PDMA_ADAPTER DmaAdapter,
  13954. IN PVOID MapRegisterBase,
  13955. IN ULONG NumberOfMapRegisters
  13956. ){
  13957. PFREE_MAP_REGISTERS freeMapRegisters;
  13958. freeMapRegisters = *(DmaAdapter)->DmaOperations->FreeMapRegisters;
  13959. ASSERT( freeMapRegisters != NULL );
  13960. freeMapRegisters( DmaAdapter,
  13961. MapRegisterBase,
  13962. NumberOfMapRegisters );
  13963. }
  13964. DECLSPEC_DEPRECATED_DDK // Use MapTransfer
  13965. FORCEINLINE
  13966. PHYSICAL_ADDRESS
  13967. IoMapTransfer(
  13968. IN PDMA_ADAPTER DmaAdapter,
  13969. IN PMDL Mdl,
  13970. IN PVOID MapRegisterBase,
  13971. IN PVOID CurrentVa,
  13972. IN OUT PULONG Length,
  13973. IN BOOLEAN WriteToDevice
  13974. ){
  13975. PHYSICAL_ADDRESS physicalAddress;
  13976. PMAP_TRANSFER mapTransfer;
  13977. mapTransfer = *(DmaAdapter)->DmaOperations->MapTransfer;
  13978. ASSERT( mapTransfer != NULL );
  13979. physicalAddress = mapTransfer( DmaAdapter,
  13980. Mdl,
  13981. MapRegisterBase,
  13982. CurrentVa,
  13983. Length,
  13984. WriteToDevice );
  13985. return physicalAddress;
  13986. }
  13987. DECLSPEC_DEPRECATED_DDK // Use GetDmaAlignment
  13988. FORCEINLINE
  13989. ULONG
  13990. HalGetDmaAlignment(
  13991. IN PDMA_ADAPTER DmaAdapter
  13992. )
  13993. {
  13994. PGET_DMA_ALIGNMENT getDmaAlignment;
  13995. ULONG alignment;
  13996. getDmaAlignment = *(DmaAdapter)->DmaOperations->GetDmaAlignment;
  13997. ASSERT( getDmaAlignment != NULL );
  13998. alignment = getDmaAlignment( DmaAdapter );
  13999. return alignment;
  14000. }
  14001. DECLSPEC_DEPRECATED_DDK // Use ReadDmaCounter
  14002. FORCEINLINE
  14003. ULONG
  14004. HalReadDmaCounter(
  14005. IN PDMA_ADAPTER DmaAdapter
  14006. )
  14007. {
  14008. PREAD_DMA_COUNTER readDmaCounter;
  14009. ULONG counter;
  14010. readDmaCounter = *(DmaAdapter)->DmaOperations->ReadDmaCounter;
  14011. ASSERT( readDmaCounter != NULL );
  14012. counter = readDmaCounter( DmaAdapter );
  14013. return counter;
  14014. }
  14015. // end_wdm
  14016. #else
  14017. //
  14018. // DMA adapter object functions.
  14019. //
  14020. DECLSPEC_DEPRECATED_DDK // Use AllocateAdapterChannel
  14021. NTHALAPI
  14022. NTSTATUS
  14023. HalAllocateAdapterChannel(
  14024. IN PADAPTER_OBJECT AdapterObject,
  14025. IN PWAIT_CONTEXT_BLOCK Wcb,
  14026. IN ULONG NumberOfMapRegisters,
  14027. IN PDRIVER_CONTROL ExecutionRoutine
  14028. );
  14029. DECLSPEC_DEPRECATED_DDK // Use AllocateCommonBuffer
  14030. NTHALAPI
  14031. PVOID
  14032. HalAllocateCommonBuffer(
  14033. IN PADAPTER_OBJECT AdapterObject,
  14034. IN ULONG Length,
  14035. OUT PPHYSICAL_ADDRESS LogicalAddress,
  14036. IN BOOLEAN CacheEnabled
  14037. );
  14038. DECLSPEC_DEPRECATED_DDK // Use FreeCommonBuffer
  14039. NTHALAPI
  14040. VOID
  14041. HalFreeCommonBuffer(
  14042. IN PADAPTER_OBJECT AdapterObject,
  14043. IN ULONG Length,
  14044. IN PHYSICAL_ADDRESS LogicalAddress,
  14045. IN PVOID VirtualAddress,
  14046. IN BOOLEAN CacheEnabled
  14047. );
  14048. DECLSPEC_DEPRECATED_DDK // Use ReadDmaCounter
  14049. NTHALAPI
  14050. ULONG
  14051. HalReadDmaCounter(
  14052. IN PADAPTER_OBJECT AdapterObject
  14053. );
  14054. DECLSPEC_DEPRECATED_DDK // Use FlushAdapterBuffers
  14055. NTHALAPI
  14056. BOOLEAN
  14057. IoFlushAdapterBuffers(
  14058. IN PADAPTER_OBJECT AdapterObject,
  14059. IN PMDL Mdl,
  14060. IN PVOID MapRegisterBase,
  14061. IN PVOID CurrentVa,
  14062. IN ULONG Length,
  14063. IN BOOLEAN WriteToDevice
  14064. );
  14065. DECLSPEC_DEPRECATED_DDK // Use FreeAdapterChannel
  14066. NTHALAPI
  14067. VOID
  14068. IoFreeAdapterChannel(
  14069. IN PADAPTER_OBJECT AdapterObject
  14070. );
  14071. DECLSPEC_DEPRECATED_DDK // Use FreeMapRegisters
  14072. NTHALAPI
  14073. VOID
  14074. IoFreeMapRegisters(
  14075. IN PADAPTER_OBJECT AdapterObject,
  14076. IN PVOID MapRegisterBase,
  14077. IN ULONG NumberOfMapRegisters
  14078. );
  14079. DECLSPEC_DEPRECATED_DDK // Use MapTransfer
  14080. NTHALAPI
  14081. PHYSICAL_ADDRESS
  14082. IoMapTransfer(
  14083. IN PADAPTER_OBJECT AdapterObject,
  14084. IN PMDL Mdl,
  14085. IN PVOID MapRegisterBase,
  14086. IN PVOID CurrentVa,
  14087. IN OUT PULONG Length,
  14088. IN BOOLEAN WriteToDevice
  14089. );
  14090. #endif // USE_DMA_MACROS && (_NTDDK_ || _NTDRIVER_)
  14091. DECLSPEC_DEPRECATED_DDK
  14092. NTSTATUS
  14093. HalGetScatterGatherList ( // Use GetScatterGatherList
  14094. IN PADAPTER_OBJECT DmaAdapter,
  14095. IN PDEVICE_OBJECT DeviceObject,
  14096. IN PMDL Mdl,
  14097. IN PVOID CurrentVa,
  14098. IN ULONG Length,
  14099. IN PDRIVER_LIST_CONTROL ExecutionRoutine,
  14100. IN PVOID Context,
  14101. IN BOOLEAN WriteToDevice
  14102. );
  14103. DECLSPEC_DEPRECATED_DDK // Use PutScatterGatherList
  14104. VOID
  14105. HalPutScatterGatherList (
  14106. IN PADAPTER_OBJECT DmaAdapter,
  14107. IN PSCATTER_GATHER_LIST ScatterGather,
  14108. IN BOOLEAN WriteToDevice
  14109. );
  14110. DECLSPEC_DEPRECATED_DDK // Use PutDmaAdapter
  14111. VOID
  14112. HalPutDmaAdapter(
  14113. IN PADAPTER_OBJECT DmaAdapter
  14114. );
  14115. //
  14116. // Define maximum disk transfer size to be used by MM and Cache Manager,
  14117. // so that packet-oriented disk drivers can optimize their packet allocation
  14118. // to this size.
  14119. //
  14120. #define MM_MAXIMUM_DISK_IO_SIZE (0x10000)
  14121. //++
  14122. //
  14123. // ULONG_PTR
  14124. // ROUND_TO_PAGES (
  14125. // IN ULONG_PTR Size
  14126. // )
  14127. //
  14128. // Routine Description:
  14129. //
  14130. // The ROUND_TO_PAGES macro takes a size in bytes and rounds it up to a
  14131. // multiple of the page size.
  14132. //
  14133. // NOTE: This macro fails for values 0xFFFFFFFF - (PAGE_SIZE - 1).
  14134. //
  14135. // Arguments:
  14136. //
  14137. // Size - Size in bytes to round up to a page multiple.
  14138. //
  14139. // Return Value:
  14140. //
  14141. // Returns the size rounded up to a multiple of the page size.
  14142. //
  14143. //--
  14144. #define ROUND_TO_PAGES(Size) (((ULONG_PTR)(Size) + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1))
  14145. //++
  14146. //
  14147. // ULONG
  14148. // BYTES_TO_PAGES (
  14149. // IN ULONG Size
  14150. // )
  14151. //
  14152. // Routine Description:
  14153. //
  14154. // The BYTES_TO_PAGES macro takes the size in bytes and calculates the
  14155. // number of pages required to contain the bytes.
  14156. //
  14157. // Arguments:
  14158. //
  14159. // Size - Size in bytes.
  14160. //
  14161. // Return Value:
  14162. //
  14163. // Returns the number of pages required to contain the specified size.
  14164. //
  14165. //--
  14166. #define BYTES_TO_PAGES(Size) (((Size) >> PAGE_SHIFT) + \
  14167. (((Size) & (PAGE_SIZE - 1)) != 0))
  14168. //++
  14169. //
  14170. // ULONG
  14171. // BYTE_OFFSET (
  14172. // IN PVOID Va
  14173. // )
  14174. //
  14175. // Routine Description:
  14176. //
  14177. // The BYTE_OFFSET macro takes a virtual address and returns the byte offset
  14178. // of that address within the page.
  14179. //
  14180. // Arguments:
  14181. //
  14182. // Va - Virtual address.
  14183. //
  14184. // Return Value:
  14185. //
  14186. // Returns the byte offset portion of the virtual address.
  14187. //
  14188. //--
  14189. #define BYTE_OFFSET(Va) ((ULONG)((LONG_PTR)(Va) & (PAGE_SIZE - 1)))
  14190. //++
  14191. //
  14192. // PVOID
  14193. // PAGE_ALIGN (
  14194. // IN PVOID Va
  14195. // )
  14196. //
  14197. // Routine Description:
  14198. //
  14199. // The PAGE_ALIGN macro takes a virtual address and returns a page-aligned
  14200. // virtual address for that page.
  14201. //
  14202. // Arguments:
  14203. //
  14204. // Va - Virtual address.
  14205. //
  14206. // Return Value:
  14207. //
  14208. // Returns the page aligned virtual address.
  14209. //
  14210. //--
  14211. #define PAGE_ALIGN(Va) ((PVOID)((ULONG_PTR)(Va) & ~(PAGE_SIZE - 1)))
  14212. //++
  14213. //
  14214. // ULONG
  14215. // ADDRESS_AND_SIZE_TO_SPAN_PAGES (
  14216. // IN PVOID Va,
  14217. // IN ULONG Size
  14218. // )
  14219. //
  14220. // Routine Description:
  14221. //
  14222. // The ADDRESS_AND_SIZE_TO_SPAN_PAGES macro takes a virtual address and
  14223. // size and returns the number of pages spanned by the size.
  14224. //
  14225. // Arguments:
  14226. //
  14227. // Va - Virtual address.
  14228. //
  14229. // Size - Size in bytes.
  14230. //
  14231. // Return Value:
  14232. //
  14233. // Returns the number of pages spanned by the size.
  14234. //
  14235. //--
  14236. #define ADDRESS_AND_SIZE_TO_SPAN_PAGES(Va,Size) \
  14237. ((ULONG)((((ULONG_PTR)(Va) & (PAGE_SIZE -1)) + (Size) + (PAGE_SIZE - 1)) >> PAGE_SHIFT))
  14238. #if PRAGMA_DEPRECATED_DDK
  14239. #pragma deprecated(COMPUTE_PAGES_SPANNED) // Use ADDRESS_AND_SIZE_TO_SPAN_PAGES
  14240. #endif
  14241. #define COMPUTE_PAGES_SPANNED(Va, Size) ADDRESS_AND_SIZE_TO_SPAN_PAGES(Va,Size)
  14242. #define IS_SYSTEM_ADDRESS(VA) ((VA) >= MM_SYSTEM_RANGE_START)
  14243. //++
  14244. // PPFN_NUMBER
  14245. // MmGetMdlPfnArray (
  14246. // IN PMDL Mdl
  14247. // )
  14248. //
  14249. // Routine Description:
  14250. //
  14251. // The MmGetMdlPfnArray routine returns the virtual address of the
  14252. // first element of the array of physical page numbers associated with
  14253. // the MDL.
  14254. //
  14255. // Arguments:
  14256. //
  14257. // Mdl - Pointer to an MDL.
  14258. //
  14259. // Return Value:
  14260. //
  14261. // Returns the virtual address of the first element of the array of
  14262. // physical page numbers associated with the MDL.
  14263. //
  14264. //--
  14265. #define MmGetMdlPfnArray(Mdl) ((PPFN_NUMBER)(Mdl + 1))
  14266. //++
  14267. //
  14268. // PVOID
  14269. // MmGetMdlVirtualAddress (
  14270. // IN PMDL Mdl
  14271. // )
  14272. //
  14273. // Routine Description:
  14274. //
  14275. // The MmGetMdlVirtualAddress returns the virtual address of the buffer
  14276. // described by the Mdl.
  14277. //
  14278. // Arguments:
  14279. //
  14280. // Mdl - Pointer to an MDL.
  14281. //
  14282. // Return Value:
  14283. //
  14284. // Returns the virtual address of the buffer described by the Mdl
  14285. //
  14286. //--
  14287. #define MmGetMdlVirtualAddress(Mdl) \
  14288. ((PVOID) ((PCHAR) ((Mdl)->StartVa) + (Mdl)->ByteOffset))
  14289. //++
  14290. //
  14291. // ULONG
  14292. // MmGetMdlByteCount (
  14293. // IN PMDL Mdl
  14294. // )
  14295. //
  14296. // Routine Description:
  14297. //
  14298. // The MmGetMdlByteCount returns the length in bytes of the buffer
  14299. // described by the Mdl.
  14300. //
  14301. // Arguments:
  14302. //
  14303. // Mdl - Pointer to an MDL.
  14304. //
  14305. // Return Value:
  14306. //
  14307. // Returns the byte count of the buffer described by the Mdl
  14308. //
  14309. //--
  14310. #define MmGetMdlByteCount(Mdl) ((Mdl)->ByteCount)
  14311. //++
  14312. //
  14313. // ULONG
  14314. // MmGetMdlByteOffset (
  14315. // IN PMDL Mdl
  14316. // )
  14317. //
  14318. // Routine Description:
  14319. //
  14320. // The MmGetMdlByteOffset returns the byte offset within the page
  14321. // of the buffer described by the Mdl.
  14322. //
  14323. // Arguments:
  14324. //
  14325. // Mdl - Pointer to an MDL.
  14326. //
  14327. // Return Value:
  14328. //
  14329. // Returns the byte offset within the page of the buffer described by the Mdl
  14330. //
  14331. //--
  14332. #define MmGetMdlByteOffset(Mdl) ((Mdl)->ByteOffset)
  14333. //++
  14334. //
  14335. // PVOID
  14336. // MmGetMdlStartVa (
  14337. // IN PMDL Mdl
  14338. // )
  14339. //
  14340. // Routine Description:
  14341. //
  14342. // The MmGetMdlBaseVa returns the virtual address of the buffer
  14343. // described by the Mdl rounded down to the nearest page.
  14344. //
  14345. // Arguments:
  14346. //
  14347. // Mdl - Pointer to an MDL.
  14348. //
  14349. // Return Value:
  14350. //
  14351. // Returns the returns the starting virtual address of the MDL.
  14352. //
  14353. //
  14354. //--
  14355. #define MmGetMdlBaseVa(Mdl) ((Mdl)->StartVa)
  14356. typedef enum _MM_SYSTEM_SIZE {
  14357. MmSmallSystem,
  14358. MmMediumSystem,
  14359. MmLargeSystem
  14360. } MM_SYSTEMSIZE;
  14361. NTKERNELAPI
  14362. MM_SYSTEMSIZE
  14363. MmQuerySystemSize (
  14364. VOID
  14365. );
  14366. // end_wdm
  14367. NTKERNELAPI
  14368. BOOLEAN
  14369. MmIsThisAnNtAsSystem (
  14370. VOID
  14371. );
  14372. NTKERNELAPI
  14373. NTSTATUS
  14374. MmGrowKernelStack (
  14375. IN PVOID CurrentStack
  14376. );
  14377. NTKERNELAPI
  14378. NTSTATUS
  14379. MmAdjustWorkingSetSize (
  14380. IN SIZE_T WorkingSetMinimum,
  14381. IN SIZE_T WorkingSetMaximum,
  14382. IN ULONG SystemCache,
  14383. IN BOOLEAN IncreaseOkay
  14384. );
  14385. NTKERNELAPI
  14386. NTSTATUS
  14387. MmCreateSection (
  14388. OUT PVOID *SectionObject,
  14389. IN ACCESS_MASK DesiredAccess,
  14390. IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL,
  14391. IN PLARGE_INTEGER MaximumSize,
  14392. IN ULONG SectionPageProtection,
  14393. IN ULONG AllocationAttributes,
  14394. IN HANDLE FileHandle OPTIONAL,
  14395. IN PFILE_OBJECT File OPTIONAL
  14396. );
  14397. NTKERNELAPI
  14398. NTSTATUS
  14399. MmMapViewOfSection (
  14400. IN PVOID SectionToMap,
  14401. IN PEPROCESS Process,
  14402. IN OUT PVOID *CapturedBase,
  14403. IN ULONG_PTR ZeroBits,
  14404. IN SIZE_T CommitSize,
  14405. IN OUT PLARGE_INTEGER SectionOffset,
  14406. IN OUT PSIZE_T CapturedViewSize,
  14407. IN SECTION_INHERIT InheritDisposition,
  14408. IN ULONG AllocationType,
  14409. IN ULONG Protect
  14410. );
  14411. NTKERNELAPI
  14412. NTSTATUS
  14413. MmUnmapViewOfSection (
  14414. IN PEPROCESS Process,
  14415. IN PVOID BaseAddress
  14416. );
  14417. NTSTATUS
  14418. MmIsVerifierEnabled (
  14419. OUT PULONG VerifierFlags
  14420. );
  14421. NTSTATUS
  14422. MmAddVerifierThunks (
  14423. IN PVOID ThunkBuffer,
  14424. IN ULONG ThunkBufferSize
  14425. );
  14426. NTKERNELAPI
  14427. VOID
  14428. MmProbeAndLockProcessPages (
  14429. IN OUT PMDL MemoryDescriptorList,
  14430. IN PEPROCESS Process,
  14431. IN KPROCESSOR_MODE AccessMode,
  14432. IN LOCK_OPERATION Operation
  14433. );
  14434. // begin_nthal
  14435. //
  14436. // I/O support routines.
  14437. //
  14438. NTKERNELAPI
  14439. VOID
  14440. MmProbeAndLockPages (
  14441. IN OUT PMDL MemoryDescriptorList,
  14442. IN KPROCESSOR_MODE AccessMode,
  14443. IN LOCK_OPERATION Operation
  14444. );
  14445. NTKERNELAPI
  14446. VOID
  14447. MmUnlockPages (
  14448. IN PMDL MemoryDescriptorList
  14449. );
  14450. NTKERNELAPI
  14451. VOID
  14452. MmBuildMdlForNonPagedPool (
  14453. IN OUT PMDL MemoryDescriptorList
  14454. );
  14455. NTKERNELAPI
  14456. PVOID
  14457. MmMapLockedPages (
  14458. IN PMDL MemoryDescriptorList,
  14459. IN KPROCESSOR_MODE AccessMode
  14460. );
  14461. LOGICAL
  14462. MmIsIoSpaceActive (
  14463. IN PHYSICAL_ADDRESS StartAddress,
  14464. IN SIZE_T NumberOfBytes
  14465. );
  14466. NTKERNELAPI
  14467. PVOID
  14468. MmGetSystemRoutineAddress (
  14469. IN PUNICODE_STRING SystemRoutineName
  14470. );
  14471. NTKERNELAPI
  14472. NTSTATUS
  14473. MmAdvanceMdl (
  14474. IN PMDL Mdl,
  14475. IN ULONG NumberOfBytes
  14476. );
  14477. // end_wdm
  14478. NTKERNELAPI
  14479. NTSTATUS
  14480. MmMapUserAddressesToPage (
  14481. IN PVOID BaseAddress,
  14482. IN SIZE_T NumberOfBytes,
  14483. IN PVOID PageAddress
  14484. );
  14485. // begin_wdm
  14486. NTKERNELAPI
  14487. NTSTATUS
  14488. MmProtectMdlSystemAddress (
  14489. IN PMDL MemoryDescriptorList,
  14490. IN ULONG NewProtect
  14491. );
  14492. //
  14493. // _MM_PAGE_PRIORITY_ provides a method for the system to handle requests
  14494. // intelligently in low resource conditions.
  14495. //
  14496. // LowPagePriority should be used when it is acceptable to the driver for the
  14497. // mapping request to fail if the system is low on resources. An example of
  14498. // this could be for a non-critical network connection where the driver can
  14499. // handle the failure case when system resources are close to being depleted.
  14500. //
  14501. // NormalPagePriority should be used when it is acceptable to the driver for the
  14502. // mapping request to fail if the system is very low on resources. An example
  14503. // of this could be for a non-critical local filesystem request.
  14504. //
  14505. // HighPagePriority should be used when it is unacceptable to the driver for the
  14506. // mapping request to fail unless the system is completely out of resources.
  14507. // An example of this would be the paging file path in a driver.
  14508. //
  14509. // begin_ntndis
  14510. typedef enum _MM_PAGE_PRIORITY {
  14511. LowPagePriority,
  14512. NormalPagePriority = 16,
  14513. HighPagePriority = 32
  14514. } MM_PAGE_PRIORITY;
  14515. // end_ntndis
  14516. //
  14517. // Note: This function is not available in WDM 1.0
  14518. //
  14519. NTKERNELAPI
  14520. PVOID
  14521. MmMapLockedPagesSpecifyCache (
  14522. IN PMDL MemoryDescriptorList,
  14523. IN KPROCESSOR_MODE AccessMode,
  14524. IN MEMORY_CACHING_TYPE CacheType,
  14525. IN PVOID BaseAddress,
  14526. IN ULONG BugCheckOnFailure,
  14527. IN MM_PAGE_PRIORITY Priority
  14528. );
  14529. NTKERNELAPI
  14530. VOID
  14531. MmUnmapLockedPages (
  14532. IN PVOID BaseAddress,
  14533. IN PMDL MemoryDescriptorList
  14534. );
  14535. PVOID
  14536. MmAllocateMappingAddress (
  14537. IN SIZE_T NumberOfBytes,
  14538. IN ULONG PoolTag
  14539. );
  14540. VOID
  14541. MmFreeMappingAddress (
  14542. IN PVOID BaseAddress,
  14543. IN ULONG PoolTag
  14544. );
  14545. PVOID
  14546. MmMapLockedPagesWithReservedMapping (
  14547. IN PVOID MappingAddress,
  14548. IN ULONG PoolTag,
  14549. IN PMDL MemoryDescriptorList,
  14550. IN MEMORY_CACHING_TYPE CacheType
  14551. );
  14552. VOID
  14553. MmUnmapReservedMapping (
  14554. IN PVOID BaseAddress,
  14555. IN ULONG PoolTag,
  14556. IN PMDL MemoryDescriptorList
  14557. );
  14558. // end_wdm
  14559. typedef struct _PHYSICAL_MEMORY_RANGE {
  14560. PHYSICAL_ADDRESS BaseAddress;
  14561. LARGE_INTEGER NumberOfBytes;
  14562. } PHYSICAL_MEMORY_RANGE, *PPHYSICAL_MEMORY_RANGE;
  14563. NTKERNELAPI
  14564. NTSTATUS
  14565. MmAddPhysicalMemory (
  14566. IN PPHYSICAL_ADDRESS StartAddress,
  14567. IN OUT PLARGE_INTEGER NumberOfBytes
  14568. );
  14569. // end_ntddk end_nthal end_ntifs
  14570. NTKERNELAPI
  14571. NTSTATUS
  14572. MmAddPhysicalMemoryEx (
  14573. IN PPHYSICAL_ADDRESS StartAddress,
  14574. IN OUT PLARGE_INTEGER NumberOfBytes,
  14575. IN ULONG Flags
  14576. );
  14577. // begin_ntddk begin_nthal begin_ntifs
  14578. NTKERNELAPI
  14579. NTSTATUS
  14580. MmRemovePhysicalMemory (
  14581. IN PPHYSICAL_ADDRESS StartAddress,
  14582. IN OUT PLARGE_INTEGER NumberOfBytes
  14583. );
  14584. // end_ntddk end_nthal end_ntifs
  14585. NTKERNELAPI
  14586. NTSTATUS
  14587. MmRemovePhysicalMemoryEx (
  14588. IN PPHYSICAL_ADDRESS StartAddress,
  14589. IN OUT PLARGE_INTEGER NumberOfBytes,
  14590. IN ULONG Flags
  14591. );
  14592. // begin_ntddk begin_nthal begin_ntifs
  14593. NTKERNELAPI
  14594. PPHYSICAL_MEMORY_RANGE
  14595. MmGetPhysicalMemoryRanges (
  14596. VOID
  14597. );
  14598. // end_ntddk end_ntifs
  14599. NTSTATUS
  14600. MmMarkPhysicalMemoryAsGood (
  14601. IN PPHYSICAL_ADDRESS StartAddress,
  14602. IN OUT PLARGE_INTEGER NumberOfBytes
  14603. );
  14604. NTSTATUS
  14605. MmMarkPhysicalMemoryAsBad (
  14606. IN PPHYSICAL_ADDRESS StartAddress,
  14607. IN OUT PLARGE_INTEGER NumberOfBytes
  14608. );
  14609. // begin_wdm begin_ntddk begin_ntifs
  14610. NTKERNELAPI
  14611. PMDL
  14612. MmAllocatePagesForMdl (
  14613. IN PHYSICAL_ADDRESS LowAddress,
  14614. IN PHYSICAL_ADDRESS HighAddress,
  14615. IN PHYSICAL_ADDRESS SkipBytes,
  14616. IN SIZE_T TotalBytes
  14617. );
  14618. NTKERNELAPI
  14619. VOID
  14620. MmFreePagesFromMdl (
  14621. IN PMDL MemoryDescriptorList
  14622. );
  14623. NTKERNELAPI
  14624. PVOID
  14625. MmMapIoSpace (
  14626. IN PHYSICAL_ADDRESS PhysicalAddress,
  14627. IN SIZE_T NumberOfBytes,
  14628. IN MEMORY_CACHING_TYPE CacheType
  14629. );
  14630. NTKERNELAPI
  14631. VOID
  14632. MmUnmapIoSpace (
  14633. IN PVOID BaseAddress,
  14634. IN SIZE_T NumberOfBytes
  14635. );
  14636. NTKERNELAPI
  14637. PVOID
  14638. MmMapVideoDisplay (
  14639. IN PHYSICAL_ADDRESS PhysicalAddress,
  14640. IN SIZE_T NumberOfBytes,
  14641. IN MEMORY_CACHING_TYPE CacheType
  14642. );
  14643. NTKERNELAPI
  14644. VOID
  14645. MmUnmapVideoDisplay (
  14646. IN PVOID BaseAddress,
  14647. IN SIZE_T NumberOfBytes
  14648. );
  14649. NTKERNELAPI
  14650. PHYSICAL_ADDRESS
  14651. MmGetPhysicalAddress (
  14652. IN PVOID BaseAddress
  14653. );
  14654. NTKERNELAPI
  14655. PVOID
  14656. MmGetVirtualForPhysical (
  14657. IN PHYSICAL_ADDRESS PhysicalAddress
  14658. );
  14659. NTKERNELAPI
  14660. PVOID
  14661. MmAllocateContiguousMemory (
  14662. IN SIZE_T NumberOfBytes,
  14663. IN PHYSICAL_ADDRESS HighestAcceptableAddress
  14664. );
  14665. NTKERNELAPI
  14666. PVOID
  14667. MmAllocateContiguousMemorySpecifyCache (
  14668. IN SIZE_T NumberOfBytes,
  14669. IN PHYSICAL_ADDRESS LowestAcceptableAddress,
  14670. IN PHYSICAL_ADDRESS HighestAcceptableAddress,
  14671. IN PHYSICAL_ADDRESS BoundaryAddressMultiple OPTIONAL,
  14672. IN MEMORY_CACHING_TYPE CacheType
  14673. );
  14674. NTKERNELAPI
  14675. VOID
  14676. MmFreeContiguousMemory (
  14677. IN PVOID BaseAddress
  14678. );
  14679. NTKERNELAPI
  14680. VOID
  14681. MmFreeContiguousMemorySpecifyCache (
  14682. IN PVOID BaseAddress,
  14683. IN SIZE_T NumberOfBytes,
  14684. IN MEMORY_CACHING_TYPE CacheType
  14685. );
  14686. NTKERNELAPI
  14687. PVOID
  14688. MmAllocateNonCachedMemory (
  14689. IN SIZE_T NumberOfBytes
  14690. );
  14691. NTKERNELAPI
  14692. VOID
  14693. MmFreeNonCachedMemory (
  14694. IN PVOID BaseAddress,
  14695. IN SIZE_T NumberOfBytes
  14696. );
  14697. NTKERNELAPI
  14698. BOOLEAN
  14699. MmIsAddressValid (
  14700. IN PVOID VirtualAddress
  14701. );
  14702. DECLSPEC_DEPRECATED_DDK
  14703. NTKERNELAPI
  14704. BOOLEAN
  14705. MmIsNonPagedSystemAddressValid (
  14706. IN PVOID VirtualAddress
  14707. );
  14708. // begin_wdm
  14709. NTKERNELAPI
  14710. SIZE_T
  14711. MmSizeOfMdl (
  14712. IN PVOID Base,
  14713. IN SIZE_T Length
  14714. );
  14715. DECLSPEC_DEPRECATED_DDK // Use IoAllocateMdl
  14716. NTKERNELAPI
  14717. PMDL
  14718. MmCreateMdl (
  14719. IN PMDL MemoryDescriptorList OPTIONAL,
  14720. IN PVOID Base,
  14721. IN SIZE_T Length
  14722. );
  14723. NTKERNELAPI
  14724. PVOID
  14725. MmLockPagableDataSection (
  14726. IN PVOID AddressWithinSection
  14727. );
  14728. // end_wdm
  14729. NTKERNELAPI
  14730. VOID
  14731. MmLockPagableSectionByHandle (
  14732. IN PVOID ImageSectionHandle
  14733. );
  14734. NTKERNELAPI
  14735. VOID
  14736. MmResetDriverPaging (
  14737. IN PVOID AddressWithinSection
  14738. );
  14739. NTKERNELAPI
  14740. PVOID
  14741. MmPageEntireDriver (
  14742. IN PVOID AddressWithinSection
  14743. );
  14744. NTKERNELAPI
  14745. VOID
  14746. MmUnlockPagableImageSection(
  14747. IN PVOID ImageSectionHandle
  14748. );
  14749. //
  14750. // Note that even though this function prototype
  14751. // says "HANDLE", MmSecureVirtualMemory does NOT return
  14752. // anything resembling a Win32-style handle. The return
  14753. // value from this function can ONLY be used with MmUnsecureVirtualMemory.
  14754. //
  14755. NTKERNELAPI
  14756. HANDLE
  14757. MmSecureVirtualMemory (
  14758. IN PVOID Address,
  14759. IN SIZE_T Size,
  14760. IN ULONG ProbeMode
  14761. );
  14762. NTKERNELAPI
  14763. VOID
  14764. MmUnsecureVirtualMemory (
  14765. IN HANDLE SecureHandle
  14766. );
  14767. NTKERNELAPI
  14768. NTSTATUS
  14769. MmMapViewInSessionSpace (
  14770. IN PVOID Section,
  14771. OUT PVOID *MappedBase,
  14772. IN OUT PSIZE_T ViewSize
  14773. );
  14774. // end_ntddk end_ntifs
  14775. NTKERNELAPI
  14776. NTSTATUS
  14777. MmCommitSessionMappedView (
  14778. IN PVOID MappedAddress,
  14779. IN SIZE_T ViewSize
  14780. );
  14781. // begin_ntddk begin_ntifs
  14782. NTKERNELAPI
  14783. NTSTATUS
  14784. MmUnmapViewInSessionSpace (
  14785. IN PVOID MappedBase
  14786. );
  14787. //++
  14788. //
  14789. // VOID
  14790. // MmInitializeMdl (
  14791. // IN PMDL MemoryDescriptorList,
  14792. // IN PVOID BaseVa,
  14793. // IN SIZE_T Length
  14794. // )
  14795. //
  14796. // Routine Description:
  14797. //
  14798. // This routine initializes the header of a Memory Descriptor List (MDL).
  14799. //
  14800. // Arguments:
  14801. //
  14802. // MemoryDescriptorList - Pointer to the MDL to initialize.
  14803. //
  14804. // BaseVa - Base virtual address mapped by the MDL.
  14805. //
  14806. // Length - Length, in bytes, of the buffer mapped by the MDL.
  14807. //
  14808. // Return Value:
  14809. //
  14810. // None.
  14811. //
  14812. //--
  14813. #define MmInitializeMdl(MemoryDescriptorList, BaseVa, Length) { \
  14814. (MemoryDescriptorList)->Next = (PMDL) NULL; \
  14815. (MemoryDescriptorList)->Size = (CSHORT)(sizeof(MDL) + \
  14816. (sizeof(PFN_NUMBER) * ADDRESS_AND_SIZE_TO_SPAN_PAGES((BaseVa), (Length)))); \
  14817. (MemoryDescriptorList)->MdlFlags = 0; \
  14818. (MemoryDescriptorList)->StartVa = (PVOID) PAGE_ALIGN((BaseVa)); \
  14819. (MemoryDescriptorList)->ByteOffset = BYTE_OFFSET((BaseVa)); \
  14820. (MemoryDescriptorList)->ByteCount = (ULONG)(Length); \
  14821. }
  14822. //++
  14823. //
  14824. // PVOID
  14825. // MmGetSystemAddressForMdlSafe (
  14826. // IN PMDL MDL,
  14827. // IN MM_PAGE_PRIORITY PRIORITY
  14828. // )
  14829. //
  14830. // Routine Description:
  14831. //
  14832. // This routine returns the mapped address of an MDL. If the
  14833. // Mdl is not already mapped or a system address, it is mapped.
  14834. //
  14835. // Arguments:
  14836. //
  14837. // MemoryDescriptorList - Pointer to the MDL to map.
  14838. //
  14839. // Priority - Supplies an indication as to how important it is that this
  14840. // request succeed under low available PTE conditions.
  14841. //
  14842. // Return Value:
  14843. //
  14844. // Returns the base address where the pages are mapped. The base address
  14845. // has the same offset as the virtual address in the MDL.
  14846. //
  14847. // Unlike MmGetSystemAddressForMdl, Safe guarantees that it will always
  14848. // return NULL on failure instead of bugchecking the system.
  14849. //
  14850. // This macro is not usable by WDM 1.0 drivers as 1.0 did not include
  14851. // MmMapLockedPagesSpecifyCache. The solution for WDM 1.0 drivers is to
  14852. // provide synchronization and set/reset the MDL_MAPPING_CAN_FAIL bit.
  14853. //
  14854. //--
  14855. #define MmGetSystemAddressForMdlSafe(MDL, PRIORITY) \
  14856. (((MDL)->MdlFlags & (MDL_MAPPED_TO_SYSTEM_VA | \
  14857. MDL_SOURCE_IS_NONPAGED_POOL)) ? \
  14858. ((MDL)->MappedSystemVa) : \
  14859. (MmMapLockedPagesSpecifyCache((MDL), \
  14860. KernelMode, \
  14861. MmCached, \
  14862. NULL, \
  14863. FALSE, \
  14864. (PRIORITY))))
  14865. //++
  14866. //
  14867. // PVOID
  14868. // MmGetSystemAddressForMdl (
  14869. // IN PMDL MDL
  14870. // )
  14871. //
  14872. // Routine Description:
  14873. //
  14874. // This routine returns the mapped address of an MDL, if the
  14875. // Mdl is not already mapped or a system address, it is mapped.
  14876. //
  14877. // Arguments:
  14878. //
  14879. // MemoryDescriptorList - Pointer to the MDL to map.
  14880. //
  14881. // Return Value:
  14882. //
  14883. // Returns the base address where the pages are mapped. The base address
  14884. // has the same offset as the virtual address in the MDL.
  14885. //
  14886. //--
  14887. //#define MmGetSystemAddressForMdl(MDL)
  14888. // (((MDL)->MdlFlags & (MDL_MAPPED_TO_SYSTEM_VA)) ?
  14889. // ((MDL)->MappedSystemVa) :
  14890. // ((((MDL)->MdlFlags & (MDL_SOURCE_IS_NONPAGED_POOL)) ?
  14891. // ((PVOID)((ULONG)(MDL)->StartVa | (MDL)->ByteOffset)) :
  14892. // (MmMapLockedPages((MDL),KernelMode)))))
  14893. #if PRAGMA_DEPRECATED_DDK
  14894. #pragma deprecated(MmGetSystemAddressForMdl) // Use MmGetSystemAddressForMdlSafe
  14895. #endif
  14896. #define MmGetSystemAddressForMdl(MDL) \
  14897. (((MDL)->MdlFlags & (MDL_MAPPED_TO_SYSTEM_VA | \
  14898. MDL_SOURCE_IS_NONPAGED_POOL)) ? \
  14899. ((MDL)->MappedSystemVa) : \
  14900. (MmMapLockedPages((MDL),KernelMode)))
  14901. //++
  14902. //
  14903. // VOID
  14904. // MmPrepareMdlForReuse (
  14905. // IN PMDL MDL
  14906. // )
  14907. //
  14908. // Routine Description:
  14909. //
  14910. // This routine will take all of the steps necessary to allow an MDL to be
  14911. // re-used.
  14912. //
  14913. // Arguments:
  14914. //
  14915. // MemoryDescriptorList - Pointer to the MDL that will be re-used.
  14916. //
  14917. // Return Value:
  14918. //
  14919. // None.
  14920. //
  14921. //--
  14922. #define MmPrepareMdlForReuse(MDL) \
  14923. if (((MDL)->MdlFlags & MDL_PARTIAL_HAS_BEEN_MAPPED) != 0) { \
  14924. ASSERT(((MDL)->MdlFlags & MDL_PARTIAL) != 0); \
  14925. MmUnmapLockedPages( (MDL)->MappedSystemVa, (MDL) ); \
  14926. } else if (((MDL)->MdlFlags & MDL_PARTIAL) == 0) { \
  14927. ASSERT(((MDL)->MdlFlags & MDL_MAPPED_TO_SYSTEM_VA) == 0); \
  14928. }
  14929. typedef NTSTATUS (*PMM_DLL_INITIALIZE)(
  14930. IN PUNICODE_STRING RegistryPath
  14931. );
  14932. typedef NTSTATUS (*PMM_DLL_UNLOAD)(
  14933. VOID
  14934. );
  14935. //
  14936. // Define an empty typedef for the _DRIVER_OBJECT structure so it may be
  14937. // referenced by function types before it is actually defined.
  14938. //
  14939. struct _DRIVER_OBJECT;
  14940. NTKERNELAPI
  14941. LOGICAL
  14942. MmIsDriverVerifying (
  14943. IN struct _DRIVER_OBJECT *DriverObject
  14944. );
  14945. VOID
  14946. MmMapMemoryDumpMdl (
  14947. IN OUT PMDL MemoryDumpMdl
  14948. );
  14949. // begin_ntminiport
  14950. //
  14951. // Graphics support routines.
  14952. //
  14953. typedef
  14954. VOID
  14955. (*PBANKED_SECTION_ROUTINE) (
  14956. IN ULONG ReadBank,
  14957. IN ULONG WriteBank,
  14958. IN PVOID Context
  14959. );
  14960. // end_ntminiport
  14961. NTSTATUS
  14962. MmSetBankedSection (
  14963. IN HANDLE ProcessHandle,
  14964. IN PVOID VirtualAddress,
  14965. IN ULONG BankLength,
  14966. IN BOOLEAN ReadWriteBank,
  14967. IN PBANKED_SECTION_ROUTINE BankRoutine,
  14968. IN PVOID Context);
  14969. //
  14970. // Security operation codes
  14971. //
  14972. typedef enum _SECURITY_OPERATION_CODE {
  14973. SetSecurityDescriptor,
  14974. QuerySecurityDescriptor,
  14975. DeleteSecurityDescriptor,
  14976. AssignSecurityDescriptor
  14977. } SECURITY_OPERATION_CODE, *PSECURITY_OPERATION_CODE;
  14978. //
  14979. // Data structure used to capture subject security context
  14980. // for access validations and auditing.
  14981. //
  14982. // THE FIELDS OF THIS DATA STRUCTURE SHOULD BE CONSIDERED OPAQUE
  14983. // BY ALL EXCEPT THE SECURITY ROUTINES.
  14984. //
  14985. typedef struct _SECURITY_SUBJECT_CONTEXT {
  14986. PACCESS_TOKEN ClientToken;
  14987. SECURITY_IMPERSONATION_LEVEL ImpersonationLevel;
  14988. PACCESS_TOKEN PrimaryToken;
  14989. PVOID ProcessAuditId;
  14990. } SECURITY_SUBJECT_CONTEXT, *PSECURITY_SUBJECT_CONTEXT;
  14991. ///////////////////////////////////////////////////////////////////////////////
  14992. // //
  14993. // ACCESS_STATE and related structures //
  14994. // //
  14995. ///////////////////////////////////////////////////////////////////////////////
  14996. //
  14997. // Initial Privilege Set - Room for three privileges, which should
  14998. // be enough for most applications. This structure exists so that
  14999. // it can be imbedded in an ACCESS_STATE structure. Use PRIVILEGE_SET
  15000. // for all other references to Privilege sets.
  15001. //
  15002. #define INITIAL_PRIVILEGE_COUNT 3
  15003. typedef struct _INITIAL_PRIVILEGE_SET {
  15004. ULONG PrivilegeCount;
  15005. ULONG Control;
  15006. LUID_AND_ATTRIBUTES Privilege[INITIAL_PRIVILEGE_COUNT];
  15007. } INITIAL_PRIVILEGE_SET, * PINITIAL_PRIVILEGE_SET;
  15008. //
  15009. // Combine the information that describes the state
  15010. // of an access-in-progress into a single structure
  15011. //
  15012. typedef struct _ACCESS_STATE {
  15013. LUID OperationID;
  15014. BOOLEAN SecurityEvaluated;
  15015. BOOLEAN GenerateAudit;
  15016. BOOLEAN GenerateOnClose;
  15017. BOOLEAN PrivilegesAllocated;
  15018. ULONG Flags;
  15019. ACCESS_MASK RemainingDesiredAccess;
  15020. ACCESS_MASK PreviouslyGrantedAccess;
  15021. ACCESS_MASK OriginalDesiredAccess;
  15022. SECURITY_SUBJECT_CONTEXT SubjectSecurityContext;
  15023. PSECURITY_DESCRIPTOR SecurityDescriptor;
  15024. PVOID AuxData;
  15025. union {
  15026. INITIAL_PRIVILEGE_SET InitialPrivilegeSet;
  15027. PRIVILEGE_SET PrivilegeSet;
  15028. } Privileges;
  15029. BOOLEAN AuditPrivileges;
  15030. UNICODE_STRING ObjectName;
  15031. UNICODE_STRING ObjectTypeName;
  15032. } ACCESS_STATE, *PACCESS_STATE;
  15033. typedef struct _AUX_ACCESS_DATA {
  15034. PPRIVILEGE_SET PrivilegesUsed;
  15035. GENERIC_MAPPING GenericMapping;
  15036. ACCESS_MASK AccessesToAudit;
  15037. ACCESS_MASK MaximumAuditMask;
  15038. } AUX_ACCESS_DATA, *PAUX_ACCESS_DATA;
  15039. typedef struct _SE_EXPORTS {
  15040. //
  15041. // Privilege values
  15042. //
  15043. LUID SeCreateTokenPrivilege;
  15044. LUID SeAssignPrimaryTokenPrivilege;
  15045. LUID SeLockMemoryPrivilege;
  15046. LUID SeIncreaseQuotaPrivilege;
  15047. LUID SeUnsolicitedInputPrivilege;
  15048. LUID SeTcbPrivilege;
  15049. LUID SeSecurityPrivilege;
  15050. LUID SeTakeOwnershipPrivilege;
  15051. LUID SeLoadDriverPrivilege;
  15052. LUID SeCreatePagefilePrivilege;
  15053. LUID SeIncreaseBasePriorityPrivilege;
  15054. LUID SeSystemProfilePrivilege;
  15055. LUID SeSystemtimePrivilege;
  15056. LUID SeProfileSingleProcessPrivilege;
  15057. LUID SeCreatePermanentPrivilege;
  15058. LUID SeBackupPrivilege;
  15059. LUID SeRestorePrivilege;
  15060. LUID SeShutdownPrivilege;
  15061. LUID SeDebugPrivilege;
  15062. LUID SeAuditPrivilege;
  15063. LUID SeSystemEnvironmentPrivilege;
  15064. LUID SeChangeNotifyPrivilege;
  15065. LUID SeRemoteShutdownPrivilege;
  15066. //
  15067. // Universally defined Sids
  15068. //
  15069. PSID SeNullSid;
  15070. PSID SeWorldSid;
  15071. PSID SeLocalSid;
  15072. PSID SeCreatorOwnerSid;
  15073. PSID SeCreatorGroupSid;
  15074. //
  15075. // Nt defined Sids
  15076. //
  15077. PSID SeNtAuthoritySid;
  15078. PSID SeDialupSid;
  15079. PSID SeNetworkSid;
  15080. PSID SeBatchSid;
  15081. PSID SeInteractiveSid;
  15082. PSID SeLocalSystemSid;
  15083. PSID SeAliasAdminsSid;
  15084. PSID SeAliasUsersSid;
  15085. PSID SeAliasGuestsSid;
  15086. PSID SeAliasPowerUsersSid;
  15087. PSID SeAliasAccountOpsSid;
  15088. PSID SeAliasSystemOpsSid;
  15089. PSID SeAliasPrintOpsSid;
  15090. PSID SeAliasBackupOpsSid;
  15091. //
  15092. // New Sids defined for NT5
  15093. //
  15094. PSID SeAuthenticatedUsersSid;
  15095. PSID SeRestrictedSid;
  15096. PSID SeAnonymousLogonSid;
  15097. //
  15098. // New Privileges defined for NT5
  15099. //
  15100. LUID SeUndockPrivilege;
  15101. LUID SeSyncAgentPrivilege;
  15102. LUID SeEnableDelegationPrivilege;
  15103. //
  15104. // New Sids defined for post-Windows 2000
  15105. PSID SeLocalServiceSid;
  15106. PSID SeNetworkServiceSid;
  15107. //
  15108. // New Privileges defined for post-Windows 2000
  15109. //
  15110. LUID SeManageVolumePrivilege;
  15111. LUID SeImpersonatePrivilege;
  15112. LUID SeCreateGlobalPrivilege;
  15113. } SE_EXPORTS, *PSE_EXPORTS;
  15114. #define SeDeleteClientSecurity(C) { \
  15115. if (SeTokenType((C)->ClientToken) == TokenPrimary) { \
  15116. PsDereferencePrimaryToken( (C)->ClientToken ); \
  15117. } else { \
  15118. PsDereferenceImpersonationToken( (C)->ClientToken ); \
  15119. } \
  15120. }
  15121. //++
  15122. //VOID
  15123. //SeStopImpersonatingClient()
  15124. //
  15125. ///*++
  15126. //
  15127. //Routine Description:
  15128. //
  15129. // This service is used to stop impersonating a client using an
  15130. // impersonation token. This service must be called in the context
  15131. // of the server thread which wishes to stop impersonating its
  15132. // client.
  15133. //
  15134. //
  15135. //Arguments:
  15136. //
  15137. // None.
  15138. //
  15139. //Return Value:
  15140. //
  15141. // None.
  15142. //
  15143. //--*/
  15144. //--
  15145. #define SeStopImpersonatingClient() PsRevertToSelf()
  15146. //++
  15147. //
  15148. // PACCESS_TOKEN
  15149. // SeQuerySubjectContextToken(
  15150. // IN PSECURITY_SUBJECT_CONTEXT SubjectContext
  15151. // );
  15152. //
  15153. // Routine Description:
  15154. //
  15155. // This routine returns the effective token from the subject context,
  15156. // either the client token, if present, or the process token.
  15157. //
  15158. // Arguments:
  15159. //
  15160. // SubjectContext - Context to query
  15161. //
  15162. // Return Value:
  15163. //
  15164. // This routine returns the PACCESS_TOKEN for the effective token.
  15165. // The pointer may be passed to SeQueryInformationToken. This routine
  15166. // does not affect the lock status of the token, i.e. the token is not
  15167. // locked. If the SubjectContext has been locked, the token remains locked,
  15168. // if not, the token remains unlocked.
  15169. //
  15170. //--
  15171. #define SeQuerySubjectContextToken( SubjectContext ) \
  15172. ( ARGUMENT_PRESENT( ((PSECURITY_SUBJECT_CONTEXT) SubjectContext)->ClientToken) ? \
  15173. ((PSECURITY_SUBJECT_CONTEXT) SubjectContext)->ClientToken : \
  15174. ((PSECURITY_SUBJECT_CONTEXT) SubjectContext)->PrimaryToken )
  15175. NTKERNELAPI
  15176. NTSTATUS
  15177. SeCaptureSecurityDescriptor (
  15178. IN PSECURITY_DESCRIPTOR InputSecurityDescriptor,
  15179. IN KPROCESSOR_MODE RequestorMode,
  15180. IN POOL_TYPE PoolType,
  15181. IN BOOLEAN ForceCapture,
  15182. OUT PSECURITY_DESCRIPTOR *OutputSecurityDescriptor
  15183. );
  15184. NTKERNELAPI
  15185. VOID
  15186. SeReleaseSecurityDescriptor (
  15187. IN PSECURITY_DESCRIPTOR CapturedSecurityDescriptor,
  15188. IN KPROCESSOR_MODE RequestorMode,
  15189. IN BOOLEAN ForceCapture
  15190. );
  15191. // begin_ntifs
  15192. NTKERNELAPI
  15193. VOID
  15194. SeCaptureSubjectContext (
  15195. OUT PSECURITY_SUBJECT_CONTEXT SubjectContext
  15196. );
  15197. NTKERNELAPI
  15198. VOID
  15199. SeLockSubjectContext(
  15200. IN PSECURITY_SUBJECT_CONTEXT SubjectContext
  15201. );
  15202. NTKERNELAPI
  15203. VOID
  15204. SeUnlockSubjectContext(
  15205. IN PSECURITY_SUBJECT_CONTEXT SubjectContext
  15206. );
  15207. NTKERNELAPI
  15208. VOID
  15209. SeReleaseSubjectContext (
  15210. IN PSECURITY_SUBJECT_CONTEXT SubjectContext
  15211. );
  15212. NTSTATUS
  15213. SeCaptureAuditPolicy(
  15214. IN PTOKEN_AUDIT_POLICY Policy,
  15215. IN KPROCESSOR_MODE RequestorMode,
  15216. IN PVOID CaptureBuffer OPTIONAL,
  15217. IN ULONG CaptureBufferLength,
  15218. IN POOL_TYPE PoolType,
  15219. IN BOOLEAN ForceCapture,
  15220. OUT PTOKEN_AUDIT_POLICY *CapturedPolicy
  15221. );
  15222. VOID
  15223. SeReleaseAuditPolicy (
  15224. IN PTOKEN_AUDIT_POLICY CapturedPolicy,
  15225. IN KPROCESSOR_MODE RequestorMode,
  15226. IN BOOLEAN ForceCapture
  15227. );
  15228. NTKERNELAPI
  15229. NTSTATUS
  15230. SeAssignSecurity (
  15231. IN PSECURITY_DESCRIPTOR ParentDescriptor OPTIONAL,
  15232. IN PSECURITY_DESCRIPTOR ExplicitDescriptor,
  15233. OUT PSECURITY_DESCRIPTOR *NewDescriptor,
  15234. IN BOOLEAN IsDirectoryObject,
  15235. IN PSECURITY_SUBJECT_CONTEXT SubjectContext,
  15236. IN PGENERIC_MAPPING GenericMapping,
  15237. IN POOL_TYPE PoolType
  15238. );
  15239. NTKERNELAPI
  15240. NTSTATUS
  15241. SeAssignSecurityEx (
  15242. IN PSECURITY_DESCRIPTOR ParentDescriptor OPTIONAL,
  15243. IN PSECURITY_DESCRIPTOR ExplicitDescriptor OPTIONAL,
  15244. OUT PSECURITY_DESCRIPTOR *NewDescriptor,
  15245. IN GUID *ObjectType OPTIONAL,
  15246. IN BOOLEAN IsDirectoryObject,
  15247. IN ULONG AutoInheritFlags,
  15248. IN PSECURITY_SUBJECT_CONTEXT SubjectContext,
  15249. IN PGENERIC_MAPPING GenericMapping,
  15250. IN POOL_TYPE PoolType
  15251. );
  15252. NTKERNELAPI
  15253. NTSTATUS
  15254. SeDeassignSecurity (
  15255. IN OUT PSECURITY_DESCRIPTOR *SecurityDescriptor
  15256. );
  15257. NTKERNELAPI
  15258. BOOLEAN
  15259. SeAccessCheck (
  15260. IN PSECURITY_DESCRIPTOR SecurityDescriptor,
  15261. IN PSECURITY_SUBJECT_CONTEXT SubjectSecurityContext,
  15262. IN BOOLEAN SubjectContextLocked,
  15263. IN ACCESS_MASK DesiredAccess,
  15264. IN ACCESS_MASK PreviouslyGrantedAccess,
  15265. OUT PPRIVILEGE_SET *Privileges OPTIONAL,
  15266. IN PGENERIC_MAPPING GenericMapping,
  15267. IN KPROCESSOR_MODE AccessMode,
  15268. OUT PACCESS_MASK GrantedAccess,
  15269. OUT PNTSTATUS AccessStatus
  15270. );
  15271. #ifdef SE_NTFS_WORLD_CACHE
  15272. VOID
  15273. SeGetWorldRights (
  15274. IN PSECURITY_DESCRIPTOR SecurityDescriptor,
  15275. IN PGENERIC_MAPPING GenericMapping,
  15276. OUT PACCESS_MASK GrantedAccess
  15277. );
  15278. #endif
  15279. NTKERNELAPI
  15280. BOOLEAN
  15281. SePrivilegeCheck(
  15282. IN OUT PPRIVILEGE_SET RequiredPrivileges,
  15283. IN PSECURITY_SUBJECT_CONTEXT SubjectSecurityContext,
  15284. IN KPROCESSOR_MODE AccessMode
  15285. );
  15286. NTKERNELAPI
  15287. VOID
  15288. SeFreePrivileges(
  15289. IN PPRIVILEGE_SET Privileges
  15290. );
  15291. NTKERNELAPI
  15292. VOID
  15293. SePrivilegeObjectAuditAlarm(
  15294. IN HANDLE Handle,
  15295. IN PSECURITY_SUBJECT_CONTEXT SubjectSecurityContext,
  15296. IN ACCESS_MASK DesiredAccess,
  15297. IN PPRIVILEGE_SET Privileges,
  15298. IN BOOLEAN AccessGranted,
  15299. IN KPROCESSOR_MODE AccessMode
  15300. );
  15301. extern struct _OBJECT_TYPE *SeTokenObjectType;
  15302. NTKERNELAPI // ntifs
  15303. TOKEN_TYPE // ntifs
  15304. SeTokenType( // ntifs
  15305. IN PACCESS_TOKEN Token // ntifs
  15306. ); // ntifs
  15307. SECURITY_IMPERSONATION_LEVEL
  15308. SeTokenImpersonationLevel(
  15309. IN PACCESS_TOKEN Token
  15310. );
  15311. NTKERNELAPI // ntifs
  15312. BOOLEAN // ntifs
  15313. SeTokenIsAdmin( // ntifs
  15314. IN PACCESS_TOKEN Token // ntifs
  15315. ); // ntifs
  15316. NTKERNELAPI // ntifs
  15317. BOOLEAN // ntifs
  15318. SeTokenIsRestricted( // ntifs
  15319. IN PACCESS_TOKEN Token // ntifs
  15320. ); // ntifs
  15321. NTKERNELAPI
  15322. NTSTATUS
  15323. SeTokenCanImpersonate(
  15324. IN PACCESS_TOKEN ProcessToken,
  15325. IN PACCESS_TOKEN Token,
  15326. IN SECURITY_IMPERSONATION_LEVEL ImpersonationLevel
  15327. );
  15328. NTKERNELAPI
  15329. NTSTATUS
  15330. SeQueryAuthenticationIdToken(
  15331. IN PACCESS_TOKEN Token,
  15332. OUT PLUID AuthenticationId
  15333. );
  15334. NTKERNELAPI
  15335. NTSTATUS
  15336. SeCreateClientSecurity (
  15337. IN PETHREAD ClientThread,
  15338. IN PSECURITY_QUALITY_OF_SERVICE ClientSecurityQos,
  15339. IN BOOLEAN RemoteSession,
  15340. OUT PSECURITY_CLIENT_CONTEXT ClientContext
  15341. );
  15342. NTKERNELAPI
  15343. NTSTATUS
  15344. SeImpersonateClientEx(
  15345. IN PSECURITY_CLIENT_CONTEXT ClientContext,
  15346. IN PETHREAD ServerThread OPTIONAL
  15347. );
  15348. NTKERNELAPI
  15349. NTSTATUS
  15350. SeCreateAccessState(
  15351. IN PACCESS_STATE AccessState,
  15352. IN PAUX_ACCESS_DATA AuxData,
  15353. IN ACCESS_MASK DesiredAccess,
  15354. IN PGENERIC_MAPPING GenericMapping
  15355. );
  15356. NTKERNELAPI
  15357. VOID
  15358. SeDeleteAccessState(
  15359. IN PACCESS_STATE AccessState
  15360. );
  15361. NTKERNELAPI
  15362. NTSTATUS
  15363. SeQuerySecurityDescriptorInfo (
  15364. IN PSECURITY_INFORMATION SecurityInformation,
  15365. OUT PSECURITY_DESCRIPTOR SecurityDescriptor,
  15366. IN OUT PULONG Length,
  15367. IN PSECURITY_DESCRIPTOR *ObjectsSecurityDescriptor
  15368. );
  15369. NTKERNELAPI
  15370. NTSTATUS
  15371. SeSetSecurityDescriptorInfo (
  15372. IN PVOID Object OPTIONAL,
  15373. IN PSECURITY_INFORMATION SecurityInformation,
  15374. IN PSECURITY_DESCRIPTOR SecurityDescriptor,
  15375. IN OUT PSECURITY_DESCRIPTOR *ObjectsSecurityDescriptor,
  15376. IN POOL_TYPE PoolType,
  15377. IN PGENERIC_MAPPING GenericMapping
  15378. );
  15379. NTKERNELAPI
  15380. NTSTATUS
  15381. SeSetSecurityDescriptorInfoEx (
  15382. IN PVOID Object OPTIONAL,
  15383. IN PSECURITY_INFORMATION SecurityInformation,
  15384. IN PSECURITY_DESCRIPTOR ModificationDescriptor,
  15385. IN OUT PSECURITY_DESCRIPTOR *ObjectsSecurityDescriptor,
  15386. IN ULONG AutoInheritFlags,
  15387. IN POOL_TYPE PoolType,
  15388. IN PGENERIC_MAPPING GenericMapping
  15389. );
  15390. NTKERNELAPI
  15391. NTSTATUS
  15392. SeAppendPrivileges(
  15393. PACCESS_STATE AccessState,
  15394. PPRIVILEGE_SET Privileges
  15395. );
  15396. NTKERNELAPI
  15397. BOOLEAN
  15398. SeSinglePrivilegeCheck(
  15399. LUID PrivilegeValue,
  15400. KPROCESSOR_MODE PreviousMode
  15401. );
  15402. NTKERNELAPI
  15403. NTSTATUS
  15404. SeQueryInformationToken (
  15405. IN PACCESS_TOKEN Token,
  15406. IN TOKEN_INFORMATION_CLASS TokenInformationClass,
  15407. OUT PVOID *TokenInformation
  15408. );
  15409. //
  15410. // Grants access to SeExports structure
  15411. //
  15412. extern NTKERNELAPI PSE_EXPORTS SeExports;
  15413. NTKERNELAPI
  15414. VOID
  15415. PoSetSystemState (
  15416. IN EXECUTION_STATE Flags
  15417. );
  15418. // begin_ntifs
  15419. NTKERNELAPI
  15420. PVOID
  15421. PoRegisterSystemState (
  15422. IN PVOID StateHandle,
  15423. IN EXECUTION_STATE Flags
  15424. );
  15425. // end_ntifs
  15426. typedef
  15427. VOID
  15428. (*PREQUEST_POWER_COMPLETE) (
  15429. IN PDEVICE_OBJECT DeviceObject,
  15430. IN UCHAR MinorFunction,
  15431. IN POWER_STATE PowerState,
  15432. IN PVOID Context,
  15433. IN PIO_STATUS_BLOCK IoStatus
  15434. );
  15435. NTKERNELAPI
  15436. NTSTATUS
  15437. PoRequestPowerIrp (
  15438. IN PDEVICE_OBJECT DeviceObject,
  15439. IN UCHAR MinorFunction,
  15440. IN POWER_STATE PowerState,
  15441. IN PREQUEST_POWER_COMPLETE CompletionFunction,
  15442. IN PVOID Context,
  15443. OUT PIRP *Irp OPTIONAL
  15444. );
  15445. NTKERNELAPI
  15446. NTSTATUS
  15447. PoRequestShutdownEvent (
  15448. OUT PVOID *Event
  15449. );
  15450. NTKERNELAPI
  15451. NTSTATUS
  15452. PoRequestShutdownWait (
  15453. IN PETHREAD Thread
  15454. );
  15455. // begin_ntifs
  15456. NTKERNELAPI
  15457. VOID
  15458. PoUnregisterSystemState (
  15459. IN PVOID StateHandle
  15460. );
  15461. // begin_nthal
  15462. NTKERNELAPI
  15463. POWER_STATE
  15464. PoSetPowerState (
  15465. IN PDEVICE_OBJECT DeviceObject,
  15466. IN POWER_STATE_TYPE Type,
  15467. IN POWER_STATE State
  15468. );
  15469. NTKERNELAPI
  15470. NTSTATUS
  15471. PoCallDriver (
  15472. IN PDEVICE_OBJECT DeviceObject,
  15473. IN OUT PIRP Irp
  15474. );
  15475. NTKERNELAPI
  15476. VOID
  15477. PoStartNextPowerIrp(
  15478. IN PIRP Irp
  15479. );
  15480. NTKERNELAPI
  15481. PULONG
  15482. PoRegisterDeviceForIdleDetection (
  15483. IN PDEVICE_OBJECT DeviceObject,
  15484. IN ULONG ConservationIdleTime,
  15485. IN ULONG PerformanceIdleTime,
  15486. IN DEVICE_POWER_STATE State
  15487. );
  15488. #define PoSetDeviceBusy(IdlePointer) \
  15489. *IdlePointer = 0
  15490. //
  15491. // \Callback\PowerState values
  15492. //
  15493. #define PO_CB_SYSTEM_POWER_POLICY 0
  15494. #define PO_CB_AC_STATUS 1
  15495. #define PO_CB_BUTTON_COLLISION 2
  15496. #define PO_CB_SYSTEM_STATE_LOCK 3
  15497. #define PO_CB_LID_SWITCH_STATE 4
  15498. #define PO_CB_PROCESSOR_POWER_POLICY 5
  15499. // end_ntddk end_wdm end_nthal
  15500. // Used for queuing work items to be performed at shutdown time. Same
  15501. // rules apply as per Ex work queues.
  15502. NTKERNELAPI
  15503. NTSTATUS
  15504. PoQueueShutdownWorkItem(
  15505. IN PWORK_QUEUE_ITEM WorkItem
  15506. );
  15507. PKTHREAD
  15508. FORCEINLINE
  15509. PsGetKernelThread(
  15510. IN PETHREAD ThreadObject
  15511. )
  15512. {
  15513. return (PKTHREAD)ThreadObject;
  15514. }
  15515. PKPROCESS
  15516. FORCEINLINE
  15517. PsGetKernelProcess(
  15518. IN PEPROCESS ProcessObject
  15519. )
  15520. {
  15521. return (PKPROCESS)ProcessObject;
  15522. }
  15523. NTSTATUS
  15524. PsGetContextThread(
  15525. IN PETHREAD Thread,
  15526. IN OUT PCONTEXT ThreadContext,
  15527. IN KPROCESSOR_MODE Mode
  15528. );
  15529. NTSTATUS
  15530. PsSetContextThread(
  15531. IN PETHREAD Thread,
  15532. IN PCONTEXT ThreadContext,
  15533. IN KPROCESSOR_MODE Mode
  15534. );
  15535. NTKERNELAPI
  15536. PEPROCESS
  15537. PsGetCurrentProcess(
  15538. VOID
  15539. );
  15540. NTKERNELAPI
  15541. PETHREAD
  15542. PsGetCurrentThread(
  15543. VOID
  15544. );
  15545. //
  15546. // System Thread and Process Creation and Termination
  15547. //
  15548. NTKERNELAPI
  15549. NTSTATUS
  15550. PsCreateSystemThread(
  15551. OUT PHANDLE ThreadHandle,
  15552. IN ULONG DesiredAccess,
  15553. IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL,
  15554. IN HANDLE ProcessHandle OPTIONAL,
  15555. OUT PCLIENT_ID ClientId OPTIONAL,
  15556. IN PKSTART_ROUTINE StartRoutine,
  15557. IN PVOID StartContext
  15558. );
  15559. NTKERNELAPI
  15560. NTSTATUS
  15561. PsTerminateSystemThread(
  15562. IN NTSTATUS ExitStatus
  15563. );
  15564. NTKERNELAPI
  15565. PACCESS_TOKEN
  15566. PsReferencePrimaryToken(
  15567. IN PEPROCESS Process
  15568. );
  15569. VOID
  15570. PsDereferencePrimaryToken(
  15571. IN PACCESS_TOKEN PrimaryToken
  15572. );
  15573. VOID
  15574. PsDereferenceImpersonationToken(
  15575. IN PACCESS_TOKEN ImpersonationToken
  15576. );
  15577. // end_ntifs
  15578. // begin_ntifs
  15579. NTKERNELAPI
  15580. PACCESS_TOKEN
  15581. PsReferenceImpersonationToken(
  15582. IN PETHREAD Thread,
  15583. OUT PBOOLEAN CopyOnOpen,
  15584. OUT PBOOLEAN EffectiveOnly,
  15585. OUT PSECURITY_IMPERSONATION_LEVEL ImpersonationLevel
  15586. );
  15587. // end_ntifs
  15588. PACCESS_TOKEN
  15589. PsReferenceEffectiveToken(
  15590. IN PETHREAD Thread,
  15591. OUT PTOKEN_TYPE TokenType,
  15592. OUT PBOOLEAN EffectiveOnly,
  15593. OUT PSECURITY_IMPERSONATION_LEVEL ImpersonationLevel
  15594. );
  15595. // begin_ntifs
  15596. LARGE_INTEGER
  15597. PsGetProcessExitTime(
  15598. VOID
  15599. );
  15600. // end_ntifs
  15601. BOOLEAN
  15602. PsIsThreadTerminating(
  15603. IN PETHREAD Thread
  15604. );
  15605. NTSTATUS
  15606. PsImpersonateClient(
  15607. IN PETHREAD Thread,
  15608. IN PACCESS_TOKEN Token,
  15609. IN BOOLEAN CopyOnOpen,
  15610. IN BOOLEAN EffectiveOnly,
  15611. IN SECURITY_IMPERSONATION_LEVEL ImpersonationLevel
  15612. );
  15613. NTKERNELAPI
  15614. VOID
  15615. PsRevertToSelf(
  15616. VOID
  15617. );
  15618. // end_ntifs
  15619. NTKERNELAPI
  15620. VOID
  15621. PsRevertThreadToSelf(
  15622. PETHREAD Thread
  15623. );
  15624. NTKERNELAPI
  15625. NTSTATUS
  15626. PsLookupProcessByProcessId(
  15627. IN HANDLE ProcessId,
  15628. OUT PEPROCESS *Process
  15629. );
  15630. NTKERNELAPI
  15631. NTSTATUS
  15632. PsLookupThreadByThreadId(
  15633. IN HANDLE ThreadId,
  15634. OUT PETHREAD *Thread
  15635. );
  15636. // begin_ntifs
  15637. //
  15638. // Quota Operations
  15639. //
  15640. VOID
  15641. PsChargePoolQuota(
  15642. IN PEPROCESS Process,
  15643. IN POOL_TYPE PoolType,
  15644. IN ULONG_PTR Amount
  15645. );
  15646. NTSTATUS
  15647. PsChargeProcessPoolQuota(
  15648. IN PEPROCESS Process,
  15649. IN POOL_TYPE PoolType,
  15650. IN ULONG_PTR Amount
  15651. );
  15652. VOID
  15653. PsReturnPoolQuota(
  15654. IN PEPROCESS Process,
  15655. IN POOL_TYPE PoolType,
  15656. IN ULONG_PTR Amount
  15657. );
  15658. // end_ntifs
  15659. typedef
  15660. NTSTATUS
  15661. (*PKWIN32_PROCESS_CALLOUT) (
  15662. IN PEPROCESS Process,
  15663. IN BOOLEAN Initialize
  15664. );
  15665. typedef enum _PSW32JOBCALLOUTTYPE {
  15666. PsW32JobCalloutSetInformation,
  15667. PsW32JobCalloutAddProcess,
  15668. PsW32JobCalloutTerminate
  15669. } PSW32JOBCALLOUTTYPE;
  15670. typedef struct _WIN32_JOBCALLOUT_PARAMETERS {
  15671. PVOID Job;
  15672. PSW32JOBCALLOUTTYPE CalloutType;
  15673. IN PVOID Data;
  15674. } WIN32_JOBCALLOUT_PARAMETERS, *PKWIN32_JOBCALLOUT_PARAMETERS;
  15675. typedef
  15676. NTSTATUS
  15677. (*PKWIN32_JOB_CALLOUT) (
  15678. IN PKWIN32_JOBCALLOUT_PARAMETERS Parm
  15679. );
  15680. typedef enum _PSW32THREADCALLOUTTYPE {
  15681. PsW32ThreadCalloutInitialize,
  15682. PsW32ThreadCalloutExit
  15683. } PSW32THREADCALLOUTTYPE;
  15684. typedef
  15685. NTSTATUS
  15686. (*PKWIN32_THREAD_CALLOUT) (
  15687. IN PETHREAD Thread,
  15688. IN PSW32THREADCALLOUTTYPE CalloutType
  15689. );
  15690. typedef enum _PSPOWEREVENTTYPE {
  15691. PsW32FullWake,
  15692. PsW32EventCode,
  15693. PsW32PowerPolicyChanged,
  15694. PsW32SystemPowerState,
  15695. PsW32SystemTime,
  15696. PsW32DisplayState,
  15697. PsW32CapabilitiesChanged,
  15698. PsW32SetStateFailed,
  15699. PsW32GdiOff,
  15700. PsW32GdiOn
  15701. } PSPOWEREVENTTYPE;
  15702. typedef struct _WIN32_POWEREVENT_PARAMETERS {
  15703. PSPOWEREVENTTYPE EventNumber;
  15704. ULONG_PTR Code;
  15705. } WIN32_POWEREVENT_PARAMETERS, *PKWIN32_POWEREVENT_PARAMETERS;
  15706. typedef enum _POWERSTATETASK {
  15707. PowerState_BlockSessionSwitch,
  15708. PowerState_Init,
  15709. PowerState_QueryApps,
  15710. PowerState_QueryFailed,
  15711. PowerState_SuspendApps,
  15712. PowerState_ShowUI,
  15713. PowerState_NotifyWL,
  15714. PowerState_ResumeApps,
  15715. PowerState_UnBlockSessionSwitch
  15716. } POWERSTATETASK;
  15717. typedef struct _WIN32_POWERSTATE_PARAMETERS {
  15718. BOOLEAN Promotion;
  15719. POWER_ACTION SystemAction;
  15720. SYSTEM_POWER_STATE MinSystemState;
  15721. ULONG Flags;
  15722. BOOLEAN fQueryDenied;
  15723. POWERSTATETASK PowerStateTask;
  15724. } WIN32_POWERSTATE_PARAMETERS, *PKWIN32_POWERSTATE_PARAMETERS;
  15725. typedef
  15726. NTSTATUS
  15727. (*PKWIN32_POWEREVENT_CALLOUT) (
  15728. IN PKWIN32_POWEREVENT_PARAMETERS Parm
  15729. );
  15730. typedef
  15731. NTSTATUS
  15732. (*PKWIN32_POWERSTATE_CALLOUT) (
  15733. IN PKWIN32_POWERSTATE_PARAMETERS Parm
  15734. );
  15735. typedef
  15736. NTSTATUS
  15737. (*PKWIN32_OBJECT_CALLOUT) (
  15738. IN PVOID Parm
  15739. );
  15740. typedef struct _WIN32_CALLOUTS_FPNS {
  15741. PKWIN32_PROCESS_CALLOUT ProcessCallout;
  15742. PKWIN32_THREAD_CALLOUT ThreadCallout;
  15743. PKWIN32_GLOBALATOMTABLE_CALLOUT GlobalAtomTableCallout;
  15744. PKWIN32_POWEREVENT_CALLOUT PowerEventCallout;
  15745. PKWIN32_POWERSTATE_CALLOUT PowerStateCallout;
  15746. PKWIN32_JOB_CALLOUT JobCallout;
  15747. PVOID BatchFlushRoutine;
  15748. PKWIN32_OBJECT_CALLOUT DesktopOpenProcedure;
  15749. PKWIN32_OBJECT_CALLOUT DesktopOkToCloseProcedure;
  15750. PKWIN32_OBJECT_CALLOUT DesktopCloseProcedure;
  15751. PKWIN32_OBJECT_CALLOUT DesktopDeleteProcedure;
  15752. PKWIN32_OBJECT_CALLOUT WindowStationOkToCloseProcedure;
  15753. PKWIN32_OBJECT_CALLOUT WindowStationCloseProcedure;
  15754. PKWIN32_OBJECT_CALLOUT WindowStationDeleteProcedure;
  15755. PKWIN32_OBJECT_CALLOUT WindowStationParseProcedure;
  15756. PKWIN32_OBJECT_CALLOUT WindowStationOpenProcedure;
  15757. } WIN32_CALLOUTS_FPNS, *PKWIN32_CALLOUTS_FPNS;
  15758. NTKERNELAPI
  15759. VOID
  15760. PsEstablishWin32Callouts(
  15761. IN PKWIN32_CALLOUTS_FPNS pWin32Callouts
  15762. );
  15763. typedef enum _PSPROCESSPRIORITYMODE {
  15764. PsProcessPriorityBackground,
  15765. PsProcessPriorityForeground,
  15766. PsProcessPrioritySpinning
  15767. } PSPROCESSPRIORITYMODE;
  15768. NTKERNELAPI
  15769. VOID
  15770. PsSetProcessPriorityByClass(
  15771. IN PEPROCESS Process,
  15772. IN PSPROCESSPRIORITYMODE PriorityMode
  15773. );
  15774. HANDLE
  15775. PsGetCurrentProcessId( VOID );
  15776. HANDLE
  15777. PsGetCurrentThreadId( VOID );
  15778. NTKERNELAPI
  15779. ULONG
  15780. PsGetCurrentProcessSessionId(
  15781. VOID
  15782. );
  15783. NTKERNELAPI
  15784. PVOID
  15785. PsGetCurrentThreadStackLimit(
  15786. VOID
  15787. );
  15788. NTKERNELAPI
  15789. PVOID
  15790. PsGetCurrentThreadStackBase(
  15791. VOID
  15792. );
  15793. NTKERNELAPI
  15794. CCHAR
  15795. PsGetCurrentThreadPreviousMode(
  15796. VOID
  15797. );
  15798. NTKERNELAPI
  15799. PERESOURCE
  15800. PsGetJobLock(
  15801. PEJOB Job
  15802. );
  15803. NTKERNELAPI
  15804. ULONG
  15805. PsGetJobSessionId(
  15806. PEJOB Job
  15807. );
  15808. NTKERNELAPI
  15809. ULONG
  15810. PsGetJobUIRestrictionsClass(
  15811. PEJOB Job
  15812. );
  15813. NTKERNELAPI
  15814. LONGLONG
  15815. PsGetProcessCreateTimeQuadPart(
  15816. PEPROCESS Process
  15817. );
  15818. NTKERNELAPI
  15819. PVOID
  15820. PsGetProcessDebugPort(
  15821. PEPROCESS Process
  15822. );
  15823. BOOLEAN
  15824. PsIsProcessBeingDebugged(
  15825. PEPROCESS Process
  15826. );
  15827. NTKERNELAPI
  15828. BOOLEAN
  15829. PsGetProcessExitProcessCalled(
  15830. PEPROCESS Process
  15831. );
  15832. NTKERNELAPI
  15833. NTSTATUS
  15834. PsGetProcessExitStatus(
  15835. PEPROCESS Process
  15836. );
  15837. NTKERNELAPI
  15838. HANDLE
  15839. PsGetProcessId(
  15840. PEPROCESS Process
  15841. );
  15842. NTKERNELAPI
  15843. UCHAR *
  15844. PsGetProcessImageFileName(
  15845. PEPROCESS Process
  15846. );
  15847. #define PsGetCurrentProcessImageFileName() PsGetProcessImageFileName(PsGetCurrentProcess())
  15848. NTKERNELAPI
  15849. HANDLE
  15850. PsGetProcessInheritedFromUniqueProcessId(
  15851. PEPROCESS Process
  15852. );
  15853. NTKERNELAPI
  15854. PEJOB
  15855. PsGetProcessJob(
  15856. PEPROCESS Process
  15857. );
  15858. NTKERNELAPI
  15859. ULONG
  15860. PsGetProcessSessionId(
  15861. PEPROCESS Process
  15862. );
  15863. NTKERNELAPI
  15864. ULONG
  15865. PsGetProcessSessionIdEx(
  15866. PEPROCESS Process
  15867. );
  15868. NTKERNELAPI
  15869. PVOID
  15870. PsGetProcessSectionBaseAddress(
  15871. PEPROCESS Process
  15872. );
  15873. #define PsGetProcessPcb(Process) ((PKPROCESS)(Process))
  15874. NTKERNELAPI
  15875. PPEB
  15876. PsGetProcessPeb(
  15877. PEPROCESS Process
  15878. );
  15879. NTKERNELAPI
  15880. UCHAR
  15881. PsGetProcessPriorityClass(
  15882. PEPROCESS Process
  15883. );
  15884. NTKERNELAPI
  15885. HANDLE
  15886. PsGetProcessWin32WindowStation(
  15887. PEPROCESS Process
  15888. );
  15889. #define PsGetCurrentProcessWin32WindowStation() PsGetProcessWin32WindowStation(PsGetCurrentProcess())
  15890. NTKERNELAPI
  15891. PVOID
  15892. PsGetProcessWin32Process(
  15893. PEPROCESS Process
  15894. );
  15895. #define PsGetCurrentProcessWin32Process() PsGetProcessWin32Process(PsGetCurrentProcess())
  15896. #if defined(_WIN64)
  15897. NTKERNELAPI
  15898. PVOID
  15899. PsGetProcessWow64Process(
  15900. PEPROCESS Process
  15901. );
  15902. #endif
  15903. NTKERNELAPI
  15904. HANDLE
  15905. PsGetThreadId(
  15906. PETHREAD Thread
  15907. );
  15908. NTKERNELAPI
  15909. CCHAR
  15910. PsGetThreadFreezeCount(
  15911. PETHREAD Thread
  15912. );
  15913. NTKERNELAPI
  15914. BOOLEAN
  15915. PsGetThreadHardErrorsAreDisabled(
  15916. PETHREAD Thread);
  15917. NTKERNELAPI
  15918. PEPROCESS
  15919. PsGetThreadProcess(
  15920. PETHREAD Thread
  15921. );
  15922. #define PsGetCurrentThreadProcess() PsGetThreadProcess(PsGetCurrentThread())
  15923. NTKERNELAPI
  15924. HANDLE
  15925. PsGetThreadProcessId(
  15926. PETHREAD Thread
  15927. );
  15928. #define PsGetCurrentThreadProcessId() PsGetThreadProcessId(PsGetCurrentThread())
  15929. NTKERNELAPI
  15930. ULONG
  15931. PsGetThreadSessionId(
  15932. PETHREAD Thread
  15933. );
  15934. #define PsGetThreadTcb(Thread) ((PKTHREAD)(Thread))
  15935. NTKERNELAPI
  15936. PVOID
  15937. PsGetThreadTeb(
  15938. PETHREAD Thread
  15939. );
  15940. #define PsGetCurrentThreadTeb() PsGetThreadTeb(PsGetCurrentThread())
  15941. NTKERNELAPI
  15942. PVOID
  15943. PsGetThreadWin32Thread(
  15944. PETHREAD Thread
  15945. );
  15946. #define PsGetCurrentThreadWin32Thread() PsGetThreadWin32Thread(PsGetCurrentThread())
  15947. NTKERNELAPI //ntifs
  15948. BOOLEAN //ntifs
  15949. PsIsSystemThread( //ntifs
  15950. PETHREAD Thread //ntifs
  15951. ); //ntifs
  15952. NTKERNELAPI
  15953. BOOLEAN
  15954. PsIsThreadImpersonating (
  15955. IN PETHREAD Thread
  15956. );
  15957. NTSTATUS
  15958. PsReferenceProcessFilePointer (
  15959. IN PEPROCESS Process,
  15960. OUT PVOID *pFilePointer
  15961. );
  15962. NTKERNELAPI
  15963. VOID
  15964. PsSetJobUIRestrictionsClass(
  15965. PEJOB Job,
  15966. ULONG UIRestrictionsClass
  15967. );
  15968. NTKERNELAPI
  15969. VOID
  15970. PsSetProcessPriorityClass(
  15971. PEPROCESS Process,
  15972. UCHAR PriorityClass
  15973. );
  15974. NTKERNELAPI
  15975. NTSTATUS
  15976. PsSetProcessWin32Process(
  15977. PEPROCESS Process,
  15978. PVOID Win32Process,
  15979. PVOID PrevWin32Proces
  15980. );
  15981. NTKERNELAPI
  15982. VOID
  15983. PsSetProcessWindowStation(
  15984. PEPROCESS Process,
  15985. HANDLE Win32WindowStation
  15986. );
  15987. NTKERNELAPI
  15988. VOID
  15989. PsSetThreadHardErrorsAreDisabled(
  15990. PETHREAD Thread,
  15991. BOOLEAN HardErrorsAreDisabled
  15992. );
  15993. NTKERNELAPI
  15994. VOID
  15995. PsSetThreadWin32Thread(
  15996. PETHREAD Thread,
  15997. PVOID Win32Thread,
  15998. PVOID PrevWin32Thread
  15999. );
  16000. NTKERNELAPI
  16001. PVOID
  16002. PsGetProcessSecurityPort(
  16003. PEPROCESS Process
  16004. );
  16005. NTKERNELAPI
  16006. NTSTATUS
  16007. PsSetProcessSecurityPort(
  16008. PEPROCESS Process,
  16009. PVOID Port
  16010. );
  16011. typedef
  16012. NTSTATUS
  16013. (*PROCESS_ENUM_ROUTINE)(
  16014. IN PEPROCESS Process,
  16015. IN PVOID Context
  16016. );
  16017. typedef
  16018. NTSTATUS
  16019. (*THREAD_ENUM_ROUTINE)(
  16020. IN PEPROCESS Process,
  16021. IN PETHREAD Thread,
  16022. IN PVOID Context
  16023. );
  16024. NTSTATUS
  16025. PsEnumProcesses (
  16026. IN PROCESS_ENUM_ROUTINE CallBack,
  16027. IN PVOID Context
  16028. );
  16029. NTSTATUS
  16030. PsEnumProcessThreads (
  16031. IN PEPROCESS Process,
  16032. IN THREAD_ENUM_ROUTINE CallBack,
  16033. IN PVOID Context
  16034. );
  16035. PEPROCESS
  16036. PsGetNextProcess (
  16037. IN PEPROCESS Process
  16038. );
  16039. PETHREAD
  16040. PsGetNextProcessThread (
  16041. IN PEPROCESS Process,
  16042. IN PETHREAD Thread
  16043. );
  16044. VOID
  16045. PsQuitNextProcess (
  16046. IN PEPROCESS Process
  16047. );
  16048. VOID
  16049. PsQuitNextProcessThread (
  16050. IN PETHREAD Thread
  16051. );
  16052. PEJOB
  16053. PsGetNextJob (
  16054. IN PEJOB Job
  16055. );
  16056. PEPROCESS
  16057. PsGetNextJobProcess (
  16058. IN PEJOB Job,
  16059. IN PEPROCESS Process
  16060. );
  16061. VOID
  16062. PsQuitNextJob (
  16063. IN PEJOB Job
  16064. );
  16065. VOID
  16066. PsQuitNextJobProcess (
  16067. IN PEPROCESS Process
  16068. );
  16069. NTSTATUS
  16070. PsSuspendProcess (
  16071. IN PEPROCESS Process
  16072. );
  16073. NTSTATUS
  16074. PsResumeProcess (
  16075. IN PEPROCESS Process
  16076. );
  16077. NTSTATUS
  16078. PsTerminateProcess(
  16079. IN PEPROCESS Process,
  16080. IN NTSTATUS Status
  16081. );
  16082. NTSTATUS
  16083. PsSuspendThread (
  16084. IN PETHREAD Thread,
  16085. OUT PULONG PreviousSuspendCount OPTIONAL
  16086. );
  16087. NTSTATUS
  16088. PsResumeThread (
  16089. IN PETHREAD Thread,
  16090. OUT PULONG PreviousSuspendCount OPTIONAL
  16091. );
  16092. #ifndef _WIN64
  16093. NTSTATUS
  16094. PsSetLdtEntries (
  16095. IN ULONG Selector0,
  16096. IN ULONG Entry0Low,
  16097. IN ULONG Entry0Hi,
  16098. IN ULONG Selector1,
  16099. IN ULONG Entry1Low,
  16100. IN ULONG Entry1Hi
  16101. );
  16102. NTSTATUS
  16103. PsSetProcessLdtInfo (
  16104. IN PPROCESS_LDT_INFORMATION LdtInformation,
  16105. IN ULONG LdtInformationLength
  16106. );
  16107. #endif
  16108. //
  16109. // Object Manager types
  16110. //
  16111. typedef struct _OBJECT_HANDLE_INFORMATION {
  16112. ULONG HandleAttributes;
  16113. ACCESS_MASK GrantedAccess;
  16114. } OBJECT_HANDLE_INFORMATION, *POBJECT_HANDLE_INFORMATION;
  16115. // end_ntddk end_wdm end_nthal end_ntifs
  16116. typedef struct _OBJECT_DUMP_CONTROL {
  16117. PVOID Stream;
  16118. ULONG Detail;
  16119. } OB_DUMP_CONTROL, *POB_DUMP_CONTROL;
  16120. typedef VOID (*OB_DUMP_METHOD)(
  16121. IN PVOID Object,
  16122. IN POB_DUMP_CONTROL Control OPTIONAL
  16123. );
  16124. typedef enum _OB_OPEN_REASON {
  16125. ObCreateHandle,
  16126. ObOpenHandle,
  16127. ObDuplicateHandle,
  16128. ObInheritHandle,
  16129. ObMaxOpenReason
  16130. } OB_OPEN_REASON;
  16131. typedef NTSTATUS (*OB_OPEN_METHOD)(
  16132. IN OB_OPEN_REASON OpenReason,
  16133. IN PEPROCESS Process OPTIONAL,
  16134. IN PVOID Object,
  16135. IN ACCESS_MASK GrantedAccess,
  16136. IN ULONG HandleCount
  16137. );
  16138. typedef BOOLEAN (*OB_OKAYTOCLOSE_METHOD)(
  16139. IN PEPROCESS Process OPTIONAL,
  16140. IN PVOID Object,
  16141. IN HANDLE Handle,
  16142. IN KPROCESSOR_MODE PreviousMode
  16143. );
  16144. typedef VOID (*OB_CLOSE_METHOD)(
  16145. IN PEPROCESS Process OPTIONAL,
  16146. IN PVOID Object,
  16147. IN ACCESS_MASK GrantedAccess,
  16148. IN ULONG_PTR ProcessHandleCount,
  16149. IN ULONG_PTR SystemHandleCount
  16150. );
  16151. typedef VOID (*OB_DELETE_METHOD)(
  16152. IN PVOID Object
  16153. );
  16154. typedef NTSTATUS (*OB_PARSE_METHOD)(
  16155. IN PVOID ParseObject,
  16156. IN PVOID ObjectType,
  16157. IN OUT PACCESS_STATE AccessState,
  16158. IN KPROCESSOR_MODE AccessMode,
  16159. IN ULONG Attributes,
  16160. IN OUT PUNICODE_STRING CompleteName,
  16161. IN OUT PUNICODE_STRING RemainingName,
  16162. IN OUT PVOID Context OPTIONAL,
  16163. IN PSECURITY_QUALITY_OF_SERVICE SecurityQos OPTIONAL,
  16164. OUT PVOID *Object
  16165. );
  16166. typedef NTSTATUS (*OB_SECURITY_METHOD)(
  16167. IN PVOID Object,
  16168. IN SECURITY_OPERATION_CODE OperationCode,
  16169. IN PSECURITY_INFORMATION SecurityInformation,
  16170. IN OUT PSECURITY_DESCRIPTOR SecurityDescriptor,
  16171. IN OUT PULONG CapturedLength,
  16172. IN OUT PSECURITY_DESCRIPTOR *ObjectsSecurityDescriptor,
  16173. IN POOL_TYPE PoolType,
  16174. IN PGENERIC_MAPPING GenericMapping
  16175. );
  16176. typedef NTSTATUS (*OB_QUERYNAME_METHOD)(
  16177. IN PVOID Object,
  16178. IN BOOLEAN HasObjectName,
  16179. OUT POBJECT_NAME_INFORMATION ObjectNameInfo,
  16180. IN ULONG Length,
  16181. OUT PULONG ReturnLength,
  16182. IN KPROCESSOR_MODE Mode
  16183. );
  16184. /*
  16185. A security method and its caller must obey the following w.r.t.
  16186. capturing and probing parameters:
  16187. For a query operation, the caller must pass a kernel space address for
  16188. CapturedLength. The caller should be able to assume that it points to
  16189. valid data that will not change. In addition, the SecurityDescriptor
  16190. parameter (which will receive the result of the query operation) must
  16191. be probed for write up to the length given in CapturedLength. The
  16192. security method itself must always write to the SecurityDescriptor
  16193. buffer in a try clause in case the caller de-allocates it.
  16194. For a set operation, the SecurityDescriptor parameter must have
  16195. been captured via SeCaptureSecurityDescriptor. This parameter is
  16196. not optional, and therefore may not be NULL.
  16197. */
  16198. //
  16199. // Prototypes for Win32 WindowStation and Desktop object callout routines
  16200. //
  16201. typedef struct _WIN32_OPENMETHOD_PARAMETERS {
  16202. OB_OPEN_REASON OpenReason;
  16203. PEPROCESS Process;
  16204. PVOID Object;
  16205. ACCESS_MASK GrantedAccess;
  16206. ULONG HandleCount;
  16207. } WIN32_OPENMETHOD_PARAMETERS, *PKWIN32_OPENMETHOD_PARAMETERS;
  16208. typedef
  16209. NTSTATUS
  16210. (*PKWIN32_OPENMETHOD_CALLOUT) ( PKWIN32_OPENMETHOD_PARAMETERS );
  16211. extern PKWIN32_OPENMETHOD_CALLOUT ExDesktopOpenProcedureCallout;
  16212. extern PKWIN32_OPENMETHOD_CALLOUT ExWindowStationOpenProcedureCallout;
  16213. typedef struct _WIN32_OKAYTOCLOSEMETHOD_PARAMETERS {
  16214. PEPROCESS Process;
  16215. PVOID Object;
  16216. HANDLE Handle;
  16217. KPROCESSOR_MODE PreviousMode;
  16218. } WIN32_OKAYTOCLOSEMETHOD_PARAMETERS, *PKWIN32_OKAYTOCLOSEMETHOD_PARAMETERS;
  16219. typedef
  16220. NTSTATUS
  16221. (*PKWIN32_OKTOCLOSEMETHOD_CALLOUT) ( PKWIN32_OKAYTOCLOSEMETHOD_PARAMETERS );
  16222. extern PKWIN32_OKTOCLOSEMETHOD_CALLOUT ExDesktopOkToCloseProcedureCallout;
  16223. extern PKWIN32_OKTOCLOSEMETHOD_CALLOUT ExWindowStationOkToCloseProcedureCallout;
  16224. typedef struct _WIN32_CLOSEMETHOD_PARAMETERS {
  16225. PEPROCESS Process;
  16226. PVOID Object;
  16227. ACCESS_MASK GrantedAccess;
  16228. ULONG ProcessHandleCount;
  16229. ULONG SystemHandleCount;
  16230. } WIN32_CLOSEMETHOD_PARAMETERS, *PKWIN32_CLOSEMETHOD_PARAMETERS;
  16231. typedef
  16232. NTSTATUS
  16233. (*PKWIN32_CLOSEMETHOD_CALLOUT) ( PKWIN32_CLOSEMETHOD_PARAMETERS );
  16234. extern PKWIN32_CLOSEMETHOD_CALLOUT ExDesktopCloseProcedureCallout;
  16235. extern PKWIN32_CLOSEMETHOD_CALLOUT ExWindowStationCloseProcedureCallout;
  16236. typedef struct _WIN32_DELETEMETHOD_PARAMETERS {
  16237. PVOID Object;
  16238. } WIN32_DELETEMETHOD_PARAMETERS, *PKWIN32_DELETEMETHOD_PARAMETERS;
  16239. typedef
  16240. NTSTATUS
  16241. (*PKWIN32_DELETEMETHOD_CALLOUT) ( PKWIN32_DELETEMETHOD_PARAMETERS );
  16242. extern PKWIN32_DELETEMETHOD_CALLOUT ExDesktopDeleteProcedureCallout;
  16243. extern PKWIN32_DELETEMETHOD_CALLOUT ExWindowStationDeleteProcedureCallout;
  16244. typedef struct _WIN32_PARSEMETHOD_PARAMETERS {
  16245. PVOID ParseObject;
  16246. PVOID ObjectType;
  16247. PACCESS_STATE AccessState;
  16248. KPROCESSOR_MODE AccessMode;
  16249. ULONG Attributes;
  16250. PUNICODE_STRING CompleteName;
  16251. PUNICODE_STRING RemainingName;
  16252. PVOID Context OPTIONAL;
  16253. PSECURITY_QUALITY_OF_SERVICE SecurityQos;
  16254. PVOID *Object;
  16255. } WIN32_PARSEMETHOD_PARAMETERS, *PKWIN32_PARSEMETHOD_PARAMETERS;
  16256. typedef
  16257. NTSTATUS
  16258. (*PKWIN32_PARSEMETHOD_CALLOUT) ( PKWIN32_PARSEMETHOD_PARAMETERS );
  16259. extern PKWIN32_PARSEMETHOD_CALLOUT ExWindowStationParseProcedureCallout;
  16260. //
  16261. // Object Type Structure
  16262. //
  16263. typedef struct _OBJECT_TYPE_INITIALIZER {
  16264. USHORT Length;
  16265. BOOLEAN UseDefaultObject;
  16266. BOOLEAN CaseInsensitive;
  16267. ULONG InvalidAttributes;
  16268. GENERIC_MAPPING GenericMapping;
  16269. ULONG ValidAccessMask;
  16270. BOOLEAN SecurityRequired;
  16271. BOOLEAN MaintainHandleCount;
  16272. BOOLEAN MaintainTypeList;
  16273. POOL_TYPE PoolType;
  16274. ULONG DefaultPagedPoolCharge;
  16275. ULONG DefaultNonPagedPoolCharge;
  16276. OB_DUMP_METHOD DumpProcedure;
  16277. OB_OPEN_METHOD OpenProcedure;
  16278. OB_CLOSE_METHOD CloseProcedure;
  16279. OB_DELETE_METHOD DeleteProcedure;
  16280. OB_PARSE_METHOD ParseProcedure;
  16281. OB_SECURITY_METHOD SecurityProcedure;
  16282. OB_QUERYNAME_METHOD QueryNameProcedure;
  16283. OB_OKAYTOCLOSE_METHOD OkayToCloseProcedure;
  16284. } OBJECT_TYPE_INITIALIZER, *POBJECT_TYPE_INITIALIZER;
  16285. #define OBJECT_LOCK_COUNT 4
  16286. typedef struct _OBJECT_TYPE {
  16287. ERESOURCE Mutex;
  16288. LIST_ENTRY TypeList;
  16289. UNICODE_STRING Name; // Copy from object header for convenience
  16290. PVOID DefaultObject;
  16291. ULONG Index;
  16292. ULONG TotalNumberOfObjects;
  16293. ULONG TotalNumberOfHandles;
  16294. ULONG HighWaterNumberOfObjects;
  16295. ULONG HighWaterNumberOfHandles;
  16296. OBJECT_TYPE_INITIALIZER TypeInfo;
  16297. #ifdef POOL_TAGGING
  16298. ULONG Key;
  16299. #endif //POOL_TAGGING
  16300. ERESOURCE ObjectLocks[ OBJECT_LOCK_COUNT ];
  16301. } OBJECT_TYPE, *POBJECT_TYPE;
  16302. //
  16303. // Object Directory Structure
  16304. //
  16305. #define NUMBER_HASH_BUCKETS 37
  16306. #define OBJ_INVALID_SESSION_ID 0xFFFFFFFF
  16307. typedef struct _OBJECT_DIRECTORY {
  16308. struct _OBJECT_DIRECTORY_ENTRY *HashBuckets[ NUMBER_HASH_BUCKETS ];
  16309. EX_PUSH_LOCK Lock;
  16310. struct _DEVICE_MAP *DeviceMap;
  16311. ULONG SessionId;
  16312. #if 0
  16313. USHORT Reserved;
  16314. USHORT SymbolicLinkUsageCount;
  16315. #endif
  16316. } OBJECT_DIRECTORY, *POBJECT_DIRECTORY;
  16317. typedef struct _OBJECT_CREATE_INFORMATION *POBJECT_CREATE_INFORMATION;;
  16318. typedef struct _OBJECT_HEADER {
  16319. LONG_PTR PointerCount;
  16320. union {
  16321. LONG_PTR HandleCount;
  16322. PVOID NextToFree;
  16323. };
  16324. POBJECT_TYPE Type;
  16325. UCHAR NameInfoOffset;
  16326. UCHAR HandleInfoOffset;
  16327. UCHAR QuotaInfoOffset;
  16328. UCHAR Flags;
  16329. union {
  16330. POBJECT_CREATE_INFORMATION ObjectCreateInfo;
  16331. PVOID QuotaBlockCharged;
  16332. };
  16333. PSECURITY_DESCRIPTOR SecurityDescriptor;
  16334. QUAD Body;
  16335. } OBJECT_HEADER, *POBJECT_HEADER;
  16336. typedef struct _OBJECT_HEADER_NAME_INFO {
  16337. POBJECT_DIRECTORY Directory;
  16338. UNICODE_STRING Name;
  16339. ULONG QueryReferences;
  16340. #if DBG
  16341. ULONG Reserved2;
  16342. LONG DbgDereferenceCount;
  16343. #ifdef _WIN64
  16344. ULONG64 Reserved3; // Win64 requires these structures to be 16 byte aligned.
  16345. #endif
  16346. #endif
  16347. } OBJECT_HEADER_NAME_INFO, *POBJECT_HEADER_NAME_INFO;
  16348. #define OBJECT_TO_OBJECT_HEADER( o ) \
  16349. CONTAINING_RECORD( (o), OBJECT_HEADER, Body )
  16350. #define OBJECT_HEADER_TO_NAME_INFO( oh ) ((POBJECT_HEADER_NAME_INFO) \
  16351. ((oh)->NameInfoOffset == 0 ? NULL : ((PCHAR)(oh) - (oh)->NameInfoOffset)))
  16352. #define OBJECT_HEADER_TO_CREATOR_INFO( oh ) ((POBJECT_HEADER_CREATOR_INFO) \
  16353. (((oh)->Flags & OB_FLAG_CREATOR_INFO) == 0 ? NULL : ((PCHAR)(oh) - sizeof(OBJECT_HEADER_CREATOR_INFO))))
  16354. NTKERNELAPI
  16355. NTSTATUS
  16356. ObCreateObjectType(
  16357. IN PUNICODE_STRING TypeName,
  16358. IN POBJECT_TYPE_INITIALIZER ObjectTypeInitializer,
  16359. IN PSECURITY_DESCRIPTOR SecurityDescriptor OPTIONAL,
  16360. OUT POBJECT_TYPE *ObjectType
  16361. );
  16362. #define OBJ_PROTECT_CLOSE 0x00000001L
  16363. NTKERNELAPI
  16364. VOID
  16365. ObDeleteCapturedInsertInfo(
  16366. IN PVOID Object
  16367. );
  16368. NTKERNELAPI
  16369. NTSTATUS
  16370. ObCreateObject(
  16371. IN KPROCESSOR_MODE ProbeMode,
  16372. IN POBJECT_TYPE ObjectType,
  16373. IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL,
  16374. IN KPROCESSOR_MODE OwnershipMode,
  16375. IN OUT PVOID ParseContext OPTIONAL,
  16376. IN ULONG ObjectBodySize,
  16377. IN ULONG PagedPoolCharge,
  16378. IN ULONG NonPagedPoolCharge,
  16379. OUT PVOID *Object
  16380. );
  16381. //
  16382. // These inlines correct an issue where the compiler refetches
  16383. // the output object over and over again because it thinks its
  16384. // a possible alias for other stores.
  16385. //
  16386. FORCEINLINE
  16387. NTSTATUS
  16388. _ObCreateObject(
  16389. IN KPROCESSOR_MODE ProbeMode,
  16390. IN POBJECT_TYPE ObjectType,
  16391. IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL,
  16392. IN KPROCESSOR_MODE OwnershipMode,
  16393. IN OUT PVOID ParseContext OPTIONAL,
  16394. IN ULONG ObjectBodySize,
  16395. IN ULONG PagedPoolCharge,
  16396. IN ULONG NonPagedPoolCharge,
  16397. OUT PVOID *pObject
  16398. )
  16399. {
  16400. PVOID Object;
  16401. NTSTATUS Status;
  16402. Status = ObCreateObject (ProbeMode,
  16403. ObjectType,
  16404. ObjectAttributes,
  16405. OwnershipMode,
  16406. ParseContext,
  16407. ObjectBodySize,
  16408. PagedPoolCharge,
  16409. NonPagedPoolCharge,
  16410. &Object);
  16411. *pObject = Object;
  16412. return Status;
  16413. }
  16414. #define ObCreateObject _ObCreateObject
  16415. NTKERNELAPI
  16416. NTSTATUS
  16417. ObInsertObject(
  16418. IN PVOID Object,
  16419. IN PACCESS_STATE PassedAccessState OPTIONAL,
  16420. IN ACCESS_MASK DesiredAccess OPTIONAL,
  16421. IN ULONG ObjectPointerBias,
  16422. OUT PVOID *NewObject OPTIONAL,
  16423. OUT PHANDLE Handle OPTIONAL
  16424. );
  16425. // end_nthal
  16426. NTKERNELAPI // ntddk wdm nthal ntifs
  16427. NTSTATUS // ntddk wdm nthal ntifs
  16428. ObReferenceObjectByHandle( // ntddk wdm nthal ntifs
  16429. IN HANDLE Handle, // ntddk wdm nthal ntifs
  16430. IN ACCESS_MASK DesiredAccess, // ntddk wdm nthal ntifs
  16431. IN POBJECT_TYPE ObjectType OPTIONAL, // ntddk wdm nthal ntifs
  16432. IN KPROCESSOR_MODE AccessMode, // ntddk wdm nthal ntifs
  16433. OUT PVOID *Object, // ntddk wdm nthal ntifs
  16434. OUT POBJECT_HANDLE_INFORMATION HandleInformation OPTIONAL // ntddk wdm nthal ntifs
  16435. ); // ntddk wdm nthal ntifs
  16436. FORCEINLINE
  16437. NTSTATUS
  16438. _ObReferenceObjectByHandle(
  16439. IN HANDLE Handle,
  16440. IN ACCESS_MASK DesiredAccess,
  16441. IN POBJECT_TYPE ObjectType OPTIONAL,
  16442. IN KPROCESSOR_MODE AccessMode,
  16443. OUT PVOID *pObject,
  16444. OUT POBJECT_HANDLE_INFORMATION pHandleInformation OPTIONAL
  16445. )
  16446. {
  16447. PVOID Object;
  16448. NTSTATUS Status;
  16449. Status = ObReferenceObjectByHandle (Handle,
  16450. DesiredAccess,
  16451. ObjectType,
  16452. AccessMode,
  16453. &Object,
  16454. pHandleInformation);
  16455. *pObject = Object;
  16456. return Status;
  16457. }
  16458. #define ObReferenceObjectByHandle _ObReferenceObjectByHandle
  16459. NTKERNELAPI
  16460. NTSTATUS
  16461. ObReferenceFileObjectForWrite(
  16462. IN HANDLE Handle,
  16463. IN KPROCESSOR_MODE AccessMode,
  16464. OUT PVOID *FileObject,
  16465. OUT POBJECT_HANDLE_INFORMATION HandleInformation
  16466. );
  16467. NTKERNELAPI
  16468. NTSTATUS
  16469. ObOpenObjectByName(
  16470. IN POBJECT_ATTRIBUTES ObjectAttributes,
  16471. IN POBJECT_TYPE ObjectType,
  16472. IN KPROCESSOR_MODE AccessMode,
  16473. IN OUT PACCESS_STATE PassedAccessState OPTIONAL,
  16474. IN ACCESS_MASK DesiredAccess OPTIONAL,
  16475. IN OUT PVOID ParseContext OPTIONAL,
  16476. OUT PHANDLE Handle
  16477. );
  16478. NTKERNELAPI // ntifs
  16479. NTSTATUS // ntifs
  16480. ObOpenObjectByPointer( // ntifs
  16481. IN PVOID Object, // ntifs
  16482. IN ULONG HandleAttributes, // ntifs
  16483. IN PACCESS_STATE PassedAccessState OPTIONAL, // ntifs
  16484. IN ACCESS_MASK DesiredAccess OPTIONAL, // ntifs
  16485. IN POBJECT_TYPE ObjectType OPTIONAL, // ntifs
  16486. IN KPROCESSOR_MODE AccessMode, // ntifs
  16487. OUT PHANDLE Handle // ntifs
  16488. ); // ntifs
  16489. NTSTATUS
  16490. ObReferenceObjectByName(
  16491. IN PUNICODE_STRING ObjectName,
  16492. IN ULONG Attributes,
  16493. IN PACCESS_STATE PassedAccessState OPTIONAL,
  16494. IN ACCESS_MASK DesiredAccess OPTIONAL,
  16495. IN POBJECT_TYPE ObjectType,
  16496. IN KPROCESSOR_MODE AccessMode,
  16497. IN OUT PVOID ParseContext OPTIONAL,
  16498. OUT PVOID *Object
  16499. );
  16500. NTKERNELAPI
  16501. BOOLEAN
  16502. ObFindHandleForObject(
  16503. IN PEPROCESS Process,
  16504. IN PVOID Object,
  16505. IN POBJECT_TYPE ObjectType OPTIONAL,
  16506. IN POBJECT_HANDLE_INFORMATION MatchCriteria OPTIONAL,
  16507. OUT PHANDLE Handle
  16508. );
  16509. // begin_ntddk begin_wdm begin_nthal begin_ntifs
  16510. #define ObDereferenceObject(a) \
  16511. ObfDereferenceObject(a)
  16512. #define ObReferenceObject(Object) ObfReferenceObject(Object)
  16513. NTKERNELAPI
  16514. LONG_PTR
  16515. FASTCALL
  16516. ObfReferenceObject(
  16517. IN PVOID Object
  16518. );
  16519. NTKERNELAPI
  16520. NTSTATUS
  16521. ObReferenceObjectByPointer(
  16522. IN PVOID Object,
  16523. IN ACCESS_MASK DesiredAccess,
  16524. IN POBJECT_TYPE ObjectType,
  16525. IN KPROCESSOR_MODE AccessMode
  16526. );
  16527. NTKERNELAPI
  16528. LONG_PTR
  16529. FASTCALL
  16530. ObfDereferenceObject(
  16531. IN PVOID Object
  16532. );
  16533. NTKERNELAPI
  16534. NTSTATUS
  16535. ObQueryNameString(
  16536. IN PVOID Object,
  16537. OUT POBJECT_NAME_INFORMATION ObjectNameInfo,
  16538. IN ULONG Length,
  16539. OUT PULONG ReturnLength
  16540. );
  16541. NTSTATUS
  16542. ObGetObjectSecurity(
  16543. IN PVOID Object,
  16544. OUT PSECURITY_DESCRIPTOR *SecurityDescriptor,
  16545. OUT PBOOLEAN MemoryAllocated
  16546. );
  16547. VOID
  16548. ObReleaseObjectSecurity(
  16549. IN PSECURITY_DESCRIPTOR SecurityDescriptor,
  16550. IN BOOLEAN MemoryAllocated
  16551. );
  16552. // end_ntifs end_ntddk end_wdm
  16553. NTSTATUS
  16554. ObLogSecurityDescriptor (
  16555. IN PSECURITY_DESCRIPTOR InputSecurityDescriptor,
  16556. OUT PSECURITY_DESCRIPTOR *OutputSecurityDescriptor,
  16557. ULONG RefBias
  16558. );
  16559. VOID
  16560. ObDereferenceSecurityDescriptor (
  16561. PSECURITY_DESCRIPTOR SecurityDescriptor,
  16562. ULONG Count
  16563. );
  16564. VOID
  16565. ObReferenceSecurityDescriptor (
  16566. IN PSECURITY_DESCRIPTOR SecurityDescriptor,
  16567. IN ULONG Count
  16568. );
  16569. NTKERNELAPI
  16570. BOOLEAN
  16571. ObCheckCreateObjectAccess(
  16572. IN PVOID DirectoryObject,
  16573. IN ACCESS_MASK CreateAccess,
  16574. IN PACCESS_STATE AccessState OPTIONAL,
  16575. IN PUNICODE_STRING ComponentName,
  16576. IN BOOLEAN TypeMutexLocked,
  16577. IN KPROCESSOR_MODE PreviousMode,
  16578. OUT PNTSTATUS AccessStatus
  16579. );
  16580. NTKERNELAPI
  16581. BOOLEAN
  16582. ObCheckObjectAccess(
  16583. IN PVOID Object,
  16584. IN PACCESS_STATE AccessState,
  16585. IN BOOLEAN TypeMutexLocked,
  16586. IN KPROCESSOR_MODE AccessMode,
  16587. OUT PNTSTATUS AccessStatus
  16588. );
  16589. NTKERNELAPI
  16590. NTSTATUS
  16591. ObAssignSecurity(
  16592. IN PACCESS_STATE AccessState,
  16593. IN PSECURITY_DESCRIPTOR ParentDescriptor OPTIONAL,
  16594. IN PVOID Object,
  16595. IN POBJECT_TYPE ObjectType
  16596. );
  16597. NTSTATUS
  16598. ObSetSecurityObjectByPointer (
  16599. IN PVOID Object,
  16600. IN SECURITY_INFORMATION SecurityInformation,
  16601. IN PSECURITY_DESCRIPTOR SecurityDescriptor
  16602. );
  16603. NTSTATUS
  16604. ObSetHandleAttributes (
  16605. IN HANDLE Handle,
  16606. IN POBJECT_HANDLE_FLAG_INFORMATION HandleFlags,
  16607. IN KPROCESSOR_MODE PreviousMode
  16608. );
  16609. NTSTATUS
  16610. ObCloseHandle (
  16611. IN HANDLE Handle,
  16612. IN KPROCESSOR_MODE PreviousMode
  16613. );
  16614. NTSTATUS
  16615. ObSwapObjectNames (
  16616. IN HANDLE DirectoryHandle,
  16617. IN HANDLE Handle1,
  16618. IN HANDLE Handle2,
  16619. IN ULONG Flags
  16620. );
  16621. NTKERNELAPI
  16622. NTSTATUS
  16623. ObSetSecurityDescriptorInfo(
  16624. IN PVOID Object,
  16625. IN PSECURITY_INFORMATION SecurityInformation,
  16626. IN OUT PSECURITY_DESCRIPTOR SecurityDescriptor,
  16627. IN OUT PSECURITY_DESCRIPTOR *ObjectsSecurityDescriptor,
  16628. IN POOL_TYPE PoolType,
  16629. IN PGENERIC_MAPPING GenericMapping
  16630. );
  16631. //
  16632. // A PCI driver can read the complete 256 bytes of configuration
  16633. // information for any PCI device by calling:
  16634. //
  16635. // ULONG
  16636. // HalGetBusData (
  16637. // IN BUS_DATA_TYPE PCIConfiguration,
  16638. // IN ULONG PciBusNumber,
  16639. // IN PCI_SLOT_NUMBER VirtualSlotNumber,
  16640. // IN PPCI_COMMON_CONFIG &PCIDeviceConfig,
  16641. // IN ULONG sizeof (PCIDeviceConfig)
  16642. // );
  16643. //
  16644. // A return value of 0 means that the specified PCI bus does not exist.
  16645. //
  16646. // A return value of 2, with a VendorID of PCI_INVALID_VENDORID means
  16647. // that the PCI bus does exist, but there is no device at the specified
  16648. // VirtualSlotNumber (PCI Device/Function number).
  16649. //
  16650. //
  16651. // begin_wdm begin_ntminiport begin_ntndis
  16652. typedef struct _PCI_SLOT_NUMBER {
  16653. union {
  16654. struct {
  16655. ULONG DeviceNumber:5;
  16656. ULONG FunctionNumber:3;
  16657. ULONG Reserved:24;
  16658. } bits;
  16659. ULONG AsULONG;
  16660. } u;
  16661. } PCI_SLOT_NUMBER, *PPCI_SLOT_NUMBER;
  16662. #define PCI_TYPE0_ADDRESSES 6
  16663. #define PCI_TYPE1_ADDRESSES 2
  16664. #define PCI_TYPE2_ADDRESSES 5
  16665. typedef struct _PCI_COMMON_CONFIG {
  16666. USHORT VendorID; // (ro)
  16667. USHORT DeviceID; // (ro)
  16668. USHORT Command; // Device control
  16669. USHORT Status;
  16670. UCHAR RevisionID; // (ro)
  16671. UCHAR ProgIf; // (ro)
  16672. UCHAR SubClass; // (ro)
  16673. UCHAR BaseClass; // (ro)
  16674. UCHAR CacheLineSize; // (ro+)
  16675. UCHAR LatencyTimer; // (ro+)
  16676. UCHAR HeaderType; // (ro)
  16677. UCHAR BIST; // Built in self test
  16678. union {
  16679. struct _PCI_HEADER_TYPE_0 {
  16680. ULONG BaseAddresses[PCI_TYPE0_ADDRESSES];
  16681. ULONG CIS;
  16682. USHORT SubVendorID;
  16683. USHORT SubSystemID;
  16684. ULONG ROMBaseAddress;
  16685. UCHAR CapabilitiesPtr;
  16686. UCHAR Reserved1[3];
  16687. ULONG Reserved2;
  16688. UCHAR InterruptLine; //
  16689. UCHAR InterruptPin; // (ro)
  16690. UCHAR MinimumGrant; // (ro)
  16691. UCHAR MaximumLatency; // (ro)
  16692. } type0;
  16693. // end_wdm end_ntminiport end_ntndis
  16694. //
  16695. // PCI to PCI Bridge
  16696. //
  16697. struct _PCI_HEADER_TYPE_1 {
  16698. ULONG BaseAddresses[PCI_TYPE1_ADDRESSES];
  16699. UCHAR PrimaryBus;
  16700. UCHAR SecondaryBus;
  16701. UCHAR SubordinateBus;
  16702. UCHAR SecondaryLatency;
  16703. UCHAR IOBase;
  16704. UCHAR IOLimit;
  16705. USHORT SecondaryStatus;
  16706. USHORT MemoryBase;
  16707. USHORT MemoryLimit;
  16708. USHORT PrefetchBase;
  16709. USHORT PrefetchLimit;
  16710. ULONG PrefetchBaseUpper32;
  16711. ULONG PrefetchLimitUpper32;
  16712. USHORT IOBaseUpper16;
  16713. USHORT IOLimitUpper16;
  16714. UCHAR CapabilitiesPtr;
  16715. UCHAR Reserved1[3];
  16716. ULONG ROMBaseAddress;
  16717. UCHAR InterruptLine;
  16718. UCHAR InterruptPin;
  16719. USHORT BridgeControl;
  16720. } type1;
  16721. //
  16722. // PCI to CARDBUS Bridge
  16723. //
  16724. struct _PCI_HEADER_TYPE_2 {
  16725. ULONG SocketRegistersBaseAddress;
  16726. UCHAR CapabilitiesPtr;
  16727. UCHAR Reserved;
  16728. USHORT SecondaryStatus;
  16729. UCHAR PrimaryBus;
  16730. UCHAR SecondaryBus;
  16731. UCHAR SubordinateBus;
  16732. UCHAR SecondaryLatency;
  16733. struct {
  16734. ULONG Base;
  16735. ULONG Limit;
  16736. } Range[PCI_TYPE2_ADDRESSES-1];
  16737. UCHAR InterruptLine;
  16738. UCHAR InterruptPin;
  16739. USHORT BridgeControl;
  16740. } type2;
  16741. // begin_wdm begin_ntminiport begin_ntndis
  16742. } u;
  16743. UCHAR DeviceSpecific[192];
  16744. } PCI_COMMON_CONFIG, *PPCI_COMMON_CONFIG;
  16745. #define PCI_COMMON_HDR_LENGTH (FIELD_OFFSET (PCI_COMMON_CONFIG, DeviceSpecific))
  16746. #define PCI_MAX_DEVICES 32
  16747. #define PCI_MAX_FUNCTION 8
  16748. #define PCI_MAX_BRIDGE_NUMBER 0xFF
  16749. #define PCI_INVALID_VENDORID 0xFFFF
  16750. //
  16751. // Bit encodings for PCI_COMMON_CONFIG.HeaderType
  16752. //
  16753. #define PCI_MULTIFUNCTION 0x80
  16754. #define PCI_DEVICE_TYPE 0x00
  16755. #define PCI_BRIDGE_TYPE 0x01
  16756. #define PCI_CARDBUS_BRIDGE_TYPE 0x02
  16757. #define PCI_CONFIGURATION_TYPE(PciData) \
  16758. (((PPCI_COMMON_CONFIG)(PciData))->HeaderType & ~PCI_MULTIFUNCTION)
  16759. #define PCI_MULTIFUNCTION_DEVICE(PciData) \
  16760. ((((PPCI_COMMON_CONFIG)(PciData))->HeaderType & PCI_MULTIFUNCTION) != 0)
  16761. //
  16762. // Bit encodings for PCI_COMMON_CONFIG.Command
  16763. //
  16764. #define PCI_ENABLE_IO_SPACE 0x0001
  16765. #define PCI_ENABLE_MEMORY_SPACE 0x0002
  16766. #define PCI_ENABLE_BUS_MASTER 0x0004
  16767. #define PCI_ENABLE_SPECIAL_CYCLES 0x0008
  16768. #define PCI_ENABLE_WRITE_AND_INVALIDATE 0x0010
  16769. #define PCI_ENABLE_VGA_COMPATIBLE_PALETTE 0x0020
  16770. #define PCI_ENABLE_PARITY 0x0040 // (ro+)
  16771. #define PCI_ENABLE_WAIT_CYCLE 0x0080 // (ro+)
  16772. #define PCI_ENABLE_SERR 0x0100 // (ro+)
  16773. #define PCI_ENABLE_FAST_BACK_TO_BACK 0x0200 // (ro)
  16774. //
  16775. // Bit encodings for PCI_COMMON_CONFIG.Status
  16776. //
  16777. #define PCI_STATUS_CAPABILITIES_LIST 0x0010 // (ro)
  16778. #define PCI_STATUS_66MHZ_CAPABLE 0x0020 // (ro)
  16779. #define PCI_STATUS_UDF_SUPPORTED 0x0040 // (ro)
  16780. #define PCI_STATUS_FAST_BACK_TO_BACK 0x0080 // (ro)
  16781. #define PCI_STATUS_DATA_PARITY_DETECTED 0x0100
  16782. #define PCI_STATUS_DEVSEL 0x0600 // 2 bits wide
  16783. #define PCI_STATUS_SIGNALED_TARGET_ABORT 0x0800
  16784. #define PCI_STATUS_RECEIVED_TARGET_ABORT 0x1000
  16785. #define PCI_STATUS_RECEIVED_MASTER_ABORT 0x2000
  16786. #define PCI_STATUS_SIGNALED_SYSTEM_ERROR 0x4000
  16787. #define PCI_STATUS_DETECTED_PARITY_ERROR 0x8000
  16788. //
  16789. // The NT PCI Driver uses a WhichSpace parameter on its CONFIG_READ/WRITE
  16790. // routines. The following values are defined-
  16791. //
  16792. #define PCI_WHICHSPACE_CONFIG 0x0
  16793. #define PCI_WHICHSPACE_ROM 0x52696350
  16794. // end_wdm
  16795. //
  16796. // PCI Capability IDs
  16797. //
  16798. #define PCI_CAPABILITY_ID_POWER_MANAGEMENT 0x01
  16799. #define PCI_CAPABILITY_ID_AGP 0x02
  16800. #define PCI_CAPABILITY_ID_MSI 0x05
  16801. #define PCI_CAPABILITY_ID_AGP_TARGET 0x0E
  16802. //
  16803. // All PCI Capability structures have the following header.
  16804. //
  16805. // CapabilityID is used to identify the type of the structure (is
  16806. // one of the PCI_CAPABILITY_ID values above.
  16807. //
  16808. // Next is the offset in PCI Configuration space (0x40 - 0xfc) of the
  16809. // next capability structure in the list, or 0x00 if there are no more
  16810. // entries.
  16811. //
  16812. typedef struct _PCI_CAPABILITIES_HEADER {
  16813. UCHAR CapabilityID;
  16814. UCHAR Next;
  16815. } PCI_CAPABILITIES_HEADER, *PPCI_CAPABILITIES_HEADER;
  16816. //
  16817. // Power Management Capability
  16818. //
  16819. typedef struct _PCI_PMC {
  16820. UCHAR Version:3;
  16821. UCHAR PMEClock:1;
  16822. UCHAR Rsvd1:1;
  16823. UCHAR DeviceSpecificInitialization:1;
  16824. UCHAR Rsvd2:2;
  16825. struct _PM_SUPPORT {
  16826. UCHAR Rsvd2:1;
  16827. UCHAR D1:1;
  16828. UCHAR D2:1;
  16829. UCHAR PMED0:1;
  16830. UCHAR PMED1:1;
  16831. UCHAR PMED2:1;
  16832. UCHAR PMED3Hot:1;
  16833. UCHAR PMED3Cold:1;
  16834. } Support;
  16835. } PCI_PMC, *PPCI_PMC;
  16836. typedef struct _PCI_PMCSR {
  16837. USHORT PowerState:2;
  16838. USHORT Rsvd1:6;
  16839. USHORT PMEEnable:1;
  16840. USHORT DataSelect:4;
  16841. USHORT DataScale:2;
  16842. USHORT PMEStatus:1;
  16843. } PCI_PMCSR, *PPCI_PMCSR;
  16844. typedef struct _PCI_PMCSR_BSE {
  16845. UCHAR Rsvd1:6;
  16846. UCHAR D3HotSupportsStopClock:1; // B2_B3#
  16847. UCHAR BusPowerClockControlEnabled:1; // BPCC_EN
  16848. } PCI_PMCSR_BSE, *PPCI_PMCSR_BSE;
  16849. typedef struct _PCI_PM_CAPABILITY {
  16850. PCI_CAPABILITIES_HEADER Header;
  16851. //
  16852. // Power Management Capabilities (Offset = 2)
  16853. //
  16854. union {
  16855. PCI_PMC Capabilities;
  16856. USHORT AsUSHORT;
  16857. } PMC;
  16858. //
  16859. // Power Management Control/Status (Offset = 4)
  16860. //
  16861. union {
  16862. PCI_PMCSR ControlStatus;
  16863. USHORT AsUSHORT;
  16864. } PMCSR;
  16865. //
  16866. // PMCSR PCI-PCI Bridge Support Extensions
  16867. //
  16868. union {
  16869. PCI_PMCSR_BSE BridgeSupport;
  16870. UCHAR AsUCHAR;
  16871. } PMCSR_BSE;
  16872. //
  16873. // Optional read only 8 bit Data register. Contents controlled by
  16874. // DataSelect and DataScale in ControlStatus.
  16875. //
  16876. UCHAR Data;
  16877. } PCI_PM_CAPABILITY, *PPCI_PM_CAPABILITY;
  16878. //
  16879. // AGP Capability
  16880. //
  16881. typedef struct _PCI_AGP_CAPABILITY {
  16882. PCI_CAPABILITIES_HEADER Header;
  16883. USHORT Minor:4;
  16884. USHORT Major:4;
  16885. USHORT Rsvd1:8;
  16886. struct _PCI_AGP_STATUS {
  16887. ULONG Rate:3;
  16888. ULONG Agp3Mode:1;
  16889. ULONG FastWrite:1;
  16890. ULONG FourGB:1;
  16891. ULONG HostTransDisable:1;
  16892. ULONG Gart64:1;
  16893. ULONG ITA_Coherent:1;
  16894. ULONG SideBandAddressing:1; // SBA
  16895. ULONG CalibrationCycle:3;
  16896. ULONG AsyncRequestSize:3;
  16897. ULONG Rsvd1:1;
  16898. ULONG Isoch:1;
  16899. ULONG Rsvd2:6;
  16900. ULONG RequestQueueDepthMaximum:8; // RQ
  16901. } AGPStatus;
  16902. struct _PCI_AGP_COMMAND {
  16903. ULONG Rate:3;
  16904. ULONG Rsvd1:1;
  16905. ULONG FastWriteEnable:1;
  16906. ULONG FourGBEnable:1;
  16907. ULONG Rsvd2:1;
  16908. ULONG Gart64:1;
  16909. ULONG AGPEnable:1;
  16910. ULONG SBAEnable:1;
  16911. ULONG CalibrationCycle:3;
  16912. ULONG AsyncReqSize:3;
  16913. ULONG Rsvd3:8;
  16914. ULONG RequestQueueDepth:8;
  16915. } AGPCommand;
  16916. } PCI_AGP_CAPABILITY, *PPCI_AGP_CAPABILITY;
  16917. //
  16918. // An AGPv3 Target must have an extended capability,
  16919. // but it's only present for a Master when the Isoch
  16920. // bit is set in its status register
  16921. //
  16922. typedef enum _EXTENDED_AGP_REGISTER {
  16923. IsochStatus,
  16924. AgpControl,
  16925. ApertureSize,
  16926. AperturePageSize,
  16927. GartLow,
  16928. GartHigh,
  16929. IsochCommand
  16930. } EXTENDED_AGP_REGISTER, *PEXTENDED_AGP_REGISTER;
  16931. typedef struct _PCI_AGP_ISOCH_STATUS {
  16932. ULONG ErrorCode: 2;
  16933. ULONG Rsvd1: 1;
  16934. ULONG Isoch_L: 3;
  16935. ULONG Isoch_Y: 2;
  16936. ULONG Isoch_N: 8;
  16937. ULONG Rsvd2: 16;
  16938. } PCI_AGP_ISOCH_STATUS, *PPCI_AGP_ISOCH_STATUS;
  16939. typedef struct _PCI_AGP_CONTROL {
  16940. ULONG Rsvd1: 7;
  16941. ULONG GTLB_Enable: 1;
  16942. ULONG AP_Enable: 1;
  16943. ULONG CAL_Disable: 1;
  16944. ULONG Rsvd2: 22;
  16945. } PCI_AGP_CONTROL, *PPCI_AGP_CONTROL;
  16946. typedef struct _PCI_AGP_APERTURE_PAGE_SIZE {
  16947. USHORT PageSizeMask: 11;
  16948. USHORT Rsvd1: 1;
  16949. USHORT PageSizeSelect: 4;
  16950. } PCI_AGP_APERTURE_PAGE_SIZE, *PPCI_AGP_APERTURE_PAGE_SIZE;
  16951. typedef struct _PCI_AGP_ISOCH_COMMAND {
  16952. USHORT Rsvd1: 6;
  16953. USHORT Isoch_Y: 2;
  16954. USHORT Isoch_N: 8;
  16955. } PCI_AGP_ISOCH_COMMAND, *PPCI_AGP_ISOCH_COMMAND;
  16956. typedef struct PCI_AGP_EXTENDED_CAPABILITY {
  16957. PCI_AGP_ISOCH_STATUS IsochStatus;
  16958. //
  16959. // Target only ----------------<<-begin->>
  16960. //
  16961. PCI_AGP_CONTROL AgpControl;
  16962. USHORT ApertureSize;
  16963. PCI_AGP_APERTURE_PAGE_SIZE AperturePageSize;
  16964. ULONG GartLow;
  16965. ULONG GartHigh;
  16966. //
  16967. // ------------------------------<<-end->>
  16968. //
  16969. PCI_AGP_ISOCH_COMMAND IsochCommand;
  16970. } PCI_AGP_EXTENDED_CAPABILITY, *PPCI_AGP_EXTENDED_CAPABILITY;
  16971. #define PCI_AGP_RATE_1X 0x1
  16972. #define PCI_AGP_RATE_2X 0x2
  16973. #define PCI_AGP_RATE_4X 0x4
  16974. //
  16975. // MSI (Message Signalled Interrupts) Capability
  16976. //
  16977. typedef struct _PCI_MSI_CAPABILITY {
  16978. PCI_CAPABILITIES_HEADER Header;
  16979. struct _PCI_MSI_MESSAGE_CONTROL {
  16980. USHORT MSIEnable:1;
  16981. USHORT MultipleMessageCapable:3;
  16982. USHORT MultipleMessageEnable:3;
  16983. USHORT CapableOf64Bits:1;
  16984. USHORT Reserved:8;
  16985. } MessageControl;
  16986. union {
  16987. struct _PCI_MSI_MESSAGE_ADDRESS {
  16988. ULONG_PTR Reserved:2; // always zero, DWORD aligned address
  16989. ULONG_PTR Address:30;
  16990. } Register;
  16991. ULONG_PTR Raw;
  16992. } MessageAddress;
  16993. //
  16994. // The rest of the Capability structure differs depending on whether
  16995. // 32bit or 64bit addressing is being used.
  16996. //
  16997. // (The CapableOf64Bits bit above determines this)
  16998. //
  16999. union {
  17000. // For 64 bit devices
  17001. struct _PCI_MSI_64BIT_DATA {
  17002. ULONG MessageUpperAddress;
  17003. USHORT MessageData;
  17004. } Bit64;
  17005. // For 32 bit devices
  17006. struct _PCI_MSI_32BIT_DATA {
  17007. USHORT MessageData;
  17008. ULONG Unused;
  17009. } Bit32;
  17010. } Data;
  17011. } PCI_MSI_CAPABILITY, *PPCI_PCI_CAPABILITY;
  17012. // begin_wdm
  17013. //
  17014. // Base Class Code encodings for Base Class (from PCI spec rev 2.1).
  17015. //
  17016. #define PCI_CLASS_PRE_20 0x00
  17017. #define PCI_CLASS_MASS_STORAGE_CTLR 0x01
  17018. #define PCI_CLASS_NETWORK_CTLR 0x02
  17019. #define PCI_CLASS_DISPLAY_CTLR 0x03
  17020. #define PCI_CLASS_MULTIMEDIA_DEV 0x04
  17021. #define PCI_CLASS_MEMORY_CTLR 0x05
  17022. #define PCI_CLASS_BRIDGE_DEV 0x06
  17023. #define PCI_CLASS_SIMPLE_COMMS_CTLR 0x07
  17024. #define PCI_CLASS_BASE_SYSTEM_DEV 0x08
  17025. #define PCI_CLASS_INPUT_DEV 0x09
  17026. #define PCI_CLASS_DOCKING_STATION 0x0a
  17027. #define PCI_CLASS_PROCESSOR 0x0b
  17028. #define PCI_CLASS_SERIAL_BUS_CTLR 0x0c
  17029. #define PCI_CLASS_WIRELESS_CTLR 0x0d
  17030. #define PCI_CLASS_INTELLIGENT_IO_CTLR 0x0e
  17031. #define PCI_CLASS_SATELLITE_COMMS_CTLR 0x0f
  17032. #define PCI_CLASS_ENCRYPTION_DECRYPTION 0x10
  17033. #define PCI_CLASS_DATA_ACQ_SIGNAL_PROC 0x11
  17034. // 0d thru fe reserved
  17035. #define PCI_CLASS_NOT_DEFINED 0xff
  17036. //
  17037. // Sub Class Code encodings (PCI rev 2.1).
  17038. //
  17039. // Class 00 - PCI_CLASS_PRE_20
  17040. #define PCI_SUBCLASS_PRE_20_NON_VGA 0x00
  17041. #define PCI_SUBCLASS_PRE_20_VGA 0x01
  17042. // Class 01 - PCI_CLASS_MASS_STORAGE_CTLR
  17043. #define PCI_SUBCLASS_MSC_SCSI_BUS_CTLR 0x00
  17044. #define PCI_SUBCLASS_MSC_IDE_CTLR 0x01
  17045. #define PCI_SUBCLASS_MSC_FLOPPY_CTLR 0x02
  17046. #define PCI_SUBCLASS_MSC_IPI_CTLR 0x03
  17047. #define PCI_SUBCLASS_MSC_RAID_CTLR 0x04
  17048. #define PCI_SUBCLASS_MSC_OTHER 0x80
  17049. // Class 02 - PCI_CLASS_NETWORK_CTLR
  17050. #define PCI_SUBCLASS_NET_ETHERNET_CTLR 0x00
  17051. #define PCI_SUBCLASS_NET_TOKEN_RING_CTLR 0x01
  17052. #define PCI_SUBCLASS_NET_FDDI_CTLR 0x02
  17053. #define PCI_SUBCLASS_NET_ATM_CTLR 0x03
  17054. #define PCI_SUBCLASS_NET_ISDN_CTLR 0x04
  17055. #define PCI_SUBCLASS_NET_OTHER 0x80
  17056. // Class 03 - PCI_CLASS_DISPLAY_CTLR
  17057. // N.B. Sub Class 00 could be VGA or 8514 depending on Interface byte
  17058. #define PCI_SUBCLASS_VID_VGA_CTLR 0x00
  17059. #define PCI_SUBCLASS_VID_XGA_CTLR 0x01
  17060. #define PCI_SUBLCASS_VID_3D_CTLR 0x02
  17061. #define PCI_SUBCLASS_VID_OTHER 0x80
  17062. // Class 04 - PCI_CLASS_MULTIMEDIA_DEV
  17063. #define PCI_SUBCLASS_MM_VIDEO_DEV 0x00
  17064. #define PCI_SUBCLASS_MM_AUDIO_DEV 0x01
  17065. #define PCI_SUBCLASS_MM_TELEPHONY_DEV 0x02
  17066. #define PCI_SUBCLASS_MM_OTHER 0x80
  17067. // Class 05 - PCI_CLASS_MEMORY_CTLR
  17068. #define PCI_SUBCLASS_MEM_RAM 0x00
  17069. #define PCI_SUBCLASS_MEM_FLASH 0x01
  17070. #define PCI_SUBCLASS_MEM_OTHER 0x80
  17071. // Class 06 - PCI_CLASS_BRIDGE_DEV
  17072. #define PCI_SUBCLASS_BR_HOST 0x00
  17073. #define PCI_SUBCLASS_BR_ISA 0x01
  17074. #define PCI_SUBCLASS_BR_EISA 0x02
  17075. #define PCI_SUBCLASS_BR_MCA 0x03
  17076. #define PCI_SUBCLASS_BR_PCI_TO_PCI 0x04
  17077. #define PCI_SUBCLASS_BR_PCMCIA 0x05
  17078. #define PCI_SUBCLASS_BR_NUBUS 0x06
  17079. #define PCI_SUBCLASS_BR_CARDBUS 0x07
  17080. #define PCI_SUBCLASS_BR_RACEWAY 0x08
  17081. #define PCI_SUBCLASS_BR_OTHER 0x80
  17082. // Class 07 - PCI_CLASS_SIMPLE_COMMS_CTLR
  17083. // N.B. Sub Class 00 and 01 additional info in Interface byte
  17084. #define PCI_SUBCLASS_COM_SERIAL 0x00
  17085. #define PCI_SUBCLASS_COM_PARALLEL 0x01
  17086. #define PCI_SUBCLASS_COM_MULTIPORT 0x02
  17087. #define PCI_SUBCLASS_COM_MODEM 0x03
  17088. #define PCI_SUBCLASS_COM_OTHER 0x80
  17089. // Class 08 - PCI_CLASS_BASE_SYSTEM_DEV
  17090. // N.B. See Interface byte for additional info.
  17091. #define PCI_SUBCLASS_SYS_INTERRUPT_CTLR 0x00
  17092. #define PCI_SUBCLASS_SYS_DMA_CTLR 0x01
  17093. #define PCI_SUBCLASS_SYS_SYSTEM_TIMER 0x02
  17094. #define PCI_SUBCLASS_SYS_REAL_TIME_CLOCK 0x03
  17095. #define PCI_SUBCLASS_SYS_GEN_HOTPLUG_CTLR 0x04
  17096. #define PCI_SUBCLASS_SYS_OTHER 0x80
  17097. // Class 09 - PCI_CLASS_INPUT_DEV
  17098. #define PCI_SUBCLASS_INP_KEYBOARD 0x00
  17099. #define PCI_SUBCLASS_INP_DIGITIZER 0x01
  17100. #define PCI_SUBCLASS_INP_MOUSE 0x02
  17101. #define PCI_SUBCLASS_INP_SCANNER 0x03
  17102. #define PCI_SUBCLASS_INP_GAMEPORT 0x04
  17103. #define PCI_SUBCLASS_INP_OTHER 0x80
  17104. // Class 0a - PCI_CLASS_DOCKING_STATION
  17105. #define PCI_SUBCLASS_DOC_GENERIC 0x00
  17106. #define PCI_SUBCLASS_DOC_OTHER 0x80
  17107. // Class 0b - PCI_CLASS_PROCESSOR
  17108. #define PCI_SUBCLASS_PROC_386 0x00
  17109. #define PCI_SUBCLASS_PROC_486 0x01
  17110. #define PCI_SUBCLASS_PROC_PENTIUM 0x02
  17111. #define PCI_SUBCLASS_PROC_ALPHA 0x10
  17112. #define PCI_SUBCLASS_PROC_POWERPC 0x20
  17113. #define PCI_SUBCLASS_PROC_COPROCESSOR 0x40
  17114. // Class 0c - PCI_CLASS_SERIAL_BUS_CTLR
  17115. #define PCI_SUBCLASS_SB_IEEE1394 0x00
  17116. #define PCI_SUBCLASS_SB_ACCESS 0x01
  17117. #define PCI_SUBCLASS_SB_SSA 0x02
  17118. #define PCI_SUBCLASS_SB_USB 0x03
  17119. #define PCI_SUBCLASS_SB_FIBRE_CHANNEL 0x04
  17120. #define PCI_SUBCLASS_SB_SMBUS 0x05
  17121. // Class 0d - PCI_CLASS_WIRELESS_CTLR
  17122. #define PCI_SUBCLASS_WIRELESS_IRDA 0x00
  17123. #define PCI_SUBCLASS_WIRELESS_CON_IR 0x01
  17124. #define PCI_SUBCLASS_WIRELESS_RF 0x10
  17125. #define PCI_SUBCLASS_WIRELESS_OTHER 0x80
  17126. // Class 0e - PCI_CLASS_INTELLIGENT_IO_CTLR
  17127. #define PCI_SUBCLASS_INTIO_I2O 0x00
  17128. // Class 0f - PCI_CLASS_SATELLITE_CTLR
  17129. #define PCI_SUBCLASS_SAT_TV 0x01
  17130. #define PCI_SUBCLASS_SAT_AUDIO 0x02
  17131. #define PCI_SUBCLASS_SAT_VOICE 0x03
  17132. #define PCI_SUBCLASS_SAT_DATA 0x04
  17133. // Class 10 - PCI_CLASS_ENCRYPTION_DECRYPTION
  17134. #define PCI_SUBCLASS_CRYPTO_NET_COMP 0x00
  17135. #define PCI_SUBCLASS_CRYPTO_ENTERTAINMENT 0x10
  17136. #define PCI_SUBCLASS_CRYPTO_OTHER 0x80
  17137. // Class 11 - PCI_CLASS_DATA_ACQ_SIGNAL_PROC
  17138. #define PCI_SUBCLASS_DASP_DPIO 0x00
  17139. #define PCI_SUBCLASS_DASP_OTHER 0x80
  17140. // end_ntndis
  17141. //
  17142. // Bit encodes for PCI_COMMON_CONFIG.u.type0.BaseAddresses
  17143. //
  17144. #define PCI_ADDRESS_IO_SPACE 0x00000001 // (ro)
  17145. #define PCI_ADDRESS_MEMORY_TYPE_MASK 0x00000006 // (ro)
  17146. #define PCI_ADDRESS_MEMORY_PREFETCHABLE 0x00000008 // (ro)
  17147. #define PCI_ADDRESS_IO_ADDRESS_MASK 0xfffffffc
  17148. #define PCI_ADDRESS_MEMORY_ADDRESS_MASK 0xfffffff0
  17149. #define PCI_ADDRESS_ROM_ADDRESS_MASK 0xfffff800
  17150. #define PCI_TYPE_32BIT 0
  17151. #define PCI_TYPE_20BIT 2
  17152. #define PCI_TYPE_64BIT 4
  17153. //
  17154. // Bit encodes for PCI_COMMON_CONFIG.u.type0.ROMBaseAddresses
  17155. //
  17156. #define PCI_ROMADDRESS_ENABLED 0x00000001
  17157. //
  17158. // Reference notes for PCI configuration fields:
  17159. //
  17160. // ro these field are read only. changes to these fields are ignored
  17161. //
  17162. // ro+ these field are intended to be read only and should be initialized
  17163. // by the system to their proper values. However, driver may change
  17164. // these settings.
  17165. //
  17166. // ---
  17167. //
  17168. // All resources comsumed by a PCI device start as unitialized
  17169. // under NT. An uninitialized memory or I/O base address can be
  17170. // determined by checking it's corrisponding enabled bit in the
  17171. // PCI_COMMON_CONFIG.Command value. An InterruptLine is unitialized
  17172. // if it contains the value of -1.
  17173. //
  17174. // end_wdm end_ntminiport
  17175. //
  17176. // Portable portion of HAL & HAL bus extender definitions for BUSHANDLER
  17177. // BusData for installed PCI buses.
  17178. //
  17179. typedef VOID
  17180. (*PciPin2Line) (
  17181. IN struct _BUS_HANDLER *BusHandler,
  17182. IN struct _BUS_HANDLER *RootHandler,
  17183. IN PCI_SLOT_NUMBER SlotNumber,
  17184. IN PPCI_COMMON_CONFIG PciData
  17185. );
  17186. typedef VOID
  17187. (*PciLine2Pin) (
  17188. IN struct _BUS_HANDLER *BusHandler,
  17189. IN struct _BUS_HANDLER *RootHandler,
  17190. IN PCI_SLOT_NUMBER SlotNumber,
  17191. IN PPCI_COMMON_CONFIG PciNewData,
  17192. IN PPCI_COMMON_CONFIG PciOldData
  17193. );
  17194. typedef VOID
  17195. (*PciReadWriteConfig) (
  17196. IN struct _BUS_HANDLER *BusHandler,
  17197. IN PCI_SLOT_NUMBER Slot,
  17198. IN PVOID Buffer,
  17199. IN ULONG Offset,
  17200. IN ULONG Length
  17201. );
  17202. #define PCI_DATA_TAG ' ICP'
  17203. #define PCI_DATA_VERSION 1
  17204. typedef struct _PCIBUSDATA {
  17205. ULONG Tag;
  17206. ULONG Version;
  17207. PciReadWriteConfig ReadConfig;
  17208. PciReadWriteConfig WriteConfig;
  17209. PciPin2Line Pin2Line;
  17210. PciLine2Pin Line2Pin;
  17211. PCI_SLOT_NUMBER ParentSlot;
  17212. PVOID Reserved[4];
  17213. } PCIBUSDATA, *PPCIBUSDATA;
  17214. typedef ULONG (*PCI_READ_WRITE_CONFIG)(
  17215. IN PVOID Context,
  17216. IN UCHAR BusOffset,
  17217. IN ULONG Slot,
  17218. IN PVOID Buffer,
  17219. IN ULONG Offset,
  17220. IN ULONG Length
  17221. );
  17222. typedef VOID (*PCI_PIN_TO_LINE)(
  17223. IN PVOID Context,
  17224. IN PPCI_COMMON_CONFIG PciData
  17225. );
  17226. typedef VOID (*PCI_LINE_TO_PIN)(
  17227. IN PVOID Context,
  17228. IN PPCI_COMMON_CONFIG PciNewData,
  17229. IN PPCI_COMMON_CONFIG PciOldData
  17230. );
  17231. typedef struct _PCI_BUS_INTERFACE_STANDARD {
  17232. //
  17233. // generic interface header
  17234. //
  17235. USHORT Size;
  17236. USHORT Version;
  17237. PVOID Context;
  17238. PINTERFACE_REFERENCE InterfaceReference;
  17239. PINTERFACE_DEREFERENCE InterfaceDereference;
  17240. //
  17241. // standard PCI bus interfaces
  17242. //
  17243. PCI_READ_WRITE_CONFIG ReadConfig;
  17244. PCI_READ_WRITE_CONFIG WriteConfig;
  17245. PCI_PIN_TO_LINE PinToLine;
  17246. PCI_LINE_TO_PIN LineToPin;
  17247. } PCI_BUS_INTERFACE_STANDARD, *PPCI_BUS_INTERFACE_STANDARD;
  17248. #define PCI_BUS_INTERFACE_STANDARD_VERSION 1
  17249. // begin_wdm
  17250. #define PCI_DEVICE_PRESENT_INTERFACE_VERSION 1
  17251. //
  17252. // Flags for PCI_DEVICE_PRESENCE_PARAMETERS
  17253. //
  17254. #define PCI_USE_SUBSYSTEM_IDS 0x00000001
  17255. #define PCI_USE_REVISION 0x00000002
  17256. // The following flags are only valid for IsDevicePresentEx
  17257. #define PCI_USE_VENDEV_IDS 0x00000004
  17258. #define PCI_USE_CLASS_SUBCLASS 0x00000008
  17259. #define PCI_USE_PROGIF 0x00000010
  17260. #define PCI_USE_LOCAL_BUS 0x00000020
  17261. #define PCI_USE_LOCAL_DEVICE 0x00000040
  17262. //
  17263. // Search parameters structure for IsDevicePresentEx
  17264. //
  17265. typedef struct _PCI_DEVICE_PRESENCE_PARAMETERS {
  17266. ULONG Size;
  17267. ULONG Flags;
  17268. USHORT VendorID;
  17269. USHORT DeviceID;
  17270. UCHAR RevisionID;
  17271. USHORT SubVendorID;
  17272. USHORT SubSystemID;
  17273. UCHAR BaseClass;
  17274. UCHAR SubClass;
  17275. UCHAR ProgIf;
  17276. } PCI_DEVICE_PRESENCE_PARAMETERS, *PPCI_DEVICE_PRESENCE_PARAMETERS;
  17277. typedef
  17278. BOOLEAN
  17279. (*PPCI_IS_DEVICE_PRESENT) (
  17280. IN USHORT VendorID,
  17281. IN USHORT DeviceID,
  17282. IN UCHAR RevisionID,
  17283. IN USHORT SubVendorID,
  17284. IN USHORT SubSystemID,
  17285. IN ULONG Flags
  17286. );
  17287. typedef
  17288. BOOLEAN
  17289. (*PPCI_IS_DEVICE_PRESENT_EX) (
  17290. IN PVOID Context,
  17291. IN PPCI_DEVICE_PRESENCE_PARAMETERS Parameters
  17292. );
  17293. typedef struct _PCI_DEVICE_PRESENT_INTERFACE {
  17294. //
  17295. // generic interface header
  17296. //
  17297. USHORT Size;
  17298. USHORT Version;
  17299. PVOID Context;
  17300. PINTERFACE_REFERENCE InterfaceReference;
  17301. PINTERFACE_DEREFERENCE InterfaceDereference;
  17302. //
  17303. // pci device info
  17304. //
  17305. PPCI_IS_DEVICE_PRESENT IsDevicePresent;
  17306. PPCI_IS_DEVICE_PRESENT_EX IsDevicePresentEx;
  17307. } PCI_DEVICE_PRESENT_INTERFACE, *PPCI_DEVICE_PRESENT_INTERFACE;
  17308. //
  17309. // Normal uncompressed Copy and Mdl Apis
  17310. //
  17311. NTKERNELAPI
  17312. BOOLEAN
  17313. FsRtlCopyRead (
  17314. IN PFILE_OBJECT FileObject,
  17315. IN PLARGE_INTEGER FileOffset,
  17316. IN ULONG Length,
  17317. IN BOOLEAN Wait,
  17318. IN ULONG LockKey,
  17319. OUT PVOID Buffer,
  17320. OUT PIO_STATUS_BLOCK IoStatus,
  17321. IN PDEVICE_OBJECT DeviceObject
  17322. );
  17323. NTKERNELAPI
  17324. BOOLEAN
  17325. FsRtlCopyWrite (
  17326. IN PFILE_OBJECT FileObject,
  17327. IN PLARGE_INTEGER FileOffset,
  17328. IN ULONG Length,
  17329. IN BOOLEAN Wait,
  17330. IN ULONG LockKey,
  17331. IN PVOID Buffer,
  17332. OUT PIO_STATUS_BLOCK IoStatus,
  17333. IN PDEVICE_OBJECT DeviceObject
  17334. );
  17335. // end_ntifs
  17336. NTKERNELAPI
  17337. BOOLEAN
  17338. FsRtlMdlRead (
  17339. IN PFILE_OBJECT FileObject,
  17340. IN PLARGE_INTEGER FileOffset,
  17341. IN ULONG Length,
  17342. IN ULONG LockKey,
  17343. OUT PMDL *MdlChain,
  17344. OUT PIO_STATUS_BLOCK IoStatus
  17345. );
  17346. BOOLEAN
  17347. FsRtlMdlReadComplete (
  17348. IN PFILE_OBJECT FileObject,
  17349. IN PMDL MdlChain
  17350. );
  17351. #define LEGAL_ANSI_CHARACTER_ARRAY (*FsRtlLegalAnsiCharacterArray)
  17352. #define NLS_OEM_LEAD_BYTE_INFO (*NlsOemLeadByteInfo)
  17353. extern UCHAR const* const LEGAL_ANSI_CHARACTER_ARRAY;
  17354. extern PUSHORT NLS_OEM_LEAD_BYTE_INFO; // Lead byte info. for ACP
  17355. //
  17356. // These following bit values are set in the FsRtlLegalDbcsCharacterArray
  17357. //
  17358. #define FSRTL_FAT_LEGAL 0x01
  17359. #define FSRTL_HPFS_LEGAL 0x02
  17360. #define FSRTL_NTFS_LEGAL 0x04
  17361. #define FSRTL_WILD_CHARACTER 0x08
  17362. #define FSRTL_OLE_LEGAL 0x10
  17363. #define FSRTL_NTFS_STREAM_LEGAL (FSRTL_NTFS_LEGAL | FSRTL_OLE_LEGAL)
  17364. //
  17365. // The following macro is used to determine if an Ansi character is wild.
  17366. //
  17367. #define FsRtlIsAnsiCharacterWild(C) ( \
  17368. FsRtlTestAnsiCharacter((C), FALSE, FALSE, FSRTL_WILD_CHARACTER) \
  17369. )
  17370. //
  17371. // The following macro is used to determine if an Ansi character is Fat legal.
  17372. //
  17373. #define FsRtlIsAnsiCharacterLegalFat(C,WILD_OK) ( \
  17374. FsRtlTestAnsiCharacter((C), TRUE, (WILD_OK), FSRTL_FAT_LEGAL) \
  17375. )
  17376. //
  17377. // The following macro is used to determine if an Ansi character is Hpfs legal.
  17378. //
  17379. #define FsRtlIsAnsiCharacterLegalHpfs(C,WILD_OK) ( \
  17380. FsRtlTestAnsiCharacter((C), TRUE, (WILD_OK), FSRTL_HPFS_LEGAL) \
  17381. )
  17382. //
  17383. // The following macro is used to determine if an Ansi character is Ntfs legal.
  17384. //
  17385. #define FsRtlIsAnsiCharacterLegalNtfs(C,WILD_OK) ( \
  17386. FsRtlTestAnsiCharacter((C), TRUE, (WILD_OK), FSRTL_NTFS_LEGAL) \
  17387. )
  17388. //
  17389. // The following macro is used to determine if an Ansi character is
  17390. // legal in an Ntfs stream name
  17391. //
  17392. #define FsRtlIsAnsiCharacterLegalNtfsStream(C,WILD_OK) ( \
  17393. FsRtlTestAnsiCharacter((C), TRUE, (WILD_OK), FSRTL_NTFS_STREAM_LEGAL) \
  17394. )
  17395. //
  17396. // The following macro is used to determine if an Ansi character is legal,
  17397. // according to the caller's specification.
  17398. //
  17399. #define FsRtlIsAnsiCharacterLegal(C,FLAGS) ( \
  17400. FsRtlTestAnsiCharacter((C), TRUE, FALSE, (FLAGS)) \
  17401. )
  17402. //
  17403. // The following macro is used to test attributes of an Ansi character,
  17404. // according to the caller's specified flags.
  17405. //
  17406. #define FsRtlTestAnsiCharacter(C, DEFAULT_RET, WILD_OK, FLAGS) ( \
  17407. ((SCHAR)(C) < 0) ? DEFAULT_RET : \
  17408. FlagOn( LEGAL_ANSI_CHARACTER_ARRAY[(C)], \
  17409. (FLAGS) | \
  17410. ((WILD_OK) ? FSRTL_WILD_CHARACTER : 0) ) \
  17411. )
  17412. //
  17413. // The following two macros use global data defined in ntos\rtl\nlsdata.c
  17414. //
  17415. // BOOLEAN
  17416. // FsRtlIsLeadDbcsCharacter (
  17417. // IN UCHAR DbcsCharacter
  17418. // );
  17419. //
  17420. // /*++
  17421. //
  17422. // Routine Description:
  17423. //
  17424. // This routine takes the first bytes of a Dbcs character and
  17425. // returns whether it is a lead byte in the system code page.
  17426. //
  17427. // Arguments:
  17428. //
  17429. // DbcsCharacter - Supplies the input character being examined
  17430. //
  17431. // Return Value:
  17432. //
  17433. // BOOLEAN - TRUE if the input character is a dbcs lead and
  17434. // FALSE otherwise
  17435. //
  17436. // --*/
  17437. //
  17438. //
  17439. #define FsRtlIsLeadDbcsCharacter(DBCS_CHAR) ( \
  17440. (BOOLEAN)((UCHAR)(DBCS_CHAR) < 0x80 ? FALSE : \
  17441. (NLS_MB_CODE_PAGE_TAG && \
  17442. (NLS_OEM_LEAD_BYTE_INFO[(UCHAR)(DBCS_CHAR)] != 0))) \
  17443. )
  17444. NTKERNELAPI
  17445. VOID
  17446. FsRtlDissectDbcs (
  17447. IN ANSI_STRING InputName,
  17448. OUT PANSI_STRING FirstPart,
  17449. OUT PANSI_STRING RemainingPart
  17450. );
  17451. NTKERNELAPI
  17452. BOOLEAN
  17453. FsRtlDoesDbcsContainWildCards (
  17454. IN PANSI_STRING Name
  17455. );
  17456. NTKERNELAPI
  17457. BOOLEAN
  17458. FsRtlIsDbcsInExpression (
  17459. IN PANSI_STRING Expression,
  17460. IN PANSI_STRING Name
  17461. );
  17462. NTKERNELAPI
  17463. BOOLEAN
  17464. FsRtlIsFatDbcsLegal (
  17465. IN ANSI_STRING DbcsName,
  17466. IN BOOLEAN WildCardsPermissible,
  17467. IN BOOLEAN PathNamePermissible,
  17468. IN BOOLEAN LeadingBackslashPermissible
  17469. );
  17470. NTKERNELAPI
  17471. NTSTATUS
  17472. LpcRequestPort(
  17473. IN PVOID PortAddress,
  17474. IN PPORT_MESSAGE RequestMessage
  17475. );
  17476. NTSTATUS
  17477. LpcRequestWaitReplyPort(
  17478. IN PVOID PortAddress,
  17479. IN PPORT_MESSAGE RequestMessage,
  17480. OUT PPORT_MESSAGE ReplyMessage
  17481. );
  17482. NTSTATUS
  17483. LpcRequestWaitReplyPortEx (
  17484. IN PVOID PortAddress,
  17485. IN PPORT_MESSAGE RequestMessage,
  17486. OUT PPORT_MESSAGE ReplyMessage
  17487. );
  17488. NTSTATUS
  17489. LpcDisconnectPort (
  17490. IN PVOID Port
  17491. );
  17492. extern POBJECT_TYPE *ExEventPairObjectType;
  17493. extern POBJECT_TYPE *IoFileObjectType;
  17494. extern POBJECT_TYPE *IoDriverObjectType;
  17495. extern POBJECT_TYPE *PsProcessType;
  17496. extern POBJECT_TYPE *PsThreadType;
  17497. extern POBJECT_TYPE *PsJobType;
  17498. extern POBJECT_TYPE *LpcPortObjectType;
  17499. extern POBJECT_TYPE *LpcWaitablePortObjectType;
  17500. extern POBJECT_TYPE MmSectionObjectType;
  17501. #ifdef __cplusplus
  17502. } // extern "C"
  17503. #endif
  17504. #endif // _NTOSP_