[BOOTLIB]: Stub MmPapFreePages

[BOOTLIB]: Implement BlImgUnallocateImageBuffer
[BOOTLIB]: Stub BlMmTranslateVirtualAddress

svn path=/trunk/; revision=73707
This commit is contained in:
Alex Ionescu 2017-02-05 15:14:44 +00:00
parent 1b634b38ec
commit 66a30f987b
6 changed files with 83 additions and 27 deletions

View file

@ -2092,6 +2092,12 @@ BlMmFreePhysicalPages (
_In_ PHYSICAL_ADDRESS Address
);
NTSTATUS
MmPapFreePages (
_In_ PVOID Address,
_In_ ULONG WhichList
);
NTSTATUS
MmPapAllocatePagesInRange (
_Inout_ PVOID* PhysicalAddress,
@ -2143,6 +2149,12 @@ BlMmUnmapVirtualAddressEx (
_In_ ULONGLONG Size
);
BOOLEAN
BlMmTranslateVirtualAddress (
_In_ PVOID VirtualAddress,
_Out_ PPHYSICAL_ADDRESS PhysicalAddress
);
/* BLOCK ALLOCATOR ROUTINES **************************************************/
NTSTATUS

View file

@ -214,9 +214,7 @@ BlockIopFreeAlignedBuffer (
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 @@ BlockIopInitialize (
/* 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);
}
}

View file

@ -163,8 +163,7 @@ BiCloseKey (
}
/* 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 @@ BiLoadHive (
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 @@ Quickie:
/* 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 @@ Quickie:
/* 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 */

View file

@ -194,8 +194,7 @@ ImgpCloseFile (
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
)
{
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 @@ Quickie:
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 */
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 @@ Quickie:
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 */
//MmPapFreePages(bootData, TRUE);
MmPapFreePages(BootData, BL_MM_INCLUDE_MAPPED_ALLOCATED);
}
/* All done */

View file

@ -284,6 +284,7 @@ BlMmUnmapVirtualAddressEx (
if ((NT_SUCCESS(Status)) && (MmTranslationType != BlNone))
{
/* TODO */
EfiPrintf(L"unhandled virtual path\r\n");
Status = STATUS_NOT_IMPLEMENTED;
}
}
@ -299,6 +300,23 @@ BlMmUnmapVirtualAddressEx (
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,

View 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)
{
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 @@ MmPapAllocateRegionFromMdl (
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,11 +615,21 @@ BlMmFreePhysicalPages (
)
{
/* 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
BlMmGetMemoryMap (
_In_ PLIST_ENTRY MemoryMap,