diff --git a/wasmtime-wasi/sandboxed-system-primitives/include/wasmtime_ssp.h b/wasmtime-wasi/sandboxed-system-primitives/include/wasmtime_ssp.h index 660c4b2538..ff46aa235d 100644 --- a/wasmtime-wasi/sandboxed-system-primitives/include/wasmtime_ssp.h +++ b/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, diff --git a/wasmtime-wasi/sandboxed-system-primitives/src/posix.c b/wasmtime-wasi/sandboxed-system-primitives/src/posix.c index 95b5846009..42799ca47b 100644 --- a/wasmtime-wasi/sandboxed-system-primitives/src/posix.c +++ b/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, diff --git a/wasmtime-wasi/src/host_impls.rs b/wasmtime-wasi/src/host_impls.rs index c73b1e845a..e545c834f7 100644 --- a/wasmtime-wasi/src/host_impls.rs +++ b/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 { diff --git a/wasmtime-wasi/src/syscalls.rs b/wasmtime-wasi/src/syscalls.rs index 0151095976..6bdf465d99 100644 --- a/wasmtime-wasi/src/syscalls.rs +++ b/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) }