about summary refs log tree commit diff
path: root/library/std/src/sys
AgeCommit message (Collapse)AuthorLines
2021-03-30Rollup merge of #83374 - reyk:fix/bsd-ancillary, r=joshtriplettDylan DPC-23/+34
unix: Fix feature(unix_socket_ancillary_data) on macos and other BSDs This adds support for CMSG handling on macOS and fixes it on OpenBSD and possibly other BSDs. When traversing the CMSG list, the previous code had an exception for Android where the next element after the last pointer could point to the first pointer instead of NULL. This is actually not specific to Android: the `libc::CMSG_NXTHDR` implementation for Linux and emscripten have a special case to return NULL when the length of the previous element is zero; most other implementations simply return the previous element plus a zero offset in this case. This MR makes the check non-optional which fixes CMSG handling and a possible endless loop on such systems; tested with file descriptor passing on OpenBSD, Linux, and macOS. This MR additionally adds `SocketAncillary::is_empty` because clippy is right that it should be added. This belongs to the `feature(unix_socket_ancillary_data)` tracking issue: https://github.com/rust-lang/rust/issues/76915 r? `@joshtriplett`
2021-03-27Rollup merge of #83522 - pickfire:patch-6, r=JohnTitorDylan DPC-5/+3
Improve fs error open_from unix Consistency for #79399 Suggested by JohnTitor r? `@JohnTitor` Not user if the error is too long now, do we handle long errors well?
2021-03-27Rollup merge of #82917 - cuviper:iter-zip, r=m-ou-seDylan DPC-2/+2
Add function core::iter::zip This makes it a little easier to `zip` iterators: ```rust for (x, y) in zip(xs, ys) {} // vs. for (x, y) in xs.into_iter().zip(ys) {} ``` You can `zip(&mut xs, &ys)` for the conventional `iter_mut()` and `iter()`, respectively. This can also support arbitrary nesting, where it's easier to see the item layout than with arbitrary `zip` chains: ```rust for ((x, y), z) in zip(zip(xs, ys), zs) {} for (x, (y, z)) in zip(xs, zip(ys, zs)) {} // vs. for ((x, y), z) in xs.into_iter().zip(ys).zip(xz) {} for (x, (y, z)) in xs.into_iter().zip((ys.into_iter().zip(xz)) {} ``` It may also format more nicely, especially when the first iterator is a longer chain of methods -- for example: ```rust iter::zip( trait_ref.substs.types().skip(1), impl_trait_ref.substs.types().skip(1), ) // vs. trait_ref .substs .types() .skip(1) .zip(impl_trait_ref.substs.types().skip(1)) ``` This replaces the tuple-pair `IntoIterator` in #78204. There is prior art for the utility of this in [`itertools::zip`]. [`itertools::zip`]: https://docs.rs/itertools/0.10.0/itertools/fn.zip.html
2021-03-28Rollup merge of #83558 - m-ou-se:use-finish-non-exhaustive, r=jackh726Yuki Okushi-1/+1
Use DebugStruct::finish_non_exhaustive() in std. See https://github.com/rust-lang/rust/issues/67364
2021-03-28Rollup merge of #83462 - ijackson:exitstatus-message-wording, r=joshtriplettYuki Okushi-3/+3
ExitStatus: print "exit status: {}" rather than "exit code: {}" on unix Proper Unix terminology is "exit status" (vs "wait status"). "exit code" is imprecise on Unix and therefore unclear. (As far as I can tell, "exit code" is correct terminology on Windows.) This new wording is unfortunately inconsistent with the identifier names in the Rust stdlib. It is the identifier names that are wrong, as discussed at length in eg https://doc.rust-lang.org/nightly/std/process/struct.ExitStatus.html https://doc.rust-lang.org/nightly/std/os/unix/process/trait.ExitStatusExt.html Unfortunately for API stability reasons it would be a lot of work, and a lot of disruption, to change the names in the stdlib (eg to rename `std::process::ExitStatus` to `std::process::ChildStatus` or something), but we should fix the message output. Many (probably most) readers of these messages about exit statuses will be users and system administrators, not programmers, who won't even know that Rust has this wrong terminology. So I think the right thing is to fix the documentation (as I have already done) and, now, the terminology in the implementation. This is a user-visible change to the behaviour of all Rust programs which run Unix subprocesses. Hopefully no-one is matching against the exit status string, except perhaps in tests.
2021-03-27Improve fs error open_from unixIvan Tham-5/+3
Consistency for #79399 Suggested by JohnTitor Improve fs error invaild input for sys_common The text was duplicated from unix.
2021-03-27Use DebugStruct::finish_non_exhaustive() in std.Mara Bos-1/+1
2021-03-26unix: Fix feature(unix_socket_ancillary_data) on macos and other BSDsReyk Floeter-23/+34
This adds support for CMSG handling on macOS and fixes it on OpenBSD and other BSDs. When traversing the CMSG list, the previous code had an exception for Android where the next element after the last pointer could point to the first pointer instead of NULL. This is actually not specific to Android: the `libc::CMSG_NXTHDR` implementation for Linux and emscripten have a special case to return NULL when the length of the previous element is zero; most other implementations simply return the previous element plus a zero offset in this case. This MR additionally adds `SocketAncillary::is_empty` because clippy is right that it should be added.
2021-03-26Use iter::zip in library/Josh Stone-2/+2
2021-03-26Rollup merge of #83463 - ijackson:exitstatusext-doc-grammar, r=kennytmDylan DPC-2/+2
ExitStatusExt: Fix missing word in two docs messages Looks like I missed the lack of these "and"s.
2021-03-25Auto merge of #83387 - cuviper:min-llvm-10, r=nagisabors-7/+4
Update the minimum external LLVM to 10 r? `@nikic`
2021-03-25ExitStatusExt: Fix missing word in two docs messagesIan Jackson-2/+2
Looks like I missed the lack of these "and"s. Acked-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-03-25ExitStatus: print "exit status: {}" rather than "exit code: {}"Ian Jackson-3/+3
Proper Unix terminology is "exit status" (vs "wait status"). "exit code" is imprecise on Unix and therefore unclear. (As far as I can tell, "exit code" is correct terminology on Windows.) This new wording is unfortunately inconsistent with the identifier names in the Rust stdlib. It is the identifier names that are wrong, as discussed at length in eg https://doc.rust-lang.org/nightly/std/process/struct.ExitStatus.html https://doc.rust-lang.org/nightly/std/os/unix/process/trait.ExitStatusExt.html Unfortunately for API stability reasons it would be a lot of work, and a lot of disruption, to change the names in the stdlib (eg to rename `std::process::ExitStatus` to `std::process::ChildStatus` or something), but we should fix the message output. Many (probably most) readers of these messages about exit statuses will be users and system administrators, not programmers, who won't even know that Rust has this wrong terminology. So I think the right thing is to fix the documentation (as I have already done) and, now, the terminology in the implementation. This is a user-visible change to the behaviour of all Rust programs which run Unix subprocesses. Hopefully no-one is matching against the exit status string, except perhaps in tests. Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-03-24Rollup merge of #83353 - m-ou-se:io-error-avoid-alloc, r=nagisaDylan DPC-161/+193
Add internal io::Error::new_const to avoid allocations. This makes it possible to have a io::Error containing a message with zero allocations, and uses that everywhere to avoid the *three* allocations involved in `io::Error::new(kind, "message")`. The function signature isn't perfect, because it needs a reference to the `&str`. So for now, this is just a `pub(crate)` function. Later, we'll be able to use `fn new_const<MSG: &'static str>(kind: ErrorKind)` to make that a bit better. (Then we'll also be able to use some ZST trickery if that would result in more efficient code.) See https://github.com/rust-lang/rust/issues/83352
2021-03-22Fix asm! from AT&T to Intel syntaxJosh Stone-1/+1
2021-03-22Update the minimum external LLVM to 10Josh Stone-6/+3
2021-03-22Rollup merge of #82686 - CDirkx:unix-platform, r=m-ou-seDylan DPC-38/+40
Move `std::sys::unix::platform` to `std::sys::unix::ext` This moves the operating system dependent alias `platform` (`std::os::{linux, android, ...}`) from `std::sys::unix` to `std::sys::unix::ext` (a.k.a. `std::os::unix`), removing the need for compatibility code in `unix_ext` when documenting on another platform. This is also a step in making it possible to properly move `std::sys::unix::ext` to `std::os::unix`, as ideally `std::sys` should not depend on the rest of `std`.
2021-03-21Use io::Error::new_const everywhere to avoid allocations.Mara Bos-161/+193
2021-03-19Rollup merge of #82500 - CDirkx:hermit-pipe, r=joshtriplettDylan DPC-38/+1
Reuse `std::sys::unsupported::pipe` on `hermit` Pipes are not supported on `hermit` and `hermit/pipe.rs` is identical to `unsupported/pipe.rs`. This PR reduces duplication between the two by doing the following on `hermit`: ```rust #[path = "../unsupported/pipe.rs"] pub mod pipe; ```
2021-03-17Display error details when a `mmap` call failsYuki Okushi-4/+6
2021-03-14Revert "Revert "use RWlock when accessing os::env #81850""The8472-12/+13
This reverts commit acdca316c3d42299d31c1b47eb792006ffdfc29c.
2021-03-14Rollup merge of #82804 - alexcrichton:fix-wasi, r=pnkfelixYuki Okushi-4/+2
std: Fix a bug on the wasm32-wasi target opening files This commit fixes an issue pointed out in #82758 where LTO changed the behavior of a program. It turns out that LTO was not at fault here, it simply uncovered an existing bug. The bindings to `__wasilibc_find_relpath` assumed that the relative portion of the path returned was always contained within thee input `buf` we passed in. This isn't actually the case, however, and sometimes the relative portion of the path may reference a sub-portion of the input string itself. The fix here is to use the relative path pointer coming out of `__wasilibc_find_relpath` as the source of truth. The `buf` used for local storage is discarded in this function and the relative path is copied out unconditionally. We might be able to get away with some `Cow`-like business or such to avoid the extra allocation, but for now this is probably the easiest patch to fix the original issue.
2021-03-11Auto merge of #82417 - the8472:fix-copy_file_range-append, r=m-ou-sebors-8/+28
Fix io::copy specialization using copy_file_range when writer was opened with O_APPEND fixes #82410 While `sendfile()` returns `EINVAL` when the output was opened with O_APPEND, `copy_file_range()` does not and returns `EBADF` instead, which – unlike other `EBADF` causes – is not fatal for this operation since a regular `write()` will likely succeed. We now treat `EBADF` as a non-fatal error for `copy_file_range` and fall back to a read-write copy as we already did for several other errors.
2021-03-10Rollup merge of #82949 - the8472:forget-envlock-on-fork, r=joshtriplettDylan DPC-7/+19
Do not attempt to unlock envlock in child process after a fork. This implements the first two points from https://github.com/rust-lang/rust/issues/64718#issuecomment-793030479 This is a breaking change for cases where the environment is accessed in a Command::pre_exec closure. Except for single-threaded programs these uses were not correct anyway since they aren't async-signal safe. Note that we had a ui test that explicitly tried `env::set_var` in `pre_exec`. As expected it failed with these changes when I tested locally.
2021-03-10Rollup merge of #82411 - ijackson:fix-exitstatus, r=dtolnayYuki Okushi-4/+57
Fixes to ExitStatus and its docs * On Unix, properly display every possible wait status (and don't panic on weird values) * In the documentation, be clear and consistent about "exit status" vs "wait status".
2021-03-09Do not attempt to unlock envlock in child process after a fork.The8472-7/+19
This is a breaking change for cases where the environment is accessed in a Command::pre_exec closure. Except for single-threaded programs these uses were not correct anyway since they aren't async-signal safe.
2021-03-09Always compile the fragile wait status test cases, just run them conditionallyIan Jackson-6/+7
Co-authored-by: David Tolnay <dtolnay@gmail.com>
2021-03-07Revert "use RWlock when accessing os::env #81850"Eric Huss-13/+12
This reverts commit 354f19cf2475148994954b6783341620c7445071, reversing changes made to 0cfba2fd090834c909d5ed9deccdee8170da791b.
2021-03-05std: Fix a bug on the wasm32-wasi target opening filesAlex Crichton-4/+2
This commit fixes an issue pointed out in #82758 where LTO changed the behavior of a program. It turns out that LTO was not at fault here, it simply uncovered an existing bug. The bindings to `__wasilibc_find_relpath` assumed that the relative portion of the path returned was always contained within thee input `buf` we passed in. This isn't actually the case, however, and sometimes the relative portion of the path may reference a sub-portion of the input string itself. The fix here is to use the relative path pointer coming out of `__wasilibc_find_relpath` as the source of truth. The `buf` used for local storage is discarded in this function and the relative path is copied out unconditionally. We might be able to get away with some `Cow`-like business or such to avoid the extra allocation, but for now this is probably the easiest patch to fix the original issue.
2021-03-04ExitStatus tests: Make less legible to satisfy "tidy"Ian Jackson-2/+4
I strongly disagree with tidy in this case but AIUI there is no way to override it. Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-03-04ExitStatus unknown wait status test: Make it Linux onlyIan Jackson-1/+1
If different unices have different bit patterns for WIFSTOPPED and WIFCONTINUED then simply being glibc is probably not good enough for this rather ad-hoc test to work. Do it on Linux only. Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-03-04ExitStatus stop signal display test: Make it Linux onlyIan Jackson-2/+7
MacOS uses a different representation. Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-03-03Auto merge of #82718 - JohnTitor:rollup-vpfx3j2, r=JohnTitorbors-45/+48
Rollup of 10 pull requests Successful merges: - #81223 ([rustdoc] Generate redirect map file) - #82439 (BTree: fix untrue safety) - #82469 (Use a crate to produce rustdoc tree comparisons instead of the `diff` command) - #82589 (unix: Non-mutable bufs in send_vectored_with_ancillary_to) - #82689 (meta: Notify Zulip for rustdoc nominated issues) - #82695 (Revert non-power-of-two vector restriction) - #82706 (use outer_expn_data() instead of outer_expn().expn_data()) - #82710 (FloatToInit: Replacing round_unchecked_to --> to_int_unchecked) - #82712 (Remove unnecessary conditional `cfg(target_os)` for `redox` and `vxworks`) - #82713 (Update cargo) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2021-03-03Rollup merge of #82589 - LinkTed:master, r=joshtriplettYuki Okushi-45/+48
unix: Non-mutable bufs in send_vectored_with_ancillary_to This is the same PR as [#79753](https://github.com/rust-lang/rust/pull/79753). It was closed because of inactivity. Therefore, I create a new one. ````@lukaslihotzki````
2021-03-03Auto merge of #76345 - okready:sgx-mem-range-overflow-checks, r=joshtriplettbors-8/+34
Add is_enclave_range/is_user_range overflow checks Fixes #76343. This adds overflow checking to `is_enclave_range` and `is_user_range` in `sgx::os::fortanix_sgx::mem` in order to mitigate possible security issues with enclave code. It also accounts for an edge case where the memory range provided ends exactly at the end of the address space, where calculating `p + len` would overflow back to zero despite the range potentially being valid.
2021-03-02Rollup merge of #82598 - GuillaumeGomez:rustdoc-rustc-pass, r=jyn514Guillaume Gomez-1/+2
Check stability and feature attributes in rustdoc Fixes #82588. cc `@Nemo157` `@camelid` r? `@jyn514`
2021-03-02Move `std::sys::unix::platform` to `std::sys::unix::ext`Christiaan Dirkx-38/+40
2021-03-01Add missing stability attributes in libstdGuillaume Gomez-1/+2
2021-02-28unix: Non-mutable bufs in send_vectored_with_ancillary_toLinkTed-45/+48
Change the arguments of `send_vectored_with_ancillary` and `send_vectored_with_ancillary_to` to take an non-mutable bufs.
2021-02-27Remove the x86_64-rumprun-netbsd targetSimonas Kazlauskas-4/+4
Closes #81514
2021-02-27Rollup merge of #82473 - de-vri-es:android-x86-accept4, r=m-ou-seDylan DPC-7/+1
Use libc::accept4 on Android instead of raw syscall. This PR replaces the use of a raw `accept4` syscall with `libc::accept4`. This was originally added (by me) because `std` couldn't update to the latest `libc` with `accept4` support for android. By now, libc is already on 0.2.85, so the workaround can be removed. `@rustbot` label +O-android +T-libs-impl
2021-02-27Rollup merge of #82421 - sunfishcode:wasi-metadata-size, r=alexcrichtonDylan DPC-0/+5
Add a `size()` function to WASI's `MetadataExt`. WASI's `filestat` type includes a size field, so expose it in `MetadataExt` via a `size()` function, similar to the corresponding Unix function. r? ``````@alexcrichton``````
2021-02-27Rollup merge of #82420 - sunfishcode:wasi-docs, r=alexcrichtonDylan DPC-26/+83
Enable API documentation for `std::os::wasi`. This adds API documentation support for `std::os::wasi` modeled after how `std::os::unix` works, so that WASI can be documented [here] along with the other platforms. [here]: https://doc.rust-lang.org/stable/std/os/index.html Two changes of particular interest: - This changes the `AsRawFd` for `io::Stdin` for WASI to return `libc::STDIN_FILENO` instead of `sys::stdio::Stdin.as_raw_fd()` (and similar for `Stdout` and `Stderr`), which matches how the `unix` version works. `STDIN_FILENO` etc. may not always be explicitly reserved at the WASI level, but as long as we have Rust's `std` and `libc`, I think it's reasonable to guarantee that we'll always use `libc::STDIN_FILENO` for stdin. - This duplicates the `osstr2str` utility function, rather than trying to share it across all the configurations that need it. r? ```@alexcrichton```
2021-02-25Rollup merge of #82467 - ojeda:tidy-normalize-safety-comments, r=kennytmAaron Hill-2/+4
library: Normalize safety-for-unsafe-block comments Almost all safety comments are of the form `// SAFETY:`, so normalize the rest and fix a few of them that should have been a `/// # Safety` section instead. Furthermore, make `tidy` only allow the uppercase form. While currently `tidy` only checks `core`, it is a good idea to prevent `core` from drifting to non-uppercase comments, so that later we can start checking `alloc` etc. too. Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2021-02-24Reuse `std::sys::unsupported::pipe` on `hermit`Christiaan Dirkx-38/+1
2021-02-24x.py fmtDan Gohman-3/+3
2021-02-24Use `super::` to refer to WASI-specific names.Dan Gohman-7/+7
This ensures that these names resolve to the right place even when building the WASI support on other platforms for generating the documentation.
2021-02-24Cast `libc::STDIN_FILENO` to `RawFd`.Dan Gohman-6/+6
WASI's `RawFd` is a `u32`, while `libc` uses `c_int`.
2021-02-24Use libc::accept4 on Android instead of raw syscall.Maarten de Vries-7/+1
2021-02-24library: Normalize safety-for-unsafe-block commentsMiguel Ojeda-2/+4
Almost all safety comments are of the form `// SAFETY:`, so normalize the rest and fix a few of them that should have been a `/// # Safety` section instead. Furthermore, make `tidy` only allow the uppercase form. While currently `tidy` only checks `core`, it is a good idea to prevent `core` from drifting to non-uppercase comments, so that later we can start checking `alloc` etc. too. Signed-off-by: Miguel Ojeda <ojeda@kernel.org>