Class Wasi.WasiSnapshotPreview1
- java.lang.Object
-
- ej.wasi.Wasi.WasiSnapshotPreview1
-
- All Implemented Interfaces:
WasiConstants
- Enclosing class:
- Wasi
public static class Wasi.WasiSnapshotPreview1 extends Object implements WasiConstants
-
-
Field Summary
-
Fields inherited from interface ej.wasi.WasiConstants
AF_INET, AF_INET6, BLOCKING_CONNECT_TIMEOUT, BUFFERED_INPUT_STREAM_SIZE, CLOCK_MONOTONIC, CLOCK_REALTIME, DIRENT_COOKIE_OFFSET, DIRENT_ENTRY_NAME_LENGTH_OFFSET, DIRENT_FILE_TYPE_OFFSET, DIRENT_INODE_OFFSET, DIRENT_SIZE, ERRNO_ACCES, ERRNO_ADDRINUSE, ERRNO_ADDRNOTAVAIL, ERRNO_AFNOSUPPORT, ERRNO_AGAIN, ERRNO_BADF, ERRNO_CONNREFUSED, ERRNO_EXIST, ERRNO_FAULT, ERRNO_HOSTUNREACH, ERRNO_INPROGRESS, ERRNO_INTR, ERRNO_INVAL, ERRNO_IO, ERRNO_ISCONN, ERRNO_ISDIR, ERRNO_MSGSIZE, ERRNO_NAMETOOLONG, ERRNO_NOENT, ERRNO_NOMEM, ERRNO_NOSYS, ERRNO_NOTCONN, ERRNO_NOTDIR, ERRNO_NOTEMPTY, ERRNO_NOTSOCK, ERRNO_NOTSUP, ERRNO_OVERFLOW, ERRNO_SPIPE, ERRNO_SUCCESS, EVENT_AVAILABLE_BYTE_OFFSET, EVENT_ERROR_OFFSET, EVENT_EVENT_TYPE_OFFSET, EVENT_READ_WRITE_HANGUP_OFFSET, EVENT_SIZE, EVENT_USER_DATA_OFFSET, FDFLAGS_APPEND_MASK, FDFLAGS_NON_BLOCK_MASK, FDSTAT_BASE_RIGHTS_OFFSET, FDSTAT_FILE_TYPE_OFFSET, FDSTAT_FLAGS_OFFSET, FDSTAT_INHERITING_RIGHTS_OFFSET, FILESTAT_FILESIZE_OFFSET, FILESTAT_FILETYPE_OFFSET, FILESTAT_INODE_OFFSET, FILESTAT_LAST_MODIFIED_TIME_OFFSET, IFF_LOOPBACK, IFF_RUNNING, IFF_UP, IOVEC_BUFFER_INDEX, IOVEC_BUFFER_LENGTH_INDEX, IOVEC_SIZE, IP_ADD_MEMBERSHIP, IP_DROP_MEMBERSHIP, IP_MULTICAST_IF, IP_MULTICAST_LOOP, IP_MULTICAST_TTL, IP_TTL, IPPROTO_IP, IPPROTO_IPV6, IPv4AddressSize, IPV6_JOIN_GROUP, IPV6_LEAVE_GROUP, IPV6_MULTICAST_HOPS, IPV6_MULTICAST_IF, IPV6_MULTICAST_LOOP, IPV6_UNICAST_HOPS, IPv6AddressSize, LOOKUPFLAGS_SYMLINK_FOLLOW_MASK, MILLIS_TO_NANO, NON_BLOCKING_TIMEOUT, OFLAGS_CREAT_MASK, OFLAGS_DIRECTORY_MASK, OFLAGS_EXCL_MASK, OFLAGS_TRUNC_MASK, POLLING_TIMEOUT, PREOPENTYPE_DIR, PREOPENTYPE_UNKNOWN, PRESTAT_PREOPEN_DIRNAME_OFFSET, PRESTAT_PREOPEN_TAG_OFFSET, RIFLAGS_MSG_PEEK_MASK, RIFLAGS_WAITALL_MASK, RIGHTS_ALL, RIGHTS_DIR, SDFLAGS_READ, SDFLAGS_WRITE, SO_BROADCAST, SO_RCVBUF, SO_REUSEADDR, SO_SNDBUF, SOCK_CLOEXEC, SOCK_NONBLOCK, SOCKET_LEVEL, UDP_PEEK_BUFFER_MAX_SIZE
-
-
Constructor Summary
Constructors Constructor Description WasiSnapshotPreview1()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static intargs_get(WasmModule module, int argNamePtr, int argValuePtr)Reads command-line argument data.static intargs_sizes_get(WasmModule module, int argsCountPtr, int argsDataSizePtr)Returns command-line argument data sizes, that is the number of arguments and the size of the argument string data.static intbind_ext(WasmModule module, int sockfd, int addrPtr, int addrlen, int port)Binds a socket to a local address.static intclock_res_get(WasmModule module, int clockid, int timeResolutionPtr)Returns the resolution of a clock.static intclock_time_get(WasmModule module, int clockid, long precision, int timePtr)Returns the time value of a clock.static intconnect_ext(WasmModule module, int sockfd, int addrPtr, int addrlen, int port)Connects a socket to a remote address.static intdup(WasmModule module, int fd)Duplicates a file descriptor.static intdup2(WasmModule module, int oldFd, int newFd)Duplicates a file descriptor to a specific target descriptor.static intenviron_get(WasmModule module, int envPtrsPtr, int envBufPtr)Reads environment variable data and writes the environment variable pointers and data into WASM linear memory.static intenviron_sizes_get(WasmModule module, int envCountPtr, int envDataSizePtr)Returns environment variable data sizes, that is the number of environment variable arguments and the size of the environment variable data.static intfd_close(WasmModule module, int fd)Closes a file descriptor.static intfd_datasync(int fd)Synchronizes the data of a file to disk.static intfd_fdstat_get(WasmModule module, int fd, int fdstatPtr)Gets the attributes of a file descriptor.static intfd_fdstat_set_flags(WasmModule module, int fd, int fdflags)Adjusts the flags associated with a file descriptor.static intfd_filestat_get(WasmModule module, int fd, int filestatPtr)Returns the attributes of an open file.static intfd_filestat_set_size(WasmModule module, int fd, long size)Adjusts the size of an open file.static intfd_pread(WasmModule module, int fd, int iovecListPtr, int iovecLen, long offset, int nbReadPtr)Reads from a file descriptor, without using and updating the file descriptor's offset.static intfd_prestat_dir_name(WasmModule module, int fd, int pathPtr, int pathLen)Returns a description of the given preopened file descriptor.static intfd_prestat_get(WasmModule module, int fd, int prestatPtr)Returns a description of the given preopened file descriptor.static intfd_pwrite(WasmModule module, int fd, int iovecListPtr, int iovecLen, long offset, int nbWritePtr)Writes to a file descriptor, without using and updating the file descriptor's offset.static intfd_read(WasmModule module, int fd, int iovecListPtr, int iovecLen, int nbReadPtr)Reads from a file descriptor.static intfd_readdir(WasmModule module, int dirfd, int bufPtr, int bufLen, long cookie, int resPtr)Reads directory entries from a directory.static intfd_renumber(WasmModule module, int fd, int to)Atomically replaces a file descriptor by renumbering another file descriptor.static intfd_seek(WasmModule module, int fd, long offset, int whence, int newOffsetPtr)Moves the offset of a file descriptor.static intfd_sync(int fd)Synchronizes the data and metadata of a file to disk.static intfd_tell(WasmModule module, int fd, int offsetPtr)Returns the current offset of a file descriptor.static intfd_write(WasmModule module, int fd, int iovecListPtr, int iovecLen, int nbWritePtr)Writes to a file descriptor.static intgetaddrinfo_ext(WasmModule module, int index, int nodeNamePtr, int nodeNameLen, int ipv4Family, int ipv6Family, int passive, int canonical, int canonicalNnamePtr, int canonicalNameLenPtr, int addrPtr, int addrLenPtr)Retrieves a single resolved address by index.static intgetaddrinfo_nb_ext(WasmModule module, int nodeNamePtr, int nodeNameLen, int ipv4Family, int ipv6Family, int passive, int nbAddrPtr)Returns the number of addresses matching a DNS query.static intgetfilepath(WasmModule module, int fd, int buf, int bufLen)Gets the path of the file or directory identified by the given file descriptorfd.static intgethostname_ext(WasmModule module, int nameOffset, int namelen)Retrieves the local hostname.static intgetifaddrs_count_ext(WasmModule module, int countPtr)Returns the number of (interface, address) pairs available.static intgetifaddrs_get_ext(WasmModule module, int index, int namePtr, int nameLen, int flagsPtr, int familyPtr, int addrPtr, int addrLenPtr, int prefixLenPtr)Retrieves the (interface, address) pair at the given index.static intgetpeername_ext(WasmModule module, int sockfd, int addrPtr, int addrLenPtr, int portPtr)Retrieves the remote address of a connected socket.static intgetsockname_ext(WasmModule module, int sockfd, int addrPtr, int addrLenPtr, int portPtr)Retrieves the local address of a socket.static intgetsockopt(WasmModule module, int sockfd, int level, int optname, int optvalPtr, int optlenPtr)Gets a socket option.static intlisten(WasmModule module, int sockfd, int backlog)Marks a socket as listening for incoming connections.static intpath_create_directory(WasmModule module, int fd, int path, int pathLen)Creates a directory.static intpath_filestat_get(WasmModule module, int dirfd, int flags, int pathPtr, int pathLen, int filestatPtr)Returns the attributes of a file or directory.static intpath_filestat_set_times(WasmModule module, int fd, int flags, int path, int pathLen, long accessedTime, long modifiedTime, int fstFlags)Adjusts the timestamps of a file or directory.static intpath_link(int oldFd, int oldFlags, int oldPathPtr, int oldPathLen, int newFd, int newPathPtr, int newPathLen)Creates a hard link.static intpath_open(WasmModule module, int dirfd, int dirflags, int pathPtr, int pathLen, int oflags, long fs_rights_base, long fs_rights_inheriting, int fdflags, int fdPtr)Opens a file or directory.static intpath_readlink(int dir_fd, int path, int path_len, int buf, int buf_len, int buf_used)Reads the contents of a symbolic link.static intpath_remove_directory(WasmModule module, int dirfd, int pathPtr, int pathLen)Removes a directory.static intpath_rename(WasmModule module, int oldFd, int oldPathPtr, int oldPathLen, int newFd, int newPathPtr, int newPathLen)Renames a file or directory.static intpath_symlink(int oldPathPtr, int oldPathLen, int dirFd, int newPathPtr, int newPathLen)Creates a symbolic link.static intpath_unlink_file(WasmModule module, int dirfd, int pathPtr, int pathLen)Unlinks a file.static intpipe(WasmModule module, int readFdPtr, int writeFdPtr)Creates a unidirectional pipe and writes the two file descriptors into WASM memory.static intpoll_oneoff(WasmModule module, int subscriptionEventPtr, int outEventPtr, int nbSubscription, int nbOccuredEventPtr)Concurrently polls for the occurrence of a set of events.static voidproc_exit(int exitcode)Terminates the process normally.static intrandom_get(WasmModule module, int ptr, int len)Writes high-quality random data into a buffer.static intrecvfrom_ext(WasmModule module, int fd, int buffPtr, int buffLen, int srcAddrPtr, int srcAddrLenPtr, int srcPortPtr, int nonblocking, int nbReadPtr)Receives data from a socket, optionally returning the sender's address.static intsched_yield()Temporarily yields execution of the calling thread.static intsendto_ext(WasmModule module, int fd, int buffPtr, int buffLen, int dstAddrPtr, int dstAddrLen, int dstPort, int nonblocking, int nbsentPtr)Sends data through a socket, optionally to a specific destination.static intsetsockopt(WasmModule module, int sockfd, int level, int optname, int optvalPtr, int optlen)Sets a socket option.static intsock_accept(WasmModule module, int fd, int fdflags, int fdPtr)Accepts a new incoming connection.static intsock_recv(WasmModule module, int fd, int iovecListPtr, int iovecLen, int riFlags, int nbRecvPtr, int roFlagsPtr)Receives a message from a socket.static intsock_send(WasmModule module, int fd, int iovecListPtr, int iovecLen, int siFlags, int nbSendPtr)Sends a message on a socket.static intsock_shutdown(WasmModule module, int sockfd, int how)Shuts down socket send and receive channels.static intsocket(WasmModule module, int domain, int type, int protocol)Creates a new socket of the specified domain, type, and protocol.
-
-
-
Method Detail
-
args_sizes_get
public static int args_sizes_get(WasmModule module, int argsCountPtr, int argsDataSizePtr)
Returns command-line argument data sizes, that is the number of arguments and the size of the argument string data.- Parameters:
module- the Wasm module instanceargsCountPtr- pointer in WASM memory where the number of arguments is writtenargsDataSizePtr- pointer in WASM memory where the size of the argument string data is written- Returns:
- an ERRNO
-
args_get
public static int args_get(WasmModule module, int argNamePtr, int argValuePtr)
Reads command-line argument data. The size of the array should match that returned byargs_sizes_get. Each argument is expected to be\0terminated.- Parameters:
module- the Wasm module instanceargNamePtr- pointer in WASM memory to the array of argument pointersargValuePtr- pointer in WASM memory to the buffer holding the argument data- Returns:
- an ERRNO
-
environ_sizes_get
public static int environ_sizes_get(WasmModule module, int envCountPtr, int envDataSizePtr)
Returns environment variable data sizes, that is the number of environment variable arguments and the size of the environment variable data.- Parameters:
module- the Wasm module instanceenvCountPtr- pointer in WASM memory where the number of environment variables is writtenenvDataSizePtr- pointer in WASM memory where the size of the environment variable data is written- Returns:
- an ERRNO
-
environ_get
public static int environ_get(WasmModule module, int envPtrsPtr, int envBufPtr)
Reads environment variable data and writes the environment variable pointers and data into WASM linear memory. The sizes of the buffers should match that returned byenviron_sizes_get. Key/value pairs are expected to be joined with=s, and terminated with\0s. The WASI convention:envPtrsPtrpoints to an array of int32 pointers,envBufPtrpoints to a contiguous buffer of null-terminated"KEY=VALUE"strings.- Parameters:
module- the Wasm module instanceenvPtrsPtr- pointer in WASM memory to the array of environment variable pointersenvBufPtr- pointer in WASM memory to the buffer holding the environment variable data- Returns:
- an ERRNO
-
proc_exit
public static void proc_exit(int exitcode)
Terminates the process normally. An exit code of 0 indicates successful termination of the program. The meanings of other values is dependent on the environment.- Parameters:
exitcode- the exit code returned by the process
-
clock_time_get
public static int clock_time_get(WasmModule module, int clockid, long precision, int timePtr)
Returns the time value of a clock. Note: This is similar toclock_gettimein POSIX.- Parameters:
module- the Wasm module instanceclockid- the clock for which to return the timeprecision- the maximum lag (exclusive) that the returned time value may have, compared to its actual valuetimePtr- pointer in WASM memory where the time value of the clock is written, in nanoseconds- Returns:
- an ERRNO
-
clock_res_get
public static int clock_res_get(WasmModule module, int clockid, int timeResolutionPtr)
Returns the resolution of a clock. Implementations are required to provide a non-zero value for supported clocks. For unsupported clocks,errno::invalis returned. Note: This is similar toclock_getresin POSIX.- Parameters:
module- the Wasm module instanceclockid- the clock for which to return the resolutiontimeResolutionPtr- pointer in WASM memory where the resolution of the clock is written, in nanoseconds- Returns:
- an ERRNO
-
fd_close
public static int fd_close(WasmModule module, int fd)
Closes a file descriptor. Note: This is similar toclosein POSIX.- Parameters:
module- the Wasm module instancefd- the file descriptor to close- Returns:
- an ERRNO
-
fd_read
public static int fd_read(WasmModule module, int fd, int iovecListPtr, int iovecLen, int nbReadPtr)
Reads from a file descriptor. Note: This is similar toreadvin POSIX.- Parameters:
module- the Wasm module instancefd- the file descriptor to read fromiovecListPtr- pointer in WASM memory to the list of scatter/gather vectors to which to store dataiovecLen- the length of the array pointed to byiovecListPtrnbReadPtr- pointer in WASM memory where the number of bytes read is written- Returns:
- an ERRNO
-
fd_pread
public static int fd_pread(WasmModule module, int fd, int iovecListPtr, int iovecLen, long offset, int nbReadPtr)
Reads from a file descriptor, without using and updating the file descriptor's offset. Note: This is similar topreadvin Linux (and other Unix-es).- Parameters:
module- the Wasm module instancefd- the file descriptor to read fromiovecListPtr- pointer in WASM memory to the list of scatter/gather vectors in which to store dataiovecLen- the length of the array pointed to byiovecListPtroffset- the offset within the file at which to readnbReadPtr- pointer in WASM memory where the number of bytes read is written- Returns:
- an ERRNO
-
fd_readdir
public static int fd_readdir(WasmModule module, int dirfd, int bufPtr, int bufLen, long cookie, int resPtr)
Reads 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 adirentobject, followed bydirent::d_namlenbytes 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.- Parameters:
module- the Wasm module instancedirfd- the file descriptor of the directory to readbufPtr- pointer in WASM memory to the buffer where directory entries are storedbufLen- the length of the buffer atbufPtrcookie- the location within the directory to start readingresPtr- pointer in WASM memory where the number of bytes stored in the read buffer is written; if less than the size of the read buffer, the end of the directory has been reached- Returns:
- an ERRNO
-
fd_write
public static int fd_write(WasmModule module, int fd, int iovecListPtr, int iovecLen, int nbWritePtr)
Writes to a file descriptor. Note: This is similar towritevin POSIX. Like POSIX, any calls ofwrite(and other functions to read or write) for a regular file by other threads in the WASI process should not be interleaved whilewriteis executed.- Parameters:
module- the Wasm module instancefd- the file descriptor to write toiovecListPtr- pointer in WASM memory to the list of scatter/gather vectors from which to retrieve dataiovecLen- the length of the array pointed to byiovecListPtrnbWritePtr- pointer in WASM memory where the number of bytes written is written- Returns:
- an ERRNO
-
fd_pwrite
public static int fd_pwrite(WasmModule module, int fd, int iovecListPtr, int iovecLen, long offset, int nbWritePtr)
Writes to a file descriptor, without using and updating the file descriptor's offset. Note: This is similar topwritevin Linux (and other Unix-es). Like Linux (and other Unix-es), any calls ofpwrite(and other functions to read or write) for a regular file by other threads in the WASI process should not be interleaved whilepwriteis executed.- Parameters:
module- the Wasm module instancefd- the file descriptor to write toiovecListPtr- pointer in WASM memory to the list of scatter/gather vectors from which to retrieve dataiovecLen- the length of the array pointed to byiovecListPtroffset- the offset within the file at which to writenbWritePtr- pointer in WASM memory where the number of bytes written is written- Returns:
- an ERRNO
-
fd_datasync
public static int fd_datasync(int fd)
Synchronizes the data of a file to disk. Note: This is similar tofdatasyncin POSIX.- Parameters:
fd- the file descriptor to synchronize- Returns:
- an ERRNO
-
fd_sync
public static int fd_sync(int fd)
Synchronizes the data and metadata of a file to disk. Note: This is similar tofsyncin POSIX.- Parameters:
fd- the file descriptor to synchronize- Returns:
- an ERRNO
-
path_create_directory
public static int path_create_directory(WasmModule module, int fd, int path, int pathLen)
Creates a directory. Note: This is similar tomkdiratin POSIX.- Parameters:
module- the Wasm module instancefd- the file descriptor of the directory the path is relative topath- pointer in WASM memory to the path at which to create the directorypathLen- the length of the path- Returns:
- an ERRNO
-
fd_filestat_set_size
public static int fd_filestat_set_size(WasmModule module, int fd, long size)
Adjusts the size of an open file. If this increases the file's size, the extra bytes are filled with zeros. Note: This is similar toftruncatein POSIX.- Parameters:
module- the Wasm module instancefd- the file descriptor of the file to resizesize- the desired file size- Returns:
- an ERRNO
-
path_filestat_set_times
public static int path_filestat_set_times(WasmModule module, int fd, int flags, int path, int pathLen, long accessedTime, long modifiedTime, int fstFlags)
Adjusts the timestamps of a file or directory. Note: This is similar toutimensatin POSIX.- Parameters:
module- the Wasm module instancefd- the file descriptor of the directory the path is relative toflags- flags determining the method of how the path is resolvedpath- pointer in WASM memory to the path of the file or directory to operate onpathLen- the length of the pathaccessedTime- the desired values of the data access timestampmodifiedTime- the desired values of the data modification timestampfstFlags- a bitmask indicating which timestamps to adjust- Returns:
- an ERRNO
-
fd_seek
public static int fd_seek(WasmModule module, int fd, long offset, int whence, int newOffsetPtr)
Moves the offset of a file descriptor. Note: This is similar tolseekin POSIX.- Parameters:
module- the Wasm module instancefd- the file descriptor to seekoffset- the number of bytes to movewhence- the base from which the offset is relativenewOffsetPtr- pointer in WASM memory where the new offset of the file descriptor, relative to the start of the file, is written- Returns:
- an ERRNO
-
fd_fdstat_get
public static int fd_fdstat_get(WasmModule module, int fd, int fdstatPtr)
Gets the attributes of a file descriptor. Note: This returns similar flags tofcntl(fd, F_GETFL)in POSIX, as well as additional fields.- Parameters:
module- the Wasm module instancefd- the file descriptor to queryfdstatPtr- pointer in WASM memory to the buffer where the file descriptor's attributes are stored- Returns:
- an ERRNO
-
fd_fdstat_set_flags
public static int fd_fdstat_set_flags(WasmModule module, int fd, int fdflags)
Adjusts the flags associated with a file descriptor. Note: This is similar tofcntl(fd, F_SETFL, flags)in POSIX.- Parameters:
module- the Wasm module instancefd- the file descriptor to configurefdflags- the desired values of the file descriptor flags- Returns:
- an ERRNO
-
fd_prestat_get
public static int fd_prestat_get(WasmModule module, int fd, int prestatPtr)
Returns a description of the given preopened file descriptor.- Parameters:
module- the Wasm module instancefd- the file descriptor to queryprestatPtr- pointer in WASM memory to the buffer where the description is stored- Returns:
- an ERRNO
-
fd_prestat_dir_name
public static int fd_prestat_dir_name(WasmModule module, int fd, int pathPtr, int pathLen)
Returns a description of the given preopened file descriptor.- Parameters:
module- the Wasm module instancefd- the file descriptor to querypathPtr- pointer in WASM memory to a buffer into which to write the preopened directory namepathLen- the length of the buffer atpathPtr- Returns:
- an ERRNO
-
sock_accept
public static int sock_accept(WasmModule module, int fd, int fdflags, int fdPtr)
Accepts a new incoming connection. Note: This is similar toacceptin POSIX.- Parameters:
module- the Wasm module instancefd- the listening socketfdflags- the desired values of the file descriptor flagsfdPtr- pointer in WASM memory where the file descriptor of the new socket connection is written- Returns:
- an ERRNO
-
sock_shutdown
public static int sock_shutdown(WasmModule module, int sockfd, int how)
Shuts down socket send and receive channels. Note: This is similar toshutdownin POSIX.- Parameters:
module- the Wasm module instancesockfd- the file descriptor of the socket to shut downhow- which channels on the socket to shut down- Returns:
- an ERRNO
-
fd_tell
public static int fd_tell(WasmModule module, int fd, int offsetPtr)
Returns the current offset of a file descriptor. Note: This is similar tolseek(fd, 0, SEEK_CUR)in POSIX.- Parameters:
module- the Wasm module instancefd- the file descriptor to queryoffsetPtr- pointer in WASM memory where the current offset of the file descriptor, relative to the start of the file, is written- Returns:
- an ERRNO
-
fd_filestat_get
public static int fd_filestat_get(WasmModule module, int fd, int filestatPtr)
Returns the attributes of an open file.- Parameters:
module- the Wasm module instancefd- the file descriptor to queryfilestatPtr- pointer in WASM memory to the buffer where the file's attributes are stored- Returns:
- an ERRNO
-
path_unlink_file
public static int path_unlink_file(WasmModule module, int dirfd, int pathPtr, int pathLen)
Unlinks a file.errno::isdiris returned if the path refers to a directory. Note: This is similar tounlinkat(fd, path, 0)in POSIX.- Parameters:
module- the Wasm module instancedirfd- the file descriptor of the directory the path is relative topathPtr- pointer in WASM memory to the path to a file to unlinkpathLen- the length of the path- Returns:
- an ERRNO
-
path_remove_directory
public static int path_remove_directory(WasmModule module, int dirfd, int pathPtr, int pathLen)
Removes a directory.errno::notemptyis returned if the directory is not empty. Note: This is similar tounlinkat(fd, path, AT_REMOVEDIR)in POSIX.- Parameters:
module- the Wasm module instancedirfd- the file descriptor of the directory the path is relative topathPtr- pointer in WASM memory to the path to a directory to removepathLen- the length of the path- Returns:
- an ERRNO
-
path_filestat_get
public static int path_filestat_get(WasmModule module, int dirfd, int flags, int pathPtr, int pathLen, int filestatPtr)
Returns the attributes of a file or directory. Note: This is similar tostatin POSIX.- Parameters:
module- the Wasm module instancedirfd- the file descriptor of the directory the path is relative toflags- flags determining the method of how the path is resolvedpathPtr- pointer in WASM memory to the path of the file or directory to inspectpathLen- the length of the pathfilestatPtr- pointer in WASM memory to the buffer where the file's attributes are stored- Returns:
- an ERRNO
-
path_open
public static int path_open(WasmModule module, int dirfd, int dirflags, int pathPtr, int pathLen, int oflags, long fs_rights_base, long fs_rights_inheriting, int fdflags, int fdPtr)
Opens 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 than2**31. Note: This is similar toopenatin POSIX.- Parameters:
module- the Wasm module instancedirfd- the file descriptor of the directory the path is relative todirflags- flags determining the method of how the path is resolvedpathPtr- pointer in WASM memory to the relative path of the file or directory to open, relative to thedirfddirectorypathLen- the length of the pathoflags- the method by which to open the filefs_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 the rights that will apply to operations using the file descriptor itselffs_rights_inheriting- the inheriting rights, that is the rights that apply to file descriptors derived from the new onefdflags- the desired values of the file descriptor flagsfdPtr- pointer in WASM memory where the file descriptor of the file that has been opened is written- Returns:
- an ERRNO
-
path_rename
public static int path_rename(WasmModule module, int oldFd, int oldPathPtr, int oldPathLen, int newFd, int newPathPtr, int newPathLen)
Renames a file or directory. Note: This is similar torenameatin POSIX.- Parameters:
module- the Wasm module instanceoldFd- the file descriptor of the directory the source path is relative tooldPathPtr- pointer in WASM memory to the source path of the file or directory to renameoldPathLen- the length of the source pathnewFd- the working directory at which the resolution of the new path startsnewPathPtr- pointer in WASM memory to the destination path to which to rename the file or directorynewPathLen- the length of the destination path- Returns:
WasiConstants.ERRNO_SUCCESSon success, or the appropriate errno value on error
-
sock_recv
public static int sock_recv(WasmModule module, int fd, int iovecListPtr, int iovecLen, int riFlags, int nbRecvPtr, int roFlagsPtr)
Receives a message from a socket. Note: This is similar torecvin POSIX, though it also supports reading the data into multiple buffers in the manner ofreadv.- Parameters:
module- the Wasm module instancefd- the file descriptor of the socket to receive fromiovecListPtr- pointer in WASM memory to the list of scatter/gather vectors to which to store dataiovecLen- the length of the array pointed to byiovecListPtrriFlags- message flagsnbRecvPtr- pointer in WASM memory where the number of bytes stored in the vectors is writtenroFlagsPtr- pointer in WASM memory where the message flags of the received message are written- Returns:
- an ERRNO
-
sock_send
public static int sock_send(WasmModule module, int fd, int iovecListPtr, int iovecLen, int siFlags, int nbSendPtr)
Sends a message on a socket. Note: This is similar tosendin POSIX, though it also supports writing the data from multiple buffers in the manner ofwritev.- Parameters:
module- the Wasm module instancefd- the file descriptor of the socket to send oniovecListPtr- pointer in WASM memory to the list of scatter/gather vectors from which to retrieve dataiovecLen- the length of the array pointed to byiovecListPtrsiFlags- message flagsnbSendPtr- pointer in WASM memory where the number of bytes transmitted is written- Returns:
- an ERRNO
-
poll_oneoff
public static int poll_oneoff(WasmModule module, int subscriptionEventPtr, int outEventPtr, int nbSubscription, int nbOccuredEventPtr)
Concurrently polls for the occurrence of a set of events. IfnbSubscriptionis 0,errno::invalis returned.- Parameters:
module- the Wasm module instancesubscriptionEventPtr- pointer in WASM memory to the events to which to subscribeoutEventPtr- pointer in WASM memory where the events that have occurred are writtennbSubscription- both the number of subscriptions and eventsnbOccuredEventPtr- pointer in WASM memory where the number of events stored is written- Returns:
- an ERRNO
-
recvfrom_ext
public static int recvfrom_ext(WasmModule module, int fd, int buffPtr, int buffLen, int srcAddrPtr, int srcAddrLenPtr, int srcPortPtr, int nonblocking, int nbReadPtr)
Receives data from a socket, optionally returning the sender's address.Uses the status-returning convention: returns
WasiConstants.ERRNO_SUCCESSon success, or a positive WASI errno on error.Supports both TCP (
WasiSocket) and UDP (WasiDatagramSocket). For UDP, the sender's IP and port are written back to WASM memory so the C side can reconstructstruct sockaddr.- Parameters:
module- the Wasm module instancefd- the socket file descriptorbuffPtr- pointer to the receive buffer in WASM memorybuffLen- the size of the receive buffersrcAddrPtr- pointer to write the sender IP bytes (UDP)srcAddrLenPtr- pointer to write the sender address length (UDP)srcPortPtr- pointer to write the sender port (UDP)nonblocking- 1 for non-blocking receive, 0 for blockingnbReadPtr- pointer to write the number of bytes read- Returns:
ERRNO_SUCCESS,ERRNO_BADF,ERRNO_NOTSOCK,ERRNO_AGAIN,ERRNO_FAULT, orERRNO_IO
-
sendto_ext
public static int sendto_ext(WasmModule module, int fd, int buffPtr, int buffLen, int dstAddrPtr, int dstAddrLen, int dstPort, int nonblocking, int nbsentPtr)
Sends data through a socket, optionally to a specific destination.Uses the status-returning convention: returns
WasiConstants.ERRNO_SUCCESSon success, or a positive WASI errno on error.Supports both TCP (
WasiSocket) and UDP (WasiDatagramSocket). For UDP, the destination address is specified via raw IP bytes and port, already parsed by the C side fromstruct sockaddr.- Parameters:
module- the Wasm module instancefd- the socket file descriptorbuffPtr- pointer to the send buffer in WASM memorybuffLen- the number of bytes to senddstAddrPtr- pointer to the destination IP bytes (UDP)dstAddrLen- the length of the destination address (UDP)dstPort- the destination port (UDP)nonblocking- 1 for non-blocking send, 0 for blockingnbsentPtr- pointer to write the number of bytes sent- Returns:
ERRNO_SUCCESS,ERRNO_BADF,ERRNO_NOTSOCK,ERRNO_FAULT,ERRNO_MSGSIZE, orERRNO_IO
-
random_get
public static int random_get(WasmModule module, int ptr, int len)
Writes high-quality random data into a buffer. This function blocks when the implementation is unable to immediately provide sufficient high-quality random data.- Parameters:
module- the Wasm module instanceptr- pointer in WASM memory to the buffer to fill with random datalen- the length of the buffer atptr- Returns:
- an ERRNO
-
socket
public static int socket(WasmModule module, int domain, int type, int protocol)
Creates a new socket of the specified domain, type, and protocol.Uses the fd-returning convention: returns the new file descriptor on success (>= 0), or a negative WASI errno on error. The C wrapper negates the return value to extract
errnoand returns -1. This convention is shared withdup(ej.lang.WasmModule, int)anddup2(ej.lang.WasmModule, int, int), which also return file descriptors.Linux-style flags (
SOCK_NONBLOCK,SOCK_CLOEXEC) OR'd intotypeare stripped and handled here.SOCK_CLOEXECis silently ignored since WASI has no fork/exec.- Parameters:
module- the Wasm module instancedomain- the address family (AF_INETorAF_INET6)type- the socket type (SOCK_STREAMorSOCK_DGRAM), optionally OR'd withSOCK_NONBLOCKorSOCK_CLOEXECprotocol- the protocol number (must be 0)- Returns:
- the new file descriptor, or:
-ERRNO_AFNOSUPPORTif the address family is not supported-ERRNO_NOTSUPif the protocol is not supported-ERRNO_INVALif the socket type is unknown-ERRNO_IOon I/O error setting non-blocking mode
-
getpeername_ext
public static int getpeername_ext(WasmModule module, int sockfd, int addrPtr, int addrLenPtr, int portPtr)
Retrieves the remote address of a connected socket.Uses the status-returning convention: returns
WasiConstants.ERRNO_SUCCESSon success, or a positive WASI errno on error.- Parameters:
module- the Wasm module instancesockfd- the socket file descriptoraddrPtr- pointer in WASM memory to write the IP address bytesaddrLenPtr- pointer in WASM memory to write the address lengthportPtr- pointer in WASM memory to write the port number- Returns:
ERRNO_SUCCESS,ERRNO_BADF,ERRNO_NOTSOCK,ERRNO_NOTCONN, orERRNO_NOTSUP
-
setsockopt
public static int setsockopt(WasmModule module, int sockfd, int level, int optname, int optvalPtr, int optlen)
Sets a socket option.Uses the status-returning convention: returns
WasiConstants.ERRNO_SUCCESS(0) on success, or a positive WASI errno on error. The C wrapper translates non-zero returns intoerrnoand returns -1.Currently
SO_REUSEADDR,SO_RCVBUF,SO_SNDBUFandSO_BROADCASTatSOL_SOCKETlevel are implemented, as well as the multicast options atIPPROTO_IPandIPPROTO_IPV6level. Unsupported options and levels returnERRNO_NOSYS, except atIPPROTO_IPandIPPROTO_IPV6level on a non-datagram socket, where the call is a no-op reportingERRNO_SUCCESS. That no-op is there because C libraries commonly use the patternif (setsockopt(...)) return -errno;, which would surface errors for options we simply do not implement yet.- Parameters:
module- the Wasm module instancesockfd- the socket file descriptorlevel- the protocol level (e.g.SOL_SOCKET)optname- the option name (e.g.SO_REUSEADDR)optvalPtr- pointer to the option value in WASM linear memoryoptlen- the size of the option value in bytes- Returns:
ERRNO_SUCCESS, or:ERRNO_BADFif the file descriptor is invalidERRNO_NOTSOCKif the file descriptor is not a socketERRNO_INVALif the option length is invalidERRNO_NOSYSif the option or the level is not supportedERRNO_IOon I/O error
-
getsockopt
public static int getsockopt(WasmModule module, int sockfd, int level, int optname, int optvalPtr, int optlenPtr)
Gets a socket option.Uses the status-returning convention: returns
WasiConstants.ERRNO_SUCCESS(0) on success, or a positive WASI errno on error.Currently supports
SO_BROADCAST,SO_RCVBUFandSO_SNDBUF; any other option returnsERRNO_NOSYS. Thelevelargument is ignored by this implementation. wasi-libc's owngetsockopt()only handlesSO_TYPEviafd_fdstat_get; this import covers the remaining queries, including the buffer-size ones, from C code.- Parameters:
module- the Wasm module instancesockfd- the socket file descriptorlevel- the protocol level (e.g.SOL_SOCKET), ignored by this implementationoptname- the option name (e.g.SO_RCVBUF)optvalPtr- pointer to write the option value in WASM memoryoptlenPtr- pointer to write the option length in WASM memory- Returns:
ERRNO_SUCCESS, or a positive WASI errno
-
bind_ext
public static int bind_ext(WasmModule module, int sockfd, int addrPtr, int addrlen, int port)
Binds a socket to a local address.Uses the status-returning convention: returns
WasiConstants.ERRNO_SUCCESSon success, or a positive WASI errno on error.For TCP sockets (
WasiSocket), binding promotes the socket to aWasiServerSocketso it can later accept connections.- Parameters:
module- the Wasm module instancesockfd- the socket file descriptoraddrPtr- pointer to the raw IP address bytes in WASM memoryaddrlen- the length of the address (4 for IPv4, 16 for IPv6)port- the port number to bind to- Returns:
ERRNO_SUCCESS,ERRNO_BADF,ERRNO_NOTSOCK,ERRNO_INVAL,ERRNO_FAULT,ERRNO_ADDRINUSE, orERRNO_IO
-
listen
public static int listen(WasmModule module, int sockfd, int backlog)
Marks a socket as listening for incoming connections.Uses the status-returning convention: returns
WasiConstants.ERRNO_SUCCESSon success, or a positive WASI errno on error.If the socket is not yet bound, it is auto-promoted to a
WasiServerSocketbound to0.0.0.0:0(ephemeral port), matching POSIX behavior for listen on an unbound socket.- Parameters:
module- the Wasm module instancesockfd- the socket file descriptorbacklog- the maximum length of the pending connection queue- Returns:
ERRNO_SUCCESS,ERRNO_INVAL, orERRNO_IO
-
connect_ext
public static int connect_ext(WasmModule module, int sockfd, int addrPtr, int addrlen, int port)
Connects a socket to a remote address.Uses the status-returning convention: returns
WasiConstants.ERRNO_SUCCESSon success, or a positive WASI errno on error.- Parameters:
module- the Wasm module instancesockfd- the socket file descriptoraddrPtr- pointer to the raw IP address bytes in WASM memoryaddrlen- the length of the address (4 for IPv4, 16 for IPv6)port- the remote port number- Returns:
ERRNO_SUCCESS,ERRNO_BADF,ERRNO_NOTSOCK,ERRNO_INVAL,ERRNO_FAULT,ERRNO_CONNREFUSED, orERRNO_IO
-
pipe
public static int pipe(WasmModule module, int readFdPtr, int writeFdPtr)
Creates a unidirectional pipe and writes the two file descriptors into WASM memory.Uses the status-returning convention: returns
WasiConstants.ERRNO_SUCCESS(0) on success, or a positive WASI errno on error. The C wrapper takes a standardint fds[2]array and passes the address of each element as separate pointers.- Parameters:
module- the Wasm module instancereadFdPtr- pointer in WASM memory where the read-end fd is writtenwriteFdPtr- pointer in WASM memory where the write-end fd is written- Returns:
ERRNO_SUCCESSorERRNO_IO
-
dup
public static int dup(WasmModule module, int fd)
Duplicates a file descriptor.Uses the fd-returning convention: returns the new file descriptor on success (>= 0), or a negative WASI errno on error. The C wrapper negates the return value to extract
errnoand returns -1. This convention is necessary because the return value must distinguish a valid fd (>= 0) from an error.- Parameters:
module- the Wasm module instancefd- the file descriptor to duplicate- Returns:
- the new file descriptor, or
-ERRNO_BADF
-
dup2
public static int dup2(WasmModule module, int oldFd, int newFd)
Duplicates a file descriptor to a specific target descriptor.Uses the fd-returning convention: returns
newFdon success (>= 0), or a negative WASI errno on error. The C wrapper negates the return value to extracterrnoand returns -1. This convention is necessary because the return value must distinguish a valid fd (>= 0) from an error.If
newFdis already open, it is closed first. IfoldFd == newFdor both refer to the same I/O object,newFdis returned as-is.- Parameters:
module- the Wasm module instanceoldFd- the source file descriptornewFd- the target file descriptor- Returns:
newFdon success, or:-ERRNO_BADFifoldFdornewFdis invalid-ERRNO_IOif closingnewFdfails
-
fd_renumber
public static int fd_renumber(WasmModule module, int fd, int to)
Atomically replaces 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, likedup2(). 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 ifdup2()were to be removed entirely. After the call,fdis invalidated andtorefers to whatfdpreviously referenced. Iftowas open, it is closed first.- Parameters:
module- the Wasm module instancefd- the source file descriptor to renumber (will be invalidated)to- the target file descriptor to overwrite (will be replaced)- Returns:
WasiConstants.ERRNO_SUCCESSon success, or the appropriate errno value on error
-
getfilepath
public static int getfilepath(WasmModule module, int fd, int buf, int bufLen)
Gets the path of the file or directory identified by the given file descriptorfd.- Parameters:
module- the Wasm module instancefd- the file descriptor to querybuf- the pointer in WASM memory to the buffer where the path is writtenbufLen- the length of the buffer atbuf- Returns:
WasiConstants.ERRNO_SUCCESSon success, or the appropriate errno value on error, one ofERRNO_BADF,ERRNO_NOENT,ERRNO_NAMETOOLONGorERRNO_IO
-
sched_yield
public static int sched_yield()
Temporarily yields execution of the calling thread. Note: This is similar tosched_yieldin POSIX.- Returns:
- an ERRNO
-
path_readlink
public static int path_readlink(int dir_fd, int path, int path_len, int buf, int buf_len, int buf_used)Reads the contents of a symbolic link. Note: This is similar toreadlinkatin POSIX.- Parameters:
dir_fd- the file descriptor of the directory the path is relative topath- pointer in WASM memory to the path of the symbolic link from which to readpath_len- the length of the pathbuf- pointer in WASM memory to the buffer to which to write the contents of the symbolic linkbuf_len- the length of the buffer atbufbuf_used- pointer in WASM memory where the number of bytes placed in the buffer is written- Returns:
- an ERRNO
-
path_link
public static int path_link(int oldFd, int oldFlags, int oldPathPtr, int oldPathLen, int newFd, int newPathPtr, int newPathLen)Creates a hard link. Note: This is similar tolinkatin POSIX.- Parameters:
oldFd- the file descriptor of the directory containing the source path, to which the source path is relativeoldFlags- flags determining the method of how the path is resolvedoldPathPtr- pointer in WASM linear memory to the source path string from which to linkoldPathLen- the length of the source path stringnewFd- the file descriptor of the directory containing the destination path, the working directory at which the resolution of the new path startsnewPathPtr- pointer in WASM linear memory to the destination path string at which to create the hard linknewPathLen- the length of the destination path string- Returns:
- an ERRNO
-
path_symlink
public static int path_symlink(int oldPathPtr, int oldPathLen, int dirFd, int newPathPtr, int newPathLen)Creates a symbolic link. Note: This is similar tosymlinkatin POSIX.- Parameters:
oldPathPtr- pointer in WASM memory to the content of the symbolic link (the target path)oldPathLen- the length of the contents of the symbolic link, the target path stringdirFd- the file descriptor of the directory containing the new link, the working directory at which the resolution of the new path startsnewPathPtr- pointer in WASM memory to the destination path at which to create the symbolic linknewPathLen- the length of the destination path string- Returns:
- an ERRNO
-
gethostname_ext
public static int gethostname_ext(WasmModule module, int nameOffset, int namelen)
Retrieves the local hostname.Uses the status-returning convention: returns
WasiConstants.ERRNO_SUCCESSon success, or a positive WASI errno on error.- Parameters:
module- the Wasm module instancenameOffset- pointer in WASM memory to write the hostnamenamelen- the size of the buffer- Returns:
ERRNO_SUCCESS,ERRNO_NAMETOOLONG,ERRNO_FAULT, orERRNO_IO
-
getsockname_ext
public static int getsockname_ext(WasmModule module, int sockfd, int addrPtr, int addrLenPtr, int portPtr)
Retrieves the local address of a socket.Uses the status-returning convention: returns
WasiConstants.ERRNO_SUCCESSon success, or a positive WASI errno on error.- Parameters:
module- the Wasm module instancesockfd- the socket file descriptoraddrPtr- pointer in WASM memory to write the IP address bytesaddrLenPtr- pointer in WASM memory to write the address lengthportPtr- pointer in WASM memory to write the port number- Returns:
ERRNO_SUCCESS,ERRNO_BADF,ERRNO_NOTSOCK,ERRNO_NOTCONN, orERRNO_NOTSUP
-
getaddrinfo_nb_ext
public static int getaddrinfo_nb_ext(WasmModule module, int nodeNamePtr, int nodeNameLen, int ipv4Family, int ipv6Family, int passive, int nbAddrPtr)
Returns the number of addresses matching a DNS query.Uses the status-returning convention: returns
WasiConstants.ERRNO_SUCCESSon success, or a positive WASI errno on error. Called first to determine how many results to iterate withgetaddrinfo_ext(ej.lang.WasmModule, int, int, int, int, int, int, int, int, int, int, int).- Parameters:
module- the Wasm module instancenodeNamePtr- pointer to the hostname string in WASM memorynodeNameLen- the length of the hostname stringipv4Family- 1 to include IPv4 results, 0 to excludeipv6Family- 1 to include IPv6 results, 0 to excludepassive- 1 for passive (bind) addresses, 0 for active (connect)nbAddrPtr- pointer to write the result count- Returns:
ERRNO_SUCCESS,ERRNO_INVAL, orERRNO_HOSTUNREACH
-
getaddrinfo_ext
public static int getaddrinfo_ext(WasmModule module, int index, int nodeNamePtr, int nodeNameLen, int ipv4Family, int ipv6Family, int passive, int canonical, int canonicalNnamePtr, int canonicalNameLenPtr, int addrPtr, int addrLenPtr)
Retrieves a single resolved address by index.Uses the status-returning convention: returns
WasiConstants.ERRNO_SUCCESSon success, or a positive WASI errno on error. Callgetaddrinfo_nb_ext(ej.lang.WasmModule, int, int, int, int, int, int)first to determine the number of results, then iterate with this function.- Parameters:
module- the Wasm module instanceindex- the 0-based index of the address to retrievenodeNamePtr- pointer to the hostname string in WASM memorynodeNameLen- the length of the hostname stringipv4Family- 1 to include IPv4 resultsipv6Family- 1 to include IPv6 resultspassive- 1 for passive addressescanonical- 1 to request the canonical namecanonicalNnamePtr- pointer to write the canonical name bytescanonicalNameLenPtr- pointer to read and write the canonical name buffer lengthaddrPtr- pointer to write the IP address bytesaddrLenPtr- pointer to write the address length- Returns:
ERRNO_SUCCESS,ERRNO_INVAL,ERRNO_HOSTUNREACH, orERRNO_NAMETOOLONG
-
getifaddrs_count_ext
public static int getifaddrs_count_ext(WasmModule module, int countPtr)
Returns the number of (interface, address) pairs available. Status-returning: 0 on success, positive WASI errno on error.- Parameters:
module- the Wasm module instancecountPtr- pointer in WASM memory where the number of pairs is written- Returns:
- an ERRNO
-
getifaddrs_get_ext
public static int getifaddrs_get_ext(WasmModule module, int index, int namePtr, int nameLen, int flagsPtr, int familyPtr, int addrPtr, int addrLenPtr, int prefixLenPtr)
Retrieves the (interface, address) pair at the given index. Status-returning: 0 on success, positive WASI errno on error.Writes to WASM memory:
namePtr: interface name bytes + null terminatorflagsPtr:IFF_UP|IFF_RUNNING(always),|IFF_LOOPBACKif loopbackfamilyPtr:AF_INET(1) orAF_INET6(2), WASI values matchingWasiConstantsaddrPtr: IP address bytes (4 for v4, 16 for v6)addrLenPtr: address byte lengthprefixLenPtr: CIDR prefix length
- Parameters:
module- the Wasm module instanceindex- the 0-based index of the pair to retrievenamePtr- pointer in WASM memory where the interface name is writtennameLen- the length of the buffer atnamePtrflagsPtr- pointer in WASM memory where the interface flags are writtenfamilyPtr- pointer in WASM memory where the address family is writtenaddrPtr- pointer in WASM memory where the IP address bytes are writtenaddrLenPtr- pointer in WASM memory where the length of the IP address is writtenprefixLenPtr- pointer in WASM memory where the CIDR prefix length is written- Returns:
- an ERRNO
-
-