summaryrefslogtreecommitdiff
path: root/InOsEmuPkg
diff options
context:
space:
mode:
authorandrewfish <andrewfish@6f19259b-4bc3-4df7-8a09-765794883524>2011-06-25 01:39:09 +0000
committerandrewfish <andrewfish@6f19259b-4bc3-4df7-8a09-765794883524>2011-06-25 01:39:09 +0000
commit8e4b3d32a8baedd7e39d4e82b4e8458e217e7f6e (patch)
treeaeef19682fa481854c0bcf782edf699384eba55b /InOsEmuPkg
parent1d7ac5a617fba582abfddb4ce240b81b2c24742f (diff)
downloadedk2-platforms-8e4b3d32a8baedd7e39d4e82b4e8458e217e7f6e.tar.xz
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
Diffstat (limited to 'InOsEmuPkg')
-rw-r--r--InOsEmuPkg/Library/GuardUefiMemoryAllocationLib/MemoryAllocationLib.c26
1 files changed, 17 insertions, 9 deletions
diff --git a/InOsEmuPkg/Library/GuardUefiMemoryAllocationLib/MemoryAllocationLib.c b/InOsEmuPkg/Library/GuardUefiMemoryAllocationLib/MemoryAllocationLib.c
index 1963c02a07..c457e7c213 100644
--- a/InOsEmuPkg/Library/GuardUefiMemoryAllocationLib/MemoryAllocationLib.c
+++ b/InOsEmuPkg/Library/GuardUefiMemoryAllocationLib/MemoryAllocationLib.c
@@ -150,8 +150,16 @@ FreePages (
IN UINTN Pages
)
{
+ EFI_STATUS Status;
+
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
)
{
+ EFI_STATUS Status;
VOID *Memory;
UINTN AlignedMemory;
UINTN AlignmentMask;
@@ -213,7 +222,7 @@ InternalAllocateAlignedPages (
//
// Free first unaligned page(s).
//
- FreePool (Memory);
+ FreePages (Memory, UnalignedPages);
}
Memory = (VOID *) (AlignedMemory + EFI_PAGES_TO_SIZE (Pages));
UnalignedPages = RealPages - Pages - UnalignedPages;
@@ -221,7 +230,7 @@ InternalAllocateAlignedPages (
//
// Free last unaligned page(s).
//
- FreePool (Memory);
+ FreePages (Memory, UnalignedPages);
}
} else {
//
@@ -341,9 +350,7 @@ FreeAlignedPages (
IN UINTN Pages
)
{
- ASSERT (Pages != 0);
-
- FreePool (Buffer);
+ FreePages (Buffer, Pages);
}
/**
@@ -799,13 +806,14 @@ FreePool (
IN VOID *Buffer
)
{
- EFI_STATUS Status;
-
+ EFI_STATUS Status;
+
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.
- gBS->FreePool (Buffer);
+ Status = gBS->FreePool (Buffer);
+ ASSERT_EFI_ERROR (Status);
}
}