Skip to content

[WASI] Implement missing WASI preview1 functions #435

Description

@clover2123

[WASI] Implement missing WASI preview1 functions

Summary

Walrus currently registers 37 WASI functions in FOR_EACH_WASI_FUNC (src/wasi/WASI.h), while the WASI preview1 (wasi_snapshot_preview1) specification defines 46 host functions. This issue tracks the remaining 9 unimplemented functions so that Walrus can reach full preview1 coverage.

Since Walrus delegates WASI to uvwasi(https://github.com/nodejs/uvwasi) and uvwasi already exposes an API for every preview1 function, most of these can be implemented as thin wrappers following the existing patterns in src/wasi/WASI.cpp (memory-pointer validation via get_memory_pointer(), TemporaryData<> for iovec marshalling, and WasiErrNo result values).

Reference: WASI preview1 documentation

Missing functions

fd operations

  • fd_allocateI32I64I64_RI32 (fd, offset, len) → errno
    • Wrap uvwasi_fd_allocate(). Structure is nearly identical to the existing fd_advise implementation.
  • fd_pwriteI32I32I32I64I32_RI32 (fd, iovs, iovs_len, offset, nwritten) → errno
    • Wrap uvwasi_fd_pwrite(). Mirror image of the already-implemented fd_pread (use uvwasi_ciovec_t instead of uvwasi_iovec_t, same as fd_write).
  • fd_filestat_set_sizeI32I64_RI32 (fd, size) → errno
    • Wrap uvwasi_fd_filestat_set_size().
  • fd_fdstat_set_rightsI32I64I64_RI32 (fd, fs_rights_base, fs_rights_inheriting) → errno
    • Wrap uvwasi_fd_fdstat_set_rights(). Note: the rights system only exists in preview1 (removed in later WASI revisions), but it is still part of the snapshot_1 ABI that toolchains such as wasi-sdk target.

path operations

  • path_linkI32I32I32I32I32I32I32_RI32 (old_fd, old_flags, old_path, old_path_len, new_fd, new_path, new_path_len) → errno
    • Wrap uvwasi_path_link(). Two-path pattern similar to the existing path_rename.
  • path_symlinkI32I32I32I32I32_RI32 (old_path, old_path_len, fd, new_path, new_path_len) → errno
    • Wrap uvwasi_path_symlink(). Counterpart of the existing path_readlink.

sock operations

  • sock_acceptI32I32I32_RI32 (fd, flags, ro_fd) → errno
    • Wrap uvwasi_sock_accept() (available since uvwasi v0.0.12).
  • sock_recvI32I32I32I32I32I32_RI32 (fd, ri_data, ri_data_len, ri_flags, ro_datalen, ro_flags) → errno
  • sock_sendI32I32I32I32I32_RI32 (fd, si_data, si_data_len, si_flags, so_datalen) → errno
    • Note: uvwasi may return UVWASI_ENOTSUP for sock_recv/sock_send depending on the pinned submodule version. If so, we should still register the functions and propagate the errno, so that modules importing them can at least instantiate (matching the behavior of other runtimes).

Suggested implementation steps (per function)

  1. Add an entry to FOR_EACH_WASI_FUNC in src/wasi/WASI.h with the correct signature string.
  2. Implement the wrapper in src/wasi/WASI.cpp, following the existing conventions:
    • Validate all guest pointers with get_memory_pointer() and return WasiErrNo::inval on failure.
    • Use TemporaryData<uvwasi_ciovec_t, 8> for scatter/gather buffers (see fd_write / fd_pread).
  3. Add a test under test/wasi/ (.wast), following existing tests such as fd_seek.wast or path_readlink.wast.
  4. Verify with tools/run-tests.py wasi and run tools/check_tidy.py before submitting the PR.

Related: missing test coverage for already-implemented functions

While auditing test/wasi/, we also noticed some implemented functions have no dedicated test yet. These could be tracked here or split into a separate issue:

  • fd_pread
  • fd_readdir
  • fd_fdstat_set_flags
  • poll_oneoff
  • path_rename / path_unlink_file / path_create_directory / path_remove_directory (partially covered by filesystem_functions.wast — dedicated edge-case tests would help)

Notes

  • We (a group of undergraduate contributors) would like to work on this incrementally, one function per PR, starting with fd_pwrite. Please let us know if this plan works for the maintainers, or if any of these functions are intentionally omitted (e.g., for embedded targets).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions