|
75 | 75 | //! other types in this module are DSTs, so pointers to the type are |
76 | 76 | //! "fat" and not suitable for FFI. |
77 | 77 | //! |
| 78 | +//! * [`PoolDevicePath`] is an owned device path on the UEFI heap. |
| 79 | +//! |
78 | 80 | //! All of these types use a packed layout and may appear on any byte |
79 | 81 | //! boundary. |
80 | 82 | //! |
@@ -133,6 +135,10 @@ opaque_type! { |
133 | 135 | } |
134 | 136 |
|
135 | 137 | /// Device path allocated from UEFI pool memory. |
| 138 | +/// |
| 139 | +/// Please note that this differs from <code>Box<[DevicePath]></code>. Although |
| 140 | +/// both represent owned values, a <code>Box<[DevicePath]></code> is on the Rust |
| 141 | +/// heap which may or may not be backed by the UEFI heap. |
136 | 142 | #[derive(Debug)] |
137 | 143 | pub struct PoolDevicePath(pub(crate) PoolAllocation); |
138 | 144 |
|
@@ -392,11 +398,15 @@ impl DevicePathInstance { |
392 | 398 | } |
393 | 399 |
|
394 | 400 | /// Returns a boxed copy of that value. |
| 401 | + /// |
| 402 | + /// The semantics slightly differs from a [`PoolDevicePath`] but is |
| 403 | + /// generally more idiomatic to use. |
395 | 404 | #[cfg(feature = "alloc")] |
396 | 405 | #[must_use] |
397 | 406 | pub fn to_boxed(&self) -> Box<Self> { |
398 | 407 | let data = self.data.to_owned(); |
399 | 408 | let data = data.into_boxed_slice(); |
| 409 | + // SAFETY: This is safe as a DevicePath has the same layout. |
400 | 410 | unsafe { mem::transmute(data) } |
401 | 411 | } |
402 | 412 | } |
@@ -581,12 +591,16 @@ impl DevicePath { |
581 | 591 | &self.data |
582 | 592 | } |
583 | 593 |
|
584 | | - /// Returns a boxed copy of that value. |
| 594 | + /// Returns a boxed copy of that value on the Rust heap. |
| 595 | + /// |
| 596 | + /// The semantics slightly differs from a [`PoolDevicePath`] but is |
| 597 | + /// generally more idiomatic to use. |
585 | 598 | #[cfg(feature = "alloc")] |
586 | 599 | #[must_use] |
587 | 600 | pub fn to_boxed(&self) -> Box<Self> { |
588 | 601 | let data = self.data.to_owned(); |
589 | 602 | let data = data.into_boxed_slice(); |
| 603 | + // SAFETY: This is safe as a DevicePath has the same layout. |
590 | 604 | unsafe { mem::transmute(data) } |
591 | 605 | } |
592 | 606 |
|
|
0 commit comments