summary refs log tree commit diff
path: root/library/std/src/sys
AgeCommit message (Collapse)AuthorLines
2021-10-15Also note tool expectations of fork vs clone3Josh Stone-0/+2
Co-authored-by: Josh Triplett <josh@joshtriplett.org>
2021-10-15Update another comment on fork vs. clone3Josh Stone-2/+2
2021-10-15Only use `clone3` when needed for pidfdJosh Stone-1/+5
In #89522 we learned that `clone3` is interacting poorly with Gentoo's `sandbox` tool. We only need that for the unstable pidfd extensions, so otherwise avoid that and use a normal `fork`.
2021-10-04Auto merge of #88587 - bdbai:fix/uwpio, r=joshtriplettbors-4/+7
Fix WinUWP std compilation errors due to I/O safety I/O safety for Windows has landed in #87329. However, it does not cover UWP specific parts and prevents all UWP targets from building. See https://github.com/YtFlow/Maple/issues/18. This PR fixes these compile errors when building std for UWP targets.
2021-09-02Auto merge of #87580 - ChrisDenton:win-arg-parse-2008, r=m-ou-sebors-123/+200
Update Windows Argument Parsing Fixes #44650 The Windows command line is passed to applications [as a single string](https://docs.microsoft.com/en-us/archive/blogs/larryosterman/the-windows-command-line-is-just-a-string) which the application then parses to get a list of arguments. The standard rules (as used by C/C++) for parsing the command line have slightly changed over the years, most recently in 2008 which added new escaping rules. This PR implements the new rules as [described on MSDN](https://docs.microsoft.com/en-us/cpp/cpp/main-function-command-line-args?view=msvc-160#parsing-c-command-line-arguments) and [further detailed here](https://daviddeley.com/autohotkey/parameters/parameters.htm#WIN). It has been tested against the behaviour of C++ by calling a C++ program that outputs its raw command line and the contents of `argv`. See [my repo](https://github.com/ChrisDenton/winarg/tree/std) if anyone wants to reproduce my work. For an overview of how this PR changes argument parsing behavior and why we feel it is warranted see https://github.com/rust-lang/rust/pull/87580#issuecomment-893833893. For some examples see: https://github.com/rust-lang/rust/pull/87580#issuecomment-894299249
2021-09-02Auto merge of #83342 - Count-Count:win-console-incomplete-utf8, r=m-ou-sebors-14/+90
Allow writing of incomplete UTF-8 sequences to the Windows console via stdout/stderr # Problem Writes of just an incomplete UTF-8 byte sequence (e.g. `b"\xC3"` or `b"\xF0\x9F"`) to stdout/stderr with a Windows console attached error with `io::ErrorKind::InvalidData, "Windows stdio in console mode does not support writing non-UTF-8 byte sequences"` even though further writes could complete the codepoint. This is currently a rare occurence since the [linewritershim](https://github.com/rust-lang/rust/blob/2c56ea38b045624dc8b42ec948fc169eaff1206a/library/std/src/io/buffered/linewritershim.rs) implementation flushes complete lines immediately and buffers up to 1024 bytes for incomplete lines. It can still happen as described in #83258. The problem will become more pronounced once the developer can switch stdout/stderr from line-buffered to block-buffered or immediate when the changes in the "Switchable buffering for Stdout" pull request (#78515) get merged. # Patch description If there is at least one valid UTF-8 codepoint all valid UTF-8 is passed through to the extracted `write_valid_utf8_to_console()` fn. The new code only comes into play if `write()` is being passed a short byte slice comprising an incomplete UTF-8 codepoint. In this case up to three bytes are buffered in the `IncompleteUtf8` struct associated with `Stdout` / `Stderr`. The bytes are accepted one at a time. As soon as an error can be detected `io::ErrorKind::InvalidData, "Windows stdio in console mode does not support writing non-UTF-8 byte sequences"` is returned. Once a complete UTF-8 codepoint is received it is passed to the `write_valid_utf8_to_console()` and the buffer length is set to zero. Calling `flush()` will neither error nor write anything if an incomplete codepoint is present in the buffer. # Tests Currently there are no Windows-specific tests for console writing code at all. Writing (regression) tests for this problem is a bit challenging since unit tests and UI tests don't run in a console and suddenly popping up another console window might be surprising to developers running the testsuite and it might not work at all in CI builds. To just test the new functionality in unit tests the code would need to be refactored. Some guidance on how to proceed would be appreciated. # Public API changes * `std::str::verifications::utf8_char_width()` would be exposed as `std::str::utf8_char_width()` behind the "str_internals" feature gate. # Related issues * Fixes #83258. * PR #78515 will exacerbate the problem. # Open questions * Add tests? * Squash into one commit with better commit message?
2021-09-01Rollup merge of #88542 - tavianator:readdir_r-errno, r=jyn514Mara Bos-2/+3
Use the return value of readdir_r() instead of errno POSIX says: > If successful, the readdir_r() function shall return zero; otherwise, > an error number shall be returned to indicate the error. But we were previously using errno instead of the return value. This led to issue #86649.
2021-08-31Use the return value of readdir_r() instead of errnoTavian Barnes-2/+3
POSIX says: > If successful, the readdir_r() function shall return zero; otherwise, > an error number shall be returned to indicate the error. But we were previously using errno instead of the return value. This led to issue #86649.
2021-08-30clean up `c::linger` conversionibraheemdev-2/+2
2021-08-30add `TcpStream::set_linger` and `TcpStream::linger`ibraheemdev-1/+95
2021-08-27Handle stack_t.ss_sp type change for DragonFlyBSDRyan Zoeller-14/+0
stack_t.ss_sp is now c_void on DragonFlyBSD, so the specialization is no longer needed. Changed in https://github.com/rust-lang/libc/commit/02922ef7504906589d02c2e4d97d1172fa247cc3.
2021-08-22Fix typos “an”→“a” and a few different ones that appeared in the ↵Frank Steffahn-1/+1
same search
2021-08-19Factor out a common `RawFd`/`AsRawFd`/etc for Unix and WASI.Dan Gohman-35/+69
2021-08-19Use the correct `into_*` on Windows to avoid dropping a stdio handle.Dan Gohman-2/+2
Use `into_raw_handle()` rather than `into_inner()` to completely consume a `Handle` without dropping its contained handle.
2021-08-19Fix an unused import warning.Dan Gohman-1/+1
2021-08-19Update PidFd for the new I/O safety APIs.Dan Gohman-5/+11
2021-08-19I/O safety.Dan Gohman-377/+771
Introduce `OwnedFd` and `BorrowedFd`, and the `AsFd` trait, and implementations of `AsFd`, `From<OwnedFd>` and `From<T> for OwnedFd` for relevant types, along with Windows counterparts for handles and sockets. Tracking issue: - <https://github.com/rust-lang/rust/issues/87074> RFC: - <https://github.com/rust-lang/rfcs/blob/master/text/3128-io-safety.md>
2021-08-19Auto merge of #88002 - hermitcore:unbox-mutex, r=dtolnaybors-3/+3
Unbox mutexes, condvars and rwlocks on hermit [RustyHermit](https://github.com/hermitcore/rusty-hermit) provides now movable synchronization primitives and we are able to unbox mutexes and condvars.
2021-08-18Rollup merge of #88012 - sunfishcode:sunfishcode/wasi-raw-fd-c-int, ↵Guillaume Gomez-47/+69
r=alexcrichton Change WASI's `RawFd` from `u32` to `c_int` (`i32`). WASI previously used `u32` as its `RawFd` type, since its "file descriptors" are unsigned table indices, and there's no fundamental reason why WASI can't have more than 2^31 handles. However, this creates myriad little incompability problems with code that also supports Unix platforms, where `RawFd` is `c_int`. While WASI isn't a Unix, it often shares code with Unix, and this difference made such shared code inconvenient. #87329 is the most recent example of such code. So, switch WASI to use `c_int`, which is `i32`. This will mean that code intending to support WASI should ideally avoid assuming that negative file descriptors are invalid, even though POSIX itself says that file descriptors are never negative. This is a breaking change, but `RawFd` is considerd an experimental feature in [the documentation]. [the documentation]: https://doc.rust-lang.org/stable/std/os/wasi/io/type.RawFd.html r? `@alexcrichton`
2021-08-13Change WASI's `RawFd` from `u32` to `c_int` (`i32`).Dan Gohman-47/+69
WASI previously used `u32` as its `RawFd` type, since its "file descriptors" are unsigned table indices, and there's no fundamental reason why WASI can't have more than 2^31 handles. However, this creates myriad little incompability problems with code that also supports Unix platforms, where `RawFd` is `c_int`. While WASI isn't a Unix, it often shares code with Unix, and this difference made such shared code inconvenient. #87329 is the most recent example of such code. So, switch WASI to use `c_int`, which is `i32`. This will mean that code intending to support WASI should ideally avoid assuming that negative file descriptors are invalid, even though POSIX itself says that file descriptors are never negative. This is a breaking change, but `RawFd` is considerd an experimental feature in [the documentation]. [the documentation]: https://doc.rust-lang.org/stable/std/os/wasi/io/type.RawFd.html
2021-08-13Don't put hermit mutexes in a box.Martin Kröning-1/+1
Hermit mutexes are movable.
2021-08-13Don't put hermit condvars in a box.Martin Kröning-1/+1
Hermit condvars are movable.
2021-08-13Don't put hermit rwlocks in a box.Martin Kröning-1/+1
Hermit rwlocks are movable.
2021-08-12Auto merge of #87963 - GuillaumeGomez:rollup-e54sbez, r=GuillaumeGomezbors-5/+24
Rollup of 4 pull requests Successful merges: - #87819 (Use a more accurate span on assoc types WF checks) - #87863 (Fix Windows Command::env("PATH")) - #87885 (Link to edition guide instead of issues for 2021 lints.) - #87941 (Fix/improve rustdoc-js tool) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2021-08-10STD support for the ESP-IDF frameworkivmarkov-42/+336
2021-08-08Implement modern Windows arg parsingChris Denton-106/+153
As derived from extensive testing of `argv` in a C/C++ application. Co-Authored-By: Jane Lusby <jlusby42@gmail.com>
2021-08-08Update Windows arg parsing testsChris Denton-17/+47
This updates the tests to be consistent with argv in modern C/C++ applications.
2021-08-08Fix Windows Command::env("PATH")Chris Denton-5/+24
2021-08-07Auto merge of #87810 - devnexen:haiku_os_simpl, r=Mark-Simulacrumbors-33/+8
current_exe haiku code path simplification all of these part of libc
2021-08-06current_exe haiku code path simplification all of these part of libcDavid Carlier-33/+8
2021-08-06Rollup merge of #87561 - devnexen:haiku_thread_build_fix, r=yaahcYuki Okushi-2/+9
thread set_name haiku implementation.
2021-08-02Rollup merge of #86509 - CDirkx:os_str, r=m-ou-seYuki Okushi-10/+276
Move `os_str_bytes` to `sys::unix` Followup to #84967, with `OsStrExt` and `OsStringExt` moved out of `sys_common`, there is no reason anymore for `os_str_bytes` to live in `sys_common` and not in sys. This pr moves it to the location `sys::unix::os_str` and reuses the code on other platforms via `#[path]` (as is common in `sys`) instead of importing.
2021-08-02Rollup merge of #86183 - inquisitivecrystal:env-nul, r=m-ou-seYuki Okushi-35/+19
Change environment variable getters to error recoverably This PR changes the standard library environment variable getter functions to error recoverably (i.e. not panic) when given an invalid value. On some platforms, it is invalid for environment variable names to contain `'\0'` or `'='`, or for their values to contain `'\0'`. Currently, the standard library panics when manipulating environment variables with names or values that violate these invariants. However, this behavior doesn't make a lot of sense, at least in the case of getters. If the environment variable is missing, the standard library just returns an error value, rather than panicking. It doesn't make sense to treat the case where the variable is invalid any differently from that. See the [internals thread](https://internals.rust-lang.org/t/why-should-std-var-panic/14847) for discussion. Thus, this PR changes the functions to error recoverably in this case as well. If desired, I could change the functions that manipulate environment variables in other ways as well. I didn't do that here because it wasn't entirely clear what to change them to. Should they error silently or do something else? If someone tells me how to change them, I'm happy to implement the changes. This fixes #86082, an ICE that arises from the current behavior. It also adds a regression test to make sure the ICE does not occur again in the future. `@rustbot` label +T-libs r? `@joshtriplett`
2021-08-01Auto merge of #87622 - pietroalbini:bump-bootstrap, r=Mark-Simulacrumbors-5/+0
Bump bootstrap compiler to 1.55 Changing the cfgs for stdarch is missing, but my understanding is that we don't need to do it as part of this PR? r? `@Mark-Simulacrum`
2021-08-01Auto merge of #81825 - voidc:pidfd, r=joshtriplettbors-3/+174
Add Linux-specific pidfd process extensions (take 2) Continuation of #77168. I addressed the following concerns from the original PR: - make `CommandExt` and `ChildExt` sealed traits - wrap file descriptors in `PidFd` struct representing ownership over the fd - add `take_pidfd` to take the fd out of `Child` - close fd when dropped Tracking Issue: #82971
2021-08-01bump bootstrap compiler to 1.55Pietro Albini-5/+0
2021-07-30Rollup merge of #87594 - devnexen:netbsd_fs_getfiledescriptor_path, ↵Yuki Okushi-2/+7
r=joshtriplett fs File get_path procfs usage for netbsd same as linux.
2021-07-29fs File get_path procfs usage for netbsd same as linux.David Carlier-2/+7
2021-07-29Fix may not to appropriate might not or must notAli Malik-2/+2
2021-07-28thread set_name haiku implementation.David Carlier-2/+9
2021-07-28Rollup merge of #87507 - jethrogb:jb/sgx-unmoveable-mutex, r=dtolnayYuki Okushi-1/+3
SGX mutex is *not* moveable Reverts the erroneous change in #85029.
2021-07-27Rollup merge of #87446 - devnexen:macos_update, r=dtolnayYuki Okushi-5/+2
macos current_exe using directly libc instead.
2021-07-27Rollup merge of #87354 - Wind-River:2021_master, r=kennytmYuki Okushi-1/+3
Update VxWork's UNIX support 1. VxWorks does not provide glibc 2. VxWorks does provide `sigemptyset` and `sigaddset` Note: these changes are concurrent to [this PR](https://github.com/rust-lang/libc/pull/2295) in libc.
2021-07-27Add warning to SGX mutex implementationJethro Beekman-0/+2
2021-07-27Revert "SGX mutex is movable"Jethro Beekman-1/+1
This reverts commit 30b82e0f96579d9f897c4e2a780af82662d89772.
2021-07-25macos current_exe using directly libc instead.David CARLIER-5/+2
2021-07-24Auto merge of #84589 - In-line:zircon-thread-name, r=JohnTitorbors-4/+30
Implement setting thread name for Fuchsia
2021-07-21VxWorks does provide sigemptyset and sigaddsetNicholas Baron-1/+1
2021-07-21Disable glibc tests on vxworksNicholas Baron-0/+2
VxWorks does not provide glibc, but we still need to test rustc on VxWorks.
2021-07-21Add tracking issue and link to man-pageDominik Stolz-1/+1