| 174 | // |
| 175 | |
| 176 | EFI_STATUS InitRefitLib(IN EFI_HANDLE ImageHandle) |
| 177 | { |
| 178 | EFI_STATUS Status; |
| 179 | XStringW FilePathAsString; |
| 180 | UINTN i; |
| 181 | UINTN DevicePathSize; |
| 182 | EFI_DEVICE_PATH_PROTOCOL* TmpDevicePath; |
| 183 | |
| 184 | SelfImageHandle = ImageHandle; |
| 185 | Status = gBS->HandleProtocol(SelfImageHandle, &gEfiLoadedImageProtocolGuid, (VOID **) &SelfLoadedImage); |
| 186 | if (CheckFatalError(Status, L"while getting a LoadedImageProtocol handle")) |
| 187 | return Status; |
| 188 | |
| 189 | SelfDeviceHandle = SelfLoadedImage->DeviceHandle; |
| 190 | TmpDevicePath = DevicePathFromHandle (SelfDeviceHandle); |
| 191 | DevicePathSize = GetDevicePathSize (TmpDevicePath); |
| 192 | SelfDevicePath = (__typeof__(SelfDevicePath))AllocateAlignedPages(EFI_SIZE_TO_PAGES(DevicePathSize), 64); |
| 193 | CopyMem(SelfDevicePath, TmpDevicePath, DevicePathSize); |
| 194 | |
| 195 | DBG("SelfDevicePath=%ls @%llX\n", FileDevicePathToXStringW(SelfDevicePath).wc_str(), (uintptr_t)SelfDeviceHandle); |
| 196 | |
| 197 | // find the current directory |
| 198 | FilePathAsString = FileDevicePathToXStringW(SelfLoadedImage->FilePath); |
| 199 | if (FilePathAsString.notEmpty()) { |
| 200 | SelfFullDevicePath = FileDevicePath(SelfDeviceHandle, FilePathAsString); |
| 201 | for (i = FilePathAsString.length(); i > 0 && FilePathAsString[i] != '\\'; i--) ; |
| 202 | if (i > 0) { |
| 203 | FilePathAsString = FilePathAsString.subString(0, i); |
| 204 | } else { |
| 205 | FilePathAsString = L"\\"_XSW; |
| 206 | } |
| 207 | } else { |
| 208 | FilePathAsString = L"\\"_XSW; |
| 209 | } |
| 210 | SelfDirPath = FilePathAsString; |
| 211 | |
| 212 | DBG("SelfDirPath = %ls\n", SelfDirPath.wc_str()); |
| 213 | |
| 214 | return FinishInitRefitLib(); |
| 215 | } |
| 216 | |
| 217 | VOID UninitRefitLib(VOID) |
| 218 | { |
no test coverage detected