OcMemoryLib: Add counting split descriptors

This commit is contained in:
vit9696 2020-04-03 02:30:24 +03:00
parent 763cab2140
commit 98f17b671d
2 changed files with 43 additions and 1 deletions

View File

@ -24,7 +24,6 @@
#define PREV_MEMORY_DESCRIPTOR(MemoryDescriptor, Size) \
((EFI_MEMORY_DESCRIPTOR *)((UINT8 *)(MemoryDescriptor) - (Size)))
/**
Get last descriptor address.
It is assumed that the descriptor contains pages.
@ -266,6 +265,16 @@ OcUpdateAttributes (
IN UINT64 DropAttributes
);
/**
Count upper bound of split runtime descriptors.
@retval amount of runtime descriptors.
**/
UINTN
OcCountSplitDescritptors (
VOID
);
/**
Return pointer to PML4 table in PageTable and PWT and PCD flags in Flags.

View File

@ -540,3 +540,36 @@ OcUpdateAttributes (
return EFI_UNSUPPORTED;
}
UINTN
OcCountSplitDescritptors (
VOID
)
{
UINTN Index;
UINTN DescriptorCount;
CONST EFI_MEMORY_ATTRIBUTES_TABLE *MemoryAttributesTable;
EFI_MEMORY_DESCRIPTOR *MemoryAttributesEntry;
DescriptorCount = 0;
for (Index = 0; Index < gST->NumberOfTableEntries; ++Index) {
if (CompareGuid (&gST->ConfigurationTable[Index].VendorGuid, &gEfiMemoryAttributesTableGuid)) {
MemoryAttributesTable = (CONST EFI_MEMORY_ATTRIBUTES_TABLE *) gST->ConfigurationTable[Index].VendorTable;
MemoryAttributesEntry = (EFI_MEMORY_DESCRIPTOR *) (MemoryAttributesTable + 1);
for (Index = 0; Index < MemoryAttributesTable->NumberOfEntries; ++Index) {
if (MemoryAttributesEntry->Type == EfiRuntimeServicesCode
|| MemoryAttributesEntry->Type == EfiRuntimeServicesData) {
++DescriptorCount;
}
MemoryAttributesEntry = NEXT_MEMORY_DESCRIPTOR (
MemoryAttributesEntry,
MemoryAttributesTable->DescriptorSize
);
}
}
}
return DescriptorCount;
}