Merge remote-tracking branch 'origin/main' into pch/wasi_error_handling

This commit is contained in:
Pat Hickey
2020-08-25 15:22:51 -07:00
94 changed files with 3333 additions and 2168 deletions

View File

@@ -1,7 +1,6 @@
use crate::handle::{Handle, HandleRights};
use crate::wasi::{self, types, RightsExt};
use crate::{Error, Result};
use log::trace;
use std::any::Any;
use std::cell::{Cell, RefCell};
use std::collections::hash_map::Entry;
@@ -11,6 +10,7 @@ use std::io;
use std::io::SeekFrom;
use std::path::{Path, PathBuf};
use std::rc::Rc;
use tracing::trace;
pub mod pipe;
@@ -97,7 +97,7 @@ impl FileContents for VecFileContents {
}
fn pread(&self, buf: &mut [u8], offset: types::Filesize) -> Result<usize> {
trace!(" | pread(buf.len={}, offset={})", buf.len(), offset);
trace!(buffer_length = buf.len(), offset = offset, "pread");
let offset: usize = offset.try_into().map_err(|_| Error::Inval)?;
let data_remaining = self.content.len().saturating_sub(offset);
@@ -106,9 +106,7 @@ impl FileContents for VecFileContents {
(&mut buf[..read_count]).copy_from_slice(&self.content[offset..][..read_count]);
let res = Ok(read_count);
trace!(" | pread={:?}", res);
res
Ok(read_count)
}
fn pwrite(&mut self, buf: &[u8], offset: types::Filesize) -> Result<usize> {
@@ -348,26 +346,16 @@ impl Handle for InMemoryFile {
fn openat(
&self,
path: &str,
read: bool,
write: bool,
_read: bool,
_write: bool,
oflags: types::Oflags,
fd_flags: types::Fdflags,
_fd_flags: types::Fdflags,
) -> Result<Box<dyn Handle>> {
log::trace!(
"InMemoryFile::openat(path={:?}, read={:?}, write={:?}, oflags={:?}, fd_flags={:?}",
path,
read,
write,
oflags,
fd_flags
);
if oflags.contains(&types::Oflags::DIRECTORY) {
log::trace!(
tracing::trace!(
"InMemoryFile::openat was passed oflags DIRECTORY, but {:?} is a file.",
path
);
log::trace!(" return Notdir");
return Err(Error::Notdir);
}
@@ -527,7 +515,7 @@ impl Handle for VirtualDir {
type Item = Result<(types::Dirent, String)>;
fn next(&mut self) -> Option<Self::Item> {
log::trace!("VirtualDirIter::next continuing from {}", self.start);
tracing::trace!("VirtualDirIter::next continuing from {}", self.start);
if self.start == SELF_DIR_COOKIE {
self.start += 1;
let name = ".".to_owned();
@@ -646,20 +634,11 @@ impl Handle for VirtualDir {
fn openat(
&self,
path: &str,
read: bool,
write: bool,
_read: bool,
_write: bool,
oflags: types::Oflags,
fd_flags: types::Fdflags,
) -> Result<Box<dyn Handle>> {
log::trace!(
"VirtualDir::openat(path={:?}, read={:?}, write={:?}, oflags={:?}, fd_flags={:?}",
path,
read,
write,
oflags,
fd_flags
);
if path == "." {
return self.try_clone().map_err(Into::into);
} else if path == ".." {
@@ -682,19 +661,17 @@ impl Handle for VirtualDir {
Entry::Occupied(e) => {
let creat_excl_mask = types::Oflags::CREAT | types::Oflags::EXCL;
if (oflags & creat_excl_mask) == creat_excl_mask {
log::trace!("VirtualDir::openat was passed oflags CREAT|EXCL, but the file {:?} exists.", file_name);
log::trace!(" return Exist");
tracing::trace!("VirtualDir::openat was passed oflags CREAT|EXCL, but the file {:?} exists.", file_name);
return Err(Error::Exist);
}
if oflags.contains(&types::Oflags::DIRECTORY)
&& e.get().get_file_type() != types::Filetype::Directory
{
log::trace!(
tracing::trace!(
"VirtualDir::openat was passed oflags DIRECTORY, but {:?} is a file.",
file_name
);
log::trace!(" return Notdir");
return Err(Error::Notdir);
}
@@ -710,7 +687,7 @@ impl Handle for VirtualDir {
return Err(Error::Nospc);
}
log::trace!("VirtualDir::openat creating an InMemoryFile named {}", path);
tracing::trace!("VirtualDir::openat creating an InMemoryFile named {}", path);
let file = Box::new(InMemoryFile::memory_backed());
file.fd_flags.set(fd_flags);
@@ -758,7 +735,7 @@ impl Handle for VirtualDir {
Ok(())
}
Entry::Vacant(_) => {
log::trace!(
tracing::trace!(
"VirtualDir::remove_directory failed to remove {}, no such entry",
trimmed_path
);
@@ -799,7 +776,7 @@ impl Handle for VirtualDir {
Ok(())
}
Entry::Vacant(_) => {
log::trace!(
tracing::trace!(
"VirtualDir::unlink_file failed to remove {}, no such entry",
trimmed_path
);