diff options
author | Taylor Beebe <taylor.d.beebe@gmail.com> | 2023-11-20 12:07:29 -0800 |
---|---|---|
committer | mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> | 2023-11-27 18:55:18 +0000 |
commit | e2f2bbe208b4c7ebcedacfc8333df1e52cbf07eb (patch) | |
tree | e49256aaa14ad27b1bbb3be9c55f1d6af402101b /MdeModulePkg | |
parent | acb29d4cbeb4f11c33576fcde438d0a37e053933 (diff) | |
download | edk2-e2f2bbe208b4c7ebcedacfc8333df1e52cbf07eb.tar.gz edk2-e2f2bbe208b4c7ebcedacfc8333df1e52cbf07eb.tar.bz2 edk2-e2f2bbe208b4c7ebcedacfc8333df1e52cbf07eb.zip |
MdeModulePkg: Fix MAT SplitRecord() Logic
SplitRecord() does not handle the case where a memory descriptor
describes an image region plus extra pages before or after the
image region. This patch fixes this case by carving off the
unrelated regions into their own descriptors.
Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Dandan Bi <dandan.bi@intel.com>
Signed-off-by: Taylor Beebe <taylor.d.beebe@gmail.com>
Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>
Diffstat (limited to 'MdeModulePkg')
-rw-r--r-- | MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLib.c | 56 |
1 files changed, 27 insertions, 29 deletions
diff --git a/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLib.c b/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLib.c index 7c0ecd07c1..9d4082280b 100644 --- a/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLib.c +++ b/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLib.c @@ -323,7 +323,6 @@ SplitRecord ( UINT64 PhysicalEnd;
UINTN NewRecordCount;
UINTN TotalNewRecordCount;
- BOOLEAN IsLastRecordData;
if (MaxSplitRecordCount == 0) {
CopyMem (NewRecord, OldRecord, DescriptorSize);
@@ -344,35 +343,16 @@ SplitRecord ( NewImageRecord = GetImageRecordByAddress (PhysicalStart, PhysicalEnd - PhysicalStart, ImageRecordList);
if (NewImageRecord == NULL) {
//
- // No more image covered by this range, stop
+ // No more images cover this range, check if we've reached the end of the old descriptor. If not,
+ // add the remaining range to the new descriptor list.
//
- if ((PhysicalEnd > PhysicalStart) && (ImageRecord != NULL)) {
- //
- // If this is still address in this record, need record.
- //
- NewRecord = PREVIOUS_MEMORY_DESCRIPTOR (NewRecord, DescriptorSize);
- IsLastRecordData = FALSE;
- if ((NewRecord->Attribute & EFI_MEMORY_XP) != 0) {
- IsLastRecordData = TRUE;
- }
-
- if (IsLastRecordData) {
- //
- // Last record is DATA, just merge it.
- //
- NewRecord->NumberOfPages = EfiSizeToPages (PhysicalEnd - NewRecord->PhysicalStart);
- } else {
- //
- // Last record is CODE, create a new DATA entry.
- //
- NewRecord = NEXT_MEMORY_DESCRIPTOR (NewRecord, DescriptorSize);
- NewRecord->Type = TempRecord.Type;
- NewRecord->PhysicalStart = TempRecord.PhysicalStart;
- NewRecord->VirtualStart = 0;
- NewRecord->NumberOfPages = TempRecord.NumberOfPages;
- NewRecord->Attribute = TempRecord.Attribute | EFI_MEMORY_XP;
- TotalNewRecordCount++;
- }
+ if (PhysicalEnd > PhysicalStart) {
+ NewRecord->Type = TempRecord.Type;
+ NewRecord->PhysicalStart = PhysicalStart;
+ NewRecord->VirtualStart = 0;
+ NewRecord->NumberOfPages = EfiSizeToPages (PhysicalEnd - PhysicalStart);
+ NewRecord->Attribute = TempRecord.Attribute;
+ TotalNewRecordCount++;
}
break;
@@ -381,6 +361,24 @@ SplitRecord ( ImageRecord = NewImageRecord;
//
+ // Update PhysicalStart to exclude the portion before the image buffer
+ //
+ if (TempRecord.PhysicalStart < ImageRecord->ImageBase) {
+ NewRecord->Type = TempRecord.Type;
+ NewRecord->PhysicalStart = TempRecord.PhysicalStart;
+ NewRecord->VirtualStart = 0;
+ NewRecord->NumberOfPages = EfiSizeToPages (ImageRecord->ImageBase - TempRecord.PhysicalStart);
+ NewRecord->Attribute = TempRecord.Attribute;
+ TotalNewRecordCount++;
+
+ PhysicalStart = ImageRecord->ImageBase;
+ TempRecord.PhysicalStart = PhysicalStart;
+ TempRecord.NumberOfPages = EfiSizeToPages (PhysicalEnd - PhysicalStart);
+
+ NewRecord = (EFI_MEMORY_DESCRIPTOR *)((UINT8 *)NewRecord + DescriptorSize);
+ }
+
+ //
// Set new record
//
NewRecordCount = SetNewRecord (ImageRecord, NewRecord, &TempRecord, DescriptorSize);
|