Move extracting fds from context into hostcalls

This commit is contained in:
Jakub Konka
2019-07-20 10:38:21 +02:00
committed by Dan Gohman
parent 14391bab56
commit 0d571a4e6d
6 changed files with 301 additions and 361 deletions

View File

@@ -1,8 +1,6 @@
#![allow(non_camel_case_types)]
#![allow(unused_unsafe)]
use crate::ctx::WasiCtx;
use crate::fdentry::Descriptor;
use crate::sys::errno_from_host;
use crate::sys::host_impl;
use crate::{host, Result};
@@ -12,12 +10,9 @@ use std::path::{Component, Path};
/// Normalizes a path to ensure that the target path is located under the directory provided.
pub(crate) fn path_get(
wasi_ctx: &WasiCtx,
dirfd: host::__wasi_fd_t,
dirfd: &File,
_dirflags: host::__wasi_lookupflags_t,
path: &str,
needed_base: host::__wasi_rights_t,
needed_inheriting: host::__wasi_rights_t,
needs_final_component: bool,
) -> Result<(File, String)> {
if path.contains("\0") {
@@ -25,14 +20,10 @@ pub(crate) fn path_get(
return Err(host::__WASI_EILSEQ);
}
let dirfe = wasi_ctx.get_fd_entry(dirfd, needed_base, needed_inheriting)?;
let dirfd = match &*dirfe.fd_object.descriptor {
Descriptor::File(f) => f.try_clone().map_err(|err| {
err.raw_os_error()
.map_or(host::__WASI_EBADF, errno_from_host)
})?,
_ => return Err(host::__WASI_EBADF),
};
let dirfd = dirfd.try_clone().map_err(|err| {
err.raw_os_error()
.map_or(host::__WASI_EBADF, errno_from_host)
})?;
// Stack of directory handles. Index 0 always corresponds with the directory provided
// to this function. Entering a directory causes a handle to be pushed, while handling