about summary refs log tree commit diff
path: root/library/std/src
AgeCommit message (Collapse)AuthorLines
2023-11-23Auto merge of #115159 - solid-rs:patch/kmc-solid/io-safety, r=workingjubileebors-132/+371
kmc-solid: I/O safety Adds the I/O safety API (#87329) for socket file descriptors in [`*-kmc-solid_*`](https://doc.rust-lang.org/nightly/rustc/platform-support/kmc-solid.html) Tier 3 targets. All new public items are gated by the `solid_ext` library feature. This PR adds the following public types and traits: std::os::solid::io::AsFd std::os::solid::io::BorrowedFd std::os::solid::io::OwnedFd std::os::solid::prelude::AsFd (re-export) std::os::solid::prelude::BorrowedFd (re-export) std::os::solid::prelude::OwnedFd (re-export) And trait implementations: From<std::net::TcpListener> for std::os::solid::io::OwnedFd From<std::net::TcpStream> for std::os::solid::io::OwnedFd From<std::net::UdpSocket> for std::os::solid::io::OwnedFd From<std::os::solid::io::OwnedFd> for std::net::TcpListener From<std::os::solid::io::OwnedFd> for std::net::TcpStream From<std::os::solid::io::OwnedFd> for std::net::UdpSocket std::fmt::Debug for std::os::solid::io::BorrowedFd<'_> std::fmt::Debug for std::os::solid::io::OwnedFd std::io::IsTerminal for std::os::solid::io::BorrowedFd<'_> std::io::IsTerminal for std::os::solid::io::OwnedFd std::os::fd::AsRawFd for std::os::solid::io::BorrowedFd<'_> std::os::fd::AsRawFd for std::os::solid::io::OwnedFd std::os::fd::FromRawFd for std::os::solid::io::OwnedFd std::os::fd::IntoRawFd for std::os::solid::io::OwnedFd std::os::solid::io::AsFd for &impl std::os::solid::io::AsFd std::os::solid::io::AsFd for &mut impl std::os::solid::io::AsFd std::os::solid::io::AsFd for Arc<impl std::os::solid::io::AsFd> std::os::solid::io::AsFd for Box<impl std::os::solid::io::AsFd> std::os::solid::io::AsFd for Rc<impl std::os::solid::io::AsFd> std::os::solid::io::AsFd for std::net::TcpListener std::os::solid::io::AsFd for std::net::TcpStream std::os::solid::io::AsFd for std::net::UdpSocket std::os::solid::io::AsFd for std::os::solid::io::BorrowedFd<'_> std::os::solid::io::AsFd for std::os::solid::io::OwnedFd Taking advantage of the above change, this PR also refactors the internal details of `std::sys::solid::net` to match the design of other targets, e.g., by redefining `Socket` as a newtype of `OwnedFd`.
2023-11-22add missing period in `std::process::Command` docsMax Heller-1/+1
2023-11-22x fmt library/stdChris Denton-3/+2
2023-11-22redundant_slicingChris Denton-1/+1
2023-11-22cmp_nullChris Denton-2/+2
comparing with null is better expressed by the `.is_null()` method
2023-11-22manual_range_containsChris Denton-2/+2
2023-11-22op_refChris Denton-1/+1
taken reference of right operand
2023-11-22manual_mapChris Denton-5/+3
manual implementation of `Option::map`
2023-11-22unnecessary_lazy_evaluationsChris Denton-1/+1
unnecessary closure used with `bool::then`
2023-11-22redundant_closureChris Denton-4/+4
2023-11-22duration_subsecChris Denton-1/+1
calling `subsec_micros()` is more concise than this calculation
2023-11-22unnecessary_castChris Denton-9/+9
casting to the same type is unnecessary
2023-11-22needless_borrowChris Denton-8/+8
this expression creates a reference which is immediately dereferenced by the compiler
2023-11-22needless_borrows_for_generic_argsChris Denton-2/+2
the borrowed expression implements the required traits
2023-11-22manual_slice_size_calculationChris Denton-1/+1
2023-11-22unnecessary_mut_passedChris Denton-4/+4
This is where our Windows API bindings previously (and incorrectly) used `*mut` instead of `*const` pointers. Now that the bindings have been corrected, the mutable references (which auto-convert to `*mut`) are unnecessary and we can use shared references.
2023-11-22useless_conversionChris Denton-1/+1
2023-11-22needless_returnChris Denton-1/+1
unneeded `return` statement
2023-11-22allow clippy style in windows/c.rsChris Denton-0/+1
We intentional use the Windows API style here.
2023-11-21Rollup merge of #117790 - rcvalle:rust-cfi-fix-000000, r=workingjubileeNilstrieb-0/+2
CFI: Add missing use core::ffi::c_int Adds missing use core::ffi::c_int for when sanitizer_cfi_normalize_integers is defined.
2023-11-19Rollup merge of #117957 - the8472:pidfd-wait, r=Mark-SimulacrumMichael Goulet-11/+90
if available use a Child's pidfd for kill/wait This should get us closer to stabilization of pidfds since they now do something useful. And they're `CLOEXEC` now. ``` $ strace -ffe clone,sendmsg,recvmsg,execve,kill,pidfd_open,pidfd_send_signal,waitpid,waitid ./x test std --no-doc -- pidfd [...] running 1 tests strace: Process 816007 attached [pid 816007] pidfd_open(816006, 0) = 3 [pid 816007] clone(child_stack=NULL, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7f0c6b787990) = 816008 strace: Process 816008 attached [pid 816007] recvmsg(3, <unfinished ...> [pid 816008] pidfd_open(816008, 0) = 3 [pid 816008] sendmsg(4, {msg_name=NULL, msg_namelen=0, msg_iov=[{iov_base="", iov_len=0}], msg_iovlen=1, msg_control=[{cmsg_len=20, cmsg_level=SOL_SOCKET, cmsg_type=SCM_RIGHTS, cmsg_data=[3]}], msg_controllen=24, msg_flags=0}, 0) = 0 [pid 816007] <... recvmsg resumed>{msg_name=NULL, msg_namelen=0, msg_iov=[{iov_base="", iov_len=0}], msg_iovlen=1, msg_control=[{cmsg_len=20, cmsg_level=SOL_SOCKET, cmsg_type=SCM_RIGHTS, cmsg_data=[4]}], msg_controllen=24, msg_flags=MSG_CMSG_CLOEXEC}, MSG_CMSG_CLOEXEC) = 0 [pid 816008] execve("/usr/bin/false", ["false"], 0x7ffcf2100048 /* 105 vars */) = 0 [pid 816007] waitid(P_PIDFD, 4, <unfinished ...> [pid 816008] +++ exited with 1 +++ [pid 816007] <... waitid resumed>{si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=816008, si_uid=1001, si_status=1, si_utime=0, si_stime=0}, WEXITED, NULL) = 0 [pid 816007] --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=816008, si_uid=1001, si_status=1, si_utime=0, si_stime=0} --- [pid 816007] clone(child_stack=NULL, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLDstrace: Process 816009 attached , child_tidptr=0x7f0c6b787990) = 816009 [pid 816007] recvmsg(3, <unfinished ...> [pid 816009] pidfd_open(816009, 0) = 3 [pid 816009] sendmsg(5, {msg_name=NULL, msg_namelen=0, msg_iov=[{iov_base="", iov_len=0}], msg_iovlen=1, msg_control=[{cmsg_len=20, cmsg_level=SOL_SOCKET, cmsg_type=SCM_RIGHTS, cmsg_data=[3]}], msg_controllen=24, msg_flags=0}, 0) = 0 [pid 816007] <... recvmsg resumed>{msg_name=NULL, msg_namelen=0, msg_iov=[{iov_base="", iov_len=0}], msg_iovlen=1, msg_control=[{cmsg_len=20, cmsg_level=SOL_SOCKET, cmsg_type=SCM_RIGHTS, cmsg_data=[5]}], msg_controllen=24, msg_flags=MSG_CMSG_CLOEXEC}, MSG_CMSG_CLOEXEC) = 0 [pid 816009] execve("/usr/bin/sleep", ["sleep", "1000"], 0x7ffcf2100048 /* 105 vars */) = 0 [pid 816007] waitid(P_PIDFD, 5, {}, WNOHANG|WEXITED, NULL) = 0 [pid 816007] pidfd_send_signal(5, SIGKILL, NULL, 0) = 0 [pid 816007] waitid(P_PIDFD, 5, <unfinished ...> [pid 816009] +++ killed by SIGKILL +++ [pid 816007] <... waitid resumed>{si_signo=SIGCHLD, si_code=CLD_KILLED, si_pid=816009, si_uid=1001, si_status=SIGKILL, si_utime=0, si_stime=0}, WEXITED, NULL) = 0 [pid 816007] --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_KILLED, si_pid=816009, si_uid=1001, si_status=SIGKILL, si_utime=0, si_stime=0} --- [pid 816007] +++ exited with 0 +++ ```
2023-11-19Use an absolute path to the NUL deviceChris Denton-1/+1
While a bare "NUL" *should* be redirected to the NUL device, especially in this simple case, let's be explicit that we aren't opening a file called "NUL" and instead open it directly. This will also set a good example for people copying std code.
2023-11-19Don't set cmsg fields in msghdr if we have no cmsg to sendThe 8472-3/+4
2023-11-19Auto merge of #117895 - mzohreva:mz/fix-sgx-backtrace, r=Mark-Simulacrumbors-1/+14
Adjust frame IP in backtraces relative to image base for SGX target This is followup to https://github.com/rust-lang/backtrace-rs/pull/566. The backtraces printed by `panic!` or generated by `std::backtrace::Backtrace` in SGX target are not usable. The frame addresses need to be relative to image base address so they can be used for symbol resolution. Here's an example panic backtrace generated before this change: ``` $ cargo r --target x86_64-fortanix-unknown-sgx ... stack backtrace: 0: 0x7f8fe401d3a5 - <unknown> 1: 0x7f8fe4034780 - <unknown> 2: 0x7f8fe401c5a3 - <unknown> 3: 0x7f8fe401d1f5 - <unknown> 4: 0x7f8fe401e6f6 - <unknown> ``` Here's the same panic after this change: ``` $ cargo +stage1 r --target x86_64-fortanix-unknown-sgx stack backtrace: 0: 0x198bf - <unknown> 1: 0x3d181 - <unknown> 2: 0x26164 - <unknown> 3: 0x19705 - <unknown> 4: 0x1ef36 - <unknown> ``` cc `@jethrogb` and `@workingjubilee`
2023-11-19Rollup merge of #116750 - fintelia:seek_seek_relative, r=Mark-SimulacrumTakayuki Maeda-0/+40
Add Seek::seek_relative The `BufReader` struct has a `seek_relative` method because its `Seek::seek` implementation involved dumping the internal buffer (https://github.com/rust-lang/rust/issues/31100). Unfortunately, there isn't really a good way to take advantage of that method in generic code. This PR adds the same method to the main `Seek` trait with the straightforward default method, and an override for `BufReader` that calls its implementation. _Also discussed in [this](https://internals.rust-lang.org/t/add-seek-seek-relative/19546) internals.rust-lang.org thread._
2023-11-18Auto merge of #117138 - zachs18:rwlock_guard_debug_unsized, r=dtolnaybors-2/+2
Add T: ?Sized to `RwLockReadGuard` and `RwLockWriteGuard`'s Debug impls. For context, `MutexGuard` has `+ ?Sized` on its `Debug` impl, and all three have `+ ?Sized` on their `Display` impls. It looks like the `?Sized` was just missed when the impls were added (the impl for `MutexGuard` was added in the same PR (https://github.com/rust-lang/rust/pull/38006) with support for `T: Debug + ?Sized`, and `RwLock*Guard`s did allow `T: ?Sized` types already); the `Display` impls were added later (https://github.com/rust-lang/rust/pull/42822) with support for `T: Debug + ?Sized` types. I think this needs a T-libs-api FCP? I'm not sure if this also needs an ACP. If so I can make one. These are changes to (stable) trait impls on stable types so will be insta-stable. `@rustbot` label +T-libs-api
2023-11-17Rollup merge of #117338 - workingjubilee:asmjs-meets-thanatos, r=b-naberMatthias Krüger-14/+0
Remove asmjs Fulfills [MCP 668](https://github.com/rust-lang/compiler-team/issues/668). `asmjs-unknown-emscripten` does not work as-specified, and lacks essential upstream support for generating asm.js, so it should not exist at all.
2023-11-17Use ptr::invalid_mut for SGX image baseMohsen Zohrevandi-1/+1
2023-11-17Update windows-bindgenChris Denton-5/+5
2023-11-17Define `INVALID_HANDLE_VALUE` ourselvesChris Denton-2/+3
2023-11-16std: personality: support gcc personality on XousSean Cross-0/+1
Xous as an operating system is compiled with gcc-type personalities when it comes to unwinding. This enables unwinding inside panics on Xous, which enables Rust tests. Signed-off-by: Sean Cross <sean@xobs.io>
2023-11-15Re-format code with new rustfmtMark Rousskov-18/+30
2023-11-16if available use a Child's pidfd for kill/waitThe 8472-4/+78
2023-11-15Bump cfg(bootstrap)sMark Rousskov-5/+1
2023-11-15Substitute version placeholdersMark Rousskov-21/+21
2023-11-16update comment, we're currently using a different syscallThe 8472-1/+1
2023-11-16set CLOEXEC on pidfd received from child processThe 8472-3/+7
2023-11-14Move SGX-specific image base logic to sys_commonMohsen Zohrevandi-11/+14
2023-11-14Adjust frame IP in backtraces relative to image base for SGX targetMohsen Zohrevandi-0/+10
2023-11-11Auto merge of #115694 - clarfonthey:std-hash-private, r=dtolnaybors-167/+272
Add `std::hash::{DefaultHasher, RandomState}` exports (needs FCP) This implements rust-lang/libs-team#267 to move the libstd hasher types to `std::hash` where they belong, instead of `std::collections::hash_map`. <details><summary>The below no longer applies, but is kept for clarity.</summary> This is a small refactor for #27242, which moves the definitions of `RandomState` and `DefaultHasher` into `std::hash`, but in a way that won't be noticed in the public API. I've opened rust-lang/libs-team#267 as a formal ACP to move these directly into the root of `std::hash`, but for now, they're at least separated out from the collections code in a way that will make moving that around easier. I decided to simply copy the rustdoc for `std::hash` from `core::hash` since I think it would be ideal for the two to diverge longer-term, especially if the ACP is accepted. However, I would be willing to factor them out into a common markdown document if that's preferred. </details>
2023-11-10Update variable name to fix `unused_variables` warningDuo Wang-1/+1
2023-11-10CFI: Add missing use core::ffi::c_intRamon de C Valle-0/+2
Adds missing use core::ffi::c_int for when sanitizer_cfi_normalize_integers is defined.
2023-11-09Move `BorrowedBuf` and `BorrowedCursor` from `std:io` to `core::io`John Millikin-495/+16
Assigned new feature name `core_io_borrowed_buf` to distinguish from the `Read::read_buf` functionality in `std::io`.
2023-11-08Auto merge of #115460 - zachs18:borrowedcursor_write_no_panic, r=dtolnaybors-2/+3
Don't panic in `<BorrowedCursor as io::Write>::write` Instead of panicking if the BorrowedCursor does not have enough capacity for the whole buffer, just return a short write, [like `<&mut [u8] as io::Write>::write` does](https://doc.rust-lang.org/src/std/io/impls.rs.html#349). (cc `@ChayimFriedman2` https://github.com/rust-lang/rust/issues/78485#issuecomment-1493129588) (I'm not sure if this needs an ACP? since it's not changing the "API", just what the function does)
2023-11-08kmc-solid: Re-export `{As,Borrowed,Owned}Fd` in `std::os::solid::prelude`Tomoaki Kawada-1/+1
2023-11-08kmc-solid: Reimplement `AsFd` etc for `{TcpStream,TcpListener,UdpSocket}` by ↵Tomoaki Kawada-3/+3
delegating to inner `Socket` Removes some `unsafe` blocks.
2023-11-08kmc-solid: Implement `{From,Into}Inner<OwnedFd>` for `Socket`Tomoaki Kawada-2/+23
2023-11-08kmc-solid: Remove `FileDesc`Tomoaki Kawada-115/+43
Removes the private type `std::sys::solid::net::FileDesc`, replacing its only usage in `std::sys::solid::net::Socket` with `std::os::solid::io:: OwnedFd`.
2023-11-08kmc-solid: Replace `{From,Into}Inner<c_int>` impls with `*RawFd` for `Socket`Tomoaki Kawada-20/+16
Follows how other targets are implemented.
2023-11-08kmc-solid: Implement `AsFd` for `{Arc,Rc,Box}<impl AsFd>`Tomoaki Kawada-0/+33