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

160 lines
3.2 KiB

  1. /*++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. setmodfy.c
  5. Abstract:
  6. This module contains the setting modify bit routine for memory management.
  7. x86 specific.
  8. Author:
  9. Lou Perazzoli (loup) 6-Jan-1990
  10. Landy Wang (landyw) 2-Jun-1997
  11. Revision History:
  12. --*/
  13. #include "mi.h"
  14. #if defined (_X86PAE_)
  15. extern PMMPTE MmSystemCacheWorkingSetListPte;
  16. #endif
  17. VOID
  18. MiSetModifyBit (
  19. IN PMMPFN Pfn
  20. )
  21. /*++
  22. Routine Description:
  23. This routine sets the modify bit in the specified PFN element
  24. and deallocates any allocated page file space.
  25. Arguments:
  26. Pfn - Supplies the pointer to the PFN element to update.
  27. Return Value:
  28. None.
  29. Environment:
  30. Kernel mode, APCs disabled, Working set mutex held and PFN lock held.
  31. --*/
  32. {
  33. //
  34. // Set the modified field in the PFN database, also, if the physical
  35. // page is currently in a paging file, free up the page file space
  36. // as the contents are now worthless.
  37. //
  38. MI_SET_MODIFIED (Pfn, 1, 0x16);
  39. if (Pfn->OriginalPte.u.Soft.Prototype == 0) {
  40. //
  41. // This page is in page file format, deallocate the page file space.
  42. //
  43. MiReleasePageFileSpace (Pfn->OriginalPte);
  44. //
  45. // Change original PTE to indicate no page file space is reserved,
  46. // otherwise the space will be deallocated when the PTE is
  47. // deleted.
  48. //
  49. Pfn->OriginalPte.u.Soft.PageFileHigh = 0;
  50. }
  51. return;
  52. }
  53. ULONG
  54. FASTCALL
  55. MiDetermineUserGlobalPteMask (
  56. IN PMMPTE Pte
  57. )
  58. /*++
  59. Routine Description:
  60. Builds a mask to OR with the PTE frame field.
  61. This mask has the valid and access bits set and
  62. has the global and owner bits set based on the
  63. address of the PTE.
  64. ******************* NOTE *********************************************
  65. THIS ROUTINE DOES NOT CHECK FOR PDEs WHICH NEED TO BE
  66. SET GLOBAL AS IT ASSUMES PDEs FOR SYSTEM SPACE ARE
  67. PROPERLY SET AT INITIALIZATION TIME!
  68. Arguments:
  69. Pte - Supplies a pointer to the PTE in which to fill.
  70. Return Value:
  71. Mask to OR into the frame to make a valid PTE.
  72. Environment:
  73. Kernel mode, 386 specific.
  74. --*/
  75. {
  76. MMPTE Mask;
  77. Mask.u.Long = 0;
  78. Mask.u.Hard.Valid = 1;
  79. Mask.u.Hard.Accessed = 1;
  80. #if defined (_X86PAE_)
  81. ASSERT (MmSystemCacheWorkingSetListPte != NULL);
  82. #endif
  83. if (Pte <= MiHighestUserPte) {
  84. Mask.u.Hard.Owner = 1;
  85. }
  86. else if ((Pte < MiGetPteAddress (PTE_BASE)) ||
  87. #if defined (_X86PAE_)
  88. (Pte >= MmSystemCacheWorkingSetListPte)
  89. #else
  90. (Pte >= MiGetPteAddress (MM_SYSTEM_CACHE_WORKING_SET))
  91. #endif
  92. ) {
  93. if (MI_IS_SESSION_PTE (Pte) == FALSE) {
  94. #if defined (_X86PAE_)
  95. if ((Pte < (PMMPTE)PDE_BASE) || (Pte > (PMMPTE)PDE_TOP))
  96. #endif
  97. Mask.u.Long |= MmPteGlobal.u.Long;
  98. }
  99. }
  100. else if ((Pte >= MiGetPdeAddress (NULL)) && (Pte <= MiHighestUserPde)) {
  101. Mask.u.Hard.Owner = 1;
  102. }
  103. //
  104. // Since the valid, accessed, global and owner bits are always in the
  105. // low dword of the PTE, returning a ULONG is ok.
  106. //
  107. return (ULONG)Mask.u.Long;
  108. }