/** @file\r
UEFI Memory pool management functions.\r
\r
-Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>\r
-This program and the accompanying materials\r
-are licensed and made available under the terms and conditions of the BSD License\r
-which accompanies this distribution. The full text of the license may be found at\r
-http://opensource.org/licenses/bsd-license.php\r
-\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
\r
**/\r
\r
} POOL_FREE;\r
\r
\r
-#define POOL_HEAD_SIGNATURE SIGNATURE_32('p','h','d','0')\r
+#define POOL_HEAD_SIGNATURE SIGNATURE_32('p','h','d','0')\r
+#define POOLPAGE_HEAD_SIGNATURE SIGNATURE_32('p','h','d','1')\r
typedef struct {\r
UINT32 Signature;\r
UINT32 Reserved;\r
UINTN NoPages;\r
UINTN Granularity;\r
BOOLEAN HasPoolTail;\r
+ BOOLEAN PageAsPool;\r
\r
ASSERT_LOCKED (&mPoolMemoryLock);\r
\r
\r
HasPoolTail = !(NeedGuard &&\r
((PcdGet8 (PcdHeapGuardPropertyMask) & BIT7) == 0));\r
+ PageAsPool = (IsHeapGuardEnabled (GUARD_HEAP_TYPE_FREED) && !mOnGuarding);\r
\r
//\r
// Adjusting the Size to be of proper alignment so that\r
// If allocation is over max size, just allocate pages for the request\r
// (slow)\r
//\r
- if (Index >= SIZE_TO_LIST (Granularity) || NeedGuard) {\r
+ if (Index >= SIZE_TO_LIST (Granularity) || NeedGuard || PageAsPool) {\r
if (!HasPoolTail) {\r
Size -= sizeof (POOL_TAIL);\r
}\r
//\r
// If we have a pool buffer, fill in the header & tail info\r
//\r
- Head->Signature = POOL_HEAD_SIGNATURE;\r
+ Head->Signature = (PageAsPool) ? POOLPAGE_HEAD_SIGNATURE : POOL_HEAD_SIGNATURE;\r
Head->Size = Size;\r
Head->Type = (EFI_MEMORY_TYPE) PoolType;\r
Buffer = Head->Data;\r
CoreFreePoolPages (Memory, NoPages);\r
CoreReleaseMemoryLock ();\r
\r
+ GuardFreedPagesChecked (Memory, NoPages);\r
ApplyMemoryProtectionPolicy (PoolType, EfiConventionalMemory,\r
(EFI_PHYSICAL_ADDRESS)(UINTN)Memory, EFI_PAGES_TO_SIZE (NoPages));\r
}\r
UINTN Granularity;\r
BOOLEAN IsGuarded;\r
BOOLEAN HasPoolTail;\r
+ BOOLEAN PageAsPool;\r
\r
ASSERT(Buffer != NULL);\r
//\r
// Get the head & tail of the pool entry\r
//\r
- Head = CR (Buffer, POOL_HEAD, Data, POOL_HEAD_SIGNATURE);\r
+ Head = BASE_CR (Buffer, POOL_HEAD, Data);\r
ASSERT(Head != NULL);\r
\r
- if (Head->Signature != POOL_HEAD_SIGNATURE) {\r
+ if (Head->Signature != POOL_HEAD_SIGNATURE &&\r
+ Head->Signature != POOLPAGE_HEAD_SIGNATURE) {\r
+ ASSERT (Head->Signature == POOL_HEAD_SIGNATURE ||\r
+ Head->Signature == POOLPAGE_HEAD_SIGNATURE);\r
return EFI_INVALID_PARAMETER;\r
}\r
\r
IsMemoryGuarded ((EFI_PHYSICAL_ADDRESS)(UINTN)Head);\r
HasPoolTail = !(IsGuarded &&\r
((PcdGet8 (PcdHeapGuardPropertyMask) & BIT7) == 0));\r
+ PageAsPool = (Head->Signature == POOLPAGE_HEAD_SIGNATURE);\r
\r
if (HasPoolTail) {\r
Tail = HEAD_TO_TAIL (Head);\r
//\r
// If it's not on the list, it must be pool pages\r
//\r
- if (Index >= SIZE_TO_LIST (Granularity) || IsGuarded) {\r
+ if (Index >= SIZE_TO_LIST (Granularity) || IsGuarded || PageAsPool) {\r
\r
//\r
// Return the memory pages back to free memory\r