Skip to content
Closed
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
25 changes: 22 additions & 3 deletions crates/wasi-common/src/old/snapshot_0/hostcalls/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,17 @@ use crate::old::snapshot_0::ctx::WasiCtx;
use crate::old::snapshot_0::{wasi, wasi32};

hostcalls_old! {
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 +46,7 @@ hostcalls_old! {

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 +76,24 @@ hostcalls_old! {

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 +106,7 @@ hostcalls_old! {

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 +115,7 @@ hostcalls_old! {

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 +196,7 @@ hostcalls_old! {

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 +205,7 @@ hostcalls_old! {

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/old/snapshot_0/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_old;

#[wasi_common_cbindgen_old]
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_old! {
) -> 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_old! {
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/old/snapshot_0/hostcalls_impl/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ use std::io::{self, Read, Seek, SeekFrom, Write};
use std::ops::DerefMut;
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,
_mem: &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 @@ -30,7 +34,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,
_mem: &mut [u8],
fd: wasi::__wasi_fd_t,
) -> Result<()> {
trace!("fd_datasync(fd={:?})", fd);

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

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

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

pub(crate) unsafe fn fd_fdstat_set_rights(
wasi_ctx: &mut WasiCtx,
_mem: &mut [u8],
fd: wasi::__wasi_fd_t,
fs_rights_base: wasi::__wasi_rights_t,
fs_rights_inheriting: wasi::__wasi_rights_t,
Expand All @@ -329,7 +340,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,
_mem: &mut [u8],
fd: wasi::__wasi_fd_t,
) -> Result<()> {
trace!("fd_sync(fd={:?})", fd);

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

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

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

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

pub(crate) unsafe fn fd_filestat_set_size(
wasi_ctx: &WasiCtx,
_mem: &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/old/snapshot_0/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
2 changes: 1 addition & 1 deletion crates/wasi-common/wig/src/wasi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ pub fn add_wrappers_to_module(args: TokenStream) -> TokenStream {
Ok(e) => e,
Err(e) => #handle_early_error,
};
wasi_common::hostcalls::#name_ident(
hostcalls::#name_ident(
wasi_ctx,
memory,
#(#hostcall_args),*
Expand Down
1 change: 1 addition & 0 deletions crates/wasi/src/instantiate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use cranelift_wasm::DefinedFuncIndex;
use std::fs::File;
use std::rc::Rc;
use target_lexicon::HOST;
use wasi_common::hostcalls;
use wasi_common::wasi;
use wasi_common::{WasiCtx, WasiCtxBuilder};
use wasmtime_environ::{translate_signature, Export, Module};
Expand Down
Loading