X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=MdeModulePkg%2FCore%2FPiSmmCore%2FSmramProfileRecord.c;h=e8d60c2d2357e43b3c815d902fd84da64337543c;hp=ac832ce38c740c096459f6914f9a35a760088d24;hb=05cfd73f011f67541cf4add560ab213daa8a99ed;hpb=9cda0af7ecfcfc5446da13e63b1930a0d83c0f3f diff --git a/MdeModulePkg/Core/PiSmmCore/SmramProfileRecord.c b/MdeModulePkg/Core/PiSmmCore/SmramProfileRecord.c index ac832ce38c..e8d60c2d23 100644 --- a/MdeModulePkg/Core/PiSmmCore/SmramProfileRecord.c +++ b/MdeModulePkg/Core/PiSmmCore/SmramProfileRecord.c @@ -1,7 +1,7 @@ /** @file Support routines for SMRAM profile. - Copyright (c) 2014 - 2016, Intel Corporation. All rights reserved.
+ Copyright (c) 2014 - 2018, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -77,11 +77,11 @@ GLOBAL_REMOVE_IF_UNREFERENCED MEMORY_PROFILE_CONTEXT_DATA mSmramProfileContext = }; GLOBAL_REMOVE_IF_UNREFERENCED MEMORY_PROFILE_CONTEXT_DATA *mSmramProfileContextPtr = NULL; -BOOLEAN mSmramReadyToLock; -BOOLEAN mSmramProfileGettingStatus = FALSE; -BOOLEAN mSmramProfileRecordingEnable = MEMORY_PROFILE_RECORDING_DISABLE; -EFI_DEVICE_PATH_PROTOCOL *mSmramProfileDriverPath; -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 infromation. @@ -99,10 +99,10 @@ DumpSmramInfo ( @param[in, out] ProfileSize On entry, points to the size in bytes of the ProfileBuffer. On return, points to the size of the data returned in ProfileBuffer. @param[out] ProfileBuffer Profile buffer. - + @return EFI_SUCCESS Get the memory profile data successfully. @return EFI_UNSUPPORTED Memory profile is unsupported. - @return EFI_BUFFER_TO_SMALL The ProfileSize is too small for the resulting data. + @return EFI_BUFFER_TO_SMALL The ProfileSize is too small for the resulting data. ProfileSize is updated with the size required. **/ @@ -232,7 +232,7 @@ SmramProfileProtocolRecord ( IN CHAR8 *ActionString OPTIONAL ); -EDKII_SMM_MEMORY_PROFILE_PROTOCOL mSmmProfileProtocol = { +GLOBAL_REMOVE_IF_UNREFERENCED EDKII_SMM_MEMORY_PROFILE_PROTOCOL mSmmProfileProtocol = { SmramProfileProtocolGetData, SmramProfileProtocolRegisterImage, SmramProfileProtocolUnregisterImage, @@ -255,35 +255,6 @@ GetSmramProfileContext ( return mSmramProfileContextPtr; } -/** - Retrieves the magic value from the PE/COFF header. - - @param Hdr The buffer in which to return the PE32, PE32+, or TE header. - - @return EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC - Image is PE32 - @return EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC - Image is PE32+ - -**/ -UINT16 -InternalPeCoffGetPeHeaderMagicValue ( - IN EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr - ) -{ - // - // NOTE: Some versions of Linux ELILO for Itanium have an incorrect magic value - // in the PE/COFF Header. If the MachineType is Itanium(IA64) and the - // Magic value in the OptionalHeader is EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC - // then override the returned value to EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC - // - if (Hdr.Pe32->FileHeader.Machine == IMAGE_FILE_MACHINE_IA64 && Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { - return EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC; - } - // - // Return the magic value from the PC/COFF Optional Header - // - return Hdr.Pe32->OptionalHeader.Magic; -} - /** Retrieves and returns the Subsystem of a PE/COFF image that has been loaded into system memory. If Pe32Data is NULL, then ASSERT(). @@ -320,7 +291,7 @@ InternalPeCoffGetSubsystem ( if (Hdr.Te->Signature == EFI_TE_IMAGE_HEADER_SIGNATURE) { return Hdr.Te->Subsystem; } else if (Hdr.Pe32->Signature == EFI_IMAGE_NT_SIGNATURE) { - Magic = InternalPeCoffGetPeHeaderMagicValue (Hdr); + Magic = Hdr.Pe32->OptionalHeader.Magic; if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { return Hdr.Pe32->OptionalHeader.Subsystem; } else if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC) { @@ -443,6 +414,7 @@ BuildDriverInfo ( if (EFI_ERROR (Status)) { return NULL; } + ASSERT (DriverInfoData != NULL); ZeroMem (DriverInfoData, sizeof (*DriverInfoData)); @@ -593,7 +565,7 @@ NeedRecordThisDriver ( // return TRUE; } - + // // Record FilePath without end node. // @@ -1595,6 +1567,7 @@ SmramProfileGetDataSize ( FREE_POOL_HEADER *Pool; UINTN PoolListIndex; UINTN Index; + UINTN SmmPoolTypeIndex; ContextData = GetSmramProfileContext (); if (ContextData == NULL) { @@ -1637,19 +1610,20 @@ SmramProfileGetDataSize ( Node = Node->BackLink) { Index++; } - for (PoolListIndex = 0; PoolListIndex < MAX_POOL_INDEX; PoolListIndex++) { - FreePoolList = &mSmmPoolLists[PoolListIndex]; - for (Node = FreePoolList->BackLink; - Node != FreePoolList; - Node = Node->BackLink) { - Pool = BASE_CR (Node, FREE_POOL_HEADER, Link); - if (Pool->Header.Available) { - 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) { + Pool = BASE_CR (Node, FREE_POOL_HEADER, Link); + if (Pool->Header.Available) { + Index++; + } } } } - TotalSize += (sizeof (MEMORY_PROFILE_FREE_MEMORY) + Index * sizeof (MEMORY_PROFILE_DESCRIPTOR)); TotalSize += (sizeof (MEMORY_PROFILE_MEMORY_RANGE) + mFullSmramRangeCount * sizeof (MEMORY_PROFILE_DESCRIPTOR)); @@ -1697,6 +1671,7 @@ SmramProfileCopyData ( UINT64 RemainingSize; UINTN PdbSize; UINTN ActionStringSize; + UINTN SmmPoolTypeIndex; ContextData = GetSmramProfileContext (); if (ContextData == NULL) { @@ -1784,14 +1759,16 @@ SmramProfileCopyData ( Node = Node->BackLink) { Index++; } - for (PoolListIndex = 0; PoolListIndex < MAX_POOL_INDEX; PoolListIndex++) { - FreePoolList = &mSmmPoolLists[MAX_POOL_INDEX - PoolListIndex - 1]; - for (Node = FreePoolList->BackLink; - Node != FreePoolList; - Node = Node->BackLink) { - Pool = BASE_CR (Node, FREE_POOL_HEADER, Link); - if (Pool->Header.Available) { - 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) { + Pool = BASE_CR (Node, FREE_POOL_HEADER, Link); + if (Pool->Header.Available) { + Index++; + } } } } @@ -1826,29 +1803,31 @@ SmramProfileCopyData ( } Offset += sizeof (MEMORY_PROFILE_DESCRIPTOR); } - for (PoolListIndex = 0; PoolListIndex < MAX_POOL_INDEX; PoolListIndex++) { - FreePoolList = &mSmmPoolLists[MAX_POOL_INDEX - PoolListIndex - 1]; - for (Node = FreePoolList->BackLink; - Node != FreePoolList; - 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->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; - - RemainingSize -= sizeof (MEMORY_PROFILE_DESCRIPTOR); - ProfileBuffer = (UINT8 *) ProfileBuffer + sizeof (MEMORY_PROFILE_DESCRIPTOR); - } else { - goto Done; + 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) { + 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->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; + + RemainingSize -= sizeof (MEMORY_PROFILE_DESCRIPTOR); + ProfileBuffer = (UINT8 *) ProfileBuffer + sizeof (MEMORY_PROFILE_DESCRIPTOR); + } else { + goto Done; + } } + Offset += sizeof (MEMORY_PROFILE_DESCRIPTOR); } - Offset += sizeof (MEMORY_PROFILE_DESCRIPTOR); } } } @@ -1905,10 +1884,10 @@ Done: @param[in, out] ProfileSize On entry, points to the size in bytes of the ProfileBuffer. On return, points to the size of the data returned in ProfileBuffer. @param[out] ProfileBuffer Profile buffer. - + @return EFI_SUCCESS Get the memory profile data successfully. @return EFI_UNSUPPORTED Memory profile is unsupported. - @return EFI_BUFFER_TO_SMALL The ProfileSize is too small for the resulting data. + @return EFI_BUFFER_TO_SMALL The ProfileSize is too small for the resulting data. ProfileSize is updated with the size required. **/ @@ -1978,7 +1957,7 @@ SmramProfileProtocolRegisterImage ( EFI_SMM_DRIVER_ENTRY DriverEntry; VOID *EntryPointInImage; EFI_GUID *Name; - + ZeroMem (&DriverEntry, sizeof (DriverEntry)); Name = GetFileNameFromFilePath (FilePath); if (Name != NULL) { @@ -2576,6 +2555,7 @@ DumpFreePoolList ( UINTN PoolListIndex; MEMORY_PROFILE_CONTEXT_DATA *ContextData; BOOLEAN SmramProfileGettingStatus; + UINTN SmmPoolTypeIndex; ContextData = GetSmramProfileContext (); if (ContextData == NULL) { @@ -2585,23 +2565,25 @@ DumpFreePoolList ( SmramProfileGettingStatus = mSmramProfileGettingStatus; mSmramProfileGettingStatus = TRUE; - DEBUG ((EFI_D_INFO, "======= SmramProfile begin =======\n")); - - for (PoolListIndex = 0; PoolListIndex < MAX_POOL_INDEX; PoolListIndex++) { - DEBUG ((EFI_D_INFO, "FreePoolList (%d):\n", PoolListIndex)); - FreePoolList = &mSmmPoolLists[PoolListIndex]; - for (Node = FreePoolList->BackLink, Index = 0; - Node != FreePoolList; - Node = Node->BackLink, Index++) { - Pool = BASE_CR (Node, FREE_POOL_HEADER, Link); - DEBUG ((EFI_D_INFO, " Index - 0x%x\n", Index)); - DEBUG ((EFI_D_INFO, " PhysicalStart - 0x%016lx\n", (PHYSICAL_ADDRESS) (UINTN) Pool)); - DEBUG ((EFI_D_INFO, " Size - 0x%08x\n", Pool->Header.Size)); - DEBUG ((EFI_D_INFO, " Available - 0x%02x\n", Pool->Header.Available)); + DEBUG ((DEBUG_INFO, "======= SmramProfile begin =======\n")); + + for (SmmPoolTypeIndex = 0; SmmPoolTypeIndex < SmmPoolTypeMax; SmmPoolTypeIndex++) { + for (PoolListIndex = 0; PoolListIndex < MAX_POOL_INDEX; PoolListIndex++) { + DEBUG ((DEBUG_INFO, "FreePoolList(%d)(%d):\n", SmmPoolTypeIndex, PoolListIndex)); + FreePoolList = &mSmmPoolLists[SmmPoolTypeIndex][PoolListIndex]; + for (Node = FreePoolList->BackLink, Index = 0; + Node != FreePoolList; + 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, " Size - 0x%08x\n", Pool->Header.Size)); + DEBUG ((DEBUG_INFO, " Available - 0x%02x\n", Pool->Header.Available)); + } } } - DEBUG ((EFI_D_INFO, "======= SmramProfile end =======\n")); + DEBUG ((DEBUG_INFO, "======= SmramProfile end =======\n")); mSmramProfileGettingStatus = SmramProfileGettingStatus; } @@ -2619,7 +2601,7 @@ typedef struct { CHAR8 *String; } ACTION_STRING; -ACTION_STRING mExtActionString[] = { +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"}, @@ -2643,8 +2625,6 @@ ACTION_STRING mExtActionString[] = { {MEMORY_PROFILE_ACTION_LIB_REALLOCATE_RESERVED_POOL, "Lib:ReallocateReservedPool"}, }; -GLOBAL_REMOVE_IF_UNREFERENCED CHAR8 mUserDefinedActionString[] = {"UserDefined-0x80000000"}; - typedef struct { EFI_MEMORY_TYPE MemoryType; CHAR8 *MemoryTypeStr; @@ -2669,7 +2649,7 @@ ProfileMemoryTypeToStr ( ) { UINTN Index; - for (Index = 0; Index < sizeof (mMemoryTypeString) / sizeof (mMemoryTypeString[0]); Index++) { + for (Index = 0; Index < ARRAY_SIZE (mMemoryTypeString); Index++) { if (mMemoryTypeString[Index].MemoryType == MemoryType) { return mMemoryTypeString[Index].MemoryTypeStr; } @@ -2696,12 +2676,12 @@ ProfileActionToStr ( CHAR8 **ActionString; ActionString = mSmmActionString; - ActionStringCount = sizeof (mSmmActionString) / sizeof (mSmmActionString[0]); + ActionStringCount = ARRAY_SIZE (mSmmActionString); if ((UINTN) (UINT32) Action < ActionStringCount) { return ActionString[Action]; } - for (Index = 0; Index < sizeof (mExtActionString) / sizeof (mExtActionString[0]); Index++) { + for (Index = 0; Index < ARRAY_SIZE (mExtActionString); Index++) { if (mExtActionString[Index].Action == Action) { return mExtActionString[Index].String; }