Skip to content

std: sys: io: io_slice: Add UEFI types #144350

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
merged 1 commit into from
Aug 11, 2025
Merged

Conversation

Ayush1325
Copy link
Contributor

UEFI networking APIs do support vectored read/write. While the types for UDP4, UDP6, TCP4 and TCP6 are defined separately, they are essentially the same C struct. So we can map IoSlice and IoSliceMut to have the same binary representation.

Since all UEFI networking types for read/write are DSTs, IoSlice and IoSliceMut will need to be copied to the end of the transmit/receive structures. So having the same binary representation just allows us to do a single memcpy instead of having to loop and set the DST.

cc @nicholasbishop

@rustbot
Copy link
Collaborator

rustbot commented Jul 23, 2025

r? @thomcc

rustbot has assigned @thomcc.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Jul 23, 2025
@Ayush1325 Ayush1325 force-pushed the uefi-io branch 2 times, most recently from 5ee308f to 17cd61d Compare July 23, 2025 07:33
// that `IoSlice` and `IoSliceMut` are compatible with the vectored types for all the
// networking protocols.

fn to_slice<T>(val: &T) -> &[u8] {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even though this is just test code, the function is unsafe and should be marked as such.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

#[inline]
pub fn advance(&mut self, n: usize) {
let count: u32 = n.try_into().unwrap();
self.len += count;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be subtracting, not adding?

A couple other notes: I think this should use checked arithmetic since advance is supposed to panic "when trying to advance beyond the end of the slice". Also the Unix and Windows impls also have a nice "advancing IoSlice beyond its length" panic message which would be good to include here.

Something like:

    self.len = u32::try_from(n)
        .ok()
        .and_then(|n| self.len.checked_sub(n))
        .expect("advancing IoSlice beyond its length");

(Ditto for the mut advance impl)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

];

assert_eq!(to_slice(&lhs), to_slice(&rhs));
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be good to add a test or two for advance/as_slice/into_slice/as_mut_slice

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added

UEFI networking APIs do support vectored read/write. While the types for
UDP4, UDP6, TCP4 and TCP6 are defined separately, they are essentially
the same C struct. So we can map IoSlice and IoSliceMut to have the same
binary representation.

Since all UEFI networking types for read/write are DSTs, `IoSlice` and
`IoSliceMut` will need to be copied to the end of the transmit/receive
structures. So having the same binary representation just allows us to
do a single memcpy instead of having to loop and set the DST.

Signed-off-by: Ayush Singh <ayush@beagleboard.org>
@Ayush1325
Copy link
Contributor Author

ping @thomcc

@tgross35
Copy link
Contributor

@bors r=tgross35,nicholasbishop

@bors
Copy link
Collaborator

bors commented Aug 11, 2025

📌 Commit 6e75abd has been approved by tgross35,nicholasbishop

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 11, 2025
@tgross35 tgross35 assigned tgross35 and unassigned thomcc Aug 11, 2025
Zalathar added a commit to Zalathar/rust that referenced this pull request Aug 11, 2025
…olasbishop

std: sys: io: io_slice: Add UEFI types

UEFI networking APIs do support vectored read/write. While the types for UDP4, UDP6, TCP4 and TCP6 are defined separately, they are essentially the same C struct. So we can map IoSlice and IoSliceMut to have the same binary representation.

Since all UEFI networking types for read/write are DSTs, `IoSlice` and `IoSliceMut` will need to be copied to the end of the transmit/receive structures. So having the same binary representation just allows us to do a single memcpy instead of having to loop and set the DST.

cc `@nicholasbishop`
bors added a commit that referenced this pull request Aug 11, 2025
Rollup of 7 pull requests

Successful merges:

 - #143949 (Constify remaining traits/impls for `const_ops`)
 - #144330 (document assumptions about `Clone` and `Eq` traits)
 - #144350 (std: sys: io: io_slice: Add UEFI types)
 - #144558 (Point at the `Fn()` or `FnMut()` bound that coerced a closure, which caused a move error)
 - #145149 (Make config method invoke inside parse use dwn_ctx)
 - #145227 (Tweak spans providing type context on errors when involving macros)
 - #145228 (Remove unnecessary parentheses in `assert!`s)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 3724e13 into rust-lang:master Aug 11, 2025
10 checks passed
@rustbot rustbot added this to the 1.91.0 milestone Aug 11, 2025
rust-timer added a commit that referenced this pull request Aug 11, 2025
Rollup merge of #144350 - Ayush1325:uefi-io, r=tgross35,nicholasbishop

std: sys: io: io_slice: Add UEFI types

UEFI networking APIs do support vectored read/write. While the types for UDP4, UDP6, TCP4 and TCP6 are defined separately, they are essentially the same C struct. So we can map IoSlice and IoSliceMut to have the same binary representation.

Since all UEFI networking types for read/write are DSTs, `IoSlice` and `IoSliceMut` will need to be copied to the end of the transmit/receive structures. So having the same binary representation just allows us to do a single memcpy instead of having to loop and set the DST.

cc ``@nicholasbishop``
@Ayush1325 Ayush1325 deleted the uefi-io branch August 11, 2025 13:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants