Port wasi-common from unsafe-io to io-lifetimes (#3049)
* Port wasi-common to io-lifetimes. This ports wasi-common from unsafe-io to io-lifetimes. Ambient authority is now indicated via calls to `ambient_authority()` from the ambient-authority crate, rather than using `unsafe` blocks. The `GetSetFdFlags::set_fd_flags` function is now split into two phases, to simplify lifetimes in implementations which need to close and re-open the underlying file. * Use posish for errno values instead of libc. This eliminates one of the few remaining direct libc dependencies. * Port to posish::io::poll. Use posish::io::poll instead of calling libc directly. This factors out more code from Wasmtime, and eliminates the need to manipulate raw file descriptors directly. And, this eliminates the last remaining direct dependency on libc in wasi-common. * Port wasi-c-api to io-lifetimes. * Update to posish 0.16.0. * Embeded NULs in filenames now get `EINVAL` instead of `EILSEQ`. * Accept either `EILSEQ` or `EINVAL` for embedded NULs. * Bump the nightly toolchain to 2021-07-12. This fixes build errors on the semver crate, which as of this writing builds with latest nightly and stable but not 2021-04-11, the old pinned version. * Have cap-std-sync re-export ambient_authority so that users get the same version.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
//! The WASI embedding API definitions for Wasmtime.
|
||||
|
||||
use anyhow::Result;
|
||||
use cap_std::ambient_authority;
|
||||
use std::ffi::CStr;
|
||||
use std::fs::File;
|
||||
use std::os::raw::{c_char, c_int};
|
||||
@@ -69,21 +70,21 @@ impl wasi_config_t {
|
||||
if self.inherit_stdin {
|
||||
builder = builder.inherit_stdin();
|
||||
} else if let Some(file) = self.stdin {
|
||||
let file = unsafe { cap_std::fs::File::from_std(file) };
|
||||
let file = cap_std::fs::File::from_std(file, ambient_authority());
|
||||
let file = wasi_cap_std_sync::file::File::from_cap_std(file);
|
||||
builder = builder.stdin(Box::new(file));
|
||||
}
|
||||
if self.inherit_stdout {
|
||||
builder = builder.inherit_stdout();
|
||||
} else if let Some(file) = self.stdout {
|
||||
let file = unsafe { cap_std::fs::File::from_std(file) };
|
||||
let file = cap_std::fs::File::from_std(file, ambient_authority());
|
||||
let file = wasi_cap_std_sync::file::File::from_cap_std(file);
|
||||
builder = builder.stdout(Box::new(file));
|
||||
}
|
||||
if self.inherit_stderr {
|
||||
builder = builder.inherit_stderr();
|
||||
} else if let Some(file) = self.stderr {
|
||||
let file = unsafe { cap_std::fs::File::from_std(file) };
|
||||
let file = cap_std::fs::File::from_std(file, ambient_authority());
|
||||
let file = wasi_cap_std_sync::file::File::from_cap_std(file);
|
||||
builder = builder.stderr(Box::new(file));
|
||||
}
|
||||
@@ -227,7 +228,7 @@ pub unsafe extern "C" fn wasi_config_preopen_dir(
|
||||
};
|
||||
|
||||
let dir = match cstr_to_path(path) {
|
||||
Some(p) => match Dir::open_ambient_dir(p) {
|
||||
Some(p) => match Dir::open_ambient_dir(p, ambient_authority()) {
|
||||
Ok(d) => d,
|
||||
Err(_) => return false,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user