From 760614b0c5e23b4d71521c8805a40720b399a20d Mon Sep 17 00:00:00 2001 From: Mikhail Krichanov Date: Wed, 25 Sep 2024 09:40:03 +0300 Subject: [PATCH] SysCall: Fixed page fault for ARM. --- .../Core/Dxe/SysCall/ARM/InitializeMsr.c | 17 +++++++++++++---- .../Core/Dxe/SysCall/SupportedProtocols.c | 6 +++--- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/MdeModulePkg/Core/Dxe/SysCall/ARM/InitializeMsr.c b/MdeModulePkg/Core/Dxe/SysCall/ARM/InitializeMsr.c index 8ffd808742..d208c9e0fe 100644 --- a/MdeModulePkg/Core/Dxe/SysCall/ARM/InitializeMsr.c +++ b/MdeModulePkg/Core/Dxe/SysCall/ARM/InitializeMsr.c @@ -11,6 +11,7 @@ #include "DxeMain.h" STATIC UINTN mCoreSp; +extern UINTN gUartBaseAddress; EFI_STATUS EFIAPI @@ -64,6 +65,12 @@ SysCallBootService ( // All remaining arguments are on User Stack. // CopyMem ((VOID *)((UINTN)Physical + 5 * sizeof (UINTN)), (VOID *)UserRsp, 4 * sizeof (UINTN)); + + SetUefiImageMemoryAttributes ( + gUartBaseAddress, + EFI_PAGE_SIZE, + EFI_MEMORY_XP + ); ForbidSupervisorAccessToUserMemory (); Status = CallBootService ( @@ -72,6 +79,12 @@ SysCallBootService ( (RING3_STACK *)(UINTN)Physical ); + SetUefiImageMemoryAttributes ( + gUartBaseAddress, + EFI_PAGE_SIZE, + EFI_MEMORY_XP | EFI_MEMORY_USER + ); + CoreFreePages (Physical, EFI_SIZE_TO_PAGES (9 * sizeof (UINTN))); return Status; @@ -84,10 +97,6 @@ InitializeMsr ( IN UINTN NumberOfEntries ) { - // - // TODO: EFI_CONFIGURATION_TABLE, HOB_DATA, Uart are accessible to User. - // Fix PageTable initialization. - // if (ArmHasPan ()) { // // Enable Privileged Access Never feature. diff --git a/MdeModulePkg/Core/Dxe/SysCall/SupportedProtocols.c b/MdeModulePkg/Core/Dxe/SysCall/SupportedProtocols.c index a04c7aa92c..4da58f9839 100644 --- a/MdeModulePkg/Core/Dxe/SysCall/SupportedProtocols.c +++ b/MdeModulePkg/Core/Dxe/SysCall/SupportedProtocols.c @@ -13,7 +13,7 @@ EFI_FILE_PROTOCOL mRing3FileProtocol; EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *mRing3SimpleFileSystemPointer; -#if defined (MDE_CPU_AARCH64) +#if defined (MDE_CPU_AARCH64) || defined (MDE_CPU_ARM) extern UINTN gUartBaseAddress; #endif @@ -73,7 +73,7 @@ GoToRing3 ( EFI_MEMORY_XP | EFI_MEMORY_USER ); } -#elif defined (MDE_CPU_AARCH64) +#elif defined (MDE_CPU_AARCH64) || defined (MDE_CPU_ARM) // // Necessary fix for DEBUG printings. // @@ -93,7 +93,7 @@ GoToRing3 ( EFI_MEMORY_XP ); } -#elif defined (MDE_CPU_AARCH64) +#elif defined (MDE_CPU_AARCH64) || defined (MDE_CPU_ARM) // // Problem 2: Uart memory maped page is not allocated at the very beginnig // and can be used for translation table later.