Author: ion Date: Sun Feb 5 15:14:44 2017 New Revision: 73707
URL: http://svn.reactos.org/svn/reactos?rev=73707&view=rev Log: [BOOTLIB]: Stub MmPapFreePages [BOOTLIB]: Implement BlImgUnallocateImageBuffer [BOOTLIB]: Stub BlMmTranslateVirtualAddress
Modified: trunk/reactos/boot/environ/include/bl.h trunk/reactos/boot/environ/lib/io/device.c trunk/reactos/boot/environ/lib/misc/bootreg.c trunk/reactos/boot/environ/lib/misc/image.c trunk/reactos/boot/environ/lib/mm/mm.c trunk/reactos/boot/environ/lib/mm/pagealloc.c
Modified: trunk/reactos/boot/environ/include/bl.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/include/bl.h?r... ============================================================================== --- trunk/reactos/boot/environ/include/bl.h [iso-8859-1] (original) +++ trunk/reactos/boot/environ/include/bl.h [iso-8859-1] Sun Feb 5 15:14:44 2017 @@ -2093,6 +2093,12 @@ );
NTSTATUS +MmPapFreePages ( + _In_ PVOID Address, + _In_ ULONG WhichList + ); + +NTSTATUS MmPapAllocatePagesInRange ( _Inout_ PVOID* PhysicalAddress, _In_ BL_MEMORY_TYPE MemoryType, @@ -2141,6 +2147,12 @@ BlMmUnmapVirtualAddressEx ( _In_ PVOID VirtualAddress, _In_ ULONGLONG Size + ); + +BOOLEAN +BlMmTranslateVirtualAddress ( + _In_ PVOID VirtualAddress, + _Out_ PPHYSICAL_ADDRESS PhysicalAddress );
/* BLOCK ALLOCATOR ROUTINES **************************************************/
Modified: trunk/reactos/boot/environ/lib/io/device.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/io/device.... ============================================================================== --- trunk/reactos/boot/environ/lib/io/device.c [iso-8859-1] (original) +++ trunk/reactos/boot/environ/lib/io/device.c [iso-8859-1] Sun Feb 5 15:14:44 2017 @@ -214,9 +214,7 @@
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; @@ -1881,8 +1879,7 @@ /* 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); } }
Modified: trunk/reactos/boot/environ/lib/misc/bootreg.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/misc/bootr... ============================================================================== --- trunk/reactos/boot/environ/lib/misc/bootreg.c [iso-8859-1] (original) +++ trunk/reactos/boot/environ/lib/misc/bootreg.c [iso-8859-1] Sun Feb 5 15:14:44 2017 @@ -163,8 +163,7 @@ }
/* 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); @@ -516,8 +515,7 @@ 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; @@ -607,8 +605,7 @@ /* 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 */ @@ -617,8 +614,7 @@ /* 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 */
Modified: trunk/reactos/boot/environ/lib/misc/image.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/misc/image... ============================================================================== --- trunk/reactos/boot/environ/lib/misc/image.c [iso-8859-1] (original) +++ trunk/reactos/boot/environ/lib/misc/image.c [iso-8859-1] Sun Feb 5 15:14:44 2017 @@ -194,8 +194,7 @@ 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 @@ _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 @@ -562,8 +590,7 @@ 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 @@ 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 */ @@ -1234,8 +1260,7 @@ 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 @@ if (BootData) { /* Free it */ - //MmPapFreePages(bootData, TRUE); + MmPapFreePages(BootData, BL_MM_INCLUDE_MAPPED_ALLOCATED); }
/* All done */
Modified: trunk/reactos/boot/environ/lib/mm/mm.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/mm/mm.c?re... ============================================================================== --- trunk/reactos/boot/environ/lib/mm/mm.c [iso-8859-1] (original) +++ trunk/reactos/boot/environ/lib/mm/mm.c [iso-8859-1] Sun Feb 5 15:14:44 2017 @@ -284,6 +284,7 @@ if ((NT_SUCCESS(Status)) && (MmTranslationType != BlNone)) { /* TODO */ + EfiPrintf(L"unhandled virtual path\r\n"); Status = STATUS_NOT_IMPLEMENTED; } } @@ -297,6 +298,23 @@ MmMdFreeGlobalDescriptors(); --MmDescriptorCallTreeCount; 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
Modified: trunk/reactos/boot/environ/lib/mm/pagealloc.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/mm/pageall... ============================================================================== --- trunk/reactos/boot/environ/lib/mm/pagealloc.c [iso-8859-1] (original) +++ trunk/reactos/boot/environ/lib/mm/pagealloc.c [iso-8859-1] Sun Feb 5 15:14:44 2017 @@ -195,7 +195,6 @@ /* 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, @@ -216,7 +215,6 @@ 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, @@ -617,9 +615,19 @@ ) { /* 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); +} + +NTSTATUS +MmPapFreePages ( + _In_ PVOID Address, + _In_ ULONG WhichList + ) +{ + EfiPrintf(L"Leaking memory: %p!\r\n", Address); + return STATUS_SUCCESS; }
NTSTATUS