| 337 | static EFI_DEVICE_PATH *LegacyLoaderMediaPath = (EFI_DEVICE_PATH *)LegacyLoaderMediaPathData; |
| 338 | |
| 339 | EFI_STATUS ExtractLegacyLoaderPaths(EFI_DEVICE_PATH **PathList, UINTN MaxPaths, EFI_DEVICE_PATH **HardcodedPathList) |
| 340 | { |
| 341 | EFI_STATUS Status; |
| 342 | UINTN HandleCount = 0; |
| 343 | UINTN HandleIndex, HardcodedIndex; |
| 344 | EFI_HANDLE *Handles = NULL; |
| 345 | EFI_HANDLE Handle; |
| 346 | UINTN PathCount = 0; |
| 347 | UINTN PathIndex; |
| 348 | EFI_LOADED_IMAGE *LoadedImage; |
| 349 | EFI_DEVICE_PATH *DevicePath; |
| 350 | BOOLEAN Seen; |
| 351 | |
| 352 | MaxPaths--; // leave space for the terminating NULL pointer |
| 353 | |
| 354 | // get all LoadedImage handles |
| 355 | Status = gBS->LocateHandleBuffer(ByProtocol, &gEfiLoadedImageProtocolGuid, NULL, |
| 356 | &HandleCount, &Handles); |
| 357 | if (CheckError(Status, L"while listing LoadedImage handles")) { |
| 358 | if (HardcodedPathList) { |
| 359 | for (HardcodedIndex = 0; HardcodedPathList[HardcodedIndex] && PathCount < MaxPaths; HardcodedIndex++) |
| 360 | PathList[PathCount++] = HardcodedPathList[HardcodedIndex]; |
| 361 | } |
| 362 | PathList[PathCount] = NULL; |
| 363 | return Status; |
| 364 | } |
| 365 | for (HandleIndex = 0; HandleIndex < HandleCount && PathCount < MaxPaths; HandleIndex++) { |
| 366 | Handle = Handles[HandleIndex]; |
| 367 | |
| 368 | Status = gBS->HandleProtocol(Handle, &gEfiLoadedImageProtocolGuid, (VOID **) &LoadedImage); |
| 369 | if (EFI_ERROR(Status)) |
| 370 | continue; // This can only happen if the firmware scewed up, ignore it. |
| 371 | |
| 372 | Status = gBS->HandleProtocol(LoadedImage->DeviceHandle, &gEfiDevicePathProtocolGuid, (VOID **) &DevicePath); |
| 373 | if (EFI_ERROR(Status)) |
| 374 | continue; // This happens, ignore it. |
| 375 | |
| 376 | // Only grab memory range nodes |
| 377 | if (DevicePathType(DevicePath) != HARDWARE_DEVICE_PATH || DevicePathSubType(DevicePath) != HW_MEMMAP_DP) |
| 378 | continue; |
| 379 | |
| 380 | // Check if we have this device path in the list already |
| 381 | // WARNING: This assumes the first node in the device path is unique! |
| 382 | Seen = FALSE; |
| 383 | for (PathIndex = 0; PathIndex < PathCount; PathIndex++) { |
| 384 | if (DevicePathNodeLength(DevicePath) != DevicePathNodeLength(PathList[PathIndex])) |
| 385 | continue; |
| 386 | if (CompareMem(DevicePath, PathList[PathIndex], DevicePathNodeLength(DevicePath)) == 0) { |
| 387 | Seen = TRUE; |
| 388 | break; |
| 389 | } |
| 390 | } |
| 391 | if (Seen) |
| 392 | continue; |
| 393 | |
| 394 | PathList[PathCount++] = AppendDevicePath(DevicePath, LegacyLoaderMediaPath); |
| 395 | } |
| 396 | FreePool(Handles); |
nothing calls this directly
no test coverage detected