Skip to content

Commit cdbcde3

Browse files
nicholasbishopGabrielMajeri
authored andcommitted
Mark handle_protocol as unsafe
This function is already marked deprecated, mark it unsafe as well and update the documentation to describe why.
1 parent e0af6b2 commit cdbcde3

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
- Added the `MemoryProtection` protocol.
1313
- Added `BootServices::get_handle_for_protocol`.
1414

15+
### Changed
16+
17+
- Marked `BootServices::handle_protocol` as `unsafe`. (This method is
18+
also deprecated -- use `open_protocol` instead.)
19+
1520
### Fixed
1621

1722
- The `BootServices::create_event_ex` and

src/table/boot.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -576,14 +576,21 @@ impl BootServices {
576576
/// protections must be implemented by user-level code, for example via a
577577
/// global `HashSet`.
578578
///
579+
/// # Safety
580+
///
581+
/// This method is unsafe because the handle database is not
582+
/// notified that the handle and protocol are in use; there is no
583+
/// guarantee that they will remain valid for the duration of their
584+
/// use. Use [`open_protocol`] instead.
585+
///
579586
/// [`open_protocol`]: BootServices::open_protocol
580587
#[deprecated(note = "it is recommended to use `open_protocol` instead")]
581-
pub fn handle_protocol<P: ProtocolPointer + ?Sized>(
588+
pub unsafe fn handle_protocol<P: ProtocolPointer + ?Sized>(
582589
&self,
583590
handle: Handle,
584591
) -> Result<&UnsafeCell<P>> {
585592
let mut ptr = ptr::null_mut();
586-
(self.handle_protocol)(handle, &P::GUID, &mut ptr).into_with_val(|| unsafe {
593+
(self.handle_protocol)(handle, &P::GUID, &mut ptr).into_with_val(|| {
587594
let ptr = P::mut_ptr_from_ffi(ptr) as *const UnsafeCell<P>;
588595
&*ptr
589596
})

0 commit comments

Comments
 (0)