diff --git a/MdeModulePkg/Core/Dxe/DxeMain.inf b/MdeModulePkg/Core/Dxe/DxeMain.inf index 7bd00b2a5b..ef383766b4 100644 --- a/MdeModulePkg/Core/Dxe/DxeMain.inf +++ b/MdeModulePkg/Core/Dxe/DxeMain.inf @@ -166,6 +166,8 @@ gEdkiiPeCoffImageEmulatorProtocolGuid ## SOMETIMES_CONSUMES gEfiDevicePathUtilitiesProtocolGuid ## SOMETIMES_CONSUMES gEfiComponentNameProtocolGuid ## SOMETIMES_CONSUMES + gEfiDiskIoProtocolGuid ## SOMETIMES_CONSUMES + gEfiBlockIoProtocolGuid ## SOMETIMES_CONSUMES # Arch Protocols gEfiBdsArchProtocolGuid ## CONSUMES diff --git a/MdeModulePkg/Core/Dxe/DxeRing3/DxeRing3.inf b/MdeModulePkg/Core/Dxe/DxeRing3/DxeRing3.inf index f22009b8cb..3dbe4b7532 100644 --- a/MdeModulePkg/Core/Dxe/DxeRing3/DxeRing3.inf +++ b/MdeModulePkg/Core/Dxe/DxeRing3/DxeRing3.inf @@ -41,6 +41,8 @@ [Protocols] gEfiDevicePathUtilitiesProtocolGuid ## SOMETIMES_CONSUMES gEfiLoadedImageProtocolGuid ## SOMETIMES_CONSUMES + gEfiDiskIoProtocolGuid ## SOMETIMES_CONSUMES + gEfiBlockIoProtocolGuid ## SOMETIMES_CONSUMES [Depex] TRUE diff --git a/MdeModulePkg/Core/Dxe/DxeRing3/Ring3UefiBootServices.c b/MdeModulePkg/Core/Dxe/DxeRing3/Ring3UefiBootServices.c index 9d02c2c6b8..c1aec1b883 100644 --- a/MdeModulePkg/Core/Dxe/DxeRing3/Ring3UefiBootServices.c +++ b/MdeModulePkg/Core/Dxe/DxeRing3/Ring3UefiBootServices.c @@ -398,7 +398,7 @@ Ring3OpenProtocol ( Attributes ); if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "Ring3: Failed to open protocol %g\n", Protocol)); + DEBUG ((DEBUG_ERROR, "Ring3: Failed to open protocol %g - %r\n", Protocol, Status)); return Status; } diff --git a/MdeModulePkg/Core/Dxe/SysCall/BootServices.c b/MdeModulePkg/Core/Dxe/SysCall/BootServices.c index 55d38e4864..24f5c79606 100644 --- a/MdeModulePkg/Core/Dxe/SysCall/BootServices.c +++ b/MdeModulePkg/Core/Dxe/SysCall/BootServices.c @@ -8,9 +8,6 @@ #include "DxeMain.h" #include "SupportedProtocols.h" -#include -#include - EFI_STATUS EFIAPI CallInstallMultipleProtocolInterfaces ( @@ -20,6 +17,43 @@ CallInstallMultipleProtocolInterfaces ( IN VOID *Function ); +EFI_STATUS +EFIAPI +FindGuid ( + IN EFI_GUID *Ring3, + OUT EFI_GUID **Core, + OUT UINT32 *CoreSize + ) +{ + ASSERT (Core != NULL); + ASSERT (CoreSize != NULL); + + if (CompareGuid (Ring3, &gEfiDevicePathUtilitiesProtocolGuid)) { + *Core = &gEfiDevicePathUtilitiesProtocolGuid; + *CoreSize = sizeof (EFI_DEVICE_PATH_UTILITIES_PROTOCOL); + } else if (CompareGuid (Ring3, &gEfiLoadedImageProtocolGuid)) { + *Core = &gEfiLoadedImageProtocolGuid; + *CoreSize = sizeof (EFI_LOADED_IMAGE_PROTOCOL); + } else if (CompareGuid (Ring3, &gEfiBlockIoProtocolGuid)) { + *Core = &gEfiBlockIoProtocolGuid; + *CoreSize = sizeof (EFI_BLOCK_IO_PROTOCOL); + } else if (CompareGuid (Ring3, &gEfiDiskIoProtocolGuid)) { + *Core = &gEfiDiskIoProtocolGuid; + *CoreSize = sizeof (EFI_DISK_IO_PROTOCOL); + } else if (CompareGuid (Ring3, &gEfiDriverBindingProtocolGuid)) { + *Core = &gEfiDriverBindingProtocolGuid; + *CoreSize = sizeof (EFI_DRIVER_BINDING_PROTOCOL); + } else if (CompareGuid (Ring3, &gEfiComponentNameProtocolGuid)) { + *Core = &gEfiComponentNameProtocolGuid; + *CoreSize = sizeof (EFI_COMPONENT_NAME_PROTOCOL); + } else { + DEBUG ((DEBUG_ERROR, "Ring0: Unknown protocol.\n")); + return EFI_NOT_FOUND; + } + + return EFI_SUCCESS; +} + typedef struct { UINTN Argument1; UINTN Argument2; @@ -76,15 +110,11 @@ CallBootService ( // Argument 3: VOID **Interface // DisableSMAP (); - if (CompareGuid ((EFI_GUID *)CoreRbp->Argument1, &gEfiDevicePathUtilitiesProtocolGuid)) { - CoreProtocol = &gEfiDevicePathUtilitiesProtocolGuid; - MemoryCoreSize = sizeof (EFI_DEVICE_PATH_UTILITIES_PROTOCOL); - } else { - DEBUG ((DEBUG_ERROR, "Ring0: Unknown protocol.\n")); - EnableSMAP (); - return EFI_INVALID_PARAMETER; - } + Status = FindGuid ((EFI_GUID *)CoreRbp->Argument1, &CoreProtocol, &MemoryCoreSize); EnableSMAP (); + if (EFI_ERROR (Status)) { + return Status; + } Status = gBS->LocateProtocol ( CoreProtocol, @@ -114,13 +144,10 @@ CallBootService ( // Argument 6: UINT32 Attributes // DisableSMAP (); - if (CompareGuid ((EFI_GUID *)CoreRbp->Argument2, &gEfiLoadedImageProtocolGuid)) { - CoreProtocol = &gEfiLoadedImageProtocolGuid; - MemoryCoreSize = sizeof (EFI_LOADED_IMAGE_PROTOCOL); - } else { - DEBUG ((DEBUG_ERROR, "Ring0: Unknown protocol.\n")); + Status = FindGuid ((EFI_GUID *)CoreRbp->Argument2, &CoreProtocol, &MemoryCoreSize); + if (EFI_ERROR (Status)) { EnableSMAP (); - return EFI_INVALID_PARAMETER; + return Status; } Argument4 = (EFI_HANDLE)UserRsp->Arguments[4]; @@ -158,22 +185,14 @@ CallBootService ( CoreHandle = *(EFI_HANDLE *)CoreRbp->Argument1; UserArgList = (VOID **)CoreRbp->Argument2; - for (Index = 0; UserArgList[Index] != NULL; ++Index) { - if (CompareGuid ((EFI_GUID *)UserArgList[Index], &gEfiDriverBindingProtocolGuid)) { - CoreArgList[Index] = (VOID *)&gEfiDriverBindingProtocolGuid; - MemoryCoreSize = sizeof (EFI_DRIVER_BINDING_PROTOCOL); - continue; - } else if (CompareGuid ((EFI_GUID *)UserArgList[Index], &gEfiComponentNameProtocolGuid)) { - CoreArgList[Index] = (VOID *)&gEfiComponentNameProtocolGuid; - MemoryCoreSize = sizeof (EFI_COMPONENT_NAME_PROTOCOL); - continue; - } else if ((Index % 2) == 0) { - DEBUG ((DEBUG_ERROR, "Ring0: Unknown protocol.\n")); + for (Index = 0; UserArgList[Index] != NULL; Index += 2) { + Status = FindGuid ((EFI_GUID *)UserArgList[Index], (EFI_GUID **)&CoreArgList[Index], &MemoryCoreSize); + if (EFI_ERROR (Status)) { EnableSMAP (); - return EFI_INVALID_PARAMETER; + return Status; } - CoreArgList[Index] = AllocateCopyPool (MemoryCoreSize, (VOID *)UserArgList[Index]); + CoreArgList[Index + 1] = AllocateCopyPool (MemoryCoreSize, (VOID *)UserArgList[Index + 1]); } EnableSMAP (); diff --git a/MdeModulePkg/Core/Dxe/SysCall/SupportedProtocols.h b/MdeModulePkg/Core/Dxe/SysCall/SupportedProtocols.h index 5e7e8b3a7a..6862030896 100644 --- a/MdeModulePkg/Core/Dxe/SysCall/SupportedProtocols.h +++ b/MdeModulePkg/Core/Dxe/SysCall/SupportedProtocols.h @@ -5,6 +5,11 @@ **/ +#include +#include +#include +#include + extern EFI_DRIVER_BINDING_PROTOCOL mRing3DriverBindingProtocol; EFI_STATUS