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.

3271 lines
75 KiB

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