summary refs log tree commit diff
path: root/library/std/src/sys
AgeCommit message (Collapse)AuthorLines
2020-11-12[beta] always disable copy_file_range to avoid EOVERFLOW errorsThe8472-1/+1
2020-10-03Rollup merge of #77182 - GuillaumeGomez:missing-examples-fd-traits, r=pickfireJonas Schievink-0/+40
Add missing examples for Fd traits Not sure what happened here... This is a reopening of #77142 r? @Dylan-DPC
2020-10-02Rollup merge of #77432 - tmiasko:posix-spawn-musl, r=cuviperJonas Schievink-6/+8
Use posix_spawn on musl targets The posix_spawn had been available in a form suitable for use in a Command implementation since musl 0.9.12. Use it in a preference to a fork when possible, to benefit from CLONE_VM|CLONE_VFORK used there.
2020-10-02Simplify fd examplesGuillaume Gomez-19/+16
2020-10-02Auto merge of #77029 - ehuss:command-access, r=dtolnaybors-8/+141
Add accessors to Command. This adds some accessor methods to `Command` to provide a way to access the values set when building the `Command`. An example where this can be useful is to display the command to be executed. This is roughly based on the [`ProcessBuilder`](https://github.com/rust-lang/cargo/blob/13b73cdaf76b2d9182515c9cf26a8f68342d08ef/src/cargo/util/process_builder.rs#L105-L134) in Cargo. Possible concerns about the API: - Values with NULs on Unix will be returned as `"<string-with-nul>"`. I don't think it is practical to avoid this, since otherwise a whole separate copy of all the values would need to be kept in `Command`. - Does not handle `arg0` on Unix. This can be awkward to support in `get_args` and is rarely used. I figure if someone really wants it, it can be added to `CommandExt` as a separate method. - Does not offer a way to detect `env_clear`. I'm uncertain if it would be useful for anyone. - Does not offer a way to get an environment variable by name (`get_env`). I figure this can be added later if anyone really wants it. I think the motivation for this is weak, though. Also, the API could be a little awkward (return a `Option<Option<&OsStr>>`?). - `get_envs` could skip "cleared" entries and just return `&OsStr` values instead of `Option<&OsStr>`. I'm on the fence here. My use case is to display a shell command, and I only intend it to be roughly equivalent to the actual execution, and I probably won't display `None` entries. I erred on the side of providing extra information, but I suspect many situations will just filter out the `None`s. - Could implement more iterator stuff (like `DoubleEndedIterator`). I have not implemented new std items before, so I'm uncertain if the existing issue should be reused, or if a new tracking issue is needed. cc #44434
2020-10-02Rollup merge of #77147 - fusion-engineering-forks:static-mutex, r=dtolnayYuki Okushi-16/+14
Split sys_common::Mutex in StaticMutex and MovableMutex. The (unsafe) `Mutex` from `sys_common` had a rather complicated interface. You were supposed to call `init()` manually, unless you could guarantee it was neither moved nor used reentrantly. Calling `destroy()` was also optional, although it was unclear if 1) resources might be leaked or not, and 2) if `destroy()` should only be called when `init()` was called. This allowed for a number of interesting (confusing?) different ways to use this `Mutex`, all captured in a single type. In practice, this type was only ever used in two ways: 1. As a static variable. In this case, neither `init()` nor `destroy()` are called. The variable is never moved, and it is never used reentrantly. It is only ever locked using the `LockGuard`, never with `raw_lock`. 2. As a `Box`ed variable. In this case, both `init()` and `destroy()` are called, it will be moved and possibly used reentrantly. No other combinations are used anywhere in `std`. This change simplifies things by splitting this `Mutex` type into two types matching the two use cases: `StaticMutex` and `MovableMutex`. The interface of both new types is now both safer and simpler. The first one does not call nor expose `init`/`destroy`, and the second one calls those automatically in its `new()` and `Drop` functions. Also, the locking functions of `MovableMutex` are no longer unsafe. --- This will also make it easier to conditionally box mutexes later, by moving that decision into sys/sys_common. Some of the mutex implementations (at least those of Wasm and 'sys/unsupported') are safe to move, so wouldn't need a box. ~~(But that's blocked on #76932 for now.)~~ (See #77380.)
2020-10-02Rollup merge of #76979 - fusion-engineering-forks:windows-fallback-check, ↵Yuki Okushi-45/+53
r=dtolnay Improve std::sys::windows::compat Improves the compat_fn macro in sys::windows, which is used for conditionally loading APIs that might not be available. - The module (dll) name can now be any string, not just an ident. (Not all Windows api modules are valid Rust identifiers. E.g. `WaitOnAddress` comes from `API-MS-Win-Core-Synch-l1-2-0.dll`.) - Adds `FuncName::is_available()` for checking if a function is really available without having to do a duplicate lookup. - Add comment explaining the lack of locking. - Use `$_:block` to simplify the macro_rules. - Apply `allow(unused_variables)` only to the fallback instead of everything. --- The second point (`is_available()`) simplifies code that needs to pick an implementation depening on what is available, like `sys/windows/mutex.rs`. Before this change, it'd do its own lookup and keep its own `AtomicUsize` to track the result. Now it can just use `c::AcquireSRWLockExclusive::is_available()` directly. This will also be useful when park/unpark/CondVar/etc. get improved implementations (e.g. from parking_lot or something else), as the best APIs for those are not available before Windows 8.
2020-10-01Auto merge of #76969 - withoutboats:rawfd-refexive-traits, r=dtolnaybors-0/+57
Make RawFd implement the RawFd traits This PR makes `RawFd` implement `AsRawFd`, `IntoRawFd` and `FromRawFd`, so it can be passed to interfaces that use one of those traits as a bound.
2020-10-01Work around potential merging/duplication issues in sys/windows/compat.Mara Bos-3/+19
2020-10-01Formatting.Mara Bos-5/+1
2020-10-01Use AcquireSRWLockExclusive::is_available() instead of an extra lookup.Mara Bos-17/+6
2020-10-01Improve std::sys::windows::compat.Mara Bos-28/+35
- Module name can now be any string, not just an ident. (Not all Windows api modules are valid Rust identifiers.) - Adds c::FuncName::is_available() for checking if a function is really available without having to do a duplicate lookup. - Add comment explaining the lack of locking. - Use `$_:block` to simplify the macro_rules. - Apply allow(unused_variables) only to the fallback instead of everything.
2020-10-01Auto merge of #76919 - fusion-engineering-forks:thread-parker, r=dtolnaybors-0/+38
Use futex-based thread::park/unpark on Linux. This moves the parking/unparking logic out of `thread/mod.rs` into a module named `thread_parker` in `sys_common`. The current implementation is moved to `sys_common/thread_parker/generic.rs` and the new implementation using futexes is added in `sys_common/thread_parker/futex.rs`.
2020-10-01Use posix_spawn on musl targetsTomasz Miąsko-6/+8
The posix_spawn had been available in a form suitable for use in a Command implementation since musl 0.9.12. Use it in a preference to a fork when possible, to benefit from CLONE_VM|CLONE_VFORK used there.
2020-09-30Rollup merge of #77328 - hyd-dev:assert-to-rtassert, r=AmanieuJonas Schievink-1/+1
Use `rtassert!` instead of `assert!` from the child process after fork() in std::sys::unix::process::Command::spawn() As discussed in #73894, `assert!` panics on failure, which is not signal-safe, and `rtassert!` is a suitable replacement. Fixes #73894. r? @Amanieu @cuviper @joshtriplett
2020-09-30Auto merge of #77292 - lzutao:std_asm, r=Amanieubors-16/+24
Prefer asm! in std - all in sgx module Similar to the change in #76669 but all `llvm_asm!` is gate in x86/x86_64 target. Godbolt: - https://rust.godbolt.org/z/h7nG1h - https://rust.godbolt.org/z/xx39hW
2020-09-29Use `rtassert!` instead of `assert!` from the child process after fork() in ↵hyd-dev-1/+1
std::sys::unix::process::Command::spawn() `assert!` panics on failure, which is not signal-safe.
2020-09-28Prefer asm! in std - all in sgx moduleLzu Tao-16/+24
2020-09-28fix building libstd for Miri on macOSRalf Jung-49/+50
2020-09-27Reopen standard streams when they are closed on UnixTomasz Miąsko-0/+62
The syscalls returning a new file descriptors generally use lowest-numbered file descriptor not currently opened, without any exceptions for those corresponding to the standard streams. Previously when any of standard streams has been closed before starting the application, operations on std::io::{stderr,stdin,stdout} objects were likely to operate on other logically unrelated file resources opened afterwards. Avoid the issue by reopening the standard streams when they are closed.
2020-09-27Check conversion from Duration to timespec in futex_wait.Mara Bos-12/+11
2020-09-27Move linux-specific futex code into `sys` module.Mara Bos-0/+39
2020-09-27Split sys_common::Mutex in StaticMutex and MovableMutex.Mara Bos-16/+14
The (unsafe) Mutex from sys_common had a rather complicated interface. You were supposed to call init() manually, unless you could guarantee it was neither moved nor used reentrantly. Calling `destroy()` was also optional, although it was unclear if 1) resources might be leaked or not, and 2) if destroy() should only be called when `init()` was called. This allowed for a number of interesting (confusing?) different ways to use this Mutex, all captured in a single type. In practice, this type was only ever used in two ways: 1. As a static variable. In this case, neither init() nor destroy() are called. The variable is never moved, and it is never used reentrantly. It is only ever locked using the LockGuard, never with raw_lock. 2. As a Boxed variable. In this case, both init() and destroy() are called, it will be moved and possibly used reentrantly. No other combinations are used anywhere in `std`. This change simplifies things by splitting this Mutex type into two types matching the two use cases: StaticMutex and MovableMutex. The interface of both new types is now both safer and simpler. The first one does not call nor expose init/destroy, and the second one calls those automatically in its new() and Drop functions. Also, the locking functions of MovableMutex are no longer unsafe.
2020-09-26Add accessors to Command.Eric Huss-8/+141
2020-09-25Add missing examples for Fd traitsGuillaume Gomez-0/+43
2020-09-22Revert "Function to convert OpenOptions to c_int"Joshua Nelson-35/+0
2020-09-22Auto merge of #76110 - FedericoPonzi:convert-openoptions-cint, r=JoshTriplettbors-0/+35
Function to convert OpenOptions to c_int Fixes: #74943 The creation_mode and access_mode function were already available in the OpenOptions struct, but currently private. I've added a new free functions to unix/fs.rs which takes the OpenOptions, and returns the c_int to be used as parameter for the `open` call.
2020-09-22enable unstable open_options_ext_as_flags feature in doc commentsFederico Ponzi-0/+1
2020-09-21Rollup merge of #76521 - tavianator:fix-pthread-getattr-destroy, r=AmanieuRalf Jung-2/+8
Fix segfault if pthread_getattr_np fails glibc [destroys][1] the passed pthread_attr_t if pthread_getattr_np() fails. Destroying it again leads to a segfault. Fix it by only destroying it on success for glibc. [1]: https://sourceware.org/git/?p=glibc.git;a=blob;f=nptl/pthread_getattr_np.c;h=ce437205e41dc05653e435f6188768cccdd91c99;hb=HEAD#l205
2020-09-20try again to appease tidyWithout Boats-1/+0
2020-09-20spend another CI build to delete a double newlineWithout Boats-1/+0
2020-09-20fix typosWithout Boats-6/+6
2020-09-20Make RawFd implement the RawFd traitsWithout Boats-0/+59
2020-09-19Add tracking issue for feature(unix_socket_peek)rijenkii-3/+3
2020-09-17Auto merge of #76645 - fusion-engineering-forks:windows-lock, r=kennytmbors-43/+41
Small cleanups in Windows Mutex. - Move `held` into the boxed part, since the SRW lock implementation does not use this. This makes the Mutex 50% smaller. - Use `Cell` instead of `UnsafeCell` for `held`, such that `.replace()` can be used. - Add some comments. - Avoid creating multiple `&mut`s to the critical section object in `ReentrantMutex`.
2020-09-16Rollup merge of #76758 - adamlesinski:clone_clock, r=tmandryTyler Mandry-1/+3
[fuchsia] Propagate the userspace UTC clock On Fuchsia, spawning a subprocess does not automatically clone all of the parent process' capabilities. UTC time on Fuchsia is managed by a top-level userspace clock capability that is cloned and passed to subprocesses. This change ensures that any Rust subprocess gets access to the UTC clock, if the parent had access to it. This is critical for tests, which on Fuchsia, use panic=abort and spawn subprocesses per test.
2020-09-16Avoid creating `&mut`s in Windows ReentrantMutex.Mara Bos-7/+7
2020-09-16Don't use `mut` in Windows Mutex.Mara Bos-9/+7
2020-09-16Sets as_flags as unstableFederico Ponzi-1/+1
2020-09-16Rollup merge of #75749 - ehuss:consolidate-sys, r=alexcrichtonDylan DPC-889/+56
Consolidate some duplicate code in the sys modules. This consolidates some modules which were duplicated throughout the sys module. The intent is to make it easier to update and maintain this code. This mainly affects the wasi, sgx, and "unsupported" targets. I explicitly skipped hermit, cloudabi, and vxworks. These tier-3 targets have copied large sections of the sys tree. I don't think they should have, but I don't want to put effort into changing them. It also doesn't help that there aren't any scripts or instructions for building them. There are still sections of duplicate code here and there, but this PR covers the easy parts where entire modules are the same.
2020-09-15[fuchsia] Propagate the userspace UTC clockAdam Lesinski-1/+3
On Fuchsia, spawning a subprocess does not automatically clone all of the parent process' capabilities. UTC time on Fuchsia is managed by a top-level userspace clock capability that is cloned and passed to subprocesses. This change ensures that any Rust subprocess gets access to the UTC clock, if the parent had access to it. This is critical for tests, which on Fuchsia, use panic=abort and spawn subprocesses per test.
2020-09-15Auto merge of #75148 - joechrisellis:master, r=Amanieubors-0/+185
Implementation of peer credentials for Unix sockets The code in `ucred.rs` is based on the work done in [PR 13](https://github.com/tokio-rs/tokio-uds/pull/13) in the tokio-uds repository on GitHub. This commit is effectively a port to the stdlib, so credit to Martin Habovštiak (`@Kixunil)` and contributors for the meat of this work. 🥇 Happy to make changes as needed. 🙂
2020-09-15Consolidate wasi::process and unsupported::processEric Huss-157/+3
2020-09-15Consolidate wasi alloc with unix alloc.Eric Huss-111/+45
2020-09-15Consolidate byte-identical modules.Eric Huss-621/+8
2020-09-14Auto merge of #76278 - jethrogb:jb/sgx-rwlock-init-test, r=Mark-Simulacrumbors-23/+11
Improve SGX RWLock initializer test r? `@eddyb` This addresses https://github.com/pnkfelix/rust/pull/1#discussion_r374239895 Fixes https://github.com/fortanix/rust-sgx/issues/213
2020-09-14Fix peer credentials for AndroidJoe Ellis-6/+5
2020-09-14Conditionally compile peer credentials feature for supported platformsJoe Ellis-0/+18
2020-09-14Add documentation to public fields of UCred structJoe Ellis-1/+8
2020-09-14Move Unix peer credentials tests to their own fileJoe Ellis-20/+16