mirror of
https://github.com/CloverHackyColor/CloverBootloader.git
synced 2024-11-10 09:40:53 +01:00
fix memory allocation for legacy Clover
Signed-off-by: Sergey Isakov <isakov-sl@bk.ru>
This commit is contained in:
parent
ecab494bd2
commit
f76a8c3019
@ -139,13 +139,17 @@ FreePages (
|
||||
IN UINTN Pages
|
||||
)
|
||||
{
|
||||
// EFI_STATUS Status;
|
||||
EFI_STATUS Status;
|
||||
|
||||
// ASSERT (Pages != 0);
|
||||
if (Pages != 0) {
|
||||
gBS->FreePages((EFI_PHYSICAL_ADDRESS)(UINTN)Buffer, Pages);
|
||||
if (!Pages) {
|
||||
return;
|
||||
}
|
||||
Status = gBS->FreePages ((EFI_PHYSICAL_ADDRESS) (UINTN) Buffer, Pages);
|
||||
// ASSERT_EFI_ERROR (Status);
|
||||
if (EFI_ERROR (Status)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -183,7 +187,10 @@ InternalAllocateAlignedPages (
|
||||
//
|
||||
// Alignment must be a power of two or zero.
|
||||
//
|
||||
ASSERT ((Alignment & (Alignment - 1)) == 0);
|
||||
// ASSERT ((Alignment & (Alignment - 1)) == 0);
|
||||
if ((Alignment & (Alignment - 1)) != 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (Pages == 0) {
|
||||
return NULL;
|
||||
@ -197,7 +204,10 @@ InternalAllocateAlignedPages (
|
||||
//
|
||||
// Make sure that Pages plus EFI_SIZE_TO_PAGES (Alignment) does not overflow.
|
||||
//
|
||||
ASSERT (RealPages > Pages);
|
||||
// ASSERT (RealPages > Pages);
|
||||
if (RealPages < Pages) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Status = gBS->AllocatePages (AllocateAnyPages, MemoryType, RealPages, &Memory);
|
||||
if (EFI_ERROR (Status)) {
|
||||
@ -210,7 +220,10 @@ InternalAllocateAlignedPages (
|
||||
// Free first unaligned page(s).
|
||||
//
|
||||
Status = gBS->FreePages (Memory, UnalignedPages);
|
||||
ASSERT_EFI_ERROR (Status);
|
||||
// ASSERT_EFI_ERROR (Status);
|
||||
if (EFI_ERROR (Status)) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
Memory = AlignedMemory + EFI_PAGES_TO_SIZE (Pages);
|
||||
UnalignedPages = RealPages - Pages - UnalignedPages;
|
||||
@ -218,8 +231,11 @@ InternalAllocateAlignedPages (
|
||||
//
|
||||
// Free last unaligned page(s).
|
||||
//
|
||||
/* Status = */ gBS->FreePages (Memory, UnalignedPages);
|
||||
Status = gBS->FreePages (Memory, UnalignedPages);
|
||||
// ASSERT_EFI_ERROR (Status);
|
||||
if (EFI_ERROR (Status)) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
//
|
||||
@ -344,9 +360,11 @@ FreeAlignedPages (
|
||||
{
|
||||
// EFI_STATUS Status;
|
||||
|
||||
if (Pages != 0) {
|
||||
/* Status = */ gBS->FreePages((EFI_PHYSICAL_ADDRESS)(UINTN)Buffer, Pages);
|
||||
// ASSERT (Pages != 0);
|
||||
if (!Pages || !Buffer) {
|
||||
return;
|
||||
}
|
||||
/* Status = */gBS->FreePages ((EFI_PHYSICAL_ADDRESS) (UINTN) Buffer, Pages);
|
||||
// ASSERT_EFI_ERROR (Status);
|
||||
}
|
||||
|
||||
@ -370,12 +388,7 @@ InternalAllocatePool (
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
VOID *Memory = NULL;
|
||||
|
||||
if (AllocationSize == 0)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
VOID *Memory;
|
||||
|
||||
Status = gBS->AllocatePool (MemoryType, AllocationSize, &Memory);
|
||||
if (EFI_ERROR (Status)) {
|
||||
@ -567,13 +580,15 @@ InternalAllocateCopyPool (
|
||||
)
|
||||
{
|
||||
VOID *Memory;
|
||||
if (!Buffer || (AllocationSize > (MAX_ADDRESS - (UINTN)Buffer + 1)))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// ASSERT (Buffer != NULL);
|
||||
if (!Buffer) {
|
||||
return NULL;
|
||||
}
|
||||
// ASSERT (AllocationSize <= (MAX_ADDRESS - (UINTN) Buffer + 1));
|
||||
if (AllocationSize > (MAX_ADDRESS - (UINTN) Buffer + 1)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Memory = InternalAllocatePool (PoolType, AllocationSize);
|
||||
if (Memory != NULL) {
|
||||
|
Loading…
Reference in New Issue
Block a user