Skip to content

Commit c7d0064

Browse files
nicholasbishopGabrielMajeri
authored andcommitted
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 cdbcde3 commit c7d0064

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

CHANGELOG.md

+3
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

+11-2
Original file line numberDiff line numberDiff line change
@@ -1019,9 +1019,18 @@ 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 [`BootServices::get_handle_for_protocol`] and
1029+
/// [`BootServices::open_protocol`] instead.
1030+
#[deprecated(note = "it is recommended to use `open_protocol` instead")]
1031+
pub unsafe fn locate_protocol<P: ProtocolPointer + ?Sized>(&self) -> Result<&UnsafeCell<P>> {
10231032
let mut ptr = ptr::null_mut();
1024-
(self.locate_protocol)(&P::GUID, ptr::null_mut(), &mut ptr).into_with_val(|| unsafe {
1033+
(self.locate_protocol)(&P::GUID, ptr::null_mut(), &mut ptr).into_with_val(|| {
10251034
let ptr = P::mut_ptr_from_ffi(ptr) as *const UnsafeCell<P>;
10261035
&*ptr
10271036
})

0 commit comments

Comments
 (0)