-
-
Notifications
You must be signed in to change notification settings - Fork 14.4k
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
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 |
|---|---|---|
|
|
@@ -651,34 +651,38 @@ 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) | ||
| /// | ||
| /// # Invariant | ||
| /// - `handle` must always be a valid UEFI handle corresponding to the `service_guid`. | ||
| /// - Copying `ServiceProtocol` is sound as long as `handle` remains valid. | ||
| /// - For most service binding protocols (in edk2 implementations), such handles remain valid | ||
| /// for the lifetime of the UEFI environment — effectively `'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
661
to
+670
Contributor
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.
Contributor
Author
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. Well, a handle typedef already exists in r_efi. It is |
||
| let handles = locate_handles(service_guid)?; | ||
|
|
||
| for handle in handles { | ||
| if let Ok(protocol) = open_protocol::<service_binding::Protocol>(handle, service_guid) { | ||
| let Ok(child_handle) = Self::create_child(protocol) else { | ||
| continue; | ||
| }; | ||
|
|
||
| return Ok(Self { service_guid, handle, child_handle }); | ||
| if let Ok(child_handle) = unsafe { Self::create_child(protocol) } { | ||
| 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( | ||
| // SAFETY: sbp must be a valid service binding protocol pointer | ||
| unsafe fn create_child( | ||
|
Comment on lines
+684
to
+685
Contributor
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. For future reference, the convention is that |
||
| sbp: NonNull<service_binding::Protocol>, | ||
| ) -> io::Result<NonNull<crate::ffi::c_void>> { | ||
| let mut child_handle: r_efi::efi::Handle = crate::ptr::null_mut(); | ||
|
|
@@ -692,17 +696,17 @@ 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()) | ||
| }; | ||
| } | ||
| // SAFETY: Child handle must be allocated by the current service binding protocol and must be | ||
| // valid. | ||
| pub(crate) unsafe fn destroy_child( | ||
| &self, | ||
| handle: NonNull<crate::ffi::c_void>, | ||
| ) -> io::Result<()> { | ||
| let sbp = open_protocol::<service_binding::Protocol>(self.handle, self.service_guid)?; | ||
|
|
||
| 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(()) } | ||
| } | ||
| } | ||
|
|
||
|
|
||
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
SAFETYcomment 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 thehandlefield. Then:unsafecalls that usehandle, you can say they are valid by the invariantServiceProtocolis 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?
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 spec does not prevent it, but most implementations are based on edk2, which has it valid for UEFI lifetime, i.e.
'static.