Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
uefi: helpers: Introduce OwnedDevicePath
This PR is split off from rust-lang#135368 to reduce noise. No real functionality changes, just some quality of life improvements. Introduce `device_path_to_text_raw` which creates a Box<[u16]> (UTF-16 string) from path instead of creating OsString. The UTF-16 returned by `EFI_DEVICE_PATH_TO_TEXT` protocol is owned by the caller, so we are just moving the memory management to box instead of freeing it in the function itself. OsString internally is stored as WTF-8, which means converting OsString to Box<[u16]> requires allocation. This is not ideal for std::fs APIs where we need to perform Device Path Protocol matching while opening a volume, and create a UEFI UTF-16 string from the remaining path (which represents file path inside a volume). This remaining path is never used on the Rust side, and thus does not need to be converted to WTF-8 to be used. By introducing direct conversion to Box<[u16]>, we shorten the conversions from `EFI_DEVICE_PATH_PROTOCOL` -> WTF-8 -> UTF-16 to `EFI_DEVICE_PATH_PROTOCOL` -> UTF-16 which is required in every file open operation. That is, we remove 2 intermediate allocation and 1 UTF-16 validation. Also implement Debug for OwnedDevicePath for some quality of life improvements. Signed-off-by: Ayush Singh <ayush@beagleboard.org>
- Loading branch information