Skip to content
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

Rollup of 12 pull requests #138636

Closed
wants to merge 15 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Implement read_buf for Hermit
  • Loading branch information
thaliaarchi committed Mar 17, 2025
commit c5fc1931a05f48fe3b4adf213ad3fcefb4e4434b
2 changes: 1 addition & 1 deletion library/std/src/sys/fs/hermit.rs
Original file line number Diff line number Diff line change
@@ -396,7 +396,7 @@ impl File {
}

pub fn read_buf(&self, cursor: BorrowedCursor<'_>) -> io::Result<()> {
crate::io::default_read_buf(|buf| self.read(buf), cursor)
self.0.read_buf(cursor)
}

pub fn write(&self, buf: &[u8]) -> io::Result<usize> {
17 changes: 16 additions & 1 deletion library/std/src/sys/pal/hermit/fd.rs
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@

use super::hermit_abi;
use crate::cmp;
use crate::io::{self, IoSlice, IoSliceMut, Read, SeekFrom};
use crate::io::{self, BorrowedCursor, IoSlice, IoSliceMut, Read, SeekFrom};
use crate::os::hermit::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, OwnedFd, RawFd};
use crate::sys::{cvt, unsupported};
use crate::sys_common::{AsInner, FromInner, IntoInner};
@@ -23,6 +23,21 @@ impl FileDesc {
Ok(result as usize)
}

pub fn read_buf(&self, mut buf: BorrowedCursor<'_>) -> io::Result<()> {
// SAFETY: The `read` syscall does not read from the buffer, so it is
// safe to use `&mut [MaybeUninit<u8>]`.
let result = cvt(unsafe {
hermit_abi::read(
self.fd.as_raw_fd(),
buf.as_mut().as_mut_ptr() as *mut u8,
buf.capacity(),
)
})?;
// SAFETY: Exactly `result` bytes have been filled.
unsafe { buf.advance_unchecked(result as usize) };
Ok(())
}

pub fn read_vectored(&self, bufs: &mut [IoSliceMut<'_>]) -> io::Result<usize> {
let ret = cvt(unsafe {
hermit_abi::readv(
5 changes: 1 addition & 4 deletions library/std/src/sys/stdio/unix.rs
Original file line number Diff line number Diff line change
@@ -3,9 +3,7 @@ use hermit_abi::{EBADF, STDERR_FILENO, STDIN_FILENO, STDOUT_FILENO};
#[cfg(target_family = "unix")]
use libc::{EBADF, STDERR_FILENO, STDIN_FILENO, STDOUT_FILENO};

#[cfg(target_family = "unix")]
use crate::io::BorrowedCursor;
use crate::io::{self, IoSlice, IoSliceMut};
use crate::io::{self, BorrowedCursor, IoSlice, IoSliceMut};
use crate::mem::ManuallyDrop;
#[cfg(target_os = "hermit")]
use crate::os::hermit::io::FromRawFd;
@@ -28,7 +26,6 @@ impl io::Read for Stdin {
unsafe { ManuallyDrop::new(FileDesc::from_raw_fd(STDIN_FILENO)).read(buf) }
}

#[cfg(not(target_os = "hermit"))]
fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> io::Result<()> {
unsafe { ManuallyDrop::new(FileDesc::from_raw_fd(STDIN_FILENO)).read_buf(buf) }
}
Loading