Browse Source

Mm bug fixes after IMAGE_SECTION.Min/MaxTouched.

Fixed a bug where the wrong inherited bitmap bit was being sampled,
causing paging entry leaks.

Fixed another bug that was causing a filled in but not Present PDE to get
smashed with an empty PDE, leaking the page table.
Evan Green 8 years ago
parent
commit
ff184d8ba4
3 changed files with 19 additions and 6 deletions
  1. 6 0
      include/minoca/kernel/mm.h
  2. 10 4
      kernel/mm/imgsec.c
  3. 3 2
      kernel/mm/x86/mapping.c

+ 6 - 0
include/minoca/kernel/mm.h

@@ -42,6 +42,12 @@ Author:
 
 #define MM_ADDRESS_SPACE_ALLOCATION_TAG 0x64416D4D
 
+//
+// Define the allocation tag used by image sections.
+//
+
+#define MM_IMAGE_SECTION_ALLOCATION_TAG 0x6D496D4D
+
 //
 // Define the pool magic values for non-paged pool (NonP) and paged-pool (PagP).
 //

+ 10 - 4
kernel/mm/imgsec.c

@@ -1283,7 +1283,9 @@ Return Value:
                  BITS_PER_BYTE;
 
     AllocationSize = sizeof(IMAGE_SECTION) + (2 * BitmapSize);
-    NewSection = MmAllocateNonPagedPool(AllocationSize, MM_ALLOCATION_TAG);
+    NewSection = MmAllocateNonPagedPool(AllocationSize,
+                                        MM_IMAGE_SECTION_ALLOCATION_TAG);
+
     if (NewSection == NULL) {
         Status = STATUS_INSUFFICIENT_RESOURCES;
         goto CopyImageSectionEnd;
@@ -2688,7 +2690,9 @@ Return Value:
                  BITS_PER_BYTE;
 
     AllocationSize = sizeof(IMAGE_SECTION) + (BitmapCount * BitmapSize);
-    NewSection = MmAllocateNonPagedPool(AllocationSize, MM_ALLOCATION_TAG);
+    NewSection = MmAllocateNonPagedPool(AllocationSize,
+                                        MM_IMAGE_SECTION_ALLOCATION_TAG);
+
     if (NewSection == NULL) {
         Status = STATUS_INSUFFICIENT_RESOURCES;
         goto AllocateImageSectionEnd;
@@ -3940,6 +3944,7 @@ Return Value:
     PKPROCESS CurrentProcess;
     UINTN DirtyPageCount;
     BOOL MarkedDirty;
+    UINTN MinOffset;
     BOOL MultipleIpisRequired;
     BOOL OtherProcess;
     PPAGE_CACHE_ENTRY PageCacheEntry;
@@ -3979,6 +3984,7 @@ Return Value:
 
     CurrentAddress = Section->MinTouched;
     PageCount = (Section->MaxTouched - CurrentAddress) >> PageShift;
+    MinOffset = (CurrentAddress - Section->VirtualAddress) >> PageShift;
 
     //
     // Depending on the image section, there are different, more efficient
@@ -4065,8 +4071,8 @@ Return Value:
     RunPhysicalAddress = INVALID_PHYSICAL_ADDRESS;
     PhysicalAddress = INVALID_PHYSICAL_ADDRESS;
     for (PageIndex = 0; PageIndex < PageCount; PageIndex += 1) {
-        BitmapIndex = IMAGE_SECTION_BITMAP_INDEX(PageIndex);
-        BitmapMask = IMAGE_SECTION_BITMAP_MASK(PageIndex);
+        BitmapIndex = IMAGE_SECTION_BITMAP_INDEX(PageIndex + MinOffset);
+        BitmapMask = IMAGE_SECTION_BITMAP_MASK(PageIndex + MinOffset);
         UnmapFlags = UNMAP_FLAG_FREE_PHYSICAL_PAGES |
                      UNMAP_FLAG_SEND_INVALIDATE_IPI;
 

+ 3 - 2
kernel/mm/x86/mapping.c

@@ -1205,7 +1205,9 @@ Return Value:
         // if so.
         //
 
-        if (Directory[DirectoryIndex].Present == 0) {
+        if ((Directory[DirectoryIndex].Present == 0) &&
+            (Directory[DirectoryIndex].Entry == 0)) {
+
             Directory[DirectoryIndex] = MmKernelPageDirectory[DirectoryIndex];
         }
 
@@ -1910,7 +1912,6 @@ Return Value:
         Directory = MmKernelPageDirectory;
 
     } else {
-        Process = PsGetCurrentProcess();
         Directory = ProcessPageDirectory;
 
         //