Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

20169 lines
452 KiB

  1. /*++ BUILD Version: 0133 // 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. // Deferred Procedure Call (DPC) object
  285. //
  286. typedef struct _KDPC {
  287. CSHORT Type;
  288. UCHAR Number;
  289. UCHAR Importance;
  290. LIST_ENTRY DpcListEntry;
  291. PKDEFERRED_ROUTINE DeferredRoutine;
  292. PVOID DeferredContext;
  293. PVOID SystemArgument1;
  294. PVOID SystemArgument2;
  295. PULONG_PTR Lock;
  296. } KDPC, *PKDPC, *RESTRICTED_POINTER PRKDPC;
  297. //
  298. // Interprocessor interrupt worker routine function prototype.
  299. //
  300. typedef PVOID PKIPI_CONTEXT;
  301. typedef
  302. VOID
  303. (*PKIPI_WORKER)(
  304. IN PKIPI_CONTEXT PacketContext,
  305. IN PVOID Parameter1,
  306. IN PVOID Parameter2,
  307. IN PVOID Parameter3
  308. );
  309. //
  310. // Define interprocessor interrupt performance counters.
  311. //
  312. typedef struct _KIPI_COUNTS {
  313. ULONG Freeze;
  314. ULONG Packet;
  315. ULONG DPC;
  316. ULONG APC;
  317. ULONG FlushSingleTb;
  318. ULONG FlushMultipleTb;
  319. ULONG FlushEntireTb;
  320. ULONG GenericCall;
  321. ULONG ChangeColor;
  322. ULONG SweepDcache;
  323. ULONG SweepIcache;
  324. ULONG SweepIcacheRange;
  325. ULONG FlushIoBuffers;
  326. ULONG GratuitousDPC;
  327. } KIPI_COUNTS, *PKIPI_COUNTS;
  328. #if defined(NT_UP)
  329. #define HOT_STATISTIC(a) a
  330. #else
  331. #define HOT_STATISTIC(a) (KeGetCurrentPrcb()->a)
  332. #endif
  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. In a future compiler this will
  341. // be placed at:
  342. //
  343. // ULONG Pages[];
  344. //
  345. // Until this declaration is permitted, however, one simply calculates the
  346. // base of the array by adding one to the base MDL pointer:
  347. //
  348. // Pages = (PULONG) (Mdl + 1);
  349. //
  350. // Notice that while in the context of the subject thread, the base virtual
  351. // address of a buffer mapped by an MDL may be referenced using the following:
  352. //
  353. // Mdl->StartVa | Mdl->ByteOffset
  354. //
  355. typedef struct _MDL {
  356. struct _MDL *Next;
  357. CSHORT Size;
  358. CSHORT MdlFlags;
  359. struct _EPROCESS *Process;
  360. PVOID MappedSystemVa;
  361. PVOID StartVa;
  362. ULONG ByteCount;
  363. ULONG ByteOffset;
  364. } MDL, *PMDL;
  365. #define MDL_MAPPED_TO_SYSTEM_VA 0x0001
  366. #define MDL_PAGES_LOCKED 0x0002
  367. #define MDL_SOURCE_IS_NONPAGED_POOL 0x0004
  368. #define MDL_ALLOCATED_FIXED_SIZE 0x0008
  369. #define MDL_PARTIAL 0x0010
  370. #define MDL_PARTIAL_HAS_BEEN_MAPPED 0x0020
  371. #define MDL_IO_PAGE_READ 0x0040
  372. #define MDL_WRITE_OPERATION 0x0080
  373. #define MDL_PARENT_MAPPED_SYSTEM_VA 0x0100
  374. #define MDL_FREE_EXTRA_PTES 0x0200
  375. #define MDL_IO_SPACE 0x0800
  376. #define MDL_NETWORK_HEADER 0x1000
  377. #define MDL_MAPPING_CAN_FAIL 0x2000
  378. #define MDL_ALLOCATED_MUST_SUCCEED 0x4000
  379. #define MDL_MAPPING_FLAGS (MDL_MAPPED_TO_SYSTEM_VA | \
  380. MDL_PAGES_LOCKED | \
  381. MDL_SOURCE_IS_NONPAGED_POOL | \
  382. MDL_PARTIAL_HAS_BEEN_MAPPED | \
  383. MDL_PARENT_MAPPED_SYSTEM_VA | \
  384. MDL_SYSTEM_VA | \
  385. MDL_IO_SPACE )
  386. // end_ntndis
  387. //
  388. // switch to DBG when appropriate
  389. //
  390. #if DBG
  391. #define PAGED_CODE() \
  392. { if (KeGetCurrentIrql() > APC_LEVEL) { \
  393. KdPrint(( "EX: Pageable code called at IRQL %d\n", KeGetCurrentIrql() )); \
  394. ASSERT(FALSE); \
  395. } \
  396. }
  397. #else
  398. #define PAGED_CODE() NOP_FUNCTION;
  399. #endif
  400. //
  401. // Data structure used to represent client security context for a thread.
  402. // This data structure is used to support impersonation.
  403. //
  404. // THE FIELDS OF THIS DATA STRUCTURE SHOULD BE CONSIDERED OPAQUE
  405. // BY ALL EXCEPT THE SECURITY ROUTINES.
  406. //
  407. typedef struct _SECURITY_CLIENT_CONTEXT {
  408. SECURITY_QUALITY_OF_SERVICE SecurityQos;
  409. PACCESS_TOKEN ClientToken;
  410. BOOLEAN DirectlyAccessClientToken;
  411. BOOLEAN DirectAccessEffectiveOnly;
  412. BOOLEAN ServerIsRemote;
  413. TOKEN_CONTROL ClientTokenControl;
  414. } SECURITY_CLIENT_CONTEXT, *PSECURITY_CLIENT_CONTEXT;
  415. //
  416. // where
  417. //
  418. // SecurityQos - is the security quality of service information in effect
  419. // for this client. This information is used when directly accessing
  420. // the client's token. In this case, the information here over-rides
  421. // the information in the client's token. If a copy of the client's
  422. // token is requested, it must be generated using this information,
  423. // not the information in the client's token. In all cases, this
  424. // information may not provide greater access than the information
  425. // in the client's token. In particular, if the client's token is
  426. // an impersonation token with an impersonation level of
  427. // "SecurityDelegation", but the information in this field indicates
  428. // an impersonation level of "SecurityIdentification", then
  429. // the server may only get a copy of the token with an Identification
  430. // level of impersonation.
  431. //
  432. // ClientToken - If the DirectlyAccessClientToken field is FALSE,
  433. // then this field contains a pointer to a duplicate of the
  434. // client's token. Otherwise, this field points directly to
  435. // the client's token.
  436. //
  437. // DirectlyAccessClientToken - This boolean flag indicates whether the
  438. // token pointed to by ClientToken is a copy of the client's token
  439. // or is a direct reference to the client's token. A value of TRUE
  440. // indicates the client's token is directly accessed, FALSE indicates
  441. // a copy has been made.
  442. //
  443. // DirectAccessEffectiveOnly - This boolean flag indicates whether the
  444. // the disabled portions of the token that is currently directly
  445. // referenced may be enabled. This field is only valid if the
  446. // DirectlyAccessClientToken field is TRUE. In that case, this
  447. // value supersedes the EffectiveOnly value in the SecurityQos
  448. // FOR THE CURRENT TOKEN ONLY! If the client changes to impersonate
  449. // another client, this value may change. This value is always
  450. // minimized by the EffectiveOnly flag in the SecurityQos field.
  451. //
  452. // ServerIsRemote - If TRUE indicates that the server of the client's
  453. // request is remote. This is used for determining the legitimacy
  454. // of certain levels of impersonation and to determine how to
  455. // track context.
  456. //
  457. // ClientTokenControl - If the ServerIsRemote flag is TRUE, and the
  458. // tracking mode is DYNAMIC, then this field contains a copy of
  459. // the TOKEN_SOURCE from the client's token to assist in deciding
  460. // whether the information at the remote server needs to be
  461. // updated to match the current state of the client's security
  462. // context.
  463. //
  464. //
  465. // NOTE: At some point, we may find it worthwhile to keep an array of
  466. // elements in this data structure, where each element of the
  467. // array contains {ClientToken, ClientTokenControl} fields.
  468. // This would allow efficient handling of the case where a client
  469. // thread was constantly switching between a couple different
  470. // contexts - presumably impersonating client's of its own.
  471. //
  472. #if defined(_NTSYSTEM_)
  473. #define NTKERNELAPI
  474. #else
  475. #define NTKERNELAPI DECLSPEC_IMPORT // wdm ntddk nthal ntndis ntifs
  476. #endif
  477. #define NTHALAPI DECLSPEC_IMPORT
  478. //
  479. // Common dispatcher object header
  480. //
  481. // N.B. The size field contains the number of dwords in the structure.
  482. //
  483. typedef struct _DISPATCHER_HEADER {
  484. UCHAR Type;
  485. UCHAR Absolute;
  486. UCHAR Size;
  487. UCHAR Inserted;
  488. LONG SignalState;
  489. LIST_ENTRY WaitListHead;
  490. } DISPATCHER_HEADER;
  491. //
  492. // Event object
  493. //
  494. typedef struct _KEVENT {
  495. DISPATCHER_HEADER Header;
  496. } KEVENT, *PKEVENT, *RESTRICTED_POINTER PRKEVENT;
  497. //
  498. // Timer object
  499. //
  500. typedef struct _KTIMER {
  501. DISPATCHER_HEADER Header;
  502. ULARGE_INTEGER DueTime;
  503. LIST_ENTRY TimerListEntry;
  504. struct _KDPC *Dpc;
  505. LONG Period;
  506. } KTIMER, *PKTIMER, *RESTRICTED_POINTER PRKTIMER;
  507. #ifndef _SLIST_HEADER_
  508. #define _SLIST_HEADER_
  509. #define SLIST_ENTRY SINGLE_LIST_ENTRY
  510. #define _SLIST_ENTRY _SINGLE_LIST_ENTRY
  511. #define PSLIST_ENTRY PSINGLE_LIST_ENTRY
  512. #if defined(_WIN64)
  513. typedef struct DECLSPEC_ALIGN(16) _SLIST_HEADER {
  514. ULONGLONG Alignment;
  515. ULONGLONG Region;
  516. } SLIST_HEADER;
  517. typedef struct _SLIST_HEADER *PSLIST_HEADER;
  518. #else
  519. typedef union _SLIST_HEADER {
  520. ULONGLONG Alignment;
  521. struct {
  522. SLIST_ENTRY Next;
  523. USHORT Depth;
  524. USHORT Sequence;
  525. };
  526. } SLIST_HEADER, *PSLIST_HEADER;
  527. #endif
  528. #endif
  529. //
  530. // Some simple Rtl routines for IP address <-> string literal conversion
  531. //
  532. struct in_addr;
  533. struct in6_addr;
  534. NTSYSAPI
  535. PSTR
  536. NTAPI
  537. RtlIpv4AddressToStringA (
  538. IN const struct in_addr *Addr,
  539. OUT PSTR S
  540. );
  541. NTSYSAPI
  542. PSTR
  543. NTAPI
  544. RtlIpv6AddressToStringA (
  545. IN const struct in6_addr *Addr,
  546. OUT PSTR S
  547. );
  548. NTSYSAPI
  549. PWSTR
  550. NTAPI
  551. RtlIpv4AddressToStringW (
  552. IN const struct in_addr *Addr,
  553. OUT PWSTR S
  554. );
  555. NTSYSAPI
  556. PWSTR
  557. NTAPI
  558. RtlIpv6AddressToStringW (
  559. IN const struct in6_addr *Addr,
  560. OUT PWSTR S
  561. );
  562. NTSYSAPI
  563. NTSTATUS
  564. NTAPI
  565. RtlIpv4StringToAddressA (
  566. IN PCSTR S,
  567. IN BOOLEAN Strict,
  568. OUT PCSTR *Terminator,
  569. OUT struct in_addr *Addr
  570. );
  571. NTSYSAPI
  572. NTSTATUS
  573. NTAPI
  574. RtlIpv6StringToAddressA (
  575. IN PCSTR S,
  576. OUT PCSTR *Terminator,
  577. OUT struct in6_addr *Addr
  578. );
  579. NTSYSAPI
  580. NTSTATUS
  581. NTAPI
  582. RtlIpv4StringToAddressW (
  583. IN PCWSTR S,
  584. IN BOOLEAN Strict,
  585. OUT LPCWSTR *Terminator,
  586. OUT struct in_addr *Addr
  587. );
  588. NTSYSAPI
  589. NTSTATUS
  590. NTAPI
  591. RtlIpv6StringToAddressW (
  592. IN PCWSTR S,
  593. OUT PCWSTR *Terminator,
  594. OUT struct in6_addr *Addr
  595. );
  596. #ifdef UNICODE
  597. #define RtlIpv4AddressToString RtlIpv4AddressToStringW
  598. #define RtlIpv6AddressToString RtlIpv6AddressToStringW
  599. #define RtlIpv4StringToAddress RtlIpv4StringToAddressW
  600. #define RtlIpv6StringToAddress RtlIpv6StringToAddressW
  601. #else
  602. #define RtlIpv4AddressToString RtlIpv4AddressToStringA
  603. #define RtlIpv6AddressToString RtlIpv6AddressToStringA
  604. #define RtlIpv4StringToAddress RtlIpv4StringToAddressA
  605. #define RtlIpv6StringToAddress RtlIpv6StringToAddressA
  606. #endif // UNICODE
  607. //
  608. // Structures used by the kernel drivers to describe which ports must be
  609. // hooked out directly from the V86 emulator to the driver.
  610. //
  611. typedef enum _EMULATOR_PORT_ACCESS_TYPE {
  612. Uchar,
  613. Ushort,
  614. Ulong
  615. } EMULATOR_PORT_ACCESS_TYPE, *PEMULATOR_PORT_ACCESS_TYPE;
  616. //
  617. // Access Modes
  618. //
  619. #define EMULATOR_READ_ACCESS 0x01
  620. #define EMULATOR_WRITE_ACCESS 0x02
  621. typedef struct _EMULATOR_ACCESS_ENTRY {
  622. ULONG BasePort;
  623. ULONG NumConsecutivePorts;
  624. EMULATOR_PORT_ACCESS_TYPE AccessType;
  625. UCHAR AccessMode;
  626. UCHAR StringSupport;
  627. PVOID Routine;
  628. } EMULATOR_ACCESS_ENTRY, *PEMULATOR_ACCESS_ENTRY;
  629. // end_ntminiport
  630. //
  631. // These are the various function prototypes of the routines that are
  632. // provided by the kernel driver to hook out access to io ports.
  633. //
  634. typedef
  635. NTSTATUS
  636. (*PDRIVER_IO_PORT_UCHAR ) (
  637. IN ULONG_PTR Context,
  638. IN ULONG Port,
  639. IN UCHAR AccessMode,
  640. IN OUT PUCHAR Data
  641. );
  642. typedef
  643. NTSTATUS
  644. (*PDRIVER_IO_PORT_UCHAR_STRING ) (
  645. IN ULONG_PTR Context,
  646. IN ULONG Port,
  647. IN UCHAR AccessMode,
  648. IN OUT PUCHAR Data,
  649. IN ULONG DataLength
  650. );
  651. typedef
  652. NTSTATUS
  653. (*PDRIVER_IO_PORT_USHORT ) (
  654. IN ULONG_PTR Context,
  655. IN ULONG Port,
  656. IN UCHAR AccessMode,
  657. IN OUT PUSHORT Data
  658. );
  659. typedef
  660. NTSTATUS
  661. (*PDRIVER_IO_PORT_USHORT_STRING ) (
  662. IN ULONG_PTR Context,
  663. IN ULONG Port,
  664. IN UCHAR AccessMode,
  665. IN OUT PUSHORT Data,
  666. IN ULONG DataLength // number of words
  667. );
  668. typedef
  669. NTSTATUS
  670. (*PDRIVER_IO_PORT_ULONG ) (
  671. IN ULONG_PTR Context,
  672. IN ULONG Port,
  673. IN UCHAR AccessMode,
  674. IN OUT PULONG Data
  675. );
  676. typedef
  677. NTSTATUS
  678. (*PDRIVER_IO_PORT_ULONG_STRING ) (
  679. IN ULONG_PTR Context,
  680. IN ULONG Port,
  681. IN UCHAR AccessMode,
  682. IN OUT PULONG Data,
  683. IN ULONG DataLength // number of dwords
  684. );
  685. #if defined(_X86_)
  686. //
  687. // Types to use to contain PFNs and their counts.
  688. //
  689. typedef ULONG PFN_COUNT;
  690. typedef LONG SPFN_NUMBER, *PSPFN_NUMBER;
  691. typedef ULONG PFN_NUMBER, *PPFN_NUMBER;
  692. //
  693. // Define maximum size of flush multiple TB request.
  694. //
  695. #define FLUSH_MULTIPLE_MAXIMUM 16
  696. //
  697. // Indicate that the i386 compiler supports the pragma textout construct.
  698. //
  699. #define ALLOC_PRAGMA 1
  700. //
  701. // Indicate that the i386 compiler supports the DATA_SEG("INIT") and
  702. // DATA_SEG("PAGE") pragmas
  703. //
  704. #define ALLOC_DATA_PRAGMA 1
  705. //
  706. // Interrupt Request Level definitions
  707. //
  708. #define PASSIVE_LEVEL 0 // Passive release level
  709. #define LOW_LEVEL 0 // Lowest interrupt level
  710. #define APC_LEVEL 1 // APC interrupt level
  711. #define DISPATCH_LEVEL 2 // Dispatcher level
  712. #define PROFILE_LEVEL 27 // timer used for profiling.
  713. #define CLOCK1_LEVEL 28 // Interval clock 1 level - Not used on x86
  714. #define CLOCK2_LEVEL 28 // Interval clock 2 level
  715. #define IPI_LEVEL 29 // Interprocessor interrupt level
  716. #define POWER_LEVEL 30 // Power failure level
  717. #define HIGH_LEVEL 31 // Highest interrupt level
  718. #if defined(NT_UP)
  719. #define SYNCH_LEVEL DISPATCH_LEVEL // synchronization level - UP system
  720. #else
  721. #define SYNCH_LEVEL (IPI_LEVEL-1) // synchronization level - MP system
  722. #endif
  723. #define MODE_MASK 1
  724. //
  725. // I/O space read and write macros.
  726. //
  727. // These have to be actual functions on the 386, because we need
  728. // to use assembler, but cannot return a value if we inline it.
  729. //
  730. // The READ/WRITE_REGISTER_* calls manipulate I/O registers in MEMORY space.
  731. // (Use x86 move instructions, with LOCK prefix to force correct behavior
  732. // w.r.t. caches and write buffers.)
  733. //
  734. // The READ/WRITE_PORT_* calls manipulate I/O registers in PORT space.
  735. // (Use x86 in/out instructions.)
  736. //
  737. NTKERNELAPI
  738. UCHAR
  739. NTAPI
  740. READ_REGISTER_UCHAR(
  741. PUCHAR Register
  742. );
  743. NTKERNELAPI
  744. USHORT
  745. NTAPI
  746. READ_REGISTER_USHORT(
  747. PUSHORT Register
  748. );
  749. NTKERNELAPI
  750. ULONG
  751. NTAPI
  752. READ_REGISTER_ULONG(
  753. PULONG Register
  754. );
  755. NTKERNELAPI
  756. VOID
  757. NTAPI
  758. READ_REGISTER_BUFFER_UCHAR(
  759. PUCHAR Register,
  760. PUCHAR Buffer,
  761. ULONG Count
  762. );
  763. NTKERNELAPI
  764. VOID
  765. NTAPI
  766. READ_REGISTER_BUFFER_USHORT(
  767. PUSHORT Register,
  768. PUSHORT Buffer,
  769. ULONG Count
  770. );
  771. NTKERNELAPI
  772. VOID
  773. NTAPI
  774. READ_REGISTER_BUFFER_ULONG(
  775. PULONG Register,
  776. PULONG Buffer,
  777. ULONG Count
  778. );
  779. NTKERNELAPI
  780. VOID
  781. NTAPI
  782. WRITE_REGISTER_UCHAR(
  783. PUCHAR Register,
  784. UCHAR Value
  785. );
  786. NTKERNELAPI
  787. VOID
  788. NTAPI
  789. WRITE_REGISTER_USHORT(
  790. PUSHORT Register,
  791. USHORT Value
  792. );
  793. NTKERNELAPI
  794. VOID
  795. NTAPI
  796. WRITE_REGISTER_ULONG(
  797. PULONG Register,
  798. ULONG Value
  799. );
  800. NTKERNELAPI
  801. VOID
  802. NTAPI
  803. WRITE_REGISTER_BUFFER_UCHAR(
  804. PUCHAR Register,
  805. PUCHAR Buffer,
  806. ULONG Count
  807. );
  808. NTKERNELAPI
  809. VOID
  810. NTAPI
  811. WRITE_REGISTER_BUFFER_USHORT(
  812. PUSHORT Register,
  813. PUSHORT Buffer,
  814. ULONG Count
  815. );
  816. NTKERNELAPI
  817. VOID
  818. NTAPI
  819. WRITE_REGISTER_BUFFER_ULONG(
  820. PULONG Register,
  821. PULONG Buffer,
  822. ULONG Count
  823. );
  824. NTHALAPI
  825. UCHAR
  826. NTAPI
  827. READ_PORT_UCHAR(
  828. PUCHAR Port
  829. );
  830. NTHALAPI
  831. USHORT
  832. NTAPI
  833. READ_PORT_USHORT(
  834. PUSHORT Port
  835. );
  836. NTHALAPI
  837. ULONG
  838. NTAPI
  839. READ_PORT_ULONG(
  840. PULONG Port
  841. );
  842. NTHALAPI
  843. VOID
  844. NTAPI
  845. READ_PORT_BUFFER_UCHAR(
  846. PUCHAR Port,
  847. PUCHAR Buffer,
  848. ULONG Count
  849. );
  850. NTHALAPI
  851. VOID
  852. NTAPI
  853. READ_PORT_BUFFER_USHORT(
  854. PUSHORT Port,
  855. PUSHORT Buffer,
  856. ULONG Count
  857. );
  858. NTHALAPI
  859. VOID
  860. NTAPI
  861. READ_PORT_BUFFER_ULONG(
  862. PULONG Port,
  863. PULONG Buffer,
  864. ULONG Count
  865. );
  866. NTHALAPI
  867. VOID
  868. NTAPI
  869. WRITE_PORT_UCHAR(
  870. PUCHAR Port,
  871. UCHAR Value
  872. );
  873. NTHALAPI
  874. VOID
  875. NTAPI
  876. WRITE_PORT_USHORT(
  877. PUSHORT Port,
  878. USHORT Value
  879. );
  880. NTHALAPI
  881. VOID
  882. NTAPI
  883. WRITE_PORT_ULONG(
  884. PULONG Port,
  885. ULONG Value
  886. );
  887. NTHALAPI
  888. VOID
  889. NTAPI
  890. WRITE_PORT_BUFFER_UCHAR(
  891. PUCHAR Port,
  892. PUCHAR Buffer,
  893. ULONG Count
  894. );
  895. NTHALAPI
  896. VOID
  897. NTAPI
  898. WRITE_PORT_BUFFER_USHORT(
  899. PUSHORT Port,
  900. PUSHORT Buffer,
  901. ULONG Count
  902. );
  903. NTHALAPI
  904. VOID
  905. NTAPI
  906. WRITE_PORT_BUFFER_ULONG(
  907. PULONG Port,
  908. PULONG Buffer,
  909. ULONG Count
  910. );
  911. // end_ntndis
  912. //
  913. // Get data cache fill size.
  914. //
  915. #if PRAGMA_DEPRECATED_DDK
  916. #pragma deprecated(KeGetDcacheFillSize) // Use GetDmaAlignment
  917. #endif
  918. #define KeGetDcacheFillSize() 1L
  919. #define KeFlushIoBuffers(Mdl, ReadOperation, DmaOperation)
  920. #define ExAcquireSpinLock(Lock, OldIrql) KeAcquireSpinLock((Lock), (OldIrql))
  921. #define ExReleaseSpinLock(Lock, OldIrql) KeReleaseSpinLock((Lock), (OldIrql))
  922. #define ExAcquireSpinLockAtDpcLevel(Lock) KeAcquireSpinLockAtDpcLevel(Lock)
  923. #define ExReleaseSpinLockFromDpcLevel(Lock) KeReleaseSpinLockFromDpcLevel(Lock)
  924. #if defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_)
  925. // begin_wdm
  926. #define KeQueryTickCount(CurrentCount ) { \
  927. volatile PKSYSTEM_TIME _TickCount = *((PKSYSTEM_TIME *)(&KeTickCount)); \
  928. while (TRUE) { \
  929. (CurrentCount)->HighPart = _TickCount->High1Time; \
  930. (CurrentCount)->LowPart = _TickCount->LowPart; \
  931. if ((CurrentCount)->HighPart == _TickCount->High2Time) break; \
  932. _asm { rep nop } \
  933. } \
  934. }
  935. // end_wdm
  936. #else
  937. VOID
  938. NTAPI
  939. KeQueryTickCount (
  940. OUT PLARGE_INTEGER CurrentCount
  941. );
  942. #endif // defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_)
  943. //
  944. // 386 hardware structures
  945. //
  946. //
  947. // A Page Table Entry on an Intel 386/486 has the following definition.
  948. //
  949. // **** NOTE A PRIVATE COPY OF THIS EXISTS IN THE MM\I386 DIRECTORY! ****
  950. // **** ANY CHANGES NEED TO BE MADE TO BOTH HEADER FILES. ****
  951. //
  952. typedef struct _HARDWARE_PTE_X86 {
  953. ULONG Valid : 1;
  954. ULONG Write : 1;
  955. ULONG Owner : 1;
  956. ULONG WriteThrough : 1;
  957. ULONG CacheDisable : 1;
  958. ULONG Accessed : 1;
  959. ULONG Dirty : 1;
  960. ULONG LargePage : 1;
  961. ULONG Global : 1;
  962. ULONG CopyOnWrite : 1; // software field
  963. ULONG Prototype : 1; // software field
  964. ULONG reserved : 1; // software field
  965. ULONG PageFrameNumber : 20;
  966. } HARDWARE_PTE_X86, *PHARDWARE_PTE_X86;
  967. typedef struct _HARDWARE_PTE_X86PAE {
  968. union {
  969. struct {
  970. ULONGLONG Valid : 1;
  971. ULONGLONG Write : 1;
  972. ULONGLONG Owner : 1;
  973. ULONGLONG WriteThrough : 1;
  974. ULONGLONG CacheDisable : 1;
  975. ULONGLONG Accessed : 1;
  976. ULONGLONG Dirty : 1;
  977. ULONGLONG LargePage : 1;
  978. ULONGLONG Global : 1;
  979. ULONGLONG CopyOnWrite : 1; // software field
  980. ULONGLONG Prototype : 1; // software field
  981. ULONGLONG reserved0 : 1; // software field
  982. ULONGLONG PageFrameNumber : 26;
  983. ULONGLONG reserved1 : 26; // software field
  984. };
  985. struct {
  986. ULONG LowPart;
  987. ULONG HighPart;
  988. };
  989. };
  990. } HARDWARE_PTE_X86PAE, *PHARDWARE_PTE_X86PAE;
  991. //
  992. // Special check to work around mspdb limitation
  993. //
  994. #if defined (_NTSYM_HARDWARE_PTE_SYMBOL_)
  995. #if !defined (_X86PAE_)
  996. typedef struct _HARDWARE_PTE {
  997. ULONG Valid : 1;
  998. ULONG Write : 1;
  999. ULONG Owner : 1;
  1000. ULONG WriteThrough : 1;
  1001. ULONG CacheDisable : 1;
  1002. ULONG Accessed : 1;
  1003. ULONG Dirty : 1;
  1004. ULONG LargePage : 1;
  1005. ULONG Global : 1;
  1006. ULONG CopyOnWrite : 1; // software field
  1007. ULONG Prototype : 1; // software field
  1008. ULONG reserved : 1; // software field
  1009. ULONG PageFrameNumber : 20;
  1010. } HARDWARE_PTE, *PHARDWARE_PTE;
  1011. #else
  1012. typedef struct _HARDWARE_PTE {
  1013. union {
  1014. struct {
  1015. ULONGLONG Valid : 1;
  1016. ULONGLONG Write : 1;
  1017. ULONGLONG Owner : 1;
  1018. ULONGLONG WriteThrough : 1;
  1019. ULONGLONG CacheDisable : 1;
  1020. ULONGLONG Accessed : 1;
  1021. ULONGLONG Dirty : 1;
  1022. ULONGLONG LargePage : 1;
  1023. ULONGLONG Global : 1;
  1024. ULONGLONG CopyOnWrite : 1; // software field
  1025. ULONGLONG Prototype : 1; // software field
  1026. ULONGLONG reserved0 : 1; // software field
  1027. ULONGLONG PageFrameNumber : 26;
  1028. ULONGLONG reserved1 : 26; // software field
  1029. };
  1030. struct {
  1031. ULONG LowPart;
  1032. ULONG HighPart;
  1033. };
  1034. };
  1035. } HARDWARE_PTE, *PHARDWARE_PTE;
  1036. #endif
  1037. #else
  1038. #if !defined (_X86PAE_)
  1039. typedef HARDWARE_PTE_X86 HARDWARE_PTE;
  1040. typedef PHARDWARE_PTE_X86 PHARDWARE_PTE;
  1041. #else
  1042. typedef HARDWARE_PTE_X86PAE HARDWARE_PTE;
  1043. typedef PHARDWARE_PTE_X86PAE PHARDWARE_PTE;
  1044. #endif
  1045. #endif
  1046. //
  1047. // GDT Entry
  1048. //
  1049. typedef struct _KGDTENTRY {
  1050. USHORT LimitLow;
  1051. USHORT BaseLow;
  1052. union {
  1053. struct {
  1054. UCHAR BaseMid;
  1055. UCHAR Flags1; // Declare as bytes to avoid alignment
  1056. UCHAR Flags2; // Problems.
  1057. UCHAR BaseHi;
  1058. } Bytes;
  1059. struct {
  1060. ULONG BaseMid : 8;
  1061. ULONG Type : 5;
  1062. ULONG Dpl : 2;
  1063. ULONG Pres : 1;
  1064. ULONG LimitHi : 4;
  1065. ULONG Sys : 1;
  1066. ULONG Reserved_0 : 1;
  1067. ULONG Default_Big : 1;
  1068. ULONG Granularity : 1;
  1069. ULONG BaseHi : 8;
  1070. } Bits;
  1071. } HighWord;
  1072. } KGDTENTRY, *PKGDTENTRY;
  1073. #define TYPE_CODE 0x10 // 11010 = Code, Readable, NOT Conforming, Accessed
  1074. #define TYPE_DATA 0x12 // 10010 = Data, ReadWrite, NOT Expanddown, Accessed
  1075. #define TYPE_TSS 0x01 // 01001 = NonBusy TSS
  1076. #define TYPE_LDT 0x02 // 00010 = LDT
  1077. #define DPL_USER 3
  1078. #define DPL_SYSTEM 0
  1079. #define GRAN_BYTE 0
  1080. #define GRAN_PAGE 1
  1081. #define SELECTOR_TABLE_INDEX 0x04
  1082. //
  1083. // Entry of Interrupt Descriptor Table (IDTENTRY)
  1084. //
  1085. typedef struct _KIDTENTRY {
  1086. USHORT Offset;
  1087. USHORT Selector;
  1088. USHORT Access;
  1089. USHORT ExtendedOffset;
  1090. } KIDTENTRY;
  1091. typedef KIDTENTRY *PKIDTENTRY;
  1092. //
  1093. // TSS (Task switch segment) NT only uses to control stack switches.
  1094. //
  1095. // The only fields we actually care about are Esp0, Ss0, the IoMapBase
  1096. // and the IoAccessMaps themselves.
  1097. //
  1098. //
  1099. // N.B. Size of TSS must be <= 0xDFFF
  1100. //
  1101. //
  1102. // The interrupt direction bitmap is used on Pentium to allow
  1103. // the processor to emulate V86 mode software interrupts for us.
  1104. // There is one for each IOPM. It is located by subtracting
  1105. // 32 from the IOPM base in the Tss.
  1106. //
  1107. #define INT_DIRECTION_MAP_SIZE 32
  1108. typedef UCHAR KINT_DIRECTION_MAP[INT_DIRECTION_MAP_SIZE];
  1109. #define IOPM_COUNT 1 // Number of i/o access maps that
  1110. // exist (in addition to
  1111. // IO_ACCESS_MAP_NONE)
  1112. #define IO_ACCESS_MAP_NONE 0
  1113. #define IOPM_SIZE 8192 // Size of map callers can set.
  1114. #define PIOPM_SIZE 8196 // Size of structure we must allocate
  1115. // to hold it.
  1116. typedef UCHAR KIO_ACCESS_MAP[IOPM_SIZE];
  1117. typedef KIO_ACCESS_MAP *PKIO_ACCESS_MAP;
  1118. typedef struct _KiIoAccessMap {
  1119. KINT_DIRECTION_MAP DirectionMap;
  1120. UCHAR IoMap[PIOPM_SIZE];
  1121. } KIIO_ACCESS_MAP;
  1122. typedef struct _KTSS {
  1123. USHORT Backlink;
  1124. USHORT Reserved0;
  1125. ULONG Esp0;
  1126. USHORT Ss0;
  1127. USHORT Reserved1;
  1128. ULONG NotUsed1[4];
  1129. ULONG CR3;
  1130. ULONG Eip;
  1131. ULONG EFlags;
  1132. ULONG Eax;
  1133. ULONG Ecx;
  1134. ULONG Edx;
  1135. ULONG Ebx;
  1136. ULONG Esp;
  1137. ULONG Ebp;
  1138. ULONG Esi;
  1139. ULONG Edi;
  1140. USHORT Es;
  1141. USHORT Reserved2;
  1142. USHORT Cs;
  1143. USHORT Reserved3;
  1144. USHORT Ss;
  1145. USHORT Reserved4;
  1146. USHORT Ds;
  1147. USHORT Reserved5;
  1148. USHORT Fs;
  1149. USHORT Reserved6;
  1150. USHORT Gs;
  1151. USHORT Reserved7;
  1152. USHORT LDT;
  1153. USHORT Reserved8;
  1154. USHORT Flags;
  1155. USHORT IoMapBase;
  1156. KIIO_ACCESS_MAP IoMaps[IOPM_COUNT];
  1157. //
  1158. // This is the Software interrupt direction bitmap associated with
  1159. // IO_ACCESS_MAP_NONE
  1160. //
  1161. KINT_DIRECTION_MAP IntDirectionMap;
  1162. } KTSS, *PKTSS;
  1163. #define KiComputeIopmOffset(MapNumber) \
  1164. (MapNumber == IO_ACCESS_MAP_NONE) ? \
  1165. (USHORT)(sizeof(KTSS)) : \
  1166. (USHORT)(FIELD_OFFSET(KTSS, IoMaps[MapNumber-1].IoMap))
  1167. // begin_windbgkd
  1168. //
  1169. // Special Registers for i386
  1170. //
  1171. #ifdef _X86_
  1172. typedef struct _DESCRIPTOR {
  1173. USHORT Pad;
  1174. USHORT Limit;
  1175. ULONG Base;
  1176. } KDESCRIPTOR, *PKDESCRIPTOR;
  1177. typedef struct _KSPECIAL_REGISTERS {
  1178. ULONG Cr0;
  1179. ULONG Cr2;
  1180. ULONG Cr3;
  1181. ULONG Cr4;
  1182. ULONG KernelDr0;
  1183. ULONG KernelDr1;
  1184. ULONG KernelDr2;
  1185. ULONG KernelDr3;
  1186. ULONG KernelDr6;
  1187. ULONG KernelDr7;
  1188. KDESCRIPTOR Gdtr;
  1189. KDESCRIPTOR Idtr;
  1190. USHORT Tr;
  1191. USHORT Ldtr;
  1192. ULONG Reserved[6];
  1193. } KSPECIAL_REGISTERS, *PKSPECIAL_REGISTERS;
  1194. //
  1195. // Processor State frame: Before a processor freezes itself, it
  1196. // dumps the processor state to the processor state frame for
  1197. // debugger to examine.
  1198. //
  1199. typedef struct _KPROCESSOR_STATE {
  1200. struct _CONTEXT ContextFrame;
  1201. struct _KSPECIAL_REGISTERS SpecialRegisters;
  1202. } KPROCESSOR_STATE, *PKPROCESSOR_STATE;
  1203. #endif // _X86_
  1204. // end_windbgkd
  1205. //
  1206. // Processor Control Block (PRCB)
  1207. //
  1208. #define PRCB_MAJOR_VERSION 1
  1209. #define PRCB_MINOR_VERSION 1
  1210. #define PRCB_BUILD_DEBUG 0x0001
  1211. #define PRCB_BUILD_UNIPROCESSOR 0x0002
  1212. typedef struct _KPRCB {
  1213. //
  1214. // Start of the architecturally defined section of the PRCB. This section
  1215. // may be directly addressed by vendor/platform specific HAL code and will
  1216. // not change from version to version of NT.
  1217. //
  1218. USHORT MinorVersion;
  1219. USHORT MajorVersion;
  1220. struct _KTHREAD *CurrentThread;
  1221. struct _KTHREAD *NextThread;
  1222. struct _KTHREAD *IdleThread;
  1223. CCHAR Number;
  1224. CCHAR Reserved;
  1225. USHORT BuildType;
  1226. KAFFINITY SetMember;
  1227. CCHAR CpuType;
  1228. CCHAR CpuID;
  1229. USHORT CpuStep;
  1230. struct _KPROCESSOR_STATE ProcessorState;
  1231. ULONG KernelReserved[16]; // For use by the kernel
  1232. ULONG HalReserved[16]; // For use by Hal
  1233. //
  1234. // Per processor lock queue entries.
  1235. //
  1236. // N.B. The following padding is such that the first lock entry falls in the
  1237. // last eight bytes of a cache line. This makes the dispatcher lock and
  1238. // the context swap lock lie in separate cache lines.
  1239. //
  1240. UCHAR PrcbPad0[28 + 64];
  1241. KSPIN_LOCK_QUEUE LockQueue[16];
  1242. UCHAR PrcbPad1[8];
  1243. // End of the architecturally defined section of the PRCB.
  1244. } KPRCB, *PKPRCB, *RESTRICTED_POINTER PRKPRCB;
  1245. //
  1246. // Processor Control Region Structure Definition
  1247. //
  1248. #define PCR_MINOR_VERSION 1
  1249. #define PCR_MAJOR_VERSION 1
  1250. typedef struct _KPCR {
  1251. //
  1252. // Start of the architecturally defined section of the PCR. This section
  1253. // may be directly addressed by vendor/platform specific HAL code and will
  1254. // not change from version to version of NT.
  1255. //
  1256. NT_TIB NtTib;
  1257. struct _KPCR *SelfPcr; // flat address of this PCR
  1258. struct _KPRCB *Prcb; // pointer to Prcb
  1259. KIRQL Irql;
  1260. ULONG IRR;
  1261. ULONG IrrActive;
  1262. ULONG IDR;
  1263. PVOID KdVersionBlock;
  1264. struct _KIDTENTRY *IDT;
  1265. struct _KGDTENTRY *GDT;
  1266. struct _KTSS *TSS;
  1267. USHORT MajorVersion;
  1268. USHORT MinorVersion;
  1269. KAFFINITY SetMember;
  1270. ULONG StallScaleFactor;
  1271. UCHAR DebugActive;
  1272. UCHAR Number;
  1273. } KPCR, *PKPCR;
  1274. #define EFLAGS_TF 0x00000100L
  1275. #define EFLAGS_INTERRUPT_MASK 0x00000200L
  1276. #define EFLAGS_DF_MASK 0x00000400L
  1277. #define EFLAGS_V86_MASK 0x00020000L
  1278. #define EFLAGS_ALIGN_CHECK 0x00040000L
  1279. #define EFLAGS_IOPL_MASK 0x00003000L
  1280. #define EFLAGS_VIF 0x00080000L
  1281. #define EFLAGS_VIP 0x00100000L
  1282. #define EFLAGS_USER_SANITIZE 0x003e0dd7L
  1283. // end_nthal
  1284. //
  1285. // Sanitize segCS and eFlags based on a processor mode.
  1286. //
  1287. // If kernel mode,
  1288. // force CPL == 0
  1289. //
  1290. // If user mode,
  1291. // force CPL == 3
  1292. //
  1293. #define SANITIZE_SEG(segCS, mode) (\
  1294. ((mode) == KernelMode ? \
  1295. ((0x00000000L) | ((segCS) & 0xfffc)) : \
  1296. ((0x00000003L) | ((segCS) & 0xffff))))
  1297. //
  1298. // If kernel mode, then
  1299. // let caller specify Carry, Parity, AuxCarry, Zero, Sign, Trap,
  1300. // Direction, Overflow, Interrupt, AlignCheck.
  1301. //
  1302. // If user mode, then
  1303. // let caller specify Carry, Parity, AuxCarry, Zero, Sign, Trap,
  1304. // Direction, Overflow, AlignCheck.
  1305. // force Interrupts on.
  1306. //
  1307. #define SANITIZE_FLAGS(eFlags, mode) (\
  1308. ((mode) == KernelMode ? \
  1309. ((0x00000000L) | ((eFlags) & 0x003e0fd7)) : \
  1310. ((((eFlags) & EFLAGS_V86_MASK) && KeI386VdmIoplAllowed) ? \
  1311. (((eFlags) & KeI386EFlagsAndMaskV86) | KeI386EFlagsOrMaskV86) : \
  1312. ((EFLAGS_INTERRUPT_MASK) | ((eFlags) & EFLAGS_USER_SANITIZE)))))
  1313. //
  1314. // Masks for Dr7 and sanitize macros for various Dr registers.
  1315. //
  1316. #define DR6_LEGAL 0x0000e00f
  1317. #define DR7_LEGAL 0xffff0155 // R/W, LEN for Dr0-Dr4,
  1318. // Local enable for Dr0-Dr4,
  1319. // Le for "perfect" trapping
  1320. #define DR7_ACTIVE 0x00000055 // If any of these bits are set, a Dr is active
  1321. #define SANITIZE_DR6(Dr6, mode) ((Dr6 & DR6_LEGAL));
  1322. #define SANITIZE_DR7(Dr7, mode) ((Dr7 & DR7_LEGAL));
  1323. #define SANITIZE_DRADDR(DrReg, mode) ( \
  1324. (mode) == KernelMode ? \
  1325. (DrReg) : \
  1326. (((PVOID)DrReg <= MM_HIGHEST_USER_ADDRESS) ? \
  1327. (DrReg) : \
  1328. (0) \
  1329. ) \
  1330. )
  1331. //
  1332. // Define macro to clear reserved bits from MXCSR so that we don't
  1333. // GP fault when doing an FRSTOR
  1334. //
  1335. extern ULONG KiMXCsrMask;
  1336. #define SANITIZE_MXCSR(_mxcsr_) ((_mxcsr_) & KiMXCsrMask)
  1337. //
  1338. // Nonvolatile context pointers
  1339. //
  1340. // bryanwi 21 feb 90 - This is bogus. The 386 doesn't have
  1341. // enough nonvolatile context to make this
  1342. // structure worthwhile. Can't declare a
  1343. // field to be void, so declare a Junk structure
  1344. // instead.
  1345. typedef struct _KNONVOLATILE_CONTEXT_POINTERS {
  1346. ULONG Junk;
  1347. } KNONVOLATILE_CONTEXT_POINTERS, *PKNONVOLATILE_CONTEXT_POINTERS;
  1348. // begin_nthal
  1349. //
  1350. // Trap frame
  1351. //
  1352. // NOTE - We deal only with 32bit registers, so the assembler equivalents
  1353. // are always the extended forms.
  1354. //
  1355. // NOTE - Unless you want to run like slow molasses everywhere in the
  1356. // the system, this structure must be of DWORD length, DWORD
  1357. // aligned, and its elements must all be DWORD aligned.
  1358. //
  1359. // NOTE WELL -
  1360. //
  1361. // The i386 does not build stack frames in a consistent format, the
  1362. // frames vary depending on whether or not a privilege transition
  1363. // was involved.
  1364. //
  1365. // In order to make NtContinue work for both user mode and kernel
  1366. // mode callers, we must force a canonical stack.
  1367. //
  1368. // If we're called from kernel mode, this structure is 8 bytes longer
  1369. // than the actual frame!
  1370. //
  1371. // WARNING:
  1372. //
  1373. // KTRAP_FRAME_LENGTH needs to be 16byte integral (at present.)
  1374. //
  1375. typedef struct _KTRAP_FRAME {
  1376. //
  1377. // Following 4 values are only used and defined for DBG systems,
  1378. // but are always allocated to make switching from DBG to non-DBG
  1379. // and back quicker. They are not DEVL because they have a non-0
  1380. // performance impact.
  1381. //
  1382. ULONG DbgEbp; // Copy of User EBP set up so KB will work.
  1383. ULONG DbgEip; // EIP of caller to system call, again, for KB.
  1384. ULONG DbgArgMark; // Marker to show no args here.
  1385. ULONG DbgArgPointer; // Pointer to the actual args
  1386. //
  1387. // Temporary values used when frames are edited.
  1388. //
  1389. //
  1390. // NOTE: Any code that want's ESP must materialize it, since it
  1391. // is not stored in the frame for kernel mode callers.
  1392. //
  1393. // And code that sets ESP in a KERNEL mode frame, must put
  1394. // the new value in TempEsp, make sure that TempSegCs holds
  1395. // the real SegCs value, and put a special marker value into SegCs.
  1396. //
  1397. ULONG TempSegCs;
  1398. ULONG TempEsp;
  1399. //
  1400. // Debug registers.
  1401. //
  1402. ULONG Dr0;
  1403. ULONG Dr1;
  1404. ULONG Dr2;
  1405. ULONG Dr3;
  1406. ULONG Dr6;
  1407. ULONG Dr7;
  1408. //
  1409. // Segment registers
  1410. //
  1411. ULONG SegGs;
  1412. ULONG SegEs;
  1413. ULONG SegDs;
  1414. //
  1415. // Volatile registers
  1416. //
  1417. ULONG Edx;
  1418. ULONG Ecx;
  1419. ULONG Eax;
  1420. //
  1421. // Nesting state, not part of context record
  1422. //
  1423. ULONG PreviousPreviousMode;
  1424. PEXCEPTION_REGISTRATION_RECORD ExceptionList;
  1425. // Trash if caller was user mode.
  1426. // Saved exception list if caller
  1427. // was kernel mode or we're in
  1428. // an interrupt.
  1429. //
  1430. // FS is TIB/PCR pointer, is here to make save sequence easy
  1431. //
  1432. ULONG SegFs;
  1433. //
  1434. // Non-volatile registers
  1435. //
  1436. ULONG Edi;
  1437. ULONG Esi;
  1438. ULONG Ebx;
  1439. ULONG Ebp;
  1440. //
  1441. // Control registers
  1442. //
  1443. ULONG ErrCode;
  1444. ULONG Eip;
  1445. ULONG SegCs;
  1446. ULONG EFlags;
  1447. ULONG HardwareEsp; // WARNING - segSS:esp are only here for stacks
  1448. ULONG HardwareSegSs; // that involve a ring transition.
  1449. ULONG V86Es; // these will be present for all transitions from
  1450. ULONG V86Ds; // V86 mode
  1451. ULONG V86Fs;
  1452. ULONG V86Gs;
  1453. } KTRAP_FRAME;
  1454. typedef KTRAP_FRAME *PKTRAP_FRAME;
  1455. typedef KTRAP_FRAME *PKEXCEPTION_FRAME;
  1456. #define KTRAP_FRAME_LENGTH (sizeof(KTRAP_FRAME))
  1457. #define KTRAP_FRAME_ALIGN (sizeof(ULONG))
  1458. #define KTRAP_FRAME_ROUND (KTRAP_FRAME_ALIGN-1)
  1459. //
  1460. // Bits forced to 0 in SegCs if Esp has been edited.
  1461. //
  1462. #define FRAME_EDITED 0xfff8
  1463. // end_nthal
  1464. //
  1465. // The frame saved by KiCallUserMode is defined here to allow
  1466. // the kernel debugger to trace the entire kernel stack
  1467. // when usermode callouts are pending.
  1468. //
  1469. typedef struct _KCALLOUT_FRAME {
  1470. ULONG InStk; // saved initial stack address
  1471. ULONG TrFr; // saved callback trap frame
  1472. ULONG CbStk; // saved callback stack address
  1473. ULONG Edi; // saved nonvolatile registers
  1474. ULONG Esi; //
  1475. ULONG Ebx; //
  1476. ULONG Ebp; //
  1477. ULONG Ret; // saved return address
  1478. ULONG OutBf; // address to store output buffer
  1479. ULONG OutLn; // address to store output length
  1480. } KCALLOUT_FRAME;
  1481. typedef KCALLOUT_FRAME *PKCALLOUT_FRAME;
  1482. //
  1483. // Switch Frame
  1484. //
  1485. // 386 doesn't have an "exception frame", and doesn't normally make
  1486. // any use of nonvolatile context register structures.
  1487. //
  1488. // However, swapcontext in ctxswap.c and KeInitializeThread in
  1489. // thredini.c need to share common stack structure used at thread
  1490. // startup and switch time.
  1491. //
  1492. // This is that structure.
  1493. //
  1494. typedef struct _KSWITCHFRAME {
  1495. ULONG ExceptionList;
  1496. ULONG Eflags;
  1497. ULONG RetAddr;
  1498. } KSWITCHFRAME, *PKSWITCHFRAME;
  1499. //
  1500. // Various 387 defines
  1501. //
  1502. #define I386_80387_NP_VECTOR 0x07 // trap 7 when hardware not present
  1503. // begin_ntddk begin_wdm
  1504. //
  1505. // The non-volatile 387 state
  1506. //
  1507. typedef struct _KFLOATING_SAVE {
  1508. ULONG ControlWord;
  1509. ULONG StatusWord;
  1510. ULONG ErrorOffset;
  1511. ULONG ErrorSelector;
  1512. ULONG DataOffset; // Not used in wdm
  1513. ULONG DataSelector;
  1514. ULONG Cr0NpxState;
  1515. ULONG Spare1; // Not used in wdm
  1516. } KFLOATING_SAVE, *PKFLOATING_SAVE;
  1517. //
  1518. // i386 Specific portions of mm component
  1519. //
  1520. //
  1521. // Define the page size for the Intel 386 as 4096 (0x1000).
  1522. //
  1523. #define PAGE_SIZE 0x1000
  1524. //
  1525. // Define the number of trailing zeroes in a page aligned virtual address.
  1526. // This is used as the shift count when shifting virtual addresses to
  1527. // virtual page numbers.
  1528. //
  1529. #define PAGE_SHIFT 12L
  1530. // end_ntndis end_wdm
  1531. //
  1532. // Define the number of bits to shift to right justify the Page Directory Index
  1533. // field of a PTE.
  1534. //
  1535. #define PDI_SHIFT_X86 22
  1536. #define PDI_SHIFT_X86PAE 21
  1537. #if !defined (_X86PAE_)
  1538. #define PDI_SHIFT PDI_SHIFT_X86
  1539. #else
  1540. #define PDI_SHIFT PDI_SHIFT_X86PAE
  1541. #define PPI_SHIFT 30
  1542. #endif
  1543. //
  1544. // Define the number of bits to shift to right justify the Page Table Index
  1545. // field of a PTE.
  1546. //
  1547. #define PTI_SHIFT 12
  1548. //
  1549. // Define the highest user address and user probe address.
  1550. //
  1551. extern PVOID *MmHighestUserAddress;
  1552. extern PVOID *MmSystemRangeStart;
  1553. extern ULONG *MmUserProbeAddress;
  1554. #define MM_HIGHEST_USER_ADDRESS *MmHighestUserAddress
  1555. #define MM_SYSTEM_RANGE_START *MmSystemRangeStart
  1556. #define MM_USER_PROBE_ADDRESS *MmUserProbeAddress
  1557. //
  1558. // The lowest user address reserves the low 64k.
  1559. //
  1560. #define MM_LOWEST_USER_ADDRESS (PVOID)0x10000
  1561. //
  1562. // The lowest address for system space.
  1563. //
  1564. #if !defined (_X86PAE_)
  1565. #define MM_LOWEST_SYSTEM_ADDRESS (PVOID)0xC0800000
  1566. #else
  1567. #define MM_LOWEST_SYSTEM_ADDRESS (PVOID)0xC0C00000
  1568. #endif
  1569. // begin_wdm
  1570. #define MmGetProcedureAddress(Address) (Address)
  1571. #define MmLockPagableCodeSection(Address) MmLockPagableDataSection(Address)
  1572. // end_ntddk end_wdm
  1573. //
  1574. // Define the number of bits to shift to right justify the Page Directory Index
  1575. // field of a PTE.
  1576. //
  1577. #define PDI_SHIFT_X86 22
  1578. #define PDI_SHIFT_X86PAE 21
  1579. #if !defined (_X86PAE_)
  1580. #define PDI_SHIFT PDI_SHIFT_X86
  1581. #else
  1582. #define PDI_SHIFT PDI_SHIFT_X86PAE
  1583. #define PPI_SHIFT 30
  1584. #endif
  1585. //
  1586. // Define the number of bits to shift to right justify the Page Table Index
  1587. // field of a PTE.
  1588. //
  1589. #define PTI_SHIFT 12
  1590. //
  1591. // Define page directory and page base addresses.
  1592. //
  1593. #define PDE_BASE_X86 0xc0300000
  1594. #define PDE_BASE_X86PAE 0xc0600000
  1595. #define PTE_TOP_X86 0xC03FFFFF
  1596. #define PDE_TOP_X86 0xC0300FFF
  1597. #define PTE_TOP_X86PAE 0xC07FFFFF
  1598. #define PDE_TOP_X86PAE 0xC0603FFF
  1599. #if !defined (_X86PAE_)
  1600. #define PDE_BASE PDE_BASE_X86
  1601. #define PTE_TOP PTE_TOP_X86
  1602. #define PDE_TOP PDE_TOP_X86
  1603. #else
  1604. #define PDE_BASE PDE_BASE_X86PAE
  1605. #define PTE_TOP PTE_TOP_X86PAE
  1606. #define PDE_TOP PDE_TOP_X86PAE
  1607. #endif
  1608. #define PTE_BASE 0xc0000000
  1609. #define KIP0PCRADDRESS 0xffdff000
  1610. #define KI_USER_SHARED_DATA 0xffdf0000
  1611. #define SharedUserData ((KUSER_SHARED_DATA * const) KI_USER_SHARED_DATA)
  1612. //
  1613. // Result type definition for i386. (Machine specific enumerate type
  1614. // which is return type for portable exinterlockedincrement/decrement
  1615. // procedures.) In general, you should use the enumerated type defined
  1616. // in ex.h instead of directly referencing these constants.
  1617. //
  1618. // Flags loaded into AH by LAHF instruction
  1619. #define EFLAG_SIGN 0x8000
  1620. #define EFLAG_ZERO 0x4000
  1621. #define EFLAG_SELECT (EFLAG_SIGN | EFLAG_ZERO)
  1622. #define RESULT_NEGATIVE ((EFLAG_SIGN & ~EFLAG_ZERO) & EFLAG_SELECT)
  1623. #define RESULT_ZERO ((~EFLAG_SIGN & EFLAG_ZERO) & EFLAG_SELECT)
  1624. #define RESULT_POSITIVE ((~EFLAG_SIGN & ~EFLAG_ZERO) & EFLAG_SELECT)
  1625. //
  1626. // Convert various portable ExInterlock APIs into their architectural
  1627. // equivalents.
  1628. //
  1629. #if PRAGMA_DEPRECATED_DDK
  1630. #pragma deprecated(ExInterlockedIncrementLong) // Use InterlockedIncrement
  1631. #pragma deprecated(ExInterlockedDecrementLong) // Use InterlockedDecrement
  1632. #pragma deprecated(ExInterlockedExchangeUlong) // Use InterlockedExchange
  1633. #endif
  1634. #define ExInterlockedIncrementLong(Addend,Lock) \
  1635. Exfi386InterlockedIncrementLong(Addend)
  1636. #define ExInterlockedDecrementLong(Addend,Lock) \
  1637. Exfi386InterlockedDecrementLong(Addend)
  1638. #define ExInterlockedExchangeUlong(Target,Value,Lock) \
  1639. Exfi386InterlockedExchangeUlong(Target,Value)
  1640. // begin_wdm
  1641. #define ExInterlockedAddUlong ExfInterlockedAddUlong
  1642. #define ExInterlockedInsertHeadList ExfInterlockedInsertHeadList
  1643. #define ExInterlockedInsertTailList ExfInterlockedInsertTailList
  1644. #define ExInterlockedRemoveHeadList ExfInterlockedRemoveHeadList
  1645. #define ExInterlockedPopEntryList ExfInterlockedPopEntryList
  1646. #define ExInterlockedPushEntryList ExfInterlockedPushEntryList
  1647. // end_wdm
  1648. //
  1649. // Prototypes for architectural specific versions of Exi386 Api
  1650. //
  1651. //
  1652. // Interlocked result type is portable, but its values are machine specific.
  1653. // Constants for value are in i386.h, mips.h, etc.
  1654. //
  1655. typedef enum _INTERLOCKED_RESULT {
  1656. ResultNegative = RESULT_NEGATIVE,
  1657. ResultZero = RESULT_ZERO,
  1658. ResultPositive = RESULT_POSITIVE
  1659. } INTERLOCKED_RESULT;
  1660. NTKERNELAPI
  1661. INTERLOCKED_RESULT
  1662. FASTCALL
  1663. Exfi386InterlockedIncrementLong (
  1664. IN PLONG Addend
  1665. );
  1666. NTKERNELAPI
  1667. INTERLOCKED_RESULT
  1668. FASTCALL
  1669. Exfi386InterlockedDecrementLong (
  1670. IN PLONG Addend
  1671. );
  1672. NTKERNELAPI
  1673. ULONG
  1674. FASTCALL
  1675. Exfi386InterlockedExchangeUlong (
  1676. IN PULONG Target,
  1677. IN ULONG Value
  1678. );
  1679. #if !defined(_WINBASE_) && !defined(NONTOSPINTERLOCK)
  1680. #if !defined(MIDL_PASS) // wdm
  1681. #if defined(NO_INTERLOCKED_INTRINSICS) || defined(_CROSS_PLATFORM_)
  1682. // begin_wdm
  1683. NTKERNELAPI
  1684. LONG
  1685. FASTCALL
  1686. InterlockedIncrement(
  1687. IN LONG volatile *Addend
  1688. );
  1689. NTKERNELAPI
  1690. LONG
  1691. FASTCALL
  1692. InterlockedDecrement(
  1693. IN LONG volatile *Addend
  1694. );
  1695. NTKERNELAPI
  1696. LONG
  1697. FASTCALL
  1698. InterlockedExchange(
  1699. IN OUT LONG volatile *Target,
  1700. IN LONG Value
  1701. );
  1702. #define InterlockedExchangePointer(Target, Value) \
  1703. (PVOID)InterlockedExchange((PLONG)(Target), (LONG)(Value))
  1704. LONG
  1705. FASTCALL
  1706. InterlockedExchangeAdd(
  1707. IN OUT LONG volatile *Addend,
  1708. IN LONG Increment
  1709. );
  1710. NTKERNELAPI
  1711. LONG
  1712. FASTCALL
  1713. InterlockedCompareExchange(
  1714. IN OUT LONG volatile *Destination,
  1715. IN LONG ExChange,
  1716. IN LONG Comperand
  1717. );
  1718. #define InterlockedCompareExchangePointer(Destination, ExChange, Comperand) \
  1719. (PVOID)InterlockedCompareExchange((PLONG)Destination, (LONG)ExChange, (LONG)Comperand)
  1720. #define InterlockedCompareExchange64(Destination, ExChange, Comperand) \
  1721. ExfInterlockedCompareExchange64(Destination, &(ExChange), &(Comperand))
  1722. NTKERNELAPI
  1723. LONGLONG
  1724. FASTCALL
  1725. ExfInterlockedCompareExchange64(
  1726. IN OUT LONGLONG volatile *Destination,
  1727. IN PLONGLONG ExChange,
  1728. IN PLONGLONG Comperand
  1729. );
  1730. // end_wdm
  1731. #else // NO_INTERLOCKED_INCREMENTS || _CROSS_PLATFORM_
  1732. #define InterlockedExchangePointer(Target, Value) \
  1733. (PVOID)InterlockedExchange((PLONG)Target, (LONG)Value)
  1734. #if (_MSC_FULL_VER > 13009037)
  1735. LONG
  1736. __cdecl
  1737. _InterlockedExchange(
  1738. IN OUT LONG volatile *Target,
  1739. IN LONG Value
  1740. );
  1741. #pragma intrinsic (_InterlockedExchange)
  1742. #define InterlockedExchange _InterlockedExchange
  1743. #else
  1744. FORCEINLINE
  1745. LONG
  1746. FASTCALL
  1747. InterlockedExchange(
  1748. IN OUT LONG volatile *Target,
  1749. IN LONG Value
  1750. )
  1751. {
  1752. __asm {
  1753. mov eax, Value
  1754. mov ecx, Target
  1755. xchg [ecx], eax
  1756. }
  1757. }
  1758. #endif
  1759. #if (_MSC_FULL_VER > 13009037)
  1760. LONG
  1761. __cdecl
  1762. _InterlockedIncrement(
  1763. IN LONG volatile *Addend
  1764. );
  1765. #pragma intrinsic (_InterlockedIncrement)
  1766. #define InterlockedIncrement _InterlockedIncrement
  1767. #else
  1768. #define InterlockedIncrement(Addend) (InterlockedExchangeAdd (Addend, 1)+1)
  1769. #endif
  1770. #if (_MSC_FULL_VER > 13009037)
  1771. LONG
  1772. __cdecl
  1773. _InterlockedDecrement(
  1774. IN LONG volatile *Addend
  1775. );
  1776. #pragma intrinsic (_InterlockedDecrement)
  1777. #define InterlockedDecrement _InterlockedDecrement
  1778. #else
  1779. #define InterlockedDecrement(Addend) (InterlockedExchangeAdd (Addend, -1)-1)
  1780. #endif
  1781. #if (_MSC_FULL_VER > 13009037)
  1782. LONG
  1783. __cdecl
  1784. _InterlockedExchangeAdd(
  1785. IN OUT LONG volatile *Addend,
  1786. IN LONG Increment
  1787. );
  1788. #pragma intrinsic (_InterlockedExchangeAdd)
  1789. #define InterlockedExchangeAdd _InterlockedExchangeAdd
  1790. #else
  1791. // begin_wdm
  1792. FORCEINLINE
  1793. LONG
  1794. FASTCALL
  1795. InterlockedExchangeAdd(
  1796. IN OUT LONG volatile *Addend,
  1797. IN LONG Increment
  1798. )
  1799. {
  1800. __asm {
  1801. mov eax, Increment
  1802. mov ecx, Addend
  1803. lock xadd [ecx], eax
  1804. }
  1805. }
  1806. // end_wdm
  1807. #endif
  1808. #if (_MSC_FULL_VER > 13009037)
  1809. LONG
  1810. __cdecl
  1811. _InterlockedCompareExchange (
  1812. IN OUT LONG volatile *Destination,
  1813. IN LONG ExChange,
  1814. IN LONG Comperand
  1815. );
  1816. #pragma intrinsic (_InterlockedCompareExchange)
  1817. #define InterlockedCompareExchange (LONG)_InterlockedCompareExchange
  1818. #else
  1819. FORCEINLINE
  1820. LONG
  1821. FASTCALL
  1822. InterlockedCompareExchange(
  1823. IN OUT LONG volatile *Destination,
  1824. IN LONG Exchange,
  1825. IN LONG Comperand
  1826. )
  1827. {
  1828. __asm {
  1829. mov eax, Comperand
  1830. mov ecx, Destination
  1831. mov edx, Exchange
  1832. lock cmpxchg [ecx], edx
  1833. }
  1834. }
  1835. #endif
  1836. #define InterlockedCompareExchangePointer(Destination, ExChange, Comperand) \
  1837. (PVOID)InterlockedCompareExchange((PLONG)Destination, (LONG)ExChange, (LONG)Comperand)
  1838. #define InterlockedCompareExchange64(Destination, ExChange, Comperand) \
  1839. ExfInterlockedCompareExchange64(Destination, &(ExChange), &(Comperand))
  1840. NTKERNELAPI
  1841. LONGLONG
  1842. FASTCALL
  1843. ExfInterlockedCompareExchange64(
  1844. IN OUT LONGLONG volatile *Destination,
  1845. IN PLONGLONG ExChange,
  1846. IN PLONGLONG Comperand
  1847. );
  1848. #endif // INTERLOCKED_INTRINSICS || _CROSS_PLATFORM_
  1849. // begin_wdm
  1850. #endif // MIDL_PASS
  1851. #endif // __WINBASE__ && !NONTOSPINTERLOCK
  1852. typedef struct _PROCESS_IO_PORT_HANDLER_INFORMATION {
  1853. BOOLEAN Install; // true if handlers to be installed
  1854. ULONG NumEntries;
  1855. ULONG Context;
  1856. PEMULATOR_ACCESS_ENTRY EmulatorAccessEntries;
  1857. } PROCESS_IO_PORT_HANDLER_INFORMATION, *PPROCESS_IO_PORT_HANDLER_INFORMATION;
  1858. //
  1859. // Vdm Objects and Io handling structure
  1860. //
  1861. typedef struct _VDM_IO_HANDLER_FUNCTIONS {
  1862. PDRIVER_IO_PORT_ULONG UlongIo;
  1863. PDRIVER_IO_PORT_ULONG_STRING UlongStringIo;
  1864. PDRIVER_IO_PORT_USHORT UshortIo[2];
  1865. PDRIVER_IO_PORT_USHORT_STRING UshortStringIo[2];
  1866. PDRIVER_IO_PORT_UCHAR UcharIo[4];
  1867. PDRIVER_IO_PORT_UCHAR_STRING UcharStringIo[4];
  1868. } VDM_IO_HANDLER_FUNCTIONS, *PVDM_IO_HANDLER_FUNCTIONS;
  1869. typedef struct _VDM_IO_HANDLER {
  1870. struct _VDM_IO_HANDLER *Next;
  1871. ULONG PortNumber;
  1872. VDM_IO_HANDLER_FUNCTIONS IoFunctions[2];
  1873. } VDM_IO_HANDLER, *PVDM_IO_HANDLER;
  1874. // begin_nthal begin_ntddk begin_wdm
  1875. #if !defined(MIDL_PASS) && defined(_M_IX86)
  1876. //
  1877. // i386 function definitions
  1878. //
  1879. #pragma warning(disable:4035) // re-enable below
  1880. // end_wdm
  1881. #if NT_UP
  1882. #define _PCR ds:[KIP0PCRADDRESS]
  1883. #else
  1884. #define _PCR fs:[0]
  1885. #endif
  1886. //
  1887. // Get address of current processor block.
  1888. //
  1889. // WARNING: This inline macro can only be used by the kernel or hal
  1890. //
  1891. FORCEINLINE
  1892. PKPRCB
  1893. NTAPI
  1894. KeGetCurrentPrcb (VOID)
  1895. {
  1896. __asm { mov eax, _PCR KPCR.Prcb }
  1897. }
  1898. // begin_ntddk begin_wdm
  1899. //
  1900. // Get current IRQL.
  1901. //
  1902. // On x86 this function resides in the HAL
  1903. //
  1904. NTHALAPI
  1905. KIRQL
  1906. NTAPI
  1907. KeGetCurrentIrql();
  1908. // end_wdm
  1909. //
  1910. // Get the current processor number
  1911. //
  1912. FORCEINLINE
  1913. ULONG
  1914. NTAPI
  1915. KeGetCurrentProcessorNumber(VOID)
  1916. {
  1917. __asm { movzx eax, _PCR KPCR.Number }
  1918. }
  1919. #pragma warning(default:4035)
  1920. // begin_wdm
  1921. #endif // !defined(MIDL_PASS) && defined(_M_IX86)
  1922. NTKERNELAPI
  1923. NTSTATUS
  1924. NTAPI
  1925. KeSaveFloatingPointState (
  1926. OUT PKFLOATING_SAVE FloatSave
  1927. );
  1928. NTKERNELAPI
  1929. NTSTATUS
  1930. NTAPI
  1931. KeRestoreFloatingPointState (
  1932. IN PKFLOATING_SAVE FloatSave
  1933. );
  1934. // end_ntddk end_wdm
  1935. // begin_nthal
  1936. NTKERNELAPI
  1937. VOID
  1938. NTAPI
  1939. KeProfileInterruptWithSource (
  1940. IN struct _KTRAP_FRAME *TrapFrame,
  1941. IN KPROFILE_SOURCE ProfileSource
  1942. );
  1943. #endif // defined(_X86_)
  1944. #ifdef _X86_
  1945. VOID
  1946. NTAPI
  1947. Ke386SetLdtProcess (
  1948. struct _KPROCESS *Process,
  1949. PLDT_ENTRY Ldt,
  1950. ULONG Limit
  1951. );
  1952. VOID
  1953. NTAPI
  1954. Ke386SetDescriptorProcess (
  1955. struct _KPROCESS *Process,
  1956. ULONG Offset,
  1957. LDT_ENTRY LdtEntry
  1958. );
  1959. VOID
  1960. NTAPI
  1961. Ke386GetGdtEntryThread (
  1962. struct _KTHREAD *Thread,
  1963. ULONG Offset,
  1964. PKGDTENTRY Descriptor
  1965. );
  1966. BOOLEAN
  1967. NTAPI
  1968. Ke386SetIoAccessMap (
  1969. ULONG MapNumber,
  1970. PKIO_ACCESS_MAP IoAccessMap
  1971. );
  1972. BOOLEAN
  1973. NTAPI
  1974. Ke386QueryIoAccessMap (
  1975. ULONG MapNumber,
  1976. PKIO_ACCESS_MAP IoAccessMap
  1977. );
  1978. BOOLEAN
  1979. NTAPI
  1980. Ke386IoSetAccessProcess (
  1981. struct _KPROCESS *Process,
  1982. ULONG MapNumber
  1983. );
  1984. VOID
  1985. NTAPI
  1986. Ke386SetIOPL(
  1987. struct _KPROCESS *Process
  1988. );
  1989. NTSTATUS
  1990. NTAPI
  1991. Ke386CallBios (
  1992. IN ULONG BiosCommand,
  1993. IN OUT PCONTEXT BiosArguments
  1994. );
  1995. VOID
  1996. NTAPI
  1997. KiEditIopmDpc (
  1998. IN struct _KDPC *Dpc,
  1999. IN PVOID DeferredContext,
  2000. IN PVOID SystemArgument1,
  2001. IN PVOID SystemArgument2
  2002. );
  2003. BOOLEAN
  2004. NTAPI
  2005. Ki386GetSelectorParameters(
  2006. IN USHORT Selector,
  2007. OUT PULONG Flags,
  2008. OUT PULONG Base,
  2009. OUT PULONG Limit
  2010. );
  2011. ULONG
  2012. Ki386DispatchOpcodeV86 (
  2013. IN PKTRAP_FRAME TrapFrame
  2014. );
  2015. NTSTATUS
  2016. NTAPI
  2017. Ke386SetVdmInterruptHandler (
  2018. IN struct _KPROCESS *Process,
  2019. IN ULONG Interrupt,
  2020. IN USHORT Selector,
  2021. IN ULONG Offset,
  2022. IN BOOLEAN Gate32
  2023. );
  2024. #endif //_X86_
  2025. #define INIT_SYSTEMROOT_LINKNAME "\\SystemRoot"
  2026. #define INIT_SYSTEMROOT_DLLPATH "\\SystemRoot\\System32"
  2027. #define INIT_SYSTEMROOT_BINPATH "\\SystemRoot\\System32"
  2028. extern ULONG NtBuildNumber;
  2029. #if defined(_M_AMD64) && !defined(RC_INVOKED) && !defined(MIDL_PASS)
  2030. //
  2031. // Define intrinsic function to do in's and out's.
  2032. //
  2033. #ifdef __cplusplus
  2034. extern "C" {
  2035. #endif
  2036. UCHAR
  2037. __inbyte (
  2038. IN USHORT Port
  2039. );
  2040. USHORT
  2041. __inword (
  2042. IN USHORT Port
  2043. );
  2044. ULONG
  2045. __indword (
  2046. IN USHORT Port
  2047. );
  2048. VOID
  2049. __outbyte (
  2050. IN USHORT Port,
  2051. IN UCHAR Data
  2052. );
  2053. VOID
  2054. __outword (
  2055. IN USHORT Port,
  2056. IN USHORT Data
  2057. );
  2058. VOID
  2059. __outdword (
  2060. IN USHORT Port,
  2061. IN ULONG Data
  2062. );
  2063. VOID
  2064. __inbytestring (
  2065. IN USHORT Port,
  2066. IN PUCHAR Buffer,
  2067. IN ULONG Count
  2068. );
  2069. VOID
  2070. __inwordstring (
  2071. IN USHORT Port,
  2072. IN PUSHORT Buffer,
  2073. IN ULONG Count
  2074. );
  2075. VOID
  2076. __indwordstring (
  2077. IN USHORT Port,
  2078. IN PULONG Buffer,
  2079. IN ULONG Count
  2080. );
  2081. VOID
  2082. __outbytestring (
  2083. IN USHORT Port,
  2084. IN PUCHAR Buffer,
  2085. IN ULONG Count
  2086. );
  2087. VOID
  2088. __outwordstring (
  2089. IN USHORT Port,
  2090. IN PUSHORT Buffer,
  2091. IN ULONG Count
  2092. );
  2093. VOID
  2094. __outdwordstring (
  2095. IN USHORT Port,
  2096. IN PULONG Buffer,
  2097. IN ULONG Count
  2098. );
  2099. #ifdef __cplusplus
  2100. }
  2101. #endif
  2102. #pragma intrinsic(__inbyte)
  2103. #pragma intrinsic(__inword)
  2104. #pragma intrinsic(__indword)
  2105. #pragma intrinsic(__outbyte)
  2106. #pragma intrinsic(__outword)
  2107. #pragma intrinsic(__outdword)
  2108. #pragma intrinsic(__inbytestring)
  2109. #pragma intrinsic(__inwordstring)
  2110. #pragma intrinsic(__indwordstring)
  2111. #pragma intrinsic(__outbytestring)
  2112. #pragma intrinsic(__outwordstring)
  2113. #pragma intrinsic(__outdwordstring)
  2114. //
  2115. // Interlocked intrinsic functions.
  2116. //
  2117. #define InterlockedAnd _InterlockedAnd
  2118. #define InterlockedOr _InterlockedOr
  2119. #define InterlockedXor _InterlockedXor
  2120. #define InterlockedIncrement _InterlockedIncrement
  2121. #define InterlockedDecrement _InterlockedDecrement
  2122. #define InterlockedAdd _InterlockedAdd
  2123. #define InterlockedExchange _InterlockedExchange
  2124. #define InterlockedExchangeAdd _InterlockedExchangeAdd
  2125. #define InterlockedCompareExchange _InterlockedCompareExchange
  2126. #define InterlockedAnd64 _InterlockedAnd64
  2127. #define InterlockedOr64 _InterlockedOr64
  2128. #define InterlockedXor64 _InterlockedXor64
  2129. #define InterlockedIncrement64 _InterlockedIncrement64
  2130. #define InterlockedDecrement64 _InterlockedDecrement64
  2131. #define InterlockedAdd64 _InterlockedAdd64
  2132. #define InterlockedExchange64 _InterlockedExchange64
  2133. #define InterlockedExchangeAdd64 _InterlockedExchangeAdd64
  2134. #define InterlockedCompareExchange64 _InterlockedCompareExchange64
  2135. #define InterlockedExchangePointer _InterlockedExchangePointer
  2136. #define InterlockedCompareExchangePointer _InterlockedCompareExchangePointer
  2137. #ifdef __cplusplus
  2138. extern "C" {
  2139. #endif
  2140. LONG
  2141. InterlockedAnd (
  2142. IN OUT LONG volatile *Destination,
  2143. IN LONG Value
  2144. );
  2145. LONG
  2146. InterlockedOr (
  2147. IN OUT LONG volatile *Destination,
  2148. IN LONG Value
  2149. );
  2150. LONG
  2151. InterlockedXor (
  2152. IN OUT LONG volatile *Destination,
  2153. IN LONG Value
  2154. );
  2155. LONG64
  2156. InterlockedAnd64 (
  2157. IN OUT LONG64 volatile *Destination,
  2158. IN LONG64 Value
  2159. );
  2160. LONG64
  2161. InterlockedOr64 (
  2162. IN OUT LONG64 volatile *Destination,
  2163. IN LONG64 Value
  2164. );
  2165. LONG64
  2166. InterlockedXor64 (
  2167. IN OUT LONG64 volatile *Destination,
  2168. IN LONG64 Value
  2169. );
  2170. LONG
  2171. InterlockedIncrement(
  2172. IN OUT LONG volatile *Addend
  2173. );
  2174. LONG
  2175. InterlockedDecrement(
  2176. IN OUT LONG volatile *Addend
  2177. );
  2178. LONG
  2179. InterlockedExchange(
  2180. IN OUT LONG volatile *Target,
  2181. IN LONG Value
  2182. );
  2183. LONG
  2184. InterlockedExchangeAdd(
  2185. IN OUT LONG volatile *Addend,
  2186. IN LONG Value
  2187. );
  2188. #if !defined(_X86AMD64_)
  2189. __forceinline
  2190. LONG
  2191. InterlockedAdd(
  2192. IN OUT LONG volatile *Addend,
  2193. IN LONG Value
  2194. )
  2195. {
  2196. return InterlockedExchangeAdd(Addend, Value) + Value;
  2197. }
  2198. #endif
  2199. LONG
  2200. InterlockedCompareExchange (
  2201. IN OUT LONG volatile *Destination,
  2202. IN LONG ExChange,
  2203. IN LONG Comperand
  2204. );
  2205. LONG64
  2206. InterlockedIncrement64(
  2207. IN OUT LONG64 volatile *Addend
  2208. );
  2209. LONG64
  2210. InterlockedDecrement64(
  2211. IN OUT LONG64 volatile *Addend
  2212. );
  2213. LONG64
  2214. InterlockedExchange64(
  2215. IN OUT LONG64 volatile *Target,
  2216. IN LONG64 Value
  2217. );
  2218. LONG64
  2219. InterlockedExchangeAdd64(
  2220. IN OUT LONG64 volatile *Addend,
  2221. IN LONG64 Value
  2222. );
  2223. #if !defined(_X86AMD64_)
  2224. __forceinline
  2225. LONG64
  2226. InterlockedAdd64(
  2227. IN OUT LONG64 volatile *Addend,
  2228. IN LONG64 Value
  2229. )
  2230. {
  2231. return InterlockedExchangeAdd64(Addend, Value) + Value;
  2232. }
  2233. #endif
  2234. LONG64
  2235. InterlockedCompareExchange64 (
  2236. IN OUT LONG64 volatile *Destination,
  2237. IN LONG64 ExChange,
  2238. IN LONG64 Comperand
  2239. );
  2240. PVOID
  2241. InterlockedCompareExchangePointer (
  2242. IN OUT PVOID volatile *Destination,
  2243. IN PVOID Exchange,
  2244. IN PVOID Comperand
  2245. );
  2246. PVOID
  2247. InterlockedExchangePointer(
  2248. IN OUT PVOID volatile *Target,
  2249. IN PVOID Value
  2250. );
  2251. #pragma intrinsic(_InterlockedAnd)
  2252. #pragma intrinsic(_InterlockedOr)
  2253. #pragma intrinsic(_InterlockedXor)
  2254. #pragma intrinsic(_InterlockedIncrement)
  2255. #pragma intrinsic(_InterlockedDecrement)
  2256. #pragma intrinsic(_InterlockedExchange)
  2257. #pragma intrinsic(_InterlockedExchangeAdd)
  2258. #pragma intrinsic(_InterlockedCompareExchange)
  2259. #pragma intrinsic(_InterlockedAnd64)
  2260. #pragma intrinsic(_InterlockedOr64)
  2261. #pragma intrinsic(_InterlockedXor64)
  2262. #pragma intrinsic(_InterlockedIncrement64)
  2263. #pragma intrinsic(_InterlockedDecrement64)
  2264. #pragma intrinsic(_InterlockedExchange64)
  2265. #pragma intrinsic(_InterlockedExchangeAdd64)
  2266. #pragma intrinsic(_InterlockedCompareExchange64)
  2267. #pragma intrinsic(_InterlockedExchangePointer)
  2268. #pragma intrinsic(_InterlockedCompareExchangePointer)
  2269. #ifdef __cplusplus
  2270. }
  2271. #endif
  2272. #endif // defined(_M_AMD64) && !defined(RC_INVOKED) && !defined(MIDL_PASS)
  2273. #if defined(_AMD64_)
  2274. //
  2275. // Types to use to contain PFNs and their counts.
  2276. //
  2277. typedef ULONG PFN_COUNT;
  2278. typedef LONG64 SPFN_NUMBER, *PSPFN_NUMBER;
  2279. typedef ULONG64 PFN_NUMBER, *PPFN_NUMBER;
  2280. //
  2281. // Define maximum size of flush multiple TB request.
  2282. //
  2283. #define FLUSH_MULTIPLE_MAXIMUM 16
  2284. //
  2285. // Indicate that the AMD64 compiler supports the allocate pragmas.
  2286. //
  2287. #define ALLOC_PRAGMA 1
  2288. #define ALLOC_DATA_PRAGMA 1
  2289. //
  2290. // Define constants for bits in CR0.
  2291. //
  2292. #define CR0_PE 0x00000001 // protection enable
  2293. #define CR0_MP 0x00000002 // math present
  2294. #define CR0_EM 0x00000004 // emulate math coprocessor
  2295. #define CR0_TS 0x00000008 // task switched
  2296. #define CR0_ET 0x00000010 // extension type (80387)
  2297. #define CR0_NE 0x00000020 // numeric error
  2298. #define CR0_WP 0x00010000 // write protect
  2299. #define CR0_AM 0x00040000 // alignment mask
  2300. #define CR0_NW 0x20000000 // not write-through
  2301. #define CR0_CD 0x40000000 // cache disable
  2302. #define CR0_PG 0x80000000 // paging
  2303. //
  2304. // Define functions to read and write CR0.
  2305. //
  2306. #ifdef __cplusplus
  2307. extern "C" {
  2308. #endif
  2309. #define ReadCR0() __readcr0()
  2310. ULONG64
  2311. __readcr0 (
  2312. VOID
  2313. );
  2314. #define WriteCR0(Data) __writecr0(Data)
  2315. VOID
  2316. __writecr0 (
  2317. IN ULONG64 Data
  2318. );
  2319. #pragma intrinsic(__readcr0)
  2320. #pragma intrinsic(__writecr0)
  2321. //
  2322. // Define functions to read and write CR3.
  2323. //
  2324. #define ReadCR3() __readcr3()
  2325. ULONG64
  2326. __readcr3 (
  2327. VOID
  2328. );
  2329. #define WriteCR3(Data) __writecr3(Data)
  2330. VOID
  2331. __writecr3 (
  2332. IN ULONG64 Data
  2333. );
  2334. #pragma intrinsic(__readcr3)
  2335. #pragma intrinsic(__writecr3)
  2336. //
  2337. // Define constants for bits in CR4.
  2338. //
  2339. #define CR4_VME 0x00000001 // V86 mode extensions
  2340. #define CR4_PVI 0x00000002 // Protected mode virtual interrupts
  2341. #define CR4_TSD 0x00000004 // Time stamp disable
  2342. #define CR4_DE 0x00000008 // Debugging Extensions
  2343. #define CR4_PSE 0x00000010 // Page size extensions
  2344. #define CR4_PAE 0x00000020 // Physical address extensions
  2345. #define CR4_MCE 0x00000040 // Machine check enable
  2346. #define CR4_PGE 0x00000080 // Page global enable
  2347. #define CR4_FXSR 0x00000200 // FXSR used by OS
  2348. #define CR4_XMMEXCPT 0x00000400 // XMMI used by OS
  2349. //
  2350. // Define functions to read and write CR4.
  2351. //
  2352. #define ReadCR4() __readcr4()
  2353. ULONG64
  2354. __readcr4 (
  2355. VOID
  2356. );
  2357. #define WriteCR4(Data) __writecr4(Data)
  2358. VOID
  2359. __writecr4 (
  2360. IN ULONG64 Data
  2361. );
  2362. #pragma intrinsic(__readcr4)
  2363. #pragma intrinsic(__writecr4)
  2364. //
  2365. // Define functions to read and write CR8.
  2366. //
  2367. // CR8 is the APIC TPR register.
  2368. //
  2369. #define ReadCR8() __readcr8()
  2370. ULONG64
  2371. __readcr8 (
  2372. VOID
  2373. );
  2374. #define WriteCR8(Data) __writecr8(Data)
  2375. VOID
  2376. __writecr8 (
  2377. IN ULONG64 Data
  2378. );
  2379. #pragma intrinsic(__readcr8)
  2380. #pragma intrinsic(__writecr8)
  2381. #ifdef __cplusplus
  2382. }
  2383. #endif
  2384. //
  2385. // Interrupt Request Level definitions
  2386. //
  2387. #define PASSIVE_LEVEL 0 // Passive release level
  2388. #define LOW_LEVEL 0 // Lowest interrupt level
  2389. #define APC_LEVEL 1 // APC interrupt level
  2390. #define DISPATCH_LEVEL 2 // Dispatcher level
  2391. #define CLOCK_LEVEL 13 // Interval clock level
  2392. #define IPI_LEVEL 14 // Interprocessor interrupt level
  2393. #define POWER_LEVEL 14 // Power failure level
  2394. #define PROFILE_LEVEL 15 // timer used for profiling.
  2395. #define HIGH_LEVEL 15 // Highest interrupt level
  2396. #if defined(NT_UP)
  2397. #define SYNCH_LEVEL DISPATCH_LEVEL // synchronization level
  2398. #else
  2399. #define SYNCH_LEVEL (IPI_LEVEL - 1) // synchronization level
  2400. #endif
  2401. #define IRQL_VECTOR_OFFSET 2 // offset from IRQL to vector / 16
  2402. #define MODE_MASK 1
  2403. //
  2404. // I/O space read and write macros.
  2405. //
  2406. // The READ/WRITE_REGISTER_* calls manipulate I/O registers in MEMORY space.
  2407. // (Use move instructions, with LOCK prefix to force correct behavior
  2408. // w.r.t. caches and write buffers.)
  2409. //
  2410. // The READ/WRITE_PORT_* calls manipulate I/O registers in PORT space.
  2411. // (Use in/out instructions.)
  2412. //
  2413. __forceinline
  2414. UCHAR
  2415. READ_REGISTER_UCHAR (
  2416. volatile UCHAR *Register
  2417. )
  2418. {
  2419. return *Register;
  2420. }
  2421. __forceinline
  2422. USHORT
  2423. READ_REGISTER_USHORT (
  2424. volatile USHORT *Register
  2425. )
  2426. {
  2427. return *Register;
  2428. }
  2429. __forceinline
  2430. ULONG
  2431. READ_REGISTER_ULONG (
  2432. volatile ULONG *Register
  2433. )
  2434. {
  2435. return *Register;
  2436. }
  2437. __forceinline
  2438. VOID
  2439. READ_REGISTER_BUFFER_UCHAR (
  2440. PUCHAR Register,
  2441. PUCHAR Buffer,
  2442. ULONG Count
  2443. )
  2444. {
  2445. __movsb(Register, Buffer, Count);
  2446. return;
  2447. }
  2448. __forceinline
  2449. VOID
  2450. READ_REGISTER_BUFFER_USHORT (
  2451. PUSHORT Register,
  2452. PUSHORT Buffer,
  2453. ULONG Count
  2454. )
  2455. {
  2456. __movsw(Register, Buffer, Count);
  2457. return;
  2458. }
  2459. __forceinline
  2460. VOID
  2461. READ_REGISTER_BUFFER_ULONG (
  2462. PULONG Register,
  2463. PULONG Buffer,
  2464. ULONG Count
  2465. )
  2466. {
  2467. __movsd(Register, Buffer, Count);
  2468. return;
  2469. }
  2470. __forceinline
  2471. VOID
  2472. WRITE_REGISTER_UCHAR (
  2473. PUCHAR Register,
  2474. UCHAR Value
  2475. )
  2476. {
  2477. LONG Synch;
  2478. *Register = Value;
  2479. InterlockedOr(&Synch, 1);
  2480. return;
  2481. }
  2482. __forceinline
  2483. VOID
  2484. WRITE_REGISTER_USHORT (
  2485. PUSHORT Register,
  2486. USHORT Value
  2487. )
  2488. {
  2489. LONG Synch;
  2490. *Register = Value;
  2491. InterlockedOr(&Synch, 1);
  2492. return;
  2493. }
  2494. __forceinline
  2495. VOID
  2496. WRITE_REGISTER_ULONG (
  2497. PULONG Register,
  2498. ULONG Value
  2499. )
  2500. {
  2501. LONG Synch;
  2502. *Register = Value;
  2503. InterlockedOr(&Synch, 1);
  2504. return;
  2505. }
  2506. __forceinline
  2507. VOID
  2508. WRITE_REGISTER_BUFFER_UCHAR (
  2509. PUCHAR Register,
  2510. PUCHAR Buffer,
  2511. ULONG Count
  2512. )
  2513. {
  2514. LONG Synch;
  2515. __movsb(Register, Buffer, Count);
  2516. InterlockedOr(&Synch, 1);
  2517. return;
  2518. }
  2519. __forceinline
  2520. VOID
  2521. WRITE_REGISTER_BUFFER_USHORT (
  2522. PUSHORT Register,
  2523. PUSHORT Buffer,
  2524. ULONG Count
  2525. )
  2526. {
  2527. LONG Synch;
  2528. __movsw(Register, Buffer, Count);
  2529. InterlockedOr(&Synch, 1);
  2530. return;
  2531. }
  2532. __forceinline
  2533. VOID
  2534. WRITE_REGISTER_BUFFER_ULONG (
  2535. PULONG Register,
  2536. PULONG Buffer,
  2537. ULONG Count
  2538. )
  2539. {
  2540. LONG Synch;
  2541. __movsd(Register, Buffer, Count);
  2542. InterlockedOr(&Synch, 1);
  2543. return;
  2544. }
  2545. __forceinline
  2546. UCHAR
  2547. READ_PORT_UCHAR (
  2548. PUCHAR Port
  2549. )
  2550. {
  2551. return __inbyte((USHORT)((ULONG64)Port));
  2552. }
  2553. __forceinline
  2554. USHORT
  2555. READ_PORT_USHORT (
  2556. PUSHORT Port
  2557. )
  2558. {
  2559. return __inword((USHORT)((ULONG64)Port));
  2560. }
  2561. __forceinline
  2562. ULONG
  2563. READ_PORT_ULONG (
  2564. PULONG Port
  2565. )
  2566. {
  2567. return __indword((USHORT)((ULONG64)Port));
  2568. }
  2569. __forceinline
  2570. VOID
  2571. READ_PORT_BUFFER_UCHAR (
  2572. PUCHAR Port,
  2573. PUCHAR Buffer,
  2574. ULONG Count
  2575. )
  2576. {
  2577. __inbytestring((USHORT)((ULONG64)Port), Buffer, Count);
  2578. return;
  2579. }
  2580. __forceinline
  2581. VOID
  2582. READ_PORT_BUFFER_USHORT (
  2583. PUSHORT Port,
  2584. PUSHORT Buffer,
  2585. ULONG Count
  2586. )
  2587. {
  2588. __inwordstring((USHORT)((ULONG64)Port), Buffer, Count);
  2589. return;
  2590. }
  2591. __forceinline
  2592. VOID
  2593. READ_PORT_BUFFER_ULONG (
  2594. PULONG Port,
  2595. PULONG Buffer,
  2596. ULONG Count
  2597. )
  2598. {
  2599. __indwordstring((USHORT)((ULONG64)Port), Buffer, Count);
  2600. return;
  2601. }
  2602. __forceinline
  2603. VOID
  2604. WRITE_PORT_UCHAR (
  2605. PUCHAR Port,
  2606. UCHAR Value
  2607. )
  2608. {
  2609. __outbyte((USHORT)((ULONG64)Port), Value);
  2610. return;
  2611. }
  2612. __forceinline
  2613. VOID
  2614. WRITE_PORT_USHORT (
  2615. PUSHORT Port,
  2616. USHORT Value
  2617. )
  2618. {
  2619. __outword((USHORT)((ULONG64)Port), Value);
  2620. return;
  2621. }
  2622. __forceinline
  2623. VOID
  2624. WRITE_PORT_ULONG (
  2625. PULONG Port,
  2626. ULONG Value
  2627. )
  2628. {
  2629. __outdword((USHORT)((ULONG64)Port), Value);
  2630. return;
  2631. }
  2632. __forceinline
  2633. VOID
  2634. WRITE_PORT_BUFFER_UCHAR (
  2635. PUCHAR Port,
  2636. PUCHAR Buffer,
  2637. ULONG Count
  2638. )
  2639. {
  2640. __outbytestring((USHORT)((ULONG64)Port), Buffer, Count);
  2641. return;
  2642. }
  2643. __forceinline
  2644. VOID
  2645. WRITE_PORT_BUFFER_USHORT (
  2646. PUSHORT Port,
  2647. PUSHORT Buffer,
  2648. ULONG Count
  2649. )
  2650. {
  2651. __outwordstring((USHORT)((ULONG64)Port), Buffer, Count);
  2652. return;
  2653. }
  2654. __forceinline
  2655. VOID
  2656. WRITE_PORT_BUFFER_ULONG (
  2657. PULONG Port,
  2658. PULONG Buffer,
  2659. ULONG Count
  2660. )
  2661. {
  2662. __outdwordstring((USHORT)((ULONG64)Port), Buffer, Count);
  2663. return;
  2664. }
  2665. // end_ntndis
  2666. //
  2667. // Get data cache fill size.
  2668. //
  2669. #if PRAGMA_DEPRECATED_DDK
  2670. #pragma deprecated(KeGetDcacheFillSize) // Use GetDmaAlignment
  2671. #endif
  2672. #define KeGetDcacheFillSize() 1L
  2673. #define KeFlushIoBuffers(Mdl, ReadOperation, DmaOperation)
  2674. #define ExAcquireSpinLock(Lock, OldIrql) KeAcquireSpinLock((Lock), (OldIrql))
  2675. #define ExReleaseSpinLock(Lock, OldIrql) KeReleaseSpinLock((Lock), (OldIrql))
  2676. #define ExAcquireSpinLockAtDpcLevel(Lock) KeAcquireSpinLockAtDpcLevel(Lock)
  2677. #define ExReleaseSpinLockFromDpcLevel(Lock) KeReleaseSpinLockFromDpcLevel(Lock)
  2678. #if defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_)
  2679. // begin_wdm
  2680. #define KeQueryTickCount(CurrentCount ) \
  2681. *(PULONG64)(CurrentCount) = **((volatile ULONG64 **)(&KeTickCount));
  2682. // end_wdm
  2683. #else
  2684. VOID
  2685. KeQueryTickCount (
  2686. OUT PLARGE_INTEGER CurrentCount
  2687. );
  2688. #endif // defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_)
  2689. //
  2690. // AMD64 hardware structures
  2691. //
  2692. // A Page Table Entry on an AMD64 has the following definition.
  2693. //
  2694. #define _HARDWARE_PTE_WORKING_SET_BITS 11
  2695. typedef struct _HARDWARE_PTE {
  2696. ULONG64 Valid : 1;
  2697. ULONG64 Write : 1; // UP version
  2698. ULONG64 Owner : 1;
  2699. ULONG64 WriteThrough : 1;
  2700. ULONG64 CacheDisable : 1;
  2701. ULONG64 Accessed : 1;
  2702. ULONG64 Dirty : 1;
  2703. ULONG64 LargePage : 1;
  2704. ULONG64 Global : 1;
  2705. ULONG64 CopyOnWrite : 1; // software field
  2706. ULONG64 Prototype : 1; // software field
  2707. ULONG64 reserved0 : 1; // software field
  2708. ULONG64 PageFrameNumber : 28;
  2709. ULONG64 reserved1 : 24 - (_HARDWARE_PTE_WORKING_SET_BITS+1);
  2710. ULONG64 SoftwareWsIndex : _HARDWARE_PTE_WORKING_SET_BITS;
  2711. ULONG64 NoExecute : 1;
  2712. } HARDWARE_PTE, *PHARDWARE_PTE;
  2713. //
  2714. // Define macro to initialize directory table base.
  2715. //
  2716. #define INITIALIZE_DIRECTORY_TABLE_BASE(dirbase,pfn) \
  2717. *((PULONG64)(dirbase)) = (((ULONG64)(pfn)) << PAGE_SHIFT)
  2718. //
  2719. // Define Global Descriptor Table (GDT) entry structure and constants.
  2720. //
  2721. // Define descriptor type codes.
  2722. //
  2723. #define TYPE_CODE 0x1A // 11010 = code, read only
  2724. #define TYPE_DATA 0x12 // 10010 = data, read and write
  2725. #define TYPE_TSS64 0x09 // 01001 = task state segment
  2726. //
  2727. // Define descriptor privilege levels for user and system.
  2728. //
  2729. #define DPL_USER 3
  2730. #define DPL_SYSTEM 0
  2731. //
  2732. // Define limit granularity.
  2733. //
  2734. #define GRANULARITY_BYTE 0
  2735. #define GRANULARITY_PAGE 1
  2736. #define SELECTOR_TABLE_INDEX 0x04
  2737. typedef union _KGDTENTRY64 {
  2738. struct {
  2739. USHORT LimitLow;
  2740. USHORT BaseLow;
  2741. union {
  2742. struct {
  2743. UCHAR BaseMiddle;
  2744. UCHAR Flags1;
  2745. UCHAR Flags2;
  2746. UCHAR BaseHigh;
  2747. } Bytes;
  2748. struct {
  2749. ULONG BaseMiddle : 8;
  2750. ULONG Type : 5;
  2751. ULONG Dpl : 2;
  2752. ULONG Present : 1;
  2753. ULONG LimitHigh : 4;
  2754. ULONG System : 1;
  2755. ULONG LongMode : 1;
  2756. ULONG DefaultBig : 1;
  2757. ULONG Granularity : 1;
  2758. ULONG BaseHigh : 8;
  2759. } Bits;
  2760. };
  2761. ULONG BaseUpper;
  2762. ULONG MustBeZero;
  2763. };
  2764. ULONG64 Alignment;
  2765. } KGDTENTRY64, *PKGDTENTRY64;
  2766. //
  2767. // Define Interrupt Descriptor Table (IDT) entry structure and constants.
  2768. //
  2769. typedef union _KIDTENTRY64 {
  2770. struct {
  2771. USHORT OffsetLow;
  2772. USHORT Selector;
  2773. USHORT IstIndex : 3;
  2774. USHORT Reserved0 : 5;
  2775. USHORT Type : 5;
  2776. USHORT Dpl : 2;
  2777. USHORT Present : 1;
  2778. USHORT OffsetMiddle;
  2779. ULONG OffsetHigh;
  2780. ULONG Reserved1;
  2781. };
  2782. ULONG64 Alignment;
  2783. } KIDTENTRY64, *PKIDTENTRY64;
  2784. //
  2785. // Define two union definitions used for parsing addresses into the
  2786. // component fields required by a GDT.
  2787. //
  2788. typedef union _KGDT_BASE {
  2789. struct {
  2790. USHORT BaseLow;
  2791. UCHAR BaseMiddle;
  2792. UCHAR BaseHigh;
  2793. ULONG BaseUpper;
  2794. };
  2795. ULONG64 Base;
  2796. } KGDT_BASE, *PKGDT_BASE;
  2797. C_ASSERT(sizeof(KGDT_BASE) == sizeof(ULONG64));
  2798. typedef union _KGDT_LIMIT {
  2799. struct {
  2800. USHORT LimitLow;
  2801. USHORT LimitHigh : 4;
  2802. USHORT MustBeZero : 12;
  2803. };
  2804. ULONG Limit;
  2805. } KGDT_LIMIT, *PKGDT_LIMIT;
  2806. C_ASSERT(sizeof(KGDT_LIMIT) == sizeof(ULONG));
  2807. //
  2808. // Define Task State Segment (TSS) structure and constants.
  2809. //
  2810. // Task switches are not supported by the AMD64, but a task state segment
  2811. // must be present to define the kernel stack pointer and I/O map base.
  2812. //
  2813. // N.B. This structure is misaligned as per the AMD64 specification.
  2814. //
  2815. // N.B. The size of TSS must be <= 0xDFFF.
  2816. //
  2817. #define IOPM_SIZE 8192
  2818. typedef UCHAR KIO_ACCESS_MAP[IOPM_SIZE];
  2819. typedef KIO_ACCESS_MAP *PKIO_ACCESS_MAP;
  2820. #pragma pack(push, 4)
  2821. typedef struct _KTSS64 {
  2822. ULONG Reserved0;
  2823. ULONG64 Rsp0;
  2824. ULONG64 Rsp1;
  2825. ULONG64 Rsp2;
  2826. //
  2827. // Element 0 of the Ist is reserved
  2828. //
  2829. ULONG64 Ist[8];
  2830. ULONG64 Reserved1;
  2831. USHORT IoMapBase;
  2832. KIO_ACCESS_MAP IoMap;
  2833. ULONG IoMapEnd;
  2834. ULONG Reserved2;
  2835. } KTSS64, *PKTSS64;
  2836. #pragma pack(pop)
  2837. C_ASSERT((sizeof(KTSS64) % sizeof(PVOID)) == 0);
  2838. #define TSS_IST_RESERVED 0
  2839. #define TSS_IST_PANIC 1
  2840. #define TSS_IST_MCA 2
  2841. #define IO_ACCESS_MAP_NONE FALSE
  2842. #define KiComputeIopmOffset(Enable) \
  2843. ((Enable == FALSE) ? \
  2844. (USHORT)(sizeof(KTSS64)) : (USHORT)(FIELD_OFFSET(KTSS64, IoMap[0])))
  2845. // begin_windbgkd
  2846. #if defined(_AMD64_)
  2847. //
  2848. // Define pseudo descriptor structures for both 64- and 32-bit mode.
  2849. //
  2850. typedef struct _KDESCRIPTOR {
  2851. USHORT Pad[3];
  2852. USHORT Limit;
  2853. PVOID Base;
  2854. } KDESCRIPTOR, *PKDESCRIPTOR;
  2855. typedef struct _KDESCRIPTOR32 {
  2856. USHORT Pad[3];
  2857. USHORT Limit;
  2858. ULONG Base;
  2859. } KDESCRIPTOR32, *PKDESCRIPTOR32;
  2860. //
  2861. // Define special kernel registers and the initial MXCSR value.
  2862. //
  2863. typedef struct _KSPECIAL_REGISTERS {
  2864. ULONG64 Cr0;
  2865. ULONG64 Cr2;
  2866. ULONG64 Cr3;
  2867. ULONG64 Cr4;
  2868. ULONG64 KernelDr0;
  2869. ULONG64 KernelDr1;
  2870. ULONG64 KernelDr2;
  2871. ULONG64 KernelDr3;
  2872. ULONG64 KernelDr6;
  2873. ULONG64 KernelDr7;
  2874. KDESCRIPTOR Gdtr;
  2875. KDESCRIPTOR Idtr;
  2876. USHORT Tr;
  2877. USHORT Ldtr;
  2878. ULONG MxCsr;
  2879. } KSPECIAL_REGISTERS, *PKSPECIAL_REGISTERS;
  2880. //
  2881. // Define processor state structure.
  2882. //
  2883. typedef struct _KPROCESSOR_STATE {
  2884. KSPECIAL_REGISTERS SpecialRegisters;
  2885. CONTEXT ContextFrame;
  2886. } KPROCESSOR_STATE, *PKPROCESSOR_STATE;
  2887. #endif // _AMD64_
  2888. // end_windbgkd
  2889. //
  2890. // Processor Control Block (PRCB)
  2891. //
  2892. #define PRCB_MAJOR_VERSION 1
  2893. #define PRCB_MINOR_VERSION 1
  2894. #define PRCB_BUILD_DEBUG 0x1
  2895. #define PRCB_BUILD_UNIPROCESSOR 0x2
  2896. typedef struct _KPRCB {
  2897. //
  2898. // Start of the architecturally defined section of the PRCB. This section
  2899. // may be directly addressed by vendor/platform specific HAL code and will
  2900. // not change from version to version of NT.
  2901. //
  2902. USHORT MinorVersion;
  2903. USHORT MajorVersion;
  2904. CCHAR Number;
  2905. CCHAR Reserved;
  2906. USHORT BuildType;
  2907. struct _KTHREAD *CurrentThread;
  2908. struct _KTHREAD *NextThread;
  2909. struct _KTHREAD *IdleThread;
  2910. KAFFINITY SetMember;
  2911. KAFFINITY NotSetMember;
  2912. KPROCESSOR_STATE ProcessorState;
  2913. CCHAR CpuType;
  2914. CCHAR CpuID;
  2915. USHORT CpuStep;
  2916. ULONG KernelReserved[16];
  2917. ULONG HalReserved[16];
  2918. UCHAR PrcbPad0[88 + 112];
  2919. //
  2920. // End of the architecturally defined section of the PRCB.
  2921. //
  2922. } KPRCB, *PKPRCB, *RESTRICTED_POINTER PRKPRCB;
  2923. //
  2924. // Processor Control Region Structure Definition
  2925. //
  2926. #define PCR_MINOR_VERSION 1
  2927. #define PCR_MAJOR_VERSION 1
  2928. typedef struct _KPCR {
  2929. //
  2930. // Start of the architecturally defined section of the PCR. This section
  2931. // may be directly addressed by vendor/platform specific HAL code and will
  2932. // not change from version to version of NT.
  2933. //
  2934. NT_TIB NtTib;
  2935. struct _KPRCB *CurrentPrcb;
  2936. ULONG64 SavedRcx;
  2937. ULONG64 SavedR11;
  2938. KIRQL Irql;
  2939. UCHAR SecondLevelCacheAssociativity;
  2940. UCHAR Number;
  2941. UCHAR Fill0;
  2942. ULONG Irr;
  2943. ULONG IrrActive;
  2944. ULONG Idr;
  2945. USHORT MajorVersion;
  2946. USHORT MinorVersion;
  2947. ULONG StallScaleFactor;
  2948. union _KIDTENTRY64 *IdtBase;
  2949. union _KGDTENTRY64 *GdtBase;
  2950. struct _KTSS64 *TssBase;
  2951. } KPCR, *PKPCR;
  2952. //
  2953. // Define legacy floating status word bit masks.
  2954. //
  2955. #define FSW_INVALID_OPERATION 0x1
  2956. #define FSW_DENORMAL 0x2
  2957. #define FSW_ZERO_DIVIDE 0x4
  2958. #define FSW_OVERFLOW 0x8
  2959. #define FSW_UNDERFLOW 0x10
  2960. #define FSW_PRECISION 0x20
  2961. #define FSW_STACK_FAULT 0x40
  2962. #define FSW_CONDITION_CODE_0 0x100
  2963. #define FSW_CONDITION_CODE_1 0x200
  2964. #define FSW_CONDITION_CODE_2 0x400
  2965. #define FSW_CONDITION_CODE_3 0x4000
  2966. #define FSW_ERROR_MASK (FSW_INVALID_OPERATION | FSW_DENORMAL | \
  2967. FSW_ZERO_DIVIDE | FSW_OVERFLOW | FSW_UNDERFLOW | \
  2968. FSW_PRECISION | FSW_STACK_FAULT)
  2969. //
  2970. // Define MxCsr floating control/status word bit masks.
  2971. //
  2972. // No flush to zero, round to nearest, and all exception masked.
  2973. //
  2974. #define INITIAL_MXCSR 0x1f80 // initial MXCSR vlaue
  2975. #define XSW_INVALID_OPERATION 0x1
  2976. #define XSW_DENORMAL 0x2
  2977. #define XSW_ZERO_DIVIDE 0x4
  2978. #define XSW_OVERFLOW 0x8
  2979. #define XSW_UNDERFLOW 0x10
  2980. #define XSW_PRECISION 0x20
  2981. #define XSW_ERROR_MASK (XSW_INVALID_OPERATION | XSW_DENORMAL | \
  2982. XSW_ZERO_DIVIDE | XSW_OVERFLOW | XSW_UNDERFLOW | \
  2983. XSW_PRECISION)
  2984. #define XSW_ERROR_SHIFT 7
  2985. #define XCW_INVALID_OPERATION 0x80
  2986. #define XCW_DENORMAL 0x100
  2987. #define XCW_ZERO_DIVIDE 0x200
  2988. #define XCW_OVERFLOW 0x400
  2989. #define XCW_UNDERFLOW 0x800
  2990. #define XCW_PRECISION 0x1000
  2991. #define XCW_ROUND_CONTROL 0x6000
  2992. #define XCW_FLUSH_ZERO 0x8000
  2993. //
  2994. // Define EFLAG bit masks and shift offsets.
  2995. //
  2996. #define EFLAGS_CF_MASK 0x00000001 // carry flag
  2997. #define EFLAGS_PF_MASK 0x00000004 // parity flag
  2998. #define EFALGS_AF_MASK 0x00000010 // auxiliary carry flag
  2999. #define EFLAGS_ZF_MASK 0x00000040 // zero flag
  3000. #define EFLAGS_SF_MASK 0x00000080 // sign flag
  3001. #define EFLAGS_TF_MASK 0x00000100 // trap flag
  3002. #define EFLAGS_IF_MASK 0x00000200 // interrupt flag
  3003. #define EFLAGS_DF_MASK 0x00000400 // direction flag
  3004. #define EFLAGS_OF_MASK 0x00000800 // overflow flag
  3005. #define EFLAGS_IOPL_MASK 0x00003000 // I/O privilege level
  3006. #define EFLAGS_NT_MASK 0x00004000 // nested task
  3007. #define EFLAGS_RF_MASK 0x00010000 // resume flag
  3008. #define EFLAGS_VM_MASK 0x00020000 // virtual 8086 mode
  3009. #define EFLAGS_AC_MASK 0x00040000 // alignment check
  3010. #define EFLAGS_VIF_MASK 0x00080000 // virtual interrupt flag
  3011. #define EFLAGS_VIP_MASK 0x00100000 // virtual interrupt pending
  3012. #define EFLAGS_ID_MASK 0x00200000 // identification flag
  3013. #define EFLAGS_TF_SHIFT 8 // trap
  3014. #define EFLAGS_IF_SHIFT 9 // interrupt enable
  3015. // end_nthal
  3016. //
  3017. // Define sanitize EFLAGS macro.
  3018. //
  3019. // If kernel mode, then
  3020. // caller can specify Carry, Parity, AuxCarry, Zero, Sign, Trap,
  3021. // Interrupt, Direction, Overflow, Align Check, identification.
  3022. //
  3023. // If user mode, then
  3024. // caller can specify Carry, Parity, AuxCarry, Zero, Sign, Trap,
  3025. // Direction, Overflow, Align Check, and force Interrupt on.
  3026. //
  3027. #define EFLAGS_KERNEL_SANITIZE 0x00240fd5L
  3028. #define EFLAGS_USER_SANITIZE 0x00040dd5L
  3029. #define SANITIZE_EFLAGS(eFlags, mode) ( \
  3030. ((mode) == KernelMode ? \
  3031. ((eFlags) & EFLAGS_KERNEL_SANITIZE) : \
  3032. (((eFlags) & EFLAGS_USER_SANITIZE) | EFLAGS_IF_MASK)))
  3033. //
  3034. // Define sanitize debug register macros.
  3035. //
  3036. // Define control register settable bits and active mask.
  3037. //
  3038. #define DR7_LEGAL 0xffff0155
  3039. #define DR7_ACTIVE 0x00000055
  3040. //
  3041. // Define macro to sanitize the debug control register.
  3042. //
  3043. #define SANITIZE_DR7(Dr7, mode) ((Dr7 & DR7_LEGAL));
  3044. //
  3045. // Define macro to santitize debug address registers.
  3046. //
  3047. #define SANITIZE_DRADDR(DrReg, mode) \
  3048. ((mode) == KernelMode ? \
  3049. (DrReg) : \
  3050. (((PVOID)(DrReg) <= MM_HIGHEST_USER_ADDRESS) ? (DrReg) : 0)) \
  3051. //
  3052. // Define macro to clear reserved bits from MXCSR.
  3053. //
  3054. #define SANITIZE_MXCSR(_mxcsr_) ((_mxcsr_) & 0xffbf)
  3055. //
  3056. // Define macro to clear reserved bits for legacy FP control word.
  3057. //
  3058. #define SANITIZE_FCW(_fcw_) ((_fcw_) & 0x1f37)
  3059. // begin_nthal
  3060. //
  3061. // Exception frame
  3062. //
  3063. // This frame is established when handling an exception. It provides a place
  3064. // to save all nonvolatile registers. The volatile registers will already
  3065. // have been saved in a trap frame.
  3066. //
  3067. typedef struct _KEXCEPTION_FRAME {
  3068. //
  3069. // Home address for the parameter registers.
  3070. //
  3071. ULONG64 P1Home;
  3072. ULONG64 P2Home;
  3073. ULONG64 P3Home;
  3074. ULONG64 P4Home;
  3075. ULONG64 P5;
  3076. //
  3077. // Kernel callout initial stack value.
  3078. //
  3079. ULONG64 InitialStack;
  3080. //
  3081. // Saved nonvolatile floating registers.
  3082. //
  3083. M128 Xmm6;
  3084. M128 Xmm7;
  3085. M128 Xmm8;
  3086. M128 Xmm9;
  3087. M128 Xmm10;
  3088. M128 Xmm11;
  3089. M128 Xmm12;
  3090. M128 Xmm13;
  3091. M128 Xmm14;
  3092. M128 Xmm15;
  3093. //
  3094. // Kernel callout frame variables.
  3095. //
  3096. ULONG64 TrapFrame;
  3097. ULONG64 CallbackStack;
  3098. ULONG64 OutputBuffer;
  3099. ULONG64 OutputLength;
  3100. //
  3101. // Saved nonvolatile register - not always saved.
  3102. //
  3103. ULONG64 Fill1;
  3104. ULONG64 Rbp;
  3105. //
  3106. // Saved nonvolatile registers.
  3107. //
  3108. ULONG64 Rbx;
  3109. ULONG64 Rdi;
  3110. ULONG64 Rsi;
  3111. ULONG64 R12;
  3112. ULONG64 R13;
  3113. ULONG64 R14;
  3114. ULONG64 R15;
  3115. //
  3116. // EFLAGS and return address.
  3117. //
  3118. ULONG64 Return;
  3119. } KEXCEPTION_FRAME, *PKEXCEPTION_FRAME;
  3120. #define KEXCEPTION_FRAME_LENGTH sizeof(KEXCEPTION_FRAME)
  3121. C_ASSERT((sizeof(KEXCEPTION_FRAME) & STACK_ROUND) == 0);
  3122. #define EXCEPTION_RECORD_LENGTH \
  3123. ((sizeof(EXCEPTION_RECORD) + STACK_ROUND) & ~STACK_ROUND)
  3124. //
  3125. // Machine Frame
  3126. //
  3127. // This frame is established by code that trampolines to user mode (e.g. user
  3128. // APC, user callback, dispatch user exception, etc.). The purpose of this
  3129. // frame is to allow unwinding through these callbacks if an exception occurs.
  3130. //
  3131. // N.B. This frame is identical to the frame that is pushed for a trap without
  3132. // an error code and is identical to the hardware part of a trap frame.
  3133. //
  3134. typedef struct _MACHINE_FRAME {
  3135. ULONG64 Rip;
  3136. USHORT SegCs;
  3137. USHORT Fill1[3];
  3138. ULONG EFlags;
  3139. ULONG Fill2;
  3140. ULONG64 Rsp;
  3141. USHORT SegSs;
  3142. USHORT Fill3[3];
  3143. } MACHINE_FRAME, *PMACHINE_FRAME;
  3144. #define MACHINE_FRAME_LENGTH sizeof(MACHINE_FRAME)
  3145. C_ASSERT((sizeof(MACHINE_FRAME) & STACK_ROUND) == 8);
  3146. //
  3147. // Switch Frame
  3148. //
  3149. // This frame is established by the code that switches context from one
  3150. // thread to the next and is used by the thread initialization code to
  3151. // construct a stack that will start the execution of a thread in the
  3152. // thread start up code.
  3153. //
  3154. typedef struct _KSWITCH_FRAME {
  3155. ULONG64 Fill0;
  3156. ULONG MxCsr;
  3157. KIRQL ApcBypass;
  3158. BOOLEAN NpxSave;
  3159. UCHAR Fill1[2];
  3160. ULONG64 Rbp;
  3161. ULONG64 Return;
  3162. } KSWITCH_FRAME, *PKSWITCH_FRAME;
  3163. #define KSWITCH_FRAME_LENGTH sizeof(KSWITCH_FRAME)
  3164. C_ASSERT((sizeof(KSWITCH_FRAME) & STACK_ROUND) == 0);
  3165. //
  3166. // Trap frame
  3167. //
  3168. // This frame is established when handling a trap. It provides a place to
  3169. // save all volatile registers. The nonvolatile registers are saved in an
  3170. // exception frame or through the normal C calling conventions for saved
  3171. // registers.
  3172. //
  3173. typedef struct _KTRAP_FRAME {
  3174. //
  3175. // Home address for the parameter registers.
  3176. //
  3177. ULONG64 P1Home;
  3178. ULONG64 P2Home;
  3179. ULONG64 P3Home;
  3180. ULONG64 P4Home;
  3181. ULONG64 P5;
  3182. //
  3183. // Previous processor mode (system services only) and previous IRQL
  3184. // (interrupts only).
  3185. //
  3186. KPROCESSOR_MODE PreviousMode;
  3187. KIRQL PreviousIrql;
  3188. UCHAR Fill0[2];
  3189. //
  3190. // Floating point state.
  3191. //
  3192. ULONG MxCsr;
  3193. //
  3194. // Volatile registers.
  3195. //
  3196. // N.B. These registers are only saved on exceptions and interrupts. They
  3197. // are not saved for system calls.
  3198. //
  3199. ULONG64 Rax;
  3200. ULONG64 Rcx;
  3201. ULONG64 Rdx;
  3202. ULONG64 R8;
  3203. ULONG64 R9;
  3204. ULONG64 R10;
  3205. ULONG64 R11;
  3206. ULONG64 Spare0;
  3207. //
  3208. // Volatile floating registers.
  3209. //
  3210. // N.B. These registers are only saved on exceptions and interrupts. They
  3211. // are not saved for system calls.
  3212. //
  3213. M128 Xmm0;
  3214. M128 Xmm1;
  3215. M128 Xmm2;
  3216. M128 Xmm3;
  3217. M128 Xmm4;
  3218. M128 Xmm5;
  3219. //
  3220. // Debug registers.
  3221. //
  3222. ULONG64 Dr0;
  3223. ULONG64 Dr1;
  3224. ULONG64 Dr2;
  3225. ULONG64 Dr3;
  3226. ULONG64 Dr6;
  3227. ULONG64 Dr7;
  3228. //
  3229. // Segment registers
  3230. //
  3231. USHORT SegDs;
  3232. USHORT SegEs;
  3233. USHORT SegFs;
  3234. USHORT SegGs;
  3235. //
  3236. // Previous trap frame address.
  3237. //
  3238. ULONG64 TrapFrame;
  3239. //
  3240. // Exception record for exceptions.
  3241. //
  3242. UCHAR ExceptionRecord[(sizeof(EXCEPTION_RECORD) + 15) & (~15)];
  3243. //
  3244. // Saved nonvolatile registers RBX, RDI and RSI. These registers are only
  3245. // saved in system service trap frames.
  3246. //
  3247. ULONG64 Rbx;
  3248. ULONG64 Rdi;
  3249. ULONG64 Rsi;
  3250. //
  3251. // Saved nonvolatile register RBP. This register is used as a frame
  3252. // pointer during trap processing and is saved in all trap frames.
  3253. //
  3254. ULONG64 Rbp;
  3255. //
  3256. // Information pushed by hardware.
  3257. //
  3258. // N.B. The error code is not always pushed by hardware. For those cases
  3259. // where it is not pushed by hardware a dummy error code is allocated
  3260. // on the stack.
  3261. //
  3262. ULONG64 ErrorCode;
  3263. ULONG64 Rip;
  3264. USHORT SegCs;
  3265. USHORT Fill1[3];
  3266. ULONG EFlags;
  3267. ULONG Fill2;
  3268. ULONG64 Rsp;
  3269. USHORT SegSs;
  3270. USHORT Fill3[3];
  3271. } KTRAP_FRAME, *PKTRAP_FRAME;
  3272. #define KTRAP_FRAME_LENGTH sizeof(KTRAP_FRAME)
  3273. C_ASSERT((sizeof(KTRAP_FRAME) & STACK_ROUND) == 0);
  3274. //
  3275. // IPI, profile, update run time, and update system time interrupt routines.
  3276. //
  3277. NTKERNELAPI
  3278. VOID
  3279. KeIpiInterrupt (
  3280. IN PKTRAP_FRAME TrapFrame
  3281. );
  3282. NTKERNELAPI
  3283. VOID
  3284. KeProfileInterruptWithSource (
  3285. IN PKTRAP_FRAME TrapFrame,
  3286. IN KPROFILE_SOURCE ProfileSource
  3287. );
  3288. NTKERNELAPI
  3289. VOID
  3290. KeUpdateRunTime (
  3291. IN PKTRAP_FRAME TrapFrame
  3292. );
  3293. NTKERNELAPI
  3294. VOID
  3295. KeUpdateSystemTime (
  3296. IN PKTRAP_FRAME TrapFrame,
  3297. IN ULONG64 Increment
  3298. );
  3299. // end_nthal
  3300. //
  3301. // The frame saved by the call out to user mode code is defined here to allow
  3302. // the kernel debugger to trace the entire kernel stack when user mode callouts
  3303. // are active.
  3304. //
  3305. // N.B. The kernel callout frame is the same as an exception frame.
  3306. //
  3307. typedef KEXCEPTION_FRAME KCALLOUT_FRAME;
  3308. typedef PKEXCEPTION_FRAME PKCALLOUT_FRAME;
  3309. typedef struct _UCALLOUT_FRAME {
  3310. ULONG64 P1Home;
  3311. ULONG64 P2Home;
  3312. ULONG64 P3Home;
  3313. ULONG64 P4Home;
  3314. PVOID Buffer;
  3315. ULONG Length;
  3316. ULONG ApiNumber;
  3317. MACHINE_FRAME MachineFrame;
  3318. } UCALLOUT_FRAME, *PUCALLOUT_FRAME;
  3319. #define UCALLOUT_FRAME_LENGTH sizeof(UCALLOUT_FRAME)
  3320. C_ASSERT((sizeof(UCALLOUT_FRAME) & STACK_ROUND) == 8);
  3321. // begin_ntddk begin_wdm
  3322. //
  3323. // The nonvolatile floating state
  3324. //
  3325. typedef struct _KFLOATING_SAVE {
  3326. ULONG MxCsr;
  3327. } KFLOATING_SAVE, *PKFLOATING_SAVE;
  3328. //
  3329. // AMD64 Specific portions of mm component.
  3330. //
  3331. // Define the page size for the AMD64 as 4096 (0x1000).
  3332. //
  3333. #define PAGE_SIZE 0x1000
  3334. //
  3335. // Define the number of trailing zeroes in a page aligned virtual address.
  3336. // This is used as the shift count when shifting virtual addresses to
  3337. // virtual page numbers.
  3338. //
  3339. #define PAGE_SHIFT 12L
  3340. // end_ntndis end_wdm
  3341. #define PXE_BASE 0xFFFFF6FB7DBED000UI64
  3342. #define PXE_SELFMAP 0xFFFFF6FB7DBEDF68UI64
  3343. #define PPE_BASE 0xFFFFF6FB7DA00000UI64
  3344. #define PDE_BASE 0xFFFFF6FB40000000UI64
  3345. #define PTE_BASE 0xFFFFF68000000000UI64
  3346. #define PXE_TOP 0xFFFFF6FB7DBEDFFFUI64
  3347. #define PPE_TOP 0xFFFFF6FB7DBFFFFFUI64
  3348. #define PDE_TOP 0xFFFFF6FB7FFFFFFFUI64
  3349. #define PTE_TOP 0xFFFFF6FFFFFFFFFFUI64
  3350. #define PDE_KTBASE_AMD64 PPE_BASE
  3351. #define PTI_SHIFT 12
  3352. #define PDI_SHIFT 21
  3353. #define PPI_SHIFT 30
  3354. #define PXI_SHIFT 39
  3355. #define PTE_PER_PAGE 512
  3356. #define PDE_PER_PAGE 512
  3357. #define PPE_PER_PAGE 512
  3358. #define PXE_PER_PAGE 512
  3359. #define PTI_MASK_AMD64 (PTE_PER_PAGE - 1)
  3360. #define PDI_MASK_AMD64 (PDE_PER_PAGE - 1)
  3361. #define PPI_MASK (PPE_PER_PAGE - 1)
  3362. #define PXI_MASK (PXE_PER_PAGE - 1)
  3363. //
  3364. // Define the highest user address and user probe address.
  3365. //
  3366. extern PVOID *MmHighestUserAddress;
  3367. extern PVOID *MmSystemRangeStart;
  3368. extern ULONG64 *MmUserProbeAddress;
  3369. #define MM_HIGHEST_USER_ADDRESS *MmHighestUserAddress
  3370. #define MM_SYSTEM_RANGE_START *MmSystemRangeStart
  3371. #define MM_USER_PROBE_ADDRESS *MmUserProbeAddress
  3372. //
  3373. // The lowest user address reserves the low 64k.
  3374. //
  3375. #define MM_LOWEST_USER_ADDRESS (PVOID)0x10000
  3376. //
  3377. // The lowest address for system space.
  3378. //
  3379. #define MM_LOWEST_SYSTEM_ADDRESS (PVOID)0xFFFF080000000000
  3380. // begin_wdm
  3381. #define MmGetProcedureAddress(Address) (Address)
  3382. #define MmLockPagableCodeSection(Address) MmLockPagableDataSection(Address)
  3383. #define KI_USER_SHARED_DATA 0xFFFFF78000000000UI64
  3384. #define SharedUserData ((KUSER_SHARED_DATA * const) KI_USER_SHARED_DATA)
  3385. //
  3386. // Intrinsic functions
  3387. //
  3388. // begin_wdm
  3389. #if defined(_M_AMD64) && !defined(RC_INVOKED) && !defined(MIDL_PASS)
  3390. // end_wdm
  3391. //
  3392. // The following routines are provided for backward compatibility with old
  3393. // code. They are no longer the preferred way to accomplish these functions.
  3394. //
  3395. #if PRAGMA_DEPRECATED_DDK
  3396. #pragma deprecated(ExInterlockedIncrementLong) // Use InterlockedIncrement
  3397. #pragma deprecated(ExInterlockedDecrementLong) // Use InterlockedDecrement
  3398. #pragma deprecated(ExInterlockedExchangeUlong) // Use InterlockedExchange
  3399. #endif
  3400. #define RESULT_ZERO 0
  3401. #define RESULT_NEGATIVE 1
  3402. #define RESULT_POSITIVE 2
  3403. typedef enum _INTERLOCKED_RESULT {
  3404. ResultNegative = RESULT_NEGATIVE,
  3405. ResultZero = RESULT_ZERO,
  3406. ResultPositive = RESULT_POSITIVE
  3407. } INTERLOCKED_RESULT;
  3408. #define ExInterlockedDecrementLong(Addend, Lock) \
  3409. _ExInterlockedDecrementLong(Addend)
  3410. __forceinline
  3411. LONG
  3412. _ExInterlockedDecrementLong (
  3413. IN OUT PLONG Addend
  3414. )
  3415. {
  3416. LONG Result;
  3417. Result = InterlockedDecrement(Addend);
  3418. if (Result < 0) {
  3419. return ResultNegative;
  3420. } else if (Result > 0) {
  3421. return ResultPositive;
  3422. } else {
  3423. return ResultZero;
  3424. }
  3425. }
  3426. #define ExInterlockedIncrementLong(Addend, Lock) \
  3427. _ExInterlockedIncrementLong(Addend)
  3428. __forceinline
  3429. LONG
  3430. _ExInterlockedIncrementLong (
  3431. IN OUT PLONG Addend
  3432. )
  3433. {
  3434. LONG Result;
  3435. Result = InterlockedIncrement(Addend);
  3436. if (Result < 0) {
  3437. return ResultNegative;
  3438. } else if (Result > 0) {
  3439. return ResultPositive;
  3440. } else {
  3441. return ResultZero;
  3442. }
  3443. }
  3444. #define ExInterlockedExchangeUlong(Target, Value, Lock) \
  3445. _ExInterlockedExchangeUlong(Target, Value)
  3446. __forceinline
  3447. _ExInterlockedExchangeUlong (
  3448. IN OUT PULONG Target,
  3449. IN ULONG Value
  3450. )
  3451. {
  3452. return (ULONG)InterlockedExchange((PLONG)Target, (LONG)Value);
  3453. }
  3454. // begin_wdm
  3455. #endif // defined(_M_AMD64) && !defined(RC_INVOKED) && !defined(MIDL_PASS)
  3456. #if !defined(MIDL_PASS) && defined(_M_AMD64)
  3457. //
  3458. // AMD646 function prototype definitions
  3459. //
  3460. // end_wdm
  3461. //
  3462. // Get address of current processor block.
  3463. //
  3464. __forceinline
  3465. PKPRCB
  3466. KeGetCurrentPrcb (
  3467. VOID
  3468. )
  3469. {
  3470. return (PKPRCB)__readgsqword(FIELD_OFFSET(KPCR, CurrentPrcb));
  3471. }
  3472. // begin_ntddk
  3473. //
  3474. // Get the current processor number
  3475. //
  3476. __forceinline
  3477. ULONG
  3478. KeGetCurrentProcessorNumber (
  3479. VOID
  3480. )
  3481. {
  3482. return (ULONG)__readgsbyte(FIELD_OFFSET(KPCR, Number));
  3483. }
  3484. // begin_wdm
  3485. #endif // !defined(MIDL_PASS) && defined(_M_AMD64)
  3486. NTKERNELAPI
  3487. NTSTATUS
  3488. KeSaveFloatingPointState (
  3489. OUT PKFLOATING_SAVE SaveArea
  3490. );
  3491. NTKERNELAPI
  3492. NTSTATUS
  3493. KeRestoreFloatingPointState (
  3494. IN PKFLOATING_SAVE SaveArea
  3495. );
  3496. #endif // defined(_AMD64_)
  3497. #ifdef _AMD64_
  3498. VOID
  3499. KeSetIoAccessMap (
  3500. PKIO_ACCESS_MAP IoAccessMap
  3501. );
  3502. VOID
  3503. KeQueryIoAccessMap (
  3504. PKIO_ACCESS_MAP IoAccessMap
  3505. );
  3506. VOID
  3507. KeSetIoAccessProcess (
  3508. struct _KPROCESS *Process,
  3509. BOOLEAN Enable
  3510. );
  3511. VOID
  3512. KiEditIopmDpc (
  3513. IN struct _KDPC *Dpc,
  3514. IN PVOID DeferredContext,
  3515. IN PVOID SystemArgument1,
  3516. IN PVOID SystemArgument2
  3517. );
  3518. #endif //_AMD64_
  3519. //
  3520. // Platform specific kernel fucntions to raise and lower IRQL.
  3521. //
  3522. // These functions are imported for ntddk, ntifs, and wdm. They are
  3523. // inlined for nthal, ntosp, and the system.
  3524. //
  3525. #if defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_) || defined(_WDMDDK_)
  3526. // begin_ntddk begin_wdm
  3527. #if defined(_AMD64_)
  3528. NTKERNELAPI
  3529. KIRQL
  3530. KeGetCurrentIrql (
  3531. VOID
  3532. );
  3533. NTKERNELAPI
  3534. VOID
  3535. KeLowerIrql (
  3536. IN KIRQL NewIrql
  3537. );
  3538. #define KeRaiseIrql(a,b) *(b) = KfRaiseIrql(a)
  3539. NTKERNELAPI
  3540. KIRQL
  3541. KfRaiseIrql (
  3542. IN KIRQL NewIrql
  3543. );
  3544. // end_wdm
  3545. NTKERNELAPI
  3546. KIRQL
  3547. KeRaiseIrqlToDpcLevel (
  3548. VOID
  3549. );
  3550. NTKERNELAPI
  3551. KIRQL
  3552. KeRaiseIrqlToSynchLevel (
  3553. VOID
  3554. );
  3555. // begin_wdm
  3556. #endif // defined(_AMD64_)
  3557. // end_ntddk end_wdm
  3558. #else
  3559. // begin_nthal
  3560. #if defined(_AMD64_) && !defined(MIDL_PASS)
  3561. __forceinline
  3562. KIRQL
  3563. KeGetCurrentIrql (
  3564. VOID
  3565. )
  3566. /*++
  3567. Routine Description:
  3568. This function return the current IRQL.
  3569. Arguments:
  3570. None.
  3571. Return Value:
  3572. The current IRQL is returned as the function value.
  3573. --*/
  3574. {
  3575. return (KIRQL)ReadCR8();
  3576. }
  3577. __forceinline
  3578. VOID
  3579. KeLowerIrql (
  3580. IN KIRQL NewIrql
  3581. )
  3582. /*++
  3583. Routine Description:
  3584. This function lowers the IRQL to the specified value.
  3585. Arguments:
  3586. NewIrql - Supplies the new IRQL value.
  3587. Return Value:
  3588. None.
  3589. --*/
  3590. {
  3591. ASSERT(KeGetCurrentIrql() >= NewIrql);
  3592. WriteCR8(NewIrql);
  3593. return;
  3594. }
  3595. #define KeRaiseIrql(a,b) *(b) = KfRaiseIrql(a)
  3596. __forceinline
  3597. KIRQL
  3598. KfRaiseIrql (
  3599. IN KIRQL NewIrql
  3600. )
  3601. /*++
  3602. Routine Description:
  3603. This function raises the current IRQL to the specified value and returns
  3604. the previous IRQL.
  3605. Arguments:
  3606. NewIrql (cl) - Supplies the new IRQL value.
  3607. Return Value:
  3608. The previous IRQL is retured as the function value.
  3609. --*/
  3610. {
  3611. KIRQL OldIrql;
  3612. OldIrql = KeGetCurrentIrql();
  3613. ASSERT(OldIrql <= NewIrql);
  3614. WriteCR8(NewIrql);
  3615. return OldIrql;
  3616. }
  3617. __forceinline
  3618. KIRQL
  3619. KeRaiseIrqlToDpcLevel (
  3620. VOID
  3621. )
  3622. /*++
  3623. Routine Description:
  3624. This function raises the current IRQL to DPC_LEVEL and returns the
  3625. previous IRQL.
  3626. Arguments:
  3627. None.
  3628. Return Value:
  3629. The previous IRQL is retured as the function value.
  3630. --*/
  3631. {
  3632. KIRQL OldIrql;
  3633. OldIrql = KeGetCurrentIrql();
  3634. ASSERT(OldIrql <= DISPATCH_LEVEL);
  3635. WriteCR8(DISPATCH_LEVEL);
  3636. return OldIrql;
  3637. }
  3638. __forceinline
  3639. KIRQL
  3640. KeRaiseIrqlToSynchLevel (
  3641. VOID
  3642. )
  3643. /*++
  3644. Routine Description:
  3645. This function raises the current IRQL to SYNCH_LEVEL and returns the
  3646. previous IRQL.
  3647. Arguments:
  3648. Return Value:
  3649. The previous IRQL is retured as the function value.
  3650. --*/
  3651. {
  3652. KIRQL OldIrql;
  3653. OldIrql = KeGetCurrentIrql();
  3654. ASSERT(OldIrql <= SYNCH_LEVEL);
  3655. WriteCR8(SYNCH_LEVEL);
  3656. return OldIrql;
  3657. }
  3658. #endif // defined(_AMD64_) && !defined(MIDL_PASS)
  3659. // end_nthal
  3660. #endif // defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_) || defined(_WDMDDK_)
  3661. #if defined(_IA64_)
  3662. //
  3663. // Types to use to contain PFNs and their counts.
  3664. //
  3665. typedef ULONG PFN_COUNT;
  3666. typedef LONG_PTR SPFN_NUMBER, *PSPFN_NUMBER;
  3667. typedef ULONG_PTR PFN_NUMBER, *PPFN_NUMBER;
  3668. //
  3669. // Define maximum size of flush multiple TB request.
  3670. //
  3671. #define FLUSH_MULTIPLE_MAXIMUM 100
  3672. //
  3673. // Indicate that the IA64 compiler supports the pragma textout construct.
  3674. //
  3675. #define ALLOC_PRAGMA 1
  3676. //
  3677. // Define intrinsic calls and their prototypes
  3678. //
  3679. #include "ia64reg.h"
  3680. #ifdef __cplusplus
  3681. extern "C" {
  3682. #endif
  3683. unsigned __int64 __getReg (int);
  3684. void __setReg (int, unsigned __int64);
  3685. void __isrlz (void);
  3686. void __dsrlz (void);
  3687. void __fwb (void);
  3688. void __mf (void);
  3689. void __mfa (void);
  3690. void __synci (void);
  3691. __int64 __thash (__int64);
  3692. __int64 __ttag (__int64);
  3693. void __ptcl (__int64, __int64);
  3694. void __ptcg (__int64, __int64);
  3695. void __ptcga (__int64, __int64);
  3696. void __ptri (__int64, __int64);
  3697. void __ptrd (__int64, __int64);
  3698. void __invalat (void);
  3699. void __break (int);
  3700. void __fc (__int64);
  3701. void __sum (int);
  3702. void __rsm (int);
  3703. void _ReleaseSpinLock( unsigned __int64 *);
  3704. #ifdef _M_IA64
  3705. #pragma intrinsic (__getReg)
  3706. #pragma intrinsic (__setReg)
  3707. #pragma intrinsic (__isrlz)
  3708. #pragma intrinsic (__dsrlz)
  3709. #pragma intrinsic (__fwb)
  3710. #pragma intrinsic (__mf)
  3711. #pragma intrinsic (__mfa)
  3712. #pragma intrinsic (__synci)
  3713. #pragma intrinsic (__thash)
  3714. #pragma intrinsic (__ttag)
  3715. #pragma intrinsic (__ptcl)
  3716. #pragma intrinsic (__ptcg)
  3717. #pragma intrinsic (__ptcga)
  3718. #pragma intrinsic (__ptri)
  3719. #pragma intrinsic (__ptrd)
  3720. #pragma intrinsic (__invalat)
  3721. #pragma intrinsic (__break)
  3722. #pragma intrinsic (__fc)
  3723. #pragma intrinsic (__sum)
  3724. #pragma intrinsic (__rsm)
  3725. #pragma intrinsic (_ReleaseSpinLock)
  3726. #endif // _M_IA64
  3727. #ifdef __cplusplus
  3728. }
  3729. #endif
  3730. // end_wdm end_ntndis
  3731. //
  3732. // Define macro to generate import names.
  3733. //
  3734. #define IMPORT_NAME(name) __imp_##name
  3735. // begin_wdm
  3736. //
  3737. // Define length of interrupt vector table.
  3738. //
  3739. #define MAXIMUM_VECTOR 256
  3740. // end_wdm
  3741. //
  3742. // IA64 specific interlocked operation result values.
  3743. //
  3744. #define RESULT_ZERO 0
  3745. #define RESULT_NEGATIVE 1
  3746. #define RESULT_POSITIVE 2
  3747. //
  3748. // Interlocked result type is portable, but its values are machine specific.
  3749. // Constants for values are in i386.h, mips.h, etc.
  3750. //
  3751. typedef enum _INTERLOCKED_RESULT {
  3752. ResultNegative = RESULT_NEGATIVE,
  3753. ResultZero = RESULT_ZERO,
  3754. ResultPositive = RESULT_POSITIVE
  3755. } INTERLOCKED_RESULT;
  3756. //
  3757. // Convert portable interlock interfaces to architecture specific interfaces.
  3758. //
  3759. #if PRAGMA_DEPRECATED_DDK
  3760. #pragma deprecated(ExInterlockedIncrementLong) // Use InterlockedIncrement
  3761. #pragma deprecated(ExInterlockedDecrementLong) // Use InterlockedDecrement
  3762. #pragma deprecated(ExInterlockedExchangeUlong) // Use InterlockedExchange
  3763. #endif
  3764. #define ExInterlockedIncrementLong(Addend, Lock) \
  3765. ExIa64InterlockedIncrementLong(Addend)
  3766. #define ExInterlockedDecrementLong(Addend, Lock) \
  3767. ExIa64InterlockedDecrementLong(Addend)
  3768. #define ExInterlockedExchangeUlong(Target, Value, Lock) \
  3769. ExIa64InterlockedExchangeUlong(Target, Value)
  3770. NTKERNELAPI
  3771. INTERLOCKED_RESULT
  3772. ExIa64InterlockedIncrementLong (
  3773. IN PLONG Addend
  3774. );
  3775. NTKERNELAPI
  3776. INTERLOCKED_RESULT
  3777. ExIa64InterlockedDecrementLong (
  3778. IN PLONG Addend
  3779. );
  3780. NTKERNELAPI
  3781. ULONG
  3782. ExIa64InterlockedExchangeUlong (
  3783. IN PULONG Target,
  3784. IN ULONG Value
  3785. );
  3786. // begin_wdm
  3787. //
  3788. // IA64 Interrupt Definitions.
  3789. //
  3790. // Define length of interrupt object dispatch code in longwords.
  3791. //
  3792. #define DISPATCH_LENGTH 2*2 // Length of dispatch code template in 32-bit words
  3793. //
  3794. // Begin of a block of definitions that must be synchronized with kxia64.h.
  3795. //
  3796. //
  3797. // Define Interrupt Request Levels.
  3798. //
  3799. #define PASSIVE_LEVEL 0 // Passive release level
  3800. #define LOW_LEVEL 0 // Lowest interrupt level
  3801. #define APC_LEVEL 1 // APC interrupt level
  3802. #define DISPATCH_LEVEL 2 // Dispatcher level
  3803. #define CMC_LEVEL 3 // Correctable machine check level
  3804. #define DEVICE_LEVEL_BASE 4 // 4 - 11 - Device IRQLs
  3805. #define PC_LEVEL 12 // Performance Counter IRQL
  3806. #define IPI_LEVEL 14 // IPI IRQL
  3807. #define CLOCK_LEVEL 13 // Clock Timer IRQL
  3808. #define POWER_LEVEL 15 // Power failure level
  3809. #define PROFILE_LEVEL 15 // Profiling level
  3810. #define HIGH_LEVEL 15 // Highest interrupt level
  3811. #if defined(NT_UP)
  3812. #define SYNCH_LEVEL DISPATCH_LEVEL // Synchronization level - UP
  3813. #else
  3814. #define SYNCH_LEVEL (IPI_LEVEL-1) // Synchronization level - MP
  3815. #endif
  3816. //
  3817. // The current IRQL is maintained in the TPR.mic field. The
  3818. // shift count is the number of bits to shift right to extract the
  3819. // IRQL from the TPR. See the GET/SET_IRQL macros.
  3820. //
  3821. #define TPR_MIC 4
  3822. #define TPR_IRQL_SHIFT TPR_MIC
  3823. // To go from vector number <-> IRQL we just do a shift
  3824. #define VECTOR_IRQL_SHIFT TPR_IRQL_SHIFT
  3825. //
  3826. // Interrupt Vector Definitions
  3827. //
  3828. #define APC_VECTOR APC_LEVEL << VECTOR_IRQL_SHIFT
  3829. #define DISPATCH_VECTOR DISPATCH_LEVEL << VECTOR_IRQL_SHIFT
  3830. //
  3831. // End of a block of definitions that must be synchronized with kxia64.h.
  3832. //
  3833. //
  3834. // Define profile intervals.
  3835. //
  3836. #define DEFAULT_PROFILE_COUNT 0x40000000 // ~= 20 seconds @50mhz
  3837. #define DEFAULT_PROFILE_INTERVAL (10 * 500) // 500 microseconds
  3838. #define MAXIMUM_PROFILE_INTERVAL (10 * 1000 * 1000) // 1 second
  3839. #define MINIMUM_PROFILE_INTERVAL (10 * 40) // 40 microseconds
  3840. #if defined(_M_IA64) && !defined(RC_INVOKED)
  3841. #define InterlockedAdd _InterlockedAdd
  3842. #define InterlockedIncrement _InterlockedIncrement
  3843. #define InterlockedDecrement _InterlockedDecrement
  3844. #define InterlockedExchange _InterlockedExchange
  3845. #define InterlockedExchangeAdd _InterlockedExchangeAdd
  3846. #define InterlockedAdd64 _InterlockedAdd64
  3847. #define InterlockedIncrement64 _InterlockedIncrement64
  3848. #define InterlockedDecrement64 _InterlockedDecrement64
  3849. #define InterlockedExchange64 _InterlockedExchange64
  3850. #define InterlockedExchangeAdd64 _InterlockedExchangeAdd64
  3851. #define InterlockedCompareExchange64 _InterlockedCompareExchange64
  3852. #define InterlockedCompareExchange _InterlockedCompareExchange
  3853. #define InterlockedExchangePointer _InterlockedExchangePointer
  3854. #define InterlockedCompareExchangePointer _InterlockedCompareExchangePointer
  3855. #ifdef __cplusplus
  3856. extern "C" {
  3857. #endif
  3858. LONG
  3859. __cdecl
  3860. InterlockedAdd (
  3861. LONG volatile *Addend,
  3862. LONG Value
  3863. );
  3864. LONGLONG
  3865. __cdecl
  3866. InterlockedAdd64 (
  3867. LONGLONG volatile *Addend,
  3868. LONGLONG Value
  3869. );
  3870. LONG
  3871. __cdecl
  3872. InterlockedIncrement(
  3873. IN OUT LONG volatile *Addend
  3874. );
  3875. LONG
  3876. __cdecl
  3877. InterlockedDecrement(
  3878. IN OUT LONG volatile *Addend
  3879. );
  3880. LONG
  3881. __cdecl
  3882. InterlockedExchange(
  3883. IN OUT LONG volatile *Target,
  3884. IN LONG Value
  3885. );
  3886. LONG
  3887. __cdecl
  3888. InterlockedExchangeAdd(
  3889. IN OUT LONG volatile *Addend,
  3890. IN LONG Value
  3891. );
  3892. LONG
  3893. __cdecl
  3894. InterlockedCompareExchange (
  3895. IN OUT LONG volatile *Destination,
  3896. IN LONG ExChange,
  3897. IN LONG Comperand
  3898. );
  3899. LONGLONG
  3900. __cdecl
  3901. InterlockedIncrement64(
  3902. IN OUT LONGLONG volatile *Addend
  3903. );
  3904. LONGLONG
  3905. __cdecl
  3906. InterlockedDecrement64(
  3907. IN OUT LONGLONG volatile *Addend
  3908. );
  3909. LONGLONG
  3910. __cdecl
  3911. InterlockedExchange64(
  3912. IN OUT LONGLONG volatile *Target,
  3913. IN LONGLONG Value
  3914. );
  3915. LONGLONG
  3916. __cdecl
  3917. InterlockedExchangeAdd64(
  3918. IN OUT LONGLONG volatile *Addend,
  3919. IN LONGLONG Value
  3920. );
  3921. LONGLONG
  3922. __cdecl
  3923. InterlockedCompareExchange64 (
  3924. IN OUT LONGLONG volatile *Destination,
  3925. IN LONGLONG ExChange,
  3926. IN LONGLONG Comperand
  3927. );
  3928. PVOID
  3929. __cdecl
  3930. InterlockedCompareExchangePointer (
  3931. IN OUT PVOID volatile *Destination,
  3932. IN PVOID Exchange,
  3933. IN PVOID Comperand
  3934. );
  3935. PVOID
  3936. __cdecl
  3937. InterlockedExchangePointer(
  3938. IN OUT PVOID volatile *Target,
  3939. IN PVOID Value
  3940. );
  3941. #pragma intrinsic(_InterlockedAdd)
  3942. #pragma intrinsic(_InterlockedIncrement)
  3943. #pragma intrinsic(_InterlockedDecrement)
  3944. #pragma intrinsic(_InterlockedExchange)
  3945. #pragma intrinsic(_InterlockedCompareExchange)
  3946. #pragma intrinsic(_InterlockedExchangeAdd)
  3947. #pragma intrinsic(_InterlockedAdd64)
  3948. #pragma intrinsic(_InterlockedIncrement64)
  3949. #pragma intrinsic(_InterlockedDecrement64)
  3950. #pragma intrinsic(_InterlockedExchange64)
  3951. #pragma intrinsic(_InterlockedCompareExchange64)
  3952. #pragma intrinsic(_InterlockedExchangeAdd64)
  3953. #pragma intrinsic(_InterlockedExchangePointer)
  3954. #pragma intrinsic(_InterlockedCompareExchangePointer)
  3955. #ifdef __cplusplus
  3956. }
  3957. #endif
  3958. #endif // defined(_M_IA64) && !defined(RC_INVOKED)
  3959. #define KI_USER_SHARED_DATA ((ULONG_PTR)(KADDRESS_BASE + 0xFFFE0000))
  3960. #define SharedUserData ((KUSER_SHARED_DATA * const)KI_USER_SHARED_DATA)
  3961. //
  3962. // Prototype for get current IRQL. **** TBD (read TPR)
  3963. //
  3964. NTKERNELAPI
  3965. KIRQL
  3966. KeGetCurrentIrql();
  3967. // end_wdm
  3968. //
  3969. // Get address of current processor block.
  3970. //
  3971. #define KeGetCurrentPrcb() PCR->Prcb
  3972. //
  3973. // Get address of processor control region.
  3974. //
  3975. #define KeGetPcr() PCR
  3976. //
  3977. // Get address of current kernel thread object.
  3978. //
  3979. #if defined(_M_IA64)
  3980. #define KeGetCurrentThread() PCR->CurrentThread
  3981. #endif
  3982. //
  3983. // Get current processor number.
  3984. //
  3985. #define KeGetCurrentProcessorNumber() PCR->Number
  3986. //
  3987. // Get data cache fill size.
  3988. //
  3989. #if PRAGMA_DEPRECATED_DDK
  3990. #pragma deprecated(KeGetDcacheFillSize) // Use GetDmaAlignment
  3991. #endif
  3992. #define KeGetDcacheFillSize() PCR->DcacheFillSize
  3993. #define KeSaveFloatingPointState(a) STATUS_SUCCESS
  3994. #define KeRestoreFloatingPointState(a) STATUS_SUCCESS
  3995. //
  3996. // Define the page size
  3997. //
  3998. #define PAGE_SIZE 0x2000
  3999. //
  4000. // Define the number of trailing zeroes in a page aligned virtual address.
  4001. // This is used as the shift count when shifting virtual addresses to
  4002. // virtual page numbers.
  4003. //
  4004. #define PAGE_SHIFT 13L
  4005. //
  4006. // Cache and write buffer flush functions.
  4007. //
  4008. NTKERNELAPI
  4009. VOID
  4010. KeFlushIoBuffers (
  4011. IN PMDL Mdl,
  4012. IN BOOLEAN ReadOperation,
  4013. IN BOOLEAN DmaOperation
  4014. );
  4015. #define ExAcquireSpinLock(Lock, OldIrql) KeAcquireSpinLock((Lock), (OldIrql))
  4016. #define ExReleaseSpinLock(Lock, OldIrql) KeReleaseSpinLock((Lock), (OldIrql))
  4017. #define ExAcquireSpinLockAtDpcLevel(Lock) KeAcquireSpinLockAtDpcLevel(Lock)
  4018. #define ExReleaseSpinLockFromDpcLevel(Lock) KeReleaseSpinLockFromDpcLevel(Lock)
  4019. #if defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_)
  4020. // begin_wdm
  4021. #define KeQueryTickCount(CurrentCount ) \
  4022. *(PULONGLONG)(CurrentCount) = **((volatile ULONGLONG **)(&KeTickCount));
  4023. // end_wdm
  4024. #else
  4025. NTKERNELAPI
  4026. VOID
  4027. KeQueryTickCount (
  4028. OUT PLARGE_INTEGER CurrentCount
  4029. );
  4030. #endif // defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_)
  4031. //
  4032. // I/O space read and write macros.
  4033. //
  4034. NTHALAPI
  4035. UCHAR
  4036. READ_PORT_UCHAR (
  4037. PUCHAR RegisterAddress
  4038. );
  4039. NTHALAPI
  4040. USHORT
  4041. READ_PORT_USHORT (
  4042. PUSHORT RegisterAddress
  4043. );
  4044. NTHALAPI
  4045. ULONG
  4046. READ_PORT_ULONG (
  4047. PULONG RegisterAddress
  4048. );
  4049. NTHALAPI
  4050. VOID
  4051. READ_PORT_BUFFER_UCHAR (
  4052. PUCHAR portAddress,
  4053. PUCHAR readBuffer,
  4054. ULONG readCount
  4055. );
  4056. NTHALAPI
  4057. VOID
  4058. READ_PORT_BUFFER_USHORT (
  4059. PUSHORT portAddress,
  4060. PUSHORT readBuffer,
  4061. ULONG readCount
  4062. );
  4063. NTHALAPI
  4064. VOID
  4065. READ_PORT_BUFFER_ULONG (
  4066. PULONG portAddress,
  4067. PULONG readBuffer,
  4068. ULONG readCount
  4069. );
  4070. NTHALAPI
  4071. VOID
  4072. WRITE_PORT_UCHAR (
  4073. PUCHAR portAddress,
  4074. UCHAR Data
  4075. );
  4076. NTHALAPI
  4077. VOID
  4078. WRITE_PORT_USHORT (
  4079. PUSHORT portAddress,
  4080. USHORT Data
  4081. );
  4082. NTHALAPI
  4083. VOID
  4084. WRITE_PORT_ULONG (
  4085. PULONG portAddress,
  4086. ULONG Data
  4087. );
  4088. NTHALAPI
  4089. VOID
  4090. WRITE_PORT_BUFFER_UCHAR (
  4091. PUCHAR portAddress,
  4092. PUCHAR writeBuffer,
  4093. ULONG writeCount
  4094. );
  4095. NTHALAPI
  4096. VOID
  4097. WRITE_PORT_BUFFER_USHORT (
  4098. PUSHORT portAddress,
  4099. PUSHORT writeBuffer,
  4100. ULONG writeCount
  4101. );
  4102. NTHALAPI
  4103. VOID
  4104. WRITE_PORT_BUFFER_ULONG (
  4105. PULONG portAddress,
  4106. PULONG writeBuffer,
  4107. ULONG writeCount
  4108. );
  4109. #define READ_REGISTER_UCHAR(x) \
  4110. (__mf(), *(volatile UCHAR * const)(x))
  4111. #define READ_REGISTER_USHORT(x) \
  4112. (__mf(), *(volatile USHORT * const)(x))
  4113. #define READ_REGISTER_ULONG(x) \
  4114. (__mf(), *(volatile ULONG * const)(x))
  4115. #define READ_REGISTER_BUFFER_UCHAR(x, y, z) { \
  4116. PUCHAR registerBuffer = x; \
  4117. PUCHAR readBuffer = y; \
  4118. ULONG readCount; \
  4119. __mf(); \
  4120. for (readCount = z; readCount--; readBuffer++, registerBuffer++) { \
  4121. *readBuffer = *(volatile UCHAR * const)(registerBuffer); \
  4122. } \
  4123. }
  4124. #define READ_REGISTER_BUFFER_USHORT(x, y, z) { \
  4125. PUSHORT registerBuffer = x; \
  4126. PUSHORT readBuffer = y; \
  4127. ULONG readCount; \
  4128. __mf(); \
  4129. for (readCount = z; readCount--; readBuffer++, registerBuffer++) { \
  4130. *readBuffer = *(volatile USHORT * const)(registerBuffer); \
  4131. } \
  4132. }
  4133. #define READ_REGISTER_BUFFER_ULONG(x, y, z) { \
  4134. PULONG registerBuffer = x; \
  4135. PULONG readBuffer = y; \
  4136. ULONG readCount; \
  4137. __mf(); \
  4138. for (readCount = z; readCount--; readBuffer++, registerBuffer++) { \
  4139. *readBuffer = *(volatile ULONG * const)(registerBuffer); \
  4140. } \
  4141. }
  4142. #define WRITE_REGISTER_UCHAR(x, y) { \
  4143. *(volatile UCHAR * const)(x) = y; \
  4144. KeFlushWriteBuffer(); \
  4145. }
  4146. #define WRITE_REGISTER_USHORT(x, y) { \
  4147. *(volatile USHORT * const)(x) = y; \
  4148. KeFlushWriteBuffer(); \
  4149. }
  4150. #define WRITE_REGISTER_ULONG(x, y) { \
  4151. *(volatile ULONG * const)(x) = y; \
  4152. KeFlushWriteBuffer(); \
  4153. }
  4154. #define WRITE_REGISTER_BUFFER_UCHAR(x, y, z) { \
  4155. PUCHAR registerBuffer = x; \
  4156. PUCHAR writeBuffer = y; \
  4157. ULONG writeCount; \
  4158. for (writeCount = z; writeCount--; writeBuffer++, registerBuffer++) { \
  4159. *(volatile UCHAR * const)(registerBuffer) = *writeBuffer; \
  4160. } \
  4161. KeFlushWriteBuffer(); \
  4162. }
  4163. #define WRITE_REGISTER_BUFFER_USHORT(x, y, z) { \
  4164. PUSHORT registerBuffer = x; \
  4165. PUSHORT writeBuffer = y; \
  4166. ULONG writeCount; \
  4167. for (writeCount = z; writeCount--; writeBuffer++, registerBuffer++) { \
  4168. *(volatile USHORT * const)(registerBuffer) = *writeBuffer; \
  4169. } \
  4170. KeFlushWriteBuffer(); \
  4171. }
  4172. #define WRITE_REGISTER_BUFFER_ULONG(x, y, z) { \
  4173. PULONG registerBuffer = x; \
  4174. PULONG writeBuffer = y; \
  4175. ULONG writeCount; \
  4176. for (writeCount = z; writeCount--; writeBuffer++, registerBuffer++) { \
  4177. *(volatile ULONG * const)(registerBuffer) = *writeBuffer; \
  4178. } \
  4179. KeFlushWriteBuffer(); \
  4180. }
  4181. //
  4182. // Non-volatile floating point state
  4183. //
  4184. typedef struct _KFLOATING_SAVE {
  4185. ULONG Reserved;
  4186. } KFLOATING_SAVE, *PKFLOATING_SAVE;
  4187. //
  4188. // Processor Control Block (PRCB)
  4189. //
  4190. #define PRCB_MINOR_VERSION 1
  4191. #define PRCB_MAJOR_VERSION 1
  4192. #define PRCB_BUILD_DEBUG 0x0001
  4193. #define PRCB_BUILD_UNIPROCESSOR 0x0002
  4194. struct _RESTART_BLOCK;
  4195. typedef struct _KPRCB {
  4196. //
  4197. // Major and minor version numbers of the PCR.
  4198. //
  4199. USHORT MinorVersion;
  4200. USHORT MajorVersion;
  4201. //
  4202. // Start of the architecturally defined section of the PRCB. This section
  4203. // may be directly addressed by vendor/platform specific HAL code and will
  4204. // not change from version to version of NT.
  4205. //
  4206. //
  4207. struct _KTHREAD *CurrentThread;
  4208. struct _KTHREAD *RESTRICTED_POINTER NextThread;
  4209. struct _KTHREAD *IdleThread;
  4210. CCHAR Number;
  4211. CCHAR WakeIdle;
  4212. USHORT BuildType;
  4213. KAFFINITY SetMember;
  4214. struct _RESTART_BLOCK *RestartBlock;
  4215. ULONG_PTR PcrPage;
  4216. ULONG Spare0[4];
  4217. //
  4218. // Processor Idendification Registers.
  4219. //
  4220. ULONG ProcessorModel;
  4221. ULONG ProcessorRevision;
  4222. ULONG ProcessorFamily;
  4223. ULONG ProcessorArchRev;
  4224. ULONGLONG ProcessorSerialNumber;
  4225. ULONGLONG ProcessorFeatureBits;
  4226. UCHAR ProcessorVendorString[16];
  4227. //
  4228. // Space reserved for the system.
  4229. //
  4230. ULONGLONG SystemReserved[8];
  4231. //
  4232. // Space reserved for the HAL.
  4233. //
  4234. ULONGLONG HalReserved[16];
  4235. //
  4236. // End of the architecturally defined section of the PRCB.
  4237. } KPRCB, *PKPRCB, *RESTRICTED_POINTER PRKPRCB;
  4238. // begin_ntndis
  4239. //
  4240. // OS_MCA, OS_INIT HandOff State definitions
  4241. //
  4242. // Note: The following definitions *must* match the definiions of the
  4243. // corresponding SAL Revision Hand-Off structures.
  4244. //
  4245. typedef struct _SAL_HANDOFF_STATE {
  4246. ULONGLONG PalProcEntryPoint;
  4247. ULONGLONG SalProcEntryPoint;
  4248. ULONGLONG SalGlobalPointer;
  4249. LONGLONG RendezVousResult;
  4250. ULONGLONG SalReturnAddress;
  4251. ULONGLONG MinStateSavePtr;
  4252. } SAL_HANDOFF_STATE, *PSAL_HANDOFF_STATE;
  4253. typedef struct _OS_HANDOFF_STATE {
  4254. ULONGLONG Result;
  4255. ULONGLONG SalGlobalPointer;
  4256. ULONGLONG MinStateSavePtr;
  4257. ULONGLONG SalReturnAddress;
  4258. ULONGLONG NewContextFlag;
  4259. } OS_HANDOFF_STATE, *POS_HANDOFF_STATE;
  4260. //
  4261. // per processor OS_MCA and OS_INIT resource structure
  4262. //
  4263. #define SER_EVENT_STACK_FRAME_ENTRIES 8
  4264. typedef struct _SAL_EVENT_RESOURCES {
  4265. SAL_HANDOFF_STATE SalToOsHandOff;
  4266. OS_HANDOFF_STATE OsToSalHandOff;
  4267. PVOID StateDump;
  4268. ULONGLONG StateDumpPhysical;
  4269. PVOID BackStore;
  4270. ULONGLONG BackStoreLimit;
  4271. PVOID Stack;
  4272. ULONGLONG StackLimit;
  4273. PULONGLONG PTOM;
  4274. ULONGLONG StackFrame[SER_EVENT_STACK_FRAME_ENTRIES];
  4275. PVOID EventPool;
  4276. ULONG EventPoolSize;
  4277. } SAL_EVENT_RESOURCES, *PSAL_EVENT_RESOURCES;
  4278. //
  4279. // PAL Mini-save area, used by MCA and INIT
  4280. //
  4281. typedef struct _PAL_MINI_SAVE_AREA {
  4282. ULONGLONG IntNats; // Nat bits for r1-r31
  4283. // r1-r31 in bits 1 thru 31.
  4284. ULONGLONG IntGp; // r1, volatile
  4285. ULONGLONG IntT0; // r2-r3, volatile
  4286. ULONGLONG IntT1; //
  4287. ULONGLONG IntS0; // r4-r7, preserved
  4288. ULONGLONG IntS1;
  4289. ULONGLONG IntS2;
  4290. ULONGLONG IntS3;
  4291. ULONGLONG IntV0; // r8, volatile
  4292. ULONGLONG IntT2; // r9-r11, volatile
  4293. ULONGLONG IntT3;
  4294. ULONGLONG IntT4;
  4295. ULONGLONG IntSp; // stack pointer (r12), special
  4296. ULONGLONG IntTeb; // teb (r13), special
  4297. ULONGLONG IntT5; // r14-r31, volatile
  4298. ULONGLONG IntT6;
  4299. ULONGLONG B0R16; // Bank 0 registers 16-31
  4300. ULONGLONG B0R17;
  4301. ULONGLONG B0R18;
  4302. ULONGLONG B0R19;
  4303. ULONGLONG B0R20;
  4304. ULONGLONG B0R21;
  4305. ULONGLONG B0R22;
  4306. ULONGLONG B0R23;
  4307. ULONGLONG B0R24;
  4308. ULONGLONG B0R25;
  4309. ULONGLONG B0R26;
  4310. ULONGLONG B0R27;
  4311. ULONGLONG B0R28;
  4312. ULONGLONG B0R29;
  4313. ULONGLONG B0R30;
  4314. ULONGLONG B0R31;
  4315. ULONGLONG IntT7; // Bank 1 registers 16-31
  4316. ULONGLONG IntT8;
  4317. ULONGLONG IntT9;
  4318. ULONGLONG IntT10;
  4319. ULONGLONG IntT11;
  4320. ULONGLONG IntT12;
  4321. ULONGLONG IntT13;
  4322. ULONGLONG IntT14;
  4323. ULONGLONG IntT15;
  4324. ULONGLONG IntT16;
  4325. ULONGLONG IntT17;
  4326. ULONGLONG IntT18;
  4327. ULONGLONG IntT19;
  4328. ULONGLONG IntT20;
  4329. ULONGLONG IntT21;
  4330. ULONGLONG IntT22;
  4331. ULONGLONG Preds; // predicates, preserved
  4332. ULONGLONG BrRp; // return pointer, b0, preserved
  4333. ULONGLONG RsRSC; // RSE configuration, volatile
  4334. ULONGLONG StIIP; // Interruption IP
  4335. ULONGLONG StIPSR; // Interruption Processor Status
  4336. ULONGLONG StIFS; // Interruption Function State
  4337. ULONGLONG XIP; // Event IP
  4338. ULONGLONG XPSR; // Event Processor Status
  4339. ULONGLONG XFS; // Event Function State
  4340. } PAL_MINI_SAVE_AREA, *PPAL_MINI_SAVE_AREA;
  4341. //
  4342. // Define Processor Control Region Structure.
  4343. //
  4344. #define PCR_MINOR_VERSION 1
  4345. #define PCR_MAJOR_VERSION 1
  4346. typedef struct _KPCR {
  4347. //
  4348. // Major and minor version numbers of the PCR.
  4349. //
  4350. ULONG MinorVersion;
  4351. ULONG MajorVersion;
  4352. //
  4353. // Start of the architecturally defined section of the PCR. This section
  4354. // may be directly addressed by vendor/platform specific HAL code and will
  4355. // not change from version to version of NT.
  4356. //
  4357. //
  4358. // First and second level cache parameters.
  4359. //
  4360. ULONG FirstLevelDcacheSize;
  4361. ULONG FirstLevelDcacheFillSize;
  4362. ULONG FirstLevelIcacheSize;
  4363. ULONG FirstLevelIcacheFillSize;
  4364. ULONG SecondLevelDcacheSize;
  4365. ULONG SecondLevelDcacheFillSize;
  4366. ULONG SecondLevelIcacheSize;
  4367. ULONG SecondLevelIcacheFillSize;
  4368. //
  4369. // Data cache alignment and fill size used for cache flushing and alignment.
  4370. // These fields are set to the larger of the first and second level data
  4371. // cache fill sizes.
  4372. //
  4373. ULONG DcacheAlignment;
  4374. ULONG DcacheFillSize;
  4375. //
  4376. // Instruction cache alignment and fill size used for cache flushing and
  4377. // alignment. These fields are set to the larger of the first and second
  4378. // level data cache fill sizes.
  4379. //
  4380. ULONG IcacheAlignment;
  4381. ULONG IcacheFillSize;
  4382. //
  4383. // Processor identification from PrId register.
  4384. //
  4385. ULONG ProcessorId;
  4386. //
  4387. // Profiling data.
  4388. //
  4389. ULONG ProfileInterval;
  4390. ULONG ProfileCount;
  4391. //
  4392. // Stall execution count and scale factor.
  4393. //
  4394. ULONG StallExecutionCount;
  4395. ULONG StallScaleFactor;
  4396. ULONG InterruptionCount;
  4397. //
  4398. // Space reserved for the system.
  4399. //
  4400. ULONGLONG SystemReserved[6];
  4401. //
  4402. // Space reserved for the HAL
  4403. //
  4404. ULONGLONG HalReserved[64];
  4405. //
  4406. // IRQL mapping tables.
  4407. //
  4408. UCHAR IrqlMask[64];
  4409. UCHAR IrqlTable[64];
  4410. //
  4411. // External Interrupt vectors.
  4412. //
  4413. PKINTERRUPT_ROUTINE InterruptRoutine[MAXIMUM_VECTOR];
  4414. //
  4415. // Reserved interrupt vector mask.
  4416. //
  4417. ULONG ReservedVectors;
  4418. //
  4419. // Processor affinity mask.
  4420. //
  4421. KAFFINITY SetMember;
  4422. //
  4423. // Complement of the processor affinity mask.
  4424. //
  4425. KAFFINITY NotMember;
  4426. //
  4427. // Pointer to processor control block.
  4428. //
  4429. struct _KPRCB *Prcb;
  4430. //
  4431. // Shadow copy of Prcb->CurrentThread for fast access
  4432. //
  4433. struct _KTHREAD *CurrentThread;
  4434. //
  4435. // Processor number.
  4436. //
  4437. CCHAR Number; // Processor Number
  4438. UCHAR DebugActive; // debug register active in user flag
  4439. UCHAR KernelDebugActive; // debug register active in kernel flag
  4440. UCHAR CurrentIrql; // Current IRQL
  4441. union {
  4442. USHORT SoftwareInterruptPending; // Software Interrupt Pending Flag
  4443. struct {
  4444. UCHAR ApcInterrupt; // 0x01 if APC int pending
  4445. UCHAR DispatchInterrupt; // 0x01 if dispatch int pending
  4446. };
  4447. };
  4448. //
  4449. // Address of per processor SAPIC EOI Table
  4450. //
  4451. PVOID EOITable;
  4452. //
  4453. // IA-64 Machine Check Events trackers
  4454. //
  4455. UCHAR InOsMca;
  4456. UCHAR InOsInit;
  4457. UCHAR InOsCmc;
  4458. UCHAR InOsCpe;
  4459. ULONG InOsULONG_Spare; // Spare ULONG
  4460. PSAL_EVENT_RESOURCES OsMcaResourcePtr;
  4461. PSAL_EVENT_RESOURCES OsInitResourcePtr;
  4462. //
  4463. // End of the architecturally defined section of the PCR. This section
  4464. // may be directly addressed by vendor/platform specific HAL code and will
  4465. // not change from version to version of NT.
  4466. //
  4467. // end_nthal end_ntddk
  4468. //
  4469. // OS Part
  4470. //
  4471. //
  4472. // Address of the thread who currently owns the high fp register set
  4473. //
  4474. struct _KTHREAD *HighFpOwner;
  4475. // Per processor kernel (ntoskrnl.exe) global pointer
  4476. ULONGLONG KernelGP;
  4477. // Per processor initial kernel stack for current thread
  4478. ULONGLONG InitialStack;
  4479. // Per processor pointer to kernel BSP
  4480. ULONGLONG InitialBStore;
  4481. // Per processor kernel stack limit
  4482. ULONGLONG StackLimit;
  4483. // Per processor kernel backing store limit
  4484. ULONGLONG BStoreLimit;
  4485. // Per processor panic kernel stack
  4486. ULONGLONG PanicStack;
  4487. //
  4488. // Save area for kernel entry/exit
  4489. //
  4490. ULONGLONG SavedIIM;
  4491. ULONGLONG SavedIFA;
  4492. ULONGLONG ForwardProgressBuffer[16];
  4493. PVOID Pcb; // holds KPROCESS for MP region synchronization
  4494. //
  4495. // Nt page table base addresses
  4496. //
  4497. ULONGLONG PteUbase;
  4498. ULONGLONG PteKbase;
  4499. ULONGLONG PteSbase;
  4500. ULONGLONG PdeUbase;
  4501. ULONGLONG PdeKbase;
  4502. ULONGLONG PdeSbase;
  4503. ULONGLONG PdeUtbase;
  4504. ULONGLONG PdeKtbase;
  4505. ULONGLONG PdeStbase;
  4506. //
  4507. // The actual resources for the OS_INIT and OS_MCA handlers
  4508. // are placed at the end of the PCR structure so that auto
  4509. // can be used to get to get between the public and private
  4510. // sections of the PCR in the traps and context routines.
  4511. //
  4512. SAL_EVENT_RESOURCES OsMcaResource;
  4513. SAL_EVENT_RESOURCES OsInitResource;
  4514. // begin_nthal begin_ntddk
  4515. } KPCR, *PKPCR;
  4516. //
  4517. // The highest user address reserves 64K bytes for a guard page. This
  4518. // the probing of address from kernel mode to only have to check the
  4519. // starting address for structures of 64k bytes or less.
  4520. //
  4521. extern NTKERNELAPI PVOID MmHighestUserAddress;
  4522. extern NTKERNELAPI PVOID MmSystemRangeStart;
  4523. extern NTKERNELAPI ULONG_PTR MmUserProbeAddress;
  4524. #define MM_HIGHEST_USER_ADDRESS MmHighestUserAddress
  4525. #define MM_USER_PROBE_ADDRESS MmUserProbeAddress
  4526. #define MM_SYSTEM_RANGE_START MmSystemRangeStart
  4527. //
  4528. // The lowest user address reserves the low 64k.
  4529. //
  4530. #define MM_LOWEST_USER_ADDRESS (PVOID)((ULONG_PTR)(UADDRESS_BASE+0x00010000))
  4531. // begin_wdm
  4532. #define MmGetProcedureAddress(Address) (Address)
  4533. #define MmLockPagableCodeSection(PLabelAddress) \
  4534. MmLockPagableDataSection((PVOID)(*((PULONGLONG)PLabelAddress)))
  4535. #define VRN_MASK 0xE000000000000000UI64 // Virtual Region Number mask
  4536. #endif // defined(_IA64_)
  4537. //
  4538. // Define structure of boot driver list.
  4539. //
  4540. typedef struct _BOOT_DRIVER_LIST_ENTRY {
  4541. LIST_ENTRY Link;
  4542. UNICODE_STRING FilePath;
  4543. UNICODE_STRING RegistryPath;
  4544. PKLDR_DATA_TABLE_ENTRY LdrEntry;
  4545. } BOOT_DRIVER_LIST_ENTRY, *PBOOT_DRIVER_LIST_ENTRY;
  4546. #define THREAD_WAIT_OBJECTS 3 // Builtin usable wait blocks
  4547. //
  4548. #if defined(_X86_)
  4549. #define PAUSE_PROCESSOR _asm { rep nop }
  4550. #else
  4551. #define PAUSE_PROCESSOR
  4552. #endif
  4553. //
  4554. // Define macro to generate an affinity mask.
  4555. //
  4556. #define AFFINITY_MASK(n) ((ULONG_PTR)1 << (n))
  4557. typedef enum _KAPC_ENVIRONMENT {
  4558. OriginalApcEnvironment,
  4559. AttachedApcEnvironment,
  4560. CurrentApcEnvironment,
  4561. InsertApcEnvironment
  4562. } KAPC_ENVIRONMENT;
  4563. // begin_ntddk begin_wdm begin_nthal begin_ntminiport begin_ntifs begin_ntndis
  4564. //
  4565. // Interrupt modes.
  4566. //
  4567. typedef enum _KINTERRUPT_MODE {
  4568. LevelSensitive,
  4569. Latched
  4570. } KINTERRUPT_MODE;
  4571. //
  4572. // Wait reasons
  4573. //
  4574. typedef enum _KWAIT_REASON {
  4575. Executive,
  4576. FreePage,
  4577. PageIn,
  4578. PoolAllocation,
  4579. DelayExecution,
  4580. Suspended,
  4581. UserRequest,
  4582. WrExecutive,
  4583. WrFreePage,
  4584. WrPageIn,
  4585. WrPoolAllocation,
  4586. WrDelayExecution,
  4587. WrSuspended,
  4588. WrUserRequest,
  4589. WrEventPair,
  4590. WrQueue,
  4591. WrLpcReceive,
  4592. WrLpcReply,
  4593. WrVirtualMemory,
  4594. WrPageOut,
  4595. WrRendezvous,
  4596. Spare2,
  4597. Spare3,
  4598. Spare4,
  4599. Spare5,
  4600. Spare6,
  4601. WrKernel,
  4602. MaximumWaitReason
  4603. } KWAIT_REASON;
  4604. // end_ntddk end_wdm end_nthal
  4605. //
  4606. // Miscellaneous type definitions
  4607. //
  4608. // APC state
  4609. //
  4610. typedef struct _KAPC_STATE {
  4611. LIST_ENTRY ApcListHead[MaximumMode];
  4612. struct _KPROCESS *Process;
  4613. BOOLEAN KernelApcInProgress;
  4614. BOOLEAN KernelApcPending;
  4615. BOOLEAN UserApcPending;
  4616. } KAPC_STATE, *PKAPC_STATE, *RESTRICTED_POINTER PRKAPC_STATE;
  4617. typedef struct _KWAIT_BLOCK {
  4618. LIST_ENTRY WaitListEntry;
  4619. struct _KTHREAD *RESTRICTED_POINTER Thread;
  4620. PVOID Object;
  4621. struct _KWAIT_BLOCK *RESTRICTED_POINTER NextWaitBlock;
  4622. USHORT WaitKey;
  4623. USHORT WaitType;
  4624. } KWAIT_BLOCK, *PKWAIT_BLOCK, *RESTRICTED_POINTER PRKWAIT_BLOCK;
  4625. //
  4626. // Thread start function
  4627. //
  4628. typedef
  4629. VOID
  4630. (*PKSTART_ROUTINE) (
  4631. IN PVOID StartContext
  4632. );
  4633. //
  4634. // Kernel object structure definitions
  4635. //
  4636. //
  4637. // Device Queue object and entry
  4638. //
  4639. typedef struct _KDEVICE_QUEUE {
  4640. CSHORT Type;
  4641. CSHORT Size;
  4642. LIST_ENTRY DeviceListHead;
  4643. KSPIN_LOCK Lock;
  4644. BOOLEAN Busy;
  4645. } KDEVICE_QUEUE, *PKDEVICE_QUEUE, *RESTRICTED_POINTER PRKDEVICE_QUEUE;
  4646. typedef struct _KDEVICE_QUEUE_ENTRY {
  4647. LIST_ENTRY DeviceListEntry;
  4648. ULONG SortKey;
  4649. BOOLEAN Inserted;
  4650. } KDEVICE_QUEUE_ENTRY, *PKDEVICE_QUEUE_ENTRY, *RESTRICTED_POINTER PRKDEVICE_QUEUE_ENTRY;
  4651. //
  4652. // Define the interrupt service function type and the empty struct
  4653. // type.
  4654. //
  4655. typedef
  4656. BOOLEAN
  4657. (*PKSERVICE_ROUTINE) (
  4658. IN struct _KINTERRUPT *Interrupt,
  4659. IN PVOID ServiceContext
  4660. );
  4661. typedef struct _KINTERRUPT *PKINTERRUPT, *RESTRICTED_POINTER PRKINTERRUPT;
  4662. //
  4663. // Mutant object
  4664. //
  4665. typedef struct _KMUTANT {
  4666. DISPATCHER_HEADER Header;
  4667. LIST_ENTRY MutantListEntry;
  4668. struct _KTHREAD *RESTRICTED_POINTER OwnerThread;
  4669. BOOLEAN Abandoned;
  4670. UCHAR ApcDisable;
  4671. } KMUTANT, *PKMUTANT, *RESTRICTED_POINTER PRKMUTANT, KMUTEX, *PKMUTEX, *RESTRICTED_POINTER PRKMUTEX;
  4672. typedef struct _KQUEUE {
  4673. DISPATCHER_HEADER Header;
  4674. LIST_ENTRY EntryListHead;
  4675. ULONG CurrentCount;
  4676. ULONG MaximumCount;
  4677. LIST_ENTRY ThreadListHead;
  4678. } KQUEUE, *PKQUEUE, *RESTRICTED_POINTER PRKQUEUE;
  4679. //
  4680. //
  4681. // Semaphore object
  4682. //
  4683. typedef struct _KSEMAPHORE {
  4684. DISPATCHER_HEADER Header;
  4685. LONG Limit;
  4686. } KSEMAPHORE, *PKSEMAPHORE, *RESTRICTED_POINTER PRKSEMAPHORE;
  4687. NTKERNELAPI
  4688. VOID
  4689. KeInitializeApc (
  4690. IN PRKAPC Apc,
  4691. IN PRKTHREAD Thread,
  4692. IN KAPC_ENVIRONMENT Environment,
  4693. IN PKKERNEL_ROUTINE KernelRoutine,
  4694. IN PKRUNDOWN_ROUTINE RundownRoutine OPTIONAL,
  4695. IN PKNORMAL_ROUTINE NormalRoutine OPTIONAL,
  4696. IN KPROCESSOR_MODE ProcessorMode OPTIONAL,
  4697. IN PVOID NormalContext OPTIONAL
  4698. );
  4699. PLIST_ENTRY
  4700. KeFlushQueueApc (
  4701. IN PKTHREAD Thread,
  4702. IN KPROCESSOR_MODE ProcessorMode
  4703. );
  4704. NTKERNELAPI
  4705. BOOLEAN
  4706. KeInsertQueueApc (
  4707. IN PRKAPC Apc,
  4708. IN PVOID SystemArgument1,
  4709. IN PVOID SystemArgument2,
  4710. IN KPRIORITY Increment
  4711. );
  4712. BOOLEAN
  4713. KeRemoveQueueApc (
  4714. IN PKAPC Apc
  4715. );
  4716. //
  4717. // DPC object
  4718. //
  4719. NTKERNELAPI
  4720. VOID
  4721. KeInitializeDpc (
  4722. IN PRKDPC Dpc,
  4723. IN PKDEFERRED_ROUTINE DeferredRoutine,
  4724. IN PVOID DeferredContext
  4725. );
  4726. NTKERNELAPI
  4727. BOOLEAN
  4728. KeInsertQueueDpc (
  4729. IN PRKDPC Dpc,
  4730. IN PVOID SystemArgument1,
  4731. IN PVOID SystemArgument2
  4732. );
  4733. NTKERNELAPI
  4734. BOOLEAN
  4735. KeRemoveQueueDpc (
  4736. IN PRKDPC Dpc
  4737. );
  4738. // end_wdm
  4739. NTKERNELAPI
  4740. VOID
  4741. KeSetImportanceDpc (
  4742. IN PRKDPC Dpc,
  4743. IN KDPC_IMPORTANCE Importance
  4744. );
  4745. NTKERNELAPI
  4746. VOID
  4747. KeSetTargetProcessorDpc (
  4748. IN PRKDPC Dpc,
  4749. IN CCHAR Number
  4750. );
  4751. // begin_wdm
  4752. NTKERNELAPI
  4753. VOID
  4754. KeFlushQueuedDpcs (
  4755. VOID
  4756. );
  4757. //
  4758. // Device queue object
  4759. //
  4760. NTKERNELAPI
  4761. VOID
  4762. KeInitializeDeviceQueue (
  4763. IN PKDEVICE_QUEUE DeviceQueue
  4764. );
  4765. NTKERNELAPI
  4766. BOOLEAN
  4767. KeInsertDeviceQueue (
  4768. IN PKDEVICE_QUEUE DeviceQueue,
  4769. IN PKDEVICE_QUEUE_ENTRY DeviceQueueEntry
  4770. );
  4771. NTKERNELAPI
  4772. BOOLEAN
  4773. KeInsertByKeyDeviceQueue (
  4774. IN PKDEVICE_QUEUE DeviceQueue,
  4775. IN PKDEVICE_QUEUE_ENTRY DeviceQueueEntry,
  4776. IN ULONG SortKey
  4777. );
  4778. NTKERNELAPI
  4779. PKDEVICE_QUEUE_ENTRY
  4780. KeRemoveDeviceQueue (
  4781. IN PKDEVICE_QUEUE DeviceQueue
  4782. );
  4783. NTKERNELAPI
  4784. PKDEVICE_QUEUE_ENTRY
  4785. KeRemoveByKeyDeviceQueue (
  4786. IN PKDEVICE_QUEUE DeviceQueue,
  4787. IN ULONG SortKey
  4788. );
  4789. NTKERNELAPI
  4790. PKDEVICE_QUEUE_ENTRY
  4791. KeRemoveByKeyDeviceQueueIfBusy (
  4792. IN PKDEVICE_QUEUE DeviceQueue,
  4793. IN ULONG SortKey
  4794. );
  4795. NTKERNELAPI
  4796. BOOLEAN
  4797. KeRemoveEntryDeviceQueue (
  4798. IN PKDEVICE_QUEUE DeviceQueue,
  4799. IN PKDEVICE_QUEUE_ENTRY DeviceQueueEntry
  4800. );
  4801. NTKERNELAPI
  4802. BOOLEAN
  4803. KeSynchronizeExecution (
  4804. IN PKINTERRUPT Interrupt,
  4805. IN PKSYNCHRONIZE_ROUTINE SynchronizeRoutine,
  4806. IN PVOID SynchronizeContext
  4807. );
  4808. NTKERNELAPI
  4809. KIRQL
  4810. KeAcquireInterruptSpinLock (
  4811. IN PKINTERRUPT Interrupt
  4812. );
  4813. NTKERNELAPI
  4814. VOID
  4815. KeReleaseInterruptSpinLock (
  4816. IN PKINTERRUPT Interrupt,
  4817. IN KIRQL OldIrql
  4818. );
  4819. //
  4820. // Kernel dispatcher object functions
  4821. //
  4822. // Event Object
  4823. //
  4824. NTKERNELAPI
  4825. VOID
  4826. KeInitializeEvent (
  4827. IN PRKEVENT Event,
  4828. IN EVENT_TYPE Type,
  4829. IN BOOLEAN State
  4830. );
  4831. NTKERNELAPI
  4832. VOID
  4833. KeClearEvent (
  4834. IN PRKEVENT Event
  4835. );
  4836. NTKERNELAPI
  4837. LONG
  4838. KePulseEvent (
  4839. IN PRKEVENT Event,
  4840. IN KPRIORITY Increment,
  4841. IN BOOLEAN Wait
  4842. );
  4843. NTKERNELAPI
  4844. LONG
  4845. KeReadStateEvent (
  4846. IN PRKEVENT Event
  4847. );
  4848. NTKERNELAPI
  4849. LONG
  4850. KeResetEvent (
  4851. IN PRKEVENT Event
  4852. );
  4853. NTKERNELAPI
  4854. LONG
  4855. KeSetEvent (
  4856. IN PRKEVENT Event,
  4857. IN KPRIORITY Increment,
  4858. IN BOOLEAN Wait
  4859. );
  4860. //
  4861. // Mutex object
  4862. //
  4863. NTKERNELAPI
  4864. VOID
  4865. KeInitializeMutex (
  4866. IN PRKMUTEX Mutex,
  4867. IN ULONG Level
  4868. );
  4869. NTKERNELAPI
  4870. LONG
  4871. KeReadStateMutex (
  4872. IN PRKMUTEX Mutex
  4873. );
  4874. NTKERNELAPI
  4875. LONG
  4876. KeReleaseMutex (
  4877. IN PRKMUTEX Mutex,
  4878. IN BOOLEAN Wait
  4879. );
  4880. // end_ntddk end_wdm
  4881. //
  4882. // Queue Object.
  4883. //
  4884. NTKERNELAPI
  4885. VOID
  4886. KeInitializeQueue (
  4887. IN PRKQUEUE Queue,
  4888. IN ULONG Count OPTIONAL
  4889. );
  4890. NTKERNELAPI
  4891. LONG
  4892. KeReadStateQueue (
  4893. IN PRKQUEUE Queue
  4894. );
  4895. NTKERNELAPI
  4896. LONG
  4897. KeInsertQueue (
  4898. IN PRKQUEUE Queue,
  4899. IN PLIST_ENTRY Entry
  4900. );
  4901. NTKERNELAPI
  4902. LONG
  4903. KeInsertHeadQueue (
  4904. IN PRKQUEUE Queue,
  4905. IN PLIST_ENTRY Entry
  4906. );
  4907. NTKERNELAPI
  4908. PLIST_ENTRY
  4909. KeRemoveQueue (
  4910. IN PRKQUEUE Queue,
  4911. IN KPROCESSOR_MODE WaitMode,
  4912. IN PLARGE_INTEGER Timeout OPTIONAL
  4913. );
  4914. PLIST_ENTRY
  4915. KeRundownQueue (
  4916. IN PRKQUEUE Queue
  4917. );
  4918. // begin_ntddk begin_wdm
  4919. //
  4920. // Semaphore object
  4921. //
  4922. NTKERNELAPI
  4923. VOID
  4924. KeInitializeSemaphore (
  4925. IN PRKSEMAPHORE Semaphore,
  4926. IN LONG Count,
  4927. IN LONG Limit
  4928. );
  4929. NTKERNELAPI
  4930. LONG
  4931. KeReadStateSemaphore (
  4932. IN PRKSEMAPHORE Semaphore
  4933. );
  4934. NTKERNELAPI
  4935. LONG
  4936. KeReleaseSemaphore (
  4937. IN PRKSEMAPHORE Semaphore,
  4938. IN KPRIORITY Increment,
  4939. IN LONG Adjustment,
  4940. IN BOOLEAN Wait
  4941. );
  4942. NTKERNELAPI
  4943. VOID
  4944. KeAttachProcess (
  4945. IN PRKPROCESS Process
  4946. );
  4947. NTKERNELAPI
  4948. VOID
  4949. KeDetachProcess (
  4950. VOID
  4951. );
  4952. NTKERNELAPI
  4953. VOID
  4954. KeStackAttachProcess (
  4955. IN PRKPROCESS PROCESS,
  4956. OUT PRKAPC_STATE ApcState
  4957. );
  4958. NTKERNELAPI
  4959. VOID
  4960. KeUnstackDetachProcess (
  4961. IN PRKAPC_STATE ApcState
  4962. );
  4963. NTKERNELAPI
  4964. BOOLEAN
  4965. KeIsAttachedProcess(
  4966. VOID
  4967. );
  4968. NTKERNELAPI // ntddk wdm nthal ntifs
  4969. NTSTATUS // ntddk wdm nthal ntifs
  4970. KeDelayExecutionThread ( // ntddk wdm nthal ntifs
  4971. IN KPROCESSOR_MODE WaitMode, // ntddk wdm nthal ntifs
  4972. IN BOOLEAN Alertable, // ntddk wdm nthal ntifs
  4973. IN PLARGE_INTEGER Interval // ntddk wdm nthal ntifs
  4974. ); // ntddk wdm nthal ntifs
  4975. // ntddk wdm nthal ntifs
  4976. VOID
  4977. KeRevertToUserAffinityThread (
  4978. VOID
  4979. );
  4980. VOID
  4981. KeSetSystemAffinityThread (
  4982. IN KAFFINITY Affinity
  4983. );
  4984. NTKERNELAPI
  4985. BOOLEAN
  4986. KeSetKernelStackSwapEnable (
  4987. IN BOOLEAN Enable
  4988. );
  4989. // end_ntifs
  4990. NTKERNELAPI // ntddk wdm nthal ntifs
  4991. KPRIORITY // ntddk wdm nthal ntifs
  4992. KeSetPriorityThread ( // ntddk wdm nthal ntifs
  4993. IN PKTHREAD Thread, // ntddk wdm nthal ntifs
  4994. IN KPRIORITY Priority // ntddk wdm nthal ntifs
  4995. ); // ntddk wdm nthal ntifs
  4996. // ntddk wdm nthal ntifs
  4997. #if ((defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_) ||defined(_NTHAL_)) && !defined(_NTSYSTEM_DRIVER_) || defined(_NTOSP_))
  4998. // begin_wdm
  4999. NTKERNELAPI
  5000. VOID
  5001. KeEnterCriticalRegion (
  5002. VOID
  5003. );
  5004. NTKERNELAPI
  5005. VOID
  5006. KeLeaveCriticalRegion (
  5007. VOID
  5008. );
  5009. NTKERNELAPI
  5010. BOOLEAN
  5011. KeAreApcsDisabled(
  5012. VOID
  5013. );
  5014. // end_wdm
  5015. #else
  5016. //++
  5017. //
  5018. // VOID
  5019. // KeEnterCriticalRegion (
  5020. // VOID
  5021. // )
  5022. //
  5023. //
  5024. // Routine Description:
  5025. //
  5026. // This function disables kernel APC's.
  5027. //
  5028. // N.B. The following code does not require any interlocks. There are
  5029. // two cases of interest: 1) On an MP system, the thread cannot
  5030. // be running on two processors as once, and 2) if the thread is
  5031. // is interrupted to deliver a kernel mode APC which also calls
  5032. // this routine, the values read and stored will stack and unstack
  5033. // properly.
  5034. //
  5035. // Arguments:
  5036. //
  5037. // None.
  5038. //
  5039. // Return Value:
  5040. //
  5041. // None.
  5042. //--
  5043. #define KeEnterCriticalRegion() KeGetCurrentThread()->KernelApcDisable -= 1
  5044. //++
  5045. //
  5046. // VOID
  5047. // KeEnterCriticalRegionThread (
  5048. // PKTHREAD CurrentThread
  5049. // )
  5050. //
  5051. //
  5052. // Routine Description:
  5053. //
  5054. // This function disables kernel APC's for the current thread only.
  5055. //
  5056. // N.B. The following code does not require any interlocks. There are
  5057. // two cases of interest: 1) On an MP system, the thread cannot
  5058. // be running on two processors as once, and 2) if the thread is
  5059. // is interrupted to deliver a kernel mode APC which also calls
  5060. // this routine, the values read and stored will stack and unstack
  5061. // properly.
  5062. //
  5063. // Arguments:
  5064. //
  5065. // CurrentThread - Current thread thats executing. This must be the
  5066. // current thread.
  5067. //
  5068. // Return Value:
  5069. //
  5070. // None.
  5071. //--
  5072. #define KeEnterCriticalRegionThread(CurrentThread) { \
  5073. ASSERT (CurrentThread == KeGetCurrentThread ()); \
  5074. (CurrentThread)->KernelApcDisable -= 1; \
  5075. }
  5076. //++
  5077. //
  5078. // VOID
  5079. // KeLeaveCriticalRegion (
  5080. // VOID
  5081. // )
  5082. //
  5083. //
  5084. // Routine Description:
  5085. //
  5086. // This function enables kernel APC's.
  5087. //
  5088. // N.B. The following code does not require any interlocks. There are
  5089. // two cases of interest: 1) On an MP system, the thread cannot
  5090. // be running on two processors as once, and 2) if the thread is
  5091. // is interrupted to deliver a kernel mode APC which also calls
  5092. // this routine, the values read and stored will stack and unstack
  5093. // properly.
  5094. //
  5095. // Arguments:
  5096. //
  5097. // None.
  5098. //
  5099. // Return Value:
  5100. //
  5101. // None.
  5102. //--
  5103. #define KeLeaveCriticalRegion() KiLeaveCriticalRegion()
  5104. //++
  5105. //
  5106. // VOID
  5107. // KeLeaveCriticalRegionThread (
  5108. // PKTHREAD CurrentThread
  5109. // )
  5110. //
  5111. //
  5112. // Routine Description:
  5113. //
  5114. // This function enables kernel APC's for the current thread.
  5115. //
  5116. // N.B. The following code does not require any interlocks. There are
  5117. // two cases of interest: 1) On an MP system, the thread cannot
  5118. // be running on two processors as once, and 2) if the thread is
  5119. // is interrupted to deliver a kernel mode APC which also calls
  5120. // this routine, the values read and stored will stack and unstack
  5121. // properly.
  5122. //
  5123. // Arguments:
  5124. //
  5125. // CurrentThread - Current thread thats executing. This must be the
  5126. // current thread.
  5127. //
  5128. // Return Value:
  5129. //
  5130. // None.
  5131. //--
  5132. #define KeLeaveCriticalRegionThread(CurrentThread) { \
  5133. ASSERT (CurrentThread == KeGetCurrentThread ()); \
  5134. KiLeaveCriticalRegionThread(CurrentThread); \
  5135. }
  5136. #define KeAreApcsDisabled() (KeGetCurrentThread()->KernelApcDisable != 0);
  5137. //++
  5138. //
  5139. // KPROCESSOR_MODE
  5140. // KeGetPReviousMode (
  5141. // VOID
  5142. // )
  5143. //
  5144. //
  5145. // Routine Description:
  5146. //
  5147. // This function gets the threads previous mode from the trap frame
  5148. //
  5149. //
  5150. // Arguments:
  5151. //
  5152. // None.
  5153. //
  5154. // Return Value:
  5155. //
  5156. // KPROCESSOR_MODE - Previous mode for this thread
  5157. //--
  5158. #define KeGetPreviousMode() (KeGetCurrentThread()->PreviousMode)
  5159. //++
  5160. //
  5161. // KPROCESSOR_MODE
  5162. // KeGetPReviousModeByThread (
  5163. // PKTHREAD xxCurrentThread
  5164. // )
  5165. //
  5166. //
  5167. // Routine Description:
  5168. //
  5169. // This function gets the threads previous mode from the trap frame.
  5170. //
  5171. //
  5172. // Arguments:
  5173. //
  5174. // xxCurrentThread - Current thread. This can not be a cross thread reference
  5175. //
  5176. // Return Value:
  5177. //
  5178. // KPROCESSOR_MODE - Previous mode for this thread
  5179. //--
  5180. #define KeGetPreviousModeByThread(xxCurrentThread) (ASSERT (xxCurrentThread == KeGetCurrentThread ()),\
  5181. (xxCurrentThread)->PreviousMode)
  5182. #endif
  5183. // begin_wdm
  5184. //
  5185. // Timer object
  5186. //
  5187. NTKERNELAPI
  5188. VOID
  5189. KeInitializeTimer (
  5190. IN PKTIMER Timer
  5191. );
  5192. NTKERNELAPI
  5193. VOID
  5194. KeInitializeTimerEx (
  5195. IN PKTIMER Timer,
  5196. IN TIMER_TYPE Type
  5197. );
  5198. NTKERNELAPI
  5199. BOOLEAN
  5200. KeCancelTimer (
  5201. IN PKTIMER
  5202. );
  5203. NTKERNELAPI
  5204. BOOLEAN
  5205. KeReadStateTimer (
  5206. PKTIMER Timer
  5207. );
  5208. NTKERNELAPI
  5209. BOOLEAN
  5210. KeSetTimer (
  5211. IN PKTIMER Timer,
  5212. IN LARGE_INTEGER DueTime,
  5213. IN PKDPC Dpc OPTIONAL
  5214. );
  5215. NTKERNELAPI
  5216. BOOLEAN
  5217. KeSetTimerEx (
  5218. IN PKTIMER Timer,
  5219. IN LARGE_INTEGER DueTime,
  5220. IN LONG Period OPTIONAL,
  5221. IN PKDPC Dpc OPTIONAL
  5222. );
  5223. #define KeWaitForMutexObject KeWaitForSingleObject
  5224. NTKERNELAPI
  5225. NTSTATUS
  5226. KeWaitForMultipleObjects (
  5227. IN ULONG Count,
  5228. IN PVOID Object[],
  5229. IN WAIT_TYPE WaitType,
  5230. IN KWAIT_REASON WaitReason,
  5231. IN KPROCESSOR_MODE WaitMode,
  5232. IN BOOLEAN Alertable,
  5233. IN PLARGE_INTEGER Timeout OPTIONAL,
  5234. IN PKWAIT_BLOCK WaitBlockArray OPTIONAL
  5235. );
  5236. NTKERNELAPI
  5237. NTSTATUS
  5238. KeWaitForSingleObject (
  5239. IN PVOID Object,
  5240. IN KWAIT_REASON WaitReason,
  5241. IN KPROCESSOR_MODE WaitMode,
  5242. IN BOOLEAN Alertable,
  5243. IN PLARGE_INTEGER Timeout OPTIONAL
  5244. );
  5245. //
  5246. // On X86 the following routines are defined in the HAL and imported by
  5247. // all other modules.
  5248. //
  5249. #if defined(_X86_) && !defined(_NTHAL_)
  5250. #define _DECL_HAL_KE_IMPORT __declspec(dllimport)
  5251. #else
  5252. #define _DECL_HAL_KE_IMPORT
  5253. #endif
  5254. _DECL_HAL_KE_IMPORT
  5255. KIRQL
  5256. FASTCALL
  5257. KeAcquireQueuedSpinLock (
  5258. IN KSPIN_LOCK_QUEUE_NUMBER Number
  5259. );
  5260. _DECL_HAL_KE_IMPORT
  5261. VOID
  5262. FASTCALL
  5263. KeReleaseQueuedSpinLock (
  5264. IN KSPIN_LOCK_QUEUE_NUMBER Number,
  5265. IN KIRQL OldIrql
  5266. );
  5267. _DECL_HAL_KE_IMPORT
  5268. LOGICAL
  5269. FASTCALL
  5270. KeTryToAcquireQueuedSpinLock(
  5271. IN KSPIN_LOCK_QUEUE_NUMBER Number,
  5272. IN PKIRQL OldIrql
  5273. );
  5274. //
  5275. // spin lock functions
  5276. //
  5277. NTKERNELAPI
  5278. VOID
  5279. NTAPI
  5280. KeInitializeSpinLock (
  5281. IN PKSPIN_LOCK SpinLock
  5282. );
  5283. #if defined(_X86_)
  5284. NTKERNELAPI
  5285. VOID
  5286. FASTCALL
  5287. KefAcquireSpinLockAtDpcLevel (
  5288. IN PKSPIN_LOCK SpinLock
  5289. );
  5290. NTKERNELAPI
  5291. VOID
  5292. FASTCALL
  5293. KefReleaseSpinLockFromDpcLevel (
  5294. IN PKSPIN_LOCK SpinLock
  5295. );
  5296. #define KeAcquireSpinLockAtDpcLevel(a) KefAcquireSpinLockAtDpcLevel(a)
  5297. #define KeReleaseSpinLockFromDpcLevel(a) KefReleaseSpinLockFromDpcLevel(a)
  5298. _DECL_HAL_KE_IMPORT
  5299. KIRQL
  5300. FASTCALL
  5301. KfAcquireSpinLock (
  5302. IN PKSPIN_LOCK SpinLock
  5303. );
  5304. _DECL_HAL_KE_IMPORT
  5305. VOID
  5306. FASTCALL
  5307. KfReleaseSpinLock (
  5308. IN PKSPIN_LOCK SpinLock,
  5309. IN KIRQL NewIrql
  5310. );
  5311. // end_wdm
  5312. _DECL_HAL_KE_IMPORT
  5313. KIRQL
  5314. FASTCALL
  5315. KeAcquireSpinLockRaiseToSynch (
  5316. IN PKSPIN_LOCK SpinLock
  5317. );
  5318. // begin_wdm
  5319. #define KeAcquireSpinLock(a,b) *(b) = KfAcquireSpinLock(a)
  5320. #define KeReleaseSpinLock(a,b) KfReleaseSpinLock(a,b)
  5321. #else
  5322. NTKERNELAPI
  5323. KIRQL
  5324. FASTCALL
  5325. KeAcquireSpinLockRaiseToSynch (
  5326. IN PKSPIN_LOCK SpinLock
  5327. );
  5328. NTKERNELAPI
  5329. VOID
  5330. KeAcquireSpinLockAtDpcLevel (
  5331. IN PKSPIN_LOCK SpinLock
  5332. );
  5333. NTKERNELAPI
  5334. VOID
  5335. KeReleaseSpinLockFromDpcLevel (
  5336. IN PKSPIN_LOCK SpinLock
  5337. );
  5338. NTKERNELAPI
  5339. KIRQL
  5340. KeAcquireSpinLockRaiseToDpc (
  5341. IN PKSPIN_LOCK SpinLock
  5342. );
  5343. #define KeAcquireSpinLock(SpinLock, OldIrql) \
  5344. *(OldIrql) = KeAcquireSpinLockRaiseToDpc(SpinLock)
  5345. NTKERNELAPI
  5346. VOID
  5347. KeReleaseSpinLock (
  5348. IN PKSPIN_LOCK SpinLock,
  5349. IN KIRQL NewIrql
  5350. );
  5351. #endif
  5352. NTKERNELAPI
  5353. BOOLEAN
  5354. FASTCALL
  5355. KeTryToAcquireSpinLockAtDpcLevel (
  5356. IN PKSPIN_LOCK SpinLock
  5357. );
  5358. #if defined(_X86_)
  5359. _DECL_HAL_KE_IMPORT
  5360. VOID
  5361. FASTCALL
  5362. KfLowerIrql (
  5363. IN KIRQL NewIrql
  5364. );
  5365. _DECL_HAL_KE_IMPORT
  5366. KIRQL
  5367. FASTCALL
  5368. KfRaiseIrql (
  5369. IN KIRQL NewIrql
  5370. );
  5371. // end_wdm
  5372. _DECL_HAL_KE_IMPORT
  5373. KIRQL
  5374. KeRaiseIrqlToDpcLevel(
  5375. VOID
  5376. );
  5377. _DECL_HAL_KE_IMPORT
  5378. KIRQL
  5379. KeRaiseIrqlToSynchLevel(
  5380. VOID
  5381. );
  5382. // begin_wdm
  5383. #define KeLowerIrql(a) KfLowerIrql(a)
  5384. #define KeRaiseIrql(a,b) *(b) = KfRaiseIrql(a)
  5385. // end_wdm
  5386. // begin_wdm
  5387. #elif defined(_ALPHA_)
  5388. #define KeLowerIrql(a) __swpirql(a)
  5389. #define KeRaiseIrql(a,b) *(b) = __swpirql(a)
  5390. // end_wdm
  5391. extern ULONG KiSynchIrql;
  5392. #define KfRaiseIrql(a) __swpirql(a)
  5393. #define KeRaiseIrqlToDpcLevel() __swpirql(DISPATCH_LEVEL)
  5394. #define KeRaiseIrqlToSynchLevel() __swpirql((UCHAR)KiSynchIrql)
  5395. // begin_wdm
  5396. #elif defined(_IA64_)
  5397. VOID
  5398. KeLowerIrql (
  5399. IN KIRQL NewIrql
  5400. );
  5401. VOID
  5402. KeRaiseIrql (
  5403. IN KIRQL NewIrql,
  5404. OUT PKIRQL OldIrql
  5405. );
  5406. // end_wdm
  5407. KIRQL
  5408. KfRaiseIrql (
  5409. IN KIRQL NewIrql
  5410. );
  5411. KIRQL
  5412. KeRaiseIrqlToDpcLevel (
  5413. VOID
  5414. );
  5415. KIRQL
  5416. KeRaiseIrqlToSynchLevel (
  5417. VOID
  5418. );
  5419. // begin_wdm
  5420. #elif defined(_AMD64_)
  5421. //
  5422. // These function are defined in amd64.h for the AMD64 platform.
  5423. //
  5424. #else
  5425. #error "no target architecture"
  5426. #endif
  5427. //
  5428. // Queued spin lock functions for "in stack" lock handles.
  5429. //
  5430. // The following three functions RAISE and LOWER IRQL when a queued
  5431. // in stack spin lock is acquired or released using these routines.
  5432. //
  5433. _DECL_HAL_KE_IMPORT
  5434. VOID
  5435. FASTCALL
  5436. KeAcquireInStackQueuedSpinLock (
  5437. IN PKSPIN_LOCK SpinLock,
  5438. IN PKLOCK_QUEUE_HANDLE LockHandle
  5439. );
  5440. _DECL_HAL_KE_IMPORT
  5441. VOID
  5442. FASTCALL
  5443. KeReleaseInStackQueuedSpinLock (
  5444. IN PKLOCK_QUEUE_HANDLE LockHandle
  5445. );
  5446. //
  5447. // The following two functions do NOT raise or lower IRQL when a queued
  5448. // in stack spin lock is acquired or released using these functions.
  5449. //
  5450. NTKERNELAPI
  5451. VOID
  5452. FASTCALL
  5453. KeAcquireInStackQueuedSpinLockAtDpcLevel (
  5454. IN PKSPIN_LOCK SpinLock,
  5455. IN PKLOCK_QUEUE_HANDLE LockHandle
  5456. );
  5457. NTKERNELAPI
  5458. VOID
  5459. FASTCALL
  5460. KeReleaseInStackQueuedSpinLockFromDpcLevel (
  5461. IN PKLOCK_QUEUE_HANDLE LockHandle
  5462. );
  5463. //
  5464. // Miscellaneous kernel functions
  5465. //
  5466. typedef enum _KBUGCHECK_BUFFER_DUMP_STATE {
  5467. BufferEmpty,
  5468. BufferInserted,
  5469. BufferStarted,
  5470. BufferFinished,
  5471. BufferIncomplete
  5472. } KBUGCHECK_BUFFER_DUMP_STATE;
  5473. typedef
  5474. VOID
  5475. (*PKBUGCHECK_CALLBACK_ROUTINE) (
  5476. IN PVOID Buffer,
  5477. IN ULONG Length
  5478. );
  5479. typedef struct _KBUGCHECK_CALLBACK_RECORD {
  5480. LIST_ENTRY Entry;
  5481. PKBUGCHECK_CALLBACK_ROUTINE CallbackRoutine;
  5482. PVOID Buffer;
  5483. ULONG Length;
  5484. PUCHAR Component;
  5485. ULONG_PTR Checksum;
  5486. UCHAR State;
  5487. } KBUGCHECK_CALLBACK_RECORD, *PKBUGCHECK_CALLBACK_RECORD;
  5488. #define KeInitializeCallbackRecord(CallbackRecord) \
  5489. (CallbackRecord)->State = BufferEmpty
  5490. NTKERNELAPI
  5491. BOOLEAN
  5492. KeDeregisterBugCheckCallback (
  5493. IN PKBUGCHECK_CALLBACK_RECORD CallbackRecord
  5494. );
  5495. NTKERNELAPI
  5496. BOOLEAN
  5497. KeRegisterBugCheckCallback (
  5498. IN PKBUGCHECK_CALLBACK_RECORD CallbackRecord,
  5499. IN PKBUGCHECK_CALLBACK_ROUTINE CallbackRoutine,
  5500. IN PVOID Buffer,
  5501. IN ULONG Length,
  5502. IN PUCHAR Component
  5503. );
  5504. typedef enum _KBUGCHECK_CALLBACK_REASON {
  5505. KbCallbackInvalid,
  5506. KbCallbackReserved1,
  5507. KbCallbackSecondaryDumpData,
  5508. KbCallbackDumpIo,
  5509. } KBUGCHECK_CALLBACK_REASON;
  5510. typedef
  5511. VOID
  5512. (*PKBUGCHECK_REASON_CALLBACK_ROUTINE) (
  5513. IN KBUGCHECK_CALLBACK_REASON Reason,
  5514. IN struct _KBUGCHECK_REASON_CALLBACK_RECORD* Record,
  5515. IN OUT PVOID ReasonSpecificData,
  5516. IN ULONG ReasonSpecificDataLength
  5517. );
  5518. typedef struct _KBUGCHECK_REASON_CALLBACK_RECORD {
  5519. LIST_ENTRY Entry;
  5520. PKBUGCHECK_REASON_CALLBACK_ROUTINE CallbackRoutine;
  5521. PUCHAR Component;
  5522. ULONG_PTR Checksum;
  5523. KBUGCHECK_CALLBACK_REASON Reason;
  5524. UCHAR State;
  5525. } KBUGCHECK_REASON_CALLBACK_RECORD, *PKBUGCHECK_REASON_CALLBACK_RECORD;
  5526. typedef struct _KBUGCHECK_SECONDARY_DUMP_DATA {
  5527. IN PVOID InBuffer;
  5528. IN ULONG InBufferLength;
  5529. IN ULONG MaximumAllowed;
  5530. OUT GUID Guid;
  5531. OUT PVOID OutBuffer;
  5532. OUT ULONG OutBufferLength;
  5533. } KBUGCHECK_SECONDARY_DUMP_DATA, *PKBUGCHECK_SECONDARY_DUMP_DATA;
  5534. typedef enum _KBUGCHECK_DUMP_IO_TYPE
  5535. {
  5536. KbDumpIoInvalid,
  5537. KbDumpIoHeader,
  5538. KbDumpIoBody,
  5539. KbDumpIoSecondaryData,
  5540. KbDumpIoComplete
  5541. } KBUGCHECK_DUMP_IO_TYPE;
  5542. typedef struct _KBUGCHECK_DUMP_IO {
  5543. IN ULONG64 Offset;
  5544. IN PVOID Buffer;
  5545. IN ULONG BufferLength;
  5546. IN KBUGCHECK_DUMP_IO_TYPE Type;
  5547. } KBUGCHECK_DUMP_IO, *PKBUGCHECK_DUMP_IO;
  5548. NTKERNELAPI
  5549. BOOLEAN
  5550. KeDeregisterBugCheckReasonCallback (
  5551. IN PKBUGCHECK_REASON_CALLBACK_RECORD CallbackRecord
  5552. );
  5553. NTKERNELAPI
  5554. BOOLEAN
  5555. KeRegisterBugCheckReasonCallback (
  5556. IN PKBUGCHECK_REASON_CALLBACK_RECORD CallbackRecord,
  5557. IN PKBUGCHECK_REASON_CALLBACK_ROUTINE CallbackRoutine,
  5558. IN KBUGCHECK_CALLBACK_REASON Reason,
  5559. IN PUCHAR Component
  5560. );
  5561. // end_wdm
  5562. NTKERNELAPI
  5563. DECLSPEC_NORETURN
  5564. VOID
  5565. NTAPI
  5566. KeBugCheck (
  5567. IN ULONG BugCheckCode
  5568. );
  5569. NTKERNELAPI
  5570. DECLSPEC_NORETURN
  5571. VOID
  5572. KeBugCheckEx(
  5573. IN ULONG BugCheckCode,
  5574. IN ULONG_PTR BugCheckParameter1,
  5575. IN ULONG_PTR BugCheckParameter2,
  5576. IN ULONG_PTR BugCheckParameter3,
  5577. IN ULONG_PTR BugCheckParameter4
  5578. );
  5579. #define WIN32K_SERVICE_INDEX 1
  5580. #define IIS_SERVICE_INDEX 2
  5581. NTKERNELAPI
  5582. BOOLEAN
  5583. KeAddSystemServiceTable(
  5584. IN PULONG_PTR Base,
  5585. IN PULONG Count OPTIONAL,
  5586. IN ULONG Limit,
  5587. IN PUCHAR Number,
  5588. IN ULONG Index
  5589. );
  5590. NTKERNELAPI
  5591. BOOLEAN
  5592. KeRemoveSystemServiceTable(
  5593. IN ULONG Index
  5594. );
  5595. NTKERNELAPI
  5596. ULONGLONG
  5597. KeQueryInterruptTime (
  5598. VOID
  5599. );
  5600. NTKERNELAPI
  5601. VOID
  5602. KeQuerySystemTime (
  5603. OUT PLARGE_INTEGER CurrentTime
  5604. );
  5605. NTKERNELAPI
  5606. ULONG
  5607. KeQueryTimeIncrement (
  5608. VOID
  5609. );
  5610. NTKERNELAPI
  5611. ULONG
  5612. KeGetRecommendedSharedDataAlignment (
  5613. VOID
  5614. );
  5615. // end_wdm
  5616. NTKERNELAPI
  5617. KAFFINITY
  5618. KeQueryActiveProcessors (
  5619. VOID
  5620. );
  5621. //
  5622. // Define the firmware routine types
  5623. //
  5624. typedef enum _FIRMWARE_REENTRY {
  5625. HalHaltRoutine,
  5626. HalPowerDownRoutine,
  5627. HalRestartRoutine,
  5628. HalRebootRoutine,
  5629. HalInteractiveModeRoutine,
  5630. HalMaximumRoutine
  5631. } FIRMWARE_REENTRY, *PFIRMWARE_REENTRY;
  5632. NTKERNELAPI
  5633. NTSTATUS
  5634. KeUserModeCallback (
  5635. IN ULONG ApiNumber,
  5636. IN PVOID InputBuffer,
  5637. IN ULONG InputLength,
  5638. OUT PVOID *OutputBuffer,
  5639. OUT PULONG OutputLength
  5640. );
  5641. //
  5642. // Time update notify routine.
  5643. //
  5644. typedef
  5645. VOID
  5646. (FASTCALL *PTIME_UPDATE_NOTIFY_ROUTINE)(
  5647. IN HANDLE ThreadId,
  5648. IN KPROCESSOR_MODE Mode
  5649. );
  5650. NTKERNELAPI
  5651. VOID
  5652. FASTCALL
  5653. KeSetTimeUpdateNotifyRoutine(
  5654. IN PTIME_UPDATE_NOTIFY_ROUTINE NotifyRoutine
  5655. );
  5656. extern PLOADER_PARAMETER_BLOCK KeLoaderBlock;
  5657. extern NTSYSAPI CCHAR KeNumberProcessors;
  5658. #if defined(_AMD64_) || defined(_ALPHA_) || defined(_IA64_)
  5659. extern volatile LARGE_INTEGER KeTickCount;
  5660. #else
  5661. extern volatile KSYSTEM_TIME KeTickCount;
  5662. #endif
  5663. typedef enum _MEMORY_CACHING_TYPE_ORIG {
  5664. MmFrameBufferCached = 2
  5665. } MEMORY_CACHING_TYPE_ORIG;
  5666. typedef enum _MEMORY_CACHING_TYPE {
  5667. MmNonCached = FALSE,
  5668. MmCached = TRUE,
  5669. MmWriteCombined = MmFrameBufferCached,
  5670. MmHardwareCoherentCached,
  5671. MmNonCachedUnordered, // IA64
  5672. MmUSWCCached,
  5673. MmMaximumCacheType
  5674. } MEMORY_CACHING_TYPE;
  5675. //
  5676. // Pool Allocation routines (in pool.c)
  5677. //
  5678. typedef enum _POOL_TYPE {
  5679. NonPagedPool,
  5680. PagedPool,
  5681. NonPagedPoolMustSucceed,
  5682. DontUseThisType,
  5683. NonPagedPoolCacheAligned,
  5684. PagedPoolCacheAligned,
  5685. NonPagedPoolCacheAlignedMustS,
  5686. MaxPoolType
  5687. // end_wdm
  5688. ,
  5689. //
  5690. // Note these per session types are carefully chosen so that the appropriate
  5691. // masking still applies as well as MaxPoolType above.
  5692. //
  5693. NonPagedPoolSession = 32,
  5694. PagedPoolSession = NonPagedPoolSession + 1,
  5695. NonPagedPoolMustSucceedSession = PagedPoolSession + 1,
  5696. DontUseThisTypeSession = NonPagedPoolMustSucceedSession + 1,
  5697. NonPagedPoolCacheAlignedSession = DontUseThisTypeSession + 1,
  5698. PagedPoolCacheAlignedSession = NonPagedPoolCacheAlignedSession + 1,
  5699. NonPagedPoolCacheAlignedMustSSession = PagedPoolCacheAlignedSession + 1,
  5700. // begin_wdm
  5701. } POOL_TYPE;
  5702. #define POOL_COLD_ALLOCATION 256 // Note this cannot encode into the header.
  5703. // end_ntddk end_wdm end_nthal end_ntifs end_ntndis begin_ntosp
  5704. //
  5705. // The following two definitions control the raising of exceptions on quota
  5706. // and allocation failures.
  5707. //
  5708. #define POOL_QUOTA_FAIL_INSTEAD_OF_RAISE 8
  5709. #define POOL_RAISE_IF_ALLOCATION_FAILURE 16 // ntifs
  5710. NTKERNELAPI
  5711. PVOID
  5712. ExAllocatePool(
  5713. IN POOL_TYPE PoolType,
  5714. IN SIZE_T NumberOfBytes
  5715. );
  5716. NTKERNELAPI
  5717. PVOID
  5718. ExAllocatePoolWithQuota(
  5719. IN POOL_TYPE PoolType,
  5720. IN SIZE_T NumberOfBytes
  5721. );
  5722. NTKERNELAPI
  5723. PVOID
  5724. NTAPI
  5725. ExAllocatePoolWithTag(
  5726. IN POOL_TYPE PoolType,
  5727. IN SIZE_T NumberOfBytes,
  5728. IN ULONG Tag
  5729. );
  5730. //
  5731. // _EX_POOL_PRIORITY_ provides a method for the system to handle requests
  5732. // intelligently in low resource conditions.
  5733. //
  5734. // LowPoolPriority should be used when it is acceptable to the driver for the
  5735. // mapping request to fail if the system is low on resources. An example of
  5736. // this could be for a non-critical network connection where the driver can
  5737. // handle the failure case when system resources are close to being depleted.
  5738. //
  5739. // NormalPoolPriority should be used when it is acceptable to the driver for the
  5740. // mapping request to fail if the system is very low on resources. An example
  5741. // of this could be for a non-critical local filesystem request.
  5742. //
  5743. // HighPoolPriority should be used when it is unacceptable to the driver for the
  5744. // mapping request to fail unless the system is completely out of resources.
  5745. // An example of this would be the paging file path in a driver.
  5746. //
  5747. // SpecialPool can be specified to bound the allocation at a page end (or
  5748. // beginning). This should only be done on systems being debugged as the
  5749. // memory cost is expensive.
  5750. //
  5751. // N.B. These values are very carefully chosen so that the pool allocation
  5752. // code can quickly crack the priority request.
  5753. //
  5754. typedef enum _EX_POOL_PRIORITY {
  5755. LowPoolPriority,
  5756. LowPoolPrioritySpecialPoolOverrun = 8,
  5757. LowPoolPrioritySpecialPoolUnderrun = 9,
  5758. NormalPoolPriority = 16,
  5759. NormalPoolPrioritySpecialPoolOverrun = 24,
  5760. NormalPoolPrioritySpecialPoolUnderrun = 25,
  5761. HighPoolPriority = 32,
  5762. HighPoolPrioritySpecialPoolOverrun = 40,
  5763. HighPoolPrioritySpecialPoolUnderrun = 41
  5764. } EX_POOL_PRIORITY;
  5765. NTKERNELAPI
  5766. PVOID
  5767. NTAPI
  5768. ExAllocatePoolWithTagPriority(
  5769. IN POOL_TYPE PoolType,
  5770. IN SIZE_T NumberOfBytes,
  5771. IN ULONG Tag,
  5772. IN EX_POOL_PRIORITY Priority
  5773. );
  5774. #ifndef POOL_TAGGING
  5775. #define ExAllocatePoolWithTag(a,b,c) ExAllocatePool(a,b)
  5776. #endif //POOL_TAGGING
  5777. NTKERNELAPI
  5778. PVOID
  5779. ExAllocatePoolWithQuotaTag(
  5780. IN POOL_TYPE PoolType,
  5781. IN SIZE_T NumberOfBytes,
  5782. IN ULONG Tag
  5783. );
  5784. #ifndef POOL_TAGGING
  5785. #define ExAllocatePoolWithQuotaTag(a,b,c) ExAllocatePoolWithQuota(a,b)
  5786. #endif //POOL_TAGGING
  5787. NTKERNELAPI
  5788. VOID
  5789. NTAPI
  5790. ExFreePool(
  5791. IN PVOID P
  5792. );
  5793. // end_wdm
  5794. #if defined(POOL_TAGGING)
  5795. #define ExFreePool(a) ExFreePoolWithTag(a,0)
  5796. #endif
  5797. //
  5798. // If high order bit in Pool tag is set, then must use ExFreePoolWithTag to free
  5799. //
  5800. #define PROTECTED_POOL 0x80000000
  5801. // begin_wdm
  5802. NTKERNELAPI
  5803. VOID
  5804. ExFreePoolWithTag(
  5805. IN PVOID P,
  5806. IN ULONG Tag
  5807. );
  5808. // end_ntddk end_wdm end_nthal end_ntifs
  5809. #ifndef POOL_TAGGING
  5810. #define ExFreePoolWithTag(a,b) ExFreePool(a)
  5811. #endif //POOL_TAGGING
  5812. NTKERNELAPI // ntifs
  5813. SIZE_T // ntifs
  5814. ExQueryPoolBlockSize ( // ntifs
  5815. IN PVOID PoolBlock, // ntifs
  5816. OUT PBOOLEAN QuotaCharged // ntifs
  5817. ); // ntifs
  5818. //
  5819. // Routines to support fast mutexes.
  5820. //
  5821. typedef struct _FAST_MUTEX {
  5822. LONG Count;
  5823. PKTHREAD Owner;
  5824. ULONG Contention;
  5825. KEVENT Event;
  5826. ULONG OldIrql;
  5827. } FAST_MUTEX, *PFAST_MUTEX;
  5828. #define ExInitializeFastMutex(_FastMutex) \
  5829. (_FastMutex)->Count = 1; \
  5830. (_FastMutex)->Owner = NULL; \
  5831. (_FastMutex)->Contention = 0; \
  5832. KeInitializeEvent(&(_FastMutex)->Event, \
  5833. SynchronizationEvent, \
  5834. FALSE);
  5835. NTKERNELAPI
  5836. VOID
  5837. FASTCALL
  5838. ExAcquireFastMutexUnsafe (
  5839. IN PFAST_MUTEX FastMutex
  5840. );
  5841. NTKERNELAPI
  5842. VOID
  5843. FASTCALL
  5844. ExReleaseFastMutexUnsafe (
  5845. IN PFAST_MUTEX FastMutex
  5846. );
  5847. #if defined(_ALPHA_) || defined(_IA64_) || defined(_AMD64_)
  5848. NTKERNELAPI
  5849. VOID
  5850. FASTCALL
  5851. ExAcquireFastMutex (
  5852. IN PFAST_MUTEX FastMutex
  5853. );
  5854. NTKERNELAPI
  5855. VOID
  5856. FASTCALL
  5857. ExReleaseFastMutex (
  5858. IN PFAST_MUTEX FastMutex
  5859. );
  5860. NTKERNELAPI
  5861. BOOLEAN
  5862. FASTCALL
  5863. ExTryToAcquireFastMutex (
  5864. IN PFAST_MUTEX FastMutex
  5865. );
  5866. #elif defined(_X86_)
  5867. NTHALAPI
  5868. VOID
  5869. FASTCALL
  5870. ExAcquireFastMutex (
  5871. IN PFAST_MUTEX FastMutex
  5872. );
  5873. NTHALAPI
  5874. VOID
  5875. FASTCALL
  5876. ExReleaseFastMutex (
  5877. IN PFAST_MUTEX FastMutex
  5878. );
  5879. NTHALAPI
  5880. BOOLEAN
  5881. FASTCALL
  5882. ExTryToAcquireFastMutex (
  5883. IN PFAST_MUTEX FastMutex
  5884. );
  5885. #else
  5886. #error "Target architecture not defined"
  5887. #endif
  5888. //
  5889. NTKERNELAPI
  5890. VOID
  5891. FASTCALL
  5892. ExInterlockedAddLargeStatistic (
  5893. IN PLARGE_INTEGER Addend,
  5894. IN ULONG Increment
  5895. );
  5896. // end_ntndis
  5897. NTKERNELAPI
  5898. LARGE_INTEGER
  5899. ExInterlockedAddLargeInteger (
  5900. IN PLARGE_INTEGER Addend,
  5901. IN LARGE_INTEGER Increment,
  5902. IN PKSPIN_LOCK Lock
  5903. );
  5904. NTKERNELAPI
  5905. ULONG
  5906. FASTCALL
  5907. ExInterlockedAddUlong (
  5908. IN PULONG Addend,
  5909. IN ULONG Increment,
  5910. IN PKSPIN_LOCK Lock
  5911. );
  5912. #if defined(_AMD64_) || defined(_AXP64_) || defined(_IA64_)
  5913. #define ExInterlockedCompareExchange64(Destination, Exchange, Comperand, Lock) \
  5914. InterlockedCompareExchange64(Destination, *(Exchange), *(Comperand))
  5915. #elif defined(_ALPHA_)
  5916. #define ExInterlockedCompareExchange64(Destination, Exchange, Comperand, Lock) \
  5917. ExpInterlockedCompareExchange64(Destination, Exchange, Comperand)
  5918. #else
  5919. #define ExInterlockedCompareExchange64(Destination, Exchange, Comperand, Lock) \
  5920. ExfInterlockedCompareExchange64(Destination, Exchange, Comperand)
  5921. #endif
  5922. NTKERNELAPI
  5923. PLIST_ENTRY
  5924. FASTCALL
  5925. ExInterlockedInsertHeadList (
  5926. IN PLIST_ENTRY ListHead,
  5927. IN PLIST_ENTRY ListEntry,
  5928. IN PKSPIN_LOCK Lock
  5929. );
  5930. NTKERNELAPI
  5931. PLIST_ENTRY
  5932. FASTCALL
  5933. ExInterlockedInsertTailList (
  5934. IN PLIST_ENTRY ListHead,
  5935. IN PLIST_ENTRY ListEntry,
  5936. IN PKSPIN_LOCK Lock
  5937. );
  5938. NTKERNELAPI
  5939. PLIST_ENTRY
  5940. FASTCALL
  5941. ExInterlockedRemoveHeadList (
  5942. IN PLIST_ENTRY ListHead,
  5943. IN PKSPIN_LOCK Lock
  5944. );
  5945. NTKERNELAPI
  5946. PSINGLE_LIST_ENTRY
  5947. FASTCALL
  5948. ExInterlockedPopEntryList (
  5949. IN PSINGLE_LIST_ENTRY ListHead,
  5950. IN PKSPIN_LOCK Lock
  5951. );
  5952. NTKERNELAPI
  5953. PSINGLE_LIST_ENTRY
  5954. FASTCALL
  5955. ExInterlockedPushEntryList (
  5956. IN PSINGLE_LIST_ENTRY ListHead,
  5957. IN PSINGLE_LIST_ENTRY ListEntry,
  5958. IN PKSPIN_LOCK Lock
  5959. );
  5960. //
  5961. // Define interlocked sequenced listhead functions.
  5962. //
  5963. // A sequenced interlocked list is a singly linked list with a header that
  5964. // contains the current depth and a sequence number. Each time an entry is
  5965. // inserted or removed from the list the depth is updated and the sequence
  5966. // number is incremented. This enables AMD64, IA64, and Pentium and later
  5967. // machines to insert and remove from the list without the use of spinlocks.
  5968. //
  5969. #if !defined(_WINBASE_)
  5970. /*++
  5971. Routine Description:
  5972. This function initializes a sequenced singly linked listhead.
  5973. Arguments:
  5974. SListHead - Supplies a pointer to a sequenced singly linked listhead.
  5975. Return Value:
  5976. None.
  5977. --*/
  5978. #if defined(_WIN64) && (defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_) || defined(_NTHAL_) || defined(_NTOSP_))
  5979. NTKERNELAPI
  5980. VOID
  5981. InitializeSListHead (
  5982. IN PSLIST_HEADER SListHead
  5983. );
  5984. #else
  5985. __inline
  5986. VOID
  5987. InitializeSListHead (
  5988. IN PSLIST_HEADER SListHead
  5989. )
  5990. {
  5991. #ifdef _WIN64
  5992. //
  5993. // Slist headers must be 16 byte aligned.
  5994. //
  5995. if ((ULONG_PTR) SListHead & 0x0f) {
  5996. DbgPrint( "InitializeSListHead unaligned Slist header. Address = %p, Caller = %p\n", SListHead, _ReturnAddress());
  5997. RtlRaiseStatus(STATUS_DATATYPE_MISALIGNMENT);
  5998. }
  5999. #endif
  6000. SListHead->Alignment = 0;
  6001. //
  6002. // For IA-64 we save the region number of the elements of the list in a
  6003. // separate field. This imposes the requirement that all elements stored
  6004. // in the list are from the same region.
  6005. #if defined(_IA64_)
  6006. SListHead->Region = (ULONG_PTR)SListHead & VRN_MASK;
  6007. #elif defined(_AMD64_)
  6008. SListHead->Region = 0;
  6009. #endif
  6010. return;
  6011. }
  6012. #endif
  6013. #endif // !defined(_WINBASE_)
  6014. #define ExInitializeSListHead InitializeSListHead
  6015. PSLIST_ENTRY
  6016. FirstEntrySList (
  6017. IN const SLIST_HEADER *SListHead
  6018. );
  6019. /*++
  6020. Routine Description:
  6021. This function queries the current number of entries contained in a
  6022. sequenced single linked list.
  6023. Arguments:
  6024. SListHead - Supplies a pointer to the sequenced listhead which is
  6025. be queried.
  6026. Return Value:
  6027. The current number of entries in the sequenced singly linked list is
  6028. returned as the function value.
  6029. --*/
  6030. #if defined(_WIN64)
  6031. #if (defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_) || defined(_NTHAL_) || defined(_NTOSP_))
  6032. NTKERNELAPI
  6033. USHORT
  6034. ExQueryDepthSList (
  6035. IN PSLIST_HEADER SListHead
  6036. );
  6037. #else
  6038. __inline
  6039. USHORT
  6040. ExQueryDepthSList (
  6041. IN PSLIST_HEADER SListHead
  6042. )
  6043. {
  6044. return (USHORT)(SListHead->Alignment & 0xffff);
  6045. }
  6046. #endif
  6047. #else
  6048. #define ExQueryDepthSList(_listhead_) (_listhead_)->Depth
  6049. #endif
  6050. #if defined(_WIN64)
  6051. #define ExInterlockedPopEntrySList(Head, Lock) \
  6052. ExpInterlockedPopEntrySList(Head)
  6053. #define ExInterlockedPushEntrySList(Head, Entry, Lock) \
  6054. ExpInterlockedPushEntrySList(Head, Entry)
  6055. #define ExInterlockedFlushSList(Head) \
  6056. ExpInterlockedFlushSList(Head)
  6057. #if !defined(_WINBASE_)
  6058. #define InterlockedPopEntrySList(Head) \
  6059. ExpInterlockedPopEntrySList(Head)
  6060. #define InterlockedPushEntrySList(Head, Entry) \
  6061. ExpInterlockedPushEntrySList(Head, Entry)
  6062. #define InterlockedFlushSList(Head) \
  6063. ExpInterlockedFlushSList(Head)
  6064. #define QueryDepthSList(Head) \
  6065. ExQueryDepthSList(Head)
  6066. #endif // !defined(_WINBASE_)
  6067. NTKERNELAPI
  6068. PSLIST_ENTRY
  6069. ExpInterlockedPopEntrySList (
  6070. IN PSLIST_HEADER ListHead
  6071. );
  6072. NTKERNELAPI
  6073. PSLIST_ENTRY
  6074. ExpInterlockedPushEntrySList (
  6075. IN PSLIST_HEADER ListHead,
  6076. IN PSLIST_ENTRY ListEntry
  6077. );
  6078. NTKERNELAPI
  6079. PSLIST_ENTRY
  6080. ExpInterlockedFlushSList (
  6081. IN PSLIST_HEADER ListHead
  6082. );
  6083. #else
  6084. #if defined(_WIN2K_COMPAT_SLIST_USAGE) && defined(_X86_)
  6085. NTKERNELAPI
  6086. PSLIST_ENTRY
  6087. FASTCALL
  6088. ExInterlockedPopEntrySList (
  6089. IN PSLIST_HEADER ListHead,
  6090. IN PKSPIN_LOCK Lock
  6091. );
  6092. NTKERNELAPI
  6093. PSLIST_ENTRY
  6094. FASTCALL
  6095. ExInterlockedPushEntrySList (
  6096. IN PSLIST_HEADER ListHead,
  6097. IN PSLIST_ENTRY ListEntry,
  6098. IN PKSPIN_LOCK Lock
  6099. );
  6100. #else
  6101. #define ExInterlockedPopEntrySList(ListHead, Lock) \
  6102. InterlockedPopEntrySList(ListHead)
  6103. #define ExInterlockedPushEntrySList(ListHead, ListEntry, Lock) \
  6104. InterlockedPushEntrySList(ListHead, ListEntry)
  6105. #endif
  6106. NTKERNELAPI
  6107. PSLIST_ENTRY
  6108. FASTCALL
  6109. ExInterlockedFlushSList (
  6110. IN PSLIST_HEADER ListHead
  6111. );
  6112. #if !defined(_WINBASE_)
  6113. NTKERNELAPI
  6114. PSLIST_ENTRY
  6115. FASTCALL
  6116. InterlockedPopEntrySList (
  6117. IN PSLIST_HEADER ListHead
  6118. );
  6119. NTKERNELAPI
  6120. PSLIST_ENTRY
  6121. FASTCALL
  6122. InterlockedPushEntrySList (
  6123. IN PSLIST_HEADER ListHead,
  6124. IN PSLIST_ENTRY ListEntry
  6125. );
  6126. #define InterlockedFlushSList(Head) \
  6127. ExInterlockedFlushSList(Head)
  6128. #define QueryDepthSList(Head) \
  6129. ExQueryDepthSList(Head)
  6130. #endif // !defined(_WINBASE_)
  6131. #endif // defined(_WIN64)
  6132. typedef
  6133. PVOID
  6134. (*PALLOCATE_FUNCTION) (
  6135. IN POOL_TYPE PoolType,
  6136. IN SIZE_T NumberOfBytes,
  6137. IN ULONG Tag
  6138. );
  6139. typedef
  6140. VOID
  6141. (*PFREE_FUNCTION) (
  6142. IN PVOID Buffer
  6143. );
  6144. #if !defined(_WIN64) && (defined(_NTDDK_) || defined(_NTIFS_) || defined(_NDIS_))
  6145. typedef struct _GENERAL_LOOKASIDE {
  6146. #else
  6147. typedef struct DECLSPEC_CACHEALIGN _GENERAL_LOOKASIDE {
  6148. #endif
  6149. SLIST_HEADER ListHead;
  6150. USHORT Depth;
  6151. USHORT MaximumDepth;
  6152. ULONG TotalAllocates;
  6153. union {
  6154. ULONG AllocateMisses;
  6155. ULONG AllocateHits;
  6156. };
  6157. ULONG TotalFrees;
  6158. union {
  6159. ULONG FreeMisses;
  6160. ULONG FreeHits;
  6161. };
  6162. POOL_TYPE Type;
  6163. ULONG Tag;
  6164. ULONG Size;
  6165. PALLOCATE_FUNCTION Allocate;
  6166. PFREE_FUNCTION Free;
  6167. LIST_ENTRY ListEntry;
  6168. ULONG LastTotalAllocates;
  6169. union {
  6170. ULONG LastAllocateMisses;
  6171. ULONG LastAllocateHits;
  6172. };
  6173. ULONG Future[2];
  6174. } GENERAL_LOOKASIDE, *PGENERAL_LOOKASIDE;
  6175. #if !defined(_WIN64) && (defined(_NTDDK_) || defined(_NTIFS_) || defined(_NDIS_))
  6176. typedef struct _NPAGED_LOOKASIDE_LIST {
  6177. #else
  6178. typedef struct DECLSPEC_CACHEALIGN _NPAGED_LOOKASIDE_LIST {
  6179. #endif
  6180. GENERAL_LOOKASIDE L;
  6181. #if !defined(_AMD64_) && !defined(_IA64_)
  6182. KSPIN_LOCK Lock__ObsoleteButDoNotDelete;
  6183. #endif
  6184. } NPAGED_LOOKASIDE_LIST, *PNPAGED_LOOKASIDE_LIST;
  6185. NTKERNELAPI
  6186. VOID
  6187. ExInitializeNPagedLookasideList (
  6188. IN PNPAGED_LOOKASIDE_LIST Lookaside,
  6189. IN PALLOCATE_FUNCTION Allocate,
  6190. IN PFREE_FUNCTION Free,
  6191. IN ULONG Flags,
  6192. IN SIZE_T Size,
  6193. IN ULONG Tag,
  6194. IN USHORT Depth
  6195. );
  6196. NTKERNELAPI
  6197. VOID
  6198. ExDeleteNPagedLookasideList (
  6199. IN PNPAGED_LOOKASIDE_LIST Lookaside
  6200. );
  6201. __inline
  6202. PVOID
  6203. ExAllocateFromNPagedLookasideList(
  6204. IN PNPAGED_LOOKASIDE_LIST Lookaside
  6205. )
  6206. /*++
  6207. Routine Description:
  6208. This function removes (pops) the first entry from the specified
  6209. nonpaged lookaside list.
  6210. Arguments:
  6211. Lookaside - Supplies a pointer to a nonpaged lookaside list structure.
  6212. Return Value:
  6213. If an entry is removed from the specified lookaside list, then the
  6214. address of the entry is returned as the function value. Otherwise,
  6215. NULL is returned.
  6216. --*/
  6217. {
  6218. PVOID Entry;
  6219. Lookaside->L.TotalAllocates += 1;
  6220. #if defined(_WIN2K_COMPAT_SLIST_USAGE) && defined(_X86_)
  6221. Entry = ExInterlockedPopEntrySList(&Lookaside->L.ListHead,
  6222. &Lookaside->Lock__ObsoleteButDoNotDelete);
  6223. #else
  6224. Entry = InterlockedPopEntrySList(&Lookaside->L.ListHead);
  6225. #endif
  6226. if (Entry == NULL) {
  6227. Lookaside->L.AllocateMisses += 1;
  6228. Entry = (Lookaside->L.Allocate)(Lookaside->L.Type,
  6229. Lookaside->L.Size,
  6230. Lookaside->L.Tag);
  6231. }
  6232. return Entry;
  6233. }
  6234. __inline
  6235. VOID
  6236. ExFreeToNPagedLookasideList(
  6237. IN PNPAGED_LOOKASIDE_LIST Lookaside,
  6238. IN PVOID Entry
  6239. )
  6240. /*++
  6241. Routine Description:
  6242. This function inserts (pushes) the specified entry into the specified
  6243. nonpaged lookaside list.
  6244. Arguments:
  6245. Lookaside - Supplies a pointer to a nonpaged lookaside list structure.
  6246. Entry - Supples a pointer to the entry that is inserted in the
  6247. lookaside list.
  6248. Return Value:
  6249. None.
  6250. --*/
  6251. {
  6252. Lookaside->L.TotalFrees += 1;
  6253. if (ExQueryDepthSList(&Lookaside->L.ListHead) >= Lookaside->L.Depth) {
  6254. Lookaside->L.FreeMisses += 1;
  6255. (Lookaside->L.Free)(Entry);
  6256. } else {
  6257. #if defined(_WIN2K_COMPAT_SLIST_USAGE) && defined(_X86_)
  6258. ExInterlockedPushEntrySList(&Lookaside->L.ListHead,
  6259. (PSLIST_ENTRY)Entry,
  6260. &Lookaside->Lock__ObsoleteButDoNotDelete);
  6261. #else
  6262. InterlockedPushEntrySList(&Lookaside->L.ListHead,
  6263. (PSLIST_ENTRY)Entry);
  6264. #endif
  6265. }
  6266. return;
  6267. }
  6268. // end_ntndis
  6269. #if !defined(_WIN64) && (defined(_NTDDK_) || defined(_NTIFS_) || defined(_NDIS_))
  6270. typedef struct _PAGED_LOOKASIDE_LIST {
  6271. #else
  6272. typedef struct DECLSPEC_CACHEALIGN _PAGED_LOOKASIDE_LIST {
  6273. #endif
  6274. GENERAL_LOOKASIDE L;
  6275. #if !defined(_AMD64_) && !defined(_IA64_)
  6276. FAST_MUTEX Lock__ObsoleteButDoNotDelete;
  6277. #endif
  6278. } PAGED_LOOKASIDE_LIST, *PPAGED_LOOKASIDE_LIST;
  6279. NTKERNELAPI
  6280. VOID
  6281. ExInitializePagedLookasideList (
  6282. IN PPAGED_LOOKASIDE_LIST Lookaside,
  6283. IN PALLOCATE_FUNCTION Allocate,
  6284. IN PFREE_FUNCTION Free,
  6285. IN ULONG Flags,
  6286. IN SIZE_T Size,
  6287. IN ULONG Tag,
  6288. IN USHORT Depth
  6289. );
  6290. NTKERNELAPI
  6291. VOID
  6292. ExDeletePagedLookasideList (
  6293. IN PPAGED_LOOKASIDE_LIST Lookaside
  6294. );
  6295. #if defined(_WIN2K_COMPAT_SLIST_USAGE) && defined(_X86_)
  6296. NTKERNELAPI
  6297. PVOID
  6298. ExAllocateFromPagedLookasideList(
  6299. IN PPAGED_LOOKASIDE_LIST Lookaside
  6300. );
  6301. #else
  6302. __inline
  6303. PVOID
  6304. ExAllocateFromPagedLookasideList(
  6305. IN PPAGED_LOOKASIDE_LIST Lookaside
  6306. )
  6307. /*++
  6308. Routine Description:
  6309. This function removes (pops) the first entry from the specified
  6310. paged lookaside list.
  6311. Arguments:
  6312. Lookaside - Supplies a pointer to a paged lookaside list structure.
  6313. Return Value:
  6314. If an entry is removed from the specified lookaside list, then the
  6315. address of the entry is returned as the function value. Otherwise,
  6316. NULL is returned.
  6317. --*/
  6318. {
  6319. PVOID Entry;
  6320. Lookaside->L.TotalAllocates += 1;
  6321. Entry = InterlockedPopEntrySList(&Lookaside->L.ListHead);
  6322. if (Entry == NULL) {
  6323. Lookaside->L.AllocateMisses += 1;
  6324. Entry = (Lookaside->L.Allocate)(Lookaside->L.Type,
  6325. Lookaside->L.Size,
  6326. Lookaside->L.Tag);
  6327. }
  6328. return Entry;
  6329. }
  6330. #endif
  6331. #if defined(_WIN2K_COMPAT_SLIST_USAGE) && defined(_X86_)
  6332. NTKERNELAPI
  6333. VOID
  6334. ExFreeToPagedLookasideList(
  6335. IN PPAGED_LOOKASIDE_LIST Lookaside,
  6336. IN PVOID Entry
  6337. );
  6338. #else
  6339. __inline
  6340. VOID
  6341. ExFreeToPagedLookasideList(
  6342. IN PPAGED_LOOKASIDE_LIST Lookaside,
  6343. IN PVOID Entry
  6344. )
  6345. /*++
  6346. Routine Description:
  6347. This function inserts (pushes) the specified entry into the specified
  6348. paged lookaside list.
  6349. Arguments:
  6350. Lookaside - Supplies a pointer to a nonpaged lookaside list structure.
  6351. Entry - Supples a pointer to the entry that is inserted in the
  6352. lookaside list.
  6353. Return Value:
  6354. None.
  6355. --*/
  6356. {
  6357. Lookaside->L.TotalFrees += 1;
  6358. if (ExQueryDepthSList(&Lookaside->L.ListHead) >= Lookaside->L.Depth) {
  6359. Lookaside->L.FreeMisses += 1;
  6360. (Lookaside->L.Free)(Entry);
  6361. } else {
  6362. InterlockedPushEntrySList(&Lookaside->L.ListHead,
  6363. (PSLIST_ENTRY)Entry);
  6364. }
  6365. return;
  6366. }
  6367. #endif
  6368. NTKERNELAPI
  6369. VOID
  6370. NTAPI
  6371. ProbeForRead(
  6372. IN CONST VOID *Address,
  6373. IN SIZE_T Length,
  6374. IN ULONG Alignment
  6375. );
  6376. // Probe function definitions
  6377. //
  6378. // Probe for read functions.
  6379. //
  6380. //++
  6381. //
  6382. // VOID
  6383. // ProbeForRead(
  6384. // IN PVOID Address,
  6385. // IN ULONG Length,
  6386. // IN ULONG Alignment
  6387. // )
  6388. //
  6389. //--
  6390. #define ProbeForRead(Address, Length, Alignment) \
  6391. ASSERT(((Alignment) == 1) || ((Alignment) == 2) || \
  6392. ((Alignment) == 4) || ((Alignment) == 8) || \
  6393. ((Alignment) == 16)); \
  6394. \
  6395. if ((Length) != 0) { \
  6396. if (((ULONG_PTR)(Address) & ((Alignment) - 1)) != 0) { \
  6397. ExRaiseDatatypeMisalignment(); \
  6398. \
  6399. } \
  6400. if ((((ULONG_PTR)(Address) + (Length)) < (ULONG_PTR)(Address)) || \
  6401. (((ULONG_PTR)(Address) + (Length)) > (ULONG_PTR)MM_USER_PROBE_ADDRESS)) { \
  6402. ExRaiseAccessViolation(); \
  6403. } \
  6404. }
  6405. //++
  6406. //
  6407. // VOID
  6408. // ProbeForReadSmallStructure(
  6409. // IN PVOID Address,
  6410. // IN ULONG Length,
  6411. // IN ULONG Alignment
  6412. // )
  6413. //
  6414. //--
  6415. #define ProbeForReadSmallStructure(Address,Size,Alignment) { \
  6416. ASSERT(((Alignment) == 1) || ((Alignment) == 2) || \
  6417. ((Alignment) == 4) || ((Alignment) == 8) || \
  6418. ((Alignment) == 16)); \
  6419. if (Size == 0 || Size > 0x10000) { \
  6420. ASSERT (0); \
  6421. ProbeForRead (Address,Size,Alignment); \
  6422. } else { \
  6423. if (((ULONG_PTR)(Address) & ((Alignment) - 1)) != 0) { \
  6424. ExRaiseDatatypeMisalignment(); \
  6425. } \
  6426. if ((ULONG_PTR)(Address) >= (ULONG_PTR)MM_USER_PROBE_ADDRESS) { \
  6427. *(volatile ULONG * const)MM_USER_PROBE_ADDRESS = 0; \
  6428. } \
  6429. } \
  6430. }
  6431. //++
  6432. //
  6433. // BOOLEAN
  6434. // ProbeAndReadBoolean(
  6435. // IN PBOOLEAN Address
  6436. // )
  6437. //
  6438. //--
  6439. #define ProbeAndReadBoolean(Address) \
  6440. (((Address) >= (BOOLEAN * const)MM_USER_PROBE_ADDRESS) ? \
  6441. (*(volatile BOOLEAN * const)MM_USER_PROBE_ADDRESS) : (*(volatile BOOLEAN *)(Address)))
  6442. //++
  6443. //
  6444. // CHAR
  6445. // ProbeAndReadChar(
  6446. // IN PCHAR Address
  6447. // )
  6448. //
  6449. //--
  6450. #define ProbeAndReadChar(Address) \
  6451. (((Address) >= (CHAR * const)MM_USER_PROBE_ADDRESS) ? \
  6452. (*(volatile CHAR * const)MM_USER_PROBE_ADDRESS) : (*(volatile CHAR *)(Address)))
  6453. //++
  6454. //
  6455. // UCHAR
  6456. // ProbeAndReadUchar(
  6457. // IN PUCHAR Address
  6458. // )
  6459. //
  6460. //--
  6461. #define ProbeAndReadUchar(Address) \
  6462. (((Address) >= (UCHAR * const)MM_USER_PROBE_ADDRESS) ? \
  6463. (*(volatile UCHAR * const)MM_USER_PROBE_ADDRESS) : (*(volatile UCHAR *)(Address)))
  6464. //++
  6465. //
  6466. // SHORT
  6467. // ProbeAndReadShort(
  6468. // IN PSHORT Address
  6469. // )
  6470. //
  6471. //--
  6472. #define ProbeAndReadShort(Address) \
  6473. (((Address) >= (SHORT * const)MM_USER_PROBE_ADDRESS) ? \
  6474. (*(volatile SHORT * const)MM_USER_PROBE_ADDRESS) : (*(volatile SHORT *)(Address)))
  6475. //++
  6476. //
  6477. // USHORT
  6478. // ProbeAndReadUshort(
  6479. // IN PUSHORT Address
  6480. // )
  6481. //
  6482. //--
  6483. #define ProbeAndReadUshort(Address) \
  6484. (((Address) >= (USHORT * const)MM_USER_PROBE_ADDRESS) ? \
  6485. (*(volatile USHORT * const)MM_USER_PROBE_ADDRESS) : (*(volatile USHORT *)(Address)))
  6486. //++
  6487. //
  6488. // HANDLE
  6489. // ProbeAndReadHandle(
  6490. // IN PHANDLE Address
  6491. // )
  6492. //
  6493. //--
  6494. #define ProbeAndReadHandle(Address) \
  6495. (((Address) >= (HANDLE * const)MM_USER_PROBE_ADDRESS) ? \
  6496. (*(volatile HANDLE * const)MM_USER_PROBE_ADDRESS) : (*(volatile HANDLE *)(Address)))
  6497. //++
  6498. //
  6499. // PVOID
  6500. // ProbeAndReadPointer(
  6501. // IN PVOID *Address
  6502. // )
  6503. //
  6504. //--
  6505. #define ProbeAndReadPointer(Address) \
  6506. (((Address) >= (PVOID * const)MM_USER_PROBE_ADDRESS) ? \
  6507. (*(volatile PVOID * const)MM_USER_PROBE_ADDRESS) : (*(volatile PVOID *)(Address)))
  6508. //++
  6509. //
  6510. // LONG
  6511. // ProbeAndReadLong(
  6512. // IN PLONG Address
  6513. // )
  6514. //
  6515. //--
  6516. #define ProbeAndReadLong(Address) \
  6517. (((Address) >= (LONG * const)MM_USER_PROBE_ADDRESS) ? \
  6518. (*(volatile LONG * const)MM_USER_PROBE_ADDRESS) : (*(volatile LONG *)(Address)))
  6519. //++
  6520. //
  6521. // ULONG
  6522. // ProbeAndReadUlong(
  6523. // IN PULONG Address
  6524. // )
  6525. //
  6526. //--
  6527. #define ProbeAndReadUlong(Address) \
  6528. (((Address) >= (ULONG * const)MM_USER_PROBE_ADDRESS) ? \
  6529. (*(volatile ULONG * const)MM_USER_PROBE_ADDRESS) : (*(volatile ULONG *)(Address)))
  6530. //++
  6531. //
  6532. // ULONG_PTR
  6533. // ProbeAndReadUlong_ptr(
  6534. // IN PULONG_PTR Address
  6535. // )
  6536. //
  6537. //--
  6538. #define ProbeAndReadUlong_ptr(Address) \
  6539. (((Address) >= (ULONG_PTR * const)MM_USER_PROBE_ADDRESS) ? \
  6540. (*(volatile ULONG_PTR * const)MM_USER_PROBE_ADDRESS) : (*(volatile ULONG_PTR *)(Address)))
  6541. //++
  6542. //
  6543. // QUAD
  6544. // ProbeAndReadQuad(
  6545. // IN PQUAD Address
  6546. // )
  6547. //
  6548. //--
  6549. #define ProbeAndReadQuad(Address) \
  6550. (((Address) >= (QUAD * const)MM_USER_PROBE_ADDRESS) ? \
  6551. (*(volatile QUAD * const)MM_USER_PROBE_ADDRESS) : (*(volatile QUAD *)(Address)))
  6552. //++
  6553. //
  6554. // UQUAD
  6555. // ProbeAndReadUquad(
  6556. // IN PUQUAD Address
  6557. // )
  6558. //
  6559. //--
  6560. #define ProbeAndReadUquad(Address) \
  6561. (((Address) >= (UQUAD * const)MM_USER_PROBE_ADDRESS) ? \
  6562. (*(volatile UQUAD * const)MM_USER_PROBE_ADDRESS) : (*(volatile UQUAD *)(Address)))
  6563. //++
  6564. //
  6565. // LARGE_INTEGER
  6566. // ProbeAndReadLargeInteger(
  6567. // IN PLARGE_INTEGER Source
  6568. // )
  6569. //
  6570. //--
  6571. #define ProbeAndReadLargeInteger(Source) \
  6572. (((Source) >= (LARGE_INTEGER * const)MM_USER_PROBE_ADDRESS) ? \
  6573. (*(volatile LARGE_INTEGER * const)MM_USER_PROBE_ADDRESS) : (*(volatile LARGE_INTEGER *)(Source)))
  6574. //++
  6575. //
  6576. // ULARGE_INTEGER
  6577. // ProbeAndReadUlargeInteger(
  6578. // IN PULARGE_INTEGER Source
  6579. // )
  6580. //
  6581. //--
  6582. #define ProbeAndReadUlargeInteger(Source) \
  6583. (((Source) >= (ULARGE_INTEGER * const)MM_USER_PROBE_ADDRESS) ? \
  6584. (*(volatile ULARGE_INTEGER * const)MM_USER_PROBE_ADDRESS) : (*(volatile ULARGE_INTEGER *)(Source)))
  6585. //++
  6586. //
  6587. // UNICODE_STRING
  6588. // ProbeAndReadUnicodeString(
  6589. // IN PUNICODE_STRING Source
  6590. // )
  6591. //
  6592. //--
  6593. #define ProbeAndReadUnicodeString(Source) \
  6594. (((Source) >= (UNICODE_STRING * const)MM_USER_PROBE_ADDRESS) ? \
  6595. (*(volatile UNICODE_STRING * const)MM_USER_PROBE_ADDRESS) : (*(volatile UNICODE_STRING *)(Source)))
  6596. //++
  6597. //
  6598. // <STRUCTURE>
  6599. // ProbeAndReadStructure(
  6600. // IN P<STRUCTURE> Source
  6601. // <STRUCTURE>
  6602. // )
  6603. //
  6604. //--
  6605. #define ProbeAndReadStructure(Source,STRUCTURE) \
  6606. (((Source) >= (STRUCTURE * const)MM_USER_PROBE_ADDRESS) ? \
  6607. (*(STRUCTURE * const)MM_USER_PROBE_ADDRESS) : (*(STRUCTURE *)(Source)))
  6608. //
  6609. // Probe for write functions definitions.
  6610. //
  6611. //++
  6612. //
  6613. // VOID
  6614. // ProbeForWriteBoolean(
  6615. // IN PBOOLEAN Address
  6616. // )
  6617. //
  6618. //--
  6619. #define ProbeForWriteBoolean(Address) { \
  6620. if ((Address) >= (BOOLEAN * const)MM_USER_PROBE_ADDRESS) { \
  6621. *(volatile BOOLEAN * const)MM_USER_PROBE_ADDRESS = 0; \
  6622. } \
  6623. \
  6624. *(volatile BOOLEAN *)(Address) = *(volatile BOOLEAN *)(Address); \
  6625. }
  6626. //++
  6627. //
  6628. // VOID
  6629. // ProbeForWriteChar(
  6630. // IN PCHAR Address
  6631. // )
  6632. //
  6633. //--
  6634. #define ProbeForWriteChar(Address) { \
  6635. if ((Address) >= (CHAR * const)MM_USER_PROBE_ADDRESS) { \
  6636. *(volatile CHAR * const)MM_USER_PROBE_ADDRESS = 0; \
  6637. } \
  6638. \
  6639. *(volatile CHAR *)(Address) = *(volatile CHAR *)(Address); \
  6640. }
  6641. //++
  6642. //
  6643. // VOID
  6644. // ProbeForWriteUchar(
  6645. // IN PUCHAR Address
  6646. // )
  6647. //
  6648. //--
  6649. #define ProbeForWriteUchar(Address) { \
  6650. if ((Address) >= (UCHAR * const)MM_USER_PROBE_ADDRESS) { \
  6651. *(volatile UCHAR * const)MM_USER_PROBE_ADDRESS = 0; \
  6652. } \
  6653. \
  6654. *(volatile UCHAR *)(Address) = *(volatile UCHAR *)(Address); \
  6655. }
  6656. //++
  6657. //
  6658. // VOID
  6659. // ProbeForWriteIoStatus(
  6660. // IN PIO_STATUS_BLOCK Address
  6661. // )
  6662. //
  6663. //--
  6664. #define ProbeForWriteIoStatus(Address) { \
  6665. if ((Address) >= (IO_STATUS_BLOCK * const)MM_USER_PROBE_ADDRESS) { \
  6666. *(volatile ULONG * const)MM_USER_PROBE_ADDRESS = 0; \
  6667. } \
  6668. \
  6669. *(volatile IO_STATUS_BLOCK *)(Address) = *(volatile IO_STATUS_BLOCK *)(Address); \
  6670. }
  6671. #ifdef _WIN64
  6672. #define ProbeForWriteIoStatusEx(Address, Cookie) { \
  6673. if ((Address) >= (IO_STATUS_BLOCK * const)MM_USER_PROBE_ADDRESS) { \
  6674. *(volatile ULONG * const)MM_USER_PROBE_ADDRESS = 0; \
  6675. } \
  6676. if ((ULONG_PTR)(Cookie) & (ULONG)1) { \
  6677. *(volatile IO_STATUS_BLOCK32 *)(Address) = *(volatile IO_STATUS_BLOCK32 *)(Address);\
  6678. } else { \
  6679. *(volatile IO_STATUS_BLOCK *)(Address) = *(volatile IO_STATUS_BLOCK *)(Address); \
  6680. } \
  6681. }
  6682. #else
  6683. #define ProbeForWriteIoStatusEx(Address, Cookie) ProbeForWriteIoStatus(Address)
  6684. #endif
  6685. //++
  6686. //
  6687. // VOID
  6688. // ProbeForWriteShort(
  6689. // IN PSHORT Address
  6690. // )
  6691. //
  6692. //--
  6693. #define ProbeForWriteShort(Address) { \
  6694. if ((Address) >= (SHORT * const)MM_USER_PROBE_ADDRESS) { \
  6695. *(volatile SHORT * const)MM_USER_PROBE_ADDRESS = 0; \
  6696. } \
  6697. \
  6698. *(volatile SHORT *)(Address) = *(volatile SHORT *)(Address); \
  6699. }
  6700. //++
  6701. //
  6702. // VOID
  6703. // ProbeForWriteUshort(
  6704. // IN PUSHORT Address
  6705. // )
  6706. //
  6707. //--
  6708. #define ProbeForWriteUshort(Address) { \
  6709. if ((Address) >= (USHORT * const)MM_USER_PROBE_ADDRESS) { \
  6710. *(volatile USHORT * const)MM_USER_PROBE_ADDRESS = 0; \
  6711. } \
  6712. \
  6713. *(volatile USHORT *)(Address) = *(volatile USHORT *)(Address); \
  6714. }
  6715. //++
  6716. //
  6717. // VOID
  6718. // ProbeForWriteHandle(
  6719. // IN PHANDLE Address
  6720. // )
  6721. //
  6722. //--
  6723. #define ProbeForWriteHandle(Address) { \
  6724. if ((Address) >= (HANDLE * const)MM_USER_PROBE_ADDRESS) { \
  6725. *(volatile HANDLE * const)MM_USER_PROBE_ADDRESS = 0; \
  6726. } \
  6727. \
  6728. *(volatile HANDLE *)(Address) = *(volatile HANDLE *)(Address); \
  6729. }
  6730. //++
  6731. //
  6732. // VOID
  6733. // ProbeAndZeroHandle(
  6734. // IN PHANDLE Address
  6735. // )
  6736. //
  6737. //--
  6738. #define ProbeAndZeroHandle(Address) { \
  6739. if ((Address) >= (HANDLE * const)MM_USER_PROBE_ADDRESS) { \
  6740. *(volatile HANDLE * const)MM_USER_PROBE_ADDRESS = 0; \
  6741. } \
  6742. \
  6743. *(volatile HANDLE *)(Address) = 0; \
  6744. }
  6745. //++
  6746. //
  6747. // VOID
  6748. // ProbeForWritePointer(
  6749. // IN PVOID Address
  6750. // )
  6751. //
  6752. //--
  6753. #define ProbeForWritePointer(Address) { \
  6754. if ((PVOID *)(Address) >= (PVOID * const)MM_USER_PROBE_ADDRESS) { \
  6755. *(volatile PVOID * const)MM_USER_PROBE_ADDRESS = NULL; \
  6756. } \
  6757. \
  6758. *(volatile PVOID *)(Address) = *(volatile PVOID *)(Address); \
  6759. }
  6760. //++
  6761. //
  6762. // VOID
  6763. // ProbeAndNullPointer(
  6764. // IN PVOID *Address
  6765. // )
  6766. //
  6767. //--
  6768. #define ProbeAndNullPointer(Address) { \
  6769. if ((PVOID *)(Address) >= (PVOID * const)MM_USER_PROBE_ADDRESS) { \
  6770. *(volatile PVOID * const)MM_USER_PROBE_ADDRESS = NULL; \
  6771. } \
  6772. \
  6773. *(volatile PVOID *)(Address) = NULL; \
  6774. }
  6775. //++
  6776. //
  6777. // VOID
  6778. // ProbeForWriteLong(
  6779. // IN PLONG Address
  6780. // )
  6781. //
  6782. //--
  6783. #define ProbeForWriteLong(Address) { \
  6784. if ((Address) >= (LONG * const)MM_USER_PROBE_ADDRESS) { \
  6785. *(volatile LONG * const)MM_USER_PROBE_ADDRESS = 0; \
  6786. } \
  6787. \
  6788. *(volatile LONG *)(Address) = *(volatile LONG *)(Address); \
  6789. }
  6790. //++
  6791. //
  6792. // VOID
  6793. // ProbeForWriteUlong(
  6794. // IN PULONG Address
  6795. // )
  6796. //
  6797. //--
  6798. #define ProbeForWriteUlong(Address) { \
  6799. if ((Address) >= (ULONG * const)MM_USER_PROBE_ADDRESS) { \
  6800. *(volatile ULONG * const)MM_USER_PROBE_ADDRESS = 0; \
  6801. } \
  6802. \
  6803. *(volatile ULONG *)(Address) = *(volatile ULONG *)(Address); \
  6804. }
  6805. //++
  6806. //
  6807. // VOID
  6808. // ProbeForWriteUlong_ptr(
  6809. // IN PULONG_PTR Address
  6810. // )
  6811. //
  6812. //--
  6813. #define ProbeForWriteUlong_ptr(Address) { \
  6814. if ((Address) >= (ULONG_PTR * const)MM_USER_PROBE_ADDRESS) { \
  6815. *(volatile ULONG_PTR * const)MM_USER_PROBE_ADDRESS = 0; \
  6816. } \
  6817. \
  6818. *(volatile ULONG_PTR *)(Address) = *(volatile ULONG_PTR *)(Address); \
  6819. }
  6820. //++
  6821. //
  6822. // VOID
  6823. // ProbeForWriteQuad(
  6824. // IN PQUAD Address
  6825. // )
  6826. //
  6827. //--
  6828. #define ProbeForWriteQuad(Address) { \
  6829. if ((Address) >= (QUAD * const)MM_USER_PROBE_ADDRESS) { \
  6830. *(volatile LONG * const)MM_USER_PROBE_ADDRESS = 0; \
  6831. } \
  6832. \
  6833. *(volatile QUAD *)(Address) = *(volatile QUAD *)(Address); \
  6834. }
  6835. //++
  6836. //
  6837. // VOID
  6838. // ProbeForWriteUquad(
  6839. // IN PUQUAD Address
  6840. // )
  6841. //
  6842. //--
  6843. #define ProbeForWriteUquad(Address) { \
  6844. if ((Address) >= (QUAD * const)MM_USER_PROBE_ADDRESS) { \
  6845. *(volatile ULONG * const)MM_USER_PROBE_ADDRESS = 0; \
  6846. } \
  6847. \
  6848. *(volatile UQUAD *)(Address) = *(volatile UQUAD *)(Address); \
  6849. }
  6850. //
  6851. // Probe and write functions definitions.
  6852. //
  6853. //++
  6854. //
  6855. // VOID
  6856. // ProbeAndWriteBoolean(
  6857. // IN PBOOLEAN Address,
  6858. // IN BOOLEAN Value
  6859. // )
  6860. //
  6861. //--
  6862. #define ProbeAndWriteBoolean(Address, Value) { \
  6863. if ((Address) >= (BOOLEAN * const)MM_USER_PROBE_ADDRESS) { \
  6864. *(volatile BOOLEAN * const)MM_USER_PROBE_ADDRESS = 0; \
  6865. } \
  6866. \
  6867. *(Address) = (Value); \
  6868. }
  6869. //++
  6870. //
  6871. // VOID
  6872. // ProbeAndWriteChar(
  6873. // IN PCHAR Address,
  6874. // IN CHAR Value
  6875. // )
  6876. //
  6877. //--
  6878. #define ProbeAndWriteChar(Address, Value) { \
  6879. if ((Address) >= (CHAR * const)MM_USER_PROBE_ADDRESS) { \
  6880. *(volatile CHAR * const)MM_USER_PROBE_ADDRESS = 0; \
  6881. } \
  6882. \
  6883. *(Address) = (Value); \
  6884. }
  6885. //++
  6886. //
  6887. // VOID
  6888. // ProbeAndWriteUchar(
  6889. // IN PUCHAR Address,
  6890. // IN UCHAR Value
  6891. // )
  6892. //
  6893. //--
  6894. #define ProbeAndWriteUchar(Address, Value) { \
  6895. if ((Address) >= (UCHAR * const)MM_USER_PROBE_ADDRESS) { \
  6896. *(volatile UCHAR * const)MM_USER_PROBE_ADDRESS = 0; \
  6897. } \
  6898. \
  6899. *(Address) = (Value); \
  6900. }
  6901. //++
  6902. //
  6903. // VOID
  6904. // ProbeAndWriteShort(
  6905. // IN PSHORT Address,
  6906. // IN SHORT Value
  6907. // )
  6908. //
  6909. //--
  6910. #define ProbeAndWriteShort(Address, Value) { \
  6911. if ((Address) >= (SHORT * const)MM_USER_PROBE_ADDRESS) { \
  6912. *(volatile SHORT * const)MM_USER_PROBE_ADDRESS = 0; \
  6913. } \
  6914. \
  6915. *(Address) = (Value); \
  6916. }
  6917. //++
  6918. //
  6919. // VOID
  6920. // ProbeAndWriteUshort(
  6921. // IN PUSHORT Address,
  6922. // IN USHORT Value
  6923. // )
  6924. //
  6925. //--
  6926. #define ProbeAndWriteUshort(Address, Value) { \
  6927. if ((Address) >= (USHORT * const)MM_USER_PROBE_ADDRESS) { \
  6928. *(volatile USHORT * const)MM_USER_PROBE_ADDRESS = 0; \
  6929. } \
  6930. \
  6931. *(Address) = (Value); \
  6932. }
  6933. //++
  6934. //
  6935. // VOID
  6936. // ProbeAndWriteHandle(
  6937. // IN PHANDLE Address,
  6938. // IN HANDLE Value
  6939. // )
  6940. //
  6941. //--
  6942. #define ProbeAndWriteHandle(Address, Value) { \
  6943. if ((Address) >= (HANDLE * const)MM_USER_PROBE_ADDRESS) { \
  6944. *(volatile HANDLE * const)MM_USER_PROBE_ADDRESS = 0; \
  6945. } \
  6946. \
  6947. *(Address) = (Value); \
  6948. }
  6949. //++
  6950. //
  6951. // VOID
  6952. // ProbeAndWriteLong(
  6953. // IN PLONG Address,
  6954. // IN LONG Value
  6955. // )
  6956. //
  6957. //--
  6958. #define ProbeAndWriteLong(Address, Value) { \
  6959. if ((Address) >= (LONG * const)MM_USER_PROBE_ADDRESS) { \
  6960. *(volatile LONG * const)MM_USER_PROBE_ADDRESS = 0; \
  6961. } \
  6962. \
  6963. *(Address) = (Value); \
  6964. }
  6965. //++
  6966. //
  6967. // VOID
  6968. // ProbeAndWriteUlong(
  6969. // IN PULONG Address,
  6970. // IN ULONG Value
  6971. // )
  6972. //
  6973. //--
  6974. #define ProbeAndWriteUlong(Address, Value) { \
  6975. if ((Address) >= (ULONG * const)MM_USER_PROBE_ADDRESS) { \
  6976. *(volatile ULONG * const)MM_USER_PROBE_ADDRESS = 0; \
  6977. } \
  6978. \
  6979. *(Address) = (Value); \
  6980. }
  6981. //++
  6982. //
  6983. // VOID
  6984. // ProbeAndWriteQuad(
  6985. // IN PQUAD Address,
  6986. // IN QUAD Value
  6987. // )
  6988. //
  6989. //--
  6990. #define ProbeAndWriteQuad(Address, Value) { \
  6991. if ((Address) >= (QUAD * const)MM_USER_PROBE_ADDRESS) { \
  6992. *(volatile LONG * const)MM_USER_PROBE_ADDRESS = 0; \
  6993. } \
  6994. \
  6995. *(Address) = (Value); \
  6996. }
  6997. //++
  6998. //
  6999. // VOID
  7000. // ProbeAndWriteUquad(
  7001. // IN PUQUAD Address,
  7002. // IN UQUAD Value
  7003. // )
  7004. //
  7005. //--
  7006. #define ProbeAndWriteUquad(Address, Value) { \
  7007. if ((Address) >= (UQUAD * const)MM_USER_PROBE_ADDRESS) { \
  7008. *(volatile ULONG * const)MM_USER_PROBE_ADDRESS = 0; \
  7009. } \
  7010. \
  7011. *(Address) = (Value); \
  7012. }
  7013. //++
  7014. //
  7015. // VOID
  7016. // ProbeAndWriteSturcture(
  7017. // IN P<STRUCTURE> Address,
  7018. // IN <STRUCTURE> Value,
  7019. // <STRUCTURE>
  7020. // )
  7021. //
  7022. //--
  7023. #define ProbeAndWriteStructure(Address, Value,STRUCTURE) { \
  7024. if ((STRUCTURE * const)(Address) >= (STRUCTURE * const)MM_USER_PROBE_ADDRESS) { \
  7025. *(volatile ULONG * const)MM_USER_PROBE_ADDRESS = 0; \
  7026. } \
  7027. \
  7028. *(Address) = (Value); \
  7029. }
  7030. // begin_ntifs begin_ntddk begin_wdm begin_ntosp
  7031. //
  7032. // Common probe for write functions.
  7033. //
  7034. NTKERNELAPI
  7035. VOID
  7036. NTAPI
  7037. ProbeForWrite (
  7038. IN PVOID Address,
  7039. IN SIZE_T Length,
  7040. IN ULONG Alignment
  7041. );
  7042. //
  7043. // Worker Thread
  7044. //
  7045. typedef enum _WORK_QUEUE_TYPE {
  7046. CriticalWorkQueue,
  7047. DelayedWorkQueue,
  7048. HyperCriticalWorkQueue,
  7049. MaximumWorkQueue
  7050. } WORK_QUEUE_TYPE;
  7051. typedef
  7052. VOID
  7053. (*PWORKER_THREAD_ROUTINE)(
  7054. IN PVOID Parameter
  7055. );
  7056. typedef struct _WORK_QUEUE_ITEM {
  7057. LIST_ENTRY List;
  7058. PWORKER_THREAD_ROUTINE WorkerRoutine;
  7059. PVOID Parameter;
  7060. } WORK_QUEUE_ITEM, *PWORK_QUEUE_ITEM;
  7061. #if PRAGMA_DEPRECATED_DDK
  7062. #pragma deprecated(ExInitializeWorkItem) // Use IoAllocateWorkItem
  7063. #endif
  7064. #define ExInitializeWorkItem(Item, Routine, Context) \
  7065. (Item)->WorkerRoutine = (Routine); \
  7066. (Item)->Parameter = (Context); \
  7067. (Item)->List.Flink = NULL;
  7068. DECLSPEC_DEPRECATED_DDK // Use IoQueueWorkItem
  7069. NTKERNELAPI
  7070. VOID
  7071. ExQueueWorkItem(
  7072. IN PWORK_QUEUE_ITEM WorkItem,
  7073. IN WORK_QUEUE_TYPE QueueType
  7074. );
  7075. NTKERNELAPI
  7076. BOOLEAN
  7077. ExIsProcessorFeaturePresent(
  7078. ULONG ProcessorFeature
  7079. );
  7080. //
  7081. // Zone Allocation
  7082. //
  7083. typedef struct _ZONE_SEGMENT_HEADER {
  7084. SINGLE_LIST_ENTRY SegmentList;
  7085. PVOID Reserved;
  7086. } ZONE_SEGMENT_HEADER, *PZONE_SEGMENT_HEADER;
  7087. typedef struct _ZONE_HEADER {
  7088. SINGLE_LIST_ENTRY FreeList;
  7089. SINGLE_LIST_ENTRY SegmentList;
  7090. ULONG BlockSize;
  7091. ULONG TotalSegmentSize;
  7092. } ZONE_HEADER, *PZONE_HEADER;
  7093. DECLSPEC_DEPRECATED_DDK
  7094. NTKERNELAPI
  7095. NTSTATUS
  7096. ExInitializeZone(
  7097. IN PZONE_HEADER Zone,
  7098. IN ULONG BlockSize,
  7099. IN PVOID InitialSegment,
  7100. IN ULONG InitialSegmentSize
  7101. );
  7102. DECLSPEC_DEPRECATED_DDK
  7103. NTKERNELAPI
  7104. NTSTATUS
  7105. ExExtendZone(
  7106. IN PZONE_HEADER Zone,
  7107. IN PVOID Segment,
  7108. IN ULONG SegmentSize
  7109. );
  7110. DECLSPEC_DEPRECATED_DDK
  7111. NTKERNELAPI
  7112. NTSTATUS
  7113. ExInterlockedExtendZone(
  7114. IN PZONE_HEADER Zone,
  7115. IN PVOID Segment,
  7116. IN ULONG SegmentSize,
  7117. IN PKSPIN_LOCK Lock
  7118. );
  7119. //++
  7120. //
  7121. // PVOID
  7122. // ExAllocateFromZone(
  7123. // IN PZONE_HEADER Zone
  7124. // )
  7125. //
  7126. // Routine Description:
  7127. //
  7128. // This routine removes an entry from the zone and returns a pointer to it.
  7129. //
  7130. // Arguments:
  7131. //
  7132. // Zone - Pointer to the zone header controlling the storage from which the
  7133. // entry is to be allocated.
  7134. //
  7135. // Return Value:
  7136. //
  7137. // The function value is a pointer to the storage allocated from the zone.
  7138. //
  7139. //--
  7140. #if PRAGMA_DEPRECATED_DDK
  7141. #pragma deprecated(ExAllocateFromZone)
  7142. #endif
  7143. #define ExAllocateFromZone(Zone) \
  7144. (PVOID)((Zone)->FreeList.Next); \
  7145. if ( (Zone)->FreeList.Next ) (Zone)->FreeList.Next = (Zone)->FreeList.Next->Next
  7146. //++
  7147. //
  7148. // PVOID
  7149. // ExFreeToZone(
  7150. // IN PZONE_HEADER Zone,
  7151. // IN PVOID Block
  7152. // )
  7153. //
  7154. // Routine Description:
  7155. //
  7156. // This routine places the specified block of storage back onto the free
  7157. // list in the specified zone.
  7158. //
  7159. // Arguments:
  7160. //
  7161. // Zone - Pointer to the zone header controlling the storage to which the
  7162. // entry is to be inserted.
  7163. //
  7164. // Block - Pointer to the block of storage to be freed back to the zone.
  7165. //
  7166. // Return Value:
  7167. //
  7168. // Pointer to previous block of storage that was at the head of the free
  7169. // list. NULL implies the zone went from no available free blocks to
  7170. // at least one free block.
  7171. //
  7172. //--
  7173. #if PRAGMA_DEPRECATED_DDK
  7174. #pragma deprecated(ExFreeToZone)
  7175. #endif
  7176. #define ExFreeToZone(Zone,Block) \
  7177. ( ((PSINGLE_LIST_ENTRY)(Block))->Next = (Zone)->FreeList.Next, \
  7178. (Zone)->FreeList.Next = ((PSINGLE_LIST_ENTRY)(Block)), \
  7179. ((PSINGLE_LIST_ENTRY)(Block))->Next \
  7180. )
  7181. //++
  7182. //
  7183. // BOOLEAN
  7184. // ExIsFullZone(
  7185. // IN PZONE_HEADER Zone
  7186. // )
  7187. //
  7188. // Routine Description:
  7189. //
  7190. // This routine determines if the specified zone is full or not. A zone
  7191. // is considered full if the free list is empty.
  7192. //
  7193. // Arguments:
  7194. //
  7195. // Zone - Pointer to the zone header to be tested.
  7196. //
  7197. // Return Value:
  7198. //
  7199. // TRUE if the zone is full and FALSE otherwise.
  7200. //
  7201. //--
  7202. #if PRAGMA_DEPRECATED_DDK
  7203. #pragma deprecated(ExIsFullZone)
  7204. #endif
  7205. #define ExIsFullZone(Zone) \
  7206. ( (Zone)->FreeList.Next == (PSINGLE_LIST_ENTRY)NULL )
  7207. //++
  7208. //
  7209. // PVOID
  7210. // ExInterlockedAllocateFromZone(
  7211. // IN PZONE_HEADER Zone,
  7212. // IN PKSPIN_LOCK Lock
  7213. // )
  7214. //
  7215. // Routine Description:
  7216. //
  7217. // This routine removes an entry from the zone and returns a pointer to it.
  7218. // The removal is performed with the specified lock owned for the sequence
  7219. // to make it MP-safe.
  7220. //
  7221. // Arguments:
  7222. //
  7223. // Zone - Pointer to the zone header controlling the storage from which the
  7224. // entry is to be allocated.
  7225. //
  7226. // Lock - Pointer to the spin lock which should be obtained before removing
  7227. // the entry from the allocation list. The lock is released before
  7228. // returning to the caller.
  7229. //
  7230. // Return Value:
  7231. //
  7232. // The function value is a pointer to the storage allocated from the zone.
  7233. //
  7234. //--
  7235. #if PRAGMA_DEPRECATED_DDK
  7236. #pragma deprecated(ExInterlockedAllocateFromZone)
  7237. #endif
  7238. #define ExInterlockedAllocateFromZone(Zone,Lock) \
  7239. (PVOID) ExInterlockedPopEntryList( &(Zone)->FreeList, Lock )
  7240. //++
  7241. //
  7242. // PVOID
  7243. // ExInterlockedFreeToZone(
  7244. // IN PZONE_HEADER Zone,
  7245. // IN PVOID Block,
  7246. // IN PKSPIN_LOCK Lock
  7247. // )
  7248. //
  7249. // Routine Description:
  7250. //
  7251. // This routine places the specified block of storage back onto the free
  7252. // list in the specified zone. The insertion is performed with the lock
  7253. // owned for the sequence to make it MP-safe.
  7254. //
  7255. // Arguments:
  7256. //
  7257. // Zone - Pointer to the zone header controlling the storage to which the
  7258. // entry is to be inserted.
  7259. //
  7260. // Block - Pointer to the block of storage to be freed back to the zone.
  7261. //
  7262. // Lock - Pointer to the spin lock which should be obtained before inserting
  7263. // the entry onto the free list. The lock is released before returning
  7264. // to the caller.
  7265. //
  7266. // Return Value:
  7267. //
  7268. // Pointer to previous block of storage that was at the head of the free
  7269. // list. NULL implies the zone went from no available free blocks to
  7270. // at least one free block.
  7271. //
  7272. //--
  7273. #if PRAGMA_DEPRECATED_DDK
  7274. #pragma deprecated(ExInterlockedFreeToZone)
  7275. #endif
  7276. #define ExInterlockedFreeToZone(Zone,Block,Lock) \
  7277. ExInterlockedPushEntryList( &(Zone)->FreeList, ((PSINGLE_LIST_ENTRY) (Block)), Lock )
  7278. //++
  7279. //
  7280. // BOOLEAN
  7281. // ExIsObjectInFirstZoneSegment(
  7282. // IN PZONE_HEADER Zone,
  7283. // IN PVOID Object
  7284. // )
  7285. //
  7286. // Routine Description:
  7287. //
  7288. // This routine determines if the specified pointer lives in the zone.
  7289. //
  7290. // Arguments:
  7291. //
  7292. // Zone - Pointer to the zone header controlling the storage to which the
  7293. // object may belong.
  7294. //
  7295. // Object - Pointer to the object in question.
  7296. //
  7297. // Return Value:
  7298. //
  7299. // TRUE if the Object came from the first segment of zone.
  7300. //
  7301. //--
  7302. #if PRAGMA_DEPRECATED_DDK
  7303. #pragma deprecated(ExIsObjectInFirstZoneSegment)
  7304. #endif
  7305. #define ExIsObjectInFirstZoneSegment(Zone,Object) ((BOOLEAN) \
  7306. (((PUCHAR)(Object) >= (PUCHAR)(Zone)->SegmentList.Next) && \
  7307. ((PUCHAR)(Object) < (PUCHAR)(Zone)->SegmentList.Next + \
  7308. (Zone)->TotalSegmentSize)) \
  7309. )
  7310. //
  7311. // Define executive resource data structures.
  7312. //
  7313. typedef ULONG_PTR ERESOURCE_THREAD;
  7314. typedef ERESOURCE_THREAD *PERESOURCE_THREAD;
  7315. typedef struct _OWNER_ENTRY {
  7316. ERESOURCE_THREAD OwnerThread;
  7317. union {
  7318. LONG OwnerCount;
  7319. ULONG TableSize;
  7320. };
  7321. } OWNER_ENTRY, *POWNER_ENTRY;
  7322. typedef struct _ERESOURCE {
  7323. LIST_ENTRY SystemResourcesList;
  7324. POWNER_ENTRY OwnerTable;
  7325. SHORT ActiveCount;
  7326. USHORT Flag;
  7327. PKSEMAPHORE SharedWaiters;
  7328. PKEVENT ExclusiveWaiters;
  7329. OWNER_ENTRY OwnerThreads[2];
  7330. ULONG ContentionCount;
  7331. USHORT NumberOfSharedWaiters;
  7332. USHORT NumberOfExclusiveWaiters;
  7333. union {
  7334. PVOID Address;
  7335. ULONG_PTR CreatorBackTraceIndex;
  7336. };
  7337. KSPIN_LOCK SpinLock;
  7338. } ERESOURCE, *PERESOURCE;
  7339. //
  7340. // Values for ERESOURCE.Flag
  7341. //
  7342. #define ResourceNeverExclusive 0x10
  7343. #define ResourceReleaseByOtherThread 0x20
  7344. #define ResourceOwnedExclusive 0x80
  7345. #define RESOURCE_HASH_TABLE_SIZE 64
  7346. typedef struct _RESOURCE_HASH_ENTRY {
  7347. LIST_ENTRY ListEntry;
  7348. PVOID Address;
  7349. ULONG ContentionCount;
  7350. ULONG Number;
  7351. } RESOURCE_HASH_ENTRY, *PRESOURCE_HASH_ENTRY;
  7352. typedef struct _RESOURCE_PERFORMANCE_DATA {
  7353. ULONG ActiveResourceCount;
  7354. ULONG TotalResourceCount;
  7355. ULONG ExclusiveAcquire;
  7356. ULONG SharedFirstLevel;
  7357. ULONG SharedSecondLevel;
  7358. ULONG StarveFirstLevel;
  7359. ULONG StarveSecondLevel;
  7360. ULONG WaitForExclusive;
  7361. ULONG OwnerTableExpands;
  7362. ULONG MaximumTableExpand;
  7363. LIST_ENTRY HashTable[RESOURCE_HASH_TABLE_SIZE];
  7364. } RESOURCE_PERFORMANCE_DATA, *PRESOURCE_PERFORMANCE_DATA;
  7365. //
  7366. // Define executive resource function prototypes.
  7367. //
  7368. NTKERNELAPI
  7369. NTSTATUS
  7370. ExInitializeResourceLite(
  7371. IN PERESOURCE Resource
  7372. );
  7373. NTKERNELAPI
  7374. NTSTATUS
  7375. ExReinitializeResourceLite(
  7376. IN PERESOURCE Resource
  7377. );
  7378. NTKERNELAPI
  7379. BOOLEAN
  7380. ExAcquireResourceSharedLite(
  7381. IN PERESOURCE Resource,
  7382. IN BOOLEAN Wait
  7383. );
  7384. NTKERNELAPI
  7385. BOOLEAN
  7386. ExAcquireResourceExclusiveLite(
  7387. IN PERESOURCE Resource,
  7388. IN BOOLEAN Wait
  7389. );
  7390. NTKERNELAPI
  7391. BOOLEAN
  7392. ExAcquireSharedStarveExclusive(
  7393. IN PERESOURCE Resource,
  7394. IN BOOLEAN Wait
  7395. );
  7396. NTKERNELAPI
  7397. BOOLEAN
  7398. ExAcquireSharedWaitForExclusive(
  7399. IN PERESOURCE Resource,
  7400. IN BOOLEAN Wait
  7401. );
  7402. NTKERNELAPI
  7403. BOOLEAN
  7404. ExTryToAcquireResourceExclusiveLite(
  7405. IN PERESOURCE Resource
  7406. );
  7407. //
  7408. // VOID
  7409. // ExReleaseResource(
  7410. // IN PERESOURCE Resource
  7411. // );
  7412. //
  7413. #if PRAGMA_DEPRECATED_DDK
  7414. #pragma deprecated(ExReleaseResource) // Use ExReleaseResourceLite
  7415. #endif
  7416. #define ExReleaseResource(R) (ExReleaseResourceLite(R))
  7417. NTKERNELAPI
  7418. VOID
  7419. FASTCALL
  7420. ExReleaseResourceLite(
  7421. IN PERESOURCE Resource
  7422. );
  7423. NTKERNELAPI
  7424. VOID
  7425. ExReleaseResourceForThreadLite(
  7426. IN PERESOURCE Resource,
  7427. IN ERESOURCE_THREAD ResourceThreadId
  7428. );
  7429. NTKERNELAPI
  7430. VOID
  7431. ExSetResourceOwnerPointer(
  7432. IN PERESOURCE Resource,
  7433. IN PVOID OwnerPointer
  7434. );
  7435. NTKERNELAPI
  7436. VOID
  7437. ExConvertExclusiveToSharedLite(
  7438. IN PERESOURCE Resource
  7439. );
  7440. NTKERNELAPI
  7441. NTSTATUS
  7442. ExDeleteResourceLite (
  7443. IN PERESOURCE Resource
  7444. );
  7445. NTKERNELAPI
  7446. ULONG
  7447. ExGetExclusiveWaiterCount (
  7448. IN PERESOURCE Resource
  7449. );
  7450. NTKERNELAPI
  7451. ULONG
  7452. ExGetSharedWaiterCount (
  7453. IN PERESOURCE Resource
  7454. );
  7455. //
  7456. // ERESOURCE_THREAD
  7457. // ExGetCurrentResourceThread(
  7458. // );
  7459. //
  7460. #define ExGetCurrentResourceThread() ((ULONG_PTR)PsGetCurrentThread())
  7461. NTKERNELAPI
  7462. BOOLEAN
  7463. ExIsResourceAcquiredExclusiveLite (
  7464. IN PERESOURCE Resource
  7465. );
  7466. NTKERNELAPI
  7467. ULONG
  7468. ExIsResourceAcquiredSharedLite (
  7469. IN PERESOURCE Resource
  7470. );
  7471. //
  7472. // An acquired resource is always owned shared, as shared ownership is a subset
  7473. // of exclusive ownership.
  7474. //
  7475. #define ExIsResourceAcquiredLite ExIsResourceAcquiredSharedLite
  7476. // end_wdm
  7477. //
  7478. // ntddk.h stole the entrypoints we wanted so fix them up here.
  7479. //
  7480. #if PRAGMA_DEPRECATED_DDK
  7481. #pragma deprecated(ExInitializeResource) // use ExInitializeResourceLite
  7482. #pragma deprecated(ExAcquireResourceShared) // use ExAcquireResourceSharedLite
  7483. #pragma deprecated(ExAcquireResourceExclusive) // use ExAcquireResourceExclusiveLite
  7484. #pragma deprecated(ExReleaseResourceForThread) // use ExReleaseResourceForThreadLite
  7485. #pragma deprecated(ExConvertExclusiveToShared) // use ExConvertExclusiveToSharedLite
  7486. #pragma deprecated(ExDeleteResource) // use ExDeleteResourceLite
  7487. #pragma deprecated(ExIsResourceAcquiredExclusive) // use ExIsResourceAcquiredExclusiveLite
  7488. #pragma deprecated(ExIsResourceAcquiredShared) // use ExIsResourceAcquiredSharedLite
  7489. #pragma deprecated(ExIsResourceAcquired) // use ExIsResourceAcquiredSharedLite
  7490. #endif
  7491. #define ExInitializeResource ExInitializeResourceLite
  7492. #define ExAcquireResourceShared ExAcquireResourceSharedLite
  7493. #define ExAcquireResourceExclusive ExAcquireResourceExclusiveLite
  7494. #define ExReleaseResourceForThread ExReleaseResourceForThreadLite
  7495. #define ExConvertExclusiveToShared ExConvertExclusiveToSharedLite
  7496. #define ExDeleteResource ExDeleteResourceLite
  7497. #define ExIsResourceAcquiredExclusive ExIsResourceAcquiredExclusiveLite
  7498. #define ExIsResourceAcquiredShared ExIsResourceAcquiredSharedLite
  7499. #define ExIsResourceAcquired ExIsResourceAcquiredSharedLite
  7500. //
  7501. // Push lock definitions
  7502. //
  7503. typedef struct _EX_PUSH_LOCK {
  7504. #define EX_PUSH_LOCK_WAITING 0x1
  7505. #define EX_PUSH_LOCK_EXCLUSIVE 0x2
  7506. #define EX_PUSH_LOCK_SHARE_INC 0x4
  7507. union {
  7508. struct {
  7509. ULONG_PTR Waiting : 1;
  7510. ULONG_PTR Exclusive : 1;
  7511. ULONG_PTR Shared : sizeof (ULONG_PTR) * 8 - 2;
  7512. };
  7513. ULONG_PTR Value;
  7514. PVOID Ptr;
  7515. };
  7516. } EX_PUSH_LOCK, *PEX_PUSH_LOCK;
  7517. #if defined (NT_UP)
  7518. #define EX_CACHE_LINE_SIZE 16
  7519. #define EX_PUSH_LOCK_FANNED_COUNT 1
  7520. #else
  7521. #define EX_CACHE_LINE_SIZE 128
  7522. #define EX_PUSH_LOCK_FANNED_COUNT (PAGE_SIZE/EX_CACHE_LINE_SIZE)
  7523. #endif
  7524. //
  7525. // Define a fan out structure for n push locks each in its own cache line
  7526. //
  7527. typedef struct _EX_PUSH_LOCK_CACHE_AWARE {
  7528. PEX_PUSH_LOCK Locks[EX_PUSH_LOCK_FANNED_COUNT];
  7529. } EX_PUSH_LOCK_CACHE_AWARE, *PEX_PUSH_LOCK_CACHE_AWARE;
  7530. //
  7531. // Define structure thats a push lock padded to the size of a cache line
  7532. //
  7533. typedef struct _EX_PUSH_LOCK_CACHE_AWARE_PADDED {
  7534. EX_PUSH_LOCK Lock;
  7535. union {
  7536. UCHAR Pad[EX_CACHE_LINE_SIZE - sizeof (EX_PUSH_LOCK)];
  7537. BOOLEAN Single;
  7538. };
  7539. } EX_PUSH_LOCK_CACHE_AWARE_PADDED, *PEX_PUSH_LOCK_CACHE_AWARE_PADDED;
  7540. //
  7541. // Rundown protection structure
  7542. //
  7543. typedef struct _EX_RUNDOWN_REF {
  7544. #define EX_RUNDOWN_ACTIVE 0x1
  7545. #define EX_RUNDOWN_COUNT_SHIFT 0x1
  7546. #define EX_RUNDOWN_COUNT_INC (1<<EX_RUNDOWN_COUNT_SHIFT)
  7547. union {
  7548. ULONG_PTR Count;
  7549. PVOID Ptr;
  7550. };
  7551. } EX_RUNDOWN_REF, *PEX_RUNDOWN_REF;
  7552. //
  7553. // The Ex/Ob handle table interface package (in handle.c)
  7554. //
  7555. //
  7556. // The Ex/Ob handle table package uses a common handle definition. The actual
  7557. // type definition for a handle is a pvoid and is declared in sdk/inc. This
  7558. // package uses only the low 32 bits of the pvoid pointer.
  7559. //
  7560. // For simplicity we declare a new typedef called an exhandle
  7561. //
  7562. // The 2 bits of an EXHANDLE is available to the application and is
  7563. // ignored by the system. The next 24 bits store the handle table entry
  7564. // index and is used to refer to a particular entry in a handle table.
  7565. //
  7566. // Note that this format is immutable because there are outside programs with
  7567. // hardwired code that already assumes the format of a handle.
  7568. //
  7569. typedef struct _EXHANDLE {
  7570. union {
  7571. struct {
  7572. //
  7573. // Application available tag bits
  7574. //
  7575. ULONG TagBits : 2;
  7576. //
  7577. // The handle table entry index
  7578. //
  7579. ULONG Index : 30;
  7580. };
  7581. HANDLE GenericHandleOverlay;
  7582. #define HANDLE_VALUE_INC 4 // Amount to increment the Value to get to the next handle
  7583. ULONG_PTR Value;
  7584. };
  7585. } EXHANDLE, *PEXHANDLE;
  7586. //
  7587. // Get previous mode
  7588. //
  7589. NTKERNELAPI
  7590. KPROCESSOR_MODE
  7591. ExGetPreviousMode(
  7592. VOID
  7593. );
  7594. //
  7595. // Raise status from kernel mode.
  7596. //
  7597. NTKERNELAPI
  7598. VOID
  7599. NTAPI
  7600. ExRaiseStatus (
  7601. IN NTSTATUS Status
  7602. );
  7603. // end_wdm
  7604. NTKERNELAPI
  7605. VOID
  7606. ExRaiseDatatypeMisalignment (
  7607. VOID
  7608. );
  7609. NTKERNELAPI
  7610. VOID
  7611. ExRaiseAccessViolation (
  7612. VOID
  7613. );
  7614. NTKERNELAPI
  7615. NTSTATUS
  7616. ExRaiseHardError(
  7617. IN NTSTATUS ErrorStatus,
  7618. IN ULONG NumberOfParameters,
  7619. IN ULONG UnicodeStringParameterMask,
  7620. IN PULONG_PTR Parameters,
  7621. IN ULONG ValidResponseOptions,
  7622. OUT PULONG Response
  7623. );
  7624. int
  7625. ExSystemExceptionFilter(
  7626. VOID
  7627. );
  7628. NTKERNELAPI
  7629. VOID
  7630. ExGetCurrentProcessorCpuUsage(
  7631. IN PULONG CpuUsage
  7632. );
  7633. NTKERNELAPI
  7634. VOID
  7635. ExGetCurrentProcessorCounts(
  7636. OUT PULONG IdleCount,
  7637. OUT PULONG KernelAndUser,
  7638. OUT PULONG Index
  7639. );
  7640. //
  7641. // Set timer resolution.
  7642. //
  7643. NTKERNELAPI
  7644. ULONG
  7645. ExSetTimerResolution (
  7646. IN ULONG DesiredTime,
  7647. IN BOOLEAN SetResolution
  7648. );
  7649. //
  7650. // Subtract time zone bias from system time to get local time.
  7651. //
  7652. NTKERNELAPI
  7653. VOID
  7654. ExSystemTimeToLocalTime (
  7655. IN PLARGE_INTEGER SystemTime,
  7656. OUT PLARGE_INTEGER LocalTime
  7657. );
  7658. //
  7659. // Add time zone bias to local time to get system time.
  7660. //
  7661. NTKERNELAPI
  7662. VOID
  7663. ExLocalTimeToSystemTime (
  7664. IN PLARGE_INTEGER LocalTime,
  7665. OUT PLARGE_INTEGER SystemTime
  7666. );
  7667. //
  7668. // Define the type for Callback function.
  7669. //
  7670. typedef struct _CALLBACK_OBJECT *PCALLBACK_OBJECT;
  7671. typedef VOID (*PCALLBACK_FUNCTION ) (
  7672. IN PVOID CallbackContext,
  7673. IN PVOID Argument1,
  7674. IN PVOID Argument2
  7675. );
  7676. NTKERNELAPI
  7677. NTSTATUS
  7678. ExCreateCallback (
  7679. OUT PCALLBACK_OBJECT *CallbackObject,
  7680. IN POBJECT_ATTRIBUTES ObjectAttributes,
  7681. IN BOOLEAN Create,
  7682. IN BOOLEAN AllowMultipleCallbacks
  7683. );
  7684. NTKERNELAPI
  7685. PVOID
  7686. ExRegisterCallback (
  7687. IN PCALLBACK_OBJECT CallbackObject,
  7688. IN PCALLBACK_FUNCTION CallbackFunction,
  7689. IN PVOID CallbackContext
  7690. );
  7691. NTKERNELAPI
  7692. VOID
  7693. ExUnregisterCallback (
  7694. IN PVOID CallbackRegistration
  7695. );
  7696. NTKERNELAPI
  7697. VOID
  7698. ExNotifyCallback (
  7699. IN PVOID CallbackObject,
  7700. IN PVOID Argument1,
  7701. IN PVOID Argument2
  7702. );
  7703. typedef
  7704. PVOID
  7705. (*PKWIN32_GLOBALATOMTABLE_CALLOUT) ( void );
  7706. extern PKWIN32_GLOBALATOMTABLE_CALLOUT ExGlobalAtomTableCallout;
  7707. //
  7708. // UUID Generation
  7709. //
  7710. typedef GUID UUID;
  7711. NTKERNELAPI
  7712. NTSTATUS
  7713. ExUuidCreate(
  7714. OUT UUID *Uuid
  7715. );
  7716. NTKERNELAPI
  7717. VOID
  7718. FASTCALL
  7719. ExfInitializeRundownProtection (
  7720. IN PEX_RUNDOWN_REF RunRef
  7721. );
  7722. NTKERNELAPI
  7723. VOID
  7724. FORCEINLINE
  7725. FASTCALL
  7726. ExInitializeRundownProtection (
  7727. IN PEX_RUNDOWN_REF RunRef
  7728. )
  7729. /*++
  7730. Routine Description:
  7731. Initialize rundown protection structure
  7732. Arguments:
  7733. RunRef - Rundown block to be referenced
  7734. Return Value:
  7735. None
  7736. --*/
  7737. {
  7738. RunRef->Count = 0;
  7739. }
  7740. //
  7741. // Reset a rundown protection block
  7742. //
  7743. NTKERNELAPI
  7744. VOID
  7745. FASTCALL
  7746. ExReInitializeRundownProtection (
  7747. IN PEX_RUNDOWN_REF RunRef
  7748. );
  7749. //
  7750. // Acquire rundown protection
  7751. //
  7752. NTKERNELAPI
  7753. BOOLEAN
  7754. FASTCALL
  7755. ExAcquireRundownProtection (
  7756. IN PEX_RUNDOWN_REF RunRef
  7757. );
  7758. NTKERNELAPI
  7759. BOOLEAN
  7760. FASTCALL
  7761. ExAcquireRundownProtectionEx (
  7762. IN PEX_RUNDOWN_REF RunRef,
  7763. IN ULONG Count
  7764. );
  7765. //
  7766. // Release rundown protection
  7767. //
  7768. NTKERNELAPI
  7769. VOID
  7770. FASTCALL
  7771. ExReleaseRundownProtection (
  7772. IN PEX_RUNDOWN_REF RunRef
  7773. );
  7774. NTKERNELAPI
  7775. VOID
  7776. FASTCALL
  7777. ExReleaseRundownProtectionEx (
  7778. IN PEX_RUNDOWN_REF RunRef,
  7779. IN ULONG Count
  7780. );
  7781. //
  7782. // Mark rundown block as rundown having been completed.
  7783. //
  7784. NTKERNELAPI
  7785. VOID
  7786. FASTCALL
  7787. ExRundownCompleted (
  7788. IN PEX_RUNDOWN_REF RunRef
  7789. );
  7790. //
  7791. // Wait for all protected acquires to exit
  7792. //
  7793. NTKERNELAPI
  7794. VOID
  7795. FASTCALL
  7796. ExWaitForRundownProtectionRelease (
  7797. IN PEX_RUNDOWN_REF RunRef
  7798. );
  7799. //
  7800. // Define external data.
  7801. // because of indirection for all drivers external to ntoskrnl these are actually ptrs
  7802. //
  7803. #if defined(_NTDDK_) || defined(_NTIFS_) || defined(_NTHAL_) || defined(_WDMDDK_) || defined(_NTOSP_)
  7804. extern PBOOLEAN KdDebuggerNotPresent;
  7805. extern PBOOLEAN KdDebuggerEnabled;
  7806. #define KD_DEBUGGER_ENABLED *KdDebuggerEnabled
  7807. #define KD_DEBUGGER_NOT_PRESENT *KdDebuggerNotPresent
  7808. #else
  7809. extern BOOLEAN KdDebuggerNotPresent;
  7810. extern BOOLEAN KdDebuggerEnabled;
  7811. #define KD_DEBUGGER_ENABLED KdDebuggerEnabled
  7812. #define KD_DEBUGGER_NOT_PRESENT KdDebuggerNotPresent
  7813. #endif
  7814. //
  7815. // Priority increment definitions. The comment for each definition gives
  7816. // the names of the system services that use the definition when satisfying
  7817. // a wait.
  7818. //
  7819. //
  7820. // Priority increment used when satisfying a wait on an executive event
  7821. // (NtPulseEvent and NtSetEvent)
  7822. //
  7823. #define EVENT_INCREMENT 1
  7824. //
  7825. // Priority increment when no I/O has been done. This is used by device
  7826. // and file system drivers when completing an IRP (IoCompleteRequest).
  7827. //
  7828. #define IO_NO_INCREMENT 0
  7829. //
  7830. // Priority increment for completing CD-ROM I/O. This is used by CD-ROM device
  7831. // and file system drivers when completing an IRP (IoCompleteRequest)
  7832. //
  7833. #define IO_CD_ROM_INCREMENT 1
  7834. //
  7835. // Priority increment for completing disk I/O. This is used by disk device
  7836. // and file system drivers when completing an IRP (IoCompleteRequest)
  7837. //
  7838. #define IO_DISK_INCREMENT 1
  7839. // end_ntifs
  7840. //
  7841. // Priority increment for completing keyboard I/O. This is used by keyboard
  7842. // device drivers when completing an IRP (IoCompleteRequest)
  7843. //
  7844. #define IO_KEYBOARD_INCREMENT 6
  7845. // begin_ntifs
  7846. //
  7847. // Priority increment for completing mailslot I/O. This is used by the mail-
  7848. // slot file system driver when completing an IRP (IoCompleteRequest).
  7849. //
  7850. #define IO_MAILSLOT_INCREMENT 2
  7851. // end_ntifs
  7852. //
  7853. // Priority increment for completing mouse I/O. This is used by mouse device
  7854. // drivers when completing an IRP (IoCompleteRequest)
  7855. //
  7856. #define IO_MOUSE_INCREMENT 6
  7857. // begin_ntifs
  7858. //
  7859. // Priority increment for completing named pipe I/O. This is used by the
  7860. // named pipe file system driver when completing an IRP (IoCompleteRequest).
  7861. //
  7862. #define IO_NAMED_PIPE_INCREMENT 2
  7863. //
  7864. // Priority increment for completing network I/O. This is used by network
  7865. // device and network file system drivers when completing an IRP
  7866. // (IoCompleteRequest).
  7867. //
  7868. #define IO_NETWORK_INCREMENT 2
  7869. // end_ntifs
  7870. //
  7871. // Priority increment for completing parallel I/O. This is used by parallel
  7872. // device drivers when completing an IRP (IoCompleteRequest)
  7873. //
  7874. #define IO_PARALLEL_INCREMENT 1
  7875. //
  7876. // Priority increment for completing serial I/O. This is used by serial device
  7877. // drivers when completing an IRP (IoCompleteRequest)
  7878. //
  7879. #define IO_SERIAL_INCREMENT 2
  7880. //
  7881. // Priority increment for completing sound I/O. This is used by sound device
  7882. // drivers when completing an IRP (IoCompleteRequest)
  7883. //
  7884. #define IO_SOUND_INCREMENT 8
  7885. //
  7886. // Priority increment for completing video I/O. This is used by video device
  7887. // drivers when completing an IRP (IoCompleteRequest)
  7888. //
  7889. #define IO_VIDEO_INCREMENT 1
  7890. // end_ntddk end_wdm
  7891. //
  7892. // Priority increment used when satisfying a wait on an executive mutant
  7893. // (NtReleaseMutant)
  7894. //
  7895. #define MUTANT_INCREMENT 1
  7896. // begin_ntddk begin_wdm begin_ntifs
  7897. //
  7898. // Priority increment used when satisfying a wait on an executive semaphore
  7899. // (NtReleaseSemaphore)
  7900. //
  7901. #define SEMAPHORE_INCREMENT 1
  7902. //
  7903. // Define I/O system data structure type codes. Each major data structure in
  7904. // the I/O system has a type code The type field in each structure is at the
  7905. // same offset. The following values can be used to determine which type of
  7906. // data structure a pointer refers to.
  7907. //
  7908. #define IO_TYPE_ADAPTER 0x00000001
  7909. #define IO_TYPE_CONTROLLER 0x00000002
  7910. #define IO_TYPE_DEVICE 0x00000003
  7911. #define IO_TYPE_DRIVER 0x00000004
  7912. #define IO_TYPE_FILE 0x00000005
  7913. #define IO_TYPE_IRP 0x00000006
  7914. #define IO_TYPE_MASTER_ADAPTER 0x00000007
  7915. #define IO_TYPE_OPEN_PACKET 0x00000008
  7916. #define IO_TYPE_TIMER 0x00000009
  7917. #define IO_TYPE_VPB 0x0000000a
  7918. #define IO_TYPE_ERROR_LOG 0x0000000b
  7919. #define IO_TYPE_ERROR_MESSAGE 0x0000000c
  7920. #define IO_TYPE_DEVICE_OBJECT_EXTENSION 0x0000000d
  7921. //
  7922. // Define the major function codes for IRPs.
  7923. //
  7924. #define IRP_MJ_CREATE 0x00
  7925. #define IRP_MJ_CREATE_NAMED_PIPE 0x01
  7926. #define IRP_MJ_CLOSE 0x02
  7927. #define IRP_MJ_READ 0x03
  7928. #define IRP_MJ_WRITE 0x04
  7929. #define IRP_MJ_QUERY_INFORMATION 0x05
  7930. #define IRP_MJ_SET_INFORMATION 0x06
  7931. #define IRP_MJ_QUERY_EA 0x07
  7932. #define IRP_MJ_SET_EA 0x08
  7933. #define IRP_MJ_FLUSH_BUFFERS 0x09
  7934. #define IRP_MJ_QUERY_VOLUME_INFORMATION 0x0a
  7935. #define IRP_MJ_SET_VOLUME_INFORMATION 0x0b
  7936. #define IRP_MJ_DIRECTORY_CONTROL 0x0c
  7937. #define IRP_MJ_FILE_SYSTEM_CONTROL 0x0d
  7938. #define IRP_MJ_DEVICE_CONTROL 0x0e
  7939. #define IRP_MJ_INTERNAL_DEVICE_CONTROL 0x0f
  7940. #define IRP_MJ_SHUTDOWN 0x10
  7941. #define IRP_MJ_LOCK_CONTROL 0x11
  7942. #define IRP_MJ_CLEANUP 0x12
  7943. #define IRP_MJ_CREATE_MAILSLOT 0x13
  7944. #define IRP_MJ_QUERY_SECURITY 0x14
  7945. #define IRP_MJ_SET_SECURITY 0x15
  7946. #define IRP_MJ_POWER 0x16
  7947. #define IRP_MJ_SYSTEM_CONTROL 0x17
  7948. #define IRP_MJ_DEVICE_CHANGE 0x18
  7949. #define IRP_MJ_QUERY_QUOTA 0x19
  7950. #define IRP_MJ_SET_QUOTA 0x1a
  7951. #define IRP_MJ_PNP 0x1b
  7952. #define IRP_MJ_PNP_POWER IRP_MJ_PNP // Obsolete....
  7953. #define IRP_MJ_MAXIMUM_FUNCTION 0x1b
  7954. //
  7955. // Make the Scsi major code the same as internal device control.
  7956. //
  7957. #define IRP_MJ_SCSI IRP_MJ_INTERNAL_DEVICE_CONTROL
  7958. //
  7959. // Define the minor function codes for IRPs. The lower 128 codes, from 0x00 to
  7960. // 0x7f are reserved to Microsoft. The upper 128 codes, from 0x80 to 0xff, are
  7961. // reserved to customers of Microsoft.
  7962. //
  7963. // end_wdm end_ntndis
  7964. //
  7965. // Directory control minor function codes
  7966. //
  7967. #define IRP_MN_QUERY_DIRECTORY 0x01
  7968. #define IRP_MN_NOTIFY_CHANGE_DIRECTORY 0x02
  7969. //
  7970. // File system control minor function codes. Note that "user request" is
  7971. // assumed to be zero by both the I/O system and file systems. Do not change
  7972. // this value.
  7973. //
  7974. #define IRP_MN_USER_FS_REQUEST 0x00
  7975. #define IRP_MN_MOUNT_VOLUME 0x01
  7976. #define IRP_MN_VERIFY_VOLUME 0x02
  7977. #define IRP_MN_LOAD_FILE_SYSTEM 0x03
  7978. #define IRP_MN_TRACK_LINK 0x04 // To be obsoleted soon
  7979. #define IRP_MN_KERNEL_CALL 0x04
  7980. //
  7981. // Lock control minor function codes
  7982. //
  7983. #define IRP_MN_LOCK 0x01
  7984. #define IRP_MN_UNLOCK_SINGLE 0x02
  7985. #define IRP_MN_UNLOCK_ALL 0x03
  7986. #define IRP_MN_UNLOCK_ALL_BY_KEY 0x04
  7987. //
  7988. // Read and Write minor function codes for file systems supporting Lan Manager
  7989. // software. All of these subfunction codes are invalid if the file has been
  7990. // opened with FO_NO_INTERMEDIATE_BUFFERING. They are also invalid in combi-
  7991. // nation with synchronous calls (Irp Flag or file open option).
  7992. //
  7993. // Note that "normal" is assumed to be zero by both the I/O system and file
  7994. // systems. Do not change this value.
  7995. //
  7996. #define IRP_MN_NORMAL 0x00
  7997. #define IRP_MN_DPC 0x01
  7998. #define IRP_MN_MDL 0x02
  7999. #define IRP_MN_COMPLETE 0x04
  8000. #define IRP_MN_COMPRESSED 0x08
  8001. #define IRP_MN_MDL_DPC (IRP_MN_MDL | IRP_MN_DPC)
  8002. #define IRP_MN_COMPLETE_MDL (IRP_MN_COMPLETE | IRP_MN_MDL)
  8003. #define IRP_MN_COMPLETE_MDL_DPC (IRP_MN_COMPLETE_MDL | IRP_MN_DPC)
  8004. // begin_wdm
  8005. //
  8006. // Device Control Request minor function codes for SCSI support. Note that
  8007. // user requests are assumed to be zero.
  8008. //
  8009. #define IRP_MN_SCSI_CLASS 0x01
  8010. //
  8011. // PNP minor function codes.
  8012. //
  8013. #define IRP_MN_START_DEVICE 0x00
  8014. #define IRP_MN_QUERY_REMOVE_DEVICE 0x01
  8015. #define IRP_MN_REMOVE_DEVICE 0x02
  8016. #define IRP_MN_CANCEL_REMOVE_DEVICE 0x03
  8017. #define IRP_MN_STOP_DEVICE 0x04
  8018. #define IRP_MN_QUERY_STOP_DEVICE 0x05
  8019. #define IRP_MN_CANCEL_STOP_DEVICE 0x06
  8020. #define IRP_MN_QUERY_DEVICE_RELATIONS 0x07
  8021. #define IRP_MN_QUERY_INTERFACE 0x08
  8022. #define IRP_MN_QUERY_CAPABILITIES 0x09
  8023. #define IRP_MN_QUERY_RESOURCES 0x0A
  8024. #define IRP_MN_QUERY_RESOURCE_REQUIREMENTS 0x0B
  8025. #define IRP_MN_QUERY_DEVICE_TEXT 0x0C
  8026. #define IRP_MN_FILTER_RESOURCE_REQUIREMENTS 0x0D
  8027. #define IRP_MN_READ_CONFIG 0x0F
  8028. #define IRP_MN_WRITE_CONFIG 0x10
  8029. #define IRP_MN_EJECT 0x11
  8030. #define IRP_MN_SET_LOCK 0x12
  8031. #define IRP_MN_QUERY_ID 0x13
  8032. #define IRP_MN_QUERY_PNP_DEVICE_STATE 0x14
  8033. #define IRP_MN_QUERY_BUS_INFORMATION 0x15
  8034. #define IRP_MN_DEVICE_USAGE_NOTIFICATION 0x16
  8035. #define IRP_MN_SURPRISE_REMOVAL 0x17
  8036. // end_wdm
  8037. #define IRP_MN_QUERY_LEGACY_BUS_INFORMATION 0x18
  8038. // begin_wdm
  8039. //
  8040. // POWER minor function codes
  8041. //
  8042. #define IRP_MN_WAIT_WAKE 0x00
  8043. #define IRP_MN_POWER_SEQUENCE 0x01
  8044. #define IRP_MN_SET_POWER 0x02
  8045. #define IRP_MN_QUERY_POWER 0x03
  8046. // begin_ntminiport
  8047. //
  8048. // WMI minor function codes under IRP_MJ_SYSTEM_CONTROL
  8049. //
  8050. #define IRP_MN_QUERY_ALL_DATA 0x00
  8051. #define IRP_MN_QUERY_SINGLE_INSTANCE 0x01
  8052. #define IRP_MN_CHANGE_SINGLE_INSTANCE 0x02
  8053. #define IRP_MN_CHANGE_SINGLE_ITEM 0x03
  8054. #define IRP_MN_ENABLE_EVENTS 0x04
  8055. #define IRP_MN_DISABLE_EVENTS 0x05
  8056. #define IRP_MN_ENABLE_COLLECTION 0x06
  8057. #define IRP_MN_DISABLE_COLLECTION 0x07
  8058. #define IRP_MN_REGINFO 0x08
  8059. #define IRP_MN_EXECUTE_METHOD 0x09
  8060. // Minor code 0x0a is reserved
  8061. #define IRP_MN_REGINFO_EX 0x0b
  8062. // end_ntminiport
  8063. //
  8064. // Define option flags for IoCreateFile. Note that these values must be
  8065. // exactly the same as the SL_... flags for a create function. Note also
  8066. // that there are flags that may be passed to IoCreateFile that are not
  8067. // placed in the stack location for the create IRP. These flags start in
  8068. // the next byte.
  8069. //
  8070. #define IO_FORCE_ACCESS_CHECK 0x0001
  8071. #define IO_NO_PARAMETER_CHECKING 0x0100
  8072. //
  8073. // Define Information fields for whether or not a REPARSE or a REMOUNT has
  8074. // occurred in the file system.
  8075. //
  8076. #define IO_REPARSE 0x0
  8077. #define IO_REMOUNT 0x1
  8078. // end_ntddk end_wdm
  8079. #define IO_CHECK_CREATE_PARAMETERS 0x0200
  8080. #define IO_ATTACH_DEVICE 0x0400
  8081. //
  8082. // This flag is only meaning full to IoCreateFileSpecifyDeviceObjectHint.
  8083. // FileHandles created using IoCreateFileSpecifyDeviceObjectHint with this
  8084. // flag set will bypass ShareAccess checks on this file.
  8085. //
  8086. #define IO_IGNORE_SHARE_ACCESS_CHECK 0x0800 // Ignores share access checks on opens.
  8087. typedef
  8088. VOID
  8089. (*PSTALL_ROUTINE) (
  8090. IN ULONG Delay
  8091. );
  8092. //
  8093. // Define the interfaces for the dump driver's routines.
  8094. //
  8095. typedef
  8096. BOOLEAN
  8097. (*PDUMP_DRIVER_OPEN) (
  8098. IN LARGE_INTEGER PartitionOffset
  8099. );
  8100. typedef
  8101. NTSTATUS
  8102. (*PDUMP_DRIVER_WRITE) (
  8103. IN PLARGE_INTEGER DiskByteOffset,
  8104. IN PMDL Mdl
  8105. );
  8106. //
  8107. // Actions accepted by DRIVER_WRITE_PENDING
  8108. //
  8109. #define IO_DUMP_WRITE_FULFILL 0 // fulfill IO request as if DRIVER_WAIT
  8110. #define IO_DUMP_WRITE_START 1 // start new IO
  8111. #define IO_DUMP_WRITE_RESUME 2 // resume pending IO
  8112. #define IO_DUMP_WRITE_FINISH 3 // finish pending IO
  8113. #define IO_DUMP_WRITE_INIT 4 // initialize locals
  8114. // size of data used by WRITE_PENDING that should be preserved
  8115. // between the calls
  8116. #define IO_DUMP_WRITE_DATA_PAGES 2
  8117. #define IO_DUMP_WRITE_DATA_SIZE (IO_DUMP_WRITE_DATA_PAGES << PAGE_SHIFT)
  8118. typedef
  8119. NTSTATUS
  8120. (*PDUMP_DRIVER_WRITE_PENDING) (
  8121. IN LONG Action,
  8122. IN PLARGE_INTEGER DiskByteOffset,
  8123. IN PMDL Mdl,
  8124. IN PVOID LocalData
  8125. );
  8126. typedef
  8127. VOID
  8128. (*PDUMP_DRIVER_FINISH) (
  8129. VOID
  8130. );
  8131. struct _ADAPTER_OBJECT;
  8132. //
  8133. // This is the information passed from the system to the disk dump driver
  8134. // during the driver's initialization.
  8135. //
  8136. typedef struct _DUMP_INITIALIZATION_CONTEXT {
  8137. ULONG Length;
  8138. ULONG Reserved; // Was MBR Checksum. Should be zero now.
  8139. PVOID MemoryBlock;
  8140. PVOID CommonBuffer[2];
  8141. PHYSICAL_ADDRESS PhysicalAddress[2];
  8142. PSTALL_ROUTINE StallRoutine;
  8143. PDUMP_DRIVER_OPEN OpenRoutine;
  8144. PDUMP_DRIVER_WRITE WriteRoutine;
  8145. PDUMP_DRIVER_FINISH FinishRoutine;
  8146. struct _ADAPTER_OBJECT *AdapterObject;
  8147. PVOID MappedRegisterBase;
  8148. PVOID PortConfiguration;
  8149. BOOLEAN CrashDump;
  8150. ULONG MaximumTransferSize;
  8151. ULONG CommonBufferSize;
  8152. PVOID TargetAddress; //Opaque pointer to target address structure
  8153. PDUMP_DRIVER_WRITE_PENDING WritePendingRoutine;
  8154. ULONG PartitionStyle;
  8155. union {
  8156. struct {
  8157. ULONG Signature;
  8158. ULONG CheckSum;
  8159. } Mbr;
  8160. struct {
  8161. GUID DiskId;
  8162. } Gpt;
  8163. } DiskInfo;
  8164. } DUMP_INITIALIZATION_CONTEXT, *PDUMP_INITIALIZATION_CONTEXT;
  8165. // begin_ntddk
  8166. //
  8167. // Define callout routine type for use in IoQueryDeviceDescription().
  8168. //
  8169. typedef NTSTATUS (*PIO_QUERY_DEVICE_ROUTINE)(
  8170. IN PVOID Context,
  8171. IN PUNICODE_STRING PathName,
  8172. IN INTERFACE_TYPE BusType,
  8173. IN ULONG BusNumber,
  8174. IN PKEY_VALUE_FULL_INFORMATION *BusInformation,
  8175. IN CONFIGURATION_TYPE ControllerType,
  8176. IN ULONG ControllerNumber,
  8177. IN PKEY_VALUE_FULL_INFORMATION *ControllerInformation,
  8178. IN CONFIGURATION_TYPE PeripheralType,
  8179. IN ULONG PeripheralNumber,
  8180. IN PKEY_VALUE_FULL_INFORMATION *PeripheralInformation
  8181. );
  8182. // Defines the order of the information in the array of
  8183. // PKEY_VALUE_FULL_INFORMATION.
  8184. //
  8185. typedef enum _IO_QUERY_DEVICE_DATA_FORMAT {
  8186. IoQueryDeviceIdentifier = 0,
  8187. IoQueryDeviceConfigurationData,
  8188. IoQueryDeviceComponentInformation,
  8189. IoQueryDeviceMaxData
  8190. } IO_QUERY_DEVICE_DATA_FORMAT, *PIO_QUERY_DEVICE_DATA_FORMAT;
  8191. // begin_wdm begin_ntifs
  8192. //
  8193. // Define the objects that can be created by IoCreateFile.
  8194. //
  8195. typedef enum _CREATE_FILE_TYPE {
  8196. CreateFileTypeNone,
  8197. CreateFileTypeNamedPipe,
  8198. CreateFileTypeMailslot
  8199. } CREATE_FILE_TYPE;
  8200. // end_ntddk end_wdm end_ntifs
  8201. //
  8202. // Define the named pipe create parameters structure used for internal calls
  8203. // to IoCreateFile when a named pipe is being created. This structure allows
  8204. // code invoking this routine to pass information specific to this function
  8205. // when creating a named pipe.
  8206. //
  8207. typedef struct _NAMED_PIPE_CREATE_PARAMETERS {
  8208. ULONG NamedPipeType;
  8209. ULONG ReadMode;
  8210. ULONG CompletionMode;
  8211. ULONG MaximumInstances;
  8212. ULONG InboundQuota;
  8213. ULONG OutboundQuota;
  8214. LARGE_INTEGER DefaultTimeout;
  8215. BOOLEAN TimeoutSpecified;
  8216. } NAMED_PIPE_CREATE_PARAMETERS, *PNAMED_PIPE_CREATE_PARAMETERS;
  8217. //
  8218. // Define the structures used by the I/O system
  8219. //
  8220. //
  8221. // Define empty typedefs for the _IRP, _DEVICE_OBJECT, and _DRIVER_OBJECT
  8222. // structures so they may be referenced by function types before they are
  8223. // actually defined.
  8224. //
  8225. struct _DEVICE_DESCRIPTION;
  8226. struct _DEVICE_OBJECT;
  8227. struct _DMA_ADAPTER;
  8228. struct _DRIVER_OBJECT;
  8229. struct _DRIVE_LAYOUT_INFORMATION;
  8230. struct _DISK_PARTITION;
  8231. struct _FILE_OBJECT;
  8232. struct _IRP;
  8233. struct _SCSI_REQUEST_BLOCK;
  8234. struct _SCATTER_GATHER_LIST;
  8235. //
  8236. // Define the I/O version of a DPC routine.
  8237. //
  8238. typedef
  8239. VOID
  8240. (*PIO_DPC_ROUTINE) (
  8241. IN PKDPC Dpc,
  8242. IN struct _DEVICE_OBJECT *DeviceObject,
  8243. IN struct _IRP *Irp,
  8244. IN PVOID Context
  8245. );
  8246. //
  8247. // Define driver timer routine type.
  8248. //
  8249. typedef
  8250. VOID
  8251. (*PIO_TIMER_ROUTINE) (
  8252. IN struct _DEVICE_OBJECT *DeviceObject,
  8253. IN PVOID Context
  8254. );
  8255. //
  8256. // Define driver initialization routine type.
  8257. //
  8258. typedef
  8259. NTSTATUS
  8260. (*PDRIVER_INITIALIZE) (
  8261. IN struct _DRIVER_OBJECT *DriverObject,
  8262. IN PUNICODE_STRING RegistryPath
  8263. );
  8264. // end_wdm
  8265. //
  8266. // Define driver reinitialization routine type.
  8267. //
  8268. typedef
  8269. VOID
  8270. (*PDRIVER_REINITIALIZE) (
  8271. IN struct _DRIVER_OBJECT *DriverObject,
  8272. IN PVOID Context,
  8273. IN ULONG Count
  8274. );
  8275. // begin_wdm begin_ntndis
  8276. //
  8277. // Define driver cancel routine type.
  8278. //
  8279. typedef
  8280. VOID
  8281. (*PDRIVER_CANCEL) (
  8282. IN struct _DEVICE_OBJECT *DeviceObject,
  8283. IN struct _IRP *Irp
  8284. );
  8285. //
  8286. // Define driver dispatch routine type.
  8287. //
  8288. typedef
  8289. NTSTATUS
  8290. (*PDRIVER_DISPATCH) (
  8291. IN struct _DEVICE_OBJECT *DeviceObject,
  8292. IN struct _IRP *Irp
  8293. );
  8294. //
  8295. // Define driver start I/O routine type.
  8296. //
  8297. typedef
  8298. VOID
  8299. (*PDRIVER_STARTIO) (
  8300. IN struct _DEVICE_OBJECT *DeviceObject,
  8301. IN struct _IRP *Irp
  8302. );
  8303. //
  8304. // Define driver unload routine type.
  8305. //
  8306. typedef
  8307. VOID
  8308. (*PDRIVER_UNLOAD) (
  8309. IN struct _DRIVER_OBJECT *DriverObject
  8310. );
  8311. //
  8312. // Define driver AddDevice routine type.
  8313. //
  8314. typedef
  8315. NTSTATUS
  8316. (*PDRIVER_ADD_DEVICE) (
  8317. IN struct _DRIVER_OBJECT *DriverObject,
  8318. IN struct _DEVICE_OBJECT *PhysicalDeviceObject
  8319. );
  8320. //
  8321. // Define fast I/O procedure prototypes.
  8322. //
  8323. // Fast I/O read and write procedures.
  8324. //
  8325. typedef
  8326. BOOLEAN
  8327. (*PFAST_IO_CHECK_IF_POSSIBLE) (
  8328. IN struct _FILE_OBJECT *FileObject,
  8329. IN PLARGE_INTEGER FileOffset,
  8330. IN ULONG Length,
  8331. IN BOOLEAN Wait,
  8332. IN ULONG LockKey,
  8333. IN BOOLEAN CheckForReadOperation,
  8334. OUT PIO_STATUS_BLOCK IoStatus,
  8335. IN struct _DEVICE_OBJECT *DeviceObject
  8336. );
  8337. typedef
  8338. BOOLEAN
  8339. (*PFAST_IO_READ) (
  8340. IN struct _FILE_OBJECT *FileObject,
  8341. IN PLARGE_INTEGER FileOffset,
  8342. IN ULONG Length,
  8343. IN BOOLEAN Wait,
  8344. IN ULONG LockKey,
  8345. OUT PVOID Buffer,
  8346. OUT PIO_STATUS_BLOCK IoStatus,
  8347. IN struct _DEVICE_OBJECT *DeviceObject
  8348. );
  8349. typedef
  8350. BOOLEAN
  8351. (*PFAST_IO_WRITE) (
  8352. IN struct _FILE_OBJECT *FileObject,
  8353. IN PLARGE_INTEGER FileOffset,
  8354. IN ULONG Length,
  8355. IN BOOLEAN Wait,
  8356. IN ULONG LockKey,
  8357. IN PVOID Buffer,
  8358. OUT PIO_STATUS_BLOCK IoStatus,
  8359. IN struct _DEVICE_OBJECT *DeviceObject
  8360. );
  8361. //
  8362. // Fast I/O query basic and standard information procedures.
  8363. //
  8364. typedef
  8365. BOOLEAN
  8366. (*PFAST_IO_QUERY_BASIC_INFO) (
  8367. IN struct _FILE_OBJECT *FileObject,
  8368. IN BOOLEAN Wait,
  8369. OUT PFILE_BASIC_INFORMATION Buffer,
  8370. OUT PIO_STATUS_BLOCK IoStatus,
  8371. IN struct _DEVICE_OBJECT *DeviceObject
  8372. );
  8373. typedef
  8374. BOOLEAN
  8375. (*PFAST_IO_QUERY_STANDARD_INFO) (
  8376. IN struct _FILE_OBJECT *FileObject,
  8377. IN BOOLEAN Wait,
  8378. OUT PFILE_STANDARD_INFORMATION Buffer,
  8379. OUT PIO_STATUS_BLOCK IoStatus,
  8380. IN struct _DEVICE_OBJECT *DeviceObject
  8381. );
  8382. //
  8383. // Fast I/O lock and unlock procedures.
  8384. //
  8385. typedef
  8386. BOOLEAN
  8387. (*PFAST_IO_LOCK) (
  8388. IN struct _FILE_OBJECT *FileObject,
  8389. IN PLARGE_INTEGER FileOffset,
  8390. IN PLARGE_INTEGER Length,
  8391. PEPROCESS ProcessId,
  8392. ULONG Key,
  8393. BOOLEAN FailImmediately,
  8394. BOOLEAN ExclusiveLock,
  8395. OUT PIO_STATUS_BLOCK IoStatus,
  8396. IN struct _DEVICE_OBJECT *DeviceObject
  8397. );
  8398. typedef
  8399. BOOLEAN
  8400. (*PFAST_IO_UNLOCK_SINGLE) (
  8401. IN struct _FILE_OBJECT *FileObject,
  8402. IN PLARGE_INTEGER FileOffset,
  8403. IN PLARGE_INTEGER Length,
  8404. PEPROCESS ProcessId,
  8405. ULONG Key,
  8406. OUT PIO_STATUS_BLOCK IoStatus,
  8407. IN struct _DEVICE_OBJECT *DeviceObject
  8408. );
  8409. typedef
  8410. BOOLEAN
  8411. (*PFAST_IO_UNLOCK_ALL) (
  8412. IN struct _FILE_OBJECT *FileObject,
  8413. PEPROCESS ProcessId,
  8414. OUT PIO_STATUS_BLOCK IoStatus,
  8415. IN struct _DEVICE_OBJECT *DeviceObject
  8416. );
  8417. typedef
  8418. BOOLEAN
  8419. (*PFAST_IO_UNLOCK_ALL_BY_KEY) (
  8420. IN struct _FILE_OBJECT *FileObject,
  8421. PVOID ProcessId,
  8422. ULONG Key,
  8423. OUT PIO_STATUS_BLOCK IoStatus,
  8424. IN struct _DEVICE_OBJECT *DeviceObject
  8425. );
  8426. //
  8427. // Fast I/O device control procedure.
  8428. //
  8429. typedef
  8430. BOOLEAN
  8431. (*PFAST_IO_DEVICE_CONTROL) (
  8432. IN struct _FILE_OBJECT *FileObject,
  8433. IN BOOLEAN Wait,
  8434. IN PVOID InputBuffer OPTIONAL,
  8435. IN ULONG InputBufferLength,
  8436. OUT PVOID OutputBuffer OPTIONAL,
  8437. IN ULONG OutputBufferLength,
  8438. IN ULONG IoControlCode,
  8439. OUT PIO_STATUS_BLOCK IoStatus,
  8440. IN struct _DEVICE_OBJECT *DeviceObject
  8441. );
  8442. //
  8443. // Define callbacks for NtCreateSection to synchronize correctly with
  8444. // the file system. It pre-acquires the resources that will be needed
  8445. // when calling to query and set file/allocation size in the file system.
  8446. //
  8447. typedef
  8448. VOID
  8449. (*PFAST_IO_ACQUIRE_FILE) (
  8450. IN struct _FILE_OBJECT *FileObject
  8451. );
  8452. typedef
  8453. VOID
  8454. (*PFAST_IO_RELEASE_FILE) (
  8455. IN struct _FILE_OBJECT *FileObject
  8456. );
  8457. //
  8458. // Define callback for drivers that have device objects attached to lower-
  8459. // level drivers' device objects. This callback is made when the lower-level
  8460. // driver is deleting its device object.
  8461. //
  8462. typedef
  8463. VOID
  8464. (*PFAST_IO_DETACH_DEVICE) (
  8465. IN struct _DEVICE_OBJECT *SourceDevice,
  8466. IN struct _DEVICE_OBJECT *TargetDevice
  8467. );
  8468. //
  8469. // This structure is used by the server to quickly get the information needed
  8470. // to service a server open call. It is takes what would be two fast io calls
  8471. // one for basic information and the other for standard information and makes
  8472. // it into one call.
  8473. //
  8474. typedef
  8475. BOOLEAN
  8476. (*PFAST_IO_QUERY_NETWORK_OPEN_INFO) (
  8477. IN struct _FILE_OBJECT *FileObject,
  8478. IN BOOLEAN Wait,
  8479. OUT struct _FILE_NETWORK_OPEN_INFORMATION *Buffer,
  8480. OUT struct _IO_STATUS_BLOCK *IoStatus,
  8481. IN struct _DEVICE_OBJECT *DeviceObject
  8482. );
  8483. //
  8484. // Define Mdl-based routines for the server to call
  8485. //
  8486. typedef
  8487. BOOLEAN
  8488. (*PFAST_IO_MDL_READ) (
  8489. IN struct _FILE_OBJECT *FileObject,
  8490. IN PLARGE_INTEGER FileOffset,
  8491. IN ULONG Length,
  8492. IN ULONG LockKey,
  8493. OUT PMDL *MdlChain,
  8494. OUT PIO_STATUS_BLOCK IoStatus,
  8495. IN struct _DEVICE_OBJECT *DeviceObject
  8496. );
  8497. typedef
  8498. BOOLEAN
  8499. (*PFAST_IO_MDL_READ_COMPLETE) (
  8500. IN struct _FILE_OBJECT *FileObject,
  8501. IN PMDL MdlChain,
  8502. IN struct _DEVICE_OBJECT *DeviceObject
  8503. );
  8504. typedef
  8505. BOOLEAN
  8506. (*PFAST_IO_PREPARE_MDL_WRITE) (
  8507. IN struct _FILE_OBJECT *FileObject,
  8508. IN PLARGE_INTEGER FileOffset,
  8509. IN ULONG Length,
  8510. IN ULONG LockKey,
  8511. OUT PMDL *MdlChain,
  8512. OUT PIO_STATUS_BLOCK IoStatus,
  8513. IN struct _DEVICE_OBJECT *DeviceObject
  8514. );
  8515. typedef
  8516. BOOLEAN
  8517. (*PFAST_IO_MDL_WRITE_COMPLETE) (
  8518. IN struct _FILE_OBJECT *FileObject,
  8519. IN PLARGE_INTEGER FileOffset,
  8520. IN PMDL MdlChain,
  8521. IN struct _DEVICE_OBJECT *DeviceObject
  8522. );
  8523. //
  8524. // If this routine is present, it will be called by FsRtl
  8525. // to acquire the file for the mapped page writer.
  8526. //
  8527. typedef
  8528. NTSTATUS
  8529. (*PFAST_IO_ACQUIRE_FOR_MOD_WRITE) (
  8530. IN struct _FILE_OBJECT *FileObject,
  8531. IN PLARGE_INTEGER EndingOffset,
  8532. OUT struct _ERESOURCE **ResourceToRelease,
  8533. IN struct _DEVICE_OBJECT *DeviceObject
  8534. );
  8535. typedef
  8536. NTSTATUS
  8537. (*PFAST_IO_RELEASE_FOR_MOD_WRITE) (
  8538. IN struct _FILE_OBJECT *FileObject,
  8539. IN struct _ERESOURCE *ResourceToRelease,
  8540. IN struct _DEVICE_OBJECT *DeviceObject
  8541. );
  8542. //
  8543. // If this routine is present, it will be called by FsRtl
  8544. // to acquire the file for the mapped page writer.
  8545. //
  8546. typedef
  8547. NTSTATUS
  8548. (*PFAST_IO_ACQUIRE_FOR_CCFLUSH) (
  8549. IN struct _FILE_OBJECT *FileObject,
  8550. IN struct _DEVICE_OBJECT *DeviceObject
  8551. );
  8552. typedef
  8553. NTSTATUS
  8554. (*PFAST_IO_RELEASE_FOR_CCFLUSH) (
  8555. IN struct _FILE_OBJECT *FileObject,
  8556. IN struct _DEVICE_OBJECT *DeviceObject
  8557. );
  8558. typedef
  8559. BOOLEAN
  8560. (*PFAST_IO_READ_COMPRESSED) (
  8561. IN struct _FILE_OBJECT *FileObject,
  8562. IN PLARGE_INTEGER FileOffset,
  8563. IN ULONG Length,
  8564. IN ULONG LockKey,
  8565. OUT PVOID Buffer,
  8566. OUT PMDL *MdlChain,
  8567. OUT PIO_STATUS_BLOCK IoStatus,
  8568. OUT struct _COMPRESSED_DATA_INFO *CompressedDataInfo,
  8569. IN ULONG CompressedDataInfoLength,
  8570. IN struct _DEVICE_OBJECT *DeviceObject
  8571. );
  8572. typedef
  8573. BOOLEAN
  8574. (*PFAST_IO_WRITE_COMPRESSED) (
  8575. IN struct _FILE_OBJECT *FileObject,
  8576. IN PLARGE_INTEGER FileOffset,
  8577. IN ULONG Length,
  8578. IN ULONG LockKey,
  8579. IN PVOID Buffer,
  8580. OUT PMDL *MdlChain,
  8581. OUT PIO_STATUS_BLOCK IoStatus,
  8582. IN struct _COMPRESSED_DATA_INFO *CompressedDataInfo,
  8583. IN ULONG CompressedDataInfoLength,
  8584. IN struct _DEVICE_OBJECT *DeviceObject
  8585. );
  8586. typedef
  8587. BOOLEAN
  8588. (*PFAST_IO_MDL_READ_COMPLETE_COMPRESSED) (
  8589. IN struct _FILE_OBJECT *FileObject,
  8590. IN PMDL MdlChain,
  8591. IN struct _DEVICE_OBJECT *DeviceObject
  8592. );
  8593. typedef
  8594. BOOLEAN
  8595. (*PFAST_IO_MDL_WRITE_COMPLETE_COMPRESSED) (
  8596. IN struct _FILE_OBJECT *FileObject,
  8597. IN PLARGE_INTEGER FileOffset,
  8598. IN PMDL MdlChain,
  8599. IN struct _DEVICE_OBJECT *DeviceObject
  8600. );
  8601. typedef
  8602. BOOLEAN
  8603. (*PFAST_IO_QUERY_OPEN) (
  8604. IN struct _IRP *Irp,
  8605. OUT PFILE_NETWORK_OPEN_INFORMATION NetworkInformation,
  8606. IN struct _DEVICE_OBJECT *DeviceObject
  8607. );
  8608. //
  8609. // Define the structure to describe the Fast I/O dispatch routines. Any
  8610. // additions made to this structure MUST be added monotonically to the end
  8611. // of the structure, and fields CANNOT be removed from the middle.
  8612. //
  8613. typedef struct _FAST_IO_DISPATCH {
  8614. ULONG SizeOfFastIoDispatch;
  8615. PFAST_IO_CHECK_IF_POSSIBLE FastIoCheckIfPossible;
  8616. PFAST_IO_READ FastIoRead;
  8617. PFAST_IO_WRITE FastIoWrite;
  8618. PFAST_IO_QUERY_BASIC_INFO FastIoQueryBasicInfo;
  8619. PFAST_IO_QUERY_STANDARD_INFO FastIoQueryStandardInfo;
  8620. PFAST_IO_LOCK FastIoLock;
  8621. PFAST_IO_UNLOCK_SINGLE FastIoUnlockSingle;
  8622. PFAST_IO_UNLOCK_ALL FastIoUnlockAll;
  8623. PFAST_IO_UNLOCK_ALL_BY_KEY FastIoUnlockAllByKey;
  8624. PFAST_IO_DEVICE_CONTROL FastIoDeviceControl;
  8625. PFAST_IO_ACQUIRE_FILE AcquireFileForNtCreateSection;
  8626. PFAST_IO_RELEASE_FILE ReleaseFileForNtCreateSection;
  8627. PFAST_IO_DETACH_DEVICE FastIoDetachDevice;
  8628. PFAST_IO_QUERY_NETWORK_OPEN_INFO FastIoQueryNetworkOpenInfo;
  8629. PFAST_IO_ACQUIRE_FOR_MOD_WRITE AcquireForModWrite;
  8630. PFAST_IO_MDL_READ MdlRead;
  8631. PFAST_IO_MDL_READ_COMPLETE MdlReadComplete;
  8632. PFAST_IO_PREPARE_MDL_WRITE PrepareMdlWrite;
  8633. PFAST_IO_MDL_WRITE_COMPLETE MdlWriteComplete;
  8634. PFAST_IO_READ_COMPRESSED FastIoReadCompressed;
  8635. PFAST_IO_WRITE_COMPRESSED FastIoWriteCompressed;
  8636. PFAST_IO_MDL_READ_COMPLETE_COMPRESSED MdlReadCompleteCompressed;
  8637. PFAST_IO_MDL_WRITE_COMPLETE_COMPRESSED MdlWriteCompleteCompressed;
  8638. PFAST_IO_QUERY_OPEN FastIoQueryOpen;
  8639. PFAST_IO_RELEASE_FOR_MOD_WRITE ReleaseForModWrite;
  8640. PFAST_IO_ACQUIRE_FOR_CCFLUSH AcquireForCcFlush;
  8641. PFAST_IO_RELEASE_FOR_CCFLUSH ReleaseForCcFlush;
  8642. } FAST_IO_DISPATCH, *PFAST_IO_DISPATCH;
  8643. //
  8644. // Define the actions that a driver execution routine may request of the
  8645. // adapter/controller allocation routines upon return.
  8646. //
  8647. typedef enum _IO_ALLOCATION_ACTION {
  8648. KeepObject = 1,
  8649. DeallocateObject,
  8650. DeallocateObjectKeepRegisters
  8651. } IO_ALLOCATION_ACTION, *PIO_ALLOCATION_ACTION;
  8652. //
  8653. // Define device driver adapter/controller execution routine.
  8654. //
  8655. typedef
  8656. IO_ALLOCATION_ACTION
  8657. (*PDRIVER_CONTROL) (
  8658. IN struct _DEVICE_OBJECT *DeviceObject,
  8659. IN struct _IRP *Irp,
  8660. IN PVOID MapRegisterBase,
  8661. IN PVOID Context
  8662. );
  8663. //
  8664. // Define the I/O system's security context type for use by file system's
  8665. // when checking access to volumes, files, and directories.
  8666. //
  8667. typedef struct _IO_SECURITY_CONTEXT {
  8668. PSECURITY_QUALITY_OF_SERVICE SecurityQos;
  8669. PACCESS_STATE AccessState;
  8670. ACCESS_MASK DesiredAccess;
  8671. ULONG FullCreateOptions;
  8672. } IO_SECURITY_CONTEXT, *PIO_SECURITY_CONTEXT;
  8673. //
  8674. // Define Volume Parameter Block (VPB) flags.
  8675. //
  8676. #define VPB_MOUNTED 0x00000001
  8677. #define VPB_LOCKED 0x00000002
  8678. #define VPB_PERSISTENT 0x00000004
  8679. #define VPB_REMOVE_PENDING 0x00000008
  8680. #define VPB_RAW_MOUNT 0x00000010
  8681. //
  8682. // Volume Parameter Block (VPB)
  8683. //
  8684. #define MAXIMUM_VOLUME_LABEL_LENGTH (32 * sizeof(WCHAR)) // 32 characters
  8685. typedef struct _VPB {
  8686. CSHORT Type;
  8687. CSHORT Size;
  8688. USHORT Flags;
  8689. USHORT VolumeLabelLength; // in bytes
  8690. struct _DEVICE_OBJECT *DeviceObject;
  8691. struct _DEVICE_OBJECT *RealDevice;
  8692. ULONG SerialNumber;
  8693. ULONG ReferenceCount;
  8694. WCHAR VolumeLabel[MAXIMUM_VOLUME_LABEL_LENGTH / sizeof(WCHAR)];
  8695. } VPB, *PVPB;
  8696. #if defined(_WIN64)
  8697. //
  8698. // Use __inline DMA macros (hal.h)
  8699. //
  8700. #ifndef USE_DMA_MACROS
  8701. #define USE_DMA_MACROS
  8702. #endif
  8703. //
  8704. // Only PnP drivers!
  8705. //
  8706. #ifndef NO_LEGACY_DRIVERS
  8707. #define NO_LEGACY_DRIVERS
  8708. #endif
  8709. #endif // _WIN64
  8710. #if defined(USE_DMA_MACROS) && (defined(_NTDDK_) || defined(_NTDRIVER_) || defined(_NTOSP_))
  8711. // begin_wdm
  8712. //
  8713. // Define object type specific fields of various objects used by the I/O system
  8714. //
  8715. typedef struct _DMA_ADAPTER *PADAPTER_OBJECT;
  8716. // end_wdm
  8717. #else
  8718. //
  8719. // Define object type specific fields of various objects used by the I/O system
  8720. //
  8721. typedef struct _ADAPTER_OBJECT *PADAPTER_OBJECT; // ntndis
  8722. #endif // USE_DMA_MACROS && (_NTDDK_ || _NTDRIVER_ || _NTOSP_)
  8723. // begin_wdm
  8724. //
  8725. // Define Wait Context Block (WCB)
  8726. //
  8727. typedef struct _WAIT_CONTEXT_BLOCK {
  8728. KDEVICE_QUEUE_ENTRY WaitQueueEntry;
  8729. PDRIVER_CONTROL DeviceRoutine;
  8730. PVOID DeviceContext;
  8731. ULONG NumberOfMapRegisters;
  8732. PVOID DeviceObject;
  8733. PVOID CurrentIrp;
  8734. PKDPC BufferChainingDpc;
  8735. } WAIT_CONTEXT_BLOCK, *PWAIT_CONTEXT_BLOCK;
  8736. // end_wdm
  8737. typedef struct _CONTROLLER_OBJECT {
  8738. CSHORT Type;
  8739. CSHORT Size;
  8740. PVOID ControllerExtension;
  8741. KDEVICE_QUEUE DeviceWaitQueue;
  8742. ULONG Spare1;
  8743. LARGE_INTEGER Spare2;
  8744. } CONTROLLER_OBJECT, *PCONTROLLER_OBJECT;
  8745. // begin_wdm
  8746. //
  8747. // Define Device Object (DO) flags
  8748. //
  8749. // end_wdm end_ntddk end_nthal end_ntifs
  8750. #define DO_VERIFY_VOLUME 0x00000002 // ntddk nthal ntifs
  8751. #define DO_BUFFERED_IO 0x00000004 // ntddk nthal ntifs wdm
  8752. #define DO_EXCLUSIVE 0x00000008 // ntddk nthal ntifs wdm
  8753. #define DO_DIRECT_IO 0x00000010 // ntddk nthal ntifs wdm
  8754. #define DO_MAP_IO_BUFFER 0x00000020 // ntddk nthal ntifs wdm
  8755. #define DO_DEVICE_HAS_NAME 0x00000040 // ntddk nthal ntifs
  8756. #define DO_DEVICE_INITIALIZING 0x00000080 // ntddk nthal ntifs wdm
  8757. #define DO_SYSTEM_BOOT_PARTITION 0x00000100 // ntddk nthal ntifs
  8758. #define DO_LONG_TERM_REQUESTS 0x00000200 // ntddk nthal ntifs
  8759. #define DO_NEVER_LAST_DEVICE 0x00000400 // ntddk nthal ntifs
  8760. #define DO_SHUTDOWN_REGISTERED 0x00000800 // ntddk nthal ntifs wdm
  8761. #define DO_BUS_ENUMERATED_DEVICE 0x00001000 // ntddk nthal ntifs wdm
  8762. #define DO_POWER_PAGABLE 0x00002000 // ntddk nthal ntifs wdm
  8763. #define DO_POWER_INRUSH 0x00004000 // ntddk nthal ntifs wdm
  8764. #define DO_POWER_NOOP 0x00008000
  8765. #define DO_LOW_PRIORITY_FILESYSTEM 0x00010000 // ntddk nthal ntifs
  8766. #define DO_XIP 0x00020000
  8767. // begin_wdm begin_ntddk begin_nthal begin_ntifs
  8768. //
  8769. // Device Object structure definition
  8770. //
  8771. typedef struct DECLSPEC_ALIGN(MEMORY_ALLOCATION_ALIGNMENT) _DEVICE_OBJECT {
  8772. CSHORT Type;
  8773. USHORT Size;
  8774. LONG ReferenceCount;
  8775. struct _DRIVER_OBJECT *DriverObject;
  8776. struct _DEVICE_OBJECT *NextDevice;
  8777. struct _DEVICE_OBJECT *AttachedDevice;
  8778. struct _IRP *CurrentIrp;
  8779. PIO_TIMER Timer;
  8780. ULONG Flags; // See above: DO_...
  8781. ULONG Characteristics; // See ntioapi: FILE_...
  8782. PVPB Vpb;
  8783. PVOID DeviceExtension;
  8784. DEVICE_TYPE DeviceType;
  8785. CCHAR StackSize;
  8786. union {
  8787. LIST_ENTRY ListEntry;
  8788. WAIT_CONTEXT_BLOCK Wcb;
  8789. } Queue;
  8790. ULONG AlignmentRequirement;
  8791. KDEVICE_QUEUE DeviceQueue;
  8792. KDPC Dpc;
  8793. //
  8794. // The following field is for exclusive use by the filesystem to keep
  8795. // track of the number of Fsp threads currently using the device
  8796. //
  8797. ULONG ActiveThreadCount;
  8798. PSECURITY_DESCRIPTOR SecurityDescriptor;
  8799. KEVENT DeviceLock;
  8800. USHORT SectorSize;
  8801. USHORT Spare1;
  8802. struct _DEVOBJ_EXTENSION *DeviceObjectExtension;
  8803. PVOID Reserved;
  8804. } DEVICE_OBJECT;
  8805. typedef struct _DEVICE_OBJECT *PDEVICE_OBJECT; // ntndis
  8806. struct _DEVICE_OBJECT_POWER_EXTENSION;
  8807. typedef struct _DEVOBJ_EXTENSION {
  8808. CSHORT Type;
  8809. USHORT Size;
  8810. //
  8811. // Public part of the DeviceObjectExtension structure
  8812. //
  8813. PDEVICE_OBJECT DeviceObject; // owning device object
  8814. } DEVOBJ_EXTENSION, *PDEVOBJ_EXTENSION;
  8815. //
  8816. // Define Driver Object (DRVO) flags
  8817. //
  8818. #define DRVO_UNLOAD_INVOKED 0x00000001
  8819. #define DRVO_LEGACY_DRIVER 0x00000002
  8820. #define DRVO_BUILTIN_DRIVER 0x00000004 // Driver objects for Hal, PnP Mgr
  8821. // end_wdm
  8822. #define DRVO_REINIT_REGISTERED 0x00000008
  8823. #define DRVO_INITIALIZED 0x00000010
  8824. #define DRVO_BOOTREINIT_REGISTERED 0x00000020
  8825. #define DRVO_LEGACY_RESOURCES 0x00000040
  8826. // begin_wdm
  8827. typedef struct _DRIVER_EXTENSION {
  8828. //
  8829. // Back pointer to Driver Object
  8830. //
  8831. struct _DRIVER_OBJECT *DriverObject;
  8832. //
  8833. // The AddDevice entry point is called by the Plug & Play manager
  8834. // to inform the driver when a new device instance arrives that this
  8835. // driver must control.
  8836. //
  8837. PDRIVER_ADD_DEVICE AddDevice;
  8838. //
  8839. // The count field is used to count the number of times the driver has
  8840. // had its registered reinitialization routine invoked.
  8841. //
  8842. ULONG Count;
  8843. //
  8844. // The service name field is used by the pnp manager to determine
  8845. // where the driver related info is stored in the registry.
  8846. //
  8847. UNICODE_STRING ServiceKeyName;
  8848. //
  8849. // Note: any new shared fields get added here.
  8850. //
  8851. } DRIVER_EXTENSION, *PDRIVER_EXTENSION;
  8852. typedef struct _DRIVER_OBJECT {
  8853. CSHORT Type;
  8854. CSHORT Size;
  8855. //
  8856. // The following links all of the devices created by a single driver
  8857. // together on a list, and the Flags word provides an extensible flag
  8858. // location for driver objects.
  8859. //
  8860. PDEVICE_OBJECT DeviceObject;
  8861. ULONG Flags;
  8862. //
  8863. // The following section describes where the driver is loaded. The count
  8864. // field is used to count the number of times the driver has had its
  8865. // registered reinitialization routine invoked.
  8866. //
  8867. PVOID DriverStart;
  8868. ULONG DriverSize;
  8869. PVOID DriverSection;
  8870. PDRIVER_EXTENSION DriverExtension;
  8871. //
  8872. // The driver name field is used by the error log thread
  8873. // determine the name of the driver that an I/O request is/was bound.
  8874. //
  8875. UNICODE_STRING DriverName;
  8876. //
  8877. // The following section is for registry support. Thise is a pointer
  8878. // to the path to the hardware information in the registry
  8879. //
  8880. PUNICODE_STRING HardwareDatabase;
  8881. //
  8882. // The following section contains the optional pointer to an array of
  8883. // alternate entry points to a driver for "fast I/O" support. Fast I/O
  8884. // is performed by invoking the driver routine directly with separate
  8885. // parameters, rather than using the standard IRP call mechanism. Note
  8886. // that these functions may only be used for synchronous I/O, and when
  8887. // the file is cached.
  8888. //
  8889. PFAST_IO_DISPATCH FastIoDispatch;
  8890. //
  8891. // The following section describes the entry points to this particular
  8892. // driver. Note that the major function dispatch table must be the last
  8893. // field in the object so that it remains extensible.
  8894. //
  8895. PDRIVER_INITIALIZE DriverInit;
  8896. PDRIVER_STARTIO DriverStartIo;
  8897. PDRIVER_UNLOAD DriverUnload;
  8898. PDRIVER_DISPATCH MajorFunction[IRP_MJ_MAXIMUM_FUNCTION + 1];
  8899. } DRIVER_OBJECT;
  8900. typedef struct _DRIVER_OBJECT *PDRIVER_OBJECT; // ntndis
  8901. //
  8902. // The following structure is pointed to by the SectionObject pointer field
  8903. // of a file object, and is allocated by the various NT file systems.
  8904. //
  8905. typedef struct _SECTION_OBJECT_POINTERS {
  8906. PVOID DataSectionObject;
  8907. PVOID SharedCacheMap;
  8908. PVOID ImageSectionObject;
  8909. } SECTION_OBJECT_POINTERS;
  8910. typedef SECTION_OBJECT_POINTERS *PSECTION_OBJECT_POINTERS;
  8911. //
  8912. // Define the format of a completion message.
  8913. //
  8914. typedef struct _IO_COMPLETION_CONTEXT {
  8915. PVOID Port;
  8916. PVOID Key;
  8917. } IO_COMPLETION_CONTEXT, *PIO_COMPLETION_CONTEXT;
  8918. //
  8919. // Define File Object (FO) flags
  8920. //
  8921. #define FO_FILE_OPEN 0x00000001
  8922. #define FO_SYNCHRONOUS_IO 0x00000002
  8923. #define FO_ALERTABLE_IO 0x00000004
  8924. #define FO_NO_INTERMEDIATE_BUFFERING 0x00000008
  8925. #define FO_WRITE_THROUGH 0x00000010
  8926. #define FO_SEQUENTIAL_ONLY 0x00000020
  8927. #define FO_CACHE_SUPPORTED 0x00000040
  8928. #define FO_NAMED_PIPE 0x00000080
  8929. #define FO_STREAM_FILE 0x00000100
  8930. #define FO_MAILSLOT 0x00000200
  8931. #define FO_GENERATE_AUDIT_ON_CLOSE 0x00000400
  8932. #define FO_DIRECT_DEVICE_OPEN 0x00000800
  8933. #define FO_FILE_MODIFIED 0x00001000
  8934. #define FO_FILE_SIZE_CHANGED 0x00002000
  8935. #define FO_CLEANUP_COMPLETE 0x00004000
  8936. #define FO_TEMPORARY_FILE 0x00008000
  8937. #define FO_DELETE_ON_CLOSE 0x00010000
  8938. #define FO_OPENED_CASE_SENSITIVE 0x00020000
  8939. #define FO_HANDLE_CREATED 0x00040000
  8940. #define FO_FILE_FAST_IO_READ 0x00080000
  8941. #define FO_RANDOM_ACCESS 0x00100000
  8942. #define FO_FILE_OPEN_CANCELLED 0x00200000
  8943. #define FO_VOLUME_OPEN 0x00400000
  8944. #define FO_FILE_OBJECT_HAS_EXTENSION 0x00800000
  8945. #define FO_REMOTE_ORIGIN 0x01000000
  8946. typedef struct _FILE_OBJECT {
  8947. CSHORT Type;
  8948. CSHORT Size;
  8949. PDEVICE_OBJECT DeviceObject;
  8950. PVPB Vpb;
  8951. PVOID FsContext;
  8952. PVOID FsContext2;
  8953. PSECTION_OBJECT_POINTERS SectionObjectPointer;
  8954. PVOID PrivateCacheMap;
  8955. NTSTATUS FinalStatus;
  8956. struct _FILE_OBJECT *RelatedFileObject;
  8957. BOOLEAN LockOperation;
  8958. BOOLEAN DeletePending;
  8959. BOOLEAN ReadAccess;
  8960. BOOLEAN WriteAccess;
  8961. BOOLEAN DeleteAccess;
  8962. BOOLEAN SharedRead;
  8963. BOOLEAN SharedWrite;
  8964. BOOLEAN SharedDelete;
  8965. ULONG Flags;
  8966. UNICODE_STRING FileName;
  8967. LARGE_INTEGER CurrentByteOffset;
  8968. ULONG Waiters;
  8969. ULONG Busy;
  8970. PVOID LastLock;
  8971. KEVENT Lock;
  8972. KEVENT Event;
  8973. PIO_COMPLETION_CONTEXT CompletionContext;
  8974. } FILE_OBJECT;
  8975. typedef struct _FILE_OBJECT *PFILE_OBJECT; // ntndis
  8976. //
  8977. // Define I/O Request Packet (IRP) flags
  8978. //
  8979. #define IRP_NOCACHE 0x00000001
  8980. #define IRP_PAGING_IO 0x00000002
  8981. #define IRP_MOUNT_COMPLETION 0x00000002
  8982. #define IRP_SYNCHRONOUS_API 0x00000004
  8983. #define IRP_ASSOCIATED_IRP 0x00000008
  8984. #define IRP_BUFFERED_IO 0x00000010
  8985. #define IRP_DEALLOCATE_BUFFER 0x00000020
  8986. #define IRP_INPUT_OPERATION 0x00000040
  8987. #define IRP_SYNCHRONOUS_PAGING_IO 0x00000040
  8988. #define IRP_CREATE_OPERATION 0x00000080
  8989. #define IRP_READ_OPERATION 0x00000100
  8990. #define IRP_WRITE_OPERATION 0x00000200
  8991. #define IRP_CLOSE_OPERATION 0x00000400
  8992. // end_wdm
  8993. #define IRP_DEFER_IO_COMPLETION 0x00000800
  8994. #define IRP_OB_QUERY_NAME 0x00001000
  8995. #define IRP_HOLD_DEVICE_QUEUE 0x00002000
  8996. #define IRP_RETRY_IO_COMPLETION 0x00004000
  8997. #define IRP_CLASS_CACHE_OPERATION 0x00008000
  8998. #define IRP_SET_USER_EVENT IRP_CLOSE_OPERATION
  8999. // begin_wdm
  9000. //
  9001. // Define I/O request packet (IRP) alternate flags for allocation control.
  9002. //
  9003. #define IRP_QUOTA_CHARGED 0x01
  9004. #define IRP_ALLOCATED_MUST_SUCCEED 0x02
  9005. #define IRP_ALLOCATED_FIXED_SIZE 0x04
  9006. #define IRP_LOOKASIDE_ALLOCATION 0x08
  9007. //
  9008. // I/O Request Packet (IRP) definition
  9009. //
  9010. typedef struct _IRP {
  9011. CSHORT Type;
  9012. USHORT Size;
  9013. //
  9014. // Define the common fields used to control the IRP.
  9015. //
  9016. //
  9017. // Define a pointer to the Memory Descriptor List (MDL) for this I/O
  9018. // request. This field is only used if the I/O is "direct I/O".
  9019. //
  9020. PMDL MdlAddress;
  9021. //
  9022. // Flags word - used to remember various flags.
  9023. //
  9024. ULONG Flags;
  9025. //
  9026. // The following union is used for one of three purposes:
  9027. //
  9028. // 1. This IRP is an associated IRP. The field is a pointer to a master
  9029. // IRP.
  9030. //
  9031. // 2. This is the master IRP. The field is the count of the number of
  9032. // IRPs which must complete (associated IRPs) before the master can
  9033. // complete.
  9034. //
  9035. // 3. This operation is being buffered and the field is the address of
  9036. // the system space buffer.
  9037. //
  9038. union {
  9039. struct _IRP *MasterIrp;
  9040. LONG IrpCount;
  9041. PVOID SystemBuffer;
  9042. } AssociatedIrp;
  9043. //
  9044. // Thread list entry - allows queueing the IRP to the thread pending I/O
  9045. // request packet list.
  9046. //
  9047. LIST_ENTRY ThreadListEntry;
  9048. //
  9049. // I/O status - final status of operation.
  9050. //
  9051. IO_STATUS_BLOCK IoStatus;
  9052. //
  9053. // Requestor mode - mode of the original requestor of this operation.
  9054. //
  9055. KPROCESSOR_MODE RequestorMode;
  9056. //
  9057. // Pending returned - TRUE if pending was initially returned as the
  9058. // status for this packet.
  9059. //
  9060. BOOLEAN PendingReturned;
  9061. //
  9062. // Stack state information.
  9063. //
  9064. CHAR StackCount;
  9065. CHAR CurrentLocation;
  9066. //
  9067. // Cancel - packet has been canceled.
  9068. //
  9069. BOOLEAN Cancel;
  9070. //
  9071. // Cancel Irql - Irql at which the cancel spinlock was acquired.
  9072. //
  9073. KIRQL CancelIrql;
  9074. //
  9075. // ApcEnvironment - Used to save the APC environment at the time that the
  9076. // packet was initialized.
  9077. //
  9078. CCHAR ApcEnvironment;
  9079. //
  9080. // Allocation control flags.
  9081. //
  9082. UCHAR AllocationFlags;
  9083. //
  9084. // User parameters.
  9085. //
  9086. PIO_STATUS_BLOCK UserIosb;
  9087. PKEVENT UserEvent;
  9088. union {
  9089. struct {
  9090. PIO_APC_ROUTINE UserApcRoutine;
  9091. PVOID UserApcContext;
  9092. } AsynchronousParameters;
  9093. LARGE_INTEGER AllocationSize;
  9094. } Overlay;
  9095. //
  9096. // CancelRoutine - Used to contain the address of a cancel routine supplied
  9097. // by a device driver when the IRP is in a cancelable state.
  9098. //
  9099. PDRIVER_CANCEL CancelRoutine;
  9100. //
  9101. // Note that the UserBuffer parameter is outside of the stack so that I/O
  9102. // completion can copy data back into the user's address space without
  9103. // having to know exactly which service was being invoked. The length
  9104. // of the copy is stored in the second half of the I/O status block. If
  9105. // the UserBuffer field is NULL, then no copy is performed.
  9106. //
  9107. PVOID UserBuffer;
  9108. //
  9109. // Kernel structures
  9110. //
  9111. // The following section contains kernel structures which the IRP needs
  9112. // in order to place various work information in kernel controller system
  9113. // queues. Because the size and alignment cannot be controlled, they are
  9114. // placed here at the end so they just hang off and do not affect the
  9115. // alignment of other fields in the IRP.
  9116. //
  9117. union {
  9118. struct {
  9119. union {
  9120. //
  9121. // DeviceQueueEntry - The device queue entry field is used to
  9122. // queue the IRP to the device driver device queue.
  9123. //
  9124. KDEVICE_QUEUE_ENTRY DeviceQueueEntry;
  9125. struct {
  9126. //
  9127. // The following are available to the driver to use in
  9128. // whatever manner is desired, while the driver owns the
  9129. // packet.
  9130. //
  9131. PVOID DriverContext[4];
  9132. } ;
  9133. } ;
  9134. //
  9135. // Thread - pointer to caller's Thread Control Block.
  9136. //
  9137. PETHREAD Thread;
  9138. //
  9139. // Auxiliary buffer - pointer to any auxiliary buffer that is
  9140. // required to pass information to a driver that is not contained
  9141. // in a normal buffer.
  9142. //
  9143. PCHAR AuxiliaryBuffer;
  9144. //
  9145. // The following unnamed structure must be exactly identical
  9146. // to the unnamed structure used in the minipacket header used
  9147. // for completion queue entries.
  9148. //
  9149. struct {
  9150. //
  9151. // List entry - used to queue the packet to completion queue, among
  9152. // others.
  9153. //
  9154. LIST_ENTRY ListEntry;
  9155. union {
  9156. //
  9157. // Current stack location - contains a pointer to the current
  9158. // IO_STACK_LOCATION structure in the IRP stack. This field
  9159. // should never be directly accessed by drivers. They should
  9160. // use the standard functions.
  9161. //
  9162. struct _IO_STACK_LOCATION *CurrentStackLocation;
  9163. //
  9164. // Minipacket type.
  9165. //
  9166. ULONG PacketType;
  9167. };
  9168. };
  9169. //
  9170. // Original file object - pointer to the original file object
  9171. // that was used to open the file. This field is owned by the
  9172. // I/O system and should not be used by any other drivers.
  9173. //
  9174. PFILE_OBJECT OriginalFileObject;
  9175. } Overlay;
  9176. //
  9177. // APC - This APC control block is used for the special kernel APC as
  9178. // well as for the caller's APC, if one was specified in the original
  9179. // argument list. If so, then the APC is reused for the normal APC for
  9180. // whatever mode the caller was in and the "special" routine that is
  9181. // invoked before the APC gets control simply deallocates the IRP.
  9182. //
  9183. KAPC Apc;
  9184. //
  9185. // CompletionKey - This is the key that is used to distinguish
  9186. // individual I/O operations initiated on a single file handle.
  9187. //
  9188. PVOID CompletionKey;
  9189. } Tail;
  9190. } IRP, *PIRP;
  9191. //
  9192. // Define completion routine types for use in stack locations in an IRP
  9193. //
  9194. typedef
  9195. NTSTATUS
  9196. (*PIO_COMPLETION_ROUTINE) (
  9197. IN PDEVICE_OBJECT DeviceObject,
  9198. IN PIRP Irp,
  9199. IN PVOID Context
  9200. );
  9201. //
  9202. // Define stack location control flags
  9203. //
  9204. #define SL_PENDING_RETURNED 0x01
  9205. #define SL_INVOKE_ON_CANCEL 0x20
  9206. #define SL_INVOKE_ON_SUCCESS 0x40
  9207. #define SL_INVOKE_ON_ERROR 0x80
  9208. //
  9209. // Define flags for various functions
  9210. //
  9211. //
  9212. // Create / Create Named Pipe
  9213. //
  9214. // The following flags must exactly match those in the IoCreateFile call's
  9215. // options. The case sensitive flag is added in later, by the parse routine,
  9216. // and is not an actual option to open. Rather, it is part of the object
  9217. // manager's attributes structure.
  9218. //
  9219. #define SL_FORCE_ACCESS_CHECK 0x01
  9220. #define SL_OPEN_PAGING_FILE 0x02
  9221. #define SL_OPEN_TARGET_DIRECTORY 0x04
  9222. #define SL_CASE_SENSITIVE 0x80
  9223. //
  9224. // Read / Write
  9225. //
  9226. #define SL_KEY_SPECIFIED 0x01
  9227. #define SL_OVERRIDE_VERIFY_VOLUME 0x02
  9228. #define SL_WRITE_THROUGH 0x04
  9229. #define SL_FT_SEQUENTIAL_WRITE 0x08
  9230. //
  9231. // Device I/O Control
  9232. //
  9233. //
  9234. // Same SL_OVERRIDE_VERIFY_VOLUME as for read/write above.
  9235. //
  9236. #define SL_READ_ACCESS_GRANTED 0x01
  9237. #define SL_WRITE_ACCESS_GRANTED 0x04 // Gap for SL_OVERRIDE_VERIFY_VOLUME
  9238. //
  9239. // Lock
  9240. //
  9241. #define SL_FAIL_IMMEDIATELY 0x01
  9242. #define SL_EXCLUSIVE_LOCK 0x02
  9243. //
  9244. // QueryDirectory / QueryEa / QueryQuota
  9245. //
  9246. #define SL_RESTART_SCAN 0x01
  9247. #define SL_RETURN_SINGLE_ENTRY 0x02
  9248. #define SL_INDEX_SPECIFIED 0x04
  9249. //
  9250. // NotifyDirectory
  9251. //
  9252. #define SL_WATCH_TREE 0x01
  9253. //
  9254. // FileSystemControl
  9255. //
  9256. // minor: mount/verify volume
  9257. //
  9258. #define SL_ALLOW_RAW_MOUNT 0x01
  9259. //
  9260. // Define PNP/POWER types required by IRP_MJ_PNP/IRP_MJ_POWER.
  9261. //
  9262. typedef enum _DEVICE_RELATION_TYPE {
  9263. BusRelations,
  9264. EjectionRelations,
  9265. PowerRelations,
  9266. RemovalRelations,
  9267. TargetDeviceRelation,
  9268. SingleBusRelations
  9269. } DEVICE_RELATION_TYPE, *PDEVICE_RELATION_TYPE;
  9270. typedef struct _DEVICE_RELATIONS {
  9271. ULONG Count;
  9272. PDEVICE_OBJECT Objects[1]; // variable length
  9273. } DEVICE_RELATIONS, *PDEVICE_RELATIONS;
  9274. typedef enum _DEVICE_USAGE_NOTIFICATION_TYPE {
  9275. DeviceUsageTypeUndefined,
  9276. DeviceUsageTypePaging,
  9277. DeviceUsageTypeHibernation,
  9278. DeviceUsageTypeDumpFile
  9279. } DEVICE_USAGE_NOTIFICATION_TYPE;
  9280. // begin_ntminiport
  9281. // workaround overloaded definition (rpc generated headers all define INTERFACE
  9282. // to match the class name).
  9283. #undef INTERFACE
  9284. typedef struct _INTERFACE {
  9285. USHORT Size;
  9286. USHORT Version;
  9287. PVOID Context;
  9288. PINTERFACE_REFERENCE InterfaceReference;
  9289. PINTERFACE_DEREFERENCE InterfaceDereference;
  9290. // interface specific entries go here
  9291. } INTERFACE, *PINTERFACE;
  9292. // end_ntminiport
  9293. typedef struct _DEVICE_CAPABILITIES {
  9294. USHORT Size;
  9295. USHORT Version; // the version documented here is version 1
  9296. ULONG DeviceD1:1;
  9297. ULONG DeviceD2:1;
  9298. ULONG LockSupported:1;
  9299. ULONG EjectSupported:1; // Ejectable in S0
  9300. ULONG Removable:1;
  9301. ULONG DockDevice:1;
  9302. ULONG UniqueID:1;
  9303. ULONG SilentInstall:1;
  9304. ULONG RawDeviceOK:1;
  9305. ULONG SurpriseRemovalOK:1;
  9306. ULONG WakeFromD0:1;
  9307. ULONG WakeFromD1:1;
  9308. ULONG WakeFromD2:1;
  9309. ULONG WakeFromD3:1;
  9310. ULONG HardwareDisabled:1;
  9311. ULONG NonDynamic:1;
  9312. ULONG WarmEjectSupported:1;
  9313. ULONG NoDisplayInUI:1;
  9314. ULONG Reserved:14;
  9315. ULONG Address;
  9316. ULONG UINumber;
  9317. DEVICE_POWER_STATE DeviceState[POWER_SYSTEM_MAXIMUM];
  9318. SYSTEM_POWER_STATE SystemWake;
  9319. DEVICE_POWER_STATE DeviceWake;
  9320. ULONG D1Latency;
  9321. ULONG D2Latency;
  9322. ULONG D3Latency;
  9323. } DEVICE_CAPABILITIES, *PDEVICE_CAPABILITIES;
  9324. typedef struct _POWER_SEQUENCE {
  9325. ULONG SequenceD1;
  9326. ULONG SequenceD2;
  9327. ULONG SequenceD3;
  9328. } POWER_SEQUENCE, *PPOWER_SEQUENCE;
  9329. typedef enum {
  9330. BusQueryDeviceID = 0, // <Enumerator>\<Enumerator-specific device id>
  9331. BusQueryHardwareIDs = 1, // Hardware ids
  9332. BusQueryCompatibleIDs = 2, // compatible device ids
  9333. BusQueryInstanceID = 3, // persistent id for this instance of the device
  9334. BusQueryDeviceSerialNumber = 4 // serial number for this device
  9335. } BUS_QUERY_ID_TYPE, *PBUS_QUERY_ID_TYPE;
  9336. typedef ULONG PNP_DEVICE_STATE, *PPNP_DEVICE_STATE;
  9337. #define PNP_DEVICE_DISABLED 0x00000001
  9338. #define PNP_DEVICE_DONT_DISPLAY_IN_UI 0x00000002
  9339. #define PNP_DEVICE_FAILED 0x00000004
  9340. #define PNP_DEVICE_REMOVED 0x00000008
  9341. #define PNP_DEVICE_RESOURCE_REQUIREMENTS_CHANGED 0x00000010
  9342. #define PNP_DEVICE_NOT_DISABLEABLE 0x00000020
  9343. typedef enum {
  9344. DeviceTextDescription = 0, // DeviceDesc property
  9345. DeviceTextLocationInformation = 1 // DeviceLocation property
  9346. } DEVICE_TEXT_TYPE, *PDEVICE_TEXT_TYPE;
  9347. //
  9348. // Define I/O Request Packet (IRP) stack locations
  9349. //
  9350. #if !defined(_AMD64_) && !defined(_IA64_)
  9351. #include "pshpack4.h"
  9352. #endif
  9353. // begin_ntndis
  9354. #if defined(_WIN64)
  9355. #define POINTER_ALIGNMENT DECLSPEC_ALIGN(8)
  9356. #else
  9357. #define POINTER_ALIGNMENT
  9358. #endif
  9359. // end_ntndis
  9360. typedef struct _IO_STACK_LOCATION {
  9361. UCHAR MajorFunction;
  9362. UCHAR MinorFunction;
  9363. UCHAR Flags;
  9364. UCHAR Control;
  9365. //
  9366. // The following user parameters are based on the service that is being
  9367. // invoked. Drivers and file systems can determine which set to use based
  9368. // on the above major and minor function codes.
  9369. //
  9370. union {
  9371. //
  9372. // System service parameters for: NtCreateFile
  9373. //
  9374. struct {
  9375. PIO_SECURITY_CONTEXT SecurityContext;
  9376. ULONG Options;
  9377. USHORT POINTER_ALIGNMENT FileAttributes;
  9378. USHORT ShareAccess;
  9379. ULONG POINTER_ALIGNMENT EaLength;
  9380. } Create;
  9381. //
  9382. // System service parameters for: NtReadFile
  9383. //
  9384. struct {
  9385. ULONG Length;
  9386. ULONG POINTER_ALIGNMENT Key;
  9387. LARGE_INTEGER ByteOffset;
  9388. } Read;
  9389. //
  9390. // System service parameters for: NtWriteFile
  9391. //
  9392. struct {
  9393. ULONG Length;
  9394. ULONG POINTER_ALIGNMENT Key;
  9395. LARGE_INTEGER ByteOffset;
  9396. } Write;
  9397. // end_ntddk end_wdm end_nthal
  9398. //
  9399. // System service parameters for: NtQueryDirectoryFile
  9400. //
  9401. struct {
  9402. ULONG Length;
  9403. PSTRING FileName;
  9404. FILE_INFORMATION_CLASS FileInformationClass;
  9405. ULONG POINTER_ALIGNMENT FileIndex;
  9406. } QueryDirectory;
  9407. //
  9408. // System service parameters for: NtNotifyChangeDirectoryFile
  9409. //
  9410. struct {
  9411. ULONG Length;
  9412. ULONG POINTER_ALIGNMENT CompletionFilter;
  9413. } NotifyDirectory;
  9414. // begin_ntddk begin_wdm begin_nthal
  9415. //
  9416. // System service parameters for: NtQueryInformationFile
  9417. //
  9418. struct {
  9419. ULONG Length;
  9420. FILE_INFORMATION_CLASS POINTER_ALIGNMENT FileInformationClass;
  9421. } QueryFile;
  9422. //
  9423. // System service parameters for: NtSetInformationFile
  9424. //
  9425. struct {
  9426. ULONG Length;
  9427. FILE_INFORMATION_CLASS POINTER_ALIGNMENT FileInformationClass;
  9428. PFILE_OBJECT FileObject;
  9429. union {
  9430. struct {
  9431. BOOLEAN ReplaceIfExists;
  9432. BOOLEAN AdvanceOnly;
  9433. };
  9434. ULONG ClusterCount;
  9435. HANDLE DeleteHandle;
  9436. };
  9437. } SetFile;
  9438. //
  9439. // System service parameters for: NtQueryVolumeInformationFile
  9440. //
  9441. struct {
  9442. ULONG Length;
  9443. FS_INFORMATION_CLASS POINTER_ALIGNMENT FsInformationClass;
  9444. } QueryVolume;
  9445. //
  9446. // System service parameters for: NtFsControlFile
  9447. //
  9448. // Note that the user's output buffer is stored in the UserBuffer field
  9449. // and the user's input buffer is stored in the SystemBuffer field.
  9450. //
  9451. struct {
  9452. ULONG OutputBufferLength;
  9453. ULONG POINTER_ALIGNMENT InputBufferLength;
  9454. ULONG POINTER_ALIGNMENT FsControlCode;
  9455. PVOID Type3InputBuffer;
  9456. } FileSystemControl;
  9457. //
  9458. // System service parameters for: NtLockFile/NtUnlockFile
  9459. //
  9460. struct {
  9461. PLARGE_INTEGER Length;
  9462. ULONG POINTER_ALIGNMENT Key;
  9463. LARGE_INTEGER ByteOffset;
  9464. } LockControl;
  9465. // begin_ntddk begin_wdm begin_nthal
  9466. //
  9467. // System service parameters for: NtFlushBuffersFile
  9468. //
  9469. // No extra user-supplied parameters.
  9470. //
  9471. // end_ntddk end_wdm end_nthal
  9472. //
  9473. // System service parameters for: NtDeviceIoControlFile
  9474. //
  9475. // Note that the user's output buffer is stored in the UserBuffer field
  9476. // and the user's input buffer is stored in the SystemBuffer field.
  9477. //
  9478. struct {
  9479. ULONG OutputBufferLength;
  9480. ULONG POINTER_ALIGNMENT InputBufferLength;
  9481. ULONG POINTER_ALIGNMENT IoControlCode;
  9482. PVOID Type3InputBuffer;
  9483. } DeviceIoControl;
  9484. // end_wdm
  9485. //
  9486. // System service parameters for: NtQuerySecurityObject
  9487. //
  9488. struct {
  9489. SECURITY_INFORMATION SecurityInformation;
  9490. ULONG POINTER_ALIGNMENT Length;
  9491. } QuerySecurity;
  9492. //
  9493. // System service parameters for: NtSetSecurityObject
  9494. //
  9495. struct {
  9496. SECURITY_INFORMATION SecurityInformation;
  9497. PSECURITY_DESCRIPTOR SecurityDescriptor;
  9498. } SetSecurity;
  9499. // begin_wdm
  9500. //
  9501. // Non-system service parameters.
  9502. //
  9503. // Parameters for MountVolume
  9504. //
  9505. struct {
  9506. PVPB Vpb;
  9507. PDEVICE_OBJECT DeviceObject;
  9508. } MountVolume;
  9509. //
  9510. // Parameters for VerifyVolume
  9511. //
  9512. struct {
  9513. PVPB Vpb;
  9514. PDEVICE_OBJECT DeviceObject;
  9515. } VerifyVolume;
  9516. //
  9517. // Parameters for Scsi with internal device contorl.
  9518. //
  9519. struct {
  9520. struct _SCSI_REQUEST_BLOCK *Srb;
  9521. } Scsi;
  9522. //
  9523. // Parameters for IRP_MN_QUERY_DEVICE_RELATIONS
  9524. //
  9525. struct {
  9526. DEVICE_RELATION_TYPE Type;
  9527. } QueryDeviceRelations;
  9528. //
  9529. // Parameters for IRP_MN_QUERY_INTERFACE
  9530. //
  9531. struct {
  9532. CONST GUID *InterfaceType;
  9533. USHORT Size;
  9534. USHORT Version;
  9535. PINTERFACE Interface;
  9536. PVOID InterfaceSpecificData;
  9537. } QueryInterface;
  9538. // end_ntifs
  9539. //
  9540. // Parameters for IRP_MN_QUERY_CAPABILITIES
  9541. //
  9542. struct {
  9543. PDEVICE_CAPABILITIES Capabilities;
  9544. } DeviceCapabilities;
  9545. //
  9546. // Parameters for IRP_MN_FILTER_RESOURCE_REQUIREMENTS
  9547. //
  9548. struct {
  9549. PIO_RESOURCE_REQUIREMENTS_LIST IoResourceRequirementList;
  9550. } FilterResourceRequirements;
  9551. //
  9552. // Parameters for IRP_MN_READ_CONFIG and IRP_MN_WRITE_CONFIG
  9553. //
  9554. struct {
  9555. ULONG WhichSpace;
  9556. PVOID Buffer;
  9557. ULONG Offset;
  9558. ULONG POINTER_ALIGNMENT Length;
  9559. } ReadWriteConfig;
  9560. //
  9561. // Parameters for IRP_MN_SET_LOCK
  9562. //
  9563. struct {
  9564. BOOLEAN Lock;
  9565. } SetLock;
  9566. //
  9567. // Parameters for IRP_MN_QUERY_ID
  9568. //
  9569. struct {
  9570. BUS_QUERY_ID_TYPE IdType;
  9571. } QueryId;
  9572. //
  9573. // Parameters for IRP_MN_QUERY_DEVICE_TEXT
  9574. //
  9575. struct {
  9576. DEVICE_TEXT_TYPE DeviceTextType;
  9577. LCID POINTER_ALIGNMENT LocaleId;
  9578. } QueryDeviceText;
  9579. //
  9580. // Parameters for IRP_MN_DEVICE_USAGE_NOTIFICATION
  9581. //
  9582. struct {
  9583. BOOLEAN InPath;
  9584. BOOLEAN Reserved[3];
  9585. DEVICE_USAGE_NOTIFICATION_TYPE POINTER_ALIGNMENT Type;
  9586. } UsageNotification;
  9587. //
  9588. // Parameters for IRP_MN_WAIT_WAKE
  9589. //
  9590. struct {
  9591. SYSTEM_POWER_STATE PowerState;
  9592. } WaitWake;
  9593. //
  9594. // Parameter for IRP_MN_POWER_SEQUENCE
  9595. //
  9596. struct {
  9597. PPOWER_SEQUENCE PowerSequence;
  9598. } PowerSequence;
  9599. //
  9600. // Parameters for IRP_MN_SET_POWER and IRP_MN_QUERY_POWER
  9601. //
  9602. struct {
  9603. ULONG SystemContext;
  9604. POWER_STATE_TYPE POINTER_ALIGNMENT Type;
  9605. POWER_STATE POINTER_ALIGNMENT State;
  9606. POWER_ACTION POINTER_ALIGNMENT ShutdownType;
  9607. } Power;
  9608. //
  9609. // Parameters for StartDevice
  9610. //
  9611. struct {
  9612. PCM_RESOURCE_LIST AllocatedResources;
  9613. PCM_RESOURCE_LIST AllocatedResourcesTranslated;
  9614. } StartDevice;
  9615. // begin_ntifs
  9616. //
  9617. // Parameters for Cleanup
  9618. //
  9619. // No extra parameters supplied
  9620. //
  9621. //
  9622. // WMI Irps
  9623. //
  9624. struct {
  9625. ULONG_PTR ProviderId;
  9626. PVOID DataPath;
  9627. ULONG BufferSize;
  9628. PVOID Buffer;
  9629. } WMI;
  9630. //
  9631. // Others - driver-specific
  9632. //
  9633. struct {
  9634. PVOID Argument1;
  9635. PVOID Argument2;
  9636. PVOID Argument3;
  9637. PVOID Argument4;
  9638. } Others;
  9639. } Parameters;
  9640. //
  9641. // Save a pointer to this device driver's device object for this request
  9642. // so it can be passed to the completion routine if needed.
  9643. //
  9644. PDEVICE_OBJECT DeviceObject;
  9645. //
  9646. // The following location contains a pointer to the file object for this
  9647. //
  9648. PFILE_OBJECT FileObject;
  9649. //
  9650. // The following routine is invoked depending on the flags in the above
  9651. // flags field.
  9652. //
  9653. PIO_COMPLETION_ROUTINE CompletionRoutine;
  9654. //
  9655. // The following is used to store the address of the context parameter
  9656. // that should be passed to the CompletionRoutine.
  9657. //
  9658. PVOID Context;
  9659. } IO_STACK_LOCATION, *PIO_STACK_LOCATION;
  9660. #if !defined(_AMD64_) && !defined(_IA64_)
  9661. #include "poppack.h"
  9662. #endif
  9663. //
  9664. // Define the share access structure used by file systems to determine
  9665. // whether or not another accessor may open the file.
  9666. //
  9667. typedef struct _SHARE_ACCESS {
  9668. ULONG OpenCount;
  9669. ULONG Readers;
  9670. ULONG Writers;
  9671. ULONG Deleters;
  9672. ULONG SharedRead;
  9673. ULONG SharedWrite;
  9674. ULONG SharedDelete;
  9675. } SHARE_ACCESS, *PSHARE_ACCESS;
  9676. // end_wdm
  9677. //
  9678. // The following structure is used by drivers that are initializing to
  9679. // determine the number of devices of a particular type that have already
  9680. // been initialized. It is also used to track whether or not the AtDisk
  9681. // address range has already been claimed. Finally, it is used by the
  9682. // NtQuerySystemInformation system service to return device type counts.
  9683. //
  9684. typedef struct _CONFIGURATION_INFORMATION {
  9685. //
  9686. // This field indicates the total number of disks in the system. This
  9687. // number should be used by the driver to determine the name of new
  9688. // disks. This field should be updated by the driver as it finds new
  9689. // disks.
  9690. //
  9691. ULONG DiskCount; // Count of hard disks thus far
  9692. ULONG FloppyCount; // Count of floppy disks thus far
  9693. ULONG CdRomCount; // Count of CD-ROM drives thus far
  9694. ULONG TapeCount; // Count of tape drives thus far
  9695. ULONG ScsiPortCount; // Count of SCSI port adapters thus far
  9696. ULONG SerialCount; // Count of serial devices thus far
  9697. ULONG ParallelCount; // Count of parallel devices thus far
  9698. //
  9699. // These next two fields indicate ownership of one of the two IO address
  9700. // spaces that are used by WD1003-compatable disk controllers.
  9701. //
  9702. BOOLEAN AtDiskPrimaryAddressClaimed; // 0x1F0 - 0x1FF
  9703. BOOLEAN AtDiskSecondaryAddressClaimed; // 0x170 - 0x17F
  9704. //
  9705. // Indicates the structure version, as anything value belong this will have been added.
  9706. // Use the structure size as the version.
  9707. //
  9708. ULONG Version;
  9709. //
  9710. // Indicates the total number of medium changer devices in the system.
  9711. // This field will be updated by the drivers as it determines that
  9712. // new devices have been found and will be supported.
  9713. //
  9714. ULONG MediumChangerCount;
  9715. } CONFIGURATION_INFORMATION, *PCONFIGURATION_INFORMATION;
  9716. //
  9717. // Public I/O routine definitions
  9718. //
  9719. NTKERNELAPI
  9720. VOID
  9721. IoAcquireCancelSpinLock(
  9722. OUT PKIRQL Irql
  9723. );
  9724. DECLSPEC_DEPRECATED_DDK // Use AllocateAdapterChannel
  9725. NTKERNELAPI
  9726. NTSTATUS
  9727. IoAllocateAdapterChannel(
  9728. IN PADAPTER_OBJECT AdapterObject,
  9729. IN PDEVICE_OBJECT DeviceObject,
  9730. IN ULONG NumberOfMapRegisters,
  9731. IN PDRIVER_CONTROL ExecutionRoutine,
  9732. IN PVOID Context
  9733. );
  9734. NTKERNELAPI
  9735. VOID
  9736. IoAllocateController(
  9737. IN PCONTROLLER_OBJECT ControllerObject,
  9738. IN PDEVICE_OBJECT DeviceObject,
  9739. IN PDRIVER_CONTROL ExecutionRoutine,
  9740. IN PVOID Context
  9741. );
  9742. // begin_wdm
  9743. NTKERNELAPI
  9744. NTSTATUS
  9745. IoAllocateDriverObjectExtension(
  9746. IN PDRIVER_OBJECT DriverObject,
  9747. IN PVOID ClientIdentificationAddress,
  9748. IN ULONG DriverObjectExtensionSize,
  9749. OUT PVOID *DriverObjectExtension
  9750. );
  9751. // begin_ntifs
  9752. NTKERNELAPI
  9753. PVOID
  9754. IoAllocateErrorLogEntry(
  9755. IN PVOID IoObject,
  9756. IN UCHAR EntrySize
  9757. );
  9758. NTKERNELAPI
  9759. PIRP
  9760. IoAllocateIrp(
  9761. IN CCHAR StackSize,
  9762. IN BOOLEAN ChargeQuota
  9763. );
  9764. NTKERNELAPI
  9765. PMDL
  9766. IoAllocateMdl(
  9767. IN PVOID VirtualAddress,
  9768. IN ULONG Length,
  9769. IN BOOLEAN SecondaryBuffer,
  9770. IN BOOLEAN ChargeQuota,
  9771. IN OUT PIRP Irp OPTIONAL
  9772. );
  9773. // end_wdm end_ntifs
  9774. //++
  9775. //
  9776. // VOID
  9777. // IoAssignArcName(
  9778. // IN PUNICODE_STRING ArcName,
  9779. // IN PUNICODE_STRING DeviceName
  9780. // )
  9781. //
  9782. // Routine Description:
  9783. //
  9784. // This routine is invoked by drivers of bootable media to create a symbolic
  9785. // link between the ARC name of their device and its NT name. This allows
  9786. // the system to determine which device in the system was actually booted
  9787. // from since the ARC firmware only deals in ARC names, and NT only deals
  9788. // in NT names.
  9789. //
  9790. // Arguments:
  9791. //
  9792. // ArcName - Supplies the Unicode string representing the ARC name.
  9793. //
  9794. // DeviceName - Supplies the name to which the ARCname refers.
  9795. //
  9796. // Return Value:
  9797. //
  9798. // None.
  9799. //
  9800. //--
  9801. #define IoAssignArcName( ArcName, DeviceName ) ( \
  9802. IoCreateSymbolicLink( (ArcName), (DeviceName) ) )
  9803. DECLSPEC_DEPRECATED_DDK // Use Pnp or IoReprtDetectedDevice
  9804. NTKERNELAPI
  9805. NTSTATUS
  9806. IoAssignResources (
  9807. IN PUNICODE_STRING RegistryPath,
  9808. IN PUNICODE_STRING DriverClassName OPTIONAL,
  9809. IN PDRIVER_OBJECT DriverObject,
  9810. IN PDEVICE_OBJECT DeviceObject OPTIONAL,
  9811. IN PIO_RESOURCE_REQUIREMENTS_LIST RequestedResources,
  9812. IN OUT PCM_RESOURCE_LIST *AllocatedResources
  9813. );
  9814. NTKERNELAPI
  9815. NTSTATUS
  9816. IoAttachDevice(
  9817. IN PDEVICE_OBJECT SourceDevice,
  9818. IN PUNICODE_STRING TargetDevice,
  9819. OUT PDEVICE_OBJECT *AttachedDevice
  9820. );
  9821. // end_wdm
  9822. DECLSPEC_DEPRECATED_DDK // Use IoAttachDeviceToDeviceStack
  9823. NTKERNELAPI
  9824. NTSTATUS
  9825. IoAttachDeviceByPointer(
  9826. IN PDEVICE_OBJECT SourceDevice,
  9827. IN PDEVICE_OBJECT TargetDevice
  9828. );
  9829. // begin_wdm
  9830. NTKERNELAPI
  9831. PDEVICE_OBJECT
  9832. IoAttachDeviceToDeviceStack(
  9833. IN PDEVICE_OBJECT SourceDevice,
  9834. IN PDEVICE_OBJECT TargetDevice
  9835. );
  9836. NTKERNELAPI
  9837. PIRP
  9838. IoBuildAsynchronousFsdRequest(
  9839. IN ULONG MajorFunction,
  9840. IN PDEVICE_OBJECT DeviceObject,
  9841. IN OUT PVOID Buffer OPTIONAL,
  9842. IN ULONG Length OPTIONAL,
  9843. IN PLARGE_INTEGER StartingOffset OPTIONAL,
  9844. IN PIO_STATUS_BLOCK IoStatusBlock OPTIONAL
  9845. );
  9846. NTKERNELAPI
  9847. PIRP
  9848. IoBuildDeviceIoControlRequest(
  9849. IN ULONG IoControlCode,
  9850. IN PDEVICE_OBJECT DeviceObject,
  9851. IN PVOID InputBuffer OPTIONAL,
  9852. IN ULONG InputBufferLength,
  9853. OUT PVOID OutputBuffer OPTIONAL,
  9854. IN ULONG OutputBufferLength,
  9855. IN BOOLEAN InternalDeviceIoControl,
  9856. IN PKEVENT Event,
  9857. OUT PIO_STATUS_BLOCK IoStatusBlock
  9858. );
  9859. NTKERNELAPI
  9860. VOID
  9861. IoBuildPartialMdl(
  9862. IN PMDL SourceMdl,
  9863. IN OUT PMDL TargetMdl,
  9864. IN PVOID VirtualAddress,
  9865. IN ULONG Length
  9866. );
  9867. typedef struct _BOOTDISK_INFORMATION {
  9868. LONGLONG BootPartitionOffset;
  9869. LONGLONG SystemPartitionOffset;
  9870. ULONG BootDeviceSignature;
  9871. ULONG SystemDeviceSignature;
  9872. } BOOTDISK_INFORMATION, *PBOOTDISK_INFORMATION;
  9873. //
  9874. // This structure should follow the previous structure field for field.
  9875. //
  9876. typedef struct _BOOTDISK_INFORMATION_EX {
  9877. LONGLONG BootPartitionOffset;
  9878. LONGLONG SystemPartitionOffset;
  9879. ULONG BootDeviceSignature;
  9880. ULONG SystemDeviceSignature;
  9881. GUID BootDeviceGuid;
  9882. GUID SystemDeviceGuid;
  9883. BOOLEAN BootDeviceIsGpt;
  9884. BOOLEAN SystemDeviceIsGpt;
  9885. } BOOTDISK_INFORMATION_EX, *PBOOTDISK_INFORMATION_EX;
  9886. NTKERNELAPI
  9887. NTSTATUS
  9888. IoGetBootDiskInformation(
  9889. IN OUT PBOOTDISK_INFORMATION BootDiskInformation,
  9890. IN ULONG Size
  9891. );
  9892. NTKERNELAPI
  9893. PIRP
  9894. IoBuildSynchronousFsdRequest(
  9895. IN ULONG MajorFunction,
  9896. IN PDEVICE_OBJECT DeviceObject,
  9897. IN OUT PVOID Buffer OPTIONAL,
  9898. IN ULONG Length OPTIONAL,
  9899. IN PLARGE_INTEGER StartingOffset OPTIONAL,
  9900. IN PKEVENT Event,
  9901. OUT PIO_STATUS_BLOCK IoStatusBlock
  9902. );
  9903. NTKERNELAPI
  9904. NTSTATUS
  9905. FASTCALL
  9906. IofCallDriver(
  9907. IN PDEVICE_OBJECT DeviceObject,
  9908. IN OUT PIRP Irp
  9909. );
  9910. #define IoCallDriver(a,b) \
  9911. IofCallDriver(a,b)
  9912. NTKERNELAPI
  9913. BOOLEAN
  9914. IoCancelIrp(
  9915. IN PIRP Irp
  9916. );
  9917. NTKERNELAPI
  9918. NTSTATUS
  9919. IoCheckShareAccess(
  9920. IN ACCESS_MASK DesiredAccess,
  9921. IN ULONG DesiredShareAccess,
  9922. IN OUT PFILE_OBJECT FileObject,
  9923. IN OUT PSHARE_ACCESS ShareAccess,
  9924. IN BOOLEAN Update
  9925. );
  9926. //
  9927. // This value should be returned from completion routines to continue
  9928. // completing the IRP upwards. Otherwise, STATUS_MORE_PROCESSING_REQUIRED
  9929. // should be returned.
  9930. //
  9931. #define STATUS_CONTINUE_COMPLETION STATUS_SUCCESS
  9932. //
  9933. // Completion routines can also use this enumeration in place of status codes.
  9934. //
  9935. typedef enum _IO_COMPLETION_ROUTINE_RESULT {
  9936. ContinueCompletion = STATUS_CONTINUE_COMPLETION,
  9937. StopCompletion = STATUS_MORE_PROCESSING_REQUIRED
  9938. } IO_COMPLETION_ROUTINE_RESULT, *PIO_COMPLETION_ROUTINE_RESULT;
  9939. NTKERNELAPI
  9940. VOID
  9941. FASTCALL
  9942. IofCompleteRequest(
  9943. IN PIRP Irp,
  9944. IN CCHAR PriorityBoost
  9945. );
  9946. #define IoCompleteRequest(a,b) \
  9947. IofCompleteRequest(a,b)
  9948. // end_ntifs
  9949. NTKERNELAPI
  9950. NTSTATUS
  9951. IoConnectInterrupt(
  9952. OUT PKINTERRUPT *InterruptObject,
  9953. IN PKSERVICE_ROUTINE ServiceRoutine,
  9954. IN PVOID ServiceContext,
  9955. IN PKSPIN_LOCK SpinLock OPTIONAL,
  9956. IN ULONG Vector,
  9957. IN KIRQL Irql,
  9958. IN KIRQL SynchronizeIrql,
  9959. IN KINTERRUPT_MODE InterruptMode,
  9960. IN BOOLEAN ShareVector,
  9961. IN KAFFINITY ProcessorEnableMask,
  9962. IN BOOLEAN FloatingSave
  9963. );
  9964. // end_wdm
  9965. NTKERNELAPI
  9966. PCONTROLLER_OBJECT
  9967. IoCreateController(
  9968. IN ULONG Size
  9969. );
  9970. // begin_wdm begin_ntifs
  9971. NTKERNELAPI
  9972. NTSTATUS
  9973. IoCreateDevice(
  9974. IN PDRIVER_OBJECT DriverObject,
  9975. IN ULONG DeviceExtensionSize,
  9976. IN PUNICODE_STRING DeviceName OPTIONAL,
  9977. IN DEVICE_TYPE DeviceType,
  9978. IN ULONG DeviceCharacteristics,
  9979. IN BOOLEAN Exclusive,
  9980. OUT PDEVICE_OBJECT *DeviceObject
  9981. );
  9982. #define WDM_MAJORVERSION 0x01
  9983. #define WDM_MINORVERSION 0x20
  9984. NTKERNELAPI
  9985. BOOLEAN
  9986. IoIsWdmVersionAvailable(
  9987. IN UCHAR MajorVersion,
  9988. IN UCHAR MinorVersion
  9989. );
  9990. // end_nthal
  9991. NTKERNELAPI
  9992. NTSTATUS
  9993. IoCreateFile(
  9994. OUT PHANDLE FileHandle,
  9995. IN ACCESS_MASK DesiredAccess,
  9996. IN POBJECT_ATTRIBUTES ObjectAttributes,
  9997. OUT PIO_STATUS_BLOCK IoStatusBlock,
  9998. IN PLARGE_INTEGER AllocationSize OPTIONAL,
  9999. IN ULONG FileAttributes,
  10000. IN ULONG ShareAccess,
  10001. IN ULONG Disposition,
  10002. IN ULONG CreateOptions,
  10003. IN PVOID EaBuffer OPTIONAL,
  10004. IN ULONG EaLength,
  10005. IN CREATE_FILE_TYPE CreateFileType,
  10006. IN PVOID ExtraCreateParameters OPTIONAL,
  10007. IN ULONG Options
  10008. );
  10009. NTKERNELAPI
  10010. PKEVENT
  10011. IoCreateNotificationEvent(
  10012. IN PUNICODE_STRING EventName,
  10013. OUT PHANDLE EventHandle
  10014. );
  10015. NTKERNELAPI
  10016. NTSTATUS
  10017. IoCreateSymbolicLink(
  10018. IN PUNICODE_STRING SymbolicLinkName,
  10019. IN PUNICODE_STRING DeviceName
  10020. );
  10021. NTKERNELAPI
  10022. PKEVENT
  10023. IoCreateSynchronizationEvent(
  10024. IN PUNICODE_STRING EventName,
  10025. OUT PHANDLE EventHandle
  10026. );
  10027. NTKERNELAPI
  10028. NTSTATUS
  10029. IoCreateUnprotectedSymbolicLink(
  10030. IN PUNICODE_STRING SymbolicLinkName,
  10031. IN PUNICODE_STRING DeviceName
  10032. );
  10033. // end_wdm
  10034. //++
  10035. //
  10036. // VOID
  10037. // IoDeassignArcName(
  10038. // IN PUNICODE_STRING ArcName
  10039. // )
  10040. //
  10041. // Routine Description:
  10042. //
  10043. // This routine is invoked by drivers to deassign an ARC name that they
  10044. // created to a device. This is generally only called if the driver is
  10045. // deleting the device object, which means that the driver is probably
  10046. // unloading.
  10047. //
  10048. // Arguments:
  10049. //
  10050. // ArcName - Supplies the ARC name to be removed.
  10051. //
  10052. // Return Value:
  10053. //
  10054. // None.
  10055. //
  10056. //--
  10057. #define IoDeassignArcName( ArcName ) ( \
  10058. IoDeleteSymbolicLink( (ArcName) ) )
  10059. // end_ntifs
  10060. NTKERNELAPI
  10061. VOID
  10062. IoDeleteController(
  10063. IN PCONTROLLER_OBJECT ControllerObject
  10064. );
  10065. // begin_wdm begin_ntifs
  10066. NTKERNELAPI
  10067. VOID
  10068. IoDeleteDevice(
  10069. IN PDEVICE_OBJECT DeviceObject
  10070. );
  10071. NTKERNELAPI
  10072. NTSTATUS
  10073. IoDeleteSymbolicLink(
  10074. IN PUNICODE_STRING SymbolicLinkName
  10075. );
  10076. NTKERNELAPI
  10077. VOID
  10078. IoDetachDevice(
  10079. IN OUT PDEVICE_OBJECT TargetDevice
  10080. );
  10081. // end_ntifs
  10082. NTKERNELAPI
  10083. VOID
  10084. IoDisconnectInterrupt(
  10085. IN PKINTERRUPT InterruptObject
  10086. );
  10087. // end_ntddk end_wdm end_nthal
  10088. NTKERNELAPI
  10089. VOID
  10090. IoEnqueueIrp(
  10091. IN PIRP Irp
  10092. );
  10093. NTKERNELAPI
  10094. VOID
  10095. IoFreeController(
  10096. IN PCONTROLLER_OBJECT ControllerObject
  10097. );
  10098. // begin_wdm begin_ntifs
  10099. NTKERNELAPI
  10100. VOID
  10101. IoFreeIrp(
  10102. IN PIRP Irp
  10103. );
  10104. NTKERNELAPI
  10105. VOID
  10106. IoFreeMdl(
  10107. IN PMDL Mdl
  10108. );
  10109. NTKERNELAPI
  10110. PDEVICE_OBJECT
  10111. IoGetAttachedDevice(
  10112. IN PDEVICE_OBJECT DeviceObject
  10113. );
  10114. NTKERNELAPI // ntddk wdm nthal
  10115. PDEVICE_OBJECT // ntddk wdm nthal
  10116. IoGetAttachedDeviceReference( // ntddk wdm nthal
  10117. IN PDEVICE_OBJECT DeviceObject // ntddk wdm nthal
  10118. ); // ntddk wdm nthal
  10119. // ntddk wdm nthal
  10120. NTKERNELAPI
  10121. PDEVICE_OBJECT
  10122. IoGetBaseFileSystemDeviceObject(
  10123. IN PFILE_OBJECT FileObject
  10124. );
  10125. NTKERNELAPI // ntddk nthal ntosp
  10126. PCONFIGURATION_INFORMATION // ntddk nthal ntosp
  10127. IoGetConfigurationInformation( VOID ); // ntddk nthal ntosp
  10128. // begin_ntddk begin_wdm begin_nthal
  10129. //++
  10130. //
  10131. // PIO_STACK_LOCATION
  10132. // IoGetCurrentIrpStackLocation(
  10133. // IN PIRP Irp
  10134. // )
  10135. //
  10136. // Routine Description:
  10137. //
  10138. // This routine is invoked to return a pointer to the current stack location
  10139. // in an I/O Request Packet (IRP).
  10140. //
  10141. // Arguments:
  10142. //
  10143. // Irp - Pointer to the I/O Request Packet.
  10144. //
  10145. // Return Value:
  10146. //
  10147. // The function value is a pointer to the current stack location in the
  10148. // packet.
  10149. //
  10150. //--
  10151. #define IoGetCurrentIrpStackLocation( Irp ) ( (Irp)->Tail.Overlay.CurrentStackLocation )
  10152. // end_nthal end_wdm
  10153. NTKERNELAPI
  10154. PDEVICE_OBJECT
  10155. IoGetDeviceToVerify(
  10156. IN PETHREAD Thread
  10157. );
  10158. // begin_wdm
  10159. NTKERNELAPI
  10160. PVOID
  10161. IoGetDriverObjectExtension(
  10162. IN PDRIVER_OBJECT DriverObject,
  10163. IN PVOID ClientIdentificationAddress
  10164. );
  10165. NTKERNELAPI
  10166. PEPROCESS
  10167. IoGetCurrentProcess(
  10168. VOID
  10169. );
  10170. // begin_nthal
  10171. NTKERNELAPI
  10172. NTSTATUS
  10173. IoGetDeviceObjectPointer(
  10174. IN PUNICODE_STRING ObjectName,
  10175. IN ACCESS_MASK DesiredAccess,
  10176. OUT PFILE_OBJECT *FileObject,
  10177. OUT PDEVICE_OBJECT *DeviceObject
  10178. );
  10179. NTKERNELAPI
  10180. struct _DMA_ADAPTER *
  10181. IoGetDmaAdapter(
  10182. IN PDEVICE_OBJECT PhysicalDeviceObject, OPTIONAL // required for PnP drivers
  10183. IN struct _DEVICE_DESCRIPTION *DeviceDescription,
  10184. IN OUT PULONG NumberOfMapRegisters
  10185. );
  10186. NTKERNELAPI
  10187. BOOLEAN
  10188. IoForwardIrpSynchronously(
  10189. IN PDEVICE_OBJECT DeviceObject,
  10190. IN PIRP Irp
  10191. );
  10192. #define IoForwardAndCatchIrp IoForwardIrpSynchronously
  10193. // end_wdm
  10194. NTKERNELAPI
  10195. PGENERIC_MAPPING
  10196. IoGetFileObjectGenericMapping(
  10197. VOID
  10198. );
  10199. // end_nthal
  10200. // begin_wdm
  10201. //++
  10202. //
  10203. // ULONG
  10204. // IoGetFunctionCodeFromCtlCode(
  10205. // IN ULONG ControlCode
  10206. // )
  10207. //
  10208. // Routine Description:
  10209. //
  10210. // This routine extracts the function code from IOCTL and FSCTL function
  10211. // control codes.
  10212. // This routine should only be used by kernel mode code.
  10213. //
  10214. // Arguments:
  10215. //
  10216. // ControlCode - A function control code (IOCTL or FSCTL) from which the
  10217. // function code must be extracted.
  10218. //
  10219. // Return Value:
  10220. //
  10221. // The extracted function code.
  10222. //
  10223. // Note:
  10224. //
  10225. // The CTL_CODE macro, used to create IOCTL and FSCTL function control
  10226. // codes, is defined in ntioapi.h
  10227. //
  10228. //--
  10229. #define IoGetFunctionCodeFromCtlCode( ControlCode ) (\
  10230. ( ControlCode >> 2) & 0x00000FFF )
  10231. // begin_nthal
  10232. NTKERNELAPI
  10233. PVOID
  10234. IoGetInitialStack(
  10235. VOID
  10236. );
  10237. NTKERNELAPI
  10238. VOID
  10239. IoGetStackLimits (
  10240. OUT PULONG_PTR LowLimit,
  10241. OUT PULONG_PTR HighLimit
  10242. );
  10243. //
  10244. // The following function is used to tell the caller how much stack is available
  10245. //
  10246. FORCEINLINE
  10247. ULONG_PTR
  10248. IoGetRemainingStackSize (
  10249. VOID
  10250. )
  10251. {
  10252. ULONG_PTR Top;
  10253. ULONG_PTR Bottom;
  10254. IoGetStackLimits( &Bottom, &Top );
  10255. return((ULONG_PTR)(&Top) - Bottom );
  10256. }
  10257. //++
  10258. //
  10259. // PIO_STACK_LOCATION
  10260. // IoGetNextIrpStackLocation(
  10261. // IN PIRP Irp
  10262. // )
  10263. //
  10264. // Routine Description:
  10265. //
  10266. // This routine is invoked to return a pointer to the next stack location
  10267. // in an I/O Request Packet (IRP).
  10268. //
  10269. // Arguments:
  10270. //
  10271. // Irp - Pointer to the I/O Request Packet.
  10272. //
  10273. // Return Value:
  10274. //
  10275. // The function value is a pointer to the next stack location in the packet.
  10276. //
  10277. //--
  10278. #define IoGetNextIrpStackLocation( Irp ) (\
  10279. (Irp)->Tail.Overlay.CurrentStackLocation - 1 )
  10280. NTKERNELAPI
  10281. PDEVICE_OBJECT
  10282. IoGetRelatedDeviceObject(
  10283. IN PFILE_OBJECT FileObject
  10284. );
  10285. // end_ntddk end_wdm end_nthal
  10286. NTKERNELAPI
  10287. ULONG
  10288. IoGetRequestorProcessId(
  10289. IN PIRP Irp
  10290. );
  10291. NTKERNELAPI
  10292. PEPROCESS
  10293. IoGetRequestorProcess(
  10294. IN PIRP Irp
  10295. );
  10296. //++
  10297. //
  10298. // VOID
  10299. // IoInitializeDpcRequest(
  10300. // IN PDEVICE_OBJECT DeviceObject,
  10301. // IN PIO_DPC_ROUTINE DpcRoutine
  10302. // )
  10303. //
  10304. // Routine Description:
  10305. //
  10306. // This routine is invoked to initialize the DPC in a device object for a
  10307. // device driver during its initialization routine. The DPC is used later
  10308. // when the driver interrupt service routine requests that a DPC routine
  10309. // be queued for later execution.
  10310. //
  10311. // Arguments:
  10312. //
  10313. // DeviceObject - Pointer to the device object that the request is for.
  10314. //
  10315. // DpcRoutine - Address of the driver's DPC routine to be executed when
  10316. // the DPC is dequeued for processing.
  10317. //
  10318. // Return Value:
  10319. //
  10320. // None.
  10321. //
  10322. //--
  10323. #define IoInitializeDpcRequest( DeviceObject, DpcRoutine ) (\
  10324. KeInitializeDpc( &(DeviceObject)->Dpc, \
  10325. (PKDEFERRED_ROUTINE) (DpcRoutine), \
  10326. (DeviceObject) ) )
  10327. NTKERNELAPI
  10328. VOID
  10329. IoInitializeIrp(
  10330. IN OUT PIRP Irp,
  10331. IN USHORT PacketSize,
  10332. IN CCHAR StackSize
  10333. );
  10334. NTKERNELAPI
  10335. NTSTATUS
  10336. IoInitializeTimer(
  10337. IN PDEVICE_OBJECT DeviceObject,
  10338. IN PIO_TIMER_ROUTINE TimerRoutine,
  10339. IN PVOID Context
  10340. );
  10341. NTKERNELAPI
  10342. VOID
  10343. IoReuseIrp(
  10344. IN OUT PIRP Irp,
  10345. IN NTSTATUS Iostatus
  10346. );
  10347. // end_wdm
  10348. NTKERNELAPI
  10349. VOID
  10350. IoCancelFileOpen(
  10351. IN PDEVICE_OBJECT DeviceObject,
  10352. IN PFILE_OBJECT FileObject
  10353. );
  10354. //++
  10355. //
  10356. // BOOLEAN
  10357. // IoIsErrorUserInduced(
  10358. // IN NTSTATUS Status
  10359. // )
  10360. //
  10361. // Routine Description:
  10362. //
  10363. // This routine is invoked to determine if an error was as a
  10364. // result of user actions. Typically these error are related
  10365. // to removable media and will result in a pop-up.
  10366. //
  10367. // Arguments:
  10368. //
  10369. // Status - The status value to check.
  10370. //
  10371. // Return Value:
  10372. // The function value is TRUE if the user induced the error,
  10373. // otherwise FALSE is returned.
  10374. //
  10375. //--
  10376. #define IoIsErrorUserInduced( Status ) ((BOOLEAN) \
  10377. (((Status) == STATUS_DEVICE_NOT_READY) || \
  10378. ((Status) == STATUS_IO_TIMEOUT) || \
  10379. ((Status) == STATUS_MEDIA_WRITE_PROTECTED) || \
  10380. ((Status) == STATUS_NO_MEDIA_IN_DEVICE) || \
  10381. ((Status) == STATUS_VERIFY_REQUIRED) || \
  10382. ((Status) == STATUS_UNRECOGNIZED_MEDIA) || \
  10383. ((Status) == STATUS_WRONG_VOLUME)))
  10384. NTKERNELAPI
  10385. PIRP
  10386. IoMakeAssociatedIrp(
  10387. IN PIRP Irp,
  10388. IN CCHAR StackSize
  10389. );
  10390. // begin_wdm
  10391. //++
  10392. //
  10393. // VOID
  10394. // IoMarkIrpPending(
  10395. // IN OUT PIRP Irp
  10396. // )
  10397. //
  10398. // Routine Description:
  10399. //
  10400. // This routine marks the specified I/O Request Packet (IRP) to indicate
  10401. // that an initial status of STATUS_PENDING was returned to the caller.
  10402. // This is used so that I/O completion can determine whether or not to
  10403. // fully complete the I/O operation requested by the packet.
  10404. //
  10405. // Arguments:
  10406. //
  10407. // Irp - Pointer to the I/O Request Packet to be marked pending.
  10408. //
  10409. // Return Value:
  10410. //
  10411. // None.
  10412. //
  10413. //--
  10414. #define IoMarkIrpPending( Irp ) ( \
  10415. IoGetCurrentIrpStackLocation( (Irp) )->Control |= SL_PENDING_RETURNED )
  10416. DECLSPEC_DEPRECATED_DDK // Use IoGetDeviceProperty
  10417. NTKERNELAPI
  10418. NTSTATUS
  10419. IoQueryDeviceDescription(
  10420. IN PINTERFACE_TYPE BusType OPTIONAL,
  10421. IN PULONG BusNumber OPTIONAL,
  10422. IN PCONFIGURATION_TYPE ControllerType OPTIONAL,
  10423. IN PULONG ControllerNumber OPTIONAL,
  10424. IN PCONFIGURATION_TYPE PeripheralType OPTIONAL,
  10425. IN PULONG PeripheralNumber OPTIONAL,
  10426. IN PIO_QUERY_DEVICE_ROUTINE CalloutRoutine,
  10427. IN PVOID Context
  10428. );
  10429. NTKERNELAPI
  10430. VOID
  10431. IoQueueThreadIrp(
  10432. IN PIRP Irp
  10433. );
  10434. NTKERNELAPI
  10435. VOID
  10436. IoRaiseHardError(
  10437. IN PIRP Irp,
  10438. IN PVPB Vpb OPTIONAL,
  10439. IN PDEVICE_OBJECT RealDeviceObject
  10440. );
  10441. NTKERNELAPI
  10442. BOOLEAN
  10443. IoRaiseInformationalHardError(
  10444. IN NTSTATUS ErrorStatus,
  10445. IN PUNICODE_STRING String OPTIONAL,
  10446. IN PKTHREAD Thread OPTIONAL
  10447. );
  10448. NTKERNELAPI
  10449. BOOLEAN
  10450. IoSetThreadHardErrorMode(
  10451. IN BOOLEAN EnableHardErrors
  10452. );
  10453. NTKERNELAPI
  10454. VOID
  10455. IoRegisterBootDriverReinitialization(
  10456. IN PDRIVER_OBJECT DriverObject,
  10457. IN PDRIVER_REINITIALIZE DriverReinitializationRoutine,
  10458. IN PVOID Context
  10459. );
  10460. NTKERNELAPI
  10461. VOID
  10462. IoRegisterDriverReinitialization(
  10463. IN PDRIVER_OBJECT DriverObject,
  10464. IN PDRIVER_REINITIALIZE DriverReinitializationRoutine,
  10465. IN PVOID Context
  10466. );
  10467. NTKERNELAPI
  10468. NTSTATUS
  10469. IoRegisterShutdownNotification(
  10470. IN PDEVICE_OBJECT DeviceObject
  10471. );
  10472. NTKERNELAPI
  10473. NTSTATUS
  10474. IoRegisterLastChanceShutdownNotification(
  10475. IN PDEVICE_OBJECT DeviceObject
  10476. );
  10477. // begin_wdm
  10478. NTKERNELAPI
  10479. VOID
  10480. IoReleaseCancelSpinLock(
  10481. IN KIRQL Irql
  10482. );
  10483. NTKERNELAPI
  10484. VOID
  10485. IoRemoveShareAccess(
  10486. IN PFILE_OBJECT FileObject,
  10487. IN OUT PSHARE_ACCESS ShareAccess
  10488. );
  10489. DECLSPEC_DEPRECATED_DDK // Use IoReportResourceForDetection
  10490. NTKERNELAPI
  10491. NTSTATUS
  10492. IoReportResourceUsage(
  10493. IN PUNICODE_STRING DriverClassName OPTIONAL,
  10494. IN PDRIVER_OBJECT DriverObject,
  10495. IN PCM_RESOURCE_LIST DriverList OPTIONAL,
  10496. IN ULONG DriverListSize OPTIONAL,
  10497. IN PDEVICE_OBJECT DeviceObject,
  10498. IN PCM_RESOURCE_LIST DeviceList OPTIONAL,
  10499. IN ULONG DeviceListSize OPTIONAL,
  10500. IN BOOLEAN OverrideConflict,
  10501. OUT PBOOLEAN ConflictDetected
  10502. );
  10503. // begin_wdm
  10504. //++
  10505. //
  10506. // VOID
  10507. // IoRequestDpc(
  10508. // IN PDEVICE_OBJECT DeviceObject,
  10509. // IN PIRP Irp,
  10510. // IN PVOID Context
  10511. // )
  10512. //
  10513. // Routine Description:
  10514. //
  10515. // This routine is invoked by the device driver's interrupt service routine
  10516. // to request that a DPC routine be queued for later execution at a lower
  10517. // IRQL.
  10518. //
  10519. // Arguments:
  10520. //
  10521. // DeviceObject - Device object for which the request is being processed.
  10522. //
  10523. // Irp - Pointer to the current I/O Request Packet (IRP) for the specified
  10524. // device.
  10525. //
  10526. // Context - Provides a general context parameter to be passed to the
  10527. // DPC routine.
  10528. //
  10529. // Return Value:
  10530. //
  10531. // None.
  10532. //
  10533. //--
  10534. #define IoRequestDpc( DeviceObject, Irp, Context ) ( \
  10535. KeInsertQueueDpc( &(DeviceObject)->Dpc, (Irp), (Context) ) )
  10536. //++
  10537. //
  10538. // PDRIVER_CANCEL
  10539. // IoSetCancelRoutine(
  10540. // IN PIRP Irp,
  10541. // IN PDRIVER_CANCEL CancelRoutine
  10542. // )
  10543. //
  10544. // Routine Description:
  10545. //
  10546. // This routine is invoked to set the address of a cancel routine which
  10547. // is to be invoked when an I/O packet has been canceled.
  10548. //
  10549. // Arguments:
  10550. //
  10551. // Irp - Pointer to the I/O Request Packet itself.
  10552. //
  10553. // CancelRoutine - Address of the cancel routine that is to be invoked
  10554. // if the IRP is cancelled.
  10555. //
  10556. // Return Value:
  10557. //
  10558. // Previous value of CancelRoutine field in the IRP.
  10559. //
  10560. //--
  10561. #define IoSetCancelRoutine( Irp, NewCancelRoutine ) ( \
  10562. (PDRIVER_CANCEL) InterlockedExchangePointer( (PVOID *) &(Irp)->CancelRoutine, (PVOID) (NewCancelRoutine) ) )
  10563. //++
  10564. //
  10565. // VOID
  10566. // IoSetCompletionRoutine(
  10567. // IN PIRP Irp,
  10568. // IN PIO_COMPLETION_ROUTINE CompletionRoutine,
  10569. // IN PVOID Context,
  10570. // IN BOOLEAN InvokeOnSuccess,
  10571. // IN BOOLEAN InvokeOnError,
  10572. // IN BOOLEAN InvokeOnCancel
  10573. // )
  10574. //
  10575. // Routine Description:
  10576. //
  10577. // This routine is invoked to set the address of a completion routine which
  10578. // is to be invoked when an I/O packet has been completed by a lower-level
  10579. // driver.
  10580. //
  10581. // Arguments:
  10582. //
  10583. // Irp - Pointer to the I/O Request Packet itself.
  10584. //
  10585. // CompletionRoutine - Address of the completion routine that is to be
  10586. // invoked once the next level driver completes the packet.
  10587. //
  10588. // Context - Specifies a context parameter to be passed to the completion
  10589. // routine.
  10590. //
  10591. // InvokeOnSuccess - Specifies that the completion routine is invoked when the
  10592. // operation is successfully completed.
  10593. //
  10594. // InvokeOnError - Specifies that the completion routine is invoked when the
  10595. // operation completes with an error status.
  10596. //
  10597. // InvokeOnCancel - Specifies that the completion routine is invoked when the
  10598. // operation is being canceled.
  10599. //
  10600. // Return Value:
  10601. //
  10602. // None.
  10603. //
  10604. //--
  10605. #define IoSetCompletionRoutine( Irp, Routine, CompletionContext, Success, Error, Cancel ) { \
  10606. PIO_STACK_LOCATION __irpSp; \
  10607. ASSERT( (Success) | (Error) | (Cancel) ? (Routine) != NULL : TRUE ); \
  10608. __irpSp = IoGetNextIrpStackLocation( (Irp) ); \
  10609. __irpSp->CompletionRoutine = (Routine); \
  10610. __irpSp->Context = (CompletionContext); \
  10611. __irpSp->Control = 0; \
  10612. if ((Success)) { __irpSp->Control = SL_INVOKE_ON_SUCCESS; } \
  10613. if ((Error)) { __irpSp->Control |= SL_INVOKE_ON_ERROR; } \
  10614. if ((Cancel)) { __irpSp->Control |= SL_INVOKE_ON_CANCEL; } }
  10615. NTSTATUS
  10616. IoSetCompletionRoutineEx(
  10617. IN PDEVICE_OBJECT DeviceObject,
  10618. IN PIRP Irp,
  10619. IN PIO_COMPLETION_ROUTINE CompletionRoutine,
  10620. IN PVOID Context,
  10621. IN BOOLEAN InvokeOnSuccess,
  10622. IN BOOLEAN InvokeOnError,
  10623. IN BOOLEAN InvokeOnCancel
  10624. );
  10625. NTKERNELAPI
  10626. VOID
  10627. IoSetHardErrorOrVerifyDevice(
  10628. IN PIRP Irp,
  10629. IN PDEVICE_OBJECT DeviceObject
  10630. );
  10631. // end_ntddk end_nthal
  10632. NTKERNELAPI
  10633. NTSTATUS
  10634. IoSetInformation(
  10635. IN PFILE_OBJECT FileObject,
  10636. IN FILE_INFORMATION_CLASS FileInformationClass,
  10637. IN ULONG Length,
  10638. IN PVOID FileInformation
  10639. );
  10640. //++
  10641. //
  10642. // VOID
  10643. // IoSetNextIrpStackLocation (
  10644. // IN OUT PIRP Irp
  10645. // )
  10646. //
  10647. // Routine Description:
  10648. //
  10649. // This routine is invoked to set the current IRP stack location to
  10650. // the next stack location, i.e. it "pushes" the stack.
  10651. //
  10652. // Arguments:
  10653. //
  10654. // Irp - Pointer to the I/O Request Packet (IRP).
  10655. //
  10656. // Return Value:
  10657. //
  10658. // None.
  10659. //
  10660. //--
  10661. #define IoSetNextIrpStackLocation( Irp ) { \
  10662. (Irp)->CurrentLocation--; \
  10663. (Irp)->Tail.Overlay.CurrentStackLocation--; }
  10664. //++
  10665. //
  10666. // VOID
  10667. // IoCopyCurrentIrpStackLocationToNext(
  10668. // IN PIRP Irp
  10669. // )
  10670. //
  10671. // Routine Description:
  10672. //
  10673. // This routine is invoked to copy the IRP stack arguments and file
  10674. // pointer from the current IrpStackLocation to the next
  10675. // in an I/O Request Packet (IRP).
  10676. //
  10677. // If the caller wants to call IoCallDriver with a completion routine
  10678. // but does not wish to change the arguments otherwise,
  10679. // the caller first calls IoCopyCurrentIrpStackLocationToNext,
  10680. // then IoSetCompletionRoutine, then IoCallDriver.
  10681. //
  10682. // Arguments:
  10683. //
  10684. // Irp - Pointer to the I/O Request Packet.
  10685. //
  10686. // Return Value:
  10687. //
  10688. // None.
  10689. //
  10690. //--
  10691. #define IoCopyCurrentIrpStackLocationToNext( Irp ) { \
  10692. PIO_STACK_LOCATION __irpSp; \
  10693. PIO_STACK_LOCATION __nextIrpSp; \
  10694. __irpSp = IoGetCurrentIrpStackLocation( (Irp) ); \
  10695. __nextIrpSp = IoGetNextIrpStackLocation( (Irp) ); \
  10696. RtlCopyMemory( __nextIrpSp, __irpSp, FIELD_OFFSET(IO_STACK_LOCATION, CompletionRoutine)); \
  10697. __nextIrpSp->Control = 0; }
  10698. //++
  10699. //
  10700. // VOID
  10701. // IoSkipCurrentIrpStackLocation (
  10702. // IN PIRP Irp
  10703. // )
  10704. //
  10705. // Routine Description:
  10706. //
  10707. // This routine is invoked to increment the current stack location of
  10708. // a given IRP.
  10709. //
  10710. // If the caller wishes to call the next driver in a stack, and does not
  10711. // wish to change the arguments, nor does he wish to set a completion
  10712. // routine, then the caller first calls IoSkipCurrentIrpStackLocation
  10713. // and the calls IoCallDriver.
  10714. //
  10715. // Arguments:
  10716. //
  10717. // Irp - Pointer to the I/O Request Packet.
  10718. //
  10719. // Return Value:
  10720. //
  10721. // None
  10722. //
  10723. //--
  10724. #define IoSkipCurrentIrpStackLocation( Irp ) { \
  10725. (Irp)->CurrentLocation++; \
  10726. (Irp)->Tail.Overlay.CurrentStackLocation++; }
  10727. NTKERNELAPI
  10728. VOID
  10729. IoSetShareAccess(
  10730. IN ACCESS_MASK DesiredAccess,
  10731. IN ULONG DesiredShareAccess,
  10732. IN OUT PFILE_OBJECT FileObject,
  10733. OUT PSHARE_ACCESS ShareAccess
  10734. );
  10735. typedef struct _IO_REMOVE_LOCK_TRACKING_BLOCK * PIO_REMOVE_LOCK_TRACKING_BLOCK;
  10736. typedef struct _IO_REMOVE_LOCK_COMMON_BLOCK {
  10737. BOOLEAN Removed;
  10738. BOOLEAN Reserved [3];
  10739. LONG IoCount;
  10740. KEVENT RemoveEvent;
  10741. } IO_REMOVE_LOCK_COMMON_BLOCK;
  10742. typedef struct _IO_REMOVE_LOCK_DBG_BLOCK {
  10743. LONG Signature;
  10744. LONG HighWatermark;
  10745. LONGLONG MaxLockedTicks;
  10746. LONG AllocateTag;
  10747. LIST_ENTRY LockList;
  10748. KSPIN_LOCK Spin;
  10749. LONG LowMemoryCount;
  10750. ULONG Reserved1[4];
  10751. PVOID Reserved2;
  10752. PIO_REMOVE_LOCK_TRACKING_BLOCK Blocks;
  10753. } IO_REMOVE_LOCK_DBG_BLOCK;
  10754. typedef struct _IO_REMOVE_LOCK {
  10755. IO_REMOVE_LOCK_COMMON_BLOCK Common;
  10756. #if DBG
  10757. IO_REMOVE_LOCK_DBG_BLOCK Dbg;
  10758. #endif
  10759. } IO_REMOVE_LOCK, *PIO_REMOVE_LOCK;
  10760. #define IoInitializeRemoveLock(Lock, Tag, Maxmin, HighWater) \
  10761. IoInitializeRemoveLockEx (Lock, Tag, Maxmin, HighWater, sizeof (IO_REMOVE_LOCK))
  10762. NTSYSAPI
  10763. VOID
  10764. NTAPI
  10765. IoInitializeRemoveLockEx(
  10766. IN PIO_REMOVE_LOCK Lock,
  10767. IN ULONG AllocateTag, // Used only on checked kernels
  10768. IN ULONG MaxLockedMinutes, // Used only on checked kernels
  10769. IN ULONG HighWatermark, // Used only on checked kernels
  10770. IN ULONG RemlockSize // are we checked or free
  10771. );
  10772. //
  10773. // Initialize a remove lock.
  10774. //
  10775. // Note: Allocation for remove locks needs to be within the device extension,
  10776. // so that the memory for this structure stays allocated until such time as the
  10777. // device object itself is deallocated.
  10778. //
  10779. #define IoAcquireRemoveLock(RemoveLock, Tag) \
  10780. IoAcquireRemoveLockEx(RemoveLock, Tag, __FILE__, __LINE__, sizeof (IO_REMOVE_LOCK))
  10781. NTSYSAPI
  10782. NTSTATUS
  10783. NTAPI
  10784. IoAcquireRemoveLockEx (
  10785. IN PIO_REMOVE_LOCK RemoveLock,
  10786. IN OPTIONAL PVOID Tag, // Optional
  10787. IN PCSTR File,
  10788. IN ULONG Line,
  10789. IN ULONG RemlockSize // are we checked or free
  10790. );
  10791. //
  10792. // Routine Description:
  10793. //
  10794. // This routine is called to acquire the remove lock for a device object.
  10795. // While the lock is held, the caller can assume that no pending pnp REMOVE
  10796. // requests will be completed.
  10797. //
  10798. // The lock should be acquired immediately upon entering a dispatch routine.
  10799. // It should also be acquired before creating any new reference to the
  10800. // device object if there's a chance of releasing the reference before the
  10801. // new one is done, in addition to references to the driver code itself,
  10802. // which is removed from memory when the last device object goes.
  10803. //
  10804. // Arguments:
  10805. //
  10806. // RemoveLock - A pointer to an initialized REMOVE_LOCK structure.
  10807. //
  10808. // Tag - Used for tracking lock allocation and release. The same tag
  10809. // specified when acquiring the lock must be used to release the lock.
  10810. // Tags are only checked in checked versions of the driver.
  10811. //
  10812. // File - set to __FILE__ as the location in the code where the lock was taken.
  10813. //
  10814. // Line - set to __LINE__.
  10815. //
  10816. // Return Value:
  10817. //
  10818. // Returns whether or not the remove lock was obtained.
  10819. // If successful the caller should continue with work calling
  10820. // IoReleaseRemoveLock when finished.
  10821. //
  10822. // If not successful the lock was not obtained. The caller should abort the
  10823. // work but not call IoReleaseRemoveLock.
  10824. //
  10825. #define IoReleaseRemoveLock(RemoveLock, Tag) \
  10826. IoReleaseRemoveLockEx(RemoveLock, Tag, sizeof (IO_REMOVE_LOCK))
  10827. NTSYSAPI
  10828. VOID
  10829. NTAPI
  10830. IoReleaseRemoveLockEx(
  10831. IN PIO_REMOVE_LOCK RemoveLock,
  10832. IN PVOID Tag, // Optional
  10833. IN ULONG RemlockSize // are we checked or free
  10834. );
  10835. //
  10836. //
  10837. // Routine Description:
  10838. //
  10839. // This routine is called to release the remove lock on the device object. It
  10840. // must be called when finished using a previously locked reference to the
  10841. // device object. If an Tag was specified when acquiring the lock then the
  10842. // same Tag must be specified when releasing the lock.
  10843. //
  10844. // When the lock count reduces to zero, this routine will signal the waiting
  10845. // event to release the waiting thread deleting the device object protected
  10846. // by this lock.
  10847. //
  10848. // Arguments:
  10849. //
  10850. // DeviceObject - the device object to lock
  10851. //
  10852. // Tag - The TAG (if any) specified when acquiring the lock. This is used
  10853. // for lock tracking purposes
  10854. //
  10855. // Return Value:
  10856. //
  10857. // none
  10858. //
  10859. #define IoReleaseRemoveLockAndWait(RemoveLock, Tag) \
  10860. IoReleaseRemoveLockAndWaitEx(RemoveLock, Tag, sizeof (IO_REMOVE_LOCK))
  10861. NTSYSAPI
  10862. VOID
  10863. NTAPI
  10864. IoReleaseRemoveLockAndWaitEx(
  10865. IN PIO_REMOVE_LOCK RemoveLock,
  10866. IN PVOID Tag,
  10867. IN ULONG RemlockSize // are we checked or free
  10868. );
  10869. //
  10870. //
  10871. // Routine Description:
  10872. //
  10873. // This routine is called when the client would like to delete the
  10874. // remove-locked resource. This routine will block until all the remove
  10875. // locks have released.
  10876. //
  10877. // This routine MUST be called after acquiring the lock.
  10878. //
  10879. // Arguments:
  10880. //
  10881. // RemoveLock
  10882. //
  10883. // Return Value:
  10884. //
  10885. // none
  10886. //
  10887. //++
  10888. //
  10889. // USHORT
  10890. // IoSizeOfIrp(
  10891. // IN CCHAR StackSize
  10892. // )
  10893. //
  10894. // Routine Description:
  10895. //
  10896. // Determines the size of an IRP given the number of stack locations
  10897. // the IRP will have.
  10898. //
  10899. // Arguments:
  10900. //
  10901. // StackSize - Number of stack locations for the IRP.
  10902. //
  10903. // Return Value:
  10904. //
  10905. // Size in bytes of the IRP.
  10906. //
  10907. //--
  10908. #define IoSizeOfIrp( StackSize ) \
  10909. ((USHORT) (sizeof( IRP ) + ((StackSize) * (sizeof( IO_STACK_LOCATION )))))
  10910. // end_ntifs
  10911. NTKERNELAPI
  10912. VOID
  10913. IoStartNextPacket(
  10914. IN PDEVICE_OBJECT DeviceObject,
  10915. IN BOOLEAN Cancelable
  10916. );
  10917. NTKERNELAPI
  10918. VOID
  10919. IoStartNextPacketByKey(
  10920. IN PDEVICE_OBJECT DeviceObject,
  10921. IN BOOLEAN Cancelable,
  10922. IN ULONG Key
  10923. );
  10924. NTKERNELAPI
  10925. VOID
  10926. IoStartPacket(
  10927. IN PDEVICE_OBJECT DeviceObject,
  10928. IN PIRP Irp,
  10929. IN PULONG Key OPTIONAL,
  10930. IN PDRIVER_CANCEL CancelFunction OPTIONAL
  10931. );
  10932. VOID
  10933. IoSetStartIoAttributes(
  10934. IN PDEVICE_OBJECT DeviceObject,
  10935. IN BOOLEAN DeferredStartIo,
  10936. IN BOOLEAN NonCancelable
  10937. );
  10938. // begin_ntifs
  10939. NTKERNELAPI
  10940. VOID
  10941. IoStartTimer(
  10942. IN PDEVICE_OBJECT DeviceObject
  10943. );
  10944. NTKERNELAPI
  10945. VOID
  10946. IoStopTimer(
  10947. IN PDEVICE_OBJECT DeviceObject
  10948. );
  10949. NTKERNELAPI
  10950. PEPROCESS
  10951. IoThreadToProcess(
  10952. IN PETHREAD Thread
  10953. );
  10954. NTKERNELAPI
  10955. VOID
  10956. IoUnregisterShutdownNotification(
  10957. IN PDEVICE_OBJECT DeviceObject
  10958. );
  10959. // end_wdm
  10960. NTKERNELAPI
  10961. VOID
  10962. IoUpdateShareAccess(
  10963. IN PFILE_OBJECT FileObject,
  10964. IN OUT PSHARE_ACCESS ShareAccess
  10965. );
  10966. // end_ntddk end_nthal
  10967. NTKERNELAPI
  10968. NTSTATUS
  10969. IoVerifyVolume(
  10970. IN PDEVICE_OBJECT DeviceObject,
  10971. IN BOOLEAN AllowRawMount
  10972. );
  10973. NTKERNELAPI // ntddk wdm nthal
  10974. VOID // ntddk wdm nthal
  10975. IoWriteErrorLogEntry( // ntddk wdm nthal
  10976. IN PVOID ElEntry // ntddk wdm nthal
  10977. ); // ntddk wdm nthal
  10978. NTKERNELAPI
  10979. NTSTATUS
  10980. IoCreateDriver (
  10981. IN PUNICODE_STRING DriverName, OPTIONAL
  10982. IN PDRIVER_INITIALIZE InitializationFunction
  10983. );
  10984. NTKERNELAPI
  10985. VOID
  10986. IoDeleteDriver (
  10987. IN PDRIVER_OBJECT DriverObject
  10988. );
  10989. typedef struct _IO_WORKITEM *PIO_WORKITEM;
  10990. typedef
  10991. VOID
  10992. (*PIO_WORKITEM_ROUTINE) (
  10993. IN PDEVICE_OBJECT DeviceObject,
  10994. IN PVOID Context
  10995. );
  10996. PIO_WORKITEM
  10997. IoAllocateWorkItem(
  10998. PDEVICE_OBJECT DeviceObject
  10999. );
  11000. VOID
  11001. IoFreeWorkItem(
  11002. PIO_WORKITEM IoWorkItem
  11003. );
  11004. VOID
  11005. IoQueueWorkItem(
  11006. IN PIO_WORKITEM IoWorkItem,
  11007. IN PIO_WORKITEM_ROUTINE WorkerRoutine,
  11008. IN WORK_QUEUE_TYPE QueueType,
  11009. IN PVOID Context
  11010. );
  11011. NTKERNELAPI
  11012. NTSTATUS
  11013. IoWMIRegistrationControl(
  11014. IN PDEVICE_OBJECT DeviceObject,
  11015. IN ULONG Action
  11016. );
  11017. //
  11018. // Action code for IoWMIRegistrationControl api
  11019. //
  11020. #define WMIREG_ACTION_REGISTER 1
  11021. #define WMIREG_ACTION_DEREGISTER 2
  11022. #define WMIREG_ACTION_REREGISTER 3
  11023. #define WMIREG_ACTION_UPDATE_GUIDS 4
  11024. #define WMIREG_ACTION_BLOCK_IRPS 5
  11025. //
  11026. // Code passed in IRP_MN_REGINFO WMI irp
  11027. //
  11028. #define WMIREGISTER 0
  11029. #define WMIUPDATE 1
  11030. NTKERNELAPI
  11031. NTSTATUS
  11032. IoWMIAllocateInstanceIds(
  11033. IN GUID *Guid,
  11034. IN ULONG InstanceCount,
  11035. OUT ULONG *FirstInstanceId
  11036. );
  11037. NTKERNELAPI
  11038. NTSTATUS
  11039. IoWMISuggestInstanceName(
  11040. IN PDEVICE_OBJECT PhysicalDeviceObject OPTIONAL,
  11041. IN PUNICODE_STRING SymbolicLinkName OPTIONAL,
  11042. IN BOOLEAN CombineNames,
  11043. OUT PUNICODE_STRING SuggestedInstanceName
  11044. );
  11045. NTKERNELAPI
  11046. NTSTATUS
  11047. IoWMIWriteEvent(
  11048. IN PVOID WnodeEventItem
  11049. );
  11050. #if defined(_WIN64)
  11051. NTKERNELAPI
  11052. ULONG IoWMIDeviceObjectToProviderId(
  11053. PDEVICE_OBJECT DeviceObject
  11054. );
  11055. #else
  11056. #define IoWMIDeviceObjectToProviderId(DeviceObject) ((ULONG)(DeviceObject))
  11057. #endif
  11058. NTKERNELAPI
  11059. NTSTATUS IoWMIOpenBlock(
  11060. IN GUID *DataBlockGuid,
  11061. IN ULONG DesiredAccess,
  11062. OUT PVOID *DataBlockObject
  11063. );
  11064. NTKERNELAPI
  11065. NTSTATUS IoWMIQueryAllData(
  11066. IN PVOID DataBlockObject,
  11067. IN OUT ULONG *InOutBufferSize,
  11068. OUT /* non paged */ PVOID OutBuffer
  11069. );
  11070. NTKERNELAPI
  11071. NTSTATUS
  11072. IoWMIQueryAllDataMultiple(
  11073. IN PVOID *DataBlockObjectList,
  11074. IN ULONG ObjectCount,
  11075. IN OUT ULONG *InOutBufferSize,
  11076. OUT /* non paged */ PVOID OutBuffer
  11077. );
  11078. NTKERNELAPI
  11079. NTSTATUS
  11080. IoWMIQuerySingleInstance(
  11081. IN PVOID DataBlockObject,
  11082. IN PUNICODE_STRING InstanceName,
  11083. IN OUT ULONG *InOutBufferSize,
  11084. OUT /* non paged */ PVOID OutBuffer
  11085. );
  11086. NTKERNELAPI
  11087. NTSTATUS
  11088. IoWMIQuerySingleInstanceMultiple(
  11089. IN PVOID *DataBlockObjectList,
  11090. IN PUNICODE_STRING InstanceNames,
  11091. IN ULONG ObjectCount,
  11092. IN OUT ULONG *InOutBufferSize,
  11093. OUT /* non paged */ PVOID OutBuffer
  11094. );
  11095. NTKERNELAPI
  11096. NTSTATUS
  11097. IoWMISetSingleInstance(
  11098. IN PVOID DataBlockObject,
  11099. IN PUNICODE_STRING InstanceName,
  11100. IN ULONG Version,
  11101. IN ULONG ValueBufferSize,
  11102. IN PVOID ValueBuffer
  11103. );
  11104. NTKERNELAPI
  11105. NTSTATUS
  11106. IoWMISetSingleItem(
  11107. IN PVOID DataBlockObject,
  11108. IN PUNICODE_STRING InstanceName,
  11109. IN ULONG DataItemId,
  11110. IN ULONG Version,
  11111. IN ULONG ValueBufferSize,
  11112. IN PVOID ValueBuffer
  11113. );
  11114. NTKERNELAPI
  11115. NTSTATUS
  11116. IoWMIExecuteMethod(
  11117. IN PVOID DataBlockObject,
  11118. IN PUNICODE_STRING InstanceName,
  11119. IN ULONG MethodId,
  11120. IN ULONG InBufferSize,
  11121. IN OUT PULONG OutBufferSize,
  11122. IN OUT PUCHAR InOutBuffer
  11123. );
  11124. typedef VOID (*WMI_NOTIFICATION_CALLBACK)(
  11125. PVOID Wnode,
  11126. PVOID Context
  11127. );
  11128. NTKERNELAPI
  11129. NTSTATUS
  11130. IoWMISetNotificationCallback(
  11131. IN PVOID Object,
  11132. IN WMI_NOTIFICATION_CALLBACK Callback,
  11133. IN PVOID Context
  11134. );
  11135. NTKERNELAPI
  11136. NTSTATUS
  11137. IoWMIHandleToInstanceName(
  11138. IN PVOID DataBlockObject,
  11139. IN HANDLE FileHandle,
  11140. OUT PUNICODE_STRING InstanceName
  11141. );
  11142. NTKERNELAPI
  11143. NTSTATUS
  11144. IoWMIDeviceObjectToInstanceName(
  11145. IN PVOID DataBlockObject,
  11146. IN PDEVICE_OBJECT DeviceObject,
  11147. OUT PUNICODE_STRING InstanceName
  11148. );
  11149. NTKERNELAPI
  11150. NTSTATUS
  11151. IoSetIoCompletion (
  11152. IN PVOID IoCompletion,
  11153. IN PVOID KeyContext,
  11154. IN PVOID ApcContext,
  11155. IN NTSTATUS IoStatus,
  11156. IN ULONG_PTR IoStatusInformation,
  11157. IN BOOLEAN Quota
  11158. );
  11159. #if defined(_WIN64)
  11160. BOOLEAN
  11161. IoIs32bitProcess(
  11162. IN PIRP Irp
  11163. );
  11164. #endif
  11165. NTKERNELAPI
  11166. VOID
  11167. FASTCALL
  11168. IoAssignDriveLetters(
  11169. PLOADER_PARAMETER_BLOCK LoaderBlock,
  11170. PSTRING NtDeviceName,
  11171. OUT PUCHAR NtSystemPath,
  11172. OUT PSTRING NtSystemPathString
  11173. );
  11174. DECLSPEC_DEPRECATED_DDK // Use IoWritePartitionTableEx
  11175. NTKERNELAPI
  11176. NTSTATUS
  11177. FASTCALL
  11178. IoWritePartitionTable(
  11179. IN PDEVICE_OBJECT DeviceObject,
  11180. IN ULONG SectorSize,
  11181. IN ULONG SectorsPerTrack,
  11182. IN ULONG NumberOfHeads,
  11183. IN struct _DRIVE_LAYOUT_INFORMATION *PartitionBuffer
  11184. );
  11185. NTKERNELAPI
  11186. NTSTATUS
  11187. IoCreateDisk(
  11188. IN PDEVICE_OBJECT DeviceObject,
  11189. IN struct _CREATE_DISK* Disk
  11190. );
  11191. NTKERNELAPI
  11192. NTSTATUS
  11193. IoReadPartitionTableEx(
  11194. IN PDEVICE_OBJECT DeviceObject,
  11195. IN struct _DRIVE_LAYOUT_INFORMATION_EX** DriveLayout
  11196. );
  11197. NTKERNELAPI
  11198. NTSTATUS
  11199. IoWritePartitionTableEx(
  11200. IN PDEVICE_OBJECT DeviceObject,
  11201. IN struct _DRIVE_LAYOUT_INFORMATION_EX* DriveLayout
  11202. );
  11203. NTKERNELAPI
  11204. NTSTATUS
  11205. IoSetPartitionInformationEx(
  11206. IN PDEVICE_OBJECT DeviceObject,
  11207. IN ULONG PartitionNumber,
  11208. IN struct _SET_PARTITION_INFORMATION_EX* PartitionInfo
  11209. );
  11210. NTKERNELAPI
  11211. NTSTATUS
  11212. IoUpdateDiskGeometry(
  11213. IN PDEVICE_OBJECT DeviceObject,
  11214. IN struct _DISK_GEOMETRY_EX* OldDiskGeometry,
  11215. IN struct _DISK_GEOMETRY_EX* NewDiskGeometry
  11216. );
  11217. NTKERNELAPI
  11218. NTSTATUS
  11219. IoVerifyPartitionTable(
  11220. IN PDEVICE_OBJECT DeviceObject,
  11221. IN BOOLEAN FixErrors
  11222. );
  11223. typedef struct _DISK_SIGNATURE {
  11224. ULONG PartitionStyle;
  11225. union {
  11226. struct {
  11227. ULONG Signature;
  11228. ULONG CheckSum;
  11229. } Mbr;
  11230. struct {
  11231. GUID DiskId;
  11232. } Gpt;
  11233. };
  11234. } DISK_SIGNATURE, *PDISK_SIGNATURE;
  11235. NTKERNELAPI
  11236. NTSTATUS
  11237. IoReadDiskSignature(
  11238. IN PDEVICE_OBJECT DeviceObject,
  11239. IN ULONG BytesPerSector,
  11240. OUT PDISK_SIGNATURE Signature
  11241. );
  11242. NTSTATUS
  11243. IoVolumeDeviceToDosName(
  11244. IN PVOID VolumeDeviceObject,
  11245. OUT PUNICODE_STRING DosName
  11246. );
  11247. NTSTATUS
  11248. IoEnumerateDeviceObjectList(
  11249. IN PDRIVER_OBJECT DriverObject,
  11250. IN PDEVICE_OBJECT *DeviceObjectList,
  11251. IN ULONG DeviceObjectListSize,
  11252. OUT PULONG ActualNumberDeviceObjects
  11253. );
  11254. PDEVICE_OBJECT
  11255. IoGetLowerDeviceObject(
  11256. IN PDEVICE_OBJECT DeviceObject
  11257. );
  11258. PDEVICE_OBJECT
  11259. IoGetDeviceAttachmentBaseRef(
  11260. IN PDEVICE_OBJECT DeviceObject
  11261. );
  11262. NTSTATUS
  11263. IoGetDiskDeviceObject(
  11264. IN PDEVICE_OBJECT FileSystemDeviceObject,
  11265. OUT PDEVICE_OBJECT *DiskDeviceObject
  11266. );
  11267. NTSTATUS
  11268. IoSetSystemPartition(
  11269. PUNICODE_STRING VolumeNameString
  11270. );
  11271. // begin_wdm
  11272. VOID
  11273. IoFreeErrorLogEntry(
  11274. PVOID ElEntry
  11275. );
  11276. // Cancel SAFE API set start
  11277. //
  11278. // The following APIs are to help ease the pain of writing queue packages that
  11279. // handle the cancellation race well. The idea of this set of APIs is to not
  11280. // force a single queue data structure but allow the cancel logic to be hidden
  11281. // from the drivers. A driver implements a queue and as part of its header
  11282. // includes the IO_CSQ structure. In its initialization routine it calls
  11283. // IoInitializeCsq. Then in the dispatch routine when the driver wants to
  11284. // insert an IRP into the queue it calls IoCsqInsertIrp. When the driver wants
  11285. // to remove something from the queue it calls IoCsqRemoveIrp. Note that Insert
  11286. // can fail if the IRP was cancelled in the meantime. Remove can also fail if
  11287. // the IRP was already cancelled.
  11288. //
  11289. // There are typically two modes where drivers queue IRPs. These two modes are
  11290. // covered by the cancel safe queue API set.
  11291. //
  11292. // Mode 1:
  11293. // One is where the driver queues the IRP and at some later
  11294. // point in time dequeues an IRP and issues the IO request.
  11295. // For this mode the driver should use IoCsqInsertIrp and IoCsqRemoveNextIrp.
  11296. // The driver in this case is expected to pass NULL to the irp context
  11297. // parameter in IoInsertIrp.
  11298. //
  11299. // Mode 2:
  11300. // In this the driver queues theIRP, issues the IO request (like issuing a DMA
  11301. // request or writing to a register) and when the IO request completes (either
  11302. // using a DPC or timer) the driver dequeues the IRP and completes it. For this
  11303. // mode the driver should use IoCsqInsertIrp and IoCsqRemoveIrp. In this case
  11304. // the driver should allocate an IRP context and pass it in to IoCsqInsertIrp.
  11305. // The cancel API code creates an association between the IRP and the context
  11306. // and thus ensures that when the time comes to remove the IRP it can ascertain
  11307. // correctly.
  11308. //
  11309. // Note that the cancel API set assumes that the field DriverContext[3] is
  11310. // always available for use and that the driver does not use it.
  11311. //
  11312. //
  11313. // Bookkeeping structure. This should be opaque to drivers.
  11314. // Drivers typically include this as part of their queue headers.
  11315. // Given a CSQ pointer the driver should be able to get its
  11316. // queue header using CONTAINING_RECORD macro
  11317. //
  11318. typedef struct _IO_CSQ IO_CSQ, *PIO_CSQ;
  11319. #define IO_TYPE_CSQ_IRP_CONTEXT 1
  11320. #define IO_TYPE_CSQ 2
  11321. //
  11322. // IRP context structure. This structure is necessary if the driver is using
  11323. // the second mode.
  11324. //
  11325. typedef struct _IO_CSQ_IRP_CONTEXT {
  11326. ULONG Type;
  11327. PIRP Irp;
  11328. PIO_CSQ Csq;
  11329. } IO_CSQ_IRP_CONTEXT, *PIO_CSQ_IRP_CONTEXT;
  11330. //
  11331. // Routines that insert/remove IRP
  11332. //
  11333. typedef VOID
  11334. (*PIO_CSQ_INSERT_IRP)(
  11335. IN struct _IO_CSQ *Csq,
  11336. IN PIRP Irp
  11337. );
  11338. typedef VOID
  11339. (*PIO_CSQ_REMOVE_IRP)(
  11340. IN PIO_CSQ Csq,
  11341. IN PIRP Irp
  11342. );
  11343. //
  11344. // Retrieves next entry after Irp from the queue.
  11345. // Returns NULL if there are no entries in the queue.
  11346. // If Irp is NUL, returns the entry in the head of the queue.
  11347. // This routine does not remove the IRP from the queue.
  11348. //
  11349. typedef PIRP
  11350. (*PIO_CSQ_PEEK_NEXT_IRP)(
  11351. IN PIO_CSQ Csq,
  11352. IN PIRP Irp,
  11353. IN PVOID PeekContext
  11354. );
  11355. //
  11356. // Lock routine that protects the cancel safe queue.
  11357. //
  11358. typedef VOID
  11359. (*PIO_CSQ_ACQUIRE_LOCK)(
  11360. IN PIO_CSQ Csq,
  11361. OUT PKIRQL Irql
  11362. );
  11363. typedef VOID
  11364. (*PIO_CSQ_RELEASE_LOCK)(
  11365. IN PIO_CSQ Csq,
  11366. IN KIRQL Irql
  11367. );
  11368. //
  11369. // Completes the IRP with STATUS_CANCELLED. IRP is guaranteed to be valid
  11370. // In most cases this routine just calls IoCompleteRequest(Irp, STATUS_CANCELLED);
  11371. //
  11372. typedef VOID
  11373. (*PIO_CSQ_COMPLETE_CANCELED_IRP)(
  11374. IN PIO_CSQ Csq,
  11375. IN PIRP Irp
  11376. );
  11377. //
  11378. // Bookkeeping structure. This should be opaque to drivers.
  11379. // Drivers typically include this as part of their queue headers.
  11380. // Given a CSQ pointer the driver should be able to get its
  11381. // queue header using CONTAINING_RECORD macro
  11382. //
  11383. typedef struct _IO_CSQ {
  11384. ULONG Type;
  11385. PIO_CSQ_INSERT_IRP CsqInsertIrp;
  11386. PIO_CSQ_REMOVE_IRP CsqRemoveIrp;
  11387. PIO_CSQ_PEEK_NEXT_IRP CsqPeekNextIrp;
  11388. PIO_CSQ_ACQUIRE_LOCK CsqAcquireLock;
  11389. PIO_CSQ_RELEASE_LOCK CsqReleaseLock;
  11390. PIO_CSQ_COMPLETE_CANCELED_IRP CsqCompleteCanceledIrp;
  11391. PVOID ReservePointer; // Future expansion
  11392. } IO_CSQ, *PIO_CSQ;
  11393. //
  11394. // Initializes the cancel queue structure.
  11395. //
  11396. NTSTATUS
  11397. IoCsqInitialize(
  11398. IN PIO_CSQ Csq,
  11399. IN PIO_CSQ_INSERT_IRP CsqInsertIrp,
  11400. IN PIO_CSQ_REMOVE_IRP CsqRemoveIrp,
  11401. IN PIO_CSQ_PEEK_NEXT_IRP CsqPeekNextIrp,
  11402. IN PIO_CSQ_ACQUIRE_LOCK CsqAcquireLock,
  11403. IN PIO_CSQ_RELEASE_LOCK CsqReleaseLock,
  11404. IN PIO_CSQ_COMPLETE_CANCELED_IRP CsqCompleteCanceledIrp
  11405. );
  11406. //
  11407. // The caller calls this routine to insert the IRP and return STATUS_PENDING.
  11408. //
  11409. VOID
  11410. IoCsqInsertIrp(
  11411. IN PIO_CSQ Csq,
  11412. IN PIRP Irp,
  11413. IN PIO_CSQ_IRP_CONTEXT Context
  11414. );
  11415. //
  11416. // Returns an IRP if one can be found. NULL otherwise.
  11417. //
  11418. PIRP
  11419. IoCsqRemoveNextIrp(
  11420. IN PIO_CSQ Csq,
  11421. IN PVOID PeekContext
  11422. );
  11423. //
  11424. // This routine is called from timeout or DPCs.
  11425. // The context is presumably part of the DPC or timer context.
  11426. // If succesfull returns the IRP associated with context.
  11427. //
  11428. PIRP
  11429. IoCsqRemoveIrp(
  11430. IN PIO_CSQ Csq,
  11431. IN PIO_CSQ_IRP_CONTEXT Context
  11432. );
  11433. // Cancel SAFE API set end
  11434. NTSTATUS
  11435. IoCreateFileSpecifyDeviceObjectHint(
  11436. OUT PHANDLE FileHandle,
  11437. IN ACCESS_MASK DesiredAccess,
  11438. IN POBJECT_ATTRIBUTES ObjectAttributes,
  11439. OUT PIO_STATUS_BLOCK IoStatusBlock,
  11440. IN PLARGE_INTEGER AllocationSize OPTIONAL,
  11441. IN ULONG FileAttributes,
  11442. IN ULONG ShareAccess,
  11443. IN ULONG Disposition,
  11444. IN ULONG CreateOptions,
  11445. IN PVOID EaBuffer OPTIONAL,
  11446. IN ULONG EaLength,
  11447. IN CREATE_FILE_TYPE CreateFileType,
  11448. IN PVOID ExtraCreateParameters OPTIONAL,
  11449. IN ULONG Options,
  11450. IN PVOID DeviceObject
  11451. );
  11452. NTSTATUS
  11453. IoAttachDeviceToDeviceStackSafe(
  11454. IN PDEVICE_OBJECT SourceDevice,
  11455. IN PDEVICE_OBJECT TargetDevice,
  11456. OUT PDEVICE_OBJECT *AttachedToDeviceObject
  11457. );
  11458. NTSTATUS
  11459. IoValidateDeviceIoControlAccess(
  11460. IN PIRP Irp,
  11461. IN ULONG RequiredAccess
  11462. );
  11463. //
  11464. // Define PnP Device Property for IoGetDeviceProperty
  11465. //
  11466. typedef enum {
  11467. DevicePropertyDeviceDescription,
  11468. DevicePropertyHardwareID,
  11469. DevicePropertyCompatibleIDs,
  11470. DevicePropertyBootConfiguration,
  11471. DevicePropertyBootConfigurationTranslated,
  11472. DevicePropertyClassName,
  11473. DevicePropertyClassGuid,
  11474. DevicePropertyDriverKeyName,
  11475. DevicePropertyManufacturer,
  11476. DevicePropertyFriendlyName,
  11477. DevicePropertyLocationInformation,
  11478. DevicePropertyPhysicalDeviceObjectName,
  11479. DevicePropertyBusTypeGuid,
  11480. DevicePropertyLegacyBusType,
  11481. DevicePropertyBusNumber,
  11482. DevicePropertyEnumeratorName,
  11483. DevicePropertyAddress,
  11484. DevicePropertyUINumber,
  11485. DevicePropertyInstallState,
  11486. DevicePropertyRemovalPolicy
  11487. } DEVICE_REGISTRY_PROPERTY;
  11488. typedef BOOLEAN (*PTRANSLATE_BUS_ADDRESS)(
  11489. IN PVOID Context,
  11490. IN PHYSICAL_ADDRESS BusAddress,
  11491. IN ULONG Length,
  11492. IN OUT PULONG AddressSpace,
  11493. OUT PPHYSICAL_ADDRESS TranslatedAddress
  11494. );
  11495. typedef struct _DMA_ADAPTER *(*PGET_DMA_ADAPTER)(
  11496. IN PVOID Context,
  11497. IN struct _DEVICE_DESCRIPTION *DeviceDescriptor,
  11498. OUT PULONG NumberOfMapRegisters
  11499. );
  11500. typedef ULONG (*PGET_SET_DEVICE_DATA)(
  11501. IN PVOID Context,
  11502. IN ULONG DataType,
  11503. IN PVOID Buffer,
  11504. IN ULONG Offset,
  11505. IN ULONG Length
  11506. );
  11507. typedef enum _DEVICE_INSTALL_STATE {
  11508. InstallStateInstalled,
  11509. InstallStateNeedsReinstall,
  11510. InstallStateFailedInstall,
  11511. InstallStateFinishInstall
  11512. } DEVICE_INSTALL_STATE, *PDEVICE_INSTALL_STATE;
  11513. //
  11514. // Define structure returned in response to IRP_MN_QUERY_BUS_INFORMATION by a
  11515. // PDO indicating the type of bus the device exists on.
  11516. //
  11517. typedef struct _PNP_BUS_INFORMATION {
  11518. GUID BusTypeGuid;
  11519. INTERFACE_TYPE LegacyBusType;
  11520. ULONG BusNumber;
  11521. } PNP_BUS_INFORMATION, *PPNP_BUS_INFORMATION;
  11522. //
  11523. // Define structure returned in response to IRP_MN_QUERY_LEGACY_BUS_INFORMATION
  11524. // by an FDO indicating the type of bus it is. This is normally the same bus
  11525. // type as the device's children (i.e., as retrieved from the child PDO's via
  11526. // IRP_MN_QUERY_BUS_INFORMATION) except for cases like CardBus, which can
  11527. // support both 16-bit (PCMCIABus) and 32-bit (PCIBus) cards.
  11528. //
  11529. typedef struct _LEGACY_BUS_INFORMATION {
  11530. GUID BusTypeGuid;
  11531. INTERFACE_TYPE LegacyBusType;
  11532. ULONG BusNumber;
  11533. } LEGACY_BUS_INFORMATION, *PLEGACY_BUS_INFORMATION;
  11534. //
  11535. // Defines for IoGetDeviceProperty(DevicePropertyRemovalPolicy).
  11536. //
  11537. typedef enum _DEVICE_REMOVAL_POLICY {
  11538. RemovalPolicyExpectNoRemoval = 1,
  11539. RemovalPolicyExpectOrderlyRemoval = 2,
  11540. RemovalPolicyExpectSurpriseRemoval = 3
  11541. } DEVICE_REMOVAL_POLICY, *PDEVICE_REMOVAL_POLICY;
  11542. typedef struct _BUS_INTERFACE_STANDARD {
  11543. //
  11544. // generic interface header
  11545. //
  11546. USHORT Size;
  11547. USHORT Version;
  11548. PVOID Context;
  11549. PINTERFACE_REFERENCE InterfaceReference;
  11550. PINTERFACE_DEREFERENCE InterfaceDereference;
  11551. //
  11552. // standard bus interfaces
  11553. //
  11554. PTRANSLATE_BUS_ADDRESS TranslateBusAddress;
  11555. PGET_DMA_ADAPTER GetDmaAdapter;
  11556. PGET_SET_DEVICE_DATA SetBusData;
  11557. PGET_SET_DEVICE_DATA GetBusData;
  11558. } BUS_INTERFACE_STANDARD, *PBUS_INTERFACE_STANDARD;
  11559. //
  11560. // The following definitions are used in ACPI QueryInterface
  11561. //
  11562. typedef BOOLEAN (* PGPE_SERVICE_ROUTINE) (
  11563. PVOID,
  11564. PVOID);
  11565. typedef NTSTATUS (* PGPE_CONNECT_VECTOR) (
  11566. PDEVICE_OBJECT,
  11567. ULONG,
  11568. KINTERRUPT_MODE,
  11569. BOOLEAN,
  11570. PGPE_SERVICE_ROUTINE,
  11571. PVOID,
  11572. PVOID);
  11573. typedef NTSTATUS (* PGPE_DISCONNECT_VECTOR) (
  11574. PVOID);
  11575. typedef NTSTATUS (* PGPE_ENABLE_EVENT) (
  11576. PDEVICE_OBJECT,
  11577. PVOID);
  11578. typedef NTSTATUS (* PGPE_DISABLE_EVENT) (
  11579. PDEVICE_OBJECT,
  11580. PVOID);
  11581. typedef NTSTATUS (* PGPE_CLEAR_STATUS) (
  11582. PDEVICE_OBJECT,
  11583. PVOID);
  11584. typedef VOID (* PDEVICE_NOTIFY_CALLBACK) (
  11585. PVOID,
  11586. ULONG);
  11587. typedef NTSTATUS (* PREGISTER_FOR_DEVICE_NOTIFICATIONS) (
  11588. PDEVICE_OBJECT,
  11589. PDEVICE_NOTIFY_CALLBACK,
  11590. PVOID);
  11591. typedef void (* PUNREGISTER_FOR_DEVICE_NOTIFICATIONS) (
  11592. PDEVICE_OBJECT,
  11593. PDEVICE_NOTIFY_CALLBACK);
  11594. typedef struct _ACPI_INTERFACE_STANDARD {
  11595. //
  11596. // Generic interface header
  11597. //
  11598. USHORT Size;
  11599. USHORT Version;
  11600. PVOID Context;
  11601. PINTERFACE_REFERENCE InterfaceReference;
  11602. PINTERFACE_DEREFERENCE InterfaceDereference;
  11603. //
  11604. // ACPI interfaces
  11605. //
  11606. PGPE_CONNECT_VECTOR GpeConnectVector;
  11607. PGPE_DISCONNECT_VECTOR GpeDisconnectVector;
  11608. PGPE_ENABLE_EVENT GpeEnableEvent;
  11609. PGPE_DISABLE_EVENT GpeDisableEvent;
  11610. PGPE_CLEAR_STATUS GpeClearStatus;
  11611. PREGISTER_FOR_DEVICE_NOTIFICATIONS RegisterForDeviceNotifications;
  11612. PUNREGISTER_FOR_DEVICE_NOTIFICATIONS UnregisterForDeviceNotifications;
  11613. } ACPI_INTERFACE_STANDARD, *PACPI_INTERFACE_STANDARD;
  11614. // end_wdm end_ntddk
  11615. typedef enum _ACPI_REG_TYPE {
  11616. PM1a_ENABLE,
  11617. PM1b_ENABLE,
  11618. PM1a_STATUS,
  11619. PM1b_STATUS,
  11620. PM1a_CONTROL,
  11621. PM1b_CONTROL,
  11622. GP_STATUS,
  11623. GP_ENABLE,
  11624. SMI_CMD,
  11625. MaxRegType
  11626. } ACPI_REG_TYPE, *PACPI_REG_TYPE;
  11627. typedef USHORT (*PREAD_ACPI_REGISTER) (
  11628. IN ACPI_REG_TYPE AcpiReg,
  11629. IN ULONG Register);
  11630. typedef VOID (*PWRITE_ACPI_REGISTER) (
  11631. IN ACPI_REG_TYPE AcpiReg,
  11632. IN ULONG Register,
  11633. IN USHORT Value
  11634. );
  11635. typedef struct ACPI_REGS_INTERFACE_STANDARD {
  11636. //
  11637. // generic interface header
  11638. //
  11639. USHORT Size;
  11640. USHORT Version;
  11641. PVOID Context;
  11642. PINTERFACE_REFERENCE InterfaceReference;
  11643. PINTERFACE_DEREFERENCE InterfaceDereference;
  11644. //
  11645. // READ/WRITE_ACPI_REGISTER functions
  11646. //
  11647. PREAD_ACPI_REGISTER ReadAcpiRegister;
  11648. PWRITE_ACPI_REGISTER WriteAcpiRegister;
  11649. } ACPI_REGS_INTERFACE_STANDARD, *PACPI_REGS_INTERFACE_STANDARD;
  11650. typedef NTSTATUS (*PHAL_QUERY_ALLOCATE_PORT_RANGE) (
  11651. IN BOOLEAN IsSparse,
  11652. IN BOOLEAN PrimaryIsMmio,
  11653. IN PVOID VirtBaseAddr OPTIONAL,
  11654. IN PHYSICAL_ADDRESS PhysBaseAddr, // Only valid if PrimaryIsMmio = TRUE
  11655. IN ULONG Length, // Only valid if PrimaryIsMmio = TRUE
  11656. OUT PUSHORT NewRangeId
  11657. );
  11658. typedef VOID (*PHAL_FREE_PORT_RANGE)(
  11659. IN USHORT RangeId
  11660. );
  11661. typedef struct _HAL_PORT_RANGE_INTERFACE {
  11662. //
  11663. // generic interface header
  11664. //
  11665. USHORT Size;
  11666. USHORT Version;
  11667. PVOID Context;
  11668. PINTERFACE_REFERENCE InterfaceReference;
  11669. PINTERFACE_DEREFERENCE InterfaceDereference;
  11670. //
  11671. // QueryAllocateRange/FreeRange functions
  11672. //
  11673. PHAL_QUERY_ALLOCATE_PORT_RANGE QueryAllocateRange;
  11674. PHAL_FREE_PORT_RANGE FreeRange;
  11675. } HAL_PORT_RANGE_INTERFACE, *PHAL_PORT_RANGE_INTERFACE;
  11676. //
  11677. // describe the CMOS HAL interface
  11678. //
  11679. typedef enum _CMOS_DEVICE_TYPE {
  11680. CmosTypeStdPCAT,
  11681. CmosTypeIntelPIIX4,
  11682. CmosTypeDal1501
  11683. } CMOS_DEVICE_TYPE;
  11684. typedef
  11685. ULONG
  11686. (*PREAD_ACPI_CMOS) (
  11687. IN CMOS_DEVICE_TYPE CmosType,
  11688. IN ULONG SourceAddress,
  11689. IN PUCHAR DataBuffer,
  11690. IN ULONG ByteCount
  11691. );
  11692. typedef
  11693. ULONG
  11694. (*PWRITE_ACPI_CMOS) (
  11695. IN CMOS_DEVICE_TYPE CmosType,
  11696. IN ULONG SourceAddress,
  11697. IN PUCHAR DataBuffer,
  11698. IN ULONG ByteCount
  11699. );
  11700. typedef struct _ACPI_CMOS_INTERFACE_STANDARD {
  11701. //
  11702. // generic interface header
  11703. //
  11704. USHORT Size;
  11705. USHORT Version;
  11706. PVOID Context;
  11707. PINTERFACE_REFERENCE InterfaceReference;
  11708. PINTERFACE_DEREFERENCE InterfaceDereference;
  11709. //
  11710. // READ/WRITE_ACPI_CMOS functions
  11711. //
  11712. PREAD_ACPI_CMOS ReadCmos;
  11713. PWRITE_ACPI_CMOS WriteCmos;
  11714. } ACPI_CMOS_INTERFACE_STANDARD, *PACPI_CMOS_INTERFACE_STANDARD;
  11715. //
  11716. // These definitions are used for getting PCI Interrupt Routing interfaces
  11717. //
  11718. typedef struct {
  11719. PVOID LinkNode;
  11720. ULONG StaticVector;
  11721. UCHAR Flags;
  11722. } ROUTING_TOKEN, *PROUTING_TOKEN;
  11723. //
  11724. // Flag indicating that the device supports
  11725. // MSI interrupt routing or that the provided token contains
  11726. // MSI routing information
  11727. //
  11728. #define PCI_MSI_ROUTING 0x1
  11729. #define PCI_STATIC_ROUTING 0x2
  11730. typedef
  11731. NTSTATUS
  11732. (*PGET_INTERRUPT_ROUTING)(
  11733. IN PDEVICE_OBJECT Pdo,
  11734. OUT ULONG *Bus,
  11735. OUT ULONG *PciSlot,
  11736. OUT UCHAR *InterruptLine,
  11737. OUT UCHAR *InterruptPin,
  11738. OUT UCHAR *ClassCode,
  11739. OUT UCHAR *SubClassCode,
  11740. OUT PDEVICE_OBJECT *ParentPdo,
  11741. OUT ROUTING_TOKEN *RoutingToken,
  11742. OUT UCHAR *Flags
  11743. );
  11744. typedef
  11745. NTSTATUS
  11746. (*PSET_INTERRUPT_ROUTING_TOKEN)(
  11747. IN PDEVICE_OBJECT Pdo,
  11748. IN PROUTING_TOKEN RoutingToken
  11749. );
  11750. typedef
  11751. VOID
  11752. (*PUPDATE_INTERRUPT_LINE)(
  11753. IN PDEVICE_OBJECT Pdo,
  11754. IN UCHAR LineRegister
  11755. );
  11756. typedef struct _INT_ROUTE_INTERFACE_STANDARD {
  11757. //
  11758. // generic interface header
  11759. //
  11760. USHORT Size;
  11761. USHORT Version;
  11762. PVOID Context;
  11763. PINTERFACE_REFERENCE InterfaceReference;
  11764. PINTERFACE_DEREFERENCE InterfaceDereference;
  11765. //
  11766. // standard bus interfaces
  11767. //
  11768. PGET_INTERRUPT_ROUTING GetInterruptRouting;
  11769. PSET_INTERRUPT_ROUTING_TOKEN SetInterruptRoutingToken;
  11770. PUPDATE_INTERRUPT_LINE UpdateInterruptLine;
  11771. } INT_ROUTE_INTERFACE_STANDARD, *PINT_ROUTE_INTERFACE_STANDARD;
  11772. // Some well-known interface versions supported by the PCI Bus Driver
  11773. #define PCI_INT_ROUTE_INTRF_STANDARD_VER 1
  11774. NTKERNELAPI
  11775. NTSTATUS
  11776. IoSynchronousInvalidateDeviceRelations(
  11777. PDEVICE_OBJECT DeviceObject,
  11778. DEVICE_RELATION_TYPE Type
  11779. );
  11780. // begin_ntddk begin_nthal begin_ntifs
  11781. NTKERNELAPI
  11782. NTSTATUS
  11783. IoReportDetectedDevice(
  11784. IN PDRIVER_OBJECT DriverObject,
  11785. IN INTERFACE_TYPE LegacyBusType,
  11786. IN ULONG BusNumber,
  11787. IN ULONG SlotNumber,
  11788. IN PCM_RESOURCE_LIST ResourceList,
  11789. IN PIO_RESOURCE_REQUIREMENTS_LIST ResourceRequirements OPTIONAL,
  11790. IN BOOLEAN ResourceAssigned,
  11791. IN OUT PDEVICE_OBJECT *DeviceObject
  11792. );
  11793. // begin_wdm
  11794. NTKERNELAPI
  11795. VOID
  11796. IoInvalidateDeviceRelations(
  11797. IN PDEVICE_OBJECT DeviceObject,
  11798. IN DEVICE_RELATION_TYPE Type
  11799. );
  11800. NTKERNELAPI
  11801. VOID
  11802. IoRequestDeviceEject(
  11803. IN PDEVICE_OBJECT PhysicalDeviceObject
  11804. );
  11805. NTKERNELAPI
  11806. NTSTATUS
  11807. IoGetDeviceProperty(
  11808. IN PDEVICE_OBJECT DeviceObject,
  11809. IN DEVICE_REGISTRY_PROPERTY DeviceProperty,
  11810. IN ULONG BufferLength,
  11811. OUT PVOID PropertyBuffer,
  11812. OUT PULONG ResultLength
  11813. );
  11814. //
  11815. // The following definitions are used in IoOpenDeviceRegistryKey
  11816. //
  11817. #define PLUGPLAY_REGKEY_DEVICE 1
  11818. #define PLUGPLAY_REGKEY_DRIVER 2
  11819. #define PLUGPLAY_REGKEY_CURRENT_HWPROFILE 4
  11820. NTKERNELAPI
  11821. NTSTATUS
  11822. IoOpenDeviceRegistryKey(
  11823. IN PDEVICE_OBJECT DeviceObject,
  11824. IN ULONG DevInstKeyType,
  11825. IN ACCESS_MASK DesiredAccess,
  11826. OUT PHANDLE DevInstRegKey
  11827. );
  11828. NTKERNELAPI
  11829. NTSTATUS
  11830. NTAPI
  11831. IoRegisterDeviceInterface(
  11832. IN PDEVICE_OBJECT PhysicalDeviceObject,
  11833. IN CONST GUID *InterfaceClassGuid,
  11834. IN PUNICODE_STRING ReferenceString, OPTIONAL
  11835. OUT PUNICODE_STRING SymbolicLinkName
  11836. );
  11837. NTKERNELAPI
  11838. NTSTATUS
  11839. IoOpenDeviceInterfaceRegistryKey(
  11840. IN PUNICODE_STRING SymbolicLinkName,
  11841. IN ACCESS_MASK DesiredAccess,
  11842. OUT PHANDLE DeviceInterfaceKey
  11843. );
  11844. NTKERNELAPI
  11845. NTSTATUS
  11846. IoSetDeviceInterfaceState(
  11847. IN PUNICODE_STRING SymbolicLinkName,
  11848. IN BOOLEAN Enable
  11849. );
  11850. NTKERNELAPI
  11851. NTSTATUS
  11852. NTAPI
  11853. IoGetDeviceInterfaces(
  11854. IN CONST GUID *InterfaceClassGuid,
  11855. IN PDEVICE_OBJECT PhysicalDeviceObject OPTIONAL,
  11856. IN ULONG Flags,
  11857. OUT PWSTR *SymbolicLinkList
  11858. );
  11859. #define DEVICE_INTERFACE_INCLUDE_NONACTIVE 0x00000001
  11860. NTKERNELAPI
  11861. NTSTATUS
  11862. NTAPI
  11863. IoGetDeviceInterfaceAlias(
  11864. IN PUNICODE_STRING SymbolicLinkName,
  11865. IN CONST GUID *AliasInterfaceClassGuid,
  11866. OUT PUNICODE_STRING AliasSymbolicLinkName
  11867. );
  11868. //
  11869. // Define PnP notification event categories
  11870. //
  11871. typedef enum _IO_NOTIFICATION_EVENT_CATEGORY {
  11872. EventCategoryReserved,
  11873. EventCategoryHardwareProfileChange,
  11874. EventCategoryDeviceInterfaceChange,
  11875. EventCategoryTargetDeviceChange
  11876. } IO_NOTIFICATION_EVENT_CATEGORY;
  11877. //
  11878. // Define flags that modify the behavior of IoRegisterPlugPlayNotification
  11879. // for the various event categories...
  11880. //
  11881. #define PNPNOTIFY_DEVICE_INTERFACE_INCLUDE_EXISTING_INTERFACES 0x00000001
  11882. typedef
  11883. NTSTATUS
  11884. (*PDRIVER_NOTIFICATION_CALLBACK_ROUTINE) (
  11885. IN PVOID NotificationStructure,
  11886. IN PVOID Context
  11887. );
  11888. NTKERNELAPI
  11889. NTSTATUS
  11890. IoRegisterPlugPlayNotification(
  11891. IN IO_NOTIFICATION_EVENT_CATEGORY EventCategory,
  11892. IN ULONG EventCategoryFlags,
  11893. IN PVOID EventCategoryData OPTIONAL,
  11894. IN PDRIVER_OBJECT DriverObject,
  11895. IN PDRIVER_NOTIFICATION_CALLBACK_ROUTINE CallbackRoutine,
  11896. IN PVOID Context,
  11897. OUT PVOID *NotificationEntry
  11898. );
  11899. NTKERNELAPI
  11900. NTSTATUS
  11901. IoUnregisterPlugPlayNotification(
  11902. IN PVOID NotificationEntry
  11903. );
  11904. NTKERNELAPI
  11905. NTSTATUS
  11906. IoReportTargetDeviceChange(
  11907. IN PDEVICE_OBJECT PhysicalDeviceObject,
  11908. IN PVOID NotificationStructure // always begins with a PLUGPLAY_NOTIFICATION_HEADER
  11909. );
  11910. typedef
  11911. VOID
  11912. (*PDEVICE_CHANGE_COMPLETE_CALLBACK)(
  11913. IN PVOID Context
  11914. );
  11915. NTKERNELAPI
  11916. VOID
  11917. IoInvalidateDeviceState(
  11918. IN PDEVICE_OBJECT PhysicalDeviceObject
  11919. );
  11920. #define IoAdjustPagingPathCount(_count_,_paging_) { \
  11921. if (_paging_) { \
  11922. InterlockedIncrement(_count_); \
  11923. } else { \
  11924. InterlockedDecrement(_count_); \
  11925. } \
  11926. }
  11927. NTKERNELAPI
  11928. NTSTATUS
  11929. IoReportTargetDeviceChangeAsynchronous(
  11930. IN PDEVICE_OBJECT PhysicalDeviceObject,
  11931. IN PVOID NotificationStructure, // always begins with a PLUGPLAY_NOTIFICATION_HEADER
  11932. IN PDEVICE_CHANGE_COMPLETE_CALLBACK Callback, OPTIONAL
  11933. IN PVOID Context OPTIONAL
  11934. );
  11935. NTKERNELAPI
  11936. NTSTATUS
  11937. IoReportResourceForDetection(
  11938. IN PDRIVER_OBJECT DriverObject,
  11939. IN PCM_RESOURCE_LIST DriverList OPTIONAL,
  11940. IN ULONG DriverListSize OPTIONAL,
  11941. IN PDEVICE_OBJECT DeviceObject OPTIONAL,
  11942. IN PCM_RESOURCE_LIST DeviceList OPTIONAL,
  11943. IN ULONG DeviceListSize OPTIONAL,
  11944. OUT PBOOLEAN ConflictDetected
  11945. );
  11946. typedef enum _RESOURCE_TRANSLATION_DIRECTION {
  11947. TranslateChildToParent,
  11948. TranslateParentToChild
  11949. } RESOURCE_TRANSLATION_DIRECTION;
  11950. typedef
  11951. NTSTATUS
  11952. (*PTRANSLATE_RESOURCE_HANDLER)(
  11953. IN PVOID Context,
  11954. IN PCM_PARTIAL_RESOURCE_DESCRIPTOR Source,
  11955. IN RESOURCE_TRANSLATION_DIRECTION Direction,
  11956. IN ULONG AlternativesCount, OPTIONAL
  11957. IN IO_RESOURCE_DESCRIPTOR Alternatives[], OPTIONAL
  11958. IN PDEVICE_OBJECT PhysicalDeviceObject,
  11959. OUT PCM_PARTIAL_RESOURCE_DESCRIPTOR Target
  11960. );
  11961. typedef
  11962. NTSTATUS
  11963. (*PTRANSLATE_RESOURCE_REQUIREMENTS_HANDLER)(
  11964. IN PVOID Context,
  11965. IN PIO_RESOURCE_DESCRIPTOR Source,
  11966. IN PDEVICE_OBJECT PhysicalDeviceObject,
  11967. OUT PULONG TargetCount,
  11968. OUT PIO_RESOURCE_DESCRIPTOR *Target
  11969. );
  11970. //
  11971. // Translator Interface
  11972. //
  11973. typedef struct _TRANSLATOR_INTERFACE {
  11974. USHORT Size;
  11975. USHORT Version;
  11976. PVOID Context;
  11977. PINTERFACE_REFERENCE InterfaceReference;
  11978. PINTERFACE_DEREFERENCE InterfaceDereference;
  11979. PTRANSLATE_RESOURCE_HANDLER TranslateResources;
  11980. PTRANSLATE_RESOURCE_REQUIREMENTS_HANDLER TranslateResourceRequirements;
  11981. } TRANSLATOR_INTERFACE, *PTRANSLATOR_INTERFACE;
  11982. //
  11983. // Header structure for all Plug&Play notification events...
  11984. //
  11985. typedef struct _PLUGPLAY_NOTIFICATION_HEADER {
  11986. USHORT Version; // presently at version 1.
  11987. USHORT Size; // size (in bytes) of header + event-specific data.
  11988. GUID Event;
  11989. //
  11990. // Event-specific stuff starts here.
  11991. //
  11992. } PLUGPLAY_NOTIFICATION_HEADER, *PPLUGPLAY_NOTIFICATION_HEADER;
  11993. //
  11994. // Notification structure for all EventCategoryHardwareProfileChange events...
  11995. //
  11996. typedef struct _HWPROFILE_CHANGE_NOTIFICATION {
  11997. USHORT Version;
  11998. USHORT Size;
  11999. GUID Event;
  12000. //
  12001. // (No event-specific data)
  12002. //
  12003. } HWPROFILE_CHANGE_NOTIFICATION, *PHWPROFILE_CHANGE_NOTIFICATION;
  12004. //
  12005. // Notification structure for all EventCategoryDeviceInterfaceChange events...
  12006. //
  12007. typedef struct _DEVICE_INTERFACE_CHANGE_NOTIFICATION {
  12008. USHORT Version;
  12009. USHORT Size;
  12010. GUID Event;
  12011. //
  12012. // Event-specific data
  12013. //
  12014. GUID InterfaceClassGuid;
  12015. PUNICODE_STRING SymbolicLinkName;
  12016. } DEVICE_INTERFACE_CHANGE_NOTIFICATION, *PDEVICE_INTERFACE_CHANGE_NOTIFICATION;
  12017. //
  12018. // Notification structures for EventCategoryTargetDeviceChange...
  12019. //
  12020. //
  12021. // The following structure is used for TargetDeviceQueryRemove,
  12022. // TargetDeviceRemoveCancelled, and TargetDeviceRemoveComplete:
  12023. //
  12024. typedef struct _TARGET_DEVICE_REMOVAL_NOTIFICATION {
  12025. USHORT Version;
  12026. USHORT Size;
  12027. GUID Event;
  12028. //
  12029. // Event-specific data
  12030. //
  12031. PFILE_OBJECT FileObject;
  12032. } TARGET_DEVICE_REMOVAL_NOTIFICATION, *PTARGET_DEVICE_REMOVAL_NOTIFICATION;
  12033. //
  12034. // The following structure header is used for all other (i.e., 3rd-party)
  12035. // target device change events. The structure accommodates both a
  12036. // variable-length binary data buffer, and a variable-length unicode text
  12037. // buffer. The header must indicate where the text buffer begins, so that
  12038. // the data can be delivered in the appropriate format (ANSI or Unicode)
  12039. // to user-mode recipients (i.e., that have registered for handle-based
  12040. // notification via RegisterDeviceNotification).
  12041. //
  12042. typedef struct _TARGET_DEVICE_CUSTOM_NOTIFICATION {
  12043. USHORT Version;
  12044. USHORT Size;
  12045. GUID Event;
  12046. //
  12047. // Event-specific data
  12048. //
  12049. PFILE_OBJECT FileObject; // This field must be set to NULL by callers of
  12050. // IoReportTargetDeviceChange. Clients that
  12051. // have registered for target device change
  12052. // notification on the affected PDO will be
  12053. // called with this field set to the file object
  12054. // they specified during registration.
  12055. //
  12056. LONG NameBufferOffset; // offset (in bytes) from beginning of
  12057. // CustomDataBuffer where text begins (-1 if none)
  12058. //
  12059. UCHAR CustomDataBuffer[1]; // variable-length buffer, containing (optionally)
  12060. // a binary data at the start of the buffer,
  12061. // followed by an optional unicode text buffer
  12062. // (word-aligned).
  12063. //
  12064. } TARGET_DEVICE_CUSTOM_NOTIFICATION, *PTARGET_DEVICE_CUSTOM_NOTIFICATION;
  12065. ULONG
  12066. IoPnPDeliverServicePowerNotification(
  12067. IN POWER_ACTION PowerOperation,
  12068. IN ULONG PowerNotificationCode,
  12069. IN ULONG PowerNotificationData,
  12070. IN BOOLEAN Synchronous
  12071. );
  12072. //
  12073. // Define OEM bitmapped font check values.
  12074. //
  12075. #define OEM_FONT_VERSION 0x200
  12076. #define OEM_FONT_TYPE 0
  12077. #define OEM_FONT_ITALIC 0
  12078. #define OEM_FONT_UNDERLINE 0
  12079. #define OEM_FONT_STRIKEOUT 0
  12080. #define OEM_FONT_CHARACTER_SET 255
  12081. #define OEM_FONT_FAMILY (3 << 4)
  12082. //
  12083. // Define OEM bitmapped font file header structure.
  12084. //
  12085. // N.B. this is a packed structure.
  12086. //
  12087. #include "pshpack1.h"
  12088. typedef struct _OEM_FONT_FILE_HEADER {
  12089. USHORT Version;
  12090. ULONG FileSize;
  12091. UCHAR Copyright[60];
  12092. USHORT Type;
  12093. USHORT Points;
  12094. USHORT VerticleResolution;
  12095. USHORT HorizontalResolution;
  12096. USHORT Ascent;
  12097. USHORT InternalLeading;
  12098. USHORT ExternalLeading;
  12099. UCHAR Italic;
  12100. UCHAR Underline;
  12101. UCHAR StrikeOut;
  12102. USHORT Weight;
  12103. UCHAR CharacterSet;
  12104. USHORT PixelWidth;
  12105. USHORT PixelHeight;
  12106. UCHAR Family;
  12107. USHORT AverageWidth;
  12108. USHORT MaximumWidth;
  12109. UCHAR FirstCharacter;
  12110. UCHAR LastCharacter;
  12111. UCHAR DefaultCharacter;
  12112. UCHAR BreakCharacter;
  12113. USHORT WidthInBytes;
  12114. ULONG Device;
  12115. ULONG Face;
  12116. ULONG BitsPointer;
  12117. ULONG BitsOffset;
  12118. UCHAR Filler;
  12119. struct {
  12120. USHORT Width;
  12121. USHORT Offset;
  12122. } Map[1];
  12123. } OEM_FONT_FILE_HEADER, *POEM_FONT_FILE_HEADER;
  12124. #include "poppack.h"
  12125. //
  12126. // Define the device description structure.
  12127. //
  12128. typedef struct _DEVICE_DESCRIPTION {
  12129. ULONG Version;
  12130. BOOLEAN Master;
  12131. BOOLEAN ScatterGather;
  12132. BOOLEAN DemandMode;
  12133. BOOLEAN AutoInitialize;
  12134. BOOLEAN Dma32BitAddresses;
  12135. BOOLEAN IgnoreCount;
  12136. BOOLEAN Reserved1; // must be false
  12137. BOOLEAN Dma64BitAddresses;
  12138. ULONG BusNumber; // unused for WDM
  12139. ULONG DmaChannel;
  12140. INTERFACE_TYPE InterfaceType;
  12141. DMA_WIDTH DmaWidth;
  12142. DMA_SPEED DmaSpeed;
  12143. ULONG MaximumLength;
  12144. ULONG DmaPort;
  12145. } DEVICE_DESCRIPTION, *PDEVICE_DESCRIPTION;
  12146. //
  12147. // Define the supported version numbers for the device description structure.
  12148. //
  12149. #define DEVICE_DESCRIPTION_VERSION 0
  12150. #define DEVICE_DESCRIPTION_VERSION1 1
  12151. #define DEVICE_DESCRIPTION_VERSION2 2
  12152. // end_ntddk end_wdm
  12153. //
  12154. // Boot record disk partition table entry structure format.
  12155. //
  12156. typedef struct _PARTITION_DESCRIPTOR {
  12157. UCHAR ActiveFlag; // Bootable or not
  12158. UCHAR StartingTrack; // Not used
  12159. UCHAR StartingCylinderLsb; // Not used
  12160. UCHAR StartingCylinderMsb; // Not used
  12161. UCHAR PartitionType; // 12 bit FAT, 16 bit FAT etc.
  12162. UCHAR EndingTrack; // Not used
  12163. UCHAR EndingCylinderLsb; // Not used
  12164. UCHAR EndingCylinderMsb; // Not used
  12165. UCHAR StartingSectorLsb0; // Hidden sectors
  12166. UCHAR StartingSectorLsb1;
  12167. UCHAR StartingSectorMsb0;
  12168. UCHAR StartingSectorMsb1;
  12169. UCHAR PartitionLengthLsb0; // Sectors in this partition
  12170. UCHAR PartitionLengthLsb1;
  12171. UCHAR PartitionLengthMsb0;
  12172. UCHAR PartitionLengthMsb1;
  12173. } PARTITION_DESCRIPTOR, *PPARTITION_DESCRIPTOR;
  12174. //
  12175. // Number of partition table entries
  12176. //
  12177. #define NUM_PARTITION_TABLE_ENTRIES 4
  12178. //
  12179. // Partition table record and boot signature offsets in 16-bit words.
  12180. //
  12181. #define PARTITION_TABLE_OFFSET (0x1be / 2)
  12182. #define BOOT_SIGNATURE_OFFSET ((0x200 / 2) - 1)
  12183. //
  12184. // Boot record signature value.
  12185. //
  12186. #define BOOT_RECORD_SIGNATURE (0xaa55)
  12187. //
  12188. // Initial size of the Partition list structure.
  12189. //
  12190. #define PARTITION_BUFFER_SIZE 2048
  12191. //
  12192. // Partition active flag - i.e., boot indicator
  12193. //
  12194. #define PARTITION_ACTIVE_FLAG 0x80
  12195. //
  12196. // Get and set environment variable values.
  12197. //
  12198. NTHALAPI
  12199. ARC_STATUS
  12200. HalGetEnvironmentVariable (
  12201. IN PCHAR Variable,
  12202. IN USHORT Length,
  12203. OUT PCHAR Buffer
  12204. );
  12205. NTHALAPI
  12206. ARC_STATUS
  12207. HalSetEnvironmentVariable (
  12208. IN PCHAR Variable,
  12209. IN PCHAR Value
  12210. );
  12211. NTHALAPI
  12212. NTSTATUS
  12213. HalGetEnvironmentVariableEx (
  12214. IN PWSTR VariableName,
  12215. IN LPGUID VendorGuid,
  12216. OUT PVOID Value,
  12217. IN OUT PULONG ValueLength,
  12218. OUT PULONG Attributes OPTIONAL
  12219. );
  12220. NTSTATUS
  12221. HalSetEnvironmentVariableEx (
  12222. IN PWSTR VariableName,
  12223. IN LPGUID VendorGuid,
  12224. IN PVOID Value,
  12225. IN ULONG ValueLength,
  12226. IN ULONG Attributes
  12227. );
  12228. NTSTATUS
  12229. HalEnumerateEnvironmentVariablesEx (
  12230. IN ULONG InformationClass,
  12231. OUT PVOID Buffer,
  12232. IN OUT PULONG BufferLength
  12233. );
  12234. #if defined(_ALPHA_) || defined(_IA64_)
  12235. NTHALAPI
  12236. VOID
  12237. HalFlushIoBuffers (
  12238. IN PMDL Mdl,
  12239. IN BOOLEAN ReadOperation,
  12240. IN BOOLEAN DmaOperation
  12241. );
  12242. // begin_ntddk begin_ntifs begin_ntndis
  12243. DECLSPEC_DEPRECATED_DDK // Use GetDmaRequirement
  12244. NTHALAPI
  12245. ULONG
  12246. HalGetDmaAlignmentRequirement (
  12247. VOID
  12248. );
  12249. #endif
  12250. #if defined(_M_IX86) || defined(_M_AMD64)
  12251. #define HalGetDmaAlignmentRequirement() 1L
  12252. #endif
  12253. NTHALAPI // ntddk ntifs wdm ntndis
  12254. VOID // ntddk ntifs wdm ntndis
  12255. KeFlushWriteBuffer ( // ntddk ntifs wdm ntndis
  12256. VOID // ntddk ntifs wdm ntndis
  12257. ); // ntddk ntifs wdm ntndis
  12258. // ntddk ntifs wdm ntndis
  12259. #if defined(_ALPHA_)
  12260. NTHALAPI
  12261. PVOID
  12262. HalCreateQva(
  12263. IN PHYSICAL_ADDRESS PhysicalAddress,
  12264. IN PVOID VirtualAddress
  12265. );
  12266. NTHALAPI
  12267. PVOID
  12268. HalDereferenceQva(
  12269. PVOID Qva,
  12270. INTERFACE_TYPE InterfaceType,
  12271. ULONG BusNumber
  12272. );
  12273. #endif
  12274. #if !defined(_X86_)
  12275. NTHALAPI
  12276. BOOLEAN
  12277. HalCallBios (
  12278. IN ULONG BiosCommand,
  12279. IN OUT PULONG Eax,
  12280. IN OUT PULONG Ebx,
  12281. IN OUT PULONG Ecx,
  12282. IN OUT PULONG Edx,
  12283. IN OUT PULONG Esi,
  12284. IN OUT PULONG Edi,
  12285. IN OUT PULONG Ebp
  12286. );
  12287. #endif
  12288. NTHALAPI
  12289. BOOLEAN
  12290. HalQueryRealTimeClock (
  12291. OUT PTIME_FIELDS TimeFields
  12292. );
  12293. //
  12294. // Firmware interface functions.
  12295. //
  12296. NTHALAPI
  12297. VOID
  12298. HalReturnToFirmware (
  12299. IN FIRMWARE_REENTRY Routine
  12300. );
  12301. //
  12302. // System interrupts functions.
  12303. //
  12304. NTHALAPI
  12305. VOID
  12306. HalDisableSystemInterrupt (
  12307. IN ULONG Vector,
  12308. IN KIRQL Irql
  12309. );
  12310. NTHALAPI
  12311. BOOLEAN
  12312. HalEnableSystemInterrupt (
  12313. IN ULONG Vector,
  12314. IN KIRQL Irql,
  12315. IN KINTERRUPT_MODE InterruptMode
  12316. );
  12317. // begin_ntddk
  12318. //
  12319. // I/O driver configuration functions.
  12320. //
  12321. #if !defined(NO_LEGACY_DRIVERS)
  12322. DECLSPEC_DEPRECATED_DDK // Use Pnp or IoReportDetectedDevice
  12323. NTHALAPI
  12324. NTSTATUS
  12325. HalAssignSlotResources (
  12326. IN PUNICODE_STRING RegistryPath,
  12327. IN PUNICODE_STRING DriverClassName OPTIONAL,
  12328. IN PDRIVER_OBJECT DriverObject,
  12329. IN PDEVICE_OBJECT DeviceObject,
  12330. IN INTERFACE_TYPE BusType,
  12331. IN ULONG BusNumber,
  12332. IN ULONG SlotNumber,
  12333. IN OUT PCM_RESOURCE_LIST *AllocatedResources
  12334. );
  12335. DECLSPEC_DEPRECATED_DDK // Use Pnp or IoReportDetectedDevice
  12336. NTHALAPI
  12337. ULONG
  12338. HalGetInterruptVector(
  12339. IN INTERFACE_TYPE InterfaceType,
  12340. IN ULONG BusNumber,
  12341. IN ULONG BusInterruptLevel,
  12342. IN ULONG BusInterruptVector,
  12343. OUT PKIRQL Irql,
  12344. OUT PKAFFINITY Affinity
  12345. );
  12346. DECLSPEC_DEPRECATED_DDK // Use IRP_MN_QUERY_INTERFACE and IRP_MN_READ_CONFIG
  12347. NTHALAPI
  12348. ULONG
  12349. HalSetBusData(
  12350. IN BUS_DATA_TYPE BusDataType,
  12351. IN ULONG BusNumber,
  12352. IN ULONG SlotNumber,
  12353. IN PVOID Buffer,
  12354. IN ULONG Length
  12355. );
  12356. #endif // NO_LEGACY_DRIVERS
  12357. DECLSPEC_DEPRECATED_DDK // Use IRP_MN_QUERY_INTERFACE and IRP_MN_READ_CONFIG
  12358. NTHALAPI
  12359. ULONG
  12360. HalSetBusDataByOffset(
  12361. IN BUS_DATA_TYPE BusDataType,
  12362. IN ULONG BusNumber,
  12363. IN ULONG SlotNumber,
  12364. IN PVOID Buffer,
  12365. IN ULONG Offset,
  12366. IN ULONG Length
  12367. );
  12368. DECLSPEC_DEPRECATED_DDK // Use IRP_MN_QUERY_INTERFACE and IRP_MN_READ_CONFIG
  12369. NTHALAPI
  12370. BOOLEAN
  12371. HalTranslateBusAddress(
  12372. IN INTERFACE_TYPE InterfaceType,
  12373. IN ULONG BusNumber,
  12374. IN PHYSICAL_ADDRESS BusAddress,
  12375. IN OUT PULONG AddressSpace,
  12376. OUT PPHYSICAL_ADDRESS TranslatedAddress
  12377. );
  12378. //
  12379. // Values for AddressSpace parameter of HalTranslateBusAddress
  12380. //
  12381. // 0x0 - Memory space
  12382. // 0x1 - Port space
  12383. // 0x2 - 0x1F - Address spaces specific for Alpha
  12384. // 0x2 - UserMode view of memory space
  12385. // 0x3 - UserMode view of port space
  12386. // 0x4 - Dense memory space
  12387. // 0x5 - reserved
  12388. // 0x6 - UserMode view of dense memory space
  12389. // 0x7 - 0x1F - reserved
  12390. //
  12391. NTHALAPI
  12392. PVOID
  12393. HalAllocateCrashDumpRegisters(
  12394. IN PADAPTER_OBJECT AdapterObject,
  12395. IN OUT PULONG NumberOfMapRegisters
  12396. );
  12397. #if !defined(NO_LEGACY_DRIVERS)
  12398. DECLSPEC_DEPRECATED_DDK // Use IRP_MN_QUERY_INTERFACE and IRP_MN_READ_CONFIG
  12399. NTHALAPI
  12400. ULONG
  12401. HalGetBusData(
  12402. IN BUS_DATA_TYPE BusDataType,
  12403. IN ULONG BusNumber,
  12404. IN ULONG SlotNumber,
  12405. IN PVOID Buffer,
  12406. IN ULONG Length
  12407. );
  12408. #endif // NO_LEGACY_DRIVERS
  12409. DECLSPEC_DEPRECATED_DDK // Use IRP_MN_QUERY_INTERFACE and IRP_MN_READ_CONFIG
  12410. NTHALAPI
  12411. ULONG
  12412. HalGetBusDataByOffset(
  12413. IN BUS_DATA_TYPE BusDataType,
  12414. IN ULONG BusNumber,
  12415. IN ULONG SlotNumber,
  12416. IN PVOID Buffer,
  12417. IN ULONG Offset,
  12418. IN ULONG Length
  12419. );
  12420. DECLSPEC_DEPRECATED_DDK // Use IoGetDmaAdapter
  12421. NTHALAPI
  12422. PADAPTER_OBJECT
  12423. HalGetAdapter(
  12424. IN PDEVICE_DESCRIPTION DeviceDescription,
  12425. IN OUT PULONG NumberOfMapRegisters
  12426. );
  12427. //
  12428. // System beep functions.
  12429. //
  12430. #if !defined(NO_LEGACY_DRIVERS)
  12431. NTHALAPI
  12432. BOOLEAN
  12433. HalMakeBeep(
  12434. IN ULONG Frequency
  12435. );
  12436. #endif // NO_LEGACY_DRIVERS
  12437. //
  12438. // The following function prototypes are for HAL routines with a prefix of Io.
  12439. //
  12440. // DMA adapter object functions.
  12441. //
  12442. //
  12443. // Performance counter function.
  12444. //
  12445. NTHALAPI
  12446. LARGE_INTEGER
  12447. KeQueryPerformanceCounter (
  12448. OUT PLARGE_INTEGER PerformanceFrequency OPTIONAL
  12449. );
  12450. // begin_ntndis
  12451. //
  12452. // Stall processor execution function.
  12453. //
  12454. NTHALAPI
  12455. VOID
  12456. KeStallExecutionProcessor (
  12457. IN ULONG MicroSeconds
  12458. );
  12459. typedef
  12460. PBUS_HANDLER
  12461. (FASTCALL *pHalHandlerForBus) (
  12462. IN INTERFACE_TYPE InterfaceType,
  12463. IN ULONG BusNumber
  12464. );
  12465. typedef
  12466. VOID
  12467. (FASTCALL *pHalReferenceBusHandler) (
  12468. IN PBUS_HANDLER BusHandler
  12469. );
  12470. //*****************************************************************************
  12471. // HAL Function dispatch
  12472. //
  12473. typedef enum _HAL_QUERY_INFORMATION_CLASS {
  12474. HalInstalledBusInformation,
  12475. HalProfileSourceInformation,
  12476. HalInformationClassUnused1,
  12477. HalPowerInformation,
  12478. HalProcessorSpeedInformation,
  12479. HalCallbackInformation,
  12480. HalMapRegisterInformation,
  12481. HalMcaLogInformation, // Machine Check Abort Information
  12482. HalFrameBufferCachingInformation,
  12483. HalDisplayBiosInformation,
  12484. HalProcessorFeatureInformation,
  12485. HalNumaTopologyInterface,
  12486. HalErrorInformation, // General MCA, CMC, CPE Error Information.
  12487. HalCmcLogInformation, // Processor Corrected Machine Check Information
  12488. HalCpeLogInformation, // Corrected Platform Error Information
  12489. HalQueryMcaInterface,
  12490. HalQueryAMLIIllegalIOPortAddresses,
  12491. HalQueryMaxHotPlugMemoryAddress,
  12492. HalPartitionIpiInterface,
  12493. HalPlatformInformation
  12494. // information levels >= 0x8000000 reserved for OEM use
  12495. } HAL_QUERY_INFORMATION_CLASS, *PHAL_QUERY_INFORMATION_CLASS;
  12496. typedef enum _HAL_SET_INFORMATION_CLASS {
  12497. HalProfileSourceInterval,
  12498. HalProfileSourceInterruptHandler,
  12499. HalMcaRegisterDriver, // Registring Machine Check Abort driver
  12500. HalKernelErrorHandler,
  12501. HalCmcRegisterDriver, // Registring Processor Corrected Machine Check driver
  12502. HalCpeRegisterDriver, // Registring Corrected Platform Error driver
  12503. HalMcaLog,
  12504. HalCmcLog,
  12505. HalCpeLog,
  12506. } HAL_SET_INFORMATION_CLASS, *PHAL_SET_INFORMATION_CLASS;
  12507. typedef
  12508. NTSTATUS
  12509. (*pHalQuerySystemInformation)(
  12510. IN HAL_QUERY_INFORMATION_CLASS InformationClass,
  12511. IN ULONG BufferSize,
  12512. IN OUT PVOID Buffer,
  12513. OUT PULONG ReturnedLength
  12514. );
  12515. NTSTATUS
  12516. HaliQuerySystemInformation(
  12517. IN HAL_SET_INFORMATION_CLASS InformationClass,
  12518. IN ULONG BufferSize,
  12519. IN OUT PVOID Buffer,
  12520. OUT PULONG ReturnedLength
  12521. );
  12522. NTSTATUS
  12523. HaliHandlePCIConfigSpaceAccess(
  12524. IN BOOLEAN Read,
  12525. IN ULONG Addr,
  12526. IN ULONG Size,
  12527. IN OUT PULONG pData
  12528. );
  12529. typedef
  12530. NTSTATUS
  12531. (*pHalSetSystemInformation)(
  12532. IN HAL_SET_INFORMATION_CLASS InformationClass,
  12533. IN ULONG BufferSize,
  12534. IN PVOID Buffer
  12535. );
  12536. NTSTATUS
  12537. HaliSetSystemInformation(
  12538. IN HAL_SET_INFORMATION_CLASS InformationClass,
  12539. IN ULONG BufferSize,
  12540. IN PVOID Buffer
  12541. );
  12542. typedef
  12543. VOID
  12544. (FASTCALL *pHalExamineMBR)(
  12545. IN PDEVICE_OBJECT DeviceObject,
  12546. IN ULONG SectorSize,
  12547. IN ULONG MBRTypeIdentifier,
  12548. OUT PVOID *Buffer
  12549. );
  12550. typedef
  12551. VOID
  12552. (FASTCALL *pHalIoAssignDriveLetters)(
  12553. IN struct _LOADER_PARAMETER_BLOCK *LoaderBlock,
  12554. IN PSTRING NtDeviceName,
  12555. OUT PUCHAR NtSystemPath,
  12556. OUT PSTRING NtSystemPathString
  12557. );
  12558. typedef
  12559. NTSTATUS
  12560. (FASTCALL *pHalIoReadPartitionTable)(
  12561. IN PDEVICE_OBJECT DeviceObject,
  12562. IN ULONG SectorSize,
  12563. IN BOOLEAN ReturnRecognizedPartitions,
  12564. OUT struct _DRIVE_LAYOUT_INFORMATION **PartitionBuffer
  12565. );
  12566. typedef
  12567. NTSTATUS
  12568. (FASTCALL *pHalIoSetPartitionInformation)(
  12569. IN PDEVICE_OBJECT DeviceObject,
  12570. IN ULONG SectorSize,
  12571. IN ULONG PartitionNumber,
  12572. IN ULONG PartitionType
  12573. );
  12574. typedef
  12575. NTSTATUS
  12576. (FASTCALL *pHalIoWritePartitionTable)(
  12577. IN PDEVICE_OBJECT DeviceObject,
  12578. IN ULONG SectorSize,
  12579. IN ULONG SectorsPerTrack,
  12580. IN ULONG NumberOfHeads,
  12581. IN struct _DRIVE_LAYOUT_INFORMATION *PartitionBuffer
  12582. );
  12583. typedef
  12584. NTSTATUS
  12585. (*pHalQueryBusSlots)(
  12586. IN PBUS_HANDLER BusHandler,
  12587. IN ULONG BufferSize,
  12588. OUT PULONG SlotNumbers,
  12589. OUT PULONG ReturnedLength
  12590. );
  12591. typedef
  12592. NTSTATUS
  12593. (*pHalInitPnpDriver)(
  12594. VOID
  12595. );
  12596. NTSTATUS
  12597. HaliInitPnpDriver(
  12598. VOID
  12599. );
  12600. typedef struct _PM_DISPATCH_TABLE {
  12601. ULONG Signature;
  12602. ULONG Version;
  12603. PVOID Function[1];
  12604. } PM_DISPATCH_TABLE, *PPM_DISPATCH_TABLE;
  12605. typedef
  12606. NTSTATUS
  12607. (*pHalInitPowerManagement)(
  12608. IN PPM_DISPATCH_TABLE PmDriverDispatchTable,
  12609. OUT PPM_DISPATCH_TABLE *PmHalDispatchTable
  12610. );
  12611. NTSTATUS
  12612. HaliInitPowerManagement(
  12613. IN PPM_DISPATCH_TABLE PmDriverDispatchTable,
  12614. IN OUT PPM_DISPATCH_TABLE *PmHalDispatchTable
  12615. );
  12616. typedef
  12617. struct _DMA_ADAPTER *
  12618. (*pHalGetDmaAdapter)(
  12619. IN PVOID Context,
  12620. IN struct _DEVICE_DESCRIPTION *DeviceDescriptor,
  12621. OUT PULONG NumberOfMapRegisters
  12622. );
  12623. struct _DMA_ADAPTER *
  12624. HaliGetDmaAdapter(
  12625. IN PVOID Context,
  12626. IN struct _DEVICE_DESCRIPTION *DeviceDescriptor,
  12627. OUT PULONG NumberOfMapRegisters
  12628. );
  12629. typedef
  12630. NTSTATUS
  12631. (*pHalGetInterruptTranslator)(
  12632. IN INTERFACE_TYPE ParentInterfaceType,
  12633. IN ULONG ParentBusNumber,
  12634. IN INTERFACE_TYPE BridgeInterfaceType,
  12635. IN USHORT Size,
  12636. IN USHORT Version,
  12637. OUT PTRANSLATOR_INTERFACE Translator,
  12638. OUT PULONG BridgeBusNumber
  12639. );
  12640. NTSTATUS
  12641. HaliGetInterruptTranslator(
  12642. IN INTERFACE_TYPE ParentInterfaceType,
  12643. IN ULONG ParentBusNumber,
  12644. IN INTERFACE_TYPE BridgeInterfaceType,
  12645. IN USHORT Size,
  12646. IN USHORT Version,
  12647. OUT PTRANSLATOR_INTERFACE Translator,
  12648. OUT PULONG BridgeBusNumber
  12649. );
  12650. typedef
  12651. BOOLEAN
  12652. (*pHalTranslateBusAddress)(
  12653. IN INTERFACE_TYPE InterfaceType,
  12654. IN ULONG BusNumber,
  12655. IN PHYSICAL_ADDRESS BusAddress,
  12656. IN OUT PULONG AddressSpace,
  12657. OUT PPHYSICAL_ADDRESS TranslatedAddress
  12658. );
  12659. typedef
  12660. NTSTATUS
  12661. (*pHalAssignSlotResources) (
  12662. IN PUNICODE_STRING RegistryPath,
  12663. IN PUNICODE_STRING DriverClassName OPTIONAL,
  12664. IN PDRIVER_OBJECT DriverObject,
  12665. IN PDEVICE_OBJECT DeviceObject,
  12666. IN INTERFACE_TYPE BusType,
  12667. IN ULONG BusNumber,
  12668. IN ULONG SlotNumber,
  12669. IN OUT PCM_RESOURCE_LIST *AllocatedResources
  12670. );
  12671. typedef
  12672. VOID
  12673. (*pHalHaltSystem) (
  12674. VOID
  12675. );
  12676. typedef
  12677. VOID
  12678. (*pHalResetDisplay) (
  12679. VOID
  12680. );
  12681. typedef
  12682. UCHAR
  12683. (*pHalVectorToIDTEntry) (
  12684. ULONG Vector
  12685. );
  12686. typedef
  12687. BOOLEAN
  12688. (*pHalFindBusAddressTranslation) (
  12689. IN PHYSICAL_ADDRESS BusAddress,
  12690. IN OUT PULONG AddressSpace,
  12691. OUT PPHYSICAL_ADDRESS TranslatedAddress,
  12692. IN OUT PULONG_PTR Context,
  12693. IN BOOLEAN NextBus
  12694. );
  12695. typedef
  12696. NTSTATUS
  12697. (*pHalStartMirroring)(
  12698. VOID
  12699. );
  12700. typedef
  12701. NTSTATUS
  12702. (*pHalEndMirroring)(
  12703. IN ULONG PassNumber
  12704. );
  12705. typedef
  12706. NTSTATUS
  12707. (*pHalMirrorPhysicalMemory)(
  12708. IN PHYSICAL_ADDRESS PhysicalAddress,
  12709. IN LARGE_INTEGER NumberOfBytes
  12710. );
  12711. typedef
  12712. NTSTATUS
  12713. (*pHalMirrorVerify)(
  12714. IN PHYSICAL_ADDRESS PhysicalAddress,
  12715. IN LARGE_INTEGER NumberOfBytes
  12716. );
  12717. typedef struct {
  12718. UCHAR Type; //CmResourceType
  12719. BOOLEAN Valid;
  12720. UCHAR Reserved[2];
  12721. PUCHAR TranslatedAddress;
  12722. ULONG Length;
  12723. } DEBUG_DEVICE_ADDRESS, *PDEBUG_DEVICE_ADDRESS;
  12724. typedef struct {
  12725. PHYSICAL_ADDRESS Start;
  12726. PHYSICAL_ADDRESS MaxEnd;
  12727. PVOID VirtualAddress;
  12728. ULONG Length;
  12729. BOOLEAN Cached;
  12730. BOOLEAN Aligned;
  12731. } DEBUG_MEMORY_REQUIREMENTS, *PDEBUG_MEMORY_REQUIREMENTS;
  12732. typedef struct {
  12733. ULONG Bus;
  12734. ULONG Slot;
  12735. USHORT VendorID;
  12736. USHORT DeviceID;
  12737. UCHAR BaseClass;
  12738. UCHAR SubClass;
  12739. UCHAR ProgIf;
  12740. BOOLEAN Initialized;
  12741. DEBUG_DEVICE_ADDRESS BaseAddress[6];
  12742. DEBUG_MEMORY_REQUIREMENTS Memory;
  12743. } DEBUG_DEVICE_DESCRIPTOR, *PDEBUG_DEVICE_DESCRIPTOR;
  12744. typedef
  12745. NTSTATUS
  12746. (*pKdSetupPciDeviceForDebugging)(
  12747. IN PVOID LoaderBlock, OPTIONAL
  12748. IN OUT PDEBUG_DEVICE_DESCRIPTOR PciDevice
  12749. );
  12750. typedef
  12751. NTSTATUS
  12752. (*pKdReleasePciDeviceForDebugging)(
  12753. IN OUT PDEBUG_DEVICE_DESCRIPTOR PciDevice
  12754. );
  12755. typedef
  12756. PVOID
  12757. (*pKdGetAcpiTablePhase0)(
  12758. IN struct _LOADER_PARAMETER_BLOCK *LoaderBlock,
  12759. IN ULONG Signature
  12760. );
  12761. typedef
  12762. VOID
  12763. (*pKdCheckPowerButton)(
  12764. VOID
  12765. );
  12766. typedef
  12767. VOID
  12768. (*pHalEndOfBoot)(
  12769. VOID
  12770. );
  12771. typedef
  12772. PVOID
  12773. (*pKdMapPhysicalMemory64)(
  12774. IN PHYSICAL_ADDRESS PhysicalAddress,
  12775. IN ULONG NumberPages
  12776. );
  12777. typedef
  12778. VOID
  12779. (*pKdUnmapVirtualAddress)(
  12780. IN PVOID VirtualAddress,
  12781. IN ULONG NumberPages
  12782. );
  12783. typedef struct {
  12784. ULONG Version;
  12785. pHalQuerySystemInformation HalQuerySystemInformation;
  12786. pHalSetSystemInformation HalSetSystemInformation;
  12787. pHalQueryBusSlots HalQueryBusSlots;
  12788. ULONG Spare1;
  12789. pHalExamineMBR HalExamineMBR;
  12790. pHalIoAssignDriveLetters HalIoAssignDriveLetters;
  12791. pHalIoReadPartitionTable HalIoReadPartitionTable;
  12792. pHalIoSetPartitionInformation HalIoSetPartitionInformation;
  12793. pHalIoWritePartitionTable HalIoWritePartitionTable;
  12794. pHalHandlerForBus HalReferenceHandlerForBus;
  12795. pHalReferenceBusHandler HalReferenceBusHandler;
  12796. pHalReferenceBusHandler HalDereferenceBusHandler;
  12797. pHalInitPnpDriver HalInitPnpDriver;
  12798. pHalInitPowerManagement HalInitPowerManagement;
  12799. pHalGetDmaAdapter HalGetDmaAdapter;
  12800. pHalGetInterruptTranslator HalGetInterruptTranslator;
  12801. pHalStartMirroring HalStartMirroring;
  12802. pHalEndMirroring HalEndMirroring;
  12803. pHalMirrorPhysicalMemory HalMirrorPhysicalMemory;
  12804. pHalEndOfBoot HalEndOfBoot;
  12805. pHalMirrorVerify HalMirrorVerify;
  12806. } HAL_DISPATCH, *PHAL_DISPATCH;
  12807. #if defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_) || defined(_NTHAL_)
  12808. extern PHAL_DISPATCH HalDispatchTable;
  12809. #define HALDISPATCH HalDispatchTable
  12810. #else
  12811. extern HAL_DISPATCH HalDispatchTable;
  12812. #define HALDISPATCH (&HalDispatchTable)
  12813. #endif
  12814. #define HAL_DISPATCH_VERSION 3
  12815. #define HalDispatchTableVersion HALDISPATCH->Version
  12816. #define HalQuerySystemInformation HALDISPATCH->HalQuerySystemInformation
  12817. #define HalSetSystemInformation HALDISPATCH->HalSetSystemInformation
  12818. #define HalQueryBusSlots HALDISPATCH->HalQueryBusSlots
  12819. #define HalReferenceHandlerForBus HALDISPATCH->HalReferenceHandlerForBus
  12820. #define HalReferenceBusHandler HALDISPATCH->HalReferenceBusHandler
  12821. #define HalDereferenceBusHandler HALDISPATCH->HalDereferenceBusHandler
  12822. #define HalInitPnpDriver HALDISPATCH->HalInitPnpDriver
  12823. #define HalInitPowerManagement HALDISPATCH->HalInitPowerManagement
  12824. #define HalGetDmaAdapter HALDISPATCH->HalGetDmaAdapter
  12825. #define HalGetInterruptTranslator HALDISPATCH->HalGetInterruptTranslator
  12826. #define HalStartMirroring HALDISPATCH->HalStartMirroring
  12827. #define HalEndMirroring HALDISPATCH->HalEndMirroring
  12828. #define HalMirrorPhysicalMemory HALDISPATCH->HalMirrorPhysicalMemory
  12829. #define HalEndOfBoot HALDISPATCH->HalEndOfBoot
  12830. #define HalMirrorVerify HALDISPATCH->HalMirrorVerify
  12831. //
  12832. // HAL System Information Structures.
  12833. //
  12834. // for the information class "HalInstalledBusInformation"
  12835. typedef struct _HAL_BUS_INFORMATION{
  12836. INTERFACE_TYPE BusType;
  12837. BUS_DATA_TYPE ConfigurationType;
  12838. ULONG BusNumber;
  12839. ULONG Reserved;
  12840. } HAL_BUS_INFORMATION, *PHAL_BUS_INFORMATION;
  12841. // for the information class "HalProfileSourceInformation"
  12842. typedef struct _HAL_PROFILE_SOURCE_INFORMATION {
  12843. KPROFILE_SOURCE Source;
  12844. BOOLEAN Supported;
  12845. ULONG Interval;
  12846. } HAL_PROFILE_SOURCE_INFORMATION, *PHAL_PROFILE_SOURCE_INFORMATION;
  12847. typedef struct _HAL_PROFILE_SOURCE_INFORMATION_EX {
  12848. KPROFILE_SOURCE Source;
  12849. BOOLEAN Supported;
  12850. ULONG_PTR Interval;
  12851. ULONG_PTR DefInterval;
  12852. ULONG_PTR MaxInterval;
  12853. ULONG_PTR MinInterval;
  12854. } HAL_PROFILE_SOURCE_INFORMATION_EX, *PHAL_PROFILE_SOURCE_INFORMATION_EX;
  12855. // for the information class "HalProfileSourceInterval"
  12856. typedef struct _HAL_PROFILE_SOURCE_INTERVAL {
  12857. KPROFILE_SOURCE Source;
  12858. ULONG_PTR Interval;
  12859. } HAL_PROFILE_SOURCE_INTERVAL, *PHAL_PROFILE_SOURCE_INTERVAL;
  12860. // for the information class "HalDispayBiosInformation"
  12861. typedef enum _HAL_DISPLAY_BIOS_INFORMATION {
  12862. HalDisplayInt10Bios,
  12863. HalDisplayEmulatedBios,
  12864. HalDisplayNoBios
  12865. } HAL_DISPLAY_BIOS_INFORMATION, *PHAL_DISPLAY_BIOS_INFORMATION;
  12866. // for the information class "HalPowerInformation"
  12867. typedef struct _HAL_POWER_INFORMATION {
  12868. ULONG TBD;
  12869. } HAL_POWER_INFORMATION, *PHAL_POWER_INFORMATION;
  12870. // for the information class "HalProcessorSpeedInformation"
  12871. typedef struct _HAL_PROCESSOR_SPEED_INFO {
  12872. ULONG ProcessorSpeed;
  12873. } HAL_PROCESSOR_SPEED_INFORMATION, *PHAL_PROCESSOR_SPEED_INFORMATION;
  12874. // for the information class "HalCallbackInformation"
  12875. typedef struct _HAL_CALLBACKS {
  12876. PCALLBACK_OBJECT SetSystemInformation;
  12877. PCALLBACK_OBJECT BusCheck;
  12878. } HAL_CALLBACKS, *PHAL_CALLBACKS;
  12879. // for the information class "HalProcessorFeatureInformation"
  12880. typedef struct _HAL_PROCESSOR_FEATURE {
  12881. ULONG UsableFeatureBits;
  12882. } HAL_PROCESSOR_FEATURE;
  12883. // for the information class "HalNumaTopologyInterface"
  12884. typedef ULONG HALNUMAPAGETONODE;
  12885. typedef
  12886. HALNUMAPAGETONODE
  12887. (*PHALNUMAPAGETONODE)(
  12888. IN ULONG_PTR PhysicalPageNumber
  12889. );
  12890. typedef
  12891. NTSTATUS
  12892. (*PHALNUMAQUERYPROCESSORNODE)(
  12893. IN ULONG ProcessorNumber,
  12894. OUT PUSHORT Identifier,
  12895. OUT PUCHAR Node
  12896. );
  12897. typedef struct _HAL_NUMA_TOPOLOGY_INTERFACE {
  12898. ULONG NumberOfNodes;
  12899. PHALNUMAQUERYPROCESSORNODE QueryProcessorNode;
  12900. PHALNUMAPAGETONODE PageToNode;
  12901. } HAL_NUMA_TOPOLOGY_INTERFACE;
  12902. typedef
  12903. NTSTATUS
  12904. (*PHALIOREADWRITEHANDLER)(
  12905. IN BOOLEAN fRead,
  12906. IN ULONG dwAddr,
  12907. IN ULONG dwSize,
  12908. IN OUT PULONG pdwData
  12909. );
  12910. // for the information class "HalQueryIllegalIOPortAddresses"
  12911. typedef struct _HAL_AMLI_BAD_IO_ADDRESS_LIST
  12912. {
  12913. ULONG BadAddrBegin;
  12914. ULONG BadAddrSize;
  12915. ULONG OSVersionTrigger;
  12916. PHALIOREADWRITEHANDLER IOHandler;
  12917. } HAL_AMLI_BAD_IO_ADDRESS_LIST, *PHAL_AMLI_BAD_IO_ADDRESS_LIST;
  12918. typedef struct _SCATTER_GATHER_ELEMENT {
  12919. PHYSICAL_ADDRESS Address;
  12920. ULONG Length;
  12921. ULONG_PTR Reserved;
  12922. } SCATTER_GATHER_ELEMENT, *PSCATTER_GATHER_ELEMENT;
  12923. #pragma warning(disable:4200)
  12924. typedef struct _SCATTER_GATHER_LIST {
  12925. ULONG NumberOfElements;
  12926. ULONG_PTR Reserved;
  12927. SCATTER_GATHER_ELEMENT Elements[];
  12928. } SCATTER_GATHER_LIST, *PSCATTER_GATHER_LIST;
  12929. #pragma warning(default:4200)
  12930. // end_ntndis
  12931. typedef struct _DMA_OPERATIONS *PDMA_OPERATIONS;
  12932. typedef struct _DMA_ADAPTER {
  12933. USHORT Version;
  12934. USHORT Size;
  12935. PDMA_OPERATIONS DmaOperations;
  12936. // Private Bus Device Driver data follows,
  12937. } DMA_ADAPTER, *PDMA_ADAPTER;
  12938. typedef VOID (*PPUT_DMA_ADAPTER)(
  12939. PDMA_ADAPTER DmaAdapter
  12940. );
  12941. typedef PVOID (*PALLOCATE_COMMON_BUFFER)(
  12942. IN PDMA_ADAPTER DmaAdapter,
  12943. IN ULONG Length,
  12944. OUT PPHYSICAL_ADDRESS LogicalAddress,
  12945. IN BOOLEAN CacheEnabled
  12946. );
  12947. typedef VOID (*PFREE_COMMON_BUFFER)(
  12948. IN PDMA_ADAPTER DmaAdapter,
  12949. IN ULONG Length,
  12950. IN PHYSICAL_ADDRESS LogicalAddress,
  12951. IN PVOID VirtualAddress,
  12952. IN BOOLEAN CacheEnabled
  12953. );
  12954. typedef NTSTATUS (*PALLOCATE_ADAPTER_CHANNEL)(
  12955. IN PDMA_ADAPTER DmaAdapter,
  12956. IN PDEVICE_OBJECT DeviceObject,
  12957. IN ULONG NumberOfMapRegisters,
  12958. IN PDRIVER_CONTROL ExecutionRoutine,
  12959. IN PVOID Context
  12960. );
  12961. typedef BOOLEAN (*PFLUSH_ADAPTER_BUFFERS)(
  12962. IN PDMA_ADAPTER DmaAdapter,
  12963. IN PMDL Mdl,
  12964. IN PVOID MapRegisterBase,
  12965. IN PVOID CurrentVa,
  12966. IN ULONG Length,
  12967. IN BOOLEAN WriteToDevice
  12968. );
  12969. typedef VOID (*PFREE_ADAPTER_CHANNEL)(
  12970. IN PDMA_ADAPTER DmaAdapter
  12971. );
  12972. typedef VOID (*PFREE_MAP_REGISTERS)(
  12973. IN PDMA_ADAPTER DmaAdapter,
  12974. PVOID MapRegisterBase,
  12975. ULONG NumberOfMapRegisters
  12976. );
  12977. typedef PHYSICAL_ADDRESS (*PMAP_TRANSFER)(
  12978. IN PDMA_ADAPTER DmaAdapter,
  12979. IN PMDL Mdl,
  12980. IN PVOID MapRegisterBase,
  12981. IN PVOID CurrentVa,
  12982. IN OUT PULONG Length,
  12983. IN BOOLEAN WriteToDevice
  12984. );
  12985. typedef ULONG (*PGET_DMA_ALIGNMENT)(
  12986. IN PDMA_ADAPTER DmaAdapter
  12987. );
  12988. typedef ULONG (*PREAD_DMA_COUNTER)(
  12989. IN PDMA_ADAPTER DmaAdapter
  12990. );
  12991. typedef VOID
  12992. (*PDRIVER_LIST_CONTROL)(
  12993. IN struct _DEVICE_OBJECT *DeviceObject,
  12994. IN struct _IRP *Irp,
  12995. IN PSCATTER_GATHER_LIST ScatterGather,
  12996. IN PVOID Context
  12997. );
  12998. typedef NTSTATUS
  12999. (*PGET_SCATTER_GATHER_LIST)(
  13000. IN PDMA_ADAPTER DmaAdapter,
  13001. IN PDEVICE_OBJECT DeviceObject,
  13002. IN PMDL Mdl,
  13003. IN PVOID CurrentVa,
  13004. IN ULONG Length,
  13005. IN PDRIVER_LIST_CONTROL ExecutionRoutine,
  13006. IN PVOID Context,
  13007. IN BOOLEAN WriteToDevice
  13008. );
  13009. typedef VOID
  13010. (*PPUT_SCATTER_GATHER_LIST)(
  13011. IN PDMA_ADAPTER DmaAdapter,
  13012. IN PSCATTER_GATHER_LIST ScatterGather,
  13013. IN BOOLEAN WriteToDevice
  13014. );
  13015. typedef NTSTATUS
  13016. (*PCALCULATE_SCATTER_GATHER_LIST_SIZE)(
  13017. IN PDMA_ADAPTER DmaAdapter,
  13018. IN OPTIONAL PMDL Mdl,
  13019. IN PVOID CurrentVa,
  13020. IN ULONG Length,
  13021. OUT PULONG ScatterGatherListSize,
  13022. OUT OPTIONAL PULONG pNumberOfMapRegisters
  13023. );
  13024. typedef NTSTATUS
  13025. (*PBUILD_SCATTER_GATHER_LIST)(
  13026. IN PDMA_ADAPTER DmaAdapter,
  13027. IN PDEVICE_OBJECT DeviceObject,
  13028. IN PMDL Mdl,
  13029. IN PVOID CurrentVa,
  13030. IN ULONG Length,
  13031. IN PDRIVER_LIST_CONTROL ExecutionRoutine,
  13032. IN PVOID Context,
  13033. IN BOOLEAN WriteToDevice,
  13034. IN PVOID ScatterGatherBuffer,
  13035. IN ULONG ScatterGatherLength
  13036. );
  13037. typedef NTSTATUS
  13038. (*PBUILD_MDL_FROM_SCATTER_GATHER_LIST)(
  13039. IN PDMA_ADAPTER DmaAdapter,
  13040. IN PSCATTER_GATHER_LIST ScatterGather,
  13041. IN PMDL OriginalMdl,
  13042. OUT PMDL *TargetMdl
  13043. );
  13044. typedef struct _DMA_OPERATIONS {
  13045. ULONG Size;
  13046. PPUT_DMA_ADAPTER PutDmaAdapter;
  13047. PALLOCATE_COMMON_BUFFER AllocateCommonBuffer;
  13048. PFREE_COMMON_BUFFER FreeCommonBuffer;
  13049. PALLOCATE_ADAPTER_CHANNEL AllocateAdapterChannel;
  13050. PFLUSH_ADAPTER_BUFFERS FlushAdapterBuffers;
  13051. PFREE_ADAPTER_CHANNEL FreeAdapterChannel;
  13052. PFREE_MAP_REGISTERS FreeMapRegisters;
  13053. PMAP_TRANSFER MapTransfer;
  13054. PGET_DMA_ALIGNMENT GetDmaAlignment;
  13055. PREAD_DMA_COUNTER ReadDmaCounter;
  13056. PGET_SCATTER_GATHER_LIST GetScatterGatherList;
  13057. PPUT_SCATTER_GATHER_LIST PutScatterGatherList;
  13058. PCALCULATE_SCATTER_GATHER_LIST_SIZE CalculateScatterGatherList;
  13059. PBUILD_SCATTER_GATHER_LIST BuildScatterGatherList;
  13060. PBUILD_MDL_FROM_SCATTER_GATHER_LIST BuildMdlFromScatterGatherList;
  13061. } DMA_OPERATIONS;
  13062. // end_wdm
  13063. #if defined(_WIN64)
  13064. //
  13065. // Use __inline DMA macros (hal.h)
  13066. //
  13067. #ifndef USE_DMA_MACROS
  13068. #define USE_DMA_MACROS
  13069. #endif
  13070. //
  13071. // Only PnP drivers!
  13072. //
  13073. #ifndef NO_LEGACY_DRIVERS
  13074. #define NO_LEGACY_DRIVERS
  13075. #endif
  13076. #endif // _WIN64
  13077. #if defined(USE_DMA_MACROS) && (defined(_NTDDK_) || defined(_NTDRIVER_))
  13078. // begin_wdm
  13079. DECLSPEC_DEPRECATED_DDK // Use AllocateCommonBuffer
  13080. FORCEINLINE
  13081. PVOID
  13082. HalAllocateCommonBuffer(
  13083. IN PDMA_ADAPTER DmaAdapter,
  13084. IN ULONG Length,
  13085. OUT PPHYSICAL_ADDRESS LogicalAddress,
  13086. IN BOOLEAN CacheEnabled
  13087. ){
  13088. PALLOCATE_COMMON_BUFFER allocateCommonBuffer;
  13089. PVOID commonBuffer;
  13090. allocateCommonBuffer = *(DmaAdapter)->DmaOperations->AllocateCommonBuffer;
  13091. ASSERT( allocateCommonBuffer != NULL );
  13092. commonBuffer = allocateCommonBuffer( DmaAdapter,
  13093. Length,
  13094. LogicalAddress,
  13095. CacheEnabled );
  13096. return commonBuffer;
  13097. }
  13098. DECLSPEC_DEPRECATED_DDK // Use FreeCommonBuffer
  13099. FORCEINLINE
  13100. VOID
  13101. HalFreeCommonBuffer(
  13102. IN PDMA_ADAPTER DmaAdapter,
  13103. IN ULONG Length,
  13104. IN PHYSICAL_ADDRESS LogicalAddress,
  13105. IN PVOID VirtualAddress,
  13106. IN BOOLEAN CacheEnabled
  13107. ){
  13108. PFREE_COMMON_BUFFER freeCommonBuffer;
  13109. freeCommonBuffer = *(DmaAdapter)->DmaOperations->FreeCommonBuffer;
  13110. ASSERT( freeCommonBuffer != NULL );
  13111. freeCommonBuffer( DmaAdapter,
  13112. Length,
  13113. LogicalAddress,
  13114. VirtualAddress,
  13115. CacheEnabled );
  13116. }
  13117. DECLSPEC_DEPRECATED_DDK // Use AllocateAdapterChannel
  13118. FORCEINLINE
  13119. NTSTATUS
  13120. IoAllocateAdapterChannel(
  13121. IN PDMA_ADAPTER DmaAdapter,
  13122. IN PDEVICE_OBJECT DeviceObject,
  13123. IN ULONG NumberOfMapRegisters,
  13124. IN PDRIVER_CONTROL ExecutionRoutine,
  13125. IN PVOID Context
  13126. ){
  13127. PALLOCATE_ADAPTER_CHANNEL allocateAdapterChannel;
  13128. NTSTATUS status;
  13129. allocateAdapterChannel =
  13130. *(DmaAdapter)->DmaOperations->AllocateAdapterChannel;
  13131. ASSERT( allocateAdapterChannel != NULL );
  13132. status = allocateAdapterChannel( DmaAdapter,
  13133. DeviceObject,
  13134. NumberOfMapRegisters,
  13135. ExecutionRoutine,
  13136. Context );
  13137. return status;
  13138. }
  13139. DECLSPEC_DEPRECATED_DDK // Use FlushAdapterBuffers
  13140. FORCEINLINE
  13141. BOOLEAN
  13142. IoFlushAdapterBuffers(
  13143. IN PDMA_ADAPTER DmaAdapter,
  13144. IN PMDL Mdl,
  13145. IN PVOID MapRegisterBase,
  13146. IN PVOID CurrentVa,
  13147. IN ULONG Length,
  13148. IN BOOLEAN WriteToDevice
  13149. ){
  13150. PFLUSH_ADAPTER_BUFFERS flushAdapterBuffers;
  13151. BOOLEAN result;
  13152. flushAdapterBuffers = *(DmaAdapter)->DmaOperations->FlushAdapterBuffers;
  13153. ASSERT( flushAdapterBuffers != NULL );
  13154. result = flushAdapterBuffers( DmaAdapter,
  13155. Mdl,
  13156. MapRegisterBase,
  13157. CurrentVa,
  13158. Length,
  13159. WriteToDevice );
  13160. return result;
  13161. }
  13162. DECLSPEC_DEPRECATED_DDK // Use FreeAdapterChannel
  13163. FORCEINLINE
  13164. VOID
  13165. IoFreeAdapterChannel(
  13166. IN PDMA_ADAPTER DmaAdapter
  13167. ){
  13168. PFREE_ADAPTER_CHANNEL freeAdapterChannel;
  13169. freeAdapterChannel = *(DmaAdapter)->DmaOperations->FreeAdapterChannel;
  13170. ASSERT( freeAdapterChannel != NULL );
  13171. freeAdapterChannel( DmaAdapter );
  13172. }
  13173. DECLSPEC_DEPRECATED_DDK // Use FreeMapRegisters
  13174. FORCEINLINE
  13175. VOID
  13176. IoFreeMapRegisters(
  13177. IN PDMA_ADAPTER DmaAdapter,
  13178. IN PVOID MapRegisterBase,
  13179. IN ULONG NumberOfMapRegisters
  13180. ){
  13181. PFREE_MAP_REGISTERS freeMapRegisters;
  13182. freeMapRegisters = *(DmaAdapter)->DmaOperations->FreeMapRegisters;
  13183. ASSERT( freeMapRegisters != NULL );
  13184. freeMapRegisters( DmaAdapter,
  13185. MapRegisterBase,
  13186. NumberOfMapRegisters );
  13187. }
  13188. DECLSPEC_DEPRECATED_DDK // Use MapTransfer
  13189. FORCEINLINE
  13190. PHYSICAL_ADDRESS
  13191. IoMapTransfer(
  13192. IN PDMA_ADAPTER DmaAdapter,
  13193. IN PMDL Mdl,
  13194. IN PVOID MapRegisterBase,
  13195. IN PVOID CurrentVa,
  13196. IN OUT PULONG Length,
  13197. IN BOOLEAN WriteToDevice
  13198. ){
  13199. PHYSICAL_ADDRESS physicalAddress;
  13200. PMAP_TRANSFER mapTransfer;
  13201. mapTransfer = *(DmaAdapter)->DmaOperations->MapTransfer;
  13202. ASSERT( mapTransfer != NULL );
  13203. physicalAddress = mapTransfer( DmaAdapter,
  13204. Mdl,
  13205. MapRegisterBase,
  13206. CurrentVa,
  13207. Length,
  13208. WriteToDevice );
  13209. return physicalAddress;
  13210. }
  13211. DECLSPEC_DEPRECATED_DDK // Use GetDmaAlignment
  13212. FORCEINLINE
  13213. ULONG
  13214. HalGetDmaAlignment(
  13215. IN PDMA_ADAPTER DmaAdapter
  13216. )
  13217. {
  13218. PGET_DMA_ALIGNMENT getDmaAlignment;
  13219. ULONG alignment;
  13220. getDmaAlignment = *(DmaAdapter)->DmaOperations->GetDmaAlignment;
  13221. ASSERT( getDmaAlignment != NULL );
  13222. alignment = getDmaAlignment( DmaAdapter );
  13223. return alignment;
  13224. }
  13225. DECLSPEC_DEPRECATED_DDK // Use ReadDmaCounter
  13226. FORCEINLINE
  13227. ULONG
  13228. HalReadDmaCounter(
  13229. IN PDMA_ADAPTER DmaAdapter
  13230. )
  13231. {
  13232. PREAD_DMA_COUNTER readDmaCounter;
  13233. ULONG counter;
  13234. readDmaCounter = *(DmaAdapter)->DmaOperations->ReadDmaCounter;
  13235. ASSERT( readDmaCounter != NULL );
  13236. counter = readDmaCounter( DmaAdapter );
  13237. return counter;
  13238. }
  13239. // end_wdm
  13240. #else
  13241. //
  13242. // DMA adapter object functions.
  13243. //
  13244. NTHALAPI
  13245. NTSTATUS
  13246. HalAllocateAdapterChannel(
  13247. IN PADAPTER_OBJECT AdapterObject,
  13248. IN PWAIT_CONTEXT_BLOCK Wcb,
  13249. IN ULONG NumberOfMapRegisters,
  13250. IN PDRIVER_CONTROL ExecutionRoutine
  13251. );
  13252. DECLSPEC_DEPRECATED_DDK // Use AllocateCommonBuffer
  13253. NTHALAPI
  13254. PVOID
  13255. HalAllocateCommonBuffer(
  13256. IN PADAPTER_OBJECT AdapterObject,
  13257. IN ULONG Length,
  13258. OUT PPHYSICAL_ADDRESS LogicalAddress,
  13259. IN BOOLEAN CacheEnabled
  13260. );
  13261. DECLSPEC_DEPRECATED_DDK // Use FreeCommonBuffer
  13262. NTHALAPI
  13263. VOID
  13264. HalFreeCommonBuffer(
  13265. IN PADAPTER_OBJECT AdapterObject,
  13266. IN ULONG Length,
  13267. IN PHYSICAL_ADDRESS LogicalAddress,
  13268. IN PVOID VirtualAddress,
  13269. IN BOOLEAN CacheEnabled
  13270. );
  13271. DECLSPEC_DEPRECATED_DDK // Use ReadDmaCounter
  13272. NTHALAPI
  13273. ULONG
  13274. HalReadDmaCounter(
  13275. IN PADAPTER_OBJECT AdapterObject
  13276. );
  13277. DECLSPEC_DEPRECATED_DDK // Use FlushAdapterBuffers
  13278. NTHALAPI
  13279. BOOLEAN
  13280. IoFlushAdapterBuffers(
  13281. IN PADAPTER_OBJECT AdapterObject,
  13282. IN PMDL Mdl,
  13283. IN PVOID MapRegisterBase,
  13284. IN PVOID CurrentVa,
  13285. IN ULONG Length,
  13286. IN BOOLEAN WriteToDevice
  13287. );
  13288. DECLSPEC_DEPRECATED_DDK // Use FreeAdapterChannel
  13289. NTHALAPI
  13290. VOID
  13291. IoFreeAdapterChannel(
  13292. IN PADAPTER_OBJECT AdapterObject
  13293. );
  13294. DECLSPEC_DEPRECATED_DDK // Use FreeMapRegisters
  13295. NTHALAPI
  13296. VOID
  13297. IoFreeMapRegisters(
  13298. IN PADAPTER_OBJECT AdapterObject,
  13299. IN PVOID MapRegisterBase,
  13300. IN ULONG NumberOfMapRegisters
  13301. );
  13302. DECLSPEC_DEPRECATED_DDK // Use MapTransfer
  13303. NTHALAPI
  13304. PHYSICAL_ADDRESS
  13305. IoMapTransfer(
  13306. IN PADAPTER_OBJECT AdapterObject,
  13307. IN PMDL Mdl,
  13308. IN PVOID MapRegisterBase,
  13309. IN PVOID CurrentVa,
  13310. IN OUT PULONG Length,
  13311. IN BOOLEAN WriteToDevice
  13312. );
  13313. #endif // USE_DMA_MACROS && (_NTDDK_ || _NTDRIVER_)
  13314. NTSTATUS
  13315. HalGetScatterGatherList (
  13316. IN PADAPTER_OBJECT DmaAdapter,
  13317. IN PDEVICE_OBJECT DeviceObject,
  13318. IN PMDL Mdl,
  13319. IN PVOID CurrentVa,
  13320. IN ULONG Length,
  13321. IN PDRIVER_LIST_CONTROL ExecutionRoutine,
  13322. IN PVOID Context,
  13323. IN BOOLEAN WriteToDevice
  13324. );
  13325. VOID
  13326. HalPutScatterGatherList (
  13327. IN PADAPTER_OBJECT DmaAdapter,
  13328. IN PSCATTER_GATHER_LIST ScatterGather,
  13329. IN BOOLEAN WriteToDevice
  13330. );
  13331. VOID
  13332. HalPutDmaAdapter(
  13333. IN PADAPTER_OBJECT DmaAdapter
  13334. );
  13335. //
  13336. // Define maximum disk transfer size to be used by MM and Cache Manager,
  13337. // so that packet-oriented disk drivers can optimize their packet allocation
  13338. // to this size.
  13339. //
  13340. #define MM_MAXIMUM_DISK_IO_SIZE (0x10000)
  13341. //++
  13342. //
  13343. // ULONG_PTR
  13344. // ROUND_TO_PAGES (
  13345. // IN ULONG_PTR Size
  13346. // )
  13347. //
  13348. // Routine Description:
  13349. //
  13350. // The ROUND_TO_PAGES macro takes a size in bytes and rounds it up to a
  13351. // multiple of the page size.
  13352. //
  13353. // NOTE: This macro fails for values 0xFFFFFFFF - (PAGE_SIZE - 1).
  13354. //
  13355. // Arguments:
  13356. //
  13357. // Size - Size in bytes to round up to a page multiple.
  13358. //
  13359. // Return Value:
  13360. //
  13361. // Returns the size rounded up to a multiple of the page size.
  13362. //
  13363. //--
  13364. #define ROUND_TO_PAGES(Size) (((ULONG_PTR)(Size) + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1))
  13365. //++
  13366. //
  13367. // ULONG
  13368. // BYTES_TO_PAGES (
  13369. // IN ULONG Size
  13370. // )
  13371. //
  13372. // Routine Description:
  13373. //
  13374. // The BYTES_TO_PAGES macro takes the size in bytes and calculates the
  13375. // number of pages required to contain the bytes.
  13376. //
  13377. // Arguments:
  13378. //
  13379. // Size - Size in bytes.
  13380. //
  13381. // Return Value:
  13382. //
  13383. // Returns the number of pages required to contain the specified size.
  13384. //
  13385. //--
  13386. #define BYTES_TO_PAGES(Size) ((ULONG)((ULONG_PTR)(Size) >> PAGE_SHIFT) + \
  13387. (((ULONG)(Size) & (PAGE_SIZE - 1)) != 0))
  13388. //++
  13389. //
  13390. // ULONG
  13391. // BYTE_OFFSET (
  13392. // IN PVOID Va
  13393. // )
  13394. //
  13395. // Routine Description:
  13396. //
  13397. // The BYTE_OFFSET macro takes a virtual address and returns the byte offset
  13398. // of that address within the page.
  13399. //
  13400. // Arguments:
  13401. //
  13402. // Va - Virtual address.
  13403. //
  13404. // Return Value:
  13405. //
  13406. // Returns the byte offset portion of the virtual address.
  13407. //
  13408. //--
  13409. #define BYTE_OFFSET(Va) ((ULONG)((LONG_PTR)(Va) & (PAGE_SIZE - 1)))
  13410. //++
  13411. //
  13412. // PVOID
  13413. // PAGE_ALIGN (
  13414. // IN PVOID Va
  13415. // )
  13416. //
  13417. // Routine Description:
  13418. //
  13419. // The PAGE_ALIGN macro takes a virtual address and returns a page-aligned
  13420. // virtual address for that page.
  13421. //
  13422. // Arguments:
  13423. //
  13424. // Va - Virtual address.
  13425. //
  13426. // Return Value:
  13427. //
  13428. // Returns the page aligned virtual address.
  13429. //
  13430. //--
  13431. #define PAGE_ALIGN(Va) ((PVOID)((ULONG_PTR)(Va) & ~(PAGE_SIZE - 1)))
  13432. //++
  13433. //
  13434. // ULONG
  13435. // ADDRESS_AND_SIZE_TO_SPAN_PAGES (
  13436. // IN PVOID Va,
  13437. // IN ULONG Size
  13438. // )
  13439. //
  13440. // Routine Description:
  13441. //
  13442. // The ADDRESS_AND_SIZE_TO_SPAN_PAGES macro takes a virtual address and
  13443. // size and returns the number of pages spanned by the size.
  13444. //
  13445. // Arguments:
  13446. //
  13447. // Va - Virtual address.
  13448. //
  13449. // Size - Size in bytes.
  13450. //
  13451. // Return Value:
  13452. //
  13453. // Returns the number of pages spanned by the size.
  13454. //
  13455. //--
  13456. #define ADDRESS_AND_SIZE_TO_SPAN_PAGES(Va,Size) \
  13457. ((ULONG)((((ULONG_PTR)(Va) & (PAGE_SIZE -1)) + (Size) + (PAGE_SIZE - 1)) >> PAGE_SHIFT))
  13458. #if PRAGMA_DEPRECATED_DDK
  13459. #pragma deprecated(COMPUTE_PAGES_SPANNED) // Use ADDRESS_AND_SIZE_TO_SPAN_PAGES
  13460. #endif
  13461. #define COMPUTE_PAGES_SPANNED(Va, Size) ADDRESS_AND_SIZE_TO_SPAN_PAGES(Va,Size)
  13462. #define IS_SYSTEM_ADDRESS(VA) ((VA) >= MM_SYSTEM_RANGE_START)
  13463. //++
  13464. // PPFN_NUMBER
  13465. // MmGetMdlPfnArray (
  13466. // IN PMDL Mdl
  13467. // )
  13468. //
  13469. // Routine Description:
  13470. //
  13471. // The MmGetMdlPfnArray routine returns the virtual address of the
  13472. // first element of the array of physical page numbers associated with
  13473. // the MDL.
  13474. //
  13475. // Arguments:
  13476. //
  13477. // Mdl - Pointer to an MDL.
  13478. //
  13479. // Return Value:
  13480. //
  13481. // Returns the virtual address of the first element of the array of
  13482. // physical page numbers associated with the MDL.
  13483. //
  13484. //--
  13485. #define MmGetMdlPfnArray(Mdl) ((PPFN_NUMBER)(Mdl + 1))
  13486. //++
  13487. //
  13488. // PVOID
  13489. // MmGetMdlVirtualAddress (
  13490. // IN PMDL Mdl
  13491. // )
  13492. //
  13493. // Routine Description:
  13494. //
  13495. // The MmGetMdlVirtualAddress returns the virtual address of the buffer
  13496. // described by the Mdl.
  13497. //
  13498. // Arguments:
  13499. //
  13500. // Mdl - Pointer to an MDL.
  13501. //
  13502. // Return Value:
  13503. //
  13504. // Returns the virtual address of the buffer described by the Mdl
  13505. //
  13506. //--
  13507. #define MmGetMdlVirtualAddress(Mdl) \
  13508. ((PVOID) ((PCHAR) ((Mdl)->StartVa) + (Mdl)->ByteOffset))
  13509. //++
  13510. //
  13511. // ULONG
  13512. // MmGetMdlByteCount (
  13513. // IN PMDL Mdl
  13514. // )
  13515. //
  13516. // Routine Description:
  13517. //
  13518. // The MmGetMdlByteCount returns the length in bytes of the buffer
  13519. // described by the Mdl.
  13520. //
  13521. // Arguments:
  13522. //
  13523. // Mdl - Pointer to an MDL.
  13524. //
  13525. // Return Value:
  13526. //
  13527. // Returns the byte count of the buffer described by the Mdl
  13528. //
  13529. //--
  13530. #define MmGetMdlByteCount(Mdl) ((Mdl)->ByteCount)
  13531. //++
  13532. //
  13533. // ULONG
  13534. // MmGetMdlByteOffset (
  13535. // IN PMDL Mdl
  13536. // )
  13537. //
  13538. // Routine Description:
  13539. //
  13540. // The MmGetMdlByteOffset returns the byte offset within the page
  13541. // of the buffer described by the Mdl.
  13542. //
  13543. // Arguments:
  13544. //
  13545. // Mdl - Pointer to an MDL.
  13546. //
  13547. // Return Value:
  13548. //
  13549. // Returns the byte offset within the page of the buffer described by the Mdl
  13550. //
  13551. //--
  13552. #define MmGetMdlByteOffset(Mdl) ((Mdl)->ByteOffset)
  13553. //++
  13554. //
  13555. // PVOID
  13556. // MmGetMdlStartVa (
  13557. // IN PMDL Mdl
  13558. // )
  13559. //
  13560. // Routine Description:
  13561. //
  13562. // The MmGetMdlBaseVa returns the virtual address of the buffer
  13563. // described by the Mdl rounded down to the nearest page.
  13564. //
  13565. // Arguments:
  13566. //
  13567. // Mdl - Pointer to an MDL.
  13568. //
  13569. // Return Value:
  13570. //
  13571. // Returns the returns the starting virtual address of the MDL.
  13572. //
  13573. //
  13574. //--
  13575. #define MmGetMdlBaseVa(Mdl) ((Mdl)->StartVa)
  13576. typedef enum _MM_SYSTEM_SIZE {
  13577. MmSmallSystem,
  13578. MmMediumSystem,
  13579. MmLargeSystem
  13580. } MM_SYSTEMSIZE;
  13581. NTKERNELAPI
  13582. MM_SYSTEMSIZE
  13583. MmQuerySystemSize(
  13584. VOID
  13585. );
  13586. // end_wdm
  13587. NTKERNELAPI
  13588. BOOLEAN
  13589. MmIsThisAnNtAsSystem(
  13590. VOID
  13591. );
  13592. // begin_wdm
  13593. typedef enum _LOCK_OPERATION {
  13594. IoReadAccess,
  13595. IoWriteAccess,
  13596. IoModifyAccess
  13597. } LOCK_OPERATION;
  13598. NTKERNELAPI
  13599. NTSTATUS
  13600. MmGrowKernelStack (
  13601. IN PVOID CurrentStack
  13602. );
  13603. NTKERNELAPI
  13604. NTSTATUS
  13605. MmAdjustWorkingSetSize (
  13606. IN SIZE_T WorkingSetMinimum,
  13607. IN SIZE_T WorkingSetMaximum,
  13608. IN ULONG SystemCache,
  13609. IN BOOLEAN IncreaseOkay
  13610. );
  13611. NTKERNELAPI
  13612. NTSTATUS
  13613. MmCreateSection (
  13614. OUT PVOID *SectionObject,
  13615. IN ACCESS_MASK DesiredAccess,
  13616. IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL,
  13617. IN PLARGE_INTEGER MaximumSize,
  13618. IN ULONG SectionPageProtection,
  13619. IN ULONG AllocationAttributes,
  13620. IN HANDLE FileHandle OPTIONAL,
  13621. IN PFILE_OBJECT File OPTIONAL
  13622. );
  13623. NTKERNELAPI
  13624. NTSTATUS
  13625. MmMapViewOfSection(
  13626. IN PVOID SectionToMap,
  13627. IN PEPROCESS Process,
  13628. IN OUT PVOID *CapturedBase,
  13629. IN ULONG_PTR ZeroBits,
  13630. IN SIZE_T CommitSize,
  13631. IN OUT PLARGE_INTEGER SectionOffset,
  13632. IN OUT PSIZE_T CapturedViewSize,
  13633. IN SECTION_INHERIT InheritDisposition,
  13634. IN ULONG AllocationType,
  13635. IN ULONG Protect
  13636. );
  13637. NTKERNELAPI
  13638. NTSTATUS
  13639. MmUnmapViewOfSection(
  13640. IN PEPROCESS Process,
  13641. IN PVOID BaseAddress
  13642. );
  13643. NTSTATUS
  13644. MmIsVerifierEnabled (
  13645. OUT PULONG VerifierFlags
  13646. );
  13647. NTSTATUS
  13648. MmAddVerifierThunks (
  13649. IN PVOID ThunkBuffer,
  13650. IN ULONG ThunkBufferSize
  13651. );
  13652. NTKERNELAPI
  13653. VOID
  13654. MmProbeAndLockProcessPages (
  13655. IN OUT PMDL MemoryDescriptorList,
  13656. IN PEPROCESS Process,
  13657. IN KPROCESSOR_MODE AccessMode,
  13658. IN LOCK_OPERATION Operation
  13659. );
  13660. // begin_nthal
  13661. //
  13662. // I/O support routines.
  13663. //
  13664. NTKERNELAPI
  13665. VOID
  13666. MmProbeAndLockPages (
  13667. IN OUT PMDL MemoryDescriptorList,
  13668. IN KPROCESSOR_MODE AccessMode,
  13669. IN LOCK_OPERATION Operation
  13670. );
  13671. NTKERNELAPI
  13672. VOID
  13673. MmUnlockPages (
  13674. IN PMDL MemoryDescriptorList
  13675. );
  13676. NTKERNELAPI
  13677. VOID
  13678. MmBuildMdlForNonPagedPool (
  13679. IN OUT PMDL MemoryDescriptorList
  13680. );
  13681. NTKERNELAPI
  13682. PVOID
  13683. MmMapLockedPages (
  13684. IN PMDL MemoryDescriptorList,
  13685. IN KPROCESSOR_MODE AccessMode
  13686. );
  13687. NTKERNELAPI
  13688. PVOID
  13689. MmGetSystemRoutineAddress (
  13690. IN PUNICODE_STRING SystemRoutineName
  13691. );
  13692. NTKERNELAPI
  13693. NTSTATUS
  13694. MmAdvanceMdl (
  13695. IN PMDL Mdl,
  13696. IN ULONG NumberOfBytes
  13697. );
  13698. // end_wdm
  13699. NTKERNELAPI
  13700. NTSTATUS
  13701. MmMapUserAddressesToPage (
  13702. IN PVOID BaseAddress,
  13703. IN SIZE_T NumberOfBytes,
  13704. IN PVOID PageAddress
  13705. );
  13706. // begin_wdm
  13707. NTKERNELAPI
  13708. NTSTATUS
  13709. MmProtectMdlSystemAddress (
  13710. IN PMDL MemoryDescriptorList,
  13711. IN ULONG NewProtect
  13712. );
  13713. //
  13714. // _MM_PAGE_PRIORITY_ provides a method for the system to handle requests
  13715. // intelligently in low resource conditions.
  13716. //
  13717. // LowPagePriority should be used when it is acceptable to the driver for the
  13718. // mapping request to fail if the system is low on resources. An example of
  13719. // this could be for a non-critical network connection where the driver can
  13720. // handle the failure case when system resources are close to being depleted.
  13721. //
  13722. // NormalPagePriority should be used when it is acceptable to the driver for the
  13723. // mapping request to fail if the system is very low on resources. An example
  13724. // of this could be for a non-critical local filesystem request.
  13725. //
  13726. // HighPagePriority should be used when it is unacceptable to the driver for the
  13727. // mapping request to fail unless the system is completely out of resources.
  13728. // An example of this would be the paging file path in a driver.
  13729. //
  13730. // begin_ntndis
  13731. typedef enum _MM_PAGE_PRIORITY {
  13732. LowPagePriority,
  13733. NormalPagePriority = 16,
  13734. HighPagePriority = 32
  13735. } MM_PAGE_PRIORITY;
  13736. // end_ntndis
  13737. //
  13738. // Note: This function is not available in WDM 1.0
  13739. //
  13740. NTKERNELAPI
  13741. PVOID
  13742. MmMapLockedPagesSpecifyCache (
  13743. IN PMDL MemoryDescriptorList,
  13744. IN KPROCESSOR_MODE AccessMode,
  13745. IN MEMORY_CACHING_TYPE CacheType,
  13746. IN PVOID BaseAddress,
  13747. IN ULONG BugCheckOnFailure,
  13748. IN MM_PAGE_PRIORITY Priority
  13749. );
  13750. NTKERNELAPI
  13751. VOID
  13752. MmUnmapLockedPages (
  13753. IN PVOID BaseAddress,
  13754. IN PMDL MemoryDescriptorList
  13755. );
  13756. PVOID
  13757. MmAllocateMappingAddress (
  13758. IN SIZE_T NumberOfBytes,
  13759. IN ULONG PoolTag
  13760. );
  13761. VOID
  13762. MmFreeMappingAddress (
  13763. IN PVOID BaseAddress,
  13764. IN ULONG PoolTag
  13765. );
  13766. PVOID
  13767. MmMapLockedPagesWithReservedMapping (
  13768. IN PVOID MappingAddress,
  13769. IN ULONG PoolTag,
  13770. IN PMDL MemoryDescriptorList,
  13771. IN MEMORY_CACHING_TYPE CacheType
  13772. );
  13773. VOID
  13774. MmUnmapReservedMapping (
  13775. IN PVOID BaseAddress,
  13776. IN ULONG PoolTag,
  13777. IN PMDL MemoryDescriptorList
  13778. );
  13779. // end_wdm
  13780. typedef struct _PHYSICAL_MEMORY_RANGE {
  13781. PHYSICAL_ADDRESS BaseAddress;
  13782. LARGE_INTEGER NumberOfBytes;
  13783. } PHYSICAL_MEMORY_RANGE, *PPHYSICAL_MEMORY_RANGE;
  13784. NTKERNELAPI
  13785. NTSTATUS
  13786. MmAddPhysicalMemory (
  13787. IN PPHYSICAL_ADDRESS StartAddress,
  13788. IN OUT PLARGE_INTEGER NumberOfBytes
  13789. );
  13790. NTKERNELAPI
  13791. NTSTATUS
  13792. MmAddPhysicalMemoryEx (
  13793. IN PPHYSICAL_ADDRESS StartAddress,
  13794. IN OUT PLARGE_INTEGER NumberOfBytes,
  13795. IN ULONG Flags
  13796. );
  13797. NTKERNELAPI
  13798. NTSTATUS
  13799. MmRemovePhysicalMemory (
  13800. IN PPHYSICAL_ADDRESS StartAddress,
  13801. IN OUT PLARGE_INTEGER NumberOfBytes
  13802. );
  13803. NTKERNELAPI
  13804. NTSTATUS
  13805. MmRemovePhysicalMemoryEx (
  13806. IN PPHYSICAL_ADDRESS StartAddress,
  13807. IN OUT PLARGE_INTEGER NumberOfBytes,
  13808. IN ULONG Flags
  13809. );
  13810. NTKERNELAPI
  13811. PPHYSICAL_MEMORY_RANGE
  13812. MmGetPhysicalMemoryRanges (
  13813. VOID
  13814. );
  13815. NTSTATUS
  13816. MmMarkPhysicalMemoryAsGood (
  13817. IN PPHYSICAL_ADDRESS StartAddress,
  13818. IN OUT PLARGE_INTEGER NumberOfBytes
  13819. );
  13820. NTSTATUS
  13821. MmMarkPhysicalMemoryAsBad (
  13822. IN PPHYSICAL_ADDRESS StartAddress,
  13823. IN OUT PLARGE_INTEGER NumberOfBytes
  13824. );
  13825. // begin_wdm
  13826. NTKERNELAPI
  13827. PMDL
  13828. MmAllocatePagesForMdl (
  13829. IN PHYSICAL_ADDRESS LowAddress,
  13830. IN PHYSICAL_ADDRESS HighAddress,
  13831. IN PHYSICAL_ADDRESS SkipBytes,
  13832. IN SIZE_T TotalBytes
  13833. );
  13834. NTKERNELAPI
  13835. VOID
  13836. MmFreePagesFromMdl (
  13837. IN PMDL MemoryDescriptorList
  13838. );
  13839. NTKERNELAPI
  13840. PVOID
  13841. MmMapIoSpace (
  13842. IN PHYSICAL_ADDRESS PhysicalAddress,
  13843. IN SIZE_T NumberOfBytes,
  13844. IN MEMORY_CACHING_TYPE CacheType
  13845. );
  13846. NTKERNELAPI
  13847. VOID
  13848. MmUnmapIoSpace (
  13849. IN PVOID BaseAddress,
  13850. IN SIZE_T NumberOfBytes
  13851. );
  13852. NTKERNELAPI
  13853. PVOID
  13854. MmMapVideoDisplay (
  13855. IN PHYSICAL_ADDRESS PhysicalAddress,
  13856. IN SIZE_T NumberOfBytes,
  13857. IN MEMORY_CACHING_TYPE CacheType
  13858. );
  13859. NTKERNELAPI
  13860. VOID
  13861. MmUnmapVideoDisplay (
  13862. IN PVOID BaseAddress,
  13863. IN SIZE_T NumberOfBytes
  13864. );
  13865. NTKERNELAPI
  13866. PHYSICAL_ADDRESS
  13867. MmGetPhysicalAddress (
  13868. IN PVOID BaseAddress
  13869. );
  13870. NTKERNELAPI
  13871. PVOID
  13872. MmGetVirtualForPhysical (
  13873. IN PHYSICAL_ADDRESS PhysicalAddress
  13874. );
  13875. NTKERNELAPI
  13876. PVOID
  13877. MmAllocateContiguousMemory (
  13878. IN SIZE_T NumberOfBytes,
  13879. IN PHYSICAL_ADDRESS HighestAcceptableAddress
  13880. );
  13881. NTKERNELAPI
  13882. PVOID
  13883. MmAllocateContiguousMemorySpecifyCache (
  13884. IN SIZE_T NumberOfBytes,
  13885. IN PHYSICAL_ADDRESS LowestAcceptableAddress,
  13886. IN PHYSICAL_ADDRESS HighestAcceptableAddress,
  13887. IN PHYSICAL_ADDRESS BoundaryAddressMultiple OPTIONAL,
  13888. IN MEMORY_CACHING_TYPE CacheType
  13889. );
  13890. NTKERNELAPI
  13891. VOID
  13892. MmFreeContiguousMemory (
  13893. IN PVOID BaseAddress
  13894. );
  13895. NTKERNELAPI
  13896. VOID
  13897. MmFreeContiguousMemorySpecifyCache (
  13898. IN PVOID BaseAddress,
  13899. IN SIZE_T NumberOfBytes,
  13900. IN MEMORY_CACHING_TYPE CacheType
  13901. );
  13902. NTKERNELAPI
  13903. PVOID
  13904. MmAllocateNonCachedMemory (
  13905. IN SIZE_T NumberOfBytes
  13906. );
  13907. NTKERNELAPI
  13908. VOID
  13909. MmFreeNonCachedMemory (
  13910. IN PVOID BaseAddress,
  13911. IN SIZE_T NumberOfBytes
  13912. );
  13913. NTKERNELAPI
  13914. BOOLEAN
  13915. MmIsAddressValid (
  13916. IN PVOID VirtualAddress
  13917. );
  13918. DECLSPEC_DEPRECATED_DDK
  13919. NTKERNELAPI
  13920. BOOLEAN
  13921. MmIsNonPagedSystemAddressValid (
  13922. IN PVOID VirtualAddress
  13923. );
  13924. // begin_wdm
  13925. NTKERNELAPI
  13926. SIZE_T
  13927. MmSizeOfMdl(
  13928. IN PVOID Base,
  13929. IN SIZE_T Length
  13930. );
  13931. DECLSPEC_DEPRECATED_DDK // Use IoCreateMdl
  13932. NTKERNELAPI
  13933. PMDL
  13934. MmCreateMdl(
  13935. IN PMDL MemoryDescriptorList OPTIONAL,
  13936. IN PVOID Base,
  13937. IN SIZE_T Length
  13938. );
  13939. NTKERNELAPI
  13940. PVOID
  13941. MmLockPagableDataSection(
  13942. IN PVOID AddressWithinSection
  13943. );
  13944. // end_wdm
  13945. NTKERNELAPI
  13946. VOID
  13947. MmLockPagableSectionByHandle (
  13948. IN PVOID ImageSectionHandle
  13949. );
  13950. NTKERNELAPI
  13951. VOID
  13952. MmResetDriverPaging (
  13953. IN PVOID AddressWithinSection
  13954. );
  13955. NTKERNELAPI
  13956. PVOID
  13957. MmPageEntireDriver (
  13958. IN PVOID AddressWithinSection
  13959. );
  13960. NTKERNELAPI
  13961. VOID
  13962. MmUnlockPagableImageSection(
  13963. IN PVOID ImageSectionHandle
  13964. );
  13965. NTKERNELAPI
  13966. HANDLE
  13967. MmSecureVirtualMemory (
  13968. IN PVOID Address,
  13969. IN SIZE_T Size,
  13970. IN ULONG ProbeMode
  13971. );
  13972. NTKERNELAPI
  13973. VOID
  13974. MmUnsecureVirtualMemory (
  13975. IN HANDLE SecureHandle
  13976. );
  13977. NTKERNELAPI
  13978. NTSTATUS
  13979. MmMapViewInSessionSpace (
  13980. IN PVOID Section,
  13981. OUT PVOID *MappedBase,
  13982. IN OUT PSIZE_T ViewSize
  13983. );
  13984. NTKERNELAPI
  13985. NTSTATUS
  13986. MmUnmapViewInSessionSpace (
  13987. IN PVOID MappedBase
  13988. );
  13989. //++
  13990. //
  13991. // VOID
  13992. // MmInitializeMdl (
  13993. // IN PMDL MemoryDescriptorList,
  13994. // IN PVOID BaseVa,
  13995. // IN SIZE_T Length
  13996. // )
  13997. //
  13998. // Routine Description:
  13999. //
  14000. // This routine initializes the header of a Memory Descriptor List (MDL).
  14001. //
  14002. // Arguments:
  14003. //
  14004. // MemoryDescriptorList - Pointer to the MDL to initialize.
  14005. //
  14006. // BaseVa - Base virtual address mapped by the MDL.
  14007. //
  14008. // Length - Length, in bytes, of the buffer mapped by the MDL.
  14009. //
  14010. // Return Value:
  14011. //
  14012. // None.
  14013. //
  14014. //--
  14015. #define MmInitializeMdl(MemoryDescriptorList, BaseVa, Length) { \
  14016. (MemoryDescriptorList)->Next = (PMDL) NULL; \
  14017. (MemoryDescriptorList)->Size = (CSHORT)(sizeof(MDL) + \
  14018. (sizeof(PFN_NUMBER) * ADDRESS_AND_SIZE_TO_SPAN_PAGES((BaseVa), (Length)))); \
  14019. (MemoryDescriptorList)->MdlFlags = 0; \
  14020. (MemoryDescriptorList)->StartVa = (PVOID) PAGE_ALIGN((BaseVa)); \
  14021. (MemoryDescriptorList)->ByteOffset = BYTE_OFFSET((BaseVa)); \
  14022. (MemoryDescriptorList)->ByteCount = (ULONG)(Length); \
  14023. }
  14024. //++
  14025. //
  14026. // PVOID
  14027. // MmGetSystemAddressForMdlSafe (
  14028. // IN PMDL MDL,
  14029. // IN MM_PAGE_PRIORITY PRIORITY
  14030. // )
  14031. //
  14032. // Routine Description:
  14033. //
  14034. // This routine returns the mapped address of an MDL. If the
  14035. // Mdl is not already mapped or a system address, it is mapped.
  14036. //
  14037. // Arguments:
  14038. //
  14039. // MemoryDescriptorList - Pointer to the MDL to map.
  14040. //
  14041. // Priority - Supplies an indication as to how important it is that this
  14042. // request succeed under low available PTE conditions.
  14043. //
  14044. // Return Value:
  14045. //
  14046. // Returns the base address where the pages are mapped. The base address
  14047. // has the same offset as the virtual address in the MDL.
  14048. //
  14049. // Unlike MmGetSystemAddressForMdl, Safe guarantees that it will always
  14050. // return NULL on failure instead of bugchecking the system.
  14051. //
  14052. // This macro is not usable by WDM 1.0 drivers as 1.0 did not include
  14053. // MmMapLockedPagesSpecifyCache. The solution for WDM 1.0 drivers is to
  14054. // provide synchronization and set/reset the MDL_MAPPING_CAN_FAIL bit.
  14055. //
  14056. //--
  14057. #define MmGetSystemAddressForMdlSafe(MDL, PRIORITY) \
  14058. (((MDL)->MdlFlags & (MDL_MAPPED_TO_SYSTEM_VA | \
  14059. MDL_SOURCE_IS_NONPAGED_POOL)) ? \
  14060. ((MDL)->MappedSystemVa) : \
  14061. (MmMapLockedPagesSpecifyCache((MDL), \
  14062. KernelMode, \
  14063. MmCached, \
  14064. NULL, \
  14065. FALSE, \
  14066. (PRIORITY))))
  14067. //++
  14068. //
  14069. // PVOID
  14070. // MmGetSystemAddressForMdl (
  14071. // IN PMDL MDL
  14072. // )
  14073. //
  14074. // Routine Description:
  14075. //
  14076. // This routine returns the mapped address of an MDL, if the
  14077. // Mdl is not already mapped or a system address, it is mapped.
  14078. //
  14079. // Arguments:
  14080. //
  14081. // MemoryDescriptorList - Pointer to the MDL to map.
  14082. //
  14083. // Return Value:
  14084. //
  14085. // Returns the base address where the pages are mapped. The base address
  14086. // has the same offset as the virtual address in the MDL.
  14087. //
  14088. //--
  14089. //#define MmGetSystemAddressForMdl(MDL)
  14090. // (((MDL)->MdlFlags & (MDL_MAPPED_TO_SYSTEM_VA)) ?
  14091. // ((MDL)->MappedSystemVa) :
  14092. // ((((MDL)->MdlFlags & (MDL_SOURCE_IS_NONPAGED_POOL)) ?
  14093. // ((PVOID)((ULONG)(MDL)->StartVa | (MDL)->ByteOffset)) :
  14094. // (MmMapLockedPages((MDL),KernelMode)))))
  14095. #if PRAGMA_DEPRECATED_DDK
  14096. #pragma deprecated(MmGetSystemAddressForMdl) // Use MmGetSystemAddressForMdlSafe
  14097. #endif
  14098. #define MmGetSystemAddressForMdl(MDL) \
  14099. (((MDL)->MdlFlags & (MDL_MAPPED_TO_SYSTEM_VA | \
  14100. MDL_SOURCE_IS_NONPAGED_POOL)) ? \
  14101. ((MDL)->MappedSystemVa) : \
  14102. (MmMapLockedPages((MDL),KernelMode)))
  14103. //++
  14104. //
  14105. // VOID
  14106. // MmPrepareMdlForReuse (
  14107. // IN PMDL MDL
  14108. // )
  14109. //
  14110. // Routine Description:
  14111. //
  14112. // This routine will take all of the steps necessary to allow an MDL to be
  14113. // re-used.
  14114. //
  14115. // Arguments:
  14116. //
  14117. // MemoryDescriptorList - Pointer to the MDL that will be re-used.
  14118. //
  14119. // Return Value:
  14120. //
  14121. // None.
  14122. //
  14123. //--
  14124. #define MmPrepareMdlForReuse(MDL) \
  14125. if (((MDL)->MdlFlags & MDL_PARTIAL_HAS_BEEN_MAPPED) != 0) { \
  14126. ASSERT(((MDL)->MdlFlags & MDL_PARTIAL) != 0); \
  14127. MmUnmapLockedPages( (MDL)->MappedSystemVa, (MDL) ); \
  14128. } else if (((MDL)->MdlFlags & MDL_PARTIAL) == 0) { \
  14129. ASSERT(((MDL)->MdlFlags & MDL_MAPPED_TO_SYSTEM_VA) == 0); \
  14130. }
  14131. typedef NTSTATUS (*PMM_DLL_INITIALIZE)(
  14132. IN PUNICODE_STRING RegistryPath
  14133. );
  14134. typedef NTSTATUS (*PMM_DLL_UNLOAD)(
  14135. VOID
  14136. );
  14137. //
  14138. // Define an empty typedef for the _DRIVER_OBJECT structure so it may be
  14139. // referenced by function types before it is actually defined.
  14140. //
  14141. struct _DRIVER_OBJECT;
  14142. NTKERNELAPI
  14143. LOGICAL
  14144. MmIsDriverVerifying (
  14145. IN struct _DRIVER_OBJECT *DriverObject
  14146. );
  14147. VOID
  14148. MmMapMemoryDumpMdl(
  14149. IN OUT PMDL MemoryDumpMdl
  14150. );
  14151. // begin_ntminiport
  14152. //
  14153. // Graphics support routines.
  14154. //
  14155. typedef
  14156. VOID
  14157. (*PBANKED_SECTION_ROUTINE) (
  14158. IN ULONG ReadBank,
  14159. IN ULONG WriteBank,
  14160. IN PVOID Context
  14161. );
  14162. // end_ntminiport
  14163. NTSTATUS
  14164. MmSetBankedSection (
  14165. IN HANDLE ProcessHandle,
  14166. IN PVOID VirtualAddress,
  14167. IN ULONG BankLength,
  14168. IN BOOLEAN ReadWriteBank,
  14169. IN PBANKED_SECTION_ROUTINE BankRoutine,
  14170. IN PVOID Context);
  14171. //
  14172. // Security operation codes
  14173. //
  14174. typedef enum _SECURITY_OPERATION_CODE {
  14175. SetSecurityDescriptor,
  14176. QuerySecurityDescriptor,
  14177. DeleteSecurityDescriptor,
  14178. AssignSecurityDescriptor
  14179. } SECURITY_OPERATION_CODE, *PSECURITY_OPERATION_CODE;
  14180. //
  14181. // Data structure used to capture subject security context
  14182. // for access validations and auditing.
  14183. //
  14184. // THE FIELDS OF THIS DATA STRUCTURE SHOULD BE CONSIDERED OPAQUE
  14185. // BY ALL EXCEPT THE SECURITY ROUTINES.
  14186. //
  14187. typedef struct _SECURITY_SUBJECT_CONTEXT {
  14188. PACCESS_TOKEN ClientToken;
  14189. SECURITY_IMPERSONATION_LEVEL ImpersonationLevel;
  14190. PACCESS_TOKEN PrimaryToken;
  14191. PVOID ProcessAuditId;
  14192. } SECURITY_SUBJECT_CONTEXT, *PSECURITY_SUBJECT_CONTEXT;
  14193. ///////////////////////////////////////////////////////////////////////////////
  14194. // //
  14195. // ACCESS_STATE and related structures //
  14196. // //
  14197. ///////////////////////////////////////////////////////////////////////////////
  14198. //
  14199. // Initial Privilege Set - Room for three privileges, which should
  14200. // be enough for most applications. This structure exists so that
  14201. // it can be imbedded in an ACCESS_STATE structure. Use PRIVILEGE_SET
  14202. // for all other references to Privilege sets.
  14203. //
  14204. #define INITIAL_PRIVILEGE_COUNT 3
  14205. typedef struct _INITIAL_PRIVILEGE_SET {
  14206. ULONG PrivilegeCount;
  14207. ULONG Control;
  14208. LUID_AND_ATTRIBUTES Privilege[INITIAL_PRIVILEGE_COUNT];
  14209. } INITIAL_PRIVILEGE_SET, * PINITIAL_PRIVILEGE_SET;
  14210. //
  14211. // Combine the information that describes the state
  14212. // of an access-in-progress into a single structure
  14213. //
  14214. typedef struct _ACCESS_STATE {
  14215. LUID OperationID;
  14216. BOOLEAN SecurityEvaluated;
  14217. BOOLEAN GenerateAudit;
  14218. BOOLEAN GenerateOnClose;
  14219. BOOLEAN PrivilegesAllocated;
  14220. ULONG Flags;
  14221. ACCESS_MASK RemainingDesiredAccess;
  14222. ACCESS_MASK PreviouslyGrantedAccess;
  14223. ACCESS_MASK OriginalDesiredAccess;
  14224. SECURITY_SUBJECT_CONTEXT SubjectSecurityContext;
  14225. PSECURITY_DESCRIPTOR SecurityDescriptor;
  14226. PVOID AuxData;
  14227. union {
  14228. INITIAL_PRIVILEGE_SET InitialPrivilegeSet;
  14229. PRIVILEGE_SET PrivilegeSet;
  14230. } Privileges;
  14231. BOOLEAN AuditPrivileges;
  14232. UNICODE_STRING ObjectName;
  14233. UNICODE_STRING ObjectTypeName;
  14234. } ACCESS_STATE, *PACCESS_STATE;
  14235. typedef struct _AUX_ACCESS_DATA {
  14236. PPRIVILEGE_SET PrivilegesUsed;
  14237. GENERIC_MAPPING GenericMapping;
  14238. ACCESS_MASK AccessesToAudit;
  14239. ACCESS_MASK MaximumAuditMask;
  14240. } AUX_ACCESS_DATA, *PAUX_ACCESS_DATA;
  14241. typedef struct _SE_EXPORTS {
  14242. //
  14243. // Privilege values
  14244. //
  14245. LUID SeCreateTokenPrivilege;
  14246. LUID SeAssignPrimaryTokenPrivilege;
  14247. LUID SeLockMemoryPrivilege;
  14248. LUID SeIncreaseQuotaPrivilege;
  14249. LUID SeUnsolicitedInputPrivilege;
  14250. LUID SeTcbPrivilege;
  14251. LUID SeSecurityPrivilege;
  14252. LUID SeTakeOwnershipPrivilege;
  14253. LUID SeLoadDriverPrivilege;
  14254. LUID SeCreatePagefilePrivilege;
  14255. LUID SeIncreaseBasePriorityPrivilege;
  14256. LUID SeSystemProfilePrivilege;
  14257. LUID SeSystemtimePrivilege;
  14258. LUID SeProfileSingleProcessPrivilege;
  14259. LUID SeCreatePermanentPrivilege;
  14260. LUID SeBackupPrivilege;
  14261. LUID SeRestorePrivilege;
  14262. LUID SeShutdownPrivilege;
  14263. LUID SeDebugPrivilege;
  14264. LUID SeAuditPrivilege;
  14265. LUID SeSystemEnvironmentPrivilege;
  14266. LUID SeChangeNotifyPrivilege;
  14267. LUID SeRemoteShutdownPrivilege;
  14268. //
  14269. // Universally defined Sids
  14270. //
  14271. PSID SeNullSid;
  14272. PSID SeWorldSid;
  14273. PSID SeLocalSid;
  14274. PSID SeCreatorOwnerSid;
  14275. PSID SeCreatorGroupSid;
  14276. //
  14277. // Nt defined Sids
  14278. //
  14279. PSID SeNtAuthoritySid;
  14280. PSID SeDialupSid;
  14281. PSID SeNetworkSid;
  14282. PSID SeBatchSid;
  14283. PSID SeInteractiveSid;
  14284. PSID SeLocalSystemSid;
  14285. PSID SeAliasAdminsSid;
  14286. PSID SeAliasUsersSid;
  14287. PSID SeAliasGuestsSid;
  14288. PSID SeAliasPowerUsersSid;
  14289. PSID SeAliasAccountOpsSid;
  14290. PSID SeAliasSystemOpsSid;
  14291. PSID SeAliasPrintOpsSid;
  14292. PSID SeAliasBackupOpsSid;
  14293. //
  14294. // New Sids defined for NT5
  14295. //
  14296. PSID SeAuthenticatedUsersSid;
  14297. PSID SeRestrictedSid;
  14298. PSID SeAnonymousLogonSid;
  14299. //
  14300. // New Privileges defined for NT5
  14301. //
  14302. LUID SeUndockPrivilege;
  14303. LUID SeSyncAgentPrivilege;
  14304. LUID SeEnableDelegationPrivilege;
  14305. //
  14306. // New Sids defined for post-Windows 2000
  14307. PSID SeLocalServiceSid;
  14308. PSID SeNetworkServiceSid;
  14309. //
  14310. // New Privileges defined for post-Windows 2000
  14311. //
  14312. LUID SeManageVolumePrivilege;
  14313. } SE_EXPORTS, *PSE_EXPORTS;
  14314. #define SeDeleteClientSecurity(C) { \
  14315. if (SeTokenType((C)->ClientToken) == TokenPrimary) { \
  14316. PsDereferencePrimaryToken( (C)->ClientToken ); \
  14317. } else { \
  14318. PsDereferenceImpersonationToken( (C)->ClientToken ); \
  14319. } \
  14320. }
  14321. // end_ntifs
  14322. //++
  14323. //VOID
  14324. //SeStopImpersonatingClient()
  14325. //
  14326. ///*++
  14327. //
  14328. //Routine Description:
  14329. //
  14330. // This service is used to stop impersonating a client using an
  14331. // impersonation token. This service must be called in the context
  14332. // of the server thread which wishes to stop impersonating its
  14333. // client.
  14334. //
  14335. //
  14336. //Arguments:
  14337. //
  14338. // None.
  14339. //
  14340. //Return Value:
  14341. //
  14342. // None.
  14343. //
  14344. //--*/
  14345. //--
  14346. #define SeStopImpersonatingClient() PsRevertToSelf()
  14347. NTKERNELAPI
  14348. NTSTATUS
  14349. SeCaptureSecurityDescriptor (
  14350. IN PSECURITY_DESCRIPTOR InputSecurityDescriptor,
  14351. IN KPROCESSOR_MODE RequestorMode,
  14352. IN POOL_TYPE PoolType,
  14353. IN BOOLEAN ForceCapture,
  14354. OUT PSECURITY_DESCRIPTOR *OutputSecurityDescriptor
  14355. );
  14356. NTKERNELAPI
  14357. VOID
  14358. SeReleaseSecurityDescriptor (
  14359. IN PSECURITY_DESCRIPTOR CapturedSecurityDescriptor,
  14360. IN KPROCESSOR_MODE RequestorMode,
  14361. IN BOOLEAN ForceCapture
  14362. );
  14363. // begin_ntifs
  14364. NTKERNELAPI
  14365. VOID
  14366. SeCaptureSubjectContext (
  14367. OUT PSECURITY_SUBJECT_CONTEXT SubjectContext
  14368. );
  14369. NTKERNELAPI
  14370. VOID
  14371. SeLockSubjectContext(
  14372. IN PSECURITY_SUBJECT_CONTEXT SubjectContext
  14373. );
  14374. NTKERNELAPI
  14375. VOID
  14376. SeUnlockSubjectContext(
  14377. IN PSECURITY_SUBJECT_CONTEXT SubjectContext
  14378. );
  14379. NTKERNELAPI
  14380. VOID
  14381. SeReleaseSubjectContext (
  14382. IN PSECURITY_SUBJECT_CONTEXT SubjectContext
  14383. );
  14384. NTKERNELAPI
  14385. NTSTATUS
  14386. SeAssignSecurity (
  14387. IN PSECURITY_DESCRIPTOR ParentDescriptor OPTIONAL,
  14388. IN PSECURITY_DESCRIPTOR ExplicitDescriptor,
  14389. OUT PSECURITY_DESCRIPTOR *NewDescriptor,
  14390. IN BOOLEAN IsDirectoryObject,
  14391. IN PSECURITY_SUBJECT_CONTEXT SubjectContext,
  14392. IN PGENERIC_MAPPING GenericMapping,
  14393. IN POOL_TYPE PoolType
  14394. );
  14395. NTKERNELAPI
  14396. NTSTATUS
  14397. SeAssignSecurityEx (
  14398. IN PSECURITY_DESCRIPTOR ParentDescriptor OPTIONAL,
  14399. IN PSECURITY_DESCRIPTOR ExplicitDescriptor OPTIONAL,
  14400. OUT PSECURITY_DESCRIPTOR *NewDescriptor,
  14401. IN GUID *ObjectType OPTIONAL,
  14402. IN BOOLEAN IsDirectoryObject,
  14403. IN ULONG AutoInheritFlags,
  14404. IN PSECURITY_SUBJECT_CONTEXT SubjectContext,
  14405. IN PGENERIC_MAPPING GenericMapping,
  14406. IN POOL_TYPE PoolType
  14407. );
  14408. NTKERNELAPI
  14409. NTSTATUS
  14410. SeDeassignSecurity (
  14411. IN OUT PSECURITY_DESCRIPTOR *SecurityDescriptor
  14412. );
  14413. NTKERNELAPI
  14414. BOOLEAN
  14415. SeAccessCheck (
  14416. IN PSECURITY_DESCRIPTOR SecurityDescriptor,
  14417. IN PSECURITY_SUBJECT_CONTEXT SubjectSecurityContext,
  14418. IN BOOLEAN SubjectContextLocked,
  14419. IN ACCESS_MASK DesiredAccess,
  14420. IN ACCESS_MASK PreviouslyGrantedAccess,
  14421. OUT PPRIVILEGE_SET *Privileges OPTIONAL,
  14422. IN PGENERIC_MAPPING GenericMapping,
  14423. IN KPROCESSOR_MODE AccessMode,
  14424. OUT PACCESS_MASK GrantedAccess,
  14425. OUT PNTSTATUS AccessStatus
  14426. );
  14427. #ifdef SE_NTFS_WORLD_CACHE
  14428. VOID
  14429. SeGetWorldRights (
  14430. IN PSECURITY_DESCRIPTOR SecurityDescriptor,
  14431. IN PGENERIC_MAPPING GenericMapping,
  14432. OUT PACCESS_MASK GrantedAccess
  14433. );
  14434. #endif
  14435. NTKERNELAPI
  14436. BOOLEAN
  14437. SePrivilegeCheck(
  14438. IN OUT PPRIVILEGE_SET RequiredPrivileges,
  14439. IN PSECURITY_SUBJECT_CONTEXT SubjectSecurityContext,
  14440. IN KPROCESSOR_MODE AccessMode
  14441. );
  14442. NTKERNELAPI
  14443. VOID
  14444. SeFreePrivileges(
  14445. IN PPRIVILEGE_SET Privileges
  14446. );
  14447. NTKERNELAPI
  14448. VOID
  14449. SePrivilegeObjectAuditAlarm(
  14450. IN HANDLE Handle,
  14451. IN PSECURITY_SUBJECT_CONTEXT SubjectSecurityContext,
  14452. IN ACCESS_MASK DesiredAccess,
  14453. IN PPRIVILEGE_SET Privileges,
  14454. IN BOOLEAN AccessGranted,
  14455. IN KPROCESSOR_MODE AccessMode
  14456. );
  14457. NTKERNELAPI // ntifs
  14458. TOKEN_TYPE // ntifs
  14459. SeTokenType( // ntifs
  14460. IN PACCESS_TOKEN Token // ntifs
  14461. ); // ntifs
  14462. SECURITY_IMPERSONATION_LEVEL
  14463. SeTokenImpersonationLevel(
  14464. IN PACCESS_TOKEN Token
  14465. );
  14466. NTKERNELAPI // ntifs
  14467. BOOLEAN // ntifs
  14468. SeTokenIsAdmin( // ntifs
  14469. IN PACCESS_TOKEN Token // ntifs
  14470. ); // ntifs
  14471. NTKERNELAPI // ntifs
  14472. BOOLEAN // ntifs
  14473. SeTokenIsRestricted( // ntifs
  14474. IN PACCESS_TOKEN Token // ntifs
  14475. ); // ntifs
  14476. NTKERNELAPI
  14477. NTSTATUS
  14478. SeQueryAuthenticationIdToken(
  14479. IN PACCESS_TOKEN Token,
  14480. OUT PLUID AuthenticationId
  14481. );
  14482. NTKERNELAPI
  14483. NTSTATUS
  14484. SeCreateClientSecurity (
  14485. IN PETHREAD ClientThread,
  14486. IN PSECURITY_QUALITY_OF_SERVICE ClientSecurityQos,
  14487. IN BOOLEAN RemoteSession,
  14488. OUT PSECURITY_CLIENT_CONTEXT ClientContext
  14489. );
  14490. NTKERNELAPI
  14491. NTSTATUS
  14492. SeImpersonateClientEx(
  14493. IN PSECURITY_CLIENT_CONTEXT ClientContext,
  14494. IN PETHREAD ServerThread OPTIONAL
  14495. );
  14496. NTKERNELAPI
  14497. NTSTATUS
  14498. SeCreateAccessState(
  14499. IN PACCESS_STATE AccessState,
  14500. IN PAUX_ACCESS_DATA AuxData,
  14501. IN ACCESS_MASK DesiredAccess,
  14502. IN PGENERIC_MAPPING GenericMapping
  14503. );
  14504. NTKERNELAPI
  14505. VOID
  14506. SeDeleteAccessState(
  14507. IN PACCESS_STATE AccessState
  14508. );
  14509. NTKERNELAPI
  14510. NTSTATUS
  14511. SeQuerySecurityDescriptorInfo (
  14512. IN PSECURITY_INFORMATION SecurityInformation,
  14513. OUT PSECURITY_DESCRIPTOR SecurityDescriptor,
  14514. IN OUT PULONG Length,
  14515. IN PSECURITY_DESCRIPTOR *ObjectsSecurityDescriptor
  14516. );
  14517. NTKERNELAPI
  14518. NTSTATUS
  14519. SeSetSecurityDescriptorInfo (
  14520. IN PVOID Object OPTIONAL,
  14521. IN PSECURITY_INFORMATION SecurityInformation,
  14522. IN PSECURITY_DESCRIPTOR SecurityDescriptor,
  14523. IN OUT PSECURITY_DESCRIPTOR *ObjectsSecurityDescriptor,
  14524. IN POOL_TYPE PoolType,
  14525. IN PGENERIC_MAPPING GenericMapping
  14526. );
  14527. NTKERNELAPI
  14528. NTSTATUS
  14529. SeSetSecurityDescriptorInfoEx (
  14530. IN PVOID Object OPTIONAL,
  14531. IN PSECURITY_INFORMATION SecurityInformation,
  14532. IN PSECURITY_DESCRIPTOR ModificationDescriptor,
  14533. IN OUT PSECURITY_DESCRIPTOR *ObjectsSecurityDescriptor,
  14534. IN ULONG AutoInheritFlags,
  14535. IN POOL_TYPE PoolType,
  14536. IN PGENERIC_MAPPING GenericMapping
  14537. );
  14538. NTKERNELAPI
  14539. NTSTATUS
  14540. SeAppendPrivileges(
  14541. PACCESS_STATE AccessState,
  14542. PPRIVILEGE_SET Privileges
  14543. );
  14544. NTKERNELAPI
  14545. BOOLEAN
  14546. SeSinglePrivilegeCheck(
  14547. LUID PrivilegeValue,
  14548. KPROCESSOR_MODE PreviousMode
  14549. );
  14550. NTKERNELAPI
  14551. NTSTATUS
  14552. SeQueryInformationToken (
  14553. IN PACCESS_TOKEN Token,
  14554. IN TOKEN_INFORMATION_CLASS TokenInformationClass,
  14555. OUT PVOID *TokenInformation
  14556. );
  14557. //
  14558. // Grants access to SeExports structure
  14559. //
  14560. extern NTKERNELAPI PSE_EXPORTS SeExports;
  14561. NTKERNELAPI
  14562. VOID
  14563. PoSetSystemState (
  14564. IN EXECUTION_STATE Flags
  14565. );
  14566. // begin_ntifs
  14567. NTKERNELAPI
  14568. PVOID
  14569. PoRegisterSystemState (
  14570. IN PVOID StateHandle,
  14571. IN EXECUTION_STATE Flags
  14572. );
  14573. // end_ntifs
  14574. typedef
  14575. VOID
  14576. (*PREQUEST_POWER_COMPLETE) (
  14577. IN PDEVICE_OBJECT DeviceObject,
  14578. IN UCHAR MinorFunction,
  14579. IN POWER_STATE PowerState,
  14580. IN PVOID Context,
  14581. IN PIO_STATUS_BLOCK IoStatus
  14582. );
  14583. NTKERNELAPI
  14584. NTSTATUS
  14585. PoRequestPowerIrp (
  14586. IN PDEVICE_OBJECT DeviceObject,
  14587. IN UCHAR MinorFunction,
  14588. IN POWER_STATE PowerState,
  14589. IN PREQUEST_POWER_COMPLETE CompletionFunction,
  14590. IN PVOID Context,
  14591. OUT PIRP *Irp OPTIONAL
  14592. );
  14593. NTKERNELAPI
  14594. NTSTATUS
  14595. PoRequestShutdownEvent (
  14596. OUT PVOID *Event
  14597. );
  14598. NTKERNELAPI
  14599. NTSTATUS
  14600. PoRequestShutdownWait (
  14601. IN PETHREAD Thread
  14602. );
  14603. // begin_ntifs
  14604. NTKERNELAPI
  14605. VOID
  14606. PoUnregisterSystemState (
  14607. IN PVOID StateHandle
  14608. );
  14609. // begin_nthal
  14610. NTKERNELAPI
  14611. POWER_STATE
  14612. PoSetPowerState (
  14613. IN PDEVICE_OBJECT DeviceObject,
  14614. IN POWER_STATE_TYPE Type,
  14615. IN POWER_STATE State
  14616. );
  14617. NTKERNELAPI
  14618. NTSTATUS
  14619. PoCallDriver (
  14620. IN PDEVICE_OBJECT DeviceObject,
  14621. IN OUT PIRP Irp
  14622. );
  14623. NTKERNELAPI
  14624. VOID
  14625. PoStartNextPowerIrp(
  14626. IN PIRP Irp
  14627. );
  14628. NTKERNELAPI
  14629. PULONG
  14630. PoRegisterDeviceForIdleDetection (
  14631. IN PDEVICE_OBJECT DeviceObject,
  14632. IN ULONG ConservationIdleTime,
  14633. IN ULONG PerformanceIdleTime,
  14634. IN DEVICE_POWER_STATE State
  14635. );
  14636. #define PoSetDeviceBusy(IdlePointer) \
  14637. *IdlePointer = 0
  14638. //
  14639. // \Callback\PowerState values
  14640. //
  14641. #define PO_CB_SYSTEM_POWER_POLICY 0
  14642. #define PO_CB_AC_STATUS 1
  14643. #define PO_CB_BUTTON_COLLISION 2
  14644. #define PO_CB_SYSTEM_STATE_LOCK 3
  14645. #define PO_CB_LID_SWITCH_STATE 4
  14646. #define PO_CB_PROCESSOR_POWER_POLICY 5
  14647. // end_ntddk end_wdm end_nthal
  14648. // Used for queuing work items to be performed at shutdown time. Same
  14649. // rules apply as per Ex work queues.
  14650. NTKERNELAPI
  14651. NTSTATUS
  14652. PoQueueShutdownWorkItem(
  14653. IN PWORK_QUEUE_ITEM WorkItem
  14654. );
  14655. PKTHREAD
  14656. FORCEINLINE
  14657. PsGetKernelThread(
  14658. IN PETHREAD ThreadObject
  14659. )
  14660. {
  14661. return (PKTHREAD)ThreadObject;
  14662. }
  14663. PKPROCESS
  14664. FORCEINLINE
  14665. PsGetKernelProcess(
  14666. IN PEPROCESS ProcessObject
  14667. )
  14668. {
  14669. return (PKPROCESS)ProcessObject;
  14670. }
  14671. NTSTATUS
  14672. PsGetContextThread(
  14673. IN PETHREAD Thread,
  14674. IN OUT PCONTEXT ThreadContext,
  14675. IN KPROCESSOR_MODE Mode
  14676. );
  14677. NTSTATUS
  14678. PsSetContextThread(
  14679. IN PETHREAD Thread,
  14680. IN PCONTEXT ThreadContext,
  14681. IN KPROCESSOR_MODE Mode
  14682. );
  14683. NTKERNELAPI
  14684. PEPROCESS
  14685. PsGetCurrentProcess(
  14686. VOID
  14687. );
  14688. NTKERNELAPI
  14689. PETHREAD
  14690. PsGetCurrentThread(
  14691. VOID
  14692. );
  14693. //
  14694. // System Thread and Process Creation and Termination
  14695. //
  14696. NTKERNELAPI
  14697. NTSTATUS
  14698. PsCreateSystemThread(
  14699. OUT PHANDLE ThreadHandle,
  14700. IN ULONG DesiredAccess,
  14701. IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL,
  14702. IN HANDLE ProcessHandle OPTIONAL,
  14703. OUT PCLIENT_ID ClientId OPTIONAL,
  14704. IN PKSTART_ROUTINE StartRoutine,
  14705. IN PVOID StartContext
  14706. );
  14707. NTKERNELAPI
  14708. NTSTATUS
  14709. PsTerminateSystemThread(
  14710. IN NTSTATUS ExitStatus
  14711. );
  14712. NTKERNELAPI
  14713. PACCESS_TOKEN
  14714. PsReferencePrimaryToken(
  14715. IN PEPROCESS Process
  14716. );
  14717. VOID
  14718. PsDereferencePrimaryToken(
  14719. IN PACCESS_TOKEN PrimaryToken
  14720. );
  14721. VOID
  14722. PsDereferenceImpersonationToken(
  14723. IN PACCESS_TOKEN ImpersonationToken
  14724. );
  14725. // end_ntifs
  14726. // begin_ntifs
  14727. NTKERNELAPI
  14728. PACCESS_TOKEN
  14729. PsReferenceImpersonationToken(
  14730. IN PETHREAD Thread,
  14731. OUT PBOOLEAN CopyOnOpen,
  14732. OUT PBOOLEAN EffectiveOnly,
  14733. OUT PSECURITY_IMPERSONATION_LEVEL ImpersonationLevel
  14734. );
  14735. // end_ntifs
  14736. PACCESS_TOKEN
  14737. PsReferenceEffectiveToken(
  14738. IN PETHREAD Thread,
  14739. OUT PTOKEN_TYPE TokenType,
  14740. OUT PBOOLEAN EffectiveOnly,
  14741. OUT PSECURITY_IMPERSONATION_LEVEL ImpersonationLevel
  14742. );
  14743. // begin_ntifs
  14744. LARGE_INTEGER
  14745. PsGetProcessExitTime(
  14746. VOID
  14747. );
  14748. // end_ntifs
  14749. BOOLEAN
  14750. PsIsThreadTerminating(
  14751. IN PETHREAD Thread
  14752. );
  14753. NTSTATUS
  14754. PsImpersonateClient(
  14755. IN PETHREAD Thread,
  14756. IN PACCESS_TOKEN Token,
  14757. IN BOOLEAN CopyOnOpen,
  14758. IN BOOLEAN EffectiveOnly,
  14759. IN SECURITY_IMPERSONATION_LEVEL ImpersonationLevel
  14760. );
  14761. NTKERNELAPI
  14762. VOID
  14763. PsRevertToSelf(
  14764. VOID
  14765. );
  14766. NTKERNELAPI
  14767. VOID
  14768. PsRevertThreadToSelf(
  14769. PETHREAD Thread
  14770. );
  14771. NTKERNELAPI
  14772. NTSTATUS
  14773. PsLookupProcessByProcessId(
  14774. IN HANDLE ProcessId,
  14775. OUT PEPROCESS *Process
  14776. );
  14777. NTKERNELAPI
  14778. NTSTATUS
  14779. PsLookupThreadByThreadId(
  14780. IN HANDLE ThreadId,
  14781. OUT PETHREAD *Thread
  14782. );
  14783. // begin_ntifs
  14784. //
  14785. // Quota Operations
  14786. //
  14787. VOID
  14788. PsChargePoolQuota(
  14789. IN PEPROCESS Process,
  14790. IN POOL_TYPE PoolType,
  14791. IN ULONG_PTR Amount
  14792. );
  14793. NTSTATUS
  14794. PsChargeProcessPoolQuota(
  14795. IN PEPROCESS Process,
  14796. IN POOL_TYPE PoolType,
  14797. IN ULONG_PTR Amount
  14798. );
  14799. VOID
  14800. PsReturnPoolQuota(
  14801. IN PEPROCESS Process,
  14802. IN POOL_TYPE PoolType,
  14803. IN ULONG_PTR Amount
  14804. );
  14805. // end_ntifs
  14806. typedef
  14807. NTSTATUS
  14808. (*PKWIN32_PROCESS_CALLOUT) (
  14809. IN PEPROCESS Process,
  14810. IN BOOLEAN Initialize
  14811. );
  14812. typedef enum _PSW32JOBCALLOUTTYPE {
  14813. PsW32JobCalloutSetInformation,
  14814. PsW32JobCalloutAddProcess,
  14815. PsW32JobCalloutTerminate
  14816. } PSW32JOBCALLOUTTYPE;
  14817. typedef struct _WIN32_JOBCALLOUT_PARAMETERS {
  14818. PVOID Job;
  14819. PSW32JOBCALLOUTTYPE CalloutType;
  14820. IN PVOID Data;
  14821. } WIN32_JOBCALLOUT_PARAMETERS, *PKWIN32_JOBCALLOUT_PARAMETERS;
  14822. typedef
  14823. NTSTATUS
  14824. (*PKWIN32_JOB_CALLOUT) (
  14825. IN PKWIN32_JOBCALLOUT_PARAMETERS Parm
  14826. );
  14827. typedef enum _PSW32THREADCALLOUTTYPE {
  14828. PsW32ThreadCalloutInitialize,
  14829. PsW32ThreadCalloutExit
  14830. } PSW32THREADCALLOUTTYPE;
  14831. typedef
  14832. NTSTATUS
  14833. (*PKWIN32_THREAD_CALLOUT) (
  14834. IN PETHREAD Thread,
  14835. IN PSW32THREADCALLOUTTYPE CalloutType
  14836. );
  14837. typedef enum _PSPOWEREVENTTYPE {
  14838. PsW32FullWake,
  14839. PsW32EventCode,
  14840. PsW32PowerPolicyChanged,
  14841. PsW32SystemPowerState,
  14842. PsW32SystemTime,
  14843. PsW32DisplayState,
  14844. PsW32CapabilitiesChanged,
  14845. PsW32SetStateFailed,
  14846. PsW32GdiOff,
  14847. PsW32GdiOn
  14848. } PSPOWEREVENTTYPE;
  14849. typedef struct _WIN32_POWEREVENT_PARAMETERS {
  14850. PSPOWEREVENTTYPE EventNumber;
  14851. ULONG_PTR Code;
  14852. } WIN32_POWEREVENT_PARAMETERS, *PKWIN32_POWEREVENT_PARAMETERS;
  14853. typedef enum _POWERSTATETASK {
  14854. PowerState_BlockSessionSwitch,
  14855. PowerState_Init,
  14856. PowerState_QueryApps,
  14857. PowerState_QueryFailed,
  14858. PowerState_SuspendApps,
  14859. PowerState_ShowUI,
  14860. PowerState_NotifyWL,
  14861. PowerState_ResumeApps,
  14862. PowerState_UnBlockSessionSwitch
  14863. } POWERSTATETASK;
  14864. typedef struct _WIN32_POWERSTATE_PARAMETERS {
  14865. BOOLEAN Promotion;
  14866. POWER_ACTION SystemAction;
  14867. SYSTEM_POWER_STATE MinSystemState;
  14868. ULONG Flags;
  14869. BOOLEAN fQueryDenied;
  14870. POWERSTATETASK PowerStateTask;
  14871. } WIN32_POWERSTATE_PARAMETERS, *PKWIN32_POWERSTATE_PARAMETERS;
  14872. typedef
  14873. NTSTATUS
  14874. (*PKWIN32_POWEREVENT_CALLOUT) (
  14875. IN PKWIN32_POWEREVENT_PARAMETERS Parm
  14876. );
  14877. typedef
  14878. NTSTATUS
  14879. (*PKWIN32_POWERSTATE_CALLOUT) (
  14880. IN PKWIN32_POWERSTATE_PARAMETERS Parm
  14881. );
  14882. typedef
  14883. NTSTATUS
  14884. (*PKWIN32_OBJECT_CALLOUT) (
  14885. IN PVOID Parm
  14886. );
  14887. typedef struct _WIN32_CALLOUTS_FPNS {
  14888. PKWIN32_PROCESS_CALLOUT ProcessCallout;
  14889. PKWIN32_THREAD_CALLOUT ThreadCallout;
  14890. PKWIN32_GLOBALATOMTABLE_CALLOUT GlobalAtomTableCallout;
  14891. PKWIN32_POWEREVENT_CALLOUT PowerEventCallout;
  14892. PKWIN32_POWERSTATE_CALLOUT PowerStateCallout;
  14893. PKWIN32_JOB_CALLOUT JobCallout;
  14894. PVOID BatchFlushRoutine;
  14895. PKWIN32_OBJECT_CALLOUT DesktopOpenProcedure;
  14896. PKWIN32_OBJECT_CALLOUT DesktopOkToCloseProcedure;
  14897. PKWIN32_OBJECT_CALLOUT DesktopCloseProcedure;
  14898. PKWIN32_OBJECT_CALLOUT DesktopDeleteProcedure;
  14899. PKWIN32_OBJECT_CALLOUT WindowStationOkToCloseProcedure;
  14900. PKWIN32_OBJECT_CALLOUT WindowStationCloseProcedure;
  14901. PKWIN32_OBJECT_CALLOUT WindowStationDeleteProcedure;
  14902. PKWIN32_OBJECT_CALLOUT WindowStationParseProcedure;
  14903. PKWIN32_OBJECT_CALLOUT WindowStationOpenProcedure;
  14904. } WIN32_CALLOUTS_FPNS, *PKWIN32_CALLOUTS_FPNS;
  14905. NTKERNELAPI
  14906. VOID
  14907. PsEstablishWin32Callouts(
  14908. IN PKWIN32_CALLOUTS_FPNS pWin32Callouts
  14909. );
  14910. typedef enum _PSPROCESSPRIORITYMODE {
  14911. PsProcessPriorityBackground,
  14912. PsProcessPriorityForeground,
  14913. PsProcessPrioritySpinning
  14914. } PSPROCESSPRIORITYMODE;
  14915. NTKERNELAPI
  14916. VOID
  14917. PsSetProcessPriorityByClass(
  14918. IN PEPROCESS Process,
  14919. IN PSPROCESSPRIORITYMODE PriorityMode
  14920. );
  14921. HANDLE
  14922. PsGetCurrentProcessId( VOID );
  14923. HANDLE
  14924. PsGetCurrentThreadId( VOID );
  14925. NTKERNELAPI
  14926. ULONG
  14927. PsGetCurrentProcessSessionId(
  14928. VOID
  14929. );
  14930. NTKERNELAPI
  14931. PVOID
  14932. PsGetCurrentThreadStackLimit(
  14933. VOID
  14934. );
  14935. NTKERNELAPI
  14936. PVOID
  14937. PsGetCurrentThreadStackBase(
  14938. VOID
  14939. );
  14940. NTKERNELAPI
  14941. CCHAR
  14942. PsGetCurrentThreadPreviousMode(
  14943. VOID
  14944. );
  14945. NTKERNELAPI
  14946. PERESOURCE
  14947. PsGetJobLock(
  14948. PEJOB Job
  14949. );
  14950. NTKERNELAPI
  14951. ULONG
  14952. PsGetJobSessionId(
  14953. PEJOB Job
  14954. );
  14955. NTKERNELAPI
  14956. ULONG
  14957. PsGetJobUIRestrictionsClass(
  14958. PEJOB Job
  14959. );
  14960. NTKERNELAPI
  14961. LONGLONG
  14962. PsGetProcessCreateTimeQuadPart(
  14963. PEPROCESS Process
  14964. );
  14965. NTKERNELAPI
  14966. PVOID
  14967. PsGetProcessDebugPort(
  14968. PEPROCESS Process
  14969. );
  14970. BOOLEAN
  14971. PsIsProcessBeingDebugged(
  14972. PEPROCESS Process
  14973. );
  14974. NTKERNELAPI
  14975. BOOLEAN
  14976. PsGetProcessExitProcessCalled(
  14977. PEPROCESS Process
  14978. );
  14979. NTKERNELAPI
  14980. NTSTATUS
  14981. PsGetProcessExitStatus(
  14982. PEPROCESS Process
  14983. );
  14984. NTKERNELAPI
  14985. HANDLE
  14986. PsGetProcessId(
  14987. PEPROCESS Process
  14988. );
  14989. NTKERNELAPI
  14990. UCHAR *
  14991. PsGetProcessImageFileName(
  14992. PEPROCESS Process
  14993. );
  14994. #define PsGetCurrentProcessImageFileName() PsGetProcessImageFileName(PsGetCurrentProcess())
  14995. NTKERNELAPI
  14996. HANDLE
  14997. PsGetProcessInheritedFromUniqueProcessId(
  14998. PEPROCESS Process
  14999. );
  15000. NTKERNELAPI
  15001. PEJOB
  15002. PsGetProcessJob(
  15003. PEPROCESS Process
  15004. );
  15005. NTKERNELAPI
  15006. ULONG
  15007. PsGetProcessSessionId(
  15008. PEPROCESS Process
  15009. );
  15010. NTKERNELAPI
  15011. PVOID
  15012. PsGetProcessSectionBaseAddress(
  15013. PEPROCESS Process
  15014. );
  15015. #define PsGetProcessPcb(Process) ((PKPROCESS)(Process))
  15016. NTKERNELAPI
  15017. PPEB
  15018. PsGetProcessPeb(
  15019. PEPROCESS Process
  15020. );
  15021. NTKERNELAPI
  15022. UCHAR
  15023. PsGetProcessPriorityClass(
  15024. PEPROCESS Process
  15025. );
  15026. NTKERNELAPI
  15027. HANDLE
  15028. PsGetProcessWin32WindowStation(
  15029. PEPROCESS Process
  15030. );
  15031. #define PsGetCurrentProcessWin32WindowStation() PsGetProcessWin32WindowStation(PsGetCurrentProcess())
  15032. NTKERNELAPI
  15033. PVOID
  15034. PsGetProcessWin32Process(
  15035. PEPROCESS Process
  15036. );
  15037. #define PsGetCurrentProcessWin32Process() PsGetProcessWin32Process(PsGetCurrentProcess())
  15038. #if defined(_WIN64)
  15039. NTKERNELAPI
  15040. PVOID
  15041. PsGetProcessWow64Process(
  15042. PEPROCESS Process
  15043. );
  15044. #endif
  15045. NTKERNELAPI
  15046. HANDLE
  15047. PsGetThreadId(
  15048. PETHREAD Thread
  15049. );
  15050. NTKERNELAPI
  15051. CCHAR
  15052. PsGetThreadFreezeCount(
  15053. PETHREAD Thread
  15054. );
  15055. NTKERNELAPI
  15056. BOOLEAN
  15057. PsGetThreadHardErrorsAreDisabled(
  15058. PETHREAD Thread);
  15059. NTKERNELAPI
  15060. PEPROCESS
  15061. PsGetThreadProcess(
  15062. PETHREAD Thread
  15063. );
  15064. #define PsGetCurrentThreadProcess() PsGetThreadProcess(PsGetCurrentThread())
  15065. NTKERNELAPI
  15066. HANDLE
  15067. PsGetThreadProcessId(
  15068. PETHREAD Thread
  15069. );
  15070. #define PsGetCurrentThreadProcessId() PsGetThreadProcessId(PsGetCurrentThread())
  15071. NTKERNELAPI
  15072. ULONG
  15073. PsGetThreadSessionId(
  15074. PETHREAD Thread
  15075. );
  15076. #define PsGetThreadTcb(Thread) ((PKTHREAD)(Thread))
  15077. NTKERNELAPI
  15078. PVOID
  15079. PsGetThreadTeb(
  15080. PETHREAD Thread
  15081. );
  15082. #define PsGetCurrentThreadTeb() PsGetThreadTeb(PsGetCurrentThread())
  15083. NTKERNELAPI
  15084. PVOID
  15085. PsGetThreadWin32Thread(
  15086. PETHREAD Thread
  15087. );
  15088. #define PsGetCurrentThreadWin32Thread() PsGetThreadWin32Thread(PsGetCurrentThread())
  15089. NTKERNELAPI //ntifs
  15090. BOOLEAN //ntifs
  15091. PsIsSystemThread( //ntifs
  15092. PETHREAD Thread //ntifs
  15093. ); //ntifs
  15094. NTKERNELAPI
  15095. BOOLEAN
  15096. PsIsThreadImpersonating (
  15097. IN PETHREAD Thread
  15098. );
  15099. NTSTATUS
  15100. PsReferenceProcessFilePointer (
  15101. IN PEPROCESS Process,
  15102. OUT PVOID *pFilePointer
  15103. );
  15104. NTKERNELAPI
  15105. VOID
  15106. PsSetJobUIRestrictionsClass(
  15107. PEJOB Job,
  15108. ULONG UIRestrictionsClass
  15109. );
  15110. NTKERNELAPI
  15111. VOID
  15112. PsSetProcessPriorityClass(
  15113. PEPROCESS Process,
  15114. UCHAR PriorityClass
  15115. );
  15116. NTKERNELAPI
  15117. NTSTATUS
  15118. PsSetProcessWin32Process(
  15119. PEPROCESS Process,
  15120. PVOID Win32Process,
  15121. PVOID PrevWin32Proces
  15122. );
  15123. NTKERNELAPI
  15124. VOID
  15125. PsSetProcessWindowStation(
  15126. PEPROCESS Process,
  15127. HANDLE Win32WindowStation
  15128. );
  15129. NTKERNELAPI
  15130. VOID
  15131. PsSetThreadHardErrorsAreDisabled(
  15132. PETHREAD Thread,
  15133. BOOLEAN HardErrorsAreDisabled
  15134. );
  15135. NTKERNELAPI
  15136. VOID
  15137. PsSetThreadWin32Thread(
  15138. PETHREAD Thread,
  15139. PVOID Win32Thread,
  15140. PVOID PrevWin32Thread
  15141. );
  15142. NTKERNELAPI
  15143. PVOID
  15144. PsGetProcessSecurityPort(
  15145. PEPROCESS Process
  15146. );
  15147. NTKERNELAPI
  15148. NTSTATUS
  15149. PsSetProcessSecurityPort(
  15150. PEPROCESS Process,
  15151. PVOID Port
  15152. );
  15153. typedef
  15154. NTSTATUS
  15155. (*PROCESS_ENUM_ROUTINE)(
  15156. IN PEPROCESS Process,
  15157. IN PVOID Context
  15158. );
  15159. typedef
  15160. NTSTATUS
  15161. (*THREAD_ENUM_ROUTINE)(
  15162. IN PEPROCESS Process,
  15163. IN PETHREAD Thread,
  15164. IN PVOID Context
  15165. );
  15166. NTSTATUS
  15167. PsEnumProcesses (
  15168. IN PROCESS_ENUM_ROUTINE CallBack,
  15169. IN PVOID Context
  15170. );
  15171. NTSTATUS
  15172. PsEnumProcessThreads (
  15173. IN PEPROCESS Process,
  15174. IN THREAD_ENUM_ROUTINE CallBack,
  15175. IN PVOID Context
  15176. );
  15177. PEPROCESS
  15178. PsGetNextProcess (
  15179. IN PEPROCESS Process
  15180. );
  15181. PETHREAD
  15182. PsGetNextProcessThread (
  15183. IN PEPROCESS Process,
  15184. IN PETHREAD Thread
  15185. );
  15186. VOID
  15187. PsQuitNextProcess (
  15188. IN PEPROCESS Process
  15189. );
  15190. VOID
  15191. PsQuitNextProcessThread (
  15192. IN PETHREAD Thread
  15193. );
  15194. PEJOB
  15195. PsGetNextJob (
  15196. IN PEJOB Job
  15197. );
  15198. PEPROCESS
  15199. PsGetNextJobProcess (
  15200. IN PEJOB Job,
  15201. IN PEPROCESS Process
  15202. );
  15203. VOID
  15204. PsQuitNextJob (
  15205. IN PEJOB Job
  15206. );
  15207. VOID
  15208. PsQuitNextJobProcess (
  15209. IN PEPROCESS Process
  15210. );
  15211. NTSTATUS
  15212. PsSuspendProcess (
  15213. IN PEPROCESS Process
  15214. );
  15215. NTSTATUS
  15216. PsResumeProcess (
  15217. IN PEPROCESS Process
  15218. );
  15219. NTSTATUS
  15220. PsTerminateProcess(
  15221. IN PEPROCESS Process,
  15222. IN NTSTATUS Status
  15223. );
  15224. NTSTATUS
  15225. PsSuspendThread (
  15226. IN PETHREAD Thread,
  15227. OUT PULONG PreviousSuspendCount OPTIONAL
  15228. );
  15229. NTSTATUS
  15230. PsResumeThread (
  15231. IN PETHREAD Thread,
  15232. OUT PULONG PreviousSuspendCount OPTIONAL
  15233. );
  15234. //
  15235. // Object Manager types
  15236. //
  15237. typedef struct _OBJECT_HANDLE_INFORMATION {
  15238. ULONG HandleAttributes;
  15239. ACCESS_MASK GrantedAccess;
  15240. } OBJECT_HANDLE_INFORMATION, *POBJECT_HANDLE_INFORMATION;
  15241. // end_ntddk end_wdm end_nthal end_ntifs
  15242. typedef struct _OBJECT_DUMP_CONTROL {
  15243. PVOID Stream;
  15244. ULONG Detail;
  15245. } OB_DUMP_CONTROL, *POB_DUMP_CONTROL;
  15246. typedef VOID (*OB_DUMP_METHOD)(
  15247. IN PVOID Object,
  15248. IN POB_DUMP_CONTROL Control OPTIONAL
  15249. );
  15250. typedef enum _OB_OPEN_REASON {
  15251. ObCreateHandle,
  15252. ObOpenHandle,
  15253. ObDuplicateHandle,
  15254. ObInheritHandle,
  15255. ObMaxOpenReason
  15256. } OB_OPEN_REASON;
  15257. typedef NTSTATUS (*OB_OPEN_METHOD)(
  15258. IN OB_OPEN_REASON OpenReason,
  15259. IN PEPROCESS Process OPTIONAL,
  15260. IN PVOID Object,
  15261. IN ACCESS_MASK GrantedAccess,
  15262. IN ULONG HandleCount
  15263. );
  15264. typedef BOOLEAN (*OB_OKAYTOCLOSE_METHOD)(
  15265. IN PEPROCESS Process OPTIONAL,
  15266. IN PVOID Object,
  15267. IN HANDLE Handle,
  15268. IN KPROCESSOR_MODE PreviousMode
  15269. );
  15270. typedef VOID (*OB_CLOSE_METHOD)(
  15271. IN PEPROCESS Process OPTIONAL,
  15272. IN PVOID Object,
  15273. IN ACCESS_MASK GrantedAccess,
  15274. IN ULONG ProcessHandleCount,
  15275. IN ULONG SystemHandleCount
  15276. );
  15277. typedef VOID (*OB_DELETE_METHOD)(
  15278. IN PVOID Object
  15279. );
  15280. typedef NTSTATUS (*OB_PARSE_METHOD)(
  15281. IN PVOID ParseObject,
  15282. IN PVOID ObjectType,
  15283. IN OUT PACCESS_STATE AccessState,
  15284. IN KPROCESSOR_MODE AccessMode,
  15285. IN ULONG Attributes,
  15286. IN OUT PUNICODE_STRING CompleteName,
  15287. IN OUT PUNICODE_STRING RemainingName,
  15288. IN OUT PVOID Context OPTIONAL,
  15289. IN PSECURITY_QUALITY_OF_SERVICE SecurityQos OPTIONAL,
  15290. OUT PVOID *Object
  15291. );
  15292. typedef NTSTATUS (*OB_SECURITY_METHOD)(
  15293. IN PVOID Object,
  15294. IN SECURITY_OPERATION_CODE OperationCode,
  15295. IN PSECURITY_INFORMATION SecurityInformation,
  15296. IN OUT PSECURITY_DESCRIPTOR SecurityDescriptor,
  15297. IN OUT PULONG CapturedLength,
  15298. IN OUT PSECURITY_DESCRIPTOR *ObjectsSecurityDescriptor,
  15299. IN POOL_TYPE PoolType,
  15300. IN PGENERIC_MAPPING GenericMapping
  15301. );
  15302. typedef NTSTATUS (*OB_QUERYNAME_METHOD)(
  15303. IN PVOID Object,
  15304. IN BOOLEAN HasObjectName,
  15305. OUT POBJECT_NAME_INFORMATION ObjectNameInfo,
  15306. IN ULONG Length,
  15307. OUT PULONG ReturnLength
  15308. );
  15309. /*
  15310. A security method and its caller must obey the following w.r.t.
  15311. capturing and probing parameters:
  15312. For a query operation, the caller must pass a kernel space address for
  15313. CapturedLength. The caller should be able to assume that it points to
  15314. valid data that will not change. In addition, the SecurityDescriptor
  15315. parameter (which will receive the result of the query operation) must
  15316. be probed for write up to the length given in CapturedLength. The
  15317. security method itself must always write to the SecurityDescriptor
  15318. buffer in a try clause in case the caller de-allocates it.
  15319. For a set operation, the SecurityDescriptor parameter must have
  15320. been captured via SeCaptureSecurityDescriptor. This parameter is
  15321. not optional, and therefore may not be NULL.
  15322. */
  15323. //
  15324. // Prototypes for Win32 WindowStation and Desktop object callout routines
  15325. //
  15326. typedef struct _WIN32_OPENMETHOD_PARAMETERS {
  15327. OB_OPEN_REASON OpenReason;
  15328. PEPROCESS Process;
  15329. PVOID Object;
  15330. ACCESS_MASK GrantedAccess;
  15331. ULONG HandleCount;
  15332. } WIN32_OPENMETHOD_PARAMETERS, *PKWIN32_OPENMETHOD_PARAMETERS;
  15333. typedef
  15334. NTSTATUS
  15335. (*PKWIN32_OPENMETHOD_CALLOUT) ( PKWIN32_OPENMETHOD_PARAMETERS );
  15336. extern PKWIN32_OPENMETHOD_CALLOUT ExDesktopOpenProcedureCallout;
  15337. extern PKWIN32_OPENMETHOD_CALLOUT ExWindowStationOpenProcedureCallout;
  15338. typedef struct _WIN32_OKAYTOCLOSEMETHOD_PARAMETERS {
  15339. PEPROCESS Process;
  15340. PVOID Object;
  15341. HANDLE Handle;
  15342. KPROCESSOR_MODE PreviousMode;
  15343. } WIN32_OKAYTOCLOSEMETHOD_PARAMETERS, *PKWIN32_OKAYTOCLOSEMETHOD_PARAMETERS;
  15344. typedef
  15345. NTSTATUS
  15346. (*PKWIN32_OKTOCLOSEMETHOD_CALLOUT) ( PKWIN32_OKAYTOCLOSEMETHOD_PARAMETERS );
  15347. extern PKWIN32_OKTOCLOSEMETHOD_CALLOUT ExDesktopOkToCloseProcedureCallout;
  15348. extern PKWIN32_OKTOCLOSEMETHOD_CALLOUT ExWindowStationOkToCloseProcedureCallout;
  15349. typedef struct _WIN32_CLOSEMETHOD_PARAMETERS {
  15350. PEPROCESS Process;
  15351. PVOID Object;
  15352. ACCESS_MASK GrantedAccess;
  15353. ULONG ProcessHandleCount;
  15354. ULONG SystemHandleCount;
  15355. } WIN32_CLOSEMETHOD_PARAMETERS, *PKWIN32_CLOSEMETHOD_PARAMETERS;
  15356. typedef
  15357. NTSTATUS
  15358. (*PKWIN32_CLOSEMETHOD_CALLOUT) ( PKWIN32_CLOSEMETHOD_PARAMETERS );
  15359. extern PKWIN32_CLOSEMETHOD_CALLOUT ExDesktopCloseProcedureCallout;
  15360. extern PKWIN32_CLOSEMETHOD_CALLOUT ExWindowStationCloseProcedureCallout;
  15361. typedef struct _WIN32_DELETEMETHOD_PARAMETERS {
  15362. PVOID Object;
  15363. } WIN32_DELETEMETHOD_PARAMETERS, *PKWIN32_DELETEMETHOD_PARAMETERS;
  15364. typedef
  15365. NTSTATUS
  15366. (*PKWIN32_DELETEMETHOD_CALLOUT) ( PKWIN32_DELETEMETHOD_PARAMETERS );
  15367. extern PKWIN32_DELETEMETHOD_CALLOUT ExDesktopDeleteProcedureCallout;
  15368. extern PKWIN32_DELETEMETHOD_CALLOUT ExWindowStationDeleteProcedureCallout;
  15369. typedef struct _WIN32_PARSEMETHOD_PARAMETERS {
  15370. PVOID ParseObject;
  15371. PVOID ObjectType;
  15372. PACCESS_STATE AccessState;
  15373. KPROCESSOR_MODE AccessMode;
  15374. ULONG Attributes;
  15375. PUNICODE_STRING CompleteName;
  15376. PUNICODE_STRING RemainingName;
  15377. PVOID Context OPTIONAL;
  15378. PSECURITY_QUALITY_OF_SERVICE SecurityQos;
  15379. PVOID *Object;
  15380. } WIN32_PARSEMETHOD_PARAMETERS, *PKWIN32_PARSEMETHOD_PARAMETERS;
  15381. typedef
  15382. NTSTATUS
  15383. (*PKWIN32_PARSEMETHOD_CALLOUT) ( PKWIN32_PARSEMETHOD_PARAMETERS );
  15384. extern PKWIN32_PARSEMETHOD_CALLOUT ExWindowStationParseProcedureCallout;
  15385. //
  15386. // Object Type Structure
  15387. //
  15388. typedef struct _OBJECT_TYPE_INITIALIZER {
  15389. USHORT Length;
  15390. BOOLEAN UseDefaultObject;
  15391. BOOLEAN CaseInsensitive;
  15392. ULONG InvalidAttributes;
  15393. GENERIC_MAPPING GenericMapping;
  15394. ULONG ValidAccessMask;
  15395. BOOLEAN SecurityRequired;
  15396. BOOLEAN MaintainHandleCount;
  15397. BOOLEAN MaintainTypeList;
  15398. POOL_TYPE PoolType;
  15399. ULONG DefaultPagedPoolCharge;
  15400. ULONG DefaultNonPagedPoolCharge;
  15401. OB_DUMP_METHOD DumpProcedure;
  15402. OB_OPEN_METHOD OpenProcedure;
  15403. OB_CLOSE_METHOD CloseProcedure;
  15404. OB_DELETE_METHOD DeleteProcedure;
  15405. OB_PARSE_METHOD ParseProcedure;
  15406. OB_SECURITY_METHOD SecurityProcedure;
  15407. OB_QUERYNAME_METHOD QueryNameProcedure;
  15408. OB_OKAYTOCLOSE_METHOD OkayToCloseProcedure;
  15409. } OBJECT_TYPE_INITIALIZER, *POBJECT_TYPE_INITIALIZER;
  15410. #define OBJECT_LOCK_COUNT 4
  15411. typedef struct _OBJECT_TYPE {
  15412. ERESOURCE Mutex;
  15413. LIST_ENTRY TypeList;
  15414. UNICODE_STRING Name; // Copy from object header for convenience
  15415. PVOID DefaultObject;
  15416. ULONG Index;
  15417. ULONG TotalNumberOfObjects;
  15418. ULONG TotalNumberOfHandles;
  15419. ULONG HighWaterNumberOfObjects;
  15420. ULONG HighWaterNumberOfHandles;
  15421. OBJECT_TYPE_INITIALIZER TypeInfo;
  15422. #ifdef POOL_TAGGING
  15423. ULONG Key;
  15424. #endif //POOL_TAGGING
  15425. ERESOURCE ObjectLocks[ OBJECT_LOCK_COUNT ];
  15426. } OBJECT_TYPE, *POBJECT_TYPE;
  15427. //
  15428. // Object Directory Structure
  15429. //
  15430. #define NUMBER_HASH_BUCKETS 37
  15431. typedef struct _OBJECT_DIRECTORY {
  15432. struct _OBJECT_DIRECTORY_ENTRY *HashBuckets[ NUMBER_HASH_BUCKETS ];
  15433. EX_PUSH_LOCK Lock;
  15434. struct _DEVICE_MAP *DeviceMap;
  15435. USHORT Reserved;
  15436. USHORT SymbolicLinkUsageCount;
  15437. } OBJECT_DIRECTORY, *POBJECT_DIRECTORY;
  15438. typedef struct _OBJECT_CREATE_INFORMATION *POBJECT_CREATE_INFORMATION;;
  15439. typedef struct _OBJECT_HEADER {
  15440. LONG PointerCount;
  15441. union {
  15442. LONG HandleCount;
  15443. PVOID NextToFree;
  15444. };
  15445. POBJECT_TYPE Type;
  15446. UCHAR NameInfoOffset;
  15447. UCHAR HandleInfoOffset;
  15448. UCHAR QuotaInfoOffset;
  15449. UCHAR Flags;
  15450. union {
  15451. POBJECT_CREATE_INFORMATION ObjectCreateInfo;
  15452. PVOID QuotaBlockCharged;
  15453. };
  15454. PSECURITY_DESCRIPTOR SecurityDescriptor;
  15455. QUAD Body;
  15456. } OBJECT_HEADER, *POBJECT_HEADER;
  15457. typedef struct _OBJECT_HEADER_NAME_INFO {
  15458. POBJECT_DIRECTORY Directory;
  15459. UNICODE_STRING Name;
  15460. ULONG QueryReferences;
  15461. #if DBG
  15462. ULONG Reserved2;
  15463. LONG DbgDereferenceCount;
  15464. #ifdef _WIN64
  15465. ULONG64 Reserved3; // Win64 requires these structures to be 16 byte aligned.
  15466. #endif
  15467. #endif
  15468. } OBJECT_HEADER_NAME_INFO, *POBJECT_HEADER_NAME_INFO;
  15469. #define OBJECT_TO_OBJECT_HEADER( o ) \
  15470. CONTAINING_RECORD( (o), OBJECT_HEADER, Body )
  15471. #define OBJECT_HEADER_TO_NAME_INFO( oh ) ((POBJECT_HEADER_NAME_INFO) \
  15472. ((oh)->NameInfoOffset == 0 ? NULL : ((PCHAR)(oh) - (oh)->NameInfoOffset)))
  15473. #define OBJECT_HEADER_TO_CREATOR_INFO( oh ) ((POBJECT_HEADER_CREATOR_INFO) \
  15474. (((oh)->Flags & OB_FLAG_CREATOR_INFO) == 0 ? NULL : ((PCHAR)(oh) - sizeof(OBJECT_HEADER_CREATOR_INFO))))
  15475. NTKERNELAPI
  15476. NTSTATUS
  15477. ObCreateObjectType(
  15478. IN PUNICODE_STRING TypeName,
  15479. IN POBJECT_TYPE_INITIALIZER ObjectTypeInitializer,
  15480. IN PSECURITY_DESCRIPTOR SecurityDescriptor OPTIONAL,
  15481. OUT POBJECT_TYPE *ObjectType
  15482. );
  15483. NTKERNELAPI
  15484. NTSTATUS
  15485. ObCreateObject(
  15486. IN KPROCESSOR_MODE ProbeMode,
  15487. IN POBJECT_TYPE ObjectType,
  15488. IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL,
  15489. IN KPROCESSOR_MODE OwnershipMode,
  15490. IN OUT PVOID ParseContext OPTIONAL,
  15491. IN ULONG ObjectBodySize,
  15492. IN ULONG PagedPoolCharge,
  15493. IN ULONG NonPagedPoolCharge,
  15494. OUT PVOID *Object
  15495. );
  15496. //
  15497. // These inlines correct an issue where the compiler refetches
  15498. // the output object over and over again because it thinks its
  15499. // a possible alias for other stores.
  15500. //
  15501. FORCEINLINE
  15502. NTSTATUS
  15503. _ObCreateObject(
  15504. IN KPROCESSOR_MODE ProbeMode,
  15505. IN POBJECT_TYPE ObjectType,
  15506. IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL,
  15507. IN KPROCESSOR_MODE OwnershipMode,
  15508. IN OUT PVOID ParseContext OPTIONAL,
  15509. IN ULONG ObjectBodySize,
  15510. IN ULONG PagedPoolCharge,
  15511. IN ULONG NonPagedPoolCharge,
  15512. OUT PVOID *pObject
  15513. )
  15514. {
  15515. PVOID Object;
  15516. NTSTATUS Status;
  15517. Status = ObCreateObject (ProbeMode,
  15518. ObjectType,
  15519. ObjectAttributes,
  15520. OwnershipMode,
  15521. ParseContext,
  15522. ObjectBodySize,
  15523. PagedPoolCharge,
  15524. NonPagedPoolCharge,
  15525. &Object);
  15526. *pObject = Object;
  15527. return Status;
  15528. }
  15529. #define ObCreateObject _ObCreateObject
  15530. NTKERNELAPI
  15531. NTSTATUS
  15532. ObInsertObject(
  15533. IN PVOID Object,
  15534. IN PACCESS_STATE PassedAccessState OPTIONAL,
  15535. IN ACCESS_MASK DesiredAccess OPTIONAL,
  15536. IN ULONG ObjectPointerBias,
  15537. OUT PVOID *NewObject OPTIONAL,
  15538. OUT PHANDLE Handle OPTIONAL
  15539. );
  15540. // end_nthal
  15541. NTKERNELAPI // ntddk wdm nthal ntifs
  15542. NTSTATUS // ntddk wdm nthal ntifs
  15543. ObReferenceObjectByHandle( // ntddk wdm nthal ntifs
  15544. IN HANDLE Handle, // ntddk wdm nthal ntifs
  15545. IN ACCESS_MASK DesiredAccess, // ntddk wdm nthal ntifs
  15546. IN POBJECT_TYPE ObjectType OPTIONAL, // ntddk wdm nthal ntifs
  15547. IN KPROCESSOR_MODE AccessMode, // ntddk wdm nthal ntifs
  15548. OUT PVOID *Object, // ntddk wdm nthal ntifs
  15549. OUT POBJECT_HANDLE_INFORMATION HandleInformation OPTIONAL // ntddk wdm nthal ntifs
  15550. ); // ntddk wdm nthal ntifs
  15551. FORCEINLINE
  15552. NTSTATUS
  15553. _ObReferenceObjectByHandle(
  15554. IN HANDLE Handle,
  15555. IN ACCESS_MASK DesiredAccess,
  15556. IN POBJECT_TYPE ObjectType OPTIONAL,
  15557. IN KPROCESSOR_MODE AccessMode,
  15558. OUT PVOID *pObject,
  15559. OUT POBJECT_HANDLE_INFORMATION pHandleInformation OPTIONAL
  15560. )
  15561. {
  15562. PVOID Object;
  15563. NTSTATUS Status;
  15564. Status = ObReferenceObjectByHandle (Handle,
  15565. DesiredAccess,
  15566. ObjectType,
  15567. AccessMode,
  15568. &Object,
  15569. pHandleInformation);
  15570. *pObject = Object;
  15571. return Status;
  15572. }
  15573. #define ObReferenceObjectByHandle _ObReferenceObjectByHandle
  15574. NTKERNELAPI
  15575. NTSTATUS
  15576. ObReferenceFileObjectForWrite(
  15577. IN HANDLE Handle,
  15578. IN KPROCESSOR_MODE AccessMode,
  15579. OUT PVOID *FileObject,
  15580. OUT POBJECT_HANDLE_INFORMATION HandleInformation
  15581. );
  15582. NTKERNELAPI
  15583. NTSTATUS
  15584. ObOpenObjectByName(
  15585. IN POBJECT_ATTRIBUTES ObjectAttributes,
  15586. IN POBJECT_TYPE ObjectType,
  15587. IN KPROCESSOR_MODE AccessMode,
  15588. IN OUT PACCESS_STATE PassedAccessState OPTIONAL,
  15589. IN ACCESS_MASK DesiredAccess OPTIONAL,
  15590. IN OUT PVOID ParseContext OPTIONAL,
  15591. OUT PHANDLE Handle
  15592. );
  15593. NTKERNELAPI // ntifs
  15594. NTSTATUS // ntifs
  15595. ObOpenObjectByPointer( // ntifs
  15596. IN PVOID Object, // ntifs
  15597. IN ULONG HandleAttributes, // ntifs
  15598. IN PACCESS_STATE PassedAccessState OPTIONAL, // ntifs
  15599. IN ACCESS_MASK DesiredAccess OPTIONAL, // ntifs
  15600. IN POBJECT_TYPE ObjectType OPTIONAL, // ntifs
  15601. IN KPROCESSOR_MODE AccessMode, // ntifs
  15602. OUT PHANDLE Handle // ntifs
  15603. ); // ntifs
  15604. NTSTATUS
  15605. ObReferenceObjectByName(
  15606. IN PUNICODE_STRING ObjectName,
  15607. IN ULONG Attributes,
  15608. IN PACCESS_STATE PassedAccessState OPTIONAL,
  15609. IN ACCESS_MASK DesiredAccess OPTIONAL,
  15610. IN POBJECT_TYPE ObjectType,
  15611. IN KPROCESSOR_MODE AccessMode,
  15612. IN OUT PVOID ParseContext OPTIONAL,
  15613. OUT PVOID *Object
  15614. );
  15615. NTKERNELAPI
  15616. BOOLEAN
  15617. ObFindHandleForObject(
  15618. IN PEPROCESS Process,
  15619. IN PVOID Object,
  15620. IN POBJECT_TYPE ObjectType OPTIONAL,
  15621. IN POBJECT_HANDLE_INFORMATION MatchCriteria OPTIONAL,
  15622. OUT PHANDLE Handle
  15623. );
  15624. // begin_ntddk begin_wdm begin_nthal begin_ntifs
  15625. #define ObDereferenceObject(a) \
  15626. ObfDereferenceObject(a)
  15627. #define ObReferenceObject(Object) ObfReferenceObject(Object)
  15628. NTKERNELAPI
  15629. LONG
  15630. FASTCALL
  15631. ObfReferenceObject(
  15632. IN PVOID Object
  15633. );
  15634. NTKERNELAPI
  15635. NTSTATUS
  15636. ObReferenceObjectByPointer(
  15637. IN PVOID Object,
  15638. IN ACCESS_MASK DesiredAccess,
  15639. IN POBJECT_TYPE ObjectType,
  15640. IN KPROCESSOR_MODE AccessMode
  15641. );
  15642. NTKERNELAPI
  15643. LONG
  15644. FASTCALL
  15645. ObfDereferenceObject(
  15646. IN PVOID Object
  15647. );
  15648. NTKERNELAPI
  15649. NTSTATUS
  15650. ObQueryNameString(
  15651. IN PVOID Object,
  15652. OUT POBJECT_NAME_INFORMATION ObjectNameInfo,
  15653. IN ULONG Length,
  15654. OUT PULONG ReturnLength
  15655. );
  15656. NTSTATUS
  15657. ObGetObjectSecurity(
  15658. IN PVOID Object,
  15659. OUT PSECURITY_DESCRIPTOR *SecurityDescriptor,
  15660. OUT PBOOLEAN MemoryAllocated
  15661. );
  15662. VOID
  15663. ObReleaseObjectSecurity(
  15664. IN PSECURITY_DESCRIPTOR SecurityDescriptor,
  15665. IN BOOLEAN MemoryAllocated
  15666. );
  15667. NTKERNELAPI
  15668. BOOLEAN
  15669. ObCheckCreateObjectAccess(
  15670. IN PVOID DirectoryObject,
  15671. IN ACCESS_MASK CreateAccess,
  15672. IN PACCESS_STATE AccessState OPTIONAL,
  15673. IN PUNICODE_STRING ComponentName,
  15674. IN BOOLEAN TypeMutexLocked,
  15675. IN KPROCESSOR_MODE PreviousMode,
  15676. OUT PNTSTATUS AccessStatus
  15677. );
  15678. NTKERNELAPI
  15679. BOOLEAN
  15680. ObCheckObjectAccess(
  15681. IN PVOID Object,
  15682. IN PACCESS_STATE AccessState,
  15683. IN BOOLEAN TypeMutexLocked,
  15684. IN KPROCESSOR_MODE AccessMode,
  15685. OUT PNTSTATUS AccessStatus
  15686. );
  15687. NTKERNELAPI
  15688. NTSTATUS
  15689. ObAssignSecurity(
  15690. IN PACCESS_STATE AccessState,
  15691. IN PSECURITY_DESCRIPTOR ParentDescriptor OPTIONAL,
  15692. IN PVOID Object,
  15693. IN POBJECT_TYPE ObjectType
  15694. );
  15695. NTSTATUS
  15696. ObSetSecurityObjectByPointer (
  15697. IN PVOID Object,
  15698. IN SECURITY_INFORMATION SecurityInformation,
  15699. IN PSECURITY_DESCRIPTOR SecurityDescriptor
  15700. );
  15701. NTSTATUS
  15702. ObSetHandleAttributes (
  15703. IN HANDLE Handle,
  15704. IN POBJECT_HANDLE_FLAG_INFORMATION HandleFlags,
  15705. IN KPROCESSOR_MODE PreviousMode
  15706. );
  15707. NTSTATUS
  15708. ObCloseHandle (
  15709. IN HANDLE Handle,
  15710. IN KPROCESSOR_MODE PreviousMode
  15711. );
  15712. NTKERNELAPI
  15713. NTSTATUS
  15714. ObSetSecurityDescriptorInfo(
  15715. IN PVOID Object,
  15716. IN PSECURITY_INFORMATION SecurityInformation,
  15717. IN OUT PSECURITY_DESCRIPTOR SecurityDescriptor,
  15718. IN OUT PSECURITY_DESCRIPTOR *ObjectsSecurityDescriptor,
  15719. IN POOL_TYPE PoolType,
  15720. IN PGENERIC_MAPPING GenericMapping
  15721. );
  15722. //
  15723. // A PCI driver can read the complete 256 bytes of configuration
  15724. // information for any PCI device by calling:
  15725. //
  15726. // ULONG
  15727. // HalGetBusData (
  15728. // IN BUS_DATA_TYPE PCIConfiguration,
  15729. // IN ULONG PciBusNumber,
  15730. // IN PCI_SLOT_NUMBER VirtualSlotNumber,
  15731. // IN PPCI_COMMON_CONFIG &PCIDeviceConfig,
  15732. // IN ULONG sizeof (PCIDeviceConfig)
  15733. // );
  15734. //
  15735. // A return value of 0 means that the specified PCI bus does not exist.
  15736. //
  15737. // A return value of 2, with a VendorID of PCI_INVALID_VENDORID means
  15738. // that the PCI bus does exist, but there is no device at the specified
  15739. // VirtualSlotNumber (PCI Device/Function number).
  15740. //
  15741. //
  15742. // begin_wdm begin_ntminiport begin_ntndis
  15743. typedef struct _PCI_SLOT_NUMBER {
  15744. union {
  15745. struct {
  15746. ULONG DeviceNumber:5;
  15747. ULONG FunctionNumber:3;
  15748. ULONG Reserved:24;
  15749. } bits;
  15750. ULONG AsULONG;
  15751. } u;
  15752. } PCI_SLOT_NUMBER, *PPCI_SLOT_NUMBER;
  15753. #define PCI_TYPE0_ADDRESSES 6
  15754. #define PCI_TYPE1_ADDRESSES 2
  15755. #define PCI_TYPE2_ADDRESSES 5
  15756. typedef struct _PCI_COMMON_CONFIG {
  15757. USHORT VendorID; // (ro)
  15758. USHORT DeviceID; // (ro)
  15759. USHORT Command; // Device control
  15760. USHORT Status;
  15761. UCHAR RevisionID; // (ro)
  15762. UCHAR ProgIf; // (ro)
  15763. UCHAR SubClass; // (ro)
  15764. UCHAR BaseClass; // (ro)
  15765. UCHAR CacheLineSize; // (ro+)
  15766. UCHAR LatencyTimer; // (ro+)
  15767. UCHAR HeaderType; // (ro)
  15768. UCHAR BIST; // Built in self test
  15769. union {
  15770. struct _PCI_HEADER_TYPE_0 {
  15771. ULONG BaseAddresses[PCI_TYPE0_ADDRESSES];
  15772. ULONG CIS;
  15773. USHORT SubVendorID;
  15774. USHORT SubSystemID;
  15775. ULONG ROMBaseAddress;
  15776. UCHAR CapabilitiesPtr;
  15777. UCHAR Reserved1[3];
  15778. ULONG Reserved2;
  15779. UCHAR InterruptLine; //
  15780. UCHAR InterruptPin; // (ro)
  15781. UCHAR MinimumGrant; // (ro)
  15782. UCHAR MaximumLatency; // (ro)
  15783. } type0;
  15784. // end_wdm end_ntminiport end_ntndis
  15785. //
  15786. // PCI to PCI Bridge
  15787. //
  15788. struct _PCI_HEADER_TYPE_1 {
  15789. ULONG BaseAddresses[PCI_TYPE1_ADDRESSES];
  15790. UCHAR PrimaryBus;
  15791. UCHAR SecondaryBus;
  15792. UCHAR SubordinateBus;
  15793. UCHAR SecondaryLatency;
  15794. UCHAR IOBase;
  15795. UCHAR IOLimit;
  15796. USHORT SecondaryStatus;
  15797. USHORT MemoryBase;
  15798. USHORT MemoryLimit;
  15799. USHORT PrefetchBase;
  15800. USHORT PrefetchLimit;
  15801. ULONG PrefetchBaseUpper32;
  15802. ULONG PrefetchLimitUpper32;
  15803. USHORT IOBaseUpper16;
  15804. USHORT IOLimitUpper16;
  15805. UCHAR CapabilitiesPtr;
  15806. UCHAR Reserved1[3];
  15807. ULONG ROMBaseAddress;
  15808. UCHAR InterruptLine;
  15809. UCHAR InterruptPin;
  15810. USHORT BridgeControl;
  15811. } type1;
  15812. //
  15813. // PCI to CARDBUS Bridge
  15814. //
  15815. struct _PCI_HEADER_TYPE_2 {
  15816. ULONG SocketRegistersBaseAddress;
  15817. UCHAR CapabilitiesPtr;
  15818. UCHAR Reserved;
  15819. USHORT SecondaryStatus;
  15820. UCHAR PrimaryBus;
  15821. UCHAR SecondaryBus;
  15822. UCHAR SubordinateBus;
  15823. UCHAR SecondaryLatency;
  15824. struct {
  15825. ULONG Base;
  15826. ULONG Limit;
  15827. } Range[PCI_TYPE2_ADDRESSES-1];
  15828. UCHAR InterruptLine;
  15829. UCHAR InterruptPin;
  15830. USHORT BridgeControl;
  15831. } type2;
  15832. // begin_wdm begin_ntminiport begin_ntndis
  15833. } u;
  15834. UCHAR DeviceSpecific[192];
  15835. } PCI_COMMON_CONFIG, *PPCI_COMMON_CONFIG;
  15836. #define PCI_COMMON_HDR_LENGTH (FIELD_OFFSET (PCI_COMMON_CONFIG, DeviceSpecific))
  15837. #define PCI_MAX_DEVICES 32
  15838. #define PCI_MAX_FUNCTION 8
  15839. #define PCI_MAX_BRIDGE_NUMBER 0xFF
  15840. #define PCI_INVALID_VENDORID 0xFFFF
  15841. //
  15842. // Bit encodings for PCI_COMMON_CONFIG.HeaderType
  15843. //
  15844. #define PCI_MULTIFUNCTION 0x80
  15845. #define PCI_DEVICE_TYPE 0x00
  15846. #define PCI_BRIDGE_TYPE 0x01
  15847. #define PCI_CARDBUS_BRIDGE_TYPE 0x02
  15848. #define PCI_CONFIGURATION_TYPE(PciData) \
  15849. (((PPCI_COMMON_CONFIG)(PciData))->HeaderType & ~PCI_MULTIFUNCTION)
  15850. #define PCI_MULTIFUNCTION_DEVICE(PciData) \
  15851. ((((PPCI_COMMON_CONFIG)(PciData))->HeaderType & PCI_MULTIFUNCTION) != 0)
  15852. //
  15853. // Bit encodings for PCI_COMMON_CONFIG.Command
  15854. //
  15855. #define PCI_ENABLE_IO_SPACE 0x0001
  15856. #define PCI_ENABLE_MEMORY_SPACE 0x0002
  15857. #define PCI_ENABLE_BUS_MASTER 0x0004
  15858. #define PCI_ENABLE_SPECIAL_CYCLES 0x0008
  15859. #define PCI_ENABLE_WRITE_AND_INVALIDATE 0x0010
  15860. #define PCI_ENABLE_VGA_COMPATIBLE_PALETTE 0x0020
  15861. #define PCI_ENABLE_PARITY 0x0040 // (ro+)
  15862. #define PCI_ENABLE_WAIT_CYCLE 0x0080 // (ro+)
  15863. #define PCI_ENABLE_SERR 0x0100 // (ro+)
  15864. #define PCI_ENABLE_FAST_BACK_TO_BACK 0x0200 // (ro)
  15865. //
  15866. // Bit encodings for PCI_COMMON_CONFIG.Status
  15867. //
  15868. #define PCI_STATUS_CAPABILITIES_LIST 0x0010 // (ro)
  15869. #define PCI_STATUS_66MHZ_CAPABLE 0x0020 // (ro)
  15870. #define PCI_STATUS_UDF_SUPPORTED 0x0040 // (ro)
  15871. #define PCI_STATUS_FAST_BACK_TO_BACK 0x0080 // (ro)
  15872. #define PCI_STATUS_DATA_PARITY_DETECTED 0x0100
  15873. #define PCI_STATUS_DEVSEL 0x0600 // 2 bits wide
  15874. #define PCI_STATUS_SIGNALED_TARGET_ABORT 0x0800
  15875. #define PCI_STATUS_RECEIVED_TARGET_ABORT 0x1000
  15876. #define PCI_STATUS_RECEIVED_MASTER_ABORT 0x2000
  15877. #define PCI_STATUS_SIGNALED_SYSTEM_ERROR 0x4000
  15878. #define PCI_STATUS_DETECTED_PARITY_ERROR 0x8000
  15879. //
  15880. // The NT PCI Driver uses a WhichSpace parameter on its CONFIG_READ/WRITE
  15881. // routines. The following values are defined-
  15882. //
  15883. #define PCI_WHICHSPACE_CONFIG 0x0
  15884. #define PCI_WHICHSPACE_ROM 0x52696350
  15885. // end_wdm
  15886. //
  15887. // PCI Capability IDs
  15888. //
  15889. #define PCI_CAPABILITY_ID_POWER_MANAGEMENT 0x01
  15890. #define PCI_CAPABILITY_ID_AGP 0x02
  15891. #define PCI_CAPABILITY_ID_MSI 0x05
  15892. //
  15893. // All PCI Capability structures have the following header.
  15894. //
  15895. // CapabilityID is used to identify the type of the structure (is
  15896. // one of the PCI_CAPABILITY_ID values above.
  15897. //
  15898. // Next is the offset in PCI Configuration space (0x40 - 0xfc) of the
  15899. // next capability structure in the list, or 0x00 if there are no more
  15900. // entries.
  15901. //
  15902. typedef struct _PCI_CAPABILITIES_HEADER {
  15903. UCHAR CapabilityID;
  15904. UCHAR Next;
  15905. } PCI_CAPABILITIES_HEADER, *PPCI_CAPABILITIES_HEADER;
  15906. //
  15907. // Power Management Capability
  15908. //
  15909. typedef struct _PCI_PMC {
  15910. UCHAR Version:3;
  15911. UCHAR PMEClock:1;
  15912. UCHAR Rsvd1:1;
  15913. UCHAR DeviceSpecificInitialization:1;
  15914. UCHAR Rsvd2:2;
  15915. struct _PM_SUPPORT {
  15916. UCHAR Rsvd2:1;
  15917. UCHAR D1:1;
  15918. UCHAR D2:1;
  15919. UCHAR PMED0:1;
  15920. UCHAR PMED1:1;
  15921. UCHAR PMED2:1;
  15922. UCHAR PMED3Hot:1;
  15923. UCHAR PMED3Cold:1;
  15924. } Support;
  15925. } PCI_PMC, *PPCI_PMC;
  15926. typedef struct _PCI_PMCSR {
  15927. USHORT PowerState:2;
  15928. USHORT Rsvd1:6;
  15929. USHORT PMEEnable:1;
  15930. USHORT DataSelect:4;
  15931. USHORT DataScale:2;
  15932. USHORT PMEStatus:1;
  15933. } PCI_PMCSR, *PPCI_PMCSR;
  15934. typedef struct _PCI_PMCSR_BSE {
  15935. UCHAR Rsvd1:6;
  15936. UCHAR D3HotSupportsStopClock:1; // B2_B3#
  15937. UCHAR BusPowerClockControlEnabled:1; // BPCC_EN
  15938. } PCI_PMCSR_BSE, *PPCI_PMCSR_BSE;
  15939. typedef struct _PCI_PM_CAPABILITY {
  15940. PCI_CAPABILITIES_HEADER Header;
  15941. //
  15942. // Power Management Capabilities (Offset = 2)
  15943. //
  15944. union {
  15945. PCI_PMC Capabilities;
  15946. USHORT AsUSHORT;
  15947. } PMC;
  15948. //
  15949. // Power Management Control/Status (Offset = 4)
  15950. //
  15951. union {
  15952. PCI_PMCSR ControlStatus;
  15953. USHORT AsUSHORT;
  15954. } PMCSR;
  15955. //
  15956. // PMCSR PCI-PCI Bridge Support Extensions
  15957. //
  15958. union {
  15959. PCI_PMCSR_BSE BridgeSupport;
  15960. UCHAR AsUCHAR;
  15961. } PMCSR_BSE;
  15962. //
  15963. // Optional read only 8 bit Data register. Contents controlled by
  15964. // DataSelect and DataScale in ControlStatus.
  15965. //
  15966. UCHAR Data;
  15967. } PCI_PM_CAPABILITY, *PPCI_PM_CAPABILITY;
  15968. //
  15969. // AGP Capability
  15970. //
  15971. typedef struct _PCI_AGP_CAPABILITY {
  15972. PCI_CAPABILITIES_HEADER Header;
  15973. USHORT Minor:4;
  15974. USHORT Major:4;
  15975. USHORT Rsvd1:8;
  15976. struct _PCI_AGP_STATUS {
  15977. ULONG Rate:3;
  15978. ULONG Rsvd1:1;
  15979. ULONG FastWrite:1;
  15980. ULONG FourGB:1;
  15981. ULONG Rsvd2:3;
  15982. ULONG SideBandAddressing:1; // SBA
  15983. ULONG Rsvd3:14;
  15984. ULONG RequestQueueDepthMaximum:8; // RQ
  15985. } AGPStatus;
  15986. struct _PCI_AGP_COMMAND {
  15987. ULONG Rate:3;
  15988. ULONG Rsvd1:1;
  15989. ULONG FastWriteEnable:1;
  15990. ULONG FourGBEnable:1;
  15991. ULONG Rsvd2:2;
  15992. ULONG AGPEnable:1;
  15993. ULONG SBAEnable:1;
  15994. ULONG Rsvd3:14;
  15995. ULONG RequestQueueDepth:8;
  15996. } AGPCommand;
  15997. } PCI_AGP_CAPABILITY, *PPCI_AGP_CAPABILITY;
  15998. #define PCI_AGP_RATE_1X 0x1
  15999. #define PCI_AGP_RATE_2X 0x2
  16000. #define PCI_AGP_RATE_4X 0x4
  16001. //
  16002. // MSI (Message Signalled Interrupts) Capability
  16003. //
  16004. typedef struct _PCI_MSI_CAPABILITY {
  16005. PCI_CAPABILITIES_HEADER Header;
  16006. struct _PCI_MSI_MESSAGE_CONTROL {
  16007. USHORT MSIEnable:1;
  16008. USHORT MultipleMessageCapable:3;
  16009. USHORT MultipleMessageEnable:3;
  16010. USHORT CapableOf64Bits:1;
  16011. USHORT Reserved:8;
  16012. } MessageControl;
  16013. union {
  16014. struct _PCI_MSI_MESSAGE_ADDRESS {
  16015. ULONG_PTR Reserved:2; // always zero, DWORD aligned address
  16016. ULONG_PTR Address:30;
  16017. } Register;
  16018. ULONG_PTR Raw;
  16019. } MessageAddress;
  16020. //
  16021. // The rest of the Capability structure differs depending on whether
  16022. // 32bit or 64bit addressing is being used.
  16023. //
  16024. // (The CapableOf64Bits bit above determines this)
  16025. //
  16026. union {
  16027. // For 64 bit devices
  16028. struct _PCI_MSI_64BIT_DATA {
  16029. ULONG MessageUpperAddress;
  16030. USHORT MessageData;
  16031. } Bit64;
  16032. // For 32 bit devices
  16033. struct _PCI_MSI_32BIT_DATA {
  16034. USHORT MessageData;
  16035. ULONG Unused;
  16036. } Bit32;
  16037. } Data;
  16038. } PCI_MSI_CAPABILITY, *PPCI_PCI_CAPABILITY;
  16039. // begin_wdm
  16040. //
  16041. // Base Class Code encodings for Base Class (from PCI spec rev 2.1).
  16042. //
  16043. #define PCI_CLASS_PRE_20 0x00
  16044. #define PCI_CLASS_MASS_STORAGE_CTLR 0x01
  16045. #define PCI_CLASS_NETWORK_CTLR 0x02
  16046. #define PCI_CLASS_DISPLAY_CTLR 0x03
  16047. #define PCI_CLASS_MULTIMEDIA_DEV 0x04
  16048. #define PCI_CLASS_MEMORY_CTLR 0x05
  16049. #define PCI_CLASS_BRIDGE_DEV 0x06
  16050. #define PCI_CLASS_SIMPLE_COMMS_CTLR 0x07
  16051. #define PCI_CLASS_BASE_SYSTEM_DEV 0x08
  16052. #define PCI_CLASS_INPUT_DEV 0x09
  16053. #define PCI_CLASS_DOCKING_STATION 0x0a
  16054. #define PCI_CLASS_PROCESSOR 0x0b
  16055. #define PCI_CLASS_SERIAL_BUS_CTLR 0x0c
  16056. #define PCI_CLASS_WIRELESS_CTLR 0x0d
  16057. #define PCI_CLASS_INTELLIGENT_IO_CTLR 0x0e
  16058. #define PCI_CLASS_SATELLITE_COMMS_CTLR 0x0f
  16059. #define PCI_CLASS_ENCRYPTION_DECRYPTION 0x10
  16060. #define PCI_CLASS_DATA_ACQ_SIGNAL_PROC 0x11
  16061. // 0d thru fe reserved
  16062. #define PCI_CLASS_NOT_DEFINED 0xff
  16063. //
  16064. // Sub Class Code encodings (PCI rev 2.1).
  16065. //
  16066. // Class 00 - PCI_CLASS_PRE_20
  16067. #define PCI_SUBCLASS_PRE_20_NON_VGA 0x00
  16068. #define PCI_SUBCLASS_PRE_20_VGA 0x01
  16069. // Class 01 - PCI_CLASS_MASS_STORAGE_CTLR
  16070. #define PCI_SUBCLASS_MSC_SCSI_BUS_CTLR 0x00
  16071. #define PCI_SUBCLASS_MSC_IDE_CTLR 0x01
  16072. #define PCI_SUBCLASS_MSC_FLOPPY_CTLR 0x02
  16073. #define PCI_SUBCLASS_MSC_IPI_CTLR 0x03
  16074. #define PCI_SUBCLASS_MSC_RAID_CTLR 0x04
  16075. #define PCI_SUBCLASS_MSC_OTHER 0x80
  16076. // Class 02 - PCI_CLASS_NETWORK_CTLR
  16077. #define PCI_SUBCLASS_NET_ETHERNET_CTLR 0x00
  16078. #define PCI_SUBCLASS_NET_TOKEN_RING_CTLR 0x01
  16079. #define PCI_SUBCLASS_NET_FDDI_CTLR 0x02
  16080. #define PCI_SUBCLASS_NET_ATM_CTLR 0x03
  16081. #define PCI_SUBCLASS_NET_ISDN_CTLR 0x04
  16082. #define PCI_SUBCLASS_NET_OTHER 0x80
  16083. // Class 03 - PCI_CLASS_DISPLAY_CTLR
  16084. // N.B. Sub Class 00 could be VGA or 8514 depending on Interface byte
  16085. #define PCI_SUBCLASS_VID_VGA_CTLR 0x00
  16086. #define PCI_SUBCLASS_VID_XGA_CTLR 0x01
  16087. #define PCI_SUBLCASS_VID_3D_CTLR 0x02
  16088. #define PCI_SUBCLASS_VID_OTHER 0x80
  16089. // Class 04 - PCI_CLASS_MULTIMEDIA_DEV
  16090. #define PCI_SUBCLASS_MM_VIDEO_DEV 0x00
  16091. #define PCI_SUBCLASS_MM_AUDIO_DEV 0x01
  16092. #define PCI_SUBCLASS_MM_TELEPHONY_DEV 0x02
  16093. #define PCI_SUBCLASS_MM_OTHER 0x80
  16094. // Class 05 - PCI_CLASS_MEMORY_CTLR
  16095. #define PCI_SUBCLASS_MEM_RAM 0x00
  16096. #define PCI_SUBCLASS_MEM_FLASH 0x01
  16097. #define PCI_SUBCLASS_MEM_OTHER 0x80
  16098. // Class 06 - PCI_CLASS_BRIDGE_DEV
  16099. #define PCI_SUBCLASS_BR_HOST 0x00
  16100. #define PCI_SUBCLASS_BR_ISA 0x01
  16101. #define PCI_SUBCLASS_BR_EISA 0x02
  16102. #define PCI_SUBCLASS_BR_MCA 0x03
  16103. #define PCI_SUBCLASS_BR_PCI_TO_PCI 0x04
  16104. #define PCI_SUBCLASS_BR_PCMCIA 0x05
  16105. #define PCI_SUBCLASS_BR_NUBUS 0x06
  16106. #define PCI_SUBCLASS_BR_CARDBUS 0x07
  16107. #define PCI_SUBCLASS_BR_RACEWAY 0x08
  16108. #define PCI_SUBCLASS_BR_OTHER 0x80
  16109. // Class 07 - PCI_CLASS_SIMPLE_COMMS_CTLR
  16110. // N.B. Sub Class 00 and 01 additional info in Interface byte
  16111. #define PCI_SUBCLASS_COM_SERIAL 0x00
  16112. #define PCI_SUBCLASS_COM_PARALLEL 0x01
  16113. #define PCI_SUBCLASS_COM_MULTIPORT 0x02
  16114. #define PCI_SUBCLASS_COM_MODEM 0x03
  16115. #define PCI_SUBCLASS_COM_OTHER 0x80
  16116. // Class 08 - PCI_CLASS_BASE_SYSTEM_DEV
  16117. // N.B. See Interface byte for additional info.
  16118. #define PCI_SUBCLASS_SYS_INTERRUPT_CTLR 0x00
  16119. #define PCI_SUBCLASS_SYS_DMA_CTLR 0x01
  16120. #define PCI_SUBCLASS_SYS_SYSTEM_TIMER 0x02
  16121. #define PCI_SUBCLASS_SYS_REAL_TIME_CLOCK 0x03
  16122. #define PCI_SUBCLASS_SYS_GEN_HOTPLUG_CTLR 0x04
  16123. #define PCI_SUBCLASS_SYS_OTHER 0x80
  16124. // Class 09 - PCI_CLASS_INPUT_DEV
  16125. #define PCI_SUBCLASS_INP_KEYBOARD 0x00
  16126. #define PCI_SUBCLASS_INP_DIGITIZER 0x01
  16127. #define PCI_SUBCLASS_INP_MOUSE 0x02
  16128. #define PCI_SUBCLASS_INP_SCANNER 0x03
  16129. #define PCI_SUBCLASS_INP_GAMEPORT 0x04
  16130. #define PCI_SUBCLASS_INP_OTHER 0x80
  16131. // Class 0a - PCI_CLASS_DOCKING_STATION
  16132. #define PCI_SUBCLASS_DOC_GENERIC 0x00
  16133. #define PCI_SUBCLASS_DOC_OTHER 0x80
  16134. // Class 0b - PCI_CLASS_PROCESSOR
  16135. #define PCI_SUBCLASS_PROC_386 0x00
  16136. #define PCI_SUBCLASS_PROC_486 0x01
  16137. #define PCI_SUBCLASS_PROC_PENTIUM 0x02
  16138. #define PCI_SUBCLASS_PROC_ALPHA 0x10
  16139. #define PCI_SUBCLASS_PROC_POWERPC 0x20
  16140. #define PCI_SUBCLASS_PROC_COPROCESSOR 0x40
  16141. // Class 0c - PCI_CLASS_SERIAL_BUS_CTLR
  16142. #define PCI_SUBCLASS_SB_IEEE1394 0x00
  16143. #define PCI_SUBCLASS_SB_ACCESS 0x01
  16144. #define PCI_SUBCLASS_SB_SSA 0x02
  16145. #define PCI_SUBCLASS_SB_USB 0x03
  16146. #define PCI_SUBCLASS_SB_FIBRE_CHANNEL 0x04
  16147. #define PCI_SUBCLASS_SB_SMBUS 0x05
  16148. // Class 0d - PCI_CLASS_WIRELESS_CTLR
  16149. #define PCI_SUBCLASS_WIRELESS_IRDA 0x00
  16150. #define PCI_SUBCLASS_WIRELESS_CON_IR 0x01
  16151. #define PCI_SUBCLASS_WIRELESS_RF 0x10
  16152. #define PCI_SUBCLASS_WIRELESS_OTHER 0x80
  16153. // Class 0e - PCI_CLASS_INTELLIGENT_IO_CTLR
  16154. #define PCI_SUBCLASS_INTIO_I2O 0x00
  16155. // Class 0f - PCI_CLASS_SATELLITE_CTLR
  16156. #define PCI_SUBCLASS_SAT_TV 0x01
  16157. #define PCI_SUBCLASS_SAT_AUDIO 0x02
  16158. #define PCI_SUBCLASS_SAT_VOICE 0x03
  16159. #define PCI_SUBCLASS_SAT_DATA 0x04
  16160. // Class 10 - PCI_CLASS_ENCRYPTION_DECRYPTION
  16161. #define PCI_SUBCLASS_CRYPTO_NET_COMP 0x00
  16162. #define PCI_SUBCLASS_CRYPTO_ENTERTAINMENT 0x10
  16163. #define PCI_SUBCLASS_CRYPTO_OTHER 0x80
  16164. // Class 11 - PCI_CLASS_DATA_ACQ_SIGNAL_PROC
  16165. #define PCI_SUBCLASS_DASP_DPIO 0x00
  16166. #define PCI_SUBCLASS_DASP_OTHER 0x80
  16167. // end_ntndis
  16168. //
  16169. // Bit encodes for PCI_COMMON_CONFIG.u.type0.BaseAddresses
  16170. //
  16171. #define PCI_ADDRESS_IO_SPACE 0x00000001 // (ro)
  16172. #define PCI_ADDRESS_MEMORY_TYPE_MASK 0x00000006 // (ro)
  16173. #define PCI_ADDRESS_MEMORY_PREFETCHABLE 0x00000008 // (ro)
  16174. #define PCI_ADDRESS_IO_ADDRESS_MASK 0xfffffffc
  16175. #define PCI_ADDRESS_MEMORY_ADDRESS_MASK 0xfffffff0
  16176. #define PCI_ADDRESS_ROM_ADDRESS_MASK 0xfffff800
  16177. #define PCI_TYPE_32BIT 0
  16178. #define PCI_TYPE_20BIT 2
  16179. #define PCI_TYPE_64BIT 4
  16180. //
  16181. // Bit encodes for PCI_COMMON_CONFIG.u.type0.ROMBaseAddresses
  16182. //
  16183. #define PCI_ROMADDRESS_ENABLED 0x00000001
  16184. //
  16185. // Reference notes for PCI configuration fields:
  16186. //
  16187. // ro these field are read only. changes to these fields are ignored
  16188. //
  16189. // ro+ these field are intended to be read only and should be initialized
  16190. // by the system to their proper values. However, driver may change
  16191. // these settings.
  16192. //
  16193. // ---
  16194. //
  16195. // All resources comsumed by a PCI device start as unitialized
  16196. // under NT. An uninitialized memory or I/O base address can be
  16197. // determined by checking it's corrisponding enabled bit in the
  16198. // PCI_COMMON_CONFIG.Command value. An InterruptLine is unitialized
  16199. // if it contains the value of -1.
  16200. //
  16201. // end_wdm end_ntminiport
  16202. //
  16203. // Portable portion of HAL & HAL bus extender definitions for BUSHANDLER
  16204. // BusData for installed PCI buses.
  16205. //
  16206. typedef VOID
  16207. (*PciPin2Line) (
  16208. IN struct _BUS_HANDLER *BusHandler,
  16209. IN struct _BUS_HANDLER *RootHandler,
  16210. IN PCI_SLOT_NUMBER SlotNumber,
  16211. IN PPCI_COMMON_CONFIG PciData
  16212. );
  16213. typedef VOID
  16214. (*PciLine2Pin) (
  16215. IN struct _BUS_HANDLER *BusHandler,
  16216. IN struct _BUS_HANDLER *RootHandler,
  16217. IN PCI_SLOT_NUMBER SlotNumber,
  16218. IN PPCI_COMMON_CONFIG PciNewData,
  16219. IN PPCI_COMMON_CONFIG PciOldData
  16220. );
  16221. typedef VOID
  16222. (*PciReadWriteConfig) (
  16223. IN struct _BUS_HANDLER *BusHandler,
  16224. IN PCI_SLOT_NUMBER Slot,
  16225. IN PVOID Buffer,
  16226. IN ULONG Offset,
  16227. IN ULONG Length
  16228. );
  16229. #define PCI_DATA_TAG ' ICP'
  16230. #define PCI_DATA_VERSION 1
  16231. typedef struct _PCIBUSDATA {
  16232. ULONG Tag;
  16233. ULONG Version;
  16234. PciReadWriteConfig ReadConfig;
  16235. PciReadWriteConfig WriteConfig;
  16236. PciPin2Line Pin2Line;
  16237. PciLine2Pin Line2Pin;
  16238. PCI_SLOT_NUMBER ParentSlot;
  16239. PVOID Reserved[4];
  16240. } PCIBUSDATA, *PPCIBUSDATA;
  16241. typedef ULONG (*PCI_READ_WRITE_CONFIG)(
  16242. IN PVOID Context,
  16243. IN UCHAR BusOffset,
  16244. IN ULONG Slot,
  16245. IN PVOID Buffer,
  16246. IN ULONG Offset,
  16247. IN ULONG Length
  16248. );
  16249. typedef VOID (*PCI_PIN_TO_LINE)(
  16250. IN PVOID Context,
  16251. IN PPCI_COMMON_CONFIG PciData
  16252. );
  16253. typedef VOID (*PCI_LINE_TO_PIN)(
  16254. IN PVOID Context,
  16255. IN PPCI_COMMON_CONFIG PciNewData,
  16256. IN PPCI_COMMON_CONFIG PciOldData
  16257. );
  16258. typedef struct _PCI_BUS_INTERFACE_STANDARD {
  16259. //
  16260. // generic interface header
  16261. //
  16262. USHORT Size;
  16263. USHORT Version;
  16264. PVOID Context;
  16265. PINTERFACE_REFERENCE InterfaceReference;
  16266. PINTERFACE_DEREFERENCE InterfaceDereference;
  16267. //
  16268. // standard PCI bus interfaces
  16269. //
  16270. PCI_READ_WRITE_CONFIG ReadConfig;
  16271. PCI_READ_WRITE_CONFIG WriteConfig;
  16272. PCI_PIN_TO_LINE PinToLine;
  16273. PCI_LINE_TO_PIN LineToPin;
  16274. } PCI_BUS_INTERFACE_STANDARD, *PPCI_BUS_INTERFACE_STANDARD;
  16275. #define PCI_BUS_INTERFACE_STANDARD_VERSION 1
  16276. // begin_wdm
  16277. #define PCI_DEVICE_PRESENT_INTERFACE_VERSION 1
  16278. //
  16279. // Flags for PCI_DEVICE_PRESENCE_PARAMETERS
  16280. //
  16281. #define PCI_USE_SUBSYSTEM_IDS 0x00000001
  16282. #define PCI_USE_REVISION 0x00000002
  16283. // The following flags are only valid for IsDevicePresentEx
  16284. #define PCI_USE_VENDEV_IDS 0x00000004
  16285. #define PCI_USE_CLASS_SUBCLASS 0x00000008
  16286. #define PCI_USE_PROGIF 0x00000010
  16287. #define PCI_USE_LOCAL_BUS 0x00000020
  16288. #define PCI_USE_LOCAL_DEVICE 0x00000040
  16289. //
  16290. // Search parameters structure for IsDevicePresentEx
  16291. //
  16292. typedef struct _PCI_DEVICE_PRESENCE_PARAMETERS {
  16293. ULONG Size;
  16294. ULONG Flags;
  16295. USHORT VendorID;
  16296. USHORT DeviceID;
  16297. UCHAR RevisionID;
  16298. USHORT SubVendorID;
  16299. USHORT SubSystemID;
  16300. UCHAR BaseClass;
  16301. UCHAR SubClass;
  16302. UCHAR ProgIf;
  16303. } PCI_DEVICE_PRESENCE_PARAMETERS, *PPCI_DEVICE_PRESENCE_PARAMETERS;
  16304. typedef
  16305. BOOLEAN
  16306. (*PPCI_IS_DEVICE_PRESENT) (
  16307. IN USHORT VendorID,
  16308. IN USHORT DeviceID,
  16309. IN UCHAR RevisionID,
  16310. IN USHORT SubVendorID,
  16311. IN USHORT SubSystemID,
  16312. IN ULONG Flags
  16313. );
  16314. typedef
  16315. BOOLEAN
  16316. (*PPCI_IS_DEVICE_PRESENT_EX) (
  16317. IN PVOID Context,
  16318. IN PPCI_DEVICE_PRESENCE_PARAMETERS Parameters
  16319. );
  16320. typedef struct _PCI_DEVICE_PRESENT_INTERFACE {
  16321. //
  16322. // generic interface header
  16323. //
  16324. USHORT Size;
  16325. USHORT Version;
  16326. PVOID Context;
  16327. PINTERFACE_REFERENCE InterfaceReference;
  16328. PINTERFACE_DEREFERENCE InterfaceDereference;
  16329. //
  16330. // pci device info
  16331. //
  16332. PPCI_IS_DEVICE_PRESENT IsDevicePresent;
  16333. PPCI_IS_DEVICE_PRESENT_EX IsDevicePresentEx;
  16334. } PCI_DEVICE_PRESENT_INTERFACE, *PPCI_DEVICE_PRESENT_INTERFACE;
  16335. //
  16336. // Normal uncompressed Copy and Mdl Apis
  16337. //
  16338. NTKERNELAPI
  16339. BOOLEAN
  16340. FsRtlCopyRead (
  16341. IN PFILE_OBJECT FileObject,
  16342. IN PLARGE_INTEGER FileOffset,
  16343. IN ULONG Length,
  16344. IN BOOLEAN Wait,
  16345. IN ULONG LockKey,
  16346. OUT PVOID Buffer,
  16347. OUT PIO_STATUS_BLOCK IoStatus,
  16348. IN PDEVICE_OBJECT DeviceObject
  16349. );
  16350. NTKERNELAPI
  16351. BOOLEAN
  16352. FsRtlCopyWrite (
  16353. IN PFILE_OBJECT FileObject,
  16354. IN PLARGE_INTEGER FileOffset,
  16355. IN ULONG Length,
  16356. IN BOOLEAN Wait,
  16357. IN ULONG LockKey,
  16358. IN PVOID Buffer,
  16359. OUT PIO_STATUS_BLOCK IoStatus,
  16360. IN PDEVICE_OBJECT DeviceObject
  16361. );
  16362. // end_ntifs
  16363. NTKERNELAPI
  16364. BOOLEAN
  16365. FsRtlMdlRead (
  16366. IN PFILE_OBJECT FileObject,
  16367. IN PLARGE_INTEGER FileOffset,
  16368. IN ULONG Length,
  16369. IN ULONG LockKey,
  16370. OUT PMDL *MdlChain,
  16371. OUT PIO_STATUS_BLOCK IoStatus
  16372. );
  16373. BOOLEAN
  16374. FsRtlMdlReadComplete (
  16375. IN PFILE_OBJECT FileObject,
  16376. IN PMDL MdlChain
  16377. );
  16378. #define LEGAL_ANSI_CHARACTER_ARRAY (*FsRtlLegalAnsiCharacterArray)
  16379. #define NLS_OEM_LEAD_BYTE_INFO (*NlsOemLeadByteInfo)
  16380. extern UCHAR const* const LEGAL_ANSI_CHARACTER_ARRAY;
  16381. extern PUSHORT NLS_OEM_LEAD_BYTE_INFO; // Lead byte info. for ACP
  16382. //
  16383. // These following bit values are set in the FsRtlLegalDbcsCharacterArray
  16384. //
  16385. #define FSRTL_FAT_LEGAL 0x01
  16386. #define FSRTL_HPFS_LEGAL 0x02
  16387. #define FSRTL_NTFS_LEGAL 0x04
  16388. #define FSRTL_WILD_CHARACTER 0x08
  16389. #define FSRTL_OLE_LEGAL 0x10
  16390. #define FSRTL_NTFS_STREAM_LEGAL (FSRTL_NTFS_LEGAL | FSRTL_OLE_LEGAL)
  16391. //
  16392. // The following macro is used to determine if an Ansi character is wild.
  16393. //
  16394. #define FsRtlIsAnsiCharacterWild(C) ( \
  16395. FsRtlTestAnsiCharacter((C), FALSE, FALSE, FSRTL_WILD_CHARACTER) \
  16396. )
  16397. //
  16398. // The following macro is used to determine if an Ansi character is Fat legal.
  16399. //
  16400. #define FsRtlIsAnsiCharacterLegalFat(C,WILD_OK) ( \
  16401. FsRtlTestAnsiCharacter((C), TRUE, (WILD_OK), FSRTL_FAT_LEGAL) \
  16402. )
  16403. //
  16404. // The following macro is used to determine if an Ansi character is Hpfs legal.
  16405. //
  16406. #define FsRtlIsAnsiCharacterLegalHpfs(C,WILD_OK) ( \
  16407. FsRtlTestAnsiCharacter((C), TRUE, (WILD_OK), FSRTL_HPFS_LEGAL) \
  16408. )
  16409. //
  16410. // The following macro is used to determine if an Ansi character is Ntfs legal.
  16411. //
  16412. #define FsRtlIsAnsiCharacterLegalNtfs(C,WILD_OK) ( \
  16413. FsRtlTestAnsiCharacter((C), TRUE, (WILD_OK), FSRTL_NTFS_LEGAL) \
  16414. )
  16415. //
  16416. // The following macro is used to determine if an Ansi character is
  16417. // legal in an Ntfs stream name
  16418. //
  16419. #define FsRtlIsAnsiCharacterLegalNtfsStream(C,WILD_OK) ( \
  16420. FsRtlTestAnsiCharacter((C), TRUE, (WILD_OK), FSRTL_NTFS_STREAM_LEGAL) \
  16421. )
  16422. //
  16423. // The following macro is used to determine if an Ansi character is legal,
  16424. // according to the caller's specification.
  16425. //
  16426. #define FsRtlIsAnsiCharacterLegal(C,FLAGS) ( \
  16427. FsRtlTestAnsiCharacter((C), TRUE, FALSE, (FLAGS)) \
  16428. )
  16429. //
  16430. // The following macro is used to test attributes of an Ansi character,
  16431. // according to the caller's specified flags.
  16432. //
  16433. #define FsRtlTestAnsiCharacter(C, DEFAULT_RET, WILD_OK, FLAGS) ( \
  16434. ((SCHAR)(C) < 0) ? DEFAULT_RET : \
  16435. FlagOn( LEGAL_ANSI_CHARACTER_ARRAY[(C)], \
  16436. (FLAGS) | \
  16437. ((WILD_OK) ? FSRTL_WILD_CHARACTER : 0) ) \
  16438. )
  16439. //
  16440. // The following two macros use global data defined in ntos\rtl\nlsdata.c
  16441. //
  16442. // BOOLEAN
  16443. // FsRtlIsLeadDbcsCharacter (
  16444. // IN UCHAR DbcsCharacter
  16445. // );
  16446. //
  16447. // /*++
  16448. //
  16449. // Routine Description:
  16450. //
  16451. // This routine takes the first bytes of a Dbcs character and
  16452. // returns whether it is a lead byte in the system code page.
  16453. //
  16454. // Arguments:
  16455. //
  16456. // DbcsCharacter - Supplies the input character being examined
  16457. //
  16458. // Return Value:
  16459. //
  16460. // BOOLEAN - TRUE if the input character is a dbcs lead and
  16461. // FALSE otherwise
  16462. //
  16463. // --*/
  16464. //
  16465. //
  16466. #define FsRtlIsLeadDbcsCharacter(DBCS_CHAR) ( \
  16467. (BOOLEAN)((UCHAR)(DBCS_CHAR) < 0x80 ? FALSE : \
  16468. (NLS_MB_CODE_PAGE_TAG && \
  16469. (NLS_OEM_LEAD_BYTE_INFO[(UCHAR)(DBCS_CHAR)] != 0))) \
  16470. )
  16471. NTKERNELAPI
  16472. VOID
  16473. FsRtlDissectDbcs (
  16474. IN ANSI_STRING InputName,
  16475. OUT PANSI_STRING FirstPart,
  16476. OUT PANSI_STRING RemainingPart
  16477. );
  16478. NTKERNELAPI
  16479. BOOLEAN
  16480. FsRtlDoesDbcsContainWildCards (
  16481. IN PANSI_STRING Name
  16482. );
  16483. NTKERNELAPI
  16484. BOOLEAN
  16485. FsRtlIsDbcsInExpression (
  16486. IN PANSI_STRING Expression,
  16487. IN PANSI_STRING Name
  16488. );
  16489. NTKERNELAPI
  16490. BOOLEAN
  16491. FsRtlIsFatDbcsLegal (
  16492. IN ANSI_STRING DbcsName,
  16493. IN BOOLEAN WildCardsPermissible,
  16494. IN BOOLEAN PathNamePermissible,
  16495. IN BOOLEAN LeadingBackslashPermissible
  16496. );
  16497. NTKERNELAPI
  16498. NTSTATUS
  16499. LpcRequestPort(
  16500. IN PVOID PortAddress,
  16501. IN PPORT_MESSAGE RequestMessage
  16502. );
  16503. NTSTATUS
  16504. LpcRequestWaitReplyPort(
  16505. IN PVOID PortAddress,
  16506. IN PPORT_MESSAGE RequestMessage,
  16507. OUT PPORT_MESSAGE ReplyMessage
  16508. );
  16509. NTSTATUS
  16510. LpcRequestWaitReplyPortEx (
  16511. IN PVOID PortAddress,
  16512. IN PPORT_MESSAGE RequestMessage,
  16513. OUT PPORT_MESSAGE ReplyMessage
  16514. );
  16515. NTSTATUS
  16516. LpcDisconnectPort (
  16517. IN PVOID Port
  16518. );
  16519. extern POBJECT_TYPE *ExEventPairObjectType;
  16520. extern POBJECT_TYPE *IoFileObjectType;
  16521. extern POBJECT_TYPE *IoDriverObjectType;
  16522. extern POBJECT_TYPE *PsProcessType;
  16523. extern POBJECT_TYPE *PsThreadType;
  16524. extern POBJECT_TYPE *PsJobType;
  16525. extern POBJECT_TYPE *LpcPortObjectType;
  16526. extern POBJECT_TYPE *LpcWaitablePortObjectType;
  16527. extern POBJECT_TYPE MmSectionObjectType;
  16528. #ifdef __cplusplus
  16529. } // extern "C"
  16530. #endif
  16531. #endif // _NTOSP_