\r
#include "DxeMain.h"\r
#include "Imem.h"\r
-#include "HeapGuard.h"
+#include "HeapGuard.h"\r
\r
STATIC EFI_LOCK mPoolMemoryLock = EFI_INITIALIZE_LOCK_VARIABLE (TPL_NOTIFY);\r
\r
}\r
}\r
\r
- Pool = CoreAllocatePoolI (EfiBootServicesData, sizeof (POOL), FALSE);
+ Pool = CoreAllocatePoolI (EfiBootServicesData, sizeof (POOL), FALSE);\r
if (Pool == NULL) {\r
return NULL;\r
}\r
OUT VOID **Buffer\r
)\r
{\r
- EFI_STATUS Status;
- BOOLEAN NeedGuard;
+ EFI_STATUS Status;\r
+ BOOLEAN NeedGuard;\r
\r
//\r
// If it's not a valid type, fail it\r
return EFI_OUT_OF_RESOURCES;\r
}\r
\r
- NeedGuard = IsPoolTypeToGuard (PoolType) && !mOnGuarding;
-
+ NeedGuard = IsPoolTypeToGuard (PoolType) && !mOnGuarding;\r
+\r
//\r
// Acquire the memory lock and make the allocation\r
//\r
return EFI_OUT_OF_RESOURCES;\r
}\r
\r
- *Buffer = CoreAllocatePoolI (PoolType, Size, NeedGuard);
+ *Buffer = CoreAllocatePoolI (PoolType, Size, NeedGuard);\r
CoreReleaseLock (&mPoolMemoryLock);\r
return (*Buffer != NULL) ? EFI_SUCCESS : EFI_OUT_OF_RESOURCES;\r
}\r
@param PoolType The type of memory for the new pool pages\r
@param NoPages No of pages to allocate\r
@param Granularity Bits to align.\r
- @param NeedGuard Flag to indicate Guard page is needed or not
+ @param NeedGuard Flag to indicate Guard page is needed or not\r
\r
@return The allocated memory, or NULL\r
\r
CoreAllocatePoolPagesI (\r
IN EFI_MEMORY_TYPE PoolType,\r
IN UINTN NoPages,\r
- IN UINTN Granularity,
- IN BOOLEAN NeedGuard
+ IN UINTN Granularity,\r
+ IN BOOLEAN NeedGuard\r
)\r
{\r
VOID *Buffer;\r
return NULL;\r
}\r
\r
- Buffer = CoreAllocatePoolPages (PoolType, NoPages, Granularity, NeedGuard);
+ Buffer = CoreAllocatePoolPages (PoolType, NoPages, Granularity, NeedGuard);\r
CoreReleaseMemoryLock ();\r
\r
if (Buffer != NULL) {\r
- if (NeedGuard) {
- SetGuardForMemory ((EFI_PHYSICAL_ADDRESS)(UINTN)Buffer, NoPages);
- }
- ApplyMemoryProtectionPolicy(EfiConventionalMemory, PoolType,
+ if (NeedGuard) {\r
+ SetGuardForMemory ((EFI_PHYSICAL_ADDRESS)(UINTN)Buffer, NoPages);\r
+ }\r
+ ApplyMemoryProtectionPolicy(EfiConventionalMemory, PoolType,\r
(EFI_PHYSICAL_ADDRESS)(UINTN)Buffer, EFI_PAGES_TO_SIZE (NoPages));\r
}\r
return Buffer;\r
\r
@param PoolType Type of pool to allocate\r
@param Size The amount of pool to allocate\r
- @param NeedGuard Flag to indicate Guard page is needed or not
+ @param NeedGuard Flag to indicate Guard page is needed or not\r
\r
@return The allocate pool, or NULL\r
\r
VOID *\r
CoreAllocatePoolI (\r
IN EFI_MEMORY_TYPE PoolType,\r
- IN UINTN Size,
- IN BOOLEAN NeedGuard
+ IN UINTN Size,\r
+ IN BOOLEAN NeedGuard\r
)\r
{\r
POOL *Pool;\r
UINTN Offset, MaxOffset;\r
UINTN NoPages;\r
UINTN Granularity;\r
- BOOLEAN HasPoolTail;
+ BOOLEAN HasPoolTail;\r
\r
ASSERT_LOCKED (&mPoolMemoryLock);\r
\r
// Adjust the size by the pool header & tail overhead\r
//\r
\r
- HasPoolTail = !(NeedGuard &&
- ((PcdGet8 (PcdHeapGuardPropertyMask) & BIT7) == 0));
-
+ HasPoolTail = !(NeedGuard &&\r
+ ((PcdGet8 (PcdHeapGuardPropertyMask) & BIT7) == 0));\r
+\r
//\r
// Adjusting the Size to be of proper alignment so that\r
// we don't get an unaligned access fault later when\r
// If allocation is over max size, just allocate pages for the request\r
// (slow)\r
//\r
- if (Index >= SIZE_TO_LIST (Granularity) || NeedGuard) {
- if (!HasPoolTail) {
- Size -= sizeof (POOL_TAIL);
- }
- NoPages = EFI_SIZE_TO_PAGES (Size) + EFI_SIZE_TO_PAGES (Granularity) - 1;
+ if (Index >= SIZE_TO_LIST (Granularity) || NeedGuard) {\r
+ if (!HasPoolTail) {\r
+ Size -= sizeof (POOL_TAIL);\r
+ }\r
+ NoPages = EFI_SIZE_TO_PAGES (Size) + EFI_SIZE_TO_PAGES (Granularity) - 1;\r
NoPages &= ~(UINTN)(EFI_SIZE_TO_PAGES (Granularity) - 1);\r
- Head = CoreAllocatePoolPagesI (PoolType, NoPages, Granularity, NeedGuard);
- if (NeedGuard) {
- Head = AdjustPoolHeadA ((EFI_PHYSICAL_ADDRESS)(UINTN)Head, NoPages, Size);
- }
+ Head = CoreAllocatePoolPagesI (PoolType, NoPages, Granularity, NeedGuard);\r
+ if (NeedGuard) {\r
+ Head = AdjustPoolHeadA ((EFI_PHYSICAL_ADDRESS)(UINTN)Head, NoPages, Size);\r
+ }\r
goto Done;\r
}\r
\r
//\r
// Get another page\r
//\r
- NewPage = CoreAllocatePoolPagesI (PoolType, EFI_SIZE_TO_PAGES (Granularity),
- Granularity, NeedGuard);
+ NewPage = CoreAllocatePoolPagesI (PoolType, EFI_SIZE_TO_PAGES (Granularity),\r
+ Granularity, NeedGuard);\r
if (NewPage == NULL) {\r
goto Done;\r
}\r
\r
if (Head != NULL) {\r
\r
- //
- // Account the allocation
- //
- Pool->Used += Size;
-
+ //\r
+ // Account the allocation\r
+ //\r
+ Pool->Used += Size;\r
+\r
//\r
// If we have a pool buffer, fill in the header & tail info\r
//\r
Head->Size = Size;\r
Head->Type = (EFI_MEMORY_TYPE) PoolType;\r
Buffer = Head->Data;\r
-
- if (HasPoolTail) {
- Tail = HEAD_TO_TAIL (Head);
- Tail->Signature = POOL_TAIL_SIGNATURE;
- Tail->Size = Size;
-
- Size -= POOL_OVERHEAD;
- } else {
- Size -= SIZE_OF_POOL_HEAD;
- }
-
- DEBUG_CLEAR_MEMORY (Buffer, Size);
+\r
+ if (HasPoolTail) {\r
+ Tail = HEAD_TO_TAIL (Head);\r
+ Tail->Signature = POOL_TAIL_SIGNATURE;\r
+ Tail->Size = Size;\r
+\r
+ Size -= POOL_OVERHEAD;\r
+ } else {\r
+ Size -= SIZE_OF_POOL_HEAD;\r
+ }\r
+\r
+ DEBUG_CLEAR_MEMORY (Buffer, Size);\r
\r
DEBUG ((\r
DEBUG_POOL,\r
"AllocatePoolI: Type %x, Addr %p (len %lx) %,ld\n", PoolType,\r
Buffer,\r
- (UINT64)Size,
+ (UINT64)Size,\r
(UINT64) Pool->Used\r
));\r
\r
(EFI_PHYSICAL_ADDRESS)(UINTN)Memory, EFI_PAGES_TO_SIZE (NoPages));\r
}\r
\r
-/**
- Internal function. Frees guarded pool pages.
-
- @param PoolType The type of memory for the pool pages
- @param Memory The base address to free
- @param NoPages The number of pages to free
-
-**/
-STATIC
-VOID
-CoreFreePoolPagesWithGuard (
- IN EFI_MEMORY_TYPE PoolType,
- IN EFI_PHYSICAL_ADDRESS Memory,
- IN UINTN NoPages
- )
-{
- EFI_PHYSICAL_ADDRESS MemoryGuarded;
- UINTN NoPagesGuarded;
-
- MemoryGuarded = Memory;
- NoPagesGuarded = NoPages;
-
- AdjustMemoryF (&Memory, &NoPages);
- CoreFreePoolPagesI (PoolType, Memory, NoPages);
-
- UnsetGuardForMemory (MemoryGuarded, NoPagesGuarded);
-}
-
+/**\r
+ Internal function. Frees guarded pool pages.\r
+\r
+ @param PoolType The type of memory for the pool pages\r
+ @param Memory The base address to free\r
+ @param NoPages The number of pages to free\r
+\r
+**/\r
+STATIC\r
+VOID\r
+CoreFreePoolPagesWithGuard (\r
+ IN EFI_MEMORY_TYPE PoolType,\r
+ IN EFI_PHYSICAL_ADDRESS Memory,\r
+ IN UINTN NoPages\r
+ )\r
+{\r
+ EFI_PHYSICAL_ADDRESS MemoryGuarded;\r
+ UINTN NoPagesGuarded;\r
+\r
+ MemoryGuarded = Memory;\r
+ NoPagesGuarded = NoPages;\r
+\r
+ AdjustMemoryF (&Memory, &NoPages);\r
+ CoreFreePoolPagesI (PoolType, Memory, NoPages);\r
+\r
+ UnsetGuardForMemory (MemoryGuarded, NoPagesGuarded);\r
+}\r
+\r
/**\r
Internal function to free a pool entry.\r
Caller must have the memory lock held\r
UINTN Offset;\r
BOOLEAN AllFree;\r
UINTN Granularity;\r
- BOOLEAN IsGuarded;
- BOOLEAN HasPoolTail;
+ BOOLEAN IsGuarded;\r
+ BOOLEAN HasPoolTail;\r
\r
ASSERT(Buffer != NULL);\r
//\r
return EFI_INVALID_PARAMETER;\r
}\r
\r
- IsGuarded = IsPoolTypeToGuard (Head->Type) &&
- IsMemoryGuarded ((EFI_PHYSICAL_ADDRESS)(UINTN)Head);
- HasPoolTail = !(IsGuarded &&
- ((PcdGet8 (PcdHeapGuardPropertyMask) & BIT7) == 0));
-\r
- if (HasPoolTail) {
- Tail = HEAD_TO_TAIL (Head);
- ASSERT (Tail != NULL);
-\r
- //
- // Debug
- //
- ASSERT (Tail->Signature == POOL_TAIL_SIGNATURE);
- ASSERT (Head->Size == Tail->Size);
-\r
- if (Tail->Signature != POOL_TAIL_SIGNATURE) {
- return EFI_INVALID_PARAMETER;
- }
-
- if (Head->Size != Tail->Size) {
- return EFI_INVALID_PARAMETER;
- }
+ IsGuarded = IsPoolTypeToGuard (Head->Type) &&\r
+ IsMemoryGuarded ((EFI_PHYSICAL_ADDRESS)(UINTN)Head);\r
+ HasPoolTail = !(IsGuarded &&\r
+ ((PcdGet8 (PcdHeapGuardPropertyMask) & BIT7) == 0));\r
+\r
+ if (HasPoolTail) {\r
+ Tail = HEAD_TO_TAIL (Head);\r
+ ASSERT (Tail != NULL);\r
+\r
+ //\r
+ // Debug\r
+ //\r
+ ASSERT (Tail->Signature == POOL_TAIL_SIGNATURE);\r
+ ASSERT (Head->Size == Tail->Size);\r
+\r
+ if (Tail->Signature != POOL_TAIL_SIGNATURE) {\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+\r
+ if (Head->Size != Tail->Size) {\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
}\r
\r
- ASSERT_LOCKED (&mPoolMemoryLock);
-
+ ASSERT_LOCKED (&mPoolMemoryLock);\r
+\r
//\r
// Determine the pool type and account for it\r
//\r
//\r
// If it's not on the list, it must be pool pages\r
//\r
- if (Index >= SIZE_TO_LIST (Granularity) || IsGuarded) {
+ if (Index >= SIZE_TO_LIST (Granularity) || IsGuarded) {\r
\r
//\r
// Return the memory pages back to free memory\r
//\r
- NoPages = EFI_SIZE_TO_PAGES (Size) + EFI_SIZE_TO_PAGES (Granularity) - 1;
+ NoPages = EFI_SIZE_TO_PAGES (Size) + EFI_SIZE_TO_PAGES (Granularity) - 1;\r
NoPages &= ~(UINTN)(EFI_SIZE_TO_PAGES (Granularity) - 1);\r
- if (IsGuarded) {
- Head = AdjustPoolHeadF ((EFI_PHYSICAL_ADDRESS)(UINTN)Head);
- CoreFreePoolPagesWithGuard (
- Pool->MemoryType,
- (EFI_PHYSICAL_ADDRESS)(UINTN)Head,
- NoPages
- );
- } else {
- CoreFreePoolPagesI (
- Pool->MemoryType,
- (EFI_PHYSICAL_ADDRESS)(UINTN)Head,
- NoPages
- );
- }
+ if (IsGuarded) {\r
+ Head = AdjustPoolHeadF ((EFI_PHYSICAL_ADDRESS)(UINTN)Head);\r
+ CoreFreePoolPagesWithGuard (\r
+ Pool->MemoryType,\r
+ (EFI_PHYSICAL_ADDRESS)(UINTN)Head,\r
+ NoPages\r
+ );\r
+ } else {\r
+ CoreFreePoolPagesI (\r
+ Pool->MemoryType,\r
+ (EFI_PHYSICAL_ADDRESS)(UINTN)Head,\r
+ NoPages\r
+ );\r
+ }\r
\r
} else {\r
\r