[BOOTLIB]: Stub MmPapFreePages
authorAlex Ionescu <aionescu@gmail.com>
Sun, 5 Feb 2017 15:14:44 +0000 (15:14 +0000)
committerAlex Ionescu <aionescu@gmail.com>
Sun, 5 Feb 2017 15:14:44 +0000 (15:14 +0000)
[BOOTLIB]: Implement BlImgUnallocateImageBuffer
[BOOTLIB]: Stub BlMmTranslateVirtualAddress

svn path=/trunk/; revision=73707

reactos/boot/environ/include/bl.h
reactos/boot/environ/lib/io/device.c
reactos/boot/environ/lib/misc/bootreg.c
reactos/boot/environ/lib/misc/image.c
reactos/boot/environ/lib/mm/mm.c
reactos/boot/environ/lib/mm/pagealloc.c

index 169700f..db9e053 100644 (file)
@@ -2092,6 +2092,12 @@ BlMmFreePhysicalPages (
     _In_ PHYSICAL_ADDRESS Address
     );
 
     _In_ PHYSICAL_ADDRESS Address
     );
 
+NTSTATUS
+MmPapFreePages (
+    _In_ PVOID Address,
+    _In_ ULONG WhichList
+    );
+
 NTSTATUS
 MmPapAllocatePagesInRange (
     _Inout_ PVOID* PhysicalAddress,
 NTSTATUS
 MmPapAllocatePagesInRange (
     _Inout_ PVOID* PhysicalAddress,
@@ -2143,6 +2149,12 @@ BlMmUnmapVirtualAddressEx (
     _In_ ULONGLONG Size
     );
 
     _In_ ULONGLONG Size
     );
 
+BOOLEAN
+BlMmTranslateVirtualAddress (
+    _In_ PVOID VirtualAddress,
+    _Out_ PPHYSICAL_ADDRESS PhysicalAddress
+    );
+
 /* BLOCK ALLOCATOR ROUTINES **************************************************/
 
 NTSTATUS
 /* BLOCK ALLOCATOR ROUTINES **************************************************/
 
 NTSTATUS
index 9a9659c..f02983a 100644 (file)
@@ -214,9 +214,7 @@ BlockIopFreeAlignedBuffer (
 
     if (*BufferSize)
     {
 
     if (*BufferSize)
     {
-        EfiPrintf(L"Aligned free not yet implemented\r\n");
-        Status = STATUS_NOT_IMPLEMENTED;
-        //Status = MmPapFreePages(*Buffer, 1);
+        Status = MmPapFreePages(*Buffer, BL_MM_INCLUDE_MAPPED_ALLOCATED);
 
         *Buffer = NULL;
         *BufferSize = 0;
 
         *Buffer = NULL;
         *BufferSize = 0;
@@ -1881,8 +1879,7 @@ BlockIopInitialize (
         /* Free the prefetch buffer is one was allocated */
         if (BlockIopPrefetchBuffer)
         {
         /* Free the prefetch buffer is one was allocated */
         if (BlockIopPrefetchBuffer)
         {
-            EfiPrintf(L"Failure path not implemented %lx\r\n", Status);
-            //MmPapFreePages(BlockIopPrefetchBuffer, 1);
+            MmPapFreePages(BlockIopPrefetchBuffer, BL_MM_INCLUDE_MAPPED_ALLOCATED);
         }
     }
 
         }
     }
 
index d1ac812..88b970d 100644 (file)
@@ -163,8 +163,7 @@ BiCloseKey (
             }
 
             /* Unmap the hive */
             }
 
             /* Unmap the hive */
-            //MmPapFreePages(KeyHive->ImageBase, 1);
-            EfiPrintf(L"Leaking hive memory\r\n");
+            MmPapFreePages(KeyHive->BaseBlock, BL_MM_INCLUDE_MAPPED_ALLOCATED);
 
             /* Free the hive and hive path */
             BlMmFreeHeap(KeyHive->FilePath);
 
             /* Free the hive and hive path */
             BlMmFreeHeap(KeyHive->FilePath);
@@ -516,8 +515,7 @@ BiLoadHive (
         RtlCopyMemory(NewBaseBlock, BaseBlock, HiveSize);
 
         /* Free the old data */
         RtlCopyMemory(NewBaseBlock, BaseBlock, HiveSize);
 
         /* Free the old data */
-        EfiPrintf(L"Leaking old hive buffer\r\n");
-        //MmPapFreePages(BaseBlock, 1);
+        MmPapFreePages(BaseBlock, BL_MM_INCLUDE_MAPPED_ALLOCATED);
 
         /* Update our pointers */
         BaseBlock = NewBaseBlock;
 
         /* Update our pointers */
         BaseBlock = NewBaseBlock;
@@ -607,8 +605,7 @@ Quickie:
     /* If we had logging data, free it */
     if (LogData)
     {
     /* If we had logging data, free it */
     if (LogData)
     {
-        EfiPrintf(L"Leaking log buffer\r\n");
-        //MmPapFreePages(LogData, 1);
+        MmPapFreePages(LogData, BL_MM_INCLUDE_MAPPED_ALLOCATED);
     }
 
     /* Check if this is the failure path */
     }
 
     /* Check if this is the failure path */
@@ -617,8 +614,7 @@ Quickie:
         /* If we mapped the hive, free it */
         if (BaseBlock)
         {
         /* If we mapped the hive, free it */
         if (BaseBlock)
         {
-            EfiPrintf(L"Leaking base block on failure\r\n");
-            //MmPapFreePages(BaseBlock, 1u);
+            MmPapFreePages(BaseBlock, BL_MM_INCLUDE_MAPPED_ALLOCATED);
         }
 
         /* If we opened the device, close it */
         }
 
         /* If we opened the device, close it */
index 61f8797..c1c2fea 100644 (file)
@@ -194,8 +194,7 @@ ImgpCloseFile (
         if (File->Flags & BL_IMG_REMOTE_FILE)
         {
             /* Then only free the memory in that scenario */
         if (File->Flags & BL_IMG_REMOTE_FILE)
         {
             /* Then only free the memory in that scenario */
-            EfiPrintf(L"TODO\r\n");
-            //return MmPapFreePages(File->BaseAddress, TRUE);
+            return MmPapFreePages(File->BaseAddress, BL_MM_INCLUDE_MAPPED_ALLOCATED);
         }
     }
 
         }
     }
 
@@ -210,8 +209,37 @@ BlImgUnallocateImageBuffer (
     _In_ ULONG ImageFlags
     )
 {
     _In_ ULONG ImageFlags
     )
 {
-    EfiPrintf(L"leaking the shit out of %p\r\n", ImageBase);
-    return STATUS_NOT_IMPLEMENTED;
+    PHYSICAL_ADDRESS PhysicalAddress;
+    NTSTATUS Status;
+
+    /* Make sure required parameters are present */
+    if (!(ImageBase) || !(ImageSize))
+    {
+        return STATUS_INVALID_PARAMETER;
+    }
+
+    /* Check if this was a physical allocation */
+    if (!(ImageFlags & BL_LOAD_IMG_VIRTUAL_BUFFER))
+    {
+        return MmPapFreePages(ImageBase, BL_MM_INCLUDE_MAPPED_ALLOCATED);
+    }
+
+    /* It's virtual, so translate it first */
+    if (!BlMmTranslateVirtualAddress(ImageBase, &PhysicalAddress))
+    {
+        return STATUS_INVALID_PARAMETER;
+    }
+
+    /* Unmap the virtual mapping */
+    Status = BlMmUnmapVirtualAddressEx(ImageBase, ROUND_TO_PAGES(ImageSize));
+    if (NT_SUCCESS(Status))
+    {
+        /* Now free the physical pages */
+        Status = BlMmFreePhysicalPages(PhysicalAddress);
+    }
+
+    /* All done */
+    return Status;
 }
 
 NTSTATUS
 }
 
 NTSTATUS
@@ -562,8 +590,7 @@ Quickie:
         else
         {
             /* Free the physical buffer */
         else
         {
             /* Free the physical buffer */
-            //MmPapFreePages(VirtualAddress, 1);
-            EfiPrintf(L"Leaking memory\r\n");
+            MmPapFreePages(BaseAddress, BL_MM_INCLUDE_MAPPED_ALLOCATED);
         }
     }
 
         }
     }
 
@@ -1192,8 +1219,7 @@ Quickie:
     if (HashBuffer)
     {
         /* Free it */
     if (HashBuffer)
     {
         /* Free it */
-        EfiPrintf(L"Leadking hash: %p\r\n", HashBuffer);
-        //MmPapFreePages(HashBuffer, TRUE);
+        MmPapFreePages(HashBuffer, BL_MM_INCLUDE_MAPPED_ALLOCATED);
     }
 
     /* Check if we have a certificate directory */
     }
 
     /* Check if we have a certificate directory */
@@ -1234,8 +1260,7 @@ Quickie:
             else
             {
                 /* Into a physical buffer -- free it */
             else
             {
                 /* Into a physical buffer -- free it */
-                EfiPrintf(L"Leaking physical pages\r\n");
-               // MmPapFreePages(VirtualAddress, TRUE);
+                MmPapFreePages(VirtualAddress, BL_MM_INCLUDE_MAPPED_ALLOCATED);
             }
         }
     }
             }
         }
     }
@@ -1888,7 +1913,7 @@ Quickie:
     if (BootData)
     {
         /* Free it */
     if (BootData)
     {
         /* Free it */
-        //MmPapFreePages(bootData, TRUE);
+        MmPapFreePages(BootData, BL_MM_INCLUDE_MAPPED_ALLOCATED);
     }
 
     /* All done */
     }
 
     /* All done */
index 9a8ae3c..bfa9cae 100644 (file)
@@ -284,6 +284,7 @@ BlMmUnmapVirtualAddressEx (
         if ((NT_SUCCESS(Status)) && (MmTranslationType != BlNone))
         {
             /* TODO */
         if ((NT_SUCCESS(Status)) && (MmTranslationType != BlNone))
         {
             /* TODO */
+            EfiPrintf(L"unhandled virtual path\r\n");
             Status = STATUS_NOT_IMPLEMENTED;
         }
     }
             Status = STATUS_NOT_IMPLEMENTED;
         }
     }
@@ -299,6 +300,23 @@ BlMmUnmapVirtualAddressEx (
     return Status;
 }
 
     return Status;
 }
 
+BOOLEAN
+BlMmTranslateVirtualAddress (
+    _In_ PVOID VirtualAddress,
+    _Out_ PPHYSICAL_ADDRESS PhysicalAddress
+    )
+{
+    /* Make sure arguments are present */
+    if (!(VirtualAddress) || !(PhysicalAddress))
+    {
+        return FALSE;
+    }
+
+    EfiPrintf(L"Unhandled virtual path\r\n");
+    return FALSE;
+    //return MmArchTranslateVirtualAddress(VirtualAddress, PhysicalAddress, NULL);
+}
+
 NTSTATUS
 BlpMmInitialize (
     _In_ PBL_MEMORY_DATA MemoryData,
 NTSTATUS
 BlpMmInitialize (
     _In_ PBL_MEMORY_DATA MemoryData,
index 453caa8..e83452d 100644 (file)
@@ -195,7 +195,6 @@ MmPapAllocateRegionFromMdl (
     /* Does the memory we received not exactly fall onto the beginning of its descriptor? */
     if (LocalDescriptor.BasePage != FoundDescriptor->BasePage)
     {
     /* Does the memory we received not exactly fall onto the beginning of its descriptor? */
     if (LocalDescriptor.BasePage != FoundDescriptor->BasePage)
     {
-        EfiPrintf(L"Local Page: %08I64X Found Page: %08I64X\r\n", LocalDescriptor.BasePage, FoundDescriptor->BasePage);
         TempDescriptor = MmMdInitByteGranularDescriptor(FoundDescriptor->Flags,
                                                         FoundDescriptor->Type,
                                                         FoundDescriptor->BasePage,
         TempDescriptor = MmMdInitByteGranularDescriptor(FoundDescriptor->Flags,
                                                         FoundDescriptor->Type,
                                                         FoundDescriptor->BasePage,
@@ -216,7 +215,6 @@ MmPapAllocateRegionFromMdl (
                           LocalDescriptor.VirtualPage + LocalDescriptor.PageCount : 0;
     if (LocalEndPage != FoundEndPage)
     {
                           LocalDescriptor.VirtualPage + LocalDescriptor.PageCount : 0;
     if (LocalEndPage != FoundEndPage)
     {
-        EfiPrintf(L"Local Page: %08I64X Found Page: %08I64X\r\n", LocalEndPage, FoundEndPage);
         TempDescriptor = MmMdInitByteGranularDescriptor(FoundDescriptor->Flags,
                                                         FoundDescriptor->Type,
                                                         LocalEndPage,
         TempDescriptor = MmMdInitByteGranularDescriptor(FoundDescriptor->Flags,
                                                         FoundDescriptor->Type,
                                                         LocalEndPage,
@@ -617,11 +615,21 @@ BlMmFreePhysicalPages (
     )
 {
     /* Call the physical allocator */
     )
 {
     /* Call the physical allocator */
-    EfiPrintf(L"Leaking memory!\r\n");
+    EfiPrintf(L"Leaking memory: %p!\r\n", Address.QuadPart);
     return STATUS_SUCCESS;
     //return MmPapFreePhysicalPages(4, 0, Address);
 }
 
     return STATUS_SUCCESS;
     //return MmPapFreePhysicalPages(4, 0, Address);
 }
 
+NTSTATUS
+MmPapFreePages (
+    _In_ PVOID Address,
+    _In_ ULONG WhichList
+    )
+{
+    EfiPrintf(L"Leaking memory: %p!\r\n", Address);
+    return STATUS_SUCCESS;
+}
+
 NTSTATUS
 BlMmGetMemoryMap (
     _In_ PLIST_ENTRY MemoryMap,
 NTSTATUS
 BlMmGetMemoryMap (
     _In_ PLIST_ENTRY MemoryMap,