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.

22509 lines
521 KiB

  1. /*++ BUILD Version: 0120 // Increment this if a change has global effects
  2. Copyright (c) Microsoft Corporation. All rights reserved.
  3. Module Name:
  4. ntddk.h
  5. Abstract:
  6. This module defines the NT types, constants, and functions that are
  7. exposed to device drivers.
  8. Revision History:
  9. --*/
  10. #ifndef _NTDDK_
  11. #define _NTDDK_
  12. #ifndef RC_INVOKED
  13. #if _MSC_VER < 1300
  14. #error Compiler version not supported by Windows DDK
  15. #endif
  16. #endif // RC_INVOKED
  17. #define NT_INCLUDED
  18. #define _CTYPE_DISABLE_MACROS
  19. #include <excpt.h>
  20. #include <ntdef.h>
  21. #include <ntstatus.h>
  22. #include <bugcodes.h>
  23. #include <ntiologc.h>
  24. //
  25. // Kernel Mutex Level Numbers (must be globallly assigned within executive)
  26. // The third token in the name is the sub-component name that defines and
  27. // uses the level number.
  28. //
  29. //
  30. // Used by Vdm for protecting io simulation structures
  31. //
  32. #define MUTEX_LEVEL_VDM_IO (ULONG)0x00000001
  33. #define MUTEX_LEVEL_EX_PROFILE (ULONG)0x00000040
  34. //
  35. // The LANMAN Redirector uses the file system major function, but defines
  36. // it's own mutex levels. We can do this safely because we know that the
  37. // local filesystem will never call the remote filesystem and vice versa.
  38. //
  39. #define MUTEX_LEVEL_RDR_FILESYS_DATABASE (ULONG)0x10100000
  40. #define MUTEX_LEVEL_RDR_FILESYS_SECURITY (ULONG)0x10100001
  41. //
  42. // File System levels.
  43. //
  44. #define MUTEX_LEVEL_FILESYSTEM_RAW_VCB (ULONG)0x11000006
  45. //
  46. // In the NT STREAMS environment, a mutex is used to serialize open, close
  47. // and Scheduler threads executing in a subsystem-parallelized stack.
  48. //
  49. #define MUTEX_LEVEL_STREAMS_SUBSYS (ULONG)0x11001001
  50. //
  51. // Mutex level used by LDT support on x86
  52. //
  53. #define MUTEX_LEVEL_PS_LDT (ULONG)0x1F000000
  54. //
  55. // Define types that are not exported.
  56. //
  57. typedef struct _BUS_HANDLER *PBUS_HANDLER;
  58. typedef struct _CALLBACK_OBJECT *PCALLBACK_OBJECT;
  59. typedef struct _DEVICE_HANDLER_OBJECT *PDEVICE_HANDLER_OBJECT;
  60. typedef struct _EPROCESS *PEPROCESS;
  61. typedef struct _ETHREAD *PETHREAD;
  62. typedef struct _IO_TIMER *PIO_TIMER;
  63. typedef struct _KINTERRUPT *PKINTERRUPT;
  64. typedef struct _KTHREAD *PKTHREAD, *PRKTHREAD;
  65. typedef struct _OBJECT_TYPE *POBJECT_TYPE;
  66. typedef struct _PEB *PPEB;
  67. #if defined(_M_AMD64)
  68. PKTHREAD
  69. NTAPI
  70. KeGetCurrentThread(
  71. VOID
  72. );
  73. #endif // defined(_M_AMD64)
  74. #if defined(_M_IX86)
  75. PKTHREAD NTAPI KeGetCurrentThread();
  76. #endif // defined(_M_IX86)
  77. #if defined(_M_IA64)
  78. //
  79. // Define Address of Processor Control Registers.
  80. //
  81. #define KIPCR ((ULONG_PTR)(KADDRESS_BASE + 0xffff0000)) // kernel address of first PCR
  82. //
  83. // Define Pointer to Processor Control Registers.
  84. //
  85. #define PCR ((volatile KPCR * const)KIPCR)
  86. PKTHREAD NTAPI KeGetCurrentThread();
  87. #endif // defined(_M_IA64)
  88. #define PsGetCurrentProcess() IoGetCurrentProcess()
  89. #define PsGetCurrentThread() ((PETHREAD) (KeGetCurrentThread()))
  90. extern NTSYSAPI CCHAR KeNumberProcessors;
  91. #include <mce.h>
  92. #ifndef FAR
  93. #define FAR
  94. #endif
  95. //
  96. // Define alignment macros to align structure sizes and pointers up and down.
  97. //
  98. #define ALIGN_DOWN(length, type) \
  99. ((ULONG)(length) & ~(sizeof(type) - 1))
  100. #define ALIGN_UP(length, type) \
  101. (ALIGN_DOWN(((ULONG)(length) + sizeof(type) - 1), type))
  102. #define ALIGN_DOWN_POINTER(address, type) \
  103. ((PVOID)((ULONG_PTR)(address) & ~((ULONG_PTR)sizeof(type) - 1)))
  104. #define ALIGN_UP_POINTER(address, type) \
  105. (ALIGN_DOWN_POINTER(((ULONG_PTR)(address) + sizeof(type) - 1), type))
  106. #define POOL_TAGGING 1
  107. #ifndef DBG
  108. #define DBG 0
  109. #endif
  110. #if DBG
  111. #define IF_DEBUG if (TRUE)
  112. #else
  113. #define IF_DEBUG if (FALSE)
  114. #endif
  115. #if DEVL
  116. extern ULONG NtGlobalFlag;
  117. #define IF_NTOS_DEBUG( FlagName ) \
  118. if (NtGlobalFlag & (FLG_ ## FlagName))
  119. #else
  120. #define IF_NTOS_DEBUG( FlagName ) if (FALSE)
  121. #endif
  122. //
  123. // Kernel definitions that need to be here for forward reference purposes
  124. //
  125. // begin_ntndis
  126. //
  127. // Processor modes.
  128. //
  129. typedef CCHAR KPROCESSOR_MODE;
  130. typedef enum _MODE {
  131. KernelMode,
  132. UserMode,
  133. MaximumMode
  134. } MODE;
  135. // end_ntndis
  136. //
  137. // APC function types
  138. //
  139. //
  140. // Put in an empty definition for the KAPC so that the
  141. // routines can reference it before it is declared.
  142. //
  143. struct _KAPC;
  144. typedef
  145. VOID
  146. (*PKNORMAL_ROUTINE) (
  147. IN PVOID NormalContext,
  148. IN PVOID SystemArgument1,
  149. IN PVOID SystemArgument2
  150. );
  151. typedef
  152. VOID
  153. (*PKKERNEL_ROUTINE) (
  154. IN struct _KAPC *Apc,
  155. IN OUT PKNORMAL_ROUTINE *NormalRoutine,
  156. IN OUT PVOID *NormalContext,
  157. IN OUT PVOID *SystemArgument1,
  158. IN OUT PVOID *SystemArgument2
  159. );
  160. typedef
  161. VOID
  162. (*PKRUNDOWN_ROUTINE) (
  163. IN struct _KAPC *Apc
  164. );
  165. typedef
  166. BOOLEAN
  167. (*PKSYNCHRONIZE_ROUTINE) (
  168. IN PVOID SynchronizeContext
  169. );
  170. typedef
  171. BOOLEAN
  172. (*PKTRANSFER_ROUTINE) (
  173. VOID
  174. );
  175. //
  176. //
  177. // Asynchronous Procedure Call (APC) object
  178. //
  179. //
  180. typedef struct _KAPC {
  181. CSHORT Type;
  182. CSHORT Size;
  183. ULONG Spare0;
  184. struct _KTHREAD *Thread;
  185. LIST_ENTRY ApcListEntry;
  186. PKKERNEL_ROUTINE KernelRoutine;
  187. PKRUNDOWN_ROUTINE RundownRoutine;
  188. PKNORMAL_ROUTINE NormalRoutine;
  189. PVOID NormalContext;
  190. //
  191. // N.B. The following two members MUST be together.
  192. //
  193. PVOID SystemArgument1;
  194. PVOID SystemArgument2;
  195. CCHAR ApcStateIndex;
  196. KPROCESSOR_MODE ApcMode;
  197. BOOLEAN Inserted;
  198. } KAPC, *PKAPC, *RESTRICTED_POINTER PRKAPC;
  199. // begin_ntndis
  200. //
  201. // DPC routine
  202. //
  203. struct _KDPC;
  204. typedef
  205. VOID
  206. (*PKDEFERRED_ROUTINE) (
  207. IN struct _KDPC *Dpc,
  208. IN PVOID DeferredContext,
  209. IN PVOID SystemArgument1,
  210. IN PVOID SystemArgument2
  211. );
  212. //
  213. // Define DPC importance.
  214. //
  215. // LowImportance - Queue DPC at end of target DPC queue.
  216. // MediumImportance - Queue DPC at end of target DPC queue.
  217. // HighImportance - Queue DPC at front of target DPC DPC queue.
  218. //
  219. // If there is currently a DPC active on the target processor, or a DPC
  220. // interrupt has already been requested on the target processor when a
  221. // DPC is queued, then no further action is necessary. The DPC will be
  222. // executed on the target processor when its queue entry is processed.
  223. //
  224. // If there is not a DPC active on the target processor and a DPC interrupt
  225. // has not been requested on the target processor, then the exact treatment
  226. // of the DPC is dependent on whether the host system is a UP system or an
  227. // MP system.
  228. //
  229. // UP system.
  230. //
  231. // If the DPC is of medium or high importance, the current DPC queue depth
  232. // is greater than the maximum target depth, or current DPC request rate is
  233. // less the minimum target rate, then a DPC interrupt is requested on the
  234. // host processor and the DPC will be processed when the interrupt occurs.
  235. // Otherwise, no DPC interupt is requested and the DPC execution will be
  236. // delayed until the DPC queue depth is greater that the target depth or the
  237. // minimum DPC rate is less than the target rate.
  238. //
  239. // MP system.
  240. //
  241. // If the DPC is being queued to another processor and the depth of the DPC
  242. // queue on the target processor is greater than the maximum target depth or
  243. // the DPC is of high importance, then a DPC interrupt is requested on the
  244. // target processor and the DPC will be processed when the interrupt occurs.
  245. // Otherwise, the DPC execution will be delayed on the target processor until
  246. // the DPC queue depth on the target processor is greater that the maximum
  247. // target depth or the minimum DPC rate on the target processor is less than
  248. // the target mimimum rate.
  249. //
  250. // If the DPC is being queued to the current processor and the DPC is not of
  251. // low importance, the current DPC queue depth is greater than the maximum
  252. // target depth, or the minimum DPC rate is less than the minimum target rate,
  253. // then a DPC interrupt is request on the current processor and the DPV will
  254. // be processed whne the interrupt occurs. Otherwise, no DPC interupt is
  255. // requested and the DPC execution will be delayed until the DPC queue depth
  256. // is greater that the target depth or the minimum DPC rate is less than the
  257. // target rate.
  258. //
  259. typedef enum _KDPC_IMPORTANCE {
  260. LowImportance,
  261. MediumImportance,
  262. HighImportance
  263. } KDPC_IMPORTANCE;
  264. //
  265. // Deferred Procedure Call (DPC) object
  266. //
  267. typedef struct _KDPC {
  268. CSHORT Type;
  269. UCHAR Number;
  270. UCHAR Importance;
  271. LIST_ENTRY DpcListEntry;
  272. PKDEFERRED_ROUTINE DeferredRoutine;
  273. PVOID DeferredContext;
  274. PVOID SystemArgument1;
  275. PVOID SystemArgument2;
  276. PULONG_PTR Lock;
  277. } KDPC, *PKDPC, *RESTRICTED_POINTER PRKDPC;
  278. //
  279. // Interprocessor interrupt worker routine function prototype.
  280. //
  281. typedef PVOID PKIPI_CONTEXT;
  282. typedef
  283. VOID
  284. (*PKIPI_WORKER)(
  285. IN PKIPI_CONTEXT PacketContext,
  286. IN PVOID Parameter1,
  287. IN PVOID Parameter2,
  288. IN PVOID Parameter3
  289. );
  290. //
  291. // Define interprocessor interrupt performance counters.
  292. //
  293. typedef struct _KIPI_COUNTS {
  294. ULONG Freeze;
  295. ULONG Packet;
  296. ULONG DPC;
  297. ULONG APC;
  298. ULONG FlushSingleTb;
  299. ULONG FlushMultipleTb;
  300. ULONG FlushEntireTb;
  301. ULONG GenericCall;
  302. ULONG ChangeColor;
  303. ULONG SweepDcache;
  304. ULONG SweepIcache;
  305. ULONG SweepIcacheRange;
  306. ULONG FlushIoBuffers;
  307. ULONG GratuitousDPC;
  308. } KIPI_COUNTS, *PKIPI_COUNTS;
  309. #if defined(NT_UP)
  310. #define HOT_STATISTIC(a) a
  311. #else
  312. #define HOT_STATISTIC(a) (KeGetCurrentPrcb()->a)
  313. #endif
  314. //
  315. // I/O system definitions.
  316. //
  317. // Define a Memory Descriptor List (MDL)
  318. //
  319. // An MDL describes pages in a virtual buffer in terms of physical pages. The
  320. // pages associated with the buffer are described in an array that is allocated
  321. // just after the MDL header structure itself. In a future compiler this will
  322. // be placed at:
  323. //
  324. // ULONG Pages[];
  325. //
  326. // Until this declaration is permitted, however, one simply calculates the
  327. // base of the array by adding one to the base MDL pointer:
  328. //
  329. // Pages = (PULONG) (Mdl + 1);
  330. //
  331. // Notice that while in the context of the subject thread, the base virtual
  332. // address of a buffer mapped by an MDL may be referenced using the following:
  333. //
  334. // Mdl->StartVa | Mdl->ByteOffset
  335. //
  336. typedef struct _MDL {
  337. struct _MDL *Next;
  338. CSHORT Size;
  339. CSHORT MdlFlags;
  340. struct _EPROCESS *Process;
  341. PVOID MappedSystemVa;
  342. PVOID StartVa;
  343. ULONG ByteCount;
  344. ULONG ByteOffset;
  345. } MDL, *PMDL;
  346. #define MDL_MAPPED_TO_SYSTEM_VA 0x0001
  347. #define MDL_PAGES_LOCKED 0x0002
  348. #define MDL_SOURCE_IS_NONPAGED_POOL 0x0004
  349. #define MDL_ALLOCATED_FIXED_SIZE 0x0008
  350. #define MDL_PARTIAL 0x0010
  351. #define MDL_PARTIAL_HAS_BEEN_MAPPED 0x0020
  352. #define MDL_IO_PAGE_READ 0x0040
  353. #define MDL_WRITE_OPERATION 0x0080
  354. #define MDL_PARENT_MAPPED_SYSTEM_VA 0x0100
  355. #define MDL_FREE_EXTRA_PTES 0x0200
  356. #define MDL_IO_SPACE 0x0800
  357. #define MDL_NETWORK_HEADER 0x1000
  358. #define MDL_MAPPING_CAN_FAIL 0x2000
  359. #define MDL_ALLOCATED_MUST_SUCCEED 0x4000
  360. #define MDL_MAPPING_FLAGS (MDL_MAPPED_TO_SYSTEM_VA | \
  361. MDL_PAGES_LOCKED | \
  362. MDL_SOURCE_IS_NONPAGED_POOL | \
  363. MDL_PARTIAL_HAS_BEEN_MAPPED | \
  364. MDL_PARENT_MAPPED_SYSTEM_VA | \
  365. MDL_SYSTEM_VA | \
  366. MDL_IO_SPACE )
  367. // end_ntndis
  368. //
  369. // switch to DBG when appropriate
  370. //
  371. #if DBG
  372. #define PAGED_CODE() \
  373. { if (KeGetCurrentIrql() > APC_LEVEL) { \
  374. KdPrint(( "EX: Pageable code called at IRQL %d\n", KeGetCurrentIrql() )); \
  375. ASSERT(FALSE); \
  376. } \
  377. }
  378. #else
  379. #define PAGED_CODE() NOP_FUNCTION;
  380. #endif
  381. #define NTKERNELAPI DECLSPEC_IMPORT
  382. #if !defined(_NTHAL_) && !defined(_BLDR_)
  383. #define NTHALAPI DECLSPEC_IMPORT // wdm ntndis ntifs ntosp
  384. #else
  385. #define NTHALAPI // nthal
  386. #endif
  387. //
  388. // Common dispatcher object header
  389. //
  390. // N.B. The size field contains the number of dwords in the structure.
  391. //
  392. typedef struct _DISPATCHER_HEADER {
  393. UCHAR Type;
  394. UCHAR Absolute;
  395. UCHAR Size;
  396. UCHAR Inserted;
  397. LONG SignalState;
  398. LIST_ENTRY WaitListHead;
  399. } DISPATCHER_HEADER;
  400. //
  401. // Event object
  402. //
  403. typedef struct _KEVENT {
  404. DISPATCHER_HEADER Header;
  405. } KEVENT, *PKEVENT, *RESTRICTED_POINTER PRKEVENT;
  406. //
  407. // Timer object
  408. //
  409. typedef struct _KTIMER {
  410. DISPATCHER_HEADER Header;
  411. ULARGE_INTEGER DueTime;
  412. LIST_ENTRY TimerListEntry;
  413. struct _KDPC *Dpc;
  414. LONG Period;
  415. } KTIMER, *PKTIMER, *RESTRICTED_POINTER PRKTIMER;
  416. #ifdef _X86_
  417. //
  418. // Disable these two pragmas that evaluate to "sti" "cli" on x86 so that driver
  419. // writers to not leave them inadvertantly in their code.
  420. //
  421. #if !defined(MIDL_PASS)
  422. #if !defined(RC_INVOKED)
  423. #if _MSC_VER >= 1200
  424. #pragma warning(push)
  425. #endif
  426. #pragma warning(disable:4164) // disable C4164 warning so that apps that
  427. // build with /Od don't get weird errors !
  428. #ifdef _M_IX86
  429. #pragma function(_enable)
  430. #pragma function(_disable)
  431. #endif
  432. #if _MSC_VER >= 1200
  433. #pragma warning(pop)
  434. #else
  435. #pragma warning(default:4164) // reenable C4164 warning
  436. #endif
  437. #endif
  438. #endif
  439. //
  440. // Size of kernel mode stack.
  441. //
  442. #define KERNEL_STACK_SIZE 12288
  443. //
  444. // Define size of large kernel mode stack for callbacks.
  445. //
  446. #define KERNEL_LARGE_STACK_SIZE 61440
  447. //
  448. // Define number of pages to initialize in a large kernel stack.
  449. //
  450. #define KERNEL_LARGE_STACK_COMMIT 12288
  451. #ifdef _X86_
  452. //
  453. // Define the size of the 80387 save area, which is in the context frame.
  454. //
  455. #define SIZE_OF_80387_REGISTERS 80
  456. //
  457. // The following flags control the contents of the CONTEXT structure.
  458. //
  459. #if !defined(RC_INVOKED)
  460. #define CONTEXT_i386 0x00010000 // this assumes that i386 and
  461. #define CONTEXT_i486 0x00010000 // i486 have identical context records
  462. // end_wx86
  463. #define CONTEXT_CONTROL (CONTEXT_i386 | 0x00000001L) // SS:SP, CS:IP, FLAGS, BP
  464. #define CONTEXT_INTEGER (CONTEXT_i386 | 0x00000002L) // AX, BX, CX, DX, SI, DI
  465. #define CONTEXT_SEGMENTS (CONTEXT_i386 | 0x00000004L) // DS, ES, FS, GS
  466. #define CONTEXT_FLOATING_POINT (CONTEXT_i386 | 0x00000008L) // 387 state
  467. #define CONTEXT_DEBUG_REGISTERS (CONTEXT_i386 | 0x00000010L) // DB 0-3,6,7
  468. #define CONTEXT_EXTENDED_REGISTERS (CONTEXT_i386 | 0x00000020L) // cpu specific extensions
  469. #define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_INTEGER |\
  470. CONTEXT_SEGMENTS)
  471. // begin_wx86
  472. #endif
  473. #define MAXIMUM_SUPPORTED_EXTENSION 512
  474. typedef struct _FLOATING_SAVE_AREA {
  475. ULONG ControlWord;
  476. ULONG StatusWord;
  477. ULONG TagWord;
  478. ULONG ErrorOffset;
  479. ULONG ErrorSelector;
  480. ULONG DataOffset;
  481. ULONG DataSelector;
  482. UCHAR RegisterArea[SIZE_OF_80387_REGISTERS];
  483. ULONG Cr0NpxState;
  484. } FLOATING_SAVE_AREA;
  485. typedef FLOATING_SAVE_AREA *PFLOATING_SAVE_AREA;
  486. //
  487. // Context Frame
  488. //
  489. // This frame has a several purposes: 1) it is used as an argument to
  490. // NtContinue, 2) is is used to constuct a call frame for APC delivery,
  491. // and 3) it is used in the user level thread creation routines.
  492. //
  493. // The layout of the record conforms to a standard call frame.
  494. //
  495. typedef struct _CONTEXT {
  496. //
  497. // The flags values within this flag control the contents of
  498. // a CONTEXT record.
  499. //
  500. // If the context record is used as an input parameter, then
  501. // for each portion of the context record controlled by a flag
  502. // whose value is set, it is assumed that that portion of the
  503. // context record contains valid context. If the context record
  504. // is being used to modify a threads context, then only that
  505. // portion of the threads context will be modified.
  506. //
  507. // If the context record is used as an IN OUT parameter to capture
  508. // the context of a thread, then only those portions of the thread's
  509. // context corresponding to set flags will be returned.
  510. //
  511. // The context record is never used as an OUT only parameter.
  512. //
  513. ULONG ContextFlags;
  514. //
  515. // This section is specified/returned if CONTEXT_DEBUG_REGISTERS is
  516. // set in ContextFlags. Note that CONTEXT_DEBUG_REGISTERS is NOT
  517. // included in CONTEXT_FULL.
  518. //
  519. ULONG Dr0;
  520. ULONG Dr1;
  521. ULONG Dr2;
  522. ULONG Dr3;
  523. ULONG Dr6;
  524. ULONG Dr7;
  525. //
  526. // This section is specified/returned if the
  527. // ContextFlags word contians the flag CONTEXT_FLOATING_POINT.
  528. //
  529. FLOATING_SAVE_AREA FloatSave;
  530. //
  531. // This section is specified/returned if the
  532. // ContextFlags word contians the flag CONTEXT_SEGMENTS.
  533. //
  534. ULONG SegGs;
  535. ULONG SegFs;
  536. ULONG SegEs;
  537. ULONG SegDs;
  538. //
  539. // This section is specified/returned if the
  540. // ContextFlags word contians the flag CONTEXT_INTEGER.
  541. //
  542. ULONG Edi;
  543. ULONG Esi;
  544. ULONG Ebx;
  545. ULONG Edx;
  546. ULONG Ecx;
  547. ULONG Eax;
  548. //
  549. // This section is specified/returned if the
  550. // ContextFlags word contians the flag CONTEXT_CONTROL.
  551. //
  552. ULONG Ebp;
  553. ULONG Eip;
  554. ULONG SegCs; // MUST BE SANITIZED
  555. ULONG EFlags; // MUST BE SANITIZED
  556. ULONG Esp;
  557. ULONG SegSs;
  558. //
  559. // This section is specified/returned if the ContextFlags word
  560. // contains the flag CONTEXT_EXTENDED_REGISTERS.
  561. // The format and contexts are processor specific
  562. //
  563. UCHAR ExtendedRegisters[MAXIMUM_SUPPORTED_EXTENSION];
  564. } CONTEXT;
  565. typedef CONTEXT *PCONTEXT;
  566. // begin_ntminiport
  567. #endif //_X86_
  568. #endif // _X86_
  569. #if defined(_AMD64_)
  570. #if defined(_M_AMD64) && !defined(RC_INVOKED) && !defined(MIDL_PASS)
  571. //
  572. // Define function to get the caller's EFLAGs value.
  573. //
  574. #define GetCallersEflags() __getcallerseflags()
  575. unsigned __int32
  576. __getcallerseflags (
  577. VOID
  578. );
  579. #pragma intrinsic(__getcallerseflags)
  580. //
  581. // Define function to read the value of the time stamp counter
  582. //
  583. #define ReadTimeStampCounter() __rdtsc()
  584. ULONG64
  585. __rdtsc (
  586. VOID
  587. );
  588. #pragma intrinsic(__rdtsc)
  589. //
  590. // Define functions to move strings or bytes, words, dwords, and qwords.
  591. //
  592. VOID
  593. __movsb (
  594. IN PUCHAR Destination,
  595. IN PUCHAR Source,
  596. IN ULONG Count
  597. );
  598. VOID
  599. __movsw (
  600. IN PUSHORT Destination,
  601. IN PUSHORT Source,
  602. IN ULONG Count
  603. );
  604. VOID
  605. __movsd (
  606. IN PULONG Destination,
  607. IN PULONG Source,
  608. IN ULONG Count
  609. );
  610. VOID
  611. __movsq (
  612. IN PULONGLONG Destination,
  613. IN PULONGLONG Source,
  614. IN ULONG Count
  615. );
  616. #pragma intrinsic(__movsb)
  617. #pragma intrinsic(__movsw)
  618. #pragma intrinsic(__movsd)
  619. #pragma intrinsic(__movsq)
  620. //
  621. // Define functions to capture the high 64-bits of a 128-bit multiply.
  622. //
  623. #define MultiplyHigh __mulh
  624. #define UnsignedMultiplyHigh __umulh
  625. LONGLONG
  626. MultiplyHigh (
  627. IN LONGLONG Multiplier,
  628. IN LONGLONG Multiplicand
  629. );
  630. ULONGLONG
  631. UnsignedMultiplyHigh (
  632. IN ULONGLONG Multiplier,
  633. IN ULONGLONG Multiplicand
  634. );
  635. #pragma intrinsic(__mulh)
  636. #pragma intrinsic(__umulh)
  637. //
  638. // Define functions to read and write the uer TEB and the system PCR/PRCB.
  639. //
  640. UCHAR
  641. __readgsbyte (
  642. IN ULONG Offset
  643. );
  644. USHORT
  645. __readgsword (
  646. IN ULONG Offset
  647. );
  648. ULONG
  649. __readgsdword (
  650. IN ULONG Offset
  651. );
  652. ULONG64
  653. __readgsqword (
  654. IN ULONG Offset
  655. );
  656. VOID
  657. __writegsbyte (
  658. IN ULONG Offset,
  659. IN UCHAR Data
  660. );
  661. VOID
  662. __writegsword (
  663. IN ULONG Offset,
  664. IN USHORT Data
  665. );
  666. VOID
  667. __writegsdword (
  668. IN ULONG Offset,
  669. IN ULONG Data
  670. );
  671. VOID
  672. __writegsqword (
  673. IN ULONG Offset,
  674. IN ULONG64 Data
  675. );
  676. #pragma intrinsic(__readgsbyte)
  677. #pragma intrinsic(__readgsword)
  678. #pragma intrinsic(__readgsdword)
  679. #pragma intrinsic(__readgsqword)
  680. #pragma intrinsic(__writegsbyte)
  681. #pragma intrinsic(__writegsword)
  682. #pragma intrinsic(__writegsdword)
  683. #pragma intrinsic(__writegsqword)
  684. #endif // defined(_M_AMD64) && !defined(RC_INVOKED) && !defined(MIDL_PASS)
  685. //
  686. // Size of kernel mode stack.
  687. //
  688. #define KERNEL_STACK_SIZE 0x5000
  689. //
  690. // Define size of large kernel mode stack for callbacks.
  691. //
  692. #define KERNEL_LARGE_STACK_SIZE 0xf000
  693. //
  694. // Define number of pages to initialize in a large kernel stack.
  695. //
  696. #define KERNEL_LARGE_STACK_COMMIT 0x5000
  697. //
  698. // Define the size of the stack used for processing an MCA exception.
  699. //
  700. #define KERNEL_MCA_EXCEPTION_STACK_SIZE 0x2000
  701. //
  702. // The following flags control the contents of the CONTEXT structure.
  703. //
  704. #if !defined(RC_INVOKED)
  705. #define CONTEXT_AMD64 0x100000
  706. // end_wx86
  707. #define CONTEXT_CONTROL (CONTEXT_AMD64 | 0x1L)
  708. #define CONTEXT_INTEGER (CONTEXT_AMD64 | 0x2L)
  709. #define CONTEXT_SEGMENTS (CONTEXT_AMD64 | 0x4L)
  710. #define CONTEXT_FLOATING_POINT (CONTEXT_AMD64 | 0x8L)
  711. #define CONTEXT_DEBUG_REGISTERS (CONTEXT_AMD64 | 0x10L)
  712. #define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_FLOATING_POINT)
  713. // begin_wx86
  714. #endif // !defined(RC_INVOKED)
  715. //
  716. // Define 128-bit 16-byte aligned xmm register type.
  717. //
  718. typedef struct DECLSPEC_ALIGN(16) _M128 {
  719. ULONGLONG Low;
  720. LONGLONG High;
  721. } M128, *PM128;
  722. //
  723. // Format of data for fnsave/frstor instructions.
  724. //
  725. // This structure is used to store the legacy floating point state.
  726. //
  727. typedef struct _LEGACY_SAVE_AREA {
  728. USHORT ControlWord;
  729. USHORT Reserved0;
  730. USHORT StatusWord;
  731. USHORT Reserved1;
  732. USHORT TagWord;
  733. USHORT Reserved2;
  734. ULONG ErrorOffset;
  735. USHORT ErrorSelector;
  736. USHORT ErrorOpcode;
  737. ULONG DataOffset;
  738. USHORT DataSelector;
  739. USHORT Reserved3;
  740. UCHAR FloatRegisters[8 * 10];
  741. } LEGACY_SAVE_AREA, *PLEGACY_SAVE_AREA;
  742. #define LEGACY_SAVE_AREA_LENGTH ((sizeof(LEGACY_SAVE_AREA) + 15) & ~15)
  743. //
  744. // Context Frame
  745. //
  746. // This frame has a several purposes: 1) it is used as an argument to
  747. // NtContinue, 2) is is used to constuct a call frame for APC delivery,
  748. // and 3) it is used in the user level thread creation routines.
  749. //
  750. //
  751. // The flags field within this record controls the contents of a CONTEXT
  752. // record.
  753. //
  754. // If the context record is used as an input parameter, then for each
  755. // portion of the context record controlled by a flag whose value is
  756. // set, it is assumed that that portion of the context record contains
  757. // valid context. If the context record is being used to modify a threads
  758. // context, then only that portion of the threads context is modified.
  759. //
  760. // If the context record is used as an output parameter to capture the
  761. // context of a thread, then only those portions of the thread's context
  762. // corresponding to set flags will be returned.
  763. //
  764. // CONTEXT_CONTROL specifies SegSs, Rsp, SegCs, Rip, and EFlags.
  765. //
  766. // CONTEXT_INTEGER specifies Rax, Rcx, Rdx, Rbx, Rbp, Rsi, Rdi, and R8-R15.
  767. //
  768. // CONTEXT_SEGMENTS specifies SegDs, SegEs, SegFs, and SegGs.
  769. //
  770. // CONTEXT_DEBUG_REGISTERS specifies Dr0-Dr3 and Dr6-Dr7.
  771. //
  772. // CONTEXT_MMX_REGISTERS specifies the floating point and extended registers
  773. // Mm0/St0-Mm7/St7 and Xmm0-Xmm15).
  774. //
  775. typedef struct DECLSPEC_ALIGN(16) _CONTEXT {
  776. //
  777. // Register parameter home addresses.
  778. //
  779. ULONG64 P1Home;
  780. ULONG64 P2Home;
  781. ULONG64 P3Home;
  782. ULONG64 P4Home;
  783. ULONG64 P5Home;
  784. ULONG64 P6Home;
  785. //
  786. // Control flags.
  787. //
  788. ULONG ContextFlags;
  789. ULONG MxCsr;
  790. //
  791. // Segment Registers and processor flags.
  792. //
  793. USHORT SegCs;
  794. USHORT SegDs;
  795. USHORT SegEs;
  796. USHORT SegFs;
  797. USHORT SegGs;
  798. USHORT SegSs;
  799. ULONG EFlags;
  800. //
  801. // Debug registers
  802. //
  803. ULONG64 Dr0;
  804. ULONG64 Dr1;
  805. ULONG64 Dr2;
  806. ULONG64 Dr3;
  807. ULONG64 Dr6;
  808. ULONG64 Dr7;
  809. //
  810. // Integer registers.
  811. //
  812. ULONG64 Rax;
  813. ULONG64 Rcx;
  814. ULONG64 Rdx;
  815. ULONG64 Rbx;
  816. ULONG64 Rsp;
  817. ULONG64 Rbp;
  818. ULONG64 Rsi;
  819. ULONG64 Rdi;
  820. ULONG64 R8;
  821. ULONG64 R9;
  822. ULONG64 R10;
  823. ULONG64 R11;
  824. ULONG64 R12;
  825. ULONG64 R13;
  826. ULONG64 R14;
  827. ULONG64 R15;
  828. //
  829. // Program counter.
  830. //
  831. ULONG64 Rip;
  832. //
  833. // MMX/floating point state.
  834. //
  835. M128 Xmm0;
  836. M128 Xmm1;
  837. M128 Xmm2;
  838. M128 Xmm3;
  839. M128 Xmm4;
  840. M128 Xmm5;
  841. M128 Xmm6;
  842. M128 Xmm7;
  843. M128 Xmm8;
  844. M128 Xmm9;
  845. M128 Xmm10;
  846. M128 Xmm11;
  847. M128 Xmm12;
  848. M128 Xmm13;
  849. M128 Xmm14;
  850. M128 Xmm15;
  851. //
  852. // Legacy floating point state.
  853. //
  854. LEGACY_SAVE_AREA FltSave;
  855. ULONG Fill;
  856. } CONTEXT, *PCONTEXT;
  857. #endif // _AMD64_
  858. #ifdef _IA64_
  859. //
  860. // Define size of kernel mode stack.
  861. //
  862. #define KERNEL_STACK_SIZE 0x8000
  863. //
  864. // Define size of large kernel mode stack for callbacks.
  865. //
  866. #define KERNEL_LARGE_STACK_SIZE 0x1A000
  867. //
  868. // Define number of pages to initialize in a large kernel stack.
  869. //
  870. #define KERNEL_LARGE_STACK_COMMIT 0x8000
  871. //
  872. // Define size of kernel mode backing store stack.
  873. //
  874. #define KERNEL_BSTORE_SIZE 0x6000
  875. //
  876. // Define size of large kernel mode backing store for callbacks.
  877. //
  878. #define KERNEL_LARGE_BSTORE_SIZE 0x10000
  879. //
  880. // Define number of pages to initialize in a large kernel backing store.
  881. //
  882. #define KERNEL_LARGE_BSTORE_COMMIT 0x6000
  883. //
  884. // Define base address for kernel and user space.
  885. //
  886. #define UREGION_INDEX 0
  887. #define KREGION_INDEX 7
  888. #define UADDRESS_BASE ((ULONGLONG)UREGION_INDEX << 61)
  889. #define KADDRESS_BASE ((ULONGLONG)KREGION_INDEX << 61)
  890. //
  891. // The following flags control the contents of the CONTEXT structure.
  892. //
  893. #if !defined(RC_INVOKED)
  894. #define CONTEXT_IA64 0x00080000
  895. #define CONTEXT_CONTROL (CONTEXT_IA64 | 0x00000001L)
  896. #define CONTEXT_LOWER_FLOATING_POINT (CONTEXT_IA64 | 0x00000002L)
  897. #define CONTEXT_HIGHER_FLOATING_POINT (CONTEXT_IA64 | 0x00000004L)
  898. #define CONTEXT_INTEGER (CONTEXT_IA64 | 0x00000008L)
  899. #define CONTEXT_DEBUG (CONTEXT_IA64 | 0x00000010L)
  900. #define CONTEXT_IA32_CONTROL (CONTEXT_IA64 | 0x00000020L) // Includes StIPSR
  901. #define CONTEXT_FLOATING_POINT (CONTEXT_LOWER_FLOATING_POINT | CONTEXT_HIGHER_FLOATING_POINT)
  902. #define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_FLOATING_POINT | CONTEXT_INTEGER | CONTEXT_IA32_CONTROL)
  903. #endif // !defined(RC_INVOKED)
  904. //
  905. // Context Frame
  906. //
  907. // This frame has a several purposes: 1) it is used as an argument to
  908. // NtContinue, 2) it is used to construct a call frame for APC delivery,
  909. // 3) it is used to construct a call frame for exception dispatching
  910. // in user mode, 4) it is used in the user level thread creation
  911. // routines, and 5) it is used to to pass thread state to debuggers.
  912. //
  913. // N.B. Because this record is used as a call frame, it must be EXACTLY
  914. // a multiple of 16 bytes in length and aligned on a 16-byte boundary.
  915. //
  916. typedef struct _CONTEXT {
  917. //
  918. // The flags values within this flag control the contents of
  919. // a CONTEXT record.
  920. //
  921. // If the context record is used as an input parameter, then
  922. // for each portion of the context record controlled by a flag
  923. // whose value is set, it is assumed that that portion of the
  924. // context record contains valid context. If the context record
  925. // is being used to modify a thread's context, then only that
  926. // portion of the threads context will be modified.
  927. //
  928. // If the context record is used as an IN OUT parameter to capture
  929. // the context of a thread, then only those portions of the thread's
  930. // context corresponding to set flags will be returned.
  931. //
  932. // The context record is never used as an OUT only parameter.
  933. //
  934. ULONG ContextFlags;
  935. ULONG Fill1[3]; // for alignment of following on 16-byte boundary
  936. //
  937. // This section is specified/returned if the ContextFlags word contains
  938. // the flag CONTEXT_DEBUG.
  939. //
  940. // N.B. CONTEXT_DEBUG is *not* part of CONTEXT_FULL.
  941. //
  942. ULONGLONG DbI0;
  943. ULONGLONG DbI1;
  944. ULONGLONG DbI2;
  945. ULONGLONG DbI3;
  946. ULONGLONG DbI4;
  947. ULONGLONG DbI5;
  948. ULONGLONG DbI6;
  949. ULONGLONG DbI7;
  950. ULONGLONG DbD0;
  951. ULONGLONG DbD1;
  952. ULONGLONG DbD2;
  953. ULONGLONG DbD3;
  954. ULONGLONG DbD4;
  955. ULONGLONG DbD5;
  956. ULONGLONG DbD6;
  957. ULONGLONG DbD7;
  958. //
  959. // This section is specified/returned if the ContextFlags word contains
  960. // the flag CONTEXT_LOWER_FLOATING_POINT.
  961. //
  962. FLOAT128 FltS0;
  963. FLOAT128 FltS1;
  964. FLOAT128 FltS2;
  965. FLOAT128 FltS3;
  966. FLOAT128 FltT0;
  967. FLOAT128 FltT1;
  968. FLOAT128 FltT2;
  969. FLOAT128 FltT3;
  970. FLOAT128 FltT4;
  971. FLOAT128 FltT5;
  972. FLOAT128 FltT6;
  973. FLOAT128 FltT7;
  974. FLOAT128 FltT8;
  975. FLOAT128 FltT9;
  976. //
  977. // This section is specified/returned if the ContextFlags word contains
  978. // the flag CONTEXT_HIGHER_FLOATING_POINT.
  979. //
  980. FLOAT128 FltS4;
  981. FLOAT128 FltS5;
  982. FLOAT128 FltS6;
  983. FLOAT128 FltS7;
  984. FLOAT128 FltS8;
  985. FLOAT128 FltS9;
  986. FLOAT128 FltS10;
  987. FLOAT128 FltS11;
  988. FLOAT128 FltS12;
  989. FLOAT128 FltS13;
  990. FLOAT128 FltS14;
  991. FLOAT128 FltS15;
  992. FLOAT128 FltS16;
  993. FLOAT128 FltS17;
  994. FLOAT128 FltS18;
  995. FLOAT128 FltS19;
  996. FLOAT128 FltF32;
  997. FLOAT128 FltF33;
  998. FLOAT128 FltF34;
  999. FLOAT128 FltF35;
  1000. FLOAT128 FltF36;
  1001. FLOAT128 FltF37;
  1002. FLOAT128 FltF38;
  1003. FLOAT128 FltF39;
  1004. FLOAT128 FltF40;
  1005. FLOAT128 FltF41;
  1006. FLOAT128 FltF42;
  1007. FLOAT128 FltF43;
  1008. FLOAT128 FltF44;
  1009. FLOAT128 FltF45;
  1010. FLOAT128 FltF46;
  1011. FLOAT128 FltF47;
  1012. FLOAT128 FltF48;
  1013. FLOAT128 FltF49;
  1014. FLOAT128 FltF50;
  1015. FLOAT128 FltF51;
  1016. FLOAT128 FltF52;
  1017. FLOAT128 FltF53;
  1018. FLOAT128 FltF54;
  1019. FLOAT128 FltF55;
  1020. FLOAT128 FltF56;
  1021. FLOAT128 FltF57;
  1022. FLOAT128 FltF58;
  1023. FLOAT128 FltF59;
  1024. FLOAT128 FltF60;
  1025. FLOAT128 FltF61;
  1026. FLOAT128 FltF62;
  1027. FLOAT128 FltF63;
  1028. FLOAT128 FltF64;
  1029. FLOAT128 FltF65;
  1030. FLOAT128 FltF66;
  1031. FLOAT128 FltF67;
  1032. FLOAT128 FltF68;
  1033. FLOAT128 FltF69;
  1034. FLOAT128 FltF70;
  1035. FLOAT128 FltF71;
  1036. FLOAT128 FltF72;
  1037. FLOAT128 FltF73;
  1038. FLOAT128 FltF74;
  1039. FLOAT128 FltF75;
  1040. FLOAT128 FltF76;
  1041. FLOAT128 FltF77;
  1042. FLOAT128 FltF78;
  1043. FLOAT128 FltF79;
  1044. FLOAT128 FltF80;
  1045. FLOAT128 FltF81;
  1046. FLOAT128 FltF82;
  1047. FLOAT128 FltF83;
  1048. FLOAT128 FltF84;
  1049. FLOAT128 FltF85;
  1050. FLOAT128 FltF86;
  1051. FLOAT128 FltF87;
  1052. FLOAT128 FltF88;
  1053. FLOAT128 FltF89;
  1054. FLOAT128 FltF90;
  1055. FLOAT128 FltF91;
  1056. FLOAT128 FltF92;
  1057. FLOAT128 FltF93;
  1058. FLOAT128 FltF94;
  1059. FLOAT128 FltF95;
  1060. FLOAT128 FltF96;
  1061. FLOAT128 FltF97;
  1062. FLOAT128 FltF98;
  1063. FLOAT128 FltF99;
  1064. FLOAT128 FltF100;
  1065. FLOAT128 FltF101;
  1066. FLOAT128 FltF102;
  1067. FLOAT128 FltF103;
  1068. FLOAT128 FltF104;
  1069. FLOAT128 FltF105;
  1070. FLOAT128 FltF106;
  1071. FLOAT128 FltF107;
  1072. FLOAT128 FltF108;
  1073. FLOAT128 FltF109;
  1074. FLOAT128 FltF110;
  1075. FLOAT128 FltF111;
  1076. FLOAT128 FltF112;
  1077. FLOAT128 FltF113;
  1078. FLOAT128 FltF114;
  1079. FLOAT128 FltF115;
  1080. FLOAT128 FltF116;
  1081. FLOAT128 FltF117;
  1082. FLOAT128 FltF118;
  1083. FLOAT128 FltF119;
  1084. FLOAT128 FltF120;
  1085. FLOAT128 FltF121;
  1086. FLOAT128 FltF122;
  1087. FLOAT128 FltF123;
  1088. FLOAT128 FltF124;
  1089. FLOAT128 FltF125;
  1090. FLOAT128 FltF126;
  1091. FLOAT128 FltF127;
  1092. //
  1093. // This section is specified/returned if the ContextFlags word contains
  1094. // the flag CONTEXT_LOWER_FLOATING_POINT | CONTEXT_HIGHER_FLOATING_POINT | CONTEXT_CONTROL.
  1095. //
  1096. ULONGLONG StFPSR; // FP status
  1097. //
  1098. // This section is specified/returned if the ContextFlags word contains
  1099. // the flag CONTEXT_INTEGER.
  1100. //
  1101. // N.B. The registers gp, sp, rp are part of the control context
  1102. //
  1103. ULONGLONG IntGp; // r1, volatile
  1104. ULONGLONG IntT0; // r2-r3, volatile
  1105. ULONGLONG IntT1; //
  1106. ULONGLONG IntS0; // r4-r7, preserved
  1107. ULONGLONG IntS1;
  1108. ULONGLONG IntS2;
  1109. ULONGLONG IntS3;
  1110. ULONGLONG IntV0; // r8, volatile
  1111. ULONGLONG IntT2; // r9-r11, volatile
  1112. ULONGLONG IntT3;
  1113. ULONGLONG IntT4;
  1114. ULONGLONG IntSp; // stack pointer (r12), special
  1115. ULONGLONG IntTeb; // teb (r13), special
  1116. ULONGLONG IntT5; // r14-r31, volatile
  1117. ULONGLONG IntT6;
  1118. ULONGLONG IntT7;
  1119. ULONGLONG IntT8;
  1120. ULONGLONG IntT9;
  1121. ULONGLONG IntT10;
  1122. ULONGLONG IntT11;
  1123. ULONGLONG IntT12;
  1124. ULONGLONG IntT13;
  1125. ULONGLONG IntT14;
  1126. ULONGLONG IntT15;
  1127. ULONGLONG IntT16;
  1128. ULONGLONG IntT17;
  1129. ULONGLONG IntT18;
  1130. ULONGLONG IntT19;
  1131. ULONGLONG IntT20;
  1132. ULONGLONG IntT21;
  1133. ULONGLONG IntT22;
  1134. ULONGLONG IntNats; // Nat bits for r1-r31
  1135. // r1-r31 in bits 1 thru 31.
  1136. ULONGLONG Preds; // predicates, preserved
  1137. ULONGLONG BrRp; // return pointer, b0, preserved
  1138. ULONGLONG BrS0; // b1-b5, preserved
  1139. ULONGLONG BrS1;
  1140. ULONGLONG BrS2;
  1141. ULONGLONG BrS3;
  1142. ULONGLONG BrS4;
  1143. ULONGLONG BrT0; // b6-b7, volatile
  1144. ULONGLONG BrT1;
  1145. //
  1146. // This section is specified/returned if the ContextFlags word contains
  1147. // the flag CONTEXT_CONTROL.
  1148. //
  1149. // Other application registers
  1150. ULONGLONG ApUNAT; // User Nat collection register, preserved
  1151. ULONGLONG ApLC; // Loop counter register, preserved
  1152. ULONGLONG ApEC; // Epilog counter register, preserved
  1153. ULONGLONG ApCCV; // CMPXCHG value register, volatile
  1154. ULONGLONG ApDCR; // Default control register (TBD)
  1155. // Register stack info
  1156. ULONGLONG RsPFS; // Previous function state, preserved
  1157. ULONGLONG RsBSP; // Backing store pointer, preserved
  1158. ULONGLONG RsBSPSTORE;
  1159. ULONGLONG RsRSC; // RSE configuration, volatile
  1160. ULONGLONG RsRNAT; // RSE Nat collection register, preserved
  1161. // Trap Status Information
  1162. ULONGLONG StIPSR; // Interruption Processor Status
  1163. ULONGLONG StIIP; // Interruption IP
  1164. ULONGLONG StIFS; // Interruption Function State
  1165. // iA32 related control registers
  1166. ULONGLONG StFCR; // copy of Ar21
  1167. ULONGLONG Eflag; // Eflag copy of Ar24
  1168. ULONGLONG SegCSD; // iA32 CSDescriptor (Ar25)
  1169. ULONGLONG SegSSD; // iA32 SSDescriptor (Ar26)
  1170. ULONGLONG Cflag; // Cr0+Cr4 copy of Ar27
  1171. ULONGLONG StFSR; // x86 FP status (copy of AR28)
  1172. ULONGLONG StFIR; // x86 FP status (copy of AR29)
  1173. ULONGLONG StFDR; // x86 FP status (copy of AR30)
  1174. ULONGLONG UNUSEDPACK; // added to pack StFDR to 16-bytes
  1175. } CONTEXT, *PCONTEXT;
  1176. // begin_winnt
  1177. //
  1178. // Plabel descriptor structure definition
  1179. //
  1180. typedef struct _PLABEL_DESCRIPTOR {
  1181. ULONGLONG EntryPoint;
  1182. ULONGLONG GlobalPointer;
  1183. } PLABEL_DESCRIPTOR, *PPLABEL_DESCRIPTOR;
  1184. // end_winnt
  1185. #endif // _IA64_
  1186. //
  1187. // Define an access token from a programmer's viewpoint. The structure is
  1188. // completely opaque and the programer is only allowed to have pointers
  1189. // to tokens.
  1190. //
  1191. typedef PVOID PACCESS_TOKEN; // winnt
  1192. //
  1193. // Pointer to a SECURITY_DESCRIPTOR opaque data type.
  1194. //
  1195. typedef PVOID PSECURITY_DESCRIPTOR; // winnt
  1196. //
  1197. // Define a pointer to the Security ID data type (an opaque data type)
  1198. //
  1199. typedef PVOID PSID; // winnt
  1200. typedef ULONG ACCESS_MASK;
  1201. typedef ACCESS_MASK *PACCESS_MASK;
  1202. // end_winnt
  1203. //
  1204. // The following are masks for the predefined standard access types
  1205. //
  1206. #define DELETE (0x00010000L)
  1207. #define READ_CONTROL (0x00020000L)
  1208. #define WRITE_DAC (0x00040000L)
  1209. #define WRITE_OWNER (0x00080000L)
  1210. #define SYNCHRONIZE (0x00100000L)
  1211. #define STANDARD_RIGHTS_REQUIRED (0x000F0000L)
  1212. #define STANDARD_RIGHTS_READ (READ_CONTROL)
  1213. #define STANDARD_RIGHTS_WRITE (READ_CONTROL)
  1214. #define STANDARD_RIGHTS_EXECUTE (READ_CONTROL)
  1215. #define STANDARD_RIGHTS_ALL (0x001F0000L)
  1216. #define SPECIFIC_RIGHTS_ALL (0x0000FFFFL)
  1217. //
  1218. // AccessSystemAcl access type
  1219. //
  1220. #define ACCESS_SYSTEM_SECURITY (0x01000000L)
  1221. //
  1222. // MaximumAllowed access type
  1223. //
  1224. #define MAXIMUM_ALLOWED (0x02000000L)
  1225. //
  1226. // These are the generic rights.
  1227. //
  1228. #define GENERIC_READ (0x80000000L)
  1229. #define GENERIC_WRITE (0x40000000L)
  1230. #define GENERIC_EXECUTE (0x20000000L)
  1231. #define GENERIC_ALL (0x10000000L)
  1232. //
  1233. // Define the generic mapping array. This is used to denote the
  1234. // mapping of each generic access right to a specific access mask.
  1235. //
  1236. typedef struct _GENERIC_MAPPING {
  1237. ACCESS_MASK GenericRead;
  1238. ACCESS_MASK GenericWrite;
  1239. ACCESS_MASK GenericExecute;
  1240. ACCESS_MASK GenericAll;
  1241. } GENERIC_MAPPING;
  1242. typedef GENERIC_MAPPING *PGENERIC_MAPPING;
  1243. ////////////////////////////////////////////////////////////////////////
  1244. // //
  1245. // LUID_AND_ATTRIBUTES //
  1246. // //
  1247. ////////////////////////////////////////////////////////////////////////
  1248. //
  1249. //
  1250. #include <pshpack4.h>
  1251. typedef struct _LUID_AND_ATTRIBUTES {
  1252. LUID Luid;
  1253. ULONG Attributes;
  1254. } LUID_AND_ATTRIBUTES, * PLUID_AND_ATTRIBUTES;
  1255. typedef LUID_AND_ATTRIBUTES LUID_AND_ATTRIBUTES_ARRAY[ANYSIZE_ARRAY];
  1256. typedef LUID_AND_ATTRIBUTES_ARRAY *PLUID_AND_ATTRIBUTES_ARRAY;
  1257. #include <poppack.h>
  1258. // This is the *current* ACL revision
  1259. #define ACL_REVISION (2)
  1260. #define ACL_REVISION_DS (4)
  1261. // This is the history of ACL revisions. Add a new one whenever
  1262. // ACL_REVISION is updated
  1263. #define ACL_REVISION1 (1)
  1264. #define MIN_ACL_REVISION ACL_REVISION2
  1265. #define ACL_REVISION2 (2)
  1266. #define ACL_REVISION3 (3)
  1267. #define ACL_REVISION4 (4)
  1268. #define MAX_ACL_REVISION ACL_REVISION4
  1269. typedef struct _ACL {
  1270. UCHAR AclRevision;
  1271. UCHAR Sbz1;
  1272. USHORT AclSize;
  1273. USHORT AceCount;
  1274. USHORT Sbz2;
  1275. } ACL;
  1276. typedef ACL *PACL;
  1277. //
  1278. // Current security descriptor revision value
  1279. //
  1280. #define SECURITY_DESCRIPTOR_REVISION (1)
  1281. #define SECURITY_DESCRIPTOR_REVISION1 (1)
  1282. //
  1283. // Privilege attributes
  1284. //
  1285. #define SE_PRIVILEGE_ENABLED_BY_DEFAULT (0x00000001L)
  1286. #define SE_PRIVILEGE_ENABLED (0x00000002L)
  1287. #define SE_PRIVILEGE_USED_FOR_ACCESS (0x80000000L)
  1288. //
  1289. // Privilege Set Control flags
  1290. //
  1291. #define PRIVILEGE_SET_ALL_NECESSARY (1)
  1292. //
  1293. // Privilege Set - This is defined for a privilege set of one.
  1294. // If more than one privilege is needed, then this structure
  1295. // will need to be allocated with more space.
  1296. //
  1297. // Note: don't change this structure without fixing the INITIAL_PRIVILEGE_SET
  1298. // structure (defined in se.h)
  1299. //
  1300. typedef struct _PRIVILEGE_SET {
  1301. ULONG PrivilegeCount;
  1302. ULONG Control;
  1303. LUID_AND_ATTRIBUTES Privilege[ANYSIZE_ARRAY];
  1304. } PRIVILEGE_SET, * PPRIVILEGE_SET;
  1305. //
  1306. // These must be converted to LUIDs before use.
  1307. //
  1308. #define SE_MIN_WELL_KNOWN_PRIVILEGE (2L)
  1309. #define SE_CREATE_TOKEN_PRIVILEGE (2L)
  1310. #define SE_ASSIGNPRIMARYTOKEN_PRIVILEGE (3L)
  1311. #define SE_LOCK_MEMORY_PRIVILEGE (4L)
  1312. #define SE_INCREASE_QUOTA_PRIVILEGE (5L)
  1313. // end_wdm
  1314. //
  1315. // Unsolicited Input is obsolete and unused.
  1316. //
  1317. #define SE_UNSOLICITED_INPUT_PRIVILEGE (6L)
  1318. // begin_wdm
  1319. #define SE_MACHINE_ACCOUNT_PRIVILEGE (6L)
  1320. #define SE_TCB_PRIVILEGE (7L)
  1321. #define SE_SECURITY_PRIVILEGE (8L)
  1322. #define SE_TAKE_OWNERSHIP_PRIVILEGE (9L)
  1323. #define SE_LOAD_DRIVER_PRIVILEGE (10L)
  1324. #define SE_SYSTEM_PROFILE_PRIVILEGE (11L)
  1325. #define SE_SYSTEMTIME_PRIVILEGE (12L)
  1326. #define SE_PROF_SINGLE_PROCESS_PRIVILEGE (13L)
  1327. #define SE_INC_BASE_PRIORITY_PRIVILEGE (14L)
  1328. #define SE_CREATE_PAGEFILE_PRIVILEGE (15L)
  1329. #define SE_CREATE_PERMANENT_PRIVILEGE (16L)
  1330. #define SE_BACKUP_PRIVILEGE (17L)
  1331. #define SE_RESTORE_PRIVILEGE (18L)
  1332. #define SE_SHUTDOWN_PRIVILEGE (19L)
  1333. #define SE_DEBUG_PRIVILEGE (20L)
  1334. #define SE_AUDIT_PRIVILEGE (21L)
  1335. #define SE_SYSTEM_ENVIRONMENT_PRIVILEGE (22L)
  1336. #define SE_CHANGE_NOTIFY_PRIVILEGE (23L)
  1337. #define SE_REMOTE_SHUTDOWN_PRIVILEGE (24L)
  1338. #define SE_UNDOCK_PRIVILEGE (25L)
  1339. #define SE_SYNC_AGENT_PRIVILEGE (26L)
  1340. #define SE_ENABLE_DELEGATION_PRIVILEGE (27L)
  1341. #define SE_MANAGE_VOLUME_PRIVILEGE (28L)
  1342. #define SE_MAX_WELL_KNOWN_PRIVILEGE (SE_MANAGE_VOLUME_PRIVILEGE)
  1343. //
  1344. // Impersonation Level
  1345. //
  1346. // Impersonation level is represented by a pair of bits in Windows.
  1347. // If a new impersonation level is added or lowest value is changed from
  1348. // 0 to something else, fix the Windows CreateFile call.
  1349. //
  1350. typedef enum _SECURITY_IMPERSONATION_LEVEL {
  1351. SecurityAnonymous,
  1352. SecurityIdentification,
  1353. SecurityImpersonation,
  1354. SecurityDelegation
  1355. } SECURITY_IMPERSONATION_LEVEL, * PSECURITY_IMPERSONATION_LEVEL;
  1356. #define SECURITY_MAX_IMPERSONATION_LEVEL SecurityDelegation
  1357. #define SECURITY_MIN_IMPERSONATION_LEVEL SecurityAnonymous
  1358. #define DEFAULT_IMPERSONATION_LEVEL SecurityImpersonation
  1359. #define VALID_IMPERSONATION_LEVEL(L) (((L) >= SECURITY_MIN_IMPERSONATION_LEVEL) && ((L) <= SECURITY_MAX_IMPERSONATION_LEVEL))
  1360. //
  1361. // Security Tracking Mode
  1362. //
  1363. #define SECURITY_DYNAMIC_TRACKING (TRUE)
  1364. #define SECURITY_STATIC_TRACKING (FALSE)
  1365. typedef BOOLEAN SECURITY_CONTEXT_TRACKING_MODE,
  1366. * PSECURITY_CONTEXT_TRACKING_MODE;
  1367. //
  1368. // Quality Of Service
  1369. //
  1370. typedef struct _SECURITY_QUALITY_OF_SERVICE {
  1371. ULONG Length;
  1372. SECURITY_IMPERSONATION_LEVEL ImpersonationLevel;
  1373. SECURITY_CONTEXT_TRACKING_MODE ContextTrackingMode;
  1374. BOOLEAN EffectiveOnly;
  1375. } SECURITY_QUALITY_OF_SERVICE, * PSECURITY_QUALITY_OF_SERVICE;
  1376. //
  1377. // Used to represent information related to a thread impersonation
  1378. //
  1379. typedef struct _SE_IMPERSONATION_STATE {
  1380. PACCESS_TOKEN Token;
  1381. BOOLEAN CopyOnOpen;
  1382. BOOLEAN EffectiveOnly;
  1383. SECURITY_IMPERSONATION_LEVEL Level;
  1384. } SE_IMPERSONATION_STATE, *PSE_IMPERSONATION_STATE;
  1385. typedef ULONG SECURITY_INFORMATION, *PSECURITY_INFORMATION;
  1386. #define OWNER_SECURITY_INFORMATION (0x00000001L)
  1387. #define GROUP_SECURITY_INFORMATION (0x00000002L)
  1388. #define DACL_SECURITY_INFORMATION (0x00000004L)
  1389. #define SACL_SECURITY_INFORMATION (0x00000008L)
  1390. #define PROTECTED_DACL_SECURITY_INFORMATION (0x80000000L)
  1391. #define PROTECTED_SACL_SECURITY_INFORMATION (0x40000000L)
  1392. #define UNPROTECTED_DACL_SECURITY_INFORMATION (0x20000000L)
  1393. #define UNPROTECTED_SACL_SECURITY_INFORMATION (0x10000000L)
  1394. #define LOW_PRIORITY 0 // Lowest thread priority level
  1395. #define LOW_REALTIME_PRIORITY 16 // Lowest realtime priority level
  1396. #define HIGH_PRIORITY 31 // Highest thread priority level
  1397. #define MAXIMUM_PRIORITY 32 // Number of thread priority levels
  1398. // begin_winnt
  1399. #define MAXIMUM_WAIT_OBJECTS 64 // Maximum number of wait objects
  1400. #define MAXIMUM_SUSPEND_COUNT MAXCHAR // Maximum times thread can be suspended
  1401. // end_winnt
  1402. //
  1403. // Define system time structure.
  1404. //
  1405. typedef struct _KSYSTEM_TIME {
  1406. ULONG LowPart;
  1407. LONG High1Time;
  1408. LONG High2Time;
  1409. } KSYSTEM_TIME, *PKSYSTEM_TIME;
  1410. //
  1411. // Thread priority
  1412. //
  1413. typedef LONG KPRIORITY;
  1414. //
  1415. // Spin Lock
  1416. //
  1417. // begin_ntndis begin_winnt
  1418. typedef ULONG_PTR KSPIN_LOCK;
  1419. typedef KSPIN_LOCK *PKSPIN_LOCK;
  1420. // end_ntndis end_winnt end_wdm
  1421. //
  1422. // Define per processor lock queue structure.
  1423. //
  1424. // N.B. The lock field of the spin lock queue structure contains the address
  1425. // of the associated kernel spin lock, an owner bit, and a lock bit. Bit
  1426. // 0 of the spin lock address is the wait bit and bit 1 is the owner bit.
  1427. // The use of this field is such that the bits can be set and cleared
  1428. // noninterlocked, however, the back pointer must be preserved.
  1429. //
  1430. // The lock wait bit is set when a processor enqueues itself on the lock
  1431. // queue and it is not the only entry in the queue. The processor will
  1432. // spin on this bit waiting for the lock to be granted.
  1433. //
  1434. // The owner bit is set when the processor owns the respective lock.
  1435. //
  1436. // The next field of the spin lock queue structure is used to line the
  1437. // queued lock structures together in fifo order. It also can set set and
  1438. // cleared noninterlocked.
  1439. //
  1440. #define LOCK_QUEUE_WAIT 1
  1441. #define LOCK_QUEUE_OWNER 2
  1442. typedef enum _KSPIN_LOCK_QUEUE_NUMBER {
  1443. LockQueueDispatcherLock,
  1444. LockQueueContextSwapLock,
  1445. LockQueuePfnLock,
  1446. LockQueueSystemSpaceLock,
  1447. LockQueueVacbLock,
  1448. LockQueueMasterLock,
  1449. LockQueueNonPagedPoolLock,
  1450. LockQueueIoCancelLock,
  1451. LockQueueWorkQueueLock,
  1452. LockQueueIoVpbLock,
  1453. LockQueueIoDatabaseLock,
  1454. LockQueueIoCompletionLock,
  1455. LockQueueNtfsStructLock,
  1456. LockQueueAfdWorkQueueLock,
  1457. LockQueueBcbLock,
  1458. LockQueueMaximumLock
  1459. } KSPIN_LOCK_QUEUE_NUMBER, *PKSPIN_LOCK_QUEUE_NUMBER;
  1460. typedef struct _KSPIN_LOCK_QUEUE {
  1461. struct _KSPIN_LOCK_QUEUE * volatile Next;
  1462. PKSPIN_LOCK volatile Lock;
  1463. } KSPIN_LOCK_QUEUE, *PKSPIN_LOCK_QUEUE;
  1464. typedef struct _KLOCK_QUEUE_HANDLE {
  1465. KSPIN_LOCK_QUEUE LockQueue;
  1466. KIRQL OldIrql;
  1467. } KLOCK_QUEUE_HANDLE, *PKLOCK_QUEUE_HANDLE;
  1468. // begin_wdm
  1469. //
  1470. // Interrupt routine (first level dispatch)
  1471. //
  1472. typedef
  1473. VOID
  1474. (*PKINTERRUPT_ROUTINE) (
  1475. VOID
  1476. );
  1477. //
  1478. // Profile source types
  1479. //
  1480. typedef enum _KPROFILE_SOURCE {
  1481. ProfileTime,
  1482. ProfileAlignmentFixup,
  1483. ProfileTotalIssues,
  1484. ProfilePipelineDry,
  1485. ProfileLoadInstructions,
  1486. ProfilePipelineFrozen,
  1487. ProfileBranchInstructions,
  1488. ProfileTotalNonissues,
  1489. ProfileDcacheMisses,
  1490. ProfileIcacheMisses,
  1491. ProfileCacheMisses,
  1492. ProfileBranchMispredictions,
  1493. ProfileStoreInstructions,
  1494. ProfileFpInstructions,
  1495. ProfileIntegerInstructions,
  1496. Profile2Issue,
  1497. Profile3Issue,
  1498. Profile4Issue,
  1499. ProfileSpecialInstructions,
  1500. ProfileTotalCycles,
  1501. ProfileIcacheIssues,
  1502. ProfileDcacheAccesses,
  1503. ProfileMemoryBarrierCycles,
  1504. ProfileLoadLinkedIssues,
  1505. ProfileMaximum
  1506. } KPROFILE_SOURCE;
  1507. //
  1508. // for move macros
  1509. //
  1510. #ifdef _MAC
  1511. #ifndef _INC_STRING
  1512. #include <string.h>
  1513. #endif /* _INC_STRING */
  1514. #else
  1515. #include <string.h>
  1516. #endif // _MAC
  1517. #ifndef _SLIST_HEADER_
  1518. #define _SLIST_HEADER_
  1519. #define SLIST_ENTRY SINGLE_LIST_ENTRY
  1520. #define _SLIST_ENTRY _SINGLE_LIST_ENTRY
  1521. #define PSLIST_ENTRY PSINGLE_LIST_ENTRY
  1522. #if defined(_WIN64)
  1523. typedef struct DECLSPEC_ALIGN(16) _SLIST_HEADER {
  1524. ULONGLONG Alignment;
  1525. ULONGLONG Region;
  1526. } SLIST_HEADER;
  1527. typedef struct _SLIST_HEADER *PSLIST_HEADER;
  1528. #else
  1529. typedef union _SLIST_HEADER {
  1530. ULONGLONG Alignment;
  1531. struct {
  1532. SLIST_ENTRY Next;
  1533. USHORT Depth;
  1534. USHORT Sequence;
  1535. };
  1536. } SLIST_HEADER, *PSLIST_HEADER;
  1537. #endif
  1538. #endif
  1539. //
  1540. // If debugging support enabled, define an ASSERT macro that works. Otherwise
  1541. // define the ASSERT macro to expand to an empty expression.
  1542. //
  1543. // The ASSERT macro has been updated to be an expression instead of a statement.
  1544. //
  1545. #if DBG
  1546. NTSYSAPI
  1547. VOID
  1548. NTAPI
  1549. RtlAssert(
  1550. PVOID FailedAssertion,
  1551. PVOID FileName,
  1552. ULONG LineNumber,
  1553. PCHAR Message
  1554. );
  1555. #define ASSERT( exp ) \
  1556. ((!(exp)) ? \
  1557. (RtlAssert( #exp, __FILE__, __LINE__, NULL ),FALSE) : \
  1558. TRUE)
  1559. #define ASSERTMSG( msg, exp ) \
  1560. ((!(exp)) ? \
  1561. (RtlAssert( #exp, __FILE__, __LINE__, msg ),FALSE) : \
  1562. TRUE)
  1563. #define RTL_SOFT_ASSERT(_exp) \
  1564. ((!(_exp)) ? \
  1565. (DbgPrint("%s(%d): Soft assertion failed\n Expression: %s\n", __FILE__, __LINE__, #_exp),FALSE) : \
  1566. TRUE)
  1567. #define RTL_SOFT_ASSERTMSG(_msg, _exp) \
  1568. ((!(_exp)) ? \
  1569. (DbgPrint("%s(%d): Soft assertion failed\n Expression: %s\n Message: %s\n", __FILE__, __LINE__, #_exp, (_msg)),FALSE) : \
  1570. TRUE)
  1571. #define RTL_VERIFY( exp ) ASSERT(exp)
  1572. #define RTL_VERIFYMSG( msg, exp ) ASSERT(msg, exp)
  1573. #define RTL_SOFT_VERIFY(_exp) RTL_SOFT_ASSERT(_exp)
  1574. #define RTL_SOFT_VERIFYMSG(_msg, _exp) RTL_SOFT_ASSERTMSG(_msg, _exp)
  1575. #else
  1576. #define ASSERT( exp ) ((void) 0)
  1577. #define ASSERTMSG( msg, exp ) ((void) 0)
  1578. #define RTL_SOFT_ASSERT(_exp) ((void) 0)
  1579. #define RTL_SOFT_ASSERTMSG(_msg, _exp) ((void) 0)
  1580. #define RTL_VERIFY( exp ) ((exp) ? TRUE : FALSE)
  1581. #define RTL_VERIFYMSG( msg, exp ) ((exp) ? TRUE : FALSE)
  1582. #define RTL_SOFT_VERIFY(_exp) ((_exp) ? TRUE : FALSE)
  1583. #define RTL_SOFT_VERIFYMSG(msg, _exp) ((_exp) ? TRUE : FALSE)
  1584. #endif // DBG
  1585. //
  1586. // Doubly-linked list manipulation routines.
  1587. //
  1588. //
  1589. // VOID
  1590. // InitializeListHead32(
  1591. // PLIST_ENTRY32 ListHead
  1592. // );
  1593. //
  1594. #define InitializeListHead32(ListHead) (\
  1595. (ListHead)->Flink = (ListHead)->Blink = PtrToUlong((ListHead)))
  1596. #if !defined(MIDL_PASS) && !defined(SORTPP_PASS)
  1597. VOID
  1598. FORCEINLINE
  1599. InitializeListHead(
  1600. IN PLIST_ENTRY ListHead
  1601. )
  1602. {
  1603. ListHead->Flink = ListHead->Blink = ListHead;
  1604. }
  1605. //
  1606. // BOOLEAN
  1607. // IsListEmpty(
  1608. // PLIST_ENTRY ListHead
  1609. // );
  1610. //
  1611. #define IsListEmpty(ListHead) \
  1612. ((ListHead)->Flink == (ListHead))
  1613. VOID
  1614. FORCEINLINE
  1615. RemoveEntryList(
  1616. IN PLIST_ENTRY Entry
  1617. )
  1618. {
  1619. PLIST_ENTRY Blink;
  1620. PLIST_ENTRY Flink;
  1621. Flink = Entry->Flink;
  1622. Blink = Entry->Blink;
  1623. Blink->Flink = Flink;
  1624. Flink->Blink = Blink;
  1625. }
  1626. PLIST_ENTRY
  1627. FORCEINLINE
  1628. RemoveHeadList(
  1629. IN PLIST_ENTRY ListHead
  1630. )
  1631. {
  1632. PLIST_ENTRY Flink;
  1633. PLIST_ENTRY Entry;
  1634. Entry = ListHead->Flink;
  1635. Flink = Entry->Flink;
  1636. ListHead->Flink = Flink;
  1637. Flink->Blink = ListHead;
  1638. return Entry;
  1639. }
  1640. PLIST_ENTRY
  1641. FORCEINLINE
  1642. RemoveTailList(
  1643. IN PLIST_ENTRY ListHead
  1644. )
  1645. {
  1646. PLIST_ENTRY Blink;
  1647. PLIST_ENTRY Entry;
  1648. Entry = ListHead->Blink;
  1649. Blink = Entry->Blink;
  1650. ListHead->Blink = Blink;
  1651. Blink->Flink = ListHead;
  1652. return Entry;
  1653. }
  1654. VOID
  1655. FORCEINLINE
  1656. InsertTailList(
  1657. IN PLIST_ENTRY ListHead,
  1658. IN PLIST_ENTRY Entry
  1659. )
  1660. {
  1661. PLIST_ENTRY Blink;
  1662. Blink = ListHead->Blink;
  1663. Entry->Flink = ListHead;
  1664. Entry->Blink = Blink;
  1665. Blink->Flink = Entry;
  1666. ListHead->Blink = Entry;
  1667. }
  1668. VOID
  1669. FORCEINLINE
  1670. InsertHeadList(
  1671. IN PLIST_ENTRY ListHead,
  1672. IN PLIST_ENTRY Entry
  1673. )
  1674. {
  1675. PLIST_ENTRY Flink;
  1676. Flink = ListHead->Flink;
  1677. Entry->Flink = Flink;
  1678. Entry->Blink = ListHead;
  1679. Flink->Blink = Entry;
  1680. ListHead->Flink = Entry;
  1681. }
  1682. //
  1683. //
  1684. // PSINGLE_LIST_ENTRY
  1685. // PopEntryList(
  1686. // PSINGLE_LIST_ENTRY ListHead
  1687. // );
  1688. //
  1689. #define PopEntryList(ListHead) \
  1690. (ListHead)->Next;\
  1691. {\
  1692. PSINGLE_LIST_ENTRY FirstEntry;\
  1693. FirstEntry = (ListHead)->Next;\
  1694. if (FirstEntry != NULL) { \
  1695. (ListHead)->Next = FirstEntry->Next;\
  1696. } \
  1697. }
  1698. //
  1699. // VOID
  1700. // PushEntryList(
  1701. // PSINGLE_LIST_ENTRY ListHead,
  1702. // PSINGLE_LIST_ENTRY Entry
  1703. // );
  1704. //
  1705. #define PushEntryList(ListHead,Entry) \
  1706. (Entry)->Next = (ListHead)->Next; \
  1707. (ListHead)->Next = (Entry)
  1708. #endif // !MIDL_PASS
  1709. // end_wdm end_nthal end_ntifs end_ntndis
  1710. #if defined (_MSC_VER) && ( _MSC_VER >= 900 )
  1711. PVOID
  1712. _ReturnAddress (
  1713. VOID
  1714. );
  1715. #pragma intrinsic(_ReturnAddress)
  1716. #endif
  1717. #if (defined(_M_AMD64) || defined(_M_IA64)) && !defined(_REALLY_GET_CALLERS_CALLER_)
  1718. #define RtlGetCallersAddress(CallersAddress, CallersCaller) \
  1719. *CallersAddress = (PVOID)_ReturnAddress(); \
  1720. *CallersCaller = NULL;
  1721. #else
  1722. NTSYSAPI
  1723. VOID
  1724. NTAPI
  1725. RtlGetCallersAddress(
  1726. OUT PVOID *CallersAddress,
  1727. OUT PVOID *CallersCaller
  1728. );
  1729. #endif
  1730. NTSYSAPI
  1731. ULONG
  1732. NTAPI
  1733. RtlWalkFrameChain (
  1734. OUT PVOID *Callers,
  1735. IN ULONG Count,
  1736. IN ULONG Flags
  1737. );
  1738. //
  1739. // Subroutines for dealing with the Registry
  1740. //
  1741. typedef NTSTATUS (NTAPI * PRTL_QUERY_REGISTRY_ROUTINE)(
  1742. IN PWSTR ValueName,
  1743. IN ULONG ValueType,
  1744. IN PVOID ValueData,
  1745. IN ULONG ValueLength,
  1746. IN PVOID Context,
  1747. IN PVOID EntryContext
  1748. );
  1749. typedef struct _RTL_QUERY_REGISTRY_TABLE {
  1750. PRTL_QUERY_REGISTRY_ROUTINE QueryRoutine;
  1751. ULONG Flags;
  1752. PWSTR Name;
  1753. PVOID EntryContext;
  1754. ULONG DefaultType;
  1755. PVOID DefaultData;
  1756. ULONG DefaultLength;
  1757. } RTL_QUERY_REGISTRY_TABLE, *PRTL_QUERY_REGISTRY_TABLE;
  1758. //
  1759. // The following flags specify how the Name field of a RTL_QUERY_REGISTRY_TABLE
  1760. // entry is interpreted. A NULL name indicates the end of the table.
  1761. //
  1762. #define RTL_QUERY_REGISTRY_SUBKEY 0x00000001 // Name is a subkey and remainder of
  1763. // table or until next subkey are value
  1764. // names for that subkey to look at.
  1765. #define RTL_QUERY_REGISTRY_TOPKEY 0x00000002 // Reset current key to original key for
  1766. // this and all following table entries.
  1767. #define RTL_QUERY_REGISTRY_REQUIRED 0x00000004 // Fail if no match found for this table
  1768. // entry.
  1769. #define RTL_QUERY_REGISTRY_NOVALUE 0x00000008 // Used to mark a table entry that has no
  1770. // value name, just wants a call out, not
  1771. // an enumeration of all values.
  1772. #define RTL_QUERY_REGISTRY_NOEXPAND 0x00000010 // Used to suppress the expansion of
  1773. // REG_MULTI_SZ into multiple callouts or
  1774. // to prevent the expansion of environment
  1775. // variable values in REG_EXPAND_SZ
  1776. #define RTL_QUERY_REGISTRY_DIRECT 0x00000020 // QueryRoutine field ignored. EntryContext
  1777. // field points to location to store value.
  1778. // For null terminated strings, EntryContext
  1779. // points to UNICODE_STRING structure that
  1780. // that describes maximum size of buffer.
  1781. // If .Buffer field is NULL then a buffer is
  1782. // allocated.
  1783. //
  1784. #define RTL_QUERY_REGISTRY_DELETE 0x00000040 // Used to delete value keys after they
  1785. // are queried.
  1786. NTSYSAPI
  1787. NTSTATUS
  1788. NTAPI
  1789. RtlQueryRegistryValues(
  1790. IN ULONG RelativeTo,
  1791. IN PCWSTR Path,
  1792. IN PRTL_QUERY_REGISTRY_TABLE QueryTable,
  1793. IN PVOID Context,
  1794. IN PVOID Environment OPTIONAL
  1795. );
  1796. NTSYSAPI
  1797. NTSTATUS
  1798. NTAPI
  1799. RtlWriteRegistryValue(
  1800. IN ULONG RelativeTo,
  1801. IN PCWSTR Path,
  1802. IN PCWSTR ValueName,
  1803. IN ULONG ValueType,
  1804. IN PVOID ValueData,
  1805. IN ULONG ValueLength
  1806. );
  1807. NTSYSAPI
  1808. NTSTATUS
  1809. NTAPI
  1810. RtlDeleteRegistryValue(
  1811. IN ULONG RelativeTo,
  1812. IN PCWSTR Path,
  1813. IN PCWSTR ValueName
  1814. );
  1815. // end_wdm
  1816. NTSYSAPI
  1817. NTSTATUS
  1818. NTAPI
  1819. RtlCreateRegistryKey(
  1820. IN ULONG RelativeTo,
  1821. IN PWSTR Path
  1822. );
  1823. NTSYSAPI
  1824. NTSTATUS
  1825. NTAPI
  1826. RtlCheckRegistryKey(
  1827. IN ULONG RelativeTo,
  1828. IN PWSTR Path
  1829. );
  1830. // begin_wdm
  1831. //
  1832. // The following values for the RelativeTo parameter determine what the
  1833. // Path parameter to RtlQueryRegistryValues is relative to.
  1834. //
  1835. #define RTL_REGISTRY_ABSOLUTE 0 // Path is a full path
  1836. #define RTL_REGISTRY_SERVICES 1 // \Registry\Machine\System\CurrentControlSet\Services
  1837. #define RTL_REGISTRY_CONTROL 2 // \Registry\Machine\System\CurrentControlSet\Control
  1838. #define RTL_REGISTRY_WINDOWS_NT 3 // \Registry\Machine\Software\Microsoft\Windows NT\CurrentVersion
  1839. #define RTL_REGISTRY_DEVICEMAP 4 // \Registry\Machine\Hardware\DeviceMap
  1840. #define RTL_REGISTRY_USER 5 // \Registry\User\CurrentUser
  1841. #define RTL_REGISTRY_MAXIMUM 6
  1842. #define RTL_REGISTRY_HANDLE 0x40000000 // Low order bits are registry handle
  1843. #define RTL_REGISTRY_OPTIONAL 0x80000000 // Indicates the key node is optional
  1844. NTSYSAPI
  1845. NTSTATUS
  1846. NTAPI
  1847. RtlCharToInteger (
  1848. PCSZ String,
  1849. ULONG Base,
  1850. PULONG Value
  1851. );
  1852. NTSYSAPI
  1853. NTSTATUS
  1854. NTAPI
  1855. RtlIntegerToUnicodeString (
  1856. ULONG Value,
  1857. ULONG Base,
  1858. PUNICODE_STRING String
  1859. );
  1860. NTSYSAPI
  1861. NTSTATUS
  1862. NTAPI
  1863. RtlInt64ToUnicodeString (
  1864. IN ULONGLONG Value,
  1865. IN ULONG Base OPTIONAL,
  1866. IN OUT PUNICODE_STRING String
  1867. );
  1868. #ifdef _WIN64
  1869. #define RtlIntPtrToUnicodeString(Value, Base, String) RtlInt64ToUnicodeString(Value, Base, String)
  1870. #else
  1871. #define RtlIntPtrToUnicodeString(Value, Base, String) RtlIntegerToUnicodeString(Value, Base, String)
  1872. #endif
  1873. NTSYSAPI
  1874. NTSTATUS
  1875. NTAPI
  1876. RtlUnicodeStringToInteger (
  1877. PCUNICODE_STRING String,
  1878. ULONG Base,
  1879. PULONG Value
  1880. );
  1881. //
  1882. // String manipulation routines
  1883. //
  1884. #ifdef _NTSYSTEM_
  1885. #define NLS_MB_CODE_PAGE_TAG NlsMbCodePageTag
  1886. #define NLS_MB_OEM_CODE_PAGE_TAG NlsMbOemCodePageTag
  1887. #else
  1888. #define NLS_MB_CODE_PAGE_TAG (*NlsMbCodePageTag)
  1889. #define NLS_MB_OEM_CODE_PAGE_TAG (*NlsMbOemCodePageTag)
  1890. #endif // _NTSYSTEM_
  1891. extern BOOLEAN NLS_MB_CODE_PAGE_TAG; // TRUE -> Multibyte CP, FALSE -> Singlebyte
  1892. extern BOOLEAN NLS_MB_OEM_CODE_PAGE_TAG; // TRUE -> Multibyte CP, FALSE -> Singlebyte
  1893. NTSYSAPI
  1894. VOID
  1895. NTAPI
  1896. RtlInitString(
  1897. PSTRING DestinationString,
  1898. PCSZ SourceString
  1899. );
  1900. NTSYSAPI
  1901. VOID
  1902. NTAPI
  1903. RtlInitAnsiString(
  1904. PANSI_STRING DestinationString,
  1905. PCSZ SourceString
  1906. );
  1907. NTSYSAPI
  1908. VOID
  1909. NTAPI
  1910. RtlInitUnicodeString(
  1911. PUNICODE_STRING DestinationString,
  1912. PCWSTR SourceString
  1913. );
  1914. #define RtlInitEmptyUnicodeString(_ucStr,_buf,_bufSize) \
  1915. ((_ucStr)->Buffer = (_buf), \
  1916. (_ucStr)->Length = 0, \
  1917. (_ucStr)->MaximumLength = (USHORT)(_bufSize))
  1918. NTSYSAPI
  1919. VOID
  1920. NTAPI
  1921. RtlCopyString(
  1922. PSTRING DestinationString,
  1923. const STRING * SourceString
  1924. );
  1925. NTSYSAPI
  1926. CHAR
  1927. NTAPI
  1928. RtlUpperChar (
  1929. CHAR Character
  1930. );
  1931. NTSYSAPI
  1932. LONG
  1933. NTAPI
  1934. RtlCompareString(
  1935. const STRING * String1,
  1936. const STRING * String2,
  1937. BOOLEAN CaseInSensitive
  1938. );
  1939. NTSYSAPI
  1940. BOOLEAN
  1941. NTAPI
  1942. RtlEqualString(
  1943. const STRING * String1,
  1944. const STRING * String2,
  1945. BOOLEAN CaseInSensitive
  1946. );
  1947. NTSYSAPI
  1948. VOID
  1949. NTAPI
  1950. RtlUpperString(
  1951. PSTRING DestinationString,
  1952. const STRING * SourceString
  1953. );
  1954. //
  1955. // NLS String functions
  1956. //
  1957. NTSYSAPI
  1958. NTSTATUS
  1959. NTAPI
  1960. RtlAnsiStringToUnicodeString(
  1961. PUNICODE_STRING DestinationString,
  1962. PCANSI_STRING SourceString,
  1963. BOOLEAN AllocateDestinationString
  1964. );
  1965. NTSYSAPI
  1966. NTSTATUS
  1967. NTAPI
  1968. RtlUnicodeStringToAnsiString(
  1969. PANSI_STRING DestinationString,
  1970. PCUNICODE_STRING SourceString,
  1971. BOOLEAN AllocateDestinationString
  1972. );
  1973. NTSYSAPI
  1974. LONG
  1975. NTAPI
  1976. RtlCompareUnicodeString(
  1977. PCUNICODE_STRING String1,
  1978. PCUNICODE_STRING String2,
  1979. BOOLEAN CaseInSensitive
  1980. );
  1981. NTSYSAPI
  1982. BOOLEAN
  1983. NTAPI
  1984. RtlEqualUnicodeString(
  1985. const UNICODE_STRING *String1,
  1986. const UNICODE_STRING *String2,
  1987. BOOLEAN CaseInSensitive
  1988. );
  1989. #define HASH_STRING_ALGORITHM_DEFAULT (0)
  1990. #define HASH_STRING_ALGORITHM_X65599 (1)
  1991. #define HASH_STRING_ALGORITHM_INVALID (0xffffffff)
  1992. NTSYSAPI
  1993. NTSTATUS
  1994. NTAPI
  1995. RtlHashUnicodeString(
  1996. IN const UNICODE_STRING *String,
  1997. IN BOOLEAN CaseInSensitive,
  1998. IN ULONG HashAlgorithm,
  1999. OUT PULONG HashValue
  2000. );
  2001. NTSYSAPI
  2002. BOOLEAN
  2003. NTAPI
  2004. RtlPrefixUnicodeString(
  2005. IN PUNICODE_STRING String1,
  2006. IN PUNICODE_STRING String2,
  2007. IN BOOLEAN CaseInSensitive
  2008. );
  2009. NTSYSAPI
  2010. NTSTATUS
  2011. NTAPI
  2012. RtlUpcaseUnicodeString(
  2013. PUNICODE_STRING DestinationString,
  2014. PCUNICODE_STRING SourceString,
  2015. BOOLEAN AllocateDestinationString
  2016. );
  2017. NTSYSAPI
  2018. VOID
  2019. NTAPI
  2020. RtlCopyUnicodeString(
  2021. PUNICODE_STRING DestinationString,
  2022. PCUNICODE_STRING SourceString
  2023. );
  2024. NTSYSAPI
  2025. NTSTATUS
  2026. NTAPI
  2027. RtlAppendUnicodeStringToString (
  2028. PUNICODE_STRING Destination,
  2029. PCUNICODE_STRING Source
  2030. );
  2031. NTSYSAPI
  2032. NTSTATUS
  2033. NTAPI
  2034. RtlAppendUnicodeToString (
  2035. PUNICODE_STRING Destination,
  2036. PCWSTR Source
  2037. );
  2038. // end_ntndis end_wdm
  2039. NTSYSAPI
  2040. WCHAR
  2041. NTAPI
  2042. RtlUpcaseUnicodeChar(
  2043. WCHAR SourceCharacter
  2044. );
  2045. NTSYSAPI
  2046. WCHAR
  2047. NTAPI
  2048. RtlDowncaseUnicodeChar(
  2049. WCHAR SourceCharacter
  2050. );
  2051. // begin_wdm
  2052. NTSYSAPI
  2053. VOID
  2054. NTAPI
  2055. RtlFreeUnicodeString(
  2056. PUNICODE_STRING UnicodeString
  2057. );
  2058. NTSYSAPI
  2059. VOID
  2060. NTAPI
  2061. RtlFreeAnsiString(
  2062. PANSI_STRING AnsiString
  2063. );
  2064. NTSYSAPI
  2065. ULONG
  2066. NTAPI
  2067. RtlxAnsiStringToUnicodeSize(
  2068. PCANSI_STRING AnsiString
  2069. );
  2070. //
  2071. // NTSYSAPI
  2072. // ULONG
  2073. // NTAPI
  2074. // RtlAnsiStringToUnicodeSize(
  2075. // PANSI_STRING AnsiString
  2076. // );
  2077. //
  2078. #define RtlAnsiStringToUnicodeSize(STRING) ( \
  2079. NLS_MB_CODE_PAGE_TAG ? \
  2080. RtlxAnsiStringToUnicodeSize(STRING) : \
  2081. ((STRING)->Length + sizeof(ANSI_NULL)) * sizeof(WCHAR) \
  2082. )
  2083. // begin_ntminiport
  2084. #include <guiddef.h>
  2085. // end_ntminiport
  2086. #ifndef DEFINE_GUIDEX
  2087. #define DEFINE_GUIDEX(name) EXTERN_C const CDECL GUID name
  2088. #endif // !defined(DEFINE_GUIDEX)
  2089. #ifndef STATICGUIDOF
  2090. #define STATICGUIDOF(guid) STATIC_##guid
  2091. #endif // !defined(STATICGUIDOF)
  2092. #ifndef __IID_ALIGNED__
  2093. #define __IID_ALIGNED__
  2094. #ifdef __cplusplus
  2095. inline int IsEqualGUIDAligned(REFGUID guid1, REFGUID guid2)
  2096. {
  2097. return ((*(PLONGLONG)(&guid1) == *(PLONGLONG)(&guid2)) && (*((PLONGLONG)(&guid1) + 1) == *((PLONGLONG)(&guid2) + 1)));
  2098. }
  2099. #else // !__cplusplus
  2100. #define IsEqualGUIDAligned(guid1, guid2) \
  2101. ((*(PLONGLONG)(guid1) == *(PLONGLONG)(guid2)) && (*((PLONGLONG)(guid1) + 1) == *((PLONGLONG)(guid2) + 1)))
  2102. #endif // !__cplusplus
  2103. #endif // !__IID_ALIGNED__
  2104. NTSYSAPI
  2105. NTSTATUS
  2106. NTAPI
  2107. RtlStringFromGUID(
  2108. IN REFGUID Guid,
  2109. OUT PUNICODE_STRING GuidString
  2110. );
  2111. NTSYSAPI
  2112. NTSTATUS
  2113. NTAPI
  2114. RtlGUIDFromString(
  2115. IN PUNICODE_STRING GuidString,
  2116. OUT GUID* Guid
  2117. );
  2118. //
  2119. // Fast primitives to compare, move, and zero memory
  2120. //
  2121. // begin_winnt begin_ntndis
  2122. NTSYSAPI
  2123. SIZE_T
  2124. NTAPI
  2125. RtlCompareMemory (
  2126. const VOID *Source1,
  2127. const VOID *Source2,
  2128. SIZE_T Length
  2129. );
  2130. #if defined(_M_AMD64) || defined(_M_IA64)
  2131. #define RtlEqualMemory(Source1, Source2, Length) \
  2132. ((Length) == RtlCompareMemory(Source1, Source2, Length))
  2133. NTSYSAPI
  2134. VOID
  2135. NTAPI
  2136. RtlCopyMemory (
  2137. VOID UNALIGNED *Destination,
  2138. CONST VOID UNALIGNED *Source,
  2139. SIZE_T Length
  2140. );
  2141. #if !defined(_M_AMD64)
  2142. NTSYSAPI
  2143. VOID
  2144. NTAPI
  2145. RtlCopyMemory32 (
  2146. VOID UNALIGNED *Destination,
  2147. CONST VOID UNALIGNED *Source,
  2148. ULONG Length
  2149. );
  2150. #endif
  2151. NTSYSAPI
  2152. VOID
  2153. NTAPI
  2154. RtlMoveMemory (
  2155. VOID UNALIGNED *Destination,
  2156. CONST VOID UNALIGNED *Source,
  2157. SIZE_T Length
  2158. );
  2159. NTSYSAPI
  2160. VOID
  2161. NTAPI
  2162. RtlFillMemory (
  2163. VOID UNALIGNED *Destination,
  2164. SIZE_T Length,
  2165. UCHAR Fill
  2166. );
  2167. NTSYSAPI
  2168. VOID
  2169. NTAPI
  2170. RtlZeroMemory (
  2171. VOID UNALIGNED *Destination,
  2172. SIZE_T Length
  2173. );
  2174. #else
  2175. #define RtlEqualMemory(Destination,Source,Length) (!memcmp((Destination),(Source),(Length)))
  2176. #define RtlMoveMemory(Destination,Source,Length) memmove((Destination),(Source),(Length))
  2177. #define RtlCopyMemory(Destination,Source,Length) memcpy((Destination),(Source),(Length))
  2178. #define RtlFillMemory(Destination,Length,Fill) memset((Destination),(Fill),(Length))
  2179. #define RtlZeroMemory(Destination,Length) memset((Destination),0,(Length))
  2180. #endif
  2181. #if !defined(MIDL_PASS)
  2182. FORCEINLINE
  2183. PVOID
  2184. RtlSecureZeroMemory(
  2185. IN PVOID ptr,
  2186. IN SIZE_T cnt
  2187. )
  2188. {
  2189. volatile char *vptr = (volatile char *)ptr;
  2190. while (cnt) {
  2191. *vptr = 0;
  2192. vptr++;
  2193. cnt--;
  2194. }
  2195. return ptr;
  2196. }
  2197. #endif
  2198. // end_ntndis end_winnt
  2199. #define RtlCopyBytes RtlCopyMemory
  2200. #define RtlZeroBytes RtlZeroMemory
  2201. #define RtlFillBytes RtlFillMemory
  2202. #if defined(_M_AMD64)
  2203. NTSYSAPI
  2204. VOID
  2205. NTAPI
  2206. RtlCopyMemoryNonTemporal (
  2207. VOID UNALIGNED *Destination,
  2208. CONST VOID UNALIGNED *Source,
  2209. SIZE_T Length
  2210. );
  2211. #else
  2212. #define RtlCopyMemoryNonTemporal RtlCopyMemory
  2213. #endif
  2214. NTSYSAPI
  2215. VOID
  2216. FASTCALL
  2217. RtlPrefetchMemoryNonTemporal(
  2218. IN PVOID Source,
  2219. IN SIZE_T Length
  2220. );
  2221. //
  2222. // Define kernel debugger print prototypes and macros.
  2223. //
  2224. // N.B. The following function cannot be directly imported because there are
  2225. // a few places in the source tree where this function is redefined.
  2226. //
  2227. VOID
  2228. NTAPI
  2229. DbgBreakPoint(
  2230. VOID
  2231. );
  2232. // end_wdm
  2233. NTSYSAPI
  2234. VOID
  2235. NTAPI
  2236. DbgBreakPointWithStatus(
  2237. IN ULONG Status
  2238. );
  2239. // begin_wdm
  2240. #define DBG_STATUS_CONTROL_C 1
  2241. #define DBG_STATUS_SYSRQ 2
  2242. #define DBG_STATUS_BUGCHECK_FIRST 3
  2243. #define DBG_STATUS_BUGCHECK_SECOND 4
  2244. #define DBG_STATUS_FATAL 5
  2245. #define DBG_STATUS_DEBUG_CONTROL 6
  2246. #define DBG_STATUS_WORKER 7
  2247. #if DBG
  2248. #define KdPrint(_x_) DbgPrint _x_
  2249. // end_wdm
  2250. #define KdPrintEx(_x_) DbgPrintEx _x_
  2251. #define vKdPrintEx(_x_) vDbgPrintEx _x_
  2252. #define vKdPrintExWithPrefix(_x_) vDbgPrintExWithPrefix _x_
  2253. // begin_wdm
  2254. #define KdBreakPoint() DbgBreakPoint()
  2255. // end_wdm
  2256. #define KdBreakPointWithStatus(s) DbgBreakPointWithStatus(s)
  2257. // begin_wdm
  2258. #else
  2259. #define KdPrint(_x_)
  2260. // end_wdm
  2261. #define KdPrintEx(_x_)
  2262. #define vKdPrintEx(_x_)
  2263. #define vKdPrintExWithPrefix(_x_)
  2264. // begin_wdm
  2265. #define KdBreakPoint()
  2266. // end_wdm
  2267. #define KdBreakPointWithStatus(s)
  2268. // begin_wdm
  2269. #endif
  2270. #ifndef _DBGNT_
  2271. ULONG
  2272. __cdecl
  2273. DbgPrint(
  2274. PCH Format,
  2275. ...
  2276. );
  2277. // end_wdm
  2278. ULONG
  2279. __cdecl
  2280. DbgPrintEx(
  2281. IN ULONG ComponentId,
  2282. IN ULONG Level,
  2283. IN PCH Format,
  2284. ...
  2285. );
  2286. #ifdef _VA_LIST_DEFINED
  2287. ULONG
  2288. vDbgPrintEx(
  2289. IN ULONG ComponentId,
  2290. IN ULONG Level,
  2291. IN PCH Format,
  2292. va_list arglist
  2293. );
  2294. ULONG
  2295. vDbgPrintExWithPrefix(
  2296. IN PCH Prefix,
  2297. IN ULONG ComponentId,
  2298. IN ULONG Level,
  2299. IN PCH Format,
  2300. va_list arglist
  2301. );
  2302. #endif
  2303. ULONG
  2304. __cdecl
  2305. DbgPrintReturnControlC(
  2306. PCH Format,
  2307. ...
  2308. );
  2309. NTSYSAPI
  2310. NTSTATUS
  2311. DbgQueryDebugFilterState(
  2312. IN ULONG ComponentId,
  2313. IN ULONG Level
  2314. );
  2315. NTSYSAPI
  2316. NTSTATUS
  2317. DbgSetDebugFilterState(
  2318. IN ULONG ComponentId,
  2319. IN ULONG Level,
  2320. IN BOOLEAN State
  2321. );
  2322. // begin_wdm
  2323. #endif // _DBGNT_
  2324. //
  2325. // Large integer arithmetic routines.
  2326. //
  2327. //
  2328. // Large integer add - 64-bits + 64-bits -> 64-bits
  2329. //
  2330. #if !defined(MIDL_PASS)
  2331. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  2332. __inline
  2333. LARGE_INTEGER
  2334. NTAPI
  2335. RtlLargeIntegerAdd (
  2336. LARGE_INTEGER Addend1,
  2337. LARGE_INTEGER Addend2
  2338. )
  2339. {
  2340. LARGE_INTEGER Sum;
  2341. Sum.QuadPart = Addend1.QuadPart + Addend2.QuadPart;
  2342. return Sum;
  2343. }
  2344. //
  2345. // Enlarged integer multiply - 32-bits * 32-bits -> 64-bits
  2346. //
  2347. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  2348. __inline
  2349. LARGE_INTEGER
  2350. NTAPI
  2351. RtlEnlargedIntegerMultiply (
  2352. LONG Multiplicand,
  2353. LONG Multiplier
  2354. )
  2355. {
  2356. LARGE_INTEGER Product;
  2357. Product.QuadPart = (LONGLONG)Multiplicand * (ULONGLONG)Multiplier;
  2358. return Product;
  2359. }
  2360. //
  2361. // Unsigned enlarged integer multiply - 32-bits * 32-bits -> 64-bits
  2362. //
  2363. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  2364. __inline
  2365. LARGE_INTEGER
  2366. NTAPI
  2367. RtlEnlargedUnsignedMultiply (
  2368. ULONG Multiplicand,
  2369. ULONG Multiplier
  2370. )
  2371. {
  2372. LARGE_INTEGER Product;
  2373. Product.QuadPart = (ULONGLONG)Multiplicand * (ULONGLONG)Multiplier;
  2374. return Product;
  2375. }
  2376. //
  2377. // Enlarged integer divide - 64-bits / 32-bits > 32-bits
  2378. //
  2379. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  2380. __inline
  2381. ULONG
  2382. NTAPI
  2383. RtlEnlargedUnsignedDivide (
  2384. IN ULARGE_INTEGER Dividend,
  2385. IN ULONG Divisor,
  2386. IN PULONG Remainder OPTIONAL
  2387. )
  2388. {
  2389. ULONG Quotient;
  2390. Quotient = (ULONG)(Dividend.QuadPart / Divisor);
  2391. if (ARGUMENT_PRESENT(Remainder)) {
  2392. *Remainder = (ULONG)(Dividend.QuadPart % Divisor);
  2393. }
  2394. return Quotient;
  2395. }
  2396. //
  2397. // Large integer negation - -(64-bits)
  2398. //
  2399. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  2400. __inline
  2401. LARGE_INTEGER
  2402. NTAPI
  2403. RtlLargeIntegerNegate (
  2404. LARGE_INTEGER Subtrahend
  2405. )
  2406. {
  2407. LARGE_INTEGER Difference;
  2408. Difference.QuadPart = -Subtrahend.QuadPart;
  2409. return Difference;
  2410. }
  2411. //
  2412. // Large integer subtract - 64-bits - 64-bits -> 64-bits.
  2413. //
  2414. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  2415. __inline
  2416. LARGE_INTEGER
  2417. NTAPI
  2418. RtlLargeIntegerSubtract (
  2419. LARGE_INTEGER Minuend,
  2420. LARGE_INTEGER Subtrahend
  2421. )
  2422. {
  2423. LARGE_INTEGER Difference;
  2424. Difference.QuadPart = Minuend.QuadPart - Subtrahend.QuadPart;
  2425. return Difference;
  2426. }
  2427. //
  2428. // Extended large integer magic divide - 64-bits / 32-bits -> 64-bits
  2429. //
  2430. #if defined(_AMD64_)
  2431. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  2432. __inline
  2433. LARGE_INTEGER
  2434. NTAPI
  2435. RtlExtendedMagicDivide (
  2436. LARGE_INTEGER Dividend,
  2437. LARGE_INTEGER MagicDivisor,
  2438. CCHAR ShiftCount
  2439. )
  2440. {
  2441. LARGE_INTEGER Quotient;
  2442. Quotient.QuadPart = UnsignedMultiplyHigh((ULONG64)Dividend.QuadPart,
  2443. (ULONG64)MagicDivisor.QuadPart);
  2444. Quotient.QuadPart = (ULONG64)Quotient.QuadPart >> ShiftCount;
  2445. return Quotient;
  2446. }
  2447. #endif // defined(_AMD64_)
  2448. #if defined(_X86_) || defined(_IA64_)
  2449. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  2450. NTSYSAPI
  2451. LARGE_INTEGER
  2452. NTAPI
  2453. RtlExtendedMagicDivide (
  2454. LARGE_INTEGER Dividend,
  2455. LARGE_INTEGER MagicDivisor,
  2456. CCHAR ShiftCount
  2457. );
  2458. #endif // defined(_X86_) || defined(_IA64_)
  2459. #if defined(_AMD64_) || defined(_IA64_)
  2460. //
  2461. // Large Integer divide - 64-bits / 32-bits -> 64-bits
  2462. //
  2463. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  2464. __inline
  2465. LARGE_INTEGER
  2466. NTAPI
  2467. RtlExtendedLargeIntegerDivide (
  2468. LARGE_INTEGER Dividend,
  2469. ULONG Divisor,
  2470. PULONG Remainder OPTIONAL
  2471. )
  2472. {
  2473. LARGE_INTEGER Quotient;
  2474. Quotient.QuadPart = (ULONG64)Dividend.QuadPart / Divisor;
  2475. if (ARGUMENT_PRESENT(Remainder)) {
  2476. *Remainder = (ULONG)(Dividend.QuadPart % Divisor);
  2477. }
  2478. return Quotient;
  2479. }
  2480. // end_wdm
  2481. //
  2482. // Large Integer divide - 64-bits / 64-bits -> 64-bits
  2483. //
  2484. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  2485. __inline
  2486. LARGE_INTEGER
  2487. NTAPI
  2488. RtlLargeIntegerDivide (
  2489. LARGE_INTEGER Dividend,
  2490. LARGE_INTEGER Divisor,
  2491. PLARGE_INTEGER Remainder OPTIONAL
  2492. )
  2493. {
  2494. LARGE_INTEGER Quotient;
  2495. Quotient.QuadPart = Dividend.QuadPart / Divisor.QuadPart;
  2496. if (ARGUMENT_PRESENT(Remainder)) {
  2497. Remainder->QuadPart = Dividend.QuadPart % Divisor.QuadPart;
  2498. }
  2499. return Quotient;
  2500. }
  2501. // begin_wdm
  2502. //
  2503. // Extended integer multiply - 32-bits * 64-bits -> 64-bits
  2504. //
  2505. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  2506. __inline
  2507. LARGE_INTEGER
  2508. NTAPI
  2509. RtlExtendedIntegerMultiply (
  2510. LARGE_INTEGER Multiplicand,
  2511. LONG Multiplier
  2512. )
  2513. {
  2514. LARGE_INTEGER Product;
  2515. Product.QuadPart = Multiplicand.QuadPart * Multiplier;
  2516. return Product;
  2517. }
  2518. #else
  2519. //
  2520. // Large Integer divide - 64-bits / 32-bits -> 64-bits
  2521. //
  2522. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  2523. NTSYSAPI
  2524. LARGE_INTEGER
  2525. NTAPI
  2526. RtlExtendedLargeIntegerDivide (
  2527. LARGE_INTEGER Dividend,
  2528. ULONG Divisor,
  2529. PULONG Remainder
  2530. );
  2531. // end_wdm
  2532. //
  2533. // Large Integer divide - 64-bits / 64-bits -> 64-bits
  2534. //
  2535. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  2536. NTSYSAPI
  2537. LARGE_INTEGER
  2538. NTAPI
  2539. RtlLargeIntegerDivide (
  2540. LARGE_INTEGER Dividend,
  2541. LARGE_INTEGER Divisor,
  2542. PLARGE_INTEGER Remainder
  2543. );
  2544. // begin_wdm
  2545. //
  2546. // Extended integer multiply - 32-bits * 64-bits -> 64-bits
  2547. //
  2548. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  2549. NTSYSAPI
  2550. LARGE_INTEGER
  2551. NTAPI
  2552. RtlExtendedIntegerMultiply (
  2553. LARGE_INTEGER Multiplicand,
  2554. LONG Multiplier
  2555. );
  2556. #endif // defined(_AMD64_) || defined(_IA64_)
  2557. //
  2558. // Large integer and - 64-bite & 64-bits -> 64-bits.
  2559. //
  2560. #if PRAGMA_DEPRECATED_DDK
  2561. #pragma deprecated(RtlLargeIntegerAnd) // Use native __int64 math
  2562. #endif
  2563. #define RtlLargeIntegerAnd(Result, Source, Mask) \
  2564. Result.QuadPart = Source.QuadPart & Mask.QuadPart
  2565. //
  2566. // Convert signed integer to large integer.
  2567. //
  2568. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  2569. __inline
  2570. LARGE_INTEGER
  2571. NTAPI
  2572. RtlConvertLongToLargeInteger (
  2573. LONG SignedInteger
  2574. )
  2575. {
  2576. LARGE_INTEGER Result;
  2577. Result.QuadPart = SignedInteger;
  2578. return Result;
  2579. }
  2580. //
  2581. // Convert unsigned integer to large integer.
  2582. //
  2583. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  2584. __inline
  2585. LARGE_INTEGER
  2586. NTAPI
  2587. RtlConvertUlongToLargeInteger (
  2588. ULONG UnsignedInteger
  2589. )
  2590. {
  2591. LARGE_INTEGER Result;
  2592. Result.QuadPart = UnsignedInteger;
  2593. return Result;
  2594. }
  2595. //
  2596. // Large integer shift routines.
  2597. //
  2598. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  2599. __inline
  2600. LARGE_INTEGER
  2601. NTAPI
  2602. RtlLargeIntegerShiftLeft (
  2603. LARGE_INTEGER LargeInteger,
  2604. CCHAR ShiftCount
  2605. )
  2606. {
  2607. LARGE_INTEGER Result;
  2608. Result.QuadPart = LargeInteger.QuadPart << ShiftCount;
  2609. return Result;
  2610. }
  2611. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  2612. __inline
  2613. LARGE_INTEGER
  2614. NTAPI
  2615. RtlLargeIntegerShiftRight (
  2616. LARGE_INTEGER LargeInteger,
  2617. CCHAR ShiftCount
  2618. )
  2619. {
  2620. LARGE_INTEGER Result;
  2621. Result.QuadPart = (ULONG64)LargeInteger.QuadPart >> ShiftCount;
  2622. return Result;
  2623. }
  2624. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  2625. __inline
  2626. LARGE_INTEGER
  2627. NTAPI
  2628. RtlLargeIntegerArithmeticShift (
  2629. LARGE_INTEGER LargeInteger,
  2630. CCHAR ShiftCount
  2631. )
  2632. {
  2633. LARGE_INTEGER Result;
  2634. Result.QuadPart = LargeInteger.QuadPart >> ShiftCount;
  2635. return Result;
  2636. }
  2637. //
  2638. // Large integer comparison routines.
  2639. //
  2640. #if PRAGMA_DEPRECATED_DDK
  2641. #pragma deprecated(RtlLargeIntegerGreaterThan) // Use native __int64 math
  2642. #pragma deprecated(RtlLargeIntegerGreaterThanOrEqualTo) // Use native __int64 math
  2643. #pragma deprecated(RtlLargeIntegerEqualTo) // Use native __int64 math
  2644. #pragma deprecated(RtlLargeIntegerNotEqualTo) // Use native __int64 math
  2645. #pragma deprecated(RtlLargeIntegerLessThan) // Use native __int64 math
  2646. #pragma deprecated(RtlLargeIntegerLessThanOrEqualTo) // Use native __int64 math
  2647. #pragma deprecated(RtlLargeIntegerGreaterThanZero) // Use native __int64 math
  2648. #pragma deprecated(RtlLargeIntegerGreaterOrEqualToZero) // Use native __int64 math
  2649. #pragma deprecated(RtlLargeIntegerEqualToZero) // Use native __int64 math
  2650. #pragma deprecated(RtlLargeIntegerNotEqualToZero) // Use native __int64 math
  2651. #pragma deprecated(RtlLargeIntegerLessThanZero) // Use native __int64 math
  2652. #pragma deprecated(RtlLargeIntegerLessOrEqualToZero) // Use native __int64 math
  2653. #endif
  2654. #define RtlLargeIntegerGreaterThan(X,Y) ( \
  2655. (((X).HighPart == (Y).HighPart) && ((X).LowPart > (Y).LowPart)) || \
  2656. ((X).HighPart > (Y).HighPart) \
  2657. )
  2658. #define RtlLargeIntegerGreaterThanOrEqualTo(X,Y) ( \
  2659. (((X).HighPart == (Y).HighPart) && ((X).LowPart >= (Y).LowPart)) || \
  2660. ((X).HighPart > (Y).HighPart) \
  2661. )
  2662. #define RtlLargeIntegerEqualTo(X,Y) ( \
  2663. !(((X).LowPart ^ (Y).LowPart) | ((X).HighPart ^ (Y).HighPart)) \
  2664. )
  2665. #define RtlLargeIntegerNotEqualTo(X,Y) ( \
  2666. (((X).LowPart ^ (Y).LowPart) | ((X).HighPart ^ (Y).HighPart)) \
  2667. )
  2668. #define RtlLargeIntegerLessThan(X,Y) ( \
  2669. (((X).HighPart == (Y).HighPart) && ((X).LowPart < (Y).LowPart)) || \
  2670. ((X).HighPart < (Y).HighPart) \
  2671. )
  2672. #define RtlLargeIntegerLessThanOrEqualTo(X,Y) ( \
  2673. (((X).HighPart == (Y).HighPart) && ((X).LowPart <= (Y).LowPart)) || \
  2674. ((X).HighPart < (Y).HighPart) \
  2675. )
  2676. #define RtlLargeIntegerGreaterThanZero(X) ( \
  2677. (((X).HighPart == 0) && ((X).LowPart > 0)) || \
  2678. ((X).HighPart > 0 ) \
  2679. )
  2680. #define RtlLargeIntegerGreaterOrEqualToZero(X) ( \
  2681. (X).HighPart >= 0 \
  2682. )
  2683. #define RtlLargeIntegerEqualToZero(X) ( \
  2684. !((X).LowPart | (X).HighPart) \
  2685. )
  2686. #define RtlLargeIntegerNotEqualToZero(X) ( \
  2687. ((X).LowPart | (X).HighPart) \
  2688. )
  2689. #define RtlLargeIntegerLessThanZero(X) ( \
  2690. ((X).HighPart < 0) \
  2691. )
  2692. #define RtlLargeIntegerLessOrEqualToZero(X) ( \
  2693. ((X).HighPart < 0) || !((X).LowPart | (X).HighPart) \
  2694. )
  2695. #endif // !defined(MIDL_PASS)
  2696. //
  2697. // Time conversion routines
  2698. //
  2699. typedef struct _TIME_FIELDS {
  2700. CSHORT Year; // range [1601...]
  2701. CSHORT Month; // range [1..12]
  2702. CSHORT Day; // range [1..31]
  2703. CSHORT Hour; // range [0..23]
  2704. CSHORT Minute; // range [0..59]
  2705. CSHORT Second; // range [0..59]
  2706. CSHORT Milliseconds;// range [0..999]
  2707. CSHORT Weekday; // range [0..6] == [Sunday..Saturday]
  2708. } TIME_FIELDS;
  2709. typedef TIME_FIELDS *PTIME_FIELDS;
  2710. NTSYSAPI
  2711. VOID
  2712. NTAPI
  2713. RtlTimeToTimeFields (
  2714. PLARGE_INTEGER Time,
  2715. PTIME_FIELDS TimeFields
  2716. );
  2717. //
  2718. // A time field record (Weekday ignored) -> 64 bit Time value
  2719. //
  2720. NTSYSAPI
  2721. BOOLEAN
  2722. NTAPI
  2723. RtlTimeFieldsToTime (
  2724. PTIME_FIELDS TimeFields,
  2725. PLARGE_INTEGER Time
  2726. );
  2727. //
  2728. // The following macros store and retrieve USHORTS and ULONGS from potentially
  2729. // unaligned addresses, avoiding alignment faults. they should probably be
  2730. // rewritten in assembler
  2731. //
  2732. #define SHORT_SIZE (sizeof(USHORT))
  2733. #define SHORT_MASK (SHORT_SIZE - 1)
  2734. #define LONG_SIZE (sizeof(LONG))
  2735. #define LONGLONG_SIZE (sizeof(LONGLONG))
  2736. #define LONG_MASK (LONG_SIZE - 1)
  2737. #define LONGLONG_MASK (LONGLONG_SIZE - 1)
  2738. #define LOWBYTE_MASK 0x00FF
  2739. #define FIRSTBYTE(VALUE) ((VALUE) & LOWBYTE_MASK)
  2740. #define SECONDBYTE(VALUE) (((VALUE) >> 8) & LOWBYTE_MASK)
  2741. #define THIRDBYTE(VALUE) (((VALUE) >> 16) & LOWBYTE_MASK)
  2742. #define FOURTHBYTE(VALUE) (((VALUE) >> 24) & LOWBYTE_MASK)
  2743. //
  2744. // if MIPS Big Endian, order of bytes is reversed.
  2745. //
  2746. #define SHORT_LEAST_SIGNIFICANT_BIT 0
  2747. #define SHORT_MOST_SIGNIFICANT_BIT 1
  2748. #define LONG_LEAST_SIGNIFICANT_BIT 0
  2749. #define LONG_3RD_MOST_SIGNIFICANT_BIT 1
  2750. #define LONG_2ND_MOST_SIGNIFICANT_BIT 2
  2751. #define LONG_MOST_SIGNIFICANT_BIT 3
  2752. //++
  2753. //
  2754. // VOID
  2755. // RtlStoreUshort (
  2756. // PUSHORT ADDRESS
  2757. // USHORT VALUE
  2758. // )
  2759. //
  2760. // Routine Description:
  2761. //
  2762. // This macro stores a USHORT value in at a particular address, avoiding
  2763. // alignment faults.
  2764. //
  2765. // Arguments:
  2766. //
  2767. // ADDRESS - where to store USHORT value
  2768. // VALUE - USHORT to store
  2769. //
  2770. // Return Value:
  2771. //
  2772. // none.
  2773. //
  2774. //--
  2775. #define RtlStoreUshort(ADDRESS,VALUE) \
  2776. if ((ULONG_PTR)(ADDRESS) & SHORT_MASK) { \
  2777. ((PUCHAR) (ADDRESS))[SHORT_LEAST_SIGNIFICANT_BIT] = (UCHAR)(FIRSTBYTE(VALUE)); \
  2778. ((PUCHAR) (ADDRESS))[SHORT_MOST_SIGNIFICANT_BIT ] = (UCHAR)(SECONDBYTE(VALUE)); \
  2779. } \
  2780. else { \
  2781. *((PUSHORT) (ADDRESS)) = (USHORT) VALUE; \
  2782. }
  2783. //++
  2784. //
  2785. // VOID
  2786. // RtlStoreUlong (
  2787. // PULONG ADDRESS
  2788. // ULONG VALUE
  2789. // )
  2790. //
  2791. // Routine Description:
  2792. //
  2793. // This macro stores a ULONG value in at a particular address, avoiding
  2794. // alignment faults.
  2795. //
  2796. // Arguments:
  2797. //
  2798. // ADDRESS - where to store ULONG value
  2799. // VALUE - ULONG to store
  2800. //
  2801. // Return Value:
  2802. //
  2803. // none.
  2804. //
  2805. // Note:
  2806. // Depending on the machine, we might want to call storeushort in the
  2807. // unaligned case.
  2808. //
  2809. //--
  2810. #define RtlStoreUlong(ADDRESS,VALUE) \
  2811. if ((ULONG_PTR)(ADDRESS) & LONG_MASK) { \
  2812. ((PUCHAR) (ADDRESS))[LONG_LEAST_SIGNIFICANT_BIT ] = (UCHAR)(FIRSTBYTE(VALUE)); \
  2813. ((PUCHAR) (ADDRESS))[LONG_3RD_MOST_SIGNIFICANT_BIT ] = (UCHAR)(SECONDBYTE(VALUE)); \
  2814. ((PUCHAR) (ADDRESS))[LONG_2ND_MOST_SIGNIFICANT_BIT ] = (UCHAR)(THIRDBYTE(VALUE)); \
  2815. ((PUCHAR) (ADDRESS))[LONG_MOST_SIGNIFICANT_BIT ] = (UCHAR)(FOURTHBYTE(VALUE)); \
  2816. } \
  2817. else { \
  2818. *((PULONG) (ADDRESS)) = (ULONG) (VALUE); \
  2819. }
  2820. //++
  2821. //
  2822. // VOID
  2823. // RtlStoreUlonglong (
  2824. // PULONGLONG ADDRESS
  2825. // ULONG VALUE
  2826. // )
  2827. //
  2828. // Routine Description:
  2829. //
  2830. // This macro stores a ULONGLONG value in at a particular address, avoiding
  2831. // alignment faults.
  2832. //
  2833. // Arguments:
  2834. //
  2835. // ADDRESS - where to store ULONGLONG value
  2836. // VALUE - ULONGLONG to store
  2837. //
  2838. // Return Value:
  2839. //
  2840. // none.
  2841. //
  2842. //--
  2843. #define RtlStoreUlonglong(ADDRESS,VALUE) \
  2844. if ((ULONG_PTR)(ADDRESS) & LONGLONG_MASK) { \
  2845. RtlStoreUlong((ULONG_PTR)(ADDRESS), \
  2846. (ULONGLONG)(VALUE) & 0xFFFFFFFF); \
  2847. RtlStoreUlong((ULONG_PTR)(ADDRESS)+sizeof(ULONG), \
  2848. (ULONGLONG)(VALUE) >> 32); \
  2849. } else { \
  2850. *((PULONGLONG)(ADDRESS)) = (ULONGLONG)(VALUE); \
  2851. }
  2852. //++
  2853. //
  2854. // VOID
  2855. // RtlStoreUlongPtr (
  2856. // PULONG_PTR ADDRESS
  2857. // ULONG_PTR VALUE
  2858. // )
  2859. //
  2860. // Routine Description:
  2861. //
  2862. // This macro stores a ULONG_PTR value in at a particular address, avoiding
  2863. // alignment faults.
  2864. //
  2865. // Arguments:
  2866. //
  2867. // ADDRESS - where to store ULONG_PTR value
  2868. // VALUE - ULONG_PTR to store
  2869. //
  2870. // Return Value:
  2871. //
  2872. // none.
  2873. //
  2874. //--
  2875. #ifdef _WIN64
  2876. #define RtlStoreUlongPtr(ADDRESS,VALUE) \
  2877. RtlStoreUlonglong(ADDRESS,VALUE)
  2878. #else
  2879. #define RtlStoreUlongPtr(ADDRESS,VALUE) \
  2880. RtlStoreUlong(ADDRESS,VALUE)
  2881. #endif
  2882. //++
  2883. //
  2884. // VOID
  2885. // RtlRetrieveUshort (
  2886. // PUSHORT DESTINATION_ADDRESS
  2887. // PUSHORT SOURCE_ADDRESS
  2888. // )
  2889. //
  2890. // Routine Description:
  2891. //
  2892. // This macro retrieves a USHORT value from the SOURCE address, avoiding
  2893. // alignment faults. The DESTINATION address is assumed to be aligned.
  2894. //
  2895. // Arguments:
  2896. //
  2897. // DESTINATION_ADDRESS - where to store USHORT value
  2898. // SOURCE_ADDRESS - where to retrieve USHORT value from
  2899. //
  2900. // Return Value:
  2901. //
  2902. // none.
  2903. //
  2904. //--
  2905. #define RtlRetrieveUshort(DEST_ADDRESS,SRC_ADDRESS) \
  2906. if ((ULONG_PTR)SRC_ADDRESS & SHORT_MASK) { \
  2907. ((PUCHAR) DEST_ADDRESS)[0] = ((PUCHAR) SRC_ADDRESS)[0]; \
  2908. ((PUCHAR) DEST_ADDRESS)[1] = ((PUCHAR) SRC_ADDRESS)[1]; \
  2909. } \
  2910. else { \
  2911. *((PUSHORT) DEST_ADDRESS) = *((PUSHORT) SRC_ADDRESS); \
  2912. } \
  2913. //++
  2914. //
  2915. // VOID
  2916. // RtlRetrieveUlong (
  2917. // PULONG DESTINATION_ADDRESS
  2918. // PULONG SOURCE_ADDRESS
  2919. // )
  2920. //
  2921. // Routine Description:
  2922. //
  2923. // This macro retrieves a ULONG value from the SOURCE address, avoiding
  2924. // alignment faults. The DESTINATION address is assumed to be aligned.
  2925. //
  2926. // Arguments:
  2927. //
  2928. // DESTINATION_ADDRESS - where to store ULONG value
  2929. // SOURCE_ADDRESS - where to retrieve ULONG value from
  2930. //
  2931. // Return Value:
  2932. //
  2933. // none.
  2934. //
  2935. // Note:
  2936. // Depending on the machine, we might want to call retrieveushort in the
  2937. // unaligned case.
  2938. //
  2939. //--
  2940. #define RtlRetrieveUlong(DEST_ADDRESS,SRC_ADDRESS) \
  2941. if ((ULONG_PTR)SRC_ADDRESS & LONG_MASK) { \
  2942. ((PUCHAR) DEST_ADDRESS)[0] = ((PUCHAR) SRC_ADDRESS)[0]; \
  2943. ((PUCHAR) DEST_ADDRESS)[1] = ((PUCHAR) SRC_ADDRESS)[1]; \
  2944. ((PUCHAR) DEST_ADDRESS)[2] = ((PUCHAR) SRC_ADDRESS)[2]; \
  2945. ((PUCHAR) DEST_ADDRESS)[3] = ((PUCHAR) SRC_ADDRESS)[3]; \
  2946. } \
  2947. else { \
  2948. *((PULONG) DEST_ADDRESS) = *((PULONG) SRC_ADDRESS); \
  2949. }
  2950. //
  2951. // BitMap routines. The following structure, routines, and macros are
  2952. // for manipulating bitmaps. The user is responsible for allocating a bitmap
  2953. // structure (which is really a header) and a buffer (which must be longword
  2954. // aligned and multiple longwords in size).
  2955. //
  2956. typedef struct _RTL_BITMAP {
  2957. ULONG SizeOfBitMap; // Number of bits in bit map
  2958. PULONG Buffer; // Pointer to the bit map itself
  2959. } RTL_BITMAP;
  2960. typedef RTL_BITMAP *PRTL_BITMAP;
  2961. //
  2962. // The following routine initializes a new bitmap. It does not alter the
  2963. // data currently in the bitmap. This routine must be called before
  2964. // any other bitmap routine/macro.
  2965. //
  2966. NTSYSAPI
  2967. VOID
  2968. NTAPI
  2969. RtlInitializeBitMap (
  2970. PRTL_BITMAP BitMapHeader,
  2971. PULONG BitMapBuffer,
  2972. ULONG SizeOfBitMap
  2973. );
  2974. //
  2975. // The following three routines clear, set, and test the state of a
  2976. // single bit in a bitmap.
  2977. //
  2978. NTSYSAPI
  2979. VOID
  2980. NTAPI
  2981. RtlClearBit (
  2982. PRTL_BITMAP BitMapHeader,
  2983. ULONG BitNumber
  2984. );
  2985. NTSYSAPI
  2986. VOID
  2987. NTAPI
  2988. RtlSetBit (
  2989. PRTL_BITMAP BitMapHeader,
  2990. ULONG BitNumber
  2991. );
  2992. NTSYSAPI
  2993. BOOLEAN
  2994. NTAPI
  2995. RtlTestBit (
  2996. PRTL_BITMAP BitMapHeader,
  2997. ULONG BitNumber
  2998. );
  2999. //
  3000. // The following two routines either clear or set all of the bits
  3001. // in a bitmap.
  3002. //
  3003. NTSYSAPI
  3004. VOID
  3005. NTAPI
  3006. RtlClearAllBits (
  3007. PRTL_BITMAP BitMapHeader
  3008. );
  3009. NTSYSAPI
  3010. VOID
  3011. NTAPI
  3012. RtlSetAllBits (
  3013. PRTL_BITMAP BitMapHeader
  3014. );
  3015. //
  3016. // The following two routines locate a contiguous region of either
  3017. // clear or set bits within the bitmap. The region will be at least
  3018. // as large as the number specified, and the search of the bitmap will
  3019. // begin at the specified hint index (which is a bit index within the
  3020. // bitmap, zero based). The return value is the bit index of the located
  3021. // region (zero based) or -1 (i.e., 0xffffffff) if such a region cannot
  3022. // be located
  3023. //
  3024. NTSYSAPI
  3025. ULONG
  3026. NTAPI
  3027. RtlFindClearBits (
  3028. PRTL_BITMAP BitMapHeader,
  3029. ULONG NumberToFind,
  3030. ULONG HintIndex
  3031. );
  3032. NTSYSAPI
  3033. ULONG
  3034. NTAPI
  3035. RtlFindSetBits (
  3036. PRTL_BITMAP BitMapHeader,
  3037. ULONG NumberToFind,
  3038. ULONG HintIndex
  3039. );
  3040. //
  3041. // The following two routines locate a contiguous region of either
  3042. // clear or set bits within the bitmap and either set or clear the bits
  3043. // within the located region. The region will be as large as the number
  3044. // specified, and the search for the region will begin at the specified
  3045. // hint index (which is a bit index within the bitmap, zero based). The
  3046. // return value is the bit index of the located region (zero based) or
  3047. // -1 (i.e., 0xffffffff) if such a region cannot be located. If a region
  3048. // cannot be located then the setting/clearing of the bitmap is not performed.
  3049. //
  3050. NTSYSAPI
  3051. ULONG
  3052. NTAPI
  3053. RtlFindClearBitsAndSet (
  3054. PRTL_BITMAP BitMapHeader,
  3055. ULONG NumberToFind,
  3056. ULONG HintIndex
  3057. );
  3058. NTSYSAPI
  3059. ULONG
  3060. NTAPI
  3061. RtlFindSetBitsAndClear (
  3062. PRTL_BITMAP BitMapHeader,
  3063. ULONG NumberToFind,
  3064. ULONG HintIndex
  3065. );
  3066. //
  3067. // The following two routines clear or set bits within a specified region
  3068. // of the bitmap. The starting index is zero based.
  3069. //
  3070. NTSYSAPI
  3071. VOID
  3072. NTAPI
  3073. RtlClearBits (
  3074. PRTL_BITMAP BitMapHeader,
  3075. ULONG StartingIndex,
  3076. ULONG NumberToClear
  3077. );
  3078. NTSYSAPI
  3079. VOID
  3080. NTAPI
  3081. RtlSetBits (
  3082. PRTL_BITMAP BitMapHeader,
  3083. ULONG StartingIndex,
  3084. ULONG NumberToSet
  3085. );
  3086. //
  3087. // The following routine locates a set of contiguous regions of clear
  3088. // bits within the bitmap. The caller specifies whether to return the
  3089. // longest runs or just the first found lcoated. The following structure is
  3090. // used to denote a contiguous run of bits. The two routines return an array
  3091. // of this structure, one for each run located.
  3092. //
  3093. typedef struct _RTL_BITMAP_RUN {
  3094. ULONG StartingIndex;
  3095. ULONG NumberOfBits;
  3096. } RTL_BITMAP_RUN;
  3097. typedef RTL_BITMAP_RUN *PRTL_BITMAP_RUN;
  3098. NTSYSAPI
  3099. ULONG
  3100. NTAPI
  3101. RtlFindClearRuns (
  3102. PRTL_BITMAP BitMapHeader,
  3103. PRTL_BITMAP_RUN RunArray,
  3104. ULONG SizeOfRunArray,
  3105. BOOLEAN LocateLongestRuns
  3106. );
  3107. //
  3108. // The following routine locates the longest contiguous region of
  3109. // clear bits within the bitmap. The returned starting index value
  3110. // denotes the first contiguous region located satisfying our requirements
  3111. // The return value is the length (in bits) of the longest region found.
  3112. //
  3113. NTSYSAPI
  3114. ULONG
  3115. NTAPI
  3116. RtlFindLongestRunClear (
  3117. PRTL_BITMAP BitMapHeader,
  3118. PULONG StartingIndex
  3119. );
  3120. //
  3121. // The following routine locates the first contiguous region of
  3122. // clear bits within the bitmap. The returned starting index value
  3123. // denotes the first contiguous region located satisfying our requirements
  3124. // The return value is the length (in bits) of the region found.
  3125. //
  3126. NTSYSAPI
  3127. ULONG
  3128. NTAPI
  3129. RtlFindFirstRunClear (
  3130. PRTL_BITMAP BitMapHeader,
  3131. PULONG StartingIndex
  3132. );
  3133. //
  3134. // The following macro returns the value of the bit stored within the
  3135. // bitmap at the specified location. If the bit is set a value of 1 is
  3136. // returned otherwise a value of 0 is returned.
  3137. //
  3138. // ULONG
  3139. // RtlCheckBit (
  3140. // PRTL_BITMAP BitMapHeader,
  3141. // ULONG BitPosition
  3142. // );
  3143. //
  3144. //
  3145. // To implement CheckBit the macro retrieves the longword containing the
  3146. // bit in question, shifts the longword to get the bit in question into the
  3147. // low order bit position and masks out all other bits.
  3148. //
  3149. #define RtlCheckBit(BMH,BP) ((((BMH)->Buffer[(BP) / 32]) >> ((BP) % 32)) & 0x1)
  3150. //
  3151. // The following two procedures return to the caller the total number of
  3152. // clear or set bits within the specified bitmap.
  3153. //
  3154. NTSYSAPI
  3155. ULONG
  3156. NTAPI
  3157. RtlNumberOfClearBits (
  3158. PRTL_BITMAP BitMapHeader
  3159. );
  3160. NTSYSAPI
  3161. ULONG
  3162. NTAPI
  3163. RtlNumberOfSetBits (
  3164. PRTL_BITMAP BitMapHeader
  3165. );
  3166. //
  3167. // The following two procedures return to the caller a boolean value
  3168. // indicating if the specified range of bits are all clear or set.
  3169. //
  3170. NTSYSAPI
  3171. BOOLEAN
  3172. NTAPI
  3173. RtlAreBitsClear (
  3174. PRTL_BITMAP BitMapHeader,
  3175. ULONG StartingIndex,
  3176. ULONG Length
  3177. );
  3178. NTSYSAPI
  3179. BOOLEAN
  3180. NTAPI
  3181. RtlAreBitsSet (
  3182. PRTL_BITMAP BitMapHeader,
  3183. ULONG StartingIndex,
  3184. ULONG Length
  3185. );
  3186. NTSYSAPI
  3187. ULONG
  3188. NTAPI
  3189. RtlFindNextForwardRunClear (
  3190. IN PRTL_BITMAP BitMapHeader,
  3191. IN ULONG FromIndex,
  3192. IN PULONG StartingRunIndex
  3193. );
  3194. NTSYSAPI
  3195. ULONG
  3196. NTAPI
  3197. RtlFindLastBackwardRunClear (
  3198. IN PRTL_BITMAP BitMapHeader,
  3199. IN ULONG FromIndex,
  3200. IN PULONG StartingRunIndex
  3201. );
  3202. //
  3203. // The following two procedures return to the caller a value indicating
  3204. // the position within a ULONGLONG of the most or least significant non-zero
  3205. // bit. A value of zero results in a return value of -1.
  3206. //
  3207. NTSYSAPI
  3208. CCHAR
  3209. NTAPI
  3210. RtlFindLeastSignificantBit (
  3211. IN ULONGLONG Set
  3212. );
  3213. NTSYSAPI
  3214. CCHAR
  3215. NTAPI
  3216. RtlFindMostSignificantBit (
  3217. IN ULONGLONG Set
  3218. );
  3219. //
  3220. // BOOLEAN
  3221. // RtlEqualLuid(
  3222. // PLUID L1,
  3223. // PLUID L2
  3224. // );
  3225. #define RtlEqualLuid(L1, L2) (((L1)->LowPart == (L2)->LowPart) && \
  3226. ((L1)->HighPart == (L2)->HighPart))
  3227. //
  3228. // BOOLEAN
  3229. // RtlIsZeroLuid(
  3230. // PLUID L1
  3231. // );
  3232. //
  3233. #define RtlIsZeroLuid(L1) ((BOOLEAN) (((L1)->LowPart | (L1)->HighPart) == 0))
  3234. #if !defined(MIDL_PASS)
  3235. FORCEINLINE LUID
  3236. NTAPI
  3237. RtlConvertLongToLuid(
  3238. LONG Long
  3239. )
  3240. {
  3241. LUID TempLuid;
  3242. LARGE_INTEGER TempLi;
  3243. TempLi.QuadPart = Long;
  3244. TempLuid.LowPart = TempLi.LowPart;
  3245. TempLuid.HighPart = TempLi.HighPart;
  3246. return(TempLuid);
  3247. }
  3248. FORCEINLINE
  3249. LUID
  3250. NTAPI
  3251. RtlConvertUlongToLuid(
  3252. ULONG Ulong
  3253. )
  3254. {
  3255. LUID TempLuid;
  3256. TempLuid.LowPart = Ulong;
  3257. TempLuid.HighPart = 0;
  3258. return(TempLuid);
  3259. }
  3260. #endif
  3261. NTSYSAPI
  3262. VOID
  3263. NTAPI
  3264. RtlMapGenericMask(
  3265. PACCESS_MASK AccessMask,
  3266. PGENERIC_MAPPING GenericMapping
  3267. );
  3268. //
  3269. // SecurityDescriptor RTL routine definitions
  3270. //
  3271. NTSYSAPI
  3272. NTSTATUS
  3273. NTAPI
  3274. RtlCreateSecurityDescriptor (
  3275. PSECURITY_DESCRIPTOR SecurityDescriptor,
  3276. ULONG Revision
  3277. );
  3278. NTSYSAPI
  3279. BOOLEAN
  3280. NTAPI
  3281. RtlValidSecurityDescriptor (
  3282. PSECURITY_DESCRIPTOR SecurityDescriptor
  3283. );
  3284. NTSYSAPI
  3285. ULONG
  3286. NTAPI
  3287. RtlLengthSecurityDescriptor (
  3288. PSECURITY_DESCRIPTOR SecurityDescriptor
  3289. );
  3290. NTSYSAPI
  3291. BOOLEAN
  3292. NTAPI
  3293. RtlValidRelativeSecurityDescriptor (
  3294. IN PSECURITY_DESCRIPTOR SecurityDescriptorInput,
  3295. IN ULONG SecurityDescriptorLength,
  3296. IN SECURITY_INFORMATION RequiredInformation
  3297. );
  3298. NTSYSAPI
  3299. NTSTATUS
  3300. NTAPI
  3301. RtlSetDaclSecurityDescriptor (
  3302. PSECURITY_DESCRIPTOR SecurityDescriptor,
  3303. BOOLEAN DaclPresent,
  3304. PACL Dacl,
  3305. BOOLEAN DaclDefaulted
  3306. );
  3307. //
  3308. // Range list package
  3309. //
  3310. typedef struct _RTL_RANGE {
  3311. //
  3312. // The start of the range
  3313. //
  3314. ULONGLONG Start; // Read only
  3315. //
  3316. // The end of the range
  3317. //
  3318. ULONGLONG End; // Read only
  3319. //
  3320. // Data the user passed in when they created the range
  3321. //
  3322. PVOID UserData; // Read/Write
  3323. //
  3324. // The owner of the range
  3325. //
  3326. PVOID Owner; // Read/Write
  3327. //
  3328. // User defined flags the user specified when they created the range
  3329. //
  3330. UCHAR Attributes; // Read/Write
  3331. //
  3332. // Flags (RTL_RANGE_*)
  3333. //
  3334. UCHAR Flags; // Read only
  3335. } RTL_RANGE, *PRTL_RANGE;
  3336. #define RTL_RANGE_SHARED 0x01
  3337. #define RTL_RANGE_CONFLICT 0x02
  3338. typedef struct _RTL_RANGE_LIST {
  3339. //
  3340. // The list of ranges
  3341. //
  3342. LIST_ENTRY ListHead;
  3343. //
  3344. // These always come in useful
  3345. //
  3346. ULONG Flags; // use RANGE_LIST_FLAG_*
  3347. //
  3348. // The number of entries in the list
  3349. //
  3350. ULONG Count;
  3351. //
  3352. // Every time an add/delete operation is performed on the list this is
  3353. // incremented. It is checked during iteration to ensure that the list
  3354. // hasn't changed between GetFirst/GetNext or GetNext/GetNext calls
  3355. //
  3356. ULONG Stamp;
  3357. } RTL_RANGE_LIST, *PRTL_RANGE_LIST;
  3358. typedef struct _RANGE_LIST_ITERATOR {
  3359. PLIST_ENTRY RangeListHead;
  3360. PLIST_ENTRY MergedHead;
  3361. PVOID Current;
  3362. ULONG Stamp;
  3363. } RTL_RANGE_LIST_ITERATOR, *PRTL_RANGE_LIST_ITERATOR;
  3364. NTSYSAPI
  3365. VOID
  3366. NTAPI
  3367. RtlInitializeRangeList(
  3368. IN OUT PRTL_RANGE_LIST RangeList
  3369. );
  3370. NTSYSAPI
  3371. VOID
  3372. NTAPI
  3373. RtlFreeRangeList(
  3374. IN PRTL_RANGE_LIST RangeList
  3375. );
  3376. NTSYSAPI
  3377. NTSTATUS
  3378. NTAPI
  3379. RtlCopyRangeList(
  3380. OUT PRTL_RANGE_LIST CopyRangeList,
  3381. IN PRTL_RANGE_LIST RangeList
  3382. );
  3383. #define RTL_RANGE_LIST_ADD_IF_CONFLICT 0x00000001
  3384. #define RTL_RANGE_LIST_ADD_SHARED 0x00000002
  3385. NTSYSAPI
  3386. NTSTATUS
  3387. NTAPI
  3388. RtlAddRange(
  3389. IN OUT PRTL_RANGE_LIST RangeList,
  3390. IN ULONGLONG Start,
  3391. IN ULONGLONG End,
  3392. IN UCHAR Attributes,
  3393. IN ULONG Flags,
  3394. IN PVOID UserData, OPTIONAL
  3395. IN PVOID Owner OPTIONAL
  3396. );
  3397. NTSYSAPI
  3398. NTSTATUS
  3399. NTAPI
  3400. RtlDeleteRange(
  3401. IN OUT PRTL_RANGE_LIST RangeList,
  3402. IN ULONGLONG Start,
  3403. IN ULONGLONG End,
  3404. IN PVOID Owner
  3405. );
  3406. NTSYSAPI
  3407. NTSTATUS
  3408. NTAPI
  3409. RtlDeleteOwnersRanges(
  3410. IN OUT PRTL_RANGE_LIST RangeList,
  3411. IN PVOID Owner
  3412. );
  3413. #define RTL_RANGE_LIST_SHARED_OK 0x00000001
  3414. #define RTL_RANGE_LIST_NULL_CONFLICT_OK 0x00000002
  3415. typedef
  3416. BOOLEAN
  3417. (*PRTL_CONFLICT_RANGE_CALLBACK) (
  3418. IN PVOID Context,
  3419. IN PRTL_RANGE Range
  3420. );
  3421. NTSYSAPI
  3422. NTSTATUS
  3423. NTAPI
  3424. RtlFindRange(
  3425. IN PRTL_RANGE_LIST RangeList,
  3426. IN ULONGLONG Minimum,
  3427. IN ULONGLONG Maximum,
  3428. IN ULONG Length,
  3429. IN ULONG Alignment,
  3430. IN ULONG Flags,
  3431. IN UCHAR AttributeAvailableMask,
  3432. IN PVOID Context OPTIONAL,
  3433. IN PRTL_CONFLICT_RANGE_CALLBACK Callback OPTIONAL,
  3434. OUT PULONGLONG Start
  3435. );
  3436. NTSYSAPI
  3437. NTSTATUS
  3438. NTAPI
  3439. RtlIsRangeAvailable(
  3440. IN PRTL_RANGE_LIST RangeList,
  3441. IN ULONGLONG Start,
  3442. IN ULONGLONG End,
  3443. IN ULONG Flags,
  3444. IN UCHAR AttributeAvailableMask,
  3445. IN PVOID Context OPTIONAL,
  3446. IN PRTL_CONFLICT_RANGE_CALLBACK Callback OPTIONAL,
  3447. OUT PBOOLEAN Available
  3448. );
  3449. #define FOR_ALL_RANGES(RangeList, Iterator, Current) \
  3450. for (RtlGetFirstRange((RangeList), (Iterator), &(Current)); \
  3451. (Current) != NULL; \
  3452. RtlGetNextRange((Iterator), &(Current), TRUE) \
  3453. )
  3454. #define FOR_ALL_RANGES_BACKWARDS(RangeList, Iterator, Current) \
  3455. for (RtlGetLastRange((RangeList), (Iterator), &(Current)); \
  3456. (Current) != NULL; \
  3457. RtlGetNextRange((Iterator), &(Current), FALSE) \
  3458. )
  3459. NTSYSAPI
  3460. NTSTATUS
  3461. NTAPI
  3462. RtlGetFirstRange(
  3463. IN PRTL_RANGE_LIST RangeList,
  3464. OUT PRTL_RANGE_LIST_ITERATOR Iterator,
  3465. OUT PRTL_RANGE *Range
  3466. );
  3467. NTSYSAPI
  3468. NTSTATUS
  3469. NTAPI
  3470. RtlGetLastRange(
  3471. IN PRTL_RANGE_LIST RangeList,
  3472. OUT PRTL_RANGE_LIST_ITERATOR Iterator,
  3473. OUT PRTL_RANGE *Range
  3474. );
  3475. NTSYSAPI
  3476. NTSTATUS
  3477. NTAPI
  3478. RtlGetNextRange(
  3479. IN OUT PRTL_RANGE_LIST_ITERATOR Iterator,
  3480. OUT PRTL_RANGE *Range,
  3481. IN BOOLEAN MoveForwards
  3482. );
  3483. #define RTL_RANGE_LIST_MERGE_IF_CONFLICT RTL_RANGE_LIST_ADD_IF_CONFLICT
  3484. NTSYSAPI
  3485. NTSTATUS
  3486. NTAPI
  3487. RtlMergeRangeLists(
  3488. OUT PRTL_RANGE_LIST MergedRangeList,
  3489. IN PRTL_RANGE_LIST RangeList1,
  3490. IN PRTL_RANGE_LIST RangeList2,
  3491. IN ULONG Flags
  3492. );
  3493. NTSYSAPI
  3494. NTSTATUS
  3495. NTAPI
  3496. RtlInvertRangeList(
  3497. OUT PRTL_RANGE_LIST InvertedRangeList,
  3498. IN PRTL_RANGE_LIST RangeList
  3499. );
  3500. // end_nthal
  3501. // begin_wdm
  3502. //
  3503. // Byte swap routines. These are used to convert from little-endian to
  3504. // big-endian and vice-versa.
  3505. //
  3506. #if (defined(_M_IX86) && (_MSC_FULL_VER > 13009037)) || ((defined(_M_AMD64) || defined(_M_IA64)) && (_MSC_FULL_VER > 13009175))
  3507. #ifdef __cplusplus
  3508. extern "C" {
  3509. #endif
  3510. unsigned short __cdecl _byteswap_ushort(unsigned short);
  3511. unsigned long __cdecl _byteswap_ulong (unsigned long);
  3512. unsigned __int64 __cdecl _byteswap_uint64(unsigned __int64);
  3513. #ifdef __cplusplus
  3514. }
  3515. #endif
  3516. #pragma intrinsic(_byteswap_ushort)
  3517. #pragma intrinsic(_byteswap_ulong)
  3518. #pragma intrinsic(_byteswap_uint64)
  3519. #define RtlUshortByteSwap(_x) _byteswap_ushort((USHORT)(_x))
  3520. #define RtlUlongByteSwap(_x) _byteswap_ulong((_x))
  3521. #define RtlUlonglongByteSwap(_x) _byteswap_uint64((_x))
  3522. #else
  3523. USHORT
  3524. FASTCALL
  3525. RtlUshortByteSwap(
  3526. IN USHORT Source
  3527. );
  3528. ULONG
  3529. FASTCALL
  3530. RtlUlongByteSwap(
  3531. IN ULONG Source
  3532. );
  3533. ULONGLONG
  3534. FASTCALL
  3535. RtlUlonglongByteSwap(
  3536. IN ULONGLONG Source
  3537. );
  3538. #endif
  3539. // end_wdm
  3540. // begin_ntifs
  3541. //
  3542. // Routine for converting from a volume device object to a DOS name.
  3543. //
  3544. NTSYSAPI
  3545. NTSTATUS
  3546. NTAPI
  3547. RtlVolumeDeviceToDosName(
  3548. IN PVOID VolumeDeviceObject,
  3549. OUT PUNICODE_STRING DosName
  3550. );
  3551. typedef struct _OSVERSIONINFOA {
  3552. ULONG dwOSVersionInfoSize;
  3553. ULONG dwMajorVersion;
  3554. ULONG dwMinorVersion;
  3555. ULONG dwBuildNumber;
  3556. ULONG dwPlatformId;
  3557. CHAR szCSDVersion[ 128 ]; // Maintenance string for PSS usage
  3558. } OSVERSIONINFOA, *POSVERSIONINFOA, *LPOSVERSIONINFOA;
  3559. typedef struct _OSVERSIONINFOW {
  3560. ULONG dwOSVersionInfoSize;
  3561. ULONG dwMajorVersion;
  3562. ULONG dwMinorVersion;
  3563. ULONG dwBuildNumber;
  3564. ULONG dwPlatformId;
  3565. WCHAR szCSDVersion[ 128 ]; // Maintenance string for PSS usage
  3566. } OSVERSIONINFOW, *POSVERSIONINFOW, *LPOSVERSIONINFOW, RTL_OSVERSIONINFOW, *PRTL_OSVERSIONINFOW;
  3567. #ifdef UNICODE
  3568. typedef OSVERSIONINFOW OSVERSIONINFO;
  3569. typedef POSVERSIONINFOW POSVERSIONINFO;
  3570. typedef LPOSVERSIONINFOW LPOSVERSIONINFO;
  3571. #else
  3572. typedef OSVERSIONINFOA OSVERSIONINFO;
  3573. typedef POSVERSIONINFOA POSVERSIONINFO;
  3574. typedef LPOSVERSIONINFOA LPOSVERSIONINFO;
  3575. #endif // UNICODE
  3576. typedef struct _OSVERSIONINFOEXA {
  3577. ULONG dwOSVersionInfoSize;
  3578. ULONG dwMajorVersion;
  3579. ULONG dwMinorVersion;
  3580. ULONG dwBuildNumber;
  3581. ULONG dwPlatformId;
  3582. CHAR szCSDVersion[ 128 ]; // Maintenance string for PSS usage
  3583. USHORT wServicePackMajor;
  3584. USHORT wServicePackMinor;
  3585. USHORT wSuiteMask;
  3586. UCHAR wProductType;
  3587. UCHAR wReserved;
  3588. } OSVERSIONINFOEXA, *POSVERSIONINFOEXA, *LPOSVERSIONINFOEXA;
  3589. typedef struct _OSVERSIONINFOEXW {
  3590. ULONG dwOSVersionInfoSize;
  3591. ULONG dwMajorVersion;
  3592. ULONG dwMinorVersion;
  3593. ULONG dwBuildNumber;
  3594. ULONG dwPlatformId;
  3595. WCHAR szCSDVersion[ 128 ]; // Maintenance string for PSS usage
  3596. USHORT wServicePackMajor;
  3597. USHORT wServicePackMinor;
  3598. USHORT wSuiteMask;
  3599. UCHAR wProductType;
  3600. UCHAR wReserved;
  3601. } OSVERSIONINFOEXW, *POSVERSIONINFOEXW, *LPOSVERSIONINFOEXW, RTL_OSVERSIONINFOEXW, *PRTL_OSVERSIONINFOEXW;
  3602. #ifdef UNICODE
  3603. typedef OSVERSIONINFOEXW OSVERSIONINFOEX;
  3604. typedef POSVERSIONINFOEXW POSVERSIONINFOEX;
  3605. typedef LPOSVERSIONINFOEXW LPOSVERSIONINFOEX;
  3606. #else
  3607. typedef OSVERSIONINFOEXA OSVERSIONINFOEX;
  3608. typedef POSVERSIONINFOEXA POSVERSIONINFOEX;
  3609. typedef LPOSVERSIONINFOEXA LPOSVERSIONINFOEX;
  3610. #endif // UNICODE
  3611. //
  3612. // RtlVerifyVersionInfo() conditions
  3613. //
  3614. #define VER_EQUAL 1
  3615. #define VER_GREATER 2
  3616. #define VER_GREATER_EQUAL 3
  3617. #define VER_LESS 4
  3618. #define VER_LESS_EQUAL 5
  3619. #define VER_AND 6
  3620. #define VER_OR 7
  3621. #define VER_CONDITION_MASK 7
  3622. #define VER_NUM_BITS_PER_CONDITION_MASK 3
  3623. //
  3624. // RtlVerifyVersionInfo() type mask bits
  3625. //
  3626. #define VER_MINORVERSION 0x0000001
  3627. #define VER_MAJORVERSION 0x0000002
  3628. #define VER_BUILDNUMBER 0x0000004
  3629. #define VER_PLATFORMID 0x0000008
  3630. #define VER_SERVICEPACKMINOR 0x0000010
  3631. #define VER_SERVICEPACKMAJOR 0x0000020
  3632. #define VER_SUITENAME 0x0000040
  3633. #define VER_PRODUCT_TYPE 0x0000080
  3634. //
  3635. // RtlVerifyVersionInfo() os product type values
  3636. //
  3637. #define VER_NT_WORKSTATION 0x0000001
  3638. #define VER_NT_DOMAIN_CONTROLLER 0x0000002
  3639. #define VER_NT_SERVER 0x0000003
  3640. //
  3641. // dwPlatformId defines:
  3642. //
  3643. #define VER_PLATFORM_WIN32s 0
  3644. #define VER_PLATFORM_WIN32_WINDOWS 1
  3645. #define VER_PLATFORM_WIN32_NT 2
  3646. //
  3647. //
  3648. // VerifyVersionInfo() macro to set the condition mask
  3649. //
  3650. // For documentation sakes here's the old version of the macro that got
  3651. // changed to call an API
  3652. // #define VER_SET_CONDITION(_m_,_t_,_c_) _m_=(_m_|(_c_<<(1<<_t_)))
  3653. //
  3654. #define VER_SET_CONDITION(_m_,_t_,_c_) \
  3655. ((_m_)=VerSetConditionMask((_m_),(_t_),(_c_)))
  3656. ULONGLONG
  3657. NTAPI
  3658. VerSetConditionMask(
  3659. IN ULONGLONG ConditionMask,
  3660. IN ULONG TypeMask,
  3661. IN UCHAR Condition
  3662. );
  3663. //
  3664. // end_winnt
  3665. //
  3666. NTSYSAPI
  3667. NTSTATUS
  3668. RtlGetVersion(
  3669. OUT PRTL_OSVERSIONINFOW lpVersionInformation
  3670. );
  3671. NTSYSAPI
  3672. NTSTATUS
  3673. RtlVerifyVersionInfo(
  3674. IN PRTL_OSVERSIONINFOEXW VersionInfo,
  3675. IN ULONG TypeMask,
  3676. IN ULONGLONG ConditionMask
  3677. );
  3678. //
  3679. //
  3680. // Interlocked bit manipulation interfaces
  3681. //
  3682. NTSYSAPI
  3683. ULONG
  3684. FASTCALL
  3685. RtlInterlockedSetBits (
  3686. IN OUT PULONG Flags,
  3687. IN ULONG Flag
  3688. );
  3689. NTSYSAPI
  3690. ULONG
  3691. FASTCALL
  3692. RtlInterlockedClearBits (
  3693. IN OUT PULONG Flags,
  3694. IN ULONG Flag
  3695. );
  3696. NTSYSAPI
  3697. ULONG
  3698. FASTCALL
  3699. RtlInterlockedSetClearBits (
  3700. IN OUT PULONG Flags,
  3701. IN ULONG sFlag,
  3702. IN ULONG cFlag
  3703. );
  3704. //
  3705. // These are for when the compiler has fixes in for these intrinsics
  3706. //
  3707. #if (_MSC_FULL_VER > 13009037) || !defined (_M_IX86)
  3708. #define RtlInterlockedSetBits(Flags, Flag) \
  3709. InterlockedOr ((PLONG) (Flags), Flag)
  3710. #define RtlInterlockedAndBits(Flags, Flag) \
  3711. InterlockedAnd ((PLONG) (Flags), Flag)
  3712. #define RtlInterlockedClearBits(Flags, Flag) \
  3713. RtlInterlockedAndBits (Flags, ~(Flag))
  3714. #define RtlInterlockedXorBits(Flags, Flag) \
  3715. InterlockedXor (Flags, Flag)
  3716. #define RtlInterlockedSetBitsDiscardReturn(Flags, Flag) \
  3717. (VOID) RtlInterlockedSetBits (Flags, Flag)
  3718. #define RtlInterlockedAndBitsDiscardReturn(Flags, Flag) \
  3719. (VOID) RtlInterlockedAndBits (Flags, Flag)
  3720. #define RtlInterlockedClearBitsDiscardReturn(Flags, Flag) \
  3721. RtlInterlockedAndBitsDiscardReturn (Flags, ~(Flag))
  3722. #else
  3723. #if defined (_X86_) && !defined(MIDL_PASS)
  3724. FORCEINLINE
  3725. VOID
  3726. RtlInterlockedSetBitsDiscardReturn(
  3727. IN OUT PULONG Flags,
  3728. IN ULONG Flag
  3729. )
  3730. {
  3731. __asm {
  3732. mov ecx, Flags
  3733. mov eax, Flag
  3734. #if defined (NT_UP)
  3735. or [ecx], eax
  3736. #else
  3737. lock or [ecx], eax
  3738. #endif
  3739. }
  3740. }
  3741. FORCEINLINE
  3742. VOID
  3743. RtlInterlockedAndBitsDiscardReturn(
  3744. IN OUT PULONG Flags,
  3745. IN ULONG Flag
  3746. )
  3747. {
  3748. __asm {
  3749. mov ecx, Flags
  3750. mov eax, Flag
  3751. #if defined (NT_UP)
  3752. and [ecx], eax
  3753. #else
  3754. lock and [ecx], eax
  3755. #endif
  3756. }
  3757. }
  3758. #define RtlInterlockedClearBitsDiscardReturn(Flags, Flag) \
  3759. (VOID) RtlInterlockedAndBitsDiscardReturn ((Flags), ~(Flag))
  3760. #else
  3761. #define RtlInterlockedSetBitsDiscardReturn(Flags, Flag) \
  3762. (VOID) RtlInterlockedSetBits ((Flags), (Flag))
  3763. #define RtlInterlockedClearBitsDiscardReturn(Flags, Flag) \
  3764. (VOID) RtlInterlockedClearBits ((Flags), (Flag))
  3765. #endif /* #if defined(_X86_) && !defined(MIDL_PASS) */
  3766. #endif
  3767. //
  3768. // Component name filter id enumeration and levels.
  3769. //
  3770. #define DPFLTR_ERROR_LEVEL 0
  3771. #define DPFLTR_WARNING_LEVEL 1
  3772. #define DPFLTR_TRACE_LEVEL 2
  3773. #define DPFLTR_INFO_LEVEL 3
  3774. #define DPFLTR_MASK 0x80000000
  3775. typedef enum _DPFLTR_TYPE {
  3776. DPFLTR_SYSTEM_ID = 0,
  3777. DPFLTR_SMSS_ID = 1,
  3778. DPFLTR_SETUP_ID = 2,
  3779. DPFLTR_NTFS_ID = 3,
  3780. DPFLTR_FSTUB_ID = 4,
  3781. DPFLTR_CRASHDUMP_ID = 5,
  3782. DPFLTR_CDAUDIO_ID = 6,
  3783. DPFLTR_CDROM_ID = 7,
  3784. DPFLTR_CLASSPNP_ID = 8,
  3785. DPFLTR_DISK_ID = 9,
  3786. DPFLTR_REDBOOK_ID = 10,
  3787. DPFLTR_STORPROP_ID = 11,
  3788. DPFLTR_SCSIPORT_ID = 12,
  3789. DPFLTR_SCSIMINIPORT_ID = 13,
  3790. DPFLTR_CONFIG_ID = 14,
  3791. DPFLTR_I8042PRT_ID = 15,
  3792. DPFLTR_SERMOUSE_ID = 16,
  3793. DPFLTR_LSERMOUS_ID = 17,
  3794. DPFLTR_KBDHID_ID = 18,
  3795. DPFLTR_MOUHID_ID = 19,
  3796. DPFLTR_KBDCLASS_ID = 20,
  3797. DPFLTR_MOUCLASS_ID = 21,
  3798. DPFLTR_TWOTRACK_ID = 22,
  3799. DPFLTR_WMILIB_ID = 23,
  3800. DPFLTR_ACPI_ID = 24,
  3801. DPFLTR_AMLI_ID = 25,
  3802. DPFLTR_HALIA64_ID = 26,
  3803. DPFLTR_VIDEO_ID = 27,
  3804. DPFLTR_SVCHOST_ID = 28,
  3805. DPFLTR_VIDEOPRT_ID = 29,
  3806. DPFLTR_TCPIP_ID = 30,
  3807. DPFLTR_DMSYNTH_ID = 31,
  3808. DPFLTR_NTOSPNP_ID = 32,
  3809. DPFLTR_FASTFAT_ID = 33,
  3810. DPFLTR_SAMSS_ID = 34,
  3811. DPFLTR_PNPMGR_ID = 35,
  3812. DPFLTR_NETAPI_ID = 36,
  3813. DPFLTR_SCSERVER_ID = 37,
  3814. DPFLTR_SCCLIENT_ID = 38,
  3815. DPFLTR_SERIAL_ID = 39,
  3816. DPFLTR_SERENUM_ID = 40,
  3817. DPFLTR_UHCD_ID = 41,
  3818. DPFLTR_BOOTOK_ID = 42,
  3819. DPFLTR_BOOTVRFY_ID = 43,
  3820. DPFLTR_RPCPROXY_ID = 44,
  3821. DPFLTR_AUTOCHK_ID = 45,
  3822. DPFLTR_DCOMSS_ID = 46,
  3823. DPFLTR_UNIMODEM_ID = 47,
  3824. DPFLTR_SIS_ID = 48,
  3825. DPFLTR_FLTMGR_ID = 49,
  3826. DPFLTR_WMICORE_ID = 50,
  3827. DPFLTR_BURNENG_ID = 51,
  3828. DPFLTR_IMAPI_ID = 52,
  3829. DPFLTR_SXS_ID = 53,
  3830. DPFLTR_FUSION_ID = 54,
  3831. DPFLTR_IDLETASK_ID = 55,
  3832. DPFLTR_SOFTPCI_ID = 56,
  3833. DPFLTR_TAPE_ID = 57,
  3834. DPFLTR_MCHGR_ID = 58,
  3835. DPFLTR_IDEP_ID = 59,
  3836. DPFLTR_PCIIDE_ID = 60,
  3837. DPFLTR_FLOPPY_ID = 61,
  3838. DPFLTR_FDC_ID = 62,
  3839. DPFLTR_TERMSRV_ID = 63,
  3840. DPFLTR_W32TIME_ID = 64,
  3841. DPFLTR_PREFETCHER_ID = 65,
  3842. DPFLTR_RSFILTER_ID = 66,
  3843. DPFLTR_FCPORT_ID = 67,
  3844. DPFLTR_PCI_ID = 68,
  3845. DPFLTR_DMIO_ID = 69,
  3846. DPFLTR_DMCONFIG_ID = 70,
  3847. DPFLTR_DMADMIN_ID = 71,
  3848. DPFLTR_WSOCKTRANSPORT_ID = 72,
  3849. DPFLTR_VSS_ID = 73,
  3850. DPFLTR_PNPMEM_ID = 74,
  3851. DPFLTR_PROCESSOR_ID = 75,
  3852. DPFLTR_DMSERVER_ID = 76,
  3853. DPFLTR_SR_ID = 77,
  3854. DPFLTR_INFINIBAND_ID = 78,
  3855. DPFLTR_IHVDRIVER_ID = 79,
  3856. DPFLTR_IHVVIDEO_ID = 80,
  3857. DPFLTR_IHVAUDIO_ID = 81,
  3858. DPFLTR_IHVNETWORK_ID = 82,
  3859. DPFLTR_IHVSTREAMING_ID = 83,
  3860. DPFLTR_IHVBUS_ID = 84,
  3861. DPFLTR_HPS_ID = 85,
  3862. DPFLTR_RTLTHREADPOOL_ID = 86,
  3863. DPFLTR_LDR_ID = 87,
  3864. DPFLTR_TCPIP6_ID = 88,
  3865. DPFLTR_ISAPNP_ID = 89,
  3866. DPFLTR_SHPC_ID = 90,
  3867. DPFLTR_STORPORT_ID = 91,
  3868. DPFLTR_STORMINIPORT_ID = 92,
  3869. DPFLTR_PRINTSPOOLER_ID = 93,
  3870. DPFLTR_ENDOFTABLE_ID
  3871. } DPFLTR_TYPE;
  3872. //
  3873. // Define the various device type values. Note that values used by Microsoft
  3874. // Corporation are in the range 0-32767, and 32768-65535 are reserved for use
  3875. // by customers.
  3876. //
  3877. #define DEVICE_TYPE ULONG
  3878. #define FILE_DEVICE_BEEP 0x00000001
  3879. #define FILE_DEVICE_CD_ROM 0x00000002
  3880. #define FILE_DEVICE_CD_ROM_FILE_SYSTEM 0x00000003
  3881. #define FILE_DEVICE_CONTROLLER 0x00000004
  3882. #define FILE_DEVICE_DATALINK 0x00000005
  3883. #define FILE_DEVICE_DFS 0x00000006
  3884. #define FILE_DEVICE_DISK 0x00000007
  3885. #define FILE_DEVICE_DISK_FILE_SYSTEM 0x00000008
  3886. #define FILE_DEVICE_FILE_SYSTEM 0x00000009
  3887. #define FILE_DEVICE_INPORT_PORT 0x0000000a
  3888. #define FILE_DEVICE_KEYBOARD 0x0000000b
  3889. #define FILE_DEVICE_MAILSLOT 0x0000000c
  3890. #define FILE_DEVICE_MIDI_IN 0x0000000d
  3891. #define FILE_DEVICE_MIDI_OUT 0x0000000e
  3892. #define FILE_DEVICE_MOUSE 0x0000000f
  3893. #define FILE_DEVICE_MULTI_UNC_PROVIDER 0x00000010
  3894. #define FILE_DEVICE_NAMED_PIPE 0x00000011
  3895. #define FILE_DEVICE_NETWORK 0x00000012
  3896. #define FILE_DEVICE_NETWORK_BROWSER 0x00000013
  3897. #define FILE_DEVICE_NETWORK_FILE_SYSTEM 0x00000014
  3898. #define FILE_DEVICE_NULL 0x00000015
  3899. #define FILE_DEVICE_PARALLEL_PORT 0x00000016
  3900. #define FILE_DEVICE_PHYSICAL_NETCARD 0x00000017
  3901. #define FILE_DEVICE_PRINTER 0x00000018
  3902. #define FILE_DEVICE_SCANNER 0x00000019
  3903. #define FILE_DEVICE_SERIAL_MOUSE_PORT 0x0000001a
  3904. #define FILE_DEVICE_SERIAL_PORT 0x0000001b
  3905. #define FILE_DEVICE_SCREEN 0x0000001c
  3906. #define FILE_DEVICE_SOUND 0x0000001d
  3907. #define FILE_DEVICE_STREAMS 0x0000001e
  3908. #define FILE_DEVICE_TAPE 0x0000001f
  3909. #define FILE_DEVICE_TAPE_FILE_SYSTEM 0x00000020
  3910. #define FILE_DEVICE_TRANSPORT 0x00000021
  3911. #define FILE_DEVICE_UNKNOWN 0x00000022
  3912. #define FILE_DEVICE_VIDEO 0x00000023
  3913. #define FILE_DEVICE_VIRTUAL_DISK 0x00000024
  3914. #define FILE_DEVICE_WAVE_IN 0x00000025
  3915. #define FILE_DEVICE_WAVE_OUT 0x00000026
  3916. #define FILE_DEVICE_8042_PORT 0x00000027
  3917. #define FILE_DEVICE_NETWORK_REDIRECTOR 0x00000028
  3918. #define FILE_DEVICE_BATTERY 0x00000029
  3919. #define FILE_DEVICE_BUS_EXTENDER 0x0000002a
  3920. #define FILE_DEVICE_MODEM 0x0000002b
  3921. #define FILE_DEVICE_VDM 0x0000002c
  3922. #define FILE_DEVICE_MASS_STORAGE 0x0000002d
  3923. #define FILE_DEVICE_SMB 0x0000002e
  3924. #define FILE_DEVICE_KS 0x0000002f
  3925. #define FILE_DEVICE_CHANGER 0x00000030
  3926. #define FILE_DEVICE_SMARTCARD 0x00000031
  3927. #define FILE_DEVICE_ACPI 0x00000032
  3928. #define FILE_DEVICE_DVD 0x00000033
  3929. #define FILE_DEVICE_FULLSCREEN_VIDEO 0x00000034
  3930. #define FILE_DEVICE_DFS_FILE_SYSTEM 0x00000035
  3931. #define FILE_DEVICE_DFS_VOLUME 0x00000036
  3932. #define FILE_DEVICE_SERENUM 0x00000037
  3933. #define FILE_DEVICE_TERMSRV 0x00000038
  3934. #define FILE_DEVICE_KSEC 0x00000039
  3935. #define FILE_DEVICE_FIPS 0x0000003A
  3936. //
  3937. // Macro definition for defining IOCTL and FSCTL function control codes. Note
  3938. // that function codes 0-2047 are reserved for Microsoft Corporation, and
  3939. // 2048-4095 are reserved for customers.
  3940. //
  3941. #define CTL_CODE( DeviceType, Function, Method, Access ) ( \
  3942. ((DeviceType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method) \
  3943. )
  3944. //
  3945. // Macro to extract device type out of the device io control code
  3946. //
  3947. #define DEVICE_TYPE_FROM_CTL_CODE(ctrlCode) (((ULONG)(ctrlCode & 0xffff0000)) >> 16)
  3948. //
  3949. // Define the method codes for how buffers are passed for I/O and FS controls
  3950. //
  3951. #define METHOD_BUFFERED 0
  3952. #define METHOD_IN_DIRECT 1
  3953. #define METHOD_OUT_DIRECT 2
  3954. #define METHOD_NEITHER 3
  3955. //
  3956. // Define the access check value for any access
  3957. //
  3958. //
  3959. // The FILE_READ_ACCESS and FILE_WRITE_ACCESS constants are also defined in
  3960. // ntioapi.h as FILE_READ_DATA and FILE_WRITE_DATA. The values for these
  3961. // constants *MUST* always be in sync.
  3962. //
  3963. //
  3964. // FILE_SPECIAL_ACCESS is checked by the NT I/O system the same as FILE_ANY_ACCESS.
  3965. // The file systems, however, may add additional access checks for I/O and FS controls
  3966. // that use this value.
  3967. //
  3968. #define FILE_ANY_ACCESS 0
  3969. #define FILE_SPECIAL_ACCESS (FILE_ANY_ACCESS)
  3970. #define FILE_READ_ACCESS ( 0x0001 ) // file & pipe
  3971. #define FILE_WRITE_ACCESS ( 0x0002 ) // file & pipe
  3972. // begin_winnt
  3973. //
  3974. // Define access rights to files and directories
  3975. //
  3976. //
  3977. // The FILE_READ_DATA and FILE_WRITE_DATA constants are also defined in
  3978. // devioctl.h as FILE_READ_ACCESS and FILE_WRITE_ACCESS. The values for these
  3979. // constants *MUST* always be in sync.
  3980. // The values are redefined in devioctl.h because they must be available to
  3981. // both DOS and NT.
  3982. //
  3983. #define FILE_READ_DATA ( 0x0001 ) // file & pipe
  3984. #define FILE_LIST_DIRECTORY ( 0x0001 ) // directory
  3985. #define FILE_WRITE_DATA ( 0x0002 ) // file & pipe
  3986. #define FILE_ADD_FILE ( 0x0002 ) // directory
  3987. #define FILE_APPEND_DATA ( 0x0004 ) // file
  3988. #define FILE_ADD_SUBDIRECTORY ( 0x0004 ) // directory
  3989. #define FILE_CREATE_PIPE_INSTANCE ( 0x0004 ) // named pipe
  3990. #define FILE_READ_EA ( 0x0008 ) // file & directory
  3991. #define FILE_WRITE_EA ( 0x0010 ) // file & directory
  3992. #define FILE_EXECUTE ( 0x0020 ) // file
  3993. #define FILE_TRAVERSE ( 0x0020 ) // directory
  3994. #define FILE_DELETE_CHILD ( 0x0040 ) // directory
  3995. #define FILE_READ_ATTRIBUTES ( 0x0080 ) // all
  3996. #define FILE_WRITE_ATTRIBUTES ( 0x0100 ) // all
  3997. #define FILE_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | 0x1FF)
  3998. #define FILE_GENERIC_READ (STANDARD_RIGHTS_READ |\
  3999. FILE_READ_DATA |\
  4000. FILE_READ_ATTRIBUTES |\
  4001. FILE_READ_EA |\
  4002. SYNCHRONIZE)
  4003. #define FILE_GENERIC_WRITE (STANDARD_RIGHTS_WRITE |\
  4004. FILE_WRITE_DATA |\
  4005. FILE_WRITE_ATTRIBUTES |\
  4006. FILE_WRITE_EA |\
  4007. FILE_APPEND_DATA |\
  4008. SYNCHRONIZE)
  4009. #define FILE_GENERIC_EXECUTE (STANDARD_RIGHTS_EXECUTE |\
  4010. FILE_READ_ATTRIBUTES |\
  4011. FILE_EXECUTE |\
  4012. SYNCHRONIZE)
  4013. // end_winnt
  4014. //
  4015. // Define share access rights to files and directories
  4016. //
  4017. #define FILE_SHARE_READ 0x00000001 // winnt
  4018. #define FILE_SHARE_WRITE 0x00000002 // winnt
  4019. #define FILE_SHARE_DELETE 0x00000004 // winnt
  4020. #define FILE_SHARE_VALID_FLAGS 0x00000007
  4021. //
  4022. // Define the file attributes values
  4023. //
  4024. // Note: 0x00000008 is reserved for use for the old DOS VOLID (volume ID)
  4025. // and is therefore not considered valid in NT.
  4026. //
  4027. // Note: 0x00000010 is reserved for use for the old DOS SUBDIRECTORY flag
  4028. // and is therefore not considered valid in NT. This flag has
  4029. // been disassociated with file attributes since the other flags are
  4030. // protected with READ_ and WRITE_ATTRIBUTES access to the file.
  4031. //
  4032. // Note: Note also that the order of these flags is set to allow both the
  4033. // FAT and the Pinball File Systems to directly set the attributes
  4034. // flags in attributes words without having to pick each flag out
  4035. // individually. The order of these flags should not be changed!
  4036. //
  4037. #define FILE_ATTRIBUTE_READONLY 0x00000001 // winnt
  4038. #define FILE_ATTRIBUTE_HIDDEN 0x00000002 // winnt
  4039. #define FILE_ATTRIBUTE_SYSTEM 0x00000004 // winnt
  4040. //OLD DOS VOLID 0x00000008
  4041. #define FILE_ATTRIBUTE_DIRECTORY 0x00000010 // winnt
  4042. #define FILE_ATTRIBUTE_ARCHIVE 0x00000020 // winnt
  4043. #define FILE_ATTRIBUTE_DEVICE 0x00000040 // winnt
  4044. #define FILE_ATTRIBUTE_NORMAL 0x00000080 // winnt
  4045. #define FILE_ATTRIBUTE_TEMPORARY 0x00000100 // winnt
  4046. #define FILE_ATTRIBUTE_SPARSE_FILE 0x00000200 // winnt
  4047. #define FILE_ATTRIBUTE_REPARSE_POINT 0x00000400 // winnt
  4048. #define FILE_ATTRIBUTE_COMPRESSED 0x00000800 // winnt
  4049. #define FILE_ATTRIBUTE_OFFLINE 0x00001000 // winnt
  4050. #define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED 0x00002000 // winnt
  4051. #define FILE_ATTRIBUTE_ENCRYPTED 0x00004000 // winnt
  4052. #define FILE_ATTRIBUTE_VALID_FLAGS 0x00007fb7
  4053. #define FILE_ATTRIBUTE_VALID_SET_FLAGS 0x000031a7
  4054. //
  4055. // Define the create disposition values
  4056. //
  4057. #define FILE_SUPERSEDE 0x00000000
  4058. #define FILE_OPEN 0x00000001
  4059. #define FILE_CREATE 0x00000002
  4060. #define FILE_OPEN_IF 0x00000003
  4061. #define FILE_OVERWRITE 0x00000004
  4062. #define FILE_OVERWRITE_IF 0x00000005
  4063. #define FILE_MAXIMUM_DISPOSITION 0x00000005
  4064. //
  4065. // Define the create/open option flags
  4066. //
  4067. #define FILE_DIRECTORY_FILE 0x00000001
  4068. #define FILE_WRITE_THROUGH 0x00000002
  4069. #define FILE_SEQUENTIAL_ONLY 0x00000004
  4070. #define FILE_NO_INTERMEDIATE_BUFFERING 0x00000008
  4071. #define FILE_SYNCHRONOUS_IO_ALERT 0x00000010
  4072. #define FILE_SYNCHRONOUS_IO_NONALERT 0x00000020
  4073. #define FILE_NON_DIRECTORY_FILE 0x00000040
  4074. #define FILE_CREATE_TREE_CONNECTION 0x00000080
  4075. #define FILE_COMPLETE_IF_OPLOCKED 0x00000100
  4076. #define FILE_NO_EA_KNOWLEDGE 0x00000200
  4077. #define FILE_OPEN_FOR_RECOVERY 0x00000400
  4078. #define FILE_RANDOM_ACCESS 0x00000800
  4079. #define FILE_DELETE_ON_CLOSE 0x00001000
  4080. #define FILE_OPEN_BY_FILE_ID 0x00002000
  4081. #define FILE_OPEN_FOR_BACKUP_INTENT 0x00004000
  4082. #define FILE_NO_COMPRESSION 0x00008000
  4083. #define FILE_RESERVE_OPFILTER 0x00100000
  4084. #define FILE_OPEN_REPARSE_POINT 0x00200000
  4085. #define FILE_OPEN_NO_RECALL 0x00400000
  4086. #define FILE_OPEN_FOR_FREE_SPACE_QUERY 0x00800000
  4087. #define FILE_COPY_STRUCTURED_STORAGE 0x00000041
  4088. #define FILE_STRUCTURED_STORAGE 0x00000441
  4089. #define FILE_VALID_OPTION_FLAGS 0x00ffffff
  4090. #define FILE_VALID_PIPE_OPTION_FLAGS 0x00000032
  4091. #define FILE_VALID_MAILSLOT_OPTION_FLAGS 0x00000032
  4092. #define FILE_VALID_SET_FLAGS 0x00000036
  4093. //
  4094. // Define the I/O status information return values for NtCreateFile/NtOpenFile
  4095. //
  4096. #define FILE_SUPERSEDED 0x00000000
  4097. #define FILE_OPENED 0x00000001
  4098. #define FILE_CREATED 0x00000002
  4099. #define FILE_OVERWRITTEN 0x00000003
  4100. #define FILE_EXISTS 0x00000004
  4101. #define FILE_DOES_NOT_EXIST 0x00000005
  4102. //
  4103. // Define special ByteOffset parameters for read and write operations
  4104. //
  4105. #define FILE_WRITE_TO_END_OF_FILE 0xffffffff
  4106. #define FILE_USE_FILE_POINTER_POSITION 0xfffffffe
  4107. //
  4108. // Define alignment requirement values
  4109. //
  4110. #define FILE_BYTE_ALIGNMENT 0x00000000
  4111. #define FILE_WORD_ALIGNMENT 0x00000001
  4112. #define FILE_LONG_ALIGNMENT 0x00000003
  4113. #define FILE_QUAD_ALIGNMENT 0x00000007
  4114. #define FILE_OCTA_ALIGNMENT 0x0000000f
  4115. #define FILE_32_BYTE_ALIGNMENT 0x0000001f
  4116. #define FILE_64_BYTE_ALIGNMENT 0x0000003f
  4117. #define FILE_128_BYTE_ALIGNMENT 0x0000007f
  4118. #define FILE_256_BYTE_ALIGNMENT 0x000000ff
  4119. #define FILE_512_BYTE_ALIGNMENT 0x000001ff
  4120. //
  4121. // Define the maximum length of a filename string
  4122. //
  4123. #define MAXIMUM_FILENAME_LENGTH 256
  4124. //
  4125. // Define the various device characteristics flags
  4126. //
  4127. #define FILE_REMOVABLE_MEDIA 0x00000001
  4128. #define FILE_READ_ONLY_DEVICE 0x00000002
  4129. #define FILE_FLOPPY_DISKETTE 0x00000004
  4130. #define FILE_WRITE_ONCE_MEDIA 0x00000008
  4131. #define FILE_REMOTE_DEVICE 0x00000010
  4132. #define FILE_DEVICE_IS_MOUNTED 0x00000020
  4133. #define FILE_VIRTUAL_VOLUME 0x00000040
  4134. #define FILE_AUTOGENERATED_DEVICE_NAME 0x00000080
  4135. #define FILE_DEVICE_SECURE_OPEN 0x00000100
  4136. #define FILE_CHARACTERISTIC_PNP_DEVICE 0x00000800
  4137. // end_wdm
  4138. //
  4139. // The FILE_EXPECT flags will only exist for WinXP. After that they will be
  4140. // ignored and an IRP will be sent in their place.
  4141. //
  4142. #define FILE_CHARACTERISTICS_EXPECT_ORDERLY_REMOVAL 0x00000200
  4143. #define FILE_CHARACTERISTICS_EXPECT_SURPRISE_REMOVAL 0x00000300
  4144. #define FILE_CHARACTERISTICS_REMOVAL_POLICY_MASK 0x00000300
  4145. //
  4146. // flags specified here will be propagated up and down a device stack
  4147. // after FDO and all filter devices are added, but before the device
  4148. // stack is started
  4149. //
  4150. #define FILE_CHARACTERISTICS_PROPAGATED ( FILE_REMOVABLE_MEDIA | \
  4151. FILE_READ_ONLY_DEVICE | \
  4152. FILE_FLOPPY_DISKETTE | \
  4153. FILE_WRITE_ONCE_MEDIA | \
  4154. FILE_DEVICE_SECURE_OPEN )
  4155. //
  4156. // Define the base asynchronous I/O argument types
  4157. //
  4158. typedef struct _IO_STATUS_BLOCK {
  4159. union {
  4160. NTSTATUS Status;
  4161. PVOID Pointer;
  4162. };
  4163. ULONG_PTR Information;
  4164. } IO_STATUS_BLOCK, *PIO_STATUS_BLOCK;
  4165. #if defined(_WIN64)
  4166. typedef struct _IO_STATUS_BLOCK32 {
  4167. NTSTATUS Status;
  4168. ULONG Information;
  4169. } IO_STATUS_BLOCK32, *PIO_STATUS_BLOCK32;
  4170. #endif
  4171. //
  4172. // Define an Asynchronous Procedure Call from I/O viewpoint
  4173. //
  4174. typedef
  4175. VOID
  4176. (NTAPI *PIO_APC_ROUTINE) (
  4177. IN PVOID ApcContext,
  4178. IN PIO_STATUS_BLOCK IoStatusBlock,
  4179. IN ULONG Reserved
  4180. );
  4181. #define PIO_APC_ROUTINE_DEFINED
  4182. //
  4183. // Define the file information class values
  4184. //
  4185. // WARNING: The order of the following values are assumed by the I/O system.
  4186. // Any changes made here should be reflected there as well.
  4187. //
  4188. typedef enum _FILE_INFORMATION_CLASS {
  4189. // end_wdm
  4190. FileDirectoryInformation = 1,
  4191. FileFullDirectoryInformation, // 2
  4192. FileBothDirectoryInformation, // 3
  4193. FileBasicInformation, // 4 wdm
  4194. FileStandardInformation, // 5 wdm
  4195. FileInternalInformation, // 6
  4196. FileEaInformation, // 7
  4197. FileAccessInformation, // 8
  4198. FileNameInformation, // 9
  4199. FileRenameInformation, // 10
  4200. FileLinkInformation, // 11
  4201. FileNamesInformation, // 12
  4202. FileDispositionInformation, // 13
  4203. FilePositionInformation, // 14 wdm
  4204. FileFullEaInformation, // 15
  4205. FileModeInformation, // 16
  4206. FileAlignmentInformation, // 17
  4207. FileAllInformation, // 18
  4208. FileAllocationInformation, // 19
  4209. FileEndOfFileInformation, // 20 wdm
  4210. FileAlternateNameInformation, // 21
  4211. FileStreamInformation, // 22
  4212. FilePipeInformation, // 23
  4213. FilePipeLocalInformation, // 24
  4214. FilePipeRemoteInformation, // 25
  4215. FileMailslotQueryInformation, // 26
  4216. FileMailslotSetInformation, // 27
  4217. FileCompressionInformation, // 28
  4218. FileObjectIdInformation, // 29
  4219. FileCompletionInformation, // 30
  4220. FileMoveClusterInformation, // 31
  4221. FileQuotaInformation, // 32
  4222. FileReparsePointInformation, // 33
  4223. FileNetworkOpenInformation, // 34
  4224. FileAttributeTagInformation, // 35
  4225. FileTrackingInformation, // 36
  4226. FileIdBothDirectoryInformation, // 37
  4227. FileIdFullDirectoryInformation, // 38
  4228. FileValidDataLengthInformation, // 39
  4229. FileShortNameInformation, // 40
  4230. FileMaximumInformation
  4231. // begin_wdm
  4232. } FILE_INFORMATION_CLASS, *PFILE_INFORMATION_CLASS;
  4233. //
  4234. // Define the various structures which are returned on query operations
  4235. //
  4236. typedef struct _FILE_BASIC_INFORMATION {
  4237. LARGE_INTEGER CreationTime;
  4238. LARGE_INTEGER LastAccessTime;
  4239. LARGE_INTEGER LastWriteTime;
  4240. LARGE_INTEGER ChangeTime;
  4241. ULONG FileAttributes;
  4242. } FILE_BASIC_INFORMATION, *PFILE_BASIC_INFORMATION;
  4243. typedef struct _FILE_STANDARD_INFORMATION {
  4244. LARGE_INTEGER AllocationSize;
  4245. LARGE_INTEGER EndOfFile;
  4246. ULONG NumberOfLinks;
  4247. BOOLEAN DeletePending;
  4248. BOOLEAN Directory;
  4249. } FILE_STANDARD_INFORMATION, *PFILE_STANDARD_INFORMATION;
  4250. typedef struct _FILE_POSITION_INFORMATION {
  4251. LARGE_INTEGER CurrentByteOffset;
  4252. } FILE_POSITION_INFORMATION, *PFILE_POSITION_INFORMATION;
  4253. typedef struct _FILE_ALIGNMENT_INFORMATION {
  4254. ULONG AlignmentRequirement;
  4255. } FILE_ALIGNMENT_INFORMATION, *PFILE_ALIGNMENT_INFORMATION;
  4256. typedef struct _FILE_NAME_INFORMATION {
  4257. ULONG FileNameLength;
  4258. WCHAR FileName[1];
  4259. } FILE_NAME_INFORMATION, *PFILE_NAME_INFORMATION;
  4260. typedef struct _FILE_NETWORK_OPEN_INFORMATION {
  4261. LARGE_INTEGER CreationTime;
  4262. LARGE_INTEGER LastAccessTime;
  4263. LARGE_INTEGER LastWriteTime;
  4264. LARGE_INTEGER ChangeTime;
  4265. LARGE_INTEGER AllocationSize;
  4266. LARGE_INTEGER EndOfFile;
  4267. ULONG FileAttributes;
  4268. } FILE_NETWORK_OPEN_INFORMATION, *PFILE_NETWORK_OPEN_INFORMATION;
  4269. typedef struct _FILE_ATTRIBUTE_TAG_INFORMATION {
  4270. ULONG FileAttributes;
  4271. ULONG ReparseTag;
  4272. } FILE_ATTRIBUTE_TAG_INFORMATION, *PFILE_ATTRIBUTE_TAG_INFORMATION;
  4273. typedef struct _FILE_DISPOSITION_INFORMATION {
  4274. BOOLEAN DeleteFile;
  4275. } FILE_DISPOSITION_INFORMATION, *PFILE_DISPOSITION_INFORMATION;
  4276. typedef struct _FILE_END_OF_FILE_INFORMATION {
  4277. LARGE_INTEGER EndOfFile;
  4278. } FILE_END_OF_FILE_INFORMATION, *PFILE_END_OF_FILE_INFORMATION;
  4279. typedef struct _FILE_VALID_DATA_LENGTH_INFORMATION {
  4280. LARGE_INTEGER ValidDataLength;
  4281. } FILE_VALID_DATA_LENGTH_INFORMATION, *PFILE_VALID_DATA_LENGTH_INFORMATION;
  4282. typedef struct _FILE_FULL_EA_INFORMATION {
  4283. ULONG NextEntryOffset;
  4284. UCHAR Flags;
  4285. UCHAR EaNameLength;
  4286. USHORT EaValueLength;
  4287. CHAR EaName[1];
  4288. } FILE_FULL_EA_INFORMATION, *PFILE_FULL_EA_INFORMATION;
  4289. //
  4290. // Define the file system information class values
  4291. //
  4292. // WARNING: The order of the following values are assumed by the I/O system.
  4293. // Any changes made here should be reflected there as well.
  4294. typedef enum _FSINFOCLASS {
  4295. FileFsVolumeInformation = 1,
  4296. FileFsLabelInformation, // 2
  4297. FileFsSizeInformation, // 3
  4298. FileFsDeviceInformation, // 4
  4299. FileFsAttributeInformation, // 5
  4300. FileFsControlInformation, // 6
  4301. FileFsFullSizeInformation, // 7
  4302. FileFsObjectIdInformation, // 8
  4303. FileFsDriverPathInformation, // 9
  4304. FileFsMaximumInformation
  4305. } FS_INFORMATION_CLASS, *PFS_INFORMATION_CLASS;
  4306. typedef struct _FILE_FS_DEVICE_INFORMATION {
  4307. DEVICE_TYPE DeviceType;
  4308. ULONG Characteristics;
  4309. } FILE_FS_DEVICE_INFORMATION, *PFILE_FS_DEVICE_INFORMATION;
  4310. //
  4311. // Define segement buffer structure for scatter/gather read/write.
  4312. //
  4313. typedef union _FILE_SEGMENT_ELEMENT {
  4314. PVOID64 Buffer;
  4315. ULONGLONG Alignment;
  4316. }FILE_SEGMENT_ELEMENT, *PFILE_SEGMENT_ELEMENT;
  4317. //
  4318. // Define the I/O bus interface types.
  4319. //
  4320. typedef enum _INTERFACE_TYPE {
  4321. InterfaceTypeUndefined = -1,
  4322. Internal,
  4323. Isa,
  4324. Eisa,
  4325. MicroChannel,
  4326. TurboChannel,
  4327. PCIBus,
  4328. VMEBus,
  4329. NuBus,
  4330. PCMCIABus,
  4331. CBus,
  4332. MPIBus,
  4333. MPSABus,
  4334. ProcessorInternal,
  4335. InternalPowerBus,
  4336. PNPISABus,
  4337. PNPBus,
  4338. MaximumInterfaceType
  4339. }INTERFACE_TYPE, *PINTERFACE_TYPE;
  4340. //
  4341. // Define the DMA transfer widths.
  4342. //
  4343. typedef enum _DMA_WIDTH {
  4344. Width8Bits,
  4345. Width16Bits,
  4346. Width32Bits,
  4347. MaximumDmaWidth
  4348. }DMA_WIDTH, *PDMA_WIDTH;
  4349. //
  4350. // Define DMA transfer speeds.
  4351. //
  4352. typedef enum _DMA_SPEED {
  4353. Compatible,
  4354. TypeA,
  4355. TypeB,
  4356. TypeC,
  4357. TypeF,
  4358. MaximumDmaSpeed
  4359. }DMA_SPEED, *PDMA_SPEED;
  4360. //
  4361. // Define Interface reference/dereference routines for
  4362. // Interfaces exported by IRP_MN_QUERY_INTERFACE
  4363. //
  4364. typedef VOID (*PINTERFACE_REFERENCE)(PVOID Context);
  4365. typedef VOID (*PINTERFACE_DEREFERENCE)(PVOID Context);
  4366. // end_wdm
  4367. //
  4368. // Define types of bus information.
  4369. //
  4370. typedef enum _BUS_DATA_TYPE {
  4371. ConfigurationSpaceUndefined = -1,
  4372. Cmos,
  4373. EisaConfiguration,
  4374. Pos,
  4375. CbusConfiguration,
  4376. PCIConfiguration,
  4377. VMEConfiguration,
  4378. NuBusConfiguration,
  4379. PCMCIAConfiguration,
  4380. MPIConfiguration,
  4381. MPSAConfiguration,
  4382. PNPISAConfiguration,
  4383. SgiInternalConfiguration,
  4384. MaximumBusDataType
  4385. } BUS_DATA_TYPE, *PBUS_DATA_TYPE;
  4386. //
  4387. // Define I/O Driver error log packet structure. This structure is filled in
  4388. // by the driver.
  4389. //
  4390. typedef struct _IO_ERROR_LOG_PACKET {
  4391. UCHAR MajorFunctionCode;
  4392. UCHAR RetryCount;
  4393. USHORT DumpDataSize;
  4394. USHORT NumberOfStrings;
  4395. USHORT StringOffset;
  4396. USHORT EventCategory;
  4397. NTSTATUS ErrorCode;
  4398. ULONG UniqueErrorValue;
  4399. NTSTATUS FinalStatus;
  4400. ULONG SequenceNumber;
  4401. ULONG IoControlCode;
  4402. LARGE_INTEGER DeviceOffset;
  4403. ULONG DumpData[1];
  4404. }IO_ERROR_LOG_PACKET, *PIO_ERROR_LOG_PACKET;
  4405. //
  4406. // Define the I/O error log message. This message is sent by the error log
  4407. // thread over the lpc port.
  4408. //
  4409. typedef struct _IO_ERROR_LOG_MESSAGE {
  4410. USHORT Type;
  4411. USHORT Size;
  4412. USHORT DriverNameLength;
  4413. LARGE_INTEGER TimeStamp;
  4414. ULONG DriverNameOffset;
  4415. IO_ERROR_LOG_PACKET EntryData;
  4416. }IO_ERROR_LOG_MESSAGE, *PIO_ERROR_LOG_MESSAGE;
  4417. //
  4418. // Define the maximum message size that will be sent over the LPC to the
  4419. // application reading the error log entries.
  4420. //
  4421. //
  4422. // Regardless of LPC size restrictions, ERROR_LOG_MAXIMUM_SIZE must remain
  4423. // a value that can fit in a UCHAR.
  4424. //
  4425. #define ERROR_LOG_LIMIT_SIZE (256-16)
  4426. //
  4427. // This limit, exclusive of IO_ERROR_LOG_MESSAGE_HEADER_LENGTH, also applies
  4428. // to IO_ERROR_LOG_MESSAGE_LENGTH
  4429. //
  4430. #define IO_ERROR_LOG_MESSAGE_HEADER_LENGTH (sizeof(IO_ERROR_LOG_MESSAGE) - \
  4431. sizeof(IO_ERROR_LOG_PACKET) + \
  4432. (sizeof(WCHAR) * 40))
  4433. #define ERROR_LOG_MESSAGE_LIMIT_SIZE \
  4434. (ERROR_LOG_LIMIT_SIZE + IO_ERROR_LOG_MESSAGE_HEADER_LENGTH)
  4435. //
  4436. // IO_ERROR_LOG_MESSAGE_LENGTH is
  4437. // min(PORT_MAXIMUM_MESSAGE_LENGTH, ERROR_LOG_MESSAGE_LIMIT_SIZE)
  4438. //
  4439. #define IO_ERROR_LOG_MESSAGE_LENGTH \
  4440. ((PORT_MAXIMUM_MESSAGE_LENGTH > ERROR_LOG_MESSAGE_LIMIT_SIZE) ? \
  4441. ERROR_LOG_MESSAGE_LIMIT_SIZE : \
  4442. PORT_MAXIMUM_MESSAGE_LENGTH)
  4443. //
  4444. // Define the maximum packet size a driver can allocate.
  4445. //
  4446. #define ERROR_LOG_MAXIMUM_SIZE (IO_ERROR_LOG_MESSAGE_LENGTH - \
  4447. IO_ERROR_LOG_MESSAGE_HEADER_LENGTH)
  4448. #ifdef _WIN64
  4449. #define PORT_MAXIMUM_MESSAGE_LENGTH 512
  4450. #else
  4451. #define PORT_MAXIMUM_MESSAGE_LENGTH 256
  4452. #endif
  4453. //
  4454. // Registry Specific Access Rights.
  4455. //
  4456. #define KEY_QUERY_VALUE (0x0001)
  4457. #define KEY_SET_VALUE (0x0002)
  4458. #define KEY_CREATE_SUB_KEY (0x0004)
  4459. #define KEY_ENUMERATE_SUB_KEYS (0x0008)
  4460. #define KEY_NOTIFY (0x0010)
  4461. #define KEY_CREATE_LINK (0x0020)
  4462. #define KEY_WOW64_32KEY (0x0200)
  4463. #define KEY_WOW64_64KEY (0x0100)
  4464. #define KEY_WOW64_RES (0x0300)
  4465. #define KEY_READ ((STANDARD_RIGHTS_READ |\
  4466. KEY_QUERY_VALUE |\
  4467. KEY_ENUMERATE_SUB_KEYS |\
  4468. KEY_NOTIFY) \
  4469. & \
  4470. (~SYNCHRONIZE))
  4471. #define KEY_WRITE ((STANDARD_RIGHTS_WRITE |\
  4472. KEY_SET_VALUE |\
  4473. KEY_CREATE_SUB_KEY) \
  4474. & \
  4475. (~SYNCHRONIZE))
  4476. #define KEY_EXECUTE ((KEY_READ) \
  4477. & \
  4478. (~SYNCHRONIZE))
  4479. #define KEY_ALL_ACCESS ((STANDARD_RIGHTS_ALL |\
  4480. KEY_QUERY_VALUE |\
  4481. KEY_SET_VALUE |\
  4482. KEY_CREATE_SUB_KEY |\
  4483. KEY_ENUMERATE_SUB_KEYS |\
  4484. KEY_NOTIFY |\
  4485. KEY_CREATE_LINK) \
  4486. & \
  4487. (~SYNCHRONIZE))
  4488. //
  4489. // Open/Create Options
  4490. //
  4491. #define REG_OPTION_RESERVED (0x00000000L) // Parameter is reserved
  4492. #define REG_OPTION_NON_VOLATILE (0x00000000L) // Key is preserved
  4493. // when system is rebooted
  4494. #define REG_OPTION_VOLATILE (0x00000001L) // Key is not preserved
  4495. // when system is rebooted
  4496. #define REG_OPTION_CREATE_LINK (0x00000002L) // Created key is a
  4497. // symbolic link
  4498. #define REG_OPTION_BACKUP_RESTORE (0x00000004L) // open for backup or restore
  4499. // special access rules
  4500. // privilege required
  4501. #define REG_OPTION_OPEN_LINK (0x00000008L) // Open symbolic link
  4502. #define REG_LEGAL_OPTION \
  4503. (REG_OPTION_RESERVED |\
  4504. REG_OPTION_NON_VOLATILE |\
  4505. REG_OPTION_VOLATILE |\
  4506. REG_OPTION_CREATE_LINK |\
  4507. REG_OPTION_BACKUP_RESTORE |\
  4508. REG_OPTION_OPEN_LINK)
  4509. //
  4510. // Key creation/open disposition
  4511. //
  4512. #define REG_CREATED_NEW_KEY (0x00000001L) // New Registry Key created
  4513. #define REG_OPENED_EXISTING_KEY (0x00000002L) // Existing Key opened
  4514. //
  4515. // hive format to be used by Reg(Nt)SaveKeyEx
  4516. //
  4517. #define REG_STANDARD_FORMAT 1
  4518. #define REG_LATEST_FORMAT 2
  4519. #define REG_NO_COMPRESSION 4
  4520. //
  4521. // Key restore flags
  4522. //
  4523. #define REG_WHOLE_HIVE_VOLATILE (0x00000001L) // Restore whole hive volatile
  4524. #define REG_REFRESH_HIVE (0x00000002L) // Unwind changes to last flush
  4525. #define REG_NO_LAZY_FLUSH (0x00000004L) // Never lazy flush this hive
  4526. #define REG_FORCE_RESTORE (0x00000008L) // Force the restore process even when we have open handles on subkeys
  4527. //
  4528. // Key query structures
  4529. //
  4530. typedef struct _KEY_BASIC_INFORMATION {
  4531. LARGE_INTEGER LastWriteTime;
  4532. ULONG TitleIndex;
  4533. ULONG NameLength;
  4534. WCHAR Name[1]; // Variable length string
  4535. } KEY_BASIC_INFORMATION, *PKEY_BASIC_INFORMATION;
  4536. typedef struct _KEY_NODE_INFORMATION {
  4537. LARGE_INTEGER LastWriteTime;
  4538. ULONG TitleIndex;
  4539. ULONG ClassOffset;
  4540. ULONG ClassLength;
  4541. ULONG NameLength;
  4542. WCHAR Name[1]; // Variable length string
  4543. // Class[1]; // Variable length string not declared
  4544. } KEY_NODE_INFORMATION, *PKEY_NODE_INFORMATION;
  4545. typedef struct _KEY_FULL_INFORMATION {
  4546. LARGE_INTEGER LastWriteTime;
  4547. ULONG TitleIndex;
  4548. ULONG ClassOffset;
  4549. ULONG ClassLength;
  4550. ULONG SubKeys;
  4551. ULONG MaxNameLen;
  4552. ULONG MaxClassLen;
  4553. ULONG Values;
  4554. ULONG MaxValueNameLen;
  4555. ULONG MaxValueDataLen;
  4556. WCHAR Class[1]; // Variable length
  4557. } KEY_FULL_INFORMATION, *PKEY_FULL_INFORMATION;
  4558. // end_wdm
  4559. typedef struct _KEY_NAME_INFORMATION {
  4560. ULONG NameLength;
  4561. WCHAR Name[1]; // Variable length string
  4562. } KEY_NAME_INFORMATION, *PKEY_NAME_INFORMATION;
  4563. typedef struct _KEY_CACHED_INFORMATION {
  4564. LARGE_INTEGER LastWriteTime;
  4565. ULONG TitleIndex;
  4566. ULONG SubKeys;
  4567. ULONG MaxNameLen;
  4568. ULONG Values;
  4569. ULONG MaxValueNameLen;
  4570. ULONG MaxValueDataLen;
  4571. ULONG NameLength;
  4572. WCHAR Name[1]; // Variable length string
  4573. } KEY_CACHED_INFORMATION, *PKEY_CACHED_INFORMATION;
  4574. typedef struct _KEY_FLAGS_INFORMATION {
  4575. ULONG UserFlags;
  4576. } KEY_FLAGS_INFORMATION, *PKEY_FLAGS_INFORMATION;
  4577. // begin_wdm
  4578. typedef enum _KEY_INFORMATION_CLASS {
  4579. KeyBasicInformation,
  4580. KeyNodeInformation,
  4581. KeyFullInformation
  4582. // end_wdm
  4583. ,
  4584. KeyNameInformation,
  4585. KeyCachedInformation,
  4586. KeyFlagsInformation
  4587. // begin_wdm
  4588. } KEY_INFORMATION_CLASS;
  4589. typedef struct _KEY_WRITE_TIME_INFORMATION {
  4590. LARGE_INTEGER LastWriteTime;
  4591. } KEY_WRITE_TIME_INFORMATION, *PKEY_WRITE_TIME_INFORMATION;
  4592. typedef struct _KEY_USER_FLAGS_INFORMATION {
  4593. ULONG UserFlags;
  4594. } KEY_USER_FLAGS_INFORMATION, *PKEY_USER_FLAGS_INFORMATION;
  4595. typedef enum _KEY_SET_INFORMATION_CLASS {
  4596. KeyWriteTimeInformation,
  4597. KeyUserFlagsInformation
  4598. } KEY_SET_INFORMATION_CLASS;
  4599. //
  4600. // Value entry query structures
  4601. //
  4602. typedef struct _KEY_VALUE_BASIC_INFORMATION {
  4603. ULONG TitleIndex;
  4604. ULONG Type;
  4605. ULONG NameLength;
  4606. WCHAR Name[1]; // Variable size
  4607. } KEY_VALUE_BASIC_INFORMATION, *PKEY_VALUE_BASIC_INFORMATION;
  4608. typedef struct _KEY_VALUE_FULL_INFORMATION {
  4609. ULONG TitleIndex;
  4610. ULONG Type;
  4611. ULONG DataOffset;
  4612. ULONG DataLength;
  4613. ULONG NameLength;
  4614. WCHAR Name[1]; // Variable size
  4615. // Data[1]; // Variable size data not declared
  4616. } KEY_VALUE_FULL_INFORMATION, *PKEY_VALUE_FULL_INFORMATION;
  4617. typedef struct _KEY_VALUE_PARTIAL_INFORMATION {
  4618. ULONG TitleIndex;
  4619. ULONG Type;
  4620. ULONG DataLength;
  4621. UCHAR Data[1]; // Variable size
  4622. } KEY_VALUE_PARTIAL_INFORMATION, *PKEY_VALUE_PARTIAL_INFORMATION;
  4623. typedef struct _KEY_VALUE_PARTIAL_INFORMATION_ALIGN64 {
  4624. ULONG Type;
  4625. ULONG DataLength;
  4626. UCHAR Data[1]; // Variable size
  4627. } KEY_VALUE_PARTIAL_INFORMATION_ALIGN64, *PKEY_VALUE_PARTIAL_INFORMATION_ALIGN64;
  4628. typedef struct _KEY_VALUE_ENTRY {
  4629. PUNICODE_STRING ValueName;
  4630. ULONG DataLength;
  4631. ULONG DataOffset;
  4632. ULONG Type;
  4633. } KEY_VALUE_ENTRY, *PKEY_VALUE_ENTRY;
  4634. typedef enum _KEY_VALUE_INFORMATION_CLASS {
  4635. KeyValueBasicInformation,
  4636. KeyValueFullInformation,
  4637. KeyValuePartialInformation,
  4638. KeyValueFullInformationAlign64,
  4639. KeyValuePartialInformationAlign64
  4640. } KEY_VALUE_INFORMATION_CLASS;
  4641. #define OBJ_NAME_PATH_SEPARATOR ((WCHAR)L'\\')
  4642. //
  4643. // Object Manager Object Type Specific Access Rights.
  4644. //
  4645. #define OBJECT_TYPE_CREATE (0x0001)
  4646. #define OBJECT_TYPE_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | 0x1)
  4647. //
  4648. // Object Manager Directory Specific Access Rights.
  4649. //
  4650. #define DIRECTORY_QUERY (0x0001)
  4651. #define DIRECTORY_TRAVERSE (0x0002)
  4652. #define DIRECTORY_CREATE_OBJECT (0x0004)
  4653. #define DIRECTORY_CREATE_SUBDIRECTORY (0x0008)
  4654. #define DIRECTORY_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | 0xF)
  4655. //
  4656. // Object Manager Symbolic Link Specific Access Rights.
  4657. //
  4658. #define SYMBOLIC_LINK_QUERY (0x0001)
  4659. #define SYMBOLIC_LINK_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | 0x1)
  4660. typedef struct _OBJECT_NAME_INFORMATION {
  4661. UNICODE_STRING Name;
  4662. } OBJECT_NAME_INFORMATION, *POBJECT_NAME_INFORMATION;
  4663. #define DUPLICATE_CLOSE_SOURCE 0x00000001 // winnt
  4664. #define DUPLICATE_SAME_ACCESS 0x00000002 // winnt
  4665. #define DUPLICATE_SAME_ATTRIBUTES 0x00000004
  4666. //
  4667. // Section Information Structures.
  4668. //
  4669. typedef enum _SECTION_INHERIT {
  4670. ViewShare = 1,
  4671. ViewUnmap = 2
  4672. } SECTION_INHERIT;
  4673. //
  4674. // Section Access Rights.
  4675. //
  4676. // begin_winnt
  4677. #define SECTION_QUERY 0x0001
  4678. #define SECTION_MAP_WRITE 0x0002
  4679. #define SECTION_MAP_READ 0x0004
  4680. #define SECTION_MAP_EXECUTE 0x0008
  4681. #define SECTION_EXTEND_SIZE 0x0010
  4682. #define SECTION_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED|SECTION_QUERY|\
  4683. SECTION_MAP_WRITE | \
  4684. SECTION_MAP_READ | \
  4685. SECTION_MAP_EXECUTE | \
  4686. SECTION_EXTEND_SIZE)
  4687. // end_winnt
  4688. #define SEGMENT_ALL_ACCESS SECTION_ALL_ACCESS
  4689. #define PAGE_NOACCESS 0x01 // winnt
  4690. #define PAGE_READONLY 0x02 // winnt
  4691. #define PAGE_READWRITE 0x04 // winnt
  4692. #define PAGE_WRITECOPY 0x08 // winnt
  4693. #define PAGE_EXECUTE 0x10 // winnt
  4694. #define PAGE_EXECUTE_READ 0x20 // winnt
  4695. #define PAGE_EXECUTE_READWRITE 0x40 // winnt
  4696. #define PAGE_EXECUTE_WRITECOPY 0x80 // winnt
  4697. #define PAGE_GUARD 0x100 // winnt
  4698. #define PAGE_NOCACHE 0x200 // winnt
  4699. #define PAGE_WRITECOMBINE 0x400 // winnt
  4700. #define MEM_COMMIT 0x1000
  4701. #define MEM_RESERVE 0x2000
  4702. #define MEM_DECOMMIT 0x4000
  4703. #define MEM_RELEASE 0x8000
  4704. #define MEM_FREE 0x10000
  4705. #define MEM_PRIVATE 0x20000
  4706. #define MEM_MAPPED 0x40000
  4707. #define MEM_RESET 0x80000
  4708. #define MEM_TOP_DOWN 0x100000
  4709. #define MEM_LARGE_PAGES 0x20000000
  4710. #define MEM_4MB_PAGES 0x80000000
  4711. #define SEC_RESERVE 0x4000000
  4712. #define PROCESS_DUP_HANDLE (0x0040) // winnt
  4713. #define PROCESS_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | \
  4714. 0xFFF)
  4715. // begin_nthal
  4716. #if defined(_WIN64)
  4717. #define MAXIMUM_PROCESSORS 64
  4718. #else
  4719. #define MAXIMUM_PROCESSORS 32
  4720. #endif
  4721. // end_nthal
  4722. // end_winnt
  4723. //
  4724. // Thread Specific Access Rights
  4725. //
  4726. #define THREAD_TERMINATE (0x0001) // winnt
  4727. #define THREAD_SET_INFORMATION (0x0020) // winnt
  4728. #define THREAD_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | \
  4729. 0x3FF)
  4730. //
  4731. // ClientId
  4732. //
  4733. typedef struct _CLIENT_ID {
  4734. HANDLE UniqueProcess;
  4735. HANDLE UniqueThread;
  4736. } CLIENT_ID;
  4737. typedef CLIENT_ID *PCLIENT_ID;
  4738. //
  4739. // Thread Environment Block (and portable part of Thread Information Block)
  4740. //
  4741. //
  4742. // NT_TIB - Thread Information Block - Portable part.
  4743. //
  4744. // This is the subsystem portable part of the Thread Information Block.
  4745. // It appears as the first part of the TEB for all threads which have
  4746. // a user mode component.
  4747. //
  4748. //
  4749. // begin_winnt
  4750. typedef struct _NT_TIB {
  4751. struct _EXCEPTION_REGISTRATION_RECORD *ExceptionList;
  4752. PVOID StackBase;
  4753. PVOID StackLimit;
  4754. PVOID SubSystemTib;
  4755. union {
  4756. PVOID FiberData;
  4757. ULONG Version;
  4758. };
  4759. PVOID ArbitraryUserPointer;
  4760. struct _NT_TIB *Self;
  4761. } NT_TIB;
  4762. typedef NT_TIB *PNT_TIB;
  4763. //
  4764. // 32 and 64 bit specific version for wow64 and the debugger
  4765. //
  4766. typedef struct _NT_TIB32 {
  4767. ULONG ExceptionList;
  4768. ULONG StackBase;
  4769. ULONG StackLimit;
  4770. ULONG SubSystemTib;
  4771. union {
  4772. ULONG FiberData;
  4773. ULONG Version;
  4774. };
  4775. ULONG ArbitraryUserPointer;
  4776. ULONG Self;
  4777. } NT_TIB32, *PNT_TIB32;
  4778. typedef struct _NT_TIB64 {
  4779. ULONG64 ExceptionList;
  4780. ULONG64 StackBase;
  4781. ULONG64 StackLimit;
  4782. ULONG64 SubSystemTib;
  4783. union {
  4784. ULONG64 FiberData;
  4785. ULONG Version;
  4786. };
  4787. ULONG64 ArbitraryUserPointer;
  4788. ULONG64 Self;
  4789. } NT_TIB64, *PNT_TIB64;
  4790. //
  4791. // Process Information Classes
  4792. //
  4793. typedef enum _PROCESSINFOCLASS {
  4794. ProcessBasicInformation,
  4795. ProcessQuotaLimits,
  4796. ProcessIoCounters,
  4797. ProcessVmCounters,
  4798. ProcessTimes,
  4799. ProcessBasePriority,
  4800. ProcessRaisePriority,
  4801. ProcessDebugPort,
  4802. ProcessExceptionPort,
  4803. ProcessAccessToken,
  4804. ProcessLdtInformation,
  4805. ProcessLdtSize,
  4806. ProcessDefaultHardErrorMode,
  4807. ProcessIoPortHandlers, // Note: this is kernel mode only
  4808. ProcessPooledUsageAndLimits,
  4809. ProcessWorkingSetWatch,
  4810. ProcessUserModeIOPL,
  4811. ProcessEnableAlignmentFaultFixup,
  4812. ProcessPriorityClass,
  4813. ProcessWx86Information,
  4814. ProcessHandleCount,
  4815. ProcessAffinityMask,
  4816. ProcessPriorityBoost,
  4817. ProcessDeviceMap,
  4818. ProcessSessionInformation,
  4819. ProcessForegroundInformation,
  4820. ProcessWow64Information,
  4821. ProcessImageFileName,
  4822. ProcessLUIDDeviceMapsEnabled,
  4823. ProcessBreakOnTermination,
  4824. ProcessDebugObjectHandle,
  4825. ProcessDebugFlags,
  4826. ProcessHandleTracing,
  4827. MaxProcessInfoClass // MaxProcessInfoClass should always be the last enum
  4828. } PROCESSINFOCLASS;
  4829. //
  4830. // Thread Information Classes
  4831. //
  4832. typedef enum _THREADINFOCLASS {
  4833. ThreadBasicInformation,
  4834. ThreadTimes,
  4835. ThreadPriority,
  4836. ThreadBasePriority,
  4837. ThreadAffinityMask,
  4838. ThreadImpersonationToken,
  4839. ThreadDescriptorTableEntry,
  4840. ThreadEnableAlignmentFaultFixup,
  4841. ThreadEventPair_Reusable,
  4842. ThreadQuerySetWin32StartAddress,
  4843. ThreadZeroTlsCell,
  4844. ThreadPerformanceCount,
  4845. ThreadAmILastThread,
  4846. ThreadIdealProcessor,
  4847. ThreadPriorityBoost,
  4848. ThreadSetTlsArrayAddress,
  4849. ThreadIsIoPending,
  4850. ThreadHideFromDebugger,
  4851. ThreadBreakOnTermination,
  4852. MaxThreadInfoClass
  4853. } THREADINFOCLASS;
  4854. //
  4855. // Process Information Structures
  4856. //
  4857. //
  4858. // PageFaultHistory Information
  4859. // NtQueryInformationProcess using ProcessWorkingSetWatch
  4860. //
  4861. typedef struct _PROCESS_WS_WATCH_INFORMATION {
  4862. PVOID FaultingPc;
  4863. PVOID FaultingVa;
  4864. } PROCESS_WS_WATCH_INFORMATION, *PPROCESS_WS_WATCH_INFORMATION;
  4865. //
  4866. // Basic Process Information
  4867. // NtQueryInformationProcess using ProcessBasicInfo
  4868. //
  4869. typedef struct _PROCESS_BASIC_INFORMATION {
  4870. NTSTATUS ExitStatus;
  4871. PPEB PebBaseAddress;
  4872. ULONG_PTR AffinityMask;
  4873. KPRIORITY BasePriority;
  4874. ULONG_PTR UniqueProcessId;
  4875. ULONG_PTR InheritedFromUniqueProcessId;
  4876. } PROCESS_BASIC_INFORMATION;
  4877. typedef PROCESS_BASIC_INFORMATION *PPROCESS_BASIC_INFORMATION;
  4878. //
  4879. // Process Device Map information
  4880. // NtQueryInformationProcess using ProcessDeviceMap
  4881. // NtSetInformationProcess using ProcessDeviceMap
  4882. //
  4883. typedef struct _PROCESS_DEVICEMAP_INFORMATION {
  4884. union {
  4885. struct {
  4886. HANDLE DirectoryHandle;
  4887. } Set;
  4888. struct {
  4889. ULONG DriveMap;
  4890. UCHAR DriveType[ 32 ];
  4891. } Query;
  4892. };
  4893. } PROCESS_DEVICEMAP_INFORMATION, *PPROCESS_DEVICEMAP_INFORMATION;
  4894. typedef struct _PROCESS_DEVICEMAP_INFORMATION_EX {
  4895. union {
  4896. struct {
  4897. HANDLE DirectoryHandle;
  4898. } Set;
  4899. struct {
  4900. ULONG DriveMap;
  4901. UCHAR DriveType[ 32 ];
  4902. } Query;
  4903. };
  4904. ULONG Flags; // specifies that the query type
  4905. } PROCESS_DEVICEMAP_INFORMATION_EX, *PPROCESS_DEVICEMAP_INFORMATION_EX;
  4906. //
  4907. // PROCESS_DEVICEMAP_INFORMATION_EX flags
  4908. //
  4909. #define PROCESS_LUID_DOSDEVICES_ONLY 0x00000001
  4910. //
  4911. // Multi-User Session specific Process Information
  4912. // NtQueryInformationProcess using ProcessSessionInformation
  4913. //
  4914. typedef struct _PROCESS_SESSION_INFORMATION {
  4915. ULONG SessionId;
  4916. } PROCESS_SESSION_INFORMATION, *PPROCESS_SESSION_INFORMATION;
  4917. typedef struct _PROCESS_HANDLE_TRACING_ENABLE {
  4918. ULONG Flags;
  4919. } PROCESS_HANDLE_TRACING_ENABLE, *PPROCESS_HANDLE_TRACING_ENABLE;
  4920. #define PROCESS_HANDLE_TRACING_MAX_STACKS 16
  4921. typedef struct _PROCESS_HANDLE_TRACING_ENTRY {
  4922. HANDLE Handle;
  4923. CLIENT_ID ClientId;
  4924. ULONG Type;
  4925. PVOID Stacks[PROCESS_HANDLE_TRACING_MAX_STACKS];
  4926. } PROCESS_HANDLE_TRACING_ENTRY, *PPROCESS_HANDLE_TRACING_ENTRY;
  4927. typedef struct _PROCESS_HANDLE_TRACING_QUERY {
  4928. HANDLE Handle;
  4929. ULONG TotalTraces;
  4930. PROCESS_HANDLE_TRACING_ENTRY HandleTrace[1];
  4931. } PROCESS_HANDLE_TRACING_QUERY, *PPROCESS_HANDLE_TRACING_QUERY;
  4932. //
  4933. // Process Quotas
  4934. // NtQueryInformationProcess using ProcessQuotaLimits
  4935. // NtQueryInformationProcess using ProcessPooledQuotaLimits
  4936. // NtSetInformationProcess using ProcessQuotaLimits
  4937. //
  4938. // begin_winnt
  4939. typedef struct _QUOTA_LIMITS {
  4940. SIZE_T PagedPoolLimit;
  4941. SIZE_T NonPagedPoolLimit;
  4942. SIZE_T MinimumWorkingSetSize;
  4943. SIZE_T MaximumWorkingSetSize;
  4944. SIZE_T PagefileLimit;
  4945. LARGE_INTEGER TimeLimit;
  4946. } QUOTA_LIMITS;
  4947. typedef QUOTA_LIMITS *PQUOTA_LIMITS;
  4948. // end_winnt
  4949. //
  4950. // Process I/O Counters
  4951. // NtQueryInformationProcess using ProcessIoCounters
  4952. //
  4953. // begin_winnt
  4954. typedef struct _IO_COUNTERS {
  4955. ULONGLONG ReadOperationCount;
  4956. ULONGLONG WriteOperationCount;
  4957. ULONGLONG OtherOperationCount;
  4958. ULONGLONG ReadTransferCount;
  4959. ULONGLONG WriteTransferCount;
  4960. ULONGLONG OtherTransferCount;
  4961. } IO_COUNTERS;
  4962. typedef IO_COUNTERS *PIO_COUNTERS;
  4963. // end_winnt
  4964. //
  4965. // Process Virtual Memory Counters
  4966. // NtQueryInformationProcess using ProcessVmCounters
  4967. //
  4968. typedef struct _VM_COUNTERS {
  4969. SIZE_T PeakVirtualSize;
  4970. SIZE_T VirtualSize;
  4971. ULONG PageFaultCount;
  4972. SIZE_T PeakWorkingSetSize;
  4973. SIZE_T WorkingSetSize;
  4974. SIZE_T QuotaPeakPagedPoolUsage;
  4975. SIZE_T QuotaPagedPoolUsage;
  4976. SIZE_T QuotaPeakNonPagedPoolUsage;
  4977. SIZE_T QuotaNonPagedPoolUsage;
  4978. SIZE_T PagefileUsage;
  4979. SIZE_T PeakPagefileUsage;
  4980. } VM_COUNTERS;
  4981. typedef VM_COUNTERS *PVM_COUNTERS;
  4982. typedef struct _VM_COUNTERS_EX {
  4983. SIZE_T PeakVirtualSize;
  4984. SIZE_T VirtualSize;
  4985. ULONG PageFaultCount;
  4986. SIZE_T PeakWorkingSetSize;
  4987. SIZE_T WorkingSetSize;
  4988. SIZE_T QuotaPeakPagedPoolUsage;
  4989. SIZE_T QuotaPagedPoolUsage;
  4990. SIZE_T QuotaPeakNonPagedPoolUsage;
  4991. SIZE_T QuotaNonPagedPoolUsage;
  4992. SIZE_T PagefileUsage;
  4993. SIZE_T PeakPagefileUsage;
  4994. SIZE_T PrivateUsage;
  4995. } VM_COUNTERS_EX;
  4996. typedef VM_COUNTERS_EX *PVM_COUNTERS_EX;
  4997. //
  4998. // Process Pooled Quota Usage and Limits
  4999. // NtQueryInformationProcess using ProcessPooledUsageAndLimits
  5000. //
  5001. typedef struct _POOLED_USAGE_AND_LIMITS {
  5002. SIZE_T PeakPagedPoolUsage;
  5003. SIZE_T PagedPoolUsage;
  5004. SIZE_T PagedPoolLimit;
  5005. SIZE_T PeakNonPagedPoolUsage;
  5006. SIZE_T NonPagedPoolUsage;
  5007. SIZE_T NonPagedPoolLimit;
  5008. SIZE_T PeakPagefileUsage;
  5009. SIZE_T PagefileUsage;
  5010. SIZE_T PagefileLimit;
  5011. } POOLED_USAGE_AND_LIMITS;
  5012. typedef POOLED_USAGE_AND_LIMITS *PPOOLED_USAGE_AND_LIMITS;
  5013. //
  5014. // Process Security Context Information
  5015. // NtSetInformationProcess using ProcessAccessToken
  5016. // PROCESS_SET_ACCESS_TOKEN access to the process is needed
  5017. // to use this info level.
  5018. //
  5019. typedef struct _PROCESS_ACCESS_TOKEN {
  5020. //
  5021. // Handle to Primary token to assign to the process.
  5022. // TOKEN_ASSIGN_PRIMARY access to this token is needed.
  5023. //
  5024. HANDLE Token;
  5025. //
  5026. // Handle to the initial thread of the process.
  5027. // A process's access token can only be changed if the process has
  5028. // no threads or one thread. If the process has no threads, this
  5029. // field must be set to NULL. Otherwise, it must contain a handle
  5030. // open to the process's only thread. THREAD_QUERY_INFORMATION access
  5031. // is needed via this handle.
  5032. HANDLE Thread;
  5033. } PROCESS_ACCESS_TOKEN, *PPROCESS_ACCESS_TOKEN;
  5034. //
  5035. // Process/Thread System and User Time
  5036. // NtQueryInformationProcess using ProcessTimes
  5037. // NtQueryInformationThread using ThreadTimes
  5038. //
  5039. typedef struct _KERNEL_USER_TIMES {
  5040. LARGE_INTEGER CreateTime;
  5041. LARGE_INTEGER ExitTime;
  5042. LARGE_INTEGER KernelTime;
  5043. LARGE_INTEGER UserTime;
  5044. } KERNEL_USER_TIMES;
  5045. typedef KERNEL_USER_TIMES *PKERNEL_USER_TIMES;
  5046. NTSYSCALLAPI
  5047. NTSTATUS
  5048. NTAPI
  5049. NtOpenProcess (
  5050. OUT PHANDLE ProcessHandle,
  5051. IN ACCESS_MASK DesiredAccess,
  5052. IN POBJECT_ATTRIBUTES ObjectAttributes,
  5053. IN PCLIENT_ID ClientId OPTIONAL
  5054. );
  5055. #define NtCurrentProcess() ( (HANDLE)(LONG_PTR) -1 )
  5056. NTSYSCALLAPI
  5057. NTSTATUS
  5058. NTAPI
  5059. NtQueryInformationProcess(
  5060. IN HANDLE ProcessHandle,
  5061. IN PROCESSINFOCLASS ProcessInformationClass,
  5062. OUT PVOID ProcessInformation,
  5063. IN ULONG ProcessInformationLength,
  5064. OUT PULONG ReturnLength OPTIONAL
  5065. );
  5066. #define NtCurrentThread() ( (HANDLE)(LONG_PTR) -2 )
  5067. #ifndef _PO_DDK_
  5068. #define _PO_DDK_
  5069. // begin_winnt
  5070. typedef enum _SYSTEM_POWER_STATE {
  5071. PowerSystemUnspecified = 0,
  5072. PowerSystemWorking = 1,
  5073. PowerSystemSleeping1 = 2,
  5074. PowerSystemSleeping2 = 3,
  5075. PowerSystemSleeping3 = 4,
  5076. PowerSystemHibernate = 5,
  5077. PowerSystemShutdown = 6,
  5078. PowerSystemMaximum = 7
  5079. } SYSTEM_POWER_STATE, *PSYSTEM_POWER_STATE;
  5080. #define POWER_SYSTEM_MAXIMUM 7
  5081. typedef enum {
  5082. PowerActionNone = 0,
  5083. PowerActionReserved,
  5084. PowerActionSleep,
  5085. PowerActionHibernate,
  5086. PowerActionShutdown,
  5087. PowerActionShutdownReset,
  5088. PowerActionShutdownOff,
  5089. PowerActionWarmEject
  5090. } POWER_ACTION, *PPOWER_ACTION;
  5091. typedef enum _DEVICE_POWER_STATE {
  5092. PowerDeviceUnspecified = 0,
  5093. PowerDeviceD0,
  5094. PowerDeviceD1,
  5095. PowerDeviceD2,
  5096. PowerDeviceD3,
  5097. PowerDeviceMaximum
  5098. } DEVICE_POWER_STATE, *PDEVICE_POWER_STATE;
  5099. // end_winnt
  5100. typedef union _POWER_STATE {
  5101. SYSTEM_POWER_STATE SystemState;
  5102. DEVICE_POWER_STATE DeviceState;
  5103. } POWER_STATE, *PPOWER_STATE;
  5104. typedef enum _POWER_STATE_TYPE {
  5105. SystemPowerState = 0,
  5106. DevicePowerState
  5107. } POWER_STATE_TYPE, *PPOWER_STATE_TYPE;
  5108. //
  5109. // Generic power related IOCTLs
  5110. //
  5111. #define IOCTL_QUERY_DEVICE_POWER_STATE \
  5112. CTL_CODE(FILE_DEVICE_BATTERY, 0x0, METHOD_BUFFERED, FILE_READ_ACCESS)
  5113. #define IOCTL_SET_DEVICE_WAKE \
  5114. CTL_CODE(FILE_DEVICE_BATTERY, 0x1, METHOD_BUFFERED, FILE_WRITE_ACCESS)
  5115. #define IOCTL_CANCEL_DEVICE_WAKE \
  5116. CTL_CODE(FILE_DEVICE_BATTERY, 0x2, METHOD_BUFFERED, FILE_WRITE_ACCESS)
  5117. //
  5118. // Defines for W32 interfaces
  5119. //
  5120. // begin_winnt
  5121. #define ES_SYSTEM_REQUIRED ((ULONG)0x00000001)
  5122. #define ES_DISPLAY_REQUIRED ((ULONG)0x00000002)
  5123. #define ES_USER_PRESENT ((ULONG)0x00000004)
  5124. #define ES_CONTINUOUS ((ULONG)0x80000000)
  5125. typedef ULONG EXECUTION_STATE;
  5126. typedef enum {
  5127. LT_DONT_CARE,
  5128. LT_LOWEST_LATENCY
  5129. } LATENCY_TIME;
  5130. typedef enum {
  5131. SystemPowerPolicyAc,
  5132. SystemPowerPolicyDc,
  5133. VerifySystemPolicyAc,
  5134. VerifySystemPolicyDc,
  5135. SystemPowerCapabilities,
  5136. SystemBatteryState,
  5137. SystemPowerStateHandler,
  5138. ProcessorStateHandler,
  5139. SystemPowerPolicyCurrent,
  5140. AdministratorPowerPolicy,
  5141. SystemReserveHiberFile,
  5142. ProcessorInformation,
  5143. SystemPowerInformation,
  5144. ProcessorStateHandler2,
  5145. LastWakeTime, // Compare with KeQueryInterruptTime()
  5146. LastSleepTime, // Compare with KeQueryInterruptTime()
  5147. SystemExecutionState,
  5148. SystemPowerStateNotifyHandler,
  5149. ProcessorPowerPolicyAc,
  5150. ProcessorPowerPolicyDc,
  5151. VerifyProcessorPowerPolicyAc,
  5152. VerifyProcessorPowerPolicyDc,
  5153. ProcessorPowerPolicyCurrent
  5154. } POWER_INFORMATION_LEVEL;
  5155. // begin_wdm
  5156. //
  5157. // System power manager capabilities
  5158. //
  5159. typedef struct {
  5160. ULONG Granularity;
  5161. ULONG Capacity;
  5162. } BATTERY_REPORTING_SCALE, *PBATTERY_REPORTING_SCALE;
  5163. // end_winnt
  5164. // begin_ntminiport
  5165. // begin_ntifs
  5166. #endif // !_PO_DDK_
  5167. #if defined(_X86_)
  5168. //
  5169. // Types to use to contain PFNs and their counts.
  5170. //
  5171. typedef ULONG PFN_COUNT;
  5172. typedef LONG SPFN_NUMBER, *PSPFN_NUMBER;
  5173. typedef ULONG PFN_NUMBER, *PPFN_NUMBER;
  5174. //
  5175. // Define maximum size of flush multiple TB request.
  5176. //
  5177. #define FLUSH_MULTIPLE_MAXIMUM 16
  5178. //
  5179. // Indicate that the i386 compiler supports the pragma textout construct.
  5180. //
  5181. #define ALLOC_PRAGMA 1
  5182. //
  5183. // Indicate that the i386 compiler supports the DATA_SEG("INIT") and
  5184. // DATA_SEG("PAGE") pragmas
  5185. //
  5186. #define ALLOC_DATA_PRAGMA 1
  5187. #define NORMAL_DISPATCH_LENGTH 106
  5188. #define DISPATCH_LENGTH NORMAL_DISPATCH_LENGTH
  5189. //
  5190. // Interrupt Request Level definitions
  5191. //
  5192. #define PASSIVE_LEVEL 0 // Passive release level
  5193. #define LOW_LEVEL 0 // Lowest interrupt level
  5194. #define APC_LEVEL 1 // APC interrupt level
  5195. #define DISPATCH_LEVEL 2 // Dispatcher level
  5196. #define PROFILE_LEVEL 27 // timer used for profiling.
  5197. #define CLOCK1_LEVEL 28 // Interval clock 1 level - Not used on x86
  5198. #define CLOCK2_LEVEL 28 // Interval clock 2 level
  5199. #define IPI_LEVEL 29 // Interprocessor interrupt level
  5200. #define POWER_LEVEL 30 // Power failure level
  5201. #define HIGH_LEVEL 31 // Highest interrupt level
  5202. #if defined(NT_UP)
  5203. #define SYNCH_LEVEL DISPATCH_LEVEL // synchronization level - UP system
  5204. #else
  5205. #define SYNCH_LEVEL (IPI_LEVEL-1) // synchronization level - MP system
  5206. #endif
  5207. //
  5208. // I/O space read and write macros.
  5209. //
  5210. // These have to be actual functions on the 386, because we need
  5211. // to use assembler, but cannot return a value if we inline it.
  5212. //
  5213. // The READ/WRITE_REGISTER_* calls manipulate I/O registers in MEMORY space.
  5214. // (Use x86 move instructions, with LOCK prefix to force correct behavior
  5215. // w.r.t. caches and write buffers.)
  5216. //
  5217. // The READ/WRITE_PORT_* calls manipulate I/O registers in PORT space.
  5218. // (Use x86 in/out instructions.)
  5219. //
  5220. NTKERNELAPI
  5221. UCHAR
  5222. NTAPI
  5223. READ_REGISTER_UCHAR(
  5224. PUCHAR Register
  5225. );
  5226. NTKERNELAPI
  5227. USHORT
  5228. NTAPI
  5229. READ_REGISTER_USHORT(
  5230. PUSHORT Register
  5231. );
  5232. NTKERNELAPI
  5233. ULONG
  5234. NTAPI
  5235. READ_REGISTER_ULONG(
  5236. PULONG Register
  5237. );
  5238. NTKERNELAPI
  5239. VOID
  5240. NTAPI
  5241. READ_REGISTER_BUFFER_UCHAR(
  5242. PUCHAR Register,
  5243. PUCHAR Buffer,
  5244. ULONG Count
  5245. );
  5246. NTKERNELAPI
  5247. VOID
  5248. NTAPI
  5249. READ_REGISTER_BUFFER_USHORT(
  5250. PUSHORT Register,
  5251. PUSHORT Buffer,
  5252. ULONG Count
  5253. );
  5254. NTKERNELAPI
  5255. VOID
  5256. NTAPI
  5257. READ_REGISTER_BUFFER_ULONG(
  5258. PULONG Register,
  5259. PULONG Buffer,
  5260. ULONG Count
  5261. );
  5262. NTKERNELAPI
  5263. VOID
  5264. NTAPI
  5265. WRITE_REGISTER_UCHAR(
  5266. PUCHAR Register,
  5267. UCHAR Value
  5268. );
  5269. NTKERNELAPI
  5270. VOID
  5271. NTAPI
  5272. WRITE_REGISTER_USHORT(
  5273. PUSHORT Register,
  5274. USHORT Value
  5275. );
  5276. NTKERNELAPI
  5277. VOID
  5278. NTAPI
  5279. WRITE_REGISTER_ULONG(
  5280. PULONG Register,
  5281. ULONG Value
  5282. );
  5283. NTKERNELAPI
  5284. VOID
  5285. NTAPI
  5286. WRITE_REGISTER_BUFFER_UCHAR(
  5287. PUCHAR Register,
  5288. PUCHAR Buffer,
  5289. ULONG Count
  5290. );
  5291. NTKERNELAPI
  5292. VOID
  5293. NTAPI
  5294. WRITE_REGISTER_BUFFER_USHORT(
  5295. PUSHORT Register,
  5296. PUSHORT Buffer,
  5297. ULONG Count
  5298. );
  5299. NTKERNELAPI
  5300. VOID
  5301. NTAPI
  5302. WRITE_REGISTER_BUFFER_ULONG(
  5303. PULONG Register,
  5304. PULONG Buffer,
  5305. ULONG Count
  5306. );
  5307. NTHALAPI
  5308. UCHAR
  5309. NTAPI
  5310. READ_PORT_UCHAR(
  5311. PUCHAR Port
  5312. );
  5313. NTHALAPI
  5314. USHORT
  5315. NTAPI
  5316. READ_PORT_USHORT(
  5317. PUSHORT Port
  5318. );
  5319. NTHALAPI
  5320. ULONG
  5321. NTAPI
  5322. READ_PORT_ULONG(
  5323. PULONG Port
  5324. );
  5325. NTHALAPI
  5326. VOID
  5327. NTAPI
  5328. READ_PORT_BUFFER_UCHAR(
  5329. PUCHAR Port,
  5330. PUCHAR Buffer,
  5331. ULONG Count
  5332. );
  5333. NTHALAPI
  5334. VOID
  5335. NTAPI
  5336. READ_PORT_BUFFER_USHORT(
  5337. PUSHORT Port,
  5338. PUSHORT Buffer,
  5339. ULONG Count
  5340. );
  5341. NTHALAPI
  5342. VOID
  5343. NTAPI
  5344. READ_PORT_BUFFER_ULONG(
  5345. PULONG Port,
  5346. PULONG Buffer,
  5347. ULONG Count
  5348. );
  5349. NTHALAPI
  5350. VOID
  5351. NTAPI
  5352. WRITE_PORT_UCHAR(
  5353. PUCHAR Port,
  5354. UCHAR Value
  5355. );
  5356. NTHALAPI
  5357. VOID
  5358. NTAPI
  5359. WRITE_PORT_USHORT(
  5360. PUSHORT Port,
  5361. USHORT Value
  5362. );
  5363. NTHALAPI
  5364. VOID
  5365. NTAPI
  5366. WRITE_PORT_ULONG(
  5367. PULONG Port,
  5368. ULONG Value
  5369. );
  5370. NTHALAPI
  5371. VOID
  5372. NTAPI
  5373. WRITE_PORT_BUFFER_UCHAR(
  5374. PUCHAR Port,
  5375. PUCHAR Buffer,
  5376. ULONG Count
  5377. );
  5378. NTHALAPI
  5379. VOID
  5380. NTAPI
  5381. WRITE_PORT_BUFFER_USHORT(
  5382. PUSHORT Port,
  5383. PUSHORT Buffer,
  5384. ULONG Count
  5385. );
  5386. NTHALAPI
  5387. VOID
  5388. NTAPI
  5389. WRITE_PORT_BUFFER_ULONG(
  5390. PULONG Port,
  5391. PULONG Buffer,
  5392. ULONG Count
  5393. );
  5394. // end_ntndis
  5395. //
  5396. // Get data cache fill size.
  5397. //
  5398. #if PRAGMA_DEPRECATED_DDK
  5399. #pragma deprecated(KeGetDcacheFillSize) // Use GetDmaAlignment
  5400. #endif
  5401. #define KeGetDcacheFillSize() 1L
  5402. #define KeFlushIoBuffers(Mdl, ReadOperation, DmaOperation)
  5403. #define ExAcquireSpinLock(Lock, OldIrql) KeAcquireSpinLock((Lock), (OldIrql))
  5404. #define ExReleaseSpinLock(Lock, OldIrql) KeReleaseSpinLock((Lock), (OldIrql))
  5405. #define ExAcquireSpinLockAtDpcLevel(Lock) KeAcquireSpinLockAtDpcLevel(Lock)
  5406. #define ExReleaseSpinLockFromDpcLevel(Lock) KeReleaseSpinLockFromDpcLevel(Lock)
  5407. #if defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_)
  5408. // begin_wdm
  5409. #define KeQueryTickCount(CurrentCount ) { \
  5410. volatile PKSYSTEM_TIME _TickCount = *((PKSYSTEM_TIME *)(&KeTickCount)); \
  5411. while (TRUE) { \
  5412. (CurrentCount)->HighPart = _TickCount->High1Time; \
  5413. (CurrentCount)->LowPart = _TickCount->LowPart; \
  5414. if ((CurrentCount)->HighPart == _TickCount->High2Time) break; \
  5415. _asm { rep nop } \
  5416. } \
  5417. }
  5418. // end_wdm
  5419. #else
  5420. VOID
  5421. NTAPI
  5422. KeQueryTickCount (
  5423. OUT PLARGE_INTEGER CurrentCount
  5424. );
  5425. #endif // defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_)
  5426. //
  5427. // Processor Control Region Structure Definition
  5428. //
  5429. #define PCR_MINOR_VERSION 1
  5430. #define PCR_MAJOR_VERSION 1
  5431. typedef struct _KPCR {
  5432. //
  5433. // Start of the architecturally defined section of the PCR. This section
  5434. // may be directly addressed by vendor/platform specific HAL code and will
  5435. // not change from version to version of NT.
  5436. //
  5437. NT_TIB NtTib;
  5438. struct _KPCR *SelfPcr; // flat address of this PCR
  5439. struct _KPRCB *Prcb; // pointer to Prcb
  5440. KIRQL Irql;
  5441. ULONG IRR;
  5442. ULONG IrrActive;
  5443. ULONG IDR;
  5444. PVOID KdVersionBlock;
  5445. struct _KIDTENTRY *IDT;
  5446. struct _KGDTENTRY *GDT;
  5447. struct _KTSS *TSS;
  5448. USHORT MajorVersion;
  5449. USHORT MinorVersion;
  5450. KAFFINITY SetMember;
  5451. ULONG StallScaleFactor;
  5452. UCHAR DebugActive;
  5453. UCHAR Number;
  5454. } KPCR, *PKPCR;
  5455. //
  5456. // The non-volatile 387 state
  5457. //
  5458. typedef struct _KFLOATING_SAVE {
  5459. ULONG ControlWord;
  5460. ULONG StatusWord;
  5461. ULONG ErrorOffset;
  5462. ULONG ErrorSelector;
  5463. ULONG DataOffset; // Not used in wdm
  5464. ULONG DataSelector;
  5465. ULONG Cr0NpxState;
  5466. ULONG Spare1; // Not used in wdm
  5467. } KFLOATING_SAVE, *PKFLOATING_SAVE;
  5468. //
  5469. // i386 Specific portions of mm component
  5470. //
  5471. //
  5472. // Define the page size for the Intel 386 as 4096 (0x1000).
  5473. //
  5474. #define PAGE_SIZE 0x1000
  5475. //
  5476. // Define the number of trailing zeroes in a page aligned virtual address.
  5477. // This is used as the shift count when shifting virtual addresses to
  5478. // virtual page numbers.
  5479. //
  5480. #define PAGE_SHIFT 12L
  5481. // end_ntndis end_wdm
  5482. //
  5483. // Define the number of bits to shift to right justify the Page Directory Index
  5484. // field of a PTE.
  5485. //
  5486. #define PDI_SHIFT_X86 22
  5487. #define PDI_SHIFT_X86PAE 21
  5488. #if !defined (_X86PAE_)
  5489. #define PDI_SHIFT PDI_SHIFT_X86
  5490. #else
  5491. #define PDI_SHIFT PDI_SHIFT_X86PAE
  5492. #define PPI_SHIFT 30
  5493. #endif
  5494. //
  5495. // Define the number of bits to shift to right justify the Page Table Index
  5496. // field of a PTE.
  5497. //
  5498. #define PTI_SHIFT 12
  5499. //
  5500. // Define the highest user address and user probe address.
  5501. //
  5502. extern PVOID *MmHighestUserAddress;
  5503. extern PVOID *MmSystemRangeStart;
  5504. extern ULONG *MmUserProbeAddress;
  5505. #define MM_HIGHEST_USER_ADDRESS *MmHighestUserAddress
  5506. #define MM_SYSTEM_RANGE_START *MmSystemRangeStart
  5507. #define MM_USER_PROBE_ADDRESS *MmUserProbeAddress
  5508. //
  5509. // The lowest user address reserves the low 64k.
  5510. //
  5511. #define MM_LOWEST_USER_ADDRESS (PVOID)0x10000
  5512. //
  5513. // The lowest address for system space.
  5514. //
  5515. #if !defined (_X86PAE_)
  5516. #define MM_LOWEST_SYSTEM_ADDRESS (PVOID)0xC0800000
  5517. #else
  5518. #define MM_LOWEST_SYSTEM_ADDRESS (PVOID)0xC0C00000
  5519. #endif
  5520. // begin_wdm
  5521. #define MmGetProcedureAddress(Address) (Address)
  5522. #define MmLockPagableCodeSection(Address) MmLockPagableDataSection(Address)
  5523. #define KIP0PCRADDRESS 0xffdff000
  5524. #define KI_USER_SHARED_DATA 0xffdf0000
  5525. #define SharedUserData ((KUSER_SHARED_DATA * const) KI_USER_SHARED_DATA)
  5526. //
  5527. // Result type definition for i386. (Machine specific enumerate type
  5528. // which is return type for portable exinterlockedincrement/decrement
  5529. // procedures.) In general, you should use the enumerated type defined
  5530. // in ex.h instead of directly referencing these constants.
  5531. //
  5532. // Flags loaded into AH by LAHF instruction
  5533. #define EFLAG_SIGN 0x8000
  5534. #define EFLAG_ZERO 0x4000
  5535. #define EFLAG_SELECT (EFLAG_SIGN | EFLAG_ZERO)
  5536. #define RESULT_NEGATIVE ((EFLAG_SIGN & ~EFLAG_ZERO) & EFLAG_SELECT)
  5537. #define RESULT_ZERO ((~EFLAG_SIGN & EFLAG_ZERO) & EFLAG_SELECT)
  5538. #define RESULT_POSITIVE ((~EFLAG_SIGN & ~EFLAG_ZERO) & EFLAG_SELECT)
  5539. //
  5540. // Convert various portable ExInterlock APIs into their architectural
  5541. // equivalents.
  5542. //
  5543. #if PRAGMA_DEPRECATED_DDK
  5544. #pragma deprecated(ExInterlockedIncrementLong) // Use InterlockedIncrement
  5545. #pragma deprecated(ExInterlockedDecrementLong) // Use InterlockedDecrement
  5546. #pragma deprecated(ExInterlockedExchangeUlong) // Use InterlockedExchange
  5547. #endif
  5548. #define ExInterlockedIncrementLong(Addend,Lock) \
  5549. Exfi386InterlockedIncrementLong(Addend)
  5550. #define ExInterlockedDecrementLong(Addend,Lock) \
  5551. Exfi386InterlockedDecrementLong(Addend)
  5552. #define ExInterlockedExchangeUlong(Target,Value,Lock) \
  5553. Exfi386InterlockedExchangeUlong(Target,Value)
  5554. // begin_wdm
  5555. #define ExInterlockedAddUlong ExfInterlockedAddUlong
  5556. #define ExInterlockedInsertHeadList ExfInterlockedInsertHeadList
  5557. #define ExInterlockedInsertTailList ExfInterlockedInsertTailList
  5558. #define ExInterlockedRemoveHeadList ExfInterlockedRemoveHeadList
  5559. #define ExInterlockedPopEntryList ExfInterlockedPopEntryList
  5560. #define ExInterlockedPushEntryList ExfInterlockedPushEntryList
  5561. // end_wdm
  5562. //
  5563. // Prototypes for architectural specific versions of Exi386 Api
  5564. //
  5565. //
  5566. // Interlocked result type is portable, but its values are machine specific.
  5567. // Constants for value are in i386.h, mips.h, etc.
  5568. //
  5569. typedef enum _INTERLOCKED_RESULT {
  5570. ResultNegative = RESULT_NEGATIVE,
  5571. ResultZero = RESULT_ZERO,
  5572. ResultPositive = RESULT_POSITIVE
  5573. } INTERLOCKED_RESULT;
  5574. NTKERNELAPI
  5575. INTERLOCKED_RESULT
  5576. FASTCALL
  5577. Exfi386InterlockedIncrementLong (
  5578. IN PLONG Addend
  5579. );
  5580. NTKERNELAPI
  5581. INTERLOCKED_RESULT
  5582. FASTCALL
  5583. Exfi386InterlockedDecrementLong (
  5584. IN PLONG Addend
  5585. );
  5586. NTKERNELAPI
  5587. ULONG
  5588. FASTCALL
  5589. Exfi386InterlockedExchangeUlong (
  5590. IN PULONG Target,
  5591. IN ULONG Value
  5592. );
  5593. #if !defined(_WINBASE_) && !defined(NONTOSPINTERLOCK)
  5594. #if !defined(MIDL_PASS) // wdm
  5595. #if defined(NO_INTERLOCKED_INTRINSICS) || defined(_CROSS_PLATFORM_)
  5596. // begin_wdm
  5597. NTKERNELAPI
  5598. LONG
  5599. FASTCALL
  5600. InterlockedIncrement(
  5601. IN LONG volatile *Addend
  5602. );
  5603. NTKERNELAPI
  5604. LONG
  5605. FASTCALL
  5606. InterlockedDecrement(
  5607. IN LONG volatile *Addend
  5608. );
  5609. NTKERNELAPI
  5610. LONG
  5611. FASTCALL
  5612. InterlockedExchange(
  5613. IN OUT LONG volatile *Target,
  5614. IN LONG Value
  5615. );
  5616. #define InterlockedExchangePointer(Target, Value) \
  5617. (PVOID)InterlockedExchange((PLONG)(Target), (LONG)(Value))
  5618. LONG
  5619. FASTCALL
  5620. InterlockedExchangeAdd(
  5621. IN OUT LONG volatile *Addend,
  5622. IN LONG Increment
  5623. );
  5624. NTKERNELAPI
  5625. LONG
  5626. FASTCALL
  5627. InterlockedCompareExchange(
  5628. IN OUT LONG volatile *Destination,
  5629. IN LONG ExChange,
  5630. IN LONG Comperand
  5631. );
  5632. #define InterlockedCompareExchangePointer(Destination, ExChange, Comperand) \
  5633. (PVOID)InterlockedCompareExchange((PLONG)Destination, (LONG)ExChange, (LONG)Comperand)
  5634. #define InterlockedCompareExchange64(Destination, ExChange, Comperand) \
  5635. ExfInterlockedCompareExchange64(Destination, &(ExChange), &(Comperand))
  5636. NTKERNELAPI
  5637. LONGLONG
  5638. FASTCALL
  5639. ExfInterlockedCompareExchange64(
  5640. IN OUT LONGLONG volatile *Destination,
  5641. IN PLONGLONG ExChange,
  5642. IN PLONGLONG Comperand
  5643. );
  5644. // end_wdm
  5645. #else // NO_INTERLOCKED_INCREMENTS || _CROSS_PLATFORM_
  5646. #define InterlockedExchangePointer(Target, Value) \
  5647. (PVOID)InterlockedExchange((PLONG)Target, (LONG)Value)
  5648. #if (_MSC_FULL_VER > 13009037)
  5649. LONG
  5650. __cdecl
  5651. _InterlockedExchange(
  5652. IN OUT LONG volatile *Target,
  5653. IN LONG Value
  5654. );
  5655. #pragma intrinsic (_InterlockedExchange)
  5656. #define InterlockedExchange _InterlockedExchange
  5657. #else
  5658. FORCEINLINE
  5659. LONG
  5660. FASTCALL
  5661. InterlockedExchange(
  5662. IN OUT LONG volatile *Target,
  5663. IN LONG Value
  5664. )
  5665. {
  5666. __asm {
  5667. mov eax, Value
  5668. mov ecx, Target
  5669. xchg [ecx], eax
  5670. }
  5671. }
  5672. #endif
  5673. #if (_MSC_FULL_VER > 13009037)
  5674. LONG
  5675. __cdecl
  5676. _InterlockedIncrement(
  5677. IN LONG volatile *Addend
  5678. );
  5679. #pragma intrinsic (_InterlockedIncrement)
  5680. #define InterlockedIncrement _InterlockedIncrement
  5681. #else
  5682. #define InterlockedIncrement(Addend) (InterlockedExchangeAdd (Addend, 1)+1)
  5683. #endif
  5684. #if (_MSC_FULL_VER > 13009037)
  5685. LONG
  5686. __cdecl
  5687. _InterlockedDecrement(
  5688. IN LONG volatile *Addend
  5689. );
  5690. #pragma intrinsic (_InterlockedDecrement)
  5691. #define InterlockedDecrement _InterlockedDecrement
  5692. #else
  5693. #define InterlockedDecrement(Addend) (InterlockedExchangeAdd (Addend, -1)-1)
  5694. #endif
  5695. #if (_MSC_FULL_VER > 13009037)
  5696. LONG
  5697. __cdecl
  5698. _InterlockedExchangeAdd(
  5699. IN OUT LONG volatile *Addend,
  5700. IN LONG Increment
  5701. );
  5702. #pragma intrinsic (_InterlockedExchangeAdd)
  5703. #define InterlockedExchangeAdd _InterlockedExchangeAdd
  5704. #else
  5705. // begin_wdm
  5706. FORCEINLINE
  5707. LONG
  5708. FASTCALL
  5709. InterlockedExchangeAdd(
  5710. IN OUT LONG volatile *Addend,
  5711. IN LONG Increment
  5712. )
  5713. {
  5714. __asm {
  5715. mov eax, Increment
  5716. mov ecx, Addend
  5717. lock xadd [ecx], eax
  5718. }
  5719. }
  5720. // end_wdm
  5721. #endif
  5722. #if (_MSC_FULL_VER > 13009037)
  5723. LONG
  5724. __cdecl
  5725. _InterlockedCompareExchange (
  5726. IN OUT LONG volatile *Destination,
  5727. IN LONG ExChange,
  5728. IN LONG Comperand
  5729. );
  5730. #pragma intrinsic (_InterlockedCompareExchange)
  5731. #define InterlockedCompareExchange (LONG)_InterlockedCompareExchange
  5732. #else
  5733. FORCEINLINE
  5734. LONG
  5735. FASTCALL
  5736. InterlockedCompareExchange(
  5737. IN OUT LONG volatile *Destination,
  5738. IN LONG Exchange,
  5739. IN LONG Comperand
  5740. )
  5741. {
  5742. __asm {
  5743. mov eax, Comperand
  5744. mov ecx, Destination
  5745. mov edx, Exchange
  5746. lock cmpxchg [ecx], edx
  5747. }
  5748. }
  5749. #endif
  5750. #define InterlockedCompareExchangePointer(Destination, ExChange, Comperand) \
  5751. (PVOID)InterlockedCompareExchange((PLONG)Destination, (LONG)ExChange, (LONG)Comperand)
  5752. #define InterlockedCompareExchange64(Destination, ExChange, Comperand) \
  5753. ExfInterlockedCompareExchange64(Destination, &(ExChange), &(Comperand))
  5754. NTKERNELAPI
  5755. LONGLONG
  5756. FASTCALL
  5757. ExfInterlockedCompareExchange64(
  5758. IN OUT LONGLONG volatile *Destination,
  5759. IN PLONGLONG ExChange,
  5760. IN PLONGLONG Comperand
  5761. );
  5762. #endif // INTERLOCKED_INTRINSICS || _CROSS_PLATFORM_
  5763. // begin_wdm
  5764. #endif // MIDL_PASS
  5765. #endif // __WINBASE__ && !NONTOSPINTERLOCK
  5766. //
  5767. // Turn these instrinsics off until the compiler can handle them
  5768. //
  5769. #if (_MSC_FULL_VER > 13009037)
  5770. LONG
  5771. _InterlockedOr (
  5772. IN OUT PLONG Target,
  5773. IN LONG Set
  5774. );
  5775. #pragma intrinsic (_InterlockedOr)
  5776. #define InterlockedOr _InterlockedOr
  5777. LONG
  5778. _InterlockedAnd (
  5779. IN OUT LONG volatile *Target,
  5780. IN LONG Set
  5781. );
  5782. #pragma intrinsic (_InterlockedAnd)
  5783. #define InterlockedAnd _InterlockedAnd
  5784. LONG
  5785. _InterlockedXor (
  5786. IN OUT LONG volatile Target,
  5787. IN LONG Set
  5788. );
  5789. #pragma intrinsic (_InterlockedXor)
  5790. #define InterlockedXor _InterlockedXor
  5791. #else // compiler version
  5792. FORCEINLINE
  5793. LONG
  5794. InterlockedAnd (
  5795. IN OUT LONG volatile *Target,
  5796. LONG Set
  5797. )
  5798. {
  5799. LONG i;
  5800. LONG j;
  5801. j = *Target;
  5802. do {
  5803. i = j;
  5804. j = InterlockedCompareExchange(Target,
  5805. i & Set,
  5806. i);
  5807. } while (i != j);
  5808. return j;
  5809. }
  5810. FORCEINLINE
  5811. LONG
  5812. InterlockedOr (
  5813. IN OUT LONG volatile *Target,
  5814. IN LONG Set
  5815. )
  5816. {
  5817. LONG i;
  5818. LONG j;
  5819. j = *Target;
  5820. do {
  5821. i = j;
  5822. j = InterlockedCompareExchange(Target,
  5823. i | Set,
  5824. i);
  5825. } while (i != j);
  5826. return j;
  5827. }
  5828. #endif // compiler version
  5829. #if !defined(MIDL_PASS) && defined(_M_IX86)
  5830. //
  5831. // i386 function definitions
  5832. //
  5833. #pragma warning(disable:4035) // re-enable below
  5834. // end_wdm
  5835. #if NT_UP
  5836. #define _PCR ds:[KIP0PCRADDRESS]
  5837. #else
  5838. #define _PCR fs:[0]
  5839. #endif
  5840. //
  5841. // Get current IRQL.
  5842. //
  5843. // On x86 this function resides in the HAL
  5844. //
  5845. NTHALAPI
  5846. KIRQL
  5847. NTAPI
  5848. KeGetCurrentIrql();
  5849. // end_wdm
  5850. //
  5851. // Get the current processor number
  5852. //
  5853. FORCEINLINE
  5854. ULONG
  5855. NTAPI
  5856. KeGetCurrentProcessorNumber(VOID)
  5857. {
  5858. __asm { movzx eax, _PCR KPCR.Number }
  5859. }
  5860. #pragma warning(default:4035)
  5861. // begin_wdm
  5862. #endif // !defined(MIDL_PASS) && defined(_M_IX86)
  5863. NTKERNELAPI
  5864. NTSTATUS
  5865. NTAPI
  5866. KeSaveFloatingPointState (
  5867. OUT PKFLOATING_SAVE FloatSave
  5868. );
  5869. NTKERNELAPI
  5870. NTSTATUS
  5871. NTAPI
  5872. KeRestoreFloatingPointState (
  5873. IN PKFLOATING_SAVE FloatSave
  5874. );
  5875. #endif // defined(_X86_)
  5876. // Use the following for kernel mode runtime checks of X86 system architecture
  5877. #ifdef _X86_
  5878. #ifdef IsNEC_98
  5879. #undef IsNEC_98
  5880. #endif
  5881. #ifdef IsNotNEC_98
  5882. #undef IsNotNEC_98
  5883. #endif
  5884. #ifdef SetNEC_98
  5885. #undef SetNEC_98
  5886. #endif
  5887. #ifdef SetNotNEC_98
  5888. #undef SetNotNEC_98
  5889. #endif
  5890. #define IsNEC_98 (SharedUserData->AlternativeArchitecture == NEC98x86)
  5891. #define IsNotNEC_98 (SharedUserData->AlternativeArchitecture != NEC98x86)
  5892. #define SetNEC_98 SharedUserData->AlternativeArchitecture = NEC98x86
  5893. #define SetNotNEC_98 SharedUserData->AlternativeArchitecture = StandardDesign
  5894. #endif
  5895. #if defined(_M_AMD64) && !defined(RC_INVOKED) && !defined(MIDL_PASS)
  5896. //
  5897. // Define intrinsic function to do in's and out's.
  5898. //
  5899. #ifdef __cplusplus
  5900. extern "C" {
  5901. #endif
  5902. UCHAR
  5903. __inbyte (
  5904. IN USHORT Port
  5905. );
  5906. USHORT
  5907. __inword (
  5908. IN USHORT Port
  5909. );
  5910. ULONG
  5911. __indword (
  5912. IN USHORT Port
  5913. );
  5914. VOID
  5915. __outbyte (
  5916. IN USHORT Port,
  5917. IN UCHAR Data
  5918. );
  5919. VOID
  5920. __outword (
  5921. IN USHORT Port,
  5922. IN USHORT Data
  5923. );
  5924. VOID
  5925. __outdword (
  5926. IN USHORT Port,
  5927. IN ULONG Data
  5928. );
  5929. VOID
  5930. __inbytestring (
  5931. IN USHORT Port,
  5932. IN PUCHAR Buffer,
  5933. IN ULONG Count
  5934. );
  5935. VOID
  5936. __inwordstring (
  5937. IN USHORT Port,
  5938. IN PUSHORT Buffer,
  5939. IN ULONG Count
  5940. );
  5941. VOID
  5942. __indwordstring (
  5943. IN USHORT Port,
  5944. IN PULONG Buffer,
  5945. IN ULONG Count
  5946. );
  5947. VOID
  5948. __outbytestring (
  5949. IN USHORT Port,
  5950. IN PUCHAR Buffer,
  5951. IN ULONG Count
  5952. );
  5953. VOID
  5954. __outwordstring (
  5955. IN USHORT Port,
  5956. IN PUSHORT Buffer,
  5957. IN ULONG Count
  5958. );
  5959. VOID
  5960. __outdwordstring (
  5961. IN USHORT Port,
  5962. IN PULONG Buffer,
  5963. IN ULONG Count
  5964. );
  5965. #ifdef __cplusplus
  5966. }
  5967. #endif
  5968. #pragma intrinsic(__inbyte)
  5969. #pragma intrinsic(__inword)
  5970. #pragma intrinsic(__indword)
  5971. #pragma intrinsic(__outbyte)
  5972. #pragma intrinsic(__outword)
  5973. #pragma intrinsic(__outdword)
  5974. #pragma intrinsic(__inbytestring)
  5975. #pragma intrinsic(__inwordstring)
  5976. #pragma intrinsic(__indwordstring)
  5977. #pragma intrinsic(__outbytestring)
  5978. #pragma intrinsic(__outwordstring)
  5979. #pragma intrinsic(__outdwordstring)
  5980. //
  5981. // Interlocked intrinsic functions.
  5982. //
  5983. #define InterlockedAnd _InterlockedAnd
  5984. #define InterlockedOr _InterlockedOr
  5985. #define InterlockedXor _InterlockedXor
  5986. #define InterlockedIncrement _InterlockedIncrement
  5987. #define InterlockedDecrement _InterlockedDecrement
  5988. #define InterlockedAdd _InterlockedAdd
  5989. #define InterlockedExchange _InterlockedExchange
  5990. #define InterlockedExchangeAdd _InterlockedExchangeAdd
  5991. #define InterlockedCompareExchange _InterlockedCompareExchange
  5992. #define InterlockedAnd64 _InterlockedAnd64
  5993. #define InterlockedOr64 _InterlockedOr64
  5994. #define InterlockedXor64 _InterlockedXor64
  5995. #define InterlockedIncrement64 _InterlockedIncrement64
  5996. #define InterlockedDecrement64 _InterlockedDecrement64
  5997. #define InterlockedAdd64 _InterlockedAdd64
  5998. #define InterlockedExchange64 _InterlockedExchange64
  5999. #define InterlockedExchangeAdd64 _InterlockedExchangeAdd64
  6000. #define InterlockedCompareExchange64 _InterlockedCompareExchange64
  6001. #define InterlockedExchangePointer _InterlockedExchangePointer
  6002. #define InterlockedCompareExchangePointer _InterlockedCompareExchangePointer
  6003. #ifdef __cplusplus
  6004. extern "C" {
  6005. #endif
  6006. LONG
  6007. InterlockedAnd (
  6008. IN OUT LONG volatile *Destination,
  6009. IN LONG Value
  6010. );
  6011. LONG
  6012. InterlockedOr (
  6013. IN OUT LONG volatile *Destination,
  6014. IN LONG Value
  6015. );
  6016. LONG
  6017. InterlockedXor (
  6018. IN OUT LONG volatile *Destination,
  6019. IN LONG Value
  6020. );
  6021. LONG64
  6022. InterlockedAnd64 (
  6023. IN OUT LONG64 volatile *Destination,
  6024. IN LONG64 Value
  6025. );
  6026. LONG64
  6027. InterlockedOr64 (
  6028. IN OUT LONG64 volatile *Destination,
  6029. IN LONG64 Value
  6030. );
  6031. LONG64
  6032. InterlockedXor64 (
  6033. IN OUT LONG64 volatile *Destination,
  6034. IN LONG64 Value
  6035. );
  6036. LONG
  6037. InterlockedIncrement(
  6038. IN OUT LONG volatile *Addend
  6039. );
  6040. LONG
  6041. InterlockedDecrement(
  6042. IN OUT LONG volatile *Addend
  6043. );
  6044. LONG
  6045. InterlockedExchange(
  6046. IN OUT LONG volatile *Target,
  6047. IN LONG Value
  6048. );
  6049. LONG
  6050. InterlockedExchangeAdd(
  6051. IN OUT LONG volatile *Addend,
  6052. IN LONG Value
  6053. );
  6054. #if !defined(_X86AMD64_)
  6055. __forceinline
  6056. LONG
  6057. InterlockedAdd(
  6058. IN OUT LONG volatile *Addend,
  6059. IN LONG Value
  6060. )
  6061. {
  6062. return InterlockedExchangeAdd(Addend, Value) + Value;
  6063. }
  6064. #endif
  6065. LONG
  6066. InterlockedCompareExchange (
  6067. IN OUT LONG volatile *Destination,
  6068. IN LONG ExChange,
  6069. IN LONG Comperand
  6070. );
  6071. LONG64
  6072. InterlockedIncrement64(
  6073. IN OUT LONG64 volatile *Addend
  6074. );
  6075. LONG64
  6076. InterlockedDecrement64(
  6077. IN OUT LONG64 volatile *Addend
  6078. );
  6079. LONG64
  6080. InterlockedExchange64(
  6081. IN OUT LONG64 volatile *Target,
  6082. IN LONG64 Value
  6083. );
  6084. LONG64
  6085. InterlockedExchangeAdd64(
  6086. IN OUT LONG64 volatile *Addend,
  6087. IN LONG64 Value
  6088. );
  6089. #if !defined(_X86AMD64_)
  6090. __forceinline
  6091. LONG64
  6092. InterlockedAdd64(
  6093. IN OUT LONG64 volatile *Addend,
  6094. IN LONG64 Value
  6095. )
  6096. {
  6097. return InterlockedExchangeAdd64(Addend, Value) + Value;
  6098. }
  6099. #endif
  6100. LONG64
  6101. InterlockedCompareExchange64 (
  6102. IN OUT LONG64 volatile *Destination,
  6103. IN LONG64 ExChange,
  6104. IN LONG64 Comperand
  6105. );
  6106. PVOID
  6107. InterlockedCompareExchangePointer (
  6108. IN OUT PVOID volatile *Destination,
  6109. IN PVOID Exchange,
  6110. IN PVOID Comperand
  6111. );
  6112. PVOID
  6113. InterlockedExchangePointer(
  6114. IN OUT PVOID volatile *Target,
  6115. IN PVOID Value
  6116. );
  6117. #pragma intrinsic(_InterlockedAnd)
  6118. #pragma intrinsic(_InterlockedOr)
  6119. #pragma intrinsic(_InterlockedXor)
  6120. #pragma intrinsic(_InterlockedIncrement)
  6121. #pragma intrinsic(_InterlockedDecrement)
  6122. #pragma intrinsic(_InterlockedExchange)
  6123. #pragma intrinsic(_InterlockedExchangeAdd)
  6124. #pragma intrinsic(_InterlockedCompareExchange)
  6125. #pragma intrinsic(_InterlockedAnd64)
  6126. #pragma intrinsic(_InterlockedOr64)
  6127. #pragma intrinsic(_InterlockedXor64)
  6128. #pragma intrinsic(_InterlockedIncrement64)
  6129. #pragma intrinsic(_InterlockedDecrement64)
  6130. #pragma intrinsic(_InterlockedExchange64)
  6131. #pragma intrinsic(_InterlockedExchangeAdd64)
  6132. #pragma intrinsic(_InterlockedCompareExchange64)
  6133. #pragma intrinsic(_InterlockedExchangePointer)
  6134. #pragma intrinsic(_InterlockedCompareExchangePointer)
  6135. #ifdef __cplusplus
  6136. }
  6137. #endif
  6138. #endif // defined(_M_AMD64) && !defined(RC_INVOKED) && !defined(MIDL_PASS)
  6139. #if defined(_AMD64_)
  6140. //
  6141. // Types to use to contain PFNs and their counts.
  6142. //
  6143. typedef ULONG PFN_COUNT;
  6144. typedef LONG64 SPFN_NUMBER, *PSPFN_NUMBER;
  6145. typedef ULONG64 PFN_NUMBER, *PPFN_NUMBER;
  6146. //
  6147. // Define maximum size of flush multiple TB request.
  6148. //
  6149. #define FLUSH_MULTIPLE_MAXIMUM 16
  6150. //
  6151. // Indicate that the AMD64 compiler supports the allocate pragmas.
  6152. //
  6153. #define ALLOC_PRAGMA 1
  6154. #define ALLOC_DATA_PRAGMA 1
  6155. #define NORMAL_DISPATCH_LENGTH 106
  6156. #define DISPATCH_LENGTH NORMAL_DISPATCH_LENGTH
  6157. //
  6158. // Interrupt Request Level definitions
  6159. //
  6160. #define PASSIVE_LEVEL 0 // Passive release level
  6161. #define LOW_LEVEL 0 // Lowest interrupt level
  6162. #define APC_LEVEL 1 // APC interrupt level
  6163. #define DISPATCH_LEVEL 2 // Dispatcher level
  6164. #define CLOCK_LEVEL 13 // Interval clock level
  6165. #define IPI_LEVEL 14 // Interprocessor interrupt level
  6166. #define POWER_LEVEL 14 // Power failure level
  6167. #define PROFILE_LEVEL 15 // timer used for profiling.
  6168. #define HIGH_LEVEL 15 // Highest interrupt level
  6169. #if defined(NT_UP)
  6170. #define SYNCH_LEVEL DISPATCH_LEVEL // synchronization level
  6171. #else
  6172. #define SYNCH_LEVEL (IPI_LEVEL - 1) // synchronization level
  6173. #endif
  6174. #define IRQL_VECTOR_OFFSET 2 // offset from IRQL to vector / 16
  6175. //
  6176. // I/O space read and write macros.
  6177. //
  6178. // The READ/WRITE_REGISTER_* calls manipulate I/O registers in MEMORY space.
  6179. // (Use move instructions, with LOCK prefix to force correct behavior
  6180. // w.r.t. caches and write buffers.)
  6181. //
  6182. // The READ/WRITE_PORT_* calls manipulate I/O registers in PORT space.
  6183. // (Use in/out instructions.)
  6184. //
  6185. __forceinline
  6186. UCHAR
  6187. READ_REGISTER_UCHAR (
  6188. volatile UCHAR *Register
  6189. )
  6190. {
  6191. return *Register;
  6192. }
  6193. __forceinline
  6194. USHORT
  6195. READ_REGISTER_USHORT (
  6196. volatile USHORT *Register
  6197. )
  6198. {
  6199. return *Register;
  6200. }
  6201. __forceinline
  6202. ULONG
  6203. READ_REGISTER_ULONG (
  6204. volatile ULONG *Register
  6205. )
  6206. {
  6207. return *Register;
  6208. }
  6209. __forceinline
  6210. VOID
  6211. READ_REGISTER_BUFFER_UCHAR (
  6212. PUCHAR Register,
  6213. PUCHAR Buffer,
  6214. ULONG Count
  6215. )
  6216. {
  6217. __movsb(Register, Buffer, Count);
  6218. return;
  6219. }
  6220. __forceinline
  6221. VOID
  6222. READ_REGISTER_BUFFER_USHORT (
  6223. PUSHORT Register,
  6224. PUSHORT Buffer,
  6225. ULONG Count
  6226. )
  6227. {
  6228. __movsw(Register, Buffer, Count);
  6229. return;
  6230. }
  6231. __forceinline
  6232. VOID
  6233. READ_REGISTER_BUFFER_ULONG (
  6234. PULONG Register,
  6235. PULONG Buffer,
  6236. ULONG Count
  6237. )
  6238. {
  6239. __movsd(Register, Buffer, Count);
  6240. return;
  6241. }
  6242. __forceinline
  6243. VOID
  6244. WRITE_REGISTER_UCHAR (
  6245. PUCHAR Register,
  6246. UCHAR Value
  6247. )
  6248. {
  6249. LONG Synch;
  6250. *Register = Value;
  6251. InterlockedOr(&Synch, 1);
  6252. return;
  6253. }
  6254. __forceinline
  6255. VOID
  6256. WRITE_REGISTER_USHORT (
  6257. PUSHORT Register,
  6258. USHORT Value
  6259. )
  6260. {
  6261. LONG Synch;
  6262. *Register = Value;
  6263. InterlockedOr(&Synch, 1);
  6264. return;
  6265. }
  6266. __forceinline
  6267. VOID
  6268. WRITE_REGISTER_ULONG (
  6269. PULONG Register,
  6270. ULONG Value
  6271. )
  6272. {
  6273. LONG Synch;
  6274. *Register = Value;
  6275. InterlockedOr(&Synch, 1);
  6276. return;
  6277. }
  6278. __forceinline
  6279. VOID
  6280. WRITE_REGISTER_BUFFER_UCHAR (
  6281. PUCHAR Register,
  6282. PUCHAR Buffer,
  6283. ULONG Count
  6284. )
  6285. {
  6286. LONG Synch;
  6287. __movsb(Register, Buffer, Count);
  6288. InterlockedOr(&Synch, 1);
  6289. return;
  6290. }
  6291. __forceinline
  6292. VOID
  6293. WRITE_REGISTER_BUFFER_USHORT (
  6294. PUSHORT Register,
  6295. PUSHORT Buffer,
  6296. ULONG Count
  6297. )
  6298. {
  6299. LONG Synch;
  6300. __movsw(Register, Buffer, Count);
  6301. InterlockedOr(&Synch, 1);
  6302. return;
  6303. }
  6304. __forceinline
  6305. VOID
  6306. WRITE_REGISTER_BUFFER_ULONG (
  6307. PULONG Register,
  6308. PULONG Buffer,
  6309. ULONG Count
  6310. )
  6311. {
  6312. LONG Synch;
  6313. __movsd(Register, Buffer, Count);
  6314. InterlockedOr(&Synch, 1);
  6315. return;
  6316. }
  6317. __forceinline
  6318. UCHAR
  6319. READ_PORT_UCHAR (
  6320. PUCHAR Port
  6321. )
  6322. {
  6323. return __inbyte((USHORT)((ULONG64)Port));
  6324. }
  6325. __forceinline
  6326. USHORT
  6327. READ_PORT_USHORT (
  6328. PUSHORT Port
  6329. )
  6330. {
  6331. return __inword((USHORT)((ULONG64)Port));
  6332. }
  6333. __forceinline
  6334. ULONG
  6335. READ_PORT_ULONG (
  6336. PULONG Port
  6337. )
  6338. {
  6339. return __indword((USHORT)((ULONG64)Port));
  6340. }
  6341. __forceinline
  6342. VOID
  6343. READ_PORT_BUFFER_UCHAR (
  6344. PUCHAR Port,
  6345. PUCHAR Buffer,
  6346. ULONG Count
  6347. )
  6348. {
  6349. __inbytestring((USHORT)((ULONG64)Port), Buffer, Count);
  6350. return;
  6351. }
  6352. __forceinline
  6353. VOID
  6354. READ_PORT_BUFFER_USHORT (
  6355. PUSHORT Port,
  6356. PUSHORT Buffer,
  6357. ULONG Count
  6358. )
  6359. {
  6360. __inwordstring((USHORT)((ULONG64)Port), Buffer, Count);
  6361. return;
  6362. }
  6363. __forceinline
  6364. VOID
  6365. READ_PORT_BUFFER_ULONG (
  6366. PULONG Port,
  6367. PULONG Buffer,
  6368. ULONG Count
  6369. )
  6370. {
  6371. __indwordstring((USHORT)((ULONG64)Port), Buffer, Count);
  6372. return;
  6373. }
  6374. __forceinline
  6375. VOID
  6376. WRITE_PORT_UCHAR (
  6377. PUCHAR Port,
  6378. UCHAR Value
  6379. )
  6380. {
  6381. __outbyte((USHORT)((ULONG64)Port), Value);
  6382. return;
  6383. }
  6384. __forceinline
  6385. VOID
  6386. WRITE_PORT_USHORT (
  6387. PUSHORT Port,
  6388. USHORT Value
  6389. )
  6390. {
  6391. __outword((USHORT)((ULONG64)Port), Value);
  6392. return;
  6393. }
  6394. __forceinline
  6395. VOID
  6396. WRITE_PORT_ULONG (
  6397. PULONG Port,
  6398. ULONG Value
  6399. )
  6400. {
  6401. __outdword((USHORT)((ULONG64)Port), Value);
  6402. return;
  6403. }
  6404. __forceinline
  6405. VOID
  6406. WRITE_PORT_BUFFER_UCHAR (
  6407. PUCHAR Port,
  6408. PUCHAR Buffer,
  6409. ULONG Count
  6410. )
  6411. {
  6412. __outbytestring((USHORT)((ULONG64)Port), Buffer, Count);
  6413. return;
  6414. }
  6415. __forceinline
  6416. VOID
  6417. WRITE_PORT_BUFFER_USHORT (
  6418. PUSHORT Port,
  6419. PUSHORT Buffer,
  6420. ULONG Count
  6421. )
  6422. {
  6423. __outwordstring((USHORT)((ULONG64)Port), Buffer, Count);
  6424. return;
  6425. }
  6426. __forceinline
  6427. VOID
  6428. WRITE_PORT_BUFFER_ULONG (
  6429. PULONG Port,
  6430. PULONG Buffer,
  6431. ULONG Count
  6432. )
  6433. {
  6434. __outdwordstring((USHORT)((ULONG64)Port), Buffer, Count);
  6435. return;
  6436. }
  6437. // end_ntndis
  6438. //
  6439. // Get data cache fill size.
  6440. //
  6441. #if PRAGMA_DEPRECATED_DDK
  6442. #pragma deprecated(KeGetDcacheFillSize) // Use GetDmaAlignment
  6443. #endif
  6444. #define KeGetDcacheFillSize() 1L
  6445. #define KeFlushIoBuffers(Mdl, ReadOperation, DmaOperation)
  6446. #define ExAcquireSpinLock(Lock, OldIrql) KeAcquireSpinLock((Lock), (OldIrql))
  6447. #define ExReleaseSpinLock(Lock, OldIrql) KeReleaseSpinLock((Lock), (OldIrql))
  6448. #define ExAcquireSpinLockAtDpcLevel(Lock) KeAcquireSpinLockAtDpcLevel(Lock)
  6449. #define ExReleaseSpinLockFromDpcLevel(Lock) KeReleaseSpinLockFromDpcLevel(Lock)
  6450. #if defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_)
  6451. // begin_wdm
  6452. #define KeQueryTickCount(CurrentCount ) \
  6453. *(PULONG64)(CurrentCount) = **((volatile ULONG64 **)(&KeTickCount));
  6454. // end_wdm
  6455. #else
  6456. VOID
  6457. KeQueryTickCount (
  6458. OUT PLARGE_INTEGER CurrentCount
  6459. );
  6460. #endif // defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_)
  6461. //
  6462. // Processor Control Region Structure Definition
  6463. //
  6464. #define PCR_MINOR_VERSION 1
  6465. #define PCR_MAJOR_VERSION 1
  6466. typedef struct _KPCR {
  6467. //
  6468. // Start of the architecturally defined section of the PCR. This section
  6469. // may be directly addressed by vendor/platform specific HAL code and will
  6470. // not change from version to version of NT.
  6471. //
  6472. NT_TIB NtTib;
  6473. struct _KPRCB *CurrentPrcb;
  6474. ULONG64 SavedRcx;
  6475. ULONG64 SavedR11;
  6476. KIRQL Irql;
  6477. UCHAR SecondLevelCacheAssociativity;
  6478. UCHAR Number;
  6479. UCHAR Fill0;
  6480. ULONG Irr;
  6481. ULONG IrrActive;
  6482. ULONG Idr;
  6483. USHORT MajorVersion;
  6484. USHORT MinorVersion;
  6485. ULONG StallScaleFactor;
  6486. union _KIDTENTRY64 *IdtBase;
  6487. union _KGDTENTRY64 *GdtBase;
  6488. struct _KTSS64 *TssBase;
  6489. } KPCR, *PKPCR;
  6490. //
  6491. // The nonvolatile floating state
  6492. //
  6493. typedef struct _KFLOATING_SAVE {
  6494. ULONG MxCsr;
  6495. } KFLOATING_SAVE, *PKFLOATING_SAVE;
  6496. //
  6497. // AMD64 Specific portions of mm component.
  6498. //
  6499. // Define the page size for the AMD64 as 4096 (0x1000).
  6500. //
  6501. #define PAGE_SIZE 0x1000
  6502. //
  6503. // Define the number of trailing zeroes in a page aligned virtual address.
  6504. // This is used as the shift count when shifting virtual addresses to
  6505. // virtual page numbers.
  6506. //
  6507. #define PAGE_SHIFT 12L
  6508. // end_ntndis end_wdm
  6509. #define PXE_BASE 0xFFFFF6FB7DBED000UI64
  6510. #define PXE_SELFMAP 0xFFFFF6FB7DBEDF68UI64
  6511. #define PPE_BASE 0xFFFFF6FB7DA00000UI64
  6512. #define PDE_BASE 0xFFFFF6FB40000000UI64
  6513. #define PTE_BASE 0xFFFFF68000000000UI64
  6514. #define PXE_TOP 0xFFFFF6FB7DBEDFFFUI64
  6515. #define PPE_TOP 0xFFFFF6FB7DBFFFFFUI64
  6516. #define PDE_TOP 0xFFFFF6FB7FFFFFFFUI64
  6517. #define PTE_TOP 0xFFFFF6FFFFFFFFFFUI64
  6518. #define PDE_KTBASE_AMD64 PPE_BASE
  6519. #define PTI_SHIFT 12
  6520. #define PDI_SHIFT 21
  6521. #define PPI_SHIFT 30
  6522. #define PXI_SHIFT 39
  6523. #define PTE_PER_PAGE 512
  6524. #define PDE_PER_PAGE 512
  6525. #define PPE_PER_PAGE 512
  6526. #define PXE_PER_PAGE 512
  6527. #define PTI_MASK_AMD64 (PTE_PER_PAGE - 1)
  6528. #define PDI_MASK_AMD64 (PDE_PER_PAGE - 1)
  6529. #define PPI_MASK (PPE_PER_PAGE - 1)
  6530. #define PXI_MASK (PXE_PER_PAGE - 1)
  6531. //
  6532. // Define the highest user address and user probe address.
  6533. //
  6534. extern PVOID *MmHighestUserAddress;
  6535. extern PVOID *MmSystemRangeStart;
  6536. extern ULONG64 *MmUserProbeAddress;
  6537. #define MM_HIGHEST_USER_ADDRESS *MmHighestUserAddress
  6538. #define MM_SYSTEM_RANGE_START *MmSystemRangeStart
  6539. #define MM_USER_PROBE_ADDRESS *MmUserProbeAddress
  6540. //
  6541. // The lowest user address reserves the low 64k.
  6542. //
  6543. #define MM_LOWEST_USER_ADDRESS (PVOID)0x10000
  6544. //
  6545. // The lowest address for system space.
  6546. //
  6547. #define MM_LOWEST_SYSTEM_ADDRESS (PVOID)0xFFFF080000000000
  6548. // begin_wdm
  6549. #define MmGetProcedureAddress(Address) (Address)
  6550. #define MmLockPagableCodeSection(Address) MmLockPagableDataSection(Address)
  6551. #define KI_USER_SHARED_DATA 0xFFFFF78000000000UI64
  6552. #define SharedUserData ((KUSER_SHARED_DATA * const) KI_USER_SHARED_DATA)
  6553. //
  6554. // Intrinsic functions
  6555. //
  6556. // begin_wdm
  6557. #if defined(_M_AMD64) && !defined(RC_INVOKED) && !defined(MIDL_PASS)
  6558. // end_wdm
  6559. //
  6560. // The following routines are provided for backward compatibility with old
  6561. // code. They are no longer the preferred way to accomplish these functions.
  6562. //
  6563. #if PRAGMA_DEPRECATED_DDK
  6564. #pragma deprecated(ExInterlockedIncrementLong) // Use InterlockedIncrement
  6565. #pragma deprecated(ExInterlockedDecrementLong) // Use InterlockedDecrement
  6566. #pragma deprecated(ExInterlockedExchangeUlong) // Use InterlockedExchange
  6567. #endif
  6568. #define RESULT_ZERO 0
  6569. #define RESULT_NEGATIVE 1
  6570. #define RESULT_POSITIVE 2
  6571. typedef enum _INTERLOCKED_RESULT {
  6572. ResultNegative = RESULT_NEGATIVE,
  6573. ResultZero = RESULT_ZERO,
  6574. ResultPositive = RESULT_POSITIVE
  6575. } INTERLOCKED_RESULT;
  6576. #define ExInterlockedDecrementLong(Addend, Lock) \
  6577. _ExInterlockedDecrementLong(Addend)
  6578. __forceinline
  6579. LONG
  6580. _ExInterlockedDecrementLong (
  6581. IN OUT PLONG Addend
  6582. )
  6583. {
  6584. LONG Result;
  6585. Result = InterlockedDecrement(Addend);
  6586. if (Result < 0) {
  6587. return ResultNegative;
  6588. } else if (Result > 0) {
  6589. return ResultPositive;
  6590. } else {
  6591. return ResultZero;
  6592. }
  6593. }
  6594. #define ExInterlockedIncrementLong(Addend, Lock) \
  6595. _ExInterlockedIncrementLong(Addend)
  6596. __forceinline
  6597. LONG
  6598. _ExInterlockedIncrementLong (
  6599. IN OUT PLONG Addend
  6600. )
  6601. {
  6602. LONG Result;
  6603. Result = InterlockedIncrement(Addend);
  6604. if (Result < 0) {
  6605. return ResultNegative;
  6606. } else if (Result > 0) {
  6607. return ResultPositive;
  6608. } else {
  6609. return ResultZero;
  6610. }
  6611. }
  6612. #define ExInterlockedExchangeUlong(Target, Value, Lock) \
  6613. _ExInterlockedExchangeUlong(Target, Value)
  6614. __forceinline
  6615. _ExInterlockedExchangeUlong (
  6616. IN OUT PULONG Target,
  6617. IN ULONG Value
  6618. )
  6619. {
  6620. return (ULONG)InterlockedExchange((PLONG)Target, (LONG)Value);
  6621. }
  6622. // begin_wdm
  6623. #endif // defined(_M_AMD64) && !defined(RC_INVOKED) && !defined(MIDL_PASS)
  6624. #if !defined(MIDL_PASS) && defined(_M_AMD64)
  6625. //
  6626. // AMD646 function prototype definitions
  6627. //
  6628. // end_wdm
  6629. //
  6630. // Get the current processor number
  6631. //
  6632. __forceinline
  6633. ULONG
  6634. KeGetCurrentProcessorNumber (
  6635. VOID
  6636. )
  6637. {
  6638. return (ULONG)__readgsbyte(FIELD_OFFSET(KPCR, Number));
  6639. }
  6640. // begin_wdm
  6641. #endif // !defined(MIDL_PASS) && defined(_M_AMD64)
  6642. NTKERNELAPI
  6643. NTSTATUS
  6644. KeSaveFloatingPointState (
  6645. OUT PKFLOATING_SAVE SaveArea
  6646. );
  6647. NTKERNELAPI
  6648. NTSTATUS
  6649. KeRestoreFloatingPointState (
  6650. IN PKFLOATING_SAVE SaveArea
  6651. );
  6652. #endif // defined(_AMD64_)
  6653. #if defined(_AMD64_)
  6654. NTKERNELAPI
  6655. KIRQL
  6656. KeGetCurrentIrql (
  6657. VOID
  6658. );
  6659. NTKERNELAPI
  6660. VOID
  6661. KeLowerIrql (
  6662. IN KIRQL NewIrql
  6663. );
  6664. #define KeRaiseIrql(a,b) *(b) = KfRaiseIrql(a)
  6665. NTKERNELAPI
  6666. KIRQL
  6667. KfRaiseIrql (
  6668. IN KIRQL NewIrql
  6669. );
  6670. // end_wdm
  6671. NTKERNELAPI
  6672. KIRQL
  6673. KeRaiseIrqlToDpcLevel (
  6674. VOID
  6675. );
  6676. NTKERNELAPI
  6677. KIRQL
  6678. KeRaiseIrqlToSynchLevel (
  6679. VOID
  6680. );
  6681. // begin_wdm
  6682. #endif // defined(_AMD64_)
  6683. #if defined(_IA64_)
  6684. //
  6685. // Types to use to contain PFNs and their counts.
  6686. //
  6687. typedef ULONG PFN_COUNT;
  6688. typedef LONG_PTR SPFN_NUMBER, *PSPFN_NUMBER;
  6689. typedef ULONG_PTR PFN_NUMBER, *PPFN_NUMBER;
  6690. //
  6691. // Define maximum size of flush multiple TB request.
  6692. //
  6693. #define FLUSH_MULTIPLE_MAXIMUM 100
  6694. //
  6695. // Indicate that the IA64 compiler supports the pragma textout construct.
  6696. //
  6697. #define ALLOC_PRAGMA 1
  6698. //
  6699. // Define intrinsic calls and their prototypes
  6700. //
  6701. #include "ia64reg.h"
  6702. #ifdef __cplusplus
  6703. extern "C" {
  6704. #endif
  6705. unsigned __int64 __getReg (int);
  6706. void __setReg (int, unsigned __int64);
  6707. void __isrlz (void);
  6708. void __dsrlz (void);
  6709. void __fwb (void);
  6710. void __mf (void);
  6711. void __mfa (void);
  6712. void __synci (void);
  6713. __int64 __thash (__int64);
  6714. __int64 __ttag (__int64);
  6715. void __ptcl (__int64, __int64);
  6716. void __ptcg (__int64, __int64);
  6717. void __ptcga (__int64, __int64);
  6718. void __ptri (__int64, __int64);
  6719. void __ptrd (__int64, __int64);
  6720. void __invalat (void);
  6721. void __break (int);
  6722. void __fc (__int64);
  6723. void __sum (int);
  6724. void __rsm (int);
  6725. void _ReleaseSpinLock( unsigned __int64 *);
  6726. #ifdef _M_IA64
  6727. #pragma intrinsic (__getReg)
  6728. #pragma intrinsic (__setReg)
  6729. #pragma intrinsic (__isrlz)
  6730. #pragma intrinsic (__dsrlz)
  6731. #pragma intrinsic (__fwb)
  6732. #pragma intrinsic (__mf)
  6733. #pragma intrinsic (__mfa)
  6734. #pragma intrinsic (__synci)
  6735. #pragma intrinsic (__thash)
  6736. #pragma intrinsic (__ttag)
  6737. #pragma intrinsic (__ptcl)
  6738. #pragma intrinsic (__ptcg)
  6739. #pragma intrinsic (__ptcga)
  6740. #pragma intrinsic (__ptri)
  6741. #pragma intrinsic (__ptrd)
  6742. #pragma intrinsic (__invalat)
  6743. #pragma intrinsic (__break)
  6744. #pragma intrinsic (__fc)
  6745. #pragma intrinsic (__sum)
  6746. #pragma intrinsic (__rsm)
  6747. #pragma intrinsic (_ReleaseSpinLock)
  6748. #endif // _M_IA64
  6749. #ifdef __cplusplus
  6750. }
  6751. #endif
  6752. // end_wdm end_ntndis
  6753. //
  6754. // Define macro to generate import names.
  6755. //
  6756. #define IMPORT_NAME(name) __imp_##name
  6757. // begin_wdm
  6758. //
  6759. // Define length of interrupt vector table.
  6760. //
  6761. #define MAXIMUM_VECTOR 256
  6762. // end_wdm
  6763. //
  6764. // IA64 specific interlocked operation result values.
  6765. //
  6766. #define RESULT_ZERO 0
  6767. #define RESULT_NEGATIVE 1
  6768. #define RESULT_POSITIVE 2
  6769. //
  6770. // Interlocked result type is portable, but its values are machine specific.
  6771. // Constants for values are in i386.h, mips.h, etc.
  6772. //
  6773. typedef enum _INTERLOCKED_RESULT {
  6774. ResultNegative = RESULT_NEGATIVE,
  6775. ResultZero = RESULT_ZERO,
  6776. ResultPositive = RESULT_POSITIVE
  6777. } INTERLOCKED_RESULT;
  6778. //
  6779. // Convert portable interlock interfaces to architecture specific interfaces.
  6780. //
  6781. #if PRAGMA_DEPRECATED_DDK
  6782. #pragma deprecated(ExInterlockedIncrementLong) // Use InterlockedIncrement
  6783. #pragma deprecated(ExInterlockedDecrementLong) // Use InterlockedDecrement
  6784. #pragma deprecated(ExInterlockedExchangeUlong) // Use InterlockedExchange
  6785. #endif
  6786. #define ExInterlockedIncrementLong(Addend, Lock) \
  6787. ExIa64InterlockedIncrementLong(Addend)
  6788. #define ExInterlockedDecrementLong(Addend, Lock) \
  6789. ExIa64InterlockedDecrementLong(Addend)
  6790. #define ExInterlockedExchangeUlong(Target, Value, Lock) \
  6791. ExIa64InterlockedExchangeUlong(Target, Value)
  6792. NTKERNELAPI
  6793. INTERLOCKED_RESULT
  6794. ExIa64InterlockedIncrementLong (
  6795. IN PLONG Addend
  6796. );
  6797. NTKERNELAPI
  6798. INTERLOCKED_RESULT
  6799. ExIa64InterlockedDecrementLong (
  6800. IN PLONG Addend
  6801. );
  6802. NTKERNELAPI
  6803. ULONG
  6804. ExIa64InterlockedExchangeUlong (
  6805. IN PULONG Target,
  6806. IN ULONG Value
  6807. );
  6808. // begin_wdm
  6809. //
  6810. // IA64 Interrupt Definitions.
  6811. //
  6812. // Define length of interrupt object dispatch code in longwords.
  6813. //
  6814. #define DISPATCH_LENGTH 2*2 // Length of dispatch code template in 32-bit words
  6815. //
  6816. // Begin of a block of definitions that must be synchronized with kxia64.h.
  6817. //
  6818. //
  6819. // Define Interrupt Request Levels.
  6820. //
  6821. #define PASSIVE_LEVEL 0 // Passive release level
  6822. #define LOW_LEVEL 0 // Lowest interrupt level
  6823. #define APC_LEVEL 1 // APC interrupt level
  6824. #define DISPATCH_LEVEL 2 // Dispatcher level
  6825. #define CMC_LEVEL 3 // Correctable machine check level
  6826. #define DEVICE_LEVEL_BASE 4 // 4 - 11 - Device IRQLs
  6827. #define PC_LEVEL 12 // Performance Counter IRQL
  6828. #define IPI_LEVEL 14 // IPI IRQL
  6829. #define CLOCK_LEVEL 13 // Clock Timer IRQL
  6830. #define POWER_LEVEL 15 // Power failure level
  6831. #define PROFILE_LEVEL 15 // Profiling level
  6832. #define HIGH_LEVEL 15 // Highest interrupt level
  6833. #if defined(NT_UP)
  6834. #define SYNCH_LEVEL DISPATCH_LEVEL // Synchronization level - UP
  6835. #else
  6836. #define SYNCH_LEVEL (IPI_LEVEL-1) // Synchronization level - MP
  6837. #endif
  6838. //
  6839. // The current IRQL is maintained in the TPR.mic field. The
  6840. // shift count is the number of bits to shift right to extract the
  6841. // IRQL from the TPR. See the GET/SET_IRQL macros.
  6842. //
  6843. #define TPR_MIC 4
  6844. #define TPR_IRQL_SHIFT TPR_MIC
  6845. // To go from vector number <-> IRQL we just do a shift
  6846. #define VECTOR_IRQL_SHIFT TPR_IRQL_SHIFT
  6847. //
  6848. // Interrupt Vector Definitions
  6849. //
  6850. #define APC_VECTOR APC_LEVEL << VECTOR_IRQL_SHIFT
  6851. #define DISPATCH_VECTOR DISPATCH_LEVEL << VECTOR_IRQL_SHIFT
  6852. //
  6853. // End of a block of definitions that must be synchronized with kxia64.h.
  6854. //
  6855. //
  6856. // Define profile intervals.
  6857. //
  6858. #define DEFAULT_PROFILE_COUNT 0x40000000 // ~= 20 seconds @50mhz
  6859. #define DEFAULT_PROFILE_INTERVAL (10 * 500) // 500 microseconds
  6860. #define MAXIMUM_PROFILE_INTERVAL (10 * 1000 * 1000) // 1 second
  6861. #define MINIMUM_PROFILE_INTERVAL (10 * 40) // 40 microseconds
  6862. #if defined(_M_IA64) && !defined(RC_INVOKED)
  6863. #define InterlockedAdd _InterlockedAdd
  6864. #define InterlockedIncrement _InterlockedIncrement
  6865. #define InterlockedDecrement _InterlockedDecrement
  6866. #define InterlockedExchange _InterlockedExchange
  6867. #define InterlockedExchangeAdd _InterlockedExchangeAdd
  6868. #define InterlockedAdd64 _InterlockedAdd64
  6869. #define InterlockedIncrement64 _InterlockedIncrement64
  6870. #define InterlockedDecrement64 _InterlockedDecrement64
  6871. #define InterlockedExchange64 _InterlockedExchange64
  6872. #define InterlockedExchangeAdd64 _InterlockedExchangeAdd64
  6873. #define InterlockedCompareExchange64 _InterlockedCompareExchange64
  6874. #define InterlockedCompareExchange _InterlockedCompareExchange
  6875. #define InterlockedExchangePointer _InterlockedExchangePointer
  6876. #define InterlockedCompareExchangePointer _InterlockedCompareExchangePointer
  6877. #ifdef __cplusplus
  6878. extern "C" {
  6879. #endif
  6880. LONG
  6881. __cdecl
  6882. InterlockedAdd (
  6883. LONG volatile *Addend,
  6884. LONG Value
  6885. );
  6886. LONGLONG
  6887. __cdecl
  6888. InterlockedAdd64 (
  6889. LONGLONG volatile *Addend,
  6890. LONGLONG Value
  6891. );
  6892. LONG
  6893. __cdecl
  6894. InterlockedIncrement(
  6895. IN OUT LONG volatile *Addend
  6896. );
  6897. LONG
  6898. __cdecl
  6899. InterlockedDecrement(
  6900. IN OUT LONG volatile *Addend
  6901. );
  6902. LONG
  6903. __cdecl
  6904. InterlockedExchange(
  6905. IN OUT LONG volatile *Target,
  6906. IN LONG Value
  6907. );
  6908. LONG
  6909. __cdecl
  6910. InterlockedExchangeAdd(
  6911. IN OUT LONG volatile *Addend,
  6912. IN LONG Value
  6913. );
  6914. LONG
  6915. __cdecl
  6916. InterlockedCompareExchange (
  6917. IN OUT LONG volatile *Destination,
  6918. IN LONG ExChange,
  6919. IN LONG Comperand
  6920. );
  6921. LONGLONG
  6922. __cdecl
  6923. InterlockedIncrement64(
  6924. IN OUT LONGLONG volatile *Addend
  6925. );
  6926. LONGLONG
  6927. __cdecl
  6928. InterlockedDecrement64(
  6929. IN OUT LONGLONG volatile *Addend
  6930. );
  6931. LONGLONG
  6932. __cdecl
  6933. InterlockedExchange64(
  6934. IN OUT LONGLONG volatile *Target,
  6935. IN LONGLONG Value
  6936. );
  6937. LONGLONG
  6938. __cdecl
  6939. InterlockedExchangeAdd64(
  6940. IN OUT LONGLONG volatile *Addend,
  6941. IN LONGLONG Value
  6942. );
  6943. LONGLONG
  6944. __cdecl
  6945. InterlockedCompareExchange64 (
  6946. IN OUT LONGLONG volatile *Destination,
  6947. IN LONGLONG ExChange,
  6948. IN LONGLONG Comperand
  6949. );
  6950. PVOID
  6951. __cdecl
  6952. InterlockedCompareExchangePointer (
  6953. IN OUT PVOID volatile *Destination,
  6954. IN PVOID Exchange,
  6955. IN PVOID Comperand
  6956. );
  6957. PVOID
  6958. __cdecl
  6959. InterlockedExchangePointer(
  6960. IN OUT PVOID volatile *Target,
  6961. IN PVOID Value
  6962. );
  6963. #pragma intrinsic(_InterlockedAdd)
  6964. #pragma intrinsic(_InterlockedIncrement)
  6965. #pragma intrinsic(_InterlockedDecrement)
  6966. #pragma intrinsic(_InterlockedExchange)
  6967. #pragma intrinsic(_InterlockedCompareExchange)
  6968. #pragma intrinsic(_InterlockedExchangeAdd)
  6969. #pragma intrinsic(_InterlockedAdd64)
  6970. #pragma intrinsic(_InterlockedIncrement64)
  6971. #pragma intrinsic(_InterlockedDecrement64)
  6972. #pragma intrinsic(_InterlockedExchange64)
  6973. #pragma intrinsic(_InterlockedCompareExchange64)
  6974. #pragma intrinsic(_InterlockedExchangeAdd64)
  6975. #pragma intrinsic(_InterlockedExchangePointer)
  6976. #pragma intrinsic(_InterlockedCompareExchangePointer)
  6977. #ifdef __cplusplus
  6978. }
  6979. #endif
  6980. #endif // defined(_M_IA64) && !defined(RC_INVOKED)
  6981. __inline
  6982. LONG
  6983. InterlockedAnd (
  6984. IN OUT LONG volatile *Target,
  6985. LONG Set
  6986. )
  6987. {
  6988. LONG i;
  6989. LONG j;
  6990. j = *Target;
  6991. do {
  6992. i = j;
  6993. j = InterlockedCompareExchange(Target,
  6994. i & Set,
  6995. i);
  6996. } while (i != j);
  6997. return j;
  6998. }
  6999. __inline
  7000. LONG
  7001. InterlockedOr (
  7002. IN OUT LONG volatile *Target,
  7003. IN LONG Set
  7004. )
  7005. {
  7006. LONG i;
  7007. LONG j;
  7008. j = *Target;
  7009. do {
  7010. i = j;
  7011. j = InterlockedCompareExchange(Target,
  7012. i | Set,
  7013. i);
  7014. } while (i != j);
  7015. return j;
  7016. }
  7017. #define KI_USER_SHARED_DATA ((ULONG_PTR)(KADDRESS_BASE + 0xFFFE0000))
  7018. #define SharedUserData ((KUSER_SHARED_DATA * const)KI_USER_SHARED_DATA)
  7019. //
  7020. // Prototype for get current IRQL. **** TBD (read TPR)
  7021. //
  7022. NTKERNELAPI
  7023. KIRQL
  7024. KeGetCurrentIrql();
  7025. // end_wdm
  7026. //
  7027. // Get address of current processor block.
  7028. //
  7029. #define KeGetCurrentPrcb() PCR->Prcb
  7030. //
  7031. // Get address of processor control region.
  7032. //
  7033. #define KeGetPcr() PCR
  7034. //
  7035. // Get address of current kernel thread object.
  7036. //
  7037. #if defined(_M_IA64)
  7038. #define KeGetCurrentThread() PCR->CurrentThread
  7039. #endif
  7040. //
  7041. // Get current processor number.
  7042. //
  7043. #define KeGetCurrentProcessorNumber() PCR->Number
  7044. //
  7045. // Get data cache fill size.
  7046. //
  7047. #if PRAGMA_DEPRECATED_DDK
  7048. #pragma deprecated(KeGetDcacheFillSize) // Use GetDmaAlignment
  7049. #endif
  7050. #define KeGetDcacheFillSize() PCR->DcacheFillSize
  7051. #define KeSaveFloatingPointState(a) STATUS_SUCCESS
  7052. #define KeRestoreFloatingPointState(a) STATUS_SUCCESS
  7053. //
  7054. // Define the page size
  7055. //
  7056. #define PAGE_SIZE 0x2000
  7057. //
  7058. // Define the number of trailing zeroes in a page aligned virtual address.
  7059. // This is used as the shift count when shifting virtual addresses to
  7060. // virtual page numbers.
  7061. //
  7062. #define PAGE_SHIFT 13L
  7063. //
  7064. // Cache and write buffer flush functions.
  7065. //
  7066. NTKERNELAPI
  7067. VOID
  7068. KeFlushIoBuffers (
  7069. IN PMDL Mdl,
  7070. IN BOOLEAN ReadOperation,
  7071. IN BOOLEAN DmaOperation
  7072. );
  7073. //
  7074. // Kernel breakin breakpoint
  7075. //
  7076. VOID
  7077. KeBreakinBreakpoint (
  7078. VOID
  7079. );
  7080. #define ExAcquireSpinLock(Lock, OldIrql) KeAcquireSpinLock((Lock), (OldIrql))
  7081. #define ExReleaseSpinLock(Lock, OldIrql) KeReleaseSpinLock((Lock), (OldIrql))
  7082. #define ExAcquireSpinLockAtDpcLevel(Lock) KeAcquireSpinLockAtDpcLevel(Lock)
  7083. #define ExReleaseSpinLockFromDpcLevel(Lock) KeReleaseSpinLockFromDpcLevel(Lock)
  7084. #if defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_)
  7085. // begin_wdm
  7086. #define KeQueryTickCount(CurrentCount ) \
  7087. *(PULONGLONG)(CurrentCount) = **((volatile ULONGLONG **)(&KeTickCount));
  7088. // end_wdm
  7089. #else
  7090. NTKERNELAPI
  7091. VOID
  7092. KeQueryTickCount (
  7093. OUT PLARGE_INTEGER CurrentCount
  7094. );
  7095. #endif // defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_)
  7096. //
  7097. // I/O space read and write macros.
  7098. //
  7099. NTHALAPI
  7100. UCHAR
  7101. READ_PORT_UCHAR (
  7102. PUCHAR RegisterAddress
  7103. );
  7104. NTHALAPI
  7105. USHORT
  7106. READ_PORT_USHORT (
  7107. PUSHORT RegisterAddress
  7108. );
  7109. NTHALAPI
  7110. ULONG
  7111. READ_PORT_ULONG (
  7112. PULONG RegisterAddress
  7113. );
  7114. NTHALAPI
  7115. VOID
  7116. READ_PORT_BUFFER_UCHAR (
  7117. PUCHAR portAddress,
  7118. PUCHAR readBuffer,
  7119. ULONG readCount
  7120. );
  7121. NTHALAPI
  7122. VOID
  7123. READ_PORT_BUFFER_USHORT (
  7124. PUSHORT portAddress,
  7125. PUSHORT readBuffer,
  7126. ULONG readCount
  7127. );
  7128. NTHALAPI
  7129. VOID
  7130. READ_PORT_BUFFER_ULONG (
  7131. PULONG portAddress,
  7132. PULONG readBuffer,
  7133. ULONG readCount
  7134. );
  7135. NTHALAPI
  7136. VOID
  7137. WRITE_PORT_UCHAR (
  7138. PUCHAR portAddress,
  7139. UCHAR Data
  7140. );
  7141. NTHALAPI
  7142. VOID
  7143. WRITE_PORT_USHORT (
  7144. PUSHORT portAddress,
  7145. USHORT Data
  7146. );
  7147. NTHALAPI
  7148. VOID
  7149. WRITE_PORT_ULONG (
  7150. PULONG portAddress,
  7151. ULONG Data
  7152. );
  7153. NTHALAPI
  7154. VOID
  7155. WRITE_PORT_BUFFER_UCHAR (
  7156. PUCHAR portAddress,
  7157. PUCHAR writeBuffer,
  7158. ULONG writeCount
  7159. );
  7160. NTHALAPI
  7161. VOID
  7162. WRITE_PORT_BUFFER_USHORT (
  7163. PUSHORT portAddress,
  7164. PUSHORT writeBuffer,
  7165. ULONG writeCount
  7166. );
  7167. NTHALAPI
  7168. VOID
  7169. WRITE_PORT_BUFFER_ULONG (
  7170. PULONG portAddress,
  7171. PULONG writeBuffer,
  7172. ULONG writeCount
  7173. );
  7174. #define READ_REGISTER_UCHAR(x) \
  7175. (__mf(), *(volatile UCHAR * const)(x))
  7176. #define READ_REGISTER_USHORT(x) \
  7177. (__mf(), *(volatile USHORT * const)(x))
  7178. #define READ_REGISTER_ULONG(x) \
  7179. (__mf(), *(volatile ULONG * const)(x))
  7180. #define READ_REGISTER_BUFFER_UCHAR(x, y, z) { \
  7181. PUCHAR registerBuffer = x; \
  7182. PUCHAR readBuffer = y; \
  7183. ULONG readCount; \
  7184. __mf(); \
  7185. for (readCount = z; readCount--; readBuffer++, registerBuffer++) { \
  7186. *readBuffer = *(volatile UCHAR * const)(registerBuffer); \
  7187. } \
  7188. }
  7189. #define READ_REGISTER_BUFFER_USHORT(x, y, z) { \
  7190. PUSHORT registerBuffer = x; \
  7191. PUSHORT readBuffer = y; \
  7192. ULONG readCount; \
  7193. __mf(); \
  7194. for (readCount = z; readCount--; readBuffer++, registerBuffer++) { \
  7195. *readBuffer = *(volatile USHORT * const)(registerBuffer); \
  7196. } \
  7197. }
  7198. #define READ_REGISTER_BUFFER_ULONG(x, y, z) { \
  7199. PULONG registerBuffer = x; \
  7200. PULONG readBuffer = y; \
  7201. ULONG readCount; \
  7202. __mf(); \
  7203. for (readCount = z; readCount--; readBuffer++, registerBuffer++) { \
  7204. *readBuffer = *(volatile ULONG * const)(registerBuffer); \
  7205. } \
  7206. }
  7207. #define WRITE_REGISTER_UCHAR(x, y) { \
  7208. *(volatile UCHAR * const)(x) = y; \
  7209. KeFlushWriteBuffer(); \
  7210. }
  7211. #define WRITE_REGISTER_USHORT(x, y) { \
  7212. *(volatile USHORT * const)(x) = y; \
  7213. KeFlushWriteBuffer(); \
  7214. }
  7215. #define WRITE_REGISTER_ULONG(x, y) { \
  7216. *(volatile ULONG * const)(x) = y; \
  7217. KeFlushWriteBuffer(); \
  7218. }
  7219. #define WRITE_REGISTER_BUFFER_UCHAR(x, y, z) { \
  7220. PUCHAR registerBuffer = x; \
  7221. PUCHAR writeBuffer = y; \
  7222. ULONG writeCount; \
  7223. for (writeCount = z; writeCount--; writeBuffer++, registerBuffer++) { \
  7224. *(volatile UCHAR * const)(registerBuffer) = *writeBuffer; \
  7225. } \
  7226. KeFlushWriteBuffer(); \
  7227. }
  7228. #define WRITE_REGISTER_BUFFER_USHORT(x, y, z) { \
  7229. PUSHORT registerBuffer = x; \
  7230. PUSHORT writeBuffer = y; \
  7231. ULONG writeCount; \
  7232. for (writeCount = z; writeCount--; writeBuffer++, registerBuffer++) { \
  7233. *(volatile USHORT * const)(registerBuffer) = *writeBuffer; \
  7234. } \
  7235. KeFlushWriteBuffer(); \
  7236. }
  7237. #define WRITE_REGISTER_BUFFER_ULONG(x, y, z) { \
  7238. PULONG registerBuffer = x; \
  7239. PULONG writeBuffer = y; \
  7240. ULONG writeCount; \
  7241. for (writeCount = z; writeCount--; writeBuffer++, registerBuffer++) { \
  7242. *(volatile ULONG * const)(registerBuffer) = *writeBuffer; \
  7243. } \
  7244. KeFlushWriteBuffer(); \
  7245. }
  7246. //
  7247. // Non-volatile floating point state
  7248. //
  7249. typedef struct _KFLOATING_SAVE {
  7250. ULONG Reserved;
  7251. } KFLOATING_SAVE, *PKFLOATING_SAVE;
  7252. //
  7253. // Processor Control Block (PRCB)
  7254. //
  7255. #define PRCB_MINOR_VERSION 1
  7256. #define PRCB_MAJOR_VERSION 1
  7257. #define PRCB_BUILD_DEBUG 0x0001
  7258. #define PRCB_BUILD_UNIPROCESSOR 0x0002
  7259. struct _RESTART_BLOCK;
  7260. typedef struct _KPRCB {
  7261. //
  7262. // Major and minor version numbers of the PCR.
  7263. //
  7264. USHORT MinorVersion;
  7265. USHORT MajorVersion;
  7266. //
  7267. // Start of the architecturally defined section of the PRCB. This section
  7268. // may be directly addressed by vendor/platform specific HAL code and will
  7269. // not change from version to version of NT.
  7270. //
  7271. //
  7272. struct _KTHREAD *CurrentThread;
  7273. struct _KTHREAD *RESTRICTED_POINTER NextThread;
  7274. struct _KTHREAD *IdleThread;
  7275. CCHAR Number;
  7276. CCHAR WakeIdle;
  7277. USHORT BuildType;
  7278. KAFFINITY SetMember;
  7279. struct _RESTART_BLOCK *RestartBlock;
  7280. ULONG_PTR PcrPage;
  7281. ULONG Spare0[4];
  7282. //
  7283. // Processor Idendification Registers.
  7284. //
  7285. ULONG ProcessorModel;
  7286. ULONG ProcessorRevision;
  7287. ULONG ProcessorFamily;
  7288. ULONG ProcessorArchRev;
  7289. ULONGLONG ProcessorSerialNumber;
  7290. ULONGLONG ProcessorFeatureBits;
  7291. UCHAR ProcessorVendorString[16];
  7292. //
  7293. // Space reserved for the system.
  7294. //
  7295. ULONGLONG SystemReserved[8];
  7296. //
  7297. // Space reserved for the HAL.
  7298. //
  7299. ULONGLONG HalReserved[16];
  7300. //
  7301. // End of the architecturally defined section of the PRCB.
  7302. } KPRCB, *PKPRCB, *RESTRICTED_POINTER PRKPRCB;
  7303. // begin_ntndis
  7304. //
  7305. // OS_MCA, OS_INIT HandOff State definitions
  7306. //
  7307. // Note: The following definitions *must* match the definiions of the
  7308. // corresponding SAL Revision Hand-Off structures.
  7309. //
  7310. typedef struct _SAL_HANDOFF_STATE {
  7311. ULONGLONG PalProcEntryPoint;
  7312. ULONGLONG SalProcEntryPoint;
  7313. ULONGLONG SalGlobalPointer;
  7314. LONGLONG RendezVousResult;
  7315. ULONGLONG SalReturnAddress;
  7316. ULONGLONG MinStateSavePtr;
  7317. } SAL_HANDOFF_STATE, *PSAL_HANDOFF_STATE;
  7318. typedef struct _OS_HANDOFF_STATE {
  7319. ULONGLONG Result;
  7320. ULONGLONG SalGlobalPointer;
  7321. ULONGLONG MinStateSavePtr;
  7322. ULONGLONG SalReturnAddress;
  7323. ULONGLONG NewContextFlag;
  7324. } OS_HANDOFF_STATE, *POS_HANDOFF_STATE;
  7325. //
  7326. // per processor OS_MCA and OS_INIT resource structure
  7327. //
  7328. #define SER_EVENT_STACK_FRAME_ENTRIES 8
  7329. typedef struct _SAL_EVENT_RESOURCES {
  7330. SAL_HANDOFF_STATE SalToOsHandOff;
  7331. OS_HANDOFF_STATE OsToSalHandOff;
  7332. PVOID StateDump;
  7333. ULONGLONG StateDumpPhysical;
  7334. PVOID BackStore;
  7335. ULONGLONG BackStoreLimit;
  7336. PVOID Stack;
  7337. ULONGLONG StackLimit;
  7338. PULONGLONG PTOM;
  7339. ULONGLONG StackFrame[SER_EVENT_STACK_FRAME_ENTRIES];
  7340. PVOID EventPool;
  7341. ULONG EventPoolSize;
  7342. } SAL_EVENT_RESOURCES, *PSAL_EVENT_RESOURCES;
  7343. //
  7344. // PAL Mini-save area, used by MCA and INIT
  7345. //
  7346. typedef struct _PAL_MINI_SAVE_AREA {
  7347. ULONGLONG IntNats; // Nat bits for r1-r31
  7348. // r1-r31 in bits 1 thru 31.
  7349. ULONGLONG IntGp; // r1, volatile
  7350. ULONGLONG IntT0; // r2-r3, volatile
  7351. ULONGLONG IntT1; //
  7352. ULONGLONG IntS0; // r4-r7, preserved
  7353. ULONGLONG IntS1;
  7354. ULONGLONG IntS2;
  7355. ULONGLONG IntS3;
  7356. ULONGLONG IntV0; // r8, volatile
  7357. ULONGLONG IntT2; // r9-r11, volatile
  7358. ULONGLONG IntT3;
  7359. ULONGLONG IntT4;
  7360. ULONGLONG IntSp; // stack pointer (r12), special
  7361. ULONGLONG IntTeb; // teb (r13), special
  7362. ULONGLONG IntT5; // r14-r31, volatile
  7363. ULONGLONG IntT6;
  7364. ULONGLONG B0R16; // Bank 0 registers 16-31
  7365. ULONGLONG B0R17;
  7366. ULONGLONG B0R18;
  7367. ULONGLONG B0R19;
  7368. ULONGLONG B0R20;
  7369. ULONGLONG B0R21;
  7370. ULONGLONG B0R22;
  7371. ULONGLONG B0R23;
  7372. ULONGLONG B0R24;
  7373. ULONGLONG B0R25;
  7374. ULONGLONG B0R26;
  7375. ULONGLONG B0R27;
  7376. ULONGLONG B0R28;
  7377. ULONGLONG B0R29;
  7378. ULONGLONG B0R30;
  7379. ULONGLONG B0R31;
  7380. ULONGLONG IntT7; // Bank 1 registers 16-31
  7381. ULONGLONG IntT8;
  7382. ULONGLONG IntT9;
  7383. ULONGLONG IntT10;
  7384. ULONGLONG IntT11;
  7385. ULONGLONG IntT12;
  7386. ULONGLONG IntT13;
  7387. ULONGLONG IntT14;
  7388. ULONGLONG IntT15;
  7389. ULONGLONG IntT16;
  7390. ULONGLONG IntT17;
  7391. ULONGLONG IntT18;
  7392. ULONGLONG IntT19;
  7393. ULONGLONG IntT20;
  7394. ULONGLONG IntT21;
  7395. ULONGLONG IntT22;
  7396. ULONGLONG Preds; // predicates, preserved
  7397. ULONGLONG BrRp; // return pointer, b0, preserved
  7398. ULONGLONG RsRSC; // RSE configuration, volatile
  7399. ULONGLONG StIIP; // Interruption IP
  7400. ULONGLONG StIPSR; // Interruption Processor Status
  7401. ULONGLONG StIFS; // Interruption Function State
  7402. ULONGLONG XIP; // Event IP
  7403. ULONGLONG XPSR; // Event Processor Status
  7404. ULONGLONG XFS; // Event Function State
  7405. } PAL_MINI_SAVE_AREA, *PPAL_MINI_SAVE_AREA;
  7406. //
  7407. // Define Processor Control Region Structure.
  7408. //
  7409. #define PCR_MINOR_VERSION 1
  7410. #define PCR_MAJOR_VERSION 1
  7411. typedef struct _KPCR {
  7412. //
  7413. // Major and minor version numbers of the PCR.
  7414. //
  7415. ULONG MinorVersion;
  7416. ULONG MajorVersion;
  7417. //
  7418. // Start of the architecturally defined section of the PCR. This section
  7419. // may be directly addressed by vendor/platform specific HAL code and will
  7420. // not change from version to version of NT.
  7421. //
  7422. //
  7423. // First and second level cache parameters.
  7424. //
  7425. ULONG FirstLevelDcacheSize;
  7426. ULONG FirstLevelDcacheFillSize;
  7427. ULONG FirstLevelIcacheSize;
  7428. ULONG FirstLevelIcacheFillSize;
  7429. ULONG SecondLevelDcacheSize;
  7430. ULONG SecondLevelDcacheFillSize;
  7431. ULONG SecondLevelIcacheSize;
  7432. ULONG SecondLevelIcacheFillSize;
  7433. //
  7434. // Data cache alignment and fill size used for cache flushing and alignment.
  7435. // These fields are set to the larger of the first and second level data
  7436. // cache fill sizes.
  7437. //
  7438. ULONG DcacheAlignment;
  7439. ULONG DcacheFillSize;
  7440. //
  7441. // Instruction cache alignment and fill size used for cache flushing and
  7442. // alignment. These fields are set to the larger of the first and second
  7443. // level data cache fill sizes.
  7444. //
  7445. ULONG IcacheAlignment;
  7446. ULONG IcacheFillSize;
  7447. //
  7448. // Processor identification from PrId register.
  7449. //
  7450. ULONG ProcessorId;
  7451. //
  7452. // Profiling data.
  7453. //
  7454. ULONG ProfileInterval;
  7455. ULONG ProfileCount;
  7456. //
  7457. // Stall execution count and scale factor.
  7458. //
  7459. ULONG StallExecutionCount;
  7460. ULONG StallScaleFactor;
  7461. ULONG InterruptionCount;
  7462. //
  7463. // Space reserved for the system.
  7464. //
  7465. ULONGLONG SystemReserved[6];
  7466. //
  7467. // Space reserved for the HAL
  7468. //
  7469. ULONGLONG HalReserved[64];
  7470. //
  7471. // IRQL mapping tables.
  7472. //
  7473. UCHAR IrqlMask[64];
  7474. UCHAR IrqlTable[64];
  7475. //
  7476. // External Interrupt vectors.
  7477. //
  7478. PKINTERRUPT_ROUTINE InterruptRoutine[MAXIMUM_VECTOR];
  7479. //
  7480. // Reserved interrupt vector mask.
  7481. //
  7482. ULONG ReservedVectors;
  7483. //
  7484. // Processor affinity mask.
  7485. //
  7486. KAFFINITY SetMember;
  7487. //
  7488. // Complement of the processor affinity mask.
  7489. //
  7490. KAFFINITY NotMember;
  7491. //
  7492. // Pointer to processor control block.
  7493. //
  7494. struct _KPRCB *Prcb;
  7495. //
  7496. // Shadow copy of Prcb->CurrentThread for fast access
  7497. //
  7498. struct _KTHREAD *CurrentThread;
  7499. //
  7500. // Processor number.
  7501. //
  7502. CCHAR Number; // Processor Number
  7503. UCHAR DebugActive; // debug register active in user flag
  7504. UCHAR KernelDebugActive; // debug register active in kernel flag
  7505. UCHAR CurrentIrql; // Current IRQL
  7506. union {
  7507. USHORT SoftwareInterruptPending; // Software Interrupt Pending Flag
  7508. struct {
  7509. UCHAR ApcInterrupt; // 0x01 if APC int pending
  7510. UCHAR DispatchInterrupt; // 0x01 if dispatch int pending
  7511. };
  7512. };
  7513. //
  7514. // Address of per processor SAPIC EOI Table
  7515. //
  7516. PVOID EOITable;
  7517. //
  7518. // IA-64 Machine Check Events trackers
  7519. //
  7520. UCHAR InOsMca;
  7521. UCHAR InOsInit;
  7522. UCHAR InOsCmc;
  7523. UCHAR InOsCpe;
  7524. ULONG InOsULONG_Spare; // Spare ULONG
  7525. PSAL_EVENT_RESOURCES OsMcaResourcePtr;
  7526. PSAL_EVENT_RESOURCES OsInitResourcePtr;
  7527. //
  7528. // End of the architecturally defined section of the PCR. This section
  7529. // may be directly addressed by vendor/platform specific HAL code and will
  7530. // not change from version to version of NT.
  7531. //
  7532. } KPCR, *PKPCR;
  7533. //
  7534. // The highest user address reserves 64K bytes for a guard page. This
  7535. // the probing of address from kernel mode to only have to check the
  7536. // starting address for structures of 64k bytes or less.
  7537. //
  7538. extern NTKERNELAPI PVOID MmHighestUserAddress;
  7539. extern NTKERNELAPI PVOID MmSystemRangeStart;
  7540. extern NTKERNELAPI ULONG_PTR MmUserProbeAddress;
  7541. #define MM_HIGHEST_USER_ADDRESS MmHighestUserAddress
  7542. #define MM_USER_PROBE_ADDRESS MmUserProbeAddress
  7543. #define MM_SYSTEM_RANGE_START MmSystemRangeStart
  7544. //
  7545. // The lowest user address reserves the low 64k.
  7546. //
  7547. #define MM_LOWEST_USER_ADDRESS (PVOID)((ULONG_PTR)(UADDRESS_BASE+0x00010000))
  7548. // begin_wdm
  7549. #define MmGetProcedureAddress(Address) (Address)
  7550. #define MmLockPagableCodeSection(PLabelAddress) \
  7551. MmLockPagableDataSection((PVOID)(*((PULONGLONG)PLabelAddress)))
  7552. #define VRN_MASK 0xE000000000000000UI64 // Virtual Region Number mask
  7553. //
  7554. // The lowest address for system space.
  7555. //
  7556. #define MM_LOWEST_SYSTEM_ADDRESS ((PVOID)((ULONG_PTR)(KADDRESS_BASE + 0xC0C00000)))
  7557. #endif // defined(_IA64_)
  7558. //
  7559. // Event Specific Access Rights.
  7560. //
  7561. #define EVENT_QUERY_STATE 0x0001
  7562. #define EVENT_MODIFY_STATE 0x0002 // winnt
  7563. #define EVENT_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE|0x3) // winnt
  7564. //
  7565. // Semaphore Specific Access Rights.
  7566. //
  7567. #define SEMAPHORE_QUERY_STATE 0x0001
  7568. #define SEMAPHORE_MODIFY_STATE 0x0002 // winnt
  7569. #define SEMAPHORE_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE|0x3) // winnt
  7570. //
  7571. // Timer APC routine definition.
  7572. //
  7573. typedef
  7574. VOID
  7575. (*PTIMER_APC_ROUTINE) (
  7576. IN PVOID TimerContext,
  7577. IN ULONG TimerLowValue,
  7578. IN LONG TimerHighValue
  7579. );
  7580. //
  7581. // Driver Verifier Definitions
  7582. //
  7583. typedef ULONG_PTR (*PDRIVER_VERIFIER_THUNK_ROUTINE) (
  7584. IN PVOID Context
  7585. );
  7586. //
  7587. // This structure is passed in by drivers that want to thunk callers of
  7588. // their exports.
  7589. //
  7590. typedef struct _DRIVER_VERIFIER_THUNK_PAIRS {
  7591. PDRIVER_VERIFIER_THUNK_ROUTINE PristineRoutine;
  7592. PDRIVER_VERIFIER_THUNK_ROUTINE NewRoutine;
  7593. } DRIVER_VERIFIER_THUNK_PAIRS, *PDRIVER_VERIFIER_THUNK_PAIRS;
  7594. //
  7595. // Driver Verifier flags.
  7596. //
  7597. #define DRIVER_VERIFIER_SPECIAL_POOLING 0x0001
  7598. #define DRIVER_VERIFIER_FORCE_IRQL_CHECKING 0x0002
  7599. #define DRIVER_VERIFIER_INJECT_ALLOCATION_FAILURES 0x0004
  7600. #define DRIVER_VERIFIER_TRACK_POOL_ALLOCATIONS 0x0008
  7601. #define DRIVER_VERIFIER_IO_CHECKING 0x0010
  7602. //
  7603. // Defined processor features
  7604. //
  7605. #define PF_FLOATING_POINT_PRECISION_ERRATA 0 // winnt
  7606. #define PF_FLOATING_POINT_EMULATED 1 // winnt
  7607. #define PF_COMPARE_EXCHANGE_DOUBLE 2 // winnt
  7608. #define PF_MMX_INSTRUCTIONS_AVAILABLE 3 // winnt
  7609. #define PF_PPC_MOVEMEM_64BIT_OK 4 // winnt
  7610. #define PF_ALPHA_BYTE_INSTRUCTIONS 5 // winnt
  7611. #define PF_XMMI_INSTRUCTIONS_AVAILABLE 6 // winnt
  7612. #define PF_3DNOW_INSTRUCTIONS_AVAILABLE 7 // winnt
  7613. #define PF_RDTSC_INSTRUCTION_AVAILABLE 8 // winnt
  7614. #define PF_PAE_ENABLED 9 // winnt
  7615. #define PF_XMMI64_INSTRUCTIONS_AVAILABLE 10 // winnt
  7616. typedef enum _ALTERNATIVE_ARCHITECTURE_TYPE {
  7617. StandardDesign, // None == 0 == standard design
  7618. NEC98x86, // NEC PC98xx series on X86
  7619. EndAlternatives // past end of known alternatives
  7620. } ALTERNATIVE_ARCHITECTURE_TYPE;
  7621. // correctly define these run-time definitions for non X86 machines
  7622. #ifndef _X86_
  7623. #ifndef IsNEC_98
  7624. #define IsNEC_98 (FALSE)
  7625. #endif
  7626. #ifndef IsNotNEC_98
  7627. #define IsNotNEC_98 (TRUE)
  7628. #endif
  7629. #ifndef SetNEC_98
  7630. #define SetNEC_98
  7631. #endif
  7632. #ifndef SetNotNEC_98
  7633. #define SetNotNEC_98
  7634. #endif
  7635. #endif
  7636. #define PROCESSOR_FEATURE_MAX 64
  7637. // end_wdm
  7638. #if defined(REMOTE_BOOT)
  7639. //
  7640. // Defined system flags.
  7641. //
  7642. /* the following two lines should be tagged with "winnt" when REMOTE_BOOT is on. */
  7643. #define SYSTEM_FLAG_REMOTE_BOOT_CLIENT 0x00000001
  7644. #define SYSTEM_FLAG_DISKLESS_CLIENT 0x00000002
  7645. #endif // defined(REMOTE_BOOT)
  7646. //
  7647. // Define data shared between kernel and user mode.
  7648. //
  7649. // N.B. User mode has read only access to this data
  7650. //
  7651. #ifdef _MAC
  7652. #pragma warning( disable : 4121)
  7653. #endif
  7654. //
  7655. // Note: When adding a new field that's processor-architecture-specific (for example, bound with #if i386),
  7656. // then place this field to be the last element in the KUSER_SHARED_DATA so that offsets into common
  7657. // fields are the same for Wow6432 and Win64.
  7658. //
  7659. typedef struct _KUSER_SHARED_DATA {
  7660. //
  7661. // Current low 32-bit of tick count and tick count multiplier.
  7662. //
  7663. // N.B. The tick count is updated each time the clock ticks.
  7664. //
  7665. volatile ULONG TickCountLow;
  7666. ULONG TickCountMultiplier;
  7667. //
  7668. // Current 64-bit interrupt time in 100ns units.
  7669. //
  7670. volatile KSYSTEM_TIME InterruptTime;
  7671. //
  7672. // Current 64-bit system time in 100ns units.
  7673. //
  7674. volatile KSYSTEM_TIME SystemTime;
  7675. //
  7676. // Current 64-bit time zone bias.
  7677. //
  7678. volatile KSYSTEM_TIME TimeZoneBias;
  7679. //
  7680. // Support image magic number range for the host system.
  7681. //
  7682. // N.B. This is an inclusive range.
  7683. //
  7684. USHORT ImageNumberLow;
  7685. USHORT ImageNumberHigh;
  7686. //
  7687. // Copy of system root in Unicode
  7688. //
  7689. WCHAR NtSystemRoot[ 260 ];
  7690. //
  7691. // Maximum stack trace depth if tracing enabled.
  7692. //
  7693. ULONG MaxStackTraceDepth;
  7694. //
  7695. // Crypto Exponent
  7696. //
  7697. ULONG CryptoExponent;
  7698. //
  7699. // TimeZoneId
  7700. //
  7701. ULONG TimeZoneId;
  7702. ULONG Reserved2[ 8 ];
  7703. //
  7704. // product type
  7705. //
  7706. NT_PRODUCT_TYPE NtProductType;
  7707. BOOLEAN ProductTypeIsValid;
  7708. //
  7709. // NT Version. Note that each process sees a version from its PEB, but
  7710. // if the process is running with an altered view of the system version,
  7711. // the following two fields are used to correctly identify the version
  7712. //
  7713. ULONG NtMajorVersion;
  7714. ULONG NtMinorVersion;
  7715. //
  7716. // Processor Feature Bits
  7717. //
  7718. BOOLEAN ProcessorFeatures[PROCESSOR_FEATURE_MAX];
  7719. //
  7720. // Reserved fields - do not use
  7721. //
  7722. ULONG Reserved1;
  7723. ULONG Reserved3;
  7724. //
  7725. // Time slippage while in debugger
  7726. //
  7727. volatile ULONG TimeSlip;
  7728. //
  7729. // Alternative system architecture. Example: NEC PC98xx on x86
  7730. //
  7731. ALTERNATIVE_ARCHITECTURE_TYPE AlternativeArchitecture;
  7732. //
  7733. // If the system is an evaluation unit, the following field contains the
  7734. // date and time that the evaluation unit expires. A value of 0 indicates
  7735. // that there is no expiration. A non-zero value is the UTC absolute time
  7736. // that the system expires.
  7737. //
  7738. LARGE_INTEGER SystemExpirationDate;
  7739. //
  7740. // Suite Support
  7741. //
  7742. ULONG SuiteMask;
  7743. //
  7744. // TRUE if a kernel debugger is connected/enabled
  7745. //
  7746. BOOLEAN KdDebuggerEnabled;
  7747. //
  7748. // Current console session Id. Always zero on non-TS systems
  7749. //
  7750. volatile ULONG ActiveConsoleId;
  7751. //
  7752. // Force-dismounts cause handles to become invalid. Rather than
  7753. // always probe handles, we maintain a serial number of
  7754. // dismounts that clients can use to see if they need to probe
  7755. // handles.
  7756. //
  7757. volatile ULONG DismountCount;
  7758. //
  7759. // This field indicates the status of the 64-bit COM+ package on the system.
  7760. // It indicates whether the Itermediate Language (IL) COM+ images need to
  7761. // use the 64-bit COM+ runtime or the 32-bit COM+ runtime.
  7762. //
  7763. ULONG ComPlusPackage;
  7764. //
  7765. // Time in tick count for system-wide last user input across all
  7766. // terminal sessions. For MP performance, it is not updated all
  7767. // the time (e.g. once a minute per session). It is used for idle
  7768. // detection.
  7769. //
  7770. ULONG LastSystemRITEventTickCount;
  7771. //
  7772. // Number of physical pages in the system. This can dynamically
  7773. // change as physical memory can be added or removed from a running
  7774. // system.
  7775. //
  7776. ULONG NumberOfPhysicalPages;
  7777. //
  7778. // True if the system was booted in safe boot mode.
  7779. //
  7780. BOOLEAN SafeBootMode;
  7781. //
  7782. // The following field is used for Heap and CritSec Tracing
  7783. // The last bit is set for Critical Sec Collision tracing and
  7784. // second Last bit is for Heap Tracing
  7785. // Also the first 16 bits are used as counter.
  7786. //
  7787. ULONG TraceLogging;
  7788. #if defined(i386)
  7789. //
  7790. // Depending on the processor, the code for fast system call
  7791. // will differ, the following buffer is filled with the appropriate
  7792. // code sequence and user mode code will branch through it.
  7793. //
  7794. // (32 bytes, using ULONGLONG for alignment).
  7795. //
  7796. ULONGLONG Fill0; // alignment
  7797. ULONGLONG SystemCall[4];
  7798. #endif
  7799. } KUSER_SHARED_DATA, *PKUSER_SHARED_DATA;
  7800. #ifdef _MAC
  7801. #pragma warning( default : 4121 )
  7802. #endif
  7803. // begin_winnt
  7804. //
  7805. // Predefined Value Types.
  7806. //
  7807. #define REG_NONE ( 0 ) // No value type
  7808. #define REG_SZ ( 1 ) // Unicode nul terminated string
  7809. #define REG_EXPAND_SZ ( 2 ) // Unicode nul terminated string
  7810. // (with environment variable references)
  7811. #define REG_BINARY ( 3 ) // Free form binary
  7812. #define REG_DWORD ( 4 ) // 32-bit number
  7813. #define REG_DWORD_LITTLE_ENDIAN ( 4 ) // 32-bit number (same as REG_DWORD)
  7814. #define REG_DWORD_BIG_ENDIAN ( 5 ) // 32-bit number
  7815. #define REG_LINK ( 6 ) // Symbolic Link (unicode)
  7816. #define REG_MULTI_SZ ( 7 ) // Multiple Unicode strings
  7817. #define REG_RESOURCE_LIST ( 8 ) // Resource list in the resource map
  7818. #define REG_FULL_RESOURCE_DESCRIPTOR ( 9 ) // Resource list in the hardware description
  7819. #define REG_RESOURCE_REQUIREMENTS_LIST ( 10 )
  7820. #define REG_QWORD ( 11 ) // 64-bit number
  7821. #define REG_QWORD_LITTLE_ENDIAN ( 11 ) // 64-bit number (same as REG_QWORD)
  7822. //
  7823. // Service Types (Bit Mask)
  7824. //
  7825. #define SERVICE_KERNEL_DRIVER 0x00000001
  7826. #define SERVICE_FILE_SYSTEM_DRIVER 0x00000002
  7827. #define SERVICE_ADAPTER 0x00000004
  7828. #define SERVICE_RECOGNIZER_DRIVER 0x00000008
  7829. #define SERVICE_DRIVER (SERVICE_KERNEL_DRIVER | \
  7830. SERVICE_FILE_SYSTEM_DRIVER | \
  7831. SERVICE_RECOGNIZER_DRIVER)
  7832. #define SERVICE_WIN32_OWN_PROCESS 0x00000010
  7833. #define SERVICE_WIN32_SHARE_PROCESS 0x00000020
  7834. #define SERVICE_WIN32 (SERVICE_WIN32_OWN_PROCESS | \
  7835. SERVICE_WIN32_SHARE_PROCESS)
  7836. #define SERVICE_INTERACTIVE_PROCESS 0x00000100
  7837. #define SERVICE_TYPE_ALL (SERVICE_WIN32 | \
  7838. SERVICE_ADAPTER | \
  7839. SERVICE_DRIVER | \
  7840. SERVICE_INTERACTIVE_PROCESS)
  7841. //
  7842. // Start Type
  7843. //
  7844. #define SERVICE_BOOT_START 0x00000000
  7845. #define SERVICE_SYSTEM_START 0x00000001
  7846. #define SERVICE_AUTO_START 0x00000002
  7847. #define SERVICE_DEMAND_START 0x00000003
  7848. #define SERVICE_DISABLED 0x00000004
  7849. //
  7850. // Error control type
  7851. //
  7852. #define SERVICE_ERROR_IGNORE 0x00000000
  7853. #define SERVICE_ERROR_NORMAL 0x00000001
  7854. #define SERVICE_ERROR_SEVERE 0x00000002
  7855. #define SERVICE_ERROR_CRITICAL 0x00000003
  7856. //
  7857. //
  7858. // Define the registry driver node enumerations
  7859. //
  7860. typedef enum _CM_SERVICE_NODE_TYPE {
  7861. DriverType = SERVICE_KERNEL_DRIVER,
  7862. FileSystemType = SERVICE_FILE_SYSTEM_DRIVER,
  7863. Win32ServiceOwnProcess = SERVICE_WIN32_OWN_PROCESS,
  7864. Win32ServiceShareProcess = SERVICE_WIN32_SHARE_PROCESS,
  7865. AdapterType = SERVICE_ADAPTER,
  7866. RecognizerType = SERVICE_RECOGNIZER_DRIVER
  7867. } SERVICE_NODE_TYPE;
  7868. typedef enum _CM_SERVICE_LOAD_TYPE {
  7869. BootLoad = SERVICE_BOOT_START,
  7870. SystemLoad = SERVICE_SYSTEM_START,
  7871. AutoLoad = SERVICE_AUTO_START,
  7872. DemandLoad = SERVICE_DEMAND_START,
  7873. DisableLoad = SERVICE_DISABLED
  7874. } SERVICE_LOAD_TYPE;
  7875. typedef enum _CM_ERROR_CONTROL_TYPE {
  7876. IgnoreError = SERVICE_ERROR_IGNORE,
  7877. NormalError = SERVICE_ERROR_NORMAL,
  7878. SevereError = SERVICE_ERROR_SEVERE,
  7879. CriticalError = SERVICE_ERROR_CRITICAL
  7880. } SERVICE_ERROR_TYPE;
  7881. // end_winnt
  7882. //
  7883. // Resource List definitions
  7884. //
  7885. // begin_ntminiport begin_ntndis
  7886. //
  7887. // Defines the Type in the RESOURCE_DESCRIPTOR
  7888. //
  7889. // NOTE: For all CM_RESOURCE_TYPE values, there must be a
  7890. // corresponding ResType value in the 32-bit ConfigMgr headerfile
  7891. // (cfgmgr32.h). Values in the range [0x6,0x80) use the same values
  7892. // as their ConfigMgr counterparts. CM_RESOURCE_TYPE values with
  7893. // the high bit set (i.e., in the range [0x80,0xFF]), are
  7894. // non-arbitrated resources. These correspond to the same values
  7895. // in cfgmgr32.h that have their high bit set (however, since
  7896. // cfgmgr32.h uses 16 bits for ResType values, these values are in
  7897. // the range [0x8000,0x807F). Note that ConfigMgr ResType values
  7898. // cannot be in the range [0x8080,0xFFFF), because they would not
  7899. // be able to map into CM_RESOURCE_TYPE values. (0xFFFF itself is
  7900. // a special value, because it maps to CmResourceTypeDeviceSpecific.)
  7901. //
  7902. typedef int CM_RESOURCE_TYPE;
  7903. // CmResourceTypeNull is reserved
  7904. #define CmResourceTypeNull 0 // ResType_All or ResType_None (0x0000)
  7905. #define CmResourceTypePort 1 // ResType_IO (0x0002)
  7906. #define CmResourceTypeInterrupt 2 // ResType_IRQ (0x0004)
  7907. #define CmResourceTypeMemory 3 // ResType_Mem (0x0001)
  7908. #define CmResourceTypeDma 4 // ResType_DMA (0x0003)
  7909. #define CmResourceTypeDeviceSpecific 5 // ResType_ClassSpecific (0xFFFF)
  7910. #define CmResourceTypeBusNumber 6 // ResType_BusNumber (0x0006)
  7911. // end_wdm
  7912. #define CmResourceTypeMaximum 7
  7913. // begin_wdm
  7914. #define CmResourceTypeNonArbitrated 128 // Not arbitrated if 0x80 bit set
  7915. #define CmResourceTypeConfigData 128 // ResType_Reserved (0x8000)
  7916. #define CmResourceTypeDevicePrivate 129 // ResType_DevicePrivate (0x8001)
  7917. #define CmResourceTypePcCardConfig 130 // ResType_PcCardConfig (0x8002)
  7918. #define CmResourceTypeMfCardConfig 131 // ResType_MfCardConfig (0x8003)
  7919. //
  7920. // Defines the ShareDisposition in the RESOURCE_DESCRIPTOR
  7921. //
  7922. typedef enum _CM_SHARE_DISPOSITION {
  7923. CmResourceShareUndetermined = 0, // Reserved
  7924. CmResourceShareDeviceExclusive,
  7925. CmResourceShareDriverExclusive,
  7926. CmResourceShareShared
  7927. } CM_SHARE_DISPOSITION;
  7928. //
  7929. // Define the bit masks for Flags when type is CmResourceTypeInterrupt
  7930. //
  7931. #define CM_RESOURCE_INTERRUPT_LEVEL_SENSITIVE 0
  7932. #define CM_RESOURCE_INTERRUPT_LATCHED 1
  7933. //
  7934. // Define the bit masks for Flags when type is CmResourceTypeMemory
  7935. //
  7936. #define CM_RESOURCE_MEMORY_READ_WRITE 0x0000
  7937. #define CM_RESOURCE_MEMORY_READ_ONLY 0x0001
  7938. #define CM_RESOURCE_MEMORY_WRITE_ONLY 0x0002
  7939. #define CM_RESOURCE_MEMORY_PREFETCHABLE 0x0004
  7940. #define CM_RESOURCE_MEMORY_COMBINEDWRITE 0x0008
  7941. #define CM_RESOURCE_MEMORY_24 0x0010
  7942. #define CM_RESOURCE_MEMORY_CACHEABLE 0x0020
  7943. //
  7944. // Define the bit masks for Flags when type is CmResourceTypePort
  7945. //
  7946. #define CM_RESOURCE_PORT_MEMORY 0x0000
  7947. #define CM_RESOURCE_PORT_IO 0x0001
  7948. #define CM_RESOURCE_PORT_10_BIT_DECODE 0x0004
  7949. #define CM_RESOURCE_PORT_12_BIT_DECODE 0x0008
  7950. #define CM_RESOURCE_PORT_16_BIT_DECODE 0x0010
  7951. #define CM_RESOURCE_PORT_POSITIVE_DECODE 0x0020
  7952. #define CM_RESOURCE_PORT_PASSIVE_DECODE 0x0040
  7953. #define CM_RESOURCE_PORT_WINDOW_DECODE 0x0080
  7954. //
  7955. // Define the bit masks for Flags when type is CmResourceTypeDma
  7956. //
  7957. #define CM_RESOURCE_DMA_8 0x0000
  7958. #define CM_RESOURCE_DMA_16 0x0001
  7959. #define CM_RESOURCE_DMA_32 0x0002
  7960. #define CM_RESOURCE_DMA_8_AND_16 0x0004
  7961. #define CM_RESOURCE_DMA_BUS_MASTER 0x0008
  7962. #define CM_RESOURCE_DMA_TYPE_A 0x0010
  7963. #define CM_RESOURCE_DMA_TYPE_B 0x0020
  7964. #define CM_RESOURCE_DMA_TYPE_F 0x0040
  7965. // end_ntminiport end_ntndis
  7966. //
  7967. // This structure defines one type of resource used by a driver.
  7968. //
  7969. // There can only be *1* DeviceSpecificData block. It must be located at
  7970. // the end of all resource descriptors in a full descriptor block.
  7971. //
  7972. //
  7973. // Make sure alignment is made properly by compiler; otherwise move
  7974. // flags back to the top of the structure (common to all members of the
  7975. // union).
  7976. //
  7977. // begin_ntndis
  7978. #include "pshpack4.h"
  7979. typedef struct _CM_PARTIAL_RESOURCE_DESCRIPTOR {
  7980. UCHAR Type;
  7981. UCHAR ShareDisposition;
  7982. USHORT Flags;
  7983. union {
  7984. //
  7985. // Range of resources, inclusive. These are physical, bus relative.
  7986. // It is known that Port and Memory below have the exact same layout
  7987. // as Generic.
  7988. //
  7989. struct {
  7990. PHYSICAL_ADDRESS Start;
  7991. ULONG Length;
  7992. } Generic;
  7993. //
  7994. // end_wdm
  7995. // Range of port numbers, inclusive. These are physical, bus
  7996. // relative. The value should be the same as the one passed to
  7997. // HalTranslateBusAddress().
  7998. // begin_wdm
  7999. //
  8000. struct {
  8001. PHYSICAL_ADDRESS Start;
  8002. ULONG Length;
  8003. } Port;
  8004. //
  8005. // end_wdm
  8006. // IRQL and vector. Should be same values as were passed to
  8007. // HalGetInterruptVector().
  8008. // begin_wdm
  8009. //
  8010. struct {
  8011. ULONG Level;
  8012. ULONG Vector;
  8013. KAFFINITY Affinity;
  8014. } Interrupt;
  8015. //
  8016. // Range of memory addresses, inclusive. These are physical, bus
  8017. // relative. The value should be the same as the one passed to
  8018. // HalTranslateBusAddress().
  8019. //
  8020. struct {
  8021. PHYSICAL_ADDRESS Start; // 64 bit physical addresses.
  8022. ULONG Length;
  8023. } Memory;
  8024. //
  8025. // Physical DMA channel.
  8026. //
  8027. struct {
  8028. ULONG Channel;
  8029. ULONG Port;
  8030. ULONG Reserved1;
  8031. } Dma;
  8032. //
  8033. // Device driver private data, usually used to help it figure
  8034. // what the resource assignments decisions that were made.
  8035. //
  8036. struct {
  8037. ULONG Data[3];
  8038. } DevicePrivate;
  8039. //
  8040. // Bus Number information.
  8041. //
  8042. struct {
  8043. ULONG Start;
  8044. ULONG Length;
  8045. ULONG Reserved;
  8046. } BusNumber;
  8047. //
  8048. // Device Specific information defined by the driver.
  8049. // The DataSize field indicates the size of the data in bytes. The
  8050. // data is located immediately after the DeviceSpecificData field in
  8051. // the structure.
  8052. //
  8053. struct {
  8054. ULONG DataSize;
  8055. ULONG Reserved1;
  8056. ULONG Reserved2;
  8057. } DeviceSpecificData;
  8058. } u;
  8059. } CM_PARTIAL_RESOURCE_DESCRIPTOR, *PCM_PARTIAL_RESOURCE_DESCRIPTOR;
  8060. #include "poppack.h"
  8061. //
  8062. // A Partial Resource List is what can be found in the ARC firmware
  8063. // or will be generated by ntdetect.com.
  8064. // The configuration manager will transform this structure into a Full
  8065. // resource descriptor when it is about to store it in the regsitry.
  8066. //
  8067. // Note: There must a be a convention to the order of fields of same type,
  8068. // (defined on a device by device basis) so that the fields can make sense
  8069. // to a driver (i.e. when multiple memory ranges are necessary).
  8070. //
  8071. typedef struct _CM_PARTIAL_RESOURCE_LIST {
  8072. USHORT Version;
  8073. USHORT Revision;
  8074. ULONG Count;
  8075. CM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptors[1];
  8076. } CM_PARTIAL_RESOURCE_LIST, *PCM_PARTIAL_RESOURCE_LIST;
  8077. //
  8078. // A Full Resource Descriptor is what can be found in the registry.
  8079. // This is what will be returned to a driver when it queries the registry
  8080. // to get device information; it will be stored under a key in the hardware
  8081. // description tree.
  8082. //
  8083. // end_wdm
  8084. // Note: The BusNumber and Type are redundant information, but we will keep
  8085. // it since it allows the driver _not_ to append it when it is creating
  8086. // a resource list which could possibly span multiple buses.
  8087. //
  8088. // begin_wdm
  8089. // Note: There must a be a convention to the order of fields of same type,
  8090. // (defined on a device by device basis) so that the fields can make sense
  8091. // to a driver (i.e. when multiple memory ranges are necessary).
  8092. //
  8093. typedef struct _CM_FULL_RESOURCE_DESCRIPTOR {
  8094. INTERFACE_TYPE InterfaceType; // unused for WDM
  8095. ULONG BusNumber; // unused for WDM
  8096. CM_PARTIAL_RESOURCE_LIST PartialResourceList;
  8097. } CM_FULL_RESOURCE_DESCRIPTOR, *PCM_FULL_RESOURCE_DESCRIPTOR;
  8098. //
  8099. // The Resource list is what will be stored by the drivers into the
  8100. // resource map via the IO API.
  8101. //
  8102. typedef struct _CM_RESOURCE_LIST {
  8103. ULONG Count;
  8104. CM_FULL_RESOURCE_DESCRIPTOR List[1];
  8105. } CM_RESOURCE_LIST, *PCM_RESOURCE_LIST;
  8106. // end_ntndis
  8107. //
  8108. // Define the structures used to interpret configuration data of
  8109. // \\Registry\machine\hardware\description tree.
  8110. // Basically, these structures are used to interpret component
  8111. // sepcific data.
  8112. //
  8113. //
  8114. // Define DEVICE_FLAGS
  8115. //
  8116. typedef struct _DEVICE_FLAGS {
  8117. ULONG Failed : 1;
  8118. ULONG ReadOnly : 1;
  8119. ULONG Removable : 1;
  8120. ULONG ConsoleIn : 1;
  8121. ULONG ConsoleOut : 1;
  8122. ULONG Input : 1;
  8123. ULONG Output : 1;
  8124. } DEVICE_FLAGS, *PDEVICE_FLAGS;
  8125. //
  8126. // Define Component Information structure
  8127. //
  8128. typedef struct _CM_COMPONENT_INFORMATION {
  8129. DEVICE_FLAGS Flags;
  8130. ULONG Version;
  8131. ULONG Key;
  8132. KAFFINITY AffinityMask;
  8133. } CM_COMPONENT_INFORMATION, *PCM_COMPONENT_INFORMATION;
  8134. //
  8135. // The following structures are used to interpret x86
  8136. // DeviceSpecificData of CM_PARTIAL_RESOURCE_DESCRIPTOR.
  8137. // (Most of the structures are defined by BIOS. They are
  8138. // not aligned on word (or dword) boundary.
  8139. //
  8140. //
  8141. // Define the Rom Block structure
  8142. //
  8143. typedef struct _CM_ROM_BLOCK {
  8144. ULONG Address;
  8145. ULONG Size;
  8146. } CM_ROM_BLOCK, *PCM_ROM_BLOCK;
  8147. // begin_ntminiport begin_ntndis
  8148. #include "pshpack1.h"
  8149. // end_ntminiport end_ntndis
  8150. //
  8151. // Define INT13 driver parameter block
  8152. //
  8153. typedef struct _CM_INT13_DRIVE_PARAMETER {
  8154. USHORT DriveSelect;
  8155. ULONG MaxCylinders;
  8156. USHORT SectorsPerTrack;
  8157. USHORT MaxHeads;
  8158. USHORT NumberDrives;
  8159. } CM_INT13_DRIVE_PARAMETER, *PCM_INT13_DRIVE_PARAMETER;
  8160. // begin_ntminiport begin_ntndis
  8161. //
  8162. // Define Mca POS data block for slot
  8163. //
  8164. typedef struct _CM_MCA_POS_DATA {
  8165. USHORT AdapterId;
  8166. UCHAR PosData1;
  8167. UCHAR PosData2;
  8168. UCHAR PosData3;
  8169. UCHAR PosData4;
  8170. } CM_MCA_POS_DATA, *PCM_MCA_POS_DATA;
  8171. //
  8172. // Memory configuration of eisa data block structure
  8173. //
  8174. typedef struct _EISA_MEMORY_TYPE {
  8175. UCHAR ReadWrite: 1;
  8176. UCHAR Cached : 1;
  8177. UCHAR Reserved0 :1;
  8178. UCHAR Type:2;
  8179. UCHAR Shared:1;
  8180. UCHAR Reserved1 :1;
  8181. UCHAR MoreEntries : 1;
  8182. } EISA_MEMORY_TYPE, *PEISA_MEMORY_TYPE;
  8183. typedef struct _EISA_MEMORY_CONFIGURATION {
  8184. EISA_MEMORY_TYPE ConfigurationByte;
  8185. UCHAR DataSize;
  8186. USHORT AddressLowWord;
  8187. UCHAR AddressHighByte;
  8188. USHORT MemorySize;
  8189. } EISA_MEMORY_CONFIGURATION, *PEISA_MEMORY_CONFIGURATION;
  8190. //
  8191. // Interrupt configurationn of eisa data block structure
  8192. //
  8193. typedef struct _EISA_IRQ_DESCRIPTOR {
  8194. UCHAR Interrupt : 4;
  8195. UCHAR Reserved :1;
  8196. UCHAR LevelTriggered :1;
  8197. UCHAR Shared : 1;
  8198. UCHAR MoreEntries : 1;
  8199. } EISA_IRQ_DESCRIPTOR, *PEISA_IRQ_DESCRIPTOR;
  8200. typedef struct _EISA_IRQ_CONFIGURATION {
  8201. EISA_IRQ_DESCRIPTOR ConfigurationByte;
  8202. UCHAR Reserved;
  8203. } EISA_IRQ_CONFIGURATION, *PEISA_IRQ_CONFIGURATION;
  8204. //
  8205. // DMA description of eisa data block structure
  8206. //
  8207. typedef struct _DMA_CONFIGURATION_BYTE0 {
  8208. UCHAR Channel : 3;
  8209. UCHAR Reserved : 3;
  8210. UCHAR Shared :1;
  8211. UCHAR MoreEntries :1;
  8212. } DMA_CONFIGURATION_BYTE0;
  8213. typedef struct _DMA_CONFIGURATION_BYTE1 {
  8214. UCHAR Reserved0 : 2;
  8215. UCHAR TransferSize : 2;
  8216. UCHAR Timing : 2;
  8217. UCHAR Reserved1 : 2;
  8218. } DMA_CONFIGURATION_BYTE1;
  8219. typedef struct _EISA_DMA_CONFIGURATION {
  8220. DMA_CONFIGURATION_BYTE0 ConfigurationByte0;
  8221. DMA_CONFIGURATION_BYTE1 ConfigurationByte1;
  8222. } EISA_DMA_CONFIGURATION, *PEISA_DMA_CONFIGURATION;
  8223. //
  8224. // Port description of eisa data block structure
  8225. //
  8226. typedef struct _EISA_PORT_DESCRIPTOR {
  8227. UCHAR NumberPorts : 5;
  8228. UCHAR Reserved :1;
  8229. UCHAR Shared :1;
  8230. UCHAR MoreEntries : 1;
  8231. } EISA_PORT_DESCRIPTOR, *PEISA_PORT_DESCRIPTOR;
  8232. typedef struct _EISA_PORT_CONFIGURATION {
  8233. EISA_PORT_DESCRIPTOR Configuration;
  8234. USHORT PortAddress;
  8235. } EISA_PORT_CONFIGURATION, *PEISA_PORT_CONFIGURATION;
  8236. //
  8237. // Eisa slot information definition
  8238. // N.B. This structure is different from the one defined
  8239. // in ARC eisa addendum.
  8240. //
  8241. typedef struct _CM_EISA_SLOT_INFORMATION {
  8242. UCHAR ReturnCode;
  8243. UCHAR ReturnFlags;
  8244. UCHAR MajorRevision;
  8245. UCHAR MinorRevision;
  8246. USHORT Checksum;
  8247. UCHAR NumberFunctions;
  8248. UCHAR FunctionInformation;
  8249. ULONG CompressedId;
  8250. } CM_EISA_SLOT_INFORMATION, *PCM_EISA_SLOT_INFORMATION;
  8251. //
  8252. // Eisa function information definition
  8253. //
  8254. typedef struct _CM_EISA_FUNCTION_INFORMATION {
  8255. ULONG CompressedId;
  8256. UCHAR IdSlotFlags1;
  8257. UCHAR IdSlotFlags2;
  8258. UCHAR MinorRevision;
  8259. UCHAR MajorRevision;
  8260. UCHAR Selections[26];
  8261. UCHAR FunctionFlags;
  8262. UCHAR TypeString[80];
  8263. EISA_MEMORY_CONFIGURATION EisaMemory[9];
  8264. EISA_IRQ_CONFIGURATION EisaIrq[7];
  8265. EISA_DMA_CONFIGURATION EisaDma[4];
  8266. EISA_PORT_CONFIGURATION EisaPort[20];
  8267. UCHAR InitializationData[60];
  8268. } CM_EISA_FUNCTION_INFORMATION, *PCM_EISA_FUNCTION_INFORMATION;
  8269. //
  8270. // The following defines the way pnp bios information is stored in
  8271. // the registry \\HKEY_LOCAL_MACHINE\HARDWARE\Description\System\MultifunctionAdapter\x
  8272. // key, where x is an integer number indicating adapter instance. The
  8273. // "Identifier" of the key must equal to "PNP BIOS" and the
  8274. // "ConfigurationData" is organized as follow:
  8275. //
  8276. // CM_PNP_BIOS_INSTALLATION_CHECK +
  8277. // CM_PNP_BIOS_DEVICE_NODE for device 1 +
  8278. // CM_PNP_BIOS_DEVICE_NODE for device 2 +
  8279. // ...
  8280. // CM_PNP_BIOS_DEVICE_NODE for device n
  8281. //
  8282. //
  8283. // Pnp BIOS device node structure
  8284. //
  8285. typedef struct _CM_PNP_BIOS_DEVICE_NODE {
  8286. USHORT Size;
  8287. UCHAR Node;
  8288. ULONG ProductId;
  8289. UCHAR DeviceType[3];
  8290. USHORT DeviceAttributes;
  8291. // followed by AllocatedResourceBlock, PossibleResourceBlock
  8292. // and CompatibleDeviceId
  8293. } CM_PNP_BIOS_DEVICE_NODE,*PCM_PNP_BIOS_DEVICE_NODE;
  8294. //
  8295. // Pnp BIOS Installation check
  8296. //
  8297. typedef struct _CM_PNP_BIOS_INSTALLATION_CHECK {
  8298. UCHAR Signature[4]; // $PnP (ascii)
  8299. UCHAR Revision;
  8300. UCHAR Length;
  8301. USHORT ControlField;
  8302. UCHAR Checksum;
  8303. ULONG EventFlagAddress; // Physical address
  8304. USHORT RealModeEntryOffset;
  8305. USHORT RealModeEntrySegment;
  8306. USHORT ProtectedModeEntryOffset;
  8307. ULONG ProtectedModeCodeBaseAddress;
  8308. ULONG OemDeviceId;
  8309. USHORT RealModeDataBaseAddress;
  8310. ULONG ProtectedModeDataBaseAddress;
  8311. } CM_PNP_BIOS_INSTALLATION_CHECK, *PCM_PNP_BIOS_INSTALLATION_CHECK;
  8312. #include "poppack.h"
  8313. //
  8314. // Masks for EISA function information
  8315. //
  8316. #define EISA_FUNCTION_ENABLED 0x80
  8317. #define EISA_FREE_FORM_DATA 0x40
  8318. #define EISA_HAS_PORT_INIT_ENTRY 0x20
  8319. #define EISA_HAS_PORT_RANGE 0x10
  8320. #define EISA_HAS_DMA_ENTRY 0x08
  8321. #define EISA_HAS_IRQ_ENTRY 0x04
  8322. #define EISA_HAS_MEMORY_ENTRY 0x02
  8323. #define EISA_HAS_TYPE_ENTRY 0x01
  8324. #define EISA_HAS_INFORMATION EISA_HAS_PORT_RANGE + \
  8325. EISA_HAS_DMA_ENTRY + \
  8326. EISA_HAS_IRQ_ENTRY + \
  8327. EISA_HAS_MEMORY_ENTRY + \
  8328. EISA_HAS_TYPE_ENTRY
  8329. //
  8330. // Masks for EISA memory configuration
  8331. //
  8332. #define EISA_MORE_ENTRIES 0x80
  8333. #define EISA_SYSTEM_MEMORY 0x00
  8334. #define EISA_MEMORY_TYPE_RAM 0x01
  8335. //
  8336. // Returned error code for EISA bios call
  8337. //
  8338. #define EISA_INVALID_SLOT 0x80
  8339. #define EISA_INVALID_FUNCTION 0x81
  8340. #define EISA_INVALID_CONFIGURATION 0x82
  8341. #define EISA_EMPTY_SLOT 0x83
  8342. #define EISA_INVALID_BIOS_CALL 0x86
  8343. // end_ntminiport end_ntndis
  8344. //
  8345. // The following structures are used to interpret mips
  8346. // DeviceSpecificData of CM_PARTIAL_RESOURCE_DESCRIPTOR.
  8347. //
  8348. //
  8349. // Device data records for adapters.
  8350. //
  8351. //
  8352. // The device data record for the Emulex SCSI controller.
  8353. //
  8354. typedef struct _CM_SCSI_DEVICE_DATA {
  8355. USHORT Version;
  8356. USHORT Revision;
  8357. UCHAR HostIdentifier;
  8358. } CM_SCSI_DEVICE_DATA, *PCM_SCSI_DEVICE_DATA;
  8359. //
  8360. // Device data records for controllers.
  8361. //
  8362. //
  8363. // The device data record for the Video controller.
  8364. //
  8365. typedef struct _CM_VIDEO_DEVICE_DATA {
  8366. USHORT Version;
  8367. USHORT Revision;
  8368. ULONG VideoClock;
  8369. } CM_VIDEO_DEVICE_DATA, *PCM_VIDEO_DEVICE_DATA;
  8370. //
  8371. // The device data record for the SONIC network controller.
  8372. //
  8373. typedef struct _CM_SONIC_DEVICE_DATA {
  8374. USHORT Version;
  8375. USHORT Revision;
  8376. USHORT DataConfigurationRegister;
  8377. UCHAR EthernetAddress[8];
  8378. } CM_SONIC_DEVICE_DATA, *PCM_SONIC_DEVICE_DATA;
  8379. //
  8380. // The device data record for the serial controller.
  8381. //
  8382. typedef struct _CM_SERIAL_DEVICE_DATA {
  8383. USHORT Version;
  8384. USHORT Revision;
  8385. ULONG BaudClock;
  8386. } CM_SERIAL_DEVICE_DATA, *PCM_SERIAL_DEVICE_DATA;
  8387. //
  8388. // Device data records for peripherals.
  8389. //
  8390. //
  8391. // The device data record for the Monitor peripheral.
  8392. //
  8393. typedef struct _CM_MONITOR_DEVICE_DATA {
  8394. USHORT Version;
  8395. USHORT Revision;
  8396. USHORT HorizontalScreenSize;
  8397. USHORT VerticalScreenSize;
  8398. USHORT HorizontalResolution;
  8399. USHORT VerticalResolution;
  8400. USHORT HorizontalDisplayTimeLow;
  8401. USHORT HorizontalDisplayTime;
  8402. USHORT HorizontalDisplayTimeHigh;
  8403. USHORT HorizontalBackPorchLow;
  8404. USHORT HorizontalBackPorch;
  8405. USHORT HorizontalBackPorchHigh;
  8406. USHORT HorizontalFrontPorchLow;
  8407. USHORT HorizontalFrontPorch;
  8408. USHORT HorizontalFrontPorchHigh;
  8409. USHORT HorizontalSyncLow;
  8410. USHORT HorizontalSync;
  8411. USHORT HorizontalSyncHigh;
  8412. USHORT VerticalBackPorchLow;
  8413. USHORT VerticalBackPorch;
  8414. USHORT VerticalBackPorchHigh;
  8415. USHORT VerticalFrontPorchLow;
  8416. USHORT VerticalFrontPorch;
  8417. USHORT VerticalFrontPorchHigh;
  8418. USHORT VerticalSyncLow;
  8419. USHORT VerticalSync;
  8420. USHORT VerticalSyncHigh;
  8421. } CM_MONITOR_DEVICE_DATA, *PCM_MONITOR_DEVICE_DATA;
  8422. //
  8423. // The device data record for the Floppy peripheral.
  8424. //
  8425. typedef struct _CM_FLOPPY_DEVICE_DATA {
  8426. USHORT Version;
  8427. USHORT Revision;
  8428. CHAR Size[8];
  8429. ULONG MaxDensity;
  8430. ULONG MountDensity;
  8431. //
  8432. // New data fields for version >= 2.0
  8433. //
  8434. UCHAR StepRateHeadUnloadTime;
  8435. UCHAR HeadLoadTime;
  8436. UCHAR MotorOffTime;
  8437. UCHAR SectorLengthCode;
  8438. UCHAR SectorPerTrack;
  8439. UCHAR ReadWriteGapLength;
  8440. UCHAR DataTransferLength;
  8441. UCHAR FormatGapLength;
  8442. UCHAR FormatFillCharacter;
  8443. UCHAR HeadSettleTime;
  8444. UCHAR MotorSettleTime;
  8445. UCHAR MaximumTrackValue;
  8446. UCHAR DataTransferRate;
  8447. } CM_FLOPPY_DEVICE_DATA, *PCM_FLOPPY_DEVICE_DATA;
  8448. //
  8449. // The device data record for the Keyboard peripheral.
  8450. // The KeyboardFlags is defined (by x86 BIOS INT 16h, function 02) as:
  8451. // bit 7 : Insert on
  8452. // bit 6 : Caps Lock on
  8453. // bit 5 : Num Lock on
  8454. // bit 4 : Scroll Lock on
  8455. // bit 3 : Alt Key is down
  8456. // bit 2 : Ctrl Key is down
  8457. // bit 1 : Left shift key is down
  8458. // bit 0 : Right shift key is down
  8459. //
  8460. typedef struct _CM_KEYBOARD_DEVICE_DATA {
  8461. USHORT Version;
  8462. USHORT Revision;
  8463. UCHAR Type;
  8464. UCHAR Subtype;
  8465. USHORT KeyboardFlags;
  8466. } CM_KEYBOARD_DEVICE_DATA, *PCM_KEYBOARD_DEVICE_DATA;
  8467. //
  8468. // Declaration of the structure for disk geometries
  8469. //
  8470. typedef struct _CM_DISK_GEOMETRY_DEVICE_DATA {
  8471. ULONG BytesPerSector;
  8472. ULONG NumberOfCylinders;
  8473. ULONG SectorsPerTrack;
  8474. ULONG NumberOfHeads;
  8475. } CM_DISK_GEOMETRY_DEVICE_DATA, *PCM_DISK_GEOMETRY_DEVICE_DATA;
  8476. // end_wdm
  8477. //
  8478. // Declaration of the structure for the PcCard ISA IRQ map
  8479. //
  8480. typedef struct _CM_PCCARD_DEVICE_DATA {
  8481. UCHAR Flags;
  8482. UCHAR ErrorCode;
  8483. USHORT Reserved;
  8484. ULONG BusData;
  8485. ULONG DeviceId;
  8486. ULONG LegacyBaseAddress;
  8487. UCHAR IRQMap[16];
  8488. } CM_PCCARD_DEVICE_DATA, *PCM_PCCARD_DEVICE_DATA;
  8489. // Definitions for Flags
  8490. #define PCCARD_MAP_ERROR 0x01
  8491. #define PCCARD_DEVICE_PCI 0x10
  8492. #define PCCARD_SCAN_DISABLED 0x01
  8493. #define PCCARD_MAP_ZERO 0x02
  8494. #define PCCARD_NO_TIMER 0x03
  8495. #define PCCARD_NO_PIC 0x04
  8496. #define PCCARD_NO_LEGACY_BASE 0x05
  8497. #define PCCARD_DUP_LEGACY_BASE 0x06
  8498. #define PCCARD_NO_CONTROLLERS 0x07
  8499. // begin_wdm
  8500. // begin_ntminiport
  8501. //
  8502. // Defines Resource Options
  8503. //
  8504. #define IO_RESOURCE_PREFERRED 0x01
  8505. #define IO_RESOURCE_DEFAULT 0x02
  8506. #define IO_RESOURCE_ALTERNATIVE 0x08
  8507. //
  8508. // This structure defines one type of resource requested by the driver
  8509. //
  8510. typedef struct _IO_RESOURCE_DESCRIPTOR {
  8511. UCHAR Option;
  8512. UCHAR Type; // use CM_RESOURCE_TYPE
  8513. UCHAR ShareDisposition; // use CM_SHARE_DISPOSITION
  8514. UCHAR Spare1;
  8515. USHORT Flags; // use CM resource flag defines
  8516. USHORT Spare2; // align
  8517. union {
  8518. struct {
  8519. ULONG Length;
  8520. ULONG Alignment;
  8521. PHYSICAL_ADDRESS MinimumAddress;
  8522. PHYSICAL_ADDRESS MaximumAddress;
  8523. } Port;
  8524. struct {
  8525. ULONG Length;
  8526. ULONG Alignment;
  8527. PHYSICAL_ADDRESS MinimumAddress;
  8528. PHYSICAL_ADDRESS MaximumAddress;
  8529. } Memory;
  8530. struct {
  8531. ULONG MinimumVector;
  8532. ULONG MaximumVector;
  8533. } Interrupt;
  8534. struct {
  8535. ULONG MinimumChannel;
  8536. ULONG MaximumChannel;
  8537. } Dma;
  8538. struct {
  8539. ULONG Length;
  8540. ULONG Alignment;
  8541. PHYSICAL_ADDRESS MinimumAddress;
  8542. PHYSICAL_ADDRESS MaximumAddress;
  8543. } Generic;
  8544. struct {
  8545. ULONG Data[3];
  8546. } DevicePrivate;
  8547. //
  8548. // Bus Number information.
  8549. //
  8550. struct {
  8551. ULONG Length;
  8552. ULONG MinBusNumber;
  8553. ULONG MaxBusNumber;
  8554. ULONG Reserved;
  8555. } BusNumber;
  8556. struct {
  8557. ULONG Priority; // use LCPRI_Xxx values in cfg.h
  8558. ULONG Reserved1;
  8559. ULONG Reserved2;
  8560. } ConfigData;
  8561. } u;
  8562. } IO_RESOURCE_DESCRIPTOR, *PIO_RESOURCE_DESCRIPTOR;
  8563. // end_ntminiport
  8564. typedef struct _IO_RESOURCE_LIST {
  8565. USHORT Version;
  8566. USHORT Revision;
  8567. ULONG Count;
  8568. IO_RESOURCE_DESCRIPTOR Descriptors[1];
  8569. } IO_RESOURCE_LIST, *PIO_RESOURCE_LIST;
  8570. typedef struct _IO_RESOURCE_REQUIREMENTS_LIST {
  8571. ULONG ListSize;
  8572. INTERFACE_TYPE InterfaceType; // unused for WDM
  8573. ULONG BusNumber; // unused for WDM
  8574. ULONG SlotNumber;
  8575. ULONG Reserved[3];
  8576. ULONG AlternativeLists;
  8577. IO_RESOURCE_LIST List[1];
  8578. } IO_RESOURCE_REQUIREMENTS_LIST, *PIO_RESOURCE_REQUIREMENTS_LIST;
  8579. //
  8580. // Exception flag definitions.
  8581. //
  8582. // begin_winnt
  8583. #define EXCEPTION_NONCONTINUABLE 0x1 // Noncontinuable exception
  8584. // end_winnt
  8585. //
  8586. // Define maximum number of exception parameters.
  8587. //
  8588. // begin_winnt
  8589. #define EXCEPTION_MAXIMUM_PARAMETERS 15 // maximum number of exception parameters
  8590. //
  8591. // Exception record definition.
  8592. //
  8593. typedef struct _EXCEPTION_RECORD {
  8594. NTSTATUS ExceptionCode;
  8595. ULONG ExceptionFlags;
  8596. struct _EXCEPTION_RECORD *ExceptionRecord;
  8597. PVOID ExceptionAddress;
  8598. ULONG NumberParameters;
  8599. ULONG_PTR ExceptionInformation[EXCEPTION_MAXIMUM_PARAMETERS];
  8600. } EXCEPTION_RECORD;
  8601. typedef EXCEPTION_RECORD *PEXCEPTION_RECORD;
  8602. typedef struct _EXCEPTION_RECORD32 {
  8603. NTSTATUS ExceptionCode;
  8604. ULONG ExceptionFlags;
  8605. ULONG ExceptionRecord;
  8606. ULONG ExceptionAddress;
  8607. ULONG NumberParameters;
  8608. ULONG ExceptionInformation[EXCEPTION_MAXIMUM_PARAMETERS];
  8609. } EXCEPTION_RECORD32, *PEXCEPTION_RECORD32;
  8610. typedef struct _EXCEPTION_RECORD64 {
  8611. NTSTATUS ExceptionCode;
  8612. ULONG ExceptionFlags;
  8613. ULONG64 ExceptionRecord;
  8614. ULONG64 ExceptionAddress;
  8615. ULONG NumberParameters;
  8616. ULONG __unusedAlignment;
  8617. ULONG64 ExceptionInformation[EXCEPTION_MAXIMUM_PARAMETERS];
  8618. } EXCEPTION_RECORD64, *PEXCEPTION_RECORD64;
  8619. //
  8620. // Typedef for pointer returned by exception_info()
  8621. //
  8622. typedef struct _EXCEPTION_POINTERS {
  8623. PEXCEPTION_RECORD ExceptionRecord;
  8624. PCONTEXT ContextRecord;
  8625. } EXCEPTION_POINTERS, *PEXCEPTION_POINTERS;
  8626. // end_winnt
  8627. //
  8628. // Define configuration routine types.
  8629. //
  8630. // Configuration information.
  8631. //
  8632. typedef enum _CONFIGURATION_TYPE {
  8633. ArcSystem,
  8634. CentralProcessor,
  8635. FloatingPointProcessor,
  8636. PrimaryIcache,
  8637. PrimaryDcache,
  8638. SecondaryIcache,
  8639. SecondaryDcache,
  8640. SecondaryCache,
  8641. EisaAdapter,
  8642. TcAdapter,
  8643. ScsiAdapter,
  8644. DtiAdapter,
  8645. MultiFunctionAdapter,
  8646. DiskController,
  8647. TapeController,
  8648. CdromController,
  8649. WormController,
  8650. SerialController,
  8651. NetworkController,
  8652. DisplayController,
  8653. ParallelController,
  8654. PointerController,
  8655. KeyboardController,
  8656. AudioController,
  8657. OtherController,
  8658. DiskPeripheral,
  8659. FloppyDiskPeripheral,
  8660. TapePeripheral,
  8661. ModemPeripheral,
  8662. MonitorPeripheral,
  8663. PrinterPeripheral,
  8664. PointerPeripheral,
  8665. KeyboardPeripheral,
  8666. TerminalPeripheral,
  8667. OtherPeripheral,
  8668. LinePeripheral,
  8669. NetworkPeripheral,
  8670. SystemMemory,
  8671. DockingInformation,
  8672. RealModeIrqRoutingTable,
  8673. RealModePCIEnumeration,
  8674. MaximumType
  8675. } CONFIGURATION_TYPE, *PCONFIGURATION_TYPE;
  8676. #define THREAD_WAIT_OBJECTS 3 // Builtin usable wait blocks
  8677. //
  8678. #if defined(_X86_)
  8679. #define PAUSE_PROCESSOR _asm { rep nop }
  8680. #else
  8681. #define PAUSE_PROCESSOR
  8682. #endif
  8683. //
  8684. // Interrupt modes.
  8685. //
  8686. typedef enum _KINTERRUPT_MODE {
  8687. LevelSensitive,
  8688. Latched
  8689. } KINTERRUPT_MODE;
  8690. //
  8691. // Wait reasons
  8692. //
  8693. typedef enum _KWAIT_REASON {
  8694. Executive,
  8695. FreePage,
  8696. PageIn,
  8697. PoolAllocation,
  8698. DelayExecution,
  8699. Suspended,
  8700. UserRequest,
  8701. WrExecutive,
  8702. WrFreePage,
  8703. WrPageIn,
  8704. WrPoolAllocation,
  8705. WrDelayExecution,
  8706. WrSuspended,
  8707. WrUserRequest,
  8708. WrEventPair,
  8709. WrQueue,
  8710. WrLpcReceive,
  8711. WrLpcReply,
  8712. WrVirtualMemory,
  8713. WrPageOut,
  8714. WrRendezvous,
  8715. Spare2,
  8716. Spare3,
  8717. Spare4,
  8718. Spare5,
  8719. Spare6,
  8720. WrKernel,
  8721. MaximumWaitReason
  8722. } KWAIT_REASON;
  8723. typedef struct _KWAIT_BLOCK {
  8724. LIST_ENTRY WaitListEntry;
  8725. struct _KTHREAD *RESTRICTED_POINTER Thread;
  8726. PVOID Object;
  8727. struct _KWAIT_BLOCK *RESTRICTED_POINTER NextWaitBlock;
  8728. USHORT WaitKey;
  8729. USHORT WaitType;
  8730. } KWAIT_BLOCK, *PKWAIT_BLOCK, *RESTRICTED_POINTER PRKWAIT_BLOCK;
  8731. //
  8732. // Thread start function
  8733. //
  8734. typedef
  8735. VOID
  8736. (*PKSTART_ROUTINE) (
  8737. IN PVOID StartContext
  8738. );
  8739. //
  8740. // Kernel object structure definitions
  8741. //
  8742. //
  8743. // Device Queue object and entry
  8744. //
  8745. typedef struct _KDEVICE_QUEUE {
  8746. CSHORT Type;
  8747. CSHORT Size;
  8748. LIST_ENTRY DeviceListHead;
  8749. KSPIN_LOCK Lock;
  8750. BOOLEAN Busy;
  8751. } KDEVICE_QUEUE, *PKDEVICE_QUEUE, *RESTRICTED_POINTER PRKDEVICE_QUEUE;
  8752. typedef struct _KDEVICE_QUEUE_ENTRY {
  8753. LIST_ENTRY DeviceListEntry;
  8754. ULONG SortKey;
  8755. BOOLEAN Inserted;
  8756. } KDEVICE_QUEUE_ENTRY, *PKDEVICE_QUEUE_ENTRY, *RESTRICTED_POINTER PRKDEVICE_QUEUE_ENTRY;
  8757. //
  8758. // Define the interrupt service function type and the empty struct
  8759. // type.
  8760. //
  8761. typedef
  8762. BOOLEAN
  8763. (*PKSERVICE_ROUTINE) (
  8764. IN struct _KINTERRUPT *Interrupt,
  8765. IN PVOID ServiceContext
  8766. );
  8767. //
  8768. // Mutant object
  8769. //
  8770. typedef struct _KMUTANT {
  8771. DISPATCHER_HEADER Header;
  8772. LIST_ENTRY MutantListEntry;
  8773. struct _KTHREAD *RESTRICTED_POINTER OwnerThread;
  8774. BOOLEAN Abandoned;
  8775. UCHAR ApcDisable;
  8776. } KMUTANT, *PKMUTANT, *RESTRICTED_POINTER PRKMUTANT, KMUTEX, *PKMUTEX, *RESTRICTED_POINTER PRKMUTEX;
  8777. //
  8778. //
  8779. // Semaphore object
  8780. //
  8781. typedef struct _KSEMAPHORE {
  8782. DISPATCHER_HEADER Header;
  8783. LONG Limit;
  8784. } KSEMAPHORE, *PKSEMAPHORE, *RESTRICTED_POINTER PRKSEMAPHORE;
  8785. //
  8786. // DPC object
  8787. //
  8788. NTKERNELAPI
  8789. VOID
  8790. KeInitializeDpc (
  8791. IN PRKDPC Dpc,
  8792. IN PKDEFERRED_ROUTINE DeferredRoutine,
  8793. IN PVOID DeferredContext
  8794. );
  8795. NTKERNELAPI
  8796. BOOLEAN
  8797. KeInsertQueueDpc (
  8798. IN PRKDPC Dpc,
  8799. IN PVOID SystemArgument1,
  8800. IN PVOID SystemArgument2
  8801. );
  8802. NTKERNELAPI
  8803. BOOLEAN
  8804. KeRemoveQueueDpc (
  8805. IN PRKDPC Dpc
  8806. );
  8807. // end_wdm
  8808. NTKERNELAPI
  8809. VOID
  8810. KeSetImportanceDpc (
  8811. IN PRKDPC Dpc,
  8812. IN KDPC_IMPORTANCE Importance
  8813. );
  8814. NTKERNELAPI
  8815. VOID
  8816. KeSetTargetProcessorDpc (
  8817. IN PRKDPC Dpc,
  8818. IN CCHAR Number
  8819. );
  8820. // begin_wdm
  8821. NTKERNELAPI
  8822. VOID
  8823. KeFlushQueuedDpcs (
  8824. VOID
  8825. );
  8826. //
  8827. // Device queue object
  8828. //
  8829. NTKERNELAPI
  8830. VOID
  8831. KeInitializeDeviceQueue (
  8832. IN PKDEVICE_QUEUE DeviceQueue
  8833. );
  8834. NTKERNELAPI
  8835. BOOLEAN
  8836. KeInsertDeviceQueue (
  8837. IN PKDEVICE_QUEUE DeviceQueue,
  8838. IN PKDEVICE_QUEUE_ENTRY DeviceQueueEntry
  8839. );
  8840. NTKERNELAPI
  8841. BOOLEAN
  8842. KeInsertByKeyDeviceQueue (
  8843. IN PKDEVICE_QUEUE DeviceQueue,
  8844. IN PKDEVICE_QUEUE_ENTRY DeviceQueueEntry,
  8845. IN ULONG SortKey
  8846. );
  8847. NTKERNELAPI
  8848. PKDEVICE_QUEUE_ENTRY
  8849. KeRemoveDeviceQueue (
  8850. IN PKDEVICE_QUEUE DeviceQueue
  8851. );
  8852. NTKERNELAPI
  8853. PKDEVICE_QUEUE_ENTRY
  8854. KeRemoveByKeyDeviceQueue (
  8855. IN PKDEVICE_QUEUE DeviceQueue,
  8856. IN ULONG SortKey
  8857. );
  8858. NTKERNELAPI
  8859. PKDEVICE_QUEUE_ENTRY
  8860. KeRemoveByKeyDeviceQueueIfBusy (
  8861. IN PKDEVICE_QUEUE DeviceQueue,
  8862. IN ULONG SortKey
  8863. );
  8864. NTKERNELAPI
  8865. BOOLEAN
  8866. KeRemoveEntryDeviceQueue (
  8867. IN PKDEVICE_QUEUE DeviceQueue,
  8868. IN PKDEVICE_QUEUE_ENTRY DeviceQueueEntry
  8869. );
  8870. NTKERNELAPI
  8871. BOOLEAN
  8872. KeSynchronizeExecution (
  8873. IN PKINTERRUPT Interrupt,
  8874. IN PKSYNCHRONIZE_ROUTINE SynchronizeRoutine,
  8875. IN PVOID SynchronizeContext
  8876. );
  8877. NTKERNELAPI
  8878. KIRQL
  8879. KeAcquireInterruptSpinLock (
  8880. IN PKINTERRUPT Interrupt
  8881. );
  8882. NTKERNELAPI
  8883. VOID
  8884. KeReleaseInterruptSpinLock (
  8885. IN PKINTERRUPT Interrupt,
  8886. IN KIRQL OldIrql
  8887. );
  8888. //
  8889. // Kernel dispatcher object functions
  8890. //
  8891. // Event Object
  8892. //
  8893. NTKERNELAPI
  8894. VOID
  8895. KeInitializeEvent (
  8896. IN PRKEVENT Event,
  8897. IN EVENT_TYPE Type,
  8898. IN BOOLEAN State
  8899. );
  8900. NTKERNELAPI
  8901. VOID
  8902. KeClearEvent (
  8903. IN PRKEVENT Event
  8904. );
  8905. NTKERNELAPI
  8906. LONG
  8907. KePulseEvent (
  8908. IN PRKEVENT Event,
  8909. IN KPRIORITY Increment,
  8910. IN BOOLEAN Wait
  8911. );
  8912. NTKERNELAPI
  8913. LONG
  8914. KeReadStateEvent (
  8915. IN PRKEVENT Event
  8916. );
  8917. NTKERNELAPI
  8918. LONG
  8919. KeResetEvent (
  8920. IN PRKEVENT Event
  8921. );
  8922. NTKERNELAPI
  8923. LONG
  8924. KeSetEvent (
  8925. IN PRKEVENT Event,
  8926. IN KPRIORITY Increment,
  8927. IN BOOLEAN Wait
  8928. );
  8929. //
  8930. // Mutex object
  8931. //
  8932. NTKERNELAPI
  8933. VOID
  8934. KeInitializeMutex (
  8935. IN PRKMUTEX Mutex,
  8936. IN ULONG Level
  8937. );
  8938. NTKERNELAPI
  8939. LONG
  8940. KeReadStateMutex (
  8941. IN PRKMUTEX Mutex
  8942. );
  8943. NTKERNELAPI
  8944. LONG
  8945. KeReleaseMutex (
  8946. IN PRKMUTEX Mutex,
  8947. IN BOOLEAN Wait
  8948. );
  8949. //
  8950. // Semaphore object
  8951. //
  8952. NTKERNELAPI
  8953. VOID
  8954. KeInitializeSemaphore (
  8955. IN PRKSEMAPHORE Semaphore,
  8956. IN LONG Count,
  8957. IN LONG Limit
  8958. );
  8959. NTKERNELAPI
  8960. LONG
  8961. KeReadStateSemaphore (
  8962. IN PRKSEMAPHORE Semaphore
  8963. );
  8964. NTKERNELAPI
  8965. LONG
  8966. KeReleaseSemaphore (
  8967. IN PRKSEMAPHORE Semaphore,
  8968. IN KPRIORITY Increment,
  8969. IN LONG Adjustment,
  8970. IN BOOLEAN Wait
  8971. );
  8972. NTKERNELAPI
  8973. NTSTATUS
  8974. KeDelayExecutionThread (
  8975. IN KPROCESSOR_MODE WaitMode,
  8976. IN BOOLEAN Alertable,
  8977. IN PLARGE_INTEGER Interval
  8978. );
  8979. NTKERNELAPI
  8980. KPRIORITY
  8981. KeQueryPriorityThread (
  8982. IN PKTHREAD Thread
  8983. );
  8984. NTKERNELAPI
  8985. ULONG
  8986. KeQueryRuntimeThread (
  8987. IN PKTHREAD Thread,
  8988. OUT PULONG UserTime
  8989. );
  8990. NTKERNELAPI
  8991. LONG
  8992. KeSetBasePriorityThread (
  8993. IN PKTHREAD Thread,
  8994. IN LONG Increment
  8995. );
  8996. NTKERNELAPI
  8997. KPRIORITY
  8998. KeSetPriorityThread (
  8999. IN PKTHREAD Thread,
  9000. IN KPRIORITY Priority
  9001. );
  9002. #if ((defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_) ||defined(_NTHAL_)) && !defined(_NTSYSTEM_DRIVER_) || defined(_NTOSP_))
  9003. // begin_wdm
  9004. NTKERNELAPI
  9005. VOID
  9006. KeEnterCriticalRegion (
  9007. VOID
  9008. );
  9009. NTKERNELAPI
  9010. VOID
  9011. KeLeaveCriticalRegion (
  9012. VOID
  9013. );
  9014. NTKERNELAPI
  9015. BOOLEAN
  9016. KeAreApcsDisabled(
  9017. VOID
  9018. );
  9019. // end_wdm
  9020. #else
  9021. //++
  9022. //
  9023. // VOID
  9024. // KeEnterCriticalRegion (
  9025. // VOID
  9026. // )
  9027. //
  9028. //
  9029. // Routine Description:
  9030. //
  9031. // This function disables kernel APC's.
  9032. //
  9033. // N.B. The following code does not require any interlocks. There are
  9034. // two cases of interest: 1) On an MP system, the thread cannot
  9035. // be running on two processors as once, and 2) if the thread is
  9036. // is interrupted to deliver a kernel mode APC which also calls
  9037. // this routine, the values read and stored will stack and unstack
  9038. // properly.
  9039. //
  9040. // Arguments:
  9041. //
  9042. // None.
  9043. //
  9044. // Return Value:
  9045. //
  9046. // None.
  9047. //--
  9048. #define KeEnterCriticalRegion() KeGetCurrentThread()->KernelApcDisable -= 1
  9049. //++
  9050. //
  9051. // VOID
  9052. // KeEnterCriticalRegionThread (
  9053. // PKTHREAD CurrentThread
  9054. // )
  9055. //
  9056. //
  9057. // Routine Description:
  9058. //
  9059. // This function disables kernel APC's for the current thread only.
  9060. //
  9061. // N.B. The following code does not require any interlocks. There are
  9062. // two cases of interest: 1) On an MP system, the thread cannot
  9063. // be running on two processors as once, and 2) if the thread is
  9064. // is interrupted to deliver a kernel mode APC which also calls
  9065. // this routine, the values read and stored will stack and unstack
  9066. // properly.
  9067. //
  9068. // Arguments:
  9069. //
  9070. // CurrentThread - Current thread thats executing. This must be the
  9071. // current thread.
  9072. //
  9073. // Return Value:
  9074. //
  9075. // None.
  9076. //--
  9077. #define KeEnterCriticalRegionThread(CurrentThread) { \
  9078. ASSERT (CurrentThread == KeGetCurrentThread ()); \
  9079. (CurrentThread)->KernelApcDisable -= 1; \
  9080. }
  9081. //++
  9082. //
  9083. // VOID
  9084. // KeLeaveCriticalRegion (
  9085. // VOID
  9086. // )
  9087. //
  9088. //
  9089. // Routine Description:
  9090. //
  9091. // This function enables kernel APC's.
  9092. //
  9093. // N.B. The following code does not require any interlocks. There are
  9094. // two cases of interest: 1) On an MP system, the thread cannot
  9095. // be running on two processors as once, and 2) if the thread is
  9096. // is interrupted to deliver a kernel mode APC which also calls
  9097. // this routine, the values read and stored will stack and unstack
  9098. // properly.
  9099. //
  9100. // Arguments:
  9101. //
  9102. // None.
  9103. //
  9104. // Return Value:
  9105. //
  9106. // None.
  9107. //--
  9108. #define KeLeaveCriticalRegion() KiLeaveCriticalRegion()
  9109. //++
  9110. //
  9111. // VOID
  9112. // KeLeaveCriticalRegionThread (
  9113. // PKTHREAD CurrentThread
  9114. // )
  9115. //
  9116. //
  9117. // Routine Description:
  9118. //
  9119. // This function enables kernel APC's for the current thread.
  9120. //
  9121. // N.B. The following code does not require any interlocks. There are
  9122. // two cases of interest: 1) On an MP system, the thread cannot
  9123. // be running on two processors as once, and 2) if the thread is
  9124. // is interrupted to deliver a kernel mode APC which also calls
  9125. // this routine, the values read and stored will stack and unstack
  9126. // properly.
  9127. //
  9128. // Arguments:
  9129. //
  9130. // CurrentThread - Current thread thats executing. This must be the
  9131. // current thread.
  9132. //
  9133. // Return Value:
  9134. //
  9135. // None.
  9136. //--
  9137. #define KeLeaveCriticalRegionThread(CurrentThread) { \
  9138. ASSERT (CurrentThread == KeGetCurrentThread ()); \
  9139. KiLeaveCriticalRegionThread(CurrentThread); \
  9140. }
  9141. #define KeAreApcsDisabled() (KeGetCurrentThread()->KernelApcDisable != 0);
  9142. //++
  9143. //
  9144. // KPROCESSOR_MODE
  9145. // KeGetPReviousMode (
  9146. // VOID
  9147. // )
  9148. //
  9149. //
  9150. // Routine Description:
  9151. //
  9152. // This function gets the threads previous mode from the trap frame
  9153. //
  9154. //
  9155. // Arguments:
  9156. //
  9157. // None.
  9158. //
  9159. // Return Value:
  9160. //
  9161. // KPROCESSOR_MODE - Previous mode for this thread
  9162. //--
  9163. #define KeGetPreviousMode() (KeGetCurrentThread()->PreviousMode)
  9164. //++
  9165. //
  9166. // KPROCESSOR_MODE
  9167. // KeGetPReviousModeByThread (
  9168. // PKTHREAD xxCurrentThread
  9169. // )
  9170. //
  9171. //
  9172. // Routine Description:
  9173. //
  9174. // This function gets the threads previous mode from the trap frame.
  9175. //
  9176. //
  9177. // Arguments:
  9178. //
  9179. // xxCurrentThread - Current thread. This can not be a cross thread reference
  9180. //
  9181. // Return Value:
  9182. //
  9183. // KPROCESSOR_MODE - Previous mode for this thread
  9184. //--
  9185. #define KeGetPreviousModeByThread(xxCurrentThread) (ASSERT (xxCurrentThread == KeGetCurrentThread ()),\
  9186. (xxCurrentThread)->PreviousMode)
  9187. #endif
  9188. // begin_wdm
  9189. //
  9190. // Timer object
  9191. //
  9192. NTKERNELAPI
  9193. VOID
  9194. KeInitializeTimer (
  9195. IN PKTIMER Timer
  9196. );
  9197. NTKERNELAPI
  9198. VOID
  9199. KeInitializeTimerEx (
  9200. IN PKTIMER Timer,
  9201. IN TIMER_TYPE Type
  9202. );
  9203. NTKERNELAPI
  9204. BOOLEAN
  9205. KeCancelTimer (
  9206. IN PKTIMER
  9207. );
  9208. NTKERNELAPI
  9209. BOOLEAN
  9210. KeReadStateTimer (
  9211. PKTIMER Timer
  9212. );
  9213. NTKERNELAPI
  9214. BOOLEAN
  9215. KeSetTimer (
  9216. IN PKTIMER Timer,
  9217. IN LARGE_INTEGER DueTime,
  9218. IN PKDPC Dpc OPTIONAL
  9219. );
  9220. NTKERNELAPI
  9221. BOOLEAN
  9222. KeSetTimerEx (
  9223. IN PKTIMER Timer,
  9224. IN LARGE_INTEGER DueTime,
  9225. IN LONG Period OPTIONAL,
  9226. IN PKDPC Dpc OPTIONAL
  9227. );
  9228. #define KeWaitForMutexObject KeWaitForSingleObject
  9229. NTKERNELAPI
  9230. NTSTATUS
  9231. KeWaitForMultipleObjects (
  9232. IN ULONG Count,
  9233. IN PVOID Object[],
  9234. IN WAIT_TYPE WaitType,
  9235. IN KWAIT_REASON WaitReason,
  9236. IN KPROCESSOR_MODE WaitMode,
  9237. IN BOOLEAN Alertable,
  9238. IN PLARGE_INTEGER Timeout OPTIONAL,
  9239. IN PKWAIT_BLOCK WaitBlockArray OPTIONAL
  9240. );
  9241. NTKERNELAPI
  9242. NTSTATUS
  9243. KeWaitForSingleObject (
  9244. IN PVOID Object,
  9245. IN KWAIT_REASON WaitReason,
  9246. IN KPROCESSOR_MODE WaitMode,
  9247. IN BOOLEAN Alertable,
  9248. IN PLARGE_INTEGER Timeout OPTIONAL
  9249. );
  9250. //
  9251. // On X86 the following routines are defined in the HAL and imported by
  9252. // all other modules.
  9253. //
  9254. #if defined(_X86_) && !defined(_NTHAL_)
  9255. #define _DECL_HAL_KE_IMPORT __declspec(dllimport)
  9256. #else
  9257. #define _DECL_HAL_KE_IMPORT
  9258. #endif
  9259. //
  9260. // spin lock functions
  9261. //
  9262. NTKERNELAPI
  9263. VOID
  9264. NTAPI
  9265. KeInitializeSpinLock (
  9266. IN PKSPIN_LOCK SpinLock
  9267. );
  9268. #if defined(_X86_)
  9269. NTKERNELAPI
  9270. VOID
  9271. FASTCALL
  9272. KefAcquireSpinLockAtDpcLevel (
  9273. IN PKSPIN_LOCK SpinLock
  9274. );
  9275. NTKERNELAPI
  9276. VOID
  9277. FASTCALL
  9278. KefReleaseSpinLockFromDpcLevel (
  9279. IN PKSPIN_LOCK SpinLock
  9280. );
  9281. #define KeAcquireSpinLockAtDpcLevel(a) KefAcquireSpinLockAtDpcLevel(a)
  9282. #define KeReleaseSpinLockFromDpcLevel(a) KefReleaseSpinLockFromDpcLevel(a)
  9283. _DECL_HAL_KE_IMPORT
  9284. KIRQL
  9285. FASTCALL
  9286. KfAcquireSpinLock (
  9287. IN PKSPIN_LOCK SpinLock
  9288. );
  9289. _DECL_HAL_KE_IMPORT
  9290. VOID
  9291. FASTCALL
  9292. KfReleaseSpinLock (
  9293. IN PKSPIN_LOCK SpinLock,
  9294. IN KIRQL NewIrql
  9295. );
  9296. // end_wdm
  9297. _DECL_HAL_KE_IMPORT
  9298. KIRQL
  9299. FASTCALL
  9300. KeAcquireSpinLockRaiseToSynch (
  9301. IN PKSPIN_LOCK SpinLock
  9302. );
  9303. // begin_wdm
  9304. #define KeAcquireSpinLock(a,b) *(b) = KfAcquireSpinLock(a)
  9305. #define KeReleaseSpinLock(a,b) KfReleaseSpinLock(a,b)
  9306. #else
  9307. NTKERNELAPI
  9308. KIRQL
  9309. FASTCALL
  9310. KeAcquireSpinLockRaiseToSynch (
  9311. IN PKSPIN_LOCK SpinLock
  9312. );
  9313. NTKERNELAPI
  9314. VOID
  9315. KeAcquireSpinLockAtDpcLevel (
  9316. IN PKSPIN_LOCK SpinLock
  9317. );
  9318. NTKERNELAPI
  9319. VOID
  9320. KeReleaseSpinLockFromDpcLevel (
  9321. IN PKSPIN_LOCK SpinLock
  9322. );
  9323. NTKERNELAPI
  9324. KIRQL
  9325. KeAcquireSpinLockRaiseToDpc (
  9326. IN PKSPIN_LOCK SpinLock
  9327. );
  9328. #define KeAcquireSpinLock(SpinLock, OldIrql) \
  9329. *(OldIrql) = KeAcquireSpinLockRaiseToDpc(SpinLock)
  9330. NTKERNELAPI
  9331. VOID
  9332. KeReleaseSpinLock (
  9333. IN PKSPIN_LOCK SpinLock,
  9334. IN KIRQL NewIrql
  9335. );
  9336. #endif
  9337. NTKERNELAPI
  9338. BOOLEAN
  9339. FASTCALL
  9340. KeTryToAcquireSpinLockAtDpcLevel (
  9341. IN PKSPIN_LOCK SpinLock
  9342. );
  9343. #if defined(_X86_)
  9344. _DECL_HAL_KE_IMPORT
  9345. VOID
  9346. FASTCALL
  9347. KfLowerIrql (
  9348. IN KIRQL NewIrql
  9349. );
  9350. _DECL_HAL_KE_IMPORT
  9351. KIRQL
  9352. FASTCALL
  9353. KfRaiseIrql (
  9354. IN KIRQL NewIrql
  9355. );
  9356. // end_wdm
  9357. _DECL_HAL_KE_IMPORT
  9358. KIRQL
  9359. KeRaiseIrqlToDpcLevel(
  9360. VOID
  9361. );
  9362. _DECL_HAL_KE_IMPORT
  9363. KIRQL
  9364. KeRaiseIrqlToSynchLevel(
  9365. VOID
  9366. );
  9367. // begin_wdm
  9368. #define KeLowerIrql(a) KfLowerIrql(a)
  9369. #define KeRaiseIrql(a,b) *(b) = KfRaiseIrql(a)
  9370. // end_wdm
  9371. // begin_wdm
  9372. #elif defined(_ALPHA_)
  9373. #define KeLowerIrql(a) __swpirql(a)
  9374. #define KeRaiseIrql(a,b) *(b) = __swpirql(a)
  9375. // end_wdm
  9376. extern ULONG KiSynchIrql;
  9377. #define KfRaiseIrql(a) __swpirql(a)
  9378. #define KeRaiseIrqlToDpcLevel() __swpirql(DISPATCH_LEVEL)
  9379. #define KeRaiseIrqlToSynchLevel() __swpirql((UCHAR)KiSynchIrql)
  9380. // begin_wdm
  9381. #elif defined(_IA64_)
  9382. VOID
  9383. KeLowerIrql (
  9384. IN KIRQL NewIrql
  9385. );
  9386. VOID
  9387. KeRaiseIrql (
  9388. IN KIRQL NewIrql,
  9389. OUT PKIRQL OldIrql
  9390. );
  9391. // end_wdm
  9392. KIRQL
  9393. KfRaiseIrql (
  9394. IN KIRQL NewIrql
  9395. );
  9396. KIRQL
  9397. KeRaiseIrqlToDpcLevel (
  9398. VOID
  9399. );
  9400. KIRQL
  9401. KeRaiseIrqlToSynchLevel (
  9402. VOID
  9403. );
  9404. // begin_wdm
  9405. #elif defined(_AMD64_)
  9406. //
  9407. // These function are defined in amd64.h for the AMD64 platform.
  9408. //
  9409. #else
  9410. #error "no target architecture"
  9411. #endif
  9412. //
  9413. // Queued spin lock functions for "in stack" lock handles.
  9414. //
  9415. // The following three functions RAISE and LOWER IRQL when a queued
  9416. // in stack spin lock is acquired or released using these routines.
  9417. //
  9418. _DECL_HAL_KE_IMPORT
  9419. VOID
  9420. FASTCALL
  9421. KeAcquireInStackQueuedSpinLock (
  9422. IN PKSPIN_LOCK SpinLock,
  9423. IN PKLOCK_QUEUE_HANDLE LockHandle
  9424. );
  9425. _DECL_HAL_KE_IMPORT
  9426. VOID
  9427. FASTCALL
  9428. KeReleaseInStackQueuedSpinLock (
  9429. IN PKLOCK_QUEUE_HANDLE LockHandle
  9430. );
  9431. //
  9432. // The following two functions do NOT raise or lower IRQL when a queued
  9433. // in stack spin lock is acquired or released using these functions.
  9434. //
  9435. NTKERNELAPI
  9436. VOID
  9437. FASTCALL
  9438. KeAcquireInStackQueuedSpinLockAtDpcLevel (
  9439. IN PKSPIN_LOCK SpinLock,
  9440. IN PKLOCK_QUEUE_HANDLE LockHandle
  9441. );
  9442. NTKERNELAPI
  9443. VOID
  9444. FASTCALL
  9445. KeReleaseInStackQueuedSpinLockFromDpcLevel (
  9446. IN PKLOCK_QUEUE_HANDLE LockHandle
  9447. );
  9448. //
  9449. // Miscellaneous kernel functions
  9450. //
  9451. typedef enum _KBUGCHECK_BUFFER_DUMP_STATE {
  9452. BufferEmpty,
  9453. BufferInserted,
  9454. BufferStarted,
  9455. BufferFinished,
  9456. BufferIncomplete
  9457. } KBUGCHECK_BUFFER_DUMP_STATE;
  9458. typedef
  9459. VOID
  9460. (*PKBUGCHECK_CALLBACK_ROUTINE) (
  9461. IN PVOID Buffer,
  9462. IN ULONG Length
  9463. );
  9464. typedef struct _KBUGCHECK_CALLBACK_RECORD {
  9465. LIST_ENTRY Entry;
  9466. PKBUGCHECK_CALLBACK_ROUTINE CallbackRoutine;
  9467. PVOID Buffer;
  9468. ULONG Length;
  9469. PUCHAR Component;
  9470. ULONG_PTR Checksum;
  9471. UCHAR State;
  9472. } KBUGCHECK_CALLBACK_RECORD, *PKBUGCHECK_CALLBACK_RECORD;
  9473. #define KeInitializeCallbackRecord(CallbackRecord) \
  9474. (CallbackRecord)->State = BufferEmpty
  9475. NTKERNELAPI
  9476. BOOLEAN
  9477. KeDeregisterBugCheckCallback (
  9478. IN PKBUGCHECK_CALLBACK_RECORD CallbackRecord
  9479. );
  9480. NTKERNELAPI
  9481. BOOLEAN
  9482. KeRegisterBugCheckCallback (
  9483. IN PKBUGCHECK_CALLBACK_RECORD CallbackRecord,
  9484. IN PKBUGCHECK_CALLBACK_ROUTINE CallbackRoutine,
  9485. IN PVOID Buffer,
  9486. IN ULONG Length,
  9487. IN PUCHAR Component
  9488. );
  9489. typedef enum _KBUGCHECK_CALLBACK_REASON {
  9490. KbCallbackInvalid,
  9491. KbCallbackReserved1,
  9492. KbCallbackSecondaryDumpData,
  9493. KbCallbackDumpIo,
  9494. } KBUGCHECK_CALLBACK_REASON;
  9495. typedef
  9496. VOID
  9497. (*PKBUGCHECK_REASON_CALLBACK_ROUTINE) (
  9498. IN KBUGCHECK_CALLBACK_REASON Reason,
  9499. IN struct _KBUGCHECK_REASON_CALLBACK_RECORD* Record,
  9500. IN OUT PVOID ReasonSpecificData,
  9501. IN ULONG ReasonSpecificDataLength
  9502. );
  9503. typedef struct _KBUGCHECK_REASON_CALLBACK_RECORD {
  9504. LIST_ENTRY Entry;
  9505. PKBUGCHECK_REASON_CALLBACK_ROUTINE CallbackRoutine;
  9506. PUCHAR Component;
  9507. ULONG_PTR Checksum;
  9508. KBUGCHECK_CALLBACK_REASON Reason;
  9509. UCHAR State;
  9510. } KBUGCHECK_REASON_CALLBACK_RECORD, *PKBUGCHECK_REASON_CALLBACK_RECORD;
  9511. typedef struct _KBUGCHECK_SECONDARY_DUMP_DATA {
  9512. IN PVOID InBuffer;
  9513. IN ULONG InBufferLength;
  9514. IN ULONG MaximumAllowed;
  9515. OUT GUID Guid;
  9516. OUT PVOID OutBuffer;
  9517. OUT ULONG OutBufferLength;
  9518. } KBUGCHECK_SECONDARY_DUMP_DATA, *PKBUGCHECK_SECONDARY_DUMP_DATA;
  9519. typedef enum _KBUGCHECK_DUMP_IO_TYPE
  9520. {
  9521. KbDumpIoInvalid,
  9522. KbDumpIoHeader,
  9523. KbDumpIoBody,
  9524. KbDumpIoSecondaryData,
  9525. KbDumpIoComplete
  9526. } KBUGCHECK_DUMP_IO_TYPE;
  9527. typedef struct _KBUGCHECK_DUMP_IO {
  9528. IN ULONG64 Offset;
  9529. IN PVOID Buffer;
  9530. IN ULONG BufferLength;
  9531. IN KBUGCHECK_DUMP_IO_TYPE Type;
  9532. } KBUGCHECK_DUMP_IO, *PKBUGCHECK_DUMP_IO;
  9533. NTKERNELAPI
  9534. BOOLEAN
  9535. KeDeregisterBugCheckReasonCallback (
  9536. IN PKBUGCHECK_REASON_CALLBACK_RECORD CallbackRecord
  9537. );
  9538. NTKERNELAPI
  9539. BOOLEAN
  9540. KeRegisterBugCheckReasonCallback (
  9541. IN PKBUGCHECK_REASON_CALLBACK_RECORD CallbackRecord,
  9542. IN PKBUGCHECK_REASON_CALLBACK_ROUTINE CallbackRoutine,
  9543. IN KBUGCHECK_CALLBACK_REASON Reason,
  9544. IN PUCHAR Component
  9545. );
  9546. // end_wdm
  9547. NTKERNELAPI
  9548. DECLSPEC_NORETURN
  9549. VOID
  9550. NTAPI
  9551. KeBugCheck (
  9552. IN ULONG BugCheckCode
  9553. );
  9554. NTKERNELAPI
  9555. DECLSPEC_NORETURN
  9556. VOID
  9557. KeBugCheckEx(
  9558. IN ULONG BugCheckCode,
  9559. IN ULONG_PTR BugCheckParameter1,
  9560. IN ULONG_PTR BugCheckParameter2,
  9561. IN ULONG_PTR BugCheckParameter3,
  9562. IN ULONG_PTR BugCheckParameter4
  9563. );
  9564. NTKERNELAPI
  9565. ULONGLONG
  9566. KeQueryInterruptTime (
  9567. VOID
  9568. );
  9569. NTKERNELAPI
  9570. VOID
  9571. KeQuerySystemTime (
  9572. OUT PLARGE_INTEGER CurrentTime
  9573. );
  9574. NTKERNELAPI
  9575. ULONG
  9576. KeQueryTimeIncrement (
  9577. VOID
  9578. );
  9579. NTKERNELAPI
  9580. ULONG
  9581. KeGetRecommendedSharedDataAlignment (
  9582. VOID
  9583. );
  9584. // end_wdm
  9585. NTKERNELAPI
  9586. KAFFINITY
  9587. KeQueryActiveProcessors (
  9588. VOID
  9589. );
  9590. //
  9591. // Time update notify routine.
  9592. //
  9593. typedef
  9594. VOID
  9595. (FASTCALL *PTIME_UPDATE_NOTIFY_ROUTINE)(
  9596. IN HANDLE ThreadId,
  9597. IN KPROCESSOR_MODE Mode
  9598. );
  9599. NTKERNELAPI
  9600. VOID
  9601. FASTCALL
  9602. KeSetTimeUpdateNotifyRoutine(
  9603. IN PTIME_UPDATE_NOTIFY_ROUTINE NotifyRoutine
  9604. );
  9605. #if defined(_AMD64_) || defined(_ALPHA_) || defined(_IA64_)
  9606. extern volatile LARGE_INTEGER KeTickCount;
  9607. #else
  9608. extern volatile KSYSTEM_TIME KeTickCount;
  9609. #endif
  9610. typedef enum _MEMORY_CACHING_TYPE_ORIG {
  9611. MmFrameBufferCached = 2
  9612. } MEMORY_CACHING_TYPE_ORIG;
  9613. typedef enum _MEMORY_CACHING_TYPE {
  9614. MmNonCached = FALSE,
  9615. MmCached = TRUE,
  9616. MmWriteCombined = MmFrameBufferCached,
  9617. MmHardwareCoherentCached,
  9618. MmNonCachedUnordered, // IA64
  9619. MmUSWCCached,
  9620. MmMaximumCacheType
  9621. } MEMORY_CACHING_TYPE;
  9622. //
  9623. // Define external data.
  9624. // because of indirection for all drivers external to ntoskrnl these are actually ptrs
  9625. //
  9626. #if defined(_NTDDK_) || defined(_NTIFS_) || defined(_NTHAL_) || defined(_WDMDDK_) || defined(_NTOSP_)
  9627. extern PBOOLEAN KdDebuggerNotPresent;
  9628. extern PBOOLEAN KdDebuggerEnabled;
  9629. #define KD_DEBUGGER_ENABLED *KdDebuggerEnabled
  9630. #define KD_DEBUGGER_NOT_PRESENT *KdDebuggerNotPresent
  9631. #else
  9632. extern BOOLEAN KdDebuggerNotPresent;
  9633. extern BOOLEAN KdDebuggerEnabled;
  9634. #define KD_DEBUGGER_ENABLED KdDebuggerEnabled
  9635. #define KD_DEBUGGER_NOT_PRESENT KdDebuggerNotPresent
  9636. #endif
  9637. VOID
  9638. KdDisableDebugger(
  9639. VOID
  9640. );
  9641. VOID
  9642. KdEnableDebugger(
  9643. VOID
  9644. );
  9645. //
  9646. // Pool Allocation routines (in pool.c)
  9647. //
  9648. typedef enum _POOL_TYPE {
  9649. NonPagedPool,
  9650. PagedPool,
  9651. NonPagedPoolMustSucceed,
  9652. DontUseThisType,
  9653. NonPagedPoolCacheAligned,
  9654. PagedPoolCacheAligned,
  9655. NonPagedPoolCacheAlignedMustS,
  9656. MaxPoolType
  9657. // end_wdm
  9658. ,
  9659. //
  9660. // Note these per session types are carefully chosen so that the appropriate
  9661. // masking still applies as well as MaxPoolType above.
  9662. //
  9663. NonPagedPoolSession = 32,
  9664. PagedPoolSession = NonPagedPoolSession + 1,
  9665. NonPagedPoolMustSucceedSession = PagedPoolSession + 1,
  9666. DontUseThisTypeSession = NonPagedPoolMustSucceedSession + 1,
  9667. NonPagedPoolCacheAlignedSession = DontUseThisTypeSession + 1,
  9668. PagedPoolCacheAlignedSession = NonPagedPoolCacheAlignedSession + 1,
  9669. NonPagedPoolCacheAlignedMustSSession = PagedPoolCacheAlignedSession + 1,
  9670. // begin_wdm
  9671. } POOL_TYPE;
  9672. #define POOL_COLD_ALLOCATION 256 // Note this cannot encode into the header.
  9673. NTKERNELAPI
  9674. PVOID
  9675. ExAllocatePool(
  9676. IN POOL_TYPE PoolType,
  9677. IN SIZE_T NumberOfBytes
  9678. );
  9679. NTKERNELAPI
  9680. PVOID
  9681. ExAllocatePoolWithQuota(
  9682. IN POOL_TYPE PoolType,
  9683. IN SIZE_T NumberOfBytes
  9684. );
  9685. NTKERNELAPI
  9686. PVOID
  9687. NTAPI
  9688. ExAllocatePoolWithTag(
  9689. IN POOL_TYPE PoolType,
  9690. IN SIZE_T NumberOfBytes,
  9691. IN ULONG Tag
  9692. );
  9693. //
  9694. // _EX_POOL_PRIORITY_ provides a method for the system to handle requests
  9695. // intelligently in low resource conditions.
  9696. //
  9697. // LowPoolPriority should be used when it is acceptable to the driver for the
  9698. // mapping request to fail if the system is low on resources. An example of
  9699. // this could be for a non-critical network connection where the driver can
  9700. // handle the failure case when system resources are close to being depleted.
  9701. //
  9702. // NormalPoolPriority should be used when it is acceptable to the driver for the
  9703. // mapping request to fail if the system is very low on resources. An example
  9704. // of this could be for a non-critical local filesystem request.
  9705. //
  9706. // HighPoolPriority should be used when it is unacceptable to the driver for the
  9707. // mapping request to fail unless the system is completely out of resources.
  9708. // An example of this would be the paging file path in a driver.
  9709. //
  9710. // SpecialPool can be specified to bound the allocation at a page end (or
  9711. // beginning). This should only be done on systems being debugged as the
  9712. // memory cost is expensive.
  9713. //
  9714. // N.B. These values are very carefully chosen so that the pool allocation
  9715. // code can quickly crack the priority request.
  9716. //
  9717. typedef enum _EX_POOL_PRIORITY {
  9718. LowPoolPriority,
  9719. LowPoolPrioritySpecialPoolOverrun = 8,
  9720. LowPoolPrioritySpecialPoolUnderrun = 9,
  9721. NormalPoolPriority = 16,
  9722. NormalPoolPrioritySpecialPoolOverrun = 24,
  9723. NormalPoolPrioritySpecialPoolUnderrun = 25,
  9724. HighPoolPriority = 32,
  9725. HighPoolPrioritySpecialPoolOverrun = 40,
  9726. HighPoolPrioritySpecialPoolUnderrun = 41
  9727. } EX_POOL_PRIORITY;
  9728. NTKERNELAPI
  9729. PVOID
  9730. NTAPI
  9731. ExAllocatePoolWithTagPriority(
  9732. IN POOL_TYPE PoolType,
  9733. IN SIZE_T NumberOfBytes,
  9734. IN ULONG Tag,
  9735. IN EX_POOL_PRIORITY Priority
  9736. );
  9737. #ifndef POOL_TAGGING
  9738. #define ExAllocatePoolWithTag(a,b,c) ExAllocatePool(a,b)
  9739. #endif //POOL_TAGGING
  9740. NTKERNELAPI
  9741. PVOID
  9742. ExAllocatePoolWithQuotaTag(
  9743. IN POOL_TYPE PoolType,
  9744. IN SIZE_T NumberOfBytes,
  9745. IN ULONG Tag
  9746. );
  9747. #ifndef POOL_TAGGING
  9748. #define ExAllocatePoolWithQuotaTag(a,b,c) ExAllocatePoolWithQuota(a,b)
  9749. #endif //POOL_TAGGING
  9750. NTKERNELAPI
  9751. VOID
  9752. NTAPI
  9753. ExFreePool(
  9754. IN PVOID P
  9755. );
  9756. // end_wdm
  9757. #if defined(POOL_TAGGING)
  9758. #define ExFreePool(a) ExFreePoolWithTag(a,0)
  9759. #endif
  9760. //
  9761. // If high order bit in Pool tag is set, then must use ExFreePoolWithTag to free
  9762. //
  9763. #define PROTECTED_POOL 0x80000000
  9764. // begin_wdm
  9765. NTKERNELAPI
  9766. VOID
  9767. ExFreePoolWithTag(
  9768. IN PVOID P,
  9769. IN ULONG Tag
  9770. );
  9771. //
  9772. // Routines to support fast mutexes.
  9773. //
  9774. typedef struct _FAST_MUTEX {
  9775. LONG Count;
  9776. PKTHREAD Owner;
  9777. ULONG Contention;
  9778. KEVENT Event;
  9779. ULONG OldIrql;
  9780. } FAST_MUTEX, *PFAST_MUTEX;
  9781. #define ExInitializeFastMutex(_FastMutex) \
  9782. (_FastMutex)->Count = 1; \
  9783. (_FastMutex)->Owner = NULL; \
  9784. (_FastMutex)->Contention = 0; \
  9785. KeInitializeEvent(&(_FastMutex)->Event, \
  9786. SynchronizationEvent, \
  9787. FALSE);
  9788. NTKERNELAPI
  9789. VOID
  9790. FASTCALL
  9791. ExAcquireFastMutexUnsafe (
  9792. IN PFAST_MUTEX FastMutex
  9793. );
  9794. NTKERNELAPI
  9795. VOID
  9796. FASTCALL
  9797. ExReleaseFastMutexUnsafe (
  9798. IN PFAST_MUTEX FastMutex
  9799. );
  9800. #if defined(_ALPHA_) || defined(_IA64_) || defined(_AMD64_)
  9801. NTKERNELAPI
  9802. VOID
  9803. FASTCALL
  9804. ExAcquireFastMutex (
  9805. IN PFAST_MUTEX FastMutex
  9806. );
  9807. NTKERNELAPI
  9808. VOID
  9809. FASTCALL
  9810. ExReleaseFastMutex (
  9811. IN PFAST_MUTEX FastMutex
  9812. );
  9813. NTKERNELAPI
  9814. BOOLEAN
  9815. FASTCALL
  9816. ExTryToAcquireFastMutex (
  9817. IN PFAST_MUTEX FastMutex
  9818. );
  9819. #elif defined(_X86_)
  9820. NTHALAPI
  9821. VOID
  9822. FASTCALL
  9823. ExAcquireFastMutex (
  9824. IN PFAST_MUTEX FastMutex
  9825. );
  9826. NTHALAPI
  9827. VOID
  9828. FASTCALL
  9829. ExReleaseFastMutex (
  9830. IN PFAST_MUTEX FastMutex
  9831. );
  9832. NTHALAPI
  9833. BOOLEAN
  9834. FASTCALL
  9835. ExTryToAcquireFastMutex (
  9836. IN PFAST_MUTEX FastMutex
  9837. );
  9838. #else
  9839. #error "Target architecture not defined"
  9840. #endif
  9841. //
  9842. NTKERNELAPI
  9843. VOID
  9844. FASTCALL
  9845. ExInterlockedAddLargeStatistic (
  9846. IN PLARGE_INTEGER Addend,
  9847. IN ULONG Increment
  9848. );
  9849. // end_ntndis
  9850. NTKERNELAPI
  9851. LARGE_INTEGER
  9852. ExInterlockedAddLargeInteger (
  9853. IN PLARGE_INTEGER Addend,
  9854. IN LARGE_INTEGER Increment,
  9855. IN PKSPIN_LOCK Lock
  9856. );
  9857. NTKERNELAPI
  9858. ULONG
  9859. FASTCALL
  9860. ExInterlockedAddUlong (
  9861. IN PULONG Addend,
  9862. IN ULONG Increment,
  9863. IN PKSPIN_LOCK Lock
  9864. );
  9865. #if defined(_AMD64_) || defined(_AXP64_) || defined(_IA64_)
  9866. #define ExInterlockedCompareExchange64(Destination, Exchange, Comperand, Lock) \
  9867. InterlockedCompareExchange64(Destination, *(Exchange), *(Comperand))
  9868. #elif defined(_ALPHA_)
  9869. #define ExInterlockedCompareExchange64(Destination, Exchange, Comperand, Lock) \
  9870. ExpInterlockedCompareExchange64(Destination, Exchange, Comperand)
  9871. #else
  9872. #define ExInterlockedCompareExchange64(Destination, Exchange, Comperand, Lock) \
  9873. ExfInterlockedCompareExchange64(Destination, Exchange, Comperand)
  9874. #endif
  9875. NTKERNELAPI
  9876. PLIST_ENTRY
  9877. FASTCALL
  9878. ExInterlockedInsertHeadList (
  9879. IN PLIST_ENTRY ListHead,
  9880. IN PLIST_ENTRY ListEntry,
  9881. IN PKSPIN_LOCK Lock
  9882. );
  9883. NTKERNELAPI
  9884. PLIST_ENTRY
  9885. FASTCALL
  9886. ExInterlockedInsertTailList (
  9887. IN PLIST_ENTRY ListHead,
  9888. IN PLIST_ENTRY ListEntry,
  9889. IN PKSPIN_LOCK Lock
  9890. );
  9891. NTKERNELAPI
  9892. PLIST_ENTRY
  9893. FASTCALL
  9894. ExInterlockedRemoveHeadList (
  9895. IN PLIST_ENTRY ListHead,
  9896. IN PKSPIN_LOCK Lock
  9897. );
  9898. NTKERNELAPI
  9899. PSINGLE_LIST_ENTRY
  9900. FASTCALL
  9901. ExInterlockedPopEntryList (
  9902. IN PSINGLE_LIST_ENTRY ListHead,
  9903. IN PKSPIN_LOCK Lock
  9904. );
  9905. NTKERNELAPI
  9906. PSINGLE_LIST_ENTRY
  9907. FASTCALL
  9908. ExInterlockedPushEntryList (
  9909. IN PSINGLE_LIST_ENTRY ListHead,
  9910. IN PSINGLE_LIST_ENTRY ListEntry,
  9911. IN PKSPIN_LOCK Lock
  9912. );
  9913. //
  9914. // Define interlocked sequenced listhead functions.
  9915. //
  9916. // A sequenced interlocked list is a singly linked list with a header that
  9917. // contains the current depth and a sequence number. Each time an entry is
  9918. // inserted or removed from the list the depth is updated and the sequence
  9919. // number is incremented. This enables AMD64, IA64, and Pentium and later
  9920. // machines to insert and remove from the list without the use of spinlocks.
  9921. //
  9922. #if !defined(_WINBASE_)
  9923. /*++
  9924. Routine Description:
  9925. This function initializes a sequenced singly linked listhead.
  9926. Arguments:
  9927. SListHead - Supplies a pointer to a sequenced singly linked listhead.
  9928. Return Value:
  9929. None.
  9930. --*/
  9931. #if defined(_WIN64) && (defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_) || defined(_NTHAL_) || defined(_NTOSP_))
  9932. NTKERNELAPI
  9933. VOID
  9934. InitializeSListHead (
  9935. IN PSLIST_HEADER SListHead
  9936. );
  9937. #else
  9938. __inline
  9939. VOID
  9940. InitializeSListHead (
  9941. IN PSLIST_HEADER SListHead
  9942. )
  9943. {
  9944. #ifdef _WIN64
  9945. //
  9946. // Slist headers must be 16 byte aligned.
  9947. //
  9948. if ((ULONG_PTR) SListHead & 0x0f) {
  9949. DbgPrint( "InitializeSListHead unaligned Slist header. Address = %p, Caller = %p\n", SListHead, _ReturnAddress());
  9950. RtlRaiseStatus(STATUS_DATATYPE_MISALIGNMENT);
  9951. }
  9952. #endif
  9953. SListHead->Alignment = 0;
  9954. //
  9955. // For IA-64 we save the region number of the elements of the list in a
  9956. // separate field. This imposes the requirement that all elements stored
  9957. // in the list are from the same region.
  9958. #if defined(_IA64_)
  9959. SListHead->Region = (ULONG_PTR)SListHead & VRN_MASK;
  9960. #elif defined(_AMD64_)
  9961. SListHead->Region = 0;
  9962. #endif
  9963. return;
  9964. }
  9965. #endif
  9966. #endif // !defined(_WINBASE_)
  9967. #define ExInitializeSListHead InitializeSListHead
  9968. PSLIST_ENTRY
  9969. FirstEntrySList (
  9970. IN const SLIST_HEADER *SListHead
  9971. );
  9972. /*++
  9973. Routine Description:
  9974. This function queries the current number of entries contained in a
  9975. sequenced single linked list.
  9976. Arguments:
  9977. SListHead - Supplies a pointer to the sequenced listhead which is
  9978. be queried.
  9979. Return Value:
  9980. The current number of entries in the sequenced singly linked list is
  9981. returned as the function value.
  9982. --*/
  9983. #if defined(_WIN64)
  9984. #if (defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_) || defined(_NTHAL_) || defined(_NTOSP_))
  9985. NTKERNELAPI
  9986. USHORT
  9987. ExQueryDepthSList (
  9988. IN PSLIST_HEADER SListHead
  9989. );
  9990. #else
  9991. __inline
  9992. USHORT
  9993. ExQueryDepthSList (
  9994. IN PSLIST_HEADER SListHead
  9995. )
  9996. {
  9997. return (USHORT)(SListHead->Alignment & 0xffff);
  9998. }
  9999. #endif
  10000. #else
  10001. #define ExQueryDepthSList(_listhead_) (_listhead_)->Depth
  10002. #endif
  10003. #if defined(_WIN64)
  10004. #define ExInterlockedPopEntrySList(Head, Lock) \
  10005. ExpInterlockedPopEntrySList(Head)
  10006. #define ExInterlockedPushEntrySList(Head, Entry, Lock) \
  10007. ExpInterlockedPushEntrySList(Head, Entry)
  10008. #define ExInterlockedFlushSList(Head) \
  10009. ExpInterlockedFlushSList(Head)
  10010. #if !defined(_WINBASE_)
  10011. #define InterlockedPopEntrySList(Head) \
  10012. ExpInterlockedPopEntrySList(Head)
  10013. #define InterlockedPushEntrySList(Head, Entry) \
  10014. ExpInterlockedPushEntrySList(Head, Entry)
  10015. #define InterlockedFlushSList(Head) \
  10016. ExpInterlockedFlushSList(Head)
  10017. #define QueryDepthSList(Head) \
  10018. ExQueryDepthSList(Head)
  10019. #endif // !defined(_WINBASE_)
  10020. NTKERNELAPI
  10021. PSLIST_ENTRY
  10022. ExpInterlockedPopEntrySList (
  10023. IN PSLIST_HEADER ListHead
  10024. );
  10025. NTKERNELAPI
  10026. PSLIST_ENTRY
  10027. ExpInterlockedPushEntrySList (
  10028. IN PSLIST_HEADER ListHead,
  10029. IN PSLIST_ENTRY ListEntry
  10030. );
  10031. NTKERNELAPI
  10032. PSLIST_ENTRY
  10033. ExpInterlockedFlushSList (
  10034. IN PSLIST_HEADER ListHead
  10035. );
  10036. #else
  10037. #if defined(_WIN2K_COMPAT_SLIST_USAGE) && defined(_X86_)
  10038. NTKERNELAPI
  10039. PSLIST_ENTRY
  10040. FASTCALL
  10041. ExInterlockedPopEntrySList (
  10042. IN PSLIST_HEADER ListHead,
  10043. IN PKSPIN_LOCK Lock
  10044. );
  10045. NTKERNELAPI
  10046. PSLIST_ENTRY
  10047. FASTCALL
  10048. ExInterlockedPushEntrySList (
  10049. IN PSLIST_HEADER ListHead,
  10050. IN PSLIST_ENTRY ListEntry,
  10051. IN PKSPIN_LOCK Lock
  10052. );
  10053. #else
  10054. #define ExInterlockedPopEntrySList(ListHead, Lock) \
  10055. InterlockedPopEntrySList(ListHead)
  10056. #define ExInterlockedPushEntrySList(ListHead, ListEntry, Lock) \
  10057. InterlockedPushEntrySList(ListHead, ListEntry)
  10058. #endif
  10059. NTKERNELAPI
  10060. PSLIST_ENTRY
  10061. FASTCALL
  10062. ExInterlockedFlushSList (
  10063. IN PSLIST_HEADER ListHead
  10064. );
  10065. #if !defined(_WINBASE_)
  10066. NTKERNELAPI
  10067. PSLIST_ENTRY
  10068. FASTCALL
  10069. InterlockedPopEntrySList (
  10070. IN PSLIST_HEADER ListHead
  10071. );
  10072. NTKERNELAPI
  10073. PSLIST_ENTRY
  10074. FASTCALL
  10075. InterlockedPushEntrySList (
  10076. IN PSLIST_HEADER ListHead,
  10077. IN PSLIST_ENTRY ListEntry
  10078. );
  10079. #define InterlockedFlushSList(Head) \
  10080. ExInterlockedFlushSList(Head)
  10081. #define QueryDepthSList(Head) \
  10082. ExQueryDepthSList(Head)
  10083. #endif // !defined(_WINBASE_)
  10084. #endif // defined(_WIN64)
  10085. typedef
  10086. PVOID
  10087. (*PALLOCATE_FUNCTION) (
  10088. IN POOL_TYPE PoolType,
  10089. IN SIZE_T NumberOfBytes,
  10090. IN ULONG Tag
  10091. );
  10092. typedef
  10093. VOID
  10094. (*PFREE_FUNCTION) (
  10095. IN PVOID Buffer
  10096. );
  10097. #if !defined(_WIN64) && (defined(_NTDDK_) || defined(_NTIFS_) || defined(_NDIS_))
  10098. typedef struct _GENERAL_LOOKASIDE {
  10099. #else
  10100. typedef struct DECLSPEC_CACHEALIGN _GENERAL_LOOKASIDE {
  10101. #endif
  10102. SLIST_HEADER ListHead;
  10103. USHORT Depth;
  10104. USHORT MaximumDepth;
  10105. ULONG TotalAllocates;
  10106. union {
  10107. ULONG AllocateMisses;
  10108. ULONG AllocateHits;
  10109. };
  10110. ULONG TotalFrees;
  10111. union {
  10112. ULONG FreeMisses;
  10113. ULONG FreeHits;
  10114. };
  10115. POOL_TYPE Type;
  10116. ULONG Tag;
  10117. ULONG Size;
  10118. PALLOCATE_FUNCTION Allocate;
  10119. PFREE_FUNCTION Free;
  10120. LIST_ENTRY ListEntry;
  10121. ULONG LastTotalAllocates;
  10122. union {
  10123. ULONG LastAllocateMisses;
  10124. ULONG LastAllocateHits;
  10125. };
  10126. ULONG Future[2];
  10127. } GENERAL_LOOKASIDE, *PGENERAL_LOOKASIDE;
  10128. #if !defined(_WIN64) && (defined(_NTDDK_) || defined(_NTIFS_) || defined(_NDIS_))
  10129. typedef struct _NPAGED_LOOKASIDE_LIST {
  10130. #else
  10131. typedef struct DECLSPEC_CACHEALIGN _NPAGED_LOOKASIDE_LIST {
  10132. #endif
  10133. GENERAL_LOOKASIDE L;
  10134. #if !defined(_AMD64_) && !defined(_IA64_)
  10135. KSPIN_LOCK Lock__ObsoleteButDoNotDelete;
  10136. #endif
  10137. } NPAGED_LOOKASIDE_LIST, *PNPAGED_LOOKASIDE_LIST;
  10138. NTKERNELAPI
  10139. VOID
  10140. ExInitializeNPagedLookasideList (
  10141. IN PNPAGED_LOOKASIDE_LIST Lookaside,
  10142. IN PALLOCATE_FUNCTION Allocate,
  10143. IN PFREE_FUNCTION Free,
  10144. IN ULONG Flags,
  10145. IN SIZE_T Size,
  10146. IN ULONG Tag,
  10147. IN USHORT Depth
  10148. );
  10149. NTKERNELAPI
  10150. VOID
  10151. ExDeleteNPagedLookasideList (
  10152. IN PNPAGED_LOOKASIDE_LIST Lookaside
  10153. );
  10154. __inline
  10155. PVOID
  10156. ExAllocateFromNPagedLookasideList(
  10157. IN PNPAGED_LOOKASIDE_LIST Lookaside
  10158. )
  10159. /*++
  10160. Routine Description:
  10161. This function removes (pops) the first entry from the specified
  10162. nonpaged lookaside list.
  10163. Arguments:
  10164. Lookaside - Supplies a pointer to a nonpaged lookaside list structure.
  10165. Return Value:
  10166. If an entry is removed from the specified lookaside list, then the
  10167. address of the entry is returned as the function value. Otherwise,
  10168. NULL is returned.
  10169. --*/
  10170. {
  10171. PVOID Entry;
  10172. Lookaside->L.TotalAllocates += 1;
  10173. #if defined(_WIN2K_COMPAT_SLIST_USAGE) && defined(_X86_)
  10174. Entry = ExInterlockedPopEntrySList(&Lookaside->L.ListHead,
  10175. &Lookaside->Lock__ObsoleteButDoNotDelete);
  10176. #else
  10177. Entry = InterlockedPopEntrySList(&Lookaside->L.ListHead);
  10178. #endif
  10179. if (Entry == NULL) {
  10180. Lookaside->L.AllocateMisses += 1;
  10181. Entry = (Lookaside->L.Allocate)(Lookaside->L.Type,
  10182. Lookaside->L.Size,
  10183. Lookaside->L.Tag);
  10184. }
  10185. return Entry;
  10186. }
  10187. __inline
  10188. VOID
  10189. ExFreeToNPagedLookasideList(
  10190. IN PNPAGED_LOOKASIDE_LIST Lookaside,
  10191. IN PVOID Entry
  10192. )
  10193. /*++
  10194. Routine Description:
  10195. This function inserts (pushes) the specified entry into the specified
  10196. nonpaged lookaside list.
  10197. Arguments:
  10198. Lookaside - Supplies a pointer to a nonpaged lookaside list structure.
  10199. Entry - Supples a pointer to the entry that is inserted in the
  10200. lookaside list.
  10201. Return Value:
  10202. None.
  10203. --*/
  10204. {
  10205. Lookaside->L.TotalFrees += 1;
  10206. if (ExQueryDepthSList(&Lookaside->L.ListHead) >= Lookaside->L.Depth) {
  10207. Lookaside->L.FreeMisses += 1;
  10208. (Lookaside->L.Free)(Entry);
  10209. } else {
  10210. #if defined(_WIN2K_COMPAT_SLIST_USAGE) && defined(_X86_)
  10211. ExInterlockedPushEntrySList(&Lookaside->L.ListHead,
  10212. (PSLIST_ENTRY)Entry,
  10213. &Lookaside->Lock__ObsoleteButDoNotDelete);
  10214. #else
  10215. InterlockedPushEntrySList(&Lookaside->L.ListHead,
  10216. (PSLIST_ENTRY)Entry);
  10217. #endif
  10218. }
  10219. return;
  10220. }
  10221. // end_ntndis
  10222. #if !defined(_WIN64) && (defined(_NTDDK_) || defined(_NTIFS_) || defined(_NDIS_))
  10223. typedef struct _PAGED_LOOKASIDE_LIST {
  10224. #else
  10225. typedef struct DECLSPEC_CACHEALIGN _PAGED_LOOKASIDE_LIST {
  10226. #endif
  10227. GENERAL_LOOKASIDE L;
  10228. #if !defined(_AMD64_) && !defined(_IA64_)
  10229. FAST_MUTEX Lock__ObsoleteButDoNotDelete;
  10230. #endif
  10231. } PAGED_LOOKASIDE_LIST, *PPAGED_LOOKASIDE_LIST;
  10232. NTKERNELAPI
  10233. VOID
  10234. ExInitializePagedLookasideList (
  10235. IN PPAGED_LOOKASIDE_LIST Lookaside,
  10236. IN PALLOCATE_FUNCTION Allocate,
  10237. IN PFREE_FUNCTION Free,
  10238. IN ULONG Flags,
  10239. IN SIZE_T Size,
  10240. IN ULONG Tag,
  10241. IN USHORT Depth
  10242. );
  10243. NTKERNELAPI
  10244. VOID
  10245. ExDeletePagedLookasideList (
  10246. IN PPAGED_LOOKASIDE_LIST Lookaside
  10247. );
  10248. #if defined(_WIN2K_COMPAT_SLIST_USAGE) && defined(_X86_)
  10249. NTKERNELAPI
  10250. PVOID
  10251. ExAllocateFromPagedLookasideList(
  10252. IN PPAGED_LOOKASIDE_LIST Lookaside
  10253. );
  10254. #else
  10255. __inline
  10256. PVOID
  10257. ExAllocateFromPagedLookasideList(
  10258. IN PPAGED_LOOKASIDE_LIST Lookaside
  10259. )
  10260. /*++
  10261. Routine Description:
  10262. This function removes (pops) the first entry from the specified
  10263. paged lookaside list.
  10264. Arguments:
  10265. Lookaside - Supplies a pointer to a paged lookaside list structure.
  10266. Return Value:
  10267. If an entry is removed from the specified lookaside list, then the
  10268. address of the entry is returned as the function value. Otherwise,
  10269. NULL is returned.
  10270. --*/
  10271. {
  10272. PVOID Entry;
  10273. Lookaside->L.TotalAllocates += 1;
  10274. Entry = InterlockedPopEntrySList(&Lookaside->L.ListHead);
  10275. if (Entry == NULL) {
  10276. Lookaside->L.AllocateMisses += 1;
  10277. Entry = (Lookaside->L.Allocate)(Lookaside->L.Type,
  10278. Lookaside->L.Size,
  10279. Lookaside->L.Tag);
  10280. }
  10281. return Entry;
  10282. }
  10283. #endif
  10284. #if defined(_WIN2K_COMPAT_SLIST_USAGE) && defined(_X86_)
  10285. NTKERNELAPI
  10286. VOID
  10287. ExFreeToPagedLookasideList(
  10288. IN PPAGED_LOOKASIDE_LIST Lookaside,
  10289. IN PVOID Entry
  10290. );
  10291. #else
  10292. __inline
  10293. VOID
  10294. ExFreeToPagedLookasideList(
  10295. IN PPAGED_LOOKASIDE_LIST Lookaside,
  10296. IN PVOID Entry
  10297. )
  10298. /*++
  10299. Routine Description:
  10300. This function inserts (pushes) the specified entry into the specified
  10301. paged lookaside list.
  10302. Arguments:
  10303. Lookaside - Supplies a pointer to a nonpaged lookaside list structure.
  10304. Entry - Supples a pointer to the entry that is inserted in the
  10305. lookaside list.
  10306. Return Value:
  10307. None.
  10308. --*/
  10309. {
  10310. Lookaside->L.TotalFrees += 1;
  10311. if (ExQueryDepthSList(&Lookaside->L.ListHead) >= Lookaside->L.Depth) {
  10312. Lookaside->L.FreeMisses += 1;
  10313. (Lookaside->L.Free)(Entry);
  10314. } else {
  10315. InterlockedPushEntrySList(&Lookaside->L.ListHead,
  10316. (PSLIST_ENTRY)Entry);
  10317. }
  10318. return;
  10319. }
  10320. #endif
  10321. NTKERNELAPI
  10322. VOID
  10323. NTAPI
  10324. ProbeForRead(
  10325. IN CONST VOID *Address,
  10326. IN SIZE_T Length,
  10327. IN ULONG Alignment
  10328. );
  10329. //
  10330. // Common probe for write functions.
  10331. //
  10332. NTKERNELAPI
  10333. VOID
  10334. NTAPI
  10335. ProbeForWrite (
  10336. IN PVOID Address,
  10337. IN SIZE_T Length,
  10338. IN ULONG Alignment
  10339. );
  10340. //
  10341. // Worker Thread
  10342. //
  10343. typedef enum _WORK_QUEUE_TYPE {
  10344. CriticalWorkQueue,
  10345. DelayedWorkQueue,
  10346. HyperCriticalWorkQueue,
  10347. MaximumWorkQueue
  10348. } WORK_QUEUE_TYPE;
  10349. typedef
  10350. VOID
  10351. (*PWORKER_THREAD_ROUTINE)(
  10352. IN PVOID Parameter
  10353. );
  10354. typedef struct _WORK_QUEUE_ITEM {
  10355. LIST_ENTRY List;
  10356. PWORKER_THREAD_ROUTINE WorkerRoutine;
  10357. PVOID Parameter;
  10358. } WORK_QUEUE_ITEM, *PWORK_QUEUE_ITEM;
  10359. #if PRAGMA_DEPRECATED_DDK
  10360. #pragma deprecated(ExInitializeWorkItem) // Use IoAllocateWorkItem
  10361. #endif
  10362. #define ExInitializeWorkItem(Item, Routine, Context) \
  10363. (Item)->WorkerRoutine = (Routine); \
  10364. (Item)->Parameter = (Context); \
  10365. (Item)->List.Flink = NULL;
  10366. DECLSPEC_DEPRECATED_DDK // Use IoQueueWorkItem
  10367. NTKERNELAPI
  10368. VOID
  10369. ExQueueWorkItem(
  10370. IN PWORK_QUEUE_ITEM WorkItem,
  10371. IN WORK_QUEUE_TYPE QueueType
  10372. );
  10373. NTKERNELAPI
  10374. BOOLEAN
  10375. ExIsProcessorFeaturePresent(
  10376. ULONG ProcessorFeature
  10377. );
  10378. //
  10379. // Zone Allocation
  10380. //
  10381. typedef struct _ZONE_SEGMENT_HEADER {
  10382. SINGLE_LIST_ENTRY SegmentList;
  10383. PVOID Reserved;
  10384. } ZONE_SEGMENT_HEADER, *PZONE_SEGMENT_HEADER;
  10385. typedef struct _ZONE_HEADER {
  10386. SINGLE_LIST_ENTRY FreeList;
  10387. SINGLE_LIST_ENTRY SegmentList;
  10388. ULONG BlockSize;
  10389. ULONG TotalSegmentSize;
  10390. } ZONE_HEADER, *PZONE_HEADER;
  10391. DECLSPEC_DEPRECATED_DDK
  10392. NTKERNELAPI
  10393. NTSTATUS
  10394. ExInitializeZone(
  10395. IN PZONE_HEADER Zone,
  10396. IN ULONG BlockSize,
  10397. IN PVOID InitialSegment,
  10398. IN ULONG InitialSegmentSize
  10399. );
  10400. DECLSPEC_DEPRECATED_DDK
  10401. NTKERNELAPI
  10402. NTSTATUS
  10403. ExExtendZone(
  10404. IN PZONE_HEADER Zone,
  10405. IN PVOID Segment,
  10406. IN ULONG SegmentSize
  10407. );
  10408. DECLSPEC_DEPRECATED_DDK
  10409. NTKERNELAPI
  10410. NTSTATUS
  10411. ExInterlockedExtendZone(
  10412. IN PZONE_HEADER Zone,
  10413. IN PVOID Segment,
  10414. IN ULONG SegmentSize,
  10415. IN PKSPIN_LOCK Lock
  10416. );
  10417. //++
  10418. //
  10419. // PVOID
  10420. // ExAllocateFromZone(
  10421. // IN PZONE_HEADER Zone
  10422. // )
  10423. //
  10424. // Routine Description:
  10425. //
  10426. // This routine removes an entry from the zone and returns a pointer to it.
  10427. //
  10428. // Arguments:
  10429. //
  10430. // Zone - Pointer to the zone header controlling the storage from which the
  10431. // entry is to be allocated.
  10432. //
  10433. // Return Value:
  10434. //
  10435. // The function value is a pointer to the storage allocated from the zone.
  10436. //
  10437. //--
  10438. #if PRAGMA_DEPRECATED_DDK
  10439. #pragma deprecated(ExAllocateFromZone)
  10440. #endif
  10441. #define ExAllocateFromZone(Zone) \
  10442. (PVOID)((Zone)->FreeList.Next); \
  10443. if ( (Zone)->FreeList.Next ) (Zone)->FreeList.Next = (Zone)->FreeList.Next->Next
  10444. //++
  10445. //
  10446. // PVOID
  10447. // ExFreeToZone(
  10448. // IN PZONE_HEADER Zone,
  10449. // IN PVOID Block
  10450. // )
  10451. //
  10452. // Routine Description:
  10453. //
  10454. // This routine places the specified block of storage back onto the free
  10455. // list in the specified zone.
  10456. //
  10457. // Arguments:
  10458. //
  10459. // Zone - Pointer to the zone header controlling the storage to which the
  10460. // entry is to be inserted.
  10461. //
  10462. // Block - Pointer to the block of storage to be freed back to the zone.
  10463. //
  10464. // Return Value:
  10465. //
  10466. // Pointer to previous block of storage that was at the head of the free
  10467. // list. NULL implies the zone went from no available free blocks to
  10468. // at least one free block.
  10469. //
  10470. //--
  10471. #if PRAGMA_DEPRECATED_DDK
  10472. #pragma deprecated(ExFreeToZone)
  10473. #endif
  10474. #define ExFreeToZone(Zone,Block) \
  10475. ( ((PSINGLE_LIST_ENTRY)(Block))->Next = (Zone)->FreeList.Next, \
  10476. (Zone)->FreeList.Next = ((PSINGLE_LIST_ENTRY)(Block)), \
  10477. ((PSINGLE_LIST_ENTRY)(Block))->Next \
  10478. )
  10479. //++
  10480. //
  10481. // BOOLEAN
  10482. // ExIsFullZone(
  10483. // IN PZONE_HEADER Zone
  10484. // )
  10485. //
  10486. // Routine Description:
  10487. //
  10488. // This routine determines if the specified zone is full or not. A zone
  10489. // is considered full if the free list is empty.
  10490. //
  10491. // Arguments:
  10492. //
  10493. // Zone - Pointer to the zone header to be tested.
  10494. //
  10495. // Return Value:
  10496. //
  10497. // TRUE if the zone is full and FALSE otherwise.
  10498. //
  10499. //--
  10500. #if PRAGMA_DEPRECATED_DDK
  10501. #pragma deprecated(ExIsFullZone)
  10502. #endif
  10503. #define ExIsFullZone(Zone) \
  10504. ( (Zone)->FreeList.Next == (PSINGLE_LIST_ENTRY)NULL )
  10505. //++
  10506. //
  10507. // PVOID
  10508. // ExInterlockedAllocateFromZone(
  10509. // IN PZONE_HEADER Zone,
  10510. // IN PKSPIN_LOCK Lock
  10511. // )
  10512. //
  10513. // Routine Description:
  10514. //
  10515. // This routine removes an entry from the zone and returns a pointer to it.
  10516. // The removal is performed with the specified lock owned for the sequence
  10517. // to make it MP-safe.
  10518. //
  10519. // Arguments:
  10520. //
  10521. // Zone - Pointer to the zone header controlling the storage from which the
  10522. // entry is to be allocated.
  10523. //
  10524. // Lock - Pointer to the spin lock which should be obtained before removing
  10525. // the entry from the allocation list. The lock is released before
  10526. // returning to the caller.
  10527. //
  10528. // Return Value:
  10529. //
  10530. // The function value is a pointer to the storage allocated from the zone.
  10531. //
  10532. //--
  10533. #if PRAGMA_DEPRECATED_DDK
  10534. #pragma deprecated(ExInterlockedAllocateFromZone)
  10535. #endif
  10536. #define ExInterlockedAllocateFromZone(Zone,Lock) \
  10537. (PVOID) ExInterlockedPopEntryList( &(Zone)->FreeList, Lock )
  10538. //++
  10539. //
  10540. // PVOID
  10541. // ExInterlockedFreeToZone(
  10542. // IN PZONE_HEADER Zone,
  10543. // IN PVOID Block,
  10544. // IN PKSPIN_LOCK Lock
  10545. // )
  10546. //
  10547. // Routine Description:
  10548. //
  10549. // This routine places the specified block of storage back onto the free
  10550. // list in the specified zone. The insertion is performed with the lock
  10551. // owned for the sequence to make it MP-safe.
  10552. //
  10553. // Arguments:
  10554. //
  10555. // Zone - Pointer to the zone header controlling the storage to which the
  10556. // entry is to be inserted.
  10557. //
  10558. // Block - Pointer to the block of storage to be freed back to the zone.
  10559. //
  10560. // Lock - Pointer to the spin lock which should be obtained before inserting
  10561. // the entry onto the free list. The lock is released before returning
  10562. // to the caller.
  10563. //
  10564. // Return Value:
  10565. //
  10566. // Pointer to previous block of storage that was at the head of the free
  10567. // list. NULL implies the zone went from no available free blocks to
  10568. // at least one free block.
  10569. //
  10570. //--
  10571. #if PRAGMA_DEPRECATED_DDK
  10572. #pragma deprecated(ExInterlockedFreeToZone)
  10573. #endif
  10574. #define ExInterlockedFreeToZone(Zone,Block,Lock) \
  10575. ExInterlockedPushEntryList( &(Zone)->FreeList, ((PSINGLE_LIST_ENTRY) (Block)), Lock )
  10576. //++
  10577. //
  10578. // BOOLEAN
  10579. // ExIsObjectInFirstZoneSegment(
  10580. // IN PZONE_HEADER Zone,
  10581. // IN PVOID Object
  10582. // )
  10583. //
  10584. // Routine Description:
  10585. //
  10586. // This routine determines if the specified pointer lives in the zone.
  10587. //
  10588. // Arguments:
  10589. //
  10590. // Zone - Pointer to the zone header controlling the storage to which the
  10591. // object may belong.
  10592. //
  10593. // Object - Pointer to the object in question.
  10594. //
  10595. // Return Value:
  10596. //
  10597. // TRUE if the Object came from the first segment of zone.
  10598. //
  10599. //--
  10600. #if PRAGMA_DEPRECATED_DDK
  10601. #pragma deprecated(ExIsObjectInFirstZoneSegment)
  10602. #endif
  10603. #define ExIsObjectInFirstZoneSegment(Zone,Object) ((BOOLEAN) \
  10604. (((PUCHAR)(Object) >= (PUCHAR)(Zone)->SegmentList.Next) && \
  10605. ((PUCHAR)(Object) < (PUCHAR)(Zone)->SegmentList.Next + \
  10606. (Zone)->TotalSegmentSize)) \
  10607. )
  10608. //
  10609. // Define executive resource data structures.
  10610. //
  10611. typedef ULONG_PTR ERESOURCE_THREAD;
  10612. typedef ERESOURCE_THREAD *PERESOURCE_THREAD;
  10613. typedef struct _OWNER_ENTRY {
  10614. ERESOURCE_THREAD OwnerThread;
  10615. union {
  10616. LONG OwnerCount;
  10617. ULONG TableSize;
  10618. };
  10619. } OWNER_ENTRY, *POWNER_ENTRY;
  10620. typedef struct _ERESOURCE {
  10621. LIST_ENTRY SystemResourcesList;
  10622. POWNER_ENTRY OwnerTable;
  10623. SHORT ActiveCount;
  10624. USHORT Flag;
  10625. PKSEMAPHORE SharedWaiters;
  10626. PKEVENT ExclusiveWaiters;
  10627. OWNER_ENTRY OwnerThreads[2];
  10628. ULONG ContentionCount;
  10629. USHORT NumberOfSharedWaiters;
  10630. USHORT NumberOfExclusiveWaiters;
  10631. union {
  10632. PVOID Address;
  10633. ULONG_PTR CreatorBackTraceIndex;
  10634. };
  10635. KSPIN_LOCK SpinLock;
  10636. } ERESOURCE, *PERESOURCE;
  10637. //
  10638. // Values for ERESOURCE.Flag
  10639. //
  10640. #define ResourceNeverExclusive 0x10
  10641. #define ResourceReleaseByOtherThread 0x20
  10642. #define ResourceOwnedExclusive 0x80
  10643. #define RESOURCE_HASH_TABLE_SIZE 64
  10644. typedef struct _RESOURCE_HASH_ENTRY {
  10645. LIST_ENTRY ListEntry;
  10646. PVOID Address;
  10647. ULONG ContentionCount;
  10648. ULONG Number;
  10649. } RESOURCE_HASH_ENTRY, *PRESOURCE_HASH_ENTRY;
  10650. typedef struct _RESOURCE_PERFORMANCE_DATA {
  10651. ULONG ActiveResourceCount;
  10652. ULONG TotalResourceCount;
  10653. ULONG ExclusiveAcquire;
  10654. ULONG SharedFirstLevel;
  10655. ULONG SharedSecondLevel;
  10656. ULONG StarveFirstLevel;
  10657. ULONG StarveSecondLevel;
  10658. ULONG WaitForExclusive;
  10659. ULONG OwnerTableExpands;
  10660. ULONG MaximumTableExpand;
  10661. LIST_ENTRY HashTable[RESOURCE_HASH_TABLE_SIZE];
  10662. } RESOURCE_PERFORMANCE_DATA, *PRESOURCE_PERFORMANCE_DATA;
  10663. //
  10664. // Define executive resource function prototypes.
  10665. //
  10666. NTKERNELAPI
  10667. NTSTATUS
  10668. ExInitializeResourceLite(
  10669. IN PERESOURCE Resource
  10670. );
  10671. NTKERNELAPI
  10672. NTSTATUS
  10673. ExReinitializeResourceLite(
  10674. IN PERESOURCE Resource
  10675. );
  10676. NTKERNELAPI
  10677. BOOLEAN
  10678. ExAcquireResourceSharedLite(
  10679. IN PERESOURCE Resource,
  10680. IN BOOLEAN Wait
  10681. );
  10682. NTKERNELAPI
  10683. BOOLEAN
  10684. ExAcquireResourceExclusiveLite(
  10685. IN PERESOURCE Resource,
  10686. IN BOOLEAN Wait
  10687. );
  10688. NTKERNELAPI
  10689. BOOLEAN
  10690. ExAcquireSharedStarveExclusive(
  10691. IN PERESOURCE Resource,
  10692. IN BOOLEAN Wait
  10693. );
  10694. NTKERNELAPI
  10695. BOOLEAN
  10696. ExAcquireSharedWaitForExclusive(
  10697. IN PERESOURCE Resource,
  10698. IN BOOLEAN Wait
  10699. );
  10700. NTKERNELAPI
  10701. BOOLEAN
  10702. ExTryToAcquireResourceExclusiveLite(
  10703. IN PERESOURCE Resource
  10704. );
  10705. //
  10706. // VOID
  10707. // ExReleaseResource(
  10708. // IN PERESOURCE Resource
  10709. // );
  10710. //
  10711. #if PRAGMA_DEPRECATED_DDK
  10712. #pragma deprecated(ExReleaseResource) // Use ExReleaseResourceLite
  10713. #endif
  10714. #define ExReleaseResource(R) (ExReleaseResourceLite(R))
  10715. NTKERNELAPI
  10716. VOID
  10717. FASTCALL
  10718. ExReleaseResourceLite(
  10719. IN PERESOURCE Resource
  10720. );
  10721. NTKERNELAPI
  10722. VOID
  10723. ExReleaseResourceForThreadLite(
  10724. IN PERESOURCE Resource,
  10725. IN ERESOURCE_THREAD ResourceThreadId
  10726. );
  10727. NTKERNELAPI
  10728. VOID
  10729. ExSetResourceOwnerPointer(
  10730. IN PERESOURCE Resource,
  10731. IN PVOID OwnerPointer
  10732. );
  10733. NTKERNELAPI
  10734. VOID
  10735. ExConvertExclusiveToSharedLite(
  10736. IN PERESOURCE Resource
  10737. );
  10738. NTKERNELAPI
  10739. NTSTATUS
  10740. ExDeleteResourceLite (
  10741. IN PERESOURCE Resource
  10742. );
  10743. NTKERNELAPI
  10744. ULONG
  10745. ExGetExclusiveWaiterCount (
  10746. IN PERESOURCE Resource
  10747. );
  10748. NTKERNELAPI
  10749. ULONG
  10750. ExGetSharedWaiterCount (
  10751. IN PERESOURCE Resource
  10752. );
  10753. //
  10754. // ERESOURCE_THREAD
  10755. // ExGetCurrentResourceThread(
  10756. // );
  10757. //
  10758. #define ExGetCurrentResourceThread() ((ULONG_PTR)PsGetCurrentThread())
  10759. NTKERNELAPI
  10760. BOOLEAN
  10761. ExIsResourceAcquiredExclusiveLite (
  10762. IN PERESOURCE Resource
  10763. );
  10764. NTKERNELAPI
  10765. ULONG
  10766. ExIsResourceAcquiredSharedLite (
  10767. IN PERESOURCE Resource
  10768. );
  10769. //
  10770. // An acquired resource is always owned shared, as shared ownership is a subset
  10771. // of exclusive ownership.
  10772. //
  10773. #define ExIsResourceAcquiredLite ExIsResourceAcquiredSharedLite
  10774. // end_wdm
  10775. //
  10776. // ntddk.h stole the entrypoints we wanted so fix them up here.
  10777. //
  10778. #if PRAGMA_DEPRECATED_DDK
  10779. #pragma deprecated(ExInitializeResource) // use ExInitializeResourceLite
  10780. #pragma deprecated(ExAcquireResourceShared) // use ExAcquireResourceSharedLite
  10781. #pragma deprecated(ExAcquireResourceExclusive) // use ExAcquireResourceExclusiveLite
  10782. #pragma deprecated(ExReleaseResourceForThread) // use ExReleaseResourceForThreadLite
  10783. #pragma deprecated(ExConvertExclusiveToShared) // use ExConvertExclusiveToSharedLite
  10784. #pragma deprecated(ExDeleteResource) // use ExDeleteResourceLite
  10785. #pragma deprecated(ExIsResourceAcquiredExclusive) // use ExIsResourceAcquiredExclusiveLite
  10786. #pragma deprecated(ExIsResourceAcquiredShared) // use ExIsResourceAcquiredSharedLite
  10787. #pragma deprecated(ExIsResourceAcquired) // use ExIsResourceAcquiredSharedLite
  10788. #endif
  10789. #define ExInitializeResource ExInitializeResourceLite
  10790. #define ExAcquireResourceShared ExAcquireResourceSharedLite
  10791. #define ExAcquireResourceExclusive ExAcquireResourceExclusiveLite
  10792. #define ExReleaseResourceForThread ExReleaseResourceForThreadLite
  10793. #define ExConvertExclusiveToShared ExConvertExclusiveToSharedLite
  10794. #define ExDeleteResource ExDeleteResourceLite
  10795. #define ExIsResourceAcquiredExclusive ExIsResourceAcquiredExclusiveLite
  10796. #define ExIsResourceAcquiredShared ExIsResourceAcquiredSharedLite
  10797. #define ExIsResourceAcquired ExIsResourceAcquiredSharedLite
  10798. //
  10799. // Get previous mode
  10800. //
  10801. NTKERNELAPI
  10802. KPROCESSOR_MODE
  10803. ExGetPreviousMode(
  10804. VOID
  10805. );
  10806. //
  10807. // Raise status from kernel mode.
  10808. //
  10809. NTKERNELAPI
  10810. VOID
  10811. NTAPI
  10812. ExRaiseStatus (
  10813. IN NTSTATUS Status
  10814. );
  10815. // end_wdm
  10816. NTKERNELAPI
  10817. VOID
  10818. ExRaiseDatatypeMisalignment (
  10819. VOID
  10820. );
  10821. NTKERNELAPI
  10822. VOID
  10823. ExRaiseAccessViolation (
  10824. VOID
  10825. );
  10826. //
  10827. // Set timer resolution.
  10828. //
  10829. NTKERNELAPI
  10830. ULONG
  10831. ExSetTimerResolution (
  10832. IN ULONG DesiredTime,
  10833. IN BOOLEAN SetResolution
  10834. );
  10835. //
  10836. // Subtract time zone bias from system time to get local time.
  10837. //
  10838. NTKERNELAPI
  10839. VOID
  10840. ExSystemTimeToLocalTime (
  10841. IN PLARGE_INTEGER SystemTime,
  10842. OUT PLARGE_INTEGER LocalTime
  10843. );
  10844. //
  10845. // Add time zone bias to local time to get system time.
  10846. //
  10847. NTKERNELAPI
  10848. VOID
  10849. ExLocalTimeToSystemTime (
  10850. IN PLARGE_INTEGER LocalTime,
  10851. OUT PLARGE_INTEGER SystemTime
  10852. );
  10853. //
  10854. // Define the type for Callback function.
  10855. //
  10856. typedef struct _CALLBACK_OBJECT *PCALLBACK_OBJECT;
  10857. typedef VOID (*PCALLBACK_FUNCTION ) (
  10858. IN PVOID CallbackContext,
  10859. IN PVOID Argument1,
  10860. IN PVOID Argument2
  10861. );
  10862. NTKERNELAPI
  10863. NTSTATUS
  10864. ExCreateCallback (
  10865. OUT PCALLBACK_OBJECT *CallbackObject,
  10866. IN POBJECT_ATTRIBUTES ObjectAttributes,
  10867. IN BOOLEAN Create,
  10868. IN BOOLEAN AllowMultipleCallbacks
  10869. );
  10870. NTKERNELAPI
  10871. PVOID
  10872. ExRegisterCallback (
  10873. IN PCALLBACK_OBJECT CallbackObject,
  10874. IN PCALLBACK_FUNCTION CallbackFunction,
  10875. IN PVOID CallbackContext
  10876. );
  10877. NTKERNELAPI
  10878. VOID
  10879. ExUnregisterCallback (
  10880. IN PVOID CallbackRegistration
  10881. );
  10882. NTKERNELAPI
  10883. VOID
  10884. ExNotifyCallback (
  10885. IN PVOID CallbackObject,
  10886. IN PVOID Argument1,
  10887. IN PVOID Argument2
  10888. );
  10889. //
  10890. // UUID Generation
  10891. //
  10892. typedef GUID UUID;
  10893. NTKERNELAPI
  10894. NTSTATUS
  10895. ExUuidCreate(
  10896. OUT UUID *Uuid
  10897. );
  10898. //
  10899. // suite support
  10900. //
  10901. NTKERNELAPI
  10902. BOOLEAN
  10903. ExVerifySuite(
  10904. SUITE_TYPE SuiteType
  10905. );
  10906. //
  10907. // Define a block to hold the actual routine registration.
  10908. //
  10909. typedef NTSTATUS (*PEX_CALLBACK_FUNCTION ) (
  10910. IN PVOID CallbackContext,
  10911. IN PVOID Argument1,
  10912. IN PVOID Argument2
  10913. );
  10914. //
  10915. // Registry kernel mode callbacks
  10916. //
  10917. //
  10918. // Hook selector
  10919. //
  10920. typedef enum _REG_NOTIFY_CLASS {
  10921. RegNtDeleteKey,
  10922. RegNtSetValueKey,
  10923. RegNtDeleteValueKey,
  10924. RegNtSetInformationKey,
  10925. RegNtRenameKey,
  10926. RegNtEnumerateKey,
  10927. RegNtEnumerateValueKey,
  10928. RegNtQueryKey,
  10929. RegNtQueryValueKey,
  10930. RegNtQueryMultipleValueKey,
  10931. RegNtPreCreateKey,
  10932. RegNtPostCreateKey,
  10933. RegNtPreOpenKey,
  10934. RegNtPostOpenKey,
  10935. RegNtKeyHandleClose
  10936. } REG_NOTIFY_CLASS;
  10937. //
  10938. // Parameter description for each notify class
  10939. //
  10940. typedef struct _REG_DELETE_KEY_INFORMATION {
  10941. PVOID Object; // IN
  10942. } REG_DELETE_KEY_INFORMATION, *PREG_DELETE_KEY_INFORMATION;
  10943. typedef struct _REG_SET_VALUE_KEY_INFORMATION {
  10944. PVOID Object; // IN
  10945. PUNICODE_STRING ValueName; // IN
  10946. ULONG TitleIndex; // IN
  10947. ULONG Type; // IN
  10948. PVOID Data; // IN
  10949. ULONG DataSize; // IN
  10950. } REG_SET_VALUE_KEY_INFORMATION, *PREG_SET_VALUE_KEY_INFORMATION;
  10951. typedef struct _REG_DELETE_VALUE_KEY_INFORMATION {
  10952. PVOID Object; // IN
  10953. PUNICODE_STRING ValueName; // IN
  10954. } REG_DELETE_VALUE_KEY_INFORMATION, *PREG_DELETE_VALUE_KEY_INFORMATION;
  10955. typedef struct _REG_SET_INFORMATION_KEY_INFORMATION {
  10956. PVOID Object; // IN
  10957. KEY_SET_INFORMATION_CLASS KeySetInformationClass; // IN
  10958. PVOID KeySetInformation; // IN
  10959. ULONG KeySetInformationLength;// IN
  10960. } REG_SET_INFORMATION_KEY_INFORMATION, *PREG_SET_INFORMATION_KEY_INFORMATION;
  10961. typedef struct _REG_ENUMERATE_KEY_INFORMATION {
  10962. PVOID Object; // IN
  10963. ULONG Index; // IN
  10964. KEY_INFORMATION_CLASS KeyInformationClass; // IN
  10965. PVOID KeyInformation; // IN
  10966. ULONG Length; // IN
  10967. PULONG ResultLength; // OUT
  10968. } REG_ENUMERATE_KEY_INFORMATION, *PREG_ENUMERATE_KEY_INFORMATION;
  10969. typedef struct _REG_ENUMERATE_VALUE_KEY_INFORMATION {
  10970. PVOID Object; // IN
  10971. ULONG Index; // IN
  10972. KEY_VALUE_INFORMATION_CLASS KeyValueInformationClass; // IN
  10973. PVOID KeyValueInformation; // IN
  10974. ULONG Length; // IN
  10975. PULONG ResultLength; // OUT
  10976. } REG_ENUMERATE_VALUE_KEY_INFORMATION, *PREG_ENUMERATE_VALUE_KEY_INFORMATION;
  10977. typedef struct _REG_QUERY_KEY_INFORMATION {
  10978. PVOID Object; // IN
  10979. KEY_INFORMATION_CLASS KeyInformationClass; // IN
  10980. PVOID KeyInformation; // IN
  10981. ULONG Length; // IN
  10982. PULONG ResultLength; // OUT
  10983. } REG_QUERY_KEY_INFORMATION, *PREG_QUERY_KEY_INFORMATION;
  10984. typedef struct _REG_QUERY_VALUE_KEY_INFORMATION {
  10985. PVOID Object; // IN
  10986. PUNICODE_STRING ValueName; // IN
  10987. KEY_VALUE_INFORMATION_CLASS KeyValueInformationClass; // IN
  10988. PVOID KeyValueInformation; // IN
  10989. ULONG Length; // IN
  10990. PULONG ResultLength; // OUT
  10991. } REG_QUERY_VALUE_KEY_INFORMATION, *PREG_QUERY_VALUE_KEY_INFORMATION;
  10992. typedef struct _REG_QUERY_MULTIPLE_VALUE_KEY_INFORMATION {
  10993. PVOID Object; // IN
  10994. PKEY_VALUE_ENTRY ValueEntries; // IN
  10995. ULONG EntryCount; // IN
  10996. PVOID ValueBuffer; // IN
  10997. PULONG BufferLength; // IN OUT
  10998. PULONG RequiredBufferLength; // OUT
  10999. } REG_QUERY_MULTIPLE_VALUE_KEY_INFORMATION, *PREG_QUERY_MULTIPLE_VALUE_KEY_INFORMATION;
  11000. typedef struct _REG_RENAME_KEY_INFORMATION {
  11001. PVOID Object; // IN
  11002. PUNICODE_STRING NewName; // IN
  11003. } REG_RENAME_KEY_INFORMATION, *PREG_RENAME_KEY_INFORMATION;
  11004. typedef struct _REG_PRE_CREATE_KEY_INFORMATION {
  11005. PUNICODE_STRING CompleteName; // IN
  11006. } REG_PRE_CREATE_KEY_INFORMATION, REG_PRE_OPEN_KEY_INFORMATION,*PREG_PRE_CREATE_KEY_INFORMATION, *PREG_PRE_OPEN_KEY_INFORMATION;;
  11007. typedef struct _REG_POST_CREATE_KEY_INFORMATION {
  11008. PUNICODE_STRING CompleteName; // IN
  11009. PVOID Object; // IN
  11010. NTSTATUS Status; // IN
  11011. } REG_POST_CREATE_KEY_INFORMATION,REG_POST_OPEN_KEY_INFORMATION, *PREG_POST_CREATE_KEY_INFORMATION, *PREG_POST_OPEN_KEY_INFORMATION;
  11012. typedef struct _REG_KEY_HANDLE_CLOSE_INFORMATION {
  11013. PVOID Object; // IN
  11014. } REG_KEY_HANDLE_CLOSE_INFORMATION, *PREG_KEY_HANDLE_CLOSE_INFORMATION;
  11015. NTSTATUS
  11016. CmRegisterCallback(IN PEX_CALLBACK_FUNCTION Function,
  11017. IN PVOID Context,
  11018. IN OUT PLARGE_INTEGER Cookie
  11019. );
  11020. NTSTATUS
  11021. CmUnRegisterCallback(IN LARGE_INTEGER Cookie);
  11022. //
  11023. // Priority increment definitions. The comment for each definition gives
  11024. // the names of the system services that use the definition when satisfying
  11025. // a wait.
  11026. //
  11027. //
  11028. // Priority increment used when satisfying a wait on an executive event
  11029. // (NtPulseEvent and NtSetEvent)
  11030. //
  11031. #define EVENT_INCREMENT 1
  11032. //
  11033. // Priority increment when no I/O has been done. This is used by device
  11034. // and file system drivers when completing an IRP (IoCompleteRequest).
  11035. //
  11036. #define IO_NO_INCREMENT 0
  11037. //
  11038. // Priority increment for completing CD-ROM I/O. This is used by CD-ROM device
  11039. // and file system drivers when completing an IRP (IoCompleteRequest)
  11040. //
  11041. #define IO_CD_ROM_INCREMENT 1
  11042. //
  11043. // Priority increment for completing disk I/O. This is used by disk device
  11044. // and file system drivers when completing an IRP (IoCompleteRequest)
  11045. //
  11046. #define IO_DISK_INCREMENT 1
  11047. // end_ntifs
  11048. //
  11049. // Priority increment for completing keyboard I/O. This is used by keyboard
  11050. // device drivers when completing an IRP (IoCompleteRequest)
  11051. //
  11052. #define IO_KEYBOARD_INCREMENT 6
  11053. // begin_ntifs
  11054. //
  11055. // Priority increment for completing mailslot I/O. This is used by the mail-
  11056. // slot file system driver when completing an IRP (IoCompleteRequest).
  11057. //
  11058. #define IO_MAILSLOT_INCREMENT 2
  11059. // end_ntifs
  11060. //
  11061. // Priority increment for completing mouse I/O. This is used by mouse device
  11062. // drivers when completing an IRP (IoCompleteRequest)
  11063. //
  11064. #define IO_MOUSE_INCREMENT 6
  11065. // begin_ntifs
  11066. //
  11067. // Priority increment for completing named pipe I/O. This is used by the
  11068. // named pipe file system driver when completing an IRP (IoCompleteRequest).
  11069. //
  11070. #define IO_NAMED_PIPE_INCREMENT 2
  11071. //
  11072. // Priority increment for completing network I/O. This is used by network
  11073. // device and network file system drivers when completing an IRP
  11074. // (IoCompleteRequest).
  11075. //
  11076. #define IO_NETWORK_INCREMENT 2
  11077. // end_ntifs
  11078. //
  11079. // Priority increment for completing parallel I/O. This is used by parallel
  11080. // device drivers when completing an IRP (IoCompleteRequest)
  11081. //
  11082. #define IO_PARALLEL_INCREMENT 1
  11083. //
  11084. // Priority increment for completing serial I/O. This is used by serial device
  11085. // drivers when completing an IRP (IoCompleteRequest)
  11086. //
  11087. #define IO_SERIAL_INCREMENT 2
  11088. //
  11089. // Priority increment for completing sound I/O. This is used by sound device
  11090. // drivers when completing an IRP (IoCompleteRequest)
  11091. //
  11092. #define IO_SOUND_INCREMENT 8
  11093. //
  11094. // Priority increment for completing video I/O. This is used by video device
  11095. // drivers when completing an IRP (IoCompleteRequest)
  11096. //
  11097. #define IO_VIDEO_INCREMENT 1
  11098. //
  11099. // Priority increment used when satisfying a wait on an executive semaphore
  11100. // (NtReleaseSemaphore)
  11101. //
  11102. #define SEMAPHORE_INCREMENT 1
  11103. //
  11104. // Indicates the system may do I/O to physical addresses above 4 GB.
  11105. //
  11106. extern PBOOLEAN Mm64BitPhysicalAddress;
  11107. //
  11108. // Define maximum disk transfer size to be used by MM and Cache Manager,
  11109. // so that packet-oriented disk drivers can optimize their packet allocation
  11110. // to this size.
  11111. //
  11112. #define MM_MAXIMUM_DISK_IO_SIZE (0x10000)
  11113. //++
  11114. //
  11115. // ULONG_PTR
  11116. // ROUND_TO_PAGES (
  11117. // IN ULONG_PTR Size
  11118. // )
  11119. //
  11120. // Routine Description:
  11121. //
  11122. // The ROUND_TO_PAGES macro takes a size in bytes and rounds it up to a
  11123. // multiple of the page size.
  11124. //
  11125. // NOTE: This macro fails for values 0xFFFFFFFF - (PAGE_SIZE - 1).
  11126. //
  11127. // Arguments:
  11128. //
  11129. // Size - Size in bytes to round up to a page multiple.
  11130. //
  11131. // Return Value:
  11132. //
  11133. // Returns the size rounded up to a multiple of the page size.
  11134. //
  11135. //--
  11136. #define ROUND_TO_PAGES(Size) (((ULONG_PTR)(Size) + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1))
  11137. //++
  11138. //
  11139. // ULONG
  11140. // BYTES_TO_PAGES (
  11141. // IN ULONG Size
  11142. // )
  11143. //
  11144. // Routine Description:
  11145. //
  11146. // The BYTES_TO_PAGES macro takes the size in bytes and calculates the
  11147. // number of pages required to contain the bytes.
  11148. //
  11149. // Arguments:
  11150. //
  11151. // Size - Size in bytes.
  11152. //
  11153. // Return Value:
  11154. //
  11155. // Returns the number of pages required to contain the specified size.
  11156. //
  11157. //--
  11158. #define BYTES_TO_PAGES(Size) ((ULONG)((ULONG_PTR)(Size) >> PAGE_SHIFT) + \
  11159. (((ULONG)(Size) & (PAGE_SIZE - 1)) != 0))
  11160. //++
  11161. //
  11162. // ULONG
  11163. // BYTE_OFFSET (
  11164. // IN PVOID Va
  11165. // )
  11166. //
  11167. // Routine Description:
  11168. //
  11169. // The BYTE_OFFSET macro takes a virtual address and returns the byte offset
  11170. // of that address within the page.
  11171. //
  11172. // Arguments:
  11173. //
  11174. // Va - Virtual address.
  11175. //
  11176. // Return Value:
  11177. //
  11178. // Returns the byte offset portion of the virtual address.
  11179. //
  11180. //--
  11181. #define BYTE_OFFSET(Va) ((ULONG)((LONG_PTR)(Va) & (PAGE_SIZE - 1)))
  11182. //++
  11183. //
  11184. // PVOID
  11185. // PAGE_ALIGN (
  11186. // IN PVOID Va
  11187. // )
  11188. //
  11189. // Routine Description:
  11190. //
  11191. // The PAGE_ALIGN macro takes a virtual address and returns a page-aligned
  11192. // virtual address for that page.
  11193. //
  11194. // Arguments:
  11195. //
  11196. // Va - Virtual address.
  11197. //
  11198. // Return Value:
  11199. //
  11200. // Returns the page aligned virtual address.
  11201. //
  11202. //--
  11203. #define PAGE_ALIGN(Va) ((PVOID)((ULONG_PTR)(Va) & ~(PAGE_SIZE - 1)))
  11204. //++
  11205. //
  11206. // ULONG
  11207. // ADDRESS_AND_SIZE_TO_SPAN_PAGES (
  11208. // IN PVOID Va,
  11209. // IN ULONG Size
  11210. // )
  11211. //
  11212. // Routine Description:
  11213. //
  11214. // The ADDRESS_AND_SIZE_TO_SPAN_PAGES macro takes a virtual address and
  11215. // size and returns the number of pages spanned by the size.
  11216. //
  11217. // Arguments:
  11218. //
  11219. // Va - Virtual address.
  11220. //
  11221. // Size - Size in bytes.
  11222. //
  11223. // Return Value:
  11224. //
  11225. // Returns the number of pages spanned by the size.
  11226. //
  11227. //--
  11228. #define ADDRESS_AND_SIZE_TO_SPAN_PAGES(Va,Size) \
  11229. ((ULONG)((((ULONG_PTR)(Va) & (PAGE_SIZE -1)) + (Size) + (PAGE_SIZE - 1)) >> PAGE_SHIFT))
  11230. #if PRAGMA_DEPRECATED_DDK
  11231. #pragma deprecated(COMPUTE_PAGES_SPANNED) // Use ADDRESS_AND_SIZE_TO_SPAN_PAGES
  11232. #endif
  11233. #define COMPUTE_PAGES_SPANNED(Va, Size) ADDRESS_AND_SIZE_TO_SPAN_PAGES(Va,Size)
  11234. //++
  11235. // PPFN_NUMBER
  11236. // MmGetMdlPfnArray (
  11237. // IN PMDL Mdl
  11238. // )
  11239. //
  11240. // Routine Description:
  11241. //
  11242. // The MmGetMdlPfnArray routine returns the virtual address of the
  11243. // first element of the array of physical page numbers associated with
  11244. // the MDL.
  11245. //
  11246. // Arguments:
  11247. //
  11248. // Mdl - Pointer to an MDL.
  11249. //
  11250. // Return Value:
  11251. //
  11252. // Returns the virtual address of the first element of the array of
  11253. // physical page numbers associated with the MDL.
  11254. //
  11255. //--
  11256. #define MmGetMdlPfnArray(Mdl) ((PPFN_NUMBER)(Mdl + 1))
  11257. //++
  11258. //
  11259. // PVOID
  11260. // MmGetMdlVirtualAddress (
  11261. // IN PMDL Mdl
  11262. // )
  11263. //
  11264. // Routine Description:
  11265. //
  11266. // The MmGetMdlVirtualAddress returns the virtual address of the buffer
  11267. // described by the Mdl.
  11268. //
  11269. // Arguments:
  11270. //
  11271. // Mdl - Pointer to an MDL.
  11272. //
  11273. // Return Value:
  11274. //
  11275. // Returns the virtual address of the buffer described by the Mdl
  11276. //
  11277. //--
  11278. #define MmGetMdlVirtualAddress(Mdl) \
  11279. ((PVOID) ((PCHAR) ((Mdl)->StartVa) + (Mdl)->ByteOffset))
  11280. //++
  11281. //
  11282. // ULONG
  11283. // MmGetMdlByteCount (
  11284. // IN PMDL Mdl
  11285. // )
  11286. //
  11287. // Routine Description:
  11288. //
  11289. // The MmGetMdlByteCount returns the length in bytes of the buffer
  11290. // described by the Mdl.
  11291. //
  11292. // Arguments:
  11293. //
  11294. // Mdl - Pointer to an MDL.
  11295. //
  11296. // Return Value:
  11297. //
  11298. // Returns the byte count of the buffer described by the Mdl
  11299. //
  11300. //--
  11301. #define MmGetMdlByteCount(Mdl) ((Mdl)->ByteCount)
  11302. //++
  11303. //
  11304. // ULONG
  11305. // MmGetMdlByteOffset (
  11306. // IN PMDL Mdl
  11307. // )
  11308. //
  11309. // Routine Description:
  11310. //
  11311. // The MmGetMdlByteOffset returns the byte offset within the page
  11312. // of the buffer described by the Mdl.
  11313. //
  11314. // Arguments:
  11315. //
  11316. // Mdl - Pointer to an MDL.
  11317. //
  11318. // Return Value:
  11319. //
  11320. // Returns the byte offset within the page of the buffer described by the Mdl
  11321. //
  11322. //--
  11323. #define MmGetMdlByteOffset(Mdl) ((Mdl)->ByteOffset)
  11324. //++
  11325. //
  11326. // PVOID
  11327. // MmGetMdlStartVa (
  11328. // IN PMDL Mdl
  11329. // )
  11330. //
  11331. // Routine Description:
  11332. //
  11333. // The MmGetMdlBaseVa returns the virtual address of the buffer
  11334. // described by the Mdl rounded down to the nearest page.
  11335. //
  11336. // Arguments:
  11337. //
  11338. // Mdl - Pointer to an MDL.
  11339. //
  11340. // Return Value:
  11341. //
  11342. // Returns the returns the starting virtual address of the MDL.
  11343. //
  11344. //
  11345. //--
  11346. #define MmGetMdlBaseVa(Mdl) ((Mdl)->StartVa)
  11347. typedef enum _MM_SYSTEM_SIZE {
  11348. MmSmallSystem,
  11349. MmMediumSystem,
  11350. MmLargeSystem
  11351. } MM_SYSTEMSIZE;
  11352. NTKERNELAPI
  11353. MM_SYSTEMSIZE
  11354. MmQuerySystemSize(
  11355. VOID
  11356. );
  11357. // end_wdm
  11358. NTKERNELAPI
  11359. BOOLEAN
  11360. MmIsThisAnNtAsSystem(
  11361. VOID
  11362. );
  11363. // begin_wdm
  11364. typedef enum _LOCK_OPERATION {
  11365. IoReadAccess,
  11366. IoWriteAccess,
  11367. IoModifyAccess
  11368. } LOCK_OPERATION;
  11369. NTSTATUS
  11370. MmIsVerifierEnabled (
  11371. OUT PULONG VerifierFlags
  11372. );
  11373. NTSTATUS
  11374. MmAddVerifierThunks (
  11375. IN PVOID ThunkBuffer,
  11376. IN ULONG ThunkBufferSize
  11377. );
  11378. NTKERNELAPI
  11379. VOID
  11380. MmProbeAndLockProcessPages (
  11381. IN OUT PMDL MemoryDescriptorList,
  11382. IN PEPROCESS Process,
  11383. IN KPROCESSOR_MODE AccessMode,
  11384. IN LOCK_OPERATION Operation
  11385. );
  11386. // begin_nthal
  11387. //
  11388. // I/O support routines.
  11389. //
  11390. NTKERNELAPI
  11391. VOID
  11392. MmProbeAndLockPages (
  11393. IN OUT PMDL MemoryDescriptorList,
  11394. IN KPROCESSOR_MODE AccessMode,
  11395. IN LOCK_OPERATION Operation
  11396. );
  11397. NTKERNELAPI
  11398. VOID
  11399. MmUnlockPages (
  11400. IN PMDL MemoryDescriptorList
  11401. );
  11402. NTKERNELAPI
  11403. VOID
  11404. MmBuildMdlForNonPagedPool (
  11405. IN OUT PMDL MemoryDescriptorList
  11406. );
  11407. NTKERNELAPI
  11408. PVOID
  11409. MmMapLockedPages (
  11410. IN PMDL MemoryDescriptorList,
  11411. IN KPROCESSOR_MODE AccessMode
  11412. );
  11413. NTKERNELAPI
  11414. PVOID
  11415. MmGetSystemRoutineAddress (
  11416. IN PUNICODE_STRING SystemRoutineName
  11417. );
  11418. NTKERNELAPI
  11419. NTSTATUS
  11420. MmAdvanceMdl (
  11421. IN PMDL Mdl,
  11422. IN ULONG NumberOfBytes
  11423. );
  11424. // end_wdm
  11425. NTKERNELAPI
  11426. NTSTATUS
  11427. MmMapUserAddressesToPage (
  11428. IN PVOID BaseAddress,
  11429. IN SIZE_T NumberOfBytes,
  11430. IN PVOID PageAddress
  11431. );
  11432. // begin_wdm
  11433. NTKERNELAPI
  11434. NTSTATUS
  11435. MmProtectMdlSystemAddress (
  11436. IN PMDL MemoryDescriptorList,
  11437. IN ULONG NewProtect
  11438. );
  11439. //
  11440. // _MM_PAGE_PRIORITY_ provides a method for the system to handle requests
  11441. // intelligently in low resource conditions.
  11442. //
  11443. // LowPagePriority should be used when it is acceptable to the driver for the
  11444. // mapping request to fail if the system is low on resources. An example of
  11445. // this could be for a non-critical network connection where the driver can
  11446. // handle the failure case when system resources are close to being depleted.
  11447. //
  11448. // NormalPagePriority should be used when it is acceptable to the driver for the
  11449. // mapping request to fail if the system is very low on resources. An example
  11450. // of this could be for a non-critical local filesystem request.
  11451. //
  11452. // HighPagePriority should be used when it is unacceptable to the driver for the
  11453. // mapping request to fail unless the system is completely out of resources.
  11454. // An example of this would be the paging file path in a driver.
  11455. //
  11456. // begin_ntndis
  11457. typedef enum _MM_PAGE_PRIORITY {
  11458. LowPagePriority,
  11459. NormalPagePriority = 16,
  11460. HighPagePriority = 32
  11461. } MM_PAGE_PRIORITY;
  11462. // end_ntndis
  11463. //
  11464. // Note: This function is not available in WDM 1.0
  11465. //
  11466. NTKERNELAPI
  11467. PVOID
  11468. MmMapLockedPagesSpecifyCache (
  11469. IN PMDL MemoryDescriptorList,
  11470. IN KPROCESSOR_MODE AccessMode,
  11471. IN MEMORY_CACHING_TYPE CacheType,
  11472. IN PVOID BaseAddress,
  11473. IN ULONG BugCheckOnFailure,
  11474. IN MM_PAGE_PRIORITY Priority
  11475. );
  11476. NTKERNELAPI
  11477. VOID
  11478. MmUnmapLockedPages (
  11479. IN PVOID BaseAddress,
  11480. IN PMDL MemoryDescriptorList
  11481. );
  11482. PVOID
  11483. MmAllocateMappingAddress (
  11484. IN SIZE_T NumberOfBytes,
  11485. IN ULONG PoolTag
  11486. );
  11487. VOID
  11488. MmFreeMappingAddress (
  11489. IN PVOID BaseAddress,
  11490. IN ULONG PoolTag
  11491. );
  11492. PVOID
  11493. MmMapLockedPagesWithReservedMapping (
  11494. IN PVOID MappingAddress,
  11495. IN ULONG PoolTag,
  11496. IN PMDL MemoryDescriptorList,
  11497. IN MEMORY_CACHING_TYPE CacheType
  11498. );
  11499. VOID
  11500. MmUnmapReservedMapping (
  11501. IN PVOID BaseAddress,
  11502. IN ULONG PoolTag,
  11503. IN PMDL MemoryDescriptorList
  11504. );
  11505. // end_wdm
  11506. typedef struct _PHYSICAL_MEMORY_RANGE {
  11507. PHYSICAL_ADDRESS BaseAddress;
  11508. LARGE_INTEGER NumberOfBytes;
  11509. } PHYSICAL_MEMORY_RANGE, *PPHYSICAL_MEMORY_RANGE;
  11510. NTKERNELAPI
  11511. NTSTATUS
  11512. MmAddPhysicalMemory (
  11513. IN PPHYSICAL_ADDRESS StartAddress,
  11514. IN OUT PLARGE_INTEGER NumberOfBytes
  11515. );
  11516. NTKERNELAPI
  11517. NTSTATUS
  11518. MmAddPhysicalMemoryEx (
  11519. IN PPHYSICAL_ADDRESS StartAddress,
  11520. IN OUT PLARGE_INTEGER NumberOfBytes,
  11521. IN ULONG Flags
  11522. );
  11523. NTKERNELAPI
  11524. NTSTATUS
  11525. MmRemovePhysicalMemory (
  11526. IN PPHYSICAL_ADDRESS StartAddress,
  11527. IN OUT PLARGE_INTEGER NumberOfBytes
  11528. );
  11529. NTKERNELAPI
  11530. NTSTATUS
  11531. MmRemovePhysicalMemoryEx (
  11532. IN PPHYSICAL_ADDRESS StartAddress,
  11533. IN OUT PLARGE_INTEGER NumberOfBytes,
  11534. IN ULONG Flags
  11535. );
  11536. NTKERNELAPI
  11537. PPHYSICAL_MEMORY_RANGE
  11538. MmGetPhysicalMemoryRanges (
  11539. VOID
  11540. );
  11541. NTSTATUS
  11542. MmMarkPhysicalMemoryAsGood (
  11543. IN PPHYSICAL_ADDRESS StartAddress,
  11544. IN OUT PLARGE_INTEGER NumberOfBytes
  11545. );
  11546. NTSTATUS
  11547. MmMarkPhysicalMemoryAsBad (
  11548. IN PPHYSICAL_ADDRESS StartAddress,
  11549. IN OUT PLARGE_INTEGER NumberOfBytes
  11550. );
  11551. // begin_wdm
  11552. NTKERNELAPI
  11553. PMDL
  11554. MmAllocatePagesForMdl (
  11555. IN PHYSICAL_ADDRESS LowAddress,
  11556. IN PHYSICAL_ADDRESS HighAddress,
  11557. IN PHYSICAL_ADDRESS SkipBytes,
  11558. IN SIZE_T TotalBytes
  11559. );
  11560. NTKERNELAPI
  11561. VOID
  11562. MmFreePagesFromMdl (
  11563. IN PMDL MemoryDescriptorList
  11564. );
  11565. NTKERNELAPI
  11566. PVOID
  11567. MmMapIoSpace (
  11568. IN PHYSICAL_ADDRESS PhysicalAddress,
  11569. IN SIZE_T NumberOfBytes,
  11570. IN MEMORY_CACHING_TYPE CacheType
  11571. );
  11572. NTKERNELAPI
  11573. VOID
  11574. MmUnmapIoSpace (
  11575. IN PVOID BaseAddress,
  11576. IN SIZE_T NumberOfBytes
  11577. );
  11578. NTKERNELAPI
  11579. PVOID
  11580. MmMapVideoDisplay (
  11581. IN PHYSICAL_ADDRESS PhysicalAddress,
  11582. IN SIZE_T NumberOfBytes,
  11583. IN MEMORY_CACHING_TYPE CacheType
  11584. );
  11585. NTKERNELAPI
  11586. VOID
  11587. MmUnmapVideoDisplay (
  11588. IN PVOID BaseAddress,
  11589. IN SIZE_T NumberOfBytes
  11590. );
  11591. NTKERNELAPI
  11592. PHYSICAL_ADDRESS
  11593. MmGetPhysicalAddress (
  11594. IN PVOID BaseAddress
  11595. );
  11596. NTKERNELAPI
  11597. PVOID
  11598. MmGetVirtualForPhysical (
  11599. IN PHYSICAL_ADDRESS PhysicalAddress
  11600. );
  11601. NTKERNELAPI
  11602. PVOID
  11603. MmAllocateContiguousMemory (
  11604. IN SIZE_T NumberOfBytes,
  11605. IN PHYSICAL_ADDRESS HighestAcceptableAddress
  11606. );
  11607. NTKERNELAPI
  11608. PVOID
  11609. MmAllocateContiguousMemorySpecifyCache (
  11610. IN SIZE_T NumberOfBytes,
  11611. IN PHYSICAL_ADDRESS LowestAcceptableAddress,
  11612. IN PHYSICAL_ADDRESS HighestAcceptableAddress,
  11613. IN PHYSICAL_ADDRESS BoundaryAddressMultiple OPTIONAL,
  11614. IN MEMORY_CACHING_TYPE CacheType
  11615. );
  11616. NTKERNELAPI
  11617. VOID
  11618. MmFreeContiguousMemory (
  11619. IN PVOID BaseAddress
  11620. );
  11621. NTKERNELAPI
  11622. VOID
  11623. MmFreeContiguousMemorySpecifyCache (
  11624. IN PVOID BaseAddress,
  11625. IN SIZE_T NumberOfBytes,
  11626. IN MEMORY_CACHING_TYPE CacheType
  11627. );
  11628. NTKERNELAPI
  11629. PVOID
  11630. MmAllocateNonCachedMemory (
  11631. IN SIZE_T NumberOfBytes
  11632. );
  11633. NTKERNELAPI
  11634. VOID
  11635. MmFreeNonCachedMemory (
  11636. IN PVOID BaseAddress,
  11637. IN SIZE_T NumberOfBytes
  11638. );
  11639. NTKERNELAPI
  11640. BOOLEAN
  11641. MmIsAddressValid (
  11642. IN PVOID VirtualAddress
  11643. );
  11644. DECLSPEC_DEPRECATED_DDK
  11645. NTKERNELAPI
  11646. BOOLEAN
  11647. MmIsNonPagedSystemAddressValid (
  11648. IN PVOID VirtualAddress
  11649. );
  11650. // begin_wdm
  11651. NTKERNELAPI
  11652. SIZE_T
  11653. MmSizeOfMdl(
  11654. IN PVOID Base,
  11655. IN SIZE_T Length
  11656. );
  11657. DECLSPEC_DEPRECATED_DDK // Use IoCreateMdl
  11658. NTKERNELAPI
  11659. PMDL
  11660. MmCreateMdl(
  11661. IN PMDL MemoryDescriptorList OPTIONAL,
  11662. IN PVOID Base,
  11663. IN SIZE_T Length
  11664. );
  11665. NTKERNELAPI
  11666. PVOID
  11667. MmLockPagableDataSection(
  11668. IN PVOID AddressWithinSection
  11669. );
  11670. // end_wdm
  11671. NTKERNELAPI
  11672. VOID
  11673. MmLockPagableSectionByHandle (
  11674. IN PVOID ImageSectionHandle
  11675. );
  11676. NTKERNELAPI
  11677. VOID
  11678. MmResetDriverPaging (
  11679. IN PVOID AddressWithinSection
  11680. );
  11681. NTKERNELAPI
  11682. PVOID
  11683. MmPageEntireDriver (
  11684. IN PVOID AddressWithinSection
  11685. );
  11686. NTKERNELAPI
  11687. VOID
  11688. MmUnlockPagableImageSection(
  11689. IN PVOID ImageSectionHandle
  11690. );
  11691. // end_wdm end_ntosp
  11692. // begin_ntosp
  11693. NTKERNELAPI
  11694. HANDLE
  11695. MmSecureVirtualMemory (
  11696. IN PVOID Address,
  11697. IN SIZE_T Size,
  11698. IN ULONG ProbeMode
  11699. );
  11700. NTKERNELAPI
  11701. VOID
  11702. MmUnsecureVirtualMemory (
  11703. IN HANDLE SecureHandle
  11704. );
  11705. // end_ntosp
  11706. NTKERNELAPI
  11707. NTSTATUS
  11708. MmMapViewInSystemSpace (
  11709. IN PVOID Section,
  11710. OUT PVOID *MappedBase,
  11711. IN PSIZE_T ViewSize
  11712. );
  11713. NTKERNELAPI
  11714. NTSTATUS
  11715. MmUnmapViewInSystemSpace (
  11716. IN PVOID MappedBase
  11717. );
  11718. // begin_ntosp
  11719. NTKERNELAPI
  11720. NTSTATUS
  11721. MmMapViewInSessionSpace (
  11722. IN PVOID Section,
  11723. OUT PVOID *MappedBase,
  11724. IN OUT PSIZE_T ViewSize
  11725. );
  11726. NTKERNELAPI
  11727. NTSTATUS
  11728. MmUnmapViewInSessionSpace (
  11729. IN PVOID MappedBase
  11730. );
  11731. // end_ntosp
  11732. // begin_wdm begin_ntosp
  11733. //++
  11734. //
  11735. // VOID
  11736. // MmInitializeMdl (
  11737. // IN PMDL MemoryDescriptorList,
  11738. // IN PVOID BaseVa,
  11739. // IN SIZE_T Length
  11740. // )
  11741. //
  11742. // Routine Description:
  11743. //
  11744. // This routine initializes the header of a Memory Descriptor List (MDL).
  11745. //
  11746. // Arguments:
  11747. //
  11748. // MemoryDescriptorList - Pointer to the MDL to initialize.
  11749. //
  11750. // BaseVa - Base virtual address mapped by the MDL.
  11751. //
  11752. // Length - Length, in bytes, of the buffer mapped by the MDL.
  11753. //
  11754. // Return Value:
  11755. //
  11756. // None.
  11757. //
  11758. //--
  11759. #define MmInitializeMdl(MemoryDescriptorList, BaseVa, Length) { \
  11760. (MemoryDescriptorList)->Next = (PMDL) NULL; \
  11761. (MemoryDescriptorList)->Size = (CSHORT)(sizeof(MDL) + \
  11762. (sizeof(PFN_NUMBER) * ADDRESS_AND_SIZE_TO_SPAN_PAGES((BaseVa), (Length)))); \
  11763. (MemoryDescriptorList)->MdlFlags = 0; \
  11764. (MemoryDescriptorList)->StartVa = (PVOID) PAGE_ALIGN((BaseVa)); \
  11765. (MemoryDescriptorList)->ByteOffset = BYTE_OFFSET((BaseVa)); \
  11766. (MemoryDescriptorList)->ByteCount = (ULONG)(Length); \
  11767. }
  11768. //++
  11769. //
  11770. // PVOID
  11771. // MmGetSystemAddressForMdlSafe (
  11772. // IN PMDL MDL,
  11773. // IN MM_PAGE_PRIORITY PRIORITY
  11774. // )
  11775. //
  11776. // Routine Description:
  11777. //
  11778. // This routine returns the mapped address of an MDL. If the
  11779. // Mdl is not already mapped or a system address, it is mapped.
  11780. //
  11781. // Arguments:
  11782. //
  11783. // MemoryDescriptorList - Pointer to the MDL to map.
  11784. //
  11785. // Priority - Supplies an indication as to how important it is that this
  11786. // request succeed under low available PTE conditions.
  11787. //
  11788. // Return Value:
  11789. //
  11790. // Returns the base address where the pages are mapped. The base address
  11791. // has the same offset as the virtual address in the MDL.
  11792. //
  11793. // Unlike MmGetSystemAddressForMdl, Safe guarantees that it will always
  11794. // return NULL on failure instead of bugchecking the system.
  11795. //
  11796. // This macro is not usable by WDM 1.0 drivers as 1.0 did not include
  11797. // MmMapLockedPagesSpecifyCache. The solution for WDM 1.0 drivers is to
  11798. // provide synchronization and set/reset the MDL_MAPPING_CAN_FAIL bit.
  11799. //
  11800. //--
  11801. #define MmGetSystemAddressForMdlSafe(MDL, PRIORITY) \
  11802. (((MDL)->MdlFlags & (MDL_MAPPED_TO_SYSTEM_VA | \
  11803. MDL_SOURCE_IS_NONPAGED_POOL)) ? \
  11804. ((MDL)->MappedSystemVa) : \
  11805. (MmMapLockedPagesSpecifyCache((MDL), \
  11806. KernelMode, \
  11807. MmCached, \
  11808. NULL, \
  11809. FALSE, \
  11810. (PRIORITY))))
  11811. //++
  11812. //
  11813. // PVOID
  11814. // MmGetSystemAddressForMdl (
  11815. // IN PMDL MDL
  11816. // )
  11817. //
  11818. // Routine Description:
  11819. //
  11820. // This routine returns the mapped address of an MDL, if the
  11821. // Mdl is not already mapped or a system address, it is mapped.
  11822. //
  11823. // Arguments:
  11824. //
  11825. // MemoryDescriptorList - Pointer to the MDL to map.
  11826. //
  11827. // Return Value:
  11828. //
  11829. // Returns the base address where the pages are mapped. The base address
  11830. // has the same offset as the virtual address in the MDL.
  11831. //
  11832. //--
  11833. //#define MmGetSystemAddressForMdl(MDL)
  11834. // (((MDL)->MdlFlags & (MDL_MAPPED_TO_SYSTEM_VA)) ?
  11835. // ((MDL)->MappedSystemVa) :
  11836. // ((((MDL)->MdlFlags & (MDL_SOURCE_IS_NONPAGED_POOL)) ?
  11837. // ((PVOID)((ULONG)(MDL)->StartVa | (MDL)->ByteOffset)) :
  11838. // (MmMapLockedPages((MDL),KernelMode)))))
  11839. #if PRAGMA_DEPRECATED_DDK
  11840. #pragma deprecated(MmGetSystemAddressForMdl) // Use MmGetSystemAddressForMdlSafe
  11841. #endif
  11842. #define MmGetSystemAddressForMdl(MDL) \
  11843. (((MDL)->MdlFlags & (MDL_MAPPED_TO_SYSTEM_VA | \
  11844. MDL_SOURCE_IS_NONPAGED_POOL)) ? \
  11845. ((MDL)->MappedSystemVa) : \
  11846. (MmMapLockedPages((MDL),KernelMode)))
  11847. //++
  11848. //
  11849. // VOID
  11850. // MmPrepareMdlForReuse (
  11851. // IN PMDL MDL
  11852. // )
  11853. //
  11854. // Routine Description:
  11855. //
  11856. // This routine will take all of the steps necessary to allow an MDL to be
  11857. // re-used.
  11858. //
  11859. // Arguments:
  11860. //
  11861. // MemoryDescriptorList - Pointer to the MDL that will be re-used.
  11862. //
  11863. // Return Value:
  11864. //
  11865. // None.
  11866. //
  11867. //--
  11868. #define MmPrepareMdlForReuse(MDL) \
  11869. if (((MDL)->MdlFlags & MDL_PARTIAL_HAS_BEEN_MAPPED) != 0) { \
  11870. ASSERT(((MDL)->MdlFlags & MDL_PARTIAL) != 0); \
  11871. MmUnmapLockedPages( (MDL)->MappedSystemVa, (MDL) ); \
  11872. } else if (((MDL)->MdlFlags & MDL_PARTIAL) == 0) { \
  11873. ASSERT(((MDL)->MdlFlags & MDL_MAPPED_TO_SYSTEM_VA) == 0); \
  11874. }
  11875. typedef NTSTATUS (*PMM_DLL_INITIALIZE)(
  11876. IN PUNICODE_STRING RegistryPath
  11877. );
  11878. typedef NTSTATUS (*PMM_DLL_UNLOAD)(
  11879. VOID
  11880. );
  11881. //
  11882. // Define an empty typedef for the _DRIVER_OBJECT structure so it may be
  11883. // referenced by function types before it is actually defined.
  11884. //
  11885. struct _DRIVER_OBJECT;
  11886. NTKERNELAPI
  11887. LOGICAL
  11888. MmIsDriverVerifying (
  11889. IN struct _DRIVER_OBJECT *DriverObject
  11890. );
  11891. //
  11892. // Security operation codes
  11893. //
  11894. typedef enum _SECURITY_OPERATION_CODE {
  11895. SetSecurityDescriptor,
  11896. QuerySecurityDescriptor,
  11897. DeleteSecurityDescriptor,
  11898. AssignSecurityDescriptor
  11899. } SECURITY_OPERATION_CODE, *PSECURITY_OPERATION_CODE;
  11900. //
  11901. // Data structure used to capture subject security context
  11902. // for access validations and auditing.
  11903. //
  11904. // THE FIELDS OF THIS DATA STRUCTURE SHOULD BE CONSIDERED OPAQUE
  11905. // BY ALL EXCEPT THE SECURITY ROUTINES.
  11906. //
  11907. typedef struct _SECURITY_SUBJECT_CONTEXT {
  11908. PACCESS_TOKEN ClientToken;
  11909. SECURITY_IMPERSONATION_LEVEL ImpersonationLevel;
  11910. PACCESS_TOKEN PrimaryToken;
  11911. PVOID ProcessAuditId;
  11912. } SECURITY_SUBJECT_CONTEXT, *PSECURITY_SUBJECT_CONTEXT;
  11913. ///////////////////////////////////////////////////////////////////////////////
  11914. // //
  11915. // ACCESS_STATE and related structures //
  11916. // //
  11917. ///////////////////////////////////////////////////////////////////////////////
  11918. //
  11919. // Initial Privilege Set - Room for three privileges, which should
  11920. // be enough for most applications. This structure exists so that
  11921. // it can be imbedded in an ACCESS_STATE structure. Use PRIVILEGE_SET
  11922. // for all other references to Privilege sets.
  11923. //
  11924. #define INITIAL_PRIVILEGE_COUNT 3
  11925. typedef struct _INITIAL_PRIVILEGE_SET {
  11926. ULONG PrivilegeCount;
  11927. ULONG Control;
  11928. LUID_AND_ATTRIBUTES Privilege[INITIAL_PRIVILEGE_COUNT];
  11929. } INITIAL_PRIVILEGE_SET, * PINITIAL_PRIVILEGE_SET;
  11930. //
  11931. // Combine the information that describes the state
  11932. // of an access-in-progress into a single structure
  11933. //
  11934. typedef struct _ACCESS_STATE {
  11935. LUID OperationID;
  11936. BOOLEAN SecurityEvaluated;
  11937. BOOLEAN GenerateAudit;
  11938. BOOLEAN GenerateOnClose;
  11939. BOOLEAN PrivilegesAllocated;
  11940. ULONG Flags;
  11941. ACCESS_MASK RemainingDesiredAccess;
  11942. ACCESS_MASK PreviouslyGrantedAccess;
  11943. ACCESS_MASK OriginalDesiredAccess;
  11944. SECURITY_SUBJECT_CONTEXT SubjectSecurityContext;
  11945. PSECURITY_DESCRIPTOR SecurityDescriptor;
  11946. PVOID AuxData;
  11947. union {
  11948. INITIAL_PRIVILEGE_SET InitialPrivilegeSet;
  11949. PRIVILEGE_SET PrivilegeSet;
  11950. } Privileges;
  11951. BOOLEAN AuditPrivileges;
  11952. UNICODE_STRING ObjectName;
  11953. UNICODE_STRING ObjectTypeName;
  11954. } ACCESS_STATE, *PACCESS_STATE;
  11955. NTKERNELAPI
  11956. NTSTATUS
  11957. SeAssignSecurity (
  11958. IN PSECURITY_DESCRIPTOR ParentDescriptor OPTIONAL,
  11959. IN PSECURITY_DESCRIPTOR ExplicitDescriptor,
  11960. OUT PSECURITY_DESCRIPTOR *NewDescriptor,
  11961. IN BOOLEAN IsDirectoryObject,
  11962. IN PSECURITY_SUBJECT_CONTEXT SubjectContext,
  11963. IN PGENERIC_MAPPING GenericMapping,
  11964. IN POOL_TYPE PoolType
  11965. );
  11966. NTKERNELAPI
  11967. NTSTATUS
  11968. SeAssignSecurityEx (
  11969. IN PSECURITY_DESCRIPTOR ParentDescriptor OPTIONAL,
  11970. IN PSECURITY_DESCRIPTOR ExplicitDescriptor OPTIONAL,
  11971. OUT PSECURITY_DESCRIPTOR *NewDescriptor,
  11972. IN GUID *ObjectType OPTIONAL,
  11973. IN BOOLEAN IsDirectoryObject,
  11974. IN ULONG AutoInheritFlags,
  11975. IN PSECURITY_SUBJECT_CONTEXT SubjectContext,
  11976. IN PGENERIC_MAPPING GenericMapping,
  11977. IN POOL_TYPE PoolType
  11978. );
  11979. NTKERNELAPI
  11980. NTSTATUS
  11981. SeDeassignSecurity (
  11982. IN OUT PSECURITY_DESCRIPTOR *SecurityDescriptor
  11983. );
  11984. NTKERNELAPI
  11985. BOOLEAN
  11986. SeAccessCheck (
  11987. IN PSECURITY_DESCRIPTOR SecurityDescriptor,
  11988. IN PSECURITY_SUBJECT_CONTEXT SubjectSecurityContext,
  11989. IN BOOLEAN SubjectContextLocked,
  11990. IN ACCESS_MASK DesiredAccess,
  11991. IN ACCESS_MASK PreviouslyGrantedAccess,
  11992. OUT PPRIVILEGE_SET *Privileges OPTIONAL,
  11993. IN PGENERIC_MAPPING GenericMapping,
  11994. IN KPROCESSOR_MODE AccessMode,
  11995. OUT PACCESS_MASK GrantedAccess,
  11996. OUT PNTSTATUS AccessStatus
  11997. );
  11998. #ifdef SE_NTFS_WORLD_CACHE
  11999. VOID
  12000. SeGetWorldRights (
  12001. IN PSECURITY_DESCRIPTOR SecurityDescriptor,
  12002. IN PGENERIC_MAPPING GenericMapping,
  12003. OUT PACCESS_MASK GrantedAccess
  12004. );
  12005. #endif
  12006. NTKERNELAPI
  12007. BOOLEAN
  12008. SeValidSecurityDescriptor(
  12009. IN ULONG Length,
  12010. IN PSECURITY_DESCRIPTOR SecurityDescriptor
  12011. );
  12012. NTKERNELAPI
  12013. BOOLEAN
  12014. SeSinglePrivilegeCheck(
  12015. LUID PrivilegeValue,
  12016. KPROCESSOR_MODE PreviousMode
  12017. );
  12018. //
  12019. // System Thread and Process Creation and Termination
  12020. //
  12021. NTKERNELAPI
  12022. NTSTATUS
  12023. PsCreateSystemThread(
  12024. OUT PHANDLE ThreadHandle,
  12025. IN ULONG DesiredAccess,
  12026. IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL,
  12027. IN HANDLE ProcessHandle OPTIONAL,
  12028. OUT PCLIENT_ID ClientId OPTIONAL,
  12029. IN PKSTART_ROUTINE StartRoutine,
  12030. IN PVOID StartContext
  12031. );
  12032. NTKERNELAPI
  12033. NTSTATUS
  12034. PsTerminateSystemThread(
  12035. IN NTSTATUS ExitStatus
  12036. );
  12037. typedef
  12038. VOID
  12039. (*PCREATE_PROCESS_NOTIFY_ROUTINE)(
  12040. IN HANDLE ParentId,
  12041. IN HANDLE ProcessId,
  12042. IN BOOLEAN Create
  12043. );
  12044. NTSTATUS
  12045. PsSetCreateProcessNotifyRoutine(
  12046. IN PCREATE_PROCESS_NOTIFY_ROUTINE NotifyRoutine,
  12047. IN BOOLEAN Remove
  12048. );
  12049. typedef
  12050. VOID
  12051. (*PCREATE_THREAD_NOTIFY_ROUTINE)(
  12052. IN HANDLE ProcessId,
  12053. IN HANDLE ThreadId,
  12054. IN BOOLEAN Create
  12055. );
  12056. NTSTATUS
  12057. PsSetCreateThreadNotifyRoutine(
  12058. IN PCREATE_THREAD_NOTIFY_ROUTINE NotifyRoutine
  12059. );
  12060. NTSTATUS
  12061. PsRemoveCreateThreadNotifyRoutine (
  12062. IN PCREATE_THREAD_NOTIFY_ROUTINE NotifyRoutine
  12063. );
  12064. //
  12065. // Structures for Load Image Notify
  12066. //
  12067. typedef struct _IMAGE_INFO {
  12068. union {
  12069. ULONG Properties;
  12070. struct {
  12071. ULONG ImageAddressingMode : 8; // code addressing mode
  12072. ULONG SystemModeImage : 1; // system mode image
  12073. ULONG ImageMappedToAllPids : 1; // image mapped into all processes
  12074. ULONG Reserved : 22;
  12075. };
  12076. };
  12077. PVOID ImageBase;
  12078. ULONG ImageSelector;
  12079. SIZE_T ImageSize;
  12080. ULONG ImageSectionNumber;
  12081. } IMAGE_INFO, *PIMAGE_INFO;
  12082. #define IMAGE_ADDRESSING_MODE_32BIT 3
  12083. typedef
  12084. VOID
  12085. (*PLOAD_IMAGE_NOTIFY_ROUTINE)(
  12086. IN PUNICODE_STRING FullImageName,
  12087. IN HANDLE ProcessId, // pid into which image is being mapped
  12088. IN PIMAGE_INFO ImageInfo
  12089. );
  12090. NTSTATUS
  12091. PsSetLoadImageNotifyRoutine(
  12092. IN PLOAD_IMAGE_NOTIFY_ROUTINE NotifyRoutine
  12093. );
  12094. NTSTATUS
  12095. PsRemoveLoadImageNotifyRoutine(
  12096. IN PLOAD_IMAGE_NOTIFY_ROUTINE NotifyRoutine
  12097. );
  12098. HANDLE
  12099. PsGetCurrentProcessId( VOID );
  12100. HANDLE
  12101. PsGetCurrentThreadId( VOID );
  12102. // end_ntosp
  12103. BOOLEAN
  12104. PsGetVersion(
  12105. PULONG MajorVersion OPTIONAL,
  12106. PULONG MinorVersion OPTIONAL,
  12107. PULONG BuildNumber OPTIONAL,
  12108. PUNICODE_STRING CSDVersion OPTIONAL
  12109. );
  12110. //
  12111. // Define I/O system data structure type codes. Each major data structure in
  12112. // the I/O system has a type code The type field in each structure is at the
  12113. // same offset. The following values can be used to determine which type of
  12114. // data structure a pointer refers to.
  12115. //
  12116. #define IO_TYPE_ADAPTER 0x00000001
  12117. #define IO_TYPE_CONTROLLER 0x00000002
  12118. #define IO_TYPE_DEVICE 0x00000003
  12119. #define IO_TYPE_DRIVER 0x00000004
  12120. #define IO_TYPE_FILE 0x00000005
  12121. #define IO_TYPE_IRP 0x00000006
  12122. #define IO_TYPE_MASTER_ADAPTER 0x00000007
  12123. #define IO_TYPE_OPEN_PACKET 0x00000008
  12124. #define IO_TYPE_TIMER 0x00000009
  12125. #define IO_TYPE_VPB 0x0000000a
  12126. #define IO_TYPE_ERROR_LOG 0x0000000b
  12127. #define IO_TYPE_ERROR_MESSAGE 0x0000000c
  12128. #define IO_TYPE_DEVICE_OBJECT_EXTENSION 0x0000000d
  12129. //
  12130. // Define the major function codes for IRPs.
  12131. //
  12132. #define IRP_MJ_CREATE 0x00
  12133. #define IRP_MJ_CREATE_NAMED_PIPE 0x01
  12134. #define IRP_MJ_CLOSE 0x02
  12135. #define IRP_MJ_READ 0x03
  12136. #define IRP_MJ_WRITE 0x04
  12137. #define IRP_MJ_QUERY_INFORMATION 0x05
  12138. #define IRP_MJ_SET_INFORMATION 0x06
  12139. #define IRP_MJ_QUERY_EA 0x07
  12140. #define IRP_MJ_SET_EA 0x08
  12141. #define IRP_MJ_FLUSH_BUFFERS 0x09
  12142. #define IRP_MJ_QUERY_VOLUME_INFORMATION 0x0a
  12143. #define IRP_MJ_SET_VOLUME_INFORMATION 0x0b
  12144. #define IRP_MJ_DIRECTORY_CONTROL 0x0c
  12145. #define IRP_MJ_FILE_SYSTEM_CONTROL 0x0d
  12146. #define IRP_MJ_DEVICE_CONTROL 0x0e
  12147. #define IRP_MJ_INTERNAL_DEVICE_CONTROL 0x0f
  12148. #define IRP_MJ_SHUTDOWN 0x10
  12149. #define IRP_MJ_LOCK_CONTROL 0x11
  12150. #define IRP_MJ_CLEANUP 0x12
  12151. #define IRP_MJ_CREATE_MAILSLOT 0x13
  12152. #define IRP_MJ_QUERY_SECURITY 0x14
  12153. #define IRP_MJ_SET_SECURITY 0x15
  12154. #define IRP_MJ_POWER 0x16
  12155. #define IRP_MJ_SYSTEM_CONTROL 0x17
  12156. #define IRP_MJ_DEVICE_CHANGE 0x18
  12157. #define IRP_MJ_QUERY_QUOTA 0x19
  12158. #define IRP_MJ_SET_QUOTA 0x1a
  12159. #define IRP_MJ_PNP 0x1b
  12160. #define IRP_MJ_PNP_POWER IRP_MJ_PNP // Obsolete....
  12161. #define IRP_MJ_MAXIMUM_FUNCTION 0x1b
  12162. //
  12163. // Make the Scsi major code the same as internal device control.
  12164. //
  12165. #define IRP_MJ_SCSI IRP_MJ_INTERNAL_DEVICE_CONTROL
  12166. //
  12167. // Define the minor function codes for IRPs. The lower 128 codes, from 0x00 to
  12168. // 0x7f are reserved to Microsoft. The upper 128 codes, from 0x80 to 0xff, are
  12169. // reserved to customers of Microsoft.
  12170. //
  12171. // end_wdm end_ntndis
  12172. //
  12173. // Directory control minor function codes
  12174. //
  12175. #define IRP_MN_QUERY_DIRECTORY 0x01
  12176. #define IRP_MN_NOTIFY_CHANGE_DIRECTORY 0x02
  12177. //
  12178. // File system control minor function codes. Note that "user request" is
  12179. // assumed to be zero by both the I/O system and file systems. Do not change
  12180. // this value.
  12181. //
  12182. #define IRP_MN_USER_FS_REQUEST 0x00
  12183. #define IRP_MN_MOUNT_VOLUME 0x01
  12184. #define IRP_MN_VERIFY_VOLUME 0x02
  12185. #define IRP_MN_LOAD_FILE_SYSTEM 0x03
  12186. #define IRP_MN_TRACK_LINK 0x04 // To be obsoleted soon
  12187. #define IRP_MN_KERNEL_CALL 0x04
  12188. //
  12189. // Lock control minor function codes
  12190. //
  12191. #define IRP_MN_LOCK 0x01
  12192. #define IRP_MN_UNLOCK_SINGLE 0x02
  12193. #define IRP_MN_UNLOCK_ALL 0x03
  12194. #define IRP_MN_UNLOCK_ALL_BY_KEY 0x04
  12195. //
  12196. // Read and Write minor function codes for file systems supporting Lan Manager
  12197. // software. All of these subfunction codes are invalid if the file has been
  12198. // opened with FO_NO_INTERMEDIATE_BUFFERING. They are also invalid in combi-
  12199. // nation with synchronous calls (Irp Flag or file open option).
  12200. //
  12201. // Note that "normal" is assumed to be zero by both the I/O system and file
  12202. // systems. Do not change this value.
  12203. //
  12204. #define IRP_MN_NORMAL 0x00
  12205. #define IRP_MN_DPC 0x01
  12206. #define IRP_MN_MDL 0x02
  12207. #define IRP_MN_COMPLETE 0x04
  12208. #define IRP_MN_COMPRESSED 0x08
  12209. #define IRP_MN_MDL_DPC (IRP_MN_MDL | IRP_MN_DPC)
  12210. #define IRP_MN_COMPLETE_MDL (IRP_MN_COMPLETE | IRP_MN_MDL)
  12211. #define IRP_MN_COMPLETE_MDL_DPC (IRP_MN_COMPLETE_MDL | IRP_MN_DPC)
  12212. // begin_wdm
  12213. //
  12214. // Device Control Request minor function codes for SCSI support. Note that
  12215. // user requests are assumed to be zero.
  12216. //
  12217. #define IRP_MN_SCSI_CLASS 0x01
  12218. //
  12219. // PNP minor function codes.
  12220. //
  12221. #define IRP_MN_START_DEVICE 0x00
  12222. #define IRP_MN_QUERY_REMOVE_DEVICE 0x01
  12223. #define IRP_MN_REMOVE_DEVICE 0x02
  12224. #define IRP_MN_CANCEL_REMOVE_DEVICE 0x03
  12225. #define IRP_MN_STOP_DEVICE 0x04
  12226. #define IRP_MN_QUERY_STOP_DEVICE 0x05
  12227. #define IRP_MN_CANCEL_STOP_DEVICE 0x06
  12228. #define IRP_MN_QUERY_DEVICE_RELATIONS 0x07
  12229. #define IRP_MN_QUERY_INTERFACE 0x08
  12230. #define IRP_MN_QUERY_CAPABILITIES 0x09
  12231. #define IRP_MN_QUERY_RESOURCES 0x0A
  12232. #define IRP_MN_QUERY_RESOURCE_REQUIREMENTS 0x0B
  12233. #define IRP_MN_QUERY_DEVICE_TEXT 0x0C
  12234. #define IRP_MN_FILTER_RESOURCE_REQUIREMENTS 0x0D
  12235. #define IRP_MN_READ_CONFIG 0x0F
  12236. #define IRP_MN_WRITE_CONFIG 0x10
  12237. #define IRP_MN_EJECT 0x11
  12238. #define IRP_MN_SET_LOCK 0x12
  12239. #define IRP_MN_QUERY_ID 0x13
  12240. #define IRP_MN_QUERY_PNP_DEVICE_STATE 0x14
  12241. #define IRP_MN_QUERY_BUS_INFORMATION 0x15
  12242. #define IRP_MN_DEVICE_USAGE_NOTIFICATION 0x16
  12243. #define IRP_MN_SURPRISE_REMOVAL 0x17
  12244. // end_wdm
  12245. #define IRP_MN_QUERY_LEGACY_BUS_INFORMATION 0x18
  12246. // begin_wdm
  12247. //
  12248. // POWER minor function codes
  12249. //
  12250. #define IRP_MN_WAIT_WAKE 0x00
  12251. #define IRP_MN_POWER_SEQUENCE 0x01
  12252. #define IRP_MN_SET_POWER 0x02
  12253. #define IRP_MN_QUERY_POWER 0x03
  12254. // begin_ntminiport
  12255. //
  12256. // WMI minor function codes under IRP_MJ_SYSTEM_CONTROL
  12257. //
  12258. #define IRP_MN_QUERY_ALL_DATA 0x00
  12259. #define IRP_MN_QUERY_SINGLE_INSTANCE 0x01
  12260. #define IRP_MN_CHANGE_SINGLE_INSTANCE 0x02
  12261. #define IRP_MN_CHANGE_SINGLE_ITEM 0x03
  12262. #define IRP_MN_ENABLE_EVENTS 0x04
  12263. #define IRP_MN_DISABLE_EVENTS 0x05
  12264. #define IRP_MN_ENABLE_COLLECTION 0x06
  12265. #define IRP_MN_DISABLE_COLLECTION 0x07
  12266. #define IRP_MN_REGINFO 0x08
  12267. #define IRP_MN_EXECUTE_METHOD 0x09
  12268. // Minor code 0x0a is reserved
  12269. #define IRP_MN_REGINFO_EX 0x0b
  12270. // end_ntminiport
  12271. //
  12272. // Define option flags for IoCreateFile. Note that these values must be
  12273. // exactly the same as the SL_... flags for a create function. Note also
  12274. // that there are flags that may be passed to IoCreateFile that are not
  12275. // placed in the stack location for the create IRP. These flags start in
  12276. // the next byte.
  12277. //
  12278. #define IO_FORCE_ACCESS_CHECK 0x0001
  12279. #define IO_NO_PARAMETER_CHECKING 0x0100
  12280. //
  12281. // Define Information fields for whether or not a REPARSE or a REMOUNT has
  12282. // occurred in the file system.
  12283. //
  12284. #define IO_REPARSE 0x0
  12285. #define IO_REMOUNT 0x1
  12286. //
  12287. // Define callout routine type for use in IoQueryDeviceDescription().
  12288. //
  12289. typedef NTSTATUS (*PIO_QUERY_DEVICE_ROUTINE)(
  12290. IN PVOID Context,
  12291. IN PUNICODE_STRING PathName,
  12292. IN INTERFACE_TYPE BusType,
  12293. IN ULONG BusNumber,
  12294. IN PKEY_VALUE_FULL_INFORMATION *BusInformation,
  12295. IN CONFIGURATION_TYPE ControllerType,
  12296. IN ULONG ControllerNumber,
  12297. IN PKEY_VALUE_FULL_INFORMATION *ControllerInformation,
  12298. IN CONFIGURATION_TYPE PeripheralType,
  12299. IN ULONG PeripheralNumber,
  12300. IN PKEY_VALUE_FULL_INFORMATION *PeripheralInformation
  12301. );
  12302. // Defines the order of the information in the array of
  12303. // PKEY_VALUE_FULL_INFORMATION.
  12304. //
  12305. typedef enum _IO_QUERY_DEVICE_DATA_FORMAT {
  12306. IoQueryDeviceIdentifier = 0,
  12307. IoQueryDeviceConfigurationData,
  12308. IoQueryDeviceComponentInformation,
  12309. IoQueryDeviceMaxData
  12310. } IO_QUERY_DEVICE_DATA_FORMAT, *PIO_QUERY_DEVICE_DATA_FORMAT;
  12311. // begin_wdm begin_ntifs
  12312. //
  12313. // Define the objects that can be created by IoCreateFile.
  12314. //
  12315. typedef enum _CREATE_FILE_TYPE {
  12316. CreateFileTypeNone,
  12317. CreateFileTypeNamedPipe,
  12318. CreateFileTypeMailslot
  12319. } CREATE_FILE_TYPE;
  12320. //
  12321. // Define the structures used by the I/O system
  12322. //
  12323. //
  12324. // Define empty typedefs for the _IRP, _DEVICE_OBJECT, and _DRIVER_OBJECT
  12325. // structures so they may be referenced by function types before they are
  12326. // actually defined.
  12327. //
  12328. struct _DEVICE_DESCRIPTION;
  12329. struct _DEVICE_OBJECT;
  12330. struct _DMA_ADAPTER;
  12331. struct _DRIVER_OBJECT;
  12332. struct _DRIVE_LAYOUT_INFORMATION;
  12333. struct _DISK_PARTITION;
  12334. struct _FILE_OBJECT;
  12335. struct _IRP;
  12336. struct _SCSI_REQUEST_BLOCK;
  12337. struct _SCATTER_GATHER_LIST;
  12338. //
  12339. // Define the I/O version of a DPC routine.
  12340. //
  12341. typedef
  12342. VOID
  12343. (*PIO_DPC_ROUTINE) (
  12344. IN PKDPC Dpc,
  12345. IN struct _DEVICE_OBJECT *DeviceObject,
  12346. IN struct _IRP *Irp,
  12347. IN PVOID Context
  12348. );
  12349. //
  12350. // Define driver timer routine type.
  12351. //
  12352. typedef
  12353. VOID
  12354. (*PIO_TIMER_ROUTINE) (
  12355. IN struct _DEVICE_OBJECT *DeviceObject,
  12356. IN PVOID Context
  12357. );
  12358. //
  12359. // Define driver initialization routine type.
  12360. //
  12361. typedef
  12362. NTSTATUS
  12363. (*PDRIVER_INITIALIZE) (
  12364. IN struct _DRIVER_OBJECT *DriverObject,
  12365. IN PUNICODE_STRING RegistryPath
  12366. );
  12367. // end_wdm
  12368. //
  12369. // Define driver reinitialization routine type.
  12370. //
  12371. typedef
  12372. VOID
  12373. (*PDRIVER_REINITIALIZE) (
  12374. IN struct _DRIVER_OBJECT *DriverObject,
  12375. IN PVOID Context,
  12376. IN ULONG Count
  12377. );
  12378. // begin_wdm begin_ntndis
  12379. //
  12380. // Define driver cancel routine type.
  12381. //
  12382. typedef
  12383. VOID
  12384. (*PDRIVER_CANCEL) (
  12385. IN struct _DEVICE_OBJECT *DeviceObject,
  12386. IN struct _IRP *Irp
  12387. );
  12388. //
  12389. // Define driver dispatch routine type.
  12390. //
  12391. typedef
  12392. NTSTATUS
  12393. (*PDRIVER_DISPATCH) (
  12394. IN struct _DEVICE_OBJECT *DeviceObject,
  12395. IN struct _IRP *Irp
  12396. );
  12397. //
  12398. // Define driver start I/O routine type.
  12399. //
  12400. typedef
  12401. VOID
  12402. (*PDRIVER_STARTIO) (
  12403. IN struct _DEVICE_OBJECT *DeviceObject,
  12404. IN struct _IRP *Irp
  12405. );
  12406. //
  12407. // Define driver unload routine type.
  12408. //
  12409. typedef
  12410. VOID
  12411. (*PDRIVER_UNLOAD) (
  12412. IN struct _DRIVER_OBJECT *DriverObject
  12413. );
  12414. //
  12415. // Define driver AddDevice routine type.
  12416. //
  12417. typedef
  12418. NTSTATUS
  12419. (*PDRIVER_ADD_DEVICE) (
  12420. IN struct _DRIVER_OBJECT *DriverObject,
  12421. IN struct _DEVICE_OBJECT *PhysicalDeviceObject
  12422. );
  12423. //
  12424. // Define fast I/O procedure prototypes.
  12425. //
  12426. // Fast I/O read and write procedures.
  12427. //
  12428. typedef
  12429. BOOLEAN
  12430. (*PFAST_IO_CHECK_IF_POSSIBLE) (
  12431. IN struct _FILE_OBJECT *FileObject,
  12432. IN PLARGE_INTEGER FileOffset,
  12433. IN ULONG Length,
  12434. IN BOOLEAN Wait,
  12435. IN ULONG LockKey,
  12436. IN BOOLEAN CheckForReadOperation,
  12437. OUT PIO_STATUS_BLOCK IoStatus,
  12438. IN struct _DEVICE_OBJECT *DeviceObject
  12439. );
  12440. typedef
  12441. BOOLEAN
  12442. (*PFAST_IO_READ) (
  12443. IN struct _FILE_OBJECT *FileObject,
  12444. IN PLARGE_INTEGER FileOffset,
  12445. IN ULONG Length,
  12446. IN BOOLEAN Wait,
  12447. IN ULONG LockKey,
  12448. OUT PVOID Buffer,
  12449. OUT PIO_STATUS_BLOCK IoStatus,
  12450. IN struct _DEVICE_OBJECT *DeviceObject
  12451. );
  12452. typedef
  12453. BOOLEAN
  12454. (*PFAST_IO_WRITE) (
  12455. IN struct _FILE_OBJECT *FileObject,
  12456. IN PLARGE_INTEGER FileOffset,
  12457. IN ULONG Length,
  12458. IN BOOLEAN Wait,
  12459. IN ULONG LockKey,
  12460. IN PVOID Buffer,
  12461. OUT PIO_STATUS_BLOCK IoStatus,
  12462. IN struct _DEVICE_OBJECT *DeviceObject
  12463. );
  12464. //
  12465. // Fast I/O query basic and standard information procedures.
  12466. //
  12467. typedef
  12468. BOOLEAN
  12469. (*PFAST_IO_QUERY_BASIC_INFO) (
  12470. IN struct _FILE_OBJECT *FileObject,
  12471. IN BOOLEAN Wait,
  12472. OUT PFILE_BASIC_INFORMATION Buffer,
  12473. OUT PIO_STATUS_BLOCK IoStatus,
  12474. IN struct _DEVICE_OBJECT *DeviceObject
  12475. );
  12476. typedef
  12477. BOOLEAN
  12478. (*PFAST_IO_QUERY_STANDARD_INFO) (
  12479. IN struct _FILE_OBJECT *FileObject,
  12480. IN BOOLEAN Wait,
  12481. OUT PFILE_STANDARD_INFORMATION Buffer,
  12482. OUT PIO_STATUS_BLOCK IoStatus,
  12483. IN struct _DEVICE_OBJECT *DeviceObject
  12484. );
  12485. //
  12486. // Fast I/O lock and unlock procedures.
  12487. //
  12488. typedef
  12489. BOOLEAN
  12490. (*PFAST_IO_LOCK) (
  12491. IN struct _FILE_OBJECT *FileObject,
  12492. IN PLARGE_INTEGER FileOffset,
  12493. IN PLARGE_INTEGER Length,
  12494. PEPROCESS ProcessId,
  12495. ULONG Key,
  12496. BOOLEAN FailImmediately,
  12497. BOOLEAN ExclusiveLock,
  12498. OUT PIO_STATUS_BLOCK IoStatus,
  12499. IN struct _DEVICE_OBJECT *DeviceObject
  12500. );
  12501. typedef
  12502. BOOLEAN
  12503. (*PFAST_IO_UNLOCK_SINGLE) (
  12504. IN struct _FILE_OBJECT *FileObject,
  12505. IN PLARGE_INTEGER FileOffset,
  12506. IN PLARGE_INTEGER Length,
  12507. PEPROCESS ProcessId,
  12508. ULONG Key,
  12509. OUT PIO_STATUS_BLOCK IoStatus,
  12510. IN struct _DEVICE_OBJECT *DeviceObject
  12511. );
  12512. typedef
  12513. BOOLEAN
  12514. (*PFAST_IO_UNLOCK_ALL) (
  12515. IN struct _FILE_OBJECT *FileObject,
  12516. PEPROCESS ProcessId,
  12517. OUT PIO_STATUS_BLOCK IoStatus,
  12518. IN struct _DEVICE_OBJECT *DeviceObject
  12519. );
  12520. typedef
  12521. BOOLEAN
  12522. (*PFAST_IO_UNLOCK_ALL_BY_KEY) (
  12523. IN struct _FILE_OBJECT *FileObject,
  12524. PVOID ProcessId,
  12525. ULONG Key,
  12526. OUT PIO_STATUS_BLOCK IoStatus,
  12527. IN struct _DEVICE_OBJECT *DeviceObject
  12528. );
  12529. //
  12530. // Fast I/O device control procedure.
  12531. //
  12532. typedef
  12533. BOOLEAN
  12534. (*PFAST_IO_DEVICE_CONTROL) (
  12535. IN struct _FILE_OBJECT *FileObject,
  12536. IN BOOLEAN Wait,
  12537. IN PVOID InputBuffer OPTIONAL,
  12538. IN ULONG InputBufferLength,
  12539. OUT PVOID OutputBuffer OPTIONAL,
  12540. IN ULONG OutputBufferLength,
  12541. IN ULONG IoControlCode,
  12542. OUT PIO_STATUS_BLOCK IoStatus,
  12543. IN struct _DEVICE_OBJECT *DeviceObject
  12544. );
  12545. //
  12546. // Define callbacks for NtCreateSection to synchronize correctly with
  12547. // the file system. It pre-acquires the resources that will be needed
  12548. // when calling to query and set file/allocation size in the file system.
  12549. //
  12550. typedef
  12551. VOID
  12552. (*PFAST_IO_ACQUIRE_FILE) (
  12553. IN struct _FILE_OBJECT *FileObject
  12554. );
  12555. typedef
  12556. VOID
  12557. (*PFAST_IO_RELEASE_FILE) (
  12558. IN struct _FILE_OBJECT *FileObject
  12559. );
  12560. //
  12561. // Define callback for drivers that have device objects attached to lower-
  12562. // level drivers' device objects. This callback is made when the lower-level
  12563. // driver is deleting its device object.
  12564. //
  12565. typedef
  12566. VOID
  12567. (*PFAST_IO_DETACH_DEVICE) (
  12568. IN struct _DEVICE_OBJECT *SourceDevice,
  12569. IN struct _DEVICE_OBJECT *TargetDevice
  12570. );
  12571. //
  12572. // This structure is used by the server to quickly get the information needed
  12573. // to service a server open call. It is takes what would be two fast io calls
  12574. // one for basic information and the other for standard information and makes
  12575. // it into one call.
  12576. //
  12577. typedef
  12578. BOOLEAN
  12579. (*PFAST_IO_QUERY_NETWORK_OPEN_INFO) (
  12580. IN struct _FILE_OBJECT *FileObject,
  12581. IN BOOLEAN Wait,
  12582. OUT struct _FILE_NETWORK_OPEN_INFORMATION *Buffer,
  12583. OUT struct _IO_STATUS_BLOCK *IoStatus,
  12584. IN struct _DEVICE_OBJECT *DeviceObject
  12585. );
  12586. //
  12587. // Define Mdl-based routines for the server to call
  12588. //
  12589. typedef
  12590. BOOLEAN
  12591. (*PFAST_IO_MDL_READ) (
  12592. IN struct _FILE_OBJECT *FileObject,
  12593. IN PLARGE_INTEGER FileOffset,
  12594. IN ULONG Length,
  12595. IN ULONG LockKey,
  12596. OUT PMDL *MdlChain,
  12597. OUT PIO_STATUS_BLOCK IoStatus,
  12598. IN struct _DEVICE_OBJECT *DeviceObject
  12599. );
  12600. typedef
  12601. BOOLEAN
  12602. (*PFAST_IO_MDL_READ_COMPLETE) (
  12603. IN struct _FILE_OBJECT *FileObject,
  12604. IN PMDL MdlChain,
  12605. IN struct _DEVICE_OBJECT *DeviceObject
  12606. );
  12607. typedef
  12608. BOOLEAN
  12609. (*PFAST_IO_PREPARE_MDL_WRITE) (
  12610. IN struct _FILE_OBJECT *FileObject,
  12611. IN PLARGE_INTEGER FileOffset,
  12612. IN ULONG Length,
  12613. IN ULONG LockKey,
  12614. OUT PMDL *MdlChain,
  12615. OUT PIO_STATUS_BLOCK IoStatus,
  12616. IN struct _DEVICE_OBJECT *DeviceObject
  12617. );
  12618. typedef
  12619. BOOLEAN
  12620. (*PFAST_IO_MDL_WRITE_COMPLETE) (
  12621. IN struct _FILE_OBJECT *FileObject,
  12622. IN PLARGE_INTEGER FileOffset,
  12623. IN PMDL MdlChain,
  12624. IN struct _DEVICE_OBJECT *DeviceObject
  12625. );
  12626. //
  12627. // If this routine is present, it will be called by FsRtl
  12628. // to acquire the file for the mapped page writer.
  12629. //
  12630. typedef
  12631. NTSTATUS
  12632. (*PFAST_IO_ACQUIRE_FOR_MOD_WRITE) (
  12633. IN struct _FILE_OBJECT *FileObject,
  12634. IN PLARGE_INTEGER EndingOffset,
  12635. OUT struct _ERESOURCE **ResourceToRelease,
  12636. IN struct _DEVICE_OBJECT *DeviceObject
  12637. );
  12638. typedef
  12639. NTSTATUS
  12640. (*PFAST_IO_RELEASE_FOR_MOD_WRITE) (
  12641. IN struct _FILE_OBJECT *FileObject,
  12642. IN struct _ERESOURCE *ResourceToRelease,
  12643. IN struct _DEVICE_OBJECT *DeviceObject
  12644. );
  12645. //
  12646. // If this routine is present, it will be called by FsRtl
  12647. // to acquire the file for the mapped page writer.
  12648. //
  12649. typedef
  12650. NTSTATUS
  12651. (*PFAST_IO_ACQUIRE_FOR_CCFLUSH) (
  12652. IN struct _FILE_OBJECT *FileObject,
  12653. IN struct _DEVICE_OBJECT *DeviceObject
  12654. );
  12655. typedef
  12656. NTSTATUS
  12657. (*PFAST_IO_RELEASE_FOR_CCFLUSH) (
  12658. IN struct _FILE_OBJECT *FileObject,
  12659. IN struct _DEVICE_OBJECT *DeviceObject
  12660. );
  12661. typedef
  12662. BOOLEAN
  12663. (*PFAST_IO_READ_COMPRESSED) (
  12664. IN struct _FILE_OBJECT *FileObject,
  12665. IN PLARGE_INTEGER FileOffset,
  12666. IN ULONG Length,
  12667. IN ULONG LockKey,
  12668. OUT PVOID Buffer,
  12669. OUT PMDL *MdlChain,
  12670. OUT PIO_STATUS_BLOCK IoStatus,
  12671. OUT struct _COMPRESSED_DATA_INFO *CompressedDataInfo,
  12672. IN ULONG CompressedDataInfoLength,
  12673. IN struct _DEVICE_OBJECT *DeviceObject
  12674. );
  12675. typedef
  12676. BOOLEAN
  12677. (*PFAST_IO_WRITE_COMPRESSED) (
  12678. IN struct _FILE_OBJECT *FileObject,
  12679. IN PLARGE_INTEGER FileOffset,
  12680. IN ULONG Length,
  12681. IN ULONG LockKey,
  12682. IN PVOID Buffer,
  12683. OUT PMDL *MdlChain,
  12684. OUT PIO_STATUS_BLOCK IoStatus,
  12685. IN struct _COMPRESSED_DATA_INFO *CompressedDataInfo,
  12686. IN ULONG CompressedDataInfoLength,
  12687. IN struct _DEVICE_OBJECT *DeviceObject
  12688. );
  12689. typedef
  12690. BOOLEAN
  12691. (*PFAST_IO_MDL_READ_COMPLETE_COMPRESSED) (
  12692. IN struct _FILE_OBJECT *FileObject,
  12693. IN PMDL MdlChain,
  12694. IN struct _DEVICE_OBJECT *DeviceObject
  12695. );
  12696. typedef
  12697. BOOLEAN
  12698. (*PFAST_IO_MDL_WRITE_COMPLETE_COMPRESSED) (
  12699. IN struct _FILE_OBJECT *FileObject,
  12700. IN PLARGE_INTEGER FileOffset,
  12701. IN PMDL MdlChain,
  12702. IN struct _DEVICE_OBJECT *DeviceObject
  12703. );
  12704. typedef
  12705. BOOLEAN
  12706. (*PFAST_IO_QUERY_OPEN) (
  12707. IN struct _IRP *Irp,
  12708. OUT PFILE_NETWORK_OPEN_INFORMATION NetworkInformation,
  12709. IN struct _DEVICE_OBJECT *DeviceObject
  12710. );
  12711. //
  12712. // Define the structure to describe the Fast I/O dispatch routines. Any
  12713. // additions made to this structure MUST be added monotonically to the end
  12714. // of the structure, and fields CANNOT be removed from the middle.
  12715. //
  12716. typedef struct _FAST_IO_DISPATCH {
  12717. ULONG SizeOfFastIoDispatch;
  12718. PFAST_IO_CHECK_IF_POSSIBLE FastIoCheckIfPossible;
  12719. PFAST_IO_READ FastIoRead;
  12720. PFAST_IO_WRITE FastIoWrite;
  12721. PFAST_IO_QUERY_BASIC_INFO FastIoQueryBasicInfo;
  12722. PFAST_IO_QUERY_STANDARD_INFO FastIoQueryStandardInfo;
  12723. PFAST_IO_LOCK FastIoLock;
  12724. PFAST_IO_UNLOCK_SINGLE FastIoUnlockSingle;
  12725. PFAST_IO_UNLOCK_ALL FastIoUnlockAll;
  12726. PFAST_IO_UNLOCK_ALL_BY_KEY FastIoUnlockAllByKey;
  12727. PFAST_IO_DEVICE_CONTROL FastIoDeviceControl;
  12728. PFAST_IO_ACQUIRE_FILE AcquireFileForNtCreateSection;
  12729. PFAST_IO_RELEASE_FILE ReleaseFileForNtCreateSection;
  12730. PFAST_IO_DETACH_DEVICE FastIoDetachDevice;
  12731. PFAST_IO_QUERY_NETWORK_OPEN_INFO FastIoQueryNetworkOpenInfo;
  12732. PFAST_IO_ACQUIRE_FOR_MOD_WRITE AcquireForModWrite;
  12733. PFAST_IO_MDL_READ MdlRead;
  12734. PFAST_IO_MDL_READ_COMPLETE MdlReadComplete;
  12735. PFAST_IO_PREPARE_MDL_WRITE PrepareMdlWrite;
  12736. PFAST_IO_MDL_WRITE_COMPLETE MdlWriteComplete;
  12737. PFAST_IO_READ_COMPRESSED FastIoReadCompressed;
  12738. PFAST_IO_WRITE_COMPRESSED FastIoWriteCompressed;
  12739. PFAST_IO_MDL_READ_COMPLETE_COMPRESSED MdlReadCompleteCompressed;
  12740. PFAST_IO_MDL_WRITE_COMPLETE_COMPRESSED MdlWriteCompleteCompressed;
  12741. PFAST_IO_QUERY_OPEN FastIoQueryOpen;
  12742. PFAST_IO_RELEASE_FOR_MOD_WRITE ReleaseForModWrite;
  12743. PFAST_IO_ACQUIRE_FOR_CCFLUSH AcquireForCcFlush;
  12744. PFAST_IO_RELEASE_FOR_CCFLUSH ReleaseForCcFlush;
  12745. } FAST_IO_DISPATCH, *PFAST_IO_DISPATCH;
  12746. //
  12747. // Define the actions that a driver execution routine may request of the
  12748. // adapter/controller allocation routines upon return.
  12749. //
  12750. typedef enum _IO_ALLOCATION_ACTION {
  12751. KeepObject = 1,
  12752. DeallocateObject,
  12753. DeallocateObjectKeepRegisters
  12754. } IO_ALLOCATION_ACTION, *PIO_ALLOCATION_ACTION;
  12755. //
  12756. // Define device driver adapter/controller execution routine.
  12757. //
  12758. typedef
  12759. IO_ALLOCATION_ACTION
  12760. (*PDRIVER_CONTROL) (
  12761. IN struct _DEVICE_OBJECT *DeviceObject,
  12762. IN struct _IRP *Irp,
  12763. IN PVOID MapRegisterBase,
  12764. IN PVOID Context
  12765. );
  12766. //
  12767. // Define the I/O system's security context type for use by file system's
  12768. // when checking access to volumes, files, and directories.
  12769. //
  12770. typedef struct _IO_SECURITY_CONTEXT {
  12771. PSECURITY_QUALITY_OF_SERVICE SecurityQos;
  12772. PACCESS_STATE AccessState;
  12773. ACCESS_MASK DesiredAccess;
  12774. ULONG FullCreateOptions;
  12775. } IO_SECURITY_CONTEXT, *PIO_SECURITY_CONTEXT;
  12776. //
  12777. // Define Volume Parameter Block (VPB) flags.
  12778. //
  12779. #define VPB_MOUNTED 0x00000001
  12780. #define VPB_LOCKED 0x00000002
  12781. #define VPB_PERSISTENT 0x00000004
  12782. #define VPB_REMOVE_PENDING 0x00000008
  12783. #define VPB_RAW_MOUNT 0x00000010
  12784. //
  12785. // Volume Parameter Block (VPB)
  12786. //
  12787. #define MAXIMUM_VOLUME_LABEL_LENGTH (32 * sizeof(WCHAR)) // 32 characters
  12788. typedef struct _VPB {
  12789. CSHORT Type;
  12790. CSHORT Size;
  12791. USHORT Flags;
  12792. USHORT VolumeLabelLength; // in bytes
  12793. struct _DEVICE_OBJECT *DeviceObject;
  12794. struct _DEVICE_OBJECT *RealDevice;
  12795. ULONG SerialNumber;
  12796. ULONG ReferenceCount;
  12797. WCHAR VolumeLabel[MAXIMUM_VOLUME_LABEL_LENGTH / sizeof(WCHAR)];
  12798. } VPB, *PVPB;
  12799. #if defined(_WIN64)
  12800. //
  12801. // Use __inline DMA macros (hal.h)
  12802. //
  12803. #ifndef USE_DMA_MACROS
  12804. #define USE_DMA_MACROS
  12805. #endif
  12806. //
  12807. // Only PnP drivers!
  12808. //
  12809. #ifndef NO_LEGACY_DRIVERS
  12810. #define NO_LEGACY_DRIVERS
  12811. #endif
  12812. #endif // _WIN64
  12813. #if defined(USE_DMA_MACROS) && (defined(_NTDDK_) || defined(_NTDRIVER_) || defined(_NTOSP_))
  12814. // begin_wdm
  12815. //
  12816. // Define object type specific fields of various objects used by the I/O system
  12817. //
  12818. typedef struct _DMA_ADAPTER *PADAPTER_OBJECT;
  12819. // end_wdm
  12820. #else
  12821. //
  12822. // Define object type specific fields of various objects used by the I/O system
  12823. //
  12824. typedef struct _ADAPTER_OBJECT *PADAPTER_OBJECT; // ntndis
  12825. #endif // USE_DMA_MACROS && (_NTDDK_ || _NTDRIVER_ || _NTOSP_)
  12826. // begin_wdm
  12827. //
  12828. // Define Wait Context Block (WCB)
  12829. //
  12830. typedef struct _WAIT_CONTEXT_BLOCK {
  12831. KDEVICE_QUEUE_ENTRY WaitQueueEntry;
  12832. PDRIVER_CONTROL DeviceRoutine;
  12833. PVOID DeviceContext;
  12834. ULONG NumberOfMapRegisters;
  12835. PVOID DeviceObject;
  12836. PVOID CurrentIrp;
  12837. PKDPC BufferChainingDpc;
  12838. } WAIT_CONTEXT_BLOCK, *PWAIT_CONTEXT_BLOCK;
  12839. // end_wdm
  12840. typedef struct _CONTROLLER_OBJECT {
  12841. CSHORT Type;
  12842. CSHORT Size;
  12843. PVOID ControllerExtension;
  12844. KDEVICE_QUEUE DeviceWaitQueue;
  12845. ULONG Spare1;
  12846. LARGE_INTEGER Spare2;
  12847. } CONTROLLER_OBJECT, *PCONTROLLER_OBJECT;
  12848. // begin_wdm
  12849. //
  12850. // Define Device Object (DO) flags
  12851. //
  12852. #define DO_VERIFY_VOLUME 0x00000002
  12853. #define DO_BUFFERED_IO 0x00000004
  12854. #define DO_EXCLUSIVE 0x00000008
  12855. #define DO_DIRECT_IO 0x00000010
  12856. #define DO_MAP_IO_BUFFER 0x00000020
  12857. #define DO_DEVICE_HAS_NAME 0x00000040
  12858. #define DO_DEVICE_INITIALIZING 0x00000080
  12859. #define DO_SYSTEM_BOOT_PARTITION 0x00000100
  12860. #define DO_LONG_TERM_REQUESTS 0x00000200
  12861. #define DO_NEVER_LAST_DEVICE 0x00000400
  12862. #define DO_SHUTDOWN_REGISTERED 0x00000800
  12863. #define DO_BUS_ENUMERATED_DEVICE 0x00001000
  12864. #define DO_POWER_PAGABLE 0x00002000
  12865. #define DO_POWER_INRUSH 0x00004000
  12866. #define DO_LOW_PRIORITY_FILESYSTEM 0x00010000
  12867. //
  12868. // Device Object structure definition
  12869. //
  12870. typedef struct DECLSPEC_ALIGN(MEMORY_ALLOCATION_ALIGNMENT) _DEVICE_OBJECT {
  12871. CSHORT Type;
  12872. USHORT Size;
  12873. LONG ReferenceCount;
  12874. struct _DRIVER_OBJECT *DriverObject;
  12875. struct _DEVICE_OBJECT *NextDevice;
  12876. struct _DEVICE_OBJECT *AttachedDevice;
  12877. struct _IRP *CurrentIrp;
  12878. PIO_TIMER Timer;
  12879. ULONG Flags; // See above: DO_...
  12880. ULONG Characteristics; // See ntioapi: FILE_...
  12881. PVPB Vpb;
  12882. PVOID DeviceExtension;
  12883. DEVICE_TYPE DeviceType;
  12884. CCHAR StackSize;
  12885. union {
  12886. LIST_ENTRY ListEntry;
  12887. WAIT_CONTEXT_BLOCK Wcb;
  12888. } Queue;
  12889. ULONG AlignmentRequirement;
  12890. KDEVICE_QUEUE DeviceQueue;
  12891. KDPC Dpc;
  12892. //
  12893. // The following field is for exclusive use by the filesystem to keep
  12894. // track of the number of Fsp threads currently using the device
  12895. //
  12896. ULONG ActiveThreadCount;
  12897. PSECURITY_DESCRIPTOR SecurityDescriptor;
  12898. KEVENT DeviceLock;
  12899. USHORT SectorSize;
  12900. USHORT Spare1;
  12901. struct _DEVOBJ_EXTENSION *DeviceObjectExtension;
  12902. PVOID Reserved;
  12903. } DEVICE_OBJECT;
  12904. typedef struct _DEVICE_OBJECT *PDEVICE_OBJECT; // ntndis
  12905. struct _DEVICE_OBJECT_POWER_EXTENSION;
  12906. typedef struct _DEVOBJ_EXTENSION {
  12907. CSHORT Type;
  12908. USHORT Size;
  12909. //
  12910. // Public part of the DeviceObjectExtension structure
  12911. //
  12912. PDEVICE_OBJECT DeviceObject; // owning device object
  12913. } DEVOBJ_EXTENSION, *PDEVOBJ_EXTENSION;
  12914. //
  12915. // Define Driver Object (DRVO) flags
  12916. //
  12917. #define DRVO_UNLOAD_INVOKED 0x00000001
  12918. #define DRVO_LEGACY_DRIVER 0x00000002
  12919. #define DRVO_BUILTIN_DRIVER 0x00000004 // Driver objects for Hal, PnP Mgr
  12920. // end_wdm
  12921. #define DRVO_REINIT_REGISTERED 0x00000008
  12922. #define DRVO_INITIALIZED 0x00000010
  12923. #define DRVO_BOOTREINIT_REGISTERED 0x00000020
  12924. #define DRVO_LEGACY_RESOURCES 0x00000040
  12925. // begin_wdm
  12926. typedef struct _DRIVER_EXTENSION {
  12927. //
  12928. // Back pointer to Driver Object
  12929. //
  12930. struct _DRIVER_OBJECT *DriverObject;
  12931. //
  12932. // The AddDevice entry point is called by the Plug & Play manager
  12933. // to inform the driver when a new device instance arrives that this
  12934. // driver must control.
  12935. //
  12936. PDRIVER_ADD_DEVICE AddDevice;
  12937. //
  12938. // The count field is used to count the number of times the driver has
  12939. // had its registered reinitialization routine invoked.
  12940. //
  12941. ULONG Count;
  12942. //
  12943. // The service name field is used by the pnp manager to determine
  12944. // where the driver related info is stored in the registry.
  12945. //
  12946. UNICODE_STRING ServiceKeyName;
  12947. //
  12948. // Note: any new shared fields get added here.
  12949. //
  12950. } DRIVER_EXTENSION, *PDRIVER_EXTENSION;
  12951. typedef struct _DRIVER_OBJECT {
  12952. CSHORT Type;
  12953. CSHORT Size;
  12954. //
  12955. // The following links all of the devices created by a single driver
  12956. // together on a list, and the Flags word provides an extensible flag
  12957. // location for driver objects.
  12958. //
  12959. PDEVICE_OBJECT DeviceObject;
  12960. ULONG Flags;
  12961. //
  12962. // The following section describes where the driver is loaded. The count
  12963. // field is used to count the number of times the driver has had its
  12964. // registered reinitialization routine invoked.
  12965. //
  12966. PVOID DriverStart;
  12967. ULONG DriverSize;
  12968. PVOID DriverSection;
  12969. PDRIVER_EXTENSION DriverExtension;
  12970. //
  12971. // The driver name field is used by the error log thread
  12972. // determine the name of the driver that an I/O request is/was bound.
  12973. //
  12974. UNICODE_STRING DriverName;
  12975. //
  12976. // The following section is for registry support. Thise is a pointer
  12977. // to the path to the hardware information in the registry
  12978. //
  12979. PUNICODE_STRING HardwareDatabase;
  12980. //
  12981. // The following section contains the optional pointer to an array of
  12982. // alternate entry points to a driver for "fast I/O" support. Fast I/O
  12983. // is performed by invoking the driver routine directly with separate
  12984. // parameters, rather than using the standard IRP call mechanism. Note
  12985. // that these functions may only be used for synchronous I/O, and when
  12986. // the file is cached.
  12987. //
  12988. PFAST_IO_DISPATCH FastIoDispatch;
  12989. //
  12990. // The following section describes the entry points to this particular
  12991. // driver. Note that the major function dispatch table must be the last
  12992. // field in the object so that it remains extensible.
  12993. //
  12994. PDRIVER_INITIALIZE DriverInit;
  12995. PDRIVER_STARTIO DriverStartIo;
  12996. PDRIVER_UNLOAD DriverUnload;
  12997. PDRIVER_DISPATCH MajorFunction[IRP_MJ_MAXIMUM_FUNCTION + 1];
  12998. } DRIVER_OBJECT;
  12999. typedef struct _DRIVER_OBJECT *PDRIVER_OBJECT; // ntndis
  13000. //
  13001. // The following structure is pointed to by the SectionObject pointer field
  13002. // of a file object, and is allocated by the various NT file systems.
  13003. //
  13004. typedef struct _SECTION_OBJECT_POINTERS {
  13005. PVOID DataSectionObject;
  13006. PVOID SharedCacheMap;
  13007. PVOID ImageSectionObject;
  13008. } SECTION_OBJECT_POINTERS;
  13009. typedef SECTION_OBJECT_POINTERS *PSECTION_OBJECT_POINTERS;
  13010. //
  13011. // Define the format of a completion message.
  13012. //
  13013. typedef struct _IO_COMPLETION_CONTEXT {
  13014. PVOID Port;
  13015. PVOID Key;
  13016. } IO_COMPLETION_CONTEXT, *PIO_COMPLETION_CONTEXT;
  13017. //
  13018. // Define File Object (FO) flags
  13019. //
  13020. #define FO_FILE_OPEN 0x00000001
  13021. #define FO_SYNCHRONOUS_IO 0x00000002
  13022. #define FO_ALERTABLE_IO 0x00000004
  13023. #define FO_NO_INTERMEDIATE_BUFFERING 0x00000008
  13024. #define FO_WRITE_THROUGH 0x00000010
  13025. #define FO_SEQUENTIAL_ONLY 0x00000020
  13026. #define FO_CACHE_SUPPORTED 0x00000040
  13027. #define FO_NAMED_PIPE 0x00000080
  13028. #define FO_STREAM_FILE 0x00000100
  13029. #define FO_MAILSLOT 0x00000200
  13030. #define FO_GENERATE_AUDIT_ON_CLOSE 0x00000400
  13031. #define FO_DIRECT_DEVICE_OPEN 0x00000800
  13032. #define FO_FILE_MODIFIED 0x00001000
  13033. #define FO_FILE_SIZE_CHANGED 0x00002000
  13034. #define FO_CLEANUP_COMPLETE 0x00004000
  13035. #define FO_TEMPORARY_FILE 0x00008000
  13036. #define FO_DELETE_ON_CLOSE 0x00010000
  13037. #define FO_OPENED_CASE_SENSITIVE 0x00020000
  13038. #define FO_HANDLE_CREATED 0x00040000
  13039. #define FO_FILE_FAST_IO_READ 0x00080000
  13040. #define FO_RANDOM_ACCESS 0x00100000
  13041. #define FO_FILE_OPEN_CANCELLED 0x00200000
  13042. #define FO_VOLUME_OPEN 0x00400000
  13043. #define FO_FILE_OBJECT_HAS_EXTENSION 0x00800000
  13044. #define FO_REMOTE_ORIGIN 0x01000000
  13045. typedef struct _FILE_OBJECT {
  13046. CSHORT Type;
  13047. CSHORT Size;
  13048. PDEVICE_OBJECT DeviceObject;
  13049. PVPB Vpb;
  13050. PVOID FsContext;
  13051. PVOID FsContext2;
  13052. PSECTION_OBJECT_POINTERS SectionObjectPointer;
  13053. PVOID PrivateCacheMap;
  13054. NTSTATUS FinalStatus;
  13055. struct _FILE_OBJECT *RelatedFileObject;
  13056. BOOLEAN LockOperation;
  13057. BOOLEAN DeletePending;
  13058. BOOLEAN ReadAccess;
  13059. BOOLEAN WriteAccess;
  13060. BOOLEAN DeleteAccess;
  13061. BOOLEAN SharedRead;
  13062. BOOLEAN SharedWrite;
  13063. BOOLEAN SharedDelete;
  13064. ULONG Flags;
  13065. UNICODE_STRING FileName;
  13066. LARGE_INTEGER CurrentByteOffset;
  13067. ULONG Waiters;
  13068. ULONG Busy;
  13069. PVOID LastLock;
  13070. KEVENT Lock;
  13071. KEVENT Event;
  13072. PIO_COMPLETION_CONTEXT CompletionContext;
  13073. } FILE_OBJECT;
  13074. typedef struct _FILE_OBJECT *PFILE_OBJECT; // ntndis
  13075. //
  13076. // Define I/O Request Packet (IRP) flags
  13077. //
  13078. #define IRP_NOCACHE 0x00000001
  13079. #define IRP_PAGING_IO 0x00000002
  13080. #define IRP_MOUNT_COMPLETION 0x00000002
  13081. #define IRP_SYNCHRONOUS_API 0x00000004
  13082. #define IRP_ASSOCIATED_IRP 0x00000008
  13083. #define IRP_BUFFERED_IO 0x00000010
  13084. #define IRP_DEALLOCATE_BUFFER 0x00000020
  13085. #define IRP_INPUT_OPERATION 0x00000040
  13086. #define IRP_SYNCHRONOUS_PAGING_IO 0x00000040
  13087. #define IRP_CREATE_OPERATION 0x00000080
  13088. #define IRP_READ_OPERATION 0x00000100
  13089. #define IRP_WRITE_OPERATION 0x00000200
  13090. #define IRP_CLOSE_OPERATION 0x00000400
  13091. // end_wdm
  13092. #define IRP_DEFER_IO_COMPLETION 0x00000800
  13093. #define IRP_OB_QUERY_NAME 0x00001000
  13094. #define IRP_HOLD_DEVICE_QUEUE 0x00002000
  13095. #define IRP_RETRY_IO_COMPLETION 0x00004000
  13096. #define IRP_CLASS_CACHE_OPERATION 0x00008000
  13097. #define IRP_SET_USER_EVENT IRP_CLOSE_OPERATION
  13098. // begin_wdm
  13099. //
  13100. // Define I/O request packet (IRP) alternate flags for allocation control.
  13101. //
  13102. #define IRP_QUOTA_CHARGED 0x01
  13103. #define IRP_ALLOCATED_MUST_SUCCEED 0x02
  13104. #define IRP_ALLOCATED_FIXED_SIZE 0x04
  13105. #define IRP_LOOKASIDE_ALLOCATION 0x08
  13106. //
  13107. // I/O Request Packet (IRP) definition
  13108. //
  13109. typedef struct _IRP {
  13110. CSHORT Type;
  13111. USHORT Size;
  13112. //
  13113. // Define the common fields used to control the IRP.
  13114. //
  13115. //
  13116. // Define a pointer to the Memory Descriptor List (MDL) for this I/O
  13117. // request. This field is only used if the I/O is "direct I/O".
  13118. //
  13119. PMDL MdlAddress;
  13120. //
  13121. // Flags word - used to remember various flags.
  13122. //
  13123. ULONG Flags;
  13124. //
  13125. // The following union is used for one of three purposes:
  13126. //
  13127. // 1. This IRP is an associated IRP. The field is a pointer to a master
  13128. // IRP.
  13129. //
  13130. // 2. This is the master IRP. The field is the count of the number of
  13131. // IRPs which must complete (associated IRPs) before the master can
  13132. // complete.
  13133. //
  13134. // 3. This operation is being buffered and the field is the address of
  13135. // the system space buffer.
  13136. //
  13137. union {
  13138. struct _IRP *MasterIrp;
  13139. LONG IrpCount;
  13140. PVOID SystemBuffer;
  13141. } AssociatedIrp;
  13142. //
  13143. // Thread list entry - allows queueing the IRP to the thread pending I/O
  13144. // request packet list.
  13145. //
  13146. LIST_ENTRY ThreadListEntry;
  13147. //
  13148. // I/O status - final status of operation.
  13149. //
  13150. IO_STATUS_BLOCK IoStatus;
  13151. //
  13152. // Requestor mode - mode of the original requestor of this operation.
  13153. //
  13154. KPROCESSOR_MODE RequestorMode;
  13155. //
  13156. // Pending returned - TRUE if pending was initially returned as the
  13157. // status for this packet.
  13158. //
  13159. BOOLEAN PendingReturned;
  13160. //
  13161. // Stack state information.
  13162. //
  13163. CHAR StackCount;
  13164. CHAR CurrentLocation;
  13165. //
  13166. // Cancel - packet has been canceled.
  13167. //
  13168. BOOLEAN Cancel;
  13169. //
  13170. // Cancel Irql - Irql at which the cancel spinlock was acquired.
  13171. //
  13172. KIRQL CancelIrql;
  13173. //
  13174. // ApcEnvironment - Used to save the APC environment at the time that the
  13175. // packet was initialized.
  13176. //
  13177. CCHAR ApcEnvironment;
  13178. //
  13179. // Allocation control flags.
  13180. //
  13181. UCHAR AllocationFlags;
  13182. //
  13183. // User parameters.
  13184. //
  13185. PIO_STATUS_BLOCK UserIosb;
  13186. PKEVENT UserEvent;
  13187. union {
  13188. struct {
  13189. PIO_APC_ROUTINE UserApcRoutine;
  13190. PVOID UserApcContext;
  13191. } AsynchronousParameters;
  13192. LARGE_INTEGER AllocationSize;
  13193. } Overlay;
  13194. //
  13195. // CancelRoutine - Used to contain the address of a cancel routine supplied
  13196. // by a device driver when the IRP is in a cancelable state.
  13197. //
  13198. PDRIVER_CANCEL CancelRoutine;
  13199. //
  13200. // Note that the UserBuffer parameter is outside of the stack so that I/O
  13201. // completion can copy data back into the user's address space without
  13202. // having to know exactly which service was being invoked. The length
  13203. // of the copy is stored in the second half of the I/O status block. If
  13204. // the UserBuffer field is NULL, then no copy is performed.
  13205. //
  13206. PVOID UserBuffer;
  13207. //
  13208. // Kernel structures
  13209. //
  13210. // The following section contains kernel structures which the IRP needs
  13211. // in order to place various work information in kernel controller system
  13212. // queues. Because the size and alignment cannot be controlled, they are
  13213. // placed here at the end so they just hang off and do not affect the
  13214. // alignment of other fields in the IRP.
  13215. //
  13216. union {
  13217. struct {
  13218. union {
  13219. //
  13220. // DeviceQueueEntry - The device queue entry field is used to
  13221. // queue the IRP to the device driver device queue.
  13222. //
  13223. KDEVICE_QUEUE_ENTRY DeviceQueueEntry;
  13224. struct {
  13225. //
  13226. // The following are available to the driver to use in
  13227. // whatever manner is desired, while the driver owns the
  13228. // packet.
  13229. //
  13230. PVOID DriverContext[4];
  13231. } ;
  13232. } ;
  13233. //
  13234. // Thread - pointer to caller's Thread Control Block.
  13235. //
  13236. PETHREAD Thread;
  13237. //
  13238. // Auxiliary buffer - pointer to any auxiliary buffer that is
  13239. // required to pass information to a driver that is not contained
  13240. // in a normal buffer.
  13241. //
  13242. PCHAR AuxiliaryBuffer;
  13243. //
  13244. // The following unnamed structure must be exactly identical
  13245. // to the unnamed structure used in the minipacket header used
  13246. // for completion queue entries.
  13247. //
  13248. struct {
  13249. //
  13250. // List entry - used to queue the packet to completion queue, among
  13251. // others.
  13252. //
  13253. LIST_ENTRY ListEntry;
  13254. union {
  13255. //
  13256. // Current stack location - contains a pointer to the current
  13257. // IO_STACK_LOCATION structure in the IRP stack. This field
  13258. // should never be directly accessed by drivers. They should
  13259. // use the standard functions.
  13260. //
  13261. struct _IO_STACK_LOCATION *CurrentStackLocation;
  13262. //
  13263. // Minipacket type.
  13264. //
  13265. ULONG PacketType;
  13266. };
  13267. };
  13268. //
  13269. // Original file object - pointer to the original file object
  13270. // that was used to open the file. This field is owned by the
  13271. // I/O system and should not be used by any other drivers.
  13272. //
  13273. PFILE_OBJECT OriginalFileObject;
  13274. } Overlay;
  13275. //
  13276. // APC - This APC control block is used for the special kernel APC as
  13277. // well as for the caller's APC, if one was specified in the original
  13278. // argument list. If so, then the APC is reused for the normal APC for
  13279. // whatever mode the caller was in and the "special" routine that is
  13280. // invoked before the APC gets control simply deallocates the IRP.
  13281. //
  13282. KAPC Apc;
  13283. //
  13284. // CompletionKey - This is the key that is used to distinguish
  13285. // individual I/O operations initiated on a single file handle.
  13286. //
  13287. PVOID CompletionKey;
  13288. } Tail;
  13289. } IRP, *PIRP;
  13290. //
  13291. // Define completion routine types for use in stack locations in an IRP
  13292. //
  13293. typedef
  13294. NTSTATUS
  13295. (*PIO_COMPLETION_ROUTINE) (
  13296. IN PDEVICE_OBJECT DeviceObject,
  13297. IN PIRP Irp,
  13298. IN PVOID Context
  13299. );
  13300. //
  13301. // Define stack location control flags
  13302. //
  13303. #define SL_PENDING_RETURNED 0x01
  13304. #define SL_INVOKE_ON_CANCEL 0x20
  13305. #define SL_INVOKE_ON_SUCCESS 0x40
  13306. #define SL_INVOKE_ON_ERROR 0x80
  13307. //
  13308. // Define flags for various functions
  13309. //
  13310. //
  13311. // Create / Create Named Pipe
  13312. //
  13313. // The following flags must exactly match those in the IoCreateFile call's
  13314. // options. The case sensitive flag is added in later, by the parse routine,
  13315. // and is not an actual option to open. Rather, it is part of the object
  13316. // manager's attributes structure.
  13317. //
  13318. #define SL_FORCE_ACCESS_CHECK 0x01
  13319. #define SL_OPEN_PAGING_FILE 0x02
  13320. #define SL_OPEN_TARGET_DIRECTORY 0x04
  13321. #define SL_CASE_SENSITIVE 0x80
  13322. //
  13323. // Read / Write
  13324. //
  13325. #define SL_KEY_SPECIFIED 0x01
  13326. #define SL_OVERRIDE_VERIFY_VOLUME 0x02
  13327. #define SL_WRITE_THROUGH 0x04
  13328. #define SL_FT_SEQUENTIAL_WRITE 0x08
  13329. //
  13330. // Device I/O Control
  13331. //
  13332. //
  13333. // Same SL_OVERRIDE_VERIFY_VOLUME as for read/write above.
  13334. //
  13335. #define SL_READ_ACCESS_GRANTED 0x01
  13336. #define SL_WRITE_ACCESS_GRANTED 0x04 // Gap for SL_OVERRIDE_VERIFY_VOLUME
  13337. //
  13338. // Lock
  13339. //
  13340. #define SL_FAIL_IMMEDIATELY 0x01
  13341. #define SL_EXCLUSIVE_LOCK 0x02
  13342. //
  13343. // QueryDirectory / QueryEa / QueryQuota
  13344. //
  13345. #define SL_RESTART_SCAN 0x01
  13346. #define SL_RETURN_SINGLE_ENTRY 0x02
  13347. #define SL_INDEX_SPECIFIED 0x04
  13348. //
  13349. // NotifyDirectory
  13350. //
  13351. #define SL_WATCH_TREE 0x01
  13352. //
  13353. // FileSystemControl
  13354. //
  13355. // minor: mount/verify volume
  13356. //
  13357. #define SL_ALLOW_RAW_MOUNT 0x01
  13358. //
  13359. // Define PNP/POWER types required by IRP_MJ_PNP/IRP_MJ_POWER.
  13360. //
  13361. typedef enum _DEVICE_RELATION_TYPE {
  13362. BusRelations,
  13363. EjectionRelations,
  13364. PowerRelations,
  13365. RemovalRelations,
  13366. TargetDeviceRelation,
  13367. SingleBusRelations
  13368. } DEVICE_RELATION_TYPE, *PDEVICE_RELATION_TYPE;
  13369. typedef struct _DEVICE_RELATIONS {
  13370. ULONG Count;
  13371. PDEVICE_OBJECT Objects[1]; // variable length
  13372. } DEVICE_RELATIONS, *PDEVICE_RELATIONS;
  13373. typedef enum _DEVICE_USAGE_NOTIFICATION_TYPE {
  13374. DeviceUsageTypeUndefined,
  13375. DeviceUsageTypePaging,
  13376. DeviceUsageTypeHibernation,
  13377. DeviceUsageTypeDumpFile
  13378. } DEVICE_USAGE_NOTIFICATION_TYPE;
  13379. // begin_ntminiport
  13380. // workaround overloaded definition (rpc generated headers all define INTERFACE
  13381. // to match the class name).
  13382. #undef INTERFACE
  13383. typedef struct _INTERFACE {
  13384. USHORT Size;
  13385. USHORT Version;
  13386. PVOID Context;
  13387. PINTERFACE_REFERENCE InterfaceReference;
  13388. PINTERFACE_DEREFERENCE InterfaceDereference;
  13389. // interface specific entries go here
  13390. } INTERFACE, *PINTERFACE;
  13391. // end_ntminiport
  13392. typedef struct _DEVICE_CAPABILITIES {
  13393. USHORT Size;
  13394. USHORT Version; // the version documented here is version 1
  13395. ULONG DeviceD1:1;
  13396. ULONG DeviceD2:1;
  13397. ULONG LockSupported:1;
  13398. ULONG EjectSupported:1; // Ejectable in S0
  13399. ULONG Removable:1;
  13400. ULONG DockDevice:1;
  13401. ULONG UniqueID:1;
  13402. ULONG SilentInstall:1;
  13403. ULONG RawDeviceOK:1;
  13404. ULONG SurpriseRemovalOK:1;
  13405. ULONG WakeFromD0:1;
  13406. ULONG WakeFromD1:1;
  13407. ULONG WakeFromD2:1;
  13408. ULONG WakeFromD3:1;
  13409. ULONG HardwareDisabled:1;
  13410. ULONG NonDynamic:1;
  13411. ULONG WarmEjectSupported:1;
  13412. ULONG NoDisplayInUI:1;
  13413. ULONG Reserved:14;
  13414. ULONG Address;
  13415. ULONG UINumber;
  13416. DEVICE_POWER_STATE DeviceState[POWER_SYSTEM_MAXIMUM];
  13417. SYSTEM_POWER_STATE SystemWake;
  13418. DEVICE_POWER_STATE DeviceWake;
  13419. ULONG D1Latency;
  13420. ULONG D2Latency;
  13421. ULONG D3Latency;
  13422. } DEVICE_CAPABILITIES, *PDEVICE_CAPABILITIES;
  13423. typedef struct _POWER_SEQUENCE {
  13424. ULONG SequenceD1;
  13425. ULONG SequenceD2;
  13426. ULONG SequenceD3;
  13427. } POWER_SEQUENCE, *PPOWER_SEQUENCE;
  13428. typedef enum {
  13429. BusQueryDeviceID = 0, // <Enumerator>\<Enumerator-specific device id>
  13430. BusQueryHardwareIDs = 1, // Hardware ids
  13431. BusQueryCompatibleIDs = 2, // compatible device ids
  13432. BusQueryInstanceID = 3, // persistent id for this instance of the device
  13433. BusQueryDeviceSerialNumber = 4 // serial number for this device
  13434. } BUS_QUERY_ID_TYPE, *PBUS_QUERY_ID_TYPE;
  13435. typedef ULONG PNP_DEVICE_STATE, *PPNP_DEVICE_STATE;
  13436. #define PNP_DEVICE_DISABLED 0x00000001
  13437. #define PNP_DEVICE_DONT_DISPLAY_IN_UI 0x00000002
  13438. #define PNP_DEVICE_FAILED 0x00000004
  13439. #define PNP_DEVICE_REMOVED 0x00000008
  13440. #define PNP_DEVICE_RESOURCE_REQUIREMENTS_CHANGED 0x00000010
  13441. #define PNP_DEVICE_NOT_DISABLEABLE 0x00000020
  13442. typedef enum {
  13443. DeviceTextDescription = 0, // DeviceDesc property
  13444. DeviceTextLocationInformation = 1 // DeviceLocation property
  13445. } DEVICE_TEXT_TYPE, *PDEVICE_TEXT_TYPE;
  13446. //
  13447. // Define I/O Request Packet (IRP) stack locations
  13448. //
  13449. #if !defined(_AMD64_) && !defined(_IA64_)
  13450. #include "pshpack4.h"
  13451. #endif
  13452. // begin_ntndis
  13453. #if defined(_WIN64)
  13454. #define POINTER_ALIGNMENT DECLSPEC_ALIGN(8)
  13455. #else
  13456. #define POINTER_ALIGNMENT
  13457. #endif
  13458. // end_ntndis
  13459. typedef struct _IO_STACK_LOCATION {
  13460. UCHAR MajorFunction;
  13461. UCHAR MinorFunction;
  13462. UCHAR Flags;
  13463. UCHAR Control;
  13464. //
  13465. // The following user parameters are based on the service that is being
  13466. // invoked. Drivers and file systems can determine which set to use based
  13467. // on the above major and minor function codes.
  13468. //
  13469. union {
  13470. //
  13471. // System service parameters for: NtCreateFile
  13472. //
  13473. struct {
  13474. PIO_SECURITY_CONTEXT SecurityContext;
  13475. ULONG Options;
  13476. USHORT POINTER_ALIGNMENT FileAttributes;
  13477. USHORT ShareAccess;
  13478. ULONG POINTER_ALIGNMENT EaLength;
  13479. } Create;
  13480. //
  13481. // System service parameters for: NtReadFile
  13482. //
  13483. struct {
  13484. ULONG Length;
  13485. ULONG POINTER_ALIGNMENT Key;
  13486. LARGE_INTEGER ByteOffset;
  13487. } Read;
  13488. //
  13489. // System service parameters for: NtWriteFile
  13490. //
  13491. struct {
  13492. ULONG Length;
  13493. ULONG POINTER_ALIGNMENT Key;
  13494. LARGE_INTEGER ByteOffset;
  13495. } Write;
  13496. //
  13497. // System service parameters for: NtQueryInformationFile
  13498. //
  13499. struct {
  13500. ULONG Length;
  13501. FILE_INFORMATION_CLASS POINTER_ALIGNMENT FileInformationClass;
  13502. } QueryFile;
  13503. //
  13504. // System service parameters for: NtSetInformationFile
  13505. //
  13506. struct {
  13507. ULONG Length;
  13508. FILE_INFORMATION_CLASS POINTER_ALIGNMENT FileInformationClass;
  13509. PFILE_OBJECT FileObject;
  13510. union {
  13511. struct {
  13512. BOOLEAN ReplaceIfExists;
  13513. BOOLEAN AdvanceOnly;
  13514. };
  13515. ULONG ClusterCount;
  13516. HANDLE DeleteHandle;
  13517. };
  13518. } SetFile;
  13519. //
  13520. // System service parameters for: NtQueryVolumeInformationFile
  13521. //
  13522. struct {
  13523. ULONG Length;
  13524. FS_INFORMATION_CLASS POINTER_ALIGNMENT FsInformationClass;
  13525. } QueryVolume;
  13526. //
  13527. // System service parameters for: NtFlushBuffersFile
  13528. //
  13529. // No extra user-supplied parameters.
  13530. //
  13531. //
  13532. // System service parameters for: NtDeviceIoControlFile
  13533. //
  13534. // Note that the user's output buffer is stored in the UserBuffer field
  13535. // and the user's input buffer is stored in the SystemBuffer field.
  13536. //
  13537. struct {
  13538. ULONG OutputBufferLength;
  13539. ULONG POINTER_ALIGNMENT InputBufferLength;
  13540. ULONG POINTER_ALIGNMENT IoControlCode;
  13541. PVOID Type3InputBuffer;
  13542. } DeviceIoControl;
  13543. // end_wdm
  13544. //
  13545. // System service parameters for: NtQuerySecurityObject
  13546. //
  13547. struct {
  13548. SECURITY_INFORMATION SecurityInformation;
  13549. ULONG POINTER_ALIGNMENT Length;
  13550. } QuerySecurity;
  13551. //
  13552. // System service parameters for: NtSetSecurityObject
  13553. //
  13554. struct {
  13555. SECURITY_INFORMATION SecurityInformation;
  13556. PSECURITY_DESCRIPTOR SecurityDescriptor;
  13557. } SetSecurity;
  13558. // begin_wdm
  13559. //
  13560. // Non-system service parameters.
  13561. //
  13562. // Parameters for MountVolume
  13563. //
  13564. struct {
  13565. PVPB Vpb;
  13566. PDEVICE_OBJECT DeviceObject;
  13567. } MountVolume;
  13568. //
  13569. // Parameters for VerifyVolume
  13570. //
  13571. struct {
  13572. PVPB Vpb;
  13573. PDEVICE_OBJECT DeviceObject;
  13574. } VerifyVolume;
  13575. //
  13576. // Parameters for Scsi with internal device contorl.
  13577. //
  13578. struct {
  13579. struct _SCSI_REQUEST_BLOCK *Srb;
  13580. } Scsi;
  13581. //
  13582. // Parameters for IRP_MN_QUERY_DEVICE_RELATIONS
  13583. //
  13584. struct {
  13585. DEVICE_RELATION_TYPE Type;
  13586. } QueryDeviceRelations;
  13587. //
  13588. // Parameters for IRP_MN_QUERY_INTERFACE
  13589. //
  13590. struct {
  13591. CONST GUID *InterfaceType;
  13592. USHORT Size;
  13593. USHORT Version;
  13594. PINTERFACE Interface;
  13595. PVOID InterfaceSpecificData;
  13596. } QueryInterface;
  13597. // end_ntifs
  13598. //
  13599. // Parameters for IRP_MN_QUERY_CAPABILITIES
  13600. //
  13601. struct {
  13602. PDEVICE_CAPABILITIES Capabilities;
  13603. } DeviceCapabilities;
  13604. //
  13605. // Parameters for IRP_MN_FILTER_RESOURCE_REQUIREMENTS
  13606. //
  13607. struct {
  13608. PIO_RESOURCE_REQUIREMENTS_LIST IoResourceRequirementList;
  13609. } FilterResourceRequirements;
  13610. //
  13611. // Parameters for IRP_MN_READ_CONFIG and IRP_MN_WRITE_CONFIG
  13612. //
  13613. struct {
  13614. ULONG WhichSpace;
  13615. PVOID Buffer;
  13616. ULONG Offset;
  13617. ULONG POINTER_ALIGNMENT Length;
  13618. } ReadWriteConfig;
  13619. //
  13620. // Parameters for IRP_MN_SET_LOCK
  13621. //
  13622. struct {
  13623. BOOLEAN Lock;
  13624. } SetLock;
  13625. //
  13626. // Parameters for IRP_MN_QUERY_ID
  13627. //
  13628. struct {
  13629. BUS_QUERY_ID_TYPE IdType;
  13630. } QueryId;
  13631. //
  13632. // Parameters for IRP_MN_QUERY_DEVICE_TEXT
  13633. //
  13634. struct {
  13635. DEVICE_TEXT_TYPE DeviceTextType;
  13636. LCID POINTER_ALIGNMENT LocaleId;
  13637. } QueryDeviceText;
  13638. //
  13639. // Parameters for IRP_MN_DEVICE_USAGE_NOTIFICATION
  13640. //
  13641. struct {
  13642. BOOLEAN InPath;
  13643. BOOLEAN Reserved[3];
  13644. DEVICE_USAGE_NOTIFICATION_TYPE POINTER_ALIGNMENT Type;
  13645. } UsageNotification;
  13646. //
  13647. // Parameters for IRP_MN_WAIT_WAKE
  13648. //
  13649. struct {
  13650. SYSTEM_POWER_STATE PowerState;
  13651. } WaitWake;
  13652. //
  13653. // Parameter for IRP_MN_POWER_SEQUENCE
  13654. //
  13655. struct {
  13656. PPOWER_SEQUENCE PowerSequence;
  13657. } PowerSequence;
  13658. //
  13659. // Parameters for IRP_MN_SET_POWER and IRP_MN_QUERY_POWER
  13660. //
  13661. struct {
  13662. ULONG SystemContext;
  13663. POWER_STATE_TYPE POINTER_ALIGNMENT Type;
  13664. POWER_STATE POINTER_ALIGNMENT State;
  13665. POWER_ACTION POINTER_ALIGNMENT ShutdownType;
  13666. } Power;
  13667. //
  13668. // Parameters for StartDevice
  13669. //
  13670. struct {
  13671. PCM_RESOURCE_LIST AllocatedResources;
  13672. PCM_RESOURCE_LIST AllocatedResourcesTranslated;
  13673. } StartDevice;
  13674. // begin_ntifs
  13675. //
  13676. // Parameters for Cleanup
  13677. //
  13678. // No extra parameters supplied
  13679. //
  13680. //
  13681. // WMI Irps
  13682. //
  13683. struct {
  13684. ULONG_PTR ProviderId;
  13685. PVOID DataPath;
  13686. ULONG BufferSize;
  13687. PVOID Buffer;
  13688. } WMI;
  13689. //
  13690. // Others - driver-specific
  13691. //
  13692. struct {
  13693. PVOID Argument1;
  13694. PVOID Argument2;
  13695. PVOID Argument3;
  13696. PVOID Argument4;
  13697. } Others;
  13698. } Parameters;
  13699. //
  13700. // Save a pointer to this device driver's device object for this request
  13701. // so it can be passed to the completion routine if needed.
  13702. //
  13703. PDEVICE_OBJECT DeviceObject;
  13704. //
  13705. // The following location contains a pointer to the file object for this
  13706. //
  13707. PFILE_OBJECT FileObject;
  13708. //
  13709. // The following routine is invoked depending on the flags in the above
  13710. // flags field.
  13711. //
  13712. PIO_COMPLETION_ROUTINE CompletionRoutine;
  13713. //
  13714. // The following is used to store the address of the context parameter
  13715. // that should be passed to the CompletionRoutine.
  13716. //
  13717. PVOID Context;
  13718. } IO_STACK_LOCATION, *PIO_STACK_LOCATION;
  13719. #if !defined(_AMD64_) && !defined(_IA64_)
  13720. #include "poppack.h"
  13721. #endif
  13722. //
  13723. // Define the share access structure used by file systems to determine
  13724. // whether or not another accessor may open the file.
  13725. //
  13726. typedef struct _SHARE_ACCESS {
  13727. ULONG OpenCount;
  13728. ULONG Readers;
  13729. ULONG Writers;
  13730. ULONG Deleters;
  13731. ULONG SharedRead;
  13732. ULONG SharedWrite;
  13733. ULONG SharedDelete;
  13734. } SHARE_ACCESS, *PSHARE_ACCESS;
  13735. // end_wdm
  13736. //
  13737. // The following structure is used by drivers that are initializing to
  13738. // determine the number of devices of a particular type that have already
  13739. // been initialized. It is also used to track whether or not the AtDisk
  13740. // address range has already been claimed. Finally, it is used by the
  13741. // NtQuerySystemInformation system service to return device type counts.
  13742. //
  13743. typedef struct _CONFIGURATION_INFORMATION {
  13744. //
  13745. // This field indicates the total number of disks in the system. This
  13746. // number should be used by the driver to determine the name of new
  13747. // disks. This field should be updated by the driver as it finds new
  13748. // disks.
  13749. //
  13750. ULONG DiskCount; // Count of hard disks thus far
  13751. ULONG FloppyCount; // Count of floppy disks thus far
  13752. ULONG CdRomCount; // Count of CD-ROM drives thus far
  13753. ULONG TapeCount; // Count of tape drives thus far
  13754. ULONG ScsiPortCount; // Count of SCSI port adapters thus far
  13755. ULONG SerialCount; // Count of serial devices thus far
  13756. ULONG ParallelCount; // Count of parallel devices thus far
  13757. //
  13758. // These next two fields indicate ownership of one of the two IO address
  13759. // spaces that are used by WD1003-compatable disk controllers.
  13760. //
  13761. BOOLEAN AtDiskPrimaryAddressClaimed; // 0x1F0 - 0x1FF
  13762. BOOLEAN AtDiskSecondaryAddressClaimed; // 0x170 - 0x17F
  13763. //
  13764. // Indicates the structure version, as anything value belong this will have been added.
  13765. // Use the structure size as the version.
  13766. //
  13767. ULONG Version;
  13768. //
  13769. // Indicates the total number of medium changer devices in the system.
  13770. // This field will be updated by the drivers as it determines that
  13771. // new devices have been found and will be supported.
  13772. //
  13773. ULONG MediumChangerCount;
  13774. } CONFIGURATION_INFORMATION, *PCONFIGURATION_INFORMATION;
  13775. //
  13776. // Public I/O routine definitions
  13777. //
  13778. NTKERNELAPI
  13779. VOID
  13780. IoAcquireCancelSpinLock(
  13781. OUT PKIRQL Irql
  13782. );
  13783. DECLSPEC_DEPRECATED_DDK // Use AllocateAdapterChannel
  13784. NTKERNELAPI
  13785. NTSTATUS
  13786. IoAllocateAdapterChannel(
  13787. IN PADAPTER_OBJECT AdapterObject,
  13788. IN PDEVICE_OBJECT DeviceObject,
  13789. IN ULONG NumberOfMapRegisters,
  13790. IN PDRIVER_CONTROL ExecutionRoutine,
  13791. IN PVOID Context
  13792. );
  13793. NTKERNELAPI
  13794. VOID
  13795. IoAllocateController(
  13796. IN PCONTROLLER_OBJECT ControllerObject,
  13797. IN PDEVICE_OBJECT DeviceObject,
  13798. IN PDRIVER_CONTROL ExecutionRoutine,
  13799. IN PVOID Context
  13800. );
  13801. // begin_wdm
  13802. NTKERNELAPI
  13803. NTSTATUS
  13804. IoAllocateDriverObjectExtension(
  13805. IN PDRIVER_OBJECT DriverObject,
  13806. IN PVOID ClientIdentificationAddress,
  13807. IN ULONG DriverObjectExtensionSize,
  13808. OUT PVOID *DriverObjectExtension
  13809. );
  13810. // begin_ntifs
  13811. NTKERNELAPI
  13812. PVOID
  13813. IoAllocateErrorLogEntry(
  13814. IN PVOID IoObject,
  13815. IN UCHAR EntrySize
  13816. );
  13817. NTKERNELAPI
  13818. PIRP
  13819. IoAllocateIrp(
  13820. IN CCHAR StackSize,
  13821. IN BOOLEAN ChargeQuota
  13822. );
  13823. NTKERNELAPI
  13824. PMDL
  13825. IoAllocateMdl(
  13826. IN PVOID VirtualAddress,
  13827. IN ULONG Length,
  13828. IN BOOLEAN SecondaryBuffer,
  13829. IN BOOLEAN ChargeQuota,
  13830. IN OUT PIRP Irp OPTIONAL
  13831. );
  13832. // end_wdm end_ntifs
  13833. //++
  13834. //
  13835. // VOID
  13836. // IoAssignArcName(
  13837. // IN PUNICODE_STRING ArcName,
  13838. // IN PUNICODE_STRING DeviceName
  13839. // )
  13840. //
  13841. // Routine Description:
  13842. //
  13843. // This routine is invoked by drivers of bootable media to create a symbolic
  13844. // link between the ARC name of their device and its NT name. This allows
  13845. // the system to determine which device in the system was actually booted
  13846. // from since the ARC firmware only deals in ARC names, and NT only deals
  13847. // in NT names.
  13848. //
  13849. // Arguments:
  13850. //
  13851. // ArcName - Supplies the Unicode string representing the ARC name.
  13852. //
  13853. // DeviceName - Supplies the name to which the ARCname refers.
  13854. //
  13855. // Return Value:
  13856. //
  13857. // None.
  13858. //
  13859. //--
  13860. #define IoAssignArcName( ArcName, DeviceName ) ( \
  13861. IoCreateSymbolicLink( (ArcName), (DeviceName) ) )
  13862. DECLSPEC_DEPRECATED_DDK // Use Pnp or IoReprtDetectedDevice
  13863. NTKERNELAPI
  13864. NTSTATUS
  13865. IoAssignResources (
  13866. IN PUNICODE_STRING RegistryPath,
  13867. IN PUNICODE_STRING DriverClassName OPTIONAL,
  13868. IN PDRIVER_OBJECT DriverObject,
  13869. IN PDEVICE_OBJECT DeviceObject OPTIONAL,
  13870. IN PIO_RESOURCE_REQUIREMENTS_LIST RequestedResources,
  13871. IN OUT PCM_RESOURCE_LIST *AllocatedResources
  13872. );
  13873. NTKERNELAPI
  13874. NTSTATUS
  13875. IoAttachDevice(
  13876. IN PDEVICE_OBJECT SourceDevice,
  13877. IN PUNICODE_STRING TargetDevice,
  13878. OUT PDEVICE_OBJECT *AttachedDevice
  13879. );
  13880. // end_wdm
  13881. DECLSPEC_DEPRECATED_DDK // Use IoAttachDeviceToDeviceStack
  13882. NTKERNELAPI
  13883. NTSTATUS
  13884. IoAttachDeviceByPointer(
  13885. IN PDEVICE_OBJECT SourceDevice,
  13886. IN PDEVICE_OBJECT TargetDevice
  13887. );
  13888. // begin_wdm
  13889. NTKERNELAPI
  13890. PDEVICE_OBJECT
  13891. IoAttachDeviceToDeviceStack(
  13892. IN PDEVICE_OBJECT SourceDevice,
  13893. IN PDEVICE_OBJECT TargetDevice
  13894. );
  13895. NTKERNELAPI
  13896. PIRP
  13897. IoBuildAsynchronousFsdRequest(
  13898. IN ULONG MajorFunction,
  13899. IN PDEVICE_OBJECT DeviceObject,
  13900. IN OUT PVOID Buffer OPTIONAL,
  13901. IN ULONG Length OPTIONAL,
  13902. IN PLARGE_INTEGER StartingOffset OPTIONAL,
  13903. IN PIO_STATUS_BLOCK IoStatusBlock OPTIONAL
  13904. );
  13905. NTKERNELAPI
  13906. PIRP
  13907. IoBuildDeviceIoControlRequest(
  13908. IN ULONG IoControlCode,
  13909. IN PDEVICE_OBJECT DeviceObject,
  13910. IN PVOID InputBuffer OPTIONAL,
  13911. IN ULONG InputBufferLength,
  13912. OUT PVOID OutputBuffer OPTIONAL,
  13913. IN ULONG OutputBufferLength,
  13914. IN BOOLEAN InternalDeviceIoControl,
  13915. IN PKEVENT Event,
  13916. OUT PIO_STATUS_BLOCK IoStatusBlock
  13917. );
  13918. NTKERNELAPI
  13919. VOID
  13920. IoBuildPartialMdl(
  13921. IN PMDL SourceMdl,
  13922. IN OUT PMDL TargetMdl,
  13923. IN PVOID VirtualAddress,
  13924. IN ULONG Length
  13925. );
  13926. typedef struct _BOOTDISK_INFORMATION {
  13927. LONGLONG BootPartitionOffset;
  13928. LONGLONG SystemPartitionOffset;
  13929. ULONG BootDeviceSignature;
  13930. ULONG SystemDeviceSignature;
  13931. } BOOTDISK_INFORMATION, *PBOOTDISK_INFORMATION;
  13932. //
  13933. // This structure should follow the previous structure field for field.
  13934. //
  13935. typedef struct _BOOTDISK_INFORMATION_EX {
  13936. LONGLONG BootPartitionOffset;
  13937. LONGLONG SystemPartitionOffset;
  13938. ULONG BootDeviceSignature;
  13939. ULONG SystemDeviceSignature;
  13940. GUID BootDeviceGuid;
  13941. GUID SystemDeviceGuid;
  13942. BOOLEAN BootDeviceIsGpt;
  13943. BOOLEAN SystemDeviceIsGpt;
  13944. } BOOTDISK_INFORMATION_EX, *PBOOTDISK_INFORMATION_EX;
  13945. NTKERNELAPI
  13946. NTSTATUS
  13947. IoGetBootDiskInformation(
  13948. IN OUT PBOOTDISK_INFORMATION BootDiskInformation,
  13949. IN ULONG Size
  13950. );
  13951. NTKERNELAPI
  13952. PIRP
  13953. IoBuildSynchronousFsdRequest(
  13954. IN ULONG MajorFunction,
  13955. IN PDEVICE_OBJECT DeviceObject,
  13956. IN OUT PVOID Buffer OPTIONAL,
  13957. IN ULONG Length OPTIONAL,
  13958. IN PLARGE_INTEGER StartingOffset OPTIONAL,
  13959. IN PKEVENT Event,
  13960. OUT PIO_STATUS_BLOCK IoStatusBlock
  13961. );
  13962. NTKERNELAPI
  13963. NTSTATUS
  13964. FASTCALL
  13965. IofCallDriver(
  13966. IN PDEVICE_OBJECT DeviceObject,
  13967. IN OUT PIRP Irp
  13968. );
  13969. #define IoCallDriver(a,b) \
  13970. IofCallDriver(a,b)
  13971. NTKERNELAPI
  13972. BOOLEAN
  13973. IoCancelIrp(
  13974. IN PIRP Irp
  13975. );
  13976. NTKERNELAPI
  13977. NTSTATUS
  13978. IoCheckShareAccess(
  13979. IN ACCESS_MASK DesiredAccess,
  13980. IN ULONG DesiredShareAccess,
  13981. IN OUT PFILE_OBJECT FileObject,
  13982. IN OUT PSHARE_ACCESS ShareAccess,
  13983. IN BOOLEAN Update
  13984. );
  13985. //
  13986. // This value should be returned from completion routines to continue
  13987. // completing the IRP upwards. Otherwise, STATUS_MORE_PROCESSING_REQUIRED
  13988. // should be returned.
  13989. //
  13990. #define STATUS_CONTINUE_COMPLETION STATUS_SUCCESS
  13991. //
  13992. // Completion routines can also use this enumeration in place of status codes.
  13993. //
  13994. typedef enum _IO_COMPLETION_ROUTINE_RESULT {
  13995. ContinueCompletion = STATUS_CONTINUE_COMPLETION,
  13996. StopCompletion = STATUS_MORE_PROCESSING_REQUIRED
  13997. } IO_COMPLETION_ROUTINE_RESULT, *PIO_COMPLETION_ROUTINE_RESULT;
  13998. NTKERNELAPI
  13999. VOID
  14000. FASTCALL
  14001. IofCompleteRequest(
  14002. IN PIRP Irp,
  14003. IN CCHAR PriorityBoost
  14004. );
  14005. #define IoCompleteRequest(a,b) \
  14006. IofCompleteRequest(a,b)
  14007. // end_ntifs
  14008. NTKERNELAPI
  14009. NTSTATUS
  14010. IoConnectInterrupt(
  14011. OUT PKINTERRUPT *InterruptObject,
  14012. IN PKSERVICE_ROUTINE ServiceRoutine,
  14013. IN PVOID ServiceContext,
  14014. IN PKSPIN_LOCK SpinLock OPTIONAL,
  14015. IN ULONG Vector,
  14016. IN KIRQL Irql,
  14017. IN KIRQL SynchronizeIrql,
  14018. IN KINTERRUPT_MODE InterruptMode,
  14019. IN BOOLEAN ShareVector,
  14020. IN KAFFINITY ProcessorEnableMask,
  14021. IN BOOLEAN FloatingSave
  14022. );
  14023. // end_wdm
  14024. NTKERNELAPI
  14025. PCONTROLLER_OBJECT
  14026. IoCreateController(
  14027. IN ULONG Size
  14028. );
  14029. // begin_wdm begin_ntifs
  14030. NTKERNELAPI
  14031. NTSTATUS
  14032. IoCreateDevice(
  14033. IN PDRIVER_OBJECT DriverObject,
  14034. IN ULONG DeviceExtensionSize,
  14035. IN PUNICODE_STRING DeviceName OPTIONAL,
  14036. IN DEVICE_TYPE DeviceType,
  14037. IN ULONG DeviceCharacteristics,
  14038. IN BOOLEAN Exclusive,
  14039. OUT PDEVICE_OBJECT *DeviceObject
  14040. );
  14041. #define WDM_MAJORVERSION 0x01
  14042. #define WDM_MINORVERSION 0x20
  14043. NTKERNELAPI
  14044. BOOLEAN
  14045. IoIsWdmVersionAvailable(
  14046. IN UCHAR MajorVersion,
  14047. IN UCHAR MinorVersion
  14048. );
  14049. // end_nthal
  14050. NTKERNELAPI
  14051. NTSTATUS
  14052. IoCreateFile(
  14053. OUT PHANDLE FileHandle,
  14054. IN ACCESS_MASK DesiredAccess,
  14055. IN POBJECT_ATTRIBUTES ObjectAttributes,
  14056. OUT PIO_STATUS_BLOCK IoStatusBlock,
  14057. IN PLARGE_INTEGER AllocationSize OPTIONAL,
  14058. IN ULONG FileAttributes,
  14059. IN ULONG ShareAccess,
  14060. IN ULONG Disposition,
  14061. IN ULONG CreateOptions,
  14062. IN PVOID EaBuffer OPTIONAL,
  14063. IN ULONG EaLength,
  14064. IN CREATE_FILE_TYPE CreateFileType,
  14065. IN PVOID ExtraCreateParameters OPTIONAL,
  14066. IN ULONG Options
  14067. );
  14068. NTKERNELAPI
  14069. PKEVENT
  14070. IoCreateNotificationEvent(
  14071. IN PUNICODE_STRING EventName,
  14072. OUT PHANDLE EventHandle
  14073. );
  14074. NTKERNELAPI
  14075. NTSTATUS
  14076. IoCreateSymbolicLink(
  14077. IN PUNICODE_STRING SymbolicLinkName,
  14078. IN PUNICODE_STRING DeviceName
  14079. );
  14080. NTKERNELAPI
  14081. PKEVENT
  14082. IoCreateSynchronizationEvent(
  14083. IN PUNICODE_STRING EventName,
  14084. OUT PHANDLE EventHandle
  14085. );
  14086. NTKERNELAPI
  14087. NTSTATUS
  14088. IoCreateUnprotectedSymbolicLink(
  14089. IN PUNICODE_STRING SymbolicLinkName,
  14090. IN PUNICODE_STRING DeviceName
  14091. );
  14092. // end_wdm
  14093. //++
  14094. //
  14095. // VOID
  14096. // IoDeassignArcName(
  14097. // IN PUNICODE_STRING ArcName
  14098. // )
  14099. //
  14100. // Routine Description:
  14101. //
  14102. // This routine is invoked by drivers to deassign an ARC name that they
  14103. // created to a device. This is generally only called if the driver is
  14104. // deleting the device object, which means that the driver is probably
  14105. // unloading.
  14106. //
  14107. // Arguments:
  14108. //
  14109. // ArcName - Supplies the ARC name to be removed.
  14110. //
  14111. // Return Value:
  14112. //
  14113. // None.
  14114. //
  14115. //--
  14116. #define IoDeassignArcName( ArcName ) ( \
  14117. IoDeleteSymbolicLink( (ArcName) ) )
  14118. // end_ntifs
  14119. NTKERNELAPI
  14120. VOID
  14121. IoDeleteController(
  14122. IN PCONTROLLER_OBJECT ControllerObject
  14123. );
  14124. // begin_wdm begin_ntifs
  14125. NTKERNELAPI
  14126. VOID
  14127. IoDeleteDevice(
  14128. IN PDEVICE_OBJECT DeviceObject
  14129. );
  14130. NTKERNELAPI
  14131. NTSTATUS
  14132. IoDeleteSymbolicLink(
  14133. IN PUNICODE_STRING SymbolicLinkName
  14134. );
  14135. NTKERNELAPI
  14136. VOID
  14137. IoDetachDevice(
  14138. IN OUT PDEVICE_OBJECT TargetDevice
  14139. );
  14140. // end_ntifs
  14141. NTKERNELAPI
  14142. VOID
  14143. IoDisconnectInterrupt(
  14144. IN PKINTERRUPT InterruptObject
  14145. );
  14146. NTKERNELAPI
  14147. VOID
  14148. IoFreeController(
  14149. IN PCONTROLLER_OBJECT ControllerObject
  14150. );
  14151. // begin_wdm begin_ntifs
  14152. NTKERNELAPI
  14153. VOID
  14154. IoFreeIrp(
  14155. IN PIRP Irp
  14156. );
  14157. NTKERNELAPI
  14158. VOID
  14159. IoFreeMdl(
  14160. IN PMDL Mdl
  14161. );
  14162. NTKERNELAPI
  14163. PDEVICE_OBJECT
  14164. IoGetAttachedDeviceReference(
  14165. IN PDEVICE_OBJECT DeviceObject
  14166. );
  14167. NTKERNELAPI
  14168. PCONFIGURATION_INFORMATION
  14169. IoGetConfigurationInformation( VOID );
  14170. //++
  14171. //
  14172. // PIO_STACK_LOCATION
  14173. // IoGetCurrentIrpStackLocation(
  14174. // IN PIRP Irp
  14175. // )
  14176. //
  14177. // Routine Description:
  14178. //
  14179. // This routine is invoked to return a pointer to the current stack location
  14180. // in an I/O Request Packet (IRP).
  14181. //
  14182. // Arguments:
  14183. //
  14184. // Irp - Pointer to the I/O Request Packet.
  14185. //
  14186. // Return Value:
  14187. //
  14188. // The function value is a pointer to the current stack location in the
  14189. // packet.
  14190. //
  14191. //--
  14192. #define IoGetCurrentIrpStackLocation( Irp ) ( (Irp)->Tail.Overlay.CurrentStackLocation )
  14193. // end_nthal end_wdm
  14194. NTKERNELAPI
  14195. PDEVICE_OBJECT
  14196. IoGetDeviceToVerify(
  14197. IN PETHREAD Thread
  14198. );
  14199. // begin_wdm
  14200. NTKERNELAPI
  14201. PVOID
  14202. IoGetDriverObjectExtension(
  14203. IN PDRIVER_OBJECT DriverObject,
  14204. IN PVOID ClientIdentificationAddress
  14205. );
  14206. NTKERNELAPI
  14207. PEPROCESS
  14208. IoGetCurrentProcess(
  14209. VOID
  14210. );
  14211. // begin_nthal
  14212. NTKERNELAPI
  14213. NTSTATUS
  14214. IoGetDeviceObjectPointer(
  14215. IN PUNICODE_STRING ObjectName,
  14216. IN ACCESS_MASK DesiredAccess,
  14217. OUT PFILE_OBJECT *FileObject,
  14218. OUT PDEVICE_OBJECT *DeviceObject
  14219. );
  14220. NTKERNELAPI
  14221. struct _DMA_ADAPTER *
  14222. IoGetDmaAdapter(
  14223. IN PDEVICE_OBJECT PhysicalDeviceObject, OPTIONAL // required for PnP drivers
  14224. IN struct _DEVICE_DESCRIPTION *DeviceDescription,
  14225. IN OUT PULONG NumberOfMapRegisters
  14226. );
  14227. NTKERNELAPI
  14228. BOOLEAN
  14229. IoForwardIrpSynchronously(
  14230. IN PDEVICE_OBJECT DeviceObject,
  14231. IN PIRP Irp
  14232. );
  14233. #define IoForwardAndCatchIrp IoForwardIrpSynchronously
  14234. // end_wdm
  14235. NTKERNELAPI
  14236. PGENERIC_MAPPING
  14237. IoGetFileObjectGenericMapping(
  14238. VOID
  14239. );
  14240. // end_nthal
  14241. // begin_wdm
  14242. //++
  14243. //
  14244. // ULONG
  14245. // IoGetFunctionCodeFromCtlCode(
  14246. // IN ULONG ControlCode
  14247. // )
  14248. //
  14249. // Routine Description:
  14250. //
  14251. // This routine extracts the function code from IOCTL and FSCTL function
  14252. // control codes.
  14253. // This routine should only be used by kernel mode code.
  14254. //
  14255. // Arguments:
  14256. //
  14257. // ControlCode - A function control code (IOCTL or FSCTL) from which the
  14258. // function code must be extracted.
  14259. //
  14260. // Return Value:
  14261. //
  14262. // The extracted function code.
  14263. //
  14264. // Note:
  14265. //
  14266. // The CTL_CODE macro, used to create IOCTL and FSCTL function control
  14267. // codes, is defined in ntioapi.h
  14268. //
  14269. //--
  14270. #define IoGetFunctionCodeFromCtlCode( ControlCode ) (\
  14271. ( ControlCode >> 2) & 0x00000FFF )
  14272. // begin_nthal
  14273. NTKERNELAPI
  14274. PVOID
  14275. IoGetInitialStack(
  14276. VOID
  14277. );
  14278. NTKERNELAPI
  14279. VOID
  14280. IoGetStackLimits (
  14281. OUT PULONG_PTR LowLimit,
  14282. OUT PULONG_PTR HighLimit
  14283. );
  14284. //
  14285. // The following function is used to tell the caller how much stack is available
  14286. //
  14287. FORCEINLINE
  14288. ULONG_PTR
  14289. IoGetRemainingStackSize (
  14290. VOID
  14291. )
  14292. {
  14293. ULONG_PTR Top;
  14294. ULONG_PTR Bottom;
  14295. IoGetStackLimits( &Bottom, &Top );
  14296. return((ULONG_PTR)(&Top) - Bottom );
  14297. }
  14298. //++
  14299. //
  14300. // PIO_STACK_LOCATION
  14301. // IoGetNextIrpStackLocation(
  14302. // IN PIRP Irp
  14303. // )
  14304. //
  14305. // Routine Description:
  14306. //
  14307. // This routine is invoked to return a pointer to the next stack location
  14308. // in an I/O Request Packet (IRP).
  14309. //
  14310. // Arguments:
  14311. //
  14312. // Irp - Pointer to the I/O Request Packet.
  14313. //
  14314. // Return Value:
  14315. //
  14316. // The function value is a pointer to the next stack location in the packet.
  14317. //
  14318. //--
  14319. #define IoGetNextIrpStackLocation( Irp ) (\
  14320. (Irp)->Tail.Overlay.CurrentStackLocation - 1 )
  14321. NTKERNELAPI
  14322. PDEVICE_OBJECT
  14323. IoGetRelatedDeviceObject(
  14324. IN PFILE_OBJECT FileObject
  14325. );
  14326. //++
  14327. //
  14328. // VOID
  14329. // IoInitializeDpcRequest(
  14330. // IN PDEVICE_OBJECT DeviceObject,
  14331. // IN PIO_DPC_ROUTINE DpcRoutine
  14332. // )
  14333. //
  14334. // Routine Description:
  14335. //
  14336. // This routine is invoked to initialize the DPC in a device object for a
  14337. // device driver during its initialization routine. The DPC is used later
  14338. // when the driver interrupt service routine requests that a DPC routine
  14339. // be queued for later execution.
  14340. //
  14341. // Arguments:
  14342. //
  14343. // DeviceObject - Pointer to the device object that the request is for.
  14344. //
  14345. // DpcRoutine - Address of the driver's DPC routine to be executed when
  14346. // the DPC is dequeued for processing.
  14347. //
  14348. // Return Value:
  14349. //
  14350. // None.
  14351. //
  14352. //--
  14353. #define IoInitializeDpcRequest( DeviceObject, DpcRoutine ) (\
  14354. KeInitializeDpc( &(DeviceObject)->Dpc, \
  14355. (PKDEFERRED_ROUTINE) (DpcRoutine), \
  14356. (DeviceObject) ) )
  14357. NTKERNELAPI
  14358. VOID
  14359. IoInitializeIrp(
  14360. IN OUT PIRP Irp,
  14361. IN USHORT PacketSize,
  14362. IN CCHAR StackSize
  14363. );
  14364. NTKERNELAPI
  14365. NTSTATUS
  14366. IoInitializeTimer(
  14367. IN PDEVICE_OBJECT DeviceObject,
  14368. IN PIO_TIMER_ROUTINE TimerRoutine,
  14369. IN PVOID Context
  14370. );
  14371. NTKERNELAPI
  14372. VOID
  14373. IoReuseIrp(
  14374. IN OUT PIRP Irp,
  14375. IN NTSTATUS Iostatus
  14376. );
  14377. // end_wdm
  14378. NTKERNELAPI
  14379. VOID
  14380. IoCancelFileOpen(
  14381. IN PDEVICE_OBJECT DeviceObject,
  14382. IN PFILE_OBJECT FileObject
  14383. );
  14384. //++
  14385. //
  14386. // BOOLEAN
  14387. // IoIsErrorUserInduced(
  14388. // IN NTSTATUS Status
  14389. // )
  14390. //
  14391. // Routine Description:
  14392. //
  14393. // This routine is invoked to determine if an error was as a
  14394. // result of user actions. Typically these error are related
  14395. // to removable media and will result in a pop-up.
  14396. //
  14397. // Arguments:
  14398. //
  14399. // Status - The status value to check.
  14400. //
  14401. // Return Value:
  14402. // The function value is TRUE if the user induced the error,
  14403. // otherwise FALSE is returned.
  14404. //
  14405. //--
  14406. #define IoIsErrorUserInduced( Status ) ((BOOLEAN) \
  14407. (((Status) == STATUS_DEVICE_NOT_READY) || \
  14408. ((Status) == STATUS_IO_TIMEOUT) || \
  14409. ((Status) == STATUS_MEDIA_WRITE_PROTECTED) || \
  14410. ((Status) == STATUS_NO_MEDIA_IN_DEVICE) || \
  14411. ((Status) == STATUS_VERIFY_REQUIRED) || \
  14412. ((Status) == STATUS_UNRECOGNIZED_MEDIA) || \
  14413. ((Status) == STATUS_WRONG_VOLUME)))
  14414. NTKERNELAPI
  14415. PIRP
  14416. IoMakeAssociatedIrp(
  14417. IN PIRP Irp,
  14418. IN CCHAR StackSize
  14419. );
  14420. // begin_wdm
  14421. //++
  14422. //
  14423. // VOID
  14424. // IoMarkIrpPending(
  14425. // IN OUT PIRP Irp
  14426. // )
  14427. //
  14428. // Routine Description:
  14429. //
  14430. // This routine marks the specified I/O Request Packet (IRP) to indicate
  14431. // that an initial status of STATUS_PENDING was returned to the caller.
  14432. // This is used so that I/O completion can determine whether or not to
  14433. // fully complete the I/O operation requested by the packet.
  14434. //
  14435. // Arguments:
  14436. //
  14437. // Irp - Pointer to the I/O Request Packet to be marked pending.
  14438. //
  14439. // Return Value:
  14440. //
  14441. // None.
  14442. //
  14443. //--
  14444. #define IoMarkIrpPending( Irp ) ( \
  14445. IoGetCurrentIrpStackLocation( (Irp) )->Control |= SL_PENDING_RETURNED )
  14446. DECLSPEC_DEPRECATED_DDK // Use IoGetDeviceProperty
  14447. NTKERNELAPI
  14448. NTSTATUS
  14449. IoQueryDeviceDescription(
  14450. IN PINTERFACE_TYPE BusType OPTIONAL,
  14451. IN PULONG BusNumber OPTIONAL,
  14452. IN PCONFIGURATION_TYPE ControllerType OPTIONAL,
  14453. IN PULONG ControllerNumber OPTIONAL,
  14454. IN PCONFIGURATION_TYPE PeripheralType OPTIONAL,
  14455. IN PULONG PeripheralNumber OPTIONAL,
  14456. IN PIO_QUERY_DEVICE_ROUTINE CalloutRoutine,
  14457. IN PVOID Context
  14458. );
  14459. NTKERNELAPI
  14460. VOID
  14461. IoRaiseHardError(
  14462. IN PIRP Irp,
  14463. IN PVPB Vpb OPTIONAL,
  14464. IN PDEVICE_OBJECT RealDeviceObject
  14465. );
  14466. NTKERNELAPI
  14467. BOOLEAN
  14468. IoRaiseInformationalHardError(
  14469. IN NTSTATUS ErrorStatus,
  14470. IN PUNICODE_STRING String OPTIONAL,
  14471. IN PKTHREAD Thread OPTIONAL
  14472. );
  14473. NTKERNELAPI
  14474. BOOLEAN
  14475. IoSetThreadHardErrorMode(
  14476. IN BOOLEAN EnableHardErrors
  14477. );
  14478. NTKERNELAPI
  14479. VOID
  14480. IoRegisterBootDriverReinitialization(
  14481. IN PDRIVER_OBJECT DriverObject,
  14482. IN PDRIVER_REINITIALIZE DriverReinitializationRoutine,
  14483. IN PVOID Context
  14484. );
  14485. NTKERNELAPI
  14486. VOID
  14487. IoRegisterDriverReinitialization(
  14488. IN PDRIVER_OBJECT DriverObject,
  14489. IN PDRIVER_REINITIALIZE DriverReinitializationRoutine,
  14490. IN PVOID Context
  14491. );
  14492. NTKERNELAPI
  14493. NTSTATUS
  14494. IoRegisterShutdownNotification(
  14495. IN PDEVICE_OBJECT DeviceObject
  14496. );
  14497. NTKERNELAPI
  14498. NTSTATUS
  14499. IoRegisterLastChanceShutdownNotification(
  14500. IN PDEVICE_OBJECT DeviceObject
  14501. );
  14502. // begin_wdm
  14503. NTKERNELAPI
  14504. VOID
  14505. IoReleaseCancelSpinLock(
  14506. IN KIRQL Irql
  14507. );
  14508. NTKERNELAPI
  14509. VOID
  14510. IoRemoveShareAccess(
  14511. IN PFILE_OBJECT FileObject,
  14512. IN OUT PSHARE_ACCESS ShareAccess
  14513. );
  14514. DECLSPEC_DEPRECATED_DDK // Use IoReportResourceForDetection
  14515. NTKERNELAPI
  14516. NTSTATUS
  14517. IoReportResourceUsage(
  14518. IN PUNICODE_STRING DriverClassName OPTIONAL,
  14519. IN PDRIVER_OBJECT DriverObject,
  14520. IN PCM_RESOURCE_LIST DriverList OPTIONAL,
  14521. IN ULONG DriverListSize OPTIONAL,
  14522. IN PDEVICE_OBJECT DeviceObject,
  14523. IN PCM_RESOURCE_LIST DeviceList OPTIONAL,
  14524. IN ULONG DeviceListSize OPTIONAL,
  14525. IN BOOLEAN OverrideConflict,
  14526. OUT PBOOLEAN ConflictDetected
  14527. );
  14528. // begin_wdm
  14529. //++
  14530. //
  14531. // VOID
  14532. // IoRequestDpc(
  14533. // IN PDEVICE_OBJECT DeviceObject,
  14534. // IN PIRP Irp,
  14535. // IN PVOID Context
  14536. // )
  14537. //
  14538. // Routine Description:
  14539. //
  14540. // This routine is invoked by the device driver's interrupt service routine
  14541. // to request that a DPC routine be queued for later execution at a lower
  14542. // IRQL.
  14543. //
  14544. // Arguments:
  14545. //
  14546. // DeviceObject - Device object for which the request is being processed.
  14547. //
  14548. // Irp - Pointer to the current I/O Request Packet (IRP) for the specified
  14549. // device.
  14550. //
  14551. // Context - Provides a general context parameter to be passed to the
  14552. // DPC routine.
  14553. //
  14554. // Return Value:
  14555. //
  14556. // None.
  14557. //
  14558. //--
  14559. #define IoRequestDpc( DeviceObject, Irp, Context ) ( \
  14560. KeInsertQueueDpc( &(DeviceObject)->Dpc, (Irp), (Context) ) )
  14561. //++
  14562. //
  14563. // PDRIVER_CANCEL
  14564. // IoSetCancelRoutine(
  14565. // IN PIRP Irp,
  14566. // IN PDRIVER_CANCEL CancelRoutine
  14567. // )
  14568. //
  14569. // Routine Description:
  14570. //
  14571. // This routine is invoked to set the address of a cancel routine which
  14572. // is to be invoked when an I/O packet has been canceled.
  14573. //
  14574. // Arguments:
  14575. //
  14576. // Irp - Pointer to the I/O Request Packet itself.
  14577. //
  14578. // CancelRoutine - Address of the cancel routine that is to be invoked
  14579. // if the IRP is cancelled.
  14580. //
  14581. // Return Value:
  14582. //
  14583. // Previous value of CancelRoutine field in the IRP.
  14584. //
  14585. //--
  14586. #define IoSetCancelRoutine( Irp, NewCancelRoutine ) ( \
  14587. (PDRIVER_CANCEL) InterlockedExchangePointer( (PVOID *) &(Irp)->CancelRoutine, (PVOID) (NewCancelRoutine) ) )
  14588. //++
  14589. //
  14590. // VOID
  14591. // IoSetCompletionRoutine(
  14592. // IN PIRP Irp,
  14593. // IN PIO_COMPLETION_ROUTINE CompletionRoutine,
  14594. // IN PVOID Context,
  14595. // IN BOOLEAN InvokeOnSuccess,
  14596. // IN BOOLEAN InvokeOnError,
  14597. // IN BOOLEAN InvokeOnCancel
  14598. // )
  14599. //
  14600. // Routine Description:
  14601. //
  14602. // This routine is invoked to set the address of a completion routine which
  14603. // is to be invoked when an I/O packet has been completed by a lower-level
  14604. // driver.
  14605. //
  14606. // Arguments:
  14607. //
  14608. // Irp - Pointer to the I/O Request Packet itself.
  14609. //
  14610. // CompletionRoutine - Address of the completion routine that is to be
  14611. // invoked once the next level driver completes the packet.
  14612. //
  14613. // Context - Specifies a context parameter to be passed to the completion
  14614. // routine.
  14615. //
  14616. // InvokeOnSuccess - Specifies that the completion routine is invoked when the
  14617. // operation is successfully completed.
  14618. //
  14619. // InvokeOnError - Specifies that the completion routine is invoked when the
  14620. // operation completes with an error status.
  14621. //
  14622. // InvokeOnCancel - Specifies that the completion routine is invoked when the
  14623. // operation is being canceled.
  14624. //
  14625. // Return Value:
  14626. //
  14627. // None.
  14628. //
  14629. //--
  14630. #define IoSetCompletionRoutine( Irp, Routine, CompletionContext, Success, Error, Cancel ) { \
  14631. PIO_STACK_LOCATION __irpSp; \
  14632. ASSERT( (Success) | (Error) | (Cancel) ? (Routine) != NULL : TRUE ); \
  14633. __irpSp = IoGetNextIrpStackLocation( (Irp) ); \
  14634. __irpSp->CompletionRoutine = (Routine); \
  14635. __irpSp->Context = (CompletionContext); \
  14636. __irpSp->Control = 0; \
  14637. if ((Success)) { __irpSp->Control = SL_INVOKE_ON_SUCCESS; } \
  14638. if ((Error)) { __irpSp->Control |= SL_INVOKE_ON_ERROR; } \
  14639. if ((Cancel)) { __irpSp->Control |= SL_INVOKE_ON_CANCEL; } }
  14640. NTSTATUS
  14641. IoSetCompletionRoutineEx(
  14642. IN PDEVICE_OBJECT DeviceObject,
  14643. IN PIRP Irp,
  14644. IN PIO_COMPLETION_ROUTINE CompletionRoutine,
  14645. IN PVOID Context,
  14646. IN BOOLEAN InvokeOnSuccess,
  14647. IN BOOLEAN InvokeOnError,
  14648. IN BOOLEAN InvokeOnCancel
  14649. );
  14650. NTKERNELAPI
  14651. VOID
  14652. IoSetHardErrorOrVerifyDevice(
  14653. IN PIRP Irp,
  14654. IN PDEVICE_OBJECT DeviceObject
  14655. );
  14656. //++
  14657. //
  14658. // VOID
  14659. // IoSetNextIrpStackLocation (
  14660. // IN OUT PIRP Irp
  14661. // )
  14662. //
  14663. // Routine Description:
  14664. //
  14665. // This routine is invoked to set the current IRP stack location to
  14666. // the next stack location, i.e. it "pushes" the stack.
  14667. //
  14668. // Arguments:
  14669. //
  14670. // Irp - Pointer to the I/O Request Packet (IRP).
  14671. //
  14672. // Return Value:
  14673. //
  14674. // None.
  14675. //
  14676. //--
  14677. #define IoSetNextIrpStackLocation( Irp ) { \
  14678. (Irp)->CurrentLocation--; \
  14679. (Irp)->Tail.Overlay.CurrentStackLocation--; }
  14680. //++
  14681. //
  14682. // VOID
  14683. // IoCopyCurrentIrpStackLocationToNext(
  14684. // IN PIRP Irp
  14685. // )
  14686. //
  14687. // Routine Description:
  14688. //
  14689. // This routine is invoked to copy the IRP stack arguments and file
  14690. // pointer from the current IrpStackLocation to the next
  14691. // in an I/O Request Packet (IRP).
  14692. //
  14693. // If the caller wants to call IoCallDriver with a completion routine
  14694. // but does not wish to change the arguments otherwise,
  14695. // the caller first calls IoCopyCurrentIrpStackLocationToNext,
  14696. // then IoSetCompletionRoutine, then IoCallDriver.
  14697. //
  14698. // Arguments:
  14699. //
  14700. // Irp - Pointer to the I/O Request Packet.
  14701. //
  14702. // Return Value:
  14703. //
  14704. // None.
  14705. //
  14706. //--
  14707. #define IoCopyCurrentIrpStackLocationToNext( Irp ) { \
  14708. PIO_STACK_LOCATION __irpSp; \
  14709. PIO_STACK_LOCATION __nextIrpSp; \
  14710. __irpSp = IoGetCurrentIrpStackLocation( (Irp) ); \
  14711. __nextIrpSp = IoGetNextIrpStackLocation( (Irp) ); \
  14712. RtlCopyMemory( __nextIrpSp, __irpSp, FIELD_OFFSET(IO_STACK_LOCATION, CompletionRoutine)); \
  14713. __nextIrpSp->Control = 0; }
  14714. //++
  14715. //
  14716. // VOID
  14717. // IoSkipCurrentIrpStackLocation (
  14718. // IN PIRP Irp
  14719. // )
  14720. //
  14721. // Routine Description:
  14722. //
  14723. // This routine is invoked to increment the current stack location of
  14724. // a given IRP.
  14725. //
  14726. // If the caller wishes to call the next driver in a stack, and does not
  14727. // wish to change the arguments, nor does he wish to set a completion
  14728. // routine, then the caller first calls IoSkipCurrentIrpStackLocation
  14729. // and the calls IoCallDriver.
  14730. //
  14731. // Arguments:
  14732. //
  14733. // Irp - Pointer to the I/O Request Packet.
  14734. //
  14735. // Return Value:
  14736. //
  14737. // None
  14738. //
  14739. //--
  14740. #define IoSkipCurrentIrpStackLocation( Irp ) { \
  14741. (Irp)->CurrentLocation++; \
  14742. (Irp)->Tail.Overlay.CurrentStackLocation++; }
  14743. NTKERNELAPI
  14744. VOID
  14745. IoSetShareAccess(
  14746. IN ACCESS_MASK DesiredAccess,
  14747. IN ULONG DesiredShareAccess,
  14748. IN OUT PFILE_OBJECT FileObject,
  14749. OUT PSHARE_ACCESS ShareAccess
  14750. );
  14751. typedef struct _IO_REMOVE_LOCK_TRACKING_BLOCK * PIO_REMOVE_LOCK_TRACKING_BLOCK;
  14752. typedef struct _IO_REMOVE_LOCK_COMMON_BLOCK {
  14753. BOOLEAN Removed;
  14754. BOOLEAN Reserved [3];
  14755. LONG IoCount;
  14756. KEVENT RemoveEvent;
  14757. } IO_REMOVE_LOCK_COMMON_BLOCK;
  14758. typedef struct _IO_REMOVE_LOCK_DBG_BLOCK {
  14759. LONG Signature;
  14760. LONG HighWatermark;
  14761. LONGLONG MaxLockedTicks;
  14762. LONG AllocateTag;
  14763. LIST_ENTRY LockList;
  14764. KSPIN_LOCK Spin;
  14765. LONG LowMemoryCount;
  14766. ULONG Reserved1[4];
  14767. PVOID Reserved2;
  14768. PIO_REMOVE_LOCK_TRACKING_BLOCK Blocks;
  14769. } IO_REMOVE_LOCK_DBG_BLOCK;
  14770. typedef struct _IO_REMOVE_LOCK {
  14771. IO_REMOVE_LOCK_COMMON_BLOCK Common;
  14772. #if DBG
  14773. IO_REMOVE_LOCK_DBG_BLOCK Dbg;
  14774. #endif
  14775. } IO_REMOVE_LOCK, *PIO_REMOVE_LOCK;
  14776. #define IoInitializeRemoveLock(Lock, Tag, Maxmin, HighWater) \
  14777. IoInitializeRemoveLockEx (Lock, Tag, Maxmin, HighWater, sizeof (IO_REMOVE_LOCK))
  14778. NTSYSAPI
  14779. VOID
  14780. NTAPI
  14781. IoInitializeRemoveLockEx(
  14782. IN PIO_REMOVE_LOCK Lock,
  14783. IN ULONG AllocateTag, // Used only on checked kernels
  14784. IN ULONG MaxLockedMinutes, // Used only on checked kernels
  14785. IN ULONG HighWatermark, // Used only on checked kernels
  14786. IN ULONG RemlockSize // are we checked or free
  14787. );
  14788. //
  14789. // Initialize a remove lock.
  14790. //
  14791. // Note: Allocation for remove locks needs to be within the device extension,
  14792. // so that the memory for this structure stays allocated until such time as the
  14793. // device object itself is deallocated.
  14794. //
  14795. #define IoAcquireRemoveLock(RemoveLock, Tag) \
  14796. IoAcquireRemoveLockEx(RemoveLock, Tag, __FILE__, __LINE__, sizeof (IO_REMOVE_LOCK))
  14797. NTSYSAPI
  14798. NTSTATUS
  14799. NTAPI
  14800. IoAcquireRemoveLockEx (
  14801. IN PIO_REMOVE_LOCK RemoveLock,
  14802. IN OPTIONAL PVOID Tag, // Optional
  14803. IN PCSTR File,
  14804. IN ULONG Line,
  14805. IN ULONG RemlockSize // are we checked or free
  14806. );
  14807. //
  14808. // Routine Description:
  14809. //
  14810. // This routine is called to acquire the remove lock for a device object.
  14811. // While the lock is held, the caller can assume that no pending pnp REMOVE
  14812. // requests will be completed.
  14813. //
  14814. // The lock should be acquired immediately upon entering a dispatch routine.
  14815. // It should also be acquired before creating any new reference to the
  14816. // device object if there's a chance of releasing the reference before the
  14817. // new one is done, in addition to references to the driver code itself,
  14818. // which is removed from memory when the last device object goes.
  14819. //
  14820. // Arguments:
  14821. //
  14822. // RemoveLock - A pointer to an initialized REMOVE_LOCK structure.
  14823. //
  14824. // Tag - Used for tracking lock allocation and release. The same tag
  14825. // specified when acquiring the lock must be used to release the lock.
  14826. // Tags are only checked in checked versions of the driver.
  14827. //
  14828. // File - set to __FILE__ as the location in the code where the lock was taken.
  14829. //
  14830. // Line - set to __LINE__.
  14831. //
  14832. // Return Value:
  14833. //
  14834. // Returns whether or not the remove lock was obtained.
  14835. // If successful the caller should continue with work calling
  14836. // IoReleaseRemoveLock when finished.
  14837. //
  14838. // If not successful the lock was not obtained. The caller should abort the
  14839. // work but not call IoReleaseRemoveLock.
  14840. //
  14841. #define IoReleaseRemoveLock(RemoveLock, Tag) \
  14842. IoReleaseRemoveLockEx(RemoveLock, Tag, sizeof (IO_REMOVE_LOCK))
  14843. NTSYSAPI
  14844. VOID
  14845. NTAPI
  14846. IoReleaseRemoveLockEx(
  14847. IN PIO_REMOVE_LOCK RemoveLock,
  14848. IN PVOID Tag, // Optional
  14849. IN ULONG RemlockSize // are we checked or free
  14850. );
  14851. //
  14852. //
  14853. // Routine Description:
  14854. //
  14855. // This routine is called to release the remove lock on the device object. It
  14856. // must be called when finished using a previously locked reference to the
  14857. // device object. If an Tag was specified when acquiring the lock then the
  14858. // same Tag must be specified when releasing the lock.
  14859. //
  14860. // When the lock count reduces to zero, this routine will signal the waiting
  14861. // event to release the waiting thread deleting the device object protected
  14862. // by this lock.
  14863. //
  14864. // Arguments:
  14865. //
  14866. // DeviceObject - the device object to lock
  14867. //
  14868. // Tag - The TAG (if any) specified when acquiring the lock. This is used
  14869. // for lock tracking purposes
  14870. //
  14871. // Return Value:
  14872. //
  14873. // none
  14874. //
  14875. #define IoReleaseRemoveLockAndWait(RemoveLock, Tag) \
  14876. IoReleaseRemoveLockAndWaitEx(RemoveLock, Tag, sizeof (IO_REMOVE_LOCK))
  14877. NTSYSAPI
  14878. VOID
  14879. NTAPI
  14880. IoReleaseRemoveLockAndWaitEx(
  14881. IN PIO_REMOVE_LOCK RemoveLock,
  14882. IN PVOID Tag,
  14883. IN ULONG RemlockSize // are we checked or free
  14884. );
  14885. //
  14886. //
  14887. // Routine Description:
  14888. //
  14889. // This routine is called when the client would like to delete the
  14890. // remove-locked resource. This routine will block until all the remove
  14891. // locks have released.
  14892. //
  14893. // This routine MUST be called after acquiring the lock.
  14894. //
  14895. // Arguments:
  14896. //
  14897. // RemoveLock
  14898. //
  14899. // Return Value:
  14900. //
  14901. // none
  14902. //
  14903. //++
  14904. //
  14905. // USHORT
  14906. // IoSizeOfIrp(
  14907. // IN CCHAR StackSize
  14908. // )
  14909. //
  14910. // Routine Description:
  14911. //
  14912. // Determines the size of an IRP given the number of stack locations
  14913. // the IRP will have.
  14914. //
  14915. // Arguments:
  14916. //
  14917. // StackSize - Number of stack locations for the IRP.
  14918. //
  14919. // Return Value:
  14920. //
  14921. // Size in bytes of the IRP.
  14922. //
  14923. //--
  14924. #define IoSizeOfIrp( StackSize ) \
  14925. ((USHORT) (sizeof( IRP ) + ((StackSize) * (sizeof( IO_STACK_LOCATION )))))
  14926. // end_ntifs
  14927. NTKERNELAPI
  14928. VOID
  14929. IoStartNextPacket(
  14930. IN PDEVICE_OBJECT DeviceObject,
  14931. IN BOOLEAN Cancelable
  14932. );
  14933. NTKERNELAPI
  14934. VOID
  14935. IoStartNextPacketByKey(
  14936. IN PDEVICE_OBJECT DeviceObject,
  14937. IN BOOLEAN Cancelable,
  14938. IN ULONG Key
  14939. );
  14940. NTKERNELAPI
  14941. VOID
  14942. IoStartPacket(
  14943. IN PDEVICE_OBJECT DeviceObject,
  14944. IN PIRP Irp,
  14945. IN PULONG Key OPTIONAL,
  14946. IN PDRIVER_CANCEL CancelFunction OPTIONAL
  14947. );
  14948. VOID
  14949. IoSetStartIoAttributes(
  14950. IN PDEVICE_OBJECT DeviceObject,
  14951. IN BOOLEAN DeferredStartIo,
  14952. IN BOOLEAN NonCancelable
  14953. );
  14954. // begin_ntifs
  14955. NTKERNELAPI
  14956. VOID
  14957. IoStartTimer(
  14958. IN PDEVICE_OBJECT DeviceObject
  14959. );
  14960. NTKERNELAPI
  14961. VOID
  14962. IoStopTimer(
  14963. IN PDEVICE_OBJECT DeviceObject
  14964. );
  14965. NTKERNELAPI
  14966. VOID
  14967. IoUnregisterShutdownNotification(
  14968. IN PDEVICE_OBJECT DeviceObject
  14969. );
  14970. // end_wdm
  14971. NTKERNELAPI
  14972. VOID
  14973. IoUpdateShareAccess(
  14974. IN PFILE_OBJECT FileObject,
  14975. IN OUT PSHARE_ACCESS ShareAccess
  14976. );
  14977. NTKERNELAPI
  14978. VOID
  14979. IoWriteErrorLogEntry(
  14980. IN PVOID ElEntry
  14981. );
  14982. typedef struct _IO_WORKITEM *PIO_WORKITEM;
  14983. typedef
  14984. VOID
  14985. (*PIO_WORKITEM_ROUTINE) (
  14986. IN PDEVICE_OBJECT DeviceObject,
  14987. IN PVOID Context
  14988. );
  14989. PIO_WORKITEM
  14990. IoAllocateWorkItem(
  14991. PDEVICE_OBJECT DeviceObject
  14992. );
  14993. VOID
  14994. IoFreeWorkItem(
  14995. PIO_WORKITEM IoWorkItem
  14996. );
  14997. VOID
  14998. IoQueueWorkItem(
  14999. IN PIO_WORKITEM IoWorkItem,
  15000. IN PIO_WORKITEM_ROUTINE WorkerRoutine,
  15001. IN WORK_QUEUE_TYPE QueueType,
  15002. IN PVOID Context
  15003. );
  15004. NTKERNELAPI
  15005. NTSTATUS
  15006. IoWMIRegistrationControl(
  15007. IN PDEVICE_OBJECT DeviceObject,
  15008. IN ULONG Action
  15009. );
  15010. //
  15011. // Action code for IoWMIRegistrationControl api
  15012. //
  15013. #define WMIREG_ACTION_REGISTER 1
  15014. #define WMIREG_ACTION_DEREGISTER 2
  15015. #define WMIREG_ACTION_REREGISTER 3
  15016. #define WMIREG_ACTION_UPDATE_GUIDS 4
  15017. #define WMIREG_ACTION_BLOCK_IRPS 5
  15018. //
  15019. // Code passed in IRP_MN_REGINFO WMI irp
  15020. //
  15021. #define WMIREGISTER 0
  15022. #define WMIUPDATE 1
  15023. NTKERNELAPI
  15024. NTSTATUS
  15025. IoWMIAllocateInstanceIds(
  15026. IN GUID *Guid,
  15027. IN ULONG InstanceCount,
  15028. OUT ULONG *FirstInstanceId
  15029. );
  15030. NTKERNELAPI
  15031. NTSTATUS
  15032. IoWMISuggestInstanceName(
  15033. IN PDEVICE_OBJECT PhysicalDeviceObject OPTIONAL,
  15034. IN PUNICODE_STRING SymbolicLinkName OPTIONAL,
  15035. IN BOOLEAN CombineNames,
  15036. OUT PUNICODE_STRING SuggestedInstanceName
  15037. );
  15038. NTKERNELAPI
  15039. NTSTATUS
  15040. IoWMIWriteEvent(
  15041. IN PVOID WnodeEventItem
  15042. );
  15043. #if defined(_WIN64)
  15044. NTKERNELAPI
  15045. ULONG IoWMIDeviceObjectToProviderId(
  15046. PDEVICE_OBJECT DeviceObject
  15047. );
  15048. #else
  15049. #define IoWMIDeviceObjectToProviderId(DeviceObject) ((ULONG)(DeviceObject))
  15050. #endif
  15051. NTKERNELAPI
  15052. NTSTATUS IoWMIOpenBlock(
  15053. IN GUID *DataBlockGuid,
  15054. IN ULONG DesiredAccess,
  15055. OUT PVOID *DataBlockObject
  15056. );
  15057. NTKERNELAPI
  15058. NTSTATUS IoWMIQueryAllData(
  15059. IN PVOID DataBlockObject,
  15060. IN OUT ULONG *InOutBufferSize,
  15061. OUT /* non paged */ PVOID OutBuffer
  15062. );
  15063. NTKERNELAPI
  15064. NTSTATUS
  15065. IoWMIQueryAllDataMultiple(
  15066. IN PVOID *DataBlockObjectList,
  15067. IN ULONG ObjectCount,
  15068. IN OUT ULONG *InOutBufferSize,
  15069. OUT /* non paged */ PVOID OutBuffer
  15070. );
  15071. NTKERNELAPI
  15072. NTSTATUS
  15073. IoWMIQuerySingleInstance(
  15074. IN PVOID DataBlockObject,
  15075. IN PUNICODE_STRING InstanceName,
  15076. IN OUT ULONG *InOutBufferSize,
  15077. OUT /* non paged */ PVOID OutBuffer
  15078. );
  15079. NTKERNELAPI
  15080. NTSTATUS
  15081. IoWMIQuerySingleInstanceMultiple(
  15082. IN PVOID *DataBlockObjectList,
  15083. IN PUNICODE_STRING InstanceNames,
  15084. IN ULONG ObjectCount,
  15085. IN OUT ULONG *InOutBufferSize,
  15086. OUT /* non paged */ PVOID OutBuffer
  15087. );
  15088. NTKERNELAPI
  15089. NTSTATUS
  15090. IoWMISetSingleInstance(
  15091. IN PVOID DataBlockObject,
  15092. IN PUNICODE_STRING InstanceName,
  15093. IN ULONG Version,
  15094. IN ULONG ValueBufferSize,
  15095. IN PVOID ValueBuffer
  15096. );
  15097. NTKERNELAPI
  15098. NTSTATUS
  15099. IoWMISetSingleItem(
  15100. IN PVOID DataBlockObject,
  15101. IN PUNICODE_STRING InstanceName,
  15102. IN ULONG DataItemId,
  15103. IN ULONG Version,
  15104. IN ULONG ValueBufferSize,
  15105. IN PVOID ValueBuffer
  15106. );
  15107. NTKERNELAPI
  15108. NTSTATUS
  15109. IoWMIExecuteMethod(
  15110. IN PVOID DataBlockObject,
  15111. IN PUNICODE_STRING InstanceName,
  15112. IN ULONG MethodId,
  15113. IN ULONG InBufferSize,
  15114. IN OUT PULONG OutBufferSize,
  15115. IN OUT PUCHAR InOutBuffer
  15116. );
  15117. typedef VOID (*WMI_NOTIFICATION_CALLBACK)(
  15118. PVOID Wnode,
  15119. PVOID Context
  15120. );
  15121. NTKERNELAPI
  15122. NTSTATUS
  15123. IoWMISetNotificationCallback(
  15124. IN PVOID Object,
  15125. IN WMI_NOTIFICATION_CALLBACK Callback,
  15126. IN PVOID Context
  15127. );
  15128. NTKERNELAPI
  15129. NTSTATUS
  15130. IoWMIHandleToInstanceName(
  15131. IN PVOID DataBlockObject,
  15132. IN HANDLE FileHandle,
  15133. OUT PUNICODE_STRING InstanceName
  15134. );
  15135. NTKERNELAPI
  15136. NTSTATUS
  15137. IoWMIDeviceObjectToInstanceName(
  15138. IN PVOID DataBlockObject,
  15139. IN PDEVICE_OBJECT DeviceObject,
  15140. OUT PUNICODE_STRING InstanceName
  15141. );
  15142. #if defined(_WIN64)
  15143. BOOLEAN
  15144. IoIs32bitProcess(
  15145. IN PIRP Irp
  15146. );
  15147. #endif
  15148. NTKERNELAPI
  15149. VOID
  15150. FASTCALL
  15151. HalExamineMBR(
  15152. IN PDEVICE_OBJECT DeviceObject,
  15153. IN ULONG SectorSize,
  15154. IN ULONG MBRTypeIdentifier,
  15155. OUT PVOID *Buffer
  15156. );
  15157. DECLSPEC_DEPRECATED_DDK // Use IoReadPartitionTableEx
  15158. NTKERNELAPI
  15159. NTSTATUS
  15160. FASTCALL
  15161. IoReadPartitionTable(
  15162. IN PDEVICE_OBJECT DeviceObject,
  15163. IN ULONG SectorSize,
  15164. IN BOOLEAN ReturnRecognizedPartitions,
  15165. OUT struct _DRIVE_LAYOUT_INFORMATION **PartitionBuffer
  15166. );
  15167. DECLSPEC_DEPRECATED_DDK // Use IoSetPartitionInformationEx
  15168. NTKERNELAPI
  15169. NTSTATUS
  15170. FASTCALL
  15171. IoSetPartitionInformation(
  15172. IN PDEVICE_OBJECT DeviceObject,
  15173. IN ULONG SectorSize,
  15174. IN ULONG PartitionNumber,
  15175. IN ULONG PartitionType
  15176. );
  15177. // begin_ntosp
  15178. DECLSPEC_DEPRECATED_DDK // Use IoWritePartitionTableEx
  15179. NTKERNELAPI
  15180. NTSTATUS
  15181. FASTCALL
  15182. IoWritePartitionTable(
  15183. IN PDEVICE_OBJECT DeviceObject,
  15184. IN ULONG SectorSize,
  15185. IN ULONG SectorsPerTrack,
  15186. IN ULONG NumberOfHeads,
  15187. IN struct _DRIVE_LAYOUT_INFORMATION *PartitionBuffer
  15188. );
  15189. NTKERNELAPI
  15190. NTSTATUS
  15191. IoCreateDisk(
  15192. IN PDEVICE_OBJECT DeviceObject,
  15193. IN struct _CREATE_DISK* Disk
  15194. );
  15195. NTKERNELAPI
  15196. NTSTATUS
  15197. IoReadPartitionTableEx(
  15198. IN PDEVICE_OBJECT DeviceObject,
  15199. IN struct _DRIVE_LAYOUT_INFORMATION_EX** DriveLayout
  15200. );
  15201. NTKERNELAPI
  15202. NTSTATUS
  15203. IoWritePartitionTableEx(
  15204. IN PDEVICE_OBJECT DeviceObject,
  15205. IN struct _DRIVE_LAYOUT_INFORMATION_EX* DriveLayout
  15206. );
  15207. NTKERNELAPI
  15208. NTSTATUS
  15209. IoSetPartitionInformationEx(
  15210. IN PDEVICE_OBJECT DeviceObject,
  15211. IN ULONG PartitionNumber,
  15212. IN struct _SET_PARTITION_INFORMATION_EX* PartitionInfo
  15213. );
  15214. NTKERNELAPI
  15215. NTSTATUS
  15216. IoUpdateDiskGeometry(
  15217. IN PDEVICE_OBJECT DeviceObject,
  15218. IN struct _DISK_GEOMETRY_EX* OldDiskGeometry,
  15219. IN struct _DISK_GEOMETRY_EX* NewDiskGeometry
  15220. );
  15221. NTKERNELAPI
  15222. NTSTATUS
  15223. IoVerifyPartitionTable(
  15224. IN PDEVICE_OBJECT DeviceObject,
  15225. IN BOOLEAN FixErrors
  15226. );
  15227. typedef struct _DISK_SIGNATURE {
  15228. ULONG PartitionStyle;
  15229. union {
  15230. struct {
  15231. ULONG Signature;
  15232. ULONG CheckSum;
  15233. } Mbr;
  15234. struct {
  15235. GUID DiskId;
  15236. } Gpt;
  15237. };
  15238. } DISK_SIGNATURE, *PDISK_SIGNATURE;
  15239. NTKERNELAPI
  15240. NTSTATUS
  15241. IoReadDiskSignature(
  15242. IN PDEVICE_OBJECT DeviceObject,
  15243. IN ULONG BytesPerSector,
  15244. OUT PDISK_SIGNATURE Signature
  15245. );
  15246. // end_ntosp
  15247. NTSTATUS
  15248. IoVolumeDeviceToDosName(
  15249. IN PVOID VolumeDeviceObject,
  15250. OUT PUNICODE_STRING DosName
  15251. );
  15252. NTSTATUS
  15253. IoSetSystemPartition(
  15254. PUNICODE_STRING VolumeNameString
  15255. );
  15256. // begin_wdm
  15257. VOID
  15258. IoFreeErrorLogEntry(
  15259. PVOID ElEntry
  15260. );
  15261. // Cancel SAFE API set start
  15262. //
  15263. // The following APIs are to help ease the pain of writing queue packages that
  15264. // handle the cancellation race well. The idea of this set of APIs is to not
  15265. // force a single queue data structure but allow the cancel logic to be hidden
  15266. // from the drivers. A driver implements a queue and as part of its header
  15267. // includes the IO_CSQ structure. In its initialization routine it calls
  15268. // IoInitializeCsq. Then in the dispatch routine when the driver wants to
  15269. // insert an IRP into the queue it calls IoCsqInsertIrp. When the driver wants
  15270. // to remove something from the queue it calls IoCsqRemoveIrp. Note that Insert
  15271. // can fail if the IRP was cancelled in the meantime. Remove can also fail if
  15272. // the IRP was already cancelled.
  15273. //
  15274. // There are typically two modes where drivers queue IRPs. These two modes are
  15275. // covered by the cancel safe queue API set.
  15276. //
  15277. // Mode 1:
  15278. // One is where the driver queues the IRP and at some later
  15279. // point in time dequeues an IRP and issues the IO request.
  15280. // For this mode the driver should use IoCsqInsertIrp and IoCsqRemoveNextIrp.
  15281. // The driver in this case is expected to pass NULL to the irp context
  15282. // parameter in IoInsertIrp.
  15283. //
  15284. // Mode 2:
  15285. // In this the driver queues theIRP, issues the IO request (like issuing a DMA
  15286. // request or writing to a register) and when the IO request completes (either
  15287. // using a DPC or timer) the driver dequeues the IRP and completes it. For this
  15288. // mode the driver should use IoCsqInsertIrp and IoCsqRemoveIrp. In this case
  15289. // the driver should allocate an IRP context and pass it in to IoCsqInsertIrp.
  15290. // The cancel API code creates an association between the IRP and the context
  15291. // and thus ensures that when the time comes to remove the IRP it can ascertain
  15292. // correctly.
  15293. //
  15294. // Note that the cancel API set assumes that the field DriverContext[3] is
  15295. // always available for use and that the driver does not use it.
  15296. //
  15297. //
  15298. // Bookkeeping structure. This should be opaque to drivers.
  15299. // Drivers typically include this as part of their queue headers.
  15300. // Given a CSQ pointer the driver should be able to get its
  15301. // queue header using CONTAINING_RECORD macro
  15302. //
  15303. typedef struct _IO_CSQ IO_CSQ, *PIO_CSQ;
  15304. #define IO_TYPE_CSQ_IRP_CONTEXT 1
  15305. #define IO_TYPE_CSQ 2
  15306. //
  15307. // IRP context structure. This structure is necessary if the driver is using
  15308. // the second mode.
  15309. //
  15310. typedef struct _IO_CSQ_IRP_CONTEXT {
  15311. ULONG Type;
  15312. PIRP Irp;
  15313. PIO_CSQ Csq;
  15314. } IO_CSQ_IRP_CONTEXT, *PIO_CSQ_IRP_CONTEXT;
  15315. //
  15316. // Routines that insert/remove IRP
  15317. //
  15318. typedef VOID
  15319. (*PIO_CSQ_INSERT_IRP)(
  15320. IN struct _IO_CSQ *Csq,
  15321. IN PIRP Irp
  15322. );
  15323. typedef VOID
  15324. (*PIO_CSQ_REMOVE_IRP)(
  15325. IN PIO_CSQ Csq,
  15326. IN PIRP Irp
  15327. );
  15328. //
  15329. // Retrieves next entry after Irp from the queue.
  15330. // Returns NULL if there are no entries in the queue.
  15331. // If Irp is NUL, returns the entry in the head of the queue.
  15332. // This routine does not remove the IRP from the queue.
  15333. //
  15334. typedef PIRP
  15335. (*PIO_CSQ_PEEK_NEXT_IRP)(
  15336. IN PIO_CSQ Csq,
  15337. IN PIRP Irp,
  15338. IN PVOID PeekContext
  15339. );
  15340. //
  15341. // Lock routine that protects the cancel safe queue.
  15342. //
  15343. typedef VOID
  15344. (*PIO_CSQ_ACQUIRE_LOCK)(
  15345. IN PIO_CSQ Csq,
  15346. OUT PKIRQL Irql
  15347. );
  15348. typedef VOID
  15349. (*PIO_CSQ_RELEASE_LOCK)(
  15350. IN PIO_CSQ Csq,
  15351. IN KIRQL Irql
  15352. );
  15353. //
  15354. // Completes the IRP with STATUS_CANCELLED. IRP is guaranteed to be valid
  15355. // In most cases this routine just calls IoCompleteRequest(Irp, STATUS_CANCELLED);
  15356. //
  15357. typedef VOID
  15358. (*PIO_CSQ_COMPLETE_CANCELED_IRP)(
  15359. IN PIO_CSQ Csq,
  15360. IN PIRP Irp
  15361. );
  15362. //
  15363. // Bookkeeping structure. This should be opaque to drivers.
  15364. // Drivers typically include this as part of their queue headers.
  15365. // Given a CSQ pointer the driver should be able to get its
  15366. // queue header using CONTAINING_RECORD macro
  15367. //
  15368. typedef struct _IO_CSQ {
  15369. ULONG Type;
  15370. PIO_CSQ_INSERT_IRP CsqInsertIrp;
  15371. PIO_CSQ_REMOVE_IRP CsqRemoveIrp;
  15372. PIO_CSQ_PEEK_NEXT_IRP CsqPeekNextIrp;
  15373. PIO_CSQ_ACQUIRE_LOCK CsqAcquireLock;
  15374. PIO_CSQ_RELEASE_LOCK CsqReleaseLock;
  15375. PIO_CSQ_COMPLETE_CANCELED_IRP CsqCompleteCanceledIrp;
  15376. PVOID ReservePointer; // Future expansion
  15377. } IO_CSQ, *PIO_CSQ;
  15378. //
  15379. // Initializes the cancel queue structure.
  15380. //
  15381. NTSTATUS
  15382. IoCsqInitialize(
  15383. IN PIO_CSQ Csq,
  15384. IN PIO_CSQ_INSERT_IRP CsqInsertIrp,
  15385. IN PIO_CSQ_REMOVE_IRP CsqRemoveIrp,
  15386. IN PIO_CSQ_PEEK_NEXT_IRP CsqPeekNextIrp,
  15387. IN PIO_CSQ_ACQUIRE_LOCK CsqAcquireLock,
  15388. IN PIO_CSQ_RELEASE_LOCK CsqReleaseLock,
  15389. IN PIO_CSQ_COMPLETE_CANCELED_IRP CsqCompleteCanceledIrp
  15390. );
  15391. //
  15392. // The caller calls this routine to insert the IRP and return STATUS_PENDING.
  15393. //
  15394. VOID
  15395. IoCsqInsertIrp(
  15396. IN PIO_CSQ Csq,
  15397. IN PIRP Irp,
  15398. IN PIO_CSQ_IRP_CONTEXT Context
  15399. );
  15400. //
  15401. // Returns an IRP if one can be found. NULL otherwise.
  15402. //
  15403. PIRP
  15404. IoCsqRemoveNextIrp(
  15405. IN PIO_CSQ Csq,
  15406. IN PVOID PeekContext
  15407. );
  15408. //
  15409. // This routine is called from timeout or DPCs.
  15410. // The context is presumably part of the DPC or timer context.
  15411. // If succesfull returns the IRP associated with context.
  15412. //
  15413. PIRP
  15414. IoCsqRemoveIrp(
  15415. IN PIO_CSQ Csq,
  15416. IN PIO_CSQ_IRP_CONTEXT Context
  15417. );
  15418. // Cancel SAFE API set end
  15419. NTSTATUS
  15420. IoValidateDeviceIoControlAccess(
  15421. IN PIRP Irp,
  15422. IN ULONG RequiredAccess
  15423. );
  15424. #ifdef RUN_WPP
  15425. #include <evntrace.h>
  15426. #include <stdarg.h>
  15427. #endif // #ifdef RUN_WPP
  15428. #ifdef RUN_WPP
  15429. NTKERNELAPI
  15430. NTSTATUS
  15431. WmiTraceMessage(
  15432. IN TRACEHANDLE LoggerHandle,
  15433. IN ULONG MessageFlags,
  15434. IN LPGUID MessageGuid,
  15435. IN USHORT MessageNumber,
  15436. IN ...
  15437. );
  15438. NTKERNELAPI
  15439. NTSTATUS
  15440. WmiTraceMessageVa(
  15441. IN TRACEHANDLE LoggerHandle,
  15442. IN ULONG MessageFlags,
  15443. IN LPGUID MessageGuid,
  15444. IN USHORT MessageNumber,
  15445. IN va_list MessageArgList
  15446. );
  15447. #endif // #ifdef RUN_WPP
  15448. #ifndef TRACE_INFORMATION_CLASS_DEFINE
  15449. typedef enum _TRACE_INFORMATION_CLASS {
  15450. TraceIdClass,
  15451. TraceHandleClass,
  15452. TraceEnableFlagsClass,
  15453. TraceEnableLevelClass,
  15454. GlobalLoggerHandleClass,
  15455. EventLoggerHandleClass,
  15456. AllLoggerHandlesClass,
  15457. TraceHandleByNameClass
  15458. } TRACE_INFORMATION_CLASS;
  15459. NTKERNELAPI
  15460. NTSTATUS
  15461. WmiQueryTraceInformation(
  15462. IN TRACE_INFORMATION_CLASS TraceInformationClass,
  15463. OUT PVOID TraceInformation,
  15464. IN ULONG TraceInformationLength,
  15465. OUT PULONG RequiredLength OPTIONAL,
  15466. IN PVOID Buffer OPTIONAL
  15467. );
  15468. #define TRACE_INFORMATION_CLASS_DEFINE
  15469. #endif // TRACE_INFOPRMATION_CLASS_DEFINE
  15470. //
  15471. // Define PnP Device Property for IoGetDeviceProperty
  15472. //
  15473. typedef enum {
  15474. DevicePropertyDeviceDescription,
  15475. DevicePropertyHardwareID,
  15476. DevicePropertyCompatibleIDs,
  15477. DevicePropertyBootConfiguration,
  15478. DevicePropertyBootConfigurationTranslated,
  15479. DevicePropertyClassName,
  15480. DevicePropertyClassGuid,
  15481. DevicePropertyDriverKeyName,
  15482. DevicePropertyManufacturer,
  15483. DevicePropertyFriendlyName,
  15484. DevicePropertyLocationInformation,
  15485. DevicePropertyPhysicalDeviceObjectName,
  15486. DevicePropertyBusTypeGuid,
  15487. DevicePropertyLegacyBusType,
  15488. DevicePropertyBusNumber,
  15489. DevicePropertyEnumeratorName,
  15490. DevicePropertyAddress,
  15491. DevicePropertyUINumber,
  15492. DevicePropertyInstallState,
  15493. DevicePropertyRemovalPolicy
  15494. } DEVICE_REGISTRY_PROPERTY;
  15495. typedef BOOLEAN (*PTRANSLATE_BUS_ADDRESS)(
  15496. IN PVOID Context,
  15497. IN PHYSICAL_ADDRESS BusAddress,
  15498. IN ULONG Length,
  15499. IN OUT PULONG AddressSpace,
  15500. OUT PPHYSICAL_ADDRESS TranslatedAddress
  15501. );
  15502. typedef struct _DMA_ADAPTER *(*PGET_DMA_ADAPTER)(
  15503. IN PVOID Context,
  15504. IN struct _DEVICE_DESCRIPTION *DeviceDescriptor,
  15505. OUT PULONG NumberOfMapRegisters
  15506. );
  15507. typedef ULONG (*PGET_SET_DEVICE_DATA)(
  15508. IN PVOID Context,
  15509. IN ULONG DataType,
  15510. IN PVOID Buffer,
  15511. IN ULONG Offset,
  15512. IN ULONG Length
  15513. );
  15514. typedef enum _DEVICE_INSTALL_STATE {
  15515. InstallStateInstalled,
  15516. InstallStateNeedsReinstall,
  15517. InstallStateFailedInstall,
  15518. InstallStateFinishInstall
  15519. } DEVICE_INSTALL_STATE, *PDEVICE_INSTALL_STATE;
  15520. //
  15521. // Define structure returned in response to IRP_MN_QUERY_BUS_INFORMATION by a
  15522. // PDO indicating the type of bus the device exists on.
  15523. //
  15524. typedef struct _PNP_BUS_INFORMATION {
  15525. GUID BusTypeGuid;
  15526. INTERFACE_TYPE LegacyBusType;
  15527. ULONG BusNumber;
  15528. } PNP_BUS_INFORMATION, *PPNP_BUS_INFORMATION;
  15529. //
  15530. // Define structure returned in response to IRP_MN_QUERY_LEGACY_BUS_INFORMATION
  15531. // by an FDO indicating the type of bus it is. This is normally the same bus
  15532. // type as the device's children (i.e., as retrieved from the child PDO's via
  15533. // IRP_MN_QUERY_BUS_INFORMATION) except for cases like CardBus, which can
  15534. // support both 16-bit (PCMCIABus) and 32-bit (PCIBus) cards.
  15535. //
  15536. typedef struct _LEGACY_BUS_INFORMATION {
  15537. GUID BusTypeGuid;
  15538. INTERFACE_TYPE LegacyBusType;
  15539. ULONG BusNumber;
  15540. } LEGACY_BUS_INFORMATION, *PLEGACY_BUS_INFORMATION;
  15541. //
  15542. // Defines for IoGetDeviceProperty(DevicePropertyRemovalPolicy).
  15543. //
  15544. typedef enum _DEVICE_REMOVAL_POLICY {
  15545. RemovalPolicyExpectNoRemoval = 1,
  15546. RemovalPolicyExpectOrderlyRemoval = 2,
  15547. RemovalPolicyExpectSurpriseRemoval = 3
  15548. } DEVICE_REMOVAL_POLICY, *PDEVICE_REMOVAL_POLICY;
  15549. typedef struct _BUS_INTERFACE_STANDARD {
  15550. //
  15551. // generic interface header
  15552. //
  15553. USHORT Size;
  15554. USHORT Version;
  15555. PVOID Context;
  15556. PINTERFACE_REFERENCE InterfaceReference;
  15557. PINTERFACE_DEREFERENCE InterfaceDereference;
  15558. //
  15559. // standard bus interfaces
  15560. //
  15561. PTRANSLATE_BUS_ADDRESS TranslateBusAddress;
  15562. PGET_DMA_ADAPTER GetDmaAdapter;
  15563. PGET_SET_DEVICE_DATA SetBusData;
  15564. PGET_SET_DEVICE_DATA GetBusData;
  15565. } BUS_INTERFACE_STANDARD, *PBUS_INTERFACE_STANDARD;
  15566. //
  15567. // The following definitions are used in ACPI QueryInterface
  15568. //
  15569. typedef BOOLEAN (* PGPE_SERVICE_ROUTINE) (
  15570. PVOID,
  15571. PVOID);
  15572. typedef NTSTATUS (* PGPE_CONNECT_VECTOR) (
  15573. PDEVICE_OBJECT,
  15574. ULONG,
  15575. KINTERRUPT_MODE,
  15576. BOOLEAN,
  15577. PGPE_SERVICE_ROUTINE,
  15578. PVOID,
  15579. PVOID);
  15580. typedef NTSTATUS (* PGPE_DISCONNECT_VECTOR) (
  15581. PVOID);
  15582. typedef NTSTATUS (* PGPE_ENABLE_EVENT) (
  15583. PDEVICE_OBJECT,
  15584. PVOID);
  15585. typedef NTSTATUS (* PGPE_DISABLE_EVENT) (
  15586. PDEVICE_OBJECT,
  15587. PVOID);
  15588. typedef NTSTATUS (* PGPE_CLEAR_STATUS) (
  15589. PDEVICE_OBJECT,
  15590. PVOID);
  15591. typedef VOID (* PDEVICE_NOTIFY_CALLBACK) (
  15592. PVOID,
  15593. ULONG);
  15594. typedef NTSTATUS (* PREGISTER_FOR_DEVICE_NOTIFICATIONS) (
  15595. PDEVICE_OBJECT,
  15596. PDEVICE_NOTIFY_CALLBACK,
  15597. PVOID);
  15598. typedef void (* PUNREGISTER_FOR_DEVICE_NOTIFICATIONS) (
  15599. PDEVICE_OBJECT,
  15600. PDEVICE_NOTIFY_CALLBACK);
  15601. typedef struct _ACPI_INTERFACE_STANDARD {
  15602. //
  15603. // Generic interface header
  15604. //
  15605. USHORT Size;
  15606. USHORT Version;
  15607. PVOID Context;
  15608. PINTERFACE_REFERENCE InterfaceReference;
  15609. PINTERFACE_DEREFERENCE InterfaceDereference;
  15610. //
  15611. // ACPI interfaces
  15612. //
  15613. PGPE_CONNECT_VECTOR GpeConnectVector;
  15614. PGPE_DISCONNECT_VECTOR GpeDisconnectVector;
  15615. PGPE_ENABLE_EVENT GpeEnableEvent;
  15616. PGPE_DISABLE_EVENT GpeDisableEvent;
  15617. PGPE_CLEAR_STATUS GpeClearStatus;
  15618. PREGISTER_FOR_DEVICE_NOTIFICATIONS RegisterForDeviceNotifications;
  15619. PUNREGISTER_FOR_DEVICE_NOTIFICATIONS UnregisterForDeviceNotifications;
  15620. } ACPI_INTERFACE_STANDARD, *PACPI_INTERFACE_STANDARD;
  15621. NTKERNELAPI
  15622. NTSTATUS
  15623. IoReportDetectedDevice(
  15624. IN PDRIVER_OBJECT DriverObject,
  15625. IN INTERFACE_TYPE LegacyBusType,
  15626. IN ULONG BusNumber,
  15627. IN ULONG SlotNumber,
  15628. IN PCM_RESOURCE_LIST ResourceList,
  15629. IN PIO_RESOURCE_REQUIREMENTS_LIST ResourceRequirements OPTIONAL,
  15630. IN BOOLEAN ResourceAssigned,
  15631. IN OUT PDEVICE_OBJECT *DeviceObject
  15632. );
  15633. // begin_wdm
  15634. NTKERNELAPI
  15635. VOID
  15636. IoInvalidateDeviceRelations(
  15637. IN PDEVICE_OBJECT DeviceObject,
  15638. IN DEVICE_RELATION_TYPE Type
  15639. );
  15640. NTKERNELAPI
  15641. VOID
  15642. IoRequestDeviceEject(
  15643. IN PDEVICE_OBJECT PhysicalDeviceObject
  15644. );
  15645. NTKERNELAPI
  15646. NTSTATUS
  15647. IoGetDeviceProperty(
  15648. IN PDEVICE_OBJECT DeviceObject,
  15649. IN DEVICE_REGISTRY_PROPERTY DeviceProperty,
  15650. IN ULONG BufferLength,
  15651. OUT PVOID PropertyBuffer,
  15652. OUT PULONG ResultLength
  15653. );
  15654. //
  15655. // The following definitions are used in IoOpenDeviceRegistryKey
  15656. //
  15657. #define PLUGPLAY_REGKEY_DEVICE 1
  15658. #define PLUGPLAY_REGKEY_DRIVER 2
  15659. #define PLUGPLAY_REGKEY_CURRENT_HWPROFILE 4
  15660. NTKERNELAPI
  15661. NTSTATUS
  15662. IoOpenDeviceRegistryKey(
  15663. IN PDEVICE_OBJECT DeviceObject,
  15664. IN ULONG DevInstKeyType,
  15665. IN ACCESS_MASK DesiredAccess,
  15666. OUT PHANDLE DevInstRegKey
  15667. );
  15668. NTKERNELAPI
  15669. NTSTATUS
  15670. NTAPI
  15671. IoRegisterDeviceInterface(
  15672. IN PDEVICE_OBJECT PhysicalDeviceObject,
  15673. IN CONST GUID *InterfaceClassGuid,
  15674. IN PUNICODE_STRING ReferenceString, OPTIONAL
  15675. OUT PUNICODE_STRING SymbolicLinkName
  15676. );
  15677. NTKERNELAPI
  15678. NTSTATUS
  15679. IoOpenDeviceInterfaceRegistryKey(
  15680. IN PUNICODE_STRING SymbolicLinkName,
  15681. IN ACCESS_MASK DesiredAccess,
  15682. OUT PHANDLE DeviceInterfaceKey
  15683. );
  15684. NTKERNELAPI
  15685. NTSTATUS
  15686. IoSetDeviceInterfaceState(
  15687. IN PUNICODE_STRING SymbolicLinkName,
  15688. IN BOOLEAN Enable
  15689. );
  15690. NTKERNELAPI
  15691. NTSTATUS
  15692. NTAPI
  15693. IoGetDeviceInterfaces(
  15694. IN CONST GUID *InterfaceClassGuid,
  15695. IN PDEVICE_OBJECT PhysicalDeviceObject OPTIONAL,
  15696. IN ULONG Flags,
  15697. OUT PWSTR *SymbolicLinkList
  15698. );
  15699. #define DEVICE_INTERFACE_INCLUDE_NONACTIVE 0x00000001
  15700. NTKERNELAPI
  15701. NTSTATUS
  15702. NTAPI
  15703. IoGetDeviceInterfaceAlias(
  15704. IN PUNICODE_STRING SymbolicLinkName,
  15705. IN CONST GUID *AliasInterfaceClassGuid,
  15706. OUT PUNICODE_STRING AliasSymbolicLinkName
  15707. );
  15708. //
  15709. // Define PnP notification event categories
  15710. //
  15711. typedef enum _IO_NOTIFICATION_EVENT_CATEGORY {
  15712. EventCategoryReserved,
  15713. EventCategoryHardwareProfileChange,
  15714. EventCategoryDeviceInterfaceChange,
  15715. EventCategoryTargetDeviceChange
  15716. } IO_NOTIFICATION_EVENT_CATEGORY;
  15717. //
  15718. // Define flags that modify the behavior of IoRegisterPlugPlayNotification
  15719. // for the various event categories...
  15720. //
  15721. #define PNPNOTIFY_DEVICE_INTERFACE_INCLUDE_EXISTING_INTERFACES 0x00000001
  15722. typedef
  15723. NTSTATUS
  15724. (*PDRIVER_NOTIFICATION_CALLBACK_ROUTINE) (
  15725. IN PVOID NotificationStructure,
  15726. IN PVOID Context
  15727. );
  15728. NTKERNELAPI
  15729. NTSTATUS
  15730. IoRegisterPlugPlayNotification(
  15731. IN IO_NOTIFICATION_EVENT_CATEGORY EventCategory,
  15732. IN ULONG EventCategoryFlags,
  15733. IN PVOID EventCategoryData OPTIONAL,
  15734. IN PDRIVER_OBJECT DriverObject,
  15735. IN PDRIVER_NOTIFICATION_CALLBACK_ROUTINE CallbackRoutine,
  15736. IN PVOID Context,
  15737. OUT PVOID *NotificationEntry
  15738. );
  15739. NTKERNELAPI
  15740. NTSTATUS
  15741. IoUnregisterPlugPlayNotification(
  15742. IN PVOID NotificationEntry
  15743. );
  15744. NTKERNELAPI
  15745. NTSTATUS
  15746. IoReportTargetDeviceChange(
  15747. IN PDEVICE_OBJECT PhysicalDeviceObject,
  15748. IN PVOID NotificationStructure // always begins with a PLUGPLAY_NOTIFICATION_HEADER
  15749. );
  15750. typedef
  15751. VOID
  15752. (*PDEVICE_CHANGE_COMPLETE_CALLBACK)(
  15753. IN PVOID Context
  15754. );
  15755. NTKERNELAPI
  15756. VOID
  15757. IoInvalidateDeviceState(
  15758. IN PDEVICE_OBJECT PhysicalDeviceObject
  15759. );
  15760. #define IoAdjustPagingPathCount(_count_,_paging_) { \
  15761. if (_paging_) { \
  15762. InterlockedIncrement(_count_); \
  15763. } else { \
  15764. InterlockedDecrement(_count_); \
  15765. } \
  15766. }
  15767. NTKERNELAPI
  15768. NTSTATUS
  15769. IoReportTargetDeviceChangeAsynchronous(
  15770. IN PDEVICE_OBJECT PhysicalDeviceObject,
  15771. IN PVOID NotificationStructure, // always begins with a PLUGPLAY_NOTIFICATION_HEADER
  15772. IN PDEVICE_CHANGE_COMPLETE_CALLBACK Callback, OPTIONAL
  15773. IN PVOID Context OPTIONAL
  15774. );
  15775. // end_wdm end_ntosp
  15776. //
  15777. // Resource arbiter declarations
  15778. //
  15779. typedef enum _ARBITER_ACTION {
  15780. ArbiterActionTestAllocation,
  15781. ArbiterActionRetestAllocation,
  15782. ArbiterActionCommitAllocation,
  15783. ArbiterActionRollbackAllocation,
  15784. ArbiterActionQueryAllocatedResources,
  15785. ArbiterActionWriteReservedResources,
  15786. ArbiterActionQueryConflict,
  15787. ArbiterActionQueryArbitrate,
  15788. ArbiterActionAddReserved,
  15789. ArbiterActionBootAllocation
  15790. } ARBITER_ACTION, *PARBITER_ACTION;
  15791. typedef struct _ARBITER_CONFLICT_INFO {
  15792. //
  15793. // The device object owning the device that is causing the conflict
  15794. //
  15795. PDEVICE_OBJECT OwningObject;
  15796. //
  15797. // The start of the conflicting range
  15798. //
  15799. ULONGLONG Start;
  15800. //
  15801. // The end of the conflicting range
  15802. //
  15803. ULONGLONG End;
  15804. } ARBITER_CONFLICT_INFO, *PARBITER_CONFLICT_INFO;
  15805. //
  15806. // The parameters for those actions
  15807. //
  15808. typedef struct _ARBITER_PARAMETERS {
  15809. union {
  15810. struct {
  15811. //
  15812. // Doubly linked list of ARBITER_LIST_ENTRY's
  15813. //
  15814. IN OUT PLIST_ENTRY ArbitrationList;
  15815. //
  15816. // The size of the AllocateFrom array
  15817. //
  15818. IN ULONG AllocateFromCount;
  15819. //
  15820. // Array of resource descriptors describing the resources available
  15821. // to the arbiter for it to arbitrate
  15822. //
  15823. IN PCM_PARTIAL_RESOURCE_DESCRIPTOR AllocateFrom;
  15824. } TestAllocation;
  15825. struct {
  15826. //
  15827. // Doubly linked list of ARBITER_LIST_ENTRY's
  15828. //
  15829. IN OUT PLIST_ENTRY ArbitrationList;
  15830. //
  15831. // The size of the AllocateFrom array
  15832. //
  15833. IN ULONG AllocateFromCount;
  15834. //
  15835. // Array of resource descriptors describing the resources available
  15836. // to the arbiter for it to arbitrate
  15837. //
  15838. IN PCM_PARTIAL_RESOURCE_DESCRIPTOR AllocateFrom;
  15839. } RetestAllocation;
  15840. struct {
  15841. //
  15842. // Doubly linked list of ARBITER_LIST_ENTRY's
  15843. //
  15844. IN OUT PLIST_ENTRY ArbitrationList;
  15845. } BootAllocation;
  15846. struct {
  15847. //
  15848. // The resources that are currently allocated
  15849. //
  15850. OUT PCM_PARTIAL_RESOURCE_LIST *AllocatedResources;
  15851. } QueryAllocatedResources;
  15852. struct {
  15853. //
  15854. // This is the device we are trying to find a conflict for
  15855. //
  15856. IN PDEVICE_OBJECT PhysicalDeviceObject;
  15857. //
  15858. // This is the resource to find the conflict for
  15859. //
  15860. IN PIO_RESOURCE_DESCRIPTOR ConflictingResource;
  15861. //
  15862. // Number of devices conflicting on the resource
  15863. //
  15864. OUT PULONG ConflictCount;
  15865. //
  15866. // Pointer to array describing the conflicting device objects and ranges
  15867. //
  15868. OUT PARBITER_CONFLICT_INFO *Conflicts;
  15869. } QueryConflict;
  15870. struct {
  15871. //
  15872. // Doubly linked list of ARBITER_LIST_ENTRY's - should have
  15873. // only one entry
  15874. //
  15875. IN PLIST_ENTRY ArbitrationList;
  15876. } QueryArbitrate;
  15877. struct {
  15878. //
  15879. // Indicates the device whose resources are to be marked as reserved
  15880. //
  15881. PDEVICE_OBJECT ReserveDevice;
  15882. } AddReserved;
  15883. } Parameters;
  15884. } ARBITER_PARAMETERS, *PARBITER_PARAMETERS;
  15885. typedef enum _ARBITER_REQUEST_SOURCE {
  15886. ArbiterRequestUndefined = -1,
  15887. ArbiterRequestLegacyReported, // IoReportResourceUsage
  15888. ArbiterRequestHalReported, // IoReportHalResourceUsage
  15889. ArbiterRequestLegacyAssigned, // IoAssignResources
  15890. ArbiterRequestPnpDetected, // IoReportResourceForDetection
  15891. ArbiterRequestPnpEnumerated // IRP_MN_QUERY_RESOURCE_REQUIREMENTS
  15892. } ARBITER_REQUEST_SOURCE;
  15893. typedef enum _ARBITER_RESULT {
  15894. ArbiterResultUndefined = -1,
  15895. ArbiterResultSuccess,
  15896. ArbiterResultExternalConflict, // This indicates that the request can never be solved for devices in this list
  15897. ArbiterResultNullRequest // The request was for length zero and thus no translation should be attempted
  15898. } ARBITER_RESULT;
  15899. //
  15900. // ARBITER_FLAG_BOOT_CONFIG - this indicates that the request is for the
  15901. // resources assigned by the firmware/BIOS. It should be succeeded even if
  15902. // it conflicts with another devices boot config.
  15903. //
  15904. #define ARBITER_FLAG_BOOT_CONFIG 0x00000001
  15905. // begin_ntosp
  15906. NTKERNELAPI
  15907. NTSTATUS
  15908. IoReportResourceForDetection(
  15909. IN PDRIVER_OBJECT DriverObject,
  15910. IN PCM_RESOURCE_LIST DriverList OPTIONAL,
  15911. IN ULONG DriverListSize OPTIONAL,
  15912. IN PDEVICE_OBJECT DeviceObject OPTIONAL,
  15913. IN PCM_RESOURCE_LIST DeviceList OPTIONAL,
  15914. IN ULONG DeviceListSize OPTIONAL,
  15915. OUT PBOOLEAN ConflictDetected
  15916. );
  15917. // end_ntosp
  15918. typedef struct _ARBITER_LIST_ENTRY {
  15919. //
  15920. // This is a doubly linked list of entries for easy sorting
  15921. //
  15922. LIST_ENTRY ListEntry;
  15923. //
  15924. // The number of alternative allocation
  15925. //
  15926. ULONG AlternativeCount;
  15927. //
  15928. // Pointer to an array of resource descriptors for the possible allocations
  15929. //
  15930. PIO_RESOURCE_DESCRIPTOR Alternatives;
  15931. //
  15932. // The device object of the device requesting these resources.
  15933. //
  15934. PDEVICE_OBJECT PhysicalDeviceObject;
  15935. //
  15936. // Indicates where the request came from
  15937. //
  15938. ARBITER_REQUEST_SOURCE RequestSource;
  15939. //
  15940. // Flags these indicate a variety of things (use ARBITER_FLAG_*)
  15941. //
  15942. ULONG Flags;
  15943. //
  15944. // Space to aid the arbiter in processing the list it is initialized to 0 when
  15945. // the entry is created. The system will not attempt to interpret it.
  15946. //
  15947. LONG_PTR WorkSpace;
  15948. //
  15949. // Interface Type, Slot Number and Bus Number from Resource Requirements list,
  15950. // used only for reverse identification.
  15951. //
  15952. INTERFACE_TYPE InterfaceType;
  15953. ULONG SlotNumber;
  15954. ULONG BusNumber;
  15955. //
  15956. // A pointer to a descriptor to indicate the resource that was allocated.
  15957. // This is allocated by the system and filled in by the arbiter in response to an
  15958. // ArbiterActionTestAllocation.
  15959. //
  15960. PCM_PARTIAL_RESOURCE_DESCRIPTOR Assignment;
  15961. //
  15962. // Pointer to the alternative that was chosen from to provide the assignment.
  15963. // This is filled in by the arbiter in response to an ArbiterActionTestAllocation.
  15964. //
  15965. PIO_RESOURCE_DESCRIPTOR SelectedAlternative;
  15966. //
  15967. // The result of the operation
  15968. // This is filled in by the arbiter in response to an ArbiterActionTestAllocation.
  15969. //
  15970. ARBITER_RESULT Result;
  15971. } ARBITER_LIST_ENTRY, *PARBITER_LIST_ENTRY;
  15972. //
  15973. // The arbiter's entry point
  15974. //
  15975. typedef
  15976. NTSTATUS
  15977. (*PARBITER_HANDLER) (
  15978. IN PVOID Context,
  15979. IN ARBITER_ACTION Action,
  15980. IN OUT PARBITER_PARAMETERS Parameters
  15981. );
  15982. //
  15983. // Arbiter interface
  15984. //
  15985. #define ARBITER_PARTIAL 0x00000001
  15986. typedef struct _ARBITER_INTERFACE {
  15987. //
  15988. // Generic interface header
  15989. //
  15990. USHORT Size;
  15991. USHORT Version;
  15992. PVOID Context;
  15993. PINTERFACE_REFERENCE InterfaceReference;
  15994. PINTERFACE_DEREFERENCE InterfaceDereference;
  15995. //
  15996. // Entry point to the arbiter
  15997. //
  15998. PARBITER_HANDLER ArbiterHandler;
  15999. //
  16000. // Other information about the arbiter, use ARBITER_* flags
  16001. //
  16002. ULONG Flags;
  16003. } ARBITER_INTERFACE, *PARBITER_INTERFACE;
  16004. //
  16005. // The directions translation can take place in
  16006. //
  16007. typedef enum _RESOURCE_TRANSLATION_DIRECTION { // ntosp
  16008. TranslateChildToParent, // ntosp
  16009. TranslateParentToChild // ntosp
  16010. } RESOURCE_TRANSLATION_DIRECTION; // ntosp
  16011. //
  16012. // Translation functions
  16013. //
  16014. // begin_ntosp
  16015. typedef
  16016. NTSTATUS
  16017. (*PTRANSLATE_RESOURCE_HANDLER)(
  16018. IN PVOID Context,
  16019. IN PCM_PARTIAL_RESOURCE_DESCRIPTOR Source,
  16020. IN RESOURCE_TRANSLATION_DIRECTION Direction,
  16021. IN ULONG AlternativesCount, OPTIONAL
  16022. IN IO_RESOURCE_DESCRIPTOR Alternatives[], OPTIONAL
  16023. IN PDEVICE_OBJECT PhysicalDeviceObject,
  16024. OUT PCM_PARTIAL_RESOURCE_DESCRIPTOR Target
  16025. );
  16026. typedef
  16027. NTSTATUS
  16028. (*PTRANSLATE_RESOURCE_REQUIREMENTS_HANDLER)(
  16029. IN PVOID Context,
  16030. IN PIO_RESOURCE_DESCRIPTOR Source,
  16031. IN PDEVICE_OBJECT PhysicalDeviceObject,
  16032. OUT PULONG TargetCount,
  16033. OUT PIO_RESOURCE_DESCRIPTOR *Target
  16034. );
  16035. //
  16036. // Translator Interface
  16037. //
  16038. typedef struct _TRANSLATOR_INTERFACE {
  16039. USHORT Size;
  16040. USHORT Version;
  16041. PVOID Context;
  16042. PINTERFACE_REFERENCE InterfaceReference;
  16043. PINTERFACE_DEREFERENCE InterfaceDereference;
  16044. PTRANSLATE_RESOURCE_HANDLER TranslateResources;
  16045. PTRANSLATE_RESOURCE_REQUIREMENTS_HANDLER TranslateResourceRequirements;
  16046. } TRANSLATOR_INTERFACE, *PTRANSLATOR_INTERFACE;
  16047. //
  16048. // Header structure for all Plug&Play notification events...
  16049. //
  16050. typedef struct _PLUGPLAY_NOTIFICATION_HEADER {
  16051. USHORT Version; // presently at version 1.
  16052. USHORT Size; // size (in bytes) of header + event-specific data.
  16053. GUID Event;
  16054. //
  16055. // Event-specific stuff starts here.
  16056. //
  16057. } PLUGPLAY_NOTIFICATION_HEADER, *PPLUGPLAY_NOTIFICATION_HEADER;
  16058. //
  16059. // Notification structure for all EventCategoryHardwareProfileChange events...
  16060. //
  16061. typedef struct _HWPROFILE_CHANGE_NOTIFICATION {
  16062. USHORT Version;
  16063. USHORT Size;
  16064. GUID Event;
  16065. //
  16066. // (No event-specific data)
  16067. //
  16068. } HWPROFILE_CHANGE_NOTIFICATION, *PHWPROFILE_CHANGE_NOTIFICATION;
  16069. //
  16070. // Notification structure for all EventCategoryDeviceInterfaceChange events...
  16071. //
  16072. typedef struct _DEVICE_INTERFACE_CHANGE_NOTIFICATION {
  16073. USHORT Version;
  16074. USHORT Size;
  16075. GUID Event;
  16076. //
  16077. // Event-specific data
  16078. //
  16079. GUID InterfaceClassGuid;
  16080. PUNICODE_STRING SymbolicLinkName;
  16081. } DEVICE_INTERFACE_CHANGE_NOTIFICATION, *PDEVICE_INTERFACE_CHANGE_NOTIFICATION;
  16082. //
  16083. // Notification structures for EventCategoryTargetDeviceChange...
  16084. //
  16085. //
  16086. // The following structure is used for TargetDeviceQueryRemove,
  16087. // TargetDeviceRemoveCancelled, and TargetDeviceRemoveComplete:
  16088. //
  16089. typedef struct _TARGET_DEVICE_REMOVAL_NOTIFICATION {
  16090. USHORT Version;
  16091. USHORT Size;
  16092. GUID Event;
  16093. //
  16094. // Event-specific data
  16095. //
  16096. PFILE_OBJECT FileObject;
  16097. } TARGET_DEVICE_REMOVAL_NOTIFICATION, *PTARGET_DEVICE_REMOVAL_NOTIFICATION;
  16098. //
  16099. // The following structure header is used for all other (i.e., 3rd-party)
  16100. // target device change events. The structure accommodates both a
  16101. // variable-length binary data buffer, and a variable-length unicode text
  16102. // buffer. The header must indicate where the text buffer begins, so that
  16103. // the data can be delivered in the appropriate format (ANSI or Unicode)
  16104. // to user-mode recipients (i.e., that have registered for handle-based
  16105. // notification via RegisterDeviceNotification).
  16106. //
  16107. typedef struct _TARGET_DEVICE_CUSTOM_NOTIFICATION {
  16108. USHORT Version;
  16109. USHORT Size;
  16110. GUID Event;
  16111. //
  16112. // Event-specific data
  16113. //
  16114. PFILE_OBJECT FileObject; // This field must be set to NULL by callers of
  16115. // IoReportTargetDeviceChange. Clients that
  16116. // have registered for target device change
  16117. // notification on the affected PDO will be
  16118. // called with this field set to the file object
  16119. // they specified during registration.
  16120. //
  16121. LONG NameBufferOffset; // offset (in bytes) from beginning of
  16122. // CustomDataBuffer where text begins (-1 if none)
  16123. //
  16124. UCHAR CustomDataBuffer[1]; // variable-length buffer, containing (optionally)
  16125. // a binary data at the start of the buffer,
  16126. // followed by an optional unicode text buffer
  16127. // (word-aligned).
  16128. //
  16129. } TARGET_DEVICE_CUSTOM_NOTIFICATION, *PTARGET_DEVICE_CUSTOM_NOTIFICATION;
  16130. //
  16131. // Define the device description structure.
  16132. //
  16133. typedef struct _DEVICE_DESCRIPTION {
  16134. ULONG Version;
  16135. BOOLEAN Master;
  16136. BOOLEAN ScatterGather;
  16137. BOOLEAN DemandMode;
  16138. BOOLEAN AutoInitialize;
  16139. BOOLEAN Dma32BitAddresses;
  16140. BOOLEAN IgnoreCount;
  16141. BOOLEAN Reserved1; // must be false
  16142. BOOLEAN Dma64BitAddresses;
  16143. ULONG BusNumber; // unused for WDM
  16144. ULONG DmaChannel;
  16145. INTERFACE_TYPE InterfaceType;
  16146. DMA_WIDTH DmaWidth;
  16147. DMA_SPEED DmaSpeed;
  16148. ULONG MaximumLength;
  16149. ULONG DmaPort;
  16150. } DEVICE_DESCRIPTION, *PDEVICE_DESCRIPTION;
  16151. //
  16152. // Define the supported version numbers for the device description structure.
  16153. //
  16154. #define DEVICE_DESCRIPTION_VERSION 0
  16155. #define DEVICE_DESCRIPTION_VERSION1 1
  16156. #define DEVICE_DESCRIPTION_VERSION2 2
  16157. //
  16158. // The following function prototypes are for HAL routines with a prefix of Hal.
  16159. //
  16160. // General functions.
  16161. //
  16162. typedef
  16163. BOOLEAN
  16164. (*PHAL_RESET_DISPLAY_PARAMETERS) (
  16165. IN ULONG Columns,
  16166. IN ULONG Rows
  16167. );
  16168. NTHALAPI
  16169. VOID
  16170. HalAcquireDisplayOwnership (
  16171. IN PHAL_RESET_DISPLAY_PARAMETERS ResetDisplayParameters
  16172. );
  16173. #if defined(_ALPHA_) || defined(_IA64_)
  16174. DECLSPEC_DEPRECATED_DDK // Use GetDmaRequirement
  16175. NTHALAPI
  16176. ULONG
  16177. HalGetDmaAlignmentRequirement (
  16178. VOID
  16179. );
  16180. #endif
  16181. #if defined(_M_IX86) || defined(_M_AMD64)
  16182. #define HalGetDmaAlignmentRequirement() 1L
  16183. #endif
  16184. NTHALAPI
  16185. VOID
  16186. KeFlushWriteBuffer (
  16187. VOID
  16188. );
  16189. //
  16190. // I/O driver configuration functions.
  16191. //
  16192. #if !defined(NO_LEGACY_DRIVERS)
  16193. DECLSPEC_DEPRECATED_DDK // Use Pnp or IoReportDetectedDevice
  16194. NTHALAPI
  16195. NTSTATUS
  16196. HalAssignSlotResources (
  16197. IN PUNICODE_STRING RegistryPath,
  16198. IN PUNICODE_STRING DriverClassName OPTIONAL,
  16199. IN PDRIVER_OBJECT DriverObject,
  16200. IN PDEVICE_OBJECT DeviceObject,
  16201. IN INTERFACE_TYPE BusType,
  16202. IN ULONG BusNumber,
  16203. IN ULONG SlotNumber,
  16204. IN OUT PCM_RESOURCE_LIST *AllocatedResources
  16205. );
  16206. DECLSPEC_DEPRECATED_DDK // Use Pnp or IoReportDetectedDevice
  16207. NTHALAPI
  16208. ULONG
  16209. HalGetInterruptVector(
  16210. IN INTERFACE_TYPE InterfaceType,
  16211. IN ULONG BusNumber,
  16212. IN ULONG BusInterruptLevel,
  16213. IN ULONG BusInterruptVector,
  16214. OUT PKIRQL Irql,
  16215. OUT PKAFFINITY Affinity
  16216. );
  16217. DECLSPEC_DEPRECATED_DDK // Use IRP_MN_QUERY_INTERFACE and IRP_MN_READ_CONFIG
  16218. NTHALAPI
  16219. ULONG
  16220. HalSetBusData(
  16221. IN BUS_DATA_TYPE BusDataType,
  16222. IN ULONG BusNumber,
  16223. IN ULONG SlotNumber,
  16224. IN PVOID Buffer,
  16225. IN ULONG Length
  16226. );
  16227. #endif // NO_LEGACY_DRIVERS
  16228. DECLSPEC_DEPRECATED_DDK // Use IRP_MN_QUERY_INTERFACE and IRP_MN_READ_CONFIG
  16229. NTHALAPI
  16230. ULONG
  16231. HalSetBusDataByOffset(
  16232. IN BUS_DATA_TYPE BusDataType,
  16233. IN ULONG BusNumber,
  16234. IN ULONG SlotNumber,
  16235. IN PVOID Buffer,
  16236. IN ULONG Offset,
  16237. IN ULONG Length
  16238. );
  16239. DECLSPEC_DEPRECATED_DDK // Use IRP_MN_QUERY_INTERFACE and IRP_MN_READ_CONFIG
  16240. NTHALAPI
  16241. BOOLEAN
  16242. HalTranslateBusAddress(
  16243. IN INTERFACE_TYPE InterfaceType,
  16244. IN ULONG BusNumber,
  16245. IN PHYSICAL_ADDRESS BusAddress,
  16246. IN OUT PULONG AddressSpace,
  16247. OUT PPHYSICAL_ADDRESS TranslatedAddress
  16248. );
  16249. //
  16250. // Values for AddressSpace parameter of HalTranslateBusAddress
  16251. //
  16252. // 0x0 - Memory space
  16253. // 0x1 - Port space
  16254. // 0x2 - 0x1F - Address spaces specific for Alpha
  16255. // 0x2 - UserMode view of memory space
  16256. // 0x3 - UserMode view of port space
  16257. // 0x4 - Dense memory space
  16258. // 0x5 - reserved
  16259. // 0x6 - UserMode view of dense memory space
  16260. // 0x7 - 0x1F - reserved
  16261. //
  16262. NTHALAPI
  16263. PVOID
  16264. HalAllocateCrashDumpRegisters(
  16265. IN PADAPTER_OBJECT AdapterObject,
  16266. IN OUT PULONG NumberOfMapRegisters
  16267. );
  16268. #if !defined(NO_LEGACY_DRIVERS)
  16269. DECLSPEC_DEPRECATED_DDK // Use IRP_MN_QUERY_INTERFACE and IRP_MN_READ_CONFIG
  16270. NTHALAPI
  16271. ULONG
  16272. HalGetBusData(
  16273. IN BUS_DATA_TYPE BusDataType,
  16274. IN ULONG BusNumber,
  16275. IN ULONG SlotNumber,
  16276. IN PVOID Buffer,
  16277. IN ULONG Length
  16278. );
  16279. #endif // NO_LEGACY_DRIVERS
  16280. DECLSPEC_DEPRECATED_DDK // Use IRP_MN_QUERY_INTERFACE and IRP_MN_READ_CONFIG
  16281. NTHALAPI
  16282. ULONG
  16283. HalGetBusDataByOffset(
  16284. IN BUS_DATA_TYPE BusDataType,
  16285. IN ULONG BusNumber,
  16286. IN ULONG SlotNumber,
  16287. IN PVOID Buffer,
  16288. IN ULONG Offset,
  16289. IN ULONG Length
  16290. );
  16291. DECLSPEC_DEPRECATED_DDK // Use IoGetDmaAdapter
  16292. NTHALAPI
  16293. PADAPTER_OBJECT
  16294. HalGetAdapter(
  16295. IN PDEVICE_DESCRIPTION DeviceDescription,
  16296. IN OUT PULONG NumberOfMapRegisters
  16297. );
  16298. //
  16299. // System beep functions.
  16300. //
  16301. #if !defined(NO_LEGACY_DRIVERS)
  16302. NTHALAPI
  16303. BOOLEAN
  16304. HalMakeBeep(
  16305. IN ULONG Frequency
  16306. );
  16307. #endif // NO_LEGACY_DRIVERS
  16308. //
  16309. // The following function prototypes are for HAL routines with a prefix of Io.
  16310. //
  16311. // DMA adapter object functions.
  16312. //
  16313. //
  16314. // Performance counter function.
  16315. //
  16316. NTHALAPI
  16317. LARGE_INTEGER
  16318. KeQueryPerformanceCounter (
  16319. OUT PLARGE_INTEGER PerformanceFrequency OPTIONAL
  16320. );
  16321. // begin_ntndis
  16322. //
  16323. // Stall processor execution function.
  16324. //
  16325. NTHALAPI
  16326. VOID
  16327. KeStallExecutionProcessor (
  16328. IN ULONG MicroSeconds
  16329. );
  16330. typedef
  16331. VOID
  16332. (*PDEVICE_CONTROL_COMPLETION)(
  16333. IN struct _DEVICE_CONTROL_CONTEXT *ControlContext
  16334. );
  16335. typedef struct _DEVICE_CONTROL_CONTEXT {
  16336. NTSTATUS Status;
  16337. PDEVICE_HANDLER_OBJECT DeviceHandler;
  16338. PDEVICE_OBJECT DeviceObject;
  16339. ULONG ControlCode;
  16340. PVOID Buffer;
  16341. PULONG BufferLength;
  16342. PVOID Context;
  16343. } DEVICE_CONTROL_CONTEXT, *PDEVICE_CONTROL_CONTEXT;
  16344. typedef
  16345. PBUS_HANDLER
  16346. (FASTCALL *pHalHandlerForBus) (
  16347. IN INTERFACE_TYPE InterfaceType,
  16348. IN ULONG BusNumber
  16349. );
  16350. typedef
  16351. VOID
  16352. (FASTCALL *pHalReferenceBusHandler) (
  16353. IN PBUS_HANDLER BusHandler
  16354. );
  16355. //*****************************************************************************
  16356. // HAL Function dispatch
  16357. //
  16358. typedef enum _HAL_QUERY_INFORMATION_CLASS {
  16359. HalInstalledBusInformation,
  16360. HalProfileSourceInformation,
  16361. HalInformationClassUnused1,
  16362. HalPowerInformation,
  16363. HalProcessorSpeedInformation,
  16364. HalCallbackInformation,
  16365. HalMapRegisterInformation,
  16366. HalMcaLogInformation, // Machine Check Abort Information
  16367. HalFrameBufferCachingInformation,
  16368. HalDisplayBiosInformation,
  16369. HalProcessorFeatureInformation,
  16370. HalNumaTopologyInterface,
  16371. HalErrorInformation, // General MCA, CMC, CPE Error Information.
  16372. HalCmcLogInformation, // Processor Corrected Machine Check Information
  16373. HalCpeLogInformation, // Corrected Platform Error Information
  16374. HalQueryMcaInterface,
  16375. HalQueryAMLIIllegalIOPortAddresses,
  16376. HalQueryMaxHotPlugMemoryAddress,
  16377. HalPartitionIpiInterface,
  16378. HalPlatformInformation
  16379. // information levels >= 0x8000000 reserved for OEM use
  16380. } HAL_QUERY_INFORMATION_CLASS, *PHAL_QUERY_INFORMATION_CLASS;
  16381. typedef enum _HAL_SET_INFORMATION_CLASS {
  16382. HalProfileSourceInterval,
  16383. HalProfileSourceInterruptHandler,
  16384. HalMcaRegisterDriver, // Registring Machine Check Abort driver
  16385. HalKernelErrorHandler,
  16386. HalCmcRegisterDriver, // Registring Processor Corrected Machine Check driver
  16387. HalCpeRegisterDriver, // Registring Corrected Platform Error driver
  16388. HalMcaLog,
  16389. HalCmcLog,
  16390. HalCpeLog,
  16391. } HAL_SET_INFORMATION_CLASS, *PHAL_SET_INFORMATION_CLASS;
  16392. typedef
  16393. NTSTATUS
  16394. (*pHalQuerySystemInformation)(
  16395. IN HAL_QUERY_INFORMATION_CLASS InformationClass,
  16396. IN ULONG BufferSize,
  16397. IN OUT PVOID Buffer,
  16398. OUT PULONG ReturnedLength
  16399. );
  16400. NTSTATUS
  16401. HaliQuerySystemInformation(
  16402. IN HAL_SET_INFORMATION_CLASS InformationClass,
  16403. IN ULONG BufferSize,
  16404. IN OUT PVOID Buffer,
  16405. OUT PULONG ReturnedLength
  16406. );
  16407. NTSTATUS
  16408. HaliHandlePCIConfigSpaceAccess(
  16409. IN BOOLEAN Read,
  16410. IN ULONG Addr,
  16411. IN ULONG Size,
  16412. IN OUT PULONG pData
  16413. );
  16414. typedef
  16415. NTSTATUS
  16416. (*pHalSetSystemInformation)(
  16417. IN HAL_SET_INFORMATION_CLASS InformationClass,
  16418. IN ULONG BufferSize,
  16419. IN PVOID Buffer
  16420. );
  16421. NTSTATUS
  16422. HaliSetSystemInformation(
  16423. IN HAL_SET_INFORMATION_CLASS InformationClass,
  16424. IN ULONG BufferSize,
  16425. IN PVOID Buffer
  16426. );
  16427. typedef
  16428. VOID
  16429. (FASTCALL *pHalExamineMBR)(
  16430. IN PDEVICE_OBJECT DeviceObject,
  16431. IN ULONG SectorSize,
  16432. IN ULONG MBRTypeIdentifier,
  16433. OUT PVOID *Buffer
  16434. );
  16435. typedef
  16436. VOID
  16437. (FASTCALL *pHalIoAssignDriveLetters)(
  16438. IN struct _LOADER_PARAMETER_BLOCK *LoaderBlock,
  16439. IN PSTRING NtDeviceName,
  16440. OUT PUCHAR NtSystemPath,
  16441. OUT PSTRING NtSystemPathString
  16442. );
  16443. typedef
  16444. NTSTATUS
  16445. (FASTCALL *pHalIoReadPartitionTable)(
  16446. IN PDEVICE_OBJECT DeviceObject,
  16447. IN ULONG SectorSize,
  16448. IN BOOLEAN ReturnRecognizedPartitions,
  16449. OUT struct _DRIVE_LAYOUT_INFORMATION **PartitionBuffer
  16450. );
  16451. typedef
  16452. NTSTATUS
  16453. (FASTCALL *pHalIoSetPartitionInformation)(
  16454. IN PDEVICE_OBJECT DeviceObject,
  16455. IN ULONG SectorSize,
  16456. IN ULONG PartitionNumber,
  16457. IN ULONG PartitionType
  16458. );
  16459. typedef
  16460. NTSTATUS
  16461. (FASTCALL *pHalIoWritePartitionTable)(
  16462. IN PDEVICE_OBJECT DeviceObject,
  16463. IN ULONG SectorSize,
  16464. IN ULONG SectorsPerTrack,
  16465. IN ULONG NumberOfHeads,
  16466. IN struct _DRIVE_LAYOUT_INFORMATION *PartitionBuffer
  16467. );
  16468. typedef
  16469. NTSTATUS
  16470. (*pHalQueryBusSlots)(
  16471. IN PBUS_HANDLER BusHandler,
  16472. IN ULONG BufferSize,
  16473. OUT PULONG SlotNumbers,
  16474. OUT PULONG ReturnedLength
  16475. );
  16476. typedef
  16477. NTSTATUS
  16478. (*pHalInitPnpDriver)(
  16479. VOID
  16480. );
  16481. NTSTATUS
  16482. HaliInitPnpDriver(
  16483. VOID
  16484. );
  16485. typedef struct _PM_DISPATCH_TABLE {
  16486. ULONG Signature;
  16487. ULONG Version;
  16488. PVOID Function[1];
  16489. } PM_DISPATCH_TABLE, *PPM_DISPATCH_TABLE;
  16490. typedef
  16491. NTSTATUS
  16492. (*pHalInitPowerManagement)(
  16493. IN PPM_DISPATCH_TABLE PmDriverDispatchTable,
  16494. OUT PPM_DISPATCH_TABLE *PmHalDispatchTable
  16495. );
  16496. NTSTATUS
  16497. HaliInitPowerManagement(
  16498. IN PPM_DISPATCH_TABLE PmDriverDispatchTable,
  16499. IN OUT PPM_DISPATCH_TABLE *PmHalDispatchTable
  16500. );
  16501. typedef
  16502. struct _DMA_ADAPTER *
  16503. (*pHalGetDmaAdapter)(
  16504. IN PVOID Context,
  16505. IN struct _DEVICE_DESCRIPTION *DeviceDescriptor,
  16506. OUT PULONG NumberOfMapRegisters
  16507. );
  16508. struct _DMA_ADAPTER *
  16509. HaliGetDmaAdapter(
  16510. IN PVOID Context,
  16511. IN struct _DEVICE_DESCRIPTION *DeviceDescriptor,
  16512. OUT PULONG NumberOfMapRegisters
  16513. );
  16514. typedef
  16515. NTSTATUS
  16516. (*pHalGetInterruptTranslator)(
  16517. IN INTERFACE_TYPE ParentInterfaceType,
  16518. IN ULONG ParentBusNumber,
  16519. IN INTERFACE_TYPE BridgeInterfaceType,
  16520. IN USHORT Size,
  16521. IN USHORT Version,
  16522. OUT PTRANSLATOR_INTERFACE Translator,
  16523. OUT PULONG BridgeBusNumber
  16524. );
  16525. NTSTATUS
  16526. HaliGetInterruptTranslator(
  16527. IN INTERFACE_TYPE ParentInterfaceType,
  16528. IN ULONG ParentBusNumber,
  16529. IN INTERFACE_TYPE BridgeInterfaceType,
  16530. IN USHORT Size,
  16531. IN USHORT Version,
  16532. OUT PTRANSLATOR_INTERFACE Translator,
  16533. OUT PULONG BridgeBusNumber
  16534. );
  16535. typedef
  16536. BOOLEAN
  16537. (*pHalTranslateBusAddress)(
  16538. IN INTERFACE_TYPE InterfaceType,
  16539. IN ULONG BusNumber,
  16540. IN PHYSICAL_ADDRESS BusAddress,
  16541. IN OUT PULONG AddressSpace,
  16542. OUT PPHYSICAL_ADDRESS TranslatedAddress
  16543. );
  16544. typedef
  16545. NTSTATUS
  16546. (*pHalAssignSlotResources) (
  16547. IN PUNICODE_STRING RegistryPath,
  16548. IN PUNICODE_STRING DriverClassName OPTIONAL,
  16549. IN PDRIVER_OBJECT DriverObject,
  16550. IN PDEVICE_OBJECT DeviceObject,
  16551. IN INTERFACE_TYPE BusType,
  16552. IN ULONG BusNumber,
  16553. IN ULONG SlotNumber,
  16554. IN OUT PCM_RESOURCE_LIST *AllocatedResources
  16555. );
  16556. typedef
  16557. VOID
  16558. (*pHalHaltSystem) (
  16559. VOID
  16560. );
  16561. typedef
  16562. VOID
  16563. (*pHalResetDisplay) (
  16564. VOID
  16565. );
  16566. typedef
  16567. UCHAR
  16568. (*pHalVectorToIDTEntry) (
  16569. ULONG Vector
  16570. );
  16571. typedef
  16572. BOOLEAN
  16573. (*pHalFindBusAddressTranslation) (
  16574. IN PHYSICAL_ADDRESS BusAddress,
  16575. IN OUT PULONG AddressSpace,
  16576. OUT PPHYSICAL_ADDRESS TranslatedAddress,
  16577. IN OUT PULONG_PTR Context,
  16578. IN BOOLEAN NextBus
  16579. );
  16580. typedef
  16581. NTSTATUS
  16582. (*pHalStartMirroring)(
  16583. VOID
  16584. );
  16585. typedef
  16586. NTSTATUS
  16587. (*pHalEndMirroring)(
  16588. IN ULONG PassNumber
  16589. );
  16590. typedef
  16591. NTSTATUS
  16592. (*pHalMirrorPhysicalMemory)(
  16593. IN PHYSICAL_ADDRESS PhysicalAddress,
  16594. IN LARGE_INTEGER NumberOfBytes
  16595. );
  16596. typedef
  16597. NTSTATUS
  16598. (*pHalMirrorVerify)(
  16599. IN PHYSICAL_ADDRESS PhysicalAddress,
  16600. IN LARGE_INTEGER NumberOfBytes
  16601. );
  16602. typedef struct {
  16603. UCHAR Type; //CmResourceType
  16604. BOOLEAN Valid;
  16605. UCHAR Reserved[2];
  16606. PUCHAR TranslatedAddress;
  16607. ULONG Length;
  16608. } DEBUG_DEVICE_ADDRESS, *PDEBUG_DEVICE_ADDRESS;
  16609. typedef struct {
  16610. PHYSICAL_ADDRESS Start;
  16611. PHYSICAL_ADDRESS MaxEnd;
  16612. PVOID VirtualAddress;
  16613. ULONG Length;
  16614. BOOLEAN Cached;
  16615. BOOLEAN Aligned;
  16616. } DEBUG_MEMORY_REQUIREMENTS, *PDEBUG_MEMORY_REQUIREMENTS;
  16617. typedef struct {
  16618. ULONG Bus;
  16619. ULONG Slot;
  16620. USHORT VendorID;
  16621. USHORT DeviceID;
  16622. UCHAR BaseClass;
  16623. UCHAR SubClass;
  16624. UCHAR ProgIf;
  16625. BOOLEAN Initialized;
  16626. DEBUG_DEVICE_ADDRESS BaseAddress[6];
  16627. DEBUG_MEMORY_REQUIREMENTS Memory;
  16628. } DEBUG_DEVICE_DESCRIPTOR, *PDEBUG_DEVICE_DESCRIPTOR;
  16629. typedef
  16630. NTSTATUS
  16631. (*pKdSetupPciDeviceForDebugging)(
  16632. IN PVOID LoaderBlock, OPTIONAL
  16633. IN OUT PDEBUG_DEVICE_DESCRIPTOR PciDevice
  16634. );
  16635. typedef
  16636. NTSTATUS
  16637. (*pKdReleasePciDeviceForDebugging)(
  16638. IN OUT PDEBUG_DEVICE_DESCRIPTOR PciDevice
  16639. );
  16640. typedef
  16641. PVOID
  16642. (*pKdGetAcpiTablePhase0)(
  16643. IN struct _LOADER_PARAMETER_BLOCK *LoaderBlock,
  16644. IN ULONG Signature
  16645. );
  16646. typedef
  16647. VOID
  16648. (*pKdCheckPowerButton)(
  16649. VOID
  16650. );
  16651. typedef
  16652. VOID
  16653. (*pHalEndOfBoot)(
  16654. VOID
  16655. );
  16656. typedef
  16657. PVOID
  16658. (*pKdMapPhysicalMemory64)(
  16659. IN PHYSICAL_ADDRESS PhysicalAddress,
  16660. IN ULONG NumberPages
  16661. );
  16662. typedef
  16663. VOID
  16664. (*pKdUnmapVirtualAddress)(
  16665. IN PVOID VirtualAddress,
  16666. IN ULONG NumberPages
  16667. );
  16668. typedef struct {
  16669. ULONG Version;
  16670. pHalQuerySystemInformation HalQuerySystemInformation;
  16671. pHalSetSystemInformation HalSetSystemInformation;
  16672. pHalQueryBusSlots HalQueryBusSlots;
  16673. ULONG Spare1;
  16674. pHalExamineMBR HalExamineMBR;
  16675. pHalIoAssignDriveLetters HalIoAssignDriveLetters;
  16676. pHalIoReadPartitionTable HalIoReadPartitionTable;
  16677. pHalIoSetPartitionInformation HalIoSetPartitionInformation;
  16678. pHalIoWritePartitionTable HalIoWritePartitionTable;
  16679. pHalHandlerForBus HalReferenceHandlerForBus;
  16680. pHalReferenceBusHandler HalReferenceBusHandler;
  16681. pHalReferenceBusHandler HalDereferenceBusHandler;
  16682. pHalInitPnpDriver HalInitPnpDriver;
  16683. pHalInitPowerManagement HalInitPowerManagement;
  16684. pHalGetDmaAdapter HalGetDmaAdapter;
  16685. pHalGetInterruptTranslator HalGetInterruptTranslator;
  16686. pHalStartMirroring HalStartMirroring;
  16687. pHalEndMirroring HalEndMirroring;
  16688. pHalMirrorPhysicalMemory HalMirrorPhysicalMemory;
  16689. pHalEndOfBoot HalEndOfBoot;
  16690. pHalMirrorVerify HalMirrorVerify;
  16691. } HAL_DISPATCH, *PHAL_DISPATCH;
  16692. #if defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_) || defined(_NTHAL_)
  16693. extern PHAL_DISPATCH HalDispatchTable;
  16694. #define HALDISPATCH HalDispatchTable
  16695. #else
  16696. extern HAL_DISPATCH HalDispatchTable;
  16697. #define HALDISPATCH (&HalDispatchTable)
  16698. #endif
  16699. #define HAL_DISPATCH_VERSION 3
  16700. #define HalDispatchTableVersion HALDISPATCH->Version
  16701. #define HalQuerySystemInformation HALDISPATCH->HalQuerySystemInformation
  16702. #define HalSetSystemInformation HALDISPATCH->HalSetSystemInformation
  16703. #define HalQueryBusSlots HALDISPATCH->HalQueryBusSlots
  16704. #define HalReferenceHandlerForBus HALDISPATCH->HalReferenceHandlerForBus
  16705. #define HalReferenceBusHandler HALDISPATCH->HalReferenceBusHandler
  16706. #define HalDereferenceBusHandler HALDISPATCH->HalDereferenceBusHandler
  16707. #define HalInitPnpDriver HALDISPATCH->HalInitPnpDriver
  16708. #define HalInitPowerManagement HALDISPATCH->HalInitPowerManagement
  16709. #define HalGetDmaAdapter HALDISPATCH->HalGetDmaAdapter
  16710. #define HalGetInterruptTranslator HALDISPATCH->HalGetInterruptTranslator
  16711. #define HalStartMirroring HALDISPATCH->HalStartMirroring
  16712. #define HalEndMirroring HALDISPATCH->HalEndMirroring
  16713. #define HalMirrorPhysicalMemory HALDISPATCH->HalMirrorPhysicalMemory
  16714. #define HalEndOfBoot HALDISPATCH->HalEndOfBoot
  16715. #define HalMirrorVerify HALDISPATCH->HalMirrorVerify
  16716. //
  16717. // HAL System Information Structures.
  16718. //
  16719. // for the information class "HalInstalledBusInformation"
  16720. typedef struct _HAL_BUS_INFORMATION{
  16721. INTERFACE_TYPE BusType;
  16722. BUS_DATA_TYPE ConfigurationType;
  16723. ULONG BusNumber;
  16724. ULONG Reserved;
  16725. } HAL_BUS_INFORMATION, *PHAL_BUS_INFORMATION;
  16726. // for the information class "HalProfileSourceInformation"
  16727. typedef struct _HAL_PROFILE_SOURCE_INFORMATION {
  16728. KPROFILE_SOURCE Source;
  16729. BOOLEAN Supported;
  16730. ULONG Interval;
  16731. } HAL_PROFILE_SOURCE_INFORMATION, *PHAL_PROFILE_SOURCE_INFORMATION;
  16732. typedef struct _HAL_PROFILE_SOURCE_INFORMATION_EX {
  16733. KPROFILE_SOURCE Source;
  16734. BOOLEAN Supported;
  16735. ULONG_PTR Interval;
  16736. ULONG_PTR DefInterval;
  16737. ULONG_PTR MaxInterval;
  16738. ULONG_PTR MinInterval;
  16739. } HAL_PROFILE_SOURCE_INFORMATION_EX, *PHAL_PROFILE_SOURCE_INFORMATION_EX;
  16740. // for the information class "HalProfileSourceInterval"
  16741. typedef struct _HAL_PROFILE_SOURCE_INTERVAL {
  16742. KPROFILE_SOURCE Source;
  16743. ULONG_PTR Interval;
  16744. } HAL_PROFILE_SOURCE_INTERVAL, *PHAL_PROFILE_SOURCE_INTERVAL;
  16745. // for the information class "HalDispayBiosInformation"
  16746. typedef enum _HAL_DISPLAY_BIOS_INFORMATION {
  16747. HalDisplayInt10Bios,
  16748. HalDisplayEmulatedBios,
  16749. HalDisplayNoBios
  16750. } HAL_DISPLAY_BIOS_INFORMATION, *PHAL_DISPLAY_BIOS_INFORMATION;
  16751. // for the information class "HalPowerInformation"
  16752. typedef struct _HAL_POWER_INFORMATION {
  16753. ULONG TBD;
  16754. } HAL_POWER_INFORMATION, *PHAL_POWER_INFORMATION;
  16755. // for the information class "HalProcessorSpeedInformation"
  16756. typedef struct _HAL_PROCESSOR_SPEED_INFO {
  16757. ULONG ProcessorSpeed;
  16758. } HAL_PROCESSOR_SPEED_INFORMATION, *PHAL_PROCESSOR_SPEED_INFORMATION;
  16759. // for the information class "HalCallbackInformation"
  16760. typedef struct _HAL_CALLBACKS {
  16761. PCALLBACK_OBJECT SetSystemInformation;
  16762. PCALLBACK_OBJECT BusCheck;
  16763. } HAL_CALLBACKS, *PHAL_CALLBACKS;
  16764. // for the information class "HalProcessorFeatureInformation"
  16765. typedef struct _HAL_PROCESSOR_FEATURE {
  16766. ULONG UsableFeatureBits;
  16767. } HAL_PROCESSOR_FEATURE;
  16768. // for the information class "HalNumaTopologyInterface"
  16769. typedef ULONG HALNUMAPAGETONODE;
  16770. typedef
  16771. HALNUMAPAGETONODE
  16772. (*PHALNUMAPAGETONODE)(
  16773. IN ULONG_PTR PhysicalPageNumber
  16774. );
  16775. typedef
  16776. NTSTATUS
  16777. (*PHALNUMAQUERYPROCESSORNODE)(
  16778. IN ULONG ProcessorNumber,
  16779. OUT PUSHORT Identifier,
  16780. OUT PUCHAR Node
  16781. );
  16782. typedef struct _HAL_NUMA_TOPOLOGY_INTERFACE {
  16783. ULONG NumberOfNodes;
  16784. PHALNUMAQUERYPROCESSORNODE QueryProcessorNode;
  16785. PHALNUMAPAGETONODE PageToNode;
  16786. } HAL_NUMA_TOPOLOGY_INTERFACE;
  16787. typedef
  16788. NTSTATUS
  16789. (*PHALIOREADWRITEHANDLER)(
  16790. IN BOOLEAN fRead,
  16791. IN ULONG dwAddr,
  16792. IN ULONG dwSize,
  16793. IN OUT PULONG pdwData
  16794. );
  16795. // for the information class "HalQueryIllegalIOPortAddresses"
  16796. typedef struct _HAL_AMLI_BAD_IO_ADDRESS_LIST
  16797. {
  16798. ULONG BadAddrBegin;
  16799. ULONG BadAddrSize;
  16800. ULONG OSVersionTrigger;
  16801. PHALIOREADWRITEHANDLER IOHandler;
  16802. } HAL_AMLI_BAD_IO_ADDRESS_LIST, *PHAL_AMLI_BAD_IO_ADDRESS_LIST;
  16803. // end_ntosp
  16804. #if defined(_X86_) || defined(_IA64_) || defined(_AMD64_)
  16805. //
  16806. // HalQueryMcaInterface
  16807. //
  16808. typedef
  16809. VOID
  16810. (*PHALMCAINTERFACELOCK)(
  16811. VOID
  16812. );
  16813. typedef
  16814. VOID
  16815. (*PHALMCAINTERFACEUNLOCK)(
  16816. VOID
  16817. );
  16818. typedef
  16819. NTSTATUS
  16820. (*PHALMCAINTERFACEREADREGISTER)(
  16821. IN UCHAR BankNumber,
  16822. IN OUT PVOID Exception
  16823. );
  16824. typedef struct _HAL_MCA_INTERFACE {
  16825. PHALMCAINTERFACELOCK Lock;
  16826. PHALMCAINTERFACEUNLOCK Unlock;
  16827. PHALMCAINTERFACEREADREGISTER ReadRegister;
  16828. } HAL_MCA_INTERFACE;
  16829. typedef
  16830. #if defined(_IA64_)
  16831. ERROR_SEVERITY
  16832. #else // !_IA64_
  16833. VOID
  16834. #endif // !_IA64_
  16835. (*PDRIVER_EXCPTN_CALLBACK) (
  16836. IN PVOID Context,
  16837. IN PMCA_EXCEPTION BankLog
  16838. );
  16839. typedef PDRIVER_EXCPTN_CALLBACK PDRIVER_MCA_EXCEPTION_CALLBACK;
  16840. //
  16841. // Structure to record the callbacks from driver
  16842. //
  16843. typedef struct _MCA_DRIVER_INFO {
  16844. PDRIVER_MCA_EXCEPTION_CALLBACK ExceptionCallback;
  16845. PKDEFERRED_ROUTINE DpcCallback;
  16846. PVOID DeviceContext;
  16847. } MCA_DRIVER_INFO, *PMCA_DRIVER_INFO;
  16848. // For the information class HalKernelErrorHandler
  16849. typedef BOOLEAN (*KERNEL_MCA_DELIVERY)( PVOID Reserved, PVOID Argument2 );
  16850. typedef BOOLEAN (*KERNEL_CMC_DELIVERY)( PVOID Reserved, PVOID Argument2 );
  16851. typedef BOOLEAN (*KERNEL_CPE_DELIVERY)( PVOID Reserved, PVOID Argument2 );
  16852. typedef BOOLEAN (*KERNEL_MCE_DELIVERY)( PVOID Reserved, PVOID Argument2 );
  16853. #define KERNEL_ERROR_HANDLER_VERSION 0x1
  16854. typedef struct
  16855. {
  16856. ULONG Version; // Version of this structure. Required to be 1rst field.
  16857. ULONG Padding;
  16858. KERNEL_MCA_DELIVERY KernelMcaDelivery; // Kernel callback for MCA DPC Queueing.
  16859. KERNEL_CMC_DELIVERY KernelCmcDelivery; // Kernel callback for CMC DPC Queueing.
  16860. KERNEL_CPE_DELIVERY KernelCpeDelivery; // Kernel callback for CPE DPC Queueing.
  16861. KERNEL_MCE_DELIVERY KernelMceDelivery; // Kernel callback for CME DPC Queueing.
  16862. // Includes the kernel notifications for FW
  16863. // interfaces errors.
  16864. } KERNEL_ERROR_HANDLER_INFO, *PKERNEL_ERROR_HANDLER_INFO;
  16865. // KERNEL_MCA_DELIVERY.McaType definition
  16866. #define KERNEL_MCA_UNKNOWN 0x0
  16867. #define KERNEL_MCA_PREVIOUS 0x1
  16868. #define KERNEL_MCA_CORRECTED 0x2
  16869. // KERNEL_MCE_DELIVERY.Reserved.EVENTTYPE definitions
  16870. #define KERNEL_MCE_EVENTTYPE_MCA 0x00
  16871. #define KERNEL_MCE_EVENTTYPE_INIT 0x01
  16872. #define KERNEL_MCE_EVENTTYPE_CMC 0x02
  16873. #define KERNEL_MCE_EVENTTYPE_CPE 0x03
  16874. #define KERNEL_MCE_EVENTTYPE_MASK 0xffff
  16875. #define KERNEL_MCE_EVENTTYPE( _Reverved ) ((USHORT)(ULONG_PTR)(_Reserved))
  16876. // KERNEL_MCE_DELIVERY.Reserved.OPERATION definitions
  16877. #define KERNEL_MCE_OPERATION_CLEAR_STATE_INFO 0x1
  16878. #define KERNEL_MCE_OPERATION_GET_STATE_INFO 0x2
  16879. #define KERNEL_MCE_OPERATION_MASK 0xffff
  16880. #define KERNEL_MCE_OPERATION_SHIFT KERNEL_MCE_EVENTTYPE_MASK
  16881. #define KERNEL_MCE_OPERATION( _Reserved ) \
  16882. ((USHORT)((((ULONG_PTR)(_Reserved)) >> KERNEL_MCE_OPERATION_SHIFT) & KERNEL_MCE_OPERATION_MASK))
  16883. // for information class HalErrorInformation
  16884. #define HAL_ERROR_INFO_VERSION 0x2
  16885. typedef struct _HAL_ERROR_INFO {
  16886. ULONG Version; // Version of this structure
  16887. ULONG Reserved; //
  16888. ULONG McaMaxSize; // Maximum size of a Machine Check Abort record
  16889. ULONG McaPreviousEventsCount; // Flag indicating previous or early-boot MCA event logs.
  16890. ULONG McaCorrectedEventsCount; // Number of corrected MCA events since boot. approx.
  16891. ULONG McaKernelDeliveryFails; // Number of Kernel callback failures. approx.
  16892. ULONG McaDriverDpcQueueFails; // Number of OEM MCA Driver Dpc queueing failures. approx.
  16893. ULONG McaReserved;
  16894. ULONG CmcMaxSize; // Maximum size of a Corrected Machine Check record
  16895. ULONG CmcPollingInterval; // In units of seconds
  16896. ULONG CmcInterruptsCount; // Number of CMC interrupts. approx.
  16897. ULONG CmcKernelDeliveryFails; // Number of Kernel callback failures. approx.
  16898. ULONG CmcDriverDpcQueueFails; // Number of OEM CMC Driver Dpc queueing failures. approx.
  16899. ULONG CmcGetStateFails; // Number of failures in getting the log from FW.
  16900. ULONG CmcClearStateFails; // Number of failures in clearing the log from FW.
  16901. ULONG CmcReserved;
  16902. ULONGLONG CmcLogId; // Last seen record identifier.
  16903. ULONG CpeMaxSize; // Maximum size of a Corrected Platform Event record
  16904. ULONG CpePollingInterval; // In units of seconds
  16905. ULONG CpeInterruptsCount; // Number of CPE interrupts. approx.
  16906. ULONG CpeKernelDeliveryFails; // Number of Kernel callback failures. approx.
  16907. ULONG CpeDriverDpcQueueFails; // Number of OEM CPE Driver Dpc queueing failures. approx.
  16908. ULONG CpeGetStateFails; // Number of failures in getting the log from FW.
  16909. ULONG CpeClearStateFails; // Number of failures in clearing the log from FW.
  16910. ULONG CpeInterruptSources; // Number of SAPIC Platform Interrupt Sources
  16911. ULONGLONG CpeLogId; // Last seen record identifier.
  16912. ULONGLONG KernelReserved[4];
  16913. } HAL_ERROR_INFO, *PHAL_ERROR_INFO;
  16914. //
  16915. // Known values for HAL_ERROR_INFO.CmcPollingInterval.
  16916. //
  16917. #define HAL_CMC_INTERRUPTS_BASED ((ULONG)-1)
  16918. #define HAL_CMC_DISABLED ((ULONG)0)
  16919. //
  16920. // Known values for HAL_ERROR_INFO.CpePollingInterval.
  16921. //
  16922. #define HAL_CPE_INTERRUPTS_BASED ((ULONG)-1)
  16923. #define HAL_CPE_DISABLED ((ULONG)0)
  16924. #define HAL_MCA_INTERRUPTS_BASED ((ULONG)-1)
  16925. #define HAL_MCA_DISABLED ((ULONG)0)
  16926. //
  16927. // Driver Callback type for the information class "HalCmcRegisterDriver"
  16928. //
  16929. typedef
  16930. VOID
  16931. (*PDRIVER_CMC_EXCEPTION_CALLBACK) (
  16932. IN PVOID Context,
  16933. IN PCMC_EXCEPTION CmcLog
  16934. );
  16935. //
  16936. // Driver Callback type for the information class "HalCpeRegisterDriver"
  16937. //
  16938. typedef
  16939. VOID
  16940. (*PDRIVER_CPE_EXCEPTION_CALLBACK) (
  16941. IN PVOID Context,
  16942. IN PCPE_EXCEPTION CmcLog
  16943. );
  16944. //
  16945. //
  16946. // Structure to record the callbacks from driver
  16947. //
  16948. typedef struct _CMC_DRIVER_INFO {
  16949. PDRIVER_CMC_EXCEPTION_CALLBACK ExceptionCallback;
  16950. PKDEFERRED_ROUTINE DpcCallback;
  16951. PVOID DeviceContext;
  16952. } CMC_DRIVER_INFO, *PCMC_DRIVER_INFO;
  16953. typedef struct _CPE_DRIVER_INFO {
  16954. PDRIVER_CPE_EXCEPTION_CALLBACK ExceptionCallback;
  16955. PKDEFERRED_ROUTINE DpcCallback;
  16956. PVOID DeviceContext;
  16957. } CPE_DRIVER_INFO, *PCPE_DRIVER_INFO;
  16958. #endif // defined(_X86_) || defined(_IA64_) || defined(_AMD64_)
  16959. #if defined(_IA64_)
  16960. typedef
  16961. NTSTATUS
  16962. (*HALSENDCROSSPARTITIONIPI)(
  16963. IN USHORT ProcessorID,
  16964. IN UCHAR HardwareVector
  16965. );
  16966. typedef
  16967. NTSTATUS
  16968. (*HALRESERVECROSSPARTITIONINTERRUPTVECTOR)(
  16969. OUT PULONG Vector,
  16970. OUT PKIRQL Irql,
  16971. IN OUT PKAFFINITY Affinity,
  16972. OUT PUCHAR HardwareVector
  16973. );
  16974. typedef struct _HAL_CROSS_PARTITION_IPI_INTERFACE {
  16975. HALSENDCROSSPARTITIONIPI HalSendCrossPartitionIpi;
  16976. HALRESERVECROSSPARTITIONINTERRUPTVECTOR HalReserveCrossPartitionInterruptVector;
  16977. } HAL_CROSS_PARTITION_IPI_INTERFACE;
  16978. #endif
  16979. typedef struct _HAL_PLATFORM_INFORMATION {
  16980. ULONG PlatformFlags;
  16981. } HAL_PLATFORM_INFORMATION, *PHAL_PLATFORM_INFORMATION;
  16982. //
  16983. // These platform flags are carried over from the IPPT table
  16984. // definition if appropriate.
  16985. //
  16986. #define HAL_PLATFORM_DISABLE_PTCG 0x04L
  16987. #define HAL_PLATFORM_DISABLE_UC_MAIN_MEMORY 0x08L
  16988. // begin_wdm begin_ntndis begin_ntosp
  16989. typedef struct _SCATTER_GATHER_ELEMENT {
  16990. PHYSICAL_ADDRESS Address;
  16991. ULONG Length;
  16992. ULONG_PTR Reserved;
  16993. } SCATTER_GATHER_ELEMENT, *PSCATTER_GATHER_ELEMENT;
  16994. #pragma warning(disable:4200)
  16995. typedef struct _SCATTER_GATHER_LIST {
  16996. ULONG NumberOfElements;
  16997. ULONG_PTR Reserved;
  16998. SCATTER_GATHER_ELEMENT Elements[];
  16999. } SCATTER_GATHER_LIST, *PSCATTER_GATHER_LIST;
  17000. #pragma warning(default:4200)
  17001. // end_ntndis
  17002. typedef struct _DMA_OPERATIONS *PDMA_OPERATIONS;
  17003. typedef struct _DMA_ADAPTER {
  17004. USHORT Version;
  17005. USHORT Size;
  17006. PDMA_OPERATIONS DmaOperations;
  17007. // Private Bus Device Driver data follows,
  17008. } DMA_ADAPTER, *PDMA_ADAPTER;
  17009. typedef VOID (*PPUT_DMA_ADAPTER)(
  17010. PDMA_ADAPTER DmaAdapter
  17011. );
  17012. typedef PVOID (*PALLOCATE_COMMON_BUFFER)(
  17013. IN PDMA_ADAPTER DmaAdapter,
  17014. IN ULONG Length,
  17015. OUT PPHYSICAL_ADDRESS LogicalAddress,
  17016. IN BOOLEAN CacheEnabled
  17017. );
  17018. typedef VOID (*PFREE_COMMON_BUFFER)(
  17019. IN PDMA_ADAPTER DmaAdapter,
  17020. IN ULONG Length,
  17021. IN PHYSICAL_ADDRESS LogicalAddress,
  17022. IN PVOID VirtualAddress,
  17023. IN BOOLEAN CacheEnabled
  17024. );
  17025. typedef NTSTATUS (*PALLOCATE_ADAPTER_CHANNEL)(
  17026. IN PDMA_ADAPTER DmaAdapter,
  17027. IN PDEVICE_OBJECT DeviceObject,
  17028. IN ULONG NumberOfMapRegisters,
  17029. IN PDRIVER_CONTROL ExecutionRoutine,
  17030. IN PVOID Context
  17031. );
  17032. typedef BOOLEAN (*PFLUSH_ADAPTER_BUFFERS)(
  17033. IN PDMA_ADAPTER DmaAdapter,
  17034. IN PMDL Mdl,
  17035. IN PVOID MapRegisterBase,
  17036. IN PVOID CurrentVa,
  17037. IN ULONG Length,
  17038. IN BOOLEAN WriteToDevice
  17039. );
  17040. typedef VOID (*PFREE_ADAPTER_CHANNEL)(
  17041. IN PDMA_ADAPTER DmaAdapter
  17042. );
  17043. typedef VOID (*PFREE_MAP_REGISTERS)(
  17044. IN PDMA_ADAPTER DmaAdapter,
  17045. PVOID MapRegisterBase,
  17046. ULONG NumberOfMapRegisters
  17047. );
  17048. typedef PHYSICAL_ADDRESS (*PMAP_TRANSFER)(
  17049. IN PDMA_ADAPTER DmaAdapter,
  17050. IN PMDL Mdl,
  17051. IN PVOID MapRegisterBase,
  17052. IN PVOID CurrentVa,
  17053. IN OUT PULONG Length,
  17054. IN BOOLEAN WriteToDevice
  17055. );
  17056. typedef ULONG (*PGET_DMA_ALIGNMENT)(
  17057. IN PDMA_ADAPTER DmaAdapter
  17058. );
  17059. typedef ULONG (*PREAD_DMA_COUNTER)(
  17060. IN PDMA_ADAPTER DmaAdapter
  17061. );
  17062. typedef VOID
  17063. (*PDRIVER_LIST_CONTROL)(
  17064. IN struct _DEVICE_OBJECT *DeviceObject,
  17065. IN struct _IRP *Irp,
  17066. IN PSCATTER_GATHER_LIST ScatterGather,
  17067. IN PVOID Context
  17068. );
  17069. typedef NTSTATUS
  17070. (*PGET_SCATTER_GATHER_LIST)(
  17071. IN PDMA_ADAPTER DmaAdapter,
  17072. IN PDEVICE_OBJECT DeviceObject,
  17073. IN PMDL Mdl,
  17074. IN PVOID CurrentVa,
  17075. IN ULONG Length,
  17076. IN PDRIVER_LIST_CONTROL ExecutionRoutine,
  17077. IN PVOID Context,
  17078. IN BOOLEAN WriteToDevice
  17079. );
  17080. typedef VOID
  17081. (*PPUT_SCATTER_GATHER_LIST)(
  17082. IN PDMA_ADAPTER DmaAdapter,
  17083. IN PSCATTER_GATHER_LIST ScatterGather,
  17084. IN BOOLEAN WriteToDevice
  17085. );
  17086. typedef NTSTATUS
  17087. (*PCALCULATE_SCATTER_GATHER_LIST_SIZE)(
  17088. IN PDMA_ADAPTER DmaAdapter,
  17089. IN OPTIONAL PMDL Mdl,
  17090. IN PVOID CurrentVa,
  17091. IN ULONG Length,
  17092. OUT PULONG ScatterGatherListSize,
  17093. OUT OPTIONAL PULONG pNumberOfMapRegisters
  17094. );
  17095. typedef NTSTATUS
  17096. (*PBUILD_SCATTER_GATHER_LIST)(
  17097. IN PDMA_ADAPTER DmaAdapter,
  17098. IN PDEVICE_OBJECT DeviceObject,
  17099. IN PMDL Mdl,
  17100. IN PVOID CurrentVa,
  17101. IN ULONG Length,
  17102. IN PDRIVER_LIST_CONTROL ExecutionRoutine,
  17103. IN PVOID Context,
  17104. IN BOOLEAN WriteToDevice,
  17105. IN PVOID ScatterGatherBuffer,
  17106. IN ULONG ScatterGatherLength
  17107. );
  17108. typedef NTSTATUS
  17109. (*PBUILD_MDL_FROM_SCATTER_GATHER_LIST)(
  17110. IN PDMA_ADAPTER DmaAdapter,
  17111. IN PSCATTER_GATHER_LIST ScatterGather,
  17112. IN PMDL OriginalMdl,
  17113. OUT PMDL *TargetMdl
  17114. );
  17115. typedef struct _DMA_OPERATIONS {
  17116. ULONG Size;
  17117. PPUT_DMA_ADAPTER PutDmaAdapter;
  17118. PALLOCATE_COMMON_BUFFER AllocateCommonBuffer;
  17119. PFREE_COMMON_BUFFER FreeCommonBuffer;
  17120. PALLOCATE_ADAPTER_CHANNEL AllocateAdapterChannel;
  17121. PFLUSH_ADAPTER_BUFFERS FlushAdapterBuffers;
  17122. PFREE_ADAPTER_CHANNEL FreeAdapterChannel;
  17123. PFREE_MAP_REGISTERS FreeMapRegisters;
  17124. PMAP_TRANSFER MapTransfer;
  17125. PGET_DMA_ALIGNMENT GetDmaAlignment;
  17126. PREAD_DMA_COUNTER ReadDmaCounter;
  17127. PGET_SCATTER_GATHER_LIST GetScatterGatherList;
  17128. PPUT_SCATTER_GATHER_LIST PutScatterGatherList;
  17129. PCALCULATE_SCATTER_GATHER_LIST_SIZE CalculateScatterGatherList;
  17130. PBUILD_SCATTER_GATHER_LIST BuildScatterGatherList;
  17131. PBUILD_MDL_FROM_SCATTER_GATHER_LIST BuildMdlFromScatterGatherList;
  17132. } DMA_OPERATIONS;
  17133. // end_wdm
  17134. #if defined(_WIN64)
  17135. //
  17136. // Use __inline DMA macros (hal.h)
  17137. //
  17138. #ifndef USE_DMA_MACROS
  17139. #define USE_DMA_MACROS
  17140. #endif
  17141. //
  17142. // Only PnP drivers!
  17143. //
  17144. #ifndef NO_LEGACY_DRIVERS
  17145. #define NO_LEGACY_DRIVERS
  17146. #endif
  17147. #endif // _WIN64
  17148. #if defined(USE_DMA_MACROS) && (defined(_NTDDK_) || defined(_NTDRIVER_))
  17149. // begin_wdm
  17150. DECLSPEC_DEPRECATED_DDK // Use AllocateCommonBuffer
  17151. FORCEINLINE
  17152. PVOID
  17153. HalAllocateCommonBuffer(
  17154. IN PDMA_ADAPTER DmaAdapter,
  17155. IN ULONG Length,
  17156. OUT PPHYSICAL_ADDRESS LogicalAddress,
  17157. IN BOOLEAN CacheEnabled
  17158. ){
  17159. PALLOCATE_COMMON_BUFFER allocateCommonBuffer;
  17160. PVOID commonBuffer;
  17161. allocateCommonBuffer = *(DmaAdapter)->DmaOperations->AllocateCommonBuffer;
  17162. ASSERT( allocateCommonBuffer != NULL );
  17163. commonBuffer = allocateCommonBuffer( DmaAdapter,
  17164. Length,
  17165. LogicalAddress,
  17166. CacheEnabled );
  17167. return commonBuffer;
  17168. }
  17169. DECLSPEC_DEPRECATED_DDK // Use FreeCommonBuffer
  17170. FORCEINLINE
  17171. VOID
  17172. HalFreeCommonBuffer(
  17173. IN PDMA_ADAPTER DmaAdapter,
  17174. IN ULONG Length,
  17175. IN PHYSICAL_ADDRESS LogicalAddress,
  17176. IN PVOID VirtualAddress,
  17177. IN BOOLEAN CacheEnabled
  17178. ){
  17179. PFREE_COMMON_BUFFER freeCommonBuffer;
  17180. freeCommonBuffer = *(DmaAdapter)->DmaOperations->FreeCommonBuffer;
  17181. ASSERT( freeCommonBuffer != NULL );
  17182. freeCommonBuffer( DmaAdapter,
  17183. Length,
  17184. LogicalAddress,
  17185. VirtualAddress,
  17186. CacheEnabled );
  17187. }
  17188. DECLSPEC_DEPRECATED_DDK // Use AllocateAdapterChannel
  17189. FORCEINLINE
  17190. NTSTATUS
  17191. IoAllocateAdapterChannel(
  17192. IN PDMA_ADAPTER DmaAdapter,
  17193. IN PDEVICE_OBJECT DeviceObject,
  17194. IN ULONG NumberOfMapRegisters,
  17195. IN PDRIVER_CONTROL ExecutionRoutine,
  17196. IN PVOID Context
  17197. ){
  17198. PALLOCATE_ADAPTER_CHANNEL allocateAdapterChannel;
  17199. NTSTATUS status;
  17200. allocateAdapterChannel =
  17201. *(DmaAdapter)->DmaOperations->AllocateAdapterChannel;
  17202. ASSERT( allocateAdapterChannel != NULL );
  17203. status = allocateAdapterChannel( DmaAdapter,
  17204. DeviceObject,
  17205. NumberOfMapRegisters,
  17206. ExecutionRoutine,
  17207. Context );
  17208. return status;
  17209. }
  17210. DECLSPEC_DEPRECATED_DDK // Use FlushAdapterBuffers
  17211. FORCEINLINE
  17212. BOOLEAN
  17213. IoFlushAdapterBuffers(
  17214. IN PDMA_ADAPTER DmaAdapter,
  17215. IN PMDL Mdl,
  17216. IN PVOID MapRegisterBase,
  17217. IN PVOID CurrentVa,
  17218. IN ULONG Length,
  17219. IN BOOLEAN WriteToDevice
  17220. ){
  17221. PFLUSH_ADAPTER_BUFFERS flushAdapterBuffers;
  17222. BOOLEAN result;
  17223. flushAdapterBuffers = *(DmaAdapter)->DmaOperations->FlushAdapterBuffers;
  17224. ASSERT( flushAdapterBuffers != NULL );
  17225. result = flushAdapterBuffers( DmaAdapter,
  17226. Mdl,
  17227. MapRegisterBase,
  17228. CurrentVa,
  17229. Length,
  17230. WriteToDevice );
  17231. return result;
  17232. }
  17233. DECLSPEC_DEPRECATED_DDK // Use FreeAdapterChannel
  17234. FORCEINLINE
  17235. VOID
  17236. IoFreeAdapterChannel(
  17237. IN PDMA_ADAPTER DmaAdapter
  17238. ){
  17239. PFREE_ADAPTER_CHANNEL freeAdapterChannel;
  17240. freeAdapterChannel = *(DmaAdapter)->DmaOperations->FreeAdapterChannel;
  17241. ASSERT( freeAdapterChannel != NULL );
  17242. freeAdapterChannel( DmaAdapter );
  17243. }
  17244. DECLSPEC_DEPRECATED_DDK // Use FreeMapRegisters
  17245. FORCEINLINE
  17246. VOID
  17247. IoFreeMapRegisters(
  17248. IN PDMA_ADAPTER DmaAdapter,
  17249. IN PVOID MapRegisterBase,
  17250. IN ULONG NumberOfMapRegisters
  17251. ){
  17252. PFREE_MAP_REGISTERS freeMapRegisters;
  17253. freeMapRegisters = *(DmaAdapter)->DmaOperations->FreeMapRegisters;
  17254. ASSERT( freeMapRegisters != NULL );
  17255. freeMapRegisters( DmaAdapter,
  17256. MapRegisterBase,
  17257. NumberOfMapRegisters );
  17258. }
  17259. DECLSPEC_DEPRECATED_DDK // Use MapTransfer
  17260. FORCEINLINE
  17261. PHYSICAL_ADDRESS
  17262. IoMapTransfer(
  17263. IN PDMA_ADAPTER DmaAdapter,
  17264. IN PMDL Mdl,
  17265. IN PVOID MapRegisterBase,
  17266. IN PVOID CurrentVa,
  17267. IN OUT PULONG Length,
  17268. IN BOOLEAN WriteToDevice
  17269. ){
  17270. PHYSICAL_ADDRESS physicalAddress;
  17271. PMAP_TRANSFER mapTransfer;
  17272. mapTransfer = *(DmaAdapter)->DmaOperations->MapTransfer;
  17273. ASSERT( mapTransfer != NULL );
  17274. physicalAddress = mapTransfer( DmaAdapter,
  17275. Mdl,
  17276. MapRegisterBase,
  17277. CurrentVa,
  17278. Length,
  17279. WriteToDevice );
  17280. return physicalAddress;
  17281. }
  17282. DECLSPEC_DEPRECATED_DDK // Use GetDmaAlignment
  17283. FORCEINLINE
  17284. ULONG
  17285. HalGetDmaAlignment(
  17286. IN PDMA_ADAPTER DmaAdapter
  17287. )
  17288. {
  17289. PGET_DMA_ALIGNMENT getDmaAlignment;
  17290. ULONG alignment;
  17291. getDmaAlignment = *(DmaAdapter)->DmaOperations->GetDmaAlignment;
  17292. ASSERT( getDmaAlignment != NULL );
  17293. alignment = getDmaAlignment( DmaAdapter );
  17294. return alignment;
  17295. }
  17296. DECLSPEC_DEPRECATED_DDK // Use ReadDmaCounter
  17297. FORCEINLINE
  17298. ULONG
  17299. HalReadDmaCounter(
  17300. IN PDMA_ADAPTER DmaAdapter
  17301. )
  17302. {
  17303. PREAD_DMA_COUNTER readDmaCounter;
  17304. ULONG counter;
  17305. readDmaCounter = *(DmaAdapter)->DmaOperations->ReadDmaCounter;
  17306. ASSERT( readDmaCounter != NULL );
  17307. counter = readDmaCounter( DmaAdapter );
  17308. return counter;
  17309. }
  17310. // end_wdm
  17311. #else
  17312. //
  17313. // DMA adapter object functions.
  17314. //
  17315. NTHALAPI
  17316. NTSTATUS
  17317. HalAllocateAdapterChannel(
  17318. IN PADAPTER_OBJECT AdapterObject,
  17319. IN PWAIT_CONTEXT_BLOCK Wcb,
  17320. IN ULONG NumberOfMapRegisters,
  17321. IN PDRIVER_CONTROL ExecutionRoutine
  17322. );
  17323. DECLSPEC_DEPRECATED_DDK // Use AllocateCommonBuffer
  17324. NTHALAPI
  17325. PVOID
  17326. HalAllocateCommonBuffer(
  17327. IN PADAPTER_OBJECT AdapterObject,
  17328. IN ULONG Length,
  17329. OUT PPHYSICAL_ADDRESS LogicalAddress,
  17330. IN BOOLEAN CacheEnabled
  17331. );
  17332. DECLSPEC_DEPRECATED_DDK // Use FreeCommonBuffer
  17333. NTHALAPI
  17334. VOID
  17335. HalFreeCommonBuffer(
  17336. IN PADAPTER_OBJECT AdapterObject,
  17337. IN ULONG Length,
  17338. IN PHYSICAL_ADDRESS LogicalAddress,
  17339. IN PVOID VirtualAddress,
  17340. IN BOOLEAN CacheEnabled
  17341. );
  17342. DECLSPEC_DEPRECATED_DDK // Use ReadDmaCounter
  17343. NTHALAPI
  17344. ULONG
  17345. HalReadDmaCounter(
  17346. IN PADAPTER_OBJECT AdapterObject
  17347. );
  17348. DECLSPEC_DEPRECATED_DDK // Use FlushAdapterBuffers
  17349. NTHALAPI
  17350. BOOLEAN
  17351. IoFlushAdapterBuffers(
  17352. IN PADAPTER_OBJECT AdapterObject,
  17353. IN PMDL Mdl,
  17354. IN PVOID MapRegisterBase,
  17355. IN PVOID CurrentVa,
  17356. IN ULONG Length,
  17357. IN BOOLEAN WriteToDevice
  17358. );
  17359. DECLSPEC_DEPRECATED_DDK // Use FreeAdapterChannel
  17360. NTHALAPI
  17361. VOID
  17362. IoFreeAdapterChannel(
  17363. IN PADAPTER_OBJECT AdapterObject
  17364. );
  17365. DECLSPEC_DEPRECATED_DDK // Use FreeMapRegisters
  17366. NTHALAPI
  17367. VOID
  17368. IoFreeMapRegisters(
  17369. IN PADAPTER_OBJECT AdapterObject,
  17370. IN PVOID MapRegisterBase,
  17371. IN ULONG NumberOfMapRegisters
  17372. );
  17373. DECLSPEC_DEPRECATED_DDK // Use MapTransfer
  17374. NTHALAPI
  17375. PHYSICAL_ADDRESS
  17376. IoMapTransfer(
  17377. IN PADAPTER_OBJECT AdapterObject,
  17378. IN PMDL Mdl,
  17379. IN PVOID MapRegisterBase,
  17380. IN PVOID CurrentVa,
  17381. IN OUT PULONG Length,
  17382. IN BOOLEAN WriteToDevice
  17383. );
  17384. #endif // USE_DMA_MACROS && (_NTDDK_ || _NTDRIVER_)
  17385. NTSTATUS
  17386. HalGetScatterGatherList (
  17387. IN PADAPTER_OBJECT DmaAdapter,
  17388. IN PDEVICE_OBJECT DeviceObject,
  17389. IN PMDL Mdl,
  17390. IN PVOID CurrentVa,
  17391. IN ULONG Length,
  17392. IN PDRIVER_LIST_CONTROL ExecutionRoutine,
  17393. IN PVOID Context,
  17394. IN BOOLEAN WriteToDevice
  17395. );
  17396. VOID
  17397. HalPutScatterGatherList (
  17398. IN PADAPTER_OBJECT DmaAdapter,
  17399. IN PSCATTER_GATHER_LIST ScatterGather,
  17400. IN BOOLEAN WriteToDevice
  17401. );
  17402. VOID
  17403. HalPutDmaAdapter(
  17404. IN PADAPTER_OBJECT DmaAdapter
  17405. );
  17406. NTKERNELAPI
  17407. VOID
  17408. PoSetSystemState (
  17409. IN EXECUTION_STATE Flags
  17410. );
  17411. // begin_ntifs
  17412. NTKERNELAPI
  17413. PVOID
  17414. PoRegisterSystemState (
  17415. IN PVOID StateHandle,
  17416. IN EXECUTION_STATE Flags
  17417. );
  17418. // end_ntifs
  17419. typedef
  17420. VOID
  17421. (*PREQUEST_POWER_COMPLETE) (
  17422. IN PDEVICE_OBJECT DeviceObject,
  17423. IN UCHAR MinorFunction,
  17424. IN POWER_STATE PowerState,
  17425. IN PVOID Context,
  17426. IN PIO_STATUS_BLOCK IoStatus
  17427. );
  17428. NTKERNELAPI
  17429. NTSTATUS
  17430. PoRequestPowerIrp (
  17431. IN PDEVICE_OBJECT DeviceObject,
  17432. IN UCHAR MinorFunction,
  17433. IN POWER_STATE PowerState,
  17434. IN PREQUEST_POWER_COMPLETE CompletionFunction,
  17435. IN PVOID Context,
  17436. OUT PIRP *Irp OPTIONAL
  17437. );
  17438. NTKERNELAPI
  17439. NTSTATUS
  17440. PoRequestShutdownEvent (
  17441. OUT PVOID *Event
  17442. );
  17443. NTKERNELAPI
  17444. NTSTATUS
  17445. PoRequestShutdownWait (
  17446. IN PETHREAD Thread
  17447. );
  17448. // begin_ntifs
  17449. NTKERNELAPI
  17450. VOID
  17451. PoUnregisterSystemState (
  17452. IN PVOID StateHandle
  17453. );
  17454. // begin_nthal
  17455. NTKERNELAPI
  17456. POWER_STATE
  17457. PoSetPowerState (
  17458. IN PDEVICE_OBJECT DeviceObject,
  17459. IN POWER_STATE_TYPE Type,
  17460. IN POWER_STATE State
  17461. );
  17462. NTKERNELAPI
  17463. NTSTATUS
  17464. PoCallDriver (
  17465. IN PDEVICE_OBJECT DeviceObject,
  17466. IN OUT PIRP Irp
  17467. );
  17468. NTKERNELAPI
  17469. VOID
  17470. PoStartNextPowerIrp(
  17471. IN PIRP Irp
  17472. );
  17473. NTKERNELAPI
  17474. PULONG
  17475. PoRegisterDeviceForIdleDetection (
  17476. IN PDEVICE_OBJECT DeviceObject,
  17477. IN ULONG ConservationIdleTime,
  17478. IN ULONG PerformanceIdleTime,
  17479. IN DEVICE_POWER_STATE State
  17480. );
  17481. #define PoSetDeviceBusy(IdlePointer) \
  17482. *IdlePointer = 0
  17483. //
  17484. // \Callback\PowerState values
  17485. //
  17486. #define PO_CB_SYSTEM_POWER_POLICY 0
  17487. #define PO_CB_AC_STATUS 1
  17488. #define PO_CB_BUTTON_COLLISION 2
  17489. #define PO_CB_SYSTEM_STATE_LOCK 3
  17490. #define PO_CB_LID_SWITCH_STATE 4
  17491. #define PO_CB_PROCESSOR_POWER_POLICY 5
  17492. //
  17493. // Determine if there is a complete device failure on an error.
  17494. //
  17495. NTKERNELAPI
  17496. BOOLEAN
  17497. FsRtlIsTotalDeviceFailure(
  17498. IN NTSTATUS Status
  17499. );
  17500. //
  17501. // Object Manager types
  17502. //
  17503. typedef struct _OBJECT_HANDLE_INFORMATION {
  17504. ULONG HandleAttributes;
  17505. ACCESS_MASK GrantedAccess;
  17506. } OBJECT_HANDLE_INFORMATION, *POBJECT_HANDLE_INFORMATION;
  17507. NTKERNELAPI
  17508. NTSTATUS
  17509. ObReferenceObjectByHandle(
  17510. IN HANDLE Handle,
  17511. IN ACCESS_MASK DesiredAccess,
  17512. IN POBJECT_TYPE ObjectType OPTIONAL,
  17513. IN KPROCESSOR_MODE AccessMode,
  17514. OUT PVOID *Object,
  17515. OUT POBJECT_HANDLE_INFORMATION HandleInformation OPTIONAL
  17516. );
  17517. #define ObDereferenceObject(a) \
  17518. ObfDereferenceObject(a)
  17519. #define ObReferenceObject(Object) ObfReferenceObject(Object)
  17520. NTKERNELAPI
  17521. LONG
  17522. FASTCALL
  17523. ObfReferenceObject(
  17524. IN PVOID Object
  17525. );
  17526. NTKERNELAPI
  17527. NTSTATUS
  17528. ObReferenceObjectByPointer(
  17529. IN PVOID Object,
  17530. IN ACCESS_MASK DesiredAccess,
  17531. IN POBJECT_TYPE ObjectType,
  17532. IN KPROCESSOR_MODE AccessMode
  17533. );
  17534. NTKERNELAPI
  17535. LONG
  17536. FASTCALL
  17537. ObfDereferenceObject(
  17538. IN PVOID Object
  17539. );
  17540. NTSTATUS
  17541. ObGetObjectSecurity(
  17542. IN PVOID Object,
  17543. OUT PSECURITY_DESCRIPTOR *SecurityDescriptor,
  17544. OUT PBOOLEAN MemoryAllocated
  17545. );
  17546. VOID
  17547. ObReleaseObjectSecurity(
  17548. IN PSECURITY_DESCRIPTOR SecurityDescriptor,
  17549. IN BOOLEAN MemoryAllocated
  17550. );
  17551. //
  17552. // A PCI driver can read the complete 256 bytes of configuration
  17553. // information for any PCI device by calling:
  17554. //
  17555. // ULONG
  17556. // HalGetBusData (
  17557. // IN BUS_DATA_TYPE PCIConfiguration,
  17558. // IN ULONG PciBusNumber,
  17559. // IN PCI_SLOT_NUMBER VirtualSlotNumber,
  17560. // IN PPCI_COMMON_CONFIG &PCIDeviceConfig,
  17561. // IN ULONG sizeof (PCIDeviceConfig)
  17562. // );
  17563. //
  17564. // A return value of 0 means that the specified PCI bus does not exist.
  17565. //
  17566. // A return value of 2, with a VendorID of PCI_INVALID_VENDORID means
  17567. // that the PCI bus does exist, but there is no device at the specified
  17568. // VirtualSlotNumber (PCI Device/Function number).
  17569. //
  17570. //
  17571. // begin_wdm begin_ntminiport begin_ntndis
  17572. typedef struct _PCI_SLOT_NUMBER {
  17573. union {
  17574. struct {
  17575. ULONG DeviceNumber:5;
  17576. ULONG FunctionNumber:3;
  17577. ULONG Reserved:24;
  17578. } bits;
  17579. ULONG AsULONG;
  17580. } u;
  17581. } PCI_SLOT_NUMBER, *PPCI_SLOT_NUMBER;
  17582. #define PCI_TYPE0_ADDRESSES 6
  17583. #define PCI_TYPE1_ADDRESSES 2
  17584. #define PCI_TYPE2_ADDRESSES 5
  17585. typedef struct _PCI_COMMON_CONFIG {
  17586. USHORT VendorID; // (ro)
  17587. USHORT DeviceID; // (ro)
  17588. USHORT Command; // Device control
  17589. USHORT Status;
  17590. UCHAR RevisionID; // (ro)
  17591. UCHAR ProgIf; // (ro)
  17592. UCHAR SubClass; // (ro)
  17593. UCHAR BaseClass; // (ro)
  17594. UCHAR CacheLineSize; // (ro+)
  17595. UCHAR LatencyTimer; // (ro+)
  17596. UCHAR HeaderType; // (ro)
  17597. UCHAR BIST; // Built in self test
  17598. union {
  17599. struct _PCI_HEADER_TYPE_0 {
  17600. ULONG BaseAddresses[PCI_TYPE0_ADDRESSES];
  17601. ULONG CIS;
  17602. USHORT SubVendorID;
  17603. USHORT SubSystemID;
  17604. ULONG ROMBaseAddress;
  17605. UCHAR CapabilitiesPtr;
  17606. UCHAR Reserved1[3];
  17607. ULONG Reserved2;
  17608. UCHAR InterruptLine; //
  17609. UCHAR InterruptPin; // (ro)
  17610. UCHAR MinimumGrant; // (ro)
  17611. UCHAR MaximumLatency; // (ro)
  17612. } type0;
  17613. // end_wdm end_ntminiport end_ntndis
  17614. //
  17615. // PCI to PCI Bridge
  17616. //
  17617. struct _PCI_HEADER_TYPE_1 {
  17618. ULONG BaseAddresses[PCI_TYPE1_ADDRESSES];
  17619. UCHAR PrimaryBus;
  17620. UCHAR SecondaryBus;
  17621. UCHAR SubordinateBus;
  17622. UCHAR SecondaryLatency;
  17623. UCHAR IOBase;
  17624. UCHAR IOLimit;
  17625. USHORT SecondaryStatus;
  17626. USHORT MemoryBase;
  17627. USHORT MemoryLimit;
  17628. USHORT PrefetchBase;
  17629. USHORT PrefetchLimit;
  17630. ULONG PrefetchBaseUpper32;
  17631. ULONG PrefetchLimitUpper32;
  17632. USHORT IOBaseUpper16;
  17633. USHORT IOLimitUpper16;
  17634. UCHAR CapabilitiesPtr;
  17635. UCHAR Reserved1[3];
  17636. ULONG ROMBaseAddress;
  17637. UCHAR InterruptLine;
  17638. UCHAR InterruptPin;
  17639. USHORT BridgeControl;
  17640. } type1;
  17641. //
  17642. // PCI to CARDBUS Bridge
  17643. //
  17644. struct _PCI_HEADER_TYPE_2 {
  17645. ULONG SocketRegistersBaseAddress;
  17646. UCHAR CapabilitiesPtr;
  17647. UCHAR Reserved;
  17648. USHORT SecondaryStatus;
  17649. UCHAR PrimaryBus;
  17650. UCHAR SecondaryBus;
  17651. UCHAR SubordinateBus;
  17652. UCHAR SecondaryLatency;
  17653. struct {
  17654. ULONG Base;
  17655. ULONG Limit;
  17656. } Range[PCI_TYPE2_ADDRESSES-1];
  17657. UCHAR InterruptLine;
  17658. UCHAR InterruptPin;
  17659. USHORT BridgeControl;
  17660. } type2;
  17661. // begin_wdm begin_ntminiport begin_ntndis
  17662. } u;
  17663. UCHAR DeviceSpecific[192];
  17664. } PCI_COMMON_CONFIG, *PPCI_COMMON_CONFIG;
  17665. #define PCI_COMMON_HDR_LENGTH (FIELD_OFFSET (PCI_COMMON_CONFIG, DeviceSpecific))
  17666. #define PCI_MAX_DEVICES 32
  17667. #define PCI_MAX_FUNCTION 8
  17668. #define PCI_MAX_BRIDGE_NUMBER 0xFF
  17669. #define PCI_INVALID_VENDORID 0xFFFF
  17670. //
  17671. // Bit encodings for PCI_COMMON_CONFIG.HeaderType
  17672. //
  17673. #define PCI_MULTIFUNCTION 0x80
  17674. #define PCI_DEVICE_TYPE 0x00
  17675. #define PCI_BRIDGE_TYPE 0x01
  17676. #define PCI_CARDBUS_BRIDGE_TYPE 0x02
  17677. #define PCI_CONFIGURATION_TYPE(PciData) \
  17678. (((PPCI_COMMON_CONFIG)(PciData))->HeaderType & ~PCI_MULTIFUNCTION)
  17679. #define PCI_MULTIFUNCTION_DEVICE(PciData) \
  17680. ((((PPCI_COMMON_CONFIG)(PciData))->HeaderType & PCI_MULTIFUNCTION) != 0)
  17681. //
  17682. // Bit encodings for PCI_COMMON_CONFIG.Command
  17683. //
  17684. #define PCI_ENABLE_IO_SPACE 0x0001
  17685. #define PCI_ENABLE_MEMORY_SPACE 0x0002
  17686. #define PCI_ENABLE_BUS_MASTER 0x0004
  17687. #define PCI_ENABLE_SPECIAL_CYCLES 0x0008
  17688. #define PCI_ENABLE_WRITE_AND_INVALIDATE 0x0010
  17689. #define PCI_ENABLE_VGA_COMPATIBLE_PALETTE 0x0020
  17690. #define PCI_ENABLE_PARITY 0x0040 // (ro+)
  17691. #define PCI_ENABLE_WAIT_CYCLE 0x0080 // (ro+)
  17692. #define PCI_ENABLE_SERR 0x0100 // (ro+)
  17693. #define PCI_ENABLE_FAST_BACK_TO_BACK 0x0200 // (ro)
  17694. //
  17695. // Bit encodings for PCI_COMMON_CONFIG.Status
  17696. //
  17697. #define PCI_STATUS_CAPABILITIES_LIST 0x0010 // (ro)
  17698. #define PCI_STATUS_66MHZ_CAPABLE 0x0020 // (ro)
  17699. #define PCI_STATUS_UDF_SUPPORTED 0x0040 // (ro)
  17700. #define PCI_STATUS_FAST_BACK_TO_BACK 0x0080 // (ro)
  17701. #define PCI_STATUS_DATA_PARITY_DETECTED 0x0100
  17702. #define PCI_STATUS_DEVSEL 0x0600 // 2 bits wide
  17703. #define PCI_STATUS_SIGNALED_TARGET_ABORT 0x0800
  17704. #define PCI_STATUS_RECEIVED_TARGET_ABORT 0x1000
  17705. #define PCI_STATUS_RECEIVED_MASTER_ABORT 0x2000
  17706. #define PCI_STATUS_SIGNALED_SYSTEM_ERROR 0x4000
  17707. #define PCI_STATUS_DETECTED_PARITY_ERROR 0x8000
  17708. //
  17709. // The NT PCI Driver uses a WhichSpace parameter on its CONFIG_READ/WRITE
  17710. // routines. The following values are defined-
  17711. //
  17712. #define PCI_WHICHSPACE_CONFIG 0x0
  17713. #define PCI_WHICHSPACE_ROM 0x52696350
  17714. // end_wdm
  17715. //
  17716. // PCI Capability IDs
  17717. //
  17718. #define PCI_CAPABILITY_ID_POWER_MANAGEMENT 0x01
  17719. #define PCI_CAPABILITY_ID_AGP 0x02
  17720. #define PCI_CAPABILITY_ID_MSI 0x05
  17721. //
  17722. // All PCI Capability structures have the following header.
  17723. //
  17724. // CapabilityID is used to identify the type of the structure (is
  17725. // one of the PCI_CAPABILITY_ID values above.
  17726. //
  17727. // Next is the offset in PCI Configuration space (0x40 - 0xfc) of the
  17728. // next capability structure in the list, or 0x00 if there are no more
  17729. // entries.
  17730. //
  17731. typedef struct _PCI_CAPABILITIES_HEADER {
  17732. UCHAR CapabilityID;
  17733. UCHAR Next;
  17734. } PCI_CAPABILITIES_HEADER, *PPCI_CAPABILITIES_HEADER;
  17735. //
  17736. // Power Management Capability
  17737. //
  17738. typedef struct _PCI_PMC {
  17739. UCHAR Version:3;
  17740. UCHAR PMEClock:1;
  17741. UCHAR Rsvd1:1;
  17742. UCHAR DeviceSpecificInitialization:1;
  17743. UCHAR Rsvd2:2;
  17744. struct _PM_SUPPORT {
  17745. UCHAR Rsvd2:1;
  17746. UCHAR D1:1;
  17747. UCHAR D2:1;
  17748. UCHAR PMED0:1;
  17749. UCHAR PMED1:1;
  17750. UCHAR PMED2:1;
  17751. UCHAR PMED3Hot:1;
  17752. UCHAR PMED3Cold:1;
  17753. } Support;
  17754. } PCI_PMC, *PPCI_PMC;
  17755. typedef struct _PCI_PMCSR {
  17756. USHORT PowerState:2;
  17757. USHORT Rsvd1:6;
  17758. USHORT PMEEnable:1;
  17759. USHORT DataSelect:4;
  17760. USHORT DataScale:2;
  17761. USHORT PMEStatus:1;
  17762. } PCI_PMCSR, *PPCI_PMCSR;
  17763. typedef struct _PCI_PMCSR_BSE {
  17764. UCHAR Rsvd1:6;
  17765. UCHAR D3HotSupportsStopClock:1; // B2_B3#
  17766. UCHAR BusPowerClockControlEnabled:1; // BPCC_EN
  17767. } PCI_PMCSR_BSE, *PPCI_PMCSR_BSE;
  17768. typedef struct _PCI_PM_CAPABILITY {
  17769. PCI_CAPABILITIES_HEADER Header;
  17770. //
  17771. // Power Management Capabilities (Offset = 2)
  17772. //
  17773. union {
  17774. PCI_PMC Capabilities;
  17775. USHORT AsUSHORT;
  17776. } PMC;
  17777. //
  17778. // Power Management Control/Status (Offset = 4)
  17779. //
  17780. union {
  17781. PCI_PMCSR ControlStatus;
  17782. USHORT AsUSHORT;
  17783. } PMCSR;
  17784. //
  17785. // PMCSR PCI-PCI Bridge Support Extensions
  17786. //
  17787. union {
  17788. PCI_PMCSR_BSE BridgeSupport;
  17789. UCHAR AsUCHAR;
  17790. } PMCSR_BSE;
  17791. //
  17792. // Optional read only 8 bit Data register. Contents controlled by
  17793. // DataSelect and DataScale in ControlStatus.
  17794. //
  17795. UCHAR Data;
  17796. } PCI_PM_CAPABILITY, *PPCI_PM_CAPABILITY;
  17797. //
  17798. // AGP Capability
  17799. //
  17800. typedef struct _PCI_AGP_CAPABILITY {
  17801. PCI_CAPABILITIES_HEADER Header;
  17802. USHORT Minor:4;
  17803. USHORT Major:4;
  17804. USHORT Rsvd1:8;
  17805. struct _PCI_AGP_STATUS {
  17806. ULONG Rate:3;
  17807. ULONG Rsvd1:1;
  17808. ULONG FastWrite:1;
  17809. ULONG FourGB:1;
  17810. ULONG Rsvd2:3;
  17811. ULONG SideBandAddressing:1; // SBA
  17812. ULONG Rsvd3:14;
  17813. ULONG RequestQueueDepthMaximum:8; // RQ
  17814. } AGPStatus;
  17815. struct _PCI_AGP_COMMAND {
  17816. ULONG Rate:3;
  17817. ULONG Rsvd1:1;
  17818. ULONG FastWriteEnable:1;
  17819. ULONG FourGBEnable:1;
  17820. ULONG Rsvd2:2;
  17821. ULONG AGPEnable:1;
  17822. ULONG SBAEnable:1;
  17823. ULONG Rsvd3:14;
  17824. ULONG RequestQueueDepth:8;
  17825. } AGPCommand;
  17826. } PCI_AGP_CAPABILITY, *PPCI_AGP_CAPABILITY;
  17827. #define PCI_AGP_RATE_1X 0x1
  17828. #define PCI_AGP_RATE_2X 0x2
  17829. #define PCI_AGP_RATE_4X 0x4
  17830. //
  17831. // MSI (Message Signalled Interrupts) Capability
  17832. //
  17833. typedef struct _PCI_MSI_CAPABILITY {
  17834. PCI_CAPABILITIES_HEADER Header;
  17835. struct _PCI_MSI_MESSAGE_CONTROL {
  17836. USHORT MSIEnable:1;
  17837. USHORT MultipleMessageCapable:3;
  17838. USHORT MultipleMessageEnable:3;
  17839. USHORT CapableOf64Bits:1;
  17840. USHORT Reserved:8;
  17841. } MessageControl;
  17842. union {
  17843. struct _PCI_MSI_MESSAGE_ADDRESS {
  17844. ULONG_PTR Reserved:2; // always zero, DWORD aligned address
  17845. ULONG_PTR Address:30;
  17846. } Register;
  17847. ULONG_PTR Raw;
  17848. } MessageAddress;
  17849. //
  17850. // The rest of the Capability structure differs depending on whether
  17851. // 32bit or 64bit addressing is being used.
  17852. //
  17853. // (The CapableOf64Bits bit above determines this)
  17854. //
  17855. union {
  17856. // For 64 bit devices
  17857. struct _PCI_MSI_64BIT_DATA {
  17858. ULONG MessageUpperAddress;
  17859. USHORT MessageData;
  17860. } Bit64;
  17861. // For 32 bit devices
  17862. struct _PCI_MSI_32BIT_DATA {
  17863. USHORT MessageData;
  17864. ULONG Unused;
  17865. } Bit32;
  17866. } Data;
  17867. } PCI_MSI_CAPABILITY, *PPCI_PCI_CAPABILITY;
  17868. // begin_wdm
  17869. //
  17870. // Base Class Code encodings for Base Class (from PCI spec rev 2.1).
  17871. //
  17872. #define PCI_CLASS_PRE_20 0x00
  17873. #define PCI_CLASS_MASS_STORAGE_CTLR 0x01
  17874. #define PCI_CLASS_NETWORK_CTLR 0x02
  17875. #define PCI_CLASS_DISPLAY_CTLR 0x03
  17876. #define PCI_CLASS_MULTIMEDIA_DEV 0x04
  17877. #define PCI_CLASS_MEMORY_CTLR 0x05
  17878. #define PCI_CLASS_BRIDGE_DEV 0x06
  17879. #define PCI_CLASS_SIMPLE_COMMS_CTLR 0x07
  17880. #define PCI_CLASS_BASE_SYSTEM_DEV 0x08
  17881. #define PCI_CLASS_INPUT_DEV 0x09
  17882. #define PCI_CLASS_DOCKING_STATION 0x0a
  17883. #define PCI_CLASS_PROCESSOR 0x0b
  17884. #define PCI_CLASS_SERIAL_BUS_CTLR 0x0c
  17885. #define PCI_CLASS_WIRELESS_CTLR 0x0d
  17886. #define PCI_CLASS_INTELLIGENT_IO_CTLR 0x0e
  17887. #define PCI_CLASS_SATELLITE_COMMS_CTLR 0x0f
  17888. #define PCI_CLASS_ENCRYPTION_DECRYPTION 0x10
  17889. #define PCI_CLASS_DATA_ACQ_SIGNAL_PROC 0x11
  17890. // 0d thru fe reserved
  17891. #define PCI_CLASS_NOT_DEFINED 0xff
  17892. //
  17893. // Sub Class Code encodings (PCI rev 2.1).
  17894. //
  17895. // Class 00 - PCI_CLASS_PRE_20
  17896. #define PCI_SUBCLASS_PRE_20_NON_VGA 0x00
  17897. #define PCI_SUBCLASS_PRE_20_VGA 0x01
  17898. // Class 01 - PCI_CLASS_MASS_STORAGE_CTLR
  17899. #define PCI_SUBCLASS_MSC_SCSI_BUS_CTLR 0x00
  17900. #define PCI_SUBCLASS_MSC_IDE_CTLR 0x01
  17901. #define PCI_SUBCLASS_MSC_FLOPPY_CTLR 0x02
  17902. #define PCI_SUBCLASS_MSC_IPI_CTLR 0x03
  17903. #define PCI_SUBCLASS_MSC_RAID_CTLR 0x04
  17904. #define PCI_SUBCLASS_MSC_OTHER 0x80
  17905. // Class 02 - PCI_CLASS_NETWORK_CTLR
  17906. #define PCI_SUBCLASS_NET_ETHERNET_CTLR 0x00
  17907. #define PCI_SUBCLASS_NET_TOKEN_RING_CTLR 0x01
  17908. #define PCI_SUBCLASS_NET_FDDI_CTLR 0x02
  17909. #define PCI_SUBCLASS_NET_ATM_CTLR 0x03
  17910. #define PCI_SUBCLASS_NET_ISDN_CTLR 0x04
  17911. #define PCI_SUBCLASS_NET_OTHER 0x80
  17912. // Class 03 - PCI_CLASS_DISPLAY_CTLR
  17913. // N.B. Sub Class 00 could be VGA or 8514 depending on Interface byte
  17914. #define PCI_SUBCLASS_VID_VGA_CTLR 0x00
  17915. #define PCI_SUBCLASS_VID_XGA_CTLR 0x01
  17916. #define PCI_SUBLCASS_VID_3D_CTLR 0x02
  17917. #define PCI_SUBCLASS_VID_OTHER 0x80
  17918. // Class 04 - PCI_CLASS_MULTIMEDIA_DEV
  17919. #define PCI_SUBCLASS_MM_VIDEO_DEV 0x00
  17920. #define PCI_SUBCLASS_MM_AUDIO_DEV 0x01
  17921. #define PCI_SUBCLASS_MM_TELEPHONY_DEV 0x02
  17922. #define PCI_SUBCLASS_MM_OTHER 0x80
  17923. // Class 05 - PCI_CLASS_MEMORY_CTLR
  17924. #define PCI_SUBCLASS_MEM_RAM 0x00
  17925. #define PCI_SUBCLASS_MEM_FLASH 0x01
  17926. #define PCI_SUBCLASS_MEM_OTHER 0x80
  17927. // Class 06 - PCI_CLASS_BRIDGE_DEV
  17928. #define PCI_SUBCLASS_BR_HOST 0x00
  17929. #define PCI_SUBCLASS_BR_ISA 0x01
  17930. #define PCI_SUBCLASS_BR_EISA 0x02
  17931. #define PCI_SUBCLASS_BR_MCA 0x03
  17932. #define PCI_SUBCLASS_BR_PCI_TO_PCI 0x04
  17933. #define PCI_SUBCLASS_BR_PCMCIA 0x05
  17934. #define PCI_SUBCLASS_BR_NUBUS 0x06
  17935. #define PCI_SUBCLASS_BR_CARDBUS 0x07
  17936. #define PCI_SUBCLASS_BR_RACEWAY 0x08
  17937. #define PCI_SUBCLASS_BR_OTHER 0x80
  17938. // Class 07 - PCI_CLASS_SIMPLE_COMMS_CTLR
  17939. // N.B. Sub Class 00 and 01 additional info in Interface byte
  17940. #define PCI_SUBCLASS_COM_SERIAL 0x00
  17941. #define PCI_SUBCLASS_COM_PARALLEL 0x01
  17942. #define PCI_SUBCLASS_COM_MULTIPORT 0x02
  17943. #define PCI_SUBCLASS_COM_MODEM 0x03
  17944. #define PCI_SUBCLASS_COM_OTHER 0x80
  17945. // Class 08 - PCI_CLASS_BASE_SYSTEM_DEV
  17946. // N.B. See Interface byte for additional info.
  17947. #define PCI_SUBCLASS_SYS_INTERRUPT_CTLR 0x00
  17948. #define PCI_SUBCLASS_SYS_DMA_CTLR 0x01
  17949. #define PCI_SUBCLASS_SYS_SYSTEM_TIMER 0x02
  17950. #define PCI_SUBCLASS_SYS_REAL_TIME_CLOCK 0x03
  17951. #define PCI_SUBCLASS_SYS_GEN_HOTPLUG_CTLR 0x04
  17952. #define PCI_SUBCLASS_SYS_OTHER 0x80
  17953. // Class 09 - PCI_CLASS_INPUT_DEV
  17954. #define PCI_SUBCLASS_INP_KEYBOARD 0x00
  17955. #define PCI_SUBCLASS_INP_DIGITIZER 0x01
  17956. #define PCI_SUBCLASS_INP_MOUSE 0x02
  17957. #define PCI_SUBCLASS_INP_SCANNER 0x03
  17958. #define PCI_SUBCLASS_INP_GAMEPORT 0x04
  17959. #define PCI_SUBCLASS_INP_OTHER 0x80
  17960. // Class 0a - PCI_CLASS_DOCKING_STATION
  17961. #define PCI_SUBCLASS_DOC_GENERIC 0x00
  17962. #define PCI_SUBCLASS_DOC_OTHER 0x80
  17963. // Class 0b - PCI_CLASS_PROCESSOR
  17964. #define PCI_SUBCLASS_PROC_386 0x00
  17965. #define PCI_SUBCLASS_PROC_486 0x01
  17966. #define PCI_SUBCLASS_PROC_PENTIUM 0x02
  17967. #define PCI_SUBCLASS_PROC_ALPHA 0x10
  17968. #define PCI_SUBCLASS_PROC_POWERPC 0x20
  17969. #define PCI_SUBCLASS_PROC_COPROCESSOR 0x40
  17970. // Class 0c - PCI_CLASS_SERIAL_BUS_CTLR
  17971. #define PCI_SUBCLASS_SB_IEEE1394 0x00
  17972. #define PCI_SUBCLASS_SB_ACCESS 0x01
  17973. #define PCI_SUBCLASS_SB_SSA 0x02
  17974. #define PCI_SUBCLASS_SB_USB 0x03
  17975. #define PCI_SUBCLASS_SB_FIBRE_CHANNEL 0x04
  17976. #define PCI_SUBCLASS_SB_SMBUS 0x05
  17977. // Class 0d - PCI_CLASS_WIRELESS_CTLR
  17978. #define PCI_SUBCLASS_WIRELESS_IRDA 0x00
  17979. #define PCI_SUBCLASS_WIRELESS_CON_IR 0x01
  17980. #define PCI_SUBCLASS_WIRELESS_RF 0x10
  17981. #define PCI_SUBCLASS_WIRELESS_OTHER 0x80
  17982. // Class 0e - PCI_CLASS_INTELLIGENT_IO_CTLR
  17983. #define PCI_SUBCLASS_INTIO_I2O 0x00
  17984. // Class 0f - PCI_CLASS_SATELLITE_CTLR
  17985. #define PCI_SUBCLASS_SAT_TV 0x01
  17986. #define PCI_SUBCLASS_SAT_AUDIO 0x02
  17987. #define PCI_SUBCLASS_SAT_VOICE 0x03
  17988. #define PCI_SUBCLASS_SAT_DATA 0x04
  17989. // Class 10 - PCI_CLASS_ENCRYPTION_DECRYPTION
  17990. #define PCI_SUBCLASS_CRYPTO_NET_COMP 0x00
  17991. #define PCI_SUBCLASS_CRYPTO_ENTERTAINMENT 0x10
  17992. #define PCI_SUBCLASS_CRYPTO_OTHER 0x80
  17993. // Class 11 - PCI_CLASS_DATA_ACQ_SIGNAL_PROC
  17994. #define PCI_SUBCLASS_DASP_DPIO 0x00
  17995. #define PCI_SUBCLASS_DASP_OTHER 0x80
  17996. // end_ntndis
  17997. //
  17998. // Bit encodes for PCI_COMMON_CONFIG.u.type0.BaseAddresses
  17999. //
  18000. #define PCI_ADDRESS_IO_SPACE 0x00000001 // (ro)
  18001. #define PCI_ADDRESS_MEMORY_TYPE_MASK 0x00000006 // (ro)
  18002. #define PCI_ADDRESS_MEMORY_PREFETCHABLE 0x00000008 // (ro)
  18003. #define PCI_ADDRESS_IO_ADDRESS_MASK 0xfffffffc
  18004. #define PCI_ADDRESS_MEMORY_ADDRESS_MASK 0xfffffff0
  18005. #define PCI_ADDRESS_ROM_ADDRESS_MASK 0xfffff800
  18006. #define PCI_TYPE_32BIT 0
  18007. #define PCI_TYPE_20BIT 2
  18008. #define PCI_TYPE_64BIT 4
  18009. //
  18010. // Bit encodes for PCI_COMMON_CONFIG.u.type0.ROMBaseAddresses
  18011. //
  18012. #define PCI_ROMADDRESS_ENABLED 0x00000001
  18013. //
  18014. // Reference notes for PCI configuration fields:
  18015. //
  18016. // ro these field are read only. changes to these fields are ignored
  18017. //
  18018. // ro+ these field are intended to be read only and should be initialized
  18019. // by the system to their proper values. However, driver may change
  18020. // these settings.
  18021. //
  18022. // ---
  18023. //
  18024. // All resources comsumed by a PCI device start as unitialized
  18025. // under NT. An uninitialized memory or I/O base address can be
  18026. // determined by checking it's corrisponding enabled bit in the
  18027. // PCI_COMMON_CONFIG.Command value. An InterruptLine is unitialized
  18028. // if it contains the value of -1.
  18029. //
  18030. // end_wdm end_ntminiport
  18031. //
  18032. // Portable portion of HAL & HAL bus extender definitions for BUSHANDLER
  18033. // BusData for installed PCI buses.
  18034. //
  18035. typedef VOID
  18036. (*PciPin2Line) (
  18037. IN struct _BUS_HANDLER *BusHandler,
  18038. IN struct _BUS_HANDLER *RootHandler,
  18039. IN PCI_SLOT_NUMBER SlotNumber,
  18040. IN PPCI_COMMON_CONFIG PciData
  18041. );
  18042. typedef VOID
  18043. (*PciLine2Pin) (
  18044. IN struct _BUS_HANDLER *BusHandler,
  18045. IN struct _BUS_HANDLER *RootHandler,
  18046. IN PCI_SLOT_NUMBER SlotNumber,
  18047. IN PPCI_COMMON_CONFIG PciNewData,
  18048. IN PPCI_COMMON_CONFIG PciOldData
  18049. );
  18050. typedef VOID
  18051. (*PciReadWriteConfig) (
  18052. IN struct _BUS_HANDLER *BusHandler,
  18053. IN PCI_SLOT_NUMBER Slot,
  18054. IN PVOID Buffer,
  18055. IN ULONG Offset,
  18056. IN ULONG Length
  18057. );
  18058. #define PCI_DATA_TAG ' ICP'
  18059. #define PCI_DATA_VERSION 1
  18060. typedef struct _PCIBUSDATA {
  18061. ULONG Tag;
  18062. ULONG Version;
  18063. PciReadWriteConfig ReadConfig;
  18064. PciReadWriteConfig WriteConfig;
  18065. PciPin2Line Pin2Line;
  18066. PciLine2Pin Line2Pin;
  18067. PCI_SLOT_NUMBER ParentSlot;
  18068. PVOID Reserved[4];
  18069. } PCIBUSDATA, *PPCIBUSDATA;
  18070. typedef ULONG (*PCI_READ_WRITE_CONFIG)(
  18071. IN PVOID Context,
  18072. IN UCHAR BusOffset,
  18073. IN ULONG Slot,
  18074. IN PVOID Buffer,
  18075. IN ULONG Offset,
  18076. IN ULONG Length
  18077. );
  18078. typedef VOID (*PCI_PIN_TO_LINE)(
  18079. IN PVOID Context,
  18080. IN PPCI_COMMON_CONFIG PciData
  18081. );
  18082. typedef VOID (*PCI_LINE_TO_PIN)(
  18083. IN PVOID Context,
  18084. IN PPCI_COMMON_CONFIG PciNewData,
  18085. IN PPCI_COMMON_CONFIG PciOldData
  18086. );
  18087. typedef struct _PCI_BUS_INTERFACE_STANDARD {
  18088. //
  18089. // generic interface header
  18090. //
  18091. USHORT Size;
  18092. USHORT Version;
  18093. PVOID Context;
  18094. PINTERFACE_REFERENCE InterfaceReference;
  18095. PINTERFACE_DEREFERENCE InterfaceDereference;
  18096. //
  18097. // standard PCI bus interfaces
  18098. //
  18099. PCI_READ_WRITE_CONFIG ReadConfig;
  18100. PCI_READ_WRITE_CONFIG WriteConfig;
  18101. PCI_PIN_TO_LINE PinToLine;
  18102. PCI_LINE_TO_PIN LineToPin;
  18103. } PCI_BUS_INTERFACE_STANDARD, *PPCI_BUS_INTERFACE_STANDARD;
  18104. #define PCI_BUS_INTERFACE_STANDARD_VERSION 1
  18105. // begin_wdm
  18106. #define PCI_DEVICE_PRESENT_INTERFACE_VERSION 1
  18107. //
  18108. // Flags for PCI_DEVICE_PRESENCE_PARAMETERS
  18109. //
  18110. #define PCI_USE_SUBSYSTEM_IDS 0x00000001
  18111. #define PCI_USE_REVISION 0x00000002
  18112. // The following flags are only valid for IsDevicePresentEx
  18113. #define PCI_USE_VENDEV_IDS 0x00000004
  18114. #define PCI_USE_CLASS_SUBCLASS 0x00000008
  18115. #define PCI_USE_PROGIF 0x00000010
  18116. #define PCI_USE_LOCAL_BUS 0x00000020
  18117. #define PCI_USE_LOCAL_DEVICE 0x00000040
  18118. //
  18119. // Search parameters structure for IsDevicePresentEx
  18120. //
  18121. typedef struct _PCI_DEVICE_PRESENCE_PARAMETERS {
  18122. ULONG Size;
  18123. ULONG Flags;
  18124. USHORT VendorID;
  18125. USHORT DeviceID;
  18126. UCHAR RevisionID;
  18127. USHORT SubVendorID;
  18128. USHORT SubSystemID;
  18129. UCHAR BaseClass;
  18130. UCHAR SubClass;
  18131. UCHAR ProgIf;
  18132. } PCI_DEVICE_PRESENCE_PARAMETERS, *PPCI_DEVICE_PRESENCE_PARAMETERS;
  18133. typedef
  18134. BOOLEAN
  18135. (*PPCI_IS_DEVICE_PRESENT) (
  18136. IN USHORT VendorID,
  18137. IN USHORT DeviceID,
  18138. IN UCHAR RevisionID,
  18139. IN USHORT SubVendorID,
  18140. IN USHORT SubSystemID,
  18141. IN ULONG Flags
  18142. );
  18143. typedef
  18144. BOOLEAN
  18145. (*PPCI_IS_DEVICE_PRESENT_EX) (
  18146. IN PVOID Context,
  18147. IN PPCI_DEVICE_PRESENCE_PARAMETERS Parameters
  18148. );
  18149. typedef struct _PCI_DEVICE_PRESENT_INTERFACE {
  18150. //
  18151. // generic interface header
  18152. //
  18153. USHORT Size;
  18154. USHORT Version;
  18155. PVOID Context;
  18156. PINTERFACE_REFERENCE InterfaceReference;
  18157. PINTERFACE_DEREFERENCE InterfaceDereference;
  18158. //
  18159. // pci device info
  18160. //
  18161. PPCI_IS_DEVICE_PRESENT IsDevicePresent;
  18162. PPCI_IS_DEVICE_PRESENT_EX IsDevicePresentEx;
  18163. } PCI_DEVICE_PRESENT_INTERFACE, *PPCI_DEVICE_PRESENT_INTERFACE;
  18164. #ifdef POOL_TAGGING
  18165. #define ExAllocatePool(a,b) ExAllocatePoolWithTag(a,b,' kdD')
  18166. #define ExAllocatePoolWithQuota(a,b) ExAllocatePoolWithQuotaTag(a,b,' kdD')
  18167. #endif
  18168. extern POBJECT_TYPE *IoFileObjectType;
  18169. extern POBJECT_TYPE *ExEventObjectType;
  18170. extern POBJECT_TYPE *ExSemaphoreObjectType;
  18171. //
  18172. // Define exported ZwXxx routines to device drivers.
  18173. //
  18174. NTSYSAPI
  18175. NTSTATUS
  18176. NTAPI
  18177. ZwCreateFile(
  18178. OUT PHANDLE FileHandle,
  18179. IN ACCESS_MASK DesiredAccess,
  18180. IN POBJECT_ATTRIBUTES ObjectAttributes,
  18181. OUT PIO_STATUS_BLOCK IoStatusBlock,
  18182. IN PLARGE_INTEGER AllocationSize OPTIONAL,
  18183. IN ULONG FileAttributes,
  18184. IN ULONG ShareAccess,
  18185. IN ULONG CreateDisposition,
  18186. IN ULONG CreateOptions,
  18187. IN PVOID EaBuffer OPTIONAL,
  18188. IN ULONG EaLength
  18189. );
  18190. NTSYSAPI
  18191. NTSTATUS
  18192. NTAPI
  18193. ZwOpenFile(
  18194. OUT PHANDLE FileHandle,
  18195. IN ACCESS_MASK DesiredAccess,
  18196. IN POBJECT_ATTRIBUTES ObjectAttributes,
  18197. OUT PIO_STATUS_BLOCK IoStatusBlock,
  18198. IN ULONG ShareAccess,
  18199. IN ULONG OpenOptions
  18200. );
  18201. NTSYSAPI
  18202. NTSTATUS
  18203. NTAPI
  18204. ZwQueryInformationFile(
  18205. IN HANDLE FileHandle,
  18206. OUT PIO_STATUS_BLOCK IoStatusBlock,
  18207. OUT PVOID FileInformation,
  18208. IN ULONG Length,
  18209. IN FILE_INFORMATION_CLASS FileInformationClass
  18210. );
  18211. NTSYSAPI
  18212. NTSTATUS
  18213. NTAPI
  18214. ZwSetInformationFile(
  18215. IN HANDLE FileHandle,
  18216. OUT PIO_STATUS_BLOCK IoStatusBlock,
  18217. IN PVOID FileInformation,
  18218. IN ULONG Length,
  18219. IN FILE_INFORMATION_CLASS FileInformationClass
  18220. );
  18221. NTSYSAPI
  18222. NTSTATUS
  18223. NTAPI
  18224. ZwReadFile(
  18225. IN HANDLE FileHandle,
  18226. IN HANDLE Event OPTIONAL,
  18227. IN PIO_APC_ROUTINE ApcRoutine OPTIONAL,
  18228. IN PVOID ApcContext OPTIONAL,
  18229. OUT PIO_STATUS_BLOCK IoStatusBlock,
  18230. OUT PVOID Buffer,
  18231. IN ULONG Length,
  18232. IN PLARGE_INTEGER ByteOffset OPTIONAL,
  18233. IN PULONG Key OPTIONAL
  18234. );
  18235. NTSYSAPI
  18236. NTSTATUS
  18237. NTAPI
  18238. ZwWriteFile(
  18239. IN HANDLE FileHandle,
  18240. IN HANDLE Event OPTIONAL,
  18241. IN PIO_APC_ROUTINE ApcRoutine OPTIONAL,
  18242. IN PVOID ApcContext OPTIONAL,
  18243. OUT PIO_STATUS_BLOCK IoStatusBlock,
  18244. IN PVOID Buffer,
  18245. IN ULONG Length,
  18246. IN PLARGE_INTEGER ByteOffset OPTIONAL,
  18247. IN PULONG Key OPTIONAL
  18248. );
  18249. NTSYSAPI
  18250. NTSTATUS
  18251. NTAPI
  18252. ZwClose(
  18253. IN HANDLE Handle
  18254. );
  18255. NTSYSAPI
  18256. NTSTATUS
  18257. NTAPI
  18258. ZwCreateDirectoryObject(
  18259. OUT PHANDLE DirectoryHandle,
  18260. IN ACCESS_MASK DesiredAccess,
  18261. IN POBJECT_ATTRIBUTES ObjectAttributes
  18262. );
  18263. NTSYSAPI
  18264. NTSTATUS
  18265. NTAPI
  18266. ZwMakeTemporaryObject(
  18267. IN HANDLE Handle
  18268. );
  18269. NTSYSAPI
  18270. NTSTATUS
  18271. NTAPI
  18272. ZwOpenSection(
  18273. OUT PHANDLE SectionHandle,
  18274. IN ACCESS_MASK DesiredAccess,
  18275. IN POBJECT_ATTRIBUTES ObjectAttributes
  18276. );
  18277. NTSYSAPI
  18278. NTSTATUS
  18279. NTAPI
  18280. ZwMapViewOfSection(
  18281. IN HANDLE SectionHandle,
  18282. IN HANDLE ProcessHandle,
  18283. IN OUT PVOID *BaseAddress,
  18284. IN ULONG ZeroBits,
  18285. IN ULONG CommitSize,
  18286. IN OUT PLARGE_INTEGER SectionOffset OPTIONAL,
  18287. IN OUT PSIZE_T ViewSize,
  18288. IN SECTION_INHERIT InheritDisposition,
  18289. IN ULONG AllocationType,
  18290. IN ULONG Protect
  18291. );
  18292. NTSYSAPI
  18293. NTSTATUS
  18294. NTAPI
  18295. ZwUnmapViewOfSection(
  18296. IN HANDLE ProcessHandle,
  18297. IN PVOID BaseAddress
  18298. );
  18299. NTSYSAPI
  18300. NTSTATUS
  18301. NTAPI
  18302. ZwSetInformationThread(
  18303. IN HANDLE ThreadHandle,
  18304. IN THREADINFOCLASS ThreadInformationClass,
  18305. IN PVOID ThreadInformation,
  18306. IN ULONG ThreadInformationLength
  18307. );
  18308. NTSYSAPI
  18309. NTSTATUS
  18310. NTAPI
  18311. ZwCreateKey(
  18312. OUT PHANDLE KeyHandle,
  18313. IN ACCESS_MASK DesiredAccess,
  18314. IN POBJECT_ATTRIBUTES ObjectAttributes,
  18315. IN ULONG TitleIndex,
  18316. IN PUNICODE_STRING Class OPTIONAL,
  18317. IN ULONG CreateOptions,
  18318. OUT PULONG Disposition OPTIONAL
  18319. );
  18320. NTSYSAPI
  18321. NTSTATUS
  18322. NTAPI
  18323. ZwOpenKey(
  18324. OUT PHANDLE KeyHandle,
  18325. IN ACCESS_MASK DesiredAccess,
  18326. IN POBJECT_ATTRIBUTES ObjectAttributes
  18327. );
  18328. NTSYSAPI
  18329. NTSTATUS
  18330. NTAPI
  18331. ZwDeleteKey(
  18332. IN HANDLE KeyHandle
  18333. );
  18334. NTSYSAPI
  18335. NTSTATUS
  18336. NTAPI
  18337. ZwDeleteValueKey(
  18338. IN HANDLE KeyHandle,
  18339. IN PUNICODE_STRING ValueName
  18340. );
  18341. NTSYSAPI
  18342. NTSTATUS
  18343. NTAPI
  18344. ZwEnumerateKey(
  18345. IN HANDLE KeyHandle,
  18346. IN ULONG Index,
  18347. IN KEY_INFORMATION_CLASS KeyInformationClass,
  18348. OUT PVOID KeyInformation,
  18349. IN ULONG Length,
  18350. OUT PULONG ResultLength
  18351. );
  18352. NTSYSAPI
  18353. NTSTATUS
  18354. NTAPI
  18355. ZwEnumerateValueKey(
  18356. IN HANDLE KeyHandle,
  18357. IN ULONG Index,
  18358. IN KEY_VALUE_INFORMATION_CLASS KeyValueInformationClass,
  18359. OUT PVOID KeyValueInformation,
  18360. IN ULONG Length,
  18361. OUT PULONG ResultLength
  18362. );
  18363. NTSYSAPI
  18364. NTSTATUS
  18365. NTAPI
  18366. ZwFlushKey(
  18367. IN HANDLE KeyHandle
  18368. );
  18369. NTSYSAPI
  18370. NTSTATUS
  18371. NTAPI
  18372. ZwQueryKey(
  18373. IN HANDLE KeyHandle,
  18374. IN KEY_INFORMATION_CLASS KeyInformationClass,
  18375. OUT PVOID KeyInformation,
  18376. IN ULONG Length,
  18377. OUT PULONG ResultLength
  18378. );
  18379. NTSYSAPI
  18380. NTSTATUS
  18381. NTAPI
  18382. ZwQueryValueKey(
  18383. IN HANDLE KeyHandle,
  18384. IN PUNICODE_STRING ValueName,
  18385. IN KEY_VALUE_INFORMATION_CLASS KeyValueInformationClass,
  18386. OUT PVOID KeyValueInformation,
  18387. IN ULONG Length,
  18388. OUT PULONG ResultLength
  18389. );
  18390. NTSYSAPI
  18391. NTSTATUS
  18392. NTAPI
  18393. ZwSetValueKey(
  18394. IN HANDLE KeyHandle,
  18395. IN PUNICODE_STRING ValueName,
  18396. IN ULONG TitleIndex OPTIONAL,
  18397. IN ULONG Type,
  18398. IN PVOID Data,
  18399. IN ULONG DataSize
  18400. );
  18401. NTSYSAPI
  18402. NTSTATUS
  18403. NTAPI
  18404. ZwOpenSymbolicLinkObject(
  18405. OUT PHANDLE LinkHandle,
  18406. IN ACCESS_MASK DesiredAccess,
  18407. IN POBJECT_ATTRIBUTES ObjectAttributes
  18408. );
  18409. NTSYSAPI
  18410. NTSTATUS
  18411. NTAPI
  18412. ZwQuerySymbolicLinkObject(
  18413. IN HANDLE LinkHandle,
  18414. IN OUT PUNICODE_STRING LinkTarget,
  18415. OUT PULONG ReturnedLength OPTIONAL
  18416. );
  18417. NTSTATUS
  18418. ZwCreateTimer (
  18419. OUT PHANDLE TimerHandle,
  18420. IN ACCESS_MASK DesiredAccess,
  18421. IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL,
  18422. IN TIMER_TYPE TimerType
  18423. );
  18424. NTSTATUS
  18425. ZwOpenTimer (
  18426. OUT PHANDLE TimerHandle,
  18427. IN ACCESS_MASK DesiredAccess,
  18428. IN POBJECT_ATTRIBUTES ObjectAttributes
  18429. );
  18430. NTSTATUS
  18431. ZwCancelTimer (
  18432. IN HANDLE TimerHandle,
  18433. OUT PBOOLEAN CurrentState OPTIONAL
  18434. );
  18435. NTSTATUS
  18436. ZwSetTimer (
  18437. IN HANDLE TimerHandle,
  18438. IN PLARGE_INTEGER DueTime,
  18439. IN PTIMER_APC_ROUTINE TimerApcRoutine OPTIONAL,
  18440. IN PVOID TimerContext OPTIONAL,
  18441. IN BOOLEAN WakeTimer,
  18442. IN LONG Period OPTIONAL,
  18443. OUT PBOOLEAN PreviousState OPTIONAL
  18444. );
  18445. #endif // _NTDDK_