-
-
Notifications
You must be signed in to change notification settings - Fork 14.3k
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
Merged
+128
−52
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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>)> { | ||
| 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(()) } | ||
| } | ||
| } | ||
|
|
||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
type Handle = NonNull<crate::ffi::c_void>may be a worthwhile typedef since it's used a few times in this file and inTcp4There 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.
Well, a handle typedef already exists in r_efi. It is
type Handle = *mut c_void. Maybe I should remove NonNull in all handles, but well, I started with NonNull 3 years ago, so kinda stuck with it.