Skip to content

Commit a65ba3e

Browse files
committed
uefi: protocols: cleanup [re_,un_]install_protocol_interface()
1 parent 44107eb commit a65ba3e

4 files changed

Lines changed: 59 additions & 9 deletions

File tree

uefi-test-runner/src/boot/misc.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ fn test_install_protocol_interface() {
164164
unsafe { alloc.write(TestProtocol { data: 123 }) };
165165

166166
let _ = unsafe {
167-
boot::install_protocol_interface(None, &TestProtocol::GUID, alloc.cast())
167+
boot::install_protocol_interface::<TestProtocol>(None, alloc.cast())
168168
.expect("Failed to install protocol interface")
169169
};
170170

@@ -178,9 +178,8 @@ fn test_reinstall_protocol_interface() {
178178
.expect("Failed to find protocol to uninstall")[0];
179179

180180
unsafe {
181-
let _ = boot::reinstall_protocol_interface(
181+
let _ = boot::reinstall_protocol_interface::<TestProtocol>(
182182
handle,
183-
&TestProtocol::GUID,
184183
ptr::null_mut(),
185184
ptr::null_mut(),
186185
);

uefi-test-runner/src/proto/load.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,15 @@ impl CustomLoadFile2Protocol {
6161

6262
unsafe fn install_protocol(handle: Handle, guid: Guid, protocol: &mut CustomLoadFile2Protocol) {
6363
unsafe {
64-
boot::install_protocol_interface(Some(handle), &guid, addr_of!(*protocol).cast()).unwrap();
64+
boot::install_protocol_interface_by_guid(Some(handle), &guid, addr_of!(*protocol).cast())
65+
.unwrap();
6566
}
6667
}
6768

6869
unsafe fn uninstall_protocol(handle: Handle, guid: Guid, protocol: &mut CustomLoadFile2Protocol) {
6970
unsafe {
70-
boot::uninstall_protocol_interface(handle, &guid, addr_of!(*protocol).cast()).unwrap();
71+
boot::uninstall_protocol_interface_by_guid(handle, &guid, addr_of!(*protocol).cast())
72+
.unwrap();
7173
}
7274
}
7375

uefi/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
- Added `proto::media::block::BlockIO2`.
1010
- Added `boot::test_protocol_by_guid()`
1111
- Added `boot::register_protocol_notify_by_guid()`
12+
- Added `boot::[re_,un_]install_protocol_interface_by_guid()` functions.
1213

1314
## Changed
1415
- Changed ordering of `proto::pci::PciIoAddress` to (bus -> dev -> fun -> reg -> ext_reg).
@@ -19,6 +20,9 @@
1920
an owned value of type `HttpConfigData`
2021
- **Breaking**: `boot::register_protocol_notify()` now follows our generic-based
2122
API and now longer consumes a `&Guid` parameter.
23+
- **Breaking:**`boot::[re_,un_]install_protocol_interface()` no longer consume a
24+
`&Guid` parameter but instead follow our generic type-based API. For example:
25+
`install_protocol_interface<DevicePath>(handle, interface)`.
2226

2327
# uefi - v0.36.1 (2025-11-05)
2428

uefi/src/boot.rs

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,12 @@ pub fn disconnect_controller(
718718
/// When a protocol interface is installed, firmware will call all functions
719719
/// that have registered to wait for that interface to be installed.
720720
///
721-
/// If `handle` is `None`, a new handle will be created and returned.
721+
/// # Arguments
722+
///
723+
/// - `handle`: Either `None` to allocate a new handle or an existing handle.
724+
/// - `interface`: The protocol implementation. The memory backing the
725+
/// implementation **must live as long as the handle!**. Callers need to
726+
/// ensure a matching lifetime!
722727
///
723728
/// # Safety
724729
///
@@ -728,7 +733,20 @@ pub fn disconnect_controller(
728733
///
729734
/// * [`Status::OUT_OF_RESOURCES`]: failed to allocate a new handle.
730735
/// * [`Status::INVALID_PARAMETER`]: this protocol is already installed on the handle.
731-
pub unsafe fn install_protocol_interface(
736+
pub unsafe fn install_protocol_interface<P: ProtocolPointer + ?Sized>(
737+
handle: Option<Handle>,
738+
interface: *const c_void,
739+
) -> Result<Handle> {
740+
unsafe { install_protocol_interface_by_guid(handle, &P::GUID, interface) }
741+
}
742+
743+
/// Variant of [`install_protocol_interface`] that consumes the [`Guid`] as
744+
/// parameter.
745+
///
746+
/// # Safety
747+
///
748+
/// See safety section in [`install_protocol_interface`].
749+
pub unsafe fn install_protocol_interface_by_guid(
732750
handle: Option<Handle>,
733751
protocol: &Guid,
734752
interface: *const c_void,
@@ -766,7 +784,21 @@ pub unsafe fn install_protocol_interface(
766784
///
767785
/// * [`Status::NOT_FOUND`]: the old interface was not found on the handle.
768786
/// * [`Status::ACCESS_DENIED`]: the old interface is still in use and cannot be uninstalled.
769-
pub unsafe fn reinstall_protocol_interface(
787+
pub unsafe fn reinstall_protocol_interface<P: ProtocolPointer + ?Sized>(
788+
handle: Handle,
789+
old_interface: *const c_void,
790+
new_interface: *const c_void,
791+
) -> Result<()> {
792+
unsafe { reinstall_protocol_interface_by_guid(handle, &P::GUID, old_interface, new_interface) }
793+
}
794+
795+
/// Variant of [`reinstall_protocol_interface`] that consumes the [`Guid`] as
796+
/// parameter.
797+
///
798+
/// # Safety
799+
///
800+
/// See safety section in [`reinstall_protocol_interface`].
801+
pub unsafe fn reinstall_protocol_interface_by_guid(
770802
handle: Handle,
771803
protocol: &Guid,
772804
old_interface: *const c_void,
@@ -796,7 +828,20 @@ pub unsafe fn reinstall_protocol_interface(
796828
///
797829
/// * [`Status::NOT_FOUND`]: the interface was not found on the handle.
798830
/// * [`Status::ACCESS_DENIED`]: the interface is still in use and cannot be uninstalled.
799-
pub unsafe fn uninstall_protocol_interface(
831+
pub unsafe fn uninstall_protocol_interface<P: ProtocolPointer + ?Sized>(
832+
handle: Handle,
833+
interface: *const c_void,
834+
) -> Result<()> {
835+
unsafe { uninstall_protocol_interface_by_guid(handle, &P::GUID, interface) }
836+
}
837+
838+
/// Variant of [`uninstall_protocol_interface`] that consumes the [`Guid`] as
839+
/// parameter.
840+
///
841+
/// # Safety
842+
///
843+
/// See safety section in [`uninstall_protocol_interface`].
844+
pub unsafe fn uninstall_protocol_interface_by_guid(
800845
handle: Handle,
801846
protocol: &Guid,
802847
interface: *const c_void,

0 commit comments

Comments
 (0)