about summary refs log tree commit diff
path: root/library/std/src/sys/pal
AgeCommit message (Collapse)AuthorLines
2024-12-01Rollup merge of #128184 - joboet:refactor_pthread_sync, r=workingjubileeMatthias Krüger-0/+332
std: refactor `pthread`-based synchronization The non-trivial code for `pthread_condvar` is duplicated across the thread parking and the `Mutex`/`Condvar` implementations. This PR moves that code into `sys::pal`, which now exposes an `unsafe` wrapper type for `pthread_mutex_t` and `pthread_condvar_t`.
2024-11-30std: clarify comments about initializationjoboet-9/+11
2024-11-30fix: hurd build, stat64.st_fsid was renamed to st_devSteve Lau-0/+2
2024-11-30Abstract `ProcThreadAttributeList` into its own structMichael van Straten-90/+13
2024-11-30Rollup merge of #133496 - rust-wasi-web:wasi-available-parallelism, r=Amanieu许杰友 Jieyou Xu (Joe)-3/+13
thread::available_parallelism for wasm32-wasip1-threads The target has limited POSIX support and provides the `libc::sysconf` function which allows querying the number of available CPUs.
2024-11-30Rollup merge of #132515 - kornelski:home_fix, r=jhpratt许杰友 Jieyou Xu (Joe)-2/+2
Fix and undeprecate home_dir() `home_dir()` has been deprecated for 6 years due to using `HOME` env var on Windows. It's been a long time, and having a perpetually buggy and deprecated function in the standard library is not useful. I propose fixing and undeprecating it. 6 years seems more than long enough to warn users against relying on this function. The change in behavior is minor, and it's more of a bug fix than breakage. The old behavior is unlikely to be useful, and even if anybody actually needed to specifically use the non-standard `HOME` on Windows, they can trivially mitigate this change by reading the env var themselves. ---- Use of `USERPROFILE` is in line with the `home` crate: https://github.com/rust-lang/cargo/blob/37bc5f0232a0bb72dedd2c14149614fd8cdae649/crates/home/src/windows.rs#L12 The `home` crate uses `SHGetKnownFolderPath` instead of `GetUserProfileDirectoryW`. AFAIK it doesn't make any difference in practice, because `SHGetKnownFolderPath` merely adds support for more kinds of folders, including virtual (non-filesystem) folders identified by a GUID, but the specific case of [`FOLDERID_Profile`](https://learn.microsoft.com/en-us/windows/win32/shell/knownfolderid#FOLDERID_Profile) is documented as a FIXED folder (a regular filesystem path). Just in case, I've added a note to documentation that the use of `GetUserProfileDirectoryW` can change. I've used `CURRENT_RUSTC_VERSION` in a doccomment. `replace-version-placeholder` tool seems to perform a simple string replacement, so hopefully it'll get updated.
2024-11-27Implement code reviewSebastian Urban-2/+1
2024-11-26chore: Improve doc commentsPiotr Osiewicz-2/+3
2024-11-26std: update internal uses of `io::const_error!`joboet-207/+176
2024-11-26thread::available_parallelism for wasm32-wasip1-threadsSebastian Urban-3/+14
The target has limited POSIX support and provides the sysconf function which allows querying the number of available CPUs.
2024-11-26Refactor ReadDir into a state machinePiotr Osiewicz-70/+101
2024-11-23Rollup merge of #131505 - madsmtm:darwin_user_temp_dir, r=dtolnay许杰友 Jieyou Xu (Joe)-4/+99
use `confstr(_CS_DARWIN_USER_TEMP_DIR, ...)` as a `TMPDIR` fallback on Darwin Rebased version of https://github.com/rust-lang/rust/pull/100824, FCP has completed there. Motivation from https://github.com/rust-lang/rust/pull/100824#issuecomment-1262264127: > This is a behavioral change in an edge case on Darwin platforms (macOS, iOS, ...). > > Specifically, this changes it so that iff `TMPDIR` is unset in the environment, then we use `confstr(_CS_DARWIN_USER_TEMP_DIR, ...)` to query the user temporary directory (previously we just returned `"/tmp"`). If this fails (probably possible in a sandboxed program), only then do we fallback to `"/tmp"` (as before). > > The motivations here are two-fold: > > 1. This is better for security, and is in line with the [platform security recommendations](https://developer.apple.com/library/archive/documentation/Security/Conceptual/SecureCodingGuide/Articles/RaceConditions.html#//apple_ref/doc/uid/TP40002585-SW10), as it is unavailable to other users (although it is the same value as seen by all other processes run by the same user). > 2. This is a more consistent fallback for when `getenv("TMPDIR")` is unavailable, as `$TMPDIR` is usually initialized to the `DARWIN_USER_TEMP_DIR`. > > It seems quite unlikely that anybody will break because of this, and I think it falls under the carve-out we have for platform specific behavior: https://doc.rust-lang.org/nightly/std/io/index.html#platform-specific-behavior. Closes https://github.com/rust-lang/rust/issues/99608. Closes https://github.com/rust-lang/rust/pull/100824. ``@rustbot`` label O-apple T-libs-api r? Dylan-DPC
2024-11-22Don't try to use confstr in MiriMads Marquart-4/+6
2024-11-20Rollup merge of #129838 - Ayush1325:uefi-process-args, r=joboetMatthias Krüger-12/+56
uefi: process: Add args support - Wrap all args with quotes. - Escape ^ and " inside quotes using ^. - Doing reverse of arg parsing: https://github.com/rust-lang/rust/blob/d571ae851d93541bef826c3c48c1e9ad99da77d6/library/std/src/sys/pal/uefi/args.rs#L81 r​? joboet
2024-11-18wasi/fs: Improve stopping condition for <ReadDir as Iterator>::nextPiotr Osiewicz-14/+17
When upgrading [Zed](https://github.com/zed-industries/zed/pull/19349) to Rust 1.82 I've encountered a test failure in our test suite. Specifically, one of our extension tests started hanging. I've tracked it down to a call to std::fs::remove_dir_all not returning when an extension is compiled with Rust 1.82 Our extension system uses WASM components, thus I've looked at the diff between 1.81 and 1.82 with respect to WASI and found 736f773844e7ebf05ccb827c17b7ad9eb28aa295 As it turned out, calling remove_dir_all from extension returned io::ErrorKind::NotFound in 1.81; the underlying issue is that the ReadDir iterator never actually terminates iteration, however since it loops around, with 1.81 we'd come across an entry second time and fail to remove it, since it would've been removed previously. With 1.82 and 736f773844e7ebf05ccb827c17b7ad9eb28aa295 it is no longer the case, thus we're seeing the hang. This commit makes ReadDir::next adhere to readdir contract, namely it will no longer call readdir once the returned # of bytes is smaller than the size of a passed-in buffer. Previously we'd only terminate the loop if readdir returned 0.
2024-11-14Rollup merge of #132984 - sunshowers:pipe2, r=tgross35Jubilee-0/+1
[illumos] use pipe2 to create anonymous pipes pipe2 allows the newly-created pipe to atomically be CLOEXEC. pipe2 was added to illumos a long time ago: https://github.com/illumos/illumos-gate/commit/5dbfd19ad5fcc2b779f40f80fa05c1bd28fd0b4e. I've verified that this change passes all of std's tests on illumos.
2024-11-14Rollup merge of #132977 - cberner:fix_solaris, r=tgross35Jubilee-0/+80
Fix compilation error on Solaris due to flock usage PR 130999 added the file_lock feature, but libc does not define flock() for the Solaris platform leading to a compilation error. Additionally, I went through all the Tier 2 platforms and read through their documentation to see whether flock was implemented. This turned up 5 more Unix platforms where flock is not supported, even though it may exist in the libc crate. Fixes https://github.com/rust-lang/rust/issues/132921 Related to #130999
2024-11-14Rollup merge of #132790 - aDotInTheVoid:ioslice-asslice-rides-again, r=cuviperJubilee-6/+36
Add as_slice/into_slice for IoSlice/IoSliceMut. ACP: https://github.com/rust-lang/libs-team/issues/93 Tracking issue: #132818 Based on a623c5233ae7f6b540e5c00f2be02f40b33b0793 (CC `@mpdn)` and #111277 (CC `@Lucretiel).` Closes: #124659 Tracking Issue: TODO try-job: test-various try-job: dist-various-1 try-job: dist-various-2 r? libs
2024-11-13Fix compilation error on Solaris due to flock usageChristopher Berner-0/+80
PR 130999 added the file_lock feature, but libc does not define flock() for the Solaris platform leading to a compilation error. Additionally, I went through all the Tier 2 platforms and read through their documentation to see whether flock was implemented. This turned up 5 more Unix platforms where flock is not supported, even though it may exist in the libc crate.
2024-11-13[illumos] use pipe2 to create anonymous pipesRain-0/+1
pipe2 allows the newly-created pipe to atomically be CLOEXEC. pipe2 was added to illumos a long time ago: https://github.com/illumos/illumos-gate/commit/5dbfd19ad5fcc2b779f40f80fa05c1bd28fd0b4e. I've verified that this change passes all tests.
2024-11-11Rollup merge of #130999 - cberner:flock_pr, r=joboetMatthias Krüger-0/+240
Implement file_lock feature This adds lock(), lock_shared(), try_lock(), try_lock_shared(), and unlock() to File gated behind the file_lock feature flag This is the initial implementation of https://github.com/rust-lang/rust/issues/130994 for Unix and Windows platforms. I will follow it up with an implementation for WASI preview 2
2024-11-09Add as_slice/into_slice for IoSlice/IoSliceMut.Alona Enraght-Moony-6/+36
Co-authored-by: Mike Pedersen <mike@mikepedersen.dk> Co-authored-by: Nathan West <Lucretiel@gmail.com>
2024-11-08Address review commentsChristopher Berner-32/+24
2024-11-08Update library/std/src/sys/pal/windows/fs.rsChristopher Berner-6/+4
Co-authored-by: Jonas Böttiger <jonasboettiger@icloud.com>
2024-11-04Fix and undeprecate home_dir()Kornel-2/+2
2024-11-02Fix type reference in documents which was being confused with html tags.Houtamelo-1/+1
2024-10-29Win: rename: Use offset_of! in struct size calculationGeorge Tokmaji-4/+7
2024-10-28std: refactor `pthread`-based synchronizationjoboet-0/+330
The non-trivial code for `pthread_condvar` is duplicated across the thread parking and the `Mutex`/`Condvar` implementations. This PR moves that code into `sys::pal`, which now exposes a non-movable wrapper type for `pthread_mutex_t` and `pthread_condvar_t`.
2024-10-25library: consistently use American spelling for 'behavior'Ralf Jung-8/+8
2024-10-23[musl] use posix_spawn if a directory change was requestedRain-11/+43
Currently, not all libcs have the `posix_spawn_file_actions_addchdir_np` symbol available to them. So we attempt to do a weak symbol lookup for that function. But that only works if libc is a dynamic library -- with statically linked musl binaries the symbol lookup would never work, so we would never be able to use it even if the musl in use supported the symbol. Now that Rust has a minimum musl version of 1.2.3, all supported musl versions now include this symbol, so we can unconditionally expect it to be there. This symbol was added to libc in https://github.com/rust-lang/libc/pull/3949 -- use it here. I couldn't find any tests for whether the posix_spawn path is used, but I've verified with cargo-nextest that this change works. This is a substantial improvement to nextest's performance with musl. On my workstation with a Ryzen 7950x, against https://github.com/clap-rs/clap at 61f5ee514f8f60ed8f04c6494bdf36c19e7a8126: Before: ``` Summary [ 1.071s] 879 tests run: 879 passed, 0 skipped ``` After: ``` Summary [ 0.392s] 879 tests run: 879 passed, 0 skipped ``` Fixes #99740.
2024-10-20fix docsklensy-6/+6
2024-10-20replace FindFirstFileW with FindFirstFileExW and apply optimizationklensy-4/+25
2024-10-20replace FindFirstFileW with FindFirstFileExW and regenerate bindingsklensy-3/+9
2024-10-19Support lock() and lock_shared() on async IO FilesChristopher Berner-13/+49
2024-10-19Rollup merge of #131921 - klensy:statx_all, r=ChrisDentonMatthias Krüger-5/+5
replace STATX_ALL with (STATX_BASIC_STATS | STATX_BTIME) as former is deprecated STATX_ALL was deprecated in https://github.com/torvalds/linux/commit/581701b7efd60ba13d8a7eed60cbdd7fefaf6696 and suggested to use equivalent (STATX_BASIC_STATS | STATX_BTIME) combination, to prevent future surprises.
2024-10-19Rollup merge of #127462 - Ayush1325:uefi-env, r=joboetMatthias Krüger-42/+125
std: uefi: Add basic Env variables - Implement environment variable functions - Using EFI Shell protocol.
2024-10-19replace STATX_ALL with (STATX_BASIC_STATS | STATX_BTIME) as former is deprecatedklensy-5/+5
2024-10-18std: uefi: Use common function for UEFI shellAyush Singh-36/+2
- Since in almost all cases, there will only be 1 UEFI shell, share the shell handle between all functions that require it. Signed-off-by: Ayush Singh <ayush@beagleboard.org>
2024-10-18std: uefi: Add basic Env variablesAyush Singh-15/+132
- Implement environment variable functions - Using EFI Shell protocol. Signed-off-by: Ayush Singh <ayush@beagleboard.org>
2024-10-18Auto merge of #131895 - jieyouxu:rollup-jyt3pic, r=jieyouxubors-3/+1
Rollup of 3 pull requests Successful merges: - #126207 (std::unix::stack_overflow::drop_handler addressing todo through libc …) - #131864 (Never emit `vptr` for empty/auto traits) - #131870 (compiletest: Store test collection context/state in two structs) r? `@ghost` `@rustbot` modify labels: rollup
2024-10-18Rollup merge of #126207 - devnexen:stack_overflow_libc_upd, r=joboet许杰友 Jieyou Xu (Joe)-3/+1
std::unix::stack_overflow::drop_handler addressing todo through libc … …update
2024-10-18Auto merge of #131841 - paulmenage:futex-abstraction, r=joboetbors-21/+41
Abstract the state type for futexes In the same way that we expose `SmallAtomic` and `SmallPrimitive` to allow Windows to use a value other than an `AtomicU32` for its futex state, switch the primary futex state type from `AtomicU32` to `futex::Futex`. The `futex::Futex` type should be usable as an atomic value with underlying primitive type equal to `futex::Primitive`. (`SmallAtomic` is also renamed to `SmallFutex`). This allows supporting the futex API on systems where the underlying kernel futex implementation requires more user state than simply an `AtomicU32`. All in-tree futex implementations simply define {`Futex`,`Primitive`} directly as {`AtomicU32`,`u32`}.
2024-10-18Rollup merge of #131654 - betrusted-io:xous-various-fixes, r=thomccMatthias Krüger-32/+507
Various fixes for Xous This patchset includes several fixes for Xous that have crept in over the last few months: * The `adjust_process()` syscall was incorrect * Warnings have started appearing in `alloc` -- adopt the same approach as wasm, until wasm figures out a workaround * Dead code warnings have appeared in the networking code. Add `allow(dead_code)` as these structs are used as IPC values * Add support for `args` and `env`, which have been useful for running tests * Update `unwinding` to `0.2.3` which fixes the recent regression due to changes in `asm!()` code
2024-10-17std::unix::stack_overflow::drop_handler addressing todo through libc updateDavid Carlier-3/+1
2024-10-17Abstract the state type for futexesPaul Menage-21/+41
In the same way that we expose SmallAtomic and SmallPrimitive to allow Windows to use a value other than an AtomicU32 for its futex state, this patch switches the primary futex state type from AtomicU32 to futex::Atomic. The futex::Atomic type should be usable as an atomic value with underlying primitive type equal to futex::Primitive. This allows supporting the futex API on systems where the underlying kernel futex implementation requires more state than simply an AtomicU32. All in-tree futex implementations simply define {Atomic,Primitive} directly as {AtomicU32,u32}.
2024-10-17Win: Remove special casing of the win7 target for `std::fs::rename`George Tokmaji-14/+1
2024-10-15Rollup merge of #129794 - Ayush1325:uefi-os-expand, r=joboetMichael Goulet-14/+73
uefi: Implement getcwd and chdir - Using EFI Shell Protocol. These functions do not make much sense unless a shell is present. - Return the exe dir in case shell protocol is missing. r? `@joboet`
2024-10-14Fix two const-hacksGeorge Bateman-15/+4
2024-10-14uefi: Implement getcwd and chdirAyush Singh-14/+73
- Using EFI Shell Protocol. These functions do not make much sense unless a shell is present. - Return the exe dir in case shell protocol is missing. Signed-off-by: Ayush Singh <ayush@beagleboard.org>
2024-10-14Rollup merge of #128967 - devnexen:get_path_fbsd_upd, r=joboetMatthias Krüger-2/+2
std::fs::get_path freebsd update. what matters is we re doing the right things as doing sizeof, rather than passing KINFO_FILE_SIZE (only defined on intel architectures), the kernel making sure it matches the expectation in its side.