The functions that are never called have been removed.
They are IsImageInsideSmram,FindImageRecord,SmmRemoveImageRecord,
SmmMemoryAttributesTableConsistencyCheck,DumpSmmMemoryMapEntry,
SmmMemoryMapConsistencyCheckRange,SmmMemoryMapConsistencyCheck,
DumpSmmMemoryMap,ClearGuardMapBit,SetGuardMapBit,AdjustMemoryA,
AdjustMemoryS,IsHeadGuard and IsTailGuard.
FindImageRecord() is called by SmmRemoveImageRecord(); however,
nothing calls SmmRemoveImageRecord().
SmmMemoryMapConsistencyCheckRange() is called by
SmmMemoryMapConsistencyCheck(); however, nothing calls
SmmMemoryMapConsistencyCheck().
https://bugzilla.tianocore.org/show_bug.cgi?id=1062
v2:append the following to the commit message.
- FindImageRecord() is called by SmmRemoveImageRecord(); however,
nothing calls SmmRemoveImageRecord().
- SmmMemoryMapConsistencyCheckRange() is called by
SmmMemoryMapConsistencyCheck(); however, nothing calls
SmmMemoryMapConsistencyCheck().
Cc: Star Zeng <star.zeng@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: shenglei <shenglei.zhang@intel.com>
Reviewed-by: Jian J Wang <jian.j.wang@intel.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Star Zeng <star.zeng@intel.com>
return 0;\r
}\r
\r
-/**\r
- Set the bit in bitmap table for the given address.\r
-\r
- @param[in] Address The address to set for.\r
-\r
- @return VOID.\r
-**/\r
-VOID\r
-EFIAPI\r
-SetGuardMapBit (\r
- IN EFI_PHYSICAL_ADDRESS Address\r
- )\r
-{\r
- UINT64 *GuardMap;\r
- UINT64 BitMask;\r
-\r
- FindGuardedMemoryMap (Address, TRUE, &GuardMap);\r
- if (GuardMap != NULL) {\r
- BitMask = LShiftU64 (1, GUARDED_HEAP_MAP_ENTRY_BIT_INDEX (Address));\r
- *GuardMap |= BitMask;\r
- }\r
-}\r
-\r
-/**\r
- Clear the bit in bitmap table for the given address.\r
-\r
- @param[in] Address The address to clear for.\r
-\r
- @return VOID.\r
-**/\r
-VOID\r
-EFIAPI\r
-ClearGuardMapBit (\r
- IN EFI_PHYSICAL_ADDRESS Address\r
- )\r
-{\r
- UINT64 *GuardMap;\r
- UINT64 BitMask;\r
-\r
- FindGuardedMemoryMap (Address, TRUE, &GuardMap);\r
- if (GuardMap != NULL) {\r
- BitMask = LShiftU64 (1, GUARDED_HEAP_MAP_ENTRY_BIT_INDEX (Address));\r
- *GuardMap &= ~BitMask;\r
- }\r
-}\r
\r
/**\r
Check to see if the page at the given address is a Guard page or not.\r
return ((BitMap == BIT0) || (BitMap == BIT2) || (BitMap == (BIT2 | BIT0)));\r
}\r
\r
-/**\r
- Check to see if the page at the given address is a head Guard page or not.\r
\r
- @param[in] Address The address to check for.\r
-\r
- @return TRUE The page at Address is a head Guard page.\r
- @return FALSE The page at Address is not a head Guard page.\r
-**/\r
-BOOLEAN\r
-EFIAPI\r
-IsHeadGuard (\r
- IN EFI_PHYSICAL_ADDRESS Address\r
- )\r
-{\r
- return (GetGuardedMemoryBits (Address, 2) == BIT1);\r
-}\r
-\r
-/**\r
- Check to see if the page at the given address is a tail Guard page or not.\r
-\r
- @param[in] Address The address to check for.\r
-\r
- @return TRUE The page at Address is a tail Guard page.\r
- @return FALSE The page at Address is not a tail Guard page.\r
-**/\r
-BOOLEAN\r
-EFIAPI\r
-IsTailGuard (\r
- IN EFI_PHYSICAL_ADDRESS Address\r
- )\r
-{\r
- return (GetGuardedMemoryBits (Address - EFI_PAGE_SIZE, 2) == BIT0);\r
-}\r
\r
/**\r
Check to see if the page at the given address is guarded or not.\r
ClearGuardedMemoryBits(Memory, NumberOfPages);\r
}\r
\r
-/**\r
- Adjust address of free memory according to existing and/or required Guard.\r
-\r
- This function will check if there're existing Guard pages of adjacent\r
- memory blocks, and try to use it as the Guard page of the memory to be\r
- allocated.\r
\r
- @param[in] Start Start address of free memory block.\r
- @param[in] Size Size of free memory block.\r
- @param[in] SizeRequested Size of memory to allocate.\r
-\r
- @return The end address of memory block found.\r
- @return 0 if no enough space for the required size of memory and its Guard.\r
-**/\r
-UINT64\r
-AdjustMemoryS (\r
- IN UINT64 Start,\r
- IN UINT64 Size,\r
- IN UINT64 SizeRequested\r
- )\r
-{\r
- UINT64 Target;\r
-\r
- //\r
- // UEFI spec requires that allocated pool must be 8-byte aligned. If it's\r
- // indicated to put the pool near the Tail Guard, we need extra bytes to\r
- // make sure alignment of the returned pool address.\r
- //\r
- if ((PcdGet8 (PcdHeapGuardPropertyMask) & BIT7) == 0) {\r
- SizeRequested = ALIGN_VALUE(SizeRequested, 8);\r
- }\r
-\r
- Target = Start + Size - SizeRequested;\r
- ASSERT (Target >= Start);\r
- if (Target == 0) {\r
- return 0;\r
- }\r
-\r
- if (!IsGuardPage (Start + Size)) {\r
- // No Guard at tail to share. One more page is needed.\r
- Target -= EFI_PAGES_TO_SIZE (1);\r
- }\r
-\r
- // Out of range?\r
- if (Target < Start) {\r
- return 0;\r
- }\r
-\r
- // At the edge?\r
- if (Target == Start) {\r
- if (!IsGuardPage (Target - EFI_PAGES_TO_SIZE (1))) {\r
- // No enough space for a new head Guard if no Guard at head to share.\r
- return 0;\r
- }\r
- }\r
-\r
- // OK, we have enough pages for memory and its Guards. Return the End of the\r
- // free space.\r
- return Target + SizeRequested - 1;\r
-}\r
\r
/**\r
Adjust the start address and number of pages to free according to Guard.\r
*NumberOfPages = PagesToFree;\r
}\r
\r
-/**\r
- Adjust the base and number of pages to really allocate according to Guard.\r
-\r
- @param[in,out] Memory Base address of free memory.\r
- @param[in,out] NumberOfPages Size of memory to allocate.\r
-\r
- @return VOID.\r
-**/\r
-VOID\r
-AdjustMemoryA (\r
- IN OUT EFI_PHYSICAL_ADDRESS *Memory,\r
- IN OUT UINTN *NumberOfPages\r
- )\r
-{\r
- //\r
- // FindFreePages() has already taken the Guard into account. It's safe to\r
- // adjust the start address and/or number of pages here, to make sure that\r
- // the Guards are also "allocated".\r
- //\r
- if (!IsGuardPage (*Memory + EFI_PAGES_TO_SIZE (*NumberOfPages))) {\r
- // No tail Guard, add one.\r
- *NumberOfPages += 1;\r
- }\r
-\r
- if (!IsGuardPage (*Memory - EFI_PAGE_SIZE)) {\r
- // No head Guard, add one.\r
- *Memory -= EFI_PAGE_SIZE;\r
- *NumberOfPages += 1;\r
- }\r
-}\r
\r
/**\r
Adjust the pool head position to make sure the Guard page is adjavent to\r
return RShiftU64 (Size, EFI_PAGE_SHIFT) + ((((UINTN)Size) & EFI_PAGE_MASK) ? 1 : 0);\r
}\r
\r
-/**\r
- Check the consistency of Smm memory attributes table.\r
-\r
- @param[in] MemoryAttributesTable PI SMM memory attributes table\r
-**/\r
-VOID\r
-SmmMemoryAttributesTableConsistencyCheck (\r
- IN EDKII_PI_SMM_MEMORY_ATTRIBUTES_TABLE *MemoryAttributesTable\r
- )\r
-{\r
- EFI_MEMORY_DESCRIPTOR *MemoryMap;\r
- UINTN MemoryMapEntryCount;\r
- UINTN DescriptorSize;\r
- UINTN Index;\r
- UINT64 Address;\r
-\r
- Address = 0;\r
- MemoryMapEntryCount = MemoryAttributesTable->NumberOfEntries;\r
- DescriptorSize = MemoryAttributesTable->DescriptorSize;\r
- MemoryMap = (EFI_MEMORY_DESCRIPTOR *)(MemoryAttributesTable + 1);\r
- for (Index = 0; Index < MemoryMapEntryCount; Index++) {\r
- if (Address != 0) {\r
- ASSERT (Address == MemoryMap->PhysicalStart);\r
- }\r
- Address = MemoryMap->PhysicalStart + EfiPagesToSize(MemoryMap->NumberOfPages);\r
- MemoryMap = NEXT_MEMORY_DESCRIPTOR(MemoryMap, DescriptorSize);\r
- }\r
-}\r
\r
/**\r
Sort memory map entries based upon PhysicalStart, from low to high.\r
return ;\r
}\r
\r
-/**\r
- Find image record according to image base and size.\r
-\r
- @param[in] ImageBase Base of PE image\r
- @param[in] ImageSize Size of PE image\r
-\r
- @return image record\r
-**/\r
-STATIC\r
-IMAGE_PROPERTIES_RECORD *\r
-FindImageRecord (\r
- IN EFI_PHYSICAL_ADDRESS ImageBase,\r
- IN UINT64 ImageSize\r
- )\r
-{\r
- IMAGE_PROPERTIES_RECORD *ImageRecord;\r
- LIST_ENTRY *ImageRecordLink;\r
- LIST_ENTRY *ImageRecordList;\r
-\r
- ImageRecordList = &mImagePropertiesPrivateData.ImageRecordList;\r
-\r
- for (ImageRecordLink = ImageRecordList->ForwardLink;\r
- ImageRecordLink != ImageRecordList;\r
- ImageRecordLink = ImageRecordLink->ForwardLink) {\r
- ImageRecord = CR (\r
- ImageRecordLink,\r
- IMAGE_PROPERTIES_RECORD,\r
- Link,\r
- IMAGE_PROPERTIES_RECORD_SIGNATURE\r
- );\r
-\r
- if ((ImageBase == ImageRecord->ImageBase) &&\r
- (ImageSize == ImageRecord->ImageSize)) {\r
- return ImageRecord;\r
- }\r
- }\r
-\r
- return NULL;\r
-}\r
-\r
-/**\r
- Remove Image record.\r
-\r
- @param[in] DriverEntry Driver information\r
-**/\r
-VOID\r
-SmmRemoveImageRecord (\r
- IN EFI_SMM_DRIVER_ENTRY *DriverEntry\r
- )\r
-{\r
- IMAGE_PROPERTIES_RECORD *ImageRecord;\r
- LIST_ENTRY *CodeSegmentListHead;\r
- IMAGE_PROPERTIES_RECORD_CODE_SECTION *ImageRecordCodeSection;\r
-\r
- DEBUG ((DEBUG_VERBOSE, "SMM RemoveImageRecord - 0x%x\n", DriverEntry));\r
- DEBUG ((DEBUG_VERBOSE, "SMM RemoveImageRecord - 0x%016lx - 0x%016lx\n", DriverEntry->ImageBuffer, DriverEntry->NumberOfPage));\r
-\r
- ImageRecord = FindImageRecord (DriverEntry->ImageBuffer, EfiPagesToSize(DriverEntry->NumberOfPage));\r
- if (ImageRecord == NULL) {\r
- DEBUG ((DEBUG_ERROR, "SMM !!!!!!!! ImageRecord not found !!!!!!!!\n"));\r
- return ;\r
- }\r
-\r
- CodeSegmentListHead = &ImageRecord->CodeSegmentList;\r
- while (!IsListEmpty (CodeSegmentListHead)) {\r
- ImageRecordCodeSection = CR (\r
- CodeSegmentListHead->ForwardLink,\r
- IMAGE_PROPERTIES_RECORD_CODE_SECTION,\r
- Link,\r
- IMAGE_PROPERTIES_RECORD_CODE_SECTION_SIGNATURE\r
- );\r
- RemoveEntryList (&ImageRecordCodeSection->Link);\r
- FreePool (ImageRecordCodeSection);\r
- }\r
-\r
- RemoveEntryList (&ImageRecord->Link);\r
- FreePool (ImageRecord);\r
- mImagePropertiesPrivateData.ImageRecordCount--;\r
-}\r
\r
/**\r
Publish MemoryAttributesTable to SMM configuration table.\r
ASSERT_EFI_ERROR (Status);\r
}\r
\r
-/**\r
- This function returns if image is inside SMRAM.\r
-\r
- @param[in] LoadedImage LoadedImage protocol instance for an image.\r
-\r
- @retval TRUE the image is inside SMRAM.\r
- @retval FALSE the image is outside SMRAM.\r
-**/\r
-BOOLEAN\r
-IsImageInsideSmram (\r
- IN EFI_LOADED_IMAGE_PROTOCOL *LoadedImage\r
- )\r
-{\r
- UINTN Index;\r
-\r
- for (Index = 0; Index < mFullSmramRangeCount; Index++) {\r
- if ((mFullSmramRanges[Index].PhysicalStart <= (UINTN)LoadedImage->ImageBase)&&\r
- (mFullSmramRanges[Index].PhysicalStart + mFullSmramRanges[Index].PhysicalSize >= (UINTN)LoadedImage->ImageBase + LoadedImage->ImageSize)) {\r
- return TRUE;\r
- }\r
- }\r
-\r
- return FALSE;\r
-}\r
\r
/**\r
This function installs all SMM image record information.\r
return Count;\r
}\r
\r
-/**\r
- Dump Smm memory map entry.\r
-**/\r
-VOID\r
-DumpSmmMemoryMapEntry (\r
- VOID\r
- )\r
-{\r
- LIST_ENTRY *Link;\r
- MEMORY_MAP *Entry;\r
- EFI_PHYSICAL_ADDRESS Last;\r
-\r
- Last = 0;\r
- DEBUG ((DEBUG_INFO, "DumpSmmMemoryMapEntry:\n"));\r
- Link = gMemoryMap.ForwardLink;\r
- while (Link != &gMemoryMap) {\r
- Entry = CR (Link, MEMORY_MAP, Link, MEMORY_MAP_SIGNATURE);\r
- Link = Link->ForwardLink;\r
-\r
- if ((Last != 0) && (Last != (UINT64)-1)) {\r
- if (Last + 1 != Entry->Start) {\r
- Last = (UINT64)-1;\r
- } else {\r
- Last = Entry->End;\r
- }\r
- } else if (Last == 0) {\r
- Last = Entry->End;\r
- }\r
-\r
- DEBUG ((DEBUG_INFO, "Entry (Link - 0x%x)\n", &Entry->Link));\r
- DEBUG ((DEBUG_INFO, " Signature - 0x%x\n", Entry->Signature));\r
- DEBUG ((DEBUG_INFO, " Link.ForwardLink - 0x%x\n", Entry->Link.ForwardLink));\r
- DEBUG ((DEBUG_INFO, " Link.BackLink - 0x%x\n", Entry->Link.BackLink));\r
- DEBUG ((DEBUG_INFO, " Type - 0x%x\n", Entry->Type));\r
- DEBUG ((DEBUG_INFO, " Start - 0x%016lx\n", Entry->Start));\r
- DEBUG ((DEBUG_INFO, " End - 0x%016lx\n", Entry->End));\r
- }\r
-\r
- ASSERT (Last != (UINT64)-1);\r
-}\r
-\r
-/**\r
- Dump Smm memory map.\r
-**/\r
-VOID\r
-DumpSmmMemoryMap (\r
- VOID\r
- )\r
-{\r
- LIST_ENTRY *Node;\r
- FREE_PAGE_LIST *Pages;\r
-\r
- DEBUG ((DEBUG_INFO, "DumpSmmMemoryMap\n"));\r
-\r
- Pages = NULL;\r
- Node = mSmmMemoryMap.ForwardLink;\r
- while (Node != &mSmmMemoryMap) {\r
- Pages = BASE_CR (Node, FREE_PAGE_LIST, Link);\r
- DEBUG ((DEBUG_INFO, "Pages - 0x%x\n", Pages));\r
- DEBUG ((DEBUG_INFO, "Pages->NumberOfPages - 0x%x\n", Pages->NumberOfPages));\r
- Node = Node->ForwardLink;\r
- }\r
-}\r
\r
-/**\r
- Check if a Smm base~length is in Smm memory map.\r
-\r
- @param[in] Base The base address of Smm memory to be checked.\r
- @param[in] Length THe length of Smm memory to be checked.\r
-\r
- @retval TRUE Smm base~length is in smm memory map.\r
- @retval FALSE Smm base~length is in smm memory map.\r
-**/\r
-BOOLEAN\r
-SmmMemoryMapConsistencyCheckRange (\r
- IN EFI_PHYSICAL_ADDRESS Base,\r
- IN UINTN Length\r
- )\r
-{\r
- LIST_ENTRY *Link;\r
- MEMORY_MAP *Entry;\r
- BOOLEAN Result;\r
-\r
- Result = FALSE;\r
- Link = gMemoryMap.ForwardLink;\r
- while (Link != &gMemoryMap) {\r
- Entry = CR (Link, MEMORY_MAP, Link, MEMORY_MAP_SIGNATURE);\r
- Link = Link->ForwardLink;\r
-\r
- if (Entry->Type != EfiConventionalMemory) {\r
- continue;\r
- }\r
- if (Entry->Start == Base && Entry->End == Base + Length - 1) {\r
- Result = TRUE;\r
- break;\r
- }\r
- }\r
-\r
- return Result;\r
-}\r
-\r
-/**\r
- Check the consistency of Smm memory map.\r
-**/\r
-VOID\r
-SmmMemoryMapConsistencyCheck (\r
- VOID\r
- )\r
-{\r
- LIST_ENTRY *Node;\r
- FREE_PAGE_LIST *Pages;\r
- BOOLEAN Result;\r
-\r
- Pages = NULL;\r
- Node = mSmmMemoryMap.ForwardLink;\r
- while (Node != &mSmmMemoryMap) {\r
- Pages = BASE_CR (Node, FREE_PAGE_LIST, Link);\r
- Result = SmmMemoryMapConsistencyCheckRange ((EFI_PHYSICAL_ADDRESS)(UINTN)Pages, (UINTN)EFI_PAGES_TO_SIZE(Pages->NumberOfPages));\r
- ASSERT (Result);\r
- Node = Node->ForwardLink;\r
- }\r
-}\r
\r
/**\r
Internal Function. Allocate n pages from given free page node.\r