Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/wasi-common/src/fs/dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ impl<'ctx> Drop for Dir<'ctx> {
// the file descriptor was closed or not, and if we retried (for
// something like EINTR), we might close another valid file descriptor
// opened after we closed ours.
let _ = unsafe { hostcalls::fd_close(self.ctx, self.fd) };
let _ = unsafe { hostcalls::fd_close(self.ctx, &mut [], self.fd) };
}
}

Expand Down
10 changes: 6 additions & 4 deletions crates/wasi-common/src/fs/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl<'ctx> File<'ctx> {
///
/// [`std::fs::File::sync_all`]: https://doc.rust-lang.org/std/fs/struct.File.html#method.sync_all
pub fn sync_all(&self) -> io::Result<()> {
wasi_errno_to_io_error(unsafe { hostcalls::fd_sync(self.ctx, self.fd) })
wasi_errno_to_io_error(unsafe { hostcalls::fd_sync(self.ctx, &mut [], self.fd) })
}

/// This function is similar to `sync_all`, except that it may not synchronize
Expand All @@ -45,7 +45,7 @@ impl<'ctx> File<'ctx> {
///
/// [`std::fs::File::sync_data`]: https://doc.rust-lang.org/std/fs/struct.File.html#method.sync_data
pub fn sync_data(&self) -> io::Result<()> {
wasi_errno_to_io_error(unsafe { hostcalls::fd_datasync(self.ctx, self.fd) })
wasi_errno_to_io_error(unsafe { hostcalls::fd_datasync(self.ctx, &mut [], self.fd) })
}

/// Truncates or extends the underlying file, updating the size of this file
Expand All @@ -55,7 +55,9 @@ impl<'ctx> File<'ctx> {
///
/// [`std::fs::File::set_len`]: https://doc.rust-lang.org/std/fs/struct.File.html#method.set_len
pub fn set_len(&self, size: u64) -> io::Result<()> {
wasi_errno_to_io_error(unsafe { hostcalls::fd_filestat_set_size(self.ctx, self.fd, size) })
wasi_errno_to_io_error(unsafe {
hostcalls::fd_filestat_set_size(self.ctx, &mut [], self.fd, size)
})
}

/// Queries metadata about the underlying file.
Expand All @@ -75,7 +77,7 @@ impl<'ctx> Drop for File<'ctx> {
// the file descriptor was closed or not, and if we retried (for
// something like EINTR), we might close another valid file descriptor
// opened after we closed ours.
let _ = unsafe { hostcalls::fd_close(self.ctx, self.fd) };
let _ = unsafe { hostcalls::fd_close(self.ctx, &mut [], self.fd) };
}
}

Expand Down
13 changes: 10 additions & 3 deletions crates/wasi-common/src/hostcalls/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ use crate::ctx::WasiCtx;
use crate::{hostcalls_impl, wasi, wasi32};

hostcalls! {
pub unsafe fn fd_close(wasi_ctx: &mut WasiCtx, fd: wasi::__wasi_fd_t,) -> wasi::__wasi_errno_t;
pub unsafe fn fd_close(wasi_ctx: &mut WasiCtx, memory: &mut [u8], fd: wasi::__wasi_fd_t,) -> wasi::__wasi_errno_t;

pub unsafe fn fd_datasync(wasi_ctx: &WasiCtx, fd: wasi::__wasi_fd_t,) -> wasi::__wasi_errno_t;
pub unsafe fn fd_datasync(wasi_ctx: &WasiCtx, memory: &mut [u8], fd: wasi::__wasi_fd_t,) -> wasi::__wasi_errno_t;

pub unsafe fn fd_pread(
wasi_ctx: &WasiCtx,
Expand Down Expand Up @@ -38,6 +38,7 @@ hostcalls! {

pub unsafe fn fd_renumber(
wasi_ctx: &mut WasiCtx,
memory: &mut [u8],
from: wasi::__wasi_fd_t,
to: wasi::__wasi_fd_t,
) -> wasi::__wasi_errno_t;
Expand Down Expand Up @@ -67,18 +68,20 @@ hostcalls! {

pub unsafe fn fd_fdstat_set_flags(
wasi_ctx: &WasiCtx,
memory: &mut [u8],
fd: wasi::__wasi_fd_t,
fdflags: wasi::__wasi_fdflags_t,
) -> wasi::__wasi_errno_t;

pub unsafe fn fd_fdstat_set_rights(
wasi_ctx: &mut WasiCtx,
memory: &mut [u8],
fd: wasi::__wasi_fd_t,
fs_rights_base: wasi::__wasi_rights_t,
fs_rights_inheriting: wasi::__wasi_rights_t,
) -> wasi::__wasi_errno_t;

pub unsafe fn fd_sync(wasi_ctx: &WasiCtx, fd: wasi::__wasi_fd_t,) -> wasi::__wasi_errno_t;
pub unsafe fn fd_sync(wasi_ctx: &WasiCtx, memory: &mut [u8], fd: wasi::__wasi_fd_t,) -> wasi::__wasi_errno_t;

pub unsafe fn fd_write(
wasi_ctx: &mut WasiCtx,
Expand All @@ -91,6 +94,7 @@ hostcalls! {

pub unsafe fn fd_advise(
wasi_ctx: &WasiCtx,
memory: &mut [u8],
fd: wasi::__wasi_fd_t,
offset: wasi::__wasi_filesize_t,
len: wasi::__wasi_filesize_t,
Expand All @@ -99,6 +103,7 @@ hostcalls! {

pub unsafe fn fd_allocate(
wasi_ctx: &WasiCtx,
memory: &mut [u8],
fd: wasi::__wasi_fd_t,
offset: wasi::__wasi_filesize_t,
len: wasi::__wasi_filesize_t,
Expand Down Expand Up @@ -179,6 +184,7 @@ hostcalls! {

pub unsafe fn fd_filestat_set_times(
wasi_ctx: &WasiCtx,
memory: &mut [u8],
fd: wasi::__wasi_fd_t,
st_atim: wasi::__wasi_timestamp_t,
st_mtim: wasi::__wasi_timestamp_t,
Expand All @@ -187,6 +193,7 @@ hostcalls! {

pub unsafe fn fd_filestat_set_size(
wasi_ctx: &WasiCtx,
memory: &mut [u8],
fd: wasi::__wasi_fd_t,
st_size: wasi::__wasi_filesize_t,
) -> wasi::__wasi_errno_t;
Expand Down
10 changes: 8 additions & 2 deletions crates/wasi-common/src/hostcalls/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use log::trace;
use wasi_common_cbindgen::wasi_common_cbindgen;

#[wasi_common_cbindgen]
pub unsafe fn proc_exit(rval: wasi::__wasi_exitcode_t) {
pub unsafe fn proc_exit(_wasi_ctx: &WasiCtx, _memory: &mut [u8], rval: wasi::__wasi_exitcode_t) {
trace!("proc_exit(rval={:?})", rval);
// TODO: Rather than call std::process::exit here, we should trigger a
// stack unwind similar to a trap.
Expand Down Expand Up @@ -51,18 +51,21 @@ hostcalls! {
) -> wasi::__wasi_errno_t;

pub unsafe fn random_get(
wasi_ctx: &WasiCtx,
memory: &mut [u8],
buf_ptr: wasi32::uintptr_t,
buf_len: wasi32::size_t,
) -> wasi::__wasi_errno_t;

pub unsafe fn clock_res_get(
wasi_ctx: &WasiCtx,
memory: &mut [u8],
clock_id: wasi::__wasi_clockid_t,
resolution_ptr: wasi32::uintptr_t,
) -> wasi::__wasi_errno_t;

pub unsafe fn clock_time_get(
wasi_ctx: &WasiCtx,
memory: &mut [u8],
clock_id: wasi::__wasi_clockid_t,
precision: wasi::__wasi_timestamp_t,
Expand All @@ -78,5 +81,8 @@ hostcalls! {
nevents: wasi32::uintptr_t,
) -> wasi::__wasi_errno_t;

pub unsafe fn sched_yield() -> wasi::__wasi_errno_t;
pub unsafe fn sched_yield(
wasi_ctx: &WasiCtx,
memory: &mut [u8],
) -> wasi::__wasi_errno_t;
}
25 changes: 22 additions & 3 deletions crates/wasi-common/src/hostcalls_impl/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ use std::fs::File;
use std::io::{self, Read, Seek, SeekFrom, Write};
use std::time::{Duration, SystemTime, UNIX_EPOCH};

pub(crate) unsafe fn fd_close(wasi_ctx: &mut WasiCtx, fd: wasi::__wasi_fd_t) -> Result<()> {
pub(crate) unsafe fn fd_close(
wasi_ctx: &mut WasiCtx,
_memory: &mut [u8],
fd: wasi::__wasi_fd_t,
) -> Result<()> {
trace!("fd_close(fd={:?})", fd);

if let Ok(fe) = wasi_ctx.get_fd_entry(fd) {
Expand All @@ -28,7 +32,11 @@ pub(crate) unsafe fn fd_close(wasi_ctx: &mut WasiCtx, fd: wasi::__wasi_fd_t) ->
Ok(())
}

pub(crate) unsafe fn fd_datasync(wasi_ctx: &WasiCtx, fd: wasi::__wasi_fd_t) -> Result<()> {
pub(crate) unsafe fn fd_datasync(
wasi_ctx: &WasiCtx,
_memory: &mut [u8],
fd: wasi::__wasi_fd_t,
) -> Result<()> {
trace!("fd_datasync(fd={:?})", fd);

let fd = wasi_ctx
Expand Down Expand Up @@ -173,6 +181,7 @@ pub(crate) unsafe fn fd_read(

pub(crate) unsafe fn fd_renumber(
wasi_ctx: &mut WasiCtx,
_memory: &mut [u8],
from: wasi::__wasi_fd_t,
to: wasi::__wasi_fd_t,
) -> Result<()> {
Expand Down Expand Up @@ -289,6 +298,7 @@ pub(crate) unsafe fn fd_fdstat_get(

pub(crate) unsafe fn fd_fdstat_set_flags(
wasi_ctx: &WasiCtx,
_memory: &mut [u8],
fd: wasi::__wasi_fd_t,
fdflags: wasi::__wasi_fdflags_t,
) -> Result<()> {
Expand All @@ -304,6 +314,7 @@ pub(crate) unsafe fn fd_fdstat_set_flags(

pub(crate) unsafe fn fd_fdstat_set_rights(
wasi_ctx: &mut WasiCtx,
_memory: &mut [u8],
fd: wasi::__wasi_fd_t,
fs_rights_base: wasi::__wasi_rights_t,
fs_rights_inheriting: wasi::__wasi_rights_t,
Expand All @@ -327,7 +338,11 @@ pub(crate) unsafe fn fd_fdstat_set_rights(
Ok(())
}

pub(crate) unsafe fn fd_sync(wasi_ctx: &WasiCtx, fd: wasi::__wasi_fd_t) -> Result<()> {
pub(crate) unsafe fn fd_sync(
wasi_ctx: &WasiCtx,
_memory: &mut [u8],
fd: wasi::__wasi_fd_t,
) -> Result<()> {
trace!("fd_sync(fd={:?})", fd);

let fd = wasi_ctx
Expand Down Expand Up @@ -381,6 +396,7 @@ pub(crate) unsafe fn fd_write(

pub(crate) unsafe fn fd_advise(
wasi_ctx: &WasiCtx,
_memory: &mut [u8],
fd: wasi::__wasi_fd_t,
offset: wasi::__wasi_filesize_t,
len: wasi::__wasi_filesize_t,
Expand All @@ -404,6 +420,7 @@ pub(crate) unsafe fn fd_advise(

pub(crate) unsafe fn fd_allocate(
wasi_ctx: &WasiCtx,
_memory: &mut [u8],
fd: wasi::__wasi_fd_t,
offset: wasi::__wasi_filesize_t,
len: wasi::__wasi_filesize_t,
Expand Down Expand Up @@ -687,6 +704,7 @@ pub(crate) unsafe fn fd_filestat_get(

pub(crate) unsafe fn fd_filestat_set_times(
wasi_ctx: &WasiCtx,
_memory: &mut [u8],
fd: wasi::__wasi_fd_t,
st_atim: wasi::__wasi_timestamp_t,
st_mtim: wasi::__wasi_timestamp_t,
Expand Down Expand Up @@ -746,6 +764,7 @@ pub(crate) fn fd_filestat_set_times_impl(

pub(crate) unsafe fn fd_filestat_set_size(
wasi_ctx: &WasiCtx,
_memory: &mut [u8],
fd: wasi::__wasi_fd_t,
st_size: wasi::__wasi_filesize_t,
) -> Result<()> {
Expand Down
5 changes: 4 additions & 1 deletion crates/wasi-common/src/hostcalls_impl/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ pub(crate) fn environ_sizes_get(
}

pub(crate) fn random_get(
_wasi_ctx: &WasiCtx,
memory: &mut [u8],
buf_ptr: wasi32::uintptr_t,
buf_len: wasi32::size_t,
Expand All @@ -143,6 +144,7 @@ pub(crate) fn random_get(
}

pub(crate) fn clock_res_get(
_wasi_ctx: &WasiCtx,
memory: &mut [u8],
clock_id: wasi::__wasi_clockid_t,
resolution_ptr: wasi32::uintptr_t,
Expand All @@ -161,6 +163,7 @@ pub(crate) fn clock_res_get(
}

pub(crate) fn clock_time_get(
_wasi_ctx: &WasiCtx,
memory: &mut [u8],
clock_id: wasi::__wasi_clockid_t,
precision: wasi::__wasi_timestamp_t,
Expand All @@ -180,7 +183,7 @@ pub(crate) fn clock_time_get(
enc_timestamp_byref(memory, time_ptr, time)
}

pub(crate) fn sched_yield() -> Result<()> {
pub(crate) fn sched_yield(_wasi_ctx: &WasiCtx, _memory: &mut [u8]) -> Result<()> {
trace!("sched_yield()");

std::thread::yield_now();
Expand Down
7 changes: 7 additions & 0 deletions crates/wasi-common/wig/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ extern crate proc_macro;

mod raw_types;
mod utils;
mod wasi;

use proc_macro::TokenStream;
use proc_macro2::TokenStream as TokenStream2;
Expand Down Expand Up @@ -29,3 +30,9 @@ pub fn witx_wasi32_types(args: TokenStream) -> TokenStream {
raw_types::Mode::Wasi32,
))
}

/// A single-use macro in the `wasmtime-wasi` crate.
#[proc_macro]
pub fn define_add_wrappers_to_module(args: TokenStream) -> TokenStream {
wasi::add_wrappers_to_module(args.into()).into()
}
5 changes: 3 additions & 2 deletions crates/wasi-common/wig/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use proc_macro2::{Literal, TokenStream, TokenTree};

/// Given the input tokens to a macro invocation, return the path to the
/// witx file to process.
pub(crate) fn witx_path_from_args(args: TokenStream) -> (String, String) {
Expand Down Expand Up @@ -26,8 +27,8 @@ pub(crate) fn witx_path_from_args(args: TokenStream) -> (String, String) {
}

fn witx_path(phase: &str, id: &str) -> String {
let root = std::env::var("CARGO_MANIFEST_DIR").unwrap_or(".".into());
format!("{}/WASI/phases/{}/witx/{}.witx", root, phase, id)
let root = env!("CARGO_MANIFEST_DIR");
format!("{}/../WASI/phases/{}/witx/{}.witx", root, phase, id)
}

// Convert a `Literal` holding a string literal into the `String`.
Expand Down
Loading