Skip to content

Commit

Permalink
add wasi documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
agazardMicroeJ committed Dec 5, 2024
1 parent bc6daa1 commit 397d226
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 1 deletion.
3 changes: 2 additions & 1 deletion ApplicationDeveloperGuide/managedc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ You can start exploring this functionality by following the instructions provide
getting_started
compilation
communication
wasi
limitations
troubleshooting
..
| Copyright 2023, MicroEJ Corp. Content in this space is free
| Copyright 2023-2024, MicroEJ Corp. Content in this space is free
for read and redistribute. Except if otherwise stated, modification
is subject to MicroEJ Corp prior approval.
| MicroEJ is a trademark of MicroEJ Corp. All other trademarks and
Expand Down
92 changes: 92 additions & 0 deletions ApplicationDeveloperGuide/managedc/wasi.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
.. _wasm.wasi:

WASI
=======

WebAssembly System Interface (WASI) provides a modular and secure system interface designed to enable WASM module to interact with the underlying operating system in a platform-independent manner.

We provide a ``WASI Add-on Library`` which implements a subset of `WASI 0.1 APIs <https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md>`_.

All the implemented functions are exported under the module name ``wasi_snapshot_preview1``.

The APIs are extended to support certain POSIX functions that are not available in `wasi-libc <https://github.com/WebAssembly/wasi-libc>`_ such as ``socket``, ``bind``, ``connect`` etc.

To use the WASI Add-on Library, add the following to the project build file:

.. tabs::

.. tab:: Gradle (build.gradle.kts)

.. code-block:: kotlin
implementation("ej.library.wasm:wasi:1.0.0")
.. tab:: MMM (module.ivy)

.. code-block:: xml
<dependency org="ej.library.wasm" name="wasi" rev="1.0.0"/>
The sections below list the WASI APIs and the high level WASI-based POSIX APIs that are currently supported.

WASI APIs
---------

.. list of supported WASI APIs
+-----------------+----------------------------------------------------------------------------------------------+
| **Group** | **WASI APIs** |
+-----------------+----------------------------------------------------------------------------------------------+
|| **FileSystem** || ``path_open``, ``fd_readdir``, ``fd_close``, ``fd_read``, ``fd_pread``, ``fd_write``, |
|| || ``fd_pwrite``, ``fd_seek``, ``fd_fdstat_get``, ``fd_fdstat_set_flags``, ``fd_prestat_get``, |
|| || ``fd_prestat_dir_name``, ``fd_tell``, ``fd_filestat_get``, ``path_unlink_file``, |
|| || ``path_remove_directory``, ``path_filestat_get`` |
+-----------------+----------------------------------------------------------------------------------------------+
| **Sockets** | ``sock_accept``, ``sock_shutdown``, ``poll_oneoff``, ``sock_recv``, ``sock_send`` |
+-----------------+----------------------------------------------------------------------------------------------+
| **Clocks** | ``clock_time_get``, ``clock_res_get`` |
+-----------------+----------------------------------------------------------------------------------------------+
| **Process** | ``proc_exit`` |
+-----------------+----------------------------------------------------------------------------------------------+

High-Level WASI-Based POSIX APIs
--------------------------------

.. list of supported high-level WASI-based POSIX APIs
+-----------------+-----------------------------------------------------------------------------------------------+
| **Group** | **High-Level WASI-Based POSIX APIs** |
+-----------------+-----------------------------------------------------------------------------------------------+
|| **FileSystem** || ``open``, ``fopen``, ``fdopendir``, ``close``, ``fclose``, ``read``, ``write``, ``fread``, |
|| || ``fwrite`, ``lseek``, ``stat``, ``fstat``, ``readdir``, ``fstatat``, ``fileno``, ``fflush``, |
|| || ``access`` |
+-----------------+-----------------------------------------------------------------------------------------------+
| **Sockets** | ``send``, ``recv``, ``shutdown``, ``close`` |
+-----------------+-----------------------------------------------------------------------------------------------+
| **Clocks** | ``clock_getres``, ``clock_gettime`` ``gettimeofday`` |
+-----------------+-----------------------------------------------------------------------------------------------+
| **Process** | ``exit`` |
+-----------------+-----------------------------------------------------------------------------------------------+
| **StdIO** | ``printf`` |
+-----------------+-----------------------------------------------------------------------------------------------+

High-Level Extended WASI POSIX APIs
-----------------------------------

.. list of supported high-level extended WASI POSIX APIs
+-------------+-----------------------------------------------+
| **Group** | **High-Level Extended WASI POSIX APIs** |
+-------------+-----------------------------------------------+
| **Sockets** | ``socket``, ``bind``, ``listen``, ``connect`` |
+-------------+-----------------------------------------------+
| **Miscs** | ``dup``, ``dup2``, ``pipe`` |
+-------------+-----------------------------------------------+

..
| Copyright 2024, MicroEJ Corp. Content in this space is free
for read and redistribute. Except if otherwise stated, modification
is subject to MicroEJ Corp prior approval.
| MicroEJ is a trademark of MicroEJ Corp. All other trademarks and
copyrights are the property of their respective owners.

0 comments on commit 397d226

Please sign in to comment.