about summary refs log tree commit diff
path: root/library/std/src/sys/wasi
AgeCommit message (Collapse)AuthorLines
2021-03-27Use DebugStruct::finish_non_exhaustive() in std.Mara Bos-1/+1
2021-03-21Use io::Error::new_const everywhere to avoid allocations.Mara Bos-5/+5
2021-03-05std: 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-27Rollup merge of #82421 - sunfishcode:wasi-metadata-size, r=alexcrichtonDylan DPC-0/+5
Add a `size()` function to WASI's `MetadataExt`. WASI's `filestat` type includes a size field, so expose it in `MetadataExt` via a `size()` function, similar to the corresponding Unix function. r? ``````@alexcrichton``````
2021-02-24x.py fmtDan Gohman-3/+3
2021-02-24Use `super::` to refer to WASI-specific names.Dan Gohman-7/+7
This ensures that these names resolve to the right place even when building the WASI support on other platforms for generating the documentation.
2021-02-24Cast `libc::STDIN_FILENO` to `RawFd`.Dan Gohman-6/+6
WASI's `RawFd` is a `u32`, while `libc` uses `c_int`.
2021-02-23Enable API documentation for `std::os::wasi`.Dan Gohman-15/+50
This adds API documentation support for `std::os::wasi` modeled after how `std::os::unix` works, so that WASI can be documented [here] along with the other platforms. [here]: https://doc.rust-lang.org/stable/std/os/index.html Two changes of particular interest: - This changes the `AsRawFd` for `io::Stdin` for WASI to return `libc::STDIN_FILENO` instead of `sys::stdio::Stdin.as_raw_fd()` (and similar for `Stdout` and `Stderr`), which matches how the `unix` version works. `STDIN_FILENO` etc. may not always be explicitly reserved at the WASI level, but as long as we have Rust's `std` and `libc`, I think it's reasonable to guarantee that we'll always use `libc::STDIN_FILENO` for stdin. - This duplicates the `osstr2str` utility function, rather than trying to share it across all the configurations that need it.
2021-02-23Rollup merge of #81984 - sunfishcode:wasi-link, r=alexcrichtonDylan DPC-6/+2
Make WASI's `hard_link` behavior match other platforms. Following #78026, `std::fs::hard_link` on most platforms does not follow symlinks. Change the WASI implementation to also not follow symlinks. r? ```@alexcrichton```
2021-02-22Add a `size()` function to WASI's `MetadataExt`.Dan Gohman-0/+5
WASI's `filestat` type includes a size field, so expose it in `MetadataExt` via a `size()` function, similar to the corresponding Unix function.
2021-02-19x.py fmtDan Gohman-6/+1
2021-02-10Make WASI's `hard_link` behavior match other platforms.Dan Gohman-1/+2
Following #78026, `std::fs::hard_link` on most platforms does not follow symlinks. Change the WASI implementation to also not follow symlinks.
2021-02-03Restore comment as it wasIngvar Stepanyan-0/+2
2021-02-03Keep old symlink; expose new symlink_pathIngvar Stepanyan-4/+14
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-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.
2020-11-14Disambiguate symlink argument namesDavid Tolnay-10/+10
2020-10-14Rollup merge of #77722 - fusion-engineering-forks:safe-unsupported-locks, ↵Yuki Okushi-0/+1
r=Mark-Simulacrum Remove unsafety from sys/unsupported and add deny(unsafe_op_in_unsafe_fn). Replacing `UnsafeCell`s by a `Cell`s simplifies things and makes the mutex and rwlock implementations safe. Other than that, only unsafety in strlen() contained unsafe code. @rustbot modify labels: +F-unsafe-block-in-unsafe-fn +C-cleanup
2020-10-13Deny unsafe_op_in_unsafe_fn for unsupported/common.rs through sys/wasm too.Mara Bos-0/+1
2020-10-08Implement `AsRawFd` for `StdinLock` etc. on WASI.Dan Gohman-0/+18
WASI implements `AsRawFd` for `Stdin`, `Stdout`, and `Stderr`, so implement it for `StdinLock`, `StdoutLock`, and `StderrLock` as well.
2020-09-20spend another CI build to delete a double newlineWithout Boats-1/+0
2020-09-20fix typosWithout Boats-2/+2
2020-09-20Make RawFd implement the RawFd traitsWithout Boats-0/+20
2020-09-15Consolidate wasi::process and unsupported::processEric Huss-151/+1
2020-09-15Consolidate wasi alloc with unix alloc.Eric Huss-69/+1
2020-09-15Consolidate byte-identical modules.Eric Huss-59/+2
2020-09-03Auto merge of #75971 - Amjad50:libstd-deny-unsafe_op_in_unsafe_fn, ↵bors-8/+60
r=Mark-Simulacrum Applied `#![deny(unsafe_op_in_unsafe_fn)]` in library/std/src/wasi partial fix for #73904 There are still more that was not applied in [mod.rs]( https://github.com/rust-lang/rust/blob/38fab2ea92a48980219989817201bf2094ae826a/library/std/src/sys/wasi/mod.rs) and that is due to its using files from `../unsupported` like: ``` #[path = "../unsupported/cmath.rs"] pub mod cmath; ```
2020-09-03Applied `#![deny(unsafe_op_in_unsafe_fn)]` in library/std/src/wasiAmjad Alsharafi-8/+60
All refactoring needed was only in `alloc.rs`, changed part of the code in `alloc` method to satisfy the SAFETY statement
2020-08-26Move to intra-doc links for wasi/ext/fs.rs, os_str_bytes.rs, ↵Surya Midatala-25/+2
primitive_docs.rs & poison.rs
2020-08-21Make raw standard stream constructors constTomasz Miąsko-3/+3
2020-08-21Remove result type from raw standard streams constructorsTomasz Miąsko-7/+7
Raw standard streams constructors are infallible. Remove unnecessary result type.
2020-08-05Fix wasi::fs::OpenOptions to imply write when append is onYuto Kawamura-3/+5
2020-07-31Fix std::fs::File::metadata permission on WASI targetShen-Ta Hsieh-0/+1
Previously `std::fs::File::metadata` on wasm32-wasi would call `fd_filestat_get` to get metadata associated with fd, but that fd is opened without RIGHTS_FD_FILESTAT_GET right, so it will failed on correctly implemented WASI environment. This change instead to add the missing rights when opening an fd.
2020-07-27mv std libs to library/mark-0/+2945