-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
Tracking issue for optional io::Read
/io::Write
methods
#136756
Labels
C-tracking-issue
Category: An issue tracking the progress of sth. like the implementation of an RFC
Comments
a1phyr
added a commit
to a1phyr/rust
that referenced
this issue
Feb 10, 2025
a1phyr
added a commit
to a1phyr/rust
that referenced
this issue
Feb 10, 2025
GuillaumeGomez
added a commit
to GuillaumeGomez/rust
that referenced
this issue
Feb 12, 2025
Implement `read*_exact` for `std:io::repeat` cc rust-lang#136756
jhpratt
added a commit
to jhpratt/rust
that referenced
this issue
Feb 13, 2025
Implement `read*_exact` for `std:io::repeat` cc rust-lang#136756
jhpratt
added a commit
to jhpratt/rust
that referenced
this issue
Feb 13, 2025
Implement `read*_exact` for `std:io::repeat` cc rust-lang#136756
rust-timer
added a commit
to rust-lang-ci/rust
that referenced
this issue
Feb 13, 2025
Rollup merge of rust-lang#136818 - a1phyr:io_repeat_exact, r=jhpratt Implement `read*_exact` for `std:io::repeat` cc rust-lang#136756
This was referenced Feb 14, 2025
thaliaarchi
added a commit
to thaliaarchi/hermit-kernel
that referenced
this issue
Feb 19, 2025
Currently, when using an uninitialized buffer for `read`, as would be typical in C or required for `Read::read_buf`, it is casted from `*mut u8` at the FFI boundary in `sys_read`/`sys_readv` to a `&[u8]`. I think this is unsound. Instead, use `&[MaybeUninit<u8>]` internally. This enables implementing `std::io::Read::read_buf` for `std::fs::File` and `std::io::Stdin` on Hermit. That effort is tracked in rust-lang/rust#136756.
thaliaarchi
added a commit
to thaliaarchi/hermit-kernel
that referenced
this issue
Feb 19, 2025
Currently, when using an uninitialized buffer for `read`, as would be typical in C or required for `Read::read_buf`, it is casted from `*mut u8` at the FFI boundary in `sys_read`/`sys_readv` to a `&[u8]`. I think this is unsound. Instead, use `&[MaybeUninit<u8>]` internally. I use this instead of `core::io::BorrowedCursor<'_>`, because there are currently no cases where the initialized portion needs to be separately tracked. This enables implementing `std::io::Read::read_buf` for `std::fs::File` and `std::io::Stdin` on Hermit. That effort is tracked in rust-lang/rust#136756.
thaliaarchi
added a commit
to thaliaarchi/hermit-kernel
that referenced
this issue
Feb 19, 2025
Currently, when using an uninitialized buffer for `read`, as would be typical in C or required for `Read::read_buf`, it is casted from `*mut u8` at the FFI boundary in `sys_read`/`sys_readv` to a `&[u8]`. I think this is unsound. Instead, use `&[MaybeUninit<u8>]` internally. I use this instead of `core::io::BorrowedCursor<'_>`, because there are currently no cases where the initialized portion needs to be separately tracked. This enables implementing `std::io::Read::read_buf` for `std::fs::File` and `std::io::Stdin` on Hermit. That effort is tracked in rust-lang/rust#136756.
This was referenced Feb 19, 2025
matthiaskrgr
added a commit
to matthiaskrgr/rust
that referenced
this issue
Feb 21, 2025
…si-stdin, r=alexcrichton Implement `read_buf` for WASI stdin `WasiFd::read_buf` already exists. Simply use it in `Stdin`. cc `@alexcrichton` Tracked in rust-lang#136756
rust-timer
added a commit
to rust-lang-ci/rust
that referenced
this issue
Feb 21, 2025
Rollup merge of rust-lang#137353 - thaliaarchi:io-optional-methods/wasi-stdin, r=alexcrichton Implement `read_buf` for WASI stdin `WasiFd::read_buf` already exists. Simply use it in `Stdin`. cc `@alexcrichton` Tracked in rust-lang#136756
github-actions bot
pushed a commit
to model-checking/verify-rust-std
that referenced
this issue
Feb 22, 2025
github-actions bot
pushed a commit
to tautschnig/verify-rust-std
that referenced
this issue
Feb 22, 2025
github-actions bot
pushed a commit
to thanhnguyen-aws/verify-rust-std
that referenced
this issue
Feb 22, 2025
tgross35
added a commit
to tgross35/rust
that referenced
this issue
Feb 24, 2025
…vm, r=Noratrieb Implement `read_buf` for zkVM stdin For the zkVM, even when a guest buffer is uninitialized, from the host's perspective it is just a normal piece of memory which was initialized before letting the guest write into it. This makes `sys_read` safe to use with an uninitialized buffer. See risc0/risc0#2853. cc `@bobbobbio,` `@flaub` r? `@Noratrieb` Tracked in rust-lang#136756
rust-timer
added a commit
to rust-lang-ci/rust
that referenced
this issue
Feb 25, 2025
Rollup merge of rust-lang#137349 - thaliaarchi:io-optional-methods/zkvm, r=Noratrieb Implement `read_buf` for zkVM stdin For the zkVM, even when a guest buffer is uninitialized, from the host's perspective it is just a normal piece of memory which was initialized before letting the guest write into it. This makes `sys_read` safe to use with an uninitialized buffer. See risc0/risc0#2853. cc `@bobbobbio,` `@flaub` r? `@Noratrieb` Tracked in rust-lang#136756
github-actions bot
pushed a commit
to rust-lang/miri
that referenced
this issue
Feb 26, 2025
…atrieb Implement `read_buf` for zkVM stdin For the zkVM, even when a guest buffer is uninitialized, from the host's perspective it is just a normal piece of memory which was initialized before letting the guest write into it. This makes `sys_read` safe to use with an uninitialized buffer. See risc0/risc0#2853. cc `@bobbobbio,` `@flaub` r? `@Noratrieb` Tracked in rust-lang/rust#136756
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
C-tracking-issue
Category: An issue tracking the progress of sth. like the implementation of an RFC
This tracks the status of specializing optional methods in implementations of
io::Read
andio::Write
in the standard library.Read
andWrite
have many methods which are provided by default, and many implementors do not override them, which can be problematic in some cases. Platform abstractions for stdio are particularly lacking; most of which do not haveread_buf
, so the buffer is forced to be initialized, and some platforms which support it might be missing vectored read/write. Since the standard library is general, this should be consistent.I am working on addressing these gaps and have created this issue to track progress for myself and reviewers. I am still a new contributor to Rust, so please let me know if I have missed something about the process.
This surveys of all implementations of
io::Read
andio::Write
inrust-lang/rust
, including for private types, by searching for\b(Read|Write) for
in .rs files. This should have no false negatives, as opposed to viewing references, which would omit other targets.Additionally, I include all platform implementations of
File
. These defineread
,read_buf
,read_vectored
,is_read_vectored
,write
,write_vectored
,is_write_vectored
, andflush
as inherent methods. Since the other methods are not currently supported with this scheme, I have marked them with N/A.Implementation history
PRs created for this effort and some relevant PRs from earlier:
io::Chain
#105917io::Read
andio::Write
methods forVecDeque<u8>
and&[u8]
#110608Read::read_buf_exact
#122393Read
implementations #122441UnixStream
: overrideread_buf
#123084read_exact
andread_buf_exact
forVecDeque
#132039Read
/Write
methods for stdio #136769read*_exact
forstd:io::repeat
#136818write_all_vectored
forVecDeque
#136819io::Empty
andio::Sink
#137051Write
methods for cursor-like types #137107read_buf
for zkVM stdin #137349read_buf
for WASI stdin #137353read_buf
and vectored read/write for SGX stdio #137355Read
impl Read for T
buf
buf_exact
vectored
exact
to_end
to_string
&mut Read
Box<Read>
&[u8]
VecDeque<u8>
std::io::Chain<Read, Read>
std::io::Take<Read>
std::io::Empty
std::io::Repeat
std::io::Cursor<AsRef<[u8]>>
std::io::BufReader<Read>
std::net::TcpStream
&std::net::TcpStream
std::os::unix::net::UnixStream
&std::os::unix::net::UnixStream
13&std::sys::net::windows::Socket
std::io::PipeReader
&std::io::PipeReader
std::fs::File
&std::fs::File
Arc<std::fs::File>
std::sys::hermit::fs::File
std::sys::solid::fs::File
std::sys::unix::fs::File
std::sys::unsupported::fs::File
std::sys::wasi::fs::File
std::sys::windows::fs::File
std::sys::unix::fd::FileDesc
std::sys::unix::fs::CachedFileMetadata
std::sys::windows::handle::Handle
14&std::sys::hermit::fd::FileDesc
std::io::Stdin
&std::io::Stdin
std::io::StdinLock<'_>
std::io::stdio::StdinRaw
std::process::ChildStdout
std::process::ChildStderr
std::sys::hermit::stdio::Stdin
std::sys::sgx::stdio::Stdin
15std::sys::solid::stdio::Stdin
15std::sys::teeos::stdio::Stdin
std::sys::uefi::stdio::Stdin
std::sys::unix::stdio::Stdin
std::sys::unsupported::stdio::Stdin
std::sys::wasi::stdio::Stdin
std::sys::windows::stdio::Stdin
15std::sys::xous::stdio::Stdin
std::sys::zkvm::stdio::Stdin
cargo::util::FileLock
cargo::util::LimitErrorReader<Read>
Write
impl Write for T
vectored
all
all_vectored
fmt
&mut Write
Box<Write>
&mut [u8]
Vec<u8>
VecDeque<u8>
std::io::Cursor<&mut [u8]>
std::io::Cursor<&mut Vec<u8>>
std::io::Cursor<Vec<u8>>
std::io::Cursor<Box<[u8]>>
std::io::Cursor<[u8; N]>
core::io::BorrowedCursor<'_>
std::io::BufWriter<Write>
std::io::LineWriter<Write>
std::io::…::LineWriterShim<'_, Write>
std::io::Empty
&std::io::Empty
std::io::Sink
&std::io::Sink
std::net::TcpStream
&std::net::TcpStream
std::os::unix::net::UnixStream
&std::os::unix::net::UnixStream
std::io::PipeWriter
&std::io::PipeWriter
std::fs::File
&std::fs::File
Arc<std::fs::File>
std::sys::hermit::fs::File
std::sys::solid::fs::File
std::sys::unix::fs::File
std::sys::unsupported::fs::File
std::sys::wasi::fs::File
std::sys::windows::fs::File
std::sys::unix::fs::CachedFileMetadata
std::io::Stdout
&std::io::Stdout
&std::io::StdoutLock<'_>
std::io::stdio::StdoutRaw
std::io::Stderr
&std::io::Stderr
&std::io::StderrLock<'_>
std::io::stdio::StderrRaw
std::process::ChildStdin
&std::process::ChildStdin
std::sys::hermit::stdio::Stdout
std::sys::hermit::stdio::Stderr
std::sys::sgx::stdio::Stdout
std::sys::sgx::stdio::Stderr
std::sys::sgx::abi::panic::SgxPanicOutput
std::sys::solid::stdio::Stdout
std::sys::solid::stdio::Stderr
std::sys::solid::stdio::PanicOutput
std::sys::teeos::stdio::Stdout
std::sys::teeos::stdio::Stderr
std::sys::uefi::stdio::Stdout
std::sys::uefi::stdio::Stderr
std::sys::unix::stdio::Stdout
std::sys::unix::stdio::Stderr
std::sys::unsupported::stdio::Stdout
std::sys::unsupported::stdio::Stderr
std::sys::wasi::stdio::Stdout
std::sys::wasi::stdio::Stderr
std::sys::windows::stdio::Stdout
std::sys::windows::stdio::Stderr
std::sys::xous::stdio::Stdout
std::sys::xous::stdio::Stderr
std::sys::xous::stdio::PanicWriter
std::sys::zkvm::stdio::Stdout
std::sys::zkvm::stdio::Stderr
test::console::OutputLocation<Write>
test::term::WinConsole<Write>
test::term::TerminfoTerminal<Write>
cargo::util::FileLock
proc_macro::bridge::buffer::Buffer
rust-installer::compression::CombinedEncoder
rustc_errors::emitter::Buffy
rustc_errors::json::…::BufWriter
FileExt
read_at
seek_read
read_vectored_at
read_exact_at
write_at
seek_write
write_vectored_at
write_all_at
std::fs::unix::fs::File
std::sys::wasi::fs::File
std::sys::windows::fs::File
Socket
read
read_buf
read_vectored
recv_from
peek
peek_from
write
write_vectored
std::sys::net::hermit::Socket
std::sys::net::solid::Socket
std::sys::net::unix::Socket
std::sys::net::wasip2::Socket
std::sys::net::windows::Socket
std::sys::net::sgx::{TcpStream, UdpSocket}
std::sys::net::wasip1::{TcpStream, UdpSocket}
Footnotes
Added in Implement most of RFC 2930, providing the ReadBuf abstraction #81156. ↩ ↩2 ↩3 ↩4 ↩5 ↩6 ↩7 ↩8 ↩9 ↩10 ↩11 ↩12 ↩13 ↩14
Added in Specialize many implementations of
Read::read_buf_exact
#122393. ↩ ↩2 ↩3 ↩4 ↩5 ↩6 ↩7 ↩8Added in Add vectored read and write support #58357. ↩ ↩2 ↩3 ↩4 ↩5 ↩6 ↩7 ↩8 ↩9 ↩10 ↩11 ↩12 ↩13 ↩14 ↩15 ↩16 ↩17 ↩18 ↩19 ↩20 ↩21 ↩22 ↩23 ↩24 ↩25 ↩26 ↩27 ↩28 ↩29 ↩30 ↩31 ↩32 ↩33
Added in Add Read/Write::can_read/write_vectored #67841. ↩ ↩2 ↩3 ↩4 ↩5 ↩6 ↩7 ↩8 ↩9 ↩10 ↩11 ↩12 ↩13 ↩14 ↩15 ↩16 ↩17 ↩18 ↩19 ↩20 ↩21 ↩22 ↩23 ↩24 ↩25 ↩26 ↩27 ↩28 ↩29 ↩30 ↩31 ↩32 ↩33 ↩34 ↩35 ↩36 ↩37 ↩38 ↩39 ↩40 ↩41 ↩42 ↩43 ↩44 ↩45 ↩46 ↩47 ↩48 ↩49 ↩50 ↩51 ↩52 ↩53 ↩54 ↩55 ↩56 ↩57 ↩58 ↩59 ↩60 ↩61 ↩62 ↩63 ↩64 ↩65
Added in std: Update the std::io adaptors to proxy all methods #22428. ↩ ↩2 ↩3 ↩4 ↩5 ↩6
Added in std: Stabilize portions of the
io
module #23010. ↩ ↩2 ↩3 ↩4Added in Specialize some
io::Read
andio::Write
methods forVecDeque<u8>
and&[u8]
#110608. ↩ ↩2 ↩3 ↩4Added in Specialize
read_exact
andread_buf_exact
forVecDeque
#132039. ↩ ↩2Added in Specialize some methods of
io::Chain
#105917. ↩ ↩2 ↩3Added in Implement
read*_exact
forstd:io::repeat
#136818. ↩ ↩2Added in Improve several
Read
implementations #122441. ↩ ↩2 ↩3Added in
UnixStream
: overrideread_buf
#123084. ↩ ↩2This
Read
implementation is unused. I plan to remove it. ↩This
Read
implementation is unused. I plan to remove it. ↩This platform doesn't have stdin. I replace it with
std::sys::unsupported::stdio::Stdin
in #136769. ↩ ↩2 ↩3Added in Implement
read_buf
for WASI stdin #137353. ↩Added in Implement
read_buf
for zkVM stdin #137349. ↩zkVM has no vectored read/write syscalls. ↩ ↩2 ↩3
Added in Forward all default methods for I/O impls #137062. ↩ ↩2
StdoutLock<'_>
andStderrLock<'_>
cannot providewrite_fmt
, because the user could supply a formatting implementation which usesStdout
orStderr
, leading to panicking. (See joboet's comment) ↩ ↩2SOLID has no vectored version of
SOLID_LOG_write
. ↩ ↩2 ↩3TEEOS has no vectored version of
KCALL_DEBUG_CMD_PUT_BYTES
. ↩ ↩2Added in Add vectored positioned I/O on Unix #89518. ↩ ↩2
The text was updated successfully, but these errors were encountered: