Create helper Result<T> type

This commit is contained in:
Jakub Konka
2019-07-18 19:32:07 +02:00
committed by Dan Gohman
parent 08aa61f066
commit 310ecb5b5b
19 changed files with 173 additions and 255 deletions

View File

@@ -1,4 +1,4 @@
use super::host;
use crate::host;
use cfg_if::cfg_if;
cfg_if! {

View File

@@ -1,7 +1,6 @@
use crate::fdentry::Descriptor;
use crate::host;
use crate::sys::errno_from_host;
use crate::{host, Result};
use std::io;
use std::os::unix::prelude::{AsRawFd, FileTypeExt, FromRawFd, RawFd};
@@ -18,14 +17,11 @@ impl AsRawFd for Descriptor {
pub(crate) fn determine_type_and_access_rights<Fd: AsRawFd>(
fd: &Fd,
) -> Result<
(
host::__wasi_filetype_t,
host::__wasi_rights_t,
host::__wasi_rights_t,
),
host::__wasi_errno_t,
> {
) -> Result<(
host::__wasi_filetype_t,
host::__wasi_rights_t,
host::__wasi_rights_t,
)> {
let (file_type, mut rights_base, rights_inheriting) = determine_type_rights(fd)?;
use nix::fcntl::{fcntl, OFlag, F_GETFL};
@@ -46,14 +42,11 @@ pub(crate) fn determine_type_and_access_rights<Fd: AsRawFd>(
pub(crate) fn determine_type_rights<Fd: AsRawFd>(
fd: &Fd,
) -> Result<
(
host::__wasi_filetype_t,
host::__wasi_rights_t,
host::__wasi_rights_t,
),
host::__wasi_errno_t,
> {
) -> Result<(
host::__wasi_filetype_t,
host::__wasi_rights_t,
host::__wasi_rights_t,
)> {
let (file_type, rights_base, rights_inheriting) = {
// we just make a `File` here for convenience; we don't want it to close when it drops
let file =

View File

@@ -2,7 +2,7 @@
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]
#![allow(dead_code)]
use crate::{host, memory, wasm32};
use crate::{host, memory, wasm32, Result};
use std::ffi::OsStr;
use std::os::unix::prelude::OsStrExt;
@@ -196,9 +196,7 @@ pub fn nix_from_filetype(sflags: host::__wasi_filetype_t) -> nix::sys::stat::SFl
nix_sflags
}
pub fn filestat_from_nix(
filestat: nix::sys::stat::FileStat,
) -> Result<host::__wasi_filestat_t, host::__wasi_errno_t> {
pub fn filestat_from_nix(filestat: nix::sys::stat::FileStat) -> Result<host::__wasi_filestat_t> {
use std::convert::TryFrom;
let filetype = nix::sys::stat::SFlag::from_bits_truncate(filestat.st_mode);
@@ -220,9 +218,7 @@ pub fn filestat_from_nix(
}
#[cfg(target_os = "linux")]
pub fn dirent_from_host(
host_entry: &nix::libc::dirent,
) -> Result<wasm32::__wasi_dirent_t, host::__wasi_errno_t> {
pub fn dirent_from_host(host_entry: &nix::libc::dirent) -> Result<wasm32::__wasi_dirent_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()
@@ -238,9 +234,7 @@ pub fn dirent_from_host(
}
#[cfg(not(target_os = "linux"))]
pub fn dirent_from_host(
host_entry: &nix::libc::dirent,
) -> Result<wasm32::__wasi_dirent_t, host::__wasi_errno_t> {
pub fn dirent_from_host(host_entry: &nix::libc::dirent) -> Result<wasm32::__wasi_dirent_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);
@@ -253,6 +247,6 @@ pub fn dirent_from_host(
///
/// NB WASI spec requires OS string to be valid UTF-8. Otherwise,
/// `__WASI_EILSEQ` error is returned.
pub fn path_from_host<S: AsRef<OsStr>>(s: S) -> Result<String, host::__wasi_errno_t> {
pub fn path_from_host<S: AsRef<OsStr>>(s: S) -> Result<String> {
host::path_from_slice(s.as_ref().as_bytes()).map(String::from)
}

View File

@@ -6,7 +6,7 @@ use crate::fdentry::FdEntry;
use crate::sys::errno_from_host;
use crate::sys::fdentry_impl::determine_type_rights;
use crate::sys::host_impl;
use crate::{host, wasm32};
use crate::{host, wasm32, Result};
use nix::libc::{self, c_long, c_void, off_t};
use std::ffi::CString;
use std::fs::File;
@@ -17,16 +17,12 @@ pub(crate) fn fd_pread(
file: &File,
buf: &mut [u8],
offset: host::__wasi_filesize_t,
) -> Result<usize, host::__wasi_errno_t> {
) -> Result<usize> {
file.read_at(buf, offset)
.map_err(|e| e.raw_os_error().map_or(host::__WASI_EIO, errno_from_host))
}
pub(crate) fn fd_pwrite(
file: &File,
buf: &[u8],
offset: host::__wasi_filesize_t,
) -> Result<usize, host::__wasi_errno_t> {
pub(crate) fn fd_pwrite(file: &File, buf: &[u8], offset: host::__wasi_filesize_t) -> Result<usize> {
file.write_at(buf, offset)
.map_err(|e| e.raw_os_error().map_or(host::__WASI_EIO, errno_from_host))
}
@@ -35,7 +31,7 @@ pub(crate) fn fd_renumber(
wasi_ctx: &mut WasiCtx,
from: host::__wasi_fd_t,
to: host::__wasi_fd_t,
) -> Result<(), host::__wasi_errno_t> {
) -> Result<()> {
let fe_from = match wasi_ctx.fds.get(&from) {
Some(fe_from) => fe_from,
None => return Err(host::__WASI_EBADF),
@@ -68,7 +64,7 @@ pub(crate) fn fd_seek(
fd_entry: &FdEntry,
offset: host::__wasi_filedelta_t,
whence: host::__wasi_whence_t,
) -> Result<u64, host::__wasi_errno_t> {
) -> Result<u64> {
use nix::unistd::{lseek, Whence};
let nwhence = match whence {
host::__WASI_WHENCE_CUR => Whence::SeekCur,
@@ -85,7 +81,7 @@ pub(crate) fn fd_seek(
}
}
pub(crate) fn fd_tell(fd_entry: &FdEntry) -> Result<u64, host::__wasi_errno_t> {
pub(crate) fn fd_tell(fd_entry: &FdEntry) -> Result<u64> {
use nix::unistd::{lseek, Whence};
let rawfd = fd_entry.fd_object.descriptor.as_raw_fd();
@@ -95,9 +91,7 @@ pub(crate) fn fd_tell(fd_entry: &FdEntry) -> Result<u64, host::__wasi_errno_t> {
}
}
pub(crate) fn fd_fdstat_get(
fd_entry: &FdEntry,
) -> Result<host::__wasi_fdflags_t, host::__wasi_errno_t> {
pub(crate) fn fd_fdstat_get(fd_entry: &FdEntry) -> Result<host::__wasi_fdflags_t> {
use nix::fcntl::{fcntl, OFlag, F_GETFL};
let rawfd = fd_entry.fd_object.descriptor.as_raw_fd();
@@ -110,7 +104,7 @@ pub(crate) fn fd_fdstat_get(
pub(crate) fn fd_fdstat_set_flags(
fd_entry: &FdEntry,
fdflags: host::__wasi_fdflags_t,
) -> Result<(), host::__wasi_errno_t> {
) -> Result<()> {
let rawfd = fd_entry.fd_object.descriptor.as_raw_fd();
let nix_flags = host_impl::nix_from_fdflags(fdflags);
match nix::fcntl::fcntl(rawfd, nix::fcntl::F_SETFL(nix_flags)) {
@@ -124,7 +118,7 @@ pub(crate) fn fd_advise(
advice: host::__wasi_advice_t,
offset: host::__wasi_filesize_t,
len: host::__wasi_filesize_t,
) -> Result<(), host::__wasi_errno_t> {
) -> Result<()> {
#[cfg(target_os = "linux")]
{
let host_advice = match advice {
@@ -164,7 +158,7 @@ pub(crate) fn path_create_directory(
ctx: &WasiCtx,
dirfd: host::__wasi_fd_t,
path: &str,
) -> Result<(), host::__wasi_errno_t> {
) -> Result<()> {
use nix::libc::mkdirat;
let (dir, path) = match path_get(
@@ -196,7 +190,7 @@ pub(crate) fn path_link(
new_path: &str,
source_rights: host::__wasi_rights_t,
target_rights: host::__wasi_rights_t,
) -> Result<(), host::__wasi_errno_t> {
) -> Result<()> {
use nix::libc::linkat;
let (old_dir, old_path) = match path_get(ctx, old_dirfd, 0, old_path, source_rights, 0, false) {
Ok((dir, path)) => (dir, path),
@@ -238,7 +232,7 @@ pub(crate) fn path_open(
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> {
) -> Result<FdEntry> {
use nix::errno::Errno;
use nix::fcntl::{openat, AtFlags, OFlag};
use nix::sys::stat::{fstatat, Mode, SFlag};
@@ -354,7 +348,7 @@ pub(crate) fn fd_readdir(
fd_entry: &FdEntry,
host_buf: &mut [u8],
cookie: host::__wasi_dircookie_t,
) -> Result<usize, host::__wasi_errno_t> {
) -> Result<usize> {
use libc::{dirent, fdopendir, memcpy, readdir_r, seekdir};
let rawfd = fd_entry.fd_object.descriptor.as_raw_fd();
@@ -415,7 +409,7 @@ pub(crate) fn path_readlink(
path: &str,
rights: host::__wasi_rights_t,
buf: &mut [u8],
) -> Result<usize, host::__wasi_errno_t> {
) -> Result<usize> {
use nix::errno::Errno;
let (dir, path) = match path_get(wasi_ctx, dirfd, 0, path, rights, 0, false) {
@@ -459,7 +453,7 @@ pub(crate) fn path_rename(
new_dirfd: host::__wasi_fd_t,
new_path: &str,
new_rights: host::__wasi_rights_t,
) -> Result<(), host::__wasi_errno_t> {
) -> Result<()> {
use nix::libc::renameat;
let (old_dir, old_path) = match path_get(wasi_ctx, old_dirfd, 0, old_path, old_rights, 0, false)
@@ -490,9 +484,7 @@ pub(crate) fn path_rename(
}
}
pub(crate) fn fd_filestat_get(
fd_entry: &FdEntry,
) -> Result<host::__wasi_filestat_t, host::__wasi_errno_t> {
pub(crate) fn fd_filestat_get(fd_entry: &FdEntry) -> Result<host::__wasi_filestat_t> {
use nix::sys::stat::fstat;
let rawfd = fd_entry.fd_object.descriptor.as_raw_fd();
@@ -507,7 +499,7 @@ pub(crate) fn fd_filestat_set_times(
st_atim: host::__wasi_timestamp_t,
mut st_mtim: host::__wasi_timestamp_t,
fst_flags: host::__wasi_fstflags_t,
) -> Result<(), host::__wasi_errno_t> {
) -> Result<()> {
use nix::sys::time::{TimeSpec, TimeValLike};
if fst_flags & host::__WASI_FILESTAT_SET_MTIM_NOW != 0 {
@@ -553,7 +545,7 @@ pub(crate) fn 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> {
) -> Result<()> {
use nix::unistd::ftruncate;
let rawfd = fd_entry.fd_object.descriptor.as_raw_fd();
@@ -565,7 +557,7 @@ pub(crate) fn path_filestat_get(
dirfd: host::__wasi_fd_t,
dirflags: host::__wasi_lookupflags_t,
path: &str,
) -> Result<host::__wasi_filestat_t, host::__wasi_errno_t> {
) -> Result<host::__wasi_filestat_t> {
use nix::fcntl::AtFlags;
use nix::sys::stat::fstatat;
@@ -601,7 +593,7 @@ pub(crate) fn path_filestat_set_times(
st_atim: host::__wasi_timestamp_t,
mut st_mtim: host::__wasi_timestamp_t,
fst_flags: host::__wasi_fstflags_t,
) -> Result<(), host::__wasi_errno_t> {
) -> Result<()> {
use nix::sys::time::{TimeSpec, TimeValLike};
let (dir, path) = match path_get(wasi_ctx, dirfd, dirflags, &path, rights, 0, false) {
@@ -661,7 +653,7 @@ pub(crate) fn path_symlink(
rights: host::__wasi_rights_t,
old_path: &str,
new_path: &str,
) -> Result<(), host::__wasi_errno_t> {
) -> Result<()> {
use nix::libc::symlinkat;
let (dir, new_path) = match path_get(wasi_ctx, dirfd, 0, new_path, rights, 0, false) {
@@ -690,7 +682,7 @@ pub(crate) fn path_unlink_file(
dirfd: host::__wasi_fd_t,
path: &str,
rights: host::__wasi_rights_t,
) -> Result<(), host::__wasi_errno_t> {
) -> Result<()> {
use nix::errno;
use nix::libc::unlinkat;
@@ -741,7 +733,7 @@ pub(crate) fn path_remove_directory(
dirfd: host::__wasi_fd_t,
path: &str,
rights: host::__wasi_rights_t,
) -> Result<(), host::__wasi_errno_t> {
) -> Result<()> {
use nix::errno;
use nix::libc::{unlinkat, AT_REMOVEDIR};

View File

@@ -3,9 +3,9 @@
use crate::ctx::WasiCtx;
use crate::fdentry::Descriptor;
use crate::host;
use crate::sys::errno_from_host;
use crate::sys::host_impl;
use crate::{host, Result};
use nix::libc::{self, c_long};
use std::fs::File;
use std::path::{Component, Path};
@@ -21,7 +21,7 @@ pub(crate) fn path_get(
needed_base: host::__wasi_rights_t,
needed_inheriting: host::__wasi_rights_t,
needs_final_component: bool,
) -> Result<(File, String), host::__wasi_errno_t> {
) -> Result<(File, String)> {
const MAX_SYMLINK_EXPANSIONS: usize = 128;
if path.contains("\0") {
@@ -186,7 +186,7 @@ pub(crate) fn path_get(
}
}
fn openat(dirfd: &File, path: &str) -> Result<File, host::__wasi_errno_t> {
fn openat(dirfd: &File, path: &str) -> Result<File> {
use nix::fcntl::{self, OFlag};
use nix::sys::stat::Mode;
use std::os::unix::prelude::{AsRawFd, FromRawFd};
@@ -201,7 +201,7 @@ fn openat(dirfd: &File, path: &str) -> Result<File, host::__wasi_errno_t> {
.map_err(|e| host_impl::errno_from_nix(e.as_errno().unwrap()))
}
fn readlinkat(dirfd: &File, path: &str) -> Result<String, host::__wasi_errno_t> {
fn readlinkat(dirfd: &File, path: &str) -> Result<String> {
use nix::fcntl;
use std::os::unix::prelude::AsRawFd;

View File

@@ -2,16 +2,13 @@
#![allow(unused_unsafe)]
use crate::memory::*;
use crate::sys::host_impl;
use crate::{host, wasm32};
use crate::{host, wasm32, Result};
use nix::convert_ioctl_res;
use nix::libc::{self, c_int};
use std::cmp;
use std::time::SystemTime;
pub(crate) fn clock_res_get(
clock_id: host::__wasi_clockid_t,
) -> Result<host::__wasi_timestamp_t, host::__wasi_errno_t> {
pub(crate) fn clock_res_get(clock_id: host::__wasi_clockid_t) -> Result<host::__wasi_timestamp_t> {
// convert the supported clocks to the libc types, or return EINVAL
let clock_id = match clock_id {
host::__WASI_CLOCK_REALTIME => libc::CLOCK_REALTIME,
@@ -45,9 +42,7 @@ pub(crate) fn clock_res_get(
})
}
pub(crate) fn clock_time_get(
clock_id: host::__wasi_clockid_t,
) -> Result<host::__wasi_timestamp_t, host::__wasi_errno_t> {
pub(crate) fn clock_time_get(clock_id: host::__wasi_clockid_t) -> Result<host::__wasi_timestamp_t> {
// convert the supported clocks to the libc types, or return EINVAL
let clock_id = match clock_id {
host::__WASI_CLOCK_REALTIME => libc::CLOCK_REALTIME,
@@ -73,9 +68,9 @@ pub(crate) fn clock_time_get(
}
pub(crate) fn poll_oneoff(
input: Vec<Result<host::__wasi_subscription_t, host::__wasi_errno_t>>,
input: Vec<Result<host::__wasi_subscription_t>>,
output_slice: &mut [wasm32::__wasi_event_t],
) -> Result<wasm32::size_t, host::__wasi_errno_t> {
) -> Result<wasm32::size_t> {
let timeout = input
.iter()
.filter_map(|event| match event {
@@ -152,7 +147,7 @@ nix::ioctl_read_bad!(fionread, nix::libc::FIONREAD, c_int);
fn wasi_clock_to_relative_ns_delay(
wasi_clock: host::__wasi_subscription_t___wasi_subscription_u___wasi_subscription_u_clock_t,
) -> Result<u128, host::__wasi_errno_t> {
) -> Result<u128> {
if wasi_clock.flags != wasm32::__WASI_SUBSCRIPTION_CLOCK_ABSTIME {
return Ok(wasi_clock.timeout as u128);
}

View File

@@ -2,16 +2,16 @@ pub(crate) mod fdentry_impl;
pub(crate) mod host_impl;
pub(crate) mod hostcalls_impl;
use crate::host;
use crate::sys::errno_from_host;
use crate::{host, Result};
use std::fs::File;
use std::path::Path;
pub(crate) fn dev_null() -> Result<File, host::__wasi_errno_t> {
pub(crate) fn dev_null() -> Result<File> {
File::open("/dev/null")
.map_err(|err| err.raw_os_error().map_or(host::__WASI_EIO, errno_from_host))
}
pub fn preopen_dir<P: AsRef<Path>>(path: P) -> Result<File, host::__wasi_errno_t> {
pub fn preopen_dir<P: AsRef<Path>>(path: P) -> Result<File> {
File::open(path).map_err(|err| err.raw_os_error().map_or(host::__WASI_EIO, errno_from_host))
}

View File

@@ -1,7 +1,6 @@
use super::host_impl;
use crate::fdentry::Descriptor;
use crate::host;
use crate::{host, Result};
use std::fs::File;
use std::io;
use std::os::windows::prelude::{AsRawHandle, FromRawHandle, RawHandle};
@@ -19,14 +18,11 @@ impl AsRawHandle for Descriptor {
pub(crate) fn determine_type_and_access_rights<Handle: AsRawHandle>(
handle: &Handle,
) -> Result<
(
host::__wasi_filetype_t,
host::__wasi_rights_t,
host::__wasi_rights_t,
),
host::__wasi_errno_t,
> {
) -> Result<(
host::__wasi_filetype_t,
host::__wasi_rights_t,
host::__wasi_rights_t,
)> {
use winx::file::{get_file_access_rights, AccessRight};
let (file_type, mut rights_base, rights_inheriting) = determine_type_rights(handle)?;
@@ -54,14 +50,11 @@ pub(crate) fn determine_type_and_access_rights<Handle: AsRawHandle>(
pub(crate) fn determine_type_rights<Handle: AsRawHandle>(
handle: &Handle,
) -> Result<
(
host::__wasi_filetype_t,
host::__wasi_rights_t,
host::__wasi_rights_t,
),
host::__wasi_errno_t,
> {
) -> Result<(
host::__wasi_filetype_t,
host::__wasi_rights_t,
host::__wasi_rights_t,
)> {
let (file_type, rights_base, rights_inheriting) = {
let file_type =
winx::file::get_file_type(handle.as_raw_handle()).map_err(host_impl::errno_from_win)?;

View File

@@ -2,7 +2,7 @@
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]
#![allow(unused)]
use crate::host;
use crate::{host, Result};
use std::ffi::OsStr;
use std::os::windows::ffi::OsStrExt;
@@ -108,7 +108,7 @@ pub fn win_from_oflags(
///
/// NB WASI spec requires OS string to be valid UTF-8. Otherwise,
/// `__WASI_EILSEQ` error is returned.
pub fn path_from_host<S: AsRef<OsStr>>(s: S) -> Result<String, host::__wasi_errno_t> {
pub fn path_from_host<S: AsRef<OsStr>>(s: S) -> Result<String> {
let vec: Vec<u16> = s.as_ref().encode_wide().collect();
String::from_utf16(&vec).map_err(|_| host::__WASI_EILSEQ)
}

View File

@@ -3,10 +3,10 @@
use super::fs_helpers::*;
use crate::ctx::WasiCtx;
use crate::fdentry::FdEntry;
use crate::host;
use crate::sys::errno_from_host;
use crate::sys::fdentry_impl::determine_type_rights;
use crate::sys::host_impl;
use crate::{host, Result};
use std::fs::File;
use std::io::{self, Seek, SeekFrom};
use std::os::windows::fs::FileExt;
@@ -36,16 +36,12 @@ pub(crate) fn fd_pread(
file: &File,
buf: &mut [u8],
offset: host::__wasi_filesize_t,
) -> Result<usize, host::__wasi_errno_t> {
) -> Result<usize> {
read_at(file, buf, offset)
.map_err(|err| err.raw_os_error().map_or(host::__WASI_EIO, errno_from_host))
}
pub(crate) fn fd_pwrite(
file: &File,
buf: &[u8],
offset: host::__wasi_filesize_t,
) -> Result<usize, host::__wasi_errno_t> {
pub(crate) fn fd_pwrite(file: &File, buf: &[u8], offset: host::__wasi_filesize_t) -> Result<usize> {
write_at(file, buf, offset)
.map_err(|err| err.raw_os_error().map_or(host::__WASI_EIO, errno_from_host))
}
@@ -54,7 +50,7 @@ pub(crate) fn fd_renumber(
wasi_ctx: &mut WasiCtx,
from: host::__wasi_fd_t,
to: host::__wasi_fd_t,
) -> Result<(), host::__wasi_errno_t> {
) -> Result<()> {
unimplemented!("fd_renumber")
}
@@ -62,17 +58,15 @@ pub(crate) fn fd_seek(
fd_entry: &FdEntry,
offset: host::__wasi_filedelta_t,
whence: host::__wasi_whence_t,
) -> Result<u64, host::__wasi_errno_t> {
) -> Result<u64> {
unimplemented!("fd_seek")
}
pub(crate) fn fd_tell(fd_entry: &FdEntry) -> Result<u64, host::__wasi_errno_t> {
pub(crate) fn fd_tell(fd_entry: &FdEntry) -> Result<u64> {
unimplemented!("fd_tell")
}
pub(crate) fn fd_fdstat_get(
fd_entry: &FdEntry,
) -> Result<host::__wasi_fdflags_t, host::__wasi_errno_t> {
pub(crate) fn fd_fdstat_get(fd_entry: &FdEntry) -> Result<host::__wasi_fdflags_t> {
use winx::file::AccessRight;
let raw_handle = fd_entry.fd_object.descriptor.as_raw_handle();
@@ -85,7 +79,7 @@ pub(crate) fn fd_fdstat_get(
pub(crate) fn fd_fdstat_set_flags(
fd_entry: &FdEntry,
fdflags: host::__wasi_fdflags_t,
) -> Result<(), host::__wasi_errno_t> {
) -> Result<()> {
unimplemented!("fd_fdstat_set_flags")
}
@@ -94,7 +88,7 @@ pub(crate) fn fd_advise(
advice: host::__wasi_advice_t,
offset: host::__wasi_filesize_t,
len: host::__wasi_filesize_t,
) -> Result<(), host::__wasi_errno_t> {
) -> Result<()> {
unimplemented!("fd_advise")
}
@@ -102,7 +96,7 @@ pub(crate) fn path_create_directory(
ctx: &WasiCtx,
dirfd: host::__wasi_fd_t,
path: &str,
) -> Result<(), host::__wasi_errno_t> {
) -> Result<()> {
unimplemented!("path_create_directory")
}
@@ -114,7 +108,7 @@ pub(crate) fn path_link(
new_path: &str,
source_rights: host::__wasi_rights_t,
target_rights: host::__wasi_rights_t,
) -> Result<(), host::__wasi_errno_t> {
) -> Result<()> {
unimplemented!("path_link")
}
@@ -129,7 +123,7 @@ pub(crate) fn path_open(
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> {
) -> Result<FdEntry> {
use winx::file::{AccessRight, CreationDisposition, FlagsAndAttributes, ShareMode};
let mut win_rights = AccessRight::READ_CONTROL;
@@ -200,7 +194,7 @@ pub(crate) fn fd_readdir(
fd_entry: &FdEntry,
host_buf: &mut [u8],
cookie: host::__wasi_dircookie_t,
) -> Result<usize, host::__wasi_errno_t> {
) -> Result<usize> {
unimplemented!("fd_readdir")
}
@@ -210,7 +204,7 @@ pub(crate) fn path_readlink(
path: &str,
rights: host::__wasi_rights_t,
buf: &mut [u8],
) -> Result<usize, host::__wasi_errno_t> {
) -> Result<usize> {
unimplemented!("path_readlink")
}
@@ -222,13 +216,11 @@ pub(crate) fn path_rename(
new_dirfd: host::__wasi_fd_t,
new_path: &str,
new_rights: host::__wasi_rights_t,
) -> Result<(), host::__wasi_errno_t> {
) -> Result<()> {
unimplemented!("path_rename")
}
pub(crate) fn fd_filestat_get(
fd_entry: &FdEntry,
) -> Result<host::__wasi_filestat_t, host::__wasi_errno_t> {
pub(crate) fn fd_filestat_get(fd_entry: &FdEntry) -> Result<host::__wasi_filestat_t> {
unimplemented!("fd_filestat_get")
}
@@ -237,14 +229,14 @@ pub(crate) fn fd_filestat_set_times(
st_atim: host::__wasi_timestamp_t,
mut st_mtim: host::__wasi_timestamp_t,
fst_flags: host::__wasi_fstflags_t,
) -> Result<(), host::__wasi_errno_t> {
) -> Result<()> {
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> {
) -> Result<()> {
unimplemented!("fd_filestat_set_size")
}
@@ -253,7 +245,7 @@ pub(crate) fn path_filestat_get(
dirfd: host::__wasi_fd_t,
dirflags: host::__wasi_lookupflags_t,
path: &str,
) -> Result<host::__wasi_filestat_t, host::__wasi_errno_t> {
) -> Result<host::__wasi_filestat_t> {
unimplemented!("path_filestat_get")
}
@@ -266,7 +258,7 @@ pub(crate) fn path_filestat_set_times(
st_atim: host::__wasi_timestamp_t,
mut st_mtim: host::__wasi_timestamp_t,
fst_flags: host::__wasi_fstflags_t,
) -> Result<(), host::__wasi_errno_t> {
) -> Result<()> {
unimplemented!("path_filestat_set_times")
}
@@ -276,7 +268,7 @@ pub(crate) fn path_symlink(
rights: host::__wasi_rights_t,
old_path: &str,
new_path: &str,
) -> Result<(), host::__wasi_errno_t> {
) -> Result<()> {
unimplemented!("path_symlink")
}
@@ -285,7 +277,7 @@ pub(crate) fn path_unlink_file(
dirfd: host::__wasi_fd_t,
path: &str,
rights: host::__wasi_rights_t,
) -> Result<(), host::__wasi_errno_t> {
) -> Result<()> {
unimplemented!("path_unlink_file")
}
@@ -294,6 +286,6 @@ pub(crate) fn path_remove_directory(
dirfd: host::__wasi_fd_t,
path: &str,
rights: host::__wasi_rights_t,
) -> Result<(), host::__wasi_errno_t> {
) -> Result<()> {
unimplemented!("path_remove_directory")
}

View File

@@ -3,9 +3,9 @@
use crate::ctx::WasiCtx;
use crate::fdentry::Descriptor;
use crate::host;
use crate::sys::errno_from_host;
use crate::sys::host_impl;
use crate::{host, Result};
use std::fs::File;
use std::os::windows::prelude::{AsRawHandle, FromRawHandle};
use std::path::{Component, Path};
@@ -19,7 +19,7 @@ pub(crate) fn path_get(
needed_base: host::__wasi_rights_t,
needed_inheriting: host::__wasi_rights_t,
needs_final_component: bool,
) -> Result<(File, String), host::__wasi_errno_t> {
) -> Result<(File, String)> {
if path.contains("\0") {
// if contains NUL, return EILSEQ
return Err(host::__WASI_EILSEQ);

View File

@@ -3,25 +3,21 @@
#![allow(unused)]
use crate::memory::*;
use crate::sys::host_impl;
use crate::{host, wasm32};
use crate::{host, wasm32, Result};
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> {
pub(crate) fn clock_res_get(clock_id: host::__wasi_clockid_t) -> Result<host::__wasi_timestamp_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> {
pub(crate) fn clock_time_get(clock_id: host::__wasi_clockid_t) -> Result<host::__wasi_timestamp_t> {
unimplemented!("clock_time_get")
}
pub(crate) fn poll_oneoff(
input: Vec<Result<host::__wasi_subscription_t, host::__wasi_errno_t>>,
input: Vec<Result<host::__wasi_subscription_t>>,
output_slice: &mut [wasm32::__wasi_event_t],
) -> Result<wasm32::size_t, host::__wasi_errno_t> {
) -> Result<wasm32::size_t> {
unimplemented!("poll_oneoff")
}

View File

@@ -2,16 +2,16 @@ pub(crate) mod fdentry_impl;
pub(crate) mod host_impl;
pub(crate) mod hostcalls_impl;
use crate::host;
use crate::sys::errno_from_host;
use crate::{host, Result};
use std::fs::File;
use std::path::Path;
pub(crate) fn dev_null() -> Result<File, host::__wasi_errno_t> {
pub(crate) fn dev_null() -> Result<File> {
File::open("NUL").map_err(|err| err.raw_os_error().map_or(host::__WASI_EIO, errno_from_host))
}
pub fn preopen_dir<P: AsRef<Path>>(path: P) -> Result<File, host::__wasi_errno_t> {
pub fn preopen_dir<P: AsRef<Path>>(path: P) -> Result<File> {
use std::fs::OpenOptions;
use std::os::windows::fs::OpenOptionsExt;
use winapi::um::winbase::FILE_FLAG_BACKUP_SEMANTICS;