Skip to content

Commit 2c52f81

Browse files
committed
uefi: implement DevicePathHeader::from_ffi_ptr
Allows for making a `DevicePathHeader` from a byte splice, used primarily to verify whether the byte splice can also contain `DevicePathHeader.length` bytes.
1 parent a70ccab commit 2c52f81

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

uefi/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
- Added `table::{set_system_table, system_table_boot, system_table_runtime}`.
1212
This provides an initial API for global tables that do not require passing
1313
around a reference.
14+
- Implemented `DevicePathHeader::from_ffi_ptr`.
1415

1516
## Changed
1617
- `SystemTable::exit_boot_services` is now `unsafe`. See that method's

uefi/src/proto/device_path/mod.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,20 @@ pub struct DevicePathHeader {
119119
pub length: u16,
120120
}
121121

122+
impl DevicePathHeader {
123+
/// Create a [`DevicePathHeader`] reference from an opaque pointer.
124+
///
125+
/// # Safety
126+
///
127+
/// The input pointer must point to valid data. That data must
128+
/// remain valid for the lifetime `'a`, and cannot be mutated during
129+
/// that lifetime.
130+
#[must_use]
131+
pub unsafe fn from_ffi_ptr<'a>(ptr: *const FfiDevicePath) -> &'a DevicePathHeader {
132+
&*ptr.cast::<DevicePathHeader>()
133+
}
134+
}
135+
122136
/// A single node within a [`DevicePath`].
123137
///
124138
/// Each node starts with a [`DevicePathHeader`]. The rest of the data

0 commit comments

Comments
 (0)