summary refs log tree commit diff
path: root/library/std/src/sys
AgeCommit message (Collapse)AuthorLines
2020-12-08[beta] always disable copy_file_range to avoid EOVERFLOW errorsThe8472-1/+1
2020-11-12Auto merge of #78965 - jryans:emscripten-threads-libc, r=kennytmbors-20/+42
Update thread and futex APIs to work with Emscripten This updates the thread and futex APIs in `std` to match the APIs exposed by Emscripten. This allows threads to run on `wasm32-unknown-emscripten` and the thread parker to compile without errors related to the missing `futex` module. To make use of this, Rust code must be compiled with `-C target-feature=atomics` and Emscripten must link with `-pthread`. I have confirmed this works well locally when building multithreaded crates. Attempting to enable `std` thread tests currently fails for seemingly obscure reasons and Emscripten is currently disabled in CI, so further work is needed to have proper test coverage here.
2020-11-12Fix timeout conversionJ. Ryan Stinnett-2/+1
2020-11-12Update thread and futex APIs to work with EmscriptenJ. Ryan Stinnett-20/+43
This updates the thread and futex APIs in `std` to match the APIs exposed by Emscripten. This allows threads to run on `wasm32-unknown-emscripten` and the thread parker to compile without errors related to the missing `futex` module. To make use of this, Rust code must be compiled with `-C target-feature=atomics` and Emscripten must link with `-pthread`. I have confirmed this works well locally when building multithreaded crates. Attempting to enable `std` thread tests currently fails for seemingly obscure reasons and Emscripten is currently disabled in CI, so further work is needed to have proper test coverage here.
2020-11-09Rollup merge of #78878 - shepmaster:intersecting-ignores, r=Mark-SimulacrumDylan DPC-10/+15
Avoid overlapping cfg attributes when both macOS and aarch64 r? ``@Mark-Simulacrum``
2020-11-09Rollup merge of #78026 - sunfishcode:symlink-hard-link, r=dtolnayDylan DPC-1/+14
Define `fs::hard_link` to not follow symlinks. POSIX leaves it [implementation-defined] whether `link` follows symlinks. In practice, for example, on Linux it does not and on FreeBSD it does. So, switch to `linkat`, so that we can pick a behavior rather than depending on OS defaults. Pick the option to not follow symlinks. This is somewhat arbitrary, but seems the less surprising choice because hard linking is a very low-level feature which requires the source and destination to be on the same mounted filesystem, and following a symbolic link could end up in a different mounted filesystem. [implementation-defined]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/link.html
2020-11-08Avoid overlapping cfg attributes when both macOS and aarch64Jake Goulding-10/+15
2020-11-08Rollup merge of #78852 - camelid:intra-doc-bonanza, r=jyn514Mara Bos-7/+7
Convert a bunch of intra-doc links An intra-doc link bonanza! This was accomplished using a bunch of trial-and-error with sed.
2020-11-08Rollup merge of #78572 - de-vri-es:bsd-cloexec, r=m-ou-seMara Bos-6/+38
Use SOCK_CLOEXEC and accept4() on more platforms. This PR enables the use of `SOCK_CLOEXEC` and `accept4` on more platforms. ----- Android uses the linux kernel, so it should also support it. DragonflyBSD introduced them in 4.4 (December 2015): https://www.dragonflybsd.org/release44/ FreeBSD introduced them in 10.0 (January 2014): https://wiki.freebsd.org/AtomicCloseOnExec Illumos introduced them in a commit in April 2013, not sure when it was released. It is quite possible that is has always been in Illumos: https://github.com/illumos/illumos-gate/commit/5dbfd19ad5fcc2b779f40f80fa05c1bd28fd0b4e https://illumos.org/man/3socket/socket https://illumos.org/man/3socket/accept4 NetBSD introduced them in 6.0 (Oktober 2012) and 8.0 (July 2018): https://man.netbsd.org/NetBSD-6.0/socket.2 https://man.netbsd.org/NetBSD-8.0/accept.2 OpenBSD introduced them in 5.7 (May 2015): https://man.openbsd.org/socket https://man.openbsd.org/accept
2020-11-07Convert a bunch of intra-doc linksCamelid-7/+7
2020-11-07Rollup merge of #74979 - maekawatoshiki:fix, r=Mark-SimulacrumYuki Okushi-0/+2
`#![deny(unsafe_op_in_unsafe_fn)]` in sys/hermit Partial fix of #73904. This encloses ``unsafe`` operations in ``unsafe fn`` in ``sys/hermit``. Some unsafe blocks are not well documented because some system-based functions lack documents.
2020-11-06Disable accept4 on Android.Maarten de Vries-1/+7
2020-10-31fix aliasing issue in unix sleep functionRalf Jung-1/+2
2020-10-30Use SOCK_CLOEXEC and accept4() on more platforms.Maarten de Vries-6/+32
2020-10-26Rollup merge of #74477 - chansuke:sys-wasm-unsafe-op-in-unsafe-fn, ↵Dylan DPC-15/+38
r=Mark-Simulacrum `#[deny(unsafe_op_in_unsafe_fn)]` in sys/wasm This is part of #73904. This encloses unsafe operations in unsafe fn in `libstd/sys/wasm`. @rustbot modify labels: F-unsafe-block-in-unsafe-fn
2020-10-24Rollup merge of #77610 - hermitcore:dtors, r=m-ou-seJonas Schievink-163/+182
revise Hermit's mutex interface to support the behaviour of StaticMutex rust-lang/rust#77147 simplifies things by splitting this Mutex type into two types matching the two use cases: StaticMutex and MovableMutex. To support the new behavior of StaticMutex, we move part of the mutex implementation into libstd. The interface to the OS changed. Consequently, I removed a few functions, which aren't longer needed.
2020-10-24Rollup merge of #75115 - chansuke:sys-cloudabi-unsafe, r=KodrAusJonas Schievink-64/+75
`#[deny(unsafe_op_in_unsafe_fn)]` in sys/cloudabi Partial fix of #73904. This encloses unsafe operations in unsafe fn in sys/cloudabi.
2020-10-24Disable use of `linkat` on Android as well.Dan Gohman-5/+5
According to [the bionic status page], `linkat` has only been available since API level 21. Since Android is based on Linux and Linux's `link` doesn't follow symlinks, just use `link` on Android. [the bionic status page]: https://android.googlesource.com/platform/bionic/+/master/docs/status.md
2020-10-24Remove unnecessary unsafe block from condvar_atomics & mutex_atomicschansuke-3/+3
2020-10-24Fix unsafe operation of wasm32::memory_atomic_notifychansuke-1/+2
2020-10-24Add documents for DLMALLOCchansuke-4/+8
2020-10-24Add some description for (malloc/calloc/free/realloc)chansuke-0/+4
2020-10-24`#[deny(unsafe_op_in_unsafe_fn)]` in sys/wasmchansuke-18/+32
2020-10-20Check that pthread mutex initialization succeededTomasz Miąsko-22/+27
If pthread mutex initialization fails, the failure will go unnoticed unless debug assertions are enabled. Any subsequent use of mutex will also silently fail, since return values from lock & unlock operations are similarly checked only through debug assertions. In some implementations the mutex initialization requires a memory allocation and so it does fail in practice. Check that initialization succeeds to ensure that mutex guarantees mutual exclusion.
2020-10-18Remove redundant 'static from library cratesest31-8/+8
2020-10-18Use `link` on platforms which lack `linkat`.Dan Gohman-4/+14
2020-10-18Fix a typo in a comment.Dan Gohman-1/+1
2020-10-18`#[deny(unsafe_op_in_unsafe_fn)]` in sys/cloudabichansuke-64/+75
2020-10-17Auto merge of #77455 - asm89:faster-spawn, r=kennytmbors-1/+7
Use posix_spawn() on unix if program is a path Previously `Command::spawn` would fall back to the non-posix_spawn based implementation if the `PATH` environment variable was possibly changed. On systems with a modern (g)libc `posix_spawn()` can be significantly faster. If program is a path itself the `PATH` environment variable is not used for the lookup and it should be safe to use the `posix_spawnp()` method. [1] We found this, because we have a cli application that effectively runs a lot of subprocesses. It would sometimes noticeably hang while printing output. Profiling showed that the process was spending the majority of time in the kernel's `copy_page_range` function while spawning subprocesses. During this time the process is completely blocked from running, explaining why users were reporting the cli app hanging. Through this we discovered that `std::process::Command` has a fast and slow path for process execution. The fast path is backed by `posix_spawnp()` and the slow path by fork/exec syscalls being called explicitly. Using fork for process creation is supposed to be fast, but it slows down as your process uses more memory. It's not because the kernel copies the actual memory from the parent, but it does need to copy the references to it (see `copy_page_range` above!). We ended up using the slow path, because the command spawn implementation in falls back to the slow path if it suspects the PATH environment variable was changed. Here is a smallish program demonstrating the slowdown before this code change: ``` use std::process::Command; use std::time::Instant; fn main() { let mut args = std::env::args().skip(1); if let Some(size) = args.next() { // Allocate some memory let _xs: Vec<_> = std::iter::repeat(0) .take(size.parse().expect("valid number")) .collect(); let mut command = Command::new("/bin/sh"); command .arg("-c") .arg("echo hello"); if args.next().is_some() { println!("Overriding PATH"); command.env("PATH", std::env::var("PATH").expect("PATH env var")); } let now = Instant::now(); let child = command .spawn() .expect("failed to execute process"); println!("Spawn took: {:?}", now.elapsed()); let output = child.wait_with_output().expect("failed to wait on process"); println!("Output: {:?}", output); } else { eprintln!("Usage: prog [size]"); std::process::exit(1); } () } ``` Running it and passing different amounts of elements to use to allocate memory shows that the time taken for `spawn()` can differ quite significantly. In latter case the `posix_spawnp()` implementation is 30x faster: ``` $ cargo run --release 10000000 ... Spawn took: 324.275µs hello $ cargo run --release 10000000 changepath ... Overriding PATH Spawn took: 2.346809ms hello $ cargo run --release 100000000 ... Spawn took: 387.842µs hello $ cargo run --release 100000000 changepath ... Overriding PATH Spawn took: 13.434677ms hello ``` [1]: https://github.com/bminor/glibc/blob/5f72f9800b250410cad3abfeeb09469ef12b2438/posix/execvpe.c#L81
2020-10-17Rollup merge of #77900 - Thomasdezeeuw:fdatasync, r=dtolnayYuki Okushi-2/+16
Use fdatasync for File::sync_data on more OSes Add support for the following OSes: * Android * FreeBSD: https://www.freebsd.org/cgi/man.cgi?query=fdatasync&sektion=2 * OpenBSD: https://man.openbsd.org/OpenBSD-5.8/fsync.2 * NetBSD: https://man.netbsd.org/fdatasync.2 * illumos: https://illumos.org/man/3c/fdatasync
2020-10-16Define `fs::hard_link` to not follow symlinks.Dan Gohman-1/+4
POSIX leaves it implementation-defined whether `link` follows symlinks. In practice, for example, on Linux it does not and on FreeBSD it does. So, switch to `linkat`, so that we can pick a behavior rather than depending on OS defaults. Pick the option to not follow symlinks. This is somewhat arbitrary, but seems the less surprising choice because hard linking is a very low-level feature which requires the source and destination to be on the same mounted filesystem, and following a symbolic link could end up in a different mounted filesystem.
2020-10-16Take some of sys/vxworks/process/* from sys/unix instead.Mara Bos-407/+77
2020-10-16Take sys/vxworks/{os,path,pipe} from sys/unix instead.Mara Bos-446/+33
2020-10-16Take sys/vxworks/{fd,fs,io} from sys/unix instead.Mara Bos-909/+63
2020-10-16Take sys/vxworks/cmath from sys/unix instead.Mara Bos-32/+1
2020-10-16Take sys/vxworks/args from sys/unix instead.Mara Bos-96/+3
2020-10-16Take sys/vxworks/memchar from sys/unix instead.Mara Bos-21/+1
2020-10-16Take sys/vxworks/net from sys/unix instead.Mara Bos-360/+9
2020-10-16Take sys/vxworks/ext/* from sys/unix instead.Mara Bos-1321/+1
2020-10-16Add weak macro to vxworks.Mara Bos-0/+4
2020-10-16Take sys/vxworks/alloc from sys/unix instead.Mara Bos-49/+1
2020-10-16Take sys/vxworks/thread_local_key from sys/unix instead.Mara Bos-34/+1
2020-10-16Take sys/vxworks/stdio from sys/unix instead.Mara Bos-69/+1
2020-10-16Take sys/vxworks/thread from sys/unix instead.Mara Bos-158/+7
2020-10-16Take sys/vxworks/stack_overflow from sys/unix instead.Mara Bos-39/+2
2020-10-16Take sys/vxworks/time from sys/unix instead.Mara Bos-197/+1
2020-10-16Take sys/vxworks/rwlock from sys/unix instead.Mara Bos-114/+1
2020-10-16Take sys/vxworks/condvar from sys/unix instead.Mara Bos-91/+1
2020-10-16Take sys/vxworks/mutex from sys/unix instead.Mara Bos-133/+1
2020-10-16Rollup merge of #77657 - fusion-engineering-forks:cleanup-cloudabi-sync, ↵Dylan DPC-77/+65
r=dtolnay Cleanup cloudabi mutexes and condvars This gets rid of lots of unnecessary unsafety. All the AtomicU32s were wrapped in UnsafeCell or UnsafeCell<MaybeUninit>, and raw pointers were used to get to the AtomicU32 inside. This change cleans that up by using AtomicU32 directly. Also replaces a UnsafeCell<u32> by a safer Cell<u32>. @rustbot modify labels: +C-cleanup