diff --git a/Library/OcBootServicesTableLib/OcBootServicesTableLib.c b/Library/OcBootServicesTableLib/OcBootServicesTableLib.c index 9b750633..922e7e6a 100644 --- a/Library/OcBootServicesTableLib/OcBootServicesTableLib.c +++ b/Library/OcBootServicesTableLib/OcBootServicesTableLib.c @@ -13,6 +13,10 @@ #include #include #include +#include + +#include +#include typedef struct OC_REGISTERED_PROTOCOL_ { EFI_GUID *ProtocolGuid; @@ -88,8 +92,9 @@ OcOpenProtocol ( IN UINT32 Attributes ) { - EFI_STATUS Status; - UINTN Index; + EFI_STATUS Status; + UINTN Index; + EFI_LOADED_IMAGE_PROTOCOL *LoadedImage; Status = mOpenProtocol ( Handle, @@ -100,6 +105,21 @@ OcOpenProtocol ( Attributes ); + // + // On Apple EFI some paths may not be valid for our DevicePath library. + // As a result we can end up in an infinite loop in GetImageNameFromHandle + // calling "drivers" in the Shell. Workaround by discarding unsupported paths. + // + if (!EFI_ERROR (Status) + && CompareGuid (Protocol, &gEfiLoadedImageProtocolGuid) + && Interface != NULL) { + LoadedImage = *Interface; + + if (LoadedImage->FilePath != NULL && !IsDevicePathValid (LoadedImage->FilePath, 0)) { + LoadedImage->FilePath = NULL; + } + } + if (Status != EFI_UNSUPPORTED || Handle != gImageHandle) { return Status; } diff --git a/Library/OcBootServicesTableLib/OcBootServicesTableLib.inf b/Library/OcBootServicesTableLib/OcBootServicesTableLib.inf index b8cad54c..67a5e09d 100644 --- a/Library/OcBootServicesTableLib/OcBootServicesTableLib.inf +++ b/Library/OcBootServicesTableLib/OcBootServicesTableLib.inf @@ -36,3 +36,4 @@ [LibraryClasses] BaseMemoryLib DebugLib + DevicePathLib diff --git a/Library/OcBootServicesTableLib/UefiBootServicesTableLib.inf b/Library/OcBootServicesTableLib/UefiBootServicesTableLib.inf index 1a311bb1..383dbddc 100644 --- a/Library/OcBootServicesTableLib/UefiBootServicesTableLib.inf +++ b/Library/OcBootServicesTableLib/UefiBootServicesTableLib.inf @@ -30,6 +30,7 @@ [Protocols] gEfiDevicePathProtocolGuid + gEfiLoadedImageProtocolGuid [LibraryClasses] BaseMemoryLib