mirror of https://github.com/acidanthera/audk.git
ArmPkg/UncachedMemoryAllocationLib: restore mapping attributes after free
In order to play nice with platforms that use strict memory permission policies, restore the original mapping attributes when freeing uncached allocations. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>
This commit is contained in:
parent
29e9bf10dc
commit
bb52ec2d6b
|
@ -42,11 +42,6 @@ UncachedInternalAllocateAlignedPages (
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//
|
|
||||||
// Assume all of memory has the same cache attributes, unless we do our magic
|
|
||||||
//
|
|
||||||
UINT64 gAttributes;
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
EFI_PHYSICAL_ADDRESS Base;
|
EFI_PHYSICAL_ADDRESS Base;
|
||||||
VOID *Allocation;
|
VOID *Allocation;
|
||||||
|
@ -54,6 +49,7 @@ typedef struct {
|
||||||
EFI_MEMORY_TYPE MemoryType;
|
EFI_MEMORY_TYPE MemoryType;
|
||||||
BOOLEAN Allocated;
|
BOOLEAN Allocated;
|
||||||
LIST_ENTRY Link;
|
LIST_ENTRY Link;
|
||||||
|
UINT64 Attributes;
|
||||||
} FREE_PAGE_NODE;
|
} FREE_PAGE_NODE;
|
||||||
|
|
||||||
STATIC LIST_ENTRY mPageList = INITIALIZE_LIST_HEAD_VARIABLE (mPageList);
|
STATIC LIST_ENTRY mPageList = INITIALIZE_LIST_HEAD_VARIABLE (mPageList);
|
||||||
|
@ -153,10 +149,7 @@ AllocatePagesFromList (
|
||||||
}
|
}
|
||||||
|
|
||||||
Status = gDS->GetMemorySpaceDescriptor (Memory, &Descriptor);
|
Status = gDS->GetMemorySpaceDescriptor (Memory, &Descriptor);
|
||||||
if (!EFI_ERROR (Status)) {
|
if (EFI_ERROR (Status)) {
|
||||||
// We are making an assumption that all of memory has the same default attributes
|
|
||||||
gAttributes = Descriptor.Attributes;
|
|
||||||
} else {
|
|
||||||
gBS->FreePages (Memory, Pages);
|
gBS->FreePages (Memory, Pages);
|
||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
|
@ -181,6 +174,7 @@ AllocatePagesFromList (
|
||||||
NewNode->Pages = Pages;
|
NewNode->Pages = Pages;
|
||||||
NewNode->Allocated = TRUE;
|
NewNode->Allocated = TRUE;
|
||||||
NewNode->MemoryType = MemoryType;
|
NewNode->MemoryType = MemoryType;
|
||||||
|
NewNode->Attributes = Descriptor.Attributes;
|
||||||
|
|
||||||
InsertTailList (&mPageList, &NewNode->Link);
|
InsertTailList (&mPageList, &NewNode->Link);
|
||||||
|
|
||||||
|
@ -266,6 +260,10 @@ UncachedMemoryAllocationLibDestructor (
|
||||||
// We only free the non-allocated buffer
|
// We only free the non-allocated buffer
|
||||||
if (OldNode->Allocated == FALSE) {
|
if (OldNode->Allocated == FALSE) {
|
||||||
gBS->FreePages ((EFI_PHYSICAL_ADDRESS)(UINTN)OldNode->Base, OldNode->Pages);
|
gBS->FreePages ((EFI_PHYSICAL_ADDRESS)(UINTN)OldNode->Base, OldNode->Pages);
|
||||||
|
|
||||||
|
gDS->SetMemorySpaceAttributes ((EFI_PHYSICAL_ADDRESS)(UINTN)OldNode->Base,
|
||||||
|
EFI_PAGES_TO_SIZE (OldNode->Pages), OldNode->Attributes);
|
||||||
|
|
||||||
RemoveEntryList (&OldNode->Link);
|
RemoveEntryList (&OldNode->Link);
|
||||||
FreePool (OldNode);
|
FreePool (OldNode);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue