summaryrefslogtreecommitdiffstats
path: root/MdeModulePkg/Core/PiSmmCore
diff options
context:
space:
mode:
Diffstat (limited to 'MdeModulePkg/Core/PiSmmCore')
-rw-r--r--MdeModulePkg/Core/PiSmmCore/Dependency.c288
-rw-r--r--MdeModulePkg/Core/PiSmmCore/Dispatcher.c637
-rw-r--r--MdeModulePkg/Core/PiSmmCore/Handle.c58
-rw-r--r--MdeModulePkg/Core/PiSmmCore/HeapGuard.c602
-rw-r--r--MdeModulePkg/Core/PiSmmCore/HeapGuard.h66
-rw-r--r--MdeModulePkg/Core/PiSmmCore/InstallConfigurationTable.c5
-rw-r--r--MdeModulePkg/Core/PiSmmCore/Locate.c166
-rw-r--r--MdeModulePkg/Core/PiSmmCore/MemoryAttributesTable.c521
-rw-r--r--MdeModulePkg/Core/PiSmmCore/Notify.c42
-rw-r--r--MdeModulePkg/Core/PiSmmCore/Page.c236
-rw-r--r--MdeModulePkg/Core/PiSmmCore/PiSmmCore.c286
-rw-r--r--MdeModulePkg/Core/PiSmmCore/PiSmmCore.h398
-rw-r--r--MdeModulePkg/Core/PiSmmCore/PiSmmCorePrivateData.h28
-rw-r--r--MdeModulePkg/Core/PiSmmCore/PiSmmIpl.c465
-rw-r--r--MdeModulePkg/Core/PiSmmCore/Pool.c135
-rw-r--r--MdeModulePkg/Core/PiSmmCore/Smi.c150
-rw-r--r--MdeModulePkg/Core/PiSmmCore/SmiHandlerProfile.c605
-rw-r--r--MdeModulePkg/Core/PiSmmCore/SmramProfileRecord.c1141
18 files changed, 3062 insertions, 2767 deletions
diff --git a/MdeModulePkg/Core/PiSmmCore/Dependency.c b/MdeModulePkg/Core/PiSmmCore/Dependency.c
index 1167807b15..c070f4216b 100644
--- a/MdeModulePkg/Core/PiSmmCore/Dependency.c
+++ b/MdeModulePkg/Core/PiSmmCore/Dependency.c
@@ -46,8 +46,8 @@ GrowDepexStack (
VOID
)
{
- BOOLEAN *NewStack;
- UINTN Size;
+ BOOLEAN *NewStack;
+ UINTN Size;
Size = DEPEX_STACK_SIZE_INCREMENT;
if (mDepexEvaluationStack != NULL) {
@@ -166,7 +166,7 @@ PopBool (
**/
BOOLEAN
SmmIsSchedulable (
- IN EFI_SMM_DRIVER_ENTRY *DriverEntry
+ IN EFI_SMM_DRIVER_ENTRY *DriverEntry
)
{
EFI_STATUS Status;
@@ -176,7 +176,7 @@ SmmIsSchedulable (
EFI_GUID DriverGuid;
VOID *Interface;
- Operator = FALSE;
+ Operator = FALSE;
Operator2 = FALSE;
if (DriverEntry->After || DriverEntry->Before) {
@@ -205,7 +205,6 @@ SmmIsSchedulable (
//
mDepexEvaluationStackPointer = mDepexEvaluationStack;
-
Iterator = DriverEntry->Depex;
while (TRUE) {
@@ -222,148 +221,155 @@ SmmIsSchedulable (
// 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_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 = SmmLocateProtocol (&DriverGuid, NULL, &Interface);
- if (EFI_ERROR (Status)) {
+ 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_PUSH:
//
- // For SMM Driver, it may depend on uefi protocols
+ // Push operator is followed by a GUID. Test to see if the GUID protocol
+ // is installed and push the boolean result on the stack.
//
- Status = gBS->LocateProtocol (&DriverGuid, NULL, &Interface);
- }
+ CopyMem (&DriverGuid, Iterator + 1, sizeof (EFI_GUID));
+
+ Status = SmmLocateProtocol (&DriverGuid, NULL, &Interface);
+ if (EFI_ERROR (Status)) {
+ //
+ // For SMM Driver, it may depend on uefi protocols
+ //
+ Status = gBS->LocateProtocol (&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;
- if (EFI_ERROR (Status)) {
- DEBUG ((DEBUG_DISPATCH, " PUSH GUID(%g) = FALSE\n", &DriverGuid));
+ 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;
}
//
diff --git a/MdeModulePkg/Core/PiSmmCore/Dispatcher.c b/MdeModulePkg/Core/PiSmmCore/Dispatcher.c
index 1736edb8d0..f635565dd1 100644
--- a/MdeModulePkg/Core/PiSmmCore/Dispatcher.c
+++ b/MdeModulePkg/Core/PiSmmCore/Dispatcher.c
@@ -40,9 +40,9 @@
//
#define KNOWN_HANDLE_SIGNATURE SIGNATURE_32('k','n','o','w')
typedef struct {
- UINTN Signature;
- LIST_ENTRY Link; // mFvHandleList
- EFI_HANDLE Handle;
+ UINTN Signature;
+ LIST_ENTRY Link; // mFvHandleList
+ EFI_HANDLE Handle;
} KNOWN_HANDLE;
//
@@ -62,7 +62,7 @@ typedef struct {
**/
VOID
SmmInsertOnScheduledQueueWhileProcessingBeforeAndAfter (
- IN EFI_SMM_DRIVER_ENTRY *InsertedDriverEntry
+ IN EFI_SMM_DRIVER_ENTRY *InsertedDriverEntry
);
//
@@ -95,7 +95,7 @@ BOOLEAN gRequestDispatch = FALSE;
//
// List of file types supported by dispatcher
//
-EFI_FV_FILETYPE mSmmFileTypes[] = {
+EFI_FV_FILETYPE mSmmFileTypes[] = {
EFI_FV_FILETYPE_SMM,
EFI_FV_FILETYPE_COMBINED_SMM_DXE,
EFI_FV_FILETYPE_SMM_CORE,
@@ -106,8 +106,8 @@ EFI_FV_FILETYPE mSmmFileTypes[] = {
};
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;
@@ -115,15 +115,15 @@ FV_FILEPATH_DEVICE_PATH mFvDevicePath;
//
// DXE Architecture Protocols
//
-EFI_SECURITY_ARCH_PROTOCOL *mSecurity = NULL;
-EFI_SECURITY2_ARCH_PROTOCOL *mSecurity2 = NULL;
+EFI_SECURITY_ARCH_PROTOCOL *mSecurity = NULL;
+EFI_SECURITY2_ARCH_PROTOCOL *mSecurity2 = NULL;
//
// The global variable is defined for Loading modules at fixed address feature to track the SMM code
// memory range usage. It is a bit mapped array in which every bit indicates the corresponding
// memory page available or not.
//
-GLOBAL_REMOVE_IF_UNREFERENCED UINT64 *mSmmCodeMemoryRangeUsageBitMap=NULL;
+GLOBAL_REMOVE_IF_UNREFERENCED UINT64 *mSmmCodeMemoryRangeUsageBitMap = NULL;
/**
To check memory usage bit map array to figure out if the memory range in which the image will be loaded is available or not. If
@@ -138,64 +138,70 @@ GLOBAL_REMOVE_IF_UNREFERENCED UINT64 *mSmmCodeMemoryRangeUsage
**/
EFI_STATUS
CheckAndMarkFixLoadingMemoryUsageBitMap (
- IN EFI_PHYSICAL_ADDRESS ImageBase,
- IN UINTN ImageSize
+ IN EFI_PHYSICAL_ADDRESS ImageBase,
+ IN UINTN ImageSize
)
{
- UINT32 SmmCodePageNumber;
- UINT64 SmmCodeSize;
- EFI_PHYSICAL_ADDRESS SmmCodeBase;
- UINTN BaseOffsetPageNumber;
- UINTN TopOffsetPageNumber;
- UINTN Index;
- //
- // Build tool will calculate the smm code size and then patch the PcdLoadFixAddressSmmCodePageNumber
- //
- SmmCodePageNumber = PcdGet32(PcdLoadFixAddressSmmCodePageNumber);
- SmmCodeSize = EFI_PAGES_TO_SIZE (SmmCodePageNumber);
- SmmCodeBase = gLoadModuleAtFixAddressSmramBase;
-
- //
- // 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 (mSmmCodeMemoryRangeUsageBitMap == NULL) {
- mSmmCodeMemoryRangeUsageBitMap = AllocateZeroPool(((SmmCodePageNumber / 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 (mSmmCodeMemoryRangeUsageBitMap == NULL) {
- return EFI_NOT_FOUND;
- }
- //
- // see if the memory range for loading the image is in the SMM code range.
- //
- if (SmmCodeBase + SmmCodeSize < ImageBase + ImageSize || SmmCodeBase > ImageBase) {
- return EFI_NOT_FOUND;
- }
- //
- // Test if the memory is available or not.
- //
- BaseOffsetPageNumber = EFI_SIZE_TO_PAGES((UINT32)(ImageBase - SmmCodeBase));
- TopOffsetPageNumber = EFI_SIZE_TO_PAGES((UINT32)(ImageBase + ImageSize - SmmCodeBase));
- for (Index = BaseOffsetPageNumber; Index < TopOffsetPageNumber; Index ++) {
- if ((mSmmCodeMemoryRangeUsageBitMap[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 ++) {
- mSmmCodeMemoryRangeUsageBitMap[Index / 64] |= LShiftU64(1, (Index % 64));
- }
- return EFI_SUCCESS;
+ UINT32 SmmCodePageNumber;
+ UINT64 SmmCodeSize;
+ EFI_PHYSICAL_ADDRESS SmmCodeBase;
+ UINTN BaseOffsetPageNumber;
+ UINTN TopOffsetPageNumber;
+ UINTN Index;
+
+ //
+ // Build tool will calculate the smm code size and then patch the PcdLoadFixAddressSmmCodePageNumber
+ //
+ SmmCodePageNumber = PcdGet32 (PcdLoadFixAddressSmmCodePageNumber);
+ SmmCodeSize = EFI_PAGES_TO_SIZE (SmmCodePageNumber);
+ SmmCodeBase = gLoadModuleAtFixAddressSmramBase;
+
+ //
+ // 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 (mSmmCodeMemoryRangeUsageBitMap == NULL) {
+ mSmmCodeMemoryRangeUsageBitMap = AllocateZeroPool (((SmmCodePageNumber / 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 (mSmmCodeMemoryRangeUsageBitMap == NULL) {
+ return EFI_NOT_FOUND;
+ }
+
+ //
+ // see if the memory range for loading the image is in the SMM code range.
+ //
+ if ((SmmCodeBase + SmmCodeSize < ImageBase + ImageSize) || (SmmCodeBase > ImageBase)) {
+ return EFI_NOT_FOUND;
+ }
+
+ //
+ // Test if the memory is available or not.
+ //
+ BaseOffsetPageNumber = EFI_SIZE_TO_PAGES ((UINT32)(ImageBase - SmmCodeBase));
+ TopOffsetPageNumber = EFI_SIZE_TO_PAGES ((UINT32)(ImageBase + ImageSize - SmmCodeBase));
+ for (Index = BaseOffsetPageNumber; Index < TopOffsetPageNumber; Index++) {
+ if ((mSmmCodeMemoryRangeUsageBitMap[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++) {
+ mSmmCodeMemoryRangeUsageBitMap[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
when Loading module at Fixed address feature enabled.
@@ -207,27 +213,27 @@ 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;
- EFI_PHYSICAL_ADDRESS FixLoadingAddress;
- UINT16 Index;
- UINTN Size;
- UINT16 NumberOfSections;
- UINT64 ValueInSectionHeader;
+ UINTN SectionHeaderOffset;
+ EFI_STATUS Status;
+ EFI_IMAGE_SECTION_HEADER SectionHeader;
+ EFI_IMAGE_OPTIONAL_HEADER_UNION *ImgHdr;
+ EFI_PHYSICAL_ADDRESS FixLoadingAddress;
+ UINT16 Index;
+ UINTN Size;
+ UINT16 NumberOfSections;
+ UINT64 ValueInSectionHeader;
FixLoadingAddress = 0;
- Status = EFI_NOT_FOUND;
+ Status = EFI_NOT_FOUND;
//
// Get PeHeader pointer
//
- ImgHdr = (EFI_IMAGE_OPTIONAL_HEADER_UNION *)((CHAR8* )ImageContext->Handle + ImageContext->PeCoffHeaderOffset);
+ ImgHdr = (EFI_IMAGE_OPTIONAL_HEADER_UNION *)((CHAR8 *)ImageContext->Handle + ImageContext->PeCoffHeaderOffset);
SectionHeaderOffset = ImageContext->PeCoffHeaderOffset +
sizeof (UINT32) +
sizeof (EFI_IMAGE_FILE_HEADER) +
@@ -241,13 +247,13 @@ GetPeCoffImageFixLoadingAssignedAddress(
//
// Read section header from file
//
- Size = sizeof (EFI_IMAGE_SECTION_HEADER);
+ Size = sizeof (EFI_IMAGE_SECTION_HEADER);
Status = ImageContext->ImageRead (
- ImageContext->Handle,
- SectionHeaderOffset,
- &Size,
- &SectionHeader
- );
+ ImageContext->Handle,
+ SectionHeaderOffset,
+ &Size,
+ &SectionHeader
+ );
if (EFI_ERROR (Status)) {
return Status;
}
@@ -261,7 +267,7 @@ GetPeCoffImageFixLoadingAssignedAddress(
// if a module with a loading address assigned by tools, the PointerToRelocations & PointerToLineNumbers fields
// should not be Zero, or else, these 2 fields should be set to Zero
//
- ValueInSectionHeader = ReadUnaligned64((UINT64*)&SectionHeader.PointerToRelocations);
+ ValueInSectionHeader = ReadUnaligned64 ((UINT64 *)&SectionHeader.PointerToRelocations);
if (ValueInSectionHeader != 0) {
//
// Found first section header that doesn't point to code section in which build tool saves the
@@ -272,20 +278,24 @@ GetPeCoffImageFixLoadingAssignedAddress(
// Check if the memory range is available.
//
Status = CheckAndMarkFixLoadingMemoryUsageBitMap (FixLoadingAddress, (UINTN)(ImageContext->ImageSize + ImageContext->SectionAlignment));
- if (!EFI_ERROR(Status)) {
+ if (!EFI_ERROR (Status)) {
//
// The assigned address is valid. Return the specified loading address
//
ImageContext->ImageAddress = FixLoadingAddress;
}
}
+
break;
}
+
SectionHeaderOffset += sizeof (EFI_IMAGE_SECTION_HEADER);
}
+
DEBUG ((DEBUG_INFO|DEBUG_LOAD, "LOADING MODULE FIXED INFO: Loading module at fixed address %x, Status = %r\n", FixLoadingAddress, Status));
return Status;
}
+
/**
Loads an EFI image into SMRAM.
@@ -318,11 +328,11 @@ SmmLoadImage (
PERF_LOAD_IMAGE_BEGIN (DriverEntry->ImageHandle);
- Buffer = NULL;
- Size = 0;
- Fv = DriverEntry->Fv;
- NameGuid = &DriverEntry->FileName;
- FilePath = DriverEntry->FvFileDevicePath;
+ Buffer = NULL;
+ Size = 0;
+ Fv = DriverEntry->Fv;
+ NameGuid = &DriverEntry->FileName;
+ FilePath = DriverEntry->FvFileDevicePath;
OriginalFilePath = FilePath;
HandleFilePath = FilePath;
@@ -335,7 +345,7 @@ SmmLoadImage (
// Try to get the image device handle by checking the match protocol.
//
Status = gBS->LocateDevicePath (&gEfiFirmwareVolume2ProtocolGuid, &HandleFilePath, &DeviceHandle);
- if (EFI_ERROR(Status)) {
+ if (EFI_ERROR (Status)) {
return Status;
}
@@ -343,11 +353,13 @@ SmmLoadImage (
// If the Security2 and Security Architectural Protocol has not been located yet, then attempt to locate it
//
if (mSecurity2 == NULL) {
- gBS->LocateProtocol (&gEfiSecurity2ArchProtocolGuid, NULL, (VOID**)&mSecurity2);
+ gBS->LocateProtocol (&gEfiSecurity2ArchProtocolGuid, NULL, (VOID **)&mSecurity2);
}
+
if (mSecurity == NULL) {
- gBS->LocateProtocol (&gEfiSecurityArchProtocolGuid, NULL, (VOID**)&mSecurity);
+ gBS->LocateProtocol (&gEfiSecurityArchProtocolGuid, NULL, (VOID **)&mSecurity);
}
+
//
// When Security2 is installed, Security Architectural Protocol must be published.
//
@@ -357,10 +369,10 @@ SmmLoadImage (
// Pull out just the file portion of the DevicePath for the LoadedImage FilePath
//
FilePath = OriginalFilePath;
- Status = gBS->HandleProtocol (DeviceHandle, &gEfiDevicePathProtocolGuid, (VOID **)&HandleFilePath);
+ Status = gBS->HandleProtocol (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);
}
//
@@ -383,20 +395,21 @@ SmmLoadImage (
Buffer = NULL;
Size = 0;
Status = Fv->ReadSection (
- Fv,
- NameGuid,
- EFI_SECTION_TE,
- 0,
- &Buffer,
- &Size,
- &AuthenticationStatus
- );
+ Fv,
+ NameGuid,
+ EFI_SECTION_TE,
+ 0,
+ &Buffer,
+ &Size,
+ &AuthenticationStatus
+ );
}
if (EFI_ERROR (Status)) {
if (Buffer != NULL) {
gBS->FreePool (Buffer);
}
+
return Status;
}
@@ -405,12 +418,12 @@ SmmLoadImage (
//
if (mSecurity2 != NULL) {
SecurityStatus = mSecurity2->FileAuthentication (
- mSecurity2,
- OriginalFilePath,
- Buffer,
- Size,
- FALSE
- );
+ mSecurity2,
+ OriginalFilePath,
+ Buffer,
+ Size,
+ FALSE
+ );
}
//
@@ -426,7 +439,7 @@ SmmLoadImage (
);
}
- if (EFI_ERROR (SecurityStatus) && SecurityStatus != EFI_SECURITY_VIOLATION) {
+ if (EFI_ERROR (SecurityStatus) && (SecurityStatus != EFI_SECURITY_VIOLATION)) {
Status = SecurityStatus;
return Status;
}
@@ -434,7 +447,7 @@ SmmLoadImage (
//
// Initialize ImageContext
//
- ImageContext.Handle = Buffer;
+ ImageContext.Handle = Buffer;
ImageContext.ImageRead = PeCoffLoaderImageReadFromMemory;
//
@@ -445,13 +458,15 @@ SmmLoadImage (
if (Buffer != NULL) {
gBS->FreePool (Buffer);
}
+
return Status;
}
+
//
// if Loading module at Fixed Address feature is enabled, then cut out a memory range started from TESG BASE
// to hold the Smm driver code
//
- if (PcdGet64(PcdLoadModuleAtFixAddressEnable) != 0) {
+ if (PcdGet64 (PcdLoadModuleAtFixAddressEnable) != 0) {
//
// Get the fixed loading address assigned by Build tool
//
@@ -464,46 +479,50 @@ SmmLoadImage (
PageCount = 0;
DstBuffer = (UINTN)gLoadModuleAtFixAddressSmramBase;
} else {
- DEBUG ((DEBUG_INFO|DEBUG_LOAD, "LOADING MODULE FIXED ERROR: Failed to load module at fixed address. \n"));
- //
- // allocate the memory to load the SMM driver
- //
- PageCount = (UINTN)EFI_SIZE_TO_PAGES((UINTN)ImageContext.ImageSize + ImageContext.SectionAlignment);
- DstBuffer = (UINTN)(-1);
-
- Status = SmmAllocatePages (
- AllocateMaxAddress,
- EfiRuntimeServicesCode,
- PageCount,
- &DstBuffer
- );
- if (EFI_ERROR (Status)) {
- if (Buffer != NULL) {
- gBS->FreePool (Buffer);
- }
- return Status;
- }
+ DEBUG ((DEBUG_INFO|DEBUG_LOAD, "LOADING MODULE FIXED ERROR: Failed to load module at fixed address. \n"));
+ //
+ // allocate the memory to load the SMM driver
+ //
+ PageCount = (UINTN)EFI_SIZE_TO_PAGES ((UINTN)ImageContext.ImageSize + ImageContext.SectionAlignment);
+ DstBuffer = (UINTN)(-1);
+
+ Status = SmmAllocatePages (
+ AllocateMaxAddress,
+ EfiRuntimeServicesCode,
+ PageCount,
+ &DstBuffer
+ );
+ if (EFI_ERROR (Status)) {
+ if (Buffer != NULL) {
+ gBS->FreePool (Buffer);
+ }
+
+ return Status;
+ }
+
ImageContext.ImageAddress = (EFI_PHYSICAL_ADDRESS)DstBuffer;
}
} else {
- PageCount = (UINTN)EFI_SIZE_TO_PAGES((UINTN)ImageContext.ImageSize + ImageContext.SectionAlignment);
- DstBuffer = (UINTN)(-1);
-
- Status = SmmAllocatePages (
- AllocateMaxAddress,
- EfiRuntimeServicesCode,
- PageCount,
- &DstBuffer
- );
- if (EFI_ERROR (Status)) {
- if (Buffer != NULL) {
- gBS->FreePool (Buffer);
- }
- return Status;
- }
-
- ImageContext.ImageAddress = (EFI_PHYSICAL_ADDRESS)DstBuffer;
+ PageCount = (UINTN)EFI_SIZE_TO_PAGES ((UINTN)ImageContext.ImageSize + ImageContext.SectionAlignment);
+ DstBuffer = (UINTN)(-1);
+
+ Status = SmmAllocatePages (
+ AllocateMaxAddress,
+ EfiRuntimeServicesCode,
+ PageCount,
+ &DstBuffer
+ );
+ if (EFI_ERROR (Status)) {
+ if (Buffer != NULL) {
+ gBS->FreePool (Buffer);
+ }
+
+ return Status;
+ }
+
+ ImageContext.ImageAddress = (EFI_PHYSICAL_ADDRESS)DstBuffer;
}
+
//
// Align buffer on section boundary
//
@@ -518,6 +537,7 @@ SmmLoadImage (
if (Buffer != NULL) {
gBS->FreePool (Buffer);
}
+
SmmFreePages (DstBuffer, PageCount);
return Status;
}
@@ -530,6 +550,7 @@ SmmLoadImage (
if (Buffer != NULL) {
gBS->FreePool (Buffer);
}
+
SmmFreePages (DstBuffer, PageCount);
return Status;
}
@@ -537,14 +558,14 @@ SmmLoadImage (
//
// Flush the instruction cache so the image data are written before we execute it
//
- InvalidateInstructionCacheRange ((VOID *)(UINTN) ImageContext.ImageAddress, (UINTN) ImageContext.ImageSize);
+ InvalidateInstructionCacheRange ((VOID *)(UINTN)ImageContext.ImageAddress, (UINTN)ImageContext.ImageSize);
//
// Save Image EntryPoint in DriverEntry
//
- DriverEntry->ImageEntryPoint = ImageContext.EntryPoint;
- DriverEntry->ImageBuffer = DstBuffer;
- DriverEntry->NumberOfPage = PageCount;
+ DriverEntry->ImageEntryPoint = ImageContext.EntryPoint;
+ DriverEntry->ImageBuffer = DstBuffer;
+ DriverEntry->NumberOfPage = PageCount;
//
// Allocate a Loaded Image Protocol in EfiBootServicesData
@@ -554,6 +575,7 @@ SmmLoadImage (
if (Buffer != NULL) {
gBS->FreePool (Buffer);
}
+
SmmFreePages (DstBuffer, PageCount);
return Status;
}
@@ -563,10 +585,10 @@ SmmLoadImage (
// Fill in the remaining fields of the Loaded Image Protocol instance.
// Note: ImageBase is an SMRAM address that can not be accessed outside of SMRAM if SMRAM window is closed.
//
- DriverEntry->LoadedImage->Revision = EFI_LOADED_IMAGE_PROTOCOL_REVISION;
- DriverEntry->LoadedImage->ParentHandle = gSmmCorePrivate->SmmIplImageHandle;
- DriverEntry->LoadedImage->SystemTable = gST;
- DriverEntry->LoadedImage->DeviceHandle = DeviceHandle;
+ DriverEntry->LoadedImage->Revision = EFI_LOADED_IMAGE_PROTOCOL_REVISION;
+ DriverEntry->LoadedImage->ParentHandle = gSmmCorePrivate->SmmIplImageHandle;
+ DriverEntry->LoadedImage->SystemTable = gST;
+ DriverEntry->LoadedImage->DeviceHandle = DeviceHandle;
DriverEntry->SmmLoadedImage.Revision = EFI_LOADED_IMAGE_PROTOCOL_REVISION;
DriverEntry->SmmLoadedImage.ParentHandle = gSmmCorePrivate->SmmIplImageHandle;
@@ -581,12 +603,14 @@ SmmLoadImage (
if (Buffer != NULL) {
gBS->FreePool (Buffer);
}
+
SmmFreePages (DstBuffer, PageCount);
return Status;
}
+
CopyMem (DriverEntry->LoadedImage->FilePath, FilePath, GetDevicePathSize (FilePath));
- DriverEntry->LoadedImage->ImageBase = (VOID *)(UINTN) ImageContext.ImageAddress;
+ DriverEntry->LoadedImage->ImageBase = (VOID *)(UINTN)ImageContext.ImageAddress;
DriverEntry->LoadedImage->ImageSize = ImageContext.ImageSize;
DriverEntry->LoadedImage->ImageCodeType = EfiRuntimeServicesCode;
DriverEntry->LoadedImage->ImageDataType = EfiRuntimeServicesData;
@@ -594,19 +618,21 @@ SmmLoadImage (
//
// Make a buffer copy of FilePath
//
- Status = SmmAllocatePool (EfiRuntimeServicesData, GetDevicePathSize(FilePath), (VOID **)&DriverEntry->SmmLoadedImage.FilePath);
+ Status = SmmAllocatePool (EfiRuntimeServicesData, GetDevicePathSize (FilePath), (VOID **)&DriverEntry->SmmLoadedImage.FilePath);
if (EFI_ERROR (Status)) {
if (Buffer != NULL) {
gBS->FreePool (Buffer);
}
+
gBS->FreePool (DriverEntry->LoadedImage->FilePath);
SmmFreePages (DstBuffer, PageCount);
return Status;
}
- CopyMem (DriverEntry->SmmLoadedImage.FilePath, FilePath, GetDevicePathSize(FilePath));
- DriverEntry->SmmLoadedImage.ImageBase = (VOID *)(UINTN) ImageContext.ImageAddress;
- DriverEntry->SmmLoadedImage.ImageSize = ImageContext.ImageSize;
+ CopyMem (DriverEntry->SmmLoadedImage.FilePath, FilePath, GetDevicePathSize (FilePath));
+
+ DriverEntry->SmmLoadedImage.ImageBase = (VOID *)(UINTN)ImageContext.ImageAddress;
+ DriverEntry->SmmLoadedImage.ImageSize = ImageContext.ImageSize;
DriverEntry->SmmLoadedImage.ImageCodeType = EfiRuntimeServicesCode;
DriverEntry->SmmLoadedImage.ImageDataType = EfiRuntimeServicesData;
@@ -614,22 +640,23 @@ SmmLoadImage (
// Create a new image handle in the UEFI handle database for the SMM Driver
//
DriverEntry->ImageHandle = NULL;
- Status = gBS->InstallMultipleProtocolInterfaces (
- &DriverEntry->ImageHandle,
- &gEfiLoadedImageProtocolGuid, DriverEntry->LoadedImage,
- NULL
- );
+ Status = gBS->InstallMultipleProtocolInterfaces (
+ &DriverEntry->ImageHandle,
+ &gEfiLoadedImageProtocolGuid,
+ DriverEntry->LoadedImage,
+ NULL
+ );
//
// Create a new image handle in the SMM handle database for the SMM Driver
//
DriverEntry->SmmImageHandle = NULL;
- Status = SmmInstallProtocolInterface (
- &DriverEntry->SmmImageHandle,
- &gEfiLoadedImageProtocolGuid,
- EFI_NATIVE_INTERFACE,
- &DriverEntry->SmmLoadedImage
- );
+ Status = SmmInstallProtocolInterface (
+ &DriverEntry->SmmImageHandle,
+ &gEfiLoadedImageProtocolGuid,
+ EFI_NATIVE_INTERFACE,
+ &DriverEntry->SmmLoadedImage
+ );
PERF_LOAD_IMAGE_END (DriverEntry->ImageHandle);
@@ -639,53 +666,57 @@ SmmLoadImage (
DEBUG_CODE_BEGIN ();
- UINTN Index;
- UINTN StartIndex;
- CHAR8 EfiFileName[256];
-
+ UINTN Index;
+ UINTN StartIndex;
+ CHAR8 EfiFileName[256];
- DEBUG ((DEBUG_INFO | DEBUG_LOAD,
- "Loading SMM driver at 0x%11p EntryPoint=0x%11p ",
- (VOID *)(UINTN) ImageContext.ImageAddress,
- FUNCTION_ENTRY_POINT (ImageContext.EntryPoint)));
+ DEBUG ((
+ DEBUG_INFO | DEBUG_LOAD,
+ "Loading SMM driver at 0x%11p EntryPoint=0x%11p ",
+ (VOID *)(UINTN)ImageContext.ImageAddress,
+ FUNCTION_ENTRY_POINT (ImageContext.EntryPoint)
+ ));
+ //
+ // Print Module Name by Pdb file path.
+ // Windows and Unix style file path are all trimmed correctly.
+ //
+ if (ImageContext.PdbPointer != NULL) {
+ StartIndex = 0;
+ for (Index = 0; ImageContext.PdbPointer[Index] != 0; Index++) {
+ if ((ImageContext.PdbPointer[Index] == '\\') || (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 redundant characters to avoid overflow in array boundary.
//
- if (ImageContext.PdbPointer != NULL) {
- StartIndex = 0;
- for (Index = 0; ImageContext.PdbPointer[Index] != 0; Index++) {
- if ((ImageContext.PdbPointer[Index] == '\\') || (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 redundant characters to avoid overflow in array boundary.
- //
- for (Index = 0; Index < sizeof (EfiFileName) - 4; Index++) {
- EfiFileName[Index] = 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] = 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 ();
@@ -695,10 +726,11 @@ SmmLoadImage (
// The UEFI Boot Services FreePool() function must be used because Fv->ReadSection
// used the UEFI Boot Services AllocatePool() function
//
- Status = gBS->FreePool(Buffer);
+ Status = gBS->FreePool (Buffer);
if (!EFI_ERROR (Status) && EFI_ERROR (SecurityStatus)) {
Status = SecurityStatus;
}
+
return Status;
}
@@ -719,7 +751,7 @@ SmmPreProcessDepex (
{
UINT8 *Iterator;
- Iterator = DriverEntry->Depex;
+ Iterator = DriverEntry->Depex;
DriverEntry->Dependent = TRUE;
if (*Iterator == EFI_DEP_BEFORE) {
@@ -763,16 +795,16 @@ SmmGetDepexSectionAndPreProccess (
// Grab Depex info, it will never be free'ed.
// (Note: DriverEntry->Depex is in DXE memory)
//
- SectionType = EFI_SECTION_SMM_DEPEX;
- Status = Fv->ReadSection (
- DriverEntry->Fv,
- &DriverEntry->FileName,
- SectionType,
- 0,
- &DriverEntry->Depex,
- (UINTN *)&DriverEntry->DepexSize,
- &AuthenticationStatus
- );
+ SectionType = EFI_SECTION_SMM_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) {
//
@@ -783,8 +815,8 @@ SmmGetDepexSectionAndPreProccess (
//
// If no Depex assume depend on all architectural protocols
//
- DriverEntry->Depex = NULL;
- DriverEntry->Dependent = TRUE;
+ DriverEntry->Depex = NULL;
+ DriverEntry->Dependent = TRUE;
DriverEntry->DepexProtocolError = FALSE;
}
} else {
@@ -867,8 +899,8 @@ SmmDispatcher (
// The SMM Driver could not be loaded, and do not attempt to load or start it again.
// Take driver from Scheduled to Initialized.
//
- DriverEntry->Initialized = TRUE;
- DriverEntry->Scheduled = FALSE;
+ DriverEntry->Initialized = TRUE;
+ DriverEntry->Scheduled = FALSE;
RemoveEntryList (&DriverEntry->ScheduledLink);
//
@@ -878,8 +910,8 @@ SmmDispatcher (
}
}
- DriverEntry->Scheduled = FALSE;
- DriverEntry->Initialized = TRUE;
+ DriverEntry->Scheduled = FALSE;
+ DriverEntry->Initialized = TRUE;
RemoveEntryList (&DriverEntry->ScheduledLink);
REPORT_STATUS_CODE_WITH_EXTENDED_DATA (
@@ -901,7 +933,7 @@ SmmDispatcher (
PERF_START_IMAGE_BEGIN (DriverEntry->ImageHandle);
Status = ((EFI_IMAGE_ENTRY_POINT)(UINTN)DriverEntry->ImageEntryPoint)(DriverEntry->ImageHandle, gST);
PERF_START_IMAGE_END (DriverEntry->ImageHandle);
- if (EFI_ERROR(Status)){
+ if (EFI_ERROR (Status)) {
DEBUG ((
DEBUG_ERROR,
"Error: SMM image at %11p start failed: %r\n",
@@ -909,7 +941,7 @@ SmmDispatcher (
Status
));
UnregisterSmramProfileImage (DriverEntry, TRUE);
- SmmFreePages(DriverEntry->ImageBuffer, DriverEntry->NumberOfPage);
+ SmmFreePages (DriverEntry->ImageBuffer, DriverEntry->NumberOfPage);
//
// Uninstall LoadedImage
//
@@ -922,14 +954,16 @@ SmmDispatcher (
if (DriverEntry->LoadedImage->FilePath != NULL) {
gBS->FreePool (DriverEntry->LoadedImage->FilePath);
}
+
gBS->FreePool (DriverEntry->LoadedImage);
}
+
Status = SmmUninstallProtocolInterface (
DriverEntry->SmmImageHandle,
&gEfiLoadedImageProtocolGuid,
&DriverEntry->SmmLoadedImage
);
- if (!EFI_ERROR(Status)) {
+ if (!EFI_ERROR (Status)) {
if (DriverEntry->SmmLoadedImage.FilePath != NULL) {
SmmFreePool (DriverEntry->SmmLoadedImage.FilePath);
}
@@ -952,7 +986,7 @@ SmmDispatcher (
// Once the SMM Entry Point has been registered, then SMM Mode will be
// used.
//
- gRequestDispatch = TRUE;
+ gRequestDispatch = TRUE;
gDispatcherRunning = FALSE;
return EFI_NOT_READY;
}
@@ -965,7 +999,7 @@ SmmDispatcher (
for (Link = mDiscoveredList.ForwardLink; Link != &mDiscoveredList; Link = Link->ForwardLink) {
DriverEntry = CR (Link, EFI_SMM_DRIVER_ENTRY, Link, EFI_SMM_DRIVER_ENTRY_SIGNATURE);
- if (DriverEntry->DepexProtocolError){
+ if (DriverEntry->DepexProtocolError) {
//
// If Section Extraction Protocol did not let the Depex be read before retry the read
//
@@ -988,7 +1022,7 @@ SmmDispatcher (
for (Link = mDiscoveredList.ForwardLink; Link != &mDiscoveredList; Link = Link->ForwardLink) {
DriverEntry = CR (Link, EFI_SMM_DRIVER_ENTRY, Link, EFI_SMM_DRIVER_ENTRY_SIGNATURE);
- if (!DriverEntry->Initialized){
+ if (!DriverEntry->Initialized) {
//
// We have SMM driver pending to dispatch
//
@@ -1015,18 +1049,18 @@ SmmDispatcher (
**/
VOID
SmmInsertOnScheduledQueueWhileProcessingBeforeAndAfter (
- IN EFI_SMM_DRIVER_ENTRY *InsertedDriverEntry
+ IN EFI_SMM_DRIVER_ENTRY *InsertedDriverEntry
)
{
LIST_ENTRY *Link;
- EFI_SMM_DRIVER_ENTRY *DriverEntry;
+ EFI_SMM_DRIVER_ENTRY *DriverEntry;
//
// Process Before Dependency
//
for (Link = mDiscoveredList.ForwardLink; Link != &mDiscoveredList; Link = Link->ForwardLink) {
- DriverEntry = CR(Link, EFI_SMM_DRIVER_ENTRY, Link, EFI_SMM_DRIVER_ENTRY_SIGNATURE);
- if (DriverEntry->Before && DriverEntry->Dependent && DriverEntry != InsertedDriverEntry) {
+ DriverEntry = CR (Link, EFI_SMM_DRIVER_ENTRY, Link, EFI_SMM_DRIVER_ENTRY_SIGNATURE);
+ if (DriverEntry->Before && DriverEntry->Dependent && (DriverEntry != InsertedDriverEntry)) {
DEBUG ((DEBUG_DISPATCH, "Evaluate SMM DEPEX for FFS(%g)\n", &DriverEntry->FileName));
DEBUG ((DEBUG_DISPATCH, " BEFORE FFS(%g) = ", &DriverEntry->BeforeAfterGuid));
if (CompareGuid (&InsertedDriverEntry->FileName, &DriverEntry->BeforeAfterGuid)) {
@@ -1049,13 +1083,12 @@ SmmInsertOnScheduledQueueWhileProcessingBeforeAndAfter (
InsertedDriverEntry->Scheduled = TRUE;
InsertTailList (&mScheduledQueue, &InsertedDriverEntry->ScheduledLink);
-
//
// Process After Dependency
//
for (Link = mDiscoveredList.ForwardLink; Link != &mDiscoveredList; Link = Link->ForwardLink) {
- DriverEntry = CR(Link, EFI_SMM_DRIVER_ENTRY, Link, EFI_SMM_DRIVER_ENTRY_SIGNATURE);
- if (DriverEntry->After && DriverEntry->Dependent && DriverEntry != InsertedDriverEntry) {
+ DriverEntry = CR (Link, EFI_SMM_DRIVER_ENTRY, Link, EFI_SMM_DRIVER_ENTRY_SIGNATURE);
+ if (DriverEntry->After && DriverEntry->Dependent && (DriverEntry != InsertedDriverEntry)) {
DEBUG ((DEBUG_DISPATCH, "Evaluate SMM DEPEX for FFS(%g)\n", &DriverEntry->FileName));
DEBUG ((DEBUG_DISPATCH, " AFTER FFS(%g) = ", &DriverEntry->BeforeAfterGuid));
if (CompareGuid (&InsertedDriverEntry->FileName, &DriverEntry->BeforeAfterGuid)) {
@@ -1090,11 +1123,12 @@ FvHasBeenProcessed (
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;
}
@@ -1117,7 +1151,7 @@ FvIsBeingProcessed (
ASSERT (KnownHandle != NULL);
KnownHandle->Signature = KNOWN_HANDLE_SIGNATURE;
- KnownHandle->Handle = FvHandle;
+ KnownHandle->Handle = FvHandle;
InsertTailList (&mFvHandleList, &KnownHandle->Link);
}
@@ -1136,14 +1170,14 @@ FvIsBeingProcessed (
**/
EFI_DEVICE_PATH_PROTOCOL *
SmmFvToDevicePath (
- 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
@@ -1162,10 +1196,11 @@ SmmFvToDevicePath (
// Note: FileNameDevicePath is in DXE memory
//
FileNameDevicePath = AppendDevicePath (
- FvDevicePath,
- (EFI_DEVICE_PATH_PROTOCOL *)&mFvDevicePath
- );
+ FvDevicePath,
+ (EFI_DEVICE_PATH_PROTOCOL *)&mFvDevicePath
+ );
}
+
return FileNameDevicePath;
}
@@ -1205,7 +1240,7 @@ SmmAddToDriverList (
DriverEntry = AllocateZeroPool (sizeof (EFI_SMM_DRIVER_ENTRY));
ASSERT (DriverEntry != NULL);
- DriverEntry->Signature = EFI_SMM_DRIVER_ENTRY_SIGNATURE;
+ DriverEntry->Signature = EFI_SMM_DRIVER_ENTRY_SIGNATURE;
CopyGuid (&DriverEntry->FileName, DriverName);
DriverEntry->FvHandle = FvHandle;
DriverEntry->Fv = Fv;
@@ -1253,36 +1288,36 @@ SmmDriverDispatchHandler (
IN OUT UINTN *CommBufferSize OPTIONAL
)
{
- EFI_STATUS Status;
- UINTN HandleCount;
- EFI_HANDLE *HandleBuffer;
- EFI_STATUS GetNextFileStatus;
- EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv;
- EFI_DEVICE_PATH_PROTOCOL *FvDevicePath;
- EFI_HANDLE FvHandle;
- EFI_GUID NameGuid;
- UINTN Key;
- EFI_FV_FILETYPE Type;
- EFI_FV_FILE_ATTRIBUTES Attributes;
- UINTN Size;
- EFI_SMM_DRIVER_ENTRY *DriverEntry;
- EFI_GUID *AprioriFile;
- UINTN AprioriEntryCount;
- UINTN HandleIndex;
- UINTN SmmTypeIndex;
- UINTN AprioriIndex;
- LIST_ENTRY *Link;
- UINT32 AuthenticationStatus;
- UINTN SizeOfBuffer;
+ EFI_STATUS Status;
+ UINTN HandleCount;
+ EFI_HANDLE *HandleBuffer;
+ EFI_STATUS GetNextFileStatus;
+ EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv;
+ EFI_DEVICE_PATH_PROTOCOL *FvDevicePath;
+ EFI_HANDLE FvHandle;
+ EFI_GUID NameGuid;
+ UINTN Key;
+ EFI_FV_FILETYPE Type;
+ EFI_FV_FILE_ATTRIBUTES Attributes;
+ UINTN Size;
+ EFI_SMM_DRIVER_ENTRY *DriverEntry;
+ EFI_GUID *AprioriFile;
+ UINTN AprioriEntryCount;
+ UINTN HandleIndex;
+ UINTN SmmTypeIndex;
+ UINTN AprioriIndex;
+ LIST_ENTRY *Link;
+ UINT32 AuthenticationStatus;
+ UINTN SizeOfBuffer;
HandleBuffer = NULL;
- Status = gBS->LocateHandleBuffer (
- ByProtocol,
- &gEfiFirmwareVolume2ProtocolGuid,
- NULL,
- &HandleCount,
- &HandleBuffer
- );
+ Status = gBS->LocateHandleBuffer (
+ ByProtocol,
+ &gEfiFirmwareVolume2ProtocolGuid,
+ NULL,
+ &HandleCount,
+ &HandleBuffer
+ );
if (EFI_ERROR (Status)) {
return EFI_NOT_FOUND;
}
@@ -1330,7 +1365,7 @@ SmmDriverDispatchHandler (
//
Key = 0;
do {
- Type = mSmmFileTypes[SmmTypeIndex];
+ Type = mSmmFileTypes[SmmTypeIndex];
GetNextFileStatus = Fv->GetNextFile (
Fv,
&Key,
@@ -1365,6 +1400,7 @@ SmmDriverDispatchHandler (
mSmmCoreLoadedImage->DeviceHandle = FvHandle;
}
+
if (mSmmCoreDriverEntry->SmmLoadedImage.FilePath == NULL) {
//
// Maybe one special FV contains only one SMM_CORE module, so its device path must
@@ -1382,7 +1418,7 @@ SmmDriverDispatchHandler (
(VOID **)&mSmmCoreDriverEntry->SmmLoadedImage.FilePath
);
ASSERT_EFI_ERROR (Status);
- CopyMem (mSmmCoreDriverEntry->SmmLoadedImage.FilePath, &mFvDevicePath, GetDevicePathSize((EFI_DEVICE_PATH_PROTOCOL *)&mFvDevicePath));
+ CopyMem (mSmmCoreDriverEntry->SmmLoadedImage.FilePath, &mFvDevicePath, GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL *)&mFvDevicePath));
mSmmCoreDriverEntry->SmmLoadedImage.DeviceHandle = FvHandle;
}
@@ -1398,15 +1434,15 @@ SmmDriverDispatchHandler (
// (Note: AprioriFile is in DXE memory)
//
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 {
@@ -1421,9 +1457,10 @@ SmmDriverDispatchHandler (
for (AprioriIndex = 0; AprioriIndex < AprioriEntryCount; AprioriIndex++) {
for (Link = mDiscoveredList.ForwardLink; Link != &mDiscoveredList; Link = Link->ForwardLink) {
- DriverEntry = CR(Link, EFI_SMM_DRIVER_ENTRY, Link, EFI_SMM_DRIVER_ENTRY_SIGNATURE);
+ DriverEntry = CR (Link, EFI_SMM_DRIVER_ENTRY, Link, EFI_SMM_DRIVER_ENTRY_SIGNATURE);
if (CompareGuid (&DriverEntry->FileName, &AprioriFile[AprioriIndex]) &&
- (FvHandle == DriverEntry->FvHandle)) {
+ (FvHandle == DriverEntry->FvHandle))
+ {
DriverEntry->Dependent = FALSE;
DriverEntry->Scheduled = TRUE;
InsertTailList (&mScheduledQueue, &DriverEntry->ScheduledLink);
@@ -1452,7 +1489,7 @@ SmmDriverDispatchHandler (
//
// Check to see if CommBuffer and CommBufferSize are valid
//
- if (CommBuffer != NULL && CommBufferSize != NULL) {
+ if ((CommBuffer != NULL) && (CommBufferSize != NULL)) {
if (*CommBufferSize > 0) {
if (Status == EFI_NOT_READY) {
//
@@ -1487,11 +1524,11 @@ SmmDisplayDiscoveredNotDispatched (
VOID
)
{
- LIST_ENTRY *Link;
- EFI_SMM_DRIVER_ENTRY *DriverEntry;
+ LIST_ENTRY *Link;
+ EFI_SMM_DRIVER_ENTRY *DriverEntry;
- for (Link = mDiscoveredList.ForwardLink;Link !=&mDiscoveredList; Link = Link->ForwardLink) {
- DriverEntry = CR(Link, EFI_SMM_DRIVER_ENTRY, Link, EFI_SMM_DRIVER_ENTRY_SIGNATURE);
+ for (Link = mDiscoveredList.ForwardLink; Link != &mDiscoveredList; Link = Link->ForwardLink) {
+ DriverEntry = CR (Link, EFI_SMM_DRIVER_ENTRY, Link, EFI_SMM_DRIVER_ENTRY_SIGNATURE);
if (DriverEntry->Dependent) {
DEBUG ((DEBUG_LOAD, "SMM Driver %g was discovered but not loaded!!\n", &DriverEntry->FileName));
}
diff --git a/MdeModulePkg/Core/PiSmmCore/Handle.c b/MdeModulePkg/Core/PiSmmCore/Handle.c
index f8dbe46449..5a8760a430 100644
--- a/MdeModulePkg/Core/PiSmmCore/Handle.c
+++ b/MdeModulePkg/Core/PiSmmCore/Handle.c
@@ -12,8 +12,8 @@
// mProtocolDatabase - A list of all protocols in the system. (simple list for now)
// gHandleList - A list of all the handles in the system
//
-LIST_ENTRY mProtocolDatabase = INITIALIZE_LIST_HEAD_VARIABLE (mProtocolDatabase);
-LIST_ENTRY gHandleList = INITIALIZE_LIST_HEAD_VARIABLE (gHandleList);
+LIST_ENTRY mProtocolDatabase = INITIALIZE_LIST_HEAD_VARIABLE (mProtocolDatabase);
+LIST_ENTRY gHandleList = INITIALIZE_LIST_HEAD_VARIABLE (gHandleList);
/**
Check whether a handle is a valid EFI_HANDLE
@@ -35,9 +35,11 @@ SmmValidateHandle (
if (Handle == NULL) {
return EFI_INVALID_PARAMETER;
}
+
if (Handle->Signature != EFI_HANDLE_SIGNATURE) {
return EFI_INVALID_PARAMETER;
}
+
return EFI_SUCCESS;
}
@@ -52,13 +54,13 @@ SmmValidateHandle (
**/
PROTOCOL_ENTRY *
SmmFindProtocolEntry (
- 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;
//
// Search the database for the matching GUID
@@ -67,9 +69,9 @@ SmmFindProtocolEntry (
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
@@ -84,7 +86,7 @@ SmmFindProtocolEntry (
// allocate a new entry
//
if ((ProtEntry == NULL) && Create) {
- ProtEntry = AllocatePool (sizeof(PROTOCOL_ENTRY));
+ ProtEntry = AllocatePool (sizeof (PROTOCOL_ENTRY));
if (ProtEntry != NULL) {
//
// Initialize new protocol entry structure
@@ -100,6 +102,7 @@ SmmFindProtocolEntry (
InsertTailList (&mProtocolDatabase, &ProtEntry->AllEntries);
}
}
+
return ProtEntry;
}
@@ -136,17 +139,19 @@ SmmFindProtocolInterface (
//
// 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;
}
+
Prot = NULL;
}
}
+
return Prot;
}
@@ -218,7 +223,7 @@ SmmInstallProtocolInterfaceNotify (
// 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;
}
@@ -229,10 +234,10 @@ SmmInstallProtocolInterfaceNotify (
//
// Print debug message
//
- DEBUG((DEBUG_LOAD | DEBUG_INFO, "SmmInstallProtocolInterface: %g %p\n", Protocol, Interface));
+ DEBUG ((DEBUG_LOAD | DEBUG_INFO, "SmmInstallProtocolInterface: %g %p\n", Protocol, Interface));
Status = EFI_OUT_OF_RESOURCES;
- Prot = NULL;
+ Prot = NULL;
Handle = NULL;
if (*UserHandle != NULL) {
@@ -253,7 +258,7 @@ SmmInstallProtocolInterfaceNotify (
//
// 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;
@@ -264,7 +269,7 @@ SmmInstallProtocolInterfaceNotify (
//
Handle = (IHANDLE *)*UserHandle;
if (Handle == NULL) {
- Handle = AllocateZeroPool (sizeof(IHANDLE));
+ Handle = AllocateZeroPool (sizeof (IHANDLE));
if (Handle == NULL) {
Status = EFI_OUT_OF_RESOURCES;
goto Done;
@@ -284,7 +289,7 @@ SmmInstallProtocolInterfaceNotify (
} else {
Status = SmmValidateHandle (Handle);
if (EFI_ERROR (Status)) {
- DEBUG((DEBUG_ERROR, "SmmInstallProtocolInterface: input handle at 0x%x is invalid\n", Handle));
+ DEBUG ((DEBUG_ERROR, "SmmInstallProtocolInterface: input handle at 0x%x is invalid\n", Handle));
goto Done;
}
}
@@ -298,8 +303,8 @@ SmmInstallProtocolInterfaceNotify (
// 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;
//
@@ -320,6 +325,7 @@ SmmInstallProtocolInterfaceNotify (
if (Notify) {
SmmNotifyProtocol (Prot);
}
+
Status = EFI_SUCCESS;
Done:
@@ -335,8 +341,10 @@ Done:
if (Prot != NULL) {
FreePool (Prot);
}
- DEBUG((DEBUG_ERROR, "SmmInstallProtocolInterface: %g %p failed with %r\n", Protocol, Interface, Status));
+
+ DEBUG ((DEBUG_ERROR, "SmmInstallProtocolInterface: %g %p failed with %r\n", Protocol, Interface, Status));
}
+
return Status;
}
@@ -417,6 +425,7 @@ SmmUninstallProtocolInterface (
RemoveEntryList (&Handle->AllHandles);
FreePool (Handle);
}
+
return Status;
}
@@ -452,12 +461,13 @@ SmmGetProtocolInterface (
// 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;
}
diff --git a/MdeModulePkg/Core/PiSmmCore/HeapGuard.c b/MdeModulePkg/Core/PiSmmCore/HeapGuard.c
index b0d0f72044..8f3bab6fee 100644
--- a/MdeModulePkg/Core/PiSmmCore/HeapGuard.c
+++ b/MdeModulePkg/Core/PiSmmCore/HeapGuard.c
@@ -12,34 +12,34 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
// Global to avoid infinite reentrance of memory allocation when updating
// page table attributes, which may need allocating 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;
//
// SMM memory attribute protocol
//
-EDKII_SMM_MEMORY_ATTRIBUTE_PROTOCOL *mSmmMemoryAttribute = NULL;
+EDKII_SMM_MEMORY_ATTRIBUTE_PROTOCOL *mSmmMemoryAttribute = NULL;
/**
Set corresponding bits in bitmap table to 1 according to the address.
@@ -53,29 +53,29 @@ EDKII_SMM_MEMORY_ATTRIBUTE_PROTOCOL *mSmmMemoryAttribute = NULL;
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) {
@@ -84,8 +84,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;
}
@@ -106,29 +109,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) {
@@ -161,21 +164,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;
@@ -185,13 +188,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);
}
}
@@ -210,11 +213,16 @@ PageAlloc (
IN UINTN Pages
)
{
- EFI_STATUS Status;
- EFI_PHYSICAL_ADDRESS Memory;
-
- Status = SmmInternalAllocatePages (AllocateAnyPages, EfiRuntimeServicesData,
- Pages, &Memory, FALSE);
+ EFI_STATUS Status;
+ EFI_PHYSICAL_ADDRESS Memory;
+
+ Status = SmmInternalAllocatePages (
+ AllocateAnyPages,
+ EfiRuntimeServicesData,
+ Pages,
+ &Memory,
+ FALSE
+ );
if (EFI_ERROR (Status)) {
Memory = 0;
}
@@ -234,17 +242,17 @@ PageAlloc (
**/
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;
+ UINTN Level;
+ UINT64 *GuardMap;
+ UINT64 MapMemory;
+ UINTN Index;
+ UINTN Size;
+ UINTN BitsToUnitEnd;
//
// Adjust current map table depth according to the address to access
@@ -254,8 +262,8 @@ 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;
@@ -265,25 +273,24 @@ FindGuardedMemoryMap (
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;
MapMemory = (UINT64)(UINTN)PageAlloc (EFI_SIZE_TO_PAGES (Size));
ASSERT (MapMemory != 0);
@@ -291,10 +298,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);
@@ -314,13 +320,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);
@@ -330,7 +336,7 @@ SetGuardedMemoryBits (
// Cross map unit
Bits = BitsToUnitEnd;
} else {
- Bits = NumberOfPages;
+ Bits = NumberOfPages;
}
SetBits (Address, Bits, BitMap);
@@ -351,13 +357,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);
@@ -367,7 +373,7 @@ ClearGuardedMemoryBits (
// Cross map unit
Bits = BitsToUnitEnd;
} else {
- Bits = NumberOfPages;
+ Bits = NumberOfPages;
}
ClearBits (Address, Bits, BitMap);
@@ -387,15 +393,15 @@ ClearGuardedMemoryBits (
**/
UINTN
GetGuardedMemoryBits (
- IN EFI_PHYSICAL_ADDRESS Address,
- IN UINTN NumberOfPages
+ IN EFI_PHYSICAL_ADDRESS Address,
+ IN UINTN NumberOfPages
)
{
- UINT64 *BitMap;
- UINTN Bits;
- UINTN Result;
- UINTN Shift;
- UINTN BitsToUnitEnd;
+ UINT64 *BitMap;
+ UINTN Bits;
+ UINTN Result;
+ UINTN Shift;
+ UINTN BitsToUnitEnd;
ASSERT (NumberOfPages <= GUARDED_HEAP_MAP_ENTRY_BITS);
@@ -406,9 +412,9 @@ GetGuardedMemoryBits (
if (NumberOfPages > BitsToUnitEnd) {
// Cross map unit
- Bits = BitsToUnitEnd;
+ Bits = BitsToUnitEnd;
} else {
- Bits = NumberOfPages;
+ Bits = NumberOfPages;
}
if (BitMap != NULL) {
@@ -433,15 +439,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;
}
}
@@ -449,7 +458,6 @@ GetGuardMapBit (
return 0;
}
-
/**
Check to see if the page at the given address is a Guard page or not.
@@ -461,10 +469,10 @@ GetGuardMapBit (
BOOLEAN
EFIAPI
IsGuardPage (
- IN EFI_PHYSICAL_ADDRESS Address
-)
+ IN EFI_PHYSICAL_ADDRESS Address
+ )
{
- UINTN BitMap;
+ UINTN BitMap;
//
// There must be at least one guarded page before and/or after given
@@ -475,8 +483,6 @@ IsGuardPage (
return ((BitMap == BIT0) || (BitMap == BIT2) || (BitMap == (BIT2 | BIT0)));
}
-
-
/**
Check to see if the page at the given address is guarded or not.
@@ -488,7 +494,7 @@ IsGuardPage (
BOOLEAN
EFIAPI
IsMemoryGuarded (
- IN EFI_PHYSICAL_ADDRESS Address
+ IN EFI_PHYSICAL_ADDRESS Address
)
{
return (GetGuardMapBit (Address) == 1);
@@ -506,19 +512,19 @@ IsMemoryGuarded (
VOID
EFIAPI
SetGuardPage (
- IN EFI_PHYSICAL_ADDRESS BaseAddress
+ IN EFI_PHYSICAL_ADDRESS BaseAddress
)
{
- EFI_STATUS Status;
+ EFI_STATUS Status;
if (mSmmMemoryAttribute != NULL) {
mOnGuarding = TRUE;
- Status = mSmmMemoryAttribute->SetMemoryAttributes (
- mSmmMemoryAttribute,
- BaseAddress,
- EFI_PAGE_SIZE,
- EFI_MEMORY_RP
- );
+ Status = mSmmMemoryAttribute->SetMemoryAttributes (
+ mSmmMemoryAttribute,
+ BaseAddress,
+ EFI_PAGE_SIZE,
+ EFI_MEMORY_RP
+ );
ASSERT_EFI_ERROR (Status);
mOnGuarding = FALSE;
}
@@ -536,19 +542,19 @@ SetGuardPage (
VOID
EFIAPI
UnsetGuardPage (
- IN EFI_PHYSICAL_ADDRESS BaseAddress
+ IN EFI_PHYSICAL_ADDRESS BaseAddress
)
{
- EFI_STATUS Status;
+ EFI_STATUS Status;
if (mSmmMemoryAttribute != NULL) {
mOnGuarding = TRUE;
- Status = mSmmMemoryAttribute->ClearMemoryAttributes (
- mSmmMemoryAttribute,
- BaseAddress,
- EFI_PAGE_SIZE,
- EFI_MEMORY_RP
- );
+ Status = mSmmMemoryAttribute->ClearMemoryAttributes (
+ mSmmMemoryAttribute,
+ BaseAddress,
+ EFI_PAGE_SIZE,
+ EFI_MEMORY_RP
+ );
ASSERT_EFI_ERROR (Status);
mOnGuarding = FALSE;
}
@@ -567,17 +573,18 @@ 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 ((PcdGet8 (PcdHeapGuardPropertyMask) & PageOrPool) == 0
- || mOnGuarding
- || AllocateType == AllocateAddress) {
+ if ( ((PcdGet8 (PcdHeapGuardPropertyMask) & PageOrPool) == 0)
+ || mOnGuarding
+ || (AllocateType == AllocateAddress))
+ {
return FALSE;
}
@@ -590,8 +597,9 @@ IsMemoryTypeToGuard (
ConfigBit |= PcdGet64 (PcdHeapGuardPageType);
}
- if (MemoryType == EfiRuntimeServicesData ||
- MemoryType == EfiRuntimeServicesCode) {
+ if ((MemoryType == EfiRuntimeServicesData) ||
+ (MemoryType == EfiRuntimeServicesCode))
+ {
TestBit = LShiftU64 (1, MemoryType);
} else if (MemoryType == EfiMaxMemoryType) {
TestBit = (UINT64)-1;
@@ -613,11 +621,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
+ );
}
/**
@@ -631,8 +642,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);
@@ -648,8 +659,11 @@ IsHeapGuardEnabled (
VOID
)
{
- return IsMemoryTypeToGuard (EfiMaxMemoryType, AllocateAnyPages,
- GUARD_HEAP_TYPE_POOL|GUARD_HEAP_TYPE_PAGE);
+ return IsMemoryTypeToGuard (
+ EfiMaxMemoryType,
+ AllocateAnyPages,
+ GUARD_HEAP_TYPE_POOL|GUARD_HEAP_TYPE_PAGE
+ );
}
/**
@@ -662,11 +676,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
@@ -698,8 +712,8 @@ SetGuardForMemory (
**/
VOID
UnsetGuardForMemory (
- IN EFI_PHYSICAL_ADDRESS Memory,
- IN UINTN NumberOfPages
+ IN EFI_PHYSICAL_ADDRESS Memory,
+ IN UINTN NumberOfPages
)
{
EFI_PHYSICAL_ADDRESS GuardPage;
@@ -721,7 +735,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) {
//
@@ -754,7 +768,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) {
//
@@ -778,11 +792,9 @@ UnsetGuardForMemory (
//
// No matter what, we just clear the mark of the Guarded memory.
//
- ClearGuardedMemoryBits(Memory, NumberOfPages);
+ ClearGuardedMemoryBits (Memory, NumberOfPages);
}
-
-
/**
Adjust the start address and number of pages to free according to Guard.
@@ -797,8 +809,8 @@ UnsetGuardForMemory (
**/
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;
@@ -807,11 +819,11 @@ AdjustMemoryF (
UINT64 GuardBitmap;
UINT64 Attributes;
- if (Memory == NULL || NumberOfPages == NULL || *NumberOfPages == 0) {
+ if ((Memory == NULL) || (NumberOfPages == NULL) || (*NumberOfPages == 0)) {
return;
}
- Start = *Memory;
+ Start = *Memory;
PagesToFree = *NumberOfPages;
//
@@ -848,7 +860,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.
@@ -883,7 +895,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.
@@ -903,11 +915,10 @@ AdjustMemoryF (
PagesToFree -= 1;
}
- *Memory = Start;
- *NumberOfPages = PagesToFree;
+ *Memory = Start;
+ *NumberOfPages = PagesToFree;
}
-
/**
Adjust the pool head position to make sure the Guard page is adjavent to
pool tail or pool head.
@@ -921,12 +932,12 @@ AdjustMemoryF (
**/
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
//
@@ -949,10 +960,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
//
@@ -977,10 +988,10 @@ AdjustPoolHeadF (
**/
UINTN
InternalAllocMaxAddressWithGuard (
- IN OUT LIST_ENTRY *FreePageList,
- IN UINTN NumberOfPages,
- IN UINTN MaxAddress,
- IN EFI_MEMORY_TYPE MemoryType
+ IN OUT LIST_ENTRY *FreePageList,
+ IN UINTN NumberOfPages,
+ IN UINTN MaxAddress,
+ IN EFI_MEMORY_TYPE MemoryType
)
{
@@ -992,16 +1003,17 @@ InternalAllocMaxAddressWithGuard (
UINTN Address;
for (Node = FreePageList->BackLink; Node != FreePageList;
- Node = Node->BackLink) {
+ Node = Node->BackLink)
+ {
Pages = BASE_CR (Node, FREE_PAGE_LIST, Link);
- if (Pages->NumberOfPages >= NumberOfPages &&
- (UINTN)Pages + EFI_PAGES_TO_SIZE (NumberOfPages) - 1 <= MaxAddress) {
-
+ if ((Pages->NumberOfPages >= NumberOfPages) &&
+ ((UINTN)Pages + EFI_PAGES_TO_SIZE (NumberOfPages) - 1 <= MaxAddress))
+ {
//
// We may need 1 or 2 more pages for Guard. Check it out.
//
PagesToAlloc = NumberOfPages;
- TailGuard = (UINTN)Pages + EFI_PAGES_TO_SIZE (Pages->NumberOfPages);
+ TailGuard = (UINTN)Pages + EFI_PAGES_TO_SIZE (Pages->NumberOfPages);
if (!IsGuardPage (TailGuard)) {
//
// Add one if no Guard at the end of current free memory block.
@@ -1027,12 +1039,13 @@ InternalAllocMaxAddressWithGuard (
}
Address = InternalAllocPagesOnOneNode (Pages, PagesToAlloc, MaxAddress);
- ConvertSmmMemoryMapEntry(MemoryType, Address, PagesToAlloc, FALSE);
- CoreFreeMemoryMapStack();
+ ConvertSmmMemoryMapEntry (MemoryType, Address, PagesToAlloc, FALSE);
+ CoreFreeMemoryMapStack ();
if (HeadGuard == 0) {
// Don't pass the Guard page to user.
Address += EFI_PAGE_SIZE;
}
+
SetGuardForMemory (Address, NumberOfPages);
return Address;
}
@@ -1059,15 +1072,15 @@ SmmInternalFreePagesExWithGuard (
IN BOOLEAN AddRegion
)
{
- EFI_PHYSICAL_ADDRESS MemoryToFree;
- UINTN PagesToFree;
+ EFI_PHYSICAL_ADDRESS MemoryToFree;
+ UINTN PagesToFree;
if (((Memory & EFI_PAGE_MASK) != 0) || (Memory == 0) || (NumberOfPages == 0)) {
return EFI_INVALID_PARAMETER;
}
- MemoryToFree = Memory;
- PagesToFree = NumberOfPages;
+ MemoryToFree = Memory;
+ PagesToFree = NumberOfPages;
AdjustMemoryF (&MemoryToFree, &PagesToFree);
UnsetGuardForMemory (Memory, NumberOfPages);
@@ -1086,30 +1099,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;
@@ -1118,32 +1132,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) {
@@ -1152,6 +1160,7 @@ SetAllGuardPages (
} else {
GuardPage = Address - EFI_PAGE_SIZE;
}
+
OnGuarding = TRUE;
} else {
if (OnGuarding) {
@@ -1159,6 +1168,7 @@ SetAllGuardPages (
} else {
GuardPage = 0;
}
+
OnGuarding = FALSE;
}
@@ -1181,10 +1191,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]);
}
}
@@ -1204,7 +1213,7 @@ SmmEntryPointMemoryManagementHook (
NULL,
(VOID **)&mSmmMemoryAttribute
);
- if (!EFI_ERROR(Status)) {
+ if (!EFI_ERROR (Status)) {
SetAllGuardPages ();
}
}
@@ -1220,11 +1229,11 @@ SmmEntryPointMemoryManagementHook (
**/
VOID
Uint64ToBinString (
- IN UINT64 Value,
- OUT CHAR8 *BinString
+ IN UINT64 Value,
+ OUT CHAR8 *BinString
)
{
- UINTN Index;
+ UINTN Index;
if (BinString == NULL) {
return;
@@ -1232,8 +1241,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';
}
@@ -1246,40 +1256,44 @@ 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;
-
- 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;
+ INTN Level;
+ UINTN RepeatZero;
+ CHAR8 String[GUARDED_HEAP_MAP_ENTRY_BITS + 1];
+ CHAR8 *Ruler1;
+ CHAR8 *Ruler2;
+
+ 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;
@@ -1288,7 +1302,6 @@ DumpGuardedMemoryBitmap (
while (TRUE) {
if (Indices[Level] > Entries[Level]) {
-
Tables[Level] = 0;
Level -= 1;
RepeatZero = 0;
@@ -1298,40 +1311,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));
-
}
}
@@ -1339,10 +1345,9 @@ 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]);
}
}
@@ -1357,8 +1362,8 @@ DumpGuardedMemoryBitmap (
**/
BOOLEAN
VerifyMemoryGuard (
- IN EFI_PHYSICAL_ADDRESS BaseAddress,
- IN UINTN NumberOfPages
+ IN EFI_PHYSICAL_ADDRESS BaseAddress,
+ IN UINTN NumberOfPages
)
{
EFI_STATUS Status;
@@ -1370,35 +1375,42 @@ VerifyMemoryGuard (
}
Attribute = 0;
- Address = BaseAddress - EFI_PAGE_SIZE;
- Status = mSmmMemoryAttribute->GetMemoryAttributes (
- mSmmMemoryAttribute,
- Address,
- EFI_PAGE_SIZE,
- &Attribute
- );
- if (EFI_ERROR (Status) || (Attribute & EFI_MEMORY_RP) == 0) {
- DEBUG ((DEBUG_ERROR, "Head Guard is not set at: %016lx (%016lX)!!!\r\n",
- Address, Attribute));
+ Address = BaseAddress - EFI_PAGE_SIZE;
+ Status = mSmmMemoryAttribute->GetMemoryAttributes (
+ mSmmMemoryAttribute,
+ Address,
+ EFI_PAGE_SIZE,
+ &Attribute
+ );
+ if (EFI_ERROR (Status) || ((Attribute & EFI_MEMORY_RP) == 0)) {
+ DEBUG ((
+ DEBUG_ERROR,
+ "Head Guard is not set at: %016lx (%016lX)!!!\r\n",
+ Address,
+ Attribute
+ ));
DumpGuardedMemoryBitmap ();
return FALSE;
}
Attribute = 0;
- Address = BaseAddress + EFI_PAGES_TO_SIZE (NumberOfPages);
- Status = mSmmMemoryAttribute->GetMemoryAttributes (
- mSmmMemoryAttribute,
- Address,
- EFI_PAGE_SIZE,
- &Attribute
- );
- if (EFI_ERROR (Status) || (Attribute & EFI_MEMORY_RP) == 0) {
- DEBUG ((DEBUG_ERROR, "Tail Guard is not set at: %016lx (%016lX)!!!\r\n",
- Address, Attribute));
+ Address = BaseAddress + EFI_PAGES_TO_SIZE (NumberOfPages);
+ Status = mSmmMemoryAttribute->GetMemoryAttributes (
+ mSmmMemoryAttribute,
+ Address,
+ EFI_PAGE_SIZE,
+ &Attribute
+ );
+ if (EFI_ERROR (Status) || ((Attribute & EFI_MEMORY_RP) == 0)) {
+ DEBUG ((
+ DEBUG_ERROR,
+ "Tail Guard is not set at: %016lx (%016lX)!!!\r\n",
+ Address,
+ Attribute
+ ));
DumpGuardedMemoryBitmap ();
return FALSE;
}
return TRUE;
}
-
diff --git a/MdeModulePkg/Core/PiSmmCore/HeapGuard.h b/MdeModulePkg/Core/PiSmmCore/HeapGuard.h
index 1b5c0f2a4f..0a447ce2e8 100644
--- a/MdeModulePkg/Core/PiSmmCore/HeapGuard.h
+++ b/MdeModulePkg/Core/PiSmmCore/HeapGuard.h
@@ -53,15 +53,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)
@@ -154,8 +154,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
//
// Memory type to guard (matching the related PCD definition)
//
-#define GUARD_HEAP_TYPE_PAGE BIT2
-#define GUARD_HEAP_TYPE_POOL BIT3
+#define GUARD_HEAP_TYPE_PAGE BIT2
+#define GUARD_HEAP_TYPE_POOL BIT3
//
// Debug message level
@@ -163,10 +163,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;
/**
@@ -179,8 +179,8 @@ typedef struct {
**/
VOID
SetGuardForMemory (
- IN EFI_PHYSICAL_ADDRESS Memory,
- IN UINTN NumberOfPages
+ IN EFI_PHYSICAL_ADDRESS Memory,
+ IN UINTN NumberOfPages
);
/**
@@ -193,8 +193,8 @@ SetGuardForMemory (
**/
VOID
UnsetGuardForMemory (
- IN EFI_PHYSICAL_ADDRESS Memory,
- IN UINTN NumberOfPages
+ IN EFI_PHYSICAL_ADDRESS Memory,
+ IN UINTN NumberOfPages
);
/**
@@ -207,8 +207,8 @@ UnsetGuardForMemory (
**/
VOID
AdjustMemoryA (
- IN OUT EFI_PHYSICAL_ADDRESS *Memory,
- IN OUT UINTN *NumberOfPages
+ IN OUT EFI_PHYSICAL_ADDRESS *Memory,
+ IN OUT UINTN *NumberOfPages
);
/**
@@ -225,8 +225,8 @@ AdjustMemoryA (
**/
VOID
AdjustMemoryF (
- IN OUT EFI_PHYSICAL_ADDRESS *Memory,
- IN OUT UINTN *NumberOfPages
+ IN OUT EFI_PHYSICAL_ADDRESS *Memory,
+ IN OUT UINTN *NumberOfPages
);
/**
@@ -240,7 +240,7 @@ AdjustMemoryF (
**/
BOOLEAN
IsPoolTypeToGuard (
- IN EFI_MEMORY_TYPE MemoryType
+ IN EFI_MEMORY_TYPE MemoryType
);
/**
@@ -254,8 +254,8 @@ IsPoolTypeToGuard (
**/
BOOLEAN
IsPageTypeToGuard (
- IN EFI_MEMORY_TYPE MemoryType,
- IN EFI_ALLOCATE_TYPE AllocateType
+ IN EFI_MEMORY_TYPE MemoryType,
+ IN EFI_ALLOCATE_TYPE AllocateType
);
/**
@@ -269,7 +269,7 @@ IsPageTypeToGuard (
BOOLEAN
EFIAPI
IsMemoryGuarded (
- IN EFI_PHYSICAL_ADDRESS Address
+ IN EFI_PHYSICAL_ADDRESS Address
);
/**
@@ -283,7 +283,7 @@ IsMemoryGuarded (
BOOLEAN
EFIAPI
IsGuardPage (
- IN EFI_PHYSICAL_ADDRESS Address
+ IN EFI_PHYSICAL_ADDRESS Address
);
/**
@@ -308,9 +308,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
);
/**
@@ -322,7 +322,7 @@ AdjustPoolHeadA (
**/
VOID *
AdjustPoolHeadF (
- IN EFI_PHYSICAL_ADDRESS Memory
+ IN EFI_PHYSICAL_ADDRESS Memory
);
/**
@@ -337,10 +337,10 @@ AdjustPoolHeadF (
**/
UINTN
InternalAllocMaxAddressWithGuard (
- IN OUT LIST_ENTRY *FreePageList,
- IN UINTN NumberOfPages,
- IN UINTN MaxAddress,
- IN EFI_MEMORY_TYPE MemoryType
+ IN OUT LIST_ENTRY *FreePageList,
+ IN UINTN NumberOfPages,
+ IN UINTN MaxAddress,
+ IN EFI_MEMORY_TYPE MemoryType
);
/**
@@ -383,10 +383,10 @@ IsHeapGuardEnabled (
**/
BOOLEAN
VerifyMemoryGuard (
- IN EFI_PHYSICAL_ADDRESS BaseAddress,
- IN UINTN NumberOfPages
+ IN EFI_PHYSICAL_ADDRESS BaseAddress,
+ IN UINTN NumberOfPages
);
-extern BOOLEAN mOnGuarding;
+extern BOOLEAN mOnGuarding;
#endif
diff --git a/MdeModulePkg/Core/PiSmmCore/InstallConfigurationTable.c b/MdeModulePkg/Core/PiSmmCore/InstallConfigurationTable.c
index 57f31fa98f..0bc51be12b 100644
--- a/MdeModulePkg/Core/PiSmmCore/InstallConfigurationTable.c
+++ b/MdeModulePkg/Core/PiSmmCore/InstallConfigurationTable.c
@@ -8,7 +8,7 @@
#include "PiSmmCore.h"
-#define CONFIG_TABLE_SIZE_INCREASED 0x10
+#define CONFIG_TABLE_SIZE_INCREASED 0x10
UINTN mSmmSystemTableAllocateSize = 0;
@@ -86,7 +86,6 @@ SmmInstallConfigurationTable (
&(ConfigurationTable[Index + 1]),
(gSmmCoreSmst.NumberOfTableEntries - Index) * sizeof (EFI_CONFIGURATION_TABLE)
);
-
} else {
//
// No matching GUIDs were found, so this is an add operation.
@@ -106,7 +105,7 @@ SmmInstallConfigurationTable (
// Allocate a table with one additional entry.
//
mSmmSystemTableAllocateSize += (CONFIG_TABLE_SIZE_INCREASED * sizeof (EFI_CONFIGURATION_TABLE));
- ConfigurationTable = AllocatePool (mSmmSystemTableAllocateSize);
+ ConfigurationTable = AllocatePool (mSmmSystemTableAllocateSize);
if (ConfigurationTable == NULL) {
//
// If a new table could not be allocated, then return an error.
diff --git a/MdeModulePkg/Core/PiSmmCore/Locate.c b/MdeModulePkg/Core/PiSmmCore/Locate.c
index 8458199ec8..2d55362580 100644
--- a/MdeModulePkg/Core/PiSmmCore/Locate.c
+++ b/MdeModulePkg/Core/PiSmmCore/Locate.c
@@ -11,24 +11,24 @@
//
// 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
);
/**
@@ -48,7 +48,7 @@ SmmGetNextLocateAllHandles (
OUT VOID **Interface
)
{
- IHANDLE *Handle;
+ IHANDLE *Handle;
//
// Next handle
@@ -58,11 +58,12 @@ SmmGetNextLocateAllHandles (
//
// 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);
}
+
return Handle;
}
@@ -89,15 +90,15 @@ SmmGetNextLocateByRegisterNotify (
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;
//
@@ -105,11 +106,12 @@ SmmGetNextLocateByRegisterNotify (
//
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;
}
}
+
return Handle;
}
@@ -134,13 +136,13 @@ SmmGetNextLocateByProtocol (
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;
//
@@ -154,8 +156,8 @@ SmmGetNextLocateByProtocol (
//
// 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;
//
@@ -167,6 +169,7 @@ SmmGetNextLocateByProtocol (
break;
}
}
+
return Handle;
}
@@ -194,17 +197,17 @@ SmmLocateProtocol (
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
@@ -223,6 +226,7 @@ SmmLocateProtocol (
if (Position.ProtEntry == NULL) {
return EFI_NOT_FOUND;
}
+
Position.Position = &Position.ProtEntry->Protocols;
Handle = SmmGetNextLocateByProtocol (&Position, Interface);
@@ -237,7 +241,7 @@ SmmLocateProtocol (
// 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;
}
@@ -298,51 +302,54 @@ SmmLocateHandle (
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 = SmmGetNextLocateAllHandles;
- break;
+ case AllHandles:
+ GetNext = SmmGetNextLocateAllHandles;
+ break;
- case ByRegisterNotify:
- GetNext = SmmGetNextLocateByRegisterNotify;
- //
- // Must have SearchKey for locate ByRegisterNotify
- //
- if (SearchKey == NULL) {
- Status = EFI_INVALID_PARAMETER;
- }
- break;
+ case ByRegisterNotify:
+ GetNext = SmmGetNextLocateByRegisterNotify;
+ //
+ // Must have SearchKey for locate ByRegisterNotify
+ //
+ if (SearchKey == NULL) {
+ Status = EFI_INVALID_PARAMETER;
+ }
- case ByProtocol:
- GetNext = SmmGetNextLocateByProtocol;
- if (Protocol == NULL) {
- Status = EFI_INVALID_PARAMETER;
break;
- }
- //
- // Look up the protocol entry and set the head pointer
- //
- Position.ProtEntry = SmmFindProtocolEntry (Protocol, FALSE);
- if (Position.ProtEntry == NULL) {
- Status = EFI_NOT_FOUND;
+
+ case ByProtocol:
+ GetNext = SmmGetNextLocateByProtocol;
+ if (Protocol == NULL) {
+ Status = EFI_INVALID_PARAMETER;
+ break;
+ }
+
+ //
+ // Look up the protocol entry and set the head pointer
+ //
+ Position.ProtEntry = SmmFindProtocolEntry (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;
}
@@ -350,7 +357,7 @@ SmmLocateHandle (
// Enumerate out the matching handles
//
mEfiLocateHandleRequest += 1;
- for (; ;) {
+ for ( ; ;) {
//
// Get the next handle. If no more handles, stop
//
@@ -363,10 +370,10 @@ SmmLocateHandle (
// 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;
}
}
@@ -387,13 +394,13 @@ SmmLocateHandle (
*BufferSize = ResultSize;
- if (SearchType == ByRegisterNotify && !EFI_ERROR(Status)) {
+ if ((SearchType == ByRegisterNotify) && !EFI_ERROR (Status)) {
ASSERT (SearchKey != NULL);
//
// If this is a search by register notify and a handle was
// returned, update the register notification position
//
- ProtNotify = SearchKey;
+ ProtNotify = SearchKey;
ProtNotify->Position = ProtNotify->Position->ForwardLink;
}
}
@@ -444,26 +451,27 @@ SmmLocateHandleBuffer (
return EFI_INVALID_PARAMETER;
}
- BufferSize = 0;
+ BufferSize = 0;
*NumberHandles = 0;
- *Buffer = NULL;
- Status = SmmLocateHandle (
- SearchType,
- Protocol,
- SearchKey,
- &BufferSize,
- *Buffer
- );
+ *Buffer = NULL;
+ Status = SmmLocateHandle (
+ SearchType,
+ Protocol,
+ SearchKey,
+ &BufferSize,
+ *Buffer
+ );
//
// LocateHandleBuffer() returns incorrect status code if SearchType is
// invalid.
//
// Add code to correctly handle expected errors from SmmLocateHandle().
//
- 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;
}
+
return Status;
}
@@ -480,8 +488,8 @@ SmmLocateHandleBuffer (
*Buffer
);
- *NumberHandles = BufferSize / sizeof(EFI_HANDLE);
- if (EFI_ERROR(Status)) {
+ *NumberHandles = BufferSize / sizeof (EFI_HANDLE);
+ if (EFI_ERROR (Status)) {
*NumberHandles = 0;
}
diff --git a/MdeModulePkg/Core/PiSmmCore/MemoryAttributesTable.c b/MdeModulePkg/Core/PiSmmCore/MemoryAttributesTable.c
index 3e8a80dd7d..394fdae507 100644
--- a/MdeModulePkg/Core/PiSmmCore/MemoryAttributesTable.c
+++ b/MdeModulePkg/Core/PiSmmCore/MemoryAttributesTable.c
@@ -25,33 +25,33 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#define PREVIOUS_MEMORY_DESCRIPTOR(MemoryDescriptor, Size) \
((EFI_MEMORY_DESCRIPTOR *)((UINT8 *)(MemoryDescriptor) - (Size)))
-#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;
-#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;
IMAGE_PROPERTIES_PRIVATE_DATA mImagePropertiesPrivateData = {
@@ -63,7 +63,7 @@ IMAGE_PROPERTIES_PRIVATE_DATA mImagePropertiesPrivateData = {
#define EFI_MEMORY_ATTRIBUTES_RUNTIME_MEMORY_PROTECTION_NON_EXECUTABLE_PE_DATA BIT0
-UINT64 mMemoryProtectionAttribute = EFI_MEMORY_ATTRIBUTES_RUNTIME_MEMORY_PROTECTION_NON_EXECUTABLE_PE_DATA;
+UINT64 mMemoryProtectionAttribute = EFI_MEMORY_ATTRIBUTES_RUNTIME_MEMORY_PROTECTION_NON_EXECUTABLE_PE_DATA;
//
// Below functions are for MemoryMap
@@ -82,7 +82,7 @@ UINT64 mMemoryProtectionAttribute = EFI_MEMORY_ATTRIBUTES_RUNTIME_MEMORY_PROTECT
STATIC
UINT64
EfiPagesToSize (
- IN UINT64 Pages
+ IN UINT64 Pages
)
{
return LShiftU64 (Pages, EFI_PAGE_SHIFT);
@@ -102,13 +102,12 @@ EfiPagesToSize (
STATIC
UINT64
EfiSizeToPages (
- IN UINT64 Size
+ IN UINT64 Size
)
{
return RShiftU64 (Size, EFI_PAGE_SHIFT) + ((((UINTN)Size) & EFI_PAGE_MASK) ? 1 : 0);
}
-
/**
Sort memory map entries based upon PhysicalStart, from low to high.
@@ -125,30 +124,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;
}
/**
@@ -170,25 +169,26 @@ 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 {
- MemoryBlockLength = (UINT64) (EfiPagesToSize (MemoryMapEntry->NumberOfPages));
+ MemoryBlockLength = (UINT64)(EfiPagesToSize (MemoryMapEntry->NumberOfPages));
if (((UINTN)NextMemoryMapEntry < (UINTN)MemoryMapEnd) &&
(MemoryMapEntry->Type == NextMemoryMapEntry->Type) &&
(MemoryMapEntry->Attribute == NextMemoryMapEntry->Attribute) &&
- ((MemoryMapEntry->PhysicalStart + MemoryBlockLength) == NextMemoryMapEntry->PhysicalStart)) {
+ ((MemoryMapEntry->PhysicalStart + MemoryBlockLength) == NextMemoryMapEntry->PhysicalStart))
+ {
MemoryMapEntry->NumberOfPages += NextMemoryMapEntry->NumberOfPages;
if (NewMemoryMapEntry != MemoryMapEntry) {
NewMemoryMapEntry->NumberOfPages += NextMemoryMapEntry->NumberOfPages;
@@ -202,13 +202,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;
}
/**
@@ -228,29 +228,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) {
if (MemoryMapEntry->Attribute != 0) {
// It is PE image, the attribute is already set.
} else {
switch (MemoryMapEntry->Type) {
- case EfiRuntimeServicesCode:
- MemoryMapEntry->Attribute = EFI_MEMORY_RO;
- break;
- case EfiRuntimeServicesData:
- default:
- MemoryMapEntry->Attribute |= EFI_MEMORY_XP;
- break;
+ case EfiRuntimeServicesCode:
+ MemoryMapEntry->Attribute = EFI_MEMORY_RO;
+ break;
+ case EfiRuntimeServicesData:
+ default:
+ MemoryMapEntry->Attribute |= EFI_MEMORY_XP;
+ break;
}
}
+
MemoryMapEntry = NEXT_MEMORY_DESCRIPTOR (MemoryMapEntry, DescriptorSize);
}
- return ;
+ return;
}
/**
@@ -268,15 +269,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,
@@ -285,7 +287,8 @@ GetImageRecordByAddress (
);
if ((Buffer <= ImageRecord->ImageBase) &&
- (Buffer + Length >= ImageRecord->ImageBase + ImageRecord->ImageSize)) {
+ (Buffer + Length >= ImageRecord->ImageBase + ImageRecord->ImageSize))
+ {
return ImageRecord;
}
}
@@ -309,43 +312,43 @@ 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;
//
// Always create a new entry for non-PE image record
//
if (ImageRecord->ImageBase > TempRecord.PhysicalStart) {
- NewRecord->Type = TempRecord.Type;
+ NewRecord->Type = TempRecord.Type;
NewRecord->PhysicalStart = TempRecord.PhysicalStart;
NewRecord->VirtualStart = 0;
- NewRecord->NumberOfPages = EfiSizeToPages(ImageRecord->ImageBase - TempRecord.PhysicalStart);
+ NewRecord->NumberOfPages = EfiSizeToPages (ImageRecord->ImageBase - TempRecord.PhysicalStart);
NewRecord->Attribute = TempRecord.Attribute;
- NewRecord = NEXT_MEMORY_DESCRIPTOR (NewRecord, DescriptorSize);
- NewRecordCount ++;
+ NewRecord = NEXT_MEMORY_DESCRIPTOR (NewRecord, DescriptorSize);
+ NewRecordCount++;
TempRecord.PhysicalStart = ImageRecord->ImageBase;
- TempRecord.NumberOfPages = EfiSizeToPages(PhysicalEnd - TempRecord.PhysicalStart);
+ TempRecord.NumberOfPages = EfiSizeToPages (PhysicalEnd - TempRecord.PhysicalStart);
}
ImageRecordCodeSectionList = &ImageRecord->CodeSegmentList;
- ImageRecordCodeSectionLink = ImageRecordCodeSectionList->ForwardLink;
+ ImageRecordCodeSectionLink = ImageRecordCodeSectionList->ForwardLink;
ImageRecordCodeSectionEndLink = ImageRecordCodeSectionList;
while (ImageRecordCodeSectionLink != ImageRecordCodeSectionEndLink) {
ImageRecordCodeSection = CR (
@@ -360,31 +363,31 @@ SetNewRecord (
//
// DATA
//
- NewRecord->Type = EfiRuntimeServicesData;
+ NewRecord->Type = EfiRuntimeServicesData;
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++;
}
//
// CODE
//
- NewRecord->Type = EfiRuntimeServicesCode;
+ NewRecord->Type = EfiRuntimeServicesCode;
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;
}
@@ -397,12 +400,12 @@ SetNewRecord (
// Final DATA
//
if (TempRecord.PhysicalStart < ImageEnd) {
- NewRecord->Type = EfiRuntimeServicesData;
+ NewRecord->Type = EfiRuntimeServicesData;
NewRecord->PhysicalStart = TempRecord.PhysicalStart;
NewRecord->VirtualStart = 0;
NewRecord->NumberOfPages = EfiSizeToPages (ImageEnd - TempRecord.PhysicalStart);
NewRecord->Attribute = TempRecord.Attribute | EFI_MEMORY_XP;
- NewRecordCount ++;
+ NewRecordCount++;
}
return NewRecordCount;
@@ -420,25 +423,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 + 2);
- PhysicalStart = ImageRecord->ImageBase + ImageRecord->ImageSize;
+ PhysicalStart = ImageRecord->ImageBase + ImageRecord->ImageSize;
} while ((ImageRecord != NULL) && (PhysicalStart < PhysicalEnd));
return SplitRecordCount;
@@ -462,19 +466,19 @@ 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;
+ EFI_MEMORY_DESCRIPTOR TempRecord;
+ IMAGE_PROPERTIES_RECORD *ImageRecord;
+ IMAGE_PROPERTIES_RECORD *NewImageRecord;
+ UINT64 PhysicalStart;
+ UINT64 PhysicalEnd;
+ UINTN NewRecordCount;
+ UINTN TotalNewRecordCount;
if (MaxSplitRecordCount == 0) {
CopyMem (NewRecord, OldRecord, DescriptorSize);
@@ -486,9 +490,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 {
@@ -501,28 +505,30 @@ SplitRecord (
//
// Always create a new entry for non-PE image record
//
- NewRecord->Type = TempRecord.Type;
+ NewRecord->Type = TempRecord.Type;
NewRecord->PhysicalStart = TempRecord.PhysicalStart;
NewRecord->VirtualStart = 0;
NewRecord->NumberOfPages = TempRecord.NumberOfPages;
NewRecord->Attribute = TempRecord.Attribute;
- 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));
@@ -590,12 +596,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 + 2) * mImagePropertiesPrivateData.ImageRecordCount;
@@ -608,12 +614,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),
@@ -630,10 +636,12 @@ SplitTable (
(RealSplitRecordCount + 1) * DescriptorSize
);
}
- IndexNew = IndexNew + MaxSplitRecordCount - RealSplitRecordCount;
+
+ IndexNew = IndexNew + MaxSplitRecordCount - RealSplitRecordCount;
TotalSplitRecordCount += RealSplitRecordCount;
- IndexNew --;
+ IndexNew--;
}
+
//
// Move all records to the beginning.
//
@@ -660,7 +668,7 @@ SplitTable (
//
MergeMemoryMap (MemoryMap, MemoryMapSize, DescriptorSize);
- return ;
+ return;
}
/**
@@ -724,7 +732,7 @@ SmmCoreGetMemoryMapMemoryAttributesTable (
AdditionalRecordCount = (2 * mImagePropertiesPrivateData.CodeSegmentCountMax + 2) * mImagePropertiesPrivateData.ImageRecordCount;
OldMemoryMapSize = *MemoryMapSize;
- Status = SmmCoreGetMemoryMap (MemoryMapSize, MemoryMap, MapKey, DescriptorSize, DescriptorVersion);
+ Status = SmmCoreGetMemoryMap (MemoryMapSize, MemoryMap, MapKey, DescriptorSize, DescriptorVersion);
if (Status == EFI_BUFFER_TOO_SMALL) {
*MemoryMapSize = *MemoryMapSize + (*DescriptorSize) * AdditionalRecordCount;
} else if (Status == EFI_SUCCESS) {
@@ -738,7 +746,7 @@ SmmCoreGetMemoryMapMemoryAttributesTable (
//
// Split PE code/data
//
- ASSERT(MemoryMap != NULL);
+ ASSERT (MemoryMap != NULL);
SplitTable (MemoryMapSize, MemoryMap, *DescriptorSize);
}
}
@@ -762,7 +770,8 @@ SetMemoryAttributesTableSectionAlignment (
)
{
if (((SectionAlignment & (RUNTIME_PAGE_ALLOCATION_GRANULARITY - 1)) != 0) &&
- ((mMemoryProtectionAttribute & EFI_MEMORY_ATTRIBUTES_RUNTIME_MEMORY_PROTECTION_NON_EXECUTABLE_PE_DATA) != 0)) {
+ ((mMemoryProtectionAttribute & EFI_MEMORY_ATTRIBUTES_RUNTIME_MEMORY_PROTECTION_NON_EXECUTABLE_PE_DATA) != 0))
+ {
DEBUG ((DEBUG_VERBOSE, "SMM SetMemoryAttributesTableSectionAlignment - Clear\n"));
mMemoryProtectionAttribute &= ~((UINT64)EFI_MEMORY_ATTRIBUTES_RUNTIME_MEMORY_PROTECTION_NON_EXECUTABLE_PE_DATA);
}
@@ -777,11 +786,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;
@@ -801,21 +810,21 @@ SwapImageRecordCodeSection (
STATIC
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,
@@ -833,10 +842,11 @@ SortImageRecordCodeSection (
if (ImageRecordCodeSection->CodeSegmentBase > NextImageRecordCodeSection->CodeSegmentBase) {
SwapImageRecordCodeSection (ImageRecordCodeSection, NextImageRecordCodeSection);
}
+
NextImageRecordCodeSectionLink = NextImageRecordCodeSectionLink->ForwardLink;
}
- ImageRecordCodeSectionLink = ImageRecordCodeSectionLink->ForwardLink;
+ ImageRecordCodeSectionLink = ImageRecordCodeSectionLink->ForwardLink;
NextImageRecordCodeSectionLink = ImageRecordCodeSectionLink->ForwardLink;
}
}
@@ -852,22 +862,22 @@ SortImageRecordCodeSection (
STATIC
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, "SMM 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,
@@ -878,15 +888,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;
@@ -909,22 +923,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);
@@ -939,18 +953,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,
@@ -968,10 +982,11 @@ SortImageRecord (
if (ImageRecord->ImageBase > NextImageRecord->ImageBase) {
SwapImageRecord (ImageRecord, NextImageRecord);
}
+
NextImageRecordLink = NextImageRecordLink->ForwardLink;
}
- ImageRecordLink = ImageRecordLink->ForwardLink;
+ ImageRecordLink = ImageRecordLink->ForwardLink;
NextImageRecordLink = ImageRecordLink->ForwardLink;
}
}
@@ -985,16 +1000,17 @@ DumpImageRecord (
VOID
)
{
- IMAGE_PROPERTIES_RECORD *ImageRecord;
- LIST_ENTRY *ImageRecordLink;
- LIST_ENTRY *ImageRecordList;
- UINTN Index;
+ IMAGE_PROPERTIES_RECORD *ImageRecord;
+ LIST_ENTRY *ImageRecordLink;
+ LIST_ENTRY *ImageRecordList;
+ UINTN Index;
ImageRecordList = &mImagePropertiesPrivateData.ImageRecordList;
- for (ImageRecordLink = ImageRecordList->ForwardLink, Index= 0;
+ for (ImageRecordLink = ImageRecordList->ForwardLink, Index = 0;
ImageRecordLink != ImageRecordList;
- ImageRecordLink = ImageRecordLink->ForwardLink, Index++) {
+ ImageRecordLink = ImageRecordLink->ForwardLink, Index++)
+ {
ImageRecord = CR (
ImageRecordLink,
IMAGE_PROPERTIES_RECORD,
@@ -1015,25 +1031,26 @@ SmmInsertImageRecord (
IN EFI_SMM_DRIVER_ENTRY *DriverEntry
)
{
- 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, "SMM InsertImageRecord - 0x%x\n", DriverEntry));
DEBUG ((DEBUG_VERBOSE, "SMM InsertImageRecord - 0x%016lx - 0x%08x\n", DriverEntry->ImageBuffer, DriverEntry->NumberOfPage));
- ImageRecord = AllocatePool (sizeof(*ImageRecord));
+ ImageRecord = AllocatePool (sizeof (*ImageRecord));
if (ImageRecord == NULL) {
- return ;
+ return;
}
+
ImageRecord->Signature = IMAGE_PROPERTIES_RECORD_SIGNATURE;
DEBUG ((DEBUG_VERBOSE, "SMM ImageRecordCount - 0x%x\n", mImagePropertiesPrivateData.ImageRecordCount));
@@ -1042,11 +1059,11 @@ SmmInsertImageRecord (
// Step 1: record whole region
//
ImageRecord->ImageBase = DriverEntry->ImageBuffer;
- ImageRecord->ImageSize = EfiPagesToSize(DriverEntry->NumberOfPage);
+ ImageRecord->ImageSize = EfiPagesToSize (DriverEntry->NumberOfPage);
ImageAddress = (VOID *)(UINTN)DriverEntry->ImageBuffer;
- PdbPointer = PeCoffLoaderGetPdbPointer ((VOID*) (UINTN) ImageAddress);
+ PdbPointer = PeCoffLoaderGetPdbPointer ((VOID *)(UINTN)ImageAddress);
if (PdbPointer != NULL) {
DEBUG ((DEBUG_VERBOSE, "SMM Image - %a\n", PdbPointer));
}
@@ -1054,13 +1071,13 @@ SmmInsertImageRecord (
//
// 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, "SMM Hdr.Pe32->Signature invalid - 0x%x\n", Hdr.Pe32->Signature));
goto Finish;
@@ -1070,29 +1087,34 @@ SmmInsertImageRecord (
// 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, "SMM !!!!!!!! InsertImageRecord - Section Alignment(0x%x) is not %dK !!!!!!!!\n",
- SectionAlignment, RUNTIME_PAGE_ALLOCATION_GRANULARITY >> 10));
- PdbPointer = PeCoffLoaderGetPdbPointer ((VOID*) (UINTN) ImageAddress);
+ DEBUG ((
+ DEBUG_WARN,
+ "SMM !!!!!!!! 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, "SMM !!!!!!!! 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++) {
@@ -1124,10 +1146,11 @@ SmmInsertImageRecord (
//
// 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;
@@ -1143,10 +1166,11 @@ SmmInsertImageRecord (
if (ImageRecord->CodeSegmentCount == 0) {
SetMemoryAttributesTableSectionAlignment (1);
DEBUG ((DEBUG_ERROR, "SMM !!!!!!!! InsertImageRecord - CodeSegmentCount is 0 !!!!!!!!\n"));
- PdbPointer = PeCoffLoaderGetPdbPointer ((VOID*) (UINTN) ImageAddress);
+ PdbPointer = PeCoffLoaderGetPdbPointer ((VOID *)(UINTN)ImageAddress);
if (PdbPointer != NULL) {
DEBUG ((DEBUG_ERROR, "SMM !!!!!!!! Image - %a !!!!!!!!\n", PdbPointer));
}
+
goto Finish;
}
@@ -1172,10 +1196,9 @@ SmmInsertImageRecord (
SortImageRecord ();
Finish:
- return ;
+ return;
}
-
/**
Publish MemoryAttributesTable to SMM configuration table.
**/
@@ -1184,27 +1207,27 @@ PublishMemoryAttributesTable (
VOID
)
{
- UINTN MemoryMapSize;
- EFI_MEMORY_DESCRIPTOR *MemoryMap;
- UINTN MapKey;
- UINTN DescriptorSize;
- UINT32 DescriptorVersion;
- UINTN Index;
- EFI_STATUS Status;
- UINTN RuntimeEntryCount;
- EDKII_PI_SMM_MEMORY_ATTRIBUTES_TABLE *MemoryAttributesTable;
- EFI_MEMORY_DESCRIPTOR *MemoryAttributesEntry;
- UINTN MemoryAttributesTableSize;
+ UINTN MemoryMapSize;
+ EFI_MEMORY_DESCRIPTOR *MemoryMap;
+ UINTN MapKey;
+ UINTN DescriptorSize;
+ UINT32 DescriptorVersion;
+ UINTN Index;
+ EFI_STATUS Status;
+ UINTN RuntimeEntryCount;
+ EDKII_PI_SMM_MEMORY_ATTRIBUTES_TABLE *MemoryAttributesTable;
+ EFI_MEMORY_DESCRIPTOR *MemoryAttributesEntry;
+ UINTN MemoryAttributesTableSize;
MemoryMapSize = 0;
- MemoryMap = NULL;
- Status = SmmCoreGetMemoryMapMemoryAttributesTable (
- &MemoryMapSize,
- MemoryMap,
- &MapKey,
- &DescriptorSize,
- &DescriptorVersion
- );
+ MemoryMap = NULL;
+ Status = SmmCoreGetMemoryMapMemoryAttributesTable (
+ &MemoryMapSize,
+ MemoryMap,
+ &MapKey,
+ &DescriptorSize,
+ &DescriptorVersion
+ );
ASSERT (Status == EFI_BUFFER_TOO_SMALL);
do {
@@ -1228,9 +1251,9 @@ PublishMemoryAttributesTable (
//
// Allocate MemoryAttributesTable
//
- RuntimeEntryCount = MemoryMapSize/DescriptorSize;
- MemoryAttributesTableSize = sizeof(EDKII_PI_SMM_MEMORY_ATTRIBUTES_TABLE) + DescriptorSize * RuntimeEntryCount;
- MemoryAttributesTable = AllocatePool (sizeof(EDKII_PI_SMM_MEMORY_ATTRIBUTES_TABLE) + DescriptorSize * RuntimeEntryCount);
+ RuntimeEntryCount = MemoryMapSize/DescriptorSize;
+ MemoryAttributesTableSize = sizeof (EDKII_PI_SMM_MEMORY_ATTRIBUTES_TABLE) + DescriptorSize * RuntimeEntryCount;
+ MemoryAttributesTable = AllocatePool (sizeof (EDKII_PI_SMM_MEMORY_ATTRIBUTES_TABLE) + DescriptorSize * RuntimeEntryCount);
ASSERT (MemoryAttributesTable != NULL);
MemoryAttributesTable->Version = EDKII_PI_SMM_MEMORY_ATTRIBUTES_TABLE_VERSION;
MemoryAttributesTable->NumberOfEntries = (UINT32)RuntimeEntryCount;
@@ -1249,16 +1272,15 @@ PublishMemoryAttributesTable (
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);
+ MemoryAttributesEntry = NEXT_MEMORY_DESCRIPTOR (MemoryAttributesEntry, DescriptorSize);
- MemoryMap = NEXT_MEMORY_DESCRIPTOR(MemoryMap, DescriptorSize);
+ MemoryMap = NEXT_MEMORY_DESCRIPTOR (MemoryMap, DescriptorSize);
}
Status = gSmst->SmmInstallConfigurationTable (gSmst, &gEdkiiPiSmmMemoryAttributesTableGuid, MemoryAttributesTable, MemoryAttributesTableSize);
ASSERT_EFI_ERROR (Status);
}
-
/**
This function installs all SMM image record information.
**/
@@ -1267,12 +1289,12 @@ SmmInstallImageRecord (
VOID
)
{
- EFI_STATUS Status;
- UINTN NoHandles;
- EFI_HANDLE *HandleBuffer;
- EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;
- UINTN Index;
- EFI_SMM_DRIVER_ENTRY DriverEntry;
+ EFI_STATUS Status;
+ UINTN NoHandles;
+ EFI_HANDLE *HandleBuffer;
+ EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;
+ UINTN Index;
+ EFI_SMM_DRIVER_ENTRY DriverEntry;
Status = SmmLocateHandleBuffer (
ByProtocol,
@@ -1282,7 +1304,7 @@ SmmInstallImageRecord (
&HandleBuffer
);
if (EFI_ERROR (Status)) {
- return ;
+ return;
}
for (Index = 0; Index < NoHandles; Index++) {
@@ -1294,18 +1316,19 @@ SmmInstallImageRecord (
if (EFI_ERROR (Status)) {
continue;
}
+
DEBUG ((DEBUG_VERBOSE, "LoadedImage - 0x%x 0x%x ", LoadedImage->ImageBase, LoadedImage->ImageSize));
{
- VOID *PdbPointer;
+ VOID *PdbPointer;
PdbPointer = PeCoffLoaderGetPdbPointer (LoadedImage->ImageBase);
if (PdbPointer != NULL) {
DEBUG ((DEBUG_VERBOSE, "(%a) ", PdbPointer));
}
}
DEBUG ((DEBUG_VERBOSE, "\n"));
- ZeroMem (&DriverEntry, sizeof(DriverEntry));
+ ZeroMem (&DriverEntry, sizeof (DriverEntry));
DriverEntry.ImageBuffer = (UINTN)LoadedImage->ImageBase;
- DriverEntry.NumberOfPage = EFI_SIZE_TO_PAGES((UINTN)LoadedImage->ImageSize);
+ DriverEntry.NumberOfPage = EFI_SIZE_TO_PAGES ((UINTN)LoadedImage->ImageSize);
SmmInsertImageRecord (&DriverEntry);
}
@@ -1354,8 +1377,8 @@ SmmCoreInitializeMemoryAttributesTable (
VOID
)
{
- EFI_STATUS Status;
- VOID *Registration;
+ EFI_STATUS Status;
+ VOID *Registration;
Status = gSmst->SmmRegisterProtocolNotify (
&gEfiSmmEndOfDxeProtocolGuid,
@@ -1364,5 +1387,5 @@ SmmCoreInitializeMemoryAttributesTable (
);
ASSERT_EFI_ERROR (Status);
- return ;
+ return;
}
diff --git a/MdeModulePkg/Core/PiSmmCore/Notify.c b/MdeModulePkg/Core/PiSmmCore/Notify.c
index 8e078f7572..7d5bff2576 100644
--- a/MdeModulePkg/Core/PiSmmCore/Notify.c
+++ b/MdeModulePkg/Core/PiSmmCore/Notify.c
@@ -24,8 +24,8 @@ SmmNotifyProtocol (
LIST_ENTRY *Link;
ProtEntry = Prot->Protocol;
- 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);
ProtNotify->Function (&ProtEntry->ProtocolID, Prot->Interface, Prot->Handle);
}
}
@@ -54,14 +54,13 @@ SmmRemoveInterfaceFromProtocol (
Prot = SmmFindProtocolInterface (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;
@@ -105,7 +104,7 @@ SmmRegisterProtocolNotify (
LIST_ENTRY *Link;
EFI_STATUS Status;
- if (Protocol == NULL || Registration == NULL) {
+ if ((Protocol == NULL) || (Registration == NULL)) {
return EFI_INVALID_PARAMETER;
}
@@ -113,16 +112,17 @@ SmmRegisterProtocolNotify (
//
// Get the protocol entry per Protocol
//
- ProtEntry = SmmFindProtocolEntry ((EFI_GUID *) Protocol, FALSE);
+ ProtEntry = SmmFindProtocolEntry ((EFI_GUID *)Protocol, FALSE);
if (ProtEntry != NULL) {
- ProtNotify = (PROTOCOL_NOTIFY * )*Registration;
+ ProtNotify = (PROTOCOL_NOTIFY *)*Registration;
for (Link = ProtEntry->Notify.ForwardLink;
Link != &ProtEntry->Notify;
- Link = Link->ForwardLink) {
+ Link = Link->ForwardLink)
+ {
//
// Compare the notification record
//
- if (ProtNotify == (CR(Link, PROTOCOL_NOTIFY, Link, PROTOCOL_NOTIFY_SIGNATURE))){
+ if (ProtNotify == (CR (Link, PROTOCOL_NOTIFY, Link, PROTOCOL_NOTIFY_SIGNATURE))) {
//
// If Registration is an existing registration, then unhook it
//
@@ -133,6 +133,7 @@ SmmRegisterProtocolNotify (
}
}
}
+
//
// If the registration is not found
//
@@ -144,19 +145,19 @@ SmmRegisterProtocolNotify (
//
// Get the protocol entry to add the notification too
//
- ProtEntry = SmmFindProtocolEntry ((EFI_GUID *) Protocol, TRUE);
+ ProtEntry = SmmFindProtocolEntry ((EFI_GUID *)Protocol, TRUE);
if (ProtEntry != NULL) {
//
// Find whether notification already exist
//
for (Link = ProtEntry->Notify.ForwardLink;
Link != &ProtEntry->Notify;
- Link = Link->ForwardLink) {
-
- ProtNotify = CR(Link, PROTOCOL_NOTIFY, Link, PROTOCOL_NOTIFY_SIGNATURE);
+ Link = Link->ForwardLink)
+ {
+ ProtNotify = CR (Link, PROTOCOL_NOTIFY, Link, PROTOCOL_NOTIFY_SIGNATURE);
if (CompareGuid (&ProtNotify->Protocol->ProtocolID, Protocol) &&
- (ProtNotify->Function == Function)) {
-
+ (ProtNotify->Function == Function))
+ {
//
// Notification already exist
//
@@ -169,11 +170,11 @@ SmmRegisterProtocolNotify (
//
// Allocate a new notification record
//
- ProtNotify = AllocatePool (sizeof(PROTOCOL_NOTIFY));
+ ProtNotify = AllocatePool (sizeof (PROTOCOL_NOTIFY));
if (ProtNotify != NULL) {
ProtNotify->Signature = PROTOCOL_NOTIFY_SIGNATURE;
- ProtNotify->Protocol = ProtEntry;
- ProtNotify->Function = Function;
+ ProtNotify->Protocol = ProtEntry;
+ ProtNotify->Function = Function;
//
// Start at the ending
//
@@ -190,7 +191,8 @@ SmmRegisterProtocolNotify (
Status = EFI_OUT_OF_RESOURCES;
if (ProtNotify != NULL) {
*Registration = ProtNotify;
- Status = EFI_SUCCESS;
+ Status = EFI_SUCCESS;
}
+
return Status;
}
diff --git a/MdeModulePkg/Core/PiSmmCore/Page.c b/MdeModulePkg/Core/PiSmmCore/Page.c
index d886187d9a..255964c23a 100644
--- a/MdeModulePkg/Core/PiSmmCore/Page.c
+++ b/MdeModulePkg/Core/PiSmmCore/Page.c
@@ -17,36 +17,34 @@ LIST_ENTRY mSmmMemoryMap = INITIALIZE_LIST_HEAD_VARIABLE (mSmmMemoryMap);
// For GetMemoryMap()
//
-#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 FromStack;
- EFI_MEMORY_TYPE Type;
- UINT64 Start;
- UINT64 End;
+ UINTN Signature;
+ LIST_ENTRY Link;
+ BOOLEAN FromStack;
+ EFI_MEMORY_TYPE Type;
+ UINT64 Start;
+ UINT64 End;
} MEMORY_MAP;
-LIST_ENTRY gMemoryMap = INITIALIZE_LIST_HEAD_VARIABLE (gMemoryMap);
-
+LIST_ENTRY gMemoryMap = INITIALIZE_LIST_HEAD_VARIABLE (gMemoryMap);
-#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);
+LIST_ENTRY mFreeMemoryMapEntryList = INITIALIZE_LIST_HEAD_VARIABLE (mFreeMemoryMapEntryList);
/**
Allocates pages from the memory map.
@@ -91,16 +89,16 @@ AllocateMemoryMapEntry (
VOID
)
{
- EFI_PHYSICAL_ADDRESS Mem;
- EFI_STATUS Status;
- MEMORY_MAP* FreeDescriptorEntries;
- MEMORY_MAP* Entry;
- UINTN Index;
+ EFI_PHYSICAL_ADDRESS Mem;
+ EFI_STATUS Status;
+ MEMORY_MAP *FreeDescriptorEntries;
+ MEMORY_MAP *Entry;
+ UINTN Index;
- //DEBUG((DEBUG_INFO, "AllocateMemoryMapEntry\n"));
+ // DEBUG((DEBUG_INFO, "AllocateMemoryMapEntry\n"));
if (IsListEmpty (&mFreeMemoryMapEntryList)) {
- //DEBUG((DEBUG_INFO, "mFreeMemoryMapEntryList is empty\n"));
+ // DEBUG((DEBUG_INFO, "mFreeMemoryMapEntryList is empty\n"));
//
// The list is empty, to allocate one page to refuel the list
//
@@ -113,13 +111,13 @@ AllocateMemoryMapEntry (
FALSE
);
ASSERT_EFI_ERROR (Status);
- if(!EFI_ERROR (Status)) {
+ if (!EFI_ERROR (Status)) {
FreeDescriptorEntries = (MEMORY_MAP *)(UINTN)Mem;
- //DEBUG((DEBUG_INFO, "New FreeDescriptorEntries - 0x%x\n", FreeDescriptorEntries));
+ // DEBUG((DEBUG_INFO, "New FreeDescriptorEntries - 0x%x\n", FreeDescriptorEntries));
//
// Enqueue the free memory map entries into the list
//
- for (Index = 0; Index< RUNTIME_PAGE_ALLOCATION_GRANULARITY / sizeof(MEMORY_MAP); Index++) {
+ for (Index = 0; Index < RUNTIME_PAGE_ALLOCATION_GRANULARITY / sizeof (MEMORY_MAP); Index++) {
FreeDescriptorEntries[Index].Signature = MEMORY_MAP_SIGNATURE;
InsertTailList (&mFreeMemoryMapEntryList, &FreeDescriptorEntries[Index].Link);
}
@@ -127,6 +125,7 @@ AllocateMemoryMapEntry (
return NULL;
}
}
+
//
// dequeue the first descriptor from the list
//
@@ -136,7 +135,6 @@ AllocateMemoryMapEntry (
return Entry;
}
-
/**
Internal function. Moves any memory descriptors that are on the
temporary descriptor stack to heap.
@@ -147,14 +145,14 @@ CoreFreeMemoryMapStack (
VOID
)
{
- MEMORY_MAP *Entry;
+ MEMORY_MAP *Entry;
//
// If already freeing the map stack, then return
//
if (mFreeMapStack != 0) {
ASSERT (FALSE);
- return ;
+ return;
}
//
@@ -175,8 +173,7 @@ CoreFreeMemoryMapStack (
mMapDepth -= 1;
if (mMapStack[mMapDepth].Link.ForwardLink != NULL) {
-
- CopyMem (Entry , &mMapStack[mMapDepth], sizeof (MEMORY_MAP));
+ CopyMem (Entry, &mMapStack[mMapDepth], sizeof (MEMORY_MAP));
Entry->FromStack = FALSE;
//
@@ -203,25 +200,25 @@ CoreFreeMemoryMapStack (
**/
VOID
InsertNewEntry (
- IN LIST_ENTRY *Link,
- IN UINT64 Start,
- IN UINT64 End,
- IN EFI_MEMORY_TYPE Type,
- IN BOOLEAN Next,
- IN BOOLEAN AddRegion
+ IN LIST_ENTRY *Link,
+ IN UINT64 Start,
+ IN UINT64 End,
+ IN EFI_MEMORY_TYPE Type,
+ IN BOOLEAN Next,
+ IN BOOLEAN AddRegion
)
{
MEMORY_MAP *Entry;
- Entry = &mMapStack[mMapDepth];
+ Entry = &mMapStack[mMapDepth];
mMapDepth += 1;
ASSERT (mMapDepth < MAX_MAP_DEPTH);
Entry->FromStack = TRUE;
Entry->Signature = MEMORY_MAP_SIGNATURE;
- Entry->Type = Type;
- Entry->Start = Start;
- Entry->End = End;
+ Entry->Type = Type;
+ Entry->Start = Start;
+ Entry->End = End;
if (Next) {
InsertHeadList (Link, &Entry->Link);
} else {
@@ -263,17 +260,17 @@ ConvertSmmMemoryMapEntry (
IN BOOLEAN AddRegion
)
{
- LIST_ENTRY *Link;
- MEMORY_MAP *Entry;
- MEMORY_MAP *NextEntry;
- LIST_ENTRY *NextLink;
- MEMORY_MAP *PreviousEntry;
- LIST_ENTRY *PreviousLink;
- EFI_PHYSICAL_ADDRESS Start;
- EFI_PHYSICAL_ADDRESS End;
+ LIST_ENTRY *Link;
+ MEMORY_MAP *Entry;
+ MEMORY_MAP *NextEntry;
+ LIST_ENTRY *NextLink;
+ MEMORY_MAP *PreviousEntry;
+ LIST_ENTRY *PreviousLink;
+ EFI_PHYSICAL_ADDRESS Start;
+ EFI_PHYSICAL_ADDRESS End;
Start = Memory;
- End = Memory + EFI_PAGES_TO_SIZE(NumberOfPages) - 1;
+ End = Memory + EFI_PAGES_TO_SIZE (NumberOfPages) - 1;
//
// Exclude memory region
@@ -296,8 +293,9 @@ ConvertSmmMemoryMapEntry (
if (Entry->Start > End) {
if ((Entry->Start == End + 1) && (Entry->Type == Type)) {
Entry->Start = Start;
- return ;
+ return;
}
+
InsertNewEntry (
&Entry->Link,
Start,
@@ -306,7 +304,7 @@ ConvertSmmMemoryMapEntry (
FALSE,
AddRegion
);
- return ;
+ return;
}
if ((Entry->Start <= Start) && (Entry->End >= End)) {
@@ -331,6 +329,7 @@ ConvertSmmMemoryMapEntry (
AddRegion
);
}
+
if (Entry->End > End) {
//
// ---------------------------------------------------
@@ -351,12 +350,13 @@ ConvertSmmMemoryMapEntry (
AddRegion
);
}
+
//
// Update this node
//
Entry->Start = Start;
- Entry->End = End;
- Entry->Type = Type;
+ Entry->End = End;
+ Entry->Type = Type;
//
// Check adjacent
@@ -375,6 +375,7 @@ ConvertSmmMemoryMapEntry (
RemoveOldEntry (NextEntry);
}
}
+
PreviousLink = Entry->Link.BackLink;
if (PreviousLink != &gMemoryMap) {
PreviousEntry = CR (PreviousLink, MEMORY_MAP, Link, MEMORY_MAP_SIGNATURE);
@@ -390,7 +391,8 @@ ConvertSmmMemoryMapEntry (
}
}
}
- return ;
+
+ return;
}
}
@@ -409,9 +411,10 @@ ConvertSmmMemoryMapEntry (
Entry = CR (Link, MEMORY_MAP, Link, MEMORY_MAP_SIGNATURE);
if ((Entry->End + 1 == Start) && (Entry->Type == Type)) {
Entry->End = End;
- return ;
+ return;
}
}
+
InsertNewEntry (
&gMemoryMap,
Start,
@@ -420,7 +423,7 @@ ConvertSmmMemoryMapEntry (
FALSE,
AddRegion
);
- return ;
+ return;
}
/**
@@ -433,20 +436,19 @@ GetSmmMemoryMapEntryCount (
VOID
)
{
- LIST_ENTRY *Link;
- UINTN Count;
+ LIST_ENTRY *Link;
+ UINTN Count;
Count = 0;
- Link = gMemoryMap.ForwardLink;
+ Link = gMemoryMap.ForwardLink;
while (Link != &gMemoryMap) {
- Link = Link->ForwardLink;
+ Link = Link->ForwardLink;
Count++;
}
+
return Count;
}
-
-
/**
Internal Function. Allocate n pages from given free page node.
@@ -472,10 +474,11 @@ InternalAllocPagesOnOneNode (
if (Top > Pages->NumberOfPages) {
Top = Pages->NumberOfPages;
}
+
Bottom = Top - NumberOfPages;
if (Top < Pages->NumberOfPages) {
- Node = (FREE_PAGE_LIST*)((UINTN)Pages + EFI_PAGES_TO_SIZE (Top));
+ Node = (FREE_PAGE_LIST *)((UINTN)Pages + EFI_PAGES_TO_SIZE (Top));
Node->NumberOfPages = Pages->NumberOfPages - Top;
InsertHeadList (&Pages->Link, &Node->Link);
}
@@ -511,11 +514,13 @@ InternalAllocMaxAddress (
for (Node = FreePageList->BackLink; Node != FreePageList; Node = Node->BackLink) {
Pages = BASE_CR (Node, FREE_PAGE_LIST, Link);
- if (Pages->NumberOfPages >= NumberOfPages &&
- (UINTN)Pages + EFI_PAGES_TO_SIZE (NumberOfPages) - 1 <= MaxAddress) {
+ if ((Pages->NumberOfPages >= NumberOfPages) &&
+ ((UINTN)Pages + EFI_PAGES_TO_SIZE (NumberOfPages) - 1 <= MaxAddress))
+ {
return InternalAllocPagesOnOneNode (Pages, NumberOfPages, MaxAddress);
}
}
+
return (UINTN)(-1);
}
@@ -545,15 +550,17 @@ InternalAllocAddress (
}
EndAddress = Address + EFI_PAGES_TO_SIZE (NumberOfPages);
- for (Node = FreePageList->BackLink; Node!= FreePageList; Node = Node->BackLink) {
+ for (Node = FreePageList->BackLink; Node != FreePageList; Node = Node->BackLink) {
Pages = BASE_CR (Node, FREE_PAGE_LIST, Link);
if ((UINTN)Pages <= Address) {
if ((UINTN)Pages + EFI_PAGES_TO_SIZE (Pages->NumberOfPages) < EndAddress) {
break;
}
+
return InternalAllocPagesOnOneNode (Pages, NumberOfPages, EndAddress);
}
}
+
return ~Address;
}
@@ -588,8 +595,9 @@ SmmInternalAllocatePagesEx (
{
UINTN RequestedAddress;
- if (MemoryType != EfiRuntimeServicesCode &&
- MemoryType != EfiRuntimeServicesData) {
+ if ((MemoryType != EfiRuntimeServicesCode) &&
+ (MemoryType != EfiRuntimeServicesData))
+ {
return EFI_INVALID_PARAMETER;
}
@@ -607,11 +615,11 @@ SmmInternalAllocatePagesEx (
case AllocateMaxAddress:
if (NeedGuard) {
*Memory = InternalAllocMaxAddressWithGuard (
- &mSmmMemoryMap,
- NumberOfPages,
- RequestedAddress,
- MemoryType
- );
+ &mSmmMemoryMap,
+ NumberOfPages,
+ RequestedAddress,
+ MemoryType
+ );
if (*Memory == (UINTN)-1) {
return EFI_OUT_OF_RESOURCES;
} else {
@@ -628,6 +636,7 @@ SmmInternalAllocatePagesEx (
if (*Memory == (UINTN)-1) {
return EFI_OUT_OF_RESOURCES;
}
+
break;
case AllocateAddress:
*Memory = InternalAllocAddress (
@@ -638,6 +647,7 @@ SmmInternalAllocatePagesEx (
if (*Memory != RequestedAddress) {
return EFI_NOT_FOUND;
}
+
break;
default:
return EFI_INVALID_PARAMETER;
@@ -648,7 +658,7 @@ SmmInternalAllocatePagesEx (
//
ConvertSmmMemoryMapEntry (MemoryType, *Memory, NumberOfPages, AddRegion);
if (!AddRegion) {
- CoreFreeMemoryMapStack();
+ CoreFreeMemoryMapStack ();
}
return EFI_SUCCESS;
@@ -682,8 +692,14 @@ SmmInternalAllocatePages (
IN BOOLEAN NeedGuard
)
{
- return SmmInternalAllocatePagesEx (Type, MemoryType, NumberOfPages, Memory,
- FALSE, NeedGuard);
+ return SmmInternalAllocatePagesEx (
+ Type,
+ MemoryType,
+ NumberOfPages,
+ Memory,
+ FALSE,
+ NeedGuard
+ );
}
/**
@@ -715,18 +731,24 @@ SmmAllocatePages (
BOOLEAN NeedGuard;
NeedGuard = IsPageTypeToGuard (MemoryType, Type);
- Status = SmmInternalAllocatePages (Type, MemoryType, NumberOfPages, Memory,
- NeedGuard);
+ Status = SmmInternalAllocatePages (
+ Type,
+ MemoryType,
+ NumberOfPages,
+ Memory,
+ NeedGuard
+ );
if (!EFI_ERROR (Status)) {
SmmCoreUpdateProfile (
- (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
);
}
+
return Status;
}
@@ -747,13 +769,15 @@ InternalMergeNodes (
Next = BASE_CR (First->Link.ForwardLink, FREE_PAGE_LIST, Link);
ASSERT (
- TRUNCATE_TO_PAGES ((UINTN)Next - (UINTN)First) >= First->NumberOfPages);
+ TRUNCATE_TO_PAGES ((UINTN)Next - (UINTN)First) >= First->NumberOfPages
+ );
if (TRUNCATE_TO_PAGES ((UINTN)Next - (UINTN)First) == First->NumberOfPages) {
First->NumberOfPages += Next->NumberOfPages;
RemoveEntryList (&Next->Link);
Next = First;
}
+
return Next;
}
@@ -784,17 +808,19 @@ SmmInternalFreePagesEx (
}
Pages = NULL;
- Node = mSmmMemoryMap.ForwardLink;
+ Node = mSmmMemoryMap.ForwardLink;
while (Node != &mSmmMemoryMap) {
Pages = BASE_CR (Node, FREE_PAGE_LIST, Link);
if (Memory < (UINTN)Pages) {
break;
}
+
Node = Node->ForwardLink;
}
- if (Node != &mSmmMemoryMap &&
- Memory + EFI_PAGES_TO_SIZE (NumberOfPages) > (UINTN)Pages) {
+ if ((Node != &mSmmMemoryMap) &&
+ (Memory + EFI_PAGES_TO_SIZE (NumberOfPages) > (UINTN)Pages))
+ {
return EFI_INVALID_PARAMETER;
}
@@ -805,7 +831,7 @@ SmmInternalFreePagesEx (
}
}
- Pages = (FREE_PAGE_LIST*)(UINTN)Memory;
+ Pages = (FREE_PAGE_LIST *)(UINTN)Memory;
Pages->NumberOfPages = NumberOfPages;
InsertTailList (Node, &Pages->Link);
@@ -824,7 +850,7 @@ SmmInternalFreePagesEx (
//
ConvertSmmMemoryMapEntry (EfiConventionalMemory, Memory, NumberOfPages, AddRegion);
if (!AddRegion) {
- CoreFreeMemoryMapStack();
+ CoreFreeMemoryMapStack ();
}
return EFI_SUCCESS;
@@ -853,6 +879,7 @@ SmmInternalFreePages (
if (IsGuarded) {
return SmmInternalFreePagesExWithGuard (Memory, NumberOfPages, FALSE);
}
+
return SmmInternalFreePagesEx (Memory, NumberOfPages, FALSE);
}
@@ -872,9 +899,9 @@ InMemMap (
IN UINTN NumberOfPages
)
{
- LIST_ENTRY *Link;
- MEMORY_MAP *Entry;
- EFI_PHYSICAL_ADDRESS Last;
+ LIST_ENTRY *Link;
+ MEMORY_MAP *Entry;
+ EFI_PHYSICAL_ADDRESS Last;
Last = Memory + EFI_PAGES_TO_SIZE (NumberOfPages) - 1;
@@ -912,22 +939,23 @@ SmmFreePages (
EFI_STATUS Status;
BOOLEAN IsGuarded;
- if (!InMemMap(Memory, NumberOfPages)) {
+ if (!InMemMap (Memory, NumberOfPages)) {
return EFI_NOT_FOUND;
}
IsGuarded = IsHeapGuardEnabled () && IsMemoryGuarded (Memory);
- Status = SmmInternalFreePages (Memory, NumberOfPages, IsGuarded);
+ Status = SmmInternalFreePages (Memory, NumberOfPages, IsGuarded);
if (!EFI_ERROR (Status)) {
SmmCoreUpdateProfile (
- (EFI_PHYSICAL_ADDRESS) (UINTN) RETURN_ADDRESS (0),
+ (EFI_PHYSICAL_ADDRESS)(UINTN)RETURN_ADDRESS (0),
MemoryProfileActionFreePages,
EfiMaxMemoryType,
EFI_PAGES_TO_SIZE (NumberOfPages),
- (VOID *) (UINTN) Memory,
+ (VOID *)(UINTN)Memory,
NULL
);
}
+
return Status;
}
@@ -969,7 +997,7 @@ SmmAddMemoryRegion (
// Align range on an EFI_PAGE_SIZE boundary
//
AlignedMemBase = (UINTN)(MemBase + EFI_PAGE_MASK) & ~EFI_PAGE_MASK;
- MemLength -= AlignedMemBase - MemBase;
+ MemLength -= AlignedMemBase - MemBase;
if (Type == EfiConventionalMemory) {
SmmInternalFreePagesEx (AlignedMemBase, TRUNCATE_TO_PAGES ((UINTN)MemLength), TRUE);
} else {
@@ -1019,11 +1047,11 @@ SmmCoreGetMemoryMap (
OUT UINT32 *DescriptorVersion
)
{
- UINTN Count;
- LIST_ENTRY *Link;
- MEMORY_MAP *Entry;
- UINTN Size;
- UINTN BufferSize;
+ UINTN Count;
+ LIST_ENTRY *Link;
+ MEMORY_MAP *Entry;
+ UINTN Size;
+ UINTN BufferSize;
Size = sizeof (EFI_MEMORY_DESCRIPTOR);
@@ -1032,7 +1060,7 @@ SmmCoreGetMemoryMap (
// 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;
@@ -1042,7 +1070,7 @@ SmmCoreGetMemoryMap (
*DescriptorVersion = EFI_MEMORY_DESCRIPTOR_VERSION;
}
- Count = GetSmmMemoryMapEntryCount ();
+ Count = GetSmmMemoryMapEntryCount ();
BufferSize = Size * Count;
if (*MemoryMapSize < BufferSize) {
*MemoryMapSize = BufferSize;
@@ -1060,9 +1088,9 @@ SmmCoreGetMemoryMap (
Entry = CR (Link, MEMORY_MAP, Link, MEMORY_MAP_SIGNATURE);
Link = Link->ForwardLink;
- MemoryMap->Type = Entry->Type;
- MemoryMap->PhysicalStart = Entry->Start;
- MemoryMap->NumberOfPages = RShiftU64 (Entry->End - Entry->Start + 1, EFI_PAGE_SHIFT);
+ MemoryMap->Type = Entry->Type;
+ MemoryMap->PhysicalStart = Entry->Start;
+ MemoryMap->NumberOfPages = RShiftU64 (Entry->End - Entry->Start + 1, EFI_PAGE_SHIFT);
MemoryMap = NEXT_MEMORY_DESCRIPTOR (MemoryMap, Size);
}
diff --git a/MdeModulePkg/Core/PiSmmCore/PiSmmCore.c b/MdeModulePkg/Core/PiSmmCore/PiSmmCore.c
index 2e6d7913f4..9e5c6cbe33 100644
--- a/MdeModulePkg/Core/PiSmmCore/PiSmmCore.c
+++ b/MdeModulePkg/Core/PiSmmCore/PiSmmCore.c
@@ -27,12 +27,12 @@ EFI_SMM_SYSTEM_TABLE2 gSmmCoreSmst = {
SmmInstallConfigurationTable,
{
{
- (EFI_SMM_CPU_IO2) SmmEfiNotAvailableYetArg5, // SmmMemRead
- (EFI_SMM_CPU_IO2) SmmEfiNotAvailableYetArg5 // SmmMemWrite
+ (EFI_SMM_CPU_IO2)SmmEfiNotAvailableYetArg5, // SmmMemRead
+ (EFI_SMM_CPU_IO2)SmmEfiNotAvailableYetArg5 // SmmMemWrite
},
{
- (EFI_SMM_CPU_IO2) SmmEfiNotAvailableYetArg5, // SmmIoRead
- (EFI_SMM_CPU_IO2) SmmEfiNotAvailableYetArg5 // SmmIoWrite
+ (EFI_SMM_CPU_IO2)SmmEfiNotAvailableYetArg5, // SmmIoRead
+ (EFI_SMM_CPU_IO2)SmmEfiNotAvailableYetArg5 // SmmIoWrite
}
},
SmmAllocatePool,
@@ -81,30 +81,30 @@ BOOLEAN mAcpiS3Enable = FALSE;
// Table of SMI Handlers that are registered by the SMM Core when it is initialized
//
SMM_CORE_SMI_HANDLERS mSmmCoreSmiHandlers[] = {
- { SmmDriverDispatchHandler, &gEfiEventDxeDispatchGuid, NULL, TRUE },
- { SmmReadyToLockHandler, &gEfiDxeSmmReadyToLockProtocolGuid, NULL, TRUE },
- { SmmLegacyBootHandler, &gEfiEventLegacyBootGuid, NULL, FALSE },
- { SmmExitBootServicesHandler, &gEfiEventExitBootServicesGuid, NULL, FALSE },
- { SmmReadyToBootHandler, &gEfiEventReadyToBootGuid, NULL, FALSE },
- { SmmEndOfDxeHandler, &gEfiEndOfDxeEventGroupGuid, NULL, TRUE },
- { NULL, NULL, NULL, FALSE }
+ { SmmDriverDispatchHandler, &gEfiEventDxeDispatchGuid, NULL, TRUE },
+ { SmmReadyToLockHandler, &gEfiDxeSmmReadyToLockProtocolGuid, NULL, TRUE },
+ { SmmLegacyBootHandler, &gEfiEventLegacyBootGuid, NULL, FALSE },
+ { SmmExitBootServicesHandler, &gEfiEventExitBootServicesGuid, NULL, FALSE },
+ { SmmReadyToBootHandler, &gEfiEventReadyToBootGuid, NULL, FALSE },
+ { SmmEndOfDxeHandler, &gEfiEndOfDxeEventGroupGuid, NULL, TRUE },
+ { NULL, NULL, NULL, FALSE }
};
//
// Table of SMI Handlers that are registered by the SMM Core when it is initialized
//
SMM_CORE_SMI_HANDLERS mSmmCoreS3SmiHandlers[] = {
- { SmmS3SmmInitDoneHandler, &gEdkiiS3SmmInitDoneGuid, NULL, FALSE },
- { SmmEndOfS3ResumeHandler, &gEdkiiEndOfS3ResumeGuid, NULL, FALSE },
- { NULL, NULL, NULL, FALSE }
+ { SmmS3SmmInitDoneHandler, &gEdkiiS3SmmInitDoneGuid, NULL, FALSE },
+ { SmmEndOfS3ResumeHandler, &gEdkiiEndOfS3ResumeGuid, NULL, FALSE },
+ { NULL, NULL, NULL, FALSE }
};
-UINTN mFullSmramRangeCount;
-EFI_SMRAM_DESCRIPTOR *mFullSmramRanges;
+UINTN mFullSmramRangeCount;
+EFI_SMRAM_DESCRIPTOR *mFullSmramRanges;
-EFI_SMM_DRIVER_ENTRY *mSmmCoreDriverEntry;
+EFI_SMM_DRIVER_ENTRY *mSmmCoreDriverEntry;
-EFI_LOADED_IMAGE_PROTOCOL *mSmmCoreLoadedImage;
+EFI_LOADED_IMAGE_PROTOCOL *mSmmCoreLoadedImage;
/**
Place holder function until all the SMM System Table Service are available.
@@ -123,11 +123,11 @@ EFI_LOADED_IMAGE_PROTOCOL *mSmmCoreLoadedImage;
EFI_STATUS
EFIAPI
SmmEfiNotAvailableYetArg5 (
- UINTN Arg1,
- UINTN Arg2,
- UINTN Arg3,
- UINTN Arg4,
- UINTN Arg5
+ UINTN Arg1,
+ UINTN Arg2,
+ UINTN Arg3,
+ UINTN Arg4,
+ UINTN Arg5
)
{
//
@@ -163,20 +163,20 @@ SmmLegacyBootHandler (
IN OUT UINTN *CommBufferSize OPTIONAL
)
{
- EFI_STATUS Status;
- EFI_HANDLE SmmHandle;
- UINTN Index;
+ EFI_STATUS Status;
+ EFI_HANDLE SmmHandle;
+ UINTN Index;
//
// Install SMM Legacy Boot protocol.
//
SmmHandle = NULL;
- Status = SmmInstallProtocolInterface (
- &SmmHandle,
- &gEdkiiSmmLegacyBootProtocolGuid,
- EFI_NATIVE_INTERFACE,
- NULL
- );
+ Status = SmmInstallProtocolInterface (
+ &SmmHandle,
+ &gEdkiiSmmLegacyBootProtocolGuid,
+ EFI_NATIVE_INTERFACE,
+ NULL
+ );
mInLegacyBoot = TRUE;
@@ -218,20 +218,20 @@ SmmExitBootServicesHandler (
IN OUT UINTN *CommBufferSize OPTIONAL
)
{
- EFI_STATUS Status;
- EFI_HANDLE SmmHandle;
- UINTN Index;
+ EFI_STATUS Status;
+ EFI_HANDLE SmmHandle;
+ UINTN Index;
//
// Install SMM Exit Boot Services protocol.
//
SmmHandle = NULL;
- Status = SmmInstallProtocolInterface (
- &SmmHandle,
- &gEdkiiSmmExitBootServicesProtocolGuid,
- EFI_NATIVE_INTERFACE,
- NULL
- );
+ Status = SmmInstallProtocolInterface (
+ &SmmHandle,
+ &gEdkiiSmmExitBootServicesProtocolGuid,
+ EFI_NATIVE_INTERFACE,
+ NULL
+ );
SmiHandlerUnRegister (DispatchHandle);
@@ -269,10 +269,10 @@ SmmExitBootServicesHandler (
EFI_STATUS
EFIAPI
SmmS3EntryCallBack (
- IN EFI_HANDLE DispatchHandle,
- IN CONST VOID *Context OPTIONAL,
- IN OUT VOID *CommBuffer OPTIONAL,
- IN OUT UINTN *CommBufferSize OPTIONAL
+ IN EFI_HANDLE DispatchHandle,
+ IN CONST VOID *Context OPTIONAL,
+ IN OUT VOID *CommBuffer OPTIONAL,
+ IN OUT UINTN *CommBufferSize OPTIONAL
)
{
mDuringS3Resume = TRUE;
@@ -302,19 +302,19 @@ SmmReadyToBootHandler (
IN OUT UINTN *CommBufferSize OPTIONAL
)
{
- EFI_STATUS Status;
- EFI_HANDLE SmmHandle;
+ EFI_STATUS Status;
+ EFI_HANDLE SmmHandle;
//
// Install SMM Ready To Boot protocol.
//
SmmHandle = NULL;
- Status = SmmInstallProtocolInterface (
- &SmmHandle,
- &gEdkiiSmmReadyToBootProtocolGuid,
- EFI_NATIVE_INTERFACE,
- NULL
- );
+ Status = SmmInstallProtocolInterface (
+ &SmmHandle,
+ &gEdkiiSmmReadyToBootProtocolGuid,
+ EFI_NATIVE_INTERFACE,
+ NULL
+ );
SmiHandlerUnRegister (DispatchHandle);
@@ -365,12 +365,12 @@ SmmReadyToLockHandler (
// Install SMM Ready to lock protocol
//
SmmHandle = NULL;
- Status = SmmInstallProtocolInterface (
- &SmmHandle,
- &gEfiSmmReadyToLockProtocolGuid,
- EFI_NATIVE_INTERFACE,
- NULL
- );
+ Status = SmmInstallProtocolInterface (
+ &SmmHandle,
+ &gEfiSmmReadyToLockProtocolGuid,
+ EFI_NATIVE_INTERFACE,
+ NULL
+ );
//
// Make sure SMM CPU I/O 2 Protocol has been installed into the handle database
@@ -381,9 +381,10 @@ SmmReadyToLockHandler (
// Print a message on a debug build if the SMM CPU I/O 2 Protocol is not installed
//
DEBUG_CODE_BEGIN ();
- if (EFI_ERROR (Status)) {
- DEBUG ((DEBUG_ERROR, "\nSMM: SmmCpuIo Arch Protocol not present!!\n"));
- }
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "\nSMM: SmmCpuIo Arch Protocol not present!!\n"));
+ }
+
DEBUG_CODE_END ();
//
@@ -396,7 +397,7 @@ SmmReadyToLockHandler (
// evaluated to false if this is a debug build
//
DEBUG_CODE_BEGIN ();
- SmmDisplayDiscoveredNotDispatched ();
+ SmmDisplayDiscoveredNotDispatched ();
DEBUG_CODE_END ();
//
@@ -433,11 +434,11 @@ SmmEndOfDxeHandler (
IN OUT UINTN *CommBufferSize OPTIONAL
)
{
- EFI_STATUS Status;
- EFI_HANDLE SmmHandle;
- EFI_SMM_SX_DISPATCH2_PROTOCOL *SxDispatch;
- EFI_SMM_SX_REGISTER_CONTEXT EntryRegisterContext;
- EFI_HANDLE S3EntryHandle;
+ EFI_STATUS Status;
+ EFI_HANDLE SmmHandle;
+ EFI_SMM_SX_DISPATCH2_PROTOCOL *SxDispatch;
+ EFI_SMM_SX_REGISTER_CONTEXT EntryRegisterContext;
+ EFI_HANDLE S3EntryHandle;
DEBUG ((DEBUG_INFO, "SmmEndOfDxeHandler\n"));
@@ -445,12 +446,12 @@ SmmEndOfDxeHandler (
// Install SMM EndOfDxe protocol
//
SmmHandle = NULL;
- Status = SmmInstallProtocolInterface (
- &SmmHandle,
- &gEfiSmmEndOfDxeProtocolGuid,
- EFI_NATIVE_INTERFACE,
- NULL
- );
+ Status = SmmInstallProtocolInterface (
+ &SmmHandle,
+ &gEfiSmmEndOfDxeProtocolGuid,
+ EFI_NATIVE_INTERFACE,
+ NULL
+ );
if (mAcpiS3Enable) {
//
@@ -468,12 +469,12 @@ SmmEndOfDxeHandler (
//
EntryRegisterContext.Type = SxS3;
EntryRegisterContext.Phase = SxEntry;
- Status = SxDispatch->Register (
- SxDispatch,
- SmmS3EntryCallBack,
- &EntryRegisterContext,
- &S3EntryHandle
- );
+ Status = SxDispatch->Register (
+ SxDispatch,
+ SmmS3EntryCallBack,
+ &EntryRegisterContext,
+ &S3EntryHandle
+ );
ASSERT_EFI_ERROR (Status);
}
}
@@ -518,12 +519,12 @@ SmmS3SmmInitDoneHandler (
// Install SMM S3SmmInitDone protocol
//
SmmHandle = NULL;
- Status = SmmInstallProtocolInterface (
- &SmmHandle,
- &gEdkiiS3SmmInitDoneGuid,
- EFI_NATIVE_INTERFACE,
- NULL
- );
+ Status = SmmInstallProtocolInterface (
+ &SmmHandle,
+ &gEdkiiS3SmmInitDoneGuid,
+ EFI_NATIVE_INTERFACE,
+ NULL
+ );
ASSERT_EFI_ERROR (Status);
//
@@ -531,10 +532,10 @@ SmmS3SmmInitDoneHandler (
// installation event.
//
Status = SmmUninstallProtocolInterface (
- SmmHandle,
- &gEdkiiS3SmmInitDoneGuid,
- NULL
- );
+ SmmHandle,
+ &gEdkiiS3SmmInitDoneGuid,
+ NULL
+ );
ASSERT_EFI_ERROR (Status);
return Status;
@@ -577,12 +578,12 @@ SmmEndOfS3ResumeHandler (
// Install SMM EndOfS3Resume protocol
//
SmmHandle = NULL;
- Status = SmmInstallProtocolInterface (
- &SmmHandle,
- &gEdkiiEndOfS3ResumeGuid,
- EFI_NATIVE_INTERFACE,
- NULL
- );
+ Status = SmmInstallProtocolInterface (
+ &SmmHandle,
+ &gEdkiiEndOfS3ResumeGuid,
+ EFI_NATIVE_INTERFACE,
+ NULL
+ );
ASSERT_EFI_ERROR (Status);
//
@@ -590,10 +591,10 @@ SmmEndOfS3ResumeHandler (
// installation event.
//
Status = SmmUninstallProtocolInterface (
- SmmHandle,
- &gEdkiiEndOfS3ResumeGuid,
- NULL
- );
+ SmmHandle,
+ &gEdkiiEndOfS3ResumeGuid,
+ NULL
+ );
ASSERT_EFI_ERROR (Status);
mDuringS3Resume = FALSE;
@@ -614,10 +615,10 @@ SmmEndOfS3ResumeHandler (
**/
BOOLEAN
InternalIsBufferOverlapped (
- IN UINT8 *Buff1,
- IN UINTN Size1,
- IN UINT8 *Buff2,
- IN UINTN Size2
+ IN UINT8 *Buff1,
+ IN UINTN Size1,
+ IN UINT8 *Buff2,
+ IN UINTN Size2
)
{
//
@@ -644,7 +645,7 @@ VOID
EFIAPI
SmmEntryPoint (
IN CONST EFI_SMM_ENTRY_CONTEXT *SmmEntryContext
-)
+ )
{
EFI_STATUS Status;
EFI_SMM_COMMUNICATE_HEADER *CommunicateHeader;
@@ -693,9 +694,9 @@ SmmEntryPoint (
// Synchronous SMI for SMM Core or request from Communicate protocol
//
IsOverlapped = InternalIsBufferOverlapped (
- (UINT8 *) CommunicationBuffer,
+ (UINT8 *)CommunicationBuffer,
BufferSize,
- (UINT8 *) gSmmCorePrivate,
+ (UINT8 *)gSmmCorePrivate,
sizeof (*gSmmCorePrivate)
);
if (!SmmIsBufferOutsideSmmValid ((UINTN)CommunicationBuffer, BufferSize) || IsOverlapped) {
@@ -705,23 +706,23 @@ SmmEntryPoint (
// return EFI_INVALID_PARAMETER
//
gSmmCorePrivate->CommunicationBuffer = NULL;
- gSmmCorePrivate->ReturnStatus = EFI_ACCESS_DENIED;
+ gSmmCorePrivate->ReturnStatus = EFI_ACCESS_DENIED;
} else {
CommunicateHeader = (EFI_SMM_COMMUNICATE_HEADER *)CommunicationBuffer;
- BufferSize -= OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data);
- Status = SmiManage (
- &CommunicateHeader->HeaderGuid,
- NULL,
- CommunicateHeader->Data,
- &BufferSize
- );
+ BufferSize -= OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data);
+ Status = SmiManage (
+ &CommunicateHeader->HeaderGuid,
+ NULL,
+ CommunicateHeader->Data,
+ &BufferSize
+ );
//
// Update CommunicationBuffer, BufferSize and ReturnStatus
// Communicate service finished, reset the pointer to CommBuffer to NULL
//
- gSmmCorePrivate->BufferSize = BufferSize + OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data);
+ gSmmCorePrivate->BufferSize = BufferSize + OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data);
gSmmCorePrivate->CommunicationBuffer = NULL;
- gSmmCorePrivate->ReturnStatus = (Status == EFI_SUCCESS) ? EFI_SUCCESS : EFI_NOT_FOUND;
+ gSmmCorePrivate->ReturnStatus = (Status == EFI_SUCCESS) ? EFI_SUCCESS : EFI_NOT_FOUND;
}
}
}
@@ -755,13 +756,13 @@ SmmCoreInstallLoadedImage (
VOID
)
{
- EFI_STATUS Status;
- EFI_HANDLE Handle;
+ EFI_STATUS Status;
+ EFI_HANDLE Handle;
//
// Allocate a Loaded Image Protocol in EfiBootServicesData
//
- Status = gBS->AllocatePool (EfiBootServicesData, sizeof(EFI_LOADED_IMAGE_PROTOCOL), (VOID **)&mSmmCoreLoadedImage);
+ Status = gBS->AllocatePool (EfiBootServicesData, sizeof (EFI_LOADED_IMAGE_PROTOCOL), (VOID **)&mSmmCoreLoadedImage);
ASSERT_EFI_ERROR (Status);
ZeroMem (mSmmCoreLoadedImage, sizeof (EFI_LOADED_IMAGE_PROTOCOL));
@@ -769,9 +770,9 @@ SmmCoreInstallLoadedImage (
// Fill in the remaining fields of the Loaded Image Protocol instance.
// Note: ImageBase is an SMRAM address that can not be accessed outside of SMRAM if SMRAM window is closed.
//
- mSmmCoreLoadedImage->Revision = EFI_LOADED_IMAGE_PROTOCOL_REVISION;
- mSmmCoreLoadedImage->ParentHandle = gSmmCorePrivate->SmmIplImageHandle;
- mSmmCoreLoadedImage->SystemTable = gST;
+ mSmmCoreLoadedImage->Revision = EFI_LOADED_IMAGE_PROTOCOL_REVISION;
+ mSmmCoreLoadedImage->ParentHandle = gSmmCorePrivate->SmmIplImageHandle;
+ mSmmCoreLoadedImage->SystemTable = gST;
mSmmCoreLoadedImage->ImageBase = (VOID *)(UINTN)gSmmCorePrivate->PiSmmCoreImageBase;
mSmmCoreLoadedImage->ImageSize = gSmmCorePrivate->PiSmmCoreImageSize;
@@ -784,7 +785,8 @@ SmmCoreInstallLoadedImage (
Handle = NULL;
Status = gBS->InstallMultipleProtocolInterfaces (
&Handle,
- &gEfiLoadedImageProtocolGuid, mSmmCoreLoadedImage,
+ &gEfiLoadedImageProtocolGuid,
+ mSmmCoreLoadedImage,
NULL
);
ASSERT_EFI_ERROR (Status);
@@ -792,40 +794,40 @@ SmmCoreInstallLoadedImage (
//
// Allocate a Loaded Image Protocol in SMM
//
- Status = SmmAllocatePool (EfiRuntimeServicesData, sizeof(EFI_SMM_DRIVER_ENTRY), (VOID **)&mSmmCoreDriverEntry);
- ASSERT_EFI_ERROR(Status);
+ Status = SmmAllocatePool (EfiRuntimeServicesData, sizeof (EFI_SMM_DRIVER_ENTRY), (VOID **)&mSmmCoreDriverEntry);
+ ASSERT_EFI_ERROR (Status);
- ZeroMem (mSmmCoreDriverEntry, sizeof(EFI_SMM_DRIVER_ENTRY));
+ ZeroMem (mSmmCoreDriverEntry, sizeof (EFI_SMM_DRIVER_ENTRY));
//
// Fill in the remaining fields of the Loaded Image Protocol instance.
//
- mSmmCoreDriverEntry->Signature = EFI_SMM_DRIVER_ENTRY_SIGNATURE;
- mSmmCoreDriverEntry->SmmLoadedImage.Revision = EFI_LOADED_IMAGE_PROTOCOL_REVISION;
+ mSmmCoreDriverEntry->Signature = EFI_SMM_DRIVER_ENTRY_SIGNATURE;
+ mSmmCoreDriverEntry->SmmLoadedImage.Revision = EFI_LOADED_IMAGE_PROTOCOL_REVISION;
mSmmCoreDriverEntry->SmmLoadedImage.ParentHandle = gSmmCorePrivate->SmmIplImageHandle;
- mSmmCoreDriverEntry->SmmLoadedImage.SystemTable = gST;
+ mSmmCoreDriverEntry->SmmLoadedImage.SystemTable = gST;
- mSmmCoreDriverEntry->SmmLoadedImage.ImageBase = (VOID *)(UINTN)gSmmCorePrivate->PiSmmCoreImageBase;
- mSmmCoreDriverEntry->SmmLoadedImage.ImageSize = gSmmCorePrivate->PiSmmCoreImageSize;
+ mSmmCoreDriverEntry->SmmLoadedImage.ImageBase = (VOID *)(UINTN)gSmmCorePrivate->PiSmmCoreImageBase;
+ mSmmCoreDriverEntry->SmmLoadedImage.ImageSize = gSmmCorePrivate->PiSmmCoreImageSize;
mSmmCoreDriverEntry->SmmLoadedImage.ImageCodeType = EfiRuntimeServicesCode;
mSmmCoreDriverEntry->SmmLoadedImage.ImageDataType = EfiRuntimeServicesData;
mSmmCoreDriverEntry->ImageEntryPoint = gSmmCorePrivate->PiSmmCoreEntryPoint;
mSmmCoreDriverEntry->ImageBuffer = gSmmCorePrivate->PiSmmCoreImageBase;
- mSmmCoreDriverEntry->NumberOfPage = EFI_SIZE_TO_PAGES((UINTN)gSmmCorePrivate->PiSmmCoreImageSize);
+ mSmmCoreDriverEntry->NumberOfPage = EFI_SIZE_TO_PAGES ((UINTN)gSmmCorePrivate->PiSmmCoreImageSize);
//
// Create a new image handle in the SMM handle database for the SMM Driver
//
mSmmCoreDriverEntry->SmmImageHandle = NULL;
- Status = SmmInstallProtocolInterface (
- &mSmmCoreDriverEntry->SmmImageHandle,
- &gEfiLoadedImageProtocolGuid,
- EFI_NATIVE_INTERFACE,
- &mSmmCoreDriverEntry->SmmLoadedImage
- );
- ASSERT_EFI_ERROR(Status);
+ Status = SmmInstallProtocolInterface (
+ &mSmmCoreDriverEntry->SmmImageHandle,
+ &gEfiLoadedImageProtocolGuid,
+ EFI_NATIVE_INTERFACE,
+ &mSmmCoreDriverEntry->SmmLoadedImage
+ );
+ ASSERT_EFI_ERROR (Status);
- return ;
+ return;
}
/**
@@ -876,7 +878,7 @@ SmmMain (
// Copy FullSmramRanges to SMRAM
//
mFullSmramRangeCount = gSmmCorePrivate->SmramRangeCount;
- mFullSmramRanges = AllocatePool (mFullSmramRangeCount * sizeof (EFI_SMRAM_DESCRIPTOR));
+ mFullSmramRanges = AllocatePool (mFullSmramRangeCount * sizeof (EFI_SMRAM_DESCRIPTOR));
ASSERT (mFullSmramRanges != NULL);
CopyMem (mFullSmramRanges, gSmmCorePrivate->SmramRanges, mFullSmramRangeCount * sizeof (EFI_SMRAM_DESCRIPTOR));
diff --git a/MdeModulePkg/Core/PiSmmCore/PiSmmCore.h b/MdeModulePkg/Core/PiSmmCore/PiSmmCore.h
index 19ce69f5e8..71422b9dfc 100644
--- a/MdeModulePkg/Core/PiSmmCore/PiSmmCore.h
+++ b/MdeModulePkg/Core/PiSmmCore/PiSmmCore.h
@@ -62,10 +62,10 @@
// Used to build a table of SMI Handlers that the SMM Core registers
//
typedef struct {
- EFI_SMM_HANDLER_ENTRY_POINT2 Handler;
- EFI_GUID *HandlerType;
- EFI_HANDLE DispatchHandle;
- BOOLEAN UnRegister;
+ EFI_SMM_HANDLER_ENTRY_POINT2 Handler;
+ EFI_GUID *HandlerType;
+ EFI_HANDLE DispatchHandle;
+ BOOLEAN UnRegister;
} SMM_CORE_SMI_HANDLERS;
//
@@ -74,89 +74,89 @@ typedef struct {
#define SMI_ENTRY_SIGNATURE SIGNATURE_32('s','m','i','e')
- typedef struct {
- UINTN Signature;
- LIST_ENTRY AllEntries; // All entries
+typedef struct {
+ UINTN Signature;
+ LIST_ENTRY AllEntries; // All entries
- EFI_GUID HandlerType; // Type of interrupt
- LIST_ENTRY SmiHandlers; // All handlers
+ EFI_GUID HandlerType; // Type of interrupt
+ LIST_ENTRY SmiHandlers; // All handlers
} SMI_ENTRY;
#define SMI_HANDLER_SIGNATURE SIGNATURE_32('s','m','i','h')
- typedef struct {
- UINTN Signature;
- LIST_ENTRY Link; // Link on SMI_ENTRY.SmiHandlers
- EFI_SMM_HANDLER_ENTRY_POINT2 Handler; // The smm handler's entry point
- UINTN CallerAddr; // The address of caller who register the SMI handler.
- SMI_ENTRY *SmiEntry;
- VOID *Context; // for profile
- UINTN ContextSize; // for profile
+typedef struct {
+ UINTN Signature;
+ LIST_ENTRY Link; // Link on SMI_ENTRY.SmiHandlers
+ EFI_SMM_HANDLER_ENTRY_POINT2 Handler; // The smm handler's entry point
+ UINTN CallerAddr; // The address of caller who register the SMI handler.
+ SMI_ENTRY *SmiEntry;
+ VOID *Context; // for profile
+ UINTN ContextSize; // for profile
} SMI_HANDLER;
//
// Structure for recording the state of an SMM Driver
//
-#define EFI_SMM_DRIVER_ENTRY_SIGNATURE SIGNATURE_32('s', 'd','r','v')
+#define EFI_SMM_DRIVER_ENTRY_SIGNATURE SIGNATURE_32('s', 'd','r','v')
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 Scheduled;
- BOOLEAN Initialized;
- BOOLEAN DepexProtocolError;
+ BOOLEAN Dependent;
+ BOOLEAN Scheduled;
+ BOOLEAN Initialized;
+ BOOLEAN DepexProtocolError;
- EFI_HANDLE ImageHandle;
- EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;
+ EFI_HANDLE ImageHandle;
+ EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;
//
// Image EntryPoint in SMRAM
//
- PHYSICAL_ADDRESS ImageEntryPoint;
+ PHYSICAL_ADDRESS ImageEntryPoint;
//
// Image Buffer in SMRAM
//
- PHYSICAL_ADDRESS ImageBuffer;
+ PHYSICAL_ADDRESS ImageBuffer;
//
// Image Page Number
//
- UINTN NumberOfPage;
- EFI_HANDLE SmmImageHandle;
- EFI_LOADED_IMAGE_PROTOCOL SmmLoadedImage;
+ UINTN NumberOfPage;
+ EFI_HANDLE SmmImageHandle;
+ EFI_LOADED_IMAGE_PROTOCOL SmmLoadedImage;
} EFI_SMM_DRIVER_ENTRY;
-#define EFI_HANDLE_SIGNATURE SIGNATURE_32('s','h','d','l')
+#define EFI_HANDLE_SIGNATURE SIGNATURE_32('s','h','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;
} IHANDLE;
#define ASSERT_IS_HANDLE(a) ASSERT((a)->Signature == EFI_HANDLE_SIGNATURE)
-#define PROTOCOL_ENTRY_SIGNATURE SIGNATURE_32('s','p','t','e')
+#define PROTOCOL_ENTRY_SIGNATURE SIGNATURE_32('s','p','t','e')
///
/// PROTOCOL_ENTRY - each different protocol has 1 entry in the protocol
@@ -164,15 +164,15 @@ 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;
/// Registered notification handlers
- LIST_ENTRY Notify;
+ LIST_ENTRY Notify;
} PROTOCOL_ENTRY;
#define PROTOCOL_INTERFACE_SIGNATURE SIGNATURE_32('s','p','i','f')
@@ -182,33 +182,33 @@ 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;
} PROTOCOL_INTERFACE;
-#define PROTOCOL_NOTIFY_SIGNATURE SIGNATURE_32('s','p','t','n')
+#define PROTOCOL_NOTIFY_SIGNATURE SIGNATURE_32('s','p','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;
/// Notification function
- EFI_SMM_NOTIFY_FN Function;
+ EFI_SMM_NOTIFY_FN Function;
/// Last position notified
- LIST_ENTRY *Position;
+ LIST_ENTRY *Position;
} PROTOCOL_NOTIFY;
//
@@ -253,9 +253,9 @@ EFI_STATUS
EFIAPI
SmmInstallConfigurationTable (
IN CONST EFI_SMM_SYSTEM_TABLE2 *SystemTable,
- IN CONST EFI_GUID *Guid,
- IN VOID *Table,
- IN UINTN TableSize
+ IN CONST EFI_GUID *Guid,
+ IN VOID *Table,
+ IN UINTN TableSize
);
/**
@@ -275,10 +275,10 @@ SmmInstallConfigurationTable (
EFI_STATUS
EFIAPI
SmmInstallProtocolInterface (
- 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
);
/**
@@ -300,10 +300,10 @@ SmmInstallProtocolInterface (
EFI_STATUS
EFIAPI
SmmAllocatePages (
- IN EFI_ALLOCATE_TYPE Type,
- IN EFI_MEMORY_TYPE MemoryType,
- IN UINTN NumberOfPages,
- OUT EFI_PHYSICAL_ADDRESS *Memory
+ IN EFI_ALLOCATE_TYPE Type,
+ IN EFI_MEMORY_TYPE MemoryType,
+ IN UINTN NumberOfPages,
+ OUT EFI_PHYSICAL_ADDRESS *Memory
);
/**
@@ -326,11 +326,11 @@ SmmAllocatePages (
EFI_STATUS
EFIAPI
SmmInternalAllocatePages (
- IN EFI_ALLOCATE_TYPE Type,
- IN EFI_MEMORY_TYPE MemoryType,
- IN UINTN NumberOfPages,
- OUT EFI_PHYSICAL_ADDRESS *Memory,
- IN BOOLEAN NeedGuard
+ IN EFI_ALLOCATE_TYPE Type,
+ IN EFI_MEMORY_TYPE MemoryType,
+ IN UINTN NumberOfPages,
+ OUT EFI_PHYSICAL_ADDRESS *Memory,
+ IN BOOLEAN NeedGuard
);
/**
@@ -347,8 +347,8 @@ SmmInternalAllocatePages (
EFI_STATUS
EFIAPI
SmmFreePages (
- IN EFI_PHYSICAL_ADDRESS Memory,
- IN UINTN NumberOfPages
+ IN EFI_PHYSICAL_ADDRESS Memory,
+ IN UINTN NumberOfPages
);
/**
@@ -367,9 +367,9 @@ SmmFreePages (
EFI_STATUS
EFIAPI
SmmInternalFreePages (
- IN EFI_PHYSICAL_ADDRESS Memory,
- IN UINTN NumberOfPages,
- IN BOOLEAN IsGuarded
+ IN EFI_PHYSICAL_ADDRESS Memory,
+ IN UINTN NumberOfPages,
+ IN BOOLEAN IsGuarded
);
/**
@@ -388,9 +388,9 @@ SmmInternalFreePages (
EFI_STATUS
EFIAPI
SmmAllocatePool (
- IN EFI_MEMORY_TYPE PoolType,
- IN UINTN Size,
- OUT VOID **Buffer
+ IN EFI_MEMORY_TYPE PoolType,
+ IN UINTN Size,
+ OUT VOID **Buffer
);
/**
@@ -409,9 +409,9 @@ SmmAllocatePool (
EFI_STATUS
EFIAPI
SmmInternalAllocatePool (
- IN EFI_MEMORY_TYPE PoolType,
- IN UINTN Size,
- OUT VOID **Buffer
+ IN EFI_MEMORY_TYPE PoolType,
+ IN UINTN Size,
+ OUT VOID **Buffer
);
/**
@@ -426,7 +426,7 @@ SmmInternalAllocatePool (
EFI_STATUS
EFIAPI
SmmFreePool (
- IN VOID *Buffer
+ IN VOID *Buffer
);
/**
@@ -441,7 +441,7 @@ SmmFreePool (
EFI_STATUS
EFIAPI
SmmInternalFreePool (
- IN VOID *Buffer
+ IN VOID *Buffer
);
/**
@@ -463,11 +463,11 @@ SmmInternalFreePool (
**/
EFI_STATUS
SmmInstallProtocolInterfaceNotify (
- 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
);
/**
@@ -486,9 +486,9 @@ SmmInstallProtocolInterfaceNotify (
EFI_STATUS
EFIAPI
SmmUninstallProtocolInterface (
- IN EFI_HANDLE UserHandle,
- IN EFI_GUID *Protocol,
- IN VOID *Interface
+ IN EFI_HANDLE UserHandle,
+ IN EFI_GUID *Protocol,
+ IN VOID *Interface
);
/**
@@ -505,9 +505,9 @@ SmmUninstallProtocolInterface (
EFI_STATUS
EFIAPI
SmmHandleProtocol (
- IN EFI_HANDLE UserHandle,
- IN EFI_GUID *Protocol,
- OUT VOID **Interface
+ IN EFI_HANDLE UserHandle,
+ IN EFI_GUID *Protocol,
+ OUT VOID **Interface
);
/**
@@ -526,9 +526,9 @@ SmmHandleProtocol (
EFI_STATUS
EFIAPI
SmmRegisterProtocolNotify (
- IN CONST EFI_GUID *Protocol,
- IN EFI_SMM_NOTIFY_FN Function,
- OUT VOID **Registration
+ IN CONST EFI_GUID *Protocol,
+ IN EFI_SMM_NOTIFY_FN Function,
+ OUT VOID **Registration
);
/**
@@ -552,11 +552,11 @@ SmmRegisterProtocolNotify (
EFI_STATUS
EFIAPI
SmmLocateHandle (
- 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
);
/**
@@ -632,10 +632,10 @@ SmmLocateHandleBuffer (
EFI_STATUS
EFIAPI
SmiManage (
- IN CONST EFI_GUID *HandlerType,
- IN CONST VOID *Context OPTIONAL,
- IN OUT VOID *CommBuffer OPTIONAL,
- IN OUT UINTN *CommBufferSize OPTIONAL
+ IN CONST EFI_GUID *HandlerType,
+ IN CONST VOID *Context OPTIONAL,
+ IN OUT VOID *CommBuffer OPTIONAL,
+ IN OUT UINTN *CommBufferSize OPTIONAL
);
/**
@@ -652,9 +652,9 @@ SmiManage (
EFI_STATUS
EFIAPI
SmiHandlerRegister (
- IN EFI_SMM_HANDLER_ENTRY_POINT2 Handler,
- IN CONST EFI_GUID *HandlerType OPTIONAL,
- OUT EFI_HANDLE *DispatchHandle
+ IN EFI_SMM_HANDLER_ENTRY_POINT2 Handler,
+ IN CONST EFI_GUID *HandlerType OPTIONAL,
+ OUT EFI_HANDLE *DispatchHandle
);
/**
@@ -669,7 +669,7 @@ SmiHandlerRegister (
EFI_STATUS
EFIAPI
SmiHandlerUnRegister (
- IN EFI_HANDLE DispatchHandle
+ IN EFI_HANDLE DispatchHandle
);
/**
@@ -688,10 +688,10 @@ SmiHandlerUnRegister (
EFI_STATUS
EFIAPI
SmmDriverDispatchHandler (
- IN EFI_HANDLE DispatchHandle,
- IN CONST VOID *Context OPTIONAL,
- IN OUT VOID *CommBuffer OPTIONAL,
- IN OUT UINTN *CommBufferSize OPTIONAL
+ IN EFI_HANDLE DispatchHandle,
+ IN CONST VOID *Context OPTIONAL,
+ IN OUT VOID *CommBuffer OPTIONAL,
+ IN OUT UINTN *CommBufferSize OPTIONAL
);
/**
@@ -710,10 +710,10 @@ SmmDriverDispatchHandler (
EFI_STATUS
EFIAPI
SmmLegacyBootHandler (
- IN EFI_HANDLE DispatchHandle,
- IN CONST VOID *Context OPTIONAL,
- IN OUT VOID *CommBuffer OPTIONAL,
- IN OUT UINTN *CommBufferSize OPTIONAL
+ IN EFI_HANDLE DispatchHandle,
+ IN CONST VOID *Context OPTIONAL,
+ IN OUT VOID *CommBuffer OPTIONAL,
+ IN OUT UINTN *CommBufferSize OPTIONAL
);
/**
@@ -732,10 +732,10 @@ SmmLegacyBootHandler (
EFI_STATUS
EFIAPI
SmmReadyToLockHandler (
- IN EFI_HANDLE DispatchHandle,
- IN CONST VOID *Context OPTIONAL,
- IN OUT VOID *CommBuffer OPTIONAL,
- IN OUT UINTN *CommBufferSize OPTIONAL
+ IN EFI_HANDLE DispatchHandle,
+ IN CONST VOID *Context OPTIONAL,
+ IN OUT VOID *CommBuffer OPTIONAL,
+ IN OUT UINTN *CommBufferSize OPTIONAL
);
/**
@@ -754,10 +754,10 @@ SmmReadyToLockHandler (
EFI_STATUS
EFIAPI
SmmEndOfDxeHandler (
- IN EFI_HANDLE DispatchHandle,
- IN CONST VOID *Context OPTIONAL,
- IN OUT VOID *CommBuffer OPTIONAL,
- IN OUT UINTN *CommBufferSize OPTIONAL
+ IN EFI_HANDLE DispatchHandle,
+ IN CONST VOID *Context OPTIONAL,
+ IN OUT VOID *CommBuffer OPTIONAL,
+ IN OUT UINTN *CommBufferSize OPTIONAL
);
/**
@@ -776,10 +776,10 @@ SmmEndOfDxeHandler (
EFI_STATUS
EFIAPI
SmmExitBootServicesHandler (
- IN EFI_HANDLE DispatchHandle,
- IN CONST VOID *Context OPTIONAL,
- IN OUT VOID *CommBuffer OPTIONAL,
- IN OUT UINTN *CommBufferSize OPTIONAL
+ IN EFI_HANDLE DispatchHandle,
+ IN CONST VOID *Context OPTIONAL,
+ IN OUT VOID *CommBuffer OPTIONAL,
+ IN OUT UINTN *CommBufferSize OPTIONAL
);
/**
@@ -798,10 +798,10 @@ SmmExitBootServicesHandler (
EFI_STATUS
EFIAPI
SmmReadyToBootHandler (
- IN EFI_HANDLE DispatchHandle,
- IN CONST VOID *Context OPTIONAL,
- IN OUT VOID *CommBuffer OPTIONAL,
- IN OUT UINTN *CommBufferSize OPTIONAL
+ IN EFI_HANDLE DispatchHandle,
+ IN CONST VOID *Context OPTIONAL,
+ IN OUT VOID *CommBuffer OPTIONAL,
+ IN OUT UINTN *CommBufferSize OPTIONAL
);
/**
@@ -865,15 +865,15 @@ SmmEndOfS3ResumeHandler (
EFI_STATUS
EFIAPI
SmmEfiNotAvailableYetArg5 (
- UINTN Arg1,
- UINTN Arg2,
- UINTN Arg3,
- UINTN Arg4,
- UINTN Arg5
+ UINTN Arg1,
+ UINTN Arg2,
+ UINTN Arg3,
+ UINTN Arg4,
+ UINTN Arg5
);
//
-//Functions used during debug builds
+// Functions used during debug builds
//
/**
@@ -897,10 +897,10 @@ SmmDisplayDiscoveredNotDispatched (
**/
VOID
SmmAddMemoryRegion (
- IN EFI_PHYSICAL_ADDRESS MemBase,
- IN UINT64 MemLength,
- IN EFI_MEMORY_TYPE Type,
- IN UINT64 Attributes
+ IN EFI_PHYSICAL_ADDRESS MemBase,
+ IN UINT64 MemLength,
+ IN EFI_MEMORY_TYPE Type,
+ IN UINT64 Attributes
);
/**
@@ -914,8 +914,8 @@ SmmAddMemoryRegion (
**/
PROTOCOL_ENTRY *
SmmFindProtocolEntry (
- IN EFI_GUID *Protocol,
- IN BOOLEAN Create
+ IN EFI_GUID *Protocol,
+ IN BOOLEAN Create
);
/**
@@ -926,7 +926,7 @@ SmmFindProtocolEntry (
**/
VOID
SmmNotifyProtocol (
- IN PROTOCOL_INTERFACE *Prot
+ IN PROTOCOL_INTERFACE *Prot
);
/**
@@ -943,9 +943,9 @@ SmmNotifyProtocol (
**/
PROTOCOL_INTERFACE *
SmmFindProtocolInterface (
- IN IHANDLE *Handle,
- IN EFI_GUID *Protocol,
- IN VOID *Interface
+ IN IHANDLE *Handle,
+ IN EFI_GUID *Protocol,
+ IN VOID *Interface
);
/**
@@ -960,9 +960,9 @@ SmmFindProtocolInterface (
**/
PROTOCOL_INTERFACE *
SmmRemoveInterfaceFromProtocol (
- IN IHANDLE *Handle,
- IN EFI_GUID *Protocol,
- IN VOID *Interface
+ IN IHANDLE *Handle,
+ IN EFI_GUID *Protocol,
+ IN VOID *Interface
);
/**
@@ -979,7 +979,7 @@ SmmRemoveInterfaceFromProtocol (
**/
BOOLEAN
SmmIsSchedulable (
- IN EFI_SMM_DRIVER_ENTRY *DriverEntry
+ IN EFI_SMM_DRIVER_ENTRY *DriverEntry
);
//
@@ -1018,8 +1018,8 @@ SmramProfileInstallProtocol (
**/
EFI_STATUS
RegisterSmramProfileImage (
- IN EFI_SMM_DRIVER_ENTRY *DriverEntry,
- IN BOOLEAN RegisterToDxe
+ IN EFI_SMM_DRIVER_ENTRY *DriverEntry,
+ IN BOOLEAN RegisterToDxe
);
/**
@@ -1036,8 +1036,8 @@ RegisterSmramProfileImage (
**/
EFI_STATUS
UnregisterSmramProfileImage (
- IN EFI_SMM_DRIVER_ENTRY *DriverEntry,
- IN BOOLEAN UnregisterToDxe
+ IN EFI_SMM_DRIVER_ENTRY *DriverEntry,
+ IN BOOLEAN UnregisterToDxe
);
/**
@@ -1171,12 +1171,12 @@ SmmCoreInitializeSmiHandlerProfile (
EFI_STATUS
EFIAPI
SmiHandlerProfileRegisterHandler (
- IN SMI_HANDLER_PROFILE_PROTOCOL *This,
- IN EFI_GUID *HandlerGuid,
- IN EFI_SMM_HANDLER_ENTRY_POINT2 Handler,
- IN PHYSICAL_ADDRESS CallerAddress,
- IN VOID *Context OPTIONAL,
- IN UINTN ContextSize OPTIONAL
+ IN SMI_HANDLER_PROFILE_PROTOCOL *This,
+ IN EFI_GUID *HandlerGuid,
+ IN EFI_SMM_HANDLER_ENTRY_POINT2 Handler,
+ IN PHYSICAL_ADDRESS CallerAddress,
+ IN VOID *Context OPTIONAL,
+ IN UINTN ContextSize OPTIONAL
);
/**
@@ -1199,17 +1199,17 @@ SmiHandlerProfileRegisterHandler (
EFI_STATUS
EFIAPI
SmiHandlerProfileUnregisterHandler (
- IN SMI_HANDLER_PROFILE_PROTOCOL *This,
- IN EFI_GUID *HandlerGuid,
- IN EFI_SMM_HANDLER_ENTRY_POINT2 Handler,
- IN VOID *Context OPTIONAL,
- IN UINTN ContextSize OPTIONAL
+ IN SMI_HANDLER_PROFILE_PROTOCOL *This,
+ IN EFI_GUID *HandlerGuid,
+ IN EFI_SMM_HANDLER_ENTRY_POINT2 Handler,
+ IN VOID *Context OPTIONAL,
+ IN UINTN ContextSize OPTIONAL
);
-extern UINTN mFullSmramRangeCount;
-extern EFI_SMRAM_DESCRIPTOR *mFullSmramRanges;
+extern UINTN mFullSmramRangeCount;
+extern EFI_SMRAM_DESCRIPTOR *mFullSmramRanges;
-extern EFI_SMM_DRIVER_ENTRY *mSmmCoreDriverEntry;
+extern EFI_SMM_DRIVER_ENTRY *mSmmCoreDriverEntry;
extern EFI_LOADED_IMAGE_PROTOCOL *mSmmCoreLoadedImage;
@@ -1218,8 +1218,8 @@ extern EFI_LOADED_IMAGE_PROTOCOL *mSmmCoreLoadedImage;
//
typedef struct {
- LIST_ENTRY Link;
- UINTN NumberOfPages;
+ LIST_ENTRY Link;
+ UINTN NumberOfPages;
} FREE_PAGE_LIST;
extern LIST_ENTRY mSmmMemoryMap;
@@ -1245,31 +1245,31 @@ extern LIST_ENTRY mSmmMemoryMap;
//
#define MAX_POOL_INDEX (MAX_POOL_SHIFT - MIN_POOL_SHIFT + 1)
-#define POOL_HEAD_SIGNATURE SIGNATURE_32('s','p','h','d')
+#define POOL_HEAD_SIGNATURE SIGNATURE_32('s','p','h','d')
typedef struct {
- UINT32 Signature;
- BOOLEAN Available;
- EFI_MEMORY_TYPE Type;
- UINTN Size;
+ UINT32 Signature;
+ BOOLEAN Available;
+ EFI_MEMORY_TYPE Type;
+ UINTN Size;
} POOL_HEADER;
-#define POOL_TAIL_SIGNATURE SIGNATURE_32('s','p','t','l')
+#define POOL_TAIL_SIGNATURE SIGNATURE_32('s','p','t','l')
typedef struct {
- UINT32 Signature;
- UINT32 Reserved;
- UINTN Size;
+ UINT32 Signature;
+ UINT32 Reserved;
+ UINTN Size;
} POOL_TAIL;
-#define POOL_OVERHEAD (sizeof(POOL_HEADER) + sizeof(POOL_TAIL))
+#define POOL_OVERHEAD (sizeof(POOL_HEADER) + sizeof(POOL_TAIL))
#define HEAD_TO_TAIL(a) \
((POOL_TAIL *) (((CHAR8 *) (a)) + (a)->Size - sizeof(POOL_TAIL)));
typedef struct {
- POOL_HEADER Header;
- LIST_ENTRY Link;
+ POOL_HEADER Header;
+ LIST_ENTRY Link;
} FREE_POOL_HEADER;
typedef enum {
@@ -1292,9 +1292,9 @@ extern LIST_ENTRY mSmmPoolLists[SmmPoolTypeMax][MAX_POOL_INDEX];
**/
UINTN
InternalAllocPagesOnOneNode (
- IN OUT FREE_PAGE_LIST *Pages,
- IN UINTN NumberOfPages,
- IN UINTN MaxAddress
+ IN OUT FREE_PAGE_LIST *Pages,
+ IN UINTN NumberOfPages,
+ IN UINTN MaxAddress
);
/**
diff --git a/MdeModulePkg/Core/PiSmmCore/PiSmmCorePrivateData.h b/MdeModulePkg/Core/PiSmmCore/PiSmmCorePrivateData.h
index 28f95d9b02..d8fe2dd9b9 100644
--- a/MdeModulePkg/Core/PiSmmCore/PiSmmCorePrivateData.h
+++ b/MdeModulePkg/Core/PiSmmCore/PiSmmCorePrivateData.h
@@ -42,26 +42,26 @@
/// thos structure.
///
typedef struct {
- UINTN Signature;
+ UINTN Signature;
///
/// The ImageHandle passed into the entry point of the SMM IPL. This ImageHandle
/// is used by the SMM Core to fill in the ParentImageHandle field of the Loaded
/// Image Protocol for each SMM Driver that is dispatched by the SMM Core.
///
- EFI_HANDLE SmmIplImageHandle;
+ EFI_HANDLE SmmIplImageHandle;
///
/// The number of SMRAM ranges passed from the SMM IPL to the SMM Core. The SMM
/// Core uses these ranges of SMRAM to initialize the SMM Core memory manager.
///
- UINTN SmramRangeCount;
+ UINTN SmramRangeCount;
///
/// A table of SMRAM ranges passed from the SMM IPL to the SMM Core. The SMM
/// Core uses these ranges of SMRAM to initialize the SMM Core memory manager.
///
- EFI_SMRAM_DESCRIPTOR *SmramRanges;
+ EFI_SMRAM_DESCRIPTOR *SmramRanges;
///
/// The SMM Foundation Entry Point. The SMM Core fills in this field when the
@@ -72,48 +72,48 @@ typedef struct {
/// the SMM Foundation Entry Point as soon as the SMM Configuration Protocol is
/// available.
///
- EFI_SMM_ENTRY_POINT SmmEntryPoint;
+ EFI_SMM_ENTRY_POINT SmmEntryPoint;
///
/// Boolean flag set to TRUE while an SMI is being processed by the SMM Core.
///
- BOOLEAN SmmEntryPointRegistered;
+ BOOLEAN SmmEntryPointRegistered;
///
/// Boolean flag set to TRUE while an SMI is being processed by the SMM Core.
///
- BOOLEAN InSmm;
+ BOOLEAN InSmm;
///
/// This field is set by the SMM Core then the SMM Core is initialized. This field is
/// used by the SMM Base 2 Protocol and SMM Communication Protocol implementations in
/// the SMM IPL.
///
- EFI_SMM_SYSTEM_TABLE2 *Smst;
+ EFI_SMM_SYSTEM_TABLE2 *Smst;
///
/// This field is used by the SMM Communication Protocol to pass a buffer into
/// a software SMI handler and for the software SMI handler to pass a buffer back to
/// the caller of the SMM Communication Protocol.
///
- VOID *CommunicationBuffer;
+ VOID *CommunicationBuffer;
///
/// This field is used by the SMM Communication Protocol to pass the size of a buffer,
/// in bytes, into a software SMI handler and for the software SMI handler to pass the
/// size, in bytes, of a buffer back to the caller of the SMM Communication Protocol.
///
- UINTN BufferSize;
+ UINTN BufferSize;
///
/// This field is used by the SMM Communication Protocol to pass the return status from
/// a software SMI handler back to the caller of the SMM Communication Protocol.
///
- EFI_STATUS ReturnStatus;
+ EFI_STATUS ReturnStatus;
- EFI_PHYSICAL_ADDRESS PiSmmCoreImageBase;
- UINT64 PiSmmCoreImageSize;
- EFI_PHYSICAL_ADDRESS PiSmmCoreEntryPoint;
+ EFI_PHYSICAL_ADDRESS PiSmmCoreImageBase;
+ UINT64 PiSmmCoreImageSize;
+ EFI_PHYSICAL_ADDRESS PiSmmCoreEntryPoint;
} SMM_CORE_PRIVATE_DATA;
#endif
diff --git a/MdeModulePkg/Core/PiSmmCore/PiSmmIpl.c b/MdeModulePkg/Core/PiSmmCore/PiSmmIpl.c
index e8e25c6c91..4f00cebaf5 100644
--- a/MdeModulePkg/Core/PiSmmCore/PiSmmIpl.c
+++ b/MdeModulePkg/Core/PiSmmCore/PiSmmIpl.c
@@ -140,10 +140,10 @@ SmmCommunicationCommunicate (
EFI_STATUS
EFIAPI
SmmCommunicationMmCommunicate2 (
- IN CONST EFI_MM_COMMUNICATION2_PROTOCOL *This,
- IN OUT VOID *CommBufferPhysical,
- IN OUT VOID *CommBufferVirtual,
- IN OUT UINTN *CommSize OPTIONAL
+ IN CONST EFI_MM_COMMUNICATION2_PROTOCOL *This,
+ IN OUT VOID *CommBufferPhysical,
+ IN OUT VOID *CommBufferVirtual,
+ IN OUT UINTN *CommSize OPTIONAL
);
/**
@@ -239,13 +239,13 @@ SmmIplSetVirtualAddressNotify (
// notifications required by the SMM IPL
//
typedef struct {
- BOOLEAN Protocol;
- BOOLEAN CloseOnLock;
- EFI_GUID *Guid;
- EFI_EVENT_NOTIFY NotifyFunction;
- VOID *NotifyContext;
- EFI_TPL NotifyTpl;
- EFI_EVENT Event;
+ BOOLEAN Protocol;
+ BOOLEAN CloseOnLock;
+ EFI_GUID *Guid;
+ EFI_EVENT_NOTIFY NotifyFunction;
+ VOID *NotifyContext;
+ EFI_TPL NotifyTpl;
+ EFI_EVENT Event;
} SMM_IPL_EVENT_NOTIFICATION;
//
@@ -309,8 +309,8 @@ BOOLEAN mEndOfDxe = FALSE;
EFI_PHYSICAL_ADDRESS mSmramCacheBase;
UINT64 mSmramCacheSize;
-EFI_SMM_COMMUNICATE_HEADER mCommunicateHeader;
-EFI_LOAD_FIXED_ADDRESS_CONFIGURATION_TABLE *mLMFAConfigurationTable = NULL;
+EFI_SMM_COMMUNICATE_HEADER mCommunicateHeader;
+EFI_LOAD_FIXED_ADDRESS_CONFIGURATION_TABLE *mLMFAConfigurationTable = NULL;
//
// Table of Protocol notification and GUIDed Event notifications that the SMM IPL requires
@@ -389,15 +389,15 @@ SMM_IPL_EVENT_NOTIFICATION mSmmIplEvents[] = {
**/
VOID
GetSmramCacheRange (
- IN EFI_SMRAM_DESCRIPTOR *SmramRange,
- OUT EFI_PHYSICAL_ADDRESS *SmramCacheBase,
- OUT UINT64 *SmramCacheSize
+ IN EFI_SMRAM_DESCRIPTOR *SmramRange,
+ OUT EFI_PHYSICAL_ADDRESS *SmramCacheBase,
+ OUT UINT64 *SmramCacheSize
)
{
- UINTN Index;
- EFI_PHYSICAL_ADDRESS RangeCpuStart;
- UINT64 RangePhysicalSize;
- BOOLEAN FoundAjacentRange;
+ UINTN Index;
+ EFI_PHYSICAL_ADDRESS RangeCpuStart;
+ UINT64 RangePhysicalSize;
+ BOOLEAN FoundAjacentRange;
*SmramCacheBase = SmramRange->CpuStart;
*SmramCacheSize = SmramRange->PhysicalSize;
@@ -407,17 +407,16 @@ GetSmramCacheRange (
for (Index = 0; Index < gSmmCorePrivate->SmramRangeCount; Index++) {
RangeCpuStart = gSmmCorePrivate->SmramRanges[Index].CpuStart;
RangePhysicalSize = gSmmCorePrivate->SmramRanges[Index].PhysicalSize;
- if (RangeCpuStart < *SmramCacheBase && *SmramCacheBase == (RangeCpuStart + RangePhysicalSize)) {
+ if ((RangeCpuStart < *SmramCacheBase) && (*SmramCacheBase == (RangeCpuStart + RangePhysicalSize))) {
*SmramCacheBase = RangeCpuStart;
*SmramCacheSize += RangePhysicalSize;
FoundAjacentRange = TRUE;
- } else if ((*SmramCacheBase + *SmramCacheSize) == RangeCpuStart && RangePhysicalSize > 0) {
+ } else if (((*SmramCacheBase + *SmramCacheSize) == RangeCpuStart) && (RangePhysicalSize > 0)) {
*SmramCacheSize += RangePhysicalSize;
FoundAjacentRange = TRUE;
}
}
} while (FoundAjacentRange);
-
}
/**
@@ -465,7 +464,7 @@ SmmBase2GetSmstLocation (
OUT EFI_SMM_SYSTEM_TABLE2 **Smst
)
{
- if ((This == NULL) ||(Smst == NULL)) {
+ if ((This == NULL) || (Smst == NULL)) {
return EFI_INVALID_PARAMETER;
}
@@ -524,7 +523,7 @@ SmmCommunicationCommunicate (
return EFI_INVALID_PARAMETER;
}
- CommunicateHeader = (EFI_SMM_COMMUNICATE_HEADER *) CommBuffer;
+ CommunicateHeader = (EFI_SMM_COMMUNICATE_HEADER *)CommBuffer;
if (CommSize == NULL) {
TempCommSize = OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data) + CommunicateHeader->MessageLength;
@@ -562,6 +561,7 @@ SmmCommunicationCommunicate (
if (CommSize != NULL) {
*CommSize = gSmmCorePrivate->BufferSize;
}
+
return gSmmCorePrivate->ReturnStatus;
}
@@ -571,7 +571,7 @@ SmmCommunicationCommunicate (
// has been called, then a direct invocation of the Software SMI is not allowed,
// so return EFI_INVALID_PARAMETER.
//
- if (EfiGoneVirtual()) {
+ if (EfiGoneVirtual ()) {
return EFI_INVALID_PARAMETER;
}
@@ -585,19 +585,19 @@ SmmCommunicationCommunicate (
//
// Save current InSmm state and set InSmm state to TRUE
//
- OldInSmm = gSmmCorePrivate->InSmm;
+ OldInSmm = gSmmCorePrivate->InSmm;
gSmmCorePrivate->InSmm = TRUE;
//
// Before SetVirtualAddressMap(), we are in SMM or SMRAM is open and unlocked, call SmiManage() directly.
//
TempCommSize -= OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data);
- Status = gSmmCorePrivate->Smst->SmiManage (
- &CommunicateHeader->HeaderGuid,
- NULL,
- CommunicateHeader->Data,
- &TempCommSize
- );
+ Status = gSmmCorePrivate->Smst->SmiManage (
+ &CommunicateHeader->HeaderGuid,
+ NULL,
+ CommunicateHeader->Data,
+ &TempCommSize
+ );
TempCommSize += OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data);
if (CommSize != NULL) {
*CommSize = TempCommSize;
@@ -638,15 +638,17 @@ SmmCommunicationCommunicate (
EFI_STATUS
EFIAPI
SmmCommunicationMmCommunicate2 (
- IN CONST EFI_MM_COMMUNICATION2_PROTOCOL *This,
- IN OUT VOID *CommBufferPhysical,
- IN OUT VOID *CommBufferVirtual,
- IN OUT UINTN *CommSize OPTIONAL
+ IN CONST EFI_MM_COMMUNICATION2_PROTOCOL *This,
+ IN OUT VOID *CommBufferPhysical,
+ IN OUT VOID *CommBufferVirtual,
+ IN OUT UINTN *CommSize OPTIONAL
)
{
- return SmmCommunicationCommunicate (&mSmmCommunication,
- CommBufferPhysical,
- CommSize);
+ return SmmCommunicationCommunicate (
+ &mSmmCommunication,
+ CommBufferPhysical,
+ CommSize
+ );
}
/**
@@ -663,14 +665,14 @@ SmmIplGuidedEventNotify (
IN VOID *Context
)
{
- UINTN Size;
+ UINTN Size;
//
// Use Guid to initialize EFI_SMM_COMMUNICATE_HEADER structure
//
CopyGuid (&mCommunicateHeader.HeaderGuid, (EFI_GUID *)Context);
mCommunicateHeader.MessageLength = 1;
- mCommunicateHeader.Data[0] = 0;
+ mCommunicateHeader.Data[0] = 0;
//
// Generate the Software SMI and return the result
@@ -710,8 +712,8 @@ SmmIplDxeDispatchEventNotify (
IN VOID *Context
)
{
- UINTN Size;
- EFI_STATUS Status;
+ UINTN Size;
+ EFI_STATUS Status;
//
// Keep calling the SMM Core Dispatcher until there is no request to restart it.
@@ -724,7 +726,7 @@ SmmIplDxeDispatchEventNotify (
//
CopyGuid (&mCommunicateHeader.HeaderGuid, (EFI_GUID *)Context);
mCommunicateHeader.MessageLength = 1;
- mCommunicateHeader.Data[0] = 0;
+ mCommunicateHeader.Data[0] = 0;
//
// Generate the Software SMI and return the result
@@ -911,89 +913,94 @@ SmmIplSetVirtualAddressNotify (
@retval EFI_NOT_FOUND The image has no assigned fixed loading address.
**/
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;
- EFI_PHYSICAL_ADDRESS FixLoadingAddress;
- UINT16 Index;
- UINTN Size;
- UINT16 NumberOfSections;
- EFI_PHYSICAL_ADDRESS SmramBase;
- UINT64 SmmCodeSize;
- UINT64 ValueInSectionHeader;
- //
- // Build tool will calculate the smm code size and then patch the PcdLoadFixAddressSmmCodePageNumber
- //
- SmmCodeSize = EFI_PAGES_TO_SIZE (PcdGet32(PcdLoadFixAddressSmmCodePageNumber));
-
- FixLoadingAddress = 0;
- Status = EFI_NOT_FOUND;
- SmramBase = mLMFAConfigurationTable->SmramBase;
- //
- // Get PeHeader pointer
- //
- ImgHdr = (EFI_IMAGE_OPTIONAL_HEADER_UNION *)((CHAR8* )ImageContext->Handle + 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;
- }
-
- Status = EFI_NOT_FOUND;
-
- if ((SectionHeader.Characteristics & EFI_IMAGE_SCN_CNT_CODE) == 0) {
- //
- // Build tool saves the offset to SMRAM base as image base in PointerToRelocations & PointerToLineNumbers fields in the
- // first section header that doesn't point to code section in 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) {
- //
- // Found first section header that doesn't point to code section in which build tool saves the
- // offset to SMRAM base as image base in PointerToRelocations & PointerToLineNumbers fields
- //
- FixLoadingAddress = (EFI_PHYSICAL_ADDRESS)(SmramBase + (INT64)ValueInSectionHeader);
-
- if (SmramBase + SmmCodeSize > FixLoadingAddress && SmramBase <= FixLoadingAddress) {
- //
- // The assigned address is valid. Return the specified loading address
- //
- ImageContext->ImageAddress = FixLoadingAddress;
- Status = EFI_SUCCESS;
- }
- }
- break;
- }
- SectionHeaderOffset += sizeof (EFI_IMAGE_SECTION_HEADER);
- }
- DEBUG ((DEBUG_INFO|DEBUG_LOAD, "LOADING MODULE FIXED INFO: Loading module at fixed address %x, Status = %r \n", FixLoadingAddress, Status));
- return Status;
+ UINTN SectionHeaderOffset;
+ EFI_STATUS Status;
+ EFI_IMAGE_SECTION_HEADER SectionHeader;
+ EFI_IMAGE_OPTIONAL_HEADER_UNION *ImgHdr;
+ EFI_PHYSICAL_ADDRESS FixLoadingAddress;
+ UINT16 Index;
+ UINTN Size;
+ UINT16 NumberOfSections;
+ EFI_PHYSICAL_ADDRESS SmramBase;
+ UINT64 SmmCodeSize;
+ UINT64 ValueInSectionHeader;
+
+ //
+ // Build tool will calculate the smm code size and then patch the PcdLoadFixAddressSmmCodePageNumber
+ //
+ SmmCodeSize = EFI_PAGES_TO_SIZE (PcdGet32 (PcdLoadFixAddressSmmCodePageNumber));
+
+ FixLoadingAddress = 0;
+ Status = EFI_NOT_FOUND;
+ SmramBase = mLMFAConfigurationTable->SmramBase;
+ //
+ // Get PeHeader pointer
+ //
+ ImgHdr = (EFI_IMAGE_OPTIONAL_HEADER_UNION *)((CHAR8 *)ImageContext->Handle + 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;
+ }
+
+ Status = EFI_NOT_FOUND;
+
+ if ((SectionHeader.Characteristics & EFI_IMAGE_SCN_CNT_CODE) == 0) {
+ //
+ // Build tool saves the offset to SMRAM base as image base in PointerToRelocations & PointerToLineNumbers fields in the
+ // first section header that doesn't point to code section in 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) {
+ //
+ // Found first section header that doesn't point to code section in which build tool saves the
+ // offset to SMRAM base as image base in PointerToRelocations & PointerToLineNumbers fields
+ //
+ FixLoadingAddress = (EFI_PHYSICAL_ADDRESS)(SmramBase + (INT64)ValueInSectionHeader);
+
+ if ((SmramBase + SmmCodeSize > FixLoadingAddress) && (SmramBase <= FixLoadingAddress)) {
+ //
+ // The assigned address is valid. Return the specified loading address
+ //
+ ImageContext->ImageAddress = FixLoadingAddress;
+ Status = EFI_SUCCESS;
+ }
+ }
+
+ break;
+ }
+
+ SectionHeaderOffset += sizeof (EFI_IMAGE_SECTION_HEADER);
+ }
+
+ DEBUG ((DEBUG_INFO|DEBUG_LOAD, "LOADING MODULE FIXED INFO: Loading module at fixed address %x, Status = %r \n", FixLoadingAddress, Status));
+ return Status;
}
+
/**
Load the SMM Core image into SMRAM and executes the SMM Core from SMRAM.
@@ -1009,9 +1016,9 @@ GetPeCoffImageFixLoadingAssignedAddress(
**/
EFI_STATUS
ExecuteSmmCoreFromSmram (
- IN OUT EFI_SMRAM_DESCRIPTOR *SmramRange,
- IN OUT EFI_SMRAM_DESCRIPTOR *SmramRangeSmmCore,
- IN VOID *Context
+ IN OUT EFI_SMRAM_DESCRIPTOR *SmramRange,
+ IN OUT EFI_SMRAM_DESCRIPTOR *SmramRangeSmmCore,
+ IN VOID *Context
)
{
EFI_STATUS Status;
@@ -1049,11 +1056,12 @@ ExecuteSmmCoreFromSmram (
if (EFI_ERROR (Status)) {
return Status;
}
+
//
// if Loading module at Fixed Address feature is enabled, the SMM core driver will be loaded to
// the address assigned by build tool.
//
- if (PcdGet64(PcdLoadModuleAtFixAddressEnable) != 0) {
+ if (PcdGet64 (PcdLoadModuleAtFixAddressEnable) != 0) {
//
// Get the fixed loading address assigned by Build tool
//
@@ -1066,23 +1074,23 @@ ExecuteSmmCoreFromSmram (
//
// Reserved Smram Region for SmmCore is not used, and remove it from SmramRangeCount.
//
- gSmmCorePrivate->SmramRangeCount --;
+ gSmmCorePrivate->SmramRangeCount--;
} else {
DEBUG ((DEBUG_INFO, "LOADING MODULE FIXED ERROR: Loading module at fixed address at address failed\n"));
//
// Allocate memory for the image being loaded from the EFI_SRAM_DESCRIPTOR
// specified by SmramRange
//
- PageCount = (UINTN)EFI_SIZE_TO_PAGES((UINTN)ImageContext.ImageSize + ImageContext.SectionAlignment);
+ PageCount = (UINTN)EFI_SIZE_TO_PAGES ((UINTN)ImageContext.ImageSize + ImageContext.SectionAlignment);
ASSERT ((SmramRange->PhysicalSize & EFI_PAGE_MASK) == 0);
ASSERT (SmramRange->PhysicalSize > EFI_PAGES_TO_SIZE (PageCount));
- SmramRange->PhysicalSize -= EFI_PAGES_TO_SIZE (PageCount);
- SmramRangeSmmCore->CpuStart = SmramRange->CpuStart + SmramRange->PhysicalSize;
+ SmramRange->PhysicalSize -= EFI_PAGES_TO_SIZE (PageCount);
+ SmramRangeSmmCore->CpuStart = SmramRange->CpuStart + SmramRange->PhysicalSize;
SmramRangeSmmCore->PhysicalStart = SmramRange->PhysicalStart + SmramRange->PhysicalSize;
- SmramRangeSmmCore->RegionState = SmramRange->RegionState | EFI_ALLOCATED;
- SmramRangeSmmCore->PhysicalSize = EFI_PAGES_TO_SIZE (PageCount);
+ SmramRangeSmmCore->RegionState = SmramRange->RegionState | EFI_ALLOCATED;
+ SmramRangeSmmCore->PhysicalSize = EFI_PAGES_TO_SIZE (PageCount);
//
// Align buffer on section boundary
@@ -1094,16 +1102,16 @@ ExecuteSmmCoreFromSmram (
// Allocate memory for the image being loaded from the EFI_SRAM_DESCRIPTOR
// specified by SmramRange
//
- PageCount = (UINTN)EFI_SIZE_TO_PAGES((UINTN)ImageContext.ImageSize + ImageContext.SectionAlignment);
+ PageCount = (UINTN)EFI_SIZE_TO_PAGES ((UINTN)ImageContext.ImageSize + ImageContext.SectionAlignment);
ASSERT ((SmramRange->PhysicalSize & EFI_PAGE_MASK) == 0);
ASSERT (SmramRange->PhysicalSize > EFI_PAGES_TO_SIZE (PageCount));
- SmramRange->PhysicalSize -= EFI_PAGES_TO_SIZE (PageCount);
- SmramRangeSmmCore->CpuStart = SmramRange->CpuStart + SmramRange->PhysicalSize;
+ SmramRange->PhysicalSize -= EFI_PAGES_TO_SIZE (PageCount);
+ SmramRangeSmmCore->CpuStart = SmramRange->CpuStart + SmramRange->PhysicalSize;
SmramRangeSmmCore->PhysicalStart = SmramRange->PhysicalStart + SmramRange->PhysicalSize;
- SmramRangeSmmCore->RegionState = SmramRange->RegionState | EFI_ALLOCATED;
- SmramRangeSmmCore->PhysicalSize = EFI_PAGES_TO_SIZE (PageCount);
+ SmramRangeSmmCore->RegionState = SmramRange->RegionState | EFI_ALLOCATED;
+ SmramRangeSmmCore->PhysicalSize = EFI_PAGES_TO_SIZE (PageCount);
//
// Align buffer on section boundary
@@ -1150,7 +1158,7 @@ ExecuteSmmCoreFromSmram (
// Execute image
//
EntryPoint = (EFI_IMAGE_ENTRY_POINT)(UINTN)ImageContext.EntryPoint;
- Status = EntryPoint ((EFI_HANDLE)Context, gST);
+ Status = EntryPoint ((EFI_HANDLE)Context, gST);
}
}
@@ -1188,14 +1196,15 @@ SmmSplitSmramEntry (
IN OUT UINTN *FinalRangeCount
)
{
- UINT64 RangeToCompareEnd;
- UINT64 ReservedRangeToCompareEnd;
+ UINT64 RangeToCompareEnd;
+ UINT64 ReservedRangeToCompareEnd;
RangeToCompareEnd = RangeToCompare->CpuStart + RangeToCompare->PhysicalSize;
ReservedRangeToCompareEnd = ReservedRangeToCompare->SmramReservedStart + ReservedRangeToCompare->SmramReservedSize;
if ((RangeToCompare->CpuStart >= ReservedRangeToCompare->SmramReservedStart) &&
- (RangeToCompare->CpuStart < ReservedRangeToCompareEnd)) {
+ (RangeToCompare->CpuStart < ReservedRangeToCompareEnd))
+ {
if (RangeToCompareEnd < ReservedRangeToCompareEnd) {
//
// RangeToCompare ReservedRangeToCompare
@@ -1222,14 +1231,14 @@ SmmSplitSmramEntry (
FinalRanges[*FinalRangeCount].PhysicalStart = RangeToCompare->PhysicalStart;
FinalRanges[*FinalRangeCount].RegionState = RangeToCompare->RegionState | EFI_ALLOCATED;
FinalRanges[*FinalRangeCount].PhysicalSize = RangeToCompare->PhysicalSize;
- *FinalRangeCount += 1;
- RangeToCompare->PhysicalSize = 0;
+ *FinalRangeCount += 1;
+ RangeToCompare->PhysicalSize = 0;
//
// 3. Update ReservedRanges[*ReservedRangeCount] and increment *ReservedRangeCount.
//
ReservedRanges[*ReservedRangeCount].SmramReservedStart = FinalRanges[*FinalRangeCount - 1].CpuStart + FinalRanges[*FinalRangeCount - 1].PhysicalSize;
ReservedRanges[*ReservedRangeCount].SmramReservedSize = ReservedRangeToCompareEnd - RangeToCompareEnd;
- *ReservedRangeCount += 1;
+ *ReservedRangeCount += 1;
} else {
//
// RangeToCompare ReservedRangeToCompare
@@ -1255,7 +1264,7 @@ SmmSplitSmramEntry (
FinalRanges[*FinalRangeCount].PhysicalStart = RangeToCompare->PhysicalStart;
FinalRanges[*FinalRangeCount].RegionState = RangeToCompare->RegionState | EFI_ALLOCATED;
FinalRanges[*FinalRangeCount].PhysicalSize = ReservedRangeToCompareEnd - RangeToCompare->CpuStart;
- *FinalRangeCount += 1;
+ *FinalRangeCount += 1;
//
// 3. Update RangeToCompare.
//
@@ -1264,7 +1273,8 @@ SmmSplitSmramEntry (
RangeToCompare->PhysicalSize -= FinalRanges[*FinalRangeCount - 1].PhysicalSize;
}
} else if ((ReservedRangeToCompare->SmramReservedStart >= RangeToCompare->CpuStart) &&
- (ReservedRangeToCompare->SmramReservedStart < RangeToCompareEnd)) {
+ (ReservedRangeToCompare->SmramReservedStart < RangeToCompareEnd))
+ {
if (ReservedRangeToCompareEnd < RangeToCompareEnd) {
//
// RangeToCompare ReservedRangeToCompare
@@ -1291,8 +1301,8 @@ SmmSplitSmramEntry (
FinalRanges[*FinalRangeCount].PhysicalStart = RangeToCompare->PhysicalStart + RangeToCompare->PhysicalSize;
FinalRanges[*FinalRangeCount].RegionState = RangeToCompare->RegionState | EFI_ALLOCATED;
FinalRanges[*FinalRangeCount].PhysicalSize = ReservedRangeToCompare->SmramReservedSize;
- *FinalRangeCount += 1;
- ReservedRangeToCompare->SmramReservedSize = 0;
+ *FinalRangeCount += 1;
+ ReservedRangeToCompare->SmramReservedSize = 0;
//
// 3. Update Ranges[*RangeCount] and increment *RangeCount.
//
@@ -1300,7 +1310,7 @@ SmmSplitSmramEntry (
Ranges[*RangeCount].PhysicalStart = FinalRanges[*FinalRangeCount - 1].PhysicalStart + FinalRanges[*FinalRangeCount - 1].PhysicalSize;
Ranges[*RangeCount].RegionState = RangeToCompare->RegionState;
Ranges[*RangeCount].PhysicalSize = RangeToCompareEnd - ReservedRangeToCompareEnd;
- *RangeCount += 1;
+ *RangeCount += 1;
} else {
//
// RangeToCompare ReservedRangeToCompare
@@ -1327,7 +1337,7 @@ SmmSplitSmramEntry (
FinalRanges[*FinalRangeCount].PhysicalStart = RangeToCompare->PhysicalStart + RangeToCompare->PhysicalSize;
FinalRanges[*FinalRangeCount].RegionState = RangeToCompare->RegionState | EFI_ALLOCATED;
FinalRanges[*FinalRangeCount].PhysicalSize = RangeToCompareEnd - ReservedRangeToCompare->SmramReservedStart;
- *FinalRangeCount += 1;
+ *FinalRangeCount += 1;
//
// 3. Update ReservedRangeToCompare.
//
@@ -1353,19 +1363,22 @@ SmmIsSmramOverlap (
IN EFI_SMM_RESERVED_SMRAM_REGION *ReservedRangeToCompare
)
{
- UINT64 RangeToCompareEnd;
- UINT64 ReservedRangeToCompareEnd;
+ UINT64 RangeToCompareEnd;
+ UINT64 ReservedRangeToCompareEnd;
RangeToCompareEnd = RangeToCompare->CpuStart + RangeToCompare->PhysicalSize;
ReservedRangeToCompareEnd = ReservedRangeToCompare->SmramReservedStart + ReservedRangeToCompare->SmramReservedSize;
if ((RangeToCompare->CpuStart >= ReservedRangeToCompare->SmramReservedStart) &&
- (RangeToCompare->CpuStart < ReservedRangeToCompareEnd)) {
+ (RangeToCompare->CpuStart < ReservedRangeToCompareEnd))
+ {
return TRUE;
} else if ((ReservedRangeToCompare->SmramReservedStart >= RangeToCompare->CpuStart) &&
- (ReservedRangeToCompare->SmramReservedStart < RangeToCompareEnd)) {
+ (ReservedRangeToCompare->SmramReservedStart < RangeToCompareEnd))
+ {
return TRUE;
}
+
return FALSE;
}
@@ -1383,35 +1396,35 @@ SmmIsSmramOverlap (
**/
EFI_SMRAM_DESCRIPTOR *
GetFullSmramRanges (
- OUT UINTN *FullSmramRangeCount
+ OUT UINTN *FullSmramRangeCount
)
{
- EFI_STATUS Status;
- EFI_SMM_CONFIGURATION_PROTOCOL *SmmConfiguration;
- UINTN Size;
- UINTN Index;
- UINTN Index2;
- EFI_SMRAM_DESCRIPTOR *FullSmramRanges;
- UINTN TempSmramRangeCount;
- UINTN AdditionSmramRangeCount;
- EFI_SMRAM_DESCRIPTOR *TempSmramRanges;
- UINTN SmramRangeCount;
- EFI_SMRAM_DESCRIPTOR *SmramRanges;
- UINTN SmramReservedCount;
- EFI_SMM_RESERVED_SMRAM_REGION *SmramReservedRanges;
- UINTN MaxCount;
- BOOLEAN Rescan;
+ EFI_STATUS Status;
+ EFI_SMM_CONFIGURATION_PROTOCOL *SmmConfiguration;
+ UINTN Size;
+ UINTN Index;
+ UINTN Index2;
+ EFI_SMRAM_DESCRIPTOR *FullSmramRanges;
+ UINTN TempSmramRangeCount;
+ UINTN AdditionSmramRangeCount;
+ EFI_SMRAM_DESCRIPTOR *TempSmramRanges;
+ UINTN SmramRangeCount;
+ EFI_SMRAM_DESCRIPTOR *SmramRanges;
+ UINTN SmramReservedCount;
+ EFI_SMM_RESERVED_SMRAM_REGION *SmramReservedRanges;
+ UINTN MaxCount;
+ BOOLEAN Rescan;
//
// Get SMM Configuration Protocol if it is present.
//
SmmConfiguration = NULL;
- Status = gBS->LocateProtocol (&gEfiSmmConfigurationProtocolGuid, NULL, (VOID **) &SmmConfiguration);
+ Status = gBS->LocateProtocol (&gEfiSmmConfigurationProtocolGuid, NULL, (VOID **)&SmmConfiguration);
//
// Get SMRAM information.
//
- Size = 0;
+ Size = 0;
Status = mSmmAccess->GetCapabilities (mSmmAccess, &Size, NULL);
ASSERT (Status == EFI_BUFFER_TOO_SMALL);
@@ -1431,7 +1444,7 @@ GetFullSmramRanges (
// Reserve one entry for SMM Core in the full SMRAM ranges.
//
AdditionSmramRangeCount = 1;
- if (PcdGet64(PcdLoadModuleAtFixAddressEnable) != 0) {
+ if (PcdGet64 (PcdLoadModuleAtFixAddressEnable) != 0) {
//
// Reserve two entries for all SMM drivers and SMM Core in the full SMRAM ranges.
//
@@ -1443,8 +1456,8 @@ GetFullSmramRanges (
// No reserved SMRAM entry from SMM Configuration Protocol.
//
*FullSmramRangeCount = SmramRangeCount + AdditionSmramRangeCount;
- Size = (*FullSmramRangeCount) * sizeof (EFI_SMRAM_DESCRIPTOR);
- FullSmramRanges = (EFI_SMRAM_DESCRIPTOR *) AllocateZeroPool (Size);
+ Size = (*FullSmramRangeCount) * sizeof (EFI_SMRAM_DESCRIPTOR);
+ FullSmramRanges = (EFI_SMRAM_DESCRIPTOR *)AllocateZeroPool (Size);
ASSERT (FullSmramRanges != NULL);
Status = mSmmAccess->GetCapabilities (mSmmAccess, &Size, FullSmramRanges);
@@ -1490,19 +1503,19 @@ GetFullSmramRanges (
//
MaxCount = SmramRangeCount + 2 * SmramReservedCount;
- Size = MaxCount * sizeof (EFI_SMM_RESERVED_SMRAM_REGION);
- SmramReservedRanges = (EFI_SMM_RESERVED_SMRAM_REGION *) AllocatePool (Size);
+ Size = MaxCount * sizeof (EFI_SMM_RESERVED_SMRAM_REGION);
+ SmramReservedRanges = (EFI_SMM_RESERVED_SMRAM_REGION *)AllocatePool (Size);
ASSERT (SmramReservedRanges != NULL);
for (Index = 0; Index < SmramReservedCount; Index++) {
CopyMem (&SmramReservedRanges[Index], &SmmConfiguration->SmramReservedRegions[Index], sizeof (EFI_SMM_RESERVED_SMRAM_REGION));
}
- Size = MaxCount * sizeof (EFI_SMRAM_DESCRIPTOR);
- TempSmramRanges = (EFI_SMRAM_DESCRIPTOR *) AllocatePool (Size);
+ Size = MaxCount * sizeof (EFI_SMRAM_DESCRIPTOR);
+ TempSmramRanges = (EFI_SMRAM_DESCRIPTOR *)AllocatePool (Size);
ASSERT (TempSmramRanges != NULL);
TempSmramRangeCount = 0;
- SmramRanges = (EFI_SMRAM_DESCRIPTOR *) AllocatePool (Size);
+ SmramRanges = (EFI_SMRAM_DESCRIPTOR *)AllocatePool (Size);
ASSERT (SmramRanges != NULL);
Status = mSmmAccess->GetCapabilities (mSmmAccess, &Size, SmramRanges);
ASSERT_EFI_ERROR (Status);
@@ -1522,7 +1535,8 @@ GetFullSmramRanges (
if (SmmIsSmramOverlap (
&SmramRanges[Index],
&SmramReservedRanges[Index2]
- )) {
+ ))
+ {
//
// There is overlap, need to split entry and then rescan.
//
@@ -1540,6 +1554,7 @@ GetFullSmramRanges (
}
}
}
+
if (!Rescan) {
//
// No any overlap, copy the entry to the temp SMRAM ranges.
@@ -1551,6 +1566,7 @@ GetFullSmramRanges (
}
}
} while (Rescan);
+
ASSERT (TempSmramRangeCount <= MaxCount);
//
@@ -1565,16 +1581,19 @@ GetFullSmramRanges (
break;
}
}
+
ASSERT (Index < TempSmramRangeCount);
for (Index2 = 0; Index2 < TempSmramRangeCount; Index2++) {
if ((Index2 != Index) && (TempSmramRanges[Index2].PhysicalSize != 0) && (TempSmramRanges[Index2].CpuStart < TempSmramRanges[Index].CpuStart)) {
Index = Index2;
}
}
+
CopyMem (&FullSmramRanges[*FullSmramRangeCount], &TempSmramRanges[Index], sizeof (EFI_SMRAM_DESCRIPTOR));
- *FullSmramRangeCount += 1;
+ *FullSmramRangeCount += 1;
TempSmramRanges[Index].PhysicalSize = 0;
} while (*FullSmramRangeCount < TempSmramRangeCount);
+
ASSERT (*FullSmramRangeCount == TempSmramRangeCount);
*FullSmramRangeCount += AdditionSmramRangeCount;
@@ -1606,15 +1625,15 @@ SmmIplEntry (
IN EFI_SYSTEM_TABLE *SystemTable
)
{
- EFI_STATUS Status;
- UINTN Index;
- UINT64 MaxSize;
- VOID *Registration;
- UINT64 SmmCodeSize;
- EFI_CPU_ARCH_PROTOCOL *CpuArch;
- EFI_STATUS SetAttrStatus;
- EFI_SMRAM_DESCRIPTOR *SmramRangeSmmDriver;
- EFI_GCD_MEMORY_SPACE_DESCRIPTOR MemDesc;
+ EFI_STATUS Status;
+ UINTN Index;
+ UINT64 MaxSize;
+ VOID *Registration;
+ UINT64 SmmCodeSize;
+ EFI_CPU_ARCH_PROTOCOL *CpuArch;
+ EFI_STATUS SetAttrStatus;
+ EFI_SMRAM_DESCRIPTOR *SmramRangeSmmDriver;
+ EFI_GCD_MEMORY_SPACE_DESCRIPTOR MemDesc;
//
// Fill in the image handle of the SMM IPL so the SMM Core can use this as the
@@ -1663,7 +1682,7 @@ SmmIplEntry (
if (gSmmCorePrivate->SmramRanges[Index].CpuStart >= BASE_1MB) {
if ((gSmmCorePrivate->SmramRanges[Index].CpuStart + gSmmCorePrivate->SmramRanges[Index].PhysicalSize - 1) <= MAX_ADDRESS) {
if (gSmmCorePrivate->SmramRanges[Index].PhysicalSize >= MaxSize) {
- MaxSize = gSmmCorePrivate->SmramRanges[Index].PhysicalSize;
+ MaxSize = gSmmCorePrivate->SmramRanges[Index].PhysicalSize;
mCurrentSmramRange = &gSmmCorePrivate->SmramRanges[Index];
}
}
@@ -1674,7 +1693,9 @@ SmmIplEntry (
//
// Print debug message showing SMRAM window that will be used by SMM IPL and SMM Core
//
- DEBUG ((DEBUG_INFO, "SMM IPL found SMRAM window %p - %p\n",
+ DEBUG ((
+ DEBUG_INFO,
+ "SMM IPL found SMRAM window %p - %p\n",
(VOID *)(UINTN)mCurrentSmramRange->CpuStart,
(VOID *)(UINTN)(mCurrentSmramRange->CpuStart + mCurrentSmramRange->PhysicalSize - 1)
));
@@ -1695,6 +1716,7 @@ SmmIplEntry (
MemDesc.Capabilities | SMRAM_CAPABILITIES
);
}
+
//
// If CPU AP is present, attempt to set SMRAM cacheability to WB and clear
// all paging attributes.
@@ -1702,15 +1724,15 @@ SmmIplEntry (
// is not available here.
//
CpuArch = NULL;
- Status = gBS->LocateProtocol (&gEfiCpuArchProtocolGuid, NULL, (VOID **)&CpuArch);
+ Status = gBS->LocateProtocol (&gEfiCpuArchProtocolGuid, NULL, (VOID **)&CpuArch);
if (!EFI_ERROR (Status)) {
MemDesc.Attributes &= ~(EFI_CACHE_ATTRIBUTE_MASK | EFI_MEMORY_ATTRIBUTE_MASK);
MemDesc.Attributes |= EFI_MEMORY_WB;
- Status = gDS->SetMemorySpaceAttributes (
- mSmramCacheBase,
- mSmramCacheSize,
- MemDesc.Attributes
- );
+ Status = gDS->SetMemorySpaceAttributes (
+ mSmramCacheBase,
+ mSmramCacheSize,
+ MemDesc.Attributes
+ );
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_WARN, "SMM IPL failed to set SMRAM window to EFI_MEMORY_WB\n"));
}
@@ -1722,17 +1744,18 @@ SmmIplEntry (
);
DEBUG ((DEBUG_INFO, "SMRAM attributes: %016lx\n", MemDesc.Attributes));
ASSERT ((MemDesc.Attributes & EFI_MEMORY_ATTRIBUTE_MASK) == 0);
- );
+ );
}
+
//
// if Loading module at Fixed Address feature is enabled, save the SMRAM base to Load
// Modules At Fixed Address Configuration Table.
//
- if (PcdGet64(PcdLoadModuleAtFixAddressEnable) != 0) {
+ if (PcdGet64 (PcdLoadModuleAtFixAddressEnable) != 0) {
//
// Build tool will calculate the smm code size and then patch the PcdLoadFixAddressSmmCodePageNumber
//
- SmmCodeSize = LShiftU64 (PcdGet32(PcdLoadFixAddressSmmCodePageNumber), EFI_PAGE_SHIFT);
+ SmmCodeSize = LShiftU64 (PcdGet32 (PcdLoadFixAddressSmmCodePageNumber), EFI_PAGE_SHIFT);
//
// The SMRAM available memory is assumed to be larger than SmmCodeSize
//
@@ -1741,10 +1764,10 @@ SmmIplEntry (
// Retrieve Load modules At fixed address configuration table and save the SMRAM base.
//
Status = EfiGetSystemConfigurationTable (
- &gLoadFixedAddressConfigurationTableGuid,
- (VOID **) &mLMFAConfigurationTable
- );
- if (!EFI_ERROR (Status) && mLMFAConfigurationTable != NULL) {
+ &gLoadFixedAddressConfigurationTableGuid,
+ (VOID **)&mLMFAConfigurationTable
+ );
+ if (!EFI_ERROR (Status) && (mLMFAConfigurationTable != NULL)) {
mLMFAConfigurationTable->SmramBase = mCurrentSmramRange->CpuStart;
//
// Print the SMRAM base
@@ -1755,16 +1778,17 @@ SmmIplEntry (
//
// Fill the Smram range for all SMM code
//
- SmramRangeSmmDriver = &gSmmCorePrivate->SmramRanges[gSmmCorePrivate->SmramRangeCount - 2];
+ SmramRangeSmmDriver = &gSmmCorePrivate->SmramRanges[gSmmCorePrivate->SmramRangeCount - 2];
SmramRangeSmmDriver->CpuStart = mCurrentSmramRange->CpuStart;
SmramRangeSmmDriver->PhysicalStart = mCurrentSmramRange->PhysicalStart;
SmramRangeSmmDriver->RegionState = mCurrentSmramRange->RegionState | EFI_ALLOCATED;
SmramRangeSmmDriver->PhysicalSize = SmmCodeSize;
- mCurrentSmramRange->PhysicalSize -= SmmCodeSize;
- mCurrentSmramRange->CpuStart = mCurrentSmramRange->CpuStart + SmmCodeSize;
- mCurrentSmramRange->PhysicalStart = mCurrentSmramRange->PhysicalStart + SmmCodeSize;
+ mCurrentSmramRange->PhysicalSize -= SmmCodeSize;
+ mCurrentSmramRange->CpuStart = mCurrentSmramRange->CpuStart + SmmCodeSize;
+ mCurrentSmramRange->PhysicalStart = mCurrentSmramRange->PhysicalStart + SmmCodeSize;
}
+
//
// Load SMM Core into SMRAM and execute it from SMRAM
//
@@ -1783,7 +1807,7 @@ SmmIplEntry (
// Attempt to reset SMRAM cacheability to UC
//
if (CpuArch != NULL) {
- SetAttrStatus = gDS->SetMemorySpaceAttributes(
+ SetAttrStatus = gDS->SetMemorySpaceAttributes (
mSmramCacheBase,
mSmramCacheSize,
EFI_MEMORY_UC
@@ -1804,7 +1828,7 @@ SmmIplEntry (
// If the SMM Core could not be loaded then close SMRAM window, free allocated
// resources, and return an error so SMM IPL will be unloaded.
//
- if (mCurrentSmramRange == NULL || EFI_ERROR (Status)) {
+ if ((mCurrentSmramRange == NULL) || EFI_ERROR (Status)) {
//
// Close all SMRAM ranges
//
@@ -1829,9 +1853,12 @@ SmmIplEntry (
//
Status = gBS->InstallMultipleProtocolInterfaces (
&mSmmIplHandle,
- &gEfiSmmBase2ProtocolGuid, &mSmmBase2,
- &gEfiSmmCommunicationProtocolGuid, &mSmmCommunication,
- &gEfiMmCommunication2ProtocolGuid, &mMmCommunication2,
+ &gEfiSmmBase2ProtocolGuid,
+ &mSmmBase2,
+ &gEfiSmmCommunicationProtocolGuid,
+ &mSmmCommunication,
+ &gEfiMmCommunication2ProtocolGuid,
+ &mMmCommunication2,
NULL
);
ASSERT_EFI_ERROR (Status);
@@ -1846,8 +1873,8 @@ SmmIplEntry (
mSmmIplEvents[Index].NotifyTpl,
mSmmIplEvents[Index].NotifyFunction,
mSmmIplEvents[Index].NotifyContext,
- &Registration
- );
+ &Registration
+ );
} else {
Status = gBS->CreateEventEx (
EVT_NOTIFY_SIGNAL,
diff --git a/MdeModulePkg/Core/PiSmmCore/Pool.c b/MdeModulePkg/Core/PiSmmCore/Pool.c
index a503ff51f5..96ebe811c6 100644
--- a/MdeModulePkg/Core/PiSmmCore/Pool.c
+++ b/MdeModulePkg/Core/PiSmmCore/Pool.c
@@ -13,7 +13,7 @@ LIST_ENTRY mSmmPoolLists[SmmPoolTypeMax][MAX_POOL_INDEX];
// To cache the SMRAM base since when Loading modules At fixed address feature is enabled,
// all module is assigned an offset relative the SMRAM base in build time.
//
-GLOBAL_REMOVE_IF_UNREFERENCED EFI_PHYSICAL_ADDRESS gLoadModuleAtFixAddressSmramBase = 0;
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_PHYSICAL_ADDRESS gLoadModuleAtFixAddressSmramBase = 0;
/**
Convert a UEFI memory type to SMM pool type.
@@ -24,21 +24,20 @@ GLOBAL_REMOVE_IF_UNREFERENCED EFI_PHYSICAL_ADDRESS gLoadModuleAtFixAddres
**/
SMM_POOL_TYPE
UefiMemoryTypeToSmmPoolType (
- IN EFI_MEMORY_TYPE MemoryType
+ IN EFI_MEMORY_TYPE MemoryType
)
{
ASSERT ((MemoryType == EfiRuntimeServicesCode) || (MemoryType == EfiRuntimeServicesData));
switch (MemoryType) {
- case EfiRuntimeServicesCode:
- return SmmPoolTypeCode;
- case EfiRuntimeServicesData:
- return SmmPoolTypeData;
- default:
- return SmmPoolTypeMax;
+ case EfiRuntimeServicesCode:
+ return SmmPoolTypeCode;
+ case EfiRuntimeServicesData:
+ return SmmPoolTypeData;
+ default:
+ return SmmPoolTypeMax;
}
}
-
/**
Called to initialize the memory service.
@@ -52,10 +51,10 @@ SmmInitializeMemoryServices (
IN EFI_SMRAM_DESCRIPTOR *SmramRanges
)
{
- UINTN Index;
- EFI_STATUS Status;
- UINTN SmmPoolTypeIndex;
- EFI_LOAD_FIXED_ADDRESS_CONFIGURATION_TABLE *LMFAConfigurationTable;
+ UINTN Index;
+ EFI_STATUS Status;
+ UINTN SmmPoolTypeIndex;
+ EFI_LOAD_FIXED_ADDRESS_CONFIGURATION_TABLE *LMFAConfigurationTable;
//
// Initialize Pool list
@@ -67,10 +66,10 @@ SmmInitializeMemoryServices (
}
Status = EfiGetSystemConfigurationTable (
- &gLoadFixedAddressConfigurationTableGuid,
- (VOID **) &LMFAConfigurationTable
- );
- if (!EFI_ERROR (Status) && LMFAConfigurationTable != NULL) {
+ &gLoadFixedAddressConfigurationTableGuid,
+ (VOID **)&LMFAConfigurationTable
+ );
+ if (!EFI_ERROR (Status) && (LMFAConfigurationTable != NULL)) {
gLoadModuleAtFixAddressSmramBase = LMFAConfigurationTable->SmramBase;
}
@@ -82,6 +81,7 @@ SmmInitializeMemoryServices (
if ((SmramRanges[Index].RegionState & (EFI_ALLOCATED | EFI_NEEDS_TESTING | EFI_NEEDS_ECC_INITIALIZATION)) != 0) {
continue;
}
+
SmmAddMemoryRegion (
SmramRanges[Index].CpuStart,
SmramRanges[Index].PhysicalSize,
@@ -97,6 +97,7 @@ SmmInitializeMemoryServices (
if ((SmramRanges[Index].RegionState & (EFI_ALLOCATED | EFI_NEEDS_TESTING | EFI_NEEDS_ECC_INITIALIZATION)) == 0) {
continue;
}
+
SmmAddMemoryRegion (
SmramRanges[Index].CpuStart,
SmramRanges[Index].PhysicalSize,
@@ -104,7 +105,6 @@ SmmInitializeMemoryServices (
SmramRanges[Index].RegionState
);
}
-
}
/**
@@ -132,19 +132,24 @@ InternalAllocPoolByIndex (
SMM_POOL_TYPE SmmPoolType;
Address = 0;
- SmmPoolType = UefiMemoryTypeToSmmPoolType(PoolType);
+ SmmPoolType = UefiMemoryTypeToSmmPoolType (PoolType);
ASSERT (PoolIndex <= MAX_POOL_INDEX);
Status = EFI_SUCCESS;
- Hdr = NULL;
+ Hdr = NULL;
if (PoolIndex == MAX_POOL_INDEX) {
- Status = SmmInternalAllocatePages (AllocateAnyPages, PoolType,
- EFI_SIZE_TO_PAGES (MAX_POOL_SIZE << 1),
- &Address, FALSE);
+ Status = SmmInternalAllocatePages (
+ AllocateAnyPages,
+ PoolType,
+ EFI_SIZE_TO_PAGES (MAX_POOL_SIZE << 1),
+ &Address,
+ FALSE
+ );
if (EFI_ERROR (Status)) {
return EFI_OUT_OF_RESOURCES;
}
- Hdr = (FREE_POOL_HEADER *) (UINTN) Address;
+
+ Hdr = (FREE_POOL_HEADER *)(UINTN)Address;
} else if (!IsListEmpty (&mSmmPoolLists[SmmPoolType][PoolIndex])) {
Hdr = BASE_CR (GetFirstNode (&mSmmPoolLists[SmmPoolType][PoolIndex]), FREE_POOL_HEADER, Link);
RemoveEntryList (&Hdr->Link);
@@ -152,25 +157,25 @@ InternalAllocPoolByIndex (
Status = InternalAllocPoolByIndex (PoolType, PoolIndex + 1, &Hdr);
if (!EFI_ERROR (Status)) {
Hdr->Header.Signature = 0;
- Hdr->Header.Size >>= 1;
+ Hdr->Header.Size >>= 1;
Hdr->Header.Available = TRUE;
- Hdr->Header.Type = 0;
- Tail = HEAD_TO_TAIL(&Hdr->Header);
- Tail->Signature = 0;
- Tail->Size = 0;
+ Hdr->Header.Type = 0;
+ Tail = HEAD_TO_TAIL (&Hdr->Header);
+ Tail->Signature = 0;
+ Tail->Size = 0;
InsertHeadList (&mSmmPoolLists[SmmPoolType][PoolIndex], &Hdr->Link);
- Hdr = (FREE_POOL_HEADER*)((UINT8*)Hdr + Hdr->Header.Size);
+ Hdr = (FREE_POOL_HEADER *)((UINT8 *)Hdr + Hdr->Header.Size);
}
}
if (!EFI_ERROR (Status)) {
Hdr->Header.Signature = POOL_HEAD_SIGNATURE;
- Hdr->Header.Size = MIN_POOL_SIZE << PoolIndex;
+ Hdr->Header.Size = MIN_POOL_SIZE << PoolIndex;
Hdr->Header.Available = FALSE;
- Hdr->Header.Type = PoolType;
- Tail = HEAD_TO_TAIL(&Hdr->Header);
- Tail->Signature = POOL_TAIL_SIGNATURE;
- Tail->Size = Hdr->Header.Size;
+ Hdr->Header.Type = PoolType;
+ Tail = HEAD_TO_TAIL (&Hdr->Header);
+ Tail->Signature = POOL_TAIL_SIGNATURE;
+ Tail->Size = Hdr->Header.Size;
}
*FreePoolHdr = Hdr;
@@ -192,21 +197,21 @@ InternalFreePoolByIndex (
IN POOL_TAIL *PoolTail
)
{
- UINTN PoolIndex;
- SMM_POOL_TYPE SmmPoolType;
+ UINTN PoolIndex;
+ SMM_POOL_TYPE SmmPoolType;
ASSERT ((FreePoolHdr->Header.Size & (FreePoolHdr->Header.Size - 1)) == 0);
ASSERT (((UINTN)FreePoolHdr & (FreePoolHdr->Header.Size - 1)) == 0);
ASSERT (FreePoolHdr->Header.Size >= MIN_POOL_SIZE);
- SmmPoolType = UefiMemoryTypeToSmmPoolType(FreePoolHdr->Header.Type);
+ SmmPoolType = UefiMemoryTypeToSmmPoolType (FreePoolHdr->Header.Type);
- PoolIndex = (UINTN) (HighBitSet32 ((UINT32)FreePoolHdr->Header.Size) - MIN_POOL_SHIFT);
+ PoolIndex = (UINTN)(HighBitSet32 ((UINT32)FreePoolHdr->Header.Size) - MIN_POOL_SHIFT);
FreePoolHdr->Header.Signature = 0;
FreePoolHdr->Header.Available = TRUE;
- FreePoolHdr->Header.Type = 0;
- PoolTail->Signature = 0;
- PoolTail->Size = 0;
+ FreePoolHdr->Header.Type = 0;
+ PoolTail->Signature = 0;
+ PoolTail->Size = 0;
ASSERT (PoolIndex < MAX_POOL_INDEX);
InsertHeadList (&mSmmPoolLists[SmmPoolType][PoolIndex], &FreePoolHdr->Link);
return EFI_SUCCESS;
@@ -245,8 +250,9 @@ SmmInternalAllocatePool (
Address = 0;
- if (PoolType != EfiRuntimeServicesCode &&
- PoolType != EfiRuntimeServicesData) {
+ if ((PoolType != EfiRuntimeServicesCode) &&
+ (PoolType != EfiRuntimeServicesData))
+ {
return EFI_INVALID_PARAMETER;
}
@@ -258,14 +264,19 @@ SmmInternalAllocatePool (
// Adjust the size by the pool header & tail overhead
//
Size += POOL_OVERHEAD;
- if (Size > MAX_POOL_SIZE || NeedGuard) {
+ if ((Size > MAX_POOL_SIZE) || NeedGuard) {
if (!HasPoolTail) {
Size -= sizeof (POOL_TAIL);
}
NoPages = EFI_SIZE_TO_PAGES (Size);
- Status = SmmInternalAllocatePages (AllocateAnyPages, PoolType, NoPages,
- &Address, NeedGuard);
+ Status = SmmInternalAllocatePages (
+ AllocateAnyPages,
+ PoolType,
+ NoPages,
+ &Address,
+ NeedGuard
+ );
if (EFI_ERROR (Status)) {
return Status;
}
@@ -279,32 +290,33 @@ SmmInternalAllocatePool (
);
}
- PoolHdr = (POOL_HEADER*)(UINTN)Address;
+ PoolHdr = (POOL_HEADER *)(UINTN)Address;
PoolHdr->Signature = POOL_HEAD_SIGNATURE;
- PoolHdr->Size = EFI_PAGES_TO_SIZE (NoPages);
+ PoolHdr->Size = EFI_PAGES_TO_SIZE (NoPages);
PoolHdr->Available = FALSE;
- PoolHdr->Type = PoolType;
+ PoolHdr->Type = PoolType;
if (HasPoolTail) {
- PoolTail = HEAD_TO_TAIL (PoolHdr);
+ PoolTail = HEAD_TO_TAIL (PoolHdr);
PoolTail->Signature = POOL_TAIL_SIGNATURE;
- PoolTail->Size = PoolHdr->Size;
+ PoolTail->Size = PoolHdr->Size;
}
*Buffer = PoolHdr + 1;
return Status;
}
- Size = (Size + MIN_POOL_SIZE - 1) >> MIN_POOL_SHIFT;
- PoolIndex = (UINTN) HighBitSet32 ((UINT32)Size);
+ Size = (Size + MIN_POOL_SIZE - 1) >> MIN_POOL_SHIFT;
+ PoolIndex = (UINTN)HighBitSet32 ((UINT32)Size);
if ((Size & (Size - 1)) != 0) {
PoolIndex++;
}
Status = InternalAllocPoolByIndex (PoolType, PoolIndex, &FreePoolHdr);
- if (!EFI_ERROR(Status)) {
+ if (!EFI_ERROR (Status)) {
*Buffer = &FreePoolHdr->Header + 1;
}
+
return Status;
}
@@ -334,7 +346,7 @@ SmmAllocatePool (
Status = SmmInternalAllocatePool (PoolType, Size, Buffer);
if (!EFI_ERROR (Status)) {
SmmCoreUpdateProfile (
- (EFI_PHYSICAL_ADDRESS) (UINTN) RETURN_ADDRESS (0),
+ (EFI_PHYSICAL_ADDRESS)(UINTN)RETURN_ADDRESS (0),
MemoryProfileActionAllocatePool,
PoolType,
Size,
@@ -342,6 +354,7 @@ SmmAllocatePool (
NULL
);
}
+
return Status;
}
@@ -371,10 +384,10 @@ SmmInternalFreePool (
MemoryGuarded = IsHeapGuardEnabled () &&
IsMemoryGuarded ((EFI_PHYSICAL_ADDRESS)(UINTN)Buffer);
- HasPoolTail = !(MemoryGuarded &&
- ((PcdGet8 (PcdHeapGuardPropertyMask) & BIT7) == 0));
+ HasPoolTail = !(MemoryGuarded &&
+ ((PcdGet8 (PcdHeapGuardPropertyMask) & BIT7) == 0));
- FreePoolHdr = (FREE_POOL_HEADER*)((POOL_HEADER*)Buffer - 1);
+ FreePoolHdr = (FREE_POOL_HEADER *)((POOL_HEADER *)Buffer - 1);
ASSERT (FreePoolHdr->Header.Signature == POOL_HEAD_SIGNATURE);
ASSERT (!FreePoolHdr->Header.Available);
if (FreePoolHdr->Header.Signature != POOL_HEAD_SIGNATURE) {
@@ -414,6 +427,7 @@ SmmInternalFreePool (
FALSE
);
}
+
return InternalFreePoolByIndex (FreePoolHdr, PoolTail);
}
@@ -437,7 +451,7 @@ SmmFreePool (
Status = SmmInternalFreePool (Buffer);
if (!EFI_ERROR (Status)) {
SmmCoreUpdateProfile (
- (EFI_PHYSICAL_ADDRESS) (UINTN) RETURN_ADDRESS (0),
+ (EFI_PHYSICAL_ADDRESS)(UINTN)RETURN_ADDRESS (0),
MemoryProfileActionFreePool,
EfiMaxMemoryType,
0,
@@ -445,5 +459,6 @@ SmmFreePool (
NULL
);
}
+
return Status;
}
diff --git a/MdeModulePkg/Core/PiSmmCore/Smi.c b/MdeModulePkg/Core/PiSmmCore/Smi.c
index aeefb392f7..6d13969979 100644
--- a/MdeModulePkg/Core/PiSmmCore/Smi.c
+++ b/MdeModulePkg/Core/PiSmmCore/Smi.c
@@ -8,12 +8,12 @@
#include "PiSmmCore.h"
-LIST_ENTRY mSmiEntryList = INITIALIZE_LIST_HEAD_VARIABLE (mSmiEntryList);
+LIST_ENTRY mSmiEntryList = INITIALIZE_LIST_HEAD_VARIABLE (mSmiEntryList);
-SMI_ENTRY mRootSmiEntry = {
+SMI_ENTRY mRootSmiEntry = {
SMI_ENTRY_SIGNATURE,
INITIALIZE_LIST_HEAD_VARIABLE (mRootSmiEntry.AllEntries),
- {0},
+ { 0 },
INITIALIZE_LIST_HEAD_VARIABLE (mRootSmiEntry.SmiHandlers),
};
@@ -43,8 +43,8 @@ SmmCoreFindSmiEntry (
SmiEntry = NULL;
for (Link = mSmiEntryList.ForwardLink;
Link != &mSmiEntryList;
- Link = Link->ForwardLink) {
-
+ Link = Link->ForwardLink)
+ {
Item = CR (Link, SMI_ENTRY, AllEntries, SMI_ENTRY_SIGNATURE);
if (CompareGuid (&Item->HandlerType, HandlerType)) {
//
@@ -60,7 +60,7 @@ SmmCoreFindSmiEntry (
// allocate a new entry
//
if ((SmiEntry == NULL) && Create) {
- SmiEntry = AllocatePool (sizeof(SMI_ENTRY));
+ SmiEntry = AllocatePool (sizeof (SMI_ENTRY));
if (SmiEntry != NULL) {
//
// Initialize new SMI entry structure
@@ -75,6 +75,7 @@ SmmCoreFindSmiEntry (
InsertTailList (&mSmiEntryList, &SmiEntry->AllEntries);
}
}
+
return SmiEntry;
}
@@ -108,7 +109,7 @@ SmiManage (
BOOLEAN SuccessReturn;
EFI_STATUS Status;
- Status = EFI_NOT_FOUND;
+ Status = EFI_NOT_FOUND;
SuccessReturn = FALSE;
if (HandlerType == NULL) {
//
@@ -119,7 +120,7 @@ SmiManage (
//
// Non-root SMI handler
//
- SmiEntry = SmmCoreFindSmiEntry ((EFI_GUID *) HandlerType, FALSE);
+ SmiEntry = SmmCoreFindSmiEntry ((EFI_GUID *)HandlerType, FALSE);
if (SmiEntry == NULL) {
//
// There is no handler registered for this interrupt source
@@ -127,62 +128,65 @@ SmiManage (
return Status;
}
}
+
Head = &SmiEntry->SmiHandlers;
for (Link = Head->ForwardLink; Link != Head; Link = Link->ForwardLink) {
SmiHandler = CR (Link, SMI_HANDLER, Link, SMI_HANDLER_SIGNATURE);
Status = SmiHandler->Handler (
- (EFI_HANDLE) SmiHandler,
- Context,
- CommBuffer,
- CommBufferSize
- );
+ (EFI_HANDLE)SmiHandler,
+ Context,
+ CommBuffer,
+ CommBufferSize
+ );
switch (Status) {
- case EFI_INTERRUPT_PENDING:
- //
- // If a handler returns EFI_INTERRUPT_PENDING and HandlerType is not NULL then
- // no additional handlers will be processed and EFI_INTERRUPT_PENDING will be returned.
- //
- if (HandlerType != NULL) {
- return EFI_INTERRUPT_PENDING;
- }
- break;
-
- case EFI_SUCCESS:
- //
- // If at least one of the handlers returns EFI_SUCCESS then the function will return
- // EFI_SUCCESS. If a handler returns EFI_SUCCESS and HandlerType is not NULL then no
- // additional handlers will be processed.
- //
- if (HandlerType != NULL) {
- return EFI_SUCCESS;
- }
- SuccessReturn = TRUE;
- break;
-
- case EFI_WARN_INTERRUPT_SOURCE_QUIESCED:
- //
- // If at least one of the handlers returns EFI_WARN_INTERRUPT_SOURCE_QUIESCED
- // then the function will return EFI_SUCCESS.
- //
- SuccessReturn = TRUE;
- break;
-
- case EFI_WARN_INTERRUPT_SOURCE_PENDING:
- //
- // If all the handlers returned EFI_WARN_INTERRUPT_SOURCE_PENDING
- // then EFI_WARN_INTERRUPT_SOURCE_PENDING will be returned.
- //
- break;
-
- default:
- //
- // Unexpected status code returned.
- //
- ASSERT (FALSE);
- break;
+ case EFI_INTERRUPT_PENDING:
+ //
+ // If a handler returns EFI_INTERRUPT_PENDING and HandlerType is not NULL then
+ // no additional handlers will be processed and EFI_INTERRUPT_PENDING will be returned.
+ //
+ if (HandlerType != NULL) {
+ return EFI_INTERRUPT_PENDING;
+ }
+
+ break;
+
+ case EFI_SUCCESS:
+ //
+ // If at least one of the handlers returns EFI_SUCCESS then the function will return
+ // EFI_SUCCESS. If a handler returns EFI_SUCCESS and HandlerType is not NULL then no
+ // additional handlers will be processed.
+ //
+ if (HandlerType != NULL) {
+ return EFI_SUCCESS;
+ }
+
+ SuccessReturn = TRUE;
+ break;
+
+ case EFI_WARN_INTERRUPT_SOURCE_QUIESCED:
+ //
+ // If at least one of the handlers returns EFI_WARN_INTERRUPT_SOURCE_QUIESCED
+ // then the function will return EFI_SUCCESS.
+ //
+ SuccessReturn = TRUE;
+ break;
+
+ case EFI_WARN_INTERRUPT_SOURCE_PENDING:
+ //
+ // If all the handlers returned EFI_WARN_INTERRUPT_SOURCE_PENDING
+ // then EFI_WARN_INTERRUPT_SOURCE_PENDING will be returned.
+ //
+ break;
+
+ default:
+ //
+ // Unexpected status code returned.
+ //
+ ASSERT (FALSE);
+ break;
}
}
@@ -216,7 +220,7 @@ SmiHandlerRegister (
SMI_ENTRY *SmiEntry;
LIST_ENTRY *List;
- if (Handler == NULL || DispatchHandle == NULL) {
+ if ((Handler == NULL) || (DispatchHandle == NULL)) {
return EFI_INVALID_PARAMETER;
}
@@ -225,8 +229,8 @@ SmiHandlerRegister (
return EFI_OUT_OF_RESOURCES;
}
- SmiHandler->Signature = SMI_HANDLER_SIGNATURE;
- SmiHandler->Handler = Handler;
+ SmiHandler->Signature = SMI_HANDLER_SIGNATURE;
+ SmiHandler->Handler = Handler;
SmiHandler->CallerAddr = (UINTN)RETURN_ADDRESS (0);
if (HandlerType == NULL) {
@@ -238,17 +242,18 @@ SmiHandlerRegister (
//
// None root SMI handler
//
- SmiEntry = SmmCoreFindSmiEntry ((EFI_GUID *) HandlerType, TRUE);
+ SmiEntry = SmmCoreFindSmiEntry ((EFI_GUID *)HandlerType, TRUE);
if (SmiEntry == NULL) {
return EFI_OUT_OF_RESOURCES;
}
}
+
List = &SmiEntry->SmiHandlers;
SmiHandler->SmiEntry = SmiEntry;
InsertTailList (List, &SmiHandler->Link);
- *DispatchHandle = (EFI_HANDLE) SmiHandler;
+ *DispatchHandle = (EFI_HANDLE)SmiHandler;
return EFI_SUCCESS;
}
@@ -282,9 +287,10 @@ SmiHandlerUnRegister (
//
SmiHandler = NULL;
for ( HandlerLink = GetFirstNode (&mRootSmiEntry.SmiHandlers)
- ; !IsNull (&mRootSmiEntry.SmiHandlers, HandlerLink) && ((EFI_HANDLE) SmiHandler != DispatchHandle)
- ; HandlerLink = GetNextNode (&mRootSmiEntry.SmiHandlers, HandlerLink)
- ) {
+ ; !IsNull (&mRootSmiEntry.SmiHandlers, HandlerLink) && ((EFI_HANDLE)SmiHandler != DispatchHandle)
+ ; HandlerLink = GetNextNode (&mRootSmiEntry.SmiHandlers, HandlerLink)
+ )
+ {
SmiHandler = CR (HandlerLink, SMI_HANDLER, Link, SMI_HANDLER_SIGNATURE);
}
@@ -292,19 +298,21 @@ SmiHandlerUnRegister (
// Look for it in non-root SMI handlers
//
for ( EntryLink = GetFirstNode (&mSmiEntryList)
- ; !IsNull (&mSmiEntryList, EntryLink) && ((EFI_HANDLE) SmiHandler != DispatchHandle)
- ; EntryLink = GetNextNode (&mSmiEntryList, EntryLink)
- ) {
+ ; !IsNull (&mSmiEntryList, EntryLink) && ((EFI_HANDLE)SmiHandler != DispatchHandle)
+ ; EntryLink = GetNextNode (&mSmiEntryList, EntryLink)
+ )
+ {
SmiEntry = CR (EntryLink, SMI_ENTRY, AllEntries, SMI_ENTRY_SIGNATURE);
for ( HandlerLink = GetFirstNode (&SmiEntry->SmiHandlers)
- ; !IsNull (&SmiEntry->SmiHandlers, HandlerLink) && ((EFI_HANDLE) SmiHandler != DispatchHandle)
- ; HandlerLink = GetNextNode (&SmiEntry->SmiHandlers, HandlerLink)
- ) {
+ ; !IsNull (&SmiEntry->SmiHandlers, HandlerLink) && ((EFI_HANDLE)SmiHandler != DispatchHandle)
+ ; HandlerLink = GetNextNode (&SmiEntry->SmiHandlers, HandlerLink)
+ )
+ {
SmiHandler = CR (HandlerLink, SMI_HANDLER, Link, SMI_HANDLER_SIGNATURE);
}
}
- if ((EFI_HANDLE) SmiHandler != DispatchHandle) {
+ if ((EFI_HANDLE)SmiHandler != DispatchHandle) {
return EFI_INVALID_PARAMETER;
}
diff --git a/MdeModulePkg/Core/PiSmmCore/SmiHandlerProfile.c b/MdeModulePkg/Core/PiSmmCore/SmiHandlerProfile.c
index 50d092d05d..27da2898dd 100644
--- a/MdeModulePkg/Core/PiSmmCore/SmiHandlerProfile.c
+++ b/MdeModulePkg/Core/PiSmmCore/SmiHandlerProfile.c
@@ -43,7 +43,7 @@ typedef struct {
Register SMI handler profile handler.
**/
VOID
-RegisterSmiHandlerProfileHandler(
+RegisterSmiHandlerProfileHandler (
VOID
);
@@ -76,13 +76,13 @@ extern SMI_ENTRY mRootSmiEntry;
extern SMI_HANDLER_PROFILE_PROTOCOL mSmiHandlerProfile;
-GLOBAL_REMOVE_IF_UNREFERENCED LIST_ENTRY mHardwareSmiEntryList = INITIALIZE_LIST_HEAD_VARIABLE (mHardwareSmiEntryList);
+GLOBAL_REMOVE_IF_UNREFERENCED LIST_ENTRY mHardwareSmiEntryList = INITIALIZE_LIST_HEAD_VARIABLE (mHardwareSmiEntryList);
-GLOBAL_REMOVE_IF_UNREFERENCED LIST_ENTRY mRootSmiEntryList = INITIALIZE_LIST_HEAD_VARIABLE (mRootSmiEntryList);
+GLOBAL_REMOVE_IF_UNREFERENCED LIST_ENTRY mRootSmiEntryList = INITIALIZE_LIST_HEAD_VARIABLE (mRootSmiEntryList);
-GLOBAL_REMOVE_IF_UNREFERENCED LIST_ENTRY *mSmmCoreRootSmiEntryList = &mRootSmiEntryList;
-GLOBAL_REMOVE_IF_UNREFERENCED LIST_ENTRY *mSmmCoreSmiEntryList = &mSmiEntryList;
-GLOBAL_REMOVE_IF_UNREFERENCED LIST_ENTRY *mSmmCoreHardwareSmiEntryList = &mHardwareSmiEntryList;
+GLOBAL_REMOVE_IF_UNREFERENCED LIST_ENTRY *mSmmCoreRootSmiEntryList = &mRootSmiEntryList;
+GLOBAL_REMOVE_IF_UNREFERENCED LIST_ENTRY *mSmmCoreSmiEntryList = &mSmiEntryList;
+GLOBAL_REMOVE_IF_UNREFERENCED LIST_ENTRY *mSmmCoreHardwareSmiEntryList = &mHardwareSmiEntryList;
GLOBAL_REMOVE_IF_UNREFERENCED IMAGE_STRUCT *mImageStruct;
GLOBAL_REMOVE_IF_UNREFERENCED UINT32 mImageStructCountMax;
@@ -116,6 +116,7 @@ InternalDumpData (
)
{
UINTN Index;
+
for (Index = 0; Index < Size; Index++) {
DEBUG ((DEBUG_INFO, "%02x ", (UINTN)Data[Index]));
}
@@ -133,17 +134,19 @@ GetDriverGuid (
OUT EFI_GUID *Guid
)
{
- EFI_GUID *FileName;
+ EFI_GUID *FileName;
FileName = NULL;
- if ((DevicePathType(LoadedImage->FilePath) == MEDIA_DEVICE_PATH) &&
- (DevicePathSubType(LoadedImage->FilePath) == MEDIA_PIWG_FW_FILE_DP)) {
+ if ((DevicePathType (LoadedImage->FilePath) == MEDIA_DEVICE_PATH) &&
+ (DevicePathSubType (LoadedImage->FilePath) == MEDIA_PIWG_FW_FILE_DP))
+ {
FileName = &((MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *)LoadedImage->FilePath)->FvFileName;
}
+
if (FileName != NULL) {
- CopyGuid(Guid, FileName);
+ CopyGuid (Guid, FileName);
} else {
- ZeroMem(Guid, sizeof(EFI_GUID));
+ ZeroMem (Guid, sizeof (EFI_GUID));
}
}
@@ -157,31 +160,31 @@ GetDriverGuid (
@param PdbString image PDB string
**/
VOID
-AddImageStruct(
- IN PHYSICAL_ADDRESS ImageBase,
- IN UINT64 ImageSize,
- IN PHYSICAL_ADDRESS EntryPoint,
- IN EFI_GUID *Guid,
- IN CHAR8 *PdbString
+AddImageStruct (
+ IN PHYSICAL_ADDRESS ImageBase,
+ IN UINT64 ImageSize,
+ IN PHYSICAL_ADDRESS EntryPoint,
+ IN EFI_GUID *Guid,
+ IN CHAR8 *PdbString
)
{
UINTN PdbStringSize;
if (mImageStructCount >= mImageStructCountMax) {
- ASSERT(FALSE);
+ ASSERT (FALSE);
return;
}
- CopyGuid(&mImageStruct[mImageStructCount].FileGuid, Guid);
- mImageStruct[mImageStructCount].ImageRef = mImageStructCount;
- mImageStruct[mImageStructCount].ImageBase = ImageBase;
- mImageStruct[mImageStructCount].ImageSize = ImageSize;
+ CopyGuid (&mImageStruct[mImageStructCount].FileGuid, Guid);
+ mImageStruct[mImageStructCount].ImageRef = mImageStructCount;
+ mImageStruct[mImageStructCount].ImageBase = ImageBase;
+ mImageStruct[mImageStructCount].ImageSize = ImageSize;
mImageStruct[mImageStructCount].EntryPoint = EntryPoint;
if (PdbString != NULL) {
- PdbStringSize = AsciiStrSize(PdbString);
+ PdbStringSize = AsciiStrSize (PdbString);
mImageStruct[mImageStructCount].PdbString = AllocateCopyPool (PdbStringSize, PdbString);
if (mImageStruct[mImageStructCount].PdbString != NULL) {
- mImageStruct[mImageStructCount].PdbStringSize = (UINT16) PdbStringSize;
+ mImageStruct[mImageStructCount].PdbStringSize = (UINT16)PdbStringSize;
}
}
@@ -196,7 +199,7 @@ AddImageStruct(
@return image structure
**/
IMAGE_STRUCT *
-AddressToImageStruct(
+AddressToImageStruct (
IN UINTN Address
)
{
@@ -204,10 +207,12 @@ AddressToImageStruct(
for (Index = 0; Index < mImageStructCount; Index++) {
if ((Address >= mImageStruct[Index].ImageBase) &&
- (Address < mImageStruct[Index].ImageBase + mImageStruct[Index].ImageSize)) {
+ (Address < mImageStruct[Index].ImageBase + mImageStruct[Index].ImageSize))
+ {
return &mImageStruct[Index];
}
}
+
return NULL;
}
@@ -219,16 +224,17 @@ AddressToImageStruct(
@return image reference index
**/
UINT32
-AddressToImageRef(
+AddressToImageRef (
IN UINTN Address
)
{
- IMAGE_STRUCT *ImageStruct;
+ IMAGE_STRUCT *ImageStruct;
- ImageStruct = AddressToImageStruct(Address);
+ ImageStruct = AddressToImageStruct (Address);
if (ImageStruct != NULL) {
return ImageStruct->ImageRef;
}
+
return (UINT32)-1;
}
@@ -236,7 +242,7 @@ AddressToImageRef(
Collect SMM image information based upon loaded image protocol.
**/
VOID
-GetSmmLoadedImage(
+GetSmmLoadedImage (
VOID
)
{
@@ -255,55 +261,58 @@ GetSmmLoadedImage(
PHYSICAL_ADDRESS RealImageBase;
HandleBufferSize = 0;
- HandleBuffer = NULL;
- Status = gSmst->SmmLocateHandle(
- ByProtocol,
- &gEfiLoadedImageProtocolGuid,
- NULL,
- &HandleBufferSize,
- HandleBuffer
- );
+ HandleBuffer = NULL;
+ Status = gSmst->SmmLocateHandle (
+ ByProtocol,
+ &gEfiLoadedImageProtocolGuid,
+ NULL,
+ &HandleBufferSize,
+ HandleBuffer
+ );
if (Status != EFI_BUFFER_TOO_SMALL) {
return;
}
+
HandleBuffer = AllocateZeroPool (HandleBufferSize);
if (HandleBuffer == NULL) {
return;
}
- Status = gSmst->SmmLocateHandle(
+
+ Status = gSmst->SmmLocateHandle (
ByProtocol,
&gEfiLoadedImageProtocolGuid,
NULL,
&HandleBufferSize,
HandleBuffer
);
- if (EFI_ERROR(Status)) {
+ if (EFI_ERROR (Status)) {
return;
}
- NoHandles = HandleBufferSize/sizeof(EFI_HANDLE);
- mImageStructCountMax = (UINT32) NoHandles;
- mImageStruct = AllocateZeroPool(mImageStructCountMax * sizeof(IMAGE_STRUCT));
+ NoHandles = HandleBufferSize/sizeof (EFI_HANDLE);
+ mImageStructCountMax = (UINT32)NoHandles;
+ mImageStruct = AllocateZeroPool (mImageStructCountMax * sizeof (IMAGE_STRUCT));
if (mImageStruct == NULL) {
goto Done;
}
for (Index = 0; Index < NoHandles; Index++) {
- Status = gSmst->SmmHandleProtocol(
+ Status = gSmst->SmmHandleProtocol (
HandleBuffer[Index],
&gEfiLoadedImageProtocolGuid,
(VOID **)&LoadedImage
);
- if (EFI_ERROR(Status)) {
+ if (EFI_ERROR (Status)) {
continue;
}
- PathStr = ConvertDevicePathToText(LoadedImage->FilePath, TRUE, TRUE);
- GetDriverGuid(LoadedImage, &Guid);
+
+ PathStr = ConvertDevicePathToText (LoadedImage->FilePath, TRUE, TRUE);
+ GetDriverGuid (LoadedImage, &Guid);
DEBUG ((DEBUG_INFO, "Image: %g ", &Guid));
- EntryPoint = 0;
- LoadedImagePrivate = BASE_CR(LoadedImage, EFI_SMM_DRIVER_ENTRY, SmmLoadedImage);
- RealImageBase = (UINTN)LoadedImage->ImageBase;
+ EntryPoint = 0;
+ LoadedImagePrivate = BASE_CR (LoadedImage, EFI_SMM_DRIVER_ENTRY, SmmLoadedImage);
+ RealImageBase = (UINTN)LoadedImage->ImageBase;
if (LoadedImagePrivate->Signature == EFI_SMM_DRIVER_ENTRY_SIGNATURE) {
EntryPoint = LoadedImagePrivate->ImageEntryPoint;
if ((EntryPoint != 0) && ((EntryPoint < (UINTN)LoadedImage->ImageBase) || (EntryPoint >= ((UINTN)LoadedImage->ImageBase + LoadedImage->ImageSize)))) {
@@ -311,30 +320,33 @@ GetSmmLoadedImage(
// 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(LoadedImage->ImageBase, &EntryPointInImage);
- ASSERT_EFI_ERROR(Status);
+ Status = InternalPeCoffGetEntryPoint (LoadedImage->ImageBase, &EntryPointInImage);
+ ASSERT_EFI_ERROR (Status);
RealImageBase = (UINTN)LoadedImage->ImageBase + EntryPoint - (UINTN)EntryPointInImage;
}
}
+
DEBUG ((DEBUG_INFO, "(0x%lx - 0x%lx", RealImageBase, LoadedImage->ImageSize));
if (EntryPoint != 0) {
DEBUG ((DEBUG_INFO, ", EntryPoint:0x%lx", EntryPoint));
}
+
DEBUG ((DEBUG_INFO, ")\n"));
if (RealImageBase != 0) {
- PdbString = PeCoffLoaderGetPdbPointer ((VOID*) (UINTN) RealImageBase);
+ PdbString = PeCoffLoaderGetPdbPointer ((VOID *)(UINTN)RealImageBase);
DEBUG ((DEBUG_INFO, " pdb - %a\n", PdbString));
} else {
PdbString = NULL;
}
+
DEBUG ((DEBUG_INFO, " (%s)\n", PathStr));
- AddImageStruct(RealImageBase, LoadedImage->ImageSize, EntryPoint, &Guid, PdbString);
+ AddImageStruct (RealImageBase, LoadedImage->ImageSize, EntryPoint, &Guid, PdbString);
}
Done:
- FreePool(HandleBuffer);
+ FreePool (HandleBuffer);
return;
}
@@ -347,12 +359,12 @@ Done:
**/
VOID
DumpSmiChildContext (
- IN EFI_GUID *HandlerType,
- IN VOID *Context,
- IN UINTN ContextSize
+ IN EFI_GUID *HandlerType,
+ IN VOID *Context,
+ IN UINTN ContextSize
)
{
- CHAR16 *Str;
+ CHAR16 *Str;
if (CompareGuid (HandlerType, &gEfiSmmSwDispatch2ProtocolGuid)) {
DEBUG ((DEBUG_INFO, " SwSmi - 0x%lx\n", ((SMI_HANDLER_PROFILE_SW_REGISTER_CONTEXT *)Context)->SwSmiInputValue));
@@ -374,7 +386,7 @@ DumpSmiChildContext (
DEBUG ((DEBUG_INFO, " IoTrapType - 0x%x\n", ((EFI_SMM_IO_TRAP_REGISTER_CONTEXT *)Context)->Type));
} else if (CompareGuid (HandlerType, &gEfiSmmUsbDispatch2ProtocolGuid)) {
DEBUG ((DEBUG_INFO, " UsbType - 0x%x\n", ((SMI_HANDLER_PROFILE_USB_REGISTER_CONTEXT *)Context)->Type));
- Str = ConvertDevicePathToText((EFI_DEVICE_PATH_PROTOCOL *)(((SMI_HANDLER_PROFILE_USB_REGISTER_CONTEXT *)Context) + 1), TRUE, TRUE);
+ Str = ConvertDevicePathToText ((EFI_DEVICE_PATH_PROTOCOL *)(((SMI_HANDLER_PROFILE_USB_REGISTER_CONTEXT *)Context) + 1), TRUE, TRUE);
DEBUG ((DEBUG_INFO, " UsbDevicePath - %s\n", Str));
if (Str != NULL) {
FreePool (Str);
@@ -392,39 +404,45 @@ DumpSmiChildContext (
@param SmiEntry SMI entry.
**/
VOID
-DumpSmiHandlerOnSmiEntry(
- IN SMI_ENTRY *SmiEntry
+DumpSmiHandlerOnSmiEntry (
+ IN SMI_ENTRY *SmiEntry
)
{
- LIST_ENTRY *ListEntry;
- SMI_HANDLER *SmiHandler;
- IMAGE_STRUCT *ImageStruct;
+ LIST_ENTRY *ListEntry;
+ SMI_HANDLER *SmiHandler;
+ IMAGE_STRUCT *ImageStruct;
ListEntry = &SmiEntry->SmiHandlers;
for (ListEntry = ListEntry->ForwardLink;
ListEntry != &SmiEntry->SmiHandlers;
- ListEntry = ListEntry->ForwardLink) {
- SmiHandler = CR(ListEntry, SMI_HANDLER, Link, SMI_HANDLER_SIGNATURE);
- ImageStruct = AddressToImageStruct((UINTN)SmiHandler->Handler);
+ ListEntry = ListEntry->ForwardLink)
+ {
+ SmiHandler = CR (ListEntry, SMI_HANDLER, Link, SMI_HANDLER_SIGNATURE);
+ ImageStruct = AddressToImageStruct ((UINTN)SmiHandler->Handler);
if (ImageStruct != NULL) {
DEBUG ((DEBUG_INFO, " Module - %g", &ImageStruct->FileGuid));
}
+
if ((ImageStruct != NULL) && (ImageStruct->PdbString[0] != 0)) {
DEBUG ((DEBUG_INFO, " (Pdb - %a)", ImageStruct->PdbString));
}
+
DEBUG ((DEBUG_INFO, "\n"));
if (SmiHandler->ContextSize != 0) {
DumpSmiChildContext (&SmiEntry->HandlerType, SmiHandler->Context, SmiHandler->ContextSize);
}
+
DEBUG ((DEBUG_INFO, " Handler - 0x%x", SmiHandler->Handler));
if (ImageStruct != NULL) {
- DEBUG ((DEBUG_INFO, " <== RVA - 0x%x", (UINTN)SmiHandler->Handler - (UINTN) ImageStruct->ImageBase));
+ DEBUG ((DEBUG_INFO, " <== RVA - 0x%x", (UINTN)SmiHandler->Handler - (UINTN)ImageStruct->ImageBase));
}
+
DEBUG ((DEBUG_INFO, "\n"));
DEBUG ((DEBUG_INFO, " CallerAddr - 0x%x", SmiHandler->CallerAddr));
if (ImageStruct != NULL) {
- DEBUG ((DEBUG_INFO, " <== RVA - 0x%x", SmiHandler->CallerAddr - (UINTN) ImageStruct->ImageBase));
+ DEBUG ((DEBUG_INFO, " <== RVA - 0x%x", SmiHandler->CallerAddr - (UINTN)ImageStruct->ImageBase));
}
+
DEBUG ((DEBUG_INFO, "\n"));
}
@@ -437,20 +455,21 @@ DumpSmiHandlerOnSmiEntry(
@param SmiEntryList a list of SMI entry.
**/
VOID
-DumpSmiEntryList(
- IN LIST_ENTRY *SmiEntryList
+DumpSmiEntryList (
+ IN LIST_ENTRY *SmiEntryList
)
{
- LIST_ENTRY *ListEntry;
- SMI_ENTRY *SmiEntry;
+ LIST_ENTRY *ListEntry;
+ SMI_ENTRY *SmiEntry;
ListEntry = SmiEntryList;
for (ListEntry = ListEntry->ForwardLink;
ListEntry != SmiEntryList;
- ListEntry = ListEntry->ForwardLink) {
- SmiEntry = CR(ListEntry, SMI_ENTRY, AllEntries, SMI_ENTRY_SIGNATURE);
+ ListEntry = ListEntry->ForwardLink)
+ {
+ SmiEntry = CR (ListEntry, SMI_ENTRY, AllEntries, SMI_ENTRY_SIGNATURE);
DEBUG ((DEBUG_INFO, "SmiEntry - %g\n", &SmiEntry->HandlerType));
- DumpSmiHandlerOnSmiEntry(SmiEntry);
+ DumpSmiHandlerOnSmiEntry (SmiEntry);
}
return;
@@ -494,25 +513,25 @@ SmmReadyToLockInSmiHandlerProfile (
DEBUG ((DEBUG_INFO, "# 1. ROOT SMI Handler #\n"));
DEBUG_CODE (
- DumpSmiEntryList(mSmmCoreRootSmiEntryList);
- );
+ DumpSmiEntryList (mSmmCoreRootSmiEntryList);
+ );
DEBUG ((DEBUG_INFO, "# 2. GUID SMI Handler #\n"));
DEBUG_CODE (
- DumpSmiEntryList(mSmmCoreSmiEntryList);
- );
+ DumpSmiEntryList (mSmmCoreSmiEntryList);
+ );
DEBUG ((DEBUG_INFO, "# 3. Hardware SMI Handler #\n"));
DEBUG_CODE (
- DumpSmiEntryList(mSmmCoreHardwareSmiEntryList);
- );
+ DumpSmiEntryList (mSmmCoreHardwareSmiEntryList);
+ );
DEBUG ((DEBUG_INFO, "\n"));
- RegisterSmiHandlerProfileHandler();
+ RegisterSmiHandlerProfileHandler ();
if (mImageStruct != NULL) {
- FreePool(mImageStruct);
+ FreePool (mImageStruct);
}
return EFI_SUCCESS;
@@ -524,17 +543,18 @@ SmmReadyToLockInSmiHandlerProfile (
@return SMM image data base size.
**/
UINTN
-GetSmmImageDatabaseSize(
+GetSmmImageDatabaseSize (
VOID
)
{
- UINTN Size;
- UINT32 Index;
+ UINTN Size;
+ UINT32 Index;
Size = 0;
for (Index = 0; Index < mImageStructCount; Index++) {
- Size += sizeof(SMM_CORE_IMAGE_DATABASE_STRUCTURE) + GET_OCCUPIED_SIZE (mImageStruct[Index].PdbStringSize, sizeof (UINT64));
+ Size += sizeof (SMM_CORE_IMAGE_DATABASE_STRUCTURE) + GET_OCCUPIED_SIZE (mImageStruct[Index].PdbStringSize, sizeof (UINT64));
}
+
return Size;
}
@@ -546,21 +566,22 @@ GetSmmImageDatabaseSize(
@return all SMI handlers' size associated with SmiEntry.
**/
UINTN
-GetSmmSmiHandlerSizeOnSmiEntry(
- IN SMI_ENTRY *SmiEntry
+GetSmmSmiHandlerSizeOnSmiEntry (
+ IN SMI_ENTRY *SmiEntry
)
{
- LIST_ENTRY *ListEntry;
- SMI_HANDLER *SmiHandler;
- UINTN Size;
+ LIST_ENTRY *ListEntry;
+ SMI_HANDLER *SmiHandler;
+ UINTN Size;
- Size = 0;
+ Size = 0;
ListEntry = &SmiEntry->SmiHandlers;
for (ListEntry = ListEntry->ForwardLink;
ListEntry != &SmiEntry->SmiHandlers;
- ListEntry = ListEntry->ForwardLink) {
- SmiHandler = CR(ListEntry, SMI_HANDLER, Link, SMI_HANDLER_SIGNATURE);
- Size += sizeof(SMM_CORE_SMI_HANDLER_STRUCTURE) + GET_OCCUPIED_SIZE (SmiHandler->ContextSize, sizeof (UINT64));
+ ListEntry = ListEntry->ForwardLink)
+ {
+ SmiHandler = CR (ListEntry, SMI_HANDLER, Link, SMI_HANDLER_SIGNATURE);
+ Size += sizeof (SMM_CORE_SMI_HANDLER_STRUCTURE) + GET_OCCUPIED_SIZE (SmiHandler->ContextSize, sizeof (UINT64));
}
return Size;
@@ -574,23 +595,25 @@ GetSmmSmiHandlerSizeOnSmiEntry(
@return all SMI handler database size on the SMI entry list.
**/
UINTN
-GetSmmSmiDatabaseSize(
- IN LIST_ENTRY *SmiEntryList
+GetSmmSmiDatabaseSize (
+ IN LIST_ENTRY *SmiEntryList
)
{
- LIST_ENTRY *ListEntry;
- SMI_ENTRY *SmiEntry;
- UINTN Size;
+ LIST_ENTRY *ListEntry;
+ SMI_ENTRY *SmiEntry;
+ UINTN Size;
- Size = 0;
+ Size = 0;
ListEntry = SmiEntryList;
for (ListEntry = ListEntry->ForwardLink;
ListEntry != SmiEntryList;
- ListEntry = ListEntry->ForwardLink) {
- SmiEntry = CR(ListEntry, SMI_ENTRY, AllEntries, SMI_ENTRY_SIGNATURE);
- Size += sizeof(SMM_CORE_SMI_DATABASE_STRUCTURE);
- Size += GetSmmSmiHandlerSizeOnSmiEntry(SmiEntry);
+ ListEntry = ListEntry->ForwardLink)
+ {
+ SmiEntry = CR (ListEntry, SMI_ENTRY, AllEntries, SMI_ENTRY_SIGNATURE);
+ Size += sizeof (SMM_CORE_SMI_DATABASE_STRUCTURE);
+ Size += GetSmmSmiHandlerSizeOnSmiEntry (SmiEntry);
}
+
return Size;
}
@@ -604,10 +627,10 @@ GetSmiHandlerProfileDatabaseSize (
VOID
)
{
- mSmmImageDatabaseSize = GetSmmImageDatabaseSize();
- mSmmRootSmiDatabaseSize = GetSmmSmiDatabaseSize(mSmmCoreRootSmiEntryList);
- mSmmSmiDatabaseSize = GetSmmSmiDatabaseSize(mSmmCoreSmiEntryList);
- mSmmHardwareSmiDatabaseSize = GetSmmSmiDatabaseSize(mSmmCoreHardwareSmiEntryList);
+ mSmmImageDatabaseSize = GetSmmImageDatabaseSize ();
+ mSmmRootSmiDatabaseSize = GetSmmSmiDatabaseSize (mSmmCoreRootSmiEntryList);
+ mSmmSmiDatabaseSize = GetSmmSmiDatabaseSize (mSmmCoreSmiEntryList);
+ mSmmHardwareSmiDatabaseSize = GetSmmSmiDatabaseSize (mSmmCoreHardwareSmiEntryList);
return mSmmImageDatabaseSize + mSmmSmiDatabaseSize + mSmmRootSmiDatabaseSize + mSmmHardwareSmiDatabaseSize;
}
@@ -622,44 +645,48 @@ GetSmiHandlerProfileDatabaseSize (
**/
UINTN
GetSmmImageDatabaseData (
- IN OUT VOID *Data,
- IN UINTN ExpectedSize
+ IN OUT VOID *Data,
+ IN UINTN ExpectedSize
)
{
- SMM_CORE_IMAGE_DATABASE_STRUCTURE *ImageStruct;
- UINTN Size;
- UINTN Index;
+ SMM_CORE_IMAGE_DATABASE_STRUCTURE *ImageStruct;
+ UINTN Size;
+ UINTN Index;
ImageStruct = Data;
- Size = 0;
+ Size = 0;
for (Index = 0; Index < mImageStructCount; Index++) {
if (Size >= ExpectedSize) {
return 0;
}
- if (sizeof(SMM_CORE_IMAGE_DATABASE_STRUCTURE) + GET_OCCUPIED_SIZE (mImageStruct[Index].PdbStringSize, sizeof (UINT64)) > ExpectedSize - Size) {
+
+ if (sizeof (SMM_CORE_IMAGE_DATABASE_STRUCTURE) + GET_OCCUPIED_SIZE (mImageStruct[Index].PdbStringSize, sizeof (UINT64)) > ExpectedSize - Size) {
return 0;
}
+
ImageStruct->Header.Signature = SMM_CORE_IMAGE_DATABASE_SIGNATURE;
- ImageStruct->Header.Length = (UINT32)(sizeof(SMM_CORE_IMAGE_DATABASE_STRUCTURE) + GET_OCCUPIED_SIZE (mImageStruct[Index].PdbStringSize, sizeof (UINT64)));
- ImageStruct->Header.Revision = SMM_CORE_IMAGE_DATABASE_REVISION;
- CopyGuid(&ImageStruct->FileGuid, &mImageStruct[Index].FileGuid);
- ImageStruct->ImageRef = mImageStruct[Index].ImageRef;
+ ImageStruct->Header.Length = (UINT32)(sizeof (SMM_CORE_IMAGE_DATABASE_STRUCTURE) + GET_OCCUPIED_SIZE (mImageStruct[Index].PdbStringSize, sizeof (UINT64)));
+ ImageStruct->Header.Revision = SMM_CORE_IMAGE_DATABASE_REVISION;
+ CopyGuid (&ImageStruct->FileGuid, &mImageStruct[Index].FileGuid);
+ ImageStruct->ImageRef = mImageStruct[Index].ImageRef;
ImageStruct->EntryPoint = mImageStruct[Index].EntryPoint;
- ImageStruct->ImageBase = mImageStruct[Index].ImageBase;
- ImageStruct->ImageSize = mImageStruct[Index].ImageSize;
+ ImageStruct->ImageBase = mImageStruct[Index].ImageBase;
+ ImageStruct->ImageSize = mImageStruct[Index].ImageSize;
if (mImageStruct[Index].PdbStringSize != 0) {
- ImageStruct->PdbStringOffset = sizeof(SMM_CORE_IMAGE_DATABASE_STRUCTURE);
+ ImageStruct->PdbStringOffset = sizeof (SMM_CORE_IMAGE_DATABASE_STRUCTURE);
CopyMem ((VOID *)((UINTN)ImageStruct + ImageStruct->PdbStringOffset), mImageStruct[Index].PdbString, mImageStruct[Index].PdbStringSize);
} else {
ImageStruct->PdbStringOffset = 0;
}
+
ImageStruct = (SMM_CORE_IMAGE_DATABASE_STRUCTURE *)((UINTN)ImageStruct + ImageStruct->Header.Length);
- Size += sizeof(SMM_CORE_IMAGE_DATABASE_STRUCTURE) + GET_OCCUPIED_SIZE (mImageStruct[Index].PdbStringSize, sizeof (UINT64));
+ Size += sizeof (SMM_CORE_IMAGE_DATABASE_STRUCTURE) + GET_OCCUPIED_SIZE (mImageStruct[Index].PdbStringSize, sizeof (UINT64));
}
if (ExpectedSize != Size) {
return 0;
}
+
return Size;
}
@@ -674,48 +701,52 @@ GetSmmImageDatabaseData (
@return SMM image data base size.
**/
UINTN
-GetSmmSmiHandlerDataOnSmiEntry(
- IN SMI_ENTRY *SmiEntry,
- IN OUT VOID *Data,
- IN UINTN MaxSize,
- OUT UINT32 *Count
+GetSmmSmiHandlerDataOnSmiEntry (
+ IN SMI_ENTRY *SmiEntry,
+ IN OUT VOID *Data,
+ IN UINTN MaxSize,
+ OUT UINT32 *Count
)
{
- SMM_CORE_SMI_HANDLER_STRUCTURE *SmiHandlerStruct;
- LIST_ENTRY *ListEntry;
- SMI_HANDLER *SmiHandler;
- UINTN Size;
+ SMM_CORE_SMI_HANDLER_STRUCTURE *SmiHandlerStruct;
+ LIST_ENTRY *ListEntry;
+ SMI_HANDLER *SmiHandler;
+ UINTN Size;
SmiHandlerStruct = Data;
- Size = 0;
- *Count = 0;
- ListEntry = &SmiEntry->SmiHandlers;
+ Size = 0;
+ *Count = 0;
+ ListEntry = &SmiEntry->SmiHandlers;
for (ListEntry = ListEntry->ForwardLink;
ListEntry != &SmiEntry->SmiHandlers;
- ListEntry = ListEntry->ForwardLink) {
- SmiHandler = CR(ListEntry, SMI_HANDLER, Link, SMI_HANDLER_SIGNATURE);
+ ListEntry = ListEntry->ForwardLink)
+ {
+ SmiHandler = CR (ListEntry, SMI_HANDLER, Link, SMI_HANDLER_SIGNATURE);
if (Size >= MaxSize) {
*Count = 0;
return 0;
}
- if (sizeof(SMM_CORE_SMI_HANDLER_STRUCTURE) + GET_OCCUPIED_SIZE (SmiHandler->ContextSize, sizeof (UINT64)) > MaxSize - Size) {
+
+ if (sizeof (SMM_CORE_SMI_HANDLER_STRUCTURE) + GET_OCCUPIED_SIZE (SmiHandler->ContextSize, sizeof (UINT64)) > MaxSize - Size) {
*Count = 0;
return 0;
}
- SmiHandlerStruct->Length = (UINT32)(sizeof(SMM_CORE_SMI_HANDLER_STRUCTURE) + GET_OCCUPIED_SIZE (SmiHandler->ContextSize, sizeof (UINT64)));
- SmiHandlerStruct->CallerAddr = (UINTN)SmiHandler->CallerAddr;
- SmiHandlerStruct->Handler = (UINTN)SmiHandler->Handler;
- SmiHandlerStruct->ImageRef = AddressToImageRef((UINTN)SmiHandler->Handler);
+
+ SmiHandlerStruct->Length = (UINT32)(sizeof (SMM_CORE_SMI_HANDLER_STRUCTURE) + GET_OCCUPIED_SIZE (SmiHandler->ContextSize, sizeof (UINT64)));
+ SmiHandlerStruct->CallerAddr = (UINTN)SmiHandler->CallerAddr;
+ SmiHandlerStruct->Handler = (UINTN)SmiHandler->Handler;
+ SmiHandlerStruct->ImageRef = AddressToImageRef ((UINTN)SmiHandler->Handler);
SmiHandlerStruct->ContextBufferSize = (UINT32)SmiHandler->ContextSize;
if (SmiHandler->ContextSize != 0) {
- SmiHandlerStruct->ContextBufferOffset = sizeof(SMM_CORE_SMI_HANDLER_STRUCTURE);
+ SmiHandlerStruct->ContextBufferOffset = sizeof (SMM_CORE_SMI_HANDLER_STRUCTURE);
CopyMem ((UINT8 *)SmiHandlerStruct + SmiHandlerStruct->ContextBufferOffset, SmiHandler->Context, SmiHandler->ContextSize);
} else {
SmiHandlerStruct->ContextBufferOffset = 0;
}
- Size += sizeof(SMM_CORE_SMI_HANDLER_STRUCTURE) + GET_OCCUPIED_SIZE (SmiHandler->ContextSize, sizeof (UINT64));
+
+ Size += sizeof (SMM_CORE_SMI_HANDLER_STRUCTURE) + GET_OCCUPIED_SIZE (SmiHandler->ContextSize, sizeof (UINT64));
SmiHandlerStruct = (SMM_CORE_SMI_HANDLER_STRUCTURE *)((UINTN)SmiHandlerStruct + SmiHandlerStruct->Length);
- *Count = *Count + 1;
+ *Count = *Count + 1;
}
return Size;
@@ -732,49 +763,53 @@ GetSmmSmiHandlerDataOnSmiEntry(
@return all SMI database size on the SMI entry list.
**/
UINTN
-GetSmmSmiDatabaseData(
- IN LIST_ENTRY *SmiEntryList,
- IN UINT32 HandlerCategory,
- IN OUT VOID *Data,
- IN UINTN ExpectedSize
+GetSmmSmiDatabaseData (
+ IN LIST_ENTRY *SmiEntryList,
+ IN UINT32 HandlerCategory,
+ IN OUT VOID *Data,
+ IN UINTN ExpectedSize
)
{
- SMM_CORE_SMI_DATABASE_STRUCTURE *SmiStruct;
- LIST_ENTRY *ListEntry;
- SMI_ENTRY *SmiEntry;
- UINTN Size;
- UINTN SmiHandlerSize;
- UINT32 SmiHandlerCount;
+ SMM_CORE_SMI_DATABASE_STRUCTURE *SmiStruct;
+ LIST_ENTRY *ListEntry;
+ SMI_ENTRY *SmiEntry;
+ UINTN Size;
+ UINTN SmiHandlerSize;
+ UINT32 SmiHandlerCount;
SmiStruct = Data;
- Size = 0;
+ Size = 0;
ListEntry = SmiEntryList;
for (ListEntry = ListEntry->ForwardLink;
ListEntry != SmiEntryList;
- ListEntry = ListEntry->ForwardLink) {
- SmiEntry = CR(ListEntry, SMI_ENTRY, AllEntries, SMI_ENTRY_SIGNATURE);
+ ListEntry = ListEntry->ForwardLink)
+ {
+ SmiEntry = CR (ListEntry, SMI_ENTRY, AllEntries, SMI_ENTRY_SIGNATURE);
if (Size >= ExpectedSize) {
return 0;
}
- if (sizeof(SMM_CORE_SMI_DATABASE_STRUCTURE) > ExpectedSize - Size) {
+
+ if (sizeof (SMM_CORE_SMI_DATABASE_STRUCTURE) > ExpectedSize - Size) {
return 0;
}
SmiStruct->Header.Signature = SMM_CORE_SMI_DATABASE_SIGNATURE;
- SmiStruct->Header.Length = sizeof(SMM_CORE_SMI_DATABASE_STRUCTURE);
- SmiStruct->Header.Revision = SMM_CORE_SMI_DATABASE_REVISION;
- SmiStruct->HandlerCategory = HandlerCategory;
- CopyGuid(&SmiStruct->HandlerType, &SmiEntry->HandlerType);
- Size += sizeof(SMM_CORE_SMI_DATABASE_STRUCTURE);
- SmiHandlerSize = GetSmmSmiHandlerDataOnSmiEntry(SmiEntry, (UINT8 *)SmiStruct + SmiStruct->Header.Length, ExpectedSize - Size, &SmiHandlerCount);
- SmiStruct->HandlerCount = SmiHandlerCount;
- Size += SmiHandlerSize;
+ SmiStruct->Header.Length = sizeof (SMM_CORE_SMI_DATABASE_STRUCTURE);
+ SmiStruct->Header.Revision = SMM_CORE_SMI_DATABASE_REVISION;
+ SmiStruct->HandlerCategory = HandlerCategory;
+ CopyGuid (&SmiStruct->HandlerType, &SmiEntry->HandlerType);
+ Size += sizeof (SMM_CORE_SMI_DATABASE_STRUCTURE);
+ SmiHandlerSize = GetSmmSmiHandlerDataOnSmiEntry (SmiEntry, (UINT8 *)SmiStruct + SmiStruct->Header.Length, ExpectedSize - Size, &SmiHandlerCount);
+ SmiStruct->HandlerCount = SmiHandlerCount;
+ Size += SmiHandlerSize;
SmiStruct->Header.Length += (UINT32)SmiHandlerSize;
- SmiStruct = (VOID *)((UINTN)SmiStruct + SmiStruct->Header.Length);
+ SmiStruct = (VOID *)((UINTN)SmiStruct + SmiStruct->Header.Length);
}
+
if (ExpectedSize != Size) {
return 0;
}
+
return Size;
}
@@ -787,8 +822,8 @@ GetSmmSmiDatabaseData(
@retval EFI_INVALID_PARAMETER the database size mismatch.
**/
EFI_STATUS
-GetSmiHandlerProfileDatabaseData(
- IN OUT VOID *Data
+GetSmiHandlerProfileDatabaseData (
+ IN OUT VOID *Data
)
{
UINTN SmmImageDatabaseSize;
@@ -796,25 +831,28 @@ GetSmiHandlerProfileDatabaseData(
UINTN SmmRootSmiDatabaseSize;
UINTN SmmHardwareSmiDatabaseSize;
- DEBUG((DEBUG_VERBOSE, "GetSmiHandlerProfileDatabaseData\n"));
- SmmImageDatabaseSize = GetSmmImageDatabaseData(Data, mSmmImageDatabaseSize);
+ DEBUG ((DEBUG_VERBOSE, "GetSmiHandlerProfileDatabaseData\n"));
+ SmmImageDatabaseSize = GetSmmImageDatabaseData (Data, mSmmImageDatabaseSize);
if (SmmImageDatabaseSize != mSmmImageDatabaseSize) {
- DEBUG((DEBUG_ERROR, "GetSmiHandlerProfileDatabaseData - SmmImageDatabaseSize mismatch!\n"));
+ DEBUG ((DEBUG_ERROR, "GetSmiHandlerProfileDatabaseData - SmmImageDatabaseSize mismatch!\n"));
return EFI_INVALID_PARAMETER;
}
- SmmRootSmiDatabaseSize = GetSmmSmiDatabaseData(mSmmCoreRootSmiEntryList, SmmCoreSmiHandlerCategoryRootHandler, (UINT8 *)Data + SmmImageDatabaseSize, mSmmRootSmiDatabaseSize);
+
+ SmmRootSmiDatabaseSize = GetSmmSmiDatabaseData (mSmmCoreRootSmiEntryList, SmmCoreSmiHandlerCategoryRootHandler, (UINT8 *)Data + SmmImageDatabaseSize, mSmmRootSmiDatabaseSize);
if (SmmRootSmiDatabaseSize != mSmmRootSmiDatabaseSize) {
- DEBUG((DEBUG_ERROR, "GetSmiHandlerProfileDatabaseData - SmmRootSmiDatabaseSize mismatch!\n"));
+ DEBUG ((DEBUG_ERROR, "GetSmiHandlerProfileDatabaseData - SmmRootSmiDatabaseSize mismatch!\n"));
return EFI_INVALID_PARAMETER;
}
- SmmSmiDatabaseSize = GetSmmSmiDatabaseData(mSmmCoreSmiEntryList, SmmCoreSmiHandlerCategoryGuidHandler, (UINT8 *)Data + SmmImageDatabaseSize + mSmmRootSmiDatabaseSize, mSmmSmiDatabaseSize);
+
+ SmmSmiDatabaseSize = GetSmmSmiDatabaseData (mSmmCoreSmiEntryList, SmmCoreSmiHandlerCategoryGuidHandler, (UINT8 *)Data + SmmImageDatabaseSize + mSmmRootSmiDatabaseSize, mSmmSmiDatabaseSize);
if (SmmSmiDatabaseSize != mSmmSmiDatabaseSize) {
- DEBUG((DEBUG_ERROR, "GetSmiHandlerProfileDatabaseData - SmmSmiDatabaseSize mismatch!\n"));
+ DEBUG ((DEBUG_ERROR, "GetSmiHandlerProfileDatabaseData - SmmSmiDatabaseSize mismatch!\n"));
return EFI_INVALID_PARAMETER;
}
- SmmHardwareSmiDatabaseSize = GetSmmSmiDatabaseData(mSmmCoreHardwareSmiEntryList, SmmCoreSmiHandlerCategoryHardwareHandler, (UINT8 *)Data + SmmImageDatabaseSize + SmmRootSmiDatabaseSize + SmmSmiDatabaseSize, mSmmHardwareSmiDatabaseSize);
+
+ SmmHardwareSmiDatabaseSize = GetSmmSmiDatabaseData (mSmmCoreHardwareSmiEntryList, SmmCoreSmiHandlerCategoryHardwareHandler, (UINT8 *)Data + SmmImageDatabaseSize + SmmRootSmiDatabaseSize + SmmSmiDatabaseSize, mSmmHardwareSmiDatabaseSize);
if (SmmHardwareSmiDatabaseSize != mSmmHardwareSmiDatabaseSize) {
- DEBUG((DEBUG_ERROR, "GetSmiHandlerProfileDatabaseData - SmmHardwareSmiDatabaseSize mismatch!\n"));
+ DEBUG ((DEBUG_ERROR, "GetSmiHandlerProfileDatabaseData - SmmHardwareSmiDatabaseSize mismatch!\n"));
return EFI_INVALID_PARAMETER;
}
@@ -825,19 +863,21 @@ GetSmiHandlerProfileDatabaseData(
build SMI handler profile database.
**/
VOID
-BuildSmiHandlerProfileDatabase(
+BuildSmiHandlerProfileDatabase (
VOID
)
{
EFI_STATUS Status;
- mSmiHandlerProfileDatabaseSize = GetSmiHandlerProfileDatabaseSize();
- mSmiHandlerProfileDatabase = AllocatePool(mSmiHandlerProfileDatabaseSize);
+
+ mSmiHandlerProfileDatabaseSize = GetSmiHandlerProfileDatabaseSize ();
+ mSmiHandlerProfileDatabase = AllocatePool (mSmiHandlerProfileDatabaseSize);
if (mSmiHandlerProfileDatabase == NULL) {
return;
}
- Status = GetSmiHandlerProfileDatabaseData(mSmiHandlerProfileDatabase);
- if (EFI_ERROR(Status)) {
- FreePool(mSmiHandlerProfileDatabase);
+
+ Status = GetSmiHandlerProfileDatabaseData (mSmiHandlerProfileDatabase);
+ if (EFI_ERROR (Status)) {
+ FreePool (mSmiHandlerProfileDatabase);
mSmiHandlerProfileDatabase = NULL;
}
}
@@ -853,21 +893,22 @@ BuildSmiHandlerProfileDatabase(
**/
VOID
-SmiHandlerProfileCopyData(
- OUT VOID *DataBuffer,
- IN OUT UINT64 *DataSize,
- IN OUT UINT64 *DataOffset
+SmiHandlerProfileCopyData (
+ OUT VOID *DataBuffer,
+ IN OUT UINT64 *DataSize,
+ IN OUT UINT64 *DataOffset
)
{
if (*DataOffset >= mSmiHandlerProfileDatabaseSize) {
*DataOffset = mSmiHandlerProfileDatabaseSize;
return;
}
+
if (mSmiHandlerProfileDatabaseSize - *DataOffset < *DataSize) {
*DataSize = mSmiHandlerProfileDatabaseSize - *DataOffset;
}
- CopyMem(
+ CopyMem (
DataBuffer,
(UINT8 *)mSmiHandlerProfileDatabase + *DataOffset,
(UINTN)*DataSize
@@ -882,16 +923,16 @@ SmiHandlerProfileCopyData(
**/
VOID
-SmiHandlerProfileHandlerGetInfo(
- IN SMI_HANDLER_PROFILE_PARAMETER_GET_INFO *SmiHandlerProfileParameterGetInfo
+SmiHandlerProfileHandlerGetInfo (
+ IN SMI_HANDLER_PROFILE_PARAMETER_GET_INFO *SmiHandlerProfileParameterGetInfo
)
{
- BOOLEAN SmiHandlerProfileRecordingStatus;
+ BOOLEAN SmiHandlerProfileRecordingStatus;
- SmiHandlerProfileRecordingStatus = mSmiHandlerProfileRecordingStatus;
+ SmiHandlerProfileRecordingStatus = mSmiHandlerProfileRecordingStatus;
mSmiHandlerProfileRecordingStatus = FALSE;
- SmiHandlerProfileParameterGetInfo->DataSize = mSmiHandlerProfileDatabaseSize;
+ SmiHandlerProfileParameterGetInfo->DataSize = mSmiHandlerProfileDatabaseSize;
SmiHandlerProfileParameterGetInfo->Header.ReturnStatus = 0;
mSmiHandlerProfileRecordingStatus = SmiHandlerProfileRecordingStatus;
@@ -904,29 +945,29 @@ SmiHandlerProfileHandlerGetInfo(
**/
VOID
-SmiHandlerProfileHandlerGetDataByOffset(
- IN SMI_HANDLER_PROFILE_PARAMETER_GET_DATA_BY_OFFSET *SmiHandlerProfileParameterGetDataByOffset
+SmiHandlerProfileHandlerGetDataByOffset (
+ IN SMI_HANDLER_PROFILE_PARAMETER_GET_DATA_BY_OFFSET *SmiHandlerProfileParameterGetDataByOffset
)
{
- SMI_HANDLER_PROFILE_PARAMETER_GET_DATA_BY_OFFSET SmiHandlerProfileGetDataByOffset;
- BOOLEAN SmiHandlerProfileRecordingStatus;
+ SMI_HANDLER_PROFILE_PARAMETER_GET_DATA_BY_OFFSET SmiHandlerProfileGetDataByOffset;
+ BOOLEAN SmiHandlerProfileRecordingStatus;
- SmiHandlerProfileRecordingStatus = mSmiHandlerProfileRecordingStatus;
+ SmiHandlerProfileRecordingStatus = mSmiHandlerProfileRecordingStatus;
mSmiHandlerProfileRecordingStatus = FALSE;
- CopyMem(&SmiHandlerProfileGetDataByOffset, SmiHandlerProfileParameterGetDataByOffset, sizeof(SmiHandlerProfileGetDataByOffset));
+ CopyMem (&SmiHandlerProfileGetDataByOffset, SmiHandlerProfileParameterGetDataByOffset, sizeof (SmiHandlerProfileGetDataByOffset));
//
// Sanity check
//
- if (!SmmIsBufferOutsideSmmValid((UINTN)SmiHandlerProfileGetDataByOffset.DataBuffer, (UINTN)SmiHandlerProfileGetDataByOffset.DataSize)) {
- DEBUG((DEBUG_ERROR, "SmiHandlerProfileHandlerGetDataByOffset: SMI handler profile get data in SMRAM or overflow!\n"));
+ if (!SmmIsBufferOutsideSmmValid ((UINTN)SmiHandlerProfileGetDataByOffset.DataBuffer, (UINTN)SmiHandlerProfileGetDataByOffset.DataSize)) {
+ DEBUG ((DEBUG_ERROR, "SmiHandlerProfileHandlerGetDataByOffset: SMI handler profile get data in SMRAM or overflow!\n"));
SmiHandlerProfileParameterGetDataByOffset->Header.ReturnStatus = (UINT64)(INT64)(INTN)EFI_ACCESS_DENIED;
goto Done;
}
- SmiHandlerProfileCopyData((VOID *)(UINTN)SmiHandlerProfileGetDataByOffset.DataBuffer, &SmiHandlerProfileGetDataByOffset.DataSize, &SmiHandlerProfileGetDataByOffset.DataOffset);
- CopyMem(SmiHandlerProfileParameterGetDataByOffset, &SmiHandlerProfileGetDataByOffset, sizeof(SmiHandlerProfileGetDataByOffset));
+ SmiHandlerProfileCopyData ((VOID *)(UINTN)SmiHandlerProfileGetDataByOffset.DataBuffer, &SmiHandlerProfileGetDataByOffset.DataSize, &SmiHandlerProfileGetDataByOffset.DataOffset);
+ CopyMem (SmiHandlerProfileParameterGetDataByOffset, &SmiHandlerProfileGetDataByOffset, sizeof (SmiHandlerProfileGetDataByOffset));
SmiHandlerProfileParameterGetDataByOffset->Header.ReturnStatus = 0;
Done:
@@ -950,17 +991,17 @@ Done:
**/
EFI_STATUS
EFIAPI
-SmiHandlerProfileHandler(
+SmiHandlerProfileHandler (
IN EFI_HANDLE DispatchHandle,
IN CONST VOID *Context OPTIONAL,
IN OUT VOID *CommBuffer OPTIONAL,
IN OUT UINTN *CommBufferSize OPTIONAL
)
{
- SMI_HANDLER_PROFILE_PARAMETER_HEADER *SmiHandlerProfileParameterHeader;
- UINTN TempCommBufferSize;
+ SMI_HANDLER_PROFILE_PARAMETER_HEADER *SmiHandlerProfileParameterHeader;
+ UINTN TempCommBufferSize;
- DEBUG((DEBUG_ERROR, "SmiHandlerProfileHandler Enter\n"));
+ DEBUG ((DEBUG_ERROR, "SmiHandlerProfileHandler Enter\n"));
if (mSmiHandlerProfileDatabase == NULL) {
return EFI_SUCCESS;
@@ -969,47 +1010,49 @@ SmiHandlerProfileHandler(
//
// If input is invalid, stop processing this SMI
//
- if (CommBuffer == NULL || CommBufferSize == NULL) {
+ if ((CommBuffer == NULL) || (CommBufferSize == NULL)) {
return EFI_SUCCESS;
}
TempCommBufferSize = *CommBufferSize;
- if (TempCommBufferSize < sizeof(SMI_HANDLER_PROFILE_PARAMETER_HEADER)) {
- DEBUG((DEBUG_ERROR, "SmiHandlerProfileHandler: SMM communication buffer size invalid!\n"));
+ if (TempCommBufferSize < sizeof (SMI_HANDLER_PROFILE_PARAMETER_HEADER)) {
+ DEBUG ((DEBUG_ERROR, "SmiHandlerProfileHandler: SMM communication buffer size invalid!\n"));
return EFI_SUCCESS;
}
- if (!SmmIsBufferOutsideSmmValid((UINTN)CommBuffer, TempCommBufferSize)) {
- DEBUG((DEBUG_ERROR, "SmiHandlerProfileHandler: SMM communication buffer in SMRAM or overflow!\n"));
+ if (!SmmIsBufferOutsideSmmValid ((UINTN)CommBuffer, TempCommBufferSize)) {
+ DEBUG ((DEBUG_ERROR, "SmiHandlerProfileHandler: SMM communication buffer in SMRAM or overflow!\n"));
return EFI_SUCCESS;
}
- SmiHandlerProfileParameterHeader = (SMI_HANDLER_PROFILE_PARAMETER_HEADER *)((UINTN)CommBuffer);
+ SmiHandlerProfileParameterHeader = (SMI_HANDLER_PROFILE_PARAMETER_HEADER *)((UINTN)CommBuffer);
SmiHandlerProfileParameterHeader->ReturnStatus = (UINT64)-1;
switch (SmiHandlerProfileParameterHeader->Command) {
- case SMI_HANDLER_PROFILE_COMMAND_GET_INFO:
- DEBUG((DEBUG_ERROR, "SmiHandlerProfileHandlerGetInfo\n"));
- if (TempCommBufferSize != sizeof(SMI_HANDLER_PROFILE_PARAMETER_GET_INFO)) {
- DEBUG((DEBUG_ERROR, "SmiHandlerProfileHandler: SMM communication buffer size invalid!\n"));
- return EFI_SUCCESS;
- }
- SmiHandlerProfileHandlerGetInfo((SMI_HANDLER_PROFILE_PARAMETER_GET_INFO *)(UINTN)CommBuffer);
- break;
- case SMI_HANDLER_PROFILE_COMMAND_GET_DATA_BY_OFFSET:
- DEBUG((DEBUG_ERROR, "SmiHandlerProfileHandlerGetDataByOffset\n"));
- if (TempCommBufferSize != sizeof(SMI_HANDLER_PROFILE_PARAMETER_GET_DATA_BY_OFFSET)) {
- DEBUG((DEBUG_ERROR, "SmiHandlerProfileHandler: SMM communication buffer size invalid!\n"));
- return EFI_SUCCESS;
- }
- SmiHandlerProfileHandlerGetDataByOffset((SMI_HANDLER_PROFILE_PARAMETER_GET_DATA_BY_OFFSET *)(UINTN)CommBuffer);
- break;
- default:
- break;
+ case SMI_HANDLER_PROFILE_COMMAND_GET_INFO:
+ DEBUG ((DEBUG_ERROR, "SmiHandlerProfileHandlerGetInfo\n"));
+ if (TempCommBufferSize != sizeof (SMI_HANDLER_PROFILE_PARAMETER_GET_INFO)) {
+ DEBUG ((DEBUG_ERROR, "SmiHandlerProfileHandler: SMM communication buffer size invalid!\n"));
+ return EFI_SUCCESS;
+ }
+
+ SmiHandlerProfileHandlerGetInfo ((SMI_HANDLER_PROFILE_PARAMETER_GET_INFO *)(UINTN)CommBuffer);
+ break;
+ case SMI_HANDLER_PROFILE_COMMAND_GET_DATA_BY_OFFSET:
+ DEBUG ((DEBUG_ERROR, "SmiHandlerProfileHandlerGetDataByOffset\n"));
+ if (TempCommBufferSize != sizeof (SMI_HANDLER_PROFILE_PARAMETER_GET_DATA_BY_OFFSET)) {
+ DEBUG ((DEBUG_ERROR, "SmiHandlerProfileHandler: SMM communication buffer size invalid!\n"));
+ return EFI_SUCCESS;
+ }
+
+ SmiHandlerProfileHandlerGetDataByOffset ((SMI_HANDLER_PROFILE_PARAMETER_GET_DATA_BY_OFFSET *)(UINTN)CommBuffer);
+ break;
+ default:
+ break;
}
- DEBUG((DEBUG_ERROR, "SmiHandlerProfileHandler Exit\n"));
+ DEBUG ((DEBUG_ERROR, "SmiHandlerProfileHandler Exit\n"));
return EFI_SUCCESS;
}
@@ -1022,8 +1065,8 @@ RegisterSmiHandlerProfileHandler (
VOID
)
{
- EFI_STATUS Status;
- EFI_HANDLE DispatchHandle;
+ EFI_STATUS Status;
+ EFI_HANDLE DispatchHandle;
Status = gSmst->SmiHandlerRegister (
SmiHandlerProfileHandler,
@@ -1032,7 +1075,7 @@ RegisterSmiHandlerProfileHandler (
);
ASSERT_EFI_ERROR (Status);
- BuildSmiHandlerProfileDatabase();
+ BuildSmiHandlerProfileDatabase ();
}
/**
@@ -1059,8 +1102,8 @@ SmmCoreFindHardwareSmiEntry (
SmiEntry = NULL;
for (Link = mHardwareSmiEntryList.ForwardLink;
Link != &mHardwareSmiEntryList;
- Link = Link->ForwardLink) {
-
+ Link = Link->ForwardLink)
+ {
Item = CR (Link, SMI_ENTRY, AllEntries, SMI_ENTRY_SIGNATURE);
if (CompareGuid (&Item->HandlerType, HandlerType)) {
//
@@ -1076,7 +1119,7 @@ SmmCoreFindHardwareSmiEntry (
// allocate a new entry
//
if ((SmiEntry == NULL) && Create) {
- SmiEntry = AllocatePool (sizeof(SMI_ENTRY));
+ SmiEntry = AllocatePool (sizeof (SMI_ENTRY));
if (SmiEntry != NULL) {
//
// Initialize new SMI entry structure
@@ -1091,6 +1134,7 @@ SmmCoreFindHardwareSmiEntry (
InsertTailList (&mHardwareSmiEntryList, &SmiEntry->AllEntries);
}
}
+
return SmiEntry;
}
@@ -1105,23 +1149,24 @@ SmmCoreFindHardwareSmiEntry (
**/
SMI_HANDLER_PROFILE_USB_REGISTER_CONTEXT *
ConvertSmiHandlerUsbContext (
- IN EFI_SMM_USB_REGISTER_CONTEXT *UsbContext,
- IN UINTN UsbContextSize,
- OUT UINTN *SmiHandlerUsbContextSize
+ IN EFI_SMM_USB_REGISTER_CONTEXT *UsbContext,
+ IN UINTN UsbContextSize,
+ OUT UINTN *SmiHandlerUsbContextSize
)
{
UINTN DevicePathSize;
SMI_HANDLER_PROFILE_USB_REGISTER_CONTEXT *SmiHandlerUsbContext;
- ASSERT (UsbContextSize == sizeof(EFI_SMM_USB_REGISTER_CONTEXT));
+ ASSERT (UsbContextSize == sizeof (EFI_SMM_USB_REGISTER_CONTEXT));
- DevicePathSize = GetDevicePathSize (UsbContext->Device);
+ DevicePathSize = GetDevicePathSize (UsbContext->Device);
SmiHandlerUsbContext = AllocatePool (sizeof (SMI_HANDLER_PROFILE_USB_REGISTER_CONTEXT) + DevicePathSize);
if (SmiHandlerUsbContext == NULL) {
*SmiHandlerUsbContextSize = 0;
return NULL;
}
- SmiHandlerUsbContext->Type = UsbContext->Type;
+
+ SmiHandlerUsbContext->Type = UsbContext->Type;
SmiHandlerUsbContext->DevicePathSize = (UINT32)DevicePathSize;
CopyMem (SmiHandlerUsbContext + 1, UsbContext->Device, DevicePathSize);
*SmiHandlerUsbContextSize = sizeof (SMI_HANDLER_PROFILE_USB_REGISTER_CONTEXT) + DevicePathSize;
@@ -1139,22 +1184,23 @@ ConvertSmiHandlerUsbContext (
**/
SMI_HANDLER_PROFILE_SW_REGISTER_CONTEXT *
ConvertSmiHandlerSwContext (
- IN EFI_SMM_SW_REGISTER_CONTEXT *SwContext,
- IN UINTN SwContextSize,
- OUT UINTN *SmiHandlerSwContextSize
+ IN EFI_SMM_SW_REGISTER_CONTEXT *SwContext,
+ IN UINTN SwContextSize,
+ OUT UINTN *SmiHandlerSwContextSize
)
{
SMI_HANDLER_PROFILE_SW_REGISTER_CONTEXT *SmiHandlerSwContext;
- ASSERT (SwContextSize == sizeof(EFI_SMM_SW_REGISTER_CONTEXT));
+ ASSERT (SwContextSize == sizeof (EFI_SMM_SW_REGISTER_CONTEXT));
SmiHandlerSwContext = AllocatePool (sizeof (SMI_HANDLER_PROFILE_SW_REGISTER_CONTEXT));
if (SmiHandlerSwContext == NULL) {
*SmiHandlerSwContextSize = 0;
return NULL;
}
+
SmiHandlerSwContext->SwSmiInputValue = SwContext->SwSmiInputValue;
- *SmiHandlerSwContextSize = sizeof (SMI_HANDLER_PROFILE_SW_REGISTER_CONTEXT);
+ *SmiHandlerSwContextSize = sizeof (SMI_HANDLER_PROFILE_SW_REGISTER_CONTEXT);
return SmiHandlerSwContext;
}
@@ -1181,12 +1227,12 @@ ConvertSmiHandlerSwContext (
EFI_STATUS
EFIAPI
SmiHandlerProfileRegisterHandler (
- IN SMI_HANDLER_PROFILE_PROTOCOL *This,
- IN EFI_GUID *HandlerGuid,
- IN EFI_SMM_HANDLER_ENTRY_POINT2 Handler,
- IN PHYSICAL_ADDRESS CallerAddress,
- IN VOID *Context OPTIONAL,
- IN UINTN ContextSize OPTIONAL
+ IN SMI_HANDLER_PROFILE_PROTOCOL *This,
+ IN EFI_GUID *HandlerGuid,
+ IN EFI_SMM_HANDLER_ENTRY_POINT2 Handler,
+ IN PHYSICAL_ADDRESS CallerAddress,
+ IN VOID *Context OPTIONAL,
+ IN UINTN ContextSize OPTIONAL
)
{
SMI_HANDLER *SmiHandler;
@@ -1194,7 +1240,8 @@ SmiHandlerProfileRegisterHandler (
LIST_ENTRY *List;
if (((ContextSize == 0) && (Context != NULL)) ||
- ((ContextSize != 0) && (Context == NULL))) {
+ ((ContextSize != 0) && (Context == NULL)))
+ {
return EFI_INVALID_PARAMETER;
}
@@ -1203,10 +1250,10 @@ SmiHandlerProfileRegisterHandler (
return EFI_OUT_OF_RESOURCES;
}
- SmiHandler->Signature = SMI_HANDLER_SIGNATURE;
- SmiHandler->Handler = Handler;
- SmiHandler->CallerAddr = (UINTN)CallerAddress;
- SmiHandler->Context = Context;
+ SmiHandler->Signature = SMI_HANDLER_SIGNATURE;
+ SmiHandler->Handler = Handler;
+ SmiHandler->CallerAddr = (UINTN)CallerAddress;
+ SmiHandler->Context = Context;
SmiHandler->ContextSize = ContextSize;
if (Context != NULL) {
@@ -1218,6 +1265,7 @@ SmiHandlerProfileRegisterHandler (
SmiHandler->Context = AllocateCopyPool (ContextSize, Context);
}
}
+
if (SmiHandler->Context == NULL) {
SmiHandler->ContextSize = 0;
}
@@ -1227,6 +1275,7 @@ SmiHandlerProfileRegisterHandler (
if (SmiHandler->Context != NULL) {
FreePool (SmiHandler->Context);
}
+
FreePool (SmiHandler);
return EFI_OUT_OF_RESOURCES;
}
@@ -1259,11 +1308,11 @@ SmiHandlerProfileRegisterHandler (
EFI_STATUS
EFIAPI
SmiHandlerProfileUnregisterHandler (
- IN SMI_HANDLER_PROFILE_PROTOCOL *This,
- IN EFI_GUID *HandlerGuid,
- IN EFI_SMM_HANDLER_ENTRY_POINT2 Handler,
- IN VOID *Context OPTIONAL,
- IN UINTN ContextSize OPTIONAL
+ IN SMI_HANDLER_PROFILE_PROTOCOL *This,
+ IN EFI_GUID *HandlerGuid,
+ IN EFI_SMM_HANDLER_ENTRY_POINT2 Handler,
+ IN VOID *Context OPTIONAL,
+ IN UINTN ContextSize OPTIONAL
)
{
LIST_ENTRY *Link;
@@ -1275,7 +1324,8 @@ SmiHandlerProfileUnregisterHandler (
UINTN SearchContextSize;
if (((ContextSize == 0) && (Context != NULL)) ||
- ((ContextSize != 0) && (Context == NULL))) {
+ ((ContextSize != 0) && (Context == NULL)))
+ {
return EFI_INVALID_PARAMETER;
}
@@ -1284,7 +1334,7 @@ SmiHandlerProfileUnregisterHandler (
return EFI_NOT_FOUND;
}
- SearchContext = Context;
+ SearchContext = Context;
SearchContextSize = ContextSize;
if (Context != NULL) {
if (CompareGuid (HandlerGuid, &gEfiSmmUsbDispatch2ProtocolGuid)) {
@@ -1295,12 +1345,13 @@ SmiHandlerProfileUnregisterHandler (
}
TargetSmiHandler = NULL;
- Head = &SmiEntry->SmiHandlers;
+ Head = &SmiEntry->SmiHandlers;
for (Link = Head->ForwardLink; Link != Head; Link = Link->ForwardLink) {
SmiHandler = CR (Link, SMI_HANDLER, Link, SMI_HANDLER_SIGNATURE);
if (SmiHandler->Handler == Handler) {
if ((SearchContext == NULL) ||
- ((SearchContextSize == SmiHandler->ContextSize) && (CompareMem (SearchContext, SmiHandler->Context, SearchContextSize) == 0))) {
+ ((SearchContextSize == SmiHandler->ContextSize) && (CompareMem (SearchContext, SmiHandler->Context, SearchContextSize) == 0)))
+ {
TargetSmiHandler = SmiHandler;
break;
}
@@ -1316,12 +1367,14 @@ SmiHandlerProfileUnregisterHandler (
if (TargetSmiHandler == NULL) {
return EFI_NOT_FOUND;
}
+
SmiHandler = TargetSmiHandler;
RemoveEntryList (&SmiHandler->Link);
if (SmiHandler->Context != NULL) {
FreePool (SmiHandler->Context);
}
+
FreePool (SmiHandler);
if (IsListEmpty (&SmiEntry->SmiHandlers)) {
diff --git a/MdeModulePkg/Core/PiSmmCore/SmramProfileRecord.c b/MdeModulePkg/Core/PiSmmCore/SmramProfileRecord.c
index 002a8e4360..b437e4c433 100644
--- a/MdeModulePkg/Core/PiSmmCore/SmramProfileRecord.c
+++ b/MdeModulePkg/Core/PiSmmCore/SmramProfileRecord.c
@@ -8,16 +8,16 @@
#include "PiSmmCore.h"
-#define IS_SMRAM_PROFILE_ENABLED ((PcdGet8 (PcdMemoryProfilePropertyMask) & BIT1) != 0)
-#define IS_UEFI_MEMORY_PROFILE_ENABLED ((PcdGet8 (PcdMemoryProfilePropertyMask) & BIT0) != 0)
+#define IS_SMRAM_PROFILE_ENABLED ((PcdGet8 (PcdMemoryProfilePropertyMask) & BIT1) != 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,10 +29,10 @@ 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;
//
@@ -40,7 +40,7 @@ typedef struct {
//
#define SMRAM_INFO_DUMP_PAGE_THRESHOLD 4
-GLOBAL_REMOVE_IF_UNREFERENCED MEMORY_PROFILE_FREE_MEMORY mSmramFreeMemory = {
+GLOBAL_REMOVE_IF_UNREFERENCED MEMORY_PROFILE_FREE_MEMORY mSmramFreeMemory = {
{
MEMORY_PROFILE_FREE_MEMORY_SIGNATURE,
sizeof (MEMORY_PROFILE_FREE_MEMORY),
@@ -50,8 +50,8 @@ GLOBAL_REMOVE_IF_UNREFERENCED MEMORY_PROFILE_FREE_MEMORY mSmramFreeMemory = {
0
};
-GLOBAL_REMOVE_IF_UNREFERENCED LIST_ENTRY mImageQueue = INITIALIZE_LIST_HEAD_VARIABLE (mImageQueue);
-GLOBAL_REMOVE_IF_UNREFERENCED MEMORY_PROFILE_CONTEXT_DATA mSmramProfileContext = {
+GLOBAL_REMOVE_IF_UNREFERENCED LIST_ENTRY mImageQueue = INITIALIZE_LIST_HEAD_VARIABLE (mImageQueue);
+GLOBAL_REMOVE_IF_UNREFERENCED MEMORY_PROFILE_CONTEXT_DATA mSmramProfileContext = {
MEMORY_PROFILE_CONTEXT_SIGNATURE,
{
{
@@ -61,21 +61,21 @@ GLOBAL_REMOVE_IF_UNREFERENCED MEMORY_PROFILE_CONTEXT_DATA mSmramProfileContext =
},
0,
0,
- {0},
- {0},
+ { 0 },
+ { 0 },
0,
0,
0
},
&mImageQueue,
};
-GLOBAL_REMOVE_IF_UNREFERENCED MEMORY_PROFILE_CONTEXT_DATA *mSmramProfileContextPtr = NULL;
+GLOBAL_REMOVE_IF_UNREFERENCED MEMORY_PROFILE_CONTEXT_DATA *mSmramProfileContextPtr = NULL;
-GLOBAL_REMOVE_IF_UNREFERENCED BOOLEAN mSmramReadyToLock;
-GLOBAL_REMOVE_IF_UNREFERENCED BOOLEAN mSmramProfileGettingStatus = FALSE;
-GLOBAL_REMOVE_IF_UNREFERENCED BOOLEAN mSmramProfileRecordingEnable = MEMORY_PROFILE_RECORDING_DISABLE;
-GLOBAL_REMOVE_IF_UNREFERENCED EFI_DEVICE_PATH_PROTOCOL *mSmramProfileDriverPath;
-GLOBAL_REMOVE_IF_UNREFERENCED UINTN mSmramProfileDriverPathSize;
+GLOBAL_REMOVE_IF_UNREFERENCED BOOLEAN mSmramReadyToLock;
+GLOBAL_REMOVE_IF_UNREFERENCED BOOLEAN mSmramProfileGettingStatus = FALSE;
+GLOBAL_REMOVE_IF_UNREFERENCED BOOLEAN mSmramProfileRecordingEnable = MEMORY_PROFILE_RECORDING_DISABLE;
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_DEVICE_PATH_PROTOCOL *mSmramProfileDriverPath;
+GLOBAL_REMOVE_IF_UNREFERENCED UINTN mSmramProfileDriverPathSize;
/**
Dump SMRAM information.
@@ -105,7 +105,7 @@ EFIAPI
SmramProfileProtocolGetData (
IN EDKII_SMM_MEMORY_PROFILE_PROTOCOL *This,
IN OUT UINT64 *ProfileSize,
- OUT VOID *ProfileBuffer
+ OUT VOID *ProfileBuffer
);
/**
@@ -226,7 +226,7 @@ SmramProfileProtocolRecord (
IN CHAR8 *ActionString OPTIONAL
);
-GLOBAL_REMOVE_IF_UNREFERENCED EDKII_SMM_MEMORY_PROFILE_PROTOCOL mSmmProfileProtocol = {
+GLOBAL_REMOVE_IF_UNREFERENCED EDKII_SMM_MEMORY_PROFILE_PROTOCOL mSmmProfileProtocol = {
SmramProfileProtocolGetData,
SmramProfileProtocolRegisterImage,
SmramProfileProtocolUnregisterImage,
@@ -269,22 +269,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;
@@ -319,23 +319,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;
}
//
@@ -343,10 +343,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;
}
@@ -369,30 +369,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));
}
}
@@ -403,53 +403,56 @@ BuildDriverInfo (
Status = SmmInternalAllocatePool (
EfiRuntimeServicesData,
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;
@@ -466,28 +469,27 @@ BuildDriverInfo (
**/
VOID
RegisterImageToDxe (
- IN EFI_GUID *FileName,
- IN PHYSICAL_ADDRESS ImageBase,
- IN UINT64 ImageSize,
- IN EFI_FV_FILETYPE FileType
+ IN EFI_GUID *FileName,
+ IN PHYSICAL_ADDRESS ImageBase,
+ IN UINT64 ImageSize,
+ IN EFI_FV_FILETYPE FileType
)
{
- EFI_STATUS Status;
- EDKII_MEMORY_PROFILE_PROTOCOL *ProfileProtocol;
- MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *FilePath;
- UINT8 TempBuffer[sizeof (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH) + sizeof (EFI_DEVICE_PATH_PROTOCOL)];
+ EFI_STATUS Status;
+ EDKII_MEMORY_PROFILE_PROTOCOL *ProfileProtocol;
+ MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *FilePath;
+ UINT8 TempBuffer[sizeof (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH) + sizeof (EFI_DEVICE_PATH_PROTOCOL)];
if (IS_UEFI_MEMORY_PROFILE_ENABLED) {
-
FilePath = (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *)TempBuffer;
- Status = gBS->LocateProtocol (&gEdkiiMemoryProfileGuid, NULL, (VOID **) &ProfileProtocol);
+ Status = gBS->LocateProtocol (&gEdkiiMemoryProfileGuid, NULL, (VOID **)&ProfileProtocol);
if (!EFI_ERROR (Status)) {
EfiInitializeFwVolDevicepathNode (FilePath, FileName);
SetDevicePathEndNode (FilePath + 1);
Status = ProfileProtocol->RegisterImage (
ProfileProtocol,
- (EFI_DEVICE_PATH_PROTOCOL *) FilePath,
+ (EFI_DEVICE_PATH_PROTOCOL *)FilePath,
ImageBase,
ImageSize,
FileType
@@ -506,27 +508,26 @@ RegisterImageToDxe (
**/
VOID
UnregisterImageFromDxe (
- IN EFI_GUID *FileName,
- IN PHYSICAL_ADDRESS ImageBase,
- IN UINT64 ImageSize
+ IN EFI_GUID *FileName,
+ IN PHYSICAL_ADDRESS ImageBase,
+ IN UINT64 ImageSize
)
{
- EFI_STATUS Status;
- EDKII_MEMORY_PROFILE_PROTOCOL *ProfileProtocol;
- MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *FilePath;
- UINT8 TempBuffer[sizeof (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH) + sizeof (EFI_DEVICE_PATH_PROTOCOL)];
+ EFI_STATUS Status;
+ EDKII_MEMORY_PROFILE_PROTOCOL *ProfileProtocol;
+ MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *FilePath;
+ UINT8 TempBuffer[sizeof (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH) + sizeof (EFI_DEVICE_PATH_PROTOCOL)];
if (IS_UEFI_MEMORY_PROFILE_ENABLED) {
-
FilePath = (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *)TempBuffer;
- Status = gBS->LocateProtocol (&gEdkiiMemoryProfileGuid, NULL, (VOID *) &ProfileProtocol);
+ Status = gBS->LocateProtocol (&gEdkiiMemoryProfileGuid, NULL, (VOID *)&ProfileProtocol);
if (!EFI_ERROR (Status)) {
EfiInitializeFwVolDevicepathNode (FilePath, FileName);
SetDevicePathEndNode (FilePath + 1);
Status = ProfileProtocol->UnregisterImage (
ProfileProtocol,
- (EFI_DEVICE_PATH_PROTOCOL *) FilePath,
+ (EFI_DEVICE_PATH_PROTOCOL *)FilePath,
ImageBase,
ImageSize
);
@@ -545,13 +546,13 @@ UnregisterImageFromDxe (
**/
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 (mSmramProfileDriverPath, mSmramProfileDriverPathSize)) {
//
@@ -563,7 +564,7 @@ NeedRecordThisDriver (
//
// Record FilePath without end node.
//
- FilePathSize = GetDevicePathSize (DriverFilePath) - sizeof(EFI_DEVICE_PATH_PROTOCOL);
+ FilePathSize = GetDevicePathSize (DriverFilePath) - sizeof (EFI_DEVICE_PATH_PROTOCOL);
DevicePathInstance = mSmramProfileDriverPath;
do {
@@ -580,14 +581,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;
@@ -604,30 +606,30 @@ NeedRecordThisDriver (
**/
BOOLEAN
RegisterSmmCore (
- IN MEMORY_PROFILE_CONTEXT_DATA *ContextData
+ IN MEMORY_PROFILE_CONTEXT_DATA *ContextData
)
{
- 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;
+ 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;
- FilePath = (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *) TempBuffer;
+ FilePath = (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *)TempBuffer;
EfiInitializeFwVolDevicepathNode (FilePath, &gEfiCallerIdGuid);
SetDevicePathEndNode (FilePath + 1);
- if (!NeedRecordThisDriver ((EFI_DEVICE_PATH_PROTOCOL *) FilePath)) {
+ if (!NeedRecordThisDriver ((EFI_DEVICE_PATH_PROTOCOL *)FilePath)) {
return FALSE;
}
- ImageBase = gSmmCorePrivate->PiSmmCoreImageBase;
+ ImageBase = gSmmCorePrivate->PiSmmCoreImageBase;
DriverInfoData = BuildDriverInfo (
ContextData,
&gEfiCallerIdGuid,
ImageBase,
gSmmCorePrivate->PiSmmCoreImageSize,
gSmmCorePrivate->PiSmmCoreEntryPoint,
- InternalPeCoffGetSubsystem ((VOID *) (UINTN) ImageBase),
+ InternalPeCoffGetSubsystem ((VOID *)(UINTN)ImageBase),
EFI_FV_FILETYPE_SMM_CORE
);
if (DriverInfoData == NULL) {
@@ -646,7 +648,7 @@ SmramProfileInit (
VOID
)
{
- MEMORY_PROFILE_CONTEXT_DATA *SmramProfileContext;
+ MEMORY_PROFILE_CONTEXT_DATA *SmramProfileContext;
RegisterImageToDxe (
&gEfiCallerIdGuid,
@@ -670,9 +672,10 @@ SmramProfileInit (
} else {
mSmramProfileRecordingEnable = MEMORY_PROFILE_RECORDING_ENABLE;
}
+
mSmramProfileDriverPathSize = PcdGetSize (PcdMemoryProfileDriverPath);
- mSmramProfileDriverPath = AllocateCopyPool (mSmramProfileDriverPathSize, PcdGetPtr (PcdMemoryProfileDriverPath));
- mSmramProfileContextPtr = &mSmramProfileContext;
+ mSmramProfileDriverPath = AllocateCopyPool (mSmramProfileDriverPathSize, PcdGetPtr (PcdMemoryProfileDriverPath));
+ mSmramProfileContextPtr = &mSmramProfileContext;
RegisterSmmCore (&mSmramProfileContext);
@@ -688,8 +691,8 @@ SmramProfileInstallProtocol (
VOID
)
{
- EFI_HANDLE Handle;
- EFI_STATUS Status;
+ EFI_HANDLE Handle;
+ EFI_STATUS Status;
if (!IS_SMRAM_PROFILE_ENABLED) {
return;
@@ -715,21 +718,22 @@ SmramProfileInstallProtocol (
**/
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);
}
}
@@ -750,14 +754,14 @@ GetFileNameFromFilePath (
**/
EFI_STATUS
RegisterSmramProfileImage (
- IN EFI_SMM_DRIVER_ENTRY *DriverEntry,
- IN BOOLEAN RegisterToDxe
+ IN EFI_SMM_DRIVER_ENTRY *DriverEntry,
+ IN BOOLEAN RegisterToDxe
)
{
- MEMORY_PROFILE_CONTEXT_DATA *ContextData;
- MEMORY_PROFILE_DRIVER_INFO_DATA *DriverInfoData;
- UINT8 TempBuffer[sizeof(MEDIA_FW_VOL_FILEPATH_DEVICE_PATH) + sizeof(EFI_DEVICE_PATH_PROTOCOL)];
- MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *FilePath;
+ MEMORY_PROFILE_CONTEXT_DATA *ContextData;
+ MEMORY_PROFILE_DRIVER_INFO_DATA *DriverInfoData;
+ UINT8 TempBuffer[sizeof (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH) + sizeof (EFI_DEVICE_PATH_PROTOCOL)];
+ MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *FilePath;
if (RegisterToDxe) {
RegisterImageToDxe (
@@ -772,11 +776,11 @@ RegisterSmramProfileImage (
return EFI_UNSUPPORTED;
}
- FilePath = (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *) TempBuffer;
+ FilePath = (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *)TempBuffer;
EfiInitializeFwVolDevicepathNode (FilePath, &DriverEntry->FileName);
SetDevicePathEndNode (FilePath + 1);
- if (!NeedRecordThisDriver ((EFI_DEVICE_PATH_PROTOCOL *) FilePath)) {
+ if (!NeedRecordThisDriver ((EFI_DEVICE_PATH_PROTOCOL *)FilePath)) {
return EFI_UNSUPPORTED;
}
@@ -791,7 +795,7 @@ RegisterSmramProfileImage (
DriverEntry->ImageBuffer,
EFI_PAGES_TO_SIZE (DriverEntry->NumberOfPage),
DriverEntry->ImageEntryPoint,
- InternalPeCoffGetSubsystem ((VOID *) (UINTN) DriverEntry->ImageBuffer),
+ InternalPeCoffGetSubsystem ((VOID *)(UINTN)DriverEntry->ImageBuffer),
EFI_FV_FILETYPE_SMM
);
if (DriverInfoData == NULL) {
@@ -813,21 +817,22 @@ RegisterSmramProfileImage (
**/
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,
@@ -837,7 +842,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;
}
}
@@ -857,20 +863,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,
@@ -879,7 +886,8 @@ GetMemoryProfileDriverInfoFromAddress (
);
DriverInfo = &DriverInfoData->DriverInfo;
if ((Address >= DriverInfo->ImageBase) &&
- (Address < (DriverInfo->ImageBase + DriverInfo->ImageSize))) {
+ (Address < (DriverInfo->ImageBase + DriverInfo->ImageSize)))
+ {
return DriverInfoData;
}
}
@@ -905,14 +913,14 @@ UnregisterSmramProfileImage (
IN BOOLEAN UnregisterFromDxe
)
{
- EFI_STATUS Status;
- MEMORY_PROFILE_CONTEXT_DATA *ContextData;
- MEMORY_PROFILE_DRIVER_INFO_DATA *DriverInfoData;
- EFI_GUID *FileName;
- PHYSICAL_ADDRESS ImageAddress;
- VOID *EntryPointInImage;
- UINT8 TempBuffer[sizeof(MEDIA_FW_VOL_FILEPATH_DEVICE_PATH) + sizeof(EFI_DEVICE_PATH_PROTOCOL)];
- MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *FilePath;
+ EFI_STATUS Status;
+ MEMORY_PROFILE_CONTEXT_DATA *ContextData;
+ MEMORY_PROFILE_DRIVER_INFO_DATA *DriverInfoData;
+ EFI_GUID *FileName;
+ PHYSICAL_ADDRESS ImageAddress;
+ VOID *EntryPointInImage;
+ UINT8 TempBuffer[sizeof (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH) + sizeof (EFI_DEVICE_PATH_PROTOCOL)];
+ MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *FilePath;
if (UnregisterFromDxe) {
UnregisterImageFromDxe (
@@ -926,11 +934,11 @@ UnregisterSmramProfileImage (
return EFI_UNSUPPORTED;
}
- FilePath = (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *) TempBuffer;
+ FilePath = (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *)TempBuffer;
EfiInitializeFwVolDevicepathNode (FilePath, &DriverEntry->FileName);
SetDevicePathEndNode (FilePath + 1);
- if (!NeedRecordThisDriver ((EFI_DEVICE_PATH_PROTOCOL *) FilePath)) {
+ if (!NeedRecordThisDriver ((EFI_DEVICE_PATH_PROTOCOL *)FilePath)) {
return EFI_UNSUPPORTED;
}
@@ -940,23 +948,26 @@ UnregisterSmramProfileImage (
}
DriverInfoData = NULL;
- FileName = &DriverEntry->FileName;
- ImageAddress = DriverEntry->ImageBuffer;
+ FileName = &DriverEntry->FileName;
+ ImageAddress = DriverEntry->ImageBuffer;
if ((DriverEntry->ImageEntryPoint < ImageAddress) || (DriverEntry->ImageEntryPoint >= (ImageAddress + EFI_PAGES_TO_SIZE (DriverEntry->NumberOfPage)))) {
//
// 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->ImageEntryPoint - (UINTN) EntryPointInImage;
+ ImageAddress = ImageAddress + (UINTN)DriverEntry->ImageEntryPoint - (UINTN)EntryPointInImage;
}
+
if (FileName != NULL) {
DriverInfoData = GetMemoryProfileDriverInfoByFileNameAndAddress (ContextData, FileName, ImageAddress);
}
+
if (DriverInfoData == NULL) {
DriverInfoData = GetMemoryProfileDriverInfoFromAddress (ContextData, ImageAddress);
}
+
if (DriverInfoData == NULL) {
return EFI_NOT_FOUND;
}
@@ -964,11 +975,11 @@ UnregisterSmramProfileImage (
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 SmmInternalFreePool() that will not update profile for this FreePool action.
@@ -991,13 +1002,14 @@ UnregisterSmramProfileImage (
**/
BOOLEAN
SmmCoreNeedRecordProfile (
- IN EFI_MEMORY_TYPE MemoryType
+ IN EFI_MEMORY_TYPE MemoryType
)
{
- UINT64 TestBit;
+ UINT64 TestBit;
- if (MemoryType != EfiRuntimeServicesCode &&
- MemoryType != EfiRuntimeServicesData) {
+ if ((MemoryType != EfiRuntimeServicesCode) &&
+ (MemoryType != EfiRuntimeServicesData))
+ {
return FALSE;
}
@@ -1023,7 +1035,7 @@ SmmCoreNeedRecordProfile (
**/
EFI_MEMORY_TYPE
GetProfileMemoryIndex (
- IN EFI_MEMORY_TYPE MemoryType
+ IN EFI_MEMORY_TYPE MemoryType
)
{
return MemoryType;
@@ -1040,17 +1052,18 @@ SmramProfileUpdateFreePages (
IN MEMORY_PROFILE_CONTEXT_DATA *ContextData
)
{
- LIST_ENTRY *Node;
- FREE_PAGE_LIST *Pages;
- LIST_ENTRY *FreePageList;
- UINTN NumberOfPages;
+ LIST_ENTRY *Node;
+ FREE_PAGE_LIST *Pages;
+ LIST_ENTRY *FreePageList;
+ UINTN NumberOfPages;
NumberOfPages = 0;
- FreePageList = &mSmmMemoryMap;
+ FreePageList = &mSmmMemoryMap;
for (Node = FreePageList->BackLink;
Node != FreePageList;
- Node = Node->BackLink) {
- Pages = BASE_CR (Node, FREE_PAGE_LIST, Link);
+ Node = Node->BackLink)
+ {
+ Pages = BASE_CR (Node, FREE_PAGE_LIST, Link);
NumberOfPages += Pages->NumberOfPages;
}
@@ -1087,17 +1100,17 @@ SmmCoreUpdateProfileAllocate (
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;
- EFI_MEMORY_TYPE 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;
+ EFI_MEMORY_TYPE ProfileMemoryIndex;
+ MEMORY_PROFILE_ACTION BasicAction;
+ UINTN ActionStringSize;
+ UINTN ActionStringOccupiedSize;
BasicAction = Action & MEMORY_PROFILE_ACTION_BASIC_MASK;
@@ -1111,10 +1124,10 @@ SmmCoreUpdateProfileAllocate (
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));
}
@@ -1122,48 +1135,49 @@ SmmCoreUpdateProfileAllocate (
// Use SmmInternalAllocatePool() that will not update profile for this AllocatePool action.
//
AllocInfoData = NULL;
- Status = SmmInternalAllocatePool (
- EfiRuntimeServicesData,
- sizeof (*AllocInfoData) + ActionStringSize,
- (VOID **) &AllocInfoData
- );
+ Status = SmmInternalAllocatePool (
+ EfiRuntimeServicesData,
+ 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 ++;
- }
-
- 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;
+ 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;
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.
@@ -1175,6 +1189,7 @@ SmmCoreUpdateProfileAllocate (
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];
@@ -1184,6 +1199,7 @@ SmmCoreUpdateProfileAllocate (
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];
@@ -1207,22 +1223,23 @@ SmmCoreUpdateProfileAllocate (
**/
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,
@@ -1233,17 +1250,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);
@@ -1306,7 +1327,7 @@ SmmCoreUpdateProfileFree (
// Need use do-while loop to find all possible record,
// because one address might be recorded multiple times.
//
- Found = FALSE;
+ Found = FALSE;
AllocInfoData = NULL;
do {
if (DriverInfoData != NULL) {
@@ -1323,6 +1344,7 @@ SmmCoreUpdateProfileFree (
break;
}
}
+
if (AllocInfoData == NULL) {
//
// Legal case, because driver A might free memory allocated by driver B, by some protocol.
@@ -1331,7 +1353,8 @@ SmmCoreUpdateProfileFree (
for (DriverLink = DriverInfoList->ForwardLink;
DriverLink != DriverInfoList;
- DriverLink = DriverLink->ForwardLink) {
+ DriverLink = DriverLink->ForwardLink)
+ {
ThisDriverInfoData = CR (
DriverLink,
MEMORY_PROFILE_DRIVER_INFO_DATA,
@@ -1350,6 +1373,7 @@ SmmCoreUpdateProfileFree (
AllocInfoData = NULL;
break;
}
+
if (AllocInfoData != NULL) {
DriverInfoData = ThisDriverInfoData;
break;
@@ -1374,44 +1398,45 @@ SmmCoreUpdateProfileFree (
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) {
SmmCoreUpdateProfileAllocate (
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)) {
SmmCoreUpdateProfileAllocate (
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
);
}
@@ -1457,9 +1482,9 @@ SmmCoreUpdateProfile (
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_SMRAM_PROFILE_ENABLED) {
return EFI_UNSUPPORTED;
@@ -1547,21 +1572,21 @@ SmramProfileGetDataSize (
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;
- LIST_ENTRY *Node;
- LIST_ENTRY *FreePageList;
- LIST_ENTRY *FreePoolList;
- FREE_POOL_HEADER *Pool;
- UINTN PoolListIndex;
- UINTN Index;
- UINTN SmmPoolTypeIndex;
+ 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;
+ LIST_ENTRY *Node;
+ LIST_ENTRY *FreePageList;
+ LIST_ENTRY *FreePoolList;
+ FREE_POOL_HEADER *Pool;
+ UINTN PoolListIndex;
+ UINTN Index;
+ UINTN SmmPoolTypeIndex;
ContextData = GetSmramProfileContext ();
if (ContextData == NULL) {
@@ -1573,19 +1598,21 @@ SmramProfileGetDataSize (
DriverInfoList = ContextData->DriverInfoList;
for (DriverLink = DriverInfoList->ForwardLink;
DriverLink != DriverInfoList;
- DriverLink = DriverLink->ForwardLink) {
+ DriverLink = DriverLink->ForwardLink)
+ {
DriverInfoData = CR (
- DriverLink,
- MEMORY_PROFILE_DRIVER_INFO_DATA,
- Link,
- MEMORY_PROFILE_DRIVER_INFO_SIGNATURE
- );
+ DriverLink,
+ MEMORY_PROFILE_DRIVER_INFO_DATA,
+ Link,
+ MEMORY_PROFILE_DRIVER_INFO_SIGNATURE
+ );
TotalSize += DriverInfoData->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,
@@ -1596,20 +1623,22 @@ SmramProfileGetDataSize (
}
}
-
- Index = 0;
+ Index = 0;
FreePageList = &mSmmMemoryMap;
for (Node = FreePageList->BackLink;
Node != FreePageList;
- Node = Node->BackLink) {
+ Node = Node->BackLink)
+ {
Index++;
}
+
for (SmmPoolTypeIndex = 0; SmmPoolTypeIndex < SmmPoolTypeMax; SmmPoolTypeIndex++) {
for (PoolListIndex = 0; PoolListIndex < MAX_POOL_INDEX; PoolListIndex++) {
FreePoolList = &mSmmPoolLists[SmmPoolTypeIndex][PoolListIndex];
for (Node = FreePoolList->BackLink;
Node != FreePoolList;
- Node = Node->BackLink) {
+ Node = Node->BackLink)
+ {
Pool = BASE_CR (Node, FREE_POOL_HEADER, Link);
if (Pool->Header.Available) {
Index++;
@@ -1636,9 +1665,9 @@ SmramProfileGetDataSize (
**/
VOID
SmramProfileCopyData (
- OUT VOID *ProfileBuffer,
- IN OUT UINT64 *ProfileSize,
- IN OUT UINT64 *ProfileOffset
+ OUT VOID *ProfileBuffer,
+ IN OUT UINT64 *ProfileSize,
+ IN OUT UINT64 *ProfileOffset
)
{
MEMORY_PROFILE_CONTEXT *Context;
@@ -1647,50 +1676,52 @@ SmramProfileCopyData (
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;
- LIST_ENTRY *Node;
- FREE_PAGE_LIST *Pages;
- LIST_ENTRY *FreePageList;
- LIST_ENTRY *FreePoolList;
- FREE_POOL_HEADER *Pool;
- UINTN PoolListIndex;
- UINT32 Index;
- MEMORY_PROFILE_FREE_MEMORY *FreeMemory;
- MEMORY_PROFILE_MEMORY_RANGE *MemoryRange;
- MEMORY_PROFILE_DESCRIPTOR *MemoryProfileDescriptor;
- UINT64 Offset;
- UINT64 RemainingSize;
- UINTN PdbSize;
- UINTN ActionStringSize;
- UINTN SmmPoolTypeIndex;
+ LIST_ENTRY *DriverInfoList;
+ LIST_ENTRY *DriverLink;
+ LIST_ENTRY *AllocInfoList;
+ LIST_ENTRY *AllocLink;
+ LIST_ENTRY *Node;
+ FREE_PAGE_LIST *Pages;
+ LIST_ENTRY *FreePageList;
+ LIST_ENTRY *FreePoolList;
+ FREE_POOL_HEADER *Pool;
+ UINTN PoolListIndex;
+ UINT32 Index;
+ MEMORY_PROFILE_FREE_MEMORY *FreeMemory;
+ MEMORY_PROFILE_MEMORY_RANGE *MemoryRange;
+ MEMORY_PROFILE_DESCRIPTOR *MemoryProfileDescriptor;
+ UINT64 Offset;
+ UINT64 RemainingSize;
+ UINTN PdbSize;
+ UINTN ActionStringSize;
+ UINTN SmmPoolTypeIndex;
ContextData = GetSmramProfileContext ();
if (ContextData == NULL) {
- return ;
+ return;
}
RemainingSize = *ProfileSize;
- Offset = 0;
+ Offset = 0;
if (*ProfileOffset < sizeof (MEMORY_PROFILE_CONTEXT)) {
if (RemainingSize >= sizeof (MEMORY_PROFILE_CONTEXT)) {
Context = ProfileBuffer;
CopyMem (Context, &ContextData->Context, sizeof (MEMORY_PROFILE_CONTEXT));
RemainingSize -= sizeof (MEMORY_PROFILE_CONTEXT);
- ProfileBuffer = (UINT8 *) ProfileBuffer + sizeof (MEMORY_PROFILE_CONTEXT);
+ ProfileBuffer = (UINT8 *)ProfileBuffer + sizeof (MEMORY_PROFILE_CONTEXT);
} else {
goto Done;
}
}
+
Offset += sizeof (MEMORY_PROFILE_CONTEXT);
DriverInfoList = ContextData->DriverInfoList;
for (DriverLink = DriverInfoList->ForwardLink;
DriverLink != DriverInfoList;
- DriverLink = DriverLink->ForwardLink) {
+ DriverLink = DriverLink->ForwardLink)
+ {
DriverInfoData = CR (
DriverLink,
MEMORY_PROFILE_DRIVER_INFO_DATA,
@@ -1703,20 +1734,23 @@ SmramProfileCopyData (
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);
}
+
RemainingSize -= DriverInfo->Header.Length;
- ProfileBuffer = (UINT8 *) ProfileBuffer + DriverInfo->Header.Length;
+ ProfileBuffer = (UINT8 *)ProfileBuffer + DriverInfo->Header.Length;
} else {
goto Done;
}
}
+
Offset += DriverInfoData->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,
@@ -1729,36 +1763,40 @@ SmramProfileCopyData (
CopyMem (AllocInfo, &AllocInfoData->AllocInfo, sizeof (MEMORY_PROFILE_ALLOC_INFO));
if (AllocInfo->ActionStringOffset) {
ActionStringSize = AsciiStrSize (AllocInfoData->ActionString);
- CopyMem ((VOID *) ((UINTN) AllocInfo + AllocInfo->ActionStringOffset), AllocInfoData->ActionString, ActionStringSize);
+ CopyMem ((VOID *)((UINTN)AllocInfo + AllocInfo->ActionStringOffset), AllocInfoData->ActionString, ActionStringSize);
}
+
RemainingSize -= AllocInfo->Header.Length;
- ProfileBuffer = (UINT8 *) ProfileBuffer + AllocInfo->Header.Length;
+ ProfileBuffer = (UINT8 *)ProfileBuffer + AllocInfo->Header.Length;
} else {
goto Done;
}
}
+
Offset += AllocInfoData->AllocInfo.Header.Length;
}
}
-
if (*ProfileOffset < (Offset + sizeof (MEMORY_PROFILE_FREE_MEMORY))) {
if (RemainingSize >= sizeof (MEMORY_PROFILE_FREE_MEMORY)) {
FreeMemory = ProfileBuffer;
CopyMem (FreeMemory, &mSmramFreeMemory, sizeof (MEMORY_PROFILE_FREE_MEMORY));
- Index = 0;
+ Index = 0;
FreePageList = &mSmmMemoryMap;
for (Node = FreePageList->BackLink;
Node != FreePageList;
- Node = Node->BackLink) {
+ Node = Node->BackLink)
+ {
Index++;
}
+
for (SmmPoolTypeIndex = 0; SmmPoolTypeIndex < SmmPoolTypeMax; SmmPoolTypeIndex++) {
for (PoolListIndex = 0; PoolListIndex < MAX_POOL_INDEX; PoolListIndex++) {
FreePoolList = &mSmmPoolLists[SmmPoolTypeIndex][MAX_POOL_INDEX - PoolListIndex - 1];
for (Node = FreePoolList->BackLink;
Node != FreePoolList;
- Node = Node->BackLink) {
+ Node = Node->BackLink)
+ {
Pool = BASE_CR (Node, FREE_POOL_HEADER, Link);
if (Pool->Header.Available) {
Index++;
@@ -1766,60 +1804,67 @@ SmramProfileCopyData (
}
}
}
+
FreeMemory->FreeMemoryEntryCount = Index;
RemainingSize -= sizeof (MEMORY_PROFILE_FREE_MEMORY);
- ProfileBuffer = (UINT8 *) ProfileBuffer + sizeof (MEMORY_PROFILE_FREE_MEMORY);
+ ProfileBuffer = (UINT8 *)ProfileBuffer + sizeof (MEMORY_PROFILE_FREE_MEMORY);
} else {
goto Done;
}
}
- Offset += sizeof (MEMORY_PROFILE_FREE_MEMORY);
+
+ Offset += sizeof (MEMORY_PROFILE_FREE_MEMORY);
FreePageList = &mSmmMemoryMap;
for (Node = FreePageList->BackLink;
Node != FreePageList;
- Node = Node->BackLink) {
+ Node = Node->BackLink)
+ {
if (*ProfileOffset < (Offset + sizeof (MEMORY_PROFILE_DESCRIPTOR))) {
if (RemainingSize >= sizeof (MEMORY_PROFILE_DESCRIPTOR)) {
- Pages = BASE_CR (Node, FREE_PAGE_LIST, Link);
- MemoryProfileDescriptor = ProfileBuffer;
+ Pages = BASE_CR (Node, FREE_PAGE_LIST, Link);
+ MemoryProfileDescriptor = ProfileBuffer;
MemoryProfileDescriptor->Header.Signature = MEMORY_PROFILE_DESCRIPTOR_SIGNATURE;
- MemoryProfileDescriptor->Header.Length = sizeof (MEMORY_PROFILE_DESCRIPTOR);
- MemoryProfileDescriptor->Header.Revision = MEMORY_PROFILE_DESCRIPTOR_REVISION;
- MemoryProfileDescriptor->Address = (PHYSICAL_ADDRESS) (UINTN) Pages;
- MemoryProfileDescriptor->Size = EFI_PAGES_TO_SIZE (Pages->NumberOfPages);
+ MemoryProfileDescriptor->Header.Length = sizeof (MEMORY_PROFILE_DESCRIPTOR);
+ MemoryProfileDescriptor->Header.Revision = MEMORY_PROFILE_DESCRIPTOR_REVISION;
+ MemoryProfileDescriptor->Address = (PHYSICAL_ADDRESS)(UINTN)Pages;
+ MemoryProfileDescriptor->Size = EFI_PAGES_TO_SIZE (Pages->NumberOfPages);
RemainingSize -= sizeof (MEMORY_PROFILE_DESCRIPTOR);
- ProfileBuffer = (UINT8 *) ProfileBuffer + sizeof (MEMORY_PROFILE_DESCRIPTOR);
+ ProfileBuffer = (UINT8 *)ProfileBuffer + sizeof (MEMORY_PROFILE_DESCRIPTOR);
} else {
goto Done;
}
}
+
Offset += sizeof (MEMORY_PROFILE_DESCRIPTOR);
}
+
for (SmmPoolTypeIndex = 0; SmmPoolTypeIndex < SmmPoolTypeMax; SmmPoolTypeIndex++) {
for (PoolListIndex = 0; PoolListIndex < MAX_POOL_INDEX; PoolListIndex++) {
FreePoolList = &mSmmPoolLists[SmmPoolTypeIndex][MAX_POOL_INDEX - PoolListIndex - 1];
for (Node = FreePoolList->BackLink;
Node != FreePoolList;
- Node = Node->BackLink) {
+ Node = Node->BackLink)
+ {
Pool = BASE_CR (Node, FREE_POOL_HEADER, Link);
if (Pool->Header.Available) {
if (*ProfileOffset < (Offset + sizeof (MEMORY_PROFILE_DESCRIPTOR))) {
if (RemainingSize >= sizeof (MEMORY_PROFILE_DESCRIPTOR)) {
- MemoryProfileDescriptor = ProfileBuffer;
+ MemoryProfileDescriptor = ProfileBuffer;
MemoryProfileDescriptor->Header.Signature = MEMORY_PROFILE_DESCRIPTOR_SIGNATURE;
- MemoryProfileDescriptor->Header.Length = sizeof (MEMORY_PROFILE_DESCRIPTOR);
- MemoryProfileDescriptor->Header.Revision = MEMORY_PROFILE_DESCRIPTOR_REVISION;
- MemoryProfileDescriptor->Address = (PHYSICAL_ADDRESS) (UINTN) Pool;
- MemoryProfileDescriptor->Size = Pool->Header.Size;
+ MemoryProfileDescriptor->Header.Length = sizeof (MEMORY_PROFILE_DESCRIPTOR);
+ MemoryProfileDescriptor->Header.Revision = MEMORY_PROFILE_DESCRIPTOR_REVISION;
+ MemoryProfileDescriptor->Address = (PHYSICAL_ADDRESS)(UINTN)Pool;
+ MemoryProfileDescriptor->Size = Pool->Header.Size;
RemainingSize -= sizeof (MEMORY_PROFILE_DESCRIPTOR);
- ProfileBuffer = (UINT8 *) ProfileBuffer + sizeof (MEMORY_PROFILE_DESCRIPTOR);
+ ProfileBuffer = (UINT8 *)ProfileBuffer + sizeof (MEMORY_PROFILE_DESCRIPTOR);
} else {
goto Done;
}
}
+
Offset += sizeof (MEMORY_PROFILE_DESCRIPTOR);
}
}
@@ -1828,35 +1873,37 @@ SmramProfileCopyData (
if (*ProfileOffset < (Offset + sizeof (MEMORY_PROFILE_MEMORY_RANGE))) {
if (RemainingSize >= sizeof (MEMORY_PROFILE_MEMORY_RANGE)) {
- MemoryRange = ProfileBuffer;
+ MemoryRange = ProfileBuffer;
MemoryRange->Header.Signature = MEMORY_PROFILE_MEMORY_RANGE_SIGNATURE;
- MemoryRange->Header.Length = sizeof (MEMORY_PROFILE_MEMORY_RANGE);
- MemoryRange->Header.Revision = MEMORY_PROFILE_MEMORY_RANGE_REVISION;
- MemoryRange->MemoryRangeCount = (UINT32) mFullSmramRangeCount;
+ MemoryRange->Header.Length = sizeof (MEMORY_PROFILE_MEMORY_RANGE);
+ MemoryRange->Header.Revision = MEMORY_PROFILE_MEMORY_RANGE_REVISION;
+ MemoryRange->MemoryRangeCount = (UINT32)mFullSmramRangeCount;
RemainingSize -= sizeof (MEMORY_PROFILE_MEMORY_RANGE);
- ProfileBuffer = (UINT8 *) ProfileBuffer + sizeof (MEMORY_PROFILE_MEMORY_RANGE);
+ ProfileBuffer = (UINT8 *)ProfileBuffer + sizeof (MEMORY_PROFILE_MEMORY_RANGE);
} else {
goto Done;
}
}
+
Offset += sizeof (MEMORY_PROFILE_MEMORY_RANGE);
for (Index = 0; Index < mFullSmramRangeCount; Index++) {
if (*ProfileOffset < (Offset + sizeof (MEMORY_PROFILE_DESCRIPTOR))) {
if (RemainingSize >= sizeof (MEMORY_PROFILE_DESCRIPTOR)) {
- MemoryProfileDescriptor = ProfileBuffer;
+ MemoryProfileDescriptor = ProfileBuffer;
MemoryProfileDescriptor->Header.Signature = MEMORY_PROFILE_DESCRIPTOR_SIGNATURE;
- MemoryProfileDescriptor->Header.Length = sizeof (MEMORY_PROFILE_DESCRIPTOR);
- MemoryProfileDescriptor->Header.Revision = MEMORY_PROFILE_DESCRIPTOR_REVISION;
- MemoryProfileDescriptor->Address = mFullSmramRanges[Index].PhysicalStart;
- MemoryProfileDescriptor->Size = mFullSmramRanges[Index].PhysicalSize;
+ MemoryProfileDescriptor->Header.Length = sizeof (MEMORY_PROFILE_DESCRIPTOR);
+ MemoryProfileDescriptor->Header.Revision = MEMORY_PROFILE_DESCRIPTOR_REVISION;
+ MemoryProfileDescriptor->Address = mFullSmramRanges[Index].PhysicalStart;
+ MemoryProfileDescriptor->Size = mFullSmramRanges[Index].PhysicalSize;
RemainingSize -= sizeof (MEMORY_PROFILE_DESCRIPTOR);
- ProfileBuffer = (UINT8 *) ProfileBuffer + sizeof (MEMORY_PROFILE_DESCRIPTOR);
+ ProfileBuffer = (UINT8 *)ProfileBuffer + sizeof (MEMORY_PROFILE_DESCRIPTOR);
} else {
goto Done;
}
}
+
Offset += sizeof (MEMORY_PROFILE_DESCRIPTOR);
}
@@ -1890,26 +1937,26 @@ EFIAPI
SmramProfileProtocolGetData (
IN EDKII_SMM_MEMORY_PROFILE_PROTOCOL *This,
IN OUT UINT64 *ProfileSize,
- OUT VOID *ProfileBuffer
+ OUT VOID *ProfileBuffer
)
{
- UINT64 Size;
- UINT64 Offset;
- MEMORY_PROFILE_CONTEXT_DATA *ContextData;
- BOOLEAN SmramProfileGettingStatus;
+ UINT64 Size;
+ UINT64 Offset;
+ MEMORY_PROFILE_CONTEXT_DATA *ContextData;
+ BOOLEAN SmramProfileGettingStatus;
ContextData = GetSmramProfileContext ();
if (ContextData == NULL) {
return EFI_UNSUPPORTED;
}
- SmramProfileGettingStatus = mSmramProfileGettingStatus;
+ SmramProfileGettingStatus = mSmramProfileGettingStatus;
mSmramProfileGettingStatus = TRUE;
Size = SmramProfileGetDataSize ();
if (*ProfileSize < Size) {
- *ProfileSize = Size;
+ *ProfileSize = Size;
mSmramProfileGettingStatus = SmramProfileGettingStatus;
return EFI_BUFFER_TOO_SMALL;
}
@@ -1947,21 +1994,22 @@ SmramProfileProtocolRegisterImage (
IN EFI_FV_FILETYPE FileType
)
{
- EFI_STATUS Status;
- EFI_SMM_DRIVER_ENTRY DriverEntry;
- VOID *EntryPointInImage;
- EFI_GUID *Name;
+ EFI_STATUS Status;
+ EFI_SMM_DRIVER_ENTRY DriverEntry;
+ VOID *EntryPointInImage;
+ EFI_GUID *Name;
ZeroMem (&DriverEntry, sizeof (DriverEntry));
Name = GetFileNameFromFilePath (FilePath);
if (Name != NULL) {
CopyMem (&DriverEntry.FileName, Name, sizeof (EFI_GUID));
}
- DriverEntry.ImageBuffer = ImageBase;
- DriverEntry.NumberOfPage = EFI_SIZE_TO_PAGES ((UINTN) ImageSize);
- Status = InternalPeCoffGetEntryPoint ((VOID *) (UINTN) DriverEntry.ImageBuffer, &EntryPointInImage);
+
+ DriverEntry.ImageBuffer = ImageBase;
+ DriverEntry.NumberOfPage = EFI_SIZE_TO_PAGES ((UINTN)ImageSize);
+ Status = InternalPeCoffGetEntryPoint ((VOID *)(UINTN)DriverEntry.ImageBuffer, &EntryPointInImage);
ASSERT_EFI_ERROR (Status);
- DriverEntry.ImageEntryPoint = (PHYSICAL_ADDRESS) (UINTN) EntryPointInImage;
+ DriverEntry.ImageEntryPoint = (PHYSICAL_ADDRESS)(UINTN)EntryPointInImage;
return RegisterSmramProfileImage (&DriverEntry, FALSE);
}
@@ -1989,21 +2037,22 @@ SmramProfileProtocolUnregisterImage (
IN UINT64 ImageSize
)
{
- EFI_STATUS Status;
- EFI_SMM_DRIVER_ENTRY DriverEntry;
- VOID *EntryPointInImage;
- EFI_GUID *Name;
+ EFI_STATUS Status;
+ EFI_SMM_DRIVER_ENTRY DriverEntry;
+ VOID *EntryPointInImage;
+ EFI_GUID *Name;
ZeroMem (&DriverEntry, sizeof (DriverEntry));
Name = GetFileNameFromFilePath (FilePath);
if (Name != NULL) {
CopyMem (&DriverEntry.FileName, Name, sizeof (EFI_GUID));
}
- DriverEntry.ImageBuffer = ImageBase;
- DriverEntry.NumberOfPage = EFI_SIZE_TO_PAGES ((UINTN) ImageSize);
- Status = InternalPeCoffGetEntryPoint ((VOID *) (UINTN) DriverEntry.ImageBuffer, &EntryPointInImage);
+
+ DriverEntry.ImageBuffer = ImageBase;
+ DriverEntry.NumberOfPage = EFI_SIZE_TO_PAGES ((UINTN)ImageSize);
+ Status = InternalPeCoffGetEntryPoint ((VOID *)(UINTN)DriverEntry.ImageBuffer, &EntryPointInImage);
ASSERT_EFI_ERROR (Status);
- DriverEntry.ImageEntryPoint = (PHYSICAL_ADDRESS) (UINTN) EntryPointInImage;
+ DriverEntry.ImageEntryPoint = (PHYSICAL_ADDRESS)(UINTN)EntryPointInImage;
return UnregisterSmramProfileImage (&DriverEntry, FALSE);
}
@@ -2026,7 +2075,7 @@ SmramProfileProtocolGetRecordingState (
OUT BOOLEAN *RecordingState
)
{
- MEMORY_PROFILE_CONTEXT_DATA *ContextData;
+ MEMORY_PROFILE_CONTEXT_DATA *ContextData;
ContextData = GetSmramProfileContext ();
if (ContextData == NULL) {
@@ -2036,6 +2085,7 @@ SmramProfileProtocolGetRecordingState (
if (RecordingState == NULL) {
return EFI_INVALID_PARAMETER;
}
+
*RecordingState = mSmramProfileRecordingEnable;
return EFI_SUCCESS;
}
@@ -2057,7 +2107,7 @@ SmramProfileProtocolSetRecordingState (
IN BOOLEAN RecordingState
)
{
- MEMORY_PROFILE_CONTEXT_DATA *ContextData;
+ MEMORY_PROFILE_CONTEXT_DATA *ContextData;
ContextData = GetSmramProfileContext ();
if (ContextData == NULL) {
@@ -2114,21 +2164,21 @@ SmramProfileProtocolRecord (
**/
VOID
SmramProfileHandlerGetInfo (
- IN SMRAM_PROFILE_PARAMETER_GET_PROFILE_INFO *SmramProfileParameterGetInfo
+ IN SMRAM_PROFILE_PARAMETER_GET_PROFILE_INFO *SmramProfileParameterGetInfo
)
{
- MEMORY_PROFILE_CONTEXT_DATA *ContextData;
- BOOLEAN SmramProfileGettingStatus;
+ MEMORY_PROFILE_CONTEXT_DATA *ContextData;
+ BOOLEAN SmramProfileGettingStatus;
ContextData = GetSmramProfileContext ();
if (ContextData == NULL) {
- return ;
+ return;
}
- SmramProfileGettingStatus = mSmramProfileGettingStatus;
+ SmramProfileGettingStatus = mSmramProfileGettingStatus;
mSmramProfileGettingStatus = TRUE;
- SmramProfileParameterGetInfo->ProfileSize = SmramProfileGetDataSize();
+ SmramProfileParameterGetInfo->ProfileSize = SmramProfileGetDataSize ();
SmramProfileParameterGetInfo->Header.ReturnStatus = 0;
mSmramProfileGettingStatus = SmramProfileGettingStatus;
@@ -2142,7 +2192,7 @@ SmramProfileHandlerGetInfo (
**/
VOID
SmramProfileHandlerGetData (
- IN SMRAM_PROFILE_PARAMETER_GET_PROFILE_DATA *SmramProfileParameterGetData
+ IN SMRAM_PROFILE_PARAMETER_GET_PROFILE_DATA *SmramProfileParameterGetData
)
{
UINT64 ProfileSize;
@@ -2153,36 +2203,35 @@ SmramProfileHandlerGetData (
ContextData = GetSmramProfileContext ();
if (ContextData == NULL) {
- return ;
+ return;
}
- SmramProfileGettingStatus = mSmramProfileGettingStatus;
+ SmramProfileGettingStatus = mSmramProfileGettingStatus;
mSmramProfileGettingStatus = TRUE;
-
CopyMem (&SmramProfileGetData, SmramProfileParameterGetData, sizeof (SmramProfileGetData));
- ProfileSize = SmramProfileGetDataSize();
+ ProfileSize = SmramProfileGetDataSize ();
//
// Sanity check
//
- if (!SmmIsBufferOutsideSmmValid ((UINTN) SmramProfileGetData.ProfileBuffer, (UINTN) ProfileSize)) {
+ if (!SmmIsBufferOutsideSmmValid ((UINTN)SmramProfileGetData.ProfileBuffer, (UINTN)ProfileSize)) {
DEBUG ((DEBUG_ERROR, "SmramProfileHandlerGetData: SMM ProfileBuffer in SMRAM or overflow!\n"));
- SmramProfileParameterGetData->ProfileSize = ProfileSize;
- SmramProfileParameterGetData->Header.ReturnStatus = (UINT64) (INT64) (INTN) EFI_ACCESS_DENIED;
+ SmramProfileParameterGetData->ProfileSize = ProfileSize;
+ SmramProfileParameterGetData->Header.ReturnStatus = (UINT64)(INT64)(INTN)EFI_ACCESS_DENIED;
goto Done;
}
if (SmramProfileGetData.ProfileSize < ProfileSize) {
- SmramProfileParameterGetData->ProfileSize = ProfileSize;
- SmramProfileParameterGetData->Header.ReturnStatus = (UINT64) (INT64) (INTN) EFI_BUFFER_TOO_SMALL;
+ SmramProfileParameterGetData->ProfileSize = ProfileSize;
+ SmramProfileParameterGetData->Header.ReturnStatus = (UINT64)(INT64)(INTN)EFI_BUFFER_TOO_SMALL;
goto Done;
}
ProfileOffset = 0;
- SmramProfileCopyData ((VOID *) (UINTN) SmramProfileGetData.ProfileBuffer, &ProfileSize, &ProfileOffset);
- SmramProfileParameterGetData->ProfileSize = ProfileSize;
+ SmramProfileCopyData ((VOID *)(UINTN)SmramProfileGetData.ProfileBuffer, &ProfileSize, &ProfileOffset);
+ SmramProfileParameterGetData->ProfileSize = ProfileSize;
SmramProfileParameterGetData->Header.ReturnStatus = 0;
Done:
@@ -2197,34 +2246,33 @@ Done:
**/
VOID
SmramProfileHandlerGetDataByOffset (
- IN SMRAM_PROFILE_PARAMETER_GET_PROFILE_DATA_BY_OFFSET *SmramProfileParameterGetDataByOffset
+ IN SMRAM_PROFILE_PARAMETER_GET_PROFILE_DATA_BY_OFFSET *SmramProfileParameterGetDataByOffset
)
{
- SMRAM_PROFILE_PARAMETER_GET_PROFILE_DATA_BY_OFFSET SmramProfileGetDataByOffset;
- MEMORY_PROFILE_CONTEXT_DATA *ContextData;
- BOOLEAN SmramProfileGettingStatus;
+ SMRAM_PROFILE_PARAMETER_GET_PROFILE_DATA_BY_OFFSET SmramProfileGetDataByOffset;
+ MEMORY_PROFILE_CONTEXT_DATA *ContextData;
+ BOOLEAN SmramProfileGettingStatus;
ContextData = GetSmramProfileContext ();
if (ContextData == NULL) {
- return ;
+ return;
}
- SmramProfileGettingStatus = mSmramProfileGettingStatus;
+ SmramProfileGettingStatus = mSmramProfileGettingStatus;
mSmramProfileGettingStatus = TRUE;
-
CopyMem (&SmramProfileGetDataByOffset, SmramProfileParameterGetDataByOffset, sizeof (SmramProfileGetDataByOffset));
//
// Sanity check
//
- if (!SmmIsBufferOutsideSmmValid ((UINTN) SmramProfileGetDataByOffset.ProfileBuffer, (UINTN) SmramProfileGetDataByOffset.ProfileSize)) {
+ if (!SmmIsBufferOutsideSmmValid ((UINTN)SmramProfileGetDataByOffset.ProfileBuffer, (UINTN)SmramProfileGetDataByOffset.ProfileSize)) {
DEBUG ((DEBUG_ERROR, "SmramProfileHandlerGetDataByOffset: SMM ProfileBuffer in SMRAM or overflow!\n"));
- SmramProfileParameterGetDataByOffset->Header.ReturnStatus = (UINT64) (INT64) (INTN) EFI_ACCESS_DENIED;
+ SmramProfileParameterGetDataByOffset->Header.ReturnStatus = (UINT64)(INT64)(INTN)EFI_ACCESS_DENIED;
goto Done;
}
- SmramProfileCopyData ((VOID *) (UINTN) SmramProfileGetDataByOffset.ProfileBuffer, &SmramProfileGetDataByOffset.ProfileSize, &SmramProfileGetDataByOffset.ProfileOffset);
+ SmramProfileCopyData ((VOID *)(UINTN)SmramProfileGetDataByOffset.ProfileBuffer, &SmramProfileGetDataByOffset.ProfileSize, &SmramProfileGetDataByOffset.ProfileOffset);
CopyMem (SmramProfileParameterGetDataByOffset, &SmramProfileGetDataByOffset, sizeof (SmramProfileGetDataByOffset));
SmramProfileParameterGetDataByOffset->Header.ReturnStatus = 0;
@@ -2266,7 +2314,7 @@ SmramProfileHandler (
//
// If input is invalid, stop processing this SMI
//
- if (CommBuffer == NULL || CommBufferSize == NULL) {
+ if ((CommBuffer == NULL) || (CommBufferSize == NULL)) {
return EFI_SUCCESS;
}
@@ -2282,72 +2330,77 @@ SmramProfileHandler (
return EFI_SUCCESS;
}
- SmramProfileParameterHeader = (SMRAM_PROFILE_PARAMETER_HEADER *) ((UINTN) CommBuffer);
+ SmramProfileParameterHeader = (SMRAM_PROFILE_PARAMETER_HEADER *)((UINTN)CommBuffer);
SmramProfileParameterHeader->ReturnStatus = (UINT64)-1;
if (GetSmramProfileContext () == NULL) {
- SmramProfileParameterHeader->ReturnStatus = (UINT64) (INT64) (INTN) EFI_UNSUPPORTED;
+ SmramProfileParameterHeader->ReturnStatus = (UINT64)(INT64)(INTN)EFI_UNSUPPORTED;
return EFI_SUCCESS;
}
switch (SmramProfileParameterHeader->Command) {
- case SMRAM_PROFILE_COMMAND_GET_PROFILE_INFO:
- DEBUG ((DEBUG_ERROR, "SmramProfileHandlerGetInfo\n"));
- if (TempCommBufferSize != sizeof (SMRAM_PROFILE_PARAMETER_GET_PROFILE_INFO)) {
- DEBUG ((DEBUG_ERROR, "SmramProfileHandler: SMM communication buffer size invalid!\n"));
- return EFI_SUCCESS;
- }
- SmramProfileHandlerGetInfo ((SMRAM_PROFILE_PARAMETER_GET_PROFILE_INFO *) (UINTN) CommBuffer);
- break;
- case SMRAM_PROFILE_COMMAND_GET_PROFILE_DATA:
- DEBUG ((DEBUG_ERROR, "SmramProfileHandlerGetData\n"));
- if (TempCommBufferSize != sizeof (SMRAM_PROFILE_PARAMETER_GET_PROFILE_DATA)) {
- DEBUG ((DEBUG_ERROR, "SmramProfileHandler: SMM communication buffer size invalid!\n"));
- return EFI_SUCCESS;
- }
- SmramProfileHandlerGetData ((SMRAM_PROFILE_PARAMETER_GET_PROFILE_DATA *) (UINTN) CommBuffer);
- break;
- case SMRAM_PROFILE_COMMAND_GET_PROFILE_DATA_BY_OFFSET:
- DEBUG ((DEBUG_ERROR, "SmramProfileHandlerGetDataByOffset\n"));
- if (TempCommBufferSize != sizeof (SMRAM_PROFILE_PARAMETER_GET_PROFILE_DATA_BY_OFFSET)) {
- DEBUG ((DEBUG_ERROR, "SmramProfileHandler: SMM communication buffer size invalid!\n"));
- return EFI_SUCCESS;
- }
- SmramProfileHandlerGetDataByOffset ((SMRAM_PROFILE_PARAMETER_GET_PROFILE_DATA_BY_OFFSET *) (UINTN) CommBuffer);
- break;
- case SMRAM_PROFILE_COMMAND_GET_RECORDING_STATE:
- DEBUG ((DEBUG_ERROR, "SmramProfileHandlerGetRecordingState\n"));
- if (TempCommBufferSize != sizeof (SMRAM_PROFILE_PARAMETER_RECORDING_STATE)) {
- DEBUG ((DEBUG_ERROR, "SmramProfileHandler: SMM communication buffer size invalid!\n"));
- return EFI_SUCCESS;
- }
- ParameterRecordingState = (SMRAM_PROFILE_PARAMETER_RECORDING_STATE *) (UINTN) CommBuffer;
- ParameterRecordingState->RecordingState = mSmramProfileRecordingEnable;
- ParameterRecordingState->Header.ReturnStatus = 0;
- break;
- case SMRAM_PROFILE_COMMAND_SET_RECORDING_STATE:
- DEBUG ((DEBUG_ERROR, "SmramProfileHandlerSetRecordingState\n"));
- if (TempCommBufferSize != sizeof (SMRAM_PROFILE_PARAMETER_RECORDING_STATE)) {
- DEBUG ((DEBUG_ERROR, "SmramProfileHandler: SMM communication buffer size invalid!\n"));
- return EFI_SUCCESS;
- }
- ParameterRecordingState = (SMRAM_PROFILE_PARAMETER_RECORDING_STATE *) (UINTN) CommBuffer;
- mSmramProfileRecordingEnable = ParameterRecordingState->RecordingState;
- ParameterRecordingState->Header.ReturnStatus = 0;
- break;
+ case SMRAM_PROFILE_COMMAND_GET_PROFILE_INFO:
+ DEBUG ((DEBUG_ERROR, "SmramProfileHandlerGetInfo\n"));
+ if (TempCommBufferSize != sizeof (SMRAM_PROFILE_PARAMETER_GET_PROFILE_INFO)) {
+ DEBUG ((DEBUG_ERROR, "SmramProfileHandler: SMM communication buffer size invalid!\n"));
+ return EFI_SUCCESS;
+ }
- //
- // Below 2 commands have been deprecated. They may not be (re-)used.
- //
- case SMRAM_PROFILE_COMMAND_DEPRECATED1:
- case SMRAM_PROFILE_COMMAND_DEPRECATED2:
- ASSERT (FALSE);
+ SmramProfileHandlerGetInfo ((SMRAM_PROFILE_PARAMETER_GET_PROFILE_INFO *)(UINTN)CommBuffer);
+ break;
+ case SMRAM_PROFILE_COMMAND_GET_PROFILE_DATA:
+ DEBUG ((DEBUG_ERROR, "SmramProfileHandlerGetData\n"));
+ if (TempCommBufferSize != sizeof (SMRAM_PROFILE_PARAMETER_GET_PROFILE_DATA)) {
+ DEBUG ((DEBUG_ERROR, "SmramProfileHandler: SMM communication buffer size invalid!\n"));
+ return EFI_SUCCESS;
+ }
+
+ SmramProfileHandlerGetData ((SMRAM_PROFILE_PARAMETER_GET_PROFILE_DATA *)(UINTN)CommBuffer);
+ break;
+ case SMRAM_PROFILE_COMMAND_GET_PROFILE_DATA_BY_OFFSET:
+ DEBUG ((DEBUG_ERROR, "SmramProfileHandlerGetDataByOffset\n"));
+ if (TempCommBufferSize != sizeof (SMRAM_PROFILE_PARAMETER_GET_PROFILE_DATA_BY_OFFSET)) {
+ DEBUG ((DEBUG_ERROR, "SmramProfileHandler: SMM communication buffer size invalid!\n"));
+ return EFI_SUCCESS;
+ }
+
+ SmramProfileHandlerGetDataByOffset ((SMRAM_PROFILE_PARAMETER_GET_PROFILE_DATA_BY_OFFSET *)(UINTN)CommBuffer);
+ break;
+ case SMRAM_PROFILE_COMMAND_GET_RECORDING_STATE:
+ DEBUG ((DEBUG_ERROR, "SmramProfileHandlerGetRecordingState\n"));
+ if (TempCommBufferSize != sizeof (SMRAM_PROFILE_PARAMETER_RECORDING_STATE)) {
+ DEBUG ((DEBUG_ERROR, "SmramProfileHandler: SMM communication buffer size invalid!\n"));
+ return EFI_SUCCESS;
+ }
+
+ ParameterRecordingState = (SMRAM_PROFILE_PARAMETER_RECORDING_STATE *)(UINTN)CommBuffer;
+ ParameterRecordingState->RecordingState = mSmramProfileRecordingEnable;
+ ParameterRecordingState->Header.ReturnStatus = 0;
+ break;
+ case SMRAM_PROFILE_COMMAND_SET_RECORDING_STATE:
+ DEBUG ((DEBUG_ERROR, "SmramProfileHandlerSetRecordingState\n"));
+ if (TempCommBufferSize != sizeof (SMRAM_PROFILE_PARAMETER_RECORDING_STATE)) {
+ DEBUG ((DEBUG_ERROR, "SmramProfileHandler: SMM communication buffer size invalid!\n"));
+ return EFI_SUCCESS;
+ }
+
+ ParameterRecordingState = (SMRAM_PROFILE_PARAMETER_RECORDING_STATE *)(UINTN)CommBuffer;
+ mSmramProfileRecordingEnable = ParameterRecordingState->RecordingState;
+ ParameterRecordingState->Header.ReturnStatus = 0;
+ break;
+
+ //
+ // Below 2 commands have been deprecated. They may not be (re-)used.
+ //
+ case SMRAM_PROFILE_COMMAND_DEPRECATED1:
+ case SMRAM_PROFILE_COMMAND_DEPRECATED2:
+ ASSERT (FALSE);
//
// Fall-through to the default (unrecognized command) case.
//
- default:
- break;
+ default:
+ break;
}
DEBUG ((DEBUG_ERROR, "SmramProfileHandler Exit\n"));
@@ -2364,8 +2417,8 @@ RegisterSmramProfileHandler (
VOID
)
{
- EFI_STATUS Status;
- EFI_HANDLE DispatchHandle;
+ EFI_STATUS Status;
+ EFI_HANDLE DispatchHandle;
if (!IS_SMRAM_PROFILE_ENABLED) {
return;
@@ -2390,16 +2443,16 @@ DumpSmramRange (
VOID
)
{
- UINTN Index;
- MEMORY_PROFILE_CONTEXT_DATA *ContextData;
- BOOLEAN SmramProfileGettingStatus;
+ UINTN Index;
+ MEMORY_PROFILE_CONTEXT_DATA *ContextData;
+ BOOLEAN SmramProfileGettingStatus;
ContextData = GetSmramProfileContext ();
if (ContextData == NULL) {
- return ;
+ return;
}
- SmramProfileGettingStatus = mSmramProfileGettingStatus;
+ SmramProfileGettingStatus = mSmramProfileGettingStatus;
mSmramProfileGettingStatus = TRUE;
DEBUG ((DEBUG_INFO, "FullSmramRange address - 0x%08x\n", mFullSmramRanges));
@@ -2429,19 +2482,19 @@ DumpFreePagesList (
VOID
)
{
- LIST_ENTRY *FreePageList;
- LIST_ENTRY *Node;
- FREE_PAGE_LIST *Pages;
- UINTN Index;
- MEMORY_PROFILE_CONTEXT_DATA *ContextData;
- BOOLEAN SmramProfileGettingStatus;
+ LIST_ENTRY *FreePageList;
+ LIST_ENTRY *Node;
+ FREE_PAGE_LIST *Pages;
+ UINTN Index;
+ MEMORY_PROFILE_CONTEXT_DATA *ContextData;
+ BOOLEAN SmramProfileGettingStatus;
ContextData = GetSmramProfileContext ();
if (ContextData == NULL) {
- return ;
+ return;
}
- SmramProfileGettingStatus = mSmramProfileGettingStatus;
+ SmramProfileGettingStatus = mSmramProfileGettingStatus;
mSmramProfileGettingStatus = TRUE;
DEBUG ((DEBUG_INFO, "======= SmramProfile begin =======\n"));
@@ -2450,10 +2503,11 @@ DumpFreePagesList (
FreePageList = &mSmmMemoryMap;
for (Node = FreePageList->BackLink, Index = 0;
Node != FreePageList;
- Node = Node->BackLink, Index++) {
+ Node = Node->BackLink, Index++)
+ {
Pages = BASE_CR (Node, FREE_PAGE_LIST, Link);
DEBUG ((DEBUG_INFO, " Index - 0x%x\n", Index));
- DEBUG ((DEBUG_INFO, " PhysicalStart - 0x%016lx\n", (PHYSICAL_ADDRESS) (UINTN) Pages));
+ DEBUG ((DEBUG_INFO, " PhysicalStart - 0x%016lx\n", (PHYSICAL_ADDRESS)(UINTN)Pages));
DEBUG ((DEBUG_INFO, " NumberOfPages - 0x%08x\n", Pages->NumberOfPages));
}
@@ -2471,21 +2525,21 @@ DumpFreePoolList (
VOID
)
{
- LIST_ENTRY *FreePoolList;
- LIST_ENTRY *Node;
- FREE_POOL_HEADER *Pool;
- UINTN Index;
- UINTN PoolListIndex;
- MEMORY_PROFILE_CONTEXT_DATA *ContextData;
- BOOLEAN SmramProfileGettingStatus;
- UINTN SmmPoolTypeIndex;
+ LIST_ENTRY *FreePoolList;
+ LIST_ENTRY *Node;
+ FREE_POOL_HEADER *Pool;
+ UINTN Index;
+ UINTN PoolListIndex;
+ MEMORY_PROFILE_CONTEXT_DATA *ContextData;
+ BOOLEAN SmramProfileGettingStatus;
+ UINTN SmmPoolTypeIndex;
ContextData = GetSmramProfileContext ();
if (ContextData == NULL) {
- return ;
+ return;
}
- SmramProfileGettingStatus = mSmramProfileGettingStatus;
+ SmramProfileGettingStatus = mSmramProfileGettingStatus;
mSmramProfileGettingStatus = TRUE;
DEBUG ((DEBUG_INFO, "======= SmramProfile begin =======\n"));
@@ -2496,10 +2550,11 @@ DumpFreePoolList (
FreePoolList = &mSmmPoolLists[SmmPoolTypeIndex][PoolListIndex];
for (Node = FreePoolList->BackLink, Index = 0;
Node != FreePoolList;
- Node = Node->BackLink, Index++) {
+ Node = Node->BackLink, Index++)
+ {
Pool = BASE_CR (Node, FREE_POOL_HEADER, Link);
DEBUG ((DEBUG_INFO, " Index - 0x%x\n", Index));
- DEBUG ((DEBUG_INFO, " PhysicalStart - 0x%016lx\n", (PHYSICAL_ADDRESS) (UINTN) Pool));
+ DEBUG ((DEBUG_INFO, " PhysicalStart - 0x%016lx\n", (PHYSICAL_ADDRESS)(UINTN)Pool));
DEBUG ((DEBUG_INFO, " Size - 0x%08x\n", Pool->Header.Size));
DEBUG ((DEBUG_INFO, " Available - 0x%02x\n", Pool->Header.Available));
}
@@ -2511,7 +2566,7 @@ DumpFreePoolList (
mSmramProfileGettingStatus = SmramProfileGettingStatus;
}
-GLOBAL_REMOVE_IF_UNREFERENCED CHAR8 *mSmmActionString[] = {
+GLOBAL_REMOVE_IF_UNREFERENCED CHAR8 *mSmmActionString[] = {
"SmmUnknown",
"gSmst->SmmAllocatePages",
"gSmst->SmmFreePages",
@@ -2520,42 +2575,42 @@ GLOBAL_REMOVE_IF_UNREFERENCED CHAR8 *mSmmActionString[] = {
};
typedef struct {
- MEMORY_PROFILE_ACTION Action;
- CHAR8 *String;
+ MEMORY_PROFILE_ACTION Action;
+ CHAR8 *String;
} ACTION_STRING;
-GLOBAL_REMOVE_IF_UNREFERENCED ACTION_STRING mExtActionString[] = {
- {MEMORY_PROFILE_ACTION_LIB_ALLOCATE_PAGES, "Lib:AllocatePages"},
- {MEMORY_PROFILE_ACTION_LIB_ALLOCATE_RUNTIME_PAGES, "Lib:AllocateRuntimePages"},
- {MEMORY_PROFILE_ACTION_LIB_ALLOCATE_RESERVED_PAGES, "Lib:AllocateReservedPages"},
- {MEMORY_PROFILE_ACTION_LIB_FREE_PAGES, "Lib:FreePages"},
- {MEMORY_PROFILE_ACTION_LIB_ALLOCATE_ALIGNED_PAGES, "Lib:AllocateAlignedPages"},
- {MEMORY_PROFILE_ACTION_LIB_ALLOCATE_ALIGNED_RUNTIME_PAGES, "Lib:AllocateAlignedRuntimePages"},
- {MEMORY_PROFILE_ACTION_LIB_ALLOCATE_ALIGNED_RESERVED_PAGES, "Lib:AllocateAlignedReservedPages"},
- {MEMORY_PROFILE_ACTION_LIB_FREE_ALIGNED_PAGES, "Lib:FreeAlignedPages"},
- {MEMORY_PROFILE_ACTION_LIB_ALLOCATE_POOL, "Lib:AllocatePool"},
- {MEMORY_PROFILE_ACTION_LIB_ALLOCATE_RUNTIME_POOL, "Lib:AllocateRuntimePool"},
- {MEMORY_PROFILE_ACTION_LIB_ALLOCATE_RESERVED_POOL, "Lib:AllocateReservedPool"},
- {MEMORY_PROFILE_ACTION_LIB_FREE_POOL, "Lib:FreePool"},
- {MEMORY_PROFILE_ACTION_LIB_ALLOCATE_ZERO_POOL, "Lib:AllocateZeroPool"},
- {MEMORY_PROFILE_ACTION_LIB_ALLOCATE_RUNTIME_ZERO_POOL, "Lib:AllocateRuntimeZeroPool"},
- {MEMORY_PROFILE_ACTION_LIB_ALLOCATE_RESERVED_ZERO_POOL, "Lib:AllocateReservedZeroPool"},
- {MEMORY_PROFILE_ACTION_LIB_ALLOCATE_COPY_POOL, "Lib:AllocateCopyPool"},
- {MEMORY_PROFILE_ACTION_LIB_ALLOCATE_RUNTIME_COPY_POOL, "Lib:AllocateRuntimeCopyPool"},
- {MEMORY_PROFILE_ACTION_LIB_ALLOCATE_RESERVED_COPY_POOL, "Lib:AllocateReservedCopyPool"},
- {MEMORY_PROFILE_ACTION_LIB_REALLOCATE_POOL, "Lib:ReallocatePool"},
- {MEMORY_PROFILE_ACTION_LIB_REALLOCATE_RUNTIME_POOL, "Lib:ReallocateRuntimePool"},
- {MEMORY_PROFILE_ACTION_LIB_REALLOCATE_RESERVED_POOL, "Lib:ReallocateReservedPool"},
+GLOBAL_REMOVE_IF_UNREFERENCED ACTION_STRING mExtActionString[] = {
+ { MEMORY_PROFILE_ACTION_LIB_ALLOCATE_PAGES, "Lib:AllocatePages" },
+ { MEMORY_PROFILE_ACTION_LIB_ALLOCATE_RUNTIME_PAGES, "Lib:AllocateRuntimePages" },
+ { MEMORY_PROFILE_ACTION_LIB_ALLOCATE_RESERVED_PAGES, "Lib:AllocateReservedPages" },
+ { MEMORY_PROFILE_ACTION_LIB_FREE_PAGES, "Lib:FreePages" },
+ { MEMORY_PROFILE_ACTION_LIB_ALLOCATE_ALIGNED_PAGES, "Lib:AllocateAlignedPages" },
+ { MEMORY_PROFILE_ACTION_LIB_ALLOCATE_ALIGNED_RUNTIME_PAGES, "Lib:AllocateAlignedRuntimePages" },
+ { MEMORY_PROFILE_ACTION_LIB_ALLOCATE_ALIGNED_RESERVED_PAGES, "Lib:AllocateAlignedReservedPages" },
+ { MEMORY_PROFILE_ACTION_LIB_FREE_ALIGNED_PAGES, "Lib:FreeAlignedPages" },
+ { MEMORY_PROFILE_ACTION_LIB_ALLOCATE_POOL, "Lib:AllocatePool" },
+ { MEMORY_PROFILE_ACTION_LIB_ALLOCATE_RUNTIME_POOL, "Lib:AllocateRuntimePool" },
+ { MEMORY_PROFILE_ACTION_LIB_ALLOCATE_RESERVED_POOL, "Lib:AllocateReservedPool" },
+ { MEMORY_PROFILE_ACTION_LIB_FREE_POOL, "Lib:FreePool" },
+ { MEMORY_PROFILE_ACTION_LIB_ALLOCATE_ZERO_POOL, "Lib:AllocateZeroPool" },
+ { MEMORY_PROFILE_ACTION_LIB_ALLOCATE_RUNTIME_ZERO_POOL, "Lib:AllocateRuntimeZeroPool" },
+ { MEMORY_PROFILE_ACTION_LIB_ALLOCATE_RESERVED_ZERO_POOL, "Lib:AllocateReservedZeroPool" },
+ { MEMORY_PROFILE_ACTION_LIB_ALLOCATE_COPY_POOL, "Lib:AllocateCopyPool" },
+ { MEMORY_PROFILE_ACTION_LIB_ALLOCATE_RUNTIME_COPY_POOL, "Lib:AllocateRuntimeCopyPool" },
+ { MEMORY_PROFILE_ACTION_LIB_ALLOCATE_RESERVED_COPY_POOL, "Lib:AllocateReservedCopyPool" },
+ { MEMORY_PROFILE_ACTION_LIB_REALLOCATE_POOL, "Lib:ReallocatePool" },
+ { MEMORY_PROFILE_ACTION_LIB_REALLOCATE_RUNTIME_POOL, "Lib:ReallocateRuntimePool" },
+ { MEMORY_PROFILE_ACTION_LIB_REALLOCATE_RESERVED_POOL, "Lib:ReallocateReservedPool" },
};
typedef struct {
- EFI_MEMORY_TYPE MemoryType;
- CHAR8 *MemoryTypeStr;
+ EFI_MEMORY_TYPE MemoryType;
+ CHAR8 *MemoryTypeStr;
} PROFILE_MEMORY_TYPE_STRING;
-GLOBAL_REMOVE_IF_UNREFERENCED PROFILE_MEMORY_TYPE_STRING mMemoryTypeString[] = {
- {EfiRuntimeServicesCode, "EfiRuntimeServicesCode"},
- {EfiRuntimeServicesData, "EfiRuntimeServicesData"}
+GLOBAL_REMOVE_IF_UNREFERENCED PROFILE_MEMORY_TYPE_STRING mMemoryTypeString[] = {
+ { EfiRuntimeServicesCode, "EfiRuntimeServicesCode" },
+ { EfiRuntimeServicesData, "EfiRuntimeServicesData" }
};
/**
@@ -2568,10 +2623,11 @@ GLOBAL_REMOVE_IF_UNREFERENCED PROFILE_MEMORY_TYPE_STRING mMemoryTypeString[] = {
**/
CHAR8 *
ProfileMemoryTypeToStr (
- IN EFI_MEMORY_TYPE MemoryType
+ IN EFI_MEMORY_TYPE MemoryType
)
{
- UINTN Index;
+ UINTN Index;
+
for (Index = 0; Index < ARRAY_SIZE (mMemoryTypeString); Index++) {
if (mMemoryTypeString[Index].MemoryType == MemoryType) {
return mMemoryTypeString[Index].MemoryTypeStr;
@@ -2594,16 +2650,17 @@ ProfileActionToStr (
IN MEMORY_PROFILE_ACTION Action
)
{
- UINTN Index;
- UINTN ActionStringCount;
- CHAR8 **ActionString;
+ UINTN Index;
+ UINTN ActionStringCount;
+ CHAR8 **ActionString;
- ActionString = mSmmActionString;
+ ActionString = mSmmActionString;
ActionStringCount = ARRAY_SIZE (mSmmActionString);
- if ((UINTN) (UINT32) Action < ActionStringCount) {
+ if ((UINTN)(UINT32)Action < ActionStringCount) {
return ActionString[Action];
}
+
for (Index = 0; Index < ARRAY_SIZE (mExtActionString); Index++) {
if (mExtActionString[Index].Action == Action) {
return mExtActionString[Index].String;
@@ -2622,27 +2679,27 @@ DumpSmramProfile (
VOID
)
{
- 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 *SmramDriverInfoList;
- UINTN DriverIndex;
- LIST_ENTRY *DriverLink;
- LIST_ENTRY *AllocInfoList;
- UINTN AllocIndex;
- LIST_ENTRY *AllocLink;
- BOOLEAN SmramProfileGettingStatus;
- UINTN TypeIndex;
+ 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 *SmramDriverInfoList;
+ UINTN DriverIndex;
+ LIST_ENTRY *DriverLink;
+ LIST_ENTRY *AllocInfoList;
+ UINTN AllocIndex;
+ LIST_ENTRY *AllocLink;
+ BOOLEAN SmramProfileGettingStatus;
+ UINTN TypeIndex;
ContextData = GetSmramProfileContext ();
if (ContextData == NULL) {
- return ;
+ return;
}
- SmramProfileGettingStatus = mSmramProfileGettingStatus;
+ SmramProfileGettingStatus = mSmramProfileGettingStatus;
mSmramProfileGettingStatus = TRUE;
Context = &ContextData->Context;
@@ -2653,11 +2710,13 @@ DumpSmramProfile (
DEBUG ((DEBUG_INFO, " PeakTotalUsage - 0x%016lx\n", Context->PeakTotalUsage));
for (TypeIndex = 0; TypeIndex < sizeof (Context->CurrentTotalUsageByType) / sizeof (Context->CurrentTotalUsageByType[0]); TypeIndex++) {
if ((Context->CurrentTotalUsageByType[TypeIndex] != 0) ||
- (Context->PeakTotalUsageByType[TypeIndex] != 0)) {
+ (Context->PeakTotalUsageByType[TypeIndex] != 0))
+ {
DEBUG ((DEBUG_INFO, " CurrentTotalUsage[0x%02x] - 0x%016lx (%a)\n", TypeIndex, Context->CurrentTotalUsageByType[TypeIndex], ProfileMemoryTypeToStr (TypeIndex)));
DEBUG ((DEBUG_INFO, " PeakTotalUsage[0x%02x] - 0x%016lx (%a)\n", TypeIndex, Context->PeakTotalUsageByType[TypeIndex], ProfileMemoryTypeToStr (TypeIndex)));
}
}
+
DEBUG ((DEBUG_INFO, " TotalImageSize - 0x%016lx\n", Context->TotalImageSize));
DEBUG ((DEBUG_INFO, " ImageCount - 0x%08x\n", Context->ImageCount));
DEBUG ((DEBUG_INFO, " SequenceCount - 0x%08x\n", Context->SequenceCount));
@@ -2665,13 +2724,14 @@ DumpSmramProfile (
SmramDriverInfoList = ContextData->DriverInfoList;
for (DriverLink = SmramDriverInfoList->ForwardLink, DriverIndex = 0;
DriverLink != SmramDriverInfoList;
- DriverLink = DriverLink->ForwardLink, DriverIndex++) {
+ DriverLink = DriverLink->ForwardLink, DriverIndex++)
+ {
DriverInfoData = CR (
- DriverLink,
- MEMORY_PROFILE_DRIVER_INFO_DATA,
- Link,
- MEMORY_PROFILE_DRIVER_INFO_SIGNATURE
- );
+ DriverLink,
+ MEMORY_PROFILE_DRIVER_INFO_DATA,
+ Link,
+ MEMORY_PROFILE_DRIVER_INFO_SIGNATURE
+ );
DriverInfo = &DriverInfoData->DriverInfo;
DEBUG ((DEBUG_INFO, " MEMORY_PROFILE_DRIVER_INFO (0x%x)\n", DriverIndex));
DEBUG ((DEBUG_INFO, " FileName - %g\n", &DriverInfo->FileName));
@@ -2684,23 +2744,26 @@ DumpSmramProfile (
DEBUG ((DEBUG_INFO, " PeakUsage - 0x%016lx\n", DriverInfo->PeakUsage));
for (TypeIndex = 0; TypeIndex < sizeof (DriverInfo->CurrentUsageByType) / sizeof (DriverInfo->CurrentUsageByType[0]); TypeIndex++) {
if ((DriverInfo->CurrentUsageByType[TypeIndex] != 0) ||
- (DriverInfo->PeakUsageByType[TypeIndex] != 0)) {
+ (DriverInfo->PeakUsageByType[TypeIndex] != 0))
+ {
DEBUG ((DEBUG_INFO, " CurrentUsage[0x%02x] - 0x%016lx (%a)\n", TypeIndex, DriverInfo->CurrentUsageByType[TypeIndex], ProfileMemoryTypeToStr (TypeIndex)));
DEBUG ((DEBUG_INFO, " PeakUsage[0x%02x] - 0x%016lx (%a)\n", TypeIndex, DriverInfo->PeakUsageByType[TypeIndex], ProfileMemoryTypeToStr (TypeIndex)));
}
}
+
DEBUG ((DEBUG_INFO, " AllocRecordCount - 0x%08x\n", DriverInfo->AllocRecordCount));
AllocInfoList = DriverInfoData->AllocInfoList;
for (AllocLink = AllocInfoList->ForwardLink, AllocIndex = 0;
AllocLink != AllocInfoList;
- AllocLink = AllocLink->ForwardLink, AllocIndex++) {
+ AllocLink = AllocLink->ForwardLink, AllocIndex++)
+ {
AllocInfoData = CR (
- AllocLink,
- MEMORY_PROFILE_ALLOC_INFO_DATA,
- Link,
- MEMORY_PROFILE_ALLOC_INFO_SIGNATURE
- );
+ AllocLink,
+ MEMORY_PROFILE_ALLOC_INFO_DATA,
+ Link,
+ MEMORY_PROFILE_ALLOC_INFO_SIGNATURE
+ );
AllocInfo = &AllocInfoData->AllocInfo;
DEBUG ((DEBUG_INFO, " MEMORY_PROFILE_ALLOC_INFO (0x%x)\n", AllocIndex));
DEBUG ((DEBUG_INFO, " CallerAddress - 0x%016lx (Offset: 0x%08x)\n", AllocInfo->CallerAddress, AllocInfo->CallerAddress - DriverInfo->ImageBase));
@@ -2714,6 +2777,7 @@ DumpSmramProfile (
} else {
DEBUG ((DEBUG_INFO, " Action - 0x%08x (%a)\n", AllocInfo->Action, ProfileActionToStr (AllocInfo->Action)));
}
+
DEBUG ((DEBUG_INFO, " MemoryType - 0x%08x (%a)\n", AllocInfo->MemoryType, ProfileMemoryTypeToStr (AllocInfo->MemoryType)));
DEBUG ((DEBUG_INFO, " Buffer - 0x%016lx\n", AllocInfo->Buffer));
DEBUG ((DEBUG_INFO, " Size - 0x%016lx\n", AllocInfo->Size));
@@ -2734,12 +2798,13 @@ DumpSmramInfo (
VOID
)
{
- DEBUG_CODE_BEGIN ();
- if (IS_SMRAM_PROFILE_ENABLED) {
- DumpSmramProfile ();
- DumpFreePagesList ();
- DumpFreePoolList ();
- DumpSmramRange ();
- }
- DEBUG_CODE_END ();
+ DEBUG_CODE_BEGIN ();
+ if (IS_SMRAM_PROFILE_ENABLED) {
+ DumpSmramProfile ();
+ DumpFreePagesList ();
+ DumpFreePoolList ();
+ DumpSmramRange ();
+ }
+
+ DEBUG_CODE_END ();
}