wasi

    wasip1 implementation + experimental wrapper (async/sync) for Moonbit

    Download zip
    Version
    0.25.0
    License
    Apache-2.0
    Last updated
    3 months ago
    Downloads
    584

    #WASI Preview 1 implementation for MoonBit

    ⚠️ It's a complete rewrite since 0.17.0

    Note: not all APIs are fully tested.

    #ABI compatibility

    This package uses inline wasm helpers to pass MoonBit strings, bytes, and arrays to WASIp1 calls. MoonBit changed the ABI layout for these values so the data pointer no longer needs the old 8-byte offset. This is a breaking change for packages that use inline wasm, but it is not something the MoonBit compiler can detect at the type level.

    Use this package with a MoonBit toolchain that has the updated ABI layout. If an older toolchain or older generated bindings are mixed with this package, programs may still compile but fail at runtime with corrupted strings/bytes or traps.

    #Implemented functions

    #Develop

    #Testing

    • Requirements: you need wasmtime & deno. You may use wasmedge or wamr if you replace the wasmtime in test.ts, but it may cause different testing result.
    • Comamnds: deno task test:build && deno task test

    Errno

    pub(all) suberror Errno {
    Success
    TooBig
    Acces
    Addrinuse
    Addrnotavail
    Afnosupport
    Again
    Already
    Badf
    Badmsg
    Busy
    Canceled
    Child
    Connaborted
    Connrefused
    Connreset
    Deadlock
    Destaddrreq
    Dom
    Dquot
    Exist
    Fault
    Fbig
    Hostunreach
    Idrm
    Ilseq
    Inprogress
    Intr
    Inval
    IO
    Isconn
    Isdir
    Loop
    Mfile
    Mlink
    Msgsize
    Multihop
    Nametoolong
    Netdown
    Netreset
    Netunreach
    Nfile
    Nobufs
    Nodev
    Noent
    Noexec
    Nolck
    Nolink
    Nomem
    Nomsg
    Noprotoopt
    Nospc
    Nosys
    Notconn
    Notdir
    Notempty
    Notrecoverable
    Notsock
    Notsup
    Notty
    Nxio
    Overflow
    Ownerdead
    Perm
    Pipe
    Proto
    Protonosupport
    Prototype
    Range
    Rofs
    Spipe
    Srch
    Stale
    Timedout
    Txtbsy
    Xdev
    Notcapable
    } derive(Eq,
    Debug
    )

    Error codes returned by functions. Not all of these error codes are returned by the functions provided by this API; some are used in higher-level library layers, and others are provided merely for alignment with POSIX.

    See : https://github.com/WebAssembly/WASI/blob/wasi-0.1/preview1/docs.md#-errno-variant

    Errno::from_value

    fn Errno::from_value(value : UInt) -> Errno?

    Convert a numeric errno into Errno.

    Errno::value

    fn Errno::value(self : Errno) -> UInt

    Return the numeric errno value.

    Advice

    pub(all) enum Advice {
    Normal
    Sequential
    Random
    Willneed
    Dontneed
    Noreuse
    } derive(Eq,
    Debug
    )

    File or memory access pattern advisory information.

    • Normal: The application has no advice to give on its behavior with respect to the specified data.
    • Sequential: The application expects to access the specified data sequentially from lower offsets to higher offsets.
    • Random: The application expects to access the specified data in a random order.
    • Willneed: The application expects to access the specified data in the near future.
    • Dontneed: The application expects that it will not access the specified data in the near future.
    • Noreuse: The application expects to access the specified data once and then not reuse it afterwards.

    Advice::from_value

    fn Advice::from_value(value : UInt) -> Advice?

    Convert a numeric advice value into Advice.

    Advice::value

    fn Advice::value(self : Advice) -> UInt

    Return the numeric advice value.

    CIOVec

    pub(all) struct CIOVec {
    buf : Int
    buf_len : Size
    } derive(Eq,
    Debug
    )

    A region of memory for scatter/gather writes.

    • buf: The address of the buffer to be written.
    • buf_len: The length of the buffer to be written.

    ClockId

    pub(all) enum ClockId {
    RealTime
    Monotonic
    ProcessCPUTimeId
    ThreadCPUTimeId
    } derive(Eq,
    Debug
    )

    Identifiers for clocks.

    • Realtime: The clock measuring real time. Time value zero corresponds with 1970-01-01T00:00:00Z.
    • Monotonic: The store-wide monotonic clock, which is defined as a clock measuring real time, whose value cannot be adjusted and which cannot have negative clock jumps. The epoch of this clock is undefined. The absolute time value of this clock therefore has no meaning.
    • ProcessCPUTimeId: The CPU-time clock associated with the current process.
    • ThreadCPUTimeId: The CPU-time clock associated with the current thread.

    ClockId::clock_res_get

    fn ClockId::clock_res_get(self : ClockId) -> TimeStamp raise Errno

    Return the resolution of a clock.

    Implementations are required to provide a non-zero value for supported clocks. For unsupported clocks, return errno::inval.

    Note: This is similar to clock_getres in POSIX.

    @param self The clock for which to return the resolution. @return The resolution of the clock, or an error if one happened.

    ClockId::clock_time_get

    fn ClockId::clock_time_get(self : ClockId, precision : TimeStamp) -> TimeStamp raise Errno

    Return the time value of a clock

    Note: This is similar to clock_gettime in POSIX.

    @param self The clodk for which to return the time. @param precision The maximum lag (exclusive) that the returned time value may have, compared to its actual value. @return The time value of the clock.

    ClockId::from_value

    fn ClockId::from_value(value : UInt) -> ClockId?

    Convert a numeric clock id into ClockId.

    ClockId::value

    fn ClockId::value(self : ClockId) -> UInt

    Return the numeric clock id value.

    Device

    pub(all) struct Device(UInt64) derive(Eq,
    Debug
    )

    Identifier for a device containing a file system. Can be used in combination with inode to uniquely identify a file or directory in the filesystem.

    DirCookie

    pub(all) struct DirCookie(UInt64) derive(Eq,
    Debug
    )

    A reference to the offset of a directory entry.

    The value 0 signifies the start of the directory.

    DirEnt

    pub(all) struct DirEnt {
    d_next : DirCookie
    d_ino : Inode
    d_namlen : DirNamlen
    d_type : FileType
    } derive(Eq,
    Debug
    )

    A directory entry.

    • d_next: The offset of the next directory entry stored in the buffer.
    • d_ino: The serial number of the file referred to by this directory entry.
    • d_namlen: The length of the name of the directory entry.
    • d_type: The type of the file referred to by this directory entry.

    DirNamlen

    pub(all) struct DirNamlen(UInt) derive(Eq,
    Debug
    )

    The type for the dirent::d_namlen field of dirent struct.

    Event

    pub(all) struct Event {
    userdata : Userdata
    error : Errno
    type_ : EventType
    fd_readwrite : Event_fd_readwrite
    } derive(Eq,
    Debug
    )

    An event that occurred.

    • userdata: User-provided value that got attched to subscription::userdata.
    • error: If non-zero, an error that occurred while processing the subscription request.
    • type_: The type of the event that occurred.
    • fd_readwrite: The contents of the event, if it is an eventtype::fd_read or eventtype::fd_write. eventtype::clock events ignore this field.

    EventRWFlag

    pub(all) enum EventRWFlag {
    Fd_readwrite_hangup
    } derive(Eq,
    Debug
    )

    The state of the file descriptor subscribed to with eventtype::fd_read or eventtype::fd_write.

    • Fd_readwrite_hangup: The peer of this socket has closed or disconnected.

    EventRWFlag::value

    fn EventRWFlag::value(self : EventRWFlag) -> UInt

    Return the numeric value for an event read/write flag.

    EventRWFlags

    pub(all) struct EventRWFlags(UInt) derive(Eq,
    Debug
    )

    The state of the file descriptor subscribed to with eventtype::fd_read or eventtype::fd_write.

    EventRWFlags::is_set

    fn EventRWFlags::is_set(self : EventRWFlags, flag : EventRWFlag) -> Bool

    Check whether an event read/write flag is enabled.

    EventRWFlags::new

    Create an empty set of event read/write flags.

    EventRWFlags::set

    Return a new event read/write flags set with the given flag enabled.

    EventRWFlags::unset

    fn EventRWFlags::unset(self : EventRWFlags, flag : EventRWFlag) -> EventRWFlags

    Return a new event read/write flags set with the given flag disabled.

    EventType

    pub(all) enum EventType {
    Clock
    Fd_read
    Fd_write
    } derive(Eq,
    Debug
    )

    Type of a subscription to an event or its occurrence.

    • Clock: The time value of clock subscription_clock::id has reached timestamp subscription_clock::timeout.
    • Fd_read: File descriptor subscription_fd_readwrite::file_descriptor has data available for reading. This event always triggers for regular files.
    • Fd_write: File descriptor subscription_fd_readwrite::file_descriptor has capacity available for writing. This event always triggers for regular files.

    EventType::from_value

    fn EventType::from_value(value : UInt) -> EventType?

    Convert a numeric event type into EventType.

    EventType::value

    fn EventType::value(self : EventType) -> UInt

    Return the numeric value for an event type.

    Event_fd_readwrite

    pub(all) struct Event_fd_readwrite {
    nbytes : FileSize
    flags : EventRWFlags
    } derive(Eq,
    Debug
    )

    The contents of an event when type is eventtype::fd_read or eventtype::fd_write.

    • nbytes: Number of bytes available for reading or writing.
    • flags: The state of the file descriptor.

    ExitCode

    pub(all) struct ExitCode(UInt) derive(Eq,
    Debug
    )

    Exit code generated by a process when exiting.
    pub(all) struct Fd(Int) derive(Eq,
    Debug
    )

    A file descriptor handle

    Fd::fd_advise

    fn Fd::fd_advise(self : Fd, offset : FileSize, len : FileSize, advice : Advice) -> Unit raise Errno

    Provide file advisory information on a file ddescriptor

    Note: This is similar to posix_fadvise in POSIX.

    @param offset The offset within the file to which the advisory applies. @param len The length of the region to which the advisory applies. @param advice The advice.

    Fd::fd_allocate

    fn Fd::fd_allocate(self : Fd, offset : FileSize, len : FileSize) -> Unit raise Errno

    Force the allocaiton of space in a file.

    Note: This is similar to posix_fallocate in POSIX.

    @param offset The offset at which to start allocating. @param len The length of the area that is allocated. @return The error code.

    Fd::fd_close

    fn Fd::fd_close(self : Fd) -> Unit raise Errno

    Close a file descriptor.

    Note: This is similar to close in POSIX.

    Fd::fd_datasync

    fn Fd::fd_datasync(self : Fd) -> Unit raise Errno

    Synchronize the data of a file to disk.

    Note: This is similar to fdatasync in POSIX.

    Fd::fd_fdstat_get

    fn Fd::fd_fdstat_get(self : Fd) -> FdStat raise Errno

    Get the attributes of a file descriptor.

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

    Fd::fd_fdstat_set_flags

    fn Fd::fd_fdstat_set_flags(self : Fd, flags : FdFlags) -> Unit raise Errno

    Adjust the flags associated with a file descriptor.

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

    @param flags The desired values of the file descriptor flags.

    Fd::fd_fdstat_set_rights

    fn Fd::fd_fdstat_set_rights(self : Fd, fs_rights_base : Rights, fs_rights_inheriting : Rights) -> Unit raise Errno

    Adjust the rights associated with a file descriptor.

    This can only be used to remove rights, and returns errno::notcapable if called in a way that would attempt to add rights.

    @param fs_rights_base The desired rights of the file descriptor.

    Fd::fd_filestat_get

    fn Fd::fd_filestat_get(self : Fd) -> FileStat raise Errno

    Return the attributes of an open file

    Fd::fd_filestat_set_size

    fn Fd::fd_filestat_set_size(self : Fd, size : FileSize) -> Unit raise Errno

    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.

    @param size The desired file size.

    Fd::fd_filestat_set_times

    fn Fd::fd_filestat_set_times(self : Fd, atim : TimeStamp, mtim : TimeStamp, fst_flags : FstFlags) -> Unit raise Errno

    Adjust the timestamps of an open file or directory.

    Note: This is similar to futimens in POSIX.

    @param atim The desired value of the data access timestamp. @param mtim The desired value of the data modification timestamp. @param fst_flags A bitmask indicating which timestamps to adjust.

    Fd::fd_pread

    fn Fd::fd_pread(self : Fd, iovs : Array[FixedArray[Byte]], offset : FileSize) -> Size raise Errno

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

    Note: This is similar to preadv in Linux (and other Unix-es).

    Fd::fd_prestat_dir_name

    fn Fd::fd_prestat_dir_name(self : Fd) -> String raise Errno

    Return a description of the given preopened file descriptor.

    Fd::fd_prestat_get

    fn Fd::fd_prestat_get(self : Fd) -> PreStat raise Errno

    Return a description of the given preopened file descriptor.

    Note: consider using fd_prestat_dir_name directly.

    Fd::fd_read

    fn Fd::fd_read(self : Fd, iovs : Array[FixedArray[Byte]]) -> Size raise Errno

    Read from a file descriptor.

    Note: This is similar to readv in POSIX.

    Fd::fd_readdir

    fn Fd::fd_readdir(self : Fd, cookie? : DirCookie, buffer? : Bytes) -> (Array[(String, DirEnt)], Bool) raise Errno

    Read directory entries from a directory. When successful, the contents of the output buffer consist of a sequence of directory entries. Each directory entry consists of a dirent object, followed by dirent::d_namlen bytes holding the name of the directory entry.

    This function fills the output buffer as much as possible, potentially truncating the last directory entry. This allows the caller to grow its read buffer size in case it's too small to fit a single large directory entry, or skip the oversized directory entry.

    Entries for the special . and .. directory entries are included in the sequence.

    @param cookie: The location within the directory to start reading. @param size: The buffer used to read. @return The entries untruncated and whether there's still other entries.

    Fd::fd_renumber

    fn Fd::fd_renumber(self : Fd, to : Fd) -> Unit raise Errno

    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.

    This function provides a way to atomically renumber file descriptors, which would disappear if dup2() were to be removed entirely.

    Fd::fd_seek

    fn Fd::fd_seek(self : Fd, offset : FileDelta, whence : Whence) -> FileSize raise Errno

    Move the offset of a file descriptor.

    Note: This is similar to lseek in POSIX.

    @param offset The number of bytes to move. @param whence The base from which the offset is calculated. @return The new offset of the file descriptor, relative to the start of the file.

    Fd::fd_sync

    fn Fd::fd_sync(self : Fd) -> Unit raise Errno

    Synchronize the data and metadata of a file to disk.

    Note: This is similar to fsync in POSIX.

    Fd::fd_tell

    fn Fd::fd_tell(self : Fd) -> FileSize raise Errno

    Return the current offset of a file descriptor.

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

    @return The current offset of the file descriptor, relative to the start of the file.

    Fd::fd_write

    fn Fd::fd_write(self : Fd, contents : Array[BytesView]) -> Size raise Errno

    Write to a file descriptor.

    Note: This is similar to writev in POSIX.

    Like POSIX, any calls of write (and other functions to read or write) for a regular file by other threads in the WASI process should not be interleaved while write is executed.

    Note: it may write less than demanded.

    Fd::path_create_directory

    fn Fd::path_create_directory(self : Fd, path : String) -> Unit raise Errno

    Create a directory.

    Note: This is similar to mkdirat in POSIX.

    @param path The path at which to create the directory.

    Fd::path_filestat_get

    fn Fd::path_filestat_get(self : Fd, flags : LookupFlags, path : String) -> FileStat raise Errno

    Return the attributes of a file or directory.

    Note: This is similar to stat in POSIX.

    @param flags Flags determining the method of how the path is resolved. @param path The path of the file or directory to inspect.

    Fd::path_filestat_set_times

    fn Fd::path_filestat_set_times(self : Fd, flags : LookupFlags, path : String, atim : TimeStamp, mtim : TimeStamp, fst_flags : FstFlags) -> Unit raise Errno

    Adjust the timestamps of a file or directory.

    Note: This is similar to utimensat in POSIX.

    @param flag Flags determining the method of how the path is resolved. @param path The path of the file or directory to operate on. @param atim The desired values of the data access timestamp. @param mtim The desired values of the data modification timestamp. @param fst_flags A bitmask indicating which timestamps to adjust.
    fn Fd::path_link(self : Fd, old_flags : LookupFlags, old_path : String, new_fd : Fd, new_path : String) -> Unit raise Errno

    Create a hard link.

    Note: This is similar to linkat in POSIX.

    @param old_flags Flags determining the method of how the path is resolved. @param old_path The source path from which to link. @param new_fd The wroking directory at which the resolution of the new path starts. @param new_path The destination path at which to create the hard link.

    Fd::path_open

    fn Fd::path_open(self : Fd, dirflags : LookupFlags, path : String, oflags : OpenFlags, fs_rights_base : Rights, fs_rights_inheriting : Rights, fs_flags : FdFlags) -> Fd raise Errno

    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.

    @param dirflags Flags determining the method of how the path is resolved. @param path The path of the file or directory to open. @param oflags The method by which to open the file. @param fs_rights_base The initial rights of the newly created file descriptor. The implementation is allowed to return a file descriptor with fewer rights than specified, if and only if those rights do not apply to the type of file being opened. The base rights are rights that will apply to operations using the file descriptor itself. @param fs_rights_inheriting The initial rights of the newly created file descriptor. The implementation is allowed to return a file descriptor with fewer rights than specified, if and only if those rights do not apply to the type of file being opened. The inheriting rights are rights that apply to file descriptors derived from it. @return The file descriptor of the file that has been opened.
    fn Fd::path_readlink(self : Fd, path : String, buffer? : FixedArray[Byte]) -> Size raise Errno

    Read the contents of a symbolic link.

    Note: This is similar to readlinkat in POSIX. If buf is not large enough to store the contents of the link, the first buf_len bytes will be written buf.

    Fd::path_remove_directory

    fn Fd::path_remove_directory(self : Fd, path : String) -> Unit raise Errno

    Remove a directory.

    Return errno::notempty if the directory is not empty.

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

    Fd::path_rename

    fn Fd::path_rename(self : Fd, old_path : String, new_fd : Fd, new_path : String) -> Unit raise Errno

    Rename a file or directory.

    Note: This is similar to renameat in POSIX.

    @param old_path The source path of the file or directory to rename. @param new_fd The working directory at which the resolution of the new path starts. @param new_path The destination path of the file or directory to rename.
    fn Fd::path_unlink_file(self : Fd, path : String) -> Unit raise Errno

    Unlink a file.

    Return errno::isdir if the path refers to a directory.

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

    Fd::sock_accept

    fn Fd::sock_accept(self : Fd, flags : FdFlags) -> Fd raise Errno

    Accept a new incoming connection on a socket.

    Note: This is similar to accept in POSIX.

    @param self The listening socket. @param flags The desired values of the file descriptor flags. @return New socket connection.

    Fd::sock_recv

    fn Fd::sock_recv(self : Fd, contents : Array[FixedArray[Byte]], flags : RiFlags) -> (Size, RoFlags) raise Errno

    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.

    @param contents List of scatter/gather vectors to which to store data. @param flags Message flags. @return Number of bytes stored in the buffers and message flags.

    Fd::sock_send

    fn Fd::sock_send(self : Fd, contents : Array[BytesView], flags : SiFlags) -> Size raise Errno

    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.

    @param contents List of scatter/gather vectors to which to retrieve the data. @param flags Message flags. @return The number of bytes transmitted.

    Fd::sock_shutdown

    fn Fd::sock_shutdown(self : Fd, how : SdFlags) -> Unit raise Errno

    Shut down socket send and receive channels.

    Note: This is similar to shutdown in POSIX.

    @param how Which channels on the socket to shut down.

    FdFlag

    pub(all) enum FdFlag {
    Append
    Dsync
    Nonblock
    Rsync
    Sync
    } derive(Eq,
    Debug
    )

    File descriptor flags.

    • Append: Append mode: Data written to the file is always appended to the file's end.
    • Dsync: Write according to synchronized I/O data integrity completion. Only the data stored in the file is synchronized.
    • Nonblock: Non-blocking mode.
    • Rsync: Synchronized read I/O operations.
    • Sync: Write according to synchronized I/O file integrity completion. In addition to synchronizing the data stored in the file, the implementation may also synchronously update the file's metadata.

    FdFlag::value

    fn FdFlag::value(self : FdFlag) -> UInt

    Return the numeric value for a single fd flag.

    FdFlags

    pub(all) struct FdFlags(UInt) derive(Eq,
    Debug
    )

    File descriptor flag.

    FdFlags::is_set

    fn FdFlags::is_set(self : FdFlags, flag : FdFlag) -> Bool

    Check whether an fd flag is enabled.

    FdFlags::new

    fn FdFlags::new() -> FdFlags

    Create an empty set of fd flags.

    FdFlags::set

    fn FdFlags::set(self : FdFlags, flag : FdFlag) -> FdFlags

    Return a new fd flags set with the given flag enabled.

    FdFlags::unset

    fn FdFlags::unset(self : FdFlags, flag : FdFlag) -> FdFlags

    Return a new fd flags set with the given flag disabled.

    FdStat

    pub(all) struct FdStat {
    fs_filetype : FileType
    fs_flags : FdFlags
    fs_rights_base : Rights
    fs_rights_inheriting : Rights
    } derive(Eq,
    Debug
    )

    File descriptor attributes.

    • fs_filetype: File type.
    • fs_flags: File descriptor flags.
    • fs_rights_base: Rights that apply to this file descriptor.
    • fs_rights_inheriting: Maximum set of rights that may be installed on new file descriptors that are created through this file descriptor, e.g., through path_open.

    FileDelta

    pub(all) struct FileDelta(Int64) derive(Eq,
    Debug
    )

    Relative offset within a file.

    FileSize

    pub(all) struct FileSize(UInt64) derive(Eq,
    Debug
    )

    Non-negative file size or length of a region within a file.

    FileStat

    pub(all) struct FileStat {
    dev : Device
    ino : Inode
    filetype : FileType
    nlink : LinkCount
    size : FileSize
    atim : TimeStamp
    mtim : TimeStamp
    ctim : TimeStamp
    } derive(Eq,
    Debug
    )

    File attributes.

    • dev: Device ID of device containing the file.
    • ino: File serial number.
    • filetype: File type.
    • nlink: Number of hard links to the file.
    • size: For regular files, the file size in bytes. For symbolic links, the length in bytes of the pathname contained in the symbolic link.
    • atim: Last data access timestamp. This can be 0 if the underlying platform doesn't provide suitable timestamp for this file.
    • mtim: Last data modification timestamp. This can be 0 if the underlying platform doesn't provide suitable timestamp for this file.
    • ctim: Last file status change timestamp. This can be 0 if the underlying platform doesn't provide suitable timestamp for this file.

    FileType

    pub(all) enum FileType {
    Unknown
    Block_device
    Character_device
    Directory
    Regular_file
    Socket_dgram
    Socket_stream
    Symbolic_link
    } derive(Eq,
    Debug
    )

    The type of a file descriptor or file.

    • Unknown: The type of the file descriptor or file is unknown or is different from any of the other types specified.
    • Block_device: The file descriptor or file refers to a block device inode.
    • Character_device: The file descriptor or file refers to a character device inode.
    • Directory: The file descriptor or file refers to a directory inode.
    • Regular_file: The file descriptor or file refers to a regular file inode.
    • Socket_dgram: The file descriptor or file refers to a datagram socket.
    • Socket_stream: The file descriptor or file refers to a byte-stream socket.
    • Symbolic_link: The file refers to a symbolic link inode.

    FileType::from_value

    fn FileType::from_value(value : Int) -> FileType?

    Convert a numeric file type into FileType.

    FileType::value

    fn FileType::value(self : FileType) -> Int

    Return the numeric file type value.

    FstFlag

    pub(all) enum FstFlag {
    Atim
    Atim_now
    Mtim
    Mtim_now
    } derive(Eq,
    Debug
    )

    Which file time attributes to adjust

    • Atim: Adjust the last access timestamp to the value stored in filestat::atim.
    • Atim_now: Adjust the last access timestamp to the time of clock clockid::realtime.
    • Mtim: Adjust the last modification timestamp to the value stored in filestat::mtim.
    • Mtim_now: Adjust the last modification timestamp to the time of clock clockid::realtime.

    FstFlag::value

    fn FstFlag::value(self : FstFlag) -> UInt

    Return the numeric value for a filestat flag.

    FstFlags

    pub(all) struct FstFlags(UInt) derive(Eq,
    Debug
    )

    Which file time attributes to adjust

    FstFlags::is_set

    fn FstFlags::is_set(self : FstFlags, flag : FstFlag) -> Bool

    Check whether a filestat flag is enabled.

    FstFlags::new

    fn FstFlags::new() -> FstFlags

    Create an empty set of filestat flags.

    FstFlags::set

    fn FstFlags::set(self : FstFlags, flag : FstFlag) -> FstFlags

    Return a new filestat flags set with the given flag enabled.

    FstFlags::unset

    fn FstFlags::unset(self : FstFlags, flag : FstFlag) -> FstFlags

    Return a new filestat flags set with the given flag disabled.

    IOVec

    pub(all) struct IOVec {
    buf : Int
    buf_len : Size
    } derive(Eq,
    Debug
    )

    A region of memory for scatter/gather reads.

    • buf: The address of the buffer to be filled.
    • buf_len: The length of the buffer to be filled.

    Inode

    pub(all) struct Inode(UInt64) derive(Eq,
    Debug
    )

    File serial number that is unique within its file system.

    LinkCount

    pub(all) struct LinkCount(UInt64) derive(Eq,
    Debug
    )

    Number of hard links to an inode.

    LookupFlag

    pub(all) enum LookupFlag {
    Symlink_follow
    } derive(Eq,
    Debug
    )

    LookupFlag::value

    fn LookupFlag::value(self : LookupFlag) -> UInt

    Return the numeric value for a lookup flag.

    LookupFlags

    pub(all) struct LookupFlags(UInt) derive(Eq,
    Debug
    )

    Flags dermining the method of how paths are resolved.

    LookupFlags::is_set

    fn LookupFlags::is_set(self : LookupFlags, flag : LookupFlag) -> Bool

    Check whether a lookup flag is enabled.

    LookupFlags::new

    Create an empty set of lookup flags.

    LookupFlags::set

    fn LookupFlags::set(self : LookupFlags, flag : LookupFlag) -> LookupFlags

    Return a new lookup flags set with the given flag enabled.

    LookupFlags::unset

    fn LookupFlags::unset(self : LookupFlags, flag : LookupFlag) -> LookupFlags

    Return a new lookup flags set with the given flag disabled.

    OpenFlag

    pub(all) enum OpenFlag {
    Create
    Directory
    Excl
    Trunc
    } derive(Eq,
    Debug
    )

    Open flags used by path_open.

    • Create: Create the file if it does not exist.
    • Directory: Fail if not a directory.
    • Excl: Fail if the file already exists.
    • Trunc: Truncate the file to size 0.

    OpenFlag::value

    fn OpenFlag::value(self : OpenFlag) -> UInt

    Return the numeric value for an open flag.

    OpenFlags

    pub(all) struct OpenFlags(UInt) derive(Eq,
    Debug
    )

    Open flags used by path_open.

    OpenFlags::is_set

    fn OpenFlags::is_set(self : OpenFlags, flag : OpenFlag) -> Bool

    Check whether an open flag is enabled.

    OpenFlags::new

    fn OpenFlags::new() -> OpenFlags

    Create an empty set of open flags.

    OpenFlags::set

    fn OpenFlags::set(self : OpenFlags, flag : OpenFlag) -> OpenFlags

    Return a new open flags set with the given flag enabled.

    OpenFlags::unset

    fn OpenFlags::unset(self : OpenFlags, flag : OpenFlag) -> OpenFlags

    Return a new open flags set with the given flag disabled.

    PreOpenType

    pub(all) enum PreOpenType {
    Dir
    } derive(Eq,
    Debug
    )

    Identifiers for preopened capabilites.

    • Dir: A pre-opened directory.

    PreOpenType::from_value

    fn PreOpenType::from_value(value : UInt) -> PreOpenType?

    Convert a numeric preopen type into PreOpenType.

    PreOpenType::value

    fn PreOpenType::value(self : PreOpenType) -> UInt

    Return the numeric preopen type value.

    PreStat

    pub(all) enum PreStat {
    Dir(PreStat_dir)
    } derive(Eq,
    Debug
    )

    Information about a pre-opened capability.

    PreStat_dir

    pub(all) struct PreStat_dir {
    pr_name_len : Size
    } derive(Eq,
    Debug
    )

    The content of a prestat when type is preopentype::dir.

    • pr_name_len: The length of the directory name for use with fd_prestat_dir_name.

    RiFlag

    pub(all) enum RiFlag {
    Recv_peek
    Recv_waitall
    } derive(Eq,
    Debug
    )

    Flags provided to sock_recv.

    • Recv_peek: Returns the message without removing it from the socket's receive queue.
    • Recv_waitall: On byte-stream sockets, block until the full amount of data can be returned.

    RiFlag::value

    fn RiFlag::value(self : RiFlag) -> UInt

    Return the numeric value for a recv flag.

    RiFlags

    pub(all) struct RiFlags(UInt) derive(Eq,
    Debug
    )

    Flags provided to sock_recv.

    RiFlags::is_set

    fn RiFlags::is_set(self : RiFlags, flag : RiFlag) -> Bool

    Check whether a recv flag is enabled.

    RiFlags::new

    fn RiFlags::new() -> RiFlags

    Create an empty set of recv flags.

    RiFlags::set

    fn RiFlags::set(self : RiFlags, flag : RiFlag) -> RiFlags

    Return a new recv flags set with the given flag enabled.

    RiFlags::unset

    fn RiFlags::unset(self : RiFlags, flag : RiFlag) -> RiFlags

    Return a new recv flags set with the given flag disabled.
    pub(all) enum Right {
    Fd_datasync
    Fd_read
    Fd_seek
    Fd_fdstat_set_flags
    Fd_sync
    Fd_tell
    Fd_write
    Fd_advice
    Fd_allocate
    Path_create_directory
    Path_create_file
    Path_link_source
    Path_link_target
    Path_open
    Fd_readdir
    Path_readlink
    Path_rename_source
    Path_rename_target
    Path_filestat_get
    Path_filestat_set_size
    Path_filestat_set_times
    Fd_filestat_get
    Fd_filestat_set_size
    Fd_filestat_set_times
    Path_symlink
    Path_remove_directory
    Path_unlink_file
    Poll_fd_readwrite
    Sock_shutdown
    Sock_accept
    } derive(Eq,
    Debug
    )

    File descriptor rights, determining which actions may be performed.

    Right::value

    fn Right::value(self : Right) -> UInt64

    Return the numeric value for a single right.

    Rights

    pub(all) struct Rights(UInt64) derive(Eq,
    Debug
    )

    File descriptor rights, determining which actions may be performed.

    Rights::is_set

    fn Rights::is_set(self : Rights, right : Right) -> Bool

    Check whether a right is enabled.

    Rights::new

    fn Rights::new() -> Rights

    Create an empty set of rights.

    Rights::set

    fn Rights::set(self : Rights, right : Right) -> Rights

    Return a new rights set with the given right enabled.

    Rights::unset

    fn Rights::unset(self : Rights, right : Right) -> Rights

    Return a new rights set with the given right disabled.

    RoFlag

    pub(all) enum RoFlag {
    Recv_data_truncated
    } derive(Eq,
    Debug
    )

    Flags returned by sock_recv.

    • Recv_data_truncated: Returned by sock_recv: Message data has been truncated.

    RoFlag::value

    fn RoFlag::value(self : RoFlag) -> UInt

    Return the numeric value for a recv open flag.

    RoFlags

    pub(all) struct RoFlags(UInt) derive(Eq,
    Debug
    )

    Flags returned by sock_recv.

    RoFlags::is_set

    fn RoFlags::is_set(self : RoFlags, flag : RoFlag) -> Bool

    Check whether a recv open flag is enabled.

    RoFlags::new

    fn RoFlags::new() -> RoFlags

    Create an empty set of recv open flags.

    RoFlags::set

    fn RoFlags::set(self : RoFlags, flag : RoFlag) -> RoFlags

    Return a new recv open flags set with the given flag enabled.

    RoFlags::unset

    fn RoFlags::unset(self : RoFlags, flag : RoFlag) -> RoFlags

    Return a new recv open flags set with the given flag disabled.

    SdFlag

    pub(all) enum SdFlag {
    Rd
    Wr
    } derive(Eq,
    Debug
    )

    Which channels on a socket to shut down.

    • Rd: Disables further receive operations.
    • Wr: Disables further send operations.

    SdFlag::value

    fn SdFlag::value(self : SdFlag) -> UInt

    Return the numeric value for a shutdown flag.

    SdFlags

    pub(all) struct SdFlags(UInt) derive(Eq,
    Debug
    )

    Which channels on a socket to shut down.

    SdFlags::is_set

    fn SdFlags::is_set(self : SdFlags, flag : SdFlag) -> Bool

    Check whether a shutdown flag is enabled.

    SdFlags::new

    fn SdFlags::new() -> SdFlags

    Create an empty set of shutdown flags.

    SdFlags::set

    fn SdFlags::set(self : SdFlags, flag : SdFlag) -> SdFlags

    Return a new shutdown flags set with the given flag enabled.

    SdFlags::unset

    fn SdFlags::unset(self : SdFlags, flag : SdFlag) -> SdFlags

    Return a new shutdown flags set with the given flag disabled.

    SiFlag

    pub(all) enum SiFlag {
    } derive(Eq,
    Debug
    )

    Flags returned by sock_send. As there are currently no flags defined, it must be set to zero.

    SiFlag::value

    fn SiFlag::value(self : SiFlag) -> UInt

    Return the numeric value for a send flag.

    SiFlags

    pub(all) struct SiFlags(UInt) derive(Eq,
    Debug
    )

    Flags provided to sock_send. As there are currently no flags defined, it must be set to zero.

    SiFlags::is_set

    fn SiFlags::is_set(self : SiFlags, flag : SiFlag) -> Bool

    Check whether a send flag is enabled.

    SiFlags::new

    fn SiFlags::new() -> SiFlags

    Create an empty set of send flags.

    SiFlags::set

    fn SiFlags::set(self : SiFlags, flag : SiFlag) -> SiFlags

    Return a new send flags set with the given flag enabled.

    SiFlags::unset

    fn SiFlags::unset(self : SiFlags, flag : SiFlag) -> SiFlags

    Return a new send flags set with the given flag disabled.

    Signal

    pub(all) enum Signal {
    None
    Hup
    Inte
    Quit
    Ill
    Trap
    Abrt
    Bus
    Fpe
    Kill
    Usr1
    Segv
    Usr2
    Pipe
    Alrm
    Term
    Chld
    Cont
    Stop
    Tstp
    Ttin
    Ttou
    Urg
    Xcpu
    Xfsz
    Vtalrm
    Prof
    Winch
    Poll
    Pwr
    Sys
    } derive(Eq,
    Debug
    )

    Signal condition.

    • None: No signal. Note that POSIX has special semantics for kill(pid, 0), so this value is reserved.
    • Hup: Hangup. Action: Terminates the process.
    • Inte: Terminate interrupt signal. Action: Terminates the process.
    • Quit: Terminal quit signal. Action: Terminates the process.
    • Ill: Illegal instruction. Action: Terminates the process.
    • Trap: Trace/breakpoint trap. Action: Terminates the process.
    • Abrt: Process abort signal. Action: Terminates the process.
    • Bus: Access to an undefined portion of a memory object. Action: Terminates the process.
    • Fpe: Erroneous arithmetic operation. Action: Terminates the process.
    • Kill: Kill. Action: Terminates the process.
    • Usr1: User-defined signal 1. Action: Terminates the process.
    • Segv: Invalid memory reference. Action: Terminates the process.
    • Usr2: User-defined signal 2. Action: Terminates the process.
    • Pipe: Write on a pipe with no one to read it. Action: Ignored.
    • Alrm: Alarm clock. Action: Terminates the process.
    • Chld: Child process terminated, stopped, or continued. Action: Ignored.
    • Cont: Continue executing, if stopped. Action: Continues the process.
    • Stop: Stop executing. Action: Stops the process.
    • Tstp: Terminal stop signal. Action: Stops the process.
    • Ttin: Background process attempting read. Action: Stops the process.
    • Ttou: Background process attempting write. Action: Stops the process.
    • Urg: High bandwidth data is available at a socket. Action: Ignored.
    • Xcpu: CPU time limit exceeded. Action: Terminates the process.
    • Xfsz: File size limit exceeded. Action: Terminates the process.
    • Vtalrm: Virtual timer expired. Action: Terminates the process.
    • Prof: Profiling timer expired. Action: Terminates the process.
    • Winch: Window changed. Action: Ignored.
    • Poll: I/O possible. Action: Terminates the process.
    • Pwr: Power failure. Action: Terminates the process.
    • Sys: Bad system call. Action: Terminates the process.

    Signal::from_value

    fn Signal::from_value(value : UInt) -> Signal?

    Convert a numeric signal into Signal.

    Signal::value

    fn Signal::value(self : Signal) -> UInt

    Return the numeric value for a signal.

    Size

    pub(all) struct Size(UInt) derive(Eq,
    Debug
    )

    SubclockFlag

    pub(all) enum SubclockFlag {
    Subscription_clock_abstime
    } derive(Eq,
    Debug
    )

    Flags determining how to interpret the timestamp provided in subscription::timeout.

    • Subscription_clock_abstime: If set, treat the timestamp provided in subscription_clock::timeout as an absolute timestamp of clock subscription_clock::id. If clear, treat the timestamp provided in subscription_clock::timeout relative to the current time value of clock subscription_clock::id.

    SubclockFlag::value

    fn SubclockFlag::value(self : SubclockFlag) -> UInt

    Return the numeric value for a subclock flag.

    SubclockFlags

    pub(all) struct SubclockFlags(UInt) derive(Eq,
    Debug
    )

    Flags determining how to interpret the timestamp provided in subscription::timeout.

    SubclockFlags::is_set

    fn SubclockFlags::is_set(self : SubclockFlags, flag : SubclockFlag) -> Bool

    Check whether a subclock flag is enabled.

    SubclockFlags::new

    Create an empty set of subclock flags.

    SubclockFlags::set

    Return a new subclock flags set with the given flag enabled.

    SubclockFlags::unset

    Return a new subclock flags set with the given flag disabled.

    Subscription

    pub(all) struct Subscription {
    userdata : Userdata
    u : Subscription_u
    } derive(Eq,
    Debug
    )

    Subscription to an event.

    • userdata: User-provided value that is attached to the subscription in the implementaiton and returned through event::userdata.
    • u: The type of the event to which to subscribe, and its contents.

    Subscription_clock

    pub(all) struct Subscription_clock {
    id : ClockId
    timeout : TimeStamp
    precision : TimeStamp
    flags : SubclockFlags
    } derive(Eq,
    Debug
    )

    The contents of a subscription when type is eventtype::clock.

    • id: The clock against which to compare the timestamp.
    • timeout: The absolute or relative timestamp.
    • precision: The amount of time that the implementation may wait additionally to coalesce with other events.
    • flags: Flags specifying whether the timeout is absolute or relative.

    Subscription_fd_readwrite

    pub(all) struct Subscription_fd_readwrite {
    file_descriptor : Fd
    } derive(Eq,
    Debug
    )

    The contents of a subscription when type is eventtype::fd_read or eventtype::fd_write.

    • file_descriptor: The file descriptor on which to wait for it to become ready for reading or writing.

    Subscription_u

    pub(all) enum Subscription_u {
    Clock(Subscription_clock)
    Fd_read(Subscription_fd_readwrite)
    Fd_write(Subscription_fd_readwrite)
    } derive(Eq,
    Debug
    )

    The contents of a subscription.

    TimeStamp

    pub(all) struct TimeStamp(UInt64) derive(Eq,
    Debug
    )

    Timestamp in nanoseconds.

    Userdata

    pub(all) struct Userdata(UInt64) derive(Eq,
    Debug
    )

    User-provided value that may be attached to objects that is retained when extracted from the implementation.

    Whence

    pub(all) enum Whence {
    Set
    Cur
    End
    } derive(Eq,
    Debug
    )

    The position relative to which to set the offset of the file descriptor

    Whence::from_value

    fn Whence::from_value(value : UInt) -> Whence?

    Convert a numeric whence into Whence.

    Whence::value

    fn Whence::value(self : Whence) -> UInt

    Return the numeric whence value.

    args_get

    fn args_get() -> Array[String] raise Errno

    Read command-line argument data.

    The size of the array should match that returned by args_sizes_get.

    Each argument is not \0 terminated.

    The first argument should be a string containing the "name" of the program. This need not be a usable filesystem path or even file name, and may even be a fixed string. Subsequent arguments are the arguments passed to the program by the user.

    args_sizes_get

    fn args_sizes_get() -> (Int, Int) raise Errno

    Return command-line argument data sizes.

    @return Returns the number of arguments and the size of the argument string data, or an error.

    environ_get

    fn environ_get() -> Array[(String, String)] raise Errno

    Read environment variable data.

    The size of the array should match that returned by environ_sizes_get.

    environ_sizes_get

    fn environ_sizes_get() -> (Int, Int) raise Errno

    Return environment variable data sizes.

    @return Returns the number of environment variables arguments and the size of the environment variable data.
    fn path_symlink(old_path : String, fd : Fd, new_path : String) -> Unit raise Errno

    Create a symbolic link.

    Note: This is similar to symlinkat in POSIX.

    poll_oneoff

    fn poll_oneoff(in_ : Array[Subscription]) -> Array[Event] raise Errno

    Concurrently poll for the occurrence of a set of events.

    If nsubscriptions is 0, returns errno::inval.

    @param in_ The events to which to subscribe. @return The events that have occurred.

    proc_exit

    fn[T] proc_exit(rval : UInt) -> T

    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.

    Note: the accepted range may depend on the runtime, meaning that it may become an error to return a value outside the accepted range of exit codes, making the actual error code environment-dependent.

    proc_raise

    fn proc_raise(sig : Signal) -> Unit raise Errno

    Send a signal to the process of the calling thread.

    Note: This is similar to raise in POSIX.

    @param sig The signal condition to trigger.

    random_get

    fn random_get(buf : FixedArray[Byte]) -> Unit raise Errno

    Write high-quality random data into a buffer.

    This function blocks when the implementaiton is unable to immediately provide sufficient high-quality random data.

    This function may execute slowly, so when larget 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.

    sched_yield

    fn sched_yield() -> Unit raise Errno

    Temporarily yield execution of the calling thread.

    Note: This is similar to sched_yield in POSIX.

    stderr

    let stderr : Fd

    Standard error file descriptor.

    stdin

    let stdin : Fd

    Standard input file descriptor.

    stdout

    let stdout : Fd

    Standard output file descriptor.

    Source Files