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

26046 lines
621 KiB

  1. /*++ BUILD Version: 0090 // Increment this if a change has global effects
  2. Copyright (c) Microsoft Corporation. All rights reserved.
  3. Module Name:
  4. nthal.h
  5. Abstract:
  6. This module defines the NT types, constants, and functions that are
  7. exposed to HALs.
  8. Revision History:
  9. --*/
  10. #ifndef _NTHAL_
  11. #define _NTHAL_
  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. #include <excpt.h>
  18. #include <ntdef.h>
  19. #include <ntstatus.h>
  20. #include <bugcodes.h>
  21. #include <ntiologc.h>
  22. //
  23. // Define types that are not exported.
  24. //
  25. typedef struct _CALLBACK_OBJECT *PCALLBACK_OBJECT;
  26. typedef struct _ETHREAD *PETHREAD;
  27. typedef struct _FAST_IO_DISPATCH *PFAST_IO_DISPATCH;
  28. typedef struct _IO_SECURITY_CONTEXT *PIO_SECURITY_CONTEXT;
  29. typedef struct _IO_TIMER *PIO_TIMER;
  30. typedef struct _KTHREAD *PKTHREAD, *PRKTHREAD;
  31. typedef struct _OBJECT_TYPE *POBJECT_TYPE;
  32. struct _IRP;
  33. #if defined(_M_AMD64)
  34. PKTHREAD
  35. NTAPI
  36. KeGetCurrentThread(
  37. VOID
  38. );
  39. #endif // defined(_M_AMD64)
  40. #if defined(_M_IX86)
  41. PKTHREAD NTAPI KeGetCurrentThread();
  42. #endif // defined(_M_IX86)
  43. #include <mce.h>
  44. #ifdef _X86_
  45. //
  46. // Disable these two pragmas that evaluate to "sti" "cli" on x86 so that driver
  47. // writers to not leave them inadvertantly in their code.
  48. //
  49. #if !defined(MIDL_PASS)
  50. #if !defined(RC_INVOKED)
  51. #if _MSC_VER >= 1200
  52. #pragma warning(push)
  53. #endif
  54. #pragma warning(disable:4164) // disable C4164 warning so that apps that
  55. // build with /Od don't get weird errors !
  56. #ifdef _M_IX86
  57. #pragma function(_enable)
  58. #pragma function(_disable)
  59. #endif
  60. #if _MSC_VER >= 1200
  61. #pragma warning(pop)
  62. #else
  63. #pragma warning(default:4164) // reenable C4164 warning
  64. #endif
  65. #endif
  66. #endif
  67. #if !defined(MIDL_PASS) || defined(_M_IX86)
  68. #if (_MSC_FULL_VER >= 13012035)
  69. //
  70. // Define bit scan intrinsics.
  71. //
  72. //#define BitScanForward _BitScanForward
  73. //#define BitScanReverse _BitScanReverse
  74. //BOOLEAN
  75. //_BitScanForward (
  76. // OUT ULONG *Index,
  77. // IN ULONG Mask
  78. // );
  79. //BOOLEAN
  80. //_BitScanReverse (
  81. // OUT ULONG *Index,
  82. // IN ULONG Mask
  83. // );
  84. //#pragma intrinsic(_BitScanForward)
  85. //#pragma intrinsic(_BitScanReverse)
  86. //
  87. // Define FS referencing intrinsics
  88. //
  89. #ifdef __cplusplus
  90. extern "C" {
  91. #endif
  92. UCHAR
  93. __readfsbyte (
  94. IN ULONG Offset
  95. );
  96. USHORT
  97. __readfsword (
  98. IN ULONG Offset
  99. );
  100. ULONG
  101. __readfsdword (
  102. IN ULONG Offset
  103. );
  104. VOID
  105. __writefsbyte (
  106. IN ULONG Offset,
  107. IN UCHAR Data
  108. );
  109. VOID
  110. __writefsword (
  111. IN ULONG Offset,
  112. IN USHORT Data
  113. );
  114. VOID
  115. __writefsdword (
  116. IN ULONG Offset,
  117. IN ULONG Data
  118. );
  119. #ifdef __cplusplus
  120. }
  121. #endif
  122. #pragma intrinsic(__readfsbyte)
  123. #pragma intrinsic(__readfsword)
  124. #pragma intrinsic(__readfsdword)
  125. #pragma intrinsic(__writefsbyte)
  126. #pragma intrinsic(__writefsword)
  127. #pragma intrinsic(__writefsdword)
  128. #endif
  129. #endif
  130. //
  131. // Size of kernel mode stack.
  132. //
  133. #define KERNEL_STACK_SIZE 12288
  134. //
  135. // Define size of large kernel mode stack for callbacks.
  136. //
  137. #define KERNEL_LARGE_STACK_SIZE 61440
  138. //
  139. // Define number of pages to initialize in a large kernel stack.
  140. //
  141. #define KERNEL_LARGE_STACK_COMMIT 12288
  142. //
  143. // Exception Registration structure
  144. //
  145. typedef struct _EXCEPTION_REGISTRATION_RECORD {
  146. struct _EXCEPTION_REGISTRATION_RECORD *Next;
  147. PEXCEPTION_ROUTINE Handler;
  148. } EXCEPTION_REGISTRATION_RECORD;
  149. typedef EXCEPTION_REGISTRATION_RECORD *PEXCEPTION_REGISTRATION_RECORD;
  150. //
  151. // Define constants for system IDTs
  152. //
  153. #define MAXIMUM_IDTVECTOR 0xff
  154. #define MAXIMUM_PRIMARY_VECTOR 0xff
  155. #define PRIMARY_VECTOR_BASE 0x30 // 0-2f are x86 trap vectors
  156. // begin_ntddk
  157. #ifdef _X86_
  158. // end_ntddk
  159. // begin_ntddk begin_winnt
  160. #if !defined(MIDL_PASS) && defined(_M_IX86)
  161. FORCEINLINE
  162. VOID
  163. MemoryBarrier (
  164. VOID
  165. )
  166. {
  167. LONG Barrier;
  168. __asm {
  169. xchg Barrier, eax
  170. }
  171. }
  172. #define YieldProcessor() __asm { rep nop }
  173. //
  174. // Prefetch is not supported on all x86 procssors.
  175. //
  176. #define PreFetchCacheLine(l, a)
  177. //
  178. // PreFetchCacheLine level defines.
  179. //
  180. #define PF_TEMPORAL_LEVEL_1
  181. #define PF_NON_TEMPORAL_LEVEL_ALL
  182. // end_ntddk
  183. #if (_MSC_FULL_VER >= 13012035)
  184. _inline PVOID GetFiberData( void ) { return *(PVOID *) (ULONG_PTR) __readfsdword (0x10);}
  185. _inline PVOID GetCurrentFiber( void ) { return (PVOID) (ULONG_PTR) __readfsdword (0x10);}
  186. #else
  187. #if _MSC_VER >= 1200
  188. #pragma warning(push)
  189. #endif
  190. #pragma warning (disable:4035) // disable 4035 (function must return something)
  191. _inline PVOID GetFiberData( void ) { __asm {
  192. mov eax, fs:[0x10]
  193. mov eax,[eax]
  194. }
  195. }
  196. _inline PVOID GetCurrentFiber( void ) { __asm mov eax, fs:[0x10] }
  197. #if _MSC_VER >= 1200
  198. #pragma warning(pop)
  199. #else
  200. #pragma warning (default:4035) // Reenable it
  201. #endif
  202. #endif
  203. // begin_ntddk
  204. #endif
  205. // begin_wx86
  206. //
  207. // Define the size of the 80387 save area, which is in the context frame.
  208. //
  209. #define SIZE_OF_80387_REGISTERS 80
  210. //
  211. // The following flags control the contents of the CONTEXT structure.
  212. //
  213. #if !defined(RC_INVOKED)
  214. #define CONTEXT_i386 0x00010000 // this assumes that i386 and
  215. #define CONTEXT_i486 0x00010000 // i486 have identical context records
  216. // end_wx86
  217. #define CONTEXT_CONTROL (CONTEXT_i386 | 0x00000001L) // SS:SP, CS:IP, FLAGS, BP
  218. #define CONTEXT_INTEGER (CONTEXT_i386 | 0x00000002L) // AX, BX, CX, DX, SI, DI
  219. #define CONTEXT_SEGMENTS (CONTEXT_i386 | 0x00000004L) // DS, ES, FS, GS
  220. #define CONTEXT_FLOATING_POINT (CONTEXT_i386 | 0x00000008L) // 387 state
  221. #define CONTEXT_DEBUG_REGISTERS (CONTEXT_i386 | 0x00000010L) // DB 0-3,6,7
  222. #define CONTEXT_EXTENDED_REGISTERS (CONTEXT_i386 | 0x00000020L) // cpu specific extensions
  223. #define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_INTEGER |\
  224. CONTEXT_SEGMENTS)
  225. #define CONTEXT_ALL (CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_SEGMENTS | CONTEXT_FLOATING_POINT | CONTEXT_DEBUG_REGISTERS | CONTEXT_EXTENDED_REGISTERS)
  226. // begin_wx86
  227. #endif
  228. #define MAXIMUM_SUPPORTED_EXTENSION 512
  229. typedef struct _FLOATING_SAVE_AREA {
  230. ULONG ControlWord;
  231. ULONG StatusWord;
  232. ULONG TagWord;
  233. ULONG ErrorOffset;
  234. ULONG ErrorSelector;
  235. ULONG DataOffset;
  236. ULONG DataSelector;
  237. UCHAR RegisterArea[SIZE_OF_80387_REGISTERS];
  238. ULONG Cr0NpxState;
  239. } FLOATING_SAVE_AREA;
  240. typedef FLOATING_SAVE_AREA *PFLOATING_SAVE_AREA;
  241. //
  242. // Context Frame
  243. //
  244. // This frame has a several purposes: 1) it is used as an argument to
  245. // NtContinue, 2) is is used to constuct a call frame for APC delivery,
  246. // and 3) it is used in the user level thread creation routines.
  247. //
  248. // The layout of the record conforms to a standard call frame.
  249. //
  250. typedef struct _CONTEXT {
  251. //
  252. // The flags values within this flag control the contents of
  253. // a CONTEXT record.
  254. //
  255. // If the context record is used as an input parameter, then
  256. // for each portion of the context record controlled by a flag
  257. // whose value is set, it is assumed that that portion of the
  258. // context record contains valid context. If the context record
  259. // is being used to modify a threads context, then only that
  260. // portion of the threads context will be modified.
  261. //
  262. // If the context record is used as an IN OUT parameter to capture
  263. // the context of a thread, then only those portions of the thread's
  264. // context corresponding to set flags will be returned.
  265. //
  266. // The context record is never used as an OUT only parameter.
  267. //
  268. ULONG ContextFlags;
  269. //
  270. // This section is specified/returned if CONTEXT_DEBUG_REGISTERS is
  271. // set in ContextFlags. Note that CONTEXT_DEBUG_REGISTERS is NOT
  272. // included in CONTEXT_FULL.
  273. //
  274. ULONG Dr0;
  275. ULONG Dr1;
  276. ULONG Dr2;
  277. ULONG Dr3;
  278. ULONG Dr6;
  279. ULONG Dr7;
  280. //
  281. // This section is specified/returned if the
  282. // ContextFlags word contians the flag CONTEXT_FLOATING_POINT.
  283. //
  284. FLOATING_SAVE_AREA FloatSave;
  285. //
  286. // This section is specified/returned if the
  287. // ContextFlags word contians the flag CONTEXT_SEGMENTS.
  288. //
  289. ULONG SegGs;
  290. ULONG SegFs;
  291. ULONG SegEs;
  292. ULONG SegDs;
  293. //
  294. // This section is specified/returned if the
  295. // ContextFlags word contians the flag CONTEXT_INTEGER.
  296. //
  297. ULONG Edi;
  298. ULONG Esi;
  299. ULONG Ebx;
  300. ULONG Edx;
  301. ULONG Ecx;
  302. ULONG Eax;
  303. //
  304. // This section is specified/returned if the
  305. // ContextFlags word contians the flag CONTEXT_CONTROL.
  306. //
  307. ULONG Ebp;
  308. ULONG Eip;
  309. ULONG SegCs; // MUST BE SANITIZED
  310. ULONG EFlags; // MUST BE SANITIZED
  311. ULONG Esp;
  312. ULONG SegSs;
  313. //
  314. // This section is specified/returned if the ContextFlags word
  315. // contains the flag CONTEXT_EXTENDED_REGISTERS.
  316. // The format and contexts are processor specific
  317. //
  318. UCHAR ExtendedRegisters[MAXIMUM_SUPPORTED_EXTENSION];
  319. } CONTEXT;
  320. typedef CONTEXT *PCONTEXT;
  321. // begin_ntminiport
  322. #endif //_X86_
  323. #endif // _X86_
  324. #if defined(_AMD64_)
  325. #if defined(_M_AMD64) && !defined(RC_INVOKED) && !defined(MIDL_PASS)
  326. //
  327. // Define bit test intrinsics.
  328. //
  329. #ifdef __cplusplus
  330. extern "C" {
  331. #endif
  332. #define BitTest _bittest
  333. #define BitTestAndComplement _bittestandcomplement
  334. #define BitTestAndSet _bittestandset
  335. #define BitTestAndReset _bittestandreset
  336. #define InterlockedBitTestAndSet _interlockedbittestandset
  337. #define InterlockedBitTestAndReset _interlockedbittestandreset
  338. #define BitTest64 _bittest64
  339. #define BitTestAndComplement64 _bittestandcomplement64
  340. #define BitTestAndSet64 _bittestandset64
  341. #define BitTestAndReset64 _bittestandreset64
  342. #define InterlockedBitTestAndSet64 _interlockedbittestandset64
  343. #define InterlockedBitTestAndReset64 _interlockedbittestandreset64
  344. BOOLEAN
  345. _bittest (
  346. IN LONG *Base,
  347. IN LONG Offset
  348. );
  349. BOOLEAN
  350. _bittestandcomplement (
  351. IN LONG *Base,
  352. IN LONG Offset
  353. );
  354. BOOLEAN
  355. _bittestandset (
  356. IN LONG *Base,
  357. IN LONG Offset
  358. );
  359. BOOLEAN
  360. _bittestandreset (
  361. IN LONG *Base,
  362. IN LONG Offset
  363. );
  364. BOOLEAN
  365. _interlockedbittestandset (
  366. IN LONG *Base,
  367. IN LONG Offset
  368. );
  369. BOOLEAN
  370. _interlockedbittestandreset (
  371. IN LONG *Base,
  372. IN LONG Offset
  373. );
  374. BOOLEAN
  375. _bittest64 (
  376. IN LONG64 *Base,
  377. IN LONG64 Offset
  378. );
  379. BOOLEAN
  380. _bittestandcomplement64 (
  381. IN LONG64 *Base,
  382. IN LONG64 Offset
  383. );
  384. BOOLEAN
  385. _bittestandset64 (
  386. IN LONG64 *Base,
  387. IN LONG64 Offset
  388. );
  389. BOOLEAN
  390. _bittestandreset64 (
  391. IN LONG64 *Base,
  392. IN LONG64 Offset
  393. );
  394. BOOLEAN
  395. _interlockedbittestandset64 (
  396. IN LONG64 *Base,
  397. IN LONG64 Offset
  398. );
  399. BOOLEAN
  400. _interlockedbittestandreset64 (
  401. IN LONG64 *Base,
  402. IN LONG64 Offset
  403. );
  404. #pragma intrinsic(_bittest)
  405. #pragma intrinsic(_bittestandcomplement)
  406. #pragma intrinsic(_bittestandset)
  407. #pragma intrinsic(_bittestandreset)
  408. #pragma intrinsic(_interlockedbittestandset)
  409. #pragma intrinsic(_interlockedbittestandreset)
  410. #pragma intrinsic(_bittest64)
  411. #pragma intrinsic(_bittestandcomplement64)
  412. #pragma intrinsic(_bittestandset64)
  413. #pragma intrinsic(_bittestandreset64)
  414. #pragma intrinsic(_interlockedbittestandset64)
  415. #pragma intrinsic(_interlockedbittestandreset64)
  416. //
  417. // Define bit scan intrinsics.
  418. //
  419. #define BitScanForward _BitScanForward
  420. #define BitScanReverse _BitScanReverse
  421. #define BitScanForward64 _BitScanForward64
  422. #define BitScanReverse64 _BitScanReverse64
  423. BOOLEAN
  424. _BitScanForward (
  425. OUT ULONG *Index,
  426. IN ULONG Mask
  427. );
  428. BOOLEAN
  429. _BitScanReverse (
  430. OUT ULONG *Index,
  431. IN ULONG Mask
  432. );
  433. BOOLEAN
  434. _BitScanForward64 (
  435. OUT ULONG *Index,
  436. IN ULONG64 Mask
  437. );
  438. BOOLEAN
  439. _BitScanReverse64 (
  440. OUT ULONG *Index,
  441. IN ULONG64 Mask
  442. );
  443. #pragma intrinsic(_BitScanForward)
  444. #pragma intrinsic(_BitScanReverse)
  445. #pragma intrinsic(_BitScanForward64)
  446. #pragma intrinsic(_BitScanReverse64)
  447. //
  448. // Define function to flush a cache line.
  449. //
  450. #define CacheLineFlush(Address) _mm_clflush(Address)
  451. VOID
  452. _mm_clflush (
  453. PVOID Address
  454. );
  455. #pragma intrinsic(_mm_clflush)
  456. //
  457. // Define memory fence intrinsics
  458. //
  459. #define LoadFence _mm_lfence
  460. #define MemoryFence _mm_mfence
  461. #define StoreFence _mm_sfence
  462. VOID
  463. _mm_lfence (
  464. VOID
  465. );
  466. VOID
  467. _mm_mfence (
  468. VOID
  469. );
  470. VOID
  471. _mm_sfence (
  472. VOID
  473. );
  474. void
  475. _mm_prefetch(
  476. CHAR CONST *a,
  477. int sel
  478. );
  479. /* constants for use with _mm_prefetch */
  480. #define _MM_HINT_T0 1
  481. #define _MM_HINT_T1 2
  482. #define _MM_HINT_T2 3
  483. #define _MM_HINT_NTA 0
  484. #pragma intrinsic(_mm_prefetch)
  485. #pragma intrinsic(_mm_lfence)
  486. #pragma intrinsic(_mm_mfence)
  487. #pragma intrinsic(_mm_sfence)
  488. #define YieldProcessor()
  489. #define MemoryBarrier _mm_mfence
  490. #define PreFetchCacheLine(l, a) _mm_prefetch((CHAR CONST *) a, l)
  491. //
  492. // PreFetchCacheLine level defines.
  493. //
  494. #define PF_TEMPORAL_LEVEL_1 _MM_HINT_T0
  495. #define PF_NON_TEMPORAL_LEVEL_ALL _MM_HINT_NTA
  496. //
  497. // Define function to get the caller's EFLAGs value.
  498. //
  499. #define GetCallersEflags() __getcallerseflags()
  500. unsigned __int32
  501. __getcallerseflags (
  502. VOID
  503. );
  504. #pragma intrinsic(__getcallerseflags)
  505. //
  506. // Define function to read the value of the time stamp counter
  507. //
  508. #define ReadTimeStampCounter() __rdtsc()
  509. ULONG64
  510. __rdtsc (
  511. VOID
  512. );
  513. #pragma intrinsic(__rdtsc)
  514. //
  515. // Define functions to move strings as bytes, words, dwords, and qwords.
  516. //
  517. VOID
  518. __movsb (
  519. IN PUCHAR Destination,
  520. IN PUCHAR Source,
  521. IN SIZE_T Count
  522. );
  523. VOID
  524. __movsw (
  525. IN PUSHORT Destination,
  526. IN PUSHORT Source,
  527. IN SIZE_T Count
  528. );
  529. VOID
  530. __movsd (
  531. IN PULONG Destination,
  532. IN PULONG Source,
  533. IN SIZE_T Count
  534. );
  535. VOID
  536. __movsq (
  537. IN PULONGLONG Destination,
  538. IN PULONGLONG Source,
  539. IN SIZE_T Count
  540. );
  541. #pragma intrinsic(__movsb)
  542. #pragma intrinsic(__movsw)
  543. #pragma intrinsic(__movsd)
  544. #pragma intrinsic(__movsq)
  545. //
  546. // Define functions to store strings as bytes, words, dwords, and qwords.
  547. //
  548. VOID
  549. __stosb (
  550. IN PUCHAR Destination,
  551. IN UCHAR Value,
  552. IN SIZE_T Count
  553. );
  554. VOID
  555. __stosw (
  556. IN PUSHORT Destination,
  557. IN USHORT Value,
  558. IN SIZE_T Count
  559. );
  560. VOID
  561. __stosd (
  562. IN PULONG Destination,
  563. IN ULONG Value,
  564. IN SIZE_T Count
  565. );
  566. VOID
  567. __stosq (
  568. IN PULONG64 Destination,
  569. IN ULONG64 Value,
  570. IN SIZE_T Count
  571. );
  572. #pragma intrinsic(__stosb)
  573. #pragma intrinsic(__stosw)
  574. #pragma intrinsic(__stosd)
  575. #pragma intrinsic(__stosq)
  576. //
  577. // Define functions to capture the high 64-bits of a 128-bit multiply.
  578. //
  579. #define MultiplyHigh __mulh
  580. #define UnsignedMultiplyHigh __umulh
  581. LONGLONG
  582. MultiplyHigh (
  583. IN LONGLONG Multiplier,
  584. IN LONGLONG Multiplicand
  585. );
  586. ULONGLONG
  587. UnsignedMultiplyHigh (
  588. IN ULONGLONG Multiplier,
  589. IN ULONGLONG Multiplicand
  590. );
  591. #pragma intrinsic(__mulh)
  592. #pragma intrinsic(__umulh)
  593. //
  594. // Define functions to read and write the uer TEB and the system PCR/PRCB.
  595. //
  596. UCHAR
  597. __readgsbyte (
  598. IN ULONG Offset
  599. );
  600. USHORT
  601. __readgsword (
  602. IN ULONG Offset
  603. );
  604. ULONG
  605. __readgsdword (
  606. IN ULONG Offset
  607. );
  608. ULONG64
  609. __readgsqword (
  610. IN ULONG Offset
  611. );
  612. VOID
  613. __writegsbyte (
  614. IN ULONG Offset,
  615. IN UCHAR Data
  616. );
  617. VOID
  618. __writegsword (
  619. IN ULONG Offset,
  620. IN USHORT Data
  621. );
  622. VOID
  623. __writegsdword (
  624. IN ULONG Offset,
  625. IN ULONG Data
  626. );
  627. VOID
  628. __writegsqword (
  629. IN ULONG Offset,
  630. IN ULONG64 Data
  631. );
  632. #pragma intrinsic(__readgsbyte)
  633. #pragma intrinsic(__readgsword)
  634. #pragma intrinsic(__readgsdword)
  635. #pragma intrinsic(__readgsqword)
  636. #pragma intrinsic(__writegsbyte)
  637. #pragma intrinsic(__writegsword)
  638. #pragma intrinsic(__writegsdword)
  639. #pragma intrinsic(__writegsqword)
  640. #ifdef __cplusplus
  641. }
  642. #endif
  643. #endif // defined(_M_AMD64) && !defined(RC_INVOKED) && !defined(MIDL_PASS)
  644. //
  645. // Size of kernel mode stack.
  646. //
  647. #define KERNEL_STACK_SIZE 0x6000
  648. //
  649. // Define size of large kernel mode stack for callbacks.
  650. //
  651. #define KERNEL_LARGE_STACK_SIZE 0xf000
  652. //
  653. // Define number of pages to initialize in a large kernel stack.
  654. //
  655. #define KERNEL_LARGE_STACK_COMMIT 0x5000
  656. //
  657. // Define the size of the stack used for processing an MCA exception.
  658. //
  659. #define KERNEL_MCA_EXCEPTION_STACK_SIZE 0x2000
  660. //
  661. // Define stack alignment and rounding values.
  662. //
  663. #define STACK_ALIGN (16UI64)
  664. #define STACK_ROUND (STACK_ALIGN - 1)
  665. //
  666. // Define constants for system IDTs
  667. //
  668. #define MAXIMUM_IDTVECTOR 0xff
  669. #define MAXIMUM_PRIMARY_VECTOR 0xff
  670. #define PRIMARY_VECTOR_BASE 0x30 // 0-2f are AMD64 trap vectors
  671. // begin_winnt begin_ntddk begin_wx86
  672. //
  673. // The following flags control the contents of the CONTEXT structure.
  674. //
  675. #if !defined(RC_INVOKED)
  676. #define CONTEXT_AMD64 0x100000
  677. // end_wx86
  678. #define CONTEXT_CONTROL (CONTEXT_AMD64 | 0x1L)
  679. #define CONTEXT_INTEGER (CONTEXT_AMD64 | 0x2L)
  680. #define CONTEXT_SEGMENTS (CONTEXT_AMD64 | 0x4L)
  681. #define CONTEXT_FLOATING_POINT (CONTEXT_AMD64 | 0x8L)
  682. #define CONTEXT_DEBUG_REGISTERS (CONTEXT_AMD64 | 0x10L)
  683. #define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_FLOATING_POINT)
  684. #define CONTEXT_ALL (CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_SEGMENTS | CONTEXT_FLOATING_POINT | CONTEXT_DEBUG_REGISTERS)
  685. // begin_wx86
  686. #endif // !defined(RC_INVOKED)
  687. //
  688. // Define initial MxCsr control.
  689. //
  690. #define INITIAL_MXCSR 0x1f80 // initial MXCSR value
  691. //
  692. // Define 128-bit 16-byte aligned xmm register type.
  693. //
  694. typedef struct DECLSPEC_ALIGN(16) _M128 {
  695. ULONGLONG Low;
  696. LONGLONG High;
  697. } M128, *PM128;
  698. //
  699. // Format of data for fnsave/frstor instructions.
  700. //
  701. // This structure is used to store the legacy floating point state.
  702. //
  703. typedef struct _LEGACY_SAVE_AREA {
  704. USHORT ControlWord;
  705. USHORT Reserved0;
  706. USHORT StatusWord;
  707. USHORT Reserved1;
  708. USHORT TagWord;
  709. USHORT Reserved2;
  710. ULONG ErrorOffset;
  711. USHORT ErrorSelector;
  712. USHORT ErrorOpcode;
  713. ULONG DataOffset;
  714. USHORT DataSelector;
  715. USHORT Reserved3;
  716. UCHAR FloatRegisters[8 * 10];
  717. } LEGACY_SAVE_AREA, *PLEGACY_SAVE_AREA;
  718. #define LEGACY_SAVE_AREA_LENGTH ((sizeof(LEGACY_SAVE_AREA) + 15) & ~15)
  719. //
  720. // Context Frame
  721. //
  722. // This frame has a several purposes: 1) it is used as an argument to
  723. // NtContinue, 2) is is used to constuct a call frame for APC delivery,
  724. // and 3) it is used in the user level thread creation routines.
  725. //
  726. //
  727. // The flags field within this record controls the contents of a CONTEXT
  728. // record.
  729. //
  730. // If the context record is used as an input parameter, then for each
  731. // portion of the context record controlled by a flag whose value is
  732. // set, it is assumed that that portion of the context record contains
  733. // valid context. If the context record is being used to modify a threads
  734. // context, then only that portion of the threads context is modified.
  735. //
  736. // If the context record is used as an output parameter to capture the
  737. // context of a thread, then only those portions of the thread's context
  738. // corresponding to set flags will be returned.
  739. //
  740. // CONTEXT_CONTROL specifies SegSs, Rsp, SegCs, Rip, and EFlags.
  741. //
  742. // CONTEXT_INTEGER specifies Rax, Rcx, Rdx, Rbx, Rbp, Rsi, Rdi, and R8-R15.
  743. //
  744. // CONTEXT_SEGMENTS specifies SegDs, SegEs, SegFs, and SegGs.
  745. //
  746. // CONTEXT_DEBUG_REGISTERS specifies Dr0-Dr3 and Dr6-Dr7.
  747. //
  748. // CONTEXT_MMX_REGISTERS specifies the floating point and extended registers
  749. // Mm0/St0-Mm7/St7 and Xmm0-Xmm15).
  750. //
  751. typedef struct DECLSPEC_ALIGN(16) _CONTEXT {
  752. //
  753. // Register parameter home addresses.
  754. //
  755. ULONG64 P1Home;
  756. ULONG64 P2Home;
  757. ULONG64 P3Home;
  758. ULONG64 P4Home;
  759. ULONG64 P5Home;
  760. ULONG64 P6Home;
  761. //
  762. // Control flags.
  763. //
  764. ULONG ContextFlags;
  765. ULONG MxCsr;
  766. //
  767. // Segment Registers and processor flags.
  768. //
  769. USHORT SegCs;
  770. USHORT SegDs;
  771. USHORT SegEs;
  772. USHORT SegFs;
  773. USHORT SegGs;
  774. USHORT SegSs;
  775. ULONG EFlags;
  776. //
  777. // Debug registers
  778. //
  779. ULONG64 Dr0;
  780. ULONG64 Dr1;
  781. ULONG64 Dr2;
  782. ULONG64 Dr3;
  783. ULONG64 Dr6;
  784. ULONG64 Dr7;
  785. //
  786. // Integer registers.
  787. //
  788. ULONG64 Rax;
  789. ULONG64 Rcx;
  790. ULONG64 Rdx;
  791. ULONG64 Rbx;
  792. ULONG64 Rsp;
  793. ULONG64 Rbp;
  794. ULONG64 Rsi;
  795. ULONG64 Rdi;
  796. ULONG64 R8;
  797. ULONG64 R9;
  798. ULONG64 R10;
  799. ULONG64 R11;
  800. ULONG64 R12;
  801. ULONG64 R13;
  802. ULONG64 R14;
  803. ULONG64 R15;
  804. //
  805. // Program counter.
  806. //
  807. ULONG64 Rip;
  808. //
  809. // MMX/floating point state.
  810. //
  811. M128 Xmm0;
  812. M128 Xmm1;
  813. M128 Xmm2;
  814. M128 Xmm3;
  815. M128 Xmm4;
  816. M128 Xmm5;
  817. M128 Xmm6;
  818. M128 Xmm7;
  819. M128 Xmm8;
  820. M128 Xmm9;
  821. M128 Xmm10;
  822. M128 Xmm11;
  823. M128 Xmm12;
  824. M128 Xmm13;
  825. M128 Xmm14;
  826. M128 Xmm15;
  827. //
  828. // Legacy floating point state.
  829. //
  830. LEGACY_SAVE_AREA FltSave;
  831. ULONG Fill;
  832. //
  833. // Special debug control registers.
  834. //
  835. ULONG64 DebugControl;
  836. ULONG64 LastBranchToRip;
  837. ULONG64 LastBranchFromRip;
  838. ULONG64 LastExceptionToRip;
  839. ULONG64 LastExceptionFromRip;
  840. ULONG64 Fill1;
  841. } CONTEXT, *PCONTEXT;
  842. //
  843. // GDT selector numbers.
  844. //
  845. // N.B. There is code in context swap that "cleanses" the user segment
  846. // registers ds, es, fs, and gs. If these values are changed or
  847. // added to, then it is very likely the code in context swap will
  848. // have to be change.
  849. //
  850. #define KGDT64_NULL (0 * 16) // NULL descriptor
  851. #define KGDT64_R0_CODE (1 * 16) // kernel mode 64-bit code
  852. #define KGDT64_R0_DATA (1 * 16) + 8 // kernel mode 64-bit data (stack)
  853. #define KGDT64_R3_CMCODE (2 * 16) // user mode 32-bit code
  854. #define KGDT64_R3_DATA (2 * 16) + 8 // user mode 32-bit data
  855. #define KGDT64_R3_CODE (3 * 16) // user mode 64-bit code
  856. #define KGDT64_SYS_TSS (4 * 16) // kernel mode system task state
  857. #define KGDT64_R3_CMTEB (5 * 16) // user mode 32-bit TEB
  858. #define KGDT64_LAST (6 * 16)
  859. #define KGDT_NUMBER KGDT_LAST
  860. #endif // _AMD64_
  861. #ifdef _IA64_
  862. //
  863. // Define size of kernel mode stack.
  864. //
  865. #define KERNEL_STACK_SIZE 0x8000
  866. //
  867. // Define size of large kernel mode stack for callbacks.
  868. //
  869. #define KERNEL_LARGE_STACK_SIZE 0x1A000
  870. //
  871. // Define number of pages to initialize in a large kernel stack.
  872. //
  873. #define KERNEL_LARGE_STACK_COMMIT 0x8000
  874. //
  875. // Define size of kernel mode backing store stack.
  876. //
  877. #define KERNEL_BSTORE_SIZE 0x8000
  878. //
  879. // Define size of large kernel mode backing store for callbacks.
  880. //
  881. #define KERNEL_LARGE_BSTORE_SIZE 0x10000
  882. //
  883. // Define number of pages to initialize in a large kernel backing store.
  884. //
  885. #define KERNEL_LARGE_BSTORE_COMMIT 0x8000
  886. //
  887. // Define base address for kernel and user space.
  888. //
  889. #define UREGION_INDEX 0
  890. #define KREGION_INDEX 7
  891. #define UADDRESS_BASE ((ULONGLONG)UREGION_INDEX << 61)
  892. #define KADDRESS_BASE ((ULONGLONG)KREGION_INDEX << 61)
  893. // Exception Registration structure
  894. //
  895. typedef struct _EXCEPTION_REGISTRATION_RECORD {
  896. struct _EXCEPTION_REGISTRATION_RECORD *Next;
  897. PEXCEPTION_ROUTINE Handler;
  898. } EXCEPTION_REGISTRATION_RECORD;
  899. void
  900. __yield(
  901. void
  902. );
  903. void
  904. __mf(
  905. void
  906. );
  907. void
  908. __lfetch(
  909. int Level,
  910. VOID CONST *Address
  911. );
  912. void
  913. __lfetchfault(
  914. int Level,
  915. VOID CONST *Address
  916. );
  917. //
  918. // __lfetch control defines.
  919. //
  920. #define MD_LFHINT_NONE 0x00
  921. #define MD_LFHINT_NT1 0x01
  922. #define MD_LFHINT_NT2 0x02
  923. #define MD_LFHINT_NTA 0x03
  924. #pragma intrinsic (__yield)
  925. #pragma intrinsic (__lfetch)
  926. #pragma intrinsic (__lfetchfault)
  927. #pragma intrinsic (__mf)
  928. #define YieldProcessor __yield
  929. #define MemoryBarrier __mf
  930. #define PreFetchCacheLine __lfetch
  931. //
  932. // PreFetchCacheLine level defines.
  933. //
  934. #define PF_TEMPORAL_LEVEL_1 MD_LFHINT_NONE
  935. #define PF_NON_TEMPORAL_LEVEL_ALL MD_LFHINT_NTA
  936. //
  937. // The following flags control the contents of the CONTEXT structure.
  938. //
  939. #if !defined(RC_INVOKED)
  940. #define CONTEXT_IA64 0x00080000
  941. #define CONTEXT_CONTROL (CONTEXT_IA64 | 0x00000001L)
  942. #define CONTEXT_LOWER_FLOATING_POINT (CONTEXT_IA64 | 0x00000002L)
  943. #define CONTEXT_HIGHER_FLOATING_POINT (CONTEXT_IA64 | 0x00000004L)
  944. #define CONTEXT_INTEGER (CONTEXT_IA64 | 0x00000008L)
  945. #define CONTEXT_DEBUG (CONTEXT_IA64 | 0x00000010L)
  946. #define CONTEXT_IA32_CONTROL (CONTEXT_IA64 | 0x00000020L) // Includes StIPSR
  947. #define CONTEXT_FLOATING_POINT (CONTEXT_LOWER_FLOATING_POINT | CONTEXT_HIGHER_FLOATING_POINT)
  948. #define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_FLOATING_POINT | CONTEXT_INTEGER | CONTEXT_IA32_CONTROL)
  949. #define CONTEXT_ALL (CONTEXT_CONTROL | CONTEXT_FLOATING_POINT | CONTEXT_INTEGER | CONTEXT_DEBUG | CONTEXT_IA32_CONTROL)
  950. #define CONTEXT_EXCEPTION_ACTIVE 0x8000000
  951. #define CONTEXT_SERVICE_ACTIVE 0x10000000
  952. #define CONTEXT_EXCEPTION_REQUEST 0x40000000
  953. #define CONTEXT_EXCEPTION_REPORTING 0x80000000
  954. #endif // !defined(RC_INVOKED)
  955. //
  956. // Context Frame
  957. //
  958. // This frame has a several purposes: 1) it is used as an argument to
  959. // NtContinue, 2) it is used to construct a call frame for APC delivery,
  960. // 3) it is used to construct a call frame for exception dispatching
  961. // in user mode, 4) it is used in the user level thread creation
  962. // routines, and 5) it is used to to pass thread state to debuggers.
  963. //
  964. // N.B. Because this record is used as a call frame, it must be EXACTLY
  965. // a multiple of 16 bytes in length and aligned on a 16-byte boundary.
  966. //
  967. typedef struct _CONTEXT {
  968. //
  969. // The flags values within this flag control the contents of
  970. // a CONTEXT record.
  971. //
  972. // If the context record is used as an input parameter, then
  973. // for each portion of the context record controlled by a flag
  974. // whose value is set, it is assumed that that portion of the
  975. // context record contains valid context. If the context record
  976. // is being used to modify a thread's context, then only that
  977. // portion of the threads context will be modified.
  978. //
  979. // If the context record is used as an IN OUT parameter to capture
  980. // the context of a thread, then only those portions of the thread's
  981. // context corresponding to set flags will be returned.
  982. //
  983. // The context record is never used as an OUT only parameter.
  984. //
  985. ULONG ContextFlags;
  986. ULONG Fill1[3]; // for alignment of following on 16-byte boundary
  987. //
  988. // This section is specified/returned if the ContextFlags word contains
  989. // the flag CONTEXT_DEBUG.
  990. //
  991. // N.B. CONTEXT_DEBUG is *not* part of CONTEXT_FULL.
  992. //
  993. ULONGLONG DbI0;
  994. ULONGLONG DbI1;
  995. ULONGLONG DbI2;
  996. ULONGLONG DbI3;
  997. ULONGLONG DbI4;
  998. ULONGLONG DbI5;
  999. ULONGLONG DbI6;
  1000. ULONGLONG DbI7;
  1001. ULONGLONG DbD0;
  1002. ULONGLONG DbD1;
  1003. ULONGLONG DbD2;
  1004. ULONGLONG DbD3;
  1005. ULONGLONG DbD4;
  1006. ULONGLONG DbD5;
  1007. ULONGLONG DbD6;
  1008. ULONGLONG DbD7;
  1009. //
  1010. // This section is specified/returned if the ContextFlags word contains
  1011. // the flag CONTEXT_LOWER_FLOATING_POINT.
  1012. //
  1013. FLOAT128 FltS0;
  1014. FLOAT128 FltS1;
  1015. FLOAT128 FltS2;
  1016. FLOAT128 FltS3;
  1017. FLOAT128 FltT0;
  1018. FLOAT128 FltT1;
  1019. FLOAT128 FltT2;
  1020. FLOAT128 FltT3;
  1021. FLOAT128 FltT4;
  1022. FLOAT128 FltT5;
  1023. FLOAT128 FltT6;
  1024. FLOAT128 FltT7;
  1025. FLOAT128 FltT8;
  1026. FLOAT128 FltT9;
  1027. //
  1028. // This section is specified/returned if the ContextFlags word contains
  1029. // the flag CONTEXT_HIGHER_FLOATING_POINT.
  1030. //
  1031. FLOAT128 FltS4;
  1032. FLOAT128 FltS5;
  1033. FLOAT128 FltS6;
  1034. FLOAT128 FltS7;
  1035. FLOAT128 FltS8;
  1036. FLOAT128 FltS9;
  1037. FLOAT128 FltS10;
  1038. FLOAT128 FltS11;
  1039. FLOAT128 FltS12;
  1040. FLOAT128 FltS13;
  1041. FLOAT128 FltS14;
  1042. FLOAT128 FltS15;
  1043. FLOAT128 FltS16;
  1044. FLOAT128 FltS17;
  1045. FLOAT128 FltS18;
  1046. FLOAT128 FltS19;
  1047. FLOAT128 FltF32;
  1048. FLOAT128 FltF33;
  1049. FLOAT128 FltF34;
  1050. FLOAT128 FltF35;
  1051. FLOAT128 FltF36;
  1052. FLOAT128 FltF37;
  1053. FLOAT128 FltF38;
  1054. FLOAT128 FltF39;
  1055. FLOAT128 FltF40;
  1056. FLOAT128 FltF41;
  1057. FLOAT128 FltF42;
  1058. FLOAT128 FltF43;
  1059. FLOAT128 FltF44;
  1060. FLOAT128 FltF45;
  1061. FLOAT128 FltF46;
  1062. FLOAT128 FltF47;
  1063. FLOAT128 FltF48;
  1064. FLOAT128 FltF49;
  1065. FLOAT128 FltF50;
  1066. FLOAT128 FltF51;
  1067. FLOAT128 FltF52;
  1068. FLOAT128 FltF53;
  1069. FLOAT128 FltF54;
  1070. FLOAT128 FltF55;
  1071. FLOAT128 FltF56;
  1072. FLOAT128 FltF57;
  1073. FLOAT128 FltF58;
  1074. FLOAT128 FltF59;
  1075. FLOAT128 FltF60;
  1076. FLOAT128 FltF61;
  1077. FLOAT128 FltF62;
  1078. FLOAT128 FltF63;
  1079. FLOAT128 FltF64;
  1080. FLOAT128 FltF65;
  1081. FLOAT128 FltF66;
  1082. FLOAT128 FltF67;
  1083. FLOAT128 FltF68;
  1084. FLOAT128 FltF69;
  1085. FLOAT128 FltF70;
  1086. FLOAT128 FltF71;
  1087. FLOAT128 FltF72;
  1088. FLOAT128 FltF73;
  1089. FLOAT128 FltF74;
  1090. FLOAT128 FltF75;
  1091. FLOAT128 FltF76;
  1092. FLOAT128 FltF77;
  1093. FLOAT128 FltF78;
  1094. FLOAT128 FltF79;
  1095. FLOAT128 FltF80;
  1096. FLOAT128 FltF81;
  1097. FLOAT128 FltF82;
  1098. FLOAT128 FltF83;
  1099. FLOAT128 FltF84;
  1100. FLOAT128 FltF85;
  1101. FLOAT128 FltF86;
  1102. FLOAT128 FltF87;
  1103. FLOAT128 FltF88;
  1104. FLOAT128 FltF89;
  1105. FLOAT128 FltF90;
  1106. FLOAT128 FltF91;
  1107. FLOAT128 FltF92;
  1108. FLOAT128 FltF93;
  1109. FLOAT128 FltF94;
  1110. FLOAT128 FltF95;
  1111. FLOAT128 FltF96;
  1112. FLOAT128 FltF97;
  1113. FLOAT128 FltF98;
  1114. FLOAT128 FltF99;
  1115. FLOAT128 FltF100;
  1116. FLOAT128 FltF101;
  1117. FLOAT128 FltF102;
  1118. FLOAT128 FltF103;
  1119. FLOAT128 FltF104;
  1120. FLOAT128 FltF105;
  1121. FLOAT128 FltF106;
  1122. FLOAT128 FltF107;
  1123. FLOAT128 FltF108;
  1124. FLOAT128 FltF109;
  1125. FLOAT128 FltF110;
  1126. FLOAT128 FltF111;
  1127. FLOAT128 FltF112;
  1128. FLOAT128 FltF113;
  1129. FLOAT128 FltF114;
  1130. FLOAT128 FltF115;
  1131. FLOAT128 FltF116;
  1132. FLOAT128 FltF117;
  1133. FLOAT128 FltF118;
  1134. FLOAT128 FltF119;
  1135. FLOAT128 FltF120;
  1136. FLOAT128 FltF121;
  1137. FLOAT128 FltF122;
  1138. FLOAT128 FltF123;
  1139. FLOAT128 FltF124;
  1140. FLOAT128 FltF125;
  1141. FLOAT128 FltF126;
  1142. FLOAT128 FltF127;
  1143. //
  1144. // This section is specified/returned if the ContextFlags word contains
  1145. // the flag CONTEXT_LOWER_FLOATING_POINT | CONTEXT_HIGHER_FLOATING_POINT | CONTEXT_CONTROL.
  1146. //
  1147. ULONGLONG StFPSR; // FP status
  1148. //
  1149. // This section is specified/returned if the ContextFlags word contains
  1150. // the flag CONTEXT_INTEGER.
  1151. //
  1152. // N.B. The registers gp, sp, rp are part of the control context
  1153. //
  1154. ULONGLONG IntGp; // r1, volatile
  1155. ULONGLONG IntT0; // r2-r3, volatile
  1156. ULONGLONG IntT1; //
  1157. ULONGLONG IntS0; // r4-r7, preserved
  1158. ULONGLONG IntS1;
  1159. ULONGLONG IntS2;
  1160. ULONGLONG IntS3;
  1161. ULONGLONG IntV0; // r8, volatile
  1162. ULONGLONG IntT2; // r9-r11, volatile
  1163. ULONGLONG IntT3;
  1164. ULONGLONG IntT4;
  1165. ULONGLONG IntSp; // stack pointer (r12), special
  1166. ULONGLONG IntTeb; // teb (r13), special
  1167. ULONGLONG IntT5; // r14-r31, volatile
  1168. ULONGLONG IntT6;
  1169. ULONGLONG IntT7;
  1170. ULONGLONG IntT8;
  1171. ULONGLONG IntT9;
  1172. ULONGLONG IntT10;
  1173. ULONGLONG IntT11;
  1174. ULONGLONG IntT12;
  1175. ULONGLONG IntT13;
  1176. ULONGLONG IntT14;
  1177. ULONGLONG IntT15;
  1178. ULONGLONG IntT16;
  1179. ULONGLONG IntT17;
  1180. ULONGLONG IntT18;
  1181. ULONGLONG IntT19;
  1182. ULONGLONG IntT20;
  1183. ULONGLONG IntT21;
  1184. ULONGLONG IntT22;
  1185. ULONGLONG IntNats; // Nat bits for r1-r31
  1186. // r1-r31 in bits 1 thru 31.
  1187. ULONGLONG Preds; // predicates, preserved
  1188. ULONGLONG BrRp; // return pointer, b0, preserved
  1189. ULONGLONG BrS0; // b1-b5, preserved
  1190. ULONGLONG BrS1;
  1191. ULONGLONG BrS2;
  1192. ULONGLONG BrS3;
  1193. ULONGLONG BrS4;
  1194. ULONGLONG BrT0; // b6-b7, volatile
  1195. ULONGLONG BrT1;
  1196. //
  1197. // This section is specified/returned if the ContextFlags word contains
  1198. // the flag CONTEXT_CONTROL.
  1199. //
  1200. // Other application registers
  1201. ULONGLONG ApUNAT; // User Nat collection register, preserved
  1202. ULONGLONG ApLC; // Loop counter register, preserved
  1203. ULONGLONG ApEC; // Epilog counter register, preserved
  1204. ULONGLONG ApCCV; // CMPXCHG value register, volatile
  1205. ULONGLONG ApDCR; // Default control register (TBD)
  1206. // Register stack info
  1207. ULONGLONG RsPFS; // Previous function state, preserved
  1208. ULONGLONG RsBSP; // Backing store pointer, preserved
  1209. ULONGLONG RsBSPSTORE;
  1210. ULONGLONG RsRSC; // RSE configuration, volatile
  1211. ULONGLONG RsRNAT; // RSE Nat collection register, preserved
  1212. // Trap Status Information
  1213. ULONGLONG StIPSR; // Interruption Processor Status
  1214. ULONGLONG StIIP; // Interruption IP
  1215. ULONGLONG StIFS; // Interruption Function State
  1216. // iA32 related control registers
  1217. ULONGLONG StFCR; // copy of Ar21
  1218. ULONGLONG Eflag; // Eflag copy of Ar24
  1219. ULONGLONG SegCSD; // iA32 CSDescriptor (Ar25)
  1220. ULONGLONG SegSSD; // iA32 SSDescriptor (Ar26)
  1221. ULONGLONG Cflag; // Cr0+Cr4 copy of Ar27
  1222. ULONGLONG StFSR; // x86 FP status (copy of AR28)
  1223. ULONGLONG StFIR; // x86 FP status (copy of AR29)
  1224. ULONGLONG StFDR; // x86 FP status (copy of AR30)
  1225. ULONGLONG UNUSEDPACK; // added to pack StFDR to 16-bytes
  1226. } CONTEXT, *PCONTEXT;
  1227. //
  1228. // Plabel descriptor structure definition
  1229. //
  1230. typedef struct _PLABEL_DESCRIPTOR {
  1231. ULONGLONG EntryPoint;
  1232. ULONGLONG GlobalPointer;
  1233. } PLABEL_DESCRIPTOR, *PPLABEL_DESCRIPTOR;
  1234. // end_winnt
  1235. // IA64 Register Definitions
  1236. #if !(defined(MIDL_PASS) || defined(__midl))
  1237. // Processor Status Register (PSR) structure
  1238. #define IA64_USER_PL 3
  1239. #define IA64_KERNEL_PL 0
  1240. struct _PSR {
  1241. // User/System mask
  1242. ULONGLONG psr_rv0 :1; // 0
  1243. ULONGLONG psr_be :1; // 1
  1244. ULONGLONG psr_up :1; // 2
  1245. ULONGLONG psr_ac :1; // 3
  1246. ULONGLONG psr_mfl :1; // 4
  1247. ULONGLONG psr_mfh :1; // 5
  1248. ULONGLONG psr_rv1 :7; // 6-12
  1249. // System mask only
  1250. ULONGLONG psr_ic :1; // 13
  1251. ULONGLONG psr_i :1; // 14
  1252. ULONGLONG psr_pk :1; // 15
  1253. ULONGLONG psr_rv2 :1; // 16
  1254. ULONGLONG psr_dt :1; // 17
  1255. ULONGLONG psr_dfl :1; // 18
  1256. ULONGLONG psr_dfh :1; // 19
  1257. ULONGLONG psr_sp :1; // 20
  1258. ULONGLONG psr_pp :1; // 21
  1259. ULONGLONG psr_di :1; // 22
  1260. ULONGLONG psr_si :1; // 23
  1261. ULONGLONG psr_db :1; // 24
  1262. ULONGLONG psr_lp :1; // 25
  1263. ULONGLONG psr_tb :1; // 26
  1264. ULONGLONG psr_rt :1; // 27
  1265. ULONGLONG psr_rv3 :4; // 28-31
  1266. // Neither
  1267. ULONGLONG psr_cpl :2; // 32-33
  1268. ULONGLONG psr_is :1; // 34
  1269. ULONGLONG psr_mc :1; // 35
  1270. ULONGLONG psr_it :1; // 36
  1271. ULONGLONG psr_id :1; // 37
  1272. ULONGLONG psr_da :1; // 38
  1273. ULONGLONG psr_dd :1; // 39
  1274. ULONGLONG psr_ss :1; // 40
  1275. ULONGLONG psr_ri :2; // 41-42
  1276. ULONGLONG psr_ed :1; // 43
  1277. ULONGLONG psr_bn :1; // 44
  1278. ULONGLONG psr_ia :1; // 45
  1279. ULONGLONG psr_rv4 :18; // 46-63
  1280. };
  1281. typedef union _UPSR {
  1282. ULONGLONG ull;
  1283. struct _PSR sb;
  1284. } PSR, *PPSR;
  1285. //
  1286. // Define hardware Floating Point Status Register.
  1287. //
  1288. // Floating Point Status Register (FPSR) structure
  1289. struct _FPSR {
  1290. // Trap disable
  1291. ULONGLONG fpsr_vd:1;
  1292. ULONGLONG fpsr_dd:1;
  1293. ULONGLONG fpsr_zd:1;
  1294. ULONGLONG fpsr_od:1;
  1295. ULONGLONG fpsr_ud:1;
  1296. ULONGLONG fpsr_id:1;
  1297. // Status Field 0 - Controls
  1298. ULONGLONG fpsr_ftz0:1;
  1299. ULONGLONG fpsr_wre0:1;
  1300. ULONGLONG fpsr_pc0:2;
  1301. ULONGLONG fpsr_rc0:2;
  1302. ULONGLONG fpsr_td0:1;
  1303. // Status Field 0 - Flags
  1304. ULONGLONG fpsr_v0:1;
  1305. ULONGLONG fpsr_d0:1;
  1306. ULONGLONG fpsr_z0:1;
  1307. ULONGLONG fpsr_o0:1;
  1308. ULONGLONG fpsr_u0:1;
  1309. ULONGLONG fpsr_i0:1;
  1310. // Status Field 1 - Controls
  1311. ULONGLONG fpsr_ftz1:1;
  1312. ULONGLONG fpsr_wre1:1;
  1313. ULONGLONG fpsr_pc1:2;
  1314. ULONGLONG fpsr_rc1:2;
  1315. ULONGLONG fpsr_td1:1;
  1316. // Status Field 1 - Flags
  1317. ULONGLONG fpsr_v1:1;
  1318. ULONGLONG fpsr_d1:1;
  1319. ULONGLONG fpsr_z1:1;
  1320. ULONGLONG fpsr_o1:1;
  1321. ULONGLONG fpsr_u1:1;
  1322. ULONGLONG fpsr_i1:1;
  1323. // Status Field 2 - Controls
  1324. ULONGLONG fpsr_ftz2:1;
  1325. ULONGLONG fpsr_wre2:1;
  1326. ULONGLONG fpsr_pc2:2;
  1327. ULONGLONG fpsr_rc2:2;
  1328. ULONGLONG fpsr_td2:1;
  1329. // Status Field 2 - Flags
  1330. ULONGLONG fpsr_v2:1;
  1331. ULONGLONG fpsr_d2:1;
  1332. ULONGLONG fpsr_z2:1;
  1333. ULONGLONG fpsr_o2:1;
  1334. ULONGLONG fpsr_u2:1;
  1335. ULONGLONG fpsr_i2:1;
  1336. // Status Field 3 - Controls
  1337. ULONGLONG fpsr_ftz3:1;
  1338. ULONGLONG fpsr_wre3:1;
  1339. ULONGLONG fpsr_pc3:2;
  1340. ULONGLONG fpsr_rc3:2;
  1341. ULONGLONG fpsr_td3:1;
  1342. // Status Field 2 - Flags
  1343. ULONGLONG fpsr_v3:1;
  1344. ULONGLONG fpsr_d3:1;
  1345. ULONGLONG fpsr_z3:1;
  1346. ULONGLONG fpsr_o3:1;
  1347. ULONGLONG fpsr_u3:1;
  1348. ULONGLONG fpsr_i3:1;
  1349. // Reserved -- must be zero
  1350. ULONGLONG fpsr_res:6;
  1351. };
  1352. typedef union _UFPSR {
  1353. ULONGLONG ull;
  1354. struct _FPSR sb;
  1355. } FPSR, *PFPSR;
  1356. //
  1357. // Define hardware Default Control Register (DCR)
  1358. //
  1359. // DCR structure
  1360. struct _DCR {
  1361. ULONGLONG dcr_pp:1; // Default privileged performance monitor enable
  1362. ULONGLONG dcr_be:1; // Default interruption big endian bit
  1363. ULONGLONG dcr_lc:1; // Lock Check Enable
  1364. ULONGLONG dcr_res1:5; // DCR Reserved
  1365. ULONGLONG dcr_dm:1; // Defer data TLB miss faults (for spec loads)
  1366. ULONGLONG dcr_dp:1; // Defer data not present faults (for spec loads)
  1367. ULONGLONG dcr_dk:1; // Defer data key miss faults (for spec loads)
  1368. ULONGLONG dcr_dx:1; // Defer data key permission faults (for spec loads)
  1369. ULONGLONG dcr_dr:1; // Defer data access rights faults (for spec loads)
  1370. ULONGLONG dcr_da:1; // Defer data access faults (for spec loads)
  1371. ULONGLONG dcr_dd:1; // Defer data debug faults (for spec loads)
  1372. ULONGLONG dcr_du:1; // Defer data unaligned reference faults (for spec loads)
  1373. ULONGLONG dcr_res2:48; // DCR reserved
  1374. };
  1375. typedef union _UDCR {
  1376. ULONGLONG ull;
  1377. struct _DCR sb;
  1378. } DCR, *PDCR;
  1379. //
  1380. // Define hardware RSE Configuration Register
  1381. //
  1382. // RSC structure
  1383. struct _RSC {
  1384. ULONGLONG rsc_mode:2; // Mode field
  1385. ULONGLONG rsc_pl:2; // RSE privilege level
  1386. ULONGLONG rsc_be:1; // RSE Endian mode (0 = little; 1 = big)
  1387. ULONGLONG rsc_res0:11; // RSC reserved
  1388. ULONGLONG rsc_loadrs:14; // RSC loadrs distance (in 64-bit words)
  1389. ULONGLONG rsc_preload:14; // Software field in reserved part of register
  1390. ULONGLONG rsc_res1:20; // RSC reserved
  1391. };
  1392. typedef union _URSC {
  1393. ULONGLONG ull;
  1394. struct _RSC sb;
  1395. } RSC, *PRSC;
  1396. //
  1397. // Define hardware Interruption Status Register (ISR)
  1398. //
  1399. // ISR structure
  1400. struct _ISR {
  1401. ULONGLONG isr_code:16; // code
  1402. ULONGLONG isr_vector:8; // iA32 vector
  1403. ULONGLONG isr_res0:8; // ISR reserved
  1404. ULONGLONG isr_x:1; // Execute exception
  1405. ULONGLONG isr_w:1; // Write exception
  1406. ULONGLONG isr_r:1; // Read exception
  1407. ULONGLONG isr_na:1; // Non-access exception
  1408. ULONGLONG isr_sp:1; // Speculative load exception
  1409. ULONGLONG isr_rs:1; // Register stack exception
  1410. ULONGLONG isr_ir:1; // Invalid register frame
  1411. ULONGLONG isr_ni:1; // Nested interruption
  1412. ULONGLONG isr_res1:1; // ISR reserved
  1413. ULONGLONG isr_ei:2; // Instruction slot
  1414. ULONGLONG isr_ed:1; // Exception deferral
  1415. ULONGLONG isr_res2:20; // ISR reserved
  1416. };
  1417. typedef union _UISR {
  1418. ULONGLONG ull;
  1419. struct _ISR sb;
  1420. } ISR, *PISR;
  1421. //
  1422. // Define hardware Previous Function State (PFS)
  1423. //
  1424. #define PFS_MAXIMUM_REGISTER_SIZE 96
  1425. #define PFS_MAXIMUM_PREDICATE_SIZE 48
  1426. struct _IA64_PFS {
  1427. ULONGLONG pfs_sof:7; // Size of frame
  1428. ULONGLONG pfs_sol:7; // Size of locals
  1429. ULONGLONG pfs_sor:4; // Size of rotating portion of stack frame
  1430. ULONGLONG pfs_rrb_gr:7; // Register rename base for general registers
  1431. ULONGLONG pfs_rrb_fr:7; // Register rename base for floating-point registers
  1432. ULONGLONG pfs_rrb_pr:6; // Register rename base for predicate registers
  1433. ULONGLONG pfs_reserved1:14; // Reserved must be zero
  1434. ULONGLONG pfs_pec:6; // Previous Epilog Count
  1435. ULONGLONG pfs_reserved2:4; // Reserved must be zero
  1436. ULONGLONG pfs_ppl:2; // Previous Privilege Level
  1437. };
  1438. typedef union _UIA64_PFS {
  1439. ULONGLONG ull;
  1440. struct _IA64_PFS sb;
  1441. } IA64_PFS, *PIA64_PFS;
  1442. struct _IA64_BSP {
  1443. ULONGLONG bsplow : 3; // Size of frame
  1444. ULONGLONG bsp83 : 6; // Size of locals
  1445. ULONGLONG bsphigh : 55;
  1446. };
  1447. typedef union _UIA64_BSP {
  1448. ULONGLONG ull;
  1449. struct _IA64_BSP sb;
  1450. } IA64_BSP;
  1451. #endif // MIDL_PASS
  1452. //
  1453. // EM Debug Register related fields.
  1454. //
  1455. #define DBR_RDWR 0xC000000000000000ULL
  1456. #define DBR_WR 0x4000000000000000ULL
  1457. #define DBR_RD 0x8000000000000000ULL
  1458. #define IBR_EX 0x8000000000000000ULL
  1459. #define DBG_REG_PLM_USER 0x0800000000000000ULL
  1460. #define DBG_MASK_MASK 0x00FFFFFFFFFFFFFFULL
  1461. #define DBG_REG_MASK(VAL) (ULONGLONG)(((((ULONGLONG)(VAL) \
  1462. << 8) >> 8)) ^ DBG_MASK_MASK)
  1463. #define DBG_MASK_LENGTH(DBG) (ULONGLONG)(DBG_REG_MASK(DBG))
  1464. #define IS_DBR_RDWR(DBR) (((DBR) & DBR_RDWR) == DBR_RDWR)
  1465. #define IS_DBR_WR(DBR) (((DBR) & DBR_RDWR) == DBR_WR)
  1466. #define IS_DBR_RD(DBR) (((DBR) & DBR_RDWR) == DBR_RD)
  1467. #define IS_IBR_EX(IBR) (((IBR) & IBR_EX) == IBR_EX)
  1468. #define DBR_ACTIVE(DBR) (IS_DBR_RDWR(DBR) || IS_DBR_WR(DBR) || IS_DBR_RD(DBR))
  1469. #define IBR_ACTIVE(IBR) (IS_IBR_EX(IBR))
  1470. #define DBR_SET_IA_RW(DBR, T, F) (DBR_ACTIVE(DBR) ? (T) : (F))
  1471. #define IBR_SET_IA_RW(IBR, T, F) (IBR_ACTIVE(IBR) ? (T) : (F))
  1472. #define SET_IF_DBR_RDWR(DBR, T, F) (IS_DBR_RDWR(DBR) ? (T) : (F))
  1473. #define SET_IF_DBR_WR(DBR, T, F) (IS_DBR_WR(DBR) ? (T) : (F))
  1474. #define SET_IF_IBR_EX(DBR, T, F) (IS_IBR_EX(DBR) ? (T) : (F))
  1475. //
  1476. // Get the iA mode Debgug R/W Debug register value from the
  1477. // specified EM debug registers.
  1478. //
  1479. // N.B. Arbitrary order of checking DBR then IBR.
  1480. //
  1481. // TBD Not sure how to get DR7_RW_IORW from EM Debug Info?
  1482. //
  1483. #define DBG_EM_ENABLE_TO_IA_RW(DBR, IBR) (UCHAR) \
  1484. DBR_SET_IA_RW(DBR, SET_IF_DBR_RDWR(DBR, DR7_RW_DWR, \
  1485. SET_IF_DBR_WR(DBR, DR7_RW_DW, 0)), \
  1486. SET_IF_IBR_EX(IBR, SET_IF_IBR_EX(IBR, DR7_RW_IX, 0), 0))
  1487. //
  1488. // Get the iA mode Len Debug register value from the
  1489. // specified EM debug registers.
  1490. //
  1491. // N.B. Arbitrary order of checking DBR then IBR.
  1492. //
  1493. //
  1494. #define IA_DR_LENGTH(VAL) ((UCHAR)((((VAL) << 62) >> 62) + 1))
  1495. #define DBG_EM_MASK_TO_IA_LEN(DBR, IBR) \
  1496. ((UCHAR)((DBR_ACTIVE(DBR) ? IA_DR_LENGTH(DBG_MASK_LENGTH(DBR)) : \
  1497. (DBR_ACTIVE(IBR) ? IA_DR_LENGTH(DBG_MASK_LENGTH(IBR)) : 0))))
  1498. //
  1499. // Get the iA mode Len Debug register value from the
  1500. // specified EM debug registers.
  1501. //
  1502. // N.B. Arbitrary order of checking DBR then IBR.
  1503. //
  1504. //
  1505. #define DBG_EM_ADDR_TO_IA_ADDR(DBR, IBR) \
  1506. (UCHAR)(DBR_ACTIVE(DBR) ? (ULONG) DBR : \
  1507. (DBR_ACTIVE(IBR) ? (ULONG) IBR : 0))
  1508. //
  1509. // Extract iA mode FP Status Registers from EM mode Context
  1510. //
  1511. #define RES_FTR(FTR) ((FTR) & 0x000000005555FFC0ULL)
  1512. #define RES_FCW(FCW) ((FCW) & 0x0F3F) // Bits 6-7, 12-15 Reserved
  1513. #define FPSTAT_FSW(FPSR, FTR) \
  1514. (ULONG)((((FPSR) << 45) >> 58) | ((RES_FTR(FTR) << 48) >> 48))
  1515. #define FPSTAT_FCW(FPSR) (ULONG)(((FPSR) << 53) >> 53)
  1516. #define FPSTAT_FTW(FTR) (ULONG)(((FTR) << 32) >> 48)
  1517. #define FPSTAT_EOFF(FIR) (ULONG)(((FIR) << 32) >> 32)
  1518. #define FPSTAT_ESEL(FIR) (ULONG)(((FIR) << 16) >> 48)
  1519. #define FPSTAT_DOFF(FDR) (ULONG)(((FDR) << 32) >> 32)
  1520. #define FPSTAT_DSEL(FDR) (ULONG)(((FDR) << 16) >> 48)
  1521. #define FPSTAT_CR0(KR0) (ULONG)(((KR0) << 32) >> 32)
  1522. //
  1523. // Setting FPSR from IA Mode Registers
  1524. //
  1525. // Bits Map as Follows: FPSR[11:0] <= FCW[11:0]
  1526. // FPSR[12:12] <= Reserved (must be zero)
  1527. // FPSR[18:13] <= FSW[5:0]
  1528. // FPSR[57:19] <= FPSR residual data
  1529. // FPSR[59:58] <= Reserved (must be zero)
  1530. // FPSR[63:60] <= FPSR residual data
  1531. //
  1532. #define IA_SET_FPSR(FPSR, FSW, FCW) \
  1533. (ULONGLONG)(((ULONGLONG)(FPSR) & 0xF3FFFFFFFFF80000ULL) | \
  1534. (((ULONG)(FSW) & 0x0000002FUL) << 13) | \
  1535. ((ULONG)(FCW) & 0x0F3FUL))
  1536. #define IA_SET_FTR(FTR, FTW, FSW) \
  1537. (ULONGLONG)(((ULONGLONG)(FTR) & 0x0000000000000000ULL) | \
  1538. ((ULONGLONG)(FTW) << 16) | \
  1539. ((ULONG)(FSW) & 0xFFC0UL))
  1540. #define IA_SET_FDR(FDS, FEA) (ULONGLONG)((((ULONGLONG)(FDS) << 48) >> 16) | (ULONG)(FEA))
  1541. #define IA_SET_FIR(FOP,FCS,FIP) (ULONGLONG)((((ULONGLONG)(FOP) << 52) >> 4) | \
  1542. (ULONG)(((FCS) << 48) >> 16) | (ULONG)(FIP))
  1543. #define IA_SET_CFLAG(CLFAG, CR0) (ULONGLONG)(((ULONGLONG)(CLFAG) & 0x000001ffe005003fULL) | CR0)
  1544. //
  1545. // Fields related to iA mode Debug Register 7 - Dr7.
  1546. //
  1547. #define DR7_RW_IX 0x00000000UL
  1548. #define DR7_RW_DW 0x00000001UL
  1549. #define DR7_RW_IORW 0x00000002UL
  1550. #define DR7_RW_DWR 0x00000003UL
  1551. #define DR7_RW_DISABLE 0xFFFFFFFFUL
  1552. #define DR7_L0(DR7) ((ULONG)(DR7) & 0x00000001UL)
  1553. #define DR7_L1(DR7) ((ULONG)(DR7) & 0x00000004UL)
  1554. #define DR7_L2(DR7) ((ULONG)(DR7) & 0x00000010UL)
  1555. #define DR7_L3(DR7) ((ULONG)(DR7) & 0x00000040UL)
  1556. #define SET_DR7_L0(DR7) ((ULONG)(DR7) &= 0x00000001UL)
  1557. #define SET_DR7_L1(DR7) ((ULONG)(DR7) &= 0x00000004UL)
  1558. #define SET_DR7_L2(DR7) ((ULONG)(DR7) &= 0x00000010UL)
  1559. #define SET_DR7_L3(DR7) ((ULONG)(DR7) &= 0x00000040UL)
  1560. #define DR7_DB0_RW(DR7) (DR7_L0(DR7) ? (((ULONG)(DR7) >> 16) & 0x00000003UL) : DR7_RW_DISABLE)
  1561. #define DR7_DB0_LEN(DR7) (DR7_L0(DR7) ? (((ULONG)(DR7) >> 18) & 0x00000003UL) : DR7_RW_DISABLE)
  1562. #define DR7_DB1_RW(DR7) (DR7_L1(DR7) ? (((ULONG)(DR7) >> 20) & 0x00000003UL) : DR7_RW_DISABLE)
  1563. #define DR7_DB1_LEN(DR7) (DR7_L1(DR7) ? (((ULONG)(DR7) >> 22) & 0x00000003UL) : DR7_RW_DISABLE)
  1564. #define DR7_DB2_RW(DR7) (DR7_L2(DR7) ? (((ULONG)(DR7) >> 24) & 0x00000003UL) : DR7_RW_DISABLE)
  1565. #define DR7_DB2_LEN(DR7) (DR7_L2(DR7) ? (((ULONG)(DR7) >> 26) & 0x00000003UL) : DR7_RW_DISABLE)
  1566. #define DR7_DB3_RW(DR7) (DR7_L3(DR7) ? (((ULONG)(DR7) >> 28) & 0x00000003UL) : DR7_RW_DISABLE)
  1567. #define DR7_DB3_LEN(DR7) (DR7_L3(DR7) ? (((ULONG)(DR7) >> 30) & 0x00000003UL) : DR7_RW_DISABLE)
  1568. #define SET_DR7_DB0_RW(DR7,VAL) ((ULONG)(DR7) |= ((VAL & 0x00000003UL) << 16))
  1569. #define SET_DR7_DB0_LEN(DR7,VAL) ((ULONG)(DR7) |= ((VAL & 0x00000003UL) << 18))
  1570. #define SET_DR7_DB1_RW(DR7,VAL) ((ULONG)(DR7) |= ((VAL & 0x00000003UL) << 20))
  1571. #define SET_DR7_DB1_LEN(DR7,VAL) ((ULONG)(DR7) |= ((VAL & 0x00000003UL) << 22))
  1572. #define SET_DR7_DB2_RW(DR7,VAL) ((ULONG)(DR7) |= ((VAL & 0x00000003UL) << 24))
  1573. #define SET_DR7_DB2_LEN(DR7,VAL) ((ULONG)(DR7) |= ((VAL & 0x00000003UL) << 26))
  1574. #define SET_DR7_DB3_RW(DR7,VAL) ((ULONG)(DR7) |= ((VAL & 0x00000003UL) << 28))
  1575. #define SET_DR7_DB3_LEN(DR7,VAL) ((ULONG)(DR7) |= ((VAL & 0x00000003UL) << 30))
  1576. #define DR_ADDR_L0(DR) (DR7_L0(DR) ? ((ULONG)(DR)) : 0UL)
  1577. #define DR_ADDR_L1(DR) (DR7_L1(DR) ? ((ULONG)(DR)) : 0UL)
  1578. #define DR_ADDR_L2(DR) (DR7_L2(DR) ? ((ULONG)(DR)) : 0UL)
  1579. #define DR_ADDR_L3(DR) (DR7_L3(DR) ? ((ULONG)(DR)) : 0UL)
  1580. #endif // _IA64_
  1581. #if defined(_WIN64)
  1582. #define MAXIMUM_PROCESSORS 64
  1583. #else
  1584. #define MAXIMUM_PROCESSORS 32
  1585. #endif
  1586. //
  1587. // ClientId
  1588. //
  1589. typedef struct _CLIENT_ID {
  1590. HANDLE UniqueProcess;
  1591. HANDLE UniqueThread;
  1592. } CLIENT_ID;
  1593. typedef CLIENT_ID *PCLIENT_ID;
  1594. //
  1595. // Thread Environment Block (and portable part of Thread Information Block)
  1596. //
  1597. //
  1598. // NT_TIB - Thread Information Block - Portable part.
  1599. //
  1600. // This is the subsystem portable part of the Thread Information Block.
  1601. // It appears as the first part of the TEB for all threads which have
  1602. // a user mode component.
  1603. //
  1604. //
  1605. // begin_winnt
  1606. typedef struct _NT_TIB {
  1607. struct _EXCEPTION_REGISTRATION_RECORD *ExceptionList;
  1608. PVOID StackBase;
  1609. PVOID StackLimit;
  1610. PVOID SubSystemTib;
  1611. union {
  1612. PVOID FiberData;
  1613. ULONG Version;
  1614. };
  1615. PVOID ArbitraryUserPointer;
  1616. struct _NT_TIB *Self;
  1617. } NT_TIB;
  1618. typedef NT_TIB *PNT_TIB;
  1619. //
  1620. // 32 and 64 bit specific version for wow64 and the debugger
  1621. //
  1622. typedef struct _NT_TIB32 {
  1623. ULONG ExceptionList;
  1624. ULONG StackBase;
  1625. ULONG StackLimit;
  1626. ULONG SubSystemTib;
  1627. union {
  1628. ULONG FiberData;
  1629. ULONG Version;
  1630. };
  1631. ULONG ArbitraryUserPointer;
  1632. ULONG Self;
  1633. } NT_TIB32, *PNT_TIB32;
  1634. typedef struct _NT_TIB64 {
  1635. ULONG64 ExceptionList;
  1636. ULONG64 StackBase;
  1637. ULONG64 StackLimit;
  1638. ULONG64 SubSystemTib;
  1639. union {
  1640. ULONG64 FiberData;
  1641. ULONG Version;
  1642. };
  1643. ULONG64 ArbitraryUserPointer;
  1644. ULONG64 Self;
  1645. } NT_TIB64, *PNT_TIB64;
  1646. //
  1647. // Define the various device type values. Note that values used by Microsoft
  1648. // Corporation are in the range 0-32767, and 32768-65535 are reserved for use
  1649. // by customers.
  1650. //
  1651. #define DEVICE_TYPE ULONG
  1652. #define FILE_DEVICE_BEEP 0x00000001
  1653. #define FILE_DEVICE_CD_ROM 0x00000002
  1654. #define FILE_DEVICE_CD_ROM_FILE_SYSTEM 0x00000003
  1655. #define FILE_DEVICE_CONTROLLER 0x00000004
  1656. #define FILE_DEVICE_DATALINK 0x00000005
  1657. #define FILE_DEVICE_DFS 0x00000006
  1658. #define FILE_DEVICE_DISK 0x00000007
  1659. #define FILE_DEVICE_DISK_FILE_SYSTEM 0x00000008
  1660. #define FILE_DEVICE_FILE_SYSTEM 0x00000009
  1661. #define FILE_DEVICE_INPORT_PORT 0x0000000a
  1662. #define FILE_DEVICE_KEYBOARD 0x0000000b
  1663. #define FILE_DEVICE_MAILSLOT 0x0000000c
  1664. #define FILE_DEVICE_MIDI_IN 0x0000000d
  1665. #define FILE_DEVICE_MIDI_OUT 0x0000000e
  1666. #define FILE_DEVICE_MOUSE 0x0000000f
  1667. #define FILE_DEVICE_MULTI_UNC_PROVIDER 0x00000010
  1668. #define FILE_DEVICE_NAMED_PIPE 0x00000011
  1669. #define FILE_DEVICE_NETWORK 0x00000012
  1670. #define FILE_DEVICE_NETWORK_BROWSER 0x00000013
  1671. #define FILE_DEVICE_NETWORK_FILE_SYSTEM 0x00000014
  1672. #define FILE_DEVICE_NULL 0x00000015
  1673. #define FILE_DEVICE_PARALLEL_PORT 0x00000016
  1674. #define FILE_DEVICE_PHYSICAL_NETCARD 0x00000017
  1675. #define FILE_DEVICE_PRINTER 0x00000018
  1676. #define FILE_DEVICE_SCANNER 0x00000019
  1677. #define FILE_DEVICE_SERIAL_MOUSE_PORT 0x0000001a
  1678. #define FILE_DEVICE_SERIAL_PORT 0x0000001b
  1679. #define FILE_DEVICE_SCREEN 0x0000001c
  1680. #define FILE_DEVICE_SOUND 0x0000001d
  1681. #define FILE_DEVICE_STREAMS 0x0000001e
  1682. #define FILE_DEVICE_TAPE 0x0000001f
  1683. #define FILE_DEVICE_TAPE_FILE_SYSTEM 0x00000020
  1684. #define FILE_DEVICE_TRANSPORT 0x00000021
  1685. #define FILE_DEVICE_UNKNOWN 0x00000022
  1686. #define FILE_DEVICE_VIDEO 0x00000023
  1687. #define FILE_DEVICE_VIRTUAL_DISK 0x00000024
  1688. #define FILE_DEVICE_WAVE_IN 0x00000025
  1689. #define FILE_DEVICE_WAVE_OUT 0x00000026
  1690. #define FILE_DEVICE_8042_PORT 0x00000027
  1691. #define FILE_DEVICE_NETWORK_REDIRECTOR 0x00000028
  1692. #define FILE_DEVICE_BATTERY 0x00000029
  1693. #define FILE_DEVICE_BUS_EXTENDER 0x0000002a
  1694. #define FILE_DEVICE_MODEM 0x0000002b
  1695. #define FILE_DEVICE_VDM 0x0000002c
  1696. #define FILE_DEVICE_MASS_STORAGE 0x0000002d
  1697. #define FILE_DEVICE_SMB 0x0000002e
  1698. #define FILE_DEVICE_KS 0x0000002f
  1699. #define FILE_DEVICE_CHANGER 0x00000030
  1700. #define FILE_DEVICE_SMARTCARD 0x00000031
  1701. #define FILE_DEVICE_ACPI 0x00000032
  1702. #define FILE_DEVICE_DVD 0x00000033
  1703. #define FILE_DEVICE_FULLSCREEN_VIDEO 0x00000034
  1704. #define FILE_DEVICE_DFS_FILE_SYSTEM 0x00000035
  1705. #define FILE_DEVICE_DFS_VOLUME 0x00000036
  1706. #define FILE_DEVICE_SERENUM 0x00000037
  1707. #define FILE_DEVICE_TERMSRV 0x00000038
  1708. #define FILE_DEVICE_KSEC 0x00000039
  1709. #define FILE_DEVICE_FIPS 0x0000003A
  1710. #define FILE_DEVICE_INFINIBAND 0x0000003B
  1711. //
  1712. // Macro definition for defining IOCTL and FSCTL function control codes. Note
  1713. // that function codes 0-2047 are reserved for Microsoft Corporation, and
  1714. // 2048-4095 are reserved for customers.
  1715. //
  1716. #define CTL_CODE( DeviceType, Function, Method, Access ) ( \
  1717. ((DeviceType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method) \
  1718. )
  1719. //
  1720. // Macro to extract device type out of the device io control code
  1721. //
  1722. #define DEVICE_TYPE_FROM_CTL_CODE(ctrlCode) (((ULONG)(ctrlCode & 0xffff0000)) >> 16)
  1723. //
  1724. // Define the method codes for how buffers are passed for I/O and FS controls
  1725. //
  1726. #define METHOD_BUFFERED 0
  1727. #define METHOD_IN_DIRECT 1
  1728. #define METHOD_OUT_DIRECT 2
  1729. #define METHOD_NEITHER 3
  1730. //
  1731. // Define some easier to comprehend aliases:
  1732. // METHOD_DIRECT_TO_HARDWARE (writes, aka METHOD_IN_DIRECT)
  1733. // METHOD_DIRECT_FROM_HARDWARE (reads, aka METHOD_OUT_DIRECT)
  1734. //
  1735. #define METHOD_DIRECT_TO_HARDWARE METHOD_IN_DIRECT
  1736. #define METHOD_DIRECT_FROM_HARDWARE METHOD_OUT_DIRECT
  1737. //
  1738. // Define the access check value for any access
  1739. //
  1740. //
  1741. // The FILE_READ_ACCESS and FILE_WRITE_ACCESS constants are also defined in
  1742. // ntioapi.h as FILE_READ_DATA and FILE_WRITE_DATA. The values for these
  1743. // constants *MUST* always be in sync.
  1744. //
  1745. //
  1746. // FILE_SPECIAL_ACCESS is checked by the NT I/O system the same as FILE_ANY_ACCESS.
  1747. // The file systems, however, may add additional access checks for I/O and FS controls
  1748. // that use this value.
  1749. //
  1750. #define FILE_ANY_ACCESS 0
  1751. #define FILE_SPECIAL_ACCESS (FILE_ANY_ACCESS)
  1752. #define FILE_READ_ACCESS ( 0x0001 ) // file & pipe
  1753. #define FILE_WRITE_ACCESS ( 0x0002 ) // file & pipe
  1754. //
  1755. // Define an access token from a programmer's viewpoint. The structure is
  1756. // completely opaque and the programer is only allowed to have pointers
  1757. // to tokens.
  1758. //
  1759. typedef PVOID PACCESS_TOKEN; // winnt
  1760. //
  1761. // Pointer to a SECURITY_DESCRIPTOR opaque data type.
  1762. //
  1763. typedef PVOID PSECURITY_DESCRIPTOR; // winnt
  1764. //
  1765. // Define a pointer to the Security ID data type (an opaque data type)
  1766. //
  1767. typedef PVOID PSID; // winnt
  1768. typedef ULONG ACCESS_MASK;
  1769. typedef ACCESS_MASK *PACCESS_MASK;
  1770. // end_winnt
  1771. //
  1772. // The following are masks for the predefined standard access types
  1773. //
  1774. #define DELETE (0x00010000L)
  1775. #define READ_CONTROL (0x00020000L)
  1776. #define WRITE_DAC (0x00040000L)
  1777. #define WRITE_OWNER (0x00080000L)
  1778. #define SYNCHRONIZE (0x00100000L)
  1779. #define STANDARD_RIGHTS_REQUIRED (0x000F0000L)
  1780. #define STANDARD_RIGHTS_READ (READ_CONTROL)
  1781. #define STANDARD_RIGHTS_WRITE (READ_CONTROL)
  1782. #define STANDARD_RIGHTS_EXECUTE (READ_CONTROL)
  1783. #define STANDARD_RIGHTS_ALL (0x001F0000L)
  1784. #define SPECIFIC_RIGHTS_ALL (0x0000FFFFL)
  1785. //
  1786. // AccessSystemAcl access type
  1787. //
  1788. #define ACCESS_SYSTEM_SECURITY (0x01000000L)
  1789. //
  1790. // MaximumAllowed access type
  1791. //
  1792. #define MAXIMUM_ALLOWED (0x02000000L)
  1793. //
  1794. // These are the generic rights.
  1795. //
  1796. #define GENERIC_READ (0x80000000L)
  1797. #define GENERIC_WRITE (0x40000000L)
  1798. #define GENERIC_EXECUTE (0x20000000L)
  1799. #define GENERIC_ALL (0x10000000L)
  1800. //
  1801. // Define the generic mapping array. This is used to denote the
  1802. // mapping of each generic access right to a specific access mask.
  1803. //
  1804. typedef struct _GENERIC_MAPPING {
  1805. ACCESS_MASK GenericRead;
  1806. ACCESS_MASK GenericWrite;
  1807. ACCESS_MASK GenericExecute;
  1808. ACCESS_MASK GenericAll;
  1809. } GENERIC_MAPPING;
  1810. typedef GENERIC_MAPPING *PGENERIC_MAPPING;
  1811. ////////////////////////////////////////////////////////////////////////
  1812. // //
  1813. // LUID_AND_ATTRIBUTES //
  1814. // //
  1815. ////////////////////////////////////////////////////////////////////////
  1816. //
  1817. //
  1818. #include <pshpack4.h>
  1819. typedef struct _LUID_AND_ATTRIBUTES {
  1820. LUID Luid;
  1821. ULONG Attributes;
  1822. } LUID_AND_ATTRIBUTES, * PLUID_AND_ATTRIBUTES;
  1823. typedef LUID_AND_ATTRIBUTES LUID_AND_ATTRIBUTES_ARRAY[ANYSIZE_ARRAY];
  1824. typedef LUID_AND_ATTRIBUTES_ARRAY *PLUID_AND_ATTRIBUTES_ARRAY;
  1825. #include <poppack.h>
  1826. //
  1827. // Privilege attributes
  1828. //
  1829. #define SE_PRIVILEGE_ENABLED_BY_DEFAULT (0x00000001L)
  1830. #define SE_PRIVILEGE_ENABLED (0x00000002L)
  1831. #define SE_PRIVILEGE_REMOVED (0X00000004L)
  1832. #define SE_PRIVILEGE_USED_FOR_ACCESS (0x80000000L)
  1833. //
  1834. // Privilege Set Control flags
  1835. //
  1836. #define PRIVILEGE_SET_ALL_NECESSARY (1)
  1837. //
  1838. // Privilege Set - This is defined for a privilege set of one.
  1839. // If more than one privilege is needed, then this structure
  1840. // will need to be allocated with more space.
  1841. //
  1842. // Note: don't change this structure without fixing the INITIAL_PRIVILEGE_SET
  1843. // structure (defined in se.h)
  1844. //
  1845. typedef struct _PRIVILEGE_SET {
  1846. ULONG PrivilegeCount;
  1847. ULONG Control;
  1848. LUID_AND_ATTRIBUTES Privilege[ANYSIZE_ARRAY];
  1849. } PRIVILEGE_SET, * PPRIVILEGE_SET;
  1850. //
  1851. // Impersonation Level
  1852. //
  1853. // Impersonation level is represented by a pair of bits in Windows.
  1854. // If a new impersonation level is added or lowest value is changed from
  1855. // 0 to something else, fix the Windows CreateFile call.
  1856. //
  1857. typedef enum _SECURITY_IMPERSONATION_LEVEL {
  1858. SecurityAnonymous,
  1859. SecurityIdentification,
  1860. SecurityImpersonation,
  1861. SecurityDelegation
  1862. } SECURITY_IMPERSONATION_LEVEL, * PSECURITY_IMPERSONATION_LEVEL;
  1863. #define SECURITY_MAX_IMPERSONATION_LEVEL SecurityDelegation
  1864. #define SECURITY_MIN_IMPERSONATION_LEVEL SecurityAnonymous
  1865. #define DEFAULT_IMPERSONATION_LEVEL SecurityImpersonation
  1866. #define VALID_IMPERSONATION_LEVEL(L) (((L) >= SECURITY_MIN_IMPERSONATION_LEVEL) && ((L) <= SECURITY_MAX_IMPERSONATION_LEVEL))
  1867. typedef ULONG SECURITY_INFORMATION, *PSECURITY_INFORMATION;
  1868. #define OWNER_SECURITY_INFORMATION (0x00000001L)
  1869. #define GROUP_SECURITY_INFORMATION (0x00000002L)
  1870. #define DACL_SECURITY_INFORMATION (0x00000004L)
  1871. #define SACL_SECURITY_INFORMATION (0x00000008L)
  1872. #define PROTECTED_DACL_SECURITY_INFORMATION (0x80000000L)
  1873. #define PROTECTED_SACL_SECURITY_INFORMATION (0x40000000L)
  1874. #define UNPROTECTED_DACL_SECURITY_INFORMATION (0x20000000L)
  1875. #define UNPROTECTED_SACL_SECURITY_INFORMATION (0x10000000L)
  1876. #define LOW_PRIORITY 0 // Lowest thread priority level
  1877. #define LOW_REALTIME_PRIORITY 16 // Lowest realtime priority level
  1878. #define HIGH_PRIORITY 31 // Highest thread priority level
  1879. #define MAXIMUM_PRIORITY 32 // Number of thread priority levels
  1880. // begin_winnt
  1881. #define MAXIMUM_WAIT_OBJECTS 64 // Maximum number of wait objects
  1882. #define MAXIMUM_SUSPEND_COUNT MAXCHAR // Maximum times thread can be suspended
  1883. // end_winnt
  1884. //
  1885. // Define system time structure.
  1886. //
  1887. typedef struct _KSYSTEM_TIME {
  1888. ULONG LowPart;
  1889. LONG High1Time;
  1890. LONG High2Time;
  1891. } KSYSTEM_TIME, *PKSYSTEM_TIME;
  1892. //
  1893. // Thread priority
  1894. //
  1895. typedef LONG KPRIORITY;
  1896. //
  1897. // Spin Lock
  1898. //
  1899. // begin_ntndis begin_winnt
  1900. typedef ULONG_PTR KSPIN_LOCK;
  1901. typedef KSPIN_LOCK *PKSPIN_LOCK;
  1902. // end_ntndis end_winnt end_wdm
  1903. //
  1904. // Define per processor lock queue structure.
  1905. //
  1906. // N.B. The lock field of the spin lock queue structure contains the address
  1907. // of the associated kernel spin lock, an owner bit, and a lock bit. Bit
  1908. // 0 of the spin lock address is the wait bit and bit 1 is the owner bit.
  1909. // The use of this field is such that the bits can be set and cleared
  1910. // noninterlocked, however, the back pointer must be preserved.
  1911. //
  1912. // The lock wait bit is set when a processor enqueues itself on the lock
  1913. // queue and it is not the only entry in the queue. The processor will
  1914. // spin on this bit waiting for the lock to be granted.
  1915. //
  1916. // The owner bit is set when the processor owns the respective lock.
  1917. //
  1918. // The next field of the spin lock queue structure is used to line the
  1919. // queued lock structures together in fifo order. It also can set set and
  1920. // cleared noninterlocked.
  1921. //
  1922. #define LOCK_QUEUE_WAIT 1
  1923. #define LOCK_QUEUE_OWNER 2
  1924. typedef enum _KSPIN_LOCK_QUEUE_NUMBER {
  1925. LockQueueDispatcherLock,
  1926. LockQueueUnusedSpare1,
  1927. LockQueuePfnLock,
  1928. LockQueueSystemSpaceLock,
  1929. LockQueueVacbLock,
  1930. LockQueueMasterLock,
  1931. LockQueueNonPagedPoolLock,
  1932. LockQueueIoCancelLock,
  1933. LockQueueWorkQueueLock,
  1934. LockQueueIoVpbLock,
  1935. LockQueueIoDatabaseLock,
  1936. LockQueueIoCompletionLock,
  1937. LockQueueNtfsStructLock,
  1938. LockQueueAfdWorkQueueLock,
  1939. LockQueueBcbLock,
  1940. LockQueueMmNonPagedPoolLock,
  1941. LockQueueMaximumLock
  1942. } KSPIN_LOCK_QUEUE_NUMBER, *PKSPIN_LOCK_QUEUE_NUMBER;
  1943. typedef struct _KSPIN_LOCK_QUEUE {
  1944. struct _KSPIN_LOCK_QUEUE * volatile Next;
  1945. PKSPIN_LOCK volatile Lock;
  1946. } KSPIN_LOCK_QUEUE, *PKSPIN_LOCK_QUEUE;
  1947. typedef struct _KLOCK_QUEUE_HANDLE {
  1948. KSPIN_LOCK_QUEUE LockQueue;
  1949. KIRQL OldIrql;
  1950. } KLOCK_QUEUE_HANDLE, *PKLOCK_QUEUE_HANDLE;
  1951. // begin_wdm
  1952. //
  1953. // Interrupt routine (first level dispatch)
  1954. //
  1955. typedef
  1956. VOID
  1957. (*PKINTERRUPT_ROUTINE) (
  1958. VOID
  1959. );
  1960. //
  1961. // Profile source types
  1962. //
  1963. typedef enum _KPROFILE_SOURCE {
  1964. ProfileTime,
  1965. ProfileAlignmentFixup,
  1966. ProfileTotalIssues,
  1967. ProfilePipelineDry,
  1968. ProfileLoadInstructions,
  1969. ProfilePipelineFrozen,
  1970. ProfileBranchInstructions,
  1971. ProfileTotalNonissues,
  1972. ProfileDcacheMisses,
  1973. ProfileIcacheMisses,
  1974. ProfileCacheMisses,
  1975. ProfileBranchMispredictions,
  1976. ProfileStoreInstructions,
  1977. ProfileFpInstructions,
  1978. ProfileIntegerInstructions,
  1979. Profile2Issue,
  1980. Profile3Issue,
  1981. Profile4Issue,
  1982. ProfileSpecialInstructions,
  1983. ProfileTotalCycles,
  1984. ProfileIcacheIssues,
  1985. ProfileDcacheAccesses,
  1986. ProfileMemoryBarrierCycles,
  1987. ProfileLoadLinkedIssues,
  1988. ProfileMaximum
  1989. } KPROFILE_SOURCE;
  1990. #if defined(USE_LPC6432)
  1991. #define LPC_CLIENT_ID CLIENT_ID64
  1992. #define LPC_SIZE_T ULONGLONG
  1993. #define LPC_PVOID ULONGLONG
  1994. #define LPC_HANDLE ULONGLONG
  1995. #else
  1996. #define LPC_CLIENT_ID CLIENT_ID
  1997. #define LPC_SIZE_T SIZE_T
  1998. #define LPC_PVOID PVOID
  1999. #define LPC_HANDLE HANDLE
  2000. #endif
  2001. typedef struct _PORT_MESSAGE {
  2002. union {
  2003. struct {
  2004. CSHORT DataLength;
  2005. CSHORT TotalLength;
  2006. } s1;
  2007. ULONG Length;
  2008. } u1;
  2009. union {
  2010. struct {
  2011. CSHORT Type;
  2012. CSHORT DataInfoOffset;
  2013. } s2;
  2014. ULONG ZeroInit;
  2015. } u2;
  2016. union {
  2017. LPC_CLIENT_ID ClientId;
  2018. double DoNotUseThisField; // Force quadword alignment
  2019. };
  2020. ULONG MessageId;
  2021. union {
  2022. LPC_SIZE_T ClientViewSize; // Only valid on LPC_CONNECTION_REQUEST message
  2023. ULONG CallbackId; // Only valid on LPC_REQUEST message
  2024. };
  2025. // UCHAR Data[];
  2026. } PORT_MESSAGE, *PPORT_MESSAGE;
  2027. //
  2028. // for move macros
  2029. //
  2030. #ifdef _MAC
  2031. #ifndef _INC_STRING
  2032. #include <string.h>
  2033. #endif /* _INC_STRING */
  2034. #else
  2035. #include <string.h>
  2036. #endif // _MAC
  2037. #ifndef _SLIST_HEADER_
  2038. #define _SLIST_HEADER_
  2039. #if defined(_WIN64)
  2040. //
  2041. // The type SINGLE_LIST_ENTRY is not suitable for use with SLISTs. For
  2042. // WIN64, an entry on an SLIST is required to be 16-byte aligned, while a
  2043. // SINGLE_LIST_ENTRY structure has only 8 byte alignment.
  2044. //
  2045. // Therefore, all SLIST code should use the SLIST_ENTRY type instead of the
  2046. // SINGLE_LIST_ENTRY type.
  2047. //
  2048. #pragma warning(push)
  2049. #pragma warning(disable:4324) // structure padded due to align()
  2050. typedef struct DECLSPEC_ALIGN(16) _SLIST_ENTRY *PSLIST_ENTRY;
  2051. typedef struct DECLSPEC_ALIGN(16) _SLIST_ENTRY {
  2052. PSLIST_ENTRY Next;
  2053. } SLIST_ENTRY;
  2054. #pragma warning(pop)
  2055. #else
  2056. #define SLIST_ENTRY SINGLE_LIST_ENTRY
  2057. #define _SLIST_ENTRY _SINGLE_LIST_ENTRY
  2058. #define PSLIST_ENTRY PSINGLE_LIST_ENTRY
  2059. #endif
  2060. #if defined(_WIN64)
  2061. typedef struct DECLSPEC_ALIGN(16) _SLIST_HEADER {
  2062. ULONGLONG Alignment;
  2063. ULONGLONG Region;
  2064. } SLIST_HEADER;
  2065. typedef struct _SLIST_HEADER *PSLIST_HEADER;
  2066. #else
  2067. typedef union _SLIST_HEADER {
  2068. ULONGLONG Alignment;
  2069. struct {
  2070. SLIST_ENTRY Next;
  2071. USHORT Depth;
  2072. USHORT Sequence;
  2073. };
  2074. } SLIST_HEADER, *PSLIST_HEADER;
  2075. #endif
  2076. #endif
  2077. //
  2078. // If debugging support enabled, define an ASSERT macro that works. Otherwise
  2079. // define the ASSERT macro to expand to an empty expression.
  2080. //
  2081. // The ASSERT macro has been updated to be an expression instead of a statement.
  2082. //
  2083. NTSYSAPI
  2084. VOID
  2085. NTAPI
  2086. RtlAssert(
  2087. PVOID FailedAssertion,
  2088. PVOID FileName,
  2089. ULONG LineNumber,
  2090. PCHAR Message
  2091. );
  2092. #if DBG
  2093. #define ASSERT( exp ) \
  2094. ((!(exp)) ? \
  2095. (RtlAssert( #exp, __FILE__, __LINE__, NULL ),FALSE) : \
  2096. TRUE)
  2097. #define ASSERTMSG( msg, exp ) \
  2098. ((!(exp)) ? \
  2099. (RtlAssert( #exp, __FILE__, __LINE__, msg ),FALSE) : \
  2100. TRUE)
  2101. #define RTL_SOFT_ASSERT(_exp) \
  2102. ((!(_exp)) ? \
  2103. (DbgPrint("%s(%d): Soft assertion failed\n Expression: %s\n", __FILE__, __LINE__, #_exp),FALSE) : \
  2104. TRUE)
  2105. #define RTL_SOFT_ASSERTMSG(_msg, _exp) \
  2106. ((!(_exp)) ? \
  2107. (DbgPrint("%s(%d): Soft assertion failed\n Expression: %s\n Message: %s\n", __FILE__, __LINE__, #_exp, (_msg)),FALSE) : \
  2108. TRUE)
  2109. #define RTL_VERIFY ASSERT
  2110. #define RTL_VERIFYMSG ASSERTMSG
  2111. #define RTL_SOFT_VERIFY RTL_SOFT_ASSERT
  2112. #define RTL_SOFT_VERIFYMSG RTL_SOFT_ASSERTMSG
  2113. #else
  2114. #define ASSERT( exp ) ((void) 0)
  2115. #define ASSERTMSG( msg, exp ) ((void) 0)
  2116. #define RTL_SOFT_ASSERT(_exp) ((void) 0)
  2117. #define RTL_SOFT_ASSERTMSG(_msg, _exp) ((void) 0)
  2118. #define RTL_VERIFY( exp ) ((exp) ? TRUE : FALSE)
  2119. #define RTL_VERIFYMSG( msg, exp ) ((exp) ? TRUE : FALSE)
  2120. #define RTL_SOFT_VERIFY(_exp) ((_exp) ? TRUE : FALSE)
  2121. #define RTL_SOFT_VERIFYMSG(msg, _exp) ((_exp) ? TRUE : FALSE)
  2122. #endif // DBG
  2123. //
  2124. // Doubly-linked list manipulation routines.
  2125. //
  2126. //
  2127. // VOID
  2128. // InitializeListHead32(
  2129. // PLIST_ENTRY32 ListHead
  2130. // );
  2131. //
  2132. #define InitializeListHead32(ListHead) (\
  2133. (ListHead)->Flink = (ListHead)->Blink = PtrToUlong((ListHead)))
  2134. #if !defined(MIDL_PASS) && !defined(SORTPP_PASS)
  2135. VOID
  2136. FORCEINLINE
  2137. InitializeListHead(
  2138. IN PLIST_ENTRY ListHead
  2139. )
  2140. {
  2141. ListHead->Flink = ListHead->Blink = ListHead;
  2142. }
  2143. //
  2144. // BOOLEAN
  2145. // IsListEmpty(
  2146. // PLIST_ENTRY ListHead
  2147. // );
  2148. //
  2149. #define IsListEmpty(ListHead) \
  2150. ((ListHead)->Flink == (ListHead))
  2151. BOOLEAN
  2152. FORCEINLINE
  2153. RemoveEntryList(
  2154. IN PLIST_ENTRY Entry
  2155. )
  2156. {
  2157. PLIST_ENTRY Blink;
  2158. PLIST_ENTRY Flink;
  2159. Flink = Entry->Flink;
  2160. Blink = Entry->Blink;
  2161. Blink->Flink = Flink;
  2162. Flink->Blink = Blink;
  2163. return (BOOLEAN)(Flink == Blink);
  2164. }
  2165. PLIST_ENTRY
  2166. FORCEINLINE
  2167. RemoveHeadList(
  2168. IN PLIST_ENTRY ListHead
  2169. )
  2170. {
  2171. PLIST_ENTRY Flink;
  2172. PLIST_ENTRY Entry;
  2173. Entry = ListHead->Flink;
  2174. Flink = Entry->Flink;
  2175. ListHead->Flink = Flink;
  2176. Flink->Blink = ListHead;
  2177. return Entry;
  2178. }
  2179. PLIST_ENTRY
  2180. FORCEINLINE
  2181. RemoveTailList(
  2182. IN PLIST_ENTRY ListHead
  2183. )
  2184. {
  2185. PLIST_ENTRY Blink;
  2186. PLIST_ENTRY Entry;
  2187. Entry = ListHead->Blink;
  2188. Blink = Entry->Blink;
  2189. ListHead->Blink = Blink;
  2190. Blink->Flink = ListHead;
  2191. return Entry;
  2192. }
  2193. VOID
  2194. FORCEINLINE
  2195. InsertTailList(
  2196. IN PLIST_ENTRY ListHead,
  2197. IN PLIST_ENTRY Entry
  2198. )
  2199. {
  2200. PLIST_ENTRY Blink;
  2201. Blink = ListHead->Blink;
  2202. Entry->Flink = ListHead;
  2203. Entry->Blink = Blink;
  2204. Blink->Flink = Entry;
  2205. ListHead->Blink = Entry;
  2206. }
  2207. VOID
  2208. FORCEINLINE
  2209. InsertHeadList(
  2210. IN PLIST_ENTRY ListHead,
  2211. IN PLIST_ENTRY Entry
  2212. )
  2213. {
  2214. PLIST_ENTRY Flink;
  2215. Flink = ListHead->Flink;
  2216. Entry->Flink = Flink;
  2217. Entry->Blink = ListHead;
  2218. Flink->Blink = Entry;
  2219. ListHead->Flink = Entry;
  2220. }
  2221. //
  2222. //
  2223. // PSINGLE_LIST_ENTRY
  2224. // PopEntryList(
  2225. // PSINGLE_LIST_ENTRY ListHead
  2226. // );
  2227. //
  2228. #define PopEntryList(ListHead) \
  2229. (ListHead)->Next;\
  2230. {\
  2231. PSINGLE_LIST_ENTRY FirstEntry;\
  2232. FirstEntry = (ListHead)->Next;\
  2233. if (FirstEntry != NULL) { \
  2234. (ListHead)->Next = FirstEntry->Next;\
  2235. } \
  2236. }
  2237. //
  2238. // VOID
  2239. // PushEntryList(
  2240. // PSINGLE_LIST_ENTRY ListHead,
  2241. // PSINGLE_LIST_ENTRY Entry
  2242. // );
  2243. //
  2244. #define PushEntryList(ListHead,Entry) \
  2245. (Entry)->Next = (ListHead)->Next; \
  2246. (ListHead)->Next = (Entry)
  2247. #endif // !MIDL_PASS
  2248. #if defined (_MSC_VER) && ( _MSC_VER >= 900 )
  2249. PVOID
  2250. _ReturnAddress (
  2251. VOID
  2252. );
  2253. #pragma intrinsic(_ReturnAddress)
  2254. #endif
  2255. #if (defined(_M_AMD64) || defined(_M_IA64)) && !defined(_REALLY_GET_CALLERS_CALLER_)
  2256. #define RtlGetCallersAddress(CallersAddress, CallersCaller) \
  2257. *CallersAddress = (PVOID)_ReturnAddress(); \
  2258. *CallersCaller = NULL;
  2259. #else
  2260. NTSYSAPI
  2261. VOID
  2262. NTAPI
  2263. RtlGetCallersAddress(
  2264. OUT PVOID *CallersAddress,
  2265. OUT PVOID *CallersCaller
  2266. );
  2267. #endif
  2268. NTSYSAPI
  2269. ULONG
  2270. NTAPI
  2271. RtlWalkFrameChain (
  2272. OUT PVOID *Callers,
  2273. IN ULONG Count,
  2274. IN ULONG Flags
  2275. );
  2276. //
  2277. // Subroutines for dealing with the Registry
  2278. //
  2279. typedef NTSTATUS (NTAPI * PRTL_QUERY_REGISTRY_ROUTINE)(
  2280. IN PWSTR ValueName,
  2281. IN ULONG ValueType,
  2282. IN PVOID ValueData,
  2283. IN ULONG ValueLength,
  2284. IN PVOID Context,
  2285. IN PVOID EntryContext
  2286. );
  2287. typedef struct _RTL_QUERY_REGISTRY_TABLE {
  2288. PRTL_QUERY_REGISTRY_ROUTINE QueryRoutine;
  2289. ULONG Flags;
  2290. PWSTR Name;
  2291. PVOID EntryContext;
  2292. ULONG DefaultType;
  2293. PVOID DefaultData;
  2294. ULONG DefaultLength;
  2295. } RTL_QUERY_REGISTRY_TABLE, *PRTL_QUERY_REGISTRY_TABLE;
  2296. //
  2297. // The following flags specify how the Name field of a RTL_QUERY_REGISTRY_TABLE
  2298. // entry is interpreted. A NULL name indicates the end of the table.
  2299. //
  2300. #define RTL_QUERY_REGISTRY_SUBKEY 0x00000001 // Name is a subkey and remainder of
  2301. // table or until next subkey are value
  2302. // names for that subkey to look at.
  2303. #define RTL_QUERY_REGISTRY_TOPKEY 0x00000002 // Reset current key to original key for
  2304. // this and all following table entries.
  2305. #define RTL_QUERY_REGISTRY_REQUIRED 0x00000004 // Fail if no match found for this table
  2306. // entry.
  2307. #define RTL_QUERY_REGISTRY_NOVALUE 0x00000008 // Used to mark a table entry that has no
  2308. // value name, just wants a call out, not
  2309. // an enumeration of all values.
  2310. #define RTL_QUERY_REGISTRY_NOEXPAND 0x00000010 // Used to suppress the expansion of
  2311. // REG_MULTI_SZ into multiple callouts or
  2312. // to prevent the expansion of environment
  2313. // variable values in REG_EXPAND_SZ
  2314. #define RTL_QUERY_REGISTRY_DIRECT 0x00000020 // QueryRoutine field ignored. EntryContext
  2315. // field points to location to store value.
  2316. // For null terminated strings, EntryContext
  2317. // points to UNICODE_STRING structure that
  2318. // that describes maximum size of buffer.
  2319. // If .Buffer field is NULL then a buffer is
  2320. // allocated.
  2321. //
  2322. #define RTL_QUERY_REGISTRY_DELETE 0x00000040 // Used to delete value keys after they
  2323. // are queried.
  2324. NTSYSAPI
  2325. NTSTATUS
  2326. NTAPI
  2327. RtlQueryRegistryValues(
  2328. IN ULONG RelativeTo,
  2329. IN PCWSTR Path,
  2330. IN PRTL_QUERY_REGISTRY_TABLE QueryTable,
  2331. IN PVOID Context,
  2332. IN PVOID Environment OPTIONAL
  2333. );
  2334. NTSYSAPI
  2335. NTSTATUS
  2336. NTAPI
  2337. RtlWriteRegistryValue(
  2338. IN ULONG RelativeTo,
  2339. IN PCWSTR Path,
  2340. IN PCWSTR ValueName,
  2341. IN ULONG ValueType,
  2342. IN PVOID ValueData,
  2343. IN ULONG ValueLength
  2344. );
  2345. NTSYSAPI
  2346. NTSTATUS
  2347. NTAPI
  2348. RtlDeleteRegistryValue(
  2349. IN ULONG RelativeTo,
  2350. IN PCWSTR Path,
  2351. IN PCWSTR ValueName
  2352. );
  2353. // end_wdm
  2354. NTSYSAPI
  2355. NTSTATUS
  2356. NTAPI
  2357. RtlCreateRegistryKey(
  2358. IN ULONG RelativeTo,
  2359. IN PWSTR Path
  2360. );
  2361. NTSYSAPI
  2362. NTSTATUS
  2363. NTAPI
  2364. RtlCheckRegistryKey(
  2365. IN ULONG RelativeTo,
  2366. IN PWSTR Path
  2367. );
  2368. // begin_wdm
  2369. //
  2370. // The following values for the RelativeTo parameter determine what the
  2371. // Path parameter to RtlQueryRegistryValues is relative to.
  2372. //
  2373. #define RTL_REGISTRY_ABSOLUTE 0 // Path is a full path
  2374. #define RTL_REGISTRY_SERVICES 1 // \Registry\Machine\System\CurrentControlSet\Services
  2375. #define RTL_REGISTRY_CONTROL 2 // \Registry\Machine\System\CurrentControlSet\Control
  2376. #define RTL_REGISTRY_WINDOWS_NT 3 // \Registry\Machine\Software\Microsoft\Windows NT\CurrentVersion
  2377. #define RTL_REGISTRY_DEVICEMAP 4 // \Registry\Machine\Hardware\DeviceMap
  2378. #define RTL_REGISTRY_USER 5 // \Registry\User\CurrentUser
  2379. #define RTL_REGISTRY_MAXIMUM 6
  2380. #define RTL_REGISTRY_HANDLE 0x40000000 // Low order bits are registry handle
  2381. #define RTL_REGISTRY_OPTIONAL 0x80000000 // Indicates the key node is optional
  2382. NTSYSAPI
  2383. NTSTATUS
  2384. NTAPI
  2385. RtlIntegerToUnicodeString (
  2386. ULONG Value,
  2387. ULONG Base,
  2388. PUNICODE_STRING String
  2389. );
  2390. NTSYSAPI
  2391. NTSTATUS
  2392. NTAPI
  2393. RtlInt64ToUnicodeString (
  2394. IN ULONGLONG Value,
  2395. IN ULONG Base OPTIONAL,
  2396. IN OUT PUNICODE_STRING String
  2397. );
  2398. #ifdef _WIN64
  2399. #define RtlIntPtrToUnicodeString(Value, Base, String) RtlInt64ToUnicodeString(Value, Base, String)
  2400. #else
  2401. #define RtlIntPtrToUnicodeString(Value, Base, String) RtlIntegerToUnicodeString(Value, Base, String)
  2402. #endif
  2403. NTSYSAPI
  2404. NTSTATUS
  2405. NTAPI
  2406. RtlUnicodeStringToInteger (
  2407. PCUNICODE_STRING String,
  2408. ULONG Base,
  2409. PULONG Value
  2410. );
  2411. //
  2412. // String manipulation routines
  2413. //
  2414. #ifdef _NTSYSTEM_
  2415. #define NLS_MB_CODE_PAGE_TAG NlsMbCodePageTag
  2416. #define NLS_MB_OEM_CODE_PAGE_TAG NlsMbOemCodePageTag
  2417. #else
  2418. #define NLS_MB_CODE_PAGE_TAG (*NlsMbCodePageTag)
  2419. #define NLS_MB_OEM_CODE_PAGE_TAG (*NlsMbOemCodePageTag)
  2420. #endif // _NTSYSTEM_
  2421. extern BOOLEAN NLS_MB_CODE_PAGE_TAG; // TRUE -> Multibyte CP, FALSE -> Singlebyte
  2422. extern BOOLEAN NLS_MB_OEM_CODE_PAGE_TAG; // TRUE -> Multibyte CP, FALSE -> Singlebyte
  2423. NTSYSAPI
  2424. VOID
  2425. NTAPI
  2426. RtlInitString(
  2427. PSTRING DestinationString,
  2428. PCSZ SourceString
  2429. );
  2430. NTSYSAPI
  2431. VOID
  2432. NTAPI
  2433. RtlInitAnsiString(
  2434. PANSI_STRING DestinationString,
  2435. PCSZ SourceString
  2436. );
  2437. NTSYSAPI
  2438. VOID
  2439. NTAPI
  2440. RtlInitUnicodeString(
  2441. PUNICODE_STRING DestinationString,
  2442. PCWSTR SourceString
  2443. );
  2444. #define RtlInitEmptyUnicodeString(_ucStr,_buf,_bufSize) \
  2445. ((_ucStr)->Buffer = (_buf), \
  2446. (_ucStr)->Length = 0, \
  2447. (_ucStr)->MaximumLength = (USHORT)(_bufSize))
  2448. // end_ntddk end_wdm
  2449. NTSYSAPI
  2450. NTSTATUS
  2451. NTAPI
  2452. RtlInitUnicodeStringEx(
  2453. PUNICODE_STRING DestinationString,
  2454. PCWSTR SourceString
  2455. );
  2456. NTSYSAPI
  2457. NTSTATUS
  2458. NTAPI
  2459. RtlInitAnsiStringEx(
  2460. OUT PANSI_STRING DestinationString,
  2461. IN PCSZ SourceString OPTIONAL
  2462. );
  2463. NTSYSAPI
  2464. BOOLEAN
  2465. NTAPI
  2466. RtlCreateUnicodeString(
  2467. OUT PUNICODE_STRING DestinationString,
  2468. IN PCWSTR SourceString
  2469. );
  2470. // end_ntifs
  2471. NTSYSAPI
  2472. BOOLEAN
  2473. NTAPI
  2474. RtlEqualDomainName(
  2475. IN PCUNICODE_STRING String1,
  2476. IN PCUNICODE_STRING String2
  2477. );
  2478. NTSYSAPI
  2479. BOOLEAN
  2480. NTAPI
  2481. RtlEqualComputerName(
  2482. IN PCUNICODE_STRING String1,
  2483. IN PCUNICODE_STRING String2
  2484. );
  2485. NTSTATUS
  2486. RtlDnsHostNameToComputerName(
  2487. OUT PUNICODE_STRING ComputerNameString,
  2488. IN PCUNICODE_STRING DnsHostNameString,
  2489. IN BOOLEAN AllocateComputerNameString
  2490. );
  2491. NTSYSAPI
  2492. BOOLEAN
  2493. NTAPI
  2494. RtlCreateUnicodeStringFromAsciiz(
  2495. OUT PUNICODE_STRING DestinationString,
  2496. IN PCSZ SourceString
  2497. );
  2498. // begin_ntddk begin_ntifs
  2499. NTSYSAPI
  2500. VOID
  2501. NTAPI
  2502. RtlCopyString(
  2503. PSTRING DestinationString,
  2504. const STRING * SourceString
  2505. );
  2506. NTSYSAPI
  2507. CHAR
  2508. NTAPI
  2509. RtlUpperChar (
  2510. CHAR Character
  2511. );
  2512. NTSYSAPI
  2513. LONG
  2514. NTAPI
  2515. RtlCompareString(
  2516. const STRING * String1,
  2517. const STRING * String2,
  2518. BOOLEAN CaseInSensitive
  2519. );
  2520. NTSYSAPI
  2521. BOOLEAN
  2522. NTAPI
  2523. RtlEqualString(
  2524. const STRING * String1,
  2525. const STRING * String2,
  2526. BOOLEAN CaseInSensitive
  2527. );
  2528. // end_ntddk end_ntifs
  2529. NTSYSAPI
  2530. BOOLEAN
  2531. NTAPI
  2532. RtlPrefixString(
  2533. const STRING * String1,
  2534. const STRING * String2,
  2535. BOOLEAN CaseInSensitive
  2536. );
  2537. // begin_ntddk begin_ntifs
  2538. NTSYSAPI
  2539. VOID
  2540. NTAPI
  2541. RtlUpperString(
  2542. PSTRING DestinationString,
  2543. const STRING * SourceString
  2544. );
  2545. // end_ntddk end_ntifs
  2546. NTSYSAPI
  2547. NTSTATUS
  2548. NTAPI
  2549. RtlAppendAsciizToString (
  2550. PSTRING Destination,
  2551. PCSZ Source
  2552. );
  2553. // begin_ntifs
  2554. NTSYSAPI
  2555. NTSTATUS
  2556. NTAPI
  2557. RtlAppendStringToString (
  2558. PSTRING Destination,
  2559. const STRING * Source
  2560. );
  2561. // begin_ntddk begin_wdm
  2562. //
  2563. // NLS String functions
  2564. //
  2565. NTSYSAPI
  2566. NTSTATUS
  2567. NTAPI
  2568. RtlAnsiStringToUnicodeString(
  2569. PUNICODE_STRING DestinationString,
  2570. PCANSI_STRING SourceString,
  2571. BOOLEAN AllocateDestinationString
  2572. );
  2573. NTSYSAPI
  2574. NTSTATUS
  2575. NTAPI
  2576. RtlUnicodeStringToAnsiString(
  2577. PANSI_STRING DestinationString,
  2578. PCUNICODE_STRING SourceString,
  2579. BOOLEAN AllocateDestinationString
  2580. );
  2581. NTSYSAPI
  2582. VOID
  2583. NTAPI
  2584. RtlCopyUnicodeString(
  2585. PUNICODE_STRING DestinationString,
  2586. PCUNICODE_STRING SourceString
  2587. );
  2588. NTSYSAPI
  2589. NTSTATUS
  2590. NTAPI
  2591. RtlAppendUnicodeStringToString (
  2592. PUNICODE_STRING Destination,
  2593. PCUNICODE_STRING Source
  2594. );
  2595. NTSYSAPI
  2596. NTSTATUS
  2597. NTAPI
  2598. RtlAppendUnicodeToString (
  2599. PUNICODE_STRING Destination,
  2600. PCWSTR Source
  2601. );
  2602. // end_ntndis end_wdm
  2603. NTSYSAPI
  2604. WCHAR
  2605. NTAPI
  2606. RtlUpcaseUnicodeChar(
  2607. WCHAR SourceCharacter
  2608. );
  2609. NTSYSAPI
  2610. WCHAR
  2611. NTAPI
  2612. RtlDowncaseUnicodeChar(
  2613. WCHAR SourceCharacter
  2614. );
  2615. // begin_wdm
  2616. NTSYSAPI
  2617. VOID
  2618. NTAPI
  2619. RtlFreeUnicodeString(
  2620. PUNICODE_STRING UnicodeString
  2621. );
  2622. NTSYSAPI
  2623. VOID
  2624. NTAPI
  2625. RtlFreeAnsiString(
  2626. PANSI_STRING AnsiString
  2627. );
  2628. // begin_ntminiport
  2629. #include <guiddef.h>
  2630. // end_ntminiport
  2631. #ifndef DEFINE_GUIDEX
  2632. #define DEFINE_GUIDEX(name) EXTERN_C const CDECL GUID name
  2633. #endif // !defined(DEFINE_GUIDEX)
  2634. #ifndef STATICGUIDOF
  2635. #define STATICGUIDOF(guid) STATIC_##guid
  2636. #endif // !defined(STATICGUIDOF)
  2637. #ifndef __IID_ALIGNED__
  2638. #define __IID_ALIGNED__
  2639. #ifdef __cplusplus
  2640. inline int IsEqualGUIDAligned(REFGUID guid1, REFGUID guid2)
  2641. {
  2642. return ((*(PLONGLONG)(&guid1) == *(PLONGLONG)(&guid2)) && (*((PLONGLONG)(&guid1) + 1) == *((PLONGLONG)(&guid2) + 1)));
  2643. }
  2644. #else // !__cplusplus
  2645. #define IsEqualGUIDAligned(guid1, guid2) \
  2646. ((*(PLONGLONG)(guid1) == *(PLONGLONG)(guid2)) && (*((PLONGLONG)(guid1) + 1) == *((PLONGLONG)(guid2) + 1)))
  2647. #endif // !__cplusplus
  2648. #endif // !__IID_ALIGNED__
  2649. NTSYSAPI
  2650. NTSTATUS
  2651. NTAPI
  2652. RtlStringFromGUID(
  2653. IN REFGUID Guid,
  2654. OUT PUNICODE_STRING GuidString
  2655. );
  2656. NTSYSAPI
  2657. NTSTATUS
  2658. NTAPI
  2659. RtlGUIDFromString(
  2660. IN PUNICODE_STRING GuidString,
  2661. OUT GUID* Guid
  2662. );
  2663. //
  2664. // Fast primitives to compare, move, and zero memory
  2665. //
  2666. // begin_winnt begin_ntndis
  2667. NTSYSAPI
  2668. SIZE_T
  2669. NTAPI
  2670. RtlCompareMemory (
  2671. const VOID *Source1,
  2672. const VOID *Source2,
  2673. SIZE_T Length
  2674. );
  2675. #define RtlEqualMemory(Destination,Source,Length) (!memcmp((Destination),(Source),(Length)))
  2676. #if defined(_M_AMD64)
  2677. NTSYSAPI
  2678. VOID
  2679. NTAPI
  2680. RtlCopyMemory (
  2681. VOID UNALIGNED *Destination,
  2682. CONST VOID UNALIGNED *Source,
  2683. SIZE_T Length
  2684. );
  2685. NTSYSAPI
  2686. VOID
  2687. NTAPI
  2688. RtlMoveMemory (
  2689. VOID UNALIGNED *Destination,
  2690. CONST VOID UNALIGNED *Source,
  2691. SIZE_T Length
  2692. );
  2693. NTSYSAPI
  2694. VOID
  2695. NTAPI
  2696. RtlFillMemory (
  2697. VOID UNALIGNED *Destination,
  2698. SIZE_T Length,
  2699. IN UCHAR Fill
  2700. );
  2701. NTSYSAPI
  2702. VOID
  2703. NTAPI
  2704. RtlZeroMemory (
  2705. VOID UNALIGNED *Destination,
  2706. SIZE_T Length
  2707. );
  2708. #else
  2709. #define RtlMoveMemory(Destination,Source,Length) memmove((Destination),(Source),(Length))
  2710. #define RtlCopyMemory(Destination,Source,Length) memcpy((Destination),(Source),(Length))
  2711. #define RtlFillMemory(Destination,Length,Fill) memset((Destination),(Fill),(Length))
  2712. #define RtlZeroMemory(Destination,Length) memset((Destination),0,(Length))
  2713. #endif
  2714. #if !defined(MIDL_PASS)
  2715. FORCEINLINE
  2716. PVOID
  2717. RtlSecureZeroMemory(
  2718. IN PVOID ptr,
  2719. IN SIZE_T cnt
  2720. )
  2721. {
  2722. volatile char *vptr = (volatile char *)ptr;
  2723. while (cnt) {
  2724. *vptr = 0;
  2725. vptr++;
  2726. cnt--;
  2727. }
  2728. return ptr;
  2729. }
  2730. #endif
  2731. // end_ntndis end_winnt
  2732. #define RtlCopyBytes RtlCopyMemory
  2733. #define RtlZeroBytes RtlZeroMemory
  2734. #define RtlFillBytes RtlFillMemory
  2735. #if defined(_M_AMD64)
  2736. NTSYSAPI
  2737. VOID
  2738. NTAPI
  2739. RtlCopyMemoryNonTemporal (
  2740. VOID UNALIGNED *Destination,
  2741. CONST VOID UNALIGNED *Source,
  2742. SIZE_T Length
  2743. );
  2744. #else
  2745. #define RtlCopyMemoryNonTemporal RtlCopyMemory
  2746. #endif
  2747. NTSYSAPI
  2748. VOID
  2749. FASTCALL
  2750. RtlPrefetchMemoryNonTemporal(
  2751. IN PVOID Source,
  2752. IN SIZE_T Length
  2753. );
  2754. //
  2755. // Define kernel debugger print prototypes and macros.
  2756. //
  2757. // N.B. The following function cannot be directly imported because there are
  2758. // a few places in the source tree where this function is redefined.
  2759. //
  2760. VOID
  2761. NTAPI
  2762. DbgBreakPoint(
  2763. VOID
  2764. );
  2765. // end_wdm
  2766. NTSYSAPI
  2767. VOID
  2768. NTAPI
  2769. DbgBreakPointWithStatus(
  2770. IN ULONG Status
  2771. );
  2772. // begin_wdm
  2773. #define DBG_STATUS_CONTROL_C 1
  2774. #define DBG_STATUS_SYSRQ 2
  2775. #define DBG_STATUS_BUGCHECK_FIRST 3
  2776. #define DBG_STATUS_BUGCHECK_SECOND 4
  2777. #define DBG_STATUS_FATAL 5
  2778. #define DBG_STATUS_DEBUG_CONTROL 6
  2779. #define DBG_STATUS_WORKER 7
  2780. #if DBG
  2781. #define KdPrint(_x_) DbgPrint _x_
  2782. // end_wdm
  2783. #define KdPrintEx(_x_) DbgPrintEx _x_
  2784. #define vKdPrintEx(_x_) vDbgPrintEx _x_
  2785. #define vKdPrintExWithPrefix(_x_) vDbgPrintExWithPrefix _x_
  2786. // begin_wdm
  2787. #define KdBreakPoint() DbgBreakPoint()
  2788. // end_wdm
  2789. #define KdBreakPointWithStatus(s) DbgBreakPointWithStatus(s)
  2790. // begin_wdm
  2791. #else
  2792. #define KdPrint(_x_)
  2793. // end_wdm
  2794. #define KdPrintEx(_x_)
  2795. #define vKdPrintEx(_x_)
  2796. #define vKdPrintExWithPrefix(_x_)
  2797. // begin_wdm
  2798. #define KdBreakPoint()
  2799. // end_wdm
  2800. #define KdBreakPointWithStatus(s)
  2801. // begin_wdm
  2802. #endif
  2803. #ifndef _DBGNT_
  2804. ULONG
  2805. __cdecl
  2806. DbgPrint(
  2807. PCH Format,
  2808. ...
  2809. );
  2810. // end_wdm
  2811. ULONG
  2812. __cdecl
  2813. DbgPrintEx(
  2814. IN ULONG ComponentId,
  2815. IN ULONG Level,
  2816. IN PCH Format,
  2817. ...
  2818. );
  2819. #ifdef _VA_LIST_DEFINED
  2820. ULONG
  2821. vDbgPrintEx(
  2822. IN ULONG ComponentId,
  2823. IN ULONG Level,
  2824. IN PCH Format,
  2825. va_list arglist
  2826. );
  2827. ULONG
  2828. vDbgPrintExWithPrefix(
  2829. IN PCH Prefix,
  2830. IN ULONG ComponentId,
  2831. IN ULONG Level,
  2832. IN PCH Format,
  2833. va_list arglist
  2834. );
  2835. #endif
  2836. ULONG
  2837. __cdecl
  2838. DbgPrintReturnControlC(
  2839. PCH Format,
  2840. ...
  2841. );
  2842. NTSYSAPI
  2843. NTSTATUS
  2844. DbgQueryDebugFilterState(
  2845. IN ULONG ComponentId,
  2846. IN ULONG Level
  2847. );
  2848. NTSYSAPI
  2849. NTSTATUS
  2850. DbgSetDebugFilterState(
  2851. IN ULONG ComponentId,
  2852. IN ULONG Level,
  2853. IN BOOLEAN State
  2854. );
  2855. // begin_wdm
  2856. #endif // _DBGNT_
  2857. //
  2858. // Large integer arithmetic routines.
  2859. //
  2860. //
  2861. // Large integer add - 64-bits + 64-bits -> 64-bits
  2862. //
  2863. #if !defined(MIDL_PASS)
  2864. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  2865. __inline
  2866. LARGE_INTEGER
  2867. NTAPI
  2868. RtlLargeIntegerAdd (
  2869. LARGE_INTEGER Addend1,
  2870. LARGE_INTEGER Addend2
  2871. )
  2872. {
  2873. LARGE_INTEGER Sum;
  2874. Sum.QuadPart = Addend1.QuadPart + Addend2.QuadPart;
  2875. return Sum;
  2876. }
  2877. //
  2878. // Enlarged integer multiply - 32-bits * 32-bits -> 64-bits
  2879. //
  2880. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  2881. __inline
  2882. LARGE_INTEGER
  2883. NTAPI
  2884. RtlEnlargedIntegerMultiply (
  2885. LONG Multiplicand,
  2886. LONG Multiplier
  2887. )
  2888. {
  2889. LARGE_INTEGER Product;
  2890. Product.QuadPart = (LONGLONG)Multiplicand * (ULONGLONG)Multiplier;
  2891. return Product;
  2892. }
  2893. //
  2894. // Unsigned enlarged integer multiply - 32-bits * 32-bits -> 64-bits
  2895. //
  2896. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  2897. __inline
  2898. LARGE_INTEGER
  2899. NTAPI
  2900. RtlEnlargedUnsignedMultiply (
  2901. ULONG Multiplicand,
  2902. ULONG Multiplier
  2903. )
  2904. {
  2905. LARGE_INTEGER Product;
  2906. Product.QuadPart = (ULONGLONG)Multiplicand * (ULONGLONG)Multiplier;
  2907. return Product;
  2908. }
  2909. //
  2910. // Enlarged integer divide - 64-bits / 32-bits > 32-bits
  2911. //
  2912. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  2913. __inline
  2914. ULONG
  2915. NTAPI
  2916. RtlEnlargedUnsignedDivide (
  2917. IN ULARGE_INTEGER Dividend,
  2918. IN ULONG Divisor,
  2919. IN PULONG Remainder OPTIONAL
  2920. )
  2921. {
  2922. ULONG Quotient;
  2923. Quotient = (ULONG)(Dividend.QuadPart / Divisor);
  2924. if (ARGUMENT_PRESENT(Remainder)) {
  2925. *Remainder = (ULONG)(Dividend.QuadPart % Divisor);
  2926. }
  2927. return Quotient;
  2928. }
  2929. //
  2930. // Large integer negation - -(64-bits)
  2931. //
  2932. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  2933. __inline
  2934. LARGE_INTEGER
  2935. NTAPI
  2936. RtlLargeIntegerNegate (
  2937. LARGE_INTEGER Subtrahend
  2938. )
  2939. {
  2940. LARGE_INTEGER Difference;
  2941. Difference.QuadPart = -Subtrahend.QuadPart;
  2942. return Difference;
  2943. }
  2944. //
  2945. // Large integer subtract - 64-bits - 64-bits -> 64-bits.
  2946. //
  2947. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  2948. __inline
  2949. LARGE_INTEGER
  2950. NTAPI
  2951. RtlLargeIntegerSubtract (
  2952. LARGE_INTEGER Minuend,
  2953. LARGE_INTEGER Subtrahend
  2954. )
  2955. {
  2956. LARGE_INTEGER Difference;
  2957. Difference.QuadPart = Minuend.QuadPart - Subtrahend.QuadPart;
  2958. return Difference;
  2959. }
  2960. //
  2961. // Extended large integer magic divide - 64-bits / 32-bits -> 64-bits
  2962. //
  2963. #if defined(_AMD64_)
  2964. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  2965. __inline
  2966. LARGE_INTEGER
  2967. NTAPI
  2968. RtlExtendedMagicDivide (
  2969. LARGE_INTEGER Dividend,
  2970. LARGE_INTEGER MagicDivisor,
  2971. CCHAR ShiftCount
  2972. )
  2973. {
  2974. LARGE_INTEGER Quotient;
  2975. if (Dividend.QuadPart >= 0) {
  2976. Quotient.QuadPart = UnsignedMultiplyHigh(Dividend.QuadPart,
  2977. (ULONG64)MagicDivisor.QuadPart);
  2978. } else {
  2979. Quotient.QuadPart = UnsignedMultiplyHigh(-Dividend.QuadPart,
  2980. (ULONG64)MagicDivisor.QuadPart);
  2981. }
  2982. Quotient.QuadPart = (ULONG64)Quotient.QuadPart >> ShiftCount;
  2983. if (Dividend.QuadPart < 0) {
  2984. Quotient.QuadPart = - Quotient.QuadPart;
  2985. }
  2986. return Quotient;
  2987. }
  2988. #endif // defined(_AMD64_)
  2989. #if defined(_X86_) || defined(_IA64_)
  2990. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  2991. NTSYSAPI
  2992. LARGE_INTEGER
  2993. NTAPI
  2994. RtlExtendedMagicDivide (
  2995. LARGE_INTEGER Dividend,
  2996. LARGE_INTEGER MagicDivisor,
  2997. CCHAR ShiftCount
  2998. );
  2999. #endif // defined(_X86_) || defined(_IA64_)
  3000. #if defined(_AMD64_) || defined(_IA64_)
  3001. //
  3002. // Large Integer divide - 64-bits / 32-bits -> 64-bits
  3003. //
  3004. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  3005. __inline
  3006. LARGE_INTEGER
  3007. NTAPI
  3008. RtlExtendedLargeIntegerDivide (
  3009. LARGE_INTEGER Dividend,
  3010. ULONG Divisor,
  3011. PULONG Remainder OPTIONAL
  3012. )
  3013. {
  3014. LARGE_INTEGER Quotient;
  3015. Quotient.QuadPart = (ULONG64)Dividend.QuadPart / Divisor;
  3016. if (ARGUMENT_PRESENT(Remainder)) {
  3017. *Remainder = (ULONG)(Dividend.QuadPart % Divisor);
  3018. }
  3019. return Quotient;
  3020. }
  3021. // end_wdm
  3022. //
  3023. // Large Integer divide - 64-bits / 64-bits -> 64-bits
  3024. //
  3025. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  3026. __inline
  3027. LARGE_INTEGER
  3028. NTAPI
  3029. RtlLargeIntegerDivide (
  3030. LARGE_INTEGER Dividend,
  3031. LARGE_INTEGER Divisor,
  3032. PLARGE_INTEGER Remainder OPTIONAL
  3033. )
  3034. {
  3035. LARGE_INTEGER Quotient;
  3036. Quotient.QuadPart = Dividend.QuadPart / Divisor.QuadPart;
  3037. if (ARGUMENT_PRESENT(Remainder)) {
  3038. Remainder->QuadPart = Dividend.QuadPart % Divisor.QuadPart;
  3039. }
  3040. return Quotient;
  3041. }
  3042. // begin_wdm
  3043. //
  3044. // Extended integer multiply - 32-bits * 64-bits -> 64-bits
  3045. //
  3046. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  3047. __inline
  3048. LARGE_INTEGER
  3049. NTAPI
  3050. RtlExtendedIntegerMultiply (
  3051. LARGE_INTEGER Multiplicand,
  3052. LONG Multiplier
  3053. )
  3054. {
  3055. LARGE_INTEGER Product;
  3056. Product.QuadPart = Multiplicand.QuadPart * Multiplier;
  3057. return Product;
  3058. }
  3059. #else
  3060. //
  3061. // Large Integer divide - 64-bits / 32-bits -> 64-bits
  3062. //
  3063. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  3064. NTSYSAPI
  3065. LARGE_INTEGER
  3066. NTAPI
  3067. RtlExtendedLargeIntegerDivide (
  3068. LARGE_INTEGER Dividend,
  3069. ULONG Divisor,
  3070. PULONG Remainder
  3071. );
  3072. // end_wdm
  3073. //
  3074. // Large Integer divide - 64-bits / 64-bits -> 64-bits
  3075. //
  3076. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  3077. NTSYSAPI
  3078. LARGE_INTEGER
  3079. NTAPI
  3080. RtlLargeIntegerDivide (
  3081. LARGE_INTEGER Dividend,
  3082. LARGE_INTEGER Divisor,
  3083. PLARGE_INTEGER Remainder
  3084. );
  3085. // begin_wdm
  3086. //
  3087. // Extended integer multiply - 32-bits * 64-bits -> 64-bits
  3088. //
  3089. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  3090. NTSYSAPI
  3091. LARGE_INTEGER
  3092. NTAPI
  3093. RtlExtendedIntegerMultiply (
  3094. LARGE_INTEGER Multiplicand,
  3095. LONG Multiplier
  3096. );
  3097. #endif // defined(_AMD64_) || defined(_IA64_)
  3098. //
  3099. // Large integer and - 64-bite & 64-bits -> 64-bits.
  3100. //
  3101. #if PRAGMA_DEPRECATED_DDK
  3102. #pragma deprecated(RtlLargeIntegerAnd) // Use native __int64 math
  3103. #endif
  3104. #define RtlLargeIntegerAnd(Result, Source, Mask) \
  3105. Result.QuadPart = Source.QuadPart & Mask.QuadPart
  3106. //
  3107. // Convert signed integer to large integer.
  3108. //
  3109. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  3110. __inline
  3111. LARGE_INTEGER
  3112. NTAPI
  3113. RtlConvertLongToLargeInteger (
  3114. LONG SignedInteger
  3115. )
  3116. {
  3117. LARGE_INTEGER Result;
  3118. Result.QuadPart = SignedInteger;
  3119. return Result;
  3120. }
  3121. //
  3122. // Convert unsigned integer to large integer.
  3123. //
  3124. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  3125. __inline
  3126. LARGE_INTEGER
  3127. NTAPI
  3128. RtlConvertUlongToLargeInteger (
  3129. ULONG UnsignedInteger
  3130. )
  3131. {
  3132. LARGE_INTEGER Result;
  3133. Result.QuadPart = UnsignedInteger;
  3134. return Result;
  3135. }
  3136. //
  3137. // Large integer shift routines.
  3138. //
  3139. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  3140. __inline
  3141. LARGE_INTEGER
  3142. NTAPI
  3143. RtlLargeIntegerShiftLeft (
  3144. LARGE_INTEGER LargeInteger,
  3145. CCHAR ShiftCount
  3146. )
  3147. {
  3148. LARGE_INTEGER Result;
  3149. Result.QuadPart = LargeInteger.QuadPart << ShiftCount;
  3150. return Result;
  3151. }
  3152. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  3153. __inline
  3154. LARGE_INTEGER
  3155. NTAPI
  3156. RtlLargeIntegerShiftRight (
  3157. LARGE_INTEGER LargeInteger,
  3158. CCHAR ShiftCount
  3159. )
  3160. {
  3161. LARGE_INTEGER Result;
  3162. Result.QuadPart = (ULONG64)LargeInteger.QuadPart >> ShiftCount;
  3163. return Result;
  3164. }
  3165. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  3166. __inline
  3167. LARGE_INTEGER
  3168. NTAPI
  3169. RtlLargeIntegerArithmeticShift (
  3170. LARGE_INTEGER LargeInteger,
  3171. CCHAR ShiftCount
  3172. )
  3173. {
  3174. LARGE_INTEGER Result;
  3175. Result.QuadPart = LargeInteger.QuadPart >> ShiftCount;
  3176. return Result;
  3177. }
  3178. //
  3179. // Large integer comparison routines.
  3180. //
  3181. #if PRAGMA_DEPRECATED_DDK
  3182. #pragma deprecated(RtlLargeIntegerGreaterThan) // Use native __int64 math
  3183. #pragma deprecated(RtlLargeIntegerGreaterThanOrEqualTo) // Use native __int64 math
  3184. #pragma deprecated(RtlLargeIntegerEqualTo) // Use native __int64 math
  3185. #pragma deprecated(RtlLargeIntegerNotEqualTo) // Use native __int64 math
  3186. #pragma deprecated(RtlLargeIntegerLessThan) // Use native __int64 math
  3187. #pragma deprecated(RtlLargeIntegerLessThanOrEqualTo) // Use native __int64 math
  3188. #pragma deprecated(RtlLargeIntegerGreaterThanZero) // Use native __int64 math
  3189. #pragma deprecated(RtlLargeIntegerGreaterOrEqualToZero) // Use native __int64 math
  3190. #pragma deprecated(RtlLargeIntegerEqualToZero) // Use native __int64 math
  3191. #pragma deprecated(RtlLargeIntegerNotEqualToZero) // Use native __int64 math
  3192. #pragma deprecated(RtlLargeIntegerLessThanZero) // Use native __int64 math
  3193. #pragma deprecated(RtlLargeIntegerLessOrEqualToZero) // Use native __int64 math
  3194. #endif
  3195. #define RtlLargeIntegerGreaterThan(X,Y) ( \
  3196. (((X).HighPart == (Y).HighPart) && ((X).LowPart > (Y).LowPart)) || \
  3197. ((X).HighPart > (Y).HighPart) \
  3198. )
  3199. #define RtlLargeIntegerGreaterThanOrEqualTo(X,Y) ( \
  3200. (((X).HighPart == (Y).HighPart) && ((X).LowPart >= (Y).LowPart)) || \
  3201. ((X).HighPart > (Y).HighPart) \
  3202. )
  3203. #define RtlLargeIntegerEqualTo(X,Y) ( \
  3204. !(((X).LowPart ^ (Y).LowPart) | ((X).HighPart ^ (Y).HighPart)) \
  3205. )
  3206. #define RtlLargeIntegerNotEqualTo(X,Y) ( \
  3207. (((X).LowPart ^ (Y).LowPart) | ((X).HighPart ^ (Y).HighPart)) \
  3208. )
  3209. #define RtlLargeIntegerLessThan(X,Y) ( \
  3210. (((X).HighPart == (Y).HighPart) && ((X).LowPart < (Y).LowPart)) || \
  3211. ((X).HighPart < (Y).HighPart) \
  3212. )
  3213. #define RtlLargeIntegerLessThanOrEqualTo(X,Y) ( \
  3214. (((X).HighPart == (Y).HighPart) && ((X).LowPart <= (Y).LowPart)) || \
  3215. ((X).HighPart < (Y).HighPart) \
  3216. )
  3217. #define RtlLargeIntegerGreaterThanZero(X) ( \
  3218. (((X).HighPart == 0) && ((X).LowPart > 0)) || \
  3219. ((X).HighPart > 0 ) \
  3220. )
  3221. #define RtlLargeIntegerGreaterOrEqualToZero(X) ( \
  3222. (X).HighPart >= 0 \
  3223. )
  3224. #define RtlLargeIntegerEqualToZero(X) ( \
  3225. !((X).LowPart | (X).HighPart) \
  3226. )
  3227. #define RtlLargeIntegerNotEqualToZero(X) ( \
  3228. ((X).LowPart | (X).HighPart) \
  3229. )
  3230. #define RtlLargeIntegerLessThanZero(X) ( \
  3231. ((X).HighPart < 0) \
  3232. )
  3233. #define RtlLargeIntegerLessOrEqualToZero(X) ( \
  3234. ((X).HighPart < 0) || !((X).LowPart | (X).HighPart) \
  3235. )
  3236. #endif // !defined(MIDL_PASS)
  3237. //
  3238. // Time conversion routines
  3239. //
  3240. typedef struct _TIME_FIELDS {
  3241. CSHORT Year; // range [1601...]
  3242. CSHORT Month; // range [1..12]
  3243. CSHORT Day; // range [1..31]
  3244. CSHORT Hour; // range [0..23]
  3245. CSHORT Minute; // range [0..59]
  3246. CSHORT Second; // range [0..59]
  3247. CSHORT Milliseconds;// range [0..999]
  3248. CSHORT Weekday; // range [0..6] == [Sunday..Saturday]
  3249. } TIME_FIELDS;
  3250. typedef TIME_FIELDS *PTIME_FIELDS;
  3251. // end_ntddk end_wdm end_ntifs
  3252. NTSYSAPI
  3253. BOOLEAN
  3254. NTAPI
  3255. RtlCutoverTimeToSystemTime(
  3256. PTIME_FIELDS CutoverTime,
  3257. PLARGE_INTEGER SystemTime,
  3258. PLARGE_INTEGER CurrentSystemTime,
  3259. BOOLEAN ThisYear
  3260. );
  3261. NTSYSAPI
  3262. NTSTATUS
  3263. NTAPI
  3264. RtlSystemTimeToLocalTime (
  3265. IN PLARGE_INTEGER SystemTime,
  3266. OUT PLARGE_INTEGER LocalTime
  3267. );
  3268. NTSYSAPI
  3269. NTSTATUS
  3270. NTAPI
  3271. RtlLocalTimeToSystemTime (
  3272. IN PLARGE_INTEGER LocalTime,
  3273. OUT PLARGE_INTEGER SystemTime
  3274. );
  3275. //
  3276. // A 64 bit Time value -> time field record
  3277. //
  3278. NTSYSAPI
  3279. VOID
  3280. NTAPI
  3281. RtlTimeToElapsedTimeFields (
  3282. IN PLARGE_INTEGER Time,
  3283. OUT PTIME_FIELDS TimeFields
  3284. );
  3285. // begin_ntddk begin_wdm begin_ntifs
  3286. NTSYSAPI
  3287. VOID
  3288. NTAPI
  3289. RtlTimeToTimeFields (
  3290. PLARGE_INTEGER Time,
  3291. PTIME_FIELDS TimeFields
  3292. );
  3293. //
  3294. // A time field record (Weekday ignored) -> 64 bit Time value
  3295. //
  3296. NTSYSAPI
  3297. BOOLEAN
  3298. NTAPI
  3299. RtlTimeFieldsToTime (
  3300. PTIME_FIELDS TimeFields,
  3301. PLARGE_INTEGER Time
  3302. );
  3303. // end_ntddk end_wdm
  3304. //
  3305. // A 64 bit Time value -> Seconds since the start of 1980
  3306. //
  3307. NTSYSAPI
  3308. BOOLEAN
  3309. NTAPI
  3310. RtlTimeToSecondsSince1980 (
  3311. PLARGE_INTEGER Time,
  3312. PULONG ElapsedSeconds
  3313. );
  3314. //
  3315. // Seconds since the start of 1980 -> 64 bit Time value
  3316. //
  3317. NTSYSAPI
  3318. VOID
  3319. NTAPI
  3320. RtlSecondsSince1980ToTime (
  3321. ULONG ElapsedSeconds,
  3322. PLARGE_INTEGER Time
  3323. );
  3324. //
  3325. // A 64 bit Time value -> Seconds since the start of 1970
  3326. //
  3327. NTSYSAPI
  3328. BOOLEAN
  3329. NTAPI
  3330. RtlTimeToSecondsSince1970 (
  3331. PLARGE_INTEGER Time,
  3332. PULONG ElapsedSeconds
  3333. );
  3334. //
  3335. // Seconds since the start of 1970 -> 64 bit Time value
  3336. //
  3337. NTSYSAPI
  3338. VOID
  3339. NTAPI
  3340. RtlSecondsSince1970ToTime (
  3341. ULONG ElapsedSeconds,
  3342. PLARGE_INTEGER Time
  3343. );
  3344. //
  3345. // The following macros store and retrieve USHORTS and ULONGS from potentially
  3346. // unaligned addresses, avoiding alignment faults. they should probably be
  3347. // rewritten in assembler
  3348. //
  3349. #define SHORT_SIZE (sizeof(USHORT))
  3350. #define SHORT_MASK (SHORT_SIZE - 1)
  3351. #define LONG_SIZE (sizeof(LONG))
  3352. #define LONGLONG_SIZE (sizeof(LONGLONG))
  3353. #define LONG_MASK (LONG_SIZE - 1)
  3354. #define LONGLONG_MASK (LONGLONG_SIZE - 1)
  3355. #define LOWBYTE_MASK 0x00FF
  3356. #define FIRSTBYTE(VALUE) ((VALUE) & LOWBYTE_MASK)
  3357. #define SECONDBYTE(VALUE) (((VALUE) >> 8) & LOWBYTE_MASK)
  3358. #define THIRDBYTE(VALUE) (((VALUE) >> 16) & LOWBYTE_MASK)
  3359. #define FOURTHBYTE(VALUE) (((VALUE) >> 24) & LOWBYTE_MASK)
  3360. //
  3361. // if MIPS Big Endian, order of bytes is reversed.
  3362. //
  3363. #define SHORT_LEAST_SIGNIFICANT_BIT 0
  3364. #define SHORT_MOST_SIGNIFICANT_BIT 1
  3365. #define LONG_LEAST_SIGNIFICANT_BIT 0
  3366. #define LONG_3RD_MOST_SIGNIFICANT_BIT 1
  3367. #define LONG_2ND_MOST_SIGNIFICANT_BIT 2
  3368. #define LONG_MOST_SIGNIFICANT_BIT 3
  3369. //++
  3370. //
  3371. // VOID
  3372. // RtlStoreUshort (
  3373. // PUSHORT ADDRESS
  3374. // USHORT VALUE
  3375. // )
  3376. //
  3377. // Routine Description:
  3378. //
  3379. // This macro stores a USHORT value in at a particular address, avoiding
  3380. // alignment faults.
  3381. //
  3382. // Arguments:
  3383. //
  3384. // ADDRESS - where to store USHORT value
  3385. // VALUE - USHORT to store
  3386. //
  3387. // Return Value:
  3388. //
  3389. // none.
  3390. //
  3391. //--
  3392. #define RtlStoreUshort(ADDRESS,VALUE) \
  3393. if ((ULONG_PTR)(ADDRESS) & SHORT_MASK) { \
  3394. ((PUCHAR) (ADDRESS))[SHORT_LEAST_SIGNIFICANT_BIT] = (UCHAR)(FIRSTBYTE(VALUE)); \
  3395. ((PUCHAR) (ADDRESS))[SHORT_MOST_SIGNIFICANT_BIT ] = (UCHAR)(SECONDBYTE(VALUE)); \
  3396. } \
  3397. else { \
  3398. *((PUSHORT) (ADDRESS)) = (USHORT) VALUE; \
  3399. }
  3400. //++
  3401. //
  3402. // VOID
  3403. // RtlStoreUlong (
  3404. // PULONG ADDRESS
  3405. // ULONG VALUE
  3406. // )
  3407. //
  3408. // Routine Description:
  3409. //
  3410. // This macro stores a ULONG value in at a particular address, avoiding
  3411. // alignment faults.
  3412. //
  3413. // Arguments:
  3414. //
  3415. // ADDRESS - where to store ULONG value
  3416. // VALUE - ULONG to store
  3417. //
  3418. // Return Value:
  3419. //
  3420. // none.
  3421. //
  3422. // Note:
  3423. // Depending on the machine, we might want to call storeushort in the
  3424. // unaligned case.
  3425. //
  3426. //--
  3427. #define RtlStoreUlong(ADDRESS,VALUE) \
  3428. if ((ULONG_PTR)(ADDRESS) & LONG_MASK) { \
  3429. ((PUCHAR) (ADDRESS))[LONG_LEAST_SIGNIFICANT_BIT ] = (UCHAR)(FIRSTBYTE(VALUE)); \
  3430. ((PUCHAR) (ADDRESS))[LONG_3RD_MOST_SIGNIFICANT_BIT ] = (UCHAR)(SECONDBYTE(VALUE)); \
  3431. ((PUCHAR) (ADDRESS))[LONG_2ND_MOST_SIGNIFICANT_BIT ] = (UCHAR)(THIRDBYTE(VALUE)); \
  3432. ((PUCHAR) (ADDRESS))[LONG_MOST_SIGNIFICANT_BIT ] = (UCHAR)(FOURTHBYTE(VALUE)); \
  3433. } \
  3434. else { \
  3435. *((PULONG) (ADDRESS)) = (ULONG) (VALUE); \
  3436. }
  3437. //++
  3438. //
  3439. // VOID
  3440. // RtlStoreUlonglong (
  3441. // PULONGLONG ADDRESS
  3442. // ULONG VALUE
  3443. // )
  3444. //
  3445. // Routine Description:
  3446. //
  3447. // This macro stores a ULONGLONG value in at a particular address, avoiding
  3448. // alignment faults.
  3449. //
  3450. // Arguments:
  3451. //
  3452. // ADDRESS - where to store ULONGLONG value
  3453. // VALUE - ULONGLONG to store
  3454. //
  3455. // Return Value:
  3456. //
  3457. // none.
  3458. //
  3459. //--
  3460. #define RtlStoreUlonglong(ADDRESS,VALUE) \
  3461. if ((ULONG_PTR)(ADDRESS) & LONGLONG_MASK) { \
  3462. RtlStoreUlong((ULONG_PTR)(ADDRESS), \
  3463. (ULONGLONG)(VALUE) & 0xFFFFFFFF); \
  3464. RtlStoreUlong((ULONG_PTR)(ADDRESS)+sizeof(ULONG), \
  3465. (ULONGLONG)(VALUE) >> 32); \
  3466. } else { \
  3467. *((PULONGLONG)(ADDRESS)) = (ULONGLONG)(VALUE); \
  3468. }
  3469. //++
  3470. //
  3471. // VOID
  3472. // RtlStoreUlongPtr (
  3473. // PULONG_PTR ADDRESS
  3474. // ULONG_PTR VALUE
  3475. // )
  3476. //
  3477. // Routine Description:
  3478. //
  3479. // This macro stores a ULONG_PTR value in at a particular address, avoiding
  3480. // alignment faults.
  3481. //
  3482. // Arguments:
  3483. //
  3484. // ADDRESS - where to store ULONG_PTR value
  3485. // VALUE - ULONG_PTR to store
  3486. //
  3487. // Return Value:
  3488. //
  3489. // none.
  3490. //
  3491. //--
  3492. #ifdef _WIN64
  3493. #define RtlStoreUlongPtr(ADDRESS,VALUE) \
  3494. RtlStoreUlonglong(ADDRESS,VALUE)
  3495. #else
  3496. #define RtlStoreUlongPtr(ADDRESS,VALUE) \
  3497. RtlStoreUlong(ADDRESS,VALUE)
  3498. #endif
  3499. //++
  3500. //
  3501. // VOID
  3502. // RtlRetrieveUshort (
  3503. // PUSHORT DESTINATION_ADDRESS
  3504. // PUSHORT SOURCE_ADDRESS
  3505. // )
  3506. //
  3507. // Routine Description:
  3508. //
  3509. // This macro retrieves a USHORT value from the SOURCE address, avoiding
  3510. // alignment faults. The DESTINATION address is assumed to be aligned.
  3511. //
  3512. // Arguments:
  3513. //
  3514. // DESTINATION_ADDRESS - where to store USHORT value
  3515. // SOURCE_ADDRESS - where to retrieve USHORT value from
  3516. //
  3517. // Return Value:
  3518. //
  3519. // none.
  3520. //
  3521. //--
  3522. #define RtlRetrieveUshort(DEST_ADDRESS,SRC_ADDRESS) \
  3523. if ((ULONG_PTR)SRC_ADDRESS & SHORT_MASK) { \
  3524. ((PUCHAR) DEST_ADDRESS)[0] = ((PUCHAR) SRC_ADDRESS)[0]; \
  3525. ((PUCHAR) DEST_ADDRESS)[1] = ((PUCHAR) SRC_ADDRESS)[1]; \
  3526. } \
  3527. else { \
  3528. *((PUSHORT) DEST_ADDRESS) = *((PUSHORT) SRC_ADDRESS); \
  3529. } \
  3530. //++
  3531. //
  3532. // VOID
  3533. // RtlRetrieveUlong (
  3534. // PULONG DESTINATION_ADDRESS
  3535. // PULONG SOURCE_ADDRESS
  3536. // )
  3537. //
  3538. // Routine Description:
  3539. //
  3540. // This macro retrieves a ULONG value from the SOURCE address, avoiding
  3541. // alignment faults. The DESTINATION address is assumed to be aligned.
  3542. //
  3543. // Arguments:
  3544. //
  3545. // DESTINATION_ADDRESS - where to store ULONG value
  3546. // SOURCE_ADDRESS - where to retrieve ULONG value from
  3547. //
  3548. // Return Value:
  3549. //
  3550. // none.
  3551. //
  3552. // Note:
  3553. // Depending on the machine, we might want to call retrieveushort in the
  3554. // unaligned case.
  3555. //
  3556. //--
  3557. #define RtlRetrieveUlong(DEST_ADDRESS,SRC_ADDRESS) \
  3558. if ((ULONG_PTR)SRC_ADDRESS & LONG_MASK) { \
  3559. ((PUCHAR) DEST_ADDRESS)[0] = ((PUCHAR) SRC_ADDRESS)[0]; \
  3560. ((PUCHAR) DEST_ADDRESS)[1] = ((PUCHAR) SRC_ADDRESS)[1]; \
  3561. ((PUCHAR) DEST_ADDRESS)[2] = ((PUCHAR) SRC_ADDRESS)[2]; \
  3562. ((PUCHAR) DEST_ADDRESS)[3] = ((PUCHAR) SRC_ADDRESS)[3]; \
  3563. } \
  3564. else { \
  3565. *((PULONG) DEST_ADDRESS) = *((PULONG) SRC_ADDRESS); \
  3566. }
  3567. // end_ntddk end_wdm
  3568. //++
  3569. //
  3570. // PCHAR
  3571. // RtlOffsetToPointer (
  3572. // PVOID Base,
  3573. // ULONG Offset
  3574. // )
  3575. //
  3576. // Routine Description:
  3577. //
  3578. // This macro generates a pointer which points to the byte that is 'Offset'
  3579. // bytes beyond 'Base'. This is useful for referencing fields within
  3580. // self-relative data structures.
  3581. //
  3582. // Arguments:
  3583. //
  3584. // Base - The address of the base of the structure.
  3585. //
  3586. // Offset - An unsigned integer offset of the byte whose address is to
  3587. // be generated.
  3588. //
  3589. // Return Value:
  3590. //
  3591. // A PCHAR pointer to the byte that is 'Offset' bytes beyond 'Base'.
  3592. //
  3593. //
  3594. //--
  3595. #define RtlOffsetToPointer(B,O) ((PCHAR)( ((PCHAR)(B)) + ((ULONG_PTR)(O)) ))
  3596. //++
  3597. //
  3598. // ULONG
  3599. // RtlPointerToOffset (
  3600. // PVOID Base,
  3601. // PVOID Pointer
  3602. // )
  3603. //
  3604. // Routine Description:
  3605. //
  3606. // This macro calculates the offset from Base to Pointer. This is useful
  3607. // for producing self-relative offsets for structures.
  3608. //
  3609. // Arguments:
  3610. //
  3611. // Base - The address of the base of the structure.
  3612. //
  3613. // Pointer - A pointer to a field, presumably within the structure
  3614. // pointed to by Base. This value must be larger than that specified
  3615. // for Base.
  3616. //
  3617. // Return Value:
  3618. //
  3619. // A ULONG offset from Base to Pointer.
  3620. //
  3621. //
  3622. //--
  3623. #define RtlPointerToOffset(B,P) ((ULONG)( ((PCHAR)(P)) - ((PCHAR)(B)) ))
  3624. // end_ntifs
  3625. // begin_ntifs begin_ntddk begin_wdm
  3626. //
  3627. // BitMap routines. The following structure, routines, and macros are
  3628. // for manipulating bitmaps. The user is responsible for allocating a bitmap
  3629. // structure (which is really a header) and a buffer (which must be longword
  3630. // aligned and multiple longwords in size).
  3631. //
  3632. typedef struct _RTL_BITMAP {
  3633. ULONG SizeOfBitMap; // Number of bits in bit map
  3634. PULONG Buffer; // Pointer to the bit map itself
  3635. } RTL_BITMAP;
  3636. typedef RTL_BITMAP *PRTL_BITMAP;
  3637. //
  3638. // The following routine initializes a new bitmap. It does not alter the
  3639. // data currently in the bitmap. This routine must be called before
  3640. // any other bitmap routine/macro.
  3641. //
  3642. NTSYSAPI
  3643. VOID
  3644. NTAPI
  3645. RtlInitializeBitMap (
  3646. PRTL_BITMAP BitMapHeader,
  3647. PULONG BitMapBuffer,
  3648. ULONG SizeOfBitMap
  3649. );
  3650. //
  3651. // The following three routines clear, set, and test the state of a
  3652. // single bit in a bitmap.
  3653. //
  3654. NTSYSAPI
  3655. VOID
  3656. NTAPI
  3657. RtlClearBit (
  3658. PRTL_BITMAP BitMapHeader,
  3659. ULONG BitNumber
  3660. );
  3661. NTSYSAPI
  3662. VOID
  3663. NTAPI
  3664. RtlSetBit (
  3665. PRTL_BITMAP BitMapHeader,
  3666. ULONG BitNumber
  3667. );
  3668. NTSYSAPI
  3669. BOOLEAN
  3670. NTAPI
  3671. RtlTestBit (
  3672. PRTL_BITMAP BitMapHeader,
  3673. ULONG BitNumber
  3674. );
  3675. //
  3676. // The following two routines either clear or set all of the bits
  3677. // in a bitmap.
  3678. //
  3679. NTSYSAPI
  3680. VOID
  3681. NTAPI
  3682. RtlClearAllBits (
  3683. PRTL_BITMAP BitMapHeader
  3684. );
  3685. NTSYSAPI
  3686. VOID
  3687. NTAPI
  3688. RtlSetAllBits (
  3689. PRTL_BITMAP BitMapHeader
  3690. );
  3691. //
  3692. // The following two routines locate a contiguous region of either
  3693. // clear or set bits within the bitmap. The region will be at least
  3694. // as large as the number specified, and the search of the bitmap will
  3695. // begin at the specified hint index (which is a bit index within the
  3696. // bitmap, zero based). The return value is the bit index of the located
  3697. // region (zero based) or -1 (i.e., 0xffffffff) if such a region cannot
  3698. // be located
  3699. //
  3700. NTSYSAPI
  3701. ULONG
  3702. NTAPI
  3703. RtlFindClearBits (
  3704. PRTL_BITMAP BitMapHeader,
  3705. ULONG NumberToFind,
  3706. ULONG HintIndex
  3707. );
  3708. NTSYSAPI
  3709. ULONG
  3710. NTAPI
  3711. RtlFindSetBits (
  3712. PRTL_BITMAP BitMapHeader,
  3713. ULONG NumberToFind,
  3714. ULONG HintIndex
  3715. );
  3716. //
  3717. // The following two routines locate a contiguous region of either
  3718. // clear or set bits within the bitmap and either set or clear the bits
  3719. // within the located region. The region will be as large as the number
  3720. // specified, and the search for the region will begin at the specified
  3721. // hint index (which is a bit index within the bitmap, zero based). The
  3722. // return value is the bit index of the located region (zero based) or
  3723. // -1 (i.e., 0xffffffff) if such a region cannot be located. If a region
  3724. // cannot be located then the setting/clearing of the bitmap is not performed.
  3725. //
  3726. NTSYSAPI
  3727. ULONG
  3728. NTAPI
  3729. RtlFindClearBitsAndSet (
  3730. PRTL_BITMAP BitMapHeader,
  3731. ULONG NumberToFind,
  3732. ULONG HintIndex
  3733. );
  3734. NTSYSAPI
  3735. ULONG
  3736. NTAPI
  3737. RtlFindSetBitsAndClear (
  3738. PRTL_BITMAP BitMapHeader,
  3739. ULONG NumberToFind,
  3740. ULONG HintIndex
  3741. );
  3742. //
  3743. // The following two routines clear or set bits within a specified region
  3744. // of the bitmap. The starting index is zero based.
  3745. //
  3746. NTSYSAPI
  3747. VOID
  3748. NTAPI
  3749. RtlClearBits (
  3750. PRTL_BITMAP BitMapHeader,
  3751. ULONG StartingIndex,
  3752. ULONG NumberToClear
  3753. );
  3754. NTSYSAPI
  3755. VOID
  3756. NTAPI
  3757. RtlSetBits (
  3758. PRTL_BITMAP BitMapHeader,
  3759. ULONG StartingIndex,
  3760. ULONG NumberToSet
  3761. );
  3762. //
  3763. // The following routine locates a set of contiguous regions of clear
  3764. // bits within the bitmap. The caller specifies whether to return the
  3765. // longest runs or just the first found lcoated. The following structure is
  3766. // used to denote a contiguous run of bits. The two routines return an array
  3767. // of this structure, one for each run located.
  3768. //
  3769. typedef struct _RTL_BITMAP_RUN {
  3770. ULONG StartingIndex;
  3771. ULONG NumberOfBits;
  3772. } RTL_BITMAP_RUN;
  3773. typedef RTL_BITMAP_RUN *PRTL_BITMAP_RUN;
  3774. NTSYSAPI
  3775. ULONG
  3776. NTAPI
  3777. RtlFindClearRuns (
  3778. PRTL_BITMAP BitMapHeader,
  3779. PRTL_BITMAP_RUN RunArray,
  3780. ULONG SizeOfRunArray,
  3781. BOOLEAN LocateLongestRuns
  3782. );
  3783. //
  3784. // The following routine locates the longest contiguous region of
  3785. // clear bits within the bitmap. The returned starting index value
  3786. // denotes the first contiguous region located satisfying our requirements
  3787. // The return value is the length (in bits) of the longest region found.
  3788. //
  3789. NTSYSAPI
  3790. ULONG
  3791. NTAPI
  3792. RtlFindLongestRunClear (
  3793. PRTL_BITMAP BitMapHeader,
  3794. PULONG StartingIndex
  3795. );
  3796. //
  3797. // The following routine locates the first contiguous region of
  3798. // clear bits within the bitmap. The returned starting index value
  3799. // denotes the first contiguous region located satisfying our requirements
  3800. // The return value is the length (in bits) of the region found.
  3801. //
  3802. NTSYSAPI
  3803. ULONG
  3804. NTAPI
  3805. RtlFindFirstRunClear (
  3806. PRTL_BITMAP BitMapHeader,
  3807. PULONG StartingIndex
  3808. );
  3809. //
  3810. // The following macro returns the value of the bit stored within the
  3811. // bitmap at the specified location. If the bit is set a value of 1 is
  3812. // returned otherwise a value of 0 is returned.
  3813. //
  3814. // ULONG
  3815. // RtlCheckBit (
  3816. // PRTL_BITMAP BitMapHeader,
  3817. // ULONG BitPosition
  3818. // );
  3819. //
  3820. //
  3821. // To implement CheckBit the macro retrieves the longword containing the
  3822. // bit in question, shifts the longword to get the bit in question into the
  3823. // low order bit position and masks out all other bits.
  3824. //
  3825. #define RtlCheckBit(BMH,BP) ((((BMH)->Buffer[(BP) / 32]) >> ((BP) % 32)) & 0x1)
  3826. //
  3827. // The following two procedures return to the caller the total number of
  3828. // clear or set bits within the specified bitmap.
  3829. //
  3830. NTSYSAPI
  3831. ULONG
  3832. NTAPI
  3833. RtlNumberOfClearBits (
  3834. PRTL_BITMAP BitMapHeader
  3835. );
  3836. NTSYSAPI
  3837. ULONG
  3838. NTAPI
  3839. RtlNumberOfSetBits (
  3840. PRTL_BITMAP BitMapHeader
  3841. );
  3842. //
  3843. // The following two procedures return to the caller a boolean value
  3844. // indicating if the specified range of bits are all clear or set.
  3845. //
  3846. NTSYSAPI
  3847. BOOLEAN
  3848. NTAPI
  3849. RtlAreBitsClear (
  3850. PRTL_BITMAP BitMapHeader,
  3851. ULONG StartingIndex,
  3852. ULONG Length
  3853. );
  3854. NTSYSAPI
  3855. BOOLEAN
  3856. NTAPI
  3857. RtlAreBitsSet (
  3858. PRTL_BITMAP BitMapHeader,
  3859. ULONG StartingIndex,
  3860. ULONG Length
  3861. );
  3862. NTSYSAPI
  3863. ULONG
  3864. NTAPI
  3865. RtlFindNextForwardRunClear (
  3866. IN PRTL_BITMAP BitMapHeader,
  3867. IN ULONG FromIndex,
  3868. IN PULONG StartingRunIndex
  3869. );
  3870. NTSYSAPI
  3871. ULONG
  3872. NTAPI
  3873. RtlFindLastBackwardRunClear (
  3874. IN PRTL_BITMAP BitMapHeader,
  3875. IN ULONG FromIndex,
  3876. IN PULONG StartingRunIndex
  3877. );
  3878. //
  3879. // The following two procedures return to the caller a value indicating
  3880. // the position within a ULONGLONG of the most or least significant non-zero
  3881. // bit. A value of zero results in a return value of -1.
  3882. //
  3883. NTSYSAPI
  3884. CCHAR
  3885. NTAPI
  3886. RtlFindLeastSignificantBit (
  3887. IN ULONGLONG Set
  3888. );
  3889. NTSYSAPI
  3890. CCHAR
  3891. NTAPI
  3892. RtlFindMostSignificantBit (
  3893. IN ULONGLONG Set
  3894. );
  3895. //
  3896. // Range list package
  3897. //
  3898. typedef struct _RTL_RANGE {
  3899. //
  3900. // The start of the range
  3901. //
  3902. ULONGLONG Start; // Read only
  3903. //
  3904. // The end of the range
  3905. //
  3906. ULONGLONG End; // Read only
  3907. //
  3908. // Data the user passed in when they created the range
  3909. //
  3910. PVOID UserData; // Read/Write
  3911. //
  3912. // The owner of the range
  3913. //
  3914. PVOID Owner; // Read/Write
  3915. //
  3916. // User defined flags the user specified when they created the range
  3917. //
  3918. UCHAR Attributes; // Read/Write
  3919. //
  3920. // Flags (RTL_RANGE_*)
  3921. //
  3922. UCHAR Flags; // Read only
  3923. } RTL_RANGE, *PRTL_RANGE;
  3924. #define RTL_RANGE_SHARED 0x01
  3925. #define RTL_RANGE_CONFLICT 0x02
  3926. typedef struct _RTL_RANGE_LIST {
  3927. //
  3928. // The list of ranges
  3929. //
  3930. LIST_ENTRY ListHead;
  3931. //
  3932. // These always come in useful
  3933. //
  3934. ULONG Flags; // use RANGE_LIST_FLAG_*
  3935. //
  3936. // The number of entries in the list
  3937. //
  3938. ULONG Count;
  3939. //
  3940. // Every time an add/delete operation is performed on the list this is
  3941. // incremented. It is checked during iteration to ensure that the list
  3942. // hasn't changed between GetFirst/GetNext or GetNext/GetNext calls
  3943. //
  3944. ULONG Stamp;
  3945. } RTL_RANGE_LIST, *PRTL_RANGE_LIST;
  3946. typedef struct _RANGE_LIST_ITERATOR {
  3947. PLIST_ENTRY RangeListHead;
  3948. PLIST_ENTRY MergedHead;
  3949. PVOID Current;
  3950. ULONG Stamp;
  3951. } RTL_RANGE_LIST_ITERATOR, *PRTL_RANGE_LIST_ITERATOR;
  3952. NTSYSAPI
  3953. VOID
  3954. NTAPI
  3955. RtlInitializeRangeList(
  3956. IN OUT PRTL_RANGE_LIST RangeList
  3957. );
  3958. NTSYSAPI
  3959. VOID
  3960. NTAPI
  3961. RtlFreeRangeList(
  3962. IN PRTL_RANGE_LIST RangeList
  3963. );
  3964. NTSYSAPI
  3965. NTSTATUS
  3966. NTAPI
  3967. RtlCopyRangeList(
  3968. OUT PRTL_RANGE_LIST CopyRangeList,
  3969. IN PRTL_RANGE_LIST RangeList
  3970. );
  3971. #define RTL_RANGE_LIST_ADD_IF_CONFLICT 0x00000001
  3972. #define RTL_RANGE_LIST_ADD_SHARED 0x00000002
  3973. NTSYSAPI
  3974. NTSTATUS
  3975. NTAPI
  3976. RtlAddRange(
  3977. IN OUT PRTL_RANGE_LIST RangeList,
  3978. IN ULONGLONG Start,
  3979. IN ULONGLONG End,
  3980. IN UCHAR Attributes,
  3981. IN ULONG Flags,
  3982. IN PVOID UserData, OPTIONAL
  3983. IN PVOID Owner OPTIONAL
  3984. );
  3985. NTSYSAPI
  3986. NTSTATUS
  3987. NTAPI
  3988. RtlDeleteRange(
  3989. IN OUT PRTL_RANGE_LIST RangeList,
  3990. IN ULONGLONG Start,
  3991. IN ULONGLONG End,
  3992. IN PVOID Owner
  3993. );
  3994. NTSYSAPI
  3995. NTSTATUS
  3996. NTAPI
  3997. RtlDeleteOwnersRanges(
  3998. IN OUT PRTL_RANGE_LIST RangeList,
  3999. IN PVOID Owner
  4000. );
  4001. #define RTL_RANGE_LIST_SHARED_OK 0x00000001
  4002. #define RTL_RANGE_LIST_NULL_CONFLICT_OK 0x00000002
  4003. typedef
  4004. BOOLEAN
  4005. (*PRTL_CONFLICT_RANGE_CALLBACK) (
  4006. IN PVOID Context,
  4007. IN PRTL_RANGE Range
  4008. );
  4009. NTSYSAPI
  4010. NTSTATUS
  4011. NTAPI
  4012. RtlFindRange(
  4013. IN PRTL_RANGE_LIST RangeList,
  4014. IN ULONGLONG Minimum,
  4015. IN ULONGLONG Maximum,
  4016. IN ULONG Length,
  4017. IN ULONG Alignment,
  4018. IN ULONG Flags,
  4019. IN UCHAR AttributeAvailableMask,
  4020. IN PVOID Context OPTIONAL,
  4021. IN PRTL_CONFLICT_RANGE_CALLBACK Callback OPTIONAL,
  4022. OUT PULONGLONG Start
  4023. );
  4024. NTSYSAPI
  4025. NTSTATUS
  4026. NTAPI
  4027. RtlIsRangeAvailable(
  4028. IN PRTL_RANGE_LIST RangeList,
  4029. IN ULONGLONG Start,
  4030. IN ULONGLONG End,
  4031. IN ULONG Flags,
  4032. IN UCHAR AttributeAvailableMask,
  4033. IN PVOID Context OPTIONAL,
  4034. IN PRTL_CONFLICT_RANGE_CALLBACK Callback OPTIONAL,
  4035. OUT PBOOLEAN Available
  4036. );
  4037. #define FOR_ALL_RANGES(RangeList, Iterator, Current) \
  4038. for (RtlGetFirstRange((RangeList), (Iterator), &(Current)); \
  4039. (Current) != NULL; \
  4040. RtlGetNextRange((Iterator), &(Current), TRUE) \
  4041. )
  4042. #define FOR_ALL_RANGES_BACKWARDS(RangeList, Iterator, Current) \
  4043. for (RtlGetLastRange((RangeList), (Iterator), &(Current)); \
  4044. (Current) != NULL; \
  4045. RtlGetNextRange((Iterator), &(Current), FALSE) \
  4046. )
  4047. NTSYSAPI
  4048. NTSTATUS
  4049. NTAPI
  4050. RtlGetFirstRange(
  4051. IN PRTL_RANGE_LIST RangeList,
  4052. OUT PRTL_RANGE_LIST_ITERATOR Iterator,
  4053. OUT PRTL_RANGE *Range
  4054. );
  4055. NTSYSAPI
  4056. NTSTATUS
  4057. NTAPI
  4058. RtlGetLastRange(
  4059. IN PRTL_RANGE_LIST RangeList,
  4060. OUT PRTL_RANGE_LIST_ITERATOR Iterator,
  4061. OUT PRTL_RANGE *Range
  4062. );
  4063. NTSYSAPI
  4064. NTSTATUS
  4065. NTAPI
  4066. RtlGetNextRange(
  4067. IN OUT PRTL_RANGE_LIST_ITERATOR Iterator,
  4068. OUT PRTL_RANGE *Range,
  4069. IN BOOLEAN MoveForwards
  4070. );
  4071. #define RTL_RANGE_LIST_MERGE_IF_CONFLICT RTL_RANGE_LIST_ADD_IF_CONFLICT
  4072. NTSYSAPI
  4073. NTSTATUS
  4074. NTAPI
  4075. RtlMergeRangeLists(
  4076. OUT PRTL_RANGE_LIST MergedRangeList,
  4077. IN PRTL_RANGE_LIST RangeList1,
  4078. IN PRTL_RANGE_LIST RangeList2,
  4079. IN ULONG Flags
  4080. );
  4081. NTSYSAPI
  4082. NTSTATUS
  4083. NTAPI
  4084. RtlInvertRangeList(
  4085. OUT PRTL_RANGE_LIST InvertedRangeList,
  4086. IN PRTL_RANGE_LIST RangeList
  4087. );
  4088. //
  4089. // Component name filter id enumeration and levels.
  4090. //
  4091. #define DPFLTR_ERROR_LEVEL 0
  4092. #define DPFLTR_WARNING_LEVEL 1
  4093. #define DPFLTR_TRACE_LEVEL 2
  4094. #define DPFLTR_INFO_LEVEL 3
  4095. #define DPFLTR_MASK 0x80000000
  4096. typedef enum _DPFLTR_TYPE {
  4097. DPFLTR_SYSTEM_ID = 0,
  4098. DPFLTR_SMSS_ID = 1,
  4099. DPFLTR_SETUP_ID = 2,
  4100. DPFLTR_NTFS_ID = 3,
  4101. DPFLTR_FSTUB_ID = 4,
  4102. DPFLTR_CRASHDUMP_ID = 5,
  4103. DPFLTR_CDAUDIO_ID = 6,
  4104. DPFLTR_CDROM_ID = 7,
  4105. DPFLTR_CLASSPNP_ID = 8,
  4106. DPFLTR_DISK_ID = 9,
  4107. DPFLTR_REDBOOK_ID = 10,
  4108. DPFLTR_STORPROP_ID = 11,
  4109. DPFLTR_SCSIPORT_ID = 12,
  4110. DPFLTR_SCSIMINIPORT_ID = 13,
  4111. DPFLTR_CONFIG_ID = 14,
  4112. DPFLTR_I8042PRT_ID = 15,
  4113. DPFLTR_SERMOUSE_ID = 16,
  4114. DPFLTR_LSERMOUS_ID = 17,
  4115. DPFLTR_KBDHID_ID = 18,
  4116. DPFLTR_MOUHID_ID = 19,
  4117. DPFLTR_KBDCLASS_ID = 20,
  4118. DPFLTR_MOUCLASS_ID = 21,
  4119. DPFLTR_TWOTRACK_ID = 22,
  4120. DPFLTR_WMILIB_ID = 23,
  4121. DPFLTR_ACPI_ID = 24,
  4122. DPFLTR_AMLI_ID = 25,
  4123. DPFLTR_HALIA64_ID = 26,
  4124. DPFLTR_VIDEO_ID = 27,
  4125. DPFLTR_SVCHOST_ID = 28,
  4126. DPFLTR_VIDEOPRT_ID = 29,
  4127. DPFLTR_TCPIP_ID = 30,
  4128. DPFLTR_DMSYNTH_ID = 31,
  4129. DPFLTR_NTOSPNP_ID = 32,
  4130. DPFLTR_FASTFAT_ID = 33,
  4131. DPFLTR_SAMSS_ID = 34,
  4132. DPFLTR_PNPMGR_ID = 35,
  4133. DPFLTR_NETAPI_ID = 36,
  4134. DPFLTR_SCSERVER_ID = 37,
  4135. DPFLTR_SCCLIENT_ID = 38,
  4136. DPFLTR_SERIAL_ID = 39,
  4137. DPFLTR_SERENUM_ID = 40,
  4138. DPFLTR_UHCD_ID = 41,
  4139. DPFLTR_RPCPROXY_ID = 42,
  4140. DPFLTR_AUTOCHK_ID = 43,
  4141. DPFLTR_DCOMSS_ID = 44,
  4142. DPFLTR_UNIMODEM_ID = 45,
  4143. DPFLTR_SIS_ID = 46,
  4144. DPFLTR_FLTMGR_ID = 47,
  4145. DPFLTR_WMICORE_ID = 48,
  4146. DPFLTR_BURNENG_ID = 49,
  4147. DPFLTR_IMAPI_ID = 50,
  4148. DPFLTR_SXS_ID = 51,
  4149. DPFLTR_FUSION_ID = 52,
  4150. DPFLTR_IDLETASK_ID = 53,
  4151. DPFLTR_SOFTPCI_ID = 54,
  4152. DPFLTR_TAPE_ID = 55,
  4153. DPFLTR_MCHGR_ID = 56,
  4154. DPFLTR_IDEP_ID = 57,
  4155. DPFLTR_PCIIDE_ID = 58,
  4156. DPFLTR_FLOPPY_ID = 59,
  4157. DPFLTR_FDC_ID = 60,
  4158. DPFLTR_TERMSRV_ID = 61,
  4159. DPFLTR_W32TIME_ID = 62,
  4160. DPFLTR_PREFETCHER_ID = 63,
  4161. DPFLTR_RSFILTER_ID = 64,
  4162. DPFLTR_FCPORT_ID = 65,
  4163. DPFLTR_PCI_ID = 66,
  4164. DPFLTR_DMIO_ID = 67,
  4165. DPFLTR_DMCONFIG_ID = 68,
  4166. DPFLTR_DMADMIN_ID = 69,
  4167. DPFLTR_WSOCKTRANSPORT_ID = 70,
  4168. DPFLTR_VSS_ID = 71,
  4169. DPFLTR_PNPMEM_ID = 72,
  4170. DPFLTR_PROCESSOR_ID = 73,
  4171. DPFLTR_DMSERVER_ID = 74,
  4172. DPFLTR_SR_ID = 75,
  4173. DPFLTR_INFINIBAND_ID = 76,
  4174. DPFLTR_IHVDRIVER_ID = 77,
  4175. DPFLTR_IHVVIDEO_ID = 78,
  4176. DPFLTR_IHVAUDIO_ID = 79,
  4177. DPFLTR_IHVNETWORK_ID = 80,
  4178. DPFLTR_IHVSTREAMING_ID = 81,
  4179. DPFLTR_IHVBUS_ID = 82,
  4180. DPFLTR_HPS_ID = 83,
  4181. DPFLTR_RTLTHREADPOOL_ID = 84,
  4182. DPFLTR_LDR_ID = 85,
  4183. DPFLTR_TCPIP6_ID = 86,
  4184. DPFLTR_ISAPNP_ID = 87,
  4185. DPFLTR_SHPC_ID = 88,
  4186. DPFLTR_STORPORT_ID = 89,
  4187. DPFLTR_STORMINIPORT_ID = 90,
  4188. DPFLTR_PRINTSPOOLER_ID = 91,
  4189. DPFLTR_VSSDYNDISK_ID = 92,
  4190. DPFLTR_VERIFIER_ID = 93,
  4191. DPFLTR_VDS_ID = 94,
  4192. DPFLTR_VDSBAS_ID = 95,
  4193. DPFLTR_VDSDYNDR_ID = 96,
  4194. DPFLTR_VDSUTIL_ID = 97,
  4195. DPFLTR_DFRGIFC_ID = 98,
  4196. DPFLTR_ENDOFTABLE_ID
  4197. } DPFLTR_TYPE;
  4198. //
  4199. // Registry Specific Access Rights.
  4200. //
  4201. #define KEY_QUERY_VALUE (0x0001)
  4202. #define KEY_SET_VALUE (0x0002)
  4203. #define KEY_CREATE_SUB_KEY (0x0004)
  4204. #define KEY_ENUMERATE_SUB_KEYS (0x0008)
  4205. #define KEY_NOTIFY (0x0010)
  4206. #define KEY_CREATE_LINK (0x0020)
  4207. #define KEY_WOW64_32KEY (0x0200)
  4208. #define KEY_WOW64_64KEY (0x0100)
  4209. #define KEY_WOW64_RES (0x0300)
  4210. #define KEY_READ ((STANDARD_RIGHTS_READ |\
  4211. KEY_QUERY_VALUE |\
  4212. KEY_ENUMERATE_SUB_KEYS |\
  4213. KEY_NOTIFY) \
  4214. & \
  4215. (~SYNCHRONIZE))
  4216. #define KEY_WRITE ((STANDARD_RIGHTS_WRITE |\
  4217. KEY_SET_VALUE |\
  4218. KEY_CREATE_SUB_KEY) \
  4219. & \
  4220. (~SYNCHRONIZE))
  4221. #define KEY_EXECUTE ((KEY_READ) \
  4222. & \
  4223. (~SYNCHRONIZE))
  4224. #define KEY_ALL_ACCESS ((STANDARD_RIGHTS_ALL |\
  4225. KEY_QUERY_VALUE |\
  4226. KEY_SET_VALUE |\
  4227. KEY_CREATE_SUB_KEY |\
  4228. KEY_ENUMERATE_SUB_KEYS |\
  4229. KEY_NOTIFY |\
  4230. KEY_CREATE_LINK) \
  4231. & \
  4232. (~SYNCHRONIZE))
  4233. //
  4234. // Open/Create Options
  4235. //
  4236. #define REG_OPTION_RESERVED (0x00000000L) // Parameter is reserved
  4237. #define REG_OPTION_NON_VOLATILE (0x00000000L) // Key is preserved
  4238. // when system is rebooted
  4239. #define REG_OPTION_VOLATILE (0x00000001L) // Key is not preserved
  4240. // when system is rebooted
  4241. #define REG_OPTION_CREATE_LINK (0x00000002L) // Created key is a
  4242. // symbolic link
  4243. #define REG_OPTION_BACKUP_RESTORE (0x00000004L) // open for backup or restore
  4244. // special access rules
  4245. // privilege required
  4246. #define REG_OPTION_OPEN_LINK (0x00000008L) // Open symbolic link
  4247. #define REG_LEGAL_OPTION \
  4248. (REG_OPTION_RESERVED |\
  4249. REG_OPTION_NON_VOLATILE |\
  4250. REG_OPTION_VOLATILE |\
  4251. REG_OPTION_CREATE_LINK |\
  4252. REG_OPTION_BACKUP_RESTORE |\
  4253. REG_OPTION_OPEN_LINK)
  4254. //
  4255. // Key creation/open disposition
  4256. //
  4257. #define REG_CREATED_NEW_KEY (0x00000001L) // New Registry Key created
  4258. #define REG_OPENED_EXISTING_KEY (0x00000002L) // Existing Key opened
  4259. //
  4260. // hive format to be used by Reg(Nt)SaveKeyEx
  4261. //
  4262. #define REG_STANDARD_FORMAT 1
  4263. #define REG_LATEST_FORMAT 2
  4264. #define REG_NO_COMPRESSION 4
  4265. //
  4266. // Key restore flags
  4267. //
  4268. #define REG_WHOLE_HIVE_VOLATILE (0x00000001L) // Restore whole hive volatile
  4269. #define REG_REFRESH_HIVE (0x00000002L) // Unwind changes to last flush
  4270. #define REG_NO_LAZY_FLUSH (0x00000004L) // Never lazy flush this hive
  4271. #define REG_FORCE_RESTORE (0x00000008L) // Force the restore process even when we have open handles on subkeys
  4272. //
  4273. // Unload Flags
  4274. //
  4275. #define REG_FORCE_UNLOAD 1
  4276. //
  4277. // Key query structures
  4278. //
  4279. typedef struct _KEY_BASIC_INFORMATION {
  4280. LARGE_INTEGER LastWriteTime;
  4281. ULONG TitleIndex;
  4282. ULONG NameLength;
  4283. WCHAR Name[1]; // Variable length string
  4284. } KEY_BASIC_INFORMATION, *PKEY_BASIC_INFORMATION;
  4285. typedef struct _KEY_NODE_INFORMATION {
  4286. LARGE_INTEGER LastWriteTime;
  4287. ULONG TitleIndex;
  4288. ULONG ClassOffset;
  4289. ULONG ClassLength;
  4290. ULONG NameLength;
  4291. WCHAR Name[1]; // Variable length string
  4292. // Class[1]; // Variable length string not declared
  4293. } KEY_NODE_INFORMATION, *PKEY_NODE_INFORMATION;
  4294. typedef struct _KEY_FULL_INFORMATION {
  4295. LARGE_INTEGER LastWriteTime;
  4296. ULONG TitleIndex;
  4297. ULONG ClassOffset;
  4298. ULONG ClassLength;
  4299. ULONG SubKeys;
  4300. ULONG MaxNameLen;
  4301. ULONG MaxClassLen;
  4302. ULONG Values;
  4303. ULONG MaxValueNameLen;
  4304. ULONG MaxValueDataLen;
  4305. WCHAR Class[1]; // Variable length
  4306. } KEY_FULL_INFORMATION, *PKEY_FULL_INFORMATION;
  4307. // end_wdm
  4308. typedef struct _KEY_NAME_INFORMATION {
  4309. ULONG NameLength;
  4310. WCHAR Name[1]; // Variable length string
  4311. } KEY_NAME_INFORMATION, *PKEY_NAME_INFORMATION;
  4312. typedef struct _KEY_CACHED_INFORMATION {
  4313. LARGE_INTEGER LastWriteTime;
  4314. ULONG TitleIndex;
  4315. ULONG SubKeys;
  4316. ULONG MaxNameLen;
  4317. ULONG Values;
  4318. ULONG MaxValueNameLen;
  4319. ULONG MaxValueDataLen;
  4320. ULONG NameLength;
  4321. WCHAR Name[1]; // Variable length string
  4322. } KEY_CACHED_INFORMATION, *PKEY_CACHED_INFORMATION;
  4323. typedef struct _KEY_FLAGS_INFORMATION {
  4324. ULONG UserFlags;
  4325. } KEY_FLAGS_INFORMATION, *PKEY_FLAGS_INFORMATION;
  4326. // begin_wdm
  4327. typedef enum _KEY_INFORMATION_CLASS {
  4328. KeyBasicInformation,
  4329. KeyNodeInformation,
  4330. KeyFullInformation
  4331. // end_wdm
  4332. ,
  4333. KeyNameInformation,
  4334. KeyCachedInformation,
  4335. KeyFlagsInformation,
  4336. MaxKeyInfoClass // MaxKeyInfoClass should always be the last enum
  4337. // begin_wdm
  4338. } KEY_INFORMATION_CLASS;
  4339. typedef struct _KEY_WRITE_TIME_INFORMATION {
  4340. LARGE_INTEGER LastWriteTime;
  4341. } KEY_WRITE_TIME_INFORMATION, *PKEY_WRITE_TIME_INFORMATION;
  4342. typedef struct _KEY_USER_FLAGS_INFORMATION {
  4343. ULONG UserFlags;
  4344. } KEY_USER_FLAGS_INFORMATION, *PKEY_USER_FLAGS_INFORMATION;
  4345. typedef enum _KEY_SET_INFORMATION_CLASS {
  4346. KeyWriteTimeInformation,
  4347. KeyUserFlagsInformation,
  4348. MaxKeySetInfoClass // MaxKeySetInfoClass should always be the last enum
  4349. } KEY_SET_INFORMATION_CLASS;
  4350. //
  4351. // Value entry query structures
  4352. //
  4353. typedef struct _KEY_VALUE_BASIC_INFORMATION {
  4354. ULONG TitleIndex;
  4355. ULONG Type;
  4356. ULONG NameLength;
  4357. WCHAR Name[1]; // Variable size
  4358. } KEY_VALUE_BASIC_INFORMATION, *PKEY_VALUE_BASIC_INFORMATION;
  4359. typedef struct _KEY_VALUE_FULL_INFORMATION {
  4360. ULONG TitleIndex;
  4361. ULONG Type;
  4362. ULONG DataOffset;
  4363. ULONG DataLength;
  4364. ULONG NameLength;
  4365. WCHAR Name[1]; // Variable size
  4366. // Data[1]; // Variable size data not declared
  4367. } KEY_VALUE_FULL_INFORMATION, *PKEY_VALUE_FULL_INFORMATION;
  4368. typedef struct _KEY_VALUE_PARTIAL_INFORMATION {
  4369. ULONG TitleIndex;
  4370. ULONG Type;
  4371. ULONG DataLength;
  4372. UCHAR Data[1]; // Variable size
  4373. } KEY_VALUE_PARTIAL_INFORMATION, *PKEY_VALUE_PARTIAL_INFORMATION;
  4374. typedef struct _KEY_VALUE_PARTIAL_INFORMATION_ALIGN64 {
  4375. ULONG Type;
  4376. ULONG DataLength;
  4377. UCHAR Data[1]; // Variable size
  4378. } KEY_VALUE_PARTIAL_INFORMATION_ALIGN64, *PKEY_VALUE_PARTIAL_INFORMATION_ALIGN64;
  4379. typedef struct _KEY_VALUE_ENTRY {
  4380. PUNICODE_STRING ValueName;
  4381. ULONG DataLength;
  4382. ULONG DataOffset;
  4383. ULONG Type;
  4384. } KEY_VALUE_ENTRY, *PKEY_VALUE_ENTRY;
  4385. typedef enum _KEY_VALUE_INFORMATION_CLASS {
  4386. KeyValueBasicInformation,
  4387. KeyValueFullInformation,
  4388. KeyValuePartialInformation,
  4389. KeyValueFullInformationAlign64,
  4390. KeyValuePartialInformationAlign64,
  4391. MaxKeyValueInfoClass // MaxKeyValueInfoClass should always be the last enum
  4392. } KEY_VALUE_INFORMATION_CLASS;
  4393. // begin_winnt
  4394. //
  4395. // Define access rights to files and directories
  4396. //
  4397. //
  4398. // The FILE_READ_DATA and FILE_WRITE_DATA constants are also defined in
  4399. // devioctl.h as FILE_READ_ACCESS and FILE_WRITE_ACCESS. The values for these
  4400. // constants *MUST* always be in sync.
  4401. // The values are redefined in devioctl.h because they must be available to
  4402. // both DOS and NT.
  4403. //
  4404. #define FILE_READ_DATA ( 0x0001 ) // file & pipe
  4405. #define FILE_LIST_DIRECTORY ( 0x0001 ) // directory
  4406. #define FILE_WRITE_DATA ( 0x0002 ) // file & pipe
  4407. #define FILE_ADD_FILE ( 0x0002 ) // directory
  4408. #define FILE_APPEND_DATA ( 0x0004 ) // file
  4409. #define FILE_ADD_SUBDIRECTORY ( 0x0004 ) // directory
  4410. #define FILE_CREATE_PIPE_INSTANCE ( 0x0004 ) // named pipe
  4411. #define FILE_READ_EA ( 0x0008 ) // file & directory
  4412. #define FILE_WRITE_EA ( 0x0010 ) // file & directory
  4413. #define FILE_EXECUTE ( 0x0020 ) // file
  4414. #define FILE_TRAVERSE ( 0x0020 ) // directory
  4415. #define FILE_DELETE_CHILD ( 0x0040 ) // directory
  4416. #define FILE_READ_ATTRIBUTES ( 0x0080 ) // all
  4417. #define FILE_WRITE_ATTRIBUTES ( 0x0100 ) // all
  4418. #define FILE_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | 0x1FF)
  4419. #define FILE_GENERIC_READ (STANDARD_RIGHTS_READ |\
  4420. FILE_READ_DATA |\
  4421. FILE_READ_ATTRIBUTES |\
  4422. FILE_READ_EA |\
  4423. SYNCHRONIZE)
  4424. #define FILE_GENERIC_WRITE (STANDARD_RIGHTS_WRITE |\
  4425. FILE_WRITE_DATA |\
  4426. FILE_WRITE_ATTRIBUTES |\
  4427. FILE_WRITE_EA |\
  4428. FILE_APPEND_DATA |\
  4429. SYNCHRONIZE)
  4430. #define FILE_GENERIC_EXECUTE (STANDARD_RIGHTS_EXECUTE |\
  4431. FILE_READ_ATTRIBUTES |\
  4432. FILE_EXECUTE |\
  4433. SYNCHRONIZE)
  4434. // end_winnt
  4435. //
  4436. // Define share access rights to files and directories
  4437. //
  4438. #define FILE_SHARE_READ 0x00000001 // winnt
  4439. #define FILE_SHARE_WRITE 0x00000002 // winnt
  4440. #define FILE_SHARE_DELETE 0x00000004 // winnt
  4441. #define FILE_SHARE_VALID_FLAGS 0x00000007
  4442. //
  4443. // Define the file attributes values
  4444. //
  4445. // Note: 0x00000008 is reserved for use for the old DOS VOLID (volume ID)
  4446. // and is therefore not considered valid in NT.
  4447. //
  4448. // Note: 0x00000010 is reserved for use for the old DOS SUBDIRECTORY flag
  4449. // and is therefore not considered valid in NT. This flag has
  4450. // been disassociated with file attributes since the other flags are
  4451. // protected with READ_ and WRITE_ATTRIBUTES access to the file.
  4452. //
  4453. // Note: Note also that the order of these flags is set to allow both the
  4454. // FAT and the Pinball File Systems to directly set the attributes
  4455. // flags in attributes words without having to pick each flag out
  4456. // individually. The order of these flags should not be changed!
  4457. //
  4458. #define FILE_ATTRIBUTE_READONLY 0x00000001 // winnt
  4459. #define FILE_ATTRIBUTE_HIDDEN 0x00000002 // winnt
  4460. #define FILE_ATTRIBUTE_SYSTEM 0x00000004 // winnt
  4461. //OLD DOS VOLID 0x00000008
  4462. #define FILE_ATTRIBUTE_DIRECTORY 0x00000010 // winnt
  4463. #define FILE_ATTRIBUTE_ARCHIVE 0x00000020 // winnt
  4464. #define FILE_ATTRIBUTE_DEVICE 0x00000040 // winnt
  4465. #define FILE_ATTRIBUTE_NORMAL 0x00000080 // winnt
  4466. #define FILE_ATTRIBUTE_TEMPORARY 0x00000100 // winnt
  4467. #define FILE_ATTRIBUTE_SPARSE_FILE 0x00000200 // winnt
  4468. #define FILE_ATTRIBUTE_REPARSE_POINT 0x00000400 // winnt
  4469. #define FILE_ATTRIBUTE_COMPRESSED 0x00000800 // winnt
  4470. #define FILE_ATTRIBUTE_OFFLINE 0x00001000 // winnt
  4471. #define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED 0x00002000 // winnt
  4472. #define FILE_ATTRIBUTE_ENCRYPTED 0x00004000 // winnt
  4473. #define FILE_ATTRIBUTE_VALID_FLAGS 0x00007fb7
  4474. #define FILE_ATTRIBUTE_VALID_SET_FLAGS 0x000031a7
  4475. //
  4476. // Define the create disposition values
  4477. //
  4478. #define FILE_SUPERSEDE 0x00000000
  4479. #define FILE_OPEN 0x00000001
  4480. #define FILE_CREATE 0x00000002
  4481. #define FILE_OPEN_IF 0x00000003
  4482. #define FILE_OVERWRITE 0x00000004
  4483. #define FILE_OVERWRITE_IF 0x00000005
  4484. #define FILE_MAXIMUM_DISPOSITION 0x00000005
  4485. //
  4486. // Define the create/open option flags
  4487. //
  4488. #define FILE_DIRECTORY_FILE 0x00000001
  4489. #define FILE_WRITE_THROUGH 0x00000002
  4490. #define FILE_SEQUENTIAL_ONLY 0x00000004
  4491. #define FILE_NO_INTERMEDIATE_BUFFERING 0x00000008
  4492. #define FILE_SYNCHRONOUS_IO_ALERT 0x00000010
  4493. #define FILE_SYNCHRONOUS_IO_NONALERT 0x00000020
  4494. #define FILE_NON_DIRECTORY_FILE 0x00000040
  4495. #define FILE_CREATE_TREE_CONNECTION 0x00000080
  4496. #define FILE_COMPLETE_IF_OPLOCKED 0x00000100
  4497. #define FILE_NO_EA_KNOWLEDGE 0x00000200
  4498. #define FILE_OPEN_FOR_RECOVERY 0x00000400
  4499. #define FILE_RANDOM_ACCESS 0x00000800
  4500. #define FILE_DELETE_ON_CLOSE 0x00001000
  4501. #define FILE_OPEN_BY_FILE_ID 0x00002000
  4502. #define FILE_OPEN_FOR_BACKUP_INTENT 0x00004000
  4503. #define FILE_NO_COMPRESSION 0x00008000
  4504. #define FILE_RESERVE_OPFILTER 0x00100000
  4505. #define FILE_OPEN_REPARSE_POINT 0x00200000
  4506. #define FILE_OPEN_NO_RECALL 0x00400000
  4507. #define FILE_OPEN_FOR_FREE_SPACE_QUERY 0x00800000
  4508. #define FILE_COPY_STRUCTURED_STORAGE 0x00000041
  4509. #define FILE_STRUCTURED_STORAGE 0x00000441
  4510. #define FILE_VALID_OPTION_FLAGS 0x00ffffff
  4511. #define FILE_VALID_PIPE_OPTION_FLAGS 0x00000032
  4512. #define FILE_VALID_MAILSLOT_OPTION_FLAGS 0x00000032
  4513. #define FILE_VALID_SET_FLAGS 0x00000036
  4514. //
  4515. // Define the I/O status information return values for NtCreateFile/NtOpenFile
  4516. //
  4517. #define FILE_SUPERSEDED 0x00000000
  4518. #define FILE_OPENED 0x00000001
  4519. #define FILE_CREATED 0x00000002
  4520. #define FILE_OVERWRITTEN 0x00000003
  4521. #define FILE_EXISTS 0x00000004
  4522. #define FILE_DOES_NOT_EXIST 0x00000005
  4523. //
  4524. // Define special ByteOffset parameters for read and write operations
  4525. //
  4526. #define FILE_WRITE_TO_END_OF_FILE 0xffffffff
  4527. #define FILE_USE_FILE_POINTER_POSITION 0xfffffffe
  4528. //
  4529. // Define alignment requirement values
  4530. //
  4531. #define FILE_BYTE_ALIGNMENT 0x00000000
  4532. #define FILE_WORD_ALIGNMENT 0x00000001
  4533. #define FILE_LONG_ALIGNMENT 0x00000003
  4534. #define FILE_QUAD_ALIGNMENT 0x00000007
  4535. #define FILE_OCTA_ALIGNMENT 0x0000000f
  4536. #define FILE_32_BYTE_ALIGNMENT 0x0000001f
  4537. #define FILE_64_BYTE_ALIGNMENT 0x0000003f
  4538. #define FILE_128_BYTE_ALIGNMENT 0x0000007f
  4539. #define FILE_256_BYTE_ALIGNMENT 0x000000ff
  4540. #define FILE_512_BYTE_ALIGNMENT 0x000001ff
  4541. //
  4542. // Define the maximum length of a filename string
  4543. //
  4544. #define MAXIMUM_FILENAME_LENGTH 256
  4545. //
  4546. // Define the various device characteristics flags
  4547. //
  4548. #define FILE_REMOVABLE_MEDIA 0x00000001
  4549. #define FILE_READ_ONLY_DEVICE 0x00000002
  4550. #define FILE_FLOPPY_DISKETTE 0x00000004
  4551. #define FILE_WRITE_ONCE_MEDIA 0x00000008
  4552. #define FILE_REMOTE_DEVICE 0x00000010
  4553. #define FILE_DEVICE_IS_MOUNTED 0x00000020
  4554. #define FILE_VIRTUAL_VOLUME 0x00000040
  4555. #define FILE_AUTOGENERATED_DEVICE_NAME 0x00000080
  4556. #define FILE_DEVICE_SECURE_OPEN 0x00000100
  4557. #define FILE_CHARACTERISTIC_PNP_DEVICE 0x00000800
  4558. // end_wdm
  4559. //
  4560. // The FILE_EXPECT flags will only exist for WinXP. After that they will be
  4561. // ignored and an IRP will be sent in their place.
  4562. //
  4563. #define FILE_CHARACTERISTICS_EXPECT_ORDERLY_REMOVAL 0x00000200
  4564. #define FILE_CHARACTERISTICS_EXPECT_SURPRISE_REMOVAL 0x00000300
  4565. #define FILE_CHARACTERISTICS_REMOVAL_POLICY_MASK 0x00000300
  4566. //
  4567. // flags specified here will be propagated up and down a device stack
  4568. // after FDO and all filter devices are added, but before the device
  4569. // stack is started
  4570. //
  4571. #define FILE_CHARACTERISTICS_PROPAGATED ( FILE_REMOVABLE_MEDIA | \
  4572. FILE_READ_ONLY_DEVICE | \
  4573. FILE_FLOPPY_DISKETTE | \
  4574. FILE_WRITE_ONCE_MEDIA | \
  4575. FILE_DEVICE_SECURE_OPEN )
  4576. //
  4577. // Define the base asynchronous I/O argument types
  4578. //
  4579. typedef struct _IO_STATUS_BLOCK {
  4580. union {
  4581. NTSTATUS Status;
  4582. PVOID Pointer;
  4583. };
  4584. ULONG_PTR Information;
  4585. } IO_STATUS_BLOCK, *PIO_STATUS_BLOCK;
  4586. #if defined(_WIN64)
  4587. typedef struct _IO_STATUS_BLOCK32 {
  4588. NTSTATUS Status;
  4589. ULONG Information;
  4590. } IO_STATUS_BLOCK32, *PIO_STATUS_BLOCK32;
  4591. #endif
  4592. //
  4593. // Define an Asynchronous Procedure Call from I/O viewpoint
  4594. //
  4595. typedef
  4596. VOID
  4597. (NTAPI *PIO_APC_ROUTINE) (
  4598. IN PVOID ApcContext,
  4599. IN PIO_STATUS_BLOCK IoStatusBlock,
  4600. IN ULONG Reserved
  4601. );
  4602. #define PIO_APC_ROUTINE_DEFINED
  4603. //
  4604. // Define the file information class values
  4605. //
  4606. // WARNING: The order of the following values are assumed by the I/O system.
  4607. // Any changes made here should be reflected there as well.
  4608. //
  4609. typedef enum _FILE_INFORMATION_CLASS {
  4610. // end_wdm
  4611. FileDirectoryInformation = 1,
  4612. FileFullDirectoryInformation, // 2
  4613. FileBothDirectoryInformation, // 3
  4614. FileBasicInformation, // 4 wdm
  4615. FileStandardInformation, // 5 wdm
  4616. FileInternalInformation, // 6
  4617. FileEaInformation, // 7
  4618. FileAccessInformation, // 8
  4619. FileNameInformation, // 9
  4620. FileRenameInformation, // 10
  4621. FileLinkInformation, // 11
  4622. FileNamesInformation, // 12
  4623. FileDispositionInformation, // 13
  4624. FilePositionInformation, // 14 wdm
  4625. FileFullEaInformation, // 15
  4626. FileModeInformation, // 16
  4627. FileAlignmentInformation, // 17
  4628. FileAllInformation, // 18
  4629. FileAllocationInformation, // 19
  4630. FileEndOfFileInformation, // 20 wdm
  4631. FileAlternateNameInformation, // 21
  4632. FileStreamInformation, // 22
  4633. FilePipeInformation, // 23
  4634. FilePipeLocalInformation, // 24
  4635. FilePipeRemoteInformation, // 25
  4636. FileMailslotQueryInformation, // 26
  4637. FileMailslotSetInformation, // 27
  4638. FileCompressionInformation, // 28
  4639. FileObjectIdInformation, // 29
  4640. FileCompletionInformation, // 30
  4641. FileMoveClusterInformation, // 31
  4642. FileQuotaInformation, // 32
  4643. FileReparsePointInformation, // 33
  4644. FileNetworkOpenInformation, // 34
  4645. FileAttributeTagInformation, // 35
  4646. FileTrackingInformation, // 36
  4647. FileIdBothDirectoryInformation, // 37
  4648. FileIdFullDirectoryInformation, // 38
  4649. FileValidDataLengthInformation, // 39
  4650. FileShortNameInformation, // 40
  4651. FileMaximumInformation
  4652. // begin_wdm
  4653. } FILE_INFORMATION_CLASS, *PFILE_INFORMATION_CLASS;
  4654. //
  4655. // Define the various structures which are returned on query operations
  4656. //
  4657. typedef struct _FILE_BASIC_INFORMATION {
  4658. LARGE_INTEGER CreationTime;
  4659. LARGE_INTEGER LastAccessTime;
  4660. LARGE_INTEGER LastWriteTime;
  4661. LARGE_INTEGER ChangeTime;
  4662. ULONG FileAttributes;
  4663. } FILE_BASIC_INFORMATION, *PFILE_BASIC_INFORMATION;
  4664. typedef struct _FILE_STANDARD_INFORMATION {
  4665. LARGE_INTEGER AllocationSize;
  4666. LARGE_INTEGER EndOfFile;
  4667. ULONG NumberOfLinks;
  4668. BOOLEAN DeletePending;
  4669. BOOLEAN Directory;
  4670. } FILE_STANDARD_INFORMATION, *PFILE_STANDARD_INFORMATION;
  4671. typedef struct _FILE_POSITION_INFORMATION {
  4672. LARGE_INTEGER CurrentByteOffset;
  4673. } FILE_POSITION_INFORMATION, *PFILE_POSITION_INFORMATION;
  4674. typedef struct _FILE_ALIGNMENT_INFORMATION {
  4675. ULONG AlignmentRequirement;
  4676. } FILE_ALIGNMENT_INFORMATION, *PFILE_ALIGNMENT_INFORMATION;
  4677. typedef struct _FILE_NETWORK_OPEN_INFORMATION {
  4678. LARGE_INTEGER CreationTime;
  4679. LARGE_INTEGER LastAccessTime;
  4680. LARGE_INTEGER LastWriteTime;
  4681. LARGE_INTEGER ChangeTime;
  4682. LARGE_INTEGER AllocationSize;
  4683. LARGE_INTEGER EndOfFile;
  4684. ULONG FileAttributes;
  4685. } FILE_NETWORK_OPEN_INFORMATION, *PFILE_NETWORK_OPEN_INFORMATION;
  4686. typedef struct _FILE_ATTRIBUTE_TAG_INFORMATION {
  4687. ULONG FileAttributes;
  4688. ULONG ReparseTag;
  4689. } FILE_ATTRIBUTE_TAG_INFORMATION, *PFILE_ATTRIBUTE_TAG_INFORMATION;
  4690. typedef struct _FILE_DISPOSITION_INFORMATION {
  4691. BOOLEAN DeleteFile;
  4692. } FILE_DISPOSITION_INFORMATION, *PFILE_DISPOSITION_INFORMATION;
  4693. typedef struct _FILE_END_OF_FILE_INFORMATION {
  4694. LARGE_INTEGER EndOfFile;
  4695. } FILE_END_OF_FILE_INFORMATION, *PFILE_END_OF_FILE_INFORMATION;
  4696. typedef struct _FILE_VALID_DATA_LENGTH_INFORMATION {
  4697. LARGE_INTEGER ValidDataLength;
  4698. } FILE_VALID_DATA_LENGTH_INFORMATION, *PFILE_VALID_DATA_LENGTH_INFORMATION;
  4699. //
  4700. // Define the file system information class values
  4701. //
  4702. // WARNING: The order of the following values are assumed by the I/O system.
  4703. // Any changes made here should be reflected there as well.
  4704. typedef enum _FSINFOCLASS {
  4705. FileFsVolumeInformation = 1,
  4706. FileFsLabelInformation, // 2
  4707. FileFsSizeInformation, // 3
  4708. FileFsDeviceInformation, // 4
  4709. FileFsAttributeInformation, // 5
  4710. FileFsControlInformation, // 6
  4711. FileFsFullSizeInformation, // 7
  4712. FileFsObjectIdInformation, // 8
  4713. FileFsDriverPathInformation, // 9
  4714. FileFsMaximumInformation
  4715. } FS_INFORMATION_CLASS, *PFS_INFORMATION_CLASS;
  4716. typedef struct _FILE_FS_DEVICE_INFORMATION {
  4717. DEVICE_TYPE DeviceType;
  4718. ULONG Characteristics;
  4719. } FILE_FS_DEVICE_INFORMATION, *PFILE_FS_DEVICE_INFORMATION;
  4720. //
  4721. // Define segement buffer structure for scatter/gather read/write.
  4722. //
  4723. typedef union _FILE_SEGMENT_ELEMENT {
  4724. PVOID64 Buffer;
  4725. ULONGLONG Alignment;
  4726. }FILE_SEGMENT_ELEMENT, *PFILE_SEGMENT_ELEMENT;
  4727. //
  4728. // Define the I/O bus interface types.
  4729. //
  4730. typedef enum _INTERFACE_TYPE {
  4731. InterfaceTypeUndefined = -1,
  4732. Internal,
  4733. Isa,
  4734. Eisa,
  4735. MicroChannel,
  4736. TurboChannel,
  4737. PCIBus,
  4738. VMEBus,
  4739. NuBus,
  4740. PCMCIABus,
  4741. CBus,
  4742. MPIBus,
  4743. MPSABus,
  4744. ProcessorInternal,
  4745. InternalPowerBus,
  4746. PNPISABus,
  4747. PNPBus,
  4748. MaximumInterfaceType
  4749. }INTERFACE_TYPE, *PINTERFACE_TYPE;
  4750. //
  4751. // Define the DMA transfer widths.
  4752. //
  4753. typedef enum _DMA_WIDTH {
  4754. Width8Bits,
  4755. Width16Bits,
  4756. Width32Bits,
  4757. MaximumDmaWidth
  4758. }DMA_WIDTH, *PDMA_WIDTH;
  4759. //
  4760. // Define DMA transfer speeds.
  4761. //
  4762. typedef enum _DMA_SPEED {
  4763. Compatible,
  4764. TypeA,
  4765. TypeB,
  4766. TypeC,
  4767. TypeF,
  4768. MaximumDmaSpeed
  4769. }DMA_SPEED, *PDMA_SPEED;
  4770. //
  4771. // Define Interface reference/dereference routines for
  4772. // Interfaces exported by IRP_MN_QUERY_INTERFACE
  4773. //
  4774. typedef VOID (*PINTERFACE_REFERENCE)(PVOID Context);
  4775. typedef VOID (*PINTERFACE_DEREFERENCE)(PVOID Context);
  4776. // end_wdm
  4777. //
  4778. // Define types of bus information.
  4779. //
  4780. typedef enum _BUS_DATA_TYPE {
  4781. ConfigurationSpaceUndefined = -1,
  4782. Cmos,
  4783. EisaConfiguration,
  4784. Pos,
  4785. CbusConfiguration,
  4786. PCIConfiguration,
  4787. VMEConfiguration,
  4788. NuBusConfiguration,
  4789. PCMCIAConfiguration,
  4790. MPIConfiguration,
  4791. MPSAConfiguration,
  4792. PNPISAConfiguration,
  4793. SgiInternalConfiguration,
  4794. MaximumBusDataType
  4795. } BUS_DATA_TYPE, *PBUS_DATA_TYPE;
  4796. //
  4797. // Define I/O Driver error log packet structure. This structure is filled in
  4798. // by the driver.
  4799. //
  4800. typedef struct _IO_ERROR_LOG_PACKET {
  4801. UCHAR MajorFunctionCode;
  4802. UCHAR RetryCount;
  4803. USHORT DumpDataSize;
  4804. USHORT NumberOfStrings;
  4805. USHORT StringOffset;
  4806. USHORT EventCategory;
  4807. NTSTATUS ErrorCode;
  4808. ULONG UniqueErrorValue;
  4809. NTSTATUS FinalStatus;
  4810. ULONG SequenceNumber;
  4811. ULONG IoControlCode;
  4812. LARGE_INTEGER DeviceOffset;
  4813. ULONG DumpData[1];
  4814. }IO_ERROR_LOG_PACKET, *PIO_ERROR_LOG_PACKET;
  4815. //
  4816. // Define the I/O error log message. This message is sent by the error log
  4817. // thread over the lpc port.
  4818. //
  4819. typedef struct _IO_ERROR_LOG_MESSAGE {
  4820. USHORT Type;
  4821. USHORT Size;
  4822. USHORT DriverNameLength;
  4823. LARGE_INTEGER TimeStamp;
  4824. ULONG DriverNameOffset;
  4825. IO_ERROR_LOG_PACKET EntryData;
  4826. }IO_ERROR_LOG_MESSAGE, *PIO_ERROR_LOG_MESSAGE;
  4827. //
  4828. // Define the maximum message size that will be sent over the LPC to the
  4829. // application reading the error log entries.
  4830. //
  4831. //
  4832. // Regardless of LPC size restrictions, ERROR_LOG_MAXIMUM_SIZE must remain
  4833. // a value that can fit in a UCHAR.
  4834. //
  4835. #define ERROR_LOG_LIMIT_SIZE (256-16)
  4836. //
  4837. // This limit, exclusive of IO_ERROR_LOG_MESSAGE_HEADER_LENGTH, also applies
  4838. // to IO_ERROR_LOG_MESSAGE_LENGTH
  4839. //
  4840. #define IO_ERROR_LOG_MESSAGE_HEADER_LENGTH (sizeof(IO_ERROR_LOG_MESSAGE) - \
  4841. sizeof(IO_ERROR_LOG_PACKET) + \
  4842. (sizeof(WCHAR) * 40))
  4843. #define ERROR_LOG_MESSAGE_LIMIT_SIZE \
  4844. (ERROR_LOG_LIMIT_SIZE + IO_ERROR_LOG_MESSAGE_HEADER_LENGTH)
  4845. //
  4846. // IO_ERROR_LOG_MESSAGE_LENGTH is
  4847. // min(PORT_MAXIMUM_MESSAGE_LENGTH, ERROR_LOG_MESSAGE_LIMIT_SIZE)
  4848. //
  4849. #define IO_ERROR_LOG_MESSAGE_LENGTH \
  4850. ((PORT_MAXIMUM_MESSAGE_LENGTH > ERROR_LOG_MESSAGE_LIMIT_SIZE) ? \
  4851. ERROR_LOG_MESSAGE_LIMIT_SIZE : \
  4852. PORT_MAXIMUM_MESSAGE_LENGTH)
  4853. //
  4854. // Define the maximum packet size a driver can allocate.
  4855. //
  4856. #define ERROR_LOG_MAXIMUM_SIZE (IO_ERROR_LOG_MESSAGE_LENGTH - \
  4857. IO_ERROR_LOG_MESSAGE_HEADER_LENGTH)
  4858. #define VARIABLE_ATTRIBUTE_NON_VOLATILE 0x00000001
  4859. #define VARIABLE_INFORMATION_NAMES 1
  4860. #define VARIABLE_INFORMATION_VALUES 2
  4861. typedef struct _VARIABLE_NAME {
  4862. ULONG NextEntryOffset;
  4863. GUID VendorGuid;
  4864. WCHAR Name[ANYSIZE_ARRAY];
  4865. } VARIABLE_NAME, *PVARIABLE_NAME;
  4866. typedef struct _VARIABLE_NAME_AND_VALUE {
  4867. ULONG NextEntryOffset;
  4868. ULONG ValueOffset;
  4869. ULONG ValueLength;
  4870. ULONG Attributes;
  4871. GUID VendorGuid;
  4872. WCHAR Name[ANYSIZE_ARRAY];
  4873. //UCHAR Value[ANYSIZE_ARRAY];
  4874. } VARIABLE_NAME_AND_VALUE, *PVARIABLE_NAME_AND_VALUE;
  4875. //
  4876. // Defined processor features
  4877. //
  4878. #define PF_FLOATING_POINT_PRECISION_ERRATA 0 // winnt
  4879. #define PF_FLOATING_POINT_EMULATED 1 // winnt
  4880. #define PF_COMPARE_EXCHANGE_DOUBLE 2 // winnt
  4881. #define PF_MMX_INSTRUCTIONS_AVAILABLE 3 // winnt
  4882. #define PF_PPC_MOVEMEM_64BIT_OK 4 // winnt
  4883. #define PF_ALPHA_BYTE_INSTRUCTIONS 5 // winnt
  4884. #define PF_XMMI_INSTRUCTIONS_AVAILABLE 6 // winnt
  4885. #define PF_3DNOW_INSTRUCTIONS_AVAILABLE 7 // winnt
  4886. #define PF_RDTSC_INSTRUCTION_AVAILABLE 8 // winnt
  4887. #define PF_PAE_ENABLED 9 // winnt
  4888. #define PF_XMMI64_INSTRUCTIONS_AVAILABLE 10 // winnt
  4889. typedef enum _ALTERNATIVE_ARCHITECTURE_TYPE {
  4890. StandardDesign, // None == 0 == standard design
  4891. NEC98x86, // NEC PC98xx series on X86
  4892. EndAlternatives // past end of known alternatives
  4893. } ALTERNATIVE_ARCHITECTURE_TYPE;
  4894. // correctly define these run-time definitions for non X86 machines
  4895. #ifndef _X86_
  4896. #ifndef IsNEC_98
  4897. #define IsNEC_98 (FALSE)
  4898. #endif
  4899. #ifndef IsNotNEC_98
  4900. #define IsNotNEC_98 (TRUE)
  4901. #endif
  4902. #ifndef SetNEC_98
  4903. #define SetNEC_98
  4904. #endif
  4905. #ifndef SetNotNEC_98
  4906. #define SetNotNEC_98
  4907. #endif
  4908. #endif
  4909. #define PROCESSOR_FEATURE_MAX 64
  4910. // end_wdm
  4911. #if defined(REMOTE_BOOT)
  4912. //
  4913. // Defined system flags.
  4914. //
  4915. /* the following two lines should be tagged with "winnt" when REMOTE_BOOT is on. */
  4916. #define SYSTEM_FLAG_REMOTE_BOOT_CLIENT 0x00000001
  4917. #define SYSTEM_FLAG_DISKLESS_CLIENT 0x00000002
  4918. #endif // defined(REMOTE_BOOT)
  4919. //
  4920. // Define data shared between kernel and user mode.
  4921. //
  4922. // N.B. User mode has read only access to this data
  4923. //
  4924. #ifdef _MAC
  4925. #pragma warning( disable : 4121)
  4926. #endif
  4927. //
  4928. // WARNING: This structure must have exactly the same layout for 32- and
  4929. // 64-bit systems. The layout of this structure cannot change and new
  4930. // fields can only be added to the end of the structure. Deprecated
  4931. // fields cannot be deleted. Platform specific fields are included on
  4932. // all systems.
  4933. //
  4934. // Layout exactness is required for Wow64 support of 32bit applications
  4935. // on Win64 systems.
  4936. //
  4937. // The layout itself cannot change since this sturcture has been exported
  4938. // in ntddk, ntifs.h, and nthal.h for some time.
  4939. //
  4940. typedef struct _KUSER_SHARED_DATA {
  4941. //
  4942. // Current low 32-bit of tick count and tick count multiplier.
  4943. //
  4944. // N.B. The tick count is updated each time the clock ticks.
  4945. //
  4946. ULONG TickCountLowDeprecated;
  4947. ULONG TickCountMultiplier;
  4948. //
  4949. // Current 64-bit interrupt time in 100ns units.
  4950. //
  4951. volatile KSYSTEM_TIME InterruptTime;
  4952. //
  4953. // Current 64-bit system time in 100ns units.
  4954. //
  4955. volatile KSYSTEM_TIME SystemTime;
  4956. //
  4957. // Current 64-bit time zone bias.
  4958. //
  4959. volatile KSYSTEM_TIME TimeZoneBias;
  4960. //
  4961. // Support image magic number range for the host system.
  4962. //
  4963. // N.B. This is an inclusive range.
  4964. //
  4965. USHORT ImageNumberLow;
  4966. USHORT ImageNumberHigh;
  4967. //
  4968. // Copy of system root in Unicode
  4969. //
  4970. WCHAR NtSystemRoot[ 260 ];
  4971. //
  4972. // Maximum stack trace depth if tracing enabled.
  4973. //
  4974. ULONG MaxStackTraceDepth;
  4975. //
  4976. // Crypto Exponent
  4977. //
  4978. ULONG CryptoExponent;
  4979. //
  4980. // TimeZoneId
  4981. //
  4982. ULONG TimeZoneId;
  4983. ULONG LargePageMinimum;
  4984. ULONG Reserved2[ 7 ];
  4985. //
  4986. // product type
  4987. //
  4988. NT_PRODUCT_TYPE NtProductType;
  4989. BOOLEAN ProductTypeIsValid;
  4990. //
  4991. // NT Version. Note that each process sees a version from its PEB, but
  4992. // if the process is running with an altered view of the system version,
  4993. // the following two fields are used to correctly identify the version
  4994. //
  4995. ULONG NtMajorVersion;
  4996. ULONG NtMinorVersion;
  4997. //
  4998. // Processor Feature Bits
  4999. //
  5000. BOOLEAN ProcessorFeatures[PROCESSOR_FEATURE_MAX];
  5001. //
  5002. // Reserved fields - do not use
  5003. //
  5004. ULONG Reserved1;
  5005. ULONG Reserved3;
  5006. //
  5007. // Time slippage while in debugger
  5008. //
  5009. volatile ULONG TimeSlip;
  5010. //
  5011. // Alternative system architecture. Example: NEC PC98xx on x86
  5012. //
  5013. ALTERNATIVE_ARCHITECTURE_TYPE AlternativeArchitecture;
  5014. //
  5015. // If the system is an evaluation unit, the following field contains the
  5016. // date and time that the evaluation unit expires. A value of 0 indicates
  5017. // that there is no expiration. A non-zero value is the UTC absolute time
  5018. // that the system expires.
  5019. //
  5020. LARGE_INTEGER SystemExpirationDate;
  5021. //
  5022. // Suite Support
  5023. //
  5024. ULONG SuiteMask;
  5025. //
  5026. // TRUE if a kernel debugger is connected/enabled
  5027. //
  5028. BOOLEAN KdDebuggerEnabled;
  5029. //
  5030. // Current console session Id. Always zero on non-TS systems
  5031. //
  5032. volatile ULONG ActiveConsoleId;
  5033. //
  5034. // Force-dismounts cause handles to become invalid. Rather than
  5035. // always probe handles, we maintain a serial number of
  5036. // dismounts that clients can use to see if they need to probe
  5037. // handles.
  5038. //
  5039. volatile ULONG DismountCount;
  5040. //
  5041. // This field indicates the status of the 64-bit COM+ package on the system.
  5042. // It indicates whether the Itermediate Language (IL) COM+ images need to
  5043. // use the 64-bit COM+ runtime or the 32-bit COM+ runtime.
  5044. //
  5045. ULONG ComPlusPackage;
  5046. //
  5047. // Time in tick count for system-wide last user input across all
  5048. // terminal sessions. For MP performance, it is not updated all
  5049. // the time (e.g. once a minute per session). It is used for idle
  5050. // detection.
  5051. //
  5052. ULONG LastSystemRITEventTickCount;
  5053. //
  5054. // Number of physical pages in the system. This can dynamically
  5055. // change as physical memory can be added or removed from a running
  5056. // system.
  5057. //
  5058. ULONG NumberOfPhysicalPages;
  5059. //
  5060. // True if the system was booted in safe boot mode.
  5061. //
  5062. BOOLEAN SafeBootMode;
  5063. //
  5064. // The following field is used for Heap and CritSec Tracing
  5065. // The last bit is set for Critical Sec Collision tracing and
  5066. // second Last bit is for Heap Tracing
  5067. // Also the first 16 bits are used as counter.
  5068. //
  5069. ULONG TraceLogging;
  5070. //
  5071. // Depending on the processor, the code for fast system call
  5072. // will differ, the following buffer is filled with the appropriate
  5073. // code sequence and user mode code will branch through it.
  5074. //
  5075. // (32 bytes, using ULONGLONG for alignment).
  5076. //
  5077. // N.B. The following two fields are only used on 32-bit systems.
  5078. //
  5079. ULONGLONG Fill0; // alignment
  5080. ULONGLONG SystemCall[4];
  5081. //
  5082. // The 64-bit tick count.
  5083. //
  5084. union {
  5085. volatile KSYSTEM_TIME TickCount;
  5086. volatile ULONG64 TickCountQuad;
  5087. };
  5088. } KUSER_SHARED_DATA, *PKUSER_SHARED_DATA;
  5089. #ifdef _MAC
  5090. #pragma warning( default : 4121 )
  5091. #endif
  5092. //
  5093. // Object Manager Object Type Specific Access Rights.
  5094. //
  5095. #define OBJECT_TYPE_CREATE (0x0001)
  5096. #define OBJECT_TYPE_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | 0x1)
  5097. //
  5098. // Object Manager Directory Specific Access Rights.
  5099. //
  5100. #define DIRECTORY_QUERY (0x0001)
  5101. #define DIRECTORY_TRAVERSE (0x0002)
  5102. #define DIRECTORY_CREATE_OBJECT (0x0004)
  5103. #define DIRECTORY_CREATE_SUBDIRECTORY (0x0008)
  5104. #define DIRECTORY_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | 0xF)
  5105. //
  5106. // Object Manager Symbolic Link Specific Access Rights.
  5107. //
  5108. #define SYMBOLIC_LINK_QUERY (0x0001)
  5109. #define SYMBOLIC_LINK_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | 0x1)
  5110. typedef struct _OBJECT_NAME_INFORMATION {
  5111. UNICODE_STRING Name;
  5112. } OBJECT_NAME_INFORMATION, *POBJECT_NAME_INFORMATION;
  5113. // begin_winnt
  5114. //
  5115. // Predefined Value Types.
  5116. //
  5117. #define REG_NONE ( 0 ) // No value type
  5118. #define REG_SZ ( 1 ) // Unicode nul terminated string
  5119. #define REG_EXPAND_SZ ( 2 ) // Unicode nul terminated string
  5120. // (with environment variable references)
  5121. #define REG_BINARY ( 3 ) // Free form binary
  5122. #define REG_DWORD ( 4 ) // 32-bit number
  5123. #define REG_DWORD_LITTLE_ENDIAN ( 4 ) // 32-bit number (same as REG_DWORD)
  5124. #define REG_DWORD_BIG_ENDIAN ( 5 ) // 32-bit number
  5125. #define REG_LINK ( 6 ) // Symbolic Link (unicode)
  5126. #define REG_MULTI_SZ ( 7 ) // Multiple Unicode strings
  5127. #define REG_RESOURCE_LIST ( 8 ) // Resource list in the resource map
  5128. #define REG_FULL_RESOURCE_DESCRIPTOR ( 9 ) // Resource list in the hardware description
  5129. #define REG_RESOURCE_REQUIREMENTS_LIST ( 10 )
  5130. #define REG_QWORD ( 11 ) // 64-bit number
  5131. #define REG_QWORD_LITTLE_ENDIAN ( 11 ) // 64-bit number (same as REG_QWORD)
  5132. //
  5133. // Service Types (Bit Mask)
  5134. //
  5135. #define SERVICE_KERNEL_DRIVER 0x00000001
  5136. #define SERVICE_FILE_SYSTEM_DRIVER 0x00000002
  5137. #define SERVICE_ADAPTER 0x00000004
  5138. #define SERVICE_RECOGNIZER_DRIVER 0x00000008
  5139. #define SERVICE_DRIVER (SERVICE_KERNEL_DRIVER | \
  5140. SERVICE_FILE_SYSTEM_DRIVER | \
  5141. SERVICE_RECOGNIZER_DRIVER)
  5142. #define SERVICE_WIN32_OWN_PROCESS 0x00000010
  5143. #define SERVICE_WIN32_SHARE_PROCESS 0x00000020
  5144. #define SERVICE_WIN32 (SERVICE_WIN32_OWN_PROCESS | \
  5145. SERVICE_WIN32_SHARE_PROCESS)
  5146. #define SERVICE_INTERACTIVE_PROCESS 0x00000100
  5147. #define SERVICE_TYPE_ALL (SERVICE_WIN32 | \
  5148. SERVICE_ADAPTER | \
  5149. SERVICE_DRIVER | \
  5150. SERVICE_INTERACTIVE_PROCESS)
  5151. //
  5152. // Start Type
  5153. //
  5154. #define SERVICE_BOOT_START 0x00000000
  5155. #define SERVICE_SYSTEM_START 0x00000001
  5156. #define SERVICE_AUTO_START 0x00000002
  5157. #define SERVICE_DEMAND_START 0x00000003
  5158. #define SERVICE_DISABLED 0x00000004
  5159. //
  5160. // Error control type
  5161. //
  5162. #define SERVICE_ERROR_IGNORE 0x00000000
  5163. #define SERVICE_ERROR_NORMAL 0x00000001
  5164. #define SERVICE_ERROR_SEVERE 0x00000002
  5165. #define SERVICE_ERROR_CRITICAL 0x00000003
  5166. //
  5167. //
  5168. // Define the registry driver node enumerations
  5169. //
  5170. typedef enum _CM_SERVICE_NODE_TYPE {
  5171. DriverType = SERVICE_KERNEL_DRIVER,
  5172. FileSystemType = SERVICE_FILE_SYSTEM_DRIVER,
  5173. Win32ServiceOwnProcess = SERVICE_WIN32_OWN_PROCESS,
  5174. Win32ServiceShareProcess = SERVICE_WIN32_SHARE_PROCESS,
  5175. AdapterType = SERVICE_ADAPTER,
  5176. RecognizerType = SERVICE_RECOGNIZER_DRIVER
  5177. } SERVICE_NODE_TYPE;
  5178. typedef enum _CM_SERVICE_LOAD_TYPE {
  5179. BootLoad = SERVICE_BOOT_START,
  5180. SystemLoad = SERVICE_SYSTEM_START,
  5181. AutoLoad = SERVICE_AUTO_START,
  5182. DemandLoad = SERVICE_DEMAND_START,
  5183. DisableLoad = SERVICE_DISABLED
  5184. } SERVICE_LOAD_TYPE;
  5185. typedef enum _CM_ERROR_CONTROL_TYPE {
  5186. IgnoreError = SERVICE_ERROR_IGNORE,
  5187. NormalError = SERVICE_ERROR_NORMAL,
  5188. SevereError = SERVICE_ERROR_SEVERE,
  5189. CriticalError = SERVICE_ERROR_CRITICAL
  5190. } SERVICE_ERROR_TYPE;
  5191. // end_winnt
  5192. //
  5193. // Resource List definitions
  5194. //
  5195. // begin_ntminiport begin_ntndis
  5196. //
  5197. // Defines the Type in the RESOURCE_DESCRIPTOR
  5198. //
  5199. // NOTE: For all CM_RESOURCE_TYPE values, there must be a
  5200. // corresponding ResType value in the 32-bit ConfigMgr headerfile
  5201. // (cfgmgr32.h). Values in the range [0x6,0x80) use the same values
  5202. // as their ConfigMgr counterparts. CM_RESOURCE_TYPE values with
  5203. // the high bit set (i.e., in the range [0x80,0xFF]), are
  5204. // non-arbitrated resources. These correspond to the same values
  5205. // in cfgmgr32.h that have their high bit set (however, since
  5206. // cfgmgr32.h uses 16 bits for ResType values, these values are in
  5207. // the range [0x8000,0x807F). Note that ConfigMgr ResType values
  5208. // cannot be in the range [0x8080,0xFFFF), because they would not
  5209. // be able to map into CM_RESOURCE_TYPE values. (0xFFFF itself is
  5210. // a special value, because it maps to CmResourceTypeDeviceSpecific.)
  5211. //
  5212. typedef int CM_RESOURCE_TYPE;
  5213. // CmResourceTypeNull is reserved
  5214. #define CmResourceTypeNull 0 // ResType_All or ResType_None (0x0000)
  5215. #define CmResourceTypePort 1 // ResType_IO (0x0002)
  5216. #define CmResourceTypeInterrupt 2 // ResType_IRQ (0x0004)
  5217. #define CmResourceTypeMemory 3 // ResType_Mem (0x0001)
  5218. #define CmResourceTypeDma 4 // ResType_DMA (0x0003)
  5219. #define CmResourceTypeDeviceSpecific 5 // ResType_ClassSpecific (0xFFFF)
  5220. #define CmResourceTypeBusNumber 6 // ResType_BusNumber (0x0006)
  5221. // end_wdm
  5222. #define CmResourceTypeMaximum 7
  5223. // begin_wdm
  5224. #define CmResourceTypeNonArbitrated 128 // Not arbitrated if 0x80 bit set
  5225. #define CmResourceTypeConfigData 128 // ResType_Reserved (0x8000)
  5226. #define CmResourceTypeDevicePrivate 129 // ResType_DevicePrivate (0x8001)
  5227. #define CmResourceTypePcCardConfig 130 // ResType_PcCardConfig (0x8002)
  5228. #define CmResourceTypeMfCardConfig 131 // ResType_MfCardConfig (0x8003)
  5229. //
  5230. // Defines the ShareDisposition in the RESOURCE_DESCRIPTOR
  5231. //
  5232. typedef enum _CM_SHARE_DISPOSITION {
  5233. CmResourceShareUndetermined = 0, // Reserved
  5234. CmResourceShareDeviceExclusive,
  5235. CmResourceShareDriverExclusive,
  5236. CmResourceShareShared
  5237. } CM_SHARE_DISPOSITION;
  5238. //
  5239. // Define the bit masks for Flags when type is CmResourceTypeInterrupt
  5240. //
  5241. #define CM_RESOURCE_INTERRUPT_LEVEL_SENSITIVE 0
  5242. #define CM_RESOURCE_INTERRUPT_LATCHED 1
  5243. //
  5244. // Define the bit masks for Flags when type is CmResourceTypeMemory
  5245. //
  5246. #define CM_RESOURCE_MEMORY_READ_WRITE 0x0000
  5247. #define CM_RESOURCE_MEMORY_READ_ONLY 0x0001
  5248. #define CM_RESOURCE_MEMORY_WRITE_ONLY 0x0002
  5249. #define CM_RESOURCE_MEMORY_PREFETCHABLE 0x0004
  5250. #define CM_RESOURCE_MEMORY_COMBINEDWRITE 0x0008
  5251. #define CM_RESOURCE_MEMORY_24 0x0010
  5252. #define CM_RESOURCE_MEMORY_CACHEABLE 0x0020
  5253. //
  5254. // Define the bit masks for Flags when type is CmResourceTypePort
  5255. //
  5256. #define CM_RESOURCE_PORT_MEMORY 0x0000
  5257. #define CM_RESOURCE_PORT_IO 0x0001
  5258. #define CM_RESOURCE_PORT_10_BIT_DECODE 0x0004
  5259. #define CM_RESOURCE_PORT_12_BIT_DECODE 0x0008
  5260. #define CM_RESOURCE_PORT_16_BIT_DECODE 0x0010
  5261. #define CM_RESOURCE_PORT_POSITIVE_DECODE 0x0020
  5262. #define CM_RESOURCE_PORT_PASSIVE_DECODE 0x0040
  5263. #define CM_RESOURCE_PORT_WINDOW_DECODE 0x0080
  5264. //
  5265. // Define the bit masks for Flags when type is CmResourceTypeDma
  5266. //
  5267. #define CM_RESOURCE_DMA_8 0x0000
  5268. #define CM_RESOURCE_DMA_16 0x0001
  5269. #define CM_RESOURCE_DMA_32 0x0002
  5270. #define CM_RESOURCE_DMA_8_AND_16 0x0004
  5271. #define CM_RESOURCE_DMA_BUS_MASTER 0x0008
  5272. #define CM_RESOURCE_DMA_TYPE_A 0x0010
  5273. #define CM_RESOURCE_DMA_TYPE_B 0x0020
  5274. #define CM_RESOURCE_DMA_TYPE_F 0x0040
  5275. // end_ntminiport end_ntndis
  5276. //
  5277. // This structure defines one type of resource used by a driver.
  5278. //
  5279. // There can only be *1* DeviceSpecificData block. It must be located at
  5280. // the end of all resource descriptors in a full descriptor block.
  5281. //
  5282. //
  5283. // Make sure alignment is made properly by compiler; otherwise move
  5284. // flags back to the top of the structure (common to all members of the
  5285. // union).
  5286. //
  5287. // begin_ntndis
  5288. #include "pshpack4.h"
  5289. typedef struct _CM_PARTIAL_RESOURCE_DESCRIPTOR {
  5290. UCHAR Type;
  5291. UCHAR ShareDisposition;
  5292. USHORT Flags;
  5293. union {
  5294. //
  5295. // Range of resources, inclusive. These are physical, bus relative.
  5296. // It is known that Port and Memory below have the exact same layout
  5297. // as Generic.
  5298. //
  5299. struct {
  5300. PHYSICAL_ADDRESS Start;
  5301. ULONG Length;
  5302. } Generic;
  5303. //
  5304. // end_wdm
  5305. // Range of port numbers, inclusive. These are physical, bus
  5306. // relative. The value should be the same as the one passed to
  5307. // HalTranslateBusAddress().
  5308. // begin_wdm
  5309. //
  5310. struct {
  5311. PHYSICAL_ADDRESS Start;
  5312. ULONG Length;
  5313. } Port;
  5314. //
  5315. // end_wdm
  5316. // IRQL and vector. Should be same values as were passed to
  5317. // HalGetInterruptVector().
  5318. // begin_wdm
  5319. //
  5320. struct {
  5321. ULONG Level;
  5322. ULONG Vector;
  5323. KAFFINITY Affinity;
  5324. } Interrupt;
  5325. //
  5326. // Range of memory addresses, inclusive. These are physical, bus
  5327. // relative. The value should be the same as the one passed to
  5328. // HalTranslateBusAddress().
  5329. //
  5330. struct {
  5331. PHYSICAL_ADDRESS Start; // 64 bit physical addresses.
  5332. ULONG Length;
  5333. } Memory;
  5334. //
  5335. // Physical DMA channel.
  5336. //
  5337. struct {
  5338. ULONG Channel;
  5339. ULONG Port;
  5340. ULONG Reserved1;
  5341. } Dma;
  5342. //
  5343. // Device driver private data, usually used to help it figure
  5344. // what the resource assignments decisions that were made.
  5345. //
  5346. struct {
  5347. ULONG Data[3];
  5348. } DevicePrivate;
  5349. //
  5350. // Bus Number information.
  5351. //
  5352. struct {
  5353. ULONG Start;
  5354. ULONG Length;
  5355. ULONG Reserved;
  5356. } BusNumber;
  5357. //
  5358. // Device Specific information defined by the driver.
  5359. // The DataSize field indicates the size of the data in bytes. The
  5360. // data is located immediately after the DeviceSpecificData field in
  5361. // the structure.
  5362. //
  5363. struct {
  5364. ULONG DataSize;
  5365. ULONG Reserved1;
  5366. ULONG Reserved2;
  5367. } DeviceSpecificData;
  5368. } u;
  5369. } CM_PARTIAL_RESOURCE_DESCRIPTOR, *PCM_PARTIAL_RESOURCE_DESCRIPTOR;
  5370. #include "poppack.h"
  5371. //
  5372. // A Partial Resource List is what can be found in the ARC firmware
  5373. // or will be generated by ntdetect.com.
  5374. // The configuration manager will transform this structure into a Full
  5375. // resource descriptor when it is about to store it in the regsitry.
  5376. //
  5377. // Note: There must a be a convention to the order of fields of same type,
  5378. // (defined on a device by device basis) so that the fields can make sense
  5379. // to a driver (i.e. when multiple memory ranges are necessary).
  5380. //
  5381. typedef struct _CM_PARTIAL_RESOURCE_LIST {
  5382. USHORT Version;
  5383. USHORT Revision;
  5384. ULONG Count;
  5385. CM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptors[1];
  5386. } CM_PARTIAL_RESOURCE_LIST, *PCM_PARTIAL_RESOURCE_LIST;
  5387. //
  5388. // A Full Resource Descriptor is what can be found in the registry.
  5389. // This is what will be returned to a driver when it queries the registry
  5390. // to get device information; it will be stored under a key in the hardware
  5391. // description tree.
  5392. //
  5393. // end_wdm
  5394. // Note: The BusNumber and Type are redundant information, but we will keep
  5395. // it since it allows the driver _not_ to append it when it is creating
  5396. // a resource list which could possibly span multiple buses.
  5397. //
  5398. // begin_wdm
  5399. // Note: There must a be a convention to the order of fields of same type,
  5400. // (defined on a device by device basis) so that the fields can make sense
  5401. // to a driver (i.e. when multiple memory ranges are necessary).
  5402. //
  5403. typedef struct _CM_FULL_RESOURCE_DESCRIPTOR {
  5404. INTERFACE_TYPE InterfaceType; // unused for WDM
  5405. ULONG BusNumber; // unused for WDM
  5406. CM_PARTIAL_RESOURCE_LIST PartialResourceList;
  5407. } CM_FULL_RESOURCE_DESCRIPTOR, *PCM_FULL_RESOURCE_DESCRIPTOR;
  5408. //
  5409. // The Resource list is what will be stored by the drivers into the
  5410. // resource map via the IO API.
  5411. //
  5412. typedef struct _CM_RESOURCE_LIST {
  5413. ULONG Count;
  5414. CM_FULL_RESOURCE_DESCRIPTOR List[1];
  5415. } CM_RESOURCE_LIST, *PCM_RESOURCE_LIST;
  5416. // end_ntndis
  5417. //
  5418. // Define the structures used to interpret configuration data of
  5419. // \\Registry\machine\hardware\description tree.
  5420. // Basically, these structures are used to interpret component
  5421. // sepcific data.
  5422. //
  5423. //
  5424. // Define DEVICE_FLAGS
  5425. //
  5426. typedef struct _DEVICE_FLAGS {
  5427. ULONG Failed : 1;
  5428. ULONG ReadOnly : 1;
  5429. ULONG Removable : 1;
  5430. ULONG ConsoleIn : 1;
  5431. ULONG ConsoleOut : 1;
  5432. ULONG Input : 1;
  5433. ULONG Output : 1;
  5434. } DEVICE_FLAGS, *PDEVICE_FLAGS;
  5435. //
  5436. // Define Component Information structure
  5437. //
  5438. typedef struct _CM_COMPONENT_INFORMATION {
  5439. DEVICE_FLAGS Flags;
  5440. ULONG Version;
  5441. ULONG Key;
  5442. KAFFINITY AffinityMask;
  5443. } CM_COMPONENT_INFORMATION, *PCM_COMPONENT_INFORMATION;
  5444. //
  5445. // The following structures are used to interpret x86
  5446. // DeviceSpecificData of CM_PARTIAL_RESOURCE_DESCRIPTOR.
  5447. // (Most of the structures are defined by BIOS. They are
  5448. // not aligned on word (or dword) boundary.
  5449. //
  5450. //
  5451. // Define the Rom Block structure
  5452. //
  5453. typedef struct _CM_ROM_BLOCK {
  5454. ULONG Address;
  5455. ULONG Size;
  5456. } CM_ROM_BLOCK, *PCM_ROM_BLOCK;
  5457. // begin_ntminiport begin_ntndis
  5458. #include "pshpack1.h"
  5459. // end_ntminiport end_ntndis
  5460. //
  5461. // Define INT13 driver parameter block
  5462. //
  5463. typedef struct _CM_INT13_DRIVE_PARAMETER {
  5464. USHORT DriveSelect;
  5465. ULONG MaxCylinders;
  5466. USHORT SectorsPerTrack;
  5467. USHORT MaxHeads;
  5468. USHORT NumberDrives;
  5469. } CM_INT13_DRIVE_PARAMETER, *PCM_INT13_DRIVE_PARAMETER;
  5470. // begin_ntminiport begin_ntndis
  5471. //
  5472. // Define Mca POS data block for slot
  5473. //
  5474. typedef struct _CM_MCA_POS_DATA {
  5475. USHORT AdapterId;
  5476. UCHAR PosData1;
  5477. UCHAR PosData2;
  5478. UCHAR PosData3;
  5479. UCHAR PosData4;
  5480. } CM_MCA_POS_DATA, *PCM_MCA_POS_DATA;
  5481. //
  5482. // Memory configuration of eisa data block structure
  5483. //
  5484. typedef struct _EISA_MEMORY_TYPE {
  5485. UCHAR ReadWrite: 1;
  5486. UCHAR Cached : 1;
  5487. UCHAR Reserved0 :1;
  5488. UCHAR Type:2;
  5489. UCHAR Shared:1;
  5490. UCHAR Reserved1 :1;
  5491. UCHAR MoreEntries : 1;
  5492. } EISA_MEMORY_TYPE, *PEISA_MEMORY_TYPE;
  5493. typedef struct _EISA_MEMORY_CONFIGURATION {
  5494. EISA_MEMORY_TYPE ConfigurationByte;
  5495. UCHAR DataSize;
  5496. USHORT AddressLowWord;
  5497. UCHAR AddressHighByte;
  5498. USHORT MemorySize;
  5499. } EISA_MEMORY_CONFIGURATION, *PEISA_MEMORY_CONFIGURATION;
  5500. //
  5501. // Interrupt configurationn of eisa data block structure
  5502. //
  5503. typedef struct _EISA_IRQ_DESCRIPTOR {
  5504. UCHAR Interrupt : 4;
  5505. UCHAR Reserved :1;
  5506. UCHAR LevelTriggered :1;
  5507. UCHAR Shared : 1;
  5508. UCHAR MoreEntries : 1;
  5509. } EISA_IRQ_DESCRIPTOR, *PEISA_IRQ_DESCRIPTOR;
  5510. typedef struct _EISA_IRQ_CONFIGURATION {
  5511. EISA_IRQ_DESCRIPTOR ConfigurationByte;
  5512. UCHAR Reserved;
  5513. } EISA_IRQ_CONFIGURATION, *PEISA_IRQ_CONFIGURATION;
  5514. //
  5515. // DMA description of eisa data block structure
  5516. //
  5517. typedef struct _DMA_CONFIGURATION_BYTE0 {
  5518. UCHAR Channel : 3;
  5519. UCHAR Reserved : 3;
  5520. UCHAR Shared :1;
  5521. UCHAR MoreEntries :1;
  5522. } DMA_CONFIGURATION_BYTE0;
  5523. typedef struct _DMA_CONFIGURATION_BYTE1 {
  5524. UCHAR Reserved0 : 2;
  5525. UCHAR TransferSize : 2;
  5526. UCHAR Timing : 2;
  5527. UCHAR Reserved1 : 2;
  5528. } DMA_CONFIGURATION_BYTE1;
  5529. typedef struct _EISA_DMA_CONFIGURATION {
  5530. DMA_CONFIGURATION_BYTE0 ConfigurationByte0;
  5531. DMA_CONFIGURATION_BYTE1 ConfigurationByte1;
  5532. } EISA_DMA_CONFIGURATION, *PEISA_DMA_CONFIGURATION;
  5533. //
  5534. // Port description of eisa data block structure
  5535. //
  5536. typedef struct _EISA_PORT_DESCRIPTOR {
  5537. UCHAR NumberPorts : 5;
  5538. UCHAR Reserved :1;
  5539. UCHAR Shared :1;
  5540. UCHAR MoreEntries : 1;
  5541. } EISA_PORT_DESCRIPTOR, *PEISA_PORT_DESCRIPTOR;
  5542. typedef struct _EISA_PORT_CONFIGURATION {
  5543. EISA_PORT_DESCRIPTOR Configuration;
  5544. USHORT PortAddress;
  5545. } EISA_PORT_CONFIGURATION, *PEISA_PORT_CONFIGURATION;
  5546. //
  5547. // Eisa slot information definition
  5548. // N.B. This structure is different from the one defined
  5549. // in ARC eisa addendum.
  5550. //
  5551. typedef struct _CM_EISA_SLOT_INFORMATION {
  5552. UCHAR ReturnCode;
  5553. UCHAR ReturnFlags;
  5554. UCHAR MajorRevision;
  5555. UCHAR MinorRevision;
  5556. USHORT Checksum;
  5557. UCHAR NumberFunctions;
  5558. UCHAR FunctionInformation;
  5559. ULONG CompressedId;
  5560. } CM_EISA_SLOT_INFORMATION, *PCM_EISA_SLOT_INFORMATION;
  5561. //
  5562. // Eisa function information definition
  5563. //
  5564. typedef struct _CM_EISA_FUNCTION_INFORMATION {
  5565. ULONG CompressedId;
  5566. UCHAR IdSlotFlags1;
  5567. UCHAR IdSlotFlags2;
  5568. UCHAR MinorRevision;
  5569. UCHAR MajorRevision;
  5570. UCHAR Selections[26];
  5571. UCHAR FunctionFlags;
  5572. UCHAR TypeString[80];
  5573. EISA_MEMORY_CONFIGURATION EisaMemory[9];
  5574. EISA_IRQ_CONFIGURATION EisaIrq[7];
  5575. EISA_DMA_CONFIGURATION EisaDma[4];
  5576. EISA_PORT_CONFIGURATION EisaPort[20];
  5577. UCHAR InitializationData[60];
  5578. } CM_EISA_FUNCTION_INFORMATION, *PCM_EISA_FUNCTION_INFORMATION;
  5579. //
  5580. // The following defines the way pnp bios information is stored in
  5581. // the registry \\HKEY_LOCAL_MACHINE\HARDWARE\Description\System\MultifunctionAdapter\x
  5582. // key, where x is an integer number indicating adapter instance. The
  5583. // "Identifier" of the key must equal to "PNP BIOS" and the
  5584. // "ConfigurationData" is organized as follow:
  5585. //
  5586. // CM_PNP_BIOS_INSTALLATION_CHECK +
  5587. // CM_PNP_BIOS_DEVICE_NODE for device 1 +
  5588. // CM_PNP_BIOS_DEVICE_NODE for device 2 +
  5589. // ...
  5590. // CM_PNP_BIOS_DEVICE_NODE for device n
  5591. //
  5592. //
  5593. // Pnp BIOS device node structure
  5594. //
  5595. typedef struct _CM_PNP_BIOS_DEVICE_NODE {
  5596. USHORT Size;
  5597. UCHAR Node;
  5598. ULONG ProductId;
  5599. UCHAR DeviceType[3];
  5600. USHORT DeviceAttributes;
  5601. // followed by AllocatedResourceBlock, PossibleResourceBlock
  5602. // and CompatibleDeviceId
  5603. } CM_PNP_BIOS_DEVICE_NODE,*PCM_PNP_BIOS_DEVICE_NODE;
  5604. //
  5605. // Pnp BIOS Installation check
  5606. //
  5607. typedef struct _CM_PNP_BIOS_INSTALLATION_CHECK {
  5608. UCHAR Signature[4]; // $PnP (ascii)
  5609. UCHAR Revision;
  5610. UCHAR Length;
  5611. USHORT ControlField;
  5612. UCHAR Checksum;
  5613. ULONG EventFlagAddress; // Physical address
  5614. USHORT RealModeEntryOffset;
  5615. USHORT RealModeEntrySegment;
  5616. USHORT ProtectedModeEntryOffset;
  5617. ULONG ProtectedModeCodeBaseAddress;
  5618. ULONG OemDeviceId;
  5619. USHORT RealModeDataBaseAddress;
  5620. ULONG ProtectedModeDataBaseAddress;
  5621. } CM_PNP_BIOS_INSTALLATION_CHECK, *PCM_PNP_BIOS_INSTALLATION_CHECK;
  5622. #include "poppack.h"
  5623. //
  5624. // Masks for EISA function information
  5625. //
  5626. #define EISA_FUNCTION_ENABLED 0x80
  5627. #define EISA_FREE_FORM_DATA 0x40
  5628. #define EISA_HAS_PORT_INIT_ENTRY 0x20
  5629. #define EISA_HAS_PORT_RANGE 0x10
  5630. #define EISA_HAS_DMA_ENTRY 0x08
  5631. #define EISA_HAS_IRQ_ENTRY 0x04
  5632. #define EISA_HAS_MEMORY_ENTRY 0x02
  5633. #define EISA_HAS_TYPE_ENTRY 0x01
  5634. #define EISA_HAS_INFORMATION EISA_HAS_PORT_RANGE + \
  5635. EISA_HAS_DMA_ENTRY + \
  5636. EISA_HAS_IRQ_ENTRY + \
  5637. EISA_HAS_MEMORY_ENTRY + \
  5638. EISA_HAS_TYPE_ENTRY
  5639. //
  5640. // Masks for EISA memory configuration
  5641. //
  5642. #define EISA_MORE_ENTRIES 0x80
  5643. #define EISA_SYSTEM_MEMORY 0x00
  5644. #define EISA_MEMORY_TYPE_RAM 0x01
  5645. //
  5646. // Returned error code for EISA bios call
  5647. //
  5648. #define EISA_INVALID_SLOT 0x80
  5649. #define EISA_INVALID_FUNCTION 0x81
  5650. #define EISA_INVALID_CONFIGURATION 0x82
  5651. #define EISA_EMPTY_SLOT 0x83
  5652. #define EISA_INVALID_BIOS_CALL 0x86
  5653. // end_ntminiport end_ntndis
  5654. //
  5655. // The following structures are used to interpret mips
  5656. // DeviceSpecificData of CM_PARTIAL_RESOURCE_DESCRIPTOR.
  5657. //
  5658. //
  5659. // Device data records for adapters.
  5660. //
  5661. //
  5662. // The device data record for the Emulex SCSI controller.
  5663. //
  5664. typedef struct _CM_SCSI_DEVICE_DATA {
  5665. USHORT Version;
  5666. USHORT Revision;
  5667. UCHAR HostIdentifier;
  5668. } CM_SCSI_DEVICE_DATA, *PCM_SCSI_DEVICE_DATA;
  5669. //
  5670. // Device data records for controllers.
  5671. //
  5672. //
  5673. // The device data record for the Video controller.
  5674. //
  5675. typedef struct _CM_VIDEO_DEVICE_DATA {
  5676. USHORT Version;
  5677. USHORT Revision;
  5678. ULONG VideoClock;
  5679. } CM_VIDEO_DEVICE_DATA, *PCM_VIDEO_DEVICE_DATA;
  5680. //
  5681. // The device data record for the SONIC network controller.
  5682. //
  5683. typedef struct _CM_SONIC_DEVICE_DATA {
  5684. USHORT Version;
  5685. USHORT Revision;
  5686. USHORT DataConfigurationRegister;
  5687. UCHAR EthernetAddress[8];
  5688. } CM_SONIC_DEVICE_DATA, *PCM_SONIC_DEVICE_DATA;
  5689. //
  5690. // The device data record for the serial controller.
  5691. //
  5692. typedef struct _CM_SERIAL_DEVICE_DATA {
  5693. USHORT Version;
  5694. USHORT Revision;
  5695. ULONG BaudClock;
  5696. } CM_SERIAL_DEVICE_DATA, *PCM_SERIAL_DEVICE_DATA;
  5697. //
  5698. // Device data records for peripherals.
  5699. //
  5700. //
  5701. // The device data record for the Monitor peripheral.
  5702. //
  5703. typedef struct _CM_MONITOR_DEVICE_DATA {
  5704. USHORT Version;
  5705. USHORT Revision;
  5706. USHORT HorizontalScreenSize;
  5707. USHORT VerticalScreenSize;
  5708. USHORT HorizontalResolution;
  5709. USHORT VerticalResolution;
  5710. USHORT HorizontalDisplayTimeLow;
  5711. USHORT HorizontalDisplayTime;
  5712. USHORT HorizontalDisplayTimeHigh;
  5713. USHORT HorizontalBackPorchLow;
  5714. USHORT HorizontalBackPorch;
  5715. USHORT HorizontalBackPorchHigh;
  5716. USHORT HorizontalFrontPorchLow;
  5717. USHORT HorizontalFrontPorch;
  5718. USHORT HorizontalFrontPorchHigh;
  5719. USHORT HorizontalSyncLow;
  5720. USHORT HorizontalSync;
  5721. USHORT HorizontalSyncHigh;
  5722. USHORT VerticalBackPorchLow;
  5723. USHORT VerticalBackPorch;
  5724. USHORT VerticalBackPorchHigh;
  5725. USHORT VerticalFrontPorchLow;
  5726. USHORT VerticalFrontPorch;
  5727. USHORT VerticalFrontPorchHigh;
  5728. USHORT VerticalSyncLow;
  5729. USHORT VerticalSync;
  5730. USHORT VerticalSyncHigh;
  5731. } CM_MONITOR_DEVICE_DATA, *PCM_MONITOR_DEVICE_DATA;
  5732. //
  5733. // The device data record for the Floppy peripheral.
  5734. //
  5735. typedef struct _CM_FLOPPY_DEVICE_DATA {
  5736. USHORT Version;
  5737. USHORT Revision;
  5738. CHAR Size[8];
  5739. ULONG MaxDensity;
  5740. ULONG MountDensity;
  5741. //
  5742. // New data fields for version >= 2.0
  5743. //
  5744. UCHAR StepRateHeadUnloadTime;
  5745. UCHAR HeadLoadTime;
  5746. UCHAR MotorOffTime;
  5747. UCHAR SectorLengthCode;
  5748. UCHAR SectorPerTrack;
  5749. UCHAR ReadWriteGapLength;
  5750. UCHAR DataTransferLength;
  5751. UCHAR FormatGapLength;
  5752. UCHAR FormatFillCharacter;
  5753. UCHAR HeadSettleTime;
  5754. UCHAR MotorSettleTime;
  5755. UCHAR MaximumTrackValue;
  5756. UCHAR DataTransferRate;
  5757. } CM_FLOPPY_DEVICE_DATA, *PCM_FLOPPY_DEVICE_DATA;
  5758. //
  5759. // The device data record for the Keyboard peripheral.
  5760. // The KeyboardFlags is defined (by x86 BIOS INT 16h, function 02) as:
  5761. // bit 7 : Insert on
  5762. // bit 6 : Caps Lock on
  5763. // bit 5 : Num Lock on
  5764. // bit 4 : Scroll Lock on
  5765. // bit 3 : Alt Key is down
  5766. // bit 2 : Ctrl Key is down
  5767. // bit 1 : Left shift key is down
  5768. // bit 0 : Right shift key is down
  5769. //
  5770. typedef struct _CM_KEYBOARD_DEVICE_DATA {
  5771. USHORT Version;
  5772. USHORT Revision;
  5773. UCHAR Type;
  5774. UCHAR Subtype;
  5775. USHORT KeyboardFlags;
  5776. } CM_KEYBOARD_DEVICE_DATA, *PCM_KEYBOARD_DEVICE_DATA;
  5777. //
  5778. // Declaration of the structure for disk geometries
  5779. //
  5780. typedef struct _CM_DISK_GEOMETRY_DEVICE_DATA {
  5781. ULONG BytesPerSector;
  5782. ULONG NumberOfCylinders;
  5783. ULONG SectorsPerTrack;
  5784. ULONG NumberOfHeads;
  5785. } CM_DISK_GEOMETRY_DEVICE_DATA, *PCM_DISK_GEOMETRY_DEVICE_DATA;
  5786. // end_wdm
  5787. //
  5788. // Declaration of the structure for the PcCard ISA IRQ map
  5789. //
  5790. typedef struct _CM_PCCARD_DEVICE_DATA {
  5791. UCHAR Flags;
  5792. UCHAR ErrorCode;
  5793. USHORT Reserved;
  5794. ULONG BusData;
  5795. ULONG DeviceId;
  5796. ULONG LegacyBaseAddress;
  5797. UCHAR IRQMap[16];
  5798. } CM_PCCARD_DEVICE_DATA, *PCM_PCCARD_DEVICE_DATA;
  5799. // Definitions for Flags
  5800. #define PCCARD_MAP_ERROR 0x01
  5801. #define PCCARD_DEVICE_PCI 0x10
  5802. #define PCCARD_SCAN_DISABLED 0x01
  5803. #define PCCARD_MAP_ZERO 0x02
  5804. #define PCCARD_NO_TIMER 0x03
  5805. #define PCCARD_NO_PIC 0x04
  5806. #define PCCARD_NO_LEGACY_BASE 0x05
  5807. #define PCCARD_DUP_LEGACY_BASE 0x06
  5808. #define PCCARD_NO_CONTROLLERS 0x07
  5809. // begin_wdm
  5810. // begin_ntminiport
  5811. //
  5812. // Defines Resource Options
  5813. //
  5814. #define IO_RESOURCE_PREFERRED 0x01
  5815. #define IO_RESOURCE_DEFAULT 0x02
  5816. #define IO_RESOURCE_ALTERNATIVE 0x08
  5817. //
  5818. // This structure defines one type of resource requested by the driver
  5819. //
  5820. typedef struct _IO_RESOURCE_DESCRIPTOR {
  5821. UCHAR Option;
  5822. UCHAR Type; // use CM_RESOURCE_TYPE
  5823. UCHAR ShareDisposition; // use CM_SHARE_DISPOSITION
  5824. UCHAR Spare1;
  5825. USHORT Flags; // use CM resource flag defines
  5826. USHORT Spare2; // align
  5827. union {
  5828. struct {
  5829. ULONG Length;
  5830. ULONG Alignment;
  5831. PHYSICAL_ADDRESS MinimumAddress;
  5832. PHYSICAL_ADDRESS MaximumAddress;
  5833. } Port;
  5834. struct {
  5835. ULONG Length;
  5836. ULONG Alignment;
  5837. PHYSICAL_ADDRESS MinimumAddress;
  5838. PHYSICAL_ADDRESS MaximumAddress;
  5839. } Memory;
  5840. struct {
  5841. ULONG MinimumVector;
  5842. ULONG MaximumVector;
  5843. } Interrupt;
  5844. struct {
  5845. ULONG MinimumChannel;
  5846. ULONG MaximumChannel;
  5847. } Dma;
  5848. struct {
  5849. ULONG Length;
  5850. ULONG Alignment;
  5851. PHYSICAL_ADDRESS MinimumAddress;
  5852. PHYSICAL_ADDRESS MaximumAddress;
  5853. } Generic;
  5854. struct {
  5855. ULONG Data[3];
  5856. } DevicePrivate;
  5857. //
  5858. // Bus Number information.
  5859. //
  5860. struct {
  5861. ULONG Length;
  5862. ULONG MinBusNumber;
  5863. ULONG MaxBusNumber;
  5864. ULONG Reserved;
  5865. } BusNumber;
  5866. struct {
  5867. ULONG Priority; // use LCPRI_Xxx values in cfg.h
  5868. ULONG Reserved1;
  5869. ULONG Reserved2;
  5870. } ConfigData;
  5871. } u;
  5872. } IO_RESOURCE_DESCRIPTOR, *PIO_RESOURCE_DESCRIPTOR;
  5873. // end_ntminiport
  5874. typedef struct _IO_RESOURCE_LIST {
  5875. USHORT Version;
  5876. USHORT Revision;
  5877. ULONG Count;
  5878. IO_RESOURCE_DESCRIPTOR Descriptors[1];
  5879. } IO_RESOURCE_LIST, *PIO_RESOURCE_LIST;
  5880. typedef struct _IO_RESOURCE_REQUIREMENTS_LIST {
  5881. ULONG ListSize;
  5882. INTERFACE_TYPE InterfaceType; // unused for WDM
  5883. ULONG BusNumber; // unused for WDM
  5884. ULONG SlotNumber;
  5885. ULONG Reserved[3];
  5886. ULONG AlternativeLists;
  5887. IO_RESOURCE_LIST List[1];
  5888. } IO_RESOURCE_REQUIREMENTS_LIST, *PIO_RESOURCE_REQUIREMENTS_LIST;
  5889. #ifndef _PO_DDK_
  5890. #define _PO_DDK_
  5891. // begin_winnt
  5892. typedef enum _SYSTEM_POWER_STATE {
  5893. PowerSystemUnspecified = 0,
  5894. PowerSystemWorking = 1,
  5895. PowerSystemSleeping1 = 2,
  5896. PowerSystemSleeping2 = 3,
  5897. PowerSystemSleeping3 = 4,
  5898. PowerSystemHibernate = 5,
  5899. PowerSystemShutdown = 6,
  5900. PowerSystemMaximum = 7
  5901. } SYSTEM_POWER_STATE, *PSYSTEM_POWER_STATE;
  5902. #define POWER_SYSTEM_MAXIMUM 7
  5903. typedef enum {
  5904. PowerActionNone = 0,
  5905. PowerActionReserved,
  5906. PowerActionSleep,
  5907. PowerActionHibernate,
  5908. PowerActionShutdown,
  5909. PowerActionShutdownReset,
  5910. PowerActionShutdownOff,
  5911. PowerActionWarmEject
  5912. } POWER_ACTION, *PPOWER_ACTION;
  5913. typedef enum _DEVICE_POWER_STATE {
  5914. PowerDeviceUnspecified = 0,
  5915. PowerDeviceD0,
  5916. PowerDeviceD1,
  5917. PowerDeviceD2,
  5918. PowerDeviceD3,
  5919. PowerDeviceMaximum
  5920. } DEVICE_POWER_STATE, *PDEVICE_POWER_STATE;
  5921. // end_winnt
  5922. typedef union _POWER_STATE {
  5923. SYSTEM_POWER_STATE SystemState;
  5924. DEVICE_POWER_STATE DeviceState;
  5925. } POWER_STATE, *PPOWER_STATE;
  5926. typedef enum _POWER_STATE_TYPE {
  5927. SystemPowerState = 0,
  5928. DevicePowerState
  5929. } POWER_STATE_TYPE, *PPOWER_STATE_TYPE;
  5930. //
  5931. // Generic power related IOCTLs
  5932. //
  5933. #define IOCTL_QUERY_DEVICE_POWER_STATE \
  5934. CTL_CODE(FILE_DEVICE_BATTERY, 0x0, METHOD_BUFFERED, FILE_READ_ACCESS)
  5935. #define IOCTL_SET_DEVICE_WAKE \
  5936. CTL_CODE(FILE_DEVICE_BATTERY, 0x1, METHOD_BUFFERED, FILE_WRITE_ACCESS)
  5937. #define IOCTL_CANCEL_DEVICE_WAKE \
  5938. CTL_CODE(FILE_DEVICE_BATTERY, 0x2, METHOD_BUFFERED, FILE_WRITE_ACCESS)
  5939. //
  5940. // Defines for W32 interfaces
  5941. //
  5942. // begin_winnt
  5943. #define ES_SYSTEM_REQUIRED ((ULONG)0x00000001)
  5944. #define ES_DISPLAY_REQUIRED ((ULONG)0x00000002)
  5945. #define ES_USER_PRESENT ((ULONG)0x00000004)
  5946. #define ES_CONTINUOUS ((ULONG)0x80000000)
  5947. typedef ULONG EXECUTION_STATE;
  5948. typedef enum {
  5949. LT_DONT_CARE,
  5950. LT_LOWEST_LATENCY
  5951. } LATENCY_TIME;
  5952. // end_ntminiport end_ntifs end_wdm end_ntddk
  5953. //-----------------------------------------------------------------------------
  5954. // Device Power Information
  5955. // Accessable via CM_Get_DevInst_Registry_Property_Ex(CM_DRP_DEVICE_POWER_DATA)
  5956. //-----------------------------------------------------------------------------
  5957. #define PDCAP_D0_SUPPORTED 0x00000001
  5958. #define PDCAP_D1_SUPPORTED 0x00000002
  5959. #define PDCAP_D2_SUPPORTED 0x00000004
  5960. #define PDCAP_D3_SUPPORTED 0x00000008
  5961. #define PDCAP_WAKE_FROM_D0_SUPPORTED 0x00000010
  5962. #define PDCAP_WAKE_FROM_D1_SUPPORTED 0x00000020
  5963. #define PDCAP_WAKE_FROM_D2_SUPPORTED 0x00000040
  5964. #define PDCAP_WAKE_FROM_D3_SUPPORTED 0x00000080
  5965. #define PDCAP_WARM_EJECT_SUPPORTED 0x00000100
  5966. typedef struct CM_Power_Data_s {
  5967. ULONG PD_Size;
  5968. DEVICE_POWER_STATE PD_MostRecentPowerState;
  5969. ULONG PD_Capabilities;
  5970. ULONG PD_D1Latency;
  5971. ULONG PD_D2Latency;
  5972. ULONG PD_D3Latency;
  5973. DEVICE_POWER_STATE PD_PowerStateMapping[POWER_SYSTEM_MAXIMUM];
  5974. SYSTEM_POWER_STATE PD_DeepestSystemWake;
  5975. } CM_POWER_DATA, *PCM_POWER_DATA;
  5976. // begin_ntddk
  5977. typedef enum {
  5978. SystemPowerPolicyAc,
  5979. SystemPowerPolicyDc,
  5980. VerifySystemPolicyAc,
  5981. VerifySystemPolicyDc,
  5982. SystemPowerCapabilities,
  5983. SystemBatteryState,
  5984. SystemPowerStateHandler,
  5985. ProcessorStateHandler,
  5986. SystemPowerPolicyCurrent,
  5987. AdministratorPowerPolicy,
  5988. SystemReserveHiberFile,
  5989. ProcessorInformation,
  5990. SystemPowerInformation,
  5991. ProcessorStateHandler2,
  5992. LastWakeTime, // Compare with KeQueryInterruptTime()
  5993. LastSleepTime, // Compare with KeQueryInterruptTime()
  5994. SystemExecutionState,
  5995. SystemPowerStateNotifyHandler,
  5996. ProcessorPowerPolicyAc,
  5997. ProcessorPowerPolicyDc,
  5998. VerifyProcessorPowerPolicyAc,
  5999. VerifyProcessorPowerPolicyDc,
  6000. ProcessorPowerPolicyCurrent,
  6001. SystemPowerStateLogging,
  6002. SystemPowerLoggingEntry
  6003. } POWER_INFORMATION_LEVEL;
  6004. // begin_wdm
  6005. //
  6006. // System power manager capabilities
  6007. //
  6008. typedef struct {
  6009. ULONG Granularity;
  6010. ULONG Capacity;
  6011. } BATTERY_REPORTING_SCALE, *PBATTERY_REPORTING_SCALE;
  6012. // end_winnt
  6013. // begin_ntminiport begin_ntifs
  6014. #endif // !_PO_DDK_
  6015. // end_ntddk end_ntminiport end_wdm end_ntifs
  6016. #define POWER_PERF_SCALE 100
  6017. #define PERF_LEVEL_TO_PERCENT(_x_) ((_x_ * 1000) / (POWER_PERF_SCALE * 10))
  6018. #define PERCENT_TO_PERF_LEVEL(_x_) ((_x_ * POWER_PERF_SCALE * 10) / 1000)
  6019. //
  6020. // Policy manager state handler interfaces
  6021. //
  6022. // power state handlers
  6023. typedef enum {
  6024. PowerStateSleeping1 = 0,
  6025. PowerStateSleeping2 = 1,
  6026. PowerStateSleeping3 = 2,
  6027. PowerStateSleeping4 = 3,
  6028. PowerStateSleeping4Firmware = 4,
  6029. PowerStateShutdownReset = 5,
  6030. PowerStateShutdownOff = 6,
  6031. PowerStateMaximum = 7
  6032. } POWER_STATE_HANDLER_TYPE, *PPOWER_STATE_HANDLER_TYPE;
  6033. #define POWER_STATE_HANDLER_TYPE_MAX 8
  6034. typedef
  6035. NTSTATUS
  6036. (*PENTER_STATE_SYSTEM_HANDLER)(
  6037. IN PVOID SystemContext
  6038. );
  6039. typedef
  6040. NTSTATUS
  6041. (*PENTER_STATE_HANDLER)(
  6042. IN PVOID Context,
  6043. IN PENTER_STATE_SYSTEM_HANDLER SystemHandler OPTIONAL,
  6044. IN PVOID SystemContext,
  6045. IN LONG NumberProcessors,
  6046. IN volatile PLONG Number
  6047. );
  6048. typedef struct {
  6049. POWER_STATE_HANDLER_TYPE Type;
  6050. BOOLEAN RtcWake;
  6051. UCHAR Spare[3];
  6052. PENTER_STATE_HANDLER Handler;
  6053. PVOID Context;
  6054. } POWER_STATE_HANDLER, *PPOWER_STATE_HANDLER;
  6055. typedef
  6056. NTSTATUS
  6057. (*PENTER_STATE_NOTIFY_HANDLER)(
  6058. IN POWER_STATE_HANDLER_TYPE State,
  6059. IN PVOID Context,
  6060. IN BOOLEAN Entering
  6061. );
  6062. typedef struct {
  6063. PENTER_STATE_NOTIFY_HANDLER Handler;
  6064. PVOID Context;
  6065. } POWER_STATE_NOTIFY_HANDLER, *PPOWER_STATE_NOTIFY_HANDLER;
  6066. NTSYSCALLAPI
  6067. NTSTATUS
  6068. NTAPI
  6069. NtPowerInformation(
  6070. IN POWER_INFORMATION_LEVEL InformationLevel,
  6071. IN PVOID InputBuffer OPTIONAL,
  6072. IN ULONG InputBufferLength,
  6073. OUT PVOID OutputBuffer OPTIONAL,
  6074. IN ULONG OutputBufferLength
  6075. );
  6076. // processor idle functions
  6077. typedef struct {
  6078. ULONGLONG StartTime;
  6079. ULONGLONG EndTime;
  6080. ULONG IdleHandlerReserved[4];
  6081. } PROCESSOR_IDLE_TIMES, *PPROCESSOR_IDLE_TIMES;
  6082. typedef
  6083. BOOLEAN
  6084. (FASTCALL *PPROCESSOR_IDLE_HANDLER) (
  6085. IN OUT PPROCESSOR_IDLE_TIMES IdleTimes
  6086. );
  6087. typedef struct {
  6088. ULONG HardwareLatency;
  6089. PPROCESSOR_IDLE_HANDLER Handler;
  6090. } PROCESSOR_IDLE_HANDLER_INFO, *PPROCESSOR_IDLE_HANDLER_INFO;
  6091. typedef
  6092. VOID
  6093. (FASTCALL *PSET_PROCESSOR_THROTTLE) (
  6094. IN UCHAR Throttle
  6095. );
  6096. typedef
  6097. NTSTATUS
  6098. (FASTCALL *PSET_PROCESSOR_THROTTLE2) (
  6099. IN UCHAR Throttle
  6100. );
  6101. #define MAX_IDLE_HANDLERS 3
  6102. typedef struct {
  6103. UCHAR ThrottleScale;
  6104. BOOLEAN ThrottleOnIdle;
  6105. PSET_PROCESSOR_THROTTLE SetThrottle;
  6106. ULONG NumIdleHandlers;
  6107. PROCESSOR_IDLE_HANDLER_INFO IdleHandler[MAX_IDLE_HANDLERS];
  6108. } PROCESSOR_STATE_HANDLER, *PPROCESSOR_STATE_HANDLER;
  6109. // Processor_Perf_Level Flags
  6110. #define PROCESSOR_STATE_TYPE_PERFORMANCE 0x1
  6111. #define PROCESSOR_STATE_TYPE_THROTTLE 0x2
  6112. typedef struct {
  6113. UCHAR PercentFrequency; // max == POWER_PERF_SCALE
  6114. UCHAR Reserved;
  6115. USHORT Flags;
  6116. } PROCESSOR_PERF_LEVEL, *PPROCESSOR_PERF_LEVEL;
  6117. typedef struct {
  6118. UCHAR PercentFrequency; // max == POWER_PERF_SCALE
  6119. UCHAR MinCapacity; // battery capacity %
  6120. USHORT Power; // in milliwatts
  6121. UCHAR IncreaseLevel; // goto higher state
  6122. UCHAR DecreaseLevel; // goto lower state
  6123. USHORT Flags;
  6124. ULONG IncreaseTime; // in tick counts
  6125. ULONG DecreaseTime; // in tick counts
  6126. ULONG IncreaseCount; // goto higher state
  6127. ULONG DecreaseCount; // goto lower state
  6128. ULONGLONG PerformanceTime; // Tick count
  6129. } PROCESSOR_PERF_STATE, *PPROCESSOR_PERF_STATE;
  6130. typedef struct {
  6131. ULONG NumIdleHandlers;
  6132. PROCESSOR_IDLE_HANDLER_INFO IdleHandler[MAX_IDLE_HANDLERS];
  6133. PSET_PROCESSOR_THROTTLE2 SetPerfLevel;
  6134. ULONG HardwareLatency;
  6135. UCHAR NumPerfStates;
  6136. PROCESSOR_PERF_LEVEL PerfLevel[1]; // variable size
  6137. } PROCESSOR_STATE_HANDLER2, *PPROCESSOR_STATE_HANDLER2;
  6138. // begin_winnt
  6139. //
  6140. // Power Policy Management interfaces
  6141. //
  6142. typedef struct {
  6143. POWER_ACTION Action;
  6144. ULONG Flags;
  6145. ULONG EventCode;
  6146. } POWER_ACTION_POLICY, *PPOWER_ACTION_POLICY;
  6147. // POWER_ACTION_POLICY->Flags:
  6148. #define POWER_ACTION_QUERY_ALLOWED 0x00000001
  6149. #define POWER_ACTION_UI_ALLOWED 0x00000002
  6150. #define POWER_ACTION_OVERRIDE_APPS 0x00000004
  6151. #define POWER_ACTION_LIGHTEST_FIRST 0x10000000
  6152. #define POWER_ACTION_LOCK_CONSOLE 0x20000000
  6153. #define POWER_ACTION_DISABLE_WAKES 0x40000000
  6154. #define POWER_ACTION_CRITICAL 0x80000000
  6155. // POWER_ACTION_POLICY->EventCode flags
  6156. #define POWER_LEVEL_USER_NOTIFY_TEXT 0x00000001
  6157. #define POWER_LEVEL_USER_NOTIFY_SOUND 0x00000002
  6158. #define POWER_LEVEL_USER_NOTIFY_EXEC 0x00000004
  6159. #define POWER_USER_NOTIFY_BUTTON 0x00000008
  6160. #define POWER_USER_NOTIFY_SHUTDOWN 0x00000010
  6161. #define POWER_FORCE_TRIGGER_RESET 0x80000000
  6162. // system battery drain policies
  6163. typedef struct {
  6164. BOOLEAN Enable;
  6165. UCHAR Spare[3];
  6166. ULONG BatteryLevel;
  6167. POWER_ACTION_POLICY PowerPolicy;
  6168. SYSTEM_POWER_STATE MinSystemState;
  6169. } SYSTEM_POWER_LEVEL, *PSYSTEM_POWER_LEVEL;
  6170. // Discharge policy constants
  6171. #define NUM_DISCHARGE_POLICIES 4
  6172. #define DISCHARGE_POLICY_CRITICAL 0
  6173. #define DISCHARGE_POLICY_LOW 1
  6174. //
  6175. // Throttling policies
  6176. //
  6177. #define PO_THROTTLE_NONE 0
  6178. #define PO_THROTTLE_CONSTANT 1
  6179. #define PO_THROTTLE_DEGRADE 2
  6180. #define PO_THROTTLE_ADAPTIVE 3
  6181. #define PO_THROTTLE_MAXIMUM 4 // not a policy, just a limit
  6182. // system power policies
  6183. typedef struct _SYSTEM_POWER_POLICY {
  6184. ULONG Revision; // 1
  6185. // events
  6186. POWER_ACTION_POLICY PowerButton;
  6187. POWER_ACTION_POLICY SleepButton;
  6188. POWER_ACTION_POLICY LidClose;
  6189. SYSTEM_POWER_STATE LidOpenWake;
  6190. ULONG Reserved;
  6191. // "system idle" detection
  6192. POWER_ACTION_POLICY Idle;
  6193. ULONG IdleTimeout;
  6194. UCHAR IdleSensitivity;
  6195. // dynamic throttling policy
  6196. // PO_THROTTLE_NONE, PO_THROTTLE_CONSTANT, PO_THROTTLE_DEGRADE, or PO_THROTTLE_ADAPTIVE
  6197. UCHAR DynamicThrottle;
  6198. UCHAR Spare2[2];
  6199. // meaning of power action "sleep"
  6200. SYSTEM_POWER_STATE MinSleep;
  6201. SYSTEM_POWER_STATE MaxSleep;
  6202. SYSTEM_POWER_STATE ReducedLatencySleep;
  6203. ULONG WinLogonFlags;
  6204. // parameters for dozing
  6205. ULONG Spare3;
  6206. ULONG DozeS4Timeout;
  6207. // battery policies
  6208. ULONG BroadcastCapacityResolution;
  6209. SYSTEM_POWER_LEVEL DischargePolicy[NUM_DISCHARGE_POLICIES];
  6210. // video policies
  6211. ULONG VideoTimeout;
  6212. BOOLEAN VideoDimDisplay;
  6213. ULONG VideoReserved[3];
  6214. // hard disk policies
  6215. ULONG SpindownTimeout;
  6216. // processor policies
  6217. BOOLEAN OptimizeForPower;
  6218. UCHAR FanThrottleTolerance;
  6219. UCHAR ForcedThrottle;
  6220. UCHAR MinThrottle;
  6221. POWER_ACTION_POLICY OverThrottled;
  6222. } SYSTEM_POWER_POLICY, *PSYSTEM_POWER_POLICY;
  6223. // processor power policy state
  6224. typedef struct _PROCESSOR_POWER_POLICY_INFO {
  6225. // Time based information (will be converted to kernel units)
  6226. ULONG TimeCheck; // in US
  6227. ULONG DemoteLimit; // in US
  6228. ULONG PromoteLimit; // in US
  6229. // Percentage based information
  6230. UCHAR DemotePercent;
  6231. UCHAR PromotePercent;
  6232. UCHAR Spare[2];
  6233. // Flags
  6234. ULONG AllowDemotion:1;
  6235. ULONG AllowPromotion:1;
  6236. ULONG Reserved:30;
  6237. } PROCESSOR_POWER_POLICY_INFO, *PPROCESSOR_POWER_POLICY_INFO;
  6238. // processor power policy
  6239. typedef struct _PROCESSOR_POWER_POLICY {
  6240. ULONG Revision; // 1
  6241. // Dynamic Throttling Policy
  6242. UCHAR DynamicThrottle;
  6243. UCHAR Spare[3];
  6244. // Flags
  6245. ULONG DisableCStates:1;
  6246. ULONG Reserved:31;
  6247. // System policy information
  6248. // The Array is last, in case it needs to be grown and the structure
  6249. // revision incremented.
  6250. ULONG PolicyCount;
  6251. PROCESSOR_POWER_POLICY_INFO Policy[3];
  6252. } PROCESSOR_POWER_POLICY, *PPROCESSOR_POWER_POLICY;
  6253. // administrator power policy overrides
  6254. typedef struct _ADMINISTRATOR_POWER_POLICY {
  6255. // meaning of power action "sleep"
  6256. SYSTEM_POWER_STATE MinSleep;
  6257. SYSTEM_POWER_STATE MaxSleep;
  6258. // video policies
  6259. ULONG MinVideoTimeout;
  6260. ULONG MaxVideoTimeout;
  6261. // disk policies
  6262. ULONG MinSpindownTimeout;
  6263. ULONG MaxSpindownTimeout;
  6264. } ADMINISTRATOR_POWER_POLICY, *PADMINISTRATOR_POWER_POLICY;
  6265. // end_winnt
  6266. NTSYSCALLAPI
  6267. NTSTATUS
  6268. NTAPI
  6269. NtSetThreadExecutionState(
  6270. IN EXECUTION_STATE esFlags, // ES_xxx flags
  6271. OUT EXECUTION_STATE *PreviousFlags
  6272. );
  6273. NTSYSCALLAPI
  6274. NTSTATUS
  6275. NTAPI
  6276. NtRequestWakeupLatency(
  6277. IN LATENCY_TIME latency
  6278. );
  6279. NTSYSCALLAPI
  6280. NTSTATUS
  6281. NTAPI
  6282. NtInitiatePowerAction(
  6283. IN POWER_ACTION SystemAction,
  6284. IN SYSTEM_POWER_STATE MinSystemState,
  6285. IN ULONG Flags, // POWER_ACTION_xxx flags
  6286. IN BOOLEAN Asynchronous
  6287. );
  6288. NTSYSCALLAPI // only called by WinLogon
  6289. NTSTATUS
  6290. NTAPI
  6291. NtSetSystemPowerState(
  6292. IN POWER_ACTION SystemAction,
  6293. IN SYSTEM_POWER_STATE MinSystemState,
  6294. IN ULONG Flags // POWER_ACTION_xxx flags
  6295. );
  6296. NTSYSCALLAPI
  6297. NTSTATUS
  6298. NTAPI
  6299. NtGetDevicePowerState(
  6300. IN HANDLE Device,
  6301. OUT DEVICE_POWER_STATE *State
  6302. );
  6303. NTSYSCALLAPI
  6304. NTSTATUS
  6305. NTAPI
  6306. NtCancelDeviceWakeupRequest(
  6307. IN HANDLE Device
  6308. );
  6309. NTSYSCALLAPI
  6310. BOOLEAN
  6311. NTAPI
  6312. NtIsSystemResumeAutomatic(
  6313. VOID
  6314. );
  6315. NTSYSCALLAPI
  6316. NTSTATUS
  6317. NTAPI
  6318. NtRequestDeviceWakeup(
  6319. IN HANDLE Device
  6320. );
  6321. // WinLogonFlags:
  6322. #define WINLOGON_LOCK_ON_SLEEP 0x00000001
  6323. // begin_winnt
  6324. typedef struct {
  6325. // Misc supported system features
  6326. BOOLEAN PowerButtonPresent;
  6327. BOOLEAN SleepButtonPresent;
  6328. BOOLEAN LidPresent;
  6329. BOOLEAN SystemS1;
  6330. BOOLEAN SystemS2;
  6331. BOOLEAN SystemS3;
  6332. BOOLEAN SystemS4; // hibernate
  6333. BOOLEAN SystemS5; // off
  6334. BOOLEAN HiberFilePresent;
  6335. BOOLEAN FullWake;
  6336. BOOLEAN VideoDimPresent;
  6337. BOOLEAN ApmPresent;
  6338. BOOLEAN UpsPresent;
  6339. // Processors
  6340. BOOLEAN ThermalControl;
  6341. BOOLEAN ProcessorThrottle;
  6342. UCHAR ProcessorMinThrottle;
  6343. UCHAR ProcessorMaxThrottle;
  6344. UCHAR spare2[4];
  6345. // Disk
  6346. BOOLEAN DiskSpinDown;
  6347. UCHAR spare3[8];
  6348. // System Battery
  6349. BOOLEAN SystemBatteriesPresent;
  6350. BOOLEAN BatteriesAreShortTerm;
  6351. BATTERY_REPORTING_SCALE BatteryScale[3];
  6352. // Wake
  6353. SYSTEM_POWER_STATE AcOnLineWake;
  6354. SYSTEM_POWER_STATE SoftLidWake;
  6355. SYSTEM_POWER_STATE RtcWake;
  6356. SYSTEM_POWER_STATE MinDeviceWakeState; // note this may change on driver load
  6357. SYSTEM_POWER_STATE DefaultLowLatencyWake;
  6358. } SYSTEM_POWER_CAPABILITIES, *PSYSTEM_POWER_CAPABILITIES;
  6359. typedef struct {
  6360. BOOLEAN AcOnLine;
  6361. BOOLEAN BatteryPresent;
  6362. BOOLEAN Charging;
  6363. BOOLEAN Discharging;
  6364. BOOLEAN Spare1[4];
  6365. ULONG MaxCapacity;
  6366. ULONG RemainingCapacity;
  6367. ULONG Rate;
  6368. ULONG EstimatedTime;
  6369. ULONG DefaultAlert1;
  6370. ULONG DefaultAlert2;
  6371. } SYSTEM_BATTERY_STATE, *PSYSTEM_BATTERY_STATE;
  6372. // end_winnt
  6373. //
  6374. // valid flags for SYSTEM_POWER_STATE_DISABLE_REASON.PowerReasonCode
  6375. //
  6376. #define SPSD_REASON_NONE 0x00000000
  6377. #define SPSD_REASON_NOBIOSSUPPORT 0x00000001
  6378. #define SPSD_REASON_BIOSINCOMPATIBLE 0x00000002
  6379. #define SPSD_REASON_NOOSPM 0x00000003
  6380. #define SPSD_REASON_LEGACYDRIVER 0x00000004
  6381. #define SPSD_REASON_HIBERSTACK 0x00000005
  6382. #define SPSD_REASON_HIBERFILE 0x00000006
  6383. #define SPSD_REASON_POINTERNAL 0x00000007
  6384. #define SPSD_REASON_PAEMODE 0x00000008
  6385. #define SPSD_REASON_MPOVERRIDE 0x00000009
  6386. #define SPSD_REASON_DRIVERDOWNGRADE 0x0000000A
  6387. #define SPSD_REASON_PREVIOUSATTEMPTFAILED 0x0000000B
  6388. #define SPSD_REASON_UNKNOWN 0xFFFFFFFF
  6389. typedef struct _SYSTEM_POWER_STATE_DISABLE_REASON {
  6390. BOOLEAN AffectedState[POWER_STATE_HANDLER_TYPE_MAX];
  6391. ULONG PowerReasonCode;
  6392. ULONG PowerReasonLength;
  6393. //UCHAR PowerReasonInfo[ANYSIZE_ARRAY];
  6394. } SYSTEM_POWER_STATE_DISABLE_REASON, *PSYSTEM_POWER_STATE_DISABLE_REASON;
  6395. //
  6396. // valid flags for SYSTEM_POWER_LOGGING_ENTRY.LoggingType
  6397. //
  6398. #define LOGGING_TYPE_SPSD 0x00000001
  6399. #define LOGGING_TYPE_POWERTRANSITION 0x00000002
  6400. typedef struct _SYSTEM_POWER_LOGGING_ENTRY {
  6401. ULONG LoggingType;
  6402. PVOID LoggingEntry;
  6403. } SYSTEM_POWER_LOGGING_ENTRY, *PSYSTEM_POWER_LOGGING_ENTRY;
  6404. //
  6405. // Define maximum number of exception parameters.
  6406. //
  6407. // begin_winnt
  6408. #define EXCEPTION_MAXIMUM_PARAMETERS 15 // maximum number of exception parameters
  6409. //
  6410. // Exception record definition.
  6411. //
  6412. typedef struct _EXCEPTION_RECORD {
  6413. NTSTATUS ExceptionCode;
  6414. ULONG ExceptionFlags;
  6415. struct _EXCEPTION_RECORD *ExceptionRecord;
  6416. PVOID ExceptionAddress;
  6417. ULONG NumberParameters;
  6418. ULONG_PTR ExceptionInformation[EXCEPTION_MAXIMUM_PARAMETERS];
  6419. } EXCEPTION_RECORD;
  6420. typedef EXCEPTION_RECORD *PEXCEPTION_RECORD;
  6421. typedef struct _EXCEPTION_RECORD32 {
  6422. NTSTATUS ExceptionCode;
  6423. ULONG ExceptionFlags;
  6424. ULONG ExceptionRecord;
  6425. ULONG ExceptionAddress;
  6426. ULONG NumberParameters;
  6427. ULONG ExceptionInformation[EXCEPTION_MAXIMUM_PARAMETERS];
  6428. } EXCEPTION_RECORD32, *PEXCEPTION_RECORD32;
  6429. typedef struct _EXCEPTION_RECORD64 {
  6430. NTSTATUS ExceptionCode;
  6431. ULONG ExceptionFlags;
  6432. ULONG64 ExceptionRecord;
  6433. ULONG64 ExceptionAddress;
  6434. ULONG NumberParameters;
  6435. ULONG __unusedAlignment;
  6436. ULONG64 ExceptionInformation[EXCEPTION_MAXIMUM_PARAMETERS];
  6437. } EXCEPTION_RECORD64, *PEXCEPTION_RECORD64;
  6438. //
  6439. // Typedef for pointer returned by exception_info()
  6440. //
  6441. typedef struct _EXCEPTION_POINTERS {
  6442. PEXCEPTION_RECORD ExceptionRecord;
  6443. PCONTEXT ContextRecord;
  6444. } EXCEPTION_POINTERS, *PEXCEPTION_POINTERS;
  6445. // end_winnt
  6446. //
  6447. // Define alignment macros to align structure sizes and pointers up and down.
  6448. //
  6449. #define ALIGN_DOWN(length, type) \
  6450. ((ULONG)(length) & ~(sizeof(type) - 1))
  6451. #define ALIGN_UP(length, type) \
  6452. (ALIGN_DOWN(((ULONG)(length) + sizeof(type) - 1), type))
  6453. #define ALIGN_DOWN_POINTER(address, type) \
  6454. ((PVOID)((ULONG_PTR)(address) & ~((ULONG_PTR)sizeof(type) - 1)))
  6455. #define ALIGN_UP_POINTER(address, type) \
  6456. (ALIGN_DOWN_POINTER(((ULONG_PTR)(address) + sizeof(type) - 1), type))
  6457. #define POOL_TAGGING 1
  6458. #ifndef DBG
  6459. #define DBG 0
  6460. #endif
  6461. #if DBG
  6462. #define IF_DEBUG if (TRUE)
  6463. #else
  6464. #define IF_DEBUG if (FALSE)
  6465. #endif
  6466. #if DEVL
  6467. extern ULONG NtGlobalFlag;
  6468. #define IF_NTOS_DEBUG( FlagName ) \
  6469. if (NtGlobalFlag & (FLG_ ## FlagName))
  6470. #else
  6471. #define IF_NTOS_DEBUG( FlagName ) if (FALSE)
  6472. #endif
  6473. //
  6474. // Kernel definitions that need to be here for forward reference purposes
  6475. //
  6476. // begin_ntndis
  6477. //
  6478. // Processor modes.
  6479. //
  6480. typedef CCHAR KPROCESSOR_MODE;
  6481. typedef enum _MODE {
  6482. KernelMode,
  6483. UserMode,
  6484. MaximumMode
  6485. } MODE;
  6486. // end_ntndis
  6487. //
  6488. // APC function types
  6489. //
  6490. //
  6491. // Put in an empty definition for the KAPC so that the
  6492. // routines can reference it before it is declared.
  6493. //
  6494. struct _KAPC;
  6495. typedef
  6496. VOID
  6497. (*PKNORMAL_ROUTINE) (
  6498. IN PVOID NormalContext,
  6499. IN PVOID SystemArgument1,
  6500. IN PVOID SystemArgument2
  6501. );
  6502. typedef
  6503. VOID
  6504. (*PKKERNEL_ROUTINE) (
  6505. IN struct _KAPC *Apc,
  6506. IN OUT PKNORMAL_ROUTINE *NormalRoutine,
  6507. IN OUT PVOID *NormalContext,
  6508. IN OUT PVOID *SystemArgument1,
  6509. IN OUT PVOID *SystemArgument2
  6510. );
  6511. typedef
  6512. VOID
  6513. (*PKRUNDOWN_ROUTINE) (
  6514. IN struct _KAPC *Apc
  6515. );
  6516. typedef
  6517. BOOLEAN
  6518. (*PKSYNCHRONIZE_ROUTINE) (
  6519. IN PVOID SynchronizeContext
  6520. );
  6521. typedef
  6522. BOOLEAN
  6523. (*PKTRANSFER_ROUTINE) (
  6524. VOID
  6525. );
  6526. //
  6527. //
  6528. // Asynchronous Procedure Call (APC) object
  6529. //
  6530. //
  6531. typedef struct _KAPC {
  6532. CSHORT Type;
  6533. CSHORT Size;
  6534. ULONG Spare0;
  6535. struct _KTHREAD *Thread;
  6536. LIST_ENTRY ApcListEntry;
  6537. PKKERNEL_ROUTINE KernelRoutine;
  6538. PKRUNDOWN_ROUTINE RundownRoutine;
  6539. PKNORMAL_ROUTINE NormalRoutine;
  6540. PVOID NormalContext;
  6541. //
  6542. // N.B. The following two members MUST be together.
  6543. //
  6544. PVOID SystemArgument1;
  6545. PVOID SystemArgument2;
  6546. CCHAR ApcStateIndex;
  6547. KPROCESSOR_MODE ApcMode;
  6548. BOOLEAN Inserted;
  6549. } KAPC, *PKAPC, *RESTRICTED_POINTER PRKAPC;
  6550. // begin_ntndis
  6551. //
  6552. // DPC routine
  6553. //
  6554. struct _KDPC;
  6555. typedef
  6556. VOID
  6557. (*PKDEFERRED_ROUTINE) (
  6558. IN struct _KDPC *Dpc,
  6559. IN PVOID DeferredContext,
  6560. IN PVOID SystemArgument1,
  6561. IN PVOID SystemArgument2
  6562. );
  6563. //
  6564. // Define DPC importance.
  6565. //
  6566. // LowImportance - Queue DPC at end of target DPC queue.
  6567. // MediumImportance - Queue DPC at end of target DPC queue.
  6568. // HighImportance - Queue DPC at front of target DPC DPC queue.
  6569. //
  6570. // If there is currently a DPC active on the target processor, or a DPC
  6571. // interrupt has already been requested on the target processor when a
  6572. // DPC is queued, then no further action is necessary. The DPC will be
  6573. // executed on the target processor when its queue entry is processed.
  6574. //
  6575. // If there is not a DPC active on the target processor and a DPC interrupt
  6576. // has not been requested on the target processor, then the exact treatment
  6577. // of the DPC is dependent on whether the host system is a UP system or an
  6578. // MP system.
  6579. //
  6580. // UP system.
  6581. //
  6582. // If the DPC is of medium or high importance, the current DPC queue depth
  6583. // is greater than the maximum target depth, or current DPC request rate is
  6584. // less the minimum target rate, then a DPC interrupt is requested on the
  6585. // host processor and the DPC will be processed when the interrupt occurs.
  6586. // Otherwise, no DPC interupt is requested and the DPC execution will be
  6587. // delayed until the DPC queue depth is greater that the target depth or the
  6588. // minimum DPC rate is less than the target rate.
  6589. //
  6590. // MP system.
  6591. //
  6592. // If the DPC is being queued to another processor and the depth of the DPC
  6593. // queue on the target processor is greater than the maximum target depth or
  6594. // the DPC is of high importance, then a DPC interrupt is requested on the
  6595. // target processor and the DPC will be processed when the interrupt occurs.
  6596. // Otherwise, the DPC execution will be delayed on the target processor until
  6597. // the DPC queue depth on the target processor is greater that the maximum
  6598. // target depth or the minimum DPC rate on the target processor is less than
  6599. // the target mimimum rate.
  6600. //
  6601. // If the DPC is being queued to the current processor and the DPC is not of
  6602. // low importance, the current DPC queue depth is greater than the maximum
  6603. // target depth, or the minimum DPC rate is less than the minimum target rate,
  6604. // then a DPC interrupt is request on the current processor and the DPV will
  6605. // be processed whne the interrupt occurs. Otherwise, no DPC interupt is
  6606. // requested and the DPC execution will be delayed until the DPC queue depth
  6607. // is greater that the target depth or the minimum DPC rate is less than the
  6608. // target rate.
  6609. //
  6610. typedef enum _KDPC_IMPORTANCE {
  6611. LowImportance,
  6612. MediumImportance,
  6613. HighImportance
  6614. } KDPC_IMPORTANCE;
  6615. //
  6616. // Define DPC type indicies.
  6617. //
  6618. #define DPC_NORMAL 0
  6619. #define DPC_THREADED 1
  6620. //
  6621. // Deferred Procedure Call (DPC) object
  6622. //
  6623. typedef struct _KDPC {
  6624. CSHORT Type;
  6625. UCHAR Number;
  6626. UCHAR Importance;
  6627. LIST_ENTRY DpcListEntry;
  6628. PKDEFERRED_ROUTINE DeferredRoutine;
  6629. PVOID DeferredContext;
  6630. PVOID SystemArgument1;
  6631. PVOID SystemArgument2;
  6632. PVOID DpcData;
  6633. } KDPC, *PKDPC, *RESTRICTED_POINTER PRKDPC;
  6634. //
  6635. // Interprocessor interrupt worker routine function prototype.
  6636. //
  6637. typedef PVOID PKIPI_CONTEXT;
  6638. typedef
  6639. VOID
  6640. (*PKIPI_WORKER)(
  6641. IN PKIPI_CONTEXT PacketContext,
  6642. IN PVOID Parameter1,
  6643. IN PVOID Parameter2,
  6644. IN PVOID Parameter3
  6645. );
  6646. //
  6647. // Define interprocessor interrupt performance counters.
  6648. //
  6649. typedef struct _KIPI_COUNTS {
  6650. ULONG Freeze;
  6651. ULONG Packet;
  6652. ULONG DPC;
  6653. ULONG APC;
  6654. ULONG FlushSingleTb;
  6655. ULONG FlushMultipleTb;
  6656. ULONG FlushEntireTb;
  6657. ULONG GenericCall;
  6658. ULONG ChangeColor;
  6659. ULONG SweepDcache;
  6660. ULONG SweepIcache;
  6661. ULONG SweepIcacheRange;
  6662. ULONG FlushIoBuffers;
  6663. ULONG GratuitousDPC;
  6664. } KIPI_COUNTS, *PKIPI_COUNTS;
  6665. // end_ntddk end_wdm end_ntifs end_ntosp end_ntndis
  6666. #if defined(NT_UP)
  6667. #define HOT_STATISTIC(a) a
  6668. #else
  6669. #define HOT_STATISTIC(a) (KeGetCurrentPrcb()->a)
  6670. #endif
  6671. // begin_ntddk begin_wdm begin_ntifs begin_ntosp begin_ntndis
  6672. //
  6673. // I/O system definitions.
  6674. //
  6675. // Define a Memory Descriptor List (MDL)
  6676. //
  6677. // An MDL describes pages in a virtual buffer in terms of physical pages. The
  6678. // pages associated with the buffer are described in an array that is allocated
  6679. // just after the MDL header structure itself.
  6680. //
  6681. // One simply calculates the base of the array by adding one to the base
  6682. // MDL pointer:
  6683. //
  6684. // Pages = (PPFN_NUMBER) (Mdl + 1);
  6685. //
  6686. // Notice that while in the context of the subject thread, the base virtual
  6687. // address of a buffer mapped by an MDL may be referenced using the following:
  6688. //
  6689. // Mdl->StartVa | Mdl->ByteOffset
  6690. //
  6691. typedef struct _MDL {
  6692. struct _MDL *Next;
  6693. CSHORT Size;
  6694. CSHORT MdlFlags;
  6695. struct _EPROCESS *Process;
  6696. PVOID MappedSystemVa;
  6697. PVOID StartVa;
  6698. ULONG ByteCount;
  6699. ULONG ByteOffset;
  6700. } MDL, *PMDL;
  6701. #define MDL_MAPPED_TO_SYSTEM_VA 0x0001
  6702. #define MDL_PAGES_LOCKED 0x0002
  6703. #define MDL_SOURCE_IS_NONPAGED_POOL 0x0004
  6704. #define MDL_ALLOCATED_FIXED_SIZE 0x0008
  6705. #define MDL_PARTIAL 0x0010
  6706. #define MDL_PARTIAL_HAS_BEEN_MAPPED 0x0020
  6707. #define MDL_IO_PAGE_READ 0x0040
  6708. #define MDL_WRITE_OPERATION 0x0080
  6709. #define MDL_PARENT_MAPPED_SYSTEM_VA 0x0100
  6710. #define MDL_FREE_EXTRA_PTES 0x0200
  6711. #define MDL_DESCRIBES_AWE 0x0400
  6712. #define MDL_IO_SPACE 0x0800
  6713. #define MDL_NETWORK_HEADER 0x1000
  6714. #define MDL_MAPPING_CAN_FAIL 0x2000
  6715. #define MDL_ALLOCATED_MUST_SUCCEED 0x4000
  6716. #define MDL_MAPPING_FLAGS (MDL_MAPPED_TO_SYSTEM_VA | \
  6717. MDL_PAGES_LOCKED | \
  6718. MDL_SOURCE_IS_NONPAGED_POOL | \
  6719. MDL_PARTIAL_HAS_BEEN_MAPPED | \
  6720. MDL_PARENT_MAPPED_SYSTEM_VA | \
  6721. MDL_SYSTEM_VA | \
  6722. MDL_IO_SPACE )
  6723. // end_ntndis
  6724. //
  6725. // switch to DBG when appropriate
  6726. //
  6727. #if DBG
  6728. #define PAGED_CODE() \
  6729. { if (KeGetCurrentIrql() > APC_LEVEL) { \
  6730. KdPrint(( "EX: Pageable code called at IRQL %d\n", KeGetCurrentIrql() )); \
  6731. ASSERT(FALSE); \
  6732. } \
  6733. }
  6734. #else
  6735. #define PAGED_CODE() NOP_FUNCTION;
  6736. #endif
  6737. #define NTKERNELAPI DECLSPEC_IMPORT
  6738. #define NTHALAPI
  6739. //
  6740. // Common dispatcher object header
  6741. //
  6742. // N.B. The size field contains the number of dwords in the structure.
  6743. //
  6744. typedef struct _DISPATCHER_HEADER {
  6745. union {
  6746. struct {
  6747. UCHAR Type;
  6748. UCHAR Absolute;
  6749. UCHAR Size;
  6750. union {
  6751. UCHAR Inserted;
  6752. BOOLEAN DebugActive;
  6753. };
  6754. };
  6755. volatile LONG Lock;
  6756. };
  6757. LONG SignalState;
  6758. LIST_ENTRY WaitListHead;
  6759. } DISPATCHER_HEADER;
  6760. //
  6761. // Event object
  6762. //
  6763. typedef struct _KEVENT {
  6764. DISPATCHER_HEADER Header;
  6765. } KEVENT, *PKEVENT, *RESTRICTED_POINTER PRKEVENT;
  6766. //
  6767. // Timer object
  6768. //
  6769. typedef struct _KTIMER {
  6770. DISPATCHER_HEADER Header;
  6771. ULARGE_INTEGER DueTime;
  6772. LIST_ENTRY TimerListEntry;
  6773. struct _KDPC *Dpc;
  6774. LONG Period;
  6775. } KTIMER, *PKTIMER, *RESTRICTED_POINTER PRKTIMER;
  6776. typedef enum _LOCK_OPERATION {
  6777. IoReadAccess,
  6778. IoWriteAccess,
  6779. IoModifyAccess
  6780. } LOCK_OPERATION;
  6781. #if defined(_X86_)
  6782. //
  6783. // Types to use to contain PFNs and their counts.
  6784. //
  6785. typedef ULONG PFN_COUNT;
  6786. typedef LONG SPFN_NUMBER, *PSPFN_NUMBER;
  6787. typedef ULONG PFN_NUMBER, *PPFN_NUMBER;
  6788. //
  6789. // Define maximum size of flush multiple TB request.
  6790. //
  6791. #define FLUSH_MULTIPLE_MAXIMUM 32
  6792. //
  6793. // Indicate that the i386 compiler supports the pragma textout construct.
  6794. //
  6795. #define ALLOC_PRAGMA 1
  6796. //
  6797. // Indicate that the i386 compiler supports the DATA_SEG("INIT") and
  6798. // DATA_SEG("PAGE") pragmas
  6799. //
  6800. #define ALLOC_DATA_PRAGMA 1
  6801. #define NORMAL_DISPATCH_LENGTH 106 // ntddk wdm
  6802. #define DISPATCH_LENGTH NORMAL_DISPATCH_LENGTH // ntddk wdm
  6803. //
  6804. // Define constants to access the bits in CR0.
  6805. //
  6806. #define CR0_PG 0x80000000 // paging
  6807. #define CR0_ET 0x00000010 // extension type (80387)
  6808. #define CR0_TS 0x00000008 // task switched
  6809. #define CR0_EM 0x00000004 // emulate math coprocessor
  6810. #define CR0_MP 0x00000002 // math present
  6811. #define CR0_PE 0x00000001 // protection enable
  6812. //
  6813. // More CR0 bits; these only apply to the 80486.
  6814. //
  6815. #define CR0_CD 0x40000000 // cache disable
  6816. #define CR0_NW 0x20000000 // not write-through
  6817. #define CR0_AM 0x00040000 // alignment mask
  6818. #define CR0_WP 0x00010000 // write protect
  6819. #define CR0_NE 0x00000020 // numeric error
  6820. //
  6821. // CR4 bits; These only apply to Pentium
  6822. //
  6823. #define CR4_VME 0x00000001 // V86 mode extensions
  6824. #define CR4_PVI 0x00000002 // Protected mode virtual interrupts
  6825. #define CR4_TSD 0x00000004 // Time stamp disable
  6826. #define CR4_DE 0x00000008 // Debugging Extensions
  6827. #define CR4_PSE 0x00000010 // Page size extensions
  6828. #define CR4_PAE 0x00000020 // Physical address extensions
  6829. #define CR4_MCE 0x00000040 // Machine check enable
  6830. #define CR4_PGE 0x00000080 // Page global enable
  6831. #define CR4_FXSR 0x00000200 // FXSR used by OS
  6832. #define CR4_XMMEXCPT 0x00000400 // XMMI used by OS
  6833. //
  6834. // Interrupt Request Level definitions
  6835. //
  6836. #define PASSIVE_LEVEL 0 // Passive release level
  6837. #define LOW_LEVEL 0 // Lowest interrupt level
  6838. #define APC_LEVEL 1 // APC interrupt level
  6839. #define DISPATCH_LEVEL 2 // Dispatcher level
  6840. #define PROFILE_LEVEL 27 // timer used for profiling.
  6841. #define CLOCK1_LEVEL 28 // Interval clock 1 level - Not used on x86
  6842. #define CLOCK2_LEVEL 28 // Interval clock 2 level
  6843. #define IPI_LEVEL 29 // Interprocessor interrupt level
  6844. #define POWER_LEVEL 30 // Power failure level
  6845. #define HIGH_LEVEL 31 // Highest interrupt level
  6846. // end_ntddk end_wdm end_ntosp
  6847. #if defined(NT_UP)
  6848. // synchronization level - UP system
  6849. #define SYNCH_LEVEL DISPATCH_LEVEL
  6850. #else
  6851. // synchronization level - MP system
  6852. #define SYNCH_LEVEL (IPI_LEVEL-2) // ntddk wdm ntosp
  6853. #endif
  6854. #define KiSynchIrql SYNCH_LEVEL // enable portable code
  6855. //
  6856. // Machine type definitions
  6857. //
  6858. #define MACHINE_TYPE_ISA 0
  6859. #define MACHINE_TYPE_EISA 1
  6860. #define MACHINE_TYPE_MCA 2
  6861. //
  6862. // Define constants used in selector tests.
  6863. //
  6864. // RPL_MASK is the real value for extracting RPL values. IT IS THE WRONG
  6865. // CONSTANT TO USE FOR MODE TESTING.
  6866. //
  6867. // MODE_MASK is the value for deciding the current mode.
  6868. // WARNING: MODE_MASK assumes that all code runs at either ring-0
  6869. // or ring-3. Ring-1 or Ring-2 support will require changing
  6870. // this value and all of the code that refers to it.
  6871. #define MODE_MASK 1 // ntosp
  6872. #define RPL_MASK 3
  6873. //
  6874. // SEGMENT_MASK is used to throw away trash part of segment. Part always
  6875. // pushes or pops 32 bits to/from stack, but if it's a segment value,
  6876. // high order 16 bits are trash.
  6877. //
  6878. #define SEGMENT_MASK 0xffff
  6879. //
  6880. // Startup count value for KeStallExecution. This value is used
  6881. // until KiInitializeStallExecution can compute the real one.
  6882. // Pick a value long enough for very fast processors.
  6883. //
  6884. #define INITIAL_STALL_COUNT 100
  6885. //
  6886. // Macro to extract the high word of a long offset
  6887. //
  6888. #define HIGHWORD(l) \
  6889. ((USHORT)(((ULONG)(l)>>16) & 0xffff))
  6890. //
  6891. // Macro to extract the low word of a long offset
  6892. //
  6893. #define LOWWORD(l) \
  6894. ((USHORT)((ULONG)l & 0x0000ffff))
  6895. //
  6896. // Macro to combine two USHORT offsets into a long offset
  6897. //
  6898. #if !defined(MAKEULONG)
  6899. #define MAKEULONG(x, y) \
  6900. (((((ULONG)(x))<<16) & 0xffff0000) | \
  6901. ((ULONG)(y) & 0xffff))
  6902. #endif
  6903. //
  6904. // I/O space read and write macros.
  6905. //
  6906. // These have to be actual functions on the 386, because we need
  6907. // to use assembler, but cannot return a value if we inline it.
  6908. //
  6909. // The READ/WRITE_REGISTER_* calls manipulate I/O registers in MEMORY space.
  6910. // (Use x86 move instructions, with LOCK prefix to force correct behavior
  6911. // w.r.t. caches and write buffers.)
  6912. //
  6913. // The READ/WRITE_PORT_* calls manipulate I/O registers in PORT space.
  6914. // (Use x86 in/out instructions.)
  6915. //
  6916. NTKERNELAPI
  6917. UCHAR
  6918. NTAPI
  6919. READ_REGISTER_UCHAR(
  6920. PUCHAR Register
  6921. );
  6922. NTKERNELAPI
  6923. USHORT
  6924. NTAPI
  6925. READ_REGISTER_USHORT(
  6926. PUSHORT Register
  6927. );
  6928. NTKERNELAPI
  6929. ULONG
  6930. NTAPI
  6931. READ_REGISTER_ULONG(
  6932. PULONG Register
  6933. );
  6934. NTKERNELAPI
  6935. VOID
  6936. NTAPI
  6937. READ_REGISTER_BUFFER_UCHAR(
  6938. PUCHAR Register,
  6939. PUCHAR Buffer,
  6940. ULONG Count
  6941. );
  6942. NTKERNELAPI
  6943. VOID
  6944. NTAPI
  6945. READ_REGISTER_BUFFER_USHORT(
  6946. PUSHORT Register,
  6947. PUSHORT Buffer,
  6948. ULONG Count
  6949. );
  6950. NTKERNELAPI
  6951. VOID
  6952. NTAPI
  6953. READ_REGISTER_BUFFER_ULONG(
  6954. PULONG Register,
  6955. PULONG Buffer,
  6956. ULONG Count
  6957. );
  6958. NTKERNELAPI
  6959. VOID
  6960. NTAPI
  6961. WRITE_REGISTER_UCHAR(
  6962. PUCHAR Register,
  6963. UCHAR Value
  6964. );
  6965. NTKERNELAPI
  6966. VOID
  6967. NTAPI
  6968. WRITE_REGISTER_USHORT(
  6969. PUSHORT Register,
  6970. USHORT Value
  6971. );
  6972. NTKERNELAPI
  6973. VOID
  6974. NTAPI
  6975. WRITE_REGISTER_ULONG(
  6976. PULONG Register,
  6977. ULONG Value
  6978. );
  6979. NTKERNELAPI
  6980. VOID
  6981. NTAPI
  6982. WRITE_REGISTER_BUFFER_UCHAR(
  6983. PUCHAR Register,
  6984. PUCHAR Buffer,
  6985. ULONG Count
  6986. );
  6987. NTKERNELAPI
  6988. VOID
  6989. NTAPI
  6990. WRITE_REGISTER_BUFFER_USHORT(
  6991. PUSHORT Register,
  6992. PUSHORT Buffer,
  6993. ULONG Count
  6994. );
  6995. NTKERNELAPI
  6996. VOID
  6997. NTAPI
  6998. WRITE_REGISTER_BUFFER_ULONG(
  6999. PULONG Register,
  7000. PULONG Buffer,
  7001. ULONG Count
  7002. );
  7003. NTHALAPI
  7004. UCHAR
  7005. NTAPI
  7006. READ_PORT_UCHAR(
  7007. PUCHAR Port
  7008. );
  7009. NTHALAPI
  7010. USHORT
  7011. NTAPI
  7012. READ_PORT_USHORT(
  7013. PUSHORT Port
  7014. );
  7015. NTHALAPI
  7016. ULONG
  7017. NTAPI
  7018. READ_PORT_ULONG(
  7019. PULONG Port
  7020. );
  7021. NTHALAPI
  7022. VOID
  7023. NTAPI
  7024. READ_PORT_BUFFER_UCHAR(
  7025. PUCHAR Port,
  7026. PUCHAR Buffer,
  7027. ULONG Count
  7028. );
  7029. NTHALAPI
  7030. VOID
  7031. NTAPI
  7032. READ_PORT_BUFFER_USHORT(
  7033. PUSHORT Port,
  7034. PUSHORT Buffer,
  7035. ULONG Count
  7036. );
  7037. NTHALAPI
  7038. VOID
  7039. NTAPI
  7040. READ_PORT_BUFFER_ULONG(
  7041. PULONG Port,
  7042. PULONG Buffer,
  7043. ULONG Count
  7044. );
  7045. NTHALAPI
  7046. VOID
  7047. NTAPI
  7048. WRITE_PORT_UCHAR(
  7049. PUCHAR Port,
  7050. UCHAR Value
  7051. );
  7052. NTHALAPI
  7053. VOID
  7054. NTAPI
  7055. WRITE_PORT_USHORT(
  7056. PUSHORT Port,
  7057. USHORT Value
  7058. );
  7059. NTHALAPI
  7060. VOID
  7061. NTAPI
  7062. WRITE_PORT_ULONG(
  7063. PULONG Port,
  7064. ULONG Value
  7065. );
  7066. NTHALAPI
  7067. VOID
  7068. NTAPI
  7069. WRITE_PORT_BUFFER_UCHAR(
  7070. PUCHAR Port,
  7071. PUCHAR Buffer,
  7072. ULONG Count
  7073. );
  7074. NTHALAPI
  7075. VOID
  7076. NTAPI
  7077. WRITE_PORT_BUFFER_USHORT(
  7078. PUSHORT Port,
  7079. PUSHORT Buffer,
  7080. ULONG Count
  7081. );
  7082. NTHALAPI
  7083. VOID
  7084. NTAPI
  7085. WRITE_PORT_BUFFER_ULONG(
  7086. PULONG Port,
  7087. PULONG Buffer,
  7088. ULONG Count
  7089. );
  7090. // end_ntndis
  7091. //
  7092. // Get data cache fill size.
  7093. //
  7094. #if PRAGMA_DEPRECATED_DDK
  7095. #pragma deprecated(KeGetDcacheFillSize) // Use GetDmaAlignment
  7096. #endif
  7097. #define KeGetDcacheFillSize() 1L
  7098. NTKERNELAPI
  7099. VOID
  7100. KeFlushCurrentTb (
  7101. VOID
  7102. );
  7103. #define KeFlushIoBuffers(Mdl, ReadOperation, DmaOperation)
  7104. // end_ntddk end_wdm end_ntndis end_ntosp
  7105. #define KeYieldProcessor() __asm { rep nop }
  7106. VOID
  7107. FASTCALL
  7108. KiAcquireSpinLock (
  7109. IN PKSPIN_LOCK SpinLock
  7110. );
  7111. VOID
  7112. FASTCALL
  7113. KiReleaseSpinLock (
  7114. IN PKSPIN_LOCK SpinLock
  7115. );
  7116. #if defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_)
  7117. // begin_wdm
  7118. #define KeQueryTickCount(CurrentCount ) { \
  7119. volatile PKSYSTEM_TIME _TickCount = *((PKSYSTEM_TIME *)(&KeTickCount)); \
  7120. while (TRUE) { \
  7121. (CurrentCount)->HighPart = _TickCount->High1Time; \
  7122. (CurrentCount)->LowPart = _TickCount->LowPart; \
  7123. if ((CurrentCount)->HighPart == _TickCount->High2Time) break; \
  7124. _asm { rep nop } \
  7125. } \
  7126. }
  7127. // end_wdm
  7128. #else
  7129. VOID
  7130. NTAPI
  7131. KeQueryTickCount (
  7132. OUT PLARGE_INTEGER CurrentCount
  7133. );
  7134. #endif // defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_)
  7135. //
  7136. // 386 hardware structures
  7137. //
  7138. //
  7139. // A Page Table Entry on an Intel 386/486 has the following definition.
  7140. //
  7141. // **** NOTE A PRIVATE COPY OF THIS EXISTS IN THE MM\I386 DIRECTORY! ****
  7142. // **** ANY CHANGES NEED TO BE MADE TO BOTH HEADER FILES. ****
  7143. //
  7144. typedef struct _HARDWARE_PTE_X86 {
  7145. ULONG Valid : 1;
  7146. ULONG Write : 1;
  7147. ULONG Owner : 1;
  7148. ULONG WriteThrough : 1;
  7149. ULONG CacheDisable : 1;
  7150. ULONG Accessed : 1;
  7151. ULONG Dirty : 1;
  7152. ULONG LargePage : 1;
  7153. ULONG Global : 1;
  7154. ULONG CopyOnWrite : 1; // software field
  7155. ULONG Prototype : 1; // software field
  7156. ULONG reserved : 1; // software field
  7157. ULONG PageFrameNumber : 20;
  7158. } HARDWARE_PTE_X86, *PHARDWARE_PTE_X86;
  7159. typedef struct _HARDWARE_PTE_X86PAE {
  7160. union {
  7161. struct {
  7162. ULONGLONG Valid : 1;
  7163. ULONGLONG Write : 1;
  7164. ULONGLONG Owner : 1;
  7165. ULONGLONG WriteThrough : 1;
  7166. ULONGLONG CacheDisable : 1;
  7167. ULONGLONG Accessed : 1;
  7168. ULONGLONG Dirty : 1;
  7169. ULONGLONG LargePage : 1;
  7170. ULONGLONG Global : 1;
  7171. ULONGLONG CopyOnWrite : 1; // software field
  7172. ULONGLONG Prototype : 1; // software field
  7173. ULONGLONG reserved0 : 1; // software field
  7174. ULONGLONG PageFrameNumber : 26;
  7175. ULONGLONG reserved1 : 26; // software field
  7176. };
  7177. struct {
  7178. ULONG LowPart;
  7179. ULONG HighPart;
  7180. };
  7181. };
  7182. } HARDWARE_PTE_X86PAE, *PHARDWARE_PTE_X86PAE;
  7183. //
  7184. // Special check to work around mspdb limitation
  7185. //
  7186. #if defined (_NTSYM_HARDWARE_PTE_SYMBOL_)
  7187. #if !defined (_X86PAE_)
  7188. typedef struct _HARDWARE_PTE {
  7189. ULONG Valid : 1;
  7190. ULONG Write : 1;
  7191. ULONG Owner : 1;
  7192. ULONG WriteThrough : 1;
  7193. ULONG CacheDisable : 1;
  7194. ULONG Accessed : 1;
  7195. ULONG Dirty : 1;
  7196. ULONG LargePage : 1;
  7197. ULONG Global : 1;
  7198. ULONG CopyOnWrite : 1; // software field
  7199. ULONG Prototype : 1; // software field
  7200. ULONG reserved : 1; // software field
  7201. ULONG PageFrameNumber : 20;
  7202. } HARDWARE_PTE, *PHARDWARE_PTE;
  7203. #else
  7204. typedef struct _HARDWARE_PTE {
  7205. union {
  7206. struct {
  7207. ULONGLONG Valid : 1;
  7208. ULONGLONG Write : 1;
  7209. ULONGLONG Owner : 1;
  7210. ULONGLONG WriteThrough : 1;
  7211. ULONGLONG CacheDisable : 1;
  7212. ULONGLONG Accessed : 1;
  7213. ULONGLONG Dirty : 1;
  7214. ULONGLONG LargePage : 1;
  7215. ULONGLONG Global : 1;
  7216. ULONGLONG CopyOnWrite : 1; // software field
  7217. ULONGLONG Prototype : 1; // software field
  7218. ULONGLONG reserved0 : 1; // software field
  7219. ULONGLONG PageFrameNumber : 26;
  7220. ULONGLONG reserved1 : 26; // software field
  7221. };
  7222. struct {
  7223. ULONG LowPart;
  7224. ULONG HighPart;
  7225. };
  7226. };
  7227. } HARDWARE_PTE, *PHARDWARE_PTE;
  7228. #endif
  7229. #else
  7230. #if !defined (_X86PAE_)
  7231. typedef HARDWARE_PTE_X86 HARDWARE_PTE;
  7232. typedef PHARDWARE_PTE_X86 PHARDWARE_PTE;
  7233. #else
  7234. typedef HARDWARE_PTE_X86PAE HARDWARE_PTE;
  7235. typedef PHARDWARE_PTE_X86PAE PHARDWARE_PTE;
  7236. #endif
  7237. #endif
  7238. //
  7239. // GDT Entry
  7240. //
  7241. typedef struct _KGDTENTRY {
  7242. USHORT LimitLow;
  7243. USHORT BaseLow;
  7244. union {
  7245. struct {
  7246. UCHAR BaseMid;
  7247. UCHAR Flags1; // Declare as bytes to avoid alignment
  7248. UCHAR Flags2; // Problems.
  7249. UCHAR BaseHi;
  7250. } Bytes;
  7251. struct {
  7252. ULONG BaseMid : 8;
  7253. ULONG Type : 5;
  7254. ULONG Dpl : 2;
  7255. ULONG Pres : 1;
  7256. ULONG LimitHi : 4;
  7257. ULONG Sys : 1;
  7258. ULONG Reserved_0 : 1;
  7259. ULONG Default_Big : 1;
  7260. ULONG Granularity : 1;
  7261. ULONG BaseHi : 8;
  7262. } Bits;
  7263. } HighWord;
  7264. } KGDTENTRY, *PKGDTENTRY;
  7265. #define TYPE_CODE 0x10 // 11010 = Code, Readable, NOT Conforming, Accessed
  7266. #define TYPE_DATA 0x12 // 10010 = Data, ReadWrite, NOT Expanddown, Accessed
  7267. #define TYPE_TSS 0x01 // 01001 = NonBusy TSS
  7268. #define TYPE_LDT 0x02 // 00010 = LDT
  7269. #define DPL_USER 3
  7270. #define DPL_SYSTEM 0
  7271. #define GRAN_BYTE 0
  7272. #define GRAN_PAGE 1
  7273. #define SELECTOR_TABLE_INDEX 0x04
  7274. #define IDT_NMI_VECTOR 2
  7275. #define IDT_DFH_VECTOR 8
  7276. #define NMI_TSS_DESC_OFFSET 0x58
  7277. #define DF_TSS_DESC_OFFSET 0x50
  7278. //
  7279. // Entry of Interrupt Descriptor Table (IDTENTRY)
  7280. //
  7281. typedef struct _KIDTENTRY {
  7282. USHORT Offset;
  7283. USHORT Selector;
  7284. USHORT Access;
  7285. USHORT ExtendedOffset;
  7286. } KIDTENTRY;
  7287. typedef KIDTENTRY *PKIDTENTRY;
  7288. //
  7289. // TSS (Task switch segment) NT only uses to control stack switches.
  7290. //
  7291. // The only fields we actually care about are Esp0, Ss0, the IoMapBase
  7292. // and the IoAccessMaps themselves.
  7293. //
  7294. //
  7295. // N.B. Size of TSS must be <= 0xDFFF
  7296. //
  7297. //
  7298. // The interrupt direction bitmap is used on Pentium to allow
  7299. // the processor to emulate V86 mode software interrupts for us.
  7300. // There is one for each IOPM. It is located by subtracting
  7301. // 32 from the IOPM base in the Tss.
  7302. //
  7303. #define INT_DIRECTION_MAP_SIZE 32
  7304. typedef UCHAR KINT_DIRECTION_MAP[INT_DIRECTION_MAP_SIZE];
  7305. #define IOPM_COUNT 1 // Number of i/o access maps that
  7306. // exist (in addition to
  7307. // IO_ACCESS_MAP_NONE)
  7308. #define IO_ACCESS_MAP_NONE 0
  7309. #define IOPM_SIZE 8192 // Size of map callers can set.
  7310. #define PIOPM_SIZE 8196 // Size of structure we must allocate
  7311. // to hold it.
  7312. typedef UCHAR KIO_ACCESS_MAP[IOPM_SIZE];
  7313. typedef KIO_ACCESS_MAP *PKIO_ACCESS_MAP;
  7314. typedef struct _KiIoAccessMap {
  7315. KINT_DIRECTION_MAP DirectionMap;
  7316. UCHAR IoMap[PIOPM_SIZE];
  7317. } KIIO_ACCESS_MAP;
  7318. typedef struct _KTSS {
  7319. USHORT Backlink;
  7320. USHORT Reserved0;
  7321. ULONG Esp0;
  7322. USHORT Ss0;
  7323. USHORT Reserved1;
  7324. ULONG NotUsed1[4];
  7325. ULONG CR3;
  7326. ULONG Eip;
  7327. ULONG EFlags;
  7328. ULONG Eax;
  7329. ULONG Ecx;
  7330. ULONG Edx;
  7331. ULONG Ebx;
  7332. ULONG Esp;
  7333. ULONG Ebp;
  7334. ULONG Esi;
  7335. ULONG Edi;
  7336. USHORT Es;
  7337. USHORT Reserved2;
  7338. USHORT Cs;
  7339. USHORT Reserved3;
  7340. USHORT Ss;
  7341. USHORT Reserved4;
  7342. USHORT Ds;
  7343. USHORT Reserved5;
  7344. USHORT Fs;
  7345. USHORT Reserved6;
  7346. USHORT Gs;
  7347. USHORT Reserved7;
  7348. USHORT LDT;
  7349. USHORT Reserved8;
  7350. USHORT Flags;
  7351. USHORT IoMapBase;
  7352. KIIO_ACCESS_MAP IoMaps[IOPM_COUNT];
  7353. //
  7354. // This is the Software interrupt direction bitmap associated with
  7355. // IO_ACCESS_MAP_NONE
  7356. //
  7357. KINT_DIRECTION_MAP IntDirectionMap;
  7358. } KTSS, *PKTSS;
  7359. #define KiComputeIopmOffset(MapNumber) \
  7360. (MapNumber == IO_ACCESS_MAP_NONE) ? \
  7361. (USHORT)(sizeof(KTSS)) : \
  7362. (USHORT)(FIELD_OFFSET(KTSS, IoMaps[MapNumber-1].IoMap))
  7363. // begin_windbgkd
  7364. //
  7365. // Special Registers for i386
  7366. //
  7367. #ifdef _X86_
  7368. typedef struct _DESCRIPTOR {
  7369. USHORT Pad;
  7370. USHORT Limit;
  7371. ULONG Base;
  7372. } KDESCRIPTOR, *PKDESCRIPTOR;
  7373. typedef struct _KSPECIAL_REGISTERS {
  7374. ULONG Cr0;
  7375. ULONG Cr2;
  7376. ULONG Cr3;
  7377. ULONG Cr4;
  7378. ULONG KernelDr0;
  7379. ULONG KernelDr1;
  7380. ULONG KernelDr2;
  7381. ULONG KernelDr3;
  7382. ULONG KernelDr6;
  7383. ULONG KernelDr7;
  7384. KDESCRIPTOR Gdtr;
  7385. KDESCRIPTOR Idtr;
  7386. USHORT Tr;
  7387. USHORT Ldtr;
  7388. ULONG Reserved[6];
  7389. } KSPECIAL_REGISTERS, *PKSPECIAL_REGISTERS;
  7390. //
  7391. // Processor State frame: Before a processor freezes itself, it
  7392. // dumps the processor state to the processor state frame for
  7393. // debugger to examine.
  7394. //
  7395. typedef struct _KPROCESSOR_STATE {
  7396. struct _CONTEXT ContextFrame;
  7397. struct _KSPECIAL_REGISTERS SpecialRegisters;
  7398. } KPROCESSOR_STATE, *PKPROCESSOR_STATE;
  7399. #endif // _X86_
  7400. // end_windbgkd
  7401. //
  7402. // DPC data structure definition.
  7403. //
  7404. typedef struct _KDPC_DATA {
  7405. LIST_ENTRY DpcListHead;
  7406. KSPIN_LOCK DpcLock;
  7407. volatile ULONG DpcQueueDepth;
  7408. ULONG DpcCount;
  7409. } KDPC_DATA, *PKDPC_DATA;
  7410. //
  7411. // Processor Control Block (PRCB)
  7412. //
  7413. #define PRCB_MAJOR_VERSION 1
  7414. #define PRCB_MINOR_VERSION 1
  7415. #define PRCB_BUILD_DEBUG 0x0001
  7416. #define PRCB_BUILD_UNIPROCESSOR 0x0002
  7417. typedef struct _KPRCB {
  7418. //
  7419. // Start of the architecturally defined section of the PRCB. This section
  7420. // may be directly addressed by vendor/platform specific HAL code and will
  7421. // not change from version to version of NT.
  7422. //
  7423. USHORT MinorVersion;
  7424. USHORT MajorVersion;
  7425. struct _KTHREAD *CurrentThread;
  7426. struct _KTHREAD *NextThread;
  7427. struct _KTHREAD *IdleThread;
  7428. CCHAR Number;
  7429. CCHAR Reserved;
  7430. USHORT BuildType;
  7431. KAFFINITY SetMember;
  7432. CCHAR CpuType;
  7433. CCHAR CpuID;
  7434. USHORT CpuStep;
  7435. struct _KPROCESSOR_STATE ProcessorState;
  7436. ULONG KernelReserved[16]; // For use by the kernel
  7437. ULONG HalReserved[16]; // For use by Hal
  7438. //
  7439. // Per processor lock queue entries.
  7440. //
  7441. // N.B. The following padding is such that the first lock entry falls in the
  7442. // last eight bytes of a cache line. This makes the dispatcher lock and
  7443. // the context swap lock lie in separate cache lines.
  7444. //
  7445. UCHAR PrcbPad0[28 + 64];
  7446. KSPIN_LOCK_QUEUE LockQueue[16];
  7447. UCHAR PrcbPad1[8];
  7448. // End of the architecturally defined section of the PRCB.
  7449. } KPRCB, *PKPRCB, *RESTRICTED_POINTER PRKPRCB;
  7450. //
  7451. // Processor Control Region Structure Definition
  7452. //
  7453. #define PCR_MINOR_VERSION 1
  7454. #define PCR_MAJOR_VERSION 1
  7455. typedef struct _KPCR {
  7456. //
  7457. // Start of the architecturally defined section of the PCR. This section
  7458. // may be directly addressed by vendor/platform specific HAL code and will
  7459. // not change from version to version of NT.
  7460. //
  7461. // Certain fields in the TIB are not used in kernel mode. These include the
  7462. // stack limit, subsystem TIB, fiber data, arbitrary user pointer, and the
  7463. // self address of then PCR itself (another field has been added for that
  7464. // purpose). Therefore, these fields are overlaid with other data to get
  7465. // better cache locality.
  7466. //
  7467. union {
  7468. NT_TIB NtTib;
  7469. struct {
  7470. struct _EXCEPTION_REGISTRATION_RECORD *Used_ExceptionList;
  7471. PVOID Used_StackBase;
  7472. PVOID PerfGlobalGroupMask;
  7473. PVOID TssCopy;
  7474. ULONG ContextSwitches;
  7475. KAFFINITY SetMemberCopy;
  7476. PVOID Used_Self;
  7477. };
  7478. };
  7479. struct _KPCR *SelfPcr; // flat address of this PCR
  7480. struct _KPRCB *Prcb; // pointer to Prcb
  7481. KIRQL Irql; // do not use 3 bytes after this as
  7482. // HALs assume they are zero.
  7483. ULONG IRR;
  7484. ULONG IrrActive;
  7485. ULONG IDR;
  7486. PVOID KdVersionBlock;
  7487. struct _KIDTENTRY *IDT;
  7488. struct _KGDTENTRY *GDT;
  7489. struct _KTSS *TSS;
  7490. USHORT MajorVersion;
  7491. USHORT MinorVersion;
  7492. KAFFINITY SetMember;
  7493. ULONG StallScaleFactor;
  7494. UCHAR SpareUnused;
  7495. UCHAR Number;
  7496. // end_ntddk end_ntosp
  7497. UCHAR Spare0;
  7498. UCHAR SecondLevelCacheAssociativity;
  7499. ULONG VdmAlert;
  7500. ULONG KernelReserved[14]; // For use by the kernel
  7501. ULONG SecondLevelCacheSize;
  7502. ULONG HalReserved[16]; // For use by Hal
  7503. // End of the architecturally defined section of the PCR.
  7504. } KPCR, *PKPCR;
  7505. //
  7506. // bits defined in Eflags
  7507. //
  7508. #define EFLAGS_CF_MASK 0x00000001L
  7509. #define EFLAGS_PF_MASK 0x00000004L
  7510. #define EFLAGS_AF_MASK 0x00000010L
  7511. #define EFLAGS_ZF_MASK 0x00000040L
  7512. #define EFLAGS_SF_MASK 0x00000080L
  7513. #define EFLAGS_TF 0x00000100L
  7514. #define EFLAGS_INTERRUPT_MASK 0x00000200L
  7515. #define EFLAGS_DF_MASK 0x00000400L
  7516. #define EFLAGS_OF_MASK 0x00000800L
  7517. #define EFLAGS_IOPL_MASK 0x00003000L
  7518. #define EFLAGS_NT 0x00004000L
  7519. #define EFLAGS_RF 0x00010000L
  7520. #define EFLAGS_V86_MASK 0x00020000L
  7521. #define EFLAGS_ALIGN_CHECK 0x00040000L
  7522. #define EFLAGS_VIF 0x00080000L
  7523. #define EFLAGS_VIP 0x00100000L
  7524. #define EFLAGS_ID_MASK 0x00200000L
  7525. #define EFLAGS_USER_SANITIZE 0x003f4dd7L
  7526. //
  7527. // Trap frame
  7528. //
  7529. // NOTE - We deal only with 32bit registers, so the assembler equivalents
  7530. // are always the extended forms.
  7531. //
  7532. // NOTE - Unless you want to run like slow molasses everywhere in the
  7533. // the system, this structure must be of DWORD length, DWORD
  7534. // aligned, and its elements must all be DWORD aligned.
  7535. //
  7536. // NOTE WELL -
  7537. //
  7538. // The i386 does not build stack frames in a consistent format, the
  7539. // frames vary depending on whether or not a privilege transition
  7540. // was involved.
  7541. //
  7542. // In order to make NtContinue work for both user mode and kernel
  7543. // mode callers, we must force a canonical stack.
  7544. //
  7545. // If we're called from kernel mode, this structure is 8 bytes longer
  7546. // than the actual frame!
  7547. //
  7548. // WARNING:
  7549. //
  7550. // KTRAP_FRAME_LENGTH needs to be 16byte integral (at present.)
  7551. //
  7552. typedef struct _KTRAP_FRAME {
  7553. //
  7554. // Following 4 values are only used and defined for DBG systems,
  7555. // but are always allocated to make switching from DBG to non-DBG
  7556. // and back quicker. They are not DEVL because they have a non-0
  7557. // performance impact.
  7558. //
  7559. ULONG DbgEbp; // Copy of User EBP set up so KB will work.
  7560. ULONG DbgEip; // EIP of caller to system call, again, for KB.
  7561. ULONG DbgArgMark; // Marker to show no args here.
  7562. ULONG DbgArgPointer; // Pointer to the actual args
  7563. //
  7564. // Temporary values used when frames are edited.
  7565. //
  7566. //
  7567. // NOTE: Any code that want's ESP must materialize it, since it
  7568. // is not stored in the frame for kernel mode callers.
  7569. //
  7570. // And code that sets ESP in a KERNEL mode frame, must put
  7571. // the new value in TempEsp, make sure that TempSegCs holds
  7572. // the real SegCs value, and put a special marker value into SegCs.
  7573. //
  7574. ULONG TempSegCs;
  7575. ULONG TempEsp;
  7576. //
  7577. // Debug registers.
  7578. //
  7579. ULONG Dr0;
  7580. ULONG Dr1;
  7581. ULONG Dr2;
  7582. ULONG Dr3;
  7583. ULONG Dr6;
  7584. ULONG Dr7;
  7585. //
  7586. // Segment registers
  7587. //
  7588. ULONG SegGs;
  7589. ULONG SegEs;
  7590. ULONG SegDs;
  7591. //
  7592. // Volatile registers
  7593. //
  7594. ULONG Edx;
  7595. ULONG Ecx;
  7596. ULONG Eax;
  7597. //
  7598. // Nesting state, not part of context record
  7599. //
  7600. ULONG PreviousPreviousMode;
  7601. PEXCEPTION_REGISTRATION_RECORD ExceptionList;
  7602. // Trash if caller was user mode.
  7603. // Saved exception list if caller
  7604. // was kernel mode or we're in
  7605. // an interrupt.
  7606. //
  7607. // FS is TIB/PCR pointer, is here to make save sequence easy
  7608. //
  7609. ULONG SegFs;
  7610. //
  7611. // Non-volatile registers
  7612. //
  7613. ULONG Edi;
  7614. ULONG Esi;
  7615. ULONG Ebx;
  7616. ULONG Ebp;
  7617. //
  7618. // Control registers
  7619. //
  7620. ULONG ErrCode;
  7621. ULONG Eip;
  7622. ULONG SegCs;
  7623. ULONG EFlags;
  7624. ULONG HardwareEsp; // WARNING - segSS:esp are only here for stacks
  7625. ULONG HardwareSegSs; // that involve a ring transition.
  7626. ULONG V86Es; // these will be present for all transitions from
  7627. ULONG V86Ds; // V86 mode
  7628. ULONG V86Fs;
  7629. ULONG V86Gs;
  7630. } KTRAP_FRAME;
  7631. typedef KTRAP_FRAME *PKTRAP_FRAME;
  7632. typedef KTRAP_FRAME *PKEXCEPTION_FRAME;
  7633. #define KTRAP_FRAME_LENGTH (sizeof(KTRAP_FRAME))
  7634. #define KTRAP_FRAME_ALIGN (sizeof(ULONG))
  7635. #define KTRAP_FRAME_ROUND (KTRAP_FRAME_ALIGN-1)
  7636. //
  7637. // Bits forced to 0 in SegCs if Esp has been edited.
  7638. //
  7639. #define FRAME_EDITED 0xfff8
  7640. //
  7641. // i386 Specific portions of mm component
  7642. //
  7643. //
  7644. // Define the page size for the Intel 386 as 4096 (0x1000).
  7645. //
  7646. #define PAGE_SIZE 0x1000
  7647. //
  7648. // Define the number of trailing zeroes in a page aligned virtual address.
  7649. // This is used as the shift count when shifting virtual addresses to
  7650. // virtual page numbers.
  7651. //
  7652. #define PAGE_SHIFT 12L
  7653. // end_ntndis end_wdm
  7654. //
  7655. // Define the number of bits to shift to right justify the Page Directory Index
  7656. // field of a PTE.
  7657. //
  7658. #define PDI_SHIFT_X86 22
  7659. #define PDI_SHIFT_X86PAE 21
  7660. #if !defined (_X86PAE_)
  7661. #define PDI_SHIFT PDI_SHIFT_X86
  7662. #else
  7663. #define PDI_SHIFT PDI_SHIFT_X86PAE
  7664. #define PPI_SHIFT 30
  7665. #endif
  7666. //
  7667. // Define the number of bits to shift to right justify the Page Table Index
  7668. // field of a PTE.
  7669. //
  7670. #define PTI_SHIFT 12
  7671. //
  7672. // Define the highest user address and user probe address.
  7673. //
  7674. extern PVOID *MmHighestUserAddress;
  7675. extern PVOID *MmSystemRangeStart;
  7676. extern ULONG *MmUserProbeAddress;
  7677. #define MM_HIGHEST_USER_ADDRESS *MmHighestUserAddress
  7678. #define MM_SYSTEM_RANGE_START *MmSystemRangeStart
  7679. #define MM_USER_PROBE_ADDRESS *MmUserProbeAddress
  7680. //
  7681. // The lowest user address reserves the low 64k.
  7682. //
  7683. #define MM_LOWEST_USER_ADDRESS (PVOID)0x10000
  7684. //
  7685. // The lowest address for system space.
  7686. //
  7687. #if !defined (_X86PAE_)
  7688. #define MM_LOWEST_SYSTEM_ADDRESS (PVOID)0xC0800000
  7689. #else
  7690. #define MM_LOWEST_SYSTEM_ADDRESS (PVOID)0xC0C00000
  7691. #endif
  7692. // begin_wdm
  7693. #define MmGetProcedureAddress(Address) (Address)
  7694. #define MmLockPagableCodeSection(Address) MmLockPagableDataSection(Address)
  7695. // end_ntddk end_wdm
  7696. //
  7697. // Define the number of bits to shift to right justify the Page Directory Index
  7698. // field of a PTE.
  7699. //
  7700. #define PDI_SHIFT_X86 22
  7701. #define PDI_SHIFT_X86PAE 21
  7702. #if !defined (_X86PAE_)
  7703. #define PDI_SHIFT PDI_SHIFT_X86
  7704. #else
  7705. #define PDI_SHIFT PDI_SHIFT_X86PAE
  7706. #define PPI_SHIFT 30
  7707. #endif
  7708. //
  7709. // Define the number of bits to shift to right justify the Page Table Index
  7710. // field of a PTE.
  7711. //
  7712. #define PTI_SHIFT 12
  7713. //
  7714. // Define page directory and page base addresses.
  7715. //
  7716. #define PDE_BASE_X86 0xc0300000
  7717. #define PDE_BASE_X86PAE 0xc0600000
  7718. #define PTE_TOP_X86 0xC03FFFFF
  7719. #define PDE_TOP_X86 0xC0300FFF
  7720. #define PTE_TOP_X86PAE 0xC07FFFFF
  7721. #define PDE_TOP_X86PAE 0xC0603FFF
  7722. #if !defined (_X86PAE_)
  7723. #define PDE_BASE PDE_BASE_X86
  7724. #define PTE_TOP PTE_TOP_X86
  7725. #define PDE_TOP PDE_TOP_X86
  7726. #else
  7727. #define PDE_BASE PDE_BASE_X86PAE
  7728. #define PTE_TOP PTE_TOP_X86PAE
  7729. #define PDE_TOP PDE_TOP_X86PAE
  7730. #endif
  7731. #define PTE_BASE 0xc0000000
  7732. //
  7733. // Location of primary PCR (used only for UP kernel & hal code)
  7734. //
  7735. // addressed from 0xffdf0000 - 0xffdfffff are reserved for the system
  7736. // (ie, not for use by the hal)
  7737. #define KI_BEGIN_KERNEL_RESERVED 0xffdf0000
  7738. #define KIP0PCRADDRESS 0xffdff000 // ntddk wdm ntosp
  7739. // begin_ntddk begin_ntosp
  7740. #define KI_USER_SHARED_DATA 0xffdf0000
  7741. #define SharedUserData ((KUSER_SHARED_DATA * const) KI_USER_SHARED_DATA)
  7742. //
  7743. // Result type definition for i386. (Machine specific enumerate type
  7744. // which is return type for portable exinterlockedincrement/decrement
  7745. // procedures.) In general, you should use the enumerated type defined
  7746. // in ex.h instead of directly referencing these constants.
  7747. //
  7748. // Flags loaded into AH by LAHF instruction
  7749. #define EFLAG_SIGN 0x8000
  7750. #define EFLAG_ZERO 0x4000
  7751. #define EFLAG_SELECT (EFLAG_SIGN | EFLAG_ZERO)
  7752. #define RESULT_NEGATIVE ((EFLAG_SIGN & ~EFLAG_ZERO) & EFLAG_SELECT)
  7753. #define RESULT_ZERO ((~EFLAG_SIGN & EFLAG_ZERO) & EFLAG_SELECT)
  7754. #define RESULT_POSITIVE ((~EFLAG_SIGN & ~EFLAG_ZERO) & EFLAG_SELECT)
  7755. //
  7756. // Convert various portable ExInterlock APIs into their architectural
  7757. // equivalents.
  7758. //
  7759. #if PRAGMA_DEPRECATED_DDK
  7760. #pragma deprecated(ExInterlockedIncrementLong) // Use InterlockedIncrement
  7761. #pragma deprecated(ExInterlockedDecrementLong) // Use InterlockedDecrement
  7762. #pragma deprecated(ExInterlockedExchangeUlong) // Use InterlockedExchange
  7763. #endif
  7764. #define ExInterlockedIncrementLong(Addend,Lock) \
  7765. Exfi386InterlockedIncrementLong(Addend)
  7766. #define ExInterlockedDecrementLong(Addend,Lock) \
  7767. Exfi386InterlockedDecrementLong(Addend)
  7768. #define ExInterlockedExchangeUlong(Target,Value,Lock) \
  7769. Exfi386InterlockedExchangeUlong(Target,Value)
  7770. // begin_wdm
  7771. #define ExInterlockedAddUlong ExfInterlockedAddUlong
  7772. #define ExInterlockedInsertHeadList ExfInterlockedInsertHeadList
  7773. #define ExInterlockedInsertTailList ExfInterlockedInsertTailList
  7774. #define ExInterlockedRemoveHeadList ExfInterlockedRemoveHeadList
  7775. #define ExInterlockedPopEntryList ExfInterlockedPopEntryList
  7776. #define ExInterlockedPushEntryList ExfInterlockedPushEntryList
  7777. // end_wdm
  7778. //
  7779. // Prototypes for architectural specific versions of Exi386 Api
  7780. //
  7781. //
  7782. // Interlocked result type is portable, but its values are machine specific.
  7783. // Constants for value are in i386.h, mips.h, etc.
  7784. //
  7785. typedef enum _INTERLOCKED_RESULT {
  7786. ResultNegative = RESULT_NEGATIVE,
  7787. ResultZero = RESULT_ZERO,
  7788. ResultPositive = RESULT_POSITIVE
  7789. } INTERLOCKED_RESULT;
  7790. NTKERNELAPI
  7791. INTERLOCKED_RESULT
  7792. FASTCALL
  7793. Exfi386InterlockedIncrementLong (
  7794. IN PLONG Addend
  7795. );
  7796. NTKERNELAPI
  7797. INTERLOCKED_RESULT
  7798. FASTCALL
  7799. Exfi386InterlockedDecrementLong (
  7800. IN PLONG Addend
  7801. );
  7802. NTKERNELAPI
  7803. ULONG
  7804. FASTCALL
  7805. Exfi386InterlockedExchangeUlong (
  7806. IN PULONG Target,
  7807. IN ULONG Value
  7808. );
  7809. #if !defined(_WINBASE_) && !defined(NONTOSPINTERLOCK)
  7810. #if !defined(MIDL_PASS) // wdm
  7811. #if defined(NO_INTERLOCKED_INTRINSICS) || defined(_CROSS_PLATFORM_)
  7812. // begin_wdm
  7813. NTKERNELAPI
  7814. LONG
  7815. FASTCALL
  7816. InterlockedIncrement(
  7817. IN LONG volatile *Addend
  7818. );
  7819. NTKERNELAPI
  7820. LONG
  7821. FASTCALL
  7822. InterlockedDecrement(
  7823. IN LONG volatile *Addend
  7824. );
  7825. NTKERNELAPI
  7826. LONG
  7827. FASTCALL
  7828. InterlockedExchange(
  7829. IN OUT LONG volatile *Target,
  7830. IN LONG Value
  7831. );
  7832. #define InterlockedExchangePointer(Target, Value) \
  7833. (PVOID)InterlockedExchange((PLONG)(Target), (LONG)(Value))
  7834. LONG
  7835. FASTCALL
  7836. InterlockedExchangeAdd(
  7837. IN OUT LONG volatile *Addend,
  7838. IN LONG Increment
  7839. );
  7840. NTKERNELAPI
  7841. LONG
  7842. FASTCALL
  7843. InterlockedCompareExchange(
  7844. IN OUT LONG volatile *Destination,
  7845. IN LONG ExChange,
  7846. IN LONG Comperand
  7847. );
  7848. #define InterlockedCompareExchangePointer(Destination, ExChange, Comperand) \
  7849. (PVOID)InterlockedCompareExchange((PLONG)Destination, (LONG)ExChange, (LONG)Comperand)
  7850. #define InterlockedCompareExchange64(Destination, ExChange, Comperand) \
  7851. ExfInterlockedCompareExchange64(Destination, &(ExChange), &(Comperand))
  7852. NTKERNELAPI
  7853. LONGLONG
  7854. FASTCALL
  7855. ExfInterlockedCompareExchange64(
  7856. IN OUT LONGLONG volatile *Destination,
  7857. IN PLONGLONG ExChange,
  7858. IN PLONGLONG Comperand
  7859. );
  7860. // end_wdm
  7861. #else // NO_INTERLOCKED_INTRINSICS || _CROSS_PLATFORM_
  7862. #define InterlockedExchangePointer(Target, Value) \
  7863. (PVOID)InterlockedExchange((PLONG)Target, (LONG)Value)
  7864. #if (_MSC_FULL_VER > 13009037)
  7865. LONG
  7866. __cdecl
  7867. _InterlockedExchange(
  7868. IN OUT LONG volatile *Target,
  7869. IN LONG Value
  7870. );
  7871. #pragma intrinsic (_InterlockedExchange)
  7872. #define InterlockedExchange _InterlockedExchange
  7873. #else
  7874. FORCEINLINE
  7875. LONG
  7876. FASTCALL
  7877. InterlockedExchange(
  7878. IN OUT LONG volatile *Target,
  7879. IN LONG Value
  7880. )
  7881. {
  7882. __asm {
  7883. mov eax, Value
  7884. mov ecx, Target
  7885. xchg [ecx], eax
  7886. }
  7887. }
  7888. #endif
  7889. #if (_MSC_FULL_VER > 13009037)
  7890. LONG
  7891. __cdecl
  7892. _InterlockedIncrement(
  7893. IN LONG volatile *Addend
  7894. );
  7895. #pragma intrinsic (_InterlockedIncrement)
  7896. #define InterlockedIncrement _InterlockedIncrement
  7897. #else
  7898. #define InterlockedIncrement(Addend) (InterlockedExchangeAdd (Addend, 1)+1)
  7899. #endif
  7900. #if (_MSC_FULL_VER > 13009037)
  7901. LONG
  7902. __cdecl
  7903. _InterlockedDecrement(
  7904. IN LONG volatile *Addend
  7905. );
  7906. #pragma intrinsic (_InterlockedDecrement)
  7907. #define InterlockedDecrement _InterlockedDecrement
  7908. #else
  7909. #define InterlockedDecrement(Addend) (InterlockedExchangeAdd (Addend, -1)-1)
  7910. #endif
  7911. #if (_MSC_FULL_VER > 13009037)
  7912. LONG
  7913. __cdecl
  7914. _InterlockedExchangeAdd(
  7915. IN OUT LONG volatile *Addend,
  7916. IN LONG Increment
  7917. );
  7918. #pragma intrinsic (_InterlockedExchangeAdd)
  7919. #define InterlockedExchangeAdd _InterlockedExchangeAdd
  7920. #else
  7921. // begin_wdm
  7922. FORCEINLINE
  7923. LONG
  7924. FASTCALL
  7925. InterlockedExchangeAdd(
  7926. IN OUT LONG volatile *Addend,
  7927. IN LONG Increment
  7928. )
  7929. {
  7930. __asm {
  7931. mov eax, Increment
  7932. mov ecx, Addend
  7933. lock xadd [ecx], eax
  7934. }
  7935. }
  7936. // end_wdm
  7937. #endif
  7938. #if (_MSC_FULL_VER > 13009037)
  7939. LONG
  7940. __cdecl
  7941. _InterlockedCompareExchange (
  7942. IN OUT LONG volatile *Destination,
  7943. IN LONG ExChange,
  7944. IN LONG Comperand
  7945. );
  7946. #pragma intrinsic (_InterlockedCompareExchange)
  7947. #define InterlockedCompareExchange (LONG)_InterlockedCompareExchange
  7948. #else
  7949. FORCEINLINE
  7950. LONG
  7951. FASTCALL
  7952. InterlockedCompareExchange(
  7953. IN OUT LONG volatile *Destination,
  7954. IN LONG Exchange,
  7955. IN LONG Comperand
  7956. )
  7957. {
  7958. __asm {
  7959. mov eax, Comperand
  7960. mov ecx, Destination
  7961. mov edx, Exchange
  7962. lock cmpxchg [ecx], edx
  7963. }
  7964. }
  7965. #endif
  7966. #define InterlockedCompareExchangePointer(Destination, ExChange, Comperand) \
  7967. (PVOID)InterlockedCompareExchange((PLONG)Destination, (LONG)ExChange, (LONG)Comperand)
  7968. #define InterlockedCompareExchange64(Destination, ExChange, Comperand) \
  7969. ExfInterlockedCompareExchange64(Destination, &(ExChange), &(Comperand))
  7970. NTKERNELAPI
  7971. LONGLONG
  7972. FASTCALL
  7973. ExfInterlockedCompareExchange64(
  7974. IN OUT LONGLONG volatile *Destination,
  7975. IN PLONGLONG ExChange,
  7976. IN PLONGLONG Comperand
  7977. );
  7978. #endif // INTERLOCKED_INTRINSICS || _CROSS_PLATFORM_
  7979. // begin_wdm
  7980. #endif // MIDL_PASS
  7981. #define InterlockedIncrementAcquire InterlockedIncrement
  7982. #define InterlockedIncrementRelease InterlockedIncrement
  7983. #define InterlockedDecrementAcquire InterlockedDecrement
  7984. #define InterlockedDecrementRelease InterlockedDecrement
  7985. #define InterlockedExchangeAcquire64 InterlockedExchange64
  7986. #define InterlockedCompareExchangeAcquire InterlockedCompareExchange
  7987. #define InterlockedCompareExchangeRelease InterlockedCompareExchange
  7988. #define InterlockedCompareExchangeAcquire64 InterlockedCompareExchange64
  7989. #define InterlockedCompareExchangeRelease64 InterlockedCompareExchange64
  7990. #endif // __WINBASE__ && !NONTOSPINTERLOCK
  7991. //
  7992. // Turn these instrinsics off until the compiler can handle them
  7993. //
  7994. #if (_MSC_FULL_VER > 13009037)
  7995. LONG
  7996. _InterlockedOr (
  7997. IN OUT LONG volatile *Target,
  7998. IN LONG Set
  7999. );
  8000. #pragma intrinsic (_InterlockedOr)
  8001. #define InterlockedOr _InterlockedOr
  8002. LONG
  8003. _InterlockedAnd (
  8004. IN OUT LONG volatile *Target,
  8005. IN LONG Set
  8006. );
  8007. #pragma intrinsic (_InterlockedAnd)
  8008. #define InterlockedAnd _InterlockedAnd
  8009. LONG
  8010. _InterlockedXor (
  8011. IN OUT LONG volatile *Target,
  8012. IN LONG Set
  8013. );
  8014. #pragma intrinsic (_InterlockedXor)
  8015. #define InterlockedXor _InterlockedXor
  8016. #else // compiler version
  8017. FORCEINLINE
  8018. LONG
  8019. InterlockedAnd (
  8020. IN OUT LONG volatile *Target,
  8021. LONG Set
  8022. )
  8023. {
  8024. LONG i;
  8025. LONG j;
  8026. j = *Target;
  8027. do {
  8028. i = j;
  8029. j = InterlockedCompareExchange(Target,
  8030. i & Set,
  8031. i);
  8032. } while (i != j);
  8033. return j;
  8034. }
  8035. FORCEINLINE
  8036. LONG
  8037. InterlockedOr (
  8038. IN OUT LONG volatile *Target,
  8039. IN LONG Set
  8040. )
  8041. {
  8042. LONG i;
  8043. LONG j;
  8044. j = *Target;
  8045. do {
  8046. i = j;
  8047. j = InterlockedCompareExchange(Target,
  8048. i | Set,
  8049. i);
  8050. } while (i != j);
  8051. return j;
  8052. }
  8053. #endif // compiler version
  8054. #if !defined(MIDL_PASS) && defined(_M_IX86)
  8055. //
  8056. // i386 function definitions
  8057. //
  8058. // end_wdm
  8059. #if _MSC_VER >= 1200
  8060. #pragma warning(push)
  8061. #endif
  8062. #pragma warning(disable:4035) // re-enable below
  8063. // end_ntddk end_ntosp
  8064. #if NT_UP
  8065. #define _PCR ds:[KIP0PCRADDRESS]
  8066. #else
  8067. #define _PCR fs:[0] // ntddk ntosp
  8068. #endif
  8069. //
  8070. // Get address of current processor block.
  8071. //
  8072. // WARNING: This inline macro can only be used by the kernel or hal
  8073. //
  8074. #define KiPcr() KeGetPcr()
  8075. FORCEINLINE
  8076. PKPCR
  8077. NTAPI
  8078. KeGetPcr(VOID)
  8079. {
  8080. #if NT_UP
  8081. return (PKPCR)KIP0PCRADDRESS;
  8082. #else
  8083. #if (_MSC_FULL_VER >= 13012035)
  8084. return (PKPCR) (ULONG_PTR) __readfsdword (FIELD_OFFSET (KPCR, SelfPcr));
  8085. #else
  8086. __asm { mov eax, _PCR KPCR.SelfPcr }
  8087. #endif
  8088. #endif
  8089. }
  8090. // begin_ntosp
  8091. //
  8092. // Get address of current processor block.
  8093. //
  8094. // WARNING: This inline macro can only be used by the kernel or hal
  8095. //
  8096. FORCEINLINE
  8097. PKPRCB
  8098. NTAPI
  8099. KeGetCurrentPrcb (VOID)
  8100. {
  8101. #if (_MSC_FULL_VER >= 13012035)
  8102. return (PKPRCB) (ULONG_PTR) __readfsdword (FIELD_OFFSET (KPCR, Prcb));
  8103. #else
  8104. __asm { mov eax, _PCR KPCR.Prcb }
  8105. #endif
  8106. }
  8107. // begin_ntddk begin_wdm
  8108. //
  8109. // Get current IRQL.
  8110. //
  8111. // On x86 this function resides in the HAL
  8112. //
  8113. // end_ntddk end_wdm
  8114. #if defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_) || defined(_NTHAL_) || !defined(_APIC_TPR_)
  8115. // begin_ntddk begin_wdm
  8116. NTHALAPI
  8117. KIRQL
  8118. NTAPI
  8119. KeGetCurrentIrql();
  8120. // end_ntddk end_wdm
  8121. #endif
  8122. // begin_ntddk begin_wdm
  8123. // end_wdm
  8124. //
  8125. // Get the current processor number
  8126. //
  8127. FORCEINLINE
  8128. ULONG
  8129. NTAPI
  8130. KeGetCurrentProcessorNumber(VOID)
  8131. {
  8132. #if (_MSC_FULL_VER >= 13012035)
  8133. return (ULONG) __readfsbyte (FIELD_OFFSET (KPCR, Number));
  8134. #else
  8135. __asm { movzx eax, _PCR KPCR.Number }
  8136. #endif
  8137. }
  8138. #if _MSC_VER >= 1200
  8139. #pragma warning(pop)
  8140. #else
  8141. #pragma warning(default:4035)
  8142. #endif
  8143. // begin_wdm
  8144. #endif // !defined(MIDL_PASS) && defined(_M_IX86)
  8145. //++
  8146. //
  8147. // VOID
  8148. // KeMemoryBarrier (
  8149. // VOID
  8150. // )
  8151. //
  8152. // VOID
  8153. // KeMemoryBarrierWithoutFence (
  8154. // VOID
  8155. // )
  8156. //
  8157. //
  8158. // Routine Description:
  8159. //
  8160. // These functions order memory accesses as seen by other processors.
  8161. //
  8162. // Arguments:
  8163. //
  8164. // None.
  8165. //
  8166. // Return Value:
  8167. //
  8168. // None.
  8169. //
  8170. //--
  8171. #ifdef __cplusplus
  8172. extern "C" {
  8173. #endif
  8174. VOID
  8175. _ReadWriteBarrier(
  8176. VOID
  8177. );
  8178. #ifdef __cplusplus
  8179. }
  8180. #endif
  8181. #pragma intrinsic (_ReadWriteBarrier)
  8182. FORCEINLINE
  8183. VOID
  8184. KeMemoryBarrier (
  8185. VOID
  8186. )
  8187. {
  8188. LONG Barrier;
  8189. __asm {
  8190. xchg Barrier, eax
  8191. }
  8192. }
  8193. #define KeMemoryBarrierWithoutFence() _ReadWriteBarrier()
  8194. //
  8195. // Macro to set address of a trap/interrupt handler to IDT
  8196. //
  8197. #define KiSetHandlerAddressToIDT(Vector, HandlerAddress) {\
  8198. UCHAR IDTEntry = HalVectorToIDTEntry(Vector); \
  8199. ULONG Ha = (ULONG)HandlerAddress; \
  8200. KeGetPcr()->IDT[IDTEntry].ExtendedOffset = HIGHWORD(Ha); \
  8201. KeGetPcr()->IDT[IDTEntry].Offset = LOWWORD(Ha); \
  8202. }
  8203. //
  8204. // Macro to return address of a trap/interrupt handler in IDT
  8205. //
  8206. #define KiReturnHandlerAddressFromIDT(Vector) \
  8207. MAKEULONG(KiPcr()->IDT[HalVectorToIDTEntry(Vector)].ExtendedOffset, KiPcr()->IDT[HalVectorToIDTEntry(Vector)].Offset)
  8208. NTKERNELAPI
  8209. VOID
  8210. NTAPI
  8211. KeProfileInterruptWithSource (
  8212. IN struct _KTRAP_FRAME *TrapFrame,
  8213. IN KPROFILE_SOURCE ProfileSource
  8214. );
  8215. // end_ntosp
  8216. VOID
  8217. NTAPI
  8218. KeProfileInterrupt (
  8219. IN KIRQL OldIrql,
  8220. IN KTRAP_FRAME TrapFrame
  8221. );
  8222. VOID
  8223. NTAPI
  8224. KeUpdateRuntime (
  8225. IN KIRQL OldIrql,
  8226. IN KTRAP_FRAME TrapFrame
  8227. );
  8228. VOID
  8229. NTAPI
  8230. KeUpdateSystemTime (
  8231. IN KIRQL OldIrql,
  8232. IN KTRAP_FRAME TrapFrame
  8233. );
  8234. // begin_ntddk begin_wdm begin_ntndis begin_ntosp
  8235. #endif // defined(_X86_)
  8236. // Use the following for kernel mode runtime checks of X86 system architecture
  8237. #ifdef _X86_
  8238. #ifdef IsNEC_98
  8239. #undef IsNEC_98
  8240. #endif
  8241. #ifdef IsNotNEC_98
  8242. #undef IsNotNEC_98
  8243. #endif
  8244. #ifdef SetNEC_98
  8245. #undef SetNEC_98
  8246. #endif
  8247. #ifdef SetNotNEC_98
  8248. #undef SetNotNEC_98
  8249. #endif
  8250. #define IsNEC_98 (SharedUserData->AlternativeArchitecture == NEC98x86)
  8251. #define IsNotNEC_98 (SharedUserData->AlternativeArchitecture != NEC98x86)
  8252. #define SetNEC_98 SharedUserData->AlternativeArchitecture = NEC98x86
  8253. #define SetNotNEC_98 SharedUserData->AlternativeArchitecture = StandardDesign
  8254. #endif
  8255. #if defined(_M_AMD64) && !defined(RC_INVOKED) && !defined(MIDL_PASS)
  8256. //
  8257. // Define intrinsic function to do in's and out's.
  8258. //
  8259. #ifdef __cplusplus
  8260. extern "C" {
  8261. #endif
  8262. UCHAR
  8263. __inbyte (
  8264. IN USHORT Port
  8265. );
  8266. USHORT
  8267. __inword (
  8268. IN USHORT Port
  8269. );
  8270. ULONG
  8271. __indword (
  8272. IN USHORT Port
  8273. );
  8274. VOID
  8275. __outbyte (
  8276. IN USHORT Port,
  8277. IN UCHAR Data
  8278. );
  8279. VOID
  8280. __outword (
  8281. IN USHORT Port,
  8282. IN USHORT Data
  8283. );
  8284. VOID
  8285. __outdword (
  8286. IN USHORT Port,
  8287. IN ULONG Data
  8288. );
  8289. VOID
  8290. __inbytestring (
  8291. IN USHORT Port,
  8292. IN PUCHAR Buffer,
  8293. IN ULONG Count
  8294. );
  8295. VOID
  8296. __inwordstring (
  8297. IN USHORT Port,
  8298. IN PUSHORT Buffer,
  8299. IN ULONG Count
  8300. );
  8301. VOID
  8302. __indwordstring (
  8303. IN USHORT Port,
  8304. IN PULONG Buffer,
  8305. IN ULONG Count
  8306. );
  8307. VOID
  8308. __outbytestring (
  8309. IN USHORT Port,
  8310. IN PUCHAR Buffer,
  8311. IN ULONG Count
  8312. );
  8313. VOID
  8314. __outwordstring (
  8315. IN USHORT Port,
  8316. IN PUSHORT Buffer,
  8317. IN ULONG Count
  8318. );
  8319. VOID
  8320. __outdwordstring (
  8321. IN USHORT Port,
  8322. IN PULONG Buffer,
  8323. IN ULONG Count
  8324. );
  8325. #ifdef __cplusplus
  8326. }
  8327. #endif
  8328. #pragma intrinsic(__inbyte)
  8329. #pragma intrinsic(__inword)
  8330. #pragma intrinsic(__indword)
  8331. #pragma intrinsic(__outbyte)
  8332. #pragma intrinsic(__outword)
  8333. #pragma intrinsic(__outdword)
  8334. #pragma intrinsic(__inbytestring)
  8335. #pragma intrinsic(__inwordstring)
  8336. #pragma intrinsic(__indwordstring)
  8337. #pragma intrinsic(__outbytestring)
  8338. #pragma intrinsic(__outwordstring)
  8339. #pragma intrinsic(__outdwordstring)
  8340. //
  8341. // Interlocked intrinsic functions.
  8342. //
  8343. #define InterlockedAnd _InterlockedAnd
  8344. #define InterlockedOr _InterlockedOr
  8345. #define InterlockedXor _InterlockedXor
  8346. #define InterlockedIncrement _InterlockedIncrement
  8347. #define InterlockedIncrementAcquire InterlockedIncrement
  8348. #define InterlockedIncrementRelease InterlockedIncrement
  8349. #define InterlockedDecrement _InterlockedDecrement
  8350. #define InterlockedDecrementAcquire InterlockedDecrement
  8351. #define InterlockedDecrementRelease InterlockedDecrement
  8352. #define InterlockedAdd _InterlockedAdd
  8353. #define InterlockedExchange _InterlockedExchange
  8354. #define InterlockedExchangeAdd _InterlockedExchangeAdd
  8355. #define InterlockedCompareExchange _InterlockedCompareExchange
  8356. #define InterlockedCompareExchangeAcquire InterlockedCompareExchange
  8357. #define InterlockedCompareExchangeRelease InterlockedCompareExchange
  8358. #define InterlockedAnd64 _InterlockedAnd64
  8359. #define InterlockedOr64 _InterlockedOr64
  8360. #define InterlockedXor64 _InterlockedXor64
  8361. #define InterlockedIncrement64 _InterlockedIncrement64
  8362. #define InterlockedDecrement64 _InterlockedDecrement64
  8363. #define InterlockedAdd64 _InterlockedAdd64
  8364. #define InterlockedExchange64 _InterlockedExchange64
  8365. #define InterlockedExchangeAcquire64 InterlockedExchange64
  8366. #define InterlockedExchangeAdd64 _InterlockedExchangeAdd64
  8367. #define InterlockedCompareExchange64 _InterlockedCompareExchange64
  8368. #define InterlockedCompareExchangeAcquire64 InterlockedCompareExchange64
  8369. #define InterlockedCompareExchangeRelease64 InterlockedCompareExchange64
  8370. #define InterlockedExchangePointer _InterlockedExchangePointer
  8371. #define InterlockedCompareExchangePointer _InterlockedCompareExchangePointer
  8372. #ifdef __cplusplus
  8373. extern "C" {
  8374. #endif
  8375. LONG
  8376. InterlockedAnd (
  8377. IN OUT LONG volatile *Destination,
  8378. IN LONG Value
  8379. );
  8380. LONG
  8381. InterlockedOr (
  8382. IN OUT LONG volatile *Destination,
  8383. IN LONG Value
  8384. );
  8385. LONG
  8386. InterlockedXor (
  8387. IN OUT LONG volatile *Destination,
  8388. IN LONG Value
  8389. );
  8390. LONG64
  8391. InterlockedAnd64 (
  8392. IN OUT LONG64 volatile *Destination,
  8393. IN LONG64 Value
  8394. );
  8395. LONG64
  8396. InterlockedOr64 (
  8397. IN OUT LONG64 volatile *Destination,
  8398. IN LONG64 Value
  8399. );
  8400. LONG64
  8401. InterlockedXor64 (
  8402. IN OUT LONG64 volatile *Destination,
  8403. IN LONG64 Value
  8404. );
  8405. LONG
  8406. InterlockedIncrement(
  8407. IN OUT LONG volatile *Addend
  8408. );
  8409. LONG
  8410. InterlockedDecrement(
  8411. IN OUT LONG volatile *Addend
  8412. );
  8413. LONG
  8414. InterlockedExchange(
  8415. IN OUT LONG volatile *Target,
  8416. IN LONG Value
  8417. );
  8418. LONG
  8419. InterlockedExchangeAdd(
  8420. IN OUT LONG volatile *Addend,
  8421. IN LONG Value
  8422. );
  8423. #if !defined(_X86AMD64_)
  8424. __forceinline
  8425. LONG
  8426. InterlockedAdd(
  8427. IN OUT LONG volatile *Addend,
  8428. IN LONG Value
  8429. )
  8430. {
  8431. return InterlockedExchangeAdd(Addend, Value) + Value;
  8432. }
  8433. #endif
  8434. LONG
  8435. InterlockedCompareExchange (
  8436. IN OUT LONG volatile *Destination,
  8437. IN LONG ExChange,
  8438. IN LONG Comperand
  8439. );
  8440. LONG64
  8441. InterlockedIncrement64(
  8442. IN OUT LONG64 volatile *Addend
  8443. );
  8444. LONG64
  8445. InterlockedDecrement64(
  8446. IN OUT LONG64 volatile *Addend
  8447. );
  8448. LONG64
  8449. InterlockedExchange64(
  8450. IN OUT LONG64 volatile *Target,
  8451. IN LONG64 Value
  8452. );
  8453. LONG64
  8454. InterlockedExchangeAdd64(
  8455. IN OUT LONG64 volatile *Addend,
  8456. IN LONG64 Value
  8457. );
  8458. #if !defined(_X86AMD64_)
  8459. __forceinline
  8460. LONG64
  8461. InterlockedAdd64(
  8462. IN OUT LONG64 volatile *Addend,
  8463. IN LONG64 Value
  8464. )
  8465. {
  8466. return InterlockedExchangeAdd64(Addend, Value) + Value;
  8467. }
  8468. #endif
  8469. LONG64
  8470. InterlockedCompareExchange64 (
  8471. IN OUT LONG64 volatile *Destination,
  8472. IN LONG64 ExChange,
  8473. IN LONG64 Comperand
  8474. );
  8475. PVOID
  8476. InterlockedCompareExchangePointer (
  8477. IN OUT PVOID volatile *Destination,
  8478. IN PVOID Exchange,
  8479. IN PVOID Comperand
  8480. );
  8481. PVOID
  8482. InterlockedExchangePointer(
  8483. IN OUT PVOID volatile *Target,
  8484. IN PVOID Value
  8485. );
  8486. #pragma intrinsic(_InterlockedAnd)
  8487. #pragma intrinsic(_InterlockedOr)
  8488. #pragma intrinsic(_InterlockedXor)
  8489. #pragma intrinsic(_InterlockedIncrement)
  8490. #pragma intrinsic(_InterlockedDecrement)
  8491. #pragma intrinsic(_InterlockedExchange)
  8492. #pragma intrinsic(_InterlockedExchangeAdd)
  8493. #pragma intrinsic(_InterlockedCompareExchange)
  8494. #pragma intrinsic(_InterlockedAnd64)
  8495. #pragma intrinsic(_InterlockedOr64)
  8496. #pragma intrinsic(_InterlockedXor64)
  8497. #pragma intrinsic(_InterlockedIncrement64)
  8498. #pragma intrinsic(_InterlockedDecrement64)
  8499. #pragma intrinsic(_InterlockedExchange64)
  8500. #pragma intrinsic(_InterlockedExchangeAdd64)
  8501. #pragma intrinsic(_InterlockedCompareExchange64)
  8502. #pragma intrinsic(_InterlockedExchangePointer)
  8503. #pragma intrinsic(_InterlockedCompareExchangePointer)
  8504. #ifdef __cplusplus
  8505. }
  8506. #endif
  8507. #endif // defined(_M_AMD64) && !defined(RC_INVOKED) && !defined(MIDL_PASS)
  8508. #if defined(_AMD64_)
  8509. //
  8510. // Types to use to contain PFNs and their counts.
  8511. //
  8512. typedef ULONG PFN_COUNT;
  8513. typedef LONG64 SPFN_NUMBER, *PSPFN_NUMBER;
  8514. typedef ULONG64 PFN_NUMBER, *PPFN_NUMBER;
  8515. //
  8516. // Define maximum size of flush multiple TB request.
  8517. //
  8518. #define FLUSH_MULTIPLE_MAXIMUM 32
  8519. //
  8520. // Indicate that the AMD64 compiler supports the allocate pragmas.
  8521. //
  8522. #define ALLOC_PRAGMA 1
  8523. #define ALLOC_DATA_PRAGMA 1
  8524. #define NORMAL_DISPATCH_LENGTH 106 // ntddk wdm
  8525. #define DISPATCH_LENGTH NORMAL_DISPATCH_LENGTH // ntddk wdm
  8526. // ntddk wdm
  8527. // begin_ntosp
  8528. //
  8529. // Define constants for bits in CR0.
  8530. //
  8531. #define CR0_PE 0x00000001 // protection enable
  8532. #define CR0_MP 0x00000002 // math present
  8533. #define CR0_EM 0x00000004 // emulate math coprocessor
  8534. #define CR0_TS 0x00000008 // task switched
  8535. #define CR0_ET 0x00000010 // extension type (80387)
  8536. #define CR0_NE 0x00000020 // numeric error
  8537. #define CR0_WP 0x00010000 // write protect
  8538. #define CR0_AM 0x00040000 // alignment mask
  8539. #define CR0_NW 0x20000000 // not write-through
  8540. #define CR0_CD 0x40000000 // cache disable
  8541. #define CR0_PG 0x80000000 // paging
  8542. //
  8543. // Define functions to read and write CR0.
  8544. //
  8545. #ifdef __cplusplus
  8546. extern "C" {
  8547. #endif
  8548. #define ReadCR0() __readcr0()
  8549. ULONG64
  8550. __readcr0 (
  8551. VOID
  8552. );
  8553. #define WriteCR0(Data) __writecr0(Data)
  8554. VOID
  8555. __writecr0 (
  8556. IN ULONG64 Data
  8557. );
  8558. #pragma intrinsic(__readcr0)
  8559. #pragma intrinsic(__writecr0)
  8560. //
  8561. // Define functions to read and write CR3.
  8562. //
  8563. #define ReadCR3() __readcr3()
  8564. ULONG64
  8565. __readcr3 (
  8566. VOID
  8567. );
  8568. #define WriteCR3(Data) __writecr3(Data)
  8569. VOID
  8570. __writecr3 (
  8571. IN ULONG64 Data
  8572. );
  8573. #pragma intrinsic(__readcr3)
  8574. #pragma intrinsic(__writecr3)
  8575. //
  8576. // Define constants for bits in CR4.
  8577. //
  8578. #define CR4_VME 0x00000001 // V86 mode extensions
  8579. #define CR4_PVI 0x00000002 // Protected mode virtual interrupts
  8580. #define CR4_TSD 0x00000004 // Time stamp disable
  8581. #define CR4_DE 0x00000008 // Debugging Extensions
  8582. #define CR4_PSE 0x00000010 // Page size extensions
  8583. #define CR4_PAE 0x00000020 // Physical address extensions
  8584. #define CR4_MCE 0x00000040 // Machine check enable
  8585. #define CR4_PGE 0x00000080 // Page global enable
  8586. #define CR4_FXSR 0x00000200 // FXSR used by OS
  8587. #define CR4_XMMEXCPT 0x00000400 // XMMI used by OS
  8588. //
  8589. // Define functions to read and write CR4.
  8590. //
  8591. #define ReadCR4() __readcr4()
  8592. ULONG64
  8593. __readcr4 (
  8594. VOID
  8595. );
  8596. #define WriteCR4(Data) __writecr4(Data)
  8597. VOID
  8598. __writecr4 (
  8599. IN ULONG64 Data
  8600. );
  8601. #pragma intrinsic(__readcr4)
  8602. #pragma intrinsic(__writecr4)
  8603. //
  8604. // Define functions to read and write CR8.
  8605. //
  8606. // CR8 is the APIC TPR register.
  8607. //
  8608. #define ReadCR8() __readcr8()
  8609. ULONG64
  8610. __readcr8 (
  8611. VOID
  8612. );
  8613. #define WriteCR8(Data) __writecr8(Data)
  8614. VOID
  8615. __writecr8 (
  8616. IN ULONG64 Data
  8617. );
  8618. #pragma intrinsic(__readcr8)
  8619. #pragma intrinsic(__writecr8)
  8620. #ifdef __cplusplus
  8621. }
  8622. #endif
  8623. //
  8624. // Interrupt Request Level definitions
  8625. //
  8626. #define PASSIVE_LEVEL 0 // Passive release level
  8627. #define LOW_LEVEL 0 // Lowest interrupt level
  8628. #define APC_LEVEL 1 // APC interrupt level
  8629. #define DISPATCH_LEVEL 2 // Dispatcher level
  8630. #define CLOCK_LEVEL 13 // Interval clock level
  8631. #define IPI_LEVEL 14 // Interprocessor interrupt level
  8632. #define POWER_LEVEL 14 // Power failure level
  8633. #define PROFILE_LEVEL 15 // timer used for profiling.
  8634. #define HIGH_LEVEL 15 // Highest interrupt level
  8635. // end_ntddk end_wdm end_ntosp
  8636. #if defined(NT_UP)
  8637. // synchronization level (UP)
  8638. #define SYNCH_LEVEL DISPATCH_LEVEL
  8639. #else
  8640. // synchronization level (MP)
  8641. #define SYNCH_LEVEL (IPI_LEVEL-2) // ntddk wdm ntosp
  8642. #endif
  8643. #define IRQL_VECTOR_OFFSET 2 // offset from IRQL to vector / 16
  8644. #define KiSynchIrql SYNCH_LEVEL // enable portable code
  8645. //
  8646. // Machine type definitions
  8647. //
  8648. #define MACHINE_TYPE_ISA 0
  8649. #define MACHINE_TYPE_EISA 1
  8650. #define MACHINE_TYPE_MCA 2
  8651. //
  8652. // Define constants used in selector tests.
  8653. //
  8654. // N.B. MODE_MASK and MODE_BIT assumes that all code runs at either ring-0
  8655. // or ring-3 and is used to test the mode. RPL_MASK is used for merging
  8656. // or extracting RPL values.
  8657. //
  8658. #define MODE_BIT 0
  8659. #define MODE_MASK 1 // ntosp
  8660. #define RPL_MASK 3
  8661. //
  8662. // Startup count value for KeStallExecution. This value is used
  8663. // until KiInitializeStallExecution can compute the real one.
  8664. // Pick a value long enough for very fast processors.
  8665. //
  8666. #define INITIAL_STALL_COUNT 100
  8667. //
  8668. // Macro to extract the high word of a long offset
  8669. //
  8670. #define HIGHWORD(l) \
  8671. ((USHORT)(((ULONG)(l)>>16) & 0xffff))
  8672. //
  8673. // Macro to extract the low word of a long offset
  8674. //
  8675. #define LOWWORD(l) \
  8676. ((USHORT)((ULONG)l & 0x0000ffff))
  8677. //
  8678. // Macro to combine two USHORT offsets into a long offset
  8679. //
  8680. #if !defined(MAKEULONG)
  8681. #define MAKEULONG(x, y) \
  8682. (((((ULONG)(x))<<16) & 0xffff0000) | \
  8683. ((ULONG)(y) & 0xffff))
  8684. #endif
  8685. //
  8686. // I/O space read and write macros.
  8687. //
  8688. // The READ/WRITE_REGISTER_* calls manipulate I/O registers in MEMORY space.
  8689. //
  8690. // The READ/WRITE_PORT_* calls manipulate I/O registers in PORT space.
  8691. //
  8692. __forceinline
  8693. UCHAR
  8694. READ_REGISTER_UCHAR (
  8695. volatile UCHAR *Register
  8696. )
  8697. {
  8698. return *Register;
  8699. }
  8700. __forceinline
  8701. USHORT
  8702. READ_REGISTER_USHORT (
  8703. volatile USHORT *Register
  8704. )
  8705. {
  8706. return *Register;
  8707. }
  8708. __forceinline
  8709. ULONG
  8710. READ_REGISTER_ULONG (
  8711. volatile ULONG *Register
  8712. )
  8713. {
  8714. return *Register;
  8715. }
  8716. __forceinline
  8717. VOID
  8718. READ_REGISTER_BUFFER_UCHAR (
  8719. PUCHAR Register,
  8720. PUCHAR Buffer,
  8721. ULONG Count
  8722. )
  8723. {
  8724. __movsb(Buffer, Register, Count);
  8725. return;
  8726. }
  8727. __forceinline
  8728. VOID
  8729. READ_REGISTER_BUFFER_USHORT (
  8730. PUSHORT Register,
  8731. PUSHORT Buffer,
  8732. ULONG Count
  8733. )
  8734. {
  8735. __movsw(Buffer, Register, Count);
  8736. return;
  8737. }
  8738. __forceinline
  8739. VOID
  8740. READ_REGISTER_BUFFER_ULONG (
  8741. PULONG Register,
  8742. PULONG Buffer,
  8743. ULONG Count
  8744. )
  8745. {
  8746. __movsd(Buffer, Register, Count);
  8747. return;
  8748. }
  8749. __forceinline
  8750. VOID
  8751. WRITE_REGISTER_UCHAR (
  8752. PUCHAR Register,
  8753. UCHAR Value
  8754. )
  8755. {
  8756. *Register = Value;
  8757. StoreFence();
  8758. return;
  8759. }
  8760. __forceinline
  8761. VOID
  8762. WRITE_REGISTER_USHORT (
  8763. PUSHORT Register,
  8764. USHORT Value
  8765. )
  8766. {
  8767. *Register = Value;
  8768. StoreFence();
  8769. return;
  8770. }
  8771. __forceinline
  8772. VOID
  8773. WRITE_REGISTER_ULONG (
  8774. PULONG Register,
  8775. ULONG Value
  8776. )
  8777. {
  8778. *Register = Value;
  8779. StoreFence();
  8780. return;
  8781. }
  8782. __forceinline
  8783. VOID
  8784. WRITE_REGISTER_BUFFER_UCHAR (
  8785. PUCHAR Register,
  8786. PUCHAR Buffer,
  8787. ULONG Count
  8788. )
  8789. {
  8790. __movsb(Register, Buffer, Count);
  8791. StoreFence();
  8792. return;
  8793. }
  8794. __forceinline
  8795. VOID
  8796. WRITE_REGISTER_BUFFER_USHORT (
  8797. PUSHORT Register,
  8798. PUSHORT Buffer,
  8799. ULONG Count
  8800. )
  8801. {
  8802. __movsw(Register, Buffer, Count);
  8803. StoreFence();
  8804. return;
  8805. }
  8806. __forceinline
  8807. VOID
  8808. WRITE_REGISTER_BUFFER_ULONG (
  8809. PULONG Register,
  8810. PULONG Buffer,
  8811. ULONG Count
  8812. )
  8813. {
  8814. __movsd(Register, Buffer, Count);
  8815. StoreFence();
  8816. return;
  8817. }
  8818. __forceinline
  8819. UCHAR
  8820. READ_PORT_UCHAR (
  8821. PUCHAR Port
  8822. )
  8823. {
  8824. return __inbyte((USHORT)((ULONG64)Port));
  8825. }
  8826. __forceinline
  8827. USHORT
  8828. READ_PORT_USHORT (
  8829. PUSHORT Port
  8830. )
  8831. {
  8832. return __inword((USHORT)((ULONG64)Port));
  8833. }
  8834. __forceinline
  8835. ULONG
  8836. READ_PORT_ULONG (
  8837. PULONG Port
  8838. )
  8839. {
  8840. return __indword((USHORT)((ULONG64)Port));
  8841. }
  8842. __forceinline
  8843. VOID
  8844. READ_PORT_BUFFER_UCHAR (
  8845. PUCHAR Port,
  8846. PUCHAR Buffer,
  8847. ULONG Count
  8848. )
  8849. {
  8850. __inbytestring((USHORT)((ULONG64)Port), Buffer, Count);
  8851. return;
  8852. }
  8853. __forceinline
  8854. VOID
  8855. READ_PORT_BUFFER_USHORT (
  8856. PUSHORT Port,
  8857. PUSHORT Buffer,
  8858. ULONG Count
  8859. )
  8860. {
  8861. __inwordstring((USHORT)((ULONG64)Port), Buffer, Count);
  8862. return;
  8863. }
  8864. __forceinline
  8865. VOID
  8866. READ_PORT_BUFFER_ULONG (
  8867. PULONG Port,
  8868. PULONG Buffer,
  8869. ULONG Count
  8870. )
  8871. {
  8872. __indwordstring((USHORT)((ULONG64)Port), Buffer, Count);
  8873. return;
  8874. }
  8875. __forceinline
  8876. VOID
  8877. WRITE_PORT_UCHAR (
  8878. PUCHAR Port,
  8879. UCHAR Value
  8880. )
  8881. {
  8882. __outbyte((USHORT)((ULONG64)Port), Value);
  8883. return;
  8884. }
  8885. __forceinline
  8886. VOID
  8887. WRITE_PORT_USHORT (
  8888. PUSHORT Port,
  8889. USHORT Value
  8890. )
  8891. {
  8892. __outword((USHORT)((ULONG64)Port), Value);
  8893. return;
  8894. }
  8895. __forceinline
  8896. VOID
  8897. WRITE_PORT_ULONG (
  8898. PULONG Port,
  8899. ULONG Value
  8900. )
  8901. {
  8902. __outdword((USHORT)((ULONG64)Port), Value);
  8903. return;
  8904. }
  8905. __forceinline
  8906. VOID
  8907. WRITE_PORT_BUFFER_UCHAR (
  8908. PUCHAR Port,
  8909. PUCHAR Buffer,
  8910. ULONG Count
  8911. )
  8912. {
  8913. __outbytestring((USHORT)((ULONG64)Port), Buffer, Count);
  8914. return;
  8915. }
  8916. __forceinline
  8917. VOID
  8918. WRITE_PORT_BUFFER_USHORT (
  8919. PUSHORT Port,
  8920. PUSHORT Buffer,
  8921. ULONG Count
  8922. )
  8923. {
  8924. __outwordstring((USHORT)((ULONG64)Port), Buffer, Count);
  8925. return;
  8926. }
  8927. __forceinline
  8928. VOID
  8929. WRITE_PORT_BUFFER_ULONG (
  8930. PULONG Port,
  8931. PULONG Buffer,
  8932. ULONG Count
  8933. )
  8934. {
  8935. __outdwordstring((USHORT)((ULONG64)Port), Buffer, Count);
  8936. return;
  8937. }
  8938. // end_ntndis
  8939. //
  8940. // Get data cache fill size.
  8941. //
  8942. #if PRAGMA_DEPRECATED_DDK
  8943. #pragma deprecated(KeGetDcacheFillSize) // Use GetDmaAlignment
  8944. #endif
  8945. #define KeGetDcacheFillSize() 1L
  8946. NTKERNELAPI
  8947. VOID
  8948. KeFlushCurrentTb (
  8949. VOID
  8950. );
  8951. #define KeFlushIoBuffers(Mdl, ReadOperation, DmaOperation)
  8952. // end_ntddk end_wdm end_ntndis end_ntosp
  8953. #define KeYieldProcessor()
  8954. //
  8955. // The acquire and release fast lock macros disable and enable interrupts
  8956. // on UP nondebug systems. On MP or debug systems, the spinlock routines
  8957. // are used.
  8958. //
  8959. // N.B. Extreme caution should be observed when using these routines.
  8960. //
  8961. #if defined(_M_AMD64) && !defined(USER_MODE_CODE)
  8962. VOID
  8963. _disable (
  8964. VOID
  8965. );
  8966. VOID
  8967. _enable (
  8968. VOID
  8969. );
  8970. #pragma warning(push)
  8971. #pragma warning(disable:4164)
  8972. #pragma intrinsic(_disable)
  8973. #pragma intrinsic(_enable)
  8974. #pragma warning(pop)
  8975. #endif
  8976. #if defined(NT_UP)
  8977. #define KiAcquireSpinLock(SpinLock)
  8978. #define KiReleaseSpinLock(SpinLock)
  8979. #else
  8980. #define KiAcquireSpinLock(SpinLock) KeAcquireSpinLockAtDpcLevel(SpinLock)
  8981. #define KiReleaseSpinLock(SpinLock) KeReleaseSpinLockFromDpcLevel(SpinLock)
  8982. #endif // defined(NT_UP)
  8983. #define KI_USER_SHARED_DATA 0xFFFFF78000000000UI64
  8984. #define SharedUserData ((KUSER_SHARED_DATA * const)KI_USER_SHARED_DATA)
  8985. #define SharedInterruptTime (KI_USER_SHARED_DATA + 0x8)
  8986. #define SharedSystemTime (KI_USER_SHARED_DATA + 0x14)
  8987. #define SharedTickCount (KI_USER_SHARED_DATA + 0x320)
  8988. #define KeQueryInterruptTime() *((volatile ULONG64 *)(SharedInterruptTime))
  8989. #define KeQuerySystemTime(CurrentCount) \
  8990. *((PULONG64)(CurrentCount)) = *((volatile ULONG64 *)(SharedSystemTime))
  8991. #define KeQueryTickCount(CurrentCount) \
  8992. *((PULONG64)(CurrentCount)) = *((volatile ULONG64 *)(SharedTickCount))
  8993. //
  8994. // AMD64 hardware structures
  8995. //
  8996. // A Page Table Entry on an AMD64 has the following definition.
  8997. //
  8998. #define _HARDWARE_PTE_WORKING_SET_BITS 11
  8999. typedef struct _HARDWARE_PTE {
  9000. ULONG64 Valid : 1;
  9001. ULONG64 Write : 1; // UP version
  9002. ULONG64 Owner : 1;
  9003. ULONG64 WriteThrough : 1;
  9004. ULONG64 CacheDisable : 1;
  9005. ULONG64 Accessed : 1;
  9006. ULONG64 Dirty : 1;
  9007. ULONG64 LargePage : 1;
  9008. ULONG64 Global : 1;
  9009. ULONG64 CopyOnWrite : 1; // software field
  9010. ULONG64 Prototype : 1; // software field
  9011. ULONG64 reserved0 : 1; // software field
  9012. ULONG64 PageFrameNumber : 28;
  9013. ULONG64 reserved1 : 24 - (_HARDWARE_PTE_WORKING_SET_BITS+1);
  9014. ULONG64 SoftwareWsIndex : _HARDWARE_PTE_WORKING_SET_BITS;
  9015. ULONG64 NoExecute : 1;
  9016. } HARDWARE_PTE, *PHARDWARE_PTE;
  9017. //
  9018. // Define macro to initialize directory table base.
  9019. //
  9020. #define INITIALIZE_DIRECTORY_TABLE_BASE(dirbase,pfn) \
  9021. *((PULONG64)(dirbase)) = (((ULONG64)(pfn)) << PAGE_SHIFT)
  9022. //
  9023. // Define Global Descriptor Table (GDT) entry structure and constants.
  9024. //
  9025. // Define descriptor type codes.
  9026. //
  9027. #define TYPE_CODE 0x1A // 11010 = code, read only
  9028. #define TYPE_DATA 0x12 // 10010 = data, read and write
  9029. #define TYPE_TSS64 0x09 // 01001 = task state segment
  9030. //
  9031. // Define descriptor privilege levels for user and system.
  9032. //
  9033. #define DPL_USER 3
  9034. #define DPL_SYSTEM 0
  9035. //
  9036. // Define limit granularity.
  9037. //
  9038. #define GRANULARITY_BYTE 0
  9039. #define GRANULARITY_PAGE 1
  9040. #define SELECTOR_TABLE_INDEX 0x04
  9041. typedef union _KGDTENTRY64 {
  9042. struct {
  9043. USHORT LimitLow;
  9044. USHORT BaseLow;
  9045. union {
  9046. struct {
  9047. UCHAR BaseMiddle;
  9048. UCHAR Flags1;
  9049. UCHAR Flags2;
  9050. UCHAR BaseHigh;
  9051. } Bytes;
  9052. struct {
  9053. ULONG BaseMiddle : 8;
  9054. ULONG Type : 5;
  9055. ULONG Dpl : 2;
  9056. ULONG Present : 1;
  9057. ULONG LimitHigh : 4;
  9058. ULONG System : 1;
  9059. ULONG LongMode : 1;
  9060. ULONG DefaultBig : 1;
  9061. ULONG Granularity : 1;
  9062. ULONG BaseHigh : 8;
  9063. } Bits;
  9064. };
  9065. ULONG BaseUpper;
  9066. ULONG MustBeZero;
  9067. };
  9068. ULONG64 Alignment;
  9069. } KGDTENTRY64, *PKGDTENTRY64;
  9070. //
  9071. // Define Interrupt Descriptor Table (IDT) entry structure and constants.
  9072. //
  9073. typedef union _KIDTENTRY64 {
  9074. struct {
  9075. USHORT OffsetLow;
  9076. USHORT Selector;
  9077. USHORT IstIndex : 3;
  9078. USHORT Reserved0 : 5;
  9079. USHORT Type : 5;
  9080. USHORT Dpl : 2;
  9081. USHORT Present : 1;
  9082. USHORT OffsetMiddle;
  9083. ULONG OffsetHigh;
  9084. ULONG Reserved1;
  9085. };
  9086. ULONG64 Alignment;
  9087. } KIDTENTRY64, *PKIDTENTRY64;
  9088. //
  9089. // Define two union definitions used for parsing addresses into the
  9090. // component fields required by a GDT.
  9091. //
  9092. typedef union _KGDT_BASE {
  9093. struct {
  9094. USHORT BaseLow;
  9095. UCHAR BaseMiddle;
  9096. UCHAR BaseHigh;
  9097. ULONG BaseUpper;
  9098. };
  9099. ULONG64 Base;
  9100. } KGDT_BASE, *PKGDT_BASE;
  9101. C_ASSERT(sizeof(KGDT_BASE) == sizeof(ULONG64));
  9102. typedef union _KGDT_LIMIT {
  9103. struct {
  9104. USHORT LimitLow;
  9105. USHORT LimitHigh : 4;
  9106. USHORT MustBeZero : 12;
  9107. };
  9108. ULONG Limit;
  9109. } KGDT_LIMIT, *PKGDT_LIMIT;
  9110. C_ASSERT(sizeof(KGDT_LIMIT) == sizeof(ULONG));
  9111. //
  9112. // Define Task State Segment (TSS) structure and constants.
  9113. //
  9114. // Task switches are not supported by the AMD64, but a task state segment
  9115. // must be present to define the kernel stack pointer and I/O map base.
  9116. //
  9117. // N.B. This structure is misaligned as per the AMD64 specification.
  9118. //
  9119. // N.B. The size of TSS must be <= 0xDFFF.
  9120. //
  9121. #pragma pack(push, 4)
  9122. typedef struct _KTSS64 {
  9123. ULONG Reserved0;
  9124. ULONG64 Rsp0;
  9125. ULONG64 Rsp1;
  9126. ULONG64 Rsp2;
  9127. //
  9128. // Element 0 of the Ist is reserved
  9129. //
  9130. ULONG64 Ist[8];
  9131. ULONG64 Reserved1;
  9132. USHORT IoMapBase;
  9133. } KTSS64, *PKTSS64;
  9134. #pragma pack(pop)
  9135. C_ASSERT((sizeof(KTSS64) % sizeof(PVOID)) == 0);
  9136. #define TSS_IST_RESERVED 0
  9137. #define TSS_IST_PANIC 1
  9138. #define TSS_IST_MCA 2
  9139. #define IO_ACCESS_MAP_NONE FALSE
  9140. #define KiComputeIopmOffset(Enable) (sizeof(KTSS64))
  9141. // begin_windbgkd
  9142. #if defined(_AMD64_)
  9143. //
  9144. // Define pseudo descriptor structures for both 64- and 32-bit mode.
  9145. //
  9146. typedef struct _KDESCRIPTOR {
  9147. USHORT Pad[3];
  9148. USHORT Limit;
  9149. PVOID Base;
  9150. } KDESCRIPTOR, *PKDESCRIPTOR;
  9151. typedef struct _KDESCRIPTOR32 {
  9152. USHORT Pad[3];
  9153. USHORT Limit;
  9154. ULONG Base;
  9155. } KDESCRIPTOR32, *PKDESCRIPTOR32;
  9156. //
  9157. // Define special kernel registers and the initial MXCSR value.
  9158. //
  9159. typedef struct _KSPECIAL_REGISTERS {
  9160. ULONG64 Cr0;
  9161. ULONG64 Cr2;
  9162. ULONG64 Cr3;
  9163. ULONG64 Cr4;
  9164. ULONG64 KernelDr0;
  9165. ULONG64 KernelDr1;
  9166. ULONG64 KernelDr2;
  9167. ULONG64 KernelDr3;
  9168. ULONG64 KernelDr6;
  9169. ULONG64 KernelDr7;
  9170. KDESCRIPTOR Gdtr;
  9171. KDESCRIPTOR Idtr;
  9172. USHORT Tr;
  9173. USHORT Ldtr;
  9174. ULONG MxCsr;
  9175. ULONG64 DebugControl;
  9176. ULONG64 LastBranchToRip;
  9177. ULONG64 LastBranchFromRip;
  9178. ULONG64 LastExceptionToRip;
  9179. ULONG64 LastExceptionFromRip;
  9180. ULONG64 Cr8;
  9181. ULONG64 MsrGsBase;
  9182. ULONG64 MsrGsSwap;
  9183. ULONG64 MsrStar;
  9184. ULONG64 MsrLStar;
  9185. ULONG64 MsrCStar;
  9186. ULONG64 MsrSyscallMask;
  9187. } KSPECIAL_REGISTERS, *PKSPECIAL_REGISTERS;
  9188. //
  9189. // Define processor state structure.
  9190. //
  9191. typedef struct _KPROCESSOR_STATE {
  9192. KSPECIAL_REGISTERS SpecialRegisters;
  9193. CONTEXT ContextFrame;
  9194. } KPROCESSOR_STATE, *PKPROCESSOR_STATE;
  9195. #endif // _AMD64_
  9196. // end_windbgkd
  9197. //
  9198. // DPC data structure definition.
  9199. //
  9200. typedef struct _KDPC_DATA {
  9201. LIST_ENTRY DpcListHead;
  9202. KSPIN_LOCK DpcLock;
  9203. volatile ULONG DpcQueueDepth;
  9204. ULONG DpcCount;
  9205. } KDPC_DATA, *PKDPC_DATA;
  9206. //
  9207. // Processor Control Block (PRCB)
  9208. //
  9209. #define PRCB_MAJOR_VERSION 1
  9210. #define PRCB_MINOR_VERSION 1
  9211. #define PRCB_BUILD_DEBUG 0x1
  9212. #define PRCB_BUILD_UNIPROCESSOR 0x2
  9213. typedef struct _KPRCB {
  9214. //
  9215. // Start of the architecturally defined section of the PRCB. This section
  9216. // may be directly addressed by vendor/platform specific HAL code and will
  9217. // not change from version to version of NT.
  9218. //
  9219. USHORT MinorVersion;
  9220. USHORT MajorVersion;
  9221. CCHAR Number;
  9222. CCHAR Reserved;
  9223. USHORT BuildType;
  9224. struct _KTHREAD *CurrentThread;
  9225. struct _KTHREAD *NextThread;
  9226. struct _KTHREAD *IdleThread;
  9227. KAFFINITY SetMember;
  9228. KAFFINITY NotSetMember;
  9229. KSPIN_LOCK PrcbLock;
  9230. KPROCESSOR_STATE ProcessorState;
  9231. CCHAR CpuType;
  9232. CCHAR CpuID;
  9233. USHORT CpuStep;
  9234. ULONG PrcbPad00;
  9235. ULONG64 HalReserved[8];
  9236. UCHAR PrcbPad0[104];
  9237. //
  9238. // End of the architecturally defined section of the PRCB.
  9239. //
  9240. } KPRCB, *PKPRCB, *RESTRICTED_POINTER PRKPRCB;
  9241. //
  9242. // Processor Control Region Structure Definition
  9243. //
  9244. #define PCR_MINOR_VERSION 1
  9245. #define PCR_MAJOR_VERSION 1
  9246. typedef struct _KPCR {
  9247. //
  9248. // Start of the architecturally defined section of the PCR. This section
  9249. // may be directly addressed by vendor/platform specific HAL code and will
  9250. // not change from version to version of NT.
  9251. //
  9252. // Certain fields in the TIB are not used in kernel mode. These include the
  9253. // exception list, stack base, stack limit, subsystem TIB, fiber data, and
  9254. // the arbitrary user pointer. Therefore, these fields are overlaid with
  9255. // other data to get better cache locality.
  9256. union {
  9257. NT_TIB NtTib;
  9258. struct {
  9259. union _KGDTENTRY64 *GdtBase;
  9260. struct _KTSS64 *TssBase;
  9261. PVOID PerfGlobalGroupMask;
  9262. struct _KPCR *Self;
  9263. ULONG ContextSwitches;
  9264. ULONG NotUsed;
  9265. KAFFINITY SetMember;
  9266. PVOID Used_Self;
  9267. };
  9268. };
  9269. struct _KPRCB *CurrentPrcb;
  9270. ULONG64 SavedRcx;
  9271. ULONG64 SavedR11;
  9272. KIRQL Irql;
  9273. UCHAR SecondLevelCacheAssociativity;
  9274. UCHAR Number;
  9275. UCHAR Fill0;
  9276. ULONG Irr;
  9277. ULONG IrrActive;
  9278. ULONG Idr;
  9279. USHORT MajorVersion;
  9280. USHORT MinorVersion;
  9281. ULONG StallScaleFactor;
  9282. union _KIDTENTRY64 *IdtBase;
  9283. PVOID Unused1;
  9284. PVOID Unused2;
  9285. // end_ntddk end_ntosp
  9286. ULONG KernelReserved[15];
  9287. ULONG SecondLevelCacheSize;
  9288. ULONG HalReserved[16];
  9289. ULONG MxCsr;
  9290. PVOID KdVersionBlock;
  9291. PVOID Unused3;
  9292. //
  9293. // End of the architecturally defined section of the PCR.
  9294. //
  9295. } KPCR, *PKPCR;
  9296. //
  9297. // Define legacy floating status word bit masks.
  9298. //
  9299. #define FSW_INVALID_OPERATION 0x1
  9300. #define FSW_DENORMAL 0x2
  9301. #define FSW_ZERO_DIVIDE 0x4
  9302. #define FSW_OVERFLOW 0x8
  9303. #define FSW_UNDERFLOW 0x10
  9304. #define FSW_PRECISION 0x20
  9305. #define FSW_STACK_FAULT 0x40
  9306. #define FSW_CONDITION_CODE_0 0x100
  9307. #define FSW_CONDITION_CODE_1 0x200
  9308. #define FSW_CONDITION_CODE_2 0x400
  9309. #define FSW_CONDITION_CODE_3 0x4000
  9310. #define FSW_ERROR_MASK (FSW_INVALID_OPERATION | FSW_DENORMAL | \
  9311. FSW_ZERO_DIVIDE | FSW_OVERFLOW | FSW_UNDERFLOW | \
  9312. FSW_PRECISION)
  9313. //
  9314. // Define legacy floating states.
  9315. //
  9316. #define LEGACY_STATE_UNUSED 0
  9317. #define LEGACY_STATE_SCRUB 1
  9318. #define LEGACY_STATE_SWITCH 2
  9319. //
  9320. // Define MxCsr floating control/status word bit masks.
  9321. //
  9322. // No flush to zero, round to nearest, and all exception masked.
  9323. //
  9324. #define XSW_INVALID_OPERATION 0x1
  9325. #define XSW_DENORMAL 0x2
  9326. #define XSW_ZERO_DIVIDE 0x4
  9327. #define XSW_OVERFLOW 0x8
  9328. #define XSW_UNDERFLOW 0x10
  9329. #define XSW_PRECISION 0x20
  9330. #define XSW_ERROR_MASK (XSW_INVALID_OPERATION | XSW_DENORMAL | \
  9331. XSW_ZERO_DIVIDE | XSW_OVERFLOW | XSW_UNDERFLOW | \
  9332. XSW_PRECISION)
  9333. #define XSW_ERROR_SHIFT 7
  9334. #define XCW_INVALID_OPERATION 0x80
  9335. #define XCW_DENORMAL 0x100
  9336. #define XCW_ZERO_DIVIDE 0x200
  9337. #define XCW_OVERFLOW 0x400
  9338. #define XCW_UNDERFLOW 0x800
  9339. #define XCW_PRECISION 0x1000
  9340. #define XCW_ROUND_CONTROL 0x6000
  9341. #define XCW_FLUSH_ZERO 0x8000
  9342. //
  9343. // Define EFLAG bit masks and shift offsets.
  9344. //
  9345. #define EFLAGS_CF_MASK 0x00000001 // carry flag
  9346. #define EFLAGS_PF_MASK 0x00000004 // parity flag
  9347. #define EFALGS_AF_MASK 0x00000010 // auxiliary carry flag
  9348. #define EFLAGS_ZF_MASK 0x00000040 // zero flag
  9349. #define EFLAGS_SF_MASK 0x00000080 // sign flag
  9350. #define EFLAGS_TF_MASK 0x00000100 // trap flag
  9351. #define EFLAGS_IF_MASK 0x00000200 // interrupt flag
  9352. #define EFLAGS_DF_MASK 0x00000400 // direction flag
  9353. #define EFLAGS_OF_MASK 0x00000800 // overflow flag
  9354. #define EFLAGS_IOPL_MASK 0x00003000 // I/O privilege level
  9355. #define EFLAGS_NT_MASK 0x00004000 // nested task
  9356. #define EFLAGS_RF_MASK 0x00010000 // resume flag
  9357. #define EFLAGS_VM_MASK 0x00020000 // virtual 8086 mode
  9358. #define EFLAGS_AC_MASK 0x00040000 // alignment check
  9359. #define EFLAGS_VIF_MASK 0x00080000 // virtual interrupt flag
  9360. #define EFLAGS_VIP_MASK 0x00100000 // virtual interrupt pending
  9361. #define EFLAGS_ID_MASK 0x00200000 // identification flag
  9362. #define EFLAGS_TF_SHIFT 8 // trap
  9363. #define EFLAGS_IF_SHIFT 9 // interrupt enable
  9364. //
  9365. // Exception frame
  9366. //
  9367. // This frame is established when handling an exception. It provides a place
  9368. // to save all nonvolatile registers. The volatile registers will already
  9369. // have been saved in a trap frame.
  9370. //
  9371. // N.B. The exception frame has a built in exception record capable of
  9372. // storing information for four parameter values. This exception
  9373. // record is used exclusively within the trap handling code.
  9374. //
  9375. #define EXCEPTION_AREA_SIZE 64
  9376. typedef struct _KEXCEPTION_FRAME {
  9377. //
  9378. // Home address for the parameter registers.
  9379. //
  9380. ULONG64 P1Home;
  9381. ULONG64 P2Home;
  9382. ULONG64 P3Home;
  9383. ULONG64 P4Home;
  9384. ULONG64 P5;
  9385. //
  9386. // Kernel callout initial stack value.
  9387. //
  9388. ULONG64 InitialStack;
  9389. //
  9390. // Saved nonvolatile floating registers.
  9391. //
  9392. M128 Xmm6;
  9393. M128 Xmm7;
  9394. M128 Xmm8;
  9395. M128 Xmm9;
  9396. M128 Xmm10;
  9397. M128 Xmm11;
  9398. M128 Xmm12;
  9399. M128 Xmm13;
  9400. M128 Xmm14;
  9401. M128 Xmm15;
  9402. //
  9403. // Kernel callout frame variables.
  9404. //
  9405. ULONG64 TrapFrame;
  9406. ULONG64 CallbackStack;
  9407. ULONG64 OutputBuffer;
  9408. ULONG64 OutputLength;
  9409. //
  9410. // Exception record for exceptions.
  9411. //
  9412. UCHAR ExceptionRecord[EXCEPTION_AREA_SIZE];
  9413. //
  9414. // Saved nonvolatile register - not always saved.
  9415. //
  9416. ULONG64 Fill1;
  9417. ULONG64 Rbp;
  9418. //
  9419. // Saved nonvolatile registers.
  9420. //
  9421. ULONG64 Rbx;
  9422. ULONG64 Rdi;
  9423. ULONG64 Rsi;
  9424. ULONG64 R12;
  9425. ULONG64 R13;
  9426. ULONG64 R14;
  9427. ULONG64 R15;
  9428. //
  9429. // EFLAGS and return address.
  9430. //
  9431. ULONG64 Return;
  9432. } KEXCEPTION_FRAME, *PKEXCEPTION_FRAME;
  9433. // end_ntddk
  9434. #define KEXCEPTION_FRAME_LENGTH sizeof(KEXCEPTION_FRAME)
  9435. C_ASSERT((sizeof(KEXCEPTION_FRAME) & STACK_ROUND) == 0);
  9436. #define EXCEPTION_RECORD_LENGTH \
  9437. ((sizeof(EXCEPTION_RECORD) + STACK_ROUND) & ~STACK_ROUND)
  9438. #if !defined(_X86AMD64_)
  9439. C_ASSERT(EXCEPTION_AREA_SIZE == (FIELD_OFFSET(EXCEPTION_RECORD, ExceptionInformation) + (4 * sizeof(ULONG_PTR))));
  9440. #endif
  9441. //
  9442. // Machine Frame
  9443. //
  9444. // This frame is established by code that trampolines to user mode (e.g. user
  9445. // APC, user callback, dispatch user exception, etc.). The purpose of this
  9446. // frame is to allow unwinding through these callbacks if an exception occurs.
  9447. //
  9448. // N.B. This frame is identical to the frame that is pushed for a trap without
  9449. // an error code and is identical to the hardware part of a trap frame.
  9450. //
  9451. typedef struct _MACHINE_FRAME {
  9452. ULONG64 Rip;
  9453. USHORT SegCs;
  9454. USHORT Fill1[3];
  9455. ULONG EFlags;
  9456. ULONG Fill2;
  9457. ULONG64 Rsp;
  9458. USHORT SegSs;
  9459. USHORT Fill3[3];
  9460. } MACHINE_FRAME, *PMACHINE_FRAME;
  9461. #define MACHINE_FRAME_LENGTH sizeof(MACHINE_FRAME)
  9462. C_ASSERT((sizeof(MACHINE_FRAME) & STACK_ROUND) == 8);
  9463. //
  9464. // Switch Frame
  9465. //
  9466. // This frame is established by the code that switches context from one
  9467. // thread to the next and is used by the thread initialization code to
  9468. // construct a stack that will start the execution of a thread in the
  9469. // thread start up code.
  9470. //
  9471. typedef struct _KSWITCH_FRAME {
  9472. ULONG64 P1Home;
  9473. ULONG64 P2Home;
  9474. ULONG64 P3Home;
  9475. ULONG64 P4Home;
  9476. ULONG64 P5Home;
  9477. ULONG MxCsr;
  9478. KIRQL ApcBypass;
  9479. UCHAR Fill1[3];
  9480. ULONG64 Rbp;
  9481. ULONG64 Return;
  9482. } KSWITCH_FRAME, *PKSWITCH_FRAME;
  9483. #define KSWITCH_FRAME_LENGTH sizeof(KSWITCH_FRAME)
  9484. C_ASSERT((sizeof(KSWITCH_FRAME) & STACK_ROUND) == 0);
  9485. //
  9486. // Start system thread frame.
  9487. //
  9488. // This frame is established by the AMD64 specific thread initialization
  9489. // code. It is used to store the initial context for starting a system
  9490. // thread.
  9491. //
  9492. typedef struct _KSTART_FRAME {
  9493. ULONG64 P1Home;
  9494. ULONG64 P2Home;
  9495. ULONG64 P3Home;
  9496. ULONG64 Return;
  9497. } KSTART_FRAME, *PKSTART_FRAME;
  9498. #define KSTART_FRAME_LENGTH sizeof(KSTART_FRAME)
  9499. C_ASSERT((sizeof(KSTART_FRAME) & STACK_ROUND) == 0);
  9500. // begin_ntddk
  9501. //
  9502. // Trap frame
  9503. //
  9504. // This frame is established when handling a trap. It provides a place to
  9505. // save all volatile registers. The nonvolatile registers are saved in an
  9506. // exception frame or through the normal C calling conventions for saved
  9507. // registers.
  9508. //
  9509. typedef struct _KTRAP_FRAME {
  9510. //
  9511. // Home address for the parameter registers.
  9512. //
  9513. ULONG64 P1Home;
  9514. ULONG64 P2Home;
  9515. ULONG64 P3Home;
  9516. ULONG64 P4Home;
  9517. ULONG64 P5;
  9518. //
  9519. // Previous processor mode (system services only) and previous IRQL
  9520. // (interrupts only).
  9521. //
  9522. KPROCESSOR_MODE PreviousMode;
  9523. KIRQL PreviousIrql;
  9524. //
  9525. // Page fault load/store indicator.
  9526. //
  9527. UCHAR FaultIndicator;
  9528. UCHAR Fill0;
  9529. //
  9530. // Floating point state.
  9531. //
  9532. ULONG MxCsr;
  9533. //
  9534. // Volatile registers.
  9535. //
  9536. // N.B. These registers are only saved on exceptions and interrupts. They
  9537. // are not saved for system calls.
  9538. //
  9539. ULONG64 Rax;
  9540. ULONG64 Rcx;
  9541. ULONG64 Rdx;
  9542. ULONG64 R8;
  9543. ULONG64 R9;
  9544. ULONG64 R10;
  9545. ULONG64 R11;
  9546. ULONG64 Spare0;
  9547. //
  9548. // Volatile floating registers.
  9549. //
  9550. // N.B. These registers are only saved on exceptions and interrupts. They
  9551. // are not saved for system calls.
  9552. //
  9553. M128 Xmm0;
  9554. M128 Xmm1;
  9555. M128 Xmm2;
  9556. M128 Xmm3;
  9557. M128 Xmm4;
  9558. M128 Xmm5;
  9559. //
  9560. // Page fault address.
  9561. //
  9562. ULONG64 FaultAddress;
  9563. //
  9564. // Debug registers.
  9565. //
  9566. ULONG64 Dr0;
  9567. ULONG64 Dr1;
  9568. ULONG64 Dr2;
  9569. ULONG64 Dr3;
  9570. ULONG64 Dr6;
  9571. ULONG64 Dr7;
  9572. //
  9573. // Special debug registers.
  9574. //
  9575. ULONG64 DebugControl;
  9576. ULONG64 LastBranchToRip;
  9577. ULONG64 LastBranchFromRip;
  9578. ULONG64 LastExceptionToRip;
  9579. ULONG64 LastExceptionFromRip;
  9580. //
  9581. // Segment registers
  9582. //
  9583. USHORT SegDs;
  9584. USHORT SegEs;
  9585. USHORT SegFs;
  9586. USHORT SegGs;
  9587. //
  9588. // Previous trap frame address.
  9589. //
  9590. ULONG64 TrapFrame;
  9591. //
  9592. // Saved nonvolatile registers RBX, RDI and RSI. These registers are only
  9593. // saved in system service trap frames.
  9594. //
  9595. ULONG64 Rbx;
  9596. ULONG64 Rdi;
  9597. ULONG64 Rsi;
  9598. //
  9599. // Saved nonvolatile register RBP. This register is used as a frame
  9600. // pointer during trap processing and is saved in all trap frames.
  9601. //
  9602. ULONG64 Rbp;
  9603. //
  9604. // Information pushed by hardware.
  9605. //
  9606. // N.B. The error code is not always pushed by hardware. For those cases
  9607. // where it is not pushed by hardware a dummy error code is allocated
  9608. // on the stack.
  9609. //
  9610. ULONG64 ErrorCode;
  9611. ULONG64 Rip;
  9612. USHORT SegCs;
  9613. USHORT Fill1[3];
  9614. ULONG EFlags;
  9615. ULONG Fill2;
  9616. ULONG64 Rsp;
  9617. USHORT SegSs;
  9618. USHORT Fill3[3];
  9619. } KTRAP_FRAME, *PKTRAP_FRAME;
  9620. // end_ntddk
  9621. #define KTRAP_FRAME_LENGTH sizeof(KTRAP_FRAME)
  9622. C_ASSERT((sizeof(KTRAP_FRAME) & STACK_ROUND) == 0);
  9623. //
  9624. // IPI, profile, update run time, and update system time interrupt routines.
  9625. //
  9626. NTKERNELAPI
  9627. VOID
  9628. KeIpiInterrupt (
  9629. IN PKTRAP_FRAME TrapFrame
  9630. );
  9631. NTKERNELAPI
  9632. VOID
  9633. KeProfileInterruptWithSource (
  9634. IN PKTRAP_FRAME TrapFrame,
  9635. IN KPROFILE_SOURCE ProfileSource
  9636. );
  9637. NTKERNELAPI
  9638. VOID
  9639. KeUpdateRunTime (
  9640. IN PKTRAP_FRAME TrapFrame
  9641. );
  9642. NTKERNELAPI
  9643. VOID
  9644. KeUpdateSystemTime (
  9645. IN PKTRAP_FRAME TrapFrame,
  9646. IN ULONG64 Increment
  9647. );
  9648. //
  9649. // AMD64 Specific portions of mm component.
  9650. //
  9651. // Define the page size for the AMD64 as 4096 (0x1000).
  9652. //
  9653. #define PAGE_SIZE 0x1000
  9654. //
  9655. // Define the number of trailing zeroes in a page aligned virtual address.
  9656. // This is used as the shift count when shifting virtual addresses to
  9657. // virtual page numbers.
  9658. //
  9659. #define PAGE_SHIFT 12L
  9660. // end_ntndis end_wdm
  9661. #define PXE_BASE 0xFFFFF6FB7DBED000UI64
  9662. #define PXE_SELFMAP 0xFFFFF6FB7DBEDF68UI64
  9663. #define PPE_BASE 0xFFFFF6FB7DA00000UI64
  9664. #define PDE_BASE 0xFFFFF6FB40000000UI64
  9665. #define PTE_BASE 0xFFFFF68000000000UI64
  9666. #define PXE_TOP 0xFFFFF6FB7DBEDFFFUI64
  9667. #define PPE_TOP 0xFFFFF6FB7DBFFFFFUI64
  9668. #define PDE_TOP 0xFFFFF6FB7FFFFFFFUI64
  9669. #define PTE_TOP 0xFFFFF6FFFFFFFFFFUI64
  9670. #define PDE_KTBASE_AMD64 PPE_BASE
  9671. #define PTI_SHIFT 12
  9672. #define PDI_SHIFT 21
  9673. #define PPI_SHIFT 30
  9674. #define PXI_SHIFT 39
  9675. #define PTE_PER_PAGE 512
  9676. #define PDE_PER_PAGE 512
  9677. #define PPE_PER_PAGE 512
  9678. #define PXE_PER_PAGE 512
  9679. #define PTI_MASK_AMD64 (PTE_PER_PAGE - 1)
  9680. #define PDI_MASK_AMD64 (PDE_PER_PAGE - 1)
  9681. #define PPI_MASK (PPE_PER_PAGE - 1)
  9682. #define PXI_MASK (PXE_PER_PAGE - 1)
  9683. //
  9684. // Define the highest user address and user probe address.
  9685. //
  9686. extern PVOID *MmHighestUserAddress;
  9687. extern PVOID *MmSystemRangeStart;
  9688. extern ULONG64 *MmUserProbeAddress;
  9689. #define MM_HIGHEST_USER_ADDRESS *MmHighestUserAddress
  9690. #define MM_SYSTEM_RANGE_START *MmSystemRangeStart
  9691. #define MM_USER_PROBE_ADDRESS *MmUserProbeAddress
  9692. //
  9693. // 4MB at the top of VA space is reserved for the HAL's use.
  9694. //
  9695. #define HAL_VA_START 0xFFFFFFFFFFC00000UI64
  9696. #define HAL_VA_SIZE (4 * 1024 * 1024)
  9697. //
  9698. // The lowest user address reserves the low 64k.
  9699. //
  9700. #define MM_LOWEST_USER_ADDRESS (PVOID)0x10000
  9701. //
  9702. // The lowest address for system space.
  9703. //
  9704. #define MM_LOWEST_SYSTEM_ADDRESS (PVOID)0xFFFF080000000000
  9705. // begin_wdm
  9706. #define MmGetProcedureAddress(Address) (Address)
  9707. #define MmLockPagableCodeSection(Address) MmLockPagableDataSection(Address)
  9708. // end_ntddk end_wdm end_ntosp
  9709. //
  9710. // Define virtual base and alternate virtual base of kernel.
  9711. //
  9712. #define KSEG0_BASE 0xFFFFF80000000000UI64
  9713. //
  9714. // Generate kernel segment physical address.
  9715. //
  9716. #define KSEG_ADDRESS(PAGE) ((PVOID)(KSEG0_BASE | ((ULONG_PTR)(PAGE) << PAGE_SHIFT)))
  9717. // begin_ntddk begin_ntosp
  9718. //
  9719. // Intrinsic functions
  9720. //
  9721. // begin_wdm
  9722. #if defined(_M_AMD64) && !defined(RC_INVOKED) && !defined(MIDL_PASS)
  9723. // end_wdm
  9724. //
  9725. // The following routines are provided for backward compatibility with old
  9726. // code. They are no longer the preferred way to accomplish these functions.
  9727. //
  9728. #if PRAGMA_DEPRECATED_DDK
  9729. #pragma deprecated(ExInterlockedIncrementLong) // Use InterlockedIncrement
  9730. #pragma deprecated(ExInterlockedDecrementLong) // Use InterlockedDecrement
  9731. #pragma deprecated(ExInterlockedExchangeUlong) // Use InterlockedExchange
  9732. #endif
  9733. #define RESULT_ZERO 0
  9734. #define RESULT_NEGATIVE 1
  9735. #define RESULT_POSITIVE 2
  9736. typedef enum _INTERLOCKED_RESULT {
  9737. ResultNegative = RESULT_NEGATIVE,
  9738. ResultZero = RESULT_ZERO,
  9739. ResultPositive = RESULT_POSITIVE
  9740. } INTERLOCKED_RESULT;
  9741. #define ExInterlockedDecrementLong(Addend, Lock) \
  9742. _ExInterlockedDecrementLong(Addend)
  9743. __forceinline
  9744. LONG
  9745. _ExInterlockedDecrementLong (
  9746. IN OUT PLONG Addend
  9747. )
  9748. {
  9749. LONG Result;
  9750. Result = InterlockedDecrement(Addend);
  9751. if (Result < 0) {
  9752. return ResultNegative;
  9753. } else if (Result > 0) {
  9754. return ResultPositive;
  9755. } else {
  9756. return ResultZero;
  9757. }
  9758. }
  9759. #define ExInterlockedIncrementLong(Addend, Lock) \
  9760. _ExInterlockedIncrementLong(Addend)
  9761. __forceinline
  9762. LONG
  9763. _ExInterlockedIncrementLong (
  9764. IN OUT PLONG Addend
  9765. )
  9766. {
  9767. LONG Result;
  9768. Result = InterlockedIncrement(Addend);
  9769. if (Result < 0) {
  9770. return ResultNegative;
  9771. } else if (Result > 0) {
  9772. return ResultPositive;
  9773. } else {
  9774. return ResultZero;
  9775. }
  9776. }
  9777. #define ExInterlockedExchangeUlong(Target, Value, Lock) \
  9778. _ExInterlockedExchangeUlong(Target, Value)
  9779. __forceinline
  9780. _ExInterlockedExchangeUlong (
  9781. IN OUT PULONG Target,
  9782. IN ULONG Value
  9783. )
  9784. {
  9785. return (ULONG)InterlockedExchange((PLONG)Target, (LONG)Value);
  9786. }
  9787. // begin_wdm
  9788. #endif // defined(_M_AMD64) && !defined(RC_INVOKED) && !defined(MIDL_PASS)
  9789. #if !defined(MIDL_PASS) && defined(_M_AMD64)
  9790. //
  9791. // AMD646 function prototype definitions
  9792. //
  9793. // end_wdm
  9794. // end_ntddk end_ntosp
  9795. //
  9796. // Get address of current processor block.
  9797. //
  9798. __forceinline
  9799. PKPCR
  9800. KeGetPcr (
  9801. VOID
  9802. )
  9803. {
  9804. return (PKPCR)__readgsqword(FIELD_OFFSET(KPCR, Self));
  9805. }
  9806. // begin_ntosp
  9807. //
  9808. // Get address of current processor block.
  9809. //
  9810. __forceinline
  9811. PKPRCB
  9812. KeGetCurrentPrcb (
  9813. VOID
  9814. )
  9815. {
  9816. return (PKPRCB)__readgsqword(FIELD_OFFSET(KPCR, CurrentPrcb));
  9817. }
  9818. // begin_ntddk
  9819. //
  9820. // Get the current processor number
  9821. //
  9822. __forceinline
  9823. ULONG
  9824. KeGetCurrentProcessorNumber (
  9825. VOID
  9826. )
  9827. {
  9828. return (ULONG)__readgsbyte(FIELD_OFFSET(KPCR, Number));
  9829. }
  9830. // begin_wdm
  9831. #endif // !defined(MIDL_PASS) && defined(_M_AMD64)
  9832. //++
  9833. //
  9834. //
  9835. // VOID
  9836. // KeMemoryBarrier (
  9837. // VOID
  9838. // )
  9839. //
  9840. // VOID
  9841. // KeMemoryBarrierWithoutFence (
  9842. // VOID
  9843. // )
  9844. //
  9845. //
  9846. // Routine Description:
  9847. //
  9848. // These functions order memory accesses as seen by other processors.
  9849. //
  9850. // Arguments:
  9851. //
  9852. // None.
  9853. //
  9854. // Return Value:
  9855. //
  9856. // None.
  9857. //
  9858. //--
  9859. #if !defined(_CROSS_PLATFORM_)
  9860. #ifdef __cplusplus
  9861. extern "C" {
  9862. #endif
  9863. VOID
  9864. _ReadWriteBarrier (
  9865. VOID
  9866. );
  9867. #pragma intrinsic(_ReadWriteBarrier)
  9868. #ifdef __cplusplus
  9869. }
  9870. #endif
  9871. #define KeMemoryBarrier() _ReadWriteBarrier()
  9872. #define KeMemoryBarrierWithoutFence() _ReadWriteBarrier()
  9873. #else
  9874. #define KeMemoryBarrier()
  9875. #define KeMemoryBarrierWithoutFence()
  9876. #endif
  9877. //
  9878. // Define inline functions to get and set the handler address in and IDT
  9879. // entry.
  9880. //
  9881. typedef union _KIDT_HANDLER_ADDRESS {
  9882. struct {
  9883. USHORT OffsetLow;
  9884. USHORT OffsetMiddle;
  9885. ULONG OffsetHigh;
  9886. };
  9887. ULONG64 Address;
  9888. } KIDT_HANDLER_ADDRESS, *PKIDT_HANDLER_ADDRESS;
  9889. #define KiGetIdtFromVector(Vector) \
  9890. &KeGetPcr()->IdtBase[HalVectorToIDTEntry(Vector)]
  9891. #define KeGetIdtHandlerAddress(Vector,Addr) { \
  9892. KIDT_HANDLER_ADDRESS Handler; \
  9893. PKIDTENTRY64 Idt; \
  9894. \
  9895. Idt = KiGetIdtFromVector(Vector); \
  9896. Handler.OffsetLow = Idt->OffsetLow; \
  9897. Handler.OffsetMiddle = Idt->OffsetMiddle; \
  9898. Handler.OffsetHigh = Idt->OffsetHigh; \
  9899. *(Addr) = (PVOID)(Handler.Address); \
  9900. }
  9901. #define KeSetIdtHandlerAddress(Vector,Addr) { \
  9902. KIDT_HANDLER_ADDRESS Handler; \
  9903. PKIDTENTRY64 Idt; \
  9904. \
  9905. Idt = KiGetIdtFromVector(Vector); \
  9906. Handler.Address = (ULONG64)(Addr); \
  9907. Idt->OffsetLow = Handler.OffsetLow; \
  9908. Idt->OffsetMiddle = Handler.OffsetMiddle; \
  9909. Idt->OffsetHigh = Handler.OffsetHigh; \
  9910. }
  9911. #endif // defined(_AMD64_)
  9912. #if defined(_AMD64_) && !defined(MIDL_PASS)
  9913. __forceinline
  9914. KIRQL
  9915. KeGetCurrentIrql (
  9916. VOID
  9917. )
  9918. /*++
  9919. Routine Description:
  9920. This function return the current IRQL.
  9921. Arguments:
  9922. None.
  9923. Return Value:
  9924. The current IRQL is returned as the function value.
  9925. --*/
  9926. {
  9927. return (KIRQL)ReadCR8();
  9928. }
  9929. __forceinline
  9930. VOID
  9931. KeLowerIrql (
  9932. IN KIRQL NewIrql
  9933. )
  9934. /*++
  9935. Routine Description:
  9936. This function lowers the IRQL to the specified value.
  9937. Arguments:
  9938. NewIrql - Supplies the new IRQL value.
  9939. Return Value:
  9940. None.
  9941. --*/
  9942. {
  9943. ASSERT(KeGetCurrentIrql() >= NewIrql);
  9944. WriteCR8(NewIrql);
  9945. return;
  9946. }
  9947. #define KeRaiseIrql(a,b) *(b) = KfRaiseIrql(a)
  9948. __forceinline
  9949. KIRQL
  9950. KfRaiseIrql (
  9951. IN KIRQL NewIrql
  9952. )
  9953. /*++
  9954. Routine Description:
  9955. This function raises the current IRQL to the specified value and returns
  9956. the previous IRQL.
  9957. Arguments:
  9958. NewIrql (cl) - Supplies the new IRQL value.
  9959. Return Value:
  9960. The previous IRQL is retured as the function value.
  9961. --*/
  9962. {
  9963. KIRQL OldIrql;
  9964. OldIrql = KeGetCurrentIrql();
  9965. ASSERT(OldIrql <= NewIrql);
  9966. WriteCR8(NewIrql);
  9967. return OldIrql;
  9968. }
  9969. __forceinline
  9970. KIRQL
  9971. KeRaiseIrqlToDpcLevel (
  9972. VOID
  9973. )
  9974. /*++
  9975. Routine Description:
  9976. This function raises the current IRQL to DPC_LEVEL and returns the
  9977. previous IRQL.
  9978. Arguments:
  9979. None.
  9980. Return Value:
  9981. The previous IRQL is retured as the function value.
  9982. --*/
  9983. {
  9984. KIRQL OldIrql;
  9985. OldIrql = KeGetCurrentIrql();
  9986. ASSERT(OldIrql <= DISPATCH_LEVEL);
  9987. WriteCR8(DISPATCH_LEVEL);
  9988. return OldIrql;
  9989. }
  9990. __forceinline
  9991. KIRQL
  9992. KeRaiseIrqlToSynchLevel (
  9993. VOID
  9994. )
  9995. /*++
  9996. Routine Description:
  9997. This function raises the current IRQL to SYNCH_LEVEL and returns the
  9998. previous IRQL.
  9999. Arguments:
  10000. Return Value:
  10001. The previous IRQL is retured as the function value.
  10002. --*/
  10003. {
  10004. KIRQL OldIrql;
  10005. OldIrql = KeGetCurrentIrql();
  10006. ASSERT(OldIrql <= SYNCH_LEVEL);
  10007. WriteCR8(SYNCH_LEVEL);
  10008. return OldIrql;
  10009. }
  10010. #endif // defined(_AMD64_) && !defined(MIDL_PASS)
  10011. #if defined(_AMD64_)
  10012. //
  10013. // Structure to aid in booting secondary processors
  10014. //
  10015. #pragma pack(push,2)
  10016. typedef struct _FAR_JMP_16 {
  10017. UCHAR OpCode; // = 0xe9
  10018. USHORT Offset;
  10019. } FAR_JMP_16;
  10020. typedef struct _FAR_TARGET_32 {
  10021. ULONG Offset;
  10022. USHORT Selector;
  10023. } FAR_TARGET_32;
  10024. typedef struct _PSEUDO_DESCRIPTOR_32 {
  10025. USHORT Limit;
  10026. ULONG Base;
  10027. } PSEUDO_DESCRIPTOR_32;
  10028. #pragma pack(pop)
  10029. #define PSB_GDT32_NULL 0 * 16
  10030. #define PSB_GDT32_CODE64 1 * 16
  10031. #define PSB_GDT32_DATA32 2 * 16
  10032. #define PSB_GDT32_CODE32 3 * 16
  10033. #define PSB_GDT32_MAX 3
  10034. typedef struct _PROCESSOR_START_BLOCK *PPROCESSOR_START_BLOCK;
  10035. typedef struct _PROCESSOR_START_BLOCK {
  10036. //
  10037. // The block starts with a jmp instruction to the end of the block
  10038. //
  10039. FAR_JMP_16 Jmp;
  10040. //
  10041. // Completion flag is set to non-zero when the target processor has
  10042. // started
  10043. //
  10044. ULONG CompletionFlag;
  10045. //
  10046. // Pseudo descriptors for GDT and IDT.
  10047. //
  10048. PSEUDO_DESCRIPTOR_32 Gdt32;
  10049. PSEUDO_DESCRIPTOR_32 Idt32;
  10050. //
  10051. // The temporary 32-bit GDT itself resides here.
  10052. //
  10053. KGDTENTRY64 Gdt[PSB_GDT32_MAX + 1];
  10054. //
  10055. // Physical address of the 64-bit top-level identity-mapped page table.
  10056. //
  10057. ULONG64 TiledCr3;
  10058. //
  10059. // Far jump target from Rm to Pm code
  10060. //
  10061. FAR_TARGET_32 PmTarget;
  10062. //
  10063. // Far jump target from Pm to Lm code
  10064. //
  10065. FAR_TARGET_32 LmIdentityTarget;
  10066. //
  10067. // Address of LmTarget
  10068. //
  10069. PVOID LmTarget;
  10070. //
  10071. // Linear address of this structure
  10072. //
  10073. PPROCESSOR_START_BLOCK SelfMap;
  10074. //
  10075. // Contents of the PAT msr
  10076. //
  10077. ULONG64 MsrPat;
  10078. //
  10079. // Initial processor state for the processor to be started
  10080. //
  10081. KPROCESSOR_STATE ProcessorState;
  10082. } PROCESSOR_START_BLOCK;
  10083. //
  10084. // AMD64 functions for special instructions
  10085. //
  10086. typedef struct _CPU_INFO {
  10087. ULONG Eax;
  10088. ULONG Ebx;
  10089. ULONG Ecx;
  10090. ULONG Edx;
  10091. } CPU_INFO, *PCPU_INFO;
  10092. VOID
  10093. KiCpuId (
  10094. ULONG Function,
  10095. PCPU_INFO CpuInfo
  10096. );
  10097. //
  10098. // Define read/write MSR functions and register definitions.
  10099. //
  10100. #define MSR_TSC 0x10 // time stamp counter
  10101. #define MSR_PAT 0x277 // page attributes table
  10102. #define MSR_MCG_CAP 0x179 // machine check capabilities
  10103. #define MSR_MCG_STATUS 0x17a // machine check status
  10104. #define MSR_MCG_CTL 0x17b // machine check control
  10105. #define MSR_MC0_CTL 0x400 // machine check control, status,
  10106. #define MSR_MC0_STATUS 0x401 // address, and miscellaneous
  10107. #define MSR_MC0_ADDR 0x402 // registers for machine check
  10108. #define MSR_MC0_MISC 0x403 // sources
  10109. #define MSR_EFER 0xc0000080 // extended function enable register
  10110. #define MSR_STAR 0xc0000081 // system call selectors
  10111. #define MSR_LSTAR 0xc0000082 // system call 64-bit entry
  10112. #define MSR_CSTAR 0xc0000083 // system call 32-bit entry
  10113. #define MSR_SYSCALL_MASK 0xc0000084 // system call flags mask
  10114. #define MSR_FS_BASE 0xc0000100 // fs long mode base address register
  10115. #define MSR_GS_BASE 0xc0000101 // gs long mode base address register
  10116. #define MSR_GS_SWAP 0xc0000102 // gs long mode swap GS base register
  10117. #define MSR_PERF_EVT_SEL0 0xc0010000 // performance event select registers
  10118. #define MSR_PERF_EVT_SEL1 0xc0010001 //
  10119. #define MSR_PERF_EVT_SEL2 0xc0010002 //
  10120. #define MSR_PERF_EVT_SEL3 0xc0010003 //
  10121. #define MSR_PERF_CTR0 0xc0010004 // performance counter registers
  10122. #define MSR_PERF_CTR1 0xc0010005 //
  10123. #define MSR_PERF_CTR2 0xc0010006 //
  10124. #define MSR_PERF_CTR3 0xc0010007 //
  10125. //
  10126. // Flags within MSR_EFER
  10127. //
  10128. #define MSR_SCE 0x00000001 // system call enable
  10129. #define MSR_LME 0x00000100 // long mode enable
  10130. #define MSR_LMA 0x00000400 // long mode active
  10131. #define MSR_NXE 0x00000800 // no execute enable
  10132. //
  10133. // Page attributes table.
  10134. //
  10135. #define PAT_TYPE_STRONG_UC 0 // uncacheable/strongly ordered
  10136. #define PAT_TYPE_USWC 1 // write combining/weakly ordered
  10137. #define PAT_TYPE_WT 4 // write through
  10138. #define PAT_TYPE_WP 5 // write protected
  10139. #define PAT_TYPE_WB 6 // write back
  10140. #define PAT_TYPE_WEAK_UC 7 // uncacheable/weakly ordered
  10141. //
  10142. // Page attributes table structure.
  10143. //
  10144. typedef union _PAT_ATTRIBUTES {
  10145. struct {
  10146. UCHAR Pat[8];
  10147. } hw;
  10148. ULONG64 QuadPart;
  10149. } PAT_ATTRIBUTES, *PPAT_ATTRIBUTES;
  10150. #define ReadMSR(Msr) __readmsr(Msr)
  10151. ULONG64
  10152. __readmsr (
  10153. IN ULONG Msr
  10154. );
  10155. #define WriteMSR(Msr, Data) __writemsr(Msr, Data)
  10156. VOID
  10157. __writemsr (
  10158. IN ULONG Msr,
  10159. IN ULONG64 Value
  10160. );
  10161. #define InvalidatePage(Page) __invlpg(Page)
  10162. VOID
  10163. __invlpg (
  10164. IN PVOID Page
  10165. );
  10166. #define WritebackInvalidate() __wbinvd()
  10167. VOID
  10168. __wbinvd (
  10169. VOID
  10170. );
  10171. #pragma intrinsic(__readmsr)
  10172. #pragma intrinsic(__writemsr)
  10173. #pragma intrinsic(__invlpg)
  10174. #pragma intrinsic(__wbinvd)
  10175. #endif // _AMD64_
  10176. #if defined(_IA64_)
  10177. //
  10178. // Types to use to contain PFNs and their counts.
  10179. //
  10180. typedef ULONG PFN_COUNT;
  10181. typedef LONG_PTR SPFN_NUMBER, *PSPFN_NUMBER;
  10182. typedef ULONG_PTR PFN_NUMBER, *PPFN_NUMBER;
  10183. //
  10184. // Indicate that the IA64 compiler supports the pragma textout construct.
  10185. //
  10186. #define ALLOC_PRAGMA 1
  10187. //
  10188. // Define intrinsic calls and their prototypes
  10189. //
  10190. #include "ia64reg.h"
  10191. #ifdef __cplusplus
  10192. extern "C" {
  10193. #endif
  10194. unsigned __int64 __getReg (int);
  10195. void __setReg (int, unsigned __int64);
  10196. void __isrlz (void);
  10197. void __dsrlz (void);
  10198. void __fwb (void);
  10199. void __mf (void);
  10200. void __mfa (void);
  10201. void __synci (void);
  10202. __int64 __thash (__int64);
  10203. __int64 __ttag (__int64);
  10204. void __ptcl (__int64, __int64);
  10205. void __ptcg (__int64, __int64);
  10206. void __ptcga (__int64, __int64);
  10207. void __ptri (__int64, __int64);
  10208. void __ptrd (__int64, __int64);
  10209. void __invalat (void);
  10210. void __break (int);
  10211. void __fc (__int64);
  10212. void __fci (__int64);
  10213. void __sum (int);
  10214. void __rsm (int);
  10215. void _ReleaseSpinLock( unsigned __int64 *);
  10216. void __yield();
  10217. void __lfetch(int, void const *);
  10218. void __lfetchfault(int, void const *);
  10219. #ifdef _M_IA64
  10220. #pragma intrinsic (__getReg)
  10221. #pragma intrinsic (__setReg)
  10222. #pragma intrinsic (__isrlz)
  10223. #pragma intrinsic (__dsrlz)
  10224. #pragma intrinsic (__fwb)
  10225. #pragma intrinsic (__mf)
  10226. #pragma intrinsic (__mfa)
  10227. #pragma intrinsic (__synci)
  10228. #pragma intrinsic (__thash)
  10229. #pragma intrinsic (__ttag)
  10230. #pragma intrinsic (__ptcl)
  10231. #pragma intrinsic (__ptcg)
  10232. #pragma intrinsic (__ptcga)
  10233. #pragma intrinsic (__ptri)
  10234. #pragma intrinsic (__ptrd)
  10235. #pragma intrinsic (__invalat)
  10236. #pragma intrinsic (__break)
  10237. #pragma intrinsic (__fc)
  10238. #pragma intrinsic (__fci)
  10239. #pragma intrinsic (__sum)
  10240. #pragma intrinsic (__rsm)
  10241. #pragma intrinsic (_ReleaseSpinLock)
  10242. #pragma intrinsic (__yield)
  10243. #pragma intrinsic (__lfetch)
  10244. #pragma intrinsic (__lfetchfault)
  10245. #endif // _M_IA64
  10246. #ifdef __cplusplus
  10247. }
  10248. #endif
  10249. // end_ntndis
  10250. //
  10251. // Define length of interrupt vector table.
  10252. //
  10253. #define MAXIMUM_VECTOR 256
  10254. // end_wdm
  10255. //
  10256. // IA64 specific interlocked operation result values.
  10257. //
  10258. #define RESULT_ZERO 0
  10259. #define RESULT_NEGATIVE 1
  10260. #define RESULT_POSITIVE 2
  10261. //
  10262. // Interlocked result type is portable, but its values are machine specific.
  10263. // Constants for values are in i386.h, mips.h, etc.
  10264. //
  10265. typedef enum _INTERLOCKED_RESULT {
  10266. ResultNegative = RESULT_NEGATIVE,
  10267. ResultZero = RESULT_ZERO,
  10268. ResultPositive = RESULT_POSITIVE
  10269. } INTERLOCKED_RESULT;
  10270. //
  10271. // Convert portable interlock interfaces to architecture specific interfaces.
  10272. //
  10273. #if PRAGMA_DEPRECATED_DDK
  10274. #pragma deprecated(ExInterlockedIncrementLong) // Use InterlockedIncrement
  10275. #pragma deprecated(ExInterlockedDecrementLong) // Use InterlockedDecrement
  10276. #pragma deprecated(ExInterlockedExchangeUlong) // Use InterlockedExchange
  10277. #endif
  10278. #define ExInterlockedIncrementLong(Addend, Lock) \
  10279. ExIa64InterlockedIncrementLong(Addend)
  10280. #define ExInterlockedDecrementLong(Addend, Lock) \
  10281. ExIa64InterlockedDecrementLong(Addend)
  10282. #define ExInterlockedExchangeUlong(Target, Value, Lock) \
  10283. ExIa64InterlockedExchangeUlong(Target, Value)
  10284. NTKERNELAPI
  10285. INTERLOCKED_RESULT
  10286. ExIa64InterlockedIncrementLong (
  10287. IN PLONG Addend
  10288. );
  10289. NTKERNELAPI
  10290. INTERLOCKED_RESULT
  10291. ExIa64InterlockedDecrementLong (
  10292. IN PLONG Addend
  10293. );
  10294. NTKERNELAPI
  10295. ULONG
  10296. ExIa64InterlockedExchangeUlong (
  10297. IN PULONG Target,
  10298. IN ULONG Value
  10299. );
  10300. // begin_wdm
  10301. //
  10302. // IA64 Interrupt Definitions.
  10303. //
  10304. //
  10305. // Define length of interrupt object dispatch code in longwords.
  10306. //
  10307. #define DISPATCH_LENGTH 2*2 // Length of dispatch code template in 32-bit words
  10308. // Begin of a block of definitions that must be synchronized with kxia64.h.
  10309. //
  10310. //
  10311. // Define Interrupt Request Levels.
  10312. //
  10313. #define PASSIVE_LEVEL 0 // Passive release level
  10314. #define LOW_LEVEL 0 // Lowest interrupt level
  10315. #define APC_LEVEL 1 // APC interrupt level
  10316. #define DISPATCH_LEVEL 2 // Dispatcher level
  10317. #define CMC_LEVEL 3 // Correctable machine check level
  10318. #define DEVICE_LEVEL_BASE 4 // 4 - 11 - Device IRQLs
  10319. #define PC_LEVEL 12 // Performance Counter IRQL
  10320. #define IPI_LEVEL 14 // IPI IRQL
  10321. #define CLOCK_LEVEL 13 // Clock Timer IRQL
  10322. #define POWER_LEVEL 15 // Power failure level
  10323. #define PROFILE_LEVEL 15 // Profiling level
  10324. #define HIGH_LEVEL 15 // Highest interrupt level
  10325. // end_ntddk end_wdm end_ntosp
  10326. #if defined(NT_UP)
  10327. #define SYNCH_LEVEL DISPATCH_LEVEL // Synchronization level - UP
  10328. #else
  10329. #define SYNCH_LEVEL (IPI_LEVEL-2) // Synchronization level - MP
  10330. #endif
  10331. //
  10332. // Define profile intervals.
  10333. //
  10334. #define DEFAULT_PROFILE_COUNT 0x40000000 // ~= 20 seconds @50mhz
  10335. #define DEFAULT_PROFILE_INTERVAL (10 * 1000 * 10) // 10 milliseconds
  10336. #define MAXIMUM_PROFILE_INTERVAL (10 * 1000 * 1000) // 1 second
  10337. #define MINIMUM_PROFILE_INTERVAL (10 * 500) // 500 microseconds
  10338. #if defined(_M_IA64) && !defined(RC_INVOKED)
  10339. #define InterlockedAdd _InterlockedAdd
  10340. #define InterlockedIncrement _InterlockedIncrement
  10341. #define InterlockedIncrementAcquire _InterlockedIncrement_acq
  10342. #define InterlockedIncrementRelease _InterlockedIncrement_rel
  10343. #define InterlockedDecrement _InterlockedDecrement
  10344. #define InterlockedDecrementAcquire _InterlockedDecrement_acq
  10345. #define InterlockedDecrementRelease _InterlockedDecrement_rel
  10346. #define InterlockedExchange _InterlockedExchange
  10347. #define InterlockedExchangeAdd _InterlockedExchangeAdd
  10348. #define InterlockedAdd64 _InterlockedAdd64
  10349. #define InterlockedIncrement64 _InterlockedIncrement64
  10350. #define InterlockedDecrement64 _InterlockedDecrement64
  10351. #define InterlockedExchange64 _InterlockedExchange64
  10352. #define InterlockedExchangeAcquire64 _InterlockedExchange64_acq
  10353. #define InterlockedExchangeAdd64 _InterlockedExchangeAdd64
  10354. #define InterlockedCompareExchange64 _InterlockedCompareExchange64
  10355. #define InterlockedCompareExchangeAcquire64 _InterlockedCompareExchange64_acq
  10356. #define InterlockedCompareExchangeRelease64 _InterlockedCompareExchange64_rel
  10357. #define InterlockedCompareExchange _InterlockedCompareExchange
  10358. #define InterlockedCompareExchangeAcquire _InterlockedCompareExchange_acq
  10359. #define InterlockedCompareExchangeRelease _InterlockedCompareExchange_rel
  10360. #define InterlockedExchangePointer _InterlockedExchangePointer
  10361. #define InterlockedCompareExchangePointer _InterlockedCompareExchangePointer
  10362. #ifdef __cplusplus
  10363. extern "C" {
  10364. #endif
  10365. LONG
  10366. __cdecl
  10367. InterlockedAdd (
  10368. LONG volatile *Addend,
  10369. LONG Value
  10370. );
  10371. LONGLONG
  10372. __cdecl
  10373. InterlockedAdd64 (
  10374. LONGLONG volatile *Addend,
  10375. LONGLONG Value
  10376. );
  10377. LONG
  10378. __cdecl
  10379. InterlockedIncrement(
  10380. IN OUT LONG volatile *Addend
  10381. );
  10382. LONG
  10383. __cdecl
  10384. InterlockedDecrement(
  10385. IN OUT LONG volatile *Addend
  10386. );
  10387. LONG
  10388. __cdecl
  10389. InterlockedIncrementAcquire(
  10390. IN OUT LONG volatile *Addend
  10391. );
  10392. LONG
  10393. __cdecl
  10394. InterlockedDecrementAcquire(
  10395. IN OUT LONG volatile *Addend
  10396. );
  10397. LONG
  10398. __cdecl
  10399. InterlockedIncrementRelease(
  10400. IN OUT LONG volatile *Addend
  10401. );
  10402. LONG
  10403. __cdecl
  10404. InterlockedDecrementRelease(
  10405. IN OUT LONG volatile *Addend
  10406. );
  10407. LONG
  10408. __cdecl
  10409. InterlockedExchange(
  10410. IN OUT LONG volatile *Target,
  10411. IN LONG Value
  10412. );
  10413. LONG
  10414. __cdecl
  10415. InterlockedExchangeAdd(
  10416. IN OUT LONG volatile *Addend,
  10417. IN LONG Value
  10418. );
  10419. LONG
  10420. __cdecl
  10421. InterlockedCompareExchange (
  10422. IN OUT LONG volatile *Destination,
  10423. IN LONG ExChange,
  10424. IN LONG Comperand
  10425. );
  10426. LONG
  10427. __cdecl
  10428. InterlockedCompareExchangeRelease (
  10429. IN OUT LONG volatile *Destination,
  10430. IN LONG ExChange,
  10431. IN LONG Comperand
  10432. );
  10433. LONG
  10434. __cdecl
  10435. InterlockedCompareExchangeAcquire (
  10436. IN OUT LONG volatile *Destination,
  10437. IN LONG ExChange,
  10438. IN LONG Comperand
  10439. );
  10440. LONGLONG
  10441. __cdecl
  10442. InterlockedIncrement64(
  10443. IN OUT LONGLONG volatile *Addend
  10444. );
  10445. LONGLONG
  10446. __cdecl
  10447. InterlockedDecrement64(
  10448. IN OUT LONGLONG volatile *Addend
  10449. );
  10450. LONGLONG
  10451. __cdecl
  10452. InterlockedExchange64(
  10453. IN OUT LONGLONG volatile *Target,
  10454. IN LONGLONG Value
  10455. );
  10456. LONGLONG
  10457. __cdecl
  10458. InterlockedExchangeAcquire64(
  10459. IN OUT LONGLONG volatile *Target,
  10460. IN LONGLONG Value
  10461. );
  10462. LONGLONG
  10463. __cdecl
  10464. InterlockedExchangeAdd64(
  10465. IN OUT LONGLONG volatile *Addend,
  10466. IN LONGLONG Value
  10467. );
  10468. LONGLONG
  10469. __cdecl
  10470. InterlockedCompareExchange64 (
  10471. IN OUT LONGLONG volatile *Destination,
  10472. IN LONGLONG ExChange,
  10473. IN LONGLONG Comperand
  10474. );
  10475. LONGLONG
  10476. __cdecl
  10477. InterlockedCompareExchangeAcquire64 (
  10478. IN OUT LONGLONG volatile *Destination,
  10479. IN LONGLONG ExChange,
  10480. IN LONGLONG Comperand
  10481. );
  10482. LONGLONG
  10483. __cdecl
  10484. InterlockedCompareExchangeRelease64 (
  10485. IN OUT LONGLONG volatile *Destination,
  10486. IN LONGLONG ExChange,
  10487. IN LONGLONG Comperand
  10488. );
  10489. PVOID
  10490. __cdecl
  10491. InterlockedCompareExchangePointer (
  10492. IN OUT PVOID volatile *Destination,
  10493. IN PVOID Exchange,
  10494. IN PVOID Comperand
  10495. );
  10496. PVOID
  10497. __cdecl
  10498. InterlockedExchangePointer(
  10499. IN OUT PVOID volatile *Target,
  10500. IN PVOID Value
  10501. );
  10502. #if !defined (InterlockedAnd64)
  10503. #define InterlockedAnd64 InterlockedAnd64_Inline
  10504. LONGLONG
  10505. FORCEINLINE
  10506. InterlockedAnd64_Inline (
  10507. IN OUT LONGLONG volatile *Destination,
  10508. IN LONGLONG Value
  10509. )
  10510. {
  10511. LONGLONG Old;
  10512. do {
  10513. Old = *Destination;
  10514. } while (InterlockedCompareExchange64(Destination,
  10515. Old & Value,
  10516. Old) != Old);
  10517. return Old;
  10518. }
  10519. #endif
  10520. #if !defined (InterlockedOr64)
  10521. #define InterlockedOr64 InterlockedOr64_Inline
  10522. LONGLONG
  10523. FORCEINLINE
  10524. InterlockedOr64_Inline (
  10525. IN OUT LONGLONG volatile *Destination,
  10526. IN LONGLONG Value
  10527. )
  10528. {
  10529. LONGLONG Old;
  10530. do {
  10531. Old = *Destination;
  10532. } while (InterlockedCompareExchange64(Destination,
  10533. Old | Value,
  10534. Old) != Old);
  10535. return Old;
  10536. }
  10537. #endif
  10538. #if !defined (InterlockedXor64)
  10539. #define InterlockedXor64 InterlockedXor64_Inline
  10540. LONGLONG
  10541. FORCEINLINE
  10542. InterlockedXor64_Inline (
  10543. IN OUT LONGLONG volatile *Destination,
  10544. IN LONGLONG Value
  10545. )
  10546. {
  10547. LONGLONG Old;
  10548. do {
  10549. Old = *Destination;
  10550. } while (InterlockedCompareExchange64(Destination,
  10551. Old ^ Value,
  10552. Old) != Old);
  10553. return Old;
  10554. }
  10555. #endif
  10556. #pragma intrinsic(_InterlockedAdd)
  10557. #pragma intrinsic(_InterlockedIncrement)
  10558. #pragma intrinsic(_InterlockedIncrement_acq)
  10559. #pragma intrinsic(_InterlockedIncrement_rel)
  10560. #pragma intrinsic(_InterlockedDecrement)
  10561. #pragma intrinsic(_InterlockedDecrement_acq)
  10562. #pragma intrinsic(_InterlockedDecrement_rel)
  10563. #pragma intrinsic(_InterlockedExchange)
  10564. #pragma intrinsic(_InterlockedCompareExchange)
  10565. #pragma intrinsic(_InterlockedCompareExchange_acq)
  10566. #pragma intrinsic(_InterlockedCompareExchange_rel)
  10567. #pragma intrinsic(_InterlockedExchangeAdd)
  10568. #pragma intrinsic(_InterlockedAdd64)
  10569. #pragma intrinsic(_InterlockedIncrement64)
  10570. #pragma intrinsic(_InterlockedDecrement64)
  10571. #pragma intrinsic(_InterlockedExchange64)
  10572. #pragma intrinsic(_InterlockedExchange64_acq)
  10573. #pragma intrinsic(_InterlockedCompareExchange64)
  10574. #pragma intrinsic(_InterlockedCompareExchange64_acq)
  10575. #pragma intrinsic(_InterlockedCompareExchange64_rel)
  10576. #pragma intrinsic(_InterlockedExchangeAdd64)
  10577. #pragma intrinsic(_InterlockedExchangePointer)
  10578. #pragma intrinsic(_InterlockedCompareExchangePointer)
  10579. #ifdef __cplusplus
  10580. }
  10581. #endif
  10582. #endif // defined(_M_IA64) && !defined(RC_INVOKED)
  10583. // end_wdm
  10584. __forceinline
  10585. LONG
  10586. InterlockedAnd (
  10587. IN OUT LONG volatile *Target,
  10588. LONG Set
  10589. )
  10590. {
  10591. LONG i;
  10592. LONG j;
  10593. j = *Target;
  10594. do {
  10595. i = j;
  10596. j = InterlockedCompareExchange(Target,
  10597. i & Set,
  10598. i);
  10599. } while (i != j);
  10600. return j;
  10601. }
  10602. __forceinline
  10603. LONG
  10604. InterlockedOr (
  10605. IN OUT LONG volatile *Target,
  10606. IN LONG Set
  10607. )
  10608. {
  10609. LONG i;
  10610. LONG j;
  10611. j = *Target;
  10612. do {
  10613. i = j;
  10614. j = InterlockedCompareExchange(Target,
  10615. i | Set,
  10616. i);
  10617. } while (i != j);
  10618. return j;
  10619. }
  10620. __forceinline
  10621. LONG
  10622. InterlockedXor (
  10623. IN OUT LONG volatile *Target,
  10624. IN LONG Set
  10625. )
  10626. {
  10627. LONG i;
  10628. LONG j;
  10629. j = *Target;
  10630. do {
  10631. i = j;
  10632. j = InterlockedCompareExchange(Target,
  10633. i ^ Set,
  10634. i);
  10635. } while (i != j);
  10636. return j;
  10637. }
  10638. //
  10639. // Define interrupt request physical address (maps to HAL virtual address)
  10640. //
  10641. #define INTERRUPT_REQUEST_PHYSICAL_ADDRESS 0xFFE00000
  10642. //
  10643. // Define Address of Processor Control Registers.
  10644. //
  10645. //
  10646. // Define Pointer to Processor Control Registers.
  10647. //
  10648. #define KIPCR ((ULONG_PTR)(KADDRESS_BASE + 0xFFFF0000)) // kernel address of first PCR
  10649. #define PCR ((KPCR * const)KIPCR)
  10650. //
  10651. // Define address for epc system calls
  10652. //
  10653. #define MM_EPC_VA (KADDRESS_BASE + 0xFFA00000)
  10654. //
  10655. // Define Base Address of PAL Mapping
  10656. //
  10657. //
  10658. #define HAL_PAL_VIRTUAL_ADDRESS (KADDRESS_BASE + 0xE0000000)
  10659. //
  10660. // Get address of current processor block.
  10661. //
  10662. #define KeGetCurrentPrcb() PCR->Prcb
  10663. // begin_ntddk begin_wdm begin_ntosp
  10664. #define KI_USER_SHARED_DATA ((ULONG_PTR)(KADDRESS_BASE + 0xFFFE0000))
  10665. #define SharedUserData ((KUSER_SHARED_DATA * const)KI_USER_SHARED_DATA)
  10666. // end_wdm
  10667. //
  10668. // Get address of processor control region.
  10669. //
  10670. #define KeGetPcr() PCR
  10671. //
  10672. // Get address of current kernel thread object.
  10673. //
  10674. #if defined(_M_IA64)
  10675. #define KeGetCurrentThread() PCR->CurrentThread
  10676. #endif
  10677. //
  10678. // Get current processor number.
  10679. //
  10680. #define KeGetCurrentProcessorNumber() ((ULONG)(PCR->Number))
  10681. //
  10682. // Get data cache fill size.
  10683. //
  10684. #if PRAGMA_DEPRECATED_DDK
  10685. #pragma deprecated(KeGetDcacheFillSize) // Use GetDmaAlignment
  10686. #endif
  10687. #define KeGetDcacheFillSize() PCR->DcacheFillSize
  10688. //
  10689. //
  10690. // VOID
  10691. // KeMemoryBarrierWithoutFence (
  10692. // VOID
  10693. // )
  10694. //
  10695. //
  10696. // Routine Description:
  10697. //
  10698. // This function cases ordering of memory acceses generated by the compiler.
  10699. //
  10700. //
  10701. // Arguments:
  10702. //
  10703. // None.
  10704. //
  10705. // Return Value:
  10706. //
  10707. // None.
  10708. //--
  10709. #ifdef __cplusplus
  10710. extern "C" {
  10711. #endif
  10712. VOID
  10713. _ReadWriteBarrier (
  10714. VOID
  10715. );
  10716. #ifdef __cplusplus
  10717. }
  10718. #endif
  10719. #pragma intrinsic(_ReadWriteBarrier)
  10720. #define KeMemoryBarrierWithoutFence() _ReadWriteBarrier()
  10721. //++
  10722. //
  10723. //
  10724. // VOID
  10725. // KeMemoryBarrier (
  10726. // VOID
  10727. // )
  10728. //
  10729. //
  10730. // Routine Description:
  10731. //
  10732. // This function cases ordering of memory acceses as generated by the compiler and
  10733. // as seen by other processors.
  10734. //
  10735. //
  10736. // Arguments:
  10737. //
  10738. // None.
  10739. //
  10740. // Return Value:
  10741. //
  10742. // None.
  10743. //--
  10744. #define KE_MEMORY_BARRIER_REQUIRED
  10745. #define KeMemoryBarrier() {_ReadWriteBarrier();__mf ();_ReadWriteBarrier();}
  10746. //
  10747. // Define the page size
  10748. //
  10749. #define PAGE_SIZE 0x2000
  10750. //
  10751. // Define the number of trailing zeroes in a page aligned virtual address.
  10752. // This is used as the shift count when shifting virtual addresses to
  10753. // virtual page numbers.
  10754. //
  10755. #define PAGE_SHIFT 13L
  10756. //
  10757. // IA64 hardware structures
  10758. //
  10759. //
  10760. // A Page Table Entry on an IA64 has the following definition.
  10761. //
  10762. #define _HARDWARE_PTE_WORKING_SET_BITS 11
  10763. typedef struct _HARDWARE_PTE {
  10764. ULONG64 Valid : 1;
  10765. ULONG64 Rsvd0 : 1;
  10766. ULONG64 Cache : 3;
  10767. ULONG64 Accessed : 1;
  10768. ULONG64 Dirty : 1;
  10769. ULONG64 Owner : 2;
  10770. ULONG64 Execute : 1;
  10771. ULONG64 Write : 1;
  10772. ULONG64 Rsvd1 : PAGE_SHIFT - 12;
  10773. ULONG64 CopyOnWrite : 1;
  10774. ULONG64 PageFrameNumber : 50 - PAGE_SHIFT;
  10775. ULONG64 Rsvd2 : 2;
  10776. ULONG64 Exception : 1;
  10777. ULONGLONG SoftwareWsIndex : _HARDWARE_PTE_WORKING_SET_BITS;
  10778. } HARDWARE_PTE, *PHARDWARE_PTE;
  10779. //
  10780. // Fill TB entry
  10781. //
  10782. // Filling TB entry on demand by VHPT H/W seems faster than done by s/w.
  10783. // Determining I/D side of TLB, disabling/enabling PSR.i and ic bits,
  10784. // serialization, writing to IIP, IDA, IDTR and IITR seem just too much
  10785. // compared to VHPT searching it automatically.
  10786. //
  10787. #define KiVhptEntry(va) ((PVOID)__thash((__int64)va))
  10788. #define KiVhptEntryTag(va) ((ULONGLONG)__ttag((__int64)va))
  10789. #define KiFlushSingleTb(va) \
  10790. __ptcl((__int64)va,PAGE_SHIFT << 2); __isrlz()
  10791. #define KeFillEntryTb( Virtual) \
  10792. KiFlushSingleTb(Virtual);
  10793. #define KiFlushFixedInstTbEx(Invalid, va, pssize) \
  10794. __ptri((__int64)va, (pssize) << 2); __isrlz()
  10795. #define KiFlushFixedInstTb(Invalid, va) \
  10796. KiFlushFixedInstTbEx(Invalid, va, PAGE_SHIFT)
  10797. #define KiFlushFixedDataTbEx(Invalid, va, pssize) \
  10798. __ptrd((__int64)va, (pssize) << 2); __dsrlz()
  10799. #define KiFlushFixedDataTb(Invalid, va) \
  10800. KiFlushFixedDataTbEx(Invalid, va, PAGE_SHIFT)
  10801. NTKERNELAPI
  10802. VOID
  10803. KeFillLargeEntryTb (
  10804. IN HARDWARE_PTE Pte[2],
  10805. IN PVOID Virtual,
  10806. IN ULONG PageSize
  10807. );
  10808. //
  10809. // Fill TB fixed entry
  10810. //
  10811. NTKERNELAPI
  10812. VOID
  10813. KeFillFixedEntryTb (
  10814. IN HARDWARE_PTE Pte[2],
  10815. IN PVOID Virtual,
  10816. IN ULONG PageSize,
  10817. IN ULONG Index
  10818. );
  10819. NTKERNELAPI
  10820. VOID
  10821. KeFillFixedLargeEntryTb (
  10822. IN HARDWARE_PTE Pte[2],
  10823. IN PVOID Virtual,
  10824. IN ULONG PageSize,
  10825. IN ULONG Index
  10826. );
  10827. #define INST_TB_BASE 0x80000000
  10828. #define DATA_TB_BASE 0
  10829. #define INST_TB_KERNEL_INDEX (INST_TB_BASE|ITR_KERNEL_INDEX)
  10830. #define INST_TB_EPC_INDEX (INST_TB_BASE|ITR_EPC_INDEX)
  10831. #define INST_TB_HAL_INDEX (INST_TB_BASE|ITR_HAL_INDEX)
  10832. #define INST_TB_PAL_INDEX (INST_TB_BASE|ITR_PAL_INDEX)
  10833. #define DATA_TB_DRIVER0_INDEX (DATA_TB_BASE|DTR_DRIVER0_INDEX)
  10834. #define DATA_TB_DRIVER1_INDEX (DATA_TB_BASE|DTR_DRIVER1_INDEX)
  10835. #define DATA_TB_KTBASE_INDEX (DATA_TB_BASE|DTR_KTBASE_INDEX)
  10836. #define DATA_TB_UTBASE_INDEX (DATA_TB_BASE|DTR_UTBASE_INDEX)
  10837. #define DATA_TB_STBASE_INDEX (DATA_TB_BASE|DTR_STBASE_INDEX)
  10838. #define DATA_TB_IOPORT_INDEX (DATA_TB_BASE|DTR_IO_PORT_INDEX)
  10839. #define DATA_TB_KTBASE_TMP_INDEX (DATA_TB_BASE|DTR_KTBASE_INDEX_TMP)
  10840. #define DATA_TB_UTBASE_TMP_INDEX (DATA_TB_BASE|DTR_UTBASE_INDEX_TMP)
  10841. #define DATA_TB_HAL_INDEX (DATA_TB_BASE|DTR_HAL_INDEX)
  10842. #define DATA_TB_PAL_INDEX (DATA_TB_BASE|DTR_PAL_INDEX)
  10843. //
  10844. // Fill Inst TB entry
  10845. //
  10846. NTKERNELAPI
  10847. VOID
  10848. KeFillInstEntryTb (
  10849. IN HARDWARE_PTE Pte,
  10850. IN PVOID Virtual
  10851. );
  10852. NTKERNELAPI
  10853. VOID
  10854. KeFlushCurrentTb (
  10855. VOID
  10856. );
  10857. #define KiFlushProcessTb() \
  10858. KeFlushEntireTb(FALSE, TRUE);
  10859. //
  10860. // Get a VHPT entry address
  10861. //
  10862. PVOID
  10863. KiVhptEntry64(
  10864. IN ULONG VirtualPageNumber
  10865. );
  10866. //
  10867. // Get a VHPT entry TAG value
  10868. //
  10869. ULONGLONG
  10870. KiVhptEntryTag64(
  10871. IN ULONG VirtualPageNumber
  10872. );
  10873. //
  10874. // Fill a VHPT entry
  10875. //
  10876. VOID
  10877. KiFillEntryVhpt(
  10878. IN PHARDWARE_PTE PointerPte,
  10879. IN PVOID Virtual
  10880. );
  10881. //
  10882. // Flush the kernel portions of Tb
  10883. //
  10884. VOID
  10885. KeFlushKernelTb(
  10886. IN BOOLEAN AllProcessors
  10887. );
  10888. //
  10889. // Flush the user portions of Tb
  10890. //
  10891. VOID
  10892. KeFlushUserTb(
  10893. IN BOOLEAN AllProcessors
  10894. );
  10895. //
  10896. // Data cache, instruction cache, I/O buffer, and write buffer flush routine
  10897. // prototypes.
  10898. //
  10899. NTKERNELAPI
  10900. VOID
  10901. KeChangeColorPage (
  10902. IN PVOID NewColor,
  10903. IN PVOID OldColor,
  10904. IN ULONG PageFrame
  10905. );
  10906. NTKERNELAPI
  10907. VOID
  10908. KeSweepDcache (
  10909. IN BOOLEAN AllProcessors
  10910. );
  10911. #define KeSweepCurrentDcache()
  10912. NTKERNELAPI
  10913. VOID
  10914. KeSweepIcache (
  10915. IN BOOLEAN AllProcessors
  10916. );
  10917. NTKERNELAPI
  10918. VOID
  10919. KeSweepIcacheRange (
  10920. IN BOOLEAN AllProcessors,
  10921. IN PVOID BaseAddress,
  10922. IN SIZE_T Length
  10923. );
  10924. NTKERNELAPI
  10925. VOID
  10926. KeSweepCurrentIcacheRange (
  10927. IN PVOID BaseAddress,
  10928. IN SIZE_T Length
  10929. );
  10930. NTKERNELAPI
  10931. VOID
  10932. KeSweepCurrentIcache();
  10933. NTKERNELAPI
  10934. VOID
  10935. KeSweepCacheRangeWithDrain (
  10936. IN BOOLEAN AllProcessors,
  10937. IN PVOID BaseAddress,
  10938. IN ULONG Length
  10939. );
  10940. // begin_ntddk begin_ntndis begin_wdm begin_ntosp
  10941. //
  10942. // Cache and write buffer flush functions.
  10943. //
  10944. NTKERNELAPI
  10945. VOID
  10946. KeFlushIoBuffers (
  10947. IN PMDL Mdl,
  10948. IN BOOLEAN ReadOperation,
  10949. IN BOOLEAN DmaOperation
  10950. );
  10951. // end_ntddk end_ntndis end_wdm end_ntosp
  10952. //
  10953. // Clock, profile, and interprocessor interrupt functions.
  10954. //
  10955. struct _KEXCEPTION_FRAME;
  10956. struct _KTRAP_FRAME;
  10957. NTKERNELAPI
  10958. VOID
  10959. KeIpiInterrupt (
  10960. IN struct _KTRAP_FRAME *TrapFrame
  10961. );
  10962. #define KeYieldProcessor __yield
  10963. NTKERNELAPI
  10964. VOID
  10965. KeProfileInterrupt (
  10966. IN struct _KTRAP_FRAME *TrapFrame
  10967. );
  10968. NTKERNELAPI
  10969. VOID
  10970. KeProfileInterruptWithSource (
  10971. IN struct _KTRAP_FRAME *TrapFrame,
  10972. IN KPROFILE_SOURCE ProfileSource
  10973. );
  10974. NTKERNELAPI
  10975. VOID
  10976. KeUpdateRunTime (
  10977. IN struct _KTRAP_FRAME *TrapFrame
  10978. );
  10979. NTKERNELAPI
  10980. VOID
  10981. KeUpdateSystemTime (
  10982. IN struct _KTRAP_FRAME *TrapFrame,
  10983. IN ULONG Increment
  10984. );
  10985. //
  10986. // The following function prototypes are exported for use in MP HALs.
  10987. //
  10988. #if defined(NT_UP)
  10989. #define KiAcquireSpinLock(SpinLock)
  10990. #else
  10991. NTKERNELAPI
  10992. VOID
  10993. KiAcquireSpinLock (
  10994. IN PKSPIN_LOCK SpinLock
  10995. );
  10996. #endif
  10997. #if defined(NT_UP)
  10998. #define KiReleaseSpinLock(SpinLock)
  10999. #else
  11000. VOID
  11001. KiReleaseSpinLock (
  11002. IN PKSPIN_LOCK SpinLock
  11003. );
  11004. #ifndef CAPKERN_SYNCH_POINTS
  11005. #define KiReleaseSpinLock _ReleaseSpinLock
  11006. #endif
  11007. #endif // !defined(NT_UP)
  11008. //
  11009. // Define cache error routine type and prototype.
  11010. //
  11011. typedef
  11012. VOID
  11013. (*PKCACHE_ERROR_ROUTINE) (
  11014. VOID
  11015. );
  11016. NTKERNELAPI
  11017. VOID
  11018. KeSetCacheErrorRoutine (
  11019. IN PKCACHE_ERROR_ROUTINE Routine
  11020. );
  11021. // begin_ntddk begin_wdm
  11022. //
  11023. // Kernel breakin breakpoint
  11024. //
  11025. VOID
  11026. KeBreakinBreakpoint (
  11027. VOID
  11028. );
  11029. #if defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_)
  11030. // begin_wdm
  11031. #define KeQueryTickCount(CurrentCount ) \
  11032. *(PULONGLONG)(CurrentCount) = **((volatile ULONGLONG **)(&KeTickCount));
  11033. // end_wdm
  11034. #else
  11035. NTKERNELAPI
  11036. VOID
  11037. KeQueryTickCount (
  11038. OUT PLARGE_INTEGER CurrentCount
  11039. );
  11040. #endif // defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_)
  11041. //
  11042. // I/O space read and write macros.
  11043. //
  11044. NTHALAPI
  11045. UCHAR
  11046. READ_PORT_UCHAR (
  11047. PUCHAR RegisterAddress
  11048. );
  11049. NTHALAPI
  11050. USHORT
  11051. READ_PORT_USHORT (
  11052. PUSHORT RegisterAddress
  11053. );
  11054. NTHALAPI
  11055. ULONG
  11056. READ_PORT_ULONG (
  11057. PULONG RegisterAddress
  11058. );
  11059. NTHALAPI
  11060. VOID
  11061. READ_PORT_BUFFER_UCHAR (
  11062. PUCHAR portAddress,
  11063. PUCHAR readBuffer,
  11064. ULONG readCount
  11065. );
  11066. NTHALAPI
  11067. VOID
  11068. READ_PORT_BUFFER_USHORT (
  11069. PUSHORT portAddress,
  11070. PUSHORT readBuffer,
  11071. ULONG readCount
  11072. );
  11073. NTHALAPI
  11074. VOID
  11075. READ_PORT_BUFFER_ULONG (
  11076. PULONG portAddress,
  11077. PULONG readBuffer,
  11078. ULONG readCount
  11079. );
  11080. NTHALAPI
  11081. VOID
  11082. WRITE_PORT_UCHAR (
  11083. PUCHAR portAddress,
  11084. UCHAR Data
  11085. );
  11086. NTHALAPI
  11087. VOID
  11088. WRITE_PORT_USHORT (
  11089. PUSHORT portAddress,
  11090. USHORT Data
  11091. );
  11092. NTHALAPI
  11093. VOID
  11094. WRITE_PORT_ULONG (
  11095. PULONG portAddress,
  11096. ULONG Data
  11097. );
  11098. NTHALAPI
  11099. VOID
  11100. WRITE_PORT_BUFFER_UCHAR (
  11101. PUCHAR portAddress,
  11102. PUCHAR writeBuffer,
  11103. ULONG writeCount
  11104. );
  11105. NTHALAPI
  11106. VOID
  11107. WRITE_PORT_BUFFER_USHORT (
  11108. PUSHORT portAddress,
  11109. PUSHORT writeBuffer,
  11110. ULONG writeCount
  11111. );
  11112. NTHALAPI
  11113. VOID
  11114. WRITE_PORT_BUFFER_ULONG (
  11115. PULONG portAddress,
  11116. PULONG writeBuffer,
  11117. ULONG writeCount
  11118. );
  11119. #define READ_REGISTER_UCHAR(x) \
  11120. (__mf(), *(volatile UCHAR * const)(x))
  11121. #define READ_REGISTER_USHORT(x) \
  11122. (__mf(), *(volatile USHORT * const)(x))
  11123. #define READ_REGISTER_ULONG(x) \
  11124. (__mf(), *(volatile ULONG * const)(x))
  11125. #define READ_REGISTER_BUFFER_UCHAR(x, y, z) { \
  11126. PUCHAR registerBuffer = x; \
  11127. PUCHAR readBuffer = y; \
  11128. ULONG readCount; \
  11129. __mf(); \
  11130. for (readCount = z; readCount--; readBuffer++, registerBuffer++) { \
  11131. *readBuffer = *(volatile UCHAR * const)(registerBuffer); \
  11132. } \
  11133. }
  11134. #define READ_REGISTER_BUFFER_USHORT(x, y, z) { \
  11135. PUSHORT registerBuffer = x; \
  11136. PUSHORT readBuffer = y; \
  11137. ULONG readCount; \
  11138. __mf(); \
  11139. for (readCount = z; readCount--; readBuffer++, registerBuffer++) { \
  11140. *readBuffer = *(volatile USHORT * const)(registerBuffer); \
  11141. } \
  11142. }
  11143. #define READ_REGISTER_BUFFER_ULONG(x, y, z) { \
  11144. PULONG registerBuffer = x; \
  11145. PULONG readBuffer = y; \
  11146. ULONG readCount; \
  11147. __mf(); \
  11148. for (readCount = z; readCount--; readBuffer++, registerBuffer++) { \
  11149. *readBuffer = *(volatile ULONG * const)(registerBuffer); \
  11150. } \
  11151. }
  11152. #define WRITE_REGISTER_UCHAR(x, y) { \
  11153. *(volatile UCHAR * const)(x) = y; \
  11154. KeFlushWriteBuffer(); \
  11155. }
  11156. #define WRITE_REGISTER_USHORT(x, y) { \
  11157. *(volatile USHORT * const)(x) = y; \
  11158. KeFlushWriteBuffer(); \
  11159. }
  11160. #define WRITE_REGISTER_ULONG(x, y) { \
  11161. *(volatile ULONG * const)(x) = y; \
  11162. KeFlushWriteBuffer(); \
  11163. }
  11164. #define WRITE_REGISTER_BUFFER_UCHAR(x, y, z) { \
  11165. PUCHAR registerBuffer = x; \
  11166. PUCHAR writeBuffer = y; \
  11167. ULONG writeCount; \
  11168. for (writeCount = z; writeCount--; writeBuffer++, registerBuffer++) { \
  11169. *(volatile UCHAR * const)(registerBuffer) = *writeBuffer; \
  11170. } \
  11171. KeFlushWriteBuffer(); \
  11172. }
  11173. #define WRITE_REGISTER_BUFFER_USHORT(x, y, z) { \
  11174. PUSHORT registerBuffer = x; \
  11175. PUSHORT writeBuffer = y; \
  11176. ULONG writeCount; \
  11177. for (writeCount = z; writeCount--; writeBuffer++, registerBuffer++) { \
  11178. *(volatile USHORT * const)(registerBuffer) = *writeBuffer; \
  11179. } \
  11180. KeFlushWriteBuffer(); \
  11181. }
  11182. #define WRITE_REGISTER_BUFFER_ULONG(x, y, z) { \
  11183. PULONG registerBuffer = x; \
  11184. PULONG writeBuffer = y; \
  11185. ULONG writeCount; \
  11186. for (writeCount = z; writeCount--; writeBuffer++, registerBuffer++) { \
  11187. *(volatile ULONG * const)(registerBuffer) = *writeBuffer; \
  11188. } \
  11189. KeFlushWriteBuffer(); \
  11190. }
  11191. // end_ntddk end_ntndis end_wdm end_ntosp
  11192. //
  11193. // Higher FP volatile
  11194. //
  11195. // This structure defines the higher FP volatile registers.
  11196. //
  11197. typedef struct _KHIGHER_FP_VOLATILE {
  11198. // volatile higher floating registers f32 - f127
  11199. FLOAT128 FltF32;
  11200. FLOAT128 FltF33;
  11201. FLOAT128 FltF34;
  11202. FLOAT128 FltF35;
  11203. FLOAT128 FltF36;
  11204. FLOAT128 FltF37;
  11205. FLOAT128 FltF38;
  11206. FLOAT128 FltF39;
  11207. FLOAT128 FltF40;
  11208. FLOAT128 FltF41;
  11209. FLOAT128 FltF42;
  11210. FLOAT128 FltF43;
  11211. FLOAT128 FltF44;
  11212. FLOAT128 FltF45;
  11213. FLOAT128 FltF46;
  11214. FLOAT128 FltF47;
  11215. FLOAT128 FltF48;
  11216. FLOAT128 FltF49;
  11217. FLOAT128 FltF50;
  11218. FLOAT128 FltF51;
  11219. FLOAT128 FltF52;
  11220. FLOAT128 FltF53;
  11221. FLOAT128 FltF54;
  11222. FLOAT128 FltF55;
  11223. FLOAT128 FltF56;
  11224. FLOAT128 FltF57;
  11225. FLOAT128 FltF58;
  11226. FLOAT128 FltF59;
  11227. FLOAT128 FltF60;
  11228. FLOAT128 FltF61;
  11229. FLOAT128 FltF62;
  11230. FLOAT128 FltF63;
  11231. FLOAT128 FltF64;
  11232. FLOAT128 FltF65;
  11233. FLOAT128 FltF66;
  11234. FLOAT128 FltF67;
  11235. FLOAT128 FltF68;
  11236. FLOAT128 FltF69;
  11237. FLOAT128 FltF70;
  11238. FLOAT128 FltF71;
  11239. FLOAT128 FltF72;
  11240. FLOAT128 FltF73;
  11241. FLOAT128 FltF74;
  11242. FLOAT128 FltF75;
  11243. FLOAT128 FltF76;
  11244. FLOAT128 FltF77;
  11245. FLOAT128 FltF78;
  11246. FLOAT128 FltF79;
  11247. FLOAT128 FltF80;
  11248. FLOAT128 FltF81;
  11249. FLOAT128 FltF82;
  11250. FLOAT128 FltF83;
  11251. FLOAT128 FltF84;
  11252. FLOAT128 FltF85;
  11253. FLOAT128 FltF86;
  11254. FLOAT128 FltF87;
  11255. FLOAT128 FltF88;
  11256. FLOAT128 FltF89;
  11257. FLOAT128 FltF90;
  11258. FLOAT128 FltF91;
  11259. FLOAT128 FltF92;
  11260. FLOAT128 FltF93;
  11261. FLOAT128 FltF94;
  11262. FLOAT128 FltF95;
  11263. FLOAT128 FltF96;
  11264. FLOAT128 FltF97;
  11265. FLOAT128 FltF98;
  11266. FLOAT128 FltF99;
  11267. FLOAT128 FltF100;
  11268. FLOAT128 FltF101;
  11269. FLOAT128 FltF102;
  11270. FLOAT128 FltF103;
  11271. FLOAT128 FltF104;
  11272. FLOAT128 FltF105;
  11273. FLOAT128 FltF106;
  11274. FLOAT128 FltF107;
  11275. FLOAT128 FltF108;
  11276. FLOAT128 FltF109;
  11277. FLOAT128 FltF110;
  11278. FLOAT128 FltF111;
  11279. FLOAT128 FltF112;
  11280. FLOAT128 FltF113;
  11281. FLOAT128 FltF114;
  11282. FLOAT128 FltF115;
  11283. FLOAT128 FltF116;
  11284. FLOAT128 FltF117;
  11285. FLOAT128 FltF118;
  11286. FLOAT128 FltF119;
  11287. FLOAT128 FltF120;
  11288. FLOAT128 FltF121;
  11289. FLOAT128 FltF122;
  11290. FLOAT128 FltF123;
  11291. FLOAT128 FltF124;
  11292. FLOAT128 FltF125;
  11293. FLOAT128 FltF126;
  11294. FLOAT128 FltF127;
  11295. } KHIGHER_FP_VOLATILE, *PKHIGHER_FP_VOLATILE;
  11296. //
  11297. // Debug registers
  11298. //
  11299. // This structure defines the hardware debug registers.
  11300. // We allow space for 4 pairs of instruction and 4 pairs of data debug registers
  11301. // The hardware may actually have more.
  11302. //
  11303. typedef struct _KDEBUG_REGISTERS {
  11304. ULONGLONG DbI0;
  11305. ULONGLONG DbI1;
  11306. ULONGLONG DbI2;
  11307. ULONGLONG DbI3;
  11308. ULONGLONG DbI4;
  11309. ULONGLONG DbI5;
  11310. ULONGLONG DbI6;
  11311. ULONGLONG DbI7;
  11312. ULONGLONG DbD0;
  11313. ULONGLONG DbD1;
  11314. ULONGLONG DbD2;
  11315. ULONGLONG DbD3;
  11316. ULONGLONG DbD4;
  11317. ULONGLONG DbD5;
  11318. ULONGLONG DbD6;
  11319. ULONGLONG DbD7;
  11320. } KDEBUG_REGISTERS, *PKDEBUG_REGISTERS;
  11321. //
  11322. // misc. application registers (mapped to IA-32 registers)
  11323. //
  11324. typedef struct _KAPPLICATION_REGISTERS {
  11325. ULONGLONG Ar21;
  11326. ULONGLONG Ar24;
  11327. ULONGLONG Unused; // AR 25 is now treated as a volitile register.
  11328. ULONGLONG Ar26;
  11329. ULONGLONG Ar27;
  11330. ULONGLONG Ar28;
  11331. ULONGLONG Ar29;
  11332. ULONGLONG Ar30;
  11333. } KAPPLICATION_REGISTERS, *PKAPPLICATION_REGISTERS;
  11334. //
  11335. // performance registers
  11336. //
  11337. typedef struct _KPERFORMANCE_REGISTERS {
  11338. ULONGLONG Perfr0;
  11339. ULONGLONG Perfr1;
  11340. ULONGLONG Perfr2;
  11341. ULONGLONG Perfr3;
  11342. ULONGLONG Perfr4;
  11343. ULONGLONG Perfr5;
  11344. ULONGLONG Perfr6;
  11345. ULONGLONG Perfr7;
  11346. } KPERFORMANCE_REGISTERS, *PKPERFORMANCE_REGISTERS;
  11347. //
  11348. // Thread State save area. Currently, beginning of Kernel Stack
  11349. //
  11350. // This structure defines the area for:
  11351. //
  11352. // higher fp register save/restore
  11353. // user debug register save/restore.
  11354. //
  11355. // The order of these area is significant.
  11356. //
  11357. typedef struct _KTHREAD_STATE_SAVEAREA {
  11358. KAPPLICATION_REGISTERS AppRegisters;
  11359. KPERFORMANCE_REGISTERS PerfRegisters;
  11360. KHIGHER_FP_VOLATILE HigherFPVolatile;
  11361. KDEBUG_REGISTERS DebugRegisters;
  11362. } KTHREAD_STATE_SAVEAREA, *PKTHREAD_STATE_SAVEAREA;
  11363. #define KTHREAD_STATE_SAVEAREA_LENGTH ((sizeof(KTHREAD_STATE_SAVEAREA) + 15) & ~((ULONG_PTR)15))
  11364. #define GET_HIGH_FLOATING_POINT_REGISTER_SAVEAREA(StackBase) \
  11365. (PKHIGHER_FP_VOLATILE) &(((PKTHREAD_STATE_SAVEAREA)(((ULONG_PTR)StackBase - sizeof(KTHREAD_STATE_SAVEAREA)) & ~((ULONG_PTR)15)))->HigherFPVolatile)
  11366. #define GET_DEBUG_REGISTER_SAVEAREA() \
  11367. (PKDEBUG_REGISTERS) &(((PKTHREAD_STATE_SAVEAREA)(((ULONG_PTR)KeGetCurrentThread()->StackBase - sizeof(KTHREAD_STATE_SAVEAREA)) & ~((ULONG_PTR)15)))->DebugRegisters)
  11368. #define GET_APPLICATION_REGISTER_SAVEAREA(StackBase) \
  11369. (PKAPPLICATION_REGISTERS) &(((PKTHREAD_STATE_SAVEAREA)(((ULONG_PTR)StackBase - sizeof(KTHREAD_STATE_SAVEAREA)) & ~((ULONG_PTR)15)))->AppRegisters)
  11370. //
  11371. // Exception frame
  11372. //
  11373. // This frame is established when handling an exception. It provides a place
  11374. // to save all preserved registers. The volatile registers will already
  11375. // have been saved in a trap frame. Also used as part of switch frame built
  11376. // at thread switch.
  11377. //
  11378. // The frame is 16-byte aligned to maintain 16-byte alignment for the stack,
  11379. //
  11380. typedef struct _KEXCEPTION_FRAME {
  11381. // Preserved application registers
  11382. ULONGLONG ApEC; // epilogue count
  11383. ULONGLONG ApLC; // loop count
  11384. ULONGLONG IntNats; // Nats for S0-S3; i.e. ar.UNAT after spill
  11385. // Preserved (saved) interger registers, s0-s3
  11386. ULONGLONG IntS0;
  11387. ULONGLONG IntS1;
  11388. ULONGLONG IntS2;
  11389. ULONGLONG IntS3;
  11390. // Preserved (saved) branch registers, bs0-bs4
  11391. ULONGLONG BrS0;
  11392. ULONGLONG BrS1;
  11393. ULONGLONG BrS2;
  11394. ULONGLONG BrS3;
  11395. ULONGLONG BrS4;
  11396. // Preserved (saved) floating point registers, f2 - f5, f16 - f31
  11397. FLOAT128 FltS0;
  11398. FLOAT128 FltS1;
  11399. FLOAT128 FltS2;
  11400. FLOAT128 FltS3;
  11401. FLOAT128 FltS4;
  11402. FLOAT128 FltS5;
  11403. FLOAT128 FltS6;
  11404. FLOAT128 FltS7;
  11405. FLOAT128 FltS8;
  11406. FLOAT128 FltS9;
  11407. FLOAT128 FltS10;
  11408. FLOAT128 FltS11;
  11409. FLOAT128 FltS12;
  11410. FLOAT128 FltS13;
  11411. FLOAT128 FltS14;
  11412. FLOAT128 FltS15;
  11413. FLOAT128 FltS16;
  11414. FLOAT128 FltS17;
  11415. FLOAT128 FltS18;
  11416. FLOAT128 FltS19;
  11417. } KEXCEPTION_FRAME, *PKEXCEPTION_FRAME;
  11418. //
  11419. // Switch frame
  11420. //
  11421. // This frame is established when doing a thread switch in SwapContext. It
  11422. // provides a place to save the preserved kernel state at the point of the
  11423. // switch registers.
  11424. // The volatile registers are scratch across the call to SwapContext.
  11425. //
  11426. // The frame is 16-byte aligned to maintain 16-byte alignment for the stack,
  11427. //
  11428. typedef struct _KSWITCH_FRAME {
  11429. ULONGLONG SwitchPredicates; // Predicates for Switch
  11430. ULONGLONG SwitchRp; // return pointer for Switch
  11431. ULONGLONG SwitchPFS; // PFS for Switch
  11432. ULONGLONG SwitchFPSR; // ProcessorFP status at thread switch
  11433. ULONGLONG SwitchBsp;
  11434. ULONGLONG SwitchRnat;
  11435. // ULONGLONG Pad;
  11436. KEXCEPTION_FRAME SwitchExceptionFrame;
  11437. } KSWITCH_FRAME, *PKSWITCH_FRAME;
  11438. // Trap frame
  11439. // This frame is established when handling a trap. It provides a place to
  11440. // save all volatile registers. The nonvolatile registers are saved in an
  11441. // exception frame or through the normal C calling conventions for saved
  11442. // registers. Its size must be a multiple of 16 bytes.
  11443. //
  11444. // N.B - the 16-byte alignment is required to maintain the stack alignment.
  11445. //
  11446. #define KTRAP_FRAME_ARGUMENTS (8 * 8) // up to 8 in-memory syscall args
  11447. typedef struct _KTRAP_FRAME {
  11448. //
  11449. // Reserved for additional memory arguments and stack scratch area
  11450. // The size of Reserved[] must be a multiple of 16 bytes.
  11451. //
  11452. ULONGLONG Reserved[(KTRAP_FRAME_ARGUMENTS+16)/8];
  11453. // Temporary (volatile) FP registers - f6-f15 (don't use f32+ in kernel)
  11454. FLOAT128 FltT0;
  11455. FLOAT128 FltT1;
  11456. FLOAT128 FltT2;
  11457. FLOAT128 FltT3;
  11458. FLOAT128 FltT4;
  11459. FLOAT128 FltT5;
  11460. FLOAT128 FltT6;
  11461. FLOAT128 FltT7;
  11462. FLOAT128 FltT8;
  11463. FLOAT128 FltT9;
  11464. // Temporary (volatile) interger registers
  11465. ULONGLONG IntGp; // global pointer (r1)
  11466. ULONGLONG IntT0;
  11467. ULONGLONG IntT1;
  11468. // The following 4 registers fill in space of preserved (S0-S3) to align Nats
  11469. ULONGLONG ApUNAT; // ar.UNAT on kernel entry
  11470. ULONGLONG ApCCV; // ar.CCV
  11471. ULONGLONG SegCSD; // Second register for 16 byte values
  11472. ULONGLONG Preds; // Predicates
  11473. ULONGLONG IntV0; // return value (r8)
  11474. ULONGLONG IntT2;
  11475. ULONGLONG IntT3;
  11476. ULONGLONG IntT4;
  11477. ULONGLONG IntSp; // stack pointer (r12)
  11478. ULONGLONG IntTeb; // teb (r13)
  11479. ULONGLONG IntT5;
  11480. ULONGLONG IntT6;
  11481. ULONGLONG IntT7;
  11482. ULONGLONG IntT8;
  11483. ULONGLONG IntT9;
  11484. ULONGLONG IntT10;
  11485. ULONGLONG IntT11;
  11486. ULONGLONG IntT12;
  11487. ULONGLONG IntT13;
  11488. ULONGLONG IntT14;
  11489. ULONGLONG IntT15;
  11490. ULONGLONG IntT16;
  11491. ULONGLONG IntT17;
  11492. ULONGLONG IntT18;
  11493. ULONGLONG IntT19;
  11494. ULONGLONG IntT20;
  11495. ULONGLONG IntT21;
  11496. ULONGLONG IntT22;
  11497. ULONGLONG IntNats; // Temporary (volatile) registers' Nats directly from ar.UNAT at point of spill
  11498. ULONGLONG BrRp; // Return pointer on kernel entry
  11499. ULONGLONG BrT0; // Temporary (volatile) branch registers (b6-b7)
  11500. ULONGLONG BrT1;
  11501. // Register stack info
  11502. ULONGLONG RsRSC; // RSC on kernel entry
  11503. ULONGLONG RsBSP; // BSP on kernel entry
  11504. ULONGLONG RsBSPSTORE; // User BSP Store at point of switch to kernel backing store
  11505. ULONGLONG RsRNAT; // old RNAT at point of switch to kernel backing store
  11506. ULONGLONG RsPFS; // PFS on kernel entry
  11507. // Trap Status Information
  11508. ULONGLONG StIPSR; // Interruption Processor Status Register
  11509. ULONGLONG StIIP; // Interruption IP
  11510. ULONGLONG StIFS; // Interruption Function State
  11511. ULONGLONG StFPSR; // FP status
  11512. ULONGLONG StISR; // Interruption Status Register
  11513. ULONGLONG StIFA; // Interruption Data Address
  11514. ULONGLONG StIIPA; // Last executed bundle address
  11515. ULONGLONG StIIM; // Interruption Immediate
  11516. ULONGLONG StIHA; // Interruption Hash Address
  11517. ULONG OldIrql; // Previous Irql.
  11518. ULONG PreviousMode; // Previous Mode.
  11519. ULONGLONG TrapFrame;// Previous Trap Frame
  11520. //
  11521. // Exception record
  11522. //
  11523. UCHAR ExceptionRecord[(sizeof(EXCEPTION_RECORD) + 15) & (~15)];
  11524. // End of frame marker (for debugging)
  11525. ULONGLONG NewBSP; // NewBSP When a stack switch occur this is the value of the new BSP
  11526. ULONGLONG EOFMarker;
  11527. } KTRAP_FRAME, *PKTRAP_FRAME;
  11528. #define KTRAP_FRAME_LENGTH ((sizeof(KTRAP_FRAME) + 15) & (~15))
  11529. #define KTRAP_FRAME_ALIGN (16)
  11530. #define KTRAP_FRAME_ROUND (KTRAP_FRAME_ALIGN - 1)
  11531. #define KTRAP_FRAME_EOF 0xe0f0e0f0e0f0e000i64
  11532. //
  11533. // Use the lowest 4 bits of EOFMarker field to encode the trap frame type
  11534. //
  11535. #define SYSCALL_FRAME 0
  11536. #define INTERRUPT_FRAME 1
  11537. #define EXCEPTION_FRAME 2
  11538. #define CONTEXT_FRAME 10
  11539. #define MODIFIED_FRAME 0x20
  11540. #define TRAP_FRAME_TYPE(tf) (tf->EOFMarker & 0xf)
  11541. //
  11542. // Define the kernel mode and user mode callback frame structures.
  11543. //
  11544. //
  11545. // The frame saved by KiCallUserMode is defined here to allow
  11546. // the kernel debugger to trace the entire kernel stack
  11547. // when usermode callouts are pending.
  11548. //
  11549. // N.B. The size of the following structure must be a multiple of 16 bytes
  11550. // and it must be 16-byte aligned.
  11551. //
  11552. typedef struct _KCALLOUT_FRAME {
  11553. ULONGLONG BrRp;
  11554. ULONGLONG RsPFS;
  11555. ULONGLONG Preds;
  11556. ULONGLONG ApUNAT;
  11557. ULONGLONG ApLC;
  11558. ULONGLONG RsRNAT;
  11559. ULONGLONG IntNats;
  11560. ULONGLONG IntS0;
  11561. ULONGLONG IntS1;
  11562. ULONGLONG IntS2;
  11563. ULONGLONG IntS3;
  11564. ULONGLONG BrS0;
  11565. ULONGLONG BrS1;
  11566. ULONGLONG BrS2;
  11567. ULONGLONG BrS3;
  11568. ULONGLONG BrS4;
  11569. FLOAT128 FltS0; // 16-byte aligned boundary
  11570. FLOAT128 FltS1;
  11571. FLOAT128 FltS2;
  11572. FLOAT128 FltS3;
  11573. FLOAT128 FltS4;
  11574. FLOAT128 FltS5;
  11575. FLOAT128 FltS6;
  11576. FLOAT128 FltS7;
  11577. FLOAT128 FltS8;
  11578. FLOAT128 FltS9;
  11579. FLOAT128 FltS10;
  11580. FLOAT128 FltS11;
  11581. FLOAT128 FltS12;
  11582. FLOAT128 FltS13;
  11583. FLOAT128 FltS14;
  11584. FLOAT128 FltS15;
  11585. FLOAT128 FltS16;
  11586. FLOAT128 FltS17;
  11587. FLOAT128 FltS18;
  11588. FLOAT128 FltS19;
  11589. ULONGLONG A0; // saved argument registers a0-a2
  11590. ULONGLONG A1;
  11591. ULONGLONG CbStk; // saved callback stack address
  11592. ULONGLONG InStack; // saved initial stack address
  11593. ULONGLONG CbBStore; // saved callback stack address
  11594. ULONGLONG InBStore; // saved initial stack address
  11595. ULONGLONG TrFrame; // saved callback trap frame address
  11596. ULONGLONG TrStIIP; // saved continuation address
  11597. } KCALLOUT_FRAME, *PKCALLOUT_FRAME;
  11598. typedef struct _UCALLOUT_FRAME {
  11599. PVOID Buffer;
  11600. ULONG Length;
  11601. ULONG ApiNumber;
  11602. ULONGLONG IntSp;
  11603. ULONGLONG RsPFS;
  11604. ULONGLONG BrRp;
  11605. ULONGLONG Pad;
  11606. } UCALLOUT_FRAME, *PUCALLOUT_FRAME;
  11607. //
  11608. // Machine type definitions
  11609. //
  11610. #define MACHINE_TYPE_ISA 0
  11611. #define MACHINE_TYPE_EISA 1
  11612. #define MACHINE_TYPE_MCA 2
  11613. //
  11614. // PAL Interface
  11615. //
  11616. // iA-64 defined PAL function IDs in decimal format as in the PAL spec
  11617. // All PAL calls done through HAL. HAL may block some calls
  11618. //
  11619. #define PAL_CACHE_FLUSH 1I64
  11620. #define PAL_CACHE_INFO 2I64
  11621. #define PAL_CACHE_INIT 3I64
  11622. #define PAL_CACHE_SUMMARY 4I64
  11623. #define PAL_PTCE_INFO 6I64
  11624. #define PAL_MEM_ATTRIB 5I64
  11625. #define PAL_VM_INFO 7I64
  11626. #define PAL_VM_SUMMARY 8I64
  11627. #define PAL_BUS_GET_FEATURES 9I64
  11628. #define PAL_BUS_SET_FEATURES 10I64
  11629. #define PAL_DEBUG_INFO 11I64
  11630. #define PAL_FIXED_ADDR 12I64
  11631. #define PAL_FREQ_BASE 13I64
  11632. #define PAL_FREQ_RATIOS 14I64
  11633. #define PAL_PERF_MON_INFO 15I64
  11634. #define PAL_PLATFORM_ADDR 16I64
  11635. #define PAL_PROC_GET_FEATURES 17I64
  11636. #define PAL_PROC_SET_FEATURES 18I64
  11637. #define PAL_RSE_INFO 19I64
  11638. #define PAL_VERSION 20I64
  11639. #define PAL_MC_CLEAR_LOG 21I64
  11640. #define PAL_MC_DRAIN 22I64
  11641. #define PAL_MC_EXPECTED 23I64
  11642. #define PAL_MC_DYNAMIC_STATE 24I64
  11643. #define PAL_MC_ERROR_INFO 25I64
  11644. #define PAL_MC_RESUME 26I64
  11645. #define PAL_MC_REGISTER_MEM 27I64
  11646. #define PAL_HALT 28I64
  11647. #define PAL_HALT_LIGHT 29I64
  11648. #define PAL_COPY_INFO 30I64
  11649. #define PAL_CACHE_LINE_INIT 31I64
  11650. #define PAL_PMI_ENTRYPOINT 32I64
  11651. #define PAL_ENTER_IA_32_ENV 33I64
  11652. #define PAL_VM_PAGE_SIZE 34I64
  11653. #define PAL_MEM_FOR_TEST 37I64
  11654. #define PAL_CACHE_PROT_INFO 38I64
  11655. #define PAL_REGISTER_INFO 39I64
  11656. #define PAL_SHUTDOWN 44I64
  11657. #define PAL_PREFETCH_VISIBILITY 41I64
  11658. #define PAL_COPY_PAL 256I64
  11659. #define PAL_HALT_INFO 257I64
  11660. #define PAL_TEST_PROC 258I64
  11661. #define PAL_CACHE_READ 259I64
  11662. #define PAL_CACHE_WRITE 260I64
  11663. #define PAL_VM_TR_READ 261I64
  11664. //
  11665. // iA-64 defined PAL return values
  11666. //
  11667. #define PAL_STATUS_INVALID_CACHELINE 1I64
  11668. #define PAL_STATUS_SUPPORT_NOT_NEEDED 1I64
  11669. #define PAL_STATUS_SUCCESS 0
  11670. #define PAL_STATUS_NOT_IMPLEMENTED -1I64
  11671. #define PAL_STATUS_INVALID_ARGUMENT -2I64
  11672. #define PAL_STATUS_ERROR -3I64
  11673. #define PAL_STATUS_UNABLE_TO_INIT_CACHE_LEVEL_AND_TYPE -4I64
  11674. #define PAL_STATUS_NOT_FOUND_IN_CACHE -5I64
  11675. #define PAL_STATUS_NO_ERROR_INFO_AVAILABLE -6I64
  11676. #ifdef _IA64_
  11677. //
  11678. // Stack Registers for IA64
  11679. //
  11680. typedef struct _STACK_REGISTERS {
  11681. ULONGLONG IntR32;
  11682. ULONGLONG IntR33;
  11683. ULONGLONG IntR34;
  11684. ULONGLONG IntR35;
  11685. ULONGLONG IntR36;
  11686. ULONGLONG IntR37;
  11687. ULONGLONG IntR38;
  11688. ULONGLONG IntR39;
  11689. ULONGLONG IntR40;
  11690. ULONGLONG IntR41;
  11691. ULONGLONG IntR42;
  11692. ULONGLONG IntR43;
  11693. ULONGLONG IntR44;
  11694. ULONGLONG IntR45;
  11695. ULONGLONG IntR46;
  11696. ULONGLONG IntR47;
  11697. ULONGLONG IntR48;
  11698. ULONGLONG IntR49;
  11699. ULONGLONG IntR50;
  11700. ULONGLONG IntR51;
  11701. ULONGLONG IntR52;
  11702. ULONGLONG IntR53;
  11703. ULONGLONG IntR54;
  11704. ULONGLONG IntR55;
  11705. ULONGLONG IntR56;
  11706. ULONGLONG IntR57;
  11707. ULONGLONG IntR58;
  11708. ULONGLONG IntR59;
  11709. ULONGLONG IntR60;
  11710. ULONGLONG IntR61;
  11711. ULONGLONG IntR62;
  11712. ULONGLONG IntR63;
  11713. ULONGLONG IntR64;
  11714. ULONGLONG IntR65;
  11715. ULONGLONG IntR66;
  11716. ULONGLONG IntR67;
  11717. ULONGLONG IntR68;
  11718. ULONGLONG IntR69;
  11719. ULONGLONG IntR70;
  11720. ULONGLONG IntR71;
  11721. ULONGLONG IntR72;
  11722. ULONGLONG IntR73;
  11723. ULONGLONG IntR74;
  11724. ULONGLONG IntR75;
  11725. ULONGLONG IntR76;
  11726. ULONGLONG IntR77;
  11727. ULONGLONG IntR78;
  11728. ULONGLONG IntR79;
  11729. ULONGLONG IntR80;
  11730. ULONGLONG IntR81;
  11731. ULONGLONG IntR82;
  11732. ULONGLONG IntR83;
  11733. ULONGLONG IntR84;
  11734. ULONGLONG IntR85;
  11735. ULONGLONG IntR86;
  11736. ULONGLONG IntR87;
  11737. ULONGLONG IntR88;
  11738. ULONGLONG IntR89;
  11739. ULONGLONG IntR90;
  11740. ULONGLONG IntR91;
  11741. ULONGLONG IntR92;
  11742. ULONGLONG IntR93;
  11743. ULONGLONG IntR94;
  11744. ULONGLONG IntR95;
  11745. ULONGLONG IntR96;
  11746. ULONGLONG IntR97;
  11747. ULONGLONG IntR98;
  11748. ULONGLONG IntR99;
  11749. ULONGLONG IntR100;
  11750. ULONGLONG IntR101;
  11751. ULONGLONG IntR102;
  11752. ULONGLONG IntR103;
  11753. ULONGLONG IntR104;
  11754. ULONGLONG IntR105;
  11755. ULONGLONG IntR106;
  11756. ULONGLONG IntR107;
  11757. ULONGLONG IntR108;
  11758. ULONGLONG IntR109;
  11759. ULONGLONG IntR110;
  11760. ULONGLONG IntR111;
  11761. ULONGLONG IntR112;
  11762. ULONGLONG IntR113;
  11763. ULONGLONG IntR114;
  11764. ULONGLONG IntR115;
  11765. ULONGLONG IntR116;
  11766. ULONGLONG IntR117;
  11767. ULONGLONG IntR118;
  11768. ULONGLONG IntR119;
  11769. ULONGLONG IntR120;
  11770. ULONGLONG IntR121;
  11771. ULONGLONG IntR122;
  11772. ULONGLONG IntR123;
  11773. ULONGLONG IntR124;
  11774. ULONGLONG IntR125;
  11775. ULONGLONG IntR126;
  11776. ULONGLONG IntR127;
  11777. // Nat bits for stack registers
  11778. ULONGLONG IntNats2; // r32-r95 in bit positions 1 to 63
  11779. ULONGLONG IntNats3; // r96-r127 in bit position 1 to 31
  11780. } STACK_REGISTERS, *PSTACK_REGISTERS;
  11781. //
  11782. // Special Registers for IA64
  11783. //
  11784. typedef struct _KSPECIAL_REGISTERS {
  11785. // Kernel debug breakpoint registers
  11786. ULONGLONG KernelDbI0; // Instruction debug registers
  11787. ULONGLONG KernelDbI1;
  11788. ULONGLONG KernelDbI2;
  11789. ULONGLONG KernelDbI3;
  11790. ULONGLONG KernelDbI4;
  11791. ULONGLONG KernelDbI5;
  11792. ULONGLONG KernelDbI6;
  11793. ULONGLONG KernelDbI7;
  11794. ULONGLONG KernelDbD0; // Data debug registers
  11795. ULONGLONG KernelDbD1;
  11796. ULONGLONG KernelDbD2;
  11797. ULONGLONG KernelDbD3;
  11798. ULONGLONG KernelDbD4;
  11799. ULONGLONG KernelDbD5;
  11800. ULONGLONG KernelDbD6;
  11801. ULONGLONG KernelDbD7;
  11802. // Kernel performance monitor registers
  11803. ULONGLONG KernelPfC0; // Performance configuration registers
  11804. ULONGLONG KernelPfC1;
  11805. ULONGLONG KernelPfC2;
  11806. ULONGLONG KernelPfC3;
  11807. ULONGLONG KernelPfC4;
  11808. ULONGLONG KernelPfC5;
  11809. ULONGLONG KernelPfC6;
  11810. ULONGLONG KernelPfC7;
  11811. ULONGLONG KernelPfD0; // Performance data registers
  11812. ULONGLONG KernelPfD1;
  11813. ULONGLONG KernelPfD2;
  11814. ULONGLONG KernelPfD3;
  11815. ULONGLONG KernelPfD4;
  11816. ULONGLONG KernelPfD5;
  11817. ULONGLONG KernelPfD6;
  11818. ULONGLONG KernelPfD7;
  11819. // kernel bank shadow (hidden) registers
  11820. ULONGLONG IntH16;
  11821. ULONGLONG IntH17;
  11822. ULONGLONG IntH18;
  11823. ULONGLONG IntH19;
  11824. ULONGLONG IntH20;
  11825. ULONGLONG IntH21;
  11826. ULONGLONG IntH22;
  11827. ULONGLONG IntH23;
  11828. ULONGLONG IntH24;
  11829. ULONGLONG IntH25;
  11830. ULONGLONG IntH26;
  11831. ULONGLONG IntH27;
  11832. ULONGLONG IntH28;
  11833. ULONGLONG IntH29;
  11834. ULONGLONG IntH30;
  11835. ULONGLONG IntH31;
  11836. // Application Registers
  11837. // - CPUID Registers - AR
  11838. ULONGLONG ApCPUID0; // Cpuid Register 0
  11839. ULONGLONG ApCPUID1; // Cpuid Register 1
  11840. ULONGLONG ApCPUID2; // Cpuid Register 2
  11841. ULONGLONG ApCPUID3; // Cpuid Register 3
  11842. ULONGLONG ApCPUID4; // Cpuid Register 4
  11843. ULONGLONG ApCPUID5; // Cpuid Register 5
  11844. ULONGLONG ApCPUID6; // Cpuid Register 6
  11845. ULONGLONG ApCPUID7; // Cpuid Register 7
  11846. // - Kernel Registers - AR
  11847. ULONGLONG ApKR0; // Kernel Register 0 (User RO)
  11848. ULONGLONG ApKR1; // Kernel Register 1 (User RO)
  11849. ULONGLONG ApKR2; // Kernel Register 2 (User RO)
  11850. ULONGLONG ApKR3; // Kernel Register 3 (User RO)
  11851. ULONGLONG ApKR4; // Kernel Register 4
  11852. ULONGLONG ApKR5; // Kernel Register 5
  11853. ULONGLONG ApKR6; // Kernel Register 6
  11854. ULONGLONG ApKR7; // Kernel Register 7
  11855. ULONGLONG ApITC; // Interval Timer Counter
  11856. // Global control registers
  11857. ULONGLONG ApITM; // Interval Timer Match register
  11858. ULONGLONG ApIVA; // Interrupt Vector Address
  11859. ULONGLONG ApPTA; // Page Table Address
  11860. ULONGLONG ApGPTA; // ia32 Page Table Address
  11861. ULONGLONG StISR; // Interrupt status
  11862. ULONGLONG StIFA; // Interruption Faulting Address
  11863. ULONGLONG StITIR; // Interruption TLB Insertion Register
  11864. ULONGLONG StIIPA; // Interruption Instruction Previous Address (RO)
  11865. ULONGLONG StIIM; // Interruption Immediate register (RO)
  11866. ULONGLONG StIHA; // Interruption Hash Address (RO)
  11867. // - External Interrupt control registers (SAPIC)
  11868. ULONGLONG SaLID; // Local SAPIC ID
  11869. ULONGLONG SaIVR; // Interrupt Vector Register (RO)
  11870. ULONGLONG SaTPR; // Task Priority Register
  11871. ULONGLONG SaEOI; // End Of Interrupt
  11872. ULONGLONG SaIRR0; // Interrupt Request Register 0 (RO)
  11873. ULONGLONG SaIRR1; // Interrupt Request Register 1 (RO)
  11874. ULONGLONG SaIRR2; // Interrupt Request Register 2 (RO)
  11875. ULONGLONG SaIRR3; // Interrupt Request Register 3 (RO)
  11876. ULONGLONG SaITV; // Interrupt Timer Vector
  11877. ULONGLONG SaPMV; // Performance Monitor Vector
  11878. ULONGLONG SaCMCV; // Corrected Machine Check Vector
  11879. ULONGLONG SaLRR0; // Local Interrupt Redirection Vector 0
  11880. ULONGLONG SaLRR1; // Local Interrupt Redirection Vector 1
  11881. // System Registers
  11882. // - Region registers
  11883. ULONGLONG Rr0; // Region register 0
  11884. ULONGLONG Rr1; // Region register 1
  11885. ULONGLONG Rr2; // Region register 2
  11886. ULONGLONG Rr3; // Region register 3
  11887. ULONGLONG Rr4; // Region register 4
  11888. ULONGLONG Rr5; // Region register 5
  11889. ULONGLONG Rr6; // Region register 6
  11890. ULONGLONG Rr7; // Region register 7
  11891. // - Protection Key registers
  11892. ULONGLONG Pkr0; // Protection Key register 0
  11893. ULONGLONG Pkr1; // Protection Key register 1
  11894. ULONGLONG Pkr2; // Protection Key register 2
  11895. ULONGLONG Pkr3; // Protection Key register 3
  11896. ULONGLONG Pkr4; // Protection Key register 4
  11897. ULONGLONG Pkr5; // Protection Key register 5
  11898. ULONGLONG Pkr6; // Protection Key register 6
  11899. ULONGLONG Pkr7; // Protection Key register 7
  11900. ULONGLONG Pkr8; // Protection Key register 8
  11901. ULONGLONG Pkr9; // Protection Key register 9
  11902. ULONGLONG Pkr10; // Protection Key register 10
  11903. ULONGLONG Pkr11; // Protection Key register 11
  11904. ULONGLONG Pkr12; // Protection Key register 12
  11905. ULONGLONG Pkr13; // Protection Key register 13
  11906. ULONGLONG Pkr14; // Protection Key register 14
  11907. ULONGLONG Pkr15; // Protection Key register 15
  11908. // - Translation Lookaside buffers
  11909. ULONGLONG TrI0; // Instruction Translation Register 0
  11910. ULONGLONG TrI1; // Instruction Translation Register 1
  11911. ULONGLONG TrI2; // Instruction Translation Register 2
  11912. ULONGLONG TrI3; // Instruction Translation Register 3
  11913. ULONGLONG TrI4; // Instruction Translation Register 4
  11914. ULONGLONG TrI5; // Instruction Translation Register 5
  11915. ULONGLONG TrI6; // Instruction Translation Register 6
  11916. ULONGLONG TrI7; // Instruction Translation Register 7
  11917. ULONGLONG TrD0; // Data Translation Register 0
  11918. ULONGLONG TrD1; // Data Translation Register 1
  11919. ULONGLONG TrD2; // Data Translation Register 2
  11920. ULONGLONG TrD3; // Data Translation Register 3
  11921. ULONGLONG TrD4; // Data Translation Register 4
  11922. ULONGLONG TrD5; // Data Translation Register 5
  11923. ULONGLONG TrD6; // Data Translation Register 6
  11924. ULONGLONG TrD7; // Data Translation Register 7
  11925. // - Machine Specific Registers
  11926. ULONGLONG SrMSR0; // Machine Specific Register 0
  11927. ULONGLONG SrMSR1; // Machine Specific Register 1
  11928. ULONGLONG SrMSR2; // Machine Specific Register 2
  11929. ULONGLONG SrMSR3; // Machine Specific Register 3
  11930. ULONGLONG SrMSR4; // Machine Specific Register 4
  11931. ULONGLONG SrMSR5; // Machine Specific Register 5
  11932. ULONGLONG SrMSR6; // Machine Specific Register 6
  11933. ULONGLONG SrMSR7; // Machine Specific Register 7
  11934. } KSPECIAL_REGISTERS, *PKSPECIAL_REGISTERS;
  11935. //
  11936. // Processor State structure.
  11937. //
  11938. typedef struct _KPROCESSOR_STATE {
  11939. struct _CONTEXT ContextFrame;
  11940. struct _KSPECIAL_REGISTERS SpecialRegisters;
  11941. } KPROCESSOR_STATE, *PKPROCESSOR_STATE;
  11942. #endif // _IA64_
  11943. // end_windbgkd
  11944. //
  11945. // DPC data structure definition.
  11946. //
  11947. typedef struct _KDPC_DATA {
  11948. LIST_ENTRY DpcListHead;
  11949. KSPIN_LOCK DpcLock;
  11950. volatile ULONG DpcQueueDepth;
  11951. ULONG DpcCount;
  11952. } KDPC_DATA, *PKDPC_DATA;
  11953. //
  11954. // Processor Control Block (PRCB)
  11955. //
  11956. #define PRCB_MINOR_VERSION 1
  11957. #define PRCB_MAJOR_VERSION 1
  11958. #define PRCB_BUILD_DEBUG 0x0001
  11959. #define PRCB_BUILD_UNIPROCESSOR 0x0002
  11960. struct _RESTART_BLOCK;
  11961. typedef struct _KPRCB {
  11962. //
  11963. // Major and minor version numbers of the PCR.
  11964. //
  11965. USHORT MinorVersion;
  11966. USHORT MajorVersion;
  11967. //
  11968. // Start of the architecturally defined section of the PRCB. This section
  11969. // may be directly addressed by vendor/platform specific HAL code and will
  11970. // not change from version to version of NT.
  11971. //
  11972. //
  11973. struct _KTHREAD *CurrentThread;
  11974. struct _KTHREAD *RESTRICTED_POINTER NextThread;
  11975. struct _KTHREAD *IdleThread;
  11976. CCHAR Number;
  11977. CCHAR WakeIdle;
  11978. USHORT BuildType;
  11979. KAFFINITY SetMember;
  11980. struct _RESTART_BLOCK *RestartBlock;
  11981. ULONG_PTR PcrPage;
  11982. ULONG Spare0[4];
  11983. //
  11984. // Processor Idendification Registers.
  11985. //
  11986. ULONG ProcessorModel;
  11987. ULONG ProcessorRevision;
  11988. ULONG ProcessorFamily;
  11989. ULONG ProcessorArchRev;
  11990. ULONGLONG ProcessorSerialNumber;
  11991. ULONGLONG ProcessorFeatureBits;
  11992. UCHAR ProcessorVendorString[16];
  11993. //
  11994. // Space reserved for the system.
  11995. //
  11996. ULONGLONG SystemReserved[8];
  11997. //
  11998. // Space reserved for the HAL.
  11999. //
  12000. ULONGLONG HalReserved[16];
  12001. //
  12002. // End of the architecturally defined section of the PRCB.
  12003. } KPRCB, *PKPRCB, *RESTRICTED_POINTER PRKPRCB;
  12004. //
  12005. // OS_MCA, OS_INIT HandOff State definitions
  12006. //
  12007. // Note: The following definitions *must* match the definions of the
  12008. // corresponding SAL Revision Hand-Off structures.
  12009. //
  12010. typedef struct _SAL_HANDOFF_STATE {
  12011. ULONGLONG PalProcEntryPoint;
  12012. ULONGLONG SalProcEntryPoint;
  12013. ULONGLONG SalGlobalPointer;
  12014. LONGLONG RendezVousResult;
  12015. ULONGLONG SalReturnAddress;
  12016. ULONGLONG MinStateSavePtr;
  12017. } SAL_HANDOFF_STATE, *PSAL_HANDOFF_STATE;
  12018. typedef struct _OS_HANDOFF_STATE {
  12019. ULONGLONG Result;
  12020. ULONGLONG SalGlobalPointer;
  12021. ULONGLONG MinStateSavePtr;
  12022. ULONGLONG SalReturnAddress;
  12023. ULONGLONG NewContextFlag;
  12024. } OS_HANDOFF_STATE, *POS_HANDOFF_STATE;
  12025. //
  12026. // per processor OS_MCA and OS_INIT resource structure
  12027. //
  12028. #define SER_EVENT_STACK_FRAME_ENTRIES 8
  12029. typedef struct _SAL_EVENT_RESOURCES {
  12030. SAL_HANDOFF_STATE SalToOsHandOff;
  12031. OS_HANDOFF_STATE OsToSalHandOff;
  12032. PVOID StateDump;
  12033. ULONGLONG StateDumpPhysical;
  12034. PVOID BackStore;
  12035. ULONGLONG BackStoreLimit;
  12036. PVOID Stack;
  12037. ULONGLONG StackLimit;
  12038. PULONGLONG PTOM;
  12039. ULONGLONG StackFrame[SER_EVENT_STACK_FRAME_ENTRIES];
  12040. PVOID EventPool;
  12041. ULONG EventPoolSize;
  12042. } SAL_EVENT_RESOURCES, *PSAL_EVENT_RESOURCES;
  12043. //
  12044. // PAL Mini-save area, used by MCA and INIT
  12045. //
  12046. typedef struct _PAL_MINI_SAVE_AREA {
  12047. ULONGLONG IntNats; // Nat bits for r1-r31
  12048. // r1-r31 in bits 1 thru 31.
  12049. ULONGLONG IntGp; // r1, volatile
  12050. ULONGLONG IntT0; // r2-r3, volatile
  12051. ULONGLONG IntT1; //
  12052. ULONGLONG IntS0; // r4-r7, preserved
  12053. ULONGLONG IntS1;
  12054. ULONGLONG IntS2;
  12055. ULONGLONG IntS3;
  12056. ULONGLONG IntV0; // r8, volatile
  12057. ULONGLONG IntT2; // r9-r11, volatile
  12058. ULONGLONG IntT3;
  12059. ULONGLONG IntT4;
  12060. ULONGLONG IntSp; // stack pointer (r12), special
  12061. ULONGLONG IntTeb; // teb (r13), special
  12062. ULONGLONG IntT5; // r14-r31, volatile
  12063. ULONGLONG IntT6;
  12064. ULONGLONG B0R16; // Bank 0 registers 16-31
  12065. ULONGLONG B0R17;
  12066. ULONGLONG B0R18;
  12067. ULONGLONG B0R19;
  12068. ULONGLONG B0R20;
  12069. ULONGLONG B0R21;
  12070. ULONGLONG B0R22;
  12071. ULONGLONG B0R23;
  12072. ULONGLONG B0R24;
  12073. ULONGLONG B0R25;
  12074. ULONGLONG B0R26;
  12075. ULONGLONG B0R27;
  12076. ULONGLONG B0R28;
  12077. ULONGLONG B0R29;
  12078. ULONGLONG B0R30;
  12079. ULONGLONG B0R31;
  12080. ULONGLONG IntT7; // Bank 1 registers 16-31
  12081. ULONGLONG IntT8;
  12082. ULONGLONG IntT9;
  12083. ULONGLONG IntT10;
  12084. ULONGLONG IntT11;
  12085. ULONGLONG IntT12;
  12086. ULONGLONG IntT13;
  12087. ULONGLONG IntT14;
  12088. ULONGLONG IntT15;
  12089. ULONGLONG IntT16;
  12090. ULONGLONG IntT17;
  12091. ULONGLONG IntT18;
  12092. ULONGLONG IntT19;
  12093. ULONGLONG IntT20;
  12094. ULONGLONG IntT21;
  12095. ULONGLONG IntT22;
  12096. ULONGLONG Preds; // predicates, preserved
  12097. ULONGLONG BrRp; // return pointer, b0, preserved
  12098. ULONGLONG RsRSC; // RSE configuration, volatile
  12099. ULONGLONG StIIP; // Interruption IP
  12100. ULONGLONG StIPSR; // Interruption Processor Status
  12101. ULONGLONG StIFS; // Interruption Function State
  12102. ULONGLONG XIP; // Event IP
  12103. ULONGLONG XPSR; // Event Processor Status
  12104. ULONGLONG XFS; // Event Function State
  12105. } PAL_MINI_SAVE_AREA, *PPAL_MINI_SAVE_AREA;
  12106. // begin_ntddk begin_ntosp
  12107. //
  12108. // Define Processor Control Region Structure.
  12109. //
  12110. #define PCR_MINOR_VERSION 1
  12111. #define PCR_MAJOR_VERSION 1
  12112. typedef struct _KPCR {
  12113. //
  12114. // Major and minor version numbers of the PCR.
  12115. //
  12116. ULONG MinorVersion;
  12117. ULONG MajorVersion;
  12118. //
  12119. // Start of the architecturally defined section of the PCR. This section
  12120. // may be directly addressed by vendor/platform specific HAL code and will
  12121. // not change from version to version of NT.
  12122. //
  12123. //
  12124. // First and second level cache parameters.
  12125. //
  12126. ULONG FirstLevelDcacheSize;
  12127. ULONG FirstLevelDcacheFillSize;
  12128. ULONG FirstLevelIcacheSize;
  12129. ULONG FirstLevelIcacheFillSize;
  12130. ULONG SecondLevelDcacheSize;
  12131. ULONG SecondLevelDcacheFillSize;
  12132. ULONG SecondLevelIcacheSize;
  12133. ULONG SecondLevelIcacheFillSize;
  12134. //
  12135. // Data cache alignment and fill size used for cache flushing and alignment.
  12136. // These fields are set to the larger of the first and second level data
  12137. // cache fill sizes.
  12138. //
  12139. ULONG DcacheAlignment;
  12140. ULONG DcacheFillSize;
  12141. //
  12142. // Instruction cache alignment and fill size used for cache flushing and
  12143. // alignment. These fields are set to the larger of the first and second
  12144. // level data cache fill sizes.
  12145. //
  12146. ULONG IcacheAlignment;
  12147. ULONG IcacheFillSize;
  12148. //
  12149. // Processor identification from PrId register.
  12150. //
  12151. ULONG ProcessorId;
  12152. //
  12153. // Profiling data.
  12154. //
  12155. ULONG ProfileInterval;
  12156. ULONG ProfileCount;
  12157. //
  12158. // Stall execution count and scale factor.
  12159. //
  12160. ULONG StallExecutionCount;
  12161. ULONG StallScaleFactor;
  12162. ULONG InterruptionCount;
  12163. //
  12164. // Space reserved for the system.
  12165. //
  12166. ULONGLONG SystemReserved[6];
  12167. //
  12168. // Space reserved for the HAL
  12169. //
  12170. ULONGLONG HalReserved[64];
  12171. //
  12172. // IRQL mapping tables.
  12173. //
  12174. UCHAR IrqlMask[64];
  12175. UCHAR IrqlTable[64];
  12176. //
  12177. // External Interrupt vectors.
  12178. //
  12179. PKINTERRUPT_ROUTINE InterruptRoutine[MAXIMUM_VECTOR];
  12180. //
  12181. // Reserved interrupt vector mask.
  12182. //
  12183. ULONG ReservedVectors;
  12184. //
  12185. // Processor affinity mask.
  12186. //
  12187. KAFFINITY SetMember;
  12188. //
  12189. // Complement of the processor affinity mask.
  12190. //
  12191. KAFFINITY NotMember;
  12192. //
  12193. // Pointer to processor control block.
  12194. //
  12195. struct _KPRCB *Prcb;
  12196. //
  12197. // Shadow copy of Prcb->CurrentThread for fast access
  12198. //
  12199. struct _KTHREAD *CurrentThread;
  12200. //
  12201. // Processor number.
  12202. //
  12203. CCHAR Number; // Processor Number
  12204. // end_ntddk end_ntosp
  12205. CCHAR PollSlot; // Used by the clock routine track when we should break in.
  12206. UCHAR KernelDebugActive; // debug register active in kernel flag
  12207. UCHAR CurrentIrql; // Current IRQL
  12208. union {
  12209. USHORT SoftwareInterruptPending; // Software Interrupt Pending Flag
  12210. struct {
  12211. UCHAR ApcInterrupt; // 0x01 if APC int pending
  12212. UCHAR DispatchInterrupt; // 0x01 if dispatch int pending
  12213. };
  12214. };
  12215. //
  12216. // Address of per processor SAPIC EOI Table
  12217. //
  12218. PVOID EOITable;
  12219. //
  12220. // IA-64 Machine Check Events trackers
  12221. //
  12222. UCHAR InOsMca;
  12223. UCHAR InOsInit;
  12224. UCHAR InOsCmc;
  12225. UCHAR InOsCpe;
  12226. ULONG InOsULONG_Spare; // Spare ULONG
  12227. PSAL_EVENT_RESOURCES OsMcaResourcePtr;
  12228. PSAL_EVENT_RESOURCES OsInitResourcePtr;
  12229. //
  12230. // End of the architecturally defined section of the PCR. This section
  12231. // may be directly addressed by vendor/platform specific HAL code and will
  12232. // not change from version to version of NT.
  12233. //
  12234. } KPCR, *PKPCR;
  12235. NTKERNELAPI
  12236. KIRQL
  12237. KeGetCurrentIrql();
  12238. NTKERNELAPI
  12239. VOID
  12240. KeLowerIrql (
  12241. IN KIRQL NewIrql
  12242. );
  12243. NTKERNELAPI
  12244. VOID
  12245. KeRaiseIrql (
  12246. IN KIRQL NewIrql,
  12247. OUT PKIRQL OldIrql
  12248. );
  12249. // end_wdm
  12250. NTKERNELAPI
  12251. KIRQL
  12252. KeRaiseIrqlToDpcLevel (
  12253. VOID
  12254. );
  12255. NTKERNELAPI
  12256. KIRQL
  12257. KeRaiseIrqlToSynchLevel (
  12258. VOID
  12259. );
  12260. //
  12261. // Define the number of bits to shift to right justify the Page Table Index
  12262. // field of a PTE.
  12263. //
  12264. #define PTI_SHIFT PAGE_SHIFT
  12265. //
  12266. // Define the number of bits to shift to right justify the Page Directory Index
  12267. // field of a PTE.
  12268. //
  12269. #define PDI_SHIFT (PTI_SHIFT + PAGE_SHIFT - PTE_SHIFT)
  12270. #define PDI1_SHIFT (PDI_SHIFT + PAGE_SHIFT - PTE_SHIFT)
  12271. #define PDI_MASK ((1 << (PAGE_SHIFT - PTE_SHIFT)) - 1)
  12272. //
  12273. // Define the number of bits to shift to left to produce page table offset
  12274. // from page table index.
  12275. //
  12276. #define PTE_SHIFT 3
  12277. //
  12278. // Define the number of bits to shift to the right justify the Page Directory
  12279. // Table Entry field.
  12280. //
  12281. #define VHPT_PDE_BITS 40
  12282. //
  12283. // Define the RID for IO Port Space.
  12284. //
  12285. #define RR_IO_PORT 6
  12286. //
  12287. // The following definitions are required for the debugger data block.
  12288. //
  12289. // begin_ntddk begin_ntosp
  12290. //
  12291. // The highest user address reserves 64K bytes for a guard page. This
  12292. // the probing of address from kernel mode to only have to check the
  12293. // starting address for structures of 64k bytes or less.
  12294. //
  12295. extern NTKERNELAPI PVOID MmHighestUserAddress;
  12296. extern NTKERNELAPI PVOID MmSystemRangeStart;
  12297. extern NTKERNELAPI ULONG_PTR MmUserProbeAddress;
  12298. #define MM_HIGHEST_USER_ADDRESS MmHighestUserAddress
  12299. #define MM_USER_PROBE_ADDRESS MmUserProbeAddress
  12300. #define MM_SYSTEM_RANGE_START MmSystemRangeStart
  12301. //
  12302. // The lowest user address reserves the low 64k.
  12303. //
  12304. #define MM_LOWEST_USER_ADDRESS (PVOID)((ULONG_PTR)(UADDRESS_BASE+0x00010000))
  12305. // begin_wdm
  12306. #define MmGetProcedureAddress(Address) (Address)
  12307. #define MmLockPagableCodeSection(PLabelAddress) \
  12308. MmLockPagableDataSection((PVOID)(*((PULONGLONG)PLabelAddress)))
  12309. #define VRN_MASK 0xE000000000000000UI64 // Virtual Region Number mask
  12310. // end_ntddk end_wdm end_ntosp
  12311. #define MI_HIGHEST_USER_ADDRESS (PVOID) (ULONG_PTR)((UADDRESS_BASE + 0x6FC00000000 - 0x10000 - 1)) // highest user address
  12312. #define MI_USER_PROBE_ADDRESS ((ULONG_PTR)(UADDRESS_BASE + 0x6FC00000000UI64 - 0x10000)) // starting address of guard page
  12313. #define MI_SYSTEM_RANGE_START (PVOID) (UADDRESS_BASE + 0x6FC00000000) // start of system space
  12314. //
  12315. // Define the page table base and the page directory base for
  12316. // the TB miss routines and memory management.
  12317. //
  12318. //
  12319. // user/kernel page table base and top addresses
  12320. //
  12321. extern ULONG_PTR KiIA64VaSignedFill;
  12322. extern ULONG_PTR KiIA64PtaSign;
  12323. #define PTA_SIGN KiIA64PtaSign
  12324. #define VA_FILL KiIA64VaSignedFill
  12325. #define SADDRESS_BASE 0x2000000000000000UI64 // session base address
  12326. #define PTE_UBASE PCR->PteUbase
  12327. #define PTE_KBASE PCR->PteKbase
  12328. #define PTE_SBASE PCR->PteSbase
  12329. #define PTE_UTOP (PTE_UBASE|(((ULONG_PTR)1 << PDI1_SHIFT) - 1)) // top level PDR address (user)
  12330. #define PTE_KTOP (PTE_KBASE|(((ULONG_PTR)1 << PDI1_SHIFT) - 1)) // top level PDR address (kernel)
  12331. #define PTE_STOP (PTE_SBASE|(((ULONG_PTR)1 << PDI1_SHIFT) - 1)) // top level PDR address (session)
  12332. //
  12333. // Second level user and kernel PDR address
  12334. //
  12335. #define PDE_UBASE PCR->PdeUbase
  12336. #define PDE_KBASE PCR->PdeKbase
  12337. #define PDE_SBASE PCR->PdeSbase
  12338. #define PDE_UTOP (PDE_UBASE|(((ULONG_PTR)1 << PDI_SHIFT) - 1)) // second level PDR address (user)
  12339. #define PDE_KTOP (PDE_KBASE|(((ULONG_PTR)1 << PDI_SHIFT) - 1)) // second level PDR address (kernel)
  12340. #define PDE_STOP (PDE_SBASE|(((ULONG_PTR)1 << PDI_SHIFT) - 1)) // second level PDR address (session)
  12341. //
  12342. // 8KB first level user and kernel PDR address
  12343. //
  12344. #define PDE_UTBASE PCR->PdeUtbase
  12345. #define PDE_KTBASE PCR->PdeKtbase
  12346. #define PDE_STBASE PCR->PdeStbase
  12347. #define PDE_USELFMAP (PDE_UTBASE|(PAGE_SIZE - (1<<PTE_SHIFT))) // self mapped PPE address (user)
  12348. #define PDE_KSELFMAP (PDE_KTBASE|(PAGE_SIZE - (1<<PTE_SHIFT))) // self mapped PPE address (kernel)
  12349. #define PDE_SSELFMAP (PDE_STBASE|(PAGE_SIZE - (1<<PTE_SHIFT))) // self mapped PPE address (kernel)
  12350. #define PTE_BASE PTE_UBASE
  12351. #define PDE_BASE PDE_UBASE
  12352. #define PDE_TBASE PDE_UTBASE
  12353. #define PDE_SELFMAP PDE_USELFMAP
  12354. #define KSEG0_BASE (KADDRESS_BASE + 0x80000000) // base of kernel
  12355. #define KSEG2_BASE (KADDRESS_BASE + 0xA0000000) // end of kernel
  12356. #define KSEG3_BASE 0x8000000000000000UI64
  12357. #define KSEG3_LIMIT 0x8000100000000000UI64
  12358. #define KSEG4_BASE 0xA000000000000000UI64
  12359. #define KSEG4_LIMIT 0xA000100000000000UI64
  12360. //
  12361. //++
  12362. //PVOID
  12363. //KSEG_ADDRESS (
  12364. // IN ULONG PAGE
  12365. // );
  12366. //
  12367. // Routine Description:
  12368. //
  12369. // This macro returns a KSEG virtual address which maps the page.
  12370. //
  12371. // Arguments:
  12372. //
  12373. // PAGE - Supplies the physical page frame number
  12374. //
  12375. // Return Value:
  12376. //
  12377. // The address of the KSEG address
  12378. //
  12379. //--
  12380. #define KSEG_ADDRESS(PAGE) ((PVOID)(KSEG3_BASE | ((ULONG_PTR)(PAGE) << PAGE_SHIFT)))
  12381. #define KSEG4_ADDRESS(PAGE) ((PVOID)(KSEG4_BASE | ((ULONG_PTR)(PAGE) << PAGE_SHIFT)))
  12382. #define MAXIMUM_FWP_BUFFER_ENTRY 8
  12383. typedef struct _REGION_MAP_INFO {
  12384. ULONG RegionId;
  12385. ULONG PageSize;
  12386. ULONGLONG SequenceNumber;
  12387. } REGION_MAP_INFO, *PREGION_MAP_INFO;
  12388. // begin_ntddk begin_wdm
  12389. //
  12390. // The lowest address for system space.
  12391. //
  12392. #define MM_LOWEST_SYSTEM_ADDRESS ((PVOID)((ULONG_PTR)(KADDRESS_BASE + 0xC0C00000)))
  12393. #endif // defined(_IA64_)
  12394. #include <arc.h>
  12395. //
  12396. #if defined(_X86_)
  12397. #define PAUSE_PROCESSOR _asm { rep nop }
  12398. #else
  12399. #define PAUSE_PROCESSOR
  12400. #endif
  12401. //
  12402. // Define macro to generate an affinity mask.
  12403. //
  12404. #if defined(_NTHAL_) || defined(_NTOSP_)
  12405. #define AFFINITY_MASK(n) ((ULONG_PTR)1 << (n))
  12406. #else
  12407. #if !defined(_WIN64)
  12408. #define KiAffinityArray KiMask32Array
  12409. #endif
  12410. extern const ULONG_PTR KiAffinityArray[];
  12411. #define AFFINITY_MASK(n) (KiAffinityArray[n])
  12412. #endif
  12413. //
  12414. // Interrupt modes.
  12415. //
  12416. typedef enum _KINTERRUPT_MODE {
  12417. LevelSensitive,
  12418. Latched
  12419. } KINTERRUPT_MODE;
  12420. //
  12421. // Wait reasons
  12422. //
  12423. typedef enum _KWAIT_REASON {
  12424. Executive,
  12425. FreePage,
  12426. PageIn,
  12427. PoolAllocation,
  12428. DelayExecution,
  12429. Suspended,
  12430. UserRequest,
  12431. WrExecutive,
  12432. WrFreePage,
  12433. WrPageIn,
  12434. WrPoolAllocation,
  12435. WrDelayExecution,
  12436. WrSuspended,
  12437. WrUserRequest,
  12438. WrEventPair,
  12439. WrQueue,
  12440. WrLpcReceive,
  12441. WrLpcReply,
  12442. WrVirtualMemory,
  12443. WrPageOut,
  12444. WrRendezvous,
  12445. Spare2,
  12446. Spare3,
  12447. Spare4,
  12448. Spare5,
  12449. Spare6,
  12450. WrKernel,
  12451. WrResource,
  12452. WrPushLock,
  12453. WrMutex,
  12454. WrQuantumEnd,
  12455. WrDispatchInt,
  12456. WrPreempted,
  12457. WrYieldExecution,
  12458. MaximumWaitReason
  12459. } KWAIT_REASON;
  12460. typedef struct _KWAIT_BLOCK {
  12461. LIST_ENTRY WaitListEntry;
  12462. struct _KTHREAD *RESTRICTED_POINTER Thread;
  12463. PVOID Object;
  12464. struct _KWAIT_BLOCK *RESTRICTED_POINTER NextWaitBlock;
  12465. USHORT WaitKey;
  12466. USHORT WaitType;
  12467. } KWAIT_BLOCK, *PKWAIT_BLOCK, *RESTRICTED_POINTER PRKWAIT_BLOCK;
  12468. //
  12469. // Thread start function
  12470. //
  12471. typedef
  12472. VOID
  12473. (*PKSTART_ROUTINE) (
  12474. IN PVOID StartContext
  12475. );
  12476. //
  12477. // Kernel object structure definitions
  12478. //
  12479. //
  12480. // Device Queue object and entry
  12481. //
  12482. typedef struct _KDEVICE_QUEUE {
  12483. CSHORT Type;
  12484. CSHORT Size;
  12485. LIST_ENTRY DeviceListHead;
  12486. KSPIN_LOCK Lock;
  12487. BOOLEAN Busy;
  12488. } KDEVICE_QUEUE, *PKDEVICE_QUEUE, *RESTRICTED_POINTER PRKDEVICE_QUEUE;
  12489. typedef struct _KDEVICE_QUEUE_ENTRY {
  12490. LIST_ENTRY DeviceListEntry;
  12491. ULONG SortKey;
  12492. BOOLEAN Inserted;
  12493. } KDEVICE_QUEUE_ENTRY, *PKDEVICE_QUEUE_ENTRY, *RESTRICTED_POINTER PRKDEVICE_QUEUE_ENTRY;
  12494. //
  12495. // Define the interrupt service function type and the empty struct
  12496. // type.
  12497. //
  12498. // end_ntddk end_wdm end_ntifs end_ntosp
  12499. struct _KINTERRUPT;
  12500. // begin_ntddk begin_wdm begin_ntifs begin_ntosp
  12501. typedef
  12502. BOOLEAN
  12503. (*PKSERVICE_ROUTINE) (
  12504. IN struct _KINTERRUPT *Interrupt,
  12505. IN PVOID ServiceContext
  12506. );
  12507. // end_ntddk end_wdm end_ntifs end_ntosp
  12508. //
  12509. // Interrupt object
  12510. //
  12511. // N.B. The layout of this structure cannot change. It is exported to HALs
  12512. // to short circuit interrupt dispatch.
  12513. //
  12514. typedef struct _KINTERRUPT {
  12515. CSHORT Type;
  12516. CSHORT Size;
  12517. LIST_ENTRY InterruptListEntry;
  12518. PKSERVICE_ROUTINE ServiceRoutine;
  12519. PVOID ServiceContext;
  12520. KSPIN_LOCK SpinLock;
  12521. ULONG TickCount;
  12522. PKSPIN_LOCK ActualLock;
  12523. PKINTERRUPT_ROUTINE DispatchAddress;
  12524. ULONG Vector;
  12525. KIRQL Irql;
  12526. KIRQL SynchronizeIrql;
  12527. BOOLEAN FloatingSave;
  12528. BOOLEAN Connected;
  12529. CCHAR Number;
  12530. BOOLEAN ShareVector;
  12531. KINTERRUPT_MODE Mode;
  12532. ULONG ServiceCount;
  12533. ULONG DispatchCount;
  12534. #if defined(_AMD64_)
  12535. PKTRAP_FRAME TrapFrame;
  12536. #endif
  12537. ULONG DispatchCode[DISPATCH_LENGTH];
  12538. } KINTERRUPT;
  12539. typedef struct _KINTERRUPT *PKINTERRUPT, *RESTRICTED_POINTER PRKINTERRUPT; // ntndis ntosp
  12540. // begin_ntifs begin_ntddk begin_wdm begin_ntosp
  12541. //
  12542. // Mutant object
  12543. //
  12544. typedef struct _KMUTANT {
  12545. DISPATCHER_HEADER Header;
  12546. LIST_ENTRY MutantListEntry;
  12547. struct _KTHREAD *RESTRICTED_POINTER OwnerThread;
  12548. BOOLEAN Abandoned;
  12549. UCHAR ApcDisable;
  12550. } KMUTANT, *PKMUTANT, *RESTRICTED_POINTER PRKMUTANT, KMUTEX, *PKMUTEX, *RESTRICTED_POINTER PRKMUTEX;
  12551. // end_ntddk end_wdm end_ntosp
  12552. //
  12553. // Queue object
  12554. //
  12555. #define ASSERT_QUEUE(Q) ASSERT(((Q)->Header.Type & ~KOBJECT_LOCK_BIT) == QueueObject);
  12556. // begin_ntosp
  12557. typedef struct _KQUEUE {
  12558. DISPATCHER_HEADER Header;
  12559. LIST_ENTRY EntryListHead;
  12560. ULONG CurrentCount;
  12561. ULONG MaximumCount;
  12562. LIST_ENTRY ThreadListHead;
  12563. } KQUEUE, *PKQUEUE, *RESTRICTED_POINTER PRKQUEUE;
  12564. // end_ntosp
  12565. // begin_ntddk begin_wdm begin_ntosp
  12566. //
  12567. //
  12568. // Semaphore object
  12569. //
  12570. typedef struct _KSEMAPHORE {
  12571. DISPATCHER_HEADER Header;
  12572. LONG Limit;
  12573. } KSEMAPHORE, *PKSEMAPHORE, *RESTRICTED_POINTER PRKSEMAPHORE;
  12574. //
  12575. // Define the maximum number of nodes supported.
  12576. //
  12577. // N.B. Node number must fit in the page color field of a PFN entry.
  12578. //
  12579. #define MAXIMUM_CCNUMA_NODES 16
  12580. //
  12581. // DPC object
  12582. //
  12583. NTKERNELAPI
  12584. VOID
  12585. KeInitializeDpc (
  12586. IN PRKDPC Dpc,
  12587. IN PKDEFERRED_ROUTINE DeferredRoutine,
  12588. IN PVOID DeferredContext
  12589. );
  12590. NTKERNELAPI
  12591. BOOLEAN
  12592. KeInsertQueueDpc (
  12593. IN PRKDPC Dpc,
  12594. IN PVOID SystemArgument1,
  12595. IN PVOID SystemArgument2
  12596. );
  12597. NTKERNELAPI
  12598. BOOLEAN
  12599. KeRemoveQueueDpc (
  12600. IN PRKDPC Dpc
  12601. );
  12602. // end_wdm
  12603. NTKERNELAPI
  12604. VOID
  12605. KeSetImportanceDpc (
  12606. IN PRKDPC Dpc,
  12607. IN KDPC_IMPORTANCE Importance
  12608. );
  12609. NTKERNELAPI
  12610. VOID
  12611. KeSetTargetProcessorDpc (
  12612. IN PRKDPC Dpc,
  12613. IN CCHAR Number
  12614. );
  12615. // begin_wdm
  12616. NTKERNELAPI
  12617. VOID
  12618. KeFlushQueuedDpcs (
  12619. VOID
  12620. );
  12621. //
  12622. // Device queue object
  12623. //
  12624. NTKERNELAPI
  12625. VOID
  12626. KeInitializeDeviceQueue (
  12627. IN PKDEVICE_QUEUE DeviceQueue
  12628. );
  12629. NTKERNELAPI
  12630. BOOLEAN
  12631. KeInsertDeviceQueue (
  12632. IN PKDEVICE_QUEUE DeviceQueue,
  12633. IN PKDEVICE_QUEUE_ENTRY DeviceQueueEntry
  12634. );
  12635. NTKERNELAPI
  12636. BOOLEAN
  12637. KeInsertByKeyDeviceQueue (
  12638. IN PKDEVICE_QUEUE DeviceQueue,
  12639. IN PKDEVICE_QUEUE_ENTRY DeviceQueueEntry,
  12640. IN ULONG SortKey
  12641. );
  12642. NTKERNELAPI
  12643. PKDEVICE_QUEUE_ENTRY
  12644. KeRemoveDeviceQueue (
  12645. IN PKDEVICE_QUEUE DeviceQueue
  12646. );
  12647. NTKERNELAPI
  12648. PKDEVICE_QUEUE_ENTRY
  12649. KeRemoveByKeyDeviceQueue (
  12650. IN PKDEVICE_QUEUE DeviceQueue,
  12651. IN ULONG SortKey
  12652. );
  12653. NTKERNELAPI
  12654. PKDEVICE_QUEUE_ENTRY
  12655. KeRemoveByKeyDeviceQueueIfBusy (
  12656. IN PKDEVICE_QUEUE DeviceQueue,
  12657. IN ULONG SortKey
  12658. );
  12659. NTKERNELAPI
  12660. BOOLEAN
  12661. KeRemoveEntryDeviceQueue (
  12662. IN PKDEVICE_QUEUE DeviceQueue,
  12663. IN PKDEVICE_QUEUE_ENTRY DeviceQueueEntry
  12664. );
  12665. // end_ntddk end_wdm end_ntifs end_ntosp
  12666. //
  12667. // Interrupt object
  12668. //
  12669. NTKERNELAPI
  12670. VOID
  12671. KeInitializeInterrupt (
  12672. IN PKINTERRUPT Interrupt,
  12673. IN PKSERVICE_ROUTINE ServiceRoutine,
  12674. IN PVOID ServiceContext,
  12675. IN PKSPIN_LOCK SpinLock OPTIONAL,
  12676. IN ULONG Vector,
  12677. IN KIRQL Irql,
  12678. IN KIRQL SynchronizeIrql,
  12679. IN KINTERRUPT_MODE InterruptMode,
  12680. IN BOOLEAN ShareVector,
  12681. IN CCHAR ProcessorNumber,
  12682. IN BOOLEAN FloatingSave
  12683. );
  12684. #if defined(_AMD64_)
  12685. #define NO_INTERRUPT_SPINLOCK ((PKSPIN_LOCK)-1I64)
  12686. #endif
  12687. NTKERNELAPI
  12688. BOOLEAN
  12689. KeConnectInterrupt (
  12690. IN PKINTERRUPT Interrupt
  12691. );
  12692. NTKERNELAPI
  12693. BOOLEAN
  12694. KeSynchronizeExecution (
  12695. IN PKINTERRUPT Interrupt,
  12696. IN PKSYNCHRONIZE_ROUTINE SynchronizeRoutine,
  12697. IN PVOID SynchronizeContext
  12698. );
  12699. NTKERNELAPI
  12700. KIRQL
  12701. KeAcquireInterruptSpinLock (
  12702. IN PKINTERRUPT Interrupt
  12703. );
  12704. NTKERNELAPI
  12705. VOID
  12706. KeReleaseInterruptSpinLock (
  12707. IN PKINTERRUPT Interrupt,
  12708. IN KIRQL OldIrql
  12709. );
  12710. //
  12711. // Kernel dispatcher object functions
  12712. //
  12713. // Event Object
  12714. //
  12715. NTKERNELAPI
  12716. VOID
  12717. KeInitializeEvent (
  12718. IN PRKEVENT Event,
  12719. IN EVENT_TYPE Type,
  12720. IN BOOLEAN State
  12721. );
  12722. NTKERNELAPI
  12723. VOID
  12724. KeClearEvent (
  12725. IN PRKEVENT Event
  12726. );
  12727. NTKERNELAPI
  12728. LONG
  12729. KeReadStateEvent (
  12730. IN PRKEVENT Event
  12731. );
  12732. NTKERNELAPI
  12733. LONG
  12734. KeResetEvent (
  12735. IN PRKEVENT Event
  12736. );
  12737. NTKERNELAPI
  12738. LONG
  12739. KeSetEvent (
  12740. IN PRKEVENT Event,
  12741. IN KPRIORITY Increment,
  12742. IN BOOLEAN Wait
  12743. );
  12744. //
  12745. // Mutex object
  12746. //
  12747. NTKERNELAPI
  12748. VOID
  12749. KeInitializeMutex (
  12750. IN PRKMUTEX Mutex,
  12751. IN ULONG Level
  12752. );
  12753. NTKERNELAPI
  12754. LONG
  12755. KeReadStateMutex (
  12756. IN PRKMUTEX Mutex
  12757. );
  12758. NTKERNELAPI
  12759. LONG
  12760. KeReleaseMutex (
  12761. IN PRKMUTEX Mutex,
  12762. IN BOOLEAN Wait
  12763. );
  12764. // end_ntddk end_wdm
  12765. //
  12766. // Queue Object.
  12767. //
  12768. NTKERNELAPI
  12769. VOID
  12770. KeInitializeQueue (
  12771. IN PRKQUEUE Queue,
  12772. IN ULONG Count OPTIONAL
  12773. );
  12774. NTKERNELAPI
  12775. LONG
  12776. KeReadStateQueue (
  12777. IN PRKQUEUE Queue
  12778. );
  12779. NTKERNELAPI
  12780. LONG
  12781. KeInsertQueue (
  12782. IN PRKQUEUE Queue,
  12783. IN PLIST_ENTRY Entry
  12784. );
  12785. NTKERNELAPI
  12786. LONG
  12787. KeInsertHeadQueue (
  12788. IN PRKQUEUE Queue,
  12789. IN PLIST_ENTRY Entry
  12790. );
  12791. NTKERNELAPI
  12792. PLIST_ENTRY
  12793. KeRemoveQueue (
  12794. IN PRKQUEUE Queue,
  12795. IN KPROCESSOR_MODE WaitMode,
  12796. IN PLARGE_INTEGER Timeout OPTIONAL
  12797. );
  12798. PLIST_ENTRY
  12799. KeRundownQueue (
  12800. IN PRKQUEUE Queue
  12801. );
  12802. // begin_ntddk begin_wdm
  12803. //
  12804. // Semaphore object
  12805. //
  12806. NTKERNELAPI
  12807. VOID
  12808. KeInitializeSemaphore (
  12809. IN PRKSEMAPHORE Semaphore,
  12810. IN LONG Count,
  12811. IN LONG Limit
  12812. );
  12813. NTKERNELAPI
  12814. LONG
  12815. KeReadStateSemaphore (
  12816. IN PRKSEMAPHORE Semaphore
  12817. );
  12818. NTKERNELAPI
  12819. LONG
  12820. KeReleaseSemaphore (
  12821. IN PRKSEMAPHORE Semaphore,
  12822. IN KPRIORITY Increment,
  12823. IN LONG Adjustment,
  12824. IN BOOLEAN Wait
  12825. );
  12826. NTKERNELAPI
  12827. NTSTATUS
  12828. KeDelayExecutionThread (
  12829. IN KPROCESSOR_MODE WaitMode,
  12830. IN BOOLEAN Alertable,
  12831. IN PLARGE_INTEGER Interval
  12832. );
  12833. NTKERNELAPI
  12834. KPRIORITY
  12835. KeQueryPriorityThread (
  12836. IN PKTHREAD Thread
  12837. );
  12838. NTKERNELAPI
  12839. ULONG
  12840. KeQueryRuntimeThread (
  12841. IN PKTHREAD Thread,
  12842. OUT PULONG UserTime
  12843. );
  12844. VOID
  12845. KeRevertToUserAffinityThread (
  12846. VOID
  12847. );
  12848. VOID
  12849. KeSetSystemAffinityThread (
  12850. IN KAFFINITY Affinity
  12851. );
  12852. NTKERNELAPI
  12853. LONG
  12854. KeSetBasePriorityThread (
  12855. IN PKTHREAD Thread,
  12856. IN LONG Increment
  12857. );
  12858. NTKERNELAPI
  12859. KPRIORITY
  12860. KeSetPriorityThread (
  12861. IN PKTHREAD Thread,
  12862. IN KPRIORITY Priority
  12863. );
  12864. #if ((defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_) ||defined(_NTHAL_)) && !defined(_NTSYSTEM_DRIVER_) || defined(_NTOSP_))
  12865. // begin_wdm
  12866. NTKERNELAPI
  12867. VOID
  12868. KeEnterCriticalRegion (
  12869. VOID
  12870. );
  12871. NTKERNELAPI
  12872. VOID
  12873. KeLeaveCriticalRegion (
  12874. VOID
  12875. );
  12876. NTKERNELAPI
  12877. BOOLEAN
  12878. KeAreApcsDisabled (
  12879. VOID
  12880. );
  12881. // end_wdm
  12882. #endif
  12883. // begin_wdm
  12884. //
  12885. // Timer object
  12886. //
  12887. NTKERNELAPI
  12888. VOID
  12889. KeInitializeTimer (
  12890. IN PKTIMER Timer
  12891. );
  12892. NTKERNELAPI
  12893. VOID
  12894. KeInitializeTimerEx (
  12895. IN PKTIMER Timer,
  12896. IN TIMER_TYPE Type
  12897. );
  12898. NTKERNELAPI
  12899. BOOLEAN
  12900. KeCancelTimer (
  12901. IN PKTIMER
  12902. );
  12903. NTKERNELAPI
  12904. BOOLEAN
  12905. KeReadStateTimer (
  12906. PKTIMER Timer
  12907. );
  12908. NTKERNELAPI
  12909. BOOLEAN
  12910. KeSetTimer (
  12911. IN PKTIMER Timer,
  12912. IN LARGE_INTEGER DueTime,
  12913. IN PKDPC Dpc OPTIONAL
  12914. );
  12915. NTKERNELAPI
  12916. BOOLEAN
  12917. KeSetTimerEx (
  12918. IN PKTIMER Timer,
  12919. IN LARGE_INTEGER DueTime,
  12920. IN LONG Period OPTIONAL,
  12921. IN PKDPC Dpc OPTIONAL
  12922. );
  12923. #define KeWaitForMutexObject KeWaitForSingleObject
  12924. NTKERNELAPI
  12925. NTSTATUS
  12926. KeWaitForMultipleObjects (
  12927. IN ULONG Count,
  12928. IN PVOID Object[],
  12929. IN WAIT_TYPE WaitType,
  12930. IN KWAIT_REASON WaitReason,
  12931. IN KPROCESSOR_MODE WaitMode,
  12932. IN BOOLEAN Alertable,
  12933. IN PLARGE_INTEGER Timeout OPTIONAL,
  12934. IN PKWAIT_BLOCK WaitBlockArray OPTIONAL
  12935. );
  12936. NTKERNELAPI
  12937. NTSTATUS
  12938. KeWaitForSingleObject (
  12939. IN PVOID Object,
  12940. IN KWAIT_REASON WaitReason,
  12941. IN KPROCESSOR_MODE WaitMode,
  12942. IN BOOLEAN Alertable,
  12943. IN PLARGE_INTEGER Timeout OPTIONAL
  12944. );
  12945. //
  12946. // Define interprocess interrupt generic call types.
  12947. //
  12948. typedef
  12949. ULONG_PTR
  12950. (*PKIPI_BROADCAST_WORKER)(
  12951. IN ULONG_PTR Argument
  12952. );
  12953. ULONG_PTR
  12954. KeIpiGenericCall (
  12955. IN PKIPI_BROADCAST_WORKER BroadcastFunction,
  12956. IN ULONG_PTR Context
  12957. );
  12958. //
  12959. // On X86 the following routines are defined in the HAL and imported by
  12960. // all other modules.
  12961. //
  12962. #if defined(_X86_) && !defined(_NTHAL_)
  12963. #define _DECL_HAL_KE_IMPORT __declspec(dllimport)
  12964. #else
  12965. #define _DECL_HAL_KE_IMPORT
  12966. #endif
  12967. //
  12968. // spin lock functions
  12969. //
  12970. #if defined(_X86_) && (defined(_WDMDDK_) || defined(WIN9X_COMPAT_SPINLOCK))
  12971. NTKERNELAPI
  12972. VOID
  12973. NTAPI
  12974. KeInitializeSpinLock (
  12975. IN PKSPIN_LOCK SpinLock
  12976. );
  12977. #else
  12978. __inline
  12979. VOID
  12980. NTAPI
  12981. KeInitializeSpinLock (
  12982. IN PKSPIN_LOCK SpinLock
  12983. )
  12984. {
  12985. *SpinLock = 0;
  12986. }
  12987. #endif
  12988. #if defined(_X86_)
  12989. NTKERNELAPI
  12990. VOID
  12991. FASTCALL
  12992. KefAcquireSpinLockAtDpcLevel (
  12993. IN PKSPIN_LOCK SpinLock
  12994. );
  12995. NTKERNELAPI
  12996. VOID
  12997. FASTCALL
  12998. KefReleaseSpinLockFromDpcLevel (
  12999. IN PKSPIN_LOCK SpinLock
  13000. );
  13001. #define KeAcquireSpinLockAtDpcLevel(a) KefAcquireSpinLockAtDpcLevel(a)
  13002. #define KeReleaseSpinLockFromDpcLevel(a) KefReleaseSpinLockFromDpcLevel(a)
  13003. _DECL_HAL_KE_IMPORT
  13004. KIRQL
  13005. FASTCALL
  13006. KfAcquireSpinLock (
  13007. IN PKSPIN_LOCK SpinLock
  13008. );
  13009. _DECL_HAL_KE_IMPORT
  13010. VOID
  13011. FASTCALL
  13012. KfReleaseSpinLock (
  13013. IN PKSPIN_LOCK SpinLock,
  13014. IN KIRQL NewIrql
  13015. );
  13016. // end_wdm end_ntddk
  13017. _DECL_HAL_KE_IMPORT
  13018. KIRQL
  13019. FASTCALL
  13020. KeAcquireSpinLockRaiseToSynch (
  13021. IN PKSPIN_LOCK SpinLock
  13022. );
  13023. // begin_wdm begin_ntddk
  13024. #define KeAcquireSpinLock(a,b) *(b) = KfAcquireSpinLock(a)
  13025. #define KeReleaseSpinLock(a,b) KfReleaseSpinLock(a,b)
  13026. NTKERNELAPI
  13027. BOOLEAN
  13028. FASTCALL
  13029. KeTestSpinLock (
  13030. IN PKSPIN_LOCK SpinLock
  13031. );
  13032. NTKERNELAPI
  13033. BOOLEAN
  13034. FASTCALL
  13035. KeTryToAcquireSpinLockAtDpcLevel (
  13036. IN PKSPIN_LOCK SpinLock
  13037. );
  13038. #else
  13039. //
  13040. // These functions are imported for IA64, ntddk, ntifs, nthal, ntosp, and wdm.
  13041. // They can be inlined for the system on AMD64.
  13042. //
  13043. #define KeAcquireSpinLock(SpinLock, OldIrql) \
  13044. *(OldIrql) = KeAcquireSpinLockRaiseToDpc(SpinLock)
  13045. #if defined(_IA64_) || defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_) || defined(_NTHAL_) || defined(_NTOSP_) || defined(_WDMDDK_)
  13046. // end_wdm end_ntddk
  13047. NTKERNELAPI
  13048. KIRQL
  13049. FASTCALL
  13050. KeAcquireSpinLockRaiseToSynch (
  13051. IN PKSPIN_LOCK SpinLock
  13052. );
  13053. // begin_wdm begin_ntddk
  13054. NTKERNELAPI
  13055. VOID
  13056. KeAcquireSpinLockAtDpcLevel (
  13057. IN PKSPIN_LOCK SpinLock
  13058. );
  13059. NTKERNELAPI
  13060. KIRQL
  13061. KeAcquireSpinLockRaiseToDpc (
  13062. IN PKSPIN_LOCK SpinLock
  13063. );
  13064. NTKERNELAPI
  13065. VOID
  13066. KeReleaseSpinLock (
  13067. IN PKSPIN_LOCK SpinLock,
  13068. IN KIRQL NewIrql
  13069. );
  13070. NTKERNELAPI
  13071. VOID
  13072. KeReleaseSpinLockFromDpcLevel (
  13073. IN PKSPIN_LOCK SpinLock
  13074. );
  13075. NTKERNELAPI
  13076. BOOLEAN
  13077. FASTCALL
  13078. KeTestSpinLock (
  13079. IN PKSPIN_LOCK SpinLock
  13080. );
  13081. NTKERNELAPI
  13082. BOOLEAN
  13083. FASTCALL
  13084. KeTryToAcquireSpinLockAtDpcLevel (
  13085. IN PKSPIN_LOCK SpinLock
  13086. );
  13087. #else
  13088. #if defined(_AMD64_)
  13089. //
  13090. // The system version of these functions are defined in amd64.h for AMD64.
  13091. //
  13092. #endif
  13093. #endif
  13094. #endif
  13095. //
  13096. NTKERNELAPI
  13097. BOOLEAN
  13098. KeDisableInterrupts (
  13099. VOID
  13100. );
  13101. NTKERNELAPI
  13102. VOID
  13103. KeEnableInterrupts (
  13104. IN BOOLEAN Enable
  13105. );
  13106. #if defined(_X86_)
  13107. _DECL_HAL_KE_IMPORT
  13108. VOID
  13109. FASTCALL
  13110. KfLowerIrql (
  13111. IN KIRQL NewIrql
  13112. );
  13113. _DECL_HAL_KE_IMPORT
  13114. KIRQL
  13115. FASTCALL
  13116. KfRaiseIrql (
  13117. IN KIRQL NewIrql
  13118. );
  13119. // end_wdm
  13120. _DECL_HAL_KE_IMPORT
  13121. KIRQL
  13122. KeRaiseIrqlToDpcLevel(
  13123. VOID
  13124. );
  13125. // end_ntddk
  13126. _DECL_HAL_KE_IMPORT
  13127. KIRQL
  13128. KeRaiseIrqlToSynchLevel(
  13129. VOID
  13130. );
  13131. // begin_wdm begin_ntddk
  13132. #define KeLowerIrql(a) KfLowerIrql(a)
  13133. #define KeRaiseIrql(a,b) *(b) = KfRaiseIrql(a)
  13134. // end_wdm
  13135. // begin_wdm
  13136. #elif defined(_IA64_)
  13137. //
  13138. // These function are defined in IA64.h for the IA64 platform.
  13139. //
  13140. #elif defined(_AMD64_)
  13141. //
  13142. // These function are defined in amd64.h for the AMD64 platform.
  13143. //
  13144. #else
  13145. #error "no target architecture"
  13146. #endif
  13147. //
  13148. // Queued spin lock functions for "in stack" lock handles.
  13149. //
  13150. // The following three functions RAISE and LOWER IRQL when a queued
  13151. // in stack spin lock is acquired or released using these routines.
  13152. //
  13153. _DECL_HAL_KE_IMPORT
  13154. VOID
  13155. FASTCALL
  13156. KeAcquireInStackQueuedSpinLock (
  13157. IN PKSPIN_LOCK SpinLock,
  13158. IN PKLOCK_QUEUE_HANDLE LockHandle
  13159. );
  13160. _DECL_HAL_KE_IMPORT
  13161. VOID
  13162. FASTCALL
  13163. KeReleaseInStackQueuedSpinLock (
  13164. IN PKLOCK_QUEUE_HANDLE LockHandle
  13165. );
  13166. //
  13167. // The following two functions do NOT raise or lower IRQL when a queued
  13168. // in stack spin lock is acquired or released using these functions.
  13169. //
  13170. NTKERNELAPI
  13171. VOID
  13172. FASTCALL
  13173. KeAcquireInStackQueuedSpinLockAtDpcLevel (
  13174. IN PKSPIN_LOCK SpinLock,
  13175. IN PKLOCK_QUEUE_HANDLE LockHandle
  13176. );
  13177. NTKERNELAPI
  13178. VOID
  13179. FASTCALL
  13180. KeReleaseInStackQueuedSpinLockFromDpcLevel (
  13181. IN PKLOCK_QUEUE_HANDLE LockHandle
  13182. );
  13183. //
  13184. // Miscellaneous kernel functions
  13185. //
  13186. typedef enum _KBUGCHECK_BUFFER_DUMP_STATE {
  13187. BufferEmpty,
  13188. BufferInserted,
  13189. BufferStarted,
  13190. BufferFinished,
  13191. BufferIncomplete
  13192. } KBUGCHECK_BUFFER_DUMP_STATE;
  13193. typedef
  13194. VOID
  13195. (*PKBUGCHECK_CALLBACK_ROUTINE) (
  13196. IN PVOID Buffer,
  13197. IN ULONG Length
  13198. );
  13199. typedef struct _KBUGCHECK_CALLBACK_RECORD {
  13200. LIST_ENTRY Entry;
  13201. PKBUGCHECK_CALLBACK_ROUTINE CallbackRoutine;
  13202. PVOID Buffer;
  13203. ULONG Length;
  13204. PUCHAR Component;
  13205. ULONG_PTR Checksum;
  13206. UCHAR State;
  13207. } KBUGCHECK_CALLBACK_RECORD, *PKBUGCHECK_CALLBACK_RECORD;
  13208. #define KeInitializeCallbackRecord(CallbackRecord) \
  13209. (CallbackRecord)->State = BufferEmpty
  13210. NTKERNELAPI
  13211. BOOLEAN
  13212. KeDeregisterBugCheckCallback (
  13213. IN PKBUGCHECK_CALLBACK_RECORD CallbackRecord
  13214. );
  13215. NTKERNELAPI
  13216. BOOLEAN
  13217. KeRegisterBugCheckCallback (
  13218. IN PKBUGCHECK_CALLBACK_RECORD CallbackRecord,
  13219. IN PKBUGCHECK_CALLBACK_ROUTINE CallbackRoutine,
  13220. IN PVOID Buffer,
  13221. IN ULONG Length,
  13222. IN PUCHAR Component
  13223. );
  13224. typedef enum _KBUGCHECK_CALLBACK_REASON {
  13225. KbCallbackInvalid,
  13226. KbCallbackReserved1,
  13227. KbCallbackSecondaryDumpData,
  13228. KbCallbackDumpIo,
  13229. } KBUGCHECK_CALLBACK_REASON;
  13230. typedef
  13231. VOID
  13232. (*PKBUGCHECK_REASON_CALLBACK_ROUTINE) (
  13233. IN KBUGCHECK_CALLBACK_REASON Reason,
  13234. IN struct _KBUGCHECK_REASON_CALLBACK_RECORD* Record,
  13235. IN OUT PVOID ReasonSpecificData,
  13236. IN ULONG ReasonSpecificDataLength
  13237. );
  13238. typedef struct _KBUGCHECK_REASON_CALLBACK_RECORD {
  13239. LIST_ENTRY Entry;
  13240. PKBUGCHECK_REASON_CALLBACK_ROUTINE CallbackRoutine;
  13241. PUCHAR Component;
  13242. ULONG_PTR Checksum;
  13243. KBUGCHECK_CALLBACK_REASON Reason;
  13244. UCHAR State;
  13245. } KBUGCHECK_REASON_CALLBACK_RECORD, *PKBUGCHECK_REASON_CALLBACK_RECORD;
  13246. typedef struct _KBUGCHECK_SECONDARY_DUMP_DATA {
  13247. IN PVOID InBuffer;
  13248. IN ULONG InBufferLength;
  13249. IN ULONG MaximumAllowed;
  13250. OUT GUID Guid;
  13251. OUT PVOID OutBuffer;
  13252. OUT ULONG OutBufferLength;
  13253. } KBUGCHECK_SECONDARY_DUMP_DATA, *PKBUGCHECK_SECONDARY_DUMP_DATA;
  13254. typedef enum _KBUGCHECK_DUMP_IO_TYPE
  13255. {
  13256. KbDumpIoInvalid,
  13257. KbDumpIoHeader,
  13258. KbDumpIoBody,
  13259. KbDumpIoSecondaryData,
  13260. KbDumpIoComplete
  13261. } KBUGCHECK_DUMP_IO_TYPE;
  13262. typedef struct _KBUGCHECK_DUMP_IO {
  13263. IN ULONG64 Offset;
  13264. IN PVOID Buffer;
  13265. IN ULONG BufferLength;
  13266. IN KBUGCHECK_DUMP_IO_TYPE Type;
  13267. } KBUGCHECK_DUMP_IO, *PKBUGCHECK_DUMP_IO;
  13268. NTKERNELAPI
  13269. BOOLEAN
  13270. KeDeregisterBugCheckReasonCallback (
  13271. IN PKBUGCHECK_REASON_CALLBACK_RECORD CallbackRecord
  13272. );
  13273. NTKERNELAPI
  13274. BOOLEAN
  13275. KeRegisterBugCheckReasonCallback (
  13276. IN PKBUGCHECK_REASON_CALLBACK_RECORD CallbackRecord,
  13277. IN PKBUGCHECK_REASON_CALLBACK_ROUTINE CallbackRoutine,
  13278. IN KBUGCHECK_CALLBACK_REASON Reason,
  13279. IN PUCHAR Component
  13280. );
  13281. typedef
  13282. BOOLEAN
  13283. (*PNMI_CALLBACK)(
  13284. IN PVOID Context,
  13285. IN BOOLEAN Handled
  13286. );
  13287. NTKERNELAPI
  13288. PVOID
  13289. KeRegisterNmiCallback(
  13290. PNMI_CALLBACK CallbackRoutine,
  13291. PVOID Context
  13292. );
  13293. NTSTATUS
  13294. KeDeregisterNmiCallback(
  13295. PVOID Handle
  13296. );
  13297. // end_wdm
  13298. NTKERNELAPI
  13299. DECLSPEC_NORETURN
  13300. VOID
  13301. NTAPI
  13302. KeBugCheck (
  13303. IN ULONG BugCheckCode
  13304. );
  13305. NTKERNELAPI
  13306. DECLSPEC_NORETURN
  13307. VOID
  13308. KeBugCheckEx(
  13309. IN ULONG BugCheckCode,
  13310. IN ULONG_PTR BugCheckParameter1,
  13311. IN ULONG_PTR BugCheckParameter2,
  13312. IN ULONG_PTR BugCheckParameter3,
  13313. IN ULONG_PTR BugCheckParameter4
  13314. );
  13315. // end_ntddk end_wdm end_ntifs end_ntosp
  13316. NTKERNELAPI
  13317. VOID
  13318. KeEnterKernelDebugger (
  13319. VOID
  13320. );
  13321. VOID
  13322. __cdecl
  13323. KeSaveStateForHibernate(
  13324. IN PKPROCESSOR_STATE ProcessorState
  13325. );
  13326. BOOLEAN
  13327. KiIpiServiceRoutine (
  13328. IN struct _KTRAP_FRAME *TrapFrame,
  13329. IN struct _KEXCEPTION_FRAME *ExceptionFrame
  13330. );
  13331. #define DMA_READ_DCACHE_INVALIDATE 0x1
  13332. #define DMA_READ_ICACHE_INVALIDATE 0x2
  13333. #define DMA_WRITE_DCACHE_SNOOP 0x4
  13334. NTKERNELAPI
  13335. VOID
  13336. KeSetDmaIoCoherency (
  13337. IN ULONG Attributes
  13338. );
  13339. NTKERNELAPI
  13340. VOID
  13341. KeSetProfileIrql (
  13342. IN KIRQL ProfileIrql
  13343. );
  13344. #if !defined(_AMD64_)
  13345. NTKERNELAPI
  13346. ULONGLONG
  13347. KeQueryInterruptTime (
  13348. VOID
  13349. );
  13350. NTKERNELAPI
  13351. VOID
  13352. KeQuerySystemTime (
  13353. OUT PLARGE_INTEGER CurrentTime
  13354. );
  13355. #endif
  13356. NTKERNELAPI
  13357. ULONG
  13358. KeQueryTimeIncrement (
  13359. VOID
  13360. );
  13361. NTKERNELAPI
  13362. ULONG
  13363. KeGetRecommendedSharedDataAlignment (
  13364. VOID
  13365. );
  13366. // end_wdm
  13367. NTKERNELAPI
  13368. KAFFINITY
  13369. KeQueryActiveProcessors (
  13370. VOID
  13371. );
  13372. NTKERNELAPI
  13373. VOID
  13374. KeSetTimeIncrement (
  13375. IN ULONG MaximumIncrement,
  13376. IN ULONG MimimumIncrement
  13377. );
  13378. //
  13379. // Define the firmware routine types
  13380. //
  13381. typedef enum _FIRMWARE_REENTRY {
  13382. HalHaltRoutine,
  13383. HalPowerDownRoutine,
  13384. HalRestartRoutine,
  13385. HalRebootRoutine,
  13386. HalInteractiveModeRoutine,
  13387. HalMaximumRoutine
  13388. } FIRMWARE_REENTRY, *PFIRMWARE_REENTRY;
  13389. //
  13390. // Find ARC configuration information function.
  13391. //
  13392. NTKERNELAPI
  13393. PCONFIGURATION_COMPONENT_DATA
  13394. KeFindConfigurationEntry (
  13395. IN PCONFIGURATION_COMPONENT_DATA Child,
  13396. IN CONFIGURATION_CLASS Class,
  13397. IN CONFIGURATION_TYPE Type,
  13398. IN PULONG Key OPTIONAL
  13399. );
  13400. NTKERNELAPI
  13401. PCONFIGURATION_COMPONENT_DATA
  13402. KeFindConfigurationNextEntry (
  13403. IN PCONFIGURATION_COMPONENT_DATA Child,
  13404. IN CONFIGURATION_CLASS Class,
  13405. IN CONFIGURATION_TYPE Type,
  13406. IN PULONG Key OPTIONAL,
  13407. IN PCONFIGURATION_COMPONENT_DATA *Resume
  13408. );
  13409. extern NTSYSAPI CCHAR KeNumberProcessors;
  13410. #if defined(_IA64_)
  13411. extern volatile LARGE_INTEGER KeTickCount;
  13412. #elif defined(_X86_)
  13413. extern volatile KSYSTEM_TIME KeTickCount;
  13414. #endif
  13415. extern PVOID KeUserApcDispatcher;
  13416. extern PVOID KeUserCallbackDispatcher;
  13417. extern PVOID KeUserExceptionDispatcher;
  13418. extern PVOID KeRaiseUserExceptionDispatcher;
  13419. extern ULONG KeTimeAdjustment;
  13420. extern ULONG KeTimeIncrement;
  13421. extern BOOLEAN KeTimeSynchronization;
  13422. typedef enum _MEMORY_CACHING_TYPE_ORIG {
  13423. MmFrameBufferCached = 2
  13424. } MEMORY_CACHING_TYPE_ORIG;
  13425. typedef enum _MEMORY_CACHING_TYPE {
  13426. MmNonCached = FALSE,
  13427. MmCached = TRUE,
  13428. MmWriteCombined = MmFrameBufferCached,
  13429. MmHardwareCoherentCached,
  13430. MmNonCachedUnordered, // IA64
  13431. MmUSWCCached,
  13432. MmMaximumCacheType
  13433. } MEMORY_CACHING_TYPE;
  13434. //
  13435. // Define the number of debugging devices we support
  13436. //
  13437. #define MAX_DEBUGGING_DEVICES_SUPPORTED 2
  13438. //
  13439. // Status Constants for reading data from comport
  13440. //
  13441. #define CP_GET_SUCCESS 0
  13442. #define CP_GET_NODATA 1
  13443. #define CP_GET_ERROR 2
  13444. //
  13445. // Defines the debug port parameters for kernel debugger
  13446. // CommunicationPort - specify which COM port to use as debugging port
  13447. // 0 - use default; N - use COM N.
  13448. // BaudRate - the baud rate used to initialize debugging port
  13449. // 0 - use default rate.
  13450. //
  13451. typedef struct _DEBUG_PARAMETERS {
  13452. ULONG CommunicationPort;
  13453. ULONG BaudRate;
  13454. } DEBUG_PARAMETERS, *PDEBUG_PARAMETERS;
  13455. //
  13456. // Define external data.
  13457. // because of indirection for all drivers external to ntoskrnl these are actually ptrs
  13458. //
  13459. #if defined(_NTDDK_) || defined(_NTIFS_) || defined(_NTHAL_) || defined(_WDMDDK_) || defined(_NTOSP_)
  13460. extern PBOOLEAN KdDebuggerNotPresent;
  13461. extern PBOOLEAN KdDebuggerEnabled;
  13462. #define KD_DEBUGGER_ENABLED *KdDebuggerEnabled
  13463. #define KD_DEBUGGER_NOT_PRESENT *KdDebuggerNotPresent
  13464. #else
  13465. extern BOOLEAN KdDebuggerNotPresent;
  13466. extern BOOLEAN KdDebuggerEnabled;
  13467. #define KD_DEBUGGER_ENABLED KdDebuggerEnabled
  13468. #define KD_DEBUGGER_NOT_PRESENT KdDebuggerNotPresent
  13469. #endif
  13470. NTSTATUS
  13471. KdDisableDebugger(
  13472. VOID
  13473. );
  13474. NTSTATUS
  13475. KdEnableDebugger(
  13476. VOID
  13477. );
  13478. //
  13479. // KdRefreshDebuggerPresent attempts to communicate with
  13480. // the debugger host machine to refresh the state of
  13481. // KdDebuggerNotPresent. It returns the state of
  13482. // KdDebuggerNotPresent while the kd locks are held.
  13483. // KdDebuggerNotPresent may immediately change state
  13484. // after the kd locks are released so it may not
  13485. // match the return value.
  13486. //
  13487. BOOLEAN
  13488. KdRefreshDebuggerNotPresent(
  13489. VOID
  13490. );
  13491. //
  13492. // Pool Allocation routines (in pool.c)
  13493. //
  13494. typedef enum _POOL_TYPE {
  13495. NonPagedPool,
  13496. PagedPool,
  13497. NonPagedPoolMustSucceed,
  13498. DontUseThisType,
  13499. NonPagedPoolCacheAligned,
  13500. PagedPoolCacheAligned,
  13501. NonPagedPoolCacheAlignedMustS,
  13502. MaxPoolType
  13503. // end_wdm
  13504. ,
  13505. //
  13506. // Note these per session types are carefully chosen so that the appropriate
  13507. // masking still applies as well as MaxPoolType above.
  13508. //
  13509. NonPagedPoolSession = 32,
  13510. PagedPoolSession = NonPagedPoolSession + 1,
  13511. NonPagedPoolMustSucceedSession = PagedPoolSession + 1,
  13512. DontUseThisTypeSession = NonPagedPoolMustSucceedSession + 1,
  13513. NonPagedPoolCacheAlignedSession = DontUseThisTypeSession + 1,
  13514. PagedPoolCacheAlignedSession = NonPagedPoolCacheAlignedSession + 1,
  13515. NonPagedPoolCacheAlignedMustSSession = PagedPoolCacheAlignedSession + 1,
  13516. // begin_wdm
  13517. } POOL_TYPE;
  13518. #define POOL_COLD_ALLOCATION 256 // Note this cannot encode into the header.
  13519. DECLSPEC_DEPRECATED_DDK // Use ExAllocatePoolWithTag
  13520. NTKERNELAPI
  13521. PVOID
  13522. ExAllocatePool(
  13523. IN POOL_TYPE PoolType,
  13524. IN SIZE_T NumberOfBytes
  13525. );
  13526. DECLSPEC_DEPRECATED_DDK // Use ExAllocatePoolWithQuotaTag
  13527. NTKERNELAPI
  13528. PVOID
  13529. ExAllocatePoolWithQuota(
  13530. IN POOL_TYPE PoolType,
  13531. IN SIZE_T NumberOfBytes
  13532. );
  13533. NTKERNELAPI
  13534. PVOID
  13535. NTAPI
  13536. ExAllocatePoolWithTag(
  13537. IN POOL_TYPE PoolType,
  13538. IN SIZE_T NumberOfBytes,
  13539. IN ULONG Tag
  13540. );
  13541. //
  13542. // _EX_POOL_PRIORITY_ provides a method for the system to handle requests
  13543. // intelligently in low resource conditions.
  13544. //
  13545. // LowPoolPriority should be used when it is acceptable to the driver for the
  13546. // mapping request to fail if the system is low on resources. An example of
  13547. // this could be for a non-critical network connection where the driver can
  13548. // handle the failure case when system resources are close to being depleted.
  13549. //
  13550. // NormalPoolPriority should be used when it is acceptable to the driver for the
  13551. // mapping request to fail if the system is very low on resources. An example
  13552. // of this could be for a non-critical local filesystem request.
  13553. //
  13554. // HighPoolPriority should be used when it is unacceptable to the driver for the
  13555. // mapping request to fail unless the system is completely out of resources.
  13556. // An example of this would be the paging file path in a driver.
  13557. //
  13558. // SpecialPool can be specified to bound the allocation at a page end (or
  13559. // beginning). This should only be done on systems being debugged as the
  13560. // memory cost is expensive.
  13561. //
  13562. // N.B. These values are very carefully chosen so that the pool allocation
  13563. // code can quickly crack the priority request.
  13564. //
  13565. typedef enum _EX_POOL_PRIORITY {
  13566. LowPoolPriority,
  13567. LowPoolPrioritySpecialPoolOverrun = 8,
  13568. LowPoolPrioritySpecialPoolUnderrun = 9,
  13569. NormalPoolPriority = 16,
  13570. NormalPoolPrioritySpecialPoolOverrun = 24,
  13571. NormalPoolPrioritySpecialPoolUnderrun = 25,
  13572. HighPoolPriority = 32,
  13573. HighPoolPrioritySpecialPoolOverrun = 40,
  13574. HighPoolPrioritySpecialPoolUnderrun = 41
  13575. } EX_POOL_PRIORITY;
  13576. NTKERNELAPI
  13577. PVOID
  13578. NTAPI
  13579. ExAllocatePoolWithTagPriority(
  13580. IN POOL_TYPE PoolType,
  13581. IN SIZE_T NumberOfBytes,
  13582. IN ULONG Tag,
  13583. IN EX_POOL_PRIORITY Priority
  13584. );
  13585. #ifndef POOL_TAGGING
  13586. #define ExAllocatePoolWithTag(a,b,c) ExAllocatePool(a,b)
  13587. #endif //POOL_TAGGING
  13588. NTKERNELAPI
  13589. PVOID
  13590. ExAllocatePoolWithQuotaTag(
  13591. IN POOL_TYPE PoolType,
  13592. IN SIZE_T NumberOfBytes,
  13593. IN ULONG Tag
  13594. );
  13595. #ifndef POOL_TAGGING
  13596. #define ExAllocatePoolWithQuotaTag(a,b,c) ExAllocatePoolWithQuota(a,b)
  13597. #endif //POOL_TAGGING
  13598. NTKERNELAPI
  13599. VOID
  13600. NTAPI
  13601. ExFreePool(
  13602. IN PVOID P
  13603. );
  13604. // end_wdm
  13605. #if defined(POOL_TAGGING)
  13606. #define ExFreePool(a) ExFreePoolWithTag(a,0)
  13607. #endif
  13608. //
  13609. // If high order bit in Pool tag is set, then must use ExFreePoolWithTag to free
  13610. //
  13611. #define PROTECTED_POOL 0x80000000
  13612. // begin_wdm
  13613. NTKERNELAPI
  13614. VOID
  13615. ExFreePoolWithTag(
  13616. IN PVOID P,
  13617. IN ULONG Tag
  13618. );
  13619. //
  13620. // Routines to support fast mutexes.
  13621. //
  13622. typedef struct _FAST_MUTEX {
  13623. LONG Count;
  13624. PKTHREAD Owner;
  13625. ULONG Contention;
  13626. KEVENT Event;
  13627. ULONG OldIrql;
  13628. } FAST_MUTEX, *PFAST_MUTEX;
  13629. #define ExInitializeFastMutex(_FastMutex) \
  13630. (_FastMutex)->Count = 1; \
  13631. (_FastMutex)->Owner = NULL; \
  13632. (_FastMutex)->Contention = 0; \
  13633. KeInitializeEvent(&(_FastMutex)->Event, \
  13634. SynchronizationEvent, \
  13635. FALSE);
  13636. NTKERNELAPI
  13637. VOID
  13638. FASTCALL
  13639. ExAcquireFastMutexUnsafe (
  13640. IN PFAST_MUTEX FastMutex
  13641. );
  13642. NTKERNELAPI
  13643. VOID
  13644. FASTCALL
  13645. ExReleaseFastMutexUnsafe (
  13646. IN PFAST_MUTEX FastMutex
  13647. );
  13648. #if defined(_IA64_) || defined(_AMD64_)
  13649. NTKERNELAPI
  13650. VOID
  13651. FASTCALL
  13652. ExAcquireFastMutex (
  13653. IN PFAST_MUTEX FastMutex
  13654. );
  13655. NTKERNELAPI
  13656. VOID
  13657. FASTCALL
  13658. ExReleaseFastMutex (
  13659. IN PFAST_MUTEX FastMutex
  13660. );
  13661. NTKERNELAPI
  13662. BOOLEAN
  13663. FASTCALL
  13664. ExTryToAcquireFastMutex (
  13665. IN PFAST_MUTEX FastMutex
  13666. );
  13667. #elif defined(_X86_)
  13668. NTHALAPI
  13669. VOID
  13670. FASTCALL
  13671. ExAcquireFastMutex (
  13672. IN PFAST_MUTEX FastMutex
  13673. );
  13674. NTHALAPI
  13675. VOID
  13676. FASTCALL
  13677. ExReleaseFastMutex (
  13678. IN PFAST_MUTEX FastMutex
  13679. );
  13680. NTHALAPI
  13681. BOOLEAN
  13682. FASTCALL
  13683. ExTryToAcquireFastMutex (
  13684. IN PFAST_MUTEX FastMutex
  13685. );
  13686. #else
  13687. #error "Target architecture not defined"
  13688. #endif
  13689. //
  13690. #if defined(_WIN64)
  13691. #define ExInterlockedAddLargeStatistic(Addend, Increment) \
  13692. (VOID) InterlockedAdd64(&(Addend)->QuadPart, Increment)
  13693. #else
  13694. #ifdef __cplusplus
  13695. extern "C" {
  13696. #endif
  13697. LONG
  13698. _InterlockedAddLargeStatistic (
  13699. IN PLONGLONG Addend,
  13700. IN ULONG Increment
  13701. );
  13702. #ifdef __cplusplus
  13703. }
  13704. #endif
  13705. #pragma intrinsic (_InterlockedAddLargeStatistic)
  13706. #define ExInterlockedAddLargeStatistic(Addend,Increment) \
  13707. (VOID) _InterlockedAddLargeStatistic ((PLONGLONG)&(Addend)->QuadPart, Increment)
  13708. #endif
  13709. // end_ntndis
  13710. NTKERNELAPI
  13711. LARGE_INTEGER
  13712. ExInterlockedAddLargeInteger (
  13713. IN PLARGE_INTEGER Addend,
  13714. IN LARGE_INTEGER Increment,
  13715. IN PKSPIN_LOCK Lock
  13716. );
  13717. NTKERNELAPI
  13718. ULONG
  13719. FASTCALL
  13720. ExInterlockedAddUlong (
  13721. IN PULONG Addend,
  13722. IN ULONG Increment,
  13723. IN PKSPIN_LOCK Lock
  13724. );
  13725. #if defined(_AMD64_) || defined(_AXP64_) || defined(_IA64_)
  13726. #define ExInterlockedCompareExchange64(Destination, Exchange, Comperand, Lock) \
  13727. InterlockedCompareExchange64(Destination, *(Exchange), *(Comperand))
  13728. #elif defined(_ALPHA_)
  13729. #define ExInterlockedCompareExchange64(Destination, Exchange, Comperand, Lock) \
  13730. ExpInterlockedCompareExchange64(Destination, Exchange, Comperand)
  13731. #else
  13732. #define ExInterlockedCompareExchange64(Destination, Exchange, Comperand, Lock) \
  13733. ExfInterlockedCompareExchange64(Destination, Exchange, Comperand)
  13734. #endif
  13735. NTKERNELAPI
  13736. PLIST_ENTRY
  13737. FASTCALL
  13738. ExInterlockedInsertHeadList (
  13739. IN PLIST_ENTRY ListHead,
  13740. IN PLIST_ENTRY ListEntry,
  13741. IN PKSPIN_LOCK Lock
  13742. );
  13743. NTKERNELAPI
  13744. PLIST_ENTRY
  13745. FASTCALL
  13746. ExInterlockedInsertTailList (
  13747. IN PLIST_ENTRY ListHead,
  13748. IN PLIST_ENTRY ListEntry,
  13749. IN PKSPIN_LOCK Lock
  13750. );
  13751. NTKERNELAPI
  13752. PLIST_ENTRY
  13753. FASTCALL
  13754. ExInterlockedRemoveHeadList (
  13755. IN PLIST_ENTRY ListHead,
  13756. IN PKSPIN_LOCK Lock
  13757. );
  13758. NTKERNELAPI
  13759. PSINGLE_LIST_ENTRY
  13760. FASTCALL
  13761. ExInterlockedPopEntryList (
  13762. IN PSINGLE_LIST_ENTRY ListHead,
  13763. IN PKSPIN_LOCK Lock
  13764. );
  13765. NTKERNELAPI
  13766. PSINGLE_LIST_ENTRY
  13767. FASTCALL
  13768. ExInterlockedPushEntryList (
  13769. IN PSINGLE_LIST_ENTRY ListHead,
  13770. IN PSINGLE_LIST_ENTRY ListEntry,
  13771. IN PKSPIN_LOCK Lock
  13772. );
  13773. //
  13774. // Define interlocked sequenced listhead functions.
  13775. //
  13776. // A sequenced interlocked list is a singly linked list with a header that
  13777. // contains the current depth and a sequence number. Each time an entry is
  13778. // inserted or removed from the list the depth is updated and the sequence
  13779. // number is incremented. This enables AMD64, IA64, and Pentium and later
  13780. // machines to insert and remove from the list without the use of spinlocks.
  13781. //
  13782. #if !defined(_WINBASE_)
  13783. /*++
  13784. Routine Description:
  13785. This function initializes a sequenced singly linked listhead.
  13786. Arguments:
  13787. SListHead - Supplies a pointer to a sequenced singly linked listhead.
  13788. Return Value:
  13789. None.
  13790. --*/
  13791. #if defined(_WIN64) && (defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_) || defined(_NTHAL_) || defined(_NTOSP_))
  13792. NTKERNELAPI
  13793. VOID
  13794. InitializeSListHead (
  13795. IN PSLIST_HEADER SListHead
  13796. );
  13797. #else
  13798. __inline
  13799. VOID
  13800. InitializeSListHead (
  13801. IN PSLIST_HEADER SListHead
  13802. )
  13803. {
  13804. #ifdef _WIN64
  13805. //
  13806. // Slist headers must be 16 byte aligned.
  13807. //
  13808. if ((ULONG_PTR) SListHead & 0x0f) {
  13809. DbgPrint( "InitializeSListHead unaligned Slist header. Address = %p, Caller = %p\n", SListHead, _ReturnAddress());
  13810. RtlRaiseStatus(STATUS_DATATYPE_MISALIGNMENT);
  13811. }
  13812. #endif
  13813. SListHead->Alignment = 0;
  13814. //
  13815. // For IA-64 we save the region number of the elements of the list in a
  13816. // separate field. This imposes the requirement that all elements stored
  13817. // in the list are from the same region.
  13818. #if defined(_IA64_)
  13819. SListHead->Region = (ULONG_PTR)SListHead & VRN_MASK;
  13820. #elif defined(_AMD64_)
  13821. SListHead->Region = 0;
  13822. #endif
  13823. return;
  13824. }
  13825. #endif
  13826. #endif // !defined(_WINBASE_)
  13827. #define ExInitializeSListHead InitializeSListHead
  13828. PSLIST_ENTRY
  13829. FirstEntrySList (
  13830. IN const SLIST_HEADER *SListHead
  13831. );
  13832. /*++
  13833. Routine Description:
  13834. This function queries the current number of entries contained in a
  13835. sequenced single linked list.
  13836. Arguments:
  13837. SListHead - Supplies a pointer to the sequenced listhead which is
  13838. be queried.
  13839. Return Value:
  13840. The current number of entries in the sequenced singly linked list is
  13841. returned as the function value.
  13842. --*/
  13843. #if defined(_WIN64)
  13844. #if (defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_) || defined(_NTHAL_) || defined(_NTOSP_))
  13845. NTKERNELAPI
  13846. USHORT
  13847. ExQueryDepthSList (
  13848. IN PSLIST_HEADER SListHead
  13849. );
  13850. #else
  13851. __inline
  13852. USHORT
  13853. ExQueryDepthSList (
  13854. IN PSLIST_HEADER SListHead
  13855. )
  13856. {
  13857. return (USHORT)(SListHead->Alignment & 0xffff);
  13858. }
  13859. #endif
  13860. #else
  13861. #define ExQueryDepthSList(_listhead_) (_listhead_)->Depth
  13862. #endif
  13863. #if defined(_WIN64)
  13864. #define ExInterlockedPopEntrySList(Head, Lock) \
  13865. ExpInterlockedPopEntrySList(Head)
  13866. #define ExInterlockedPushEntrySList(Head, Entry, Lock) \
  13867. ExpInterlockedPushEntrySList(Head, Entry)
  13868. #define ExInterlockedFlushSList(Head) \
  13869. ExpInterlockedFlushSList(Head)
  13870. #if !defined(_WINBASE_)
  13871. #define InterlockedPopEntrySList(Head) \
  13872. ExpInterlockedPopEntrySList(Head)
  13873. #define InterlockedPushEntrySList(Head, Entry) \
  13874. ExpInterlockedPushEntrySList(Head, Entry)
  13875. #define InterlockedFlushSList(Head) \
  13876. ExpInterlockedFlushSList(Head)
  13877. #define QueryDepthSList(Head) \
  13878. ExQueryDepthSList(Head)
  13879. #endif // !defined(_WINBASE_)
  13880. NTKERNELAPI
  13881. PSLIST_ENTRY
  13882. ExpInterlockedPopEntrySList (
  13883. IN PSLIST_HEADER ListHead
  13884. );
  13885. NTKERNELAPI
  13886. PSLIST_ENTRY
  13887. ExpInterlockedPushEntrySList (
  13888. IN PSLIST_HEADER ListHead,
  13889. IN PSLIST_ENTRY ListEntry
  13890. );
  13891. NTKERNELAPI
  13892. PSLIST_ENTRY
  13893. ExpInterlockedFlushSList (
  13894. IN PSLIST_HEADER ListHead
  13895. );
  13896. #else
  13897. #if defined(_WIN2K_COMPAT_SLIST_USAGE) && defined(_X86_)
  13898. NTKERNELAPI
  13899. PSLIST_ENTRY
  13900. FASTCALL
  13901. ExInterlockedPopEntrySList (
  13902. IN PSLIST_HEADER ListHead,
  13903. IN PKSPIN_LOCK Lock
  13904. );
  13905. NTKERNELAPI
  13906. PSLIST_ENTRY
  13907. FASTCALL
  13908. ExInterlockedPushEntrySList (
  13909. IN PSLIST_HEADER ListHead,
  13910. IN PSLIST_ENTRY ListEntry,
  13911. IN PKSPIN_LOCK Lock
  13912. );
  13913. #else
  13914. #define ExInterlockedPopEntrySList(ListHead, Lock) \
  13915. InterlockedPopEntrySList(ListHead)
  13916. #define ExInterlockedPushEntrySList(ListHead, ListEntry, Lock) \
  13917. InterlockedPushEntrySList(ListHead, ListEntry)
  13918. #endif
  13919. NTKERNELAPI
  13920. PSLIST_ENTRY
  13921. FASTCALL
  13922. ExInterlockedFlushSList (
  13923. IN PSLIST_HEADER ListHead
  13924. );
  13925. #if !defined(_WINBASE_)
  13926. NTKERNELAPI
  13927. PSLIST_ENTRY
  13928. FASTCALL
  13929. InterlockedPopEntrySList (
  13930. IN PSLIST_HEADER ListHead
  13931. );
  13932. NTKERNELAPI
  13933. PSLIST_ENTRY
  13934. FASTCALL
  13935. InterlockedPushEntrySList (
  13936. IN PSLIST_HEADER ListHead,
  13937. IN PSLIST_ENTRY ListEntry
  13938. );
  13939. #define InterlockedFlushSList(Head) \
  13940. ExInterlockedFlushSList(Head)
  13941. #define QueryDepthSList(Head) \
  13942. ExQueryDepthSList(Head)
  13943. #endif // !defined(_WINBASE_)
  13944. #endif // defined(_WIN64)
  13945. // end_ntddk end_wdm end_ntosp
  13946. PSLIST_ENTRY
  13947. FASTCALL
  13948. InterlockedPushListSList (
  13949. IN PSLIST_HEADER ListHead,
  13950. IN PSLIST_ENTRY List,
  13951. IN PSLIST_ENTRY ListEnd,
  13952. IN ULONG Count
  13953. );
  13954. //
  13955. // Define interlocked lookaside list structure and allocation functions.
  13956. //
  13957. VOID
  13958. ExAdjustLookasideDepth (
  13959. VOID
  13960. );
  13961. // begin_ntddk begin_wdm begin_ntosp
  13962. typedef
  13963. PVOID
  13964. (*PALLOCATE_FUNCTION) (
  13965. IN POOL_TYPE PoolType,
  13966. IN SIZE_T NumberOfBytes,
  13967. IN ULONG Tag
  13968. );
  13969. typedef
  13970. VOID
  13971. (*PFREE_FUNCTION) (
  13972. IN PVOID Buffer
  13973. );
  13974. #if !defined(_WIN64) && (defined(_NTDDK_) || defined(_NTIFS_) || defined(_NDIS_))
  13975. typedef struct _GENERAL_LOOKASIDE {
  13976. #else
  13977. typedef struct DECLSPEC_CACHEALIGN _GENERAL_LOOKASIDE {
  13978. #endif
  13979. SLIST_HEADER ListHead;
  13980. USHORT Depth;
  13981. USHORT MaximumDepth;
  13982. ULONG TotalAllocates;
  13983. union {
  13984. ULONG AllocateMisses;
  13985. ULONG AllocateHits;
  13986. };
  13987. ULONG TotalFrees;
  13988. union {
  13989. ULONG FreeMisses;
  13990. ULONG FreeHits;
  13991. };
  13992. POOL_TYPE Type;
  13993. ULONG Tag;
  13994. ULONG Size;
  13995. PALLOCATE_FUNCTION Allocate;
  13996. PFREE_FUNCTION Free;
  13997. LIST_ENTRY ListEntry;
  13998. ULONG LastTotalAllocates;
  13999. union {
  14000. ULONG LastAllocateMisses;
  14001. ULONG LastAllocateHits;
  14002. };
  14003. ULONG Future[2];
  14004. } GENERAL_LOOKASIDE, *PGENERAL_LOOKASIDE;
  14005. #if !defined(_WIN64) && (defined(_NTDDK_) || defined(_NTIFS_) || defined(_NDIS_))
  14006. typedef struct _NPAGED_LOOKASIDE_LIST {
  14007. #else
  14008. typedef struct DECLSPEC_CACHEALIGN _NPAGED_LOOKASIDE_LIST {
  14009. #endif
  14010. GENERAL_LOOKASIDE L;
  14011. #if !defined(_AMD64_) && !defined(_IA64_)
  14012. KSPIN_LOCK Lock__ObsoleteButDoNotDelete;
  14013. #endif
  14014. } NPAGED_LOOKASIDE_LIST, *PNPAGED_LOOKASIDE_LIST;
  14015. NTKERNELAPI
  14016. VOID
  14017. ExInitializeNPagedLookasideList (
  14018. IN PNPAGED_LOOKASIDE_LIST Lookaside,
  14019. IN PALLOCATE_FUNCTION Allocate,
  14020. IN PFREE_FUNCTION Free,
  14021. IN ULONG Flags,
  14022. IN SIZE_T Size,
  14023. IN ULONG Tag,
  14024. IN USHORT Depth
  14025. );
  14026. NTKERNELAPI
  14027. VOID
  14028. ExDeleteNPagedLookasideList (
  14029. IN PNPAGED_LOOKASIDE_LIST Lookaside
  14030. );
  14031. __inline
  14032. PVOID
  14033. ExAllocateFromNPagedLookasideList(
  14034. IN PNPAGED_LOOKASIDE_LIST Lookaside
  14035. )
  14036. /*++
  14037. Routine Description:
  14038. This function removes (pops) the first entry from the specified
  14039. nonpaged lookaside list.
  14040. Arguments:
  14041. Lookaside - Supplies a pointer to a nonpaged lookaside list structure.
  14042. Return Value:
  14043. If an entry is removed from the specified lookaside list, then the
  14044. address of the entry is returned as the function value. Otherwise,
  14045. NULL is returned.
  14046. --*/
  14047. {
  14048. PVOID Entry;
  14049. Lookaside->L.TotalAllocates += 1;
  14050. #if defined(_WIN2K_COMPAT_SLIST_USAGE) && defined(_X86_)
  14051. Entry = ExInterlockedPopEntrySList(&Lookaside->L.ListHead,
  14052. &Lookaside->Lock__ObsoleteButDoNotDelete);
  14053. #else
  14054. Entry = InterlockedPopEntrySList(&Lookaside->L.ListHead);
  14055. #endif
  14056. if (Entry == NULL) {
  14057. Lookaside->L.AllocateMisses += 1;
  14058. Entry = (Lookaside->L.Allocate)(Lookaside->L.Type,
  14059. Lookaside->L.Size,
  14060. Lookaside->L.Tag);
  14061. }
  14062. return Entry;
  14063. }
  14064. __inline
  14065. VOID
  14066. ExFreeToNPagedLookasideList(
  14067. IN PNPAGED_LOOKASIDE_LIST Lookaside,
  14068. IN PVOID Entry
  14069. )
  14070. /*++
  14071. Routine Description:
  14072. This function inserts (pushes) the specified entry into the specified
  14073. nonpaged lookaside list.
  14074. Arguments:
  14075. Lookaside - Supplies a pointer to a nonpaged lookaside list structure.
  14076. Entry - Supples a pointer to the entry that is inserted in the
  14077. lookaside list.
  14078. Return Value:
  14079. None.
  14080. --*/
  14081. {
  14082. Lookaside->L.TotalFrees += 1;
  14083. if (ExQueryDepthSList(&Lookaside->L.ListHead) >= Lookaside->L.Depth) {
  14084. Lookaside->L.FreeMisses += 1;
  14085. (Lookaside->L.Free)(Entry);
  14086. } else {
  14087. #if defined(_WIN2K_COMPAT_SLIST_USAGE) && defined(_X86_)
  14088. ExInterlockedPushEntrySList(&Lookaside->L.ListHead,
  14089. (PSLIST_ENTRY)Entry,
  14090. &Lookaside->Lock__ObsoleteButDoNotDelete);
  14091. #else
  14092. InterlockedPushEntrySList(&Lookaside->L.ListHead,
  14093. (PSLIST_ENTRY)Entry);
  14094. #endif
  14095. }
  14096. return;
  14097. }
  14098. // end_ntndis
  14099. #if !defined(_WIN64) && (defined(_NTDDK_) || defined(_NTIFS_) || defined(_NDIS_))
  14100. typedef struct _PAGED_LOOKASIDE_LIST {
  14101. #else
  14102. typedef struct DECLSPEC_CACHEALIGN _PAGED_LOOKASIDE_LIST {
  14103. #endif
  14104. GENERAL_LOOKASIDE L;
  14105. #if !defined(_AMD64_) && !defined(_IA64_)
  14106. FAST_MUTEX Lock__ObsoleteButDoNotDelete;
  14107. #endif
  14108. } PAGED_LOOKASIDE_LIST, *PPAGED_LOOKASIDE_LIST;
  14109. NTKERNELAPI
  14110. VOID
  14111. ExInitializePagedLookasideList (
  14112. IN PPAGED_LOOKASIDE_LIST Lookaside,
  14113. IN PALLOCATE_FUNCTION Allocate,
  14114. IN PFREE_FUNCTION Free,
  14115. IN ULONG Flags,
  14116. IN SIZE_T Size,
  14117. IN ULONG Tag,
  14118. IN USHORT Depth
  14119. );
  14120. NTKERNELAPI
  14121. VOID
  14122. ExDeletePagedLookasideList (
  14123. IN PPAGED_LOOKASIDE_LIST Lookaside
  14124. );
  14125. #if defined(_WIN2K_COMPAT_SLIST_USAGE) && defined(_X86_)
  14126. NTKERNELAPI
  14127. PVOID
  14128. ExAllocateFromPagedLookasideList(
  14129. IN PPAGED_LOOKASIDE_LIST Lookaside
  14130. );
  14131. #else
  14132. __inline
  14133. PVOID
  14134. ExAllocateFromPagedLookasideList(
  14135. IN PPAGED_LOOKASIDE_LIST Lookaside
  14136. )
  14137. /*++
  14138. Routine Description:
  14139. This function removes (pops) the first entry from the specified
  14140. paged lookaside list.
  14141. Arguments:
  14142. Lookaside - Supplies a pointer to a paged lookaside list structure.
  14143. Return Value:
  14144. If an entry is removed from the specified lookaside list, then the
  14145. address of the entry is returned as the function value. Otherwise,
  14146. NULL is returned.
  14147. --*/
  14148. {
  14149. PVOID Entry;
  14150. Lookaside->L.TotalAllocates += 1;
  14151. Entry = InterlockedPopEntrySList(&Lookaside->L.ListHead);
  14152. if (Entry == NULL) {
  14153. Lookaside->L.AllocateMisses += 1;
  14154. Entry = (Lookaside->L.Allocate)(Lookaside->L.Type,
  14155. Lookaside->L.Size,
  14156. Lookaside->L.Tag);
  14157. }
  14158. return Entry;
  14159. }
  14160. #endif
  14161. #if defined(_WIN2K_COMPAT_SLIST_USAGE) && defined(_X86_)
  14162. NTKERNELAPI
  14163. VOID
  14164. ExFreeToPagedLookasideList(
  14165. IN PPAGED_LOOKASIDE_LIST Lookaside,
  14166. IN PVOID Entry
  14167. );
  14168. #else
  14169. __inline
  14170. VOID
  14171. ExFreeToPagedLookasideList(
  14172. IN PPAGED_LOOKASIDE_LIST Lookaside,
  14173. IN PVOID Entry
  14174. )
  14175. /*++
  14176. Routine Description:
  14177. This function inserts (pushes) the specified entry into the specified
  14178. paged lookaside list.
  14179. Arguments:
  14180. Lookaside - Supplies a pointer to a nonpaged lookaside list structure.
  14181. Entry - Supples a pointer to the entry that is inserted in the
  14182. lookaside list.
  14183. Return Value:
  14184. None.
  14185. --*/
  14186. {
  14187. Lookaside->L.TotalFrees += 1;
  14188. if (ExQueryDepthSList(&Lookaside->L.ListHead) >= Lookaside->L.Depth) {
  14189. Lookaside->L.FreeMisses += 1;
  14190. (Lookaside->L.Free)(Entry);
  14191. } else {
  14192. InterlockedPushEntrySList(&Lookaside->L.ListHead,
  14193. (PSLIST_ENTRY)Entry);
  14194. }
  14195. return;
  14196. }
  14197. #endif
  14198. //
  14199. // Worker Thread
  14200. //
  14201. typedef enum _WORK_QUEUE_TYPE {
  14202. CriticalWorkQueue,
  14203. DelayedWorkQueue,
  14204. HyperCriticalWorkQueue,
  14205. MaximumWorkQueue
  14206. } WORK_QUEUE_TYPE;
  14207. typedef
  14208. VOID
  14209. (*PWORKER_THREAD_ROUTINE)(
  14210. IN PVOID Parameter
  14211. );
  14212. typedef struct _WORK_QUEUE_ITEM {
  14213. LIST_ENTRY List;
  14214. PWORKER_THREAD_ROUTINE WorkerRoutine;
  14215. PVOID Parameter;
  14216. } WORK_QUEUE_ITEM, *PWORK_QUEUE_ITEM;
  14217. #if PRAGMA_DEPRECATED_DDK
  14218. #pragma deprecated(ExInitializeWorkItem) // Use IoAllocateWorkItem
  14219. #endif
  14220. #define ExInitializeWorkItem(Item, Routine, Context) \
  14221. (Item)->WorkerRoutine = (Routine); \
  14222. (Item)->Parameter = (Context); \
  14223. (Item)->List.Flink = NULL;
  14224. DECLSPEC_DEPRECATED_DDK // Use IoQueueWorkItem
  14225. NTKERNELAPI
  14226. VOID
  14227. ExQueueWorkItem(
  14228. IN PWORK_QUEUE_ITEM WorkItem,
  14229. IN WORK_QUEUE_TYPE QueueType
  14230. );
  14231. NTKERNELAPI
  14232. BOOLEAN
  14233. ExIsProcessorFeaturePresent(
  14234. ULONG ProcessorFeature
  14235. );
  14236. //
  14237. // Zone Allocation
  14238. //
  14239. typedef struct _ZONE_SEGMENT_HEADER {
  14240. SINGLE_LIST_ENTRY SegmentList;
  14241. PVOID Reserved;
  14242. } ZONE_SEGMENT_HEADER, *PZONE_SEGMENT_HEADER;
  14243. typedef struct _ZONE_HEADER {
  14244. SINGLE_LIST_ENTRY FreeList;
  14245. SINGLE_LIST_ENTRY SegmentList;
  14246. ULONG BlockSize;
  14247. ULONG TotalSegmentSize;
  14248. } ZONE_HEADER, *PZONE_HEADER;
  14249. DECLSPEC_DEPRECATED_DDK
  14250. NTKERNELAPI
  14251. NTSTATUS
  14252. ExInitializeZone(
  14253. IN PZONE_HEADER Zone,
  14254. IN ULONG BlockSize,
  14255. IN PVOID InitialSegment,
  14256. IN ULONG InitialSegmentSize
  14257. );
  14258. DECLSPEC_DEPRECATED_DDK
  14259. NTKERNELAPI
  14260. NTSTATUS
  14261. ExExtendZone(
  14262. IN PZONE_HEADER Zone,
  14263. IN PVOID Segment,
  14264. IN ULONG SegmentSize
  14265. );
  14266. DECLSPEC_DEPRECATED_DDK
  14267. NTKERNELAPI
  14268. NTSTATUS
  14269. ExInterlockedExtendZone(
  14270. IN PZONE_HEADER Zone,
  14271. IN PVOID Segment,
  14272. IN ULONG SegmentSize,
  14273. IN PKSPIN_LOCK Lock
  14274. );
  14275. //++
  14276. //
  14277. // PVOID
  14278. // ExAllocateFromZone(
  14279. // IN PZONE_HEADER Zone
  14280. // )
  14281. //
  14282. // Routine Description:
  14283. //
  14284. // This routine removes an entry from the zone and returns a pointer to it.
  14285. //
  14286. // Arguments:
  14287. //
  14288. // Zone - Pointer to the zone header controlling the storage from which the
  14289. // entry is to be allocated.
  14290. //
  14291. // Return Value:
  14292. //
  14293. // The function value is a pointer to the storage allocated from the zone.
  14294. //
  14295. //--
  14296. #if PRAGMA_DEPRECATED_DDK
  14297. #pragma deprecated(ExAllocateFromZone)
  14298. #endif
  14299. #define ExAllocateFromZone(Zone) \
  14300. (PVOID)((Zone)->FreeList.Next); \
  14301. if ( (Zone)->FreeList.Next ) (Zone)->FreeList.Next = (Zone)->FreeList.Next->Next
  14302. //++
  14303. //
  14304. // PVOID
  14305. // ExFreeToZone(
  14306. // IN PZONE_HEADER Zone,
  14307. // IN PVOID Block
  14308. // )
  14309. //
  14310. // Routine Description:
  14311. //
  14312. // This routine places the specified block of storage back onto the free
  14313. // list in the specified zone.
  14314. //
  14315. // Arguments:
  14316. //
  14317. // Zone - Pointer to the zone header controlling the storage to which the
  14318. // entry is to be inserted.
  14319. //
  14320. // Block - Pointer to the block of storage to be freed back to the zone.
  14321. //
  14322. // Return Value:
  14323. //
  14324. // Pointer to previous block of storage that was at the head of the free
  14325. // list. NULL implies the zone went from no available free blocks to
  14326. // at least one free block.
  14327. //
  14328. //--
  14329. #if PRAGMA_DEPRECATED_DDK
  14330. #pragma deprecated(ExFreeToZone)
  14331. #endif
  14332. #define ExFreeToZone(Zone,Block) \
  14333. ( ((PSINGLE_LIST_ENTRY)(Block))->Next = (Zone)->FreeList.Next, \
  14334. (Zone)->FreeList.Next = ((PSINGLE_LIST_ENTRY)(Block)), \
  14335. ((PSINGLE_LIST_ENTRY)(Block))->Next \
  14336. )
  14337. //++
  14338. //
  14339. // BOOLEAN
  14340. // ExIsFullZone(
  14341. // IN PZONE_HEADER Zone
  14342. // )
  14343. //
  14344. // Routine Description:
  14345. //
  14346. // This routine determines if the specified zone is full or not. A zone
  14347. // is considered full if the free list is empty.
  14348. //
  14349. // Arguments:
  14350. //
  14351. // Zone - Pointer to the zone header to be tested.
  14352. //
  14353. // Return Value:
  14354. //
  14355. // TRUE if the zone is full and FALSE otherwise.
  14356. //
  14357. //--
  14358. #if PRAGMA_DEPRECATED_DDK
  14359. #pragma deprecated(ExIsFullZone)
  14360. #endif
  14361. #define ExIsFullZone(Zone) \
  14362. ( (Zone)->FreeList.Next == (PSINGLE_LIST_ENTRY)NULL )
  14363. //++
  14364. //
  14365. // PVOID
  14366. // ExInterlockedAllocateFromZone(
  14367. // IN PZONE_HEADER Zone,
  14368. // IN PKSPIN_LOCK Lock
  14369. // )
  14370. //
  14371. // Routine Description:
  14372. //
  14373. // This routine removes an entry from the zone and returns a pointer to it.
  14374. // The removal is performed with the specified lock owned for the sequence
  14375. // to make it MP-safe.
  14376. //
  14377. // Arguments:
  14378. //
  14379. // Zone - Pointer to the zone header controlling the storage from which the
  14380. // entry is to be allocated.
  14381. //
  14382. // Lock - Pointer to the spin lock which should be obtained before removing
  14383. // the entry from the allocation list. The lock is released before
  14384. // returning to the caller.
  14385. //
  14386. // Return Value:
  14387. //
  14388. // The function value is a pointer to the storage allocated from the zone.
  14389. //
  14390. //--
  14391. #if PRAGMA_DEPRECATED_DDK
  14392. #pragma deprecated(ExInterlockedAllocateFromZone)
  14393. #endif
  14394. #define ExInterlockedAllocateFromZone(Zone,Lock) \
  14395. (PVOID) ExInterlockedPopEntryList( &(Zone)->FreeList, Lock )
  14396. //++
  14397. //
  14398. // PVOID
  14399. // ExInterlockedFreeToZone(
  14400. // IN PZONE_HEADER Zone,
  14401. // IN PVOID Block,
  14402. // IN PKSPIN_LOCK Lock
  14403. // )
  14404. //
  14405. // Routine Description:
  14406. //
  14407. // This routine places the specified block of storage back onto the free
  14408. // list in the specified zone. The insertion is performed with the lock
  14409. // owned for the sequence to make it MP-safe.
  14410. //
  14411. // Arguments:
  14412. //
  14413. // Zone - Pointer to the zone header controlling the storage to which the
  14414. // entry is to be inserted.
  14415. //
  14416. // Block - Pointer to the block of storage to be freed back to the zone.
  14417. //
  14418. // Lock - Pointer to the spin lock which should be obtained before inserting
  14419. // the entry onto the free list. The lock is released before returning
  14420. // to the caller.
  14421. //
  14422. // Return Value:
  14423. //
  14424. // Pointer to previous block of storage that was at the head of the free
  14425. // list. NULL implies the zone went from no available free blocks to
  14426. // at least one free block.
  14427. //
  14428. //--
  14429. #if PRAGMA_DEPRECATED_DDK
  14430. #pragma deprecated(ExInterlockedFreeToZone)
  14431. #endif
  14432. #define ExInterlockedFreeToZone(Zone,Block,Lock) \
  14433. ExInterlockedPushEntryList( &(Zone)->FreeList, ((PSINGLE_LIST_ENTRY) (Block)), Lock )
  14434. //++
  14435. //
  14436. // BOOLEAN
  14437. // ExIsObjectInFirstZoneSegment(
  14438. // IN PZONE_HEADER Zone,
  14439. // IN PVOID Object
  14440. // )
  14441. //
  14442. // Routine Description:
  14443. //
  14444. // This routine determines if the specified pointer lives in the zone.
  14445. //
  14446. // Arguments:
  14447. //
  14448. // Zone - Pointer to the zone header controlling the storage to which the
  14449. // object may belong.
  14450. //
  14451. // Object - Pointer to the object in question.
  14452. //
  14453. // Return Value:
  14454. //
  14455. // TRUE if the Object came from the first segment of zone.
  14456. //
  14457. //--
  14458. #if PRAGMA_DEPRECATED_DDK
  14459. #pragma deprecated(ExIsObjectInFirstZoneSegment)
  14460. #endif
  14461. #define ExIsObjectInFirstZoneSegment(Zone,Object) ((BOOLEAN) \
  14462. (((PUCHAR)(Object) >= (PUCHAR)(Zone)->SegmentList.Next) && \
  14463. ((PUCHAR)(Object) < (PUCHAR)(Zone)->SegmentList.Next + \
  14464. (Zone)->TotalSegmentSize)) \
  14465. )
  14466. //
  14467. // Define the type for Callback function.
  14468. //
  14469. typedef struct _CALLBACK_OBJECT *PCALLBACK_OBJECT;
  14470. typedef VOID (*PCALLBACK_FUNCTION ) (
  14471. IN PVOID CallbackContext,
  14472. IN PVOID Argument1,
  14473. IN PVOID Argument2
  14474. );
  14475. NTKERNELAPI
  14476. NTSTATUS
  14477. ExCreateCallback (
  14478. OUT PCALLBACK_OBJECT *CallbackObject,
  14479. IN POBJECT_ATTRIBUTES ObjectAttributes,
  14480. IN BOOLEAN Create,
  14481. IN BOOLEAN AllowMultipleCallbacks
  14482. );
  14483. NTKERNELAPI
  14484. PVOID
  14485. ExRegisterCallback (
  14486. IN PCALLBACK_OBJECT CallbackObject,
  14487. IN PCALLBACK_FUNCTION CallbackFunction,
  14488. IN PVOID CallbackContext
  14489. );
  14490. NTKERNELAPI
  14491. VOID
  14492. ExUnregisterCallback (
  14493. IN PVOID CallbackRegistration
  14494. );
  14495. NTKERNELAPI
  14496. VOID
  14497. ExNotifyCallback (
  14498. IN PVOID CallbackObject,
  14499. IN PVOID Argument1,
  14500. IN PVOID Argument2
  14501. );
  14502. //
  14503. // Security operation codes
  14504. //
  14505. typedef enum _SECURITY_OPERATION_CODE {
  14506. SetSecurityDescriptor,
  14507. QuerySecurityDescriptor,
  14508. DeleteSecurityDescriptor,
  14509. AssignSecurityDescriptor
  14510. } SECURITY_OPERATION_CODE, *PSECURITY_OPERATION_CODE;
  14511. //
  14512. // Data structure used to capture subject security context
  14513. // for access validations and auditing.
  14514. //
  14515. // THE FIELDS OF THIS DATA STRUCTURE SHOULD BE CONSIDERED OPAQUE
  14516. // BY ALL EXCEPT THE SECURITY ROUTINES.
  14517. //
  14518. typedef struct _SECURITY_SUBJECT_CONTEXT {
  14519. PACCESS_TOKEN ClientToken;
  14520. SECURITY_IMPERSONATION_LEVEL ImpersonationLevel;
  14521. PACCESS_TOKEN PrimaryToken;
  14522. PVOID ProcessAuditId;
  14523. } SECURITY_SUBJECT_CONTEXT, *PSECURITY_SUBJECT_CONTEXT;
  14524. ///////////////////////////////////////////////////////////////////////////////
  14525. // //
  14526. // ACCESS_STATE and related structures //
  14527. // //
  14528. ///////////////////////////////////////////////////////////////////////////////
  14529. //
  14530. // Initial Privilege Set - Room for three privileges, which should
  14531. // be enough for most applications. This structure exists so that
  14532. // it can be imbedded in an ACCESS_STATE structure. Use PRIVILEGE_SET
  14533. // for all other references to Privilege sets.
  14534. //
  14535. #define INITIAL_PRIVILEGE_COUNT 3
  14536. typedef struct _INITIAL_PRIVILEGE_SET {
  14537. ULONG PrivilegeCount;
  14538. ULONG Control;
  14539. LUID_AND_ATTRIBUTES Privilege[INITIAL_PRIVILEGE_COUNT];
  14540. } INITIAL_PRIVILEGE_SET, * PINITIAL_PRIVILEGE_SET;
  14541. //
  14542. // Combine the information that describes the state
  14543. // of an access-in-progress into a single structure
  14544. //
  14545. typedef struct _ACCESS_STATE {
  14546. LUID OperationID;
  14547. BOOLEAN SecurityEvaluated;
  14548. BOOLEAN GenerateAudit;
  14549. BOOLEAN GenerateOnClose;
  14550. BOOLEAN PrivilegesAllocated;
  14551. ULONG Flags;
  14552. ACCESS_MASK RemainingDesiredAccess;
  14553. ACCESS_MASK PreviouslyGrantedAccess;
  14554. ACCESS_MASK OriginalDesiredAccess;
  14555. SECURITY_SUBJECT_CONTEXT SubjectSecurityContext;
  14556. PSECURITY_DESCRIPTOR SecurityDescriptor;
  14557. PVOID AuxData;
  14558. union {
  14559. INITIAL_PRIVILEGE_SET InitialPrivilegeSet;
  14560. PRIVILEGE_SET PrivilegeSet;
  14561. } Privileges;
  14562. BOOLEAN AuditPrivileges;
  14563. UNICODE_STRING ObjectName;
  14564. UNICODE_STRING ObjectTypeName;
  14565. } ACCESS_STATE, *PACCESS_STATE;
  14566. //
  14567. // System Thread and Process Creation and Termination
  14568. //
  14569. NTKERNELAPI
  14570. NTSTATUS
  14571. PsCreateSystemThread(
  14572. OUT PHANDLE ThreadHandle,
  14573. IN ULONG DesiredAccess,
  14574. IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL,
  14575. IN HANDLE ProcessHandle OPTIONAL,
  14576. OUT PCLIENT_ID ClientId OPTIONAL,
  14577. IN PKSTART_ROUTINE StartRoutine,
  14578. IN PVOID StartContext
  14579. );
  14580. NTKERNELAPI
  14581. NTSTATUS
  14582. PsTerminateSystemThread(
  14583. IN NTSTATUS ExitStatus
  14584. );
  14585. HANDLE
  14586. PsGetCurrentProcessId( VOID );
  14587. HANDLE
  14588. PsGetCurrentThreadId( VOID );
  14589. // end_ntosp
  14590. BOOLEAN
  14591. PsGetVersion(
  14592. PULONG MajorVersion OPTIONAL,
  14593. PULONG MinorVersion OPTIONAL,
  14594. PULONG BuildNumber OPTIONAL,
  14595. PUNICODE_STRING CSDVersion OPTIONAL
  14596. );
  14597. //
  14598. // Define I/O system data structure type codes. Each major data structure in
  14599. // the I/O system has a type code The type field in each structure is at the
  14600. // same offset. The following values can be used to determine which type of
  14601. // data structure a pointer refers to.
  14602. //
  14603. #define IO_TYPE_ADAPTER 0x00000001
  14604. #define IO_TYPE_CONTROLLER 0x00000002
  14605. #define IO_TYPE_DEVICE 0x00000003
  14606. #define IO_TYPE_DRIVER 0x00000004
  14607. #define IO_TYPE_FILE 0x00000005
  14608. #define IO_TYPE_IRP 0x00000006
  14609. #define IO_TYPE_MASTER_ADAPTER 0x00000007
  14610. #define IO_TYPE_OPEN_PACKET 0x00000008
  14611. #define IO_TYPE_TIMER 0x00000009
  14612. #define IO_TYPE_VPB 0x0000000a
  14613. #define IO_TYPE_ERROR_LOG 0x0000000b
  14614. #define IO_TYPE_ERROR_MESSAGE 0x0000000c
  14615. #define IO_TYPE_DEVICE_OBJECT_EXTENSION 0x0000000d
  14616. //
  14617. // Define the major function codes for IRPs.
  14618. //
  14619. #define IRP_MJ_CREATE 0x00
  14620. #define IRP_MJ_CREATE_NAMED_PIPE 0x01
  14621. #define IRP_MJ_CLOSE 0x02
  14622. #define IRP_MJ_READ 0x03
  14623. #define IRP_MJ_WRITE 0x04
  14624. #define IRP_MJ_QUERY_INFORMATION 0x05
  14625. #define IRP_MJ_SET_INFORMATION 0x06
  14626. #define IRP_MJ_QUERY_EA 0x07
  14627. #define IRP_MJ_SET_EA 0x08
  14628. #define IRP_MJ_FLUSH_BUFFERS 0x09
  14629. #define IRP_MJ_QUERY_VOLUME_INFORMATION 0x0a
  14630. #define IRP_MJ_SET_VOLUME_INFORMATION 0x0b
  14631. #define IRP_MJ_DIRECTORY_CONTROL 0x0c
  14632. #define IRP_MJ_FILE_SYSTEM_CONTROL 0x0d
  14633. #define IRP_MJ_DEVICE_CONTROL 0x0e
  14634. #define IRP_MJ_INTERNAL_DEVICE_CONTROL 0x0f
  14635. #define IRP_MJ_SHUTDOWN 0x10
  14636. #define IRP_MJ_LOCK_CONTROL 0x11
  14637. #define IRP_MJ_CLEANUP 0x12
  14638. #define IRP_MJ_CREATE_MAILSLOT 0x13
  14639. #define IRP_MJ_QUERY_SECURITY 0x14
  14640. #define IRP_MJ_SET_SECURITY 0x15
  14641. #define IRP_MJ_POWER 0x16
  14642. #define IRP_MJ_SYSTEM_CONTROL 0x17
  14643. #define IRP_MJ_DEVICE_CHANGE 0x18
  14644. #define IRP_MJ_QUERY_QUOTA 0x19
  14645. #define IRP_MJ_SET_QUOTA 0x1a
  14646. #define IRP_MJ_PNP 0x1b
  14647. #define IRP_MJ_PNP_POWER IRP_MJ_PNP // Obsolete....
  14648. #define IRP_MJ_MAXIMUM_FUNCTION 0x1b
  14649. //
  14650. // Make the Scsi major code the same as internal device control.
  14651. //
  14652. #define IRP_MJ_SCSI IRP_MJ_INTERNAL_DEVICE_CONTROL
  14653. //
  14654. // Define the minor function codes for IRPs. The lower 128 codes, from 0x00 to
  14655. // 0x7f are reserved to Microsoft. The upper 128 codes, from 0x80 to 0xff, are
  14656. // reserved to customers of Microsoft.
  14657. //
  14658. // end_wdm end_ntndis
  14659. //
  14660. // Directory control minor function codes
  14661. //
  14662. #define IRP_MN_QUERY_DIRECTORY 0x01
  14663. #define IRP_MN_NOTIFY_CHANGE_DIRECTORY 0x02
  14664. //
  14665. // File system control minor function codes. Note that "user request" is
  14666. // assumed to be zero by both the I/O system and file systems. Do not change
  14667. // this value.
  14668. //
  14669. #define IRP_MN_USER_FS_REQUEST 0x00
  14670. #define IRP_MN_MOUNT_VOLUME 0x01
  14671. #define IRP_MN_VERIFY_VOLUME 0x02
  14672. #define IRP_MN_LOAD_FILE_SYSTEM 0x03
  14673. #define IRP_MN_TRACK_LINK 0x04 // To be obsoleted soon
  14674. #define IRP_MN_KERNEL_CALL 0x04
  14675. //
  14676. // Lock control minor function codes
  14677. //
  14678. #define IRP_MN_LOCK 0x01
  14679. #define IRP_MN_UNLOCK_SINGLE 0x02
  14680. #define IRP_MN_UNLOCK_ALL 0x03
  14681. #define IRP_MN_UNLOCK_ALL_BY_KEY 0x04
  14682. //
  14683. // Read and Write minor function codes for file systems supporting Lan Manager
  14684. // software. All of these subfunction codes are invalid if the file has been
  14685. // opened with FO_NO_INTERMEDIATE_BUFFERING. They are also invalid in combi-
  14686. // nation with synchronous calls (Irp Flag or file open option).
  14687. //
  14688. // Note that "normal" is assumed to be zero by both the I/O system and file
  14689. // systems. Do not change this value.
  14690. //
  14691. #define IRP_MN_NORMAL 0x00
  14692. #define IRP_MN_DPC 0x01
  14693. #define IRP_MN_MDL 0x02
  14694. #define IRP_MN_COMPLETE 0x04
  14695. #define IRP_MN_COMPRESSED 0x08
  14696. #define IRP_MN_MDL_DPC (IRP_MN_MDL | IRP_MN_DPC)
  14697. #define IRP_MN_COMPLETE_MDL (IRP_MN_COMPLETE | IRP_MN_MDL)
  14698. #define IRP_MN_COMPLETE_MDL_DPC (IRP_MN_COMPLETE_MDL | IRP_MN_DPC)
  14699. // begin_wdm
  14700. //
  14701. // Device Control Request minor function codes for SCSI support. Note that
  14702. // user requests are assumed to be zero.
  14703. //
  14704. #define IRP_MN_SCSI_CLASS 0x01
  14705. //
  14706. // PNP minor function codes.
  14707. //
  14708. #define IRP_MN_START_DEVICE 0x00
  14709. #define IRP_MN_QUERY_REMOVE_DEVICE 0x01
  14710. #define IRP_MN_REMOVE_DEVICE 0x02
  14711. #define IRP_MN_CANCEL_REMOVE_DEVICE 0x03
  14712. #define IRP_MN_STOP_DEVICE 0x04
  14713. #define IRP_MN_QUERY_STOP_DEVICE 0x05
  14714. #define IRP_MN_CANCEL_STOP_DEVICE 0x06
  14715. #define IRP_MN_QUERY_DEVICE_RELATIONS 0x07
  14716. #define IRP_MN_QUERY_INTERFACE 0x08
  14717. #define IRP_MN_QUERY_CAPABILITIES 0x09
  14718. #define IRP_MN_QUERY_RESOURCES 0x0A
  14719. #define IRP_MN_QUERY_RESOURCE_REQUIREMENTS 0x0B
  14720. #define IRP_MN_QUERY_DEVICE_TEXT 0x0C
  14721. #define IRP_MN_FILTER_RESOURCE_REQUIREMENTS 0x0D
  14722. #define IRP_MN_READ_CONFIG 0x0F
  14723. #define IRP_MN_WRITE_CONFIG 0x10
  14724. #define IRP_MN_EJECT 0x11
  14725. #define IRP_MN_SET_LOCK 0x12
  14726. #define IRP_MN_QUERY_ID 0x13
  14727. #define IRP_MN_QUERY_PNP_DEVICE_STATE 0x14
  14728. #define IRP_MN_QUERY_BUS_INFORMATION 0x15
  14729. #define IRP_MN_DEVICE_USAGE_NOTIFICATION 0x16
  14730. #define IRP_MN_SURPRISE_REMOVAL 0x17
  14731. // end_wdm
  14732. #define IRP_MN_QUERY_LEGACY_BUS_INFORMATION 0x18
  14733. // begin_wdm
  14734. //
  14735. // POWER minor function codes
  14736. //
  14737. #define IRP_MN_WAIT_WAKE 0x00
  14738. #define IRP_MN_POWER_SEQUENCE 0x01
  14739. #define IRP_MN_SET_POWER 0x02
  14740. #define IRP_MN_QUERY_POWER 0x03
  14741. // begin_ntminiport
  14742. //
  14743. // WMI minor function codes under IRP_MJ_SYSTEM_CONTROL
  14744. //
  14745. #define IRP_MN_QUERY_ALL_DATA 0x00
  14746. #define IRP_MN_QUERY_SINGLE_INSTANCE 0x01
  14747. #define IRP_MN_CHANGE_SINGLE_INSTANCE 0x02
  14748. #define IRP_MN_CHANGE_SINGLE_ITEM 0x03
  14749. #define IRP_MN_ENABLE_EVENTS 0x04
  14750. #define IRP_MN_DISABLE_EVENTS 0x05
  14751. #define IRP_MN_ENABLE_COLLECTION 0x06
  14752. #define IRP_MN_DISABLE_COLLECTION 0x07
  14753. #define IRP_MN_REGINFO 0x08
  14754. #define IRP_MN_EXECUTE_METHOD 0x09
  14755. // Minor code 0x0a is reserved
  14756. #define IRP_MN_REGINFO_EX 0x0b
  14757. // end_ntminiport
  14758. //
  14759. // Define option flags for IoCreateFile. Note that these values must be
  14760. // exactly the same as the SL_... flags for a create function. Note also
  14761. // that there are flags that may be passed to IoCreateFile that are not
  14762. // placed in the stack location for the create IRP. These flags start in
  14763. // the next byte.
  14764. //
  14765. #define IO_FORCE_ACCESS_CHECK 0x0001
  14766. //
  14767. // Define the structures used by the I/O system
  14768. //
  14769. //
  14770. // Define empty typedefs for the _IRP, _DEVICE_OBJECT, and _DRIVER_OBJECT
  14771. // structures so they may be referenced by function types before they are
  14772. // actually defined.
  14773. //
  14774. struct _DEVICE_DESCRIPTION;
  14775. struct _DEVICE_OBJECT;
  14776. struct _DMA_ADAPTER;
  14777. struct _DRIVER_OBJECT;
  14778. struct _DRIVE_LAYOUT_INFORMATION;
  14779. struct _DISK_PARTITION;
  14780. struct _FILE_OBJECT;
  14781. struct DECLSPEC_ALIGN(MEMORY_ALLOCATION_ALIGNMENT) _IRP;
  14782. struct _SCSI_REQUEST_BLOCK;
  14783. struct _SCATTER_GATHER_LIST;
  14784. //
  14785. // Define the I/O version of a DPC routine.
  14786. //
  14787. typedef
  14788. VOID
  14789. (*PIO_DPC_ROUTINE) (
  14790. IN PKDPC Dpc,
  14791. IN struct _DEVICE_OBJECT *DeviceObject,
  14792. IN struct _IRP *Irp,
  14793. IN PVOID Context
  14794. );
  14795. //
  14796. // Define driver timer routine type.
  14797. //
  14798. typedef
  14799. VOID
  14800. (*PIO_TIMER_ROUTINE) (
  14801. IN struct _DEVICE_OBJECT *DeviceObject,
  14802. IN PVOID Context
  14803. );
  14804. //
  14805. // Define driver initialization routine type.
  14806. //
  14807. typedef
  14808. NTSTATUS
  14809. (*PDRIVER_INITIALIZE) (
  14810. IN struct _DRIVER_OBJECT *DriverObject,
  14811. IN PUNICODE_STRING RegistryPath
  14812. );
  14813. // end_wdm
  14814. //
  14815. // Define driver reinitialization routine type.
  14816. //
  14817. typedef
  14818. VOID
  14819. (*PDRIVER_REINITIALIZE) (
  14820. IN struct _DRIVER_OBJECT *DriverObject,
  14821. IN PVOID Context,
  14822. IN ULONG Count
  14823. );
  14824. // begin_wdm begin_ntndis
  14825. //
  14826. // Define driver cancel routine type.
  14827. //
  14828. typedef
  14829. VOID
  14830. (*PDRIVER_CANCEL) (
  14831. IN struct _DEVICE_OBJECT *DeviceObject,
  14832. IN struct _IRP *Irp
  14833. );
  14834. //
  14835. // Define driver dispatch routine type.
  14836. //
  14837. typedef
  14838. NTSTATUS
  14839. (*PDRIVER_DISPATCH) (
  14840. IN struct _DEVICE_OBJECT *DeviceObject,
  14841. IN struct _IRP *Irp
  14842. );
  14843. //
  14844. // Define driver start I/O routine type.
  14845. //
  14846. typedef
  14847. VOID
  14848. (*PDRIVER_STARTIO) (
  14849. IN struct _DEVICE_OBJECT *DeviceObject,
  14850. IN struct _IRP *Irp
  14851. );
  14852. //
  14853. // Define driver unload routine type.
  14854. //
  14855. typedef
  14856. VOID
  14857. (*PDRIVER_UNLOAD) (
  14858. IN struct _DRIVER_OBJECT *DriverObject
  14859. );
  14860. //
  14861. // Define driver AddDevice routine type.
  14862. //
  14863. typedef
  14864. NTSTATUS
  14865. (*PDRIVER_ADD_DEVICE) (
  14866. IN struct _DRIVER_OBJECT *DriverObject,
  14867. IN struct _DEVICE_OBJECT *PhysicalDeviceObject
  14868. );
  14869. //
  14870. // Define the actions that a driver execution routine may request of the
  14871. // adapter/controller allocation routines upon return.
  14872. //
  14873. typedef enum _IO_ALLOCATION_ACTION {
  14874. KeepObject = 1,
  14875. DeallocateObject,
  14876. DeallocateObjectKeepRegisters
  14877. } IO_ALLOCATION_ACTION, *PIO_ALLOCATION_ACTION;
  14878. //
  14879. // Define device driver adapter/controller execution routine.
  14880. //
  14881. typedef
  14882. IO_ALLOCATION_ACTION
  14883. (*PDRIVER_CONTROL) (
  14884. IN struct _DEVICE_OBJECT *DeviceObject,
  14885. IN struct _IRP *Irp,
  14886. IN PVOID MapRegisterBase,
  14887. IN PVOID Context
  14888. );
  14889. //
  14890. // Define Volume Parameter Block (VPB) flags.
  14891. //
  14892. #define VPB_MOUNTED 0x00000001
  14893. #define VPB_LOCKED 0x00000002
  14894. #define VPB_PERSISTENT 0x00000004
  14895. #define VPB_REMOVE_PENDING 0x00000008
  14896. #define VPB_RAW_MOUNT 0x00000010
  14897. //
  14898. // Volume Parameter Block (VPB)
  14899. //
  14900. #define MAXIMUM_VOLUME_LABEL_LENGTH (32 * sizeof(WCHAR)) // 32 characters
  14901. typedef struct _VPB {
  14902. CSHORT Type;
  14903. CSHORT Size;
  14904. USHORT Flags;
  14905. USHORT VolumeLabelLength; // in bytes
  14906. struct _DEVICE_OBJECT *DeviceObject;
  14907. struct _DEVICE_OBJECT *RealDevice;
  14908. ULONG SerialNumber;
  14909. ULONG ReferenceCount;
  14910. WCHAR VolumeLabel[MAXIMUM_VOLUME_LABEL_LENGTH / sizeof(WCHAR)];
  14911. } VPB, *PVPB;
  14912. #if defined(_WIN64)
  14913. //
  14914. // Use __inline DMA macros (hal.h)
  14915. //
  14916. #ifndef USE_DMA_MACROS
  14917. #define USE_DMA_MACROS
  14918. #endif
  14919. //
  14920. // Only PnP drivers!
  14921. //
  14922. #ifndef NO_LEGACY_DRIVERS
  14923. #define NO_LEGACY_DRIVERS
  14924. #endif
  14925. #endif // _WIN64
  14926. #if defined(USE_DMA_MACROS) && (defined(_NTDDK_) || defined(_NTDRIVER_) || defined(_NTOSP_))
  14927. // begin_wdm
  14928. //
  14929. // Define object type specific fields of various objects used by the I/O system
  14930. //
  14931. typedef struct _DMA_ADAPTER *PADAPTER_OBJECT;
  14932. // end_wdm
  14933. #else
  14934. //
  14935. // Define object type specific fields of various objects used by the I/O system
  14936. //
  14937. typedef struct _ADAPTER_OBJECT *PADAPTER_OBJECT; // ntndis
  14938. #endif // USE_DMA_MACROS && (_NTDDK_ || _NTDRIVER_ || _NTOSP_)
  14939. // begin_wdm
  14940. //
  14941. // Define Wait Context Block (WCB)
  14942. //
  14943. typedef struct _WAIT_CONTEXT_BLOCK {
  14944. KDEVICE_QUEUE_ENTRY WaitQueueEntry;
  14945. PDRIVER_CONTROL DeviceRoutine;
  14946. PVOID DeviceContext;
  14947. ULONG NumberOfMapRegisters;
  14948. PVOID DeviceObject;
  14949. PVOID CurrentIrp;
  14950. PKDPC BufferChainingDpc;
  14951. } WAIT_CONTEXT_BLOCK, *PWAIT_CONTEXT_BLOCK;
  14952. // end_wdm
  14953. typedef struct _CONTROLLER_OBJECT {
  14954. CSHORT Type;
  14955. CSHORT Size;
  14956. PVOID ControllerExtension;
  14957. KDEVICE_QUEUE DeviceWaitQueue;
  14958. ULONG Spare1;
  14959. LARGE_INTEGER Spare2;
  14960. } CONTROLLER_OBJECT, *PCONTROLLER_OBJECT;
  14961. // begin_wdm
  14962. //
  14963. // Define Device Object (DO) flags
  14964. //
  14965. #define DO_VERIFY_VOLUME 0x00000002
  14966. #define DO_BUFFERED_IO 0x00000004
  14967. #define DO_EXCLUSIVE 0x00000008
  14968. #define DO_DIRECT_IO 0x00000010
  14969. #define DO_MAP_IO_BUFFER 0x00000020
  14970. #define DO_DEVICE_HAS_NAME 0x00000040
  14971. #define DO_DEVICE_INITIALIZING 0x00000080
  14972. #define DO_SYSTEM_BOOT_PARTITION 0x00000100
  14973. #define DO_LONG_TERM_REQUESTS 0x00000200
  14974. #define DO_NEVER_LAST_DEVICE 0x00000400
  14975. #define DO_SHUTDOWN_REGISTERED 0x00000800
  14976. #define DO_BUS_ENUMERATED_DEVICE 0x00001000
  14977. #define DO_POWER_PAGABLE 0x00002000
  14978. #define DO_POWER_INRUSH 0x00004000
  14979. #define DO_LOW_PRIORITY_FILESYSTEM 0x00010000
  14980. //
  14981. // Device Object structure definition
  14982. //
  14983. typedef struct DECLSPEC_ALIGN(MEMORY_ALLOCATION_ALIGNMENT) _DEVICE_OBJECT {
  14984. CSHORT Type;
  14985. USHORT Size;
  14986. LONG ReferenceCount;
  14987. struct _DRIVER_OBJECT *DriverObject;
  14988. struct _DEVICE_OBJECT *NextDevice;
  14989. struct _DEVICE_OBJECT *AttachedDevice;
  14990. struct _IRP *CurrentIrp;
  14991. PIO_TIMER Timer;
  14992. ULONG Flags; // See above: DO_...
  14993. ULONG Characteristics; // See ntioapi: FILE_...
  14994. PVPB Vpb;
  14995. PVOID DeviceExtension;
  14996. DEVICE_TYPE DeviceType;
  14997. CCHAR StackSize;
  14998. union {
  14999. LIST_ENTRY ListEntry;
  15000. WAIT_CONTEXT_BLOCK Wcb;
  15001. } Queue;
  15002. ULONG AlignmentRequirement;
  15003. KDEVICE_QUEUE DeviceQueue;
  15004. KDPC Dpc;
  15005. //
  15006. // The following field is for exclusive use by the filesystem to keep
  15007. // track of the number of Fsp threads currently using the device
  15008. //
  15009. ULONG ActiveThreadCount;
  15010. PSECURITY_DESCRIPTOR SecurityDescriptor;
  15011. KEVENT DeviceLock;
  15012. USHORT SectorSize;
  15013. USHORT Spare1;
  15014. struct _DEVOBJ_EXTENSION *DeviceObjectExtension;
  15015. PVOID Reserved;
  15016. } DEVICE_OBJECT;
  15017. typedef struct _DEVICE_OBJECT *PDEVICE_OBJECT; // ntndis
  15018. struct _DEVICE_OBJECT_POWER_EXTENSION;
  15019. typedef struct _DEVOBJ_EXTENSION {
  15020. CSHORT Type;
  15021. USHORT Size;
  15022. //
  15023. // Public part of the DeviceObjectExtension structure
  15024. //
  15025. PDEVICE_OBJECT DeviceObject; // owning device object
  15026. } DEVOBJ_EXTENSION, *PDEVOBJ_EXTENSION;
  15027. //
  15028. // Define Driver Object (DRVO) flags
  15029. //
  15030. #define DRVO_UNLOAD_INVOKED 0x00000001
  15031. #define DRVO_LEGACY_DRIVER 0x00000002
  15032. #define DRVO_BUILTIN_DRIVER 0x00000004 // Driver objects for Hal, PnP Mgr
  15033. // end_wdm
  15034. #define DRVO_REINIT_REGISTERED 0x00000008
  15035. #define DRVO_INITIALIZED 0x00000010
  15036. #define DRVO_BOOTREINIT_REGISTERED 0x00000020
  15037. #define DRVO_LEGACY_RESOURCES 0x00000040
  15038. // begin_wdm
  15039. typedef struct _DRIVER_EXTENSION {
  15040. //
  15041. // Back pointer to Driver Object
  15042. //
  15043. struct _DRIVER_OBJECT *DriverObject;
  15044. //
  15045. // The AddDevice entry point is called by the Plug & Play manager
  15046. // to inform the driver when a new device instance arrives that this
  15047. // driver must control.
  15048. //
  15049. PDRIVER_ADD_DEVICE AddDevice;
  15050. //
  15051. // The count field is used to count the number of times the driver has
  15052. // had its registered reinitialization routine invoked.
  15053. //
  15054. ULONG Count;
  15055. //
  15056. // The service name field is used by the pnp manager to determine
  15057. // where the driver related info is stored in the registry.
  15058. //
  15059. UNICODE_STRING ServiceKeyName;
  15060. //
  15061. // Note: any new shared fields get added here.
  15062. //
  15063. } DRIVER_EXTENSION, *PDRIVER_EXTENSION;
  15064. typedef struct _DRIVER_OBJECT {
  15065. CSHORT Type;
  15066. CSHORT Size;
  15067. //
  15068. // The following links all of the devices created by a single driver
  15069. // together on a list, and the Flags word provides an extensible flag
  15070. // location for driver objects.
  15071. //
  15072. PDEVICE_OBJECT DeviceObject;
  15073. ULONG Flags;
  15074. //
  15075. // The following section describes where the driver is loaded. The count
  15076. // field is used to count the number of times the driver has had its
  15077. // registered reinitialization routine invoked.
  15078. //
  15079. PVOID DriverStart;
  15080. ULONG DriverSize;
  15081. PVOID DriverSection;
  15082. PDRIVER_EXTENSION DriverExtension;
  15083. //
  15084. // The driver name field is used by the error log thread
  15085. // determine the name of the driver that an I/O request is/was bound.
  15086. //
  15087. UNICODE_STRING DriverName;
  15088. //
  15089. // The following section is for registry support. Thise is a pointer
  15090. // to the path to the hardware information in the registry
  15091. //
  15092. PUNICODE_STRING HardwareDatabase;
  15093. //
  15094. // The following section contains the optional pointer to an array of
  15095. // alternate entry points to a driver for "fast I/O" support. Fast I/O
  15096. // is performed by invoking the driver routine directly with separate
  15097. // parameters, rather than using the standard IRP call mechanism. Note
  15098. // that these functions may only be used for synchronous I/O, and when
  15099. // the file is cached.
  15100. //
  15101. PFAST_IO_DISPATCH FastIoDispatch;
  15102. //
  15103. // The following section describes the entry points to this particular
  15104. // driver. Note that the major function dispatch table must be the last
  15105. // field in the object so that it remains extensible.
  15106. //
  15107. PDRIVER_INITIALIZE DriverInit;
  15108. PDRIVER_STARTIO DriverStartIo;
  15109. PDRIVER_UNLOAD DriverUnload;
  15110. PDRIVER_DISPATCH MajorFunction[IRP_MJ_MAXIMUM_FUNCTION + 1];
  15111. } DRIVER_OBJECT;
  15112. typedef struct _DRIVER_OBJECT *PDRIVER_OBJECT; // ntndis
  15113. // end_ntddk end_wdm end_ntifs end_ntosp
  15114. //
  15115. // Device Handler Object. There is one of these objects per PnP
  15116. // device. This object is given to the device driver as a PVOID
  15117. // and is used by the driver to refer to a particular device.
  15118. //
  15119. typedef struct _DEVICE_HANDLER_OBJECT {
  15120. CSHORT Type;
  15121. USHORT Size;
  15122. //
  15123. // Indentifies which bus extender this device handler
  15124. // object is associated with
  15125. //
  15126. struct _BUS_HANDLER *BusHandler;
  15127. //
  15128. // The associated SlotNumber for this device handler
  15129. //
  15130. ULONG SlotNumber;
  15131. } DEVICE_HANDLER_OBJECT, *PDEVICE_HANDLER_OBJECT;
  15132. // begin_ntddk begin_wdm begin_ntifs begin_ntosp
  15133. //
  15134. // The following structure is pointed to by the SectionObject pointer field
  15135. // of a file object, and is allocated by the various NT file systems.
  15136. //
  15137. typedef struct _SECTION_OBJECT_POINTERS {
  15138. PVOID DataSectionObject;
  15139. PVOID SharedCacheMap;
  15140. PVOID ImageSectionObject;
  15141. } SECTION_OBJECT_POINTERS;
  15142. typedef SECTION_OBJECT_POINTERS *PSECTION_OBJECT_POINTERS;
  15143. //
  15144. // Define the format of a completion message.
  15145. //
  15146. typedef struct _IO_COMPLETION_CONTEXT {
  15147. PVOID Port;
  15148. PVOID Key;
  15149. } IO_COMPLETION_CONTEXT, *PIO_COMPLETION_CONTEXT;
  15150. //
  15151. // Define File Object (FO) flags
  15152. //
  15153. #define FO_FILE_OPEN 0x00000001
  15154. #define FO_SYNCHRONOUS_IO 0x00000002
  15155. #define FO_ALERTABLE_IO 0x00000004
  15156. #define FO_NO_INTERMEDIATE_BUFFERING 0x00000008
  15157. #define FO_WRITE_THROUGH 0x00000010
  15158. #define FO_SEQUENTIAL_ONLY 0x00000020
  15159. #define FO_CACHE_SUPPORTED 0x00000040
  15160. #define FO_NAMED_PIPE 0x00000080
  15161. #define FO_STREAM_FILE 0x00000100
  15162. #define FO_MAILSLOT 0x00000200
  15163. #define FO_GENERATE_AUDIT_ON_CLOSE 0x00000400
  15164. #define FO_DIRECT_DEVICE_OPEN 0x00000800
  15165. #define FO_FILE_MODIFIED 0x00001000
  15166. #define FO_FILE_SIZE_CHANGED 0x00002000
  15167. #define FO_CLEANUP_COMPLETE 0x00004000
  15168. #define FO_TEMPORARY_FILE 0x00008000
  15169. #define FO_DELETE_ON_CLOSE 0x00010000
  15170. #define FO_OPENED_CASE_SENSITIVE 0x00020000
  15171. #define FO_HANDLE_CREATED 0x00040000
  15172. #define FO_FILE_FAST_IO_READ 0x00080000
  15173. #define FO_RANDOM_ACCESS 0x00100000
  15174. #define FO_FILE_OPEN_CANCELLED 0x00200000
  15175. #define FO_VOLUME_OPEN 0x00400000
  15176. #define FO_FILE_OBJECT_HAS_EXTENSION 0x00800000
  15177. #define FO_REMOTE_ORIGIN 0x01000000
  15178. typedef struct _FILE_OBJECT {
  15179. CSHORT Type;
  15180. CSHORT Size;
  15181. PDEVICE_OBJECT DeviceObject;
  15182. PVPB Vpb;
  15183. PVOID FsContext;
  15184. PVOID FsContext2;
  15185. PSECTION_OBJECT_POINTERS SectionObjectPointer;
  15186. PVOID PrivateCacheMap;
  15187. NTSTATUS FinalStatus;
  15188. struct _FILE_OBJECT *RelatedFileObject;
  15189. BOOLEAN LockOperation;
  15190. BOOLEAN DeletePending;
  15191. BOOLEAN ReadAccess;
  15192. BOOLEAN WriteAccess;
  15193. BOOLEAN DeleteAccess;
  15194. BOOLEAN SharedRead;
  15195. BOOLEAN SharedWrite;
  15196. BOOLEAN SharedDelete;
  15197. ULONG Flags;
  15198. UNICODE_STRING FileName;
  15199. LARGE_INTEGER CurrentByteOffset;
  15200. ULONG Waiters;
  15201. ULONG Busy;
  15202. PVOID LastLock;
  15203. KEVENT Lock;
  15204. KEVENT Event;
  15205. PIO_COMPLETION_CONTEXT CompletionContext;
  15206. } FILE_OBJECT;
  15207. typedef struct _FILE_OBJECT *PFILE_OBJECT; // ntndis
  15208. //
  15209. // Define I/O Request Packet (IRP) flags
  15210. //
  15211. #define IRP_NOCACHE 0x00000001
  15212. #define IRP_PAGING_IO 0x00000002
  15213. #define IRP_MOUNT_COMPLETION 0x00000002
  15214. #define IRP_SYNCHRONOUS_API 0x00000004
  15215. #define IRP_ASSOCIATED_IRP 0x00000008
  15216. #define IRP_BUFFERED_IO 0x00000010
  15217. #define IRP_DEALLOCATE_BUFFER 0x00000020
  15218. #define IRP_INPUT_OPERATION 0x00000040
  15219. #define IRP_SYNCHRONOUS_PAGING_IO 0x00000040
  15220. #define IRP_CREATE_OPERATION 0x00000080
  15221. #define IRP_READ_OPERATION 0x00000100
  15222. #define IRP_WRITE_OPERATION 0x00000200
  15223. #define IRP_CLOSE_OPERATION 0x00000400
  15224. // end_wdm
  15225. #define IRP_DEFER_IO_COMPLETION 0x00000800
  15226. #define IRP_OB_QUERY_NAME 0x00001000
  15227. #define IRP_HOLD_DEVICE_QUEUE 0x00002000
  15228. // end_ntddk end_ntifs end_ntosp
  15229. #define IRP_RETRY_IO_COMPLETION 0x00004000
  15230. #define IRP_HIGH_PRIORITY_PAGING_IO 0x00008000
  15231. //
  15232. // Mask currently used by verifier. This should be made 1 flag in the
  15233. // next release.
  15234. //
  15235. #define IRP_VERIFIER_MASK 0xC0000000
  15236. #define IRP_SET_USER_EVENT IRP_CLOSE_OPERATION
  15237. // begin_ntddk begin_ntifs begin_ntosp
  15238. // begin_wdm
  15239. //
  15240. // Define I/O request packet (IRP) alternate flags for allocation control.
  15241. //
  15242. #define IRP_QUOTA_CHARGED 0x01
  15243. #define IRP_ALLOCATED_MUST_SUCCEED 0x02
  15244. #define IRP_ALLOCATED_FIXED_SIZE 0x04
  15245. #define IRP_LOOKASIDE_ALLOCATION 0x08
  15246. //
  15247. // I/O Request Packet (IRP) definition
  15248. //
  15249. typedef struct DECLSPEC_ALIGN(MEMORY_ALLOCATION_ALIGNMENT) _IRP {
  15250. CSHORT Type;
  15251. USHORT Size;
  15252. //
  15253. // Define the common fields used to control the IRP.
  15254. //
  15255. //
  15256. // Define a pointer to the Memory Descriptor List (MDL) for this I/O
  15257. // request. This field is only used if the I/O is "direct I/O".
  15258. //
  15259. PMDL MdlAddress;
  15260. //
  15261. // Flags word - used to remember various flags.
  15262. //
  15263. ULONG Flags;
  15264. //
  15265. // The following union is used for one of three purposes:
  15266. //
  15267. // 1. This IRP is an associated IRP. The field is a pointer to a master
  15268. // IRP.
  15269. //
  15270. // 2. This is the master IRP. The field is the count of the number of
  15271. // IRPs which must complete (associated IRPs) before the master can
  15272. // complete.
  15273. //
  15274. // 3. This operation is being buffered and the field is the address of
  15275. // the system space buffer.
  15276. //
  15277. union {
  15278. struct _IRP *MasterIrp;
  15279. LONG IrpCount;
  15280. PVOID SystemBuffer;
  15281. } AssociatedIrp;
  15282. //
  15283. // Thread list entry - allows queueing the IRP to the thread pending I/O
  15284. // request packet list.
  15285. //
  15286. LIST_ENTRY ThreadListEntry;
  15287. //
  15288. // I/O status - final status of operation.
  15289. //
  15290. IO_STATUS_BLOCK IoStatus;
  15291. //
  15292. // Requestor mode - mode of the original requestor of this operation.
  15293. //
  15294. KPROCESSOR_MODE RequestorMode;
  15295. //
  15296. // Pending returned - TRUE if pending was initially returned as the
  15297. // status for this packet.
  15298. //
  15299. BOOLEAN PendingReturned;
  15300. //
  15301. // Stack state information.
  15302. //
  15303. CHAR StackCount;
  15304. CHAR CurrentLocation;
  15305. //
  15306. // Cancel - packet has been canceled.
  15307. //
  15308. BOOLEAN Cancel;
  15309. //
  15310. // Cancel Irql - Irql at which the cancel spinlock was acquired.
  15311. //
  15312. KIRQL CancelIrql;
  15313. //
  15314. // ApcEnvironment - Used to save the APC environment at the time that the
  15315. // packet was initialized.
  15316. //
  15317. CCHAR ApcEnvironment;
  15318. //
  15319. // Allocation control flags.
  15320. //
  15321. UCHAR AllocationFlags;
  15322. //
  15323. // User parameters.
  15324. //
  15325. PIO_STATUS_BLOCK UserIosb;
  15326. PKEVENT UserEvent;
  15327. union {
  15328. struct {
  15329. PIO_APC_ROUTINE UserApcRoutine;
  15330. PVOID UserApcContext;
  15331. } AsynchronousParameters;
  15332. LARGE_INTEGER AllocationSize;
  15333. } Overlay;
  15334. //
  15335. // CancelRoutine - Used to contain the address of a cancel routine supplied
  15336. // by a device driver when the IRP is in a cancelable state.
  15337. //
  15338. PDRIVER_CANCEL CancelRoutine;
  15339. //
  15340. // Note that the UserBuffer parameter is outside of the stack so that I/O
  15341. // completion can copy data back into the user's address space without
  15342. // having to know exactly which service was being invoked. The length
  15343. // of the copy is stored in the second half of the I/O status block. If
  15344. // the UserBuffer field is NULL, then no copy is performed.
  15345. //
  15346. PVOID UserBuffer;
  15347. //
  15348. // Kernel structures
  15349. //
  15350. // The following section contains kernel structures which the IRP needs
  15351. // in order to place various work information in kernel controller system
  15352. // queues. Because the size and alignment cannot be controlled, they are
  15353. // placed here at the end so they just hang off and do not affect the
  15354. // alignment of other fields in the IRP.
  15355. //
  15356. union {
  15357. struct {
  15358. union {
  15359. //
  15360. // DeviceQueueEntry - The device queue entry field is used to
  15361. // queue the IRP to the device driver device queue.
  15362. //
  15363. KDEVICE_QUEUE_ENTRY DeviceQueueEntry;
  15364. struct {
  15365. //
  15366. // The following are available to the driver to use in
  15367. // whatever manner is desired, while the driver owns the
  15368. // packet.
  15369. //
  15370. PVOID DriverContext[4];
  15371. } ;
  15372. } ;
  15373. //
  15374. // Thread - pointer to caller's Thread Control Block.
  15375. //
  15376. PETHREAD Thread;
  15377. //
  15378. // Auxiliary buffer - pointer to any auxiliary buffer that is
  15379. // required to pass information to a driver that is not contained
  15380. // in a normal buffer.
  15381. //
  15382. PCHAR AuxiliaryBuffer;
  15383. //
  15384. // The following unnamed structure must be exactly identical
  15385. // to the unnamed structure used in the minipacket header used
  15386. // for completion queue entries.
  15387. //
  15388. struct {
  15389. //
  15390. // List entry - used to queue the packet to completion queue, among
  15391. // others.
  15392. //
  15393. LIST_ENTRY ListEntry;
  15394. union {
  15395. //
  15396. // Current stack location - contains a pointer to the current
  15397. // IO_STACK_LOCATION structure in the IRP stack. This field
  15398. // should never be directly accessed by drivers. They should
  15399. // use the standard functions.
  15400. //
  15401. struct _IO_STACK_LOCATION *CurrentStackLocation;
  15402. //
  15403. // Minipacket type.
  15404. //
  15405. ULONG PacketType;
  15406. };
  15407. };
  15408. //
  15409. // Original file object - pointer to the original file object
  15410. // that was used to open the file. This field is owned by the
  15411. // I/O system and should not be used by any other drivers.
  15412. //
  15413. PFILE_OBJECT OriginalFileObject;
  15414. } Overlay;
  15415. //
  15416. // APC - This APC control block is used for the special kernel APC as
  15417. // well as for the caller's APC, if one was specified in the original
  15418. // argument list. If so, then the APC is reused for the normal APC for
  15419. // whatever mode the caller was in and the "special" routine that is
  15420. // invoked before the APC gets control simply deallocates the IRP.
  15421. //
  15422. KAPC Apc;
  15423. //
  15424. // CompletionKey - This is the key that is used to distinguish
  15425. // individual I/O operations initiated on a single file handle.
  15426. //
  15427. PVOID CompletionKey;
  15428. } Tail;
  15429. } IRP, *PIRP;
  15430. //
  15431. // Define completion routine types for use in stack locations in an IRP
  15432. //
  15433. typedef
  15434. NTSTATUS
  15435. (*PIO_COMPLETION_ROUTINE) (
  15436. IN PDEVICE_OBJECT DeviceObject,
  15437. IN PIRP Irp,
  15438. IN PVOID Context
  15439. );
  15440. //
  15441. // Define stack location control flags
  15442. //
  15443. #define SL_PENDING_RETURNED 0x01
  15444. #define SL_INVOKE_ON_CANCEL 0x20
  15445. #define SL_INVOKE_ON_SUCCESS 0x40
  15446. #define SL_INVOKE_ON_ERROR 0x80
  15447. //
  15448. // Define flags for various functions
  15449. //
  15450. //
  15451. // Create / Create Named Pipe
  15452. //
  15453. // The following flags must exactly match those in the IoCreateFile call's
  15454. // options. The case sensitive flag is added in later, by the parse routine,
  15455. // and is not an actual option to open. Rather, it is part of the object
  15456. // manager's attributes structure.
  15457. //
  15458. #define SL_FORCE_ACCESS_CHECK 0x01
  15459. #define SL_OPEN_PAGING_FILE 0x02
  15460. #define SL_OPEN_TARGET_DIRECTORY 0x04
  15461. #define SL_CASE_SENSITIVE 0x80
  15462. //
  15463. // Read / Write
  15464. //
  15465. #define SL_KEY_SPECIFIED 0x01
  15466. #define SL_OVERRIDE_VERIFY_VOLUME 0x02
  15467. #define SL_WRITE_THROUGH 0x04
  15468. #define SL_FT_SEQUENTIAL_WRITE 0x08
  15469. //
  15470. // Device I/O Control
  15471. //
  15472. //
  15473. // Same SL_OVERRIDE_VERIFY_VOLUME as for read/write above.
  15474. //
  15475. #define SL_READ_ACCESS_GRANTED 0x01
  15476. #define SL_WRITE_ACCESS_GRANTED 0x04 // Gap for SL_OVERRIDE_VERIFY_VOLUME
  15477. //
  15478. // Lock
  15479. //
  15480. #define SL_FAIL_IMMEDIATELY 0x01
  15481. #define SL_EXCLUSIVE_LOCK 0x02
  15482. //
  15483. // QueryDirectory / QueryEa / QueryQuota
  15484. //
  15485. #define SL_RESTART_SCAN 0x01
  15486. #define SL_RETURN_SINGLE_ENTRY 0x02
  15487. #define SL_INDEX_SPECIFIED 0x04
  15488. //
  15489. // NotifyDirectory
  15490. //
  15491. #define SL_WATCH_TREE 0x01
  15492. //
  15493. // FileSystemControl
  15494. //
  15495. // minor: mount/verify volume
  15496. //
  15497. #define SL_ALLOW_RAW_MOUNT 0x01
  15498. //
  15499. // Define PNP/POWER types required by IRP_MJ_PNP/IRP_MJ_POWER.
  15500. //
  15501. typedef enum _DEVICE_RELATION_TYPE {
  15502. BusRelations,
  15503. EjectionRelations,
  15504. PowerRelations,
  15505. RemovalRelations,
  15506. TargetDeviceRelation,
  15507. SingleBusRelations
  15508. } DEVICE_RELATION_TYPE, *PDEVICE_RELATION_TYPE;
  15509. typedef struct _DEVICE_RELATIONS {
  15510. ULONG Count;
  15511. PDEVICE_OBJECT Objects[1]; // variable length
  15512. } DEVICE_RELATIONS, *PDEVICE_RELATIONS;
  15513. typedef enum _DEVICE_USAGE_NOTIFICATION_TYPE {
  15514. DeviceUsageTypeUndefined,
  15515. DeviceUsageTypePaging,
  15516. DeviceUsageTypeHibernation,
  15517. DeviceUsageTypeDumpFile
  15518. } DEVICE_USAGE_NOTIFICATION_TYPE;
  15519. // begin_ntminiport
  15520. // workaround overloaded definition (rpc generated headers all define INTERFACE
  15521. // to match the class name).
  15522. #undef INTERFACE
  15523. typedef struct _INTERFACE {
  15524. USHORT Size;
  15525. USHORT Version;
  15526. PVOID Context;
  15527. PINTERFACE_REFERENCE InterfaceReference;
  15528. PINTERFACE_DEREFERENCE InterfaceDereference;
  15529. // interface specific entries go here
  15530. } INTERFACE, *PINTERFACE;
  15531. // end_ntminiport
  15532. typedef struct _DEVICE_CAPABILITIES {
  15533. USHORT Size;
  15534. USHORT Version; // the version documented here is version 1
  15535. ULONG DeviceD1:1;
  15536. ULONG DeviceD2:1;
  15537. ULONG LockSupported:1;
  15538. ULONG EjectSupported:1; // Ejectable in S0
  15539. ULONG Removable:1;
  15540. ULONG DockDevice:1;
  15541. ULONG UniqueID:1;
  15542. ULONG SilentInstall:1;
  15543. ULONG RawDeviceOK:1;
  15544. ULONG SurpriseRemovalOK:1;
  15545. ULONG WakeFromD0:1;
  15546. ULONG WakeFromD1:1;
  15547. ULONG WakeFromD2:1;
  15548. ULONG WakeFromD3:1;
  15549. ULONG HardwareDisabled:1;
  15550. ULONG NonDynamic:1;
  15551. ULONG WarmEjectSupported:1;
  15552. ULONG NoDisplayInUI:1;
  15553. ULONG Reserved:14;
  15554. ULONG Address;
  15555. ULONG UINumber;
  15556. DEVICE_POWER_STATE DeviceState[POWER_SYSTEM_MAXIMUM];
  15557. SYSTEM_POWER_STATE SystemWake;
  15558. DEVICE_POWER_STATE DeviceWake;
  15559. ULONG D1Latency;
  15560. ULONG D2Latency;
  15561. ULONG D3Latency;
  15562. } DEVICE_CAPABILITIES, *PDEVICE_CAPABILITIES;
  15563. typedef struct _POWER_SEQUENCE {
  15564. ULONG SequenceD1;
  15565. ULONG SequenceD2;
  15566. ULONG SequenceD3;
  15567. } POWER_SEQUENCE, *PPOWER_SEQUENCE;
  15568. typedef enum {
  15569. BusQueryDeviceID = 0, // <Enumerator>\<Enumerator-specific device id>
  15570. BusQueryHardwareIDs = 1, // Hardware ids
  15571. BusQueryCompatibleIDs = 2, // compatible device ids
  15572. BusQueryInstanceID = 3, // persistent id for this instance of the device
  15573. BusQueryDeviceSerialNumber = 4 // serial number for this device
  15574. } BUS_QUERY_ID_TYPE, *PBUS_QUERY_ID_TYPE;
  15575. typedef ULONG PNP_DEVICE_STATE, *PPNP_DEVICE_STATE;
  15576. #define PNP_DEVICE_DISABLED 0x00000001
  15577. #define PNP_DEVICE_DONT_DISPLAY_IN_UI 0x00000002
  15578. #define PNP_DEVICE_FAILED 0x00000004
  15579. #define PNP_DEVICE_REMOVED 0x00000008
  15580. #define PNP_DEVICE_RESOURCE_REQUIREMENTS_CHANGED 0x00000010
  15581. #define PNP_DEVICE_NOT_DISABLEABLE 0x00000020
  15582. typedef enum {
  15583. DeviceTextDescription = 0, // DeviceDesc property
  15584. DeviceTextLocationInformation = 1 // DeviceLocation property
  15585. } DEVICE_TEXT_TYPE, *PDEVICE_TEXT_TYPE;
  15586. //
  15587. // Define I/O Request Packet (IRP) stack locations
  15588. //
  15589. #if !defined(_AMD64_) && !defined(_IA64_)
  15590. #include "pshpack4.h"
  15591. #endif
  15592. // begin_ntndis
  15593. #if defined(_WIN64)
  15594. #define POINTER_ALIGNMENT DECLSPEC_ALIGN(8)
  15595. #else
  15596. #define POINTER_ALIGNMENT
  15597. #endif
  15598. // end_ntndis
  15599. typedef struct _IO_STACK_LOCATION {
  15600. UCHAR MajorFunction;
  15601. UCHAR MinorFunction;
  15602. UCHAR Flags;
  15603. UCHAR Control;
  15604. //
  15605. // The following user parameters are based on the service that is being
  15606. // invoked. Drivers and file systems can determine which set to use based
  15607. // on the above major and minor function codes.
  15608. //
  15609. union {
  15610. //
  15611. // System service parameters for: NtCreateFile
  15612. //
  15613. struct {
  15614. PIO_SECURITY_CONTEXT SecurityContext;
  15615. ULONG Options;
  15616. USHORT POINTER_ALIGNMENT FileAttributes;
  15617. USHORT ShareAccess;
  15618. ULONG POINTER_ALIGNMENT EaLength;
  15619. } Create;
  15620. //
  15621. // System service parameters for: NtReadFile
  15622. //
  15623. struct {
  15624. ULONG Length;
  15625. ULONG POINTER_ALIGNMENT Key;
  15626. LARGE_INTEGER ByteOffset;
  15627. } Read;
  15628. //
  15629. // System service parameters for: NtWriteFile
  15630. //
  15631. struct {
  15632. ULONG Length;
  15633. ULONG POINTER_ALIGNMENT Key;
  15634. LARGE_INTEGER ByteOffset;
  15635. } Write;
  15636. //
  15637. // System service parameters for: NtQueryInformationFile
  15638. //
  15639. struct {
  15640. ULONG Length;
  15641. FILE_INFORMATION_CLASS POINTER_ALIGNMENT FileInformationClass;
  15642. } QueryFile;
  15643. //
  15644. // System service parameters for: NtSetInformationFile
  15645. //
  15646. struct {
  15647. ULONG Length;
  15648. FILE_INFORMATION_CLASS POINTER_ALIGNMENT FileInformationClass;
  15649. PFILE_OBJECT FileObject;
  15650. union {
  15651. struct {
  15652. BOOLEAN ReplaceIfExists;
  15653. BOOLEAN AdvanceOnly;
  15654. };
  15655. ULONG ClusterCount;
  15656. HANDLE DeleteHandle;
  15657. };
  15658. } SetFile;
  15659. //
  15660. // System service parameters for: NtQueryVolumeInformationFile
  15661. //
  15662. struct {
  15663. ULONG Length;
  15664. FS_INFORMATION_CLASS POINTER_ALIGNMENT FsInformationClass;
  15665. } QueryVolume;
  15666. //
  15667. // System service parameters for: NtFlushBuffersFile
  15668. //
  15669. // No extra user-supplied parameters.
  15670. //
  15671. //
  15672. // System service parameters for: NtDeviceIoControlFile
  15673. //
  15674. // Note that the user's output buffer is stored in the UserBuffer field
  15675. // and the user's input buffer is stored in the SystemBuffer field.
  15676. //
  15677. struct {
  15678. ULONG OutputBufferLength;
  15679. ULONG POINTER_ALIGNMENT InputBufferLength;
  15680. ULONG POINTER_ALIGNMENT IoControlCode;
  15681. PVOID Type3InputBuffer;
  15682. } DeviceIoControl;
  15683. // end_wdm
  15684. //
  15685. // System service parameters for: NtQuerySecurityObject
  15686. //
  15687. struct {
  15688. SECURITY_INFORMATION SecurityInformation;
  15689. ULONG POINTER_ALIGNMENT Length;
  15690. } QuerySecurity;
  15691. //
  15692. // System service parameters for: NtSetSecurityObject
  15693. //
  15694. struct {
  15695. SECURITY_INFORMATION SecurityInformation;
  15696. PSECURITY_DESCRIPTOR SecurityDescriptor;
  15697. } SetSecurity;
  15698. // begin_wdm
  15699. //
  15700. // Non-system service parameters.
  15701. //
  15702. // Parameters for MountVolume
  15703. //
  15704. struct {
  15705. PVPB Vpb;
  15706. PDEVICE_OBJECT DeviceObject;
  15707. } MountVolume;
  15708. //
  15709. // Parameters for VerifyVolume
  15710. //
  15711. struct {
  15712. PVPB Vpb;
  15713. PDEVICE_OBJECT DeviceObject;
  15714. } VerifyVolume;
  15715. //
  15716. // Parameters for Scsi with internal device contorl.
  15717. //
  15718. struct {
  15719. struct _SCSI_REQUEST_BLOCK *Srb;
  15720. } Scsi;
  15721. //
  15722. // Parameters for IRP_MN_QUERY_DEVICE_RELATIONS
  15723. //
  15724. struct {
  15725. DEVICE_RELATION_TYPE Type;
  15726. } QueryDeviceRelations;
  15727. //
  15728. // Parameters for IRP_MN_QUERY_INTERFACE
  15729. //
  15730. struct {
  15731. CONST GUID *InterfaceType;
  15732. USHORT Size;
  15733. USHORT Version;
  15734. PINTERFACE Interface;
  15735. PVOID InterfaceSpecificData;
  15736. } QueryInterface;
  15737. // end_ntifs
  15738. //
  15739. // Parameters for IRP_MN_QUERY_CAPABILITIES
  15740. //
  15741. struct {
  15742. PDEVICE_CAPABILITIES Capabilities;
  15743. } DeviceCapabilities;
  15744. //
  15745. // Parameters for IRP_MN_FILTER_RESOURCE_REQUIREMENTS
  15746. //
  15747. struct {
  15748. PIO_RESOURCE_REQUIREMENTS_LIST IoResourceRequirementList;
  15749. } FilterResourceRequirements;
  15750. //
  15751. // Parameters for IRP_MN_READ_CONFIG and IRP_MN_WRITE_CONFIG
  15752. //
  15753. struct {
  15754. ULONG WhichSpace;
  15755. PVOID Buffer;
  15756. ULONG Offset;
  15757. ULONG POINTER_ALIGNMENT Length;
  15758. } ReadWriteConfig;
  15759. //
  15760. // Parameters for IRP_MN_SET_LOCK
  15761. //
  15762. struct {
  15763. BOOLEAN Lock;
  15764. } SetLock;
  15765. //
  15766. // Parameters for IRP_MN_QUERY_ID
  15767. //
  15768. struct {
  15769. BUS_QUERY_ID_TYPE IdType;
  15770. } QueryId;
  15771. //
  15772. // Parameters for IRP_MN_QUERY_DEVICE_TEXT
  15773. //
  15774. struct {
  15775. DEVICE_TEXT_TYPE DeviceTextType;
  15776. LCID POINTER_ALIGNMENT LocaleId;
  15777. } QueryDeviceText;
  15778. //
  15779. // Parameters for IRP_MN_DEVICE_USAGE_NOTIFICATION
  15780. //
  15781. struct {
  15782. BOOLEAN InPath;
  15783. BOOLEAN Reserved[3];
  15784. DEVICE_USAGE_NOTIFICATION_TYPE POINTER_ALIGNMENT Type;
  15785. } UsageNotification;
  15786. //
  15787. // Parameters for IRP_MN_WAIT_WAKE
  15788. //
  15789. struct {
  15790. SYSTEM_POWER_STATE PowerState;
  15791. } WaitWake;
  15792. //
  15793. // Parameter for IRP_MN_POWER_SEQUENCE
  15794. //
  15795. struct {
  15796. PPOWER_SEQUENCE PowerSequence;
  15797. } PowerSequence;
  15798. //
  15799. // Parameters for IRP_MN_SET_POWER and IRP_MN_QUERY_POWER
  15800. //
  15801. struct {
  15802. ULONG SystemContext;
  15803. POWER_STATE_TYPE POINTER_ALIGNMENT Type;
  15804. POWER_STATE POINTER_ALIGNMENT State;
  15805. POWER_ACTION POINTER_ALIGNMENT ShutdownType;
  15806. } Power;
  15807. //
  15808. // Parameters for StartDevice
  15809. //
  15810. struct {
  15811. PCM_RESOURCE_LIST AllocatedResources;
  15812. PCM_RESOURCE_LIST AllocatedResourcesTranslated;
  15813. } StartDevice;
  15814. // begin_ntifs
  15815. //
  15816. // Parameters for Cleanup
  15817. //
  15818. // No extra parameters supplied
  15819. //
  15820. //
  15821. // WMI Irps
  15822. //
  15823. struct {
  15824. ULONG_PTR ProviderId;
  15825. PVOID DataPath;
  15826. ULONG BufferSize;
  15827. PVOID Buffer;
  15828. } WMI;
  15829. //
  15830. // Others - driver-specific
  15831. //
  15832. struct {
  15833. PVOID Argument1;
  15834. PVOID Argument2;
  15835. PVOID Argument3;
  15836. PVOID Argument4;
  15837. } Others;
  15838. } Parameters;
  15839. //
  15840. // Save a pointer to this device driver's device object for this request
  15841. // so it can be passed to the completion routine if needed.
  15842. //
  15843. PDEVICE_OBJECT DeviceObject;
  15844. //
  15845. // The following location contains a pointer to the file object for this
  15846. //
  15847. PFILE_OBJECT FileObject;
  15848. //
  15849. // The following routine is invoked depending on the flags in the above
  15850. // flags field.
  15851. //
  15852. PIO_COMPLETION_ROUTINE CompletionRoutine;
  15853. //
  15854. // The following is used to store the address of the context parameter
  15855. // that should be passed to the CompletionRoutine.
  15856. //
  15857. PVOID Context;
  15858. } IO_STACK_LOCATION, *PIO_STACK_LOCATION;
  15859. #if !defined(_AMD64_) && !defined(_IA64_)
  15860. #include "poppack.h"
  15861. #endif
  15862. //
  15863. // Define the share access structure used by file systems to determine
  15864. // whether or not another accessor may open the file.
  15865. //
  15866. typedef struct _SHARE_ACCESS {
  15867. ULONG OpenCount;
  15868. ULONG Readers;
  15869. ULONG Writers;
  15870. ULONG Deleters;
  15871. ULONG SharedRead;
  15872. ULONG SharedWrite;
  15873. ULONG SharedDelete;
  15874. } SHARE_ACCESS, *PSHARE_ACCESS;
  15875. // end_wdm
  15876. //
  15877. // The following structure is used by drivers that are initializing to
  15878. // determine the number of devices of a particular type that have already
  15879. // been initialized. It is also used to track whether or not the AtDisk
  15880. // address range has already been claimed. Finally, it is used by the
  15881. // NtQuerySystemInformation system service to return device type counts.
  15882. //
  15883. typedef struct _CONFIGURATION_INFORMATION {
  15884. //
  15885. // This field indicates the total number of disks in the system. This
  15886. // number should be used by the driver to determine the name of new
  15887. // disks. This field should be updated by the driver as it finds new
  15888. // disks.
  15889. //
  15890. ULONG DiskCount; // Count of hard disks thus far
  15891. ULONG FloppyCount; // Count of floppy disks thus far
  15892. ULONG CdRomCount; // Count of CD-ROM drives thus far
  15893. ULONG TapeCount; // Count of tape drives thus far
  15894. ULONG ScsiPortCount; // Count of SCSI port adapters thus far
  15895. ULONG SerialCount; // Count of serial devices thus far
  15896. ULONG ParallelCount; // Count of parallel devices thus far
  15897. //
  15898. // These next two fields indicate ownership of one of the two IO address
  15899. // spaces that are used by WD1003-compatable disk controllers.
  15900. //
  15901. BOOLEAN AtDiskPrimaryAddressClaimed; // 0x1F0 - 0x1FF
  15902. BOOLEAN AtDiskSecondaryAddressClaimed; // 0x170 - 0x17F
  15903. //
  15904. // Indicates the structure version, as anything value belong this will have been added.
  15905. // Use the structure size as the version.
  15906. //
  15907. ULONG Version;
  15908. //
  15909. // Indicates the total number of medium changer devices in the system.
  15910. // This field will be updated by the drivers as it determines that
  15911. // new devices have been found and will be supported.
  15912. //
  15913. ULONG MediumChangerCount;
  15914. } CONFIGURATION_INFORMATION, *PCONFIGURATION_INFORMATION;
  15915. //
  15916. // Public I/O routine definitions
  15917. //
  15918. NTKERNELAPI
  15919. VOID
  15920. IoAcquireCancelSpinLock(
  15921. OUT PKIRQL Irql
  15922. );
  15923. DECLSPEC_DEPRECATED_DDK // Use AllocateAdapterChannel
  15924. NTKERNELAPI
  15925. NTSTATUS
  15926. IoAllocateAdapterChannel(
  15927. IN PADAPTER_OBJECT AdapterObject,
  15928. IN PDEVICE_OBJECT DeviceObject,
  15929. IN ULONG NumberOfMapRegisters,
  15930. IN PDRIVER_CONTROL ExecutionRoutine,
  15931. IN PVOID Context
  15932. );
  15933. NTKERNELAPI
  15934. VOID
  15935. IoAllocateController(
  15936. IN PCONTROLLER_OBJECT ControllerObject,
  15937. IN PDEVICE_OBJECT DeviceObject,
  15938. IN PDRIVER_CONTROL ExecutionRoutine,
  15939. IN PVOID Context
  15940. );
  15941. // begin_wdm
  15942. NTKERNELAPI
  15943. NTSTATUS
  15944. IoAllocateDriverObjectExtension(
  15945. IN PDRIVER_OBJECT DriverObject,
  15946. IN PVOID ClientIdentificationAddress,
  15947. IN ULONG DriverObjectExtensionSize,
  15948. OUT PVOID *DriverObjectExtension
  15949. );
  15950. // begin_ntifs
  15951. NTKERNELAPI
  15952. PVOID
  15953. IoAllocateErrorLogEntry(
  15954. IN PVOID IoObject,
  15955. IN UCHAR EntrySize
  15956. );
  15957. NTKERNELAPI
  15958. PIRP
  15959. IoAllocateIrp(
  15960. IN CCHAR StackSize,
  15961. IN BOOLEAN ChargeQuota
  15962. );
  15963. NTKERNELAPI
  15964. PMDL
  15965. IoAllocateMdl(
  15966. IN PVOID VirtualAddress,
  15967. IN ULONG Length,
  15968. IN BOOLEAN SecondaryBuffer,
  15969. IN BOOLEAN ChargeQuota,
  15970. IN OUT PIRP Irp OPTIONAL
  15971. );
  15972. // end_wdm end_ntifs
  15973. //++
  15974. //
  15975. // VOID
  15976. // IoAssignArcName(
  15977. // IN PUNICODE_STRING ArcName,
  15978. // IN PUNICODE_STRING DeviceName
  15979. // )
  15980. //
  15981. // Routine Description:
  15982. //
  15983. // This routine is invoked by drivers of bootable media to create a symbolic
  15984. // link between the ARC name of their device and its NT name. This allows
  15985. // the system to determine which device in the system was actually booted
  15986. // from since the ARC firmware only deals in ARC names, and NT only deals
  15987. // in NT names.
  15988. //
  15989. // Arguments:
  15990. //
  15991. // ArcName - Supplies the Unicode string representing the ARC name.
  15992. //
  15993. // DeviceName - Supplies the name to which the ARCname refers.
  15994. //
  15995. // Return Value:
  15996. //
  15997. // None.
  15998. //
  15999. //--
  16000. #define IoAssignArcName( ArcName, DeviceName ) ( \
  16001. IoCreateSymbolicLink( (ArcName), (DeviceName) ) )
  16002. DECLSPEC_DEPRECATED_DDK // Use Pnp or IoReprtDetectedDevice
  16003. NTKERNELAPI
  16004. NTSTATUS
  16005. IoAssignResources (
  16006. IN PUNICODE_STRING RegistryPath,
  16007. IN PUNICODE_STRING DriverClassName OPTIONAL,
  16008. IN PDRIVER_OBJECT DriverObject,
  16009. IN PDEVICE_OBJECT DeviceObject OPTIONAL,
  16010. IN PIO_RESOURCE_REQUIREMENTS_LIST RequestedResources,
  16011. IN OUT PCM_RESOURCE_LIST *AllocatedResources
  16012. );
  16013. typedef enum _IO_PAGING_PRIORITY {
  16014. IoPagingPriorityInvalid, // Returned if a non-paging IO IRP is passed.
  16015. IoPagingPriorityNormal, // For regular paging IO
  16016. IoPagingPriorityHigh, // For high priority paging IO
  16017. IoPagingPriorityReserved1, // Reserved for future use.
  16018. IoPagingPriorityReserved2 // Reserved for future use.
  16019. } IO_PAGING_PRIORITY;
  16020. NTKERNELAPI
  16021. NTSTATUS
  16022. IoAttachDevice(
  16023. IN PDEVICE_OBJECT SourceDevice,
  16024. IN PUNICODE_STRING TargetDevice,
  16025. OUT PDEVICE_OBJECT *AttachedDevice
  16026. );
  16027. // end_wdm
  16028. DECLSPEC_DEPRECATED_DDK // Use IoAttachDeviceToDeviceStack
  16029. NTKERNELAPI
  16030. NTSTATUS
  16031. IoAttachDeviceByPointer(
  16032. IN PDEVICE_OBJECT SourceDevice,
  16033. IN PDEVICE_OBJECT TargetDevice
  16034. );
  16035. // begin_wdm
  16036. NTKERNELAPI
  16037. PDEVICE_OBJECT
  16038. IoAttachDeviceToDeviceStack(
  16039. IN PDEVICE_OBJECT SourceDevice,
  16040. IN PDEVICE_OBJECT TargetDevice
  16041. );
  16042. NTKERNELAPI
  16043. PIRP
  16044. IoBuildAsynchronousFsdRequest(
  16045. IN ULONG MajorFunction,
  16046. IN PDEVICE_OBJECT DeviceObject,
  16047. IN OUT PVOID Buffer OPTIONAL,
  16048. IN ULONG Length OPTIONAL,
  16049. IN PLARGE_INTEGER StartingOffset OPTIONAL,
  16050. IN PIO_STATUS_BLOCK IoStatusBlock OPTIONAL
  16051. );
  16052. NTKERNELAPI
  16053. PIRP
  16054. IoBuildDeviceIoControlRequest(
  16055. IN ULONG IoControlCode,
  16056. IN PDEVICE_OBJECT DeviceObject,
  16057. IN PVOID InputBuffer OPTIONAL,
  16058. IN ULONG InputBufferLength,
  16059. OUT PVOID OutputBuffer OPTIONAL,
  16060. IN ULONG OutputBufferLength,
  16061. IN BOOLEAN InternalDeviceIoControl,
  16062. IN PKEVENT Event,
  16063. OUT PIO_STATUS_BLOCK IoStatusBlock
  16064. );
  16065. NTKERNELAPI
  16066. VOID
  16067. IoBuildPartialMdl(
  16068. IN PMDL SourceMdl,
  16069. IN OUT PMDL TargetMdl,
  16070. IN PVOID VirtualAddress,
  16071. IN ULONG Length
  16072. );
  16073. typedef struct _BOOTDISK_INFORMATION {
  16074. LONGLONG BootPartitionOffset;
  16075. LONGLONG SystemPartitionOffset;
  16076. ULONG BootDeviceSignature;
  16077. ULONG SystemDeviceSignature;
  16078. } BOOTDISK_INFORMATION, *PBOOTDISK_INFORMATION;
  16079. //
  16080. // This structure should follow the previous structure field for field.
  16081. //
  16082. typedef struct _BOOTDISK_INFORMATION_EX {
  16083. LONGLONG BootPartitionOffset;
  16084. LONGLONG SystemPartitionOffset;
  16085. ULONG BootDeviceSignature;
  16086. ULONG SystemDeviceSignature;
  16087. GUID BootDeviceGuid;
  16088. GUID SystemDeviceGuid;
  16089. BOOLEAN BootDeviceIsGpt;
  16090. BOOLEAN SystemDeviceIsGpt;
  16091. } BOOTDISK_INFORMATION_EX, *PBOOTDISK_INFORMATION_EX;
  16092. NTKERNELAPI
  16093. NTSTATUS
  16094. IoGetBootDiskInformation(
  16095. IN OUT PBOOTDISK_INFORMATION BootDiskInformation,
  16096. IN ULONG Size
  16097. );
  16098. NTKERNELAPI
  16099. PIRP
  16100. IoBuildSynchronousFsdRequest(
  16101. IN ULONG MajorFunction,
  16102. IN PDEVICE_OBJECT DeviceObject,
  16103. IN OUT PVOID Buffer OPTIONAL,
  16104. IN ULONG Length OPTIONAL,
  16105. IN PLARGE_INTEGER StartingOffset OPTIONAL,
  16106. IN PKEVENT Event,
  16107. OUT PIO_STATUS_BLOCK IoStatusBlock
  16108. );
  16109. NTKERNELAPI
  16110. NTSTATUS
  16111. FASTCALL
  16112. IofCallDriver(
  16113. IN PDEVICE_OBJECT DeviceObject,
  16114. IN OUT PIRP Irp
  16115. );
  16116. #define IoCallDriver(a,b) \
  16117. IofCallDriver(a,b)
  16118. NTKERNELAPI
  16119. BOOLEAN
  16120. IoCancelIrp(
  16121. IN PIRP Irp
  16122. );
  16123. NTKERNELAPI
  16124. NTSTATUS
  16125. IoCheckShareAccess(
  16126. IN ACCESS_MASK DesiredAccess,
  16127. IN ULONG DesiredShareAccess,
  16128. IN OUT PFILE_OBJECT FileObject,
  16129. IN OUT PSHARE_ACCESS ShareAccess,
  16130. IN BOOLEAN Update
  16131. );
  16132. //
  16133. // This value should be returned from completion routines to continue
  16134. // completing the IRP upwards. Otherwise, STATUS_MORE_PROCESSING_REQUIRED
  16135. // should be returned.
  16136. //
  16137. #define STATUS_CONTINUE_COMPLETION STATUS_SUCCESS
  16138. //
  16139. // Completion routines can also use this enumeration in place of status codes.
  16140. //
  16141. typedef enum _IO_COMPLETION_ROUTINE_RESULT {
  16142. ContinueCompletion = STATUS_CONTINUE_COMPLETION,
  16143. StopCompletion = STATUS_MORE_PROCESSING_REQUIRED
  16144. } IO_COMPLETION_ROUTINE_RESULT, *PIO_COMPLETION_ROUTINE_RESULT;
  16145. NTKERNELAPI
  16146. VOID
  16147. FASTCALL
  16148. IofCompleteRequest(
  16149. IN PIRP Irp,
  16150. IN CCHAR PriorityBoost
  16151. );
  16152. #define IoCompleteRequest(a,b) \
  16153. IofCompleteRequest(a,b)
  16154. // end_ntifs
  16155. NTKERNELAPI
  16156. NTSTATUS
  16157. IoConnectInterrupt(
  16158. OUT PKINTERRUPT *InterruptObject,
  16159. IN PKSERVICE_ROUTINE ServiceRoutine,
  16160. IN PVOID ServiceContext,
  16161. IN PKSPIN_LOCK SpinLock OPTIONAL,
  16162. IN ULONG Vector,
  16163. IN KIRQL Irql,
  16164. IN KIRQL SynchronizeIrql,
  16165. IN KINTERRUPT_MODE InterruptMode,
  16166. IN BOOLEAN ShareVector,
  16167. IN KAFFINITY ProcessorEnableMask,
  16168. IN BOOLEAN FloatingSave
  16169. );
  16170. // end_wdm
  16171. NTKERNELAPI
  16172. PCONTROLLER_OBJECT
  16173. IoCreateController(
  16174. IN ULONG Size
  16175. );
  16176. // begin_wdm begin_ntifs
  16177. NTKERNELAPI
  16178. NTSTATUS
  16179. IoCreateDevice(
  16180. IN PDRIVER_OBJECT DriverObject,
  16181. IN ULONG DeviceExtensionSize,
  16182. IN PUNICODE_STRING DeviceName OPTIONAL,
  16183. IN DEVICE_TYPE DeviceType,
  16184. IN ULONG DeviceCharacteristics,
  16185. IN BOOLEAN Exclusive,
  16186. OUT PDEVICE_OBJECT *DeviceObject
  16187. );
  16188. #define WDM_MAJORVERSION 0x01
  16189. #define WDM_MINORVERSION 0x30
  16190. NTKERNELAPI
  16191. BOOLEAN
  16192. IoIsWdmVersionAvailable(
  16193. IN UCHAR MajorVersion,
  16194. IN UCHAR MinorVersion
  16195. );
  16196. NTKERNELAPI
  16197. PKEVENT
  16198. IoCreateNotificationEvent(
  16199. IN PUNICODE_STRING EventName,
  16200. OUT PHANDLE EventHandle
  16201. );
  16202. NTKERNELAPI
  16203. NTSTATUS
  16204. IoCreateSymbolicLink(
  16205. IN PUNICODE_STRING SymbolicLinkName,
  16206. IN PUNICODE_STRING DeviceName
  16207. );
  16208. NTKERNELAPI
  16209. PKEVENT
  16210. IoCreateSynchronizationEvent(
  16211. IN PUNICODE_STRING EventName,
  16212. OUT PHANDLE EventHandle
  16213. );
  16214. NTKERNELAPI
  16215. NTSTATUS
  16216. IoCreateUnprotectedSymbolicLink(
  16217. IN PUNICODE_STRING SymbolicLinkName,
  16218. IN PUNICODE_STRING DeviceName
  16219. );
  16220. // end_wdm
  16221. //++
  16222. //
  16223. // VOID
  16224. // IoDeassignArcName(
  16225. // IN PUNICODE_STRING ArcName
  16226. // )
  16227. //
  16228. // Routine Description:
  16229. //
  16230. // This routine is invoked by drivers to deassign an ARC name that they
  16231. // created to a device. This is generally only called if the driver is
  16232. // deleting the device object, which means that the driver is probably
  16233. // unloading.
  16234. //
  16235. // Arguments:
  16236. //
  16237. // ArcName - Supplies the ARC name to be removed.
  16238. //
  16239. // Return Value:
  16240. //
  16241. // None.
  16242. //
  16243. //--
  16244. #define IoDeassignArcName( ArcName ) ( \
  16245. IoDeleteSymbolicLink( (ArcName) ) )
  16246. // end_ntifs
  16247. NTKERNELAPI
  16248. VOID
  16249. IoDeleteController(
  16250. IN PCONTROLLER_OBJECT ControllerObject
  16251. );
  16252. // begin_wdm begin_ntifs
  16253. NTKERNELAPI
  16254. VOID
  16255. IoDeleteDevice(
  16256. IN PDEVICE_OBJECT DeviceObject
  16257. );
  16258. NTKERNELAPI
  16259. NTSTATUS
  16260. IoDeleteSymbolicLink(
  16261. IN PUNICODE_STRING SymbolicLinkName
  16262. );
  16263. NTKERNELAPI
  16264. VOID
  16265. IoDetachDevice(
  16266. IN OUT PDEVICE_OBJECT TargetDevice
  16267. );
  16268. // end_ntifs
  16269. NTKERNELAPI
  16270. VOID
  16271. IoDisconnectInterrupt(
  16272. IN PKINTERRUPT InterruptObject
  16273. );
  16274. NTKERNELAPI
  16275. VOID
  16276. IoFreeController(
  16277. IN PCONTROLLER_OBJECT ControllerObject
  16278. );
  16279. // begin_wdm begin_ntifs
  16280. NTKERNELAPI
  16281. VOID
  16282. IoFreeIrp(
  16283. IN PIRP Irp
  16284. );
  16285. NTKERNELAPI
  16286. VOID
  16287. IoFreeMdl(
  16288. IN PMDL Mdl
  16289. );
  16290. NTKERNELAPI
  16291. PDEVICE_OBJECT
  16292. IoGetAttachedDeviceReference(
  16293. IN PDEVICE_OBJECT DeviceObject
  16294. );
  16295. NTKERNELAPI
  16296. PCONFIGURATION_INFORMATION
  16297. IoGetConfigurationInformation( VOID );
  16298. //++
  16299. //
  16300. // PIO_STACK_LOCATION
  16301. // IoGetCurrentIrpStackLocation(
  16302. // IN PIRP Irp
  16303. // )
  16304. //
  16305. // Routine Description:
  16306. //
  16307. // This routine is invoked to return a pointer to the current stack location
  16308. // in an I/O Request Packet (IRP).
  16309. //
  16310. // Arguments:
  16311. //
  16312. // Irp - Pointer to the I/O Request Packet.
  16313. //
  16314. // Return Value:
  16315. //
  16316. // The function value is a pointer to the current stack location in the
  16317. // packet.
  16318. //
  16319. //--
  16320. #define IoGetCurrentIrpStackLocation( Irp ) ( (Irp)->Tail.Overlay.CurrentStackLocation )
  16321. NTKERNELAPI
  16322. NTSTATUS
  16323. IoGetDeviceObjectPointer(
  16324. IN PUNICODE_STRING ObjectName,
  16325. IN ACCESS_MASK DesiredAccess,
  16326. OUT PFILE_OBJECT *FileObject,
  16327. OUT PDEVICE_OBJECT *DeviceObject
  16328. );
  16329. NTKERNELAPI
  16330. struct _DMA_ADAPTER *
  16331. IoGetDmaAdapter(
  16332. IN PDEVICE_OBJECT PhysicalDeviceObject, OPTIONAL // required for PnP drivers
  16333. IN struct _DEVICE_DESCRIPTION *DeviceDescription,
  16334. IN OUT PULONG NumberOfMapRegisters
  16335. );
  16336. NTKERNELAPI
  16337. BOOLEAN
  16338. IoForwardIrpSynchronously(
  16339. IN PDEVICE_OBJECT DeviceObject,
  16340. IN PIRP Irp
  16341. );
  16342. #define IoForwardAndCatchIrp IoForwardIrpSynchronously
  16343. // end_wdm
  16344. NTKERNELAPI
  16345. PGENERIC_MAPPING
  16346. IoGetFileObjectGenericMapping(
  16347. VOID
  16348. );
  16349. NTKERNELAPI
  16350. PVOID
  16351. IoGetInitialStack(
  16352. VOID
  16353. );
  16354. NTKERNELAPI
  16355. VOID
  16356. IoGetStackLimits (
  16357. OUT PULONG_PTR LowLimit,
  16358. OUT PULONG_PTR HighLimit
  16359. );
  16360. //
  16361. // The following function is used to tell the caller how much stack is available
  16362. //
  16363. FORCEINLINE
  16364. ULONG_PTR
  16365. IoGetRemainingStackSize (
  16366. VOID
  16367. )
  16368. {
  16369. ULONG_PTR Top;
  16370. ULONG_PTR Bottom;
  16371. IoGetStackLimits( &Bottom, &Top );
  16372. return((ULONG_PTR)(&Top) - Bottom );
  16373. }
  16374. //++
  16375. //
  16376. // PIO_STACK_LOCATION
  16377. // IoGetNextIrpStackLocation(
  16378. // IN PIRP Irp
  16379. // )
  16380. //
  16381. // Routine Description:
  16382. //
  16383. // This routine is invoked to return a pointer to the next stack location
  16384. // in an I/O Request Packet (IRP).
  16385. //
  16386. // Arguments:
  16387. //
  16388. // Irp - Pointer to the I/O Request Packet.
  16389. //
  16390. // Return Value:
  16391. //
  16392. // The function value is a pointer to the next stack location in the packet.
  16393. //
  16394. //--
  16395. #define IoGetNextIrpStackLocation( Irp ) (\
  16396. (Irp)->Tail.Overlay.CurrentStackLocation - 1 )
  16397. NTKERNELAPI
  16398. PDEVICE_OBJECT
  16399. IoGetRelatedDeviceObject(
  16400. IN PFILE_OBJECT FileObject
  16401. );
  16402. //++
  16403. //
  16404. // VOID
  16405. // IoInitializeDpcRequest(
  16406. // IN PDEVICE_OBJECT DeviceObject,
  16407. // IN PIO_DPC_ROUTINE DpcRoutine
  16408. // )
  16409. //
  16410. // Routine Description:
  16411. //
  16412. // This routine is invoked to initialize the DPC in a device object for a
  16413. // device driver during its initialization routine. The DPC is used later
  16414. // when the driver interrupt service routine requests that a DPC routine
  16415. // be queued for later execution.
  16416. //
  16417. // Arguments:
  16418. //
  16419. // DeviceObject - Pointer to the device object that the request is for.
  16420. //
  16421. // DpcRoutine - Address of the driver's DPC routine to be executed when
  16422. // the DPC is dequeued for processing.
  16423. //
  16424. // Return Value:
  16425. //
  16426. // None.
  16427. //
  16428. //--
  16429. #define IoInitializeDpcRequest( DeviceObject, DpcRoutine ) (\
  16430. KeInitializeDpc( &(DeviceObject)->Dpc, \
  16431. (PKDEFERRED_ROUTINE) (DpcRoutine), \
  16432. (DeviceObject) ) )
  16433. NTKERNELAPI
  16434. VOID
  16435. IoInitializeIrp(
  16436. IN OUT PIRP Irp,
  16437. IN USHORT PacketSize,
  16438. IN CCHAR StackSize
  16439. );
  16440. NTKERNELAPI
  16441. NTSTATUS
  16442. IoInitializeTimer(
  16443. IN PDEVICE_OBJECT DeviceObject,
  16444. IN PIO_TIMER_ROUTINE TimerRoutine,
  16445. IN PVOID Context
  16446. );
  16447. //++
  16448. //
  16449. // BOOLEAN
  16450. // IoIsErrorUserInduced(
  16451. // IN NTSTATUS Status
  16452. // )
  16453. //
  16454. // Routine Description:
  16455. //
  16456. // This routine is invoked to determine if an error was as a
  16457. // result of user actions. Typically these error are related
  16458. // to removable media and will result in a pop-up.
  16459. //
  16460. // Arguments:
  16461. //
  16462. // Status - The status value to check.
  16463. //
  16464. // Return Value:
  16465. // The function value is TRUE if the user induced the error,
  16466. // otherwise FALSE is returned.
  16467. //
  16468. //--
  16469. #define IoIsErrorUserInduced( Status ) ((BOOLEAN) \
  16470. (((Status) == STATUS_DEVICE_NOT_READY) || \
  16471. ((Status) == STATUS_IO_TIMEOUT) || \
  16472. ((Status) == STATUS_MEDIA_WRITE_PROTECTED) || \
  16473. ((Status) == STATUS_NO_MEDIA_IN_DEVICE) || \
  16474. ((Status) == STATUS_VERIFY_REQUIRED) || \
  16475. ((Status) == STATUS_UNRECOGNIZED_MEDIA) || \
  16476. ((Status) == STATUS_WRONG_VOLUME)))
  16477. NTKERNELAPI
  16478. PIRP
  16479. IoMakeAssociatedIrp(
  16480. IN PIRP Irp,
  16481. IN CCHAR StackSize
  16482. );
  16483. // begin_wdm
  16484. //++
  16485. //
  16486. // VOID
  16487. // IoMarkIrpPending(
  16488. // IN OUT PIRP Irp
  16489. // )
  16490. //
  16491. // Routine Description:
  16492. //
  16493. // This routine marks the specified I/O Request Packet (IRP) to indicate
  16494. // that an initial status of STATUS_PENDING was returned to the caller.
  16495. // This is used so that I/O completion can determine whether or not to
  16496. // fully complete the I/O operation requested by the packet.
  16497. //
  16498. // Arguments:
  16499. //
  16500. // Irp - Pointer to the I/O Request Packet to be marked pending.
  16501. //
  16502. // Return Value:
  16503. //
  16504. // None.
  16505. //
  16506. //--
  16507. #define IoMarkIrpPending( Irp ) ( \
  16508. IoGetCurrentIrpStackLocation( (Irp) )->Control |= SL_PENDING_RETURNED )
  16509. NTKERNELAPI
  16510. VOID
  16511. IoRaiseHardError(
  16512. IN PIRP Irp,
  16513. IN PVPB Vpb OPTIONAL,
  16514. IN PDEVICE_OBJECT RealDeviceObject
  16515. );
  16516. NTKERNELAPI
  16517. BOOLEAN
  16518. IoRaiseInformationalHardError(
  16519. IN NTSTATUS ErrorStatus,
  16520. IN PUNICODE_STRING String OPTIONAL,
  16521. IN PKTHREAD Thread OPTIONAL
  16522. );
  16523. NTKERNELAPI
  16524. BOOLEAN
  16525. IoSetThreadHardErrorMode(
  16526. IN BOOLEAN EnableHardErrors
  16527. );
  16528. NTKERNELAPI
  16529. VOID
  16530. IoRegisterBootDriverReinitialization(
  16531. IN PDRIVER_OBJECT DriverObject,
  16532. IN PDRIVER_REINITIALIZE DriverReinitializationRoutine,
  16533. IN PVOID Context
  16534. );
  16535. NTKERNELAPI
  16536. VOID
  16537. IoRegisterDriverReinitialization(
  16538. IN PDRIVER_OBJECT DriverObject,
  16539. IN PDRIVER_REINITIALIZE DriverReinitializationRoutine,
  16540. IN PVOID Context
  16541. );
  16542. NTKERNELAPI
  16543. NTSTATUS
  16544. IoRegisterShutdownNotification(
  16545. IN PDEVICE_OBJECT DeviceObject
  16546. );
  16547. NTKERNELAPI
  16548. NTSTATUS
  16549. IoRegisterLastChanceShutdownNotification(
  16550. IN PDEVICE_OBJECT DeviceObject
  16551. );
  16552. // begin_wdm
  16553. NTKERNELAPI
  16554. VOID
  16555. IoReleaseCancelSpinLock(
  16556. IN KIRQL Irql
  16557. );
  16558. NTKERNELAPI
  16559. VOID
  16560. IoRemoveShareAccess(
  16561. IN PFILE_OBJECT FileObject,
  16562. IN OUT PSHARE_ACCESS ShareAccess
  16563. );
  16564. // end_ntddk end_ntifs end_ntosp
  16565. NTKERNELAPI
  16566. NTSTATUS
  16567. IoReportHalResourceUsage(
  16568. IN PUNICODE_STRING HalName,
  16569. IN PCM_RESOURCE_LIST RawResourceList,
  16570. IN PCM_RESOURCE_LIST TranslatedResourceList,
  16571. IN ULONG ResourceListSize
  16572. );
  16573. // begin_ntddk begin_ntifs begin_ntosp
  16574. DECLSPEC_DEPRECATED_DDK // Use IoReportResourceForDetection
  16575. NTKERNELAPI
  16576. NTSTATUS
  16577. IoReportResourceUsage(
  16578. IN PUNICODE_STRING DriverClassName OPTIONAL,
  16579. IN PDRIVER_OBJECT DriverObject,
  16580. IN PCM_RESOURCE_LIST DriverList OPTIONAL,
  16581. IN ULONG DriverListSize OPTIONAL,
  16582. IN PDEVICE_OBJECT DeviceObject,
  16583. IN PCM_RESOURCE_LIST DeviceList OPTIONAL,
  16584. IN ULONG DeviceListSize OPTIONAL,
  16585. IN BOOLEAN OverrideConflict,
  16586. OUT PBOOLEAN ConflictDetected
  16587. );
  16588. // begin_wdm
  16589. //++
  16590. //
  16591. // VOID
  16592. // IoRequestDpc(
  16593. // IN PDEVICE_OBJECT DeviceObject,
  16594. // IN PIRP Irp,
  16595. // IN PVOID Context
  16596. // )
  16597. //
  16598. // Routine Description:
  16599. //
  16600. // This routine is invoked by the device driver's interrupt service routine
  16601. // to request that a DPC routine be queued for later execution at a lower
  16602. // IRQL.
  16603. //
  16604. // Arguments:
  16605. //
  16606. // DeviceObject - Device object for which the request is being processed.
  16607. //
  16608. // Irp - Pointer to the current I/O Request Packet (IRP) for the specified
  16609. // device.
  16610. //
  16611. // Context - Provides a general context parameter to be passed to the
  16612. // DPC routine.
  16613. //
  16614. // Return Value:
  16615. //
  16616. // None.
  16617. //
  16618. //--
  16619. #define IoRequestDpc( DeviceObject, Irp, Context ) ( \
  16620. KeInsertQueueDpc( &(DeviceObject)->Dpc, (Irp), (Context) ) )
  16621. //++
  16622. //
  16623. // PDRIVER_CANCEL
  16624. // IoSetCancelRoutine(
  16625. // IN PIRP Irp,
  16626. // IN PDRIVER_CANCEL CancelRoutine
  16627. // )
  16628. //
  16629. // Routine Description:
  16630. //
  16631. // This routine is invoked to set the address of a cancel routine which
  16632. // is to be invoked when an I/O packet has been canceled.
  16633. //
  16634. // Arguments:
  16635. //
  16636. // Irp - Pointer to the I/O Request Packet itself.
  16637. //
  16638. // CancelRoutine - Address of the cancel routine that is to be invoked
  16639. // if the IRP is cancelled.
  16640. //
  16641. // Return Value:
  16642. //
  16643. // Previous value of CancelRoutine field in the IRP.
  16644. //
  16645. //--
  16646. #define IoSetCancelRoutine( Irp, NewCancelRoutine ) ( \
  16647. (PDRIVER_CANCEL) (ULONG_PTR) InterlockedExchangePointer( (PVOID *) &(Irp)->CancelRoutine, (PVOID) (ULONG_PTR)(NewCancelRoutine) ) )
  16648. //++
  16649. //
  16650. // VOID
  16651. // IoSetCompletionRoutine(
  16652. // IN PIRP Irp,
  16653. // IN PIO_COMPLETION_ROUTINE CompletionRoutine,
  16654. // IN PVOID Context,
  16655. // IN BOOLEAN InvokeOnSuccess,
  16656. // IN BOOLEAN InvokeOnError,
  16657. // IN BOOLEAN InvokeOnCancel
  16658. // )
  16659. //
  16660. // Routine Description:
  16661. //
  16662. // This routine is invoked to set the address of a completion routine which
  16663. // is to be invoked when an I/O packet has been completed by a lower-level
  16664. // driver.
  16665. //
  16666. // Arguments:
  16667. //
  16668. // Irp - Pointer to the I/O Request Packet itself.
  16669. //
  16670. // CompletionRoutine - Address of the completion routine that is to be
  16671. // invoked once the next level driver completes the packet.
  16672. //
  16673. // Context - Specifies a context parameter to be passed to the completion
  16674. // routine.
  16675. //
  16676. // InvokeOnSuccess - Specifies that the completion routine is invoked when the
  16677. // operation is successfully completed.
  16678. //
  16679. // InvokeOnError - Specifies that the completion routine is invoked when the
  16680. // operation completes with an error status.
  16681. //
  16682. // InvokeOnCancel - Specifies that the completion routine is invoked when the
  16683. // operation is being canceled.
  16684. //
  16685. // Return Value:
  16686. //
  16687. // None.
  16688. //
  16689. //--
  16690. #define IoSetCompletionRoutine( Irp, Routine, CompletionContext, Success, Error, Cancel ) { \
  16691. PIO_STACK_LOCATION __irpSp; \
  16692. ASSERT( (Success) | (Error) | (Cancel) ? (Routine) != NULL : TRUE ); \
  16693. __irpSp = IoGetNextIrpStackLocation( (Irp) ); \
  16694. __irpSp->CompletionRoutine = (Routine); \
  16695. __irpSp->Context = (CompletionContext); \
  16696. __irpSp->Control = 0; \
  16697. if ((Success)) { __irpSp->Control = SL_INVOKE_ON_SUCCESS; } \
  16698. if ((Error)) { __irpSp->Control |= SL_INVOKE_ON_ERROR; } \
  16699. if ((Cancel)) { __irpSp->Control |= SL_INVOKE_ON_CANCEL; } }
  16700. NTSTATUS
  16701. IoSetCompletionRoutineEx(
  16702. IN PDEVICE_OBJECT DeviceObject,
  16703. IN PIRP Irp,
  16704. IN PIO_COMPLETION_ROUTINE CompletionRoutine,
  16705. IN PVOID Context,
  16706. IN BOOLEAN InvokeOnSuccess,
  16707. IN BOOLEAN InvokeOnError,
  16708. IN BOOLEAN InvokeOnCancel
  16709. );
  16710. NTKERNELAPI
  16711. VOID
  16712. IoSetHardErrorOrVerifyDevice(
  16713. IN PIRP Irp,
  16714. IN PDEVICE_OBJECT DeviceObject
  16715. );
  16716. //++
  16717. //
  16718. // VOID
  16719. // IoSetNextIrpStackLocation (
  16720. // IN OUT PIRP Irp
  16721. // )
  16722. //
  16723. // Routine Description:
  16724. //
  16725. // This routine is invoked to set the current IRP stack location to
  16726. // the next stack location, i.e. it "pushes" the stack.
  16727. //
  16728. // Arguments:
  16729. //
  16730. // Irp - Pointer to the I/O Request Packet (IRP).
  16731. //
  16732. // Return Value:
  16733. //
  16734. // None.
  16735. //
  16736. //--
  16737. #define IoSetNextIrpStackLocation( Irp ) { \
  16738. (Irp)->CurrentLocation--; \
  16739. (Irp)->Tail.Overlay.CurrentStackLocation--; }
  16740. //++
  16741. //
  16742. // VOID
  16743. // IoCopyCurrentIrpStackLocationToNext(
  16744. // IN PIRP Irp
  16745. // )
  16746. //
  16747. // Routine Description:
  16748. //
  16749. // This routine is invoked to copy the IRP stack arguments and file
  16750. // pointer from the current IrpStackLocation to the next
  16751. // in an I/O Request Packet (IRP).
  16752. //
  16753. // If the caller wants to call IoCallDriver with a completion routine
  16754. // but does not wish to change the arguments otherwise,
  16755. // the caller first calls IoCopyCurrentIrpStackLocationToNext,
  16756. // then IoSetCompletionRoutine, then IoCallDriver.
  16757. //
  16758. // Arguments:
  16759. //
  16760. // Irp - Pointer to the I/O Request Packet.
  16761. //
  16762. // Return Value:
  16763. //
  16764. // None.
  16765. //
  16766. //--
  16767. #define IoCopyCurrentIrpStackLocationToNext( Irp ) { \
  16768. PIO_STACK_LOCATION __irpSp; \
  16769. PIO_STACK_LOCATION __nextIrpSp; \
  16770. __irpSp = IoGetCurrentIrpStackLocation( (Irp) ); \
  16771. __nextIrpSp = IoGetNextIrpStackLocation( (Irp) ); \
  16772. RtlCopyMemory( __nextIrpSp, __irpSp, FIELD_OFFSET(IO_STACK_LOCATION, CompletionRoutine)); \
  16773. __nextIrpSp->Control = 0; }
  16774. //++
  16775. //
  16776. // VOID
  16777. // IoSkipCurrentIrpStackLocation (
  16778. // IN PIRP Irp
  16779. // )
  16780. //
  16781. // Routine Description:
  16782. //
  16783. // This routine is invoked to increment the current stack location of
  16784. // a given IRP.
  16785. //
  16786. // If the caller wishes to call the next driver in a stack, and does not
  16787. // wish to change the arguments, nor does he wish to set a completion
  16788. // routine, then the caller first calls IoSkipCurrentIrpStackLocation
  16789. // and the calls IoCallDriver.
  16790. //
  16791. // Arguments:
  16792. //
  16793. // Irp - Pointer to the I/O Request Packet.
  16794. //
  16795. // Return Value:
  16796. //
  16797. // None
  16798. //
  16799. //--
  16800. #define IoSkipCurrentIrpStackLocation( Irp ) { \
  16801. (Irp)->CurrentLocation++; \
  16802. (Irp)->Tail.Overlay.CurrentStackLocation++; }
  16803. NTKERNELAPI
  16804. VOID
  16805. IoSetShareAccess(
  16806. IN ACCESS_MASK DesiredAccess,
  16807. IN ULONG DesiredShareAccess,
  16808. IN OUT PFILE_OBJECT FileObject,
  16809. OUT PSHARE_ACCESS ShareAccess
  16810. );
  16811. //++
  16812. //
  16813. // USHORT
  16814. // IoSizeOfIrp(
  16815. // IN CCHAR StackSize
  16816. // )
  16817. //
  16818. // Routine Description:
  16819. //
  16820. // Determines the size of an IRP given the number of stack locations
  16821. // the IRP will have.
  16822. //
  16823. // Arguments:
  16824. //
  16825. // StackSize - Number of stack locations for the IRP.
  16826. //
  16827. // Return Value:
  16828. //
  16829. // Size in bytes of the IRP.
  16830. //
  16831. //--
  16832. #define IoSizeOfIrp( StackSize ) \
  16833. ((USHORT) (sizeof( IRP ) + ((StackSize) * (sizeof( IO_STACK_LOCATION )))))
  16834. // end_ntifs
  16835. NTKERNELAPI
  16836. VOID
  16837. IoStartNextPacket(
  16838. IN PDEVICE_OBJECT DeviceObject,
  16839. IN BOOLEAN Cancelable
  16840. );
  16841. NTKERNELAPI
  16842. VOID
  16843. IoStartNextPacketByKey(
  16844. IN PDEVICE_OBJECT DeviceObject,
  16845. IN BOOLEAN Cancelable,
  16846. IN ULONG Key
  16847. );
  16848. NTKERNELAPI
  16849. VOID
  16850. IoStartPacket(
  16851. IN PDEVICE_OBJECT DeviceObject,
  16852. IN PIRP Irp,
  16853. IN PULONG Key OPTIONAL,
  16854. IN PDRIVER_CANCEL CancelFunction OPTIONAL
  16855. );
  16856. VOID
  16857. IoSetStartIoAttributes(
  16858. IN PDEVICE_OBJECT DeviceObject,
  16859. IN BOOLEAN DeferredStartIo,
  16860. IN BOOLEAN NonCancelable
  16861. );
  16862. // begin_ntifs
  16863. NTKERNELAPI
  16864. VOID
  16865. IoStartTimer(
  16866. IN PDEVICE_OBJECT DeviceObject
  16867. );
  16868. NTKERNELAPI
  16869. VOID
  16870. IoStopTimer(
  16871. IN PDEVICE_OBJECT DeviceObject
  16872. );
  16873. NTKERNELAPI
  16874. VOID
  16875. IoUnregisterShutdownNotification(
  16876. IN PDEVICE_OBJECT DeviceObject
  16877. );
  16878. // end_wdm
  16879. NTKERNELAPI
  16880. VOID
  16881. IoUpdateShareAccess(
  16882. IN PFILE_OBJECT FileObject,
  16883. IN OUT PSHARE_ACCESS ShareAccess
  16884. );
  16885. NTKERNELAPI
  16886. VOID
  16887. IoWriteErrorLogEntry(
  16888. IN PVOID ElEntry
  16889. );
  16890. NTKERNELAPI
  16891. NTSTATUS
  16892. IoCreateDriver (
  16893. IN PUNICODE_STRING DriverName, OPTIONAL
  16894. IN PDRIVER_INITIALIZE InitializationFunction
  16895. );
  16896. NTKERNELAPI
  16897. VOID
  16898. IoDeleteDriver (
  16899. IN PDRIVER_OBJECT DriverObject
  16900. );
  16901. //
  16902. // Define PnP Device Property for IoGetDeviceProperty
  16903. //
  16904. typedef enum {
  16905. DevicePropertyDeviceDescription,
  16906. DevicePropertyHardwareID,
  16907. DevicePropertyCompatibleIDs,
  16908. DevicePropertyBootConfiguration,
  16909. DevicePropertyBootConfigurationTranslated,
  16910. DevicePropertyClassName,
  16911. DevicePropertyClassGuid,
  16912. DevicePropertyDriverKeyName,
  16913. DevicePropertyManufacturer,
  16914. DevicePropertyFriendlyName,
  16915. DevicePropertyLocationInformation,
  16916. DevicePropertyPhysicalDeviceObjectName,
  16917. DevicePropertyBusTypeGuid,
  16918. DevicePropertyLegacyBusType,
  16919. DevicePropertyBusNumber,
  16920. DevicePropertyEnumeratorName,
  16921. DevicePropertyAddress,
  16922. DevicePropertyUINumber,
  16923. DevicePropertyInstallState,
  16924. DevicePropertyRemovalPolicy
  16925. } DEVICE_REGISTRY_PROPERTY;
  16926. typedef BOOLEAN (*PTRANSLATE_BUS_ADDRESS)(
  16927. IN PVOID Context,
  16928. IN PHYSICAL_ADDRESS BusAddress,
  16929. IN ULONG Length,
  16930. IN OUT PULONG AddressSpace,
  16931. OUT PPHYSICAL_ADDRESS TranslatedAddress
  16932. );
  16933. typedef struct _DMA_ADAPTER *(*PGET_DMA_ADAPTER)(
  16934. IN PVOID Context,
  16935. IN struct _DEVICE_DESCRIPTION *DeviceDescriptor,
  16936. OUT PULONG NumberOfMapRegisters
  16937. );
  16938. typedef ULONG (*PGET_SET_DEVICE_DATA)(
  16939. IN PVOID Context,
  16940. IN ULONG DataType,
  16941. IN PVOID Buffer,
  16942. IN ULONG Offset,
  16943. IN ULONG Length
  16944. );
  16945. typedef enum _DEVICE_INSTALL_STATE {
  16946. InstallStateInstalled,
  16947. InstallStateNeedsReinstall,
  16948. InstallStateFailedInstall,
  16949. InstallStateFinishInstall
  16950. } DEVICE_INSTALL_STATE, *PDEVICE_INSTALL_STATE;
  16951. //
  16952. // Define structure returned in response to IRP_MN_QUERY_BUS_INFORMATION by a
  16953. // PDO indicating the type of bus the device exists on.
  16954. //
  16955. typedef struct _PNP_BUS_INFORMATION {
  16956. GUID BusTypeGuid;
  16957. INTERFACE_TYPE LegacyBusType;
  16958. ULONG BusNumber;
  16959. } PNP_BUS_INFORMATION, *PPNP_BUS_INFORMATION;
  16960. //
  16961. // Define structure returned in response to IRP_MN_QUERY_LEGACY_BUS_INFORMATION
  16962. // by an FDO indicating the type of bus it is. This is normally the same bus
  16963. // type as the device's children (i.e., as retrieved from the child PDO's via
  16964. // IRP_MN_QUERY_BUS_INFORMATION) except for cases like CardBus, which can
  16965. // support both 16-bit (PCMCIABus) and 32-bit (PCIBus) cards.
  16966. //
  16967. typedef struct _LEGACY_BUS_INFORMATION {
  16968. GUID BusTypeGuid;
  16969. INTERFACE_TYPE LegacyBusType;
  16970. ULONG BusNumber;
  16971. } LEGACY_BUS_INFORMATION, *PLEGACY_BUS_INFORMATION;
  16972. //
  16973. // Defines for IoGetDeviceProperty(DevicePropertyRemovalPolicy).
  16974. //
  16975. typedef enum _DEVICE_REMOVAL_POLICY {
  16976. RemovalPolicyExpectNoRemoval = 1,
  16977. RemovalPolicyExpectOrderlyRemoval = 2,
  16978. RemovalPolicyExpectSurpriseRemoval = 3
  16979. } DEVICE_REMOVAL_POLICY, *PDEVICE_REMOVAL_POLICY;
  16980. typedef struct _BUS_INTERFACE_STANDARD {
  16981. //
  16982. // generic interface header
  16983. //
  16984. USHORT Size;
  16985. USHORT Version;
  16986. PVOID Context;
  16987. PINTERFACE_REFERENCE InterfaceReference;
  16988. PINTERFACE_DEREFERENCE InterfaceDereference;
  16989. //
  16990. // standard bus interfaces
  16991. //
  16992. PTRANSLATE_BUS_ADDRESS TranslateBusAddress;
  16993. PGET_DMA_ADAPTER GetDmaAdapter;
  16994. PGET_SET_DEVICE_DATA SetBusData;
  16995. PGET_SET_DEVICE_DATA GetBusData;
  16996. } BUS_INTERFACE_STANDARD, *PBUS_INTERFACE_STANDARD;
  16997. // end_wdm
  16998. typedef struct _AGP_TARGET_BUS_INTERFACE_STANDARD {
  16999. //
  17000. // generic interface header
  17001. //
  17002. USHORT Size;
  17003. USHORT Version;
  17004. PVOID Context;
  17005. PINTERFACE_REFERENCE InterfaceReference;
  17006. PINTERFACE_DEREFERENCE InterfaceDereference;
  17007. //
  17008. // config munging routines
  17009. //
  17010. PGET_SET_DEVICE_DATA SetBusData;
  17011. PGET_SET_DEVICE_DATA GetBusData;
  17012. UCHAR CapabilityID; // 2 (AGPv2 host) or new 0xE (AGPv3 bridge)
  17013. } AGP_TARGET_BUS_INTERFACE_STANDARD, *PAGP_TARGET_BUS_INTERFACE_STANDARD;
  17014. // begin_wdm
  17015. //
  17016. // The following definitions are used in ACPI QueryInterface
  17017. //
  17018. typedef BOOLEAN (* PGPE_SERVICE_ROUTINE) (
  17019. PVOID,
  17020. PVOID);
  17021. typedef NTSTATUS (* PGPE_CONNECT_VECTOR) (
  17022. PDEVICE_OBJECT,
  17023. ULONG,
  17024. KINTERRUPT_MODE,
  17025. BOOLEAN,
  17026. PGPE_SERVICE_ROUTINE,
  17027. PVOID,
  17028. PVOID);
  17029. typedef NTSTATUS (* PGPE_DISCONNECT_VECTOR) (
  17030. PVOID);
  17031. typedef NTSTATUS (* PGPE_ENABLE_EVENT) (
  17032. PDEVICE_OBJECT,
  17033. PVOID);
  17034. typedef NTSTATUS (* PGPE_DISABLE_EVENT) (
  17035. PDEVICE_OBJECT,
  17036. PVOID);
  17037. typedef NTSTATUS (* PGPE_CLEAR_STATUS) (
  17038. PDEVICE_OBJECT,
  17039. PVOID);
  17040. typedef VOID (* PDEVICE_NOTIFY_CALLBACK) (
  17041. PVOID,
  17042. ULONG);
  17043. typedef NTSTATUS (* PREGISTER_FOR_DEVICE_NOTIFICATIONS) (
  17044. PDEVICE_OBJECT,
  17045. PDEVICE_NOTIFY_CALLBACK,
  17046. PVOID);
  17047. typedef void (* PUNREGISTER_FOR_DEVICE_NOTIFICATIONS) (
  17048. PDEVICE_OBJECT,
  17049. PDEVICE_NOTIFY_CALLBACK);
  17050. typedef struct _ACPI_INTERFACE_STANDARD {
  17051. //
  17052. // Generic interface header
  17053. //
  17054. USHORT Size;
  17055. USHORT Version;
  17056. PVOID Context;
  17057. PINTERFACE_REFERENCE InterfaceReference;
  17058. PINTERFACE_DEREFERENCE InterfaceDereference;
  17059. //
  17060. // ACPI interfaces
  17061. //
  17062. PGPE_CONNECT_VECTOR GpeConnectVector;
  17063. PGPE_DISCONNECT_VECTOR GpeDisconnectVector;
  17064. PGPE_ENABLE_EVENT GpeEnableEvent;
  17065. PGPE_DISABLE_EVENT GpeDisableEvent;
  17066. PGPE_CLEAR_STATUS GpeClearStatus;
  17067. PREGISTER_FOR_DEVICE_NOTIFICATIONS RegisterForDeviceNotifications;
  17068. PUNREGISTER_FOR_DEVICE_NOTIFICATIONS UnregisterForDeviceNotifications;
  17069. } ACPI_INTERFACE_STANDARD, *PACPI_INTERFACE_STANDARD;
  17070. // end_wdm end_ntddk
  17071. typedef enum _ACPI_REG_TYPE {
  17072. PM1a_ENABLE,
  17073. PM1b_ENABLE,
  17074. PM1a_STATUS,
  17075. PM1b_STATUS,
  17076. PM1a_CONTROL,
  17077. PM1b_CONTROL,
  17078. GP_STATUS,
  17079. GP_ENABLE,
  17080. SMI_CMD,
  17081. MaxRegType
  17082. } ACPI_REG_TYPE, *PACPI_REG_TYPE;
  17083. typedef USHORT (*PREAD_ACPI_REGISTER) (
  17084. IN ACPI_REG_TYPE AcpiReg,
  17085. IN ULONG Register);
  17086. typedef VOID (*PWRITE_ACPI_REGISTER) (
  17087. IN ACPI_REG_TYPE AcpiReg,
  17088. IN ULONG Register,
  17089. IN USHORT Value
  17090. );
  17091. typedef struct ACPI_REGS_INTERFACE_STANDARD {
  17092. //
  17093. // generic interface header
  17094. //
  17095. USHORT Size;
  17096. USHORT Version;
  17097. PVOID Context;
  17098. PINTERFACE_REFERENCE InterfaceReference;
  17099. PINTERFACE_DEREFERENCE InterfaceDereference;
  17100. //
  17101. // READ/WRITE_ACPI_REGISTER functions
  17102. //
  17103. PREAD_ACPI_REGISTER ReadAcpiRegister;
  17104. PWRITE_ACPI_REGISTER WriteAcpiRegister;
  17105. } ACPI_REGS_INTERFACE_STANDARD, *PACPI_REGS_INTERFACE_STANDARD;
  17106. typedef NTSTATUS (*PHAL_QUERY_ALLOCATE_PORT_RANGE) (
  17107. IN BOOLEAN IsSparse,
  17108. IN BOOLEAN PrimaryIsMmio,
  17109. IN PVOID VirtBaseAddr OPTIONAL,
  17110. IN PHYSICAL_ADDRESS PhysBaseAddr, // Only valid if PrimaryIsMmio = TRUE
  17111. IN ULONG Length, // Only valid if PrimaryIsMmio = TRUE
  17112. OUT PUSHORT NewRangeId
  17113. );
  17114. typedef VOID (*PHAL_FREE_PORT_RANGE)(
  17115. IN USHORT RangeId
  17116. );
  17117. typedef struct _HAL_PORT_RANGE_INTERFACE {
  17118. //
  17119. // generic interface header
  17120. //
  17121. USHORT Size;
  17122. USHORT Version;
  17123. PVOID Context;
  17124. PINTERFACE_REFERENCE InterfaceReference;
  17125. PINTERFACE_DEREFERENCE InterfaceDereference;
  17126. //
  17127. // QueryAllocateRange/FreeRange functions
  17128. //
  17129. PHAL_QUERY_ALLOCATE_PORT_RANGE QueryAllocateRange;
  17130. PHAL_FREE_PORT_RANGE FreeRange;
  17131. } HAL_PORT_RANGE_INTERFACE, *PHAL_PORT_RANGE_INTERFACE;
  17132. //
  17133. // describe the CMOS HAL interface
  17134. //
  17135. typedef enum _CMOS_DEVICE_TYPE {
  17136. CmosTypeStdPCAT,
  17137. CmosTypeIntelPIIX4,
  17138. CmosTypeDal1501
  17139. } CMOS_DEVICE_TYPE;
  17140. typedef
  17141. ULONG
  17142. (*PREAD_ACPI_CMOS) (
  17143. IN CMOS_DEVICE_TYPE CmosType,
  17144. IN ULONG SourceAddress,
  17145. IN PUCHAR DataBuffer,
  17146. IN ULONG ByteCount
  17147. );
  17148. typedef
  17149. ULONG
  17150. (*PWRITE_ACPI_CMOS) (
  17151. IN CMOS_DEVICE_TYPE CmosType,
  17152. IN ULONG SourceAddress,
  17153. IN PUCHAR DataBuffer,
  17154. IN ULONG ByteCount
  17155. );
  17156. typedef struct _ACPI_CMOS_INTERFACE_STANDARD {
  17157. //
  17158. // generic interface header
  17159. //
  17160. USHORT Size;
  17161. USHORT Version;
  17162. PVOID Context;
  17163. PINTERFACE_REFERENCE InterfaceReference;
  17164. PINTERFACE_DEREFERENCE InterfaceDereference;
  17165. //
  17166. // READ/WRITE_ACPI_CMOS functions
  17167. //
  17168. PREAD_ACPI_CMOS ReadCmos;
  17169. PWRITE_ACPI_CMOS WriteCmos;
  17170. } ACPI_CMOS_INTERFACE_STANDARD, *PACPI_CMOS_INTERFACE_STANDARD;
  17171. //
  17172. // These definitions are used for getting PCI Interrupt Routing interfaces
  17173. //
  17174. typedef struct {
  17175. PVOID LinkNode;
  17176. ULONG StaticVector;
  17177. UCHAR Flags;
  17178. } ROUTING_TOKEN, *PROUTING_TOKEN;
  17179. //
  17180. // Flag indicating that the device supports
  17181. // MSI interrupt routing or that the provided token contains
  17182. // MSI routing information
  17183. //
  17184. #define PCI_MSI_ROUTING 0x1
  17185. #define PCI_STATIC_ROUTING 0x2
  17186. typedef
  17187. NTSTATUS
  17188. (*PGET_INTERRUPT_ROUTING)(
  17189. IN PDEVICE_OBJECT Pdo,
  17190. OUT ULONG *Bus,
  17191. OUT ULONG *PciSlot,
  17192. OUT UCHAR *InterruptLine,
  17193. OUT UCHAR *InterruptPin,
  17194. OUT UCHAR *ClassCode,
  17195. OUT UCHAR *SubClassCode,
  17196. OUT PDEVICE_OBJECT *ParentPdo,
  17197. OUT ROUTING_TOKEN *RoutingToken,
  17198. OUT UCHAR *Flags
  17199. );
  17200. typedef
  17201. NTSTATUS
  17202. (*PSET_INTERRUPT_ROUTING_TOKEN)(
  17203. IN PDEVICE_OBJECT Pdo,
  17204. IN PROUTING_TOKEN RoutingToken
  17205. );
  17206. typedef
  17207. VOID
  17208. (*PUPDATE_INTERRUPT_LINE)(
  17209. IN PDEVICE_OBJECT Pdo,
  17210. IN UCHAR LineRegister
  17211. );
  17212. typedef struct _INT_ROUTE_INTERFACE_STANDARD {
  17213. //
  17214. // generic interface header
  17215. //
  17216. USHORT Size;
  17217. USHORT Version;
  17218. PVOID Context;
  17219. PINTERFACE_REFERENCE InterfaceReference;
  17220. PINTERFACE_DEREFERENCE InterfaceDereference;
  17221. //
  17222. // standard bus interfaces
  17223. //
  17224. PGET_INTERRUPT_ROUTING GetInterruptRouting;
  17225. PSET_INTERRUPT_ROUTING_TOKEN SetInterruptRoutingToken;
  17226. PUPDATE_INTERRUPT_LINE UpdateInterruptLine;
  17227. } INT_ROUTE_INTERFACE_STANDARD, *PINT_ROUTE_INTERFACE_STANDARD;
  17228. // Some well-known interface versions supported by the PCI Bus Driver
  17229. #define PCI_INT_ROUTE_INTRF_STANDARD_VER 1
  17230. NTKERNELAPI
  17231. NTSTATUS
  17232. IoReportDetectedDevice(
  17233. IN PDRIVER_OBJECT DriverObject,
  17234. IN INTERFACE_TYPE LegacyBusType,
  17235. IN ULONG BusNumber,
  17236. IN ULONG SlotNumber,
  17237. IN PCM_RESOURCE_LIST ResourceList,
  17238. IN PIO_RESOURCE_REQUIREMENTS_LIST ResourceRequirements OPTIONAL,
  17239. IN BOOLEAN ResourceAssigned,
  17240. IN OUT PDEVICE_OBJECT *DeviceObject
  17241. );
  17242. // begin_wdm
  17243. NTKERNELAPI
  17244. VOID
  17245. IoInvalidateDeviceRelations(
  17246. IN PDEVICE_OBJECT DeviceObject,
  17247. IN DEVICE_RELATION_TYPE Type
  17248. );
  17249. NTKERNELAPI
  17250. VOID
  17251. IoRequestDeviceEject(
  17252. IN PDEVICE_OBJECT PhysicalDeviceObject
  17253. );
  17254. NTKERNELAPI
  17255. NTSTATUS
  17256. IoGetDeviceProperty(
  17257. IN PDEVICE_OBJECT DeviceObject,
  17258. IN DEVICE_REGISTRY_PROPERTY DeviceProperty,
  17259. IN ULONG BufferLength,
  17260. OUT PVOID PropertyBuffer,
  17261. OUT PULONG ResultLength
  17262. );
  17263. //
  17264. // The following definitions are used in IoOpenDeviceRegistryKey
  17265. //
  17266. #define PLUGPLAY_REGKEY_DEVICE 1
  17267. #define PLUGPLAY_REGKEY_DRIVER 2
  17268. #define PLUGPLAY_REGKEY_CURRENT_HWPROFILE 4
  17269. NTKERNELAPI
  17270. NTSTATUS
  17271. IoOpenDeviceRegistryKey(
  17272. IN PDEVICE_OBJECT DeviceObject,
  17273. IN ULONG DevInstKeyType,
  17274. IN ACCESS_MASK DesiredAccess,
  17275. OUT PHANDLE DevInstRegKey
  17276. );
  17277. NTKERNELAPI
  17278. NTSTATUS
  17279. NTAPI
  17280. IoRegisterDeviceInterface(
  17281. IN PDEVICE_OBJECT PhysicalDeviceObject,
  17282. IN CONST GUID *InterfaceClassGuid,
  17283. IN PUNICODE_STRING ReferenceString, OPTIONAL
  17284. OUT PUNICODE_STRING SymbolicLinkName
  17285. );
  17286. NTKERNELAPI
  17287. NTSTATUS
  17288. IoOpenDeviceInterfaceRegistryKey(
  17289. IN PUNICODE_STRING SymbolicLinkName,
  17290. IN ACCESS_MASK DesiredAccess,
  17291. OUT PHANDLE DeviceInterfaceKey
  17292. );
  17293. NTKERNELAPI
  17294. NTSTATUS
  17295. IoSetDeviceInterfaceState(
  17296. IN PUNICODE_STRING SymbolicLinkName,
  17297. IN BOOLEAN Enable
  17298. );
  17299. NTKERNELAPI
  17300. NTSTATUS
  17301. NTAPI
  17302. IoGetDeviceInterfaces(
  17303. IN CONST GUID *InterfaceClassGuid,
  17304. IN PDEVICE_OBJECT PhysicalDeviceObject OPTIONAL,
  17305. IN ULONG Flags,
  17306. OUT PWSTR *SymbolicLinkList
  17307. );
  17308. #define DEVICE_INTERFACE_INCLUDE_NONACTIVE 0x00000001
  17309. NTKERNELAPI
  17310. NTSTATUS
  17311. NTAPI
  17312. IoGetDeviceInterfaceAlias(
  17313. IN PUNICODE_STRING SymbolicLinkName,
  17314. IN CONST GUID *AliasInterfaceClassGuid,
  17315. OUT PUNICODE_STRING AliasSymbolicLinkName
  17316. );
  17317. //
  17318. // Define PnP notification event categories
  17319. //
  17320. typedef enum _IO_NOTIFICATION_EVENT_CATEGORY {
  17321. EventCategoryReserved,
  17322. EventCategoryHardwareProfileChange,
  17323. EventCategoryDeviceInterfaceChange,
  17324. EventCategoryTargetDeviceChange
  17325. } IO_NOTIFICATION_EVENT_CATEGORY;
  17326. //
  17327. // Define flags that modify the behavior of IoRegisterPlugPlayNotification
  17328. // for the various event categories...
  17329. //
  17330. #define PNPNOTIFY_DEVICE_INTERFACE_INCLUDE_EXISTING_INTERFACES 0x00000001
  17331. typedef
  17332. NTSTATUS
  17333. (*PDRIVER_NOTIFICATION_CALLBACK_ROUTINE) (
  17334. IN PVOID NotificationStructure,
  17335. IN PVOID Context
  17336. );
  17337. NTKERNELAPI
  17338. NTSTATUS
  17339. IoRegisterPlugPlayNotification(
  17340. IN IO_NOTIFICATION_EVENT_CATEGORY EventCategory,
  17341. IN ULONG EventCategoryFlags,
  17342. IN PVOID EventCategoryData OPTIONAL,
  17343. IN PDRIVER_OBJECT DriverObject,
  17344. IN PDRIVER_NOTIFICATION_CALLBACK_ROUTINE CallbackRoutine,
  17345. IN PVOID Context,
  17346. OUT PVOID *NotificationEntry
  17347. );
  17348. NTKERNELAPI
  17349. NTSTATUS
  17350. IoUnregisterPlugPlayNotification(
  17351. IN PVOID NotificationEntry
  17352. );
  17353. NTKERNELAPI
  17354. NTSTATUS
  17355. IoReportTargetDeviceChange(
  17356. IN PDEVICE_OBJECT PhysicalDeviceObject,
  17357. IN PVOID NotificationStructure // always begins with a PLUGPLAY_NOTIFICATION_HEADER
  17358. );
  17359. typedef
  17360. VOID
  17361. (*PDEVICE_CHANGE_COMPLETE_CALLBACK)(
  17362. IN PVOID Context
  17363. );
  17364. NTKERNELAPI
  17365. VOID
  17366. IoInvalidateDeviceState(
  17367. IN PDEVICE_OBJECT PhysicalDeviceObject
  17368. );
  17369. #define IoAdjustPagingPathCount(_count_,_paging_) { \
  17370. if (_paging_) { \
  17371. InterlockedIncrement(_count_); \
  17372. } else { \
  17373. InterlockedDecrement(_count_); \
  17374. } \
  17375. }
  17376. NTKERNELAPI
  17377. NTSTATUS
  17378. IoReportTargetDeviceChangeAsynchronous(
  17379. IN PDEVICE_OBJECT PhysicalDeviceObject,
  17380. IN PVOID NotificationStructure, // always begins with a PLUGPLAY_NOTIFICATION_HEADER
  17381. IN PDEVICE_CHANGE_COMPLETE_CALLBACK Callback, OPTIONAL
  17382. IN PVOID Context OPTIONAL
  17383. );
  17384. // end_wdm end_ntosp
  17385. //
  17386. // Device location interface declarations
  17387. //
  17388. typedef
  17389. NTSTATUS
  17390. (*PGET_LOCATION_STRING) (
  17391. IN PVOID Context,
  17392. OUT PWCHAR *LocationStrings
  17393. );
  17394. typedef struct _PNP_LOCATION_INTERFACE {
  17395. //
  17396. // generic interface header
  17397. //
  17398. USHORT Size;
  17399. USHORT Version;
  17400. PVOID Context;
  17401. PINTERFACE_REFERENCE InterfaceReference;
  17402. PINTERFACE_DEREFERENCE InterfaceDereference;
  17403. //
  17404. // interface specific entry
  17405. //
  17406. PGET_LOCATION_STRING GetLocationString;
  17407. } PNP_LOCATION_INTERFACE, *PPNP_LOCATION_INTERFACE;
  17408. //
  17409. // Resource arbiter declarations
  17410. //
  17411. typedef enum _ARBITER_ACTION {
  17412. ArbiterActionTestAllocation,
  17413. ArbiterActionRetestAllocation,
  17414. ArbiterActionCommitAllocation,
  17415. ArbiterActionRollbackAllocation,
  17416. ArbiterActionQueryAllocatedResources,
  17417. ArbiterActionWriteReservedResources,
  17418. ArbiterActionQueryConflict,
  17419. ArbiterActionQueryArbitrate,
  17420. ArbiterActionAddReserved,
  17421. ArbiterActionBootAllocation
  17422. } ARBITER_ACTION, *PARBITER_ACTION;
  17423. typedef struct _ARBITER_CONFLICT_INFO {
  17424. //
  17425. // The device object owning the device that is causing the conflict
  17426. //
  17427. PDEVICE_OBJECT OwningObject;
  17428. //
  17429. // The start of the conflicting range
  17430. //
  17431. ULONGLONG Start;
  17432. //
  17433. // The end of the conflicting range
  17434. //
  17435. ULONGLONG End;
  17436. } ARBITER_CONFLICT_INFO, *PARBITER_CONFLICT_INFO;
  17437. //
  17438. // The parameters for those actions
  17439. //
  17440. typedef struct _ARBITER_PARAMETERS {
  17441. union {
  17442. struct {
  17443. //
  17444. // Doubly linked list of ARBITER_LIST_ENTRY's
  17445. //
  17446. IN OUT PLIST_ENTRY ArbitrationList;
  17447. //
  17448. // The size of the AllocateFrom array
  17449. //
  17450. IN ULONG AllocateFromCount;
  17451. //
  17452. // Array of resource descriptors describing the resources available
  17453. // to the arbiter for it to arbitrate
  17454. //
  17455. IN PCM_PARTIAL_RESOURCE_DESCRIPTOR AllocateFrom;
  17456. } TestAllocation;
  17457. struct {
  17458. //
  17459. // Doubly linked list of ARBITER_LIST_ENTRY's
  17460. //
  17461. IN OUT PLIST_ENTRY ArbitrationList;
  17462. //
  17463. // The size of the AllocateFrom array
  17464. //
  17465. IN ULONG AllocateFromCount;
  17466. //
  17467. // Array of resource descriptors describing the resources available
  17468. // to the arbiter for it to arbitrate
  17469. //
  17470. IN PCM_PARTIAL_RESOURCE_DESCRIPTOR AllocateFrom;
  17471. } RetestAllocation;
  17472. struct {
  17473. //
  17474. // Doubly linked list of ARBITER_LIST_ENTRY's
  17475. //
  17476. IN OUT PLIST_ENTRY ArbitrationList;
  17477. } BootAllocation;
  17478. struct {
  17479. //
  17480. // The resources that are currently allocated
  17481. //
  17482. OUT PCM_PARTIAL_RESOURCE_LIST *AllocatedResources;
  17483. } QueryAllocatedResources;
  17484. struct {
  17485. //
  17486. // This is the device we are trying to find a conflict for
  17487. //
  17488. IN PDEVICE_OBJECT PhysicalDeviceObject;
  17489. //
  17490. // This is the resource to find the conflict for
  17491. //
  17492. IN PIO_RESOURCE_DESCRIPTOR ConflictingResource;
  17493. //
  17494. // Number of devices conflicting on the resource
  17495. //
  17496. OUT PULONG ConflictCount;
  17497. //
  17498. // Pointer to array describing the conflicting device objects and ranges
  17499. //
  17500. OUT PARBITER_CONFLICT_INFO *Conflicts;
  17501. } QueryConflict;
  17502. struct {
  17503. //
  17504. // Doubly linked list of ARBITER_LIST_ENTRY's - should have
  17505. // only one entry
  17506. //
  17507. IN PLIST_ENTRY ArbitrationList;
  17508. } QueryArbitrate;
  17509. struct {
  17510. //
  17511. // Indicates the device whose resources are to be marked as reserved
  17512. //
  17513. PDEVICE_OBJECT ReserveDevice;
  17514. } AddReserved;
  17515. } Parameters;
  17516. } ARBITER_PARAMETERS, *PARBITER_PARAMETERS;
  17517. typedef enum _ARBITER_REQUEST_SOURCE {
  17518. ArbiterRequestUndefined = -1,
  17519. ArbiterRequestLegacyReported, // IoReportResourceUsage
  17520. ArbiterRequestHalReported, // IoReportHalResourceUsage
  17521. ArbiterRequestLegacyAssigned, // IoAssignResources
  17522. ArbiterRequestPnpDetected, // IoReportResourceForDetection
  17523. ArbiterRequestPnpEnumerated // IRP_MN_QUERY_RESOURCE_REQUIREMENTS
  17524. } ARBITER_REQUEST_SOURCE;
  17525. typedef enum _ARBITER_RESULT {
  17526. ArbiterResultUndefined = -1,
  17527. ArbiterResultSuccess,
  17528. ArbiterResultExternalConflict, // This indicates that the request can never be solved for devices in this list
  17529. ArbiterResultNullRequest // The request was for length zero and thus no translation should be attempted
  17530. } ARBITER_RESULT;
  17531. //
  17532. // ARBITER_FLAG_BOOT_CONFIG - this indicates that the request is for the
  17533. // resources assigned by the firmware/BIOS. It should be succeeded even if
  17534. // it conflicts with another devices boot config.
  17535. //
  17536. #define ARBITER_FLAG_BOOT_CONFIG 0x00000001
  17537. // begin_ntosp
  17538. NTKERNELAPI
  17539. NTSTATUS
  17540. IoReportResourceForDetection(
  17541. IN PDRIVER_OBJECT DriverObject,
  17542. IN PCM_RESOURCE_LIST DriverList OPTIONAL,
  17543. IN ULONG DriverListSize OPTIONAL,
  17544. IN PDEVICE_OBJECT DeviceObject OPTIONAL,
  17545. IN PCM_RESOURCE_LIST DeviceList OPTIONAL,
  17546. IN ULONG DeviceListSize OPTIONAL,
  17547. OUT PBOOLEAN ConflictDetected
  17548. );
  17549. // end_ntosp
  17550. typedef struct _ARBITER_LIST_ENTRY {
  17551. //
  17552. // This is a doubly linked list of entries for easy sorting
  17553. //
  17554. LIST_ENTRY ListEntry;
  17555. //
  17556. // The number of alternative allocation
  17557. //
  17558. ULONG AlternativeCount;
  17559. //
  17560. // Pointer to an array of resource descriptors for the possible allocations
  17561. //
  17562. PIO_RESOURCE_DESCRIPTOR Alternatives;
  17563. //
  17564. // The device object of the device requesting these resources.
  17565. //
  17566. PDEVICE_OBJECT PhysicalDeviceObject;
  17567. //
  17568. // Indicates where the request came from
  17569. //
  17570. ARBITER_REQUEST_SOURCE RequestSource;
  17571. //
  17572. // Flags these indicate a variety of things (use ARBITER_FLAG_*)
  17573. //
  17574. ULONG Flags;
  17575. //
  17576. // Space to aid the arbiter in processing the list it is initialized to 0 when
  17577. // the entry is created. The system will not attempt to interpret it.
  17578. //
  17579. LONG_PTR WorkSpace;
  17580. //
  17581. // Interface Type, Slot Number and Bus Number from Resource Requirements list,
  17582. // used only for reverse identification.
  17583. //
  17584. INTERFACE_TYPE InterfaceType;
  17585. ULONG SlotNumber;
  17586. ULONG BusNumber;
  17587. //
  17588. // A pointer to a descriptor to indicate the resource that was allocated.
  17589. // This is allocated by the system and filled in by the arbiter in response to an
  17590. // ArbiterActionTestAllocation.
  17591. //
  17592. PCM_PARTIAL_RESOURCE_DESCRIPTOR Assignment;
  17593. //
  17594. // Pointer to the alternative that was chosen from to provide the assignment.
  17595. // This is filled in by the arbiter in response to an ArbiterActionTestAllocation.
  17596. //
  17597. PIO_RESOURCE_DESCRIPTOR SelectedAlternative;
  17598. //
  17599. // The result of the operation
  17600. // This is filled in by the arbiter in response to an ArbiterActionTestAllocation.
  17601. //
  17602. ARBITER_RESULT Result;
  17603. } ARBITER_LIST_ENTRY, *PARBITER_LIST_ENTRY;
  17604. //
  17605. // The arbiter's entry point
  17606. //
  17607. typedef
  17608. NTSTATUS
  17609. (*PARBITER_HANDLER) (
  17610. IN PVOID Context,
  17611. IN ARBITER_ACTION Action,
  17612. IN OUT PARBITER_PARAMETERS Parameters
  17613. );
  17614. //
  17615. // Arbiter interface
  17616. //
  17617. #define ARBITER_PARTIAL 0x00000001
  17618. typedef struct _ARBITER_INTERFACE {
  17619. //
  17620. // Generic interface header
  17621. //
  17622. USHORT Size;
  17623. USHORT Version;
  17624. PVOID Context;
  17625. PINTERFACE_REFERENCE InterfaceReference;
  17626. PINTERFACE_DEREFERENCE InterfaceDereference;
  17627. //
  17628. // Entry point to the arbiter
  17629. //
  17630. PARBITER_HANDLER ArbiterHandler;
  17631. //
  17632. // Other information about the arbiter, use ARBITER_* flags
  17633. //
  17634. ULONG Flags;
  17635. } ARBITER_INTERFACE, *PARBITER_INTERFACE;
  17636. //
  17637. // The directions translation can take place in
  17638. //
  17639. typedef enum _RESOURCE_TRANSLATION_DIRECTION { // ntosp
  17640. TranslateChildToParent, // ntosp
  17641. TranslateParentToChild // ntosp
  17642. } RESOURCE_TRANSLATION_DIRECTION; // ntosp
  17643. //
  17644. // Translation functions
  17645. //
  17646. // begin_ntosp
  17647. typedef
  17648. NTSTATUS
  17649. (*PTRANSLATE_RESOURCE_HANDLER)(
  17650. IN PVOID Context,
  17651. IN PCM_PARTIAL_RESOURCE_DESCRIPTOR Source,
  17652. IN RESOURCE_TRANSLATION_DIRECTION Direction,
  17653. IN ULONG AlternativesCount, OPTIONAL
  17654. IN IO_RESOURCE_DESCRIPTOR Alternatives[], OPTIONAL
  17655. IN PDEVICE_OBJECT PhysicalDeviceObject,
  17656. OUT PCM_PARTIAL_RESOURCE_DESCRIPTOR Target
  17657. );
  17658. typedef
  17659. NTSTATUS
  17660. (*PTRANSLATE_RESOURCE_REQUIREMENTS_HANDLER)(
  17661. IN PVOID Context,
  17662. IN PIO_RESOURCE_DESCRIPTOR Source,
  17663. IN PDEVICE_OBJECT PhysicalDeviceObject,
  17664. OUT PULONG TargetCount,
  17665. OUT PIO_RESOURCE_DESCRIPTOR *Target
  17666. );
  17667. //
  17668. // Translator Interface
  17669. //
  17670. typedef struct _TRANSLATOR_INTERFACE {
  17671. USHORT Size;
  17672. USHORT Version;
  17673. PVOID Context;
  17674. PINTERFACE_REFERENCE InterfaceReference;
  17675. PINTERFACE_DEREFERENCE InterfaceDereference;
  17676. PTRANSLATE_RESOURCE_HANDLER TranslateResources;
  17677. PTRANSLATE_RESOURCE_REQUIREMENTS_HANDLER TranslateResourceRequirements;
  17678. } TRANSLATOR_INTERFACE, *PTRANSLATOR_INTERFACE;
  17679. // end_ntddk end_ntosp
  17680. //
  17681. // Legacy Device Detection Handler
  17682. //
  17683. typedef
  17684. NTSTATUS
  17685. (*PLEGACY_DEVICE_DETECTION_HANDLER)(
  17686. IN PVOID Context,
  17687. IN INTERFACE_TYPE LegacyBusType,
  17688. IN ULONG BusNumber,
  17689. IN ULONG SlotNumber,
  17690. OUT PDEVICE_OBJECT *PhysicalDeviceObject
  17691. );
  17692. //
  17693. // Legacy Device Detection Interface
  17694. //
  17695. typedef struct _LEGACY_DEVICE_DETECTION_INTERFACE {
  17696. USHORT Size;
  17697. USHORT Version;
  17698. PVOID Context;
  17699. PINTERFACE_REFERENCE InterfaceReference;
  17700. PINTERFACE_DEREFERENCE InterfaceDereference;
  17701. PLEGACY_DEVICE_DETECTION_HANDLER LegacyDeviceDetection;
  17702. } LEGACY_DEVICE_DETECTION_INTERFACE, *PLEGACY_DEVICE_DETECTION_INTERFACE;
  17703. //
  17704. // Header structure for all Plug&Play notification events...
  17705. //
  17706. typedef struct _PLUGPLAY_NOTIFICATION_HEADER {
  17707. USHORT Version; // presently at version 1.
  17708. USHORT Size; // size (in bytes) of header + event-specific data.
  17709. GUID Event;
  17710. //
  17711. // Event-specific stuff starts here.
  17712. //
  17713. } PLUGPLAY_NOTIFICATION_HEADER, *PPLUGPLAY_NOTIFICATION_HEADER;
  17714. //
  17715. // Notification structure for all EventCategoryHardwareProfileChange events...
  17716. //
  17717. typedef struct _HWPROFILE_CHANGE_NOTIFICATION {
  17718. USHORT Version;
  17719. USHORT Size;
  17720. GUID Event;
  17721. //
  17722. // (No event-specific data)
  17723. //
  17724. } HWPROFILE_CHANGE_NOTIFICATION, *PHWPROFILE_CHANGE_NOTIFICATION;
  17725. //
  17726. // Notification structure for all EventCategoryDeviceInterfaceChange events...
  17727. //
  17728. typedef struct _DEVICE_INTERFACE_CHANGE_NOTIFICATION {
  17729. USHORT Version;
  17730. USHORT Size;
  17731. GUID Event;
  17732. //
  17733. // Event-specific data
  17734. //
  17735. GUID InterfaceClassGuid;
  17736. PUNICODE_STRING SymbolicLinkName;
  17737. } DEVICE_INTERFACE_CHANGE_NOTIFICATION, *PDEVICE_INTERFACE_CHANGE_NOTIFICATION;
  17738. //
  17739. // Notification structures for EventCategoryTargetDeviceChange...
  17740. //
  17741. //
  17742. // The following structure is used for TargetDeviceQueryRemove,
  17743. // TargetDeviceRemoveCancelled, and TargetDeviceRemoveComplete:
  17744. //
  17745. typedef struct _TARGET_DEVICE_REMOVAL_NOTIFICATION {
  17746. USHORT Version;
  17747. USHORT Size;
  17748. GUID Event;
  17749. //
  17750. // Event-specific data
  17751. //
  17752. PFILE_OBJECT FileObject;
  17753. } TARGET_DEVICE_REMOVAL_NOTIFICATION, *PTARGET_DEVICE_REMOVAL_NOTIFICATION;
  17754. //
  17755. // The following structure header is used for all other (i.e., 3rd-party)
  17756. // target device change events. The structure accommodates both a
  17757. // variable-length binary data buffer, and a variable-length unicode text
  17758. // buffer. The header must indicate where the text buffer begins, so that
  17759. // the data can be delivered in the appropriate format (ANSI or Unicode)
  17760. // to user-mode recipients (i.e., that have registered for handle-based
  17761. // notification via RegisterDeviceNotification).
  17762. //
  17763. typedef struct _TARGET_DEVICE_CUSTOM_NOTIFICATION {
  17764. USHORT Version;
  17765. USHORT Size;
  17766. GUID Event;
  17767. //
  17768. // Event-specific data
  17769. //
  17770. PFILE_OBJECT FileObject; // This field must be set to NULL by callers of
  17771. // IoReportTargetDeviceChange. Clients that
  17772. // have registered for target device change
  17773. // notification on the affected PDO will be
  17774. // called with this field set to the file object
  17775. // they specified during registration.
  17776. //
  17777. LONG NameBufferOffset; // offset (in bytes) from beginning of
  17778. // CustomDataBuffer where text begins (-1 if none)
  17779. //
  17780. UCHAR CustomDataBuffer[1]; // variable-length buffer, containing (optionally)
  17781. // a binary data at the start of the buffer,
  17782. // followed by an optional unicode text buffer
  17783. // (word-aligned).
  17784. //
  17785. } TARGET_DEVICE_CUSTOM_NOTIFICATION, *PTARGET_DEVICE_CUSTOM_NOTIFICATION;
  17786. NTKERNELAPI
  17787. VOID
  17788. PoSetHiberRange (
  17789. IN PVOID MemoryMap,
  17790. IN ULONG Flags,
  17791. IN PVOID Address,
  17792. IN ULONG_PTR Length,
  17793. IN ULONG Tag
  17794. );
  17795. // memory_range.Type
  17796. #define PO_MEM_PRESERVE 0x00000001 // memory range needs preserved
  17797. #define PO_MEM_CLONE 0x00000002 // Clone this range
  17798. #define PO_MEM_CL_OR_NCHK 0x00000004 // Either clone or do not checksum
  17799. #define PO_MEM_DISCARD 0x00008000 // This range to be removed
  17800. #define PO_MEM_PAGE_ADDRESS 0x00004000 // Arguments passed are physical pages
  17801. NTKERNELAPI
  17802. POWER_STATE
  17803. PoSetPowerState (
  17804. IN PDEVICE_OBJECT DeviceObject,
  17805. IN POWER_STATE_TYPE Type,
  17806. IN POWER_STATE State
  17807. );
  17808. NTKERNELAPI
  17809. NTSTATUS
  17810. PoCallDriver (
  17811. IN PDEVICE_OBJECT DeviceObject,
  17812. IN OUT PIRP Irp
  17813. );
  17814. NTKERNELAPI
  17815. VOID
  17816. PoStartNextPowerIrp(
  17817. IN PIRP Irp
  17818. );
  17819. NTKERNELAPI
  17820. PULONG
  17821. PoRegisterDeviceForIdleDetection (
  17822. IN PDEVICE_OBJECT DeviceObject,
  17823. IN ULONG ConservationIdleTime,
  17824. IN ULONG PerformanceIdleTime,
  17825. IN DEVICE_POWER_STATE State
  17826. );
  17827. #define PoSetDeviceBusy(IdlePointer) \
  17828. *IdlePointer = 0
  17829. //
  17830. // \Callback\PowerState values
  17831. //
  17832. #define PO_CB_SYSTEM_POWER_POLICY 0
  17833. #define PO_CB_AC_STATUS 1
  17834. #define PO_CB_BUTTON_COLLISION 2
  17835. #define PO_CB_SYSTEM_STATE_LOCK 3
  17836. #define PO_CB_LID_SWITCH_STATE 4
  17837. #define PO_CB_PROCESSOR_POWER_POLICY 5
  17838. //
  17839. // Indicates the system may do I/O to physical addresses above 4 GB.
  17840. //
  17841. extern PBOOLEAN Mm64BitPhysicalAddress;
  17842. //
  17843. // Define maximum disk transfer size to be used by MM and Cache Manager,
  17844. // so that packet-oriented disk drivers can optimize their packet allocation
  17845. // to this size.
  17846. //
  17847. #define MM_MAXIMUM_DISK_IO_SIZE (0x10000)
  17848. //++
  17849. //
  17850. // ULONG_PTR
  17851. // ROUND_TO_PAGES (
  17852. // IN ULONG_PTR Size
  17853. // )
  17854. //
  17855. // Routine Description:
  17856. //
  17857. // The ROUND_TO_PAGES macro takes a size in bytes and rounds it up to a
  17858. // multiple of the page size.
  17859. //
  17860. // NOTE: This macro fails for values 0xFFFFFFFF - (PAGE_SIZE - 1).
  17861. //
  17862. // Arguments:
  17863. //
  17864. // Size - Size in bytes to round up to a page multiple.
  17865. //
  17866. // Return Value:
  17867. //
  17868. // Returns the size rounded up to a multiple of the page size.
  17869. //
  17870. //--
  17871. #define ROUND_TO_PAGES(Size) (((ULONG_PTR)(Size) + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1))
  17872. //++
  17873. //
  17874. // ULONG
  17875. // BYTES_TO_PAGES (
  17876. // IN ULONG Size
  17877. // )
  17878. //
  17879. // Routine Description:
  17880. //
  17881. // The BYTES_TO_PAGES macro takes the size in bytes and calculates the
  17882. // number of pages required to contain the bytes.
  17883. //
  17884. // Arguments:
  17885. //
  17886. // Size - Size in bytes.
  17887. //
  17888. // Return Value:
  17889. //
  17890. // Returns the number of pages required to contain the specified size.
  17891. //
  17892. //--
  17893. #define BYTES_TO_PAGES(Size) (((Size) >> PAGE_SHIFT) + \
  17894. (((Size) & (PAGE_SIZE - 1)) != 0))
  17895. //++
  17896. //
  17897. // ULONG
  17898. // BYTE_OFFSET (
  17899. // IN PVOID Va
  17900. // )
  17901. //
  17902. // Routine Description:
  17903. //
  17904. // The BYTE_OFFSET macro takes a virtual address and returns the byte offset
  17905. // of that address within the page.
  17906. //
  17907. // Arguments:
  17908. //
  17909. // Va - Virtual address.
  17910. //
  17911. // Return Value:
  17912. //
  17913. // Returns the byte offset portion of the virtual address.
  17914. //
  17915. //--
  17916. #define BYTE_OFFSET(Va) ((ULONG)((LONG_PTR)(Va) & (PAGE_SIZE - 1)))
  17917. //++
  17918. //
  17919. // PVOID
  17920. // PAGE_ALIGN (
  17921. // IN PVOID Va
  17922. // )
  17923. //
  17924. // Routine Description:
  17925. //
  17926. // The PAGE_ALIGN macro takes a virtual address and returns a page-aligned
  17927. // virtual address for that page.
  17928. //
  17929. // Arguments:
  17930. //
  17931. // Va - Virtual address.
  17932. //
  17933. // Return Value:
  17934. //
  17935. // Returns the page aligned virtual address.
  17936. //
  17937. //--
  17938. #define PAGE_ALIGN(Va) ((PVOID)((ULONG_PTR)(Va) & ~(PAGE_SIZE - 1)))
  17939. //++
  17940. //
  17941. // ULONG
  17942. // ADDRESS_AND_SIZE_TO_SPAN_PAGES (
  17943. // IN PVOID Va,
  17944. // IN ULONG Size
  17945. // )
  17946. //
  17947. // Routine Description:
  17948. //
  17949. // The ADDRESS_AND_SIZE_TO_SPAN_PAGES macro takes a virtual address and
  17950. // size and returns the number of pages spanned by the size.
  17951. //
  17952. // Arguments:
  17953. //
  17954. // Va - Virtual address.
  17955. //
  17956. // Size - Size in bytes.
  17957. //
  17958. // Return Value:
  17959. //
  17960. // Returns the number of pages spanned by the size.
  17961. //
  17962. //--
  17963. #define ADDRESS_AND_SIZE_TO_SPAN_PAGES(Va,Size) \
  17964. ((ULONG)((((ULONG_PTR)(Va) & (PAGE_SIZE -1)) + (Size) + (PAGE_SIZE - 1)) >> PAGE_SHIFT))
  17965. #if PRAGMA_DEPRECATED_DDK
  17966. #pragma deprecated(COMPUTE_PAGES_SPANNED) // Use ADDRESS_AND_SIZE_TO_SPAN_PAGES
  17967. #endif
  17968. #define COMPUTE_PAGES_SPANNED(Va, Size) ADDRESS_AND_SIZE_TO_SPAN_PAGES(Va,Size)
  17969. //++
  17970. // PPFN_NUMBER
  17971. // MmGetMdlPfnArray (
  17972. // IN PMDL Mdl
  17973. // )
  17974. //
  17975. // Routine Description:
  17976. //
  17977. // The MmGetMdlPfnArray routine returns the virtual address of the
  17978. // first element of the array of physical page numbers associated with
  17979. // the MDL.
  17980. //
  17981. // Arguments:
  17982. //
  17983. // Mdl - Pointer to an MDL.
  17984. //
  17985. // Return Value:
  17986. //
  17987. // Returns the virtual address of the first element of the array of
  17988. // physical page numbers associated with the MDL.
  17989. //
  17990. //--
  17991. #define MmGetMdlPfnArray(Mdl) ((PPFN_NUMBER)(Mdl + 1))
  17992. //++
  17993. //
  17994. // PVOID
  17995. // MmGetMdlVirtualAddress (
  17996. // IN PMDL Mdl
  17997. // )
  17998. //
  17999. // Routine Description:
  18000. //
  18001. // The MmGetMdlVirtualAddress returns the virtual address of the buffer
  18002. // described by the Mdl.
  18003. //
  18004. // Arguments:
  18005. //
  18006. // Mdl - Pointer to an MDL.
  18007. //
  18008. // Return Value:
  18009. //
  18010. // Returns the virtual address of the buffer described by the Mdl
  18011. //
  18012. //--
  18013. #define MmGetMdlVirtualAddress(Mdl) \
  18014. ((PVOID) ((PCHAR) ((Mdl)->StartVa) + (Mdl)->ByteOffset))
  18015. //++
  18016. //
  18017. // ULONG
  18018. // MmGetMdlByteCount (
  18019. // IN PMDL Mdl
  18020. // )
  18021. //
  18022. // Routine Description:
  18023. //
  18024. // The MmGetMdlByteCount returns the length in bytes of the buffer
  18025. // described by the Mdl.
  18026. //
  18027. // Arguments:
  18028. //
  18029. // Mdl - Pointer to an MDL.
  18030. //
  18031. // Return Value:
  18032. //
  18033. // Returns the byte count of the buffer described by the Mdl
  18034. //
  18035. //--
  18036. #define MmGetMdlByteCount(Mdl) ((Mdl)->ByteCount)
  18037. //++
  18038. //
  18039. // ULONG
  18040. // MmGetMdlByteOffset (
  18041. // IN PMDL Mdl
  18042. // )
  18043. //
  18044. // Routine Description:
  18045. //
  18046. // The MmGetMdlByteOffset returns the byte offset within the page
  18047. // of the buffer described by the Mdl.
  18048. //
  18049. // Arguments:
  18050. //
  18051. // Mdl - Pointer to an MDL.
  18052. //
  18053. // Return Value:
  18054. //
  18055. // Returns the byte offset within the page of the buffer described by the Mdl
  18056. //
  18057. //--
  18058. #define MmGetMdlByteOffset(Mdl) ((Mdl)->ByteOffset)
  18059. //++
  18060. //
  18061. // PVOID
  18062. // MmGetMdlStartVa (
  18063. // IN PMDL Mdl
  18064. // )
  18065. //
  18066. // Routine Description:
  18067. //
  18068. // The MmGetMdlBaseVa returns the virtual address of the buffer
  18069. // described by the Mdl rounded down to the nearest page.
  18070. //
  18071. // Arguments:
  18072. //
  18073. // Mdl - Pointer to an MDL.
  18074. //
  18075. // Return Value:
  18076. //
  18077. // Returns the returns the starting virtual address of the MDL.
  18078. //
  18079. //
  18080. //--
  18081. #define MmGetMdlBaseVa(Mdl) ((Mdl)->StartVa)
  18082. typedef enum _MM_SYSTEM_SIZE {
  18083. MmSmallSystem,
  18084. MmMediumSystem,
  18085. MmLargeSystem
  18086. } MM_SYSTEMSIZE;
  18087. NTKERNELAPI
  18088. MM_SYSTEMSIZE
  18089. MmQuerySystemSize (
  18090. VOID
  18091. );
  18092. // end_wdm
  18093. NTKERNELAPI
  18094. BOOLEAN
  18095. MmIsThisAnNtAsSystem (
  18096. VOID
  18097. );
  18098. //
  18099. // I/O support routines.
  18100. //
  18101. NTKERNELAPI
  18102. VOID
  18103. MmProbeAndLockPages (
  18104. IN OUT PMDL MemoryDescriptorList,
  18105. IN KPROCESSOR_MODE AccessMode,
  18106. IN LOCK_OPERATION Operation
  18107. );
  18108. NTKERNELAPI
  18109. VOID
  18110. MmUnlockPages (
  18111. IN PMDL MemoryDescriptorList
  18112. );
  18113. NTKERNELAPI
  18114. VOID
  18115. MmBuildMdlForNonPagedPool (
  18116. IN OUT PMDL MemoryDescriptorList
  18117. );
  18118. NTKERNELAPI
  18119. PVOID
  18120. MmMapLockedPages (
  18121. IN PMDL MemoryDescriptorList,
  18122. IN KPROCESSOR_MODE AccessMode
  18123. );
  18124. LOGICAL
  18125. MmIsIoSpaceActive (
  18126. IN PHYSICAL_ADDRESS StartAddress,
  18127. IN SIZE_T NumberOfBytes
  18128. );
  18129. NTKERNELAPI
  18130. PVOID
  18131. MmGetSystemRoutineAddress (
  18132. IN PUNICODE_STRING SystemRoutineName
  18133. );
  18134. NTKERNELAPI
  18135. NTSTATUS
  18136. MmAdvanceMdl (
  18137. IN PMDL Mdl,
  18138. IN ULONG NumberOfBytes
  18139. );
  18140. // end_wdm
  18141. NTKERNELAPI
  18142. NTSTATUS
  18143. MmMapUserAddressesToPage (
  18144. IN PVOID BaseAddress,
  18145. IN SIZE_T NumberOfBytes,
  18146. IN PVOID PageAddress
  18147. );
  18148. // begin_wdm
  18149. NTKERNELAPI
  18150. NTSTATUS
  18151. MmProtectMdlSystemAddress (
  18152. IN PMDL MemoryDescriptorList,
  18153. IN ULONG NewProtect
  18154. );
  18155. //
  18156. // _MM_PAGE_PRIORITY_ provides a method for the system to handle requests
  18157. // intelligently in low resource conditions.
  18158. //
  18159. // LowPagePriority should be used when it is acceptable to the driver for the
  18160. // mapping request to fail if the system is low on resources. An example of
  18161. // this could be for a non-critical network connection where the driver can
  18162. // handle the failure case when system resources are close to being depleted.
  18163. //
  18164. // NormalPagePriority should be used when it is acceptable to the driver for the
  18165. // mapping request to fail if the system is very low on resources. An example
  18166. // of this could be for a non-critical local filesystem request.
  18167. //
  18168. // HighPagePriority should be used when it is unacceptable to the driver for the
  18169. // mapping request to fail unless the system is completely out of resources.
  18170. // An example of this would be the paging file path in a driver.
  18171. //
  18172. // begin_ntndis
  18173. typedef enum _MM_PAGE_PRIORITY {
  18174. LowPagePriority,
  18175. NormalPagePriority = 16,
  18176. HighPagePriority = 32
  18177. } MM_PAGE_PRIORITY;
  18178. // end_ntndis
  18179. //
  18180. // Note: This function is not available in WDM 1.0
  18181. //
  18182. NTKERNELAPI
  18183. PVOID
  18184. MmMapLockedPagesSpecifyCache (
  18185. IN PMDL MemoryDescriptorList,
  18186. IN KPROCESSOR_MODE AccessMode,
  18187. IN MEMORY_CACHING_TYPE CacheType,
  18188. IN PVOID BaseAddress,
  18189. IN ULONG BugCheckOnFailure,
  18190. IN MM_PAGE_PRIORITY Priority
  18191. );
  18192. NTKERNELAPI
  18193. VOID
  18194. MmUnmapLockedPages (
  18195. IN PVOID BaseAddress,
  18196. IN PMDL MemoryDescriptorList
  18197. );
  18198. PVOID
  18199. MmAllocateMappingAddress (
  18200. IN SIZE_T NumberOfBytes,
  18201. IN ULONG PoolTag
  18202. );
  18203. VOID
  18204. MmFreeMappingAddress (
  18205. IN PVOID BaseAddress,
  18206. IN ULONG PoolTag
  18207. );
  18208. PVOID
  18209. MmMapLockedPagesWithReservedMapping (
  18210. IN PVOID MappingAddress,
  18211. IN ULONG PoolTag,
  18212. IN PMDL MemoryDescriptorList,
  18213. IN MEMORY_CACHING_TYPE CacheType
  18214. );
  18215. VOID
  18216. MmUnmapReservedMapping (
  18217. IN PVOID BaseAddress,
  18218. IN ULONG PoolTag,
  18219. IN PMDL MemoryDescriptorList
  18220. );
  18221. // end_wdm
  18222. typedef struct _PHYSICAL_MEMORY_RANGE {
  18223. PHYSICAL_ADDRESS BaseAddress;
  18224. LARGE_INTEGER NumberOfBytes;
  18225. } PHYSICAL_MEMORY_RANGE, *PPHYSICAL_MEMORY_RANGE;
  18226. NTKERNELAPI
  18227. NTSTATUS
  18228. MmAddPhysicalMemory (
  18229. IN PPHYSICAL_ADDRESS StartAddress,
  18230. IN OUT PLARGE_INTEGER NumberOfBytes
  18231. );
  18232. NTKERNELAPI
  18233. NTSTATUS
  18234. MmRemovePhysicalMemory (
  18235. IN PPHYSICAL_ADDRESS StartAddress,
  18236. IN OUT PLARGE_INTEGER NumberOfBytes
  18237. );
  18238. NTKERNELAPI
  18239. PPHYSICAL_MEMORY_RANGE
  18240. MmGetPhysicalMemoryRanges (
  18241. VOID
  18242. );
  18243. // end_ntddk end_ntifs
  18244. NTSTATUS
  18245. MmMarkPhysicalMemoryAsGood (
  18246. IN PPHYSICAL_ADDRESS StartAddress,
  18247. IN OUT PLARGE_INTEGER NumberOfBytes
  18248. );
  18249. NTSTATUS
  18250. MmMarkPhysicalMemoryAsBad (
  18251. IN PPHYSICAL_ADDRESS StartAddress,
  18252. IN OUT PLARGE_INTEGER NumberOfBytes
  18253. );
  18254. // begin_wdm begin_ntddk begin_ntifs
  18255. NTKERNELAPI
  18256. PMDL
  18257. MmAllocatePagesForMdl (
  18258. IN PHYSICAL_ADDRESS LowAddress,
  18259. IN PHYSICAL_ADDRESS HighAddress,
  18260. IN PHYSICAL_ADDRESS SkipBytes,
  18261. IN SIZE_T TotalBytes
  18262. );
  18263. NTKERNELAPI
  18264. VOID
  18265. MmFreePagesFromMdl (
  18266. IN PMDL MemoryDescriptorList
  18267. );
  18268. NTKERNELAPI
  18269. PVOID
  18270. MmMapIoSpace (
  18271. IN PHYSICAL_ADDRESS PhysicalAddress,
  18272. IN SIZE_T NumberOfBytes,
  18273. IN MEMORY_CACHING_TYPE CacheType
  18274. );
  18275. NTKERNELAPI
  18276. VOID
  18277. MmUnmapIoSpace (
  18278. IN PVOID BaseAddress,
  18279. IN SIZE_T NumberOfBytes
  18280. );
  18281. // end_wdm end_ntddk end_ntifs end_ntosp
  18282. NTKERNELAPI
  18283. VOID
  18284. MmProbeAndLockSelectedPages (
  18285. IN OUT PMDL MemoryDescriptorList,
  18286. IN PFILE_SEGMENT_ELEMENT SegmentArray,
  18287. IN KPROCESSOR_MODE AccessMode,
  18288. IN LOCK_OPERATION Operation
  18289. );
  18290. // begin_ntddk begin_ntifs begin_ntosp
  18291. NTKERNELAPI
  18292. PVOID
  18293. MmMapVideoDisplay (
  18294. IN PHYSICAL_ADDRESS PhysicalAddress,
  18295. IN SIZE_T NumberOfBytes,
  18296. IN MEMORY_CACHING_TYPE CacheType
  18297. );
  18298. NTKERNELAPI
  18299. VOID
  18300. MmUnmapVideoDisplay (
  18301. IN PVOID BaseAddress,
  18302. IN SIZE_T NumberOfBytes
  18303. );
  18304. NTKERNELAPI
  18305. PHYSICAL_ADDRESS
  18306. MmGetPhysicalAddress (
  18307. IN PVOID BaseAddress
  18308. );
  18309. NTKERNELAPI
  18310. PVOID
  18311. MmGetVirtualForPhysical (
  18312. IN PHYSICAL_ADDRESS PhysicalAddress
  18313. );
  18314. NTKERNELAPI
  18315. PVOID
  18316. MmAllocateContiguousMemory (
  18317. IN SIZE_T NumberOfBytes,
  18318. IN PHYSICAL_ADDRESS HighestAcceptableAddress
  18319. );
  18320. NTKERNELAPI
  18321. PVOID
  18322. MmAllocateContiguousMemorySpecifyCache (
  18323. IN SIZE_T NumberOfBytes,
  18324. IN PHYSICAL_ADDRESS LowestAcceptableAddress,
  18325. IN PHYSICAL_ADDRESS HighestAcceptableAddress,
  18326. IN PHYSICAL_ADDRESS BoundaryAddressMultiple OPTIONAL,
  18327. IN MEMORY_CACHING_TYPE CacheType
  18328. );
  18329. NTKERNELAPI
  18330. VOID
  18331. MmFreeContiguousMemory (
  18332. IN PVOID BaseAddress
  18333. );
  18334. NTKERNELAPI
  18335. VOID
  18336. MmFreeContiguousMemorySpecifyCache (
  18337. IN PVOID BaseAddress,
  18338. IN SIZE_T NumberOfBytes,
  18339. IN MEMORY_CACHING_TYPE CacheType
  18340. );
  18341. NTKERNELAPI
  18342. PVOID
  18343. MmAllocateNonCachedMemory (
  18344. IN SIZE_T NumberOfBytes
  18345. );
  18346. NTKERNELAPI
  18347. VOID
  18348. MmFreeNonCachedMemory (
  18349. IN PVOID BaseAddress,
  18350. IN SIZE_T NumberOfBytes
  18351. );
  18352. NTKERNELAPI
  18353. BOOLEAN
  18354. MmIsAddressValid (
  18355. IN PVOID VirtualAddress
  18356. );
  18357. DECLSPEC_DEPRECATED_DDK
  18358. NTKERNELAPI
  18359. BOOLEAN
  18360. MmIsNonPagedSystemAddressValid (
  18361. IN PVOID VirtualAddress
  18362. );
  18363. // begin_wdm
  18364. NTKERNELAPI
  18365. SIZE_T
  18366. MmSizeOfMdl (
  18367. IN PVOID Base,
  18368. IN SIZE_T Length
  18369. );
  18370. DECLSPEC_DEPRECATED_DDK // Use IoAllocateMdl
  18371. NTKERNELAPI
  18372. PMDL
  18373. MmCreateMdl (
  18374. IN PMDL MemoryDescriptorList OPTIONAL,
  18375. IN PVOID Base,
  18376. IN SIZE_T Length
  18377. );
  18378. NTKERNELAPI
  18379. PVOID
  18380. MmLockPagableDataSection (
  18381. IN PVOID AddressWithinSection
  18382. );
  18383. // end_wdm
  18384. NTKERNELAPI
  18385. VOID
  18386. MmLockPagableSectionByHandle (
  18387. IN PVOID ImageSectionHandle
  18388. );
  18389. // end_ntddk end_ntifs end_ntosp
  18390. NTKERNELAPI
  18391. VOID
  18392. MmLockPagedPool (
  18393. IN PVOID Address,
  18394. IN SIZE_T Size
  18395. );
  18396. NTKERNELAPI
  18397. VOID
  18398. MmUnlockPagedPool (
  18399. IN PVOID Address,
  18400. IN SIZE_T Size
  18401. );
  18402. // begin_wdm begin_ntddk begin_ntifs begin_ntosp
  18403. NTKERNELAPI
  18404. VOID
  18405. MmResetDriverPaging (
  18406. IN PVOID AddressWithinSection
  18407. );
  18408. NTKERNELAPI
  18409. PVOID
  18410. MmPageEntireDriver (
  18411. IN PVOID AddressWithinSection
  18412. );
  18413. NTKERNELAPI
  18414. VOID
  18415. MmUnlockPagableImageSection(
  18416. IN PVOID ImageSectionHandle
  18417. );
  18418. // end_wdm end_ntosp
  18419. // begin_ntosp
  18420. //
  18421. // Note that even though this function prototype
  18422. // says "HANDLE", MmSecureVirtualMemory does NOT return
  18423. // anything resembling a Win32-style handle. The return
  18424. // value from this function can ONLY be used with MmUnsecureVirtualMemory.
  18425. //
  18426. NTKERNELAPI
  18427. HANDLE
  18428. MmSecureVirtualMemory (
  18429. IN PVOID Address,
  18430. IN SIZE_T Size,
  18431. IN ULONG ProbeMode
  18432. );
  18433. NTKERNELAPI
  18434. VOID
  18435. MmUnsecureVirtualMemory (
  18436. IN HANDLE SecureHandle
  18437. );
  18438. // end_ntosp
  18439. NTKERNELAPI
  18440. NTSTATUS
  18441. MmMapViewInSystemSpace (
  18442. IN PVOID Section,
  18443. OUT PVOID *MappedBase,
  18444. IN PSIZE_T ViewSize
  18445. );
  18446. NTKERNELAPI
  18447. NTSTATUS
  18448. MmUnmapViewInSystemSpace (
  18449. IN PVOID MappedBase
  18450. );
  18451. // begin_ntosp
  18452. NTKERNELAPI
  18453. NTSTATUS
  18454. MmMapViewInSessionSpace (
  18455. IN PVOID Section,
  18456. OUT PVOID *MappedBase,
  18457. IN OUT PSIZE_T ViewSize
  18458. );
  18459. // end_ntddk end_ntifs
  18460. NTKERNELAPI
  18461. NTSTATUS
  18462. MmCommitSessionMappedView (
  18463. IN PVOID MappedAddress,
  18464. IN SIZE_T ViewSize
  18465. );
  18466. // begin_ntddk begin_ntifs
  18467. NTKERNELAPI
  18468. NTSTATUS
  18469. MmUnmapViewInSessionSpace (
  18470. IN PVOID MappedBase
  18471. );
  18472. // end_ntosp
  18473. // begin_wdm begin_ntosp
  18474. //++
  18475. //
  18476. // VOID
  18477. // MmInitializeMdl (
  18478. // IN PMDL MemoryDescriptorList,
  18479. // IN PVOID BaseVa,
  18480. // IN SIZE_T Length
  18481. // )
  18482. //
  18483. // Routine Description:
  18484. //
  18485. // This routine initializes the header of a Memory Descriptor List (MDL).
  18486. //
  18487. // Arguments:
  18488. //
  18489. // MemoryDescriptorList - Pointer to the MDL to initialize.
  18490. //
  18491. // BaseVa - Base virtual address mapped by the MDL.
  18492. //
  18493. // Length - Length, in bytes, of the buffer mapped by the MDL.
  18494. //
  18495. // Return Value:
  18496. //
  18497. // None.
  18498. //
  18499. //--
  18500. #define MmInitializeMdl(MemoryDescriptorList, BaseVa, Length) { \
  18501. (MemoryDescriptorList)->Next = (PMDL) NULL; \
  18502. (MemoryDescriptorList)->Size = (CSHORT)(sizeof(MDL) + \
  18503. (sizeof(PFN_NUMBER) * ADDRESS_AND_SIZE_TO_SPAN_PAGES((BaseVa), (Length)))); \
  18504. (MemoryDescriptorList)->MdlFlags = 0; \
  18505. (MemoryDescriptorList)->StartVa = (PVOID) PAGE_ALIGN((BaseVa)); \
  18506. (MemoryDescriptorList)->ByteOffset = BYTE_OFFSET((BaseVa)); \
  18507. (MemoryDescriptorList)->ByteCount = (ULONG)(Length); \
  18508. }
  18509. //++
  18510. //
  18511. // PVOID
  18512. // MmGetSystemAddressForMdlSafe (
  18513. // IN PMDL MDL,
  18514. // IN MM_PAGE_PRIORITY PRIORITY
  18515. // )
  18516. //
  18517. // Routine Description:
  18518. //
  18519. // This routine returns the mapped address of an MDL. If the
  18520. // Mdl is not already mapped or a system address, it is mapped.
  18521. //
  18522. // Arguments:
  18523. //
  18524. // MemoryDescriptorList - Pointer to the MDL to map.
  18525. //
  18526. // Priority - Supplies an indication as to how important it is that this
  18527. // request succeed under low available PTE conditions.
  18528. //
  18529. // Return Value:
  18530. //
  18531. // Returns the base address where the pages are mapped. The base address
  18532. // has the same offset as the virtual address in the MDL.
  18533. //
  18534. // Unlike MmGetSystemAddressForMdl, Safe guarantees that it will always
  18535. // return NULL on failure instead of bugchecking the system.
  18536. //
  18537. // This macro is not usable by WDM 1.0 drivers as 1.0 did not include
  18538. // MmMapLockedPagesSpecifyCache. The solution for WDM 1.0 drivers is to
  18539. // provide synchronization and set/reset the MDL_MAPPING_CAN_FAIL bit.
  18540. //
  18541. //--
  18542. #define MmGetSystemAddressForMdlSafe(MDL, PRIORITY) \
  18543. (((MDL)->MdlFlags & (MDL_MAPPED_TO_SYSTEM_VA | \
  18544. MDL_SOURCE_IS_NONPAGED_POOL)) ? \
  18545. ((MDL)->MappedSystemVa) : \
  18546. (MmMapLockedPagesSpecifyCache((MDL), \
  18547. KernelMode, \
  18548. MmCached, \
  18549. NULL, \
  18550. FALSE, \
  18551. (PRIORITY))))
  18552. //++
  18553. //
  18554. // PVOID
  18555. // MmGetSystemAddressForMdl (
  18556. // IN PMDL MDL
  18557. // )
  18558. //
  18559. // Routine Description:
  18560. //
  18561. // This routine returns the mapped address of an MDL, if the
  18562. // Mdl is not already mapped or a system address, it is mapped.
  18563. //
  18564. // Arguments:
  18565. //
  18566. // MemoryDescriptorList - Pointer to the MDL to map.
  18567. //
  18568. // Return Value:
  18569. //
  18570. // Returns the base address where the pages are mapped. The base address
  18571. // has the same offset as the virtual address in the MDL.
  18572. //
  18573. //--
  18574. //#define MmGetSystemAddressForMdl(MDL)
  18575. // (((MDL)->MdlFlags & (MDL_MAPPED_TO_SYSTEM_VA)) ?
  18576. // ((MDL)->MappedSystemVa) :
  18577. // ((((MDL)->MdlFlags & (MDL_SOURCE_IS_NONPAGED_POOL)) ?
  18578. // ((PVOID)((ULONG)(MDL)->StartVa | (MDL)->ByteOffset)) :
  18579. // (MmMapLockedPages((MDL),KernelMode)))))
  18580. #if PRAGMA_DEPRECATED_DDK
  18581. #pragma deprecated(MmGetSystemAddressForMdl) // Use MmGetSystemAddressForMdlSafe
  18582. #endif
  18583. #define MmGetSystemAddressForMdl(MDL) \
  18584. (((MDL)->MdlFlags & (MDL_MAPPED_TO_SYSTEM_VA | \
  18585. MDL_SOURCE_IS_NONPAGED_POOL)) ? \
  18586. ((MDL)->MappedSystemVa) : \
  18587. (MmMapLockedPages((MDL),KernelMode)))
  18588. //++
  18589. //
  18590. // VOID
  18591. // MmPrepareMdlForReuse (
  18592. // IN PMDL MDL
  18593. // )
  18594. //
  18595. // Routine Description:
  18596. //
  18597. // This routine will take all of the steps necessary to allow an MDL to be
  18598. // re-used.
  18599. //
  18600. // Arguments:
  18601. //
  18602. // MemoryDescriptorList - Pointer to the MDL that will be re-used.
  18603. //
  18604. // Return Value:
  18605. //
  18606. // None.
  18607. //
  18608. //--
  18609. #define MmPrepareMdlForReuse(MDL) \
  18610. if (((MDL)->MdlFlags & MDL_PARTIAL_HAS_BEEN_MAPPED) != 0) { \
  18611. ASSERT(((MDL)->MdlFlags & MDL_PARTIAL) != 0); \
  18612. MmUnmapLockedPages( (MDL)->MappedSystemVa, (MDL) ); \
  18613. } else if (((MDL)->MdlFlags & MDL_PARTIAL) == 0) { \
  18614. ASSERT(((MDL)->MdlFlags & MDL_MAPPED_TO_SYSTEM_VA) == 0); \
  18615. }
  18616. typedef NTSTATUS (*PMM_DLL_INITIALIZE)(
  18617. IN PUNICODE_STRING RegistryPath
  18618. );
  18619. typedef NTSTATUS (*PMM_DLL_UNLOAD)(
  18620. VOID
  18621. );
  18622. NTKERNELAPI
  18623. NTSTATUS
  18624. MmCreateMirror (
  18625. VOID
  18626. );
  18627. //
  18628. // Object Manager types
  18629. //
  18630. typedef struct _OBJECT_HANDLE_INFORMATION {
  18631. ULONG HandleAttributes;
  18632. ACCESS_MASK GrantedAccess;
  18633. } OBJECT_HANDLE_INFORMATION, *POBJECT_HANDLE_INFORMATION;
  18634. // begin_ntosp
  18635. NTKERNELAPI
  18636. VOID
  18637. ObDeleteCapturedInsertInfo(
  18638. IN PVOID Object
  18639. );
  18640. NTKERNELAPI
  18641. NTSTATUS
  18642. ObCreateObject(
  18643. IN KPROCESSOR_MODE ProbeMode,
  18644. IN POBJECT_TYPE ObjectType,
  18645. IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL,
  18646. IN KPROCESSOR_MODE OwnershipMode,
  18647. IN OUT PVOID ParseContext OPTIONAL,
  18648. IN ULONG ObjectBodySize,
  18649. IN ULONG PagedPoolCharge,
  18650. IN ULONG NonPagedPoolCharge,
  18651. OUT PVOID *Object
  18652. );
  18653. //
  18654. // These inlines correct an issue where the compiler refetches
  18655. // the output object over and over again because it thinks its
  18656. // a possible alias for other stores.
  18657. //
  18658. FORCEINLINE
  18659. NTSTATUS
  18660. _ObCreateObject(
  18661. IN KPROCESSOR_MODE ProbeMode,
  18662. IN POBJECT_TYPE ObjectType,
  18663. IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL,
  18664. IN KPROCESSOR_MODE OwnershipMode,
  18665. IN OUT PVOID ParseContext OPTIONAL,
  18666. IN ULONG ObjectBodySize,
  18667. IN ULONG PagedPoolCharge,
  18668. IN ULONG NonPagedPoolCharge,
  18669. OUT PVOID *pObject
  18670. )
  18671. {
  18672. PVOID Object;
  18673. NTSTATUS Status;
  18674. Status = ObCreateObject (ProbeMode,
  18675. ObjectType,
  18676. ObjectAttributes,
  18677. OwnershipMode,
  18678. ParseContext,
  18679. ObjectBodySize,
  18680. PagedPoolCharge,
  18681. NonPagedPoolCharge,
  18682. &Object);
  18683. *pObject = Object;
  18684. return Status;
  18685. }
  18686. #define ObCreateObject _ObCreateObject
  18687. NTKERNELAPI
  18688. NTSTATUS
  18689. ObInsertObject(
  18690. IN PVOID Object,
  18691. IN PACCESS_STATE PassedAccessState OPTIONAL,
  18692. IN ACCESS_MASK DesiredAccess OPTIONAL,
  18693. IN ULONG ObjectPointerBias,
  18694. OUT PVOID *NewObject OPTIONAL,
  18695. OUT PHANDLE Handle OPTIONAL
  18696. );
  18697. NTKERNELAPI
  18698. NTSTATUS
  18699. ObReferenceObjectByHandle(
  18700. IN HANDLE Handle,
  18701. IN ACCESS_MASK DesiredAccess,
  18702. IN POBJECT_TYPE ObjectType OPTIONAL,
  18703. IN KPROCESSOR_MODE AccessMode,
  18704. OUT PVOID *Object,
  18705. OUT POBJECT_HANDLE_INFORMATION HandleInformation OPTIONAL
  18706. );
  18707. #define ObDereferenceObject(a) \
  18708. ObfDereferenceObject(a)
  18709. #define ObReferenceObject(Object) ObfReferenceObject(Object)
  18710. NTKERNELAPI
  18711. LONG_PTR
  18712. FASTCALL
  18713. ObfReferenceObject(
  18714. IN PVOID Object
  18715. );
  18716. NTKERNELAPI
  18717. NTSTATUS
  18718. ObReferenceObjectByPointer(
  18719. IN PVOID Object,
  18720. IN ACCESS_MASK DesiredAccess,
  18721. IN POBJECT_TYPE ObjectType,
  18722. IN KPROCESSOR_MODE AccessMode
  18723. );
  18724. NTKERNELAPI
  18725. LONG_PTR
  18726. FASTCALL
  18727. ObfDereferenceObject(
  18728. IN PVOID Object
  18729. );
  18730. #ifndef _HAL_
  18731. #define _HAL_
  18732. // begin_ntosp
  18733. //
  18734. // Define OEM bitmapped font check values.
  18735. //
  18736. #define OEM_FONT_VERSION 0x200
  18737. #define OEM_FONT_TYPE 0
  18738. #define OEM_FONT_ITALIC 0
  18739. #define OEM_FONT_UNDERLINE 0
  18740. #define OEM_FONT_STRIKEOUT 0
  18741. #define OEM_FONT_CHARACTER_SET 255
  18742. #define OEM_FONT_FAMILY (3 << 4)
  18743. //
  18744. // Define OEM bitmapped font file header structure.
  18745. //
  18746. // N.B. this is a packed structure.
  18747. //
  18748. #include "pshpack1.h"
  18749. typedef struct _OEM_FONT_FILE_HEADER {
  18750. USHORT Version;
  18751. ULONG FileSize;
  18752. UCHAR Copyright[60];
  18753. USHORT Type;
  18754. USHORT Points;
  18755. USHORT VerticleResolution;
  18756. USHORT HorizontalResolution;
  18757. USHORT Ascent;
  18758. USHORT InternalLeading;
  18759. USHORT ExternalLeading;
  18760. UCHAR Italic;
  18761. UCHAR Underline;
  18762. UCHAR StrikeOut;
  18763. USHORT Weight;
  18764. UCHAR CharacterSet;
  18765. USHORT PixelWidth;
  18766. USHORT PixelHeight;
  18767. UCHAR Family;
  18768. USHORT AverageWidth;
  18769. USHORT MaximumWidth;
  18770. UCHAR FirstCharacter;
  18771. UCHAR LastCharacter;
  18772. UCHAR DefaultCharacter;
  18773. UCHAR BreakCharacter;
  18774. USHORT WidthInBytes;
  18775. ULONG Device;
  18776. ULONG Face;
  18777. ULONG BitsPointer;
  18778. ULONG BitsOffset;
  18779. UCHAR Filler;
  18780. struct {
  18781. USHORT Width;
  18782. USHORT Offset;
  18783. } Map[1];
  18784. } OEM_FONT_FILE_HEADER, *POEM_FONT_FILE_HEADER;
  18785. #include "poppack.h"
  18786. // end_ntosp
  18787. // begin_ntddk begin_wdm begin_ntosp
  18788. //
  18789. // Define the device description structure.
  18790. //
  18791. typedef struct _DEVICE_DESCRIPTION {
  18792. ULONG Version;
  18793. BOOLEAN Master;
  18794. BOOLEAN ScatterGather;
  18795. BOOLEAN DemandMode;
  18796. BOOLEAN AutoInitialize;
  18797. BOOLEAN Dma32BitAddresses;
  18798. BOOLEAN IgnoreCount;
  18799. BOOLEAN Reserved1; // must be false
  18800. BOOLEAN Dma64BitAddresses;
  18801. ULONG BusNumber; // unused for WDM
  18802. ULONG DmaChannel;
  18803. INTERFACE_TYPE InterfaceType;
  18804. DMA_WIDTH DmaWidth;
  18805. DMA_SPEED DmaSpeed;
  18806. ULONG MaximumLength;
  18807. ULONG DmaPort;
  18808. } DEVICE_DESCRIPTION, *PDEVICE_DESCRIPTION;
  18809. //
  18810. // Define the supported version numbers for the device description structure.
  18811. //
  18812. #define DEVICE_DESCRIPTION_VERSION 0
  18813. #define DEVICE_DESCRIPTION_VERSION1 1
  18814. #define DEVICE_DESCRIPTION_VERSION2 2
  18815. // end_ntddk end_wdm
  18816. //
  18817. // Boot record disk partition table entry structure format.
  18818. //
  18819. typedef struct _PARTITION_DESCRIPTOR {
  18820. UCHAR ActiveFlag; // Bootable or not
  18821. UCHAR StartingTrack; // Not used
  18822. UCHAR StartingCylinderLsb; // Not used
  18823. UCHAR StartingCylinderMsb; // Not used
  18824. UCHAR PartitionType; // 12 bit FAT, 16 bit FAT etc.
  18825. UCHAR EndingTrack; // Not used
  18826. UCHAR EndingCylinderLsb; // Not used
  18827. UCHAR EndingCylinderMsb; // Not used
  18828. UCHAR StartingSectorLsb0; // Hidden sectors
  18829. UCHAR StartingSectorLsb1;
  18830. UCHAR StartingSectorMsb0;
  18831. UCHAR StartingSectorMsb1;
  18832. UCHAR PartitionLengthLsb0; // Sectors in this partition
  18833. UCHAR PartitionLengthLsb1;
  18834. UCHAR PartitionLengthMsb0;
  18835. UCHAR PartitionLengthMsb1;
  18836. } PARTITION_DESCRIPTOR, *PPARTITION_DESCRIPTOR;
  18837. //
  18838. // Number of partition table entries
  18839. //
  18840. #define NUM_PARTITION_TABLE_ENTRIES 4
  18841. //
  18842. // Partition table record and boot signature offsets in 16-bit words.
  18843. //
  18844. #define PARTITION_TABLE_OFFSET (0x1be / 2)
  18845. #define BOOT_SIGNATURE_OFFSET ((0x200 / 2) - 1)
  18846. //
  18847. // Boot record signature value.
  18848. //
  18849. #define BOOT_RECORD_SIGNATURE (0xaa55)
  18850. //
  18851. // Initial size of the Partition list structure.
  18852. //
  18853. #define PARTITION_BUFFER_SIZE 2048
  18854. //
  18855. // Partition active flag - i.e., boot indicator
  18856. //
  18857. #define PARTITION_ACTIVE_FLAG 0x80
  18858. // end_ntosp
  18859. // begin_ntddk
  18860. //
  18861. // The following function prototypes are for HAL routines with a prefix of Hal.
  18862. //
  18863. // General functions.
  18864. //
  18865. typedef
  18866. BOOLEAN
  18867. (*PHAL_RESET_DISPLAY_PARAMETERS) (
  18868. IN ULONG Columns,
  18869. IN ULONG Rows
  18870. );
  18871. DECLSPEC_DEPRECATED_DDK
  18872. NTHALAPI
  18873. VOID
  18874. HalAcquireDisplayOwnership (
  18875. IN PHAL_RESET_DISPLAY_PARAMETERS ResetDisplayParameters
  18876. );
  18877. // end_ntddk
  18878. NTHALAPI
  18879. VOID
  18880. HalDisplayString (
  18881. PUCHAR String
  18882. );
  18883. NTHALAPI
  18884. VOID
  18885. HalQueryDisplayParameters (
  18886. OUT PULONG WidthInCharacters,
  18887. OUT PULONG HeightInLines,
  18888. OUT PULONG CursorColumn,
  18889. OUT PULONG CursorRow
  18890. );
  18891. NTHALAPI
  18892. VOID
  18893. HalSetDisplayParameters (
  18894. IN ULONG CursorColumn,
  18895. IN ULONG CursorRow
  18896. );
  18897. NTHALAPI
  18898. BOOLEAN
  18899. HalInitSystem (
  18900. IN ULONG Phase,
  18901. IN PLOADER_PARAMETER_BLOCK LoaderBlock
  18902. );
  18903. NTHALAPI
  18904. VOID
  18905. HalProcessorIdle(
  18906. VOID
  18907. );
  18908. NTHALAPI
  18909. VOID
  18910. HalReportResourceUsage (
  18911. VOID
  18912. );
  18913. NTHALAPI
  18914. ULONG
  18915. HalSetTimeIncrement (
  18916. IN ULONG DesiredIncrement
  18917. );
  18918. // begin_ntosp
  18919. //
  18920. // Get and set environment variable values.
  18921. //
  18922. NTHALAPI
  18923. ARC_STATUS
  18924. HalGetEnvironmentVariable (
  18925. IN PCHAR Variable,
  18926. IN USHORT Length,
  18927. OUT PCHAR Buffer
  18928. );
  18929. NTHALAPI
  18930. ARC_STATUS
  18931. HalSetEnvironmentVariable (
  18932. IN PCHAR Variable,
  18933. IN PCHAR Value
  18934. );
  18935. NTHALAPI
  18936. NTSTATUS
  18937. HalGetEnvironmentVariableEx (
  18938. IN PWSTR VariableName,
  18939. IN LPGUID VendorGuid,
  18940. OUT PVOID Value,
  18941. IN OUT PULONG ValueLength,
  18942. OUT PULONG Attributes OPTIONAL
  18943. );
  18944. NTSTATUS
  18945. HalSetEnvironmentVariableEx (
  18946. IN PWSTR VariableName,
  18947. IN LPGUID VendorGuid,
  18948. IN PVOID Value,
  18949. IN ULONG ValueLength,
  18950. IN ULONG Attributes
  18951. );
  18952. NTSTATUS
  18953. HalEnumerateEnvironmentVariablesEx (
  18954. IN ULONG InformationClass,
  18955. OUT PVOID Buffer,
  18956. IN OUT PULONG BufferLength
  18957. );
  18958. // end_ntosp
  18959. //
  18960. // Cache and write buffer flush functions.
  18961. //
  18962. //
  18963. #if defined(_IA64_) // ntddk ntifs ntndis ntosp
  18964. // ntddk ntifs ntndis ntosp
  18965. NTHALAPI
  18966. VOID
  18967. HalChangeColorPage (
  18968. IN PVOID NewColor,
  18969. IN PVOID OldColor,
  18970. IN ULONG PageFrame
  18971. );
  18972. NTHALAPI
  18973. VOID
  18974. HalFlushDcachePage (
  18975. IN PVOID Color,
  18976. IN ULONG PageFrame,
  18977. IN ULONG Length
  18978. );
  18979. // begin_ntosp
  18980. NTHALAPI
  18981. VOID
  18982. HalFlushIoBuffers (
  18983. IN PMDL Mdl,
  18984. IN BOOLEAN ReadOperation,
  18985. IN BOOLEAN DmaOperation
  18986. );
  18987. // begin_ntddk begin_ntifs begin_ntndis
  18988. DECLSPEC_DEPRECATED_DDK // Use GetDmaRequirement
  18989. NTHALAPI
  18990. ULONG
  18991. HalGetDmaAlignmentRequirement (
  18992. VOID
  18993. );
  18994. // end_ntosp end_ntddk end_ntifs end_ntndis
  18995. NTHALAPI
  18996. VOID
  18997. HalPurgeDcachePage (
  18998. IN PVOID Color,
  18999. IN ULONG PageFrame,
  19000. IN ULONG Length
  19001. );
  19002. NTHALAPI
  19003. VOID
  19004. HalPurgeIcachePage (
  19005. IN PVOID Color,
  19006. IN ULONG PageFrame,
  19007. IN ULONG Length
  19008. );
  19009. NTHALAPI
  19010. VOID
  19011. HalSweepDcache (
  19012. VOID
  19013. );
  19014. NTHALAPI
  19015. VOID
  19016. HalSweepDcacheRange (
  19017. IN PVOID BaseAddress,
  19018. IN SIZE_T Length
  19019. );
  19020. NTHALAPI
  19021. VOID
  19022. HalSweepIcache (
  19023. VOID
  19024. );
  19025. NTHALAPI
  19026. VOID
  19027. HalSweepIcacheRange (
  19028. IN PVOID BaseAddress,
  19029. IN SIZE_T Length
  19030. );
  19031. NTHALAPI
  19032. VOID
  19033. HalZeroPage (
  19034. IN PVOID NewColor,
  19035. IN PVOID OldColor,
  19036. IN PFN_NUMBER PageFrame
  19037. );
  19038. #endif // ntddk ntifs ntndis ntosp
  19039. // ntddk ntifs ntndis ntosp
  19040. #if defined(_M_IX86) || defined(_M_AMD64) // ntddk ntifs ntndis ntosp
  19041. // ntddk ntifs ntndis ntosp
  19042. #define HalGetDmaAlignmentRequirement() 1L // ntddk ntifs ntndis ntosp
  19043. NTHALAPI
  19044. VOID
  19045. HalHandleNMI (
  19046. IN OUT PVOID NmiInformation
  19047. );
  19048. #if defined(_AMD64_)
  19049. NTHALAPI
  19050. VOID
  19051. HalHandleMcheck (
  19052. IN PKTRAP_FRAME TrapFrame,
  19053. IN PKEXCEPTION_FRAME ExceptionFrame
  19054. );
  19055. #endif
  19056. //
  19057. // The following are temporary.
  19058. //
  19059. #if defined(_M_AMD64)
  19060. NTHALAPI
  19061. KIRQL
  19062. HalSwapIrql (
  19063. IN KIRQL Irql
  19064. );
  19065. NTHALAPI
  19066. KIRQL
  19067. HalGetCurrentIrql (
  19068. VOID
  19069. );
  19070. #endif
  19071. #endif // ntddk ntifs ntndis ntosp
  19072. // ntddk ntifs wdm ntndis
  19073. #if defined(_M_IA64)
  19074. NTHALAPI
  19075. VOID
  19076. HalSweepCacheRange (
  19077. IN PVOID BaseAddress,
  19078. IN SIZE_T Length
  19079. );
  19080. NTHALAPI
  19081. LONGLONG
  19082. HalCallPal (
  19083. IN ULONGLONG FunctionIndex,
  19084. IN ULONGLONG Arguement1,
  19085. IN ULONGLONG Arguement2,
  19086. IN ULONGLONG Arguement3,
  19087. OUT PULONGLONG ReturnValue0,
  19088. OUT PULONGLONG ReturnValue1,
  19089. OUT PULONGLONG ReturnValue2,
  19090. OUT PULONGLONG ReturnValue3
  19091. );
  19092. #endif
  19093. // begin_ntosp
  19094. NTHALAPI // ntddk ntifs wdm ntndis
  19095. VOID // ntddk ntifs wdm ntndis
  19096. KeFlushWriteBuffer ( // ntddk ntifs wdm ntndis
  19097. VOID // ntddk ntifs wdm ntndis
  19098. ); // ntddk ntifs wdm ntndis
  19099. // ntddk ntifs wdm ntndis
  19100. #if defined(_ALPHA_)
  19101. NTHALAPI
  19102. PVOID
  19103. HalCreateQva(
  19104. IN PHYSICAL_ADDRESS PhysicalAddress,
  19105. IN PVOID VirtualAddress
  19106. );
  19107. NTHALAPI
  19108. PVOID
  19109. HalDereferenceQva(
  19110. PVOID Qva,
  19111. INTERFACE_TYPE InterfaceType,
  19112. ULONG BusNumber
  19113. );
  19114. #endif
  19115. #if !defined(_X86_)
  19116. NTHALAPI
  19117. BOOLEAN
  19118. HalCallBios (
  19119. IN ULONG BiosCommand,
  19120. IN OUT PULONG Eax,
  19121. IN OUT PULONG Ebx,
  19122. IN OUT PULONG Ecx,
  19123. IN OUT PULONG Edx,
  19124. IN OUT PULONG Esi,
  19125. IN OUT PULONG Edi,
  19126. IN OUT PULONG Ebp
  19127. );
  19128. #endif
  19129. // end_ntosp
  19130. //
  19131. // Profiling functions.
  19132. //
  19133. NTHALAPI
  19134. VOID
  19135. HalCalibratePerformanceCounter (
  19136. IN LONG volatile *Number,
  19137. IN ULONGLONG NewCount
  19138. );
  19139. NTHALAPI
  19140. ULONG_PTR
  19141. HalSetProfileInterval (
  19142. IN ULONG_PTR Interval
  19143. );
  19144. NTHALAPI
  19145. VOID
  19146. HalStartProfileInterrupt (
  19147. KPROFILE_SOURCE ProfileSource
  19148. );
  19149. NTHALAPI
  19150. VOID
  19151. HalStopProfileInterrupt (
  19152. KPROFILE_SOURCE ProfileSource
  19153. );
  19154. //
  19155. // Timer and interrupt functions.
  19156. //
  19157. // begin_ntosp
  19158. NTHALAPI
  19159. BOOLEAN
  19160. HalQueryRealTimeClock (
  19161. OUT PTIME_FIELDS TimeFields
  19162. );
  19163. // end_ntosp
  19164. NTHALAPI
  19165. BOOLEAN
  19166. HalSetRealTimeClock (
  19167. IN PTIME_FIELDS TimeFields
  19168. );
  19169. #if defined(_M_IX86) || defined(_M_AMD64)
  19170. NTHALAPI
  19171. VOID
  19172. FASTCALL
  19173. HalRequestSoftwareInterrupt (
  19174. KIRQL RequestIrql
  19175. );
  19176. ULONG
  19177. FASTCALL
  19178. HalSystemVectorDispatchEntry (
  19179. IN ULONG Vector,
  19180. OUT PKINTERRUPT_ROUTINE **FlatDispatch,
  19181. OUT PKINTERRUPT_ROUTINE *NoConnection
  19182. );
  19183. #endif
  19184. // begin_ntosp
  19185. //
  19186. // Firmware interface functions.
  19187. //
  19188. NTHALAPI
  19189. VOID
  19190. HalReturnToFirmware (
  19191. IN FIRMWARE_REENTRY Routine
  19192. );
  19193. //
  19194. // System interrupts functions.
  19195. //
  19196. NTHALAPI
  19197. VOID
  19198. HalDisableSystemInterrupt (
  19199. IN ULONG Vector,
  19200. IN KIRQL Irql
  19201. );
  19202. NTHALAPI
  19203. BOOLEAN
  19204. HalEnableSystemInterrupt (
  19205. IN ULONG Vector,
  19206. IN KIRQL Irql,
  19207. IN KINTERRUPT_MODE InterruptMode
  19208. );
  19209. // begin_ntddk
  19210. //
  19211. // I/O driver configuration functions.
  19212. //
  19213. #if !defined(NO_LEGACY_DRIVERS)
  19214. DECLSPEC_DEPRECATED_DDK // Use Pnp or IoReportDetectedDevice
  19215. NTHALAPI
  19216. NTSTATUS
  19217. HalAssignSlotResources (
  19218. IN PUNICODE_STRING RegistryPath,
  19219. IN PUNICODE_STRING DriverClassName OPTIONAL,
  19220. IN PDRIVER_OBJECT DriverObject,
  19221. IN PDEVICE_OBJECT DeviceObject,
  19222. IN INTERFACE_TYPE BusType,
  19223. IN ULONG BusNumber,
  19224. IN ULONG SlotNumber,
  19225. IN OUT PCM_RESOURCE_LIST *AllocatedResources
  19226. );
  19227. DECLSPEC_DEPRECATED_DDK // Use Pnp or IoReportDetectedDevice
  19228. NTHALAPI
  19229. ULONG
  19230. HalGetInterruptVector(
  19231. IN INTERFACE_TYPE InterfaceType,
  19232. IN ULONG BusNumber,
  19233. IN ULONG BusInterruptLevel,
  19234. IN ULONG BusInterruptVector,
  19235. OUT PKIRQL Irql,
  19236. OUT PKAFFINITY Affinity
  19237. );
  19238. DECLSPEC_DEPRECATED_DDK // Use IRP_MN_QUERY_INTERFACE and IRP_MN_READ_CONFIG
  19239. NTHALAPI
  19240. ULONG
  19241. HalSetBusData(
  19242. IN BUS_DATA_TYPE BusDataType,
  19243. IN ULONG BusNumber,
  19244. IN ULONG SlotNumber,
  19245. IN PVOID Buffer,
  19246. IN ULONG Length
  19247. );
  19248. #endif // NO_LEGACY_DRIVERS
  19249. DECLSPEC_DEPRECATED_DDK // Use IRP_MN_QUERY_INTERFACE and IRP_MN_READ_CONFIG
  19250. NTHALAPI
  19251. ULONG
  19252. HalSetBusDataByOffset(
  19253. IN BUS_DATA_TYPE BusDataType,
  19254. IN ULONG BusNumber,
  19255. IN ULONG SlotNumber,
  19256. IN PVOID Buffer,
  19257. IN ULONG Offset,
  19258. IN ULONG Length
  19259. );
  19260. DECLSPEC_DEPRECATED_DDK // Use IRP_MN_QUERY_INTERFACE and IRP_MN_READ_CONFIG
  19261. NTHALAPI
  19262. BOOLEAN
  19263. HalTranslateBusAddress(
  19264. IN INTERFACE_TYPE InterfaceType,
  19265. IN ULONG BusNumber,
  19266. IN PHYSICAL_ADDRESS BusAddress,
  19267. IN OUT PULONG AddressSpace,
  19268. OUT PPHYSICAL_ADDRESS TranslatedAddress
  19269. );
  19270. //
  19271. // Values for AddressSpace parameter of HalTranslateBusAddress
  19272. //
  19273. // 0x0 - Memory space
  19274. // 0x1 - Port space
  19275. // 0x2 - 0x1F - Address spaces specific for Alpha
  19276. // 0x2 - UserMode view of memory space
  19277. // 0x3 - UserMode view of port space
  19278. // 0x4 - Dense memory space
  19279. // 0x5 - reserved
  19280. // 0x6 - UserMode view of dense memory space
  19281. // 0x7 - 0x1F - reserved
  19282. //
  19283. NTHALAPI
  19284. PVOID
  19285. HalAllocateCrashDumpRegisters(
  19286. IN PADAPTER_OBJECT AdapterObject,
  19287. IN OUT PULONG NumberOfMapRegisters
  19288. );
  19289. #if !defined(NO_LEGACY_DRIVERS)
  19290. DECLSPEC_DEPRECATED_DDK // Use IRP_MN_QUERY_INTERFACE and IRP_MN_READ_CONFIG
  19291. NTHALAPI
  19292. ULONG
  19293. HalGetBusData(
  19294. IN BUS_DATA_TYPE BusDataType,
  19295. IN ULONG BusNumber,
  19296. IN ULONG SlotNumber,
  19297. IN PVOID Buffer,
  19298. IN ULONG Length
  19299. );
  19300. #endif // NO_LEGACY_DRIVERS
  19301. DECLSPEC_DEPRECATED_DDK // Use IRP_MN_QUERY_INTERFACE and IRP_MN_READ_CONFIG
  19302. NTHALAPI
  19303. ULONG
  19304. HalGetBusDataByOffset(
  19305. IN BUS_DATA_TYPE BusDataType,
  19306. IN ULONG BusNumber,
  19307. IN ULONG SlotNumber,
  19308. IN PVOID Buffer,
  19309. IN ULONG Offset,
  19310. IN ULONG Length
  19311. );
  19312. DECLSPEC_DEPRECATED_DDK // Use IoGetDmaAdapter
  19313. NTHALAPI
  19314. PADAPTER_OBJECT
  19315. HalGetAdapter(
  19316. IN PDEVICE_DESCRIPTION DeviceDescription,
  19317. IN OUT PULONG NumberOfMapRegisters
  19318. );
  19319. // end_ntddk end_ntosp
  19320. #if !defined(NO_LEGACY_DRIVERS)
  19321. NTHALAPI
  19322. NTSTATUS
  19323. HalAdjustResourceList (
  19324. IN OUT PIO_RESOURCE_REQUIREMENTS_LIST *pResourceList
  19325. );
  19326. #endif // NO_LEGACY_DRIVERS
  19327. // begin_ntddk begin_ntosp
  19328. //
  19329. // System beep functions.
  19330. //
  19331. #if !defined(NO_LEGACY_DRIVERS)
  19332. DECLSPEC_DEPRECATED_DDK
  19333. NTHALAPI
  19334. BOOLEAN
  19335. HalMakeBeep(
  19336. IN ULONG Frequency
  19337. );
  19338. #endif // NO_LEGACY_DRIVERS
  19339. //
  19340. // The following function prototypes are for HAL routines with a prefix of Io.
  19341. //
  19342. // DMA adapter object functions.
  19343. //
  19344. // end_ntddk end_ntosp
  19345. //
  19346. // Multi-Processorfunctions.
  19347. //
  19348. NTHALAPI
  19349. BOOLEAN
  19350. HalAllProcessorsStarted (
  19351. VOID
  19352. );
  19353. NTHALAPI
  19354. VOID
  19355. HalInitializeProcessor (
  19356. IN ULONG Number,
  19357. IN PLOADER_PARAMETER_BLOCK LoaderBlock
  19358. );
  19359. NTHALAPI
  19360. BOOLEAN
  19361. HalStartNextProcessor (
  19362. IN PLOADER_PARAMETER_BLOCK LoaderBlock,
  19363. IN PKPROCESSOR_STATE ProcessorState
  19364. );
  19365. NTHALAPI
  19366. VOID
  19367. HalRequestIpi (
  19368. IN KAFFINITY Mask
  19369. );
  19370. //
  19371. // The following function prototypes are for HAL routines with a prefix of Kd.
  19372. //
  19373. // Kernel debugger port functions.
  19374. //
  19375. NTHALAPI
  19376. BOOLEAN
  19377. KdPortInitialize (
  19378. PDEBUG_PARAMETERS DebugParameters,
  19379. PLOADER_PARAMETER_BLOCK LoaderBlock,
  19380. BOOLEAN Initialize
  19381. );
  19382. NTHALAPI
  19383. ULONG
  19384. KdPortGetByte (
  19385. OUT PUCHAR Input
  19386. );
  19387. NTHALAPI
  19388. ULONG
  19389. KdPortPollByte (
  19390. OUT PUCHAR Input
  19391. );
  19392. NTHALAPI
  19393. VOID
  19394. KdPortPutByte (
  19395. IN UCHAR Output
  19396. );
  19397. NTHALAPI
  19398. VOID
  19399. KdPortRestore (
  19400. VOID
  19401. );
  19402. NTHALAPI
  19403. VOID
  19404. KdPortSave (
  19405. VOID
  19406. );
  19407. //
  19408. // The following function prototypes are for HAL routines with a prefix of Ke.
  19409. //
  19410. // begin_ntddk begin_ntifs begin_wdm begin_ntosp
  19411. //
  19412. // Performance counter function.
  19413. //
  19414. NTHALAPI
  19415. LARGE_INTEGER
  19416. KeQueryPerformanceCounter (
  19417. OUT PLARGE_INTEGER PerformanceFrequency OPTIONAL
  19418. );
  19419. // begin_ntndis
  19420. //
  19421. // Stall processor execution function.
  19422. //
  19423. NTHALAPI
  19424. VOID
  19425. KeStallExecutionProcessor (
  19426. IN ULONG MicroSeconds
  19427. );
  19428. // end_ntddk end_ntifs end_wdm end_ntndis end_ntosp
  19429. //*****************************************************************************
  19430. //
  19431. // HAL BUS EXTENDERS
  19432. //
  19433. // Bus handlers
  19434. //
  19435. // begin_ntddk
  19436. typedef
  19437. VOID
  19438. (*PDEVICE_CONTROL_COMPLETION)(
  19439. IN struct _DEVICE_CONTROL_CONTEXT *ControlContext
  19440. );
  19441. typedef struct _DEVICE_CONTROL_CONTEXT {
  19442. NTSTATUS Status;
  19443. PDEVICE_HANDLER_OBJECT DeviceHandler;
  19444. PDEVICE_OBJECT DeviceObject;
  19445. ULONG ControlCode;
  19446. PVOID Buffer;
  19447. PULONG BufferLength;
  19448. PVOID Context;
  19449. } DEVICE_CONTROL_CONTEXT, *PDEVICE_CONTROL_CONTEXT;
  19450. // end_ntddk
  19451. typedef struct _HAL_DEVICE_CONTROL {
  19452. //
  19453. // Handler this DeviceControl is for
  19454. //
  19455. struct _BUS_HANDLER *Handler;
  19456. struct _BUS_HANDLER *RootHandler;
  19457. //
  19458. // Bus specific storage for this Context
  19459. //
  19460. PVOID BusExtensionData;
  19461. //
  19462. // Reserved for HALs use
  19463. //
  19464. ULONG HalReserved[4];
  19465. //
  19466. // Reserved for BusExtneder use
  19467. //
  19468. ULONG BusExtenderReserved[4];
  19469. //
  19470. // DeviceControl Context and the CompletionRoutine
  19471. //
  19472. PDEVICE_CONTROL_COMPLETION CompletionRoutine;
  19473. DEVICE_CONTROL_CONTEXT DeviceControl;
  19474. } HAL_DEVICE_CONTROL_CONTEXT, *PHAL_DEVICE_CONTROL_CONTEXT;
  19475. typedef
  19476. ULONG
  19477. (*PGETSETBUSDATA)(
  19478. IN struct _BUS_HANDLER *BusHandler,
  19479. IN struct _BUS_HANDLER *RootHandler,
  19480. IN ULONG SlotNumber,
  19481. IN PVOID Buffer,
  19482. IN ULONG Offset,
  19483. IN ULONG Length
  19484. );
  19485. typedef
  19486. ULONG
  19487. (*PGETINTERRUPTVECTOR)(
  19488. IN struct _BUS_HANDLER *BusHandler,
  19489. IN struct _BUS_HANDLER *RootHandler,
  19490. IN ULONG BusInterruptLevel,
  19491. IN ULONG BusInterruptVector,
  19492. OUT PKIRQL Irql,
  19493. OUT PKAFFINITY Affinity
  19494. );
  19495. typedef
  19496. BOOLEAN
  19497. (*PTRANSLATEBUSADDRESS)(
  19498. IN struct _BUS_HANDLER *BusHandler,
  19499. IN struct _BUS_HANDLER *RootHandler,
  19500. IN PHYSICAL_ADDRESS BusAddress,
  19501. IN OUT PULONG AddressSpace,
  19502. OUT PPHYSICAL_ADDRESS TranslatedAddress
  19503. );
  19504. typedef NTSTATUS
  19505. (*PADJUSTRESOURCELIST)(
  19506. IN struct _BUS_HANDLER *BusHandler,
  19507. IN struct _BUS_HANDLER *RootHandler,
  19508. IN OUT PIO_RESOURCE_REQUIREMENTS_LIST *pResourceList
  19509. );
  19510. typedef PDEVICE_HANDLER_OBJECT
  19511. (*PREFERENCE_DEVICE_HANDLER)(
  19512. IN struct _BUS_HANDLER *BusHandler,
  19513. IN struct _BUS_HANDLER *RootHandler,
  19514. IN ULONG SlotNumber
  19515. );
  19516. //typedef VOID
  19517. //(*PDEREFERENCE_DEVICE_HANDLER)(
  19518. // IN PDEVICE_HANDLER_OBJECT DeviceHandler
  19519. // );
  19520. typedef NTSTATUS
  19521. (*PASSIGNSLOTRESOURCES)(
  19522. IN struct _BUS_HANDLER *BusHandler,
  19523. IN struct _BUS_HANDLER *RootHandler,
  19524. IN PUNICODE_STRING RegistryPath,
  19525. IN PUNICODE_STRING DriverClassName OPTIONAL,
  19526. IN PDRIVER_OBJECT DriverObject,
  19527. IN PDEVICE_OBJECT DeviceObject OPTIONAL,
  19528. IN ULONG SlotNumber,
  19529. IN OUT PCM_RESOURCE_LIST *AllocatedResources
  19530. );
  19531. typedef
  19532. NTSTATUS
  19533. (*PQUERY_BUS_SLOTS)(
  19534. IN struct _BUS_HANDLER *BusHandler,
  19535. IN struct _BUS_HANDLER *RootHandler,
  19536. IN ULONG BufferSize,
  19537. OUT PULONG SlotNumbers,
  19538. OUT PULONG ReturnedLength
  19539. );
  19540. typedef ULONG
  19541. (*PGET_SET_DEVICE_INSTANCE_DATA)(
  19542. IN struct _BUS_HANDLER *BusHandler,
  19543. IN struct _BUS_HANDLER *RootHandler,
  19544. IN PDEVICE_HANDLER_OBJECT DeviceHandler,
  19545. IN ULONG DataType,
  19546. IN PVOID Buffer,
  19547. IN ULONG Offset,
  19548. IN ULONG Length
  19549. );
  19550. typedef
  19551. NTSTATUS
  19552. (*PDEVICE_CONTROL)(
  19553. IN PHAL_DEVICE_CONTROL_CONTEXT Context
  19554. );
  19555. typedef
  19556. NTSTATUS
  19557. (*PHIBERNATEBRESUMEBUS)(
  19558. IN struct _BUS_HANDLER *BusHandler,
  19559. IN struct _BUS_HANDLER *RootHandler
  19560. );
  19561. //
  19562. // Supported range structures
  19563. //
  19564. #define BUS_SUPPORTED_RANGE_VERSION 1
  19565. typedef struct _SUPPORTED_RANGE {
  19566. struct _SUPPORTED_RANGE *Next;
  19567. ULONG SystemAddressSpace;
  19568. LONGLONG SystemBase;
  19569. LONGLONG Base;
  19570. LONGLONG Limit;
  19571. } SUPPORTED_RANGE, *PSUPPORTED_RANGE;
  19572. typedef struct _SUPPORTED_RANGES {
  19573. USHORT Version;
  19574. BOOLEAN Sorted;
  19575. UCHAR Reserved;
  19576. ULONG NoIO;
  19577. SUPPORTED_RANGE IO;
  19578. ULONG NoMemory;
  19579. SUPPORTED_RANGE Memory;
  19580. ULONG NoPrefetchMemory;
  19581. SUPPORTED_RANGE PrefetchMemory;
  19582. ULONG NoDma;
  19583. SUPPORTED_RANGE Dma;
  19584. } SUPPORTED_RANGES, *PSUPPORTED_RANGES;
  19585. //
  19586. // Bus handler structure
  19587. //
  19588. #define BUS_HANDLER_VERSION 1
  19589. typedef struct _BUS_HANDLER {
  19590. //
  19591. // Version of structure
  19592. //
  19593. ULONG Version;
  19594. //
  19595. // This bus handler structure is for the following bus
  19596. //
  19597. INTERFACE_TYPE InterfaceType;
  19598. BUS_DATA_TYPE ConfigurationType;
  19599. ULONG BusNumber;
  19600. //
  19601. // Device object for this bus extender, or NULL if it is
  19602. // a hal internal bus extender
  19603. //
  19604. PDEVICE_OBJECT DeviceObject;
  19605. //
  19606. // The parent handlers for this bus
  19607. //
  19608. struct _BUS_HANDLER *ParentHandler;
  19609. //
  19610. // Bus specific strorage
  19611. //
  19612. PVOID BusData;
  19613. //
  19614. // Amount of bus specific storage needed for DeviceControl function calls
  19615. //
  19616. ULONG DeviceControlExtensionSize;
  19617. //
  19618. // Supported address ranges this bus allows
  19619. //
  19620. PSUPPORTED_RANGES BusAddresses;
  19621. //
  19622. // For future use
  19623. //
  19624. ULONG Reserved[4];
  19625. //
  19626. // Handlers for this bus
  19627. //
  19628. PGETSETBUSDATA GetBusData;
  19629. PGETSETBUSDATA SetBusData;
  19630. PADJUSTRESOURCELIST AdjustResourceList;
  19631. PASSIGNSLOTRESOURCES AssignSlotResources;
  19632. PGETINTERRUPTVECTOR GetInterruptVector;
  19633. PTRANSLATEBUSADDRESS TranslateBusAddress;
  19634. PVOID Spare1;
  19635. PVOID Spare2;
  19636. PVOID Spare3;
  19637. PVOID Spare4;
  19638. PVOID Spare5;
  19639. PVOID Spare6;
  19640. PVOID Spare7;
  19641. PVOID Spare8;
  19642. } BUS_HANDLER, *PBUS_HANDLER;
  19643. VOID
  19644. HalpInitBusHandler (
  19645. VOID
  19646. );
  19647. // begin_ntosp
  19648. typedef
  19649. NTSTATUS
  19650. (*PINSTALL_BUS_HANDLER)(
  19651. IN PBUS_HANDLER Bus
  19652. );
  19653. typedef
  19654. NTSTATUS
  19655. (*pHalRegisterBusHandler)(
  19656. IN INTERFACE_TYPE InterfaceType,
  19657. IN BUS_DATA_TYPE AssociatedConfigurationSpace,
  19658. IN ULONG BusNumber,
  19659. IN INTERFACE_TYPE ParentBusType,
  19660. IN ULONG ParentBusNumber,
  19661. IN ULONG SizeofBusExtensionData,
  19662. IN PINSTALL_BUS_HANDLER InstallBusHandlers,
  19663. OUT PBUS_HANDLER *BusHandler
  19664. );
  19665. // end_ntosp
  19666. NTSTATUS
  19667. HaliRegisterBusHandler (
  19668. IN INTERFACE_TYPE InterfaceType,
  19669. IN BUS_DATA_TYPE AssociatedConfigurationSpace,
  19670. IN ULONG BusNumber,
  19671. IN INTERFACE_TYPE ParentBusType,
  19672. IN ULONG ParentBusNumber,
  19673. IN ULONG SizeofBusExtensionData,
  19674. IN PINSTALL_BUS_HANDLER InstallBusHandlers,
  19675. OUT PBUS_HANDLER *BusHandler
  19676. );
  19677. // begin_ntddk begin_ntosp
  19678. typedef
  19679. PBUS_HANDLER
  19680. (FASTCALL *pHalHandlerForBus) (
  19681. IN INTERFACE_TYPE InterfaceType,
  19682. IN ULONG BusNumber
  19683. );
  19684. // end_ntddk end_ntosp
  19685. PBUS_HANDLER
  19686. FASTCALL
  19687. HaliReferenceHandlerForBus (
  19688. IN INTERFACE_TYPE InterfaceType,
  19689. IN ULONG BusNumber
  19690. );
  19691. PBUS_HANDLER
  19692. FASTCALL
  19693. HaliHandlerForBus (
  19694. IN INTERFACE_TYPE InterfaceType,
  19695. IN ULONG BusNumber
  19696. );
  19697. typedef VOID
  19698. (FASTCALL *pHalRefernceBusHandler) (
  19699. IN PBUS_HANDLER BusHandler
  19700. );
  19701. VOID
  19702. FASTCALL
  19703. HaliDerefernceBusHandler (
  19704. IN PBUS_HANDLER BusHandler
  19705. );
  19706. // begin_ntosp
  19707. typedef
  19708. PBUS_HANDLER
  19709. (FASTCALL *pHalHandlerForConfigSpace) (
  19710. IN BUS_DATA_TYPE ConfigSpace,
  19711. IN ULONG BusNumber
  19712. );
  19713. // end_ntosp
  19714. PBUS_HANDLER
  19715. FASTCALL
  19716. HaliHandlerForConfigSpace (
  19717. IN BUS_DATA_TYPE ConfigSpace,
  19718. IN ULONG BusNumber
  19719. );
  19720. // begin_ntddk begin_ntosp
  19721. typedef
  19722. VOID
  19723. (FASTCALL *pHalReferenceBusHandler) (
  19724. IN PBUS_HANDLER BusHandler
  19725. );
  19726. // end_ntddk end_ntosp
  19727. VOID
  19728. FASTCALL
  19729. HaliReferenceBusHandler (
  19730. IN PBUS_HANDLER BusHandler
  19731. );
  19732. VOID
  19733. FASTCALL
  19734. HaliDereferenceBusHandler (
  19735. IN PBUS_HANDLER BusHandler
  19736. );
  19737. NTSTATUS
  19738. HaliQueryBusSlots (
  19739. IN PBUS_HANDLER BusHandler,
  19740. IN ULONG BufferSize,
  19741. OUT PULONG SlotNumbers,
  19742. OUT PULONG ReturnedLength
  19743. );
  19744. NTSTATUS
  19745. HaliAdjustResourceListRange (
  19746. IN PSUPPORTED_RANGES SupportedRanges,
  19747. IN PSUPPORTED_RANGE InterruptRanges,
  19748. IN OUT PIO_RESOURCE_REQUIREMENTS_LIST *pResourceList
  19749. );
  19750. VOID
  19751. HaliLocateHiberRanges (
  19752. IN PVOID MemoryMap
  19753. );
  19754. // begin_ntosp
  19755. typedef
  19756. VOID
  19757. (*pHalSetWakeEnable)(
  19758. IN BOOLEAN Enable
  19759. );
  19760. typedef
  19761. VOID
  19762. (*pHalSetWakeAlarm)(
  19763. IN ULONGLONG WakeTime,
  19764. IN PTIME_FIELDS WakeTimeFields
  19765. );
  19766. typedef
  19767. VOID
  19768. (*pHalLocateHiberRanges)(
  19769. IN PVOID MemoryMap
  19770. );
  19771. // begin_ntddk
  19772. //*****************************************************************************
  19773. // HAL Function dispatch
  19774. //
  19775. typedef enum _HAL_QUERY_INFORMATION_CLASS {
  19776. HalInstalledBusInformation,
  19777. HalProfileSourceInformation,
  19778. HalInformationClassUnused1,
  19779. HalPowerInformation,
  19780. HalProcessorSpeedInformation,
  19781. HalCallbackInformation,
  19782. HalMapRegisterInformation,
  19783. HalMcaLogInformation, // Machine Check Abort Information
  19784. HalFrameBufferCachingInformation,
  19785. HalDisplayBiosInformation,
  19786. HalProcessorFeatureInformation,
  19787. HalNumaTopologyInterface,
  19788. HalErrorInformation, // General MCA, CMC, CPE Error Information.
  19789. HalCmcLogInformation, // Processor Corrected Machine Check Information
  19790. HalCpeLogInformation, // Corrected Platform Error Information
  19791. HalQueryMcaInterface,
  19792. HalQueryAMLIIllegalIOPortAddresses,
  19793. HalQueryMaxHotPlugMemoryAddress,
  19794. HalPartitionIpiInterface,
  19795. HalPlatformInformation,
  19796. HalQueryProfileSourceList
  19797. // information levels >= 0x8000000 reserved for OEM use
  19798. } HAL_QUERY_INFORMATION_CLASS, *PHAL_QUERY_INFORMATION_CLASS;
  19799. typedef enum _HAL_SET_INFORMATION_CLASS {
  19800. HalProfileSourceInterval,
  19801. HalProfileSourceInterruptHandler,
  19802. HalMcaRegisterDriver, // Registring Machine Check Abort driver
  19803. HalKernelErrorHandler,
  19804. HalCmcRegisterDriver, // Registring Processor Corrected Machine Check driver
  19805. HalCpeRegisterDriver, // Registring Corrected Platform Error driver
  19806. HalMcaLog,
  19807. HalCmcLog,
  19808. HalCpeLog,
  19809. HalGenerateCmcInterrupt // Used to test CMC
  19810. } HAL_SET_INFORMATION_CLASS, *PHAL_SET_INFORMATION_CLASS;
  19811. typedef
  19812. NTSTATUS
  19813. (*pHalQuerySystemInformation)(
  19814. IN HAL_QUERY_INFORMATION_CLASS InformationClass,
  19815. IN ULONG BufferSize,
  19816. IN OUT PVOID Buffer,
  19817. OUT PULONG ReturnedLength
  19818. );
  19819. // end_ntddk
  19820. NTSTATUS
  19821. HaliQuerySystemInformation(
  19822. IN HAL_SET_INFORMATION_CLASS InformationClass,
  19823. IN ULONG BufferSize,
  19824. IN OUT PVOID Buffer,
  19825. OUT PULONG ReturnedLength
  19826. );
  19827. NTSTATUS
  19828. HaliHandlePCIConfigSpaceAccess(
  19829. IN BOOLEAN Read,
  19830. IN ULONG Addr,
  19831. IN ULONG Size,
  19832. IN OUT PULONG pData
  19833. );
  19834. //begin_ntddk
  19835. typedef
  19836. NTSTATUS
  19837. (*pHalSetSystemInformation)(
  19838. IN HAL_SET_INFORMATION_CLASS InformationClass,
  19839. IN ULONG BufferSize,
  19840. IN PVOID Buffer
  19841. );
  19842. // end_ntddk
  19843. NTSTATUS
  19844. HaliSetSystemInformation(
  19845. IN HAL_SET_INFORMATION_CLASS InformationClass,
  19846. IN ULONG BufferSize,
  19847. IN PVOID Buffer
  19848. );
  19849. // begin_ntddk
  19850. typedef
  19851. VOID
  19852. (FASTCALL *pHalExamineMBR)(
  19853. IN PDEVICE_OBJECT DeviceObject,
  19854. IN ULONG SectorSize,
  19855. IN ULONG MBRTypeIdentifier,
  19856. OUT PVOID *Buffer
  19857. );
  19858. typedef
  19859. VOID
  19860. (FASTCALL *pHalIoAssignDriveLetters)(
  19861. IN struct _LOADER_PARAMETER_BLOCK *LoaderBlock,
  19862. IN PSTRING NtDeviceName,
  19863. OUT PUCHAR NtSystemPath,
  19864. OUT PSTRING NtSystemPathString
  19865. );
  19866. typedef
  19867. NTSTATUS
  19868. (FASTCALL *pHalIoReadPartitionTable)(
  19869. IN PDEVICE_OBJECT DeviceObject,
  19870. IN ULONG SectorSize,
  19871. IN BOOLEAN ReturnRecognizedPartitions,
  19872. OUT struct _DRIVE_LAYOUT_INFORMATION **PartitionBuffer
  19873. );
  19874. typedef
  19875. NTSTATUS
  19876. (FASTCALL *pHalIoSetPartitionInformation)(
  19877. IN PDEVICE_OBJECT DeviceObject,
  19878. IN ULONG SectorSize,
  19879. IN ULONG PartitionNumber,
  19880. IN ULONG PartitionType
  19881. );
  19882. typedef
  19883. NTSTATUS
  19884. (FASTCALL *pHalIoWritePartitionTable)(
  19885. IN PDEVICE_OBJECT DeviceObject,
  19886. IN ULONG SectorSize,
  19887. IN ULONG SectorsPerTrack,
  19888. IN ULONG NumberOfHeads,
  19889. IN struct _DRIVE_LAYOUT_INFORMATION *PartitionBuffer
  19890. );
  19891. typedef
  19892. NTSTATUS
  19893. (*pHalQueryBusSlots)(
  19894. IN PBUS_HANDLER BusHandler,
  19895. IN ULONG BufferSize,
  19896. OUT PULONG SlotNumbers,
  19897. OUT PULONG ReturnedLength
  19898. );
  19899. typedef
  19900. NTSTATUS
  19901. (*pHalInitPnpDriver)(
  19902. VOID
  19903. );
  19904. // end_ntddk
  19905. NTSTATUS
  19906. HaliInitPnpDriver(
  19907. VOID
  19908. );
  19909. // begin_ntddk
  19910. typedef struct _PM_DISPATCH_TABLE {
  19911. ULONG Signature;
  19912. ULONG Version;
  19913. PVOID Function[1];
  19914. } PM_DISPATCH_TABLE, *PPM_DISPATCH_TABLE;
  19915. typedef
  19916. NTSTATUS
  19917. (*pHalInitPowerManagement)(
  19918. IN PPM_DISPATCH_TABLE PmDriverDispatchTable,
  19919. OUT PPM_DISPATCH_TABLE *PmHalDispatchTable
  19920. );
  19921. // end_ntddk
  19922. NTSTATUS
  19923. HaliInitPowerManagement(
  19924. IN PPM_DISPATCH_TABLE PmDriverDispatchTable,
  19925. IN OUT PPM_DISPATCH_TABLE *PmHalDispatchTable
  19926. );
  19927. // begin_ntddk
  19928. typedef
  19929. struct _DMA_ADAPTER *
  19930. (*pHalGetDmaAdapter)(
  19931. IN PVOID Context,
  19932. IN struct _DEVICE_DESCRIPTION *DeviceDescriptor,
  19933. OUT PULONG NumberOfMapRegisters
  19934. );
  19935. // end_ntddk
  19936. struct _DMA_ADAPTER *
  19937. HaliGetDmaAdapter(
  19938. IN PVOID Context,
  19939. IN struct _DEVICE_DESCRIPTION *DeviceDescriptor,
  19940. OUT PULONG NumberOfMapRegisters
  19941. );
  19942. // begin_ntddk
  19943. typedef
  19944. NTSTATUS
  19945. (*pHalGetInterruptTranslator)(
  19946. IN INTERFACE_TYPE ParentInterfaceType,
  19947. IN ULONG ParentBusNumber,
  19948. IN INTERFACE_TYPE BridgeInterfaceType,
  19949. IN USHORT Size,
  19950. IN USHORT Version,
  19951. OUT PTRANSLATOR_INTERFACE Translator,
  19952. OUT PULONG BridgeBusNumber
  19953. );
  19954. // end_ntddk
  19955. NTSTATUS
  19956. HaliGetInterruptTranslator(
  19957. IN INTERFACE_TYPE ParentInterfaceType,
  19958. IN ULONG ParentBusNumber,
  19959. IN INTERFACE_TYPE BridgeInterfaceType,
  19960. IN USHORT Size,
  19961. IN USHORT Version,
  19962. OUT PTRANSLATOR_INTERFACE Translator,
  19963. OUT PULONG BridgeBusNumber
  19964. );
  19965. // begin_ntddk
  19966. typedef
  19967. BOOLEAN
  19968. (*pHalTranslateBusAddress)(
  19969. IN INTERFACE_TYPE InterfaceType,
  19970. IN ULONG BusNumber,
  19971. IN PHYSICAL_ADDRESS BusAddress,
  19972. IN OUT PULONG AddressSpace,
  19973. OUT PPHYSICAL_ADDRESS TranslatedAddress
  19974. );
  19975. typedef
  19976. NTSTATUS
  19977. (*pHalAssignSlotResources) (
  19978. IN PUNICODE_STRING RegistryPath,
  19979. IN PUNICODE_STRING DriverClassName OPTIONAL,
  19980. IN PDRIVER_OBJECT DriverObject,
  19981. IN PDEVICE_OBJECT DeviceObject,
  19982. IN INTERFACE_TYPE BusType,
  19983. IN ULONG BusNumber,
  19984. IN ULONG SlotNumber,
  19985. IN OUT PCM_RESOURCE_LIST *AllocatedResources
  19986. );
  19987. typedef
  19988. VOID
  19989. (*pHalHaltSystem) (
  19990. VOID
  19991. );
  19992. typedef
  19993. BOOLEAN
  19994. (*pHalResetDisplay) (
  19995. VOID
  19996. );
  19997. // begin_ntndis
  19998. typedef struct _MAP_REGISTER_ENTRY {
  19999. PVOID MapRegister;
  20000. BOOLEAN WriteToDevice;
  20001. } MAP_REGISTER_ENTRY, *PMAP_REGISTER_ENTRY;
  20002. // end_ntndis
  20003. // end_ntddk
  20004. typedef
  20005. NTSTATUS
  20006. (*pHalAllocateMapRegisters)(
  20007. IN struct _ADAPTER_OBJECT *DmaAdapter,
  20008. IN ULONG NumberOfMapRegisters,
  20009. IN ULONG BaseAddressCount,
  20010. OUT PMAP_REGISTER_ENTRY MapRegsiterArray
  20011. );
  20012. NTSTATUS
  20013. HalAllocateMapRegisters(
  20014. IN struct _ADAPTER_OBJECT *DmaAdapter,
  20015. IN ULONG NumberOfMapRegisters,
  20016. IN ULONG BaseAddressCount,
  20017. OUT PMAP_REGISTER_ENTRY MapRegsiterArray
  20018. );
  20019. // begin_ntddk
  20020. typedef
  20021. UCHAR
  20022. (*pHalVectorToIDTEntry) (
  20023. ULONG Vector
  20024. );
  20025. typedef
  20026. BOOLEAN
  20027. (*pHalFindBusAddressTranslation) (
  20028. IN PHYSICAL_ADDRESS BusAddress,
  20029. IN OUT PULONG AddressSpace,
  20030. OUT PPHYSICAL_ADDRESS TranslatedAddress,
  20031. IN OUT PULONG_PTR Context,
  20032. IN BOOLEAN NextBus
  20033. );
  20034. typedef
  20035. NTSTATUS
  20036. (*pHalStartMirroring)(
  20037. VOID
  20038. );
  20039. typedef
  20040. NTSTATUS
  20041. (*pHalEndMirroring)(
  20042. IN ULONG PassNumber
  20043. );
  20044. typedef
  20045. NTSTATUS
  20046. (*pHalMirrorPhysicalMemory)(
  20047. IN PHYSICAL_ADDRESS PhysicalAddress,
  20048. IN LARGE_INTEGER NumberOfBytes
  20049. );
  20050. typedef
  20051. NTSTATUS
  20052. (*pHalMirrorVerify)(
  20053. IN PHYSICAL_ADDRESS PhysicalAddress,
  20054. IN LARGE_INTEGER NumberOfBytes
  20055. );
  20056. typedef struct {
  20057. UCHAR Type; //CmResourceType
  20058. BOOLEAN Valid;
  20059. UCHAR Reserved[2];
  20060. PUCHAR TranslatedAddress;
  20061. ULONG Length;
  20062. } DEBUG_DEVICE_ADDRESS, *PDEBUG_DEVICE_ADDRESS;
  20063. typedef struct {
  20064. PHYSICAL_ADDRESS Start;
  20065. PHYSICAL_ADDRESS MaxEnd;
  20066. PVOID VirtualAddress;
  20067. ULONG Length;
  20068. BOOLEAN Cached;
  20069. BOOLEAN Aligned;
  20070. } DEBUG_MEMORY_REQUIREMENTS, *PDEBUG_MEMORY_REQUIREMENTS;
  20071. typedef struct {
  20072. ULONG Bus;
  20073. ULONG Slot;
  20074. USHORT VendorID;
  20075. USHORT DeviceID;
  20076. UCHAR BaseClass;
  20077. UCHAR SubClass;
  20078. UCHAR ProgIf;
  20079. BOOLEAN Initialized;
  20080. DEBUG_DEVICE_ADDRESS BaseAddress[6];
  20081. DEBUG_MEMORY_REQUIREMENTS Memory;
  20082. } DEBUG_DEVICE_DESCRIPTOR, *PDEBUG_DEVICE_DESCRIPTOR;
  20083. typedef
  20084. NTSTATUS
  20085. (*pKdSetupPciDeviceForDebugging)(
  20086. IN PVOID LoaderBlock, OPTIONAL
  20087. IN OUT PDEBUG_DEVICE_DESCRIPTOR PciDevice
  20088. );
  20089. typedef
  20090. NTSTATUS
  20091. (*pKdReleasePciDeviceForDebugging)(
  20092. IN OUT PDEBUG_DEVICE_DESCRIPTOR PciDevice
  20093. );
  20094. typedef
  20095. PVOID
  20096. (*pKdGetAcpiTablePhase0)(
  20097. IN struct _LOADER_PARAMETER_BLOCK *LoaderBlock,
  20098. IN ULONG Signature
  20099. );
  20100. typedef
  20101. VOID
  20102. (*pKdCheckPowerButton)(
  20103. VOID
  20104. );
  20105. typedef
  20106. VOID
  20107. (*pHalEndOfBoot)(
  20108. VOID
  20109. );
  20110. typedef
  20111. PVOID
  20112. (*pKdMapPhysicalMemory64)(
  20113. IN PHYSICAL_ADDRESS PhysicalAddress,
  20114. IN ULONG NumberPages
  20115. );
  20116. typedef
  20117. VOID
  20118. (*pKdUnmapVirtualAddress)(
  20119. IN PVOID VirtualAddress,
  20120. IN ULONG NumberPages
  20121. );
  20122. typedef struct {
  20123. ULONG Version;
  20124. pHalQuerySystemInformation HalQuerySystemInformation;
  20125. pHalSetSystemInformation HalSetSystemInformation;
  20126. pHalQueryBusSlots HalQueryBusSlots;
  20127. ULONG Spare1;
  20128. pHalExamineMBR HalExamineMBR;
  20129. pHalIoAssignDriveLetters HalIoAssignDriveLetters;
  20130. pHalIoReadPartitionTable HalIoReadPartitionTable;
  20131. pHalIoSetPartitionInformation HalIoSetPartitionInformation;
  20132. pHalIoWritePartitionTable HalIoWritePartitionTable;
  20133. pHalHandlerForBus HalReferenceHandlerForBus;
  20134. pHalReferenceBusHandler HalReferenceBusHandler;
  20135. pHalReferenceBusHandler HalDereferenceBusHandler;
  20136. pHalInitPnpDriver HalInitPnpDriver;
  20137. pHalInitPowerManagement HalInitPowerManagement;
  20138. pHalGetDmaAdapter HalGetDmaAdapter;
  20139. pHalGetInterruptTranslator HalGetInterruptTranslator;
  20140. pHalStartMirroring HalStartMirroring;
  20141. pHalEndMirroring HalEndMirroring;
  20142. pHalMirrorPhysicalMemory HalMirrorPhysicalMemory;
  20143. pHalEndOfBoot HalEndOfBoot;
  20144. pHalMirrorVerify HalMirrorVerify;
  20145. } HAL_DISPATCH, *PHAL_DISPATCH;
  20146. #if defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_) || defined(_NTHAL_)
  20147. extern PHAL_DISPATCH HalDispatchTable;
  20148. #define HALDISPATCH HalDispatchTable
  20149. #else
  20150. extern HAL_DISPATCH HalDispatchTable;
  20151. #define HALDISPATCH (&HalDispatchTable)
  20152. #endif
  20153. #define HAL_DISPATCH_VERSION 3
  20154. #define HalDispatchTableVersion HALDISPATCH->Version
  20155. #define HalQuerySystemInformation HALDISPATCH->HalQuerySystemInformation
  20156. #define HalSetSystemInformation HALDISPATCH->HalSetSystemInformation
  20157. #define HalQueryBusSlots HALDISPATCH->HalQueryBusSlots
  20158. #define HalReferenceHandlerForBus HALDISPATCH->HalReferenceHandlerForBus
  20159. #define HalReferenceBusHandler HALDISPATCH->HalReferenceBusHandler
  20160. #define HalDereferenceBusHandler HALDISPATCH->HalDereferenceBusHandler
  20161. #define HalInitPnpDriver HALDISPATCH->HalInitPnpDriver
  20162. #define HalInitPowerManagement HALDISPATCH->HalInitPowerManagement
  20163. #define HalGetDmaAdapter HALDISPATCH->HalGetDmaAdapter
  20164. #define HalGetInterruptTranslator HALDISPATCH->HalGetInterruptTranslator
  20165. #define HalStartMirroring HALDISPATCH->HalStartMirroring
  20166. #define HalEndMirroring HALDISPATCH->HalEndMirroring
  20167. #define HalMirrorPhysicalMemory HALDISPATCH->HalMirrorPhysicalMemory
  20168. #define HalEndOfBoot HALDISPATCH->HalEndOfBoot
  20169. #define HalMirrorVerify HALDISPATCH->HalMirrorVerify
  20170. // end_ntddk
  20171. typedef struct {
  20172. ULONG Version;
  20173. pHalHandlerForBus HalHandlerForBus;
  20174. pHalHandlerForConfigSpace HalHandlerForConfigSpace;
  20175. pHalLocateHiberRanges HalLocateHiberRanges;
  20176. pHalRegisterBusHandler HalRegisterBusHandler;
  20177. pHalSetWakeEnable HalSetWakeEnable;
  20178. pHalSetWakeAlarm HalSetWakeAlarm;
  20179. pHalTranslateBusAddress HalPciTranslateBusAddress;
  20180. pHalAssignSlotResources HalPciAssignSlotResources;
  20181. pHalHaltSystem HalHaltSystem;
  20182. pHalFindBusAddressTranslation HalFindBusAddressTranslation;
  20183. pHalResetDisplay HalResetDisplay;
  20184. pHalAllocateMapRegisters HalAllocateMapRegisters;
  20185. pKdSetupPciDeviceForDebugging KdSetupPciDeviceForDebugging;
  20186. pKdReleasePciDeviceForDebugging KdReleasePciDeviceForDebugging;
  20187. pKdGetAcpiTablePhase0 KdGetAcpiTablePhase0;
  20188. pKdCheckPowerButton KdCheckPowerButton;
  20189. pHalVectorToIDTEntry HalVectorToIDTEntry;
  20190. pKdMapPhysicalMemory64 KdMapPhysicalMemory64;
  20191. pKdUnmapVirtualAddress KdUnmapVirtualAddress;
  20192. } HAL_PRIVATE_DISPATCH, *PHAL_PRIVATE_DISPATCH;
  20193. #if defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_) || defined(_NTHAL_)
  20194. extern PHAL_PRIVATE_DISPATCH HalPrivateDispatchTable;
  20195. #define HALPDISPATCH HalPrivateDispatchTable
  20196. #else
  20197. extern HAL_PRIVATE_DISPATCH HalPrivateDispatchTable;
  20198. #define HALPDISPATCH (&HalPrivateDispatchTable)
  20199. #endif
  20200. #define HAL_PRIVATE_DISPATCH_VERSION 2
  20201. #define HalRegisterBusHandler HALPDISPATCH->HalRegisterBusHandler
  20202. #define HalHandlerForBus HALPDISPATCH->HalHandlerForBus
  20203. #define HalHandlerForConfigSpace HALPDISPATCH->HalHandlerForConfigSpace
  20204. #define HalLocateHiberRanges HALPDISPATCH->HalLocateHiberRanges
  20205. #define HalSetWakeEnable HALPDISPATCH->HalSetWakeEnable
  20206. #define HalSetWakeAlarm HALPDISPATCH->HalSetWakeAlarm
  20207. #define HalHaltSystem HALPDISPATCH->HalHaltSystem
  20208. #define HalResetDisplay HALPDISPATCH->HalResetDisplay
  20209. #define HalAllocateMapRegisters HALPDISPATCH->HalAllocateMapRegisters
  20210. #define KdSetupPciDeviceForDebugging HALPDISPATCH->KdSetupPciDeviceForDebugging
  20211. #define KdReleasePciDeviceForDebugging HALPDISPATCH->KdReleasePciDeviceForDebugging
  20212. #define KdGetAcpiTablePhase0 HALPDISPATCH->KdGetAcpiTablePhase0
  20213. #define KdCheckPowerButton HALPDISPATCH->KdCheckPowerButton
  20214. #define HalVectorToIDTEntry HALPDISPATCH->HalVectorToIDTEntry
  20215. #define KdMapPhysicalMemory64 HALPDISPATCH->KdMapPhysicalMemory64
  20216. #define KdUnmapVirtualAddress HALPDISPATCH->KdUnmapVirtualAddress
  20217. // begin_ntddk
  20218. //
  20219. // HAL System Information Structures.
  20220. //
  20221. // for the information class "HalInstalledBusInformation"
  20222. typedef struct _HAL_BUS_INFORMATION{
  20223. INTERFACE_TYPE BusType;
  20224. BUS_DATA_TYPE ConfigurationType;
  20225. ULONG BusNumber;
  20226. ULONG Reserved;
  20227. } HAL_BUS_INFORMATION, *PHAL_BUS_INFORMATION;
  20228. // for the information class "HalProfileSourceInformation"
  20229. typedef struct _HAL_PROFILE_SOURCE_INFORMATION {
  20230. KPROFILE_SOURCE Source;
  20231. BOOLEAN Supported;
  20232. ULONG Interval;
  20233. } HAL_PROFILE_SOURCE_INFORMATION, *PHAL_PROFILE_SOURCE_INFORMATION;
  20234. // for the information class "HalProfileSourceInformation"
  20235. typedef struct _HAL_PROFILE_SOURCE_INFORMATION_EX {
  20236. KPROFILE_SOURCE Source;
  20237. BOOLEAN Supported;
  20238. ULONG_PTR Interval;
  20239. ULONG_PTR DefInterval;
  20240. ULONG_PTR MaxInterval;
  20241. ULONG_PTR MinInterval;
  20242. } HAL_PROFILE_SOURCE_INFORMATION_EX, *PHAL_PROFILE_SOURCE_INFORMATION_EX;
  20243. // for the information class "HalProfileSourceInterval"
  20244. typedef struct _HAL_PROFILE_SOURCE_INTERVAL {
  20245. KPROFILE_SOURCE Source;
  20246. ULONG_PTR Interval;
  20247. } HAL_PROFILE_SOURCE_INTERVAL, *PHAL_PROFILE_SOURCE_INTERVAL;
  20248. // for the information class "HalQueryProfileSourceList"
  20249. typedef struct _HAL_PROFILE_SOURCE_LIST {
  20250. KPROFILE_SOURCE Source;
  20251. PWSTR Description;
  20252. } HAL_PROFILE_SOURCE_LIST, *PHAL_PROFILE_SOURCE_LIST;
  20253. // for the information class "HalDispayBiosInformation"
  20254. typedef enum _HAL_DISPLAY_BIOS_INFORMATION {
  20255. HalDisplayInt10Bios,
  20256. HalDisplayEmulatedBios,
  20257. HalDisplayNoBios
  20258. } HAL_DISPLAY_BIOS_INFORMATION, *PHAL_DISPLAY_BIOS_INFORMATION;
  20259. // for the information class "HalPowerInformation"
  20260. typedef struct _HAL_POWER_INFORMATION {
  20261. ULONG TBD;
  20262. } HAL_POWER_INFORMATION, *PHAL_POWER_INFORMATION;
  20263. // for the information class "HalProcessorSpeedInformation"
  20264. typedef struct _HAL_PROCESSOR_SPEED_INFO {
  20265. ULONG ProcessorSpeed;
  20266. } HAL_PROCESSOR_SPEED_INFORMATION, *PHAL_PROCESSOR_SPEED_INFORMATION;
  20267. // for the information class "HalCallbackInformation"
  20268. typedef struct _HAL_CALLBACKS {
  20269. PCALLBACK_OBJECT SetSystemInformation;
  20270. PCALLBACK_OBJECT BusCheck;
  20271. } HAL_CALLBACKS, *PHAL_CALLBACKS;
  20272. // for the information class "HalProcessorFeatureInformation"
  20273. typedef struct _HAL_PROCESSOR_FEATURE {
  20274. ULONG UsableFeatureBits;
  20275. } HAL_PROCESSOR_FEATURE;
  20276. // for the information class "HalNumaTopologyInterface"
  20277. typedef ULONG HALNUMAPAGETONODE;
  20278. typedef
  20279. HALNUMAPAGETONODE
  20280. (*PHALNUMAPAGETONODE)(
  20281. IN ULONG_PTR PhysicalPageNumber
  20282. );
  20283. typedef
  20284. NTSTATUS
  20285. (*PHALNUMAQUERYPROCESSORNODE)(
  20286. IN ULONG ProcessorNumber,
  20287. OUT PUSHORT Identifier,
  20288. OUT PUCHAR Node
  20289. );
  20290. typedef struct _HAL_NUMA_TOPOLOGY_INTERFACE {
  20291. ULONG NumberOfNodes;
  20292. PHALNUMAQUERYPROCESSORNODE QueryProcessorNode;
  20293. PHALNUMAPAGETONODE PageToNode;
  20294. } HAL_NUMA_TOPOLOGY_INTERFACE;
  20295. typedef
  20296. NTSTATUS
  20297. (*PHALIOREADWRITEHANDLER)(
  20298. IN BOOLEAN fRead,
  20299. IN ULONG dwAddr,
  20300. IN ULONG dwSize,
  20301. IN OUT PULONG pdwData
  20302. );
  20303. // for the information class "HalQueryIllegalIOPortAddresses"
  20304. typedef struct _HAL_AMLI_BAD_IO_ADDRESS_LIST
  20305. {
  20306. ULONG BadAddrBegin;
  20307. ULONG BadAddrSize;
  20308. ULONG OSVersionTrigger;
  20309. PHALIOREADWRITEHANDLER IOHandler;
  20310. } HAL_AMLI_BAD_IO_ADDRESS_LIST, *PHAL_AMLI_BAD_IO_ADDRESS_LIST;
  20311. // end_ntosp
  20312. #if defined(_X86_) || defined(_IA64_) || defined(_AMD64_)
  20313. //
  20314. // HalQueryMcaInterface
  20315. //
  20316. typedef
  20317. VOID
  20318. (*PHALMCAINTERFACELOCK)(
  20319. VOID
  20320. );
  20321. typedef
  20322. VOID
  20323. (*PHALMCAINTERFACEUNLOCK)(
  20324. VOID
  20325. );
  20326. typedef
  20327. NTSTATUS
  20328. (*PHALMCAINTERFACEREADREGISTER)(
  20329. IN UCHAR BankNumber,
  20330. IN OUT PVOID Exception
  20331. );
  20332. typedef struct _HAL_MCA_INTERFACE {
  20333. PHALMCAINTERFACELOCK Lock;
  20334. PHALMCAINTERFACEUNLOCK Unlock;
  20335. PHALMCAINTERFACEREADREGISTER ReadRegister;
  20336. } HAL_MCA_INTERFACE;
  20337. #if defined(_AMD64_)
  20338. struct _KTRAP_FRAME;
  20339. struct _KEXCEPTION_FRAME;
  20340. typedef
  20341. ERROR_SEVERITY
  20342. (*PDRIVER_EXCPTN_CALLBACK) (
  20343. IN PVOID Context,
  20344. IN struct _KTRAP_FRAME *TrapFrame,
  20345. IN struct _KEXCEPTION_FRAME *ExceptionFrame,
  20346. IN PMCA_EXCEPTION Exception
  20347. );
  20348. #endif
  20349. #if defined(_X86_) || defined(_IA64_)
  20350. typedef
  20351. #if defined(_IA64_)
  20352. ERROR_SEVERITY
  20353. #else
  20354. VOID
  20355. #endif
  20356. (*PDRIVER_EXCPTN_CALLBACK) (
  20357. IN PVOID Context,
  20358. IN PMCA_EXCEPTION BankLog
  20359. );
  20360. #endif
  20361. typedef PDRIVER_EXCPTN_CALLBACK PDRIVER_MCA_EXCEPTION_CALLBACK;
  20362. //
  20363. // Structure to record the callbacks from driver
  20364. //
  20365. typedef struct _MCA_DRIVER_INFO {
  20366. PDRIVER_MCA_EXCEPTION_CALLBACK ExceptionCallback;
  20367. PKDEFERRED_ROUTINE DpcCallback;
  20368. PVOID DeviceContext;
  20369. } MCA_DRIVER_INFO, *PMCA_DRIVER_INFO;
  20370. // end_ntddk
  20371. // For the information class HalKernelErrorHandler
  20372. typedef enum
  20373. {
  20374. MceNotification, // An MCE realated event occured
  20375. McaAvailable, // An CPE is available for processing
  20376. CmcAvailable, // An CMC is available for processing
  20377. CpeAvailable, // An CPE is available for processing
  20378. CmcSwitchToPolledMode, // CMC Threshold exceeded - switching to polled mode
  20379. CpeSwitchToPolledMode // CPE Threshold exceeded - switching to polled mode
  20380. } KERNEL_MCE_DELIVERY_OPERATION, *PKERNEL_MCE_DELIVERY_OPERATION;
  20381. typedef BOOLEAN (*KERNEL_MCA_DELIVERY)( PVOID Reserved, KERNEL_MCE_DELIVERY_OPERATION Operation, PVOID Argument2 );
  20382. typedef BOOLEAN (*KERNEL_CMC_DELIVERY)( PVOID Reserved, KERNEL_MCE_DELIVERY_OPERATION Operation, PVOID Argument2 );
  20383. typedef BOOLEAN (*KERNEL_CPE_DELIVERY)( PVOID Reserved, KERNEL_MCE_DELIVERY_OPERATION Operation, PVOID Argument2 );
  20384. typedef BOOLEAN (*KERNEL_MCE_DELIVERY)( PVOID Reserved, KERNEL_MCE_DELIVERY_OPERATION Operation, PVOID Argument2 );
  20385. #define KERNEL_ERROR_HANDLER_VERSION 0x2
  20386. typedef struct
  20387. {
  20388. ULONG Version; // Version of this structure. Required to be 1rst field.
  20389. ULONG Padding;
  20390. KERNEL_MCA_DELIVERY KernelMcaDelivery; // Kernel callback for MCA DPC Queueing.
  20391. KERNEL_CMC_DELIVERY KernelCmcDelivery; // Kernel callback for CMC DPC Queueing.
  20392. KERNEL_CPE_DELIVERY KernelCpeDelivery; // Kernel callback for CPE DPC Queueing.
  20393. KERNEL_MCE_DELIVERY KernelMceDelivery; // Kernel callback for CME DPC Queueing.
  20394. // Includes the kernel notifications for FW
  20395. // interfaces errors.
  20396. } KERNEL_ERROR_HANDLER_INFO, *PKERNEL_ERROR_HANDLER_INFO;
  20397. // KERNEL_MCA_DELIVERY.McaType definition
  20398. #define KERNEL_MCA_UNKNOWN 0x0
  20399. #define KERNEL_MCA_PREVIOUS 0x1
  20400. #define KERNEL_MCA_CORRECTED 0x2
  20401. // KERNEL_MCE_DELIVERY.Reserved.EVENTTYPE definitions
  20402. #define KERNEL_MCE_EVENTTYPE_MCA 0x00
  20403. #define KERNEL_MCE_EVENTTYPE_INIT 0x01
  20404. #define KERNEL_MCE_EVENTTYPE_CMC 0x02
  20405. #define KERNEL_MCE_EVENTTYPE_CPE 0x03
  20406. #define KERNEL_MCE_EVENTTYPE_MASK 0xffff
  20407. #define KERNEL_MCE_EVENTTYPE( _Reserved ) ((USHORT)(ULONG_PTR)(_Reserved))
  20408. // KERNEL_MCE_DELIVERY.Reserved.OPERATION definitions
  20409. #define KERNEL_MCE_OPERATION_CLEAR_STATE_INFO 0x1
  20410. #define KERNEL_MCE_OPERATION_GET_STATE_INFO 0x2
  20411. #define KERNEL_MCE_OPERATION_MASK 0xffff
  20412. #define KERNEL_MCE_OPERATION_SHIFT 16
  20413. #define KERNEL_MCE_OPERATION( _Reserved ) \
  20414. ((USHORT)((((ULONG_PTR)(_Reserved)) >> KERNEL_MCE_OPERATION_SHIFT) & KERNEL_MCE_OPERATION_MASK))
  20415. // for information class HalErrorInformation
  20416. #define HAL_ERROR_INFO_VERSION 0x2
  20417. // begin_ntddk
  20418. typedef struct _HAL_ERROR_INFO {
  20419. ULONG Version; // Version of this structure
  20420. ULONG Reserved; //
  20421. ULONG McaMaxSize; // Maximum size of a Machine Check Abort record
  20422. ULONG McaPreviousEventsCount; // Flag indicating previous or early-boot MCA event logs.
  20423. ULONG McaCorrectedEventsCount; // Number of corrected MCA events since boot. approx.
  20424. ULONG McaKernelDeliveryFails; // Number of Kernel callback failures. approx.
  20425. ULONG McaDriverDpcQueueFails; // Number of OEM MCA Driver Dpc queueing failures. approx.
  20426. ULONG McaReserved;
  20427. ULONG CmcMaxSize; // Maximum size of a Corrected Machine Check record
  20428. ULONG CmcPollingInterval; // In units of seconds
  20429. ULONG CmcInterruptsCount; // Number of CMC interrupts. approx.
  20430. ULONG CmcKernelDeliveryFails; // Number of Kernel callback failures. approx.
  20431. ULONG CmcDriverDpcQueueFails; // Number of OEM CMC Driver Dpc queueing failures. approx.
  20432. ULONG CmcGetStateFails; // Number of failures in getting the log from FW.
  20433. ULONG CmcClearStateFails; // Number of failures in clearing the log from FW.
  20434. ULONG CmcReserved;
  20435. ULONGLONG CmcLogId; // Last seen record identifier.
  20436. ULONG CpeMaxSize; // Maximum size of a Corrected Platform Event record
  20437. ULONG CpePollingInterval; // In units of seconds
  20438. ULONG CpeInterruptsCount; // Number of CPE interrupts. approx.
  20439. ULONG CpeKernelDeliveryFails; // Number of Kernel callback failures. approx.
  20440. ULONG CpeDriverDpcQueueFails; // Number of OEM CPE Driver Dpc queueing failures. approx.
  20441. ULONG CpeGetStateFails; // Number of failures in getting the log from FW.
  20442. ULONG CpeClearStateFails; // Number of failures in clearing the log from FW.
  20443. ULONG CpeInterruptSources; // Number of SAPIC Platform Interrupt Sources
  20444. ULONGLONG CpeLogId; // Last seen record identifier.
  20445. ULONGLONG KernelReserved[4];
  20446. } HAL_ERROR_INFO, *PHAL_ERROR_INFO;
  20447. #define HAL_MCE_INTERRUPTS_BASED ((ULONG)-1)
  20448. #define HAL_MCE_DISABLED ((ULONG)0)
  20449. //
  20450. // Known values for HAL_ERROR_INFO.CmcPollingInterval.
  20451. //
  20452. #define HAL_CMC_INTERRUPTS_BASED HAL_MCE_INTERRUPTS_BASED
  20453. #define HAL_CMC_DISABLED HAL_MCE_DISABLED
  20454. //
  20455. // Known values for HAL_ERROR_INFO.CpePollingInterval.
  20456. //
  20457. #define HAL_CPE_INTERRUPTS_BASED HAL_MCE_INTERRUPTS_BASED
  20458. #define HAL_CPE_DISABLED HAL_MCE_DISABLED
  20459. #define HAL_MCA_INTERRUPTS_BASED HAL_MCE_INTERRUPTS_BASED
  20460. #define HAL_MCA_DISABLED HAL_MCE_DISABLED
  20461. // end_ntddk
  20462. //
  20463. // Kernel/WMI Tokens for HAL MCE Log Interfaces
  20464. //
  20465. #define McaKernelToken KernelReserved[0]
  20466. #define CmcKernelToken KernelReserved[1]
  20467. #define CpeKernelToken KernelReserved[2]
  20468. // begin_ntddk
  20469. //
  20470. // Driver Callback type for the information class "HalCmcRegisterDriver"
  20471. //
  20472. typedef
  20473. VOID
  20474. (*PDRIVER_CMC_EXCEPTION_CALLBACK) (
  20475. IN PVOID Context,
  20476. IN PCMC_EXCEPTION CmcLog
  20477. );
  20478. //
  20479. // Driver Callback type for the information class "HalCpeRegisterDriver"
  20480. //
  20481. typedef
  20482. VOID
  20483. (*PDRIVER_CPE_EXCEPTION_CALLBACK) (
  20484. IN PVOID Context,
  20485. IN PCPE_EXCEPTION CmcLog
  20486. );
  20487. //
  20488. //
  20489. // Structure to record the callbacks from driver
  20490. //
  20491. typedef struct _CMC_DRIVER_INFO {
  20492. PDRIVER_CMC_EXCEPTION_CALLBACK ExceptionCallback;
  20493. PKDEFERRED_ROUTINE DpcCallback;
  20494. PVOID DeviceContext;
  20495. } CMC_DRIVER_INFO, *PCMC_DRIVER_INFO;
  20496. typedef struct _CPE_DRIVER_INFO {
  20497. PDRIVER_CPE_EXCEPTION_CALLBACK ExceptionCallback;
  20498. PKDEFERRED_ROUTINE DpcCallback;
  20499. PVOID DeviceContext;
  20500. } CPE_DRIVER_INFO, *PCPE_DRIVER_INFO;
  20501. #endif // defined(_X86_) || defined(_IA64_) || defined(_AMD64_)
  20502. #if defined(_IA64_)
  20503. typedef
  20504. NTSTATUS
  20505. (*HALSENDCROSSPARTITIONIPI)(
  20506. IN USHORT ProcessorID,
  20507. IN UCHAR HardwareVector
  20508. );
  20509. typedef
  20510. NTSTATUS
  20511. (*HALRESERVECROSSPARTITIONINTERRUPTVECTOR)(
  20512. OUT PULONG Vector,
  20513. OUT PKIRQL Irql,
  20514. IN OUT PKAFFINITY Affinity,
  20515. OUT PUCHAR HardwareVector
  20516. );
  20517. typedef struct _HAL_CROSS_PARTITION_IPI_INTERFACE {
  20518. HALSENDCROSSPARTITIONIPI HalSendCrossPartitionIpi;
  20519. HALRESERVECROSSPARTITIONINTERRUPTVECTOR HalReserveCrossPartitionInterruptVector;
  20520. } HAL_CROSS_PARTITION_IPI_INTERFACE;
  20521. #endif
  20522. typedef struct _HAL_PLATFORM_INFORMATION {
  20523. ULONG PlatformFlags;
  20524. } HAL_PLATFORM_INFORMATION, *PHAL_PLATFORM_INFORMATION;
  20525. //
  20526. // These platform flags are carried over from the IPPT table
  20527. // definition if appropriate.
  20528. //
  20529. #define HAL_PLATFORM_DISABLE_WRITE_COMBINING 0x01L
  20530. #define HAL_PLATFORM_DISABLE_PTCG 0x04L
  20531. #define HAL_PLATFORM_DISABLE_UC_MAIN_MEMORY 0x08L
  20532. #define HAL_PLATFORM_ENABLE_WRITE_COMBINING_MMIO 0x10L
  20533. #define HAL_PLATFORM_ACPI_TABLES_CACHED 0x20L
  20534. // begin_wdm begin_ntndis begin_ntosp
  20535. typedef struct _SCATTER_GATHER_ELEMENT {
  20536. PHYSICAL_ADDRESS Address;
  20537. ULONG Length;
  20538. ULONG_PTR Reserved;
  20539. } SCATTER_GATHER_ELEMENT, *PSCATTER_GATHER_ELEMENT;
  20540. #if _MSC_VER >= 1200
  20541. #pragma warning(push)
  20542. #endif
  20543. #pragma warning(disable:4200)
  20544. typedef struct _SCATTER_GATHER_LIST {
  20545. ULONG NumberOfElements;
  20546. ULONG_PTR Reserved;
  20547. SCATTER_GATHER_ELEMENT Elements[];
  20548. } SCATTER_GATHER_LIST, *PSCATTER_GATHER_LIST;
  20549. #if _MSC_VER >= 1200
  20550. #pragma warning(pop)
  20551. #else
  20552. #pragma warning(default:4200)
  20553. #endif
  20554. // end_ntndis
  20555. typedef struct _DMA_OPERATIONS *PDMA_OPERATIONS;
  20556. typedef struct _DMA_ADAPTER {
  20557. USHORT Version;
  20558. USHORT Size;
  20559. PDMA_OPERATIONS DmaOperations;
  20560. // Private Bus Device Driver data follows,
  20561. } DMA_ADAPTER, *PDMA_ADAPTER;
  20562. typedef VOID (*PPUT_DMA_ADAPTER)(
  20563. PDMA_ADAPTER DmaAdapter
  20564. );
  20565. typedef PVOID (*PALLOCATE_COMMON_BUFFER)(
  20566. IN PDMA_ADAPTER DmaAdapter,
  20567. IN ULONG Length,
  20568. OUT PPHYSICAL_ADDRESS LogicalAddress,
  20569. IN BOOLEAN CacheEnabled
  20570. );
  20571. typedef VOID (*PFREE_COMMON_BUFFER)(
  20572. IN PDMA_ADAPTER DmaAdapter,
  20573. IN ULONG Length,
  20574. IN PHYSICAL_ADDRESS LogicalAddress,
  20575. IN PVOID VirtualAddress,
  20576. IN BOOLEAN CacheEnabled
  20577. );
  20578. typedef NTSTATUS (*PALLOCATE_ADAPTER_CHANNEL)(
  20579. IN PDMA_ADAPTER DmaAdapter,
  20580. IN PDEVICE_OBJECT DeviceObject,
  20581. IN ULONG NumberOfMapRegisters,
  20582. IN PDRIVER_CONTROL ExecutionRoutine,
  20583. IN PVOID Context
  20584. );
  20585. typedef BOOLEAN (*PFLUSH_ADAPTER_BUFFERS)(
  20586. IN PDMA_ADAPTER DmaAdapter,
  20587. IN PMDL Mdl,
  20588. IN PVOID MapRegisterBase,
  20589. IN PVOID CurrentVa,
  20590. IN ULONG Length,
  20591. IN BOOLEAN WriteToDevice
  20592. );
  20593. typedef VOID (*PFREE_ADAPTER_CHANNEL)(
  20594. IN PDMA_ADAPTER DmaAdapter
  20595. );
  20596. typedef VOID (*PFREE_MAP_REGISTERS)(
  20597. IN PDMA_ADAPTER DmaAdapter,
  20598. PVOID MapRegisterBase,
  20599. ULONG NumberOfMapRegisters
  20600. );
  20601. typedef PHYSICAL_ADDRESS (*PMAP_TRANSFER)(
  20602. IN PDMA_ADAPTER DmaAdapter,
  20603. IN PMDL Mdl,
  20604. IN PVOID MapRegisterBase,
  20605. IN PVOID CurrentVa,
  20606. IN OUT PULONG Length,
  20607. IN BOOLEAN WriteToDevice
  20608. );
  20609. typedef ULONG (*PGET_DMA_ALIGNMENT)(
  20610. IN PDMA_ADAPTER DmaAdapter
  20611. );
  20612. typedef ULONG (*PREAD_DMA_COUNTER)(
  20613. IN PDMA_ADAPTER DmaAdapter
  20614. );
  20615. typedef VOID
  20616. (*PDRIVER_LIST_CONTROL)(
  20617. IN struct _DEVICE_OBJECT *DeviceObject,
  20618. IN struct _IRP *Irp,
  20619. IN PSCATTER_GATHER_LIST ScatterGather,
  20620. IN PVOID Context
  20621. );
  20622. typedef NTSTATUS
  20623. (*PGET_SCATTER_GATHER_LIST)(
  20624. IN PDMA_ADAPTER DmaAdapter,
  20625. IN PDEVICE_OBJECT DeviceObject,
  20626. IN PMDL Mdl,
  20627. IN PVOID CurrentVa,
  20628. IN ULONG Length,
  20629. IN PDRIVER_LIST_CONTROL ExecutionRoutine,
  20630. IN PVOID Context,
  20631. IN BOOLEAN WriteToDevice
  20632. );
  20633. typedef VOID
  20634. (*PPUT_SCATTER_GATHER_LIST)(
  20635. IN PDMA_ADAPTER DmaAdapter,
  20636. IN PSCATTER_GATHER_LIST ScatterGather,
  20637. IN BOOLEAN WriteToDevice
  20638. );
  20639. typedef NTSTATUS
  20640. (*PCALCULATE_SCATTER_GATHER_LIST_SIZE)(
  20641. IN PDMA_ADAPTER DmaAdapter,
  20642. IN OPTIONAL PMDL Mdl,
  20643. IN PVOID CurrentVa,
  20644. IN ULONG Length,
  20645. OUT PULONG ScatterGatherListSize,
  20646. OUT OPTIONAL PULONG pNumberOfMapRegisters
  20647. );
  20648. typedef NTSTATUS
  20649. (*PBUILD_SCATTER_GATHER_LIST)(
  20650. IN PDMA_ADAPTER DmaAdapter,
  20651. IN PDEVICE_OBJECT DeviceObject,
  20652. IN PMDL Mdl,
  20653. IN PVOID CurrentVa,
  20654. IN ULONG Length,
  20655. IN PDRIVER_LIST_CONTROL ExecutionRoutine,
  20656. IN PVOID Context,
  20657. IN BOOLEAN WriteToDevice,
  20658. IN PVOID ScatterGatherBuffer,
  20659. IN ULONG ScatterGatherLength
  20660. );
  20661. typedef NTSTATUS
  20662. (*PBUILD_MDL_FROM_SCATTER_GATHER_LIST)(
  20663. IN PDMA_ADAPTER DmaAdapter,
  20664. IN PSCATTER_GATHER_LIST ScatterGather,
  20665. IN PMDL OriginalMdl,
  20666. OUT PMDL *TargetMdl
  20667. );
  20668. typedef struct _DMA_OPERATIONS {
  20669. ULONG Size;
  20670. PPUT_DMA_ADAPTER PutDmaAdapter;
  20671. PALLOCATE_COMMON_BUFFER AllocateCommonBuffer;
  20672. PFREE_COMMON_BUFFER FreeCommonBuffer;
  20673. PALLOCATE_ADAPTER_CHANNEL AllocateAdapterChannel;
  20674. PFLUSH_ADAPTER_BUFFERS FlushAdapterBuffers;
  20675. PFREE_ADAPTER_CHANNEL FreeAdapterChannel;
  20676. PFREE_MAP_REGISTERS FreeMapRegisters;
  20677. PMAP_TRANSFER MapTransfer;
  20678. PGET_DMA_ALIGNMENT GetDmaAlignment;
  20679. PREAD_DMA_COUNTER ReadDmaCounter;
  20680. PGET_SCATTER_GATHER_LIST GetScatterGatherList;
  20681. PPUT_SCATTER_GATHER_LIST PutScatterGatherList;
  20682. PCALCULATE_SCATTER_GATHER_LIST_SIZE CalculateScatterGatherList;
  20683. PBUILD_SCATTER_GATHER_LIST BuildScatterGatherList;
  20684. PBUILD_MDL_FROM_SCATTER_GATHER_LIST BuildMdlFromScatterGatherList;
  20685. } DMA_OPERATIONS;
  20686. // end_wdm
  20687. #if defined(_WIN64)
  20688. //
  20689. // Use __inline DMA macros (hal.h)
  20690. //
  20691. #ifndef USE_DMA_MACROS
  20692. #define USE_DMA_MACROS
  20693. #endif
  20694. //
  20695. // Only PnP drivers!
  20696. //
  20697. #ifndef NO_LEGACY_DRIVERS
  20698. #define NO_LEGACY_DRIVERS
  20699. #endif
  20700. #endif // _WIN64
  20701. #if defined(USE_DMA_MACROS) && (defined(_NTDDK_) || defined(_NTDRIVER_))
  20702. // begin_wdm
  20703. DECLSPEC_DEPRECATED_DDK // Use AllocateCommonBuffer
  20704. FORCEINLINE
  20705. PVOID
  20706. HalAllocateCommonBuffer(
  20707. IN PDMA_ADAPTER DmaAdapter,
  20708. IN ULONG Length,
  20709. OUT PPHYSICAL_ADDRESS LogicalAddress,
  20710. IN BOOLEAN CacheEnabled
  20711. ){
  20712. PALLOCATE_COMMON_BUFFER allocateCommonBuffer;
  20713. PVOID commonBuffer;
  20714. allocateCommonBuffer = *(DmaAdapter)->DmaOperations->AllocateCommonBuffer;
  20715. ASSERT( allocateCommonBuffer != NULL );
  20716. commonBuffer = allocateCommonBuffer( DmaAdapter,
  20717. Length,
  20718. LogicalAddress,
  20719. CacheEnabled );
  20720. return commonBuffer;
  20721. }
  20722. DECLSPEC_DEPRECATED_DDK // Use FreeCommonBuffer
  20723. FORCEINLINE
  20724. VOID
  20725. HalFreeCommonBuffer(
  20726. IN PDMA_ADAPTER DmaAdapter,
  20727. IN ULONG Length,
  20728. IN PHYSICAL_ADDRESS LogicalAddress,
  20729. IN PVOID VirtualAddress,
  20730. IN BOOLEAN CacheEnabled
  20731. ){
  20732. PFREE_COMMON_BUFFER freeCommonBuffer;
  20733. freeCommonBuffer = *(DmaAdapter)->DmaOperations->FreeCommonBuffer;
  20734. ASSERT( freeCommonBuffer != NULL );
  20735. freeCommonBuffer( DmaAdapter,
  20736. Length,
  20737. LogicalAddress,
  20738. VirtualAddress,
  20739. CacheEnabled );
  20740. }
  20741. DECLSPEC_DEPRECATED_DDK // Use AllocateAdapterChannel
  20742. FORCEINLINE
  20743. NTSTATUS
  20744. IoAllocateAdapterChannel(
  20745. IN PDMA_ADAPTER DmaAdapter,
  20746. IN PDEVICE_OBJECT DeviceObject,
  20747. IN ULONG NumberOfMapRegisters,
  20748. IN PDRIVER_CONTROL ExecutionRoutine,
  20749. IN PVOID Context
  20750. ){
  20751. PALLOCATE_ADAPTER_CHANNEL allocateAdapterChannel;
  20752. NTSTATUS status;
  20753. allocateAdapterChannel =
  20754. *(DmaAdapter)->DmaOperations->AllocateAdapterChannel;
  20755. ASSERT( allocateAdapterChannel != NULL );
  20756. status = allocateAdapterChannel( DmaAdapter,
  20757. DeviceObject,
  20758. NumberOfMapRegisters,
  20759. ExecutionRoutine,
  20760. Context );
  20761. return status;
  20762. }
  20763. DECLSPEC_DEPRECATED_DDK // Use FlushAdapterBuffers
  20764. FORCEINLINE
  20765. BOOLEAN
  20766. IoFlushAdapterBuffers(
  20767. IN PDMA_ADAPTER DmaAdapter,
  20768. IN PMDL Mdl,
  20769. IN PVOID MapRegisterBase,
  20770. IN PVOID CurrentVa,
  20771. IN ULONG Length,
  20772. IN BOOLEAN WriteToDevice
  20773. ){
  20774. PFLUSH_ADAPTER_BUFFERS flushAdapterBuffers;
  20775. BOOLEAN result;
  20776. flushAdapterBuffers = *(DmaAdapter)->DmaOperations->FlushAdapterBuffers;
  20777. ASSERT( flushAdapterBuffers != NULL );
  20778. result = flushAdapterBuffers( DmaAdapter,
  20779. Mdl,
  20780. MapRegisterBase,
  20781. CurrentVa,
  20782. Length,
  20783. WriteToDevice );
  20784. return result;
  20785. }
  20786. DECLSPEC_DEPRECATED_DDK // Use FreeAdapterChannel
  20787. FORCEINLINE
  20788. VOID
  20789. IoFreeAdapterChannel(
  20790. IN PDMA_ADAPTER DmaAdapter
  20791. ){
  20792. PFREE_ADAPTER_CHANNEL freeAdapterChannel;
  20793. freeAdapterChannel = *(DmaAdapter)->DmaOperations->FreeAdapterChannel;
  20794. ASSERT( freeAdapterChannel != NULL );
  20795. freeAdapterChannel( DmaAdapter );
  20796. }
  20797. DECLSPEC_DEPRECATED_DDK // Use FreeMapRegisters
  20798. FORCEINLINE
  20799. VOID
  20800. IoFreeMapRegisters(
  20801. IN PDMA_ADAPTER DmaAdapter,
  20802. IN PVOID MapRegisterBase,
  20803. IN ULONG NumberOfMapRegisters
  20804. ){
  20805. PFREE_MAP_REGISTERS freeMapRegisters;
  20806. freeMapRegisters = *(DmaAdapter)->DmaOperations->FreeMapRegisters;
  20807. ASSERT( freeMapRegisters != NULL );
  20808. freeMapRegisters( DmaAdapter,
  20809. MapRegisterBase,
  20810. NumberOfMapRegisters );
  20811. }
  20812. DECLSPEC_DEPRECATED_DDK // Use MapTransfer
  20813. FORCEINLINE
  20814. PHYSICAL_ADDRESS
  20815. IoMapTransfer(
  20816. IN PDMA_ADAPTER DmaAdapter,
  20817. IN PMDL Mdl,
  20818. IN PVOID MapRegisterBase,
  20819. IN PVOID CurrentVa,
  20820. IN OUT PULONG Length,
  20821. IN BOOLEAN WriteToDevice
  20822. ){
  20823. PHYSICAL_ADDRESS physicalAddress;
  20824. PMAP_TRANSFER mapTransfer;
  20825. mapTransfer = *(DmaAdapter)->DmaOperations->MapTransfer;
  20826. ASSERT( mapTransfer != NULL );
  20827. physicalAddress = mapTransfer( DmaAdapter,
  20828. Mdl,
  20829. MapRegisterBase,
  20830. CurrentVa,
  20831. Length,
  20832. WriteToDevice );
  20833. return physicalAddress;
  20834. }
  20835. DECLSPEC_DEPRECATED_DDK // Use GetDmaAlignment
  20836. FORCEINLINE
  20837. ULONG
  20838. HalGetDmaAlignment(
  20839. IN PDMA_ADAPTER DmaAdapter
  20840. )
  20841. {
  20842. PGET_DMA_ALIGNMENT getDmaAlignment;
  20843. ULONG alignment;
  20844. getDmaAlignment = *(DmaAdapter)->DmaOperations->GetDmaAlignment;
  20845. ASSERT( getDmaAlignment != NULL );
  20846. alignment = getDmaAlignment( DmaAdapter );
  20847. return alignment;
  20848. }
  20849. DECLSPEC_DEPRECATED_DDK // Use ReadDmaCounter
  20850. FORCEINLINE
  20851. ULONG
  20852. HalReadDmaCounter(
  20853. IN PDMA_ADAPTER DmaAdapter
  20854. )
  20855. {
  20856. PREAD_DMA_COUNTER readDmaCounter;
  20857. ULONG counter;
  20858. readDmaCounter = *(DmaAdapter)->DmaOperations->ReadDmaCounter;
  20859. ASSERT( readDmaCounter != NULL );
  20860. counter = readDmaCounter( DmaAdapter );
  20861. return counter;
  20862. }
  20863. // end_wdm
  20864. #else
  20865. //
  20866. // DMA adapter object functions.
  20867. //
  20868. DECLSPEC_DEPRECATED_DDK // Use AllocateAdapterChannel
  20869. NTHALAPI
  20870. NTSTATUS
  20871. HalAllocateAdapterChannel(
  20872. IN PADAPTER_OBJECT AdapterObject,
  20873. IN PWAIT_CONTEXT_BLOCK Wcb,
  20874. IN ULONG NumberOfMapRegisters,
  20875. IN PDRIVER_CONTROL ExecutionRoutine
  20876. );
  20877. DECLSPEC_DEPRECATED_DDK // Use AllocateCommonBuffer
  20878. NTHALAPI
  20879. PVOID
  20880. HalAllocateCommonBuffer(
  20881. IN PADAPTER_OBJECT AdapterObject,
  20882. IN ULONG Length,
  20883. OUT PPHYSICAL_ADDRESS LogicalAddress,
  20884. IN BOOLEAN CacheEnabled
  20885. );
  20886. DECLSPEC_DEPRECATED_DDK // Use FreeCommonBuffer
  20887. NTHALAPI
  20888. VOID
  20889. HalFreeCommonBuffer(
  20890. IN PADAPTER_OBJECT AdapterObject,
  20891. IN ULONG Length,
  20892. IN PHYSICAL_ADDRESS LogicalAddress,
  20893. IN PVOID VirtualAddress,
  20894. IN BOOLEAN CacheEnabled
  20895. );
  20896. DECLSPEC_DEPRECATED_DDK // Use ReadDmaCounter
  20897. NTHALAPI
  20898. ULONG
  20899. HalReadDmaCounter(
  20900. IN PADAPTER_OBJECT AdapterObject
  20901. );
  20902. DECLSPEC_DEPRECATED_DDK // Use FlushAdapterBuffers
  20903. NTHALAPI
  20904. BOOLEAN
  20905. IoFlushAdapterBuffers(
  20906. IN PADAPTER_OBJECT AdapterObject,
  20907. IN PMDL Mdl,
  20908. IN PVOID MapRegisterBase,
  20909. IN PVOID CurrentVa,
  20910. IN ULONG Length,
  20911. IN BOOLEAN WriteToDevice
  20912. );
  20913. DECLSPEC_DEPRECATED_DDK // Use FreeAdapterChannel
  20914. NTHALAPI
  20915. VOID
  20916. IoFreeAdapterChannel(
  20917. IN PADAPTER_OBJECT AdapterObject
  20918. );
  20919. DECLSPEC_DEPRECATED_DDK // Use FreeMapRegisters
  20920. NTHALAPI
  20921. VOID
  20922. IoFreeMapRegisters(
  20923. IN PADAPTER_OBJECT AdapterObject,
  20924. IN PVOID MapRegisterBase,
  20925. IN ULONG NumberOfMapRegisters
  20926. );
  20927. DECLSPEC_DEPRECATED_DDK // Use MapTransfer
  20928. NTHALAPI
  20929. PHYSICAL_ADDRESS
  20930. IoMapTransfer(
  20931. IN PADAPTER_OBJECT AdapterObject,
  20932. IN PMDL Mdl,
  20933. IN PVOID MapRegisterBase,
  20934. IN PVOID CurrentVa,
  20935. IN OUT PULONG Length,
  20936. IN BOOLEAN WriteToDevice
  20937. );
  20938. #endif // USE_DMA_MACROS && (_NTDDK_ || _NTDRIVER_)
  20939. DECLSPEC_DEPRECATED_DDK
  20940. NTSTATUS
  20941. HalGetScatterGatherList ( // Use GetScatterGatherList
  20942. IN PADAPTER_OBJECT DmaAdapter,
  20943. IN PDEVICE_OBJECT DeviceObject,
  20944. IN PMDL Mdl,
  20945. IN PVOID CurrentVa,
  20946. IN ULONG Length,
  20947. IN PDRIVER_LIST_CONTROL ExecutionRoutine,
  20948. IN PVOID Context,
  20949. IN BOOLEAN WriteToDevice
  20950. );
  20951. DECLSPEC_DEPRECATED_DDK // Use PutScatterGatherList
  20952. VOID
  20953. HalPutScatterGatherList (
  20954. IN PADAPTER_OBJECT DmaAdapter,
  20955. IN PSCATTER_GATHER_LIST ScatterGather,
  20956. IN BOOLEAN WriteToDevice
  20957. );
  20958. DECLSPEC_DEPRECATED_DDK // Use PutDmaAdapter
  20959. VOID
  20960. HalPutDmaAdapter(
  20961. IN PADAPTER_OBJECT DmaAdapter
  20962. );
  20963. // end_ntddk end_ntosp
  20964. #endif // _HAL_
  20965. //
  20966. // Define exported ZwXxx routines to device drivers & hal
  20967. //
  20968. NTSYSAPI
  20969. NTSTATUS
  20970. NTAPI
  20971. ZwClose(
  20972. IN HANDLE Handle
  20973. );
  20974. NTSYSAPI
  20975. NTSTATUS
  20976. NTAPI
  20977. ZwCreateDirectoryObject(
  20978. OUT PHANDLE DirectoryHandle,
  20979. IN ACCESS_MASK DesiredAccess,
  20980. IN POBJECT_ATTRIBUTES ObjectAttributes
  20981. );
  20982. NTSYSAPI
  20983. NTSTATUS
  20984. NTAPI
  20985. ZwCreateKey(
  20986. OUT PHANDLE KeyHandle,
  20987. IN ACCESS_MASK DesiredAccess,
  20988. IN POBJECT_ATTRIBUTES ObjectAttributes,
  20989. IN ULONG TitleIndex,
  20990. IN PUNICODE_STRING Class OPTIONAL,
  20991. IN ULONG CreateOptions,
  20992. OUT PULONG Disposition OPTIONAL
  20993. );
  20994. NTSYSAPI
  20995. NTSTATUS
  20996. NTAPI
  20997. ZwOpenKey(
  20998. OUT PHANDLE KeyHandle,
  20999. IN ACCESS_MASK DesiredAccess,
  21000. IN POBJECT_ATTRIBUTES ObjectAttributes
  21001. );
  21002. NTSYSAPI
  21003. NTSTATUS
  21004. NTAPI
  21005. ZwEnumerateKey(
  21006. IN HANDLE KeyHandle,
  21007. IN ULONG Index,
  21008. IN KEY_INFORMATION_CLASS KeyInformationClass,
  21009. OUT PVOID KeyInformation,
  21010. IN ULONG Length,
  21011. OUT PULONG ResultLength
  21012. );
  21013. NTSYSAPI
  21014. NTSTATUS
  21015. NTAPI
  21016. ZwEnumerateValueKey(
  21017. IN HANDLE KeyHandle,
  21018. IN ULONG Index,
  21019. IN KEY_VALUE_INFORMATION_CLASS KeyValueInformationClass,
  21020. OUT PVOID KeyValueInformation,
  21021. IN ULONG Length,
  21022. OUT PULONG ResultLength
  21023. );
  21024. NTSYSAPI
  21025. NTSTATUS
  21026. NTAPI
  21027. ZwFlushKey(
  21028. IN HANDLE KeyHandle
  21029. );
  21030. NTSYSAPI
  21031. NTSTATUS
  21032. NTAPI
  21033. ZwQueryKey(
  21034. IN HANDLE KeyHandle,
  21035. IN KEY_INFORMATION_CLASS KeyInformationClass,
  21036. OUT PVOID KeyInformation,
  21037. IN ULONG Length,
  21038. OUT PULONG ResultLength
  21039. );
  21040. NTSYSAPI
  21041. NTSTATUS
  21042. NTAPI
  21043. ZwQueryValueKey(
  21044. IN HANDLE KeyHandle,
  21045. IN PUNICODE_STRING ValueName,
  21046. IN KEY_VALUE_INFORMATION_CLASS KeyValueInformationClass,
  21047. OUT PVOID KeyValueInformation,
  21048. IN ULONG Length,
  21049. OUT PULONG ResultLength
  21050. );
  21051. NTSYSAPI
  21052. NTSTATUS
  21053. NTAPI
  21054. ZwSetValueKey(
  21055. IN HANDLE KeyHandle,
  21056. IN PUNICODE_STRING ValueName,
  21057. IN ULONG TitleIndex OPTIONAL,
  21058. IN ULONG Type,
  21059. IN PVOID Data,
  21060. IN ULONG DataSize
  21061. );
  21062. NTSYSAPI
  21063. NTSTATUS
  21064. NTAPI
  21065. ZwMakeTemporaryObject(
  21066. IN HANDLE Handle
  21067. );
  21068. NTSYSAPI
  21069. NTSTATUS
  21070. NTAPI
  21071. ZwQueryVolumeInformationFile(
  21072. IN HANDLE FileHandle,
  21073. OUT PIO_STATUS_BLOCK IoStatusBlock,
  21074. OUT PVOID FsInformation,
  21075. IN ULONG Length,
  21076. IN FS_INFORMATION_CLASS FsInformationClass
  21077. );
  21078. NTSYSAPI
  21079. NTSTATUS
  21080. NTAPI
  21081. ZwOpenFile(
  21082. OUT PHANDLE FileHandle,
  21083. IN ACCESS_MASK DesiredAccess,
  21084. IN POBJECT_ATTRIBUTES ObjectAttributes,
  21085. OUT PIO_STATUS_BLOCK IoStatusBlock,
  21086. IN ULONG ShareAccess,
  21087. IN ULONG OpenOptions
  21088. );
  21089. NTSYSAPI
  21090. NTSTATUS
  21091. NTAPI
  21092. ZwDeviceIoControlFile(
  21093. IN HANDLE FileHandle,
  21094. IN HANDLE Event OPTIONAL,
  21095. IN PIO_APC_ROUTINE ApcRoutine OPTIONAL,
  21096. IN PVOID ApcContext OPTIONAL,
  21097. OUT PIO_STATUS_BLOCK IoStatusBlock,
  21098. IN ULONG IoControlCode,
  21099. IN PVOID InputBuffer OPTIONAL,
  21100. IN ULONG InputBufferLength,
  21101. OUT PVOID OutputBuffer OPTIONAL,
  21102. IN ULONG OutputBufferLength
  21103. );
  21104. NTSYSAPI
  21105. NTSTATUS
  21106. NTAPI
  21107. ZwDisplayString(
  21108. IN PUNICODE_STRING String
  21109. );
  21110. NTSYSAPI
  21111. NTSTATUS
  21112. NTAPI
  21113. ZwPowerInformation(
  21114. IN POWER_INFORMATION_LEVEL InformationLevel,
  21115. IN PVOID InputBuffer OPTIONAL,
  21116. IN ULONG InputBufferLength,
  21117. OUT PVOID OutputBuffer OPTIONAL,
  21118. IN ULONG OutputBufferLength
  21119. );
  21120. #endif // _NTHAL_