mirror of
https://github.com/acidanthera/audk.git
synced 2025-07-22 13:14:26 +02:00
InOsEmuPkg: Make the Guard MemoryAllocationLib handle EFI allocated pages correctly.
signed-off-by: andrewfish git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@11887 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
parent
1d7ac5a617
commit
8e4b3d32a8
@ -150,8 +150,16 @@ FreePages (
|
|||||||
IN UINTN Pages
|
IN UINTN Pages
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
EFI_STATUS Status;
|
||||||
|
|
||||||
ASSERT (Pages != 0);
|
ASSERT (Pages != 0);
|
||||||
FreePool (Buffer);
|
if (!gEmuThunk->Free (Buffer)) {
|
||||||
|
// The Free thunk will not free memory allocated in emulated EFI memory.
|
||||||
|
// The assmuption is this was allocated directly by EFI. We need this as some
|
||||||
|
// times protocols or EFI BootServices can return dynamically allocated buffers.
|
||||||
|
Status = gBS->FreePages ((EFI_PHYSICAL_ADDRESS) (UINTN) Buffer, Pages);
|
||||||
|
ASSERT_EFI_ERROR (Status);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -178,6 +186,7 @@ InternalAllocateAlignedPages (
|
|||||||
IN UINTN Alignment
|
IN UINTN Alignment
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
EFI_STATUS Status;
|
||||||
VOID *Memory;
|
VOID *Memory;
|
||||||
UINTN AlignedMemory;
|
UINTN AlignedMemory;
|
||||||
UINTN AlignmentMask;
|
UINTN AlignmentMask;
|
||||||
@ -213,7 +222,7 @@ InternalAllocateAlignedPages (
|
|||||||
//
|
//
|
||||||
// Free first unaligned page(s).
|
// Free first unaligned page(s).
|
||||||
//
|
//
|
||||||
FreePool (Memory);
|
FreePages (Memory, UnalignedPages);
|
||||||
}
|
}
|
||||||
Memory = (VOID *) (AlignedMemory + EFI_PAGES_TO_SIZE (Pages));
|
Memory = (VOID *) (AlignedMemory + EFI_PAGES_TO_SIZE (Pages));
|
||||||
UnalignedPages = RealPages - Pages - UnalignedPages;
|
UnalignedPages = RealPages - Pages - UnalignedPages;
|
||||||
@ -221,7 +230,7 @@ InternalAllocateAlignedPages (
|
|||||||
//
|
//
|
||||||
// Free last unaligned page(s).
|
// Free last unaligned page(s).
|
||||||
//
|
//
|
||||||
FreePool (Memory);
|
FreePages (Memory, UnalignedPages);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
//
|
//
|
||||||
@ -341,9 +350,7 @@ FreeAlignedPages (
|
|||||||
IN UINTN Pages
|
IN UINTN Pages
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
ASSERT (Pages != 0);
|
FreePages (Buffer, Pages);
|
||||||
|
|
||||||
FreePool (Buffer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -799,13 +806,14 @@ FreePool (
|
|||||||
IN VOID *Buffer
|
IN VOID *Buffer
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
EFI_STATUS Status;
|
EFI_STATUS Status;
|
||||||
|
|
||||||
if (!gEmuThunk->Free (Buffer)) {
|
if (!gEmuThunk->Free (Buffer)) {
|
||||||
// The Free thunk will not free memory allocated in emulated EFI memory.
|
// The Free thunk will not free memory allocated in emulated EFI memory.
|
||||||
// The assmuption is this was allocated directly by EFI. We need this as some
|
// The assmuption is this was allocated directly by EFI. We need this as some
|
||||||
// times protocols or EFI BootServices can return dynamically allocated buffers.
|
// times protocols or EFI BootServices can return dynamically allocated buffers.
|
||||||
gBS->FreePool (Buffer);
|
Status = gBS->FreePool (Buffer);
|
||||||
|
ASSERT_EFI_ERROR (Status);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user