about summary refs log tree commit diff
path: root/library/std/src/os
AgeCommit message (Collapse)AuthorLines
2022-07-06Fix typo in file descriptor docsFlorian Spieß-1/+1
2022-07-03Auto merge of #97437 - jyn514:impl-asrawfd-arc, r=dtolnaybors-0/+62
`impl<T: AsRawFd> AsRawFd for {Arc,Box}<T>` This allows implementing traits that require a raw FD on Arc and Box. Previously, you'd have to add the function to the trait itself: ```rust trait MyTrait { fn as_raw_fd(&self) -> RawFd; } impl<T: MyTrait> MyTrait for Arc<T> { fn as_raw_fd(&self) -> RawFd { (**self).as_raw_fd() } } ``` In particular, this leads to lots of "multiple applicable items in scope" errors because you have to disambiguate `MyTrait::as_raw_fd` from `AsRawFd::as_raw_fd` at each call site. In generic contexts, when passing the type to a function that takes `impl AsRawFd` it's also sometimes required to use `T: MyTrait + AsRawFd`, which wouldn't be necessary if I could write `MyTrait: AsRawFd`. After this PR, the code can be simpler: ```rust trait MyTrait: AsRawFd {} impl<T: MyTrait> MyTrait for Arc<T> {} ```
2022-06-27Seal Windows `FileTypeExt` extension trait to allow adding future methodsJosh Triplett-1/+5
2022-06-27Stabilize Windows `FileTypeExt` with `is_symlink_dir` and `is_symlink_file`Josh Triplett-4/+4
These calls allow detecting whether a symlink is a file or a directory, a distinction Windows maintains, and one important to software that wants to do further operations on the symlink (e.g. removing it).
2022-06-21`impl<T: AsFd> AsFd for {Arc,Box}<T>`Joshua Nelson-3/+33
2022-06-21`impl<T: AsRawFd> for {Arc,Box}<T>`Joshua Nelson-0/+32
This allows implementing traits that require a raw FD on Arc and Box. Previously, you'd have to add the function to the trait itself: ```rust trait MyTrait { fn as_raw_fd(&self) -> RawFd; } impl<T: MyTrait> MyTrait for Arc<T> { fn as_raw_fd(&self) -> RawFd { (**self).as_raw_fd() } } ```
2022-06-21update ioslice docs to use shared slicesConrad Ludgate-2/+2
2022-06-20Rollup merge of #97837 - sunfishcode:sunfishcode/proc-self-mem, r=m-ou-seDylan DPC-0/+19
Document Rust's stance on `/proc/self/mem` Add documentation to `std::os::unix::io` describing Rust's stance on `/proc/self/mem`, treating it as an external entity which is outside the scope of Rust's safety guarantees.
2022-06-20Rollup merge of #97149 - ChrisDenton:win_async_pipes, r=m-ou-seDylan DPC-0/+40
Windows: `CommandExt::async_pipes` Discussed in https://github.com/tokio-rs/tokio/issues/4670 was the need for third party crates to be able to force `process::Command::spawn` to create pipes as async. This implements the suggestion for a `async_pipes` method that gives third party crates that option. # Example: ```rust use std::process::{Command, Stdio}; Command::new("cmd") .async_pipes(true) .stdin(Stdio::piped()) .stdout(Stdio::piped()) .stderr(Stdio::piped()) .spawn() .unwrap(); ```
2022-06-20Windows: `CommandExt::async_pipes`Chris Denton-0/+40
2022-06-15Auto merge of #97178 - sunfishcode:ownedfd-and-dup, r=joshtriplettbors-35/+80
Add a `BorrowedFd::try_clone_to_owned` and accompanying documentation Add a `BorrowedFd::try_clone_to_owned`, which returns a new `OwnedFd` sharing the underlying file description. And similar for `BorrowedHandle` and `BorrowedSocket` on WIndows. This is similar to the existing `OwnedFd::try_clone`, but it's named differently to reflect that it doesn't return `Result<Self, ...>`. I'm open to suggestions for better names. Also, extend the `unix::io` documentation to mention that `dup` is permitted on `BorrowedFd`. This was originally requsted [here](https://github.com/rust-lang/rust/issues/88564#issuecomment-910786081). At the time I wasn't sure whether it was desirable, but it does have uses and it helps clarify the API. The documentation previously didn't rule out using `dup` on a `BorrowedFd`, but the API only offered convenient ways to do it from an `OwnedFd`. With this patch, the API allows one to do `try_clone` on any type where it's permitted.
2022-06-15Add the new stability attributes, for Windows.Dan Gohman-0/+2
2022-06-15Revise the documentation for `try_clone`.Dan Gohman-6/+8
On Unix, describe these in terms of the underlying "file description". On Windows, describe them in terms of the underlying "object".
2022-06-15Add `BorrowedFd::try_clone_to_owned`.Dan Gohman-17/+42
And `BorrowedHandle::try_clone_to_owned` and `BorrowedSocket::try_clone_to_owned` on Windows.
2022-06-15Document that `BorrowedFd` may be used to do a `dup`.Dan Gohman-12/+28
2022-06-15Auto merge of #95897 - AzureMarker:feature/horizon-std, r=nagisabors-30/+191
STD support for the Nintendo 3DS Rustc already supports compiling for the Nintendo 3DS using the `armv6k-nintendo-3ds` target (Tier 3). Until now though, only `core` and `alloc` were supported. This PR adds standard library support for the Nintendo 3DS. A notable exclusion is `std::thread` support, which will come in a follow-up PR as it requires more complicated changes. This has been a joint effort by `@Meziu,` `@ian-h-chamberlain,` myself, and prior work by `@rust3ds` members. ### Background The Nintendo 3DS (Horizon OS) is a mostly-UNIX looking system, with the caveat that it does not come with a full libc implementation out of the box. On the homebrew side (I'm not under NDA), the libc interface is partially implemented by the [devkitPro](https://devkitpro.org/wiki/devkitPro_pacman) toolchain and a user library like [`libctru`](https://github.com/devkitPro/libctru). This is important because there are [some possible legal barriers](https://github.com/rust-lang/rust/pull/88529#issuecomment-919938396) to linking directly to a library that uses the underlying platform APIs, since they might be considered a trade secret or under NDA. To get around this, the standard library impl for the 3DS does not directly depend on any platform-level APIs. Instead, it expects standard libc functions to be linked in. The implementation of these libc functions is left to the user. Some functions are provided by the devkitPro toolchain, but in our testing, we used the following to fill in the other functions: - [`libctru`] - provides more basic APIs, such as `nanosleep`. Linked in by way of [`ctru-sys`](https://github.com/Meziu/ctru-rs/tree/master/ctru-sys). - [`pthread-3ds`](https://github.com/Meziu/pthread-3ds) - provides pthread APIs for `std::thread`. Implemented using [`libctru`]. - [`linker-fix-3ds`](https://github.com/Meziu/rust-linker-fix-3ds) - fulfills some other missing libc APIs. Implemented using [`libctru`]. For more details, see the `src/doc/rustc/src/platform-support/armv6k-nintendo-3ds.md` file added in this PR. ### Notes We've already upstreamed changes to the [`libc`] crate to support this PR, as well as the upcoming threading PR. These changes have all been released as of 0.2.121, so we bump the crate version in this PR. Edit: After some rebases, the version bump has already been merged so it doesn't appear in this PR. A lot of the changes in this PR are straightforward, and follow in the footsteps of the ESP-IDF target: https://github.com/rust-lang/rust/pull/87666. The 3DS does not support user space process spawning, so these APIs are unimplemented (similar to ESP-IDF). [`libctru`]: https://github.com/devkitPro/libctru [`libc`]: https://github.com/rust-lang/libc
2022-06-14Add a stability attribute to WASI's `try_clone()`.Dan Gohman-0/+1
2022-06-14Implement stabilization of `#[feature(io_safety)]`.Dan Gohman-78/+139
Implement stabilization of [I/O safety], aka `#[feature(io_safety)]`. Fixes #87074. [I/O safety]: https://github.com/rust-lang/rfcs/blob/master/text/3128-io-safety.md
2022-06-13Use a private type definition to reduce cfg noiseMark Drobnak-36/+16
I checked with t-libs to make sure this is OK to do on stable functions: https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/Replacing.20std.20function.20arg.20type.20with.20private.20type.20def.3F
2022-06-13Update libc::stat field namesIan Chamberlain-6/+6
See https://github.com/Meziu/rust-horizon/pull/14
2022-06-13Horizon OS STD supportMeziu-12/+193
Co-authored-by: Ian Chamberlain <ian.h.chamberlain@gmail.com> Co-authored-by: Mark Drobnak <mark.drobnak@gmail.com>
2022-06-10net listen backlog set to negative on Linux.David Carlier-2/+10
it will be 4076 (from 5.4) or 128.
2022-06-10Make "windows_process_exit_code_from" unstableAron Parker-3/+3
2022-06-10Incorporate warning for potential exit code ambiguitiesAron Parker-0/+4
2022-06-10Fix copy paste errorAron Parker-1/+1
2022-06-09Implement ExitCodeExt for WindowsAron Parker-0/+19
2022-06-08Fix trailing whitespace.Dan Gohman-1/+1
2022-06-08Reword the question in the section header too.Dan Gohman-2/+2
This adopts the wording suggested in https://github.com/rust-lang/rust/pull/97837#discussion_r892524129.
2022-06-08Update library/std/src/os/unix/io/mod.rsDan Gohman-3/+2
Co-authored-by: Mara Bos <m-ou.se@m-ou.se>
2022-06-08Reword a question into a statement.Dan Gohman-2/+2
2022-06-07Inline Windows `OsStrExt::encode_wide`Nikolai Vazquez-0/+1
User crates currently produce much more code than necessary because the optimizer fails to make assumptions about this method.
2022-06-07Update library/std/src/os/unix/io/mod.rsDan Gohman-1/+1
Co-authored-by: Josh Triplett <josh@joshtriplett.org>
2022-06-07Update library/std/src/os/unix/io/mod.rsDan Gohman-1/+1
Co-authored-by: Josh Triplett <josh@joshtriplett.org>
2022-06-07Update library/std/src/os/unix/io/mod.rsDan Gohman-1/+1
Co-authored-by: Sean Stangl <sean.stangl@gmail.com>
2022-06-07Update library/std/src/os/unix/io/mod.rsDan Gohman-1/+1
Co-authored-by: Sean Stangl <sean.stangl@gmail.com>
2022-06-07Document Rust's stance on `/proc/self/mem`Dan Gohman-0/+20
Add documentation to `std::os::unix::io` describing Rust's stance on `/proc/self/mem`, treating it as an external entity which is outside the scope of Rust's safety guarantees.
2022-05-25Disable unix::net::ancillary on BSD.Mara Bos-155/+31
2022-05-17Revert "Auto merge of #96441 - ChrisDenton:sync-pipes, r=m-ou-se"Mark Rousskov-13/+0
This reverts commit ddb7fbe8434be481607ae199fe2aee976ee2fc2e, reversing changes made to baaa3b682986879c7784b5733ecea942e9ae7de3.
2022-05-15Rollup merge of #97060 - bdbai:fix/uwphandle, r=ChrisDentonDylan DPC-0/+2
Fix use of SetHandleInformation on UWP The use of `SetHandleInformation` (introduced in #96441 to make `HANDLE` inheritable) breaks UWP builds because it is not available for UWP targets. Proposed workaround: duplicate the `HANDLE` with `inherit = true` and immediately close the old one. Traditional Windows Desktop programs are not affected. cc `@ChrisDenton`
2022-05-15Rollup merge of #96947 - ↵Dylan DPC-0/+47
sunfishcode:sunfishcode/rustc-nonnull-optimization-guaranteed, r=joshtriplett Add rustc_nonnull_optimization_guaranteed to Owned/Borrowed Fd/Socket PR #94586 added support for using `rustc_nonnull_optimization_guaranteed` on values where the "null" value is the all-ones bitpattern. Now that #94586 has made it to the stage0 compiler, add `rustc_nonnull_optimization_guaranteed` to `OwnedFd`, `BorrowedFd`, `OwnedSocket`, and `BorrowedSocket`, since these types all exclude all-ones bitpatterns. This allows `Option<OwnedFd>`, `Option<BorrowedFd>`, `Option<OwnedSocket>`, and `Option<BorrowedSocket>` to be used in FFI declarations, as described in the [I/O safety RFC]. [I/O safety RFC]: https://github.com/rust-lang/rfcs/blob/master/text/3128-io-safety.md#ownedfd-and-borrowedfdfd-1
2022-05-15fix use of SetHandleInformation on UWPbdbai-0/+2
2022-05-11Fix comment syntax.Dan Gohman-0/+1
2022-05-11Relax the wording about the meaning of -1.Dan Gohman-6/+11
2022-05-11Fix attribute name.Dan Gohman-2/+2
2022-05-11RawSocket is unsigned on Windows.Dan Gohman-10/+9
2022-05-11Fix duplicate import on Windows.Dan Gohman-1/+1
2022-05-11Add rustc_nonnull_optimization_guaranteed to Owned/Borrowed Fd/SocketDan Gohman-0/+48
PR #94586 added support for using `rustc_nonnull_optimization_guaranteed` on values where the "null" value is the all-ones bitpattern. Now that #94586 has made it to the stage0 compiler, add `rustc_nonnull_optimization_guaranteed` to `OwnedFd`, `BorrowedFd`, `OwnedSocket`, and `BorrowedSocket`, since these types all exclude all-ones bitpatterns. This allows `Option<OwnedFd>`, `Option<BorrowedFd>`, `Option<OwnedSocket>`, and `Option<BorrowedSocket>` to be used in FFI declarations, as described in the [I/O safety RFC]. [I/O safety RFC]: https://github.com/rust-lang/rfcs/blob/master/text/3128-io-safety.md#ownedfd-and-borrowedfdfd-1
2022-05-11HandleOrNull can hold null, and HandleOrInvalid can hold INVALID_HANDLE_VALUE.Dan Gohman-9/+5
2022-05-10Fix incorrect mentions of `OwnedFd` and `BorrowedFd` in Windows docs.Dan Gohman-4/+4
2022-05-10Also document that `as_raw_handle` may return NULL.Dan Gohman-0/+7