Ring3: Added support for User page table to AllocatePages(), FreePages().

This commit is contained in:
Mikhail Krichanov 2024-12-02 12:04:46 +03:00
parent 1bde91a85d
commit fcd47185eb
3 changed files with 20 additions and 1 deletions

View File

@ -245,7 +245,8 @@ DxeMain (
EFI_VECTOR_HANDOFF_INFO *VectorInfoList;
EFI_VECTOR_HANDOFF_INFO *VectorInfo;
gRing3Data = NULL;
gRing3Data = NULL;
gUserPageTable = 0;
//
// Setup Stack Guard

View File

@ -909,6 +909,7 @@ ApplyMemoryProtectionPolicy (
{
UINT64 OldAttributes;
UINT64 NewAttributes;
UINT64 CurrentAttributes;
//
// The policy configured in PcdDxeNxMemoryProtectionPolicy
@ -964,11 +965,27 @@ ApplyMemoryProtectionPolicy (
NewAttributes = GetPermissionAttributeForMemoryType (NewType);
if (OldType != EfiMaxMemoryType) {
//
// AllocatePages
//
OldAttributes = GetPermissionAttributeForMemoryType (OldType);
if (OldAttributes == NewAttributes) {
// policy is the same between OldType and NewType
return EFI_SUCCESS;
}
if ((gUserPageTable != 0) && (NewType == EfiRing3MemoryType)) {
gCpu->SetUserMemoryAttributes (gCpu, gUserPageTable, Memory, Length, NewAttributes);
}
} else {
//
// FreePages
//
gCpu->GetMemoryAttributes (gCpu, Memory, &CurrentAttributes);
if ((gUserPageTable != 0) && ((CurrentAttributes & EFI_MEMORY_USER) != 0)) {
gCpu->SetUserMemoryAttributes (gCpu, gUserPageTable, Memory, Length, EFI_MEMORY_RP);
}
}
return gCpu->SetMemoryAttributes (gCpu, Memory, Length, NewAttributes);

View File

@ -421,6 +421,7 @@ CpuGetMemoryAttributes (
PageEntry = GetPageTableEntry (&PagingContext, Address, &PageAttribute);
if (PageEntry == NULL) {
*Attributes = 0;
return EFI_NOT_FOUND;
}