[][src]Trait wasihost_core::wasi_snapshot_preview1::WasiImports

pub trait WasiImports: Send + Sync + 'static {
    type StringRepresentation: StringRepresentation;
    fn args_get(&self) -> WasiResult<&[Self::StringRepresentation]>;
fn environ_get(&self) -> WasiResult<&[Self::StringRepresentation]>;
fn clock_res_get(&self, id: Clockid) -> WasiResult<Timestamp>;
fn clock_time_get(
        &self,
        id: Clockid,
        precision: Timestamp
    ) -> WasiResult<Timestamp>;
fn fd_advise(
        &self,
        fd: Fd,
        offset: Filesize,
        len: Filesize,
        advice: Advice
    ) -> WasiResult<()>;
fn fd_allocate(
        &self,
        fd: Fd,
        offset: Filesize,
        len: Filesize
    ) -> WasiResult<()>;
fn fd_close(&self, fd: Fd) -> WasiResult<()>;
fn fd_datasync(&self, fd: Fd) -> WasiResult<()>;
fn fd_fdstat_get(&self, fd: Fd) -> WasiResult<Fdstat>;
fn fd_fdstat_set_flags(&self, fd: Fd, flags: Fdflags) -> WasiResult<()>;
fn fd_fdstat_set_rights(
        &self,
        fd: Fd,
        fs_rights_base: Rights,
        fs_rights_inheriting: Rights
    ) -> WasiResult<()>;
fn fd_filestat_get(&self, fd: Fd) -> WasiResult<Filestat>;
fn fd_filestat_set_size(&self, fd: Fd, size: Filesize) -> WasiResult<()>;
fn fd_filestat_set_times(
        &self,
        fd: Fd,
        atim: Timestamp,
        mtim: Timestamp,
        fst_flags: Fstflags
    ) -> WasiResult<()>;
fn fd_pread(
        &self,
        fd: Fd,
        iovs: &mut [IoSliceMut],
        offset: Filesize
    ) -> WasiResult<Size>;
fn fd_prestat_get(&self, fd: Fd) -> WasiResult<Prestat>;
fn fd_prestat_dir_name(
        &self,
        fd: Fd
    ) -> WasiResult<Self::StringRepresentation>;
fn fd_pwrite(
        &self,
        fd: Fd,
        bufs: &[IoSlice],
        offset: Filesize
    ) -> WasiResult<Size>;
fn fd_read(&self, fd: Fd, iovs: &mut [IoSliceMut]) -> WasiResult<Size>;
fn fd_readdir(
        &self,
        fd: Fd,
        cookie: Dircookie
    ) -> WasiResult<Option<(Dirent, Self::StringRepresentation)>>;
fn fd_renumber(&self, fd: Fd, to: Fd) -> WasiResult<()>;
fn fd_seek(
        &self,
        fd: Fd,
        offset: Filedelta,
        whence: Whence
    ) -> WasiResult<Filesize>;
fn fd_sync(&self, fd: Fd) -> WasiResult<()>;
fn fd_tell(&self, fd: Fd) -> WasiResult<Filesize>;
fn fd_write(&self, fd: Fd, bufs: &[IoSlice]) -> WasiResult<Size>;
fn path_create_directory(
        &self,
        fd: Fd,
        path: &<Self::StringRepresentation as Deref>::Target
    ) -> WasiResult<()>;
fn path_filestat_get(
        &self,
        fd: Fd,
        flags: Lookupflags,
        path: &<Self::StringRepresentation as Deref>::Target
    ) -> WasiResult<Filestat>;
fn path_filestat_set_times(
        &self,
        fd: Fd,
        flags: Lookupflags,
        path: &<Self::StringRepresentation as Deref>::Target,
        atim: Timestamp,
        mtim: Timestamp,
        fst_flags: Fstflags
    ) -> WasiResult<()>;
fn path_link(
        &self,
        old_fd: Fd,
        old_flags: Lookupflags,
        old_path: &<Self::StringRepresentation as Deref>::Target,
        new_fd: Fd,
        new_path: &<Self::StringRepresentation as Deref>::Target
    ) -> WasiResult<()>;
fn path_open(
        &self,
        fd: Fd,
        dirflags: Lookupflags,
        path: &<Self::StringRepresentation as Deref>::Target,
        oflags: Oflags,
        fs_rights_base: Rights,
        fs_rights_inheriting: Rights,
        fdflags: Fdflags
    ) -> WasiResult<Fd>;
fn path_readlink(
        &self,
        fd: Fd,
        path: &<Self::StringRepresentation as Deref>::Target
    ) -> WasiResult<Self::StringRepresentation>;
fn path_remove_directory(
        &self,
        fd: Fd,
        path: &<Self::StringRepresentation as Deref>::Target
    ) -> WasiResult<()>;
fn path_rename(
        &self,
        fd: Fd,
        old_path: &<Self::StringRepresentation as Deref>::Target,
        new_fd: Fd,
        new_path: &<Self::StringRepresentation as Deref>::Target
    ) -> WasiResult<()>;
fn path_symlink(
        &self,
        old_path: &<Self::StringRepresentation as Deref>::Target,
        fd: Fd,
        new_path: &<Self::StringRepresentation as Deref>::Target
    ) -> WasiResult<()>;
fn path_unlink_file(
        &self,
        fd: Fd,
        path: &<Self::StringRepresentation as Deref>::Target
    ) -> WasiResult<()>;
fn poll_oneoff(
        &self,
        subscriptions: &[Subscription]
    ) -> WasiResult<Vec<Event>>;
fn proc_exit(&self, rval: Exitcode) -> Result<Infallible, Exitcode>;
fn proc_raise(&self, sig: Signal) -> WasiResult<()>;
fn random_get(&self, buf: &mut [u8]) -> WasiResult<()>;
fn sched_yield(&self) -> WasiResult<()>;
fn sock_recv(
        &self,
        fd: Fd,
        ri_data: &mut [IoSliceMut],
        ri_flags: Riflags
    ) -> WasiResult<(Size, Roflags)>;
fn sock_send(
        &self,
        fd: Fd,
        si_data: &[IoSlice],
        si_flags: Siflags
    ) -> WasiResult<Size>;
fn sock_shutdown(&self, fd: Fd, how: Sdflags) -> WasiResult<()>; }

Functions necessary to satisfy the WASI specification.

Associated Types

type StringRepresentation: StringRepresentation

String representation in the high-level APIs.

Loading content...

Required methods

fn args_get(&self) -> WasiResult<&[Self::StringRepresentation]>

Gets the command-line parameters.

fn environ_get(&self) -> WasiResult<&[Self::StringRepresentation]>

Gets the environment. Is is common convention that each string is of the form key=value.

fn clock_res_get(&self, id: Clockid) -> WasiResult<Timestamp>

Return the resolution of a clock. Implementations are required to provide a non-zero value for supported clocks. For unsupported clocks, return Err(Errno::Inval).

Note: This is similar to clock_getres in POSIX.

fn clock_time_get(
    &self,
    id: Clockid,
    precision: Timestamp
) -> WasiResult<Timestamp>

Return the time value of a clock.

Note: This is similar to clock_gettime in POSIX.

fn fd_advise(
    &self,
    fd: Fd,
    offset: Filesize,
    len: Filesize,
    advice: Advice
) -> WasiResult<()>

Provide file advisory information on a file descriptor.

Note: This is similar to posix_fadvise in POSIX.

fn fd_allocate(&self, fd: Fd, offset: Filesize, len: Filesize) -> WasiResult<()>

Force the allocation of space in a file.

Note: This is similar to posix_fallocate in POSIX.

fn fd_close(&self, fd: Fd) -> WasiResult<()>

Close a file descriptor.

Note: This is similar to close in POSIX.

fn fd_datasync(&self, fd: Fd) -> WasiResult<()>

Synchronize the data of a file to disk.

Note: This is similar to fdatasync in POSIX.

fn fd_fdstat_get(&self, fd: Fd) -> WasiResult<Fdstat>

Get the attributes of a file descriptor.

Note: This returns similar flags to fsync(fd, F_GETFL) in POSIX, as well as additional fields.

fn fd_fdstat_set_flags(&self, fd: Fd, flags: Fdflags) -> WasiResult<()>

Adjust the flags associated with a file descriptor.

Note: This is similar to fcntl(fd, F_SETFL, flags) in POSIX.

fn fd_fdstat_set_rights(
    &self,
    fd: Fd,
    fs_rights_base: Rights,
    fs_rights_inheriting: Rights
) -> WasiResult<()>

Adjust the rights associated with a file descriptor. This can only be used to remove rights, and returns Err(Errno::Notcapable) if called in a way that would attempt to add rights.

fn fd_filestat_get(&self, fd: Fd) -> WasiResult<Filestat>

Return the attributes of an open file.

fn fd_filestat_set_size(&self, fd: Fd, size: Filesize) -> WasiResult<()>

Adjust the size of an open file. If this increases the file's size, the extra bytes are filled with zeros.

Note: This is similar to ftruncate in POSIX.

fn fd_filestat_set_times(
    &self,
    fd: Fd,
    atim: Timestamp,
    mtim: Timestamp,
    fst_flags: Fstflags
) -> WasiResult<()>

Adjust the timestamps of an open file or directory.

Note: This is similar to futimens in POSIX.

fn fd_pread(
    &self,
    fd: Fd,
    iovs: &mut [IoSliceMut],
    offset: Filesize
) -> WasiResult<Size>

Read from a file descriptor, without using and updating the file descriptor's offset.

Note: This is similar to preadv in POSIX.

fn fd_prestat_get(&self, fd: Fd) -> WasiResult<Prestat>

Return a description of the given preopened file descriptor.

fn fd_prestat_dir_name(&self, fd: Fd) -> WasiResult<Self::StringRepresentation>

Return the directory name of the given preopened file descriptor.

fn fd_pwrite(
    &self,
    fd: Fd,
    bufs: &[IoSlice],
    offset: Filesize
) -> WasiResult<Size>

Write to a file descriptor, without using and updating the file descriptor's offset.

Note: This is similar to pwritev in POSIX.

fn fd_read(&self, fd: Fd, iovs: &mut [IoSliceMut]) -> WasiResult<Size>

Read from a file descriptor.

Note: This is similar to readv in POSIX.

fn fd_readdir(
    &self,
    fd: Fd,
    cookie: Dircookie
) -> WasiResult<Option<(Dirent, Self::StringRepresentation)>>

Read one directory entry from a directory.

The cookie of first entry in a directory is always Dircookie(0).

fn fd_renumber(&self, fd: Fd, to: Fd) -> WasiResult<()>

Atomically replace a file descriptor by renumbering another file descriptor. Due to the strong focus on thread safety, this environment does not provide a mechanism to duplicate or renumber a file descriptor to an arbitrary number, like dup2(). This would be prone to race conditions, as an actual file descriptor with the same number could be allocated by a different thread at the same time.

fn fd_seek(
    &self,
    fd: Fd,
    offset: Filedelta,
    whence: Whence
) -> WasiResult<Filesize>

Move the offset of a file descriptor.

Note: This is similar to lseek in POSIX.

fn fd_sync(&self, fd: Fd) -> WasiResult<()>

Synchronize the data and metadata of a file to disk.

Note: This is similar to fsync in POSIX.

fn fd_tell(&self, fd: Fd) -> WasiResult<Filesize>

Return the current offset of a file descriptor.

Note: This is similar to lseek(fd, 0, SEEK_CUR) in POSIX.

fn fd_write(&self, fd: Fd, bufs: &[IoSlice]) -> WasiResult<Size>

Write to a file descriptor.

Note: This is similar to writev in POSIX.

fn path_create_directory(
    &self,
    fd: Fd,
    path: &<Self::StringRepresentation as Deref>::Target
) -> WasiResult<()>

Create a directory.

Note: This is similar to mkdirat in POSIX.

fn path_filestat_get(
    &self,
    fd: Fd,
    flags: Lookupflags,
    path: &<Self::StringRepresentation as Deref>::Target
) -> WasiResult<Filestat>

Return the attributes of a file or directory.

Note: This is similar to stat in POSIX.

fn path_filestat_set_times(
    &self,
    fd: Fd,
    flags: Lookupflags,
    path: &<Self::StringRepresentation as Deref>::Target,
    atim: Timestamp,
    mtim: Timestamp,
    fst_flags: Fstflags
) -> WasiResult<()>

Adjust the timestamps of a file or directory.

Note: This is similar to utimensat in POSIX.

Create a hard link.

Note: This is similar to linkat in POSIX.

fn path_open(
    &self,
    fd: Fd,
    dirflags: Lookupflags,
    path: &<Self::StringRepresentation as Deref>::Target,
    oflags: Oflags,
    fs_rights_base: Rights,
    fs_rights_inheriting: Rights,
    fdflags: Fdflags
) -> WasiResult<Fd>

Open a file or directory. The returned file descriptor is not guaranteed to be the lowest-numbered file descriptor not currently open; it is randomized to prevent applications from depending on making assumptions about indexes, since this is error-prone in multi-threaded contexts. The returned file descriptor is guaranteed to be less than 2^31.

Note: This is similar to openat in POSIX.

Read the contents of a symbolic link.

Note: This is similar to readlinkat in POSIX.

fn path_remove_directory(
    &self,
    fd: Fd,
    path: &<Self::StringRepresentation as Deref>::Target
) -> WasiResult<()>

Remove a directory. Return Err(Errno::Notempty) if the directory is not empty.

Note: This is similar to unlinkat(fd, path, AT_REMOVEDIR) in POSIX.

fn path_rename(
    &self,
    fd: Fd,
    old_path: &<Self::StringRepresentation as Deref>::Target,
    new_fd: Fd,
    new_path: &<Self::StringRepresentation as Deref>::Target
) -> WasiResult<()>

Rename a file or directory.

Note: This is similar to renameat in POSIX.

Create a symbolic link.

Note: This is similar to symlinkat in POSIX.

Unlink a file. Return Err(Errno::Isdir) if the path refers to a directory.

Note: This is similar to unlinkat(fd, path, 0) in POSIX.

fn poll_oneoff(&self, subscriptions: &[Subscription]) -> WasiResult<Vec<Event>>

Concurrently poll for the occurrence of a set of events.

fn proc_exit(&self, rval: Exitcode) -> Result<Infallible, Exitcode>

Terminate the process normally. An exit code of 0 indicates successful termination of the program. The meanings of other values is dependent on the environment.

Implementations should always return Err(rval).

fn proc_raise(&self, sig: Signal) -> WasiResult<()>

Send a signal to the process of the calling thread.

Note: This is similar to raise in POSIX.

fn random_get(&self, buf: &mut [u8]) -> WasiResult<()>

Write high-quality random data into a buffer. This function blocks when the implementation is unable to immediately provide sufficient high-quality random data. This function may execute slowly, so when large mounts of random data are required, it's advisable to use this function to seed a pseudo-random number generator, rather than to provide the random data directly.

fn sched_yield(&self) -> WasiResult<()>

Temporarily yield execution of the calling thread.

Note: This is similar to sched_yield in POSIX.

fn sock_recv(
    &self,
    fd: Fd,
    ri_data: &mut [IoSliceMut],
    ri_flags: Riflags
) -> WasiResult<(Size, Roflags)>

Receive a message from a socket.

Note: This is similar to recv in POSIX, though it also supports reading the data into multiple buffers in the manner of readv.

fn sock_send(
    &self,
    fd: Fd,
    si_data: &[IoSlice],
    si_flags: Siflags
) -> WasiResult<Size>

Send a message on a socket.

Note: This is similar to send in POSIX, though it also supports writing the data from multiple buffers in the manner of writev.

fn sock_shutdown(&self, fd: Fd, how: Sdflags) -> WasiResult<()>

Shut down socket send and receive channels.

Note: This is similar to shutdown in POSIX.

Loading content...

Implementors

Loading content...