Ring3: Defined CpuGetMemoryAttributes(), DisableSMAP(), EnableSMAP() for AARCH64.

This commit is contained in:
Mikhail Krichanov 2024-05-20 11:34:40 +03:00
parent d1fa366ba2
commit 04c34b8135
6 changed files with 58 additions and 20 deletions

View File

@ -95,6 +95,12 @@ PageAttributeToGcdAttribute (
GcdAttributes |= EFI_MEMORY_XP;
}
if (((PageAttributes & TT_AP_MASK) == TT_AP_RW_RW) ||
((PageAttributes & TT_AP_MASK) == TT_AP_RO_RO))
{
GcdAttributes |= EFI_MEMORY_USER;
}
return GcdAttributes;
}

View File

@ -218,6 +218,7 @@ EFI_CPU_ARCH_PROTOCOL mCpu = {
CpuSetMemoryAttributes,
0, // NumberOfTimers
2048, // DmaBufferAlignment
CpuGetMemoryAttributes
};
STATIC

View File

@ -96,6 +96,14 @@ CpuSetMemoryAttributes (
IN UINT64 Attributes
);
EFI_STATUS
EFIAPI
CpuGetMemoryAttributes (
IN EFI_CPU_ARCH_PROTOCOL *This,
IN EFI_PHYSICAL_ADDRESS Address,
OUT UINT64 *Attributes
);
EFI_STATUS
InitializeExceptions (
IN EFI_CPU_ARCH_PROTOCOL *Cpu

View File

@ -222,3 +222,28 @@ CpuSetMemoryAttributes (
return EFI_SUCCESS;
}
}
EFI_STATUS
EFIAPI
CpuGetMemoryAttributes (
IN EFI_CPU_ARCH_PROTOCOL *This,
IN EFI_PHYSICAL_ADDRESS Address,
OUT UINT64 *Attributes
)
{
EFI_STATUS Status;
UINTN RegionBaseAddress;
UINTN RegionLength;
UINTN RegionArmAttributes;
RegionBaseAddress = Address;
Status = GetMemoryRegion (&RegionBaseAddress, &RegionLength, &RegionArmAttributes);
if (EFI_ERROR (Status)) {
return EFI_NOT_FOUND;
}
*Attributes = RegionAttributeToGcdAttribute (RegionArmAttributes);
return Status;
}

View File

@ -7,26 +7,6 @@
#include <AsmMacroIoLibV8.h>
//------------------------------------------------------------------------------
// VOID
// EFIAPI
// DisableSMAP (
// VOID
// );
//------------------------------------------------------------------------------
ASM_FUNC(DisableSMAP)
ret
//------------------------------------------------------------------------------
// VOID
// EFIAPI
// EnableSMAP (
// VOID
// );
//------------------------------------------------------------------------------
ASM_FUNC(EnableSMAP)
ret
//------------------------------------------------------------------------------
// EFI_STATUS
// EFIAPI

View File

@ -41,3 +41,21 @@ InitializeMsr (
ASSERT (FALSE);
}
}
VOID
EFIAPI
DisableSMAP (
VOID
)
{
ArmClearPan ();
}
VOID
EFIAPI
EnableSMAP (
VOID
)
{
ArmSetPan ();
}