Add Rust impl of wasmtime_ssp_fd_prestat_dir_name
This commit is contained in:
@@ -497,15 +497,6 @@ __wasi_errno_t wasmtime_ssp_environ_sizes_get(
|
|||||||
size_t *environ_buf_size
|
size_t *environ_buf_size
|
||||||
) WASMTIME_SSP_SYSCALL_NAME(environ_sizes_get) __attribute__((__warn_unused_result__));
|
) 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(
|
__wasi_errno_t wasmtime_ssp_fd_close(
|
||||||
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
|
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
|
||||||
struct fd_table *curfds,
|
struct fd_table *curfds,
|
||||||
|
|||||||
@@ -652,33 +652,6 @@ static __wasi_errno_t fd_table_insert_fd(
|
|||||||
return fd_table_insert(ft, fo, rights_base, rights_inheriting, out);
|
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(
|
__wasi_errno_t wasmtime_ssp_fd_close(
|
||||||
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
|
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
|
||||||
struct fd_table *curfds,
|
struct fd_table *curfds,
|
||||||
|
|||||||
@@ -147,6 +147,31 @@ pub fn wasmtime_ssp_fd_prestat_get(
|
|||||||
ret_code
|
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 {
|
pub fn wasmtime_ssp_sched_yield() -> host::__wasi_errno_t {
|
||||||
unsafe {
|
unsafe {
|
||||||
if libc::sched_yield() < 0 {
|
if libc::sched_yield() < 0 {
|
||||||
|
|||||||
@@ -404,7 +404,11 @@ syscalls! {
|
|||||||
|
|
||||||
trace!(" | (path,path_len)={:?}", str_for_trace(path, path_len));
|
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)
|
return_encoded_errno(e)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user