-
Notifications
You must be signed in to change notification settings - Fork 13.8k
std: sys: net: uefi: tcp: Initial TcpListener support #145339
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -646,14 +646,21 @@ pub(crate) fn get_device_path_from_map(map: &Path) -> io::Result<BorrowedDeviceP | |
|
||
/// Helper for UEFI Protocols which are created and destroyed using | ||
/// [EFI_SERVICE_BINDING_PROTOCOL](https://uefi.org/specs/UEFI/2.11/11_Protocols_UEFI_Driver_Model.html#efi-service-binding-protocol) | ||
/// | ||
/// SAFETY: Copying ServiceProtocol is safe as long as handle is valid. For most service binding | ||
/// protocols, at least in edk2 implementations, the lifetime of these handles will be till UEFI is | ||
/// active, i.e. 'static | ||
#[derive(Clone, Copy)] | ||
pub(crate) struct ServiceProtocol { | ||
service_guid: r_efi::efi::Guid, | ||
handle: NonNull<crate::ffi::c_void>, | ||
child_handle: NonNull<crate::ffi::c_void>, | ||
} | ||
|
||
impl ServiceProtocol { | ||
pub(crate) fn open(service_guid: r_efi::efi::Guid) -> io::Result<Self> { | ||
/// Open a child handle on a service_binding protocol. | ||
pub(crate) fn open( | ||
service_guid: r_efi::efi::Guid, | ||
) -> io::Result<(Self, NonNull<crate::ffi::c_void>)> { | ||
Comment on lines
654
to
+663
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
let handles = locate_handles(service_guid)?; | ||
|
||
for handle in handles { | ||
|
@@ -662,17 +669,13 @@ impl ServiceProtocol { | |
continue; | ||
}; | ||
|
||
return Ok(Self { service_guid, handle, child_handle }); | ||
return Ok((Self { service_guid, handle }, child_handle)); | ||
} | ||
} | ||
|
||
Err(io::const_error!(io::ErrorKind::NotFound, "no service binding protocol found")) | ||
} | ||
|
||
pub(crate) fn child_handle(&self) -> NonNull<crate::ffi::c_void> { | ||
self.child_handle | ||
} | ||
|
||
fn create_child( | ||
sbp: NonNull<service_binding::Protocol>, | ||
) -> io::Result<NonNull<crate::ffi::c_void>> { | ||
Comment on lines
679
to
681
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually I think this needs to be |
||
|
@@ -687,17 +690,13 @@ impl ServiceProtocol { | |
.ok_or(const_error!(io::ErrorKind::Other, "null child handle")) | ||
} | ||
} | ||
} | ||
|
||
impl Drop for ServiceProtocol { | ||
fn drop(&mut self) { | ||
if let Ok(sbp) = open_protocol::<service_binding::Protocol>(self.handle, self.service_guid) | ||
{ | ||
// SAFETY: Child handle must be allocated by the current service binding protocol. | ||
let _ = unsafe { | ||
((*sbp.as_ptr()).destroy_child)(sbp.as_ptr(), self.child_handle.as_ptr()) | ||
}; | ||
} | ||
pub(crate) fn destroy_child(&self, handle: NonNull<crate::ffi::c_void>) -> io::Result<()> { | ||
let sbp = open_protocol::<service_binding::Protocol>(self.handle, self.service_guid)?; | ||
|
||
// SAFETY: Child handle must be allocated by the current service binding protocol. | ||
let r = unsafe { ((*sbp.as_ptr()).destroy_child)(sbp.as_ptr(), handle.as_ptr()) }; | ||
if r.is_error() { Err(crate::io::Error::from_raw_os_error(r.as_usize())) } else { Ok(()) } | ||
} | ||
Comment on lines
+694
to
700
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs to be unsafe if the precondition of the Also, is it safe to call |
||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
SAFETY
comment shouldn't be here since duplicating this struct doesn't do anything by itself. If the handle is expected to be valid for'static
, this would be better expressed as an/// Invariant: ...
comment on thehandle
field. Then:unsafe
calls that usehandle
, you can say they are valid by the invariantServiceProtocol
is constructed, you can add an// INVARIANT:
comment saying why they meet that invariant. And call out the assumption.Are there cases where a relevant handle here will disappear earlier that we need to worry about?