about summary refs log tree commit diff
path: root/library/std/src/sys
AgeCommit message (Collapse)AuthorLines
2022-07-20Library changes for Apple WatchOSVladimir Michael Eatwell-20/+61
2022-07-20Rollup merge of #98916 - ChrisDenton:hiberfil.sys, r=thomccDylan DPC-26/+82
Windows: Use `FindFirstFileW` for getting the metadata of locked system files Fixes #96980 Usually opening a file handle with access set to metadata only will always succeed, even if the file is locked. However some special system files, such as `C:\hiberfil.sys`, are locked by the system in a way that denies even that. So as a fallback we try reading the cached metadata from the directory. Note that the test is a bit iffy. I don't know if `hiberfil.sys` actually exists in the CI. r? rust-lang/libs
2022-07-18std: panic instead of deadlocking in mutex implementation on Fuchsiajoboet-16/+15
2022-07-17Simplify Windows `hashmap_random_keys`Chris Denton-60/+8
2022-07-15Don't fall back to futimes on Android; it needs a newer API level than futimensJosh Triplett-7/+18
Just return `io::ErrorKind::Unsupported` instead.
2022-07-15Also use fallback for futimens on AndroidJosh Triplett-3/+3
futimens requires Android API level 19, and std still supports older API levels.
2022-07-15Return an error if trying to set a file timestamp to 0 on WindowsJosh Triplett-5/+12
This would otherwise silently ignore the attempt, since 0 serves as a flag to not set a timestamp.
2022-07-15Support setting file accessed/modified timestampsJosh Triplett-1/+143
Add `struct FileTimes` to contain the relevant file timestamps, since most platforms require setting all of them at once. (This also allows for future platform-specific extensions such as setting creation time.) Add `File::set_file_time` to set the timestamps for a `File`. Implement the `sys` backends for UNIX, macOS (which needs to fall back to `futimes` before macOS 10.13 because it lacks `futimens`), Windows, and WASI.
2022-07-12std: fix issue with perma-locked mutexes on Fuchsiajoboet-9/+20
2022-07-09Auto merge of #98950 - ChrisDenton:getoverlapped-io, r=thomccbors-8/+53
Windows: Fallback for overlapped I/O Fixes #98947
2022-07-07Rollup merge of #97917 - AronParker:master, r=ChrisDentonMatthias Krüger-0/+6
Implement ExitCodeExt for Windows Fixes #97914 ### Motivation: On Windows it is common for applications to return `HRESULT` (`i32`) or `DWORD` (`u32`) values. These stem from COM based components ([HRESULTS](https://docs.microsoft.com/en-us/windows/win32/api/objbase/nf-objbase-coinitialize)), Win32 errors ([GetLastError](https://docs.microsoft.com/en-us/windows/win32/api/errhandlingapi/nf-errhandlingapi-getlasterror)), GUI applications ([WM_QUIT](https://docs.microsoft.com/en-us/windows/win32/winmsg/wm-quit)) and more. The newly stabilized `ExitCode` provides an excellent fit for propagating these values, because `std::process::exit` does not run deconstructors which can result in errors. However, `ExitCode` currently only implements `From<u8> for ExitCode`, which disallows the full range of `i32`/`u32` values. This pull requests attempts to address that shortcoming by providing windows specific extensions that accept a `u32` value (which covers all possible `HRESULTS` and Win32 errors) analog to [ExitStatusExt::from_raw](https://doc.rust-lang.org/std/os/windows/process/trait.ExitStatusExt.html#tymethod.from_raw). This was also intended by the original Stabilization https://github.com/rust-lang/rust/pull/93840#issue-1129209143= as pointed out by ``@eggyal`` in https://github.com/rust-lang/rust/issues/97914#issuecomment-1151076755: > Issues around platform specific representations: We resolved this issue by changing the return type of report from i32 to the opaque type ExitCode. __That way we can change the underlying representation without affecting the API, letting us offer full support for platform specific exit code APIs in the future.__ [Emphasis added] ### API ```rust /// Windows-specific extensions to [`process::ExitCode`]. /// /// This trait is sealed: it cannot be implemented outside the standard library. /// This is so that future additional methods are not breaking changes. #[stable(feature = "windows_process_exit_code_from", since = "1.63.0")] pub trait ExitCodeExt: Sealed { /// Creates a new `ExitCode` from the raw underlying `u32` return value of /// a process. #[stable(feature = "windows_process_exit_code_from", since = "1.63.0")] fn from_raw(raw: u32) -> Self; } #[stable(feature = "windows_process_exit_code_from", since = "1.63.0")] impl ExitCodeExt for process::ExitCode { fn from_raw(raw: u32) -> Self { process::ExitCode::from_inner(From::from(raw)) } } ``` ### Misc I apologize in advance if I misplaced any attributes regarding stabilzation, as far as I learned traits are insta-stable so I chose to make them stable. If this is an error, please let me know and I'll correct it. I also added some additional machinery to make it work, analog to [ExitStatus](https://doc.rust-lang.org/std/process/struct.ExitStatus.html#). EDIT: Proposal: https://github.com/rust-lang/libs-team/issues/48
2022-07-06changes from feedbackDavid Carlier-12/+8
2022-07-06doc additionsDavid Carlier-0/+5
2022-07-06socket `set_mark` addition.David Carlier-0/+10
to be able to set a marker/id on the socket for network filtering (iptables/ipfw here) purpose.
2022-07-06Tests for unsound Windows file methodsChris Denton-0/+25
2022-07-06Windows: Fallback for overlapped I/OChris Denton-1/+26
Try waiting on the file handle once. If that fails then give up.
2022-07-06Use `rtabort!` instead of `process::abort`Chris Denton-7/+2
2022-07-05Windows: Use `FindFirstFileW` if `metadata` failsChris Denton-10/+61
Usually opening a file handle with access set to metadata only will always succeed, even if the file is locked. However some special system files, such as `C:\hiberfil.sys`, are locked by the system in a way that denies even that. So as a fallback we try reading the cached metadata from the directory.
2022-07-05`impl From<c::WIN32_FIND_DATAW> for FileAttr`Chris Denton-16/+21
2022-06-30std: use futex-based locks on Fuchsiajoboet-64/+246
2022-06-28Rollup merge of #98617 - ChrisDenton:const-unwrap, r=Mark-SimulacrumMatthias Krüger-4/+15
Remove feature `const_option` from std This is part of the effort to reduce the number of unstable features used by std. This one is easy as it's only used in one place.
2022-06-28Add a fixme commentChris Denton-0/+3
2022-06-28Remove feature `const_option` from stdChris Denton-4/+12
2022-06-28Rollup merge of #98555 - mkroening:hermit-lock-init, r=m-ou-seDylan DPC-9/+25
Hermit: Fix initializing lazy locks Closes https://github.com/hermitcore/rusty-hermit/issues/322. The initialization function of hermit's `Condvar` is not called since https://github.com/rust-lang/rust/pull/97647 and was erroneously removed in https://github.com/rust-lang/rust/pull/97879. r? ``@m-ou-se`` CC: ``@stlankes``
2022-06-27make Condvar, Mutex, RwLock const constructors work with unsupported implJorge Aparicio-0/+3
2022-06-26Hermit: Make Mutex::init a no-opMartin Kröning-3/+1
2022-06-26Hermit: Fix initializing lazy locksMartin Kröning-6/+24
2022-06-26Rollup merge of #97140 - joboet:solid_parker, r=m-ou-seMatthias Krüger-3/+119
std: use an event-flag-based thread parker on SOLID `Mutex` and `Condvar` are being replaced by more efficient implementations, which need thread parking themselves (see #93740). Therefore, the generic `Parker` needs to be replaced on all platforms where the new lock implementation will be used, which, after #96393, are SOLID, SGX and Hermit (more PRs coming soon). SOLID, conforming to the [μITRON specification](http://www.ertl.jp/ITRON/SPEC/FILE/mitron-400e.pdf), has event flags, which are a thread parking primitive very similar to `Parker`. However, they do not make any atomic ordering guarantees (even though those can probably be assumed) and necessitate a system call even when the thread token is already available. Hence, this `Parker`, like the Windows parker, uses an extra atomic state variable. I future-proofed the code by wrapping the event flag in a `WaitFlag` structure, as both SGX and Hermit can share the Parker implementation, they just have slightly different primitives (SGX uses signals and Hermit has a thread blocking API). `````@kawadakk````` I assume you are the target maintainer? Could you test this for me?
2022-06-25Rollup merge of #98194 - m-ou-se:leak-locked-pthread-mutex, r=AmanieuMatthias Krüger-1/+35
Leak pthread_{mutex,rwlock}_t if it's dropped while locked. Fixes https://github.com/rust-lang/rust/issues/85434.
2022-06-25Rollup merge of #98126 - fortanix:raoul/mitigate_stale_data_vulnerability, ↵Matthias Krüger-10/+142
r=cuviper Mitigate MMIO stale data vulnerability Intel publicly disclosed the MMIO stale data vulnerability on June 14. To mitigate this vulnerability, compiler changes are required for the `x86_64-fortanix-unknown-sgx` target. cc: ````@jethrogb````
2022-06-25Rollup merge of #96412 - ChrisDenton:remove-dir-all, r=thomccMatthias Krüger-75/+81
Windows: Iterative `remove_dir_all` This will allow better strategies for use of memory and File handles. However, fully taking advantage of that is left to future work. Note to reviewer: It's probably best to view the `remove_dir_all_recursive` as a new function. The diff is not very helpful (imho).
2022-06-24scan mountinfo when hardcoded cgroupv1 mountpoints don't workThe 8472-19/+83
2022-06-23Optimize `Wtf8Buf::into_string` for the case where it contains UTF-8.Dan Gohman-3/+1
Add a `is_known_utf8` flag to `Wtf8Buf`, which tracks whether the string is known to contain UTF-8. This is efficiently computed in many common situations, such as when a `Wtf8Buf` is constructed from a `String` or `&str`, or with `Wtf8Buf::from_wide` which is already doing UTF-16 decoding and already checking for surrogates. This makes `OsString::into_string` O(1) rather than O(N) on Windows in common cases. And, it eliminates the need to scan through the string for surrogates in `Args::next` and `Vars::next`, because the strings are already being translated with `Wtf8Buf::from_wide`. Many things on Windows construct `OsString`s with `Wtf8Buf::from_wide`, such as `DirEntry::file_name` and `fs::read_link`, so with this patch, users of those functions can subsequently call `.into_string()` without paying for an extra scan through the string for surrogates.
2022-06-23Represent SocketAddrV4 and SocketAddrV6 as Rust native encodingLinus Färnstrand-4/+4
2022-06-22std: reimplement SGX thread joining to use `Parker`joboet-12/+9
2022-06-22std: rewrite SGX thread parkerjoboet-0/+94
2022-06-22Address reviewer commentsRaoul Strackx-5/+10
2022-06-22Rollup merge of #96768 - m-ou-se:futex-fuchsia, r=tmandryYuki Okushi-0/+51
Use futex based thread parker on Fuchsia.
2022-06-21Use futex based thread parker on Fuchsia.Mara Bos-0/+51
2022-06-20Leak pthreax_rwlock_t when it's dropped while locked.Mara Bos-0/+16
2022-06-19Auto merge of #97791 - m-ou-se:const-locks, r=m-ou-sebors-0/+8
Make {Mutex, Condvar, RwLock}::new() const. This makes it possible to have `static M: Mutex<_> = Mutex::new(..);` 🎉 Our implementations [on Linux](https://github.com/rust-lang/rust/pull/95035), [on Windows](https://github.com/rust-lang/rust/pull/77380), and various BSDs and some tier 3 platforms have already been using a non-allocating const-constructible implementation. As of https://github.com/rust-lang/rust/pull/97647, the remaining platforms (most notably macOS) now have a const-constructible implementation as well. This means we can finally make these functions publicly const. Tracking issue: https://github.com/rust-lang/rust/issues/93740
2022-06-19Rollup merge of #98165 - WaffleLapkin:once_things_renamings, r=m-ou-seMatthias Krüger-4/+4
once cell renamings This PR does the renamings proposed in https://github.com/rust-lang/rust/issues/74465#issuecomment-1153703128 - Move/rename `lazy::{OnceCell, Lazy}` to `cell::{OnceCell, LazyCell}` - Move/rename `lazy::{SyncOnceCell, SyncLazy}` to `sync::{OnceLock, LazyLock}` (I used `Lazy...` instead of `...Lazy` as it seems to be more consistent, easier to pronounce, etc) ```@rustbot``` label +T-libs-api -T-libs
2022-06-17Rollup merge of #97844 - ChrisDenton:dont-panic, r=JohnTitorDylan DPC-4/+5
Windows: No panic if function not (yet) available In some situations (e.g. #97814) it is possible for required functions to be called before they've had a chance to be loaded. Therefore, we make it possible to recover from this situation simply by looking at error codes. `@rustbot` label +O-windows
2022-06-17Auto merge of #98143 - cuviper:futex-rwlock-inline, r=thomccbors-0/+9
Add `#[inline]` to small fns of futex `RwLock` The important methods like `read` and `write` were already inlined, which can propagate all the way to inlining in user code, but these small state functions were left behind as normal calls. They should almost always be inlined as well, as they're just a few instructions.
2022-06-16Move/rename `lazy::Sync{OnceCell,Lazy}` to `sync::{Once,Lazy}Lock`Maybe Waffle-4/+4
2022-06-16Leak pthreax_mutex_t when it's dropped while locked.Mara Bos-1/+19
2022-06-15Auto merge of #97178 - sunfishcode:ownedfd-and-dup, r=joshtriplettbors-1/+1
Add a `BorrowedFd::try_clone_to_owned` and accompanying documentation Add a `BorrowedFd::try_clone_to_owned`, which returns a new `OwnedFd` sharing the underlying file description. And similar for `BorrowedHandle` and `BorrowedSocket` on WIndows. This is similar to the existing `OwnedFd::try_clone`, but it's named differently to reflect that it doesn't return `Result<Self, ...>`. I'm open to suggestions for better names. Also, extend the `unix::io` documentation to mention that `dup` is permitted on `BorrowedFd`. This was originally requsted [here](https://github.com/rust-lang/rust/issues/88564#issuecomment-910786081). At the time I wasn't sure whether it was desirable, but it does have uses and it helps clarify the API. The documentation previously didn't rule out using `dup` on a `BorrowedFd`, but the API only offered convenient ways to do it from an `OwnedFd`. With this patch, the API allows one to do `try_clone` on any type where it's permitted.
2022-06-15Add `#[inline]` to small fns of futex `RwLock`Josh Stone-0/+9
The important methods like `read` and `write` were already inlined, which can propagate all the way to inlining in user code, but these small state functions were left behind as normal calls. They should almost always be inlined as well, as they're just a few instructions.
2022-06-15Document that `BorrowedFd` may be used to do a `dup`.Dan Gohman-1/+1
2022-06-15Auto merge of #95897 - AzureMarker:feature/horizon-std, r=nagisabors-55/+96
STD support for the Nintendo 3DS Rustc already supports compiling for the Nintendo 3DS using the `armv6k-nintendo-3ds` target (Tier 3). Until now though, only `core` and `alloc` were supported. This PR adds standard library support for the Nintendo 3DS. A notable exclusion is `std::thread` support, which will come in a follow-up PR as it requires more complicated changes. This has been a joint effort by `@Meziu,` `@ian-h-chamberlain,` myself, and prior work by `@rust3ds` members. ### Background The Nintendo 3DS (Horizon OS) is a mostly-UNIX looking system, with the caveat that it does not come with a full libc implementation out of the box. On the homebrew side (I'm not under NDA), the libc interface is partially implemented by the [devkitPro](https://devkitpro.org/wiki/devkitPro_pacman) toolchain and a user library like [`libctru`](https://github.com/devkitPro/libctru). This is important because there are [some possible legal barriers](https://github.com/rust-lang/rust/pull/88529#issuecomment-919938396) to linking directly to a library that uses the underlying platform APIs, since they might be considered a trade secret or under NDA. To get around this, the standard library impl for the 3DS does not directly depend on any platform-level APIs. Instead, it expects standard libc functions to be linked in. The implementation of these libc functions is left to the user. Some functions are provided by the devkitPro toolchain, but in our testing, we used the following to fill in the other functions: - [`libctru`] - provides more basic APIs, such as `nanosleep`. Linked in by way of [`ctru-sys`](https://github.com/Meziu/ctru-rs/tree/master/ctru-sys). - [`pthread-3ds`](https://github.com/Meziu/pthread-3ds) - provides pthread APIs for `std::thread`. Implemented using [`libctru`]. - [`linker-fix-3ds`](https://github.com/Meziu/rust-linker-fix-3ds) - fulfills some other missing libc APIs. Implemented using [`libctru`]. For more details, see the `src/doc/rustc/src/platform-support/armv6k-nintendo-3ds.md` file added in this PR. ### Notes We've already upstreamed changes to the [`libc`] crate to support this PR, as well as the upcoming threading PR. These changes have all been released as of 0.2.121, so we bump the crate version in this PR. Edit: After some rebases, the version bump has already been merged so it doesn't appear in this PR. A lot of the changes in this PR are straightforward, and follow in the footsteps of the ESP-IDF target: https://github.com/rust-lang/rust/pull/87666. The 3DS does not support user space process spawning, so these APIs are unimplemented (similar to ESP-IDF). [`libctru`]: https://github.com/devkitPro/libctru [`libc`]: https://github.com/rust-lang/libc