-
-
Notifications
You must be signed in to change notification settings - Fork 14.2k
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: main
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 |
|---|---|---|
|
|
@@ -650,34 +650,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
660
to
+669
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( | ||
| sbp: NonNull<service_binding::Protocol>, | ||
| ) -> io::Result<NonNull<crate::ffi::c_void>> { | ||
| let mut child_handle: r_efi::efi::Handle = crate::ptr::null_mut(); | ||
|
|
@@ -691,17 +695,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.
According to the UEFI spec,
UseDefaultAddressoverrides only theStationAddressandSubnetMask: it does not override theStationPort. However the present logic provides no mechanism by which the caller can elect toUseDefaultAddresswhilst providing aStationPort(such as would be useful when configuring a passive instance to accept inbound connections).With this suggestion, callers can configure such a passive instance by providing a
station_addressofSome(SocketAddrV4::new(Ipv4Addr::UNSPECIFIED, port)).