Skip to content

Commit 4d6aabe

Browse files
committed
Apply suggestions from @nicholasbishop
Adjust changelog Rename `SearchKey` to `ProtocolSearchKey` and move to `boot.rs`. Fixup doclinks. Adjust signatures of the `[re/un]install_protocol_interface` functions
1 parent 94b5ee1 commit 4d6aabe

File tree

4 files changed

+44
-42
lines changed

4 files changed

+44
-42
lines changed

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
`BootServices::uninstall_protocol_interface`, and
2121
`BootServices::reinstall_protocol_interface`.
2222
- Added `BootServices::register_protocol_notify`.
23-
- Added `SearchType::ByRegisterNotify` and `SearchKey` type.
23+
- Added `SearchType::ByRegisterNotify`and `ProtocolSearchKey`.
2424

2525
### Changed
2626

src/data_types/mod.rs

-6
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,6 @@ pub type PhysicalAddress = u64;
117117
/// of target platform.
118118
pub type VirtualAddress = u64;
119119

120-
/// Opaque pointer returned by `BootServices::register_protocol_notify() to be used
121-
/// with `BootServices::locate_handle` as the `key` parameter.
122-
#[derive(Debug, Clone, Copy)]
123-
#[repr(transparent)]
124-
pub struct SearchKey(NonNull<c_void>);
125-
126120
mod guid;
127121
pub use self::guid::Guid;
128122
pub use self::guid::{unsafe_guid, Identify};

src/table/boot.rs

+34-31
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! UEFI services available during boot.
22
33
use super::{Header, Revision};
4-
use crate::data_types::{Align, PhysicalAddress, SearchKey, VirtualAddress};
4+
use crate::data_types::{Align, PhysicalAddress, VirtualAddress};
55
use crate::proto::device_path::{DevicePath, FfiDevicePath};
66
#[cfg(feature = "exts")]
77
use crate::proto::{loaded_image::LoadedImage, media::fs::SimpleFileSystem};
@@ -129,31 +129,34 @@ pub struct BootServices {
129129

130130
// Protocol handlers
131131
install_protocol_interface: unsafe extern "efiapi" fn(
132-
handle: NonNull<Option<Handle>>,
132+
handle: &mut Option<Handle>,
133133
guid: &Guid,
134134
interface_type: InterfaceType,
135-
interface: Option<NonNull<c_void>>,
135+
interface: *mut c_void,
136136
) -> Status,
137137
reinstall_protocol_interface: unsafe extern "efiapi" fn(
138138
handle: Handle,
139139
protocol: &Guid,
140-
old_interface: Option<NonNull<c_void>>,
141-
new_interface: Option<NonNull<c_void>>,
140+
old_interface: *mut c_void,
141+
new_interface: *mut c_void,
142142
) -> Status,
143143
uninstall_protocol_interface: unsafe extern "efiapi" fn(
144144
handle: Handle,
145145
protocol: &Guid,
146-
interface: Option<NonNull<c_void>>,
146+
interface: *mut c_void,
147147
) -> Status,
148148
handle_protocol:
149149
extern "efiapi" fn(handle: Handle, proto: &Guid, out_proto: &mut *mut c_void) -> Status,
150150
_reserved: usize,
151-
register_protocol_notify:
152-
extern "efiapi" fn(protocol: &Guid, event: Event, registration: *mut SearchKey) -> Status,
151+
register_protocol_notify: extern "efiapi" fn(
152+
protocol: &Guid,
153+
event: Event,
154+
registration: *mut ProtocolSearchKey,
155+
) -> Status,
153156
locate_handle: unsafe extern "efiapi" fn(
154157
search_ty: i32,
155158
proto: Option<&Guid>,
156-
key: Option<SearchKey>,
159+
key: Option<ProtocolSearchKey>,
157160
buf_sz: &mut usize,
158161
buf: *mut MaybeUninit<Handle>,
159162
) -> Status,
@@ -237,7 +240,7 @@ pub struct BootServices {
237240
locate_handle_buffer: unsafe extern "efiapi" fn(
238241
search_ty: i32,
239242
proto: Option<&Guid>,
240-
key: Option<SearchKey>,
243+
key: Option<ProtocolSearchKey>,
241244
no_handles: &mut usize,
242245
buf: &mut *mut Handle,
243246
) -> Status,
@@ -634,7 +637,7 @@ impl BootServices {
634637
}
635638

636639
/// 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."
640+
/// one will be created and added to the list of handles in the system and then returned.
638641
///
639642
/// When a protocol interface is installed, firmware will call all functions that have registered
640643
/// to wait for that interface to be installed.
@@ -646,14 +649,10 @@ impl BootServices {
646649
&self,
647650
mut handle: Option<Handle>,
648651
protocol: &Guid,
649-
interface: Option<NonNull<c_void>>,
652+
interface: *mut c_void,
650653
) -> 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-
655654
((self.install_protocol_interface)(
656-
handle_ptr,
655+
&mut handle,
657656
protocol,
658657
InterfaceType::NATIVE_INTERFACE,
659658
interface,
@@ -678,8 +677,8 @@ impl BootServices {
678677
&self,
679678
handle: Handle,
680679
protocol: &Guid,
681-
old_interface: Option<NonNull<c_void>>,
682-
new_interface: Option<NonNull<c_void>>,
680+
old_interface: *mut c_void,
681+
new_interface: *mut c_void,
683682
) -> Result<()> {
684683
(self.reinstall_protocol_interface)(handle, protocol, old_interface, new_interface).into()
685684
}
@@ -698,7 +697,7 @@ impl BootServices {
698697
&self,
699698
handle: Handle,
700699
protocol: &Guid,
701-
interface: Option<NonNull<c_void>>,
700+
interface: *mut c_void,
702701
) -> Result<()> {
703702
(self.uninstall_protocol_interface)(handle, protocol, interface).into()
704703
}
@@ -752,12 +751,17 @@ impl BootServices {
752751
&self,
753752
protocol: &Guid,
754753
event: Event,
755-
) -> Result<(Event, SearchKey)> {
756-
let mut key: MaybeUninit<SearchKey> = MaybeUninit::uninit();
754+
) -> Result<(Event, SearchType)> {
755+
let mut key: MaybeUninit<ProtocolSearchKey> = MaybeUninit::uninit();
757756
// Safety: we clone `event` a couple times, but there will be only one left once we return.
758757
unsafe { (self.register_protocol_notify)(protocol, event.unsafe_clone(), key.as_mut_ptr()) }
759758
// Safety: as long as this call is successful, `key` will be valid.
760-
.into_with_val(|| unsafe { (event.unsafe_clone(), key.assume_init()) })
759+
.into_with_val(|| unsafe {
760+
(
761+
event.unsafe_clone(),
762+
SearchType::ByRegisterNotify(key.assume_init()),
763+
)
764+
})
761765
}
762766

763767
/// Enumerates all handles installed on the system which match a certain query.
@@ -1840,7 +1844,7 @@ pub enum SearchType<'guid> {
18401844
ByProtocol(&'guid Guid),
18411845
/// Return all handles that implement a protocol when an interface for that protocol
18421846
/// is (re)installed.
1843-
ByRegisterNotify(SearchKey),
1847+
ByRegisterNotify(ProtocolSearchKey),
18441848
}
18451849

18461850
impl<'guid> SearchType<'guid> {
@@ -1850,13 +1854,6 @@ impl<'guid> SearchType<'guid> {
18501854
}
18511855
}
18521856

1853-
impl SearchType<'_> {
1854-
/// Constructs a new search type from a SearchKey.
1855-
pub fn from_search_key(key: SearchKey) -> Self {
1856-
SearchType::ByRegisterNotify(key)
1857-
}
1858-
}
1859-
18601857
bitflags! {
18611858
/// Flags describing the type of an UEFI event and its attributes.
18621859
pub struct EventType: u32 {
@@ -1970,3 +1967,9 @@ pub enum InterfaceType: i32 => {
19701967
NATIVE_INTERFACE = 0,
19711968
}
19721969
}
1970+
1971+
/// Opaque pointer returned by [`BootServices::register_protocol_notify`] to be used
1972+
/// with [`BootServices::locate_handle`] via [`SearchType::ByRegisterNotify`].
1973+
#[derive(Debug, Clone, Copy)]
1974+
#[repr(transparent)]
1975+
pub struct ProtocolSearchKey(NonNull<c_void>);

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

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use core::ffi::c_void;
2-
use core::ptr::NonNull;
2+
use core::ptr::{self, NonNull};
33

44
use uefi::proto::Protocol;
55
use uefi::table::boot::{BootServices, EventType, SearchType, TimerTrigger, Tpl};
@@ -108,7 +108,7 @@ fn test_install_protocol_interface(bt: &BootServices) {
108108
info!("Installing TestProtocol");
109109

110110
let _ = unsafe {
111-
bt.install_protocol_interface(None, &TestProtocol::GUID, None)
111+
bt.install_protocol_interface(None, &TestProtocol::GUID, ptr::null_mut())
112112
.expect("Failed to install protocol interface")
113113
};
114114

@@ -125,7 +125,12 @@ fn test_reinstall_protocol_interface(bt: &BootServices) {
125125
.handles()[0];
126126

127127
unsafe {
128-
let _ = bt.reinstall_protocol_interface(handle, &TestProtocol::GUID, None, None);
128+
let _ = bt.reinstall_protocol_interface(
129+
handle,
130+
&TestProtocol::GUID,
131+
ptr::null_mut(),
132+
ptr::null_mut(),
133+
);
129134
}
130135
}
131136

@@ -137,7 +142,7 @@ fn test_uninstall_protocol_interface(bt: &BootServices) {
137142
.handles()[0];
138143

139144
unsafe {
140-
bt.uninstall_protocol_interface(handle, &TestProtocol::GUID, None)
145+
bt.uninstall_protocol_interface(handle, &TestProtocol::GUID, ptr::null_mut())
141146
.expect("Failed to uninstall protocol interface");
142147
}
143148
}

0 commit comments

Comments
 (0)