Package ej.wasi

Class Wasi

    • 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, or null for 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 via WasmModule.setHostInfo(java.lang.Object).

        Parameters:
        module - the WASI module instance to initialize.
        preopenedDirs - the list of directories to pre-open, or null to 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[]) with new 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 a NativeIOException. MicroEJ's native networking layer sometimes wraps the real error inside a generic IOException; this unwraps it so we can extract the specific error code.
        Returns:
        the mapped WASI errno, or WasiConstants.ERRNO_IO if no native error found.