diff --git a/MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c b/MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c index 6f48479d62..5c65d62d94 100644 --- a/MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c +++ b/MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c @@ -768,6 +768,15 @@ CoreExitBootServices ( // Free resources allocated for Ring3. // if (gRing3Data != NULL) { + DisableSMAP (); + if (gRing3Data->SystemTable.ConfigurationTable != NULL) { + CoreFreePages ( + (EFI_PHYSICAL_ADDRESS)(UINTN)gRing3Data->SystemTable.ConfigurationTable, + EFI_SIZE_TO_PAGES (gRing3Data->SystemTable.NumberOfTableEntries * sizeof (EFI_CONFIGURATION_TABLE)) + ); + } + EnableSMAP (); + CoreFreePages ( (EFI_PHYSICAL_ADDRESS)(UINTN)gRing3Data, EFI_SIZE_TO_PAGES (sizeof (RING3_DATA)) diff --git a/MdeModulePkg/Core/Dxe/SysCall/BootServices.c b/MdeModulePkg/Core/Dxe/SysCall/BootServices.c index 98d06a6229..508fe4fba6 100644 --- a/MdeModulePkg/Core/Dxe/SysCall/BootServices.c +++ b/MdeModulePkg/Core/Dxe/SysCall/BootServices.c @@ -1400,9 +1400,30 @@ SysCallBootService ( IN VOID *UserRsp ) { - return CallBootService ( - Type, - (CORE_STACK *)CoreRbp, - (RING3_STACK *)UserRsp - ); + EFI_STATUS Status; + EFI_PHYSICAL_ADDRESS Physical; + + Status = CoreAllocatePages ( + AllocateAnyPages, + EfiRing3MemoryType, + EFI_SIZE_TO_PAGES (8 * sizeof (UINTN)), + &Physical + ); + if (EFI_ERROR (Status)) { + return Status; + } + + DisableSMAP (); + CopyMem ((VOID *)(UINTN)Physical, (VOID *)UserRsp, 8 * sizeof (UINTN)); + EnableSMAP (); + + Status = CallBootService ( + Type, + (CORE_STACK *)CoreRbp, + (RING3_STACK *)(UINTN)Physical + ); + + CoreFreePages (Physical, EFI_SIZE_TO_PAGES (8 * sizeof (UINTN))); + + return Status; } diff --git a/MdeModulePkg/Core/Dxe/SysCall/Initialization.c b/MdeModulePkg/Core/Dxe/SysCall/Initialization.c index 0b108d34fa..58651a4963 100644 --- a/MdeModulePkg/Core/Dxe/SysCall/Initialization.c +++ b/MdeModulePkg/Core/Dxe/SysCall/Initialization.c @@ -32,6 +32,8 @@ InitializeRing3 ( VOID *TopOfStack; UINTN SizeOfStack; EFI_PHYSICAL_ADDRESS Physical; + UINTN Index; + EFI_CONFIGURATION_TABLE *Conf; // // Set Ring3 EntryPoint and BootServices. @@ -50,6 +52,28 @@ InitializeRing3 ( gRing3Data = (RING3_DATA *)(UINTN)Physical; CopyMem ((VOID *)gRing3Data, (VOID *)Image->Info.SystemTable, sizeof (EFI_SYSTEM_TABLE)); + + Status = CoreAllocatePages ( + AllocateAnyPages, + EfiRing3MemoryType, + EFI_SIZE_TO_PAGES (gRing3Data->SystemTable.NumberOfTableEntries * sizeof (EFI_CONFIGURATION_TABLE)), + &Physical + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "Core: Failed to allocate memory for Ring3 ConfigurationTable.\n")); + return Status; + } + + Conf = (EFI_CONFIGURATION_TABLE *)(UINTN)Physical; + + for (Index = 0; Index < gRing3Data->SystemTable.NumberOfTableEntries; ++Index) { + Conf->VendorGuid = gRing3Data->SystemTable.ConfigurationTable[Index].VendorGuid; + Conf->VendorTable = gRing3Data->SystemTable.ConfigurationTable[Index].VendorTable; + ++Conf; + } + + gRing3Data->SystemTable.ConfigurationTable = (EFI_CONFIGURATION_TABLE *)(UINTN)Physical; + // // Initialize DxeRing3 with Supervisor privileges. // diff --git a/MdeModulePkg/Core/Dxe/SysCall/SupportedProtocols.c b/MdeModulePkg/Core/Dxe/SysCall/SupportedProtocols.c index b6fd7d7cc1..90fd9761a1 100644 --- a/MdeModulePkg/Core/Dxe/SysCall/SupportedProtocols.c +++ b/MdeModulePkg/Core/Dxe/SysCall/SupportedProtocols.c @@ -58,6 +58,7 @@ GoToRing3 ( VA_END (Marker); EnableSMAP (); +#if defined (MDE_CPU_X64) || defined (MDE_CPU_IA32) if (Number == 2) { // // Necessary fix for ProcessLibraryConstructorList() -> DxeCcProbeLibConstructor() @@ -68,9 +69,11 @@ GoToRing3 ( EFI_MEMORY_XP | EFI_MEMORY_USER ); } +#endif Status = CallRing3 (Input); +#if defined (MDE_CPU_X64) || defined (MDE_CPU_IA32) if (Number == 2) { SetUefiImageMemoryAttributes ( FixedPcdGet32 (PcdOvmfWorkAreaBase), @@ -78,6 +81,7 @@ GoToRing3 ( EFI_MEMORY_XP ); } +#endif CoreFreePages (Ring3Pages, PagesNumber);