Skip to content

Commit 8920d4b

Browse files
Deprecate BootServices::locate_protocol and mark it unsafe
This method has the same problems as `handle_protocol`; it does not mark the handle and protocol as in use. Calls to `locate_protocol` can be replaced by calling `get_handle_for_protocol` and `open_protocol`. #359
1 parent e63bf6d commit 8920d4b

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616

1717
- Marked `BootServices::handle_protocol` as `unsafe`. (This method is
1818
also deprecated -- use `open_protocol` instead.)
19+
- Deprecated `BootServices::locate_protocol` and marked it `unsafe`. Use
20+
`BootServices::get_handle_for_protocol` and
21+
`BootServices::open_protocol` instead.
1922

2023
### Fixed
2124

src/table/boot.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,9 +1019,17 @@ impl BootServices {
10191019
/// Returns a protocol implementation, if present on the system.
10201020
///
10211021
/// The caveats of `BootServices::handle_protocol()` also apply here.
1022-
pub fn locate_protocol<P: ProtocolPointer + ?Sized>(&self) -> Result<&UnsafeCell<P>> {
1022+
///
1023+
/// # Safety
1024+
///
1025+
/// This method is unsafe because the handle database is not
1026+
/// notified that the handle and protocol are in use; there is no
1027+
/// guarantee that they will remain valid for the duration of their
1028+
/// use. Use [`open_protocol`] instead.
1029+
#[deprecated(note = "it is recommended to use `open_protocol` instead")]
1030+
pub unsafe fn locate_protocol<P: ProtocolPointer + ?Sized>(&self) -> Result<&UnsafeCell<P>> {
10231031
let mut ptr = ptr::null_mut();
1024-
(self.locate_protocol)(&P::GUID, ptr::null_mut(), &mut ptr).into_with_val(|| unsafe {
1032+
(self.locate_protocol)(&P::GUID, ptr::null_mut(), &mut ptr).into_with_val(|| {
10251033
let ptr = P::mut_ptr_from_ffi(ptr) as *const UnsafeCell<P>;
10261034
&*ptr
10271035
})

0 commit comments

Comments
 (0)