summary refs log tree commit diff
path: root/library/std/src/sys
AgeCommit message (Collapse)AuthorLines
2022-01-07Fix testsChris Denton-0/+4
2022-01-07Quote bat script command lineChris Denton-0/+16
2021-11-24Improving the readabilityStefan Lankes-1/+1
Co-authored-by: kennytm <kennytm@gmail.com>
2021-11-24If the thread does not get the lock in the short term, yield the CPUStefan Lankes-1/+10
Reduces the amount of wasted processor cycles
2021-11-23kernel_copy: avoid panic on unexpected OS errorGeorg Brandl-2/+4
According to documentation, the listed errnos should only occur if the `copy_file_range` call cannot be made at all, so the assert be correct. However, since in practice file system drivers (incl. FUSE etc.) can return any errno they want, we should not panic here. Fixes #91152
2021-11-20Auto merge of #87704 - ChrisDenton:win-resolve-exe, r=yaahcbors-29/+216
Windows: Resolve `process::Command` program without using the current directory Currently `std::process::Command` searches many directories for the executable to run, including the current directory. This has lead to a [CVE for `ripgrep`](https://cve.circl.lu/cve/CVE-2021-3013) but presumably other command line utilities could be similarly vulnerable if they run commands. This was [discussed on the internals forum](https://internals.rust-lang.org/t/std-command-resolve-to-avoid-security-issues-on-windows/14800). Also discussed was [which directories should be searched](https://internals.rust-lang.org/t/windows-where-should-command-new-look-for-executables/15015). EDIT: This PR originally removed all implicit paths. They've now been added back as laid out in the rest of this comment. ## Old Search Strategy The old search strategy is [documented here][1]. Additionally Rust adds searching the child's paths (see also #37519). So the full list of paths that were searched was: 1. The directories that are listed in the child's `PATH` environment variable. 2. The directory from which the application loaded. 3. The current directory for the parent process. 4. The 32-bit Windows system directory. 5. The 16-bit Windows system directory. 6. The Windows directory. 7. The directories that are listed in the PATH environment variable. ## New Search Strategy The new strategy removes the current directory from the searched paths. 1. The directories that are listed in the child's PATH environment variable. 2. The directory from which the application loaded. 3. The 32-bit Windows system directory. 4. The Windows directory. 5. The directories that are listed in the parent's PATH environment variable. Note that it also removes the 16-bit system directory, mostly because there isn't a function to get it. I do not anticipate this being an issue in modern Windows. ## Impact Removing the current directory should fix CVE's like the one linked above. However, it's possible some Windows users of affected Rust CLI applications have come to expect the old behaviour. This change could also affect small Windows-only script-like programs that assumed the current directory would be used. The user would need to use `.\file.exe` instead of the bare application name. This PR could break tests, especially those that test the exact output of error messages (e.g. Cargo) as this does change the error messages is some cases. [1]: https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-createprocessa#parameters
2021-11-19Rollup merge of #90942 - JohnTitor:should-os-error-3, r=m-ou-seYuki Okushi-4/+3
windows: Return the "Not Found" error when a path is empty Fixes #90940
2021-11-18Auto merge of #90382 - alexcrichton:wasm64-libstd, r=joshtriplettbors-4/+5
std: Get the standard library compiling for wasm64 This commit goes through and updates various `#[cfg]` as appropriate to get the wasm64-unknown-unknown target behaving similarly to the wasm32-unknown-unknown target. Most of this is just updating various conditions for `target_arch = "wasm32"` to also account for `target_arch = "wasm64"` where appropriate. This commit also lists `wasm64` as an allow-listed architecture to not have the `restricted_std` feature enabled, enabling experimentation with `-Z build-std` externally. The main goal of this commit is to enable playing around with `wasm64-unknown-unknown` externally via `-Z build-std` in a way that's similar to the `wasm32-unknown-unknown` target. These targets are effectively the same and only differ in their pointer size, but wasm64 is much newer and has much less ecosystem/library support so it'll still take time to get wasm64 fully-fledged.
2021-11-17windows: Return the "Not Found" error when a path is emptyYuki Okushi-4/+3
2021-11-14Auto merge of #90596 - the8472:path-hash-opt, r=Mark-Simulacrumbors-0/+1
Optimize Eq and Hash for Path/PathBuf ``` # new test path::tests::bench_hash_path_long ... bench: 86 ns/iter (+/- 1) test path::tests::bench_hash_path_short ... bench: 13 ns/iter (+/- 1) test path::tests::bench_path_hashset ... bench: 197 ns/iter (+/- 6) test path::tests::bench_path_hashset_miss ... bench: 94 ns/iter (+/- 4) # old test path::tests::bench_hash_path_long ... bench: 192 ns/iter (+/- 2) test path::tests::bench_hash_path_short ... bench: 33 ns/iter (+/- 1) test path::tests::bench_path_hashset ... bench: 1,121 ns/iter (+/- 24) test path::tests::bench_path_hashset_miss ... bench: 273 ns/iter (+/- 6) ```
2021-11-12Rollup merge of #90704 - ijackson:exitstatus-comments, r=joshtriplettMatthias Krüger-0/+3
Unix ExitStatus comments and a tiny docs fix Some nits left over from #88300
2021-11-11`Prefix` can be case-insensitive, delegate to its Hash impl instead of ↵The8472-0/+1
trying to hash the raw bytes This should have 0 performance overhead on unix since Prefix is always None.
2021-11-11unix::ExitStatus: Add comment saying that it's a wait statusIan Jackson-0/+3
With cross-reference. Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-11-10Rollup merge of #89930 - cuviper:avoid-clone3, r=joshtriplettMatthias Krüger-9/+10
Only use `clone3` when needed for pidfd 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`. This is a re-application of beta #89924, now that we're aware that we need more than just a temporary release fix. I also reverted 12fbabd27f700, as that was just fallout from using `clone3` instead of `fork`. r? `@Mark-Simulacrum` cc `@joshtriplett`
2021-11-10Review commentsAlex Crichton-1/+1
2021-11-10Use `target_family = "wasm"`Alex Crichton-1/+1
2021-11-10std: Get the standard library compiling for wasm64Alex Crichton-4/+5
This commit goes through and updates various `#[cfg]` as appropriate to get the wasm64-unknown-unknown target behaving similarly to the wasm32-unknown-unknown target. Most of this is just updating various conditions for `target_arch = "wasm32"` to also account for `target_arch = "wasm64"` where appropriate. This commit also lists `wasm64` as an allow-listed architecture to not have the `restricted_std` feature enabled, enabling experimentation with `-Z build-std` externally. The main goal of this commit is to enable playing around with `wasm64-unknown-unknown` externally via `-Z build-std` in a way that's similar to the `wasm32-unknown-unknown` target. These targets are effectively the same and only differ in their pointer size, but wasm64 is much newer and has much less ecosystem/library support so it'll still take time to get wasm64 fully-fledged.
2021-11-08kmc-solid: Avoid the use of `asm_const`Tomoaki Kawada-7/+6
2021-11-07Auto merge of #89310 - joshtriplett:available-concurrency-affinity, r=m-ou-sebors-0/+8
Make `std::thread::available_concurrency` support process-limited number of CPUs Use `libc::sched_getaffinity` and count the number of CPUs in the returned mask. This handles cases where the process doesn't have access to all CPUs, such as when limited via `taskset` or similar. This also covers cgroup cpusets.
2021-11-05Also note tool expectations of fork vs clone3Josh Stone-0/+2
Co-authored-by: Josh Triplett <josh@joshtriplett.org>
2021-11-05Update another comment on fork vs. clone3Josh Stone-2/+2
2021-11-05Only use `clone3` when needed for pidfdJosh Stone-7/+6
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-11-04Auto merge of #90392 - solid-rs:fix-solid-support, r=Mark-Simulacrumbors-1/+1
kmc-solid: Fix SOLID target This PR is a follow-up for #86191 and necessary to make the [`*-kmc-solid_*`](https://doc.rust-lang.org/nightly/rustc/platform-support/kmc-solid.html) Tier 3 targets actually usable. - Bumps `libc` to 0.2.106, which includes <https://github.com/rust-lang/libc/pull/2227>. - Applies the change made by #89324 to this target's target-specific code.
2021-11-01Run destructors from existing tls callbackChris Denton-23/+14
2021-11-01itron: Rename `itron::thread::{available_conccurrency -> available_parallelism}`Tomoaki Kawada-1/+1
Catching up with commit b4615b5bf9e3e722b480190714ad44ecd7fa2ed1
2021-10-31 Windows: Resolve Command program without using the current directoryChris Denton-29/+216
2021-10-31Windows thread-local keyless dropChris Denton-1/+36
`#[thread_local]` allows us to maintain a per-thread list of destructors. This also avoids the need to synchronize global data (which is particularly tricky within the TLS callback function).
2021-10-31Rollup merge of #89068 - bjorn3:restructure_rt2, r=joshtriplettMatthias Krüger-10/+10
Restructure std::rt (part 2) A couple more cleanups on top of https://github.com/rust-lang/rust/pull/89011 Blocked on #89011
2021-10-31Make std::thread::available_concurrency support process-limited number of CPUsJosh Triplett-0/+8
Use libc::sched_getaffinity and count the number of CPUs in the returned mask. This handles cases where the process doesn't have access to all CPUs, such as when limited via taskset or similar.
2021-10-31Rollup merge of #90401 - mkroening:hermit-condvar, r=joshtriplettMatthias Krüger-2/+14
hermit: Implement Condvar::wait_timeout This implements `Condvar::wait_timeout` for the `hermit` target. See * https://github.com/hermitcore/rust/pull/2 * https://github.com/hermitcore/rust/pull/5 CC: `@stlankes`
2021-10-30Auto merge of #89174 - ChrisDenton:automatic-verbatim-paths, r=dtolnaybors-13/+174
Automatically convert paths to verbatim for filesystem operations that support it This allows using longer paths without the user needing to `canonicalize` or manually prefix paths. If the path is already verbatim then this has no effect. Fixes: #32689
2021-10-29hermit: Implement Condvar::wait_timeoutMartin Kröning-2/+14
2021-10-23Fix typoChris Denton-1/+1
Co-authored-by: Ruslan Sayfutdinov <ruslan@sayfutdinov.com>
2021-10-23Make sure `CreateDirectoryW` works for path lengths > 247Chris Denton-1/+12
2021-10-22Add comment documenting why we can't use a simpler solutionSteven-0/+4
See #90144 for context. r? @joshtriplett
2021-10-19Rollup merge of #89941 - hermitcore:kernel, r=joshtriplettMatthias Krüger-1/+1
removing TLS support in x86_64-unknown-none-hermitkernel HermitCore's kernel itself doesn't support TLS. Consequently, the entries in x86_64-unknown-none-hermitkernel should be removed. This commit should help to finalize #89062.
2021-10-17Auto merge of #88652 - AGSaidi:linux-aarch64-should-be-actually-monotonic, ↵bors-0/+1
r=yaahc linux/aarch64 Now() should be actually_monotonic() While issues have been seen on arm64 platforms the Arm architecture requires that the counter monotonically increases and that it must provide a uniform view of system time (e.g. it must not be possible for a core to receive a message from another core with a time stamp and observe time going backwards (ARM DDI 0487G.b D11.1.2). While there have been a few 64bit SoCs that have bugs (#49281, #56940) which cause time to not monotonically increase, these have been fixed in the Linux kernel and we shouldn't penalize all Arm SoCs for those who refuse to update their kernels: SUN50I_ERRATUM_UNKNOWN1 - Allwinner A64 / Pine A64 - fixed in 5.1 FSL_ERRATUM_A008585 - Freescale LS2080A/LS1043A - fixed in 4.10 HISILICON_ERRATUM_161010101 - Hisilicon 1610 - fixed in 4.11 ARM64_ERRATUM_858921 - Cortex A73 - fixed in 4.12 255a3f3e183 std: Force `Instant::now()` to be monotonic added a Mutex to work around this problem and a small test program using glommio shows the majority of time spent acquiring and releasing this Mutex. 3914a7b0da8 tries to improve this, but actually makes it worse on big systems as for 128b atomics a ldxp/stxp pair (and successful loop) for v8.4 systems that don't support FEAT_LSE2 is required which is expensive as a lock and because of how the load/store-exclusives scale on large Arm systems is both unfair to threads and tends to go backwards in performance. A small sample program using glommio improves by 70x on a 32 core Graviton2 system with this change.
2021-10-16remove compiler warningsStefan Lankes-1/+1
2021-10-16Rollup merge of #89921 - joshuaseaton:zircon-process, r=tmandryMatthias Krüger-4/+7
[fuchsia] Update process info struct The fuchsia platform is in the process of softly transitioning over to using a new value for ZX_INFO_PROCESS with a new corresponding struct. This change migrates libstd. See [fxrev.dev/510478](https://fxrev.dev/510478) and [fxbug.dev/30751](https://fxbug.dev/30751) for more detail.
2021-10-15Auto merge of #84096 - m-ou-se:windows-bcrypt-random, r=dtolnaybors-27/+14
Use BCryptGenRandom instead of RtlGenRandom on Windows. This removes usage of RtlGenRandom on Windows, in favour of BCryptGenRandom. BCryptGenRandom isn't available on XP, but we dropped XP support a while ago.
2021-10-15[fuchsia] Update process info structJoshua Seaton-4/+7
The fuchsia platform is in the process of softly transitioning over to using a new value for ZX_INFO_PROCESS with a new corresponding struct. This change migrates libstd. See fxrev.dev/510478 and fxbug.dev/30751 for more detail.
2021-10-15Use BCryptGenRandom instead of RtlGenRandom on Windows.Mara Bos-27/+14
BCryptGenRandom isn't available on XP, but we dropped XP support a while ago.
2021-10-14Rollup merge of #89433 - arlosi:stdin-fix, r=joshtriplettMatthias Krüger-9/+19
Fix ctrl-c causing reads of stdin to return empty on Windows. Pressing ctrl+c (or ctrl+break) on Windows caused a blocking read of stdin to unblock and return empty, unlike other platforms which continue to block. On ctrl-c, `ReadConsoleW` will return success, but also set `LastError` to `ERROR_OPERATION_ABORTED`. This change detects this case, and re-tries the call to `ReadConsoleW`. Fixes #89177. See issue for further details. Tested on Windows 7 and Windows 10 with both MSVC and GNU toolchains
2021-10-11Rollup merge of #89707 - clemenswasser:apply_clippy_suggestions, ↵Matthias Krüger-6/+6
r=Mark-Simulacrum Apply clippy suggestions for std
2021-10-10Auto merge of #88952 - skrap:add-armv7-uclibc, r=nagisabors-1/+5
Add new tier-3 target: armv7-unknown-linux-uclibceabihf This change adds a new tier-3 target: armv7-unknown-linux-uclibceabihf This target is primarily used in embedded linux devices where system resources are slim and glibc is deemed too heavyweight. Cross compilation C toolchains are available [here](https://toolchains.bootlin.com/) or via [buildroot](https://buildroot.org). The change is based largely on a previous PR #79380 with a few minor modifications. The author of that PR was unable to push the PR forward, and graciously allowed me to take it over. Per the [target tier 3 policy](https://github.com/rust-lang/rfcs/blob/master/text/2803-target-tier-policy.md), I volunteer to be the "target maintainer". This is my first PR to Rust itself, so I apologize if I've missed things!
2021-10-09Apply clippy suggestionsClemens Wasser-6/+6
2021-10-09Rollup merge of #87528 - :stack_overflow_obsd, r=joshtriplettGuillaume Gomez-8/+9
stack overflow handler specific openbsd change.
2021-10-08Let stack_overflow::imp::cleanup call drop_handler directlybjorn3-10/+10
instead of through the Drop impl for Handler
2021-10-06Rollup merge of #89324 - yoshuawuyts:hardware-parallelism, r=m-ou-seManish Goregaokar-7/+7
Rename `std::thread::available_conccurrency` to `std::thread::available_parallelism` _Tracking issue: https://github.com/rust-lang/rust/issues/74479_ This PR renames `std::thread::available_conccurrency` to `std::thread::available_parallelism`. ## Rationale The API was initially named `std::thread::hardware_concurrency`, mirroring the [C++ API of the same name](https://en.cppreference.com/w/cpp/thread/thread/hardware_concurrency). We eventually decided to omit any reference to the word "hardware" after [this comment](https://github.com/rust-lang/rust/pull/74480#issuecomment-662045841). And so we ended up with `available_concurrency` instead. --- For a talk I was preparing this week I was reading through ["Understanding and expressing scalable concurrency" (A. Turon, 2013)](http://aturon.github.io/academic/turon-thesis.pdf), and the following passage stood out to me (emphasis mine): > __Concurrency is a system-structuring mechanism.__ An interactive system that deals with disparate asynchronous events is naturally structured by division into concurrent threads with disparate responsibilities. Doing so creates a better fit between problem and solution, and can also decrease the average latency of the system by preventing long-running computations from obstructing quicker ones. > __Parallelism is a resource.__ A given machine provides a certain capacity for parallelism, i.e., a bound on the number of computations it can perform simultaneously. The goal is to maximize throughput by intelligently using this resource. For interactive systems, parallelism can decrease latency as well. _Chapter 2.1: Concurrency is not Parallelism. Page 30._ --- _"Concurrency is a system-structuring mechanism. Parallelism is a resource."_ — It feels like this accurately captures the way we should be thinking about these APIs. What this API returns is not "the amount of concurrency available to the program" which is a property of the program, and thus even with just a single thread is effectively unbounded. But instead it returns "the amount of _parallelism_ available to the program", which is a resource hard-constrained by the machine's capacity (and can be further restricted by e.g. operating systems). That's why I'd like to propose we rename this API from `available_concurrency` to `available_parallelism`. This still meets the criteria we previously established of not attempting to define what exactly we mean by "hardware", "threads", and other such words. Instead we only talk about "concurrency" as an abstract resource available to our program. r? `@joshtriplett`
2021-10-06add platform support details file for armv7-unknown-linux-uclibcJonah Petri-1/+1