- 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;