Browse Source

Add Rust impl of wasmtime_ssp_fd_prestat_dir_name

pull/137/head
Jakub Konka 6 years ago
committed by Dan Gohman
parent
commit
3e94af81df
  1. 9
      wasmtime-wasi/sandboxed-system-primitives/include/wasmtime_ssp.h
  2. 27
      wasmtime-wasi/sandboxed-system-primitives/src/posix.c
  3. 25
      wasmtime-wasi/src/host_impls.rs
  4. 6
      wasmtime-wasi/src/syscalls.rs

9
wasmtime-wasi/sandboxed-system-primitives/include/wasmtime_ssp.h

@ -497,15 +497,6 @@ __wasi_errno_t wasmtime_ssp_environ_sizes_get(
size_t *environ_buf_size
) WASMTIME_SSP_SYSCALL_NAME(environ_sizes_get) __attribute__((__warn_unused_result__));
__wasi_errno_t wasmtime_ssp_fd_prestat_dir_name(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
struct fd_prestats *prestats,
#endif
__wasi_fd_t fd,
char *path,
size_t path_len
) WASMTIME_SSP_SYSCALL_NAME(fd_prestat_dir_name) __attribute__((__warn_unused_result__));
__wasi_errno_t wasmtime_ssp_fd_close(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
struct fd_table *curfds,

27
wasmtime-wasi/sandboxed-system-primitives/src/posix.c

@ -652,33 +652,6 @@ static __wasi_errno_t fd_table_insert_fd(
return fd_table_insert(ft, fo, rights_base, rights_inheriting, out);
}
__wasi_errno_t wasmtime_ssp_fd_prestat_dir_name(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
struct fd_prestats *prestats,
#endif
__wasi_fd_t fd,
char *path,
size_t path_len
) {
rwlock_rdlock(&prestats->lock);
struct fd_prestat *prestat;
__wasi_errno_t error = fd_prestats_get_entry(prestats, fd, &prestat);
if (error != 0) {
rwlock_unlock(&prestats->lock);
return error;
}
if (path_len != prestat->dir_name_len) {
rwlock_unlock(&prestats->lock);
return EINVAL;
}
memcpy(path, prestat->dir_name, path_len);
rwlock_unlock(&prestats->lock);
return 0;
}
__wasi_errno_t wasmtime_ssp_fd_close(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
struct fd_table *curfds,

25
wasmtime-wasi/src/host_impls.rs

@ -147,6 +147,31 @@ pub fn wasmtime_ssp_fd_prestat_get(
ret_code
}
pub fn wasmtime_ssp_fd_prestat_dir_name(
prestats: &mut host::fd_prestats,
fd: host::__wasi_fd_t,
path: &mut [host::char],
) -> host::__wasi_errno_t {
rwlock_rdlock!(prestats);
let ret_code = if let Some(prestat) = fd_prestats_get_entry(prestats, fd) {
if path.len() != prestat.dir_name_len {
host::__WASI_EINVAL
} else {
path.copy_from_slice(unsafe {
::std::slice::from_raw_parts(prestat.dir_name, prestat.dir_name_len)
});
host::__WASI_ESUCCESS
}
} else {
host::__WASI_EBADF
};
rwlock_unlock!(prestats);
ret_code
}
pub fn wasmtime_ssp_sched_yield() -> host::__wasi_errno_t {
unsafe {
if libc::sched_yield() < 0 {

6
wasmtime-wasi/src/syscalls.rs

@ -404,7 +404,11 @@ syscalls! {
trace!(" | (path,path_len)={:?}", str_for_trace(path, path_len));
let e = host::wasmtime_ssp_fd_prestat_dir_name(prestats, fd, path, path_len);
let e = host_impls::wasmtime_ssp_fd_prestat_dir_name(
&mut *prestats,
fd,
::std::slice::from_raw_parts_mut(path, path_len),
);
return_encoded_errno(e)
}

Loading…
Cancel
Save