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 + EFI_PAGES_TO_SIZE(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
\r
- @param[in] MemoryMap A pointer to the buffer in which firmware places\r
- the current memory map.\r
- @param[in] MemoryMapSize Size, in bytes, of the MemoryMap buffer.\r
- @param[in] DescriptorSize Size, in bytes, of an individual EFI_MEMORY_DESCRIPTOR.\r
+ @param[in,out] MemoryMap A pointer to the buffer in which firmware places\r
+ the current memory map.\r
+ @param[in] MemoryMapSize Size, in bytes, of the MemoryMap buffer.\r
+ @param[in] DescriptorSize Size, in bytes, of an individual EFI_MEMORY_DESCRIPTOR.\r
**/\r
STATIC\r
VOID\r
//\r
\r
/**\r
- Set MemoryProtectionAttribute accroding to PE/COFF image section alignment.\r
+ Set MemoryProtectionAttribute according to PE/COFF image section alignment.\r
\r
@param[in] SectionAlignment PE/COFF section alignment\r
**/\r
IN UINT32 SectionAlignment\r
)\r
{\r
- if (((SectionAlignment & (EFI_ACPI_RUNTIME_PAGE_ALLOCATION_ALIGNMENT - 1)) != 0) &&\r
+ if (((SectionAlignment & (RUNTIME_PAGE_ALLOCATION_GRANULARITY - 1)) != 0) &&\r
((mMemoryProtectionAttribute & EFI_MEMORY_ATTRIBUTES_RUNTIME_MEMORY_PROTECTION_NON_EXECUTABLE_PE_DATA) != 0)) {\r
DEBUG ((DEBUG_VERBOSE, "SMM SetMemoryAttributesTableSectionAlignment - Clear\n"));\r
mMemoryProtectionAttribute &= ~((UINT64)EFI_MEMORY_ATTRIBUTES_RUNTIME_MEMORY_PROTECTION_NON_EXECUTABLE_PE_DATA);\r
IMAGE_PROPERTIES_RECORD *ImageRecord;\r
CHAR8 *PdbPointer;\r
IMAGE_PROPERTIES_RECORD_CODE_SECTION *ImageRecordCodeSection;\r
- UINT16 Magic;\r
\r
DEBUG ((DEBUG_VERBOSE, "SMM InsertImageRecord - 0x%x\n", DriverEntry));\r
DEBUG ((DEBUG_VERBOSE, "SMM InsertImageRecord - 0x%016lx - 0x%08x\n", DriverEntry->ImageBuffer, DriverEntry->NumberOfPage));\r
// Step 1: record whole region\r
//\r
ImageRecord->ImageBase = DriverEntry->ImageBuffer;\r
- ImageRecord->ImageSize = EFI_PAGES_TO_SIZE(DriverEntry->NumberOfPage);\r
+ ImageRecord->ImageSize = EfiPagesToSize(DriverEntry->NumberOfPage);\r
\r
ImageAddress = (VOID *)(UINTN)DriverEntry->ImageBuffer;\r
\r
//\r
// Get SectionAlignment\r
//\r
- if (Hdr.Pe32->FileHeader.Machine == IMAGE_FILE_MACHINE_IA64 && Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {\r
- //\r
- // NOTE: Some versions of Linux ELILO for Itanium have an incorrect magic value\r
- // in the PE/COFF Header. If the MachineType is Itanium(IA64) and the\r
- // Magic value in the OptionalHeader is EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC\r
- // then override the magic value to EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC\r
- //\r
- Magic = EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC;\r
- } else {\r
- //\r
- // Get the magic value from the PE/COFF Optional Header\r
- //\r
- Magic = Hdr.Pe32->OptionalHeader.Magic;\r
- }\r
- if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {\r
+ if (Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {\r
SectionAlignment = Hdr.Pe32->OptionalHeader.SectionAlignment;\r
} else {\r
SectionAlignment = Hdr.Pe32Plus->OptionalHeader.SectionAlignment;\r
}\r
\r
SetMemoryAttributesTableSectionAlignment (SectionAlignment);\r
- if ((SectionAlignment & (EFI_ACPI_RUNTIME_PAGE_ALLOCATION_ALIGNMENT - 1)) != 0) {\r
- DEBUG ((DEBUG_ERROR, "SMM !!!!!!!! InsertImageRecord - Section Alignment(0x%x) is not %dK !!!!!!!!\n",\r
- SectionAlignment, EFI_ACPI_RUNTIME_PAGE_ALLOCATION_ALIGNMENT >> 10));\r
+ if ((SectionAlignment & (RUNTIME_PAGE_ALLOCATION_GRANULARITY - 1)) != 0) {\r
+ DEBUG ((DEBUG_WARN, "SMM !!!!!!!! InsertImageRecord - Section Alignment(0x%x) is not %dK !!!!!!!!\n",\r
+ SectionAlignment, RUNTIME_PAGE_ALLOCATION_GRANULARITY >> 10));\r
PdbPointer = PeCoffLoaderGetPdbPointer ((VOID*) (UINTN) ImageAddress);\r
if (PdbPointer != NULL) {\r
- DEBUG ((DEBUG_ERROR, "SMM !!!!!!!! Image - %a !!!!!!!!\n", PdbPointer));\r
+ DEBUG ((DEBUG_WARN, "SMM !!!!!!!! Image - %a !!!!!!!!\n", PdbPointer));\r
}\r
goto Finish;\r
}\r
InsertTailList (&mImagePropertiesPrivateData.ImageRecordList, &ImageRecord->Link);\r
mImagePropertiesPrivateData.ImageRecordCount++;\r
\r
- SortImageRecord ();\r
-\r
if (mImagePropertiesPrivateData.CodeSegmentCountMax < ImageRecord->CodeSegmentCount) {\r
mImagePropertiesPrivateData.CodeSegmentCountMax = ImageRecord->CodeSegmentCount;\r
}\r
\r
+ SortImageRecord ();\r
+\r
Finish:\r
return ;\r
}\r
\r
-/**\r
- Find image record accroding 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, EFI_PAGES_TO_SIZE(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