| From 62f535fa4e1a259aabd5f22449af01e32aeb6f47 Mon Sep 17 00:00:00 2001 |
| From: Dan Gohman <sunfish@mozilla.com> |
| Date: Tue, 23 Jul 2019 10:23:06 -0700 |
| Subject: [PATCH] maybe |
| |
| --- |
| src/wasi_unstable/constants.rs | 188 +++++++++++++ |
| src/wasi_unstable/minimal_safe.rs | 336 +++++++++++++++++++++++ |
| src/wasi_unstable/mod.rs | 431 ++++-------------------------- |
| src/wasi_unstable/types.rs | 41 +++ |
| 4 files changed, 623 insertions(+), 373 deletions(-) |
| create mode 100644 src/wasi_unstable/constants.rs |
| create mode 100644 src/wasi_unstable/minimal_safe.rs |
| create mode 100644 src/wasi_unstable/types.rs |
| |
| diff --git a/src/wasi_unstable/constants.rs b/src/wasi_unstable/constants.rs |
| new file mode 100644 |
| index 0000000..0af896b |
| --- /dev/null |
| +++ b/src/wasi_unstable/constants.rs |
| @@ -0,0 +1,188 @@ |
| +//! This file defines idiomatic Rust names for constants. |
| + |
| +use crate::wasi_unstable::raw::*; |
| +use crate::wasi_unstable::types::*; |
| + |
| +pub const ADVICE_NORMAL: Advice = __WASI_ADVICE_NORMAL; |
| +pub const ADVICE_SEQUENTIAL: Advice = __WASI_ADVICE_SEQUENTIAL; |
| +pub const ADVICE_RANDOM: Advice = __WASI_ADVICE_RANDOM; |
| +pub const ADVICE_WILLNEED: Advice = __WASI_ADVICE_WILLNEED; |
| +pub const ADVICE_DONTNEED: Advice = __WASI_ADVICE_DONTNEED; |
| +pub const ADVICE_NOREUSE: Advice = __WASI_ADVICE_NOREUSE; |
| +pub const CLOCK_REALTIME: ClockId = __WASI_CLOCK_REALTIME; |
| +pub const CLOCK_MONOTONIC: ClockId = __WASI_CLOCK_MONOTONIC; |
| +pub const CLOCK_PROCESS_CPUTIME_ID: ClockId = __WASI_CLOCK_PROCESS_CPUTIME_ID; |
| +pub const CLOCK_THREAD_CPUTIME_ID: ClockId = __WASI_CLOCK_THREAD_CPUTIME_ID; |
| +pub const DIRCOOKIE_START: DirCookie = __WASI_DIRCOOKIE_START; |
| +pub const ESUCCESS: Errno = __WASI_ESUCCESS; |
| +pub const E2BIG: Errno = __WASI_E2BIG; |
| +pub const EACCES: Errno = __WASI_EACCES; |
| +pub const EADDRINUSE: Errno = __WASI_EADDRINUSE; |
| +pub const EADDRNOTAVAIL: Errno = __WASI_EADDRNOTAVAIL; |
| +pub const EAFNOSUPPORT: Errno = __WASI_EAFNOSUPPORT; |
| +pub const EAGAIN: Errno = __WASI_EAGAIN; |
| +pub const EALREADY: Errno = __WASI_EALREADY; |
| +pub const EBADF: Errno = __WASI_EBADF; |
| +pub const EBADMSG: Errno = __WASI_EBADMSG; |
| +pub const EBUSY: Errno = __WASI_EBUSY; |
| +pub const ECANCELED: Errno = __WASI_ECANCELED; |
| +pub const ECHILD: Errno = __WASI_ECHILD; |
| +pub const ECONNABORTED: Errno = __WASI_ECONNABORTED; |
| +pub const ECONNREFUSED: Errno = __WASI_ECONNREFUSED; |
| +pub const ECONNRESET: Errno = __WASI_ECONNRESET; |
| +pub const EDEADLK: Errno = __WASI_EDEADLK; |
| +pub const EDESTADDRREQ: Errno = __WASI_EDESTADDRREQ; |
| +pub const EDOM: Errno = __WASI_EDOM; |
| +pub const EDQUOT: Errno = __WASI_EDQUOT; |
| +pub const EEXIST: Errno = __WASI_EEXIST; |
| +pub const EFAULT: Errno = __WASI_EFAULT; |
| +pub const EFBIG: Errno = __WASI_EFBIG; |
| +pub const EHOSTUNREACH: Errno = __WASI_EHOSTUNREACH; |
| +pub const EIDRM: Errno = __WASI_EIDRM; |
| +pub const EILSEQ: Errno = __WASI_EILSEQ; |
| +pub const EINPROGRESS: Errno = __WASI_EINPROGRESS; |
| +pub const EINTR: Errno = __WASI_EINTR; |
| +pub const EINVAL: Errno = __WASI_EINVAL; |
| +pub const EIO: Errno = __WASI_EIO; |
| +pub const EISCONN: Errno = __WASI_EISCONN; |
| +pub const EISDIR: Errno = __WASI_EISDIR; |
| +pub const ELOOP: Errno = __WASI_ELOOP; |
| +pub const EMFILE: Errno = __WASI_EMFILE; |
| +pub const EMLINK: Errno = __WASI_EMLINK; |
| +pub const EMSGSIZE: Errno = __WASI_EMSGSIZE; |
| +pub const EMULTIHOP: Errno = __WASI_EMULTIHOP; |
| +pub const ENAMETOOLONG: Errno = __WASI_ENAMETOOLONG; |
| +pub const ENETDOWN: Errno = __WASI_ENETDOWN; |
| +pub const ENETRESET: Errno = __WASI_ENETRESET; |
| +pub const ENETUNREACH: Errno = __WASI_ENETUNREACH; |
| +pub const ENFILE: Errno = __WASI_ENFILE; |
| +pub const ENOBUFS: Errno = __WASI_ENOBUFS; |
| +pub const ENODEV: Errno = __WASI_ENODEV; |
| +pub const ENOENT: Errno = __WASI_ENOENT; |
| +pub const ENOEXEC: Errno = __WASI_ENOEXEC; |
| +pub const ENOLCK: Errno = __WASI_ENOLCK; |
| +pub const ENOLINK: Errno = __WASI_ENOLINK; |
| +pub const ENOMEM: Errno = __WASI_ENOMEM; |
| +pub const ENOMSG: Errno = __WASI_ENOMSG; |
| +pub const ENOPROTOOPT: Errno = __WASI_ENOPROTOOPT; |
| +pub const ENOSPC: Errno = __WASI_ENOSPC; |
| +pub const ENOSYS: Errno = __WASI_ENOSYS; |
| +pub const ENOTCONN: Errno = __WASI_ENOTCONN; |
| +pub const ENOTDIR: Errno = __WASI_ENOTDIR; |
| +pub const ENOTEMPTY: Errno = __WASI_ENOTEMPTY; |
| +pub const ENOTRECOVERABLE: Errno = __WASI_ENOTRECOVERABLE; |
| +pub const ENOTSOCK: Errno = __WASI_ENOTSOCK; |
| +pub const ENOTSUP: Errno = __WASI_ENOTSUP; |
| +pub const ENOTTY: Errno = __WASI_ENOTTY; |
| +pub const ENXIO: Errno = __WASI_ENXIO; |
| +pub const EOVERFLOW: Errno = __WASI_EOVERFLOW; |
| +pub const EOWNERDEAD: Errno = __WASI_EOWNERDEAD; |
| +pub const EPERM: Errno = __WASI_EPERM; |
| +pub const EPIPE: Errno = __WASI_EPIPE; |
| +pub const EPROTO: Errno = __WASI_EPROTO; |
| +pub const EPROTONOSUPPORT: Errno = __WASI_EPROTONOSUPPORT; |
| +pub const EPROTOTYPE: Errno = __WASI_EPROTOTYPE; |
| +pub const ERANGE: Errno = __WASI_ERANGE; |
| +pub const EROFS: Errno = __WASI_EROFS; |
| +pub const ESPIPE: Errno = __WASI_ESPIPE; |
| +pub const ESRCH: Errno = __WASI_ESRCH; |
| +pub const ESTALE: Errno = __WASI_ESTALE; |
| +pub const ETIMEDOUT: Errno = __WASI_ETIMEDOUT; |
| +pub const ETXTBSY: Errno = __WASI_ETXTBSY; |
| +pub const EXDEV: Errno = __WASI_EXDEV; |
| +pub const ENOTCAPABLE: Errno = __WASI_ENOTCAPABLE; |
| +pub const EVENT_FD_READWRITE_HANGUP: EventRwFlags = __WASI_EVENT_FD_READWRITE_HANGUP; |
| +pub const EVENTTYPE_CLOCK: EventType = __WASI_EVENTTYPE_CLOCK; |
| +pub const EVENTTYPE_FD_READ: EventType = __WASI_EVENTTYPE_FD_READ; |
| +pub const EVENTTYPE_FD_WRITE: EventType = __WASI_EVENTTYPE_FD_WRITE; |
| +pub const FDFLAG_APPEND: FdFlags = __WASI_FDFLAG_APPEND; |
| +pub const FDFLAG_DSYNC: FdFlags = __WASI_FDFLAG_DSYNC; |
| +pub const FDFLAG_NONBLOCK: FdFlags = __WASI_FDFLAG_NONBLOCK; |
| +pub const FDFLAG_RSYNC: FdFlags = __WASI_FDFLAG_RSYNC; |
| +pub const FDFLAG_SYNC: FdFlags = __WASI_FDFLAG_SYNC; |
| +pub const FILETYPE_UNKNOWN: FileType = __WASI_FILETYPE_UNKNOWN; |
| +pub const FILETYPE_BLOCK_DEVICE: FileType = __WASI_FILETYPE_BLOCK_DEVICE; |
| +pub const FILETYPE_CHARACTER_DEVICE: FileType = __WASI_FILETYPE_CHARACTER_DEVICE; |
| +pub const FILETYPE_DIRECTORY: FileType = __WASI_FILETYPE_DIRECTORY; |
| +pub const FILETYPE_REGULAR_FILE: FileType = __WASI_FILETYPE_REGULAR_FILE; |
| +pub const FILETYPE_SOCKET_DGRAM: FileType = __WASI_FILETYPE_SOCKET_DGRAM; |
| +pub const FILETYPE_SOCKET_STREAM: FileType = __WASI_FILETYPE_SOCKET_STREAM; |
| +pub const FILETYPE_SYMBOLIC_LINK: FileType = __WASI_FILETYPE_SYMBOLIC_LINK; |
| +pub const FILESTAT_SET_ATIM: FstFlags = __WASI_FILESTAT_SET_ATIM; |
| +pub const FILESTAT_SET_ATIM_NOW: FstFlags = __WASI_FILESTAT_SET_ATIM_NOW; |
| +pub const FILESTAT_SET_MTIM: FstFlags = __WASI_FILESTAT_SET_MTIM; |
| +pub const FILESTAT_SET_MTIM_NOW: FstFlags = __WASI_FILESTAT_SET_MTIM_NOW; |
| +pub const LOOKUP_SYMLINK_FOLLOW: LookupFlags = __WASI_LOOKUP_SYMLINK_FOLLOW; |
| +pub const O_CREAT: OFlags = __WASI_O_CREAT; |
| +pub const O_DIRECTORY: OFlags = __WASI_O_DIRECTORY; |
| +pub const O_EXCL: OFlags = __WASI_O_EXCL; |
| +pub const O_TRUNC: OFlags = __WASI_O_TRUNC; |
| +pub const PREOPENTYPE_DIR: PreopenType = __WASI_PREOPENTYPE_DIR; |
| +pub const SOCK_RECV_PEEK: RiFlags = __WASI_SOCK_RECV_PEEK; |
| +pub const SOCK_RECV_WAITALL: RiFlags = __WASI_SOCK_RECV_WAITALL; |
| +pub const RIGHT_FD_DATASYNC: Rights = __WASI_RIGHT_FD_DATASYNC; |
| +pub const RIGHT_FD_READ: Rights = __WASI_RIGHT_FD_READ; |
| +pub const RIGHT_FD_SEEK: Rights = __WASI_RIGHT_FD_SEEK; |
| +pub const RIGHT_FD_FDSTAT_SET_FLAGS: Rights = __WASI_RIGHT_FD_FDSTAT_SET_FLAGS; |
| +pub const RIGHT_FD_SYNC: Rights = __WASI_RIGHT_FD_SYNC; |
| +pub const RIGHT_FD_TELL: Rights = __WASI_RIGHT_FD_TELL; |
| +pub const RIGHT_FD_WRITE: Rights = __WASI_RIGHT_FD_WRITE; |
| +pub const RIGHT_FD_ADVISE: Rights = __WASI_RIGHT_FD_ADVISE; |
| +pub const RIGHT_FD_ALLOCATE: Rights = __WASI_RIGHT_FD_ALLOCATE; |
| +pub const RIGHT_PATH_CREATE_DIRECTORY: Rights = __WASI_RIGHT_PATH_CREATE_DIRECTORY; |
| +pub const RIGHT_PATH_CREATE_FILE: Rights = __WASI_RIGHT_PATH_CREATE_FILE; |
| +pub const RIGHT_PATH_LINK_SOURCE: Rights = __WASI_RIGHT_PATH_LINK_SOURCE; |
| +pub const RIGHT_PATH_LINK_TARGET: Rights = __WASI_RIGHT_PATH_LINK_TARGET; |
| +pub const RIGHT_PATH_OPEN: Rights = __WASI_RIGHT_PATH_OPEN; |
| +pub const RIGHT_FD_READDIR: Rights = __WASI_RIGHT_FD_READDIR; |
| +pub const RIGHT_PATH_READLINK: Rights = __WASI_RIGHT_PATH_READLINK; |
| +pub const RIGHT_PATH_RENAME_SOURCE: Rights = __WASI_RIGHT_PATH_RENAME_SOURCE; |
| +pub const RIGHT_PATH_RENAME_TARGET: Rights = __WASI_RIGHT_PATH_RENAME_TARGET; |
| +pub const RIGHT_PATH_FILESTAT_GET: Rights = __WASI_RIGHT_PATH_FILESTAT_GET; |
| +pub const RIGHT_PATH_FILESTAT_SET_SIZE: Rights = __WASI_RIGHT_PATH_FILESTAT_SET_SIZE; |
| +pub const RIGHT_PATH_FILESTAT_SET_TIMES: Rights = __WASI_RIGHT_PATH_FILESTAT_SET_TIMES; |
| +pub const RIGHT_FD_FILESTAT_GET: Rights = __WASI_RIGHT_FD_FILESTAT_GET; |
| +pub const RIGHT_FD_FILESTAT_SET_SIZE: Rights = __WASI_RIGHT_FD_FILESTAT_SET_SIZE; |
| +pub const RIGHT_FD_FILESTAT_SET_TIMES: Rights = __WASI_RIGHT_FD_FILESTAT_SET_TIMES; |
| +pub const RIGHT_PATH_SYMLINK: Rights = __WASI_RIGHT_PATH_SYMLINK; |
| +pub const RIGHT_PATH_REMOVE_DIRECTORY: Rights = __WASI_RIGHT_PATH_REMOVE_DIRECTORY; |
| +pub const RIGHT_PATH_UNLINK_FILE: Rights = __WASI_RIGHT_PATH_UNLINK_FILE; |
| +pub const RIGHT_POLL_FD_READWRITE: Rights = __WASI_RIGHT_POLL_FD_READWRITE; |
| +pub const RIGHT_SOCK_SHUTDOWN: Rights = __WASI_RIGHT_SOCK_SHUTDOWN; |
| +pub const SOCK_RECV_DATA_TRUNCATED: RoFlags = __WASI_SOCK_RECV_DATA_TRUNCATED; |
| +pub const SHUT_RD: SdFlags = __WASI_SHUT_RD; |
| +pub const SHUT_WR: SdFlags = __WASI_SHUT_WR; |
| +pub const SIGHUP: Signal = __WASI_SIGHUP; |
| +pub const SIGINT: Signal = __WASI_SIGINT; |
| +pub const SIGQUIT: Signal = __WASI_SIGQUIT; |
| +pub const SIGILL: Signal = __WASI_SIGILL; |
| +pub const SIGTRAP: Signal = __WASI_SIGTRAP; |
| +pub const SIGABRT: Signal = __WASI_SIGABRT; |
| +pub const SIGBUS: Signal = __WASI_SIGBUS; |
| +pub const SIGFPE: Signal = __WASI_SIGFPE; |
| +pub const SIGKILL: Signal = __WASI_SIGKILL; |
| +pub const SIGUSR1: Signal = __WASI_SIGUSR1; |
| +pub const SIGSEGV: Signal = __WASI_SIGSEGV; |
| +pub const SIGUSR2: Signal = __WASI_SIGUSR2; |
| +pub const SIGPIPE: Signal = __WASI_SIGPIPE; |
| +pub const SIGALRM: Signal = __WASI_SIGALRM; |
| +pub const SIGTERM: Signal = __WASI_SIGTERM; |
| +pub const SIGCHLD: Signal = __WASI_SIGCHLD; |
| +pub const SIGCONT: Signal = __WASI_SIGCONT; |
| +pub const SIGSTOP: Signal = __WASI_SIGSTOP; |
| +pub const SIGTSTP: Signal = __WASI_SIGTSTP; |
| +pub const SIGTTIN: Signal = __WASI_SIGTTIN; |
| +pub const SIGTTOU: Signal = __WASI_SIGTTOU; |
| +pub const SIGURG: Signal = __WASI_SIGURG; |
| +pub const SIGXCPU: Signal = __WASI_SIGXCPU; |
| +pub const SIGXFSZ: Signal = __WASI_SIGXFSZ; |
| +pub const SIGVTALRM: Signal = __WASI_SIGVTALRM; |
| +pub const SIGPROF: Signal = __WASI_SIGPROF; |
| +pub const SIGWINCH: Signal = __WASI_SIGWINCH; |
| +pub const SIGPOLL: Signal = __WASI_SIGPOLL; |
| +pub const SIGPWR: Signal = __WASI_SIGPWR; |
| +pub const SIGSYS: Signal = __WASI_SIGSYS; |
| +pub const SUBSCRIPTION_CLOCK_ABSTIME: SubclockFlags = __WASI_SUBSCRIPTION_CLOCK_ABSTIME; |
| +pub const WHENCE_CUR: Whence = __WASI_WHENCE_CUR; |
| +pub const WHENCE_END: Whence = __WASI_WHENCE_END; |
| +pub const WHENCE_SET: Whence = __WASI_WHENCE_SET; |
| diff --git a/src/wasi_unstable/minimal_safe.rs b/src/wasi_unstable/minimal_safe.rs |
| new file mode 100644 |
| index 0000000..91a1ef1 |
| --- /dev/null |
| +++ b/src/wasi_unstable/minimal_safe.rs |
| @@ -0,0 +1,336 @@ |
| +//! This file defines minimally safe wrappers around the raw functions. |
| +//! Pointer-length pairs are translated to Rust slice, and output pointer |
| +//! parameters are translated to output reference parameters. |
| +//! |
| +//! These are primarily useful for writing low-level API tests. For most |
| +//! other use cases, the interfaces defined in the top-level `wasi_unstable` |
| +//! module will be easier to use. |
| + |
| +use crate::wasi_unstable::raw::*; |
| +use core::ffi::c_void; |
| + |
| +pub use crate::wasi_unstable::constants::*; |
| +pub use crate::wasi_unstable::types::*; |
| + |
| +#[inline] |
| +pub fn clock_res_get(clock_id: ClockId, resolution: &mut Timestamp) -> Errno { |
| + unsafe { __wasi_clock_res_get(clock_id, resolution) } |
| +} |
| + |
| +#[inline] |
| +pub fn clock_time_get(clock_id: ClockId, precision: Timestamp, time: &mut Timestamp) -> Errno { |
| + unsafe { __wasi_clock_time_get(clock_id, precision, time) } |
| +} |
| + |
| +#[inline] |
| +pub fn fd_pread(fd: Fd, iovs: &[IoVec], offset: FileSize, nread: &mut usize) -> Errno { |
| + unsafe { __wasi_fd_pread(fd, iovs.as_ptr(), iovs.len(), offset, nread) } |
| +} |
| + |
| +#[inline] |
| +pub fn fd_pwrite(fd: Fd, iovs: &[CIoVec], offset: FileSize, nwritten: &mut usize) -> Errno { |
| + unsafe { __wasi_fd_pwrite(fd, iovs.as_ptr(), iovs.len(), offset, nwritten) } |
| +} |
| + |
| +#[inline] |
| +pub fn random_get(buf: &mut [u8]) -> Errno { |
| + unsafe { __wasi_random_get(buf.as_mut_ptr() as *mut c_void, buf.len()) } |
| +} |
| + |
| +#[inline] |
| +pub fn fd_close(fd: Fd) -> Errno { |
| + unsafe { __wasi_fd_close(fd) } |
| +} |
| + |
| +#[inline] |
| +pub fn fd_datasync(fd: Fd) -> Errno { |
| + unsafe { __wasi_fd_datasync(fd) } |
| +} |
| + |
| +#[inline] |
| +pub fn fd_read(fd: Fd, iovs: &[IoVec], nread: &mut usize) -> Errno { |
| + unsafe { __wasi_fd_read(fd, iovs.as_ptr(), iovs.len(), nread) } |
| +} |
| + |
| +#[inline] |
| +pub fn fd_renumber(from: Fd, to: Fd) -> Errno { |
| + unsafe { __wasi_fd_renumber(from, to) } |
| +} |
| + |
| +#[inline] |
| +pub fn fd_seek(fd: Fd, offset: FileDelta, whence: Whence, newoffset: &mut FileSize) -> Errno { |
| + unsafe { __wasi_fd_seek(fd, offset, whence, newoffset) } |
| +} |
| + |
| +#[inline] |
| +pub fn fd_tell(fd: Fd, newoffset: &mut FileSize) -> Errno { |
| + unsafe { __wasi_fd_tell(fd, newoffset) } |
| +} |
| + |
| +#[inline] |
| +pub fn fd_fdstat_get(fd: Fd, buf: &mut FdStat) -> Errno { |
| + unsafe { __wasi_fd_fdstat_get(fd, buf) } |
| +} |
| + |
| +#[inline] |
| +pub fn fd_fdstat_set_flags(fd: Fd, flags: FdFlags) -> Errno { |
| + unsafe { __wasi_fd_fdstat_set_flags(fd, flags) } |
| +} |
| + |
| +#[inline] |
| +pub fn fd_fdstat_set_rights(fd: Fd, fs_rights_base: Rights, fs_rights_inheriting: Rights) -> Errno { |
| + unsafe { __wasi_fd_fdstat_set_rights(fd, fs_rights_base, fs_rights_inheriting) } |
| +} |
| + |
| +#[inline] |
| +pub fn fd_sync(fd: Fd) -> Errno { |
| + unsafe { __wasi_fd_sync(fd) } |
| +} |
| + |
| +#[inline] |
| +pub fn fd_write(fd: Fd, iovs: &[CIoVec], nwritten: &mut usize) -> Errno { |
| + unsafe { __wasi_fd_write(fd, iovs.as_ptr(), iovs.len(), nwritten) } |
| +} |
| + |
| +#[inline] |
| +pub fn fd_advise(fd: Fd, offset: FileSize, len: FileSize, advice: Advice) -> Errno { |
| + unsafe { __wasi_fd_advise(fd, offset, len, advice) } |
| +} |
| + |
| +#[inline] |
| +pub fn fd_allocate(fd: Fd, offset: FileSize, len: FileSize) -> Errno { |
| + unsafe { __wasi_fd_allocate(fd, offset, len) } |
| +} |
| + |
| +#[inline] |
| +pub fn path_create_directory(fd: Fd, path: &[u8]) -> Errno { |
| + unsafe { __wasi_path_create_directory(fd, path.as_ptr(), path.len()) } |
| +} |
| + |
| +#[inline] |
| +pub fn path_link( |
| + old_fd: Fd, |
| + old_flags: LookupFlags, |
| + old_path: &[u8], |
| + new_fd: Fd, |
| + new_path: &[u8], |
| +) -> Errno { |
| + unsafe { |
| + __wasi_path_link( |
| + old_fd, |
| + old_flags, |
| + old_path.as_ptr(), |
| + old_path.len(), |
| + new_fd, |
| + new_path.as_ptr(), |
| + new_path.len(), |
| + ) |
| + } |
| +} |
| + |
| +#[inline] |
| +#[allow(clippy::too_many_arguments)] |
| +pub fn path_open( |
| + dirfd: Fd, |
| + dirflags: LookupFlags, |
| + path: &[u8], |
| + oflags: OFlags, |
| + fs_rights_base: Rights, |
| + fs_rights_inheriting: Rights, |
| + fs_flags: FdFlags, |
| + fd: &mut Fd, |
| +) -> Errno { |
| + unsafe { |
| + __wasi_path_open( |
| + dirfd, |
| + dirflags, |
| + path.as_ptr(), |
| + path.len(), |
| + oflags, |
| + fs_rights_base, |
| + fs_rights_inheriting, |
| + fs_flags, |
| + fd, |
| + ) |
| + } |
| +} |
| + |
| +#[inline] |
| +pub fn fd_readdir(fd: Fd, buf: &mut [u8], cookie: DirCookie, bufused: &mut usize) -> Errno { |
| + unsafe { |
| + __wasi_fd_readdir( |
| + fd, |
| + buf.as_mut_ptr() as *mut c_void, |
| + buf.len(), |
| + cookie, |
| + bufused, |
| + ) |
| + } |
| +} |
| + |
| +#[inline] |
| +pub fn path_readlink(fd: Fd, path: &[u8], buf: &mut [u8], bufused: &mut usize) -> Errno { |
| + unsafe { |
| + __wasi_path_readlink( |
| + fd, |
| + path.as_ptr(), |
| + path.len(), |
| + buf.as_mut_ptr(), |
| + buf.len(), |
| + bufused, |
| + ) |
| + } |
| +} |
| + |
| +#[inline] |
| +pub fn path_rename(old_fd: Fd, old_path: &[u8], new_fd: Fd, new_path: &[u8]) -> Errno { |
| + unsafe { |
| + __wasi_path_rename( |
| + old_fd, |
| + old_path.as_ptr(), |
| + old_path.len(), |
| + new_fd, |
| + new_path.as_ptr(), |
| + new_path.len(), |
| + ) |
| + } |
| +} |
| + |
| +#[inline] |
| +pub fn fd_filestat_get(fd: Fd, buf: &mut FileStat) -> Errno { |
| + unsafe { __wasi_fd_filestat_get(fd, buf) } |
| +} |
| + |
| +#[inline] |
| +pub fn fd_filestat_set_times( |
| + fd: Fd, |
| + st_atim: Timestamp, |
| + st_mtim: Timestamp, |
| + fstflags: FstFlags, |
| +) -> Errno { |
| + unsafe { __wasi_fd_filestat_set_times(fd, st_atim, st_mtim, fstflags) } |
| +} |
| + |
| +#[inline] |
| +pub fn fd_filestat_set_size(fd: Fd, st_size: FileSize) -> Errno { |
| + unsafe { __wasi_fd_filestat_set_size(fd, st_size) } |
| +} |
| + |
| +#[inline] |
| +pub fn path_filestat_get(fd: Fd, flags: LookupFlags, path: &[u8], buf: &mut FileStat) -> Errno { |
| + unsafe { __wasi_path_filestat_get(fd, flags, path.as_ptr(), path.len(), buf) } |
| +} |
| + |
| +#[inline] |
| +pub fn path_filestat_set_times( |
| + fd: Fd, |
| + flags: LookupFlags, |
| + path: &[u8], |
| + st_atim: Timestamp, |
| + st_mtim: Timestamp, |
| + fstflags: FstFlags, |
| +) -> Errno { |
| + unsafe { |
| + __wasi_path_filestat_set_times( |
| + fd, |
| + flags, |
| + path.as_ptr(), |
| + path.len(), |
| + st_atim, |
| + st_mtim, |
| + fstflags, |
| + ) |
| + } |
| +} |
| + |
| +#[inline] |
| +pub fn path_symlink(old_path: &[u8], fd: Fd, new_path: &[u8]) -> Errno { |
| + unsafe { |
| + __wasi_path_symlink( |
| + old_path.as_ptr(), |
| + old_path.len(), |
| + fd, |
| + new_path.as_ptr(), |
| + new_path.len(), |
| + ) |
| + } |
| +} |
| + |
| +#[inline] |
| +pub fn path_unlink_file(fd: Fd, path: &[u8]) -> Errno { |
| + unsafe { __wasi_path_unlink_file(fd, path.as_ptr(), path.len()) } |
| +} |
| + |
| +#[inline] |
| +pub fn path_remove_directory(fd: Fd, path: &[u8]) -> Errno { |
| + unsafe { __wasi_path_remove_directory(fd, path.as_ptr(), path.len()) } |
| +} |
| + |
| +#[inline] |
| +pub fn poll_oneoff(in_: &[Subscription], out: &mut [Event], nevents: &mut usize) -> Errno { |
| + assert!(out.len() >= in_.len()); |
| + unsafe { __wasi_poll_oneoff(in_.as_ptr(), out.as_mut_ptr(), in_.len(), nevents) } |
| +} |
| + |
| +#[inline] |
| +pub fn proc_exit(rval: ExitCode) { |
| + unsafe { __wasi_proc_exit(rval) } |
| +} |
| + |
| +#[inline] |
| +pub fn proc_raise(sig: Signal) -> Errno { |
| + unsafe { __wasi_proc_raise(sig) } |
| +} |
| + |
| +#[inline] |
| +pub fn sock_recv( |
| + sock: Fd, |
| + ri_data: &[IoVec], |
| + ri_flags: RiFlags, |
| + ro_datalen: &mut usize, |
| + ro_flags: &mut RoFlags, |
| +) -> Errno { |
| + unsafe { |
| + __wasi_sock_recv( |
| + sock, |
| + ri_data.as_ptr(), |
| + ri_data.len(), |
| + ri_flags, |
| + ro_datalen, |
| + ro_flags, |
| + ) |
| + } |
| +} |
| + |
| +#[inline] |
| +pub fn sock_send(sock: Fd, si_data: &[CIoVec], si_flags: SiFlags, so_datalen: &mut usize) -> Errno { |
| + unsafe { __wasi_sock_send(sock, si_data.as_ptr(), si_data.len(), si_flags, so_datalen) } |
| +} |
| + |
| +#[inline] |
| +pub fn sock_shutdown(sock: Fd, how: SdFlags) -> Errno { |
| + unsafe { __wasi_sock_shutdown(sock, how) } |
| +} |
| + |
| +#[inline] |
| +pub fn sched_yield() -> Errno { |
| + unsafe { __wasi_sched_yield() } |
| +} |
| + |
| +#[inline] |
| +pub fn fd_prestat_get(fd: Fd, buf: &mut Prestat) -> Errno { |
| + unsafe { __wasi_fd_prestat_get(fd, buf) } |
| +} |
| + |
| +#[inline] |
| +pub fn fd_prestat_dir_name(fd: Fd, path: &mut [u8]) -> Errno { |
| + unsafe { __wasi_fd_prestat_dir_name(fd, path.as_mut_ptr(), path.len()) } |
| +} |
| + |
| +// TODO: Safe interfaces to the args and environ functions |
| +/* |
| +pub fn args_get(argv: *mut *mut u8, argv_buf: *mut u8) -> Errno {} |
| +pub fn args_sizes_get(argc: *mut usize, argv_buf_size: *mut usize) -> Errno {} |
| +pub fn environ_get(environ: *mut *mut u8, environ_buf: *mut u8) -> Errno {} |
| +pub fn environ_sizes_get(environ_count: *mut usize, environ_buf_size: *mut usize) -> Errno {} |
| +*/ |
| diff --git a/src/wasi_unstable/mod.rs b/src/wasi_unstable/mod.rs |
| index 37bec24..893f59a 100644 |
| --- a/src/wasi_unstable/mod.rs |
| +++ b/src/wasi_unstable/mod.rs |
| @@ -1,241 +1,56 @@ |
| //! This module declares the Rust bindings to the `wasi_unstable` API. |
| //! |
| //! The raw bindings are in the `raw` submodule. They use raw pointers and |
| -//! are unsafe. In the the top-level module, raw pointer-length pairs are |
| -//! replaced by Rust slice types, output parameters are converted to normal |
| +//! are unsafe. Minimally safe versions which replace raw pointers with |
| +//! slices and references are in the `minimal_safe` module. |
| +//! |
| +//! In the the top-level module, output parameters are converted to normal |
| //! return values, names are translated to be more Rust-idiomatic, and the |
| //! functions are safe. |
| -//! |
| -//! TODO: Not all functions are covered yet; implement the rest of the API. |
| |
| +mod constants; |
| +mod types; |
| + |
| +pub mod minimal_safe; |
| pub mod raw; |
| |
| use core::ffi::c_void; |
| use core::mem::MaybeUninit; |
| use raw::*; |
| |
| -pub type Advice = __wasi_advice_t; |
| -pub type ClockId = __wasi_clockid_t; |
| -pub type Device = __wasi_device_t; |
| -pub type DirCookie = __wasi_dircookie_t; |
| -pub type Errno = __wasi_errno_t; |
| -pub type EventRwFlags = __wasi_eventrwflags_t; |
| -pub type EventType = __wasi_eventtype_t; |
| -pub type ExitCode = __wasi_exitcode_t; |
| -pub type Fd = __wasi_fd_t; |
| -pub type FdFlags = __wasi_fdflags_t; |
| -pub type FileDelta = __wasi_filedelta_t; |
| -pub type FileSize = __wasi_filesize_t; |
| -pub type FileType = __wasi_filetype_t; |
| -pub type FstFlags = __wasi_fstflags_t; |
| -pub type Inode = __wasi_inode_t; |
| -pub type LinkCount = __wasi_linkcount_t; |
| -pub type LookupFlags = __wasi_lookupflags_t; |
| -pub type OFlags = __wasi_oflags_t; |
| -pub type PreopenType = __wasi_preopentype_t; |
| -pub type RiFlags = __wasi_riflags_t; |
| -pub type Rights = __wasi_rights_t; |
| -pub type RoFlags = __wasi_roflags_t; |
| -pub type SdFlags = __wasi_sdflags_t; |
| -pub type SiFlags = __wasi_siflags_t; |
| -pub type Signal = __wasi_signal_t; |
| -pub type SubclockFlags = __wasi_subclockflags_t; |
| -pub type Timestamp = __wasi_timestamp_t; |
| -pub type Userdata = __wasi_userdata_t; |
| -pub type Whence = __wasi_whence_t; |
| -pub type Dirent = __wasi_dirent_t; |
| -pub type FdStat = __wasi_fdstat_t; |
| -pub type FileStat = __wasi_filestat_t; |
| -pub type CIoVec = __wasi_ciovec_t; |
| -pub type IoVec = __wasi_iovec_t; |
| -pub type Subscription = __wasi_subscription_t; |
| -pub type Event = __wasi_event_t; |
| -pub type Prestat = __wasi_prestat_t; |
| - |
| -pub const ADVICE_NORMAL: Advice = __WASI_ADVICE_NORMAL; |
| -pub const ADVICE_SEQUENTIAL: Advice = __WASI_ADVICE_SEQUENTIAL; |
| -pub const ADVICE_RANDOM: Advice = __WASI_ADVICE_RANDOM; |
| -pub const ADVICE_WILLNEED: Advice = __WASI_ADVICE_WILLNEED; |
| -pub const ADVICE_DONTNEED: Advice = __WASI_ADVICE_DONTNEED; |
| -pub const ADVICE_NOREUSE: Advice = __WASI_ADVICE_NOREUSE; |
| -pub const CLOCK_REALTIME: ClockId = __WASI_CLOCK_REALTIME; |
| -pub const CLOCK_MONOTONIC: ClockId = __WASI_CLOCK_MONOTONIC; |
| -pub const CLOCK_PROCESS_CPUTIME_ID: ClockId = __WASI_CLOCK_PROCESS_CPUTIME_ID; |
| -pub const CLOCK_THREAD_CPUTIME_ID: ClockId = __WASI_CLOCK_THREAD_CPUTIME_ID; |
| -pub const DIRCOOKIE_START: DirCookie = __WASI_DIRCOOKIE_START; |
| -pub const ESUCCESS: Errno = __WASI_ESUCCESS; |
| -pub const E2BIG: Errno = __WASI_E2BIG; |
| -pub const EACCES: Errno = __WASI_EACCES; |
| -pub const EADDRINUSE: Errno = __WASI_EADDRINUSE; |
| -pub const EADDRNOTAVAIL: Errno = __WASI_EADDRNOTAVAIL; |
| -pub const EAFNOSUPPORT: Errno = __WASI_EAFNOSUPPORT; |
| -pub const EAGAIN: Errno = __WASI_EAGAIN; |
| -pub const EALREADY: Errno = __WASI_EALREADY; |
| -pub const EBADF: Errno = __WASI_EBADF; |
| -pub const EBADMSG: Errno = __WASI_EBADMSG; |
| -pub const EBUSY: Errno = __WASI_EBUSY; |
| -pub const ECANCELED: Errno = __WASI_ECANCELED; |
| -pub const ECHILD: Errno = __WASI_ECHILD; |
| -pub const ECONNABORTED: Errno = __WASI_ECONNABORTED; |
| -pub const ECONNREFUSED: Errno = __WASI_ECONNREFUSED; |
| -pub const ECONNRESET: Errno = __WASI_ECONNRESET; |
| -pub const EDEADLK: Errno = __WASI_EDEADLK; |
| -pub const EDESTADDRREQ: Errno = __WASI_EDESTADDRREQ; |
| -pub const EDOM: Errno = __WASI_EDOM; |
| -pub const EDQUOT: Errno = __WASI_EDQUOT; |
| -pub const EEXIST: Errno = __WASI_EEXIST; |
| -pub const EFAULT: Errno = __WASI_EFAULT; |
| -pub const EFBIG: Errno = __WASI_EFBIG; |
| -pub const EHOSTUNREACH: Errno = __WASI_EHOSTUNREACH; |
| -pub const EIDRM: Errno = __WASI_EIDRM; |
| -pub const EILSEQ: Errno = __WASI_EILSEQ; |
| -pub const EINPROGRESS: Errno = __WASI_EINPROGRESS; |
| -pub const EINTR: Errno = __WASI_EINTR; |
| -pub const EINVAL: Errno = __WASI_EINVAL; |
| -pub const EIO: Errno = __WASI_EIO; |
| -pub const EISCONN: Errno = __WASI_EISCONN; |
| -pub const EISDIR: Errno = __WASI_EISDIR; |
| -pub const ELOOP: Errno = __WASI_ELOOP; |
| -pub const EMFILE: Errno = __WASI_EMFILE; |
| -pub const EMLINK: Errno = __WASI_EMLINK; |
| -pub const EMSGSIZE: Errno = __WASI_EMSGSIZE; |
| -pub const EMULTIHOP: Errno = __WASI_EMULTIHOP; |
| -pub const ENAMETOOLONG: Errno = __WASI_ENAMETOOLONG; |
| -pub const ENETDOWN: Errno = __WASI_ENETDOWN; |
| -pub const ENETRESET: Errno = __WASI_ENETRESET; |
| -pub const ENETUNREACH: Errno = __WASI_ENETUNREACH; |
| -pub const ENFILE: Errno = __WASI_ENFILE; |
| -pub const ENOBUFS: Errno = __WASI_ENOBUFS; |
| -pub const ENODEV: Errno = __WASI_ENODEV; |
| -pub const ENOENT: Errno = __WASI_ENOENT; |
| -pub const ENOEXEC: Errno = __WASI_ENOEXEC; |
| -pub const ENOLCK: Errno = __WASI_ENOLCK; |
| -pub const ENOLINK: Errno = __WASI_ENOLINK; |
| -pub const ENOMEM: Errno = __WASI_ENOMEM; |
| -pub const ENOMSG: Errno = __WASI_ENOMSG; |
| -pub const ENOPROTOOPT: Errno = __WASI_ENOPROTOOPT; |
| -pub const ENOSPC: Errno = __WASI_ENOSPC; |
| -pub const ENOSYS: Errno = __WASI_ENOSYS; |
| -pub const ENOTCONN: Errno = __WASI_ENOTCONN; |
| -pub const ENOTDIR: Errno = __WASI_ENOTDIR; |
| -pub const ENOTEMPTY: Errno = __WASI_ENOTEMPTY; |
| -pub const ENOTRECOVERABLE: Errno = __WASI_ENOTRECOVERABLE; |
| -pub const ENOTSOCK: Errno = __WASI_ENOTSOCK; |
| -pub const ENOTSUP: Errno = __WASI_ENOTSUP; |
| -pub const ENOTTY: Errno = __WASI_ENOTTY; |
| -pub const ENXIO: Errno = __WASI_ENXIO; |
| -pub const EOVERFLOW: Errno = __WASI_EOVERFLOW; |
| -pub const EOWNERDEAD: Errno = __WASI_EOWNERDEAD; |
| -pub const EPERM: Errno = __WASI_EPERM; |
| -pub const EPIPE: Errno = __WASI_EPIPE; |
| -pub const EPROTO: Errno = __WASI_EPROTO; |
| -pub const EPROTONOSUPPORT: Errno = __WASI_EPROTONOSUPPORT; |
| -pub const EPROTOTYPE: Errno = __WASI_EPROTOTYPE; |
| -pub const ERANGE: Errno = __WASI_ERANGE; |
| -pub const EROFS: Errno = __WASI_EROFS; |
| -pub const ESPIPE: Errno = __WASI_ESPIPE; |
| -pub const ESRCH: Errno = __WASI_ESRCH; |
| -pub const ESTALE: Errno = __WASI_ESTALE; |
| -pub const ETIMEDOUT: Errno = __WASI_ETIMEDOUT; |
| -pub const ETXTBSY: Errno = __WASI_ETXTBSY; |
| -pub const EXDEV: Errno = __WASI_EXDEV; |
| -pub const ENOTCAPABLE: Errno = __WASI_ENOTCAPABLE; |
| -pub const EVENT_FD_READWRITE_HANGUP: EventRwFlags = __WASI_EVENT_FD_READWRITE_HANGUP; |
| -pub const EVENTTYPE_CLOCK: EventType = __WASI_EVENTTYPE_CLOCK; |
| -pub const EVENTTYPE_FD_READ: EventType = __WASI_EVENTTYPE_FD_READ; |
| -pub const EVENTTYPE_FD_WRITE: EventType = __WASI_EVENTTYPE_FD_WRITE; |
| -pub const FDFLAG_APPEND: FdFlags = __WASI_FDFLAG_APPEND; |
| -pub const FDFLAG_DSYNC: FdFlags = __WASI_FDFLAG_DSYNC; |
| -pub const FDFLAG_NONBLOCK: FdFlags = __WASI_FDFLAG_NONBLOCK; |
| -pub const FDFLAG_RSYNC: FdFlags = __WASI_FDFLAG_RSYNC; |
| -pub const FDFLAG_SYNC: FdFlags = __WASI_FDFLAG_SYNC; |
| -pub const FILETYPE_UNKNOWN: FileType = __WASI_FILETYPE_UNKNOWN; |
| -pub const FILETYPE_BLOCK_DEVICE: FileType = __WASI_FILETYPE_BLOCK_DEVICE; |
| -pub const FILETYPE_CHARACTER_DEVICE: FileType = __WASI_FILETYPE_CHARACTER_DEVICE; |
| -pub const FILETYPE_DIRECTORY: FileType = __WASI_FILETYPE_DIRECTORY; |
| -pub const FILETYPE_REGULAR_FILE: FileType = __WASI_FILETYPE_REGULAR_FILE; |
| -pub const FILETYPE_SOCKET_DGRAM: FileType = __WASI_FILETYPE_SOCKET_DGRAM; |
| -pub const FILETYPE_SOCKET_STREAM: FileType = __WASI_FILETYPE_SOCKET_STREAM; |
| -pub const FILETYPE_SYMBOLIC_LINK: FileType = __WASI_FILETYPE_SYMBOLIC_LINK; |
| -pub const FILESTAT_SET_ATIM: FstFlags = __WASI_FILESTAT_SET_ATIM; |
| -pub const FILESTAT_SET_ATIM_NOW: FstFlags = __WASI_FILESTAT_SET_ATIM_NOW; |
| -pub const FILESTAT_SET_MTIM: FstFlags = __WASI_FILESTAT_SET_MTIM; |
| -pub const FILESTAT_SET_MTIM_NOW: FstFlags = __WASI_FILESTAT_SET_MTIM_NOW; |
| -pub const LOOKUP_SYMLINK_FOLLOW: LookupFlags = __WASI_LOOKUP_SYMLINK_FOLLOW; |
| -pub const O_CREAT: OFlags = __WASI_O_CREAT; |
| -pub const O_DIRECTORY: OFlags = __WASI_O_DIRECTORY; |
| -pub const O_EXCL: OFlags = __WASI_O_EXCL; |
| -pub const O_TRUNC: OFlags = __WASI_O_TRUNC; |
| -pub const PREOPENTYPE_DIR: PreopenType = __WASI_PREOPENTYPE_DIR; |
| -pub const SOCK_RECV_PEEK: RiFlags = __WASI_SOCK_RECV_PEEK; |
| -pub const SOCK_RECV_WAITALL: RiFlags = __WASI_SOCK_RECV_WAITALL; |
| -pub const RIGHT_FD_DATASYNC: Rights = __WASI_RIGHT_FD_DATASYNC; |
| -pub const RIGHT_FD_READ: Rights = __WASI_RIGHT_FD_READ; |
| -pub const RIGHT_FD_SEEK: Rights = __WASI_RIGHT_FD_SEEK; |
| -pub const RIGHT_FD_FDSTAT_SET_FLAGS: Rights = __WASI_RIGHT_FD_FDSTAT_SET_FLAGS; |
| -pub const RIGHT_FD_SYNC: Rights = __WASI_RIGHT_FD_SYNC; |
| -pub const RIGHT_FD_TELL: Rights = __WASI_RIGHT_FD_TELL; |
| -pub const RIGHT_FD_WRITE: Rights = __WASI_RIGHT_FD_WRITE; |
| -pub const RIGHT_FD_ADVISE: Rights = __WASI_RIGHT_FD_ADVISE; |
| -pub const RIGHT_FD_ALLOCATE: Rights = __WASI_RIGHT_FD_ALLOCATE; |
| -pub const RIGHT_PATH_CREATE_DIRECTORY: Rights = __WASI_RIGHT_PATH_CREATE_DIRECTORY; |
| -pub const RIGHT_PATH_CREATE_FILE: Rights = __WASI_RIGHT_PATH_CREATE_FILE; |
| -pub const RIGHT_PATH_LINK_SOURCE: Rights = __WASI_RIGHT_PATH_LINK_SOURCE; |
| -pub const RIGHT_PATH_LINK_TARGET: Rights = __WASI_RIGHT_PATH_LINK_TARGET; |
| -pub const RIGHT_PATH_OPEN: Rights = __WASI_RIGHT_PATH_OPEN; |
| -pub const RIGHT_FD_READDIR: Rights = __WASI_RIGHT_FD_READDIR; |
| -pub const RIGHT_PATH_READLINK: Rights = __WASI_RIGHT_PATH_READLINK; |
| -pub const RIGHT_PATH_RENAME_SOURCE: Rights = __WASI_RIGHT_PATH_RENAME_SOURCE; |
| -pub const RIGHT_PATH_RENAME_TARGET: Rights = __WASI_RIGHT_PATH_RENAME_TARGET; |
| -pub const RIGHT_PATH_FILESTAT_GET: Rights = __WASI_RIGHT_PATH_FILESTAT_GET; |
| -pub const RIGHT_PATH_FILESTAT_SET_SIZE: Rights = __WASI_RIGHT_PATH_FILESTAT_SET_SIZE; |
| -pub const RIGHT_PATH_FILESTAT_SET_TIMES: Rights = __WASI_RIGHT_PATH_FILESTAT_SET_TIMES; |
| -pub const RIGHT_FD_FILESTAT_GET: Rights = __WASI_RIGHT_FD_FILESTAT_GET; |
| -pub const RIGHT_FD_FILESTAT_SET_SIZE: Rights = __WASI_RIGHT_FD_FILESTAT_SET_SIZE; |
| -pub const RIGHT_FD_FILESTAT_SET_TIMES: Rights = __WASI_RIGHT_FD_FILESTAT_SET_TIMES; |
| -pub const RIGHT_PATH_SYMLINK: Rights = __WASI_RIGHT_PATH_SYMLINK; |
| -pub const RIGHT_PATH_REMOVE_DIRECTORY: Rights = __WASI_RIGHT_PATH_REMOVE_DIRECTORY; |
| -pub const RIGHT_PATH_UNLINK_FILE: Rights = __WASI_RIGHT_PATH_UNLINK_FILE; |
| -pub const RIGHT_POLL_FD_READWRITE: Rights = __WASI_RIGHT_POLL_FD_READWRITE; |
| -pub const RIGHT_SOCK_SHUTDOWN: Rights = __WASI_RIGHT_SOCK_SHUTDOWN; |
| -pub const SOCK_RECV_DATA_TRUNCATED: RoFlags = __WASI_SOCK_RECV_DATA_TRUNCATED; |
| -pub const SHUT_RD: SdFlags = __WASI_SHUT_RD; |
| -pub const SHUT_WR: SdFlags = __WASI_SHUT_WR; |
| -pub const SIGHUP: Signal = __WASI_SIGHUP; |
| -pub const SIGINT: Signal = __WASI_SIGINT; |
| -pub const SIGQUIT: Signal = __WASI_SIGQUIT; |
| -pub const SIGILL: Signal = __WASI_SIGILL; |
| -pub const SIGTRAP: Signal = __WASI_SIGTRAP; |
| -pub const SIGABRT: Signal = __WASI_SIGABRT; |
| -pub const SIGBUS: Signal = __WASI_SIGBUS; |
| -pub const SIGFPE: Signal = __WASI_SIGFPE; |
| -pub const SIGKILL: Signal = __WASI_SIGKILL; |
| -pub const SIGUSR1: Signal = __WASI_SIGUSR1; |
| -pub const SIGSEGV: Signal = __WASI_SIGSEGV; |
| -pub const SIGUSR2: Signal = __WASI_SIGUSR2; |
| -pub const SIGPIPE: Signal = __WASI_SIGPIPE; |
| -pub const SIGALRM: Signal = __WASI_SIGALRM; |
| -pub const SIGTERM: Signal = __WASI_SIGTERM; |
| -pub const SIGCHLD: Signal = __WASI_SIGCHLD; |
| -pub const SIGCONT: Signal = __WASI_SIGCONT; |
| -pub const SIGSTOP: Signal = __WASI_SIGSTOP; |
| -pub const SIGTSTP: Signal = __WASI_SIGTSTP; |
| -pub const SIGTTIN: Signal = __WASI_SIGTTIN; |
| -pub const SIGTTOU: Signal = __WASI_SIGTTOU; |
| -pub const SIGURG: Signal = __WASI_SIGURG; |
| -pub const SIGXCPU: Signal = __WASI_SIGXCPU; |
| -pub const SIGXFSZ: Signal = __WASI_SIGXFSZ; |
| -pub const SIGVTALRM: Signal = __WASI_SIGVTALRM; |
| -pub const SIGPROF: Signal = __WASI_SIGPROF; |
| -pub const SIGWINCH: Signal = __WASI_SIGWINCH; |
| -pub const SIGPOLL: Signal = __WASI_SIGPOLL; |
| -pub const SIGPWR: Signal = __WASI_SIGPWR; |
| -pub const SIGSYS: Signal = __WASI_SIGSYS; |
| -pub const SUBSCRIPTION_CLOCK_ABSTIME: SubclockFlags = __WASI_SUBSCRIPTION_CLOCK_ABSTIME; |
| -pub const WHENCE_CUR: Whence = __WASI_WHENCE_CUR; |
| -pub const WHENCE_END: Whence = __WASI_WHENCE_END; |
| -pub const WHENCE_SET: Whence = __WASI_WHENCE_SET; |
| - |
| +pub use constants::*; |
| +pub use types::*; |
| + |
| +// These are for WASI functions which don't use output parameters, so we can |
| +// just export the minimal_safe versions. |
| +pub use minimal_safe::fd_advise; |
| +pub use minimal_safe::fd_allocate; |
| +pub use minimal_safe::fd_close; |
| +pub use minimal_safe::fd_datasync; |
| +pub use minimal_safe::fd_fdstat_set_flags; |
| +pub use minimal_safe::fd_fdstat_set_rights; |
| +pub use minimal_safe::fd_filestat_set_size; |
| +pub use minimal_safe::fd_filestat_set_times; |
| +pub use minimal_safe::fd_prestat_dir_name; |
| +pub use minimal_safe::fd_renumber; |
| +pub use minimal_safe::fd_sync; |
| +pub use minimal_safe::path_create_directory; |
| +pub use minimal_safe::path_filestat_set_times; |
| +pub use minimal_safe::path_link; |
| +pub use minimal_safe::path_remove_directory; |
| +pub use minimal_safe::path_rename; |
| +pub use minimal_safe::path_symlink; |
| +pub use minimal_safe::path_unlink_file; |
| +pub use minimal_safe::proc_exit; |
| +pub use minimal_safe::proc_raise; |
| +pub use minimal_safe::random_get; |
| +pub use minimal_safe::sched_yield; |
| +pub use minimal_safe::sock_shutdown; |
| + |
| +// The following are for WASI functions which do use output parameters. We |
| +// wrap them separately to avoid creating references to uninitialized data. |
| + |
| +#[inline] |
| pub fn clock_res_get(clock_id: ClockId) -> (Errno, Timestamp) { |
| let mut resolution = MaybeUninit::<Timestamp>::uninit(); |
| unsafe { |
| @@ -246,6 +61,7 @@ pub fn clock_res_get(clock_id: ClockId) -> (Errno, Timestamp) { |
| } |
| } |
| |
| +#[inline] |
| pub fn clock_time_get(clock_id: ClockId, precision: Timestamp) -> (Errno, Timestamp) { |
| let mut time = MaybeUninit::<Timestamp>::uninit(); |
| unsafe { |
| @@ -256,6 +72,7 @@ pub fn clock_time_get(clock_id: ClockId, precision: Timestamp) -> (Errno, Timest |
| } |
| } |
| |
| +#[inline] |
| pub fn fd_pread(fd: Fd, iovs: &[IoVec], offset: FileSize) -> (Errno, usize) { |
| let mut nread = MaybeUninit::<usize>::uninit(); |
| unsafe { |
| @@ -266,6 +83,7 @@ pub fn fd_pread(fd: Fd, iovs: &[IoVec], offset: FileSize) -> (Errno, usize) { |
| } |
| } |
| |
| +#[inline] |
| pub fn fd_pwrite(fd: Fd, iovs: &[CIoVec], offset: FileSize) -> (Errno, usize) { |
| let mut nwritten = MaybeUninit::<usize>::uninit(); |
| unsafe { |
| @@ -276,18 +94,7 @@ pub fn fd_pwrite(fd: Fd, iovs: &[CIoVec], offset: FileSize) -> (Errno, usize) { |
| } |
| } |
| |
| -pub fn random_get(buf: &mut [u8]) -> Errno { |
| - unsafe { __wasi_random_get(buf.as_mut_ptr() as *mut c_void, buf.len()) } |
| -} |
| - |
| -pub fn fd_close(fd: Fd) -> Errno { |
| - unsafe { __wasi_fd_close(fd) } |
| -} |
| - |
| -pub fn fd_datasync(fd: Fd) -> Errno { |
| - unsafe { __wasi_fd_datasync(fd) } |
| -} |
| - |
| +#[inline] |
| pub fn fd_read(fd: Fd, iovs: &[IoVec]) -> (Errno, usize) { |
| let mut nread = MaybeUninit::<usize>::uninit(); |
| unsafe { |
| @@ -298,10 +105,7 @@ pub fn fd_read(fd: Fd, iovs: &[IoVec]) -> (Errno, usize) { |
| } |
| } |
| |
| -pub fn fd_renumber(from: Fd, to: Fd) -> Errno { |
| - unsafe { __wasi_fd_renumber(from, to) } |
| -} |
| - |
| +#[inline] |
| pub fn fd_seek(fd: Fd, offset: FileDelta, whence: Whence) -> (Errno, FileSize) { |
| let mut newoffset = MaybeUninit::<FileSize>::uninit(); |
| unsafe { |
| @@ -312,6 +116,7 @@ pub fn fd_seek(fd: Fd, offset: FileDelta, whence: Whence) -> (Errno, FileSize) { |
| } |
| } |
| |
| +#[inline] |
| pub fn fd_tell(fd: Fd) -> (Errno, FileSize) { |
| let mut newoffset = MaybeUninit::<FileSize>::uninit(); |
| unsafe { |
| @@ -322,6 +127,7 @@ pub fn fd_tell(fd: Fd) -> (Errno, FileSize) { |
| } |
| } |
| |
| +#[inline] |
| pub fn fd_fdstat_get(fd: Fd) -> (Errno, FdStat) { |
| let mut buf = MaybeUninit::<FdStat>::uninit(); |
| unsafe { |
| @@ -332,18 +138,7 @@ pub fn fd_fdstat_get(fd: Fd) -> (Errno, FdStat) { |
| } |
| } |
| |
| -pub fn fd_fdstat_set_flags(fd: Fd, flags: FdFlags) -> Errno { |
| - unsafe { __wasi_fd_fdstat_set_flags(fd, flags) } |
| -} |
| - |
| -pub fn fd_fdstat_set_rights(fd: Fd, fs_rights_base: Rights, fs_rights_inheriting: Rights) -> Errno { |
| - unsafe { __wasi_fd_fdstat_set_rights(fd, fs_rights_base, fs_rights_inheriting) } |
| -} |
| - |
| -pub fn fd_sync(fd: Fd) -> Errno { |
| - unsafe { __wasi_fd_sync(fd) } |
| -} |
| - |
| +#[inline] |
| pub fn fd_write(fd: Fd, iovs: &[CIoVec]) -> (Errno, usize) { |
| let mut nwritten = MaybeUninit::<usize>::uninit(); |
| unsafe { |
| @@ -354,38 +149,7 @@ pub fn fd_write(fd: Fd, iovs: &[CIoVec]) -> (Errno, usize) { |
| } |
| } |
| |
| -pub fn fd_advise(fd: Fd, offset: FileSize, len: FileSize, advice: Advice) -> Errno { |
| - unsafe { __wasi_fd_advise(fd, offset, len, advice) } |
| -} |
| - |
| -pub fn fd_allocate(fd: Fd, offset: FileSize, len: FileSize) -> Errno { |
| - unsafe { __wasi_fd_allocate(fd, offset, len) } |
| -} |
| - |
| -pub fn path_create_directory(fd: Fd, path: &[u8]) -> Errno { |
| - unsafe { __wasi_path_create_directory(fd, path.as_ptr(), path.len()) } |
| -} |
| - |
| -pub fn path_link( |
| - old_fd: Fd, |
| - old_flags: LookupFlags, |
| - old_path: &[u8], |
| - new_fd: Fd, |
| - new_path: &[u8], |
| -) -> Errno { |
| - unsafe { |
| - __wasi_path_link( |
| - old_fd, |
| - old_flags, |
| - old_path.as_ptr(), |
| - old_path.len(), |
| - new_fd, |
| - new_path.as_ptr(), |
| - new_path.len(), |
| - ) |
| - } |
| -} |
| - |
| +#[inline] |
| pub fn path_open( |
| dirfd: Fd, |
| dirflags: LookupFlags, |
| @@ -414,6 +178,7 @@ pub fn path_open( |
| } |
| } |
| |
| +#[inline] |
| pub fn fd_readdir(fd: Fd, buf: &mut [u8], cookie: DirCookie) -> (Errno, usize) { |
| let mut bufused = MaybeUninit::<usize>::uninit(); |
| unsafe { |
| @@ -430,6 +195,7 @@ pub fn fd_readdir(fd: Fd, buf: &mut [u8], cookie: DirCookie) -> (Errno, usize) { |
| } |
| } |
| |
| +#[inline] |
| pub fn path_readlink(fd: Fd, path: &[u8], buf: &mut [u8]) -> (Errno, usize) { |
| let mut bufused = MaybeUninit::<usize>::uninit(); |
| unsafe { |
| @@ -447,19 +213,7 @@ pub fn path_readlink(fd: Fd, path: &[u8], buf: &mut [u8]) -> (Errno, usize) { |
| } |
| } |
| |
| -pub fn path_rename(old_fd: Fd, old_path: &[u8], new_fd: Fd, new_path: &[u8]) -> Errno { |
| - unsafe { |
| - __wasi_path_rename( |
| - old_fd, |
| - old_path.as_ptr(), |
| - old_path.len(), |
| - new_fd, |
| - new_path.as_ptr(), |
| - new_path.len(), |
| - ) |
| - } |
| -} |
| - |
| +#[inline] |
| pub fn fd_filestat_get(fd: Fd) -> (Errno, FileStat) { |
| let mut buf = MaybeUninit::<FileStat>::uninit(); |
| unsafe { |
| @@ -470,19 +224,7 @@ pub fn fd_filestat_get(fd: Fd) -> (Errno, FileStat) { |
| } |
| } |
| |
| -pub fn fd_filestat_set_times( |
| - fd: Fd, |
| - st_atim: Timestamp, |
| - st_mtim: Timestamp, |
| - fstflags: FstFlags, |
| -) -> Errno { |
| - unsafe { __wasi_fd_filestat_set_times(fd, st_atim, st_mtim, fstflags) } |
| -} |
| - |
| -pub fn fd_filestat_set_size(fd: Fd, st_size: FileSize) -> Errno { |
| - unsafe { __wasi_fd_filestat_set_size(fd, st_size) } |
| -} |
| - |
| +#[inline] |
| pub fn path_filestat_get(fd: Fd, flags: LookupFlags, path: &[u8]) -> (Errno, FileStat) { |
| let mut buf = MaybeUninit::<FileStat>::uninit(); |
| unsafe { |
| @@ -493,47 +235,7 @@ pub fn path_filestat_get(fd: Fd, flags: LookupFlags, path: &[u8]) -> (Errno, Fil |
| } |
| } |
| |
| -pub fn path_filestat_set_times( |
| - fd: Fd, |
| - flags: LookupFlags, |
| - path: &[u8], |
| - st_atim: Timestamp, |
| - st_mtim: Timestamp, |
| - fstflags: FstFlags, |
| -) -> Errno { |
| - unsafe { |
| - __wasi_path_filestat_set_times( |
| - fd, |
| - flags, |
| - path.as_ptr(), |
| - path.len(), |
| - st_atim, |
| - st_mtim, |
| - fstflags, |
| - ) |
| - } |
| -} |
| - |
| -pub fn path_symlink(old_path: &[u8], fd: Fd, new_path: &[u8]) -> Errno { |
| - unsafe { |
| - __wasi_path_symlink( |
| - old_path.as_ptr(), |
| - old_path.len(), |
| - fd, |
| - new_path.as_ptr(), |
| - new_path.len(), |
| - ) |
| - } |
| -} |
| - |
| -pub fn path_unlink_file(fd: Fd, path: &[u8]) -> Errno { |
| - unsafe { __wasi_path_unlink_file(fd, path.as_ptr(), path.len()) } |
| -} |
| - |
| -pub fn path_remove_directory(fd: Fd, path: &[u8]) -> Errno { |
| - unsafe { __wasi_path_remove_directory(fd, path.as_ptr(), path.len()) } |
| -} |
| - |
| +#[inline] |
| pub fn poll_oneoff(in_: &[Subscription], out: &mut [Event]) -> (Errno, usize) { |
| assert!(out.len() >= in_.len()); |
| let mut nevents = MaybeUninit::<usize>::uninit(); |
| @@ -550,14 +252,7 @@ pub fn poll_oneoff(in_: &[Subscription], out: &mut [Event]) -> (Errno, usize) { |
| } |
| } |
| |
| -pub fn proc_exit(rval: ExitCode) { |
| - unsafe { __wasi_proc_exit(rval) } |
| -} |
| - |
| -pub fn proc_raise(sig: Signal) -> Errno { |
| - unsafe { __wasi_proc_raise(sig) } |
| -} |
| - |
| +#[inline] |
| pub fn sock_recv(sock: Fd, ri_data: &[IoVec], ri_flags: RiFlags) -> (Errno, usize, RoFlags) { |
| let mut ro_datalen = MaybeUninit::<usize>::uninit(); |
| let mut ro_flags = MaybeUninit::<RoFlags>::uninit(); |
| @@ -577,6 +272,7 @@ pub fn sock_recv(sock: Fd, ri_data: &[IoVec], ri_flags: RiFlags) -> (Errno, usiz |
| } |
| } |
| |
| +#[inline] |
| pub fn sock_send(sock: Fd, si_data: &[CIoVec], si_flags: SiFlags) -> (Errno, usize) { |
| let mut so_datalen = MaybeUninit::<usize>::uninit(); |
| unsafe { |
| @@ -593,14 +289,7 @@ pub fn sock_send(sock: Fd, si_data: &[CIoVec], si_flags: SiFlags) -> (Errno, usi |
| } |
| } |
| |
| -pub fn sock_shutdown(sock: Fd, how: SdFlags) -> Errno { |
| - unsafe { __wasi_sock_shutdown(sock, how) } |
| -} |
| - |
| -pub fn sched_yield() -> Errno { |
| - unsafe { __wasi_sched_yield() } |
| -} |
| - |
| +#[inline] |
| pub fn fd_prestat_get(fd: Fd) -> (Errno, Prestat) { |
| let mut buf = MaybeUninit::<Prestat>::uninit(); |
| unsafe { |
| @@ -611,10 +300,6 @@ pub fn fd_prestat_get(fd: Fd) -> (Errno, Prestat) { |
| } |
| } |
| |
| -pub fn fd_prestat_dir_name(fd: Fd, path: &mut [u8]) -> Errno { |
| - unsafe { __wasi_fd_prestat_dir_name(fd, path.as_mut_ptr(), path.len()) } |
| -} |
| - |
| // TODO: Safe interfaces to the args and environ functions |
| /* |
| pub fn args_get(argv: *mut *mut u8, argv_buf: *mut u8) -> Errno {} |
| diff --git a/src/wasi_unstable/types.rs b/src/wasi_unstable/types.rs |
| new file mode 100644 |
| index 0000000..dd744c9 |
| --- /dev/null |
| +++ b/src/wasi_unstable/types.rs |
| @@ -0,0 +1,41 @@ |
| +//! This file defines idiomatic Rust names for types. |
| + |
| +use crate::wasi_unstable::raw::*; |
| + |
| +pub type Advice = __wasi_advice_t; |
| +pub type ClockId = __wasi_clockid_t; |
| +pub type Device = __wasi_device_t; |
| +pub type DirCookie = __wasi_dircookie_t; |
| +pub type Errno = __wasi_errno_t; |
| +pub type EventRwFlags = __wasi_eventrwflags_t; |
| +pub type EventType = __wasi_eventtype_t; |
| +pub type ExitCode = __wasi_exitcode_t; |
| +pub type Fd = __wasi_fd_t; |
| +pub type FdFlags = __wasi_fdflags_t; |
| +pub type FileDelta = __wasi_filedelta_t; |
| +pub type FileSize = __wasi_filesize_t; |
| +pub type FileType = __wasi_filetype_t; |
| +pub type FstFlags = __wasi_fstflags_t; |
| +pub type Inode = __wasi_inode_t; |
| +pub type LinkCount = __wasi_linkcount_t; |
| +pub type LookupFlags = __wasi_lookupflags_t; |
| +pub type OFlags = __wasi_oflags_t; |
| +pub type PreopenType = __wasi_preopentype_t; |
| +pub type RiFlags = __wasi_riflags_t; |
| +pub type Rights = __wasi_rights_t; |
| +pub type RoFlags = __wasi_roflags_t; |
| +pub type SdFlags = __wasi_sdflags_t; |
| +pub type SiFlags = __wasi_siflags_t; |
| +pub type Signal = __wasi_signal_t; |
| +pub type SubclockFlags = __wasi_subclockflags_t; |
| +pub type Timestamp = __wasi_timestamp_t; |
| +pub type Userdata = __wasi_userdata_t; |
| +pub type Whence = __wasi_whence_t; |
| +pub type Dirent = __wasi_dirent_t; |
| +pub type FdStat = __wasi_fdstat_t; |
| +pub type FileStat = __wasi_filestat_t; |
| +pub type CIoVec = __wasi_ciovec_t; |
| +pub type IoVec = __wasi_iovec_t; |
| +pub type Subscription = __wasi_subscription_t; |
| +pub type Event = __wasi_event_t; |
| +pub type Prestat = __wasi_prestat_t; |
| -- |
| 2.17.1 |
| |