Skip to content

Commit 89688e6

Browse files
committed
Correct implementation of install_protocol_interface
1 parent 1855be5 commit 89688e6

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/table/boot.rs

+10-6
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ pub struct BootServices {
129129

130130
// Protocol handlers
131131
install_protocol_interface: unsafe extern "efiapi" fn(
132-
handle: Option<&Handle>,
132+
handle: NonNull<Option<Handle>>,
133133
guid: &Guid,
134134
interface_type: InterfaceType,
135135
interface: Option<NonNull<c_void>>,
@@ -633,8 +633,8 @@ impl BootServices {
633633
}
634634
}
635635

636-
/// Installs a protocol interface on a device handle. If `handle` is `None`, one will be
637-
/// created and added to the list of handles in the system and then returned.
636+
/// Installs a protocol interface on a device handle. If the inner `Option` in `handle` is `None`,
637+
/// one will be created and added to the list of handles in the system and then returned."
638638
///
639639
/// When a protocol interface is installed, firmware will call all functions that have registered
640640
/// to wait for that interface to be installed.
@@ -644,19 +644,23 @@ impl BootServices {
644644
/// The caller is responsible for ensuring that they pass a valid `Guid` for `protocol`.
645645
pub unsafe fn install_protocol_interface(
646646
&self,
647-
handle: Option<&Handle>,
647+
mut handle: Option<Handle>,
648648
protocol: &Guid,
649649
interface: Option<NonNull<c_void>>,
650650
) -> Result<Handle> {
651+
// Safety: The given pointer is guaranteed to be non-null, even though what it's indirectly pointing to
652+
// may be null, thus this is safe
653+
let handle_ptr = NonNull::new(&mut handle as *mut _).unwrap_unchecked();
654+
651655
((self.install_protocol_interface)(
652-
handle,
656+
handle_ptr,
653657
protocol,
654658
InterfaceType::NATIVE_INTERFACE,
655659
interface,
656660
))
657661
// this `unwrapped_unchecked` is safe, `handle` is guaranteed to be Some() if this call is
658662
// successful
659-
.into_with_val(|| *handle.unwrap_unchecked())
663+
.into_with_val(|| handle.unwrap_unchecked())
660664
}
661665

662666
/// Reinstalls a protocol interface on a device handle. `old_interface` is replaced with `new_interface`.

0 commit comments

Comments
 (0)