about summary refs log tree commit diff
path: root/library/std/src/sys/wasi
AgeCommit message (Collapse)AuthorLines
2024-01-11std: begin moving platform support modules into `pal`joboet-2713/+0
2023-11-15Re-format code with new rustfmtMark Rousskov-6/+7
2023-10-06Use `io_error_more` on WASIShE3py-23/+92
2023-08-25Add a new helper to avoid calling io::Error::kindBen Kimock-0/+5
2023-08-23Rollup merge of #114696 - g0djan:godjan/fix_114610, r=Mark-SimulacrumGuillaume Gomez-0/+8
Fix a pthread_t handle leak #114610 https://github.com/rust-lang/rust/issues/114610 Ran the tests as described in https://github.com/rust-lang/rust/blob/master/src/doc/rustc/src/platform-support/wasm32-wasi-preview1-threads.md?plain=1#L125
2023-08-18Fix UB in `std::sys::os::getenv()`ShE3py-8/+15
2023-08-16address commentsGeorgii Rylov-11/+7
2023-08-16Fix a pthread_t handle leak #114610Georgii Rylov-0/+12
2023-08-15Rollup merge of #114619 - g0djan:godjan/fix_#114608, r=m-ou-seMatthias Krüger-3/+3
Fix pthread_attr_union layout on Wasi Fixes https://github.com/rust-lang/rust/issues/114608 Ran the tests as described in https://github.com/rust-lang/rust/blob/master/src/doc/rustc/src/platform-support/wasm32-wasi-preview1-threads.md?plain=1#L125
2023-08-14std: add some missing repr(transparent)Ralf Jung-2/+8
2023-08-08Fix #114608Georgii Rylov-3/+3
2023-08-07Better Debug for Vars and VarsOsTamir Duberstein-0/+29
Display actual vars instead of two dots. The same was done for Args and ArgsOs in 275f9a04af6191e3aee3852a5a1713.
2023-07-29Add wasm32-wasi-threads target + WASI threadsGeorgii Rylov-11/+140
2023-05-25std: make internal-only items `pub(crate)`Michael Howell-5/+5
This works around a weird problem that looks like a bug in the `exported_private_dependencies` lint.
2023-05-03Rollup merge of #105695 - joboet:remove_generic_parker, r=m-ou-seManish Goregaokar-0/+2
Replace generic thread parker with explicit no-op parker With #98391 merged, all platforms supporting threads now have their own parking implementations. Therefore, the generic implementation can be removed. On the remaining platforms (really just WASM without atomics), parking is not supported, so calls to `thread::park` now return instantly, which is [allowed by their API](https://doc.rust-lang.org/nightly/std/thread/fn.park.html). This is a change in behaviour, as spurious wakeups do not currently occur since all platforms guard against them. It is invalid to depend on this, but I'm still going to tag this as libs-api for confirmation. ````@rustbot```` label +T-libs +T-libs-api +A-atomic r? rust-lang/libs
2023-05-01Inline AsRawFd implementationsKonrad Borowski-0/+3
2023-05-01Inline socket function implementationsKonrad Borowski-0/+3
2023-05-01Inline AsInner implementationsKonrad Borowski-0/+6
2023-04-20Fix `std` compilation error for wasi+atomicsPierre Krieger-2/+7
2023-03-06Implement read_buf for a few more typesTomasz Miąsko-3/+23
Implement read_buf for TcpStream, Stdin, StdinLock, ChildStdout, ChildStderr (and internally for AnonPipe, Handle, Socket), so that it skips buffer initialization. The other provided methods like read_to_string and read_to_end are implemented in terms of read_buf and so benefit from the optimization as well. This commit also implements read_vectored and is_read_vectored where applicable.
2023-02-16std: replace generic thread parker with explicit no-op parkerjoboet-0/+2
2023-02-09Allow wasi-libc to initialize its environment variables lazily.Dan Gohman-1/+7
Use `__wasilibc_get_environ()` to read the environment variable list from wasi-libc instead of using `environ`. `environ` is a global variable which effectively requires wasi-libc to initialize the environment variables eagerly, and `__wasilibc_get_environ()` is specifically designed to be an alternative that lets wasi-libc intiailize its environment variables lazily. This should have the side effect of fixing at least some of the cases of #107635.
2022-12-14std: use a more efficient `Once` on platforms without threadsjoboet-0/+2
2022-11-24feat: implement TcpStream shutdown for wasm32-wasiHarald Hoyer-2/+8
Signed-off-by: Harald Hoyer <harald@profian.com>
2022-10-15Add `IsTerminal` trait to determine if a descriptor or handle is a terminalJosh Triplett-0/+6
The UNIX and WASI implementations use `isatty`. The Windows implementation uses the same logic the `atty` crate uses, including the hack needed to detect msys terminals. Implement this trait for `File` and for `Stdin`/`Stdout`/`Stderr` and their locked counterparts on all platforms. On UNIX and WASI, implement it for `BorrowedFd`/`OwnedFd`. On Windows, implement it for `BorrowedHandle`/`OwnedHandle`. Based on https://github.com/rust-lang/rust/pull/91121 Co-authored-by: Matt Wilkinson <mattwilki17@gmail.com>
2022-10-14Rollup merge of #102847 - joshtriplett:bugfix-impl-fd-traits-for-io-types, ↵Dylan DPC-49/+1
r=m-ou-se impl AsFd and AsRawFd for io::{Stdin, Stdout, Stderr}, not the sys versions https://github.com/rust-lang/rust/pull/100892 implemented AsFd for the sys versions, rather than for the public types. Change the implementations to apply to the public types.
2022-10-11fix: return type of single-threaded dummy lock must be droppableAndrew Brown-2/+2
2022-10-10Implement `env_lock` with `RwLock`Andrew Brown-12/+23
Copying the approach of the Unix target, this change uses the standard `RwLock` to protect against concurrent access of libc's environment. This locking is only enabled when WebAssembly's `atomics` feature is also enabled.
2022-10-10Allow compiling the `wasm32-wasi` std library with atomicsAndrew Brown-3/+11
The issue #102157 demonstrates how currently the `-Z build-std` option will fail when re-compiling the standard library with `RUSTFLAGS` like `RUSTFLAGS="-C target-feature=+atomics,+bulk-memory -C link-args=--shared-memory"`. This change attempts to resolve those build issues by depending on the the WebAssembly `futex` module and providing an implementation for `env_lock`. Fixes #102157.
2022-10-10Consolidate AsFd instances for stdio types into `library/std/src/os/fd/owned.rs`Josh Triplett-49/+1
2022-10-09impl AsFd for io::{Stdin, Stdout, Stderr}, not the sys versionsJosh Triplett-3/+3
https://github.com/rust-lang/rust/pull/100892 implemented AsFd for the sys versions, rather than for the public types. Change the implementations to apply to the public types.
2022-10-09Auto merge of #93668 - SUPERCILEX:path_alloc, r=joshtriplettbors-69/+66
Reduce CString allocations in std as much as possible Currently, every operation involving paths in `fs` allocates memory to hold the path before sending it through the syscall. This PR instead uses a stack allocation (chosen size is somewhat arbitrary) when the path is short before falling back to heap allocations for long paths. Benchmarks show that the stack allocation is ~2x faster for short paths: ``` test sys::unix::fd::tests::bench_heap_path_alloc ... bench: 34 ns/iter (+/- 2) test sys::unix::fd::tests::bench_stack_path_alloc ... bench: 15 ns/iter (+/- 1) ``` For long paths, I couldn't find any measurable difference. --- I'd be surprised if I was the first to think of this, so I didn't fully flush out the PR. If this change is desirable, I'll make use of `run_with_cstr` across all platforms in every fs method (currently just unix open for testing). I also added an `impl From<FromBytesWithNulError>` which is presumably a no-no (or at least needs to be done in another PR). --- Also see https://github.com/nix-rust/nix/pull/1655 with a bunch of discussion where I'm doing something similar.
2022-10-04Auto merge of #101768 - sunfishcode:sunfishcode/wasi-stdio-lock-asfd, ↵bors-0/+27
r=joshtriplett Add `AsFd` implementations for stdio lock types on WASI. This mirrors the implementations on Unix platforms, and also mirrors the existing `AsRawFd` impls. This is similar to #100892, but is for the `*Lock` types.
2022-10-03Reduce CString allocations in std as much as possibleAlex Saveau-69/+66
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
2022-10-03Add SAFETY comments for AsFd implementations on stdin/stdout/stderrJosh Triplett-0/+3
2022-10-03Add stability attributes.Dan Gohman-3/+6
2022-10-01Error instead of panicking when setting file times if the passed ↵beetrees-8/+15
`SystemTime` doesn't fit into the required type
2022-09-22Add `AsFd` implementations for stdio lock types on WASI.Dan Gohman-0/+21
This mirrors the implementations on Unix platforms, and also mirrors the existing `AsRawFd` impls. This is similar to #100892, but is for the `*Lock` types.
2022-08-31Rollup merge of #100892 - sunfishcode:wasi-stdio-asfd, r=joshtriplettYuki Okushi-1/+22
Add `AsFd` implementations for stdio types on WASI. This mirrors the implementations on Unix platforms, and also mirrors the existing `AsRawFd` impls.
2022-08-22Add `AsFd` implementations for stdio types on WASI.Dan Gohman-1/+22
This mirrors the implementations on Unix platforms, and also mirrors the existing `AsRawFd` impls.
2022-08-18Address reviewer commentsNick Cameron-1/+1
Signed-off-by: Nick Cameron <nrc@ncameron.org>
2022-08-05non-linux platformsNick Cameron-3/+3
Signed-off-by: Nick Cameron <nrc@ncameron.org>
2022-08-01Auto merge of #98246 - joshtriplett:times, r=m-ou-sebors-0/+29
Support setting file accessed/modified timestamps 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-30Remove socklen_t from platforms where it's no longer usedLinus Färnstrand-2/+0
2022-07-15Support setting file accessed/modified timestampsJosh Triplett-0/+29
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-05-09Use Rust 2021 prelude in std itself.Mara Bos-1/+0
2022-03-22Move std::sys::{mutex, condvar, rwlock} to std::sys::locks.Mara Bos-6/+2
2022-02-13make Instant::{duration_since, elapsed, sub} saturating and remove workaroundsThe8472-8/+0
This removes all mutex/atomics based workarounds for non-monotonic clocks and makes the previously panicking methods saturating instead. Effectively this moves the monotonization from `Instant` construction to the comparisons. This has some observable effects, especially on platforms without monotonic clocks: * Incorrectly ordered Instant comparisons no longer panic. This may hide some programming errors until someone actually looks at the resulting `Duration` * `checked_duration_since` will now return `None` in more cases. Previously it only happened when one compared instants obtained in the wrong order or manually created ones. Now it also does on backslides. The upside is reduced complexity and lower overhead of `Instant::now`.
2022-02-04Hide Repr details from io::Error, and rework `io::Error::new_const`.Thom Chiovoloni-2/+2
2022-01-28wasi: enable TcpListener and TcpStreamHarald Hoyer-13/+57
With the addition of `sock_accept()` to snapshot1, simple networking via a passed `TcpListener` is possible. This patch implements the basics to make a simple server work. Signed-off-by: Harald Hoyer <harald@profian.com>