about summary refs log tree commit diff
path: root/library/std/src/sys
AgeCommit message (Collapse)AuthorLines
2020-11-16Use syscall! for copy_file_range tooJosh Stone-9/+9
2020-11-16Try weak symbols for all linux syscall! wrappersJosh Stone-17/+8
2020-11-16linux: try to use libc getrandom to allow interpositionJosh Stone-5/+31
We'll try to use a weak `getrandom` symbol first, because that allows things like `LD_PRELOAD` interposition. For example, perf measurements might want to disable randomness to get reproducible results. If the weak symbol is not found, we fall back to a raw `SYS_getrandom` call.
2020-11-15Make the libstd build script smallerbjorn3-0/+71
Remove all rustc-link-lib from the std build script. Also remove use of feature = "restricted-std" where not necessary.
2020-11-15Rollup merge of #78988 - alexcrichton:one-more-intrinsic, r=sfacklerDylan DPC-1/+1
Fix an intrinsic invocation on threaded wasm This looks like it was forgotten to get updated in #74482 and wasm with threads isn't built on CI so we didn't catch this by accident.
2020-11-14Disambiguate symlink argument namesDavid Tolnay-49/+54
2020-11-14Auto merge of #75272 - the8472:spec-copy, r=KodrAusbors-77/+826
specialize io::copy to use copy_file_range, splice or sendfile Fixes #74426. Also covers #60689 but only as an optimization instead of an official API. The specialization only covers std-owned structs so it should avoid the problems with #71091 Currently linux-only but it should be generalizable to other unix systems that have sendfile/sosplice and similar. There is a bit of optimization potential around the syscall count. Right now it may end up doing more syscalls than the naive copy loop when doing short (<8KiB) copies between file descriptors. The test case executes the following: ``` [pid 103776] statx(3, "", AT_STATX_SYNC_AS_STAT|AT_EMPTY_PATH, STATX_ALL, {stx_mask=STATX_ALL|STATX_MNT_ID, stx_attributes=0, stx_mode=S_IFREG|0644, stx_size=17, ...}) = 0 [pid 103776] write(4, "wxyz", 4) = 4 [pid 103776] write(4, "iklmn", 5) = 5 [pid 103776] copy_file_range(3, NULL, 4, NULL, 5, 0) = 5 ``` 0-1 `stat` calls to identify the source file type. 0 if the type can be inferred from the struct from which the FD was extracted 𝖬 `write` to drain the `BufReader`/`BufWriter` wrappers. only happen when buffers are present. 𝖬 ≾ number of wrappers present. If there is a write buffer it may absorb the read buffer contents first so only result in a single write. Vectored writes would also be an option but that would require more invasive changes to `BufWriter`. 𝖭 `copy_file_range`/`splice`/`sendfile` until file size, EOF or the byte limit from `Take` is reached. This should generally be *much* more efficient than the read-write loop and also have other benefits such as DMA offload or extent sharing. ## Benchmarks ``` OLD test io::tests::bench_file_to_file_copy ... bench: 21,002 ns/iter (+/- 750) = 6240 MB/s [ext4] test io::tests::bench_file_to_file_copy ... bench: 35,704 ns/iter (+/- 1,108) = 3671 MB/s [btrfs] test io::tests::bench_file_to_socket_copy ... bench: 57,002 ns/iter (+/- 4,205) = 2299 MB/s test io::tests::bench_socket_pipe_socket_copy ... bench: 142,640 ns/iter (+/- 77,851) = 918 MB/s NEW test io::tests::bench_file_to_file_copy ... bench: 14,745 ns/iter (+/- 519) = 8889 MB/s [ext4] test io::tests::bench_file_to_file_copy ... bench: 6,128 ns/iter (+/- 227) = 21389 MB/s [btrfs] test io::tests::bench_file_to_socket_copy ... bench: 13,767 ns/iter (+/- 3,767) = 9520 MB/s test io::tests::bench_socket_pipe_socket_copy ... bench: 26,471 ns/iter (+/- 6,412) = 4951 MB/s ```
2020-11-13Tighten the bounds on atomic Ordering in std::sys::unix::weakThom Chiovoloni-6/+40
2020-11-13Always handle EOVERFLOW by falling back to the generic copy loopThe8472-11/+9
Previously EOVERFLOW handling was only applied for io::copy specialization but not for fs::copy sharing the same code. Additionally we lower the chunk size to 1GB since we have a user report that older kernels may return EINVAL when passing 0x8000_0000 but smaller values succeed.
2020-11-13do direct splice syscall and probe availability to get android builds to workThe8472-4/+72
Android builds use feature level 14, the libc wrapper for splice is gated on feature level 21+ so we have to invoke the syscall directly. Additionally the emulator doesn't seem to support it so we also have to add ENOSYS checks.
2020-11-13move sendfile/splice/copy_file_range into kernel_copy moduleThe8472-153/+150
2020-11-13limit visibility of copy offload helpers to sys::unix moduleThe8472-4/+186
2020-11-13move copy specialization into sys::unix moduleThe8472-15/+427
2020-11-13reduce syscalls by inferring FD types based on source struct instead of ↵The8472-27/+56
calling stat() also adds handling for edge-cases involving large sparse files where sendfile could fail with EOVERFLOW
2020-11-13hide unused exports on other platformsThe8472-2/+2
2020-11-13specialize io::copy to use copy_file_range, splice or sendfileThe8472-6/+69
Currently it only applies to linux systems. It can be extended to make use of similar syscalls on other unix systems.
2020-11-12Upgrading dlmalloc to 0.2.1Raoul Strackx-2/+58
2020-11-12Add missing stability attributeMohsen Zohrevandi-0/+2
2020-11-12Fix an intrinsic invocation on threaded wasmAlex Crichton-1/+1
This looks like it was forgotten to get updated in #74482 and wasm with threads isn't built on CI so we didn't catch this by accident.
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-11Add Metadata in std::os::fortanix_sgx::io::FromRawFdMohsen Zohrevandi-10/+33
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-07Refactor `parse_prefix` on WindowsChristiaan Dirkx-78/+135
Refactor `get_first_two_components` to `get_next_component`. Fixes the following behaviour of `parse_prefix`: - series of separator bytes in a prefix are correctly parsed as a single separator - device namespace prefixes correctly recognize both `\\` and `/` as separators
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-11-04Fix docs for MacOs (again)LinkTed-1/+2
2020-11-03Fix docs for MacOs (correction)LinkTed-1/+2
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-28Fix test cases for MacOsLinkTed-2/+28
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