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

3114 lines
70 KiB

  1. /*++
  2. Copyright (c) 1990 Microsoft Corporation
  3. Module Name:
  4. mipae.h
  5. Abstract:
  6. This module contains the private data structures and procedure
  7. prototypes for the hardware dependent portion of the
  8. memory management system.
  9. This module is specifically tailored for the PAE x86,
  10. Author:
  11. Landy Wang (landyw) 30-Nov-1998
  12. Revision History:
  13. --*/
  14. #if defined(_X86PAE_)
  15. /*++
  16. Virtual Memory Layout on the PAE x86 is:
  17. +------------------------------------+
  18. 00000000 | |
  19. | |
  20. | |
  21. | User Mode Addresses |
  22. | |
  23. | All pages within this range |
  24. | are potentially accessible while |
  25. | the CPU is in USER mode. |
  26. | |
  27. | |
  28. +------------------------------------+
  29. 7ffff000 | 64k No Access Area |
  30. +------------------------------------+
  31. 80000000 | |
  32. | NTLDR loads the kernel, HAL and |
  33. | boot drivers here. The kernel |
  34. | then relocates the drivers to the |
  35. | system PTE area. |
  36. | |
  37. | Kernel mode access only. |
  38. | |
  39. | When possible, the PFN database & |
  40. | initial non paged pool is built |
  41. | here using large page mappings. |
  42. | |
  43. +------------------------------------+
  44. | |
  45. | Additional system PTEs, system |
  46. | cache or special pooling |
  47. | |
  48. +------------------------------------+
  49. | |
  50. | System mapped views. |
  51. | |
  52. +------------------------------------+
  53. | |
  54. | Session space. |
  55. | |
  56. +------------------------------------+
  57. C0000000 | Page Table Pages mapped through |
  58. | this 8mb region |
  59. | Kernel mode access only. |
  60. | |
  61. +------------------------------------+
  62. C0800000 | HyperSpace - working set lists |
  63. | and per process memory management |
  64. | structures mapped in this 4mb |
  65. | region. |
  66. | Kernel mode access only. |
  67. +------------------------------------+
  68. C0C00000 | System Cache Structures |
  69. | reside in this 4mb region |
  70. | Kernel mode access only. |
  71. +------------------------------------+
  72. C1000000 | System cache resides here. |
  73. | Kernel mode access only. |
  74. | |
  75. | |
  76. +------------------------------------+
  77. E1000000 | Start of paged system area |
  78. | Kernel mode access only. |
  79. | |
  80. +------------------------------------+
  81. | |
  82. | System PTE area - for mapping |
  83. | kernel thread stacks and MDLs |
  84. | that require system VAs. |
  85. | Kernel mode access only. |
  86. | |
  87. +------------------------------------+
  88. | |
  89. | NonPaged System area |
  90. | Kernel mode access only. |
  91. | |
  92. +------------------------------------+
  93. FFBE0000 | Crash Dump Driver area |
  94. | Kernel mode access only. |
  95. +------------------------------------+
  96. FFC00000 | Last 4mb reserved for HAL usage |
  97. +------------------------------------+
  98. --*/
  99. #define _MI_PAGING_LEVELS 2
  100. #define _MI_MORE_THAN_4GB_ 1
  101. //
  102. // Define empty list markers.
  103. //
  104. #define MM_EMPTY_LIST ((ULONG)0xFFFFFFFF) //
  105. #define MM_EMPTY_PTE_LIST ((ULONG)0xFFFFFFFF) // N.B. tied to MMPTE definition
  106. #define MI_PTE_BASE_FOR_LOWEST_KERNEL_ADDRESS (MiGetPteAddress (0x00000000))
  107. #define MM_SESSION_SPACE_DEFAULT (0xA0000000)
  108. #define MM_SESSION_SPACE_DEFAULT_END (0xC0000000)
  109. extern ULONG_PTR MmBootImageSize;
  110. //
  111. // PAGE_SIZE for PAE x86 is 4k, virtual page is 20 bits with a PAGE_SHIFT
  112. // byte offset.
  113. //
  114. #define MM_VIRTUAL_PAGE_FILLER 0
  115. #define MM_VIRTUAL_PAGE_SIZE 20
  116. //
  117. // Address space layout definitions.
  118. //
  119. #define MM_KSEG0_BASE ((ULONG)0x80000000)
  120. #define MM_KSEG2_BASE ((ULONG)0xA0000000)
  121. #define MM_PAGES_IN_KSEG0 ((MM_KSEG2_BASE - MM_KSEG0_BASE) >> PAGE_SHIFT)
  122. #define CODE_START MM_KSEG0_BASE
  123. #define CODE_END MM_KSEG2_BASE
  124. #define MM_SYSTEM_SPACE_START (0xC0C00000)
  125. #define MM_SYSTEM_SPACE_END (0xFFFFFFFF)
  126. #define HYPER_SPACE ((PVOID)0xC0800000)
  127. #define HYPER_SPACE2 ((PVOID)0xC0A00000)
  128. #define HYPER_SPACE_END (0xC0BFFFFF)
  129. #define MM_SYSTEM_VIEW_START (0xA0000000)
  130. #define MM_SYSTEM_VIEW_SIZE (16*1024*1024)
  131. #define MM_USER_ADDRESS_RANGE_LIMIT 0xFFFFFFFF // user address range limit
  132. #define MM_MAXIMUM_ZERO_BITS 21 // maximum number of zero bits
  133. //
  134. // Define the start and maximum size for the system cache.
  135. // Maximum size is normally 512MB, but can be up to 512MB + 448MB = 960MB for
  136. // large system cache machines.
  137. //
  138. #define MM_SYSTEM_CACHE_WORKING_SET (0xC0C00000)
  139. #define MM_SYSTEM_CACHE_START (0xC1000000)
  140. #define MM_SYSTEM_CACHE_END (0xE1000000)
  141. //
  142. //
  143. // Various resources like additional system PTEs or system cache views, etc,
  144. // can be allocated out of this virtual address range.
  145. //
  146. extern ULONG MiExtraResourceStart;
  147. extern ULONG MiExtraResourceEnd;
  148. extern ULONG_PTR MiUseMaximumSystemSpace;
  149. extern ULONG_PTR MiUseMaximumSystemSpaceEnd;
  150. extern ULONG MiNumberOfExtraSystemPdes;
  151. extern ULONG MiMaximumSystemExtraSystemPdes;
  152. extern ULONG MiMaximumSystemCacheSizeExtra;
  153. extern PVOID MiSystemCacheStartExtra;
  154. extern PVOID MiSystemCacheEndExtra;
  155. #define MM_SYSTEM_CACHE_END_EXTRA (0xC0000000)
  156. #define MM_PAGED_POOL_START (MmPagedPoolStart)
  157. #define MM_DEFAULT_PAGED_POOL_START (0xE1000000)
  158. #define MM_LOWEST_NONPAGED_SYSTEM_START ((PVOID)(0xEB000000))
  159. #define MmProtopte_Base ((ULONG)MmPagedPoolStart)
  160. #define MM_NONPAGED_POOL_END ((PVOID)(0xFFBE0000))
  161. #define MM_CRASH_DUMP_VA ((PVOID)(0xFFBE0000))
  162. #define MM_DEBUG_VA ((PVOID)0xFFBFF000)
  163. #define NON_PAGED_SYSTEM_END ((ULONG)0xFFFFFFF0) //quadword aligned.
  164. extern BOOLEAN MiWriteCombiningPtes;
  165. LOGICAL
  166. MiRecoverExtraPtes (
  167. VOID
  168. );
  169. //
  170. // Define absolute minimum and maximum count for system PTEs.
  171. //
  172. #define MM_MINIMUM_SYSTEM_PTES 7000
  173. #define MM_MAXIMUM_SYSTEM_PTES 50000
  174. #define MM_DEFAULT_SYSTEM_PTES 11000
  175. //
  176. // Pool limits
  177. //
  178. //
  179. // The maximum amount of nonpaged pool that can be initially created.
  180. //
  181. #define MM_MAX_INITIAL_NONPAGED_POOL ((ULONG)(128*1024*1024))
  182. //
  183. // The total amount of nonpaged pool (initial pool + expansion).
  184. //
  185. #define MM_MAX_ADDITIONAL_NONPAGED_POOL ((ULONG)(128*1024*1024))
  186. //
  187. // The maximum amount of paged pool that can be created.
  188. //
  189. #define MM_MAX_PAGED_POOL ((ULONG)MM_NONPAGED_POOL_END - (ULONG)MM_PAGED_POOL_START)
  190. #define MM_MAX_TOTAL_POOL (((ULONG)MM_NONPAGED_POOL_END) - ((ULONG)(MM_PAGED_POOL_START)))
  191. //
  192. // Structure layout definitions.
  193. //
  194. #define MM_PROTO_PTE_ALIGNMENT ((ULONG)PAGE_SIZE)
  195. #define PAGE_DIRECTORY_MASK ((ULONG)0x001FFFFF)
  196. #define MM_VA_MAPPED_BY_PDE (0x200000)
  197. #define LOWEST_IO_ADDRESS 0xa0000
  198. #define PTE_SHIFT 3
  199. //
  200. // The number of bits in a physical address.
  201. //
  202. #define PHYSICAL_ADDRESS_BITS 36
  203. #define MM_MAXIMUM_NUMBER_OF_COLORS (1)
  204. //
  205. // x86 does not require support for colored pages.
  206. //
  207. #define MM_NUMBER_OF_COLORS (1)
  208. //
  209. // Mask for obtaining color from a physical page number.
  210. //
  211. #define MM_COLOR_MASK (0)
  212. //
  213. // Boundary for aligned pages of like color upon.
  214. //
  215. #define MM_COLOR_ALIGNMENT (0)
  216. //
  217. // Mask for isolating color from virtual address.
  218. //
  219. #define MM_COLOR_MASK_VIRTUAL (0)
  220. //
  221. // Define 256k worth of secondary colors.
  222. //
  223. #define MM_SECONDARY_COLORS_DEFAULT (64)
  224. #define MM_SECONDARY_COLORS_MIN (2)
  225. #define MM_SECONDARY_COLORS_MAX (1024)
  226. //
  227. // Maximum number of paging files.
  228. //
  229. #define MAX_PAGE_FILES 16
  230. //
  231. // Hyper space definitions.
  232. //
  233. #define FIRST_MAPPING_PTE ((ULONG)0xC0801000)
  234. #define NUMBER_OF_MAPPING_PTES 126
  235. #define LAST_MAPPING_PTE \
  236. ((ULONG)((ULONG)FIRST_MAPPING_PTE + (NUMBER_OF_MAPPING_PTES * PAGE_SIZE)))
  237. #define COMPRESSION_MAPPING_PTE ((PMMPTE)((ULONG)LAST_MAPPING_PTE + PAGE_SIZE))
  238. #define IMAGE_MAPPING_PTE ((PMMPTE)((ULONG)COMPRESSION_MAPPING_PTE + PAGE_SIZE))
  239. #define NUMBER_OF_ZEROING_PTES 256
  240. //
  241. // This bitmap consumes 4K when booted /2GB and 6K when booted /3GB, thus
  242. // the working set list start is variable.
  243. //
  244. #define VAD_BITMAP_SPACE ((PVOID)((ULONG)IMAGE_MAPPING_PTE + PAGE_SIZE))
  245. #define WORKING_SET_LIST MmWorkingSetList
  246. #define MM_MAXIMUM_WORKING_SET MiMaximumWorkingSet
  247. #define MmWsle ((PMMWSLE)((PUCHAR)WORKING_SET_LIST + sizeof(MMWSL)))
  248. extern ULONG MiMaximumWorkingSet;
  249. #define MM_WORKING_SET_END ((ULONG)0xC0BFF000)
  250. //
  251. // Define masks for fields within the PTE.
  252. ///
  253. #define MM_PTE_VALID_MASK 0x1
  254. #if defined(NT_UP)
  255. #define MM_PTE_WRITE_MASK 0x2
  256. #else
  257. #define MM_PTE_WRITE_MASK 0x800
  258. #endif
  259. #define MM_PTE_OWNER_MASK 0x4
  260. #define MM_PTE_WRITE_THROUGH_MASK 0x8
  261. #define MM_PTE_CACHE_DISABLE_MASK 0x10
  262. #define MM_PTE_ACCESS_MASK 0x20
  263. #if defined(NT_UP)
  264. #define MM_PTE_DIRTY_MASK 0x40
  265. #else
  266. #define MM_PTE_DIRTY_MASK 0x42
  267. #endif
  268. #define MM_PTE_LARGE_PAGE_MASK 0x80
  269. #define MM_PTE_GLOBAL_MASK 0x100
  270. #define MM_PTE_COPY_ON_WRITE_MASK 0x200
  271. #define MM_PTE_PROTOTYPE_MASK 0x400
  272. #define MM_PTE_TRANSITION_MASK 0x800
  273. //
  274. // Bit fields to or into PTE to make a PTE valid based on the
  275. // protection field of the invalid PTE.
  276. //
  277. #define MM_PTE_NOACCESS 0x0 // not expressable on x86
  278. #define MM_PTE_READONLY 0x0
  279. #define MM_PTE_READWRITE MM_PTE_WRITE_MASK
  280. #define MM_PTE_WRITECOPY 0x200 // read-only copy on write bit set.
  281. #define MM_PTE_EXECUTE 0x0 // read-only on x86
  282. #define MM_PTE_EXECUTE_READ 0x0
  283. #define MM_PTE_EXECUTE_READWRITE MM_PTE_WRITE_MASK
  284. #define MM_PTE_EXECUTE_WRITECOPY 0x200 // read-only copy on write bit set.
  285. #define MM_PTE_NOCACHE 0x010
  286. #define MM_PTE_GUARD 0x0 // not expressable on x86
  287. #define MM_PTE_CACHE 0x0
  288. #define MM_PROTECT_FIELD_SHIFT 5
  289. //
  290. // Bits available for the software working set index within the hardware PTE.
  291. //
  292. #define MI_MAXIMUM_PTE_WORKING_SET_INDEX 0
  293. //
  294. // Zero PTE
  295. //
  296. #define MM_ZERO_PTE 0
  297. //
  298. // Zero Kernel PTE
  299. //
  300. #define MM_ZERO_KERNEL_PTE 0
  301. //
  302. // A demand zero PTE with a protection of PAGE_READWRITE.
  303. //
  304. #define MM_DEMAND_ZERO_WRITE_PTE (MM_READWRITE << MM_PROTECT_FIELD_SHIFT)
  305. //
  306. // A demand zero PTE with a protection of PAGE_READWRITE for system space.
  307. //
  308. #define MM_KERNEL_DEMAND_ZERO_PTE (MM_READWRITE << MM_PROTECT_FIELD_SHIFT)
  309. //
  310. // A no access PTE for system space.
  311. //
  312. #define MM_KERNEL_NOACCESS_PTE (MM_NOACCESS << MM_PROTECT_FIELD_SHIFT)
  313. //
  314. // Kernel stack alignment requirements.
  315. //
  316. #define MM_STACK_ALIGNMENT 0x0
  317. #define MM_STACK_OFFSET 0x0
  318. //
  319. // System process definitions
  320. //
  321. #define PDE_PER_PAGE ((ULONG)512)
  322. #define PTE_PER_PAGE ((ULONG)512)
  323. #define PD_PER_SYSTEM ((ULONG)4)
  324. //
  325. // Number of page table pages for user addresses.
  326. //
  327. #define MM_USER_PAGE_TABLE_PAGES (1536)
  328. VOID
  329. MiPaeInitialize (
  330. VOID
  331. );
  332. //++
  333. //VOID
  334. //MI_MAKE_VALID_PTE (
  335. // OUT OUTPTE,
  336. // IN FRAME,
  337. // IN PMASK,
  338. // IN PPTE
  339. // );
  340. //
  341. // Routine Description:
  342. //
  343. // This macro makes a valid PTE from a page frame number, protection mask,
  344. // and owner.
  345. //
  346. // Arguments
  347. //
  348. // OUTPTE - Supplies the PTE in which to build the transition PTE.
  349. //
  350. // FRAME - Supplies the page frame number for the PTE.
  351. //
  352. // PMASK - Supplies the protection to set in the transition PTE.
  353. //
  354. // PPTE - Supplies a pointer to the PTE which is being made valid.
  355. // For prototype PTEs NULL should be specified.
  356. //
  357. // Return Value:
  358. //
  359. // None.
  360. //
  361. //--
  362. #define MI_MAKE_VALID_PTE(OUTPTE,FRAME,PMASK,PPTE) \
  363. (OUTPTE).u.Long = (((ULONGLONG)FRAME << 12) | \
  364. (MmProtectToPteMask[PMASK]) | \
  365. MiDetermineUserGlobalPteMask ((PMMPTE)PPTE)); \
  366. if (MmPaeMask != 0) { \
  367. if (((PPTE) >= (PMMPTE)PDE_BASE) && ((PPTE) < (PMMPTE)PDE_TOP)) { \
  368. (OUTPTE).u.Long &= ~MmPaeMask; \
  369. } \
  370. }
  371. //++
  372. //VOID
  373. //MI_MAKE_VALID_PTE_TRANSITION (
  374. // IN OUT OUTPTE
  375. // IN PROTECT
  376. // );
  377. //
  378. // Routine Description:
  379. //
  380. // This macro takes a valid pte and turns it into a transition PTE.
  381. //
  382. // Arguments
  383. //
  384. // OUTPTE - Supplies the current valid PTE. This PTE is then
  385. // modified to become a transition PTE.
  386. //
  387. // PROTECT - Supplies the protection to set in the transition PTE.
  388. //
  389. // Return Value:
  390. //
  391. // None.
  392. //
  393. //--
  394. #define MI_MAKE_VALID_PTE_TRANSITION(OUTPTE,PROTECT) \
  395. (OUTPTE).u.Soft.Transition = 1; \
  396. (OUTPTE).u.Soft.Valid = 0; \
  397. (OUTPTE).u.Soft.Prototype = 0; \
  398. (OUTPTE).u.Soft.Protection = PROTECT;
  399. //++
  400. //VOID
  401. //MI_MAKE_TRANSITION_PTE (
  402. // OUT OUTPTE,
  403. // IN PAGE,
  404. // IN PROTECT,
  405. // IN PPTE
  406. // );
  407. //
  408. // Routine Description:
  409. //
  410. // This macro takes a valid pte and turns it into a transition PTE.
  411. //
  412. // Arguments
  413. //
  414. // OUTPTE - Supplies the PTE in which to build the transition PTE.
  415. //
  416. // PAGE - Supplies the page frame number for the PTE.
  417. //
  418. // PROTECT - Supplies the protection to set in the transition PTE.
  419. //
  420. // PPTE - Supplies a pointer to the PTE, this is used to determine
  421. // the owner of the PTE.
  422. //
  423. // Return Value:
  424. //
  425. // None.
  426. //
  427. //--
  428. #define MI_MAKE_TRANSITION_PTE(OUTPTE,PAGE,PROTECT,PPTE) \
  429. (OUTPTE).u.Long = 0; \
  430. (OUTPTE).u.Trans.PageFrameNumber = PAGE; \
  431. (OUTPTE).u.Trans.Transition = 1; \
  432. (OUTPTE).u.Trans.Protection = PROTECT; \
  433. (OUTPTE).u.Trans.Owner = MI_DETERMINE_OWNER(PPTE);
  434. //++
  435. //VOID
  436. //MI_MAKE_TRANSITION_PTE_VALID (
  437. // OUT OUTPTE,
  438. // IN PPTE
  439. // );
  440. //
  441. // Routine Description:
  442. //
  443. // This macro takes a transition pte and makes it a valid PTE.
  444. //
  445. // Arguments
  446. //
  447. // OUTPTE - Supplies the PTE in which to build the valid PTE.
  448. //
  449. // PPTE - Supplies a pointer to the transition PTE.
  450. //
  451. // Return Value:
  452. //
  453. // None.
  454. //
  455. //--
  456. #define MI_MAKE_TRANSITION_PTE_VALID(OUTPTE,PPTE) \
  457. ASSERT (((PPTE)->u.Hard.Valid == 0) && \
  458. ((PPTE)->u.Trans.Prototype == 0) && \
  459. ((PPTE)->u.Trans.Transition == 1)); \
  460. (OUTPTE).u.Long = (((PPTE)->u.Long & ~0xFFF) | \
  461. (MmProtectToPteMask[(PPTE)->u.Trans.Protection]) | \
  462. MiDetermineUserGlobalPteMask ((PMMPTE)PPTE));
  463. #define MI_FAULT_STATUS_INDICATES_EXECUTION(_FaultStatus) (_FaultStatus & MmPaeErrMask)
  464. #define MI_FAULT_STATUS_INDICATES_WRITE(_FaultStatus) (_FaultStatus & 0x1)
  465. #define MI_CLEAR_FAULT_STATUS(_FaultStatus) (_FaultStatus = 0)
  466. #define MI_IS_PTE_EXECUTABLE(_TempPte) (((_TempPte)->u.Long & MmPaeMask) == 0)
  467. //++
  468. //VOID
  469. //MI_SET_PTE_IN_WORKING_SET (
  470. // OUT PMMPTE PTE,
  471. // IN ULONG WSINDEX
  472. // );
  473. //
  474. // Routine Description:
  475. //
  476. // This macro inserts the specified working set index into the argument PTE.
  477. // Since the x86 PTE has no free bits in the valid PTE, nothing needs to
  478. // be done on this architecture.
  479. //
  480. // Arguments
  481. //
  482. // OUTPTE - Supplies the PTE in which to insert the working set index.
  483. //
  484. // WSINDEX - Supplies the working set index for the PTE.
  485. //
  486. // Return Value:
  487. //
  488. // None.
  489. //
  490. //--
  491. #define MI_SET_PTE_IN_WORKING_SET(PTE, WSINDEX)
  492. //++
  493. //ULONG WsIndex
  494. //MI_GET_WORKING_SET_FROM_PTE(
  495. // IN PMMPTE PTE
  496. // );
  497. //
  498. // Routine Description:
  499. //
  500. // This macro returns the working set index from the argument PTE.
  501. // Since the x86 PTE has no free bits in the valid PTE, nothing needs to
  502. // be done on this architecture.
  503. //
  504. // Arguments
  505. //
  506. // PTE - Supplies the PTE to extract the working set index from.
  507. //
  508. // Return Value:
  509. //
  510. // This macro returns the working set index for the argument PTE.
  511. //
  512. //--
  513. #define MI_GET_WORKING_SET_FROM_PTE(PTE) 0
  514. //++
  515. //VOID
  516. //MI_SET_PTE_WRITE_COMBINE (
  517. // IN MMPTE PTE
  518. // );
  519. //
  520. // Routine Description:
  521. //
  522. // This macro takes a valid PTE and enables WriteCombining as the
  523. // caching state. Note that the PTE bits may only be set this way
  524. // if the Page Attribute Table is present and the PAT has been
  525. // initialized to provide Write Combining.
  526. //
  527. // If either of the above conditions is not satisfied, then
  528. // the macro enables WEAK UC (PCD = 1, PWT = 0) in the PTE.
  529. //
  530. // Arguments
  531. //
  532. // PTE - Supplies a valid PTE.
  533. //
  534. // Return Value:
  535. //
  536. // None.
  537. //
  538. //--
  539. //
  540. #define MI_SET_PTE_WRITE_COMBINE(PTE) \
  541. { \
  542. if (MiWriteCombiningPtes == TRUE) { \
  543. ((PTE).u.Hard.CacheDisable = 0); \
  544. ((PTE).u.Hard.WriteThrough = 1); \
  545. } else { \
  546. ((PTE).u.Hard.CacheDisable = 1); \
  547. ((PTE).u.Hard.WriteThrough = 0); \
  548. } \
  549. }
  550. //++
  551. //VOID
  552. //MI_PREPARE_FOR_NONCACHED (
  553. // IN MI_PFN_CACHE_ATTRIBUTE CacheAttribute
  554. // );
  555. //
  556. // Routine Description:
  557. //
  558. // This macro prepares the system prior to noncached PTEs being created.
  559. //
  560. // Note the entire TB must be flushed on all processors because there may
  561. // be stale system PTE (or hyperspace or zeropage) mappings in the TB which
  562. // may refer to the same physical page but with a different cache attribute.
  563. //
  564. // Arguments
  565. //
  566. // CacheAttribute - Supplies the cache attribute the PTEs will be filled
  567. // with.
  568. //
  569. // Return Value:
  570. //
  571. // None.
  572. //
  573. //--
  574. #define MI_PREPARE_FOR_NONCACHED(_CacheAttribute) \
  575. if (_CacheAttribute != MiCached) { \
  576. KeFlushEntireTb (FALSE, TRUE); \
  577. KeInvalidateAllCaches (TRUE); \
  578. }
  579. //++
  580. //VOID
  581. //MI_SWEEP_CACHE (
  582. // IN MI_PFN_CACHE_ATTRIBUTE CacheAttribute,
  583. // IN PVOID StartVa,
  584. // IN ULONG NumberOfBytes
  585. // );
  586. //
  587. // Routine Description:
  588. //
  589. // This macro prepares the system prior to noncached PTEs being created.
  590. // This does nothing on x86.
  591. //
  592. // Arguments
  593. //
  594. // CacheAttribute - Supplies the cache attribute the PTEs were filled with.
  595. //
  596. // StartVa - Supplies the starting address that's been mapped.
  597. //
  598. // NumberOfBytes - Supplies the number of bytes that have been mapped.
  599. //
  600. // Return Value:
  601. //
  602. // None.
  603. //
  604. //--
  605. #define MI_SWEEP_CACHE(_CacheType,_StartVa,_NumberOfBytes)
  606. LOGICAL
  607. MiMustFrameBeCached (
  608. IN PFN_NUMBER PageFrameIndex
  609. );
  610. typedef struct _MI_LARGE_PAGE_RANGES {
  611. PFN_NUMBER StartFrame;
  612. PFN_NUMBER LastFrame;
  613. } MI_LARGE_PAGE_RANGES, *PMI_LARGE_PAGE_RANGES;
  614. extern ULONG MiLargePageRangeIndex;
  615. extern MI_LARGE_PAGE_RANGES MiLargePageRanges[];
  616. #define MI_PAGE_FRAME_INDEX_MUST_BE_CACHED(PageFrameIndex) \
  617. MiMustFrameBeCached (PageFrameIndex)
  618. //++
  619. //VOID
  620. //MI_SET_PTE_DIRTY (
  621. // IN MMPTE PTE
  622. // );
  623. //
  624. // Routine Description:
  625. //
  626. // This macro sets the dirty bit(s) in the specified PTE.
  627. //
  628. // Arguments
  629. //
  630. // PTE - Supplies the PTE to set dirty.
  631. //
  632. // Return Value:
  633. //
  634. // None.
  635. //
  636. //--
  637. #define MI_SET_PTE_DIRTY(PTE) (PTE).u.Long |= HARDWARE_PTE_DIRTY_MASK
  638. //++
  639. //VOID
  640. //MI_SET_PTE_CLEAN (
  641. // IN MMPTE PTE
  642. // );
  643. //
  644. // Routine Description:
  645. //
  646. // This macro clears the dirty bit(s) in the specified PTE.
  647. //
  648. // Arguments
  649. //
  650. // PTE - Supplies the PTE to set clear.
  651. //
  652. // Return Value:
  653. //
  654. // None.
  655. //
  656. //--
  657. #define MI_SET_PTE_CLEAN(PTE) (PTE).u.Long &= ~HARDWARE_PTE_DIRTY_MASK
  658. //++
  659. //VOID
  660. //MI_IS_PTE_DIRTY (
  661. // IN MMPTE PTE
  662. // );
  663. //
  664. // Routine Description:
  665. //
  666. // This macro checks the dirty bit(s) in the specified PTE.
  667. //
  668. // Arguments
  669. //
  670. // PTE - Supplies the PTE to check.
  671. //
  672. // Return Value:
  673. //
  674. // TRUE if the page is dirty (modified), FALSE otherwise.
  675. //
  676. //--
  677. #define MI_IS_PTE_DIRTY(PTE) ((PTE).u.Hard.Dirty != 0)
  678. //++
  679. //VOID
  680. //MI_SET_GLOBAL_BIT_IF_SYSTEM (
  681. // OUT OUTPTE,
  682. // IN PPTE
  683. // );
  684. //
  685. // Routine Description:
  686. //
  687. // This macro sets the global bit if the pointer PTE is within
  688. // system space.
  689. //
  690. // Arguments
  691. //
  692. // OUTPTE - Supplies the PTE in which to build the valid PTE.
  693. //
  694. // PPTE - Supplies a pointer to the PTE becoming valid.
  695. //
  696. // Return Value:
  697. //
  698. // None.
  699. //
  700. //--
  701. #define MI_SET_GLOBAL_BIT_IF_SYSTEM(OUTPTE,PPTE) \
  702. if ((((PMMPTE)PPTE) > MiHighestUserPte) && \
  703. ((((PMMPTE)PPTE) <= MiGetPteAddress (PTE_BASE)) || \
  704. (((PMMPTE)PPTE) >= MiGetPteAddress (MM_SYSTEM_CACHE_WORKING_SET)))) { \
  705. (OUTPTE).u.Long |= MmPteGlobal.u.Long; \
  706. } \
  707. else { \
  708. (OUTPTE).u.Long &= ~MmPteGlobal.u.Long; \
  709. }
  710. //++
  711. //VOID
  712. //MI_SET_GLOBAL_STATE (
  713. // IN MMPTE PTE,
  714. // IN ULONG STATE
  715. // );
  716. //
  717. // Routine Description:
  718. //
  719. // This macro sets the global bit in the PTE based on the state argument.
  720. //
  721. // Arguments
  722. //
  723. // PTE - Supplies the PTE to set global state into.
  724. //
  725. // STATE - Supplies 1 if global, 0 if not.
  726. //
  727. // Return Value:
  728. //
  729. // None.
  730. //
  731. //--
  732. #define MI_SET_GLOBAL_STATE(PTE,STATE) \
  733. if (STATE) { \
  734. (PTE).u.Long |= MmPteGlobal.u.Long; \
  735. } \
  736. else { \
  737. (PTE).u.Long &= ~MmPteGlobal.u.Long; \
  738. }
  739. //++
  740. //VOID
  741. //MI_ENABLE_CACHING (
  742. // IN MMPTE PTE
  743. // );
  744. //
  745. // Routine Description:
  746. //
  747. // This macro takes a valid PTE and sets the caching state to be
  748. // enabled. This is performed by clearing the PCD and PWT bits in the PTE.
  749. //
  750. // Semantics of the overlap between PCD, PWT, and the
  751. // USWC memory type in the MTRR are:
  752. //
  753. // PCD PWT Mtrr Mem Type Effective Memory Type
  754. // 1 0 USWC USWC
  755. // 1 1 USWC UC
  756. //
  757. // Arguments
  758. //
  759. // PTE - Supplies a valid PTE.
  760. //
  761. // Return Value:
  762. //
  763. // None.
  764. //
  765. //--
  766. #define MI_ENABLE_CACHING(PTE) \
  767. { \
  768. ((PTE).u.Hard.CacheDisable = 0); \
  769. ((PTE).u.Hard.WriteThrough = 0); \
  770. }
  771. //++
  772. //VOID
  773. //MI_DISABLE_CACHING (
  774. // IN MMPTE PTE
  775. // );
  776. //
  777. // Routine Description:
  778. //
  779. // This macro takes a valid PTE and sets the caching state to be
  780. // disabled. This is performed by setting the PCD and PWT bits in the PTE.
  781. //
  782. // Semantics of the overlap between PCD, PWT, and the
  783. // USWC memory type in the MTRR are:
  784. //
  785. // PCD PWT Mtrr Mem Type Effective Memory Type
  786. // 1 0 USWC USWC
  787. // 1 1 USWC UC
  788. //
  789. // Since an effective memory type of UC is desired here,
  790. // the WT bit is set.
  791. //
  792. // Arguments
  793. //
  794. // PTE - Supplies a pointer to the valid PTE.
  795. //
  796. // Return Value:
  797. //
  798. // None.
  799. //
  800. //--
  801. #define MI_DISABLE_CACHING(PTE) \
  802. { \
  803. ((PTE).u.Hard.CacheDisable = 1); \
  804. ((PTE).u.Hard.WriteThrough = 1); \
  805. }
  806. //++
  807. //BOOLEAN
  808. //MI_IS_CACHING_DISABLED (
  809. // IN PMMPTE PPTE
  810. // );
  811. //
  812. // Routine Description:
  813. //
  814. // This macro takes a valid PTE and returns TRUE if caching is
  815. // disabled.
  816. //
  817. // Arguments
  818. //
  819. // PPTE - Supplies a pointer to the valid PTE.
  820. //
  821. // Return Value:
  822. //
  823. // TRUE if caching is disabled, FALSE if it is enabled.
  824. //
  825. //--
  826. #define MI_IS_CACHING_DISABLED(PPTE) \
  827. ((PPTE)->u.Hard.CacheDisable == 1)
  828. //++
  829. //VOID
  830. //MI_SET_PFN_DELETED (
  831. // IN PMMPFN PPFN
  832. // );
  833. //
  834. // Routine Description:
  835. //
  836. // This macro takes a pointer to a PFN element and indicates that
  837. // the PFN is no longer in use.
  838. //
  839. // Arguments
  840. //
  841. // PPFN - Supplies a pointer to the PFN element.
  842. //
  843. // Return Value:
  844. //
  845. // none.
  846. //
  847. //--
  848. #define MI_SET_PFN_DELETED(PPFN) \
  849. PPFN->PteAddress = (PMMPTE)(((ULONG_PTR)(PPFN->PteAddress)) | 0x1);
  850. //++
  851. //VOID
  852. //MI_MARK_PFN_UNDELETED (
  853. // IN PMMPFN PPFN
  854. // );
  855. //
  856. // Routine Description:
  857. //
  858. // This macro takes a pointer to a deleted PFN element and mark that
  859. // the PFN is not deleted.
  860. //
  861. // Arguments
  862. //
  863. // PPTE - Supplies a pointer to the PFN element.
  864. //
  865. // Return Value:
  866. //
  867. // none.
  868. //
  869. //--
  870. #define MI_MARK_PFN_UNDELETED(PPFN) \
  871. PPFN->PteAddress = (PMMPTE)((ULONG_PTR)PPFN->PteAddress & ~0x1);
  872. //++
  873. //BOOLEAN
  874. //MI_IS_PFN_DELETED (
  875. // IN PMMPFN PPFN
  876. // );
  877. //
  878. // Routine Description:
  879. //
  880. // This macro takes a pointer to a PFN element and determines if
  881. // the PFN is no longer in use.
  882. //
  883. // Arguments
  884. //
  885. // PPTE - Supplies a pointer to the PFN element.
  886. //
  887. // Return Value:
  888. //
  889. // TRUE if PFN is no longer used, FALSE if it is still being used.
  890. //
  891. //--
  892. #define MI_IS_PFN_DELETED(PPFN) \
  893. ((ULONG_PTR)(PPFN)->PteAddress & 0x1)
  894. //++
  895. //VOID
  896. //MI_CHECK_PAGE_ALIGNMENT (
  897. // IN ULONG PAGE,
  898. // IN PMMPTE PPTE
  899. // );
  900. //
  901. // Routine Description:
  902. //
  903. // This macro takes a PFN element number (Page) and checks to see
  904. // if the virtual alignment for the previous address of the page
  905. // is compatible with the new address of the page. If they are
  906. // not compatible, the D cache is flushed.
  907. //
  908. // Arguments
  909. //
  910. // PAGE - Supplies the PFN element.
  911. // PPTE - Supplies a pointer to the new PTE which will contain the page.
  912. //
  913. // Return Value:
  914. //
  915. // none.
  916. //
  917. //--
  918. // does nothing on x86.
  919. #define MI_CHECK_PAGE_ALIGNMENT(PAGE,PPTE)
  920. //++
  921. //VOID
  922. //MI_INITIALIZE_HYPERSPACE_MAP (
  923. // VOID
  924. // );
  925. //
  926. // Routine Description:
  927. //
  928. // This macro initializes the PTEs reserved for double mapping within
  929. // hyperspace.
  930. //
  931. // Arguments
  932. //
  933. // None.
  934. //
  935. // Return Value:
  936. //
  937. // None.
  938. //
  939. //--
  940. // does nothing on x86.
  941. #define MI_INITIALIZE_HYPERSPACE_MAP(INDEX)
  942. //++
  943. //ULONG
  944. //MI_GET_PAGE_COLOR_FROM_PTE (
  945. // IN PMMPTE PTEADDRESS
  946. // );
  947. //
  948. // Routine Description:
  949. //
  950. // This macro determines the page's color based on the PTE address
  951. // that maps the page.
  952. //
  953. // Arguments
  954. //
  955. // PTEADDRESS - Supplies the PTE address the page is (or was) mapped at.
  956. //
  957. // Return Value:
  958. //
  959. // The page's color.
  960. //
  961. //--
  962. #define MI_GET_PAGE_COLOR_FROM_PTE(PTEADDRESS) \
  963. ((ULONG)((MI_SYSTEM_PAGE_COLOR++) & MmSecondaryColorMask) | MI_CURRENT_NODE_COLOR)
  964. //++
  965. //ULONG
  966. //MI_GET_PAGE_COLOR_FROM_VA (
  967. // IN PVOID ADDRESS
  968. // );
  969. //
  970. // Routine Description:
  971. //
  972. // This macro determines the page's color based on the PTE address
  973. // that maps the page.
  974. //
  975. // Arguments
  976. //
  977. // ADDRESS - Supplies the address the page is (or was) mapped at.
  978. //
  979. // Return Value:
  980. //
  981. // The page's color.
  982. //
  983. //--
  984. #define MI_GET_PAGE_COLOR_FROM_VA(ADDRESS) \
  985. ((ULONG)((MI_SYSTEM_PAGE_COLOR++) & MmSecondaryColorMask) | MI_CURRENT_NODE_COLOR)
  986. //++
  987. //ULONG
  988. //MI_GET_PAGE_COLOR_FROM_SESSION (
  989. // IN PMM_SESSION_SPACE SessionSpace
  990. // );
  991. //
  992. // Routine Description:
  993. //
  994. // This macro determines the page's color based on the PTE address
  995. // that maps the page.
  996. //
  997. // Arguments
  998. //
  999. // SessionSpace - Supplies the session space the page will be mapped into.
  1000. //
  1001. // Return Value:
  1002. //
  1003. // The page's color.
  1004. //
  1005. //--
  1006. #define MI_GET_PAGE_COLOR_FROM_SESSION(_SessionSpace) \
  1007. ((ULONG)((_SessionSpace->Color++) & MmSecondaryColorMask) | MI_CURRENT_NODE_COLOR)
  1008. //++
  1009. //ULONG
  1010. //MI_PAGE_COLOR_PTE_PROCESS (
  1011. // IN PMMPTE PTE,
  1012. // IN PUSHORT COLOR
  1013. // );
  1014. //
  1015. // Routine Description:
  1016. //
  1017. // Select page color for this process.
  1018. //
  1019. // Arguments
  1020. //
  1021. // PTE Not used.
  1022. // COLOR Value from which color is determined. This
  1023. // variable is incremented.
  1024. //
  1025. // Return Value:
  1026. //
  1027. // Page color.
  1028. //
  1029. //--
  1030. #define MI_PAGE_COLOR_PTE_PROCESS(PTE,COLOR) \
  1031. (((ULONG)((*(COLOR))++) & MmSecondaryColorMask) | MI_CURRENT_NODE_COLOR)
  1032. //++
  1033. //ULONG
  1034. //MI_PAGE_COLOR_VA_PROCESS (
  1035. // IN PVOID ADDRESS,
  1036. // IN PEPROCESS COLOR
  1037. // );
  1038. //
  1039. // Routine Description:
  1040. //
  1041. // This macro determines the page's color based on the PTE address
  1042. // that maps the page.
  1043. //
  1044. // Arguments
  1045. //
  1046. // ADDRESS - Supplies the address the page is (or was) mapped at.
  1047. //
  1048. // Return Value:
  1049. //
  1050. // The page's color.
  1051. //
  1052. //--
  1053. #define MI_PAGE_COLOR_VA_PROCESS(ADDRESS,COLOR) \
  1054. (((ULONG)((*(COLOR))++) & MmSecondaryColorMask) | MI_CURRENT_NODE_COLOR)
  1055. //++
  1056. //ULONG
  1057. //MI_GET_NEXT_COLOR (
  1058. // IN ULONG COLOR
  1059. // );
  1060. //
  1061. // Routine Description:
  1062. //
  1063. // This macro returns the next color in the sequence.
  1064. //
  1065. // Arguments
  1066. //
  1067. // COLOR - Supplies the color to return the next of.
  1068. //
  1069. // Return Value:
  1070. //
  1071. // Next color in sequence.
  1072. //
  1073. //--
  1074. #define MI_GET_NEXT_COLOR(COLOR) ((COLOR + 1) & MM_COLOR_MASK)
  1075. //++
  1076. //ULONG
  1077. //MI_GET_PREVIOUS_COLOR (
  1078. // IN ULONG COLOR
  1079. // );
  1080. //
  1081. // Routine Description:
  1082. //
  1083. // This macro returns the previous color in the sequence.
  1084. //
  1085. // Arguments
  1086. //
  1087. // COLOR - Supplies the color to return the previous of.
  1088. //
  1089. // Return Value:
  1090. //
  1091. // Previous color in sequence.
  1092. //
  1093. //--
  1094. #define MI_GET_PREVIOUS_COLOR(COLOR) (0)
  1095. #define MI_GET_SECONDARY_COLOR(PAGE,PFN) (PAGE & MmSecondaryColorMask)
  1096. #define MI_GET_COLOR_FROM_SECONDARY(SECONDARY_COLOR) (0)
  1097. //++
  1098. //VOID
  1099. //MI_GET_MODIFIED_PAGE_BY_COLOR (
  1100. // OUT ULONG PAGE,
  1101. // IN ULONG COLOR
  1102. // );
  1103. //
  1104. // Routine Description:
  1105. //
  1106. // This macro returns the first page destined for a paging
  1107. // file with the desired color. It does NOT remove the page
  1108. // from its list.
  1109. //
  1110. // Arguments
  1111. //
  1112. // PAGE - Returns the page located, the value MM_EMPTY_LIST is
  1113. // returned if there is no page of the specified color.
  1114. //
  1115. // COLOR - Supplies the color of page to locate.
  1116. //
  1117. // Return Value:
  1118. //
  1119. // none.
  1120. //
  1121. //--
  1122. #define MI_GET_MODIFIED_PAGE_BY_COLOR(PAGE,COLOR) \
  1123. PAGE = MmModifiedPageListByColor[COLOR].Flink
  1124. //++
  1125. //VOID
  1126. //MI_GET_MODIFIED_PAGE_ANY_COLOR (
  1127. // OUT ULONG PAGE,
  1128. // IN OUT ULONG COLOR
  1129. // );
  1130. //
  1131. // Routine Description:
  1132. //
  1133. // This macro returns the first page destined for a paging
  1134. // file with the desired color. If not page of the desired
  1135. // color exists, all colored lists are searched for a page.
  1136. // It does NOT remove the page from its list.
  1137. //
  1138. // Arguments
  1139. //
  1140. // PAGE - Returns the page located, the value MM_EMPTY_LIST is
  1141. // returned if there is no page of the specified color.
  1142. //
  1143. // COLOR - Supplies the color of page to locate and returns the
  1144. // color of the page located.
  1145. //
  1146. // Return Value:
  1147. //
  1148. // none.
  1149. //
  1150. //--
  1151. #define MI_GET_MODIFIED_PAGE_ANY_COLOR(PAGE,COLOR) \
  1152. { \
  1153. if (MmTotalPagesForPagingFile == 0) { \
  1154. PAGE = MM_EMPTY_LIST; \
  1155. } else { \
  1156. PAGE = MmModifiedPageListByColor[COLOR].Flink; \
  1157. } \
  1158. }
  1159. //++
  1160. //VOID
  1161. //MI_MAKE_VALID_PTE_WRITE_COPY (
  1162. // IN OUT PMMPTE PTE
  1163. // );
  1164. //
  1165. // Routine Description:
  1166. //
  1167. // This macro checks to see if the PTE indicates that the
  1168. // page is writable and if so it clears the write bit and
  1169. // sets the copy-on-write bit.
  1170. //
  1171. // Arguments
  1172. //
  1173. // PTE - Supplies the PTE to operate upon.
  1174. //
  1175. // Return Value:
  1176. //
  1177. // None.
  1178. //
  1179. //--
  1180. #if defined(NT_UP)
  1181. #define MI_MAKE_VALID_PTE_WRITE_COPY(PPTE) \
  1182. if ((PPTE)->u.Hard.Write == 1) { \
  1183. (PPTE)->u.Hard.CopyOnWrite = 1; \
  1184. (PPTE)->u.Hard.Write = 0; \
  1185. }
  1186. #else
  1187. #define MI_MAKE_VALID_PTE_WRITE_COPY(PPTE) \
  1188. if ((PPTE)->u.Hard.Write == 1) { \
  1189. (PPTE)->u.Hard.CopyOnWrite = 1; \
  1190. (PPTE)->u.Hard.Write = 0; \
  1191. (PPTE)->u.Hard.Writable = 0; \
  1192. }
  1193. #endif
  1194. //++
  1195. //ULONG
  1196. //MI_DETERMINE_OWNER (
  1197. // IN MMPTE PPTE
  1198. // );
  1199. //
  1200. // Routine Description:
  1201. //
  1202. // This macro examines the virtual address of the PTE and determines
  1203. // if the PTE resides in system space or user space.
  1204. //
  1205. // Arguments
  1206. //
  1207. // PTE - Supplies the PTE to operate upon.
  1208. //
  1209. // Return Value:
  1210. //
  1211. // 1 if the owner is USER_MODE, 0 if the owner is KERNEL_MODE.
  1212. //
  1213. //--
  1214. #define MI_DETERMINE_OWNER(PPTE) \
  1215. ((((PPTE) <= MiHighestUserPte) || \
  1216. ((PPTE) >= MiGetPdeAddress(NULL) && \
  1217. ((PPTE) <= MiHighestUserPde))) ? 1 : 0)
  1218. //++
  1219. //VOID
  1220. //MI_SET_ACCESSED_IN_PTE (
  1221. // IN OUT MMPTE PPTE
  1222. // );
  1223. //
  1224. // Routine Description:
  1225. //
  1226. // This macro sets the ACCESSED field in the PTE.
  1227. //
  1228. // Arguments
  1229. //
  1230. // PTE - Supplies the PTE to operate upon.
  1231. //
  1232. // Return Value:
  1233. //
  1234. // None
  1235. //
  1236. //--
  1237. #define MI_SET_ACCESSED_IN_PTE(PPTE,ACCESSED) \
  1238. ((PPTE)->u.Hard.Accessed = ACCESSED)
  1239. //++
  1240. //ULONG
  1241. //MI_GET_ACCESSED_IN_PTE (
  1242. // IN OUT MMPTE PPTE
  1243. // );
  1244. //
  1245. // Routine Description:
  1246. //
  1247. // This macro returns the state of the ACCESSED field in the PTE.
  1248. //
  1249. // Arguments
  1250. //
  1251. // PTE - Supplies the PTE to operate upon.
  1252. //
  1253. // Return Value:
  1254. //
  1255. // The state of the ACCESSED field.
  1256. //
  1257. //--
  1258. #define MI_GET_ACCESSED_IN_PTE(PPTE) ((PPTE)->u.Hard.Accessed)
  1259. //++
  1260. //VOID
  1261. //MI_SET_OWNER_IN_PTE (
  1262. // IN PMMPTE PPTE
  1263. // IN ULONG OWNER
  1264. // );
  1265. //
  1266. // Routine Description:
  1267. //
  1268. // This macro sets the owner field in the PTE.
  1269. //
  1270. // Arguments
  1271. //
  1272. // PTE - Supplies the PTE to operate upon.
  1273. //
  1274. // Return Value:
  1275. //
  1276. // None.
  1277. //
  1278. //--
  1279. #define MI_SET_OWNER_IN_PTE(PPTE,OWNER) ((PPTE)->u.Hard.Owner = OWNER)
  1280. //++
  1281. //ULONG
  1282. //MI_GET_OWNER_IN_PTE (
  1283. // IN PMMPTE PPTE
  1284. // );
  1285. //
  1286. // Routine Description:
  1287. //
  1288. // This macro gets the owner field from the PTE.
  1289. //
  1290. // Arguments
  1291. //
  1292. // PTE - Supplies the PTE to operate upon.
  1293. //
  1294. // Return Value:
  1295. //
  1296. // The state of the OWNER field.
  1297. //
  1298. //--
  1299. #define MI_GET_OWNER_IN_PTE(PPTE) ((PPTE)->u.Hard.Owner)
  1300. //
  1301. // bit mask to clear out fields in a PTE to or in paging file location.
  1302. //
  1303. #define CLEAR_FOR_PAGE_FILE 0x000003E0
  1304. //++
  1305. //VOID
  1306. //MI_SET_PAGING_FILE_INFO (
  1307. // OUT MMPTE OUTPTE,
  1308. // IN MMPTE PPTE,
  1309. // IN ULONG FILEINFO,
  1310. // IN ULONG OFFSET
  1311. // );
  1312. //
  1313. // Routine Description:
  1314. //
  1315. // This macro sets into the specified PTE the supplied information
  1316. // to indicate where the backing store for the page is located.
  1317. //
  1318. // Arguments
  1319. //
  1320. // OUTPTE - Supplies the PTE in which to store the result.
  1321. //
  1322. // PTE - Supplies the PTE to operate upon.
  1323. //
  1324. // FILEINFO - Supplies the number of the paging file.
  1325. //
  1326. // OFFSET - Supplies the offset into the paging file.
  1327. //
  1328. // Return Value:
  1329. //
  1330. // None.
  1331. //
  1332. //--
  1333. #define MI_SET_PAGING_FILE_INFO(OUTPTE,PPTE,FILEINFO,OFFSET) \
  1334. (OUTPTE).u.Long = (PPTE).u.Long; \
  1335. (OUTPTE).u.Long &= CLEAR_FOR_PAGE_FILE; \
  1336. (OUTPTE).u.Long |= (FILEINFO << 1); \
  1337. (OUTPTE).u.Soft.PageFileHigh = (OFFSET);
  1338. //++
  1339. //PMMPTE
  1340. //MiPteToProto (
  1341. // IN OUT MMPTE PPTE,
  1342. // IN ULONG FILEINFO,
  1343. // IN ULONG OFFSET
  1344. // );
  1345. //
  1346. // Routine Description:
  1347. //
  1348. // This macro returns the address of the corresponding prototype which
  1349. // was encoded earlier into the supplied PTE.
  1350. //
  1351. // Arguments
  1352. //
  1353. // lpte - Supplies the PTE to operate upon.
  1354. //
  1355. // Return Value:
  1356. //
  1357. // Pointer to the prototype PTE that backs this PTE.
  1358. //
  1359. //--
  1360. #define MiPteToProto(lpte) \
  1361. ((PMMPTE)(ULONG_PTR)((lpte)->u.Proto.ProtoAddress))
  1362. //++
  1363. //MMPTE
  1364. //MiProtoAddressForPte (
  1365. // IN PMMPTE proto_va
  1366. // );
  1367. //
  1368. // Routine Description:
  1369. //
  1370. // This macro sets into the specified PTE the supplied information
  1371. // to indicate where the backing store for the page is located.
  1372. // MiProtoAddressForPte returns the bit field to OR into the PTE to
  1373. // reference a prototype PTE. And set the protoPTE bit,
  1374. //
  1375. // N.B. This macro is dependent on the layout of the prototype PTE.
  1376. //
  1377. // Arguments
  1378. //
  1379. // proto_va - Supplies the address of the prototype PTE.
  1380. //
  1381. // Return Value:
  1382. //
  1383. // Mask to set into the PTE.
  1384. //
  1385. //--
  1386. #define MiProtoAddressForPte(proto_va) \
  1387. (((ULONGLONG)proto_va << 32) | MM_PTE_PROTOTYPE_MASK)
  1388. //++
  1389. //ULONG
  1390. //MiProtoAddressForKernelPte (
  1391. // IN PMMPTE proto_va
  1392. // );
  1393. //
  1394. // Routine Description:
  1395. //
  1396. // This macro sets into the specified PTE the supplied information
  1397. // to indicate where the backing store for the page is located.
  1398. // MiProtoAddressForPte returns the bit field to OR into the PTE to
  1399. // reference a prototype PTE. And set the protoPTE bit,
  1400. // MM_PTE_PROTOTYPE_MASK.
  1401. //
  1402. // This macro also sets any other information (such as global bits)
  1403. // required for kernel mode PTEs.
  1404. //
  1405. // Arguments
  1406. //
  1407. // proto_va - Supplies the address of the prototype PTE.
  1408. //
  1409. // Return Value:
  1410. //
  1411. // Mask to set into the PTE.
  1412. //
  1413. //--
  1414. // not different on x86.
  1415. #define MiProtoAddressForKernelPte(proto_va) MiProtoAddressForPte(proto_va)
  1416. //++
  1417. //PSUBSECTION
  1418. //MiGetSubsectionAddress (
  1419. // IN PMMPTE lpte
  1420. // );
  1421. //
  1422. // Routine Description:
  1423. //
  1424. // This macro takes a PTE and returns the address of the subsection that
  1425. // the PTE refers to. Subsections are quadword structures allocated
  1426. // from nonpaged pool.
  1427. //
  1428. // Arguments
  1429. //
  1430. // lpte - Supplies the PTE to operate upon.
  1431. //
  1432. // Return Value:
  1433. //
  1434. // A pointer to the subsection referred to by the supplied PTE.
  1435. //
  1436. //--
  1437. #define MiGetSubsectionAddress(lpte) \
  1438. ((PSUBSECTION)(ULONG_PTR)((lpte)->u.Subsect.SubsectionAddress))
  1439. //++
  1440. //ULONG
  1441. //MiGetSubsectionAddressForPte (
  1442. // IN PSUBSECTION VA
  1443. // );
  1444. //
  1445. // Routine Description:
  1446. //
  1447. // This macro takes the address of a subsection and encodes it for use
  1448. // in a PTE.
  1449. //
  1450. // Arguments
  1451. //
  1452. // VA - Supplies a pointer to the subsection to encode.
  1453. //
  1454. // Return Value:
  1455. //
  1456. // The mask to set into the PTE to make it reference the supplied
  1457. // subsection.
  1458. //
  1459. //--
  1460. #define MiGetSubsectionAddressForPte(VA) ((ULONGLONG)VA << 32)
  1461. //++
  1462. //PMMPTE
  1463. //MiGetPdeAddress (
  1464. // IN PVOID va
  1465. // );
  1466. //
  1467. // Routine Description:
  1468. //
  1469. // MiGetPdeAddress returns the address of the PDE which maps the
  1470. // given virtual address.
  1471. //
  1472. // Arguments
  1473. //
  1474. // Va - Supplies the virtual address to locate the PDE for.
  1475. //
  1476. // Return Value:
  1477. //
  1478. // The address of the PDE.
  1479. //
  1480. //--
  1481. #define MiGetPdeAddress(va) ((PMMPTE)(PDE_BASE + ((((ULONG)(va)) >> 21) << 3)))
  1482. //++
  1483. //PMMPTE
  1484. //MiGetPteAddress (
  1485. // IN PVOID va
  1486. // );
  1487. //
  1488. // Routine Description:
  1489. //
  1490. // MiGetPteAddress returns the address of the PTE which maps the
  1491. // given virtual address.
  1492. //
  1493. // Arguments
  1494. //
  1495. // Va - Supplies the virtual address to locate the PTE for.
  1496. //
  1497. // Return Value:
  1498. //
  1499. // The address of the PTE.
  1500. //
  1501. //--
  1502. #define MiGetPteAddress(va) ((PMMPTE)(PTE_BASE + ((((ULONG)(va)) >> 12) << 3)))
  1503. //++
  1504. //ULONG
  1505. //MiGetPpeOffset (
  1506. // IN PVOID va
  1507. // );
  1508. //
  1509. // Routine Description:
  1510. //
  1511. // MiGetPpeOffset returns the offset into a page root
  1512. // for a given virtual address.
  1513. //
  1514. // Arguments
  1515. //
  1516. // Va - Supplies the virtual address to locate the offset for.
  1517. //
  1518. // Return Value:
  1519. //
  1520. // The offset into the page root table the corresponding PPE is at.
  1521. //
  1522. //--
  1523. #define MiGetPpeOffset(va) (0)
  1524. //++
  1525. //ULONG
  1526. //MiGetPdPteOffset (
  1527. // IN PVOID va
  1528. // );
  1529. //
  1530. // Routine Description:
  1531. //
  1532. // MiGetPdPteOffset returns the offset into a page directory
  1533. // pointer PTE table for a given virtual address.
  1534. //
  1535. // Arguments
  1536. //
  1537. // Va - Supplies the virtual address to locate the offset for.
  1538. //
  1539. // Return Value:
  1540. //
  1541. // The offset into the page directory pointer PTE table the corresponding
  1542. // PDE is at.
  1543. //
  1544. //--
  1545. #define MiGetPdPteOffset(va) (((ULONG)(va)) >> 30)
  1546. //++
  1547. //ULONG
  1548. //MiGetPdeOffset (
  1549. // IN PVOID va
  1550. // );
  1551. //
  1552. // Routine Description:
  1553. //
  1554. // MiGetPdeOffset returns the offset into a page directory
  1555. // for a given virtual address.
  1556. //
  1557. // Arguments
  1558. //
  1559. // Va - Supplies the virtual address to locate the offset for.
  1560. //
  1561. // Return Value:
  1562. //
  1563. // The offset into the page directory table the corresponding PDE is at.
  1564. //
  1565. //--
  1566. #define MiGetPdeOffset(va) ((((ULONG)(va)) >> 21) & 0x1FF)
  1567. //++
  1568. //ULONG
  1569. //MiGetPdeIndex (
  1570. // IN PVOID va
  1571. // );
  1572. //
  1573. // Routine Description:
  1574. //
  1575. // MiGetPdeIndex returns the page directory index
  1576. // for a given virtual address.
  1577. //
  1578. // N.B. This does not mask off PPE bits.
  1579. //
  1580. // Arguments
  1581. //
  1582. // Va - Supplies the virtual address to locate the offset for.
  1583. //
  1584. // Return Value:
  1585. //
  1586. // The index into the page directory - ie: the virtual page table number.
  1587. // This is different from the page directory offset because this spans
  1588. // page directories on supported platforms.
  1589. //
  1590. //--
  1591. #define MiGetPdeIndex(va) (((ULONG)(va)) >> 21)
  1592. //++
  1593. //ULONG
  1594. //MiGetPteOffset (
  1595. // IN PVOID va
  1596. // );
  1597. //
  1598. // Routine Description:
  1599. //
  1600. // MiGetPteOffset returns the offset into a page table page
  1601. // for a given virtual address.
  1602. //
  1603. // Arguments
  1604. //
  1605. // Va - Supplies the virtual address to locate the offset for.
  1606. //
  1607. // Return Value:
  1608. //
  1609. // The offset into the page table page table the corresponding PTE is at.
  1610. //
  1611. //--
  1612. #define MiGetPteOffset(va) ((((ULONG)(va)) << 11) >> 23)
  1613. //++
  1614. //PVOID
  1615. //MiGetVirtualAddressMappedByPpe (
  1616. // IN PMMPTE PTE
  1617. // );
  1618. //
  1619. // Routine Description:
  1620. //
  1621. // MiGetVirtualAddressMappedByPpe returns the virtual address
  1622. // which is mapped by a given PPE address.
  1623. //
  1624. // Arguments
  1625. //
  1626. // PPE - Supplies the PPE to get the virtual address for.
  1627. //
  1628. // Return Value:
  1629. //
  1630. // Virtual address mapped by the PPE.
  1631. //
  1632. //--
  1633. #define MiGetVirtualAddressMappedByPpe(PPE) (NULL)
  1634. //++
  1635. //PVOID
  1636. //MiGetVirtualAddressMappedByPde (
  1637. // IN PMMPTE PTE
  1638. // );
  1639. //
  1640. // Routine Description:
  1641. //
  1642. // MiGetVirtualAddressMappedByPde returns the virtual address
  1643. // which is mapped by a given PDE address.
  1644. //
  1645. // Arguments
  1646. //
  1647. // PDE - Supplies the PDE to get the virtual address for.
  1648. //
  1649. // Return Value:
  1650. //
  1651. // Virtual address mapped by the PDE.
  1652. //
  1653. //--
  1654. #define MiGetVirtualAddressMappedByPde(PDE) ((PVOID)((ULONG)(PDE) << 18))
  1655. //++
  1656. //PVOID
  1657. //MiGetVirtualAddressMappedByPte (
  1658. // IN PMMPTE PTE
  1659. // );
  1660. //
  1661. // Routine Description:
  1662. //
  1663. // MiGetVirtualAddressMappedByPte returns the virtual address
  1664. // which is mapped by a given PTE address.
  1665. //
  1666. // Arguments
  1667. //
  1668. // PTE - Supplies the PTE to get the virtual address for.
  1669. //
  1670. // Return Value:
  1671. //
  1672. // Virtual address mapped by the PTE.
  1673. //
  1674. //--
  1675. #define MiGetVirtualAddressMappedByPte(PTE) ((PVOID)((ULONG)(PTE) << 9))
  1676. //++
  1677. //LOGICAL
  1678. //MiIsVirtualAddressOnPpeBoundary (
  1679. // IN PVOID VA
  1680. // );
  1681. //
  1682. // Routine Description:
  1683. //
  1684. // MiIsVirtualAddressOnPpeBoundary returns TRUE if the virtual address is
  1685. // on a page directory entry boundary.
  1686. //
  1687. // Arguments
  1688. //
  1689. // VA - Supplies the virtual address to check.
  1690. //
  1691. // Return Value:
  1692. //
  1693. // TRUE if on a boundary, FALSE if not.
  1694. //
  1695. //--
  1696. #define MiIsVirtualAddressOnPpeBoundary(VA) (FALSE)
  1697. //++
  1698. //LOGICAL
  1699. //MiIsVirtualAddressOnPdeBoundary (
  1700. // IN PVOID VA
  1701. // );
  1702. //
  1703. // Routine Description:
  1704. //
  1705. // MiIsVirtualAddressOnPdeBoundary returns TRUE if the virtual address is
  1706. // on a page directory entry boundary.
  1707. //
  1708. // Arguments
  1709. //
  1710. // VA - Supplies the virtual address to check.
  1711. //
  1712. // Return Value:
  1713. //
  1714. // TRUE if on a 4MB PDE boundary, FALSE if not.
  1715. //
  1716. //--
  1717. #define MiIsVirtualAddressOnPdeBoundary(VA) (((ULONG_PTR)(VA) & PAGE_DIRECTORY_MASK) == 0)
  1718. //++
  1719. //LOGICAL
  1720. //MiIsPteOnPdeBoundary (
  1721. // IN PVOID PTE
  1722. // );
  1723. //
  1724. // Routine Description:
  1725. //
  1726. // MiIsPteOnPdeBoundary returns TRUE if the PTE is
  1727. // on a page directory entry boundary.
  1728. //
  1729. // Arguments
  1730. //
  1731. // PTE - Supplies the PTE to check.
  1732. //
  1733. // Return Value:
  1734. //
  1735. // TRUE if on a 4MB PDE boundary, FALSE if not.
  1736. //
  1737. //--
  1738. #define MiIsPteOnPdeBoundary(PTE) (((ULONG_PTR)(PTE) & (PAGE_SIZE - 1)) == 0)
  1739. //++
  1740. //ULONG
  1741. //GET_PAGING_FILE_NUMBER (
  1742. // IN MMPTE PTE
  1743. // );
  1744. //
  1745. // Routine Description:
  1746. //
  1747. // This macro extracts the paging file number from a PTE.
  1748. //
  1749. // Arguments
  1750. //
  1751. // PTE - Supplies the PTE to operate upon.
  1752. //
  1753. // Return Value:
  1754. //
  1755. // The paging file number.
  1756. //
  1757. //--
  1758. #define GET_PAGING_FILE_NUMBER(PTE) ((ULONG)((((PTE).u.Long) >> 1) & 0x0000000F))
  1759. //++
  1760. //ULONG
  1761. //GET_PAGING_FILE_OFFSET (
  1762. // IN MMPTE PTE
  1763. // );
  1764. //
  1765. // Routine Description:
  1766. //
  1767. // This macro extracts the offset into the paging file from a PTE.
  1768. //
  1769. // Arguments
  1770. //
  1771. // PTE - Supplies the PTE to operate upon.
  1772. //
  1773. // Return Value:
  1774. //
  1775. // The paging file offset.
  1776. //
  1777. //--
  1778. #define GET_PAGING_FILE_OFFSET(PTE) ((ULONG)((PTE).u.Soft.PageFileHigh))
  1779. //++
  1780. //ULONG
  1781. //IS_PTE_NOT_DEMAND_ZERO (
  1782. // IN PMMPTE PPTE
  1783. // );
  1784. //
  1785. // Routine Description:
  1786. //
  1787. // This macro checks to see if a given PTE is NOT a demand zero PTE.
  1788. //
  1789. // Arguments
  1790. //
  1791. // PTE - Supplies the PTE to operate upon.
  1792. //
  1793. // Return Value:
  1794. //
  1795. // Returns 0 if the PTE is demand zero, non-zero otherwise.
  1796. //
  1797. //--
  1798. #define IS_PTE_NOT_DEMAND_ZERO(PTE) ((PTE).u.Long & ~0x3FE)
  1799. //++
  1800. //VOID
  1801. //MI_MAKING_VALID_PTE_INVALID(
  1802. // IN PMMPTE PPTE
  1803. // );
  1804. //
  1805. // Routine Description:
  1806. //
  1807. // Prepare to make a single valid PTE invalid.
  1808. // No action is required on x86.
  1809. //
  1810. // Arguments
  1811. //
  1812. // SYSTEM_WIDE - Supplies TRUE if this will happen on all processors.
  1813. //
  1814. // Return Value:
  1815. //
  1816. // None.
  1817. //
  1818. //--
  1819. #define MI_MAKING_VALID_PTE_INVALID(SYSTEM_WIDE)
  1820. //++
  1821. //VOID
  1822. //MI_MAKING_VALID_MULTIPLE_PTES_INVALID(
  1823. // IN PMMPTE PPTE
  1824. // );
  1825. //
  1826. // Routine Description:
  1827. //
  1828. // Prepare to make multiple valid PTEs invalid.
  1829. // No action is required on x86.
  1830. //
  1831. // Arguments
  1832. //
  1833. // SYSTEM_WIDE - Supplies TRUE if this will happen on all processors.
  1834. //
  1835. // Return Value:
  1836. //
  1837. // None.
  1838. //
  1839. //--
  1840. #define MI_MAKING_MULTIPLE_PTES_INVALID(SYSTEM_WIDE)
  1841. //++
  1842. //VOID
  1843. //MI_MAKE_PROTECT_WRITE_COPY (
  1844. // IN OUT MMPTE PPTE
  1845. // );
  1846. //
  1847. // Routine Description:
  1848. //
  1849. // This macro makes a writable PTE a writable-copy PTE.
  1850. //
  1851. // Arguments
  1852. //
  1853. // PTE - Supplies the PTE to operate upon.
  1854. //
  1855. // Return Value:
  1856. //
  1857. // NONE
  1858. //
  1859. //--
  1860. #define MI_MAKE_PROTECT_WRITE_COPY(PTE) \
  1861. if ((PTE).u.Soft.Protection & MM_PROTECTION_WRITE_MASK) { \
  1862. (PTE).u.Long |= MM_PROTECTION_COPY_MASK << MM_PROTECT_FIELD_SHIFT; \
  1863. }
  1864. //++
  1865. //VOID
  1866. //MI_SET_PAGE_DIRTY(
  1867. // IN PMMPTE PPTE,
  1868. // IN PVOID VA,
  1869. // IN PVOID PFNHELD
  1870. // );
  1871. //
  1872. // Routine Description:
  1873. //
  1874. // This macro sets the dirty bit (and release page file space).
  1875. //
  1876. // Arguments
  1877. //
  1878. // PPTE - Supplies a pointer to the PTE that corresponds to VA.
  1879. //
  1880. // VA - Supplies a the virtual address of the page fault.
  1881. //
  1882. // PFNHELD - Supplies TRUE if the PFN lock is held.
  1883. //
  1884. // Return Value:
  1885. //
  1886. // None.
  1887. //
  1888. //--
  1889. #if defined(NT_UP)
  1890. #define MI_SET_PAGE_DIRTY(PPTE,VA,PFNHELD)
  1891. #else
  1892. #define MI_SET_PAGE_DIRTY(PPTE,VA,PFNHELD) \
  1893. if ((PPTE)->u.Hard.Dirty == 1) { \
  1894. MiSetDirtyBit ((VA),(PPTE),(PFNHELD)); \
  1895. }
  1896. #endif
  1897. //++
  1898. //VOID
  1899. //MI_NO_FAULT_FOUND(
  1900. // IN FAULTSTATUS,
  1901. // IN PMMPTE PPTE,
  1902. // IN PVOID VA,
  1903. // IN PVOID PFNHELD
  1904. // );
  1905. //
  1906. // Routine Description:
  1907. //
  1908. // This macro handles the case when a page fault is taken and no
  1909. // PTE with the valid bit clear is found.
  1910. //
  1911. // Arguments
  1912. //
  1913. // FAULTSTATUS - Supplies the fault status.
  1914. //
  1915. // PPTE - Supplies a pointer to the PTE that corresponds to VA.
  1916. //
  1917. // VA - Supplies a the virtual address of the page fault.
  1918. //
  1919. // PFNHELD - Supplies TRUE if the PFN lock is held.
  1920. //
  1921. // Return Value:
  1922. //
  1923. // None.
  1924. //
  1925. //--
  1926. #if defined(NT_UP)
  1927. #define MI_NO_FAULT_FOUND(FAULTSTATUS,PPTE,VA,PFNHELD)
  1928. #else
  1929. #define MI_NO_FAULT_FOUND(FAULTSTATUS,PPTE,VA,PFNHELD) \
  1930. if ((MI_FAULT_STATUS_INDICATES_WRITE(FAULTSTATUS)) && ((PPTE)->u.Hard.Dirty == 0)) { \
  1931. MiSetDirtyBit ((VA),(PPTE),(PFNHELD)); \
  1932. }
  1933. #endif
  1934. //++
  1935. //ULONG
  1936. //MI_CAPTURE_DIRTY_BIT_TO_PFN (
  1937. // IN PMMPTE PPTE,
  1938. // IN PMMPFN PPFN
  1939. // );
  1940. //
  1941. // Routine Description:
  1942. //
  1943. // This macro gets captures the state of the dirty bit to the PFN
  1944. // and frees any associated page file space if the PTE has been
  1945. // modified element.
  1946. //
  1947. // NOTE - THE PFN LOCK MUST BE HELD!
  1948. //
  1949. // Arguments
  1950. //
  1951. // PPTE - Supplies the PTE to operate upon.
  1952. //
  1953. // PPFN - Supplies a pointer to the PFN database element that corresponds
  1954. // to the page mapped by the PTE.
  1955. //
  1956. // Return Value:
  1957. //
  1958. // None.
  1959. //
  1960. //--
  1961. #define MI_CAPTURE_DIRTY_BIT_TO_PFN(PPTE,PPFN) \
  1962. ASSERT (KeGetCurrentIrql() > APC_LEVEL); \
  1963. if (((PPFN)->u3.e1.Modified == 0) && \
  1964. ((PPTE)->u.Hard.Dirty != 0)) { \
  1965. MI_SET_MODIFIED (PPFN, 1, 0x18); \
  1966. if (((PPFN)->OriginalPte.u.Soft.Prototype == 0) && \
  1967. ((PPFN)->u3.e1.WriteInProgress == 0)) { \
  1968. MiReleasePageFileSpace ((PPFN)->OriginalPte); \
  1969. (PPFN)->OriginalPte.u.Soft.PageFileHigh = 0; \
  1970. } \
  1971. }
  1972. //++
  1973. //BOOLEAN
  1974. //MI_IS_PHYSICAL_ADDRESS (
  1975. // IN PVOID VA
  1976. // );
  1977. //
  1978. // Routine Description:
  1979. //
  1980. // This macro determines if a given virtual address is really a
  1981. // physical address.
  1982. //
  1983. // Arguments
  1984. //
  1985. // VA - Supplies the virtual address.
  1986. //
  1987. // Return Value:
  1988. //
  1989. // FALSE if it is not a physical address, TRUE if it is.
  1990. //
  1991. //--
  1992. #define MI_IS_PHYSICAL_ADDRESS(Va) \
  1993. ((MiGetPdeAddress(Va)->u.Long & 0x81) == 0x81)
  1994. //++
  1995. //ULONG
  1996. //MI_CONVERT_PHYSICAL_TO_PFN (
  1997. // IN PVOID VA
  1998. // );
  1999. //
  2000. // Routine Description:
  2001. //
  2002. // This macro converts a physical address (see MI_IS_PHYSICAL_ADDRESS)
  2003. // to its corresponding physical frame number.
  2004. //
  2005. // Arguments
  2006. //
  2007. // VA - Supplies a pointer to the physical address.
  2008. //
  2009. // Return Value:
  2010. //
  2011. // Returns the PFN for the page.
  2012. //
  2013. //--
  2014. #define MI_CONVERT_PHYSICAL_TO_PFN(Va) \
  2015. ((PFN_NUMBER)(MiGetPdeAddress(Va)->u.Hard.PageFrameNumber) + (MiGetPteOffset((ULONG)Va)))
  2016. typedef struct _MMCOLOR_TABLES {
  2017. PFN_NUMBER Flink;
  2018. PVOID Blink;
  2019. PFN_NUMBER Count;
  2020. } MMCOLOR_TABLES, *PMMCOLOR_TABLES;
  2021. extern PMMCOLOR_TABLES MmFreePagesByColor[2];
  2022. extern ULONG MmTotalPagesForPagingFile;
  2023. //
  2024. // A VALID Page Table Entry on PAE x86 has the following definition.
  2025. //
  2026. #define MI_MAXIMUM_PAGEFILE_SIZE (((UINT64)4 * 1024 * 1024 * 1024 - 1) * PAGE_SIZE)
  2027. #define MI_PTE_LOOKUP_NEEDED (0xffffffff)
  2028. typedef struct _MMPTE_SOFTWARE {
  2029. ULONGLONG Valid : 1;
  2030. ULONGLONG PageFileLow : 4;
  2031. ULONGLONG Protection : 5;
  2032. ULONGLONG Prototype : 1;
  2033. ULONGLONG Transition : 1;
  2034. ULONGLONG Unused : 20;
  2035. ULONGLONG PageFileHigh : 32;
  2036. } MMPTE_SOFTWARE;
  2037. typedef struct _MMPTE_TRANSITION {
  2038. ULONGLONG Valid : 1;
  2039. ULONGLONG Write : 1;
  2040. ULONGLONG Owner : 1;
  2041. ULONGLONG WriteThrough : 1;
  2042. ULONGLONG CacheDisable : 1;
  2043. ULONGLONG Protection : 5;
  2044. ULONGLONG Prototype : 1;
  2045. ULONGLONG Transition : 1;
  2046. ULONGLONG PageFrameNumber : 26;
  2047. ULONGLONG Unused : 26;
  2048. } MMPTE_TRANSITION;
  2049. typedef struct _MMPTE_PROTOTYPE {
  2050. ULONGLONG Valid : 1;
  2051. ULONGLONG Unused0: 7;
  2052. ULONGLONG ReadOnly : 1; // if set allow read only access.
  2053. ULONGLONG Unused1: 1;
  2054. ULONGLONG Prototype : 1;
  2055. ULONGLONG Protection : 5;
  2056. ULONGLONG Unused: 16;
  2057. ULONGLONG ProtoAddress: 32;
  2058. } MMPTE_PROTOTYPE;
  2059. typedef struct _MMPTE_SUBSECTION {
  2060. ULONGLONG Valid : 1;
  2061. ULONGLONG Unused0 : 4;
  2062. ULONGLONG Protection : 5;
  2063. ULONGLONG Prototype : 1;
  2064. ULONGLONG Unused1 : 21;
  2065. ULONGLONG SubsectionAddress : 32;
  2066. } MMPTE_SUBSECTION;
  2067. typedef struct _MMPTE_LIST {
  2068. ULONGLONG Valid : 1;
  2069. ULONGLONG OneEntry : 1;
  2070. ULONGLONG filler0 : 8;
  2071. //
  2072. // Note the Prototype bit must not be used for lists like freed nonpaged
  2073. // pool because lookaside pops can legitimately reference bogus addresses
  2074. // (since the pop is unsynchronized) and the fault handler must be able to
  2075. // distinguish lists from protos so a retry status can be returned (vs a
  2076. // fatal bugcheck).
  2077. //
  2078. ULONGLONG Prototype : 1; // MUST BE ZERO as per above comment.
  2079. ULONGLONG filler1 : 21;
  2080. ULONGLONG NextEntry : 32;
  2081. } MMPTE_LIST;
  2082. typedef struct _MMPTE_HIGHLOW {
  2083. ULONG LowPart;
  2084. ULONG HighPart;
  2085. } MMPTE_HIGHLOW;
  2086. //
  2087. // A Page Table Entry on PAE has the following definition.
  2088. // Note the MP version is to avoid stalls when flushing TBs across processors.
  2089. //
  2090. //
  2091. // Uniprocessor version.
  2092. //
  2093. typedef struct _MMPTE_HARDWARE {
  2094. ULONGLONG Valid : 1;
  2095. #if defined(NT_UP)
  2096. ULONGLONG Write : 1; // UP version
  2097. #else
  2098. ULONGLONG Writable : 1; // changed for MP version
  2099. #endif
  2100. ULONGLONG Owner : 1;
  2101. ULONGLONG WriteThrough : 1;
  2102. ULONGLONG CacheDisable : 1;
  2103. ULONGLONG Accessed : 1;
  2104. ULONGLONG Dirty : 1;
  2105. ULONGLONG LargePage : 1;
  2106. ULONGLONG Global : 1;
  2107. ULONGLONG CopyOnWrite : 1; // software field
  2108. ULONGLONG Prototype : 1; // software field
  2109. #if defined(NT_UP)
  2110. ULONGLONG reserved0 : 1; // software field
  2111. #else
  2112. ULONGLONG Write : 1; // software field - MP change
  2113. #endif
  2114. ULONGLONG PageFrameNumber : 26;
  2115. ULONGLONG reserved1 : 26; // software field
  2116. } MMPTE_HARDWARE, *PMMPTE_HARDWARE;
  2117. #if defined(NT_UP)
  2118. #define HARDWARE_PTE_DIRTY_MASK 0x40
  2119. #else
  2120. #define HARDWARE_PTE_DIRTY_MASK 0x42
  2121. #endif
  2122. #define MI_GET_PAGE_FRAME_FROM_PTE(PTE) ((PFN_NUMBER)(PTE)->u.Hard.PageFrameNumber)
  2123. #define MI_GET_PAGE_FRAME_FROM_TRANSITION_PTE(PTE) ((PFN_NUMBER)(PTE)->u.Trans.PageFrameNumber)
  2124. #define MI_GET_PROTECTION_FROM_SOFT_PTE(PTE) ((ULONG)(PTE)->u.Soft.Protection)
  2125. #define MI_GET_PROTECTION_FROM_TRANSITION_PTE(PTE) ((ULONG)(PTE)->u.Trans.Protection)
  2126. typedef struct _MMPTE {
  2127. union {
  2128. ULONGLONG Long;
  2129. MMPTE_HIGHLOW HighLow;
  2130. MMPTE_HARDWARE Hard;
  2131. HARDWARE_PTE Flush;
  2132. MMPTE_PROTOTYPE Proto;
  2133. MMPTE_SOFTWARE Soft;
  2134. MMPTE_TRANSITION Trans;
  2135. MMPTE_SUBSECTION Subsect;
  2136. MMPTE_LIST List;
  2137. } u;
  2138. } MMPTE;
  2139. typedef MMPTE *PMMPTE;
  2140. extern MMPTE MmPteGlobal; // Set if processor supports Global Page, else zero.
  2141. extern PMMPTE MiFirstReservedZeroingPte;
  2142. //
  2143. // A compiler intrinsic for InterlockedCompareExchange64I would be much better
  2144. // but since there isn't, make it an inline.
  2145. //
  2146. FORCEINLINE
  2147. LONG64
  2148. FASTCALL
  2149. InterlockedCompareExchange64I (
  2150. IN OUT LONG64 volatile *Destination,
  2151. IN PLONG64 Exchange,
  2152. IN PLONG64 Comperand
  2153. )
  2154. {
  2155. __asm {
  2156. push ebx
  2157. push esi
  2158. mov esi, Destination ; set destination address
  2159. mov edx, Exchange
  2160. mov ebx, [edx] ; get exchange value
  2161. mov ecx, [edx] + 4 ;
  2162. mov edx, Comperand ; get comperand address
  2163. mov eax, [edx] ; get comperand value
  2164. mov edx, [edx] + 4 ;
  2165. lock cmpxchg8b qword ptr [esi] ; compare and exchange
  2166. pop esi ; restore nonvolatile registers
  2167. pop ebx ;
  2168. }
  2169. }
  2170. #define InterlockedCompareExchangePte(Destination, ExChange, Comperand) \
  2171. InterlockedCompareExchange64I((LONG64 volatile *)(Destination), (PLONG64)&(ExChange), (PLONG64)&(Comperand))
  2172. //++
  2173. //VOID
  2174. //MI_WRITE_VALID_PTE (
  2175. // IN PMMPTE PointerPte,
  2176. // IN MMPTE PteContents
  2177. // );
  2178. //
  2179. // Routine Description:
  2180. //
  2181. // MI_WRITE_VALID_PTE fills in the specified PTE making it valid with the
  2182. // specified contents. Note that the contents are very carefully written.
  2183. //
  2184. // Arguments
  2185. //
  2186. // PointerPte - Supplies a PTE to fill.
  2187. //
  2188. // PteContents - Supplies the contents to put in the PTE.
  2189. //
  2190. // Return Value:
  2191. //
  2192. // None.
  2193. //
  2194. //--
  2195. #define MI_WRITE_VALID_PTE(_PointerPte, _PteContents) \
  2196. ASSERT ((_PointerPte)->u.Hard.Valid == 0); \
  2197. ASSERT ((_PteContents).u.Hard.Valid == 1); \
  2198. ((_PointerPte)->u.HighLow.HighPart = ((_PteContents).u.HighLow.HighPart)); \
  2199. ((_PointerPte)->u.HighLow.LowPart = ((_PteContents).u.HighLow.LowPart))
  2200. //++
  2201. //VOID
  2202. //MI_WRITE_INVALID_PTE (
  2203. // IN PMMPTE PointerPte,
  2204. // IN MMPTE PteContents
  2205. // );
  2206. //
  2207. // Routine Description:
  2208. //
  2209. // MI_WRITE_INVALID_PTE fills in the specified PTE making it invalid with the
  2210. // specified contents. Note that the contents are very carefully written.
  2211. //
  2212. // Arguments
  2213. //
  2214. // PointerPte - Supplies a PTE to fill.
  2215. //
  2216. // PteContents - Supplies the contents to put in the PTE.
  2217. //
  2218. // Return Value:
  2219. //
  2220. // None.
  2221. //
  2222. //--
  2223. #define MI_WRITE_INVALID_PTE(_PointerPte, _PteContents) \
  2224. ASSERT ((_PteContents).u.Hard.Valid == 0); \
  2225. ((_PointerPte)->u.HighLow.LowPart = ((_PteContents).u.HighLow.LowPart)); \
  2226. ((_PointerPte)->u.HighLow.HighPart = ((_PteContents).u.HighLow.HighPart))
  2227. //++
  2228. //VOID
  2229. //MI_WRITE_VALID_PTE_NEW_PROTECTION (
  2230. // IN PMMPTE PointerPte,
  2231. // IN MMPTE PteContents
  2232. // );
  2233. //
  2234. // Routine Description:
  2235. //
  2236. // MI_WRITE_VALID_PTE_NEW_PROTECTION fills in the specified PTE (which was
  2237. // already valid) changing only the protection or the dirty bit.
  2238. // Note that the contents are very carefully written.
  2239. //
  2240. // Arguments
  2241. //
  2242. // PointerPte - Supplies a PTE to fill.
  2243. //
  2244. // PteContents - Supplies the contents to put in the PTE.
  2245. //
  2246. // Return Value:
  2247. //
  2248. // None.
  2249. //
  2250. //--
  2251. #define MI_WRITE_VALID_PTE_NEW_PROTECTION(_PointerPte, _PteContents) \
  2252. ASSERT ((_PointerPte)->u.Hard.Valid == 1); \
  2253. ASSERT ((_PteContents).u.Hard.Valid == 1); \
  2254. ASSERT ((_PointerPte)->u.Hard.PageFrameNumber == (_PteContents).u.Hard.PageFrameNumber); \
  2255. ((_PointerPte)->u.HighLow.LowPart = ((_PteContents).u.HighLow.LowPart));
  2256. //++
  2257. //VOID
  2258. //MiFillMemoryPte (
  2259. // IN PMMPTE Destination,
  2260. // IN ULONG Length,
  2261. // IN MMPTE Pattern,
  2262. // };
  2263. //
  2264. // Routine Description:
  2265. //
  2266. // This function fills memory with the specified PTE pattern.
  2267. //
  2268. // Arguments
  2269. //
  2270. // Destination - Supplies a pointer to the memory to fill.
  2271. //
  2272. // Length - Supplies the length, in bytes, of the memory to be
  2273. // filled.
  2274. //
  2275. // Pattern - Supplies the PTE fill pattern.
  2276. //
  2277. // Return Value:
  2278. //
  2279. // None.
  2280. //
  2281. //--
  2282. #define MiFillMemoryPte(Destination, Length, Pattern) \
  2283. RtlFillMemoryUlonglong ((Destination), (Length), (Pattern))
  2284. ULONG
  2285. FASTCALL
  2286. MiDetermineUserGlobalPteMask (
  2287. IN PMMPTE Pte
  2288. );
  2289. //++
  2290. //BOOLEAN
  2291. //MI_IS_PAGE_TABLE_ADDRESS (
  2292. // IN PVOID VA
  2293. // );
  2294. //
  2295. // Routine Description:
  2296. //
  2297. // This macro takes a virtual address and determines if
  2298. // it is a page table address.
  2299. //
  2300. // Arguments
  2301. //
  2302. // VA - Supplies a virtual address.
  2303. //
  2304. // Return Value:
  2305. //
  2306. // TRUE if the address is a page table address, FALSE if not.
  2307. //
  2308. //--
  2309. #define MI_IS_PAGE_TABLE_ADDRESS(VA) \
  2310. ((PVOID)(VA) >= (PVOID)PTE_BASE && (PVOID)(VA) <= (PVOID)PTE_TOP)
  2311. //++
  2312. //BOOLEAN
  2313. //MI_IS_KERNEL_PAGE_TABLE_ADDRESS (
  2314. // IN PVOID VA
  2315. // );
  2316. //
  2317. // Routine Description:
  2318. //
  2319. // This macro takes a virtual address and determines if
  2320. // it is a page table address for a kernel address.
  2321. //
  2322. // Arguments
  2323. //
  2324. // VA - Supplies a virtual address.
  2325. //
  2326. // Return Value:
  2327. //
  2328. // TRUE if the address is a kernel page table address, FALSE if not.
  2329. //
  2330. //--
  2331. #define MI_IS_KERNEL_PAGE_TABLE_ADDRESS(VA) \
  2332. ((PVOID)(VA) >= (PVOID)MiGetPteAddress(MmSystemRangeStart) && (PVOID)(VA) <= (PVOID)PTE_TOP)
  2333. //++
  2334. //BOOLEAN
  2335. //MI_IS_PAGE_DIRECTORY_ADDRESS (
  2336. // IN PVOID VA
  2337. // );
  2338. //
  2339. // Routine Description:
  2340. //
  2341. // This macro takes a virtual address and determines if
  2342. // it is a page directory address.
  2343. //
  2344. // Arguments
  2345. //
  2346. // VA - Supplies a virtual address.
  2347. //
  2348. // Return Value:
  2349. //
  2350. // TRUE if the address is a page directory address, FALSE if not.
  2351. //
  2352. //--
  2353. #define MI_IS_PAGE_DIRECTORY_ADDRESS(VA) \
  2354. ((PVOID)(VA) >= (PVOID)PDE_BASE && (PVOID)(VA) <= (PVOID)PDE_TOP)
  2355. //++
  2356. //BOOLEAN
  2357. //MI_IS_HYPER_SPACE_ADDRESS (
  2358. // IN PVOID VA
  2359. // );
  2360. //
  2361. // Routine Description:
  2362. //
  2363. // This macro takes a virtual address and determines if
  2364. // it is a hyper space address.
  2365. //
  2366. // Arguments
  2367. //
  2368. // VA - Supplies a virtual address.
  2369. //
  2370. // Return Value:
  2371. //
  2372. // TRUE if the address is a hyper space address, FALSE if not.
  2373. //
  2374. //--
  2375. #define MI_IS_HYPER_SPACE_ADDRESS(VA) \
  2376. ((PVOID)(VA) >= (PVOID)HYPER_SPACE && (PVOID)(VA) <= (PVOID)HYPER_SPACE_END)
  2377. //++
  2378. //BOOLEAN
  2379. //MI_IS_PROCESS_SPACE_ADDRESS (
  2380. // IN PVOID VA
  2381. // );
  2382. //
  2383. // Routine Description:
  2384. //
  2385. // This macro takes a virtual address and determines if
  2386. // it is a process-specific address. This is an address in user space
  2387. // or page table pages or hyper space.
  2388. //
  2389. // Arguments
  2390. //
  2391. // VA - Supplies a virtual address.
  2392. //
  2393. // Return Value:
  2394. //
  2395. // TRUE if the address is a process-specific address, FALSE if not.
  2396. //
  2397. //--
  2398. #define MI_IS_PROCESS_SPACE_ADDRESS(VA) \
  2399. (((PVOID)(VA) <= (PVOID)MM_HIGHEST_USER_ADDRESS) || \
  2400. ((PVOID)(VA) >= (PVOID)PTE_BASE && (PVOID)(VA) <= (PVOID)HYPER_SPACE_END))
  2401. //++
  2402. //BOOLEAN
  2403. //MI_IS_PTE_PROTOTYPE (
  2404. // IN PMMPTE PTE
  2405. // );
  2406. //
  2407. // Routine Description:
  2408. //
  2409. // This macro takes a PTE address and determines if it is a prototype PTE.
  2410. //
  2411. // Arguments
  2412. //
  2413. // PTE - Supplies the virtual address of the PTE to check.
  2414. //
  2415. // Return Value:
  2416. //
  2417. // TRUE if the PTE is in a segment (ie, a prototype PTE), FALSE if not.
  2418. //
  2419. //--
  2420. #define MI_IS_PTE_PROTOTYPE(PTE) \
  2421. ((PTE) > (PMMPTE)PTE_TOP)
  2422. //++
  2423. //BOOLEAN
  2424. //MI_IS_SYSTEM_CACHE_ADDRESS (
  2425. // IN PVOID VA
  2426. // );
  2427. //
  2428. // Routine Description:
  2429. //
  2430. // This macro takes a virtual address and determines if
  2431. // it is a system cache address.
  2432. //
  2433. // Arguments
  2434. //
  2435. // VA - Supplies a virtual address.
  2436. //
  2437. // Return Value:
  2438. //
  2439. // TRUE if the address is in the system cache, FALSE if not.
  2440. //
  2441. //--
  2442. #define MI_IS_SYSTEM_CACHE_ADDRESS(VA) \
  2443. (((PVOID)(VA) >= (PVOID)MmSystemCacheStart && \
  2444. (PVOID)(VA) <= (PVOID)MmSystemCacheEnd) || \
  2445. ((PVOID)(VA) >= (PVOID)MiSystemCacheStartExtra && \
  2446. (PVOID)(VA) <= (PVOID)MiSystemCacheEndExtra))
  2447. //++
  2448. //VOID
  2449. //MI_BARRIER_SYNCHRONIZE (
  2450. // IN ULONG TimeStamp
  2451. // );
  2452. //
  2453. // Routine Description:
  2454. //
  2455. // MI_BARRIER_SYNCHRONIZE compares the argument timestamp against the
  2456. // current IPI barrier sequence stamp. When equal, all processors will
  2457. // issue memory barriers to ensure that newly created pages remain coherent.
  2458. //
  2459. // When a page is put in the zeroed or free page list the current
  2460. // barrier sequence stamp is read (interlocked - this is necessary
  2461. // to get the correct value - memory barriers won't do the trick)
  2462. // and stored in the pfn entry for the page. The current barrier
  2463. // sequence stamp is maintained by the IPI send logic and is
  2464. // incremented (interlocked) when the target set of an IPI send
  2465. // includes all processors, but the one doing the send. When a page
  2466. // is needed its sequence number is compared against the current
  2467. // barrier sequence number. If it is equal, then the contents of
  2468. // the page may not be coherent on all processors, and an IPI must
  2469. // be sent to all processors to ensure a memory barrier is
  2470. // executed (generic call can be used for this). Sending the IPI
  2471. // automatically updates the barrier sequence number. The compare
  2472. // is for equality as this is the only value that requires the IPI
  2473. // (i.e., the sequence number wraps, values in both directions are
  2474. // older). When a page is removed in this fashion and either found
  2475. // to be coherent or made coherent, it cannot be modified between
  2476. // that time and writing the PTE. If the page is modified between
  2477. // these times, then an IPI must be sent.
  2478. //
  2479. // Arguments
  2480. //
  2481. // TimeStamp - Supplies the timestamp at the time when the page was zeroed.
  2482. //
  2483. // Return Value:
  2484. //
  2485. // None.
  2486. //
  2487. //--
  2488. // does nothing on PAE.
  2489. #define MI_BARRIER_SYNCHRONIZE(TimeStamp)
  2490. //++
  2491. //VOID
  2492. //MI_BARRIER_STAMP_ZEROED_PAGE (
  2493. // IN PULONG PointerTimeStamp
  2494. // );
  2495. //
  2496. // Routine Description:
  2497. //
  2498. // MI_BARRIER_STAMP_ZEROED_PAGE issues an interlocked read to get the
  2499. // current IPI barrier sequence stamp. This is called AFTER a page is
  2500. // zeroed.
  2501. //
  2502. // Arguments
  2503. //
  2504. // PointerTimeStamp - Supplies a timestamp pointer to fill with the
  2505. // current IPI barrier sequence stamp.
  2506. //
  2507. // Return Value:
  2508. //
  2509. // None.
  2510. //
  2511. //--
  2512. // does nothing on PAE.
  2513. #define MI_BARRIER_STAMP_ZEROED_PAGE(PointerTimeStamp)
  2514. typedef struct _PAE_PAGEINFO {
  2515. LIST_ENTRY ListHead;
  2516. PFN_NUMBER PageFrameNumber;
  2517. ULONG EntriesInUse;
  2518. } PAE_PAGEINFO, *PPAE_PAGEINFO;
  2519. typedef struct _PAE_ENTRY {
  2520. union {
  2521. MMPTE PteEntry[PD_PER_SYSTEM];
  2522. PAE_PAGEINFO PaeEntry;
  2523. SINGLE_LIST_ENTRY NextPae;
  2524. };
  2525. } PAE_ENTRY, *PPAE_ENTRY;
  2526. extern PAE_ENTRY MiSystemPaeVa;
  2527. //++
  2528. //VOID
  2529. //MI_FLUSH_SINGLE_SESSION_TB (
  2530. // IN PVOID Virtual,
  2531. // IN ULONG Invalid,
  2532. // IN LOGICAL AllProcessors,
  2533. // IN PMMPTE PtePointer,
  2534. // IN MMPTE PteValue,
  2535. // IN MMPTE PreviousPte
  2536. // );
  2537. //
  2538. // Routine Description:
  2539. //
  2540. // MI_FLUSH_SINGLE_SESSION_TB flushes the requested single address
  2541. // translation from the TB.
  2542. //
  2543. // Since there are no ASNs on the x86, this routine becomes a single
  2544. // TB invalidate.
  2545. //
  2546. // Arguments
  2547. //
  2548. // Virtual - Supplies the virtual address to invalidate.
  2549. //
  2550. // Invalid - TRUE if invalidating.
  2551. //
  2552. // AllProcessors - TRUE if all processors need to be IPI'd.
  2553. //
  2554. // PtePointer - Supplies the PTE to invalidate.
  2555. //
  2556. // PteValue - Supplies the new PTE value.
  2557. //
  2558. // PreviousPte - The previous PTE value is returned here.
  2559. //
  2560. // Return Value:
  2561. //
  2562. // None.
  2563. //
  2564. //--
  2565. #define MI_FLUSH_SINGLE_SESSION_TB(Virtual, Invalid, AllProcessors, PtePointer, PteValue, PreviousPte) \
  2566. PreviousPte.u.Flush = KeFlushSingleTb (Virtual, \
  2567. TRUE, \
  2568. TRUE, \
  2569. PtePointer, \
  2570. PteValue);
  2571. //++
  2572. //VOID
  2573. //MI_FLUSH_ENTIRE_SESSION_TB (
  2574. // IN ULONG Invalid,
  2575. // IN LOGICAL AllProcessors
  2576. // );
  2577. //
  2578. // Routine Description:
  2579. //
  2580. // MI_FLUSH_ENTIRE_SESSION_TB flushes the entire TB on processors which
  2581. // support ASNs.
  2582. //
  2583. // Since there are no ASNs on the x86, this routine does nothing.
  2584. //
  2585. // Arguments
  2586. //
  2587. // Invalid - TRUE if invalidating.
  2588. //
  2589. // AllProcessors - TRUE if all processors need to be IPI'd.
  2590. //
  2591. // Return Value:
  2592. //
  2593. // None.
  2594. //
  2595. #define MI_FLUSH_ENTIRE_SESSION_TB(Invalid, AllProcessors) \
  2596. NOTHING;
  2597. //++
  2598. //LOGICAL
  2599. //MI_RESERVED_BITS_CANONICAL (
  2600. // IN PVOID VirtualAddress
  2601. // );
  2602. //
  2603. // Routine Description:
  2604. //
  2605. // This routine checks whether all of the reserved bits are correct.
  2606. //
  2607. // This does nothing on PAE x86.
  2608. //
  2609. // Arguments
  2610. //
  2611. // VirtualAddress - Supplies the virtual address to check.
  2612. //
  2613. // Return Value:
  2614. //
  2615. // None.
  2616. //
  2617. #define MI_RESERVED_BITS_CANONICAL(VirtualAddress) TRUE
  2618. //++
  2619. //VOID
  2620. //MI_DISPLAY_TRAP_INFORMATION (
  2621. // IN PVOID TrapInformation
  2622. // );
  2623. //
  2624. // Routine Description:
  2625. //
  2626. // Display any relevant trap information to aid debugging.
  2627. //
  2628. // Arguments
  2629. //
  2630. // TrapInformation - Supplies a pointer to a trap frame.
  2631. //
  2632. // Return Value:
  2633. //
  2634. // None.
  2635. //
  2636. #define MI_DISPLAY_TRAP_INFORMATION(TrapInformation) \
  2637. KdPrint(("MM:***EIP %p, EFL %p\n", \
  2638. ((PKTRAP_FRAME) (TrapInformation))->Eip, \
  2639. ((PKTRAP_FRAME) (TrapInformation))->EFlags)); \
  2640. KdPrint(("MM:***EAX %p, ECX %p EDX %p\n", \
  2641. ((PKTRAP_FRAME) (TrapInformation))->Eax, \
  2642. ((PKTRAP_FRAME) (TrapInformation))->Ecx, \
  2643. ((PKTRAP_FRAME) (TrapInformation))->Edx)); \
  2644. KdPrint(("MM:***EBX %p, ESI %p EDI %p\n", \
  2645. ((PKTRAP_FRAME) (TrapInformation))->Ebx, \
  2646. ((PKTRAP_FRAME) (TrapInformation))->Esi, \
  2647. ((PKTRAP_FRAME) (TrapInformation))->Edi));
  2648. //
  2649. // Turn off U/S, R/W and any other appropriate bits required by the processor.
  2650. //
  2651. #define MM_PAE_PDPTE_MASK 0x1e6
  2652. ULONG
  2653. MiPaeAllocate (
  2654. PPAE_ENTRY *
  2655. );
  2656. VOID
  2657. MiPaeFree (
  2658. PPAE_ENTRY Pae
  2659. );
  2660. #endif