Package ej.wasi
Class Wasi
- java.lang.Object
-
- ej.wasi.Wasi
-
- All Implemented Interfaces:
WasiConstants
public class Wasi extends Object implements WasiConstants
The Web Assembly System Interface (WASI) implementation for MicroEJ. Included APIs:- WasiSnapshotPreview1 subset.
- WASI Threads
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classWasi.StdOutstatic classWasi.WasiSnapshotPreview1
-
Field Summary
Fields Modifier and Type Field Description static intNULLstatic intSTDERR_FILENOFile number ofstderrstatic intSTDIN_FILENOFile number ofstdinstatic intSTDOUT_FILENOFile number ofstdout-
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
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static intextractWasiErrno(Throwable t)Walks an exception's cause chain looking for aNativeIOException.static voidinit(WasmModule module)Initializes WASI for the given module instance with the root directory ("/") pre-opened.static voidinit(WasmModule module, String[] preopenedDirs)Initializes WASI for the given module instance.static voidsetEnvironment(WasmModule module, String[] env)Sets environment variables for the given module.static voidsetStdErr(WasmModule module, WritableIO stdErr)Reassigns the "standard" error output stream for WASI.static voidsetStdIn(WasmModule module, ReadableIO stdIn)Reassigns the "standard" input stream for WASI.static voidsetStdOut(WasmModule module, WritableIO stdOut)Reassigns the "standard" output stream for WASI.static intthreadSpawn(WasmModule currentModule, int args)
-
-
-
Field Detail
-
NULL
public static final int NULL
- See Also:
- Constant Field Values
-
STDIN_FILENO
public static final int STDIN_FILENO
File number ofstdin- See Also:
- Constant Field Values
-
STDOUT_FILENO
public static final int STDOUT_FILENO
File number ofstdout- See Also:
- Constant Field Values
-
STDERR_FILENO
public static final int STDERR_FILENO
File number ofstderr- See Also:
- Constant Field Values
-
-
Method Detail
-
setEnvironment
public static void setEnvironment(WasmModule module, @Nullable String[] env)
Sets environment variables for the given module.- Parameters:
module- the WASI module instance.env- array of "KEY=VALUE" strings, ornullfor no environment.
-
setStdOut
public static void setStdOut(WasmModule module, WritableIO stdOut)
Reassigns the "standard" output stream for WASI.- Parameters:
module- the WASI module instance.stdOut- the new standard output stream
-
setStdErr
public static void setStdErr(WasmModule module, WritableIO stdErr)
Reassigns the "standard" error output stream for WASI.- Parameters:
module- the WASI module instance.stdErr- the new standard error output stream
-
setStdIn
public static void setStdIn(WasmModule module, ReadableIO stdIn)
Reassigns the "standard" input stream for WASI.- Parameters:
module- the WASI module instance.stdIn- the new standard input stream
-
init
public static void init(WasmModule module, @Nullable String[] preopenedDirs) throws IOException
Initializes WASI for the given module instance.Creates a fresh
WasiContext, wires up standard I/O, registers pre-opened directories, and stores the context on the module viaWasmModule.setHostInfo(java.lang.Object).- Parameters:
module- the WASI module instance to initialize.preopenedDirs- the list of directories to pre-open, ornullto pre-open none.- Throws:
IOException- if a pre-opened directory cannot be opened.IllegalStateException- if the module was already initialized.
-
init
public static void init(WasmModule module) throws IOException
Initializes WASI for the given module instance with the root directory ("/") pre-opened.Equivalent to calling
init(WasmModule, String[])withnew String[]{"/"}as the directory list.- Parameters:
module- the WASI module instance to initialize.- Throws:
IOException- if a pre-opened directory cannot be opened.IllegalStateException- if the module was already initialized.
-
threadSpawn
public static int threadSpawn(WasmModule currentModule, int args)
-
extractWasiErrno
public static int extractWasiErrno(@Nullable Throwable t)
Walks an exception's cause chain looking for aNativeIOException. MicroEJ's native networking layer sometimes wraps the real error inside a genericIOException; this unwraps it so we can extract the specific error code.- Returns:
- the mapped WASI errno, or
WasiConstants.ERRNO_IOif no native error found.
-
-