Skip to content

Commit

Permalink
fixes to #6462: make wasi-common API compatible with 9.0.1 (#6471)
Browse files Browse the repository at this point in the history
* fixes to #6462: make wasi-common API compatible with 9.0.1

required in order to make 9.0.2 a valid patch release.

* `struct FdStat` is public, so I backed out changes to it, and manually
applied the rights bits in the implementation of fd_fdstat_get.

* new `FileAccessMode` changed to be pub(crate), to make sure it doesnt
appear in any pub interfaces. WasiCtx::insert_file and push_file
reverted to their original type signature. Private helper insert_file_
used for the set_{stdio} implementations.

* add release notes for 9.0.1 and 9.0.2
  • Loading branch information
Pat Hickey committed May 26, 2023
1 parent bf98dca commit 32afef6
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 28 deletions.
22 changes: 22 additions & 0 deletions RELEASES.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,26 @@
--------------------------------------------------------------------------------
## 9.0.2

Released 2023-05-26.

### Fixed

* Fix Wasi rights system to work with wasi-libc. This regression was
introduced in the 9.0.0 release.
[#6462](https://github.com/bytecodealliance/wasmtime/pull/6462)
[#6471](https://github.com/bytecodealliance/wasmtime/pull/6471)

--------------------------------------------------------------------------------

## 9.0.1

Released 2023-05-22.
### Fixed
* A panic which happened when enabling support for native platform profilers was
fixed.
[#6435](https://github.com/bytecodealliance/wasmtime/pull/6435)

--------------------------------------------------------------------------------

## 9.0.0

Expand Down
5 changes: 2 additions & 3 deletions crates/wasi-common/cap-std-sync/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub use sched::sched_ctx;
use crate::net::Socket;
use cap_rand::{Rng, RngCore, SeedableRng};
use std::path::Path;
use wasi_common::{file::FileAccessMode, table::Table, Error, WasiCtx, WasiFile};
use wasi_common::{table::Table, Error, WasiCtx, WasiFile};

pub struct WasiCtxBuilder(WasiCtx);

Expand Down Expand Up @@ -126,8 +126,7 @@ impl WasiCtxBuilder {
pub fn preopened_socket(self, fd: u32, socket: impl Into<Socket>) -> Result<Self, Error> {
let socket: Socket = socket.into();
let file: Box<dyn WasiFile> = socket.into();
self.0
.insert_file(fd, file, FileAccessMode::READ | FileAccessMode::WRITE);
self.0.insert_file(fd, file);
Ok(self)
}
pub fn build(self) -> WasiCtx {
Expand Down
19 changes: 9 additions & 10 deletions crates/wasi-common/src/ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,17 @@ impl WasiCtx {
s
}

pub fn insert_file(&self, fd: u32, file: Box<dyn WasiFile>, access_mode: FileAccessMode) {
fn insert_file_(&self, fd: u32, file: Box<dyn WasiFile>, access_mode: FileAccessMode) {
self.table()
.insert_at(fd, Arc::new(FileEntry::new(file, access_mode)));
}
pub fn insert_file(&self, fd: u32, file: Box<dyn WasiFile>) {
self.insert_file_(fd, file, FileAccessMode::all())
}

pub fn push_file(
&self,
file: Box<dyn WasiFile>,
access_mode: FileAccessMode,
) -> Result<u32, Error> {
pub fn push_file(&self, file: Box<dyn WasiFile>) -> Result<u32, Error> {
self.table()
.push(Arc::new(FileEntry::new(file, access_mode)))
.push(Arc::new(FileEntry::new(file, FileAccessMode::all())))
}

pub fn insert_dir(&self, fd: u32, dir: Box<dyn WasiDir>, path: PathBuf) {
Expand Down Expand Up @@ -98,15 +97,15 @@ impl WasiCtx {
}

pub fn set_stdin(&self, f: Box<dyn WasiFile>) {
self.insert_file(0, f, FileAccessMode::READ);
self.insert_file_(0, f, FileAccessMode::READ);
}

pub fn set_stdout(&self, f: Box<dyn WasiFile>) {
self.insert_file(1, f, FileAccessMode::WRITE);
self.insert_file_(1, f, FileAccessMode::WRITE);
}

pub fn set_stderr(&self, f: Box<dyn WasiFile>) {
self.insert_file(2, f, FileAccessMode::WRITE);
self.insert_file_(2, f, FileAccessMode::WRITE);
}

pub fn push_preopened_dir(
Expand Down
4 changes: 1 addition & 3 deletions crates/wasi-common/src/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ pub(crate) struct FileEntry {
}

bitflags! {
pub struct FileAccessMode : u32 {
pub(crate) struct FileAccessMode : u32 {
const READ = 0b1;
const WRITE= 0b10;
}
Expand All @@ -239,7 +239,6 @@ impl FileEntry {
Ok(FdStat {
filetype: self.file.get_filetype().await?,
flags: self.file.get_fdflags().await?,
access_mode: self.access_mode,
})
}
}
Expand All @@ -248,7 +247,6 @@ impl FileEntry {
pub struct FdStat {
pub filetype: FileType,
pub flags: FdFlags,
pub access_mode: FileAccessMode,
}

#[derive(Debug, Clone)]
Expand Down
18 changes: 9 additions & 9 deletions crates/wasi-common/src/snapshots/preview_1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,14 @@ impl wasi_snapshot_preview1::WasiSnapshotPreview1 for WasiCtx {
if table.is::<FileEntry>(fd) {
let file_entry: Arc<FileEntry> = table.get(fd)?;
let fdstat = file_entry.get_fdstat().await?;
Ok(types::Fdstat::from(&fdstat))
let mut fdstat = types::Fdstat::from(&fdstat);
if file_entry.access_mode.contains(FileAccessMode::READ) {
fdstat.fs_rights_base |= types::Rights::FD_READ;
}
if file_entry.access_mode.contains(FileAccessMode::WRITE) {
fdstat.fs_rights_base |= types::Rights::FD_WRITE;
}
Ok(fdstat)
} else if table.is::<DirEntry>(fd) {
let _dir_entry: Arc<DirEntry> = table.get(fd)?;
let dir_fdstat = types::Fdstat {
Expand Down Expand Up @@ -1240,16 +1247,9 @@ impl From<types::Advice> for Advice {

impl From<&FdStat> for types::Fdstat {
fn from(fdstat: &FdStat) -> types::Fdstat {
let mut fs_rights_base = types::Rights::empty();
if fdstat.access_mode.contains(FileAccessMode::READ) {
fs_rights_base |= types::Rights::FD_READ;
}
if fdstat.access_mode.contains(FileAccessMode::WRITE) {
fs_rights_base |= types::Rights::FD_WRITE;
}
types::Fdstat {
fs_filetype: types::Filetype::from(&fdstat.filetype),
fs_rights_base,
fs_rights_base: types::Rights::empty(),
fs_rights_inheriting: types::Rights::empty(),
fs_flags: types::Fdflags::from(fdstat.flags),
}
Expand Down
5 changes: 2 additions & 3 deletions crates/wasi-common/tokio/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub mod stdio;
use std::future::Future;
use std::path::Path;
pub use wasi_cap_std_sync::{clocks_ctx, random_ctx};
use wasi_common::{file::FileAccessMode, Error, Table, WasiCtx, WasiFile};
use wasi_common::{Error, Table, WasiCtx, WasiFile};

use crate::sched::sched_ctx;
pub use dir::Dir;
Expand Down Expand Up @@ -96,8 +96,7 @@ impl WasiCtxBuilder {
pub fn preopened_socket(self, fd: u32, socket: impl Into<Socket>) -> Result<Self, Error> {
let socket: Socket = socket.into();
let file: Box<dyn WasiFile> = socket.into();
self.0
.insert_file(fd, file, FileAccessMode::READ | FileAccessMode::WRITE);
self.0.insert_file(fd, file);
Ok(self)
}

Expand Down

0 comments on commit 32afef6

Please sign in to comment.