Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 11 additions & 15 deletions src/table/boot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -776,12 +776,10 @@ impl BootServices {
}
}

status.into_with_val(|| {
let protocols = unsafe { slice::from_raw_parts_mut(protocols as *mut &Guid, count) };
ProtocolsPerHandle {
boot_services: self,
protocols,
}
status.into_with_val(|| ProtocolsPerHandle {
boot_services: self,
protocols: protocols as *mut &Guid,
count,
})
}

Expand Down Expand Up @@ -1421,25 +1419,23 @@ pub struct ProtocolsPerHandle<'a> {
// `free_pool`, so keep a reference to boot services for that purpose.
boot_services: &'a BootServices,

// This is mutable so that it can later be free'd with `free_pool`. Users
// should only get an immutable reference though, so the field is not
// public.
protocols: &'a mut [&'a Guid],
protocols: *mut &'a Guid,
count: usize,
}

impl<'a> Drop for ProtocolsPerHandle<'a> {
fn drop(&mut self) {
// Ignore the result, we can't do anything about an error here.
let _ = self
.boot_services
.free_pool(self.protocols.as_mut_ptr() as *mut u8);
let _ = self.boot_services.free_pool(self.protocols as *mut u8);
}
}

impl<'a> ProtocolsPerHandle<'a> {
/// Get the protocol interface [`Guids`][Guid] that are installed on the
/// [`Handle`].
pub fn protocols(&self) -> &[&Guid] {
self.protocols
pub fn protocols<'b>(&'b self) -> &'b [&'a Guid] {
// convert raw pointer to slice here so that we can get
// appropriate lifetime of the slice.
unsafe { slice::from_raw_parts(self.protocols, self.count) }
}
}