From 9216e4195efbf78bd21f06bbafc796a7722c5f4c Mon Sep 17 00:00:00 2001 From: Mikhail Krichanov Date: Thu, 30 Jan 2025 14:06:15 +0300 Subject: [PATCH] Ring3: Fixed bug in Uart initialization. --- .../Library/DebugLibFdtPL011Uart/User.c | 3 +- .../Core/Dxe/SysCall/Initialization.c | 28 +++++++++---------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/ArmVirtPkg/Library/DebugLibFdtPL011Uart/User.c b/ArmVirtPkg/Library/DebugLibFdtPL011Uart/User.c index 6e012ee85b..2229cffde0 100644 --- a/ArmVirtPkg/Library/DebugLibFdtPL011Uart/User.c +++ b/ArmVirtPkg/Library/DebugLibFdtPL011Uart/User.c @@ -29,10 +29,11 @@ DebugLibFdtPL011UartUserConstructor ( for (Index = 0; Index < SystemTable->NumberOfTableEntries; ++Index) { if (CompareGuid (&gEarlyPL011BaseAddressGuid, &(SystemTable->ConfigurationTable[Index].VendorGuid))) { mDebugLibFdtPL011UartAddress = (UINTN)SystemTable->ConfigurationTable[Index].VendorTable; + return EFI_SUCCESS; } } - return EFI_SUCCESS; + return EFI_NOT_FOUND; } /** diff --git a/MdeModulePkg/Core/Dxe/SysCall/Initialization.c b/MdeModulePkg/Core/Dxe/SysCall/Initialization.c index ee9a256080..b3a731ce63 100644 --- a/MdeModulePkg/Core/Dxe/SysCall/Initialization.c +++ b/MdeModulePkg/Core/Dxe/SysCall/Initialization.c @@ -73,6 +73,15 @@ InitializeRing3 ( EFI_MEMORY_XP | EFI_MEMORY_USER ); + Status = InitializePlatform (&gRing3Data->SystemTable); + if (EFI_ERROR (Status)) { + CoreFreePages ( + (EFI_PHYSICAL_ADDRESS)(UINTN)gRing3Data, + EFI_SIZE_TO_PAGES (sizeof (RING3_DATA)) + ); + return Status; + } + // // Initialize DxeRing3 with Supervisor privileges. // @@ -81,14 +90,16 @@ InitializeRing3 ( SetUefiImageProtectionAttributes (mDxeRing3, FALSE); + AllowSupervisorAccessToUserMemory (); Status = Image->EntryPoint (ImageHandle, (EFI_SYSTEM_TABLE *)gRing3Data); - SetUefiImageProtectionAttributes (mDxeRing3, TRUE); - gRing3EntryPoint = gRing3Data->EntryPoint; gRing3Data->SystemTable.BootServices = gRing3Data->BootServices; gRing3Data->SystemTable.RuntimeServices = gRing3Data->RuntimeServices; + ForbidSupervisorAccessToUserMemory (); + + SetUefiImageProtectionAttributes (mDxeRing3, TRUE); Status = CoreAllocatePages ( AllocateAnyPages, @@ -112,19 +123,6 @@ InitializeRing3 ( EFI_MEMORY_XP | EFI_MEMORY_USER ); - Status = InitializePlatform (&gRing3Data->SystemTable); - if (EFI_ERROR (Status)) { - CoreFreePages ( - (EFI_PHYSICAL_ADDRESS)(UINTN)gRing3Data, - EFI_SIZE_TO_PAGES (sizeof (RING3_DATA)) - ); - CoreFreePages ( - (EFI_PHYSICAL_ADDRESS)(UINTN)gRing3Interfaces, - RING3_INTERFACES_PAGES - ); - return Status; - } - mExceptionAddresses = GetExceptionAddresses (); PeiHob.Raw = GetHobList ();