Move common functionality into hostcalls mod
This commit is contained in:
@@ -4,7 +4,9 @@
|
||||
#![allow(unused)]
|
||||
use crate::host;
|
||||
|
||||
use std::ffi::{OsStr, OsString};
|
||||
use std::marker::PhantomData;
|
||||
use std::os::windows::prelude::{OsStrExt, OsStringExt};
|
||||
use std::slice;
|
||||
use winapi::shared::{ntdef, ws2def};
|
||||
|
||||
@@ -82,3 +84,17 @@ pub unsafe fn iovec_to_win_mut<'a>(iovec: &'a mut host::__wasi_iovec_t) -> IoVec
|
||||
let slice = slice::from_raw_parts_mut(iovec.buf as *mut u8, iovec.buf_len);
|
||||
IoVecMut::new(slice)
|
||||
}
|
||||
|
||||
pub fn path_from_raw(raw_path: &[u8]) -> OsString {
|
||||
OsString::from_wide(&raw_path.iter().map(|&x| x as u16).collect::<Vec<u16>>())
|
||||
}
|
||||
|
||||
pub fn path_to_raw<P: AsRef<OsStr>>(path: P) -> Vec<u8> {
|
||||
path.as_ref()
|
||||
.encode_wide()
|
||||
.map(u16::to_le_bytes)
|
||||
.fold(Vec::new(), |mut acc, bytes| {
|
||||
acc.extend_from_slice(&bytes);
|
||||
acc
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,452 +0,0 @@
|
||||
#![allow(non_camel_case_types)]
|
||||
#![allow(unused_unsafe)]
|
||||
#![allow(unused)]
|
||||
use super::host_impl;
|
||||
use super::host_impl::IoVec;
|
||||
|
||||
use crate::ctx::WasiCtx;
|
||||
use crate::memory::*;
|
||||
use crate::{host, wasm32};
|
||||
|
||||
use std::cmp;
|
||||
use std::os::windows::prelude::OsStrExt;
|
||||
use wasi_common_cbindgen::wasi_common_cbindgen;
|
||||
|
||||
#[wasi_common_cbindgen]
|
||||
pub fn fd_close(wasi_ctx: &mut WasiCtx, fd: wasm32::__wasi_fd_t) -> wasm32::__wasi_errno_t {
|
||||
unimplemented!("fd_close")
|
||||
}
|
||||
|
||||
#[wasi_common_cbindgen]
|
||||
pub fn fd_datasync(wasi_ctx: &WasiCtx, fd: wasm32::__wasi_fd_t) -> wasm32::__wasi_errno_t {
|
||||
unimplemented!("fd_datasync")
|
||||
}
|
||||
|
||||
#[wasi_common_cbindgen]
|
||||
pub fn fd_pread(
|
||||
wasi_ctx: &WasiCtx,
|
||||
memory: &mut [u8],
|
||||
fd: wasm32::__wasi_fd_t,
|
||||
iovs_ptr: wasm32::uintptr_t,
|
||||
iovs_len: wasm32::size_t,
|
||||
offset: wasm32::__wasi_filesize_t,
|
||||
nread: wasm32::uintptr_t,
|
||||
) -> wasm32::__wasi_errno_t {
|
||||
unimplemented!("fd_pread")
|
||||
}
|
||||
|
||||
#[wasi_common_cbindgen]
|
||||
pub fn fd_pwrite(
|
||||
wasi_ctx: &WasiCtx,
|
||||
memory: &mut [u8],
|
||||
fd: wasm32::__wasi_fd_t,
|
||||
iovs_ptr: wasm32::uintptr_t,
|
||||
iovs_len: wasm32::size_t,
|
||||
offset: wasm32::__wasi_filesize_t,
|
||||
nwritten: wasm32::uintptr_t,
|
||||
) -> wasm32::__wasi_errno_t {
|
||||
unimplemented!("fd_pwrite")
|
||||
}
|
||||
|
||||
#[wasi_common_cbindgen]
|
||||
pub fn fd_read(
|
||||
wasi_ctx: &mut WasiCtx,
|
||||
memory: &mut [u8],
|
||||
fd: wasm32::__wasi_fd_t,
|
||||
iovs_ptr: wasm32::uintptr_t,
|
||||
iovs_len: wasm32::size_t,
|
||||
nread: wasm32::uintptr_t,
|
||||
) -> wasm32::__wasi_errno_t {
|
||||
unimplemented!("fd_read")
|
||||
}
|
||||
|
||||
#[wasi_common_cbindgen]
|
||||
pub fn fd_renumber(
|
||||
wasi_ctx: &mut WasiCtx,
|
||||
from: wasm32::__wasi_fd_t,
|
||||
to: wasm32::__wasi_fd_t,
|
||||
) -> wasm32::__wasi_errno_t {
|
||||
unimplemented!("fd_renumber")
|
||||
}
|
||||
|
||||
#[wasi_common_cbindgen]
|
||||
pub fn fd_seek(
|
||||
wasi_ctx: &WasiCtx,
|
||||
memory: &mut [u8],
|
||||
fd: wasm32::__wasi_fd_t,
|
||||
offset: wasm32::__wasi_filedelta_t,
|
||||
whence: wasm32::__wasi_whence_t,
|
||||
newoffset: wasm32::uintptr_t,
|
||||
) -> wasm32::__wasi_errno_t {
|
||||
unimplemented!("fd_seek")
|
||||
}
|
||||
|
||||
#[wasi_common_cbindgen]
|
||||
pub fn fd_tell(
|
||||
wasi_ctx: &WasiCtx,
|
||||
memory: &mut [u8],
|
||||
fd: wasm32::__wasi_fd_t,
|
||||
newoffset: wasm32::uintptr_t,
|
||||
) -> wasm32::__wasi_errno_t {
|
||||
unimplemented!("fd_tell")
|
||||
}
|
||||
|
||||
#[wasi_common_cbindgen]
|
||||
pub fn fd_fdstat_get(
|
||||
wasi_ctx: &WasiCtx,
|
||||
memory: &mut [u8],
|
||||
fd: wasm32::__wasi_fd_t,
|
||||
fdstat_ptr: wasm32::uintptr_t, // *mut wasm32::__wasi_fdstat_t
|
||||
) -> wasm32::__wasi_errno_t {
|
||||
unimplemented!("fd_fdstat_get")
|
||||
}
|
||||
|
||||
#[wasi_common_cbindgen]
|
||||
pub fn fd_fdstat_set_flags(
|
||||
wasi_ctx: &WasiCtx,
|
||||
fd: wasm32::__wasi_fd_t,
|
||||
fdflags: wasm32::__wasi_fdflags_t,
|
||||
) -> wasm32::__wasi_errno_t {
|
||||
unimplemented!("fd_fdstat_set_flags")
|
||||
}
|
||||
|
||||
#[wasi_common_cbindgen]
|
||||
pub fn fd_fdstat_set_rights(
|
||||
wasi_ctx: &mut WasiCtx,
|
||||
fd: wasm32::__wasi_fd_t,
|
||||
fs_rights_base: wasm32::__wasi_rights_t,
|
||||
fs_rights_inheriting: wasm32::__wasi_rights_t,
|
||||
) -> wasm32::__wasi_errno_t {
|
||||
unimplemented!("fd_fdstat_set_rights")
|
||||
}
|
||||
|
||||
#[wasi_common_cbindgen]
|
||||
pub fn fd_sync(wasi_ctx: &WasiCtx, fd: wasm32::__wasi_fd_t) -> wasm32::__wasi_errno_t {
|
||||
unimplemented!("fd_sync")
|
||||
}
|
||||
|
||||
#[wasi_common_cbindgen]
|
||||
pub fn fd_write(
|
||||
wasi_ctx: &WasiCtx,
|
||||
memory: &mut [u8],
|
||||
fd: wasm32::__wasi_fd_t,
|
||||
iovs_ptr: wasm32::uintptr_t,
|
||||
iovs_len: wasm32::size_t,
|
||||
nwritten: wasm32::uintptr_t,
|
||||
) -> wasm32::__wasi_errno_t {
|
||||
use winapi::shared::minwindef::{DWORD, LPVOID};
|
||||
use winapi::shared::ws2def::WSABUF;
|
||||
use winapi::um::fileapi::WriteFile;
|
||||
|
||||
let fd = dec_fd(fd);
|
||||
let mut iovs = match dec_iovec_slice(memory, iovs_ptr, iovs_len) {
|
||||
Ok(iovs) => iovs,
|
||||
Err(e) => return enc_errno(e),
|
||||
};
|
||||
|
||||
let fe = match wasi_ctx.get_fd_entry(fd, host::__WASI_RIGHT_FD_WRITE.into(), 0) {
|
||||
Ok(fe) => fe,
|
||||
Err(e) => return enc_errno(e),
|
||||
};
|
||||
|
||||
let iovs: Vec<IoVec> = iovs
|
||||
.iter()
|
||||
.map(|iov| unsafe { host_impl::iovec_to_win(iov) })
|
||||
.collect();
|
||||
|
||||
let buf = iovs
|
||||
.iter()
|
||||
.find(|b| !b.as_slice().is_empty())
|
||||
.map_or(&[][..], |b| b.as_slice());
|
||||
|
||||
let mut host_nwritten = 0;
|
||||
let len = cmp::min(buf.len(), <DWORD>::max_value() as usize) as DWORD;
|
||||
unsafe {
|
||||
WriteFile(
|
||||
fe.fd_object.raw_handle,
|
||||
buf.as_ptr() as LPVOID,
|
||||
len,
|
||||
&mut host_nwritten,
|
||||
std::ptr::null_mut(),
|
||||
)
|
||||
};
|
||||
|
||||
enc_usize_byref(memory, nwritten, host_nwritten as usize)
|
||||
.map(|_| wasm32::__WASI_ESUCCESS)
|
||||
.unwrap_or_else(|e| e)
|
||||
}
|
||||
|
||||
#[wasi_common_cbindgen]
|
||||
pub fn fd_advise(
|
||||
wasi_ctx: &WasiCtx,
|
||||
fd: wasm32::__wasi_fd_t,
|
||||
offset: wasm32::__wasi_filesize_t,
|
||||
len: wasm32::__wasi_filesize_t,
|
||||
advice: wasm32::__wasi_advice_t,
|
||||
) -> wasm32::__wasi_errno_t {
|
||||
unimplemented!("fd_advise")
|
||||
}
|
||||
|
||||
#[wasi_common_cbindgen]
|
||||
pub fn fd_allocate(
|
||||
wasi_ctx: &WasiCtx,
|
||||
fd: wasm32::__wasi_fd_t,
|
||||
offset: wasm32::__wasi_filesize_t,
|
||||
len: wasm32::__wasi_filesize_t,
|
||||
) -> wasm32::__wasi_errno_t {
|
||||
unimplemented!("fd_allocate")
|
||||
}
|
||||
|
||||
#[wasi_common_cbindgen]
|
||||
pub fn path_create_directory(
|
||||
wasi_ctx: &WasiCtx,
|
||||
memory: &mut [u8],
|
||||
dirfd: wasm32::__wasi_fd_t,
|
||||
path_ptr: wasm32::uintptr_t,
|
||||
path_len: wasm32::size_t,
|
||||
) -> wasm32::__wasi_errno_t {
|
||||
unimplemented!("path_create_directory")
|
||||
}
|
||||
|
||||
#[wasi_common_cbindgen]
|
||||
pub fn path_link(
|
||||
wasi_ctx: &WasiCtx,
|
||||
memory: &mut [u8],
|
||||
old_dirfd: wasm32::__wasi_fd_t,
|
||||
_old_flags: wasm32::__wasi_lookupflags_t,
|
||||
old_path_ptr: wasm32::uintptr_t,
|
||||
old_path_len: wasm32::size_t,
|
||||
new_dirfd: wasm32::__wasi_fd_t,
|
||||
new_path_ptr: wasm32::uintptr_t,
|
||||
new_path_len: wasm32::size_t,
|
||||
) -> wasm32::__wasi_errno_t {
|
||||
unimplemented!("path_link")
|
||||
}
|
||||
|
||||
#[wasi_common_cbindgen]
|
||||
pub fn path_open(
|
||||
wasi_ctx: &mut WasiCtx,
|
||||
memory: &mut [u8],
|
||||
dirfd: wasm32::__wasi_fd_t,
|
||||
dirflags: wasm32::__wasi_lookupflags_t,
|
||||
path_ptr: wasm32::uintptr_t,
|
||||
path_len: wasm32::size_t,
|
||||
oflags: wasm32::__wasi_oflags_t,
|
||||
fs_rights_base: wasm32::__wasi_rights_t,
|
||||
fs_rights_inheriting: wasm32::__wasi_rights_t,
|
||||
fs_flags: wasm32::__wasi_fdflags_t,
|
||||
fd_out_ptr: wasm32::uintptr_t,
|
||||
) -> wasm32::__wasi_errno_t {
|
||||
unimplemented!("path_open")
|
||||
}
|
||||
|
||||
#[wasi_common_cbindgen]
|
||||
pub fn fd_readdir(
|
||||
wasi_ctx: &WasiCtx,
|
||||
memory: &mut [u8],
|
||||
fd: wasm32::__wasi_fd_t,
|
||||
buf: wasm32::uintptr_t,
|
||||
buf_len: wasm32::size_t,
|
||||
cookie: wasm32::__wasi_dircookie_t,
|
||||
buf_used: wasm32::uintptr_t,
|
||||
) -> wasm32::__wasi_errno_t {
|
||||
unimplemented!("fd_readdir")
|
||||
}
|
||||
|
||||
#[wasi_common_cbindgen]
|
||||
pub fn path_readlink(
|
||||
wasi_ctx: &WasiCtx,
|
||||
memory: &mut [u8],
|
||||
dirfd: wasm32::__wasi_fd_t,
|
||||
path_ptr: wasm32::uintptr_t,
|
||||
path_len: wasm32::size_t,
|
||||
buf_ptr: wasm32::uintptr_t,
|
||||
buf_len: wasm32::size_t,
|
||||
buf_used: wasm32::uintptr_t,
|
||||
) -> wasm32::__wasi_errno_t {
|
||||
unimplemented!("path_readlink")
|
||||
}
|
||||
|
||||
#[wasi_common_cbindgen]
|
||||
pub fn path_rename(
|
||||
wasi_ctx: &WasiCtx,
|
||||
memory: &mut [u8],
|
||||
old_dirfd: wasm32::__wasi_fd_t,
|
||||
old_path_ptr: wasm32::uintptr_t,
|
||||
old_path_len: wasm32::size_t,
|
||||
new_dirfd: wasm32::__wasi_fd_t,
|
||||
new_path_ptr: wasm32::uintptr_t,
|
||||
new_path_len: wasm32::size_t,
|
||||
) -> wasm32::__wasi_errno_t {
|
||||
unimplemented!("path_rename")
|
||||
}
|
||||
|
||||
#[wasi_common_cbindgen]
|
||||
pub fn fd_filestat_get(
|
||||
wasi_ctx: &WasiCtx,
|
||||
memory: &mut [u8],
|
||||
fd: wasm32::__wasi_fd_t,
|
||||
filestat_ptr: wasm32::uintptr_t,
|
||||
) -> wasm32::__wasi_errno_t {
|
||||
unimplemented!("fd_filestat_get")
|
||||
}
|
||||
|
||||
#[wasi_common_cbindgen]
|
||||
pub fn fd_filestat_set_times(
|
||||
wasi_ctx: &WasiCtx,
|
||||
fd: wasm32::__wasi_fd_t,
|
||||
st_atim: wasm32::__wasi_timestamp_t,
|
||||
st_mtim: wasm32::__wasi_timestamp_t,
|
||||
fst_flags: wasm32::__wasi_fstflags_t,
|
||||
) -> wasm32::__wasi_errno_t {
|
||||
unimplemented!("fd_filestat_set_times")
|
||||
}
|
||||
|
||||
#[wasi_common_cbindgen]
|
||||
pub fn fd_filestat_set_size(
|
||||
wasi_ctx: &WasiCtx,
|
||||
fd: wasm32::__wasi_fd_t,
|
||||
st_size: wasm32::__wasi_filesize_t,
|
||||
) -> wasm32::__wasi_errno_t {
|
||||
unimplemented!("fd_filestat_set_size")
|
||||
}
|
||||
|
||||
#[wasi_common_cbindgen]
|
||||
pub fn path_filestat_get(
|
||||
wasi_ctx: &WasiCtx,
|
||||
memory: &mut [u8],
|
||||
dirfd: wasm32::__wasi_fd_t,
|
||||
dirflags: wasm32::__wasi_lookupflags_t,
|
||||
path_ptr: wasm32::uintptr_t,
|
||||
path_len: wasm32::size_t,
|
||||
filestat_ptr: wasm32::uintptr_t,
|
||||
) -> wasm32::__wasi_errno_t {
|
||||
unimplemented!("path_filestat_get")
|
||||
}
|
||||
|
||||
#[wasi_common_cbindgen]
|
||||
pub fn path_filestat_set_times(
|
||||
wasi_ctx: &WasiCtx,
|
||||
memory: &mut [u8],
|
||||
dirfd: wasm32::__wasi_fd_t,
|
||||
dirflags: wasm32::__wasi_lookupflags_t,
|
||||
path_ptr: wasm32::uintptr_t,
|
||||
path_len: wasm32::size_t,
|
||||
st_atim: wasm32::__wasi_timestamp_t,
|
||||
st_mtim: wasm32::__wasi_timestamp_t,
|
||||
fst_flags: wasm32::__wasi_fstflags_t,
|
||||
) -> wasm32::__wasi_errno_t {
|
||||
unimplemented!("path_filestat_set_times")
|
||||
}
|
||||
|
||||
#[wasi_common_cbindgen]
|
||||
pub fn path_symlink(
|
||||
wasi_ctx: &WasiCtx,
|
||||
memory: &mut [u8],
|
||||
old_path_ptr: wasm32::uintptr_t,
|
||||
old_path_len: wasm32::size_t,
|
||||
dirfd: wasm32::__wasi_fd_t,
|
||||
new_path_ptr: wasm32::uintptr_t,
|
||||
new_path_len: wasm32::size_t,
|
||||
) -> wasm32::__wasi_errno_t {
|
||||
unimplemented!("path_symlink")
|
||||
}
|
||||
|
||||
#[wasi_common_cbindgen]
|
||||
pub fn path_unlink_file(
|
||||
wasi_ctx: &WasiCtx,
|
||||
memory: &mut [u8],
|
||||
dirfd: wasm32::__wasi_fd_t,
|
||||
path_ptr: wasm32::uintptr_t,
|
||||
path_len: wasm32::size_t,
|
||||
) -> wasm32::__wasi_errno_t {
|
||||
unimplemented!("path_unlink_file")
|
||||
}
|
||||
|
||||
#[wasi_common_cbindgen]
|
||||
pub fn path_remove_directory(
|
||||
wasi_ctx: &WasiCtx,
|
||||
memory: &mut [u8],
|
||||
dirfd: wasm32::__wasi_fd_t,
|
||||
path_ptr: wasm32::uintptr_t,
|
||||
path_len: wasm32::size_t,
|
||||
) -> wasm32::__wasi_errno_t {
|
||||
unimplemented!("path_remove_directory")
|
||||
}
|
||||
|
||||
#[wasi_common_cbindgen]
|
||||
pub fn fd_prestat_get(
|
||||
wasi_ctx: &WasiCtx,
|
||||
memory: &mut [u8],
|
||||
fd: wasm32::__wasi_fd_t,
|
||||
prestat_ptr: wasm32::uintptr_t,
|
||||
) -> wasm32::__wasi_errno_t {
|
||||
let fd = dec_fd(fd);
|
||||
// TODO: is this the correct right for this?
|
||||
match wasi_ctx.get_fd_entry(fd, host::__WASI_RIGHT_PATH_OPEN.into(), 0) {
|
||||
Ok(fe) => {
|
||||
if let Some(po_path) = &fe.preopen_path {
|
||||
if fe.fd_object.ty != host::__WASI_FILETYPE_DIRECTORY {
|
||||
return wasm32::__WASI_ENOTDIR;
|
||||
}
|
||||
enc_prestat_byref(
|
||||
memory,
|
||||
prestat_ptr,
|
||||
host::__wasi_prestat_t {
|
||||
pr_type: host::__WASI_PREOPENTYPE_DIR,
|
||||
u: host::__wasi_prestat_t___wasi_prestat_u {
|
||||
dir: host::__wasi_prestat_t___wasi_prestat_u___wasi_prestat_u_dir_t {
|
||||
// TODO: clean up
|
||||
pr_name_len: po_path.as_os_str().encode_wide().count() * 2,
|
||||
},
|
||||
},
|
||||
},
|
||||
)
|
||||
.map(|_| wasm32::__WASI_ESUCCESS)
|
||||
.unwrap_or_else(|e| e)
|
||||
} else {
|
||||
wasm32::__WASI_ENOTSUP
|
||||
}
|
||||
}
|
||||
Err(e) => enc_errno(e),
|
||||
}
|
||||
}
|
||||
|
||||
#[wasi_common_cbindgen]
|
||||
pub fn fd_prestat_dir_name(
|
||||
wasi_ctx: &WasiCtx,
|
||||
memory: &mut [u8],
|
||||
fd: wasm32::__wasi_fd_t,
|
||||
path_ptr: wasm32::uintptr_t,
|
||||
path_len: wasm32::size_t,
|
||||
) -> wasm32::__wasi_errno_t {
|
||||
let fd = dec_fd(fd);
|
||||
|
||||
match wasi_ctx.get_fd_entry(fd, host::__WASI_RIGHT_PATH_OPEN.into(), 0) {
|
||||
Ok(fe) => {
|
||||
if let Some(po_path) = &fe.preopen_path {
|
||||
if fe.fd_object.ty != host::__WASI_FILETYPE_DIRECTORY {
|
||||
return wasm32::__WASI_ENOTDIR;
|
||||
}
|
||||
// TODO: clean up
|
||||
let path_bytes = &po_path
|
||||
.as_os_str()
|
||||
.encode_wide()
|
||||
.map(u16::to_le_bytes)
|
||||
.fold(Vec::new(), |mut acc, bytes| {
|
||||
acc.extend_from_slice(&bytes);
|
||||
acc
|
||||
});
|
||||
if path_bytes.len() > dec_usize(path_len) {
|
||||
return wasm32::__WASI_ENAMETOOLONG;
|
||||
}
|
||||
enc_slice_of(memory, path_bytes, path_ptr)
|
||||
.map(|_| wasm32::__WASI_ESUCCESS)
|
||||
.unwrap_or_else(|e| e)
|
||||
} else {
|
||||
wasm32::__WASI_ENOTSUP
|
||||
}
|
||||
}
|
||||
Err(e) => enc_errno(e),
|
||||
}
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
#![allow(non_camel_case_types)]
|
||||
#![allow(unused_unsafe)]
|
||||
#![allow(unused)]
|
||||
use super::host_impl;
|
||||
|
||||
use crate::memory::*;
|
||||
use crate::{host, wasm32};
|
||||
|
||||
use std::cmp;
|
||||
use std::time::SystemTime;
|
||||
use wasi_common_cbindgen::wasi_common_cbindgen;
|
||||
|
||||
#[wasi_common_cbindgen]
|
||||
pub fn clock_res_get(
|
||||
memory: &mut [u8],
|
||||
clock_id: wasm32::__wasi_clockid_t,
|
||||
resolution_ptr: wasm32::uintptr_t,
|
||||
) -> wasm32::__wasi_errno_t {
|
||||
unimplemented!("clock_res_get")
|
||||
}
|
||||
|
||||
#[wasi_common_cbindgen]
|
||||
pub fn clock_time_get(
|
||||
memory: &mut [u8],
|
||||
clock_id: wasm32::__wasi_clockid_t,
|
||||
precision: wasm32::__wasi_timestamp_t,
|
||||
time_ptr: wasm32::uintptr_t,
|
||||
) -> wasm32::__wasi_errno_t {
|
||||
unimplemented!("clock_time_get")
|
||||
}
|
||||
|
||||
#[wasi_common_cbindgen]
|
||||
pub fn poll_oneoff(
|
||||
memory: &mut [u8],
|
||||
input: wasm32::uintptr_t,
|
||||
output: wasm32::uintptr_t,
|
||||
nsubscriptions: wasm32::size_t,
|
||||
nevents: wasm32::uintptr_t,
|
||||
) -> wasm32::__wasi_errno_t {
|
||||
unimplemented!("poll_oneoff")
|
||||
}
|
||||
|
||||
#[wasi_common_cbindgen]
|
||||
pub fn sched_yield() -> wasm32::__wasi_errno_t {
|
||||
unimplemented!("sched_yield")
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
#![allow(non_camel_case_types)]
|
||||
#![allow(unused_unsafe)]
|
||||
#![allow(unused)]
|
||||
|
||||
use crate::ctx::WasiCtx;
|
||||
use crate::wasm32;
|
||||
use wasi_common_cbindgen::wasi_common_cbindgen;
|
||||
|
||||
#[wasi_common_cbindgen]
|
||||
pub fn sock_recv(
|
||||
wasi_ctx: &WasiCtx,
|
||||
memory: &mut [u8],
|
||||
sock: wasm32::__wasi_fd_t,
|
||||
ri_data: wasm32::uintptr_t,
|
||||
ri_data_len: wasm32::size_t,
|
||||
ri_flags: wasm32::__wasi_riflags_t,
|
||||
ro_datalen: wasm32::uintptr_t,
|
||||
ro_flags: wasm32::uintptr_t,
|
||||
) -> wasm32::__wasi_errno_t {
|
||||
unimplemented!("sock_recv")
|
||||
}
|
||||
|
||||
#[wasi_common_cbindgen]
|
||||
pub fn sock_send(
|
||||
wasi_ctx: &WasiCtx,
|
||||
memory: &mut [u8],
|
||||
sock: wasm32::__wasi_fd_t,
|
||||
si_data: wasm32::uintptr_t,
|
||||
si_data_len: wasm32::size_t,
|
||||
si_flags: wasm32::__wasi_siflags_t,
|
||||
so_datalen: wasm32::uintptr_t,
|
||||
) -> wasm32::__wasi_errno_t {
|
||||
unimplemented!("sock_send")
|
||||
}
|
||||
|
||||
#[wasi_common_cbindgen]
|
||||
pub fn sock_shutdown(
|
||||
wasi_ctx: &WasiCtx,
|
||||
memory: &mut [u8],
|
||||
sock: wasm32::__wasi_fd_t,
|
||||
how: wasm32::__wasi_sdflags_t,
|
||||
) -> wasm32::__wasi_errno_t {
|
||||
unimplemented!("sock_shutdown")
|
||||
}
|
||||
264
src/sys/windows/hostcalls_impl/fs.rs
Normal file
264
src/sys/windows/hostcalls_impl/fs.rs
Normal file
@@ -0,0 +1,264 @@
|
||||
#![allow(non_camel_case_types)]
|
||||
#![allow(unused_unsafe)]
|
||||
#![allow(unused)]
|
||||
use super::fdentry::FdEntry;
|
||||
use super::host_impl;
|
||||
|
||||
use crate::ctx::WasiCtx;
|
||||
use crate::host;
|
||||
|
||||
use std::ffi::OsStr;
|
||||
|
||||
pub(crate) fn fd_close(fd_entry: FdEntry) -> Result<(), host::__wasi_errno_t> {
|
||||
unimplemented!("fd_close")
|
||||
}
|
||||
|
||||
pub(crate) fn fd_datasync(fd_entry: &FdEntry) -> Result<(), host::__wasi_errno_t> {
|
||||
unimplemented!("fd_datasync")
|
||||
}
|
||||
|
||||
pub(crate) fn fd_pread(
|
||||
fd_entry: &FdEntry,
|
||||
buf: &mut [u8],
|
||||
offset: host::__wasi_filesize_t,
|
||||
) -> Result<usize, host::__wasi_errno_t> {
|
||||
unimplemented!("fd_pread")
|
||||
}
|
||||
|
||||
pub(crate) fn fd_pwrite(
|
||||
fd_entry: &FdEntry,
|
||||
buf: &[u8],
|
||||
offset: host::__wasi_filesize_t,
|
||||
) -> Result<usize, host::__wasi_errno_t> {
|
||||
unimplemented!("fd_pwrite")
|
||||
}
|
||||
|
||||
pub(crate) fn fd_read(
|
||||
fd_entry: &FdEntry,
|
||||
iovs: &mut [host::__wasi_iovec_t],
|
||||
) -> Result<usize, host::__wasi_errno_t> {
|
||||
unimplemented!("fd_pread")
|
||||
}
|
||||
|
||||
pub(crate) fn fd_renumber(
|
||||
wasi_ctx: &mut WasiCtx,
|
||||
from: host::__wasi_fd_t,
|
||||
to: host::__wasi_fd_t,
|
||||
) -> Result<(), host::__wasi_errno_t> {
|
||||
unimplemented!("fd_renumber")
|
||||
}
|
||||
|
||||
pub(crate) fn fd_seek(
|
||||
fd_entry: &FdEntry,
|
||||
offset: host::__wasi_filedelta_t,
|
||||
whence: host::__wasi_whence_t,
|
||||
) -> Result<u64, host::__wasi_errno_t> {
|
||||
unimplemented!("fd_seek")
|
||||
}
|
||||
|
||||
pub(crate) fn fd_tell(fd_entry: &FdEntry) -> Result<u64, host::__wasi_errno_t> {
|
||||
unimplemented!("fd_tell")
|
||||
}
|
||||
|
||||
pub(crate) fn fd_fdstat_get(
|
||||
fd_entry: &FdEntry,
|
||||
) -> Result<host::__wasi_fdflags_t, host::__wasi_errno_t> {
|
||||
unimplemented!("fd_fdstat_get")
|
||||
}
|
||||
|
||||
pub(crate) fn fd_fdstat_set_flags(
|
||||
fd_entry: &FdEntry,
|
||||
fdflags: host::__wasi_fdflags_t,
|
||||
) -> Result<(), host::__wasi_errno_t> {
|
||||
unimplemented!("fd_fdstat_set_flags")
|
||||
}
|
||||
|
||||
pub(crate) fn fd_sync(fd_entry: &FdEntry) -> Result<(), host::__wasi_errno_t> {
|
||||
unimplemented!("fd_sync")
|
||||
}
|
||||
|
||||
pub(crate) fn fd_write(
|
||||
fd_entry: &FdEntry,
|
||||
iovs: &[host::__wasi_iovec_t],
|
||||
) -> Result<usize, host::__wasi_errno_t> {
|
||||
use winapi::shared::minwindef::{DWORD, LPVOID};
|
||||
use winapi::um::fileapi::WriteFile;
|
||||
|
||||
let iovs: Vec<host_impl::IoVec> = iovs
|
||||
.iter()
|
||||
.map(|iov| unsafe { host_impl::iovec_to_win(iov) })
|
||||
.collect();
|
||||
|
||||
let buf = iovs
|
||||
.iter()
|
||||
.find(|b| !b.as_slice().is_empty())
|
||||
.map_or(&[][..], |b| b.as_slice());
|
||||
|
||||
let mut host_nwritten = 0;
|
||||
let len = std::cmp::min(buf.len(), <DWORD>::max_value() as usize) as DWORD;
|
||||
unsafe {
|
||||
WriteFile(
|
||||
fd_entry.fd_object.raw_handle,
|
||||
buf.as_ptr() as LPVOID,
|
||||
len,
|
||||
&mut host_nwritten,
|
||||
std::ptr::null_mut(),
|
||||
)
|
||||
};
|
||||
|
||||
Ok(host_nwritten as usize)
|
||||
}
|
||||
|
||||
pub(crate) fn fd_advise(
|
||||
fd_entry: &FdEntry,
|
||||
advice: host::__wasi_advice_t,
|
||||
offset: host::__wasi_filesize_t,
|
||||
len: host::__wasi_filesize_t,
|
||||
) -> Result<(), host::__wasi_errno_t> {
|
||||
unimplemented!("fd_advise")
|
||||
}
|
||||
|
||||
pub(crate) fn fd_allocate(
|
||||
fd_entry: &FdEntry,
|
||||
offset: host::__wasi_filesize_t,
|
||||
len: host::__wasi_filesize_t,
|
||||
) -> Result<(), host::__wasi_errno_t> {
|
||||
unimplemented!("fd_allocate")
|
||||
}
|
||||
|
||||
pub(crate) fn path_create_directory(
|
||||
ctx: &WasiCtx,
|
||||
dirfd: host::__wasi_fd_t,
|
||||
path: &OsStr,
|
||||
) -> Result<(), host::__wasi_errno_t> {
|
||||
unimplemented!("path_create_directory")
|
||||
}
|
||||
|
||||
pub(crate) fn path_link(
|
||||
ctx: &WasiCtx,
|
||||
old_dirfd: host::__wasi_fd_t,
|
||||
new_dirfd: host::__wasi_fd_t,
|
||||
old_path: &OsStr,
|
||||
new_path: &OsStr,
|
||||
source_rights: host::__wasi_rights_t,
|
||||
target_rights: host::__wasi_rights_t,
|
||||
) -> Result<(), host::__wasi_errno_t> {
|
||||
unimplemented!("path_link")
|
||||
}
|
||||
|
||||
pub(crate) fn path_open(
|
||||
ctx: &WasiCtx,
|
||||
dirfd: host::__wasi_fd_t,
|
||||
dirflags: host::__wasi_lookupflags_t,
|
||||
path: &OsStr,
|
||||
oflags: host::__wasi_oflags_t,
|
||||
read: bool,
|
||||
write: bool,
|
||||
mut needed_base: host::__wasi_rights_t,
|
||||
mut needed_inheriting: host::__wasi_rights_t,
|
||||
fs_flags: host::__wasi_fdflags_t,
|
||||
) -> Result<FdEntry, host::__wasi_errno_t> {
|
||||
unimplemented!("path_open")
|
||||
}
|
||||
|
||||
pub(crate) fn fd_readdir(
|
||||
fd_entry: &FdEntry,
|
||||
host_buf: &mut [u8],
|
||||
cookie: host::__wasi_dircookie_t,
|
||||
) -> Result<usize, host::__wasi_errno_t> {
|
||||
unimplemented!("fd_readdir")
|
||||
}
|
||||
|
||||
pub(crate) fn path_readlink(
|
||||
wasi_ctx: &WasiCtx,
|
||||
dirfd: host::__wasi_fd_t,
|
||||
path: &OsStr,
|
||||
rights: host::__wasi_rights_t,
|
||||
buf: &mut [u8],
|
||||
) -> Result<usize, host::__wasi_errno_t> {
|
||||
unimplemented!("path_readlink")
|
||||
}
|
||||
|
||||
pub(crate) fn path_rename(
|
||||
wasi_ctx: &WasiCtx,
|
||||
old_dirfd: host::__wasi_fd_t,
|
||||
old_path: &OsStr,
|
||||
old_rights: host::__wasi_rights_t,
|
||||
new_dirfd: host::__wasi_fd_t,
|
||||
new_path: &OsStr,
|
||||
new_rights: host::__wasi_rights_t,
|
||||
) -> Result<(), host::__wasi_errno_t> {
|
||||
unimplemented!("path_rename")
|
||||
}
|
||||
|
||||
pub(crate) fn fd_filestat_get(
|
||||
fd_entry: &FdEntry,
|
||||
) -> Result<host::__wasi_filestat_t, host::__wasi_errno_t> {
|
||||
unimplemented!("fd_filestat_get")
|
||||
}
|
||||
|
||||
pub(crate) fn fd_filestat_set_times(
|
||||
fd_entry: &FdEntry,
|
||||
st_atim: host::__wasi_timestamp_t,
|
||||
mut st_mtim: host::__wasi_timestamp_t,
|
||||
fst_flags: host::__wasi_fstflags_t,
|
||||
) -> Result<(), host::__wasi_errno_t> {
|
||||
unimplemented!("fd_filestat_set_times")
|
||||
}
|
||||
|
||||
pub(crate) fn fd_filestat_set_size(
|
||||
fd_entry: &FdEntry,
|
||||
st_size: host::__wasi_filesize_t,
|
||||
) -> Result<(), host::__wasi_errno_t> {
|
||||
unimplemented!("fd_filestat_set_size")
|
||||
}
|
||||
|
||||
pub(crate) fn path_filestat_get(
|
||||
wasi_ctx: &WasiCtx,
|
||||
dirfd: host::__wasi_fd_t,
|
||||
dirflags: host::__wasi_lookupflags_t,
|
||||
path: &OsStr,
|
||||
) -> Result<host::__wasi_filestat_t, host::__wasi_errno_t> {
|
||||
unimplemented!("path_filestat_get")
|
||||
}
|
||||
|
||||
pub(crate) fn path_filestat_set_times(
|
||||
wasi_ctx: &WasiCtx,
|
||||
dirfd: host::__wasi_fd_t,
|
||||
dirflags: host::__wasi_lookupflags_t,
|
||||
path: &OsStr,
|
||||
rights: host::__wasi_rights_t,
|
||||
st_atim: host::__wasi_timestamp_t,
|
||||
mut st_mtim: host::__wasi_timestamp_t,
|
||||
fst_flags: host::__wasi_fstflags_t,
|
||||
) -> Result<(), host::__wasi_errno_t> {
|
||||
unimplemented!("path_filestat_set_times")
|
||||
}
|
||||
|
||||
pub(crate) fn path_symlink(
|
||||
wasi_ctx: &WasiCtx,
|
||||
dirfd: host::__wasi_fd_t,
|
||||
rights: host::__wasi_rights_t,
|
||||
old_path: &OsStr,
|
||||
new_path: &OsStr,
|
||||
) -> Result<(), host::__wasi_errno_t> {
|
||||
unimplemented!("path_symlink")
|
||||
}
|
||||
|
||||
pub(crate) fn path_unlink_file(
|
||||
wasi_ctx: &WasiCtx,
|
||||
dirfd: host::__wasi_fd_t,
|
||||
path: &OsStr,
|
||||
rights: host::__wasi_rights_t,
|
||||
) -> Result<(), host::__wasi_errno_t> {
|
||||
unimplemented!("path_unlink_file")
|
||||
}
|
||||
|
||||
pub(crate) fn path_remove_directory(
|
||||
wasi_ctx: &WasiCtx,
|
||||
dirfd: host::__wasi_fd_t,
|
||||
path: &OsStr,
|
||||
rights: host::__wasi_rights_t,
|
||||
) -> Result<(), host::__wasi_errno_t> {
|
||||
unimplemented!("path_remove_directory")
|
||||
}
|
||||
31
src/sys/windows/hostcalls_impl/misc.rs
Normal file
31
src/sys/windows/hostcalls_impl/misc.rs
Normal file
@@ -0,0 +1,31 @@
|
||||
#![allow(non_camel_case_types)]
|
||||
#![allow(unused_unsafe)]
|
||||
#![allow(unused)]
|
||||
use super::host_impl;
|
||||
use crate::memory::*;
|
||||
use crate::{host, wasm32};
|
||||
|
||||
use wasi_common_cbindgen::wasi_common_cbindgen;
|
||||
|
||||
pub(crate) fn clock_res_get(
|
||||
clock_id: host::__wasi_clockid_t,
|
||||
) -> Result<host::__wasi_timestamp_t, host::__wasi_errno_t> {
|
||||
unimplemented!("clock_res_get")
|
||||
}
|
||||
|
||||
pub(crate) fn clock_time_get(
|
||||
clock_id: host::__wasi_clockid_t,
|
||||
) -> Result<host::__wasi_timestamp_t, host::__wasi_errno_t> {
|
||||
unimplemented!("clock_time_get")
|
||||
}
|
||||
|
||||
pub(crate) fn poll_oneoff(
|
||||
input: Vec<Result<host::__wasi_subscription_t, host::__wasi_errno_t>>,
|
||||
output_slice: &mut [wasm32::__wasi_event_t],
|
||||
) -> Result<wasm32::size_t, host::__wasi_errno_t> {
|
||||
unimplemented!("poll_oneoff")
|
||||
}
|
||||
|
||||
pub(crate) fn sched_yield() -> Result<(), host::__wasi_errno_t> {
|
||||
unimplemented!("sched_yield")
|
||||
}
|
||||
@@ -2,10 +2,9 @@
|
||||
//! [WASI](https://github.com/CraneStation/wasmtime-wasi/blob/wasi/docs/WASI-overview.md).
|
||||
mod fs;
|
||||
mod misc;
|
||||
mod sock;
|
||||
|
||||
use super::fdentry;
|
||||
use super::host_impl;
|
||||
|
||||
pub use self::fs::*;
|
||||
pub use self::misc::*;
|
||||
pub use self::sock::*;
|
||||
pub(crate) use self::fs::*;
|
||||
pub(crate) use self::misc::*;
|
||||
@@ -1,12 +1,12 @@
|
||||
pub mod fdentry;
|
||||
mod host_impl;
|
||||
pub mod hostcalls;
|
||||
pub(crate) mod fdentry;
|
||||
pub(crate) mod host_impl;
|
||||
pub(crate) mod hostcalls_impl;
|
||||
|
||||
use std::fs::File;
|
||||
use std::io;
|
||||
use std::path::Path;
|
||||
|
||||
pub fn dev_null() -> File {
|
||||
pub(crate) fn dev_null() -> File {
|
||||
File::open("NUL").expect("failed to open NUL")
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user