Index: /trunk/src/VBox/Devices/EFI/Firmware/BaseTools/Source/C/DevicePath/DevicePathFromText.c
===================================================================
--- /trunk/src/VBox/Devices/EFI/Firmware/BaseTools/Source/C/DevicePath/DevicePathFromText.c	(revision 82321)
+++ /trunk/src/VBox/Devices/EFI/Firmware/BaseTools/Source/C/DevicePath/DevicePathFromText.c	(revision 82322)
@@ -3338,5 +3338,9 @@
   {L"UartFlowCtrl",            DevPathFromTextUartFlowCtrl            },
   {L"SAS",                     DevPathFromTextSAS                     },
+#ifndef VBOX
   {L"SasEx",                   DevPathFromTextSasEx                   },
+#else
+  {L"NVMe",                    DevPathFromTextNVMe                    },
+#endif
   {L"NVMe",                    DevPathFromTextNVMe                    },
   {L"UFS",                     DevPathFromTextUfs                     },
Index: /trunk/src/VBox/Devices/EFI/Firmware/MdeModulePkg/Core/Dxe/Hand/Locate.c
===================================================================
--- /trunk/src/VBox/Devices/EFI/Firmware/MdeModulePkg/Core/Dxe/Hand/Locate.c	(revision 82321)
+++ /trunk/src/VBox/Devices/EFI/Firmware/MdeModulePkg/Core/Dxe/Hand/Locate.c	(revision 82322)
@@ -398,4 +398,81 @@
   return Handle;
 }
+
+
+#ifdef VBOX
+/**
+ * This works around several issues with device paths created by macOS AppleACPIPlatform.kext.
+ *
+ * See @bugref{6930} comment 84 and following for an in depth explanation.
+ */
+BOOLEAN
+EFIAPI
+vboxDevicePathCompareMacOsHacks(IN EFI_DEVICE_PATH_PROTOCOL *LocateDevicePath,
+                                IN EFI_DEVICE_PATH_PROTOCOL *HandleDevicePath,
+                                UINTN Size)
+{
+    EFI_DEVICE_PATH_PROTOCOL *AlteredDevicePath = NULL;
+    EFI_DEVICE_PATH_PROTOCOL *TmpDevicePath = LocateDevicePath;
+
+    /* First check whether the device path to be located contains a NVMe or SATA node where we have to employ the hacks. */
+    while (!IsDevicePathEnd(TmpDevicePath)) {
+        if (IsDevicePathEndInstance(TmpDevicePath)) {
+          //
+          // If DevicePath is a multi-instance device path,
+          // the function will operate on the first instance
+          //
+          break;
+        }
+
+        if (   DevicePathType(TmpDevicePath) == MESSAGING_DEVICE_PATH
+            && DevicePathSubType(TmpDevicePath) == MSG_SASEX_DP)
+        {
+            /*
+             * macOS uses the SasEx path sub type for NVMe entries (the node is actually an
+             * NVMe one). So we alter the device path to contain a proper NVMe sub type for
+             * matching against the devices device path.
+             */
+            AlteredDevicePath = DuplicateDevicePath(LocateDevicePath);
+            if (AlteredDevicePath != NULL)
+            {
+                UINTN offNode = (UINTN)TmpDevicePath - (UINTN)LocateDevicePath;
+                EFI_DEVICE_PATH_PROTOCOL *NvmeNode = (EFI_DEVICE_PATH_PROTOCOL *)((UINTN)AlteredDevicePath + offNode);
+
+                NvmeNode->SubType = MSG_NVME_NAMESPACE_DP;
+            }
+            break;
+        }
+        else if (   DevicePathType(TmpDevicePath) == MESSAGING_DEVICE_PATH
+                 && DevicePathSubType(TmpDevicePath) == MSG_SATA_DP)
+        {
+            /*
+             * macOS uses a 0 port multiplier number for devices directly attached
+             * to the HBA while it should be 0xffff according to the UEFI spec.
+             * We alter this here and try to match against the devices device path.
+             */
+            AlteredDevicePath = DuplicateDevicePath(LocateDevicePath);
+            if (AlteredDevicePath != NULL)
+            {
+                UINTN offNode = (UINTN)TmpDevicePath - (UINTN)LocateDevicePath;
+                SATA_DEVICE_PATH *SataNode = (SATA_DEVICE_PATH *)((UINTN)AlteredDevicePath + offNode);
+
+                SataNode->PortMultiplierPortNumber = 0xffff;
+            }
+            break;
+        }
+
+        TmpDevicePath = NextDevicePathNode(TmpDevicePath);
+    }
+
+    if (AlteredDevicePath != NULL)
+    {
+        BOOLEAN fMatch = CompareMem(AlteredDevicePath, HandleDevicePath, Size) == 0;
+        FreePool(AlteredDevicePath);
+        return fMatch;
+    }
+
+    return FALSE;
+}
+#endif
 
 
@@ -485,5 +562,11 @@
     Size = GetDevicePathSize (TmpDevicePath) - sizeof(EFI_DEVICE_PATH_PROTOCOL);
     ASSERT (Size >= 0);
+#ifndef VBOX
     if ((Size <= SourceSize) && CompareMem (SourcePath, TmpDevicePath, (UINTN) Size) == 0) {
+#else
+    if (   (Size <= SourceSize)
+        && (   CompareMem (SourcePath, TmpDevicePath, (UINTN) Size) == 0
+            || vboxDevicePathCompareMacOsHacks(SourcePath, TmpDevicePath, (UINTN)Size))) {
+#endif
       //
       // If the size is equal to the best match, then we
Index: /trunk/src/VBox/Devices/EFI/Firmware/MdePkg/Library/UefiDevicePathLib/DevicePathFromText.c
===================================================================
--- /trunk/src/VBox/Devices/EFI/Firmware/MdePkg/Library/UefiDevicePathLib/DevicePathFromText.c	(revision 82321)
+++ /trunk/src/VBox/Devices/EFI/Firmware/MdePkg/Library/UefiDevicePathLib/DevicePathFromText.c	(revision 82322)
@@ -3493,5 +3493,9 @@
   {L"UartFlowCtrl",            DevPathFromTextUartFlowCtrl            },
   {L"SAS",                     DevPathFromTextSAS                     },
+#ifndef VBOX
   {L"SasEx",                   DevPathFromTextSasEx                   },
+#else
+  {L"NVMe",                    DevPathFromTextNVMe                    },
+#endif
   {L"NVMe",                    DevPathFromTextNVMe                    },
   {L"UFS",                     DevPathFromTextUfs                     },
Index: /trunk/src/VBox/Devices/EFI/Firmware/MdePkg/Library/UefiDevicePathLib/DevicePathToText.c
===================================================================
--- /trunk/src/VBox/Devices/EFI/Firmware/MdePkg/Library/UefiDevicePathLib/DevicePathToText.c	(revision 82321)
+++ /trunk/src/VBox/Devices/EFI/Firmware/MdePkg/Library/UefiDevicePathLib/DevicePathToText.c	(revision 82322)
@@ -2277,5 +2277,9 @@
   {MESSAGING_DEVICE_PATH, MSG_FIBRECHANNEL_DP,              DevPathToTextFibre          },
   {MESSAGING_DEVICE_PATH, MSG_FIBRECHANNELEX_DP,            DevPathToTextFibreEx        },
+#ifndef VBOX
   {MESSAGING_DEVICE_PATH, MSG_SASEX_DP,                     DevPathToTextSasEx          },
+#else
+  {MESSAGING_DEVICE_PATH, MSG_SASEX_DP,                     DevPathToTextNVMe           },
+#endif
   {MESSAGING_DEVICE_PATH, MSG_NVME_NAMESPACE_DP,            DevPathToTextNVMe           },
   {MESSAGING_DEVICE_PATH, MSG_UFS_DP,                       DevPathToTextUfs            },
