diff options
Diffstat (limited to 'MdeModulePkg/Core/Dxe')
41 files changed, 5186 insertions, 5195 deletions
diff --git a/MdeModulePkg/Core/Dxe/Dispatcher/Dependency.c b/MdeModulePkg/Core/Dxe/Dispatcher/Dependency.c index 89e540ba75..acbf68b700 100644 --- a/MdeModulePkg/Core/Dxe/Dispatcher/Dependency.c +++ b/MdeModulePkg/Core/Dxe/Dispatcher/Dependency.c @@ -15,15 +15,14 @@ SPDX-License-Identifier: BSD-2-Clause-Patent //
// Global stack used to evaluate dependency expressions
//
-BOOLEAN *mDepexEvaluationStack = NULL;
-BOOLEAN *mDepexEvaluationStackEnd = NULL;
-BOOLEAN *mDepexEvaluationStackPointer = NULL;
+BOOLEAN *mDepexEvaluationStack = NULL;
+BOOLEAN *mDepexEvaluationStackEnd = NULL;
+BOOLEAN *mDepexEvaluationStackPointer = NULL;
//
// Worker functions
//
-
/**
Grow size of the Depex stack
@@ -36,8 +35,8 @@ GrowDepexStack ( VOID
)
{
- BOOLEAN *NewStack;
- UINTN Size;
+ BOOLEAN *NewStack;
+ UINTN Size;
Size = DEPEX_STACK_SIZE_INCREMENT;
if (mDepexEvaluationStack != NULL) {
@@ -75,8 +74,6 @@ GrowDepexStack ( return EFI_SUCCESS;
}
-
-
/**
Push an element onto the Boolean Stack.
@@ -115,8 +112,6 @@ PushBool ( return EFI_SUCCESS;
}
-
-
/**
Pop an element from the Boolean stack.
@@ -146,8 +141,6 @@ PopBool ( return EFI_SUCCESS;
}
-
-
/**
Preprocess dependency expression and update DriverEntry to reflect the
state of Before, After, and SOR dependencies. If DriverEntry->Before
@@ -162,7 +155,7 @@ PopBool ( **/
EFI_STATUS
CorePreProcessDepex (
- IN EFI_CORE_DRIVER_ENTRY *DriverEntry
+ IN EFI_CORE_DRIVER_ENTRY *DriverEntry
)
{
UINT8 *Iterator;
@@ -187,8 +180,6 @@ CorePreProcessDepex ( return EFI_SUCCESS;
}
-
-
/**
This is the POSTFIX version of the dependency evaluator. This code does
not need to handle Before or After, as it is not valid to call this
@@ -204,7 +195,7 @@ CorePreProcessDepex ( **/
BOOLEAN
CoreIsSchedulable (
- IN EFI_CORE_DRIVER_ENTRY *DriverEntry
+ IN EFI_CORE_DRIVER_ENTRY *DriverEntry
)
{
EFI_STATUS Status;
@@ -214,7 +205,7 @@ CoreIsSchedulable ( EFI_GUID DriverGuid;
VOID *Interface;
- Operator = FALSE;
+ Operator = FALSE;
Operator2 = FALSE;
if (DriverEntry->After || DriverEntry->Before) {
@@ -237,6 +228,7 @@ CoreIsSchedulable ( DEBUG ((DEBUG_DISPATCH, "FALSE\n RESULT = FALSE\n"));
return FALSE;
}
+
DEBUG ((DEBUG_DISPATCH, "TRUE\n RESULT = TRUE\n"));
return TRUE;
}
@@ -247,7 +239,6 @@ CoreIsSchedulable ( //
mDepexEvaluationStackPointer = mDepexEvaluationStack;
-
Iterator = DriverEntry->Depex;
while (TRUE) {
@@ -264,158 +255,166 @@ CoreIsSchedulable ( // Look at the opcode of the dependency expression instruction.
//
switch (*Iterator) {
- case EFI_DEP_BEFORE:
- case EFI_DEP_AFTER:
- //
- // For a well-formed Dependency Expression, the code should never get here.
- // The BEFORE and AFTER are processed prior to this routine's invocation.
- // If the code flow arrives at this point, there was a BEFORE or AFTER
- // that were not the first opcodes.
- //
- DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected BEFORE or AFTER opcode)\n"));
- ASSERT (FALSE);
- case EFI_DEP_SOR:
- //
- // These opcodes can only appear once as the first opcode. If it is found
- // at any other location, then the dependency expression evaluates to FALSE
- //
- if (Iterator != DriverEntry->Depex) {
- DEBUG ((DEBUG_DISPATCH, " SOR\n"));
- DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected SOR opcode)\n"));
- return FALSE;
- }
- DEBUG ((DEBUG_DISPATCH, " SOR = Requested\n"));
- //
- // Otherwise, it is the first opcode and should be treated as a NOP.
- //
- break;
-
- case EFI_DEP_PUSH:
- //
- // Push operator is followed by a GUID. Test to see if the GUID protocol
- // is installed and push the boolean result on the stack.
- //
- CopyMem (&DriverGuid, Iterator + 1, sizeof (EFI_GUID));
-
- Status = CoreLocateProtocol (&DriverGuid, NULL, &Interface);
-
- if (EFI_ERROR (Status)) {
- DEBUG ((DEBUG_DISPATCH, " PUSH GUID(%g) = FALSE\n", &DriverGuid));
+ case EFI_DEP_BEFORE:
+ case EFI_DEP_AFTER:
+ //
+ // For a well-formed Dependency Expression, the code should never get here.
+ // The BEFORE and AFTER are processed prior to this routine's invocation.
+ // If the code flow arrives at this point, there was a BEFORE or AFTER
+ // that were not the first opcodes.
+ //
+ DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected BEFORE or AFTER opcode)\n"));
+ ASSERT (FALSE);
+ case EFI_DEP_SOR:
+ //
+ // These opcodes can only appear once as the first opcode. If it is found
+ // at any other location, then the dependency expression evaluates to FALSE
+ //
+ if (Iterator != DriverEntry->Depex) {
+ DEBUG ((DEBUG_DISPATCH, " SOR\n"));
+ DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected SOR opcode)\n"));
+ return FALSE;
+ }
+
+ DEBUG ((DEBUG_DISPATCH, " SOR = Requested\n"));
+ //
+ // Otherwise, it is the first opcode and should be treated as a NOP.
+ //
+ break;
+
+ case EFI_DEP_PUSH:
+ //
+ // Push operator is followed by a GUID. Test to see if the GUID protocol
+ // is installed and push the boolean result on the stack.
+ //
+ CopyMem (&DriverGuid, Iterator + 1, sizeof (EFI_GUID));
+
+ Status = CoreLocateProtocol (&DriverGuid, NULL, &Interface);
+
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_DISPATCH, " PUSH GUID(%g) = FALSE\n", &DriverGuid));
+ Status = PushBool (FALSE);
+ } else {
+ DEBUG ((DEBUG_DISPATCH, " PUSH GUID(%g) = TRUE\n", &DriverGuid));
+ *Iterator = EFI_DEP_REPLACE_TRUE;
+ Status = PushBool (TRUE);
+ }
+
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n"));
+ return FALSE;
+ }
+
+ Iterator += sizeof (EFI_GUID);
+ break;
+
+ case EFI_DEP_AND:
+ DEBUG ((DEBUG_DISPATCH, " AND\n"));
+ Status = PopBool (&Operator);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n"));
+ return FALSE;
+ }
+
+ Status = PopBool (&Operator2);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n"));
+ return FALSE;
+ }
+
+ Status = PushBool ((BOOLEAN)(Operator && Operator2));
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n"));
+ return FALSE;
+ }
+
+ break;
+
+ case EFI_DEP_OR:
+ DEBUG ((DEBUG_DISPATCH, " OR\n"));
+ Status = PopBool (&Operator);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n"));
+ return FALSE;
+ }
+
+ Status = PopBool (&Operator2);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n"));
+ return FALSE;
+ }
+
+ Status = PushBool ((BOOLEAN)(Operator || Operator2));
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n"));
+ return FALSE;
+ }
+
+ break;
+
+ case EFI_DEP_NOT:
+ DEBUG ((DEBUG_DISPATCH, " NOT\n"));
+ Status = PopBool (&Operator);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n"));
+ return FALSE;
+ }
+
+ Status = PushBool ((BOOLEAN)(!Operator));
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n"));
+ return FALSE;
+ }
+
+ break;
+
+ case EFI_DEP_TRUE:
+ DEBUG ((DEBUG_DISPATCH, " TRUE\n"));
+ Status = PushBool (TRUE);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n"));
+ return FALSE;
+ }
+
+ break;
+
+ case EFI_DEP_FALSE:
+ DEBUG ((DEBUG_DISPATCH, " FALSE\n"));
Status = PushBool (FALSE);
- } else {
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n"));
+ return FALSE;
+ }
+
+ break;
+
+ case EFI_DEP_END:
+ DEBUG ((DEBUG_DISPATCH, " END\n"));
+ Status = PopBool (&Operator);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n"));
+ return FALSE;
+ }
+
+ DEBUG ((DEBUG_DISPATCH, " RESULT = %a\n", Operator ? "TRUE" : "FALSE"));
+ return Operator;
+
+ case EFI_DEP_REPLACE_TRUE:
+ CopyMem (&DriverGuid, Iterator + 1, sizeof (EFI_GUID));
DEBUG ((DEBUG_DISPATCH, " PUSH GUID(%g) = TRUE\n", &DriverGuid));
- *Iterator = EFI_DEP_REPLACE_TRUE;
+
Status = PushBool (TRUE);
- }
- if (EFI_ERROR (Status)) {
- DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n"));
- return FALSE;
- }
-
- Iterator += sizeof (EFI_GUID);
- break;
-
- case EFI_DEP_AND:
- DEBUG ((DEBUG_DISPATCH, " AND\n"));
- Status = PopBool (&Operator);
- if (EFI_ERROR (Status)) {
- DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n"));
- return FALSE;
- }
-
- Status = PopBool (&Operator2);
- if (EFI_ERROR (Status)) {
- DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n"));
- return FALSE;
- }
-
- Status = PushBool ((BOOLEAN)(Operator && Operator2));
- if (EFI_ERROR (Status)) {
- DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n"));
- return FALSE;
- }
- break;
-
- case EFI_DEP_OR:
- DEBUG ((DEBUG_DISPATCH, " OR\n"));
- Status = PopBool (&Operator);
- if (EFI_ERROR (Status)) {
- DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n"));
- return FALSE;
- }
-
- Status = PopBool (&Operator2);
- if (EFI_ERROR (Status)) {
- DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n"));
- return FALSE;
- }
-
- Status = PushBool ((BOOLEAN)(Operator || Operator2));
- if (EFI_ERROR (Status)) {
- DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n"));
- return FALSE;
- }
- break;
-
- case EFI_DEP_NOT:
- DEBUG ((DEBUG_DISPATCH, " NOT\n"));
- Status = PopBool (&Operator);
- if (EFI_ERROR (Status)) {
- DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n"));
- return FALSE;
- }
-
- Status = PushBool ((BOOLEAN)(!Operator));
- if (EFI_ERROR (Status)) {
- DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n"));
- return FALSE;
- }
- break;
-
- case EFI_DEP_TRUE:
- DEBUG ((DEBUG_DISPATCH, " TRUE\n"));
- Status = PushBool (TRUE);
- if (EFI_ERROR (Status)) {
- DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n"));
- return FALSE;
- }
- break;
-
- case EFI_DEP_FALSE:
- DEBUG ((DEBUG_DISPATCH, " FALSE\n"));
- Status = PushBool (FALSE);
- if (EFI_ERROR (Status)) {
- DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n"));
- return FALSE;
- }
- break;
-
- case EFI_DEP_END:
- DEBUG ((DEBUG_DISPATCH, " END\n"));
- Status = PopBool (&Operator);
- if (EFI_ERROR (Status)) {
- DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n"));
- return FALSE;
- }
- DEBUG ((DEBUG_DISPATCH, " RESULT = %a\n", Operator ? "TRUE" : "FALSE"));
- return Operator;
-
- case EFI_DEP_REPLACE_TRUE:
- CopyMem (&DriverGuid, Iterator + 1, sizeof (EFI_GUID));
- DEBUG ((DEBUG_DISPATCH, " PUSH GUID(%g) = TRUE\n", &DriverGuid));
-
- Status = PushBool (TRUE);
- if (EFI_ERROR (Status)) {
- DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n"));
- return FALSE;
- }
-
- Iterator += sizeof (EFI_GUID);
- break;
-
- default:
- DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unknown opcode)\n"));
- goto Done;
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n"));
+ return FALSE;
+ }
+
+ Iterator += sizeof (EFI_GUID);
+ break;
+
+ default:
+ DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unknown opcode)\n"));
+ goto Done;
}
//
@@ -432,5 +431,3 @@ CoreIsSchedulable ( Done:
return FALSE;
}
-
-
diff --git a/MdeModulePkg/Core/Dxe/Dispatcher/Dispatcher.c b/MdeModulePkg/Core/Dxe/Dispatcher/Dispatcher.c index 3605605e91..fb9ae3ce78 100644 --- a/MdeModulePkg/Core/Dxe/Dispatcher/Dispatcher.c +++ b/MdeModulePkg/Core/Dxe/Dispatcher/Dispatcher.c @@ -55,7 +55,6 @@ LIST_ENTRY mFvHandleList = INITIALIZE_LIST_HEAD_VARIABLE (mFvHandleList); //
EFI_LOCK mDispatcherLock = EFI_INITIALIZE_LOCK_VARIABLE (TPL_HIGH_LEVEL);
-
//
// Flag for the DXE Dispacher. TRUE if dispatcher is execuing.
//
@@ -64,13 +63,13 @@ BOOLEAN gDispatcherRunning = FALSE; //
// Module globals to manage the FwVol registration notification event
//
-EFI_EVENT mFwVolEvent;
-VOID *mFwVolEventRegistration;
+EFI_EVENT mFwVolEvent;
+VOID *mFwVolEventRegistration;
//
// List of file types supported by dispatcher
//
-EFI_FV_FILETYPE mDxeFileTypes[] = {
+EFI_FV_FILETYPE mDxeFileTypes[] = {
EFI_FV_FILETYPE_DRIVER,
EFI_FV_FILETYPE_COMBINED_SMM_DXE,
EFI_FV_FILETYPE_COMBINED_PEIM_DRIVER,
@@ -79,15 +78,16 @@ EFI_FV_FILETYPE mDxeFileTypes[] = { };
typedef struct {
- MEDIA_FW_VOL_FILEPATH_DEVICE_PATH File;
- EFI_DEVICE_PATH_PROTOCOL End;
+ MEDIA_FW_VOL_FILEPATH_DEVICE_PATH File;
+ EFI_DEVICE_PATH_PROTOCOL End;
} FV_FILEPATH_DEVICE_PATH;
-FV_FILEPATH_DEVICE_PATH mFvDevicePath;
+FV_FILEPATH_DEVICE_PATH mFvDevicePath;
//
// Function Prototypes
//
+
/**
Insert InsertedDriverEntry onto the mScheduledQueue. To do this you
must add any driver with a before dependency on InsertedDriverEntry first.
@@ -101,7 +101,7 @@ FV_FILEPATH_DEVICE_PATH mFvDevicePath; **/
VOID
CoreInsertOnScheduledQueueWhileProcessingBeforeAndAfter (
- IN EFI_CORE_DRIVER_ENTRY *InsertedDriverEntry
+ IN EFI_CORE_DRIVER_ENTRY *InsertedDriverEntry
);
/**
@@ -124,8 +124,8 @@ CoreInsertOnScheduledQueueWhileProcessingBeforeAndAfter ( VOID
EFIAPI
CoreFwVolEventProtocolNotify (
- IN EFI_EVENT Event,
- IN VOID *Context
+ IN EFI_EVENT Event,
+ IN VOID *Context
);
/**
@@ -143,9 +143,9 @@ CoreFwVolEventProtocolNotify ( **/
EFI_DEVICE_PATH_PROTOCOL *
CoreFvToDevicePath (
- IN EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv,
- IN EFI_HANDLE FvHandle,
- IN EFI_GUID *DriverName
+ IN EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv,
+ IN EFI_HANDLE FvHandle,
+ IN EFI_GUID *DriverName
);
/**
@@ -171,10 +171,10 @@ CoreFvToDevicePath ( **/
EFI_STATUS
CoreAddToDriverList (
- IN EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv,
- IN EFI_HANDLE FvHandle,
- IN EFI_GUID *DriverName,
- IN EFI_FV_FILETYPE Type
+ IN EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv,
+ IN EFI_HANDLE FvHandle,
+ IN EFI_GUID *DriverName,
+ IN EFI_FV_FILETYPE Type
);
/**
@@ -190,12 +190,11 @@ CoreAddToDriverList ( **/
EFI_STATUS
CoreProcessFvImageFile (
- IN EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv,
- IN EFI_HANDLE FvHandle,
- IN EFI_GUID *FileName
+ IN EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv,
+ IN EFI_HANDLE FvHandle,
+ IN EFI_GUID *FileName
);
-
/**
Enter critical section by gaining lock on mDispatcherLock.
@@ -208,7 +207,6 @@ CoreAcquireDispatcherLock ( CoreAcquireLock (&mDispatcherLock);
}
-
/**
Exit critical section by releasing lock on mDispatcherLock.
@@ -221,7 +219,6 @@ CoreReleaseDispatcherLock ( CoreReleaseLock (&mDispatcherLock);
}
-
/**
Read Depex and pre-process the Depex for Before and After. If Section Extraction
protocol returns an error via ReadSection defer the reading of the Depex.
@@ -236,30 +233,29 @@ CoreReleaseDispatcherLock ( **/
EFI_STATUS
CoreGetDepexSectionAndPreProccess (
- IN EFI_CORE_DRIVER_ENTRY *DriverEntry
+ IN EFI_CORE_DRIVER_ENTRY *DriverEntry
)
{
- EFI_STATUS Status;
- EFI_SECTION_TYPE SectionType;
- UINT32 AuthenticationStatus;
- EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv;
-
+ EFI_STATUS Status;
+ EFI_SECTION_TYPE SectionType;
+ UINT32 AuthenticationStatus;
+ EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv;
Fv = DriverEntry->Fv;
//
// Grab Depex info, it will never be free'ed.
//
- SectionType = EFI_SECTION_DXE_DEPEX;
- Status = Fv->ReadSection (
- DriverEntry->Fv,
- &DriverEntry->FileName,
- SectionType,
- 0,
- &DriverEntry->Depex,
- (UINTN *)&DriverEntry->DepexSize,
- &AuthenticationStatus
- );
+ SectionType = EFI_SECTION_DXE_DEPEX;
+ Status = Fv->ReadSection (
+ DriverEntry->Fv,
+ &DriverEntry->FileName,
+ SectionType,
+ 0,
+ &DriverEntry->Depex,
+ (UINTN *)&DriverEntry->DepexSize,
+ &AuthenticationStatus
+ );
if (EFI_ERROR (Status)) {
if (Status == EFI_PROTOCOL_ERROR) {
//
@@ -270,8 +266,8 @@ CoreGetDepexSectionAndPreProccess ( //
// If no Depex assume UEFI 2.0 driver model
//
- DriverEntry->Depex = NULL;
- DriverEntry->Dependent = TRUE;
+ DriverEntry->Depex = NULL;
+ DriverEntry->Dependent = TRUE;
DriverEntry->DepexProtocolError = FALSE;
}
} else {
@@ -286,7 +282,6 @@ CoreGetDepexSectionAndPreProccess ( return Status;
}
-
/**
Check every driver and locate a matching one. If the driver is found, the Unrequested
state flag is cleared.
@@ -308,23 +303,24 @@ CoreSchedule ( IN EFI_GUID *DriverName
)
{
- LIST_ENTRY *Link;
- EFI_CORE_DRIVER_ENTRY *DriverEntry;
+ LIST_ENTRY *Link;
+ EFI_CORE_DRIVER_ENTRY *DriverEntry;
//
// Check every driver
//
for (Link = mDiscoveredList.ForwardLink; Link != &mDiscoveredList; Link = Link->ForwardLink) {
- DriverEntry = CR(Link, EFI_CORE_DRIVER_ENTRY, Link, EFI_CORE_DRIVER_ENTRY_SIGNATURE);
- if (DriverEntry->FvHandle == FirmwareVolumeHandle &&
+ DriverEntry = CR (Link, EFI_CORE_DRIVER_ENTRY, Link, EFI_CORE_DRIVER_ENTRY_SIGNATURE);
+ if ((DriverEntry->FvHandle == FirmwareVolumeHandle) &&
DriverEntry->Unrequested &&
- CompareGuid (DriverName, &DriverEntry->FileName)) {
+ CompareGuid (DriverName, &DriverEntry->FileName))
+ {
//
// Move the driver from the Unrequested to the Dependent state
//
CoreAcquireDispatcherLock ();
- DriverEntry->Unrequested = FALSE;
- DriverEntry->Dependent = TRUE;
+ DriverEntry->Unrequested = FALSE;
+ DriverEntry->Dependent = TRUE;
CoreReleaseDispatcherLock ();
DEBUG ((DEBUG_DISPATCH, "Schedule FFS(%g) - EFI_SUCCESS\n", DriverName));
@@ -338,8 +334,6 @@ CoreSchedule ( return EFI_NOT_FOUND;
}
-
-
/**
Convert a driver from the Untrused back to the Scheduled state.
@@ -359,17 +353,18 @@ CoreTrust ( IN EFI_GUID *DriverName
)
{
- LIST_ENTRY *Link;
- EFI_CORE_DRIVER_ENTRY *DriverEntry;
+ LIST_ENTRY *Link;
+ EFI_CORE_DRIVER_ENTRY *DriverEntry;
//
// Check every driver
//
for (Link = mDiscoveredList.ForwardLink; Link != &mDiscoveredList; Link = Link->ForwardLink) {
- DriverEntry = CR(Link, EFI_CORE_DRIVER_ENTRY, Link, EFI_CORE_DRIVER_ENTRY_SIGNATURE);
- if (DriverEntry->FvHandle == FirmwareVolumeHandle &&
+ DriverEntry = CR (Link, EFI_CORE_DRIVER_ENTRY, Link, EFI_CORE_DRIVER_ENTRY_SIGNATURE);
+ if ((DriverEntry->FvHandle == FirmwareVolumeHandle) &&
DriverEntry->Untrusted &&
- CompareGuid (DriverName, &DriverEntry->FileName)) {
+ CompareGuid (DriverName, &DriverEntry->FileName))
+ {
//
// Transition driver from Untrusted to Scheduled state.
//
@@ -382,6 +377,7 @@ CoreTrust ( return EFI_SUCCESS;
}
}
+
return EFI_NOT_FOUND;
}
@@ -405,12 +401,12 @@ CoreDispatcher ( VOID
)
{
- EFI_STATUS Status;
- EFI_STATUS ReturnStatus;
- LIST_ENTRY *Link;
- EFI_CORE_DRIVER_ENTRY *DriverEntry;
- BOOLEAN ReadyToRun;
- EFI_EVENT DxeDispatchEvent;
+ EFI_STATUS Status;
+ EFI_STATUS ReturnStatus;
+ LIST_ENTRY *Link;
+ EFI_CORE_DRIVER_ENTRY *DriverEntry;
+ BOOLEAN ReadyToRun;
+ EFI_EVENT DxeDispatchEvent;
PERF_FUNCTION_BEGIN ();
@@ -453,16 +449,16 @@ CoreDispatcher ( // Untrused to Scheduled it would have already been loaded so we may need to
// skip the LoadImage
//
- if (DriverEntry->ImageHandle == NULL && !DriverEntry->IsFvImage) {
+ if ((DriverEntry->ImageHandle == NULL) && !DriverEntry->IsFvImage) {
DEBUG ((DEBUG_INFO, "Loading driver %g\n", &DriverEntry->FileName));
Status = CoreLoadImage (
- FALSE,
- gDxeCoreImageHandle,
- DriverEntry->FvFileDevicePath,
- NULL,
- 0,
- &DriverEntry->ImageHandle
- );
+ FALSE,
+ gDxeCoreImageHandle,
+ DriverEntry->FvFileDevicePath,
+ NULL,
+ 0,
+ &DriverEntry->ImageHandle
+ );
//
// Update the driver state to reflect that it's been loaded
@@ -482,7 +478,7 @@ CoreDispatcher ( //
// This case include the Never Trusted state if EFI_ACCESS_DENIED is returned
//
- DriverEntry->Initialized = TRUE;
+ DriverEntry->Initialized = TRUE;
}
DriverEntry->Scheduled = FALSE;
@@ -499,13 +495,12 @@ CoreDispatcher ( CoreAcquireDispatcherLock ();
- DriverEntry->Scheduled = FALSE;
- DriverEntry->Initialized = TRUE;
+ DriverEntry->Scheduled = FALSE;
+ DriverEntry->Initialized = TRUE;
RemoveEntryList (&DriverEntry->ScheduledLink);
CoreReleaseDispatcherLock ();
-
if (DriverEntry->IsFvImage) {
//
// Produce a firmware volume block protocol for FvImage so it gets dispatched from.
@@ -549,7 +544,7 @@ CoreDispatcher ( for (Link = mDiscoveredList.ForwardLink; Link != &mDiscoveredList; Link = Link->ForwardLink) {
DriverEntry = CR (Link, EFI_CORE_DRIVER_ENTRY, Link, EFI_CORE_DRIVER_ENTRY_SIGNATURE);
- if (DriverEntry->DepexProtocolError){
+ if (DriverEntry->DepexProtocolError) {
//
// If Section Extraction Protocol did not let the Depex be read before retry the read
//
@@ -583,7 +578,6 @@ CoreDispatcher ( return ReturnStatus;
}
-
/**
Insert InsertedDriverEntry onto the mScheduledQueue. To do this you
must add any driver with a before dependency on InsertedDriverEntry first.
@@ -597,18 +591,18 @@ CoreDispatcher ( **/
VOID
CoreInsertOnScheduledQueueWhileProcessingBeforeAndAfter (
- IN EFI_CORE_DRIVER_ENTRY *InsertedDriverEntry
+ IN EFI_CORE_DRIVER_ENTRY *InsertedDriverEntry
)
{
- LIST_ENTRY *Link;
- EFI_CORE_DRIVER_ENTRY *DriverEntry;
+ LIST_ENTRY *Link;
+ EFI_CORE_DRIVER_ENTRY *DriverEntry;
//
// Process Before Dependency
//
for (Link = mDiscoveredList.ForwardLink; Link != &mDiscoveredList; Link = Link->ForwardLink) {
- DriverEntry = CR(Link, EFI_CORE_DRIVER_ENTRY, Link, EFI_CORE_DRIVER_ENTRY_SIGNATURE);
- if (DriverEntry->Before && DriverEntry->Dependent && DriverEntry != InsertedDriverEntry) {
+ DriverEntry = CR (Link, EFI_CORE_DRIVER_ENTRY, Link, EFI_CORE_DRIVER_ENTRY_SIGNATURE);
+ if (DriverEntry->Before && DriverEntry->Dependent && (DriverEntry != InsertedDriverEntry)) {
DEBUG ((DEBUG_DISPATCH, "Evaluate DXE DEPEX for FFS(%g)\n", &DriverEntry->FileName));
DEBUG ((DEBUG_DISPATCH, " BEFORE FFS(%g) = ", &DriverEntry->BeforeAfterGuid));
if (CompareGuid (&InsertedDriverEntry->FileName, &DriverEntry->BeforeAfterGuid)) {
@@ -638,8 +632,8 @@ CoreInsertOnScheduledQueueWhileProcessingBeforeAndAfter ( // Process After Dependency
//
for (Link = mDiscoveredList.ForwardLink; Link != &mDiscoveredList; Link = Link->ForwardLink) {
- DriverEntry = CR(Link, EFI_CORE_DRIVER_ENTRY, Link, EFI_CORE_DRIVER_ENTRY_SIGNATURE);
- if (DriverEntry->After && DriverEntry->Dependent && DriverEntry != InsertedDriverEntry) {
+ DriverEntry = CR (Link, EFI_CORE_DRIVER_ENTRY, Link, EFI_CORE_DRIVER_ENTRY_SIGNATURE);
+ if (DriverEntry->After && DriverEntry->Dependent && (DriverEntry != InsertedDriverEntry)) {
DEBUG ((DEBUG_DISPATCH, "Evaluate DXE DEPEX for FFS(%g)\n", &DriverEntry->FileName));
DEBUG ((DEBUG_DISPATCH, " AFTER FFS(%g) = ", &DriverEntry->BeforeAfterGuid));
if (CompareGuid (&InsertedDriverEntry->FileName, &DriverEntry->BeforeAfterGuid)) {
@@ -655,7 +649,6 @@ CoreInsertOnScheduledQueueWhileProcessingBeforeAndAfter ( }
}
-
/**
Return TRUE if the Fv has been processed, FALSE if not.
@@ -667,22 +660,22 @@ CoreInsertOnScheduledQueueWhileProcessingBeforeAndAfter ( **/
BOOLEAN
FvHasBeenProcessed (
- IN EFI_HANDLE FvHandle
+ IN EFI_HANDLE FvHandle
)
{
- LIST_ENTRY *Link;
- KNOWN_HANDLE *KnownHandle;
+ LIST_ENTRY *Link;
+ KNOWN_HANDLE *KnownHandle;
for (Link = mFvHandleList.ForwardLink; Link != &mFvHandleList; Link = Link->ForwardLink) {
- KnownHandle = CR(Link, KNOWN_HANDLE, Link, KNOWN_HANDLE_SIGNATURE);
+ KnownHandle = CR (Link, KNOWN_HANDLE, Link, KNOWN_HANDLE_SIGNATURE);
if (KnownHandle->Handle == FvHandle) {
return TRUE;
}
}
+
return FALSE;
}
-
/**
Remember that Fv protocol on FvHandle has had it's drivers placed on the
mDiscoveredList. This fucntion adds entries on the mFvHandleList if new
@@ -697,21 +690,21 @@ FvHasBeenProcessed ( **/
KNOWN_HANDLE *
FvIsBeingProcessed (
- IN EFI_HANDLE FvHandle
+ IN EFI_HANDLE FvHandle
)
{
- EFI_STATUS Status;
- EFI_GUID FvNameGuid;
- BOOLEAN FvNameGuidIsFound;
- UINT32 ExtHeaderOffset;
- EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *Fvb;
- EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader;
- EFI_FV_BLOCK_MAP_ENTRY *BlockMap;
- UINTN LbaOffset;
- UINTN Index;
- EFI_LBA LbaIndex;
- LIST_ENTRY *Link;
- KNOWN_HANDLE *KnownHandle;
+ EFI_STATUS Status;
+ EFI_GUID FvNameGuid;
+ BOOLEAN FvNameGuidIsFound;
+ UINT32 ExtHeaderOffset;
+ EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *Fvb;
+ EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader;
+ EFI_FV_BLOCK_MAP_ENTRY *BlockMap;
+ UINTN LbaOffset;
+ UINTN Index;
+ EFI_LBA LbaIndex;
+ LIST_ENTRY *Link;
+ KNOWN_HANDLE *KnownHandle;
FwVolHeader = NULL;
@@ -719,7 +712,7 @@ FvIsBeingProcessed ( // Get the FirmwareVolumeBlock protocol on that handle
//
FvNameGuidIsFound = FALSE;
- Status = CoreHandleProtocol (FvHandle, &gEfiFirmwareVolumeBlockProtocolGuid, (VOID **)&Fvb);
+ Status = CoreHandleProtocol (FvHandle, &gEfiFirmwareVolumeBlockProtocolGuid, (VOID **)&Fvb);
if (!EFI_ERROR (Status)) {
//
// Get the full FV header based on FVB protocol.
@@ -728,19 +721,20 @@ FvIsBeingProcessed ( Status = GetFwVolHeader (Fvb, &FwVolHeader);
if (!EFI_ERROR (Status)) {
ASSERT (FwVolHeader != NULL);
- if (VerifyFvHeaderChecksum (FwVolHeader) && FwVolHeader->ExtHeaderOffset != 0) {
- ExtHeaderOffset = (UINT32) FwVolHeader->ExtHeaderOffset;
- BlockMap = FwVolHeader->BlockMap;
- LbaIndex = 0;
- LbaOffset = 0;
+ if (VerifyFvHeaderChecksum (FwVolHeader) && (FwVolHeader->ExtHeaderOffset != 0)) {
+ ExtHeaderOffset = (UINT32)FwVolHeader->ExtHeaderOffset;
+ BlockMap = FwVolHeader->BlockMap;
+ LbaIndex = 0;
+ LbaOffset = 0;
//
// Find LbaIndex and LbaOffset for FV extension header based on BlockMap.
//
while ((BlockMap->NumBlocks != 0) || (BlockMap->Length != 0)) {
- for (Index = 0; Index < BlockMap->NumBlocks && ExtHeaderOffset >= BlockMap->Length; Index ++) {
+ for (Index = 0; Index < BlockMap->NumBlocks && ExtHeaderOffset >= BlockMap->Length; Index++) {
ExtHeaderOffset -= BlockMap->Length;
- LbaIndex ++;
+ LbaIndex++;
}
+
//
// Check whether FvExtHeader is crossing the multi block range.
//
@@ -748,16 +742,19 @@ FvIsBeingProcessed ( LbaOffset = ExtHeaderOffset;
break;
}
+
BlockMap++;
}
+
//
// Read FvNameGuid from FV extension header.
//
- Status = ReadFvbData (Fvb, &LbaIndex, &LbaOffset, sizeof (FvNameGuid), (UINT8 *) &FvNameGuid);
+ Status = ReadFvbData (Fvb, &LbaIndex, &LbaOffset, sizeof (FvNameGuid), (UINT8 *)&FvNameGuid);
if (!EFI_ERROR (Status)) {
FvNameGuidIsFound = TRUE;
}
}
+
CoreFreePool (FwVolHeader);
}
}
@@ -767,7 +764,7 @@ FvIsBeingProcessed ( // Check whether the FV image with the found FvNameGuid has been processed.
//
for (Link = mFvHandleList.ForwardLink; Link != &mFvHandleList; Link = Link->ForwardLink) {
- KnownHandle = CR(Link, KNOWN_HANDLE, Link, KNOWN_HANDLE_SIGNATURE);
+ KnownHandle = CR (Link, KNOWN_HANDLE, Link, KNOWN_HANDLE_SIGNATURE);
if (CompareGuid (&FvNameGuid, &KnownHandle->FvNameGuid)) {
DEBUG ((DEBUG_ERROR, "FvImage on FvHandle %p and %p has the same FvNameGuid %g.\n", FvHandle, KnownHandle->Handle, &FvNameGuid));
return NULL;
@@ -779,17 +776,15 @@ FvIsBeingProcessed ( ASSERT (KnownHandle != NULL);
KnownHandle->Signature = KNOWN_HANDLE_SIGNATURE;
- KnownHandle->Handle = FvHandle;
+ KnownHandle->Handle = FvHandle;
if (FvNameGuidIsFound) {
CopyGuid (&KnownHandle->FvNameGuid, &FvNameGuid);
}
+
InsertTailList (&mFvHandleList, &KnownHandle->Link);
return KnownHandle;
}
-
-
-
/**
Convert FvHandle and DriverName into an EFI device path
@@ -805,14 +800,14 @@ FvIsBeingProcessed ( **/
EFI_DEVICE_PATH_PROTOCOL *
CoreFvToDevicePath (
- IN EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv,
- IN EFI_HANDLE FvHandle,
- IN EFI_GUID *DriverName
+ IN EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv,
+ IN EFI_HANDLE FvHandle,
+ IN EFI_GUID *DriverName
)
{
- EFI_STATUS Status;
- EFI_DEVICE_PATH_PROTOCOL *FvDevicePath;
- EFI_DEVICE_PATH_PROTOCOL *FileNameDevicePath;
+ EFI_STATUS Status;
+ EFI_DEVICE_PATH_PROTOCOL *FvDevicePath;
+ EFI_DEVICE_PATH_PROTOCOL *FileNameDevicePath;
//
// Remember the device path of the FV
@@ -828,16 +823,14 @@ CoreFvToDevicePath ( SetDevicePathEndNode (&mFvDevicePath.End);
FileNameDevicePath = AppendDevicePath (
- FvDevicePath,
- (EFI_DEVICE_PATH_PROTOCOL *)&mFvDevicePath
- );
+ FvDevicePath,
+ (EFI_DEVICE_PATH_PROTOCOL *)&mFvDevicePath
+ );
}
return FileNameDevicePath;
}
-
-
/**
Add an entry to the mDiscoveredList. Allocate memory to store the DriverEntry,
and initilize any state variables. Read the Depex from the FV and store it
@@ -861,14 +854,13 @@ CoreFvToDevicePath ( **/
EFI_STATUS
CoreAddToDriverList (
- IN EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv,
- IN EFI_HANDLE FvHandle,
- IN EFI_GUID *DriverName,
- IN EFI_FV_FILETYPE Type
+ IN EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv,
+ IN EFI_HANDLE FvHandle,
+ IN EFI_GUID *DriverName,
+ IN EFI_FV_FILETYPE Type
)
{
- EFI_CORE_DRIVER_ENTRY *DriverEntry;
-
+ EFI_CORE_DRIVER_ENTRY *DriverEntry;
//
// Create the Driver Entry for the list. ZeroPool initializes lots of variables to
@@ -880,7 +872,7 @@ CoreAddToDriverList ( DriverEntry->IsFvImage = TRUE;
}
- DriverEntry->Signature = EFI_CORE_DRIVER_ENTRY_SIGNATURE;
+ DriverEntry->Signature = EFI_CORE_DRIVER_ENTRY_SIGNATURE;
CopyGuid (&DriverEntry->FileName, DriverName);
DriverEntry->FvHandle = FvHandle;
DriverEntry->Fv = Fv;
@@ -897,7 +889,6 @@ CoreAddToDriverList ( return EFI_SUCCESS;
}
-
/**
Check if a FV Image type file (EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE) is
described by a EFI_HOB_FIRMWARE_VOLUME2 Hob.
@@ -912,11 +903,11 @@ CoreAddToDriverList ( **/
BOOLEAN
FvFoundInHobFv2 (
- IN CONST EFI_GUID *FvNameGuid,
- IN CONST EFI_GUID *DriverName
+ IN CONST EFI_GUID *FvNameGuid,
+ IN CONST EFI_GUID *DriverName
)
{
- EFI_PEI_HOB_POINTERS HobFv2;
+ EFI_PEI_HOB_POINTERS HobFv2;
HobFv2.Raw = GetHobList ();
@@ -925,9 +916,11 @@ FvFoundInHobFv2 ( // Compare parent FvNameGuid and FileGuid both.
//
if (CompareGuid (DriverName, &HobFv2.FirmwareVolume2->FileName) &&
- CompareGuid (FvNameGuid, &HobFv2.FirmwareVolume2->FvName)) {
+ CompareGuid (FvNameGuid, &HobFv2.FirmwareVolume2->FvName))
+ {
return TRUE;
}
+
HobFv2.Raw = GET_NEXT_HOB (HobFv2);
}
@@ -950,9 +943,9 @@ FvFoundInHobFv2 ( **/
BOOLEAN
GetFvUsedSize (
- IN EFI_FIRMWARE_VOLUME_HEADER *FvHeader,
- OUT UINT32 *FvUsedSize,
- OUT UINT8 *EraseByte
+ IN EFI_FIRMWARE_VOLUME_HEADER *FvHeader,
+ OUT UINT32 *FvUsedSize,
+ OUT UINT8 *EraseByte
)
{
UINT16 ExtHeaderOffset;
@@ -962,20 +955,21 @@ GetFvUsedSize ( ExtHeaderOffset = ReadUnaligned16 (&FvHeader->ExtHeaderOffset);
if (ExtHeaderOffset != 0) {
- ExtHeader = (EFI_FIRMWARE_VOLUME_EXT_HEADER *) ((UINT8 *) FvHeader + ExtHeaderOffset);
- ExtEntryList = (EFI_FIRMWARE_VOLUME_EXT_ENTRY *) (ExtHeader + 1);
- while ((UINTN) ExtEntryList < ((UINTN) ExtHeader + ReadUnaligned32 (&ExtHeader->ExtHeaderSize))) {
+ ExtHeader = (EFI_FIRMWARE_VOLUME_EXT_HEADER *)((UINT8 *)FvHeader + ExtHeaderOffset);
+ ExtEntryList = (EFI_FIRMWARE_VOLUME_EXT_ENTRY *)(ExtHeader + 1);
+ while ((UINTN)ExtEntryList < ((UINTN)ExtHeader + ReadUnaligned32 (&ExtHeader->ExtHeaderSize))) {
if (ReadUnaligned16 (&ExtEntryList->ExtEntryType) == EFI_FV_EXT_TYPE_USED_SIZE_TYPE) {
//
// USED_SIZE FV_EXT_TYPE entry is found.
//
- ExtEntryUsedSize = (EFI_FIRMWARE_VOLUME_EXT_ENTRY_USED_SIZE_TYPE *) ExtEntryList;
- *FvUsedSize = ReadUnaligned32 (&ExtEntryUsedSize->UsedSize);
+ ExtEntryUsedSize = (EFI_FIRMWARE_VOLUME_EXT_ENTRY_USED_SIZE_TYPE *)ExtEntryList;
+ *FvUsedSize = ReadUnaligned32 (&ExtEntryUsedSize->UsedSize);
if ((ReadUnaligned32 (&FvHeader->Attributes) & EFI_FVB2_ERASE_POLARITY) != 0) {
*EraseByte = 0xFF;
} else {
*EraseByte = 0;
}
+
DEBUG ((
DEBUG_INFO,
"FV at 0x%x has 0x%x used size, and erase byte is 0x%02x\n",
@@ -985,8 +979,9 @@ GetFvUsedSize ( ));
return TRUE;
}
+
ExtEntryList = (EFI_FIRMWARE_VOLUME_EXT_ENTRY *)
- ((UINT8 *) ExtEntryList + ReadUnaligned16 (&ExtEntryList->ExtEntrySize));
+ ((UINT8 *)ExtEntryList + ReadUnaligned16 (&ExtEntryList->ExtEntrySize));
}
}
@@ -1009,28 +1004,28 @@ GetFvUsedSize ( **/
EFI_STATUS
CoreProcessFvImageFile (
- IN EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv,
- IN EFI_HANDLE FvHandle,
- IN EFI_GUID *FileName
+ IN EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv,
+ IN EFI_HANDLE FvHandle,
+ IN EFI_GUID *FileName
)
{
- EFI_STATUS Status;
- EFI_SECTION_TYPE SectionType;
- UINT32 AuthenticationStatus;
- VOID *Buffer;
- VOID *AlignedBuffer;
- UINTN BufferSize;
- EFI_FIRMWARE_VOLUME_HEADER *FvHeader;
- UINT32 FvAlignment;
- EFI_DEVICE_PATH_PROTOCOL *FvFileDevicePath;
- UINT32 FvUsedSize;
- UINT8 EraseByte;
- UINTN Index;
+ EFI_STATUS Status;
+ EFI_SECTION_TYPE SectionType;
+ UINT32 AuthenticationStatus;
+ VOID *Buffer;
+ VOID *AlignedBuffer;
+ UINTN BufferSize;
+ EFI_FIRMWARE_VOLUME_HEADER *FvHeader;
+ UINT32 FvAlignment;
+ EFI_DEVICE_PATH_PROTOCOL *FvFileDevicePath;
+ UINT32 FvUsedSize;
+ UINT8 EraseByte;
+ UINTN Index;
//
// Read firmware volume section(s)
//
- SectionType = EFI_SECTION_FIRMWARE_VOLUME_IMAGE;
+ SectionType = EFI_SECTION_FIRMWARE_VOLUME_IMAGE;
Index = 0;
do {
@@ -1039,27 +1034,27 @@ CoreProcessFvImageFile ( Buffer = NULL;
BufferSize = 0;
AlignedBuffer = NULL;
- Status = Fv->ReadSection (
- Fv,
- FileName,
- SectionType,
- Index,
- &Buffer,
- &BufferSize,
- &AuthenticationStatus
- );
+ Status = Fv->ReadSection (
+ Fv,
+ FileName,
+ SectionType,
+ Index,
+ &Buffer,
+ &BufferSize,
+ &AuthenticationStatus
+ );
if (!EFI_ERROR (Status)) {
- //
+ //
// Evaluate the authentication status of the Firmware Volume through
// Security Architectural Protocol
//
if (gSecurity != NULL) {
FvFileDevicePath = CoreFvToDevicePath (Fv, FvHandle, FileName);
- Status = gSecurity->FileAuthenticationState (
- gSecurity,
- AuthenticationStatus,
- FvFileDevicePath
- );
+ Status = gSecurity->FileAuthenticationState (
+ gSecurity,
+ AuthenticationStatus,
+ FvFileDevicePath
+ );
if (FvFileDevicePath != NULL) {
FreePool (FvFileDevicePath);
}
@@ -1071,6 +1066,7 @@ CoreProcessFvImageFile ( if (Buffer != NULL) {
FreePool (Buffer);
}
+
break;
}
}
@@ -1078,7 +1074,7 @@ CoreProcessFvImageFile ( //
// FvImage should be at its required alignment.
//
- FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *) Buffer;
+ FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *)Buffer;
//
// If EFI_FVB2_WEAK_ALIGNMENT is set in the volume header then the first byte of the volume
// can be aligned on any power-of-two boundary. A weakly aligned volume can not be moved from
@@ -1107,11 +1103,11 @@ CoreProcessFvImageFile ( //
// Check FvImage alignment.
//
- if ((UINTN) FvHeader % FvAlignment != 0) {
+ if ((UINTN)FvHeader % FvAlignment != 0) {
//
// Allocate the aligned buffer for the FvImage.
//
- AlignedBuffer = AllocateAlignedPages (EFI_SIZE_TO_PAGES (BufferSize), (UINTN) FvAlignment);
+ AlignedBuffer = AllocateAlignedPages (EFI_SIZE_TO_PAGES (BufferSize), (UINTN)FvAlignment);
if (AlignedBuffer == NULL) {
FreePool (Buffer);
Status = EFI_OUT_OF_RESOURCES;
@@ -1124,31 +1120,33 @@ CoreProcessFvImageFile ( //
// Copy the used bytes and fill the rest with the erase value.
//
- CopyMem (AlignedBuffer, FvHeader, (UINTN) FvUsedSize);
+ CopyMem (AlignedBuffer, FvHeader, (UINTN)FvUsedSize);
SetMem (
- (UINT8 *) AlignedBuffer + FvUsedSize,
- (UINTN) (BufferSize - FvUsedSize),
+ (UINT8 *)AlignedBuffer + FvUsedSize,
+ (UINTN)(BufferSize - FvUsedSize),
EraseByte
);
} else {
CopyMem (AlignedBuffer, Buffer, BufferSize);
}
- FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *) AlignedBuffer;
+
+ FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *)AlignedBuffer;
FreePool (Buffer);
Buffer = NULL;
}
}
}
+
//
// Produce a FVB protocol for the file
//
Status = ProduceFVBProtocolOnBuffer (
- (EFI_PHYSICAL_ADDRESS) (UINTN) FvHeader,
- (UINT64)BufferSize,
- FvHandle,
- AuthenticationStatus,
- NULL
- );
+ (EFI_PHYSICAL_ADDRESS)(UINTN)FvHeader,
+ (UINT64)BufferSize,
+ FvHandle,
+ AuthenticationStatus,
+ NULL
+ );
}
if (EFI_ERROR (Status)) {
@@ -1179,7 +1177,6 @@ CoreProcessFvImageFile ( }
}
-
/**
Event notification that is fired every time a FV dispatch protocol is added.
More than one protocol may have been added when this event is fired, so you
@@ -1200,42 +1197,42 @@ CoreProcessFvImageFile ( VOID
EFIAPI
CoreFwVolEventProtocolNotify (
- IN EFI_EVENT Event,
- IN VOID *Context
+ IN EFI_EVENT Event,
+ IN VOID *Context
)
{
- EFI_STATUS Status;
- EFI_STATUS GetNextFileStatus;
- EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv;
- EFI_DEVICE_PATH_PROTOCOL *FvDevicePath;
- EFI_HANDLE FvHandle;
- UINTN BufferSize;
- EFI_GUID NameGuid;
- UINTN Key;
- EFI_FV_FILETYPE Type;
- EFI_FV_FILE_ATTRIBUTES Attributes;
- UINTN Size;
- EFI_CORE_DRIVER_ENTRY *DriverEntry;
- EFI_GUID *AprioriFile;
- UINTN AprioriEntryCount;
- UINTN Index;
- LIST_ENTRY *Link;
- UINT32 AuthenticationStatus;
- UINTN SizeOfBuffer;
- VOID *DepexBuffer;
- KNOWN_HANDLE *KnownHandle;
+ EFI_STATUS Status;
+ EFI_STATUS GetNextFileStatus;
+ EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv;
+ EFI_DEVICE_PATH_PROTOCOL *FvDevicePath;
+ EFI_HANDLE FvHandle;
+ UINTN BufferSize;
+ EFI_GUID NameGuid;
+ UINTN Key;
+ EFI_FV_FILETYPE Type;
+ EFI_FV_FILE_ATTRIBUTES Attributes;
+ UINTN Size;
+ EFI_CORE_DRIVER_ENTRY *DriverEntry;
+ EFI_GUID *AprioriFile;
+ UINTN AprioriEntryCount;
+ UINTN Index;
+ LIST_ENTRY *Link;
+ UINT32 AuthenticationStatus;
+ UINTN SizeOfBuffer;
+ VOID *DepexBuffer;
+ KNOWN_HANDLE *KnownHandle;
FvHandle = NULL;
while (TRUE) {
BufferSize = sizeof (EFI_HANDLE);
- Status = CoreLocateHandle (
- ByRegisterNotify,
- NULL,
- mFwVolEventRegistration,
- &BufferSize,
- &FvHandle
- );
+ Status = CoreLocateHandle (
+ ByRegisterNotify,
+ NULL,
+ mFwVolEventRegistration,
+ &BufferSize,
+ &FvHandle
+ );
if (EFI_ERROR (Status)) {
//
// If no more notification events exit
@@ -1263,7 +1260,7 @@ CoreFwVolEventProtocolNotify ( }
Status = CoreHandleProtocol (FvHandle, &gEfiFirmwareVolume2ProtocolGuid, (VOID **)&Fv);
- if (EFI_ERROR (Status) || Fv == NULL) {
+ if (EFI_ERROR (Status) || (Fv == NULL)) {
//
// FvHandle must have Firmware Volume2 protocol thus we should never get here.
//
@@ -1291,7 +1288,7 @@ CoreFwVolEventProtocolNotify ( //
Key = 0;
do {
- Type = mDxeFileTypes[Index];
+ Type = mDxeFileTypes[Index];
GetNextFileStatus = Fv->GetNextFile (
Fv,
&Key,
@@ -1334,15 +1331,15 @@ CoreFwVolEventProtocolNotify ( //
DepexBuffer = NULL;
SizeOfBuffer = 0;
- Status = Fv->ReadSection (
- Fv,
- &NameGuid,
- EFI_SECTION_SMM_DEPEX,
- 0,
- &DepexBuffer,
- &SizeOfBuffer,
- &AuthenticationStatus
- );
+ Status = Fv->ReadSection (
+ Fv,
+ &NameGuid,
+ EFI_SECTION_SMM_DEPEX,
+ 0,
+ &DepexBuffer,
+ &SizeOfBuffer,
+ &AuthenticationStatus
+ );
if (!EFI_ERROR (Status)) {
//
// If SMM depex section is found, this FV image is invalid to be supported.
@@ -1357,15 +1354,15 @@ CoreFwVolEventProtocolNotify ( //
DepexBuffer = NULL;
SizeOfBuffer = 0;
- Status = Fv->ReadSection (
- Fv,
- &NameGuid,
- EFI_SECTION_DXE_DEPEX,
- 0,
- &DepexBuffer,
- &SizeOfBuffer,
- &AuthenticationStatus
- );
+ Status = Fv->ReadSection (
+ Fv,
+ &NameGuid,
+ EFI_SECTION_DXE_DEPEX,
+ 0,
+ &DepexBuffer,
+ &SizeOfBuffer,
+ &AuthenticationStatus
+ );
if (EFI_ERROR (Status)) {
//
// If no depex section, produce a firmware volume block protocol for it so it gets dispatched from.
@@ -1392,15 +1389,15 @@ CoreFwVolEventProtocolNotify ( // Read the array of GUIDs from the Apriori file if it is present in the firmware volume
//
AprioriFile = NULL;
- Status = Fv->ReadSection (
- Fv,
- &gAprioriGuid,
- EFI_SECTION_RAW,
- 0,
- (VOID **)&AprioriFile,
- &SizeOfBuffer,
- &AuthenticationStatus
- );
+ Status = Fv->ReadSection (
+ Fv,
+ &gAprioriGuid,
+ EFI_SECTION_RAW,
+ 0,
+ (VOID **)&AprioriFile,
+ &SizeOfBuffer,
+ &AuthenticationStatus
+ );
if (!EFI_ERROR (Status)) {
AprioriEntryCount = SizeOfBuffer / sizeof (EFI_GUID);
} else {
@@ -1415,9 +1412,10 @@ CoreFwVolEventProtocolNotify ( for (Index = 0; Index < AprioriEntryCount; Index++) {
for (Link = mDiscoveredList.ForwardLink; Link != &mDiscoveredList; Link = Link->ForwardLink) {
- DriverEntry = CR(Link, EFI_CORE_DRIVER_ENTRY, Link, EFI_CORE_DRIVER_ENTRY_SIGNATURE);
+ DriverEntry = CR (Link, EFI_CORE_DRIVER_ENTRY, Link, EFI_CORE_DRIVER_ENTRY_SIGNATURE);
if (CompareGuid (&DriverEntry->FileName, &AprioriFile[Index]) &&
- (FvHandle == DriverEntry->FvHandle)) {
+ (FvHandle == DriverEntry->FvHandle))
+ {
CoreAcquireDispatcherLock ();
DriverEntry->Dependent = FALSE;
DriverEntry->Scheduled = TRUE;
@@ -1437,8 +1435,6 @@ CoreFwVolEventProtocolNotify ( }
}
-
-
/**
Initialize the dispatcher. Initialize the notification function that runs when
an FV2 protocol is added to the system.
@@ -1476,11 +1472,11 @@ CoreDisplayDiscoveredNotDispatched ( VOID
)
{
- LIST_ENTRY *Link;
- EFI_CORE_DRIVER_ENTRY *DriverEntry;
+ LIST_ENTRY *Link;
+ EFI_CORE_DRIVER_ENTRY *DriverEntry;
- for (Link = mDiscoveredList.ForwardLink;Link !=&mDiscoveredList; Link = Link->ForwardLink) {
- DriverEntry = CR(Link, EFI_CORE_DRIVER_ENTRY, Link, EFI_CORE_DRIVER_ENTRY_SIGNATURE);
+ for (Link = mDiscoveredList.ForwardLink; Link != &mDiscoveredList; Link = Link->ForwardLink) {
+ DriverEntry = CR (Link, EFI_CORE_DRIVER_ENTRY, Link, EFI_CORE_DRIVER_ENTRY_SIGNATURE);
if (DriverEntry->Dependent) {
DEBUG ((DEBUG_LOAD, "Driver %g was discovered but not loaded!!\n", &DriverEntry->FileName));
}
diff --git a/MdeModulePkg/Core/Dxe/DxeMain.h b/MdeModulePkg/Core/Dxe/DxeMain.h index 7779e2d4e3..815a6b4bd8 100644 --- a/MdeModulePkg/Core/Dxe/DxeMain.h +++ b/MdeModulePkg/Core/Dxe/DxeMain.h @@ -10,8 +10,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #ifndef _DXE_MAIN_H_
#define _DXE_MAIN_H_
-
-
#include <PiDxe.h>
#include <Protocol/LoadedImage.h>
@@ -87,7 +85,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include <Library/DebugAgentLib.h>
#include <Library/CpuExceptionHandlerLib.h>
-
//
// attributes for reserved memory before it is promoted to system memory
//
@@ -100,7 +97,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent //
#define EFI_MEMORY_PORT_IO 0x4000000000000000ULL
-
///
/// EFI_DEP_REPLACE_TRUE - Used to dynamically patch the dependency expression
/// to save time. A EFI_DEP_PUSH is evaluated one an
@@ -117,11 +113,11 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #define DEPEX_STACK_SIZE_INCREMENT 0x1000
typedef struct {
- EFI_GUID *ProtocolGuid;
- VOID **Protocol;
- EFI_EVENT Event;
- VOID *Registration;
- BOOLEAN Present;
+ EFI_GUID *ProtocolGuid;
+ VOID **Protocol;
+ EFI_EVENT Event;
+ VOID *Registration;
+ BOOLEAN Present;
} EFI_CORE_PROTOCOL_NOTIFY_ENTRY;
//
@@ -130,171 +126,166 @@ typedef struct { #define KNOWN_HANDLE_SIGNATURE SIGNATURE_32('k','n','o','w')
typedef struct {
- UINTN Signature;
- LIST_ENTRY Link; // mFvHandleList
- EFI_HANDLE Handle;
- EFI_GUID FvNameGuid;
+ UINTN Signature;
+ LIST_ENTRY Link; // mFvHandleList
+ EFI_HANDLE Handle;
+ EFI_GUID FvNameGuid;
} KNOWN_HANDLE;
-
-#define EFI_CORE_DRIVER_ENTRY_SIGNATURE SIGNATURE_32('d','r','v','r')
+#define EFI_CORE_DRIVER_ENTRY_SIGNATURE SIGNATURE_32('d','r','v','r')
typedef struct {
- UINTN Signature;
- LIST_ENTRY Link; // mDriverList
+ UINTN Signature;
+ LIST_ENTRY Link; // mDriverList
- LIST_ENTRY ScheduledLink; // mScheduledQueue
+ LIST_ENTRY ScheduledLink; // mScheduledQueue
- EFI_HANDLE FvHandle;
- EFI_GUID FileName;
- EFI_DEVICE_PATH_PROTOCOL *FvFileDevicePath;
- EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv;
+ EFI_HANDLE FvHandle;
+ EFI_GUID FileName;
+ EFI_DEVICE_PATH_PROTOCOL *FvFileDevicePath;
+ EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv;
- VOID *Depex;
- UINTN DepexSize;
+ VOID *Depex;
+ UINTN DepexSize;
- BOOLEAN Before;
- BOOLEAN After;
- EFI_GUID BeforeAfterGuid;
+ BOOLEAN Before;
+ BOOLEAN After;
+ EFI_GUID BeforeAfterGuid;
- BOOLEAN Dependent;
- BOOLEAN Unrequested;
- BOOLEAN Scheduled;
- BOOLEAN Untrusted;
- BOOLEAN Initialized;
- BOOLEAN DepexProtocolError;
-
- EFI_HANDLE ImageHandle;
- BOOLEAN IsFvImage;
+ BOOLEAN Dependent;
+ BOOLEAN Unrequested;
+ BOOLEAN Scheduled;
+ BOOLEAN Untrusted;
+ BOOLEAN Initialized;
+ BOOLEAN DepexProtocolError;
+ EFI_HANDLE ImageHandle;
+ BOOLEAN IsFvImage;
} EFI_CORE_DRIVER_ENTRY;
//
-//The data structure of GCD memory map entry
+// The data structure of GCD memory map entry
//
#define EFI_GCD_MAP_SIGNATURE SIGNATURE_32('g','c','d','m')
typedef struct {
- UINTN Signature;
- LIST_ENTRY Link;
- EFI_PHYSICAL_ADDRESS BaseAddress;
- UINT64 EndAddress;
- UINT64 Capabilities;
- UINT64 Attributes;
- EFI_GCD_MEMORY_TYPE GcdMemoryType;
- EFI_GCD_IO_TYPE GcdIoType;
- EFI_HANDLE ImageHandle;
- EFI_HANDLE DeviceHandle;
+ UINTN Signature;
+ LIST_ENTRY Link;
+ EFI_PHYSICAL_ADDRESS BaseAddress;
+ UINT64 EndAddress;
+ UINT64 Capabilities;
+ UINT64 Attributes;
+ EFI_GCD_MEMORY_TYPE GcdMemoryType;
+ EFI_GCD_IO_TYPE GcdIoType;
+ EFI_HANDLE ImageHandle;
+ EFI_HANDLE DeviceHandle;
} EFI_GCD_MAP_ENTRY;
-
-#define LOADED_IMAGE_PRIVATE_DATA_SIGNATURE SIGNATURE_32('l','d','r','i')
+#define LOADED_IMAGE_PRIVATE_DATA_SIGNATURE SIGNATURE_32('l','d','r','i')
typedef struct {
- UINTN Signature;
+ UINTN Signature;
/// Image handle
- EFI_HANDLE Handle;
+ EFI_HANDLE Handle;
/// Image type
- UINTN Type;
+ UINTN Type;
/// If entrypoint has been called
- BOOLEAN Started;
+ BOOLEAN Started;
/// The image's entry point
- EFI_IMAGE_ENTRY_POINT EntryPoint;
+ EFI_IMAGE_ENTRY_POINT EntryPoint;
/// loaded image protocol
- EFI_LOADED_IMAGE_PROTOCOL Info;
+ EFI_LOADED_IMAGE_PROTOCOL Info;
/// Location in memory
- EFI_PHYSICAL_ADDRESS ImageBasePage;
+ EFI_PHYSICAL_ADDRESS ImageBasePage;
/// Number of pages
- UINTN NumberOfPages;
+ UINTN NumberOfPages;
/// Original fixup data
- CHAR8 *FixupData;
+ CHAR8 *FixupData;
/// Tpl of started image
- EFI_TPL Tpl;
+ EFI_TPL Tpl;
/// Status returned by started image
- EFI_STATUS Status;
+ EFI_STATUS Status;
/// Size of ExitData from started image
- UINTN ExitDataSize;
+ UINTN ExitDataSize;
/// Pointer to exit data from started image
- VOID *ExitData;
+ VOID *ExitData;
/// Pointer to pool allocation for context save/restore
- VOID *JumpBuffer;
+ VOID *JumpBuffer;
/// Pointer to buffer for context save/restore
- BASE_LIBRARY_JUMP_BUFFER *JumpContext;
+ BASE_LIBRARY_JUMP_BUFFER *JumpContext;
/// Machine type from PE image
- UINT16 Machine;
+ UINT16 Machine;
/// PE/COFF Image Emulator Protocol pointer
- EDKII_PECOFF_IMAGE_EMULATOR_PROTOCOL *PeCoffEmu;
+ EDKII_PECOFF_IMAGE_EMULATOR_PROTOCOL *PeCoffEmu;
/// Runtime image list
- EFI_RUNTIME_IMAGE_ENTRY *RuntimeData;
+ EFI_RUNTIME_IMAGE_ENTRY *RuntimeData;
/// Pointer to Loaded Image Device Path Protocol
- EFI_DEVICE_PATH_PROTOCOL *LoadedImageDevicePath;
+ EFI_DEVICE_PATH_PROTOCOL *LoadedImageDevicePath;
/// PeCoffLoader ImageContext
- PE_COFF_LOADER_IMAGE_CONTEXT ImageContext;
+ PE_COFF_LOADER_IMAGE_CONTEXT ImageContext;
/// Status returned by LoadImage() service.
- EFI_STATUS LoadImageStatus;
+ EFI_STATUS LoadImageStatus;
} LOADED_IMAGE_PRIVATE_DATA;
#define LOADED_IMAGE_PRIVATE_DATA_FROM_THIS(a) \
CR(a, LOADED_IMAGE_PRIVATE_DATA, Info, LOADED_IMAGE_PRIVATE_DATA_SIGNATURE)
-#define IMAGE_PROPERTIES_RECORD_CODE_SECTION_SIGNATURE SIGNATURE_32 ('I','P','R','C')
+#define IMAGE_PROPERTIES_RECORD_CODE_SECTION_SIGNATURE SIGNATURE_32 ('I','P','R','C')
typedef struct {
- UINT32 Signature;
- LIST_ENTRY Link;
- EFI_PHYSICAL_ADDRESS CodeSegmentBase;
- UINT64 CodeSegmentSize;
+ UINT32 Signature;
+ LIST_ENTRY Link;
+ EFI_PHYSICAL_ADDRESS CodeSegmentBase;
+ UINT64 CodeSegmentSize;
} IMAGE_PROPERTIES_RECORD_CODE_SECTION;
-#define IMAGE_PROPERTIES_RECORD_SIGNATURE SIGNATURE_32 ('I','P','R','D')
+#define IMAGE_PROPERTIES_RECORD_SIGNATURE SIGNATURE_32 ('I','P','R','D')
typedef struct {
- UINT32 Signature;
- LIST_ENTRY Link;
- EFI_PHYSICAL_ADDRESS ImageBase;
- UINT64 ImageSize;
- UINTN CodeSegmentCount;
- LIST_ENTRY CodeSegmentList;
+ UINT32 Signature;
+ LIST_ENTRY Link;
+ EFI_PHYSICAL_ADDRESS ImageBase;
+ UINT64 ImageSize;
+ UINTN CodeSegmentCount;
+ LIST_ENTRY CodeSegmentList;
} IMAGE_PROPERTIES_RECORD;
//
// DXE Core Global Variables
//
-extern EFI_SYSTEM_TABLE *gDxeCoreST;
-extern EFI_RUNTIME_SERVICES *gDxeCoreRT;
-extern EFI_DXE_SERVICES *gDxeCoreDS;
-extern EFI_HANDLE gDxeCoreImageHandle;
+extern EFI_SYSTEM_TABLE *gDxeCoreST;
+extern EFI_RUNTIME_SERVICES *gDxeCoreRT;
+extern EFI_DXE_SERVICES *gDxeCoreDS;
+extern EFI_HANDLE gDxeCoreImageHandle;
-extern BOOLEAN gMemoryMapTerminated;
+extern BOOLEAN gMemoryMapTerminated;
-extern EFI_DECOMPRESS_PROTOCOL gEfiDecompress;
+extern EFI_DECOMPRESS_PROTOCOL gEfiDecompress;
-extern EFI_RUNTIME_ARCH_PROTOCOL *gRuntime;
-extern EFI_CPU_ARCH_PROTOCOL *gCpu;
-extern EFI_WATCHDOG_TIMER_ARCH_PROTOCOL *gWatchdogTimer;
-extern EFI_METRONOME_ARCH_PROTOCOL *gMetronome;
-extern EFI_TIMER_ARCH_PROTOCOL *gTimer;
-extern EFI_SECURITY_ARCH_PROTOCOL *gSecurity;
-extern EFI_SECURITY2_ARCH_PROTOCOL *gSecurity2;
-extern EFI_BDS_ARCH_PROTOCOL *gBds;
-extern EFI_SMM_BASE2_PROTOCOL *gSmmBase2;
+extern EFI_RUNTIME_ARCH_PROTOCOL *gRuntime;
+extern EFI_CPU_ARCH_PROTOCOL *gCpu;
+extern EFI_WATCHDOG_TIMER_ARCH_PROTOCOL *gWatchdogTimer;
+extern EFI_METRONOME_ARCH_PROTOCOL *gMetronome;
+extern EFI_TIMER_ARCH_PROTOCOL *gTimer;
+extern EFI_SECURITY_ARCH_PROTOCOL *gSecurity;
+extern EFI_SECURITY2_ARCH_PROTOCOL *gSecurity2;
+extern EFI_BDS_ARCH_PROTOCOL *gBds;
+extern EFI_SMM_BASE2_PROTOCOL *gSmmBase2;
-extern EFI_TPL gEfiCurrentTpl;
+extern EFI_TPL gEfiCurrentTpl;
-extern EFI_GUID *gDxeCoreFileName;
-extern EFI_LOADED_IMAGE_PROTOCOL *gDxeCoreLoadedImage;
+extern EFI_GUID *gDxeCoreFileName;
+extern EFI_LOADED_IMAGE_PROTOCOL *gDxeCoreLoadedImage;
-extern EFI_MEMORY_TYPE_INFORMATION gMemoryTypeInformation[EfiMaxMemoryType + 1];
+extern EFI_MEMORY_TYPE_INFORMATION gMemoryTypeInformation[EfiMaxMemoryType + 1];
-extern BOOLEAN gDispatcherRunning;
-extern EFI_RUNTIME_ARCH_PROTOCOL gRuntimeTemplate;
+extern BOOLEAN gDispatcherRunning;
+extern EFI_RUNTIME_ARCH_PROTOCOL gRuntimeTemplate;
-extern EFI_LOAD_FIXED_ADDRESS_CONFIGURATION_TABLE gLoadModuleAtFixAddressConfigurationTable;
-extern BOOLEAN gLoadFixedAddressCodeMemoryReady;
+extern EFI_LOAD_FIXED_ADDRESS_CONFIGURATION_TABLE gLoadModuleAtFixAddressConfigurationTable;
+extern BOOLEAN gLoadFixedAddressCodeMemoryReady;
//
// Service Initialization Functions
//
-
-
/**
Called to initialize the pool.
@@ -304,7 +295,6 @@ CoreInitializePool ( VOID
);
-
/**
Called to initialize the memory map and add descriptors to
the current descriptor list.
@@ -328,7 +318,6 @@ CoreAddMemoryDescriptor ( IN UINT64 Attribute
);
-
/**
Release memory lock on mGcdMemorySpaceLock.
@@ -338,7 +327,6 @@ CoreReleaseGcdMemoryLock ( VOID
);
-
/**
Acquire memory lock on mGcdMemorySpaceLock.
@@ -348,7 +336,6 @@ CoreAcquireGcdMemoryLock ( VOID
);
-
/**
External function. Initializes memory services based on the memory
descriptor HOBs. This function is responsible for priming the memory
@@ -371,8 +358,6 @@ CoreInitializeMemoryServices ( OUT UINT64 *MemoryLength
);
-
-
/**
External function. Initializes the GCD and memory services based on the memory
descriptor HOBs. This function is responsible for priming the GCD map and the
@@ -394,7 +379,6 @@ CoreInitializeGcdServices ( IN UINT64 MemoryLength
);
-
/**
Initializes "event" support.
@@ -406,7 +390,6 @@ CoreInitializeEventServices ( VOID
);
-
/**
Add the Image Services to EFI Boot Services Table and install the protocol
interfaces for this image.
@@ -418,10 +401,9 @@ CoreInitializeEventServices ( **/
EFI_STATUS
CoreInitializeImageServices (
- IN VOID *HobStart
+ IN VOID *HobStart
);
-
/**
Creates an event that is fired everytime a Protocol of a specific type is installed.
@@ -431,7 +413,6 @@ CoreNotifyOnProtocolInstallation ( VOID
);
-
/**
Return TRUE if all AP services are available.
@@ -444,7 +425,6 @@ CoreAllEfiServicesAvailable ( VOID
);
-
/**
Calcualte the 32-bit CRC in a EFI table using the service provided by the
gRuntime service.
@@ -454,10 +434,9 @@ CoreAllEfiServicesAvailable ( **/
VOID
CalculateEfiHdrCrc (
- IN OUT EFI_TABLE_HEADER *Hdr
+ IN OUT EFI_TABLE_HEADER *Hdr
);
-
/**
Called by the platform code to process a tick.
@@ -468,10 +447,9 @@ CalculateEfiHdrCrc ( VOID
EFIAPI
CoreTimerTick (
- IN UINT64 Duration
+ IN UINT64 Duration
);
-
/**
Initialize the dispatcher. Initialize the notification function that runs when
an FV2 protocol is added to the system.
@@ -482,7 +460,6 @@ CoreInitializeDispatcher ( VOID
);
-
/**
This is the POSTFIX version of the dependency evaluator. This code does
not need to handle Before or After, as it is not valid to call this
@@ -498,10 +475,9 @@ CoreInitializeDispatcher ( **/
BOOLEAN
CoreIsSchedulable (
- IN EFI_CORE_DRIVER_ENTRY *DriverEntry
+ IN EFI_CORE_DRIVER_ENTRY *DriverEntry
);
-
/**
Preprocess dependency expression and update DriverEntry to reflect the
state of Before, After, and SOR dependencies. If DriverEntry->Before
@@ -516,11 +492,9 @@ CoreIsSchedulable ( **/
EFI_STATUS
CorePreProcessDepex (
- IN EFI_CORE_DRIVER_ENTRY *DriverEntry
+ IN EFI_CORE_DRIVER_ENTRY *DriverEntry
);
-
-
/**
Terminates all boot services.
@@ -534,11 +508,10 @@ CorePreProcessDepex ( EFI_STATUS
EFIAPI
CoreExitBootServices (
- IN EFI_HANDLE ImageHandle,
- IN UINTN MapKey
+ IN EFI_HANDLE ImageHandle,
+ IN UINTN MapKey
);
-
/**
Make sure the memory map is following all the construction rules,
it is the last time to check memory map error before exit boot services.
@@ -552,10 +525,9 @@ CoreExitBootServices ( **/
EFI_STATUS
CoreTerminateMemoryMap (
- IN UINTN MapKey
+ IN UINTN MapKey
);
-
/**
Signals all events in the EventGroup.
@@ -564,11 +536,9 @@ CoreTerminateMemoryMap ( **/
VOID
CoreNotifySignalList (
- IN EFI_GUID *EventGroup
+ IN EFI_GUID *EventGroup
);
-
-
/**
Boot Service called to add, modify, or remove a system configuration table from
the EFI System Table.
@@ -587,12 +557,10 @@ CoreNotifySignalList ( EFI_STATUS
EFIAPI
CoreInstallConfigurationTable (
- IN EFI_GUID *Guid,
- IN VOID *Table
+ IN EFI_GUID *Guid,
+ IN VOID *Table
);
-
-
/**
Raise the task priority level to the new level.
High level is implemented by disabling processor interrupts.
@@ -605,11 +573,9 @@ CoreInstallConfigurationTable ( EFI_TPL
EFIAPI
CoreRaiseTpl (
- IN EFI_TPL NewTpl
+ IN EFI_TPL NewTpl
);
-
-
/**
Lowers the task priority to the previous value. If the new
priority unmasks events at a higher priority, they are dispatched.
@@ -620,11 +586,9 @@ CoreRaiseTpl ( VOID
EFIAPI
CoreRestoreTpl (
- IN EFI_TPL NewTpl
+ IN EFI_TPL NewTpl
);
-
-
/**
Introduces a fine-grained stall.
@@ -638,11 +602,9 @@ CoreRestoreTpl ( EFI_STATUS
EFIAPI
CoreStall (
- IN UINTN Microseconds
+ IN UINTN Microseconds
);
-
-
/**
Sets the system's watchdog timer.
@@ -668,14 +630,12 @@ CoreStall ( EFI_STATUS
EFIAPI
CoreSetWatchdogTimer (
- IN UINTN Timeout,
- IN UINT64 WatchdogCode,
- IN UINTN DataSize,
- IN CHAR16 *WatchdogData OPTIONAL
+ IN UINTN Timeout,
+ IN UINT64 WatchdogCode,
+ IN UINTN DataSize,
+ IN CHAR16 *WatchdogData OPTIONAL
);
-
-
/**
Wrapper function to CoreInstallProtocolInterfaceNotify. This is the public API which
Calls the private one which contains a BOOLEAN parameter for notifications
@@ -693,13 +653,12 @@ CoreSetWatchdogTimer ( EFI_STATUS
EFIAPI
CoreInstallProtocolInterface (
- IN OUT EFI_HANDLE *UserHandle,
- IN EFI_GUID *Protocol,
- IN EFI_INTERFACE_TYPE InterfaceType,
- IN VOID *Interface
+ IN OUT EFI_HANDLE *UserHandle,
+ IN EFI_GUID *Protocol,
+ IN EFI_INTERFACE_TYPE InterfaceType,
+ IN VOID *Interface
);
-
/**
Installs a protocol interface into the boot services environment.
@@ -719,15 +678,13 @@ CoreInstallProtocolInterface ( **/
EFI_STATUS
CoreInstallProtocolInterfaceNotify (
- IN OUT EFI_HANDLE *UserHandle,
- IN EFI_GUID *Protocol,
- IN EFI_INTERFACE_TYPE InterfaceType,
- IN VOID *Interface,
- IN BOOLEAN Notify
+ IN OUT EFI_HANDLE *UserHandle,
+ IN EFI_GUID *Protocol,
+ IN EFI_INTERFACE_TYPE InterfaceType,
+ IN VOID *Interface,
+ IN BOOLEAN Notify
);
-
-
/**
Installs a list of protocol interface into the boot services environment.
This function calls InstallProtocolInterface() in a loop. If any error
@@ -752,12 +709,10 @@ CoreInstallProtocolInterfaceNotify ( EFI_STATUS
EFIAPI
CoreInstallMultipleProtocolInterfaces (
- IN OUT EFI_HANDLE *Handle,
+ IN OUT EFI_HANDLE *Handle,
...
);
-
-
/**
Uninstalls a list of protocol interface in the boot services environment.
This function calls UnisatllProtocolInterface() in a loop. This is
@@ -775,12 +730,10 @@ CoreInstallMultipleProtocolInterfaces ( EFI_STATUS
EFIAPI
CoreUninstallMultipleProtocolInterfaces (
- IN EFI_HANDLE Handle,
+ IN EFI_HANDLE Handle,
...
);
-
-
/**
Reinstall a protocol interface on a device handle. The OldInterface for Protocol is replaced by the NewInterface.
@@ -798,14 +751,12 @@ CoreUninstallMultipleProtocolInterfaces ( EFI_STATUS
EFIAPI
CoreReinstallProtocolInterface (
- IN EFI_HANDLE UserHandle,
- IN EFI_GUID *Protocol,
- IN VOID *OldInterface,
- IN VOID *NewInterface
+ IN EFI_HANDLE UserHandle,
+ IN EFI_GUID *Protocol,
+ IN VOID *OldInterface,
+ IN VOID *NewInterface
);
-
-
/**
Uninstalls all instances of a protocol:interfacer from a handle.
If the last protocol interface is remove from the handle, the
@@ -822,13 +773,11 @@ CoreReinstallProtocolInterface ( EFI_STATUS
EFIAPI
CoreUninstallProtocolInterface (
- IN EFI_HANDLE UserHandle,
- IN EFI_GUID *Protocol,
- IN VOID *Interface
+ IN EFI_HANDLE UserHandle,
+ IN EFI_GUID *Protocol,
+ IN VOID *Interface
);
-
-
/**
Queries a handle to determine if it supports a specified protocol.
@@ -843,13 +792,11 @@ CoreUninstallProtocolInterface ( EFI_STATUS
EFIAPI
CoreHandleProtocol (
- IN EFI_HANDLE UserHandle,
- IN EFI_GUID *Protocol,
- OUT VOID **Interface
+ IN EFI_HANDLE UserHandle,
+ IN EFI_GUID *Protocol,
+ OUT VOID **Interface
);
-
-
/**
Locates the installed protocol handler for the handle, and
invokes it to obtain the protocol interface. Usage information
@@ -873,16 +820,14 @@ CoreHandleProtocol ( EFI_STATUS
EFIAPI
CoreOpenProtocol (
- IN EFI_HANDLE UserHandle,
- IN EFI_GUID *Protocol,
- OUT VOID **Interface OPTIONAL,
- IN EFI_HANDLE ImageHandle,
- IN EFI_HANDLE ControllerHandle,
- IN UINT32 Attributes
+ IN EFI_HANDLE UserHandle,
+ IN EFI_GUID *Protocol,
+ OUT VOID **Interface OPTIONAL,
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_HANDLE ControllerHandle,
+ IN UINT32 Attributes
);
-
-
/**
Return information about Opened protocols in the system
@@ -897,14 +842,12 @@ CoreOpenProtocol ( EFI_STATUS
EFIAPI
CoreOpenProtocolInformation (
- IN EFI_HANDLE UserHandle,
- IN EFI_GUID *Protocol,
- OUT EFI_OPEN_PROTOCOL_INFORMATION_ENTRY **EntryBuffer,
- OUT UINTN *EntryCount
+ IN EFI_HANDLE UserHandle,
+ IN EFI_GUID *Protocol,
+ OUT EFI_OPEN_PROTOCOL_INFORMATION_ENTRY **EntryBuffer,
+ OUT UINTN *EntryCount
);
-
-
/**
Closes a protocol on a handle that was opened using OpenProtocol().
@@ -933,14 +876,12 @@ CoreOpenProtocolInformation ( EFI_STATUS
EFIAPI
CoreCloseProtocol (
- IN EFI_HANDLE UserHandle,
- IN EFI_GUID *Protocol,
- IN EFI_HANDLE AgentHandle,
- IN EFI_HANDLE ControllerHandle
+ IN EFI_HANDLE UserHandle,
+ IN EFI_GUID *Protocol,
+ IN EFI_HANDLE AgentHandle,
+ IN EFI_HANDLE ControllerHandle
);
-
-
/**
Retrieves the list of protocol interface GUIDs that are installed on a handle in a buffer allocated
from pool.
@@ -967,13 +908,11 @@ CoreCloseProtocol ( EFI_STATUS
EFIAPI
CoreProtocolsPerHandle (
- IN EFI_HANDLE UserHandle,
- OUT EFI_GUID ***ProtocolBuffer,
- OUT UINTN *ProtocolBufferCount
+ IN EFI_HANDLE UserHandle,
+ OUT EFI_GUID ***ProtocolBuffer,
+ OUT UINTN *ProtocolBufferCount
);
-
-
/**
Add a new protocol notification record for the request protocol.
@@ -990,12 +929,11 @@ CoreProtocolsPerHandle ( EFI_STATUS
EFIAPI
CoreRegisterProtocolNotify (
- IN EFI_GUID *Protocol,
- IN EFI_EVENT Event,
- OUT VOID **Registration
+ IN EFI_GUID *Protocol,
+ IN EFI_EVENT Event,
+ OUT VOID **Registration
);
-
/**
Removes all the events in the protocol database that match Event.
@@ -1007,10 +945,9 @@ CoreRegisterProtocolNotify ( **/
EFI_STATUS
CoreUnregisterProtocolNotify (
- IN EFI_EVENT Event
+ IN EFI_EVENT Event
);
-
/**
Locates the requested handle(s) and returns them in Buffer.
@@ -1032,15 +969,13 @@ CoreUnregisterProtocolNotify ( EFI_STATUS
EFIAPI
CoreLocateHandle (
- IN EFI_LOCATE_SEARCH_TYPE SearchType,
- IN EFI_GUID *Protocol OPTIONAL,
- IN VOID *SearchKey OPTIONAL,
- IN OUT UINTN *BufferSize,
- OUT EFI_HANDLE *Buffer
+ IN EFI_LOCATE_SEARCH_TYPE SearchType,
+ IN EFI_GUID *Protocol OPTIONAL,
+ IN VOID *SearchKey OPTIONAL,
+ IN OUT UINTN *BufferSize,
+ OUT EFI_HANDLE *Buffer
);
-
-
/**
Locates the handle to a device on the device path that best matches the specified protocol.
@@ -1059,13 +994,11 @@ CoreLocateHandle ( EFI_STATUS
EFIAPI
CoreLocateDevicePath (
- IN EFI_GUID *Protocol,
- IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath,
- OUT EFI_HANDLE *Device
+ IN EFI_GUID *Protocol,
+ IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath,
+ OUT EFI_HANDLE *Device
);
-
-
/**
Function returns an array of handles that support the requested protocol
in a buffer allocated from pool. This is a version of CoreLocateHandle()
@@ -1091,15 +1024,13 @@ CoreLocateDevicePath ( EFI_STATUS
EFIAPI
CoreLocateHandleBuffer (
- IN EFI_LOCATE_SEARCH_TYPE SearchType,
- IN EFI_GUID *Protocol OPTIONAL,
- IN VOID *SearchKey OPTIONAL,
- IN OUT UINTN *NumberHandles,
- OUT EFI_HANDLE **Buffer
+ IN EFI_LOCATE_SEARCH_TYPE SearchType,
+ IN EFI_GUID *Protocol OPTIONAL,
+ IN VOID *SearchKey OPTIONAL,
+ IN OUT UINTN *NumberHandles,
+ OUT EFI_HANDLE **Buffer
);
-
-
/**
Return the first Protocol Interface that matches the Protocol GUID. If
Registration is passed in, return a Protocol Instance that was just add
@@ -1124,7 +1055,6 @@ CoreLocateProtocol ( OUT VOID **Interface
);
-
/**
return handle database key.
@@ -1137,7 +1067,6 @@ CoreGetHandleDatabaseKey ( VOID
);
-
/**
Go connect any handles that were created or modified while a image executed.
@@ -1150,8 +1079,6 @@ CoreConnectHandlesByKey ( UINT64 Key
);
-
-
/**
Connects one or more drivers to a controller.
@@ -1187,8 +1114,6 @@ CoreConnectController ( IN BOOLEAN Recursive
);
-
-
/**
Disonnects a controller from a driver
@@ -1229,8 +1154,6 @@ CoreDisconnectController ( IN EFI_HANDLE ChildHandle OPTIONAL
);
-
-
/**
Allocates pages from the memory map.
@@ -1252,9 +1175,9 @@ CoreDisconnectController ( EFI_STATUS
EFIAPI
CoreAllocatePages (
- IN EFI_ALLOCATE_TYPE Type,
- IN EFI_MEMORY_TYPE MemoryType,
- IN UINTN NumberOfPages,
+ IN EFI_ALLOCATE_TYPE Type,
+ IN EFI_MEMORY_TYPE MemoryType,
+ IN UINTN NumberOfPages,
IN OUT EFI_PHYSICAL_ADDRESS *Memory
);
@@ -1272,8 +1195,8 @@ CoreAllocatePages ( EFI_STATUS
EFIAPI
CoreFreePages (
- IN EFI_PHYSICAL_ADDRESS Memory,
- IN UINTN NumberOfPages
+ IN EFI_PHYSICAL_ADDRESS Memory,
+ IN UINTN NumberOfPages
);
/**
@@ -1316,8 +1239,6 @@ CoreGetMemoryMap ( OUT UINT32 *DescriptorVersion
);
-
-
/**
Allocate pool of a particular type.
@@ -1372,7 +1293,7 @@ CoreInternalAllocatePool ( EFI_STATUS
EFIAPI
CoreFreePool (
- IN VOID *Buffer
+ IN VOID *Buffer
);
/**
@@ -1388,8 +1309,8 @@ CoreFreePool ( EFI_STATUS
EFIAPI
CoreInternalFreePool (
- IN VOID *Buffer,
- OUT EFI_MEMORY_TYPE *PoolType OPTIONAL
+ IN VOID *Buffer,
+ OUT EFI_MEMORY_TYPE *PoolType OPTIONAL
);
/**
@@ -1429,16 +1350,14 @@ CoreInternalFreePool ( EFI_STATUS
EFIAPI
CoreLoadImage (
- IN BOOLEAN BootPolicy,
- IN EFI_HANDLE ParentImageHandle,
- IN EFI_DEVICE_PATH_PROTOCOL *FilePath,
- IN VOID *SourceBuffer OPTIONAL,
- IN UINTN SourceSize,
- OUT EFI_HANDLE *ImageHandle
+ IN BOOLEAN BootPolicy,
+ IN EFI_HANDLE ParentImageHandle,
+ IN EFI_DEVICE_PATH_PROTOCOL *FilePath,
+ IN VOID *SourceBuffer OPTIONAL,
+ IN UINTN SourceSize,
+ OUT EFI_HANDLE *ImageHandle
);
-
-
/**
Unloads an image.
@@ -1457,8 +1376,6 @@ CoreUnloadImage ( IN EFI_HANDLE ImageHandle
);
-
-
/**
Transfer control to a loaded image's entry point.
@@ -1486,8 +1403,6 @@ CoreStartImage ( OUT CHAR16 **ExitData OPTIONAL
);
-
-
/**
Terminates the currently loaded EFI image and returns control to boot services.
@@ -1520,8 +1435,6 @@ CoreExit ( IN CHAR16 *ExitData OPTIONAL
);
-
-
/**
Creates an event.
@@ -1543,15 +1456,13 @@ CoreExit ( EFI_STATUS
EFIAPI
CoreCreateEvent (
- IN UINT32 Type,
- IN EFI_TPL NotifyTpl,
- IN EFI_EVENT_NOTIFY NotifyFunction OPTIONAL,
- IN VOID *NotifyContext OPTIONAL,
- OUT EFI_EVENT *Event
+ IN UINT32 Type,
+ IN EFI_TPL NotifyTpl,
+ IN EFI_EVENT_NOTIFY NotifyFunction OPTIONAL,
+ IN VOID *NotifyContext OPTIONAL,
+ OUT EFI_EVENT *Event
);
-
-
/**
Creates an event in a group.
@@ -1575,12 +1486,12 @@ CoreCreateEvent ( EFI_STATUS
EFIAPI
CoreCreateEventEx (
- IN UINT32 Type,
- IN EFI_TPL NotifyTpl,
- IN EFI_EVENT_NOTIFY NotifyFunction OPTIONAL,
- IN CONST VOID *NotifyContext OPTIONAL,
- IN CONST EFI_GUID *EventGroup OPTIONAL,
- OUT EFI_EVENT *Event
+ IN UINT32 Type,
+ IN EFI_TPL NotifyTpl,
+ IN EFI_EVENT_NOTIFY NotifyFunction OPTIONAL,
+ IN CONST VOID *NotifyContext OPTIONAL,
+ IN CONST EFI_GUID *EventGroup OPTIONAL,
+ OUT EFI_EVENT *Event
);
/**
@@ -1606,12 +1517,12 @@ CoreCreateEventEx ( EFI_STATUS
EFIAPI
CoreCreateEventInternal (
- IN UINT32 Type,
- IN EFI_TPL NotifyTpl,
- IN EFI_EVENT_NOTIFY NotifyFunction OPTIONAL,
- IN CONST VOID *NotifyContext OPTIONAL,
- IN CONST EFI_GUID *EventGroup OPTIONAL,
- OUT EFI_EVENT *Event
+ IN UINT32 Type,
+ IN EFI_TPL NotifyTpl,
+ IN EFI_EVENT_NOTIFY NotifyFunction OPTIONAL,
+ IN CONST VOID *NotifyContext OPTIONAL,
+ IN CONST EFI_GUID *EventGroup OPTIONAL,
+ OUT EFI_EVENT *Event
);
/**
@@ -1632,13 +1543,11 @@ CoreCreateEventInternal ( EFI_STATUS
EFIAPI
CoreSetTimer (
- IN EFI_EVENT UserEvent,
- IN EFI_TIMER_DELAY Type,
- IN UINT64 TriggerTime
+ IN EFI_EVENT UserEvent,
+ IN EFI_TIMER_DELAY Type,
+ IN UINT64 TriggerTime
);
-
-
/**
Signals the event. Queues the event to be notified if needed.
@@ -1651,11 +1560,9 @@ CoreSetTimer ( EFI_STATUS
EFIAPI
CoreSignalEvent (
- IN EFI_EVENT UserEvent
+ IN EFI_EVENT UserEvent
);
-
-
/**
Stops execution until an event is signaled.
@@ -1673,13 +1580,11 @@ CoreSignalEvent ( EFI_STATUS
EFIAPI
CoreWaitForEvent (
- IN UINTN NumberOfEvents,
- IN EFI_EVENT *UserEvents,
- OUT UINTN *UserIndex
+ IN UINTN NumberOfEvents,
+ IN EFI_EVENT *UserEvents,
+ OUT UINTN *UserIndex
);
-
-
/**
Closes an event and frees the event structure.
@@ -1692,11 +1597,9 @@ CoreWaitForEvent ( EFI_STATUS
EFIAPI
CoreCloseEvent (
- IN EFI_EVENT UserEvent
+ IN EFI_EVENT UserEvent
);
-
-
/**
Check the status of an event.
@@ -1710,10 +1613,9 @@ CoreCloseEvent ( EFI_STATUS
EFIAPI
CoreCheckEvent (
- IN EFI_EVENT UserEvent
+ IN EFI_EVENT UserEvent
);
-
/**
Adds reserved memory, system memory, or memory-mapped I/O resources to the
global coherency domain of the processor.
@@ -1735,7 +1637,6 @@ CoreAddMemorySpace ( IN UINT64 Capabilities
);
-
/**
Allocates nonexistent memory, reserved memory, system memory, or memorymapped
I/O resources from the global coherency domain of the processor.
@@ -1765,7 +1666,6 @@ CoreAllocateMemorySpace ( IN EFI_HANDLE DeviceHandle OPTIONAL
);
-
/**
Frees nonexistent memory, reserved memory, system memory, or memory-mapped
I/O resources from the global coherency domain of the processor.
@@ -1783,7 +1683,6 @@ CoreFreeMemorySpace ( IN UINT64 Length
);
-
/**
Removes reserved memory, system memory, or memory-mapped I/O resources from
the global coherency domain of the processor.
@@ -1801,7 +1700,6 @@ CoreRemoveMemorySpace ( IN UINT64 Length
);
-
/**
Retrieves the descriptor for a memory region containing a specified address.
@@ -1819,7 +1717,6 @@ CoreGetMemorySpaceDescriptor ( OUT EFI_GCD_MEMORY_SPACE_DESCRIPTOR *Descriptor
);
-
/**
Modifies the attributes for a memory region in the global coherency domain of the
processor.
@@ -1850,7 +1747,6 @@ CoreSetMemorySpaceAttributes ( IN UINT64 Attributes
);
-
/**
Modifies the capabilities for a memory region in the global coherency domain of the
processor.
@@ -1876,7 +1772,6 @@ CoreSetMemorySpaceCapabilities ( IN UINT64 Capabilities
);
-
/**
Returns a map of the memory resources in the global coherency domain of the
processor.
@@ -1896,7 +1791,6 @@ CoreGetMemorySpaceMap ( OUT EFI_GCD_MEMORY_SPACE_DESCRIPTOR **MemorySpaceMap
);
-
/**
Adds reserved I/O or I/O resources to the global coherency domain of the processor.
@@ -1916,7 +1810,6 @@ CoreAddIoSpace ( IN UINT64 Length
);
-
/**
Allocates nonexistent I/O, reserved I/O, or I/O resources from the global coherency
domain of the processor.
@@ -1946,7 +1839,6 @@ CoreAllocateIoSpace ( IN EFI_HANDLE DeviceHandle OPTIONAL
);
-
/**
Frees nonexistent I/O, reserved I/O, or I/O resources from the global coherency
domain of the processor.
@@ -1964,7 +1856,6 @@ CoreFreeIoSpace ( IN UINT64 Length
);
-
/**
Removes reserved I/O or I/O resources from the global coherency domain of the
processor.
@@ -1982,7 +1873,6 @@ CoreRemoveIoSpace ( IN UINT64 Length
);
-
/**
Retrieves the descriptor for an I/O region containing a specified address.
@@ -2000,7 +1890,6 @@ CoreGetIoSpaceDescriptor ( OUT EFI_GCD_IO_SPACE_DESCRIPTOR *Descriptor
);
-
/**
Returns a map of the I/O resources in the global coherency domain of the processor.
@@ -2019,7 +1908,6 @@ CoreGetIoSpaceMap ( OUT EFI_GCD_IO_SPACE_DESCRIPTOR **IoSpaceMap
);
-
/**
This is the main Dispatcher for DXE and it exits when there are no more
drivers to run. Drain the mScheduledQueue and load and start a PE
@@ -2061,7 +1949,6 @@ CoreSchedule ( IN EFI_GUID *DriverName
);
-
/**
Convert a driver from the Untrused back to the Scheduled state.
@@ -2081,7 +1968,6 @@ CoreTrust ( IN EFI_GUID *DriverName
);
-
/**
This routine is the driver initialization entry point. It initializes the
libraries, and registers two notification functions. These notification
@@ -2096,11 +1982,10 @@ CoreTrust ( EFI_STATUS
EFIAPI
FwVolDriverInit (
- IN EFI_HANDLE ImageHandle,
- IN EFI_SYSTEM_TABLE *SystemTable
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
);
-
/**
Entry point of the section extraction code. Initializes an instance of the
section extraction interface and installs it on a new handle.
@@ -2115,11 +2000,10 @@ FwVolDriverInit ( EFI_STATUS
EFIAPI
InitializeSectionExtraction (
- IN EFI_HANDLE ImageHandle,
- IN EFI_SYSTEM_TABLE *SystemTable
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
);
-
/**
This DXE service routine is used to process a firmware volume. In
particular, it can be called by BDS to process a single firmware
@@ -2140,13 +2024,13 @@ InitializeSectionExtraction ( EFI_STATUS
EFIAPI
CoreProcessFirmwareVolume (
- IN VOID *FvHeader,
- IN UINTN Size,
- OUT EFI_HANDLE *FVProtocolHandle
+ IN VOID *FvHeader,
+ IN UINTN Size,
+ OUT EFI_HANDLE *FVProtocolHandle
);
//
-//Functions used during debug buils
+// Functions used during debug buils
//
/**
@@ -2159,7 +2043,6 @@ CoreDisplayMissingArchProtocols ( VOID
);
-
/**
Traverse the discovered list for any drivers that were discovered but not loaded
because the dependency experessions evaluated to false.
@@ -2170,8 +2053,6 @@ CoreDisplayDiscoveredNotDispatched ( VOID
);
-
-
/**
Place holder function until all the Boot Services and Runtime Services are
available.
@@ -2184,10 +2065,9 @@ CoreDisplayDiscoveredNotDispatched ( EFI_STATUS
EFIAPI
CoreEfiNotAvailableYetArg1 (
- UINTN Arg1
+ UINTN Arg1
);
-
/**
Place holder function until all the Boot Services and Runtime Services are available.
@@ -2200,11 +2080,10 @@ CoreEfiNotAvailableYetArg1 ( EFI_STATUS
EFIAPI
CoreEfiNotAvailableYetArg2 (
- UINTN Arg1,
- UINTN Arg2
+ UINTN Arg1,
+ UINTN Arg2
);
-
/**
Place holder function until all the Boot Services and Runtime Services are available.
@@ -2218,12 +2097,11 @@ CoreEfiNotAvailableYetArg2 ( EFI_STATUS
EFIAPI
CoreEfiNotAvailableYetArg3 (
- UINTN Arg1,
- UINTN Arg2,
- UINTN Arg3
+ UINTN Arg1,
+ UINTN Arg2,
+ UINTN Arg3
);
-
/**
Place holder function until all the Boot Services and Runtime Services are available.
@@ -2238,13 +2116,12 @@ CoreEfiNotAvailableYetArg3 ( EFI_STATUS
EFIAPI
CoreEfiNotAvailableYetArg4 (
- UINTN Arg1,
- UINTN Arg2,
- UINTN Arg3,
- UINTN Arg4
+ UINTN Arg1,
+ UINTN Arg2,
+ UINTN Arg3,
+ UINTN Arg4
);
-
/**
Place holder function until all the Boot Services and Runtime Services are available.
@@ -2260,14 +2137,13 @@ CoreEfiNotAvailableYetArg4 ( EFI_STATUS
EFIAPI
CoreEfiNotAvailableYetArg5 (
- UINTN Arg1,
- UINTN Arg2,
- UINTN Arg3,
- UINTN Arg4,
- UINTN Arg5
+ UINTN Arg1,
+ UINTN Arg2,
+ UINTN Arg3,
+ UINTN Arg4,
+ UINTN Arg5
);
-
/**
Given a compressed source buffer, this function retrieves the size of the
uncompressed buffer and the size of the scratch buffer required to decompress
@@ -2310,14 +2186,13 @@ CoreEfiNotAvailableYetArg5 ( EFI_STATUS
EFIAPI
DxeMainUefiDecompressGetInfo (
- IN EFI_DECOMPRESS_PROTOCOL *This,
- IN VOID *Source,
- IN UINT32 SourceSize,
- OUT UINT32 *DestinationSize,
- OUT UINT32 *ScratchSize
+ IN EFI_DECOMPRESS_PROTOCOL *This,
+ IN VOID *Source,
+ IN UINT32 SourceSize,
+ OUT UINT32 *DestinationSize,
+ OUT UINT32 *ScratchSize
);
-
/**
Decompresses a compressed source buffer.
@@ -2355,13 +2230,13 @@ DxeMainUefiDecompressGetInfo ( EFI_STATUS
EFIAPI
DxeMainUefiDecompress (
- IN EFI_DECOMPRESS_PROTOCOL *This,
- IN VOID *Source,
- IN UINT32 SourceSize,
- IN OUT VOID *Destination,
- IN UINT32 DestinationSize,
- IN OUT VOID *Scratch,
- IN UINT32 ScratchSize
+ IN EFI_DECOMPRESS_PROTOCOL *This,
+ IN VOID *Source,
+ IN UINT32 SourceSize,
+ IN OUT VOID *Destination,
+ IN UINT32 DestinationSize,
+ IN OUT VOID *Scratch,
+ IN UINT32 ScratchSize
);
/**
@@ -2382,13 +2257,11 @@ DxeMainUefiDecompress ( EFI_STATUS
EFIAPI
OpenSectionStream (
- IN UINTN SectionStreamLength,
- IN VOID *SectionStream,
- OUT UINTN *SectionStreamHandle
+ IN UINTN SectionStreamLength,
+ IN VOID *SectionStream,
+ OUT UINTN *SectionStreamHandle
);
-
-
/**
SEP member function. Retrieves requested section from section stream.
@@ -2450,17 +2323,16 @@ OpenSectionStream ( EFI_STATUS
EFIAPI
GetSection (
- IN UINTN SectionStreamHandle,
- IN EFI_SECTION_TYPE *SectionType,
- IN EFI_GUID *SectionDefinitionGuid,
- IN UINTN SectionInstance,
- IN VOID **Buffer,
- IN OUT UINTN *BufferSize,
- OUT UINT32 *AuthenticationStatus,
- IN BOOLEAN IsFfs3Fv
+ IN UINTN SectionStreamHandle,
+ IN EFI_SECTION_TYPE *SectionType,
+ IN EFI_GUID *SectionDefinitionGuid,
+ IN UINTN SectionInstance,
+ IN VOID **Buffer,
+ IN OUT UINTN *BufferSize,
+ OUT UINT32 *AuthenticationStatus,
+ IN BOOLEAN IsFfs3Fv
);
-
/**
SEP member function. Deletes an existing section stream
@@ -2477,8 +2349,8 @@ GetSection ( EFI_STATUS
EFIAPI
CloseSectionStream (
- IN UINTN StreamHandleToClose,
- IN BOOLEAN FreeStreamBuffer
+ IN UINTN StreamHandleToClose,
+ IN BOOLEAN FreeStreamBuffer
);
/**
@@ -2497,7 +2369,6 @@ CoreInitializeDebugImageInfoTable ( VOID
);
-
/**
Update the CRC32 in the Debug Table.
Since the CRC32 service is made available by the Runtime driver, we have to
@@ -2511,7 +2382,6 @@ CoreUpdateDebugTableCrc32 ( VOID
);
-
/**
Adds a new DebugImageInfo structure to the DebugImageInfo Table. Re-Allocates
the table if it's not large enough to accomidate another entry.
@@ -2524,12 +2394,11 @@ CoreUpdateDebugTableCrc32 ( **/
VOID
CoreNewDebugImageInfoEntry (
- IN UINT32 ImageInfoType,
- IN EFI_LOADED_IMAGE_PROTOCOL *LoadedImage,
- IN EFI_HANDLE ImageHandle
+ IN UINT32 ImageInfoType,
+ IN EFI_LOADED_IMAGE_PROTOCOL *LoadedImage,
+ IN EFI_HANDLE ImageHandle
);
-
/**
Removes and frees an entry from the DebugImageInfo Table.
@@ -2538,10 +2407,9 @@ CoreNewDebugImageInfoEntry ( **/
VOID
CoreRemoveDebugImageInfoEntry (
- EFI_HANDLE ImageHandle
+ EFI_HANDLE ImageHandle
);
-
/**
This routine consumes FV hobs and produces instances of FW_VOL_BLOCK_PROTOCOL as appropriate.
@@ -2555,8 +2423,8 @@ CoreRemoveDebugImageInfoEntry ( EFI_STATUS
EFIAPI
FwVolBlockDriverInit (
- IN EFI_HANDLE ImageHandle,
- IN EFI_SYSTEM_TABLE *SystemTable
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
);
/**
@@ -2570,7 +2438,7 @@ FwVolBlockDriverInit ( **/
UINT32
GetFvbAuthenticationStatus (
- IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *FvbProtocol
+ IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *FvbProtocol
);
/**
@@ -2594,14 +2462,13 @@ GetFvbAuthenticationStatus ( **/
EFI_STATUS
ProduceFVBProtocolOnBuffer (
- IN EFI_PHYSICAL_ADDRESS BaseAddress,
- IN UINT64 Length,
- IN EFI_HANDLE ParentHandle,
- IN UINT32 AuthenticationStatus,
- OUT EFI_HANDLE *FvProtocol OPTIONAL
+ IN EFI_PHYSICAL_ADDRESS BaseAddress,
+ IN UINT64 Length,
+ IN EFI_HANDLE ParentHandle,
+ IN UINT32 AuthenticationStatus,
+ OUT EFI_HANDLE *FvProtocol OPTIONAL
);
-
/**
Raising to the task priority level of the mutual exclusion
lock, and then acquires ownership of the lock.
@@ -2616,7 +2483,6 @@ CoreAcquireLock ( IN EFI_LOCK *Lock
);
-
/**
Initialize a basic mutual exclusion lock. Each lock
provides mutual exclusion access at it's task priority
@@ -2635,7 +2501,6 @@ CoreAcquireLockOrFail ( IN EFI_LOCK *Lock
);
-
/**
Releases ownership of the mutual exclusion lock, and
restores the previous task priority level.
@@ -2669,11 +2534,11 @@ CoreReleaseLock ( **/
EFI_STATUS
ReadFvbData (
- IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *Fvb,
- IN OUT EFI_LBA *StartLba,
- IN OUT UINTN *Offset,
- IN UINTN DataSize,
- OUT UINT8 *Data
+ IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *Fvb,
+ IN OUT EFI_LBA *StartLba,
+ IN OUT UINTN *Offset,
+ IN UINTN DataSize,
+ OUT UINT8 *Data
);
/**
@@ -2694,8 +2559,8 @@ ReadFvbData ( **/
EFI_STATUS
GetFwVolHeader (
- IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *Fvb,
- OUT EFI_FIRMWARE_VOLUME_HEADER **FwVolHeader
+ IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *Fvb,
+ OUT EFI_FIRMWARE_VOLUME_HEADER **FwVolHeader
);
/**
@@ -2709,7 +2574,7 @@ GetFwVolHeader ( **/
BOOLEAN
VerifyFvHeaderChecksum (
- IN EFI_FIRMWARE_VOLUME_HEADER *FvHeader
+ IN EFI_FIRMWARE_VOLUME_HEADER *FvHeader
);
/**
@@ -2720,7 +2585,7 @@ VerifyFvHeaderChecksum ( **/
VOID
MemoryProfileInit (
- IN VOID *HobStart
+ IN VOID *HobStart
);
/**
@@ -2840,7 +2705,7 @@ CoreInitializeMemoryProtection ( **/
VOID
InstallMemoryAttributesTableOnMemoryAllocation (
- IN EFI_MEMORY_TYPE MemoryType
+ IN EFI_MEMORY_TYPE MemoryType
);
/**
@@ -2871,8 +2736,8 @@ RemoveImageRecord ( **/
VOID
ProtectUefiImage (
- IN EFI_LOADED_IMAGE_PROTOCOL *LoadedImage,
- IN EFI_DEVICE_PATH_PROTOCOL *LoadedImageDevicePath
+ IN EFI_LOADED_IMAGE_PROTOCOL *LoadedImage,
+ IN EFI_DEVICE_PATH_PROTOCOL *LoadedImageDevicePath
);
/**
@@ -2883,8 +2748,8 @@ ProtectUefiImage ( **/
VOID
UnprotectUefiImage (
- IN EFI_LOADED_IMAGE_PROTOCOL *LoadedImage,
- IN EFI_DEVICE_PATH_PROTOCOL *LoadedImageDevicePath
+ IN EFI_LOADED_IMAGE_PROTOCOL *LoadedImage,
+ IN EFI_DEVICE_PATH_PROTOCOL *LoadedImageDevicePath
);
/**
diff --git a/MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c b/MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c index db21311f93..2c27fc0695 100644 --- a/MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c +++ b/MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c @@ -11,7 +11,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent //
// DXE Core Global Variables for Protocols from PEI
//
-EFI_HANDLE mDecompressHandle = NULL;
+EFI_HANDLE mDecompressHandle = NULL;
//
// DXE Core globals for Architecture Protocols
@@ -27,18 +27,18 @@ EFI_WATCHDOG_TIMER_ARCH_PROTOCOL *gWatchdogTimer = NULL; //
// DXE Core globals for optional protocol dependencies
//
-EFI_SMM_BASE2_PROTOCOL *gSmmBase2 = NULL;
+EFI_SMM_BASE2_PROTOCOL *gSmmBase2 = NULL;
//
// DXE Core Global used to update core loaded image protocol handle
//
-EFI_GUID *gDxeCoreFileName;
-EFI_LOADED_IMAGE_PROTOCOL *gDxeCoreLoadedImage;
+EFI_GUID *gDxeCoreFileName;
+EFI_LOADED_IMAGE_PROTOCOL *gDxeCoreLoadedImage;
//
// DXE Core Module Variables
//
-EFI_BOOT_SERVICES mBootServices = {
+EFI_BOOT_SERVICES mBootServices = {
{
EFI_BOOT_SERVICES_SIGNATURE, // Signature
EFI_BOOT_SERVICES_REVISION, // Revision
@@ -46,81 +46,81 @@ EFI_BOOT_SERVICES mBootServices = { 0, // CRC32
0 // Reserved
},
- (EFI_RAISE_TPL) CoreRaiseTpl, // RaiseTPL
- (EFI_RESTORE_TPL) CoreRestoreTpl, // RestoreTPL
- (EFI_ALLOCATE_PAGES) CoreAllocatePages, // AllocatePages
- (EFI_FREE_PAGES) CoreFreePages, // FreePages
- (EFI_GET_MEMORY_MAP) CoreGetMemoryMap, // GetMemoryMap
- (EFI_ALLOCATE_POOL) CoreAllocatePool, // AllocatePool
- (EFI_FREE_POOL) CoreFreePool, // FreePool
- (EFI_CREATE_EVENT) CoreCreateEvent, // CreateEvent
- (EFI_SET_TIMER) CoreSetTimer, // SetTimer
- (EFI_WAIT_FOR_EVENT) CoreWaitForEvent, // WaitForEvent
- (EFI_SIGNAL_EVENT) CoreSignalEvent, // SignalEvent
- (EFI_CLOSE_EVENT) CoreCloseEvent, // CloseEvent
- (EFI_CHECK_EVENT) CoreCheckEvent, // CheckEvent
- (EFI_INSTALL_PROTOCOL_INTERFACE) CoreInstallProtocolInterface, // InstallProtocolInterface
- (EFI_REINSTALL_PROTOCOL_INTERFACE) CoreReinstallProtocolInterface, // ReinstallProtocolInterface
- (EFI_UNINSTALL_PROTOCOL_INTERFACE) CoreUninstallProtocolInterface, // UninstallProtocolInterface
- (EFI_HANDLE_PROTOCOL) CoreHandleProtocol, // HandleProtocol
- (VOID *) NULL, // Reserved
- (EFI_REGISTER_PROTOCOL_NOTIFY) CoreRegisterProtocolNotify, // RegisterProtocolNotify
- (EFI_LOCATE_HANDLE) CoreLocateHandle, // LocateHandle
- (EFI_LOCATE_DEVICE_PATH) CoreLocateDevicePath, // LocateDevicePath
- (EFI_INSTALL_CONFIGURATION_TABLE) CoreInstallConfigurationTable, // InstallConfigurationTable
- (EFI_IMAGE_LOAD) CoreLoadImage, // LoadImage
- (EFI_IMAGE_START) CoreStartImage, // StartImage
- (EFI_EXIT) CoreExit, // Exit
- (EFI_IMAGE_UNLOAD) CoreUnloadImage, // UnloadImage
- (EFI_EXIT_BOOT_SERVICES) CoreExitBootServices, // ExitBootServices
- (EFI_GET_NEXT_MONOTONIC_COUNT) CoreEfiNotAvailableYetArg1, // GetNextMonotonicCount
- (EFI_STALL) CoreStall, // Stall
- (EFI_SET_WATCHDOG_TIMER) CoreSetWatchdogTimer, // SetWatchdogTimer
- (EFI_CONNECT_CONTROLLER) CoreConnectController, // ConnectController
- (EFI_DISCONNECT_CONTROLLER) CoreDisconnectController, // DisconnectController
- (EFI_OPEN_PROTOCOL) CoreOpenProtocol, // OpenProtocol
- (EFI_CLOSE_PROTOCOL) CoreCloseProtocol, // CloseProtocol
- (EFI_OPEN_PROTOCOL_INFORMATION) CoreOpenProtocolInformation, // OpenProtocolInformation
- (EFI_PROTOCOLS_PER_HANDLE) CoreProtocolsPerHandle, // ProtocolsPerHandle
- (EFI_LOCATE_HANDLE_BUFFER) CoreLocateHandleBuffer, // LocateHandleBuffer
- (EFI_LOCATE_PROTOCOL) CoreLocateProtocol, // LocateProtocol
- (EFI_INSTALL_MULTIPLE_PROTOCOL_INTERFACES) CoreInstallMultipleProtocolInterfaces, // InstallMultipleProtocolInterfaces
- (EFI_UNINSTALL_MULTIPLE_PROTOCOL_INTERFACES) CoreUninstallMultipleProtocolInterfaces, // UninstallMultipleProtocolInterfaces
- (EFI_CALCULATE_CRC32) CoreEfiNotAvailableYetArg3, // CalculateCrc32
- (EFI_COPY_MEM) CopyMem, // CopyMem
- (EFI_SET_MEM) SetMem, // SetMem
- (EFI_CREATE_EVENT_EX) CoreCreateEventEx // CreateEventEx
+ (EFI_RAISE_TPL)CoreRaiseTpl, // RaiseTPL
+ (EFI_RESTORE_TPL)CoreRestoreTpl, // RestoreTPL
+ (EFI_ALLOCATE_PAGES)CoreAllocatePages, // AllocatePages
+ (EFI_FREE_PAGES)CoreFreePages, // FreePages
+ (EFI_GET_MEMORY_MAP)CoreGetMemoryMap, // GetMemoryMap
+ (EFI_ALLOCATE_POOL)CoreAllocatePool, // AllocatePool
+ (EFI_FREE_POOL)CoreFreePool, // FreePool
+ (EFI_CREATE_EVENT)CoreCreateEvent, // CreateEvent
+ (EFI_SET_TIMER)CoreSetTimer, // SetTimer
+ (EFI_WAIT_FOR_EVENT)CoreWaitForEvent, // WaitForEvent
+ (EFI_SIGNAL_EVENT)CoreSignalEvent, // SignalEvent
+ (EFI_CLOSE_EVENT)CoreCloseEvent, // CloseEvent
+ (EFI_CHECK_EVENT)CoreCheckEvent, // CheckEvent
+ (EFI_INSTALL_PROTOCOL_INTERFACE)CoreInstallProtocolInterface, // InstallProtocolInterface
+ (EFI_REINSTALL_PROTOCOL_INTERFACE)CoreReinstallProtocolInterface, // ReinstallProtocolInterface
+ (EFI_UNINSTALL_PROTOCOL_INTERFACE)CoreUninstallProtocolInterface, // UninstallProtocolInterface
+ (EFI_HANDLE_PROTOCOL)CoreHandleProtocol, // HandleProtocol
+ (VOID *)NULL, // Reserved
+ (EFI_REGISTER_PROTOCOL_NOTIFY)CoreRegisterProtocolNotify, // RegisterProtocolNotify
+ (EFI_LOCATE_HANDLE)CoreLocateHandle, // LocateHandle
+ (EFI_LOCATE_DEVICE_PATH)CoreLocateDevicePath, // LocateDevicePath
+ (EFI_INSTALL_CONFIGURATION_TABLE)CoreInstallConfigurationTable, // InstallConfigurationTable
+ (EFI_IMAGE_LOAD)CoreLoadImage, // LoadImage
+ (EFI_IMAGE_START)CoreStartImage, // StartImage
+ (EFI_EXIT)CoreExit, // Exit
+ (EFI_IMAGE_UNLOAD)CoreUnloadImage, // UnloadImage
+ (EFI_EXIT_BOOT_SERVICES)CoreExitBootServices, // ExitBootServices
+ (EFI_GET_NEXT_MONOTONIC_COUNT)CoreEfiNotAvailableYetArg1, // GetNextMonotonicCount
+ (EFI_STALL)CoreStall, // Stall
+ (EFI_SET_WATCHDOG_TIMER)CoreSetWatchdogTimer, // SetWatchdogTimer
+ (EFI_CONNECT_CONTROLLER)CoreConnectController, // ConnectController
+ (EFI_DISCONNECT_CONTROLLER)CoreDisconnectController, // DisconnectController
+ (EFI_OPEN_PROTOCOL)CoreOpenProtocol, // OpenProtocol
+ (EFI_CLOSE_PROTOCOL)CoreCloseProtocol, // CloseProtocol
+ (EFI_OPEN_PROTOCOL_INFORMATION)CoreOpenProtocolInformation, // OpenProtocolInformation
+ (EFI_PROTOCOLS_PER_HANDLE)CoreProtocolsPerHandle, // ProtocolsPerHandle
+ (EFI_LOCATE_HANDLE_BUFFER)CoreLocateHandleBuffer, // LocateHandleBuffer
+ (EFI_LOCATE_PROTOCOL)CoreLocateProtocol, // LocateProtocol
+ (EFI_INSTALL_MULTIPLE_PROTOCOL_INTERFACES)CoreInstallMultipleProtocolInterfaces, // InstallMultipleProtocolInterfaces
+ (EFI_UNINSTALL_MULTIPLE_PROTOCOL_INTERFACES)CoreUninstallMultipleProtocolInterfaces, // UninstallMultipleProtocolInterfaces
+ (EFI_CALCULATE_CRC32)CoreEfiNotAvailableYetArg3, // CalculateCrc32
+ (EFI_COPY_MEM)CopyMem, // CopyMem
+ (EFI_SET_MEM)SetMem, // SetMem
+ (EFI_CREATE_EVENT_EX)CoreCreateEventEx // CreateEventEx
};
-EFI_DXE_SERVICES mDxeServices = {
+EFI_DXE_SERVICES mDxeServices = {
{
DXE_SERVICES_SIGNATURE, // Signature
DXE_SERVICES_REVISION, // Revision
sizeof (DXE_SERVICES), // HeaderSize
- 0, // CRC32
- 0 // Reserved
+ 0, // CRC32
+ 0 // Reserved
},
- (EFI_ADD_MEMORY_SPACE) CoreAddMemorySpace, // AddMemorySpace
- (EFI_ALLOCATE_MEMORY_SPACE) CoreAllocateMemorySpace, // AllocateMemorySpace
- (EFI_FREE_MEMORY_SPACE) CoreFreeMemorySpace, // FreeMemorySpace
- (EFI_REMOVE_MEMORY_SPACE) CoreRemoveMemorySpace, // RemoveMemorySpace
- (EFI_GET_MEMORY_SPACE_DESCRIPTOR) CoreGetMemorySpaceDescriptor, // GetMemorySpaceDescriptor
- (EFI_SET_MEMORY_SPACE_ATTRIBUTES) CoreSetMemorySpaceAttributes, // SetMemorySpaceAttributes
- (EFI_GET_MEMORY_SPACE_MAP) CoreGetMemorySpaceMap, // GetMemorySpaceMap
- (EFI_ADD_IO_SPACE) CoreAddIoSpace, // AddIoSpace
- (EFI_ALLOCATE_IO_SPACE) CoreAllocateIoSpace, // AllocateIoSpace
- (EFI_FREE_IO_SPACE) CoreFreeIoSpace, // FreeIoSpace
- (EFI_REMOVE_IO_SPACE) CoreRemoveIoSpace, // RemoveIoSpace
- (EFI_GET_IO_SPACE_DESCRIPTOR) CoreGetIoSpaceDescriptor, // GetIoSpaceDescriptor
- (EFI_GET_IO_SPACE_MAP) CoreGetIoSpaceMap, // GetIoSpaceMap
- (EFI_DISPATCH) CoreDispatcher, // Dispatch
- (EFI_SCHEDULE) CoreSchedule, // Schedule
- (EFI_TRUST) CoreTrust, // Trust
- (EFI_PROCESS_FIRMWARE_VOLUME) CoreProcessFirmwareVolume, // ProcessFirmwareVolume
+ (EFI_ADD_MEMORY_SPACE)CoreAddMemorySpace, // AddMemorySpace
+ (EFI_ALLOCATE_MEMORY_SPACE)CoreAllocateMemorySpace, // AllocateMemorySpace
+ (EFI_FREE_MEMORY_SPACE)CoreFreeMemorySpace, // FreeMemorySpace
+ (EFI_REMOVE_MEMORY_SPACE)CoreRemoveMemorySpace, // RemoveMemorySpace
+ (EFI_GET_MEMORY_SPACE_DESCRIPTOR)CoreGetMemorySpaceDescriptor, // GetMemorySpaceDescriptor
+ (EFI_SET_MEMORY_SPACE_ATTRIBUTES)CoreSetMemorySpaceAttributes, // SetMemorySpaceAttributes
+ (EFI_GET_MEMORY_SPACE_MAP)CoreGetMemorySpaceMap, // GetMemorySpaceMap
+ (EFI_ADD_IO_SPACE)CoreAddIoSpace, // AddIoSpace
+ (EFI_ALLOCATE_IO_SPACE)CoreAllocateIoSpace, // AllocateIoSpace
+ (EFI_FREE_IO_SPACE)CoreFreeIoSpace, // FreeIoSpace
+ (EFI_REMOVE_IO_SPACE)CoreRemoveIoSpace, // RemoveIoSpace
+ (EFI_GET_IO_SPACE_DESCRIPTOR)CoreGetIoSpaceDescriptor, // GetIoSpaceDescriptor
+ (EFI_GET_IO_SPACE_MAP)CoreGetIoSpaceMap, // GetIoSpaceMap
+ (EFI_DISPATCH)CoreDispatcher, // Dispatch
+ (EFI_SCHEDULE)CoreSchedule, // Schedule
+ (EFI_TRUST)CoreTrust, // Trust
+ (EFI_PROCESS_FIRMWARE_VOLUME)CoreProcessFirmwareVolume, // ProcessFirmwareVolume
(EFI_SET_MEMORY_SPACE_CAPABILITIES)CoreSetMemorySpaceCapabilities, // SetMemorySpaceCapabilities
};
-EFI_SYSTEM_TABLE mEfiSystemTableTemplate = {
+EFI_SYSTEM_TABLE mEfiSystemTableTemplate = {
{
EFI_SYSTEM_TABLE_SIGNATURE, // Signature
EFI_SYSTEM_TABLE_REVISION, // Revision
@@ -142,7 +142,7 @@ EFI_SYSTEM_TABLE mEfiSystemTableTemplate = { NULL // ConfigurationTable
};
-EFI_RUNTIME_SERVICES mEfiRuntimeServicesTableTemplate = {
+EFI_RUNTIME_SERVICES mEfiRuntimeServicesTableTemplate = {
{
EFI_RUNTIME_SERVICES_SIGNATURE, // Signature
EFI_RUNTIME_SERVICES_REVISION, // Revision
@@ -150,23 +150,23 @@ EFI_RUNTIME_SERVICES mEfiRuntimeServicesTableTemplate = { 0, // CRC32
0 // Reserved
},
- (EFI_GET_TIME) CoreEfiNotAvailableYetArg2, // GetTime
- (EFI_SET_TIME) CoreEfiNotAvailableYetArg1, // SetTime
- (EFI_GET_WAKEUP_TIME) CoreEfiNotAvailableYetArg3, // GetWakeupTime
- (EFI_SET_WAKEUP_TIME) CoreEfiNotAvailableYetArg2, // SetWakeupTime
- (EFI_SET_VIRTUAL_ADDRESS_MAP) CoreEfiNotAvailableYetArg4, // SetVirtualAddressMap
- (EFI_CONVERT_POINTER) CoreEfiNotAvailableYetArg2, // ConvertPointer
- (EFI_GET_VARIABLE) CoreEfiNotAvailableYetArg5, // GetVariable
- (EFI_GET_NEXT_VARIABLE_NAME) CoreEfiNotAvailableYetArg3, // GetNextVariableName
- (EFI_SET_VARIABLE) CoreEfiNotAvailableYetArg5, // SetVariable
- (EFI_GET_NEXT_HIGH_MONO_COUNT) CoreEfiNotAvailableYetArg1, // GetNextHighMonotonicCount
- (EFI_RESET_SYSTEM) CoreEfiNotAvailableYetArg4, // ResetSystem
- (EFI_UPDATE_CAPSULE) CoreEfiNotAvailableYetArg3, // UpdateCapsule
- (EFI_QUERY_CAPSULE_CAPABILITIES) CoreEfiNotAvailableYetArg4, // QueryCapsuleCapabilities
- (EFI_QUERY_VARIABLE_INFO) CoreEfiNotAvailableYetArg4 // QueryVariableInfo
+ (EFI_GET_TIME)CoreEfiNotAvailableYetArg2, // GetTime
+ (EFI_SET_TIME)CoreEfiNotAvailableYetArg1, // SetTime
+ (EFI_GET_WAKEUP_TIME)CoreEfiNotAvailableYetArg3, // GetWakeupTime
+ (EFI_SET_WAKEUP_TIME)CoreEfiNotAvailableYetArg2, // SetWakeupTime
+ (EFI_SET_VIRTUAL_ADDRESS_MAP)CoreEfiNotAvailableYetArg4, // SetVirtualAddressMap
+ (EFI_CONVERT_POINTER)CoreEfiNotAvailableYetArg2, // ConvertPointer
+ (EFI_GET_VARIABLE)CoreEfiNotAvailableYetArg5, // GetVariable
+ (EFI_GET_NEXT_VARIABLE_NAME)CoreEfiNotAvailableYetArg3, // GetNextVariableName
+ (EFI_SET_VARIABLE)CoreEfiNotAvailableYetArg5, // SetVariable
+ (EFI_GET_NEXT_HIGH_MONO_COUNT)CoreEfiNotAvailableYetArg1, // GetNextHighMonotonicCount
+ (EFI_RESET_SYSTEM)CoreEfiNotAvailableYetArg4, // ResetSystem
+ (EFI_UPDATE_CAPSULE)CoreEfiNotAvailableYetArg3, // UpdateCapsule
+ (EFI_QUERY_CAPSULE_CAPABILITIES)CoreEfiNotAvailableYetArg4, // QueryCapsuleCapabilities
+ (EFI_QUERY_VARIABLE_INFO)CoreEfiNotAvailableYetArg4 // QueryVariableInfo
};
-EFI_RUNTIME_ARCH_PROTOCOL gRuntimeTemplate = {
+EFI_RUNTIME_ARCH_PROTOCOL gRuntimeTemplate = {
INITIALIZE_LIST_HEAD_VARIABLE (gRuntimeTemplate.ImageHead),
INITIALIZE_LIST_HEAD_VARIABLE (gRuntimeTemplate.EventHead),
@@ -184,24 +184,24 @@ EFI_RUNTIME_ARCH_PROTOCOL gRuntimeTemplate = { FALSE
};
-EFI_RUNTIME_ARCH_PROTOCOL *gRuntime = &gRuntimeTemplate;
+EFI_RUNTIME_ARCH_PROTOCOL *gRuntime = &gRuntimeTemplate;
//
// DXE Core Global Variables for the EFI System Table, Boot Services Table,
// DXE Services Table, and Runtime Services Table
//
-EFI_DXE_SERVICES *gDxeCoreDS = &mDxeServices;
-EFI_SYSTEM_TABLE *gDxeCoreST = NULL;
+EFI_DXE_SERVICES *gDxeCoreDS = &mDxeServices;
+EFI_SYSTEM_TABLE *gDxeCoreST = NULL;
//
// For debug initialize gDxeCoreRT to template. gDxeCoreRT must be allocated from RT memory
// but gDxeCoreRT is used for ASSERT () and DEBUG () type macros so lets give it
// a value that will not cause debug infrastructure to crash early on.
//
-EFI_RUNTIME_SERVICES *gDxeCoreRT = &mEfiRuntimeServicesTableTemplate;
+EFI_RUNTIME_SERVICES *gDxeCoreRT = &mEfiRuntimeServicesTableTemplate;
EFI_HANDLE gDxeCoreImageHandle = NULL;
-BOOLEAN gMemoryMapTerminated = FALSE;
+BOOLEAN gMemoryMapTerminated = FALSE;
//
// EFI Decompress Protocol
@@ -215,7 +215,7 @@ EFI_DECOMPRESS_PROTOCOL gEfiDecompress = { // For Loading modules at fixed address feature, the configuration table is to cache the top address below which to load
// Runtime code&boot time code
//
-GLOBAL_REMOVE_IF_UNREFERENCED EFI_LOAD_FIXED_ADDRESS_CONFIGURATION_TABLE gLoadModuleAtFixAddressConfigurationTable = {0, 0};
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_LOAD_FIXED_ADDRESS_CONFIGURATION_TABLE gLoadModuleAtFixAddressConfigurationTable = { 0, 0 };
// Main entry point to the DXE Core
//
@@ -231,7 +231,7 @@ GLOBAL_REMOVE_IF_UNREFERENCED EFI_LOAD_FIXED_ADDRESS_CONFIGURATION_TABLE gLoa VOID
EFIAPI
DxeMain (
- IN VOID *HobStart
+ IN VOID *HobStart
)
{
EFI_STATUS Status;
@@ -248,10 +248,11 @@ DxeMain ( // Setup the default exception handlers
//
VectorInfoList = NULL;
- GuidHob = GetNextGuidHob (&gEfiVectorHandoffInfoPpiGuid, HobStart);
+ GuidHob = GetNextGuidHob (&gEfiVectorHandoffInfoPpiGuid, HobStart);
if (GuidHob != NULL) {
- VectorInfoList = (EFI_VECTOR_HANDOFF_INFO *) (GET_GUID_HOB_DATA(GuidHob));
+ VectorInfoList = (EFI_VECTOR_HANDOFF_INFO *)(GET_GUID_HOB_DATA (GuidHob));
}
+
Status = InitializeCpuExceptionHandlersEx (VectorInfoList, NULL);
ASSERT_EFI_ERROR (Status);
@@ -295,7 +296,7 @@ DxeMain ( // Call constructor for all libraries
//
ProcessLibraryConstructorList (gDxeCoreImageHandle, gDxeCoreST);
- PERF_CROSSMODULE_END ("PEI");
+ PERF_CROSSMODULE_END ("PEI");
PERF_CROSSMODULE_BEGIN ("DXE");
//
@@ -303,22 +304,28 @@ DxeMain ( // CoreInitializeMemoryServices()), now that library constructors have
// executed.
//
- DEBUG ((DEBUG_INFO, "%a: MemoryBaseAddress=0x%Lx MemoryLength=0x%Lx\n",
- __FUNCTION__, MemoryBaseAddress, MemoryLength));
+ DEBUG ((
+ DEBUG_INFO,
+ "%a: MemoryBaseAddress=0x%Lx MemoryLength=0x%Lx\n",
+ __FUNCTION__,
+ MemoryBaseAddress,
+ MemoryLength
+ ));
//
// Report DXE Core image information to the PE/COFF Extra Action Library
//
ZeroMem (&ImageContext, sizeof (ImageContext));
- ImageContext.ImageAddress = (EFI_PHYSICAL_ADDRESS)(UINTN)gDxeCoreLoadedImage->ImageBase;
- ImageContext.PdbPointer = PeCoffLoaderGetPdbPointer ((VOID*)(UINTN)ImageContext.ImageAddress);
- ImageContext.SizeOfHeaders = PeCoffGetSizeOfHeaders ((VOID*)(UINTN)ImageContext.ImageAddress);
- Status = PeCoffLoaderGetEntryPoint ((VOID*)(UINTN)ImageContext.ImageAddress, &EntryPoint);
+ ImageContext.ImageAddress = (EFI_PHYSICAL_ADDRESS)(UINTN)gDxeCoreLoadedImage->ImageBase;
+ ImageContext.PdbPointer = PeCoffLoaderGetPdbPointer ((VOID *)(UINTN)ImageContext.ImageAddress);
+ ImageContext.SizeOfHeaders = PeCoffGetSizeOfHeaders ((VOID *)(UINTN)ImageContext.ImageAddress);
+ Status = PeCoffLoaderGetEntryPoint ((VOID *)(UINTN)ImageContext.ImageAddress, &EntryPoint);
if (Status == EFI_SUCCESS) {
ImageContext.EntryPoint = (EFI_PHYSICAL_ADDRESS)(UINTN)EntryPoint;
}
- ImageContext.Handle = (VOID *)(UINTN)gDxeCoreLoadedImage->ImageBase;
- ImageContext.ImageRead = PeCoffLoaderImageReadFromMemory;
+
+ ImageContext.Handle = (VOID *)(UINTN)gDxeCoreLoadedImage->ImageBase;
+ ImageContext.ImageRead = PeCoffLoaderImageReadFromMemory;
PeCoffLoaderRelocateImageExtraAction (&ImageContext);
//
@@ -344,10 +351,11 @@ DxeMain ( // Configuration Table so that user could easily to retrieve the top address to load Dxe and PEI
// Code and Tseg base to load SMM driver.
//
- if (PcdGet64(PcdLoadModuleAtFixAddressEnable) != 0) {
+ if (PcdGet64 (PcdLoadModuleAtFixAddressEnable) != 0) {
Status = CoreInstallConfigurationTable (&gLoadFixedAddressConfigurationTableGuid, &gLoadModuleAtFixAddressConfigurationTable);
ASSERT_EFI_ERROR (Status);
}
+
//
// Report Status Code here for DXE_ENTRY_POINT once it is available
//
@@ -371,56 +379,61 @@ DxeMain ( DEBUG ((DEBUG_INFO | DEBUG_LOAD, "HOBLIST address in DXE = 0x%p\n", HobStart));
DEBUG_CODE_BEGIN ();
- EFI_PEI_HOB_POINTERS Hob;
-
- for (Hob.Raw = HobStart; !END_OF_HOB_LIST(Hob); Hob.Raw = GET_NEXT_HOB(Hob)) {
- if (GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_MEMORY_ALLOCATION) {
- DEBUG ((DEBUG_INFO | DEBUG_LOAD, "Memory Allocation 0x%08x 0x%0lx - 0x%0lx\n", \
- Hob.MemoryAllocation->AllocDescriptor.MemoryType, \
- Hob.MemoryAllocation->AllocDescriptor.MemoryBaseAddress, \
- Hob.MemoryAllocation->AllocDescriptor.MemoryBaseAddress + Hob.MemoryAllocation->AllocDescriptor.MemoryLength - 1));
- }
+ EFI_PEI_HOB_POINTERS Hob;
+
+ for (Hob.Raw = HobStart; !END_OF_HOB_LIST (Hob); Hob.Raw = GET_NEXT_HOB (Hob)) {
+ if (GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_MEMORY_ALLOCATION) {
+ DEBUG ((
+ DEBUG_INFO | DEBUG_LOAD,
+ "Memory Allocation 0x%08x 0x%0lx - 0x%0lx\n", \
+ Hob.MemoryAllocation->AllocDescriptor.MemoryType, \
+ Hob.MemoryAllocation->AllocDescriptor.MemoryBaseAddress, \
+ Hob.MemoryAllocation->AllocDescriptor.MemoryBaseAddress + Hob.MemoryAllocation->AllocDescriptor.MemoryLength - 1
+ ));
}
- for (Hob.Raw = HobStart; !END_OF_HOB_LIST(Hob); Hob.Raw = GET_NEXT_HOB(Hob)) {
- if (GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_FV) {
- DEBUG ((
- DEBUG_INFO | DEBUG_LOAD,
- "FV Hob 0x%0lx - 0x%0lx\n",
- Hob.FirmwareVolume->BaseAddress,
- Hob.FirmwareVolume->BaseAddress + Hob.FirmwareVolume->Length - 1
- ));
- } else if (GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_FV2) {
- DEBUG ((
- DEBUG_INFO | DEBUG_LOAD,
- "FV2 Hob 0x%0lx - 0x%0lx\n",
- Hob.FirmwareVolume2->BaseAddress,
- Hob.FirmwareVolume2->BaseAddress + Hob.FirmwareVolume2->Length - 1
- ));
+ }
+
+ for (Hob.Raw = HobStart; !END_OF_HOB_LIST (Hob); Hob.Raw = GET_NEXT_HOB (Hob)) {
+ if (GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_FV) {
+ DEBUG ((
+ DEBUG_INFO | DEBUG_LOAD,
+ "FV Hob 0x%0lx - 0x%0lx\n",
+ Hob.FirmwareVolume->BaseAddress,
+ Hob.FirmwareVolume->BaseAddress + Hob.FirmwareVolume->Length - 1
+ ));
+ } else if (GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_FV2) {
+ DEBUG ((
+ DEBUG_INFO | DEBUG_LOAD,
+ "FV2 Hob 0x%0lx - 0x%0lx\n",
+ Hob.FirmwareVolume2->BaseAddress,
+ Hob.FirmwareVolume2->BaseAddress + Hob.FirmwareVolume2->Length - 1
+ ));
+ DEBUG ((
+ DEBUG_INFO | DEBUG_LOAD,
+ " %g - %g\n",
+ &Hob.FirmwareVolume2->FvName,
+ &Hob.FirmwareVolume2->FileName
+ ));
+ } else if (GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_FV3) {
+ DEBUG ((
+ DEBUG_INFO | DEBUG_LOAD,
+ "FV3 Hob 0x%0lx - 0x%0lx - 0x%x - 0x%x\n",
+ Hob.FirmwareVolume3->BaseAddress,
+ Hob.FirmwareVolume3->BaseAddress + Hob.FirmwareVolume3->Length - 1,
+ Hob.FirmwareVolume3->AuthenticationStatus,
+ Hob.FirmwareVolume3->ExtractedFv
+ ));
+ if (Hob.FirmwareVolume3->ExtractedFv) {
DEBUG ((
DEBUG_INFO | DEBUG_LOAD,
" %g - %g\n",
- &Hob.FirmwareVolume2->FvName,
- &Hob.FirmwareVolume2->FileName
- ));
- } else if (GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_FV3) {
- DEBUG ((
- DEBUG_INFO | DEBUG_LOAD,
- "FV3 Hob 0x%0lx - 0x%0lx - 0x%x - 0x%x\n",
- Hob.FirmwareVolume3->BaseAddress,
- Hob.FirmwareVolume3->BaseAddress + Hob.FirmwareVolume3->Length - 1,
- Hob.FirmwareVolume3->AuthenticationStatus,
- Hob.FirmwareVolume3->ExtractedFv
+ &Hob.FirmwareVolume3->FvName,
+ &Hob.FirmwareVolume3->FileName
));
- if (Hob.FirmwareVolume3->ExtractedFv) {
- DEBUG ((
- DEBUG_INFO | DEBUG_LOAD,
- " %g - %g\n",
- &Hob.FirmwareVolume3->FvName,
- &Hob.FirmwareVolume3->FileName
- ));
- }
}
}
+ }
+
DEBUG_CODE_END ();
//
@@ -440,16 +453,17 @@ DxeMain ( //
GuidHob = GetNextGuidHob (&gEfiVectorHandoffInfoPpiGuid, HobStart);
if (GuidHob != NULL) {
- VectorInfoList = (EFI_VECTOR_HANDOFF_INFO *) (GET_GUID_HOB_DATA(GuidHob));
- VectorInfo = VectorInfoList;
- Index = 1;
+ VectorInfoList = (EFI_VECTOR_HANDOFF_INFO *)(GET_GUID_HOB_DATA (GuidHob));
+ VectorInfo = VectorInfoList;
+ Index = 1;
while (VectorInfo->Attribute != EFI_VECTOR_HANDOFF_LAST_ENTRY) {
- VectorInfo ++;
- Index ++;
+ VectorInfo++;
+ Index++;
}
- VectorInfo = AllocateCopyPool (sizeof (EFI_VECTOR_HANDOFF_INFO) * Index, (VOID *) VectorInfoList);
+
+ VectorInfo = AllocateCopyPool (sizeof (EFI_VECTOR_HANDOFF_INFO) * Index, (VOID *)VectorInfoList);
ASSERT (VectorInfo != NULL);
- Status = CoreInstallConfigurationTable (&gEfiVectorHandoffTableGuid, (VOID *) VectorInfo);
+ Status = CoreInstallConfigurationTable (&gEfiVectorHandoffTableGuid, (VOID *)VectorInfo);
ASSERT_EFI_ERROR (Status);
}
@@ -470,7 +484,8 @@ DxeMain ( //
Status = CoreInstallMultipleProtocolInterfaces (
&mDecompressHandle,
- &gEfiDecompressProtocolGuid, &gEfiDecompress,
+ &gEfiDecompressProtocolGuid,
+ &gEfiDecompress,
NULL
);
ASSERT_EFI_ERROR (Status);
@@ -511,7 +526,7 @@ DxeMain ( // Display Architectural protocols that were not loaded if this is DEBUG build
//
DEBUG_CODE_BEGIN ();
- CoreDisplayMissingArchProtocols ();
+ CoreDisplayMissingArchProtocols ();
DEBUG_CODE_END ();
//
@@ -519,14 +534,14 @@ DxeMain ( // evaluated to false if this is a debug build
//
DEBUG_CODE_BEGIN ();
- CoreDisplayDiscoveredNotDispatched ();
+ CoreDisplayDiscoveredNotDispatched ();
DEBUG_CODE_END ();
//
// Assert if the Architectural Protocols are not present.
//
Status = CoreAllEfiServicesAvailable ();
- if (EFI_ERROR(Status)) {
+ if (EFI_ERROR (Status)) {
//
// Report Status code that some Architectural Protocols are not present.
//
@@ -535,6 +550,7 @@ DxeMain ( (EFI_SOFTWARE_DXE_CORE | EFI_SW_DXE_CORE_EC_NO_ARCH)
);
}
+
ASSERT_EFI_ERROR (Status);
//
@@ -559,9 +575,6 @@ DxeMain ( UNREACHABLE ();
}
-
-
-
/**
Place holder function until all the Boot Services and Runtime Services are
available.
@@ -574,7 +587,7 @@ DxeMain ( EFI_STATUS
EFIAPI
CoreEfiNotAvailableYetArg1 (
- UINTN Arg1
+ UINTN Arg1
)
{
//
@@ -586,7 +599,6 @@ CoreEfiNotAvailableYetArg1 ( return EFI_NOT_AVAILABLE_YET;
}
-
/**
Place holder function until all the Boot Services and Runtime Services are available.
@@ -599,8 +611,8 @@ CoreEfiNotAvailableYetArg1 ( EFI_STATUS
EFIAPI
CoreEfiNotAvailableYetArg2 (
- UINTN Arg1,
- UINTN Arg2
+ UINTN Arg1,
+ UINTN Arg2
)
{
//
@@ -612,7 +624,6 @@ CoreEfiNotAvailableYetArg2 ( return EFI_NOT_AVAILABLE_YET;
}
-
/**
Place holder function until all the Boot Services and Runtime Services are available.
@@ -626,9 +637,9 @@ CoreEfiNotAvailableYetArg2 ( EFI_STATUS
EFIAPI
CoreEfiNotAvailableYetArg3 (
- UINTN Arg1,
- UINTN Arg2,
- UINTN Arg3
+ UINTN Arg1,
+ UINTN Arg2,
+ UINTN Arg3
)
{
//
@@ -640,7 +651,6 @@ CoreEfiNotAvailableYetArg3 ( return EFI_NOT_AVAILABLE_YET;
}
-
/**
Place holder function until all the Boot Services and Runtime Services are available.
@@ -655,10 +665,10 @@ CoreEfiNotAvailableYetArg3 ( EFI_STATUS
EFIAPI
CoreEfiNotAvailableYetArg4 (
- UINTN Arg1,
- UINTN Arg2,
- UINTN Arg3,
- UINTN Arg4
+ UINTN Arg1,
+ UINTN Arg2,
+ UINTN Arg3,
+ UINTN Arg4
)
{
//
@@ -670,7 +680,6 @@ CoreEfiNotAvailableYetArg4 ( return EFI_NOT_AVAILABLE_YET;
}
-
/**
Place holder function until all the Boot Services and Runtime Services are available.
@@ -686,11 +695,11 @@ CoreEfiNotAvailableYetArg4 ( EFI_STATUS
EFIAPI
CoreEfiNotAvailableYetArg5 (
- UINTN Arg1,
- UINTN Arg2,
- UINTN Arg3,
- UINTN Arg4,
- UINTN Arg5
+ UINTN Arg1,
+ UINTN Arg2,
+ UINTN Arg3,
+ UINTN Arg4,
+ UINTN Arg5
)
{
//
@@ -702,7 +711,6 @@ CoreEfiNotAvailableYetArg5 ( return EFI_NOT_AVAILABLE_YET;
}
-
/**
Calcualte the 32-bit CRC in a EFI table using the service provided by the
gRuntime service.
@@ -712,10 +720,10 @@ CoreEfiNotAvailableYetArg5 ( **/
VOID
CalculateEfiHdrCrc (
- IN OUT EFI_TABLE_HEADER *Hdr
+ IN OUT EFI_TABLE_HEADER *Hdr
)
{
- UINT32 Crc;
+ UINT32 Crc;
Hdr->CRC32 = 0;
@@ -728,7 +736,6 @@ CalculateEfiHdrCrc ( Hdr->CRC32 = Crc;
}
-
/**
Terminates all boot services.
@@ -742,11 +749,11 @@ CalculateEfiHdrCrc ( EFI_STATUS
EFIAPI
CoreExitBootServices (
- IN EFI_HANDLE ImageHandle,
- IN UINTN MapKey
+ IN EFI_HANDLE ImageHandle,
+ IN UINTN MapKey
)
{
- EFI_STATUS Status;
+ EFI_STATUS Status;
//
// Disable Timer
@@ -780,7 +787,7 @@ CoreExitBootServices ( (EFI_SOFTWARE_EFI_BOOT_SERVICE | EFI_SW_BS_PC_EXIT_BOOT_SERVICES)
);
- MemoryProtectionExitBootServicesCallback();
+ MemoryProtectionExitBootServicesCallback ();
//
// Disable interrupt of Debug timer.
@@ -822,7 +829,6 @@ CoreExitBootServices ( return Status;
}
-
/**
Given a compressed source buffer, this function retrieves the size of the
uncompressed buffer and the size of the scratch buffer required to decompress
@@ -865,20 +871,20 @@ CoreExitBootServices ( EFI_STATUS
EFIAPI
DxeMainUefiDecompressGetInfo (
- IN EFI_DECOMPRESS_PROTOCOL *This,
- IN VOID *Source,
- IN UINT32 SourceSize,
- OUT UINT32 *DestinationSize,
- OUT UINT32 *ScratchSize
+ IN EFI_DECOMPRESS_PROTOCOL *This,
+ IN VOID *Source,
+ IN UINT32 SourceSize,
+ OUT UINT32 *DestinationSize,
+ OUT UINT32 *ScratchSize
)
{
- if (Source == NULL || DestinationSize == NULL || ScratchSize == NULL) {
+ if ((Source == NULL) || (DestinationSize == NULL) || (ScratchSize == NULL)) {
return EFI_INVALID_PARAMETER;
}
+
return UefiDecompressGetInfo (Source, SourceSize, DestinationSize, ScratchSize);
}
-
/**
Decompresses a compressed source buffer.
@@ -916,20 +922,20 @@ DxeMainUefiDecompressGetInfo ( EFI_STATUS
EFIAPI
DxeMainUefiDecompress (
- IN EFI_DECOMPRESS_PROTOCOL *This,
- IN VOID *Source,
- IN UINT32 SourceSize,
- IN OUT VOID *Destination,
- IN UINT32 DestinationSize,
- IN OUT VOID *Scratch,
- IN UINT32 ScratchSize
+ IN EFI_DECOMPRESS_PROTOCOL *This,
+ IN VOID *Source,
+ IN UINT32 SourceSize,
+ IN OUT VOID *Destination,
+ IN UINT32 DestinationSize,
+ IN OUT VOID *Scratch,
+ IN UINT32 ScratchSize
)
{
EFI_STATUS Status;
UINT32 TestDestinationSize;
UINT32 TestScratchSize;
- if (Source == NULL || Destination== NULL || Scratch == NULL) {
+ if ((Source == NULL) || (Destination == NULL) || (Scratch == NULL)) {
return EFI_INVALID_PARAMETER;
}
@@ -938,7 +944,7 @@ DxeMainUefiDecompress ( return Status;
}
- if (ScratchSize < TestScratchSize || DestinationSize < TestDestinationSize) {
+ if ((ScratchSize < TestScratchSize) || (DestinationSize < TestDestinationSize)) {
return RETURN_INVALID_PARAMETER;
}
diff --git a/MdeModulePkg/Core/Dxe/DxeMain/DxeProtocolNotify.c b/MdeModulePkg/Core/Dxe/DxeMain/DxeProtocolNotify.c index 29a55d02e6..3fe02940ed 100644 --- a/MdeModulePkg/Core/Dxe/DxeMain/DxeProtocolNotify.c +++ b/MdeModulePkg/Core/Dxe/DxeMain/DxeProtocolNotify.c @@ -39,34 +39,34 @@ EFI_CORE_PROTOCOL_NOTIFY_ENTRY mArchProtocols[] = { // Optional protocols that the DXE Core will use if they are present
//
EFI_CORE_PROTOCOL_NOTIFY_ENTRY mOptionalProtocols[] = {
- { &gEfiSecurity2ArchProtocolGuid, (VOID **)&gSecurity2, NULL, NULL, FALSE },
- { &gEfiSmmBase2ProtocolGuid, (VOID **)&gSmmBase2, NULL, NULL, FALSE },
- { NULL, (VOID **)NULL, NULL, NULL, FALSE }
+ { &gEfiSecurity2ArchProtocolGuid, (VOID **)&gSecurity2, NULL, NULL, FALSE },
+ { &gEfiSmmBase2ProtocolGuid, (VOID **)&gSmmBase2, NULL, NULL, FALSE },
+ { NULL, (VOID **)NULL, NULL, NULL, FALSE }
};
//
// Following is needed to display missing architectural protocols in debug builds
//
typedef struct {
- EFI_GUID *ProtocolGuid;
- CHAR8 *GuidString;
+ EFI_GUID *ProtocolGuid;
+ CHAR8 *GuidString;
} GUID_TO_STRING_PROTOCOL_ENTRY;
-GLOBAL_REMOVE_IF_UNREFERENCED CONST GUID_TO_STRING_PROTOCOL_ENTRY mMissingProtocols[] = {
- { &gEfiSecurityArchProtocolGuid, "Security" },
- { &gEfiCpuArchProtocolGuid, "CPU" },
- { &gEfiMetronomeArchProtocolGuid, "Metronome" },
- { &gEfiTimerArchProtocolGuid, "Timer" },
- { &gEfiBdsArchProtocolGuid, "Bds" },
- { &gEfiWatchdogTimerArchProtocolGuid, "Watchdog Timer" },
- { &gEfiRuntimeArchProtocolGuid, "Runtime" },
- { &gEfiVariableArchProtocolGuid, "Variable" },
- { &gEfiVariableWriteArchProtocolGuid, "Variable Write" },
- { &gEfiCapsuleArchProtocolGuid, "Capsule" },
- { &gEfiMonotonicCounterArchProtocolGuid, "Monotonic Counter" },
- { &gEfiResetArchProtocolGuid, "Reset" },
- { &gEfiRealTimeClockArchProtocolGuid, "Real Time Clock" },
- { NULL, "" }
+GLOBAL_REMOVE_IF_UNREFERENCED CONST GUID_TO_STRING_PROTOCOL_ENTRY mMissingProtocols[] = {
+ { &gEfiSecurityArchProtocolGuid, "Security" },
+ { &gEfiCpuArchProtocolGuid, "CPU" },
+ { &gEfiMetronomeArchProtocolGuid, "Metronome" },
+ { &gEfiTimerArchProtocolGuid, "Timer" },
+ { &gEfiBdsArchProtocolGuid, "Bds" },
+ { &gEfiWatchdogTimerArchProtocolGuid, "Watchdog Timer" },
+ { &gEfiRuntimeArchProtocolGuid, "Runtime" },
+ { &gEfiVariableArchProtocolGuid, "Variable" },
+ { &gEfiVariableWriteArchProtocolGuid, "Variable Write" },
+ { &gEfiCapsuleArchProtocolGuid, "Capsule" },
+ { &gEfiMonotonicCounterArchProtocolGuid, "Monotonic Counter" },
+ { &gEfiResetArchProtocolGuid, "Reset" },
+ { &gEfiRealTimeClockArchProtocolGuid, "Real Time Clock" },
+ { NULL, "" }
};
/**
@@ -88,10 +88,10 @@ CoreAllEfiServicesAvailable ( return EFI_NOT_FOUND;
}
}
+
return EFI_SUCCESS;
}
-
/**
Notification event handler registered by CoreNotifyOnArchProtocolInstallation ().
This notify function is registered for every architectural protocol. This handler
@@ -170,14 +170,15 @@ GenericProtocolNotify ( // Copy all the registered Image to new gRuntime protocol
//
for (Link = gRuntimeTemplate.ImageHead.ForwardLink; Link != &gRuntimeTemplate.ImageHead; Link = TempLinkNode.ForwardLink) {
- CopyMem (&TempLinkNode, Link, sizeof(LIST_ENTRY));
+ CopyMem (&TempLinkNode, Link, sizeof (LIST_ENTRY));
InsertTailList (&gRuntime->ImageHead, Link);
}
+
//
// Copy all the registered Event to new gRuntime protocol
//
for (Link = gRuntimeTemplate.EventHead.ForwardLink; Link != &gRuntimeTemplate.EventHead; Link = TempLinkNode.ForwardLink) {
- CopyMem (&TempLinkNode, Link, sizeof(LIST_ENTRY));
+ CopyMem (&TempLinkNode, Link, sizeof (LIST_ENTRY));
InsertTailList (&gRuntime->EventHead, Link);
}
@@ -213,28 +214,28 @@ CoreNotifyOnProtocolEntryTable ( {
EFI_STATUS Status;
- for (; Entry->ProtocolGuid != NULL; Entry++) {
+ for ( ; Entry->ProtocolGuid != NULL; Entry++) {
//
// Create the event
//
Status = CoreCreateEvent (
- EVT_NOTIFY_SIGNAL,
- TPL_CALLBACK,
- GenericProtocolNotify,
- Entry,
- &Entry->Event
- );
- ASSERT_EFI_ERROR(Status);
+ EVT_NOTIFY_SIGNAL,
+ TPL_CALLBACK,
+ GenericProtocolNotify,
+ Entry,
+ &Entry->Event
+ );
+ ASSERT_EFI_ERROR (Status);
//
// Register for protocol notifactions on this event
//
Status = CoreRegisterProtocolNotify (
- Entry->ProtocolGuid,
- Entry->Event,
- &Entry->Registration
- );
- ASSERT_EFI_ERROR(Status);
+ Entry->ProtocolGuid,
+ Entry->Event,
+ &Entry->Registration
+ );
+ ASSERT_EFI_ERROR (Status);
}
}
@@ -252,7 +253,6 @@ CoreNotifyOnProtocolInstallation ( CoreNotifyOnProtocolEntryTable (mOptionalProtocols);
}
-
/**
Displays Architectural protocols that were not loaded and are required for DXE
core to function. Only used in Debug Builds.
diff --git a/MdeModulePkg/Core/Dxe/Event/Event.c b/MdeModulePkg/Core/Dxe/Event/Event.c index 6f96e12815..dc82abb021 100644 --- a/MdeModulePkg/Core/Dxe/Event/Event.c +++ b/MdeModulePkg/Core/Dxe/Event/Event.c @@ -7,7 +7,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent **/
-
#include "DxeMain.h"
#include "Event.h"
@@ -19,27 +18,27 @@ EFI_TPL gEfiCurrentTpl = TPL_APPLICATION; ///
/// gEventQueueLock - Protects the event queues
///
-EFI_LOCK gEventQueueLock = EFI_INITIALIZE_LOCK_VARIABLE (TPL_HIGH_LEVEL);
+EFI_LOCK gEventQueueLock = EFI_INITIALIZE_LOCK_VARIABLE (TPL_HIGH_LEVEL);
///
/// gEventQueue - A list of event's to notify for each priority level
///
-LIST_ENTRY gEventQueue[TPL_HIGH_LEVEL + 1];
+LIST_ENTRY gEventQueue[TPL_HIGH_LEVEL + 1];
///
/// gEventPending - A bitmask of the EventQueues that are pending
///
-UINTN gEventPending = 0;
+UINTN gEventPending = 0;
///
/// gEventSignalQueue - A list of events to signal based on EventGroup type
///
-LIST_ENTRY gEventSignalQueue = INITIALIZE_LIST_HEAD_VARIABLE (gEventSignalQueue);
+LIST_ENTRY gEventSignalQueue = INITIALIZE_LIST_HEAD_VARIABLE (gEventSignalQueue);
///
/// Enumerate the valid types
///
-UINT32 mEventTable[] = {
+UINT32 mEventTable[] = {
///
/// 0x80000200 Timer event with a notification function that is
/// queue when the event is signaled with SignalEvent()
@@ -85,8 +84,7 @@ UINT32 mEventTable[] = { ///
/// gIdleLoopEvent - Event which is signalled when the core is idle
///
-EFI_EVENT gIdleLoopEvent = NULL;
-
+EFI_EVENT gIdleLoopEvent = NULL;
/**
Enter critical section by acquiring the lock on gEventQueueLock.
@@ -100,7 +98,6 @@ CoreAcquireEventLock ( CoreAcquireLock (&gEventQueueLock);
}
-
/**
Exit critical section by releasing the lock on gEventQueueLock.
@@ -113,8 +110,6 @@ CoreReleaseEventLock ( CoreReleaseLock (&gEventQueueLock);
}
-
-
/**
Initializes "event" support.
@@ -126,9 +121,9 @@ CoreInitializeEventServices ( VOID
)
{
- UINTN Index;
+ UINTN Index;
- for (Index=0; Index <= TPL_HIGH_LEVEL; Index++) {
+ for (Index = 0; Index <= TPL_HIGH_LEVEL; Index++) {
InitializeListHead (&gEventQueue[Index]);
}
@@ -146,8 +141,6 @@ CoreInitializeEventServices ( return EFI_SUCCESS;
}
-
-
/**
Dispatches all pending events.
@@ -157,11 +150,11 @@ CoreInitializeEventServices ( **/
VOID
CoreDispatchEventNotifies (
- IN EFI_TPL Priority
+ IN EFI_TPL Priority
)
{
- IEVENT *Event;
- LIST_ENTRY *Head;
+ IEVENT *Event;
+ LIST_ENTRY *Head;
CoreAcquireEventLock ();
ASSERT (gEventQueueLock.OwnerTpl == Priority);
@@ -171,7 +164,6 @@ CoreDispatchEventNotifies ( // Dispatch all the pending notifications
//
while (!IsListEmpty (Head)) {
-
Event = CR (Head->ForwardLink, IEVENT, NotifyLink, EVENT_SIGNATURE);
RemoveEntryList (&Event->NotifyLink);
@@ -203,8 +195,6 @@ CoreDispatchEventNotifies ( CoreReleaseEventLock ();
}
-
-
/**
Queues the event's notification function to fire.
@@ -213,10 +203,9 @@ CoreDispatchEventNotifies ( **/
VOID
CoreNotifyEvent (
- IN IEVENT *Event
+ IN IEVENT *Event
)
{
-
//
// Event database must be locked
//
@@ -239,9 +228,6 @@ CoreNotifyEvent ( gEventPending |= (UINTN)(1 << Event->NotifyTpl);
}
-
-
-
/**
Signals all events in the EventGroup.
@@ -250,12 +236,12 @@ CoreNotifyEvent ( **/
VOID
CoreNotifySignalList (
- IN EFI_GUID *EventGroup
+ IN EFI_GUID *EventGroup
)
{
- LIST_ENTRY *Link;
- LIST_ENTRY *Head;
- IEVENT *Event;
+ LIST_ENTRY *Link;
+ LIST_ENTRY *Head;
+ IEVENT *Event;
CoreAcquireEventLock ();
@@ -270,7 +256,6 @@ CoreNotifySignalList ( CoreReleaseEventLock ();
}
-
/**
Creates an event.
@@ -292,18 +277,16 @@ CoreNotifySignalList ( EFI_STATUS
EFIAPI
CoreCreateEvent (
- IN UINT32 Type,
- IN EFI_TPL NotifyTpl,
- IN EFI_EVENT_NOTIFY NotifyFunction OPTIONAL,
- IN VOID *NotifyContext OPTIONAL,
- OUT EFI_EVENT *Event
+ IN UINT32 Type,
+ IN EFI_TPL NotifyTpl,
+ IN EFI_EVENT_NOTIFY NotifyFunction OPTIONAL,
+ IN VOID *NotifyContext OPTIONAL,
+ OUT EFI_EVENT *Event
)
{
return CoreCreateEventEx (Type, NotifyTpl, NotifyFunction, NotifyContext, NULL, Event);
}
-
-
/**
Creates an event in a group.
@@ -327,21 +310,22 @@ CoreCreateEvent ( EFI_STATUS
EFIAPI
CoreCreateEventEx (
- IN UINT32 Type,
- IN EFI_TPL NotifyTpl,
- IN EFI_EVENT_NOTIFY NotifyFunction OPTIONAL,
- IN CONST VOID *NotifyContext OPTIONAL,
- IN CONST EFI_GUID *EventGroup OPTIONAL,
- OUT EFI_EVENT *Event
+ IN UINT32 Type,
+ IN EFI_TPL NotifyTpl,
+ IN EFI_EVENT_NOTIFY NotifyFunction OPTIONAL,
+ IN CONST VOID *NotifyContext OPTIONAL,
+ IN CONST EFI_GUID *EventGroup OPTIONAL,
+ OUT EFI_EVENT *Event
)
{
//
// If it's a notify type of event, check for invalid NotifyTpl
//
if ((Type & (EVT_NOTIFY_WAIT | EVT_NOTIFY_SIGNAL)) != 0) {
- if (NotifyTpl != TPL_APPLICATION &&
- NotifyTpl != TPL_CALLBACK &&
- NotifyTpl != TPL_NOTIFY) {
+ if ((NotifyTpl != TPL_APPLICATION) &&
+ (NotifyTpl != TPL_CALLBACK) &&
+ (NotifyTpl != TPL_NOTIFY))
+ {
return EFI_INVALID_PARAMETER;
}
}
@@ -372,18 +356,17 @@ CoreCreateEventEx ( EFI_STATUS
EFIAPI
CoreCreateEventInternal (
- IN UINT32 Type,
- IN EFI_TPL NotifyTpl,
- IN EFI_EVENT_NOTIFY NotifyFunction OPTIONAL,
- IN CONST VOID *NotifyContext OPTIONAL,
- IN CONST EFI_GUID *EventGroup OPTIONAL,
- OUT EFI_EVENT *Event
+ IN UINT32 Type,
+ IN EFI_TPL NotifyTpl,
+ IN EFI_EVENT_NOTIFY NotifyFunction OPTIONAL,
+ IN CONST VOID *NotifyContext OPTIONAL,
+ IN CONST EFI_GUID *EventGroup OPTIONAL,
+ OUT EFI_EVENT *Event
)
{
- EFI_STATUS Status;
- IEVENT *IEvent;
- INTN Index;
-
+ EFI_STATUS Status;
+ IEVENT *IEvent;
+ INTN Index;
if (Event == NULL) {
return EFI_INVALID_PARAMETER;
@@ -394,12 +377,13 @@ CoreCreateEventInternal ( //
Status = EFI_INVALID_PARAMETER;
for (Index = 0; Index < (sizeof (mEventTable) / sizeof (UINT32)); Index++) {
- if (Type == mEventTable[Index]) {
- Status = EFI_SUCCESS;
- break;
- }
+ if (Type == mEventTable[Index]) {
+ Status = EFI_SUCCESS;
+ break;
+ }
}
- if(EFI_ERROR (Status)) {
+
+ if (EFI_ERROR (Status)) {
return EFI_INVALID_PARAMETER;
}
@@ -414,6 +398,7 @@ CoreCreateEventInternal ( if ((Type == EVT_SIGNAL_EXIT_BOOT_SERVICES) || (Type == EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE)) {
return EFI_INVALID_PARAMETER;
}
+
if (CompareGuid (EventGroup, &gEfiEventExitBootServicesGuid)) {
Type = EVT_SIGNAL_EXIT_BOOT_SERVICES;
} else if (CompareGuid (EventGroup, &gEfiEventVirtualAddressChangeGuid)) {
@@ -439,17 +424,17 @@ CoreCreateEventInternal ( //
if ((NotifyFunction == NULL) ||
(NotifyTpl <= TPL_APPLICATION) ||
- (NotifyTpl >= TPL_HIGH_LEVEL)) {
+ (NotifyTpl >= TPL_HIGH_LEVEL))
+ {
return EFI_INVALID_PARAMETER;
}
-
} else {
//
// No notification needed, zero ignored values
//
- NotifyTpl = 0;
+ NotifyTpl = 0;
NotifyFunction = NULL;
- NotifyContext = NULL;
+ NotifyContext = NULL;
}
//
@@ -460,12 +445,13 @@ CoreCreateEventInternal ( } else {
IEvent = AllocateZeroPool (sizeof (IEVENT));
}
+
if (IEvent == NULL) {
return EFI_OUT_OF_RESOURCES;
}
IEvent->Signature = EVENT_SIGNATURE;
- IEvent->Type = Type;
+ IEvent->Type = Type;
IEvent->NotifyTpl = NotifyTpl;
IEvent->NotifyFunction = NotifyFunction;
@@ -484,7 +470,7 @@ CoreCreateEventInternal ( IEvent->RuntimeData.Type = Type;
IEvent->RuntimeData.NotifyTpl = NotifyTpl;
IEvent->RuntimeData.NotifyFunction = NotifyFunction;
- IEvent->RuntimeData.NotifyContext = (VOID *) NotifyContext;
+ IEvent->RuntimeData.NotifyContext = (VOID *)NotifyContext;
//
// Work around the bug in the Platform Init specification (v1.7), reported
// as Mantis#2017: "EFI_RUNTIME_EVENT_ENTRY.Event" should have type
@@ -493,7 +479,7 @@ CoreCreateEventInternal ( // doesn't match the natural language description. Therefore we need an
// explicit cast here.
//
- IEvent->RuntimeData.Event = (EFI_EVENT *) IEvent;
+ IEvent->RuntimeData.Event = (EFI_EVENT *)IEvent;
InsertTailList (&gRuntime->EventHead, &IEvent->RuntimeData.Link);
}
@@ -514,9 +500,6 @@ CoreCreateEventInternal ( return EFI_SUCCESS;
}
-
-
-
/**
Signals the event. Queues the event to be notified if needed.
@@ -529,10 +512,10 @@ CoreCreateEventInternal ( EFI_STATUS
EFIAPI
CoreSignalEvent (
- IN EFI_EVENT UserEvent
+ IN EFI_EVENT UserEvent
)
{
- IEVENT *Event;
+ IEVENT *Event;
Event = UserEvent;
@@ -565,7 +548,7 @@ CoreSignalEvent ( CoreReleaseEventLock ();
CoreNotifySignalList (&Event->EventGroup);
CoreAcquireEventLock ();
- } else {
+ } else {
CoreNotifyEvent (Event);
}
}
@@ -575,8 +558,6 @@ CoreSignalEvent ( return EFI_SUCCESS;
}
-
-
/**
Check the status of an event.
@@ -590,7 +571,7 @@ CoreSignalEvent ( EFI_STATUS
EFIAPI
CoreCheckEvent (
- IN EFI_EVENT UserEvent
+ IN EFI_EVENT UserEvent
)
{
IEVENT *Event;
@@ -613,7 +594,6 @@ CoreCheckEvent ( Status = EFI_NOT_READY;
if ((Event->SignalCount == 0) && ((Event->Type & EVT_NOTIFY_WAIT) != 0)) {
-
//
// Queue the wait notify function
//
@@ -621,6 +601,7 @@ CoreCheckEvent ( if (Event->SignalCount == 0) {
CoreNotifyEvent (Event);
}
+
CoreReleaseEventLock ();
}
@@ -633,7 +614,7 @@ CoreCheckEvent ( if (Event->SignalCount != 0) {
Event->SignalCount = 0;
- Status = EFI_SUCCESS;
+ Status = EFI_SUCCESS;
}
CoreReleaseEventLock ();
@@ -642,8 +623,6 @@ CoreCheckEvent ( return Status;
}
-
-
/**
Stops execution until an event is signaled.
@@ -661,13 +640,13 @@ CoreCheckEvent ( EFI_STATUS
EFIAPI
CoreWaitForEvent (
- IN UINTN NumberOfEvents,
- IN EFI_EVENT *UserEvents,
- OUT UINTN *UserIndex
+ IN UINTN NumberOfEvents,
+ IN EFI_EVENT *UserEvents,
+ OUT UINTN *UserIndex
)
{
- EFI_STATUS Status;
- UINTN Index;
+ EFI_STATUS Status;
+ UINTN Index;
//
// Can only WaitForEvent at TPL_APPLICATION
@@ -684,10 +663,8 @@ CoreWaitForEvent ( return EFI_INVALID_PARAMETER;
}
- for(;;) {
-
- for(Index = 0; Index < NumberOfEvents; Index++) {
-
+ for ( ; ;) {
+ for (Index = 0; Index < NumberOfEvents; Index++) {
Status = CoreCheckEvent (UserEvents[Index]);
//
@@ -697,6 +674,7 @@ CoreWaitForEvent ( if (UserIndex != NULL) {
*UserIndex = Index;
}
+
return Status;
}
}
@@ -708,7 +686,6 @@ CoreWaitForEvent ( }
}
-
/**
Closes an event and frees the event structure.
@@ -721,7 +698,7 @@ CoreWaitForEvent ( EFI_STATUS
EFIAPI
CoreCloseEvent (
- IN EFI_EVENT UserEvent
+ IN EFI_EVENT UserEvent
)
{
EFI_STATUS Status;
@@ -776,7 +753,7 @@ CoreCloseEvent ( // clear the Signature of Event before free pool.
//
Event->Signature = 0;
- Status = CoreFreePool (Event);
+ Status = CoreFreePool (Event);
ASSERT_EFI_ERROR (Status);
return Status;
diff --git a/MdeModulePkg/Core/Dxe/Event/Event.h b/MdeModulePkg/Core/Dxe/Event/Event.h index 8141c5003e..201b90b301 100644 --- a/MdeModulePkg/Core/Dxe/Event/Event.h +++ b/MdeModulePkg/Core/Dxe/Event/Event.h @@ -10,18 +10,17 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #ifndef __EVENT_H__
#define __EVENT_H__
-
-#define VALID_TPL(a) ((a) <= TPL_HIGH_LEVEL)
-extern UINTN gEventPending;
+#define VALID_TPL(a) ((a) <= TPL_HIGH_LEVEL)
+extern UINTN gEventPending;
///
/// Set if Event is part of an event group
///
-#define EVT_EXFLAG_EVENT_GROUP 0x01
+#define EVT_EXFLAG_EVENT_GROUP 0x01
///
/// Set if Event is registered on a protocol notify
///
-#define EVT_EXFLAG_EVENT_PROTOCOL_NOTIFICATION 0x02
+#define EVT_EXFLAG_EVENT_PROTOCOL_NOTIFICATION 0x02
//
// EFI_EVENT
@@ -31,41 +30,40 @@ extern UINTN gEventPending; /// Timer event information
///
typedef struct {
- LIST_ENTRY Link;
- UINT64 TriggerTime;
- UINT64 Period;
+ LIST_ENTRY Link;
+ UINT64 TriggerTime;
+ UINT64 Period;
} TIMER_EVENT_INFO;
-#define EVENT_SIGNATURE SIGNATURE_32('e','v','n','t')
+#define EVENT_SIGNATURE SIGNATURE_32('e','v','n','t')
typedef struct {
- UINTN Signature;
- UINT32 Type;
- UINT32 SignalCount;
+ UINTN Signature;
+ UINT32 Type;
+ UINT32 SignalCount;
///
/// Entry if the event is registered to be signalled
///
- LIST_ENTRY SignalLink;
+ LIST_ENTRY SignalLink;
///
/// Notification information for this event
///
- EFI_TPL NotifyTpl;
- EFI_EVENT_NOTIFY NotifyFunction;
- VOID *NotifyContext;
- EFI_GUID EventGroup;
- LIST_ENTRY NotifyLink;
- UINT8 ExFlag;
+ EFI_TPL NotifyTpl;
+ EFI_EVENT_NOTIFY NotifyFunction;
+ VOID *NotifyContext;
+ EFI_GUID EventGroup;
+ LIST_ENTRY NotifyLink;
+ UINT8 ExFlag;
///
/// A list of all runtime events
///
- EFI_RUNTIME_EVENT_ENTRY RuntimeData;
- TIMER_EVENT_INFO Timer;
+ EFI_RUNTIME_EVENT_ENTRY RuntimeData;
+ TIMER_EVENT_INFO Timer;
} IEVENT;
//
// Internal prototypes
//
-
/**
Dispatches all pending events.
@@ -75,10 +73,9 @@ typedef struct { **/
VOID
CoreDispatchEventNotifies (
- IN EFI_TPL Priority
+ IN EFI_TPL Priority
);
-
/**
Initializes timer support.
diff --git a/MdeModulePkg/Core/Dxe/Event/Timer.c b/MdeModulePkg/Core/Dxe/Event/Timer.c index 7a94712d81..29e507c67c 100644 --- a/MdeModulePkg/Core/Dxe/Event/Timer.c +++ b/MdeModulePkg/Core/Dxe/Event/Timer.c @@ -6,7 +6,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent **/
-
#include "DxeMain.h"
#include "Event.h"
@@ -14,16 +13,17 @@ SPDX-License-Identifier: BSD-2-Clause-Patent // Internal data
//
-LIST_ENTRY mEfiTimerList = INITIALIZE_LIST_HEAD_VARIABLE (mEfiTimerList);
-EFI_LOCK mEfiTimerLock = EFI_INITIALIZE_LOCK_VARIABLE (TPL_HIGH_LEVEL - 1);
-EFI_EVENT mEfiCheckTimerEvent = NULL;
+LIST_ENTRY mEfiTimerList = INITIALIZE_LIST_HEAD_VARIABLE (mEfiTimerList);
+EFI_LOCK mEfiTimerLock = EFI_INITIALIZE_LOCK_VARIABLE (TPL_HIGH_LEVEL - 1);
+EFI_EVENT mEfiCheckTimerEvent = NULL;
-EFI_LOCK mEfiSystemTimeLock = EFI_INITIALIZE_LOCK_VARIABLE (TPL_HIGH_LEVEL);
-UINT64 mEfiSystemTime = 0;
+EFI_LOCK mEfiSystemTimeLock = EFI_INITIALIZE_LOCK_VARIABLE (TPL_HIGH_LEVEL);
+UINT64 mEfiSystemTime = 0;
//
// Timer functions
//
+
/**
Inserts the timer event.
@@ -33,12 +33,12 @@ UINT64 mEfiSystemTime = 0; **/
VOID
CoreInsertEventTimer (
- IN IEVENT *Event
+ IN IEVENT *Event
)
{
- UINT64 TriggerTime;
- LIST_ENTRY *Link;
- IEVENT *Event2;
+ UINT64 TriggerTime;
+ LIST_ENTRY *Link;
+ IEVENT *Event2;
ASSERT_LOCKED (&mEfiTimerLock);
@@ -72,7 +72,7 @@ CoreCurrentSystemTime ( VOID
)
{
- UINT64 SystemTime;
+ UINT64 SystemTime;
CoreAcquireLock (&mEfiSystemTimeLock);
SystemTime = mEfiSystemTime;
@@ -92,12 +92,12 @@ CoreCurrentSystemTime ( VOID
EFIAPI
CoreCheckTimers (
- IN EFI_EVENT CheckEvent,
- IN VOID *Context
+ IN EFI_EVENT CheckEvent,
+ IN VOID *Context
)
{
- UINT64 SystemTime;
- IEVENT *Event;
+ UINT64 SystemTime;
+ IEVENT *Event;
//
// Check the timer database for expired timers
@@ -154,7 +154,6 @@ CoreCheckTimers ( CoreReleaseLock (&mEfiTimerLock);
}
-
/**
Initializes timer support.
@@ -177,7 +176,6 @@ CoreInitializeTimer ( ASSERT_EFI_ERROR (Status);
}
-
/**
Called by the platform code to process a tick.
@@ -188,10 +186,10 @@ CoreInitializeTimer ( VOID
EFIAPI
CoreTimerTick (
- IN UINT64 Duration
+ IN UINT64 Duration
)
{
- IEVENT *Event;
+ IEVENT *Event;
//
// Check runtiem flag in case there are ticks while exiting boot services
@@ -218,8 +216,6 @@ CoreTimerTick ( CoreReleaseLock (&mEfiSystemTimeLock);
}
-
-
/**
Sets the type of timer and the trigger time for a timer event.
@@ -238,12 +234,12 @@ CoreTimerTick ( EFI_STATUS
EFIAPI
CoreSetTimer (
- IN EFI_EVENT UserEvent,
- IN EFI_TIMER_DELAY Type,
- IN UINT64 TriggerTime
+ IN EFI_EVENT UserEvent,
+ IN EFI_TIMER_DELAY Type,
+ IN UINT64 TriggerTime
)
{
- IEVENT *Event;
+ IEVENT *Event;
Event = UserEvent;
@@ -255,7 +251,7 @@ CoreSetTimer ( return EFI_INVALID_PARAMETER;
}
- if ((UINT32)Type > TimerRelative || (Event->Type & EVT_TIMER) == 0) {
+ if (((UINT32)Type > TimerRelative) || ((Event->Type & EVT_TIMER) == 0)) {
return EFI_INVALID_PARAMETER;
}
@@ -270,14 +266,14 @@ CoreSetTimer ( }
Event->Timer.TriggerTime = 0;
- Event->Timer.Period = 0;
+ Event->Timer.Period = 0;
if (Type != TimerCancel) {
-
if (Type == TimerPeriodic) {
if (TriggerTime == 0) {
gTimer->GetTimerPeriod (gTimer, &TriggerTime);
}
+
Event->Timer.Period = TriggerTime;
}
diff --git a/MdeModulePkg/Core/Dxe/Event/Tpl.c b/MdeModulePkg/Core/Dxe/Event/Tpl.c index 8b5928df00..b33f80573c 100644 --- a/MdeModulePkg/Core/Dxe/Event/Tpl.c +++ b/MdeModulePkg/Core/Dxe/Event/Tpl.c @@ -17,7 +17,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent **/
VOID
CoreSetInterruptState (
- IN BOOLEAN Enable
+ IN BOOLEAN Enable
)
{
EFI_STATUS Status;
@@ -26,21 +26,23 @@ CoreSetInterruptState ( if (gCpu == NULL) {
return;
}
+
if (!Enable) {
gCpu->DisableInterrupt (gCpu);
return;
}
+
if (gSmmBase2 == NULL) {
gCpu->EnableInterrupt (gCpu);
return;
}
+
Status = gSmmBase2->InSmm (gSmmBase2, &InSmm);
if (!EFI_ERROR (Status) && !InSmm) {
- gCpu->EnableInterrupt(gCpu);
+ gCpu->EnableInterrupt (gCpu);
}
}
-
/**
Raise the task priority level to the new level.
High level is implemented by disabling processor interrupts.
@@ -53,22 +55,23 @@ CoreSetInterruptState ( EFI_TPL
EFIAPI
CoreRaiseTpl (
- IN EFI_TPL NewTpl
+ IN EFI_TPL NewTpl
)
{
- EFI_TPL OldTpl;
+ EFI_TPL OldTpl;
OldTpl = gEfiCurrentTpl;
if (OldTpl > NewTpl) {
DEBUG ((DEBUG_ERROR, "FATAL ERROR - RaiseTpl with OldTpl(0x%x) > NewTpl(0x%x)\n", OldTpl, NewTpl));
ASSERT (FALSE);
}
+
ASSERT (VALID_TPL (NewTpl));
//
// If raising to high level, disable interrupts
//
- if (NewTpl >= TPL_HIGH_LEVEL && OldTpl < TPL_HIGH_LEVEL) {
+ if ((NewTpl >= TPL_HIGH_LEVEL) && (OldTpl < TPL_HIGH_LEVEL)) {
CoreSetInterruptState (FALSE);
}
@@ -80,9 +83,6 @@ CoreRaiseTpl ( return OldTpl;
}
-
-
-
/**
Lowers the task priority to the previous value. If the new
priority unmasks events at a higher priority, they are dispatched.
@@ -93,17 +93,18 @@ CoreRaiseTpl ( VOID
EFIAPI
CoreRestoreTpl (
- IN EFI_TPL NewTpl
+ IN EFI_TPL NewTpl
)
{
- EFI_TPL OldTpl;
- EFI_TPL PendingTpl;
+ EFI_TPL OldTpl;
+ EFI_TPL PendingTpl;
OldTpl = gEfiCurrentTpl;
if (NewTpl > OldTpl) {
DEBUG ((DEBUG_ERROR, "FATAL ERROR - RestoreTpl with NewTpl(0x%x) > OldTpl(0x%x)\n", NewTpl, OldTpl));
ASSERT (FALSE);
}
+
ASSERT (VALID_TPL (NewTpl));
//
@@ -111,7 +112,7 @@ CoreRestoreTpl ( // interrupts are enabled
//
- if (OldTpl >= TPL_HIGH_LEVEL && NewTpl < TPL_HIGH_LEVEL) {
+ if ((OldTpl >= TPL_HIGH_LEVEL) && (NewTpl < TPL_HIGH_LEVEL)) {
gEfiCurrentTpl = TPL_HIGH_LEVEL;
}
@@ -119,7 +120,7 @@ CoreRestoreTpl ( // Dispatch any pending events
//
while (gEventPending != 0) {
- PendingTpl = (UINTN) HighBitSet64 (gEventPending);
+ PendingTpl = (UINTN)HighBitSet64 (gEventPending);
if (PendingTpl <= NewTpl) {
break;
}
@@ -128,6 +129,7 @@ CoreRestoreTpl ( if (gEfiCurrentTpl < TPL_HIGH_LEVEL) {
CoreSetInterruptState (TRUE);
}
+
CoreDispatchEventNotifies (gEfiCurrentTpl);
}
@@ -144,5 +146,4 @@ CoreRestoreTpl ( if (gEfiCurrentTpl < TPL_HIGH_LEVEL) {
CoreSetInterruptState (TRUE);
}
-
}
diff --git a/MdeModulePkg/Core/Dxe/FwVol/Ffs.c b/MdeModulePkg/Core/Dxe/FwVol/Ffs.c index 199c7f821b..17e599cc15 100644 --- a/MdeModulePkg/Core/Dxe/FwVol/Ffs.c +++ b/MdeModulePkg/Core/Dxe/FwVol/Ffs.c @@ -6,11 +6,9 @@ SPDX-License-Identifier: BSD-2-Clause-Patent **/
-
#include "DxeMain.h"
#include "FwVolDriver.h"
-
/**
Get the FFS file state by checking the highest bit set in the header's state field.
@@ -26,13 +24,13 @@ GetFileState ( IN EFI_FFS_FILE_HEADER *FfsHeader
)
{
- EFI_FFS_FILE_STATE FileState;
- UINT8 HighestBit;
+ EFI_FFS_FILE_STATE FileState;
+ UINT8 HighestBit;
FileState = FfsHeader->State;
if (ErasePolarity != 0) {
- FileState = (EFI_FFS_FILE_STATE)~FileState;
+ FileState = (EFI_FFS_FILE_STATE) ~FileState;
}
HighestBit = 0x80;
@@ -40,11 +38,9 @@ GetFileState ( HighestBit >>= 1;
}
- return (EFI_FFS_FILE_STATE) HighestBit;
+ return (EFI_FFS_FILE_STATE)HighestBit;
}
-
-
/**
Check if a block of buffer is erased.
@@ -58,16 +54,16 @@ GetFileState ( **/
BOOLEAN
IsBufferErased (
- IN UINT8 ErasePolarity,
- IN VOID *InBuffer,
- IN UINTN BufferSize
+ IN UINT8 ErasePolarity,
+ IN VOID *InBuffer,
+ IN UINTN BufferSize
)
{
- UINTN Count;
- UINT8 EraseByte;
- UINT8 *Buffer;
+ UINTN Count;
+ UINT8 EraseByte;
+ UINT8 *Buffer;
- if(ErasePolarity == 1) {
+ if (ErasePolarity == 1) {
EraseByte = 0xFF;
} else {
EraseByte = 0;
@@ -83,8 +79,6 @@ IsBufferErased ( return TRUE;
}
-
-
/**
Verify checksum of the firmware volume header.
@@ -96,12 +90,12 @@ IsBufferErased ( **/
BOOLEAN
VerifyFvHeaderChecksum (
- IN EFI_FIRMWARE_VOLUME_HEADER *FvHeader
+ IN EFI_FIRMWARE_VOLUME_HEADER *FvHeader
)
{
UINT16 Checksum;
- Checksum = CalculateSum16 ((UINT16 *) FvHeader, FvHeader->HeaderLength);
+ Checksum = CalculateSum16 ((UINT16 *)FvHeader, FvHeader->HeaderLength);
if (Checksum == 0) {
return TRUE;
@@ -110,7 +104,6 @@ VerifyFvHeaderChecksum ( }
}
-
/**
Verify checksum of the FFS file header.
@@ -125,14 +118,15 @@ VerifyHeaderChecksum ( IN EFI_FFS_FILE_HEADER *FfsHeader
)
{
- UINT8 HeaderChecksum;
+ UINT8 HeaderChecksum;
if (IS_FFS_FILE2 (FfsHeader)) {
- HeaderChecksum = CalculateSum8 ((UINT8 *) FfsHeader, sizeof (EFI_FFS_FILE_HEADER2));
+ HeaderChecksum = CalculateSum8 ((UINT8 *)FfsHeader, sizeof (EFI_FFS_FILE_HEADER2));
} else {
- HeaderChecksum = CalculateSum8 ((UINT8 *) FfsHeader, sizeof (EFI_FFS_FILE_HEADER));
+ HeaderChecksum = CalculateSum8 ((UINT8 *)FfsHeader, sizeof (EFI_FFS_FILE_HEADER));
}
- HeaderChecksum = (UINT8) (HeaderChecksum - FfsHeader->State - FfsHeader->IntegrityCheck.Checksum.File);
+
+ HeaderChecksum = (UINT8)(HeaderChecksum - FfsHeader->State - FfsHeader->IntegrityCheck.Checksum.File);
if (HeaderChecksum == 0) {
return TRUE;
@@ -141,8 +135,6 @@ VerifyHeaderChecksum ( }
}
-
-
/**
Check if it's a valid FFS file header.
@@ -164,23 +156,22 @@ IsValidFfsHeader ( *FileState = GetFileState (ErasePolarity, FfsHeader);
switch (*FileState) {
- case EFI_FILE_HEADER_VALID:
- case EFI_FILE_DATA_VALID:
- case EFI_FILE_MARKED_FOR_UPDATE:
- case EFI_FILE_DELETED:
- //
- // Here we need to verify header checksum
- //
- return VerifyHeaderChecksum (FfsHeader);
-
- case EFI_FILE_HEADER_CONSTRUCTION:
- case EFI_FILE_HEADER_INVALID:
- default:
- return FALSE;
+ case EFI_FILE_HEADER_VALID:
+ case EFI_FILE_DATA_VALID:
+ case EFI_FILE_MARKED_FOR_UPDATE:
+ case EFI_FILE_DELETED:
+ //
+ // Here we need to verify header checksum
+ //
+ return VerifyHeaderChecksum (FfsHeader);
+
+ case EFI_FILE_HEADER_CONSTRUCTION:
+ case EFI_FILE_HEADER_INVALID:
+ default:
+ return FALSE;
}
}
-
/**
Check if it's a valid FFS file.
Here we are sure that it has a valid FFS file header since we must call IsValidFfsHeader() first.
@@ -203,25 +194,23 @@ IsValidFfsFile ( FileState = GetFileState (ErasePolarity, FfsHeader);
switch (FileState) {
+ case EFI_FILE_DELETED:
+ case EFI_FILE_DATA_VALID:
+ case EFI_FILE_MARKED_FOR_UPDATE:
+ DataCheckSum = FFS_FIXED_CHECKSUM;
+ if ((FfsHeader->Attributes & FFS_ATTRIB_CHECKSUM) == FFS_ATTRIB_CHECKSUM) {
+ if (IS_FFS_FILE2 (FfsHeader)) {
+ DataCheckSum = CalculateCheckSum8 ((CONST UINT8 *)FfsHeader + sizeof (EFI_FFS_FILE_HEADER2), FFS_FILE2_SIZE (FfsHeader) - sizeof (EFI_FFS_FILE_HEADER2));
+ } else {
+ DataCheckSum = CalculateCheckSum8 ((CONST UINT8 *)FfsHeader + sizeof (EFI_FFS_FILE_HEADER), FFS_FILE_SIZE (FfsHeader) - sizeof (EFI_FFS_FILE_HEADER));
+ }
+ }
- case EFI_FILE_DELETED:
- case EFI_FILE_DATA_VALID:
- case EFI_FILE_MARKED_FOR_UPDATE:
- DataCheckSum = FFS_FIXED_CHECKSUM;
- if ((FfsHeader->Attributes & FFS_ATTRIB_CHECKSUM) == FFS_ATTRIB_CHECKSUM) {
- if (IS_FFS_FILE2 (FfsHeader)) {
- DataCheckSum = CalculateCheckSum8 ((CONST UINT8 *) FfsHeader + sizeof (EFI_FFS_FILE_HEADER2), FFS_FILE2_SIZE (FfsHeader) - sizeof(EFI_FFS_FILE_HEADER2));
- } else {
- DataCheckSum = CalculateCheckSum8 ((CONST UINT8 *) FfsHeader + sizeof (EFI_FFS_FILE_HEADER), FFS_FILE_SIZE (FfsHeader) - sizeof(EFI_FFS_FILE_HEADER));
+ if (FfsHeader->IntegrityCheck.Checksum.File == DataCheckSum) {
+ return TRUE;
}
- }
- if (FfsHeader->IntegrityCheck.Checksum.File == DataCheckSum) {
- return TRUE;
- }
- default:
- return FALSE;
+ default:
+ return FALSE;
}
}
-
-
diff --git a/MdeModulePkg/Core/Dxe/FwVol/FwVol.c b/MdeModulePkg/Core/Dxe/FwVol/FwVol.c index 0059b0f2d9..153bfecafa 100644 --- a/MdeModulePkg/Core/Dxe/FwVol/FwVol.c +++ b/MdeModulePkg/Core/Dxe/FwVol/FwVol.c @@ -11,14 +11,13 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include "DxeMain.h"
#include "FwVolDriver.h"
-
//
// Protocol notify related globals
//
-VOID *gEfiFwVolBlockNotifyReg;
-EFI_EVENT gEfiFwVolBlockEvent;
+VOID *gEfiFwVolBlockNotifyReg;
+EFI_EVENT gEfiFwVolBlockEvent;
-FV_DEVICE mFvDevice = {
+FV_DEVICE mFvDevice = {
FV2_DEVICE_SIGNATURE,
NULL,
NULL,
@@ -29,7 +28,7 @@ FV_DEVICE mFvDevice = { FvReadFileSection,
FvWriteFile,
FvGetNextFile,
- sizeof (UINTN),
+ sizeof (UINTN),
NULL,
FvGetVolumeInfo,
FvSetVolumeInfo
@@ -38,17 +37,17 @@ FV_DEVICE mFvDevice = { NULL,
NULL,
NULL,
- { NULL, NULL },
+ { NULL, NULL},
0,
0,
FALSE,
FALSE
};
-
//
// FFS helper functions
//
+
/**
Read data from Firmware Block by FVB protocol Read.
The data may cross the multi block ranges.
@@ -68,27 +67,27 @@ FV_DEVICE mFvDevice = { **/
EFI_STATUS
ReadFvbData (
- IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *Fvb,
- IN OUT EFI_LBA *StartLba,
- IN OUT UINTN *Offset,
- IN UINTN DataSize,
- OUT UINT8 *Data
+ IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *Fvb,
+ IN OUT EFI_LBA *StartLba,
+ IN OUT UINTN *Offset,
+ IN UINTN DataSize,
+ OUT UINT8 *Data
)
{
- UINTN BlockSize;
- UINTN NumberOfBlocks;
- UINTN BlockIndex;
- UINTN ReadDataSize;
- EFI_STATUS Status;
+ UINTN BlockSize;
+ UINTN NumberOfBlocks;
+ UINTN BlockIndex;
+ UINTN ReadDataSize;
+ EFI_STATUS Status;
//
// Try read data in current block
//
BlockIndex = 0;
ReadDataSize = DataSize;
- Status = Fvb->Read (Fvb, *StartLba, *Offset, &ReadDataSize, Data);
+ Status = Fvb->Read (Fvb, *StartLba, *Offset, &ReadDataSize, Data);
if (Status == EFI_SUCCESS) {
- *Offset += DataSize;
+ *Offset += DataSize;
return EFI_SUCCESS;
} else if (Status != EFI_BAD_BUFFER_SIZE) {
//
@@ -118,9 +117,10 @@ ReadFvbData ( if (EFI_ERROR (Status)) {
return Status;
}
- Data += BlockSize;
+
+ Data += BlockSize;
DataSize -= BlockSize;
- BlockIndex ++;
+ BlockIndex++;
}
//
@@ -150,7 +150,7 @@ ReadFvbData ( // Update Lba and Offset used by the following read.
//
*StartLba += BlockIndex;
- *Offset = DataSize;
+ *Offset = DataSize;
return EFI_SUCCESS;
}
@@ -173,8 +173,8 @@ ReadFvbData ( **/
EFI_STATUS
GetFwVolHeader (
- IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *Fvb,
- OUT EFI_FIRMWARE_VOLUME_HEADER **FwVolHeader
+ IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *Fvb,
+ OUT EFI_FIRMWARE_VOLUME_HEADER **FwVolHeader
)
{
EFI_STATUS Status;
@@ -187,10 +187,10 @@ GetFwVolHeader ( //
// Read the standard FV header
//
- StartLba = 0;
- Offset = 0;
+ StartLba = 0;
+ Offset = 0;
FvhLength = sizeof (EFI_FIRMWARE_VOLUME_HEADER);
- Status = ReadFvbData (Fvb, &StartLba, &Offset, FvhLength, (UINT8 *)&TempFvh);
+ Status = ReadFvbData (Fvb, &StartLba, &Offset, FvhLength, (UINT8 *)&TempFvh);
if (EFI_ERROR (Status)) {
return Status;
}
@@ -207,7 +207,8 @@ GetFwVolHeader ( // understand it...
//
if ((!CompareGuid (&TempFvh.FileSystemGuid, &gEfiFirmwareFileSystem2Guid)) &&
- (!CompareGuid (&TempFvh.FileSystemGuid, &gEfiFirmwareFileSystem3Guid))) {
+ (!CompareGuid (&TempFvh.FileSystemGuid, &gEfiFirmwareFileSystem3Guid)))
+ {
return EFI_INVALID_PARAMETER;
}
@@ -228,8 +229,8 @@ GetFwVolHeader ( // Read the rest of the header
//
FvhLength = TempFvh.HeaderLength - sizeof (EFI_FIRMWARE_VOLUME_HEADER);
- Buffer = (UINT8 *)*FwVolHeader + sizeof (EFI_FIRMWARE_VOLUME_HEADER);
- Status = ReadFvbData (Fvb, &StartLba, &Offset, FvhLength, Buffer);
+ Buffer = (UINT8 *)*FwVolHeader + sizeof (EFI_FIRMWARE_VOLUME_HEADER);
+ Status = ReadFvbData (Fvb, &StartLba, &Offset, FvhLength, Buffer);
if (EFI_ERROR (Status)) {
//
// Read failed so free buffer
@@ -240,8 +241,6 @@ GetFwVolHeader ( return Status;
}
-
-
/**
Free FvDevice resource when error happens
@@ -253,8 +252,8 @@ FreeFvDeviceResource ( IN FV_DEVICE *FvDevice
)
{
- FFS_FILE_LIST_ENTRY *FfsFileEntry;
- LIST_ENTRY *NextEntry;
+ FFS_FILE_LIST_ENTRY *FfsFileEntry;
+ LIST_ENTRY *NextEntry;
//
// Free File List Entry
@@ -279,7 +278,7 @@ FreeFvDeviceResource ( CoreFreePool (FfsFileEntry);
- FfsFileEntry = (FFS_FILE_LIST_ENTRY *) NextEntry;
+ FfsFileEntry = (FFS_FILE_LIST_ENTRY *)NextEntry;
}
if (!FvDevice->IsMemoryMapped) {
@@ -297,8 +296,6 @@ FreeFvDeviceResource ( return;
}
-
-
/**
Check if an FV is consistent and allocate cache for it.
@@ -314,30 +311,30 @@ FvCheck ( IN OUT FV_DEVICE *FvDevice
)
{
- EFI_STATUS Status;
- EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *Fvb;
- EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader;
- EFI_FIRMWARE_VOLUME_EXT_HEADER *FwVolExtHeader;
- EFI_FVB_ATTRIBUTES_2 FvbAttributes;
- EFI_FV_BLOCK_MAP_ENTRY *BlockMap;
- FFS_FILE_LIST_ENTRY *FfsFileEntry;
- EFI_FFS_FILE_HEADER *FfsHeader;
- UINT8 *CacheLocation;
- UINTN Index;
- EFI_LBA LbaIndex;
- UINTN Size;
- EFI_FFS_FILE_STATE FileState;
- UINT8 *TopFvAddress;
- UINTN TestLength;
- EFI_PHYSICAL_ADDRESS PhysicalAddress;
- BOOLEAN FileCached;
- UINTN WholeFileSize;
- EFI_FFS_FILE_HEADER *CacheFfsHeader;
-
- FileCached = FALSE;
+ EFI_STATUS Status;
+ EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *Fvb;
+ EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader;
+ EFI_FIRMWARE_VOLUME_EXT_HEADER *FwVolExtHeader;
+ EFI_FVB_ATTRIBUTES_2 FvbAttributes;
+ EFI_FV_BLOCK_MAP_ENTRY *BlockMap;
+ FFS_FILE_LIST_ENTRY *FfsFileEntry;
+ EFI_FFS_FILE_HEADER *FfsHeader;
+ UINT8 *CacheLocation;
+ UINTN Index;
+ EFI_LBA LbaIndex;
+ UINTN Size;
+ EFI_FFS_FILE_STATE FileState;
+ UINT8 *TopFvAddress;
+ UINTN TestLength;
+ EFI_PHYSICAL_ADDRESS PhysicalAddress;
+ BOOLEAN FileCached;
+ UINTN WholeFileSize;
+ EFI_FFS_FILE_HEADER *CacheFfsHeader;
+
+ FileCached = FALSE;
CacheFfsHeader = NULL;
- Fvb = FvDevice->Fvb;
+ Fvb = FvDevice->Fvb;
FwVolHeader = FvDevice->FwVolHeader;
Status = Fvb->GetAttributes (Fvb, &FvbAttributes);
@@ -345,7 +342,7 @@ FvCheck ( return Status;
}
- Size = (UINTN) FwVolHeader->FvLength;
+ Size = (UINTN)FwVolHeader->FvLength;
if ((FvbAttributes & EFI_FVB2_MEMORY_MAPPED) != 0) {
FvDevice->IsMemoryMapped = TRUE;
@@ -357,10 +354,10 @@ FvCheck ( //
// Don't cache memory mapped FV really.
//
- FvDevice->CachedFv = (UINT8 *) (UINTN) PhysicalAddress;
+ FvDevice->CachedFv = (UINT8 *)(UINTN)PhysicalAddress;
} else {
FvDevice->IsMemoryMapped = FALSE;
- FvDevice->CachedFv = AllocatePool (Size);
+ FvDevice->CachedFv = AllocatePool (Size);
if (FvDevice->CachedFv == NULL) {
return EFI_OUT_OF_RESOURCES;
@@ -376,9 +373,9 @@ FvCheck ( //
// Copy FV into memory using the block map.
//
- BlockMap = FwVolHeader->BlockMap;
+ BlockMap = FwVolHeader->BlockMap;
CacheLocation = FvDevice->CachedFv;
- LbaIndex = 0;
+ LbaIndex = 0;
while ((BlockMap->NumBlocks != 0) || (BlockMap->Length != 0)) {
//
// read the FV data
@@ -417,7 +414,6 @@ FvCheck ( FvDevice->ErasePolarity = 0;
}
-
//
// go through the whole FV cache, check the consistence of the FV.
// Make a linked list of all the Ffs file headers
@@ -432,21 +428,21 @@ FvCheck ( //
// Searching for files starts on an 8 byte aligned boundary after the end of the Extended Header if it exists.
//
- FwVolExtHeader = (EFI_FIRMWARE_VOLUME_EXT_HEADER *) (FvDevice->CachedFv + FwVolHeader->ExtHeaderOffset);
- FfsHeader = (EFI_FFS_FILE_HEADER *) ((UINT8 *) FwVolExtHeader + FwVolExtHeader->ExtHeaderSize);
+ FwVolExtHeader = (EFI_FIRMWARE_VOLUME_EXT_HEADER *)(FvDevice->CachedFv + FwVolHeader->ExtHeaderOffset);
+ FfsHeader = (EFI_FFS_FILE_HEADER *)((UINT8 *)FwVolExtHeader + FwVolExtHeader->ExtHeaderSize);
} else {
- FfsHeader = (EFI_FFS_FILE_HEADER *) (FvDevice->CachedFv + FwVolHeader->HeaderLength);
+ FfsHeader = (EFI_FFS_FILE_HEADER *)(FvDevice->CachedFv + FwVolHeader->HeaderLength);
}
- FfsHeader = (EFI_FFS_FILE_HEADER *) ALIGN_POINTER (FfsHeader, 8);
- TopFvAddress = FvDevice->EndOfCachedFv;
- while (((UINTN) FfsHeader >= (UINTN) FvDevice->CachedFv) && ((UINTN) FfsHeader <= (UINTN) ((UINTN) TopFvAddress - sizeof (EFI_FFS_FILE_HEADER)))) {
+ FfsHeader = (EFI_FFS_FILE_HEADER *)ALIGN_POINTER (FfsHeader, 8);
+ TopFvAddress = FvDevice->EndOfCachedFv;
+ while (((UINTN)FfsHeader >= (UINTN)FvDevice->CachedFv) && ((UINTN)FfsHeader <= (UINTN)((UINTN)TopFvAddress - sizeof (EFI_FFS_FILE_HEADER)))) {
if (FileCached) {
CoreFreePool (CacheFfsHeader);
FileCached = FALSE;
}
- TestLength = TopFvAddress - ((UINT8 *) FfsHeader);
+ TestLength = TopFvAddress - ((UINT8 *)FfsHeader);
if (TestLength > sizeof (EFI_FFS_FILE_HEADER)) {
TestLength = sizeof (EFI_FFS_FILE_HEADER);
}
@@ -460,15 +456,18 @@ FvCheck ( if (!IsValidFfsHeader (FvDevice->ErasePolarity, FfsHeader, &FileState)) {
if ((FileState == EFI_FILE_HEADER_INVALID) ||
- (FileState == EFI_FILE_HEADER_CONSTRUCTION)) {
+ (FileState == EFI_FILE_HEADER_CONSTRUCTION))
+ {
if (IS_FFS_FILE2 (FfsHeader)) {
if (!FvDevice->IsFfs3Fv) {
DEBUG ((DEBUG_ERROR, "Found a FFS3 formatted file: %g in a non-FFS3 formatted FV.\n", &FfsHeader->Name));
}
- FfsHeader = (EFI_FFS_FILE_HEADER *) ((UINT8 *) FfsHeader + sizeof (EFI_FFS_FILE_HEADER2));
+
+ FfsHeader = (EFI_FFS_FILE_HEADER *)((UINT8 *)FfsHeader + sizeof (EFI_FFS_FILE_HEADER2));
} else {
- FfsHeader = (EFI_FFS_FILE_HEADER *) ((UINT8 *) FfsHeader + sizeof (EFI_FFS_FILE_HEADER));
+ FfsHeader = (EFI_FFS_FILE_HEADER *)((UINT8 *)FfsHeader + sizeof (EFI_FFS_FILE_HEADER));
}
+
continue;
} else {
//
@@ -487,12 +486,13 @@ FvCheck ( // Here is to cache FFS file to memory buffer for following checksum calculating.
// And then, the cached file buffer can be also used for FvReadFile.
//
- WholeFileSize = IS_FFS_FILE2 (CacheFfsHeader) ? FFS_FILE2_SIZE (CacheFfsHeader): FFS_FILE_SIZE (CacheFfsHeader);
+ WholeFileSize = IS_FFS_FILE2 (CacheFfsHeader) ? FFS_FILE2_SIZE (CacheFfsHeader) : FFS_FILE_SIZE (CacheFfsHeader);
CacheFfsHeader = AllocateCopyPool (WholeFileSize, CacheFfsHeader);
if (CacheFfsHeader == NULL) {
Status = EFI_OUT_OF_RESOURCES;
goto Done;
}
+
FileCached = TRUE;
}
}
@@ -509,11 +509,11 @@ FvCheck ( ASSERT (FFS_FILE2_SIZE (CacheFfsHeader) > 0x00FFFFFF);
if (!FvDevice->IsFfs3Fv) {
DEBUG ((DEBUG_ERROR, "Found a FFS3 formatted file: %g in a non-FFS3 formatted FV.\n", &CacheFfsHeader->Name));
- FfsHeader = (EFI_FFS_FILE_HEADER *) ((UINT8 *) FfsHeader + FFS_FILE2_SIZE (CacheFfsHeader));
+ FfsHeader = (EFI_FFS_FILE_HEADER *)((UINT8 *)FfsHeader + FFS_FILE2_SIZE (CacheFfsHeader));
//
// Adjust pointer to the next 8-byte aligned boundary.
//
- FfsHeader = (EFI_FFS_FILE_HEADER *) (((UINTN) FfsHeader + 7) & ~0x07);
+ FfsHeader = (EFI_FFS_FILE_HEADER *)(((UINTN)FfsHeader + 7) & ~0x07);
continue;
}
}
@@ -533,23 +533,22 @@ FvCheck ( goto Done;
}
- FfsFileEntry->FfsHeader = CacheFfsHeader;
+ FfsFileEntry->FfsHeader = CacheFfsHeader;
FfsFileEntry->FileCached = FileCached;
- FileCached = FALSE;
+ FileCached = FALSE;
InsertTailList (&FvDevice->FfsFileListHeader, &FfsFileEntry->Link);
}
if (IS_FFS_FILE2 (CacheFfsHeader)) {
- FfsHeader = (EFI_FFS_FILE_HEADER *) ((UINT8 *) FfsHeader + FFS_FILE2_SIZE (CacheFfsHeader));
+ FfsHeader = (EFI_FFS_FILE_HEADER *)((UINT8 *)FfsHeader + FFS_FILE2_SIZE (CacheFfsHeader));
} else {
- FfsHeader = (EFI_FFS_FILE_HEADER *) ((UINT8 *) FfsHeader + FFS_FILE_SIZE (CacheFfsHeader));
+ FfsHeader = (EFI_FFS_FILE_HEADER *)((UINT8 *)FfsHeader + FFS_FILE_SIZE (CacheFfsHeader));
}
//
// Adjust pointer to the next 8-byte aligned boundary.
//
FfsHeader = (EFI_FFS_FILE_HEADER *)(((UINTN)FfsHeader + 7) & ~0x07);
-
}
Done:
@@ -558,14 +557,13 @@ Done: CoreFreePool (CacheFfsHeader);
FileCached = FALSE;
}
+
FreeFvDeviceResource (FvDevice);
}
return Status;
}
-
-
/**
This notification function is invoked when an instance of the
EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL is produced. It layers an instance of the
@@ -579,32 +577,33 @@ Done: VOID
EFIAPI
NotifyFwVolBlock (
- IN EFI_EVENT Event,
- IN VOID *Context
+ IN EFI_EVENT Event,
+ IN VOID *Context
)
{
- EFI_HANDLE Handle;
- EFI_STATUS Status;
- UINTN BufferSize;
- EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *Fvb;
- EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv;
- FV_DEVICE *FvDevice;
- EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader;
+ EFI_HANDLE Handle;
+ EFI_STATUS Status;
+ UINTN BufferSize;
+ EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *Fvb;
+ EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv;
+ FV_DEVICE *FvDevice;
+ EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader;
+
//
// Examine all new handles
//
- for (;;) {
+ for ( ; ;) {
//
// Get the next handle
//
BufferSize = sizeof (Handle);
- Status = CoreLocateHandle (
- ByRegisterNotify,
- NULL,
- gEfiFwVolBlockNotifyReg,
- &BufferSize,
- &Handle
- );
+ Status = CoreLocateHandle (
+ ByRegisterNotify,
+ NULL,
+ gEfiFwVolBlockNotifyReg,
+ &BufferSize,
+ &Handle
+ );
//
// If not found, we're done
@@ -631,6 +630,7 @@ NotifyFwVolBlock ( if (EFI_ERROR (Status)) {
continue;
}
+
ASSERT (FwVolHeader != NULL);
if (!VerifyFvHeaderChecksum (FwVolHeader)) {
@@ -653,7 +653,6 @@ NotifyFwVolBlock ( //
FvDevice->Fvb = Fvb;
}
-
} else {
//
// No FwVol protocol on the handle so create a new one
@@ -678,11 +677,11 @@ NotifyFwVolBlock ( // Install an New FV protocol on the existing handle
//
Status = CoreInstallProtocolInterface (
- &Handle,
- &gEfiFirmwareVolume2ProtocolGuid,
- EFI_NATIVE_INTERFACE,
- &FvDevice->Fv
- );
+ &Handle,
+ &gEfiFirmwareVolume2ProtocolGuid,
+ EFI_NATIVE_INTERFACE,
+ &FvDevice->Fv
+ );
ASSERT_EFI_ERROR (Status);
} else {
//
@@ -696,8 +695,6 @@ NotifyFwVolBlock ( return;
}
-
-
/**
This routine is the driver initialization entry point. It registers
a notification function. This notification function are responsible
@@ -712,8 +709,8 @@ NotifyFwVolBlock ( EFI_STATUS
EFIAPI
FwVolDriverInit (
- IN EFI_HANDLE ImageHandle,
- IN EFI_SYSTEM_TABLE *SystemTable
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
)
{
gEfiFwVolBlockEvent = EfiCreateProtocolNotifyEvent (
diff --git a/MdeModulePkg/Core/Dxe/FwVol/FwVolAttrib.c b/MdeModulePkg/Core/Dxe/FwVol/FwVolAttrib.c index ab7b3feff3..eed9f86305 100644 --- a/MdeModulePkg/Core/Dxe/FwVol/FwVolAttrib.c +++ b/MdeModulePkg/Core/Dxe/FwVol/FwVolAttrib.c @@ -9,7 +9,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include "DxeMain.h"
#include "FwVolDriver.h"
-
/**
Retrieves attributes, insures positive polarity of attribute bits, returns
resulting attributes in output parameter.
@@ -23,17 +22,17 @@ SPDX-License-Identifier: BSD-2-Clause-Patent EFI_STATUS
EFIAPI
FvGetVolumeAttributes (
- IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This,
- OUT EFI_FV_ATTRIBUTES *Attributes
+ IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This,
+ OUT EFI_FV_ATTRIBUTES *Attributes
)
{
- EFI_STATUS Status;
- FV_DEVICE *FvDevice;
- EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *Fvb;
- EFI_FVB_ATTRIBUTES_2 FvbAttributes;
+ EFI_STATUS Status;
+ FV_DEVICE *FvDevice;
+ EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *Fvb;
+ EFI_FVB_ATTRIBUTES_2 FvbAttributes;
FvDevice = FV_DEVICE_FROM_THIS (This);
- Fvb = FvDevice->Fvb;
+ Fvb = FvDevice->Fvb;
//
// First get the Firmware Volume Block Attributes
@@ -50,8 +49,6 @@ FvGetVolumeAttributes ( return Status;
}
-
-
/**
Sets current attributes for volume
@@ -72,7 +69,6 @@ FvSetVolumeAttributes ( return EFI_UNSUPPORTED;
}
-
/**
Return information of type InformationType for the requested firmware
volume.
@@ -89,17 +85,15 @@ FvSetVolumeAttributes ( EFI_STATUS
EFIAPI
FvGetVolumeInfo (
- IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This,
- IN CONST EFI_GUID *InformationType,
- IN OUT UINTN *BufferSize,
- OUT VOID *Buffer
+ IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This,
+ IN CONST EFI_GUID *InformationType,
+ IN OUT UINTN *BufferSize,
+ OUT VOID *Buffer
)
{
return EFI_UNSUPPORTED;
}
-
-
/**
Set information of type InformationType for the requested firmware
volume.
@@ -116,14 +110,11 @@ FvGetVolumeInfo ( EFI_STATUS
EFIAPI
FvSetVolumeInfo (
- IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This,
- IN CONST EFI_GUID *InformationType,
- IN UINTN BufferSize,
- IN CONST VOID *Buffer
+ IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This,
+ IN CONST EFI_GUID *InformationType,
+ IN UINTN BufferSize,
+ IN CONST VOID *Buffer
)
{
return EFI_UNSUPPORTED;
}
-
-
-
diff --git a/MdeModulePkg/Core/Dxe/FwVol/FwVolDriver.h b/MdeModulePkg/Core/Dxe/FwVol/FwVolDriver.h index 19ad39871e..3403c812b2 100644 --- a/MdeModulePkg/Core/Dxe/FwVol/FwVolDriver.h +++ b/MdeModulePkg/Core/Dxe/FwVol/FwVolDriver.h @@ -10,40 +10,39 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #ifndef __FW_VOL_DRIVER_H_
#define __FW_VOL_DRIVER_H_
-
-#define FV2_DEVICE_SIGNATURE SIGNATURE_32 ('_', 'F', 'V', '2')
+#define FV2_DEVICE_SIGNATURE SIGNATURE_32 ('_', 'F', 'V', '2')
//
// Used to track all non-deleted files
//
typedef struct {
- LIST_ENTRY Link;
- EFI_FFS_FILE_HEADER *FfsHeader;
- UINTN StreamHandle;
- BOOLEAN FileCached;
+ LIST_ENTRY Link;
+ EFI_FFS_FILE_HEADER *FfsHeader;
+ UINTN StreamHandle;
+ BOOLEAN FileCached;
} FFS_FILE_LIST_ENTRY;
typedef struct {
- UINTN Signature;
- EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *Fvb;
- EFI_HANDLE Handle;
- EFI_FIRMWARE_VOLUME2_PROTOCOL Fv;
+ UINTN Signature;
+ EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *Fvb;
+ EFI_HANDLE Handle;
+ EFI_FIRMWARE_VOLUME2_PROTOCOL Fv;
- EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader;
- UINT8 *CachedFv;
- UINT8 *EndOfCachedFv;
+ EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader;
+ UINT8 *CachedFv;
+ UINT8 *EndOfCachedFv;
- FFS_FILE_LIST_ENTRY *LastKey;
+ FFS_FILE_LIST_ENTRY *LastKey;
- LIST_ENTRY FfsFileListHeader;
+ LIST_ENTRY FfsFileListHeader;
- UINT32 AuthenticationStatus;
- UINT8 ErasePolarity;
- BOOLEAN IsFfs3Fv;
- BOOLEAN IsMemoryMapped;
+ UINT32 AuthenticationStatus;
+ UINT8 ErasePolarity;
+ BOOLEAN IsFfs3Fv;
+ BOOLEAN IsMemoryMapped;
} FV_DEVICE;
-#define FV_DEVICE_FROM_THIS(a) CR(a, FV_DEVICE, Fv, FV2_DEVICE_SIGNATURE)
+#define FV_DEVICE_FROM_THIS(a) CR(a, FV_DEVICE, Fv, FV2_DEVICE_SIGNATURE)
/**
Retrieves attributes, insures positive polarity of attribute bits, returns
@@ -58,11 +57,10 @@ typedef struct { EFI_STATUS
EFIAPI
FvGetVolumeAttributes (
- IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This,
- OUT EFI_FV_ATTRIBUTES *Attributes
+ IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This,
+ OUT EFI_FV_ATTRIBUTES *Attributes
);
-
/**
Sets current attributes for volume
@@ -80,7 +78,6 @@ FvSetVolumeAttributes ( IN OUT EFI_FV_ATTRIBUTES *Attributes
);
-
/**
Given the input key, search for the next matching file in the volume.
@@ -130,16 +127,14 @@ FvSetVolumeAttributes ( EFI_STATUS
EFIAPI
FvGetNextFile (
- IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This,
- IN OUT VOID *Key,
- IN OUT EFI_FV_FILETYPE *FileType,
- OUT EFI_GUID *NameGuid,
- OUT EFI_FV_FILE_ATTRIBUTES *Attributes,
- OUT UINTN *Size
+ IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This,
+ IN OUT VOID *Key,
+ IN OUT EFI_FV_FILETYPE *FileType,
+ OUT EFI_GUID *NameGuid,
+ OUT EFI_FV_FILE_ATTRIBUTES *Attributes,
+ OUT UINTN *Size
);
-
-
/**
Locates a file in the firmware volume and
copies it to the supplied buffer.
@@ -183,16 +178,15 @@ FvGetNextFile ( EFI_STATUS
EFIAPI
FvReadFile (
- IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This,
- IN CONST EFI_GUID *NameGuid,
- IN OUT VOID **Buffer,
- IN OUT UINTN *BufferSize,
- OUT EFI_FV_FILETYPE *FoundType,
- OUT EFI_FV_FILE_ATTRIBUTES *FileAttributes,
- OUT UINT32 *AuthenticationStatus
+ IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This,
+ IN CONST EFI_GUID *NameGuid,
+ IN OUT VOID **Buffer,
+ IN OUT UINTN *BufferSize,
+ OUT EFI_FV_FILETYPE *FoundType,
+ OUT EFI_FV_FILE_ATTRIBUTES *FileAttributes,
+ OUT UINT32 *AuthenticationStatus
);
-
/**
Locates a section in a given FFS File and
copies it to the supplied buffer (not including section header).
@@ -233,7 +227,6 @@ FvReadFileSection ( OUT UINT32 *AuthenticationStatus
);
-
/**
Writes one or more files to the firmware volume.
@@ -264,7 +257,6 @@ FvWriteFile ( IN EFI_FV_WRITE_FILE_DATA *FileData
);
-
/**
Return information of type InformationType for the requested firmware
volume.
@@ -281,14 +273,12 @@ FvWriteFile ( EFI_STATUS
EFIAPI
FvGetVolumeInfo (
- IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This,
- IN CONST EFI_GUID *InformationType,
- IN OUT UINTN *BufferSize,
- OUT VOID *Buffer
+ IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This,
+ IN CONST EFI_GUID *InformationType,
+ IN OUT UINTN *BufferSize,
+ OUT VOID *Buffer
);
-
-
/**
Set information of type InformationType for the requested firmware
volume.
@@ -305,14 +295,12 @@ FvGetVolumeInfo ( EFI_STATUS
EFIAPI
FvSetVolumeInfo (
- IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This,
- IN CONST EFI_GUID *InformationType,
- IN UINTN BufferSize,
- IN CONST VOID *Buffer
+ IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This,
+ IN CONST EFI_GUID *InformationType,
+ IN UINTN BufferSize,
+ IN CONST VOID *Buffer
);
-
-
/**
Check if a block of buffer is erased.
@@ -326,12 +314,11 @@ FvSetVolumeInfo ( **/
BOOLEAN
IsBufferErased (
- IN UINT8 ErasePolarity,
- IN VOID *InBuffer,
- IN UINTN BufferSize
+ IN UINT8 ErasePolarity,
+ IN VOID *InBuffer,
+ IN UINTN BufferSize
);
-
/**
Get the FFS file state by checking the highest bit set in the header's state field.
@@ -347,7 +334,6 @@ GetFileState ( IN EFI_FFS_FILE_HEADER *FfsHeader
);
-
/**
Set the FFS file state.
@@ -381,7 +367,6 @@ IsValidFfsHeader ( OUT EFI_FFS_FILE_STATE *FileState
);
-
/**
Check if it's a valid FFS file.
Here we are sure that it has a valid FFS file header since we must call IsValidFfsHeader() first.
diff --git a/MdeModulePkg/Core/Dxe/FwVol/FwVolRead.c b/MdeModulePkg/Core/Dxe/FwVol/FwVolRead.c index 8dcbbeb5ee..2ff22c93aa 100644 --- a/MdeModulePkg/Core/Dxe/FwVol/FwVolRead.c +++ b/MdeModulePkg/Core/Dxe/FwVol/FwVolRead.c @@ -29,8 +29,8 @@ Required Alignment Alignment Value in FFS FFS_ATTRIB_DATA_ALIGNMENT2 Align 8 MB 6 1 23
16 MB 7 1 24
**/
-UINT8 mFvAttributes[] = {0, 4, 7, 9, 10, 12, 15, 16};
-UINT8 mFvAttributes2[] = {17, 18, 19, 20, 21, 22, 23, 24};
+UINT8 mFvAttributes[] = { 0, 4, 7, 9, 10, 12, 15, 16 };
+UINT8 mFvAttributes2[] = { 17, 18, 19, 20, 21, 22, 23, 24 };
/**
Convert the FFS File Attributes to FV File Attributes
@@ -42,19 +42,19 @@ UINT8 mFvAttributes2[] = {17, 18, 19, 20, 21, 22, 23, 24}; **/
EFI_FV_FILE_ATTRIBUTES
FfsAttributes2FvFileAttributes (
- IN EFI_FFS_FILE_ATTRIBUTES FfsAttributes
+ IN EFI_FFS_FILE_ATTRIBUTES FfsAttributes
)
{
- UINT8 DataAlignment;
- EFI_FV_FILE_ATTRIBUTES FileAttribute;
+ UINT8 DataAlignment;
+ EFI_FV_FILE_ATTRIBUTES FileAttribute;
- DataAlignment = (UINT8) ((FfsAttributes & FFS_ATTRIB_DATA_ALIGNMENT) >> 3);
+ DataAlignment = (UINT8)((FfsAttributes & FFS_ATTRIB_DATA_ALIGNMENT) >> 3);
ASSERT (DataAlignment < 8);
if ((FfsAttributes & FFS_ATTRIB_DATA_ALIGNMENT_2) != 0) {
- FileAttribute = (EFI_FV_FILE_ATTRIBUTES) mFvAttributes2[DataAlignment];
+ FileAttribute = (EFI_FV_FILE_ATTRIBUTES)mFvAttributes2[DataAlignment];
} else {
- FileAttribute = (EFI_FV_FILE_ATTRIBUTES) mFvAttributes[DataAlignment];
+ FileAttribute = (EFI_FV_FILE_ATTRIBUTES)mFvAttributes[DataAlignment];
}
if ((FfsAttributes & FFS_ATTRIB_FIXED) == FFS_ATTRIB_FIXED) {
@@ -113,26 +113,26 @@ FfsAttributes2FvFileAttributes ( EFI_STATUS
EFIAPI
FvGetNextFile (
- IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This,
- IN OUT VOID *Key,
- IN OUT EFI_FV_FILETYPE *FileType,
- OUT EFI_GUID *NameGuid,
- OUT EFI_FV_FILE_ATTRIBUTES *Attributes,
- OUT UINTN *Size
+ IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This,
+ IN OUT VOID *Key,
+ IN OUT EFI_FV_FILETYPE *FileType,
+ OUT EFI_GUID *NameGuid,
+ OUT EFI_FV_FILE_ATTRIBUTES *Attributes,
+ OUT UINTN *Size
)
{
- EFI_STATUS Status;
- FV_DEVICE *FvDevice;
- EFI_FV_ATTRIBUTES FvAttributes;
- EFI_FFS_FILE_HEADER *FfsFileHeader;
- UINTN *KeyValue;
- LIST_ENTRY *Link;
- FFS_FILE_LIST_ENTRY *FfsFileEntry;
+ EFI_STATUS Status;
+ FV_DEVICE *FvDevice;
+ EFI_FV_ATTRIBUTES FvAttributes;
+ EFI_FFS_FILE_HEADER *FfsFileHeader;
+ UINTN *KeyValue;
+ LIST_ENTRY *Link;
+ FFS_FILE_LIST_ENTRY *FfsFileEntry;
FvDevice = FV_DEVICE_FROM_THIS (This);
Status = FvGetVolumeAttributes (This, &FvAttributes);
- if (EFI_ERROR (Status)){
+ if (EFI_ERROR (Status)) {
return Status;
}
@@ -151,7 +151,7 @@ FvGetNextFile ( }
KeyValue = (UINTN *)Key;
- for (;;) {
+ for ( ; ;) {
if (*KeyValue == 0) {
//
// Search for 1st matching file
@@ -171,7 +171,7 @@ FvGetNextFile ( return EFI_NOT_FOUND;
}
- FfsFileEntry = (FFS_FILE_LIST_ENTRY *)Link->ForwardLink;
+ FfsFileEntry = (FFS_FILE_LIST_ENTRY *)Link->ForwardLink;
FfsFileHeader = (EFI_FFS_FILE_HEADER *)FfsFileEntry->FfsHeader;
//
@@ -199,7 +199,6 @@ FvGetNextFile ( //
break;
}
-
}
//
@@ -224,8 +223,6 @@ FvGetNextFile ( return EFI_SUCCESS;
}
-
-
/**
Locates a file in the firmware volume and
copies it to the supplied buffer.
@@ -269,25 +266,25 @@ FvGetNextFile ( EFI_STATUS
EFIAPI
FvReadFile (
- IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This,
- IN CONST EFI_GUID *NameGuid,
- IN OUT VOID **Buffer,
- IN OUT UINTN *BufferSize,
- OUT EFI_FV_FILETYPE *FoundType,
- OUT EFI_FV_FILE_ATTRIBUTES *FileAttributes,
- OUT UINT32 *AuthenticationStatus
+ IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This,
+ IN CONST EFI_GUID *NameGuid,
+ IN OUT VOID **Buffer,
+ IN OUT UINTN *BufferSize,
+ OUT EFI_FV_FILETYPE *FoundType,
+ OUT EFI_FV_FILE_ATTRIBUTES *FileAttributes,
+ OUT UINT32 *AuthenticationStatus
)
{
- EFI_STATUS Status;
- FV_DEVICE *FvDevice;
- EFI_GUID SearchNameGuid;
- EFI_FV_FILETYPE LocalFoundType;
- EFI_FV_FILE_ATTRIBUTES LocalAttributes;
- UINTN FileSize;
- UINT8 *SrcPtr;
- EFI_FFS_FILE_HEADER *FfsHeader;
- UINTN InputBufferSize;
- UINTN WholeFileSize;
+ EFI_STATUS Status;
+ FV_DEVICE *FvDevice;
+ EFI_GUID SearchNameGuid;
+ EFI_FV_FILETYPE LocalFoundType;
+ EFI_FV_FILE_ATTRIBUTES LocalAttributes;
+ UINTN FileSize;
+ UINT8 *SrcPtr;
+ EFI_FFS_FILE_HEADER *FfsHeader;
+ UINTN InputBufferSize;
+ UINTN WholeFileSize;
if (NameGuid == NULL) {
return EFI_INVALID_PARAMETER;
@@ -295,7 +292,6 @@ FvReadFile ( FvDevice = FV_DEVICE_FROM_THIS (This);
-
//
// Keep looking until we find the matching NameGuid.
// The Key is really a FfsFileEntry
@@ -303,14 +299,14 @@ FvReadFile ( FvDevice->LastKey = 0;
do {
LocalFoundType = 0;
- Status = FvGetNextFile (
- This,
- &FvDevice->LastKey,
- &LocalFoundType,
- &SearchNameGuid,
- &LocalAttributes,
- &FileSize
- );
+ Status = FvGetNextFile (
+ This,
+ &FvDevice->LastKey,
+ &LocalFoundType,
+ &SearchNameGuid,
+ &LocalAttributes,
+ &FileSize
+ );
if (EFI_ERROR (Status)) {
return EFI_NOT_FOUND;
}
@@ -328,15 +324,16 @@ FvReadFile ( //
// Cache FFS file to memory buffer.
//
- WholeFileSize = IS_FFS_FILE2 (FfsHeader) ? FFS_FILE2_SIZE (FfsHeader): FFS_FILE_SIZE (FfsHeader);
- FfsHeader = AllocateCopyPool (WholeFileSize, FfsHeader);
+ WholeFileSize = IS_FFS_FILE2 (FfsHeader) ? FFS_FILE2_SIZE (FfsHeader) : FFS_FILE_SIZE (FfsHeader);
+ FfsHeader = AllocateCopyPool (WholeFileSize, FfsHeader);
if (FfsHeader == NULL) {
return EFI_OUT_OF_RESOURCES;
}
+
//
// Let FfsHeader in FfsFileEntry point to the cached file buffer.
//
- FvDevice->LastKey->FfsHeader = FfsHeader;
+ FvDevice->LastKey->FfsHeader = FfsHeader;
FvDevice->LastKey->FileCached = TRUE;
}
}
@@ -349,16 +346,17 @@ FvReadFile ( //
// Calculate return values
//
- *FoundType = FfsHeader->Type;
+ *FoundType = FfsHeader->Type;
*FileAttributes = FfsAttributes2FvFileAttributes (FfsHeader->Attributes);
- if ((FvDevice->FwVolHeader->Attributes & EFI_FVB2_MEMORY_MAPPED) == EFI_FVB2_MEMORY_MAPPED) {
- *FileAttributes |= EFI_FV_FILE_ATTRIB_MEMORY_MAPPED;
- }
+ if ((FvDevice->FwVolHeader->Attributes & EFI_FVB2_MEMORY_MAPPED) == EFI_FVB2_MEMORY_MAPPED) {
+ *FileAttributes |= EFI_FV_FILE_ATTRIB_MEMORY_MAPPED;
+ }
+
//
// Inherit the authentication status.
//
*AuthenticationStatus = FvDevice->AuthenticationStatus;
- *BufferSize = FileSize;
+ *BufferSize = FileSize;
if (Buffer == NULL) {
//
@@ -371,9 +369,9 @@ FvReadFile ( // Skip over file header
//
if (IS_FFS_FILE2 (FfsHeader)) {
- SrcPtr = ((UINT8 *) FfsHeader) + sizeof (EFI_FFS_FILE_HEADER2);
+ SrcPtr = ((UINT8 *)FfsHeader) + sizeof (EFI_FFS_FILE_HEADER2);
} else {
- SrcPtr = ((UINT8 *) FfsHeader) + sizeof (EFI_FFS_FILE_HEADER);
+ SrcPtr = ((UINT8 *)FfsHeader) + sizeof (EFI_FFS_FILE_HEADER);
}
Status = EFI_SUCCESS;
@@ -389,7 +387,7 @@ FvReadFile ( //
// Callers buffer was not big enough
//
- Status = EFI_WARN_BUFFER_TOO_SMALL;
+ Status = EFI_WARN_BUFFER_TOO_SMALL;
FileSize = InputBufferSize;
}
@@ -401,8 +399,6 @@ FvReadFile ( return Status;
}
-
-
/**
Locates a section in a given FFS File and
copies it to the supplied buffer (not including section header).
@@ -443,15 +439,15 @@ FvReadFileSection ( OUT UINT32 *AuthenticationStatus
)
{
- EFI_STATUS Status;
- FV_DEVICE *FvDevice;
- EFI_FV_FILETYPE FileType;
- EFI_FV_FILE_ATTRIBUTES FileAttributes;
- UINTN FileSize;
- UINT8 *FileBuffer;
- FFS_FILE_LIST_ENTRY *FfsEntry;
-
- if (NameGuid == NULL || Buffer == NULL) {
+ EFI_STATUS Status;
+ FV_DEVICE *FvDevice;
+ EFI_FV_FILETYPE FileType;
+ EFI_FV_FILE_ATTRIBUTES FileAttributes;
+ UINTN FileSize;
+ UINT8 *FileBuffer;
+ FFS_FILE_LIST_ENTRY *FfsEntry;
+
+ if ((NameGuid == NULL) || (Buffer == NULL)) {
return EFI_INVALID_PARAMETER;
}
@@ -461,27 +457,29 @@ FvReadFileSection ( // Read the file
//
Status = FvReadFile (
- This,
- NameGuid,
- NULL,
- &FileSize,
- &FileType,
- &FileAttributes,
- AuthenticationStatus
- );
+ This,
+ NameGuid,
+ NULL,
+ &FileSize,
+ &FileType,
+ &FileAttributes,
+ AuthenticationStatus
+ );
//
// Get the last key used by our call to FvReadFile as it is the FfsEntry for this file.
//
- FfsEntry = (FFS_FILE_LIST_ENTRY *) FvDevice->LastKey;
+ FfsEntry = (FFS_FILE_LIST_ENTRY *)FvDevice->LastKey;
if (EFI_ERROR (Status)) {
return Status;
}
+
if (IS_FFS_FILE2 (FfsEntry->FfsHeader)) {
- FileBuffer = ((UINT8 *) FfsEntry->FfsHeader) + sizeof (EFI_FFS_FILE_HEADER2);
+ FileBuffer = ((UINT8 *)FfsEntry->FfsHeader) + sizeof (EFI_FFS_FILE_HEADER2);
} else {
- FileBuffer = ((UINT8 *) FfsEntry->FfsHeader) + sizeof (EFI_FFS_FILE_HEADER);
+ FileBuffer = ((UINT8 *)FfsEntry->FfsHeader) + sizeof (EFI_FFS_FILE_HEADER);
}
+
//
// Check to see that the file actually HAS sections before we go any further.
//
@@ -532,5 +530,3 @@ FvReadFileSection ( Done:
return Status;
}
-
-
diff --git a/MdeModulePkg/Core/Dxe/FwVol/FwVolWrite.c b/MdeModulePkg/Core/Dxe/FwVol/FwVolWrite.c index 3a3b569b74..6e3a59bc4c 100644 --- a/MdeModulePkg/Core/Dxe/FwVol/FwVolWrite.c +++ b/MdeModulePkg/Core/Dxe/FwVol/FwVolWrite.c @@ -9,7 +9,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include "DxeMain.h"
#include "FwVolDriver.h"
-
/**
Writes one or more files to the firmware volume.
@@ -42,5 +41,3 @@ FvWriteFile ( {
return EFI_UNSUPPORTED;
}
-
-
diff --git a/MdeModulePkg/Core/Dxe/FwVolBlock/FwVolBlock.c b/MdeModulePkg/Core/Dxe/FwVolBlock/FwVolBlock.c index 95174c1e46..d81334ce24 100644 --- a/MdeModulePkg/Core/Dxe/FwVolBlock/FwVolBlock.c +++ b/MdeModulePkg/Core/Dxe/FwVolBlock/FwVolBlock.c @@ -12,7 +12,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include "DxeMain.h"
#include "FwVolBlock.h"
-FV_MEMMAP_DEVICE_PATH mFvMemmapDevicePathTemplate = {
+FV_MEMMAP_DEVICE_PATH mFvMemmapDevicePathTemplate = {
{
{
HARDWARE_DEVICE_PATH,
@@ -23,8 +23,8 @@ FV_MEMMAP_DEVICE_PATH mFvMemmapDevicePathTemplate = { }
},
EfiMemoryMappedIO,
- (EFI_PHYSICAL_ADDRESS) 0,
- (EFI_PHYSICAL_ADDRESS) 0,
+ (EFI_PHYSICAL_ADDRESS)0,
+ (EFI_PHYSICAL_ADDRESS)0,
},
{
END_DEVICE_PATH_TYPE,
@@ -36,7 +36,7 @@ FV_MEMMAP_DEVICE_PATH mFvMemmapDevicePathTemplate = { }
};
-FV_PIWG_DEVICE_PATH mFvPIWGDevicePathTemplate = {
+FV_PIWG_DEVICE_PATH mFvPIWGDevicePathTemplate = {
{
{
MEDIA_DEVICE_PATH,
@@ -79,8 +79,6 @@ EFI_FW_VOL_BLOCK_DEVICE mFwVolBlock = { 0
};
-
-
/**
Retrieves Volume attributes. No polarity translations are done.
@@ -97,7 +95,7 @@ FwVolBlockGetAttributes ( OUT EFI_FVB_ATTRIBUTES_2 *Attributes
)
{
- EFI_FW_VOL_BLOCK_DEVICE *FvbDevice;
+ EFI_FW_VOL_BLOCK_DEVICE *FvbDevice;
FvbDevice = FVB_DEVICE_FROM_THIS (This);
@@ -109,8 +107,6 @@ FwVolBlockGetAttributes ( return EFI_SUCCESS;
}
-
-
/**
Modifies the current settings of the firmware volume according to the input parameter.
@@ -134,8 +130,6 @@ FwVolBlockSetAttributes ( return EFI_UNSUPPORTED;
}
-
-
/**
The EraseBlock() function erases one or more blocks as denoted by the
variable argument list. The entire parameter list of blocks must be verified
@@ -162,15 +156,13 @@ FwVolBlockSetAttributes ( EFI_STATUS
EFIAPI
FwVolBlockEraseBlock (
- IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This,
+ IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This,
...
)
{
return EFI_UNSUPPORTED;
}
-
-
/**
Read the specified number of bytes from the block to the input buffer.
@@ -194,19 +186,19 @@ FwVolBlockEraseBlock ( EFI_STATUS
EFIAPI
FwVolBlockReadBlock (
- IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This,
- IN CONST EFI_LBA Lba,
- IN CONST UINTN Offset,
- IN OUT UINTN *NumBytes,
- IN OUT UINT8 *Buffer
+ IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This,
+ IN CONST EFI_LBA Lba,
+ IN CONST UINTN Offset,
+ IN OUT UINTN *NumBytes,
+ IN OUT UINT8 *Buffer
)
{
- EFI_FW_VOL_BLOCK_DEVICE *FvbDevice;
- EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader;
- UINT8 *LbaOffset;
- UINTN LbaStart;
- UINTN NumOfBytesRead;
- UINTN LbaIndex;
+ EFI_FW_VOL_BLOCK_DEVICE *FvbDevice;
+ EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader;
+ UINT8 *LbaOffset;
+ UINTN LbaStart;
+ UINTN NumOfBytesRead;
+ UINTN LbaIndex;
FvbDevice = FVB_DEVICE_FROM_THIS (This);
@@ -217,7 +209,7 @@ FwVolBlockReadBlock ( return EFI_ACCESS_DENIED;
}
- LbaIndex = (UINTN) Lba;
+ LbaIndex = (UINTN)Lba;
if (LbaIndex >= FvbDevice->NumBlocks) {
//
// Invalid Lba, read nothing.
@@ -242,9 +234,9 @@ FwVolBlockReadBlock ( NumOfBytesRead = FvbDevice->LbaCache[LbaIndex].Length - Offset;
}
- LbaStart = FvbDevice->LbaCache[LbaIndex].Base;
- FwVolHeader = (EFI_FIRMWARE_VOLUME_HEADER *)((UINTN) FvbDevice->BaseAddress);
- LbaOffset = (UINT8 *) FwVolHeader + LbaStart + Offset;
+ LbaStart = FvbDevice->LbaCache[LbaIndex].Base;
+ FwVolHeader = (EFI_FIRMWARE_VOLUME_HEADER *)((UINTN)FvbDevice->BaseAddress);
+ LbaOffset = (UINT8 *)FwVolHeader + LbaStart + Offset;
//
// Perform read operation
@@ -259,8 +251,6 @@ FwVolBlockReadBlock ( return EFI_BAD_BUFFER_SIZE;
}
-
-
/**
Writes the specified number of bytes from the input buffer to the block.
@@ -288,18 +278,16 @@ FwVolBlockReadBlock ( EFI_STATUS
EFIAPI
FwVolBlockWriteBlock (
- IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This,
- IN EFI_LBA Lba,
- IN UINTN Offset,
- IN OUT UINTN *NumBytes,
- IN UINT8 *Buffer
+ IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This,
+ IN EFI_LBA Lba,
+ IN UINTN Offset,
+ IN OUT UINTN *NumBytes,
+ IN UINT8 *Buffer
)
{
return EFI_UNSUPPORTED;
}
-
-
/**
Get Fvb's base address.
@@ -317,7 +305,7 @@ FwVolBlockGetPhysicalAddress ( OUT EFI_PHYSICAL_ADDRESS *Address
)
{
- EFI_FW_VOL_BLOCK_DEVICE *FvbDevice;
+ EFI_FW_VOL_BLOCK_DEVICE *FvbDevice;
FvbDevice = FVB_DEVICE_FROM_THIS (This);
@@ -329,8 +317,6 @@ FwVolBlockGetPhysicalAddress ( return EFI_UNSUPPORTED;
}
-
-
/**
Retrieves the size in bytes of a specific block within a firmware volume.
@@ -357,10 +343,10 @@ FwVolBlockGetBlockSize ( IN OUT UINTN *NumberOfBlocks
)
{
- UINTN TotalBlocks;
- EFI_FW_VOL_BLOCK_DEVICE *FvbDevice;
- EFI_FV_BLOCK_MAP_ENTRY *PtrBlockMapEntry;
- EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader;
+ UINTN TotalBlocks;
+ EFI_FW_VOL_BLOCK_DEVICE *FvbDevice;
+ EFI_FV_BLOCK_MAP_ENTRY *PtrBlockMapEntry;
+ EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader;
FvbDevice = FVB_DEVICE_FROM_THIS (This);
@@ -379,7 +365,7 @@ FwVolBlockGetBlockSize ( // Search the block map for the given block
//
TotalBlocks = 0;
- while ((PtrBlockMapEntry->NumBlocks != 0) || (PtrBlockMapEntry->Length !=0 )) {
+ while ((PtrBlockMapEntry->NumBlocks != 0) || (PtrBlockMapEntry->Length != 0)) {
TotalBlocks += PtrBlockMapEntry->NumBlocks;
if (Lba < TotalBlocks) {
//
@@ -391,7 +377,7 @@ FwVolBlockGetBlockSize ( PtrBlockMapEntry++;
}
- *BlockSize = PtrBlockMapEntry->Length;
+ *BlockSize = PtrBlockMapEntry->Length;
*NumberOfBlocks = TotalBlocks - (UINTN)Lba;
return EFI_SUCCESS;
@@ -408,14 +394,14 @@ FwVolBlockGetBlockSize ( **/
UINT32
GetFvbAuthenticationStatus (
- IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *FvbProtocol
+ IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *FvbProtocol
)
{
- EFI_FW_VOL_BLOCK_DEVICE *FvbDevice;
- UINT32 AuthenticationStatus;
+ EFI_FW_VOL_BLOCK_DEVICE *FvbDevice;
+ UINT32 AuthenticationStatus;
AuthenticationStatus = 0;
- FvbDevice = BASE_CR (FvbProtocol, EFI_FW_VOL_BLOCK_DEVICE, FwVolBlockInstance);
+ FvbDevice = BASE_CR (FvbProtocol, EFI_FW_VOL_BLOCK_DEVICE, FwVolBlockInstance);
if (FvbDevice->Signature == FVB_DEVICE_SIGNATURE) {
AuthenticationStatus = FvbDevice->AuthenticationStatus;
}
@@ -444,24 +430,24 @@ GetFvbAuthenticationStatus ( **/
EFI_STATUS
ProduceFVBProtocolOnBuffer (
- IN EFI_PHYSICAL_ADDRESS BaseAddress,
- IN UINT64 Length,
- IN EFI_HANDLE ParentHandle,
- IN UINT32 AuthenticationStatus,
- OUT EFI_HANDLE *FvProtocol OPTIONAL
+ IN EFI_PHYSICAL_ADDRESS BaseAddress,
+ IN UINT64 Length,
+ IN EFI_HANDLE ParentHandle,
+ IN UINT32 AuthenticationStatus,
+ OUT EFI_HANDLE *FvProtocol OPTIONAL
)
{
- EFI_STATUS Status;
- EFI_FW_VOL_BLOCK_DEVICE *FvbDev;
- EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader;
- UINTN BlockIndex;
- UINTN BlockIndex2;
- UINTN LinearOffset;
- UINT32 FvAlignment;
- EFI_FV_BLOCK_MAP_ENTRY *PtrBlockMapEntry;
+ EFI_STATUS Status;
+ EFI_FW_VOL_BLOCK_DEVICE *FvbDev;
+ EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader;
+ UINTN BlockIndex;
+ UINTN BlockIndex2;
+ UINTN LinearOffset;
+ UINT32 FvAlignment;
+ EFI_FV_BLOCK_MAP_ENTRY *PtrBlockMapEntry;
FvAlignment = 0;
- FwVolHeader = (EFI_FIRMWARE_VOLUME_HEADER *)(UINTN) BaseAddress;
+ FwVolHeader = (EFI_FIRMWARE_VOLUME_HEADER *)(UINTN)BaseAddress;
//
// Validate FV Header, if not as expected, return
//
@@ -485,6 +471,7 @@ ProduceFVBProtocolOnBuffer ( if (FvAlignment < 8) {
FvAlignment = 8;
}
+
if ((UINTN)BaseAddress % FvAlignment != 0) {
//
// FvImage buffer is not at its required alignment.
@@ -508,10 +495,10 @@ ProduceFVBProtocolOnBuffer ( return EFI_OUT_OF_RESOURCES;
}
- FvbDev->BaseAddress = BaseAddress;
- FvbDev->FvbAttributes = FwVolHeader->Attributes;
+ FvbDev->BaseAddress = BaseAddress;
+ FvbDev->FvbAttributes = FwVolHeader->Attributes;
FvbDev->FwVolBlockInstance.ParentHandle = ParentHandle;
- FvbDev->AuthenticationStatus = AuthenticationStatus;
+ FvbDev->AuthenticationStatus = AuthenticationStatus;
//
// Init the block caching fields of the device
@@ -520,7 +507,8 @@ ProduceFVBProtocolOnBuffer ( FvbDev->NumBlocks = 0;
for (PtrBlockMapEntry = FwVolHeader->BlockMap;
PtrBlockMapEntry->NumBlocks != 0;
- PtrBlockMapEntry++) {
+ PtrBlockMapEntry++)
+ {
FvbDev->NumBlocks += PtrBlockMapEntry->NumBlocks;
}
@@ -531,6 +519,7 @@ ProduceFVBProtocolOnBuffer ( CoreFreePool (FvbDev);
return EFI_OUT_OF_RESOURCES;
}
+
FvbDev->LbaCache = AllocatePool (FvbDev->NumBlocks * sizeof (LBA_CACHE));
if (FvbDev->LbaCache == NULL) {
CoreFreePool (FvbDev);
@@ -540,14 +529,15 @@ ProduceFVBProtocolOnBuffer ( //
// Last, fill in the cache with the linear address of the blocks
//
- BlockIndex = 0;
+ BlockIndex = 0;
LinearOffset = 0;
for (PtrBlockMapEntry = FwVolHeader->BlockMap;
- PtrBlockMapEntry->NumBlocks != 0; PtrBlockMapEntry++) {
+ PtrBlockMapEntry->NumBlocks != 0; PtrBlockMapEntry++)
+ {
for (BlockIndex2 = 0; BlockIndex2 < PtrBlockMapEntry->NumBlocks; BlockIndex2++) {
- FvbDev->LbaCache[BlockIndex].Base = LinearOffset;
+ FvbDev->LbaCache[BlockIndex].Base = LinearOffset;
FvbDev->LbaCache[BlockIndex].Length = PtrBlockMapEntry->Length;
- LinearOffset += PtrBlockMapEntry->Length;
+ LinearOffset += PtrBlockMapEntry->Length;
BlockIndex++;
}
}
@@ -559,22 +549,24 @@ ProduceFVBProtocolOnBuffer ( //
// FV does not contains extension header, then produce MEMMAP_DEVICE_PATH
//
- FvbDev->DevicePath = (EFI_DEVICE_PATH_PROTOCOL *) AllocateCopyPool (sizeof (FV_MEMMAP_DEVICE_PATH), &mFvMemmapDevicePathTemplate);
+ FvbDev->DevicePath = (EFI_DEVICE_PATH_PROTOCOL *)AllocateCopyPool (sizeof (FV_MEMMAP_DEVICE_PATH), &mFvMemmapDevicePathTemplate);
if (FvbDev->DevicePath == NULL) {
FreePool (FvbDev);
return EFI_OUT_OF_RESOURCES;
}
- ((FV_MEMMAP_DEVICE_PATH *) FvbDev->DevicePath)->MemMapDevPath.StartingAddress = BaseAddress;
- ((FV_MEMMAP_DEVICE_PATH *) FvbDev->DevicePath)->MemMapDevPath.EndingAddress = BaseAddress + FwVolHeader->FvLength - 1;
+
+ ((FV_MEMMAP_DEVICE_PATH *)FvbDev->DevicePath)->MemMapDevPath.StartingAddress = BaseAddress;
+ ((FV_MEMMAP_DEVICE_PATH *)FvbDev->DevicePath)->MemMapDevPath.EndingAddress = BaseAddress + FwVolHeader->FvLength - 1;
} else {
//
// FV contains extension header, then produce MEDIA_FW_VOL_DEVICE_PATH
//
- FvbDev->DevicePath = (EFI_DEVICE_PATH_PROTOCOL *) AllocateCopyPool (sizeof (FV_PIWG_DEVICE_PATH), &mFvPIWGDevicePathTemplate);
+ FvbDev->DevicePath = (EFI_DEVICE_PATH_PROTOCOL *)AllocateCopyPool (sizeof (FV_PIWG_DEVICE_PATH), &mFvPIWGDevicePathTemplate);
if (FvbDev->DevicePath == NULL) {
FreePool (FvbDev);
return EFI_OUT_OF_RESOURCES;
}
+
CopyGuid (
&((FV_PIWG_DEVICE_PATH *)FvbDev->DevicePath)->FvDevPath.FvName,
(GUID *)(UINTN)(BaseAddress + FwVolHeader->ExtHeaderOffset)
@@ -587,8 +579,10 @@ ProduceFVBProtocolOnBuffer ( //
Status = CoreInstallMultipleProtocolInterfaces (
&FvbDev->Handle,
- &gEfiFirmwareVolumeBlockProtocolGuid, &FvbDev->FwVolBlockInstance,
- &gEfiDevicePathProtocolGuid, FvbDev->DevicePath,
+ &gEfiFirmwareVolumeBlockProtocolGuid,
+ &FvbDev->FwVolBlockInstance,
+ &gEfiDevicePathProtocolGuid,
+ FvbDev->DevicePath,
NULL
);
@@ -602,8 +596,6 @@ ProduceFVBProtocolOnBuffer ( return Status;
}
-
-
/**
This routine consumes FV hobs and produces instances of FW_VOL_BLOCK_PROTOCOL as appropriate.
@@ -617,13 +609,13 @@ ProduceFVBProtocolOnBuffer ( EFI_STATUS
EFIAPI
FwVolBlockDriverInit (
- IN EFI_HANDLE ImageHandle,
- IN EFI_SYSTEM_TABLE *SystemTable
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
)
{
- EFI_PEI_HOB_POINTERS FvHob;
- EFI_PEI_HOB_POINTERS Fv3Hob;
- UINT32 AuthenticationStatus;
+ EFI_PEI_HOB_POINTERS FvHob;
+ EFI_PEI_HOB_POINTERS Fv3Hob;
+ UINT32 AuthenticationStatus;
//
// Core Needs Firmware Volumes to function
@@ -637,12 +629,15 @@ FwVolBlockDriverInit ( Fv3Hob.Raw = GetHobList ();
while ((Fv3Hob.Raw = GetNextHob (EFI_HOB_TYPE_FV3, Fv3Hob.Raw)) != NULL) {
if ((Fv3Hob.FirmwareVolume3->BaseAddress == FvHob.FirmwareVolume->BaseAddress) &&
- (Fv3Hob.FirmwareVolume3->Length == FvHob.FirmwareVolume->Length)) {
+ (Fv3Hob.FirmwareVolume3->Length == FvHob.FirmwareVolume->Length))
+ {
AuthenticationStatus = Fv3Hob.FirmwareVolume3->AuthenticationStatus;
break;
}
+
Fv3Hob.Raw = GET_NEXT_HOB (Fv3Hob);
}
+
//
// Produce an FVB protocol for it
//
@@ -653,8 +648,6 @@ FwVolBlockDriverInit ( return EFI_SUCCESS;
}
-
-
/**
This DXE service routine is used to process a firmware volume. In
particular, it can be called by BDS to process a single firmware
@@ -679,22 +672,22 @@ FwVolBlockDriverInit ( EFI_STATUS
EFIAPI
CoreProcessFirmwareVolume (
- IN VOID *FvHeader,
- IN UINTN Size,
- OUT EFI_HANDLE *FVProtocolHandle
+ IN VOID *FvHeader,
+ IN UINTN Size,
+ OUT EFI_HANDLE *FVProtocolHandle
)
{
VOID *Ptr;
EFI_STATUS Status;
*FVProtocolHandle = NULL;
- Status = ProduceFVBProtocolOnBuffer (
- (EFI_PHYSICAL_ADDRESS) (UINTN) FvHeader,
- (UINT64)Size,
- NULL,
- 0,
- FVProtocolHandle
- );
+ Status = ProduceFVBProtocolOnBuffer (
+ (EFI_PHYSICAL_ADDRESS)(UINTN)FvHeader,
+ (UINT64)Size,
+ NULL,
+ 0,
+ FVProtocolHandle
+ );
//
// Since in our implementation we use register-protocol-notify to put a
// FV protocol on the FVB protocol handle, we can't directly verify that
@@ -703,17 +696,16 @@ CoreProcessFirmwareVolume ( // well. Otherwise we have to assume that the volume was corrupted
// somehow.
//
- if (!EFI_ERROR(Status)) {
+ if (!EFI_ERROR (Status)) {
ASSERT (*FVProtocolHandle != NULL);
- Ptr = NULL;
- Status = CoreHandleProtocol (*FVProtocolHandle, &gEfiFirmwareVolume2ProtocolGuid, (VOID **) &Ptr);
- if (EFI_ERROR(Status) || (Ptr == NULL)) {
+ Ptr = NULL;
+ Status = CoreHandleProtocol (*FVProtocolHandle, &gEfiFirmwareVolume2ProtocolGuid, (VOID **)&Ptr);
+ if (EFI_ERROR (Status) || (Ptr == NULL)) {
return EFI_VOLUME_CORRUPTED;
}
+
return EFI_SUCCESS;
}
+
return Status;
}
-
-
-
diff --git a/MdeModulePkg/Core/Dxe/FwVolBlock/FwVolBlock.h b/MdeModulePkg/Core/Dxe/FwVolBlock/FwVolBlock.h index 2205e9e77d..aa2ab7f7c2 100644 --- a/MdeModulePkg/Core/Dxe/FwVolBlock/FwVolBlock.h +++ b/MdeModulePkg/Core/Dxe/FwVolBlock/FwVolBlock.h @@ -10,13 +10,11 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #ifndef _FWVOL_BLOCK_H_
#define _FWVOL_BLOCK_H_
-
-#define FVB_DEVICE_SIGNATURE SIGNATURE_32('_','F','V','B')
-
+#define FVB_DEVICE_SIGNATURE SIGNATURE_32('_','F','V','B')
typedef struct {
- UINTN Base;
- UINTN Length;
+ UINTN Base;
+ UINTN Length;
} LBA_CACHE;
typedef struct {
@@ -44,11 +42,9 @@ typedef struct { UINT32 AuthenticationStatus;
} EFI_FW_VOL_BLOCK_DEVICE;
-
#define FVB_DEVICE_FROM_THIS(a) \
CR(a, EFI_FW_VOL_BLOCK_DEVICE, FwVolBlockInstance, FVB_DEVICE_SIGNATURE)
-
/**
Retrieves Volume attributes. No polarity translations are done.
@@ -65,8 +61,6 @@ FwVolBlockGetAttributes ( OUT EFI_FVB_ATTRIBUTES_2 *Attributes
);
-
-
/**
Modifies the current settings of the firmware volume according to the input parameter.
@@ -87,8 +81,6 @@ FwVolBlockSetAttributes ( IN CONST EFI_FVB_ATTRIBUTES_2 *Attributes
);
-
-
/**
The EraseBlock() function erases one or more blocks as denoted by the
variable argument list. The entire parameter list of blocks must be verified
@@ -115,12 +107,10 @@ FwVolBlockSetAttributes ( EFI_STATUS
EFIAPI
FwVolBlockEraseBlock (
- IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This,
+ IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This,
...
);
-
-
/**
Read the specified number of bytes from the block to the input buffer.
@@ -144,15 +134,13 @@ FwVolBlockEraseBlock ( EFI_STATUS
EFIAPI
FwVolBlockReadBlock (
- IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This,
- IN CONST EFI_LBA Lba,
- IN CONST UINTN Offset,
- IN OUT UINTN *NumBytes,
- IN OUT UINT8 *Buffer
+ IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This,
+ IN CONST EFI_LBA Lba,
+ IN CONST UINTN Offset,
+ IN OUT UINTN *NumBytes,
+ IN OUT UINT8 *Buffer
);
-
-
/**
Writes the specified number of bytes from the input buffer to the block.
@@ -180,15 +168,13 @@ FwVolBlockReadBlock ( EFI_STATUS
EFIAPI
FwVolBlockWriteBlock (
- IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This,
- IN EFI_LBA Lba,
- IN UINTN Offset,
- IN OUT UINTN *NumBytes,
- IN UINT8 *Buffer
+ IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This,
+ IN EFI_LBA Lba,
+ IN UINTN Offset,
+ IN OUT UINTN *NumBytes,
+ IN UINT8 *Buffer
);
-
-
/**
Get Fvb's base address.
@@ -206,8 +192,6 @@ FwVolBlockGetPhysicalAddress ( OUT EFI_PHYSICAL_ADDRESS *Address
);
-
-
/**
Retrieves the size in bytes of a specific block within a firmware volume.
@@ -234,5 +218,4 @@ FwVolBlockGetBlockSize ( IN OUT UINTN *NumberOfBlocks
);
-
#endif
diff --git a/MdeModulePkg/Core/Dxe/Gcd/Gcd.c b/MdeModulePkg/Core/Dxe/Gcd/Gcd.c index 2224aae281..3763467bdb 100644 --- a/MdeModulePkg/Core/Dxe/Gcd/Gcd.c +++ b/MdeModulePkg/Core/Dxe/Gcd/Gcd.c @@ -12,9 +12,9 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include "Gcd.h"
#include "Mem/HeapGuard.h"
-#define MINIMUM_INITIAL_MEMORY_SIZE 0x10000
+#define MINIMUM_INITIAL_MEMORY_SIZE 0x10000
-#define MEMORY_ATTRIBUTE_MASK (EFI_RESOURCE_ATTRIBUTE_PRESENT | \
+#define MEMORY_ATTRIBUTE_MASK (EFI_RESOURCE_ATTRIBUTE_PRESENT | \
EFI_RESOURCE_ATTRIBUTE_INITIALIZED | \
EFI_RESOURCE_ATTRIBUTE_TESTED | \
EFI_RESOURCE_ATTRIBUTE_READ_PROTECTED | \
@@ -26,24 +26,24 @@ SPDX-License-Identifier: BSD-2-Clause-Patent EFI_RESOURCE_ATTRIBUTE_64_BIT_IO | \
EFI_RESOURCE_ATTRIBUTE_PERSISTENT )
-#define TESTED_MEMORY_ATTRIBUTES (EFI_RESOURCE_ATTRIBUTE_PRESENT | \
+#define TESTED_MEMORY_ATTRIBUTES (EFI_RESOURCE_ATTRIBUTE_PRESENT | \
EFI_RESOURCE_ATTRIBUTE_INITIALIZED | \
EFI_RESOURCE_ATTRIBUTE_TESTED )
-#define INITIALIZED_MEMORY_ATTRIBUTES (EFI_RESOURCE_ATTRIBUTE_PRESENT | \
+#define INITIALIZED_MEMORY_ATTRIBUTES (EFI_RESOURCE_ATTRIBUTE_PRESENT |\
EFI_RESOURCE_ATTRIBUTE_INITIALIZED )
-#define PRESENT_MEMORY_ATTRIBUTES (EFI_RESOURCE_ATTRIBUTE_PRESENT)
+#define PRESENT_MEMORY_ATTRIBUTES (EFI_RESOURCE_ATTRIBUTE_PRESENT)
//
// Module Variables
//
-EFI_LOCK mGcdMemorySpaceLock = EFI_INITIALIZE_LOCK_VARIABLE (TPL_NOTIFY);
-EFI_LOCK mGcdIoSpaceLock = EFI_INITIALIZE_LOCK_VARIABLE (TPL_NOTIFY);
-LIST_ENTRY mGcdMemorySpaceMap = INITIALIZE_LIST_HEAD_VARIABLE (mGcdMemorySpaceMap);
-LIST_ENTRY mGcdIoSpaceMap = INITIALIZE_LIST_HEAD_VARIABLE (mGcdIoSpaceMap);
+EFI_LOCK mGcdMemorySpaceLock = EFI_INITIALIZE_LOCK_VARIABLE (TPL_NOTIFY);
+EFI_LOCK mGcdIoSpaceLock = EFI_INITIALIZE_LOCK_VARIABLE (TPL_NOTIFY);
+LIST_ENTRY mGcdMemorySpaceMap = INITIALIZE_LIST_HEAD_VARIABLE (mGcdMemorySpaceMap);
+LIST_ENTRY mGcdIoSpaceMap = INITIALIZE_LIST_HEAD_VARIABLE (mGcdIoSpaceMap);
-EFI_GCD_MAP_ENTRY mGcdMemorySpaceMapEntryTemplate = {
+EFI_GCD_MAP_ENTRY mGcdMemorySpaceMapEntryTemplate = {
EFI_GCD_MAP_SIGNATURE,
{
NULL,
@@ -54,12 +54,12 @@ EFI_GCD_MAP_ENTRY mGcdMemorySpaceMapEntryTemplate = { 0,
0,
EfiGcdMemoryTypeNonExistent,
- (EFI_GCD_IO_TYPE) 0,
+ (EFI_GCD_IO_TYPE)0,
NULL,
NULL
};
-EFI_GCD_MAP_ENTRY mGcdIoSpaceMapEntryTemplate = {
+EFI_GCD_MAP_ENTRY mGcdIoSpaceMapEntryTemplate = {
EFI_GCD_MAP_SIGNATURE,
{
NULL,
@@ -69,34 +69,34 @@ EFI_GCD_MAP_ENTRY mGcdIoSpaceMapEntryTemplate = { 0,
0,
0,
- (EFI_GCD_MEMORY_TYPE) 0,
+ (EFI_GCD_MEMORY_TYPE)0,
EfiGcdIoTypeNonExistent,
NULL,
NULL
};
-GCD_ATTRIBUTE_CONVERSION_ENTRY mAttributeConversionTable[] = {
- { EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE, EFI_MEMORY_UC, TRUE },
- { EFI_RESOURCE_ATTRIBUTE_UNCACHED_EXPORTED, EFI_MEMORY_UCE, TRUE },
- { EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE, EFI_MEMORY_WC, TRUE },
- { EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE, EFI_MEMORY_WT, TRUE },
- { EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE, EFI_MEMORY_WB, TRUE },
- { EFI_RESOURCE_ATTRIBUTE_READ_PROTECTABLE, EFI_MEMORY_RP, TRUE },
- { EFI_RESOURCE_ATTRIBUTE_WRITE_PROTECTABLE, EFI_MEMORY_WP, TRUE },
- { EFI_RESOURCE_ATTRIBUTE_EXECUTION_PROTECTABLE, EFI_MEMORY_XP, TRUE },
- { EFI_RESOURCE_ATTRIBUTE_READ_ONLY_PROTECTABLE, EFI_MEMORY_RO, TRUE },
- { EFI_RESOURCE_ATTRIBUTE_PRESENT, EFI_MEMORY_PRESENT, FALSE },
- { EFI_RESOURCE_ATTRIBUTE_INITIALIZED, EFI_MEMORY_INITIALIZED, FALSE },
- { EFI_RESOURCE_ATTRIBUTE_TESTED, EFI_MEMORY_TESTED, FALSE },
- { EFI_RESOURCE_ATTRIBUTE_PERSISTABLE, EFI_MEMORY_NV, TRUE },
- { EFI_RESOURCE_ATTRIBUTE_MORE_RELIABLE, EFI_MEMORY_MORE_RELIABLE, TRUE },
- { 0, 0, FALSE }
+GCD_ATTRIBUTE_CONVERSION_ENTRY mAttributeConversionTable[] = {
+ { EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE, EFI_MEMORY_UC, TRUE },
+ { EFI_RESOURCE_ATTRIBUTE_UNCACHED_EXPORTED, EFI_MEMORY_UCE, TRUE },
+ { EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE, EFI_MEMORY_WC, TRUE },
+ { EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE, EFI_MEMORY_WT, TRUE },
+ { EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE, EFI_MEMORY_WB, TRUE },
+ { EFI_RESOURCE_ATTRIBUTE_READ_PROTECTABLE, EFI_MEMORY_RP, TRUE },
+ { EFI_RESOURCE_ATTRIBUTE_WRITE_PROTECTABLE, EFI_MEMORY_WP, TRUE },
+ { EFI_RESOURCE_ATTRIBUTE_EXECUTION_PROTECTABLE, EFI_MEMORY_XP, TRUE },
+ { EFI_RESOURCE_ATTRIBUTE_READ_ONLY_PROTECTABLE, EFI_MEMORY_RO, TRUE },
+ { EFI_RESOURCE_ATTRIBUTE_PRESENT, EFI_MEMORY_PRESENT, FALSE },
+ { EFI_RESOURCE_ATTRIBUTE_INITIALIZED, EFI_MEMORY_INITIALIZED, FALSE },
+ { EFI_RESOURCE_ATTRIBUTE_TESTED, EFI_MEMORY_TESTED, FALSE },
+ { EFI_RESOURCE_ATTRIBUTE_PERSISTABLE, EFI_MEMORY_NV, TRUE },
+ { EFI_RESOURCE_ATTRIBUTE_MORE_RELIABLE, EFI_MEMORY_MORE_RELIABLE, TRUE },
+ { 0, 0, FALSE }
};
///
/// Lookup table used to print GCD Memory Space Map
///
-GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 *mGcdMemoryTypeNames[] = {
+GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 *mGcdMemoryTypeNames[] = {
"NonExist ", // EfiGcdMemoryTypeNonExistent
"Reserved ", // EfiGcdMemoryTypeReserved
"SystemMem", // EfiGcdMemoryTypeSystemMemory
@@ -109,7 +109,7 @@ GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 *mGcdMemoryTypeNames[] = { ///
/// Lookup table used to print GCD I/O Space Map
///
-GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 *mGcdIoTypeNames[] = {
+GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 *mGcdIoTypeNames[] = {
"NonExist", // EfiGcdIoTypeNonExistent
"Reserved", // EfiGcdIoTypeReserved
"I/O ", // EfiGcdIoTypeIo
@@ -119,7 +119,7 @@ GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 *mGcdIoTypeNames[] = { ///
/// Lookup table used to print GCD Allocation Types
///
-GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 *mGcdAllocationTypeNames[] = {
+GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 *mGcdAllocationTypeNames[] = {
"AnySearchBottomUp ", // EfiGcdAllocateAnySearchBottomUp
"MaxAddressSearchBottomUp ", // EfiGcdAllocateMaxAddressSearchBottomUp
"AtAddress ", // EfiGcdAllocateAddress
@@ -141,33 +141,37 @@ CoreDumpGcdMemorySpaceMap ( BOOLEAN InitialMap
)
{
- DEBUG_CODE_BEGIN ();
- EFI_STATUS Status;
- UINTN NumberOfDescriptors;
- EFI_GCD_MEMORY_SPACE_DESCRIPTOR *MemorySpaceMap;
- UINTN Index;
+ DEBUG_CODE_BEGIN ();
+ EFI_STATUS Status;
+ UINTN NumberOfDescriptors;
+ EFI_GCD_MEMORY_SPACE_DESCRIPTOR *MemorySpaceMap;
+ UINTN Index;
- Status = CoreGetMemorySpaceMap (&NumberOfDescriptors, &MemorySpaceMap);
- ASSERT (Status == EFI_SUCCESS && MemorySpaceMap != NULL);
+ Status = CoreGetMemorySpaceMap (&NumberOfDescriptors, &MemorySpaceMap);
+ ASSERT (Status == EFI_SUCCESS && MemorySpaceMap != NULL);
- if (InitialMap) {
- DEBUG ((DEBUG_GCD, "GCD:Initial GCD Memory Space Map\n"));
- }
- DEBUG ((DEBUG_GCD, "GCDMemType Range Capabilities Attributes \n"));
- DEBUG ((DEBUG_GCD, "========== ================================= ================ ================\n"));
- for (Index = 0; Index < NumberOfDescriptors; Index++) {
- DEBUG ((DEBUG_GCD, "%a %016lx-%016lx %016lx %016lx%c\n",
- mGcdMemoryTypeNames[MIN (MemorySpaceMap[Index].GcdMemoryType, EfiGcdMemoryTypeMaximum)],
- MemorySpaceMap[Index].BaseAddress,
- MemorySpaceMap[Index].BaseAddress + MemorySpaceMap[Index].Length - 1,
- MemorySpaceMap[Index].Capabilities,
- MemorySpaceMap[Index].Attributes,
- MemorySpaceMap[Index].ImageHandle == NULL ? ' ' : '*'
- ));
- }
- DEBUG ((DEBUG_GCD, "\n"));
- FreePool (MemorySpaceMap);
- DEBUG_CODE_END ();
+ if (InitialMap) {
+ DEBUG ((DEBUG_GCD, "GCD:Initial GCD Memory Space Map\n"));
+ }
+
+ DEBUG ((DEBUG_GCD, "GCDMemType Range Capabilities Attributes \n"));
+ DEBUG ((DEBUG_GCD, "========== ================================= ================ ================\n"));
+ for (Index = 0; Index < NumberOfDescriptors; Index++) {
+ DEBUG ((
+ DEBUG_GCD,
+ "%a %016lx-%016lx %016lx %016lx%c\n",
+ mGcdMemoryTypeNames[MIN (MemorySpaceMap[Index].GcdMemoryType, EfiGcdMemoryTypeMaximum)],
+ MemorySpaceMap[Index].BaseAddress,
+ MemorySpaceMap[Index].BaseAddress + MemorySpaceMap[Index].Length - 1,
+ MemorySpaceMap[Index].Capabilities,
+ MemorySpaceMap[Index].Attributes,
+ MemorySpaceMap[Index].ImageHandle == NULL ? ' ' : '*'
+ ));
+ }
+
+ DEBUG ((DEBUG_GCD, "\n"));
+ FreePool (MemorySpaceMap);
+ DEBUG_CODE_END ();
}
/**
@@ -183,32 +187,35 @@ CoreDumpGcdIoSpaceMap ( BOOLEAN InitialMap
)
{
- DEBUG_CODE_BEGIN ();
- EFI_STATUS Status;
- UINTN NumberOfDescriptors;
- EFI_GCD_IO_SPACE_DESCRIPTOR *IoSpaceMap;
- UINTN Index;
+ DEBUG_CODE_BEGIN ();
+ EFI_STATUS Status;
+ UINTN NumberOfDescriptors;
+ EFI_GCD_IO_SPACE_DESCRIPTOR *IoSpaceMap;
+ UINTN Index;
- Status = CoreGetIoSpaceMap (&NumberOfDescriptors, &IoSpaceMap);
- ASSERT (Status == EFI_SUCCESS && IoSpaceMap != NULL);
+ Status = CoreGetIoSpaceMap (&NumberOfDescriptors, &IoSpaceMap);
+ ASSERT (Status == EFI_SUCCESS && IoSpaceMap != NULL);
- if (InitialMap) {
- DEBUG ((DEBUG_GCD, "GCD:Initial GCD I/O Space Map\n"));
- }
+ if (InitialMap) {
+ DEBUG ((DEBUG_GCD, "GCD:Initial GCD I/O Space Map\n"));
+ }
- DEBUG ((DEBUG_GCD, "GCDIoType Range \n"));
- DEBUG ((DEBUG_GCD, "========== =================================\n"));
- for (Index = 0; Index < NumberOfDescriptors; Index++) {
- DEBUG ((DEBUG_GCD, "%a %016lx-%016lx%c\n",
- mGcdIoTypeNames[MIN (IoSpaceMap[Index].GcdIoType, EfiGcdIoTypeMaximum)],
- IoSpaceMap[Index].BaseAddress,
- IoSpaceMap[Index].BaseAddress + IoSpaceMap[Index].Length - 1,
- IoSpaceMap[Index].ImageHandle == NULL ? ' ' : '*'
- ));
- }
- DEBUG ((DEBUG_GCD, "\n"));
- FreePool (IoSpaceMap);
- DEBUG_CODE_END ();
+ DEBUG ((DEBUG_GCD, "GCDIoType Range \n"));
+ DEBUG ((DEBUG_GCD, "========== =================================\n"));
+ for (Index = 0; Index < NumberOfDescriptors; Index++) {
+ DEBUG ((
+ DEBUG_GCD,
+ "%a %016lx-%016lx%c\n",
+ mGcdIoTypeNames[MIN (IoSpaceMap[Index].GcdIoType, EfiGcdIoTypeMaximum)],
+ IoSpaceMap[Index].BaseAddress,
+ IoSpaceMap[Index].BaseAddress + IoSpaceMap[Index].Length - 1,
+ IoSpaceMap[Index].ImageHandle == NULL ? ' ' : '*'
+ ));
+ }
+
+ DEBUG ((DEBUG_GCD, "\n"));
+ FreePool (IoSpaceMap);
+ DEBUG_CODE_END ();
}
/**
@@ -225,16 +232,26 @@ CoreValidateResourceDescriptorHobAttributes ( IN UINT64 Attributes
)
{
- ASSERT (((Attributes & EFI_RESOURCE_ATTRIBUTE_READ_PROTECTED) == 0) ||
- ((Attributes & EFI_RESOURCE_ATTRIBUTE_READ_PROTECTABLE) != 0));
- ASSERT (((Attributes & EFI_RESOURCE_ATTRIBUTE_WRITE_PROTECTED) == 0) ||
- ((Attributes & EFI_RESOURCE_ATTRIBUTE_WRITE_PROTECTABLE) != 0));
- ASSERT (((Attributes & EFI_RESOURCE_ATTRIBUTE_EXECUTION_PROTECTED) == 0) ||
- ((Attributes & EFI_RESOURCE_ATTRIBUTE_EXECUTION_PROTECTABLE) != 0));
- ASSERT (((Attributes & EFI_RESOURCE_ATTRIBUTE_READ_ONLY_PROTECTED) == 0) ||
- ((Attributes & EFI_RESOURCE_ATTRIBUTE_READ_ONLY_PROTECTABLE) != 0));
- ASSERT (((Attributes & EFI_RESOURCE_ATTRIBUTE_PERSISTENT) == 0) ||
- ((Attributes & EFI_RESOURCE_ATTRIBUTE_PERSISTABLE) != 0));
+ ASSERT (
+ ((Attributes & EFI_RESOURCE_ATTRIBUTE_READ_PROTECTED) == 0) ||
+ ((Attributes & EFI_RESOURCE_ATTRIBUTE_READ_PROTECTABLE) != 0)
+ );
+ ASSERT (
+ ((Attributes & EFI_RESOURCE_ATTRIBUTE_WRITE_PROTECTED) == 0) ||
+ ((Attributes & EFI_RESOURCE_ATTRIBUTE_WRITE_PROTECTABLE) != 0)
+ );
+ ASSERT (
+ ((Attributes & EFI_RESOURCE_ATTRIBUTE_EXECUTION_PROTECTED) == 0) ||
+ ((Attributes & EFI_RESOURCE_ATTRIBUTE_EXECUTION_PROTECTABLE) != 0)
+ );
+ ASSERT (
+ ((Attributes & EFI_RESOURCE_ATTRIBUTE_READ_ONLY_PROTECTED) == 0) ||
+ ((Attributes & EFI_RESOURCE_ATTRIBUTE_READ_ONLY_PROTECTABLE) != 0)
+ );
+ ASSERT (
+ ((Attributes & EFI_RESOURCE_ATTRIBUTE_PERSISTENT) == 0) ||
+ ((Attributes & EFI_RESOURCE_ATTRIBUTE_PERSISTABLE) != 0)
+ );
}
/**
@@ -249,8 +266,6 @@ CoreAcquireGcdMemoryLock ( CoreAcquireLock (&mGcdMemorySpaceLock);
}
-
-
/**
Release memory lock on mGcdMemorySpaceLock.
@@ -263,8 +278,6 @@ CoreReleaseGcdMemoryLock ( CoreReleaseLock (&mGcdMemorySpaceLock);
}
-
-
/**
Acquire memory lock on mGcdIoSpaceLock.
@@ -277,7 +290,6 @@ CoreAcquireGcdIoLock ( CoreAcquireLock (&mGcdIoSpaceLock);
}
-
/**
Release memory lock on mGcdIoSpaceLock.
@@ -290,11 +302,10 @@ CoreReleaseGcdIoLock ( CoreReleaseLock (&mGcdIoSpaceLock);
}
-
-
//
// GCD Initialization Worker Functions
//
+
/**
Aligns a value to the specified boundary.
@@ -320,10 +331,10 @@ AlignValue ( if (RoundUp) {
Value += AlignmentMask;
}
+
return Value & (~AlignmentMask);
}
-
/**
Aligns address to the page boundary.
@@ -334,13 +345,12 @@ AlignValue ( **/
UINT64
PageAlignAddress (
- IN UINT64 Value
+ IN UINT64 Value
)
{
return AlignValue (Value, EFI_PAGE_SHIFT, TRUE);
}
-
/**
Aligns length to the page boundary.
@@ -351,7 +361,7 @@ PageAlignAddress ( **/
UINT64
PageAlignLength (
- IN UINT64 Value
+ IN UINT64 Value
)
{
return AlignValue (Value, EFI_PAGE_SHIFT, FALSE);
@@ -383,15 +393,15 @@ CoreAllocateGcdMapEntry ( // cause problem when it's freed (if HeapGuard is enabled).
//
mOnGuarding = TRUE;
- *TopEntry = AllocateZeroPool (sizeof (EFI_GCD_MAP_ENTRY));
+ *TopEntry = AllocateZeroPool (sizeof (EFI_GCD_MAP_ENTRY));
mOnGuarding = FALSE;
if (*TopEntry == NULL) {
return EFI_OUT_OF_RESOURCES;
}
- mOnGuarding = TRUE;
+ mOnGuarding = TRUE;
*BottomEntry = AllocateZeroPool (sizeof (EFI_GCD_MAP_ENTRY));
- mOnGuarding = FALSE;
+ mOnGuarding = FALSE;
if (*BottomEntry == NULL) {
CoreFreePool (*TopEntry);
return EFI_OUT_OF_RESOURCES;
@@ -400,7 +410,6 @@ CoreAllocateGcdMapEntry ( return EFI_SUCCESS;
}
-
/**
Internal function. Inserts a new descriptor into a sorted list
@@ -417,7 +426,7 @@ CoreAllocateGcdMapEntry ( **/
EFI_STATUS
CoreInsertGcdMapEntry (
- IN LIST_ENTRY *Link,
+ IN LIST_ENTRY *Link,
IN EFI_GCD_MAP_ENTRY *Entry,
IN EFI_PHYSICAL_ADDRESS BaseAddress,
IN UINT64 Length,
@@ -448,7 +457,6 @@ CoreInsertGcdMapEntry ( return EFI_SUCCESS;
}
-
/**
Merge the Gcd region specified by Link and its adjacent entry.
@@ -463,9 +471,9 @@ CoreInsertGcdMapEntry ( **/
EFI_STATUS
CoreMergeGcdMapEntry (
- IN LIST_ENTRY *Link,
- IN BOOLEAN Forward,
- IN LIST_ENTRY *Map
+ IN LIST_ENTRY *Link,
+ IN BOOLEAN Forward,
+ IN LIST_ENTRY *Map
)
{
LIST_ENTRY *AdjacentLink;
@@ -494,34 +502,39 @@ CoreMergeGcdMapEntry ( if (Entry->Capabilities != AdjacentEntry->Capabilities) {
return EFI_UNSUPPORTED;
}
+
if (Entry->Attributes != AdjacentEntry->Attributes) {
return EFI_UNSUPPORTED;
}
+
if (Entry->GcdMemoryType != AdjacentEntry->GcdMemoryType) {
return EFI_UNSUPPORTED;
}
+
if (Entry->GcdIoType != AdjacentEntry->GcdIoType) {
return EFI_UNSUPPORTED;
}
+
if (Entry->ImageHandle != AdjacentEntry->ImageHandle) {
return EFI_UNSUPPORTED;
}
+
if (Entry->DeviceHandle != AdjacentEntry->DeviceHandle) {
return EFI_UNSUPPORTED;
}
if (Forward) {
- Entry->EndAddress = AdjacentEntry->EndAddress;
+ Entry->EndAddress = AdjacentEntry->EndAddress;
} else {
Entry->BaseAddress = AdjacentEntry->BaseAddress;
}
+
RemoveEntryList (AdjacentLink);
CoreFreePool (AdjacentEntry);
return EFI_SUCCESS;
}
-
/**
Merge adjacent entries on total chain.
@@ -548,6 +561,7 @@ CoreCleanupGcdMapEntry ( if (TopEntry->Signature == 0) {
CoreFreePool (TopEntry);
}
+
if (BottomEntry->Signature == 0) {
CoreFreePool (BottomEntry);
}
@@ -557,12 +571,12 @@ CoreCleanupGcdMapEntry ( CoreMergeGcdMapEntry (Link, FALSE, Map);
Link = Link->ForwardLink;
}
+
CoreMergeGcdMapEntry (EndLink, TRUE, Map);
return EFI_SUCCESS;
}
-
/**
Search a segment of memory space in GCD map. The result is a range of GCD entry list.
@@ -598,23 +612,25 @@ CoreSearchGcdMapEntry ( Link = Map->ForwardLink;
while (Link != Map) {
Entry = CR (Link, EFI_GCD_MAP_ENTRY, Link, EFI_GCD_MAP_SIGNATURE);
- if (BaseAddress >= Entry->BaseAddress && BaseAddress <= Entry->EndAddress) {
+ if ((BaseAddress >= Entry->BaseAddress) && (BaseAddress <= Entry->EndAddress)) {
*StartLink = Link;
}
+
if (*StartLink != NULL) {
- if ((BaseAddress + Length - 1) >= Entry->BaseAddress &&
- (BaseAddress + Length - 1) <= Entry->EndAddress ) {
+ if (((BaseAddress + Length - 1) >= Entry->BaseAddress) &&
+ ((BaseAddress + Length - 1) <= Entry->EndAddress))
+ {
*EndLink = Link;
return EFI_SUCCESS;
}
}
+
Link = Link->ForwardLink;
}
return EFI_NOT_FOUND;
}
-
/**
Count the amount of GCD map entries.
@@ -628,11 +644,11 @@ CoreCountGcdMapEntry ( IN LIST_ENTRY *Map
)
{
- UINTN Count;
- LIST_ENTRY *Link;
+ UINTN Count;
+ LIST_ENTRY *Link;
Count = 0;
- Link = Map->ForwardLink;
+ Link = Map->ForwardLink;
while (Link != Map) {
Count++;
Link = Link->ForwardLink;
@@ -641,8 +657,6 @@ CoreCountGcdMapEntry ( return Count;
}
-
-
/**
Return the memory attribute specified by Attributes
@@ -653,31 +667,30 @@ CoreCountGcdMapEntry ( **/
UINT64
ConverToCpuArchAttributes (
- UINT64 Attributes
+ UINT64 Attributes
)
{
- UINT64 CpuArchAttributes;
+ UINT64 CpuArchAttributes;
CpuArchAttributes = Attributes & EFI_MEMORY_ATTRIBUTE_MASK;
- if ( (Attributes & EFI_MEMORY_UC) == EFI_MEMORY_UC) {
+ if ((Attributes & EFI_MEMORY_UC) == EFI_MEMORY_UC) {
CpuArchAttributes |= EFI_MEMORY_UC;
- } else if ( (Attributes & EFI_MEMORY_WC ) == EFI_MEMORY_WC) {
+ } else if ((Attributes & EFI_MEMORY_WC) == EFI_MEMORY_WC) {
CpuArchAttributes |= EFI_MEMORY_WC;
- } else if ( (Attributes & EFI_MEMORY_WT ) == EFI_MEMORY_WT) {
+ } else if ((Attributes & EFI_MEMORY_WT) == EFI_MEMORY_WT) {
CpuArchAttributes |= EFI_MEMORY_WT;
- } else if ( (Attributes & EFI_MEMORY_WB) == EFI_MEMORY_WB) {
+ } else if ((Attributes & EFI_MEMORY_WB) == EFI_MEMORY_WB) {
CpuArchAttributes |= EFI_MEMORY_WB;
- } else if ( (Attributes & EFI_MEMORY_UCE) == EFI_MEMORY_UCE) {
+ } else if ((Attributes & EFI_MEMORY_UCE) == EFI_MEMORY_UCE) {
CpuArchAttributes |= EFI_MEMORY_UCE;
- } else if ( (Attributes & EFI_MEMORY_WP) == EFI_MEMORY_WP) {
+ } else if ((Attributes & EFI_MEMORY_WP) == EFI_MEMORY_WP) {
CpuArchAttributes |= EFI_MEMORY_WP;
}
return CpuArchAttributes;
}
-
/**
Do operation on a segment of memory space specified (add, free, remove, change attribute ...).
@@ -748,6 +761,7 @@ CoreConvertSpace ( goto Done;
}
+
ASSERT (StartLink != NULL && EndLink != NULL);
//
@@ -757,89 +771,103 @@ CoreConvertSpace ( while (Link != EndLink->ForwardLink) {
Entry = CR (Link, EFI_GCD_MAP_ENTRY, Link, EFI_GCD_MAP_SIGNATURE);
switch (Operation) {
- //
- // Add operations
- //
- case GCD_ADD_MEMORY_OPERATION:
- if (Entry->GcdMemoryType != EfiGcdMemoryTypeNonExistent ||
- Entry->ImageHandle != NULL ) {
- Status = EFI_ACCESS_DENIED;
- goto Done;
- }
- break;
- case GCD_ADD_IO_OPERATION:
- if (Entry->GcdIoType != EfiGcdIoTypeNonExistent ||
- Entry->ImageHandle != NULL ) {
- Status = EFI_ACCESS_DENIED;
- goto Done;
- }
- break;
- //
- // Free operations
- //
- case GCD_FREE_MEMORY_OPERATION:
- case GCD_FREE_IO_OPERATION:
- if (Entry->ImageHandle == NULL) {
- Status = EFI_NOT_FOUND;
- goto Done;
- }
- break;
- //
- // Remove operations
- //
- case GCD_REMOVE_MEMORY_OPERATION:
- if (Entry->GcdMemoryType == EfiGcdMemoryTypeNonExistent) {
- Status = EFI_NOT_FOUND;
- goto Done;
- }
- if (Entry->ImageHandle != NULL) {
- Status = EFI_ACCESS_DENIED;
- goto Done;
- }
- break;
- case GCD_REMOVE_IO_OPERATION:
- if (Entry->GcdIoType == EfiGcdIoTypeNonExistent) {
- Status = EFI_NOT_FOUND;
- goto Done;
- }
- if (Entry->ImageHandle != NULL) {
- Status = EFI_ACCESS_DENIED;
- goto Done;
- }
- break;
- //
- // Set attributes operation
- //
- case GCD_SET_ATTRIBUTES_MEMORY_OPERATION:
- if ((Attributes & EFI_MEMORY_RUNTIME) != 0) {
- if ((BaseAddress & EFI_PAGE_MASK) != 0 || (Length & EFI_PAGE_MASK) != 0) {
- Status = EFI_INVALID_PARAMETER;
+ //
+ // Add operations
+ //
+ case GCD_ADD_MEMORY_OPERATION:
+ if ((Entry->GcdMemoryType != EfiGcdMemoryTypeNonExistent) ||
+ (Entry->ImageHandle != NULL))
+ {
+ Status = EFI_ACCESS_DENIED;
goto Done;
}
- }
- if ((Entry->Capabilities & Attributes) != Attributes) {
- Status = EFI_UNSUPPORTED;
- goto Done;
- }
- break;
- //
- // Set capabilities operation
- //
- case GCD_SET_CAPABILITIES_MEMORY_OPERATION:
- if ((BaseAddress & EFI_PAGE_MASK) != 0 || (Length & EFI_PAGE_MASK) != 0) {
- Status = EFI_INVALID_PARAMETER;
- goto Done;
- }
+ break;
+ case GCD_ADD_IO_OPERATION:
+ if ((Entry->GcdIoType != EfiGcdIoTypeNonExistent) ||
+ (Entry->ImageHandle != NULL))
+ {
+ Status = EFI_ACCESS_DENIED;
+ goto Done;
+ }
+
+ break;
//
- // Current attributes must still be supported with new capabilities
+ // Free operations
//
- if ((Capabilities & Entry->Attributes) != Entry->Attributes) {
- Status = EFI_UNSUPPORTED;
- goto Done;
- }
- break;
+ case GCD_FREE_MEMORY_OPERATION:
+ case GCD_FREE_IO_OPERATION:
+ if (Entry->ImageHandle == NULL) {
+ Status = EFI_NOT_FOUND;
+ goto Done;
+ }
+
+ break;
+ //
+ // Remove operations
+ //
+ case GCD_REMOVE_MEMORY_OPERATION:
+ if (Entry->GcdMemoryType == EfiGcdMemoryTypeNonExistent) {
+ Status = EFI_NOT_FOUND;
+ goto Done;
+ }
+
+ if (Entry->ImageHandle != NULL) {
+ Status = EFI_ACCESS_DENIED;
+ goto Done;
+ }
+
+ break;
+ case GCD_REMOVE_IO_OPERATION:
+ if (Entry->GcdIoType == EfiGcdIoTypeNonExistent) {
+ Status = EFI_NOT_FOUND;
+ goto Done;
+ }
+
+ if (Entry->ImageHandle != NULL) {
+ Status = EFI_ACCESS_DENIED;
+ goto Done;
+ }
+
+ break;
+ //
+ // Set attributes operation
+ //
+ case GCD_SET_ATTRIBUTES_MEMORY_OPERATION:
+ if ((Attributes & EFI_MEMORY_RUNTIME) != 0) {
+ if (((BaseAddress & EFI_PAGE_MASK) != 0) || ((Length & EFI_PAGE_MASK) != 0)) {
+ Status = EFI_INVALID_PARAMETER;
+ goto Done;
+ }
+ }
+
+ if ((Entry->Capabilities & Attributes) != Attributes) {
+ Status = EFI_UNSUPPORTED;
+ goto Done;
+ }
+
+ break;
+ //
+ // Set capabilities operation
+ //
+ case GCD_SET_CAPABILITIES_MEMORY_OPERATION:
+ if (((BaseAddress & EFI_PAGE_MASK) != 0) || ((Length & EFI_PAGE_MASK) != 0)) {
+ Status = EFI_INVALID_PARAMETER;
+
+ goto Done;
+ }
+
+ //
+ // Current attributes must still be supported with new capabilities
+ //
+ if ((Capabilities & Entry->Attributes) != Entry->Attributes) {
+ Status = EFI_UNSUPPORTED;
+ goto Done;
+ }
+
+ break;
}
+
Link = Link->ForwardLink;
}
@@ -851,6 +879,7 @@ CoreConvertSpace ( Status = EFI_OUT_OF_RESOURCES;
goto Done;
}
+
ASSERT (TopEntry != NULL && BottomEntry != NULL);
//
@@ -887,6 +916,7 @@ CoreConvertSpace ( CpuArchAttributes
);
}
+
if (EFI_ERROR (Status)) {
CoreFreePool (TopEntry);
CoreFreePool (BottomEntry);
@@ -903,58 +933,61 @@ CoreConvertSpace ( Entry = CR (Link, EFI_GCD_MAP_ENTRY, Link, EFI_GCD_MAP_SIGNATURE);
CoreInsertGcdMapEntry (Link, Entry, BaseAddress, Length, TopEntry, BottomEntry);
switch (Operation) {
- //
- // Add operations
- //
- case GCD_ADD_MEMORY_OPERATION:
- Entry->GcdMemoryType = GcdMemoryType;
- if (GcdMemoryType == EfiGcdMemoryTypeMemoryMappedIo) {
- Entry->Capabilities = Capabilities | EFI_MEMORY_RUNTIME | EFI_MEMORY_PORT_IO;
- } else {
- Entry->Capabilities = Capabilities | EFI_MEMORY_RUNTIME;
- }
- break;
- case GCD_ADD_IO_OPERATION:
- Entry->GcdIoType = GcdIoType;
- break;
- //
- // Free operations
- //
- case GCD_FREE_MEMORY_OPERATION:
- case GCD_FREE_IO_OPERATION:
- Entry->ImageHandle = NULL;
- Entry->DeviceHandle = NULL;
- break;
- //
- // Remove operations
- //
- case GCD_REMOVE_MEMORY_OPERATION:
- Entry->GcdMemoryType = EfiGcdMemoryTypeNonExistent;
- Entry->Capabilities = 0;
- break;
- case GCD_REMOVE_IO_OPERATION:
- Entry->GcdIoType = EfiGcdIoTypeNonExistent;
- break;
- //
- // Set attributes operation
- //
- case GCD_SET_ATTRIBUTES_MEMORY_OPERATION:
- if (CpuArchAttributes == 0) {
- //
- // Keep original CPU arch attributes when caller just calls
- // SetMemorySpaceAttributes() with none CPU arch attributes (for example, RUNTIME).
- //
- Attributes |= (Entry->Attributes & (EFI_CACHE_ATTRIBUTE_MASK | EFI_MEMORY_ATTRIBUTE_MASK));
- }
- Entry->Attributes = Attributes;
- break;
- //
- // Set capabilities operation
- //
- case GCD_SET_CAPABILITIES_MEMORY_OPERATION:
- Entry->Capabilities = Capabilities;
- break;
+ //
+ // Add operations
+ //
+ case GCD_ADD_MEMORY_OPERATION:
+ Entry->GcdMemoryType = GcdMemoryType;
+ if (GcdMemoryType == EfiGcdMemoryTypeMemoryMappedIo) {
+ Entry->Capabilities = Capabilities | EFI_MEMORY_RUNTIME | EFI_MEMORY_PORT_IO;
+ } else {
+ Entry->Capabilities = Capabilities | EFI_MEMORY_RUNTIME;
+ }
+
+ break;
+ case GCD_ADD_IO_OPERATION:
+ Entry->GcdIoType = GcdIoType;
+ break;
+ //
+ // Free operations
+ //
+ case GCD_FREE_MEMORY_OPERATION:
+ case GCD_FREE_IO_OPERATION:
+ Entry->ImageHandle = NULL;
+ Entry->DeviceHandle = NULL;
+ break;
+ //
+ // Remove operations
+ //
+ case GCD_REMOVE_MEMORY_OPERATION:
+ Entry->GcdMemoryType = EfiGcdMemoryTypeNonExistent;
+ Entry->Capabilities = 0;
+ break;
+ case GCD_REMOVE_IO_OPERATION:
+ Entry->GcdIoType = EfiGcdIoTypeNonExistent;
+ break;
+ //
+ // Set attributes operation
+ //
+ case GCD_SET_ATTRIBUTES_MEMORY_OPERATION:
+ if (CpuArchAttributes == 0) {
+ //
+ // Keep original CPU arch attributes when caller just calls
+ // SetMemorySpaceAttributes() with none CPU arch attributes (for example, RUNTIME).
+ //
+ Attributes |= (Entry->Attributes & (EFI_CACHE_ATTRIBUTE_MASK | EFI_MEMORY_ATTRIBUTE_MASK));
+ }
+
+ Entry->Attributes = Attributes;
+ break;
+ //
+ // Set capabilities operation
+ //
+ case GCD_SET_CAPABILITIES_MEMORY_OPERATION:
+ Entry->Capabilities = Capabilities;
+ break;
}
+
Link = Link->ForwardLink;
}
@@ -970,6 +1003,7 @@ Done: CoreReleaseGcdMemoryLock ();
CoreDumpGcdMemorySpaceMap (FALSE);
}
+
if ((Operation & GCD_IO_SPACE_OPERATION) != 0) {
CoreReleaseGcdIoLock ();
CoreDumpGcdIoSpaceMap (FALSE);
@@ -978,7 +1012,6 @@ Done: return Status;
}
-
/**
Check whether an entry could be used to allocate space.
@@ -1005,24 +1038,27 @@ CoreAllocateSpaceCheckEntry ( if (Entry->ImageHandle != NULL) {
return EFI_NOT_FOUND;
}
+
switch (Operation) {
- case GCD_ALLOCATE_MEMORY_OPERATION:
- if (Entry->GcdMemoryType != GcdMemoryType) {
- return EFI_NOT_FOUND;
- }
- break;
- case GCD_ALLOCATE_IO_OPERATION:
- if (Entry->GcdIoType != GcdIoType) {
- return EFI_NOT_FOUND;
- }
- break;
- default:
- return EFI_UNSUPPORTED;
+ case GCD_ALLOCATE_MEMORY_OPERATION:
+ if (Entry->GcdMemoryType != GcdMemoryType) {
+ return EFI_NOT_FOUND;
+ }
+
+ break;
+ case GCD_ALLOCATE_IO_OPERATION:
+ if (Entry->GcdIoType != GcdIoType) {
+ return EFI_NOT_FOUND;
+ }
+
+ break;
+ default:
+ return EFI_UNSUPPORTED;
}
+
return EFI_SUCCESS;
}
-
/**
Allocate space on specified address and length.
@@ -1074,26 +1110,32 @@ CoreAllocateSpace ( DEBUG ((DEBUG_GCD, " Status = %r\n", EFI_INVALID_PARAMETER));
return EFI_INVALID_PARAMETER;
}
+
if ((UINT32)GcdMemoryType >= EfiGcdMemoryTypeMaximum) {
DEBUG ((DEBUG_GCD, " Status = %r\n", EFI_INVALID_PARAMETER));
return EFI_INVALID_PARAMETER;
}
+
if ((UINT32)GcdIoType >= EfiGcdIoTypeMaximum) {
DEBUG ((DEBUG_GCD, " Status = %r\n", EFI_INVALID_PARAMETER));
return EFI_INVALID_PARAMETER;
}
+
if (BaseAddress == NULL) {
DEBUG ((DEBUG_GCD, " Status = %r\n", EFI_INVALID_PARAMETER));
return EFI_INVALID_PARAMETER;
}
+
if (ImageHandle == NULL) {
DEBUG ((DEBUG_GCD, " Status = %r\n", EFI_INVALID_PARAMETER));
return EFI_INVALID_PARAMETER;
}
+
if (Alignment >= 64) {
DEBUG ((DEBUG_GCD, " Status = %r\n", EFI_NOT_FOUND));
return EFI_NOT_FOUND;
}
+
if (Length == 0) {
DEBUG ((DEBUG_GCD, " Status = %r\n", EFI_INVALID_PARAMETER));
return EFI_INVALID_PARAMETER;
@@ -1135,6 +1177,7 @@ CoreAllocateSpace ( Status = EFI_NOT_FOUND;
goto Done;
}
+
ASSERT (StartLink != NULL && EndLink != NULL);
//
@@ -1142,23 +1185,24 @@ CoreAllocateSpace ( //
Link = StartLink;
while (Link != EndLink->ForwardLink) {
- Entry = CR (Link, EFI_GCD_MAP_ENTRY, Link, EFI_GCD_MAP_SIGNATURE);
- Link = Link->ForwardLink;
+ Entry = CR (Link, EFI_GCD_MAP_ENTRY, Link, EFI_GCD_MAP_SIGNATURE);
+ Link = Link->ForwardLink;
Status = CoreAllocateSpaceCheckEntry (Operation, Entry, GcdMemoryType, GcdIoType);
if (EFI_ERROR (Status)) {
goto Done;
}
}
+
Found = TRUE;
} else {
-
Entry = CR (Map->BackLink, EFI_GCD_MAP_ENTRY, Link, EFI_GCD_MAP_SIGNATURE);
//
// Compute the maximum address to use in the search algorithm
//
- if (GcdAllocateType == EfiGcdAllocateMaxAddressSearchBottomUp ||
- GcdAllocateType == EfiGcdAllocateMaxAddressSearchTopDown ) {
+ if ((GcdAllocateType == EfiGcdAllocateMaxAddressSearchBottomUp) ||
+ (GcdAllocateType == EfiGcdAllocateMaxAddressSearchTopDown))
+ {
MaxAddress = *BaseAddress;
} else {
MaxAddress = Entry->EndAddress;
@@ -1167,17 +1211,20 @@ CoreAllocateSpace ( //
// Verify that the list of descriptors are unallocated memory matching GcdMemoryType.
//
- if (GcdAllocateType == EfiGcdAllocateMaxAddressSearchTopDown ||
- GcdAllocateType == EfiGcdAllocateAnySearchTopDown ) {
+ if ((GcdAllocateType == EfiGcdAllocateMaxAddressSearchTopDown) ||
+ (GcdAllocateType == EfiGcdAllocateAnySearchTopDown))
+ {
Link = Map->BackLink;
} else {
Link = Map->ForwardLink;
}
+
while (Link != Map) {
Entry = CR (Link, EFI_GCD_MAP_ENTRY, Link, EFI_GCD_MAP_SIGNATURE);
- if (GcdAllocateType == EfiGcdAllocateMaxAddressSearchTopDown ||
- GcdAllocateType == EfiGcdAllocateAnySearchTopDown ) {
+ if ((GcdAllocateType == EfiGcdAllocateMaxAddressSearchTopDown) ||
+ (GcdAllocateType == EfiGcdAllocateAnySearchTopDown))
+ {
Link = Link->BackLink;
} else {
Link = Link->ForwardLink;
@@ -1188,20 +1235,24 @@ CoreAllocateSpace ( continue;
}
- if (GcdAllocateType == EfiGcdAllocateMaxAddressSearchTopDown ||
- GcdAllocateType == EfiGcdAllocateAnySearchTopDown) {
+ if ((GcdAllocateType == EfiGcdAllocateMaxAddressSearchTopDown) ||
+ (GcdAllocateType == EfiGcdAllocateAnySearchTopDown))
+ {
if ((Entry->BaseAddress + Length) > MaxAddress) {
continue;
}
+
if (Length > (Entry->EndAddress + 1)) {
Status = EFI_NOT_FOUND;
goto Done;
}
+
if (Entry->EndAddress > MaxAddress) {
*BaseAddress = MaxAddress;
} else {
*BaseAddress = Entry->EndAddress;
}
+
*BaseAddress = (*BaseAddress + 1 - Length) & (~AlignmentMask);
} else {
*BaseAddress = (Entry->BaseAddress + AlignmentMask) & (~AlignmentMask);
@@ -1219,29 +1270,33 @@ CoreAllocateSpace ( Status = EFI_NOT_FOUND;
goto Done;
}
+
ASSERT (StartLink != NULL && EndLink != NULL);
Link = StartLink;
//
// Verify that the list of descriptors are unallocated memory matching GcdMemoryType.
//
- Found = TRUE;
+ Found = TRUE;
SubLink = StartLink;
while (SubLink != EndLink->ForwardLink) {
- Entry = CR (SubLink, EFI_GCD_MAP_ENTRY, Link, EFI_GCD_MAP_SIGNATURE);
+ Entry = CR (SubLink, EFI_GCD_MAP_ENTRY, Link, EFI_GCD_MAP_SIGNATURE);
Status = CoreAllocateSpaceCheckEntry (Operation, Entry, GcdMemoryType, GcdIoType);
if (EFI_ERROR (Status)) {
- Link = SubLink;
+ Link = SubLink;
Found = FALSE;
break;
}
+
SubLink = SubLink->ForwardLink;
}
+
if (Found) {
break;
}
}
}
+
if (!Found) {
Status = EFI_NOT_FOUND;
goto Done;
@@ -1255,6 +1310,7 @@ CoreAllocateSpace ( Status = EFI_OUT_OF_RESOURCES;
goto Done;
}
+
ASSERT (TopEntry != NULL && BottomEntry != NULL);
//
@@ -1266,7 +1322,7 @@ CoreAllocateSpace ( CoreInsertGcdMapEntry (Link, Entry, *BaseAddress, Length, TopEntry, BottomEntry);
Entry->ImageHandle = ImageHandle;
Entry->DeviceHandle = DeviceHandle;
- Link = Link->ForwardLink;
+ Link = Link->ForwardLink;
}
//
@@ -1279,13 +1335,15 @@ Done: if (!EFI_ERROR (Status)) {
DEBUG ((DEBUG_GCD, " (BaseAddress = %016lx)", *BaseAddress));
}
+
DEBUG ((DEBUG_GCD, "\n"));
if ((Operation & GCD_MEMORY_SPACE_OPERATION) != 0) {
CoreReleaseGcdMemoryLock ();
CoreDumpGcdMemorySpaceMap (FALSE);
}
- if ((Operation & GCD_IO_SPACE_OPERATION) !=0) {
+
+ if ((Operation & GCD_IO_SPACE_OPERATION) != 0) {
CoreReleaseGcdIoLock ();
CoreDumpGcdIoSpaceMap (FALSE);
}
@@ -1293,7 +1351,6 @@ Done: return Status;
}
-
/**
Add a segment of memory to GCD map.
@@ -1321,11 +1378,11 @@ CoreInternalAddMemorySpace ( //
// Make sure parameters are valid
//
- if (GcdMemoryType <= EfiGcdMemoryTypeNonExistent || GcdMemoryType >= EfiGcdMemoryTypeMaximum) {
+ if ((GcdMemoryType <= EfiGcdMemoryTypeNonExistent) || (GcdMemoryType >= EfiGcdMemoryTypeMaximum)) {
return EFI_INVALID_PARAMETER;
}
- return CoreConvertSpace (GCD_ADD_MEMORY_OPERATION, GcdMemoryType, (EFI_GCD_IO_TYPE) 0, BaseAddress, Length, Capabilities, 0);
+ return CoreConvertSpace (GCD_ADD_MEMORY_OPERATION, GcdMemoryType, (EFI_GCD_IO_TYPE)0, BaseAddress, Length, Capabilities, 0);
}
//
@@ -1366,6 +1423,7 @@ CoreAllocateMemorySpace ( } else {
DEBUG ((DEBUG_GCD, "GCD:AllocateMemorySpace(Base=<NULL>,Length=%016lx)\n", Length));
}
+
DEBUG ((DEBUG_GCD, " GcdAllocateType = %a\n", mGcdAllocationTypeNames[MIN (GcdAllocateType, EfiGcdMaxAllocateType)]));
DEBUG ((DEBUG_GCD, " GcdMemoryType = %a\n", mGcdMemoryTypeNames[MIN (GcdMemoryType, EfiGcdMemoryTypeMaximum)]));
DEBUG ((DEBUG_GCD, " Alignment = %016lx\n", LShiftU64 (1, Alignment)));
@@ -1376,7 +1434,7 @@ CoreAllocateMemorySpace ( GCD_ALLOCATE_MEMORY_OPERATION,
GcdAllocateType,
GcdMemoryType,
- (EFI_GCD_IO_TYPE) 0,
+ (EFI_GCD_IO_TYPE)0,
Alignment,
Length,
BaseAddress,
@@ -1385,7 +1443,6 @@ CoreAllocateMemorySpace ( );
}
-
/**
Adds reserved memory, system memory, or memory-mapped I/O resources to the
global coherency domain of the processor.
@@ -1414,7 +1471,6 @@ CoreAddMemorySpace ( Status = CoreInternalAddMemorySpace (GcdMemoryType, BaseAddress, Length, Capabilities);
if (!EFI_ERROR (Status) && ((GcdMemoryType == EfiGcdMemoryTypeSystemMemory) || (GcdMemoryType == EfiGcdMemoryTypeMoreReliable))) {
-
PageBaseAddress = PageAlignAddress (BaseAddress);
PageLength = PageAlignLength (BaseAddress + Length - PageBaseAddress);
@@ -1436,7 +1492,7 @@ CoreAddMemorySpace ( Capabilities
);
} else {
- for (; PageLength != 0; PageLength -= EFI_PAGE_SIZE, PageBaseAddress += EFI_PAGE_SIZE) {
+ for ( ; PageLength != 0; PageLength -= EFI_PAGE_SIZE, PageBaseAddress += EFI_PAGE_SIZE) {
Status = CoreAllocateMemorySpace (
EfiGcdAllocateAddress,
GcdMemoryType,
@@ -1458,10 +1514,10 @@ CoreAddMemorySpace ( }
}
}
+
return Status;
}
-
/**
Frees nonexistent memory, reserved memory, system memory, or memory-mapped
I/O resources from the global coherency domain of the processor.
@@ -1481,10 +1537,9 @@ CoreFreeMemorySpace ( {
DEBUG ((DEBUG_GCD, "GCD:FreeMemorySpace(Base=%016lx,Length=%016lx)\n", BaseAddress, Length));
- return CoreConvertSpace (GCD_FREE_MEMORY_OPERATION, (EFI_GCD_MEMORY_TYPE) 0, (EFI_GCD_IO_TYPE) 0, BaseAddress, Length, 0, 0);
+ return CoreConvertSpace (GCD_FREE_MEMORY_OPERATION, (EFI_GCD_MEMORY_TYPE)0, (EFI_GCD_IO_TYPE)0, BaseAddress, Length, 0, 0);
}
-
/**
Removes reserved memory, system memory, or memory-mapped I/O resources from
the global coherency domain of the processor.
@@ -1504,10 +1559,9 @@ CoreRemoveMemorySpace ( {
DEBUG ((DEBUG_GCD, "GCD:RemoveMemorySpace(Base=%016lx,Length=%016lx)\n", BaseAddress, Length));
- return CoreConvertSpace (GCD_REMOVE_MEMORY_OPERATION, (EFI_GCD_MEMORY_TYPE) 0, (EFI_GCD_IO_TYPE) 0, BaseAddress, Length, 0, 0);
+ return CoreConvertSpace (GCD_REMOVE_MEMORY_OPERATION, (EFI_GCD_MEMORY_TYPE)0, (EFI_GCD_IO_TYPE)0, BaseAddress, Length, 0, 0);
}
-
/**
Build a memory descriptor according to an entry.
@@ -1518,7 +1572,7 @@ CoreRemoveMemorySpace ( VOID
BuildMemoryDescriptor (
IN OUT EFI_GCD_MEMORY_SPACE_DESCRIPTOR *Descriptor,
- IN EFI_GCD_MAP_ENTRY *Entry
+ IN EFI_GCD_MAP_ENTRY *Entry
)
{
Descriptor->BaseAddress = Entry->BaseAddress;
@@ -1530,7 +1584,6 @@ BuildMemoryDescriptor ( Descriptor->DeviceHandle = Entry->DeviceHandle;
}
-
/**
Retrieves the descriptor for a memory region containing a specified address.
@@ -1582,7 +1635,6 @@ CoreGetMemorySpaceDescriptor ( return Status;
}
-
/**
Modifies the attributes for a memory region in the global coherency domain of the
processor.
@@ -1616,10 +1668,9 @@ CoreSetMemorySpaceAttributes ( DEBUG ((DEBUG_GCD, "GCD:SetMemorySpaceAttributes(Base=%016lx,Length=%016lx)\n", BaseAddress, Length));
DEBUG ((DEBUG_GCD, " Attributes = %016lx\n", Attributes));
- return CoreConvertSpace (GCD_SET_ATTRIBUTES_MEMORY_OPERATION, (EFI_GCD_MEMORY_TYPE) 0, (EFI_GCD_IO_TYPE) 0, BaseAddress, Length, 0, Attributes);
+ return CoreConvertSpace (GCD_SET_ATTRIBUTES_MEMORY_OPERATION, (EFI_GCD_MEMORY_TYPE)0, (EFI_GCD_IO_TYPE)0, BaseAddress, Length, 0, Attributes);
}
-
/**
Modifies the capabilities for a memory region in the global coherency domain of the
processor.
@@ -1645,20 +1696,19 @@ CoreSetMemorySpaceCapabilities ( IN UINT64 Capabilities
)
{
- EFI_STATUS Status;
+ EFI_STATUS Status;
DEBUG ((DEBUG_GCD, "GCD:CoreSetMemorySpaceCapabilities(Base=%016lx,Length=%016lx)\n", BaseAddress, Length));
DEBUG ((DEBUG_GCD, " Capabilities = %016lx\n", Capabilities));
- Status = CoreConvertSpace (GCD_SET_CAPABILITIES_MEMORY_OPERATION, (EFI_GCD_MEMORY_TYPE) 0, (EFI_GCD_IO_TYPE) 0, BaseAddress, Length, Capabilities, 0);
- if (!EFI_ERROR(Status)) {
- CoreUpdateMemoryAttributes(BaseAddress, RShiftU64(Length, EFI_PAGE_SHIFT), Capabilities & (~EFI_MEMORY_RUNTIME));
+ Status = CoreConvertSpace (GCD_SET_CAPABILITIES_MEMORY_OPERATION, (EFI_GCD_MEMORY_TYPE)0, (EFI_GCD_IO_TYPE)0, BaseAddress, Length, Capabilities, 0);
+ if (!EFI_ERROR (Status)) {
+ CoreUpdateMemoryAttributes (BaseAddress, RShiftU64 (Length, EFI_PAGE_SHIFT), Capabilities & (~EFI_MEMORY_RUNTIME));
}
return Status;
}
-
/**
Returns a map of the memory resources in the global coherency domain of the
processor.
@@ -1689,12 +1739,13 @@ CoreGetMemorySpaceMap ( if (NumberOfDescriptors == NULL) {
return EFI_INVALID_PARAMETER;
}
+
if (MemorySpaceMap == NULL) {
return EFI_INVALID_PARAMETER;
}
- *NumberOfDescriptors = 0;
- *MemorySpaceMap = NULL;
+ *NumberOfDescriptors = 0;
+ *MemorySpaceMap = NULL;
//
// Take the lock, for entering the loop with the lock held.
@@ -1706,18 +1757,19 @@ CoreGetMemorySpaceMap ( // AllocatePool() called below has to be running outside the GCD lock.
//
DescriptorCount = CoreCountGcdMapEntry (&mGcdMemorySpaceMap);
- if (DescriptorCount == *NumberOfDescriptors && *MemorySpaceMap != NULL) {
+ if ((DescriptorCount == *NumberOfDescriptors) && (*MemorySpaceMap != NULL)) {
//
// Fill in the MemorySpaceMap if no memory space map change.
//
Descriptor = *MemorySpaceMap;
- Link = mGcdMemorySpaceMap.ForwardLink;
+ Link = mGcdMemorySpaceMap.ForwardLink;
while (Link != &mGcdMemorySpaceMap) {
Entry = CR (Link, EFI_GCD_MAP_ENTRY, Link, EFI_GCD_MAP_SIGNATURE);
BuildMemoryDescriptor (Descriptor, Entry);
Descriptor++;
Link = Link->ForwardLink;
}
+
//
// We're done; exit the loop with the lock held.
//
@@ -1739,8 +1791,10 @@ CoreGetMemorySpaceMap ( FreePool (*MemorySpaceMap);
}
- *MemorySpaceMap = AllocatePool (DescriptorCount *
- sizeof (EFI_GCD_MEMORY_SPACE_DESCRIPTOR));
+ *MemorySpaceMap = AllocatePool (
+ DescriptorCount *
+ sizeof (EFI_GCD_MEMORY_SPACE_DESCRIPTOR)
+ );
if (*MemorySpaceMap == NULL) {
*NumberOfDescriptors = 0;
return EFI_OUT_OF_RESOURCES;
@@ -1756,6 +1810,7 @@ CoreGetMemorySpaceMap ( //
CoreAcquireGcdMemoryLock ();
}
+
//
// We exited the loop with the lock held, release it.
//
@@ -1764,7 +1819,6 @@ CoreGetMemorySpaceMap ( return EFI_SUCCESS;
}
-
/**
Adds reserved I/O or I/O resources to the global coherency domain of the processor.
@@ -1790,12 +1844,12 @@ CoreAddIoSpace ( //
// Make sure parameters are valid
//
- if (GcdIoType <= EfiGcdIoTypeNonExistent || GcdIoType >= EfiGcdIoTypeMaximum) {
+ if ((GcdIoType <= EfiGcdIoTypeNonExistent) || (GcdIoType >= EfiGcdIoTypeMaximum)) {
return EFI_INVALID_PARAMETER;
}
- return CoreConvertSpace (GCD_ADD_IO_OPERATION, (EFI_GCD_MEMORY_TYPE) 0, GcdIoType, BaseAddress, Length, 0, 0);
-}
+ return CoreConvertSpace (GCD_ADD_IO_OPERATION, (EFI_GCD_MEMORY_TYPE)0, GcdIoType, BaseAddress, Length, 0, 0);
+}
/**
Allocates nonexistent I/O, reserved I/O, or I/O resources from the global coherency
@@ -1831,6 +1885,7 @@ CoreAllocateIoSpace ( } else {
DEBUG ((DEBUG_GCD, "GCD:AllocateIoSpace(Base=<NULL>,Length=%016lx)\n", Length));
}
+
DEBUG ((DEBUG_GCD, " GcdAllocateType = %a\n", mGcdAllocationTypeNames[MIN (GcdAllocateType, EfiGcdMaxAllocateType)]));
DEBUG ((DEBUG_GCD, " GcdIoType = %a\n", mGcdIoTypeNames[MIN (GcdIoType, EfiGcdIoTypeMaximum)]));
DEBUG ((DEBUG_GCD, " Alignment = %016lx\n", LShiftU64 (1, Alignment)));
@@ -1840,7 +1895,7 @@ CoreAllocateIoSpace ( return CoreAllocateSpace (
GCD_ALLOCATE_IO_OPERATION,
GcdAllocateType,
- (EFI_GCD_MEMORY_TYPE) 0,
+ (EFI_GCD_MEMORY_TYPE)0,
GcdIoType,
Alignment,
Length,
@@ -1850,7 +1905,6 @@ CoreAllocateIoSpace ( );
}
-
/**
Frees nonexistent I/O, reserved I/O, or I/O resources from the global coherency
domain of the processor.
@@ -1870,10 +1924,9 @@ CoreFreeIoSpace ( {
DEBUG ((DEBUG_GCD, "GCD:FreeIoSpace(Base=%016lx,Length=%016lx)\n", BaseAddress, Length));
- return CoreConvertSpace (GCD_FREE_IO_OPERATION, (EFI_GCD_MEMORY_TYPE) 0, (EFI_GCD_IO_TYPE) 0, BaseAddress, Length, 0, 0);
+ return CoreConvertSpace (GCD_FREE_IO_OPERATION, (EFI_GCD_MEMORY_TYPE)0, (EFI_GCD_IO_TYPE)0, BaseAddress, Length, 0, 0);
}
-
/**
Removes reserved I/O or I/O resources from the global coherency domain of the
processor.
@@ -1893,10 +1946,9 @@ CoreRemoveIoSpace ( {
DEBUG ((DEBUG_GCD, "GCD:RemoveIoSpace(Base=%016lx,Length=%016lx)\n", BaseAddress, Length));
- return CoreConvertSpace (GCD_REMOVE_IO_OPERATION, (EFI_GCD_MEMORY_TYPE) 0, (EFI_GCD_IO_TYPE) 0, BaseAddress, Length, 0, 0);
+ return CoreConvertSpace (GCD_REMOVE_IO_OPERATION, (EFI_GCD_MEMORY_TYPE)0, (EFI_GCD_IO_TYPE)0, BaseAddress, Length, 0, 0);
}
-
/**
Build a IO descriptor according to an entry.
@@ -1917,7 +1969,6 @@ BuildIoDescriptor ( Descriptor->DeviceHandle = Entry->DeviceHandle;
}
-
/**
Retrieves the descriptor for an I/O region containing a specified address.
@@ -1969,7 +2020,6 @@ CoreGetIoSpaceDescriptor ( return Status;
}
-
/**
Returns a map of the I/O resources in the global coherency domain of the processor.
@@ -1999,6 +2049,7 @@ CoreGetIoSpaceMap ( if (NumberOfDescriptors == NULL) {
return EFI_INVALID_PARAMETER;
}
+
if (IoSpaceMap == NULL) {
return EFI_INVALID_PARAMETER;
}
@@ -2023,13 +2074,14 @@ CoreGetIoSpaceMap ( // Fill in the IoSpaceMap
//
Descriptor = *IoSpaceMap;
- Link = mGcdIoSpaceMap.ForwardLink;
+ Link = mGcdIoSpaceMap.ForwardLink;
while (Link != &mGcdIoSpaceMap) {
Entry = CR (Link, EFI_GCD_MAP_ENTRY, Link, EFI_GCD_MAP_SIGNATURE);
BuildIoDescriptor (Descriptor, Entry);
Descriptor++;
Link = Link->ForwardLink;
}
+
Status = EFI_SUCCESS;
Done:
@@ -2037,7 +2089,6 @@ Done: return Status;
}
-
/**
Converts a Resource Descriptor HOB attributes mask to an EFI Memory Descriptor
capabilities mask
@@ -2083,8 +2134,8 @@ CalculateTotalMemoryBinSizeNeeded ( VOID
)
{
- UINTN Index;
- UINT64 TotalSize;
+ UINTN Index;
+ UINT64 TotalSize;
//
// Loop through each memory type in the order specified by the gMemoryTypeInformation[] array
@@ -2108,45 +2159,49 @@ CalculateTotalMemoryBinSizeNeeded ( **/
VOID
FindLargestFreeRegion (
- IN OUT EFI_PHYSICAL_ADDRESS *BaseAddress,
- IN OUT UINT64 *Length,
- IN EFI_HOB_MEMORY_ALLOCATION *MemoryHob
- )
+ IN OUT EFI_PHYSICAL_ADDRESS *BaseAddress,
+ IN OUT UINT64 *Length,
+ IN EFI_HOB_MEMORY_ALLOCATION *MemoryHob
+ )
{
- EFI_PHYSICAL_ADDRESS TopAddress;
- EFI_PHYSICAL_ADDRESS AllocatedTop;
- EFI_PHYSICAL_ADDRESS LowerBase;
- UINT64 LowerSize;
- EFI_PHYSICAL_ADDRESS UpperBase;
- UINT64 UpperSize;
+ EFI_PHYSICAL_ADDRESS TopAddress;
+ EFI_PHYSICAL_ADDRESS AllocatedTop;
+ EFI_PHYSICAL_ADDRESS LowerBase;
+ UINT64 LowerSize;
+ EFI_PHYSICAL_ADDRESS UpperBase;
+ UINT64 UpperSize;
TopAddress = *BaseAddress + *Length;
while (MemoryHob != NULL) {
AllocatedTop = MemoryHob->AllocDescriptor.MemoryBaseAddress + MemoryHob->AllocDescriptor.MemoryLength;
if ((MemoryHob->AllocDescriptor.MemoryBaseAddress >= *BaseAddress) &&
- (AllocatedTop <= TopAddress)) {
+ (AllocatedTop <= TopAddress))
+ {
LowerBase = *BaseAddress;
LowerSize = MemoryHob->AllocDescriptor.MemoryBaseAddress - *BaseAddress;
UpperBase = AllocatedTop;
UpperSize = TopAddress - AllocatedTop;
if (LowerSize != 0) {
- FindLargestFreeRegion (&LowerBase, &LowerSize, (EFI_HOB_MEMORY_ALLOCATION *) GetNextHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, GET_NEXT_HOB (MemoryHob)));
+ FindLargestFreeRegion (&LowerBase, &LowerSize, (EFI_HOB_MEMORY_ALLOCATION *)GetNextHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, GET_NEXT_HOB (MemoryHob)));
}
+
if (UpperSize != 0) {
- FindLargestFreeRegion (&UpperBase, &UpperSize, (EFI_HOB_MEMORY_ALLOCATION *) GetNextHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, GET_NEXT_HOB (MemoryHob)));
+ FindLargestFreeRegion (&UpperBase, &UpperSize, (EFI_HOB_MEMORY_ALLOCATION *)GetNextHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, GET_NEXT_HOB (MemoryHob)));
}
if (UpperSize >= LowerSize) {
- *Length = UpperSize;
+ *Length = UpperSize;
*BaseAddress = UpperBase;
} else {
- *Length = LowerSize;
+ *Length = LowerSize;
*BaseAddress = LowerBase;
}
+
return;
}
+
MemoryHob = GetNextHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, GET_NEXT_HOB (MemoryHob));
}
}
@@ -2173,23 +2228,23 @@ CoreInitializeMemoryServices ( OUT UINT64 *MemoryLength
)
{
- EFI_PEI_HOB_POINTERS Hob;
- EFI_MEMORY_TYPE_INFORMATION *EfiMemoryTypeInformation;
- UINTN DataSize;
- BOOLEAN Found;
- EFI_HOB_HANDOFF_INFO_TABLE *PhitHob;
- EFI_HOB_RESOURCE_DESCRIPTOR *ResourceHob;
- EFI_HOB_RESOURCE_DESCRIPTOR *PhitResourceHob;
- EFI_PHYSICAL_ADDRESS BaseAddress;
- UINT64 Length;
- UINT64 Attributes;
- UINT64 Capabilities;
- EFI_PHYSICAL_ADDRESS TestedMemoryBaseAddress;
- UINT64 TestedMemoryLength;
- EFI_PHYSICAL_ADDRESS HighAddress;
- EFI_HOB_GUID_TYPE *GuidHob;
- UINT32 ReservedCodePageNumber;
- UINT64 MinimalMemorySizeNeeded;
+ EFI_PEI_HOB_POINTERS Hob;
+ EFI_MEMORY_TYPE_INFORMATION *EfiMemoryTypeInformation;
+ UINTN DataSize;
+ BOOLEAN Found;
+ EFI_HOB_HANDOFF_INFO_TABLE *PhitHob;
+ EFI_HOB_RESOURCE_DESCRIPTOR *ResourceHob;
+ EFI_HOB_RESOURCE_DESCRIPTOR *PhitResourceHob;
+ EFI_PHYSICAL_ADDRESS BaseAddress;
+ UINT64 Length;
+ UINT64 Attributes;
+ UINT64 Capabilities;
+ EFI_PHYSICAL_ADDRESS TestedMemoryBaseAddress;
+ UINT64 TestedMemoryLength;
+ EFI_PHYSICAL_ADDRESS HighAddress;
+ EFI_HOB_GUID_TYPE *GuidHob;
+ UINT32 ReservedCodePageNumber;
+ UINT64 MinimalMemorySizeNeeded;
//
// Point at the first HOB. This must be the PHIT HOB.
@@ -2206,27 +2261,28 @@ CoreInitializeMemoryServices ( //
// Initialize Local Variables
//
- PhitResourceHob = NULL;
- ResourceHob = NULL;
- BaseAddress = 0;
- Length = 0;
- Attributes = 0;
+ PhitResourceHob = NULL;
+ ResourceHob = NULL;
+ BaseAddress = 0;
+ Length = 0;
+ Attributes = 0;
//
// Cache the PHIT HOB for later use
//
PhitHob = Hob.HandoffInformationTable;
- if (PcdGet64(PcdLoadModuleAtFixAddressEnable) != 0) {
- ReservedCodePageNumber = PcdGet32(PcdLoadFixAddressRuntimeCodePageNumber);
- ReservedCodePageNumber += PcdGet32(PcdLoadFixAddressBootTimeCodePageNumber);
+ if (PcdGet64 (PcdLoadModuleAtFixAddressEnable) != 0) {
+ ReservedCodePageNumber = PcdGet32 (PcdLoadFixAddressRuntimeCodePageNumber);
+ ReservedCodePageNumber += PcdGet32 (PcdLoadFixAddressBootTimeCodePageNumber);
//
// cache the Top address for loading modules at Fixed Address
//
gLoadModuleAtFixAddressConfigurationTable.DxeCodeTopAddress = PhitHob->EfiMemoryTop
- + EFI_PAGES_TO_SIZE(ReservedCodePageNumber);
+ + EFI_PAGES_TO_SIZE (ReservedCodePageNumber);
}
+
//
// See if a Memory Type Information HOB is available
//
@@ -2234,7 +2290,7 @@ CoreInitializeMemoryServices ( if (GuidHob != NULL) {
EfiMemoryTypeInformation = GET_GUID_HOB_DATA (GuidHob);
DataSize = GET_GUID_HOB_DATA_SIZE (GuidHob);
- if (EfiMemoryTypeInformation != NULL && DataSize > 0 && DataSize <= (EfiMaxMemoryType + 1) * sizeof (EFI_MEMORY_TYPE_INFORMATION)) {
+ if ((EfiMemoryTypeInformation != NULL) && (DataSize > 0) && (DataSize <= (EfiMaxMemoryType + 1) * sizeof (EFI_MEMORY_TYPE_INFORMATION))) {
CopyMem (&gMemoryTypeInformation, EfiMemoryTypeInformation, DataSize);
}
}
@@ -2247,8 +2303,8 @@ CoreInitializeMemoryServices ( //
// Find the Resource Descriptor HOB that contains PHIT range EfiFreeMemoryBottom..EfiFreeMemoryTop
//
- Found = FALSE;
- for (Hob.Raw = *HobStart; !END_OF_HOB_LIST(Hob); Hob.Raw = GET_NEXT_HOB(Hob)) {
+ Found = FALSE;
+ for (Hob.Raw = *HobStart; !END_OF_HOB_LIST (Hob); Hob.Raw = GET_NEXT_HOB (Hob)) {
//
// Skip all HOBs except Resource Descriptor HOBs
//
@@ -2263,6 +2319,7 @@ CoreInitializeMemoryServices ( if (ResourceHob->ResourceType != EFI_RESOURCE_SYSTEM_MEMORY) {
continue;
}
+
if ((ResourceHob->ResourceAttribute & MEMORY_ATTRIBUTE_MASK) != TESTED_MEMORY_ATTRIBUTES) {
continue;
}
@@ -2273,6 +2330,7 @@ CoreInitializeMemoryServices ( if (PhitHob->EfiFreeMemoryBottom < ResourceHob->PhysicalStart) {
continue;
}
+
if (PhitHob->EfiFreeMemoryTop > (ResourceHob->PhysicalStart + ResourceHob->ResourceLength)) {
continue;
}
@@ -2281,14 +2339,14 @@ CoreInitializeMemoryServices ( // Cache the resource descriptor HOB for the memory region described by the PHIT HOB
//
PhitResourceHob = ResourceHob;
- Found = TRUE;
+ Found = TRUE;
//
// Compute range between PHIT EfiMemoryTop and the end of the Resource Descriptor HOB
//
Attributes = PhitResourceHob->ResourceAttribute;
BaseAddress = PageAlignAddress (PhitHob->EfiMemoryTop);
- Length = PageAlignLength (ResourceHob->PhysicalStart + ResourceHob->ResourceLength - BaseAddress);
+ Length = PageAlignLength (ResourceHob->PhysicalStart + ResourceHob->ResourceLength - BaseAddress);
FindLargestFreeRegion (&BaseAddress, &Length, (EFI_HOB_MEMORY_ALLOCATION *)GetFirstHob (EFI_HOB_TYPE_MEMORY_ALLOCATION));
if (Length < MinimalMemorySizeNeeded) {
//
@@ -2296,18 +2354,19 @@ CoreInitializeMemoryServices ( // Compute range between PHIT EfiFreeMemoryBottom and PHIT EfiFreeMemoryTop
//
BaseAddress = PageAlignAddress (PhitHob->EfiFreeMemoryBottom);
- Length = PageAlignLength (PhitHob->EfiFreeMemoryTop - BaseAddress);
- //This region is required to have no memory allocation inside it, skip check for entries in HOB List
+ Length = PageAlignLength (PhitHob->EfiFreeMemoryTop - BaseAddress);
+ // This region is required to have no memory allocation inside it, skip check for entries in HOB List
if (Length < MinimalMemorySizeNeeded) {
//
// If that range is not large enough to intialize the DXE Core, then
// Compute range between the start of the Resource Descriptor HOB and the start of the HOB List
//
BaseAddress = PageAlignAddress (ResourceHob->PhysicalStart);
- Length = PageAlignLength ((UINT64)((UINTN)*HobStart - BaseAddress));
+ Length = PageAlignLength ((UINT64)((UINTN)*HobStart - BaseAddress));
FindLargestFreeRegion (&BaseAddress, &Length, (EFI_HOB_MEMORY_ALLOCATION *)GetFirstHob (EFI_HOB_TYPE_MEMORY_ALLOCATION));
}
}
+
break;
}
@@ -2329,13 +2388,14 @@ CoreInitializeMemoryServices ( // The max address must be within the physically addressible range for the processor.
//
HighAddress = MAX_ALLOC_ADDRESS;
- for (Hob.Raw = *HobStart; !END_OF_HOB_LIST(Hob); Hob.Raw = GET_NEXT_HOB(Hob)) {
+ for (Hob.Raw = *HobStart; !END_OF_HOB_LIST (Hob); Hob.Raw = GET_NEXT_HOB (Hob)) {
//
// Skip the Resource Descriptor HOB that contains the PHIT
//
if (Hob.ResourceDescriptor == PhitResourceHob) {
continue;
}
+
//
// Skip all HOBs except Resource Descriptor HOBs
//
@@ -2350,9 +2410,11 @@ CoreInitializeMemoryServices ( if (ResourceHob->ResourceType != EFI_RESOURCE_SYSTEM_MEMORY) {
continue;
}
+
if ((ResourceHob->ResourceAttribute & MEMORY_ATTRIBUTE_MASK) != TESTED_MEMORY_ATTRIBUTES) {
continue;
}
+
if ((ResourceHob->PhysicalStart + ResourceHob->ResourceLength) > (EFI_PHYSICAL_ADDRESS)MAX_ALLOC_ADDRESS) {
continue;
}
@@ -2360,7 +2422,7 @@ CoreInitializeMemoryServices ( //
// Skip Resource Descriptor HOBs that are below a previously found Resource Descriptor HOB
//
- if (HighAddress != (EFI_PHYSICAL_ADDRESS)MAX_ALLOC_ADDRESS && ResourceHob->PhysicalStart <= HighAddress) {
+ if ((HighAddress != (EFI_PHYSICAL_ADDRESS)MAX_ALLOC_ADDRESS) && (ResourceHob->PhysicalStart <= HighAddress)) {
continue;
}
@@ -2368,7 +2430,7 @@ CoreInitializeMemoryServices ( // Skip Resource Descriptor HOBs that are not large enough to initilize the DXE Core
//
TestedMemoryBaseAddress = PageAlignAddress (ResourceHob->PhysicalStart);
- TestedMemoryLength = PageAlignLength (ResourceHob->PhysicalStart + ResourceHob->ResourceLength - TestedMemoryBaseAddress);
+ TestedMemoryLength = PageAlignLength (ResourceHob->PhysicalStart + ResourceHob->ResourceLength - TestedMemoryBaseAddress);
FindLargestFreeRegion (&TestedMemoryBaseAddress, &TestedMemoryLength, (EFI_HOB_MEMORY_ALLOCATION *)GetFirstHob (EFI_HOB_TYPE_MEMORY_ALLOCATION));
if (TestedMemoryLength < MinimalMemorySizeNeeded) {
continue;
@@ -2417,7 +2479,6 @@ CoreInitializeMemoryServices ( return EFI_SUCCESS;
}
-
/**
External function. Initializes the GCD and memory services based on the memory
descriptor HOBs. This function is responsible for priming the GCD map and the
@@ -2439,27 +2500,27 @@ CoreInitializeGcdServices ( IN UINT64 MemoryLength
)
{
- EFI_PEI_HOB_POINTERS Hob;
- VOID *NewHobList;
- EFI_HOB_HANDOFF_INFO_TABLE *PhitHob;
- UINT8 SizeOfMemorySpace;
- UINT8 SizeOfIoSpace;
- EFI_HOB_RESOURCE_DESCRIPTOR *ResourceHob;
- EFI_PHYSICAL_ADDRESS BaseAddress;
- UINT64 Length;
- EFI_STATUS Status;
- EFI_GCD_MAP_ENTRY *Entry;
- EFI_GCD_MEMORY_TYPE GcdMemoryType;
- EFI_GCD_IO_TYPE GcdIoType;
- EFI_GCD_MEMORY_SPACE_DESCRIPTOR Descriptor;
- EFI_HOB_MEMORY_ALLOCATION *MemoryHob;
- EFI_HOB_FIRMWARE_VOLUME *FirmwareVolumeHob;
- UINTN NumberOfDescriptors;
- EFI_GCD_MEMORY_SPACE_DESCRIPTOR *MemorySpaceMap;
- UINTN Index;
- UINT64 Capabilities;
- EFI_HOB_CPU * CpuHob;
- EFI_GCD_MEMORY_SPACE_DESCRIPTOR *MemorySpaceMapHobList;
+ EFI_PEI_HOB_POINTERS Hob;
+ VOID *NewHobList;
+ EFI_HOB_HANDOFF_INFO_TABLE *PhitHob;
+ UINT8 SizeOfMemorySpace;
+ UINT8 SizeOfIoSpace;
+ EFI_HOB_RESOURCE_DESCRIPTOR *ResourceHob;
+ EFI_PHYSICAL_ADDRESS BaseAddress;
+ UINT64 Length;
+ EFI_STATUS Status;
+ EFI_GCD_MAP_ENTRY *Entry;
+ EFI_GCD_MEMORY_TYPE GcdMemoryType;
+ EFI_GCD_IO_TYPE GcdIoType;
+ EFI_GCD_MEMORY_SPACE_DESCRIPTOR Descriptor;
+ EFI_HOB_MEMORY_ALLOCATION *MemoryHob;
+ EFI_HOB_FIRMWARE_VOLUME *FirmwareVolumeHob;
+ UINTN NumberOfDescriptors;
+ EFI_GCD_MEMORY_SPACE_DESCRIPTOR *MemorySpaceMap;
+ UINTN Index;
+ UINT64 Capabilities;
+ EFI_HOB_CPU *CpuHob;
+ EFI_GCD_MEMORY_SPACE_DESCRIPTOR *MemorySpaceMapHobList;
//
// Cache the PHIT HOB for later use
@@ -2501,48 +2562,50 @@ CoreInitializeGcdServices ( //
// Walk the HOB list and add all resource descriptors to the GCD
//
- for (Hob.Raw = *HobStart; !END_OF_HOB_LIST(Hob); Hob.Raw = GET_NEXT_HOB(Hob)) {
-
+ for (Hob.Raw = *HobStart; !END_OF_HOB_LIST (Hob); Hob.Raw = GET_NEXT_HOB (Hob)) {
GcdMemoryType = EfiGcdMemoryTypeNonExistent;
GcdIoType = EfiGcdIoTypeNonExistent;
if (GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_RESOURCE_DESCRIPTOR) {
-
ResourceHob = Hob.ResourceDescriptor;
switch (ResourceHob->ResourceType) {
- case EFI_RESOURCE_SYSTEM_MEMORY:
- if ((ResourceHob->ResourceAttribute & MEMORY_ATTRIBUTE_MASK) == TESTED_MEMORY_ATTRIBUTES) {
- if ((ResourceHob->ResourceAttribute & EFI_RESOURCE_ATTRIBUTE_MORE_RELIABLE) == EFI_RESOURCE_ATTRIBUTE_MORE_RELIABLE) {
- GcdMemoryType = EfiGcdMemoryTypeMoreReliable;
- } else {
- GcdMemoryType = EfiGcdMemoryTypeSystemMemory;
+ case EFI_RESOURCE_SYSTEM_MEMORY:
+ if ((ResourceHob->ResourceAttribute & MEMORY_ATTRIBUTE_MASK) == TESTED_MEMORY_ATTRIBUTES) {
+ if ((ResourceHob->ResourceAttribute & EFI_RESOURCE_ATTRIBUTE_MORE_RELIABLE) == EFI_RESOURCE_ATTRIBUTE_MORE_RELIABLE) {
+ GcdMemoryType = EfiGcdMemoryTypeMoreReliable;
+ } else {
+ GcdMemoryType = EfiGcdMemoryTypeSystemMemory;
+ }
}
- }
- if ((ResourceHob->ResourceAttribute & MEMORY_ATTRIBUTE_MASK) == INITIALIZED_MEMORY_ATTRIBUTES) {
- GcdMemoryType = EfiGcdMemoryTypeReserved;
- }
- if ((ResourceHob->ResourceAttribute & MEMORY_ATTRIBUTE_MASK) == PRESENT_MEMORY_ATTRIBUTES) {
+
+ if ((ResourceHob->ResourceAttribute & MEMORY_ATTRIBUTE_MASK) == INITIALIZED_MEMORY_ATTRIBUTES) {
+ GcdMemoryType = EfiGcdMemoryTypeReserved;
+ }
+
+ if ((ResourceHob->ResourceAttribute & MEMORY_ATTRIBUTE_MASK) == PRESENT_MEMORY_ATTRIBUTES) {
+ GcdMemoryType = EfiGcdMemoryTypeReserved;
+ }
+
+ if ((ResourceHob->ResourceAttribute & EFI_RESOURCE_ATTRIBUTE_PERSISTENT) == EFI_RESOURCE_ATTRIBUTE_PERSISTENT) {
+ GcdMemoryType = EfiGcdMemoryTypePersistent;
+ }
+
+ break;
+ case EFI_RESOURCE_MEMORY_MAPPED_IO:
+ case EFI_RESOURCE_FIRMWARE_DEVICE:
+ GcdMemoryType = EfiGcdMemoryTypeMemoryMappedIo;
+ break;
+ case EFI_RESOURCE_MEMORY_MAPPED_IO_PORT:
+ case EFI_RESOURCE_MEMORY_RESERVED:
GcdMemoryType = EfiGcdMemoryTypeReserved;
- }
- if ((ResourceHob->ResourceAttribute & EFI_RESOURCE_ATTRIBUTE_PERSISTENT) == EFI_RESOURCE_ATTRIBUTE_PERSISTENT) {
- GcdMemoryType = EfiGcdMemoryTypePersistent;
- }
- break;
- case EFI_RESOURCE_MEMORY_MAPPED_IO:
- case EFI_RESOURCE_FIRMWARE_DEVICE:
- GcdMemoryType = EfiGcdMemoryTypeMemoryMappedIo;
- break;
- case EFI_RESOURCE_MEMORY_MAPPED_IO_PORT:
- case EFI_RESOURCE_MEMORY_RESERVED:
- GcdMemoryType = EfiGcdMemoryTypeReserved;
- break;
- case EFI_RESOURCE_IO:
- GcdIoType = EfiGcdIoTypeIo;
- break;
- case EFI_RESOURCE_IO_RESERVED:
- GcdIoType = EfiGcdIoTypeReserved;
- break;
+ break;
+ case EFI_RESOURCE_IO:
+ GcdIoType = EfiGcdIoTypeIo;
+ break;
+ case EFI_RESOURCE_IO_RESERVED:
+ GcdIoType = EfiGcdIoTypeReserved;
+ break;
}
if (GcdMemoryType != EfiGcdMemoryTypeNonExistent) {
@@ -2582,8 +2645,10 @@ CoreInitializeGcdServices ( //
Status = CoreGetMemorySpaceDescriptor (MemoryBaseAddress, &Descriptor);
if (!EFI_ERROR (Status)) {
- ASSERT ((Descriptor.GcdMemoryType == EfiGcdMemoryTypeSystemMemory) ||
- (Descriptor.GcdMemoryType == EfiGcdMemoryTypeMoreReliable));
+ ASSERT (
+ (Descriptor.GcdMemoryType == EfiGcdMemoryTypeSystemMemory) ||
+ (Descriptor.GcdMemoryType == EfiGcdMemoryTypeMoreReliable)
+ );
Status = CoreAllocateMemorySpace (
EfiGcdAllocateAddress,
Descriptor.GcdMemoryType,
@@ -2599,11 +2664,11 @@ CoreInitializeGcdServices ( // Walk the HOB list and allocate all memory space that is consumed by memory allocation HOBs,
// and Firmware Volume HOBs. Also update the EFI Memory Map with the memory allocation HOBs.
//
- for (Hob.Raw = *HobStart; !END_OF_HOB_LIST(Hob); Hob.Raw = GET_NEXT_HOB(Hob)) {
+ for (Hob.Raw = *HobStart; !END_OF_HOB_LIST (Hob); Hob.Raw = GET_NEXT_HOB (Hob)) {
if (GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_MEMORY_ALLOCATION) {
- MemoryHob = Hob.MemoryAllocation;
+ MemoryHob = Hob.MemoryAllocation;
BaseAddress = MemoryHob->AllocDescriptor.MemoryBaseAddress;
- Status = CoreGetMemorySpaceDescriptor (BaseAddress, &Descriptor);
+ Status = CoreGetMemorySpaceDescriptor (BaseAddress, &Descriptor);
if (!EFI_ERROR (Status)) {
Status = CoreAllocateMemorySpace (
EfiGcdAllocateAddress,
@@ -2616,7 +2681,8 @@ CoreInitializeGcdServices ( );
if (!EFI_ERROR (Status) &&
((Descriptor.GcdMemoryType == EfiGcdMemoryTypeSystemMemory) ||
- (Descriptor.GcdMemoryType == EfiGcdMemoryTypeMoreReliable))) {
+ (Descriptor.GcdMemoryType == EfiGcdMemoryTypeMoreReliable)))
+ {
CoreAddMemoryDescriptor (
MemoryHob->AllocDescriptor.MemoryType,
MemoryHob->AllocDescriptor.MemoryBaseAddress,
@@ -2629,16 +2695,16 @@ CoreInitializeGcdServices ( if (GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_FV) {
FirmwareVolumeHob = Hob.FirmwareVolume;
- BaseAddress = FirmwareVolumeHob->BaseAddress;
- Status = CoreAllocateMemorySpace (
- EfiGcdAllocateAddress,
- EfiGcdMemoryTypeMemoryMappedIo,
- 0,
- FirmwareVolumeHob->Length,
- &BaseAddress,
- gDxeCoreImageHandle,
- NULL
- );
+ BaseAddress = FirmwareVolumeHob->BaseAddress;
+ Status = CoreAllocateMemorySpace (
+ EfiGcdAllocateAddress,
+ EfiGcdMemoryTypeMemoryMappedIo,
+ 0,
+ FirmwareVolumeHob->Length,
+ &BaseAddress,
+ gDxeCoreImageHandle,
+ NULL
+ );
}
}
@@ -2651,15 +2717,18 @@ CoreInitializeGcdServices ( MemorySpaceMapHobList = NULL;
for (Index = 0; Index < NumberOfDescriptors; Index++) {
if ((MemorySpaceMap[Index].GcdMemoryType == EfiGcdMemoryTypeSystemMemory) ||
- (MemorySpaceMap[Index].GcdMemoryType == EfiGcdMemoryTypeMoreReliable)) {
+ (MemorySpaceMap[Index].GcdMemoryType == EfiGcdMemoryTypeMoreReliable))
+ {
if (MemorySpaceMap[Index].ImageHandle == NULL) {
- BaseAddress = PageAlignAddress (MemorySpaceMap[Index].BaseAddress);
- Length = PageAlignLength (MemorySpaceMap[Index].BaseAddress + MemorySpaceMap[Index].Length - BaseAddress);
- if (Length == 0 || MemorySpaceMap[Index].BaseAddress + MemorySpaceMap[Index].Length < BaseAddress) {
+ BaseAddress = PageAlignAddress (MemorySpaceMap[Index].BaseAddress);
+ Length = PageAlignLength (MemorySpaceMap[Index].BaseAddress + MemorySpaceMap[Index].Length - BaseAddress);
+ if ((Length == 0) || (MemorySpaceMap[Index].BaseAddress + MemorySpaceMap[Index].Length < BaseAddress)) {
continue;
}
- if (((UINTN) MemorySpaceMap[Index].BaseAddress <= (UINTN) (*HobStart)) &&
- ((UINTN) (MemorySpaceMap[Index].BaseAddress + MemorySpaceMap[Index].Length) >= (UINTN) PhitHob->EfiFreeMemoryBottom)) {
+
+ if (((UINTN)MemorySpaceMap[Index].BaseAddress <= (UINTN)(*HobStart)) &&
+ ((UINTN)(MemorySpaceMap[Index].BaseAddress + MemorySpaceMap[Index].Length) >= (UINTN)PhitHob->EfiFreeMemoryBottom))
+ {
//
// Skip the memory space that covers HOB List, it should be processed
// after HOB List relocation to avoid the resources allocated by others
@@ -2668,6 +2737,7 @@ CoreInitializeGcdServices ( MemorySpaceMapHobList = &MemorySpaceMap[Index];
continue;
}
+
CoreAddMemoryDescriptor (
EfiConventionalMemory,
BaseAddress,
@@ -2695,7 +2765,7 @@ CoreInitializeGcdServices ( // may have not enough remaining resource for HOB List.
//
NewHobList = AllocateCopyPool (
- (UINTN) PhitHob->EfiFreeMemoryBottom - (UINTN) (*HobStart),
+ (UINTN)PhitHob->EfiFreeMemoryBottom - (UINTN)(*HobStart),
*HobStart
);
ASSERT (NewHobList != NULL);
@@ -2709,7 +2779,7 @@ CoreInitializeGcdServices ( // after HOB List relocation.
//
BaseAddress = PageAlignAddress (MemorySpaceMapHobList->BaseAddress);
- Length = PageAlignLength (MemorySpaceMapHobList->BaseAddress + MemorySpaceMapHobList->Length - BaseAddress);
+ Length = PageAlignLength (MemorySpaceMapHobList->BaseAddress + MemorySpaceMapHobList->Length - BaseAddress);
CoreAddMemoryDescriptor (
EfiConventionalMemory,
BaseAddress,
diff --git a/MdeModulePkg/Core/Dxe/Gcd/Gcd.h b/MdeModulePkg/Core/Dxe/Gcd/Gcd.h index 715687b928..d4a4dd7c1b 100644 --- a/MdeModulePkg/Core/Dxe/Gcd/Gcd.h +++ b/MdeModulePkg/Core/Dxe/Gcd/Gcd.h @@ -13,8 +13,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent //
// GCD Operations
//
-#define GCD_MEMORY_SPACE_OPERATION 0x20
-#define GCD_IO_SPACE_OPERATION 0x40
+#define GCD_MEMORY_SPACE_OPERATION 0x20
+#define GCD_IO_SPACE_OPERATION 0x40
#define GCD_ADD_MEMORY_OPERATION (GCD_MEMORY_SPACE_OPERATION | 0)
#define GCD_ALLOCATE_MEMORY_OPERATION (GCD_MEMORY_SPACE_OPERATION | 1)
@@ -23,18 +23,18 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #define GCD_SET_ATTRIBUTES_MEMORY_OPERATION (GCD_MEMORY_SPACE_OPERATION | 4)
#define GCD_SET_CAPABILITIES_MEMORY_OPERATION (GCD_MEMORY_SPACE_OPERATION | 5)
-#define GCD_ADD_IO_OPERATION (GCD_IO_SPACE_OPERATION | 0)
-#define GCD_ALLOCATE_IO_OPERATION (GCD_IO_SPACE_OPERATION | 1)
-#define GCD_FREE_IO_OPERATION (GCD_IO_SPACE_OPERATION | 2)
-#define GCD_REMOVE_IO_OPERATION (GCD_IO_SPACE_OPERATION | 3)
+#define GCD_ADD_IO_OPERATION (GCD_IO_SPACE_OPERATION | 0)
+#define GCD_ALLOCATE_IO_OPERATION (GCD_IO_SPACE_OPERATION | 1)
+#define GCD_FREE_IO_OPERATION (GCD_IO_SPACE_OPERATION | 2)
+#define GCD_REMOVE_IO_OPERATION (GCD_IO_SPACE_OPERATION | 3)
//
// The data structure used to convert from GCD attributes to EFI Memory Map attributes
//
typedef struct {
- UINT64 Attribute;
- UINT64 Capability;
- BOOLEAN Memory;
+ UINT64 Attribute;
+ UINT64 Capability;
+ BOOLEAN Memory;
} GCD_ATTRIBUTE_CONVERSION_ENTRY;
#endif
diff --git a/MdeModulePkg/Core/Dxe/Hand/DriverSupport.c b/MdeModulePkg/Core/Dxe/Hand/DriverSupport.c index 12a202417c..0b824c62b7 100644 --- a/MdeModulePkg/Core/Dxe/Hand/DriverSupport.c +++ b/MdeModulePkg/Core/Dxe/Hand/DriverSupport.c @@ -9,10 +9,10 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include "DxeMain.h"
#include "Handle.h"
-
//
// Driver Support Functions
//
+
/**
Connects one or more drivers to a controller.
@@ -48,22 +48,22 @@ CoreConnectController ( IN BOOLEAN Recursive
)
{
- EFI_STATUS Status;
- EFI_STATUS ReturnStatus;
- IHANDLE *Handle;
- PROTOCOL_INTERFACE *Prot;
- LIST_ENTRY *Link;
- LIST_ENTRY *ProtLink;
- OPEN_PROTOCOL_DATA *OpenData;
- EFI_DEVICE_PATH_PROTOCOL *AlignedRemainingDevicePath;
- EFI_HANDLE *ChildHandleBuffer;
- UINTN ChildHandleCount;
- UINTN Index;
- UINTN HandleFilePathSize;
- UINTN RemainingDevicePathSize;
- EFI_DEVICE_PATH_PROTOCOL *HandleFilePath;
- EFI_DEVICE_PATH_PROTOCOL *FilePath;
- EFI_DEVICE_PATH_PROTOCOL *TempFilePath;
+ EFI_STATUS Status;
+ EFI_STATUS ReturnStatus;
+ IHANDLE *Handle;
+ PROTOCOL_INTERFACE *Prot;
+ LIST_ENTRY *Link;
+ LIST_ENTRY *ProtLink;
+ OPEN_PROTOCOL_DATA *OpenData;
+ EFI_DEVICE_PATH_PROTOCOL *AlignedRemainingDevicePath;
+ EFI_HANDLE *ChildHandleBuffer;
+ UINTN ChildHandleCount;
+ UINTN Index;
+ UINTN HandleFilePathSize;
+ UINTN RemainingDevicePathSize;
+ EFI_DEVICE_PATH_PROTOCOL *HandleFilePath;
+ EFI_DEVICE_PATH_PROTOCOL *FilePath;
+ EFI_DEVICE_PATH_PROTOCOL *TempFilePath;
//
// Make sure ControllerHandle is valid
@@ -87,25 +87,27 @@ CoreConnectController ( ASSERT (HandleFilePath != NULL);
FilePath = HandleFilePath;
TempFilePath = NULL;
- if (RemainingDevicePath != NULL && !Recursive) {
+ if ((RemainingDevicePath != NULL) && !Recursive) {
HandleFilePathSize = GetDevicePathSize (HandleFilePath) - sizeof (EFI_DEVICE_PATH_PROTOCOL);
RemainingDevicePathSize = GetDevicePathSize (RemainingDevicePath);
- TempFilePath = AllocateZeroPool (HandleFilePathSize + RemainingDevicePathSize);
+ TempFilePath = AllocateZeroPool (HandleFilePathSize + RemainingDevicePathSize);
ASSERT (TempFilePath != NULL);
CopyMem (TempFilePath, HandleFilePath, HandleFilePathSize);
- CopyMem ((UINT8 *) TempFilePath + HandleFilePathSize, RemainingDevicePath, RemainingDevicePathSize);
+ CopyMem ((UINT8 *)TempFilePath + HandleFilePathSize, RemainingDevicePath, RemainingDevicePathSize);
FilePath = TempFilePath;
}
+
Status = gSecurity2->FileAuthentication (
- gSecurity2,
- FilePath,
- NULL,
- 0,
- FALSE
- );
+ gSecurity2,
+ FilePath,
+ NULL,
+ 0,
+ FALSE
+ );
if (TempFilePath != NULL) {
FreePool (TempFilePath);
}
+
if (EFI_ERROR (Status)) {
return Status;
}
@@ -169,15 +171,15 @@ CoreConnectController ( return ReturnStatus;
}
-
//
// Count ControllerHandle's children
//
for (Link = Handle->Protocols.ForwardLink, ChildHandleCount = 0; Link != &Handle->Protocols; Link = Link->ForwardLink) {
- Prot = CR(Link, PROTOCOL_INTERFACE, Link, PROTOCOL_INTERFACE_SIGNATURE);
+ Prot = CR (Link, PROTOCOL_INTERFACE, Link, PROTOCOL_INTERFACE_SIGNATURE);
for (ProtLink = Prot->OpenList.ForwardLink;
- ProtLink != &Prot->OpenList;
- ProtLink = ProtLink->ForwardLink) {
+ ProtLink != &Prot->OpenList;
+ ProtLink = ProtLink->ForwardLink)
+ {
OpenData = CR (ProtLink, OPEN_PROTOCOL_DATA, Link, OPEN_PROTOCOL_DATA_SIGNATURE);
if ((OpenData->Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) != 0) {
ChildHandleCount++;
@@ -188,7 +190,7 @@ CoreConnectController ( //
// Allocate a handle buffer for ControllerHandle's children
//
- ChildHandleBuffer = AllocatePool (ChildHandleCount * sizeof(EFI_HANDLE));
+ ChildHandleBuffer = AllocatePool (ChildHandleCount * sizeof (EFI_HANDLE));
if (ChildHandleBuffer == NULL) {
CoreReleaseProtocolLock ();
return EFI_OUT_OF_RESOURCES;
@@ -198,10 +200,11 @@ CoreConnectController ( // Fill in a handle buffer with ControllerHandle's children
//
for (Link = Handle->Protocols.ForwardLink, ChildHandleCount = 0; Link != &Handle->Protocols; Link = Link->ForwardLink) {
- Prot = CR(Link, PROTOCOL_INTERFACE, Link, PROTOCOL_INTERFACE_SIGNATURE);
+ Prot = CR (Link, PROTOCOL_INTERFACE, Link, PROTOCOL_INTERFACE_SIGNATURE);
for (ProtLink = Prot->OpenList.ForwardLink;
- ProtLink != &Prot->OpenList;
- ProtLink = ProtLink->ForwardLink) {
+ ProtLink != &Prot->OpenList;
+ ProtLink = ProtLink->ForwardLink)
+ {
OpenData = CR (ProtLink, OPEN_PROTOCOL_DATA, Link, OPEN_PROTOCOL_DATA_SIGNATURE);
if ((OpenData->Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) != 0) {
ChildHandleBuffer[ChildHandleCount] = OpenData->ControllerHandle;
@@ -236,7 +239,6 @@ CoreConnectController ( return ReturnStatus;
}
-
/**
Add Driver Binding Protocols from Context Driver Image Handles to sorted
Driver Binding Protocol list.
@@ -296,11 +298,11 @@ AddSortedDriverBindingProtocol ( // Retrieve the Driver Binding Protocol associated with each Driver Binding Handle
//
Status = CoreHandleProtocol (
- DriverBindingHandleBuffer[Index],
- &gEfiDriverBindingProtocolGuid,
- (VOID **) &DriverBinding
- );
- if (EFI_ERROR (Status) || DriverBinding == NULL) {
+ DriverBindingHandleBuffer[Index],
+ &gEfiDriverBindingProtocolGuid,
+ (VOID **)&DriverBinding
+ );
+ if (EFI_ERROR (Status) || (DriverBinding == NULL)) {
continue;
}
@@ -319,21 +321,22 @@ AddSortedDriverBindingProtocol ( );
}
}
+
return;
}
//
// Retrieve the Driver Binding Protocol from DriverBindingHandle
//
- Status = CoreHandleProtocol(
+ Status = CoreHandleProtocol (
DriverBindingHandle,
&gEfiDriverBindingProtocolGuid,
- (VOID **) &DriverBinding
+ (VOID **)&DriverBinding
);
//
// If DriverBindingHandle does not support the Driver Binding Protocol then return
//
- if (EFI_ERROR (Status) || DriverBinding == NULL) {
+ if (EFI_ERROR (Status) || (DriverBinding == NULL)) {
return;
}
@@ -352,6 +355,7 @@ AddSortedDriverBindingProtocol ( if (*NumberOfSortedDriverBindingProtocols < DriverBindingHandleCount) {
SortedDriverBindingProtocols[*NumberOfSortedDriverBindingProtocols] = DriverBinding;
}
+
*NumberOfSortedDriverBindingProtocols = *NumberOfSortedDriverBindingProtocols + 1;
//
@@ -364,7 +368,6 @@ AddSortedDriverBindingProtocol ( }
}
-
/**
Connects a controller to a driver.
@@ -416,12 +419,12 @@ CoreConnectSingleController ( //
// Initialize local variables
//
- DriverBindingHandleCount = 0;
- DriverBindingHandleBuffer = NULL;
- NumberOfSortedDriverBindingProtocols = 0;
- SortedDriverBindingProtocols = NULL;
- PlatformDriverOverride = NULL;
- NewDriverBindingHandleBuffer = NULL;
+ DriverBindingHandleCount = 0;
+ DriverBindingHandleBuffer = NULL;
+ NumberOfSortedDriverBindingProtocols = 0;
+ SortedDriverBindingProtocols = NULL;
+ PlatformDriverOverride = NULL;
+ NewDriverBindingHandleBuffer = NULL;
//
// Get list of all Driver Binding Protocol Instances
@@ -468,7 +471,7 @@ CoreConnectSingleController ( Status = CoreLocateProtocol (
&gEfiPlatformDriverOverrideProtocolGuid,
NULL,
- (VOID **) &PlatformDriverOverride
+ (VOID **)&PlatformDriverOverride
);
if (!EFI_ERROR (Status) && (PlatformDriverOverride != NULL)) {
DriverImageHandle = NULL;
@@ -501,7 +504,7 @@ CoreConnectSingleController ( Status = CoreHandleProtocol (
DriverBindingHandleBuffer[Index],
&gEfiDriverFamilyOverrideProtocolGuid,
- (VOID **) &DriverFamilyOverride
+ (VOID **)&DriverFamilyOverride
);
if (!EFI_ERROR (Status) && (DriverFamilyOverride != NULL)) {
DriverFamilyOverrideVersion = DriverFamilyOverride->GetVersion (DriverFamilyOverride);
@@ -532,7 +535,7 @@ CoreConnectSingleController ( Status = CoreHandleProtocol (
ControllerHandle,
&gEfiBusSpecificDriverOverrideProtocolGuid,
- (VOID **) &BusSpecificDriverOverride
+ (VOID **)&BusSpecificDriverOverride
);
if (!EFI_ERROR (Status) && (BusSpecificDriverOverride != NULL)) {
DriverImageHandle = NULL;
@@ -608,9 +611,10 @@ CoreConnectSingleController ( HighestIndex = Index;
}
}
+
if (SortIndex != HighestIndex) {
- DriverBinding = SortedDriverBindingProtocols[SortIndex];
- SortedDriverBindingProtocols[SortIndex] = SortedDriverBindingProtocols[HighestIndex];
+ DriverBinding = SortedDriverBindingProtocols[SortIndex];
+ SortedDriverBindingProtocols[SortIndex] = SortedDriverBindingProtocols[HighestIndex];
SortedDriverBindingProtocols[HighestIndex] = DriverBinding;
}
}
@@ -620,19 +624,18 @@ CoreConnectSingleController ( //
OneStarted = FALSE;
do {
-
//
// Loop through the sorted Driver Binding Protocol Instances in order, and see if
// any of the Driver Binding Protocols support the controller specified by
// ControllerHandle.
//
DriverBinding = NULL;
- DriverFound = FALSE;
+ DriverFound = FALSE;
for (Index = 0; (Index < NumberOfSortedDriverBindingProtocols) && !DriverFound; Index++) {
if (SortedDriverBindingProtocols[Index] != NULL) {
DriverBinding = SortedDriverBindingProtocols[Index];
PERF_DRIVER_BINDING_SUPPORT_BEGIN (DriverBinding->DriverBindingHandle, ControllerHandle);
- Status = DriverBinding->Supported(
+ Status = DriverBinding->Supported (
DriverBinding,
ControllerHandle,
RemainingDevicePath
@@ -640,7 +643,7 @@ CoreConnectSingleController ( PERF_DRIVER_BINDING_SUPPORT_END (DriverBinding->DriverBindingHandle, ControllerHandle);
if (!EFI_ERROR (Status)) {
SortedDriverBindingProtocols[Index] = NULL;
- DriverFound = TRUE;
+ DriverFound = TRUE;
//
// A driver was found that supports ControllerHandle, so attempt to start the driver
@@ -692,8 +695,6 @@ CoreConnectSingleController ( return EFI_NOT_FOUND;
}
-
-
/**
Disonnects a controller from a driver
@@ -734,24 +735,24 @@ CoreDisconnectController ( IN EFI_HANDLE ChildHandle OPTIONAL
)
{
- EFI_STATUS Status;
- IHANDLE *Handle;
- EFI_HANDLE *DriverImageHandleBuffer;
- EFI_HANDLE *ChildBuffer;
- UINTN Index;
- UINTN HandleIndex;
- UINTN DriverImageHandleCount;
- UINTN ChildrenToStop;
- UINTN ChildBufferCount;
- UINTN StopCount;
- BOOLEAN Duplicate;
- BOOLEAN ChildHandleValid;
- BOOLEAN DriverImageHandleValid;
- LIST_ENTRY *Link;
- LIST_ENTRY *ProtLink;
- OPEN_PROTOCOL_DATA *OpenData;
- PROTOCOL_INTERFACE *Prot;
- EFI_DRIVER_BINDING_PROTOCOL *DriverBinding;
+ EFI_STATUS Status;
+ IHANDLE *Handle;
+ EFI_HANDLE *DriverImageHandleBuffer;
+ EFI_HANDLE *ChildBuffer;
+ UINTN Index;
+ UINTN HandleIndex;
+ UINTN DriverImageHandleCount;
+ UINTN ChildrenToStop;
+ UINTN ChildBufferCount;
+ UINTN StopCount;
+ BOOLEAN Duplicate;
+ BOOLEAN ChildHandleValid;
+ BOOLEAN DriverImageHandleValid;
+ LIST_ENTRY *Link;
+ LIST_ENTRY *ProtLink;
+ OPEN_PROTOCOL_DATA *OpenData;
+ PROTOCOL_INTERFACE *Prot;
+ EFI_DRIVER_BINDING_PROTOCOL *DriverBinding;
//
// Make sure ControllerHandle is valid
@@ -793,16 +794,18 @@ CoreDisconnectController ( CoreAcquireProtocolLock ();
for (Link = Handle->Protocols.ForwardLink; Link != &Handle->Protocols; Link = Link->ForwardLink) {
- Prot = CR(Link, PROTOCOL_INTERFACE, Link, PROTOCOL_INTERFACE_SIGNATURE);
+ Prot = CR (Link, PROTOCOL_INTERFACE, Link, PROTOCOL_INTERFACE_SIGNATURE);
for (ProtLink = Prot->OpenList.ForwardLink;
ProtLink != &Prot->OpenList;
- ProtLink = ProtLink->ForwardLink) {
+ ProtLink = ProtLink->ForwardLink)
+ {
OpenData = CR (ProtLink, OPEN_PROTOCOL_DATA, Link, OPEN_PROTOCOL_DATA_SIGNATURE);
if ((OpenData->Attributes & EFI_OPEN_PROTOCOL_BY_DRIVER) != 0) {
DriverImageHandleCount++;
}
}
}
+
CoreReleaseProtocolLock ();
//
@@ -823,19 +826,21 @@ CoreDisconnectController ( CoreAcquireProtocolLock ();
for (Link = Handle->Protocols.ForwardLink; Link != &Handle->Protocols; Link = Link->ForwardLink) {
- Prot = CR(Link, PROTOCOL_INTERFACE, Link, PROTOCOL_INTERFACE_SIGNATURE);
+ Prot = CR (Link, PROTOCOL_INTERFACE, Link, PROTOCOL_INTERFACE_SIGNATURE);
for (ProtLink = Prot->OpenList.ForwardLink;
ProtLink != &Prot->OpenList;
- ProtLink = ProtLink->ForwardLink) {
+ ProtLink = ProtLink->ForwardLink)
+ {
OpenData = CR (ProtLink, OPEN_PROTOCOL_DATA, Link, OPEN_PROTOCOL_DATA_SIGNATURE);
if ((OpenData->Attributes & EFI_OPEN_PROTOCOL_BY_DRIVER) != 0) {
Duplicate = FALSE;
- for (Index = 0; Index< DriverImageHandleCount; Index++) {
+ for (Index = 0; Index < DriverImageHandleCount; Index++) {
if (DriverImageHandleBuffer[Index] == OpenData->AgentHandle) {
Duplicate = TRUE;
break;
}
}
+
if (!Duplicate) {
DriverImageHandleBuffer[DriverImageHandleCount] = OpenData->AgentHandle;
DriverImageHandleCount++;
@@ -843,12 +848,12 @@ CoreDisconnectController ( }
}
}
+
CoreReleaseProtocolLock ();
}
StopCount = 0;
for (HandleIndex = 0; HandleIndex < DriverImageHandleCount; HandleIndex++) {
-
if (DriverImageHandleBuffer != NULL) {
DriverImageHandle = DriverImageHandleBuffer[HandleIndex];
}
@@ -861,7 +866,7 @@ CoreDisconnectController ( &gEfiDriverBindingProtocolGuid,
(VOID **)&DriverBinding
);
- if (EFI_ERROR (Status) || DriverBinding == NULL) {
+ if (EFI_ERROR (Status) || (DriverBinding == NULL)) {
Status = EFI_INVALID_PARAMETER;
goto Done;
}
@@ -870,30 +875,33 @@ CoreDisconnectController ( // Look at each protocol interface for a match
//
DriverImageHandleValid = FALSE;
- ChildBufferCount = 0;
+ ChildBufferCount = 0;
CoreAcquireProtocolLock ();
for (Link = Handle->Protocols.ForwardLink; Link != &Handle->Protocols; Link = Link->ForwardLink) {
- Prot = CR(Link, PROTOCOL_INTERFACE, Link, PROTOCOL_INTERFACE_SIGNATURE);
+ Prot = CR (Link, PROTOCOL_INTERFACE, Link, PROTOCOL_INTERFACE_SIGNATURE);
for (ProtLink = Prot->OpenList.ForwardLink;
ProtLink != &Prot->OpenList;
- ProtLink = ProtLink->ForwardLink) {
+ ProtLink = ProtLink->ForwardLink)
+ {
OpenData = CR (ProtLink, OPEN_PROTOCOL_DATA, Link, OPEN_PROTOCOL_DATA_SIGNATURE);
if (OpenData->AgentHandle == DriverImageHandle) {
if ((OpenData->Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) != 0) {
ChildBufferCount++;
}
+
if ((OpenData->Attributes & EFI_OPEN_PROTOCOL_BY_DRIVER) != 0) {
DriverImageHandleValid = TRUE;
}
}
}
}
+
CoreReleaseProtocolLock ();
if (DriverImageHandleValid) {
ChildHandleValid = FALSE;
- ChildBuffer = NULL;
+ ChildBuffer = NULL;
if (ChildBufferCount != 0) {
ChildBuffer = AllocatePool (sizeof (EFI_HANDLE) * ChildBufferCount);
if (ChildBuffer == NULL) {
@@ -905,13 +913,15 @@ CoreDisconnectController ( CoreAcquireProtocolLock ();
for (Link = Handle->Protocols.ForwardLink; Link != &Handle->Protocols; Link = Link->ForwardLink) {
- Prot = CR(Link, PROTOCOL_INTERFACE, Link, PROTOCOL_INTERFACE_SIGNATURE);
+ Prot = CR (Link, PROTOCOL_INTERFACE, Link, PROTOCOL_INTERFACE_SIGNATURE);
for (ProtLink = Prot->OpenList.ForwardLink;
ProtLink != &Prot->OpenList;
- ProtLink = ProtLink->ForwardLink) {
+ ProtLink = ProtLink->ForwardLink)
+ {
OpenData = CR (ProtLink, OPEN_PROTOCOL_DATA, Link, OPEN_PROTOCOL_DATA_SIGNATURE);
if ((OpenData->AgentHandle == DriverImageHandle) &&
- ((OpenData->Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) != 0)) {
+ ((OpenData->Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) != 0))
+ {
Duplicate = FALSE;
for (Index = 0; Index < ChildBufferCount; Index++) {
if (ChildBuffer[Index] == OpenData->ControllerHandle) {
@@ -919,34 +929,39 @@ CoreDisconnectController ( break;
}
}
+
if (!Duplicate) {
ChildBuffer[ChildBufferCount] = OpenData->ControllerHandle;
if (ChildHandle == ChildBuffer[ChildBufferCount]) {
ChildHandleValid = TRUE;
}
+
ChildBufferCount++;
}
}
}
}
+
CoreReleaseProtocolLock ();
}
- if (ChildHandle == NULL || ChildHandleValid) {
+ if ((ChildHandle == NULL) || ChildHandleValid) {
ChildrenToStop = 0;
- Status = EFI_SUCCESS;
+ Status = EFI_SUCCESS;
if (ChildBufferCount > 0) {
if (ChildHandle != NULL) {
ChildrenToStop = 1;
- Status = DriverBinding->Stop (DriverBinding, ControllerHandle, ChildrenToStop, &ChildHandle);
+ Status = DriverBinding->Stop (DriverBinding, ControllerHandle, ChildrenToStop, &ChildHandle);
} else {
ChildrenToStop = ChildBufferCount;
- Status = DriverBinding->Stop (DriverBinding, ControllerHandle, ChildrenToStop, ChildBuffer);
+ Status = DriverBinding->Stop (DriverBinding, ControllerHandle, ChildrenToStop, ChildBuffer);
}
}
+
if (!EFI_ERROR (Status) && ((ChildHandle == NULL) || (ChildBufferCount == ChildrenToStop))) {
Status = DriverBinding->Stop (DriverBinding, ControllerHandle, 0, NULL);
}
+
if (!EFI_ERROR (Status)) {
StopCount++;
}
diff --git a/MdeModulePkg/Core/Dxe/Hand/Handle.c b/MdeModulePkg/Core/Dxe/Hand/Handle.c index 92979281b7..bd6c57843e 100644 --- a/MdeModulePkg/Core/Dxe/Hand/Handle.c +++ b/MdeModulePkg/Core/Dxe/Hand/Handle.c @@ -9,19 +9,16 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include "DxeMain.h"
#include "Handle.h"
-
//
// mProtocolDatabase - A list of all protocols in the system. (simple list for now)
// gHandleList - A list of all the handles in the system
// gProtocolDatabaseLock - Lock to protect the mProtocolDatabase
// gHandleDatabaseKey - The Key to show that the handle has been created/modified
//
-LIST_ENTRY mProtocolDatabase = INITIALIZE_LIST_HEAD_VARIABLE (mProtocolDatabase);
-LIST_ENTRY gHandleList = INITIALIZE_LIST_HEAD_VARIABLE (gHandleList);
-EFI_LOCK gProtocolDatabaseLock = EFI_INITIALIZE_LOCK_VARIABLE (TPL_NOTIFY);
-UINT64 gHandleDatabaseKey = 0;
-
-
+LIST_ENTRY mProtocolDatabase = INITIALIZE_LIST_HEAD_VARIABLE (mProtocolDatabase);
+LIST_ENTRY gHandleList = INITIALIZE_LIST_HEAD_VARIABLE (gHandleList);
+EFI_LOCK gProtocolDatabaseLock = EFI_INITIALIZE_LOCK_VARIABLE (TPL_NOTIFY);
+UINT64 gHandleDatabaseKey = 0;
/**
Acquire lock on gProtocolDatabaseLock.
@@ -35,8 +32,6 @@ CoreAcquireProtocolLock ( CoreAcquireLock (&gProtocolDatabaseLock);
}
-
-
/**
Release lock on gProtocolDatabaseLock.
@@ -49,8 +44,6 @@ CoreReleaseProtocolLock ( CoreReleaseLock (&gProtocolDatabaseLock);
}
-
-
/**
Check whether a handle is a valid EFI_HANDLE
The gProtocolDatabaseLock must be owned
@@ -63,21 +56,21 @@ CoreReleaseProtocolLock ( **/
EFI_STATUS
CoreValidateHandle (
- IN EFI_HANDLE UserHandle
+ IN EFI_HANDLE UserHandle
)
{
- IHANDLE *Handle;
- LIST_ENTRY *Link;
+ IHANDLE *Handle;
+ LIST_ENTRY *Link;
if (UserHandle == NULL) {
return EFI_INVALID_PARAMETER;
}
- ASSERT_LOCKED(&gProtocolDatabaseLock);
+ ASSERT_LOCKED (&gProtocolDatabaseLock);
for (Link = gHandleList.BackLink; Link != &gHandleList; Link = Link->BackLink) {
Handle = CR (Link, IHANDLE, AllHandles, EFI_HANDLE_SIGNATURE);
- if (Handle == (IHANDLE *) UserHandle) {
+ if (Handle == (IHANDLE *)UserHandle) {
return EFI_SUCCESS;
}
}
@@ -85,8 +78,6 @@ CoreValidateHandle ( return EFI_INVALID_PARAMETER;
}
-
-
/**
Finds the protocol entry for the requested protocol.
The gProtocolDatabaseLock must be owned
@@ -99,15 +90,15 @@ CoreValidateHandle ( **/
PROTOCOL_ENTRY *
CoreFindProtocolEntry (
- IN EFI_GUID *Protocol,
- IN BOOLEAN Create
+ IN EFI_GUID *Protocol,
+ IN BOOLEAN Create
)
{
- LIST_ENTRY *Link;
- PROTOCOL_ENTRY *Item;
- PROTOCOL_ENTRY *ProtEntry;
+ LIST_ENTRY *Link;
+ PROTOCOL_ENTRY *Item;
+ PROTOCOL_ENTRY *ProtEntry;
- ASSERT_LOCKED(&gProtocolDatabaseLock);
+ ASSERT_LOCKED (&gProtocolDatabaseLock);
//
// Search the database for the matching GUID
@@ -116,11 +107,10 @@ CoreFindProtocolEntry ( ProtEntry = NULL;
for (Link = mProtocolDatabase.ForwardLink;
Link != &mProtocolDatabase;
- Link = Link->ForwardLink) {
-
- Item = CR(Link, PROTOCOL_ENTRY, AllEntries, PROTOCOL_ENTRY_SIGNATURE);
+ Link = Link->ForwardLink)
+ {
+ Item = CR (Link, PROTOCOL_ENTRY, AllEntries, PROTOCOL_ENTRY_SIGNATURE);
if (CompareGuid (&Item->ProtocolID, Protocol)) {
-
//
// This is the protocol entry
//
@@ -135,7 +125,7 @@ CoreFindProtocolEntry ( // allocate a new entry
//
if ((ProtEntry == NULL) && Create) {
- ProtEntry = AllocatePool (sizeof(PROTOCOL_ENTRY));
+ ProtEntry = AllocatePool (sizeof (PROTOCOL_ENTRY));
if (ProtEntry != NULL) {
//
@@ -156,8 +146,6 @@ CoreFindProtocolEntry ( return ProtEntry;
}
-
-
/**
Finds the protocol instance for the requested handle and protocol.
Note: This function doesn't do parameters checking, it's caller's responsibility
@@ -172,16 +160,16 @@ CoreFindProtocolEntry ( **/
PROTOCOL_INTERFACE *
CoreFindProtocolInterface (
- IN IHANDLE *Handle,
- IN EFI_GUID *Protocol,
- IN VOID *Interface
+ IN IHANDLE *Handle,
+ IN EFI_GUID *Protocol,
+ IN VOID *Interface
)
{
PROTOCOL_INTERFACE *Prot;
PROTOCOL_ENTRY *ProtEntry;
LIST_ENTRY *Link;
- ASSERT_LOCKED(&gProtocolDatabaseLock);
+ ASSERT_LOCKED (&gProtocolDatabaseLock);
Prot = NULL;
//
@@ -190,17 +178,15 @@ CoreFindProtocolInterface ( ProtEntry = CoreFindProtocolEntry (Protocol, FALSE);
if (ProtEntry != NULL) {
-
//
// Look at each protocol interface for any matches
//
- for (Link = Handle->Protocols.ForwardLink; Link != &Handle->Protocols; Link=Link->ForwardLink) {
-
+ for (Link = Handle->Protocols.ForwardLink; Link != &Handle->Protocols; Link = Link->ForwardLink) {
//
// If this protocol interface matches, remove it
//
- Prot = CR(Link, PROTOCOL_INTERFACE, Link, PROTOCOL_INTERFACE_SIGNATURE);
- if (Prot->Interface == Interface && Prot->Protocol == ProtEntry) {
+ Prot = CR (Link, PROTOCOL_INTERFACE, Link, PROTOCOL_INTERFACE_SIGNATURE);
+ if ((Prot->Interface == Interface) && (Prot->Protocol == ProtEntry)) {
break;
}
@@ -211,7 +197,6 @@ CoreFindProtocolInterface ( return Prot;
}
-
/**
Removes an event from a register protocol notify list on a protocol.
@@ -224,31 +209,31 @@ CoreFindProtocolInterface ( **/
EFI_STATUS
CoreUnregisterProtocolNotifyEvent (
- IN EFI_EVENT Event
+ IN EFI_EVENT Event
)
{
- LIST_ENTRY *Link;
- PROTOCOL_ENTRY *ProtEntry;
- LIST_ENTRY *NotifyLink;
- PROTOCOL_NOTIFY *ProtNotify;
+ LIST_ENTRY *Link;
+ PROTOCOL_ENTRY *ProtEntry;
+ LIST_ENTRY *NotifyLink;
+ PROTOCOL_NOTIFY *ProtNotify;
CoreAcquireProtocolLock ();
for ( Link = mProtocolDatabase.ForwardLink;
Link != &mProtocolDatabase;
- Link = Link->ForwardLink) {
-
- ProtEntry = CR(Link, PROTOCOL_ENTRY, AllEntries, PROTOCOL_ENTRY_SIGNATURE);
+ Link = Link->ForwardLink)
+ {
+ ProtEntry = CR (Link, PROTOCOL_ENTRY, AllEntries, PROTOCOL_ENTRY_SIGNATURE);
for ( NotifyLink = ProtEntry->Notify.ForwardLink;
NotifyLink != &ProtEntry->Notify;
- NotifyLink = NotifyLink->ForwardLink) {
-
- ProtNotify = CR(NotifyLink, PROTOCOL_NOTIFY, Link, PROTOCOL_NOTIFY_SIGNATURE);
+ NotifyLink = NotifyLink->ForwardLink)
+ {
+ ProtNotify = CR (NotifyLink, PROTOCOL_NOTIFY, Link, PROTOCOL_NOTIFY_SIGNATURE);
if (ProtNotify->Event == Event) {
- RemoveEntryList(&ProtNotify->Link);
- CoreFreePool(ProtNotify);
+ RemoveEntryList (&ProtNotify->Link);
+ CoreFreePool (ProtNotify);
CoreReleaseProtocolLock ();
return EFI_SUCCESS;
}
@@ -259,8 +244,6 @@ CoreUnregisterProtocolNotifyEvent ( return EFI_NOT_FOUND;
}
-
-
/**
Removes all the events in the protocol database that match Event.
@@ -272,10 +255,10 @@ CoreUnregisterProtocolNotifyEvent ( **/
EFI_STATUS
CoreUnregisterProtocolNotify (
- IN EFI_EVENT Event
+ IN EFI_EVENT Event
)
{
- EFI_STATUS Status;
+ EFI_STATUS Status;
do {
Status = CoreUnregisterProtocolNotifyEvent (Event);
@@ -284,9 +267,6 @@ CoreUnregisterProtocolNotify ( return EFI_SUCCESS;
}
-
-
-
/**
Wrapper function to CoreInstallProtocolInterfaceNotify. This is the public API which
Calls the private one which contains a BOOLEAN parameter for notifications
@@ -304,22 +284,21 @@ CoreUnregisterProtocolNotify ( EFI_STATUS
EFIAPI
CoreInstallProtocolInterface (
- IN OUT EFI_HANDLE *UserHandle,
- IN EFI_GUID *Protocol,
- IN EFI_INTERFACE_TYPE InterfaceType,
- IN VOID *Interface
+ IN OUT EFI_HANDLE *UserHandle,
+ IN EFI_GUID *Protocol,
+ IN EFI_INTERFACE_TYPE InterfaceType,
+ IN VOID *Interface
)
{
return CoreInstallProtocolInterfaceNotify (
- UserHandle,
- Protocol,
- InterfaceType,
- Interface,
- TRUE
- );
+ UserHandle,
+ Protocol,
+ InterfaceType,
+ Interface,
+ TRUE
+ );
}
-
/**
Installs a protocol interface into the boot services environment.
@@ -339,11 +318,11 @@ CoreInstallProtocolInterface ( **/
EFI_STATUS
CoreInstallProtocolInterfaceNotify (
- IN OUT EFI_HANDLE *UserHandle,
- IN EFI_GUID *Protocol,
- IN EFI_INTERFACE_TYPE InterfaceType,
- IN VOID *Interface,
- IN BOOLEAN Notify
+ IN OUT EFI_HANDLE *UserHandle,
+ IN EFI_GUID *Protocol,
+ IN EFI_INTERFACE_TYPE InterfaceType,
+ IN VOID *Interface,
+ IN BOOLEAN Notify
)
{
PROTOCOL_INTERFACE *Prot;
@@ -356,7 +335,7 @@ CoreInstallProtocolInterfaceNotify ( // returns EFI_INVALID_PARAMETER if InterfaceType is invalid.
// Also added check for invalid UserHandle and Protocol pointers.
//
- if (UserHandle == NULL || Protocol == NULL) {
+ if ((UserHandle == NULL) || (Protocol == NULL)) {
return EFI_INVALID_PARAMETER;
}
@@ -367,10 +346,10 @@ CoreInstallProtocolInterfaceNotify ( //
// Print debug message
//
- DEBUG((DEBUG_INFO, "InstallProtocolInterface: %g %p\n", Protocol, Interface));
+ DEBUG ((DEBUG_INFO, "InstallProtocolInterface: %g %p\n", Protocol, Interface));
Status = EFI_OUT_OF_RESOURCES;
- Prot = NULL;
+ Prot = NULL;
Handle = NULL;
if (*UserHandle != NULL) {
@@ -396,7 +375,7 @@ CoreInstallProtocolInterfaceNotify ( //
// Allocate a new protocol interface structure
//
- Prot = AllocateZeroPool (sizeof(PROTOCOL_INTERFACE));
+ Prot = AllocateZeroPool (sizeof (PROTOCOL_INTERFACE));
if (Prot == NULL) {
Status = EFI_OUT_OF_RESOURCES;
goto Done;
@@ -407,7 +386,7 @@ CoreInstallProtocolInterfaceNotify ( //
Handle = (IHANDLE *)*UserHandle;
if (Handle == NULL) {
- Handle = AllocateZeroPool (sizeof(IHANDLE));
+ Handle = AllocateZeroPool (sizeof (IHANDLE));
if (Handle == NULL) {
Status = EFI_OUT_OF_RESOURCES;
goto Done;
@@ -433,7 +412,7 @@ CoreInstallProtocolInterfaceNotify ( } else {
Status = CoreValidateHandle (Handle);
if (EFI_ERROR (Status)) {
- DEBUG((DEBUG_ERROR, "InstallProtocolInterface: input handle at 0x%x is invalid\n", Handle));
+ DEBUG ((DEBUG_ERROR, "InstallProtocolInterface: input handle at 0x%x is invalid\n", Handle));
goto Done;
}
}
@@ -447,8 +426,8 @@ CoreInstallProtocolInterfaceNotify ( // Initialize the protocol interface structure
//
Prot->Signature = PROTOCOL_INTERFACE_SIGNATURE;
- Prot->Handle = Handle;
- Prot->Protocol = ProtEntry;
+ Prot->Handle = Handle;
+ Prot->Protocol = ProtEntry;
Prot->Interface = Interface;
//
@@ -475,6 +454,7 @@ CoreInstallProtocolInterfaceNotify ( if (Notify) {
CoreNotifyProtocolEntry (ProtEntry);
}
+
Status = EFI_SUCCESS;
Done:
@@ -494,15 +474,13 @@ Done: if (Prot != NULL) {
CoreFreePool (Prot);
}
- DEBUG((DEBUG_ERROR, "InstallProtocolInterface: %g %p failed with %r\n", Protocol, Interface, Status));
+
+ DEBUG ((DEBUG_ERROR, "InstallProtocolInterface: %g %p failed with %r\n", Protocol, Interface, Status));
}
return Status;
}
-
-
-
/**
Installs a list of protocol interface into the boot services environment.
This function calls InstallProtocolInterface() in a loop. If any error
@@ -528,7 +506,7 @@ Done: EFI_STATUS
EFIAPI
CoreInstallMultipleProtocolInterfaces (
- IN OUT EFI_HANDLE *Handle,
+ IN OUT EFI_HANDLE *Handle,
...
)
{
@@ -549,7 +527,7 @@ CoreInstallMultipleProtocolInterfaces ( //
// Syncronize with notifcations.
//
- OldTpl = CoreRaiseTpl (TPL_NOTIFY);
+ OldTpl = CoreRaiseTpl (TPL_NOTIFY);
OldHandle = *Handle;
//
@@ -573,8 +551,8 @@ CoreInstallMultipleProtocolInterfaces ( if (CompareGuid (Protocol, &gEfiDevicePathProtocolGuid)) {
DeviceHandle = NULL;
DevicePath = Interface;
- Status = CoreLocateDevicePath (&gEfiDevicePathProtocolGuid, &DevicePath, &DeviceHandle);
- if (!EFI_ERROR (Status) && (DeviceHandle != NULL) && IsDevicePathEnd(DevicePath)) {
+ Status = CoreLocateDevicePath (&gEfiDevicePathProtocolGuid, &DevicePath, &DeviceHandle);
+ if (!EFI_ERROR (Status) && (DeviceHandle != NULL) && IsDevicePathEnd (DevicePath)) {
Status = EFI_ALREADY_STARTED;
continue;
}
@@ -585,6 +563,7 @@ CoreInstallMultipleProtocolInterfaces ( //
Status = CoreInstallProtocolInterface (Handle, Protocol, EFI_NATIVE_INTERFACE, Interface);
}
+
VA_END (Args);
//
@@ -595,11 +574,12 @@ CoreInstallMultipleProtocolInterfaces ( // Reset the va_arg back to the first argument.
//
VA_START (Args, Handle);
- for (; Index > 1; Index--) {
- Protocol = VA_ARG (Args, EFI_GUID *);
+ for ( ; Index > 1; Index--) {
+ Protocol = VA_ARG (Args, EFI_GUID *);
Interface = VA_ARG (Args, VOID *);
CoreUninstallProtocolInterface (*Handle, Protocol, Interface);
}
+
VA_END (Args);
*Handle = OldHandle;
@@ -612,7 +592,6 @@ CoreInstallMultipleProtocolInterfaces ( return Status;
}
-
/**
Attempts to disconnect all drivers that are using the protocol interface being queried.
If failed, reconnect all drivers disconnected.
@@ -629,14 +608,14 @@ CoreInstallMultipleProtocolInterfaces ( **/
EFI_STATUS
CoreDisconnectControllersUsingProtocolInterface (
- IN EFI_HANDLE UserHandle,
- IN PROTOCOL_INTERFACE *Prot
+ IN EFI_HANDLE UserHandle,
+ IN PROTOCOL_INTERFACE *Prot
)
{
- EFI_STATUS Status;
- BOOLEAN ItemFound;
- LIST_ENTRY *Link;
- OPEN_PROTOCOL_DATA *OpenData;
+ EFI_STATUS Status;
+ BOOLEAN ItemFound;
+ LIST_ENTRY *Link;
+ OPEN_PROTOCOL_DATA *OpenData;
Status = EFI_SUCCESS;
@@ -654,6 +633,7 @@ CoreDisconnectControllersUsingProtocolInterface ( if (!EFI_ERROR (Status)) {
ItemFound = TRUE;
}
+
break;
}
}
@@ -666,7 +646,8 @@ CoreDisconnectControllersUsingProtocolInterface ( for (Link = Prot->OpenList.ForwardLink; Link != &Prot->OpenList;) {
OpenData = CR (Link, OPEN_PROTOCOL_DATA, Link, OPEN_PROTOCOL_DATA_SIGNATURE);
if ((OpenData->Attributes &
- (EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL | EFI_OPEN_PROTOCOL_GET_PROTOCOL | EFI_OPEN_PROTOCOL_TEST_PROTOCOL)) != 0) {
+ (EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL | EFI_OPEN_PROTOCOL_GET_PROTOCOL | EFI_OPEN_PROTOCOL_TEST_PROTOCOL)) != 0)
+ {
Link = RemoveEntryList (&OpenData->Link);
Prot->OpenListCount--;
CoreFreePool (OpenData);
@@ -689,8 +670,6 @@ CoreDisconnectControllersUsingProtocolInterface ( return Status;
}
-
-
/**
Uninstalls all instances of a protocol:interfacer from a handle.
If the last protocol interface is remove from the handle, the
@@ -707,14 +686,14 @@ CoreDisconnectControllersUsingProtocolInterface ( EFI_STATUS
EFIAPI
CoreUninstallProtocolInterface (
- IN EFI_HANDLE UserHandle,
- IN EFI_GUID *Protocol,
- IN VOID *Interface
+ IN EFI_HANDLE UserHandle,
+ IN EFI_GUID *Protocol,
+ IN VOID *Interface
)
{
- EFI_STATUS Status;
- IHANDLE *Handle;
- PROTOCOL_INTERFACE *Prot;
+ EFI_STATUS Status;
+ IHANDLE *Handle;
+ PROTOCOL_INTERFACE *Prot;
//
// Check that Protocol is valid
@@ -803,8 +782,6 @@ Done: return Status;
}
-
-
/**
Uninstalls a list of protocol interface in the boot services environment.
This function calls UninstallProtocolInterface() in a loop. This is
@@ -830,15 +807,15 @@ Done: EFI_STATUS
EFIAPI
CoreUninstallMultipleProtocolInterfaces (
- IN EFI_HANDLE Handle,
+ IN EFI_HANDLE Handle,
...
)
{
- EFI_STATUS Status;
- VA_LIST Args;
- EFI_GUID *Protocol;
- VOID *Interface;
- UINTN Index;
+ EFI_STATUS Status;
+ VA_LIST Args;
+ EFI_GUID *Protocol;
+ VOID *Interface;
+ UINTN Index;
VA_START (Args, Handle);
for (Index = 0, Status = EFI_SUCCESS; !EFI_ERROR (Status); Index++) {
@@ -857,6 +834,7 @@ CoreUninstallMultipleProtocolInterfaces ( //
Status = CoreUninstallProtocolInterface (Handle, Protocol, Interface);
}
+
VA_END (Args);
//
@@ -868,11 +846,12 @@ CoreUninstallMultipleProtocolInterfaces ( // Reset the va_arg back to the first argument.
//
VA_START (Args, Handle);
- for (; Index > 1; Index--) {
- Protocol = VA_ARG(Args, EFI_GUID *);
- Interface = VA_ARG(Args, VOID *);
+ for ( ; Index > 1; Index--) {
+ Protocol = VA_ARG (Args, EFI_GUID *);
+ Interface = VA_ARG (Args, VOID *);
CoreInstallProtocolInterface (&Handle, Protocol, EFI_NATIVE_INTERFACE, Interface);
}
+
VA_END (Args);
Status = EFI_INVALID_PARAMETER;
}
@@ -880,7 +859,6 @@ CoreUninstallMultipleProtocolInterfaces ( return Status;
}
-
/**
Locate a certain GUID protocol interface in a Handle's protocols.
@@ -892,8 +870,8 @@ CoreUninstallMultipleProtocolInterfaces ( **/
PROTOCOL_INTERFACE *
CoreGetProtocolInterface (
- IN EFI_HANDLE UserHandle,
- IN EFI_GUID *Protocol
+ IN EFI_HANDLE UserHandle,
+ IN EFI_GUID *Protocol
)
{
EFI_STATUS Status;
@@ -913,17 +891,16 @@ CoreGetProtocolInterface ( // Look at each protocol interface for a match
//
for (Link = Handle->Protocols.ForwardLink; Link != &Handle->Protocols; Link = Link->ForwardLink) {
- Prot = CR(Link, PROTOCOL_INTERFACE, Link, PROTOCOL_INTERFACE_SIGNATURE);
+ Prot = CR (Link, PROTOCOL_INTERFACE, Link, PROTOCOL_INTERFACE_SIGNATURE);
ProtEntry = Prot->Protocol;
if (CompareGuid (&ProtEntry->ProtocolID, Protocol)) {
return Prot;
}
}
+
return NULL;
}
-
-
/**
Queries a handle to determine if it supports a specified protocol.
@@ -942,23 +919,21 @@ CoreGetProtocolInterface ( EFI_STATUS
EFIAPI
CoreHandleProtocol (
- IN EFI_HANDLE UserHandle,
- IN EFI_GUID *Protocol,
- OUT VOID **Interface
+ IN EFI_HANDLE UserHandle,
+ IN EFI_GUID *Protocol,
+ OUT VOID **Interface
)
{
return CoreOpenProtocol (
- UserHandle,
- Protocol,
- Interface,
- gDxeCoreImageHandle,
- NULL,
- EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL
- );
+ UserHandle,
+ Protocol,
+ Interface,
+ gDxeCoreImageHandle,
+ NULL,
+ EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL
+ );
}
-
-
/**
Locates the installed protocol handler for the handle, and
invokes it to obtain the protocol interface. Usage information
@@ -982,12 +957,12 @@ CoreHandleProtocol ( EFI_STATUS
EFIAPI
CoreOpenProtocol (
- IN EFI_HANDLE UserHandle,
- IN EFI_GUID *Protocol,
- OUT VOID **Interface OPTIONAL,
- IN EFI_HANDLE ImageHandle,
- IN EFI_HANDLE ControllerHandle,
- IN UINT32 Attributes
+ IN EFI_HANDLE UserHandle,
+ IN EFI_GUID *Protocol,
+ OUT VOID **Interface OPTIONAL,
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_HANDLE ControllerHandle,
+ IN UINT32 Attributes
)
{
EFI_STATUS Status;
@@ -1030,47 +1005,52 @@ CoreOpenProtocol ( // Check for invalid Attributes
//
switch (Attributes) {
- case EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER :
- Status = CoreValidateHandle (ImageHandle);
- if (EFI_ERROR (Status)) {
- goto Done;
- }
- Status = CoreValidateHandle (ControllerHandle);
- if (EFI_ERROR (Status)) {
- goto Done;
- }
- if (UserHandle == ControllerHandle) {
+ case EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER:
+ Status = CoreValidateHandle (ImageHandle);
+ if (EFI_ERROR (Status)) {
+ goto Done;
+ }
+
+ Status = CoreValidateHandle (ControllerHandle);
+ if (EFI_ERROR (Status)) {
+ goto Done;
+ }
+
+ if (UserHandle == ControllerHandle) {
+ Status = EFI_INVALID_PARAMETER;
+ goto Done;
+ }
+
+ break;
+ case EFI_OPEN_PROTOCOL_BY_DRIVER:
+ case EFI_OPEN_PROTOCOL_BY_DRIVER | EFI_OPEN_PROTOCOL_EXCLUSIVE:
+ Status = CoreValidateHandle (ImageHandle);
+ if (EFI_ERROR (Status)) {
+ goto Done;
+ }
+
+ Status = CoreValidateHandle (ControllerHandle);
+ if (EFI_ERROR (Status)) {
+ goto Done;
+ }
+
+ break;
+ case EFI_OPEN_PROTOCOL_EXCLUSIVE:
+ Status = CoreValidateHandle (ImageHandle);
+ if (EFI_ERROR (Status)) {
+ goto Done;
+ }
+
+ break;
+ case EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL:
+ case EFI_OPEN_PROTOCOL_GET_PROTOCOL:
+ case EFI_OPEN_PROTOCOL_TEST_PROTOCOL:
+ break;
+ default:
Status = EFI_INVALID_PARAMETER;
goto Done;
- }
- break;
- case EFI_OPEN_PROTOCOL_BY_DRIVER :
- case EFI_OPEN_PROTOCOL_BY_DRIVER | EFI_OPEN_PROTOCOL_EXCLUSIVE :
- Status = CoreValidateHandle (ImageHandle);
- if (EFI_ERROR (Status)) {
- goto Done;
- }
- Status = CoreValidateHandle (ControllerHandle);
- if (EFI_ERROR (Status)) {
- goto Done;
- }
- break;
- case EFI_OPEN_PROTOCOL_EXCLUSIVE :
- Status = CoreValidateHandle (ImageHandle);
- if (EFI_ERROR (Status)) {
- goto Done;
- }
- break;
- case EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL :
- case EFI_OPEN_PROTOCOL_GET_PROTOCOL :
- case EFI_OPEN_PROTOCOL_TEST_PROTOCOL :
- break;
- default:
- Status = EFI_INVALID_PARAMETER;
- goto Done;
}
-
//
// Look at each protocol interface for a match
//
@@ -1082,10 +1062,10 @@ CoreOpenProtocol ( Status = EFI_SUCCESS;
- ByDriver = FALSE;
- Exclusive = FALSE;
+ ByDriver = FALSE;
+ Exclusive = FALSE;
for ( Link = Prot->OpenList.ForwardLink; Link != &Prot->OpenList; Link = Link->ForwardLink) {
- OpenData = CR (Link, OPEN_PROTOCOL_DATA, Link, OPEN_PROTOCOL_DATA_SIGNATURE);
+ OpenData = CR (Link, OPEN_PROTOCOL_DATA, Link, OPEN_PROTOCOL_DATA_SIGNATURE);
ExactMatch = (BOOLEAN)((OpenData->AgentHandle == ImageHandle) &&
(OpenData->Attributes == Attributes) &&
(OpenData->ControllerHandle == ControllerHandle));
@@ -1096,6 +1076,7 @@ CoreOpenProtocol ( goto Done;
}
}
+
if ((OpenData->Attributes & EFI_OPEN_PROTOCOL_EXCLUSIVE) != 0) {
Exclusive = TRUE;
} else if (ExactMatch) {
@@ -1113,62 +1094,66 @@ CoreOpenProtocol ( //
switch (Attributes) {
- case EFI_OPEN_PROTOCOL_BY_DRIVER :
- if (Exclusive || ByDriver) {
- Status = EFI_ACCESS_DENIED;
- goto Done;
- }
- break;
- case EFI_OPEN_PROTOCOL_BY_DRIVER | EFI_OPEN_PROTOCOL_EXCLUSIVE :
- case EFI_OPEN_PROTOCOL_EXCLUSIVE :
- if (Exclusive) {
- Status = EFI_ACCESS_DENIED;
- goto Done;
- }
- if (ByDriver) {
- do {
- Disconnect = FALSE;
- for (Link = Prot->OpenList.ForwardLink; Link != &Prot->OpenList; Link = Link->ForwardLink) {
- OpenData = CR (Link, OPEN_PROTOCOL_DATA, Link, OPEN_PROTOCOL_DATA_SIGNATURE);
- if ((OpenData->Attributes & EFI_OPEN_PROTOCOL_BY_DRIVER) != 0) {
- Disconnect = TRUE;
- CoreReleaseProtocolLock ();
- Status = CoreDisconnectController (UserHandle, OpenData->AgentHandle, NULL);
- CoreAcquireProtocolLock ();
- if (EFI_ERROR (Status)) {
- Status = EFI_ACCESS_DENIED;
- goto Done;
- } else {
- break;
+ case EFI_OPEN_PROTOCOL_BY_DRIVER:
+ if (Exclusive || ByDriver) {
+ Status = EFI_ACCESS_DENIED;
+ goto Done;
+ }
+
+ break;
+ case EFI_OPEN_PROTOCOL_BY_DRIVER | EFI_OPEN_PROTOCOL_EXCLUSIVE:
+ case EFI_OPEN_PROTOCOL_EXCLUSIVE:
+ if (Exclusive) {
+ Status = EFI_ACCESS_DENIED;
+ goto Done;
+ }
+
+ if (ByDriver) {
+ do {
+ Disconnect = FALSE;
+ for (Link = Prot->OpenList.ForwardLink; Link != &Prot->OpenList; Link = Link->ForwardLink) {
+ OpenData = CR (Link, OPEN_PROTOCOL_DATA, Link, OPEN_PROTOCOL_DATA_SIGNATURE);
+ if ((OpenData->Attributes & EFI_OPEN_PROTOCOL_BY_DRIVER) != 0) {
+ Disconnect = TRUE;
+ CoreReleaseProtocolLock ();
+ Status = CoreDisconnectController (UserHandle, OpenData->AgentHandle, NULL);
+ CoreAcquireProtocolLock ();
+ if (EFI_ERROR (Status)) {
+ Status = EFI_ACCESS_DENIED;
+ goto Done;
+ } else {
+ break;
+ }
}
}
- }
- } while (Disconnect);
- }
- break;
- case EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER :
- case EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL :
- case EFI_OPEN_PROTOCOL_GET_PROTOCOL :
- case EFI_OPEN_PROTOCOL_TEST_PROTOCOL :
- break;
+ } while (Disconnect);
+ }
+
+ break;
+ case EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER:
+ case EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL:
+ case EFI_OPEN_PROTOCOL_GET_PROTOCOL:
+ case EFI_OPEN_PROTOCOL_TEST_PROTOCOL:
+ break;
}
if (ImageHandle == NULL) {
Status = EFI_SUCCESS;
goto Done;
}
+
//
// Create new entry
//
- OpenData = AllocatePool (sizeof(OPEN_PROTOCOL_DATA));
+ OpenData = AllocatePool (sizeof (OPEN_PROTOCOL_DATA));
if (OpenData == NULL) {
Status = EFI_OUT_OF_RESOURCES;
} else {
- OpenData->Signature = OPEN_PROTOCOL_DATA_SIGNATURE;
- OpenData->AgentHandle = ImageHandle;
- OpenData->ControllerHandle = ControllerHandle;
- OpenData->Attributes = Attributes;
- OpenData->OpenCount = 1;
+ OpenData->Signature = OPEN_PROTOCOL_DATA_SIGNATURE;
+ OpenData->AgentHandle = ImageHandle;
+ OpenData->ControllerHandle = ControllerHandle;
+ OpenData->Attributes = Attributes;
+ OpenData->OpenCount = 1;
InsertTailList (&Prot->OpenList, &OpenData->Link);
Prot->OpenListCount++;
Status = EFI_SUCCESS;
@@ -1181,7 +1166,7 @@ Done: // Keep Interface unmodified in case of any Error
// except EFI_ALREADY_STARTED and EFI_UNSUPPORTED.
//
- if (!EFI_ERROR (Status) || Status == EFI_ALREADY_STARTED) {
+ if (!EFI_ERROR (Status) || (Status == EFI_ALREADY_STARTED)) {
//
// According to above logic, if 'Prot' is NULL, then the 'Status' must be
// EFI_UNSUPPORTED. Here the 'Status' is not EFI_UNSUPPORTED, so 'Prot'
@@ -1211,8 +1196,6 @@ Done: return Status;
}
-
-
/**
Closes a protocol on a handle that was opened using OpenProtocol().
@@ -1241,10 +1224,10 @@ Done: EFI_STATUS
EFIAPI
CoreCloseProtocol (
- IN EFI_HANDLE UserHandle,
- IN EFI_GUID *Protocol,
- IN EFI_HANDLE AgentHandle,
- IN EFI_HANDLE ControllerHandle
+ IN EFI_HANDLE UserHandle,
+ IN EFI_GUID *Protocol,
+ IN EFI_HANDLE AgentHandle,
+ IN EFI_HANDLE ControllerHandle
)
{
EFI_STATUS Status;
@@ -1264,16 +1247,19 @@ CoreCloseProtocol ( if (EFI_ERROR (Status)) {
goto Done;
}
+
Status = CoreValidateHandle (AgentHandle);
if (EFI_ERROR (Status)) {
goto Done;
}
+
if (ControllerHandle != NULL) {
Status = CoreValidateHandle (ControllerHandle);
if (EFI_ERROR (Status)) {
goto Done;
}
}
+
if (Protocol == NULL) {
Status = EFI_INVALID_PARAMETER;
goto Done;
@@ -1282,7 +1268,7 @@ CoreCloseProtocol ( //
// Look at each protocol interface for a match
//
- Status = EFI_NOT_FOUND;
+ Status = EFI_NOT_FOUND;
ProtocolInterface = CoreGetProtocolInterface (UserHandle, Protocol);
if (ProtocolInterface == NULL) {
goto Done;
@@ -1294,12 +1280,12 @@ CoreCloseProtocol ( Link = ProtocolInterface->OpenList.ForwardLink;
while (Link != &ProtocolInterface->OpenList) {
OpenData = CR (Link, OPEN_PROTOCOL_DATA, Link, OPEN_PROTOCOL_DATA_SIGNATURE);
- Link = Link->ForwardLink;
+ Link = Link->ForwardLink;
if ((OpenData->AgentHandle == AgentHandle) && (OpenData->ControllerHandle == ControllerHandle)) {
- RemoveEntryList (&OpenData->Link);
- ProtocolInterface->OpenListCount--;
- CoreFreePool (OpenData);
- Status = EFI_SUCCESS;
+ RemoveEntryList (&OpenData->Link);
+ ProtocolInterface->OpenListCount--;
+ CoreFreePool (OpenData);
+ Status = EFI_SUCCESS;
}
}
@@ -1311,9 +1297,6 @@ Done: return Status;
}
-
-
-
/**
Return information about Opened protocols in the system
@@ -1332,22 +1315,22 @@ Done: EFI_STATUS
EFIAPI
CoreOpenProtocolInformation (
- IN EFI_HANDLE UserHandle,
- IN EFI_GUID *Protocol,
- OUT EFI_OPEN_PROTOCOL_INFORMATION_ENTRY **EntryBuffer,
- OUT UINTN *EntryCount
+ IN EFI_HANDLE UserHandle,
+ IN EFI_GUID *Protocol,
+ OUT EFI_OPEN_PROTOCOL_INFORMATION_ENTRY **EntryBuffer,
+ OUT UINTN *EntryCount
)
{
- EFI_STATUS Status;
- PROTOCOL_INTERFACE *ProtocolInterface;
- LIST_ENTRY *Link;
- OPEN_PROTOCOL_DATA *OpenData;
- EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *Buffer;
- UINTN Count;
- UINTN Size;
+ EFI_STATUS Status;
+ PROTOCOL_INTERFACE *ProtocolInterface;
+ LIST_ENTRY *Link;
+ OPEN_PROTOCOL_DATA *OpenData;
+ EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *Buffer;
+ UINTN Count;
+ UINTN Size;
*EntryBuffer = NULL;
- *EntryCount = 0;
+ *EntryCount = 0;
//
// Lock the protocol database
@@ -1357,7 +1340,7 @@ CoreOpenProtocolInformation ( //
// Look at each protocol interface for a match
//
- Status = EFI_NOT_FOUND;
+ Status = EFI_NOT_FOUND;
ProtocolInterface = CoreGetProtocolInterface (UserHandle, Protocol);
if (ProtocolInterface == NULL) {
goto Done;
@@ -1367,17 +1350,18 @@ CoreOpenProtocolInformation ( // Count the number of Open Entries
//
for ( Link = ProtocolInterface->OpenList.ForwardLink, Count = 0;
- (Link != &ProtocolInterface->OpenList) ;
- Link = Link->ForwardLink ) {
+ (Link != &ProtocolInterface->OpenList);
+ Link = Link->ForwardLink )
+ {
Count++;
}
ASSERT (Count == ProtocolInterface->OpenListCount);
if (Count == 0) {
- Size = sizeof(EFI_OPEN_PROTOCOL_INFORMATION_ENTRY);
+ Size = sizeof (EFI_OPEN_PROTOCOL_INFORMATION_ENTRY);
} else {
- Size = Count * sizeof(EFI_OPEN_PROTOCOL_INFORMATION_ENTRY);
+ Size = Count * sizeof (EFI_OPEN_PROTOCOL_INFORMATION_ENTRY);
}
Buffer = AllocatePool (Size);
@@ -1389,7 +1373,8 @@ CoreOpenProtocolInformation ( Status = EFI_SUCCESS;
for ( Link = ProtocolInterface->OpenList.ForwardLink, Count = 0;
(Link != &ProtocolInterface->OpenList);
- Link = Link->ForwardLink, Count++ ) {
+ Link = Link->ForwardLink, Count++ )
+ {
OpenData = CR (Link, OPEN_PROTOCOL_DATA, Link, OPEN_PROTOCOL_DATA_SIGNATURE);
Buffer[Count].AgentHandle = OpenData->AgentHandle;
@@ -1399,7 +1384,7 @@ CoreOpenProtocolInformation ( }
*EntryBuffer = Buffer;
- *EntryCount = Count;
+ *EntryCount = Count;
Done:
//
@@ -1409,9 +1394,6 @@ Done: return Status;
}
-
-
-
/**
Retrieves the list of protocol interface GUIDs that are installed on a handle in a buffer allocated
from pool.
@@ -1438,17 +1420,17 @@ Done: EFI_STATUS
EFIAPI
CoreProtocolsPerHandle (
- IN EFI_HANDLE UserHandle,
- OUT EFI_GUID ***ProtocolBuffer,
- OUT UINTN *ProtocolBufferCount
+ IN EFI_HANDLE UserHandle,
+ OUT EFI_GUID ***ProtocolBuffer,
+ OUT UINTN *ProtocolBufferCount
)
{
- EFI_STATUS Status;
- IHANDLE *Handle;
- PROTOCOL_INTERFACE *Prot;
- LIST_ENTRY *Link;
- UINTN ProtocolCount;
- EFI_GUID **Buffer;
+ EFI_STATUS Status;
+ IHANDLE *Handle;
+ PROTOCOL_INTERFACE *Prot;
+ LIST_ENTRY *Link;
+ UINTN ProtocolCount;
+ EFI_GUID **Buffer;
if (ProtocolBuffer == NULL) {
return EFI_INVALID_PARAMETER;
@@ -1489,15 +1471,17 @@ CoreProtocolsPerHandle ( goto Done;
}
- *ProtocolBuffer = Buffer;
+ *ProtocolBuffer = Buffer;
*ProtocolBufferCount = ProtocolCount;
for ( Link = Handle->Protocols.ForwardLink, ProtocolCount = 0;
Link != &Handle->Protocols;
- Link = Link->ForwardLink, ProtocolCount++) {
- Prot = CR(Link, PROTOCOL_INTERFACE, Link, PROTOCOL_INTERFACE_SIGNATURE);
+ Link = Link->ForwardLink, ProtocolCount++)
+ {
+ Prot = CR (Link, PROTOCOL_INTERFACE, Link, PROTOCOL_INTERFACE_SIGNATURE);
Buffer[ProtocolCount] = &(Prot->Protocol->ProtocolID);
}
+
Status = EFI_SUCCESS;
Done:
@@ -1505,8 +1489,6 @@ Done: return Status;
}
-
-
/**
return handle database key.
@@ -1522,8 +1504,6 @@ CoreGetHandleDatabaseKey ( return gHandleDatabaseKey;
}
-
-
/**
Go connect any handles that were created or modified while a image executed.
@@ -1536,11 +1516,11 @@ CoreConnectHandlesByKey ( UINT64 Key
)
{
- UINTN Count;
- LIST_ENTRY *Link;
- EFI_HANDLE *HandleBuffer;
- IHANDLE *Handle;
- UINTN Index;
+ UINTN Count;
+ LIST_ENTRY *Link;
+ EFI_HANDLE *HandleBuffer;
+ IHANDLE *Handle;
+ UINTN Index;
//
// Lock the protocol database
@@ -1579,5 +1559,5 @@ CoreConnectHandlesByKey ( CoreConnectController (HandleBuffer[Index], NULL, NULL, TRUE);
}
- CoreFreePool(HandleBuffer);
+ CoreFreePool (HandleBuffer);
}
diff --git a/MdeModulePkg/Core/Dxe/Hand/Handle.h b/MdeModulePkg/Core/Dxe/Hand/Handle.h index 3f83e3af15..5c66e4da66 100644 --- a/MdeModulePkg/Core/Dxe/Hand/Handle.h +++ b/MdeModulePkg/Core/Dxe/Hand/Handle.h @@ -9,26 +9,25 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #ifndef _HAND_H_
#define _HAND_H_
-
-#define EFI_HANDLE_SIGNATURE SIGNATURE_32('h','n','d','l')
+#define EFI_HANDLE_SIGNATURE SIGNATURE_32('h','n','d','l')
///
/// IHANDLE - contains a list of protocol handles
///
typedef struct {
- UINTN Signature;
+ UINTN Signature;
/// All handles list of IHANDLE
- LIST_ENTRY AllHandles;
+ LIST_ENTRY AllHandles;
/// List of PROTOCOL_INTERFACE's for this handle
- LIST_ENTRY Protocols;
- UINTN LocateRequest;
+ LIST_ENTRY Protocols;
+ UINTN LocateRequest;
/// The Handle Database Key value when this handle was last created or modified
- UINT64 Key;
+ UINT64 Key;
} IHANDLE;
#define ASSERT_IS_HANDLE(a) ASSERT((a)->Signature == EFI_HANDLE_SIGNATURE)
-#define PROTOCOL_ENTRY_SIGNATURE SIGNATURE_32('p','r','t','e')
+#define PROTOCOL_ENTRY_SIGNATURE SIGNATURE_32('p','r','t','e')
///
/// PROTOCOL_ENTRY - each different protocol has 1 entry in the protocol
@@ -36,18 +35,17 @@ typedef struct { /// with a list of registered notifies.
///
typedef struct {
- UINTN Signature;
+ UINTN Signature;
/// Link Entry inserted to mProtocolDatabase
- LIST_ENTRY AllEntries;
+ LIST_ENTRY AllEntries;
/// ID of the protocol
- EFI_GUID ProtocolID;
+ EFI_GUID ProtocolID;
/// All protocol interfaces
- LIST_ENTRY Protocols;
+ LIST_ENTRY Protocols;
/// Registerd notification handlers
- LIST_ENTRY Notify;
+ LIST_ENTRY Notify;
} PROTOCOL_ENTRY;
-
#define PROTOCOL_INTERFACE_SIGNATURE SIGNATURE_32('p','i','f','c')
///
@@ -55,55 +53,51 @@ typedef struct { /// with a protocol interface structure
///
typedef struct {
- UINTN Signature;
+ UINTN Signature;
/// Link on IHANDLE.Protocols
- LIST_ENTRY Link;
+ LIST_ENTRY Link;
/// Back pointer
- IHANDLE *Handle;
+ IHANDLE *Handle;
/// Link on PROTOCOL_ENTRY.Protocols
- LIST_ENTRY ByProtocol;
+ LIST_ENTRY ByProtocol;
/// The protocol ID
- PROTOCOL_ENTRY *Protocol;
+ PROTOCOL_ENTRY *Protocol;
/// The interface value
- VOID *Interface;
+ VOID *Interface;
/// OPEN_PROTOCOL_DATA list
- LIST_ENTRY OpenList;
- UINTN OpenListCount;
-
+ LIST_ENTRY OpenList;
+ UINTN OpenListCount;
} PROTOCOL_INTERFACE;
#define OPEN_PROTOCOL_DATA_SIGNATURE SIGNATURE_32('p','o','d','l')
typedef struct {
- UINTN Signature;
- ///Link on PROTOCOL_INTERFACE.OpenList
- LIST_ENTRY Link;
-
- EFI_HANDLE AgentHandle;
- EFI_HANDLE ControllerHandle;
- UINT32 Attributes;
- UINT32 OpenCount;
+ UINTN Signature;
+ /// Link on PROTOCOL_INTERFACE.OpenList
+ LIST_ENTRY Link;
+
+ EFI_HANDLE AgentHandle;
+ EFI_HANDLE ControllerHandle;
+ UINT32 Attributes;
+ UINT32 OpenCount;
} OPEN_PROTOCOL_DATA;
-
-#define PROTOCOL_NOTIFY_SIGNATURE SIGNATURE_32('p','r','t','n')
+#define PROTOCOL_NOTIFY_SIGNATURE SIGNATURE_32('p','r','t','n')
///
/// PROTOCOL_NOTIFY - used for each register notification for a protocol
///
typedef struct {
- UINTN Signature;
- PROTOCOL_ENTRY *Protocol;
+ UINTN Signature;
+ PROTOCOL_ENTRY *Protocol;
/// All notifications for this protocol
- LIST_ENTRY Link;
+ LIST_ENTRY Link;
/// Event to notify
- EFI_EVENT Event;
+ EFI_EVENT Event;
/// Last position notified
- LIST_ENTRY *Position;
+ LIST_ENTRY *Position;
} PROTOCOL_NOTIFY;
-
-
/**
Finds the protocol entry for the requested protocol.
The gProtocolDatabaseLock must be owned
@@ -116,11 +110,10 @@ typedef struct { **/
PROTOCOL_ENTRY *
CoreFindProtocolEntry (
- IN EFI_GUID *Protocol,
- IN BOOLEAN Create
+ IN EFI_GUID *Protocol,
+ IN BOOLEAN Create
);
-
/**
Signal event for every protocol in protocol entry.
@@ -129,10 +122,9 @@ CoreFindProtocolEntry ( **/
VOID
CoreNotifyProtocolEntry (
- IN PROTOCOL_ENTRY *ProtEntry
+ IN PROTOCOL_ENTRY *ProtEntry
);
-
/**
Finds the protocol instance for the requested handle and protocol.
Note: This function doesn't do parameters checking, it's caller's responsibility
@@ -147,12 +139,11 @@ CoreNotifyProtocolEntry ( **/
PROTOCOL_INTERFACE *
CoreFindProtocolInterface (
- IN IHANDLE *Handle,
- IN EFI_GUID *Protocol,
- IN VOID *Interface
+ IN IHANDLE *Handle,
+ IN EFI_GUID *Protocol,
+ IN VOID *Interface
);
-
/**
Removes Protocol from the protocol list (but not the handle list).
@@ -165,12 +156,11 @@ CoreFindProtocolInterface ( **/
PROTOCOL_INTERFACE *
CoreRemoveInterfaceFromProtocol (
- IN IHANDLE *Handle,
- IN EFI_GUID *Protocol,
- IN VOID *Interface
+ IN IHANDLE *Handle,
+ IN EFI_GUID *Protocol,
+ IN VOID *Interface
);
-
/**
Connects a controller to a driver.
@@ -215,11 +205,10 @@ CoreConnectSingleController ( **/
EFI_STATUS
CoreDisconnectControllersUsingProtocolInterface (
- IN EFI_HANDLE UserHandle,
- IN PROTOCOL_INTERFACE *Prot
+ IN EFI_HANDLE UserHandle,
+ IN PROTOCOL_INTERFACE *Prot
);
-
/**
Acquire lock on gProtocolDatabaseLock.
@@ -229,7 +218,6 @@ CoreAcquireProtocolLock ( VOID
);
-
/**
Release lock on gProtocolDatabaseLock.
@@ -239,7 +227,6 @@ CoreReleaseProtocolLock ( VOID
);
-
/**
Check whether a handle is a valid EFI_HANDLE
The gProtocolDatabaseLock must be owned
@@ -252,14 +239,14 @@ CoreReleaseProtocolLock ( **/
EFI_STATUS
CoreValidateHandle (
- IN EFI_HANDLE UserHandle
+ IN EFI_HANDLE UserHandle
);
//
// Externs
//
-extern EFI_LOCK gProtocolDatabaseLock;
-extern LIST_ENTRY gHandleList;
-extern UINT64 gHandleDatabaseKey;
+extern EFI_LOCK gProtocolDatabaseLock;
+extern LIST_ENTRY gHandleList;
+extern UINT64 gHandleDatabaseKey;
#endif
diff --git a/MdeModulePkg/Core/Dxe/Hand/Locate.c b/MdeModulePkg/Core/Dxe/Hand/Locate.c index 4987c046c6..a29010a545 100644 --- a/MdeModulePkg/Core/Dxe/Hand/Locate.c +++ b/MdeModulePkg/Core/Dxe/Hand/Locate.c @@ -12,24 +12,24 @@ SPDX-License-Identifier: BSD-2-Clause-Patent //
// ProtocolRequest - Last LocateHandle request ID
//
-UINTN mEfiLocateHandleRequest = 0;
+UINTN mEfiLocateHandleRequest = 0;
//
// Internal prototypes
//
typedef struct {
- EFI_GUID *Protocol;
- VOID *SearchKey;
- LIST_ENTRY *Position;
- PROTOCOL_ENTRY *ProtEntry;
+ EFI_GUID *Protocol;
+ VOID *SearchKey;
+ LIST_ENTRY *Position;
+ PROTOCOL_ENTRY *ProtEntry;
} LOCATE_POSITION;
typedef
IHANDLE *
-(* CORE_GET_NEXT) (
- IN OUT LOCATE_POSITION *Position,
- OUT VOID **Interface
+(*CORE_GET_NEXT) (
+ IN OUT LOCATE_POSITION *Position,
+ OUT VOID **Interface
);
/**
@@ -45,8 +45,8 @@ IHANDLE * **/
IHANDLE *
CoreGetNextLocateAllHandles (
- IN OUT LOCATE_POSITION *Position,
- OUT VOID **Interface
+ IN OUT LOCATE_POSITION *Position,
+ OUT VOID **Interface
);
/**
@@ -63,8 +63,8 @@ CoreGetNextLocateAllHandles ( **/
IHANDLE *
CoreGetNextLocateByRegisterNotify (
- IN OUT LOCATE_POSITION *Position,
- OUT VOID **Interface
+ IN OUT LOCATE_POSITION *Position,
+ OUT VOID **Interface
);
/**
@@ -80,11 +80,10 @@ CoreGetNextLocateByRegisterNotify ( **/
IHANDLE *
CoreGetNextLocateByProtocol (
- IN OUT LOCATE_POSITION *Position,
- OUT VOID **Interface
+ IN OUT LOCATE_POSITION *Position,
+ OUT VOID **Interface
);
-
/**
Internal function for locating the requested handle(s) and returns them in Buffer.
The caller should already have acquired the ProtocolLock.
@@ -106,21 +105,21 @@ CoreGetNextLocateByProtocol ( **/
EFI_STATUS
InternalCoreLocateHandle (
- IN EFI_LOCATE_SEARCH_TYPE SearchType,
- IN EFI_GUID *Protocol OPTIONAL,
- IN VOID *SearchKey OPTIONAL,
- IN OUT UINTN *BufferSize,
- OUT EFI_HANDLE *Buffer
+ IN EFI_LOCATE_SEARCH_TYPE SearchType,
+ IN EFI_GUID *Protocol OPTIONAL,
+ IN VOID *SearchKey OPTIONAL,
+ IN OUT UINTN *BufferSize,
+ OUT EFI_HANDLE *Buffer
)
{
- EFI_STATUS Status;
- LOCATE_POSITION Position;
- PROTOCOL_NOTIFY *ProtNotify;
- CORE_GET_NEXT GetNext;
- UINTN ResultSize;
- IHANDLE *Handle;
- IHANDLE **ResultBuffer;
- VOID *Interface;
+ EFI_STATUS Status;
+ LOCATE_POSITION Position;
+ PROTOCOL_NOTIFY *ProtNotify;
+ CORE_GET_NEXT GetNext;
+ UINTN ResultSize;
+ IHANDLE *Handle;
+ IHANDLE **ResultBuffer;
+ VOID *Interface;
if (BufferSize == NULL) {
return EFI_INVALID_PARAMETER;
@@ -139,52 +138,55 @@ InternalCoreLocateHandle ( Position.SearchKey = SearchKey;
Position.Position = &gHandleList;
- ResultSize = 0;
- ResultBuffer = (IHANDLE **) Buffer;
- Status = EFI_SUCCESS;
+ ResultSize = 0;
+ ResultBuffer = (IHANDLE **)Buffer;
+ Status = EFI_SUCCESS;
//
// Get the search function based on type
//
switch (SearchType) {
- case AllHandles:
- GetNext = CoreGetNextLocateAllHandles;
- break;
-
- case ByRegisterNotify:
- //
- // Must have SearchKey for locate ByRegisterNotify
- //
- if (SearchKey == NULL) {
- Status = EFI_INVALID_PARAMETER;
+ case AllHandles:
+ GetNext = CoreGetNextLocateAllHandles;
break;
- }
- GetNext = CoreGetNextLocateByRegisterNotify;
- break;
- case ByProtocol:
- GetNext = CoreGetNextLocateByProtocol;
- if (Protocol == NULL) {
- Status = EFI_INVALID_PARAMETER;
+ case ByRegisterNotify:
+ //
+ // Must have SearchKey for locate ByRegisterNotify
+ //
+ if (SearchKey == NULL) {
+ Status = EFI_INVALID_PARAMETER;
+ break;
+ }
+
+ GetNext = CoreGetNextLocateByRegisterNotify;
break;
- }
- //
- // Look up the protocol entry and set the head pointer
- //
- Position.ProtEntry = CoreFindProtocolEntry (Protocol, FALSE);
- if (Position.ProtEntry == NULL) {
- Status = EFI_NOT_FOUND;
+
+ case ByProtocol:
+ GetNext = CoreGetNextLocateByProtocol;
+ if (Protocol == NULL) {
+ Status = EFI_INVALID_PARAMETER;
+ break;
+ }
+
+ //
+ // Look up the protocol entry and set the head pointer
+ //
+ Position.ProtEntry = CoreFindProtocolEntry (Protocol, FALSE);
+ if (Position.ProtEntry == NULL) {
+ Status = EFI_NOT_FOUND;
+ break;
+ }
+
+ Position.Position = &Position.ProtEntry->Protocols;
break;
- }
- Position.Position = &Position.ProtEntry->Protocols;
- break;
- default:
- Status = EFI_INVALID_PARAMETER;
- break;
+ default:
+ Status = EFI_INVALID_PARAMETER;
+ break;
}
- if (EFI_ERROR(Status)) {
+ if (EFI_ERROR (Status)) {
return Status;
}
@@ -193,7 +195,7 @@ InternalCoreLocateHandle ( // Enumerate out the matching handles
//
mEfiLocateHandleRequest += 1;
- for (; ;) {
+ for ( ; ;) {
//
// Get the next handle. If no more handles, stop
//
@@ -206,10 +208,10 @@ InternalCoreLocateHandle ( // Increase the resulting buffer size, and if this handle
// fits return it
//
- ResultSize += sizeof(Handle);
+ ResultSize += sizeof (Handle);
if (ResultSize <= *BufferSize) {
- *ResultBuffer = Handle;
- ResultBuffer += 1;
+ *ResultBuffer = Handle;
+ ResultBuffer += 1;
}
}
@@ -230,13 +232,13 @@ InternalCoreLocateHandle ( *BufferSize = ResultSize;
- if (SearchType == ByRegisterNotify && !EFI_ERROR(Status)) {
+ if ((SearchType == ByRegisterNotify) && !EFI_ERROR (Status)) {
//
// If this is a search by register notify and a handle was
// returned, update the register notification position
//
ASSERT (SearchKey != NULL);
- ProtNotify = SearchKey;
+ ProtNotify = SearchKey;
ProtNotify->Position = ProtNotify->Position->ForwardLink;
}
}
@@ -265,25 +267,24 @@ InternalCoreLocateHandle ( EFI_STATUS
EFIAPI
CoreLocateHandle (
- IN EFI_LOCATE_SEARCH_TYPE SearchType,
- IN EFI_GUID *Protocol OPTIONAL,
- IN VOID *SearchKey OPTIONAL,
- IN OUT UINTN *BufferSize,
- OUT EFI_HANDLE *Buffer
+ IN EFI_LOCATE_SEARCH_TYPE SearchType,
+ IN EFI_GUID *Protocol OPTIONAL,
+ IN VOID *SearchKey OPTIONAL,
+ IN OUT UINTN *BufferSize,
+ OUT EFI_HANDLE *Buffer
)
{
- EFI_STATUS Status;
+ EFI_STATUS Status;
//
// Lock the protocol database
//
CoreAcquireProtocolLock ();
- Status = InternalCoreLocateHandle(SearchType, Protocol, SearchKey, BufferSize, Buffer);
+ Status = InternalCoreLocateHandle (SearchType, Protocol, SearchKey, BufferSize, Buffer);
CoreReleaseProtocolLock ();
return Status;
}
-
/**
Routine to get the next Handle, when you are searching for all handles.
@@ -297,11 +298,11 @@ CoreLocateHandle ( **/
IHANDLE *
CoreGetNextLocateAllHandles (
- IN OUT LOCATE_POSITION *Position,
- OUT VOID **Interface
+ IN OUT LOCATE_POSITION *Position,
+ OUT VOID **Interface
)
{
- IHANDLE *Handle;
+ IHANDLE *Handle;
//
// Next handle
@@ -311,8 +312,8 @@ CoreGetNextLocateAllHandles ( //
// If not at the end of the list, get the handle
//
- Handle = NULL;
- *Interface = NULL;
+ Handle = NULL;
+ *Interface = NULL;
if (Position->Position != &gHandleList) {
Handle = CR (Position->Position, IHANDLE, AllHandles, EFI_HANDLE_SIGNATURE);
}
@@ -320,8 +321,6 @@ CoreGetNextLocateAllHandles ( return Handle;
}
-
-
/**
Routine to get the next Handle, when you are searching for register protocol
notifies.
@@ -336,8 +335,8 @@ CoreGetNextLocateAllHandles ( **/
IHANDLE *
CoreGetNextLocateByRegisterNotify (
- IN OUT LOCATE_POSITION *Position,
- OUT VOID **Interface
+ IN OUT LOCATE_POSITION *Position,
+ OUT VOID **Interface
)
{
IHANDLE *Handle;
@@ -345,15 +344,15 @@ CoreGetNextLocateByRegisterNotify ( PROTOCOL_INTERFACE *Prot;
LIST_ENTRY *Link;
- Handle = NULL;
- *Interface = NULL;
+ Handle = NULL;
+ *Interface = NULL;
ProtNotify = Position->SearchKey;
//
// If this is the first request, get the next handle
//
if (ProtNotify != NULL) {
- ASSERT(ProtNotify->Signature == PROTOCOL_NOTIFY_SIGNATURE);
+ ASSERT (ProtNotify->Signature == PROTOCOL_NOTIFY_SIGNATURE);
Position->SearchKey = NULL;
//
@@ -361,8 +360,8 @@ CoreGetNextLocateByRegisterNotify ( //
Link = ProtNotify->Position->ForwardLink;
if (Link != &ProtNotify->Protocol->Protocols) {
- Prot = CR (Link, PROTOCOL_INTERFACE, ByProtocol, PROTOCOL_INTERFACE_SIGNATURE);
- Handle = Prot->Handle;
+ Prot = CR (Link, PROTOCOL_INTERFACE, ByProtocol, PROTOCOL_INTERFACE_SIGNATURE);
+ Handle = Prot->Handle;
*Interface = Prot->Interface;
}
}
@@ -370,7 +369,6 @@ CoreGetNextLocateByRegisterNotify ( return Handle;
}
-
/**
Routine to get the next Handle, when you are searching for a given protocol.
@@ -384,21 +382,21 @@ CoreGetNextLocateByRegisterNotify ( **/
IHANDLE *
CoreGetNextLocateByProtocol (
- IN OUT LOCATE_POSITION *Position,
- OUT VOID **Interface
+ IN OUT LOCATE_POSITION *Position,
+ OUT VOID **Interface
)
{
IHANDLE *Handle;
LIST_ENTRY *Link;
PROTOCOL_INTERFACE *Prot;
- Handle = NULL;
- *Interface = NULL;
- for (; ;) {
+ Handle = NULL;
+ *Interface = NULL;
+ for ( ; ;) {
//
// Next entry
//
- Link = Position->Position->ForwardLink;
+ Link = Position->Position->ForwardLink;
Position->Position = Link;
//
@@ -412,8 +410,8 @@ CoreGetNextLocateByProtocol ( //
// Get the handle
//
- Prot = CR(Link, PROTOCOL_INTERFACE, ByProtocol, PROTOCOL_INTERFACE_SIGNATURE);
- Handle = Prot->Handle;
+ Prot = CR (Link, PROTOCOL_INTERFACE, ByProtocol, PROTOCOL_INTERFACE_SIGNATURE);
+ Handle = Prot->Handle;
*Interface = Prot->Interface;
//
@@ -429,7 +427,6 @@ CoreGetNextLocateByProtocol ( return Handle;
}
-
/**
Locates the handle to a device on the device path that supports the specified protocol.
@@ -449,22 +446,22 @@ CoreGetNextLocateByProtocol ( EFI_STATUS
EFIAPI
CoreLocateDevicePath (
- IN EFI_GUID *Protocol,
- IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath,
- OUT EFI_HANDLE *Device
+ IN EFI_GUID *Protocol,
+ IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath,
+ OUT EFI_HANDLE *Device
)
{
- INTN SourceSize;
- INTN Size;
- INTN BestMatch;
- UINTN HandleCount;
- UINTN Index;
- EFI_STATUS Status;
- EFI_HANDLE *Handles;
- EFI_HANDLE Handle;
- EFI_HANDLE BestDevice;
- EFI_DEVICE_PATH_PROTOCOL *SourcePath;
- EFI_DEVICE_PATH_PROTOCOL *TmpDevicePath;
+ INTN SourceSize;
+ INTN Size;
+ INTN BestMatch;
+ UINTN HandleCount;
+ UINTN Index;
+ EFI_STATUS Status;
+ EFI_HANDLE *Handles;
+ EFI_HANDLE Handle;
+ EFI_HANDLE BestDevice;
+ EFI_DEVICE_PATH_PROTOCOL *SourcePath;
+ EFI_DEVICE_PATH_PROTOCOL *TmpDevicePath;
if (Protocol == NULL) {
return EFI_INVALID_PARAMETER;
@@ -474,9 +471,9 @@ CoreLocateDevicePath ( return EFI_INVALID_PARAMETER;
}
- Handles = NULL;
- BestDevice = NULL;
- SourcePath = *DevicePath;
+ Handles = NULL;
+ BestDevice = NULL;
+ SourcePath = *DevicePath;
TmpDevicePath = SourcePath;
while (!IsDevicePathEnd (TmpDevicePath)) {
if (IsDevicePathEndInstance (TmpDevicePath)) {
@@ -486,21 +483,22 @@ CoreLocateDevicePath ( //
break;
}
+
TmpDevicePath = NextDevicePathNode (TmpDevicePath);
}
- SourceSize = (UINTN) TmpDevicePath - (UINTN) SourcePath;
+ SourceSize = (UINTN)TmpDevicePath - (UINTN)SourcePath;
//
// Get a list of all handles that support the requested protocol
//
Status = CoreLocateHandleBuffer (ByProtocol, Protocol, NULL, &HandleCount, &Handles);
- if (EFI_ERROR (Status) || HandleCount == 0) {
+ if (EFI_ERROR (Status) || (HandleCount == 0)) {
return EFI_NOT_FOUND;
}
BestMatch = -1;
- for(Index = 0; Index < HandleCount; Index += 1) {
+ for (Index = 0; Index < HandleCount; Index += 1) {
Handle = Handles[Index];
Status = CoreHandleProtocol (Handle, &gEfiDevicePathProtocolGuid, (VOID **)&TmpDevicePath);
if (EFI_ERROR (Status)) {
@@ -513,9 +511,9 @@ CoreLocateDevicePath ( //
// Check if DevicePath is first part of SourcePath
//
- Size = GetDevicePathSize (TmpDevicePath) - sizeof(EFI_DEVICE_PATH_PROTOCOL);
+ Size = GetDevicePathSize (TmpDevicePath) - sizeof (EFI_DEVICE_PATH_PROTOCOL);
ASSERT (Size >= 0);
- if ((Size <= SourceSize) && CompareMem (SourcePath, TmpDevicePath, (UINTN) Size) == 0) {
+ if ((Size <= SourceSize) && (CompareMem (SourcePath, TmpDevicePath, (UINTN)Size) == 0)) {
//
// If the size is equal to the best match, then we
// have a duplicate device path for 2 different device
@@ -527,7 +525,7 @@ CoreLocateDevicePath ( // We've got a match, see if it's the best match so far
//
if (Size > BestMatch) {
- BestMatch = Size;
+ BestMatch = Size;
BestDevice = Handle;
}
}
@@ -544,18 +542,18 @@ CoreLocateDevicePath ( }
if (Device == NULL) {
- return EFI_INVALID_PARAMETER;
+ return EFI_INVALID_PARAMETER;
}
+
*Device = BestDevice;
//
// Return the remaining part of the device path
//
- *DevicePath = (EFI_DEVICE_PATH_PROTOCOL *) (((UINT8 *) SourcePath) + BestMatch);
+ *DevicePath = (EFI_DEVICE_PATH_PROTOCOL *)(((UINT8 *)SourcePath) + BestMatch);
return EFI_SUCCESS;
}
-
/**
Return the first Protocol Interface that matches the Protocol GUID. If
Registration is passed in, return a Protocol Instance that was just add
@@ -580,17 +578,17 @@ CoreLocateProtocol ( OUT VOID **Interface
)
{
- EFI_STATUS Status;
- LOCATE_POSITION Position;
- PROTOCOL_NOTIFY *ProtNotify;
- IHANDLE *Handle;
+ EFI_STATUS Status;
+ LOCATE_POSITION Position;
+ PROTOCOL_NOTIFY *ProtNotify;
+ IHANDLE *Handle;
if ((Interface == NULL) || (Protocol == NULL)) {
return EFI_INVALID_PARAMETER;
}
*Interface = NULL;
- Status = EFI_SUCCESS;
+ Status = EFI_SUCCESS;
//
// Set initial position
@@ -618,6 +616,7 @@ CoreLocateProtocol ( Status = EFI_NOT_FOUND;
goto Done;
}
+
Position.Position = &Position.ProtEntry->Protocols;
Handle = CoreGetNextLocateByProtocol (&Position, Interface);
@@ -632,7 +631,7 @@ CoreLocateProtocol ( // If this is a search by register notify and a handle was
// returned, update the register notification position
//
- ProtNotify = Registration;
+ ProtNotify = Registration;
ProtNotify->Position = ProtNotify->Position->ForwardLink;
}
@@ -666,15 +665,15 @@ Done: EFI_STATUS
EFIAPI
CoreLocateHandleBuffer (
- IN EFI_LOCATE_SEARCH_TYPE SearchType,
- IN EFI_GUID *Protocol OPTIONAL,
- IN VOID *SearchKey OPTIONAL,
- IN OUT UINTN *NumberHandles,
- OUT EFI_HANDLE **Buffer
+ IN EFI_LOCATE_SEARCH_TYPE SearchType,
+ IN EFI_GUID *Protocol OPTIONAL,
+ IN VOID *SearchKey OPTIONAL,
+ IN OUT UINTN *NumberHandles,
+ OUT EFI_HANDLE **Buffer
)
{
- EFI_STATUS Status;
- UINTN BufferSize;
+ EFI_STATUS Status;
+ UINTN BufferSize;
if (NumberHandles == NULL) {
return EFI_INVALID_PARAMETER;
@@ -684,14 +683,14 @@ CoreLocateHandleBuffer ( return EFI_INVALID_PARAMETER;
}
- BufferSize = 0;
+ BufferSize = 0;
*NumberHandles = 0;
- *Buffer = NULL;
+ *Buffer = NULL;
//
// Lock the protocol database
//
- CoreAcquireProtocolLock();
+ CoreAcquireProtocolLock ();
Status = InternalCoreLocateHandle (
SearchType,
Protocol,
@@ -705,10 +704,11 @@ CoreLocateHandleBuffer ( //
// Add code to correctly handle expected errors from CoreLocateHandle().
//
- if (EFI_ERROR(Status) && Status != EFI_BUFFER_TOO_SMALL) {
+ if (EFI_ERROR (Status) && (Status != EFI_BUFFER_TOO_SMALL)) {
if (Status != EFI_INVALID_PARAMETER) {
Status = EFI_NOT_FOUND;
}
+
CoreReleaseProtocolLock ();
return Status;
}
@@ -727,14 +727,11 @@ CoreLocateHandleBuffer ( *Buffer
);
- *NumberHandles = BufferSize / sizeof(EFI_HANDLE);
- if (EFI_ERROR(Status)) {
+ *NumberHandles = BufferSize / sizeof (EFI_HANDLE);
+ if (EFI_ERROR (Status)) {
*NumberHandles = 0;
}
CoreReleaseProtocolLock ();
return Status;
}
-
-
-
diff --git a/MdeModulePkg/Core/Dxe/Hand/Notify.c b/MdeModulePkg/Core/Dxe/Hand/Notify.c index d05f95207f..a6e20cad23 100644 --- a/MdeModulePkg/Core/Dxe/Hand/Notify.c +++ b/MdeModulePkg/Core/Dxe/Hand/Notify.c @@ -19,22 +19,20 @@ SPDX-License-Identifier: BSD-2-Clause-Patent **/
VOID
CoreNotifyProtocolEntry (
- IN PROTOCOL_ENTRY *ProtEntry
+ IN PROTOCOL_ENTRY *ProtEntry
)
{
- PROTOCOL_NOTIFY *ProtNotify;
- LIST_ENTRY *Link;
+ PROTOCOL_NOTIFY *ProtNotify;
+ LIST_ENTRY *Link;
ASSERT_LOCKED (&gProtocolDatabaseLock);
- for (Link=ProtEntry->Notify.ForwardLink; Link != &ProtEntry->Notify; Link=Link->ForwardLink) {
- ProtNotify = CR(Link, PROTOCOL_NOTIFY, Link, PROTOCOL_NOTIFY_SIGNATURE);
+ for (Link = ProtEntry->Notify.ForwardLink; Link != &ProtEntry->Notify; Link = Link->ForwardLink) {
+ ProtNotify = CR (Link, PROTOCOL_NOTIFY, Link, PROTOCOL_NOTIFY_SIGNATURE);
CoreSignalEvent (ProtNotify->Event);
}
}
-
-
/**
Removes Protocol from the protocol list (but not the handle list).
@@ -47,9 +45,9 @@ CoreNotifyProtocolEntry ( **/
PROTOCOL_INTERFACE *
CoreRemoveInterfaceFromProtocol (
- IN IHANDLE *Handle,
- IN EFI_GUID *Protocol,
- IN VOID *Interface
+ IN IHANDLE *Handle,
+ IN EFI_GUID *Protocol,
+ IN VOID *Interface
)
{
PROTOCOL_INTERFACE *Prot;
@@ -61,14 +59,13 @@ CoreRemoveInterfaceFromProtocol ( Prot = CoreFindProtocolInterface (Handle, Protocol, Interface);
if (Prot != NULL) {
-
ProtEntry = Prot->Protocol;
//
// If there's a protocol notify location pointing to this entry, back it up one
//
- for(Link = ProtEntry->Notify.ForwardLink; Link != &ProtEntry->Notify; Link=Link->ForwardLink) {
- ProtNotify = CR(Link, PROTOCOL_NOTIFY, Link, PROTOCOL_NOTIFY_SIGNATURE);
+ for (Link = ProtEntry->Notify.ForwardLink; Link != &ProtEntry->Notify; Link = Link->ForwardLink) {
+ ProtNotify = CR (Link, PROTOCOL_NOTIFY, Link, PROTOCOL_NOTIFY_SIGNATURE);
if (ProtNotify->Position == &Prot->ByProtocol) {
ProtNotify->Position = Prot->ByProtocol.BackLink;
@@ -84,7 +81,6 @@ CoreRemoveInterfaceFromProtocol ( return Prot;
}
-
/**
Add a new protocol notification record for the request protocol.
@@ -101,16 +97,16 @@ CoreRemoveInterfaceFromProtocol ( EFI_STATUS
EFIAPI
CoreRegisterProtocolNotify (
- IN EFI_GUID *Protocol,
- IN EFI_EVENT Event,
- OUT VOID **Registration
+ IN EFI_GUID *Protocol,
+ IN EFI_EVENT Event,
+ OUT VOID **Registration
)
{
- PROTOCOL_ENTRY *ProtEntry;
- PROTOCOL_NOTIFY *ProtNotify;
- EFI_STATUS Status;
+ PROTOCOL_ENTRY *ProtEntry;
+ PROTOCOL_NOTIFY *ProtNotify;
+ EFI_STATUS Status;
- if ((Protocol == NULL) || (Event == NULL) || (Registration == NULL)) {
+ if ((Protocol == NULL) || (Event == NULL) || (Registration == NULL)) {
return EFI_INVALID_PARAMETER;
}
@@ -124,16 +120,15 @@ CoreRegisterProtocolNotify ( ProtEntry = CoreFindProtocolEntry (Protocol, TRUE);
if (ProtEntry != NULL) {
-
//
// Allocate a new notification record
//
- ProtNotify = AllocatePool (sizeof(PROTOCOL_NOTIFY));
+ ProtNotify = AllocatePool (sizeof (PROTOCOL_NOTIFY));
if (ProtNotify != NULL) {
((IEVENT *)Event)->ExFlag |= EVT_EXFLAG_EVENT_PROTOCOL_NOTIFICATION;
- ProtNotify->Signature = PROTOCOL_NOTIFY_SIGNATURE;
- ProtNotify->Protocol = ProtEntry;
- ProtNotify->Event = Event;
+ ProtNotify->Signature = PROTOCOL_NOTIFY_SIGNATURE;
+ ProtNotify->Protocol = ProtEntry;
+ ProtNotify->Event = Event;
//
// start at the begining
//
@@ -153,13 +148,12 @@ CoreRegisterProtocolNotify ( Status = EFI_OUT_OF_RESOURCES;
if (ProtNotify != NULL) {
*Registration = ProtNotify;
- Status = EFI_SUCCESS;
+ Status = EFI_SUCCESS;
}
return Status;
}
-
/**
Reinstall a protocol interface on a device handle. The OldInterface for Protocol is replaced by the NewInterface.
@@ -177,16 +171,16 @@ CoreRegisterProtocolNotify ( EFI_STATUS
EFIAPI
CoreReinstallProtocolInterface (
- IN EFI_HANDLE UserHandle,
- IN EFI_GUID *Protocol,
- IN VOID *OldInterface,
- IN VOID *NewInterface
+ IN EFI_HANDLE UserHandle,
+ IN EFI_GUID *Protocol,
+ IN VOID *OldInterface,
+ IN VOID *NewInterface
)
{
- EFI_STATUS Status;
- IHANDLE *Handle;
- PROTOCOL_INTERFACE *Prot;
- PROTOCOL_ENTRY *ProtEntry;
+ EFI_STATUS Status;
+ IHANDLE *Handle;
+ PROTOCOL_INTERFACE *Prot;
+ PROTOCOL_ENTRY *ProtEntry;
if (Protocol == NULL) {
return EFI_INVALID_PARAMETER;
@@ -202,7 +196,7 @@ CoreReinstallProtocolInterface ( goto Done;
}
- Handle = (IHANDLE *) UserHandle;
+ Handle = (IHANDLE *)UserHandle;
//
// Check that Protocol exists on UserHandle, and Interface matches the interface in the database
//
diff --git a/MdeModulePkg/Core/Dxe/Image/Image.c b/MdeModulePkg/Core/Dxe/Image/Image.c index 44b7f105a2..68bde5c15c 100644 --- a/MdeModulePkg/Core/Dxe/Image/Image.c +++ b/MdeModulePkg/Core/Dxe/Image/Image.c @@ -15,24 +15,24 @@ SPDX-License-Identifier: BSD-2-Clause-Patent LOADED_IMAGE_PRIVATE_DATA *mCurrentImage = NULL;
typedef struct {
- LIST_ENTRY Link;
- EDKII_PECOFF_IMAGE_EMULATOR_PROTOCOL *Emulator;
- UINT16 MachineType;
+ LIST_ENTRY Link;
+ EDKII_PECOFF_IMAGE_EMULATOR_PROTOCOL *Emulator;
+ UINT16 MachineType;
} EMULATOR_ENTRY;
-STATIC LIST_ENTRY mAvailableEmulators;
-STATIC EFI_EVENT mPeCoffEmuProtocolRegistrationEvent;
-STATIC VOID *mPeCoffEmuProtocolNotifyRegistration;
+STATIC LIST_ENTRY mAvailableEmulators;
+STATIC EFI_EVENT mPeCoffEmuProtocolRegistrationEvent;
+STATIC VOID *mPeCoffEmuProtocolNotifyRegistration;
//
// This code is needed to build the Image handle for the DXE Core
//
-LOADED_IMAGE_PRIVATE_DATA mCorePrivateImage = {
- LOADED_IMAGE_PRIVATE_DATA_SIGNATURE, // Signature
- NULL, // Image handle
- EFI_IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER, // Image type
- TRUE, // If entrypoint has been called
- NULL, // EntryPoint
+LOADED_IMAGE_PRIVATE_DATA mCorePrivateImage = {
+ LOADED_IMAGE_PRIVATE_DATA_SIGNATURE, // Signature
+ NULL, // Image handle
+ EFI_IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER, // Image type
+ TRUE, // If entrypoint has been called
+ NULL, // EntryPoint
{
EFI_LOADED_IMAGE_INFORMATION_REVISION, // Revision
NULL, // Parent handle
@@ -69,22 +69,22 @@ LOADED_IMAGE_PRIVATE_DATA mCorePrivateImage = { // memory range usage. It is a bit mapped array in which every bit indicates the correspoding memory page
// available or not.
//
-GLOBAL_REMOVE_IF_UNREFERENCED UINT64 *mDxeCodeMemoryRangeUsageBitMap=NULL;
+GLOBAL_REMOVE_IF_UNREFERENCED UINT64 *mDxeCodeMemoryRangeUsageBitMap = NULL;
typedef struct {
- UINT16 MachineType;
- CHAR16 *MachineTypeName;
+ UINT16 MachineType;
+ CHAR16 *MachineTypeName;
} MACHINE_TYPE_INFO;
GLOBAL_REMOVE_IF_UNREFERENCED MACHINE_TYPE_INFO mMachineTypeInfo[] = {
- {EFI_IMAGE_MACHINE_IA32, L"IA32"},
- {EFI_IMAGE_MACHINE_IA64, L"IA64"},
- {EFI_IMAGE_MACHINE_X64, L"X64"},
- {EFI_IMAGE_MACHINE_ARMTHUMB_MIXED, L"ARM"},
- {EFI_IMAGE_MACHINE_AARCH64, L"AARCH64"}
+ { EFI_IMAGE_MACHINE_IA32, L"IA32" },
+ { EFI_IMAGE_MACHINE_IA64, L"IA64" },
+ { EFI_IMAGE_MACHINE_X64, L"X64" },
+ { EFI_IMAGE_MACHINE_ARMTHUMB_MIXED, L"ARM" },
+ { EFI_IMAGE_MACHINE_AARCH64, L"AARCH64" }
};
-UINT16 mDxeCoreImageMachineType = 0;
+UINT16 mDxeCoreImageMachineType = 0;
/**
Return machine type name.
@@ -95,12 +95,12 @@ UINT16 mDxeCoreImageMachineType = 0; **/
CHAR16 *
GetMachineTypeName (
- UINT16 MachineType
+ UINT16 MachineType
)
{
UINTN Index;
- for (Index = 0; Index < sizeof(mMachineTypeInfo)/sizeof(mMachineTypeInfo[0]); Index++) {
+ for (Index = 0; Index < sizeof (mMachineTypeInfo)/sizeof (mMachineTypeInfo[0]); Index++) {
if (mMachineTypeInfo[Index].MachineType == MachineType) {
return mMachineTypeInfo[Index].MachineTypeName;
}
@@ -121,8 +121,8 @@ STATIC VOID
EFIAPI
PeCoffEmuProtocolNotify (
- IN EFI_EVENT Event,
- IN VOID *Context
+ IN EFI_EVENT Event,
+ IN VOID *Context
)
{
EFI_STATUS Status;
@@ -136,13 +136,13 @@ PeCoffEmuProtocolNotify ( while (TRUE) {
BufferSize = sizeof (EmuHandle);
- Status = CoreLocateHandle (
- ByRegisterNotify,
- NULL,
- mPeCoffEmuProtocolNotifyRegistration,
- &BufferSize,
- &EmuHandle
- );
+ Status = CoreLocateHandle (
+ ByRegisterNotify,
+ NULL,
+ mPeCoffEmuProtocolNotifyRegistration,
+ &BufferSize,
+ &EmuHandle
+ );
if (EFI_ERROR (Status)) {
//
// If no more notification events exit
@@ -155,7 +155,7 @@ PeCoffEmuProtocolNotify ( &gEdkiiPeCoffImageEmulatorProtocolGuid,
(VOID **)&Emulator
);
- if (EFI_ERROR (Status) || Emulator == NULL) {
+ if (EFI_ERROR (Status) || (Emulator == NULL)) {
continue;
}
@@ -180,20 +180,20 @@ PeCoffEmuProtocolNotify ( **/
EFI_STATUS
CoreInitializeImageServices (
- IN VOID *HobStart
+ IN VOID *HobStart
)
{
- EFI_STATUS Status;
- LOADED_IMAGE_PRIVATE_DATA *Image;
- EFI_PHYSICAL_ADDRESS DxeCoreImageBaseAddress;
- UINT64 DxeCoreImageLength;
- VOID *DxeCoreEntryPoint;
- EFI_PEI_HOB_POINTERS DxeCoreHob;
+ EFI_STATUS Status;
+ LOADED_IMAGE_PRIVATE_DATA *Image;
+ EFI_PHYSICAL_ADDRESS DxeCoreImageBaseAddress;
+ UINT64 DxeCoreImageLength;
+ VOID *DxeCoreEntryPoint;
+ EFI_PEI_HOB_POINTERS DxeCoreHob;
//
// Searching for image hob
//
- DxeCoreHob.Raw = HobStart;
+ DxeCoreHob.Raw = HobStart;
while ((DxeCoreHob.Raw = GetNextHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, DxeCoreHob.Raw)) != NULL) {
if (CompareGuid (&DxeCoreHob.MemoryAllocationModule->MemoryAllocationHeader.Name, &gEfiHobMemoryAllocModuleGuid)) {
//
@@ -201,13 +201,15 @@ CoreInitializeImageServices ( //
break;
}
+
DxeCoreHob.Raw = GET_NEXT_HOB (DxeCoreHob);
}
+
ASSERT (DxeCoreHob.Raw != NULL);
DxeCoreImageBaseAddress = DxeCoreHob.MemoryAllocationModule->MemoryAllocationHeader.MemoryBaseAddress;
DxeCoreImageLength = DxeCoreHob.MemoryAllocationModule->MemoryAllocationHeader.MemoryLength;
- DxeCoreEntryPoint = (VOID *) (UINTN) DxeCoreHob.MemoryAllocationModule->EntryPoint;
+ DxeCoreEntryPoint = (VOID *)(UINTN)DxeCoreHob.MemoryAllocationModule->EntryPoint;
gDxeCoreFileName = &DxeCoreHob.MemoryAllocationModule->ModuleName;
//
@@ -215,13 +217,13 @@ CoreInitializeImageServices ( //
Image = &mCorePrivateImage;
- Image->EntryPoint = (EFI_IMAGE_ENTRY_POINT)(UINTN)DxeCoreEntryPoint;
- Image->ImageBasePage = DxeCoreImageBaseAddress;
- Image->NumberOfPages = (UINTN)(EFI_SIZE_TO_PAGES((UINTN)(DxeCoreImageLength)));
- Image->Tpl = gEfiCurrentTpl;
- Image->Info.SystemTable = gDxeCoreST;
- Image->Info.ImageBase = (VOID *)(UINTN)DxeCoreImageBaseAddress;
- Image->Info.ImageSize = DxeCoreImageLength;
+ Image->EntryPoint = (EFI_IMAGE_ENTRY_POINT)(UINTN)DxeCoreEntryPoint;
+ Image->ImageBasePage = DxeCoreImageBaseAddress;
+ Image->NumberOfPages = (UINTN)(EFI_SIZE_TO_PAGES ((UINTN)(DxeCoreImageLength)));
+ Image->Tpl = gEfiCurrentTpl;
+ Image->Info.SystemTable = gDxeCoreST;
+ Image->Info.ImageBase = (VOID *)(UINTN)DxeCoreImageBaseAddress;
+ Image->Info.ImageSize = DxeCoreImageLength;
//
// Install the protocol interfaces for this image
@@ -240,8 +242,8 @@ CoreInitializeImageServices ( // Fill in DXE globals
//
mDxeCoreImageMachineType = PeCoffLoaderGetMachineType (Image->Info.ImageBase);
- gDxeCoreImageHandle = Image->Handle;
- gDxeCoreLoadedImage = &Image->Info;
+ gDxeCoreImageHandle = Image->Handle;
+ gDxeCoreLoadedImage = &Image->Info;
//
// Create the PE/COFF emulator protocol registration event
@@ -253,7 +255,7 @@ CoreInitializeImageServices ( NULL,
&mPeCoffEmuProtocolRegistrationEvent
);
- ASSERT_EFI_ERROR(Status);
+ ASSERT_EFI_ERROR (Status);
//
// Register for protocol notifications on this event
@@ -263,7 +265,7 @@ CoreInitializeImageServices ( mPeCoffEmuProtocolRegistrationEvent,
&mPeCoffEmuProtocolNotifyRegistration
);
- ASSERT_EFI_ERROR(Status);
+ ASSERT_EFI_ERROR (Status);
InitializeListHead (&mAvailableEmulators);
@@ -289,16 +291,16 @@ CoreInitializeImageServices ( EFI_STATUS
EFIAPI
CoreReadImageFile (
- IN VOID *UserHandle,
- IN UINTN Offset,
- IN OUT UINTN *ReadSize,
- OUT VOID *Buffer
+ IN VOID *UserHandle,
+ IN UINTN Offset,
+ IN OUT UINTN *ReadSize,
+ OUT VOID *Buffer
)
{
- UINTN EndPosition;
+ UINTN EndPosition;
IMAGE_FILE_HANDLE *FHand;
- if (UserHandle == NULL || ReadSize == NULL || Buffer == NULL) {
+ if ((UserHandle == NULL) || (ReadSize == NULL) || (Buffer == NULL)) {
return EFI_INVALID_PARAMETER;
}
@@ -316,13 +318,15 @@ CoreReadImageFile ( if (EndPosition > FHand->SourceSize) {
*ReadSize = (UINT32)(FHand->SourceSize - Offset);
}
+
if (Offset >= FHand->SourceSize) {
- *ReadSize = 0;
+ *ReadSize = 0;
}
CopyMem (Buffer, (CHAR8 *)FHand->Source + Offset, *ReadSize);
return EFI_SUCCESS;
}
+
/**
To check memory usage bit map array to figure out if the memory range the image will be loaded in is available or not. If
memory range is available, the function will mark the corresponding bits to 1 which indicates the memory range is used.
@@ -336,66 +340,73 @@ CoreReadImageFile ( **/
EFI_STATUS
CheckAndMarkFixLoadingMemoryUsageBitMap (
- IN EFI_PHYSICAL_ADDRESS ImageBase,
- IN UINTN ImageSize
+ IN EFI_PHYSICAL_ADDRESS ImageBase,
+ IN UINTN ImageSize
)
{
- UINT32 DxeCodePageNumber;
- UINT64 DxeCodeSize;
- EFI_PHYSICAL_ADDRESS DxeCodeBase;
- UINTN BaseOffsetPageNumber;
- UINTN TopOffsetPageNumber;
- UINTN Index;
- //
- // The DXE code range includes RuntimeCodePage range and Boot time code range.
- //
- DxeCodePageNumber = PcdGet32(PcdLoadFixAddressRuntimeCodePageNumber);
- DxeCodePageNumber += PcdGet32(PcdLoadFixAddressBootTimeCodePageNumber);
- DxeCodeSize = EFI_PAGES_TO_SIZE(DxeCodePageNumber);
- DxeCodeBase = gLoadModuleAtFixAddressConfigurationTable.DxeCodeTopAddress - DxeCodeSize;
-
- //
- // If the memory usage bit map is not initialized, do it. Every bit in the array
- // indicate the status of the corresponding memory page, available or not
- //
- if (mDxeCodeMemoryRangeUsageBitMap == NULL) {
- mDxeCodeMemoryRangeUsageBitMap = AllocateZeroPool(((DxeCodePageNumber/64) + 1)*sizeof(UINT64));
- }
- //
- // If the Dxe code memory range is not allocated or the bit map array allocation failed, return EFI_NOT_FOUND
- //
- if (!gLoadFixedAddressCodeMemoryReady || mDxeCodeMemoryRangeUsageBitMap == NULL) {
- return EFI_NOT_FOUND;
- }
- //
- // Test the memory range for loading the image in the DXE code range.
- //
- if (gLoadModuleAtFixAddressConfigurationTable.DxeCodeTopAddress < ImageBase + ImageSize ||
- DxeCodeBase > ImageBase) {
- return EFI_NOT_FOUND;
- }
- //
- // Test if the memory is avalaible or not.
- //
- BaseOffsetPageNumber = EFI_SIZE_TO_PAGES((UINT32)(ImageBase - DxeCodeBase));
- TopOffsetPageNumber = EFI_SIZE_TO_PAGES((UINT32)(ImageBase + ImageSize - DxeCodeBase));
- for (Index = BaseOffsetPageNumber; Index < TopOffsetPageNumber; Index ++) {
- if ((mDxeCodeMemoryRangeUsageBitMap[Index / 64] & LShiftU64(1, (Index % 64))) != 0) {
- //
- // This page is already used.
- //
- return EFI_NOT_FOUND;
- }
- }
-
- //
- // Being here means the memory range is available. So mark the bits for the memory range
- //
- for (Index = BaseOffsetPageNumber; Index < TopOffsetPageNumber; Index ++) {
- mDxeCodeMemoryRangeUsageBitMap[Index / 64] |= LShiftU64(1, (Index % 64));
- }
- return EFI_SUCCESS;
+ UINT32 DxeCodePageNumber;
+ UINT64 DxeCodeSize;
+ EFI_PHYSICAL_ADDRESS DxeCodeBase;
+ UINTN BaseOffsetPageNumber;
+ UINTN TopOffsetPageNumber;
+ UINTN Index;
+
+ //
+ // The DXE code range includes RuntimeCodePage range and Boot time code range.
+ //
+ DxeCodePageNumber = PcdGet32 (PcdLoadFixAddressRuntimeCodePageNumber);
+ DxeCodePageNumber += PcdGet32 (PcdLoadFixAddressBootTimeCodePageNumber);
+ DxeCodeSize = EFI_PAGES_TO_SIZE (DxeCodePageNumber);
+ DxeCodeBase = gLoadModuleAtFixAddressConfigurationTable.DxeCodeTopAddress - DxeCodeSize;
+
+ //
+ // If the memory usage bit map is not initialized, do it. Every bit in the array
+ // indicate the status of the corresponding memory page, available or not
+ //
+ if (mDxeCodeMemoryRangeUsageBitMap == NULL) {
+ mDxeCodeMemoryRangeUsageBitMap = AllocateZeroPool (((DxeCodePageNumber/64) + 1)*sizeof (UINT64));
+ }
+
+ //
+ // If the Dxe code memory range is not allocated or the bit map array allocation failed, return EFI_NOT_FOUND
+ //
+ if (!gLoadFixedAddressCodeMemoryReady || (mDxeCodeMemoryRangeUsageBitMap == NULL)) {
+ return EFI_NOT_FOUND;
+ }
+
+ //
+ // Test the memory range for loading the image in the DXE code range.
+ //
+ if ((gLoadModuleAtFixAddressConfigurationTable.DxeCodeTopAddress < ImageBase + ImageSize) ||
+ (DxeCodeBase > ImageBase))
+ {
+ return EFI_NOT_FOUND;
+ }
+
+ //
+ // Test if the memory is avalaible or not.
+ //
+ BaseOffsetPageNumber = EFI_SIZE_TO_PAGES ((UINT32)(ImageBase - DxeCodeBase));
+ TopOffsetPageNumber = EFI_SIZE_TO_PAGES ((UINT32)(ImageBase + ImageSize - DxeCodeBase));
+ for (Index = BaseOffsetPageNumber; Index < TopOffsetPageNumber; Index++) {
+ if ((mDxeCodeMemoryRangeUsageBitMap[Index / 64] & LShiftU64 (1, (Index % 64))) != 0) {
+ //
+ // This page is already used.
+ //
+ return EFI_NOT_FOUND;
+ }
+ }
+
+ //
+ // Being here means the memory range is available. So mark the bits for the memory range
+ //
+ for (Index = BaseOffsetPageNumber; Index < TopOffsetPageNumber; Index++) {
+ mDxeCodeMemoryRangeUsageBitMap[Index / 64] |= LShiftU64 (1, (Index % 64));
+ }
+
+ return EFI_SUCCESS;
}
+
/**
Get the fixed loading address from image header assigned by build tool. This function only be called
@@ -408,85 +419,89 @@ CheckAndMarkFixLoadingMemoryUsageBitMap ( **/
EFI_STATUS
-GetPeCoffImageFixLoadingAssignedAddress(
+GetPeCoffImageFixLoadingAssignedAddress (
IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
)
{
- UINTN SectionHeaderOffset;
- EFI_STATUS Status;
- EFI_IMAGE_SECTION_HEADER SectionHeader;
- EFI_IMAGE_OPTIONAL_HEADER_UNION *ImgHdr;
- UINT16 Index;
- UINTN Size;
- UINT16 NumberOfSections;
- IMAGE_FILE_HANDLE *Handle;
- UINT64 ValueInSectionHeader;
-
-
- Status = EFI_NOT_FOUND;
-
- //
- // Get PeHeader pointer
- //
- Handle = (IMAGE_FILE_HANDLE*)ImageContext->Handle;
- ImgHdr = (EFI_IMAGE_OPTIONAL_HEADER_UNION *)((CHAR8* )Handle->Source + ImageContext->PeCoffHeaderOffset);
- SectionHeaderOffset = ImageContext->PeCoffHeaderOffset +
- sizeof (UINT32) +
- sizeof (EFI_IMAGE_FILE_HEADER) +
- ImgHdr->Pe32.FileHeader.SizeOfOptionalHeader;
- NumberOfSections = ImgHdr->Pe32.FileHeader.NumberOfSections;
-
- //
- // Get base address from the first section header that doesn't point to code section.
- //
- for (Index = 0; Index < NumberOfSections; Index++) {
- //
- // Read section header from file
- //
- Size = sizeof (EFI_IMAGE_SECTION_HEADER);
- Status = ImageContext->ImageRead (
- ImageContext->Handle,
- SectionHeaderOffset,
- &Size,
- &SectionHeader
- );
- if (EFI_ERROR (Status)) {
- return Status;
- }
- if (Size != sizeof (EFI_IMAGE_SECTION_HEADER)) {
- return EFI_NOT_FOUND;
- }
-
- Status = EFI_NOT_FOUND;
-
- if ((SectionHeader.Characteristics & EFI_IMAGE_SCN_CNT_CODE) == 0) {
- //
- // Build tool will save the address in PointerToRelocations & PointerToLineNumbers fields in the first section header
- // that doesn't point to code section in image header, as well as ImageBase field of image header. And there is an
- // assumption that when the feature is enabled, if a module is assigned a loading address by tools, PointerToRelocations
- // & PointerToLineNumbers fields should NOT be Zero, or else, these 2 fields should be set to Zero
- //
- ValueInSectionHeader = ReadUnaligned64((UINT64*)&SectionHeader.PointerToRelocations);
- if (ValueInSectionHeader != 0) {
- //
- // When the feature is configured as load module at fixed absolute address, the ImageAddress field of ImageContext
- // hold the specified address. If the feature is configured as load module at fixed offset, ImageAddress hold an offset
- // relative to top address
- //
- if ((INT64)PcdGet64(PcdLoadModuleAtFixAddressEnable) < 0) {
- ImageContext->ImageAddress = gLoadModuleAtFixAddressConfigurationTable.DxeCodeTopAddress + (INT64)(INTN)ImageContext->ImageAddress;
- }
- //
- // Check if the memory range is available.
- //
- Status = CheckAndMarkFixLoadingMemoryUsageBitMap (ImageContext->ImageAddress, (UINTN)(ImageContext->ImageSize + ImageContext->SectionAlignment));
- }
- break;
- }
- SectionHeaderOffset += sizeof (EFI_IMAGE_SECTION_HEADER);
- }
- DEBUG ((DEBUG_INFO|DEBUG_LOAD, "LOADING MODULE FIXED INFO: Loading module at fixed address 0x%11p. Status = %r \n", (VOID *)(UINTN)(ImageContext->ImageAddress), Status));
- return Status;
+ UINTN SectionHeaderOffset;
+ EFI_STATUS Status;
+ EFI_IMAGE_SECTION_HEADER SectionHeader;
+ EFI_IMAGE_OPTIONAL_HEADER_UNION *ImgHdr;
+ UINT16 Index;
+ UINTN Size;
+ UINT16 NumberOfSections;
+ IMAGE_FILE_HANDLE *Handle;
+ UINT64 ValueInSectionHeader;
+
+ Status = EFI_NOT_FOUND;
+
+ //
+ // Get PeHeader pointer
+ //
+ Handle = (IMAGE_FILE_HANDLE *)ImageContext->Handle;
+ ImgHdr = (EFI_IMAGE_OPTIONAL_HEADER_UNION *)((CHAR8 *)Handle->Source + ImageContext->PeCoffHeaderOffset);
+ SectionHeaderOffset = ImageContext->PeCoffHeaderOffset +
+ sizeof (UINT32) +
+ sizeof (EFI_IMAGE_FILE_HEADER) +
+ ImgHdr->Pe32.FileHeader.SizeOfOptionalHeader;
+ NumberOfSections = ImgHdr->Pe32.FileHeader.NumberOfSections;
+
+ //
+ // Get base address from the first section header that doesn't point to code section.
+ //
+ for (Index = 0; Index < NumberOfSections; Index++) {
+ //
+ // Read section header from file
+ //
+ Size = sizeof (EFI_IMAGE_SECTION_HEADER);
+ Status = ImageContext->ImageRead (
+ ImageContext->Handle,
+ SectionHeaderOffset,
+ &Size,
+ &SectionHeader
+ );
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ if (Size != sizeof (EFI_IMAGE_SECTION_HEADER)) {
+ return EFI_NOT_FOUND;
+ }
+
+ Status = EFI_NOT_FOUND;
+
+ if ((SectionHeader.Characteristics & EFI_IMAGE_SCN_CNT_CODE) == 0) {
+ //
+ // Build tool will save the address in PointerToRelocations & PointerToLineNumbers fields in the first section header
+ // that doesn't point to code section in image header, as well as ImageBase field of image header. And there is an
+ // assumption that when the feature is enabled, if a module is assigned a loading address by tools, PointerToRelocations
+ // & PointerToLineNumbers fields should NOT be Zero, or else, these 2 fields should be set to Zero
+ //
+ ValueInSectionHeader = ReadUnaligned64 ((UINT64 *)&SectionHeader.PointerToRelocations);
+ if (ValueInSectionHeader != 0) {
+ //
+ // When the feature is configured as load module at fixed absolute address, the ImageAddress field of ImageContext
+ // hold the specified address. If the feature is configured as load module at fixed offset, ImageAddress hold an offset
+ // relative to top address
+ //
+ if ((INT64)PcdGet64 (PcdLoadModuleAtFixAddressEnable) < 0) {
+ ImageContext->ImageAddress = gLoadModuleAtFixAddressConfigurationTable.DxeCodeTopAddress + (INT64)(INTN)ImageContext->ImageAddress;
+ }
+
+ //
+ // Check if the memory range is available.
+ //
+ Status = CheckAndMarkFixLoadingMemoryUsageBitMap (ImageContext->ImageAddress, (UINTN)(ImageContext->ImageSize + ImageContext->SectionAlignment));
+ }
+
+ break;
+ }
+
+ SectionHeaderOffset += sizeof (EFI_IMAGE_SECTION_HEADER);
+ }
+
+ DEBUG ((DEBUG_INFO|DEBUG_LOAD, "LOADING MODULE FIXED INFO: Loading module at fixed address 0x%11p. Status = %r \n", (VOID *)(UINTN)(ImageContext->ImageAddress), Status));
+ return Status;
}
/**
@@ -507,21 +522,24 @@ CoreIsImageTypeSupported ( IN OUT LOADED_IMAGE_PRIVATE_DATA *Image
)
{
- LIST_ENTRY *Link;
- EMULATOR_ENTRY *Entry;
+ LIST_ENTRY *Link;
+ EMULATOR_ENTRY *Entry;
for (Link = GetFirstNode (&mAvailableEmulators);
!IsNull (&mAvailableEmulators, Link);
- Link = GetNextNode (&mAvailableEmulators, Link)) {
-
+ Link = GetNextNode (&mAvailableEmulators, Link))
+ {
Entry = BASE_CR (Link, EMULATOR_ENTRY, Link);
if (Entry->MachineType != Image->ImageContext.Machine) {
continue;
}
- if (Entry->Emulator->IsImageSupported (Entry->Emulator,
+ if (Entry->Emulator->IsImageSupported (
+ Entry->Emulator,
Image->ImageContext.ImageType,
- Image->Info.FilePath)) {
+ Image->Info.FilePath
+ ))
+ {
Image->PeCoffEmu = Entry->Emulator;
return TRUE;
}
@@ -554,17 +572,17 @@ CoreIsImageTypeSupported ( **/
EFI_STATUS
CoreLoadPeImage (
- IN BOOLEAN BootPolicy,
- IN VOID *Pe32Handle,
- IN LOADED_IMAGE_PRIVATE_DATA *Image,
- IN EFI_PHYSICAL_ADDRESS DstBuffer OPTIONAL,
- OUT EFI_PHYSICAL_ADDRESS *EntryPoint OPTIONAL,
- IN UINT32 Attribute
+ IN BOOLEAN BootPolicy,
+ IN VOID *Pe32Handle,
+ IN LOADED_IMAGE_PRIVATE_DATA *Image,
+ IN EFI_PHYSICAL_ADDRESS DstBuffer OPTIONAL,
+ OUT EFI_PHYSICAL_ADDRESS *EntryPoint OPTIONAL,
+ IN UINT32 Attribute
)
{
- EFI_STATUS Status;
- BOOLEAN DstBufAlocated;
- UINTN Size;
+ EFI_STATUS Status;
+ BOOLEAN DstBufAlocated;
+ UINTN Size;
ZeroMem (&Image->ImageContext, sizeof (Image->ImageContext));
@@ -584,9 +602,12 @@ CoreLoadPeImage ( // The PE/COFF loader can support loading image types that can be executed.
// If we loaded an image type that we can not execute return EFI_UNSUPPORTED.
//
- DEBUG ((DEBUG_ERROR, "Image type %s can't be loaded on %s UEFI system.\n",
+ DEBUG ((
+ DEBUG_ERROR,
+ "Image type %s can't be loaded on %s UEFI system.\n",
GetMachineTypeName (Image->ImageContext.Machine),
- GetMachineTypeName (mDxeCoreImageMachineType)));
+ GetMachineTypeName (mDxeCoreImageMachineType)
+ ));
return EFI_UNSUPPORTED;
}
@@ -594,22 +615,22 @@ CoreLoadPeImage ( // Set EFI memory type based on ImageType
//
switch (Image->ImageContext.ImageType) {
- case EFI_IMAGE_SUBSYSTEM_EFI_APPLICATION:
- Image->ImageContext.ImageCodeMemoryType = EfiLoaderCode;
- Image->ImageContext.ImageDataMemoryType = EfiLoaderData;
- break;
- case EFI_IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER:
- Image->ImageContext.ImageCodeMemoryType = EfiBootServicesCode;
- Image->ImageContext.ImageDataMemoryType = EfiBootServicesData;
- break;
- case EFI_IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER:
- case EFI_IMAGE_SUBSYSTEM_SAL_RUNTIME_DRIVER:
- Image->ImageContext.ImageCodeMemoryType = EfiRuntimeServicesCode;
- Image->ImageContext.ImageDataMemoryType = EfiRuntimeServicesData;
- break;
- default:
- Image->ImageContext.ImageError = IMAGE_ERROR_INVALID_SUBSYSTEM;
- return EFI_UNSUPPORTED;
+ case EFI_IMAGE_SUBSYSTEM_EFI_APPLICATION:
+ Image->ImageContext.ImageCodeMemoryType = EfiLoaderCode;
+ Image->ImageContext.ImageDataMemoryType = EfiLoaderData;
+ break;
+ case EFI_IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER:
+ Image->ImageContext.ImageCodeMemoryType = EfiBootServicesCode;
+ Image->ImageContext.ImageDataMemoryType = EfiBootServicesData;
+ break;
+ case EFI_IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER:
+ case EFI_IMAGE_SUBSYSTEM_SAL_RUNTIME_DRIVER:
+ Image->ImageContext.ImageCodeMemoryType = EfiRuntimeServicesCode;
+ Image->ImageContext.ImageDataMemoryType = EfiRuntimeServicesData;
+ break;
+ default:
+ Image->ImageContext.ImageError = IMAGE_ERROR_INVALID_SUBSYSTEM;
+ return EFI_UNSUPPORTED;
}
//
@@ -641,43 +662,46 @@ CoreLoadPeImage ( // If Loading Module At Fixed Address feature is enabled, the module should be loaded to
// a specified address.
//
- if (PcdGet64(PcdLoadModuleAtFixAddressEnable) != 0 ) {
+ if (PcdGet64 (PcdLoadModuleAtFixAddressEnable) != 0 ) {
Status = GetPeCoffImageFixLoadingAssignedAddress (&(Image->ImageContext));
- if (EFI_ERROR (Status)) {
- //
- // If the code memory is not ready, invoke CoreAllocatePage with AllocateAnyPages to load the driver.
- //
- DEBUG ((DEBUG_INFO|DEBUG_LOAD, "LOADING MODULE FIXED ERROR: Loading module at fixed address failed since specified memory is not available.\n"));
-
- Status = CoreAllocatePages (
- AllocateAnyPages,
- (EFI_MEMORY_TYPE) (Image->ImageContext.ImageCodeMemoryType),
- Image->NumberOfPages,
- &Image->ImageContext.ImageAddress
- );
+ if (EFI_ERROR (Status)) {
+ //
+ // If the code memory is not ready, invoke CoreAllocatePage with AllocateAnyPages to load the driver.
+ //
+ DEBUG ((DEBUG_INFO|DEBUG_LOAD, "LOADING MODULE FIXED ERROR: Loading module at fixed address failed since specified memory is not available.\n"));
+
+ Status = CoreAllocatePages (
+ AllocateAnyPages,
+ (EFI_MEMORY_TYPE)(Image->ImageContext.ImageCodeMemoryType),
+ Image->NumberOfPages,
+ &Image->ImageContext.ImageAddress
+ );
}
} else {
- if (Image->ImageContext.ImageAddress >= 0x100000 || Image->ImageContext.RelocationsStripped) {
+ if ((Image->ImageContext.ImageAddress >= 0x100000) || Image->ImageContext.RelocationsStripped) {
Status = CoreAllocatePages (
AllocateAddress,
- (EFI_MEMORY_TYPE) (Image->ImageContext.ImageCodeMemoryType),
+ (EFI_MEMORY_TYPE)(Image->ImageContext.ImageCodeMemoryType),
Image->NumberOfPages,
&Image->ImageContext.ImageAddress
);
}
+
if (EFI_ERROR (Status) && !Image->ImageContext.RelocationsStripped) {
Status = CoreAllocatePages (
AllocateAnyPages,
- (EFI_MEMORY_TYPE) (Image->ImageContext.ImageCodeMemoryType),
+ (EFI_MEMORY_TYPE)(Image->ImageContext.ImageCodeMemoryType),
Image->NumberOfPages,
&Image->ImageContext.ImageAddress
);
}
}
+
if (EFI_ERROR (Status)) {
return Status;
}
+
DstBufAlocated = TRUE;
} else {
//
@@ -693,22 +717,23 @@ CoreLoadPeImage ( return EFI_INVALID_PARAMETER;
}
- if (Image->NumberOfPages != 0 &&
- Image->NumberOfPages <
- (EFI_SIZE_TO_PAGES ((UINTN)Image->ImageContext.ImageSize + Image->ImageContext.SectionAlignment))) {
+ if ((Image->NumberOfPages != 0) &&
+ (Image->NumberOfPages <
+ (EFI_SIZE_TO_PAGES ((UINTN)Image->ImageContext.ImageSize + Image->ImageContext.SectionAlignment))))
+ {
Image->NumberOfPages = EFI_SIZE_TO_PAGES ((UINTN)Image->ImageContext.ImageSize + Image->ImageContext.SectionAlignment);
return EFI_BUFFER_TOO_SMALL;
}
- Image->NumberOfPages = EFI_SIZE_TO_PAGES ((UINTN)Image->ImageContext.ImageSize + Image->ImageContext.SectionAlignment);
+ Image->NumberOfPages = EFI_SIZE_TO_PAGES ((UINTN)Image->ImageContext.ImageSize + Image->ImageContext.SectionAlignment);
Image->ImageContext.ImageAddress = DstBuffer;
}
Image->ImageBasePage = Image->ImageContext.ImageAddress;
if (!Image->ImageContext.IsTeImage) {
Image->ImageContext.ImageAddress =
- (Image->ImageContext.ImageAddress + Image->ImageContext.SectionAlignment - 1) &
- ~((UINTN)Image->ImageContext.SectionAlignment - 1);
+ (Image->ImageContext.ImageAddress + Image->ImageContext.SectionAlignment - 1) &
+ ~((UINTN)Image->ImageContext.SectionAlignment - 1);
}
//
@@ -755,7 +780,7 @@ CoreLoadPeImage ( //
// Get the image entry point.
//
- Image->EntryPoint = (EFI_IMAGE_ENTRY_POINT)(UINTN)Image->ImageContext.EntryPoint;
+ Image->EntryPoint = (EFI_IMAGE_ENTRY_POINT)(UINTN)Image->ImageContext.EntryPoint;
//
// Fill in the image information for the Loaded Image Protocol
@@ -763,19 +788,20 @@ CoreLoadPeImage ( Image->Type = Image->ImageContext.ImageType;
Image->Info.ImageBase = (VOID *)(UINTN)Image->ImageContext.ImageAddress;
Image->Info.ImageSize = Image->ImageContext.ImageSize;
- Image->Info.ImageCodeType = (EFI_MEMORY_TYPE) (Image->ImageContext.ImageCodeMemoryType);
- Image->Info.ImageDataType = (EFI_MEMORY_TYPE) (Image->ImageContext.ImageDataMemoryType);
+ Image->Info.ImageCodeType = (EFI_MEMORY_TYPE)(Image->ImageContext.ImageCodeMemoryType);
+ Image->Info.ImageDataType = (EFI_MEMORY_TYPE)(Image->ImageContext.ImageDataMemoryType);
if ((Attribute & EFI_LOAD_PE_IMAGE_ATTRIBUTE_RUNTIME_REGISTRATION) != 0) {
if (Image->ImageContext.ImageType == EFI_IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER) {
//
// Make a list off all the RT images so we can let the RT AP know about them.
//
- Image->RuntimeData = AllocateRuntimePool (sizeof(EFI_RUNTIME_IMAGE_ENTRY));
+ Image->RuntimeData = AllocateRuntimePool (sizeof (EFI_RUNTIME_IMAGE_ENTRY));
if (Image->RuntimeData == NULL) {
goto Done;
}
+
Image->RuntimeData->ImageBase = Image->Info.ImageBase;
- Image->RuntimeData->ImageSize = (UINT64) (Image->Info.ImageSize);
+ Image->RuntimeData->ImageSize = (UINT64)(Image->Info.ImageSize);
Image->RuntimeData->RelocationData = Image->ImageContext.FixupData;
Image->RuntimeData->Handle = Image->Handle;
InsertTailList (&gRuntime->ImageHead, &Image->RuntimeData->Link);
@@ -796,53 +822,57 @@ CoreLoadPeImage ( DEBUG_CODE_BEGIN ();
- UINTN Index;
- UINTN StartIndex;
- CHAR8 EfiFileName[256];
-
+ UINTN Index;
+ UINTN StartIndex;
+ CHAR8 EfiFileName[256];
- DEBUG ((DEBUG_INFO | DEBUG_LOAD,
- "Loading driver at 0x%11p EntryPoint=0x%11p ",
- (VOID *)(UINTN) Image->ImageContext.ImageAddress,
- FUNCTION_ENTRY_POINT (Image->ImageContext.EntryPoint)));
+ DEBUG ((
+ DEBUG_INFO | DEBUG_LOAD,
+ "Loading driver at 0x%11p EntryPoint=0x%11p ",
+ (VOID *)(UINTN)Image->ImageContext.ImageAddress,
+ FUNCTION_ENTRY_POINT (Image->ImageContext.EntryPoint)
+ ));
+ //
+ // Print Module Name by Pdb file path.
+ // Windows and Unix style file path are all trimmed correctly.
+ //
+ if (Image->ImageContext.PdbPointer != NULL) {
+ StartIndex = 0;
+ for (Index = 0; Image->ImageContext.PdbPointer[Index] != 0; Index++) {
+ if ((Image->ImageContext.PdbPointer[Index] == '\\') || (Image->ImageContext.PdbPointer[Index] == '/')) {
+ StartIndex = Index + 1;
+ }
+ }
//
- // Print Module Name by Pdb file path.
- // Windows and Unix style file path are all trimmed correctly.
+ // Copy the PDB file name to our temporary string, and replace .pdb with .efi
+ // The PDB file name is limited in the range of 0~255.
+ // If the length is bigger than 255, trim the redudant characters to avoid overflow in array boundary.
//
- if (Image->ImageContext.PdbPointer != NULL) {
- StartIndex = 0;
- for (Index = 0; Image->ImageContext.PdbPointer[Index] != 0; Index++) {
- if ((Image->ImageContext.PdbPointer[Index] == '\\') || (Image->ImageContext.PdbPointer[Index] == '/')) {
- StartIndex = Index + 1;
- }
- }
- //
- // Copy the PDB file name to our temporary string, and replace .pdb with .efi
- // The PDB file name is limited in the range of 0~255.
- // If the length is bigger than 255, trim the redudant characters to avoid overflow in array boundary.
- //
- for (Index = 0; Index < sizeof (EfiFileName) - 4; Index++) {
- EfiFileName[Index] = Image->ImageContext.PdbPointer[Index + StartIndex];
- if (EfiFileName[Index] == 0) {
- EfiFileName[Index] = '.';
- }
- if (EfiFileName[Index] == '.') {
- EfiFileName[Index + 1] = 'e';
- EfiFileName[Index + 2] = 'f';
- EfiFileName[Index + 3] = 'i';
- EfiFileName[Index + 4] = 0;
- break;
- }
+ for (Index = 0; Index < sizeof (EfiFileName) - 4; Index++) {
+ EfiFileName[Index] = Image->ImageContext.PdbPointer[Index + StartIndex];
+ if (EfiFileName[Index] == 0) {
+ EfiFileName[Index] = '.';
}
- if (Index == sizeof (EfiFileName) - 4) {
- EfiFileName[Index] = 0;
+ if (EfiFileName[Index] == '.') {
+ EfiFileName[Index + 1] = 'e';
+ EfiFileName[Index + 2] = 'f';
+ EfiFileName[Index + 3] = 'i';
+ EfiFileName[Index + 4] = 0;
+ break;
}
- DEBUG ((DEBUG_INFO | DEBUG_LOAD, "%a", EfiFileName)); // &Image->ImageContext.PdbPointer[StartIndex]));
}
- DEBUG ((DEBUG_INFO | DEBUG_LOAD, "\n"));
+
+ if (Index == sizeof (EfiFileName) - 4) {
+ EfiFileName[Index] = 0;
+ }
+
+ DEBUG ((DEBUG_INFO | DEBUG_LOAD, "%a", EfiFileName)); // &Image->ImageContext.PdbPointer[StartIndex]));
+ }
+
+ DEBUG ((DEBUG_INFO | DEBUG_LOAD, "\n"));
DEBUG_CODE_END ();
@@ -857,7 +887,7 @@ Done: if (DstBufAlocated) {
CoreFreePages (Image->ImageContext.ImageAddress, Image->NumberOfPages);
Image->ImageContext.ImageAddress = 0;
- Image->ImageBasePage = 0;
+ Image->ImageBasePage = 0;
}
if (Image->ImageContext.FixupData != NULL) {
@@ -867,8 +897,6 @@ Done: return Status;
}
-
-
/**
Get the image's private data from its handle.
@@ -901,7 +929,6 @@ CoreLoadedImageInfo ( return Image;
}
-
/**
Unloads EFI image from memory.
@@ -915,18 +942,18 @@ CoreUnloadAndCloseImage ( IN BOOLEAN FreePage
)
{
- EFI_STATUS Status;
- UINTN HandleCount;
- EFI_HANDLE *HandleBuffer;
- UINTN HandleIndex;
- EFI_GUID **ProtocolGuidArray;
- UINTN ArrayCount;
- UINTN ProtocolIndex;
- EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *OpenInfo;
- UINTN OpenInfoCount;
- UINTN OpenInfoIndex;
-
- HandleBuffer = NULL;
+ EFI_STATUS Status;
+ UINTN HandleCount;
+ EFI_HANDLE *HandleBuffer;
+ UINTN HandleIndex;
+ EFI_GUID **ProtocolGuidArray;
+ UINTN ArrayCount;
+ UINTN ProtocolIndex;
+ EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *OpenInfo;
+ UINTN OpenInfoCount;
+ UINTN OpenInfoIndex;
+
+ HandleBuffer = NULL;
ProtocolGuidArray = NULL;
if (Image->Started) {
@@ -951,7 +978,6 @@ CoreUnloadAndCloseImage ( // Free our references to the image handle
//
if (Image->Handle != NULL) {
-
Status = CoreLocateHandleBuffer (
AllHandles,
NULL,
@@ -985,16 +1011,19 @@ CoreUnloadAndCloseImage ( );
}
}
+
if (OpenInfo != NULL) {
- CoreFreePool(OpenInfo);
+ CoreFreePool (OpenInfo);
}
}
}
+
if (ProtocolGuidArray != NULL) {
- CoreFreePool(ProtocolGuidArray);
+ CoreFreePool (ProtocolGuidArray);
}
}
}
+
if (HandleBuffer != NULL) {
CoreFreePool (HandleBuffer);
}
@@ -1018,10 +1047,9 @@ CoreUnloadAndCloseImage ( Status = CoreUninstallProtocolInterface (
Image->Handle,
&gEfiHiiPackageListProtocolGuid,
- (VOID *) (UINTN) Image->ImageContext.HiiResourceData
+ (VOID *)(UINTN)Image->ImageContext.HiiResourceData
);
}
-
}
if (Image->RuntimeData != NULL) {
@@ -1032,6 +1060,7 @@ CoreUnloadAndCloseImage ( RemoveEntryList (&Image->RuntimeData->Link);
RemoveImageRecord (Image->RuntimeData);
}
+
CoreFreePool (Image->RuntimeData);
}
@@ -1060,7 +1089,6 @@ CoreUnloadAndCloseImage ( CoreFreePool (Image);
}
-
/**
Loads an EFI image into memory and returns a handle to the image.
@@ -1107,16 +1135,16 @@ CoreUnloadAndCloseImage ( **/
EFI_STATUS
CoreLoadImageCommon (
- IN BOOLEAN BootPolicy,
- IN EFI_HANDLE ParentImageHandle,
- IN EFI_DEVICE_PATH_PROTOCOL *FilePath,
- IN VOID *SourceBuffer OPTIONAL,
- IN UINTN SourceSize,
- IN EFI_PHYSICAL_ADDRESS DstBuffer OPTIONAL,
- IN OUT UINTN *NumberOfPages OPTIONAL,
- OUT EFI_HANDLE *ImageHandle,
- OUT EFI_PHYSICAL_ADDRESS *EntryPoint OPTIONAL,
- IN UINT32 Attribute
+ IN BOOLEAN BootPolicy,
+ IN EFI_HANDLE ParentImageHandle,
+ IN EFI_DEVICE_PATH_PROTOCOL *FilePath,
+ IN VOID *SourceBuffer OPTIONAL,
+ IN UINTN SourceSize,
+ IN EFI_PHYSICAL_ADDRESS DstBuffer OPTIONAL,
+ IN OUT UINTN *NumberOfPages OPTIONAL,
+ OUT EFI_HANDLE *ImageHandle,
+ OUT EFI_PHYSICAL_ADDRESS *EntryPoint OPTIONAL,
+ IN UINT32 Attribute
)
{
LOADED_IMAGE_PRIVATE_DATA *Image;
@@ -1142,23 +1170,23 @@ CoreLoadImageCommon ( //
// The caller must pass in a valid ParentImageHandle
//
- if (ImageHandle == NULL || ParentImageHandle == NULL) {
+ if ((ImageHandle == NULL) || (ParentImageHandle == NULL)) {
return EFI_INVALID_PARAMETER;
}
ParentImage = CoreLoadedImageInfo (ParentImageHandle);
if (ParentImage == NULL) {
- DEBUG((DEBUG_LOAD|DEBUG_ERROR, "LoadImageEx: Parent handle not an image handle\n"));
+ DEBUG ((DEBUG_LOAD|DEBUG_ERROR, "LoadImageEx: Parent handle not an image handle\n"));
return EFI_INVALID_PARAMETER;
}
ZeroMem (&FHand, sizeof (IMAGE_FILE_HANDLE));
- FHand.Signature = IMAGE_FILE_HANDLE_SIGNATURE;
- OriginalFilePath = FilePath;
- InputFilePath = FilePath;
- HandleFilePath = FilePath;
- DeviceHandle = NULL;
- Status = EFI_SUCCESS;
+ FHand.Signature = IMAGE_FILE_HANDLE_SIGNATURE;
+ OriginalFilePath = FilePath;
+ InputFilePath = FilePath;
+ HandleFilePath = FilePath;
+ DeviceHandle = NULL;
+ Status = EFI_SUCCESS;
AuthenticationStatus = 0;
ImageIsFromFv = FALSE;
ImageIsFromLoadFile = FALSE;
@@ -1169,10 +1197,11 @@ CoreLoadImageCommon ( if (SourceBuffer != NULL) {
FHand.Source = SourceBuffer;
FHand.SourceSize = SourceSize;
- Status = CoreLocateDevicePath (&gEfiDevicePathProtocolGuid, &HandleFilePath, &DeviceHandle);
+ Status = CoreLocateDevicePath (&gEfiDevicePathProtocolGuid, &HandleFilePath, &DeviceHandle);
if (EFI_ERROR (Status)) {
DeviceHandle = NULL;
}
+
if (SourceSize > 0) {
Status = EFI_SUCCESS;
} else {
@@ -1192,18 +1221,19 @@ CoreLoadImageCommon ( ImageIsFromFv = TRUE;
} else {
HandleFilePath = FilePath;
- Status = CoreLocateDevicePath (&gEfiSimpleFileSystemProtocolGuid, &HandleFilePath, &DeviceHandle);
+ Status = CoreLocateDevicePath (&gEfiSimpleFileSystemProtocolGuid, &HandleFilePath, &DeviceHandle);
if (EFI_ERROR (Status)) {
if (!BootPolicy) {
HandleFilePath = FilePath;
- Status = CoreLocateDevicePath (&gEfiLoadFile2ProtocolGuid, &HandleFilePath, &DeviceHandle);
+ Status = CoreLocateDevicePath (&gEfiLoadFile2ProtocolGuid, &HandleFilePath, &DeviceHandle);
}
+
if (EFI_ERROR (Status)) {
HandleFilePath = FilePath;
- Status = CoreLocateDevicePath (&gEfiLoadFileProtocolGuid, &HandleFilePath, &DeviceHandle);
+ Status = CoreLocateDevicePath (&gEfiLoadFileProtocolGuid, &HandleFilePath, &DeviceHandle);
if (!EFI_ERROR (Status)) {
ImageIsFromLoadFile = TRUE;
- Node = HandleFilePath;
+ Node = HandleFilePath;
}
}
}
@@ -1213,11 +1243,11 @@ CoreLoadImageCommon ( // Get the source file buffer by its device path.
//
FHand.Source = GetFileBufferByFilePath (
- BootPolicy,
- FilePath,
- &FHand.SourceSize,
- &AuthenticationStatus
- );
+ BootPolicy,
+ FilePath,
+ &FHand.SourceSize,
+ &AuthenticationStatus
+ );
if (FHand.Source == NULL) {
Status = EFI_NOT_FOUND;
} else {
@@ -1241,12 +1271,12 @@ CoreLoadImageCommon ( // Verify File Authentication through the Security2 Architectural Protocol
//
SecurityStatus = gSecurity2->FileAuthentication (
- gSecurity2,
- OriginalFilePath,
- FHand.Source,
- FHand.SourceSize,
- BootPolicy
- );
+ gSecurity2,
+ OriginalFilePath,
+ FHand.Source,
+ FHand.SourceSize,
+ BootPolicy
+ );
if (!EFI_ERROR (SecurityStatus) && ImageIsFromFv) {
//
// When Security2 is installed, Security Architectural Protocol must be published.
@@ -1277,7 +1307,7 @@ CoreLoadImageCommon ( //
// Check Security Status.
//
- if (EFI_ERROR (SecurityStatus) && SecurityStatus != EFI_SECURITY_VIOLATION) {
+ if (EFI_ERROR (SecurityStatus) && (SecurityStatus != EFI_SECURITY_VIOLATION)) {
if (SecurityStatus == EFI_ACCESS_DENIED) {
//
// Image was not loaded because the platform policy prohibits the image from being loaded.
@@ -1285,15 +1315,16 @@ CoreLoadImageCommon ( //
*ImageHandle = NULL;
}
+
Status = SecurityStatus;
- Image = NULL;
+ Image = NULL;
goto Done;
}
//
// Allocate a new image structure
//
- Image = AllocateZeroPool (sizeof(LOADED_IMAGE_PRIVATE_DATA));
+ Image = AllocateZeroPool (sizeof (LOADED_IMAGE_PRIVATE_DATA));
if (Image == NULL) {
Status = EFI_OUT_OF_RESOURCES;
goto Done;
@@ -1306,10 +1337,11 @@ CoreLoadImageCommon ( if (DeviceHandle != NULL) {
Status = CoreHandleProtocol (DeviceHandle, &gEfiDevicePathProtocolGuid, (VOID **)&HandleFilePath);
if (!EFI_ERROR (Status)) {
- FilePathSize = GetDevicePathSize (HandleFilePath) - sizeof(EFI_DEVICE_PATH_PROTOCOL);
- FilePath = (EFI_DEVICE_PATH_PROTOCOL *) (((UINT8 *)FilePath) + FilePathSize );
+ FilePathSize = GetDevicePathSize (HandleFilePath) - sizeof (EFI_DEVICE_PATH_PROTOCOL);
+ FilePath = (EFI_DEVICE_PATH_PROTOCOL *)(((UINT8 *)FilePath) + FilePathSize);
}
}
+
//
// Initialize the fields for an internal driver
//
@@ -1320,11 +1352,10 @@ CoreLoadImageCommon ( Image->Info.FilePath = DuplicateDevicePath (FilePath);
Image->Info.ParentHandle = ParentImageHandle;
-
if (NumberOfPages != NULL) {
- Image->NumberOfPages = *NumberOfPages ;
+ Image->NumberOfPages = *NumberOfPages;
} else {
- Image->NumberOfPages = 0 ;
+ Image->NumberOfPages = 0;
}
//
@@ -1352,6 +1383,7 @@ CoreLoadImageCommon ( *NumberOfPages = Image->NumberOfPages;
}
}
+
goto Done;
}
@@ -1367,7 +1399,7 @@ CoreLoadImageCommon ( }
//
- //Reinstall loaded image protocol to fire any notifications
+ // Reinstall loaded image protocol to fire any notifications
//
Status = CoreReinstallProtocolInterface (
Image->Handle,
@@ -1391,11 +1423,11 @@ CoreLoadImageCommon ( // Install Loaded Image Device Path Protocol onto the image handle of a PE/COFE image
//
Status = CoreInstallProtocolInterface (
- &Image->Handle,
- &gEfiLoadedImageDevicePathProtocolGuid,
- EFI_NATIVE_INTERFACE,
- Image->LoadedImageDevicePath
- );
+ &Image->Handle,
+ &gEfiLoadedImageDevicePathProtocolGuid,
+ EFI_NATIVE_INTERFACE,
+ Image->LoadedImageDevicePath
+ );
if (EFI_ERROR (Status)) {
goto Done;
}
@@ -1408,12 +1440,13 @@ CoreLoadImageCommon ( &Image->Handle,
&gEfiHiiPackageListProtocolGuid,
EFI_NATIVE_INTERFACE,
- (VOID *) (UINTN) Image->ImageContext.HiiResourceData
+ (VOID *)(UINTN)Image->ImageContext.HiiResourceData
);
if (EFI_ERROR (Status)) {
goto Done;
}
}
+
ProtectUefiImage (&Image->Info, Image->LoadedImageDevicePath);
//
@@ -1429,6 +1462,7 @@ Done: if (FHand.FreeBuffer) {
CoreFreePool (FHand.Source);
}
+
if (OriginalFilePath != InputFilePath) {
CoreFreePool (OriginalFilePath);
}
@@ -1455,9 +1489,6 @@ Done: return Status;
}
-
-
-
/**
Loads an EFI image into memory and returns a handle to the image.
@@ -1495,16 +1526,16 @@ Done: EFI_STATUS
EFIAPI
CoreLoadImage (
- IN BOOLEAN BootPolicy,
- IN EFI_HANDLE ParentImageHandle,
- IN EFI_DEVICE_PATH_PROTOCOL *FilePath,
- IN VOID *SourceBuffer OPTIONAL,
- IN UINTN SourceSize,
- OUT EFI_HANDLE *ImageHandle
+ IN BOOLEAN BootPolicy,
+ IN EFI_HANDLE ParentImageHandle,
+ IN EFI_DEVICE_PATH_PROTOCOL *FilePath,
+ IN VOID *SourceBuffer OPTIONAL,
+ IN UINTN SourceSize,
+ OUT EFI_HANDLE *ImageHandle
)
{
- EFI_STATUS Status;
- EFI_HANDLE Handle;
+ EFI_STATUS Status;
+ EFI_HANDLE Handle;
PERF_LOAD_IMAGE_BEGIN (NULL);
@@ -1514,7 +1545,7 @@ CoreLoadImage ( FilePath,
SourceBuffer,
SourceSize,
- (EFI_PHYSICAL_ADDRESS) (UINTN) NULL,
+ (EFI_PHYSICAL_ADDRESS)(UINTN)NULL,
NULL,
ImageHandle,
NULL,
@@ -1561,19 +1592,20 @@ CoreStartImage ( OUT CHAR16 **ExitData OPTIONAL
)
{
- EFI_STATUS Status;
- LOADED_IMAGE_PRIVATE_DATA *Image;
- LOADED_IMAGE_PRIVATE_DATA *LastImage;
- UINT64 HandleDatabaseKey;
- UINTN SetJumpFlag;
- EFI_HANDLE Handle;
+ EFI_STATUS Status;
+ LOADED_IMAGE_PRIVATE_DATA *Image;
+ LOADED_IMAGE_PRIVATE_DATA *LastImage;
+ UINT64 HandleDatabaseKey;
+ UINTN SetJumpFlag;
+ EFI_HANDLE Handle;
Handle = ImageHandle;
Image = CoreLoadedImageInfo (ImageHandle);
- if (Image == NULL || Image->Started) {
+ if ((Image == NULL) || Image->Started) {
return EFI_INVALID_PARAMETER;
}
+
if (EFI_ERROR (Image->LoadImageStatus)) {
return Image->LoadImageStatus;
}
@@ -1582,32 +1614,36 @@ CoreStartImage ( // The image to be started must have the machine type supported by DxeCore.
//
if (!EFI_IMAGE_MACHINE_TYPE_SUPPORTED (Image->Machine) &&
- Image->PeCoffEmu == NULL) {
+ (Image->PeCoffEmu == NULL))
+ {
//
// Do not ASSERT here, because image might be loaded via EFI_IMAGE_MACHINE_CROSS_TYPE_SUPPORTED
// But it can not be started.
//
- DEBUG ((DEBUG_ERROR, "Image type %s can't be started ", GetMachineTypeName(Image->Machine)));
- DEBUG ((DEBUG_ERROR, "on %s UEFI system.\n", GetMachineTypeName(mDxeCoreImageMachineType)));
+ DEBUG ((DEBUG_ERROR, "Image type %s can't be started ", GetMachineTypeName (Image->Machine)));
+ DEBUG ((DEBUG_ERROR, "on %s UEFI system.\n", GetMachineTypeName (mDxeCoreImageMachineType)));
return EFI_UNSUPPORTED;
}
if (Image->PeCoffEmu != NULL) {
- Status = Image->PeCoffEmu->RegisterImage (Image->PeCoffEmu,
+ Status = Image->PeCoffEmu->RegisterImage (
+ Image->PeCoffEmu,
Image->ImageBasePage,
EFI_PAGES_TO_SIZE (Image->NumberOfPages),
- &Image->EntryPoint);
+ &Image->EntryPoint
+ );
if (EFI_ERROR (Status)) {
- DEBUG ((DEBUG_LOAD | DEBUG_ERROR,
+ DEBUG ((
+ DEBUG_LOAD | DEBUG_ERROR,
"CoreLoadPeImage: Failed to register foreign image with emulator - %r\n",
- Status));
+ Status
+ ));
return Status;
}
}
PERF_START_IMAGE_BEGIN (Handle);
-
//
// Push the current start image context, and
// link the current image to the head. This is the
@@ -1638,6 +1674,7 @@ CoreStartImage ( return EFI_OUT_OF_RESOURCES;
}
+
Image->JumpContext = ALIGN_POINTER (Image->JumpBuffer, BASE_LIBRARY_JUMP_BUFFER_ALIGNMENT);
SetJumpFlag = SetJump (Image->JumpContext);
@@ -1651,7 +1688,7 @@ CoreStartImage ( // Call the image's entry point
//
Image->Started = TRUE;
- Image->Status = Image->EntryPoint (ImageHandle, Image->Info.SystemTable);
+ Image->Status = Image->EntryPoint (ImageHandle, Image->Info.SystemTable);
//
// Add some debug information if the image returned with error.
@@ -1659,9 +1696,10 @@ CoreStartImage ( // all the resource in this situation.
//
DEBUG_CODE_BEGIN ();
- if (EFI_ERROR (Image->Status)) {
- DEBUG ((DEBUG_ERROR, "Error: Image at %11p start failed: %r\n", Image->Info.ImageBase, Image->Status));
- }
+ if (EFI_ERROR (Image->Status)) {
+ DEBUG ((DEBUG_ERROR, "Error: Image at %11p start failed: %r\n", Image->Info.ImageBase, Image->Status));
+ }
+
DEBUG_CODE_END ();
//
@@ -1700,20 +1738,21 @@ CoreStartImage ( // Handle the image's returned ExitData
//
DEBUG_CODE_BEGIN ();
- if (Image->ExitDataSize != 0 || Image->ExitData != NULL) {
-
- DEBUG ((DEBUG_LOAD, "StartImage: ExitDataSize %d, ExitData %p", (UINT32)Image->ExitDataSize, Image->ExitData));
- if (Image->ExitData != NULL) {
- DEBUG ((DEBUG_LOAD, " (%hs)", Image->ExitData));
- }
- DEBUG ((DEBUG_LOAD, "\n"));
+ if ((Image->ExitDataSize != 0) || (Image->ExitData != NULL)) {
+ DEBUG ((DEBUG_LOAD, "StartImage: ExitDataSize %d, ExitData %p", (UINT32)Image->ExitDataSize, Image->ExitData));
+ if (Image->ExitData != NULL) {
+ DEBUG ((DEBUG_LOAD, " (%hs)", Image->ExitData));
}
+
+ DEBUG ((DEBUG_LOAD, "\n"));
+ }
+
DEBUG_CODE_END ();
//
// Return the exit data to the caller
//
- if (ExitData != NULL && ExitDataSize != NULL) {
+ if ((ExitData != NULL) && (ExitDataSize != NULL)) {
*ExitDataSize = Image->ExitDataSize;
*ExitData = Image->ExitData;
} else {
@@ -1733,7 +1772,7 @@ CoreStartImage ( // If the image returned an error, or if the image is an application
// unload it
//
- if (EFI_ERROR (Image->Status) || Image->Type == EFI_IMAGE_SUBSYSTEM_EFI_APPLICATION) {
+ if (EFI_ERROR (Image->Status) || (Image->Type == EFI_IMAGE_SUBSYSTEM_EFI_APPLICATION)) {
CoreUnloadAndCloseImage (Image, TRUE);
//
// ImageHandle may be invalid after the image is unloaded, so use NULL handle to record perf log.
@@ -1823,11 +1862,12 @@ CoreExit ( //
if (ExitData != NULL) {
Image->ExitDataSize = ExitDataSize;
- Image->ExitData = AllocatePool (Image->ExitDataSize);
+ Image->ExitData = AllocatePool (Image->ExitDataSize);
if (Image->ExitData == NULL) {
Status = EFI_OUT_OF_RESOURCES;
goto Done;
}
+
CopyMem (Image->ExitData, ExitData, Image->ExitDataSize);
}
@@ -1847,9 +1887,6 @@ Done: return Status;
}
-
-
-
/**
Unloads an image.
@@ -1888,7 +1925,6 @@ CoreUnloadImage ( if (Image->Info.Unload != NULL) {
Status = Image->Info.Unload (ImageHandle);
}
-
} else {
//
// This Image hasn't been started, thus it can be unloaded
@@ -1896,7 +1932,6 @@ CoreUnloadImage ( Status = EFI_SUCCESS;
}
-
if (!EFI_ERROR (Status)) {
//
// if the Image was not started or Unloaded O.K. then clean up
diff --git a/MdeModulePkg/Core/Dxe/Image/Image.h b/MdeModulePkg/Core/Dxe/Image/Image.h index e9c44ab2a7..7e4175e562 100644 --- a/MdeModulePkg/Core/Dxe/Image/Image.h +++ b/MdeModulePkg/Core/Dxe/Image/Image.h @@ -6,19 +6,18 @@ SPDX-License-Identifier: BSD-2-Clause-Patent **/
-
#ifndef _IMAGE_H_
#define _IMAGE_H_
//
// Private Data Types
//
-#define IMAGE_FILE_HANDLE_SIGNATURE SIGNATURE_32('i','m','g','f')
+#define IMAGE_FILE_HANDLE_SIGNATURE SIGNATURE_32('i','m','g','f')
typedef struct {
- UINTN Signature;
- BOOLEAN FreeBuffer;
- VOID *Source;
- UINTN SourceSize;
+ UINTN Signature;
+ BOOLEAN FreeBuffer;
+ VOID *Source;
+ UINTN SourceSize;
} IMAGE_FILE_HANDLE;
#endif
diff --git a/MdeModulePkg/Core/Dxe/Library/Library.c b/MdeModulePkg/Core/Dxe/Library/Library.c index b7f0781ed7..63cef1daca 100644 --- a/MdeModulePkg/Core/Dxe/Library/Library.c +++ b/MdeModulePkg/Core/Dxe/Library/Library.c @@ -11,6 +11,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent //
// Lock Stuff
//
+
/**
Initialize a basic mutual exclusion lock. Each lock
provides mutual exclusion access at it's task priority
@@ -45,8 +46,6 @@ CoreAcquireLockOrFail ( return EFI_SUCCESS;
}
-
-
/**
Raising to the task priority level of the mutual exclusion
lock, and then acquires ownership of the lock.
@@ -68,8 +67,6 @@ CoreAcquireLock ( Lock->Lock = EfiLockAcquired;
}
-
-
/**
Releases ownership of the mutual exclusion lock, and
restores the previous task priority level.
@@ -84,7 +81,7 @@ CoreReleaseLock ( IN EFI_LOCK *Lock
)
{
- EFI_TPL Tpl;
+ EFI_TPL Tpl;
ASSERT (Lock != NULL);
ASSERT (Lock->Lock == EfiLockAcquired);
@@ -95,6 +92,3 @@ CoreReleaseLock ( CoreRestoreTpl (Tpl);
}
-
-
-
diff --git a/MdeModulePkg/Core/Dxe/Mem/HeapGuard.c b/MdeModulePkg/Core/Dxe/Mem/HeapGuard.c index b4cb48843f..9377f620c5 100644 --- a/MdeModulePkg/Core/Dxe/Mem/HeapGuard.c +++ b/MdeModulePkg/Core/Dxe/Mem/HeapGuard.c @@ -14,34 +14,34 @@ SPDX-License-Identifier: BSD-2-Clause-Patent // Global to avoid infinite reentrance of memory allocation when updating
// page table attributes, which may need allocate pages for new PDE/PTE.
//
-GLOBAL_REMOVE_IF_UNREFERENCED BOOLEAN mOnGuarding = FALSE;
+GLOBAL_REMOVE_IF_UNREFERENCED BOOLEAN mOnGuarding = FALSE;
//
// Pointer to table tracking the Guarded memory with bitmap, in which '1'
// is used to indicate memory guarded. '0' might be free memory or Guard
// page itself, depending on status of memory adjacent to it.
//
-GLOBAL_REMOVE_IF_UNREFERENCED UINT64 mGuardedMemoryMap = 0;
+GLOBAL_REMOVE_IF_UNREFERENCED UINT64 mGuardedMemoryMap = 0;
//
// Current depth level of map table pointed by mGuardedMemoryMap.
// mMapLevel must be initialized at least by 1. It will be automatically
// updated according to the address of memory just tracked.
//
-GLOBAL_REMOVE_IF_UNREFERENCED UINTN mMapLevel = 1;
+GLOBAL_REMOVE_IF_UNREFERENCED UINTN mMapLevel = 1;
//
// Shift and mask for each level of map table
//
-GLOBAL_REMOVE_IF_UNREFERENCED UINTN mLevelShift[GUARDED_HEAP_MAP_TABLE_DEPTH]
- = GUARDED_HEAP_MAP_TABLE_DEPTH_SHIFTS;
-GLOBAL_REMOVE_IF_UNREFERENCED UINTN mLevelMask[GUARDED_HEAP_MAP_TABLE_DEPTH]
- = GUARDED_HEAP_MAP_TABLE_DEPTH_MASKS;
+GLOBAL_REMOVE_IF_UNREFERENCED UINTN mLevelShift[GUARDED_HEAP_MAP_TABLE_DEPTH]
+ = GUARDED_HEAP_MAP_TABLE_DEPTH_SHIFTS;
+GLOBAL_REMOVE_IF_UNREFERENCED UINTN mLevelMask[GUARDED_HEAP_MAP_TABLE_DEPTH]
+ = GUARDED_HEAP_MAP_TABLE_DEPTH_MASKS;
//
// Used for promoting freed but not used pages.
//
-GLOBAL_REMOVE_IF_UNREFERENCED EFI_PHYSICAL_ADDRESS mLastPromotedPage = BASE_4GB;
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_PHYSICAL_ADDRESS mLastPromotedPage = BASE_4GB;
/**
Set corresponding bits in bitmap table to 1 according to the address.
@@ -55,29 +55,29 @@ GLOBAL_REMOVE_IF_UNREFERENCED EFI_PHYSICAL_ADDRESS mLastPromotedPage = BASE_4GB; STATIC
VOID
SetBits (
- IN EFI_PHYSICAL_ADDRESS Address,
- IN UINTN BitNumber,
- IN UINT64 *BitMap
+ IN EFI_PHYSICAL_ADDRESS Address,
+ IN UINTN BitNumber,
+ IN UINT64 *BitMap
)
{
- UINTN Lsbs;
- UINTN Qwords;
- UINTN Msbs;
- UINTN StartBit;
- UINTN EndBit;
+ UINTN Lsbs;
+ UINTN Qwords;
+ UINTN Msbs;
+ UINTN StartBit;
+ UINTN EndBit;
- StartBit = (UINTN)GUARDED_HEAP_MAP_ENTRY_BIT_INDEX (Address);
- EndBit = (StartBit + BitNumber - 1) % GUARDED_HEAP_MAP_ENTRY_BITS;
+ StartBit = (UINTN)GUARDED_HEAP_MAP_ENTRY_BIT_INDEX (Address);
+ EndBit = (StartBit + BitNumber - 1) % GUARDED_HEAP_MAP_ENTRY_BITS;
if ((StartBit + BitNumber) >= GUARDED_HEAP_MAP_ENTRY_BITS) {
- Msbs = (GUARDED_HEAP_MAP_ENTRY_BITS - StartBit) %
- GUARDED_HEAP_MAP_ENTRY_BITS;
- Lsbs = (EndBit + 1) % GUARDED_HEAP_MAP_ENTRY_BITS;
- Qwords = (BitNumber - Msbs) / GUARDED_HEAP_MAP_ENTRY_BITS;
+ Msbs = (GUARDED_HEAP_MAP_ENTRY_BITS - StartBit) %
+ GUARDED_HEAP_MAP_ENTRY_BITS;
+ Lsbs = (EndBit + 1) % GUARDED_HEAP_MAP_ENTRY_BITS;
+ Qwords = (BitNumber - Msbs) / GUARDED_HEAP_MAP_ENTRY_BITS;
} else {
- Msbs = BitNumber;
- Lsbs = 0;
- Qwords = 0;
+ Msbs = BitNumber;
+ Lsbs = 0;
+ Qwords = 0;
}
if (Msbs > 0) {
@@ -86,8 +86,11 @@ SetBits ( }
if (Qwords > 0) {
- SetMem64 ((VOID *)BitMap, Qwords * GUARDED_HEAP_MAP_ENTRY_BYTES,
- (UINT64)-1);
+ SetMem64 (
+ (VOID *)BitMap,
+ Qwords * GUARDED_HEAP_MAP_ENTRY_BYTES,
+ (UINT64)-1
+ );
BitMap += Qwords;
}
@@ -108,29 +111,29 @@ SetBits ( STATIC
VOID
ClearBits (
- IN EFI_PHYSICAL_ADDRESS Address,
- IN UINTN BitNumber,
- IN UINT64 *BitMap
+ IN EFI_PHYSICAL_ADDRESS Address,
+ IN UINTN BitNumber,
+ IN UINT64 *BitMap
)
{
- UINTN Lsbs;
- UINTN Qwords;
- UINTN Msbs;
- UINTN StartBit;
- UINTN EndBit;
+ UINTN Lsbs;
+ UINTN Qwords;
+ UINTN Msbs;
+ UINTN StartBit;
+ UINTN EndBit;
- StartBit = (UINTN)GUARDED_HEAP_MAP_ENTRY_BIT_INDEX (Address);
- EndBit = (StartBit + BitNumber - 1) % GUARDED_HEAP_MAP_ENTRY_BITS;
+ StartBit = (UINTN)GUARDED_HEAP_MAP_ENTRY_BIT_INDEX (Address);
+ EndBit = (StartBit + BitNumber - 1) % GUARDED_HEAP_MAP_ENTRY_BITS;
if ((StartBit + BitNumber) >= GUARDED_HEAP_MAP_ENTRY_BITS) {
- Msbs = (GUARDED_HEAP_MAP_ENTRY_BITS - StartBit) %
- GUARDED_HEAP_MAP_ENTRY_BITS;
- Lsbs = (EndBit + 1) % GUARDED_HEAP_MAP_ENTRY_BITS;
- Qwords = (BitNumber - Msbs) / GUARDED_HEAP_MAP_ENTRY_BITS;
+ Msbs = (GUARDED_HEAP_MAP_ENTRY_BITS - StartBit) %
+ GUARDED_HEAP_MAP_ENTRY_BITS;
+ Lsbs = (EndBit + 1) % GUARDED_HEAP_MAP_ENTRY_BITS;
+ Qwords = (BitNumber - Msbs) / GUARDED_HEAP_MAP_ENTRY_BITS;
} else {
- Msbs = BitNumber;
- Lsbs = 0;
- Qwords = 0;
+ Msbs = BitNumber;
+ Lsbs = 0;
+ Qwords = 0;
}
if (Msbs > 0) {
@@ -163,21 +166,21 @@ ClearBits ( STATIC
UINT64
GetBits (
- IN EFI_PHYSICAL_ADDRESS Address,
- IN UINTN BitNumber,
- IN UINT64 *BitMap
+ IN EFI_PHYSICAL_ADDRESS Address,
+ IN UINTN BitNumber,
+ IN UINT64 *BitMap
)
{
- UINTN StartBit;
- UINTN EndBit;
- UINTN Lsbs;
- UINTN Msbs;
- UINT64 Result;
+ UINTN StartBit;
+ UINTN EndBit;
+ UINTN Lsbs;
+ UINTN Msbs;
+ UINT64 Result;
ASSERT (BitNumber <= GUARDED_HEAP_MAP_ENTRY_BITS);
- StartBit = (UINTN)GUARDED_HEAP_MAP_ENTRY_BIT_INDEX (Address);
- EndBit = (StartBit + BitNumber - 1) % GUARDED_HEAP_MAP_ENTRY_BITS;
+ StartBit = (UINTN)GUARDED_HEAP_MAP_ENTRY_BIT_INDEX (Address);
+ EndBit = (StartBit + BitNumber - 1) % GUARDED_HEAP_MAP_ENTRY_BITS;
if ((StartBit + BitNumber) > GUARDED_HEAP_MAP_ENTRY_BITS) {
Msbs = GUARDED_HEAP_MAP_ENTRY_BITS - StartBit;
@@ -187,13 +190,13 @@ GetBits ( Lsbs = 0;
}
- if (StartBit == 0 && BitNumber == GUARDED_HEAP_MAP_ENTRY_BITS) {
+ if ((StartBit == 0) && (BitNumber == GUARDED_HEAP_MAP_ENTRY_BITS)) {
Result = *BitMap;
} else {
- Result = RShiftU64((*BitMap), StartBit) & (LShiftU64(1, Msbs) - 1);
+ Result = RShiftU64 ((*BitMap), StartBit) & (LShiftU64 (1, Msbs) - 1);
if (Lsbs > 0) {
- BitMap += 1;
- Result |= LShiftU64 ((*BitMap) & (LShiftU64 (1, Lsbs) - 1), Msbs);
+ BitMap += 1;
+ Result |= LShiftU64 ((*BitMap) & (LShiftU64 (1, Lsbs) - 1), Msbs);
}
}
@@ -212,18 +215,18 @@ GetBits ( **/
UINTN
FindGuardedMemoryMap (
- IN EFI_PHYSICAL_ADDRESS Address,
- IN BOOLEAN AllocMapUnit,
- OUT UINT64 **BitMap
+ IN EFI_PHYSICAL_ADDRESS Address,
+ IN BOOLEAN AllocMapUnit,
+ OUT UINT64 **BitMap
)
{
- UINTN Level;
- UINT64 *GuardMap;
- UINT64 MapMemory;
- UINTN Index;
- UINTN Size;
- UINTN BitsToUnitEnd;
- EFI_STATUS Status;
+ UINTN Level;
+ UINT64 *GuardMap;
+ UINT64 MapMemory;
+ UINTN Index;
+ UINTN Size;
+ UINTN BitsToUnitEnd;
+ EFI_STATUS Status;
MapMemory = 0;
@@ -235,50 +238,49 @@ FindGuardedMemoryMap ( RShiftU64 (
Address,
mLevelShift[GUARDED_HEAP_MAP_TABLE_DEPTH - mMapLevel - 1]
- ) != 0) {
-
+ ) != 0)
+ {
if (mGuardedMemoryMap != 0) {
Size = (mLevelMask[GUARDED_HEAP_MAP_TABLE_DEPTH - mMapLevel - 1] + 1)
* GUARDED_HEAP_MAP_ENTRY_BYTES;
Status = CoreInternalAllocatePages (
- AllocateAnyPages,
- EfiBootServicesData,
- EFI_SIZE_TO_PAGES (Size),
- &MapMemory,
- FALSE
- );
+ AllocateAnyPages,
+ EfiBootServicesData,
+ EFI_SIZE_TO_PAGES (Size),
+ &MapMemory,
+ FALSE
+ );
ASSERT_EFI_ERROR (Status);
ASSERT (MapMemory != 0);
SetMem ((VOID *)(UINTN)MapMemory, Size, 0);
*(UINT64 *)(UINTN)MapMemory = mGuardedMemoryMap;
- mGuardedMemoryMap = MapMemory;
+ mGuardedMemoryMap = MapMemory;
}
mMapLevel++;
-
}
GuardMap = &mGuardedMemoryMap;
for (Level = GUARDED_HEAP_MAP_TABLE_DEPTH - mMapLevel;
Level < GUARDED_HEAP_MAP_TABLE_DEPTH;
- ++Level) {
-
+ ++Level)
+ {
if (*GuardMap == 0) {
if (!AllocMapUnit) {
GuardMap = NULL;
break;
}
- Size = (mLevelMask[Level] + 1) * GUARDED_HEAP_MAP_ENTRY_BYTES;
+ Size = (mLevelMask[Level] + 1) * GUARDED_HEAP_MAP_ENTRY_BYTES;
Status = CoreInternalAllocatePages (
- AllocateAnyPages,
- EfiBootServicesData,
- EFI_SIZE_TO_PAGES (Size),
- &MapMemory,
- FALSE
- );
+ AllocateAnyPages,
+ EfiBootServicesData,
+ EFI_SIZE_TO_PAGES (Size),
+ &MapMemory,
+ FALSE
+ );
ASSERT_EFI_ERROR (Status);
ASSERT (MapMemory != 0);
@@ -286,10 +288,9 @@ FindGuardedMemoryMap ( *GuardMap = MapMemory;
}
- Index = (UINTN)RShiftU64 (Address, mLevelShift[Level]);
- Index &= mLevelMask[Level];
- GuardMap = (UINT64 *)(UINTN)((*GuardMap) + Index * sizeof (UINT64));
-
+ Index = (UINTN)RShiftU64 (Address, mLevelShift[Level]);
+ Index &= mLevelMask[Level];
+ GuardMap = (UINT64 *)(UINTN)((*GuardMap) + Index * sizeof (UINT64));
}
BitsToUnitEnd = GUARDED_HEAP_MAP_BITS - GUARDED_HEAP_MAP_BIT_INDEX (Address);
@@ -309,13 +310,13 @@ FindGuardedMemoryMap ( VOID
EFIAPI
SetGuardedMemoryBits (
- IN EFI_PHYSICAL_ADDRESS Address,
- IN UINTN NumberOfPages
+ IN EFI_PHYSICAL_ADDRESS Address,
+ IN UINTN NumberOfPages
)
{
- UINT64 *BitMap;
- UINTN Bits;
- UINTN BitsToUnitEnd;
+ UINT64 *BitMap;
+ UINTN Bits;
+ UINTN BitsToUnitEnd;
while (NumberOfPages > 0) {
BitsToUnitEnd = FindGuardedMemoryMap (Address, TRUE, &BitMap);
@@ -325,7 +326,7 @@ SetGuardedMemoryBits ( // Cross map unit
Bits = BitsToUnitEnd;
} else {
- Bits = NumberOfPages;
+ Bits = NumberOfPages;
}
SetBits (Address, Bits, BitMap);
@@ -346,13 +347,13 @@ SetGuardedMemoryBits ( VOID
EFIAPI
ClearGuardedMemoryBits (
- IN EFI_PHYSICAL_ADDRESS Address,
- IN UINTN NumberOfPages
+ IN EFI_PHYSICAL_ADDRESS Address,
+ IN UINTN NumberOfPages
)
{
- UINT64 *BitMap;
- UINTN Bits;
- UINTN BitsToUnitEnd;
+ UINT64 *BitMap;
+ UINTN Bits;
+ UINTN BitsToUnitEnd;
while (NumberOfPages > 0) {
BitsToUnitEnd = FindGuardedMemoryMap (Address, TRUE, &BitMap);
@@ -362,7 +363,7 @@ ClearGuardedMemoryBits ( // Cross map unit
Bits = BitsToUnitEnd;
} else {
- Bits = NumberOfPages;
+ Bits = NumberOfPages;
}
ClearBits (Address, Bits, BitMap);
@@ -382,15 +383,15 @@ ClearGuardedMemoryBits ( **/
UINT64
GetGuardedMemoryBits (
- IN EFI_PHYSICAL_ADDRESS Address,
- IN UINTN NumberOfPages
+ IN EFI_PHYSICAL_ADDRESS Address,
+ IN UINTN NumberOfPages
)
{
- UINT64 *BitMap;
- UINTN Bits;
- UINT64 Result;
- UINTN Shift;
- UINTN BitsToUnitEnd;
+ UINT64 *BitMap;
+ UINTN Bits;
+ UINT64 Result;
+ UINTN Shift;
+ UINTN BitsToUnitEnd;
ASSERT (NumberOfPages <= GUARDED_HEAP_MAP_ENTRY_BITS);
@@ -401,9 +402,9 @@ GetGuardedMemoryBits ( if (NumberOfPages > BitsToUnitEnd) {
// Cross map unit
- Bits = BitsToUnitEnd;
+ Bits = BitsToUnitEnd;
} else {
- Bits = NumberOfPages;
+ Bits = NumberOfPages;
}
if (BitMap != NULL) {
@@ -428,15 +429,18 @@ GetGuardedMemoryBits ( UINTN
EFIAPI
GetGuardMapBit (
- IN EFI_PHYSICAL_ADDRESS Address
+ IN EFI_PHYSICAL_ADDRESS Address
)
{
- UINT64 *GuardMap;
+ UINT64 *GuardMap;
FindGuardedMemoryMap (Address, FALSE, &GuardMap);
if (GuardMap != NULL) {
- if (RShiftU64 (*GuardMap,
- GUARDED_HEAP_MAP_ENTRY_BIT_INDEX (Address)) & 1) {
+ if (RShiftU64 (
+ *GuardMap,
+ GUARDED_HEAP_MAP_ENTRY_BIT_INDEX (Address)
+ ) & 1)
+ {
return 1;
}
}
@@ -444,7 +448,6 @@ GetGuardMapBit ( return 0;
}
-
/**
Check to see if the page at the given address is a Guard page or not.
@@ -456,10 +459,10 @@ GetGuardMapBit ( BOOLEAN
EFIAPI
IsGuardPage (
- IN EFI_PHYSICAL_ADDRESS Address
+ IN EFI_PHYSICAL_ADDRESS Address
)
{
- UINT64 BitMap;
+ UINT64 BitMap;
//
// There must be at least one guarded page before and/or after given
@@ -470,7 +473,6 @@ IsGuardPage ( return ((BitMap == BIT0) || (BitMap == BIT2) || (BitMap == (BIT2 | BIT0)));
}
-
/**
Check to see if the page at the given address is guarded or not.
@@ -482,7 +484,7 @@ IsGuardPage ( BOOLEAN
EFIAPI
IsMemoryGuarded (
- IN EFI_PHYSICAL_ADDRESS Address
+ IN EFI_PHYSICAL_ADDRESS Address
)
{
return (GetGuardMapBit (Address) == 1);
@@ -500,10 +502,10 @@ IsMemoryGuarded ( VOID
EFIAPI
SetGuardPage (
- IN EFI_PHYSICAL_ADDRESS BaseAddress
+ IN EFI_PHYSICAL_ADDRESS BaseAddress
)
{
- EFI_STATUS Status;
+ EFI_STATUS Status;
if (gCpu == NULL) {
return;
@@ -535,11 +537,11 @@ SetGuardPage ( VOID
EFIAPI
UnsetGuardPage (
- IN EFI_PHYSICAL_ADDRESS BaseAddress
+ IN EFI_PHYSICAL_ADDRESS BaseAddress
)
{
- UINT64 Attributes;
- EFI_STATUS Status;
+ UINT64 Attributes;
+ EFI_STATUS Status;
if (gCpu == NULL) {
return;
@@ -583,13 +585,13 @@ UnsetGuardPage ( **/
BOOLEAN
IsMemoryTypeToGuard (
- IN EFI_MEMORY_TYPE MemoryType,
- IN EFI_ALLOCATE_TYPE AllocateType,
- IN UINT8 PageOrPool
+ IN EFI_MEMORY_TYPE MemoryType,
+ IN EFI_ALLOCATE_TYPE AllocateType,
+ IN UINT8 PageOrPool
)
{
- UINT64 TestBit;
- UINT64 ConfigBit;
+ UINT64 TestBit;
+ UINT64 ConfigBit;
if (AllocateType == AllocateAddress) {
return FALSE;
@@ -609,7 +611,7 @@ IsMemoryTypeToGuard ( if ((UINT32)MemoryType >= MEMORY_TYPE_OS_RESERVED_MIN) {
TestBit = BIT63;
- } else if ((UINT32) MemoryType >= MEMORY_TYPE_OEM_RESERVED_MIN) {
+ } else if ((UINT32)MemoryType >= MEMORY_TYPE_OEM_RESERVED_MIN) {
TestBit = BIT62;
} else if (MemoryType < EfiMaxMemoryType) {
TestBit = LShiftU64 (1, MemoryType);
@@ -633,11 +635,14 @@ IsMemoryTypeToGuard ( **/
BOOLEAN
IsPoolTypeToGuard (
- IN EFI_MEMORY_TYPE MemoryType
+ IN EFI_MEMORY_TYPE MemoryType
)
{
- return IsMemoryTypeToGuard (MemoryType, AllocateAnyPages,
- GUARD_HEAP_TYPE_POOL);
+ return IsMemoryTypeToGuard (
+ MemoryType,
+ AllocateAnyPages,
+ GUARD_HEAP_TYPE_POOL
+ );
}
/**
@@ -651,8 +656,8 @@ IsPoolTypeToGuard ( **/
BOOLEAN
IsPageTypeToGuard (
- IN EFI_MEMORY_TYPE MemoryType,
- IN EFI_ALLOCATE_TYPE AllocateType
+ IN EFI_MEMORY_TYPE MemoryType,
+ IN EFI_ALLOCATE_TYPE AllocateType
)
{
return IsMemoryTypeToGuard (MemoryType, AllocateType, GUARD_HEAP_TYPE_PAGE);
@@ -667,7 +672,7 @@ IsPageTypeToGuard ( **/
BOOLEAN
IsHeapGuardEnabled (
- UINT8 GuardType
+ UINT8 GuardType
)
{
return IsMemoryTypeToGuard (EfiMaxMemoryType, AllocateAnyPages, GuardType);
@@ -683,11 +688,11 @@ IsHeapGuardEnabled ( **/
VOID
SetGuardForMemory (
- IN EFI_PHYSICAL_ADDRESS Memory,
- IN UINTN NumberOfPages
+ IN EFI_PHYSICAL_ADDRESS Memory,
+ IN UINTN NumberOfPages
)
{
- EFI_PHYSICAL_ADDRESS GuardPage;
+ EFI_PHYSICAL_ADDRESS GuardPage;
//
// Set tail Guard
@@ -719,8 +724,8 @@ SetGuardForMemory ( **/
VOID
UnsetGuardForMemory (
- IN EFI_PHYSICAL_ADDRESS Memory,
- IN UINTN NumberOfPages
+ IN EFI_PHYSICAL_ADDRESS Memory,
+ IN UINTN NumberOfPages
)
{
EFI_PHYSICAL_ADDRESS GuardPage;
@@ -742,7 +747,7 @@ UnsetGuardForMemory ( // -------------------
// Start -> -1 -2
//
- GuardPage = Memory - EFI_PAGES_TO_SIZE (1);
+ GuardPage = Memory - EFI_PAGES_TO_SIZE (1);
GuardBitmap = GetGuardedMemoryBits (Memory - EFI_PAGES_TO_SIZE (2), 2);
if ((GuardBitmap & BIT1) == 0) {
//
@@ -775,7 +780,7 @@ UnsetGuardForMemory ( // --------------------
// +1 +0 <- End
//
- GuardPage = Memory + EFI_PAGES_TO_SIZE (NumberOfPages);
+ GuardPage = Memory + EFI_PAGES_TO_SIZE (NumberOfPages);
GuardBitmap = GetGuardedMemoryBits (GuardPage, 2);
if ((GuardBitmap & BIT0) == 0) {
//
@@ -799,7 +804,7 @@ UnsetGuardForMemory ( //
// No matter what, we just clear the mark of the Guarded memory.
//
- ClearGuardedMemoryBits(Memory, NumberOfPages);
+ ClearGuardedMemoryBits (Memory, NumberOfPages);
}
/**
@@ -818,9 +823,9 @@ UnsetGuardForMemory ( **/
UINT64
AdjustMemoryS (
- IN UINT64 Start,
- IN UINT64 Size,
- IN UINT64 SizeRequested
+ IN UINT64 Start,
+ IN UINT64 Size,
+ IN UINT64 SizeRequested
)
{
UINT64 Target;
@@ -831,7 +836,7 @@ AdjustMemoryS ( // make sure alignment of the returned pool address.
//
if ((PcdGet8 (PcdHeapGuardPropertyMask) & BIT7) == 0) {
- SizeRequested = ALIGN_VALUE(SizeRequested, 8);
+ SizeRequested = ALIGN_VALUE (SizeRequested, 8);
}
Target = Start + Size - SizeRequested;
@@ -877,8 +882,8 @@ AdjustMemoryS ( **/
VOID
AdjustMemoryF (
- IN OUT EFI_PHYSICAL_ADDRESS *Memory,
- IN OUT UINTN *NumberOfPages
+ IN OUT EFI_PHYSICAL_ADDRESS *Memory,
+ IN OUT UINTN *NumberOfPages
)
{
EFI_PHYSICAL_ADDRESS Start;
@@ -886,11 +891,11 @@ AdjustMemoryF ( UINTN PagesToFree;
UINT64 GuardBitmap;
- if (Memory == NULL || NumberOfPages == NULL || *NumberOfPages == 0) {
+ if ((Memory == NULL) || (NumberOfPages == NULL) || (*NumberOfPages == 0)) {
return;
}
- Start = *Memory;
+ Start = *Memory;
PagesToFree = *NumberOfPages;
//
@@ -906,7 +911,7 @@ AdjustMemoryF ( // Start -> -1 -2
//
MemoryToTest = Start - EFI_PAGES_TO_SIZE (2);
- GuardBitmap = GetGuardedMemoryBits (MemoryToTest, 2);
+ GuardBitmap = GetGuardedMemoryBits (MemoryToTest, 2);
if ((GuardBitmap & BIT1) == 0) {
//
// Head Guard exists.
@@ -941,7 +946,7 @@ AdjustMemoryF ( // +1 +0 <- End
//
MemoryToTest = Start + EFI_PAGES_TO_SIZE (PagesToFree);
- GuardBitmap = GetGuardedMemoryBits (MemoryToTest, 2);
+ GuardBitmap = GetGuardedMemoryBits (MemoryToTest, 2);
if ((GuardBitmap & BIT0) == 0) {
//
// Tail Guard exists.
@@ -961,8 +966,8 @@ AdjustMemoryF ( PagesToFree -= 1;
}
- *Memory = Start;
- *NumberOfPages = PagesToFree;
+ *Memory = Start;
+ *NumberOfPages = PagesToFree;
}
/**
@@ -975,8 +980,8 @@ AdjustMemoryF ( **/
VOID
AdjustMemoryA (
- IN OUT EFI_PHYSICAL_ADDRESS *Memory,
- IN OUT UINTN *NumberOfPages
+ IN OUT EFI_PHYSICAL_ADDRESS *Memory,
+ IN OUT UINTN *NumberOfPages
)
{
//
@@ -1009,12 +1014,12 @@ AdjustMemoryA ( **/
VOID *
AdjustPoolHeadA (
- IN EFI_PHYSICAL_ADDRESS Memory,
- IN UINTN NoPages,
- IN UINTN Size
+ IN EFI_PHYSICAL_ADDRESS Memory,
+ IN UINTN NoPages,
+ IN UINTN Size
)
{
- if (Memory == 0 || (PcdGet8 (PcdHeapGuardPropertyMask) & BIT7) != 0) {
+ if ((Memory == 0) || ((PcdGet8 (PcdHeapGuardPropertyMask) & BIT7) != 0)) {
//
// Pool head is put near the head Guard
//
@@ -1037,10 +1042,10 @@ AdjustPoolHeadA ( **/
VOID *
AdjustPoolHeadF (
- IN EFI_PHYSICAL_ADDRESS Memory
+ IN EFI_PHYSICAL_ADDRESS Memory
)
{
- if (Memory == 0 || (PcdGet8 (PcdHeapGuardPropertyMask) & BIT7) != 0) {
+ if ((Memory == 0) || ((PcdGet8 (PcdHeapGuardPropertyMask) & BIT7) != 0)) {
//
// Pool head is put near the head Guard
//
@@ -1103,30 +1108,31 @@ SetAllGuardPages ( VOID
)
{
- UINTN Entries[GUARDED_HEAP_MAP_TABLE_DEPTH];
- UINTN Shifts[GUARDED_HEAP_MAP_TABLE_DEPTH];
- UINTN Indices[GUARDED_HEAP_MAP_TABLE_DEPTH];
- UINT64 Tables[GUARDED_HEAP_MAP_TABLE_DEPTH];
- UINT64 Addresses[GUARDED_HEAP_MAP_TABLE_DEPTH];
- UINT64 TableEntry;
- UINT64 Address;
- UINT64 GuardPage;
- INTN Level;
- UINTN Index;
- BOOLEAN OnGuarding;
-
- if (mGuardedMemoryMap == 0 ||
- mMapLevel == 0 ||
- mMapLevel > GUARDED_HEAP_MAP_TABLE_DEPTH) {
+ UINTN Entries[GUARDED_HEAP_MAP_TABLE_DEPTH];
+ UINTN Shifts[GUARDED_HEAP_MAP_TABLE_DEPTH];
+ UINTN Indices[GUARDED_HEAP_MAP_TABLE_DEPTH];
+ UINT64 Tables[GUARDED_HEAP_MAP_TABLE_DEPTH];
+ UINT64 Addresses[GUARDED_HEAP_MAP_TABLE_DEPTH];
+ UINT64 TableEntry;
+ UINT64 Address;
+ UINT64 GuardPage;
+ INTN Level;
+ UINTN Index;
+ BOOLEAN OnGuarding;
+
+ if ((mGuardedMemoryMap == 0) ||
+ (mMapLevel == 0) ||
+ (mMapLevel > GUARDED_HEAP_MAP_TABLE_DEPTH))
+ {
return;
}
CopyMem (Entries, mLevelMask, sizeof (Entries));
CopyMem (Shifts, mLevelShift, sizeof (Shifts));
- SetMem (Tables, sizeof(Tables), 0);
- SetMem (Addresses, sizeof(Addresses), 0);
- SetMem (Indices, sizeof(Indices), 0);
+ SetMem (Tables, sizeof (Tables), 0);
+ SetMem (Addresses, sizeof (Addresses), 0);
+ SetMem (Indices, sizeof (Indices), 0);
Level = GUARDED_HEAP_MAP_TABLE_DEPTH - mMapLevel;
Tables[Level] = mGuardedMemoryMap;
@@ -1135,32 +1141,26 @@ SetAllGuardPages ( DEBUG_CODE (
DumpGuardedMemoryBitmap ();
- );
+ );
while (TRUE) {
if (Indices[Level] > Entries[Level]) {
Tables[Level] = 0;
Level -= 1;
} else {
-
- TableEntry = ((UINT64 *)(UINTN)(Tables[Level]))[Indices[Level]];
- Address = Addresses[Level];
+ TableEntry = ((UINT64 *)(UINTN)(Tables[Level]))[Indices[Level]];
+ Address = Addresses[Level];
if (TableEntry == 0) {
-
OnGuarding = FALSE;
-
} else if (Level < GUARDED_HEAP_MAP_TABLE_DEPTH - 1) {
-
- Level += 1;
- Tables[Level] = TableEntry;
- Addresses[Level] = Address;
- Indices[Level] = 0;
+ Level += 1;
+ Tables[Level] = TableEntry;
+ Addresses[Level] = Address;
+ Indices[Level] = 0;
continue;
-
} else {
-
Index = 0;
while (Index < GUARDED_HEAP_MAP_ENTRY_BITS) {
if ((TableEntry & 1) == 1) {
@@ -1169,6 +1169,7 @@ SetAllGuardPages ( } else {
GuardPage = Address - EFI_PAGE_SIZE;
}
+
OnGuarding = TRUE;
} else {
if (OnGuarding) {
@@ -1176,6 +1177,7 @@ SetAllGuardPages ( } else {
GuardPage = 0;
}
+
OnGuarding = FALSE;
}
@@ -1198,10 +1200,9 @@ SetAllGuardPages ( break;
}
- Indices[Level] += 1;
- Address = (Level == 0) ? 0 : Addresses[Level - 1];
- Addresses[Level] = Address | LShiftU64(Indices[Level], Shifts[Level]);
-
+ Indices[Level] += 1;
+ Address = (Level == 0) ? 0 : Addresses[Level - 1];
+ Addresses[Level] = Address | LShiftU64 (Indices[Level], Shifts[Level]);
}
}
@@ -1214,31 +1215,32 @@ SetAllGuardPages ( **/
VOID
GetLastGuardedFreePageAddress (
- OUT EFI_PHYSICAL_ADDRESS *Address
+ OUT EFI_PHYSICAL_ADDRESS *Address
)
{
- EFI_PHYSICAL_ADDRESS AddressGranularity;
- EFI_PHYSICAL_ADDRESS BaseAddress;
- UINTN Level;
- UINT64 Map;
- INTN Index;
+ EFI_PHYSICAL_ADDRESS AddressGranularity;
+ EFI_PHYSICAL_ADDRESS BaseAddress;
+ UINTN Level;
+ UINT64 Map;
+ INTN Index;
ASSERT (mMapLevel >= 1);
BaseAddress = 0;
- Map = mGuardedMemoryMap;
+ Map = mGuardedMemoryMap;
for (Level = GUARDED_HEAP_MAP_TABLE_DEPTH - mMapLevel;
Level < GUARDED_HEAP_MAP_TABLE_DEPTH;
- ++Level) {
+ ++Level)
+ {
AddressGranularity = LShiftU64 (1, mLevelShift[Level]);
//
// Find the non-NULL entry at largest index.
//
- for (Index = (INTN)mLevelMask[Level]; Index >= 0 ; --Index) {
+ for (Index = (INTN)mLevelMask[Level]; Index >= 0; --Index) {
if (((UINT64 *)(UINTN)Map)[Index] != 0) {
BaseAddress += MultU64x32 (AddressGranularity, (UINT32)Index);
- Map = ((UINT64 *)(UINTN)Map)[Index];
+ Map = ((UINT64 *)(UINTN)Map)[Index];
break;
}
}
@@ -1248,7 +1250,7 @@ GetLastGuardedFreePageAddress ( // Find the non-zero MSB then get the page address.
//
while (Map != 0) {
- Map = RShiftU64 (Map, 1);
+ Map = RShiftU64 (Map, 1);
BaseAddress += EFI_PAGES_TO_SIZE (1);
}
@@ -1265,8 +1267,8 @@ GetLastGuardedFreePageAddress ( **/
VOID
MarkFreedPages (
- IN EFI_PHYSICAL_ADDRESS BaseAddress,
- IN UINTN Pages
+ IN EFI_PHYSICAL_ADDRESS BaseAddress,
+ IN UINTN Pages
)
{
SetGuardedMemoryBits (BaseAddress, Pages);
@@ -1283,11 +1285,11 @@ MarkFreedPages ( VOID
EFIAPI
GuardFreedPages (
- IN EFI_PHYSICAL_ADDRESS BaseAddress,
- IN UINTN Pages
+ IN EFI_PHYSICAL_ADDRESS BaseAddress,
+ IN UINTN Pages
)
{
- EFI_STATUS Status;
+ EFI_STATUS Status;
//
// Legacy memory lower than 1MB might be accessed with no allocation. Leave
@@ -1322,6 +1324,7 @@ GuardFreedPages ( if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_WARN, "Failed to guard freed pages: %p (%lu)\n", BaseAddress, (UINT64)Pages));
}
+
mOnGuarding = FALSE;
}
}
@@ -1337,8 +1340,8 @@ GuardFreedPages ( VOID
EFIAPI
GuardFreedPagesChecked (
- IN EFI_PHYSICAL_ADDRESS BaseAddress,
- IN UINTN Pages
+ IN EFI_PHYSICAL_ADDRESS BaseAddress,
+ IN UINTN Pages
)
{
if (IsHeapGuardEnabled (GUARD_HEAP_TYPE_FREED)) {
@@ -1355,30 +1358,31 @@ GuardAllFreedPages ( VOID
)
{
- UINTN Entries[GUARDED_HEAP_MAP_TABLE_DEPTH];
- UINTN Shifts[GUARDED_HEAP_MAP_TABLE_DEPTH];
- UINTN Indices[GUARDED_HEAP_MAP_TABLE_DEPTH];
- UINT64 Tables[GUARDED_HEAP_MAP_TABLE_DEPTH];
- UINT64 Addresses[GUARDED_HEAP_MAP_TABLE_DEPTH];
- UINT64 TableEntry;
- UINT64 Address;
- UINT64 GuardPage;
- INTN Level;
- UINT64 BitIndex;
- UINTN GuardPageNumber;
-
- if (mGuardedMemoryMap == 0 ||
- mMapLevel == 0 ||
- mMapLevel > GUARDED_HEAP_MAP_TABLE_DEPTH) {
+ UINTN Entries[GUARDED_HEAP_MAP_TABLE_DEPTH];
+ UINTN Shifts[GUARDED_HEAP_MAP_TABLE_DEPTH];
+ UINTN Indices[GUARDED_HEAP_MAP_TABLE_DEPTH];
+ UINT64 Tables[GUARDED_HEAP_MAP_TABLE_DEPTH];
+ UINT64 Addresses[GUARDED_HEAP_MAP_TABLE_DEPTH];
+ UINT64 TableEntry;
+ UINT64 Address;
+ UINT64 GuardPage;
+ INTN Level;
+ UINT64 BitIndex;
+ UINTN GuardPageNumber;
+
+ if ((mGuardedMemoryMap == 0) ||
+ (mMapLevel == 0) ||
+ (mMapLevel > GUARDED_HEAP_MAP_TABLE_DEPTH))
+ {
return;
}
CopyMem (Entries, mLevelMask, sizeof (Entries));
CopyMem (Shifts, mLevelShift, sizeof (Shifts));
- SetMem (Tables, sizeof(Tables), 0);
- SetMem (Addresses, sizeof(Addresses), 0);
- SetMem (Indices, sizeof(Indices), 0);
+ SetMem (Tables, sizeof (Tables), 0);
+ SetMem (Addresses, sizeof (Addresses), 0);
+ SetMem (Indices, sizeof (Indices), 0);
Level = GUARDED_HEAP_MAP_TABLE_DEPTH - mMapLevel;
Tables[Level] = mGuardedMemoryMap;
@@ -1391,14 +1395,14 @@ GuardAllFreedPages ( Tables[Level] = 0;
Level -= 1;
} else {
- TableEntry = ((UINT64 *)(UINTN)(Tables[Level]))[Indices[Level]];
- Address = Addresses[Level];
+ TableEntry = ((UINT64 *)(UINTN)(Tables[Level]))[Indices[Level]];
+ Address = Addresses[Level];
if (Level < GUARDED_HEAP_MAP_TABLE_DEPTH - 1) {
- Level += 1;
- Tables[Level] = TableEntry;
- Addresses[Level] = Address;
- Indices[Level] = 0;
+ Level += 1;
+ Tables[Level] = TableEntry;
+ Addresses[Level] = Address;
+ Indices[Level] = 0;
continue;
} else {
@@ -1408,6 +1412,7 @@ GuardAllFreedPages ( if (GuardPage == (UINT64)-1) {
GuardPage = Address;
}
+
++GuardPageNumber;
} else if (GuardPageNumber > 0) {
GuardFreedPages (GuardPage, GuardPageNumber);
@@ -1429,10 +1434,9 @@ GuardAllFreedPages ( break;
}
- Indices[Level] += 1;
- Address = (Level == 0) ? 0 : Addresses[Level - 1];
+ Indices[Level] += 1;
+ Address = (Level == 0) ? 0 : Addresses[Level - 1];
Addresses[Level] = Address | LShiftU64 (Indices[Level], Shifts[Level]);
-
}
//
@@ -1457,16 +1461,17 @@ GuardAllFreedPages ( **/
VOID
MergeGuardPages (
- IN EFI_MEMORY_DESCRIPTOR *MemoryMapEntry,
- IN EFI_PHYSICAL_ADDRESS MaxAddress
+ IN EFI_MEMORY_DESCRIPTOR *MemoryMapEntry,
+ IN EFI_PHYSICAL_ADDRESS MaxAddress
)
{
- EFI_PHYSICAL_ADDRESS EndAddress;
- UINT64 Bitmap;
- INTN Pages;
+ EFI_PHYSICAL_ADDRESS EndAddress;
+ UINT64 Bitmap;
+ INTN Pages;
if (!IsHeapGuardEnabled (GUARD_HEAP_TYPE_FREED) ||
- MemoryMapEntry->Type >= EfiMemoryMappedIO) {
+ (MemoryMapEntry->Type >= EfiMemoryMappedIO))
+ {
return;
}
@@ -1511,14 +1516,14 @@ MergeGuardPages ( **/
BOOLEAN
PromoteGuardedFreePages (
- OUT EFI_PHYSICAL_ADDRESS *StartAddress,
- OUT EFI_PHYSICAL_ADDRESS *EndAddress
+ OUT EFI_PHYSICAL_ADDRESS *StartAddress,
+ OUT EFI_PHYSICAL_ADDRESS *EndAddress
)
{
- EFI_STATUS Status;
- UINTN AvailablePages;
- UINT64 Bitmap;
- EFI_PHYSICAL_ADDRESS Start;
+ EFI_STATUS Status;
+ UINTN AvailablePages;
+ UINT64 Bitmap;
+ EFI_PHYSICAL_ADDRESS Start;
if (!IsHeapGuardEnabled (GUARD_HEAP_TYPE_FREED)) {
return FALSE;
@@ -1528,8 +1533,8 @@ PromoteGuardedFreePages ( // Similar to memory allocation service, always search the freed pages in
// descending direction.
//
- Start = mLastPromotedPage;
- AvailablePages = 0;
+ Start = mLastPromotedPage;
+ AvailablePages = 0;
while (AvailablePages == 0) {
Start -= EFI_PAGES_TO_SIZE (GUARDED_HEAP_MAP_ENTRY_BITS);
//
@@ -1565,7 +1570,7 @@ PromoteGuardedFreePages ( // operation; otherwise infinite loops could be caused.
//
mOnGuarding = TRUE;
- Status = gCpu->SetMemoryAttributes (gCpu, Start, EFI_PAGES_TO_SIZE(AvailablePages), 0);
+ Status = gCpu->SetMemoryAttributes (gCpu, Start, EFI_PAGES_TO_SIZE (AvailablePages), 0);
ASSERT_EFI_ERROR (Status);
mOnGuarding = FALSE;
}
@@ -1590,7 +1595,8 @@ HeapGuardCpuArchProtocolNotify ( ASSERT (gCpu != NULL);
if (IsHeapGuardEnabled (GUARD_HEAP_TYPE_PAGE|GUARD_HEAP_TYPE_POOL) &&
- IsHeapGuardEnabled (GUARD_HEAP_TYPE_FREED)) {
+ IsHeapGuardEnabled (GUARD_HEAP_TYPE_FREED))
+ {
DEBUG ((DEBUG_ERROR, "Heap guard and freed memory guard cannot be enabled at the same time.\n"));
CpuDeadLoop ();
}
@@ -1614,11 +1620,11 @@ HeapGuardCpuArchProtocolNotify ( **/
VOID
Uint64ToBinString (
- IN UINT64 Value,
- OUT CHAR8 *BinString
+ IN UINT64 Value,
+ OUT CHAR8 *BinString
)
{
- UINTN Index;
+ UINTN Index;
if (BinString == NULL) {
return;
@@ -1626,8 +1632,9 @@ Uint64ToBinString ( for (Index = 64; Index > 0; --Index) {
BinString[Index - 1] = '0' + (Value & 1);
- Value = RShiftU64 (Value, 1);
+ Value = RShiftU64 (Value, 1);
}
+
BinString[64] = '\0';
}
@@ -1640,44 +1647,48 @@ DumpGuardedMemoryBitmap ( VOID
)
{
- UINTN Entries[GUARDED_HEAP_MAP_TABLE_DEPTH];
- UINTN Shifts[GUARDED_HEAP_MAP_TABLE_DEPTH];
- UINTN Indices[GUARDED_HEAP_MAP_TABLE_DEPTH];
- UINT64 Tables[GUARDED_HEAP_MAP_TABLE_DEPTH];
- UINT64 Addresses[GUARDED_HEAP_MAP_TABLE_DEPTH];
- UINT64 TableEntry;
- UINT64 Address;
- INTN Level;
- UINTN RepeatZero;
- CHAR8 String[GUARDED_HEAP_MAP_ENTRY_BITS + 1];
- CHAR8 *Ruler1;
- CHAR8 *Ruler2;
+ UINTN Entries[GUARDED_HEAP_MAP_TABLE_DEPTH];
+ UINTN Shifts[GUARDED_HEAP_MAP_TABLE_DEPTH];
+ UINTN Indices[GUARDED_HEAP_MAP_TABLE_DEPTH];
+ UINT64 Tables[GUARDED_HEAP_MAP_TABLE_DEPTH];
+ UINT64 Addresses[GUARDED_HEAP_MAP_TABLE_DEPTH];
+ UINT64 TableEntry;
+ UINT64 Address;
+ INTN Level;
+ UINTN RepeatZero;
+ CHAR8 String[GUARDED_HEAP_MAP_ENTRY_BITS + 1];
+ CHAR8 *Ruler1;
+ CHAR8 *Ruler2;
if (!IsHeapGuardEnabled (GUARD_HEAP_TYPE_ALL)) {
return;
}
- if (mGuardedMemoryMap == 0 ||
- mMapLevel == 0 ||
- mMapLevel > GUARDED_HEAP_MAP_TABLE_DEPTH) {
+ if ((mGuardedMemoryMap == 0) ||
+ (mMapLevel == 0) ||
+ (mMapLevel > GUARDED_HEAP_MAP_TABLE_DEPTH))
+ {
return;
}
Ruler1 = " 3 2 1 0";
Ruler2 = "FEDCBA9876543210FEDCBA9876543210FEDCBA9876543210FEDCBA9876543210";
- DEBUG ((HEAP_GUARD_DEBUG_LEVEL, "============================="
- " Guarded Memory Bitmap "
- "==============================\r\n"));
+ DEBUG ((
+ HEAP_GUARD_DEBUG_LEVEL,
+ "============================="
+ " Guarded Memory Bitmap "
+ "==============================\r\n"
+ ));
DEBUG ((HEAP_GUARD_DEBUG_LEVEL, " %a\r\n", Ruler1));
DEBUG ((HEAP_GUARD_DEBUG_LEVEL, " %a\r\n", Ruler2));
CopyMem (Entries, mLevelMask, sizeof (Entries));
CopyMem (Shifts, mLevelShift, sizeof (Shifts));
- SetMem (Indices, sizeof(Indices), 0);
- SetMem (Tables, sizeof(Tables), 0);
- SetMem (Addresses, sizeof(Addresses), 0);
+ SetMem (Indices, sizeof (Indices), 0);
+ SetMem (Tables, sizeof (Tables), 0);
+ SetMem (Addresses, sizeof (Addresses), 0);
Level = GUARDED_HEAP_MAP_TABLE_DEPTH - mMapLevel;
Tables[Level] = mGuardedMemoryMap;
@@ -1686,7 +1697,6 @@ DumpGuardedMemoryBitmap ( while (TRUE) {
if (Indices[Level] > Entries[Level]) {
-
Tables[Level] = 0;
Level -= 1;
RepeatZero = 0;
@@ -1696,40 +1706,33 @@ DumpGuardedMemoryBitmap ( "========================================="
"=========================================\r\n"
));
-
} else {
-
- TableEntry = ((UINT64 *)(UINTN)Tables[Level])[Indices[Level]];
- Address = Addresses[Level];
+ TableEntry = ((UINT64 *)(UINTN)Tables[Level])[Indices[Level]];
+ Address = Addresses[Level];
if (TableEntry == 0) {
-
if (Level == GUARDED_HEAP_MAP_TABLE_DEPTH - 1) {
if (RepeatZero == 0) {
- Uint64ToBinString(TableEntry, String);
+ Uint64ToBinString (TableEntry, String);
DEBUG ((HEAP_GUARD_DEBUG_LEVEL, "%016lx: %a\r\n", Address, String));
} else if (RepeatZero == 1) {
DEBUG ((HEAP_GUARD_DEBUG_LEVEL, "... : ...\r\n"));
}
+
RepeatZero += 1;
}
-
} else if (Level < GUARDED_HEAP_MAP_TABLE_DEPTH - 1) {
-
- Level += 1;
- Tables[Level] = TableEntry;
- Addresses[Level] = Address;
- Indices[Level] = 0;
- RepeatZero = 0;
+ Level += 1;
+ Tables[Level] = TableEntry;
+ Addresses[Level] = Address;
+ Indices[Level] = 0;
+ RepeatZero = 0;
continue;
-
} else {
-
RepeatZero = 0;
- Uint64ToBinString(TableEntry, String);
+ Uint64ToBinString (TableEntry, String);
DEBUG ((HEAP_GUARD_DEBUG_LEVEL, "%016lx: %a\r\n", Address, String));
-
}
}
@@ -1737,10 +1740,8 @@ DumpGuardedMemoryBitmap ( break;
}
- Indices[Level] += 1;
- Address = (Level == 0) ? 0 : Addresses[Level - 1];
- Addresses[Level] = Address | LShiftU64(Indices[Level], Shifts[Level]);
-
+ Indices[Level] += 1;
+ Address = (Level == 0) ? 0 : Addresses[Level - 1];
+ Addresses[Level] = Address | LShiftU64 (Indices[Level], Shifts[Level]);
}
}
-
diff --git a/MdeModulePkg/Core/Dxe/Mem/HeapGuard.h b/MdeModulePkg/Core/Dxe/Mem/HeapGuard.h index d6e4ed39dd..9a32b4dd51 100644 --- a/MdeModulePkg/Core/Dxe/Mem/HeapGuard.h +++ b/MdeModulePkg/Core/Dxe/Mem/HeapGuard.h @@ -51,15 +51,15 @@ SPDX-License-Identifier: BSD-2-Clause-Patent // Each entry occupies 8B/64b. 1-page can hold 512 entries, which spans 9
// bits in address. (512 = 1 << 9)
//
-#define BYTE_LENGTH_SHIFT 3 // (8 = 1 << 3)
+#define BYTE_LENGTH_SHIFT 3 // (8 = 1 << 3)
#define GUARDED_HEAP_MAP_TABLE_ENTRY_SHIFT \
(EFI_PAGE_SHIFT - BYTE_LENGTH_SHIFT)
-#define GUARDED_HEAP_MAP_TABLE_DEPTH 5
+#define GUARDED_HEAP_MAP_TABLE_DEPTH 5
// Use UINT64_index + bit_index_of_UINT64 to locate the bit in may
-#define GUARDED_HEAP_MAP_ENTRY_BIT_SHIFT 6 // (64 = 1 << 6)
+#define GUARDED_HEAP_MAP_ENTRY_BIT_SHIFT 6 // (64 = 1 << 6)
#define GUARDED_HEAP_MAP_ENTRY_BITS \
(1 << GUARDED_HEAP_MAP_ENTRY_BIT_SHIFT)
@@ -152,9 +152,9 @@ SPDX-License-Identifier: BSD-2-Clause-Patent //
// Memory type to guard (matching the related PCD definition)
//
-#define GUARD_HEAP_TYPE_PAGE BIT0
-#define GUARD_HEAP_TYPE_POOL BIT1
-#define GUARD_HEAP_TYPE_FREED BIT4
+#define GUARD_HEAP_TYPE_PAGE BIT0
+#define GUARD_HEAP_TYPE_POOL BIT1
+#define GUARD_HEAP_TYPE_FREED BIT4
#define GUARD_HEAP_TYPE_ALL \
(GUARD_HEAP_TYPE_PAGE|GUARD_HEAP_TYPE_POOL|GUARD_HEAP_TYPE_FREED)
@@ -164,10 +164,10 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #define HEAP_GUARD_DEBUG_LEVEL (DEBUG_POOL|DEBUG_PAGE)
typedef struct {
- UINT32 TailMark;
- UINT32 HeadMark;
- EFI_PHYSICAL_ADDRESS Address;
- LIST_ENTRY Link;
+ UINT32 TailMark;
+ UINT32 HeadMark;
+ EFI_PHYSICAL_ADDRESS Address;
+ LIST_ENTRY Link;
} HEAP_GUARD_NODE;
/**
@@ -219,8 +219,8 @@ CoreConvertPagesWithGuard ( **/
VOID
SetGuardForMemory (
- IN EFI_PHYSICAL_ADDRESS Memory,
- IN UINTN NumberOfPages
+ IN EFI_PHYSICAL_ADDRESS Memory,
+ IN UINTN NumberOfPages
);
/**
@@ -233,8 +233,8 @@ SetGuardForMemory ( **/
VOID
UnsetGuardForMemory (
- IN EFI_PHYSICAL_ADDRESS Memory,
- IN UINTN NumberOfPages
+ IN EFI_PHYSICAL_ADDRESS Memory,
+ IN UINTN NumberOfPages
);
/**
@@ -247,8 +247,8 @@ UnsetGuardForMemory ( **/
VOID
AdjustMemoryA (
- IN OUT EFI_PHYSICAL_ADDRESS *Memory,
- IN OUT UINTN *NumberOfPages
+ IN OUT EFI_PHYSICAL_ADDRESS *Memory,
+ IN OUT UINTN *NumberOfPages
);
/**
@@ -265,8 +265,8 @@ AdjustMemoryA ( **/
VOID
AdjustMemoryF (
- IN OUT EFI_PHYSICAL_ADDRESS *Memory,
- IN OUT UINTN *NumberOfPages
+ IN OUT EFI_PHYSICAL_ADDRESS *Memory,
+ IN OUT UINTN *NumberOfPages
);
/**
@@ -285,9 +285,9 @@ AdjustMemoryF ( **/
UINT64
AdjustMemoryS (
- IN UINT64 Start,
- IN UINT64 Size,
- IN UINT64 SizeRequested
+ IN UINT64 Start,
+ IN UINT64 Size,
+ IN UINT64 SizeRequested
);
/**
@@ -301,7 +301,7 @@ AdjustMemoryS ( **/
BOOLEAN
IsPoolTypeToGuard (
- IN EFI_MEMORY_TYPE MemoryType
+ IN EFI_MEMORY_TYPE MemoryType
);
/**
@@ -315,8 +315,8 @@ IsPoolTypeToGuard ( **/
BOOLEAN
IsPageTypeToGuard (
- IN EFI_MEMORY_TYPE MemoryType,
- IN EFI_ALLOCATE_TYPE AllocateType
+ IN EFI_MEMORY_TYPE MemoryType,
+ IN EFI_ALLOCATE_TYPE AllocateType
);
/**
@@ -330,7 +330,7 @@ IsPageTypeToGuard ( BOOLEAN
EFIAPI
IsMemoryGuarded (
- IN EFI_PHYSICAL_ADDRESS Address
+ IN EFI_PHYSICAL_ADDRESS Address
);
/**
@@ -344,7 +344,7 @@ IsMemoryGuarded ( BOOLEAN
EFIAPI
IsGuardPage (
- IN EFI_PHYSICAL_ADDRESS Address
+ IN EFI_PHYSICAL_ADDRESS Address
);
/**
@@ -369,9 +369,9 @@ DumpGuardedMemoryBitmap ( **/
VOID *
AdjustPoolHeadA (
- IN EFI_PHYSICAL_ADDRESS Memory,
- IN UINTN NoPages,
- IN UINTN Size
+ IN EFI_PHYSICAL_ADDRESS Memory,
+ IN UINTN NoPages,
+ IN UINTN Size
);
/**
@@ -383,7 +383,7 @@ AdjustPoolHeadA ( **/
VOID *
AdjustPoolHeadF (
- IN EFI_PHYSICAL_ADDRESS Memory
+ IN EFI_PHYSICAL_ADDRESS Memory
);
/**
@@ -395,7 +395,7 @@ AdjustPoolHeadF ( **/
BOOLEAN
IsHeapGuardEnabled (
- UINT8 GuardType
+ UINT8 GuardType
);
/**
@@ -418,8 +418,8 @@ HeapGuardCpuArchProtocolNotify ( **/
VOID
MergeGuardPages (
- IN EFI_MEMORY_DESCRIPTOR *MemoryMapEntry,
- IN EFI_PHYSICAL_ADDRESS MaxAddress
+ IN EFI_MEMORY_DESCRIPTOR *MemoryMapEntry,
+ IN EFI_PHYSICAL_ADDRESS MaxAddress
);
/**
@@ -433,8 +433,8 @@ MergeGuardPages ( VOID
EFIAPI
GuardFreedPagesChecked (
- IN EFI_PHYSICAL_ADDRESS BaseAddress,
- IN UINTN Pages
+ IN EFI_PHYSICAL_ADDRESS BaseAddress,
+ IN UINTN Pages
);
/**
@@ -458,10 +458,10 @@ GuardFreedPagesChecked ( **/
BOOLEAN
PromoteGuardedFreePages (
- OUT EFI_PHYSICAL_ADDRESS *StartAddress,
- OUT EFI_PHYSICAL_ADDRESS *EndAddress
+ OUT EFI_PHYSICAL_ADDRESS *StartAddress,
+ OUT EFI_PHYSICAL_ADDRESS *EndAddress
);
-extern BOOLEAN mOnGuarding;
+extern BOOLEAN mOnGuarding;
#endif
diff --git a/MdeModulePkg/Core/Dxe/Mem/Imem.h b/MdeModulePkg/Core/Dxe/Mem/Imem.h index 090f3f089f..2f0bf2bf63 100644 --- a/MdeModulePkg/Core/Dxe/Mem/Imem.h +++ b/MdeModulePkg/Core/Dxe/Mem/Imem.h @@ -20,34 +20,33 @@ SPDX-License-Identifier: BSD-2-Clause-Patent // | 0x80000000..0xFFFFFFFF - OS reserved |
// +---------------------------------------------------+
//
-#define MEMORY_TYPE_OS_RESERVED_MIN 0x80000000
-#define MEMORY_TYPE_OS_RESERVED_MAX 0xFFFFFFFF
-#define MEMORY_TYPE_OEM_RESERVED_MIN 0x70000000
-#define MEMORY_TYPE_OEM_RESERVED_MAX 0x7FFFFFFF
+#define MEMORY_TYPE_OS_RESERVED_MIN 0x80000000
+#define MEMORY_TYPE_OS_RESERVED_MAX 0xFFFFFFFF
+#define MEMORY_TYPE_OEM_RESERVED_MIN 0x70000000
+#define MEMORY_TYPE_OEM_RESERVED_MAX 0x7FFFFFFF
//
// MEMORY_MAP_ENTRY
//
-#define MEMORY_MAP_SIGNATURE SIGNATURE_32('m','m','a','p')
+#define MEMORY_MAP_SIGNATURE SIGNATURE_32('m','m','a','p')
typedef struct {
- UINTN Signature;
- LIST_ENTRY Link;
- BOOLEAN FromPages;
+ UINTN Signature;
+ LIST_ENTRY Link;
+ BOOLEAN FromPages;
- EFI_MEMORY_TYPE Type;
- UINT64 Start;
- UINT64 End;
+ EFI_MEMORY_TYPE Type;
+ UINT64 Start;
+ UINT64 End;
- UINT64 VirtualStart;
- UINT64 Attribute;
+ UINT64 VirtualStart;
+ UINT64 Attribute;
} MEMORY_MAP;
//
// Internal prototypes
//
-
/**
Internal function. Used by the pool functions to allocate pages
to back pool allocation requests.
@@ -62,14 +61,12 @@ typedef struct { **/
VOID *
CoreAllocatePoolPages (
- IN EFI_MEMORY_TYPE PoolType,
- IN UINTN NumberOfPages,
- IN UINTN Alignment,
- IN BOOLEAN NeedGuard
+ IN EFI_MEMORY_TYPE PoolType,
+ IN UINTN NumberOfPages,
+ IN UINTN Alignment,
+ IN BOOLEAN NeedGuard
);
-
-
/**
Internal function. Frees pool pages allocated via AllocatePoolPages ()
@@ -79,12 +76,10 @@ CoreAllocatePoolPages ( **/
VOID
CoreFreePoolPages (
- IN EFI_PHYSICAL_ADDRESS Memory,
- IN UINTN NumberOfPages
+ IN EFI_PHYSICAL_ADDRESS Memory,
+ IN UINTN NumberOfPages
);
-
-
/**
Internal function to allocate pool of a particular type.
Caller must have the memory lock held
@@ -103,8 +98,6 @@ CoreAllocatePoolI ( IN BOOLEAN NeedGuard
);
-
-
/**
Internal function to free a pool entry.
Caller must have the memory lock held
@@ -118,12 +111,10 @@ CoreAllocatePoolI ( **/
EFI_STATUS
CoreFreePoolI (
- IN VOID *Buffer,
- OUT EFI_MEMORY_TYPE *PoolType OPTIONAL
+ IN VOID *Buffer,
+ OUT EFI_MEMORY_TYPE *PoolType OPTIONAL
);
-
-
/**
Enter critical section by gaining lock on gMemoryLock.
@@ -133,7 +124,6 @@ CoreAcquireMemoryLock ( VOID
);
-
/**
Exit critical section by releasing lock on gMemoryLock.
@@ -165,18 +155,18 @@ CoreReleaseMemoryLock ( EFI_STATUS
EFIAPI
CoreInternalAllocatePages (
- IN EFI_ALLOCATE_TYPE Type,
- IN EFI_MEMORY_TYPE MemoryType,
- IN UINTN NumberOfPages,
+ IN EFI_ALLOCATE_TYPE Type,
+ IN EFI_MEMORY_TYPE MemoryType,
+ IN UINTN NumberOfPages,
IN OUT EFI_PHYSICAL_ADDRESS *Memory,
- IN BOOLEAN NeedGuard
+ IN BOOLEAN NeedGuard
);
//
// Internal Global data
//
-extern EFI_LOCK gMemoryLock;
-extern LIST_ENTRY gMemoryMap;
-extern LIST_ENTRY mGcdMemorySpaceMap;
+extern EFI_LOCK gMemoryLock;
+extern LIST_ENTRY gMemoryMap;
+extern LIST_ENTRY mGcdMemorySpaceMap;
#endif
diff --git a/MdeModulePkg/Core/Dxe/Mem/MemData.c b/MdeModulePkg/Core/Dxe/Mem/MemData.c index 67d8868322..8f138b703e 100644 --- a/MdeModulePkg/Core/Dxe/Mem/MemData.c +++ b/MdeModulePkg/Core/Dxe/Mem/MemData.c @@ -8,13 +8,12 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include "DxeMain.h"
-
//
// MemoryLock - synchronizes access to the memory map and pool lists
//
-EFI_LOCK gMemoryLock = EFI_INITIALIZE_LOCK_VARIABLE (TPL_NOTIFY);
+EFI_LOCK gMemoryLock = EFI_INITIALIZE_LOCK_VARIABLE (TPL_NOTIFY);
//
// MemoryMap - the current memory map
//
-LIST_ENTRY gMemoryMap = INITIALIZE_LIST_HEAD_VARIABLE (gMemoryMap);
+LIST_ENTRY gMemoryMap = INITIALIZE_LIST_HEAD_VARIABLE (gMemoryMap);
diff --git a/MdeModulePkg/Core/Dxe/Mem/MemoryProfileRecord.c b/MdeModulePkg/Core/Dxe/Mem/MemoryProfileRecord.c index 62bbe3cdc8..00e33b707d 100644 --- a/MdeModulePkg/Core/Dxe/Mem/MemoryProfileRecord.c +++ b/MdeModulePkg/Core/Dxe/Mem/MemoryProfileRecord.c @@ -9,15 +9,15 @@ #include "DxeMain.h"
#include "Imem.h"
-#define IS_UEFI_MEMORY_PROFILE_ENABLED ((PcdGet8 (PcdMemoryProfilePropertyMask) & BIT0) != 0)
+#define IS_UEFI_MEMORY_PROFILE_ENABLED ((PcdGet8 (PcdMemoryProfilePropertyMask) & BIT0) != 0)
#define GET_OCCUPIED_SIZE(ActualSize, Alignment) \
((ActualSize) + (((Alignment) - ((ActualSize) & ((Alignment) - 1))) & ((Alignment) - 1)))
typedef struct {
- UINT32 Signature;
- MEMORY_PROFILE_CONTEXT Context;
- LIST_ENTRY *DriverInfoList;
+ UINT32 Signature;
+ MEMORY_PROFILE_CONTEXT Context;
+ LIST_ENTRY *DriverInfoList;
} MEMORY_PROFILE_CONTEXT_DATA;
typedef struct {
@@ -29,15 +29,14 @@ typedef struct { } MEMORY_PROFILE_DRIVER_INFO_DATA;
typedef struct {
- UINT32 Signature;
- MEMORY_PROFILE_ALLOC_INFO AllocInfo;
- CHAR8 *ActionString;
- LIST_ENTRY Link;
+ UINT32 Signature;
+ MEMORY_PROFILE_ALLOC_INFO AllocInfo;
+ CHAR8 *ActionString;
+ LIST_ENTRY Link;
} MEMORY_PROFILE_ALLOC_INFO_DATA;
-
-GLOBAL_REMOVE_IF_UNREFERENCED LIST_ENTRY mImageQueue = INITIALIZE_LIST_HEAD_VARIABLE (mImageQueue);
-GLOBAL_REMOVE_IF_UNREFERENCED MEMORY_PROFILE_CONTEXT_DATA mMemoryProfileContext = {
+GLOBAL_REMOVE_IF_UNREFERENCED LIST_ENTRY mImageQueue = INITIALIZE_LIST_HEAD_VARIABLE (mImageQueue);
+GLOBAL_REMOVE_IF_UNREFERENCED MEMORY_PROFILE_CONTEXT_DATA mMemoryProfileContext = {
MEMORY_PROFILE_CONTEXT_SIGNATURE,
{
{
@@ -47,21 +46,21 @@ GLOBAL_REMOVE_IF_UNREFERENCED MEMORY_PROFILE_CONTEXT_DATA mMemoryProfileContext },
0,
0,
- {0},
- {0},
+ { 0 },
+ { 0 },
0,
0,
0
},
&mImageQueue,
};
-GLOBAL_REMOVE_IF_UNREFERENCED MEMORY_PROFILE_CONTEXT_DATA *mMemoryProfileContextPtr = NULL;
+GLOBAL_REMOVE_IF_UNREFERENCED MEMORY_PROFILE_CONTEXT_DATA *mMemoryProfileContextPtr = NULL;
-GLOBAL_REMOVE_IF_UNREFERENCED EFI_LOCK mMemoryProfileLock = EFI_INITIALIZE_LOCK_VARIABLE (TPL_NOTIFY);
-GLOBAL_REMOVE_IF_UNREFERENCED BOOLEAN mMemoryProfileGettingStatus = FALSE;
-GLOBAL_REMOVE_IF_UNREFERENCED BOOLEAN mMemoryProfileRecordingEnable = MEMORY_PROFILE_RECORDING_DISABLE;
-GLOBAL_REMOVE_IF_UNREFERENCED EFI_DEVICE_PATH_PROTOCOL *mMemoryProfileDriverPath;
-GLOBAL_REMOVE_IF_UNREFERENCED UINTN mMemoryProfileDriverPathSize;
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_LOCK mMemoryProfileLock = EFI_INITIALIZE_LOCK_VARIABLE (TPL_NOTIFY);
+GLOBAL_REMOVE_IF_UNREFERENCED BOOLEAN mMemoryProfileGettingStatus = FALSE;
+GLOBAL_REMOVE_IF_UNREFERENCED BOOLEAN mMemoryProfileRecordingEnable = MEMORY_PROFILE_RECORDING_DISABLE;
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_DEVICE_PATH_PROTOCOL *mMemoryProfileDriverPath;
+GLOBAL_REMOVE_IF_UNREFERENCED UINTN mMemoryProfileDriverPathSize;
/**
Get memory profile data.
@@ -82,7 +81,7 @@ EFIAPI ProfileProtocolGetData (
IN EDKII_MEMORY_PROFILE_PROTOCOL *This,
IN OUT UINT64 *ProfileSize,
- OUT VOID *ProfileBuffer
+ OUT VOID *ProfileBuffer
);
/**
@@ -103,11 +102,11 @@ ProfileProtocolGetData ( EFI_STATUS
EFIAPI
ProfileProtocolRegisterImage (
- IN EDKII_MEMORY_PROFILE_PROTOCOL *This,
- IN EFI_DEVICE_PATH_PROTOCOL *FilePath,
- IN PHYSICAL_ADDRESS ImageBase,
- IN UINT64 ImageSize,
- IN EFI_FV_FILETYPE FileType
+ IN EDKII_MEMORY_PROFILE_PROTOCOL *This,
+ IN EFI_DEVICE_PATH_PROTOCOL *FilePath,
+ IN PHYSICAL_ADDRESS ImageBase,
+ IN UINT64 ImageSize,
+ IN EFI_FV_FILETYPE FileType
);
/**
@@ -127,10 +126,10 @@ ProfileProtocolRegisterImage ( EFI_STATUS
EFIAPI
ProfileProtocolUnregisterImage (
- IN EDKII_MEMORY_PROFILE_PROTOCOL *This,
- IN EFI_DEVICE_PATH_PROTOCOL *FilePath,
- IN PHYSICAL_ADDRESS ImageBase,
- IN UINT64 ImageSize
+ IN EDKII_MEMORY_PROFILE_PROTOCOL *This,
+ IN EFI_DEVICE_PATH_PROTOCOL *FilePath,
+ IN PHYSICAL_ADDRESS ImageBase,
+ IN UINT64 ImageSize
);
/**
@@ -147,8 +146,8 @@ ProfileProtocolUnregisterImage ( EFI_STATUS
EFIAPI
ProfileProtocolGetRecordingState (
- IN EDKII_MEMORY_PROFILE_PROTOCOL *This,
- OUT BOOLEAN *RecordingState
+ IN EDKII_MEMORY_PROFILE_PROTOCOL *This,
+ OUT BOOLEAN *RecordingState
);
/**
@@ -164,8 +163,8 @@ ProfileProtocolGetRecordingState ( EFI_STATUS
EFIAPI
ProfileProtocolSetRecordingState (
- IN EDKII_MEMORY_PROFILE_PROTOCOL *This,
- IN BOOLEAN RecordingState
+ IN EDKII_MEMORY_PROFILE_PROTOCOL *This,
+ IN BOOLEAN RecordingState
);
/**
@@ -194,16 +193,16 @@ ProfileProtocolSetRecordingState ( EFI_STATUS
EFIAPI
ProfileProtocolRecord (
- IN EDKII_MEMORY_PROFILE_PROTOCOL *This,
- IN PHYSICAL_ADDRESS CallerAddress,
- IN MEMORY_PROFILE_ACTION Action,
- IN EFI_MEMORY_TYPE MemoryType,
- IN VOID *Buffer,
- IN UINTN Size,
- IN CHAR8 *ActionString OPTIONAL
+ IN EDKII_MEMORY_PROFILE_PROTOCOL *This,
+ IN PHYSICAL_ADDRESS CallerAddress,
+ IN MEMORY_PROFILE_ACTION Action,
+ IN EFI_MEMORY_TYPE MemoryType,
+ IN VOID *Buffer,
+ IN UINTN Size,
+ IN CHAR8 *ActionString OPTIONAL
);
-GLOBAL_REMOVE_IF_UNREFERENCED EDKII_MEMORY_PROFILE_PROTOCOL mProfileProtocol = {
+GLOBAL_REMOVE_IF_UNREFERENCED EDKII_MEMORY_PROFILE_PROTOCOL mProfileProtocol = {
ProfileProtocolGetData,
ProfileProtocolRegisterImage,
ProfileProtocolUnregisterImage,
@@ -268,22 +267,22 @@ InternalPeCoffGetSubsystem ( ASSERT (Pe32Data != NULL);
- DosHdr = (EFI_IMAGE_DOS_HEADER *) Pe32Data;
+ DosHdr = (EFI_IMAGE_DOS_HEADER *)Pe32Data;
if (DosHdr->e_magic == EFI_IMAGE_DOS_SIGNATURE) {
//
// DOS image header is present, so read the PE header after the DOS image header.
//
- Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *) ((UINTN) Pe32Data + (UINTN) ((DosHdr->e_lfanew) & 0x0ffff));
+ Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)((UINTN)Pe32Data + (UINTN)((DosHdr->e_lfanew) & 0x0ffff));
} else {
//
// DOS image header is not present, so PE header is at the image base.
//
- Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *) Pe32Data;
+ Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)Pe32Data;
}
if (Hdr.Te->Signature == EFI_TE_IMAGE_HEADER_SIGNATURE) {
return Hdr.Te->Subsystem;
- } else if (Hdr.Pe32->Signature == EFI_IMAGE_NT_SIGNATURE) {
+ } else if (Hdr.Pe32->Signature == EFI_IMAGE_NT_SIGNATURE) {
Magic = Hdr.Pe32->OptionalHeader.Magic;
if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {
return Hdr.Pe32->OptionalHeader.Subsystem;
@@ -318,23 +317,23 @@ InternalPeCoffGetEntryPoint ( OUT VOID **EntryPoint
)
{
- EFI_IMAGE_DOS_HEADER *DosHdr;
- EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr;
+ EFI_IMAGE_DOS_HEADER *DosHdr;
+ EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr;
ASSERT (Pe32Data != NULL);
ASSERT (EntryPoint != NULL);
- DosHdr = (EFI_IMAGE_DOS_HEADER *) Pe32Data;
+ DosHdr = (EFI_IMAGE_DOS_HEADER *)Pe32Data;
if (DosHdr->e_magic == EFI_IMAGE_DOS_SIGNATURE) {
//
// DOS image header is present, so read the PE header after the DOS image header.
//
- Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *) ((UINTN) Pe32Data + (UINTN) ((DosHdr->e_lfanew) & 0x0ffff));
+ Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)((UINTN)Pe32Data + (UINTN)((DosHdr->e_lfanew) & 0x0ffff));
} else {
//
// DOS image header is not present, so PE header is at the image base.
//
- Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *) Pe32Data;
+ Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)Pe32Data;
}
//
@@ -342,10 +341,10 @@ InternalPeCoffGetEntryPoint ( // AddressOfEntryPoint is common for PE32 & PE32+
//
if (Hdr.Te->Signature == EFI_TE_IMAGE_HEADER_SIGNATURE) {
- *EntryPoint = (VOID *) ((UINTN) Pe32Data + (UINTN) (Hdr.Te->AddressOfEntryPoint & 0x0ffffffff) + sizeof (EFI_TE_IMAGE_HEADER) - Hdr.Te->StrippedSize);
+ *EntryPoint = (VOID *)((UINTN)Pe32Data + (UINTN)(Hdr.Te->AddressOfEntryPoint & 0x0ffffffff) + sizeof (EFI_TE_IMAGE_HEADER) - Hdr.Te->StrippedSize);
return RETURN_SUCCESS;
} else if (Hdr.Pe32->Signature == EFI_IMAGE_NT_SIGNATURE) {
- *EntryPoint = (VOID *) ((UINTN) Pe32Data + (UINTN) (Hdr.Pe32->OptionalHeader.AddressOfEntryPoint & 0x0ffffffff));
+ *EntryPoint = (VOID *)((UINTN)Pe32Data + (UINTN)(Hdr.Pe32->OptionalHeader.AddressOfEntryPoint & 0x0ffffffff));
return RETURN_SUCCESS;
}
@@ -368,30 +367,30 @@ InternalPeCoffGetEntryPoint ( **/
MEMORY_PROFILE_DRIVER_INFO_DATA *
BuildDriverInfo (
- IN MEMORY_PROFILE_CONTEXT_DATA *ContextData,
- IN EFI_GUID *FileName,
- IN PHYSICAL_ADDRESS ImageBase,
- IN UINT64 ImageSize,
- IN PHYSICAL_ADDRESS EntryPoint,
- IN UINT16 ImageSubsystem,
- IN EFI_FV_FILETYPE FileType
+ IN MEMORY_PROFILE_CONTEXT_DATA *ContextData,
+ IN EFI_GUID *FileName,
+ IN PHYSICAL_ADDRESS ImageBase,
+ IN UINT64 ImageSize,
+ IN PHYSICAL_ADDRESS EntryPoint,
+ IN UINT16 ImageSubsystem,
+ IN EFI_FV_FILETYPE FileType
)
{
- EFI_STATUS Status;
- MEMORY_PROFILE_DRIVER_INFO *DriverInfo;
- MEMORY_PROFILE_DRIVER_INFO_DATA *DriverInfoData;
- VOID *EntryPointInImage;
- CHAR8 *PdbString;
- UINTN PdbSize;
- UINTN PdbOccupiedSize;
-
- PdbSize = 0;
+ EFI_STATUS Status;
+ MEMORY_PROFILE_DRIVER_INFO *DriverInfo;
+ MEMORY_PROFILE_DRIVER_INFO_DATA *DriverInfoData;
+ VOID *EntryPointInImage;
+ CHAR8 *PdbString;
+ UINTN PdbSize;
+ UINTN PdbOccupiedSize;
+
+ PdbSize = 0;
PdbOccupiedSize = 0;
- PdbString = NULL;
+ PdbString = NULL;
if (ImageBase != 0) {
- PdbString = PeCoffLoaderGetPdbPointer ((VOID*) (UINTN) ImageBase);
+ PdbString = PeCoffLoaderGetPdbPointer ((VOID *)(UINTN)ImageBase);
if (PdbString != NULL) {
- PdbSize = AsciiStrSize (PdbString);
+ PdbSize = AsciiStrSize (PdbString);
PdbOccupiedSize = GET_OCCUPIED_SIZE (PdbSize, sizeof (UINT64));
}
}
@@ -402,53 +401,56 @@ BuildDriverInfo ( Status = CoreInternalAllocatePool (
EfiBootServicesData,
sizeof (*DriverInfoData) + sizeof (LIST_ENTRY) + PdbSize,
- (VOID **) &DriverInfoData
+ (VOID **)&DriverInfoData
);
if (EFI_ERROR (Status)) {
return NULL;
}
+
ASSERT (DriverInfoData != NULL);
ZeroMem (DriverInfoData, sizeof (*DriverInfoData));
- DriverInfo = &DriverInfoData->DriverInfo;
- DriverInfoData->Signature = MEMORY_PROFILE_DRIVER_INFO_SIGNATURE;
+ DriverInfo = &DriverInfoData->DriverInfo;
+ DriverInfoData->Signature = MEMORY_PROFILE_DRIVER_INFO_SIGNATURE;
DriverInfo->Header.Signature = MEMORY_PROFILE_DRIVER_INFO_SIGNATURE;
- DriverInfo->Header.Length = (UINT16) (sizeof (MEMORY_PROFILE_DRIVER_INFO) + PdbOccupiedSize);
- DriverInfo->Header.Revision = MEMORY_PROFILE_DRIVER_INFO_REVISION;
+ DriverInfo->Header.Length = (UINT16)(sizeof (MEMORY_PROFILE_DRIVER_INFO) + PdbOccupiedSize);
+ DriverInfo->Header.Revision = MEMORY_PROFILE_DRIVER_INFO_REVISION;
if (FileName != NULL) {
CopyMem (&DriverInfo->FileName, FileName, sizeof (EFI_GUID));
}
- DriverInfo->ImageBase = ImageBase;
- DriverInfo->ImageSize = ImageSize;
- DriverInfo->EntryPoint = EntryPoint;
+
+ DriverInfo->ImageBase = ImageBase;
+ DriverInfo->ImageSize = ImageSize;
+ DriverInfo->EntryPoint = EntryPoint;
DriverInfo->ImageSubsystem = ImageSubsystem;
if ((EntryPoint != 0) && ((EntryPoint < ImageBase) || (EntryPoint >= (ImageBase + ImageSize)))) {
//
// If the EntryPoint is not in the range of image buffer, it should come from emulation environment.
// So patch ImageBuffer here to align the EntryPoint.
//
- Status = InternalPeCoffGetEntryPoint ((VOID *) (UINTN) ImageBase, &EntryPointInImage);
+ Status = InternalPeCoffGetEntryPoint ((VOID *)(UINTN)ImageBase, &EntryPointInImage);
ASSERT_EFI_ERROR (Status);
- DriverInfo->ImageBase = ImageBase + EntryPoint - (PHYSICAL_ADDRESS) (UINTN) EntryPointInImage;
+ DriverInfo->ImageBase = ImageBase + EntryPoint - (PHYSICAL_ADDRESS)(UINTN)EntryPointInImage;
}
- DriverInfo->FileType = FileType;
- DriverInfoData->AllocInfoList = (LIST_ENTRY *) (DriverInfoData + 1);
+
+ DriverInfo->FileType = FileType;
+ DriverInfoData->AllocInfoList = (LIST_ENTRY *)(DriverInfoData + 1);
InitializeListHead (DriverInfoData->AllocInfoList);
- DriverInfo->CurrentUsage = 0;
- DriverInfo->PeakUsage = 0;
+ DriverInfo->CurrentUsage = 0;
+ DriverInfo->PeakUsage = 0;
DriverInfo->AllocRecordCount = 0;
if (PdbSize != 0) {
- DriverInfo->PdbStringOffset = (UINT16) sizeof (MEMORY_PROFILE_DRIVER_INFO);
- DriverInfoData->PdbString = (CHAR8 *) (DriverInfoData->AllocInfoList + 1);
+ DriverInfo->PdbStringOffset = (UINT16)sizeof (MEMORY_PROFILE_DRIVER_INFO);
+ DriverInfoData->PdbString = (CHAR8 *)(DriverInfoData->AllocInfoList + 1);
CopyMem (DriverInfoData->PdbString, PdbString, PdbSize);
} else {
DriverInfo->PdbStringOffset = 0;
- DriverInfoData->PdbString = NULL;
+ DriverInfoData->PdbString = NULL;
}
InsertTailList (ContextData->DriverInfoList, &DriverInfoData->Link);
- ContextData->Context.ImageCount ++;
+ ContextData->Context.ImageCount++;
ContextData->Context.TotalImageSize += DriverInfo->ImageSize;
return DriverInfoData;
@@ -465,13 +467,13 @@ BuildDriverInfo ( **/
BOOLEAN
NeedRecordThisDriver (
- IN EFI_DEVICE_PATH_PROTOCOL *DriverFilePath
+ IN EFI_DEVICE_PATH_PROTOCOL *DriverFilePath
)
{
- EFI_DEVICE_PATH_PROTOCOL *TmpDevicePath;
- EFI_DEVICE_PATH_PROTOCOL *DevicePathInstance;
- UINTN DevicePathSize;
- UINTN FilePathSize;
+ EFI_DEVICE_PATH_PROTOCOL *TmpDevicePath;
+ EFI_DEVICE_PATH_PROTOCOL *DevicePathInstance;
+ UINTN DevicePathSize;
+ UINTN FilePathSize;
if (!IsDevicePathValid (mMemoryProfileDriverPath, mMemoryProfileDriverPathSize)) {
//
@@ -483,7 +485,7 @@ NeedRecordThisDriver ( //
// Record FilePath without END node.
//
- FilePathSize = GetDevicePathSize (DriverFilePath) - sizeof(EFI_DEVICE_PATH_PROTOCOL);
+ FilePathSize = GetDevicePathSize (DriverFilePath) - sizeof (EFI_DEVICE_PATH_PROTOCOL);
DevicePathInstance = mMemoryProfileDriverPath;
do {
@@ -500,14 +502,15 @@ NeedRecordThisDriver ( //
DevicePathSize = (UINTN)TmpDevicePath - (UINTN)DevicePathInstance;
if ((FilePathSize == DevicePathSize) &&
- (CompareMem (DriverFilePath, DevicePathInstance, DevicePathSize) == 0)) {
+ (CompareMem (DriverFilePath, DevicePathInstance, DevicePathSize) == 0))
+ {
return TRUE;
}
//
// Get next instance.
//
- DevicePathInstance = (EFI_DEVICE_PATH_PROTOCOL *)((UINTN)DevicePathInstance + DevicePathSize + DevicePathNodeLength(TmpDevicePath));
+ DevicePathInstance = (EFI_DEVICE_PATH_PROTOCOL *)((UINTN)DevicePathInstance + DevicePathSize + DevicePathNodeLength (TmpDevicePath));
} while (DevicePathSubType (TmpDevicePath) != END_ENTIRE_DEVICE_PATH_SUBTYPE);
return FALSE;
@@ -525,22 +528,22 @@ NeedRecordThisDriver ( **/
BOOLEAN
RegisterDxeCore (
- IN VOID *HobStart,
- IN MEMORY_PROFILE_CONTEXT_DATA *ContextData
+ IN VOID *HobStart,
+ IN MEMORY_PROFILE_CONTEXT_DATA *ContextData
)
{
- EFI_PEI_HOB_POINTERS DxeCoreHob;
- MEMORY_PROFILE_DRIVER_INFO_DATA *DriverInfoData;
- PHYSICAL_ADDRESS ImageBase;
- UINT8 TempBuffer[sizeof(MEDIA_FW_VOL_FILEPATH_DEVICE_PATH) + sizeof(EFI_DEVICE_PATH_PROTOCOL)];
- MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *FilePath;
+ EFI_PEI_HOB_POINTERS DxeCoreHob;
+ MEMORY_PROFILE_DRIVER_INFO_DATA *DriverInfoData;
+ PHYSICAL_ADDRESS ImageBase;
+ UINT8 TempBuffer[sizeof (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH) + sizeof (EFI_DEVICE_PATH_PROTOCOL)];
+ MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *FilePath;
ASSERT (ContextData != NULL);
//
// Searching for image hob
//
- DxeCoreHob.Raw = HobStart;
+ DxeCoreHob.Raw = HobStart;
while ((DxeCoreHob.Raw = GetNextHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, DxeCoreHob.Raw)) != NULL) {
if (CompareGuid (&DxeCoreHob.MemoryAllocationModule->MemoryAllocationHeader.Name, &gEfiHobMemoryAllocModuleGuid)) {
//
@@ -548,26 +551,28 @@ RegisterDxeCore ( //
break;
}
+
DxeCoreHob.Raw = GET_NEXT_HOB (DxeCoreHob);
}
+
ASSERT (DxeCoreHob.Raw != NULL);
- FilePath = (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *) TempBuffer;
+ FilePath = (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *)TempBuffer;
EfiInitializeFwVolDevicepathNode (FilePath, &DxeCoreHob.MemoryAllocationModule->ModuleName);
SetDevicePathEndNode (FilePath + 1);
- if (!NeedRecordThisDriver ((EFI_DEVICE_PATH_PROTOCOL *) FilePath)) {
+ if (!NeedRecordThisDriver ((EFI_DEVICE_PATH_PROTOCOL *)FilePath)) {
return FALSE;
}
- ImageBase = DxeCoreHob.MemoryAllocationModule->MemoryAllocationHeader.MemoryBaseAddress;
+ ImageBase = DxeCoreHob.MemoryAllocationModule->MemoryAllocationHeader.MemoryBaseAddress;
DriverInfoData = BuildDriverInfo (
ContextData,
&DxeCoreHob.MemoryAllocationModule->ModuleName,
ImageBase,
DxeCoreHob.MemoryAllocationModule->MemoryAllocationHeader.MemoryLength,
DxeCoreHob.MemoryAllocationModule->EntryPoint,
- InternalPeCoffGetSubsystem ((VOID *) (UINTN) ImageBase),
+ InternalPeCoffGetSubsystem ((VOID *)(UINTN)ImageBase),
EFI_FV_FILETYPE_DXE_CORE
);
if (DriverInfoData == NULL) {
@@ -585,10 +590,10 @@ RegisterDxeCore ( **/
VOID
MemoryProfileInit (
- IN VOID *HobStart
+ IN VOID *HobStart
)
{
- MEMORY_PROFILE_CONTEXT_DATA *ContextData;
+ MEMORY_PROFILE_CONTEXT_DATA *ContextData;
if (!IS_UEFI_MEMORY_PROFILE_ENABLED) {
return;
@@ -605,9 +610,10 @@ MemoryProfileInit ( } else {
mMemoryProfileRecordingEnable = MEMORY_PROFILE_RECORDING_ENABLE;
}
+
mMemoryProfileDriverPathSize = PcdGetSize (PcdMemoryProfileDriverPath);
- mMemoryProfileDriverPath = AllocateCopyPool (mMemoryProfileDriverPathSize, PcdGetPtr (PcdMemoryProfileDriverPath));
- mMemoryProfileContextPtr = &mMemoryProfileContext;
+ mMemoryProfileDriverPath = AllocateCopyPool (mMemoryProfileDriverPathSize, PcdGetPtr (PcdMemoryProfileDriverPath));
+ mMemoryProfileContextPtr = &mMemoryProfileContext;
RegisterDxeCore (HobStart, &mMemoryProfileContext);
@@ -623,8 +629,8 @@ MemoryProfileInstallProtocol ( VOID
)
{
- EFI_HANDLE Handle;
- EFI_STATUS Status;
+ EFI_HANDLE Handle;
+ EFI_STATUS Status;
if (!IS_UEFI_MEMORY_PROFILE_ENABLED) {
return;
@@ -650,21 +656,22 @@ MemoryProfileInstallProtocol ( **/
EFI_GUID *
GetFileNameFromFilePath (
- IN EFI_DEVICE_PATH_PROTOCOL *FilePath
+ IN EFI_DEVICE_PATH_PROTOCOL *FilePath
)
{
- MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *ThisFilePath;
- EFI_GUID *FileName;
+ MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *ThisFilePath;
+ EFI_GUID *FileName;
FileName = NULL;
if (FilePath != NULL) {
- ThisFilePath = (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *) FilePath;
+ ThisFilePath = (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *)FilePath;
while (!IsDevicePathEnd (ThisFilePath)) {
FileName = EfiGetNameGuidFromFwVolDevicePathNode (ThisFilePath);
if (FileName != NULL) {
break;
}
- ThisFilePath = (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *) NextDevicePathNode (ThisFilePath);
+
+ ThisFilePath = (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *)NextDevicePathNode (ThisFilePath);
}
}
@@ -689,8 +696,8 @@ RegisterMemoryProfileImage ( IN EFI_FV_FILETYPE FileType
)
{
- MEMORY_PROFILE_CONTEXT_DATA *ContextData;
- MEMORY_PROFILE_DRIVER_INFO_DATA *DriverInfoData;
+ MEMORY_PROFILE_CONTEXT_DATA *ContextData;
+ MEMORY_PROFILE_DRIVER_INFO_DATA *DriverInfoData;
if (!IS_UEFI_MEMORY_PROFILE_ENABLED) {
return EFI_UNSUPPORTED;
@@ -733,21 +740,22 @@ RegisterMemoryProfileImage ( **/
MEMORY_PROFILE_DRIVER_INFO_DATA *
GetMemoryProfileDriverInfoByFileNameAndAddress (
- IN MEMORY_PROFILE_CONTEXT_DATA *ContextData,
- IN EFI_GUID *FileName,
- IN PHYSICAL_ADDRESS Address
+ IN MEMORY_PROFILE_CONTEXT_DATA *ContextData,
+ IN EFI_GUID *FileName,
+ IN PHYSICAL_ADDRESS Address
)
{
- MEMORY_PROFILE_DRIVER_INFO *DriverInfo;
- MEMORY_PROFILE_DRIVER_INFO_DATA *DriverInfoData;
- LIST_ENTRY *DriverLink;
- LIST_ENTRY *DriverInfoList;
+ MEMORY_PROFILE_DRIVER_INFO *DriverInfo;
+ MEMORY_PROFILE_DRIVER_INFO_DATA *DriverInfoData;
+ LIST_ENTRY *DriverLink;
+ LIST_ENTRY *DriverInfoList;
DriverInfoList = ContextData->DriverInfoList;
for (DriverLink = DriverInfoList->ForwardLink;
DriverLink != DriverInfoList;
- DriverLink = DriverLink->ForwardLink) {
+ DriverLink = DriverLink->ForwardLink)
+ {
DriverInfoData = CR (
DriverLink,
MEMORY_PROFILE_DRIVER_INFO_DATA,
@@ -757,7 +765,8 @@ GetMemoryProfileDriverInfoByFileNameAndAddress ( DriverInfo = &DriverInfoData->DriverInfo;
if ((CompareGuid (&DriverInfo->FileName, FileName)) &&
(Address >= DriverInfo->ImageBase) &&
- (Address < (DriverInfo->ImageBase + DriverInfo->ImageSize))) {
+ (Address < (DriverInfo->ImageBase + DriverInfo->ImageSize)))
+ {
return DriverInfoData;
}
}
@@ -777,20 +786,21 @@ GetMemoryProfileDriverInfoByFileNameAndAddress ( **/
MEMORY_PROFILE_DRIVER_INFO_DATA *
GetMemoryProfileDriverInfoFromAddress (
- IN MEMORY_PROFILE_CONTEXT_DATA *ContextData,
- IN PHYSICAL_ADDRESS Address
+ IN MEMORY_PROFILE_CONTEXT_DATA *ContextData,
+ IN PHYSICAL_ADDRESS Address
)
{
- MEMORY_PROFILE_DRIVER_INFO *DriverInfo;
- MEMORY_PROFILE_DRIVER_INFO_DATA *DriverInfoData;
- LIST_ENTRY *DriverLink;
- LIST_ENTRY *DriverInfoList;
+ MEMORY_PROFILE_DRIVER_INFO *DriverInfo;
+ MEMORY_PROFILE_DRIVER_INFO_DATA *DriverInfoData;
+ LIST_ENTRY *DriverLink;
+ LIST_ENTRY *DriverInfoList;
DriverInfoList = ContextData->DriverInfoList;
for (DriverLink = DriverInfoList->ForwardLink;
DriverLink != DriverInfoList;
- DriverLink = DriverLink->ForwardLink) {
+ DriverLink = DriverLink->ForwardLink)
+ {
DriverInfoData = CR (
DriverLink,
MEMORY_PROFILE_DRIVER_INFO_DATA,
@@ -799,7 +809,8 @@ GetMemoryProfileDriverInfoFromAddress ( );
DriverInfo = &DriverInfoData->DriverInfo;
if ((Address >= DriverInfo->ImageBase) &&
- (Address < (DriverInfo->ImageBase + DriverInfo->ImageSize))) {
+ (Address < (DriverInfo->ImageBase + DriverInfo->ImageSize)))
+ {
return DriverInfoData;
}
}
@@ -820,15 +831,15 @@ GetMemoryProfileDriverInfoFromAddress ( **/
EFI_STATUS
UnregisterMemoryProfileImage (
- IN LOADED_IMAGE_PRIVATE_DATA *DriverEntry
+ IN LOADED_IMAGE_PRIVATE_DATA *DriverEntry
)
{
- EFI_STATUS Status;
- MEMORY_PROFILE_CONTEXT_DATA *ContextData;
- MEMORY_PROFILE_DRIVER_INFO_DATA *DriverInfoData;
- EFI_GUID *FileName;
- PHYSICAL_ADDRESS ImageAddress;
- VOID *EntryPointInImage;
+ EFI_STATUS Status;
+ MEMORY_PROFILE_CONTEXT_DATA *ContextData;
+ MEMORY_PROFILE_DRIVER_INFO_DATA *DriverInfoData;
+ EFI_GUID *FileName;
+ PHYSICAL_ADDRESS ImageAddress;
+ VOID *EntryPointInImage;
if (!IS_UEFI_MEMORY_PROFILE_ENABLED) {
return EFI_UNSUPPORTED;
@@ -844,23 +855,26 @@ UnregisterMemoryProfileImage ( }
DriverInfoData = NULL;
- FileName = GetFileNameFromFilePath (DriverEntry->Info.FilePath);
- ImageAddress = DriverEntry->ImageContext.ImageAddress;
+ FileName = GetFileNameFromFilePath (DriverEntry->Info.FilePath);
+ ImageAddress = DriverEntry->ImageContext.ImageAddress;
if ((DriverEntry->ImageContext.EntryPoint < ImageAddress) || (DriverEntry->ImageContext.EntryPoint >= (ImageAddress + DriverEntry->ImageContext.ImageSize))) {
//
// If the EntryPoint is not in the range of image buffer, it should come from emulation environment.
// So patch ImageAddress here to align the EntryPoint.
//
- Status = InternalPeCoffGetEntryPoint ((VOID *) (UINTN) ImageAddress, &EntryPointInImage);
+ Status = InternalPeCoffGetEntryPoint ((VOID *)(UINTN)ImageAddress, &EntryPointInImage);
ASSERT_EFI_ERROR (Status);
- ImageAddress = ImageAddress + (UINTN) DriverEntry->ImageContext.EntryPoint - (UINTN) EntryPointInImage;
+ ImageAddress = ImageAddress + (UINTN)DriverEntry->ImageContext.EntryPoint - (UINTN)EntryPointInImage;
}
+
if (FileName != NULL) {
DriverInfoData = GetMemoryProfileDriverInfoByFileNameAndAddress (ContextData, FileName, ImageAddress);
}
+
if (DriverInfoData == NULL) {
DriverInfoData = GetMemoryProfileDriverInfoFromAddress (ContextData, ImageAddress);
}
+
if (DriverInfoData == NULL) {
return EFI_NOT_FOUND;
}
@@ -868,11 +882,11 @@ UnregisterMemoryProfileImage ( ContextData->Context.TotalImageSize -= DriverInfoData->DriverInfo.ImageSize;
// Keep the ImageBase for RVA calculation in Application.
- //DriverInfoData->DriverInfo.ImageBase = 0;
+ // DriverInfoData->DriverInfo.ImageBase = 0;
DriverInfoData->DriverInfo.ImageSize = 0;
if (DriverInfoData->DriverInfo.PeakUsage == 0) {
- ContextData->Context.ImageCount --;
+ ContextData->Context.ImageCount--;
RemoveEntryList (&DriverInfoData->Link);
//
// Use CoreInternalFreePool() that will not update profile for this FreePool action.
@@ -897,14 +911,14 @@ UnregisterMemoryProfileImage ( **/
BOOLEAN
CoreNeedRecordProfile (
- IN EFI_MEMORY_TYPE MemoryType
+ IN EFI_MEMORY_TYPE MemoryType
)
{
- UINT64 TestBit;
+ UINT64 TestBit;
- if ((UINT32) MemoryType >= MEMORY_TYPE_OS_RESERVED_MIN) {
+ if ((UINT32)MemoryType >= MEMORY_TYPE_OS_RESERVED_MIN) {
TestBit = BIT63;
- } else if ((UINT32) MemoryType >= MEMORY_TYPE_OEM_RESERVED_MIN) {
+ } else if ((UINT32)MemoryType >= MEMORY_TYPE_OEM_RESERVED_MIN) {
TestBit = BIT62;
} else {
TestBit = LShiftU64 (1, MemoryType);
@@ -930,12 +944,12 @@ CoreNeedRecordProfile ( **/
UINTN
GetProfileMemoryIndex (
- IN EFI_MEMORY_TYPE MemoryType
+ IN EFI_MEMORY_TYPE MemoryType
)
{
- if ((UINT32) MemoryType >= MEMORY_TYPE_OS_RESERVED_MIN) {
+ if ((UINT32)MemoryType >= MEMORY_TYPE_OS_RESERVED_MIN) {
return EfiMaxMemoryType;
- } else if ((UINT32) MemoryType >= MEMORY_TYPE_OEM_RESERVED_MIN) {
+ } else if ((UINT32)MemoryType >= MEMORY_TYPE_OEM_RESERVED_MIN) {
return EfiMaxMemoryType + 1;
} else {
return MemoryType;
@@ -968,17 +982,17 @@ CoreUpdateProfileAllocate ( IN CHAR8 *ActionString OPTIONAL
)
{
- EFI_STATUS Status;
- MEMORY_PROFILE_CONTEXT *Context;
- MEMORY_PROFILE_DRIVER_INFO *DriverInfo;
- MEMORY_PROFILE_ALLOC_INFO *AllocInfo;
- MEMORY_PROFILE_CONTEXT_DATA *ContextData;
- MEMORY_PROFILE_DRIVER_INFO_DATA *DriverInfoData;
- MEMORY_PROFILE_ALLOC_INFO_DATA *AllocInfoData;
- UINTN ProfileMemoryIndex;
- MEMORY_PROFILE_ACTION BasicAction;
- UINTN ActionStringSize;
- UINTN ActionStringOccupiedSize;
+ EFI_STATUS Status;
+ MEMORY_PROFILE_CONTEXT *Context;
+ MEMORY_PROFILE_DRIVER_INFO *DriverInfo;
+ MEMORY_PROFILE_ALLOC_INFO *AllocInfo;
+ MEMORY_PROFILE_CONTEXT_DATA *ContextData;
+ MEMORY_PROFILE_DRIVER_INFO_DATA *DriverInfoData;
+ MEMORY_PROFILE_ALLOC_INFO_DATA *AllocInfoData;
+ UINTN ProfileMemoryIndex;
+ MEMORY_PROFILE_ACTION BasicAction;
+ UINTN ActionStringSize;
+ UINTN ActionStringOccupiedSize;
BasicAction = Action & MEMORY_PROFILE_ACTION_BASIC_MASK;
@@ -992,10 +1006,10 @@ CoreUpdateProfileAllocate ( return EFI_UNSUPPORTED;
}
- ActionStringSize = 0;
+ ActionStringSize = 0;
ActionStringOccupiedSize = 0;
if (ActionString != NULL) {
- ActionStringSize = AsciiStrSize (ActionString);
+ ActionStringSize = AsciiStrSize (ActionString);
ActionStringOccupiedSize = GET_OCCUPIED_SIZE (ActionStringSize, sizeof (UINT64));
}
@@ -1003,48 +1017,49 @@ CoreUpdateProfileAllocate ( // Use CoreInternalAllocatePool() that will not update profile for this AllocatePool action.
//
AllocInfoData = NULL;
- Status = CoreInternalAllocatePool (
- EfiBootServicesData,
- sizeof (*AllocInfoData) + ActionStringSize,
- (VOID **) &AllocInfoData
- );
+ Status = CoreInternalAllocatePool (
+ EfiBootServicesData,
+ sizeof (*AllocInfoData) + ActionStringSize,
+ (VOID **)&AllocInfoData
+ );
if (EFI_ERROR (Status)) {
return EFI_OUT_OF_RESOURCES;
}
+
ASSERT (AllocInfoData != NULL);
//
// Only update SequenceCount if and only if it is basic action.
//
if (Action == BasicAction) {
- ContextData->Context.SequenceCount ++;
+ ContextData->Context.SequenceCount++;
}
- AllocInfo = &AllocInfoData->AllocInfo;
- AllocInfoData->Signature = MEMORY_PROFILE_ALLOC_INFO_SIGNATURE;
- AllocInfo->Header.Signature = MEMORY_PROFILE_ALLOC_INFO_SIGNATURE;
- AllocInfo->Header.Length = (UINT16) (sizeof (MEMORY_PROFILE_ALLOC_INFO) + ActionStringOccupiedSize);
- AllocInfo->Header.Revision = MEMORY_PROFILE_ALLOC_INFO_REVISION;
- AllocInfo->CallerAddress = CallerAddress;
- AllocInfo->SequenceId = ContextData->Context.SequenceCount;
- AllocInfo->Action = Action;
- AllocInfo->MemoryType = MemoryType;
- AllocInfo->Buffer = (PHYSICAL_ADDRESS) (UINTN) Buffer;
- AllocInfo->Size = Size;
+ AllocInfo = &AllocInfoData->AllocInfo;
+ AllocInfoData->Signature = MEMORY_PROFILE_ALLOC_INFO_SIGNATURE;
+ AllocInfo->Header.Signature = MEMORY_PROFILE_ALLOC_INFO_SIGNATURE;
+ AllocInfo->Header.Length = (UINT16)(sizeof (MEMORY_PROFILE_ALLOC_INFO) + ActionStringOccupiedSize);
+ AllocInfo->Header.Revision = MEMORY_PROFILE_ALLOC_INFO_REVISION;
+ AllocInfo->CallerAddress = CallerAddress;
+ AllocInfo->SequenceId = ContextData->Context.SequenceCount;
+ AllocInfo->Action = Action;
+ AllocInfo->MemoryType = MemoryType;
+ AllocInfo->Buffer = (PHYSICAL_ADDRESS)(UINTN)Buffer;
+ AllocInfo->Size = Size;
if (ActionString != NULL) {
- AllocInfo->ActionStringOffset = (UINT16) sizeof (MEMORY_PROFILE_ALLOC_INFO);
- AllocInfoData->ActionString = (CHAR8 *) (AllocInfoData + 1);
+ AllocInfo->ActionStringOffset = (UINT16)sizeof (MEMORY_PROFILE_ALLOC_INFO);
+ AllocInfoData->ActionString = (CHAR8 *)(AllocInfoData + 1);
CopyMem (AllocInfoData->ActionString, ActionString, ActionStringSize);
} else {
AllocInfo->ActionStringOffset = 0;
- AllocInfoData->ActionString = NULL;
+ AllocInfoData->ActionString = NULL;
}
InsertTailList (DriverInfoData->AllocInfoList, &AllocInfoData->Link);
- Context = &ContextData->Context;
+ Context = &ContextData->Context;
DriverInfo = &DriverInfoData->DriverInfo;
- DriverInfo->AllocRecordCount ++;
+ DriverInfo->AllocRecordCount++;
//
// Update summary if and only if it is basic action.
@@ -1056,6 +1071,7 @@ CoreUpdateProfileAllocate ( if (DriverInfo->PeakUsage < DriverInfo->CurrentUsage) {
DriverInfo->PeakUsage = DriverInfo->CurrentUsage;
}
+
DriverInfo->CurrentUsageByType[ProfileMemoryIndex] += Size;
if (DriverInfo->PeakUsageByType[ProfileMemoryIndex] < DriverInfo->CurrentUsageByType[ProfileMemoryIndex]) {
DriverInfo->PeakUsageByType[ProfileMemoryIndex] = DriverInfo->CurrentUsageByType[ProfileMemoryIndex];
@@ -1065,6 +1081,7 @@ CoreUpdateProfileAllocate ( if (Context->PeakTotalUsage < Context->CurrentTotalUsage) {
Context->PeakTotalUsage = Context->CurrentTotalUsage;
}
+
Context->CurrentTotalUsageByType[ProfileMemoryIndex] += Size;
if (Context->PeakTotalUsageByType[ProfileMemoryIndex] < Context->CurrentTotalUsageByType[ProfileMemoryIndex]) {
Context->PeakTotalUsageByType[ProfileMemoryIndex] = Context->CurrentTotalUsageByType[ProfileMemoryIndex];
@@ -1087,22 +1104,23 @@ CoreUpdateProfileAllocate ( **/
MEMORY_PROFILE_ALLOC_INFO_DATA *
GetMemoryProfileAllocInfoFromAddress (
- IN MEMORY_PROFILE_DRIVER_INFO_DATA *DriverInfoData,
- IN MEMORY_PROFILE_ACTION BasicAction,
- IN UINTN Size,
- IN VOID *Buffer
+ IN MEMORY_PROFILE_DRIVER_INFO_DATA *DriverInfoData,
+ IN MEMORY_PROFILE_ACTION BasicAction,
+ IN UINTN Size,
+ IN VOID *Buffer
)
{
- LIST_ENTRY *AllocInfoList;
- LIST_ENTRY *AllocLink;
- MEMORY_PROFILE_ALLOC_INFO *AllocInfo;
- MEMORY_PROFILE_ALLOC_INFO_DATA *AllocInfoData;
+ LIST_ENTRY *AllocInfoList;
+ LIST_ENTRY *AllocLink;
+ MEMORY_PROFILE_ALLOC_INFO *AllocInfo;
+ MEMORY_PROFILE_ALLOC_INFO_DATA *AllocInfoData;
AllocInfoList = DriverInfoData->AllocInfoList;
for (AllocLink = AllocInfoList->ForwardLink;
AllocLink != AllocInfoList;
- AllocLink = AllocLink->ForwardLink) {
+ AllocLink = AllocLink->ForwardLink)
+ {
AllocInfoData = CR (
AllocLink,
MEMORY_PROFILE_ALLOC_INFO_DATA,
@@ -1113,17 +1131,21 @@ GetMemoryProfileAllocInfoFromAddress ( if ((AllocInfo->Action & MEMORY_PROFILE_ACTION_BASIC_MASK) != BasicAction) {
continue;
}
+
switch (BasicAction) {
case MemoryProfileActionAllocatePages:
- if ((AllocInfo->Buffer <= (PHYSICAL_ADDRESS) (UINTN) Buffer) &&
- ((AllocInfo->Buffer + AllocInfo->Size) >= ((PHYSICAL_ADDRESS) (UINTN) Buffer + Size))) {
+ if ((AllocInfo->Buffer <= (PHYSICAL_ADDRESS)(UINTN)Buffer) &&
+ ((AllocInfo->Buffer + AllocInfo->Size) >= ((PHYSICAL_ADDRESS)(UINTN)Buffer + Size)))
+ {
return AllocInfoData;
}
+
break;
case MemoryProfileActionAllocatePool:
- if (AllocInfo->Buffer == (PHYSICAL_ADDRESS) (UINTN) Buffer) {
+ if (AllocInfo->Buffer == (PHYSICAL_ADDRESS)(UINTN)Buffer) {
return AllocInfoData;
}
+
break;
default:
ASSERT (FALSE);
@@ -1186,7 +1208,7 @@ CoreUpdateProfileFree ( // Need use do-while loop to find all possible records,
// because one address might be recorded multiple times.
//
- Found = FALSE;
+ Found = FALSE;
AllocInfoData = NULL;
do {
if (DriverInfoData != NULL) {
@@ -1203,6 +1225,7 @@ CoreUpdateProfileFree ( break;
}
}
+
if (AllocInfoData == NULL) {
//
// Legal case, because driver A might free memory allocated by driver B, by some protocol.
@@ -1211,7 +1234,8 @@ CoreUpdateProfileFree ( for (DriverLink = DriverInfoList->ForwardLink;
DriverLink != DriverInfoList;
- DriverLink = DriverLink->ForwardLink) {
+ DriverLink = DriverLink->ForwardLink)
+ {
ThisDriverInfoData = CR (
DriverLink,
MEMORY_PROFILE_DRIVER_INFO_DATA,
@@ -1230,6 +1254,7 @@ CoreUpdateProfileFree ( AllocInfoData = NULL;
break;
}
+
if (AllocInfoData != NULL) {
DriverInfoData = ThisDriverInfoData;
break;
@@ -1254,44 +1279,45 @@ CoreUpdateProfileFree ( Found = TRUE;
- Context = &ContextData->Context;
+ Context = &ContextData->Context;
DriverInfo = &DriverInfoData->DriverInfo;
- AllocInfo = &AllocInfoData->AllocInfo;
+ AllocInfo = &AllocInfoData->AllocInfo;
- DriverInfo->AllocRecordCount --;
+ DriverInfo->AllocRecordCount--;
//
// Update summary if and only if it is basic action.
//
if (AllocInfo->Action == (AllocInfo->Action & MEMORY_PROFILE_ACTION_BASIC_MASK)) {
ProfileMemoryIndex = GetProfileMemoryIndex (AllocInfo->MemoryType);
- Context->CurrentTotalUsage -= AllocInfo->Size;
+ Context->CurrentTotalUsage -= AllocInfo->Size;
Context->CurrentTotalUsageByType[ProfileMemoryIndex] -= AllocInfo->Size;
- DriverInfo->CurrentUsage -= AllocInfo->Size;
+ DriverInfo->CurrentUsage -= AllocInfo->Size;
DriverInfo->CurrentUsageByType[ProfileMemoryIndex] -= AllocInfo->Size;
}
RemoveEntryList (&AllocInfoData->Link);
if (BasicAction == MemoryProfileActionFreePages) {
- if (AllocInfo->Buffer != (PHYSICAL_ADDRESS) (UINTN) Buffer) {
+ if (AllocInfo->Buffer != (PHYSICAL_ADDRESS)(UINTN)Buffer) {
CoreUpdateProfileAllocate (
AllocInfo->CallerAddress,
AllocInfo->Action,
AllocInfo->MemoryType,
- (UINTN) ((PHYSICAL_ADDRESS) (UINTN) Buffer - AllocInfo->Buffer),
- (VOID *) (UINTN) AllocInfo->Buffer,
+ (UINTN)((PHYSICAL_ADDRESS)(UINTN)Buffer - AllocInfo->Buffer),
+ (VOID *)(UINTN)AllocInfo->Buffer,
AllocInfoData->ActionString
);
}
- if (AllocInfo->Buffer + AllocInfo->Size != ((PHYSICAL_ADDRESS) (UINTN) Buffer + Size)) {
+
+ if (AllocInfo->Buffer + AllocInfo->Size != ((PHYSICAL_ADDRESS)(UINTN)Buffer + Size)) {
CoreUpdateProfileAllocate (
AllocInfo->CallerAddress,
AllocInfo->Action,
AllocInfo->MemoryType,
- (UINTN) ((AllocInfo->Buffer + AllocInfo->Size) - ((PHYSICAL_ADDRESS) (UINTN) Buffer + Size)),
- (VOID *) ((UINTN) Buffer + Size),
+ (UINTN)((AllocInfo->Buffer + AllocInfo->Size) - ((PHYSICAL_ADDRESS)(UINTN)Buffer + Size)),
+ (VOID *)((UINTN)Buffer + Size),
AllocInfoData->ActionString
);
}
@@ -1337,9 +1363,9 @@ CoreUpdateProfile ( IN CHAR8 *ActionString OPTIONAL
)
{
- EFI_STATUS Status;
- MEMORY_PROFILE_CONTEXT_DATA *ContextData;
- MEMORY_PROFILE_ACTION BasicAction;
+ EFI_STATUS Status;
+ MEMORY_PROFILE_CONTEXT_DATA *ContextData;
+ MEMORY_PROFILE_ACTION BasicAction;
if (!IS_UEFI_MEMORY_PROFILE_ENABLED) {
return EFI_UNSUPPORTED;
@@ -1394,6 +1420,7 @@ CoreUpdateProfile ( Status = EFI_UNSUPPORTED;
break;
}
+
CoreReleaseMemoryProfileLock ();
return Status;
@@ -1412,15 +1439,14 @@ MemoryProfileGetDataSize ( VOID
)
{
- MEMORY_PROFILE_CONTEXT_DATA *ContextData;
- MEMORY_PROFILE_DRIVER_INFO_DATA *DriverInfoData;
- MEMORY_PROFILE_ALLOC_INFO_DATA *AllocInfoData;
- LIST_ENTRY *DriverInfoList;
- LIST_ENTRY *DriverLink;
- LIST_ENTRY *AllocInfoList;
- LIST_ENTRY *AllocLink;
- UINTN TotalSize;
-
+ MEMORY_PROFILE_CONTEXT_DATA *ContextData;
+ MEMORY_PROFILE_DRIVER_INFO_DATA *DriverInfoData;
+ MEMORY_PROFILE_ALLOC_INFO_DATA *AllocInfoData;
+ LIST_ENTRY *DriverInfoList;
+ LIST_ENTRY *DriverLink;
+ LIST_ENTRY *AllocInfoList;
+ LIST_ENTRY *AllocLink;
+ UINTN TotalSize;
ContextData = GetMemoryProfileContext ();
if (ContextData == NULL) {
@@ -1432,7 +1458,8 @@ MemoryProfileGetDataSize ( DriverInfoList = ContextData->DriverInfoList;
for (DriverLink = DriverInfoList->ForwardLink;
DriverLink != DriverInfoList;
- DriverLink = DriverLink->ForwardLink) {
+ DriverLink = DriverLink->ForwardLink)
+ {
DriverInfoData = CR (
DriverLink,
MEMORY_PROFILE_DRIVER_INFO_DATA,
@@ -1444,7 +1471,8 @@ MemoryProfileGetDataSize ( AllocInfoList = DriverInfoData->AllocInfoList;
for (AllocLink = AllocInfoList->ForwardLink;
AllocLink != AllocInfoList;
- AllocLink = AllocLink->ForwardLink) {
+ AllocLink = AllocLink->ForwardLink)
+ {
AllocInfoData = CR (
AllocLink,
MEMORY_PROFILE_ALLOC_INFO_DATA,
@@ -1466,35 +1494,36 @@ MemoryProfileGetDataSize ( **/
VOID
MemoryProfileCopyData (
- IN VOID *ProfileBuffer
+ IN VOID *ProfileBuffer
)
{
- MEMORY_PROFILE_CONTEXT *Context;
- MEMORY_PROFILE_DRIVER_INFO *DriverInfo;
- MEMORY_PROFILE_ALLOC_INFO *AllocInfo;
- MEMORY_PROFILE_CONTEXT_DATA *ContextData;
- MEMORY_PROFILE_DRIVER_INFO_DATA *DriverInfoData;
- MEMORY_PROFILE_ALLOC_INFO_DATA *AllocInfoData;
- LIST_ENTRY *DriverInfoList;
- LIST_ENTRY *DriverLink;
- LIST_ENTRY *AllocInfoList;
- LIST_ENTRY *AllocLink;
- UINTN PdbSize;
- UINTN ActionStringSize;
+ MEMORY_PROFILE_CONTEXT *Context;
+ MEMORY_PROFILE_DRIVER_INFO *DriverInfo;
+ MEMORY_PROFILE_ALLOC_INFO *AllocInfo;
+ MEMORY_PROFILE_CONTEXT_DATA *ContextData;
+ MEMORY_PROFILE_DRIVER_INFO_DATA *DriverInfoData;
+ MEMORY_PROFILE_ALLOC_INFO_DATA *AllocInfoData;
+ LIST_ENTRY *DriverInfoList;
+ LIST_ENTRY *DriverLink;
+ LIST_ENTRY *AllocInfoList;
+ LIST_ENTRY *AllocLink;
+ UINTN PdbSize;
+ UINTN ActionStringSize;
ContextData = GetMemoryProfileContext ();
if (ContextData == NULL) {
- return ;
+ return;
}
Context = ProfileBuffer;
CopyMem (Context, &ContextData->Context, sizeof (MEMORY_PROFILE_CONTEXT));
- DriverInfo = (MEMORY_PROFILE_DRIVER_INFO *) (Context + 1);
+ DriverInfo = (MEMORY_PROFILE_DRIVER_INFO *)(Context + 1);
DriverInfoList = ContextData->DriverInfoList;
for (DriverLink = DriverInfoList->ForwardLink;
DriverLink != DriverInfoList;
- DriverLink = DriverLink->ForwardLink) {
+ DriverLink = DriverLink->ForwardLink)
+ {
DriverInfoData = CR (
DriverLink,
MEMORY_PROFILE_DRIVER_INFO_DATA,
@@ -1504,14 +1533,16 @@ MemoryProfileCopyData ( CopyMem (DriverInfo, &DriverInfoData->DriverInfo, sizeof (MEMORY_PROFILE_DRIVER_INFO));
if (DriverInfo->PdbStringOffset != 0) {
PdbSize = AsciiStrSize (DriverInfoData->PdbString);
- CopyMem ((VOID *) ((UINTN) DriverInfo + DriverInfo->PdbStringOffset), DriverInfoData->PdbString, PdbSize);
+ CopyMem ((VOID *)((UINTN)DriverInfo + DriverInfo->PdbStringOffset), DriverInfoData->PdbString, PdbSize);
}
- AllocInfo = (MEMORY_PROFILE_ALLOC_INFO *) ((UINTN) DriverInfo + DriverInfo->Header.Length);
+
+ AllocInfo = (MEMORY_PROFILE_ALLOC_INFO *)((UINTN)DriverInfo + DriverInfo->Header.Length);
AllocInfoList = DriverInfoData->AllocInfoList;
for (AllocLink = AllocInfoList->ForwardLink;
AllocLink != AllocInfoList;
- AllocLink = AllocLink->ForwardLink) {
+ AllocLink = AllocLink->ForwardLink)
+ {
AllocInfoData = CR (
AllocLink,
MEMORY_PROFILE_ALLOC_INFO_DATA,
@@ -1521,12 +1552,13 @@ MemoryProfileCopyData ( CopyMem (AllocInfo, &AllocInfoData->AllocInfo, sizeof (MEMORY_PROFILE_ALLOC_INFO));
if (AllocInfo->ActionStringOffset != 0) {
ActionStringSize = AsciiStrSize (AllocInfoData->ActionString);
- CopyMem ((VOID *) ((UINTN) AllocInfo + AllocInfo->ActionStringOffset), AllocInfoData->ActionString, ActionStringSize);
+ CopyMem ((VOID *)((UINTN)AllocInfo + AllocInfo->ActionStringOffset), AllocInfoData->ActionString, ActionStringSize);
}
- AllocInfo = (MEMORY_PROFILE_ALLOC_INFO *) ((UINTN) AllocInfo + AllocInfo->Header.Length);
+
+ AllocInfo = (MEMORY_PROFILE_ALLOC_INFO *)((UINTN)AllocInfo + AllocInfo->Header.Length);
}
- DriverInfo = (MEMORY_PROFILE_DRIVER_INFO *) AllocInfo;
+ DriverInfo = (MEMORY_PROFILE_DRIVER_INFO *)AllocInfo;
}
}
@@ -1549,25 +1581,25 @@ EFIAPI ProfileProtocolGetData (
IN EDKII_MEMORY_PROFILE_PROTOCOL *This,
IN OUT UINT64 *ProfileSize,
- OUT VOID *ProfileBuffer
+ OUT VOID *ProfileBuffer
)
{
- UINTN Size;
- MEMORY_PROFILE_CONTEXT_DATA *ContextData;
- BOOLEAN MemoryProfileGettingStatus;
+ UINTN Size;
+ MEMORY_PROFILE_CONTEXT_DATA *ContextData;
+ BOOLEAN MemoryProfileGettingStatus;
ContextData = GetMemoryProfileContext ();
if (ContextData == NULL) {
return EFI_UNSUPPORTED;
}
- MemoryProfileGettingStatus = mMemoryProfileGettingStatus;
+ MemoryProfileGettingStatus = mMemoryProfileGettingStatus;
mMemoryProfileGettingStatus = TRUE;
Size = MemoryProfileGetDataSize ();
if (*ProfileSize < Size) {
- *ProfileSize = Size;
+ *ProfileSize = Size;
mMemoryProfileGettingStatus = MemoryProfileGettingStatus;
return EFI_BUFFER_TOO_SMALL;
}
@@ -1604,18 +1636,18 @@ ProfileProtocolRegisterImage ( IN EFI_FV_FILETYPE FileType
)
{
- EFI_STATUS Status;
- LOADED_IMAGE_PRIVATE_DATA DriverEntry;
- VOID *EntryPointInImage;
+ EFI_STATUS Status;
+ LOADED_IMAGE_PRIVATE_DATA DriverEntry;
+ VOID *EntryPointInImage;
ZeroMem (&DriverEntry, sizeof (DriverEntry));
- DriverEntry.Info.FilePath = FilePath;
+ DriverEntry.Info.FilePath = FilePath;
DriverEntry.ImageContext.ImageAddress = ImageBase;
- DriverEntry.ImageContext.ImageSize = ImageSize;
- Status = InternalPeCoffGetEntryPoint ((VOID *) (UINTN) ImageBase, &EntryPointInImage);
+ DriverEntry.ImageContext.ImageSize = ImageSize;
+ Status = InternalPeCoffGetEntryPoint ((VOID *)(UINTN)ImageBase, &EntryPointInImage);
ASSERT_EFI_ERROR (Status);
- DriverEntry.ImageContext.EntryPoint = (PHYSICAL_ADDRESS) (UINTN) EntryPointInImage;
- DriverEntry.ImageContext.ImageType = InternalPeCoffGetSubsystem ((VOID *) (UINTN) ImageBase);
+ DriverEntry.ImageContext.EntryPoint = (PHYSICAL_ADDRESS)(UINTN)EntryPointInImage;
+ DriverEntry.ImageContext.ImageType = InternalPeCoffGetSubsystem ((VOID *)(UINTN)ImageBase);
return RegisterMemoryProfileImage (&DriverEntry, FileType);
}
@@ -1643,17 +1675,17 @@ ProfileProtocolUnregisterImage ( IN UINT64 ImageSize
)
{
- EFI_STATUS Status;
- LOADED_IMAGE_PRIVATE_DATA DriverEntry;
- VOID *EntryPointInImage;
+ EFI_STATUS Status;
+ LOADED_IMAGE_PRIVATE_DATA DriverEntry;
+ VOID *EntryPointInImage;
ZeroMem (&DriverEntry, sizeof (DriverEntry));
- DriverEntry.Info.FilePath = FilePath;
+ DriverEntry.Info.FilePath = FilePath;
DriverEntry.ImageContext.ImageAddress = ImageBase;
- DriverEntry.ImageContext.ImageSize = ImageSize;
- Status = InternalPeCoffGetEntryPoint ((VOID *) (UINTN) ImageBase, &EntryPointInImage);
+ DriverEntry.ImageContext.ImageSize = ImageSize;
+ Status = InternalPeCoffGetEntryPoint ((VOID *)(UINTN)ImageBase, &EntryPointInImage);
ASSERT_EFI_ERROR (Status);
- DriverEntry.ImageContext.EntryPoint = (PHYSICAL_ADDRESS) (UINTN) EntryPointInImage;
+ DriverEntry.ImageContext.EntryPoint = (PHYSICAL_ADDRESS)(UINTN)EntryPointInImage;
return UnregisterMemoryProfileImage (&DriverEntry);
}
@@ -1672,11 +1704,11 @@ ProfileProtocolUnregisterImage ( EFI_STATUS
EFIAPI
ProfileProtocolGetRecordingState (
- IN EDKII_MEMORY_PROFILE_PROTOCOL *This,
- OUT BOOLEAN *RecordingState
+ IN EDKII_MEMORY_PROFILE_PROTOCOL *This,
+ OUT BOOLEAN *RecordingState
)
{
- MEMORY_PROFILE_CONTEXT_DATA *ContextData;
+ MEMORY_PROFILE_CONTEXT_DATA *ContextData;
ContextData = GetMemoryProfileContext ();
if (ContextData == NULL) {
@@ -1686,6 +1718,7 @@ ProfileProtocolGetRecordingState ( if (RecordingState == NULL) {
return EFI_INVALID_PARAMETER;
}
+
*RecordingState = mMemoryProfileRecordingEnable;
return EFI_SUCCESS;
}
@@ -1703,11 +1736,11 @@ ProfileProtocolGetRecordingState ( EFI_STATUS
EFIAPI
ProfileProtocolSetRecordingState (
- IN EDKII_MEMORY_PROFILE_PROTOCOL *This,
- IN BOOLEAN RecordingState
+ IN EDKII_MEMORY_PROFILE_PROTOCOL *This,
+ IN BOOLEAN RecordingState
)
{
- MEMORY_PROFILE_CONTEXT_DATA *ContextData;
+ MEMORY_PROFILE_CONTEXT_DATA *ContextData;
ContextData = GetMemoryProfileContext ();
if (ContextData == NULL) {
@@ -1744,13 +1777,13 @@ ProfileProtocolSetRecordingState ( EFI_STATUS
EFIAPI
ProfileProtocolRecord (
- IN EDKII_MEMORY_PROFILE_PROTOCOL *This,
- IN PHYSICAL_ADDRESS CallerAddress,
- IN MEMORY_PROFILE_ACTION Action,
- IN EFI_MEMORY_TYPE MemoryType,
- IN VOID *Buffer,
- IN UINTN Size,
- IN CHAR8 *ActionString OPTIONAL
+ IN EDKII_MEMORY_PROFILE_PROTOCOL *This,
+ IN PHYSICAL_ADDRESS CallerAddress,
+ IN MEMORY_PROFILE_ACTION Action,
+ IN EFI_MEMORY_TYPE MemoryType,
+ IN VOID *Buffer,
+ IN UINTN Size,
+ IN CHAR8 *ActionString OPTIONAL
)
{
return CoreUpdateProfile (CallerAddress, Action, MemoryType, Size, Buffer, ActionString);
diff --git a/MdeModulePkg/Core/Dxe/Mem/Page.c b/MdeModulePkg/Core/Dxe/Mem/Page.c index 731bf08bc9..47d4c5d92e 100644 --- a/MdeModulePkg/Core/Dxe/Mem/Page.c +++ b/MdeModulePkg/Core/Dxe/Mem/Page.c @@ -14,38 +14,38 @@ SPDX-License-Identifier: BSD-2-Clause-Patent // Entry for tracking the memory regions for each memory type to coalesce similar memory types
//
typedef struct {
- EFI_PHYSICAL_ADDRESS BaseAddress;
- EFI_PHYSICAL_ADDRESS MaximumAddress;
- UINT64 CurrentNumberOfPages;
- UINT64 NumberOfPages;
- UINTN InformationIndex;
- BOOLEAN Special;
- BOOLEAN Runtime;
+ EFI_PHYSICAL_ADDRESS BaseAddress;
+ EFI_PHYSICAL_ADDRESS MaximumAddress;
+ UINT64 CurrentNumberOfPages;
+ UINT64 NumberOfPages;
+ UINTN InformationIndex;
+ BOOLEAN Special;
+ BOOLEAN Runtime;
} EFI_MEMORY_TYPE_STATISTICS;
//
// MemoryMap - The current memory map
//
-UINTN mMemoryMapKey = 0;
+UINTN mMemoryMapKey = 0;
-#define MAX_MAP_DEPTH 6
+#define MAX_MAP_DEPTH 6
///
/// mMapDepth - depth of new descriptor stack
///
-UINTN mMapDepth = 0;
+UINTN mMapDepth = 0;
///
/// mMapStack - space to use as temp storage to build new map descriptors
///
-MEMORY_MAP mMapStack[MAX_MAP_DEPTH];
-UINTN mFreeMapStack = 0;
+MEMORY_MAP mMapStack[MAX_MAP_DEPTH];
+UINTN mFreeMapStack = 0;
///
/// This list maintain the free memory map list
///
-LIST_ENTRY mFreeMemoryMapEntryList = INITIALIZE_LIST_HEAD_VARIABLE (mFreeMemoryMapEntryList);
-BOOLEAN mMemoryTypeInformationInitialized = FALSE;
+LIST_ENTRY mFreeMemoryMapEntryList = INITIALIZE_LIST_HEAD_VARIABLE (mFreeMemoryMapEntryList);
+BOOLEAN mMemoryTypeInformationInitialized = FALSE;
-EFI_MEMORY_TYPE_STATISTICS mMemoryTypeStatistics[EfiMaxMemoryType + 1] = {
+EFI_MEMORY_TYPE_STATISTICS mMemoryTypeStatistics[EfiMaxMemoryType + 1] = {
{ 0, MAX_ALLOC_ADDRESS, 0, 0, EfiMaxMemoryType, TRUE, FALSE }, // EfiReservedMemoryType
{ 0, MAX_ALLOC_ADDRESS, 0, 0, EfiMaxMemoryType, FALSE, FALSE }, // EfiLoaderCode
{ 0, MAX_ALLOC_ADDRESS, 0, 0, EfiMaxMemoryType, FALSE, FALSE }, // EfiLoaderData
@@ -64,10 +64,10 @@ EFI_MEMORY_TYPE_STATISTICS mMemoryTypeStatistics[EfiMaxMemoryType + 1] = { { 0, MAX_ALLOC_ADDRESS, 0, 0, EfiMaxMemoryType, FALSE, FALSE } // EfiMaxMemoryType
};
-EFI_PHYSICAL_ADDRESS mDefaultMaximumAddress = MAX_ALLOC_ADDRESS;
-EFI_PHYSICAL_ADDRESS mDefaultBaseAddress = MAX_ALLOC_ADDRESS;
+EFI_PHYSICAL_ADDRESS mDefaultMaximumAddress = MAX_ALLOC_ADDRESS;
+EFI_PHYSICAL_ADDRESS mDefaultBaseAddress = MAX_ALLOC_ADDRESS;
-EFI_MEMORY_TYPE_INFORMATION gMemoryTypeInformation[EfiMaxMemoryType + 1] = {
+EFI_MEMORY_TYPE_INFORMATION gMemoryTypeInformation[EfiMaxMemoryType + 1] = {
{ EfiReservedMemoryType, 0 },
{ EfiLoaderCode, 0 },
{ EfiLoaderData, 0 },
@@ -90,7 +90,7 @@ EFI_MEMORY_TYPE_INFORMATION gMemoryTypeInformation[EfiMaxMemoryType + 1] = { // and ready to load the module in to specified address.or else, the memory is not ready and module will be loaded at a
// address assigned by DXE core.
//
-GLOBAL_REMOVE_IF_UNREFERENCED BOOLEAN gLoadFixedAddressCodeMemoryReady = FALSE;
+GLOBAL_REMOVE_IF_UNREFERENCED BOOLEAN gLoadFixedAddressCodeMemoryReady = FALSE;
/**
Enter critical section by gaining lock on gMemoryLock.
@@ -104,8 +104,6 @@ CoreAcquireMemoryLock ( CoreAcquireLock (&gMemoryLock);
}
-
-
/**
Exit critical section by releasing lock on gMemoryLock.
@@ -118,9 +116,6 @@ CoreReleaseMemoryLock ( CoreReleaseLock (&gMemoryLock);
}
-
-
-
/**
Internal function. Removes a descriptor entry.
@@ -129,7 +124,7 @@ CoreReleaseMemoryLock ( **/
VOID
RemoveMemoryMapEntry (
- IN OUT MEMORY_MAP *Entry
+ IN OUT MEMORY_MAP *Entry
)
{
RemoveEntryList (&Entry->Link);
@@ -157,17 +152,17 @@ RemoveMemoryMapEntry ( **/
VOID
CoreAddRange (
- IN EFI_MEMORY_TYPE Type,
- IN EFI_PHYSICAL_ADDRESS Start,
- IN EFI_PHYSICAL_ADDRESS End,
- IN UINT64 Attribute
+ IN EFI_MEMORY_TYPE Type,
+ IN EFI_PHYSICAL_ADDRESS Start,
+ IN EFI_PHYSICAL_ADDRESS End,
+ IN UINT64 Attribute
)
{
- LIST_ENTRY *Link;
- MEMORY_MAP *Entry;
+ LIST_ENTRY *Link;
+ MEMORY_MAP *Entry;
ASSERT ((Start & EFI_PAGE_MASK) == 0);
- ASSERT (End > Start) ;
+ ASSERT (End > Start);
ASSERT_LOCKED (&gMemoryLock);
@@ -182,7 +177,7 @@ CoreAddRange ( // at address 0, then do not zero the page at address 0 because the page is being
// used for other purposes.
//
- if (Type == EfiConventionalMemory && Start == 0 && (End >= EFI_PAGE_SIZE - 1)) {
+ if ((Type == EfiConventionalMemory) && (Start == 0) && (End >= EFI_PAGE_SIZE - 1)) {
if ((PcdGet8 (PcdNullPointerDetectionPropertyMask) & BIT0) == 0) {
SetMem ((VOID *)(UINTN)Start, EFI_PAGE_SIZE, 0);
}
@@ -226,12 +221,9 @@ CoreAddRange ( }
if (Entry->End + 1 == Start) {
-
Start = Entry->Start;
RemoveMemoryMapEntry (Entry);
-
} else if (Entry->Start == End + 1) {
-
End = Entry->End;
RemoveMemoryMapEntry (Entry);
}
@@ -241,19 +233,19 @@ CoreAddRange ( // Add descriptor
//
- mMapStack[mMapDepth].Signature = MEMORY_MAP_SIGNATURE;
- mMapStack[mMapDepth].FromPages = FALSE;
- mMapStack[mMapDepth].Type = Type;
- mMapStack[mMapDepth].Start = Start;
- mMapStack[mMapDepth].End = End;
- mMapStack[mMapDepth].VirtualStart = 0;
- mMapStack[mMapDepth].Attribute = Attribute;
+ mMapStack[mMapDepth].Signature = MEMORY_MAP_SIGNATURE;
+ mMapStack[mMapDepth].FromPages = FALSE;
+ mMapStack[mMapDepth].Type = Type;
+ mMapStack[mMapDepth].Start = Start;
+ mMapStack[mMapDepth].End = End;
+ mMapStack[mMapDepth].VirtualStart = 0;
+ mMapStack[mMapDepth].Attribute = Attribute;
InsertTailList (&gMemoryMap, &mMapStack[mMapDepth].Link);
mMapDepth += 1;
ASSERT (mMapDepth < MAX_MAP_DEPTH);
- return ;
+ return;
}
/**
@@ -274,9 +266,9 @@ AllocateMemoryMapEntry ( VOID
)
{
- MEMORY_MAP* FreeDescriptorEntries;
- MEMORY_MAP* Entry;
- UINTN Index;
+ MEMORY_MAP *FreeDescriptorEntries;
+ MEMORY_MAP *Entry;
+ UINTN Index;
if (IsListEmpty (&mFreeMemoryMapEntryList)) {
//
@@ -292,7 +284,7 @@ AllocateMemoryMapEntry ( //
// Enque the free memmory map entries into the list
//
- for (Index = 0; Index < DEFAULT_PAGE_ALLOCATION_GRANULARITY / sizeof(MEMORY_MAP); Index++) {
+ for (Index = 0; Index < DEFAULT_PAGE_ALLOCATION_GRANULARITY / sizeof (MEMORY_MAP); Index++) {
FreeDescriptorEntries[Index].Signature = MEMORY_MAP_SIGNATURE;
InsertTailList (&mFreeMemoryMapEntryList, &FreeDescriptorEntries[Index].Link);
}
@@ -300,6 +292,7 @@ AllocateMemoryMapEntry ( return NULL;
}
}
+
//
// dequeue the first descriptor from the list
//
@@ -309,7 +302,6 @@ AllocateMemoryMapEntry ( return Entry;
}
-
/**
Internal function. Moves any memory descriptors that are on the
temporary descriptor stack to heap.
@@ -320,9 +312,9 @@ CoreFreeMemoryMapStack ( VOID
)
{
- MEMORY_MAP *Entry;
- MEMORY_MAP *Entry2;
- LIST_ENTRY *Link2;
+ MEMORY_MAP *Entry;
+ MEMORY_MAP *Entry2;
+ LIST_ENTRY *Link2;
ASSERT_LOCKED (&gMemoryLock);
@@ -330,7 +322,7 @@ CoreFreeMemoryMapStack ( // If already freeing the map stack, then return
//
if (mFreeMapStack != 0) {
- return ;
+ return;
}
//
@@ -352,14 +344,13 @@ CoreFreeMemoryMapStack ( mMapDepth -= 1;
if (mMapStack[mMapDepth].Link.ForwardLink != NULL) {
-
//
// Move this entry to general memory
//
RemoveEntryList (&mMapStack[mMapDepth].Link);
mMapStack[mMapDepth].Link.ForwardLink = NULL;
- CopyMem (Entry , &mMapStack[mMapDepth], sizeof (MEMORY_MAP));
+ CopyMem (Entry, &mMapStack[mMapDepth], sizeof (MEMORY_MAP));
Entry->FromPages = TRUE;
//
@@ -367,13 +358,12 @@ CoreFreeMemoryMapStack ( //
for (Link2 = gMemoryMap.ForwardLink; Link2 != &gMemoryMap; Link2 = Link2->ForwardLink) {
Entry2 = CR (Link2, MEMORY_MAP, Link, MEMORY_MAP_SIGNATURE);
- if (Entry2->FromPages && Entry2->Start > Entry->Start) {
+ if (Entry2->FromPages && (Entry2->Start > Entry->Start)) {
break;
}
}
InsertTailList (Link2, &Entry->Link);
-
} else {
//
// This item of mMapStack[mMapDepth] has already been dequeued from gMemoryMap list,
@@ -395,27 +385,27 @@ PromoteMemoryResource ( VOID
)
{
- LIST_ENTRY *Link;
- EFI_GCD_MAP_ENTRY *Entry;
- BOOLEAN Promoted;
- EFI_PHYSICAL_ADDRESS StartAddress;
- EFI_PHYSICAL_ADDRESS EndAddress;
- EFI_GCD_MEMORY_SPACE_DESCRIPTOR Descriptor;
+ LIST_ENTRY *Link;
+ EFI_GCD_MAP_ENTRY *Entry;
+ BOOLEAN Promoted;
+ EFI_PHYSICAL_ADDRESS StartAddress;
+ EFI_PHYSICAL_ADDRESS EndAddress;
+ EFI_GCD_MEMORY_SPACE_DESCRIPTOR Descriptor;
DEBUG ((DEBUG_PAGE, "Promote the memory resource\n"));
CoreAcquireGcdMemoryLock ();
Promoted = FALSE;
- Link = mGcdMemorySpaceMap.ForwardLink;
+ Link = mGcdMemorySpaceMap.ForwardLink;
while (Link != &mGcdMemorySpaceMap) {
-
Entry = CR (Link, EFI_GCD_MAP_ENTRY, Link, EFI_GCD_MAP_SIGNATURE);
- if (Entry->GcdMemoryType == EfiGcdMemoryTypeReserved &&
- Entry->EndAddress < MAX_ALLOC_ADDRESS &&
- (Entry->Capabilities & (EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED | EFI_MEMORY_TESTED)) ==
- (EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED)) {
+ if ((Entry->GcdMemoryType == EfiGcdMemoryTypeReserved) &&
+ (Entry->EndAddress < MAX_ALLOC_ADDRESS) &&
+ ((Entry->Capabilities & (EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED | EFI_MEMORY_TESTED)) ==
+ (EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED)))
+ {
//
// Update the GCD map
//
@@ -424,9 +414,10 @@ PromoteMemoryResource ( } else {
Entry->GcdMemoryType = EfiGcdMemoryTypeSystemMemory;
}
+
Entry->Capabilities |= EFI_MEMORY_TESTED;
- Entry->ImageHandle = gDxeCoreImageHandle;
- Entry->DeviceHandle = NULL;
+ Entry->ImageHandle = gDxeCoreImageHandle;
+ Entry->DeviceHandle = NULL;
//
// Add to allocable system memory resource
@@ -468,6 +459,7 @@ PromoteMemoryResource ( return Promoted;
}
+
/**
This function try to allocate Runtime code & Boot time code memory range. If LMFA enabled, 2 patchable PCD
PcdLoadFixAddressRuntimeCodePageNumber & PcdLoadFixAddressBootTimeCodePageNumber which are set by tools will record the
@@ -479,58 +471,61 @@ CoreLoadingFixedAddressHook ( VOID
)
{
- UINT32 RuntimeCodePageNumber;
- UINT32 BootTimeCodePageNumber;
- EFI_PHYSICAL_ADDRESS RuntimeCodeBase;
- EFI_PHYSICAL_ADDRESS BootTimeCodeBase;
- EFI_STATUS Status;
-
- //
- // Make sure these 2 areas are not initialzied.
- //
- if (!gLoadFixedAddressCodeMemoryReady) {
- RuntimeCodePageNumber = PcdGet32(PcdLoadFixAddressRuntimeCodePageNumber);
- BootTimeCodePageNumber= PcdGet32(PcdLoadFixAddressBootTimeCodePageNumber);
- RuntimeCodeBase = (EFI_PHYSICAL_ADDRESS)(gLoadModuleAtFixAddressConfigurationTable.DxeCodeTopAddress - EFI_PAGES_TO_SIZE (RuntimeCodePageNumber));
- BootTimeCodeBase = (EFI_PHYSICAL_ADDRESS)(RuntimeCodeBase - EFI_PAGES_TO_SIZE (BootTimeCodePageNumber));
- //
- // Try to allocate runtime memory.
- //
- Status = CoreAllocatePages (
- AllocateAddress,
- EfiRuntimeServicesCode,
- RuntimeCodePageNumber,
- &RuntimeCodeBase
- );
- if (EFI_ERROR(Status)) {
- //
- // Runtime memory allocation failed
- //
- return;
- }
- //
- // Try to allocate boot memory.
- //
- Status = CoreAllocatePages (
- AllocateAddress,
- EfiBootServicesCode,
- BootTimeCodePageNumber,
- &BootTimeCodeBase
- );
- if (EFI_ERROR(Status)) {
- //
- // boot memory allocation failed. Free Runtime code range and will try the allocation again when
- // new memory range is installed.
- //
- CoreFreePages (
- RuntimeCodeBase,
- RuntimeCodePageNumber
- );
- return;
- }
- gLoadFixedAddressCodeMemoryReady = TRUE;
- }
- return;
+ UINT32 RuntimeCodePageNumber;
+ UINT32 BootTimeCodePageNumber;
+ EFI_PHYSICAL_ADDRESS RuntimeCodeBase;
+ EFI_PHYSICAL_ADDRESS BootTimeCodeBase;
+ EFI_STATUS Status;
+
+ //
+ // Make sure these 2 areas are not initialzied.
+ //
+ if (!gLoadFixedAddressCodeMemoryReady) {
+ RuntimeCodePageNumber = PcdGet32 (PcdLoadFixAddressRuntimeCodePageNumber);
+ BootTimeCodePageNumber = PcdGet32 (PcdLoadFixAddressBootTimeCodePageNumber);
+ RuntimeCodeBase = (EFI_PHYSICAL_ADDRESS)(gLoadModuleAtFixAddressConfigurationTable.DxeCodeTopAddress - EFI_PAGES_TO_SIZE (RuntimeCodePageNumber));
+ BootTimeCodeBase = (EFI_PHYSICAL_ADDRESS)(RuntimeCodeBase - EFI_PAGES_TO_SIZE (BootTimeCodePageNumber));
+ //
+ // Try to allocate runtime memory.
+ //
+ Status = CoreAllocatePages (
+ AllocateAddress,
+ EfiRuntimeServicesCode,
+ RuntimeCodePageNumber,
+ &RuntimeCodeBase
+ );
+ if (EFI_ERROR (Status)) {
+ //
+ // Runtime memory allocation failed
+ //
+ return;
+ }
+
+ //
+ // Try to allocate boot memory.
+ //
+ Status = CoreAllocatePages (
+ AllocateAddress,
+ EfiBootServicesCode,
+ BootTimeCodePageNumber,
+ &BootTimeCodeBase
+ );
+ if (EFI_ERROR (Status)) {
+ //
+ // boot memory allocation failed. Free Runtime code range and will try the allocation again when
+ // new memory range is installed.
+ //
+ CoreFreePages (
+ RuntimeCodeBase,
+ RuntimeCodePageNumber
+ );
+ return;
+ }
+
+ gLoadFixedAddressCodeMemoryReady = TRUE;
+ }
+
+ return;
}
/**
@@ -556,32 +551,37 @@ CoreAddMemoryDescriptor ( IN UINT64 Attribute
)
{
- EFI_PHYSICAL_ADDRESS End;
- EFI_STATUS Status;
- UINTN Index;
- UINTN FreeIndex;
+ EFI_PHYSICAL_ADDRESS End;
+ EFI_STATUS Status;
+ UINTN Index;
+ UINTN FreeIndex;
if ((Start & EFI_PAGE_MASK) != 0) {
return;
}
- if (Type >= EfiMaxMemoryType && Type < MEMORY_TYPE_OEM_RESERVED_MIN) {
+ if ((Type >= EfiMaxMemoryType) && (Type < MEMORY_TYPE_OEM_RESERVED_MIN)) {
return;
}
+
CoreAcquireMemoryLock ();
End = Start + LShiftU64 (NumberOfPages, EFI_PAGE_SHIFT) - 1;
CoreAddRange (Type, Start, End, Attribute);
CoreFreeMemoryMapStack ();
CoreReleaseMemoryLock ();
- ApplyMemoryProtectionPolicy (EfiMaxMemoryType, Type, Start,
- LShiftU64 (NumberOfPages, EFI_PAGE_SHIFT));
+ ApplyMemoryProtectionPolicy (
+ EfiMaxMemoryType,
+ Type,
+ Start,
+ LShiftU64 (NumberOfPages, EFI_PAGE_SHIFT)
+ );
//
// If Loading Module At Fixed Address feature is enabled. try to allocate memory with Runtime code & Boot time code type
//
- if (PcdGet64(PcdLoadModuleAtFixAddressEnable) != 0) {
- CoreLoadingFixedAddressHook();
+ if (PcdGet64 (PcdLoadModuleAtFixAddressEnable) != 0) {
+ CoreLoadingFixedAddressHook ();
}
//
@@ -591,7 +591,6 @@ CoreAddMemoryDescriptor ( return;
}
-
//
// Loop through each memory type in the order specified by the gMemoryTypeInformation[] array
//
@@ -599,10 +598,11 @@ CoreAddMemoryDescriptor ( //
// Make sure the memory type in the gMemoryTypeInformation[] array is valid
//
- Type = (EFI_MEMORY_TYPE) (gMemoryTypeInformation[Index].Type);
+ Type = (EFI_MEMORY_TYPE)(gMemoryTypeInformation[Index].Type);
if ((UINT32)Type > EfiMaxMemoryType) {
continue;
}
+
if (gMemoryTypeInformation[Index].NumberOfPages != 0) {
//
// Allocate pages for the current memory type from the top of available memory
@@ -623,7 +623,7 @@ CoreAddMemoryDescriptor ( //
// Make sure the memory type in the gMemoryTypeInformation[] array is valid
//
- Type = (EFI_MEMORY_TYPE) (gMemoryTypeInformation[FreeIndex].Type);
+ Type = (EFI_MEMORY_TYPE)(gMemoryTypeInformation[FreeIndex].Type);
if ((UINT32)Type > EfiMaxMemoryType) {
continue;
}
@@ -637,6 +637,7 @@ CoreAddMemoryDescriptor ( mMemoryTypeStatistics[Type].MaximumAddress = MAX_ALLOC_ADDRESS;
}
}
+
return;
}
@@ -666,10 +667,11 @@ CoreAddMemoryDescriptor ( //
// Make sure the memory type in the gMemoryTypeInformation[] array is valid
//
- Type = (EFI_MEMORY_TYPE) (gMemoryTypeInformation[Index].Type);
+ Type = (EFI_MEMORY_TYPE)(gMemoryTypeInformation[Index].Type);
if ((UINT32)Type > EfiMaxMemoryType) {
continue;
}
+
if (gMemoryTypeInformation[Index].NumberOfPages != 0) {
CoreFreePages (
mMemoryTypeStatistics[Type].BaseAddress,
@@ -684,12 +686,13 @@ CoreAddMemoryDescriptor ( // If the number of pages reserved for a memory type is 0, then all allocations for that type
// should be in the default range.
//
- for (Type = (EFI_MEMORY_TYPE) 0; Type < EfiMaxMemoryType; Type++) {
+ for (Type = (EFI_MEMORY_TYPE)0; Type < EfiMaxMemoryType; Type++) {
for (Index = 0; gMemoryTypeInformation[Index].Type != EfiMaxMemoryType; Index++) {
if (Type == (EFI_MEMORY_TYPE)gMemoryTypeInformation[Index].Type) {
mMemoryTypeStatistics[Type].InformationIndex = Index;
}
}
+
mMemoryTypeStatistics[Type].CurrentNumberOfPages = 0;
if (mMemoryTypeStatistics[Type].MaximumAddress == MAX_ALLOC_ADDRESS) {
mMemoryTypeStatistics[Type].MaximumAddress = mDefaultMaximumAddress;
@@ -699,7 +702,6 @@ CoreAddMemoryDescriptor ( mMemoryTypeInformationInitialized = TRUE;
}
-
/**
Internal function. Converts a memory range to the specified type or attributes.
The range must exist in the memory map. Either ChangingType or
@@ -730,26 +732,25 @@ CoreConvertPagesEx ( IN UINT64 NewAttributes
)
{
+ UINT64 NumberOfBytes;
+ UINT64 End;
+ UINT64 RangeEnd;
+ UINT64 Attribute;
+ EFI_MEMORY_TYPE MemType;
+ LIST_ENTRY *Link;
+ MEMORY_MAP *Entry;
- UINT64 NumberOfBytes;
- UINT64 End;
- UINT64 RangeEnd;
- UINT64 Attribute;
- EFI_MEMORY_TYPE MemType;
- LIST_ENTRY *Link;
- MEMORY_MAP *Entry;
-
- Entry = NULL;
+ Entry = NULL;
NumberOfBytes = LShiftU64 (NumberOfPages, EFI_PAGE_SHIFT);
- End = Start + NumberOfBytes - 1;
+ End = Start + NumberOfBytes - 1;
ASSERT (NumberOfPages);
ASSERT ((Start & EFI_PAGE_MASK) == 0);
- ASSERT (End > Start) ;
+ ASSERT (End > Start);
ASSERT_LOCKED (&gMemoryLock);
- ASSERT ( (ChangingType == FALSE) || (ChangingAttributes == FALSE) );
+ ASSERT ((ChangingType == FALSE) || (ChangingAttributes == FALSE));
- if (NumberOfPages == 0 || ((Start & EFI_PAGE_MASK) != 0) || (Start >= End)) {
+ if ((NumberOfPages == 0) || ((Start & EFI_PAGE_MASK) != 0) || (Start >= End)) {
return EFI_INVALID_PARAMETER;
}
@@ -758,14 +759,13 @@ CoreConvertPagesEx ( //
while (Start < End) {
-
//
// Find the entry that the covers the range
//
for (Link = gMemoryMap.ForwardLink; Link != &gMemoryMap; Link = Link->ForwardLink) {
Entry = CR (Link, MEMORY_MAP, Link, MEMORY_MAP_SIGNATURE);
- if (Entry->Start <= Start && Entry->End > Start) {
+ if ((Entry->Start <= Start) && (Entry->End > Start)) {
break;
}
}
@@ -786,6 +786,7 @@ CoreConvertPagesEx ( return EFI_NOT_FOUND;
}
}
+
//
// Convert range to the end, or to the end of the descriptor
// if that's all we've got
@@ -800,6 +801,7 @@ CoreConvertPagesEx ( if (ChangingType) {
DEBUG ((DEBUG_PAGE, "ConvertRange: %lx-%lx to type %d\n", Start, RangeEnd, NewType));
}
+
if (ChangingAttributes) {
DEBUG ((DEBUG_PAGE, "ConvertRange: %lx-%lx to attr %lx\n", Start, RangeEnd, NewAttributes));
}
@@ -808,13 +810,14 @@ CoreConvertPagesEx ( //
// Debug code - verify conversion is allowed
//
- if (!(NewType == EfiConventionalMemory ? 1 : 0) ^ (Entry->Type == EfiConventionalMemory ? 1 : 0)) {
+ if (!((NewType == EfiConventionalMemory) ? 1 : 0) ^ ((Entry->Type == EfiConventionalMemory) ? 1 : 0)) {
DEBUG ((DEBUG_ERROR | DEBUG_PAGE, "ConvertPages: Incompatible memory types, "));
if (Entry->Type == EfiConventionalMemory) {
DEBUG ((DEBUG_ERROR | DEBUG_PAGE, "the pages to free have been freed\n"));
} else {
DEBUG ((DEBUG_ERROR | DEBUG_PAGE, "the pages to allocate have been allocated\n"));
}
+
return EFI_NOT_FOUND;
}
@@ -822,8 +825,9 @@ CoreConvertPagesEx ( // Update counters for the number of pages allocated to each memory type
//
if ((UINT32)Entry->Type < EfiMaxMemoryType) {
- if ((Start >= mMemoryTypeStatistics[Entry->Type].BaseAddress && Start <= mMemoryTypeStatistics[Entry->Type].MaximumAddress) ||
- (Start >= mDefaultBaseAddress && Start <= mDefaultMaximumAddress) ) {
+ if (((Start >= mMemoryTypeStatistics[Entry->Type].BaseAddress) && (Start <= mMemoryTypeStatistics[Entry->Type].MaximumAddress)) ||
+ ((Start >= mDefaultBaseAddress) && (Start <= mDefaultMaximumAddress)))
+ {
if (NumberOfPages > mMemoryTypeStatistics[Entry->Type].CurrentNumberOfPages) {
mMemoryTypeStatistics[Entry->Type].CurrentNumberOfPages = 0;
} else {
@@ -833,8 +837,9 @@ CoreConvertPagesEx ( }
if ((UINT32)NewType < EfiMaxMemoryType) {
- if ((Start >= mMemoryTypeStatistics[NewType].BaseAddress && Start <= mMemoryTypeStatistics[NewType].MaximumAddress) ||
- (Start >= mDefaultBaseAddress && Start <= mDefaultMaximumAddress) ) {
+ if (((Start >= mMemoryTypeStatistics[NewType].BaseAddress) && (Start <= mMemoryTypeStatistics[NewType].MaximumAddress)) ||
+ ((Start >= mDefaultBaseAddress) && (Start <= mDefaultMaximumAddress)))
+ {
mMemoryTypeStatistics[NewType].CurrentNumberOfPages += NumberOfPages;
if (mMemoryTypeStatistics[NewType].CurrentNumberOfPages > gMemoryTypeInformation[mMemoryTypeStatistics[NewType].InformationIndex].NumberOfPages) {
gMemoryTypeInformation[mMemoryTypeStatistics[NewType].InformationIndex].NumberOfPages = (UINT32)mMemoryTypeStatistics[NewType].CurrentNumberOfPages;
@@ -847,21 +852,16 @@ CoreConvertPagesEx ( // Pull range out of descriptor
//
if (Entry->Start == Start) {
-
//
// Clip start
//
Entry->Start = RangeEnd + 1;
-
} else if (Entry->End == RangeEnd) {
-
//
// Clip end
//
Entry->End = Start - 1;
-
} else {
-
//
// Pull it out of the center, clip current
//
@@ -870,7 +870,7 @@ CoreConvertPagesEx ( // Add a new one
//
mMapStack[mMapDepth].Signature = MEMORY_MAP_SIGNATURE;
- mMapStack[mMapDepth].FromPages = FALSE;
+ mMapStack[mMapDepth].FromPages = FALSE;
mMapStack[mMapDepth].Type = Entry->Type;
mMapStack[mMapDepth].Start = RangeEnd+1;
mMapStack[mMapDepth].End = Entry->End;
@@ -896,10 +896,10 @@ CoreConvertPagesEx ( //
if (ChangingType) {
Attribute = Entry->Attribute;
- MemType = NewType;
+ MemType = NewType;
} else {
Attribute = NewAttributes;
- MemType = Entry->Type;
+ MemType = Entry->Type;
}
//
@@ -916,7 +916,8 @@ CoreConvertPagesEx ( //
if (!IsHeapGuardEnabled (GUARD_HEAP_TYPE_FREED) ||
!ChangingType ||
- MemType != EfiConventionalMemory) {
+ (MemType != EfiConventionalMemory))
+ {
CoreAddRange (MemType, Start, RangeEnd, Attribute);
}
@@ -928,10 +929,10 @@ CoreConvertPagesEx ( //
if (Start == 0) {
if (RangeEnd > EFI_PAGE_SIZE) {
- DEBUG_CLEAR_MEMORY ((VOID *)(UINTN) EFI_PAGE_SIZE, (UINTN) (RangeEnd - EFI_PAGE_SIZE + 1));
+ DEBUG_CLEAR_MEMORY ((VOID *)(UINTN)EFI_PAGE_SIZE, (UINTN)(RangeEnd - EFI_PAGE_SIZE + 1));
}
} else {
- DEBUG_CLEAR_MEMORY ((VOID *)(UINTN) Start, (UINTN) (RangeEnd - Start + 1));
+ DEBUG_CLEAR_MEMORY ((VOID *)(UINTN)Start, (UINTN)(RangeEnd - Start + 1));
}
}
@@ -953,7 +954,6 @@ CoreConvertPagesEx ( return EFI_SUCCESS;
}
-
/**
Internal function. Converts a memory range to the specified type.
The range must exist in the memory map.
@@ -977,10 +977,9 @@ CoreConvertPages ( IN EFI_MEMORY_TYPE NewType
)
{
- return CoreConvertPagesEx(Start, NumberOfPages, TRUE, NewType, FALSE, 0);
+ return CoreConvertPagesEx (Start, NumberOfPages, TRUE, NewType, FALSE, 0);
}
-
/**
Internal function. Converts a memory range to use new attributes.
@@ -1002,12 +1001,11 @@ CoreUpdateMemoryAttributes ( //
// Update the attributes to the new value
//
- CoreConvertPagesEx(Start, NumberOfPages, FALSE, (EFI_MEMORY_TYPE)0, TRUE, NewAttributes);
+ CoreConvertPagesEx (Start, NumberOfPages, FALSE, (EFI_MEMORY_TYPE)0, TRUE, NewAttributes);
CoreReleaseMemoryLock ();
}
-
/**
Internal function. Finds a consecutive free page range below
the requested address.
@@ -1033,20 +1031,19 @@ CoreFindFreePagesI ( IN BOOLEAN NeedGuard
)
{
- UINT64 NumberOfBytes;
- UINT64 Target;
- UINT64 DescStart;
- UINT64 DescEnd;
- UINT64 DescNumberOfBytes;
- LIST_ENTRY *Link;
- MEMORY_MAP *Entry;
-
- if ((MaxAddress < EFI_PAGE_MASK) ||(NumberOfPages == 0)) {
+ UINT64 NumberOfBytes;
+ UINT64 Target;
+ UINT64 DescStart;
+ UINT64 DescEnd;
+ UINT64 DescNumberOfBytes;
+ LIST_ENTRY *Link;
+ MEMORY_MAP *Entry;
+
+ if ((MaxAddress < EFI_PAGE_MASK) || (NumberOfPages == 0)) {
return 0;
}
if ((MaxAddress & EFI_PAGE_MASK) != EFI_PAGE_MASK) {
-
//
// If MaxAddress is not aligned to the end of a page
//
@@ -1068,7 +1065,7 @@ CoreFindFreePagesI ( }
NumberOfBytes = LShiftU64 (NumberOfPages, EFI_PAGE_SHIFT);
- Target = 0;
+ Target = 0;
for (Link = gMemoryMap.ForwardLink; Link != &gMemoryMap; Link = Link->ForwardLink) {
Entry = CR (Link, MEMORY_MAP, Link, MEMORY_MAP_SIGNATURE);
@@ -1081,7 +1078,7 @@ CoreFindFreePagesI ( }
DescStart = Entry->Start;
- DescEnd = Entry->End;
+ DescEnd = Entry->End;
//
// If desc is past max allowed address or below min allowed address, skip it
@@ -1153,7 +1150,6 @@ CoreFindFreePagesI ( return Target;
}
-
/**
Internal function. Finds a consecutive free page range below
the requested address
@@ -1170,19 +1166,19 @@ CoreFindFreePagesI ( **/
UINT64
FindFreePages (
- IN UINT64 MaxAddress,
- IN UINT64 NoPages,
- IN EFI_MEMORY_TYPE NewType,
- IN UINTN Alignment,
- IN BOOLEAN NeedGuard
- )
+ IN UINT64 MaxAddress,
+ IN UINT64 NoPages,
+ IN EFI_MEMORY_TYPE NewType,
+ IN UINTN Alignment,
+ IN BOOLEAN NeedGuard
+ )
{
- UINT64 Start;
+ UINT64 Start;
//
// Attempt to find free pages in the preferred bin based on the requested memory type
//
- if ((UINT32)NewType < EfiMaxMemoryType && MaxAddress >= mMemoryTypeStatistics[NewType].MaximumAddress) {
+ if (((UINT32)NewType < EfiMaxMemoryType) && (MaxAddress >= mMemoryTypeStatistics[NewType].MaximumAddress)) {
Start = CoreFindFreePagesI (
mMemoryTypeStatistics[NewType].MaximumAddress,
mMemoryTypeStatistics[NewType].BaseAddress,
@@ -1200,12 +1196,19 @@ FindFreePages ( // Attempt to find free pages in the default allocation bin
//
if (MaxAddress >= mDefaultMaximumAddress) {
- Start = CoreFindFreePagesI (mDefaultMaximumAddress, 0, NoPages, NewType,
- Alignment, NeedGuard);
+ Start = CoreFindFreePagesI (
+ mDefaultMaximumAddress,
+ 0,
+ NoPages,
+ NewType,
+ Alignment,
+ NeedGuard
+ );
if (Start != 0) {
if (Start < mDefaultBaseAddress) {
mDefaultBaseAddress = Start;
}
+
return Start;
}
}
@@ -1216,8 +1219,14 @@ FindFreePages ( // address range. If this allocation fails, then there are not enough
// resources anywhere to satisfy the request.
//
- Start = CoreFindFreePagesI (MaxAddress, 0, NoPages, NewType, Alignment,
- NeedGuard);
+ Start = CoreFindFreePagesI (
+ MaxAddress,
+ 0,
+ NoPages,
+ NewType,
+ Alignment,
+ NeedGuard
+ );
if (Start != 0) {
return Start;
}
@@ -1235,7 +1244,6 @@ FindFreePages ( return FindFreePages (MaxAddress, NoPages, NewType, Alignment, NeedGuard);
}
-
/**
Allocates pages from the memory map.
@@ -1258,11 +1266,11 @@ FindFreePages ( EFI_STATUS
EFIAPI
CoreInternalAllocatePages (
- IN EFI_ALLOCATE_TYPE Type,
- IN EFI_MEMORY_TYPE MemoryType,
- IN UINTN NumberOfPages,
+ IN EFI_ALLOCATE_TYPE Type,
+ IN EFI_MEMORY_TYPE MemoryType,
+ IN UINTN NumberOfPages,
IN OUT EFI_PHYSICAL_ADDRESS *Memory,
- IN BOOLEAN NeedGuard
+ IN BOOLEAN NeedGuard
)
{
EFI_STATUS Status;
@@ -1277,8 +1285,9 @@ CoreInternalAllocatePages ( return EFI_INVALID_PARAMETER;
}
- if ((MemoryType >= EfiMaxMemoryType && MemoryType < MEMORY_TYPE_OEM_RESERVED_MIN) ||
- (MemoryType == EfiConventionalMemory) || (MemoryType == EfiPersistentMemory)) {
+ if (((MemoryType >= EfiMaxMemoryType) && (MemoryType < MEMORY_TYPE_OEM_RESERVED_MIN)) ||
+ (MemoryType == EfiConventionalMemory) || (MemoryType == EfiPersistentMemory))
+ {
return EFI_INVALID_PARAMETER;
}
@@ -1288,11 +1297,11 @@ CoreInternalAllocatePages ( Alignment = DEFAULT_PAGE_ALLOCATION_GRANULARITY;
- if (MemoryType == EfiACPIReclaimMemory ||
- MemoryType == EfiACPIMemoryNVS ||
- MemoryType == EfiRuntimeServicesCode ||
- MemoryType == EfiRuntimeServicesData) {
-
+ if ((MemoryType == EfiACPIReclaimMemory) ||
+ (MemoryType == EfiACPIMemoryNVS) ||
+ (MemoryType == EfiRuntimeServicesCode) ||
+ (MemoryType == EfiRuntimeServicesData))
+ {
Alignment = RUNTIME_PAGE_ALLOCATION_GRANULARITY;
}
@@ -1327,15 +1336,18 @@ CoreInternalAllocatePages ( //
if (Type == AllocateAddress) {
if ((NumberOfPages == 0) ||
- (NumberOfPages > RShiftU64 (MaxAddress, EFI_PAGE_SHIFT))) {
+ (NumberOfPages > RShiftU64 (MaxAddress, EFI_PAGE_SHIFT)))
+ {
return EFI_NOT_FOUND;
}
+
NumberOfBytes = LShiftU64 (NumberOfPages, EFI_PAGE_SHIFT);
- End = Start + NumberOfBytes - 1;
+ End = Start + NumberOfBytes - 1;
if ((Start >= End) ||
(Start > MaxAddress) ||
- (End > MaxAddress)) {
+ (End > MaxAddress))
+ {
return EFI_NOT_FOUND;
}
@@ -1347,20 +1359,26 @@ CoreInternalAllocatePages ( // fragmented.
//
- for (CheckType = (EFI_MEMORY_TYPE) 0; CheckType < EfiMaxMemoryType; CheckType++) {
- if (MemoryType != CheckType &&
+ for (CheckType = (EFI_MEMORY_TYPE)0; CheckType < EfiMaxMemoryType; CheckType++) {
+ if ((MemoryType != CheckType) &&
mMemoryTypeStatistics[CheckType].Special &&
- mMemoryTypeStatistics[CheckType].NumberOfPages > 0) {
- if (Start >= mMemoryTypeStatistics[CheckType].BaseAddress &&
- Start <= mMemoryTypeStatistics[CheckType].MaximumAddress) {
+ (mMemoryTypeStatistics[CheckType].NumberOfPages > 0))
+ {
+ if ((Start >= mMemoryTypeStatistics[CheckType].BaseAddress) &&
+ (Start <= mMemoryTypeStatistics[CheckType].MaximumAddress))
+ {
return EFI_NOT_FOUND;
}
- if (End >= mMemoryTypeStatistics[CheckType].BaseAddress &&
- End <= mMemoryTypeStatistics[CheckType].MaximumAddress) {
+
+ if ((End >= mMemoryTypeStatistics[CheckType].BaseAddress) &&
+ (End <= mMemoryTypeStatistics[CheckType].MaximumAddress))
+ {
return EFI_NOT_FOUND;
}
- if (Start < mMemoryTypeStatistics[CheckType].BaseAddress &&
- End > mMemoryTypeStatistics[CheckType].MaximumAddress) {
+
+ if ((Start < mMemoryTypeStatistics[CheckType].BaseAddress) &&
+ (End > mMemoryTypeStatistics[CheckType].MaximumAddress))
+ {
return EFI_NOT_FOUND;
}
}
@@ -1377,8 +1395,13 @@ CoreInternalAllocatePages ( // If not a specific address, then find an address to allocate
//
if (Type != AllocateAddress) {
- Start = FindFreePages (MaxAddress, NumberOfPages, MemoryType, Alignment,
- NeedGuard);
+ Start = FindFreePages (
+ MaxAddress,
+ NumberOfPages,
+ MemoryType,
+ Alignment,
+ NeedGuard
+ );
if (Start == 0) {
Status = EFI_OUT_OF_RESOURCES;
goto Done;
@@ -1389,9 +1412,9 @@ CoreInternalAllocatePages ( // Convert pages from FreeMemory to the requested type
//
if (NeedGuard) {
- Status = CoreConvertPagesWithGuard(Start, NumberOfPages, MemoryType);
+ Status = CoreConvertPagesWithGuard (Start, NumberOfPages, MemoryType);
} else {
- Status = CoreConvertPages(Start, NumberOfPages, MemoryType);
+ Status = CoreConvertPages (Start, NumberOfPages, MemoryType);
}
Done:
@@ -1401,6 +1424,7 @@ Done: if (NeedGuard) {
SetGuardForMemory (Start, NumberOfPages);
}
+
*Memory = Start;
}
@@ -1438,21 +1462,31 @@ CoreAllocatePages ( BOOLEAN NeedGuard;
NeedGuard = IsPageTypeToGuard (MemoryType, Type) && !mOnGuarding;
- Status = CoreInternalAllocatePages (Type, MemoryType, NumberOfPages, Memory,
- NeedGuard);
+ Status = CoreInternalAllocatePages (
+ Type,
+ MemoryType,
+ NumberOfPages,
+ Memory,
+ NeedGuard
+ );
if (!EFI_ERROR (Status)) {
CoreUpdateProfile (
- (EFI_PHYSICAL_ADDRESS) (UINTN) RETURN_ADDRESS (0),
+ (EFI_PHYSICAL_ADDRESS)(UINTN)RETURN_ADDRESS (0),
MemoryProfileActionAllocatePages,
MemoryType,
EFI_PAGES_TO_SIZE (NumberOfPages),
- (VOID *) (UINTN) *Memory,
+ (VOID *)(UINTN)*Memory,
NULL
);
InstallMemoryAttributesTableOnMemoryAllocation (MemoryType);
- ApplyMemoryProtectionPolicy (EfiConventionalMemory, MemoryType, *Memory,
- EFI_PAGES_TO_SIZE (NumberOfPages));
+ ApplyMemoryProtectionPolicy (
+ EfiConventionalMemory,
+ MemoryType,
+ *Memory,
+ EFI_PAGES_TO_SIZE (NumberOfPages)
+ );
}
+
return Status;
}
@@ -1471,16 +1505,16 @@ CoreAllocatePages ( EFI_STATUS
EFIAPI
CoreInternalFreePages (
- IN EFI_PHYSICAL_ADDRESS Memory,
- IN UINTN NumberOfPages,
- OUT EFI_MEMORY_TYPE *MemoryType OPTIONAL
+ IN EFI_PHYSICAL_ADDRESS Memory,
+ IN UINTN NumberOfPages,
+ OUT EFI_MEMORY_TYPE *MemoryType OPTIONAL
)
{
- EFI_STATUS Status;
- LIST_ENTRY *Link;
- MEMORY_MAP *Entry;
- UINTN Alignment;
- BOOLEAN IsGuarded;
+ EFI_STATUS Status;
+ LIST_ENTRY *Link;
+ MEMORY_MAP *Entry;
+ UINTN Alignment;
+ BOOLEAN IsGuarded;
//
// Free the range
@@ -1491,13 +1525,14 @@ CoreInternalFreePages ( // Find the entry that the covers the range
//
IsGuarded = FALSE;
- Entry = NULL;
+ Entry = NULL;
for (Link = gMemoryMap.ForwardLink; Link != &gMemoryMap; Link = Link->ForwardLink) {
- Entry = CR(Link, MEMORY_MAP, Link, MEMORY_MAP_SIGNATURE);
- if (Entry->Start <= Memory && Entry->End > Memory) {
- break;
+ Entry = CR (Link, MEMORY_MAP, Link, MEMORY_MAP_SIGNATURE);
+ if ((Entry->Start <= Memory) && (Entry->End > Memory)) {
+ break;
}
}
+
if (Link == &gMemoryMap) {
Status = EFI_NOT_FOUND;
goto Done;
@@ -1506,13 +1541,12 @@ CoreInternalFreePages ( Alignment = DEFAULT_PAGE_ALLOCATION_GRANULARITY;
ASSERT (Entry != NULL);
- if (Entry->Type == EfiACPIReclaimMemory ||
- Entry->Type == EfiACPIMemoryNVS ||
- Entry->Type == EfiRuntimeServicesCode ||
- Entry->Type == EfiRuntimeServicesData) {
-
+ if ((Entry->Type == EfiACPIReclaimMemory) ||
+ (Entry->Type == EfiACPIMemoryNVS) ||
+ (Entry->Type == EfiRuntimeServicesCode) ||
+ (Entry->Type == EfiRuntimeServicesData))
+ {
Alignment = RUNTIME_PAGE_ALLOCATION_GRANULARITY;
-
}
if ((Memory & (Alignment - 1)) != 0) {
@@ -1530,8 +1564,11 @@ CoreInternalFreePages ( IsGuarded = IsPageTypeToGuard (Entry->Type, AllocateAnyPages) &&
IsMemoryGuarded (Memory);
if (IsGuarded) {
- Status = CoreConvertPagesWithGuard (Memory, NumberOfPages,
- EfiConventionalMemory);
+ Status = CoreConvertPagesWithGuard (
+ Memory,
+ NumberOfPages,
+ EfiConventionalMemory
+ );
} else {
Status = CoreConvertPages (Memory, NumberOfPages, EfiConventionalMemory);
}
@@ -1559,24 +1596,29 @@ CoreFreePages ( IN UINTN NumberOfPages
)
{
- EFI_STATUS Status;
- EFI_MEMORY_TYPE MemoryType;
+ EFI_STATUS Status;
+ EFI_MEMORY_TYPE MemoryType;
Status = CoreInternalFreePages (Memory, NumberOfPages, &MemoryType);
if (!EFI_ERROR (Status)) {
GuardFreedPagesChecked (Memory, NumberOfPages);
CoreUpdateProfile (
- (EFI_PHYSICAL_ADDRESS) (UINTN) RETURN_ADDRESS (0),
+ (EFI_PHYSICAL_ADDRESS)(UINTN)RETURN_ADDRESS (0),
MemoryProfileActionFreePages,
MemoryType,
EFI_PAGES_TO_SIZE (NumberOfPages),
- (VOID *) (UINTN) Memory,
+ (VOID *)(UINTN)Memory,
NULL
);
InstallMemoryAttributesTableOnMemoryAllocation (MemoryType);
- ApplyMemoryProtectionPolicy (MemoryType, EfiConventionalMemory, Memory,
- EFI_PAGES_TO_SIZE (NumberOfPages));
+ ApplyMemoryProtectionPolicy (
+ MemoryType,
+ EfiConventionalMemory,
+ Memory,
+ EFI_PAGES_TO_SIZE (NumberOfPages)
+ );
}
+
return Status;
}
@@ -1604,7 +1646,7 @@ MergeMemoryMapDescriptor ( //
// Traverse the array of descriptors in MemoryMap
//
- for (; MemoryMap != MemoryMapDescriptor; MemoryMap = NEXT_MEMORY_DESCRIPTOR (MemoryMap, DescriptorSize)) {
+ for ( ; MemoryMap != MemoryMapDescriptor; MemoryMap = NEXT_MEMORY_DESCRIPTOR (MemoryMap, DescriptorSize)) {
//
// Check to see if the Type fields are identical.
//
@@ -1701,17 +1743,17 @@ CoreGetMemoryMap ( OUT UINT32 *DescriptorVersion
)
{
- EFI_STATUS Status;
- UINTN Size;
- UINTN BufferSize;
- UINTN NumberOfEntries;
- LIST_ENTRY *Link;
- MEMORY_MAP *Entry;
- EFI_GCD_MAP_ENTRY *GcdMapEntry;
- EFI_GCD_MAP_ENTRY MergeGcdMapEntry;
- EFI_MEMORY_TYPE Type;
- EFI_MEMORY_DESCRIPTOR *MemoryMapStart;
- EFI_MEMORY_DESCRIPTOR *MemoryMapEnd;
+ EFI_STATUS Status;
+ UINTN Size;
+ UINTN BufferSize;
+ UINTN NumberOfEntries;
+ LIST_ENTRY *Link;
+ MEMORY_MAP *Entry;
+ EFI_GCD_MAP_ENTRY *GcdMapEntry;
+ EFI_GCD_MAP_ENTRY MergeGcdMapEntry;
+ EFI_MEMORY_TYPE Type;
+ EFI_MEMORY_DESCRIPTOR *MemoryMapStart;
+ EFI_MEMORY_DESCRIPTOR *MemoryMapEnd;
//
// Make sure the parameters are valid
@@ -1732,8 +1774,9 @@ CoreGetMemoryMap ( if ((GcdMapEntry->GcdMemoryType == EfiGcdMemoryTypePersistent) ||
(GcdMapEntry->GcdMemoryType == EfiGcdMemoryTypeReserved) ||
((GcdMapEntry->GcdMemoryType == EfiGcdMemoryTypeMemoryMappedIo) &&
- ((GcdMapEntry->Attributes & EFI_MEMORY_RUNTIME) == EFI_MEMORY_RUNTIME))) {
- NumberOfEntries ++;
+ ((GcdMapEntry->Attributes & EFI_MEMORY_RUNTIME) == EFI_MEMORY_RUNTIME)))
+ {
+ NumberOfEntries++;
}
}
@@ -1744,7 +1787,7 @@ CoreGetMemoryMap ( // prevent people from having pointer math bugs in their code.
// now you have to use *DescriptorSize to make things work.
//
- Size += sizeof(UINT64) - (Size % sizeof (UINT64));
+ Size += sizeof (UINT64) - (Size % sizeof (UINT64));
if (DescriptorSize != NULL) {
*DescriptorSize = Size;
@@ -1786,10 +1829,10 @@ CoreGetMemoryMap ( //
// Convert internal map into an EFI_MEMORY_DESCRIPTOR
//
- MemoryMap->Type = Entry->Type;
- MemoryMap->PhysicalStart = Entry->Start;
- MemoryMap->VirtualStart = Entry->VirtualStart;
- MemoryMap->NumberOfPages = RShiftU64 (Entry->End - Entry->Start + 1, EFI_PAGE_SHIFT);
+ MemoryMap->Type = Entry->Type;
+ MemoryMap->PhysicalStart = Entry->Start;
+ MemoryMap->VirtualStart = Entry->VirtualStart;
+ MemoryMap->NumberOfPages = RShiftU64 (Entry->End - Entry->Start + 1, EFI_PAGE_SHIFT);
//
// If the memory type is EfiConventionalMemory, then determine if the range is part of a
// memory type bin and needs to be converted to the same memory type as the rest of the
@@ -1798,15 +1841,17 @@ CoreGetMemoryMap ( // differences across reboots.
//
if (MemoryMap->Type == EfiConventionalMemory) {
- for (Type = (EFI_MEMORY_TYPE) 0; Type < EfiMaxMemoryType; Type++) {
+ for (Type = (EFI_MEMORY_TYPE)0; Type < EfiMaxMemoryType; Type++) {
if (mMemoryTypeStatistics[Type].Special &&
- mMemoryTypeStatistics[Type].NumberOfPages > 0 &&
- Entry->Start >= mMemoryTypeStatistics[Type].BaseAddress &&
- Entry->End <= mMemoryTypeStatistics[Type].MaximumAddress) {
+ (mMemoryTypeStatistics[Type].NumberOfPages > 0) &&
+ (Entry->Start >= mMemoryTypeStatistics[Type].BaseAddress) &&
+ (Entry->End <= mMemoryTypeStatistics[Type].MaximumAddress))
+ {
MemoryMap->Type = Type;
}
}
}
+
MemoryMap->Attribute = Entry->Attribute;
if (MemoryMap->Type < EfiMaxMemoryType) {
if (mMemoryTypeStatistics[MemoryMap->Type].Runtime) {
@@ -1821,7 +1866,6 @@ CoreGetMemoryMap ( MemoryMap = MergeMemoryMapDescriptor (MemoryMapStart, MemoryMap, Size);
}
-
ZeroMem (&MergeGcdMapEntry, sizeof (MergeGcdMapEntry));
GcdMapEntry = NULL;
for (Link = mGcdMemorySpaceMap.ForwardLink; ; Link = Link->ForwardLink) {
@@ -1834,15 +1878,17 @@ CoreGetMemoryMap ( if ((MergeGcdMapEntry.Capabilities == GcdMapEntry->Capabilities) &&
(MergeGcdMapEntry.Attributes == GcdMapEntry->Attributes) &&
(MergeGcdMapEntry.GcdMemoryType == GcdMapEntry->GcdMemoryType) &&
- (MergeGcdMapEntry.GcdIoType == GcdMapEntry->GcdIoType)) {
- MergeGcdMapEntry.EndAddress = GcdMapEntry->EndAddress;
+ (MergeGcdMapEntry.GcdIoType == GcdMapEntry->GcdIoType))
+ {
+ MergeGcdMapEntry.EndAddress = GcdMapEntry->EndAddress;
continue;
}
}
if ((MergeGcdMapEntry.GcdMemoryType == EfiGcdMemoryTypeReserved) ||
((MergeGcdMapEntry.GcdMemoryType == EfiGcdMemoryTypeMemoryMappedIo) &&
- ((MergeGcdMapEntry.Attributes & EFI_MEMORY_RUNTIME) == EFI_MEMORY_RUNTIME))) {
+ ((MergeGcdMapEntry.Attributes & EFI_MEMORY_RUNTIME) == EFI_MEMORY_RUNTIME)))
+ {
//
// Page Align GCD range is required. When it is converted to EFI_MEMORY_DESCRIPTOR,
// it will be recorded as page PhysicalStart and NumberOfPages.
@@ -1857,7 +1903,7 @@ CoreGetMemoryMap ( MemoryMap->VirtualStart = 0;
MemoryMap->NumberOfPages = RShiftU64 ((MergeGcdMapEntry.EndAddress - MergeGcdMapEntry.BaseAddress + 1), EFI_PAGE_SHIFT);
MemoryMap->Attribute = (MergeGcdMapEntry.Attributes & ~EFI_MEMORY_PORT_IO) |
- (MergeGcdMapEntry.Capabilities & (EFI_CACHE_ATTRIBUTE_MASK | EFI_MEMORY_ATTRIBUTE_MASK));
+ (MergeGcdMapEntry.Capabilities & (EFI_CACHE_ATTRIBUTE_MASK | EFI_MEMORY_ATTRIBUTE_MASK));
if (MergeGcdMapEntry.GcdMemoryType == EfiGcdMemoryTypeReserved) {
MemoryMap->Type = EfiReservedMemoryType;
@@ -1891,8 +1937,8 @@ CoreGetMemoryMap ( MemoryMap->VirtualStart = 0;
MemoryMap->NumberOfPages = RShiftU64 ((MergeGcdMapEntry.EndAddress - MergeGcdMapEntry.BaseAddress + 1), EFI_PAGE_SHIFT);
MemoryMap->Attribute = MergeGcdMapEntry.Attributes | EFI_MEMORY_NV |
- (MergeGcdMapEntry.Capabilities & (EFI_CACHE_ATTRIBUTE_MASK | EFI_MEMORY_ATTRIBUTE_MASK));
- MemoryMap->Type = EfiPersistentMemory;
+ (MergeGcdMapEntry.Capabilities & (EFI_CACHE_ATTRIBUTE_MASK | EFI_MEMORY_ATTRIBUTE_MASK));
+ MemoryMap->Type = EfiPersistentMemory;
//
// Check to see if the new Memory Map Descriptor can be merged with an
@@ -1900,12 +1946,14 @@ CoreGetMemoryMap ( //
MemoryMap = MergeMemoryMapDescriptor (MemoryMapStart, MemoryMap, Size);
}
+
if (Link == &mGcdMemorySpaceMap) {
//
// break loop when arrive at head.
//
break;
}
+
if (GcdMapEntry != NULL) {
//
// Copy new GCD map entry for the following GCD range merge
@@ -1931,11 +1979,12 @@ CoreGetMemoryMap ( // all supported OSs.
//
MemoryMapEnd = MemoryMap;
- MemoryMap = MemoryMapStart;
+ MemoryMap = MemoryMapStart;
while (MemoryMap < MemoryMapEnd) {
MemoryMap->Attribute &= ~(UINT64)EFI_MEMORY_ACCESS_MASK;
- MemoryMap = NEXT_MEMORY_DESCRIPTOR (MemoryMap, Size);
+ MemoryMap = NEXT_MEMORY_DESCRIPTOR (MemoryMap, Size);
}
+
MergeMemoryMap (MemoryMapStart, &BufferSize, Size);
MemoryMapEnd = (EFI_MEMORY_DESCRIPTOR *)((UINT8 *)MemoryMapStart + BufferSize);
@@ -1957,12 +2006,11 @@ Done: DEBUG_CODE (
DumpGuardedMemoryBitmap ();
- );
+ );
return Status;
}
-
/**
Internal function. Used by the pool functions to allocate pages
to back pool allocation requests.
@@ -1977,19 +2025,24 @@ Done: **/
VOID *
CoreAllocatePoolPages (
- IN EFI_MEMORY_TYPE PoolType,
- IN UINTN NumberOfPages,
- IN UINTN Alignment,
- IN BOOLEAN NeedGuard
+ IN EFI_MEMORY_TYPE PoolType,
+ IN UINTN NumberOfPages,
+ IN UINTN Alignment,
+ IN BOOLEAN NeedGuard
)
{
- UINT64 Start;
+ UINT64 Start;
//
// Find the pages to convert
//
- Start = FindFreePages (MAX_ALLOC_ADDRESS, NumberOfPages, PoolType, Alignment,
- NeedGuard);
+ Start = FindFreePages (
+ MAX_ALLOC_ADDRESS,
+ NumberOfPages,
+ PoolType,
+ Alignment,
+ NeedGuard
+ );
//
// Convert it to boot services data
@@ -2004,10 +2057,9 @@ CoreAllocatePoolPages ( }
}
- return (VOID *)(UINTN) Start;
+ return (VOID *)(UINTN)Start;
}
-
/**
Internal function. Frees pool pages allocated via AllocatePoolPages ()
@@ -2017,15 +2069,13 @@ CoreAllocatePoolPages ( **/
VOID
CoreFreePoolPages (
- IN EFI_PHYSICAL_ADDRESS Memory,
- IN UINTN NumberOfPages
+ IN EFI_PHYSICAL_ADDRESS Memory,
+ IN UINTN NumberOfPages
)
{
CoreConvertPages (Memory, NumberOfPages, EfiConventionalMemory);
}
-
-
/**
Make sure the memory map is following all the construction rules,
it is the last time to check memory map error before exit boot services.
@@ -2039,19 +2089,18 @@ CoreFreePoolPages ( **/
EFI_STATUS
CoreTerminateMemoryMap (
- IN UINTN MapKey
+ IN UINTN MapKey
)
{
- EFI_STATUS Status;
- LIST_ENTRY *Link;
- MEMORY_MAP *Entry;
+ EFI_STATUS Status;
+ LIST_ENTRY *Link;
+ MEMORY_MAP *Entry;
Status = EFI_SUCCESS;
CoreAcquireMemoryLock ();
if (MapKey == mMemoryMapKey) {
-
//
// Make sure the memory map is following all the construction rules
// This is the last chance we will be able to display any messages on
@@ -2059,18 +2108,19 @@ CoreTerminateMemoryMap ( //
for (Link = gMemoryMap.ForwardLink; Link != &gMemoryMap; Link = Link->ForwardLink) {
- Entry = CR(Link, MEMORY_MAP, Link, MEMORY_MAP_SIGNATURE);
+ Entry = CR (Link, MEMORY_MAP, Link, MEMORY_MAP_SIGNATURE);
if (Entry->Type < EfiMaxMemoryType) {
if (mMemoryTypeStatistics[Entry->Type].Runtime) {
ASSERT (Entry->Type != EfiACPIReclaimMemory);
ASSERT (Entry->Type != EfiACPIMemoryNVS);
if ((Entry->Start & (RUNTIME_PAGE_ALLOCATION_GRANULARITY - 1)) != 0) {
- DEBUG((DEBUG_ERROR | DEBUG_PAGE, "ExitBootServices: A RUNTIME memory entry is not on a proper alignment.\n"));
+ DEBUG ((DEBUG_ERROR | DEBUG_PAGE, "ExitBootServices: A RUNTIME memory entry is not on a proper alignment.\n"));
Status = EFI_INVALID_PARAMETER;
goto Done;
}
+
if (((Entry->End + 1) & (RUNTIME_PAGE_ALLOCATION_GRANULARITY - 1)) != 0) {
- DEBUG((DEBUG_ERROR | DEBUG_PAGE, "ExitBootServices: A RUNTIME memory entry is not on a proper alignment.\n"));
+ DEBUG ((DEBUG_ERROR | DEBUG_PAGE, "ExitBootServices: A RUNTIME memory entry is not on a proper alignment.\n"));
Status = EFI_INVALID_PARAMETER;
goto Done;
}
@@ -2094,12 +2144,3 @@ Done: return Status;
}
-
-
-
-
-
-
-
-
-
diff --git a/MdeModulePkg/Core/Dxe/Mem/Pool.c b/MdeModulePkg/Core/Dxe/Mem/Pool.c index 734fc94bf6..7aaf501600 100644 --- a/MdeModulePkg/Core/Dxe/Mem/Pool.c +++ b/MdeModulePkg/Core/Dxe/Mem/Pool.c @@ -10,36 +10,35 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include "Imem.h"
#include "HeapGuard.h"
-STATIC EFI_LOCK mPoolMemoryLock = EFI_INITIALIZE_LOCK_VARIABLE (TPL_NOTIFY);
+STATIC EFI_LOCK mPoolMemoryLock = EFI_INITIALIZE_LOCK_VARIABLE (TPL_NOTIFY);
-#define POOL_FREE_SIGNATURE SIGNATURE_32('p','f','r','0')
+#define POOL_FREE_SIGNATURE SIGNATURE_32('p','f','r','0')
typedef struct {
- UINT32 Signature;
- UINT32 Index;
- LIST_ENTRY Link;
+ UINT32 Signature;
+ UINT32 Index;
+ LIST_ENTRY Link;
} POOL_FREE;
-
-#define POOL_HEAD_SIGNATURE SIGNATURE_32('p','h','d','0')
-#define POOLPAGE_HEAD_SIGNATURE SIGNATURE_32('p','h','d','1')
+#define POOL_HEAD_SIGNATURE SIGNATURE_32('p','h','d','0')
+#define POOLPAGE_HEAD_SIGNATURE SIGNATURE_32('p','h','d','1')
typedef struct {
- UINT32 Signature;
- UINT32 Reserved;
- EFI_MEMORY_TYPE Type;
- UINTN Size;
- CHAR8 Data[1];
+ UINT32 Signature;
+ UINT32 Reserved;
+ EFI_MEMORY_TYPE Type;
+ UINTN Size;
+ CHAR8 Data[1];
} POOL_HEAD;
-#define SIZE_OF_POOL_HEAD OFFSET_OF(POOL_HEAD,Data)
+#define SIZE_OF_POOL_HEAD OFFSET_OF(POOL_HEAD,Data)
-#define POOL_TAIL_SIGNATURE SIGNATURE_32('p','t','a','l')
+#define POOL_TAIL_SIGNATURE SIGNATURE_32('p','t','a','l')
typedef struct {
- UINT32 Signature;
- UINT32 Reserved;
- UINTN Size;
+ UINT32 Signature;
+ UINT32 Reserved;
+ UINTN Size;
} POOL_TAIL;
-#define POOL_OVERHEAD (SIZE_OF_POOL_HEAD + sizeof(POOL_TAIL))
+#define POOL_OVERHEAD (SIZE_OF_POOL_HEAD + sizeof(POOL_TAIL))
#define HEAD_TO_TAIL(a) \
((POOL_TAIL *) (((CHAR8 *) (a)) + (a)->Size - sizeof(POOL_TAIL)));
@@ -49,16 +48,16 @@ typedef struct { // blocks between bins by splitting them up, while not wasting too much memory
// as we would in a strict power-of-2 sequence
//
-STATIC CONST UINT16 mPoolSizeTable[] = {
+STATIC CONST UINT16 mPoolSizeTable[] = {
128, 256, 384, 640, 1024, 1664, 2688, 4352, 7040, 11392, 18432, 29824
};
-#define SIZE_TO_LIST(a) (GetPoolIndexFromSize (a))
-#define LIST_TO_SIZE(a) (mPoolSizeTable [a])
+#define SIZE_TO_LIST(a) (GetPoolIndexFromSize (a))
+#define LIST_TO_SIZE(a) (mPoolSizeTable [a])
-#define MAX_POOL_LIST (ARRAY_SIZE (mPoolSizeTable))
+#define MAX_POOL_LIST (ARRAY_SIZE (mPoolSizeTable))
-#define MAX_POOL_SIZE (MAX_ADDRESS - POOL_OVERHEAD)
+#define MAX_POOL_SIZE (MAX_ADDRESS - POOL_OVERHEAD)
//
// Globals
@@ -66,22 +65,22 @@ STATIC CONST UINT16 mPoolSizeTable[] = { #define POOL_SIGNATURE SIGNATURE_32('p','l','s','t')
typedef struct {
- INTN Signature;
- UINTN Used;
- EFI_MEMORY_TYPE MemoryType;
- LIST_ENTRY FreeList[MAX_POOL_LIST];
- LIST_ENTRY Link;
+ INTN Signature;
+ UINTN Used;
+ EFI_MEMORY_TYPE MemoryType;
+ LIST_ENTRY FreeList[MAX_POOL_LIST];
+ LIST_ENTRY Link;
} POOL;
//
// Pool header for each memory type.
//
-POOL mPoolHead[EfiMaxMemoryType];
+POOL mPoolHead[EfiMaxMemoryType];
//
// List of pool header to search for the appropriate memory type.
//
-LIST_ENTRY mPoolHeadList = INITIALIZE_LIST_HEAD_VARIABLE (mPoolHeadList);
+LIST_ENTRY mPoolHeadList = INITIALIZE_LIST_HEAD_VARIABLE (mPoolHeadList);
/**
Get pool size table index from the specified size.
@@ -94,16 +93,17 @@ LIST_ENTRY mPoolHeadList = INITIALIZE_LIST_HEAD_VARIABLE (mPoolHeadList); STATIC
UINTN
GetPoolIndexFromSize (
- UINTN Size
+ UINTN Size
)
{
- UINTN Index;
+ UINTN Index;
for (Index = 0; Index < MAX_POOL_LIST; Index++) {
- if (mPoolSizeTable [Index] >= Size) {
+ if (mPoolSizeTable[Index] >= Size) {
return Index;
}
}
+
return MAX_POOL_LIST;
}
@@ -119,17 +119,16 @@ CoreInitializePool ( UINTN Type;
UINTN Index;
- for (Type=0; Type < EfiMaxMemoryType; Type++) {
+ for (Type = 0; Type < EfiMaxMemoryType; Type++) {
mPoolHead[Type].Signature = 0;
mPoolHead[Type].Used = 0;
- mPoolHead[Type].MemoryType = (EFI_MEMORY_TYPE) Type;
- for (Index=0; Index < MAX_POOL_LIST; Index++) {
+ mPoolHead[Type].MemoryType = (EFI_MEMORY_TYPE)Type;
+ for (Index = 0; Index < MAX_POOL_LIST; Index++) {
InitializeListHead (&mPoolHead[Type].FreeList[Index]);
}
}
}
-
/**
Look up pool head for specified memory type.
@@ -143,9 +142,9 @@ LookupPoolHead ( IN EFI_MEMORY_TYPE MemoryType
)
{
- LIST_ENTRY *Link;
- POOL *Pool;
- UINTN Index;
+ LIST_ENTRY *Link;
+ POOL *Pool;
+ UINTN Index;
if ((UINT32)MemoryType < EfiMaxMemoryType) {
return &mPoolHead[MemoryType];
@@ -156,10 +155,9 @@ LookupPoolHead ( // OS loaders that are provided by operating system vendors.
// MemoryType values in the range 0x70000000..0x7FFFFFFF are reserved for OEM use.
//
- if ((UINT32) MemoryType >= MEMORY_TYPE_OEM_RESERVED_MIN) {
-
+ if ((UINT32)MemoryType >= MEMORY_TYPE_OEM_RESERVED_MIN) {
for (Link = mPoolHeadList.ForwardLink; Link != &mPoolHeadList; Link = Link->ForwardLink) {
- Pool = CR(Link, POOL, Link, POOL_SIGNATURE);
+ Pool = CR (Link, POOL, Link, POOL_SIGNATURE);
if (Pool->MemoryType == MemoryType) {
return Pool;
}
@@ -170,10 +168,10 @@ LookupPoolHead ( return NULL;
}
- Pool->Signature = POOL_SIGNATURE;
- Pool->Used = 0;
+ Pool->Signature = POOL_SIGNATURE;
+ Pool->Used = 0;
Pool->MemoryType = MemoryType;
- for (Index=0; Index < MAX_POOL_LIST; Index++) {
+ for (Index = 0; Index < MAX_POOL_LIST; Index++) {
InitializeListHead (&Pool->FreeList[Index]);
}
@@ -185,8 +183,6 @@ LookupPoolHead ( return NULL;
}
-
-
/**
Allocate pool of a particular type.
@@ -210,14 +206,15 @@ CoreInternalAllocatePool ( OUT VOID **Buffer
)
{
- EFI_STATUS Status;
- BOOLEAN NeedGuard;
+ EFI_STATUS Status;
+ BOOLEAN NeedGuard;
//
// If it's not a valid type, fail it
//
- if ((PoolType >= EfiMaxMemoryType && PoolType < MEMORY_TYPE_OEM_RESERVED_MIN) ||
- (PoolType == EfiConventionalMemory) || (PoolType == EfiPersistentMemory)) {
+ if (((PoolType >= EfiMaxMemoryType) && (PoolType < MEMORY_TYPE_OEM_RESERVED_MIN)) ||
+ (PoolType == EfiConventionalMemory) || (PoolType == EfiPersistentMemory))
+ {
return EFI_INVALID_PARAMETER;
}
@@ -278,7 +275,7 @@ CoreAllocatePool ( Status = CoreInternalAllocatePool (PoolType, Size, Buffer);
if (!EFI_ERROR (Status)) {
CoreUpdateProfile (
- (EFI_PHYSICAL_ADDRESS) (UINTN) RETURN_ADDRESS (0),
+ (EFI_PHYSICAL_ADDRESS)(UINTN)RETURN_ADDRESS (0),
MemoryProfileActionAllocatePool,
PoolType,
Size,
@@ -287,6 +284,7 @@ CoreAllocatePool ( );
InstallMemoryAttributesTableOnMemoryAllocation (PoolType);
}
+
return Status;
}
@@ -305,10 +303,10 @@ CoreAllocatePool ( STATIC
VOID *
CoreAllocatePoolPagesI (
- IN EFI_MEMORY_TYPE PoolType,
- IN UINTN NoPages,
- IN UINTN Granularity,
- IN BOOLEAN NeedGuard
+ IN EFI_MEMORY_TYPE PoolType,
+ IN UINTN NoPages,
+ IN UINTN Granularity,
+ IN BOOLEAN NeedGuard
)
{
VOID *Buffer;
@@ -326,9 +324,15 @@ CoreAllocatePoolPagesI ( if (NeedGuard) {
SetGuardForMemory ((EFI_PHYSICAL_ADDRESS)(UINTN)Buffer, NoPages);
}
- ApplyMemoryProtectionPolicy(EfiConventionalMemory, PoolType,
- (EFI_PHYSICAL_ADDRESS)(UINTN)Buffer, EFI_PAGES_TO_SIZE (NoPages));
+
+ ApplyMemoryProtectionPolicy (
+ EfiConventionalMemory,
+ PoolType,
+ (EFI_PHYSICAL_ADDRESS)(UINTN)Buffer,
+ EFI_PAGES_TO_SIZE (NoPages)
+ );
}
+
return Buffer;
}
@@ -350,27 +354,27 @@ CoreAllocatePoolI ( IN BOOLEAN NeedGuard
)
{
- POOL *Pool;
- POOL_FREE *Free;
- POOL_HEAD *Head;
- POOL_TAIL *Tail;
- CHAR8 *NewPage;
- VOID *Buffer;
- UINTN Index;
- UINTN FSize;
- UINTN Offset, MaxOffset;
- UINTN NoPages;
- UINTN Granularity;
- BOOLEAN HasPoolTail;
- BOOLEAN PageAsPool;
+ POOL *Pool;
+ POOL_FREE *Free;
+ POOL_HEAD *Head;
+ POOL_TAIL *Tail;
+ CHAR8 *NewPage;
+ VOID *Buffer;
+ UINTN Index;
+ UINTN FSize;
+ UINTN Offset, MaxOffset;
+ UINTN NoPages;
+ UINTN Granularity;
+ BOOLEAN HasPoolTail;
+ BOOLEAN PageAsPool;
ASSERT_LOCKED (&mPoolMemoryLock);
- if (PoolType == EfiACPIReclaimMemory ||
- PoolType == EfiACPIMemoryNVS ||
- PoolType == EfiRuntimeServicesCode ||
- PoolType == EfiRuntimeServicesData) {
-
+ if ((PoolType == EfiACPIReclaimMemory) ||
+ (PoolType == EfiACPIMemoryNVS) ||
+ (PoolType == EfiRuntimeServicesCode) ||
+ (PoolType == EfiRuntimeServicesData))
+ {
Granularity = RUNTIME_PAGE_ALLOCATION_GRANULARITY;
} else {
Granularity = DEFAULT_PAGE_ALLOCATION_GRANULARITY;
@@ -380,8 +384,8 @@ CoreAllocatePoolI ( // Adjust the size by the pool header & tail overhead
//
- HasPoolTail = !(NeedGuard &&
- ((PcdGet8 (PcdHeapGuardPropertyMask) & BIT7) == 0));
+ HasPoolTail = !(NeedGuard &&
+ ((PcdGet8 (PcdHeapGuardPropertyMask) & BIT7) == 0));
PageAsPool = (IsHeapGuardEnabled (GUARD_HEAP_TYPE_FREED) && !mOnGuarding);
//
@@ -392,27 +396,30 @@ CoreAllocatePoolI ( Size = ALIGN_VARIABLE (Size);
Size += POOL_OVERHEAD;
- Index = SIZE_TO_LIST(Size);
- Pool = LookupPoolHead (PoolType);
- if (Pool== NULL) {
+ Index = SIZE_TO_LIST (Size);
+ Pool = LookupPoolHead (PoolType);
+ if (Pool == NULL) {
return NULL;
}
+
Head = NULL;
//
// If allocation is over max size, just allocate pages for the request
// (slow)
//
- if (Index >= SIZE_TO_LIST (Granularity) || NeedGuard || PageAsPool) {
+ if ((Index >= SIZE_TO_LIST (Granularity)) || NeedGuard || PageAsPool) {
if (!HasPoolTail) {
Size -= sizeof (POOL_TAIL);
}
- NoPages = EFI_SIZE_TO_PAGES (Size) + EFI_SIZE_TO_PAGES (Granularity) - 1;
+
+ NoPages = EFI_SIZE_TO_PAGES (Size) + EFI_SIZE_TO_PAGES (Granularity) - 1;
NoPages &= ~(UINTN)(EFI_SIZE_TO_PAGES (Granularity) - 1);
- Head = CoreAllocatePoolPagesI (PoolType, NoPages, Granularity, NeedGuard);
+ Head = CoreAllocatePoolPagesI (PoolType, NoPages, Granularity, NeedGuard);
if (NeedGuard) {
Head = AdjustPoolHeadA ((EFI_PHYSICAL_ADDRESS)(UINTN)Head, NoPages, Size);
}
+
goto Done;
}
@@ -420,8 +427,7 @@ CoreAllocatePoolI ( // If there's no free pool in the proper list size, go get some more pages
//
if (IsListEmpty (&Pool->FreeList[Index])) {
-
- Offset = LIST_TO_SIZE (Index);
+ Offset = LIST_TO_SIZE (Index);
MaxOffset = Granularity;
//
@@ -431,7 +437,7 @@ CoreAllocatePoolI ( if (!IsListEmpty (&Pool->FreeList[Index])) {
Free = CR (Pool->FreeList[Index].ForwardLink, POOL_FREE, Link, POOL_FREE_SIGNATURE);
RemoveEntryList (&Free->Link);
- NewPage = (VOID *) Free;
+ NewPage = (VOID *)Free;
MaxOffset = LIST_TO_SIZE (Index);
goto Carve;
}
@@ -440,8 +446,12 @@ CoreAllocatePoolI ( //
// Get another page
//
- NewPage = CoreAllocatePoolPagesI (PoolType, EFI_SIZE_TO_PAGES (Granularity),
- Granularity, NeedGuard);
+ NewPage = CoreAllocatePoolPagesI (
+ PoolType,
+ EFI_SIZE_TO_PAGES (Granularity),
+ Granularity,
+ NeedGuard
+ );
if (NewPage == NULL) {
goto Done;
}
@@ -450,7 +460,7 @@ CoreAllocatePoolI ( // Serve the allocation request from the head of the allocated block
//
Carve:
- Head = (POOL_HEAD *) NewPage;
+ Head = (POOL_HEAD *)NewPage;
//
// Carve up remaining space into free pool blocks
@@ -458,15 +468,16 @@ Carve: Index--;
while (Offset < MaxOffset) {
ASSERT (Index < MAX_POOL_LIST);
- FSize = LIST_TO_SIZE(Index);
+ FSize = LIST_TO_SIZE (Index);
while (Offset + FSize <= MaxOffset) {
- Free = (POOL_FREE *) &NewPage[Offset];
+ Free = (POOL_FREE *)&NewPage[Offset];
Free->Signature = POOL_FREE_SIGNATURE;
Free->Index = (UINT32)Index;
InsertHeadList (&Pool->FreeList[Index], &Free->Link);
Offset += FSize;
}
+
Index -= 1;
}
@@ -480,13 +491,12 @@ Carve: Free = CR (Pool->FreeList[Index].ForwardLink, POOL_FREE, Link, POOL_FREE_SIGNATURE);
RemoveEntryList (&Free->Link);
- Head = (POOL_HEAD *) Free;
+ Head = (POOL_HEAD *)Free;
Done:
Buffer = NULL;
if (Head != NULL) {
-
//
// Account the allocation
//
@@ -497,7 +507,7 @@ Done: //
Head->Signature = (PageAsPool) ? POOLPAGE_HEAD_SIGNATURE : POOL_HEAD_SIGNATURE;
Head->Size = Size;
- Head->Type = (EFI_MEMORY_TYPE) PoolType;
+ Head->Type = (EFI_MEMORY_TYPE)PoolType;
Buffer = Head->Data;
if (HasPoolTail) {
@@ -514,22 +524,19 @@ Done: DEBUG ((
DEBUG_POOL,
- "AllocatePoolI: Type %x, Addr %p (len %lx) %,ld\n", PoolType,
+ "AllocatePoolI: Type %x, Addr %p (len %lx) %,ld\n",
+ PoolType,
Buffer,
(UINT64)Size,
- (UINT64) Pool->Used
+ (UINT64)Pool->Used
));
-
-
} else {
- DEBUG ((DEBUG_ERROR | DEBUG_POOL, "AllocatePool: failed to allocate %ld bytes\n", (UINT64) Size));
+ DEBUG ((DEBUG_ERROR | DEBUG_POOL, "AllocatePool: failed to allocate %ld bytes\n", (UINT64)Size));
}
return Buffer;
}
-
-
/**
Frees pool.
@@ -543,11 +550,11 @@ Done: EFI_STATUS
EFIAPI
CoreInternalFreePool (
- IN VOID *Buffer,
- OUT EFI_MEMORY_TYPE *PoolType OPTIONAL
+ IN VOID *Buffer,
+ OUT EFI_MEMORY_TYPE *PoolType OPTIONAL
)
{
- EFI_STATUS Status;
+ EFI_STATUS Status;
if (Buffer == NULL) {
return EFI_INVALID_PARAMETER;
@@ -574,13 +581,13 @@ CoreFreePool ( IN VOID *Buffer
)
{
- EFI_STATUS Status;
- EFI_MEMORY_TYPE PoolType;
+ EFI_STATUS Status;
+ EFI_MEMORY_TYPE PoolType;
Status = CoreInternalFreePool (Buffer, &PoolType);
if (!EFI_ERROR (Status)) {
CoreUpdateProfile (
- (EFI_PHYSICAL_ADDRESS) (UINTN) RETURN_ADDRESS (0),
+ (EFI_PHYSICAL_ADDRESS)(UINTN)RETURN_ADDRESS (0),
MemoryProfileActionFreePool,
PoolType,
0,
@@ -589,6 +596,7 @@ CoreFreePool ( );
InstallMemoryAttributesTableOnMemoryAllocation (PoolType);
}
+
return Status;
}
@@ -603,9 +611,9 @@ CoreFreePool ( STATIC
VOID
CoreFreePoolPagesI (
- IN EFI_MEMORY_TYPE PoolType,
- IN EFI_PHYSICAL_ADDRESS Memory,
- IN UINTN NoPages
+ IN EFI_MEMORY_TYPE PoolType,
+ IN EFI_PHYSICAL_ADDRESS Memory,
+ IN UINTN NoPages
)
{
CoreAcquireMemoryLock ();
@@ -613,8 +621,12 @@ CoreFreePoolPagesI ( CoreReleaseMemoryLock ();
GuardFreedPagesChecked (Memory, NoPages);
- ApplyMemoryProtectionPolicy (PoolType, EfiConventionalMemory,
- (EFI_PHYSICAL_ADDRESS)(UINTN)Memory, EFI_PAGES_TO_SIZE (NoPages));
+ ApplyMemoryProtectionPolicy (
+ PoolType,
+ EfiConventionalMemory,
+ (EFI_PHYSICAL_ADDRESS)(UINTN)Memory,
+ EFI_PAGES_TO_SIZE (NoPages)
+ );
}
/**
@@ -628,13 +640,13 @@ CoreFreePoolPagesI ( STATIC
VOID
CoreFreePoolPagesWithGuard (
- IN EFI_MEMORY_TYPE PoolType,
- IN EFI_PHYSICAL_ADDRESS Memory,
- IN UINTN NoPages
+ IN EFI_MEMORY_TYPE PoolType,
+ IN EFI_PHYSICAL_ADDRESS Memory,
+ IN UINTN NoPages
)
{
- EFI_PHYSICAL_ADDRESS MemoryGuarded;
- UINTN NoPagesGuarded;
+ EFI_PHYSICAL_ADDRESS MemoryGuarded;
+ UINTN NoPagesGuarded;
MemoryGuarded = Memory;
NoPagesGuarded = NoPages;
@@ -666,41 +678,44 @@ CoreFreePoolPagesWithGuard ( **/
EFI_STATUS
CoreFreePoolI (
- IN VOID *Buffer,
- OUT EFI_MEMORY_TYPE *PoolType OPTIONAL
+ IN VOID *Buffer,
+ OUT EFI_MEMORY_TYPE *PoolType OPTIONAL
)
{
- POOL *Pool;
- POOL_HEAD *Head;
- POOL_TAIL *Tail;
- POOL_FREE *Free;
- UINTN Index;
- UINTN NoPages;
- UINTN Size;
- CHAR8 *NewPage;
- UINTN Offset;
- BOOLEAN AllFree;
- UINTN Granularity;
- BOOLEAN IsGuarded;
- BOOLEAN HasPoolTail;
- BOOLEAN PageAsPool;
-
- ASSERT(Buffer != NULL);
+ POOL *Pool;
+ POOL_HEAD *Head;
+ POOL_TAIL *Tail;
+ POOL_FREE *Free;
+ UINTN Index;
+ UINTN NoPages;
+ UINTN Size;
+ CHAR8 *NewPage;
+ UINTN Offset;
+ BOOLEAN AllFree;
+ UINTN Granularity;
+ BOOLEAN IsGuarded;
+ BOOLEAN HasPoolTail;
+ BOOLEAN PageAsPool;
+
+ ASSERT (Buffer != NULL);
//
// Get the head & tail of the pool entry
//
Head = BASE_CR (Buffer, POOL_HEAD, Data);
- ASSERT(Head != NULL);
-
- if (Head->Signature != POOL_HEAD_SIGNATURE &&
- Head->Signature != POOLPAGE_HEAD_SIGNATURE) {
- ASSERT (Head->Signature == POOL_HEAD_SIGNATURE ||
- Head->Signature == POOLPAGE_HEAD_SIGNATURE);
+ ASSERT (Head != NULL);
+
+ if ((Head->Signature != POOL_HEAD_SIGNATURE) &&
+ (Head->Signature != POOLPAGE_HEAD_SIGNATURE))
+ {
+ ASSERT (
+ Head->Signature == POOL_HEAD_SIGNATURE ||
+ Head->Signature == POOLPAGE_HEAD_SIGNATURE
+ );
return EFI_INVALID_PARAMETER;
}
- IsGuarded = IsPoolTypeToGuard (Head->Type) &&
- IsMemoryGuarded ((EFI_PHYSICAL_ADDRESS)(UINTN)Head);
+ IsGuarded = IsPoolTypeToGuard (Head->Type) &&
+ IsMemoryGuarded ((EFI_PHYSICAL_ADDRESS)(UINTN)Head);
HasPoolTail = !(IsGuarded &&
((PcdGet8 (PcdHeapGuardPropertyMask) & BIT7) == 0));
PageAsPool = (Head->Signature == POOLPAGE_HEAD_SIGNATURE);
@@ -734,14 +749,15 @@ CoreFreePoolI ( if (Pool == NULL) {
return EFI_INVALID_PARAMETER;
}
- 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 == EfiACPIReclaimMemory ||
- Head->Type == EfiACPIMemoryNVS ||
- Head->Type == EfiRuntimeServicesCode ||
- Head->Type == EfiRuntimeServicesData) {
+ 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 == EfiACPIReclaimMemory) ||
+ (Head->Type == EfiACPIMemoryNVS) ||
+ (Head->Type == EfiRuntimeServicesCode) ||
+ (Head->Type == EfiRuntimeServicesData))
+ {
Granularity = RUNTIME_PAGE_ALLOCATION_GRANULARITY;
} else {
Granularity = DEFAULT_PAGE_ALLOCATION_GRANULARITY;
@@ -754,18 +770,17 @@ CoreFreePoolI ( //
// Determine the pool list
//
- Index = SIZE_TO_LIST(Size);
+ Index = SIZE_TO_LIST (Size);
DEBUG_CLEAR_MEMORY (Head, Size);
//
// If it's not on the list, it must be pool pages
//
- if (Index >= SIZE_TO_LIST (Granularity) || IsGuarded || PageAsPool) {
-
+ if ((Index >= SIZE_TO_LIST (Granularity)) || IsGuarded || PageAsPool) {
//
// Return the memory pages back to free memory
//
- NoPages = EFI_SIZE_TO_PAGES (Size) + EFI_SIZE_TO_PAGES (Granularity) - 1;
+ NoPages = EFI_SIZE_TO_PAGES (Size) + EFI_SIZE_TO_PAGES (Granularity) - 1;
NoPages &= ~(UINTN)(EFI_SIZE_TO_PAGES (Granularity) - 1);
if (IsGuarded) {
Head = AdjustPoolHeadF ((EFI_PHYSICAL_ADDRESS)(UINTN)Head);
@@ -781,14 +796,12 @@ CoreFreePoolI ( NoPages
);
}
-
} else {
-
//
// Put the pool entry onto the free pool list
//
- Free = (POOL_FREE *) Head;
- ASSERT(Free != NULL);
+ Free = (POOL_FREE *)Head;
+ ASSERT (Free != NULL);
Free->Signature = POOL_FREE_SIGNATURE;
Free->Index = (UINT32)Index;
InsertHeadList (&Pool->FreeList[Index], &Free->Link);
@@ -798,46 +811,48 @@ CoreFreePoolI ( // entries
//
NewPage = (CHAR8 *)((UINTN)Free & ~(Granularity - 1));
- Free = (POOL_FREE *) &NewPage[0];
- ASSERT(Free != NULL);
+ Free = (POOL_FREE *)&NewPage[0];
+ ASSERT (Free != NULL);
if (Free->Signature == POOL_FREE_SIGNATURE) {
-
AllFree = TRUE;
- Offset = 0;
+ Offset = 0;
while ((Offset < Granularity) && (AllFree)) {
- Free = (POOL_FREE *) &NewPage[Offset];
- ASSERT(Free != NULL);
+ Free = (POOL_FREE *)&NewPage[Offset];
+ ASSERT (Free != NULL);
if (Free->Signature != POOL_FREE_SIGNATURE) {
AllFree = FALSE;
}
- Offset += LIST_TO_SIZE(Free->Index);
+
+ Offset += LIST_TO_SIZE (Free->Index);
}
if (AllFree) {
-
//
// All of the pool entries in the same page as Free are free pool
// entries
// Remove all of these pool entries from the free loop lists.
//
- Free = (POOL_FREE *) &NewPage[0];
- ASSERT(Free != NULL);
+ Free = (POOL_FREE *)&NewPage[0];
+ ASSERT (Free != NULL);
Offset = 0;
while (Offset < Granularity) {
- Free = (POOL_FREE *) &NewPage[Offset];
- ASSERT(Free != NULL);
+ Free = (POOL_FREE *)&NewPage[Offset];
+ ASSERT (Free != NULL);
RemoveEntryList (&Free->Link);
- Offset += LIST_TO_SIZE(Free->Index);
+ Offset += LIST_TO_SIZE (Free->Index);
}
//
// Free the page
//
- CoreFreePoolPagesI (Pool->MemoryType, (EFI_PHYSICAL_ADDRESS) (UINTN)NewPage,
- EFI_SIZE_TO_PAGES (Granularity));
+ CoreFreePoolPagesI (
+ Pool->MemoryType,
+ (EFI_PHYSICAL_ADDRESS)(UINTN)NewPage,
+ EFI_SIZE_TO_PAGES (Granularity)
+ );
}
}
}
@@ -847,11 +862,10 @@ CoreFreePoolI ( // portion of that memory type has been freed. If it has, then free the
// list entry for that memory type
//
- if (((UINT32) Pool->MemoryType >= MEMORY_TYPE_OEM_RESERVED_MIN) && Pool->Used == 0) {
+ if (((UINT32)Pool->MemoryType >= MEMORY_TYPE_OEM_RESERVED_MIN) && (Pool->Used == 0)) {
RemoveEntryList (&Pool->Link);
CoreFreePoolI (Pool, NULL);
}
return EFI_SUCCESS;
}
-
diff --git a/MdeModulePkg/Core/Dxe/Misc/DebugImageInfo.c b/MdeModulePkg/Core/Dxe/Misc/DebugImageInfo.c index c637e35076..eeb18f6e47 100644 --- a/MdeModulePkg/Core/Dxe/Misc/DebugImageInfo.c +++ b/MdeModulePkg/Core/Dxe/Misc/DebugImageInfo.c @@ -9,18 +9,17 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include "DxeMain.h"
-
EFI_DEBUG_IMAGE_INFO_TABLE_HEADER mDebugInfoTableHeader = {
0, // volatile UINT32 UpdateStatus;
0, // UINT32 TableSize;
NULL // EFI_DEBUG_IMAGE_INFO *EfiDebugImageInfoTable;
};
-UINTN mMaxTableEntries = 0;
+UINTN mMaxTableEntries = 0;
EFI_SYSTEM_TABLE_POINTER *mDebugTable = NULL;
-#define EFI_DEBUG_TABLE_ENTRY_SIZE (sizeof (VOID *))
+#define EFI_DEBUG_TABLE_ENTRY_SIZE (sizeof (VOID *))
/**
Creates and initializes the DebugImageInfo Table. Also creates the configuration
@@ -45,9 +44,9 @@ CoreInitializeDebugImageInfoTable ( // Ideally we would update the CRC now as well, but the service may not yet be available.
// See comments in the CoreUpdateDebugTableCrc32() function below for details.
//
- Pages = EFI_SIZE_TO_PAGES (sizeof (EFI_SYSTEM_TABLE_POINTER));
- AlignmentMask = SIZE_4MB - 1;
- RealPages = Pages + EFI_SIZE_TO_PAGES (SIZE_4MB);
+ Pages = EFI_SIZE_TO_PAGES (sizeof (EFI_SYSTEM_TABLE_POINTER));
+ AlignmentMask = SIZE_4MB - 1;
+ RealPages = Pages + EFI_SIZE_TO_PAGES (SIZE_4MB);
//
// Attempt to allocate memory below PcdMaxEfiSystemTablePointerAddress
@@ -58,6 +57,7 @@ CoreInitializeDebugImageInfoTable ( if (Memory == 0) {
Memory = MAX_ADDRESS;
}
+
Status = CoreAllocatePages (
AllocateMaxAddress,
EfiBootServicesData,
@@ -69,6 +69,7 @@ CoreInitializeDebugImageInfoTable ( DEBUG ((DEBUG_INFO, "Allocate memory for EFI_SYSTEM_TABLE_POINTER below PcdMaxEfiSystemTablePointerAddress failed. \
Retry to allocate memroy as close to the top of memory as feasible.\n"));
}
+
//
// If the initial memory allocation fails, then reattempt allocation
// as close to the top of memory as feasible.
@@ -88,7 +89,7 @@ CoreInitializeDebugImageInfoTable ( //
// Free overallocated pages
//
- AlignedMemory = ((UINTN) Memory + AlignmentMask) & ~AlignmentMask;
+ AlignedMemory = ((UINTN)Memory + AlignmentMask) & ~AlignmentMask;
UnalignedPages = EFI_SIZE_TO_PAGES (AlignedMemory - (UINTN)Memory);
if (UnalignedPages > 0) {
//
@@ -97,6 +98,7 @@ CoreInitializeDebugImageInfoTable ( Status = CoreFreePages (Memory, UnalignedPages);
ASSERT_EFI_ERROR (Status);
}
+
Memory = AlignedMemory + EFI_PAGES_TO_SIZE (Pages);
UnalignedPages = RealPages - Pages - UnalignedPages;
if (UnalignedPages > 0) {
@@ -117,7 +119,7 @@ CoreInitializeDebugImageInfoTable ( // Initialize EFI_SYSTEM_TABLE_POINTER structure
//
mDebugTable->Signature = EFI_SYSTEM_TABLE_SIGNATURE;
- mDebugTable->EfiSystemTableBase = (EFI_PHYSICAL_ADDRESS) (UINTN) gDxeCoreST;
+ mDebugTable->EfiSystemTableBase = (EFI_PHYSICAL_ADDRESS)(UINTN)gDxeCoreST;
mDebugTable->Crc32 = 0;
//
@@ -128,7 +130,6 @@ CoreInitializeDebugImageInfoTable ( ASSERT_EFI_ERROR (Status);
}
-
/**
Update the CRC32 in the Debug Table.
Since the CRC32 service is made available by the Runtime driver, we have to
@@ -142,12 +143,11 @@ CoreUpdateDebugTableCrc32 ( VOID
)
{
- ASSERT(mDebugTable != NULL);
+ ASSERT (mDebugTable != NULL);
mDebugTable->Crc32 = 0;
gBS->CalculateCrc32 ((VOID *)mDebugTable, sizeof (EFI_SYSTEM_TABLE_POINTER), &mDebugTable->Crc32);
}
-
/**
Adds a new DebugImageInfo structure to the DebugImageInfo Table. Re-Allocates
the table if it's not large enough to accomidate another entry.
@@ -160,15 +160,15 @@ CoreUpdateDebugTableCrc32 ( **/
VOID
CoreNewDebugImageInfoEntry (
- IN UINT32 ImageInfoType,
- IN EFI_LOADED_IMAGE_PROTOCOL *LoadedImage,
- IN EFI_HANDLE ImageHandle
+ IN UINT32 ImageInfoType,
+ IN EFI_LOADED_IMAGE_PROTOCOL *LoadedImage,
+ IN EFI_HANDLE ImageHandle
)
{
- EFI_DEBUG_IMAGE_INFO *Table;
- EFI_DEBUG_IMAGE_INFO *NewTable;
- UINTN Index;
- UINTN TableSize;
+ EFI_DEBUG_IMAGE_INFO *Table;
+ EFI_DEBUG_IMAGE_INFO *NewTable;
+ UINTN Index;
+ UINTN TableSize;
//
// Set the flag indicating that we're in the process of updating the table.
@@ -185,6 +185,7 @@ CoreNewDebugImageInfoEntry ( while (Table[Index].NormalImage != NULL) {
Index++;
}
+
//
// There must be an empty entry in the in the table.
//
@@ -194,11 +195,12 @@ CoreNewDebugImageInfoEntry ( // Table is full, so re-allocate another page for a larger table...
//
TableSize = mMaxTableEntries * EFI_DEBUG_TABLE_ENTRY_SIZE;
- NewTable = AllocateZeroPool (TableSize + EFI_PAGE_SIZE);
+ NewTable = AllocateZeroPool (TableSize + EFI_PAGE_SIZE);
if (NewTable == NULL) {
mDebugInfoTableHeader.UpdateStatus &= ~EFI_DEBUG_IMAGE_INFO_UPDATE_IN_PROGRESS;
return;
}
+
//
// Copy the old table into the new one
//
@@ -210,7 +212,7 @@ CoreNewDebugImageInfoEntry ( //
// Update the table header
//
- Table = NewTable;
+ Table = NewTable;
mDebugInfoTableHeader.EfiDebugImageInfoTable = NewTable;
//
// Enlarge the max table entries and set the first empty entry index to
@@ -228,7 +230,7 @@ CoreNewDebugImageInfoEntry ( //
// Update the entry
//
- Table[Index].NormalImage->ImageInfoType = (UINT32) ImageInfoType;
+ Table[Index].NormalImage->ImageInfoType = (UINT32)ImageInfoType;
Table[Index].NormalImage->LoadedImageProtocolInstance = LoadedImage;
Table[Index].NormalImage->ImageHandle = ImageHandle;
//
@@ -237,11 +239,10 @@ CoreNewDebugImageInfoEntry ( mDebugInfoTableHeader.TableSize++;
mDebugInfoTableHeader.UpdateStatus |= EFI_DEBUG_IMAGE_INFO_TABLE_MODIFIED;
}
+
mDebugInfoTableHeader.UpdateStatus &= ~EFI_DEBUG_IMAGE_INFO_UPDATE_IN_PROGRESS;
}
-
-
/**
Removes and frees an entry from the DebugImageInfo Table.
@@ -250,7 +251,7 @@ CoreNewDebugImageInfoEntry ( **/
VOID
CoreRemoveDebugImageInfoEntry (
- EFI_HANDLE ImageHandle
+ EFI_HANDLE ImageHandle
)
{
EFI_DEBUG_IMAGE_INFO *Table;
@@ -261,7 +262,7 @@ CoreRemoveDebugImageInfoEntry ( Table = mDebugInfoTableHeader.EfiDebugImageInfoTable;
for (Index = 0; Index < mMaxTableEntries; Index++) {
- if (Table[Index].NormalImage != NULL && Table[Index].NormalImage->ImageHandle == ImageHandle) {
+ if ((Table[Index].NormalImage != NULL) && (Table[Index].NormalImage->ImageHandle == ImageHandle)) {
//
// Found a match. Free up the record, then NULL the pointer to indicate the slot
// is free.
@@ -276,5 +277,6 @@ CoreRemoveDebugImageInfoEntry ( break;
}
}
+
mDebugInfoTableHeader.UpdateStatus &= ~EFI_DEBUG_IMAGE_INFO_UPDATE_IN_PROGRESS;
}
diff --git a/MdeModulePkg/Core/Dxe/Misc/InstallConfigurationTable.c b/MdeModulePkg/Core/Dxe/Misc/InstallConfigurationTable.c index ba4e55fcd0..f47f3bd804 100755 --- a/MdeModulePkg/Core/Dxe/Misc/InstallConfigurationTable.c +++ b/MdeModulePkg/Core/Dxe/Misc/InstallConfigurationTable.c @@ -8,9 +8,9 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include "DxeMain.h"
-#define CONFIG_TABLE_SIZE_INCREASED 0x10
+#define CONFIG_TABLE_SIZE_INCREASED 0x10
-UINTN mSystemTableAllocateSize = 0;
+UINTN mSystemTableAllocateSize = 0;
/**
Boot Service called to add, modify, or remove a system configuration table from
@@ -30,13 +30,13 @@ UINTN mSystemTableAllocateSize = 0; EFI_STATUS
EFIAPI
CoreInstallConfigurationTable (
- IN EFI_GUID *Guid,
- IN VOID *Table
+ IN EFI_GUID *Guid,
+ IN VOID *Table
)
{
- UINTN Index;
- EFI_CONFIGURATION_TABLE *EfiConfigurationTable;
- EFI_CONFIGURATION_TABLE *OldTable;
+ UINTN Index;
+ EFI_CONFIGURATION_TABLE *EfiConfigurationTable;
+ EFI_CONFIGURATION_TABLE *OldTable;
//
// If Guid is NULL, then this operation cannot be performed
@@ -88,9 +88,7 @@ CoreInstallConfigurationTable ( &(gDxeCoreST->ConfigurationTable[Index + 1]),
(gDxeCoreST->NumberOfTableEntries - Index) * sizeof (EFI_CONFIGURATION_TABLE)
);
-
} else {
-
//
// No matching GUIDs were found, so this is an add operation.
//
@@ -110,7 +108,7 @@ CoreInstallConfigurationTable ( // Allocate a table with one additional entry.
//
mSystemTableAllocateSize += (CONFIG_TABLE_SIZE_INCREASED * sizeof (EFI_CONFIGURATION_TABLE));
- EfiConfigurationTable = AllocateRuntimePool (mSystemTableAllocateSize);
+ EfiConfigurationTable = AllocateRuntimePool (mSystemTableAllocateSize);
if (EfiConfigurationTable == NULL) {
//
// If a new table could not be allocated, then return an error.
@@ -159,7 +157,7 @@ CoreInstallConfigurationTable ( // Fill in the new entry
//
CopyGuid ((VOID *)&EfiConfigurationTable[Index].VendorGuid, Guid);
- EfiConfigurationTable[Index].VendorTable = Table;
+ EfiConfigurationTable[Index].VendorTable = Table;
//
// This is an add operation, so increment the number of table entries
diff --git a/MdeModulePkg/Core/Dxe/Misc/MemoryAttributesTable.c b/MdeModulePkg/Core/Dxe/Misc/MemoryAttributesTable.c index 02a67cafa9..e079213711 100644 --- a/MdeModulePkg/Core/Dxe/Misc/MemoryAttributesTable.c +++ b/MdeModulePkg/Core/Dxe/Misc/MemoryAttributesTable.c @@ -67,13 +67,13 @@ CoreGetMemoryMapWithSeparatedImageSection ( #define PREVIOUS_MEMORY_DESCRIPTOR(MemoryDescriptor, Size) \
((EFI_MEMORY_DESCRIPTOR *)((UINT8 *)(MemoryDescriptor) - (Size)))
-#define IMAGE_PROPERTIES_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('I','P','P','D')
+#define IMAGE_PROPERTIES_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('I','P','P','D')
typedef struct {
- UINT32 Signature;
- UINTN ImageRecordCount;
- UINTN CodeSegmentCountMax;
- LIST_ENTRY ImageRecordList;
+ UINT32 Signature;
+ UINTN ImageRecordCount;
+ UINTN CodeSegmentCountMax;
+ LIST_ENTRY ImageRecordList;
} IMAGE_PROPERTIES_PRIVATE_DATA;
STATIC IMAGE_PROPERTIES_PRIVATE_DATA mImagePropertiesPrivateData = {
@@ -83,11 +83,11 @@ STATIC IMAGE_PROPERTIES_PRIVATE_DATA mImagePropertiesPrivateData = { INITIALIZE_LIST_HEAD_VARIABLE (mImagePropertiesPrivateData.ImageRecordList)
};
-STATIC EFI_LOCK mMemoryAttributesTableLock = EFI_INITIALIZE_LOCK_VARIABLE (TPL_NOTIFY);
+STATIC EFI_LOCK mMemoryAttributesTableLock = EFI_INITIALIZE_LOCK_VARIABLE (TPL_NOTIFY);
-BOOLEAN mMemoryAttributesTableEnable = TRUE;
-BOOLEAN mMemoryAttributesTableEndOfDxe = FALSE;
-EFI_MEMORY_ATTRIBUTES_TABLE *mMemoryAttributesTable = NULL;
+BOOLEAN mMemoryAttributesTableEnable = TRUE;
+BOOLEAN mMemoryAttributesTableEndOfDxe = FALSE;
+EFI_MEMORY_ATTRIBUTES_TABLE *mMemoryAttributesTable = NULL;
BOOLEAN mMemoryAttributesTableReadyToBoot = FALSE;
/**
@@ -99,17 +99,17 @@ InstallMemoryAttributesTable ( VOID
)
{
- UINTN MemoryMapSize;
- EFI_MEMORY_DESCRIPTOR *MemoryMap;
- EFI_MEMORY_DESCRIPTOR *MemoryMapStart;
- UINTN MapKey;
- UINTN DescriptorSize;
- UINT32 DescriptorVersion;
- UINTN Index;
- EFI_STATUS Status;
- UINT32 RuntimeEntryCount;
- EFI_MEMORY_ATTRIBUTES_TABLE *MemoryAttributesTable;
- EFI_MEMORY_DESCRIPTOR *MemoryAttributesEntry;
+ UINTN MemoryMapSize;
+ EFI_MEMORY_DESCRIPTOR *MemoryMap;
+ EFI_MEMORY_DESCRIPTOR *MemoryMapStart;
+ UINTN MapKey;
+ UINTN DescriptorSize;
+ UINT32 DescriptorVersion;
+ UINTN Index;
+ EFI_STATUS Status;
+ UINT32 RuntimeEntryCount;
+ EFI_MEMORY_ATTRIBUTES_TABLE *MemoryAttributesTable;
+ EFI_MEMORY_DESCRIPTOR *MemoryAttributesEntry;
if (gMemoryMapTerminated) {
//
@@ -121,7 +121,7 @@ InstallMemoryAttributesTable ( if (!mMemoryAttributesTableEnable) {
DEBUG ((DEBUG_VERBOSE, "Cannot install Memory Attributes Table "));
DEBUG ((DEBUG_VERBOSE, "because Runtime Driver Section Alignment is not %dK.\n", RUNTIME_PAGE_ALLOCATION_GRANULARITY >> 10));
- return ;
+ return;
}
if (mMemoryAttributesTable == NULL) {
@@ -130,19 +130,19 @@ InstallMemoryAttributesTable ( // before GetMemoryMap below, as InstallConfigurationTable may allocate runtime
// memory for the new entry.
//
- Status = gBS->InstallConfigurationTable (&gEfiMemoryAttributesTableGuid, (VOID *) (UINTN) MAX_ADDRESS);
+ Status = gBS->InstallConfigurationTable (&gEfiMemoryAttributesTableGuid, (VOID *)(UINTN)MAX_ADDRESS);
ASSERT_EFI_ERROR (Status);
}
MemoryMapSize = 0;
- MemoryMap = NULL;
- Status = CoreGetMemoryMapWithSeparatedImageSection (
- &MemoryMapSize,
- MemoryMap,
- &MapKey,
- &DescriptorSize,
- &DescriptorVersion
- );
+ MemoryMap = NULL;
+ Status = CoreGetMemoryMapWithSeparatedImageSection (
+ &MemoryMapSize,
+ MemoryMap,
+ &MapKey,
+ &DescriptorSize,
+ &DescriptorVersion
+ );
ASSERT (Status == EFI_BUFFER_TOO_SMALL);
do {
@@ -161,22 +161,23 @@ InstallMemoryAttributesTable ( }
} while (Status == EFI_BUFFER_TOO_SMALL);
- MemoryMapStart = MemoryMap;
+ MemoryMapStart = MemoryMap;
RuntimeEntryCount = 0;
for (Index = 0; Index < MemoryMapSize/DescriptorSize; Index++) {
switch (MemoryMap->Type) {
- case EfiRuntimeServicesCode:
- case EfiRuntimeServicesData:
- RuntimeEntryCount ++;
- break;
+ case EfiRuntimeServicesCode:
+ case EfiRuntimeServicesData:
+ RuntimeEntryCount++;
+ break;
}
- MemoryMap = NEXT_MEMORY_DESCRIPTOR(MemoryMap, DescriptorSize);
+
+ MemoryMap = NEXT_MEMORY_DESCRIPTOR (MemoryMap, DescriptorSize);
}
//
// Allocate MemoryAttributesTable
//
- MemoryAttributesTable = AllocatePool (sizeof(EFI_MEMORY_ATTRIBUTES_TABLE) + DescriptorSize * RuntimeEntryCount);
+ MemoryAttributesTable = AllocatePool (sizeof (EFI_MEMORY_ATTRIBUTES_TABLE) + DescriptorSize * RuntimeEntryCount);
ASSERT (MemoryAttributesTable != NULL);
MemoryAttributesTable->Version = EFI_MEMORY_ATTRIBUTES_TABLE_VERSION;
MemoryAttributesTable->NumberOfEntries = RuntimeEntryCount;
@@ -187,24 +188,26 @@ InstallMemoryAttributesTable ( DEBUG ((DEBUG_VERBOSE, " NumberOfEntries - 0x%08x\n", MemoryAttributesTable->NumberOfEntries));
DEBUG ((DEBUG_VERBOSE, " DescriptorSize - 0x%08x\n", MemoryAttributesTable->DescriptorSize));
MemoryAttributesEntry = (EFI_MEMORY_DESCRIPTOR *)(MemoryAttributesTable + 1);
- MemoryMap = MemoryMapStart;
+ MemoryMap = MemoryMapStart;
for (Index = 0; Index < MemoryMapSize/DescriptorSize; Index++) {
switch (MemoryMap->Type) {
- case EfiRuntimeServicesCode:
- case EfiRuntimeServicesData:
- CopyMem (MemoryAttributesEntry, MemoryMap, DescriptorSize);
- MemoryAttributesEntry->Attribute &= (EFI_MEMORY_RO|EFI_MEMORY_XP|EFI_MEMORY_RUNTIME);
- DEBUG ((DEBUG_VERBOSE, "Entry (0x%x)\n", MemoryAttributesEntry));
- DEBUG ((DEBUG_VERBOSE, " Type - 0x%x\n", MemoryAttributesEntry->Type));
- DEBUG ((DEBUG_VERBOSE, " PhysicalStart - 0x%016lx\n", MemoryAttributesEntry->PhysicalStart));
- DEBUG ((DEBUG_VERBOSE, " VirtualStart - 0x%016lx\n", MemoryAttributesEntry->VirtualStart));
- DEBUG ((DEBUG_VERBOSE, " NumberOfPages - 0x%016lx\n", MemoryAttributesEntry->NumberOfPages));
- DEBUG ((DEBUG_VERBOSE, " Attribute - 0x%016lx\n", MemoryAttributesEntry->Attribute));
- MemoryAttributesEntry = NEXT_MEMORY_DESCRIPTOR(MemoryAttributesEntry, DescriptorSize);
- break;
+ case EfiRuntimeServicesCode:
+ case EfiRuntimeServicesData:
+ CopyMem (MemoryAttributesEntry, MemoryMap, DescriptorSize);
+ MemoryAttributesEntry->Attribute &= (EFI_MEMORY_RO|EFI_MEMORY_XP|EFI_MEMORY_RUNTIME);
+ DEBUG ((DEBUG_VERBOSE, "Entry (0x%x)\n", MemoryAttributesEntry));
+ DEBUG ((DEBUG_VERBOSE, " Type - 0x%x\n", MemoryAttributesEntry->Type));
+ DEBUG ((DEBUG_VERBOSE, " PhysicalStart - 0x%016lx\n", MemoryAttributesEntry->PhysicalStart));
+ DEBUG ((DEBUG_VERBOSE, " VirtualStart - 0x%016lx\n", MemoryAttributesEntry->VirtualStart));
+ DEBUG ((DEBUG_VERBOSE, " NumberOfPages - 0x%016lx\n", MemoryAttributesEntry->NumberOfPages));
+ DEBUG ((DEBUG_VERBOSE, " Attribute - 0x%016lx\n", MemoryAttributesEntry->Attribute));
+ MemoryAttributesEntry = NEXT_MEMORY_DESCRIPTOR (MemoryAttributesEntry, DescriptorSize);
+ break;
}
- MemoryMap = NEXT_MEMORY_DESCRIPTOR(MemoryMap, DescriptorSize);
+
+ MemoryMap = NEXT_MEMORY_DESCRIPTOR (MemoryMap, DescriptorSize);
}
+
MemoryMap = MemoryMapStart;
FreePool (MemoryMap);
@@ -217,6 +220,7 @@ InstallMemoryAttributesTable ( if (mMemoryAttributesTable != NULL) {
FreePool (mMemoryAttributesTable);
}
+
mMemoryAttributesTable = MemoryAttributesTable;
}
@@ -227,14 +231,15 @@ InstallMemoryAttributesTable ( **/
VOID
InstallMemoryAttributesTableOnMemoryAllocation (
- IN EFI_MEMORY_TYPE MemoryType
+ IN EFI_MEMORY_TYPE MemoryType
)
{
//
// Install MemoryAttributesTable after ReadyToBoot on runtime memory allocation.
//
if (mMemoryAttributesTableReadyToBoot &&
- ((MemoryType == EfiRuntimeServicesCode) || (MemoryType == EfiRuntimeServicesData))) {
+ ((MemoryType == EfiRuntimeServicesCode) || (MemoryType == EfiRuntimeServicesData)))
+ {
InstallMemoryAttributesTable ();
}
}
@@ -248,8 +253,8 @@ InstallMemoryAttributesTableOnMemoryAllocation ( VOID
EFIAPI
InstallMemoryAttributesTableOnReadyToBoot (
- IN EFI_EVENT Event,
- IN VOID *Context
+ IN EFI_EVENT Event,
+ IN VOID *Context
)
{
InstallMemoryAttributesTable ();
@@ -266,8 +271,8 @@ InstallMemoryAttributesTableOnReadyToBoot ( VOID
EFIAPI
InstallMemoryAttributesTableOnEndOfDxe (
- IN EFI_EVENT Event,
- IN VOID *Context
+ IN EFI_EVENT Event,
+ IN VOID *Context
)
{
mMemoryAttributesTableEndOfDxe = TRUE;
@@ -315,7 +320,7 @@ CoreInitializeMemoryAttributesTable ( &EndOfDxeEvent
);
ASSERT_EFI_ERROR (Status);
- return ;
+ return;
}
//
@@ -335,7 +340,7 @@ CoreInitializeMemoryAttributesTable ( STATIC
UINT64
EfiPagesToSize (
- IN UINT64 Pages
+ IN UINT64 Pages
)
{
return LShiftU64 (Pages, EFI_PAGE_SHIFT);
@@ -355,7 +360,7 @@ EfiPagesToSize ( STATIC
UINT64
EfiSizeToPages (
- IN UINT64 Size
+ IN UINT64 Size
)
{
return RShiftU64 (Size, EFI_PAGE_SHIFT) + ((((UINTN)Size) & EFI_PAGE_MASK) ? 1 : 0);
@@ -401,30 +406,30 @@ SortMemoryMap ( IN UINTN DescriptorSize
)
{
- EFI_MEMORY_DESCRIPTOR *MemoryMapEntry;
- EFI_MEMORY_DESCRIPTOR *NextMemoryMapEntry;
- EFI_MEMORY_DESCRIPTOR *MemoryMapEnd;
- EFI_MEMORY_DESCRIPTOR TempMemoryMap;
+ EFI_MEMORY_DESCRIPTOR *MemoryMapEntry;
+ EFI_MEMORY_DESCRIPTOR *NextMemoryMapEntry;
+ EFI_MEMORY_DESCRIPTOR *MemoryMapEnd;
+ EFI_MEMORY_DESCRIPTOR TempMemoryMap;
- MemoryMapEntry = MemoryMap;
+ MemoryMapEntry = MemoryMap;
NextMemoryMapEntry = NEXT_MEMORY_DESCRIPTOR (MemoryMapEntry, DescriptorSize);
- MemoryMapEnd = (EFI_MEMORY_DESCRIPTOR *) ((UINT8 *) MemoryMap + MemoryMapSize);
+ MemoryMapEnd = (EFI_MEMORY_DESCRIPTOR *)((UINT8 *)MemoryMap + MemoryMapSize);
while (MemoryMapEntry < MemoryMapEnd) {
while (NextMemoryMapEntry < MemoryMapEnd) {
if (MemoryMapEntry->PhysicalStart > NextMemoryMapEntry->PhysicalStart) {
- CopyMem (&TempMemoryMap, MemoryMapEntry, sizeof(EFI_MEMORY_DESCRIPTOR));
- CopyMem (MemoryMapEntry, NextMemoryMapEntry, sizeof(EFI_MEMORY_DESCRIPTOR));
- CopyMem (NextMemoryMapEntry, &TempMemoryMap, sizeof(EFI_MEMORY_DESCRIPTOR));
+ CopyMem (&TempMemoryMap, MemoryMapEntry, sizeof (EFI_MEMORY_DESCRIPTOR));
+ CopyMem (MemoryMapEntry, NextMemoryMapEntry, sizeof (EFI_MEMORY_DESCRIPTOR));
+ CopyMem (NextMemoryMapEntry, &TempMemoryMap, sizeof (EFI_MEMORY_DESCRIPTOR));
}
NextMemoryMapEntry = NEXT_MEMORY_DESCRIPTOR (NextMemoryMapEntry, DescriptorSize);
}
- MemoryMapEntry = NEXT_MEMORY_DESCRIPTOR (MemoryMapEntry, DescriptorSize);
- NextMemoryMapEntry = NEXT_MEMORY_DESCRIPTOR (MemoryMapEntry, DescriptorSize);
+ MemoryMapEntry = NEXT_MEMORY_DESCRIPTOR (MemoryMapEntry, DescriptorSize);
+ NextMemoryMapEntry = NEXT_MEMORY_DESCRIPTOR (MemoryMapEntry, DescriptorSize);
}
- return ;
+ return;
}
/**
@@ -445,28 +450,29 @@ MergeMemoryMap ( IN UINTN DescriptorSize
)
{
- EFI_MEMORY_DESCRIPTOR *MemoryMapEntry;
- EFI_MEMORY_DESCRIPTOR *MemoryMapEnd;
- UINT64 MemoryBlockLength;
- EFI_MEMORY_DESCRIPTOR *NewMemoryMapEntry;
- EFI_MEMORY_DESCRIPTOR *NextMemoryMapEntry;
+ EFI_MEMORY_DESCRIPTOR *MemoryMapEntry;
+ EFI_MEMORY_DESCRIPTOR *MemoryMapEnd;
+ UINT64 MemoryBlockLength;
+ EFI_MEMORY_DESCRIPTOR *NewMemoryMapEntry;
+ EFI_MEMORY_DESCRIPTOR *NextMemoryMapEntry;
- MemoryMapEntry = MemoryMap;
+ MemoryMapEntry = MemoryMap;
NewMemoryMapEntry = MemoryMap;
- MemoryMapEnd = (EFI_MEMORY_DESCRIPTOR *) ((UINT8 *) MemoryMap + *MemoryMapSize);
+ MemoryMapEnd = (EFI_MEMORY_DESCRIPTOR *)((UINT8 *)MemoryMap + *MemoryMapSize);
while ((UINTN)MemoryMapEntry < (UINTN)MemoryMapEnd) {
- CopyMem (NewMemoryMapEntry, MemoryMapEntry, sizeof(EFI_MEMORY_DESCRIPTOR));
+ CopyMem (NewMemoryMapEntry, MemoryMapEntry, sizeof (EFI_MEMORY_DESCRIPTOR));
NextMemoryMapEntry = NEXT_MEMORY_DESCRIPTOR (MemoryMapEntry, DescriptorSize);
do {
MergeGuardPages (NewMemoryMapEntry, NextMemoryMapEntry->PhysicalStart);
- MemoryBlockLength = (UINT64) (EfiPagesToSize (NewMemoryMapEntry->NumberOfPages));
+ MemoryBlockLength = (UINT64)(EfiPagesToSize (NewMemoryMapEntry->NumberOfPages));
if (((UINTN)NextMemoryMapEntry < (UINTN)MemoryMapEnd) &&
(NewMemoryMapEntry->Type == NextMemoryMapEntry->Type) &&
(NewMemoryMapEntry->Attribute == NextMemoryMapEntry->Attribute) &&
- ((NewMemoryMapEntry->PhysicalStart + MemoryBlockLength) == NextMemoryMapEntry->PhysicalStart)) {
+ ((NewMemoryMapEntry->PhysicalStart + MemoryBlockLength) == NextMemoryMapEntry->PhysicalStart))
+ {
NewMemoryMapEntry->NumberOfPages += NextMemoryMapEntry->NumberOfPages;
- NextMemoryMapEntry = NEXT_MEMORY_DESCRIPTOR (NextMemoryMapEntry, DescriptorSize);
+ NextMemoryMapEntry = NEXT_MEMORY_DESCRIPTOR (NextMemoryMapEntry, DescriptorSize);
continue;
} else {
MemoryMapEntry = PREVIOUS_MEMORY_DESCRIPTOR (NextMemoryMapEntry, DescriptorSize);
@@ -474,13 +480,13 @@ MergeMemoryMap ( }
} while (TRUE);
- MemoryMapEntry = NEXT_MEMORY_DESCRIPTOR (MemoryMapEntry, DescriptorSize);
+ MemoryMapEntry = NEXT_MEMORY_DESCRIPTOR (MemoryMapEntry, DescriptorSize);
NewMemoryMapEntry = NEXT_MEMORY_DESCRIPTOR (NewMemoryMapEntry, DescriptorSize);
}
*MemoryMapSize = (UINTN)NewMemoryMapEntry - (UINTN)MemoryMap;
- return ;
+ return;
}
/**
@@ -500,30 +506,30 @@ EnforceMemoryMapAttribute ( IN UINTN DescriptorSize
)
{
- EFI_MEMORY_DESCRIPTOR *MemoryMapEntry;
- EFI_MEMORY_DESCRIPTOR *MemoryMapEnd;
+ EFI_MEMORY_DESCRIPTOR *MemoryMapEntry;
+ EFI_MEMORY_DESCRIPTOR *MemoryMapEnd;
MemoryMapEntry = MemoryMap;
- MemoryMapEnd = (EFI_MEMORY_DESCRIPTOR *) ((UINT8 *) MemoryMap + MemoryMapSize);
+ MemoryMapEnd = (EFI_MEMORY_DESCRIPTOR *)((UINT8 *)MemoryMap + MemoryMapSize);
while ((UINTN)MemoryMapEntry < (UINTN)MemoryMapEnd) {
switch (MemoryMapEntry->Type) {
- case EfiRuntimeServicesCode:
- // do nothing
- break;
- case EfiRuntimeServicesData:
- case EfiMemoryMappedIO:
- case EfiMemoryMappedIOPortSpace:
- MemoryMapEntry->Attribute |= EFI_MEMORY_XP;
- break;
- case EfiReservedMemoryType:
- case EfiACPIMemoryNVS:
- break;
+ case EfiRuntimeServicesCode:
+ // do nothing
+ break;
+ case EfiRuntimeServicesData:
+ case EfiMemoryMappedIO:
+ case EfiMemoryMappedIOPortSpace:
+ MemoryMapEntry->Attribute |= EFI_MEMORY_XP;
+ break;
+ case EfiReservedMemoryType:
+ case EfiACPIMemoryNVS:
+ break;
}
MemoryMapEntry = NEXT_MEMORY_DESCRIPTOR (MemoryMapEntry, DescriptorSize);
}
- return ;
+ return;
}
/**
@@ -541,15 +547,16 @@ GetImageRecordByAddress ( IN UINT64 Length
)
{
- IMAGE_PROPERTIES_RECORD *ImageRecord;
- LIST_ENTRY *ImageRecordLink;
- LIST_ENTRY *ImageRecordList;
+ IMAGE_PROPERTIES_RECORD *ImageRecord;
+ LIST_ENTRY *ImageRecordLink;
+ LIST_ENTRY *ImageRecordList;
ImageRecordList = &mImagePropertiesPrivateData.ImageRecordList;
for (ImageRecordLink = ImageRecordList->ForwardLink;
ImageRecordLink != ImageRecordList;
- ImageRecordLink = ImageRecordLink->ForwardLink) {
+ ImageRecordLink = ImageRecordLink->ForwardLink)
+ {
ImageRecord = CR (
ImageRecordLink,
IMAGE_PROPERTIES_RECORD,
@@ -558,7 +565,8 @@ GetImageRecordByAddress ( );
if ((Buffer <= ImageRecord->ImageBase) &&
- (Buffer + Length >= ImageRecord->ImageBase + ImageRecord->ImageSize)) {
+ (Buffer + Length >= ImageRecord->ImageBase + ImageRecord->ImageSize))
+ {
return ImageRecord;
}
}
@@ -582,28 +590,28 @@ GetImageRecordByAddress ( STATIC
UINTN
SetNewRecord (
- IN IMAGE_PROPERTIES_RECORD *ImageRecord,
- IN OUT EFI_MEMORY_DESCRIPTOR *NewRecord,
- IN EFI_MEMORY_DESCRIPTOR *OldRecord,
- IN UINTN DescriptorSize
+ IN IMAGE_PROPERTIES_RECORD *ImageRecord,
+ IN OUT EFI_MEMORY_DESCRIPTOR *NewRecord,
+ IN EFI_MEMORY_DESCRIPTOR *OldRecord,
+ IN UINTN DescriptorSize
)
{
- EFI_MEMORY_DESCRIPTOR TempRecord;
- IMAGE_PROPERTIES_RECORD_CODE_SECTION *ImageRecordCodeSection;
- LIST_ENTRY *ImageRecordCodeSectionLink;
- LIST_ENTRY *ImageRecordCodeSectionEndLink;
- LIST_ENTRY *ImageRecordCodeSectionList;
- UINTN NewRecordCount;
- UINT64 PhysicalEnd;
- UINT64 ImageEnd;
-
- CopyMem (&TempRecord, OldRecord, sizeof(EFI_MEMORY_DESCRIPTOR));
- PhysicalEnd = TempRecord.PhysicalStart + EfiPagesToSize(TempRecord.NumberOfPages);
+ EFI_MEMORY_DESCRIPTOR TempRecord;
+ IMAGE_PROPERTIES_RECORD_CODE_SECTION *ImageRecordCodeSection;
+ LIST_ENTRY *ImageRecordCodeSectionLink;
+ LIST_ENTRY *ImageRecordCodeSectionEndLink;
+ LIST_ENTRY *ImageRecordCodeSectionList;
+ UINTN NewRecordCount;
+ UINT64 PhysicalEnd;
+ UINT64 ImageEnd;
+
+ CopyMem (&TempRecord, OldRecord, sizeof (EFI_MEMORY_DESCRIPTOR));
+ PhysicalEnd = TempRecord.PhysicalStart + EfiPagesToSize (TempRecord.NumberOfPages);
NewRecordCount = 0;
ImageRecordCodeSectionList = &ImageRecord->CodeSegmentList;
- ImageRecordCodeSectionLink = ImageRecordCodeSectionList->ForwardLink;
+ ImageRecordCodeSectionLink = ImageRecordCodeSectionList->ForwardLink;
ImageRecordCodeSectionEndLink = ImageRecordCodeSectionList;
while (ImageRecordCodeSectionLink != ImageRecordCodeSectionEndLink) {
ImageRecordCodeSection = CR (
@@ -621,11 +629,11 @@ SetNewRecord ( NewRecord->Type = TempRecord.Type;
NewRecord->PhysicalStart = TempRecord.PhysicalStart;
NewRecord->VirtualStart = 0;
- NewRecord->NumberOfPages = EfiSizeToPages(ImageRecordCodeSection->CodeSegmentBase - NewRecord->PhysicalStart);
+ NewRecord->NumberOfPages = EfiSizeToPages (ImageRecordCodeSection->CodeSegmentBase - NewRecord->PhysicalStart);
NewRecord->Attribute = TempRecord.Attribute | EFI_MEMORY_XP;
if (NewRecord->NumberOfPages != 0) {
NewRecord = NEXT_MEMORY_DESCRIPTOR (NewRecord, DescriptorSize);
- NewRecordCount ++;
+ NewRecordCount++;
}
//
@@ -634,15 +642,15 @@ SetNewRecord ( NewRecord->Type = TempRecord.Type;
NewRecord->PhysicalStart = ImageRecordCodeSection->CodeSegmentBase;
NewRecord->VirtualStart = 0;
- NewRecord->NumberOfPages = EfiSizeToPages(ImageRecordCodeSection->CodeSegmentSize);
+ NewRecord->NumberOfPages = EfiSizeToPages (ImageRecordCodeSection->CodeSegmentSize);
NewRecord->Attribute = (TempRecord.Attribute & (~EFI_MEMORY_XP)) | EFI_MEMORY_RO;
if (NewRecord->NumberOfPages != 0) {
NewRecord = NEXT_MEMORY_DESCRIPTOR (NewRecord, DescriptorSize);
- NewRecordCount ++;
+ NewRecordCount++;
}
- TempRecord.PhysicalStart = ImageRecordCodeSection->CodeSegmentBase + EfiPagesToSize (EfiSizeToPages(ImageRecordCodeSection->CodeSegmentSize));
- TempRecord.NumberOfPages = EfiSizeToPages(PhysicalEnd - TempRecord.PhysicalStart);
+ TempRecord.PhysicalStart = ImageRecordCodeSection->CodeSegmentBase + EfiPagesToSize (EfiSizeToPages (ImageRecordCodeSection->CodeSegmentSize));
+ TempRecord.NumberOfPages = EfiSizeToPages (PhysicalEnd - TempRecord.PhysicalStart);
if (TempRecord.NumberOfPages == 0) {
break;
}
@@ -660,7 +668,7 @@ SetNewRecord ( NewRecord->VirtualStart = 0;
NewRecord->NumberOfPages = EfiSizeToPages (ImageEnd - TempRecord.PhysicalStart);
NewRecord->Attribute = TempRecord.Attribute | EFI_MEMORY_XP;
- NewRecordCount ++;
+ NewRecordCount++;
}
return NewRecordCount;
@@ -678,25 +686,26 @@ SetNewRecord ( STATIC
UINTN
GetMaxSplitRecordCount (
- IN EFI_MEMORY_DESCRIPTOR *OldRecord
+ IN EFI_MEMORY_DESCRIPTOR *OldRecord
)
{
- IMAGE_PROPERTIES_RECORD *ImageRecord;
- UINTN SplitRecordCount;
- UINT64 PhysicalStart;
- UINT64 PhysicalEnd;
+ IMAGE_PROPERTIES_RECORD *ImageRecord;
+ UINTN SplitRecordCount;
+ UINT64 PhysicalStart;
+ UINT64 PhysicalEnd;
SplitRecordCount = 0;
- PhysicalStart = OldRecord->PhysicalStart;
- PhysicalEnd = OldRecord->PhysicalStart + EfiPagesToSize(OldRecord->NumberOfPages);
+ PhysicalStart = OldRecord->PhysicalStart;
+ PhysicalEnd = OldRecord->PhysicalStart + EfiPagesToSize (OldRecord->NumberOfPages);
do {
ImageRecord = GetImageRecordByAddress (PhysicalStart, PhysicalEnd - PhysicalStart);
if (ImageRecord == NULL) {
break;
}
+
SplitRecordCount += (2 * ImageRecord->CodeSegmentCount + 1);
- PhysicalStart = ImageRecord->ImageBase + ImageRecord->ImageSize;
+ PhysicalStart = ImageRecord->ImageBase + ImageRecord->ImageSize;
} while ((ImageRecord != NULL) && (PhysicalStart < PhysicalEnd));
if (SplitRecordCount != 0) {
@@ -724,20 +733,20 @@ GetMaxSplitRecordCount ( STATIC
UINTN
SplitRecord (
- IN EFI_MEMORY_DESCRIPTOR *OldRecord,
- IN OUT EFI_MEMORY_DESCRIPTOR *NewRecord,
- IN UINTN MaxSplitRecordCount,
- IN UINTN DescriptorSize
+ IN EFI_MEMORY_DESCRIPTOR *OldRecord,
+ IN OUT EFI_MEMORY_DESCRIPTOR *NewRecord,
+ IN UINTN MaxSplitRecordCount,
+ IN UINTN DescriptorSize
)
{
- EFI_MEMORY_DESCRIPTOR TempRecord;
- IMAGE_PROPERTIES_RECORD *ImageRecord;
- IMAGE_PROPERTIES_RECORD *NewImageRecord;
- UINT64 PhysicalStart;
- UINT64 PhysicalEnd;
- UINTN NewRecordCount;
- UINTN TotalNewRecordCount;
- BOOLEAN IsLastRecordData;
+ EFI_MEMORY_DESCRIPTOR TempRecord;
+ IMAGE_PROPERTIES_RECORD *ImageRecord;
+ IMAGE_PROPERTIES_RECORD *NewImageRecord;
+ UINT64 PhysicalStart;
+ UINT64 PhysicalEnd;
+ UINTN NewRecordCount;
+ UINTN TotalNewRecordCount;
+ BOOLEAN IsLastRecordData;
if (MaxSplitRecordCount == 0) {
CopyMem (NewRecord, OldRecord, DescriptorSize);
@@ -749,9 +758,9 @@ SplitRecord ( //
// Override previous record
//
- CopyMem (&TempRecord, OldRecord, sizeof(EFI_MEMORY_DESCRIPTOR));
+ CopyMem (&TempRecord, OldRecord, sizeof (EFI_MEMORY_DESCRIPTOR));
PhysicalStart = TempRecord.PhysicalStart;
- PhysicalEnd = TempRecord.PhysicalStart + EfiPagesToSize(TempRecord.NumberOfPages);
+ PhysicalEnd = TempRecord.PhysicalStart + EfiPagesToSize (TempRecord.NumberOfPages);
ImageRecord = NULL;
do {
@@ -764,44 +773,47 @@ SplitRecord ( //
// If this is still address in this record, need record.
//
- NewRecord = PREVIOUS_MEMORY_DESCRIPTOR (NewRecord, DescriptorSize);
+ NewRecord = PREVIOUS_MEMORY_DESCRIPTOR (NewRecord, DescriptorSize);
IsLastRecordData = FALSE;
if ((NewRecord->Attribute & EFI_MEMORY_XP) != 0) {
IsLastRecordData = TRUE;
}
+
if (IsLastRecordData) {
//
// Last record is DATA, just merge it.
//
- NewRecord->NumberOfPages = EfiSizeToPages(PhysicalEnd - NewRecord->PhysicalStart);
+ NewRecord->NumberOfPages = EfiSizeToPages (PhysicalEnd - NewRecord->PhysicalStart);
} else {
//
// Last record is CODE, create a new DATA entry.
//
- NewRecord = NEXT_MEMORY_DESCRIPTOR (NewRecord, DescriptorSize);
+ NewRecord = NEXT_MEMORY_DESCRIPTOR (NewRecord, DescriptorSize);
NewRecord->Type = TempRecord.Type;
NewRecord->PhysicalStart = TempRecord.PhysicalStart;
NewRecord->VirtualStart = 0;
NewRecord->NumberOfPages = TempRecord.NumberOfPages;
NewRecord->Attribute = TempRecord.Attribute | EFI_MEMORY_XP;
- TotalNewRecordCount ++;
+ TotalNewRecordCount++;
}
}
+
break;
}
+
ImageRecord = NewImageRecord;
//
// Set new record
//
- NewRecordCount = SetNewRecord (ImageRecord, NewRecord, &TempRecord, DescriptorSize);
+ NewRecordCount = SetNewRecord (ImageRecord, NewRecord, &TempRecord, DescriptorSize);
TotalNewRecordCount += NewRecordCount;
- NewRecord = (EFI_MEMORY_DESCRIPTOR *)((UINT8 *)NewRecord + NewRecordCount * DescriptorSize);
+ NewRecord = (EFI_MEMORY_DESCRIPTOR *)((UINT8 *)NewRecord + NewRecordCount * DescriptorSize);
//
// Update PhysicalStart, in order to exclude the image buffer already splitted.
//
- PhysicalStart = ImageRecord->ImageBase + ImageRecord->ImageSize;
+ PhysicalStart = ImageRecord->ImageBase + ImageRecord->ImageSize;
TempRecord.PhysicalStart = PhysicalStart;
TempRecord.NumberOfPages = EfiSizeToPages (PhysicalEnd - PhysicalStart);
} while ((ImageRecord != NULL) && (PhysicalStart < PhysicalEnd));
@@ -868,12 +880,12 @@ SplitTable ( IN UINTN DescriptorSize
)
{
- INTN IndexOld;
- INTN IndexNew;
- UINTN MaxSplitRecordCount;
- UINTN RealSplitRecordCount;
- UINTN TotalSplitRecordCount;
- UINTN AdditionalRecordCount;
+ INTN IndexOld;
+ INTN IndexNew;
+ UINTN MaxSplitRecordCount;
+ UINTN RealSplitRecordCount;
+ UINTN TotalSplitRecordCount;
+ UINTN AdditionalRecordCount;
AdditionalRecordCount = (2 * mImagePropertiesPrivateData.CodeSegmentCountMax + 1) * mImagePropertiesPrivateData.ImageRecordCount;
@@ -886,12 +898,12 @@ SplitTable ( // Let new record point to end of full MemoryMap buffer.
//
IndexNew = ((*MemoryMapSize) / DescriptorSize) - 1 + AdditionalRecordCount;
- for (; IndexOld >= 0; IndexOld--) {
+ for ( ; IndexOld >= 0; IndexOld--) {
MaxSplitRecordCount = GetMaxSplitRecordCount ((EFI_MEMORY_DESCRIPTOR *)((UINT8 *)MemoryMap + IndexOld * DescriptorSize));
//
// Split this MemoryMap record
//
- IndexNew -= MaxSplitRecordCount;
+ IndexNew -= MaxSplitRecordCount;
RealSplitRecordCount = SplitRecord (
(EFI_MEMORY_DESCRIPTOR *)((UINT8 *)MemoryMap + IndexOld * DescriptorSize),
(EFI_MEMORY_DESCRIPTOR *)((UINT8 *)MemoryMap + IndexNew * DescriptorSize),
@@ -906,10 +918,11 @@ SplitTable ( ((UINT8 *)MemoryMap + IndexNew * DescriptorSize),
RealSplitRecordCount * DescriptorSize
);
- IndexNew = IndexNew + MaxSplitRecordCount - RealSplitRecordCount;
+ IndexNew = IndexNew + MaxSplitRecordCount - RealSplitRecordCount;
TotalSplitRecordCount += RealSplitRecordCount;
- IndexNew --;
+ IndexNew--;
}
+
//
// Move all records to the beginning.
//
@@ -936,7 +949,7 @@ SplitTable ( //
MergeMemoryMap (MemoryMap, MemoryMapSize, DescriptorSize);
- return ;
+ return;
}
/**
@@ -1001,7 +1014,7 @@ CoreGetMemoryMapWithSeparatedImageSection ( AdditionalRecordCount = (2 * mImagePropertiesPrivateData.CodeSegmentCountMax + 1) * mImagePropertiesPrivateData.ImageRecordCount;
OldMemoryMapSize = *MemoryMapSize;
- Status = CoreGetMemoryMap (MemoryMapSize, MemoryMap, MapKey, DescriptorSize, DescriptorVersion);
+ Status = CoreGetMemoryMap (MemoryMapSize, MemoryMap, MapKey, DescriptorSize, DescriptorVersion);
if (Status == EFI_BUFFER_TOO_SMALL) {
*MemoryMapSize = *MemoryMapSize + (*DescriptorSize) * AdditionalRecordCount;
} else if (Status == EFI_SUCCESS) {
@@ -1040,7 +1053,8 @@ SetMemoryAttributesTableSectionAlignment ( )
{
if (((SectionAlignment & (RUNTIME_PAGE_ALLOCATION_GRANULARITY - 1)) != 0) &&
- mMemoryAttributesTableEnable) {
+ mMemoryAttributesTableEnable)
+ {
DEBUG ((DEBUG_VERBOSE, "SetMemoryAttributesTableSectionAlignment - Clear\n"));
mMemoryAttributesTableEnable = FALSE;
}
@@ -1055,11 +1069,11 @@ SetMemoryAttributesTableSectionAlignment ( STATIC
VOID
SwapImageRecordCodeSection (
- IN IMAGE_PROPERTIES_RECORD_CODE_SECTION *FirstImageRecordCodeSection,
- IN IMAGE_PROPERTIES_RECORD_CODE_SECTION *SecondImageRecordCodeSection
+ IN IMAGE_PROPERTIES_RECORD_CODE_SECTION *FirstImageRecordCodeSection,
+ IN IMAGE_PROPERTIES_RECORD_CODE_SECTION *SecondImageRecordCodeSection
)
{
- IMAGE_PROPERTIES_RECORD_CODE_SECTION TempImageRecordCodeSection;
+ IMAGE_PROPERTIES_RECORD_CODE_SECTION TempImageRecordCodeSection;
TempImageRecordCodeSection.CodeSegmentBase = FirstImageRecordCodeSection->CodeSegmentBase;
TempImageRecordCodeSection.CodeSegmentSize = FirstImageRecordCodeSection->CodeSegmentSize;
@@ -1078,21 +1092,21 @@ SwapImageRecordCodeSection ( **/
VOID
SortImageRecordCodeSection (
- IN IMAGE_PROPERTIES_RECORD *ImageRecord
+ IN IMAGE_PROPERTIES_RECORD *ImageRecord
)
{
- IMAGE_PROPERTIES_RECORD_CODE_SECTION *ImageRecordCodeSection;
- IMAGE_PROPERTIES_RECORD_CODE_SECTION *NextImageRecordCodeSection;
- LIST_ENTRY *ImageRecordCodeSectionLink;
- LIST_ENTRY *NextImageRecordCodeSectionLink;
- LIST_ENTRY *ImageRecordCodeSectionEndLink;
- LIST_ENTRY *ImageRecordCodeSectionList;
+ IMAGE_PROPERTIES_RECORD_CODE_SECTION *ImageRecordCodeSection;
+ IMAGE_PROPERTIES_RECORD_CODE_SECTION *NextImageRecordCodeSection;
+ LIST_ENTRY *ImageRecordCodeSectionLink;
+ LIST_ENTRY *NextImageRecordCodeSectionLink;
+ LIST_ENTRY *ImageRecordCodeSectionEndLink;
+ LIST_ENTRY *ImageRecordCodeSectionList;
ImageRecordCodeSectionList = &ImageRecord->CodeSegmentList;
- ImageRecordCodeSectionLink = ImageRecordCodeSectionList->ForwardLink;
+ ImageRecordCodeSectionLink = ImageRecordCodeSectionList->ForwardLink;
NextImageRecordCodeSectionLink = ImageRecordCodeSectionLink->ForwardLink;
- ImageRecordCodeSectionEndLink = ImageRecordCodeSectionList;
+ ImageRecordCodeSectionEndLink = ImageRecordCodeSectionList;
while (ImageRecordCodeSectionLink != ImageRecordCodeSectionEndLink) {
ImageRecordCodeSection = CR (
ImageRecordCodeSectionLink,
@@ -1110,10 +1124,11 @@ SortImageRecordCodeSection ( if (ImageRecordCodeSection->CodeSegmentBase > NextImageRecordCodeSection->CodeSegmentBase) {
SwapImageRecordCodeSection (ImageRecordCodeSection, NextImageRecordCodeSection);
}
+
NextImageRecordCodeSectionLink = NextImageRecordCodeSectionLink->ForwardLink;
}
- ImageRecordCodeSectionLink = ImageRecordCodeSectionLink->ForwardLink;
+ ImageRecordCodeSectionLink = ImageRecordCodeSectionLink->ForwardLink;
NextImageRecordCodeSectionLink = ImageRecordCodeSectionLink->ForwardLink;
}
}
@@ -1128,22 +1143,22 @@ SortImageRecordCodeSection ( **/
BOOLEAN
IsImageRecordCodeSectionValid (
- IN IMAGE_PROPERTIES_RECORD *ImageRecord
+ IN IMAGE_PROPERTIES_RECORD *ImageRecord
)
{
- IMAGE_PROPERTIES_RECORD_CODE_SECTION *ImageRecordCodeSection;
- IMAGE_PROPERTIES_RECORD_CODE_SECTION *LastImageRecordCodeSection;
- LIST_ENTRY *ImageRecordCodeSectionLink;
- LIST_ENTRY *ImageRecordCodeSectionEndLink;
- LIST_ENTRY *ImageRecordCodeSectionList;
+ IMAGE_PROPERTIES_RECORD_CODE_SECTION *ImageRecordCodeSection;
+ IMAGE_PROPERTIES_RECORD_CODE_SECTION *LastImageRecordCodeSection;
+ LIST_ENTRY *ImageRecordCodeSectionLink;
+ LIST_ENTRY *ImageRecordCodeSectionEndLink;
+ LIST_ENTRY *ImageRecordCodeSectionList;
DEBUG ((DEBUG_VERBOSE, "ImageCode SegmentCount - 0x%x\n", ImageRecord->CodeSegmentCount));
ImageRecordCodeSectionList = &ImageRecord->CodeSegmentList;
- ImageRecordCodeSectionLink = ImageRecordCodeSectionList->ForwardLink;
+ ImageRecordCodeSectionLink = ImageRecordCodeSectionList->ForwardLink;
ImageRecordCodeSectionEndLink = ImageRecordCodeSectionList;
- LastImageRecordCodeSection = NULL;
+ LastImageRecordCodeSection = NULL;
while (ImageRecordCodeSectionLink != ImageRecordCodeSectionEndLink) {
ImageRecordCodeSection = CR (
ImageRecordCodeSectionLink,
@@ -1154,15 +1169,19 @@ IsImageRecordCodeSectionValid ( if (ImageRecordCodeSection->CodeSegmentSize == 0) {
return FALSE;
}
+
if (ImageRecordCodeSection->CodeSegmentBase < ImageRecord->ImageBase) {
return FALSE;
}
+
if (ImageRecordCodeSection->CodeSegmentBase >= MAX_ADDRESS - ImageRecordCodeSection->CodeSegmentSize) {
return FALSE;
}
+
if ((ImageRecordCodeSection->CodeSegmentBase + ImageRecordCodeSection->CodeSegmentSize) > (ImageRecord->ImageBase + ImageRecord->ImageSize)) {
return FALSE;
}
+
if (LastImageRecordCodeSection != NULL) {
if ((LastImageRecordCodeSection->CodeSegmentBase + LastImageRecordCodeSection->CodeSegmentSize) > ImageRecordCodeSection->CodeSegmentBase) {
return FALSE;
@@ -1185,22 +1204,22 @@ IsImageRecordCodeSectionValid ( STATIC
VOID
SwapImageRecord (
- IN IMAGE_PROPERTIES_RECORD *FirstImageRecord,
- IN IMAGE_PROPERTIES_RECORD *SecondImageRecord
+ IN IMAGE_PROPERTIES_RECORD *FirstImageRecord,
+ IN IMAGE_PROPERTIES_RECORD *SecondImageRecord
)
{
- IMAGE_PROPERTIES_RECORD TempImageRecord;
+ IMAGE_PROPERTIES_RECORD TempImageRecord;
- TempImageRecord.ImageBase = FirstImageRecord->ImageBase;
- TempImageRecord.ImageSize = FirstImageRecord->ImageSize;
+ TempImageRecord.ImageBase = FirstImageRecord->ImageBase;
+ TempImageRecord.ImageSize = FirstImageRecord->ImageSize;
TempImageRecord.CodeSegmentCount = FirstImageRecord->CodeSegmentCount;
- FirstImageRecord->ImageBase = SecondImageRecord->ImageBase;
- FirstImageRecord->ImageSize = SecondImageRecord->ImageSize;
+ FirstImageRecord->ImageBase = SecondImageRecord->ImageBase;
+ FirstImageRecord->ImageSize = SecondImageRecord->ImageSize;
FirstImageRecord->CodeSegmentCount = SecondImageRecord->CodeSegmentCount;
- SecondImageRecord->ImageBase = TempImageRecord.ImageBase;
- SecondImageRecord->ImageSize = TempImageRecord.ImageSize;
+ SecondImageRecord->ImageBase = TempImageRecord.ImageBase;
+ SecondImageRecord->ImageSize = TempImageRecord.ImageSize;
SecondImageRecord->CodeSegmentCount = TempImageRecord.CodeSegmentCount;
SwapListEntries (&FirstImageRecord->CodeSegmentList, &SecondImageRecord->CodeSegmentList);
@@ -1215,18 +1234,18 @@ SortImageRecord ( VOID
)
{
- IMAGE_PROPERTIES_RECORD *ImageRecord;
- IMAGE_PROPERTIES_RECORD *NextImageRecord;
- LIST_ENTRY *ImageRecordLink;
- LIST_ENTRY *NextImageRecordLink;
- LIST_ENTRY *ImageRecordEndLink;
- LIST_ENTRY *ImageRecordList;
+ IMAGE_PROPERTIES_RECORD *ImageRecord;
+ IMAGE_PROPERTIES_RECORD *NextImageRecord;
+ LIST_ENTRY *ImageRecordLink;
+ LIST_ENTRY *NextImageRecordLink;
+ LIST_ENTRY *ImageRecordEndLink;
+ LIST_ENTRY *ImageRecordList;
ImageRecordList = &mImagePropertiesPrivateData.ImageRecordList;
- ImageRecordLink = ImageRecordList->ForwardLink;
+ ImageRecordLink = ImageRecordList->ForwardLink;
NextImageRecordLink = ImageRecordLink->ForwardLink;
- ImageRecordEndLink = ImageRecordList;
+ ImageRecordEndLink = ImageRecordList;
while (ImageRecordLink != ImageRecordEndLink) {
ImageRecord = CR (
ImageRecordLink,
@@ -1244,10 +1263,11 @@ SortImageRecord ( if (ImageRecord->ImageBase > NextImageRecord->ImageBase) {
SwapImageRecord (ImageRecord, NextImageRecord);
}
+
NextImageRecordLink = NextImageRecordLink->ForwardLink;
}
- ImageRecordLink = ImageRecordLink->ForwardLink;
+ ImageRecordLink = ImageRecordLink->ForwardLink;
NextImageRecordLink = ImageRecordLink->ForwardLink;
}
}
@@ -1262,30 +1282,31 @@ InsertImageRecord ( IN EFI_RUNTIME_IMAGE_ENTRY *RuntimeImage
)
{
- VOID *ImageAddress;
- EFI_IMAGE_DOS_HEADER *DosHdr;
- UINT32 PeCoffHeaderOffset;
- UINT32 SectionAlignment;
- EFI_IMAGE_SECTION_HEADER *Section;
- EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr;
- UINT8 *Name;
- UINTN Index;
- IMAGE_PROPERTIES_RECORD *ImageRecord;
- CHAR8 *PdbPointer;
- IMAGE_PROPERTIES_RECORD_CODE_SECTION *ImageRecordCodeSection;
+ VOID *ImageAddress;
+ EFI_IMAGE_DOS_HEADER *DosHdr;
+ UINT32 PeCoffHeaderOffset;
+ UINT32 SectionAlignment;
+ EFI_IMAGE_SECTION_HEADER *Section;
+ EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr;
+ UINT8 *Name;
+ UINTN Index;
+ IMAGE_PROPERTIES_RECORD *ImageRecord;
+ CHAR8 *PdbPointer;
+ IMAGE_PROPERTIES_RECORD_CODE_SECTION *ImageRecordCodeSection;
DEBUG ((DEBUG_VERBOSE, "InsertImageRecord - 0x%x\n", RuntimeImage));
DEBUG ((DEBUG_VERBOSE, "InsertImageRecord - 0x%016lx - 0x%016lx\n", (EFI_PHYSICAL_ADDRESS)(UINTN)RuntimeImage->ImageBase, RuntimeImage->ImageSize));
if (mMemoryAttributesTableEndOfDxe) {
DEBUG ((DEBUG_INFO, "Do not insert runtime image record after EndOfDxe\n"));
- return ;
+ return;
}
- ImageRecord = AllocatePool (sizeof(*ImageRecord));
+ ImageRecord = AllocatePool (sizeof (*ImageRecord));
if (ImageRecord == NULL) {
- return ;
+ return;
}
+
ImageRecord->Signature = IMAGE_PROPERTIES_RECORD_SIGNATURE;
DEBUG ((DEBUG_VERBOSE, "ImageRecordCount - 0x%x\n", mImagePropertiesPrivateData.ImageRecordCount));
@@ -1298,7 +1319,7 @@ InsertImageRecord ( ImageAddress = RuntimeImage->ImageBase;
- PdbPointer = PeCoffLoaderGetPdbPointer ((VOID*) (UINTN) ImageAddress);
+ PdbPointer = PeCoffLoaderGetPdbPointer ((VOID *)(UINTN)ImageAddress);
if (PdbPointer != NULL) {
DEBUG ((DEBUG_VERBOSE, " Image - %a\n", PdbPointer));
}
@@ -1306,13 +1327,13 @@ InsertImageRecord ( //
// Check PE/COFF image
//
- DosHdr = (EFI_IMAGE_DOS_HEADER *) (UINTN) ImageAddress;
+ DosHdr = (EFI_IMAGE_DOS_HEADER *)(UINTN)ImageAddress;
PeCoffHeaderOffset = 0;
if (DosHdr->e_magic == EFI_IMAGE_DOS_SIGNATURE) {
PeCoffHeaderOffset = DosHdr->e_lfanew;
}
- Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)((UINT8 *) (UINTN) ImageAddress + PeCoffHeaderOffset);
+ Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)((UINT8 *)(UINTN)ImageAddress + PeCoffHeaderOffset);
if (Hdr.Pe32->Signature != EFI_IMAGE_NT_SIGNATURE) {
DEBUG ((DEBUG_VERBOSE, "Hdr.Pe32->Signature invalid - 0x%x\n", Hdr.Pe32->Signature));
// It might be image in SMM.
@@ -1323,29 +1344,34 @@ InsertImageRecord ( // Get SectionAlignment
//
if (Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {
- SectionAlignment = Hdr.Pe32->OptionalHeader.SectionAlignment;
+ SectionAlignment = Hdr.Pe32->OptionalHeader.SectionAlignment;
} else {
- SectionAlignment = Hdr.Pe32Plus->OptionalHeader.SectionAlignment;
+ SectionAlignment = Hdr.Pe32Plus->OptionalHeader.SectionAlignment;
}
SetMemoryAttributesTableSectionAlignment (SectionAlignment);
if ((SectionAlignment & (RUNTIME_PAGE_ALLOCATION_GRANULARITY - 1)) != 0) {
- DEBUG ((DEBUG_WARN, "!!!!!!!! InsertImageRecord - Section Alignment(0x%x) is not %dK !!!!!!!!\n",
- SectionAlignment, RUNTIME_PAGE_ALLOCATION_GRANULARITY >> 10));
- PdbPointer = PeCoffLoaderGetPdbPointer ((VOID*) (UINTN) ImageAddress);
+ DEBUG ((
+ DEBUG_WARN,
+ "!!!!!!!! InsertImageRecord - Section Alignment(0x%x) is not %dK !!!!!!!!\n",
+ SectionAlignment,
+ RUNTIME_PAGE_ALLOCATION_GRANULARITY >> 10
+ ));
+ PdbPointer = PeCoffLoaderGetPdbPointer ((VOID *)(UINTN)ImageAddress);
if (PdbPointer != NULL) {
DEBUG ((DEBUG_WARN, "!!!!!!!! Image - %a !!!!!!!!\n", PdbPointer));
}
+
goto Finish;
}
- Section = (EFI_IMAGE_SECTION_HEADER *) (
- (UINT8 *) (UINTN) ImageAddress +
- PeCoffHeaderOffset +
- sizeof(UINT32) +
- sizeof(EFI_IMAGE_FILE_HEADER) +
- Hdr.Pe32->FileHeader.SizeOfOptionalHeader
- );
+ Section = (EFI_IMAGE_SECTION_HEADER *)(
+ (UINT8 *)(UINTN)ImageAddress +
+ PeCoffHeaderOffset +
+ sizeof (UINT32) +
+ sizeof (EFI_IMAGE_FILE_HEADER) +
+ Hdr.Pe32->FileHeader.SizeOfOptionalHeader
+ );
ImageRecord->CodeSegmentCount = 0;
InitializeListHead (&ImageRecord->CodeSegmentList);
for (Index = 0; Index < Hdr.Pe32->FileHeader.NumberOfSections; Index++) {
@@ -1377,10 +1403,11 @@ InsertImageRecord ( //
// Step 2: record code section
//
- ImageRecordCodeSection = AllocatePool (sizeof(*ImageRecordCodeSection));
+ ImageRecordCodeSection = AllocatePool (sizeof (*ImageRecordCodeSection));
if (ImageRecordCodeSection == NULL) {
- return ;
+ return;
}
+
ImageRecordCodeSection->Signature = IMAGE_PROPERTIES_RECORD_CODE_SECTION_SIGNATURE;
ImageRecordCodeSection->CodeSegmentBase = (UINTN)ImageAddress + Section[Index].VirtualAddress;
@@ -1396,10 +1423,11 @@ InsertImageRecord ( if (ImageRecord->CodeSegmentCount == 0) {
SetMemoryAttributesTableSectionAlignment (1);
DEBUG ((DEBUG_ERROR, "!!!!!!!! InsertImageRecord - CodeSegmentCount is 0 !!!!!!!!\n"));
- PdbPointer = PeCoffLoaderGetPdbPointer ((VOID*) (UINTN) ImageAddress);
+ PdbPointer = PeCoffLoaderGetPdbPointer ((VOID *)(UINTN)ImageAddress);
if (PdbPointer != NULL) {
DEBUG ((DEBUG_ERROR, "!!!!!!!! Image - %a !!!!!!!!\n", PdbPointer));
}
+
goto Finish;
}
@@ -1425,7 +1453,7 @@ InsertImageRecord ( SortImageRecord ();
Finish:
- return ;
+ return;
}
/**
@@ -1443,15 +1471,16 @@ FindImageRecord ( IN UINT64 ImageSize
)
{
- IMAGE_PROPERTIES_RECORD *ImageRecord;
- LIST_ENTRY *ImageRecordLink;
- LIST_ENTRY *ImageRecordList;
+ IMAGE_PROPERTIES_RECORD *ImageRecord;
+ LIST_ENTRY *ImageRecordLink;
+ LIST_ENTRY *ImageRecordList;
ImageRecordList = &mImagePropertiesPrivateData.ImageRecordList;
for (ImageRecordLink = ImageRecordList->ForwardLink;
ImageRecordLink != ImageRecordList;
- ImageRecordLink = ImageRecordLink->ForwardLink) {
+ ImageRecordLink = ImageRecordLink->ForwardLink)
+ {
ImageRecord = CR (
ImageRecordLink,
IMAGE_PROPERTIES_RECORD,
@@ -1460,7 +1489,8 @@ FindImageRecord ( );
if ((ImageBase == ImageRecord->ImageBase) &&
- (ImageSize == ImageRecord->ImageSize)) {
+ (ImageSize == ImageRecord->ImageSize))
+ {
return ImageRecord;
}
}
@@ -1478,22 +1508,22 @@ RemoveImageRecord ( IN EFI_RUNTIME_IMAGE_ENTRY *RuntimeImage
)
{
- IMAGE_PROPERTIES_RECORD *ImageRecord;
- LIST_ENTRY *CodeSegmentListHead;
- IMAGE_PROPERTIES_RECORD_CODE_SECTION *ImageRecordCodeSection;
+ IMAGE_PROPERTIES_RECORD *ImageRecord;
+ LIST_ENTRY *CodeSegmentListHead;
+ IMAGE_PROPERTIES_RECORD_CODE_SECTION *ImageRecordCodeSection;
DEBUG ((DEBUG_VERBOSE, "RemoveImageRecord - 0x%x\n", RuntimeImage));
DEBUG ((DEBUG_VERBOSE, "RemoveImageRecord - 0x%016lx - 0x%016lx\n", (EFI_PHYSICAL_ADDRESS)(UINTN)RuntimeImage->ImageBase, RuntimeImage->ImageSize));
if (mMemoryAttributesTableEndOfDxe) {
DEBUG ((DEBUG_INFO, "Do not remove runtime image record after EndOfDxe\n"));
- return ;
+ return;
}
ImageRecord = FindImageRecord ((EFI_PHYSICAL_ADDRESS)(UINTN)RuntimeImage->ImageBase, RuntimeImage->ImageSize);
if (ImageRecord == NULL) {
DEBUG ((DEBUG_ERROR, "!!!!!!!! ImageRecord not found !!!!!!!!\n"));
- return ;
+ return;
}
CodeSegmentListHead = &ImageRecord->CodeSegmentList;
diff --git a/MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c b/MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c index 7d1daf0b19..b89ab046fa 100644 --- a/MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c +++ b/MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c @@ -45,26 +45,26 @@ SPDX-License-Identifier: BSD-2-Clause-Patent //
// Image type definitions
//
-#define IMAGE_UNKNOWN 0x00000001
-#define IMAGE_FROM_FV 0x00000002
+#define IMAGE_UNKNOWN 0x00000001
+#define IMAGE_FROM_FV 0x00000002
//
// Protection policy bit definition
//
-#define DO_NOT_PROTECT 0x00000000
-#define PROTECT_IF_ALIGNED_ELSE_ALLOW 0x00000001
+#define DO_NOT_PROTECT 0x00000000
+#define PROTECT_IF_ALIGNED_ELSE_ALLOW 0x00000001
-#define MEMORY_TYPE_OS_RESERVED_MIN 0x80000000
-#define MEMORY_TYPE_OEM_RESERVED_MIN 0x70000000
+#define MEMORY_TYPE_OS_RESERVED_MIN 0x80000000
+#define MEMORY_TYPE_OEM_RESERVED_MIN 0x70000000
#define PREVIOUS_MEMORY_DESCRIPTOR(MemoryDescriptor, Size) \
((EFI_MEMORY_DESCRIPTOR *)((UINT8 *)(MemoryDescriptor) - (Size)))
-UINT32 mImageProtectionPolicy;
+UINT32 mImageProtectionPolicy;
-extern LIST_ENTRY mGcdMemorySpaceMap;
+extern LIST_ENTRY mGcdMemorySpaceMap;
-STATIC LIST_ENTRY mProtectedImageRecordList;
+STATIC LIST_ENTRY mProtectedImageRecordList;
/**
Sort code section in image record, based upon CodeSegmentBase from low to high.
@@ -73,7 +73,7 @@ STATIC LIST_ENTRY mProtectedImageRecordList; **/
VOID
SortImageRecordCodeSection (
- IN IMAGE_PROPERTIES_RECORD *ImageRecord
+ IN IMAGE_PROPERTIES_RECORD *ImageRecord
);
/**
@@ -86,7 +86,7 @@ SortImageRecordCodeSection ( **/
BOOLEAN
IsImageRecordCodeSectionValid (
- IN IMAGE_PROPERTIES_RECORD *ImageRecord
+ IN IMAGE_PROPERTIES_RECORD *ImageRecord
);
/**
@@ -99,12 +99,12 @@ IsImageRecordCodeSectionValid ( **/
UINT32
GetImageType (
- IN CONST EFI_DEVICE_PATH_PROTOCOL *File
+ IN CONST EFI_DEVICE_PATH_PROTOCOL *File
)
{
- EFI_STATUS Status;
- EFI_HANDLE DeviceHandle;
- EFI_DEVICE_PATH_PROTOCOL *TempDevicePath;
+ EFI_STATUS Status;
+ EFI_HANDLE DeviceHandle;
+ EFI_DEVICE_PATH_PROTOCOL *TempDevicePath;
if (File == NULL) {
return IMAGE_UNKNOWN;
@@ -113,13 +113,13 @@ GetImageType ( //
// First check to see if File is from a Firmware Volume
//
- DeviceHandle = NULL;
- TempDevicePath = (EFI_DEVICE_PATH_PROTOCOL *) File;
- Status = gBS->LocateDevicePath (
- &gEfiFirmwareVolume2ProtocolGuid,
- &TempDevicePath,
- &DeviceHandle
- );
+ DeviceHandle = NULL;
+ TempDevicePath = (EFI_DEVICE_PATH_PROTOCOL *)File;
+ Status = gBS->LocateDevicePath (
+ &gEfiFirmwareVolume2ProtocolGuid,
+ &TempDevicePath,
+ &DeviceHandle
+ );
if (!EFI_ERROR (Status)) {
Status = gBS->OpenProtocol (
DeviceHandle,
@@ -133,6 +133,7 @@ GetImageType ( return IMAGE_FROM_FV;
}
}
+
return IMAGE_UNKNOWN;
}
@@ -165,13 +166,13 @@ GetProtectionPolicyFromImageType ( **/
UINT32
GetUefiImageProtectionPolicy (
- IN EFI_LOADED_IMAGE_PROTOCOL *LoadedImage,
- IN EFI_DEVICE_PATH_PROTOCOL *LoadedImageDevicePath
+ IN EFI_LOADED_IMAGE_PROTOCOL *LoadedImage,
+ IN EFI_DEVICE_PATH_PROTOCOL *LoadedImageDevicePath
)
{
- BOOLEAN InSmm;
- UINT32 ImageType;
- UINT32 ProtectionPolicy;
+ BOOLEAN InSmm;
+ UINT32 ImageType;
+ UINT32 ProtectionPolicy;
//
// Check SMM
@@ -180,6 +181,7 @@ GetUefiImageProtectionPolicy ( if (gSmmBase2 != NULL) {
gSmmBase2->InSmm (gSmmBase2, &InSmm);
}
+
if (InSmm) {
return FALSE;
}
@@ -192,11 +194,11 @@ GetUefiImageProtectionPolicy ( } else {
ImageType = GetImageType (LoadedImageDevicePath);
}
+
ProtectionPolicy = GetProtectionPolicyFromImageType (ImageType);
return ProtectionPolicy;
}
-
/**
Set UEFI image memory attributes.
@@ -206,23 +208,23 @@ GetUefiImageProtectionPolicy ( **/
VOID
SetUefiImageMemoryAttributes (
- IN UINT64 BaseAddress,
- IN UINT64 Length,
- IN UINT64 Attributes
+ IN UINT64 BaseAddress,
+ IN UINT64 Length,
+ IN UINT64 Attributes
)
{
EFI_STATUS Status;
EFI_GCD_MEMORY_SPACE_DESCRIPTOR Descriptor;
UINT64 FinalAttributes;
- Status = CoreGetMemorySpaceDescriptor(BaseAddress, &Descriptor);
- ASSERT_EFI_ERROR(Status);
+ Status = CoreGetMemorySpaceDescriptor (BaseAddress, &Descriptor);
+ ASSERT_EFI_ERROR (Status);
FinalAttributes = (Descriptor.Attributes & EFI_CACHE_ATTRIBUTE_MASK) | (Attributes & EFI_MEMORY_ATTRIBUTE_MASK);
DEBUG ((DEBUG_INFO, "SetUefiImageMemoryAttributes - 0x%016lx - 0x%016lx (0x%016lx)\n", BaseAddress, Length, FinalAttributes));
- ASSERT(gCpu != NULL);
+ ASSERT (gCpu != NULL);
gCpu->SetMemoryAttributes (gCpu, BaseAddress, Length, FinalAttributes);
}
@@ -233,22 +235,22 @@ SetUefiImageMemoryAttributes ( **/
VOID
SetUefiImageProtectionAttributes (
- IN IMAGE_PROPERTIES_RECORD *ImageRecord
+ IN IMAGE_PROPERTIES_RECORD *ImageRecord
)
{
- IMAGE_PROPERTIES_RECORD_CODE_SECTION *ImageRecordCodeSection;
- LIST_ENTRY *ImageRecordCodeSectionLink;
- LIST_ENTRY *ImageRecordCodeSectionEndLink;
- LIST_ENTRY *ImageRecordCodeSectionList;
- UINT64 CurrentBase;
- UINT64 ImageEnd;
+ IMAGE_PROPERTIES_RECORD_CODE_SECTION *ImageRecordCodeSection;
+ LIST_ENTRY *ImageRecordCodeSectionLink;
+ LIST_ENTRY *ImageRecordCodeSectionEndLink;
+ LIST_ENTRY *ImageRecordCodeSectionList;
+ UINT64 CurrentBase;
+ UINT64 ImageEnd;
ImageRecordCodeSectionList = &ImageRecord->CodeSegmentList;
CurrentBase = ImageRecord->ImageBase;
ImageEnd = ImageRecord->ImageBase + ImageRecord->ImageSize;
- ImageRecordCodeSectionLink = ImageRecordCodeSectionList->ForwardLink;
+ ImageRecordCodeSectionLink = ImageRecordCodeSectionList->ForwardLink;
ImageRecordCodeSectionEndLink = ImageRecordCodeSectionList;
while (ImageRecordCodeSectionLink != ImageRecordCodeSectionEndLink) {
ImageRecordCodeSection = CR (
@@ -270,6 +272,7 @@ SetUefiImageProtectionAttributes ( EFI_MEMORY_XP
);
}
+
//
// CODE
//
@@ -280,6 +283,7 @@ SetUefiImageProtectionAttributes ( );
CurrentBase = ImageRecordCodeSection->CodeSegmentBase + ImageRecordCodeSection->CodeSegmentSize;
}
+
//
// Last DATA
//
@@ -294,7 +298,8 @@ SetUefiImageProtectionAttributes ( EFI_MEMORY_XP
);
}
- return ;
+
+ return;
}
/**
@@ -315,24 +320,24 @@ IsMemoryProtectionSectionAligned ( UINT32 PageAlignment;
switch (MemoryType) {
- case EfiRuntimeServicesCode:
- case EfiACPIMemoryNVS:
- PageAlignment = RUNTIME_PAGE_ALLOCATION_GRANULARITY;
- break;
- case EfiRuntimeServicesData:
- case EfiACPIReclaimMemory:
- ASSERT (FALSE);
- PageAlignment = RUNTIME_PAGE_ALLOCATION_GRANULARITY;
- break;
- case EfiBootServicesCode:
- case EfiLoaderCode:
- case EfiReservedMemoryType:
- PageAlignment = EFI_PAGE_SIZE;
- break;
- default:
- ASSERT (FALSE);
- PageAlignment = EFI_PAGE_SIZE;
- break;
+ case EfiRuntimeServicesCode:
+ case EfiACPIMemoryNVS:
+ PageAlignment = RUNTIME_PAGE_ALLOCATION_GRANULARITY;
+ break;
+ case EfiRuntimeServicesData:
+ case EfiACPIReclaimMemory:
+ ASSERT (FALSE);
+ PageAlignment = RUNTIME_PAGE_ALLOCATION_GRANULARITY;
+ break;
+ case EfiBootServicesCode:
+ case EfiLoaderCode:
+ case EfiReservedMemoryType:
+ PageAlignment = EFI_PAGE_SIZE;
+ break;
+ default:
+ ASSERT (FALSE);
+ PageAlignment = EFI_PAGE_SIZE;
+ break;
}
if ((SectionAlignment & (PageAlignment - 1)) != 0) {
@@ -349,11 +354,11 @@ IsMemoryProtectionSectionAligned ( **/
VOID
FreeImageRecord (
- IN IMAGE_PROPERTIES_RECORD *ImageRecord
+ IN IMAGE_PROPERTIES_RECORD *ImageRecord
)
{
- LIST_ENTRY *CodeSegmentListHead;
- IMAGE_PROPERTIES_RECORD_CODE_SECTION *ImageRecordCodeSection;
+ LIST_ENTRY *CodeSegmentListHead;
+ IMAGE_PROPERTIES_RECORD_CODE_SECTION *ImageRecordCodeSection;
CodeSegmentListHead = &ImageRecord->CodeSegmentList;
while (!IsListEmpty (CodeSegmentListHead)) {
@@ -370,6 +375,7 @@ FreeImageRecord ( if (ImageRecord->Link.ForwardLink != NULL) {
RemoveEntryList (&ImageRecord->Link);
}
+
FreePool (ImageRecord);
}
@@ -381,46 +387,47 @@ FreeImageRecord ( **/
VOID
ProtectUefiImage (
- IN EFI_LOADED_IMAGE_PROTOCOL *LoadedImage,
- IN EFI_DEVICE_PATH_PROTOCOL *LoadedImageDevicePath
+ IN EFI_LOADED_IMAGE_PROTOCOL *LoadedImage,
+ IN EFI_DEVICE_PATH_PROTOCOL *LoadedImageDevicePath
)
{
- VOID *ImageAddress;
- EFI_IMAGE_DOS_HEADER *DosHdr;
- UINT32 PeCoffHeaderOffset;
- UINT32 SectionAlignment;
- EFI_IMAGE_SECTION_HEADER *Section;
- EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr;
- UINT8 *Name;
- UINTN Index;
- IMAGE_PROPERTIES_RECORD *ImageRecord;
- CHAR8 *PdbPointer;
- IMAGE_PROPERTIES_RECORD_CODE_SECTION *ImageRecordCodeSection;
- BOOLEAN IsAligned;
- UINT32 ProtectionPolicy;
+ VOID *ImageAddress;
+ EFI_IMAGE_DOS_HEADER *DosHdr;
+ UINT32 PeCoffHeaderOffset;
+ UINT32 SectionAlignment;
+ EFI_IMAGE_SECTION_HEADER *Section;
+ EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr;
+ UINT8 *Name;
+ UINTN Index;
+ IMAGE_PROPERTIES_RECORD *ImageRecord;
+ CHAR8 *PdbPointer;
+ IMAGE_PROPERTIES_RECORD_CODE_SECTION *ImageRecordCodeSection;
+ BOOLEAN IsAligned;
+ UINT32 ProtectionPolicy;
DEBUG ((DEBUG_INFO, "ProtectUefiImageCommon - 0x%x\n", LoadedImage));
DEBUG ((DEBUG_INFO, " - 0x%016lx - 0x%016lx\n", (EFI_PHYSICAL_ADDRESS)(UINTN)LoadedImage->ImageBase, LoadedImage->ImageSize));
if (gCpu == NULL) {
- return ;
+ return;
}
ProtectionPolicy = GetUefiImageProtectionPolicy (LoadedImage, LoadedImageDevicePath);
switch (ProtectionPolicy) {
- case DO_NOT_PROTECT:
- return ;
- case PROTECT_IF_ALIGNED_ELSE_ALLOW:
- break;
- default:
- ASSERT(FALSE);
- return ;
+ case DO_NOT_PROTECT:
+ return;
+ case PROTECT_IF_ALIGNED_ELSE_ALLOW:
+ break;
+ default:
+ ASSERT (FALSE);
+ return;
}
- ImageRecord = AllocateZeroPool (sizeof(*ImageRecord));
+ ImageRecord = AllocateZeroPool (sizeof (*ImageRecord));
if (ImageRecord == NULL) {
- return ;
+ return;
}
+
ImageRecord->Signature = IMAGE_PROPERTIES_RECORD_SIGNATURE;
//
@@ -431,7 +438,7 @@ ProtectUefiImage ( ImageAddress = LoadedImage->ImageBase;
- PdbPointer = PeCoffLoaderGetPdbPointer ((VOID*) (UINTN) ImageAddress);
+ PdbPointer = PeCoffLoaderGetPdbPointer ((VOID *)(UINTN)ImageAddress);
if (PdbPointer != NULL) {
DEBUG ((DEBUG_VERBOSE, " Image - %a\n", PdbPointer));
}
@@ -439,13 +446,13 @@ ProtectUefiImage ( //
// Check PE/COFF image
//
- DosHdr = (EFI_IMAGE_DOS_HEADER *) (UINTN) ImageAddress;
+ DosHdr = (EFI_IMAGE_DOS_HEADER *)(UINTN)ImageAddress;
PeCoffHeaderOffset = 0;
if (DosHdr->e_magic == EFI_IMAGE_DOS_SIGNATURE) {
PeCoffHeaderOffset = DosHdr->e_lfanew;
}
- Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)((UINT8 *) (UINTN) ImageAddress + PeCoffHeaderOffset);
+ Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)((UINT8 *)(UINTN)ImageAddress + PeCoffHeaderOffset);
if (Hdr.Pe32->Signature != EFI_IMAGE_NT_SIGNATURE) {
DEBUG ((DEBUG_VERBOSE, "Hdr.Pe32->Signature invalid - 0x%x\n", Hdr.Pe32->Signature));
// It might be image in SMM.
@@ -456,29 +463,33 @@ ProtectUefiImage ( // Get SectionAlignment
//
if (Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {
- SectionAlignment = Hdr.Pe32->OptionalHeader.SectionAlignment;
+ SectionAlignment = Hdr.Pe32->OptionalHeader.SectionAlignment;
} else {
- SectionAlignment = Hdr.Pe32Plus->OptionalHeader.SectionAlignment;
+ SectionAlignment = Hdr.Pe32Plus->OptionalHeader.SectionAlignment;
}
IsAligned = IsMemoryProtectionSectionAligned (SectionAlignment, LoadedImage->ImageCodeType);
if (!IsAligned) {
- DEBUG ((DEBUG_VERBOSE, "!!!!!!!! ProtectUefiImageCommon - Section Alignment(0x%x) is incorrect !!!!!!!!\n",
- SectionAlignment));
- PdbPointer = PeCoffLoaderGetPdbPointer ((VOID*) (UINTN) ImageAddress);
+ DEBUG ((
+ DEBUG_VERBOSE,
+ "!!!!!!!! ProtectUefiImageCommon - Section Alignment(0x%x) is incorrect !!!!!!!!\n",
+ SectionAlignment
+ ));
+ PdbPointer = PeCoffLoaderGetPdbPointer ((VOID *)(UINTN)ImageAddress);
if (PdbPointer != NULL) {
DEBUG ((DEBUG_VERBOSE, "!!!!!!!! Image - %a !!!!!!!!\n", PdbPointer));
}
+
goto Finish;
}
- Section = (EFI_IMAGE_SECTION_HEADER *) (
- (UINT8 *) (UINTN) ImageAddress +
- PeCoffHeaderOffset +
- sizeof(UINT32) +
- sizeof(EFI_IMAGE_FILE_HEADER) +
- Hdr.Pe32->FileHeader.SizeOfOptionalHeader
- );
+ Section = (EFI_IMAGE_SECTION_HEADER *)(
+ (UINT8 *)(UINTN)ImageAddress +
+ PeCoffHeaderOffset +
+ sizeof (UINT32) +
+ sizeof (EFI_IMAGE_FILE_HEADER) +
+ Hdr.Pe32->FileHeader.SizeOfOptionalHeader
+ );
ImageRecord->CodeSegmentCount = 0;
InitializeListHead (&ImageRecord->CodeSegmentList);
for (Index = 0; Index < Hdr.Pe32->FileHeader.NumberOfSections; Index++) {
@@ -518,14 +529,15 @@ ProtectUefiImage ( //
// Step 2: record code section
//
- ImageRecordCodeSection = AllocatePool (sizeof(*ImageRecordCodeSection));
+ ImageRecordCodeSection = AllocatePool (sizeof (*ImageRecordCodeSection));
if (ImageRecordCodeSection == NULL) {
- return ;
+ return;
}
+
ImageRecordCodeSection->Signature = IMAGE_PROPERTIES_RECORD_CODE_SECTION_SIGNATURE;
ImageRecordCodeSection->CodeSegmentBase = (UINTN)ImageAddress + Section[Index].VirtualAddress;
- ImageRecordCodeSection->CodeSegmentSize = ALIGN_VALUE(Section[Index].SizeOfRawData, SectionAlignment);
+ ImageRecordCodeSection->CodeSegmentSize = ALIGN_VALUE (Section[Index].SizeOfRawData, SectionAlignment);
DEBUG ((DEBUG_VERBOSE, "ImageCode: 0x%016lx - 0x%016lx\n", ImageRecordCodeSection->CodeSegmentBase, ImageRecordCodeSection->CodeSegmentSize));
@@ -544,10 +556,11 @@ ProtectUefiImage ( // of course).
//
DEBUG ((DEBUG_WARN, "!!!!!!!! ProtectUefiImageCommon - CodeSegmentCount is 0 !!!!!!!!\n"));
- PdbPointer = PeCoffLoaderGetPdbPointer ((VOID*) (UINTN) ImageAddress);
+ PdbPointer = PeCoffLoaderGetPdbPointer ((VOID *)(UINTN)ImageAddress);
if (PdbPointer != NULL) {
DEBUG ((DEBUG_WARN, "!!!!!!!! Image - %a !!!!!!!!\n", PdbPointer));
}
+
goto Finish;
}
@@ -567,7 +580,7 @@ ProtectUefiImage ( // Round up the ImageSize, some CPU arch may return EFI_UNSUPPORTED if ImageSize is not aligned.
// Given that the loader always allocates full pages, we know the space after the image is not used.
//
- ImageRecord->ImageSize = ALIGN_VALUE(LoadedImage->ImageSize, EFI_PAGE_SIZE);
+ ImageRecord->ImageSize = ALIGN_VALUE (LoadedImage->ImageSize, EFI_PAGE_SIZE);
//
// CPU ARCH present. Update memory attribute directly.
@@ -580,7 +593,7 @@ ProtectUefiImage ( InsertTailList (&mProtectedImageRecordList, &ImageRecord->Link);
Finish:
- return ;
+ return;
}
/**
@@ -591,17 +604,18 @@ Finish: **/
VOID
UnprotectUefiImage (
- IN EFI_LOADED_IMAGE_PROTOCOL *LoadedImage,
- IN EFI_DEVICE_PATH_PROTOCOL *LoadedImageDevicePath
+ IN EFI_LOADED_IMAGE_PROTOCOL *LoadedImage,
+ IN EFI_DEVICE_PATH_PROTOCOL *LoadedImageDevicePath
)
{
- IMAGE_PROPERTIES_RECORD *ImageRecord;
- LIST_ENTRY *ImageRecordLink;
+ IMAGE_PROPERTIES_RECORD *ImageRecord;
+ LIST_ENTRY *ImageRecordLink;
- if (PcdGet32(PcdImageProtectionPolicy) != 0) {
+ if (PcdGet32 (PcdImageProtectionPolicy) != 0) {
for (ImageRecordLink = mProtectedImageRecordList.ForwardLink;
ImageRecordLink != &mProtectedImageRecordList;
- ImageRecordLink = ImageRecordLink->ForwardLink) {
+ ImageRecordLink = ImageRecordLink->ForwardLink)
+ {
ImageRecord = CR (
ImageRecordLink,
IMAGE_PROPERTIES_RECORD,
@@ -610,9 +624,11 @@ UnprotectUefiImage ( );
if (ImageRecord->ImageBase == (EFI_PHYSICAL_ADDRESS)(UINTN)LoadedImage->ImageBase) {
- SetUefiImageMemoryAttributes (ImageRecord->ImageBase,
- ImageRecord->ImageSize,
- 0);
+ SetUefiImageMemoryAttributes (
+ ImageRecord->ImageBase,
+ ImageRecord->ImageSize,
+ 0
+ );
FreeImageRecord (ImageRecord);
return;
}
@@ -629,10 +645,10 @@ UnprotectUefiImage ( STATIC
UINT64
GetPermissionAttributeForMemoryType (
- IN EFI_MEMORY_TYPE MemoryType
+ IN EFI_MEMORY_TYPE MemoryType
)
{
- UINT64 TestBit;
+ UINT64 TestBit;
if ((UINT32)MemoryType >= MEMORY_TYPE_OS_RESERVED_MIN) {
TestBit = BIT63;
@@ -665,27 +681,27 @@ SortMemoryMap ( IN UINTN DescriptorSize
)
{
- EFI_MEMORY_DESCRIPTOR *MemoryMapEntry;
- EFI_MEMORY_DESCRIPTOR *NextMemoryMapEntry;
- EFI_MEMORY_DESCRIPTOR *MemoryMapEnd;
- EFI_MEMORY_DESCRIPTOR TempMemoryMap;
+ EFI_MEMORY_DESCRIPTOR *MemoryMapEntry;
+ EFI_MEMORY_DESCRIPTOR *NextMemoryMapEntry;
+ EFI_MEMORY_DESCRIPTOR *MemoryMapEnd;
+ EFI_MEMORY_DESCRIPTOR TempMemoryMap;
- MemoryMapEntry = MemoryMap;
+ MemoryMapEntry = MemoryMap;
NextMemoryMapEntry = NEXT_MEMORY_DESCRIPTOR (MemoryMapEntry, DescriptorSize);
- MemoryMapEnd = (EFI_MEMORY_DESCRIPTOR *) ((UINT8 *) MemoryMap + MemoryMapSize);
+ MemoryMapEnd = (EFI_MEMORY_DESCRIPTOR *)((UINT8 *)MemoryMap + MemoryMapSize);
while (MemoryMapEntry < MemoryMapEnd) {
while (NextMemoryMapEntry < MemoryMapEnd) {
if (MemoryMapEntry->PhysicalStart > NextMemoryMapEntry->PhysicalStart) {
- CopyMem (&TempMemoryMap, MemoryMapEntry, sizeof(EFI_MEMORY_DESCRIPTOR));
- CopyMem (MemoryMapEntry, NextMemoryMapEntry, sizeof(EFI_MEMORY_DESCRIPTOR));
- CopyMem (NextMemoryMapEntry, &TempMemoryMap, sizeof(EFI_MEMORY_DESCRIPTOR));
+ CopyMem (&TempMemoryMap, MemoryMapEntry, sizeof (EFI_MEMORY_DESCRIPTOR));
+ CopyMem (MemoryMapEntry, NextMemoryMapEntry, sizeof (EFI_MEMORY_DESCRIPTOR));
+ CopyMem (NextMemoryMapEntry, &TempMemoryMap, sizeof (EFI_MEMORY_DESCRIPTOR));
}
NextMemoryMapEntry = NEXT_MEMORY_DESCRIPTOR (NextMemoryMapEntry, DescriptorSize);
}
- MemoryMapEntry = NEXT_MEMORY_DESCRIPTOR (MemoryMapEntry, DescriptorSize);
- NextMemoryMapEntry = NEXT_MEMORY_DESCRIPTOR (MemoryMapEntry, DescriptorSize);
+ MemoryMapEntry = NEXT_MEMORY_DESCRIPTOR (MemoryMapEntry, DescriptorSize);
+ NextMemoryMapEntry = NEXT_MEMORY_DESCRIPTOR (MemoryMapEntry, DescriptorSize);
}
}
@@ -708,29 +724,30 @@ MergeMemoryMapForProtectionPolicy ( IN UINTN DescriptorSize
)
{
- EFI_MEMORY_DESCRIPTOR *MemoryMapEntry;
- EFI_MEMORY_DESCRIPTOR *MemoryMapEnd;
- UINT64 MemoryBlockLength;
- EFI_MEMORY_DESCRIPTOR *NewMemoryMapEntry;
- EFI_MEMORY_DESCRIPTOR *NextMemoryMapEntry;
- UINT64 Attributes;
+ EFI_MEMORY_DESCRIPTOR *MemoryMapEntry;
+ EFI_MEMORY_DESCRIPTOR *MemoryMapEnd;
+ UINT64 MemoryBlockLength;
+ EFI_MEMORY_DESCRIPTOR *NewMemoryMapEntry;
+ EFI_MEMORY_DESCRIPTOR *NextMemoryMapEntry;
+ UINT64 Attributes;
SortMemoryMap (MemoryMap, *MemoryMapSize, DescriptorSize);
- MemoryMapEntry = MemoryMap;
+ MemoryMapEntry = MemoryMap;
NewMemoryMapEntry = MemoryMap;
- MemoryMapEnd = (EFI_MEMORY_DESCRIPTOR *) ((UINT8 *) MemoryMap + *MemoryMapSize);
+ MemoryMapEnd = (EFI_MEMORY_DESCRIPTOR *)((UINT8 *)MemoryMap + *MemoryMapSize);
while ((UINTN)MemoryMapEntry < (UINTN)MemoryMapEnd) {
- CopyMem (NewMemoryMapEntry, MemoryMapEntry, sizeof(EFI_MEMORY_DESCRIPTOR));
+ CopyMem (NewMemoryMapEntry, MemoryMapEntry, sizeof (EFI_MEMORY_DESCRIPTOR));
NextMemoryMapEntry = NEXT_MEMORY_DESCRIPTOR (MemoryMapEntry, DescriptorSize);
do {
- MemoryBlockLength = (UINT64) (EFI_PAGES_TO_SIZE((UINTN)MemoryMapEntry->NumberOfPages));
- Attributes = GetPermissionAttributeForMemoryType (MemoryMapEntry->Type);
+ MemoryBlockLength = (UINT64)(EFI_PAGES_TO_SIZE ((UINTN)MemoryMapEntry->NumberOfPages));
+ Attributes = GetPermissionAttributeForMemoryType (MemoryMapEntry->Type);
if (((UINTN)NextMemoryMapEntry < (UINTN)MemoryMapEnd) &&
- Attributes == GetPermissionAttributeForMemoryType (NextMemoryMapEntry->Type) &&
- ((MemoryMapEntry->PhysicalStart + MemoryBlockLength) == NextMemoryMapEntry->PhysicalStart)) {
+ (Attributes == GetPermissionAttributeForMemoryType (NextMemoryMapEntry->Type)) &&
+ ((MemoryMapEntry->PhysicalStart + MemoryBlockLength) == NextMemoryMapEntry->PhysicalStart))
+ {
MemoryMapEntry->NumberOfPages += NextMemoryMapEntry->NumberOfPages;
if (NewMemoryMapEntry != MemoryMapEntry) {
NewMemoryMapEntry->NumberOfPages += NextMemoryMapEntry->NumberOfPages;
@@ -744,16 +761,15 @@ MergeMemoryMapForProtectionPolicy ( }
} while (TRUE);
- MemoryMapEntry = NEXT_MEMORY_DESCRIPTOR (MemoryMapEntry, DescriptorSize);
+ MemoryMapEntry = NEXT_MEMORY_DESCRIPTOR (MemoryMapEntry, DescriptorSize);
NewMemoryMapEntry = NEXT_MEMORY_DESCRIPTOR (NewMemoryMapEntry, DescriptorSize);
}
*MemoryMapSize = (UINTN)NewMemoryMapEntry - (UINTN)MemoryMap;
- return ;
+ return;
}
-
/**
Remove exec permissions from all regions whose type is identified by
PcdDxeNxMemoryProtectionPolicy.
@@ -764,20 +780,20 @@ InitializeDxeNxMemoryProtectionPolicy ( VOID
)
{
- UINTN MemoryMapSize;
- UINTN MapKey;
- UINTN DescriptorSize;
- UINT32 DescriptorVersion;
- EFI_MEMORY_DESCRIPTOR *MemoryMap;
- EFI_MEMORY_DESCRIPTOR *MemoryMapEntry;
- EFI_MEMORY_DESCRIPTOR *MemoryMapEnd;
- EFI_STATUS Status;
- UINT64 Attributes;
- LIST_ENTRY *Link;
- EFI_GCD_MAP_ENTRY *Entry;
- EFI_PEI_HOB_POINTERS Hob;
- EFI_HOB_MEMORY_ALLOCATION *MemoryHob;
- EFI_PHYSICAL_ADDRESS StackBase;
+ UINTN MemoryMapSize;
+ UINTN MapKey;
+ UINTN DescriptorSize;
+ UINT32 DescriptorVersion;
+ EFI_MEMORY_DESCRIPTOR *MemoryMap;
+ EFI_MEMORY_DESCRIPTOR *MemoryMapEntry;
+ EFI_MEMORY_DESCRIPTOR *MemoryMapEnd;
+ EFI_STATUS Status;
+ UINT64 Attributes;
+ LIST_ENTRY *Link;
+ EFI_GCD_MAP_ENTRY *Entry;
+ EFI_PEI_HOB_POINTERS Hob;
+ EFI_HOB_MEMORY_ALLOCATION *MemoryHob;
+ EFI_PHYSICAL_ADDRESS StackBase;
//
// Get the EFI memory map.
@@ -794,7 +810,7 @@ InitializeDxeNxMemoryProtectionPolicy ( );
ASSERT (Status == EFI_BUFFER_TOO_SMALL);
do {
- MemoryMap = (EFI_MEMORY_DESCRIPTOR *) AllocatePool (MemoryMapSize);
+ MemoryMap = (EFI_MEMORY_DESCRIPTOR *)AllocatePool (MemoryMapSize);
ASSERT (MemoryMap != NULL);
Status = gBS->GetMemoryMap (
&MemoryMapSize,
@@ -807,6 +823,7 @@ InitializeDxeNxMemoryProtectionPolicy ( FreePool (MemoryMap);
}
} while (Status == EFI_BUFFER_TOO_SMALL);
+
ASSERT_EFI_ERROR (Status);
StackBase = 0;
@@ -817,7 +834,7 @@ InitializeDxeNxMemoryProtectionPolicy ( Hob.Raw = GetHobList ();
while ((Hob.Raw = GetNextHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, Hob.Raw)) != NULL) {
MemoryHob = Hob.MemoryAllocation;
- if (CompareGuid(&gEfiHobMemoryAllocStackGuid, &MemoryHob->AllocDescriptor.Name)) {
+ if (CompareGuid (&gEfiHobMemoryAllocStackGuid, &MemoryHob->AllocDescriptor.Name)) {
DEBUG ((
DEBUG_INFO,
"%a: StackBase = 0x%016lx StackSize = 0x%016lx\n",
@@ -833,6 +850,7 @@ InitializeDxeNxMemoryProtectionPolicy ( ASSERT ((StackBase & EFI_PAGE_MASK) == 0);
break;
}
+
Hob.Raw = GET_NEXT_HOB (Hob);
}
@@ -852,49 +870,52 @@ InitializeDxeNxMemoryProtectionPolicy ( MergeMemoryMapForProtectionPolicy (MemoryMap, &MemoryMapSize, DescriptorSize);
MemoryMapEntry = MemoryMap;
- MemoryMapEnd = (EFI_MEMORY_DESCRIPTOR *) ((UINT8 *) MemoryMap + MemoryMapSize);
- while ((UINTN) MemoryMapEntry < (UINTN) MemoryMapEnd) {
-
+ MemoryMapEnd = (EFI_MEMORY_DESCRIPTOR *)((UINT8 *)MemoryMap + MemoryMapSize);
+ while ((UINTN)MemoryMapEntry < (UINTN)MemoryMapEnd) {
Attributes = GetPermissionAttributeForMemoryType (MemoryMapEntry->Type);
if (Attributes != 0) {
SetUefiImageMemoryAttributes (
MemoryMapEntry->PhysicalStart,
LShiftU64 (MemoryMapEntry->NumberOfPages, EFI_PAGE_SHIFT),
- Attributes);
+ Attributes
+ );
//
// Add EFI_MEMORY_RP attribute for page 0 if NULL pointer detection is
// enabled.
//
- if (MemoryMapEntry->PhysicalStart == 0 &&
- PcdGet8 (PcdNullPointerDetectionPropertyMask) != 0) {
-
+ if ((MemoryMapEntry->PhysicalStart == 0) &&
+ (PcdGet8 (PcdNullPointerDetectionPropertyMask) != 0))
+ {
ASSERT (MemoryMapEntry->NumberOfPages > 0);
SetUefiImageMemoryAttributes (
0,
EFI_PAGES_TO_SIZE (1),
- EFI_MEMORY_RP | Attributes);
+ EFI_MEMORY_RP | Attributes
+ );
}
//
// Add EFI_MEMORY_RP attribute for the first page of the stack if stack
// guard is enabled.
//
- if (StackBase != 0 &&
- (StackBase >= MemoryMapEntry->PhysicalStart &&
- StackBase < MemoryMapEntry->PhysicalStart +
- LShiftU64 (MemoryMapEntry->NumberOfPages, EFI_PAGE_SHIFT)) &&
- PcdGetBool (PcdCpuStackGuard)) {
-
+ if ((StackBase != 0) &&
+ ((StackBase >= MemoryMapEntry->PhysicalStart) &&
+ (StackBase < MemoryMapEntry->PhysicalStart +
+ LShiftU64 (MemoryMapEntry->NumberOfPages, EFI_PAGE_SHIFT))) &&
+ PcdGetBool (PcdCpuStackGuard))
+ {
SetUefiImageMemoryAttributes (
StackBase,
EFI_PAGES_TO_SIZE (1),
- EFI_MEMORY_RP | Attributes);
+ EFI_MEMORY_RP | Attributes
+ );
}
-
}
+
MemoryMapEntry = NEXT_MEMORY_DESCRIPTOR (MemoryMapEntry, DescriptorSize);
}
+
FreePool (MemoryMap);
//
@@ -912,34 +933,40 @@ InitializeDxeNxMemoryProtectionPolicy ( Link = mGcdMemorySpaceMap.ForwardLink;
while (Link != &mGcdMemorySpaceMap) {
-
Entry = CR (Link, EFI_GCD_MAP_ENTRY, Link, EFI_GCD_MAP_SIGNATURE);
- if (Entry->GcdMemoryType == EfiGcdMemoryTypeReserved &&
- Entry->EndAddress < MAX_ADDRESS &&
- (Entry->Capabilities & (EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED | EFI_MEMORY_TESTED)) ==
- (EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED)) {
-
+ if ((Entry->GcdMemoryType == EfiGcdMemoryTypeReserved) &&
+ (Entry->EndAddress < MAX_ADDRESS) &&
+ ((Entry->Capabilities & (EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED | EFI_MEMORY_TESTED)) ==
+ (EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED)))
+ {
Attributes = GetPermissionAttributeForMemoryType (EfiConventionalMemory) |
(Entry->Attributes & EFI_CACHE_ATTRIBUTE_MASK);
- DEBUG ((DEBUG_INFO,
+ DEBUG ((
+ DEBUG_INFO,
"Untested GCD memory space region: - 0x%016lx - 0x%016lx (0x%016lx)\n",
- Entry->BaseAddress, Entry->EndAddress - Entry->BaseAddress + 1,
- Attributes));
+ Entry->BaseAddress,
+ Entry->EndAddress - Entry->BaseAddress + 1,
+ Attributes
+ ));
- ASSERT(gCpu != NULL);
- gCpu->SetMemoryAttributes (gCpu, Entry->BaseAddress,
- Entry->EndAddress - Entry->BaseAddress + 1, Attributes);
+ ASSERT (gCpu != NULL);
+ gCpu->SetMemoryAttributes (
+ gCpu,
+ Entry->BaseAddress,
+ Entry->EndAddress - Entry->BaseAddress + 1,
+ Attributes
+ );
}
Link = Link->ForwardLink;
}
+
CoreReleaseGcdMemoryLock ();
}
}
-
/**
A notification for CPU_ARCH protocol.
@@ -951,16 +978,16 @@ InitializeDxeNxMemoryProtectionPolicy ( VOID
EFIAPI
MemoryProtectionCpuArchProtocolNotify (
- IN EFI_EVENT Event,
- IN VOID *Context
+ IN EFI_EVENT Event,
+ IN VOID *Context
)
{
- EFI_STATUS Status;
- EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;
- EFI_DEVICE_PATH_PROTOCOL *LoadedImageDevicePath;
- UINTN NoHandles;
- EFI_HANDLE *HandleBuffer;
- UINTN Index;
+ EFI_STATUS Status;
+ EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;
+ EFI_DEVICE_PATH_PROTOCOL *LoadedImageDevicePath;
+ UINTN NoHandles;
+ EFI_HANDLE *HandleBuffer;
+ UINTN Index;
DEBUG ((DEBUG_INFO, "MemoryProtectionCpuArchProtocolNotify:\n"));
Status = CoreLocateProtocol (&gEfiCpuArchProtocolGuid, NULL, (VOID **)&gCpu);
@@ -1001,20 +1028,22 @@ MemoryProtectionCpuArchProtocolNotify ( &gEfiLoadedImageProtocolGuid,
(VOID **)&LoadedImage
);
- if (EFI_ERROR(Status)) {
+ if (EFI_ERROR (Status)) {
continue;
}
+
Status = gBS->HandleProtocol (
HandleBuffer[Index],
&gEfiLoadedImageDevicePathProtocolGuid,
(VOID **)&LoadedImageDevicePath
);
- if (EFI_ERROR(Status)) {
+ if (EFI_ERROR (Status)) {
LoadedImageDevicePath = NULL;
}
ProtectUefiImage (LoadedImage, LoadedImageDevicePath);
}
+
FreePool (HandleBuffer);
Done:
@@ -1029,8 +1058,8 @@ MemoryProtectionExitBootServicesCallback ( VOID
)
{
- EFI_RUNTIME_IMAGE_ENTRY *RuntimeImage;
- LIST_ENTRY *Link;
+ EFI_RUNTIME_IMAGE_ENTRY *RuntimeImage;
+ LIST_ENTRY *Link;
//
// We need remove the RT protection, because RT relocation need write code segment
@@ -1044,7 +1073,7 @@ MemoryProtectionExitBootServicesCallback ( if (mImageProtectionPolicy != 0) {
for (Link = gRuntime->ImageHead.ForwardLink; Link != &gRuntime->ImageHead; Link = Link->ForwardLink) {
RuntimeImage = BASE_CR (Link, EFI_RUNTIME_IMAGE_ENTRY, Link);
- SetUefiImageMemoryAttributes ((UINT64)(UINTN)RuntimeImage->ImageBase, ALIGN_VALUE(RuntimeImage->ImageSize, EFI_PAGE_SIZE), 0);
+ SetUefiImageMemoryAttributes ((UINT64)(UINTN)RuntimeImage->ImageBase, ALIGN_VALUE (RuntimeImage->ImageSize, EFI_PAGE_SIZE), 0);
}
}
}
@@ -1060,12 +1089,12 @@ MemoryProtectionExitBootServicesCallback ( VOID
EFIAPI
DisableNullDetectionAtTheEndOfDxe (
- EFI_EVENT Event,
- VOID *Context
+ EFI_EVENT Event,
+ VOID *Context
)
{
- EFI_STATUS Status;
- EFI_GCD_MEMORY_SPACE_DESCRIPTOR Desc;
+ EFI_STATUS Status;
+ EFI_GCD_MEMORY_SPACE_DESCRIPTOR Desc;
DEBUG ((DEBUG_INFO, "DisableNullDetectionAtTheEndOfDxe(): start\r\n"));
//
@@ -1076,18 +1105,18 @@ DisableNullDetectionAtTheEndOfDxe ( if ((Desc.Capabilities & EFI_MEMORY_RP) == 0) {
Status = CoreSetMemorySpaceCapabilities (
- 0,
- EFI_PAGE_SIZE,
- Desc.Capabilities | EFI_MEMORY_RP
- );
+ 0,
+ EFI_PAGE_SIZE,
+ Desc.Capabilities | EFI_MEMORY_RP
+ );
ASSERT_EFI_ERROR (Status);
}
Status = CoreSetMemorySpaceAttributes (
- 0,
- EFI_PAGE_SIZE,
- Desc.Attributes & ~EFI_MEMORY_RP
- );
+ 0,
+ EFI_PAGE_SIZE,
+ Desc.Attributes & ~EFI_MEMORY_RP
+ );
ASSERT_EFI_ERROR (Status);
//
@@ -1115,7 +1144,7 @@ CoreInitializeMemoryProtection ( EFI_EVENT EndOfDxeEvent;
VOID *Registration;
- mImageProtectionPolicy = PcdGet32(PcdImageProtectionPolicy);
+ mImageProtectionPolicy = PcdGet32 (PcdImageProtectionPolicy);
InitializeListHead (&mProtectedImageRecordList);
@@ -1128,8 +1157,10 @@ CoreInitializeMemoryProtection ( ASSERT ((GetPermissionAttributeForMemoryType (EfiBootServicesCode) & EFI_MEMORY_XP) == 0);
ASSERT ((GetPermissionAttributeForMemoryType (EfiRuntimeServicesCode) & EFI_MEMORY_XP) == 0);
ASSERT ((GetPermissionAttributeForMemoryType (EfiLoaderCode) & EFI_MEMORY_XP) == 0);
- ASSERT (GetPermissionAttributeForMemoryType (EfiBootServicesData) ==
- GetPermissionAttributeForMemoryType (EfiConventionalMemory));
+ ASSERT (
+ GetPermissionAttributeForMemoryType (EfiBootServicesData) ==
+ GetPermissionAttributeForMemoryType (EfiConventionalMemory)
+ );
Status = CoreCreateEvent (
EVT_NOTIFY_SIGNAL,
@@ -1138,7 +1169,7 @@ CoreInitializeMemoryProtection ( NULL,
&Event
);
- ASSERT_EFI_ERROR(Status);
+ ASSERT_EFI_ERROR (Status);
//
// Register for protocol notifactions on this event
@@ -1148,25 +1179,26 @@ CoreInitializeMemoryProtection ( Event,
&Registration
);
- ASSERT_EFI_ERROR(Status);
+ ASSERT_EFI_ERROR (Status);
//
// Register a callback to disable NULL pointer detection at EndOfDxe
//
if ((PcdGet8 (PcdNullPointerDetectionPropertyMask) & (BIT0|BIT7))
- == (BIT0|BIT7)) {
+ == (BIT0|BIT7))
+ {
Status = CoreCreateEventEx (
- EVT_NOTIFY_SIGNAL,
- TPL_NOTIFY,
- DisableNullDetectionAtTheEndOfDxe,
- NULL,
- &gEfiEndOfDxeEventGroupGuid,
- &EndOfDxeEvent
- );
+ EVT_NOTIFY_SIGNAL,
+ TPL_NOTIFY,
+ DisableNullDetectionAtTheEndOfDxe,
+ NULL,
+ &gEfiEndOfDxeEventGroupGuid,
+ &EndOfDxeEvent
+ );
ASSERT_EFI_ERROR (Status);
}
- return ;
+ return;
}
/**
@@ -1178,12 +1210,13 @@ IsInSmm ( VOID
)
{
- BOOLEAN InSmm;
+ BOOLEAN InSmm;
InSmm = FALSE;
if (gSmmBase2 != NULL) {
gSmmBase2->InSmm (gSmmBase2, &InSmm);
}
+
return InSmm;
}
@@ -1245,7 +1278,7 @@ ApplyMemoryProtectionPolicy ( // if any.
//
if (IsHeapGuardEnabled (GUARD_HEAP_TYPE_PAGE|GUARD_HEAP_TYPE_POOL)) {
- if (IsGuardPage (Memory)) {
+ if (IsGuardPage (Memory)) {
Memory += EFI_PAGE_SIZE;
Length -= EFI_PAGE_SIZE;
if (Length == 0) {
@@ -1253,7 +1286,7 @@ ApplyMemoryProtectionPolicy ( }
}
- if (IsGuardPage (Memory + Length - EFI_PAGE_SIZE)) {
+ if (IsGuardPage (Memory + Length - EFI_PAGE_SIZE)) {
Length -= EFI_PAGE_SIZE;
if (Length == 0) {
return EFI_SUCCESS;
diff --git a/MdeModulePkg/Core/Dxe/Misc/SetWatchdogTimer.c b/MdeModulePkg/Core/Dxe/Misc/SetWatchdogTimer.c index a9bf1284f5..c3cabc0d36 100644 --- a/MdeModulePkg/Core/Dxe/Misc/SetWatchdogTimer.c +++ b/MdeModulePkg/Core/Dxe/Misc/SetWatchdogTimer.c @@ -8,7 +8,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include "DxeMain.h"
-#define WATCHDOG_TIMER_CALIBRATE_PER_SECOND 10000000
+#define WATCHDOG_TIMER_CALIBRATE_PER_SECOND 10000000
/**
Sets the system's watchdog timer.
@@ -35,10 +35,10 @@ SPDX-License-Identifier: BSD-2-Clause-Patent EFI_STATUS
EFIAPI
CoreSetWatchdogTimer (
- IN UINTN Timeout,
- IN UINT64 WatchdogCode,
- IN UINTN DataSize,
- IN CHAR16 *WatchdogData OPTIONAL
+ IN UINTN Timeout,
+ IN UINT64 WatchdogCode,
+ IN UINTN DataSize,
+ IN CHAR16 *WatchdogData OPTIONAL
)
{
EFI_STATUS Status;
diff --git a/MdeModulePkg/Core/Dxe/Misc/Stall.c b/MdeModulePkg/Core/Dxe/Misc/Stall.c index 6ecc708ac3..35e045d41a 100644 --- a/MdeModulePkg/Core/Dxe/Misc/Stall.c +++ b/MdeModulePkg/Core/Dxe/Misc/Stall.c @@ -30,6 +30,7 @@ CoreInternalWaitForTick ( gMetronome->WaitForTick (gMetronome, 0xffffffff);
Counter -= 0xffffffff;
}
+
gMetronome->WaitForTick (gMetronome, (UINT32)Counter);
}
@@ -46,7 +47,7 @@ CoreInternalWaitForTick ( EFI_STATUS
EFIAPI
CoreStall (
- IN UINTN Microseconds
+ IN UINTN Microseconds
)
{
UINT64 Counter;
@@ -61,7 +62,7 @@ CoreStall ( // Counter = Microseconds * 10 / gMetronome->TickPeriod
// 0x1999999999999999 = (2^64 - 1) / 10
//
- if ((UINT64) Microseconds > 0x1999999999999999ULL) {
+ if ((UINT64)Microseconds > 0x1999999999999999ULL) {
//
// Microseconds is too large to multiple by 10 first. Perform the divide
// operation first and loop 10 times to avoid 64-bit math overflow.
@@ -100,6 +101,7 @@ CoreStall ( //
Counter++;
}
+
CoreInternalWaitForTick (Counter);
}
diff --git a/MdeModulePkg/Core/Dxe/SectionExtraction/CoreSectionExtraction.c b/MdeModulePkg/Core/Dxe/SectionExtraction/CoreSectionExtraction.c index 908617d1ca..b8d4184b50 100644 --- a/MdeModulePkg/Core/Dxe/SectionExtraction/CoreSectionExtraction.c +++ b/MdeModulePkg/Core/Dxe/SectionExtraction/CoreSectionExtraction.c @@ -42,15 +42,15 @@ SPDX-License-Identifier: BSD-2-Clause-Patent CR (Node, CORE_SECTION_CHILD_NODE, Link, CORE_SECTION_CHILD_SIGNATURE)
typedef struct {
- UINT32 Signature;
- LIST_ENTRY Link;
- UINT32 Type;
- UINT32 Size;
+ UINT32 Signature;
+ LIST_ENTRY Link;
+ UINT32 Type;
+ UINT32 Size;
//
// StreamBase + OffsetInStream == pointer to section header in stream. The
// stream base is always known when walking the sections within.
//
- UINT32 OffsetInStream;
+ UINT32 OffsetInStream;
//
// Then EncapsulatedStreamHandle below is always 0 if the section is NOT an
// encapsulating section. Otherwise, it contains the stream handle
@@ -58,33 +58,33 @@ typedef struct { // encapsulating child is encountered, irrespective of whether the
// encapsulated stream is processed further.
//
- UINTN EncapsulatedStreamHandle;
- EFI_GUID *EncapsulationGuid;
+ UINTN EncapsulatedStreamHandle;
+ EFI_GUID *EncapsulationGuid;
//
// If the section REQUIRES an extraction protocol, register for RPN
// when the required GUIDed extraction protocol becomes available.
//
- EFI_EVENT Event;
+ EFI_EVENT Event;
} CORE_SECTION_CHILD_NODE;
-#define CORE_SECTION_STREAM_SIGNATURE SIGNATURE_32('S','X','S','S')
+#define CORE_SECTION_STREAM_SIGNATURE SIGNATURE_32('S','X','S','S')
#define STREAM_NODE_FROM_LINK(Node) \
CR (Node, CORE_SECTION_STREAM_NODE, Link, CORE_SECTION_STREAM_SIGNATURE)
typedef struct {
- UINT32 Signature;
- LIST_ENTRY Link;
- UINTN StreamHandle;
- UINT8 *StreamBuffer;
- UINTN StreamLength;
- LIST_ENTRY Children;
+ UINT32 Signature;
+ LIST_ENTRY Link;
+ UINTN StreamHandle;
+ UINT8 *StreamBuffer;
+ UINTN StreamLength;
+ LIST_ENTRY Children;
//
// Authentication status is from GUIDed encapsulations.
//
- UINT32 AuthenticationStatus;
+ UINT32 AuthenticationStatus;
} CORE_SECTION_STREAM_NODE;
-#define NULL_STREAM_HANDLE 0
+#define NULL_STREAM_HANDLE 0
typedef struct {
CORE_SECTION_CHILD_NODE *ChildNode;
@@ -92,7 +92,6 @@ typedef struct { VOID *Registration;
} RPN_EVENT_CONTEXT;
-
/**
The ExtractSection() function processes the input section and
allocates a buffer from the pool in which it returns the section
@@ -179,25 +178,24 @@ typedef struct { EFI_STATUS
EFIAPI
CustomGuidedSectionExtract (
- IN CONST EFI_GUIDED_SECTION_EXTRACTION_PROTOCOL *This,
- IN CONST VOID *InputSection,
- OUT VOID **OutputBuffer,
- OUT UINTN *OutputSize,
- OUT UINT32 *AuthenticationStatus
+ IN CONST EFI_GUIDED_SECTION_EXTRACTION_PROTOCOL *This,
+ IN CONST VOID *InputSection,
+ OUT VOID **OutputBuffer,
+ OUT UINTN *OutputSize,
+ OUT UINT32 *AuthenticationStatus
);
//
// Module globals
//
-LIST_ENTRY mStreamRoot = INITIALIZE_LIST_HEAD_VARIABLE (mStreamRoot);
+LIST_ENTRY mStreamRoot = INITIALIZE_LIST_HEAD_VARIABLE (mStreamRoot);
-EFI_HANDLE mSectionExtractionHandle = NULL;
+EFI_HANDLE mSectionExtractionHandle = NULL;
-EFI_GUIDED_SECTION_EXTRACTION_PROTOCOL mCustomGuidedSectionExtractionProtocol = {
+EFI_GUIDED_SECTION_EXTRACTION_PROTOCOL mCustomGuidedSectionExtractionProtocol = {
CustomGuidedSectionExtract
};
-
/**
Entry point of the section extraction code. Initializes an instance of the
section extraction interface and installs it on a new handle.
@@ -212,13 +210,13 @@ EFI_GUIDED_SECTION_EXTRACTION_PROTOCOL mCustomGuidedSectionExtractionProtocol = EFI_STATUS
EFIAPI
InitializeSectionExtraction (
- IN EFI_HANDLE ImageHandle,
- IN EFI_SYSTEM_TABLE *SystemTable
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
)
{
- EFI_STATUS Status;
- EFI_GUID *ExtractHandlerGuidTable;
- UINTN ExtractHandlerNumber;
+ EFI_STATUS Status;
+ EFI_GUID *ExtractHandlerGuidTable;
+ UINTN ExtractHandlerNumber;
//
// Get custom extract guided section method guid list
@@ -231,18 +229,17 @@ InitializeSectionExtraction ( //
while (ExtractHandlerNumber-- > 0) {
Status = CoreInstallProtocolInterface (
- &mSectionExtractionHandle,
- &ExtractHandlerGuidTable [ExtractHandlerNumber],
- EFI_NATIVE_INTERFACE,
- &mCustomGuidedSectionExtractionProtocol
- );
+ &mSectionExtractionHandle,
+ &ExtractHandlerGuidTable[ExtractHandlerNumber],
+ EFI_NATIVE_INTERFACE,
+ &mCustomGuidedSectionExtractionProtocol
+ );
ASSERT_EFI_ERROR (Status);
}
return Status;
}
-
/**
Check if a stream is valid.
@@ -254,16 +251,16 @@ InitializeSectionExtraction ( **/
BOOLEAN
IsValidSectionStream (
- IN VOID *SectionStream,
- IN UINTN SectionStreamLength
+ IN VOID *SectionStream,
+ IN UINTN SectionStreamLength
)
{
- UINTN TotalLength;
- UINTN SectionLength;
- EFI_COMMON_SECTION_HEADER *SectionHeader;
- EFI_COMMON_SECTION_HEADER *NextSectionHeader;
+ UINTN TotalLength;
+ UINTN SectionLength;
+ EFI_COMMON_SECTION_HEADER *SectionHeader;
+ EFI_COMMON_SECTION_HEADER *NextSectionHeader;
- TotalLength = 0;
+ TotalLength = 0;
SectionHeader = (EFI_COMMON_SECTION_HEADER *)SectionStream;
while (TotalLength < SectionStreamLength) {
@@ -272,6 +269,7 @@ IsValidSectionStream ( } else {
SectionLength = SECTION_SIZE (SectionHeader);
}
+
TotalLength += SectionLength;
if (TotalLength == SectionStreamLength) {
@@ -281,21 +279,20 @@ IsValidSectionStream ( //
// Move to the next byte following the section...
//
- SectionHeader = (EFI_COMMON_SECTION_HEADER *) ((UINT8 *) SectionHeader + SectionLength);
+ SectionHeader = (EFI_COMMON_SECTION_HEADER *)((UINT8 *)SectionHeader + SectionLength);
//
// Figure out where the next section begins
//
- NextSectionHeader = ALIGN_POINTER(SectionHeader, 4);
- TotalLength += (UINTN) NextSectionHeader - (UINTN) SectionHeader;
- SectionHeader = NextSectionHeader;
+ NextSectionHeader = ALIGN_POINTER (SectionHeader, 4);
+ TotalLength += (UINTN)NextSectionHeader - (UINTN)SectionHeader;
+ SectionHeader = NextSectionHeader;
}
ASSERT (FALSE);
return FALSE;
}
-
/**
Worker function. Constructor for section streams.
@@ -331,15 +328,15 @@ IsValidSectionStream ( **/
EFI_STATUS
OpenSectionStreamEx (
- IN UINTN SectionStreamLength,
- IN VOID *SectionStream,
- IN BOOLEAN AllocateBuffer,
- IN UINT32 AuthenticationStatus,
- OUT UINTN *SectionStreamHandle
+ IN UINTN SectionStreamLength,
+ IN VOID *SectionStream,
+ IN BOOLEAN AllocateBuffer,
+ IN UINT32 AuthenticationStatus,
+ OUT UINTN *SectionStreamHandle
)
{
- CORE_SECTION_STREAM_NODE *NewStream;
- EFI_TPL OldTpl;
+ CORE_SECTION_STREAM_NODE *NewStream;
+ EFI_TPL OldTpl;
//
// Allocate a new stream
@@ -360,6 +357,7 @@ OpenSectionStreamEx ( CoreFreePool (NewStream);
return EFI_OUT_OF_RESOURCES;
}
+
//
// Copy in stream data
//
@@ -382,8 +380,8 @@ OpenSectionStreamEx ( //
// Initialize the rest of the section stream
//
- NewStream->Signature = CORE_SECTION_STREAM_SIGNATURE;
- NewStream->StreamHandle = (UINTN) NewStream;
+ NewStream->Signature = CORE_SECTION_STREAM_SIGNATURE;
+ NewStream->StreamHandle = (UINTN)NewStream;
NewStream->StreamLength = SectionStreamLength;
InitializeListHead (&NewStream->Children);
NewStream->AuthenticationStatus = AuthenticationStatus;
@@ -400,7 +398,6 @@ OpenSectionStreamEx ( return EFI_SUCCESS;
}
-
/**
SEP member function. This function creates and returns a new section stream
handle to represent the new section stream.
@@ -419,9 +416,9 @@ OpenSectionStreamEx ( EFI_STATUS
EFIAPI
OpenSectionStream (
- IN UINTN SectionStreamLength,
- IN VOID *SectionStream,
- OUT UINTN *SectionStreamHandle
+ IN UINTN SectionStreamLength,
+ IN VOID *SectionStream,
+ OUT UINTN *SectionStreamHandle
)
{
//
@@ -440,8 +437,6 @@ OpenSectionStream ( );
}
-
-
/**
Worker function. Determine if the input stream:child matches the input type.
@@ -459,26 +454,29 @@ OpenSectionStream ( **/
BOOLEAN
ChildIsType (
- IN CORE_SECTION_STREAM_NODE *Stream,
- IN CORE_SECTION_CHILD_NODE *Child,
- IN EFI_SECTION_TYPE SearchType,
- IN EFI_GUID *SectionDefinitionGuid
+ IN CORE_SECTION_STREAM_NODE *Stream,
+ IN CORE_SECTION_CHILD_NODE *Child,
+ IN EFI_SECTION_TYPE SearchType,
+ IN EFI_GUID *SectionDefinitionGuid
)
{
- EFI_GUID_DEFINED_SECTION *GuidedSection;
+ EFI_GUID_DEFINED_SECTION *GuidedSection;
if (SearchType == EFI_SECTION_ALL) {
return TRUE;
}
+
if (Child->Type != SearchType) {
return FALSE;
}
+
if ((SearchType != EFI_SECTION_GUID_DEFINED) || (SectionDefinitionGuid == NULL)) {
return TRUE;
}
- GuidedSection = (EFI_GUID_DEFINED_SECTION * )(Stream->StreamBuffer + Child->OffsetInStream);
+
+ GuidedSection = (EFI_GUID_DEFINED_SECTION *)(Stream->StreamBuffer + Child->OffsetInStream);
if (IS_SECTION2 (GuidedSection)) {
- return CompareGuid (&(((EFI_GUID_DEFINED_SECTION2 *) GuidedSection)->SectionDefinitionGuid), SectionDefinitionGuid);
+ return CompareGuid (&(((EFI_GUID_DEFINED_SECTION2 *)GuidedSection)->SectionDefinitionGuid), SectionDefinitionGuid);
} else {
return CompareGuid (&GuidedSection->SectionDefinitionGuid, SectionDefinitionGuid);
}
@@ -499,33 +497,34 @@ ChildIsType ( **/
BOOLEAN
VerifyGuidedSectionGuid (
- IN EFI_GUID *GuidedSectionGuid,
- OUT EFI_GUIDED_SECTION_EXTRACTION_PROTOCOL **GuidedSectionExtraction
+ IN EFI_GUID *GuidedSectionGuid,
+ OUT EFI_GUIDED_SECTION_EXTRACTION_PROTOCOL **GuidedSectionExtraction
)
{
- EFI_GUID *GuidRecorded;
- VOID *Interface;
- EFI_STATUS Status;
+ EFI_GUID *GuidRecorded;
+ VOID *Interface;
+ EFI_STATUS Status;
Interface = NULL;
//
// Check if there is the Guided Section GUID configuration table recorded the GUID itself.
//
- Status = EfiGetSystemConfigurationTable (GuidedSectionGuid, (VOID **) &GuidRecorded);
+ Status = EfiGetSystemConfigurationTable (GuidedSectionGuid, (VOID **)&GuidRecorded);
if (Status == EFI_SUCCESS) {
if (CompareGuid (GuidRecorded, GuidedSectionGuid)) {
//
// Found the recorded GuidedSectionGuid.
//
- Status = CoreLocateProtocol (GuidedSectionGuid, NULL, (VOID **) &Interface);
- if (!EFI_ERROR (Status) && Interface != NULL) {
+ Status = CoreLocateProtocol (GuidedSectionGuid, NULL, (VOID **)&Interface);
+ if (!EFI_ERROR (Status) && (Interface != NULL)) {
//
// Found the supported Guided Section Extraction Porotocol for the Guided Section.
//
- *GuidedSectionExtraction = (EFI_GUIDED_SECTION_EXTRACTION_PROTOCOL *) Interface;
+ *GuidedSectionExtraction = (EFI_GUIDED_SECTION_EXTRACTION_PROTOCOL *)Interface;
return TRUE;
}
+
return FALSE;
}
}
@@ -544,8 +543,8 @@ VerifyGuidedSectionGuid ( VOID
EFIAPI
NotifyGuidedExtraction (
- IN EFI_EVENT Event,
- IN VOID *RpnContext
+ IN EFI_EVENT Event,
+ IN VOID *RpnContext
)
{
EFI_STATUS Status;
@@ -558,7 +557,7 @@ NotifyGuidedExtraction ( Context = RpnContext;
- GuidedHeader = (EFI_GUID_DEFINED_SECTION *) (Context->ParentStream->StreamBuffer + Context->ChildNode->OffsetInStream);
+ GuidedHeader = (EFI_GUID_DEFINED_SECTION *)(Context->ParentStream->StreamBuffer + Context->ChildNode->OffsetInStream);
ASSERT (GuidedHeader->CommonHeader.Type == EFI_SECTION_GUID_DEFINED);
if (!VerifyGuidedSectionGuid (Context->ChildNode->EncapsulationGuid, &GuidedExtraction)) {
@@ -617,11 +616,11 @@ NotifyGuidedExtraction ( **/
VOID
CreateGuidedExtractionRpnEvent (
- IN CORE_SECTION_STREAM_NODE *ParentStream,
- IN CORE_SECTION_CHILD_NODE *ChildNode
+ IN CORE_SECTION_STREAM_NODE *ParentStream,
+ IN CORE_SECTION_CHILD_NODE *ChildNode
)
{
- RPN_EVENT_CONTEXT *Context;
+ RPN_EVENT_CONTEXT *Context;
//
// Allocate new event structure and context
@@ -629,7 +628,7 @@ CreateGuidedExtractionRpnEvent ( Context = AllocatePool (sizeof (RPN_EVENT_CONTEXT));
ASSERT (Context != NULL);
- Context->ChildNode = ChildNode;
+ Context->ChildNode = ChildNode;
Context->ParentStream = ParentStream;
Context->ChildNode->Event = EfiCreateProtocolNotifyEvent (
@@ -664,37 +663,37 @@ CreateGuidedExtractionRpnEvent ( **/
EFI_STATUS
CreateChildNode (
- IN CORE_SECTION_STREAM_NODE *Stream,
- IN UINT32 ChildOffset,
- OUT CORE_SECTION_CHILD_NODE **ChildNode
+ IN CORE_SECTION_STREAM_NODE *Stream,
+ IN UINT32 ChildOffset,
+ OUT CORE_SECTION_CHILD_NODE **ChildNode
)
{
- EFI_STATUS Status;
- EFI_COMMON_SECTION_HEADER *SectionHeader;
- EFI_COMPRESSION_SECTION *CompressionHeader;
- EFI_GUID_DEFINED_SECTION *GuidedHeader;
- EFI_DECOMPRESS_PROTOCOL *Decompress;
- EFI_GUIDED_SECTION_EXTRACTION_PROTOCOL *GuidedExtraction;
- VOID *NewStreamBuffer;
- VOID *ScratchBuffer;
- UINT32 ScratchSize;
- UINTN NewStreamBufferSize;
- UINT32 AuthenticationStatus;
- VOID *CompressionSource;
- UINT32 CompressionSourceSize;
- UINT32 UncompressedLength;
- UINT8 CompressionType;
- UINT16 GuidedSectionAttributes;
-
- CORE_SECTION_CHILD_NODE *Node;
-
- SectionHeader = (EFI_COMMON_SECTION_HEADER *) (Stream->StreamBuffer + ChildOffset);
+ EFI_STATUS Status;
+ EFI_COMMON_SECTION_HEADER *SectionHeader;
+ EFI_COMPRESSION_SECTION *CompressionHeader;
+ EFI_GUID_DEFINED_SECTION *GuidedHeader;
+ EFI_DECOMPRESS_PROTOCOL *Decompress;
+ EFI_GUIDED_SECTION_EXTRACTION_PROTOCOL *GuidedExtraction;
+ VOID *NewStreamBuffer;
+ VOID *ScratchBuffer;
+ UINT32 ScratchSize;
+ UINTN NewStreamBufferSize;
+ UINT32 AuthenticationStatus;
+ VOID *CompressionSource;
+ UINT32 CompressionSourceSize;
+ UINT32 UncompressedLength;
+ UINT8 CompressionType;
+ UINT16 GuidedSectionAttributes;
+
+ CORE_SECTION_CHILD_NODE *Node;
+
+ SectionHeader = (EFI_COMMON_SECTION_HEADER *)(Stream->StreamBuffer + ChildOffset);
//
// Allocate a new node
//
*ChildNode = AllocateZeroPool (sizeof (CORE_SECTION_CHILD_NODE));
- Node = *ChildNode;
+ Node = *ChildNode;
if (Node == NULL) {
return EFI_OUT_OF_RESOURCES;
}
@@ -703,15 +702,16 @@ CreateChildNode ( // Now initialize it
//
Node->Signature = CORE_SECTION_CHILD_SIGNATURE;
- Node->Type = SectionHeader->Type;
+ Node->Type = SectionHeader->Type;
if (IS_SECTION2 (SectionHeader)) {
Node->Size = SECTION2_SIZE (SectionHeader);
} else {
Node->Size = SECTION_SIZE (SectionHeader);
}
- Node->OffsetInStream = ChildOffset;
+
+ Node->OffsetInStream = ChildOffset;
Node->EncapsulatedStreamHandle = NULL_STREAM_HANDLE;
- Node->EncapsulationGuid = NULL;
+ Node->EncapsulationGuid = NULL;
//
// If it's an encapsulating section, then create the new section stream also
@@ -726,18 +726,18 @@ CreateChildNode ( return EFI_NOT_FOUND;
}
- CompressionHeader = (EFI_COMPRESSION_SECTION *) SectionHeader;
+ CompressionHeader = (EFI_COMPRESSION_SECTION *)SectionHeader;
if (IS_SECTION2 (CompressionHeader)) {
- CompressionSource = (VOID *) ((UINT8 *) CompressionHeader + sizeof (EFI_COMPRESSION_SECTION2));
- CompressionSourceSize = (UINT32) (SECTION2_SIZE (CompressionHeader) - sizeof (EFI_COMPRESSION_SECTION2));
- UncompressedLength = ((EFI_COMPRESSION_SECTION2 *) CompressionHeader)->UncompressedLength;
- CompressionType = ((EFI_COMPRESSION_SECTION2 *) CompressionHeader)->CompressionType;
+ CompressionSource = (VOID *)((UINT8 *)CompressionHeader + sizeof (EFI_COMPRESSION_SECTION2));
+ CompressionSourceSize = (UINT32)(SECTION2_SIZE (CompressionHeader) - sizeof (EFI_COMPRESSION_SECTION2));
+ UncompressedLength = ((EFI_COMPRESSION_SECTION2 *)CompressionHeader)->UncompressedLength;
+ CompressionType = ((EFI_COMPRESSION_SECTION2 *)CompressionHeader)->CompressionType;
} else {
- CompressionSource = (VOID *) ((UINT8 *) CompressionHeader + sizeof (EFI_COMPRESSION_SECTION));
- CompressionSourceSize = (UINT32) (SECTION_SIZE (CompressionHeader) - sizeof (EFI_COMPRESSION_SECTION));
- UncompressedLength = CompressionHeader->UncompressedLength;
- CompressionType = CompressionHeader->CompressionType;
+ CompressionSource = (VOID *)((UINT8 *)CompressionHeader + sizeof (EFI_COMPRESSION_SECTION));
+ CompressionSourceSize = (UINT32)(SECTION_SIZE (CompressionHeader) - sizeof (EFI_COMPRESSION_SECTION));
+ UncompressedLength = CompressionHeader->UncompressedLength;
+ CompressionType = CompressionHeader->CompressionType;
}
//
@@ -745,7 +745,7 @@ CreateChildNode ( //
if (UncompressedLength > 0) {
NewStreamBufferSize = UncompressedLength;
- NewStreamBuffer = AllocatePool (NewStreamBufferSize);
+ NewStreamBuffer = AllocatePool (NewStreamBufferSize);
if (NewStreamBuffer == NULL) {
CoreFreePool (Node);
return EFI_OUT_OF_RESOURCES;
@@ -781,6 +781,7 @@ CreateChildNode ( if (!EFI_ERROR (Status)) {
Status = EFI_BAD_BUFFER_SIZE;
}
+
return Status;
}
@@ -808,7 +809,7 @@ CreateChildNode ( }
}
} else {
- NewStreamBuffer = NULL;
+ NewStreamBuffer = NULL;
NewStreamBufferSize = 0;
}
@@ -824,17 +825,19 @@ CreateChildNode ( CoreFreePool (NewStreamBuffer);
return Status;
}
+
break;
case EFI_SECTION_GUID_DEFINED:
- GuidedHeader = (EFI_GUID_DEFINED_SECTION *) SectionHeader;
+ GuidedHeader = (EFI_GUID_DEFINED_SECTION *)SectionHeader;
if (IS_SECTION2 (GuidedHeader)) {
- Node->EncapsulationGuid = &(((EFI_GUID_DEFINED_SECTION2 *) GuidedHeader)->SectionDefinitionGuid);
- GuidedSectionAttributes = ((EFI_GUID_DEFINED_SECTION2 *) GuidedHeader)->Attributes;
+ Node->EncapsulationGuid = &(((EFI_GUID_DEFINED_SECTION2 *)GuidedHeader)->SectionDefinitionGuid);
+ GuidedSectionAttributes = ((EFI_GUID_DEFINED_SECTION2 *)GuidedHeader)->Attributes;
} else {
Node->EncapsulationGuid = &GuidedHeader->SectionDefinitionGuid;
GuidedSectionAttributes = GuidedHeader->Attributes;
}
+
if (VerifyGuidedSectionGuid (Node->EncapsulationGuid, &GuidedExtraction)) {
//
// NewStreamBuffer is always allocated by ExtractSection... No caller
@@ -903,21 +906,22 @@ CreateChildNode ( if (IS_SECTION2 (GuidedHeader)) {
Status = OpenSectionStreamEx (
- SECTION2_SIZE (GuidedHeader) - ((EFI_GUID_DEFINED_SECTION2 *) GuidedHeader)->DataOffset,
- (UINT8 *) GuidedHeader + ((EFI_GUID_DEFINED_SECTION2 *) GuidedHeader)->DataOffset,
+ SECTION2_SIZE (GuidedHeader) - ((EFI_GUID_DEFINED_SECTION2 *)GuidedHeader)->DataOffset,
+ (UINT8 *)GuidedHeader + ((EFI_GUID_DEFINED_SECTION2 *)GuidedHeader)->DataOffset,
TRUE,
AuthenticationStatus,
&Node->EncapsulatedStreamHandle
);
} else {
Status = OpenSectionStreamEx (
- SECTION_SIZE (GuidedHeader) - ((EFI_GUID_DEFINED_SECTION *) GuidedHeader)->DataOffset,
- (UINT8 *) GuidedHeader + ((EFI_GUID_DEFINED_SECTION *) GuidedHeader)->DataOffset,
+ SECTION_SIZE (GuidedHeader) - ((EFI_GUID_DEFINED_SECTION *)GuidedHeader)->DataOffset,
+ (UINT8 *)GuidedHeader + ((EFI_GUID_DEFINED_SECTION *)GuidedHeader)->DataOffset,
TRUE,
AuthenticationStatus,
&Node->EncapsulatedStreamHandle
);
}
+
if (EFI_ERROR (Status)) {
CoreFreePool (Node);
return Status;
@@ -943,7 +947,6 @@ CreateChildNode ( return EFI_SUCCESS;
}
-
/**
Worker function Recursively searches / builds section stream database
looking for requested section.
@@ -978,22 +981,22 @@ CreateChildNode ( **/
EFI_STATUS
FindChildNode (
- IN CORE_SECTION_STREAM_NODE *SourceStream,
- IN EFI_SECTION_TYPE SearchType,
- IN OUT UINTN *SectionInstance,
- IN EFI_GUID *SectionDefinitionGuid,
- IN UINT32 Depth,
- OUT CORE_SECTION_CHILD_NODE **FoundChild,
- OUT CORE_SECTION_STREAM_NODE **FoundStream,
- OUT UINT32 *AuthenticationStatus
+ IN CORE_SECTION_STREAM_NODE *SourceStream,
+ IN EFI_SECTION_TYPE SearchType,
+ IN OUT UINTN *SectionInstance,
+ IN EFI_GUID *SectionDefinitionGuid,
+ IN UINT32 Depth,
+ OUT CORE_SECTION_CHILD_NODE **FoundChild,
+ OUT CORE_SECTION_STREAM_NODE **FoundStream,
+ OUT UINT32 *AuthenticationStatus
)
{
- CORE_SECTION_CHILD_NODE *CurrentChildNode;
- CORE_SECTION_CHILD_NODE *RecursedChildNode;
- CORE_SECTION_STREAM_NODE *RecursedFoundStream;
- UINT32 NextChildOffset;
- EFI_STATUS ErrorStatus;
- EFI_STATUS Status;
+ CORE_SECTION_CHILD_NODE *CurrentChildNode;
+ CORE_SECTION_CHILD_NODE *RecursedChildNode;
+ CORE_SECTION_STREAM_NODE *RecursedFoundStream;
+ UINT32 NextChildOffset;
+ EFI_STATUS ErrorStatus;
+ EFI_STATUS Status;
ASSERT (*SectionInstance > 0);
@@ -1002,14 +1005,15 @@ FindChildNode ( }
CurrentChildNode = NULL;
- ErrorStatus = EFI_NOT_FOUND;
+ ErrorStatus = EFI_NOT_FOUND;
if (SourceStream->StreamLength == 0) {
return EFI_NOT_FOUND;
}
if (IsListEmpty (&SourceStream->Children) &&
- SourceStream->StreamLength >= sizeof (EFI_COMMON_SECTION_HEADER)) {
+ (SourceStream->StreamLength >= sizeof (EFI_COMMON_SECTION_HEADER)))
+ {
//
// This occurs when a section stream exists, but no child sections
// have been parsed out yet. Therefore, extract the first child and add it
@@ -1030,9 +1034,9 @@ FindChildNode ( // adding children until either the requested section is found, or we run
// out of data
//
- CurrentChildNode = CHILD_SECTION_NODE_FROM_LINK (GetFirstNode(&SourceStream->Children));
+ CurrentChildNode = CHILD_SECTION_NODE_FROM_LINK (GetFirstNode (&SourceStream->Children));
- for (;;) {
+ for ( ; ;) {
ASSERT (CurrentChildNode != NULL);
if (ChildIsType (SourceStream, CurrentChildNode, SearchType, SectionDefinitionGuid)) {
//
@@ -1043,8 +1047,8 @@ FindChildNode ( //
// Got it!
//
- *FoundChild = CurrentChildNode;
- *FoundStream = SourceStream;
+ *FoundChild = CurrentChildNode;
+ *FoundStream = SourceStream;
*AuthenticationStatus = SourceStream->AuthenticationStatus;
return EFI_SUCCESS;
}
@@ -1060,22 +1064,22 @@ FindChildNode ( // If the current node is an encapsulating node, recurse into it...
//
Status = FindChildNode (
- (CORE_SECTION_STREAM_NODE *)CurrentChildNode->EncapsulatedStreamHandle,
- SearchType,
- SectionInstance,
- SectionDefinitionGuid,
- Depth + 1,
- &RecursedChildNode,
- &RecursedFoundStream,
- AuthenticationStatus
- );
+ (CORE_SECTION_STREAM_NODE *)CurrentChildNode->EncapsulatedStreamHandle,
+ SearchType,
+ SectionInstance,
+ SectionDefinitionGuid,
+ Depth + 1,
+ &RecursedChildNode,
+ &RecursedFoundStream,
+ AuthenticationStatus
+ );
if (*SectionInstance == 0) {
//
// The recursive FindChildNode() call decreased (*SectionInstance) to
// zero.
//
ASSERT_EFI_ERROR (Status);
- *FoundChild = RecursedChildNode;
+ *FoundChild = RecursedChildNode;
*FoundStream = RecursedFoundStream;
return EFI_SUCCESS;
} else {
@@ -1087,6 +1091,7 @@ FindChildNode ( //
return Status;
}
+
//
// Save the error code and continue to find the requested child node in
// the rest of the stream.
@@ -1120,7 +1125,7 @@ FindChildNode ( // Round up to 4 byte boundary
//
NextChildOffset += 3;
- NextChildOffset &= ~(UINTN) 3;
+ NextChildOffset &= ~(UINTN)3;
if (NextChildOffset <= SourceStream->StreamLength - sizeof (EFI_COMMON_SECTION_HEADER)) {
//
// There's an unparsed child remaining in the stream, so create a new child node
@@ -1137,7 +1142,6 @@ FindChildNode ( }
}
-
/**
Worker function. Search stream database for requested stream handle.
@@ -1152,15 +1156,15 @@ FindChildNode ( **/
EFI_STATUS
FindStreamNode (
- IN UINTN SearchHandle,
- OUT CORE_SECTION_STREAM_NODE **FoundStream
+ IN UINTN SearchHandle,
+ OUT CORE_SECTION_STREAM_NODE **FoundStream
)
{
- CORE_SECTION_STREAM_NODE *StreamNode;
+ CORE_SECTION_STREAM_NODE *StreamNode;
if (!IsListEmpty (&mStreamRoot)) {
StreamNode = STREAM_NODE_FROM_LINK (GetFirstNode (&mStreamRoot));
- for (;;) {
+ for ( ; ;) {
if (StreamNode->StreamHandle == SearchHandle) {
*FoundStream = StreamNode;
return EFI_SUCCESS;
@@ -1175,7 +1179,6 @@ FindStreamNode ( return EFI_NOT_FOUND;
}
-
/**
SEP member function. Retrieves requested section from section stream.
@@ -1237,32 +1240,31 @@ FindStreamNode ( EFI_STATUS
EFIAPI
GetSection (
- IN UINTN SectionStreamHandle,
- IN EFI_SECTION_TYPE *SectionType,
- IN EFI_GUID *SectionDefinitionGuid,
- IN UINTN SectionInstance,
- IN VOID **Buffer,
- IN OUT UINTN *BufferSize,
- OUT UINT32 *AuthenticationStatus,
- IN BOOLEAN IsFfs3Fv
+ IN UINTN SectionStreamHandle,
+ IN EFI_SECTION_TYPE *SectionType,
+ IN EFI_GUID *SectionDefinitionGuid,
+ IN UINTN SectionInstance,
+ IN VOID **Buffer,
+ IN OUT UINTN *BufferSize,
+ OUT UINT32 *AuthenticationStatus,
+ IN BOOLEAN IsFfs3Fv
)
{
- CORE_SECTION_STREAM_NODE *StreamNode;
- EFI_TPL OldTpl;
- EFI_STATUS Status;
- CORE_SECTION_CHILD_NODE *ChildNode;
- CORE_SECTION_STREAM_NODE *ChildStreamNode;
- UINTN CopySize;
- UINT32 ExtractedAuthenticationStatus;
- UINTN Instance;
- UINT8 *CopyBuffer;
- UINTN SectionSize;
- EFI_COMMON_SECTION_HEADER *Section;
-
+ CORE_SECTION_STREAM_NODE *StreamNode;
+ EFI_TPL OldTpl;
+ EFI_STATUS Status;
+ CORE_SECTION_CHILD_NODE *ChildNode;
+ CORE_SECTION_STREAM_NODE *ChildStreamNode;
+ UINTN CopySize;
+ UINT32 ExtractedAuthenticationStatus;
+ UINTN Instance;
+ UINT8 *CopyBuffer;
+ UINTN SectionSize;
+ EFI_COMMON_SECTION_HEADER *Section;
ChildStreamNode = NULL;
- OldTpl = CoreRaiseTpl (TPL_NOTIFY);
- Instance = SectionInstance + 1;
+ OldTpl = CoreRaiseTpl (TPL_NOTIFY);
+ Instance = SectionInstance + 1;
//
// Locate target stream
@@ -1280,8 +1282,8 @@ GetSection ( //
// SectionType == NULL means return the WHOLE section stream...
//
- CopySize = StreamNode->StreamLength;
- CopyBuffer = StreamNode->StreamBuffer;
+ CopySize = StreamNode->StreamLength;
+ CopyBuffer = StreamNode->StreamBuffer;
*AuthenticationStatus = StreamNode->AuthenticationStatus;
} else {
//
@@ -1299,17 +1301,21 @@ GetSection ( );
if (EFI_ERROR (Status)) {
if (Status == EFI_ABORTED) {
- DEBUG ((DEBUG_ERROR, "%a: recursion aborted due to nesting depth\n",
- __FUNCTION__));
+ DEBUG ((
+ DEBUG_ERROR,
+ "%a: recursion aborted due to nesting depth\n",
+ __FUNCTION__
+ ));
//
// Map "aborted" to "not found".
//
Status = EFI_NOT_FOUND;
}
+
goto GetSection_Done;
}
- Section = (EFI_COMMON_SECTION_HEADER *) (ChildStreamNode->StreamBuffer + ChildNode->OffsetInStream);
+ Section = (EFI_COMMON_SECTION_HEADER *)(ChildStreamNode->StreamBuffer + ChildNode->OffsetInStream);
if (IS_SECTION2 (Section)) {
ASSERT (SECTION2_SIZE (Section) > 0x00FFFFFF);
@@ -1318,12 +1324,14 @@ GetSection ( Status = EFI_NOT_FOUND;
goto GetSection_Done;
}
- CopySize = SECTION2_SIZE (Section) - sizeof (EFI_COMMON_SECTION_HEADER2);
- CopyBuffer = (UINT8 *) Section + sizeof (EFI_COMMON_SECTION_HEADER2);
+
+ CopySize = SECTION2_SIZE (Section) - sizeof (EFI_COMMON_SECTION_HEADER2);
+ CopyBuffer = (UINT8 *)Section + sizeof (EFI_COMMON_SECTION_HEADER2);
} else {
- CopySize = SECTION_SIZE (Section) - sizeof (EFI_COMMON_SECTION_HEADER);
- CopyBuffer = (UINT8 *) Section + sizeof (EFI_COMMON_SECTION_HEADER);
+ CopySize = SECTION_SIZE (Section) - sizeof (EFI_COMMON_SECTION_HEADER);
+ CopyBuffer = (UINT8 *)Section + sizeof (EFI_COMMON_SECTION_HEADER);
}
+
*AuthenticationStatus = ExtractedAuthenticationStatus;
}
@@ -1333,7 +1341,7 @@ GetSection ( // Caller allocated buffer. Fill to size and return required size...
//
if (*BufferSize < CopySize) {
- Status = EFI_WARN_BUFFER_TOO_SMALL;
+ Status = EFI_WARN_BUFFER_TOO_SMALL;
CopySize = *BufferSize;
}
} else {
@@ -1346,6 +1354,7 @@ GetSection ( goto GetSection_Done;
}
}
+
CopyMem (*Buffer, CopyBuffer, CopySize);
*BufferSize = SectionSize;
@@ -1355,7 +1364,6 @@ GetSection_Done: return Status;
}
-
/**
Worker function. Destructor for child nodes.
@@ -1364,7 +1372,7 @@ GetSection_Done: **/
VOID
FreeChildNode (
- IN CORE_SECTION_CHILD_NODE *ChildNode
+ IN CORE_SECTION_CHILD_NODE *ChildNode
)
{
ASSERT (ChildNode->Signature == CORE_SECTION_CHILD_SIGNATURE);
@@ -1391,7 +1399,6 @@ FreeChildNode ( CoreFreePool (ChildNode);
}
-
/**
SEP member function. Deletes an existing section stream
@@ -1408,15 +1415,15 @@ FreeChildNode ( EFI_STATUS
EFIAPI
CloseSectionStream (
- IN UINTN StreamHandleToClose,
- IN BOOLEAN FreeStreamBuffer
+ IN UINTN StreamHandleToClose,
+ IN BOOLEAN FreeStreamBuffer
)
{
- CORE_SECTION_STREAM_NODE *StreamNode;
- EFI_TPL OldTpl;
- EFI_STATUS Status;
- LIST_ENTRY *Link;
- CORE_SECTION_CHILD_NODE *ChildNode;
+ CORE_SECTION_STREAM_NODE *StreamNode;
+ EFI_TPL OldTpl;
+ EFI_STATUS Status;
+ LIST_ENTRY *Link;
+ CORE_SECTION_CHILD_NODE *ChildNode;
OldTpl = CoreRaiseTpl (TPL_NOTIFY);
@@ -1430,13 +1437,15 @@ CloseSectionStream ( //
RemoveEntryList (&StreamNode->Link);
while (!IsListEmpty (&StreamNode->Children)) {
- Link = GetFirstNode (&StreamNode->Children);
+ Link = GetFirstNode (&StreamNode->Children);
ChildNode = CHILD_SECTION_NODE_FROM_LINK (Link);
FreeChildNode (ChildNode);
}
+
if (FreeStreamBuffer) {
CoreFreePool (StreamNode->StreamBuffer);
}
+
CoreFreePool (StreamNode);
Status = EFI_SUCCESS;
} else {
@@ -1447,7 +1456,6 @@ CloseSectionStream ( return Status;
}
-
/**
The ExtractSection() function processes the input section and
allocates a buffer from the pool in which it returns the section
@@ -1534,19 +1542,19 @@ CloseSectionStream ( EFI_STATUS
EFIAPI
CustomGuidedSectionExtract (
- IN CONST EFI_GUIDED_SECTION_EXTRACTION_PROTOCOL *This,
- IN CONST VOID *InputSection,
- OUT VOID **OutputBuffer,
- OUT UINTN *OutputSize,
- OUT UINT32 *AuthenticationStatus
+ IN CONST EFI_GUIDED_SECTION_EXTRACTION_PROTOCOL *This,
+ IN CONST VOID *InputSection,
+ OUT VOID **OutputBuffer,
+ OUT UINTN *OutputSize,
+ OUT UINT32 *AuthenticationStatus
)
{
- EFI_STATUS Status;
- VOID *ScratchBuffer;
- VOID *AllocatedOutputBuffer;
- UINT32 OutputBufferSize;
- UINT32 ScratchBufferSize;
- UINT16 SectionAttribute;
+ EFI_STATUS Status;
+ VOID *ScratchBuffer;
+ VOID *AllocatedOutputBuffer;
+ UINT32 OutputBufferSize;
+ UINT32 ScratchBufferSize;
+ UINT16 SectionAttribute;
//
// Init local variable
@@ -1588,8 +1596,10 @@ CustomGuidedSectionExtract ( if (ScratchBuffer != NULL) {
FreePool (ScratchBuffer);
}
+
return EFI_OUT_OF_RESOURCES;
}
+
*OutputBuffer = AllocatedOutputBuffer;
}
@@ -1609,9 +1619,11 @@ CustomGuidedSectionExtract ( if (AllocatedOutputBuffer != NULL) {
CoreFreePool (AllocatedOutputBuffer);
}
+
if (ScratchBuffer != NULL) {
CoreFreePool (ScratchBuffer);
}
+
DEBUG ((DEBUG_ERROR, "Extract guided section Failed - %r\n", Status));
return Status;
}
@@ -1628,7 +1640,7 @@ CustomGuidedSectionExtract ( //
// Set real size of output buffer.
//
- *OutputSize = (UINTN) OutputBufferSize;
+ *OutputSize = (UINTN)OutputBufferSize;
//
// Free unused scratch buffer.
|