summary refs log tree commit diff
path: root/library/std/src/sys
AgeCommit message (Collapse)AuthorLines
2021-03-22fix io::copy specialization when writer was opened with O_APPENDThe8472-8/+10
2021-03-22add test for failing io::copy specializationThe8472-0/+18
2021-03-22std: Fix a bug on the wasm32-wasi target opening filesAlex Crichton-4/+2
This commit fixes an issue pointed out in #82758 where LTO changed the behavior of a program. It turns out that LTO was not at fault here, it simply uncovered an existing bug. The bindings to `__wasilibc_find_relpath` assumed that the relative portion of the path returned was always contained within thee input `buf` we passed in. This isn't actually the case, however, and sometimes the relative portion of the path may reference a sub-portion of the input string itself. The fix here is to use the relative path pointer coming out of `__wasilibc_find_relpath` as the source of truth. The `buf` used for local storage is discarded in this function and the relative path is copied out unconditionally. We might be able to get away with some `Cow`-like business or such to avoid the extra allocation, but for now this is probably the easiest patch to fix the original issue.
2021-02-24Disable use of accept4 on x86 Android.Maarten de Vries-1/+1
On x86 before Linux 4.3, accept4 is not a separate syscall. Instead, it can be called using `socketcall(SYS_ACCEPT4, ...). Rather than implementing that here, just fall back to `accept`.
2021-02-05Rollup merge of #81542 - RReverser:wasi-symlink, r=alexcrichtonMara Bos-0/+8
Expose correct symlink API on WASI As described in https://github.com/rust-lang/rust/issues/68574, the currently exposed API for symlinks is, in fact, a thin wrapper around the corresponding syscall, and not suitable for public usage. The reason is that the 2nd param in the call is expected to be a handle of a "preopened directory" (a WASI concept for exposing dirs), and the only way to retrieve such handle right now is by tinkering with a private `__wasilibc_find_relpath` API, which is an implementation detail and definitely not something we want users to call directly. Making matters worse, the semantics of this param aren't obvious from its name (`fd`), and easy to misinterpret, resulting in people trying to pass a handle of the target file itself (as in https://github.com/vitiral/path_abs/pull/50), which doesn't work as expected. I did a [codesearch among open-source repos](https://sourcegraph.com/search?q=std%3A%3Aos%3A%3Awasi%3A%3Afs%3A%3Asymlink&patternType=literal), and the usage above is so far the only usage of this API at all, but we should fix it before more people start using it incorrectly. While this is technically a breaking API change, I believe it's a justified one, as 1) it's OS-specific and 2) there was strictly no way to correctly use the previous form of the API, and if someone does use it, they're likely doing it wrong like in the example above. The new API does not lead to the same confusion, as it mirrors `std::os::unix::fs::symlink` and `std::os::windows::fs::symlink_{file,dir}` variants by accepting source/target paths. Fixes #68574. r? ``@alexcrichton``
2021-02-03Restore comment as it wasIngvar Stepanyan-0/+2
2021-02-03Keep old symlink; expose new symlink_pathIngvar Stepanyan-4/+14
2021-02-02Rollup merge of #81530 - ojeda:sys-use-abort-instead-of-wasm32-unreachable, ↵Jack Huey-1/+1
r=Mark-Simulacrum sys: use `process::abort()` instead of `arch::wasm32::unreachable()` Rationale: - `abort()` lowers to `wasm32::unreachable()` anyway. - `abort()` isn't `unsafe`. - `abort()` matches the comment better. - `abort()` avoids confusion by future readers (e.g. https://github.com/rust-lang/rust/pull/81527): the naming of wasm's `unreachable` instruction is a bit unfortunate because it is not related to the `unreachable()` intrinsic (intended to trigger UB). Codegen is likely to be different since `unreachable()` is `inline` while `abort()` is `cold`. Since it doesn't look like we are expecting here to trigger this case, the latter seems better anyway.
2021-01-31Fix calling convention for CRT startupArlie Davis-12/+10
My PR #81478 used the wrong calling convention for a set of functions that are called by the CRT. These functions need to use `extern "C"`. This would only affect x86, which is the only target (that I know of) that has multiple calling conventions.
2021-01-30Expose correct symlink API on WASIIngvar Stepanyan-9/+5
As described in https://github.com/rust-lang/rust/issues/68574, the currently exposed API for symlinks is, in fact, a thin wrapper around the corresponding syscall, and not suitable for public usage. The reason is that the 2nd param in the call is expected to be a handle of a "preopened directory" (a WASI concept for exposing dirs), and the only way to retrieve such handle right now is by tinkering with a private `__wasilibc_find_relpath` API, which is an implementation detail and definitely not something we want users to call directly. Making matters worse, the semantics of this param aren't obvious from its name (`fd`), and easy to misinterpret, resulting in people trying to pass a handle of the target file itself (as in https://github.com/vitiral/path_abs/pull/50), which doesn't work as expected. I did a codesearch among open-source repos, and the usage above is so far the only usage of this API at all, but we should fix it before more people start using it incorrectly. While this is technically a breaking API change, I believe it's a justified one, as 1) it's OS-specific and 2) there was strictly no way to correctly use the previous form of the API, and if someone does use it, they're likely doing it wrong like in the example above. The new API does not lead to the same confusion, as it mirrors `std::os::unix::fs::symlink` and `std::os::windows::fs::symlink_{file,dir}` variants by accepting source/target paths. Fixes #68574.
2021-01-29sys: use `process::abort()` instead of `arch::wasm32::unreachable()`Miguel Ojeda-1/+1
Rationale: - `abort()` lowers to `wasm32::unreachable()` anyway. - `abort()` isn't `unsafe`. - `abort()` matches the comment better. - `abort()` avoids confusion by future readers (e.g. https://github.com/rust-lang/rust/pull/81527): the naming of wasm's `unreachable' instruction is a bit unfortunate because it is not related to the `unreachable()` intrinsic (intended to trigger UB). Codegen is likely to be different since `unreachable()` is `inline` while `abort()` is `cold`. Since it doesn't look like we are expecting here to trigger this case, the latter seems better anyway. Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2021-01-29Resolve DLL imports at CRT startup, not on demandArlie Davis-71/+95
On Windows, libstd uses GetProcAddress to locate some DLL imports, so that libstd can run on older versions of Windows. If a given DLL import is not present, then libstd uses other behavior (such as fallback implementations). This commit uses a feature of the Windows CRT to do these DLL imports during module initialization, before main() (or DllMain()) is called. This is the ideal time to resolve imports, because the module is effectively single-threaded at that point; no other threads can touch the data or code of the module that is being initialized. This avoids several problems. First, it makes the cost of performing the DLL import lookups deterministic. Right now, the DLL imports are done on demand, which means that application threads _might_ have to do the DLL import during some time-sensitive operation. This is a small source of unpredictability. Since threads can race, it's even possible to have more than one thread running the same redundant DLL lookup. This commit also removes using the heap to allocate strings, during the DLL lookups.
2021-01-24Auto merge of #81250 - sivadeilra:remove_xp_compat, r=joshtriplett,m-ou-sebors-145/+81
Remove delay-binding for Win XP and Vista The minimum supported Windows version is now Windows 7. Windows XP and Windows Vista are no longer supported; both are already broken, and require extra steps to use. This commit removes the delayed-binding support for Windows API functions that are present on all supported Windows targets. This has several benefits: Removes needless complexity. Removes a load and dynamic call on hot paths in mutex acquire / release. This may have performance benefits. * "Drop official support for Windows XP" https://github.com/rust-lang/compiler-team/issues/378 * "Firefox has ended support for Windows XP and Vista" https://support.mozilla.org/en-US/kb/end-support-windows-xp-and-vista
2021-01-22Remove delay-binding for Win XP and VistaArlie Davis-145/+81
The minimum supported Windows version is now Windows 7. Windows XP and Windows Vista are no longer supported; both are already broken, and require extra steps to use. This commit removes the delayed-binding support for Windows API functions that are present on all supported Windows targets. This has several benefits: Removes needless complexity. Removes a load and dynamic call on hot paths in mutex acquire / release. This may have performance benefits. * "Drop official support for Windows XP" https://github.com/rust-lang/compiler-team/issues/378 * "Firefox has ended support for Windows XP and Vista" https://support.mozilla.org/en-US/kb/end-support-windows-xp-and-vista
2021-01-21Add setgroups to std::os::unix::process::CommandExtslo1-7/+41
2021-01-20Deprecate-in-future the constants superceded by RFC 2700bstrie-1/+0
2021-01-19Auto merge of #79578 - alexcrichton:update-waasi, r=KodrAusbors-22/+78
std: Update wasi-libc commit of the wasm32-wasi target This brings in an implementation of `current_dir` and `set_current_dir` (emulation in `wasi-libc`) as well as an updated version of finding relative paths. This also additionally updates clang to the latest release to build wasi-libc with.
2021-01-17Don't use posix_spawn_file_actions_addchdir_np on macOS.Eric Huss-4/+14
2021-01-14std: Update wasi-libc commit of the wasm32-wasi targetAlex Crichton-22/+78
This brings in an implementation of `current_dir` and `set_current_dir` (emulation in `wasi-libc`) as well as an updated version of finding relative paths. This also additionally updates clang to the latest release to build wasi-libc with.
2021-01-14Rollup merge of #80966 - KodrAus:deprecate/spin_loop_hint, r=m-ou-seMara Bos-4/+6
Deprecate atomic::spin_loop_hint in favour of hint::spin_loop For https://github.com/rust-lang/rust/issues/55002 We wanted to leave `atomic::spin_loop_hint` alone when stabilizing `hint::spin_loop` so folks had some time to migrate. This now deprecates `atomic_spin_loop_hint`.
2021-01-14Rollup merge of #79982 - ijackson:exit-status, r=dtolnayMara Bos-3/+131
Add missing methods to unix ExitStatusExt These are the methods corresponding to the remaining exit status examination macros from `wait.h`. `WCOREDUMP` isn't in SuS but is it is very standard. I have not done portability testing to see if this builds everywhere, so I may need to Do Something if it doesn't. There is also a bugfix and doc improvement to `.signal()`, and an `.into_raw()` accessor. This would fix #73128 and fix #73129. Please let me know if you like this direction, and if so I will open the tracking issue and so on. If this MR goes well, I may tackle #73125 next - I have an idea for how to do it.
2021-01-13Fix typos in Fuchsia unix_process_wait_moreDavid Tolnay-2/+2
2021-01-13ExitStatusExt: Fix build on FuchsiaIan Jackson-0/+44
This is not particularly pretty but the current situation is a mess and I don't think I'm making it significantly worse. Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-01-13Fix typo saeled -> sealedDavid Tolnay-2/+2
2021-01-13ExitStatusExt windows: Retrospectively seal this traitIan Jackson-1/+15
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-01-13ExitStatusExt unix: Retrospectively seal this traitIan Jackson-1/+15
As discussed in #79982. I think the "new interfaces", ie the new trait and impl, must be insta-stable. This seems OK because we are, in fact, adding a new restriction to the stable API. Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-01-13unix ExitStatus: Add tracking issue to new methodsIan Jackson-4/+4
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-01-13Replace `Ie` with `In other words`Ian Jackson-1/+1
Co-authored-by: Joshua Nelson <joshua@yottadb.com>
2021-01-13Replace `Ie` with `In other words`Ian Jackson-1/+1
Co-authored-by: Joshua Nelson <joshua@yottadb.com>
2021-01-13unix ExitStatus: Provide .continued()Ian Jackson-0/+15
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-01-13unix ExitStatus: Provide .stopped_signal()Ian Jackson-0/+15
Necessary to handle WIFSTOPPED. Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-01-13unix ExitStatus: Provide .core_dumpedIan Jackson-0/+12
This is essential for proper reporting of child process status on Unix. Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-01-13unix ExitStatus: Provide .into_raw()Ian Jackson-0/+12
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-01-13unix ExitStatus: Clarify docs for .signal()Ian Jackson-0/+2
We need to be clear that this never returns WSTOPSIG. That is, if WIFSTOPPED, the return value is None. Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-01-13unix ExitStatus: Do not treat WIFSTOPPED as WIFSIGNALEDIan Jackson-1/+1
A unix wait status can contain, at least, exit statuses, termination signals, and stop signals. WTERMSIG is only valid if WIFSIGNALED. https://pubs.opengroup.org/onlinepubs/9699919799/functions/wait.html It will not be easy to experience this bug with `Command`, because that doesn't pass WUNTRACED. But you could make an ExitStatus containing, say, a WIFSTOPPED, from a call to one of the libc wait functions. (In the WIFSTOPPED case, there is WSTOPSIG. But a stop signal is encoded differently to a termination signal, so WTERMSIG and WSTOPSIG are by no means the same.) Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-01-13Update code to account for extern ABI requirementMark Rousskov-1/+1
2021-01-13deprecate atomic::spin_loop_hint in favour of hint::spin_loopAshley Mannix-4/+6
2020-12-29Fix small typo in time commentBlackHoleFox-1/+1
2020-12-22Update library/std/src/sys/windows/thread_parker.rsLinus Färnstrand-1/+1
Co-authored-by: Mara Bos <m-ou.se@m-ou.se>
2020-12-22Fix compare_and_swap in Windows thread_parkerLinus Färnstrand-1/+1
2020-12-22Migrate standard library away from compare_and_swapLinus Färnstrand-8/+8
2020-12-21Auto merge of #80088 - operutka:fix-cmsg-len-uclibc, r=dtolnaybors-1/+5
Fix failing build of std on armv5te-unknown-linux-uclibceabi due to missing cmsg_len_zero I'm getting the following error when trying to build `std` on `armv5te-unknown-linux-uclibceabi`: ``` error[E0425]: cannot find value `cmsg_len_zero` in this scope --> /home/operutka/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/sys/unix/ext/net/ancillary.rs:376:47 | 376 | let data_len = (*cmsg).cmsg_len - cmsg_len_zero; | ^^^^^^^^^^^^^ not found in this scope ``` Obviously, this branch: ```rust cfg_if::cfg_if! { if #[cfg(any(target_os = "android", all(target_os = "linux", target_env = "gnu")))] { let cmsg_len_zero = libc::CMSG_LEN(0) as libc::size_t; } else if #[cfg(any( target_os = "dragonfly", target_os = "emscripten", target_os = "freebsd", all(target_os = "linux", target_env = "musl",), target_os = "netbsd", target_os = "openbsd", ))] { let cmsg_len_zero = libc::CMSG_LEN(0) as libc::socklen_t; } } ``` does not cover the case `all(target_os = "linux", target_env = "uclibc")`.
2020-12-20Auto merge of #74699 - notriddle:fd-non-negative, r=m-ou-sebors-2/+9
Mark `-1` as an available niche for file descriptors Based on discussion from <https://internals.rust-lang.org/t/can-the-standard-library-shrink-option-file/12768>, the file descriptor `-1` is chosen based on the POSIX API designs that use it as a sentinel to report errors. A bigger niche could've been chosen, particularly on Linux, but would not necessarily be portable. This PR also adds a test case to ensure that the -1 niche (which is kind of hacky and has no obvious test case) works correctly. It requires the "upper" bound, which is actually -1, to be expressed in two's complement.
2020-12-20Check that c_int is i32 in FileDesc::new.Mara Bos-1/+1
2020-12-16Fix failing build of std on armv5te-unknown-linux-uclibceabi due to missing ↵Ondrej Perutka-1/+5
cmsg_len_zero
2020-12-16Auto merge of #78833 - CDirkx:parse_prefix, r=dtolnaybors-78/+135
Refactor and fix `parse_prefix` on Windows This PR is an extension of #78692 as well as a general refactor of `parse_prefix`: **Fixes**: There are two errors in the current implementation of `parse_prefix`: Firstly, in the current implementation only `\` is recognized as a separator character in device namespace prefixes. This behavior is only correct for verbatim paths; `"\\.\C:/foo"` should be parsed as `"C:"` instead of `"C:/foo"`. Secondly, the current implementation only handles single separator characters. In non-verbatim paths a series of separator characters should be recognized as a single boundary, e.g. the UNC path `"\\localhost\\\\\\C$\foo"` should be parsed as `"\\localhost\\\\\\C$"` and then `UNC(server: "localhost", share: "C$")`, but currently it is not parsed at all, because it starts being parsed as `\\localhost\` and then has an invalid empty share location. Paths like `"\\.\C:/foo"` and `"\\localhost\\\\\\C$\foo"` are valid on Windows, they are equivalent to just `"C:\foo"`. **Refactoring**: All uses of `&[u8]` within `parse_prefix` are extracted to helper functions and`&OsStr` is used instead. This reduces the number of places unsafe is used: - `get_first_two_components` is adapted to the more general `parse_next_component` and used in more places - code for parsing drive prefixes is extracted to `parse_drive`
2020-12-14Auto merge of #77618 - fusion-engineering-forks:windows-parker, r=Amanieubors-0/+299
Add fast futex-based thread parker for Windows. This adds a fast futex-based thread parker for Windows. It either uses WaitOnAddress+WakeByAddressSingle or NT Keyed Events (NtWaitForKeyedEvent+NtReleaseKeyedEvent), depending on which is available. Together, this makes this thread parker work for Windows XP and up. Before this change, park()/unpark() did not work on Windows XP: it needs condition variables, which only exist since Windows Vista. --- Unfortunately, NT Keyed Events are an undocumented Windows API. However: - This API is relatively simple with obvious behaviour, and there are several (unofficial) articles documenting the details. [1] - parking_lot has been using this API for years (on Windows versions before Windows 8). [2] Many big projects extensively use parking_lot, such as servo and the Rust compiler itself. - It is the underlying API used by Windows SRW locks and Windows critical sections. [3] [4] - The source code of the implementations of Wine, ReactOs, and Windows XP are available and match the expected behaviour. - The main risk with an undocumented API is that it might change in the future. But since we only use it for older versions of Windows, that's not a problem. - Even if these functions do not block or wake as we expect (which is unlikely, see all previous points), this implementation would still be memory safe. The NT Keyed Events API is only used to sleep/block in the right place. [1]\: http://www.locklessinc.com/articles/keyed_events/ [2]\: https://github.com/Amanieu/parking_lot/commit/43abbc964e [3]\: https://docs.microsoft.com/en-us/archive/msdn-magazine/2012/november/windows-with-c-the-evolution-of-synchronization-in-windows-and-c [4]\: Windows Internals, Part 1, ISBN 9780735671300 --- The choice of fallback API is inspired by parking_lot(_core), but the implementation of this thread parker is different. While parking_lot has no use for a fast path (park() directly returning if unpark() was already called), this implementation has a fast path that returns without even checking which waiting/waking API to use, as the same atomic variable with compatible states is used in all cases.
2020-12-11Auto merge of #79893 - RalfJung:forget-windows, r=oli-obkbors-7/+4
Windows TLS: ManuallyDrop instead of mem::forget The Windows TLS implementation still used `mem::forget` instead of `ManuallyDrop`, leading to the usual problem of "using" the `Box` when it should not be used any more.
2020-12-10Rollup merge of #79375 - vext01:kernel-copy-temps, r=bjorn3Tyler Mandry-8/+11
Make the kernel_copy tests more robust/concurrent. These tests write to the same filenames in /tmp and in some cases these files don't get cleaned up properly. This caused issues for us when different users run the tests on the same system, e.g.: ``` ---- sys::unix::kernel_copy::tests::bench_file_to_file_copy stdout ---- thread 'sys::unix::kernel_copy::tests::bench_file_to_file_copy' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 13, kind: PermissionDenied, message: "Permission denied" }', library/std/src/sys/unix/kernel_copy/tests.rs:71:10 ---- sys::unix::kernel_copy::tests::bench_file_to_socket_copy stdout ---- thread 'sys::unix::kernel_copy::tests::bench_file_to_socket_copy' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 13, kind: PermissionDenied, message: "Permission denied" }', library/std/src/sys/unix/kernel_copy/tests.rs💯10 ``` Use `std::sys_common::io__test::tmpdir()` to solve this. CC ``@the8472.``
2020-12-10Fix fd test caseMichael Howell-1/+1