Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ GetFlatPageTableData (
UINTN NumPage1GNotPresent = 0;
UINT64 RootEntryCount = 0;
UINT64 Address;
BOOLEAN SelfMapped;

SelfMapped = FALSE;

// Count parameters should be provided.
if ((Pte1GCount == NULL) || (Pte2MCount == NULL) || (Pte4KCount == NULL) || (GuardCount == NULL)) {
Expand All @@ -89,15 +92,27 @@ GetFlatPageTableData (
Pml0 = (UINT64 *)ArmGetTTBR0BaseAddress ();
RootEntryCount = ROOT_TABLE_LEN (ArmGetTCR () & TCR_T0SZ_MASK);

//
// Check for the self-map entry as the last entry
//
if ((Pml0[0x1FF] & TT_ADDRESS_MASK) == (UINT64)Pml0) {
SelfMapped = TRUE;
Pml0 = (UINT64 *)0xFFFFFFFFF000;
}

for (Index0 = 0x0; Index0 < RootEntryCount; Index0++) {
Index1 = 0;
Index2 = 0;
Index3 = 0;
if (!IS_TABLE (Pml0[Index0], 0)) {
if (!IS_TABLE (Pml0[Index0], 0) || (SelfMapped && ((Index0 == 0x1FF) || (Index0 == 0x1FE)))) {
continue;
}

Pte1G = (UINT64 *)(Pml0[Index0] & TT_ADDRESS_MASK);
if (SelfMapped) {
Pte1G = (UINT64 *)((0xFFFFFFE00000 + SIZE_4KB * Index0));
} else {
Pte1G = (UINT64 *)(Pml0[Index0] & TT_ADDRESS_MASK);
}

for (Index1 = 0x0; Index1 < TT_ENTRY_COUNT; Index1++ ) {
Index2 = 0;
Expand All @@ -108,7 +123,13 @@ GetFlatPageTableData (
}

if (!IS_BLOCK (Pte1G[Index1], 1)) {
Pte2M = (UINT64 *)(Pte1G[Index1] & TT_ADDRESS_MASK);
if (SelfMapped) {
Pte2M = (UINT64 *)(0xFFFFC0000000 +
SIZE_2MB * Index0 +
SIZE_4KB * Index1);
} else {
Pte2M = (UINT64 *)(Pte1G[Index1] & TT_ADDRESS_MASK);
}

for (Index2 = 0x0; Index2 < TT_ENTRY_COUNT; Index2++ ) {
Index3 = 0;
Expand All @@ -118,7 +139,15 @@ GetFlatPageTableData (
}

if (!IS_BLOCK (Pte2M[Index2], 2)) {
Pte4K = (UINT64 *)(Pte2M[Index2] & TT_ADDRESS_MASK);
if (SelfMapped) {
Pte4K = (UINT64 *)(0xFF8000000000 +
SIZE_1GB * Index0 +
SIZE_2MB * Index1 +
SIZE_4KB * Index2
);
} else {
Pte4K = (UINT64 *)(Pte2M[Index2] & TT_ADDRESS_MASK);
}

for (Index3 = 0x0; Index3 < TT_ENTRY_COUNT; Index3++ ) {
Address = IndexToAddress (Index0, Index1, Index2, Index3);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@

[LibraryClasses.X64]
CpuLib
CpuPageTableLib

[Guids]
gEfiDebugImageInfoTableGuid ## SOMETIMES_CONSUMES ## GUID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,10 @@ AllocateMemoryMapBuffer (
goto FailureFreeMem;
}

// ensure we store the unmerged buffer size as that is the required size.
// Add some padding.
mMemoryMapBufferSize = mMemoryMapSize + (mMemoryMapSize / 5);

Status = gBS->GetMemoryMap (
&mMemoryMapSize,
mMemoryMap,
Expand Down Expand Up @@ -797,11 +801,6 @@ AllocateMemoryMapBuffer (
goto FailureFreeMem;
}

// mMemoryMapSize now contains the size of the filled in memory map. Increase
// it by 20% to account for any additional entries that may be required after
// other buffers are allocated.
mMemoryMapSize += (mMemoryMapSize / 5);
mMemoryMapBufferSize = mMemoryMapSize;
FreePool (mMemoryMap);
mMemoryMap = AllocateZeroPool (mMemoryMapBufferSize);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,9 @@ GetFlatPageTableData (
UINTN NumPage2MNotPresent = 0;
UINTN NumPage1GNotPresent = 0;
UINT64 Address;
BOOLEAN SelfMapped;

SelfMapped = FALSE;

//
// First, fail fast if some of the parameters don't look right.
Expand All @@ -599,12 +602,27 @@ GetFlatPageTableData (
//
Pml4 = (PAGE_MAP_AND_DIRECTORY_POINTER *)AsmReadCr3 ();

//
// Check for the self-map entry as the last entry
//
if ((Pml4[0x1FF].Bits.PageTableBaseAddress << 12) == (UINTN)Pml4) {
SelfMapped = TRUE;
Pml4 = (PAGE_MAP_AND_DIRECTORY_POINTER *)0xFFFFFFFFFFFFF000;
}

for (Index4 = 0x0; Index4 < 0x200; Index4++) {
if (!Pml4[Index4].Bits.Present) {
if (!Pml4[Index4].Bits.Present || (((Index4 == 0x1FF) || (Index4 == 0x1FE)) && SelfMapped)) {
continue;
}

Pte1G = (PAGE_TABLE_1G_ENTRY *)(UINTN)(Pml4[Index4].Bits.PageTableBaseAddress << 12);
if (SelfMapped) {
Pte1G = (PAGE_TABLE_1G_ENTRY *)(UINTN)((0xFFFFFFFFFFE00000 + SIZE_4KB * Index4));
} else {
//
// No self-map entry, so just use the physical address.
//
Pte1G = (PAGE_TABLE_1G_ENTRY *)(UINTN)(Pml4[Index4].Bits.PageTableBaseAddress << 12);
}

for (Index3 = 0x0; Index3 < 0x200; Index3++ ) {
if (!Pte1G[Index3].Bits.Present) {
Expand All @@ -621,8 +639,15 @@ GetFlatPageTableData (
// We have to cast 1G and 2M directories to this to
// get all of their address bits.
//
Work = (PAGE_MAP_AND_DIRECTORY_POINTER *)Pte1G;
Pte2M = (PAGE_TABLE_ENTRY *)(UINTN)(Work[Index3].Bits.PageTableBaseAddress << 12);
if (SelfMapped) {
Work = (PAGE_MAP_AND_DIRECTORY_POINTER *)Pte1G;
Pte2M = (PAGE_TABLE_ENTRY *)(UINTN)(0xFFFFFFFFC0000000 +
SIZE_2MB * Index4 +
SIZE_4KB * Index3);
} else {
Work = (PAGE_MAP_AND_DIRECTORY_POINTER *)Pte1G;
Pte2M = (PAGE_TABLE_ENTRY *)(UINTN)(Work[Index3].Bits.PageTableBaseAddress << 12);
}

for (Index2 = 0x0; Index2 < 0x200; Index2++ ) {
if (!Pte2M[Index2].Bits.Present) {
Expand All @@ -631,8 +656,16 @@ GetFlatPageTableData (
}

if (!(Pte2M[Index2].Bits.MustBe1)) {
Work = (PAGE_MAP_AND_DIRECTORY_POINTER *)Pte2M;
Pte4K = (PAGE_TABLE_4K_ENTRY *)(UINTN)(Work[Index2].Bits.PageTableBaseAddress << 12);
if (SelfMapped) {
Work = (PAGE_MAP_AND_DIRECTORY_POINTER *)Pte2M;
Pte4K = (PAGE_TABLE_4K_ENTRY *)(UINTN)(0xFFFFFF8000000000 +
SIZE_1GB * Index4 +
SIZE_2MB * Index3 +
SIZE_4KB * Index2);
} else {
Work = (PAGE_MAP_AND_DIRECTORY_POINTER *)Pte2M;
Pte4K = (PAGE_TABLE_4K_ENTRY *)(UINTN)(Work[Index2].Bits.PageTableBaseAddress << 12);
}

for (Index1 = 0x0; Index1 < 0x200; Index1++ ) {
if (!Pte4K[Index1].Bits.Present) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -633,22 +633,6 @@ <h3>External Licenses</h3>
} //end of configuring filter inputs
});

SavedFilters.push({
"Name": "Check Memory Not in EFI Memory Map is Inaccessible",
"Description": "Memory not in the EFI memory map should cause a fault if accessed",
"Filter": function (mrObject) {
var isTargetType = mrObject["Memory Type"] === "None";
var hasInvalidAttributes = mrObject["Access Flag"] !== "No";
return isTargetType && hasInvalidAttributes;
}, //end of Filter function
"ConfigureFilter": function () {
$("button#ClearAllFilter").click(); //clear the filters
SetMultiselectTo("MemoryTypeFilter", ["None"]);
SetMultiselectTo("AccessFlagFilter", ["Yes"]);
return true;
} //end of configuring filter inputs
});

//Fill in the test results tab
SavedFilters.forEach(function (TestObject) {
var FailedCount = EmbeddedJd.MemoryRanges.filter(TestObject.Filter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -654,22 +654,6 @@ <h3>External Licenses</h3>
} //end of configuring filter inputs
});

SavedFilters.push({
"Name": "Check Memory Not in EFI Memory Map is Inaccessible",
"Description": "Memory not in the EFI memory map should cause a fault if accessed",
"Filter": function (mrObject) {
var isTargetType = mrObject["Memory Type"] === "None";
var hasInvalidAttributes = mrObject["Present"] !== "No";
return isTargetType && hasInvalidAttributes;
}, //end of Filter function
"ConfigureFilter": function () {
$("button#ClearAllFilter").click(); //clear the filters
SetMultiselectTo("MemoryTypeFilter", ["None"]);
SetMultiselectTo("PresentFilter", ["Yes"]);
return true;
} //end of configuring filter inputs
});

//Fill in the test results tab
SavedFilters.forEach(function (TestObject) {
var FailedCount = EmbeddedJd.MemoryRanges.filter(TestObject.Filter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ def toDictionary(self):
if ("GDT" in self.ImageName or "IDT" in self.ImageName):
section_type = "Descriptor Table"
else:
section_type = "ERROR"
section_type = "RODATA"
elif self.Nx == 1:
section_type = "DATA"
elif self.ReadWrite == 0:
Expand All @@ -342,10 +342,8 @@ def toDictionary(self):
if self.ImageName == None:
section_type = "Not Tracked"
else:
# if an image range can't be read or executed, this is almost certainly
# an error.
if self.Ux == 0 and self.ReadWrite == 0:
section_type = "ERROR"
section_type = "RODATA"
elif self.Ux == 0:
section_type = "DATA"
elif self.ReadWrite == 0:
Expand Down
Loading