Add template for Windows impl

This commit is contained in:
Jakub Konka
2019-05-20 11:04:51 +02:00
committed by Dan Gohman
parent 7605584691
commit c3ff3cf075
20 changed files with 575 additions and 339 deletions

View File

@@ -1,9 +1,8 @@
use crate::host;
use std::fs::File;
use std::os::unix::prelude::{FileTypeExt, FromRawFd, IntoRawFd, RawFd, AsRawFd};
use std::os::unix::prelude::{AsRawFd, FileTypeExt, FromRawFd, IntoRawFd, RawFd};
use std::path::PathBuf;
use std::collections::HashMap;
#[derive(Clone, Debug)]
pub struct FdObject {
@@ -21,11 +20,6 @@ pub struct FdEntry {
pub preopen_path: Option<PathBuf>,
}
#[derive(Debug)]
pub struct FdMap {
entries: HashMap<host::__wasi_fd_t, FdEntry>,
}
impl Drop for FdObject {
fn drop(&mut self) {
if self.needs_close {
@@ -148,63 +142,3 @@ pub unsafe fn determine_type_rights(
};
Ok((ty, rights_base, rights_inheriting))
}
impl FdMap {
pub fn new() -> Self {
Self {
entries: HashMap::new()
}
}
pub(crate) fn insert_fd_entry_at(&mut self, fd: host::__wasi_fd_t, fe: FdEntry) {
self.entries.insert(fd, fe);
}
pub(crate) fn get(&self, fd: &host::__wasi_fd_t) -> Option<&FdEntry> {
self.entries.get(fd)
}
pub(crate) fn get_mut(&mut self, fd: &host::__wasi_fd_t) -> Option<&mut FdEntry> {
self.entries.get_mut(fd)
}
pub(crate) fn remove(&mut self, fd: &host::__wasi_fd_t) -> Option<FdEntry> {
self.entries.remove(fd)
}
pub fn get_fd_entry(
&self,
fd: host::__wasi_fd_t,
rights_base: host::__wasi_rights_t,
rights_inheriting: host::__wasi_rights_t,
) -> Result<&FdEntry, host::__wasi_errno_t> {
if let Some(fe) = self.entries.get(&fd) {
// validate rights
if !fe.rights_base & rights_base != 0 || !fe.rights_inheriting & rights_inheriting != 0
{
Err(host::__WASI_ENOTCAPABLE)
} else {
Ok(fe)
}
} else {
Err(host::__WASI_EBADF)
}
}
pub fn insert_fd_entry(
&mut self,
fe: FdEntry,
) -> Result<host::__wasi_fd_t, host::__wasi_errno_t> {
// never insert where stdio handles usually are
let mut fd = 3;
while self.entries.contains_key(&fd) {
if let Some(next_fd) = fd.checked_add(1) {
fd = next_fd;
} else {
return Err(host::__WASI_EMFILE);
}
}
self.entries.insert(fd, fe);
Ok(fd)
}
}

View File

@@ -3,26 +3,28 @@
#![allow(non_snake_case)]
#![allow(dead_code)]
use crate::host;
use crate::memory;
use crate::wasm32;
pub fn errno_from_nix(errno: nix::errno::Errno) -> host::__wasi_errno_t {
match errno {
nix::errno::Errno::EPERM => host::__WASI_EPERM,
nix::errno::Errno::EPERM => host::__WASI_EPERM,
nix::errno::Errno::ENOENT => host::__WASI_ENOENT,
nix::errno::Errno::ESRCH => host::__WASI_ESRCH,
nix::errno::Errno::EINTR => host::__WASI_EINTR,
nix::errno::Errno::EIO => host::__WASI_EIO,
nix::errno::Errno::ENXIO => host::__WASI_ENXIO,
nix::errno::Errno::E2BIG => host::__WASI_E2BIG,
nix::errno::Errno::ESRCH => host::__WASI_ESRCH,
nix::errno::Errno::EINTR => host::__WASI_EINTR,
nix::errno::Errno::EIO => host::__WASI_EIO,
nix::errno::Errno::ENXIO => host::__WASI_ENXIO,
nix::errno::Errno::E2BIG => host::__WASI_E2BIG,
nix::errno::Errno::ENOEXEC => host::__WASI_ENOEXEC,
nix::errno::Errno::EBADF => host::__WASI_EBADF,
nix::errno::Errno::EBADF => host::__WASI_EBADF,
nix::errno::Errno::ECHILD => host::__WASI_ECHILD,
nix::errno::Errno::EAGAIN => host::__WASI_EAGAIN,
nix::errno::Errno::ENOMEM => host::__WASI_ENOMEM,
nix::errno::Errno::EACCES => host::__WASI_EACCES,
nix::errno::Errno::EFAULT => host::__WASI_EFAULT,
nix::errno::Errno::EBUSY => host::__WASI_EBUSY,
nix::errno::Errno::EBUSY => host::__WASI_EBUSY,
nix::errno::Errno::EEXIST => host::__WASI_EEXIST,
nix::errno::Errno::EXDEV => host::__WASI_EXDEV,
nix::errno::Errno::EXDEV => host::__WASI_EXDEV,
nix::errno::Errno::ENODEV => host::__WASI_ENODEV,
nix::errno::Errno::ENOTDIR => host::__WASI_ENOTDIR,
nix::errno::Errno::EISDIR => host::__WASI_EISDIR,
@@ -31,60 +33,62 @@ pub fn errno_from_nix(errno: nix::errno::Errno) -> host::__wasi_errno_t {
nix::errno::Errno::EMFILE => host::__WASI_EMFILE,
nix::errno::Errno::ENOTTY => host::__WASI_ENOTTY,
nix::errno::Errno::ETXTBSY => host::__WASI_ETXTBSY,
nix::errno::Errno::EFBIG => host::__WASI_EFBIG,
nix::errno::Errno::EFBIG => host::__WASI_EFBIG,
nix::errno::Errno::ENOSPC => host::__WASI_ENOSPC,
nix::errno::Errno::ESPIPE => host::__WASI_ESPIPE,
nix::errno::Errno::EROFS => host::__WASI_EROFS,
nix::errno::Errno::EROFS => host::__WASI_EROFS,
nix::errno::Errno::EMLINK => host::__WASI_EMLINK,
nix::errno::Errno::EPIPE => host::__WASI_EPIPE,
nix::errno::Errno::EDOM => host::__WASI_EDOM,
nix::errno::Errno::EPIPE => host::__WASI_EPIPE,
nix::errno::Errno::EDOM => host::__WASI_EDOM,
nix::errno::Errno::ERANGE => host::__WASI_ERANGE,
nix::errno::Errno::EDEADLK => host::__WASI_EDEADLK,
nix::errno::Errno::EDEADLK => host::__WASI_EDEADLK,
nix::errno::Errno::ENAMETOOLONG => host::__WASI_ENAMETOOLONG,
nix::errno::Errno::ENOLCK => host::__WASI_ENOLCK,
nix::errno::Errno::ENOSYS => host::__WASI_ENOSYS,
nix::errno::Errno::ENOTEMPTY => host::__WASI_ENOTEMPTY,
nix::errno::Errno::ELOOP => host::__WASI_ELOOP,
nix::errno::Errno::ENOMSG => host::__WASI_ENOMSG,
nix::errno::Errno::EIDRM => host::__WASI_EIDRM,
nix::errno::Errno::ENOLINK => host::__WASI_ENOLINK,
nix::errno::Errno::EPROTO => host::__WASI_EPROTO,
nix::errno::Errno::EMULTIHOP => host::__WASI_EMULTIHOP,
nix::errno::Errno::EBADMSG => host::__WASI_EBADMSG,
nix::errno::Errno::EOVERFLOW => host::__WASI_EOVERFLOW,
nix::errno::Errno::EILSEQ => host::__WASI_EILSEQ,
nix::errno::Errno::ENOTSOCK => host::__WASI_ENOTSOCK,
nix::errno::Errno::ENOLCK => host::__WASI_ENOLCK,
nix::errno::Errno::ENOSYS => host::__WASI_ENOSYS,
nix::errno::Errno::ENOTEMPTY => host::__WASI_ENOTEMPTY,
nix::errno::Errno::ELOOP => host::__WASI_ELOOP,
nix::errno::Errno::ENOMSG => host::__WASI_ENOMSG,
nix::errno::Errno::EIDRM => host::__WASI_EIDRM,
nix::errno::Errno::ENOLINK => host::__WASI_ENOLINK,
nix::errno::Errno::EPROTO => host::__WASI_EPROTO,
nix::errno::Errno::EMULTIHOP => host::__WASI_EMULTIHOP,
nix::errno::Errno::EBADMSG => host::__WASI_EBADMSG,
nix::errno::Errno::EOVERFLOW => host::__WASI_EOVERFLOW,
nix::errno::Errno::EILSEQ => host::__WASI_EILSEQ,
nix::errno::Errno::ENOTSOCK => host::__WASI_ENOTSOCK,
nix::errno::Errno::EDESTADDRREQ => host::__WASI_EDESTADDRREQ,
nix::errno::Errno::EMSGSIZE => host::__WASI_EMSGSIZE,
nix::errno::Errno::EPROTOTYPE => host::__WASI_EPROTOTYPE,
nix::errno::Errno::ENOPROTOOPT => host::__WASI_ENOPROTOOPT,
nix::errno::Errno::EMSGSIZE => host::__WASI_EMSGSIZE,
nix::errno::Errno::EPROTOTYPE => host::__WASI_EPROTOTYPE,
nix::errno::Errno::ENOPROTOOPT => host::__WASI_ENOPROTOOPT,
nix::errno::Errno::EPROTONOSUPPORT => host::__WASI_EPROTONOSUPPORT,
nix::errno::Errno::EAFNOSUPPORT => host::__WASI_EAFNOSUPPORT,
nix::errno::Errno::EADDRINUSE => host::__WASI_EADDRINUSE,
nix::errno::Errno::EAFNOSUPPORT => host::__WASI_EAFNOSUPPORT,
nix::errno::Errno::EADDRINUSE => host::__WASI_EADDRINUSE,
nix::errno::Errno::EADDRNOTAVAIL => host::__WASI_EADDRNOTAVAIL,
nix::errno::Errno::ENETDOWN => host::__WASI_ENETDOWN,
nix::errno::Errno::ENETUNREACH => host::__WASI_ENETUNREACH,
nix::errno::Errno::ENETRESET => host::__WASI_ENETRESET,
nix::errno::Errno::ECONNABORTED => host::__WASI_ECONNABORTED,
nix::errno::Errno::ECONNRESET => host::__WASI_ECONNRESET,
nix::errno::Errno::ENOBUFS => host::__WASI_ENOBUFS,
nix::errno::Errno::EISCONN => host::__WASI_EISCONN,
nix::errno::Errno::ENOTCONN => host::__WASI_ENOTCONN,
nix::errno::Errno::ETIMEDOUT => host::__WASI_ETIMEDOUT,
nix::errno::Errno::ECONNREFUSED => host::__WASI_ECONNREFUSED,
nix::errno::Errno::EHOSTUNREACH => host::__WASI_EHOSTUNREACH,
nix::errno::Errno::EALREADY => host::__WASI_EALREADY,
nix::errno::Errno::EINPROGRESS => host::__WASI_EINPROGRESS,
nix::errno::Errno::ESTALE => host::__WASI_ESTALE,
nix::errno::Errno::EDQUOT => host::__WASI_EDQUOT,
nix::errno::Errno::ECANCELED => host::__WASI_ECANCELED,
nix::errno::Errno::EOWNERDEAD => host::__WASI_EOWNERDEAD,
nix::errno::Errno::ENETDOWN => host::__WASI_ENETDOWN,
nix::errno::Errno::ENETUNREACH => host::__WASI_ENETUNREACH,
nix::errno::Errno::ENETRESET => host::__WASI_ENETRESET,
nix::errno::Errno::ECONNABORTED => host::__WASI_ECONNABORTED,
nix::errno::Errno::ECONNRESET => host::__WASI_ECONNRESET,
nix::errno::Errno::ENOBUFS => host::__WASI_ENOBUFS,
nix::errno::Errno::EISCONN => host::__WASI_EISCONN,
nix::errno::Errno::ENOTCONN => host::__WASI_ENOTCONN,
nix::errno::Errno::ETIMEDOUT => host::__WASI_ETIMEDOUT,
nix::errno::Errno::ECONNREFUSED => host::__WASI_ECONNREFUSED,
nix::errno::Errno::EHOSTUNREACH => host::__WASI_EHOSTUNREACH,
nix::errno::Errno::EALREADY => host::__WASI_EALREADY,
nix::errno::Errno::EINPROGRESS => host::__WASI_EINPROGRESS,
nix::errno::Errno::ESTALE => host::__WASI_ESTALE,
nix::errno::Errno::EDQUOT => host::__WASI_EDQUOT,
nix::errno::Errno::ECANCELED => host::__WASI_ECANCELED,
nix::errno::Errno::EOWNERDEAD => host::__WASI_EOWNERDEAD,
nix::errno::Errno::ENOTRECOVERABLE => host::__WASI_ENOTRECOVERABLE,
_ => host::__WASI_ENOSYS,
}
}
pub unsafe fn ciovec_to_nix<'a>(ciovec: &'a host::__wasi_ciovec_t) -> nix::sys::uio::IoVec<&'a [u8]> {
pub unsafe fn ciovec_to_nix<'a>(
ciovec: &'a host::__wasi_ciovec_t,
) -> nix::sys::uio::IoVec<&'a [u8]> {
let slice = std::slice::from_raw_parts(ciovec.buf as *const u8, ciovec.buf_len);
nix::sys::uio::IoVec::from_slice(slice)
}
@@ -231,10 +235,40 @@ pub fn filestat_from_nix(filestat: nix::sys::stat::FileStat) -> host::__wasi_fil
st_dev: dev,
st_ino: ino,
st_nlink: filestat.st_nlink as host::__wasi_linkcount_t,
st_size: filestat.st_size as host::__wasi_filesize_t,
st_size: filestat.st_size as host::__wasi_filesize_t,
st_atim: filestat.st_atime as host::__wasi_timestamp_t,
st_ctim: filestat.st_ctime as host::__wasi_timestamp_t,
st_mtim: filestat.st_mtime as host::__wasi_timestamp_t,
st_filetype: filetype_from_nix(filetype),
}
}
#[cfg(target_os = "linux")]
pub fn dirent_from_host(
host_entry: &nix::libc::dirent,
) -> Result<wasm32::__wasi_dirent_t, host::__wasi_errno_t> {
let mut entry = unsafe { std::mem::zeroed::<wasm32::__wasi_dirent_t>() };
let d_namlen = unsafe { std::ffi::CStr::from_ptr(host_entry.d_name.as_ptr()) }
.to_bytes()
.len();
if d_namlen > u32::max_value() as usize {
return Err(host::__WASI_EIO);
}
entry.d_ino = memory::enc_inode(host_entry.d_ino);
entry.d_next = memory::enc_dircookie(host_entry.d_off as u64);
entry.d_namlen = memory::enc_u32(d_namlen as u32);
entry.d_type = memory::enc_filetype(host_entry.d_type);
Ok(entry)
}
#[cfg(not(target_os = "linux"))]
pub fn dirent_from_host(
host_entry: &nix::libc::dirent,
) -> Result<wasm32::__wasi_dirent_t, host::__wasi_errno_t> {
let mut entry = unsafe { std::mem::zeroed::<wasm32::__wasi_dirent_t>() };
entry.d_ino = memory::enc_inode(host_entry.d_ino);
entry.d_next = memory::enc_dircookie(host_entry.d_seekoff);
entry.d_namlen = memory::enc_u32(u32::from(host_entry.d_namlen));
entry.d_type = memory::enc_filetype(host_entry.d_type);
Ok(entry)
}

View File

@@ -1,18 +1,19 @@
#![allow(non_camel_case_types)]
#![allow(unused_unsafe)]
use crate::sys::fdmap::{determine_type_rights, FdEntry};
use crate::sys::host as host_impl;
use super::fdentry::{determine_type_rights, FdEntry};
use super::fs_helpers::*;
use super::host_impl;
use crate::ctx::WasiCtx;
use crate::memory::*;
use crate::{host, wasm32};
use super::fs_helpers::*;
use nix::libc::{self, c_long, c_void, off_t};
use std::ffi::OsStr;
use std::os::unix::prelude::{FromRawFd, 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 {
let fd = dec_fd(fd);
if let Some(fdent) = wasi_ctx.fds.get(&fd) {
@@ -32,6 +33,7 @@ pub fn fd_close(wasi_ctx: &mut WasiCtx, fd: wasm32::__wasi_fd_t) -> wasm32::__wa
}
}
#[wasi_common_cbindgen]
pub fn fd_datasync(wasi_ctx: &WasiCtx, fd: wasm32::__wasi_fd_t) -> wasm32::__wasi_errno_t {
let host_fd = dec_fd(fd);
let rights = host::__WASI_RIGHT_FD_DATASYNC;
@@ -57,6 +59,7 @@ pub fn fd_datasync(wasi_ctx: &WasiCtx, fd: wasm32::__wasi_fd_t) -> wasm32::__was
wasm32::__WASI_ESUCCESS
}
#[wasi_common_cbindgen]
pub fn fd_pread(
wasi_ctx: &WasiCtx,
memory: &mut [u8],
@@ -106,6 +109,7 @@ pub fn fd_pread(
.unwrap_or_else(|e| e)
}
#[wasi_common_cbindgen]
pub fn fd_pwrite(
wasi_ctx: &WasiCtx,
memory: &mut [u8],
@@ -147,6 +151,7 @@ pub fn fd_pwrite(
.unwrap_or_else(|e| e)
}
#[wasi_common_cbindgen]
pub fn fd_read(
wasi_ctx: &mut WasiCtx,
memory: &mut [u8],
@@ -189,6 +194,7 @@ pub fn fd_read(
.unwrap_or_else(|e| e)
}
#[wasi_common_cbindgen]
pub fn fd_renumber(
wasi_ctx: &mut WasiCtx,
from: wasm32::__wasi_fd_t,
@@ -213,6 +219,7 @@ pub fn fd_renumber(
wasm32::__WASI_ESUCCESS
}
#[wasi_common_cbindgen]
pub fn fd_seek(
wasi_ctx: &WasiCtx,
memory: &mut [u8],
@@ -253,6 +260,7 @@ pub fn fd_seek(
.unwrap_or_else(|e| e)
}
#[wasi_common_cbindgen]
pub fn fd_tell(
wasi_ctx: &WasiCtx,
memory: &mut [u8],
@@ -279,6 +287,7 @@ pub fn fd_tell(
.unwrap_or_else(|e| e)
}
#[wasi_common_cbindgen]
pub fn fd_fdstat_get(
wasi_ctx: &WasiCtx,
memory: &mut [u8],
@@ -313,6 +322,7 @@ pub fn fd_fdstat_get(
errno
}
#[wasi_common_cbindgen]
pub fn fd_fdstat_set_flags(
wasi_ctx: &WasiCtx,
fd: wasm32::__wasi_fd_t,
@@ -332,6 +342,7 @@ pub fn fd_fdstat_set_flags(
}
}
#[wasi_common_cbindgen]
pub fn fd_fdstat_set_rights(
wasi_ctx: &mut WasiCtx,
fd: wasm32::__wasi_fd_t,
@@ -354,6 +365,7 @@ pub fn fd_fdstat_set_rights(
wasm32::__WASI_ESUCCESS
}
#[wasi_common_cbindgen]
pub fn fd_sync(wasi_ctx: &WasiCtx, fd: wasm32::__wasi_fd_t) -> wasm32::__wasi_errno_t {
let host_fd = dec_fd(fd);
let rights = host::__WASI_RIGHT_FD_SYNC;
@@ -368,6 +380,7 @@ pub fn fd_sync(wasi_ctx: &WasiCtx, fd: wasm32::__wasi_fd_t) -> wasm32::__wasi_er
wasm32::__WASI_ESUCCESS
}
#[wasi_common_cbindgen]
pub fn fd_write(
wasi_ctx: &WasiCtx,
memory: &mut [u8],
@@ -404,6 +417,7 @@ pub fn fd_write(
.unwrap_or_else(|e| e)
}
#[wasi_common_cbindgen]
pub fn fd_advise(
wasi_ctx: &WasiCtx,
fd: wasm32::__wasi_fd_t,
@@ -462,6 +476,7 @@ pub fn fd_advise(
wasm32::__WASI_ESUCCESS
}
#[wasi_common_cbindgen]
pub fn fd_allocate(
wasi_ctx: &WasiCtx,
fd: wasm32::__wasi_fd_t,
@@ -514,6 +529,7 @@ pub fn fd_allocate(
wasm32::__WASI_ESUCCESS
}
#[wasi_common_cbindgen]
pub fn path_create_directory(
wasi_ctx: &WasiCtx,
memory: &mut [u8],
@@ -552,6 +568,7 @@ pub fn path_create_directory(
}
}
#[wasi_common_cbindgen]
pub fn path_link(
wasi_ctx: &WasiCtx,
memory: &mut [u8],
@@ -613,6 +630,7 @@ pub fn path_link(
wasm32::__WASI_ESUCCESS
}
#[wasi_common_cbindgen]
pub fn path_open(
wasi_ctx: &mut WasiCtx,
memory: &mut [u8],
@@ -770,6 +788,7 @@ pub fn path_open(
.unwrap_or_else(|e| e)
}
#[wasi_common_cbindgen]
pub fn fd_readdir(
wasi_ctx: &WasiCtx,
memory: &mut [u8],
@@ -817,10 +836,11 @@ pub fn fd_readdir(
if host_entry.is_null() {
break;
}
let entry: wasm32::__wasi_dirent_t = match dirent_from_host(&unsafe { *host_entry }) {
Ok(entry) => entry,
Err(e) => return enc_errno(e),
};
let entry: wasm32::__wasi_dirent_t =
match host_impl::dirent_from_host(&unsafe { *host_entry }) {
Ok(entry) => entry,
Err(e) => return enc_errno(e),
};
let name_len = entry.d_namlen as usize;
let required_space = std::mem::size_of_val(&entry) + name_len;
if required_space > left {
@@ -849,6 +869,7 @@ pub fn fd_readdir(
.unwrap_or_else(|e| e)
}
#[wasi_common_cbindgen]
pub fn path_readlink(
wasi_ctx: &WasiCtx,
memory: &mut [u8],
@@ -892,6 +913,7 @@ pub fn path_readlink(
wasm32::__WASI_ESUCCESS
}
#[wasi_common_cbindgen]
pub fn path_rename(
wasi_ctx: &WasiCtx,
memory: &mut [u8],
@@ -948,6 +970,7 @@ pub fn path_rename(
wasm32::__WASI_ESUCCESS
}
#[wasi_common_cbindgen]
pub fn fd_filestat_get(
wasi_ctx: &WasiCtx,
memory: &mut [u8],
@@ -974,6 +997,7 @@ pub fn fd_filestat_get(
errno
}
#[wasi_common_cbindgen]
pub fn fd_filestat_set_times(
wasi_ctx: &WasiCtx,
fd: wasm32::__wasi_fd_t,
@@ -1030,6 +1054,7 @@ pub fn fd_filestat_set_times(
wasm32::__WASI_ESUCCESS
}
#[wasi_common_cbindgen]
pub fn fd_filestat_set_size(
wasi_ctx: &WasiCtx,
fd: wasm32::__wasi_fd_t,
@@ -1053,6 +1078,7 @@ pub fn fd_filestat_set_size(
wasm32::__WASI_ESUCCESS
}
#[wasi_common_cbindgen]
pub fn path_filestat_get(
wasi_ctx: &WasiCtx,
memory: &mut [u8],
@@ -1098,6 +1124,7 @@ pub fn path_filestat_get(
}
}
#[wasi_common_cbindgen]
pub fn path_filestat_set_times(
wasi_ctx: &WasiCtx,
memory: &mut [u8],
@@ -1171,6 +1198,7 @@ pub fn path_filestat_set_times(
wasm32::__WASI_ESUCCESS
}
#[wasi_common_cbindgen]
pub fn path_symlink(
wasi_ctx: &WasiCtx,
memory: &mut [u8],
@@ -1211,6 +1239,7 @@ pub fn path_symlink(
wasm32::__WASI_ESUCCESS
}
#[wasi_common_cbindgen]
pub fn path_unlink_file(
wasi_ctx: &WasiCtx,
memory: &mut [u8],
@@ -1249,6 +1278,7 @@ pub fn path_unlink_file(
}
}
#[wasi_common_cbindgen]
pub fn path_remove_directory(
wasi_ctx: &WasiCtx,
memory: &mut [u8],
@@ -1280,6 +1310,7 @@ pub fn path_remove_directory(
}
}
#[wasi_common_cbindgen]
pub fn fd_prestat_get(
wasi_ctx: &WasiCtx,
memory: &mut [u8],
@@ -1316,6 +1347,7 @@ pub fn fd_prestat_get(
}
}
#[wasi_common_cbindgen]
pub fn fd_prestat_dir_name(
wasi_ctx: &WasiCtx,
memory: &mut [u8],

View File

@@ -1,9 +1,9 @@
#![allow(non_camel_case_types)]
#![allow(unused_unsafe)]
use super::host_impl;
use crate::ctx::WasiCtx;
use crate::host;
use crate::sys::host as host_impl;
use nix::libc::{self, c_long};
use std::ffi::{OsStr, OsString};

View File

@@ -1,15 +1,17 @@
#![allow(non_camel_case_types)]
#![allow(unused_unsafe)]
use super::host_impl;
use crate::memory::*;
use crate::{host, wasm32};
use crate::sys::host as host_impl;
use nix::convert_ioctl_res;
use nix::libc::{self, c_int};
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,
@@ -49,6 +51,7 @@ pub fn clock_res_get(
})
}
#[wasi_common_cbindgen]
pub fn clock_time_get(
memory: &mut [u8],
clock_id: wasm32::__wasi_clockid_t,
@@ -85,6 +88,7 @@ pub fn clock_time_get(
})
}
#[wasi_common_cbindgen]
pub fn poll_oneoff(
memory: &mut [u8],
input: wasm32::uintptr_t,
@@ -176,6 +180,7 @@ pub fn poll_oneoff(
wasm32::__WASI_ESUCCESS
}
#[wasi_common_cbindgen]
pub fn sched_yield() -> wasm32::__wasi_errno_t {
unsafe { libc::sched_yield() };
wasm32::__WASI_ESUCCESS

View File

@@ -1,10 +1,13 @@
//! Hostcalls that implement
//! Unix-specific hostcalls that implement
//! [WASI](https://github.com/CraneStation/wasmtime-wasi/blob/wasi/docs/WASI-overview.md).
mod fs;
mod fs_helpers;
mod misc;
mod sock;
use super::fdentry;
use super::host_impl;
pub use self::fs::*;
pub use self::misc::*;
pub use self::sock::*;

View File

@@ -6,6 +6,7 @@ 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],
@@ -19,6 +20,7 @@ pub fn sock_recv(
unimplemented!("sock_recv")
}
#[wasi_common_cbindgen]
pub fn sock_send(
wasi_ctx: &WasiCtx,
memory: &mut [u8],
@@ -31,6 +33,7 @@ pub fn sock_send(
unimplemented!("sock_send")
}
#[wasi_common_cbindgen]
pub fn sock_shutdown(
wasi_ctx: &WasiCtx,
memory: &mut [u8],
@@ -38,4 +41,4 @@ pub fn sock_shutdown(
how: wasm32::__wasi_sdflags_t,
) -> wasm32::__wasi_errno_t {
unimplemented!("sock_shutdown")
}
}

View File

@@ -1,41 +1,6 @@
pub mod host;
pub mod fdentry;
mod host_impl;
pub mod hostcalls;
pub mod fdmap;
pub mod memory {
use crate::{host, wasm32};
use crate::memory::*;
#[cfg(target_os = "linux")]
pub fn dirent_from_host(
host_entry: &nix::libc::dirent,
) -> Result<wasm32::__wasi_dirent_t, host::__wasi_errno_t> {
let mut entry = unsafe { std::mem::zeroed::<wasm32::__wasi_dirent_t>() };
let d_namlen = unsafe { std::ffi::CStr::from_ptr(host_entry.d_name.as_ptr()) }
.to_bytes()
.len();
if d_namlen > u32::max_value() as usize {
return Err(host::__WASI_EIO);
}
entry.d_ino = enc_inode(host_entry.d_ino);
entry.d_next = enc_dircookie(host_entry.d_off as u64);
entry.d_namlen = enc_u32(d_namlen as u32);
entry.d_type = enc_filetype(host_entry.d_type);
Ok(entry)
}
#[cfg(not(target_os = "linux"))]
pub fn dirent_from_host(
host_entry: &nix::libc::dirent,
) -> Result<wasm32::__wasi_dirent_t, host::__wasi_errno_t> {
let mut entry = unsafe { std::mem::zeroed::<wasm32::__wasi_dirent_t>() };
entry.d_ino = enc_inode(host_entry.d_ino);
entry.d_next = enc_dircookie(host_entry.d_seekoff);
entry.d_namlen = enc_u32(u32::from(host_entry.d_namlen));
entry.d_type = enc_filetype(host_entry.d_type);
Ok(entry)
}
}
pub fn dev_null() -> std::fs::File {
std::fs::File::open("/dev/null").expect("failed to open /dev/null")