Commit 2ea801a
committed
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 <[email protected]>1 parent 12445e0 commit 2ea801a
2 files changed
+15
-7
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
| |||
222 | 223 | | |
223 | 224 | | |
224 | 225 | | |
225 | | - | |
| 226 | + | |
226 | 227 | | |
227 | | - | |
| 228 | + | |
228 | 229 | | |
229 | 230 | | |
230 | 231 | | |
231 | 232 | | |
232 | | - | |
| 233 | + | |
233 | 234 | | |
234 | 235 | | |
235 | 236 | | |
| |||
242 | 243 | | |
243 | 244 | | |
244 | 245 | | |
245 | | - | |
| 246 | + | |
246 | 247 | | |
247 | 248 | | |
248 | 249 | | |
| |||
275 | 276 | | |
276 | 277 | | |
277 | 278 | | |
278 | | - | |
| 279 | + | |
279 | 280 | | |
280 | 281 | | |
281 | 282 | | |
282 | 283 | | |
283 | | - | |
| 284 | + | |
284 | 285 | | |
285 | 286 | | |
286 | 287 | | |
| |||
291 | 292 | | |
292 | 293 | | |
293 | 294 | | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
294 | 302 | | |
295 | 303 | | |
296 | 304 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
326 | 326 | | |
327 | 327 | | |
328 | 328 | | |
329 | | - | |
| 329 | + | |
330 | 330 | | |
331 | 331 | | |
332 | 332 | | |
| |||
0 commit comments