@return The number of bytes associated with the number of EFI_PAGEs specified\r
by Pages.\r
**/\r
+STATIC\r
UINT64\r
EfiPagesToSize (\r
IN UINT64 Pages\r
by Size.\r
\r
**/\r
+STATIC\r
UINT64\r
EfiSizeToPages (\r
IN UINT64 Size\r
/**\r
Acquire memory lock on mPropertiesTableLock.\r
**/\r
+STATIC\r
VOID\r
CoreAcquirePropertiesTableLock (\r
VOID\r
/**\r
Release memory lock on mPropertiesTableLock.\r
**/\r
+STATIC\r
VOID\r
CoreReleasePropertiesTableLock (\r
VOID\r
CoreReleaseLock (&mPropertiesTableLock);\r
}\r
\r
-/**\r
- Dump memory map.\r
-\r
- @param MemoryMap A pointer to the buffer in which firmware places\r
- the current memory map.\r
- @param MemoryMapSize Size, in bytes, of the MemoryMap buffer.\r
- @param DescriptorSize Size, in bytes, of an individual EFI_MEMORY_DESCRIPTOR.\r
-**/\r
-VOID\r
-DumpMemoryMap (\r
- IN EFI_MEMORY_DESCRIPTOR *MemoryMap,\r
- IN UINTN MemoryMapSize,\r
- IN UINTN DescriptorSize\r
- )\r
-{\r
- EFI_MEMORY_DESCRIPTOR *MemoryMapEntry;\r
- EFI_MEMORY_DESCRIPTOR *MemoryMapEnd;\r
- UINT64 MemoryBlockLength;\r
-\r
- DEBUG ((EFI_D_VERBOSE, " MemoryMap:\n"));\r
- MemoryMapEntry = MemoryMap;\r
- MemoryMapEnd = (EFI_MEMORY_DESCRIPTOR *) ((UINT8 *) MemoryMap + MemoryMapSize);\r
- while (MemoryMapEntry < MemoryMapEnd) {\r
- MemoryBlockLength = (UINT64) (EfiPagesToSize (MemoryMapEntry->NumberOfPages));\r
- DEBUG ((EFI_D_VERBOSE, " Entry(0x%02x) 0x%016lx - 0x%016lx (0x%016lx)\n", MemoryMapEntry->Type, MemoryMapEntry->PhysicalStart, MemoryMapEntry->PhysicalStart + MemoryBlockLength, MemoryMapEntry->Attribute));\r
- MemoryMapEntry = NEXT_MEMORY_DESCRIPTOR (MemoryMapEntry, DescriptorSize);\r
- }\r
-}\r
-\r
/**\r
Sort memory map entries based upon PhysicalStart, from low to high.\r
\r
@param MemoryMapSize Size, in bytes, of the MemoryMap buffer.\r
@param DescriptorSize Size, in bytes, of an individual EFI_MEMORY_DESCRIPTOR.\r
**/\r
+STATIC\r
VOID\r
SortMemoryMap (\r
IN OUT EFI_MEMORY_DESCRIPTOR *MemoryMap,\r
it is the size of new memory map after merge.\r
@param DescriptorSize Size, in bytes, of an individual EFI_MEMORY_DESCRIPTOR.\r
**/\r
+STATIC\r
VOID\r
MergeMemoryMap (\r
IN OUT EFI_MEMORY_DESCRIPTOR *MemoryMap,\r
@param MemoryMapSize Size, in bytes, of the MemoryMap buffer.\r
@param DescriptorSize Size, in bytes, of an individual EFI_MEMORY_DESCRIPTOR.\r
**/\r
+STATIC\r
VOID\r
EnforceMemoryMapAttribute (\r
IN OUT EFI_MEMORY_DESCRIPTOR *MemoryMap,\r
return ;\r
}\r
\r
-/**\r
- Sort memory map entries whose type is EfiRuntimeServicesCode/EfiRuntimeServicesData,\r
- from high to low.\r
- This function assumes memory map is already from low to high, so it just reverts them.\r
-\r
- @param MemoryMap A pointer to the buffer in which firmware places\r
- the current memory map.\r
- @param MemoryMapSize Size, in bytes, of the MemoryMap buffer.\r
- @param DescriptorSize Size, in bytes, of an individual EFI_MEMORY_DESCRIPTOR.\r
-**/\r
-VOID\r
-RevertRuntimeMemoryMap (\r
- IN OUT EFI_MEMORY_DESCRIPTOR *MemoryMap,\r
- IN UINTN MemoryMapSize,\r
- IN UINTN DescriptorSize\r
- )\r
-{\r
- EFI_MEMORY_DESCRIPTOR *MemoryMapEntry;\r
- EFI_MEMORY_DESCRIPTOR *MemoryMapEnd;\r
- EFI_MEMORY_DESCRIPTOR TempMemoryMap;\r
-\r
- EFI_MEMORY_DESCRIPTOR *RuntimeMapEntryBegin;\r
- EFI_MEMORY_DESCRIPTOR *RuntimeMapEntryEnd;\r
-\r
- MemoryMapEntry = MemoryMap;\r
- RuntimeMapEntryBegin = NULL;\r
- RuntimeMapEntryEnd = NULL;\r
- MemoryMapEnd = (EFI_MEMORY_DESCRIPTOR *) ((UINT8 *) MemoryMap + MemoryMapSize);\r
- while ((UINTN)MemoryMapEntry < (UINTN)MemoryMapEnd) {\r
- if ((MemoryMapEntry->Type == EfiRuntimeServicesCode) ||\r
- (MemoryMapEntry->Type == EfiRuntimeServicesData)) {\r
- if (RuntimeMapEntryBegin == NULL) {\r
- RuntimeMapEntryBegin = MemoryMapEntry;\r
- }\r
- RuntimeMapEntryEnd = MemoryMapEntry;\r
- }\r
- MemoryMapEntry = NEXT_MEMORY_DESCRIPTOR (MemoryMapEntry, DescriptorSize);\r
- }\r
-\r
- MemoryMapEntry = RuntimeMapEntryBegin;\r
- MemoryMapEnd = RuntimeMapEntryEnd;\r
- while (MemoryMapEntry < MemoryMapEnd) {\r
- CopyMem (&TempMemoryMap, MemoryMapEntry, sizeof(EFI_MEMORY_DESCRIPTOR));\r
- CopyMem (MemoryMapEntry, MemoryMapEnd, sizeof(EFI_MEMORY_DESCRIPTOR));\r
- CopyMem (MemoryMapEnd, &TempMemoryMap, sizeof(EFI_MEMORY_DESCRIPTOR));\r
-\r
- MemoryMapEntry = NEXT_MEMORY_DESCRIPTOR (MemoryMapEntry, DescriptorSize);\r
- MemoryMapEnd = PREVIOUS_MEMORY_DESCRIPTOR (MemoryMapEnd, DescriptorSize);\r
- }\r
-\r
- return ;\r
-}\r
-\r
/**\r
Return the first image record, whose [ImageBase, ImageSize] covered by [Buffer, Length].\r
\r
\r
@return first image record covered by [buffer, length]\r
**/\r
+STATIC\r
IMAGE_PROPERTIES_RECORD *\r
GetImageRecordByAddress (\r
IN EFI_PHYSICAL_ADDRESS Buffer,\r
@param OldRecord A pointer to one old memory map entry.\r
@param DescriptorSize Size, in bytes, of an individual EFI_MEMORY_DESCRIPTOR.\r
**/\r
+STATIC\r
UINTN\r
SetNewRecord (\r
IN IMAGE_PROPERTIES_RECORD *ImageRecord,\r
@retval 0 no entry need to be splitted.\r
@return the max number of new splitted entries\r
**/\r
+STATIC\r
UINTN\r
GetMaxSplitRecordCount (\r
IN EFI_MEMORY_DESCRIPTOR *OldRecord\r
The caller gurantee the buffer size be 1 +\r
(SplitRecordCount * DescriptorSize) calculated\r
below.\r
+ @param MaxSplitRecordCount The max number of splitted entries\r
@param DescriptorSize Size, in bytes, of an individual EFI_MEMORY_DESCRIPTOR.\r
\r
@retval 0 no entry is splitted.\r
@return the real number of splitted record.\r
**/\r
+STATIC\r
UINTN\r
SplitRecord (\r
IN EFI_MEMORY_DESCRIPTOR *OldRecord,\r
the current memory map.\r
@param DescriptorSize Size, in bytes, of an individual EFI_MEMORY_DESCRIPTOR.\r
**/\r
+STATIC\r
VOID\r
SplitTable (\r
IN OUT UINTN *MemoryMapSize,\r
@retval EFI_INVALID_PARAMETER One of the parameters has an invalid value.\r
\r
**/\r
+STATIC\r
EFI_STATUS\r
EFIAPI\r
CoreGetMemoryMapPropertiesTable (\r
\r
@param SectionAlignment PE/COFF section alignment\r
**/\r
+STATIC\r
VOID\r
SetPropertiesTableSectionAlignment (\r
IN UINT32 SectionAlignment\r
)\r
{\r
- if (((SectionAlignment & (SIZE_4KB - 1)) != 0) &&\r
+ if (((SectionAlignment & (EFI_ACPI_RUNTIME_PAGE_ALLOCATION_ALIGNMENT - 1)) != 0) &&\r
((mPropertiesTable.MemoryProtectionAttribute & EFI_PROPERTIES_RUNTIME_MEMORY_PROTECTION_NON_EXECUTABLE_PE_DATA) != 0)) {\r
DEBUG ((EFI_D_VERBOSE, "SetPropertiesTableSectionAlignment - Clear\n"));\r
- mPropertiesTable.MemoryProtectionAttribute &= ~EFI_PROPERTIES_RUNTIME_MEMORY_PROTECTION_NON_EXECUTABLE_PE_DATA;\r
+ mPropertiesTable.MemoryProtectionAttribute &= ~((UINT64)EFI_PROPERTIES_RUNTIME_MEMORY_PROTECTION_NON_EXECUTABLE_PE_DATA);\r
gBS->GetMemoryMap = CoreGetMemoryMap;\r
gBS->Hdr.CRC32 = 0;\r
gBS->CalculateCrc32 ((UINT8 *)gBS, gBS->Hdr.HeaderSize, &gBS->Hdr.CRC32);\r
@param FirstImageRecordCodeSection first code section in image record\r
@param SecondImageRecordCodeSection second code section in image record\r
**/\r
+STATIC\r
VOID\r
SwapImageRecordCodeSection (\r
IN IMAGE_PROPERTIES_RECORD_CODE_SECTION *FirstImageRecordCodeSection,\r
\r
@param ImageRecord image record to be sorted\r
**/\r
+STATIC\r
VOID\r
SortImageRecordCodeSection (\r
IN IMAGE_PROPERTIES_RECORD *ImageRecord\r
}\r
\r
/**\r
- Check if code section in image record is valid\r
+ Check if code section in image record is valid.\r
\r
@param ImageRecord image record to be checked\r
\r
@retval TRUE image record is valid\r
@retval FALSE image record is invalid\r
**/\r
+STATIC\r
BOOLEAN\r
IsImageRecordCodeSectionValid (\r
IN IMAGE_PROPERTIES_RECORD *ImageRecord\r
@param FirstImageRecord first image record.\r
@param SecondImageRecord second image record.\r
**/\r
+STATIC\r
VOID\r
SwapImageRecord (\r
IN IMAGE_PROPERTIES_RECORD *FirstImageRecord,\r
/**\r
Sort image record based upon the ImageBase from low to high.\r
**/\r
+STATIC\r
VOID\r
SortImageRecord (\r
VOID\r
}\r
\r
/**\r
- Dump image record\r
+ Dump image record.\r
**/\r
+STATIC\r
VOID\r
DumpImageRecord (\r
VOID\r
EFI_IMAGE_DOS_HEADER *DosHdr;\r
UINT32 PeCoffHeaderOffset;\r
UINT32 SectionAlignment;\r
- UINT16 ImageType;\r
EFI_IMAGE_SECTION_HEADER *Section;\r
EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr;\r
- UINT16 Magic;\r
UINT8 *Name;\r
UINTN Index;\r
IMAGE_PROPERTIES_RECORD *ImageRecord;\r
CHAR8 *PdbPointer;\r
IMAGE_PROPERTIES_RECORD_CODE_SECTION *ImageRecordCodeSection;\r
+ UINT16 Magic;\r
\r
DEBUG ((EFI_D_VERBOSE, "InsertImageRecord - 0x%x\n", RuntimeImage));\r
DEBUG ((EFI_D_VERBOSE, "InsertImageRecord - 0x%016lx - 0x%016lx\n", (EFI_PHYSICAL_ADDRESS)(UINTN)RuntimeImage->ImageBase, RuntimeImage->ImageSize));\r
Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)((UINT8 *) (UINTN) ImageAddress + PeCoffHeaderOffset);\r
if (Hdr.Pe32->Signature != EFI_IMAGE_NT_SIGNATURE) {\r
DEBUG ((EFI_D_VERBOSE, "Hdr.Pe32->Signature invalid - 0x%x\n", Hdr.Pe32->Signature));\r
- // It might be image in SMM.\r
+ // It might be image in SMM.\r
goto Finish;\r
}\r
\r
//\r
- // Measuring PE/COFF Image Header;\r
- // But CheckSum field and SECURITY data directory (certificate) are excluded\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
// then override the magic value to EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC\r
//\r
Magic = EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC;\r
- ImageType = Hdr.Pe32->OptionalHeader.Subsystem;\r
- SectionAlignment = Hdr.Pe32->OptionalHeader.SectionAlignment;\r
} else {\r
//\r
// Get the magic value from the PE/COFF Optional Header\r
//\r
Magic = Hdr.Pe32->OptionalHeader.Magic;\r
- ImageType = Hdr.Pe32Plus->OptionalHeader.Subsystem;\r
+ }\r
+ if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {\r
+ SectionAlignment = Hdr.Pe32->OptionalHeader.SectionAlignment;\r
+ } else {\r
SectionAlignment = Hdr.Pe32Plus->OptionalHeader.SectionAlignment;\r
}\r
\r
SetPropertiesTableSectionAlignment (SectionAlignment);\r
- if ((SectionAlignment & (SIZE_4KB - 1)) != 0) {\r
- DEBUG ((EFI_D_ERROR, "!!!!!!!! InsertImageRecord - Section Alignment(0x%x) is not 4K !!!!!!!!\n", SectionAlignment));\r
+ if ((SectionAlignment & (EFI_ACPI_RUNTIME_PAGE_ALLOCATION_ALIGNMENT - 1)) != 0) {\r
+ DEBUG ((EFI_D_ERROR, "!!!!!!!! InsertImageRecord - Section Alignment(0x%x) is not %dK !!!!!!!!\n",\r
+ SectionAlignment, EFI_ACPI_RUNTIME_PAGE_ALLOCATION_ALIGNMENT >> 10));\r
PdbPointer = PeCoffLoaderGetPdbPointer ((VOID*) (UINTN) ImageAddress);\r
if (PdbPointer != NULL) {\r
DEBUG ((EFI_D_ERROR, "!!!!!!!! Image - %a !!!!!!!!\n", PdbPointer));\r
\r
@return image record\r
**/\r
+STATIC\r
IMAGE_PROPERTIES_RECORD *\r
FindImageRecord (\r
IN EFI_PHYSICAL_ADDRESS ImageBase,\r
VOID *Context\r
)\r
{\r
- if (PcdGetBool (PropertiesTableEnable)) {\r
+ if (PcdGetBool (PcdPropertiesTableEnable)) {\r
EFI_STATUS Status;\r
\r
Status = gBS->InstallConfigurationTable (&gEfiPropertiesTableGuid, &mPropertiesTable);\r