[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 _In_ PHYSICAL_ADDRESS Address
); );
NTSTATUS
MmPapFreePages (
_In_ PVOID Address,
_In_ ULONG WhichList
);
NTSTATUS NTSTATUS
MmPapAllocatePagesInRange ( MmPapAllocatePagesInRange (
_Inout_ PVOID* PhysicalAddress, _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 **************************************************/ /* BLOCK ALLOCATOR ROUTINES **************************************************/
NTSTATUS NTSTATUS

View file

@ -214,9 +214,7 @@ BlockIopFreeAlignedBuffer (
if (*BufferSize) if (*BufferSize)
{ {
EfiPrintf(L"Aligned free not yet implemented\r\n"); Status = MmPapFreePages(*Buffer, BL_MM_INCLUDE_MAPPED_ALLOCATED);
Status = STATUS_NOT_IMPLEMENTED;
//Status = MmPapFreePages(*Buffer, 1);
*Buffer = NULL; *Buffer = NULL;
*BufferSize = 0; *BufferSize = 0;
@ -1881,8 +1879,7 @@ BlockIopInitialize (
/* Free the prefetch buffer is one was allocated */ /* Free the prefetch buffer is one was allocated */
if (BlockIopPrefetchBuffer) if (BlockIopPrefetchBuffer)
{ {
EfiPrintf(L"Failure path not implemented %lx\r\n", Status); MmPapFreePages(BlockIopPrefetchBuffer, BL_MM_INCLUDE_MAPPED_ALLOCATED);
//MmPapFreePages(BlockIopPrefetchBuffer, 1);
} }
} }

View file

@ -163,8 +163,7 @@ BiCloseKey (
} }
/* Unmap the hive */ /* Unmap the hive */
//MmPapFreePages(KeyHive->ImageBase, 1); MmPapFreePages(KeyHive->BaseBlock, BL_MM_INCLUDE_MAPPED_ALLOCATED);
EfiPrintf(L"Leaking hive memory\r\n");
/* Free the hive and hive path */ /* Free the hive and hive path */
BlMmFreeHeap(KeyHive->FilePath); BlMmFreeHeap(KeyHive->FilePath);
@ -516,8 +515,7 @@ BiLoadHive (
RtlCopyMemory(NewBaseBlock, BaseBlock, HiveSize); RtlCopyMemory(NewBaseBlock, BaseBlock, HiveSize);
/* Free the old data */ /* Free the old data */
EfiPrintf(L"Leaking old hive buffer\r\n"); MmPapFreePages(BaseBlock, BL_MM_INCLUDE_MAPPED_ALLOCATED);
//MmPapFreePages(BaseBlock, 1);
/* Update our pointers */ /* Update our pointers */
BaseBlock = NewBaseBlock; BaseBlock = NewBaseBlock;
@ -607,8 +605,7 @@ Quickie:
/* If we had logging data, free it */ /* If we had logging data, free it */
if (LogData) if (LogData)
{ {
EfiPrintf(L"Leaking log buffer\r\n"); MmPapFreePages(LogData, BL_MM_INCLUDE_MAPPED_ALLOCATED);
//MmPapFreePages(LogData, 1);
} }
/* 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 we mapped the hive, free it */
if (BaseBlock) if (BaseBlock)
{ {
EfiPrintf(L"Leaking base block on failure\r\n"); MmPapFreePages(BaseBlock, BL_MM_INCLUDE_MAPPED_ALLOCATED);
//MmPapFreePages(BaseBlock, 1u);
} }
/* If we opened the device, close it */ /* If we opened the device, close it */

View file

@ -194,8 +194,7 @@ ImgpCloseFile (
if (File->Flags & BL_IMG_REMOTE_FILE) if (File->Flags & BL_IMG_REMOTE_FILE)
{ {
/* Then only free the memory in that scenario */ /* Then only free the memory in that scenario */
EfiPrintf(L"TODO\r\n"); return MmPapFreePages(File->BaseAddress, BL_MM_INCLUDE_MAPPED_ALLOCATED);
//return MmPapFreePages(File->BaseAddress, TRUE);
} }
} }
@ -210,8 +209,37 @@ BlImgUnallocateImageBuffer (
_In_ ULONG ImageFlags _In_ ULONG ImageFlags
) )
{ {
EfiPrintf(L"leaking the shit out of %p\r\n", ImageBase); PHYSICAL_ADDRESS PhysicalAddress;
return STATUS_NOT_IMPLEMENTED; 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 else
{ {
/* Free the physical buffer */ /* Free the physical buffer */
//MmPapFreePages(VirtualAddress, 1); MmPapFreePages(BaseAddress, BL_MM_INCLUDE_MAPPED_ALLOCATED);
EfiPrintf(L"Leaking memory\r\n");
} }
} }
@ -1192,8 +1219,7 @@ Quickie:
if (HashBuffer) if (HashBuffer)
{ {
/* Free it */ /* Free it */
EfiPrintf(L"Leadking hash: %p\r\n", HashBuffer); MmPapFreePages(HashBuffer, BL_MM_INCLUDE_MAPPED_ALLOCATED);
//MmPapFreePages(HashBuffer, TRUE);
} }
/* Check if we have a certificate directory */ /* Check if we have a certificate directory */
@ -1234,8 +1260,7 @@ Quickie:
else else
{ {
/* Into a physical buffer -- free it */ /* Into a physical buffer -- free it */
EfiPrintf(L"Leaking physical pages\r\n"); MmPapFreePages(VirtualAddress, BL_MM_INCLUDE_MAPPED_ALLOCATED);
// MmPapFreePages(VirtualAddress, TRUE);
} }
} }
} }
@ -1888,7 +1913,7 @@ Quickie:
if (BootData) if (BootData)
{ {
/* Free it */ /* Free it */
//MmPapFreePages(bootData, TRUE); MmPapFreePages(BootData, BL_MM_INCLUDE_MAPPED_ALLOCATED);
} }
/* All done */ /* All done */

View file

@ -284,6 +284,7 @@ BlMmUnmapVirtualAddressEx (
if ((NT_SUCCESS(Status)) && (MmTranslationType != BlNone)) if ((NT_SUCCESS(Status)) && (MmTranslationType != BlNone))
{ {
/* TODO */ /* 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 NTSTATUS
BlpMmInitialize ( BlpMmInitialize (
_In_ PBL_MEMORY_DATA MemoryData, _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? */ /* Does the memory we received not exactly fall onto the beginning of its descriptor? */
if (LocalDescriptor.BasePage != FoundDescriptor->BasePage) if (LocalDescriptor.BasePage != FoundDescriptor->BasePage)
{ {
EfiPrintf(L"Local Page: %08I64X Found Page: %08I64X\r\n", LocalDescriptor.BasePage, FoundDescriptor->BasePage);
TempDescriptor = MmMdInitByteGranularDescriptor(FoundDescriptor->Flags, TempDescriptor = MmMdInitByteGranularDescriptor(FoundDescriptor->Flags,
FoundDescriptor->Type, FoundDescriptor->Type,
FoundDescriptor->BasePage, FoundDescriptor->BasePage,
@ -216,7 +215,6 @@ MmPapAllocateRegionFromMdl (
LocalDescriptor.VirtualPage + LocalDescriptor.PageCount : 0; LocalDescriptor.VirtualPage + LocalDescriptor.PageCount : 0;
if (LocalEndPage != FoundEndPage) if (LocalEndPage != FoundEndPage)
{ {
EfiPrintf(L"Local Page: %08I64X Found Page: %08I64X\r\n", LocalEndPage, FoundEndPage);
TempDescriptor = MmMdInitByteGranularDescriptor(FoundDescriptor->Flags, TempDescriptor = MmMdInitByteGranularDescriptor(FoundDescriptor->Flags,
FoundDescriptor->Type, FoundDescriptor->Type,
LocalEndPage, 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 STATUS_SUCCESS;
//return MmPapFreePhysicalPages(4, 0, Address); //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 NTSTATUS
BlMmGetMemoryMap ( BlMmGetMemoryMap (
_In_ PLIST_ENTRY MemoryMap, _In_ PLIST_ENTRY MemoryMap,