mirror of https://github.com/acidanthera/audk.git
Ring3: Properly refactored MemoryPoolLib to support User spaces.
This commit is contained in:
parent
9216e4195e
commit
b6a7e2b3be
|
@ -259,7 +259,7 @@ Ring3Initialization (
|
|||
gBS = &mBootServices;
|
||||
gRT = &mRuntimeServices;
|
||||
|
||||
CoreInitializePool ();
|
||||
CoreInitializePool (FALSE);
|
||||
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
|
||||
BOOLEAN mOnGuarding = FALSE;
|
||||
|
||||
STATIC UINTN mMemoryTypes[EfiMaxMemoryType];
|
||||
STATIC UINTN mMemoryTypes[MAX_MEMORY_TYPE];
|
||||
STATIC UINTN mNumberOfUsers = 0;
|
||||
|
||||
STATIC
|
||||
|
@ -32,18 +32,16 @@ GetMemoryType (
|
|||
|
||||
for (Index = 0; Index < mNumberOfUsers; ++Index) {
|
||||
if (mMemoryTypes[Index] == UserPageTable) {
|
||||
break;
|
||||
return Index;
|
||||
}
|
||||
}
|
||||
|
||||
if (Index == mNumberOfUsers) {
|
||||
++mNumberOfUsers;
|
||||
mMemoryTypes[Index] = UserPageTable;
|
||||
}
|
||||
ASSERT (mNumberOfUsers < MAX_MEMORY_TYPE);
|
||||
|
||||
ASSERT (mNumberOfUsers <= EfiMaxMemoryType);
|
||||
mMemoryTypes[mNumberOfUsers] = UserPageTable;
|
||||
++mNumberOfUsers;
|
||||
|
||||
return Index;
|
||||
return (mNumberOfUsers - 1);
|
||||
}
|
||||
|
||||
STATIC
|
||||
|
|
|
@ -2261,7 +2261,7 @@ CoreInitializeMemoryServices (
|
|||
// Initialize the spin locks and maps in the memory services.
|
||||
// Also fill in the memory services into the EFI Boot Services Table
|
||||
//
|
||||
CoreInitializePool ();
|
||||
CoreInitializePool (TRUE);
|
||||
|
||||
//
|
||||
// Initialize Local Variables
|
||||
|
|
|
@ -36,13 +36,19 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
|
|||
#define GUARD_HEAP_TYPE_ALL \
|
||||
(GUARD_HEAP_TYPE_PAGE|GUARD_HEAP_TYPE_POOL|GUARD_HEAP_TYPE_FREED)
|
||||
|
||||
#define MAX_MEMORY_TYPE 100
|
||||
|
||||
/**
|
||||
Called to initialize the pool.
|
||||
|
||||
@param IsCore Selects between the purposes of mPoolHead array.
|
||||
In DxeCore each element describes EFI_MEMORY_TYPE.
|
||||
In DxeRing3 each element describes User space.
|
||||
|
||||
**/
|
||||
VOID
|
||||
CoreInitializePool (
|
||||
VOID
|
||||
IN BOOLEAN IsCore
|
||||
);
|
||||
|
||||
/**
|
||||
|
|
|
@ -80,7 +80,9 @@ typedef struct {
|
|||
//
|
||||
// Pool header for each memory type.
|
||||
//
|
||||
POOL mPoolHead[EfiMaxMemoryType];
|
||||
POOL mPoolHead[MAX_MEMORY_TYPE];
|
||||
|
||||
STATIC BOOLEAN mIsCore;
|
||||
|
||||
//
|
||||
// List of pool header to search for the appropriate memory type.
|
||||
|
@ -185,12 +187,14 @@ GetPoolIndexFromSize (
|
|||
**/
|
||||
VOID
|
||||
CoreInitializePool (
|
||||
VOID
|
||||
IN BOOLEAN IsCore
|
||||
)
|
||||
{
|
||||
UINTN Type;
|
||||
UINTN Index;
|
||||
|
||||
mIsCore = IsCore;
|
||||
|
||||
for (Type = 0; Type < EfiMaxMemoryType; Type++) {
|
||||
mPoolHead[Type].Signature = 0;
|
||||
mPoolHead[Type].Used = 0;
|
||||
|
@ -219,6 +223,14 @@ LookupPoolHead (
|
|||
POOL *Pool;
|
||||
UINTN Index;
|
||||
|
||||
if (!mIsCore) {
|
||||
if ((UINT32)MemoryType < MAX_MEMORY_TYPE) {
|
||||
return &mPoolHead[MemoryType];
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ((UINT32)MemoryType < EfiMaxMemoryType) {
|
||||
return &mPoolHead[MemoryType];
|
||||
}
|
||||
|
@ -285,8 +297,8 @@ CoreInternalAllocatePool (
|
|||
//
|
||||
// If it's not a valid type, fail it
|
||||
//
|
||||
if (((PoolType >= EfiMaxMemoryType) && (PoolType < MEMORY_TYPE_OEM_RESERVED_MIN)) ||
|
||||
(PoolType == EfiConventionalMemory) || (PoolType == EfiPersistentMemory) || (PoolType == EfiUnacceptedMemoryType))
|
||||
if (mIsCore && (((PoolType >= EfiMaxMemoryType) && (PoolType < MEMORY_TYPE_OEM_RESERVED_MIN)) ||
|
||||
(PoolType == EfiConventionalMemory) || (PoolType == EfiPersistentMemory) || (PoolType == EfiUnacceptedMemoryType)))
|
||||
{
|
||||
return EFI_INVALID_PARAMETER;
|
||||
}
|
||||
|
@ -395,10 +407,11 @@ CoreAllocatePoolI (
|
|||
|
||||
ASSERT_LOCKED (&mPoolMemoryLock);
|
||||
|
||||
if ((PoolType == EfiReservedMemoryType) ||
|
||||
if (mIsCore &&
|
||||
((PoolType == EfiReservedMemoryType) ||
|
||||
(PoolType == EfiACPIMemoryNVS) ||
|
||||
(PoolType == EfiRuntimeServicesCode) ||
|
||||
(PoolType == EfiRuntimeServicesData))
|
||||
(PoolType == EfiRuntimeServicesData)))
|
||||
{
|
||||
Granularity = RUNTIME_PAGE_ALLOCATION_GRANULARITY;
|
||||
} else {
|
||||
|
@ -724,10 +737,11 @@ CoreFreePoolI (
|
|||
Pool->Used -= Size;
|
||||
DEBUG ((DEBUG_POOL, "FreePool: %p (len %lx) %,ld\n", Head->Data, (UINT64)(Head->Size - POOL_OVERHEAD), (UINT64)Pool->Used));
|
||||
|
||||
if ((Head->Type == EfiReservedMemoryType) ||
|
||||
if (mIsCore &&
|
||||
((Head->Type == EfiReservedMemoryType) ||
|
||||
(Head->Type == EfiACPIMemoryNVS) ||
|
||||
(Head->Type == EfiRuntimeServicesCode) ||
|
||||
(Head->Type == EfiRuntimeServicesData))
|
||||
(Head->Type == EfiRuntimeServicesData)))
|
||||
{
|
||||
Granularity = RUNTIME_PAGE_ALLOCATION_GRANULARITY;
|
||||
} else {
|
||||
|
@ -898,6 +912,10 @@ IsMemoryTypeToGuard (
|
|||
UINT64 TestBit;
|
||||
UINT64 ConfigBit;
|
||||
|
||||
if (!mIsCore) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (AllocateType == AllocateAddress) {
|
||||
return FALSE;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue